Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp565459pxb; Tue, 14 Sep 2021 04:06:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjPXhJ1jXeH+hYhPyAo/xr7Y224oQGpcHGSe0IB81PeKigGujoRFLmHoxOdYr9Xb3bvmvP X-Received: by 2002:a50:d6d8:: with SMTP id l24mr18974968edj.297.1631617604463; Tue, 14 Sep 2021 04:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631617604; cv=none; d=google.com; s=arc-20160816; b=LIfAZdNFKXikVDlmrct8htxoGpGwoJ3w2AlZGXRxtIWaerh7qE00lZvZ2wSDyTuma9 M1BiwHUEojudQJ/p4jMlFrZ0fT4NUqaUOd5lI8Bypl0f3Y2ObpiuTP53QjhUDiajJAOZ KaangJ63z742+O06/0URx328JAhnVLaQaqkpApXWWVnoc+2wpkrfj/K5qyIVUY9jbCPB u+tzvH5kY854ZnRQoj+gAQ7nX8iWQDB4cBF7QBdxmRXMimwn5J2cfApQLRrCNKJISKXr jXfYKLI5qijib7i0XLlE/O/zHymronFQoM12EoFr4uDT6o1u96Zo0GBi7Scv4gN7od4Y INgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mMZLspAs4SibC8RtzDy4xBKwM9DL7s6XmwYmYiusX18=; b=e1zTzWb4shi4qVQQteizGOO4wAvSkxBi5rEL41OPIsgjZoettE+VYD8b77dZtSd+lT NRrd8nKmMFHWfcSv1Vs97Uh1bUeVhiQcwhjPc+sTE9g8DXLL7oHNM6KqsS2MKcMHVlQU zsZG5hzOqEyqVj83WtrlmwjC8fbrUb138wjg6QSCpJg8+50TrhNd8jjYW4xq48NAfU6V /xiHSXTgqhK7Nfyk0xDvXjh9Tj23oeCaVRJEMwkhjCi5dusrWIPJYeKZqyshoQSCsz4O +uF52OOgJbQyHpC1wSxQqF7Ja3WghDnM9lsBKLzN1XNr9WX5AqniBdXtqvxkPXTGdAuj kHyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=rNwoE9hF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv54si10138149ejc.58.2021.09.14.04.06.18; Tue, 14 Sep 2021 04:06:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=rNwoE9hF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231851AbhINLGA (ORCPT + 99 others); Tue, 14 Sep 2021 07:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231732AbhINLGA (ORCPT ); Tue, 14 Sep 2021 07:06:00 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2D1FC061574 for ; Tue, 14 Sep 2021 04:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=mMZLspAs4SibC8RtzDy4xBKwM9DL7s6XmwYmYiusX18=; b=rNwoE9hFA4si/ZyTkc3P2xDSE7 dcDCaJMft5fR4xVFBTYgKbPlTrZobXVQCFvH5slK9GNtC8AsiWSO1E52cxfHL+8hDcJzCnIU7bnO+ 5284nOCG0guLsFRtNKk9mOpa+t8kHLtFTlOqLF5cadZkcvqQYIQhTJYITteqcomdiUyCmoaczvSVd 3bUD9lxuc3YT+t2ug8Z+Mr0ptYmcX5blTE3UTp7QhWKR3vNK7bdpN3aI6Ik2v1hXccBUNiwH8cNqE 7FS0N0sS7q4CoyuNfKZozcRXEoLqjCQctkiifuggp9azW6hpMeitTSp8Yo6dePlYN8Ge4Ly83VSTj rAXlcRvA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mQ6DQ-00Ea8d-1B; Tue, 14 Sep 2021 11:03:20 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CE829300255; Tue, 14 Sep 2021 13:03:02 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A4AA62D0615DB; Tue, 14 Sep 2021 13:03:02 +0200 (CEST) Date: Tue, 14 Sep 2021 13:03:02 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: Jason Wang , mst@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, f.hetzelt@tu-berlin.de, david.kaplan@amd.com, konrad.wilk@oracle.com, Will Deacon , Boqun Feng , "Paul E. McKenney" Subject: Re: [PATCH 7/9] virtio-pci: harden INTX interrupts Message-ID: References: <20210913055353.35219-1-jasowang@redhat.com> <20210913055353.35219-8-jasowang@redhat.com> <875yv4f99j.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875yv4f99j.ffs@tglx> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 13, 2021 at 11:36:24PM +0200, Thomas Gleixner wrote: > That's the real problem and for that your barrier is at the wrong place > because you want to make sure that those stores are visible before the > store to intx_soft_enabled becomes visible, i.e. this should be: > > > /* Ensure that all preceeding stores are visible before intx_soft_enabled */ > smp_wmb(); > vp_dev->intx_soft_enabled = true; That arguably wants to be smp_store_release() instead of smp_wmb() :-) > Now Micheal is not really enthusiatic about the barrier in the interrupt > handler hotpath, which is understandable. > > As the device startup is not really happening often it's sensible to do > the following > > disable_irq(); > vp_dev->intx_soft_enabled = true; > enable_irq(); > > because: > > disable_irq() > synchronize_irq() > > acts as a barrier for the preceeding stores: > > disable_irq() > raw_spin_lock(desc->lock); > __disable_irq(desc); > raw_spin_unlock(desc->lock); > > synchronize_irq() > do { > raw_spin_lock(desc->lock); > in_progress = check_inprogress(desc); > raw_spin_unlock(desc->lock); > } while (in_progress); Here you rely on the UNLOCK+LOCK pattern because we have two adjacent critical sections (or rather, the same twice), which provides RCtso ordering, which is sufficient to make the below store: > > intx_soft_enabled = true; a RELEASE. still, I would suggest writing it at least using WRITE_ONCE() with a comment on. disable_irq(); /* * The above disable_irq() provides TSO ordering and as such * promotes the below store to store-release. */ WRITE_ONCE(intx_soft_enabled, true); enable_irq(); > In this case synchronize_irq() prevents the subsequent store to > intx_soft_enabled to leak into the __disable_irq(desc) section which in > turn makes it impossible for an interrupt handler to observe > intx_soft_enabled == true before the prerequisites which preceed the > call to disable_irq() are visible. > > Of course the memory ordering wizards might disagree, but if they do, > then we have a massive chase of ordering problems vs. similar constructs > all over the tree ahead of us. Your case, UNLOCK s + LOCK s, is fully documented to provide RCtso ordering. The more general case of: UNLOCK r + LOCK s, will shortly appear in documentation near you. Meaning we can forget about the details an blanket state that any UNLOCK followed by a LOCK (on the same CPU) will provide TSO ordering.