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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Date: Fri, 4 Nov 2022 16:23:55 +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=pEw6Ps8mug7G4A+QhO2oaXYDI+K/H84ed4gbyS14lPo=; b=Iv+ngoxtGI5hcZ23u8GCYdyfq++M/XvRHi8+pZhlr2EDF445nILN+1bCuhzd9op5dIvmWXdyGpzFs7sDHaDoT1c+sfFKE6TviSHPL2ANbqGBSa1ew3q2+CuTxlIdaip3gWL9rfw9aq49SG7rKOLLBvhKgFarmjFWgMZ6aqgMhLFkVHuxRtl0G9lNH8MYNvK0N7Gtuvn0f+Fyn5ANDoLSrJ13euQu8Rp4oAXaidFtdpWYhB564j5co3dadZmgNI3Veng206e6qEPaRupIXs5EWD9LNfg0ft3j1MZOaE1aOLDTvzpEetyQu3im1ShKQ1ahPGOOE0cgLWsMntH51r/F1w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JyH9RSrmME2e3c+e+May26dI908uORfNPmqtAu+rR491ZCUZO+Crpkb1vuPFFwSUeXjdq6yNOirBKi4P4zku7gqmW9ew5VlWt1IzGYXO7qcRaVy9sm1IexYEwfBr/+kkBamEl9ToGcTzCD/N35rDVo6CttYz40WO+D3+lOH0a8APpIhby2Vt6PX+TfwdDSaWp4B3UxvN/6Pr58kbm1K2GJ+RKADJRPuKzf3aG00uYiazM2XDN8itdlPMAqmJfW7G543ZGks7AuOWoXC79WOaiNOQRRp2Vfv7GkZeospZn03Sq0O1ihb/l/Prpwhj7d835QudoTqiZ3KJ/KE63J+j6A==
  • 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: Fri, 04 Nov 2022 16:26:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Ayan Kumar Halder <ayankuma@xxxxxxx>

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@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx
---

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




 


Rackspace

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