From patchwork Wed Dec 21 14:00:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 35379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3541658wrn; Wed, 21 Dec 2022 06:06:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXskX9MzP5rtiA8NnCGHN2lJOuRVE6Y+77aFa1GPfn58IxDSh/VawYnrvvq+XOqn6sPhng5p X-Received: by 2002:a17:906:7187:b0:7bd:f540:9bf9 with SMTP id h7-20020a170906718700b007bdf5409bf9mr1523365ejk.32.1671631594774; Wed, 21 Dec 2022 06:06:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671631594; cv=none; d=google.com; s=arc-20160816; b=GzxY05zSSnhaxanAkDumMeWUbL8RgRNI5gPFqassLbtponMcPq8T0d5CZ8zBVCIzQu RboAPb3ZAR6LP94CJlmOllShuVXsQOK2vo8xcf/7iYKtOZanbGQRilAxT3CNt173PuDA M49w2mSlogU8ZqQPT2jAlKC59YHsbOmGdxAeJYLgn4H79TrZ6PO0PT6GEE+Vwc2t4CsH +8HqSExGVaqBiv6nSD39fPaXWy2eTpo1JGHPXsUXYWDNnu4iJMquug+pOYbmrsbqNphk FqmHCwvmoDykJtHwG0Pb8NPYedLOqerIpc9cMsMHbuAe2IlmKSYuUgLKxqB1RFDkN/8W lsWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Nkgr/PILpuVC3sCWYta0XXo8hnwU8RgWZjFpRgXAELg=; b=kouPvdP43KGO5inOCOmhAmuufKHCHB8PbwBave3ZC11KXd8HpDhKJIWkcMuKKn1WHT ExXFGZ2FDyk4fNOq140V+gxAzMjUfCGWAlS3MBe8ZE785WOkdgSjSoElXiC9FLu+jAcx zUIC3K9JluyoYoU/mU9vKyeFepwuS3AqSL8TUL84PoP6O/uHLdpXBxPPycM/gEUFU2hE ITbiFFdGuDLwausy9Duat5uvsNcnG9W8A+r/mrxjlCWqejt/rpkvk51i8flxq6iY3iu4 WQ9k95ADMiSS5U0k17phYBQYPppCnTLF8CuFE0oUYdC2XIoGBg83Vlg5/PQY7+KMxCQg tn3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nsIQjMlh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t13-20020a170906178d00b007ad8bd5b636si9613686eje.377.2022.12.21.06.05.58; Wed, 21 Dec 2022 06:06:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nsIQjMlh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231206AbiLUOAW (ORCPT + 99 others); Wed, 21 Dec 2022 09:00:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229694AbiLUOAU (ORCPT ); Wed, 21 Dec 2022 09:00:20 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 025E2F58B; Wed, 21 Dec 2022 06:00:20 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id i187-20020a1c3bc4000000b003d1e906ca23so1601108wma.3; Wed, 21 Dec 2022 06:00:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Nkgr/PILpuVC3sCWYta0XXo8hnwU8RgWZjFpRgXAELg=; b=nsIQjMlh47JuKX0YRjs58BTfW1aBQ7t5ZpnD/DFRfzGo5NBhsoW9TqyXb1I4m7pgJz 7gwgdDC8ybyqdZYc3oI1t4qIXXm11MsB9Wnw0++hgtJIgfn0O5Omzdl/VLpn+LJlNaCR MLwsTeF9OqoFAPRpZU8yGNBJMdO5YuAIWj3zCzROLJESoeAdWwvEZilLucSAWglY+bv9 Gy0xn4Iv13/jCUtx2Bus2T4E90w3JWoXJ4aepFVAJkGthrGrdmigii0k207784ouqokB qCZRkdfhzTVykbbjlBDk5mD/IJ0mNi8zxZr2DyKF8EnIHuaeDD2RuJ/xhyckg6m39ke3 efhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Nkgr/PILpuVC3sCWYta0XXo8hnwU8RgWZjFpRgXAELg=; b=Yxzz7vrfVzDIEXQY2puBa02OHvkklGl88SksYi5FsCeMAdEgBnxqN7W/sjlixlVpdF x1tp9brDuN1l7yJaC5ihDZyPFKC8Yerr7z3wIozIhF1e0EsJTsQ9kERwT5ViQBZzvDOa 8TpwP68xIrChQTf4zI5GfzSl8pJBMwaOczmoALcvEQ1GYOd73PRt0IvLDkR1U9Jul5LU yDxkdqzb3yNPONvamhQ3P1kiKj6SkVA59Hr3SybU+Vy423kG9DM7IsN1GUI2wRCLV7DX f4qXhYlI810f760ZM5lXKIy5XTvziZHdO6EmZa9huVMokD77YJiJEtsCcIxxXQ1IZwSn 8frg== X-Gm-Message-State: AFqh2koUhPkD+HX2r2WFEIpkMANhi3jquY5EHKyhLm8yi6PtOgbfc9SM j3ndlfAUMCVLiez26mCC4dsSlB5eCsk= X-Received: by 2002:a05:600c:2252:b0:3d3:5d8b:7af with SMTP id a18-20020a05600c225200b003d35d8b07afmr1882310wmm.41.1671631218074; Wed, 21 Dec 2022 06:00:18 -0800 (PST) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id c12-20020a05600c0a4c00b003cfa3a12660sm7243731wmq.1.2022.12.21.06.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 06:00:17 -0800 (PST) From: Lorenzo Stoakes To: linux-block@vger.kernel.org, Dmitry Fomichev , Stefan Hajnoczi , "Michael S . Tsirkin" , Jason Wang , Paolo Bonzini , Jens Axboe Cc: Damien Le Moal , virtualization@lists.linux-foundation.org, virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org, Hannes Reinecke , Sam Li , Lorenzo Stoakes Subject: [PATCH] virtio-blk: avoid kernel panic on VIRTIO_BLK_F_ZONED check Date: Wed, 21 Dec 2022 14:00:12 +0000 Message-Id: <20221221140012.238494-1-lstoakes@gmail.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752832771180913976?= X-GMAIL-MSGID: =?utf-8?q?1752832771180913976?= virtio zoned block device support is added by commit 0562d7bf1604 ("virtio-blk: add support for zoned block devices") which adds VIRTIO_BLK_F_ZONED to the features array in virtio_blk.c but makes it conditional on CONFIG_BLK_DEV_ZONED. In it virtblk_probe() calls virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED) unconditionally, which invokes virtio_check_driver_offered_feature(). This function checks whether virtio_blk.feature_table (assigned to the static features array) contains the specified feature enum, and if not _causes a kernel panic_ via BUG(). This therefore means that failing to enable CONFIG_BLK_DEV_ZONED while using virtio is a guaranteed kernel panic. Fix the issue by making the feature test also conditional on CONFIG_BLK_DEV_ZONED. Signed-off-by: Lorenzo Stoakes --- drivers/block/virtio_blk.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.39.0 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index ff49052e26f7..34fdc141fb21 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1580,11 +1580,13 @@ static int virtblk_probe(struct virtio_device *vdev) virtblk_update_capacity(vblk, false); virtio_device_ready(vdev); +#ifdef CONFIG_BLK_DEV_ZONED if (virtio_has_feature(vdev, VIRTIO_BLK_F_ZONED)) { err = virtblk_probe_zoned_device(vdev, vblk, q); if (err) goto out_cleanup_disk; } +#endif /* CONFIG_BLK_DEV_ZONED */ dev_info(&vdev->dev, "blk config size: %zu\n", sizeof(struct virtio_blk_config));