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

Re: [PATCH] xen/arm: smmuv3: Add cache maintenance for non-coherent SMMU queues


  • To: Dmytro Firsov <Dmytro_Firsov@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Fri, 22 Aug 2025 10:12:20 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=epam.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=BQw5ZiP/6KXo+yB5VlhXRjgkmQYBUqSOxz+sZjqK76s=; b=uYNFFKSPEe6XeFMYn9bipWvbu7Uj+WgN8wCjtjBLK94DSCeNn77T4hjMuCagfmJmKffNnVhgCnug8K0M3JCan2rMqYcITgG3y22jGTN5ZQKfjTi4UBCnnOeen5fdJ5YyD1YsU1zjW+2c2Owf2Moo3T/kgSXNOcDil/tg7llSko8iGl/W/dvAjakt1yNfE4BwKHcDPbCDOhdUozcILN7l1fMwMh3kprCzNsrx76N3OXOmHJRx7VcXFC9awxe9NP0vFW/pSZpF8HduJEwoOCsNRvado3GnPX8mXz8zfe0beWz+2SNAa2xb2d/AGGqnAPfZxthp6HUYsGPxtX/YjZFl7g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ga7xeHUAPX/4KOox0LimwoxCJZ8N2TbxZj2lpQZ7ytry020wdHqxcXN7A6JBomEAwseRpasI+60AYmrygeEdAHJ+Cc197JOpN0KKl4ozh1ZPjaaokhkYHp0zA2hLbm1Z98Lp+PAB0oV952joYnYCKFsWk4mMsuF2Hrs1ij/rvJksU3rng2EJVmB4VPD8WZLJK2SLpwJuP5oPRmfWmfHRpYb1EJWpuEwavW6i8d9qX4ArvdRh4H2tSQxD1lO5YA8h0EnQg743OS2WcQnxOZ4Lic08pEN676dan3vFUrYHQjoE2IKeqExOxo0fUqghSZqfaKUnMKtz5unWySrWod/gNw==
  • Cc: Bertrand Marquis <bertrand.marquis@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 22 Aug 2025 08:12:40 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 06/08/2025 16:58, Dmytro Firsov wrote:
> According to the Arm SMMUv3 spec (ARM IHI 0070), a system may have
> SMMU(s) that is/are non-coherent to the PE (processing element). In such
> cases, memory accesses from the PE should be either non-cached or be
> augmented with manual cache maintenance. SMMU cache coherency is reported
> by bit 4 (COHACC) of the SMMU_IDR0 register and is already present in the
> Xen driver. However, the current implementation is not aware of cache
> maintenance for memory that is shared between the PE and non-coherent
> SMMUs. It contains dmam_alloc_coherent() function, that is added during
> Linux driver porting. But it is actually a wrapper for _xzalloc(), that
> returns normal writeback memory (which is OK for coherent SMMUs).
> 
> During Xen bring-up on a system with non-coherent SMMUs, the driver did
> not work properly - the SMMU was not functional and halted initialization
> at the very beginning due to a timeout while waiting for CMD_SYNC
> completion:
> 
>   (XEN) SMMUv3: /soc/iommu@fa000000: CMD_SYNC timeout
>   (XEN) SMMUv3: /soc/iommu@fa000000: CMD_SYNC timeout
> 
> To properly handle such scenarios, add the non_coherent flag to the
> arm_smmu_queue struct. It is initialized using features reported by the
> SMMU HW and will be used for triggering cache clean/invalidate operations.
> This flag is not queue-specific (it is applicable to the whole SMMU), but
> adding it to arm_smmu_queue allows us to not change function signatures
> and simplify the patch (smmu->features, which contains the required flag,
> are not available in code parts that require cache maintenance).
There are already a few places advertising the SMMU coherency:
1) smmu->features
2) d->iommu->features
3) platform_features

All of them are better places than queue struct (that as you pointed out is not
specific to coherency). I'd suggest maybe to use 3) and removing ro_after_init
if you don't have access to 1) and 2). All in all, providing yet another place
for coherency flag seems a bit too much.

> 
> Signed-off-by: Dmytro Firsov <dmytro_firsov@xxxxxxxx>
> ---
>  xen/drivers/passthrough/arm/smmu-v3.c | 27 +++++++++++++++++++++++----
>  xen/drivers/passthrough/arm/smmu-v3.h |  7 +++++++
>  2 files changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
> b/xen/drivers/passthrough/arm/smmu-v3.c
> index 5e9e3e048e..bf153227db 100644
> --- a/xen/drivers/passthrough/arm/smmu-v3.c
> +++ b/xen/drivers/passthrough/arm/smmu-v3.c
> @@ -346,10 +346,14 @@ static void queue_write(__le64 *dst, u64 *src, size_t 
> n_dwords)
>  
>  static int queue_insert_raw(struct arm_smmu_queue *q, u64 *ent)
>  {
> +     __le64 *q_addr = Q_ENT(q, q->llq.prod);
> +
>       if (queue_full(&q->llq))
>               return -ENOSPC;
>  
> -     queue_write(Q_ENT(q, q->llq.prod), ent, q->ent_dwords);
> +     queue_write(q_addr, ent, q->ent_dwords);
> +     if (q->non_coherent)
> +             clean_dcache_va_range(q_addr, q->ent_dwords * sizeof(*q_addr));
I think it would be better to move the cache operation to queue_{write,read} to
avoid having to repeat them at each occurence of the helpers.

~Michal




 


Rackspace

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