[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 03/10] xen/arm: smmuv3: Ensure queue is read after updating prod pointer


  • To: Rahul Singh <Rahul.Singh@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Tue, 6 Sep 2022 14:45:13 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6z8KUo+QFq4Jyj4JVloTBzfjaAx35/FUsJVSJtNT8Pc=; b=SxJ8zzZYF3xcPABeGzrp179ihCbinQwl9GqCyQe+G/L6lG55g78M4AeZAfArmYR+nCIAeBCZp6/LOoz9PtkpUdYc1T4fu9V/PUSOeE5Yj3L4JKu96uDeNFGMoWlGlv7ifAgcGUh6Xs/8ocY5ZqnMad/l8R+X3qrYzd5BGHOq7ncf/s3Tiotq+uwXssH4FNkx3VW4+88Do/m4+5ULsPQunLJ41rvmYbqiHwPCW9+9wxG6M3oyNyxfvCH9Gc669nWcmqL5CcbkmtcG43YVEsDoPEqPfH4FikFmunHEG9A4xQFYZ4I7J4d/wNK0L4HvP2Ua0t2jamZ1wz1UOMmlNOOe1Q==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6z8KUo+QFq4Jyj4JVloTBzfjaAx35/FUsJVSJtNT8Pc=; b=ACibcI/rmEPKCC1GmFSZovPnZeER0FNBeCdZ3xv+Yc8u0TgPam9Ce8sEsJF8BiRRhmMwlwqGTAU5QFgx3d9OVZhxk29K1S6+S5cj5sAs3kWVGbdXSAvJ2RCcuLShW8ofHgcB17BcgMzmO5zOW73ByPrPXPGOm3EcIuy4SYQIC9VRoDE+b7DHL919WzH+PL4WN19n9fx6uz5A2hrHKba+QXu06Ccge0hCcW76mkV7C2Prz58DMy3uTbGcW3Guj2rhyIpMPn7GnfLngz4lAe+apWVZk8rkAuRBLFScfZGTaPrJjkgaCHS1YAhnDQp7dVuFNqSdrpUZXPj13N2BYmKLfQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=U1LE+jtsBkb03mh9FMDEy7Ic0NPd+Olz5uLEdbpKzqgWUbpBzwnToY9b6FRd0B63vWzTf3pgaRuJMpahutjBNkGsCvvSUg/l9Vbve19bK0md9+UnyzJ3BEfLP4bnlHE5mi/aXihfqTPyYSDkWXrPFlakR73P1sOaP1sB8HCzMFlnEBWbDe/gV3YVQiPDeUaH4SEL9vHX0IoV1kxAHF/3VxcwiRFeukSwFQXwCppFRAn0xQu5t4Z9p00mNC3dAbOcirCOYf9Kp00ogEu4x808g+6sR6yVVV7VLKHDvtvyq6ENlUZwGWelwzU32pojQ2kUUGCq5JaiIKFkADLnnObXSg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fw/K6CKZZvrwHlzym+dw0BhiQF2pNx+n06FABGkjVAzUCYOT7VeOlB0XnO3jNsaSvII27lAweZIYKGOyZegRmgH3ZQUB+OZ1ArgiqheGDajHXQ4PfV1SdFzCn8vf4aWMTXyhabuHdSZ3zxSmsAHAOQTy3U+H9l2FEKEIiFts//9ngyvpydCZrWF8y7Ee/F8UDbcNXmRE+2XK+ssdf1vaMUH/XwKtlaWjgyK62iL3j24X2Igm9RTxqmzaY53jKxtIk6wdTP943SnKSHHhAIvOAaEVF2UV+kcXFCfaKR4CaY/YwXMHavwINEeAahrGmPFIbcpmE1L5qtBaEcFO6k1k4g==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Zhou Wang <wangzhou1@xxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Will Deacon <will@xxxxxxxxxx>
  • Delivery-date: Tue, 06 Sep 2022 14:45:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYwdelUBSV4OOcQUmjNGIzTG/77q3SetoA
  • Thread-topic: [PATCH v4 03/10] xen/arm: smmuv3: Ensure queue is read after updating prod pointer

Hi Rahul,

> On 6 Sep 2022, at 10:55, Rahul Singh <Rahul.Singh@xxxxxxx> wrote:
> 
> From: Zhou Wang <wangzhou1@xxxxxxxxxxxxx>
> 
> Backport Linux commit a76a37777f2c. Introduce __iomb() in the smmu-v3.c
> file with other Linux compatibility definitions.
> 
> Reading the 'prod' MMIO register in order to determine whether or
> not there is valid data beyond 'cons' for a given queue does not
> provide sufficient dependency ordering, as the resulting access is
> address dependent only on 'cons' and can therefore be speculated
> ahead of time, potentially allowing stale data to be read by the
> CPU.
> 
> Use readl() instead of readl_relaxed() when updating the shadow copy
> of the 'prod' pointer, so that all speculated memory reads from the
> corresponding queue can occur only from valid slots.
> 
> Signed-off-by: Zhou Wang <wangzhou1@xxxxxxxxxxxxx>
> Link: 
> https://lore.kernel.org/r/1601281922-117296-1-git-send-email-wangzhou1@xxxxxxxxxxxxx
> [will: Use readl() instead of explicit barrier. Update 'cons' side to match.]
> Signed-off-by: Will Deacon <will@xxxxxxxxxx>
> Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
> a76a37777f2c
> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>

Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>

Cheers
Bertrand

> ---
> Changes in v4:
> - rename iomb() to __iomb()
> Changes in v3:
> - rename __iomb() to iomb() and also move it from common file to
>   smmu-v3.c file
> Changes in v2:
> - fix commit msg
> - add __iomb changes also from the origin patch
> ---
> xen/drivers/passthrough/arm/smmu-v3.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
> b/xen/drivers/passthrough/arm/smmu-v3.c
> index 64d39bb4d3..229b9a4b0d 100644
> --- a/xen/drivers/passthrough/arm/smmu-v3.c
> +++ b/xen/drivers/passthrough/arm/smmu-v3.c
> @@ -107,6 +107,8 @@ typedef paddr_t           dma_addr_t;
> typedef paddr_t               phys_addr_t;
> typedef unsigned int          gfp_t;
> 
> +#define __iomb()             dmb(osh)
> +
> #define platform_device               device
> 
> #define GFP_KERNEL            0
> @@ -951,7 +953,7 @@ static void queue_sync_cons_out(struct arm_smmu_queue *q)
>        * Ensure that all CPU accesses (reads and writes) to the queue
>        * are complete before we update the cons pointer.
>        */
> -     mb();
> +     __iomb();
>       writel_relaxed(q->llq.cons, q->cons_reg);
> }
> 
> @@ -963,8 +965,15 @@ static void queue_inc_cons(struct arm_smmu_ll_queue *q)
> 
> static int queue_sync_prod_in(struct arm_smmu_queue *q)
> {
> +     u32 prod;
>       int ret = 0;
> -     u32 prod = readl_relaxed(q->prod_reg);
> +
> +     /*
> +      * We can't use the _relaxed() variant here, as we must prevent
> +      * speculative reads of the queue before we have determined that
> +      * prod has indeed moved.
> +      */
> +     prod = readl(q->prod_reg);
> 
>       if (Q_OVF(prod) != Q_OVF(q->llq.prod))
>               ret = -EOVERFLOW;
> -- 
> 2.25.1
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.