Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3645944iog; Tue, 21 Jun 2022 03:04:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uw64pUS1de9AR/J8CRSxb5K+92HsXj+WQT7R/FDdexYDyJCd9mkBQhVdK0CG5tWm3KJONn X-Received: by 2002:a17:907:7b8d:b0:722:dcae:6417 with SMTP id ne13-20020a1709077b8d00b00722dcae6417mr4201367ejc.225.1655805879779; Tue, 21 Jun 2022 03:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655805879; cv=none; d=google.com; s=arc-20160816; b=Yt4rn5XR73NbC5PjvYgRdDO5eWaXmBZFlQnzSYINYKJozJ/XXWDC8hi5nnn0jV+NTe kdOJmKZLUsaMkPfV9wLksp4Nna7p3BxYekRuGExS4gwNeov2sLdqcuzaGzlxOE/0WPZJ c009vfrtXyki+6aQOGuFRVAYM6WJpHv4HIdWonD8oVBXxR1VgMhRhQ1YRvXFbmLe2jTb HAOJEwQAJcRgqOnD1jRfCRkiyKy1WfZtl0Se9oAsQOxkzHgHfzuq3k49IN71noECKxpv vXaigK4NSLomvmps7HL69a8RV2m9FvPVMqRp8ciazJFKIZL3JrmSVadwDY4tKIUnb72h ENaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=NcXrei2y1YJ8W4iMhBTE/8lC+VPJchskiCKRKCR2d9s=; b=zGf3c6vNlUvXjQCnu6JLdQ2h0eVHqlWeeFwbRI8sbgyE76FkwwwMvYOT3pdsh7439I HF69Yx7FxfBx8OXzG7hLUbG9Kb8C8OnoVw1UOmmkLLVKCOSJ6Yfi3Bw2jKfuZ4wb6AOr dRbnhmxkcZAEn37qRCHSMeE5T1z3P4OtqPj1MDJpL5x4XQpXjDFyoJz2iJOZQsv7a2Sl or22vkAjUlSwBahmb7yfm98TyIaq1CVv4VrgQkkO8LxOU1KIrc8v60mj56W8t8PkIko4 SOIl46UBgZiJ48+TJsuhqTW5dab2iXM/wSfA02S6KBiwF5wgOSfKH8ilm4/1uhKcPbSN I9OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="i4KS9I/2"; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a170906015400b00722e7e8b484si226861ejh.625.2022.06.21.03.04.14; Tue, 21 Jun 2022 03:04:39 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b="i4KS9I/2"; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349106AbiFUJgk (ORCPT + 99 others); Tue, 21 Jun 2022 05:36:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349088AbiFUJgj (ORCPT ); Tue, 21 Jun 2022 05:36:39 -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 BC2832715F for ; Tue, 21 Jun 2022 02:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655804197; 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=NcXrei2y1YJ8W4iMhBTE/8lC+VPJchskiCKRKCR2d9s=; b=i4KS9I/2XQCQTAPK5aPHsCn79CcE0vQYaDZSk40VxSdne0XByS80xZ+v0Z0EtQnqFkr3bm iPzeBE3CF3bygg25ueG/zQFKSriJsrUf00uPzCZG/Wtvf7/zX9AnF2sdvHWjrOZNXHQQca vsnla0Rc2ugbC/wNEO2/y9MDyZSbGJo= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-8MF_foIyMxydEE8DZvB-3Q-1; Tue, 21 Jun 2022 05:36:36 -0400 X-MC-Unique: 8MF_foIyMxydEE8DZvB-3Q-1 Received: by mail-lf1-f69.google.com with SMTP id j3-20020a05651231c300b0047dbea7b031so6680886lfe.19 for ; Tue, 21 Jun 2022 02:36:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NcXrei2y1YJ8W4iMhBTE/8lC+VPJchskiCKRKCR2d9s=; b=hXyly7YuWzGPE5mQh9+QN1VlDUuhM6tsGE4eTNuGuWpbO91wLRaVl72YtEnFLq6l+m LBKLXPK/bJUBPoJJ9qnTYoYos2GfdX0FItLFSKvmpCoZok1nvMCa+J1VBzr+saN+Tz/N P4vLJxyMV1TZqmTGkFFRZKxtoNRdCPFeMNRw8Xsh91hhDZj9OJEFnG+wrkDP5jF0FHmM scWcZOJiVofdHmw8eNoprhzlwqggth0OFX6172TQz/7NoTliG3jEwUiBsc4J9GFUnoLs rXAqYr7pyxkGQ2v92pbyxt2Tfn7ne6B7XEJEwP49qwnSxRwxQ/Mau5JEybepkCqKxJIb o6kw== X-Gm-Message-State: AJIora/370UFiRsQDx19O9DH98YVvWn9hC/mLK2kDWifmYjDHMm3uXeK 8mUFbdrA73ilx4UN5KM6CvkZIWRYcsPW3lxo0AR1Qcf60mDOSn4ozkIFJcvFfTVGnU9ycHAxthP G1UmVG0fc2C/iNCx9971cO43t3iXWWXvbnSpym5du X-Received: by 2002:a05:6512:13a5:b0:47d:c1d9:dea8 with SMTP id p37-20020a05651213a500b0047dc1d9dea8mr16179015lfa.442.1655804194871; Tue, 21 Jun 2022 02:36:34 -0700 (PDT) X-Received: by 2002:a05:6512:13a5:b0:47d:c1d9:dea8 with SMTP id p37-20020a05651213a500b0047dc1d9dea8mr16178998lfa.442.1655804194646; Tue, 21 Jun 2022 02:36:34 -0700 (PDT) MIME-Version: 1.0 References: <20220620024158.2505-1-jasowang@redhat.com> <87y1xq8jgw.fsf@redhat.com> In-Reply-To: <87y1xq8jgw.fsf@redhat.com> From: Jason Wang Date: Tue, 21 Jun 2022 17:36:23 +0800 Message-ID: Subject: Re: [PATCH V2] virtio: disable notification hardening by default To: Cornelia Huck Cc: Halil Pasic , mst , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , linux-s390@vger.kernel.org, virtualization , kvm , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On Tue, Jun 21, 2022 at 5:16 PM Cornelia Huck wrote: > > 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. Fine. > > > +#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." ? Ok. > > > + > > + 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? Looks fine. > > > + > > + 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. I guess you meant the ccw part, I leave the spinlock here in V1, but Michael prefers to have that. In the future, we may consider removing that, one possible way is to have a per driver boolean for the hardening. Tanks >