All of lore.kernel.org
 help / color / mirror / Atom feed
* [XEN v2] xen/Arm: Enforce alignment check for atomic read/write
@ 2022-11-04 16:23 Ayan Kumar Halder
  2022-11-04 16:32 ` Bertrand Marquis
  2022-11-06 17:54 ` Julien Grall
  0 siblings, 2 replies; 10+ messages in thread
From: Ayan Kumar Halder @ 2022-11-04 16:23 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, stefanos, julien, Volodymyr_Babchuk,
	bertrand.marquis, michal.orzel, Ayan Kumar Halder,
	Ayan Kumar Halder

From: Ayan Kumar Halder <ayankuma@amd.com>

Refer ARM DDI 0487I.a ID081822, B2.2.1
"Requirements for single-copy atomicity

- A read that is generated by a load instruction that loads a single
general-purpose register and is aligned to the size of the read in the
instruction is single-copy atomic.

-A write that is generated by a store instruction that stores a single
general-purpose register and is aligned to the size of the write in the
instruction is single-copy atomic"

On AArch32, the alignment check is enabled at boot time by setting HSCTLR.A bit.
("HSCTLR, Hyp System Control Register").
However in AArch64, alignment check is not enabled at boot time.

Thus, one needs to check for alignment when performing atomic operations.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com
---

Changes from :-
v1 - 1. Referred to the latest Arm Architecture Reference Manual in the commit
message.

 xen/arch/arm/include/asm/atomic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xen/arch/arm/include/asm/atomic.h b/xen/arch/arm/include/asm/atomic.h
index 1f60c28b1b..64314d59b3 100644
--- a/xen/arch/arm/include/asm/atomic.h
+++ b/xen/arch/arm/include/asm/atomic.h
@@ -78,6 +78,7 @@ static always_inline void read_atomic_size(const volatile void *p,
                                            void *res,
                                            unsigned int size)
 {
+    ASSERT(IS_ALIGNED((vaddr_t)p, size));
     switch ( size )
     {
     case 1:
@@ -102,6 +103,7 @@ static always_inline void write_atomic_size(volatile void *p,
                                             void *val,
                                             unsigned int size)
 {
+    ASSERT(IS_ALIGNED((vaddr_t)p, size));
     switch ( size )
     {
     case 1:
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-11-08  9:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-04 16:23 [XEN v2] xen/Arm: Enforce alignment check for atomic read/write Ayan Kumar Halder
2022-11-04 16:32 ` Bertrand Marquis
2022-11-06 17:54 ` Julien Grall
2022-11-07 10:36   ` Ayan Kumar Halder
2022-11-07 10:44     ` Julien Grall
2022-11-07 12:49       ` Ayan Kumar Halder
2022-11-07 18:06         ` Julien Grall
2022-11-08  7:26           ` Michal Orzel
2022-11-08  8:34             ` Bertrand Marquis
2022-11-08  9:48               ` Ayan Kumar Halder

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.