Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6781424iob; Wed, 11 May 2022 05:20:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt7y17l0e5owTqswnQeyPQnJpQhy4sbLhMmM4m0/skg5W2fhVm3+ZiRVhjEMm1Q/MbOjW0 X-Received: by 2002:a17:907:7f8e:b0:6f4:2d7c:1b75 with SMTP id qk14-20020a1709077f8e00b006f42d7c1b75mr23500569ejc.726.1652271642600; Wed, 11 May 2022 05:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652271642; cv=none; d=google.com; s=arc-20160816; b=bZCu7rq8nQgJcKq8vmE0GlDGNtSCinizEf5e+dm20bquaImBVBegQ4lbZ8ReOdBEp5 +wiLf9sCd+J/QHiUgs2I+lrbhOi1xZ2jnQdwAhGHQ+AbFcd0ALnPfSKVgx7q/GfsMjrd xeGttaozXRAziu/HE7wqYppAzekZDKTYKWU4JBszmrYBdLKYzo6sIGK5yeBxMUuhzpac zVsXVa+oOInDFLfDe0zuhJd1eI82dl34l7rqcdiNVkM9KxCRKgnW9aRi5UXzM9wsgVyW Xkyd+q5xhCQdc5ZabixUPkELRO46qlxckqhpr1ObLcFJfaIb9CKW0XURtqfCghi6xof1 +iGw== 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=ehAdFMHQin7sBzIsjKPJMBNM1tNTUowv6Coiiw6E2YI=; b=PoOLn+K12J6IxR3PzS9haRURdjWauu6Q1ojpIhZI8QnwNafbk7wmE7hiQnNsfgrV79 rIziJ8xfjwBin2vj33M+EDybPeiEis3vnX+h4JJC9/qbrdBtY/aF1tERZAYBa0e6tjd/ Mm5SpL1fHGr4ke9RPdDp36JrNxyoYIs/kLJbW80fTO9fZzd11S6QWywyE+Ywi0VJzfa9 RoRGp3EXKGfO/Kp/E/2o9NoGAN24xkktEtjWaov0GzM5vWkWKF9pfQfcVjyeWp4Utgdz rD2FMZMTmipZXikDmA2ZJN7H99bSq6CdkHPPRVmsoQLcgzMi5Rqa43Sv+KYqJho29tmi tEAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bKKCg1m8; 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 sd22-20020a170906ce3600b006e07d5f6986si2271726ejb.933.2022.05.11.05.20.16; Wed, 11 May 2022 05:20:42 -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=bKKCg1m8; 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 S230017AbiEKJ2L (ORCPT + 99 others); Wed, 11 May 2022 05:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbiEKJ2D (ORCPT ); Wed, 11 May 2022 05:28:03 -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 6C2B2E5299 for ; Wed, 11 May 2022 02:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652261280; 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=ehAdFMHQin7sBzIsjKPJMBNM1tNTUowv6Coiiw6E2YI=; b=bKKCg1m8r9y+gSruvmXUWmM9bQd7gUeWSwJ4cyCeE5kMK1sE79iAtWHBKmgyKdLmNsdEuO /+UZVlyZ6/Z2ATVDMJ3vDHHqUt9j2XXyv0QTG9cn0MuItUGTND3mQKxSe+9Tu/V48fcLxv M8YaiMo8PgiU97TbPh2ZowubOSlaVhg= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-307-tDcr2LFbMRy9maZKk_mODQ-1; Wed, 11 May 2022 05:27:57 -0400 X-MC-Unique: tDcr2LFbMRy9maZKk_mODQ-1 Received: by mail-lf1-f71.google.com with SMTP id a13-20020a19ca0d000000b0047233f64994so584893lfg.14 for ; Wed, 11 May 2022 02:27:57 -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=ehAdFMHQin7sBzIsjKPJMBNM1tNTUowv6Coiiw6E2YI=; b=SVKcJFcUzaST8Ba+grHjZMtJcv4x2zbK0JVffH3iCGICX829JNt2qG5GbFnphrMhWh ar/TY0UYB+/GHFjrrCD59o73FtNOUOe3hJw61nRbkg0MKnaZQk6Xvg8GU4YI4iaVSmj6 YTXGP7PlLKPjqzYGxIaPK2QNNlMdaTFq6gX4lAj7w/LX1zYHYUyAKTLxXhSGVEW9g2YK hXUF1KQuIZ6jh7YJgHLhA6F/EuRZLZwLPGIVmAXHmXAAE9yVcq7s2pi+kHmFPv+1Saro v6V3Q9E+8rP/HPro/RtaHcr7wNJ7sZPBUwQrVKQPhOhE9cgz+pL3INvNKJbBZP99qyTH FALA== X-Gm-Message-State: AOAM530yl4f8zQsOhRGEk1RCEAkpiVI+whvF+lcaRxbq4eAK9XMclYct zSMq2Qav9bSYDiQijcE9CtcxkTL4L1mzwzMvqEgWATwe6WaUAvThyWTENBvyz3rmZNoAqFVfelK LTq4CsEp4V4X5cLwMeDUsxnf60QaClB/KW54/W57Q X-Received: by 2002:a2e:b057:0:b0:24f:2668:833b with SMTP id d23-20020a2eb057000000b0024f2668833bmr16381999ljl.300.1652261276012; Wed, 11 May 2022 02:27:56 -0700 (PDT) X-Received: by 2002:a2e:b057:0:b0:24f:2668:833b with SMTP id d23-20020a2eb057000000b0024f2668833bmr16381981ljl.300.1652261275822; Wed, 11 May 2022 02:27:55 -0700 (PDT) MIME-Version: 1.0 References: <20220507071954.14455-1-jasowang@redhat.com> <20220507071954.14455-9-jasowang@redhat.com> <20220510072833-mutt-send-email-mst@kernel.org> <87o804bgrl.fsf@redhat.com> In-Reply-To: <87o804bgrl.fsf@redhat.com> From: Jason Wang Date: Wed, 11 May 2022 17:27:44 +0800 Message-ID: Subject: Re: [PATCH V4 8/9] virtio: harden vring IRQ To: Cornelia Huck Cc: "Michael S. Tsirkin" , virtualization , linux-kernel , Thomas Gleixner , Peter Zijlstra , "Paul E. McKenney" , Marc Zyngier , Halil Pasic , eperezma , Cindy Lu , Stefano Garzarella , Xuan Zhuo 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 Wed, May 11, 2022 at 4:44 PM Cornelia Huck wrote: > > On Wed, May 11 2022, Jason Wang wrote: > > > On Tue, May 10, 2022 at 7:32 PM Michael S. Tsirkin wrote: > >> > >> On Sat, May 07, 2022 at 03:19:53PM +0800, Jason Wang wrote: > >> > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h > >> > index d8a2340f928e..23f1694cdbd5 100644 > >> > --- a/include/linux/virtio_config.h > >> > +++ b/include/linux/virtio_config.h > >> > @@ -256,6 +256,18 @@ void virtio_device_ready(struct virtio_device *dev) > >> > unsigned status = dev->config->get_status(dev); > >> > > >> > BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK); > >> > + > >> > + /* > >> > + * The virtio_synchronize_cbs() makes sure vring_interrupt() > >> > + * will see the driver specific setup if it sees vq->broken > >> > + * as false. > >> > + */ > >> > + virtio_synchronize_cbs(dev); > >> > >> since you mention vq->broken above, maybe add > >> "set vq->broken to false" > > > > Ok. > > > >> > >> > + __virtio_unbreak_device(dev); > >> > + /* > >> > + * The transport is expected ensure the visibility of > >> > >> to ensure > > > > Will fix. > > > >> > >> > + * vq->broken > >> > >> let's add: "visibility by vq callbacks" > > > > Sure. > > > >> > >> > before setting VIRTIO_CONFIG_S_DRIVER_OK. > >> > + */ > >> > >> > >> Can I see some analysis of existing transports showing > >> this is actually the case for them? > > > > Yes. > > > >> And maybe add a comment near set_status to document the > >> requirement. > > > > For PCI and MMIO, we can quote the memory-barriers.txt or explain that > > wmb() is not needed before the MMIO writel(). > > For CCW, it looks not obvious, it looks to me the IO was submitted via > > __ssch() which has an inline assembly. Cornelia and Hali, could you > > help me to understand if and how did virtio_ccw_set_status() can > > ensure the visibility of the previous driver setup and vq->broken > > here? > > I'm not sure I completely understand the question here, but let me try: It's something like the following case: CPU 0: vq->broken = false CPU 0: set_status(DRIVER_OK) CPU 1: vring_interrupt() { if (vq->broken) return IRQ_NONE; } We need to make sure the CPU 1 sees the vq->broken if the interrupt is raised after DRVER_OK. For PCI, we use MMIO of writel() for set_status(), a wmb() is not needed in this case according to memory-barriers.txt. " Note that, when using writel(), a prior wmb() is not needed to guarantee that the cache coherent memory writes have completed before writing to the MMIO region. " So CPU 1 will see the broken as false. > > virtio_ccw_set_status() uses a channel command to set the status, with > the interesting stuff done inside ccw_io_helper(). That function > - takes the subchannel lock, disabling interrupts Then it is, for x86 the operation to disable interrupt is a full barrier. I guess this should apply to other architecture like s390. I see a stnsm is used in this case but a quick google doesn't tell me if it's a barrier. If this is true. The vring_interrupt will see broken as false. > - does the ssch; this instruction will fail if there's already another > I/O in progress, or an interrupt is pending for the subchannel; on > success, it is guaranteed that we'll get an interrupt eventually I guess ssch might imply a barrier as well, otherwise we may need a lot of barriers before this. Thanks > - unlock the subchannel, and wait for the interupt handler to eventually > process the interrupt, so I guess it should see the vq->broken value? > > If the I/O fails, virtio_ccw_set_status() will revert its internal > status to the old value. > > > > > > Thanks > > > >> > >> > dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK); > >> > } >