From nobody Mon Apr 27 04:36:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08656CCA479 for ; Fri, 17 Jun 2022 07:26:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380401AbiFQH0h (ORCPT ); Fri, 17 Jun 2022 03:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380260AbiFQH0f (ORCPT ); Fri, 17 Jun 2022 03:26:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BCA5B663C2 for ; Fri, 17 Jun 2022 00:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655450793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=v1OzxUTdVxm25FyB56AWfj0qHOMIBXGWkHMr1WYBfyA=; b=YlDQbLD5mxGk9dXeh8Ry7a0odyQKd0eS8SqJxWBXey+br/1I583PHGhOdt0ry/k9rsRLmv XFArbnigerbfR6gYgSSWK7qUenZBWSwxyS33hoaEnUhQwPH2pOAaW8oeZ4L9Jognmcr9Sj f7mMZB60+RBk5VWaknhWoTpoM5XX+uE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-278-h6hkhi_fM2KAFgmeglqjfw-1; Fri, 17 Jun 2022 03:26:31 -0400 X-MC-Unique: h6hkhi_fM2KAFgmeglqjfw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 180A4101AA46; Fri, 17 Jun 2022 07:26:31 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-87.pek2.redhat.com [10.72.13.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0694910725; Fri, 17 Jun 2022 07:26:28 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] virtio: disable notification hardening by default Date: Fri, 17 Jun 2022 15:26:26 +0800 Message-Id: <20220617072626.30503-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We try to harden virtio device notifications in 8b4ec69d7e09 ("virtio: harden vring IRQ"). It works with the assumption that the driver or core can properly call virtio_device_ready() at the right place. Unfortunately, this seems to be not true and uncover various bugs of the existing drivers, mainly the issue of using virtio_device_ready() incorrectly. So let's having a Kconfig option and disable it by default. It gives us a breath to fix the drivers and then we can consider to enable it by default. Signed-off-by: Jason Wang --- drivers/virtio/Kconfig | 6 ++++++ drivers/virtio/virtio.c | 2 ++ drivers/virtio/virtio_ring.c | 12 ++++++++++++ include/linux/virtio_config.h | 2 ++ 4 files changed, 22 insertions(+) diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index b5adf6abd241..b059c39af3d4 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -35,6 +35,12 @@ menuconfig VIRTIO_MENU =20 if VIRTIO_MENU =20 +config VIRTIO_HARDEN_NOTIFICATION + bool "Harden virtio notification" + help + Enable to this to harden the device notifications and + supress the ones that are illegal. + config VIRTIO_PCI tristate "PCI driver for virtio devices" depends on PCI diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index ef04a96942bf..21dc08d2f32d 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -220,6 +220,7 @@ static int virtio_features_ok(struct virtio_device *dev) * */ void virtio_reset_device(struct virtio_device *dev) { +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION /* * The below virtio_synchronize_cbs() guarantees that any * interrupt for this line arriving after @@ -228,6 +229,7 @@ void virtio_reset_device(struct virtio_device *dev) */ virtio_break_device(dev); virtio_synchronize_cbs(dev); +#endif =20 dev->config->reset(dev); } diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 13a7348cedff..d9d3b6e201fb 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1688,7 +1688,11 @@ static struct virtqueue *vring_create_virtqueue_pack= ed( vq->we_own_ring =3D true; vq->notify =3D notify; vq->weak_barriers =3D weak_barriers; +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION vq->broken =3D true; +#else + vq->broken =3D false; +#endif vq->last_used_idx =3D 0; vq->event_triggered =3D false; vq->num_added =3D 0; @@ -2135,9 +2139,13 @@ irqreturn_t vring_interrupt(int irq, void *_vq) } =20 if (unlikely(vq->broken)) { +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION dev_warn_once(&vq->vq.vdev->dev, "virtio vring IRQ raised before DRIVER_OK"); return IRQ_NONE; +#else + return IRQ_HANDLED; +#endif } =20 /* Just a hint for performance: so it's ok that this can be racy! */ @@ -2180,7 +2188,11 @@ struct virtqueue *__vring_new_virtqueue(unsigned int= index, vq->we_own_ring =3D false; vq->notify =3D notify; vq->weak_barriers =3D weak_barriers; +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION vq->broken =3D true; +#else + vq->broken =3D false; +#endif vq->last_used_idx =3D 0; vq->event_triggered =3D false; vq->num_added =3D 0; diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 9a36051ceb76..d15c3cdda2d2 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -257,6 +257,7 @@ void virtio_device_ready(struct virtio_device *dev) =20 WARN_ON(status & VIRTIO_CONFIG_S_DRIVER_OK); =20 +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION /* * The virtio_synchronize_cbs() makes sure vring_interrupt() * will see the driver specific setup if it sees vq->broken @@ -264,6 +265,7 @@ void virtio_device_ready(struct virtio_device *dev) */ virtio_synchronize_cbs(dev); __virtio_unbreak_device(dev); +#endif /* * The transport should ensure the visibility of vq->broken * before setting DRIVER_OK. See the comments for the transport --=20 2.25.1