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

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


  • To: Julien Grall <julien@xxxxxxx>, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Ayan Kumar Halder <ayankuma@xxxxxxx>
  • Date: Mon, 7 Nov 2022 12:49:26 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=UITH3pPH1dVUoCM8Kj/tElqVfTF+vparNAHDqJ+glHk=; b=i4F4bCcjy1x2/IVOLwgHUgKJgixGMx5E8dWXC8Q3eFGxaClMlas6KCr/Ju3kNDcn8nD+vgY3LZE2xIDHhVHN7UWtX+4mJo22/409NDx21QwZjfwu1/rM7IL9vmDN2Us7wgUOIdW1VpyxAqjPUirwT0hrjXB1dpa2Q+/bwD5bNNpRKVMRvQNnhGd5xWPCmz9waOLKYqpHMdk0u0gR5FHbRPrmNwpqAFZoXpK1SLyda8hwz+Vj67ijW86Ry5FZnUgPtQ0AkpKsHMqH7PEcrdzkPqXHCYhk1OZ/xUCwG4x5J8I3VtQwHatc6CLfD6JNTIxYigKJ3U9NFqdexKGzPyi+lg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VG2JKDT6DIwxYUEHxUD91w0ZaGAmITDo29Hiw09NbIrj07ikA2vbbDufPeWDbs/fhc3NqF5ZWkTE3yX2UuwLHQX4JthxMKwOv4MT9WDwLpRNwlhcM3fF34i2y3kJ6nU6CBGC54v4IQYScPQTrmDECTkO1+WgEYtyKdg8gWeMvOAwqCOuUUoRZiOZ2JUAk9rAGeQ0EDRPC7MNW061WIv9leYjnWZx9FyXgoha0CaxjoWH28ix2qHlhDghJfyL4vlW1+vQzaNWRYR3BMPERHPUA4XoVM2JOJn1Mk4nMEfElNRgbqH0MTpJGL7fw5a8So5vHo9pbGcwCvCEyi72ldMpuA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: sstabellini@xxxxxxxxxx, stefanos@xxxxxxxxxx, Volodymyr_Babchuk@xxxxxxxx, bertrand.marquis@xxxxxxx, michal.orzel@xxxxxxx
  • Delivery-date: Mon, 07 Nov 2022 12:49:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 07/11/2022 10:44, Julien Grall wrote:
Hi Ayan,
Hi Julien,

On 07/11/2022 10:36, Ayan Kumar Halder wrote:

On 06/11/2022 17:54, Julien Grall wrote:
Hi Ayan,

Hi Julien,

I need some clarification.


To me the title and the explaination below suggests...

On 04/11/2022 16:23, Ayan Kumar Halder wrote:
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.

... you want to enable the alignment check on AArch64 always.

I want to enable alignment check *only* for atomic access.

May be I should remove this line --> "However in AArch64, alignment check is not enabled at boot time.".

However, this is not possible to do because memcpy() is using unaligned access.
This is a non atomic access. So the commit does not apply here.

Right, but your commit message refers to the alignment check on arm32. You wrote too much for someone to wonder but not enough to explain why we can't enable the alignment check on arm64.


I think the commit message/title should clarify that the check is *only* done during debug build. IOW, there are no enforcement in producation build.

AFAICS read_atomic()/write_atomic() is enabled during non debug builds (ie CONFIG_DEBUG=n) as well.

My point was that ASSERT() is a NOP in production build. So you effectively the enforcement happens only in debug build.

IOW, unless you test exhaustively with a debug build, you may never notice that the access was not atomic.

This makes sense.

Does the following commit message look better ?

xen/Arm: Enforce alignment check for atomic read/write

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"

Thus, one needs to check for alignment when performing atomic operations.
However, as ASSERT() are disabled in production builds, so one needs to
run the debug builds to catch any unaligned access during atomic operations.
Enforcing alignment checks during production build has quite a high overhead.

On AArch32, the alignment check is enabled at boot time by setting HSCTLR.A bit.
("HSCTLR, Hyp System Control Register").
However, on AArch64, memcpy()/memset() may be used on 64bit unaligned addresses.
Thus, one does not wish to enable alignment check at boot time.

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

I think I can keep R-b as there is no code change ?

- Ayan


Cheers,




 


Rackspace

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