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

[XEN v1] xen/Arm: Enforce alignment check for atomic read/write


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayankuma@xxxxxxx>
  • Date: Sat, 29 Oct 2022 23:48:02 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org 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
  • 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=ZYPO/ZJx5OoPn847hTGmKX837OvG63RvUdsnPCdXzUs=; b=lP0MIySkc8lSCAGuCcRR/8EityVRGvRtFE5AhylMfKuHiYP3bQ/+McgTz/TFiFMSgO/b/V98kTRLMy4WBe6pildYKL3HcCewz5L/HhPvmMiLOKacLaSPnScOFY9puKRwGNdNMlWRCyRW/DraavNSER5FCUQn80x/xojEJZME8mYrVCnPTn+QP8JVcdlXVLuV1HK6AgAKPoxSFzE/+8KjxcMw4LJO7KMtwRq12mWkTennIjz+xTgj1MRGxXZB/tThy8zspwjxL0vv6prnmO+wo571RusxS8prb32Dt6tQ4gGIsJAZB0xu6XrqmHdHQtyb1dGzzKrKsym36yutkyBG2Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IksFvbwPn0madVIVrgwmP0RR+9JANWDmd/PGqSDMLeiNiuCnDDC43+AUnkGlHXGhAQ30yoeclQQGLYe/YN7lISr45qcf03h2WgguqHWTInsS6ELTjSce5Tfgr3aWRaM66bDpdfs/7+vC5SP+uJcifpQgvbF6RDUJ+U/QE47vppBdyX8cb4alz7sJF31AV0Km1UXNrK7yNzsjZl+5P/aWZy88KYhyBIZXCo1hWEtp6qmUHrJKBXEPq/+Fd7hypedLTZTLNVCD3Kqyu5uFGGy9Sl5HAJDE/pjNLVnDvesRDgc8YbY2qrnk0n9YHELf3+ZVO9dpAwrHt5B49ZUYEbTn/g==
  • Cc: <sstabellini@xxxxxxxxxx>, <stefanos@xxxxxxxxxx>, <julien@xxxxxxx>, <Volodymyr_Babchuk@xxxxxxxx>, <bertrand.marquis@xxxxxxx>, <andre.przywara@xxxxxxx>, Ayan Kumar Halder <ayankuma@xxxxxxx>
  • Delivery-date: Sat, 29 Oct 2022 22:48:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Refer ARM DDI 0487G.b ID072021, 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 <ayankuma@xxxxxxx>
---

This came up during discussion 
https://www.mail-archive.com/xen-devel@xxxxxxxxxxxxxxxxxxxx/msg131185.html

 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




 


Rackspace

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