[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [XEN v3] xen/arm: Enforce alignment check in debug build for {read, write}_atomic
- To: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
- From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
- Date: Tue, 8 Nov 2022 11:22:33 +0000
- Accept-language: en-GB, en-US
- Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
- Arc-message-signature: i=2; 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=ctSarpqe0aWgVPoCD6N3eCH6G/W3lXgybkfIntDyAis=; b=JTFCuRGXOyyMi26pxGhGboFGR86NJi8tLzMoy0Oa1nN8Wx92yw0w75nTY6006EVTpRZ2GwqW7uySFPbJY82HIZWRfhxS5OnwjPjToNDHhFu6h0Xz65rOMmTo5LAUo2qpIffAZiQuVHKpGIvIjrdb3/GVXZA/f3ONkPTQ0mfKpOELOLJnhoOv5QkV1uBNRKHnbl7u+YHZNmInaIHC4dxescvIDQ68HYC082HOtcpRJHiAWLjQzjEgNFccqA/vWh5GDB3hzsXbZcR8CWwGz7Cn19tf0xBkgqG++GdU+gMHJPr+1vh+sd8FzI0JluCWNfjPTJs+DCRcp2QoNd9iqPmsLw==
- 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=ctSarpqe0aWgVPoCD6N3eCH6G/W3lXgybkfIntDyAis=; b=Aw9J8sEc5GXxpD28+BaCrpTs4oGbpYYXshi/Bv2FRpzSEM4wlwtQK+mQGkpZnEJSzYB2sON2wZ173Q/+laoEIMyVmmZQR5MH/eE+GvJzcyMRdQvlso8kFVaRqOD8g4KeD+bYtaQD0U31K+rp+RN71j/SXSorzTS/kzRGWG9I8L7/+E4E8h6FJjKdp6J9NMqQX35GSODi/xaRQrSAdFVQCk9htRh2ZLeAny+ryQwWhVMMYhTiTo3sPj4PhHuYWXiN/MuCUD37pP0MZqOUWT49LCY57SOVHUL7eu477+oONLnDIpQQ1VhxaNTh2ZTK+s3677XXZ9k6Vf8O/7lRFKdQjw==
- Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=m+NPF3pZAWUjPQHkadOmUXe7VkoL9RdBxlfNiJRbiFvqRU2a1VrSKcG+jn+m/nInIZV2A4YFRuWQYvz8H+qQzShaexVsmjltLB7tCwMWzpzGLptyRN0QEkQ3e6IQgDG6FuPCRrDV1n3aD0fPcMVpQAI0QtMsDJzF0v/5D9rf4emVZ0dUVjWVNG3tDEqOFouXkcpvKqtlXFj0qhrskZNP8oXa7/SwTPFOPmus28ExWSSDVlRbqVyzj6W6K98Bi5eDMC4IzDqn5Tu2gxC+l9i790W6P63iJfR0CWO45Kt37WLJK0YvyJOK3u16SfiyViUKblPzMDqZpALcCJkgYsmcpg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dMQ536QVJPiYI5eNZXMhdzhbGNN12v/u1h5Djoo1mQ5ZE5AXnb9nag+591WfJSNPrDyCt8djYiw/9Z7o8RYpjlMHqOs+X29fo1+eJ7RS70WMIHjXxLkpgMtZBBcrB/qGHuC9baYR30UfYRmChnCHCRsgX4M7OX5hv2TK/aOxAYz4bfq9IAvApo5JJMW82gI1nywVQhgRBLqLFAqae7Ao/y2wQ18RgmrU4v7Ym5ZqKNpvaxTWC9nE/ESo6QsSpy15ilPaW0lBddflZZQw/cf72ASgvVzpM3cnlGXNjnBnjMT91e65HfjpYcmItq5Kxpy1fXyZlHHVO3f2mHFEnV2tIw==
- Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Cc: Xen developer discussion <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, "stefanos@xxxxxxxxxx" <stefanos@xxxxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "Volodymyr_Babchuk@xxxxxxxx" <Volodymyr_Babchuk@xxxxxxxx>, "michal.orzel@xxxxxxx" <michal.orzel@xxxxxxx>, Ayan Kumar Halder <ayankuma@xxxxxxx>
- Delivery-date: Tue, 08 Nov 2022 11:22:57 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Nodisclaimer: true
- Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Thread-index: AQHY81buqq5XOHkvVUuD4StMug7I3a404hsA
- Thread-topic: [XEN v3] xen/arm: Enforce alignment check in debug build for {read, write}_atomic
Hi Ayan,,
> On 8 Nov 2022, at 09:45, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx> wrote:
>
> 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>
I confirm my Reviewed-by.
Side note: You should actually have removed it :-)
Cheers
Bertrand
> ---
>
> 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
>
|