From mboxrd@z Thu Jan 1 00:00:00 1970 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 1F0F5C43334 for ; Tue, 21 Jun 2022 09:16:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348053AbiFUJQn (ORCPT ); Tue, 21 Jun 2022 05:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348259AbiFUJQl (ORCPT ); Tue, 21 Jun 2022 05:16:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B45AC19FB1 for ; Tue, 21 Jun 2022 02:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655802999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xE1eQ7rSn112nzVYfSbRI8lphkzHLYug/d5ePoCHz4Q=; b=Ra5Vu20mK7iDqxAvq4gOZRFAHvO78FAzFR2c8XJKyKdVgeo60CSaYZ+BDv1z8J89MGzZtB 54p9eJ25vbnyb3GgjwFoW/bCOqu2YxdT2BegD1S4sOXVR+Ap5dqidkbscW54xqmSKlAJfa AUqwqeKqDiIj9XDeOeoA0bxBCm7g7Ck= 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-73-ETFWK0YNNTm6xaO8-uYDiQ-1; Tue, 21 Jun 2022 05:16:34 -0400 X-MC-Unique: ETFWK0YNNTm6xaO8-uYDiQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADBB8811E81; Tue, 21 Jun 2022 09:16:33 +0000 (UTC) Received: from localhost (unknown [10.39.193.229]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5593C1121314; Tue, 21 Jun 2022 09:16:33 +0000 (UTC) From: Cornelia Huck To: Jason Wang , pasic@linux.ibm.com, jasowang@redhat.com, mst@redhat.com Cc: gor@linux.ibm.com, borntraeger@de.ibm.com, agordeev@linux.ibm.com, linux-s390@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] virtio: disable notification hardening by default In-Reply-To: <20220620024158.2505-1-jasowang@redhat.com> Organization: Red Hat GmbH References: <20220620024158.2505-1-jasowang@redhat.com> User-Agent: Notmuch/0.36 (https://notmuchmail.org) Date: Tue, 21 Jun 2022 11:16:31 +0200 Message-ID: <87y1xq8jgw.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 20 2022, Jason Wang wrote: > 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 > --- > Changes since V1: > - tweak the Kconfig prompt > - don't hold spinlock for IRQ path in s390 > --- > drivers/s390/virtio/virtio_ccw.c | 4 ++++ > drivers/virtio/Kconfig | 11 +++++++++++ > drivers/virtio/virtio.c | 2 ++ > drivers/virtio/virtio_ring.c | 12 ++++++++++++ > include/linux/virtio_config.h | 2 ++ > 5 files changed, 31 insertions(+) > > diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c > index 97e51c34e6cf..89bbf7ccfdd1 100644 > --- a/drivers/s390/virtio/virtio_ccw.c > +++ b/drivers/s390/virtio/virtio_ccw.c > @@ -1136,8 +1136,10 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev, > vcdev->err = -EIO; > } > virtio_ccw_check_activity(vcdev, activity); > +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION > /* Interrupts are disabled here */ > read_lock(&vcdev->irq_lock); Should we add a comment that this pairs with virtio_ccw_synchronize_cbs()? Just to avoid future headscratching as to why this lock is only needed when notification hardening is enabled. > +#endif > for_each_set_bit(i, indicators(vcdev), > sizeof(*indicators(vcdev)) * BITS_PER_BYTE) { > /* The bit clear must happen before the vring kick. */ > @@ -1146,7 +1148,9 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev, > vq = virtio_ccw_vq_by_ind(vcdev, i); > vring_interrupt(0, vq); > } > +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION > read_unlock(&vcdev->irq_lock); > +#endif > if (test_bit(0, indicators2(vcdev))) { > virtio_config_changed(&vcdev->vdev); > clear_bit(0, indicators2(vcdev)); > diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig > index b5adf6abd241..96ec56d44b91 100644 > --- a/drivers/virtio/Kconfig > +++ b/drivers/virtio/Kconfig > @@ -35,6 +35,17 @@ menuconfig VIRTIO_MENU > > if VIRTIO_MENU > > +config VIRTIO_HARDEN_NOTIFICATION > + bool "Harden virtio notification" > + help > + Enable this to harden the device notifications and supress > + the ones that are illegal. "...and suppress those that happen at a time where notifications are illegal." ? > + > + Experimental: not all drivers handle this correctly at this > + point. "Note that several drivers still have bugs that may cause crashes or hangs when correct handling of notifications is enforced; depending on the subset of drivers and devices you use, this may or may not work." Or is that too verbose? > + > + If unsure, say N. > + > config VIRTIO_PCI > tristate "PCI driver for virtio devices" > depends on PCI The ifdeffery looks a big ugly, but I don't have a better idea. From mboxrd@z Thu Jan 1 00:00:00 1970 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 smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75E93CCA473 for ; Tue, 21 Jun 2022 09:16:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id E983F83E79; Tue, 21 Jun 2022 09:16:42 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org E983F83E79 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L8EIsaXX X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PKEjeadvhK7W; Tue, 21 Jun 2022 09:16:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 7691D831A5; Tue, 21 Jun 2022 09:16:41 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 7691D831A5 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4A88AC0032; Tue, 21 Jun 2022 09:16:41 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 88318C002D for ; Tue, 21 Jun 2022 09:16:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 550C760D5E for ; Tue, 21 Jun 2022 09:16:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 550C760D5E Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=L8EIsaXX X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id T_id9SVacgpJ for ; Tue, 21 Jun 2022 09:16:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 725AE605E3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 725AE605E3 for ; Tue, 21 Jun 2022 09:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655802997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xE1eQ7rSn112nzVYfSbRI8lphkzHLYug/d5ePoCHz4Q=; b=L8EIsaXXy0GcVJkiihGfI7mLeFU7QIRQ/RXKFefjD0QE6ADT3Bv3pYj3IdBmDdXJCJmRyZ qSv3imLpqhKL9BqNhD2udd4MHXRMPLe2PRXa5Bbbv2rytYsW+9mZ/uRBKMSO2l/NBtdA6d N+kzfUNRy1x5MsLmYkiMaYtur718eFo= 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-73-ETFWK0YNNTm6xaO8-uYDiQ-1; Tue, 21 Jun 2022 05:16:34 -0400 X-MC-Unique: ETFWK0YNNTm6xaO8-uYDiQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADBB8811E81; Tue, 21 Jun 2022 09:16:33 +0000 (UTC) Received: from localhost (unknown [10.39.193.229]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5593C1121314; Tue, 21 Jun 2022 09:16:33 +0000 (UTC) From: Cornelia Huck To: Jason Wang , pasic@linux.ibm.com, jasowang@redhat.com, mst@redhat.com Subject: Re: [PATCH V2] virtio: disable notification hardening by default In-Reply-To: <20220620024158.2505-1-jasowang@redhat.com> Organization: Red Hat GmbH References: <20220620024158.2505-1-jasowang@redhat.com> User-Agent: Notmuch/0.36 (https://notmuchmail.org) Date: Tue, 21 Jun 2022 11:16:31 +0200 Message-ID: <87y1xq8jgw.fsf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Cc: linux-s390@vger.kernel.org, gor@linux.ibm.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, borntraeger@de.ibm.com, agordeev@linux.ibm.com X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Mon, Jun 20 2022, Jason Wang wrote: > 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 > --- > Changes since V1: > - tweak the Kconfig prompt > - don't hold spinlock for IRQ path in s390 > --- > drivers/s390/virtio/virtio_ccw.c | 4 ++++ > drivers/virtio/Kconfig | 11 +++++++++++ > drivers/virtio/virtio.c | 2 ++ > drivers/virtio/virtio_ring.c | 12 ++++++++++++ > include/linux/virtio_config.h | 2 ++ > 5 files changed, 31 insertions(+) > > diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c > index 97e51c34e6cf..89bbf7ccfdd1 100644 > --- a/drivers/s390/virtio/virtio_ccw.c > +++ b/drivers/s390/virtio/virtio_ccw.c > @@ -1136,8 +1136,10 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev, > vcdev->err = -EIO; > } > virtio_ccw_check_activity(vcdev, activity); > +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION > /* Interrupts are disabled here */ > read_lock(&vcdev->irq_lock); Should we add a comment that this pairs with virtio_ccw_synchronize_cbs()? Just to avoid future headscratching as to why this lock is only needed when notification hardening is enabled. > +#endif > for_each_set_bit(i, indicators(vcdev), > sizeof(*indicators(vcdev)) * BITS_PER_BYTE) { > /* The bit clear must happen before the vring kick. */ > @@ -1146,7 +1148,9 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev, > vq = virtio_ccw_vq_by_ind(vcdev, i); > vring_interrupt(0, vq); > } > +#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION > read_unlock(&vcdev->irq_lock); > +#endif > if (test_bit(0, indicators2(vcdev))) { > virtio_config_changed(&vcdev->vdev); > clear_bit(0, indicators2(vcdev)); > diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig > index b5adf6abd241..96ec56d44b91 100644 > --- a/drivers/virtio/Kconfig > +++ b/drivers/virtio/Kconfig > @@ -35,6 +35,17 @@ menuconfig VIRTIO_MENU > > if VIRTIO_MENU > > +config VIRTIO_HARDEN_NOTIFICATION > + bool "Harden virtio notification" > + help > + Enable this to harden the device notifications and supress > + the ones that are illegal. "...and suppress those that happen at a time where notifications are illegal." ? > + > + Experimental: not all drivers handle this correctly at this > + point. "Note that several drivers still have bugs that may cause crashes or hangs when correct handling of notifications is enforced; depending on the subset of drivers and devices you use, this may or may not work." Or is that too verbose? > + > + If unsure, say N. > + > config VIRTIO_PCI > tristate "PCI driver for virtio devices" > depends on PCI The ifdeffery looks a big ugly, but I don't have a better idea. _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization