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

[XEN v3] xen/arm: Enforce alignment check in debug build for {read, write}_atomic


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Date: Tue, 8 Nov 2022 09:45:03 +0000
  • 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=JjVJB5MYlDRfIruHI/1g6NGUyb/oTyRx5dUFFXbwFbM=; b=jg4Uj+7kGfbT2w2IomyHAtahUHXnYrejEikWmQ+2poOMWtA5NHavBc4q/nwbizcUiU43UtC7N1UI6k0dqSodh9nWiM0r66GjAHcZOi0zRne/x/tgctj0fg5gU01riQA1CBKFciLbmhUqb387LiXDC6wW+1uRgifsQtwyEvDrULrResxUuDNrJpmJaVWD6HSjYRY++mOpDu/BNax3/j4izQDD8IeB/MHGLA6mRplj+EXc5tEG9neK5IEW65UJt88xIkYy0qOfL3f9GJ0MRt4M579DWZN8lnzKvwv0yQpC5oA5TW1hZuY/yz8vmpMtBkK4sDZ4nVd7QxNmdy+aCpp6zA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KufQWCFB6USxsL32AOx3i0sr2CeCUE6OSe41FkbYy5Rp1h6E/7iDZjS/7L1dIe1mbHk1jTjOw/xOweO9R4WGWliXWfekYUuAVk7KZKewo90XM2TDaV7ix3d6SIKR/Bdtsl5+QSIkOY7Rn0qv82Fja+0FTbnSo81rG0VDqIklghK3sJeXj7nSBWEKoY3ZnG5LmIHoSXyYNcoponWEZUkWrjzQ9iXLgcrnKob8qJPmp3M76McAKtlMhtaJizvFhMef0xm71c9x3ggnBG27rpXAN+vpMVrRMi+FAIl/Yp36vS76Z1/B97xeE40Ez9Xa2OPxcLd1D0GTycqZd99nSDmfBw==
  • Cc: <sstabellini@xxxxxxxxxx>, <stefanos@xxxxxxxxxx>, <julien@xxxxxxx>, <Volodymyr_Babchuk@xxxxxxxx>, <bertrand.marquis@xxxxxxx>, <michal.orzel@xxxxxxx>, Ayan Kumar Halder <ayankuma@xxxxxxx>, "Ayan Kumar Halder" <ayan.kumar.halder@xxxxxxx>
  • Delivery-date: Tue, 08 Nov 2022 09:46:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Ayan Kumar Halder <ayankuma@xxxxxxx>

Xen provides helper to atomically read/write memory (see {read,
write}_atomic()). Those helpers can only work if the address is aligned
to the size of the access (see B2.2.1 ARM DDI 08476I.a).

On Arm32, the alignment is already enforced by the processor because
HSCTLR.A bit is set (it enforce alignment for every access). For Arm64,
this bit is not set because memcpy()/memset() can use unaligned access
for performance reason (the implementation is taken from the Cortex
library).

To avoid any overhead in production build, the alignment will only be
checked using an ASSERT. Note that it might be possible to do it in
production build using the acquire/exclusive version of load/store. But
this is left to a follow-up (if wanted).

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
Signed-off-by: Julien Grall <julien@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
---

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

v2 - 1. Updated commit message to specify the reason for using ASSERT().
2. Added Julien's SoB.

 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®.