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

Re: [XEN PATCH v1 2/5] xen/arm: ffa: use ACCESS_ONCE()


  • To: Jens Wiklander <jens.wiklander@xxxxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 10 Apr 2024 07:05:35 +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=F/MwjtnK9qmzlWjtgCd002xcrCUf8czW5AHH3/FHceY=; b=iRsGgKrQq6XZ8sJDyUQFEi59O6dLk5ei73Lyg0cWymdtSlzjyHXIgjPzjOh1p4smiFCjHTRuorQ8qq7kZgrloPecjURegjkV3ziCBNl0aDWi7nwI0y/eC6fw7IlnoeMcfum1xUudpZtlxyRCryR5RsrKGWJ94a/fzQU7z1mwUESyBXV3dqHMEm3yUyKfdVPQXbg8PMtcryE8WJ3d2OOWiTvcISkJD4yFPyzi7XUbNlrVxGb+/nT7NAWRf8TT/VrifqdRDHq1+RXprjMUENCW323MmJi1oFjVSghecT2X3ZvvWx6/6ABJPmp9GQ6Ij776XFVlpBL9lKoq5kP7yoGqKw==
  • 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=F/MwjtnK9qmzlWjtgCd002xcrCUf8czW5AHH3/FHceY=; b=OK/7WBC+z6SpUHAbxZu/KS/Jm2WNrfsKXtEGykajyMOZZDroExTMXeqiEi5yQeACUctOkhD8kDrcl3una6V9GPd4ILQ9B6DpDcRyMlSyBTsy8N9kEywA+0R8TBRsTcFmKSBgp3Gj9Phy4pwYdRtMBEze8udT87tg8S+8X3L3HjqMmI3k4ipd4Mj6w3A2W1cEcwCql9ZgvSbkwyl0P+H2WkfgF/cjspoIEesHfLUibiIbtQbEfNge2z9qmXFZGkdOyKlpl+qvUwrvvmhPoJ7NeYAImeFFOTHreZw2fuR50M0CA/QXjtr/58zK/OCJSe6GdtKdbRXSQsvkpBiC9JCK8w==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ehHJUmx24aaxZooFRZZ/lgN9nrm0x8MLSMolkpilruYh7FTQ4kbWIWIevoNS5xWbUAU9QdY6pR9Y+STInMWQBGgOfYLvXRu7/lyTPiCm5yexDihTflmzJxqKUra72b06XFC2EzybOWLTUeChePmGwwmdBW2PUq6g5ehhQDyZbLMrv3AfYpzwQ4jaYU2Dgyi9ftcyyMbSuzvlyPrQNygOz4mIsg8SnGenGPuabH3VNiA9SXmIfYMaV6KBzOmPpzHJ1mgpvKdJGtuKKpsaaVEBaphF/U2zf7wMkCP43r0+bNn9AwWDQ48U5d/OXxakeIUbYjYF7IAolFZbq2/fKJwN6w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mjO4LVHuEL8YN3knICxtC72utVmX+zH6ma4XYOk8HedA8t7Lnzx2GxI23dt2nc2F9T/Mzg37tZkVqZMESprGi5mD4ckZ/yfBxKd6P7lEcJVYbTN+oATLw51y8iwCBk0Cxn/q2ZEwQEERM3hms/dLQXd9QBLRrVMp5IOCmcgn/Kyu+c2RiKgITdsvQ/a80zzZUzalQEGM4tfLwlGPbVvJWYMi0OiZjKNCUjgyE6iIOHPqj4Al0IFbWQKJsJoWuYGyhp/HMUstQ7wfhUAOraF4YVdedr7fx+Zi11kDEh2XsjqYMvW+xX/AhAlg8HnFY0FOqKxJhydG2tA+sLDIe82LZA==
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "patches@xxxxxxxxxx" <patches@xxxxxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Wed, 10 Apr 2024 07:05:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHaipO90m+vC5zVBEutoTp706SovLFhFcSA
  • Thread-topic: [XEN PATCH v1 2/5] xen/arm: ffa: use ACCESS_ONCE()

Hi Jens,

> On 9 Apr 2024, at 17:36, Jens Wiklander <jens.wiklander@xxxxxxxxxx> wrote:
> 
> Replace read_atomic() with ACCESS_ONCE() to match the intended use, that
> is, to prevent the compiler from (via optimization) reading shared
> memory more than once.

This definitely makes sense.

> 
> Signed-off-by: Jens Wiklander <jens.wiklander@xxxxxxxxxx>

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

Cheers
Bertrand

> ---
> xen/arch/arm/tee/ffa_shm.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/xen/arch/arm/tee/ffa_shm.c b/xen/arch/arm/tee/ffa_shm.c
> index eed9ad2d2986..75a5b66aeb4c 100644
> --- a/xen/arch/arm/tee/ffa_shm.c
> +++ b/xen/arch/arm/tee/ffa_shm.c
> @@ -7,6 +7,7 @@
> #include <xen/sizes.h>
> #include <xen/types.h>
> #include <xen/mm.h>
> +#include <xen/lib.h>
> #include <xen/list.h>
> #include <xen/spinlock.h>
> 
> @@ -171,8 +172,8 @@ static int get_shm_pages(struct domain *d, struct 
> ffa_shm_mem *shm,
> 
>     for ( n = 0; n < range_count; n++ )
>     {
> -        page_count = read_atomic(&range[n].page_count);
> -        addr = read_atomic(&range[n].address);
> +        page_count = ACCESS_ONCE(range[n].page_count);
> +        addr = ACCESS_ONCE(range[n].address);
>         for ( m = 0; m < page_count; m++ )
>         {
>             if ( pg_idx >= shm->page_count )
> @@ -527,13 +528,13 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
>         goto out_unlock;
> 
>     mem_access = ctx->tx + trans.mem_access_offs;
> -    if ( read_atomic(&mem_access->access_perm.perm) != FFA_MEM_ACC_RW )
> +    if ( ACCESS_ONCE(mem_access->access_perm.perm) != FFA_MEM_ACC_RW )
>     {
>         ret = FFA_RET_NOT_SUPPORTED;
>         goto out_unlock;
>     }
> 
> -    region_offs = read_atomic(&mem_access->region_offs);
> +    region_offs = ACCESS_ONCE(mem_access->region_offs);
>     if ( sizeof(*region_descr) + region_offs > frag_len )
>     {
>         ret = FFA_RET_NOT_SUPPORTED;
> @@ -541,8 +542,8 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
>     }
> 
>     region_descr = ctx->tx + region_offs;
> -    range_count = read_atomic(&region_descr->address_range_count);
> -    page_count = read_atomic(&region_descr->total_page_count);
> +    range_count = ACCESS_ONCE(region_descr->address_range_count);
> +    page_count = ACCESS_ONCE(region_descr->total_page_count);
> 
>     if ( !page_count )
>     {
> @@ -557,7 +558,7 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
>         goto out_unlock;
>     }
>     shm->sender_id = trans.sender_id;
> -    shm->ep_id = read_atomic(&mem_access->access_perm.endpoint_id);
> +    shm->ep_id = ACCESS_ONCE(mem_access->access_perm.endpoint_id);
> 
>     /*
>      * Check that the Composite memory region descriptor fits.
> -- 
> 2.34.1
> 




 


Rackspace

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