Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp506975pxb; Tue, 14 Sep 2021 02:35:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXmtnMifCkyLgfZAcwk5wHg5FRWjXVsDnsxJ5LGx0ZjAs1UGPiMGgMHbGqZF48r/WsY03s X-Received: by 2002:a5d:9da4:: with SMTP id ay36mr13366552iob.153.1631612158207; Tue, 14 Sep 2021 02:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631612158; cv=none; d=google.com; s=arc-20160816; b=jbnXKNPLnmtRMEb212F7HYFbfoqLC27R2ZaDUZNqRiRz3DeYR1pTHekYSbtToHW22a Wtmk4VR6PDlCB7Uj01Qm7+GKDSyqP5ZeKIf1QPzeHZ3ZjRyZLIWJxR+nC4D5uMFel8RC WbqdLalEoE8A4MTtflZw3H6ZcW+szJdyGEG1iI3Fv9au03klq2vMXlxEJqo535E7zLSp HkvXQLyEp423ezQ7vYP0AFPVWBvd3eDhlT86CEeowzs0pAtpWKmkLSnlIx7ljgxYcGBP FAAyb0P8p6/C/ZFXlJFQRwJ8Cnzh+7nbSWatjG+uxyDwYsJN5kv7I8S/RLnxCIow3ZTW NdBw== 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=hMAVv0XT+E1ILWD7RS17ZuL6RZs23nNagE+ZxXeUmc4=; b=JKshHHVlhI4hDo7hHpCstQFcQHt/IpjI9VeShYVIr2ZTLLbgiXJeQhOxxi8jEi2h+p RXIr/N2N7HFyagp0fJ8RebcNZpVTPkq1bxks6okO0LJPkMM6dEMA92qSdQcHwPfConpW IfdA7cEqEC154NfUPPXh7d5G1oM0rAQbgjoEKf+gnd7BvMpDfuvsXR37sVGLcZBijfk9 EytjXo1eJ5FpndhUpIrxCslT/zuIRLhbYX9gE8NK4r5TG4EcfFCgGYaNYiQskK5X8f4G gBQEVvdYLTEoyn0bOCR4JcQs16NlUcZATelGr4I1yTnS1InzFBZE+FR4kB6Li+C8kTdU sIcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DfhK2XQP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si1040382ili.160.2021.09.14.02.35.46; Tue, 14 Sep 2021 02:35:58 -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=@gmail.com header.s=20210112 header.b=DfhK2XQP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbhINJf4 (ORCPT + 99 others); Tue, 14 Sep 2021 05:35:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbhINJfz (ORCPT ); Tue, 14 Sep 2021 05:35:55 -0400 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E104BC061574 for ; Tue, 14 Sep 2021 02:34:38 -0700 (PDT) Received: by mail-il1-x12d.google.com with SMTP id b15so12819363ils.10 for ; Tue, 14 Sep 2021 02:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hMAVv0XT+E1ILWD7RS17ZuL6RZs23nNagE+ZxXeUmc4=; b=DfhK2XQPq77fyylJZQ6SV9Tt0LGuzDR4qtbIiJf7rBrsCGFNdpeAejKoqrCDd66/lF pbBfFW6GAaUaEiEhXv/kxgaoTiR4gOMv5Zi+Bvh8KfbmwhkXiFKLLq5Q+Wb5gI4Go1PN w0phzrNI//UhNz13RTgymvcPwbJIlST/X/Y8Bqc+n7IOd1PswOjwP77lRbUKukQxiVdt CPu68BWokEqnslEps5io/YtGIwK6PoexZJHmUREQRXORnG/D0UKudbJ5mq/Q523Nbnrm MI9bgAmT6P7gA4KBOag52QslmNasWIaXxgx7ScOxXUTzJUExKPZIheLeK7NWdHFjKYam h0cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hMAVv0XT+E1ILWD7RS17ZuL6RZs23nNagE+ZxXeUmc4=; b=OoCGqWv5E3yHK0FLeOdQC7HA8iu2xN1fx8h3ORlC7CQ3r2UUf/XG75QYp61OTnwbLH qELBzf6a33cC5sySER2NfqcaRjRr6130uf18CrdkHcD25wcxjLqg6yBhU6eAuIbnuFd7 Zm5hGYBIVxVfaLz/IGfA3TCffDtvQdKgXUZ6EJC5Ve0hUexBqFtYBAK6JhipsDpoAN3T Y6yLs+a2j6fHEYnVkQOsfcW7PJ4wsXAwMA17qFnp4Cd9UBc1EsFc7qTm4/NaOVMBwgri /+PJWS6p3FtEKdqFTASV/L9UQagykD4AiEIo7D4BzGL8YIXa/rSucbGr+nWIyAf9pJyJ D/eg== X-Gm-Message-State: AOAM530yli+4aknYMHWMEzAbDdvjt/j8bcvYKjhGEdZKQjiDzsvVxFkA 9FZXs7ZQbQhDnBrfZE5AHuc= X-Received: by 2002:a05:6e02:e53:: with SMTP id l19mr4706527ilk.217.1631612078377; Tue, 14 Sep 2021 02:34:38 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id g13sm6557821ile.68.2021.09.14.02.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 02:34:37 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id E839427C0054; Tue, 14 Sep 2021 05:34:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 14 Sep 2021 05:34:36 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudegledgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhepvdelieegudfggeevjefhjeevueevieetjeeikedvgfejfeduheefhffggedv geejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsg hoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieeg qddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigi hmvgdrnhgrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Sep 2021 05:34:34 -0400 (EDT) Date: Tue, 14 Sep 2021 17:34:31 +0800 From: Boqun Feng 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, Peter Zijlstra , Will Deacon , "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: [...] > 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); > > 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. > Right. In our memory model, raw_spin_unlock(desc->lock) + raw_spin_lock(desc->lock) provides the so-call RCtso ordering, that is for the following code: A ... raw_spin_unlock(desc->lock); ... raw_spin_lock(desc->lock); ... B Memory accesses A and B will not be reordered unless A is a store and B is a load. Such an ordering guarantee fulfils the requirement here. For more information, see the LOCKING section of tools/memory-model/Documentation/explanation.txt Regards, Boqun > 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. > > From the interrupt perspective the sequence: > > disable_irq(); > vp_dev->intx_soft_enabled = true; > enable_irq(); > > is perfectly fine as well. Any interrupt arriving during the disabled > section will be reraised on enable_irq() in hardware because it's a > level interrupt. Any resulting failure is either a hardware or a > hypervisor bug. > > Thanks, > > tglx