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

Re: Unaligned access on arm32


  • To: Julien Grall <julien@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 7 Sep 2022 15:45:07 +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=Mm7RCssHSVB72mF5TsSZZ6r3qwhKtdWpn7Zx+wr+95w=; b=ffxGbqh35azrGam5viKfUhEhBLVCUWHR6grtR+soOo/Ebh5RgtLeyxVhWvytNjUIYfKhFnvykzseER1rf5DHms/kxb5hH7YCJNu/WjnQr1BwHzkB6rhVMomAhkizpf+NIiNSNHli/kM7/2J4jBIxaz8/KeiIe0pK7Apq43Ejey4z1WjDHBgzCLi3C4YETAPuBcvzdYVnD3tOmPkYZauzkjECYa2knwHSnyJis6ZKD8joauVTtBCnCZ3qfglPght8VEymIqELgyFbbh/iXF8kw5154Xa73KPgo/TEHDhxQZloh8pN5bUljyyhOSzEtPGeaFSjupUJgycLvWQu/+nnQg==
  • 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=Mm7RCssHSVB72mF5TsSZZ6r3qwhKtdWpn7Zx+wr+95w=; b=LO5mLZdTnj2hGkV7MvxJArBjkeOseRznbE8X3PUcTYGn6uvjdoR0Zd/8/+uCD3vmsFkNQza/TtJzYx1jOJ9Ug0/rYctheCsuezgCU+W5OCzMLJk40ZKkI6kTHf5wr0ul6ZU+MlUm9wrm8sWH258Jnqnjyl/5RALwbxcB8jFcbVaY/HrznVgUww9KPgudnXcwBiIOP9fCenbTmKaGjG6dTxWvwz6ailix0wVP7dLTozKPS+W07BNpQVgTJnL3lt0dxBXqIqjZNn4W50p1Gg2brvehMD8cF+r4vilhoXQH8KQoCVOYjDapOaWPv7f9/7ks4J0ZhUc4jSGoW1At2SlahA==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Pt4DLXBpg7Nn1rK4H72L3Ky1/as1W9Yglzu83dLuzwFeo/noEkd0flp8sG0xyKhWVbRp40amZ5xFNl07d5gyEnxY8M8fHgVpmpcS31akkaeg2H1fabg/PC9eh8eCfuPIJHuo/WZc0NhVGl1TAH2KXluTxqqh3THTI5u3tmrdRPC6cx54o9w0iU7TLtAMHG0DAPci8CVETi3nfp7AHdDHFjLHvpu/O40DLRt6N7Z06q8ZfJR8boPRhXDMDSVrRCvP3EaWdV4KOS61OlDxr97cnGSk8ZKycYINQmCSD3ZPbPlWrQM29ouWAuNjB0zDBKvRFn6HxyioOQ8tb1LpxUuk0A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YctznOlrxOFex2awQCatqxZGK3LPkXZhJTKJ8AUAJmJNOLHdZmf2YenTun7+BIV8xZZqxPXLir3daad4VPlbokg332fB23+ks0WgUHYVcJJRp1MJp18ZT+bguNGuMO4iYieWIyEW22V8qaZstWwlhWzRVh16zrMJ237ahsPmVdUeM4R8wmGSfL8OqlNAOCku2L+IHyuf1XhomBT6L906E3QFAXhUsOOdWrU3U3vw3mFTxPvCkES48sO5CTNrTQ/plj70la1ZmfNGIVuxuWuaFs12AKe6aceiSxUi5GG72F/aPgi/CzZWTCvT3IgeeMNcR+EqJeF3MISbNj3tYNCdKQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 07 Sep 2022 15:45:26 +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: AQHYws7Zew4zoBRJmEmNmoI/aV0uva3UG/wA
  • Thread-topic: Unaligned access on arm32

Hi Julien,

> On 7 Sep 2022, at 16:30, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi all,
> 
> I think mentioned it privately a while a go, but never sent an e-mail about 
> it.
> 
> While testing arm32 with IOREQ, I noticed Xen is crashing because an 
> alignment fault:
> 
> (XEN) Data Abort Trap. Syndrome=0x1800061
> (XEN) Walking Hypervisor VA 0x40027ebb on CPU0 via TTBR 0x000000004012f000
> (XEN) 1ST[0x001] = 0x00400000bbffff7f
> (XEN) 2ND[0x000] = 0x00500000bc000f7d
> (XEN) CPU0: Unexpected Trap: Data Abort
> (XEN) ----[ Xen-4.17-unstable  arm32  debug=n  Tainted:   C    ]----
> (XEN) CPU:    0
> (XEN) PC:     002613b8 try_fwd_ioserv+0x44/0x1bc
> (XEN) CPSR:   6000005a MODE:Hypervisor
> (XEN)      R0: 00000000 R1: 00000001 R2: 0022a748 R3: 00000006
> (XEN)      R4: 40027f20 R5: 40027f58 R6: 40028000 R7: 00000000
> (XEN)      R8: 40027f20 R9: 4003a438 R10:002f0044 R11:40027edc R12:00000002
> (XEN) HYP: SP: 40027e94 LR: 00260edc
> (XEN)
> (XEN)   VTCR_EL2: 80003558
> (XEN)  VTTBR_EL2: 00010000bbff8000
> (XEN)
> (XEN)  SCTLR_EL2: 30cd187f
> (XEN)    HCR_EL2: 007c663f
> (XEN)  TTBR0_EL2: 000000004012f000
> (XEN)
> (XEN)    ESR_EL2: 97800061
> (XEN)  HPFAR_EL2: 0067faf0
> (XEN)      HDFAR: 40027ebb
> (XEN)      HIFAR: 67600000
> (XEN)
> (XEN) Xen stack trace from sp=40027e94:
> (XEN)    97800061 0022a748 00000001 00000000 8000005a 00800000 4003a000 
> 00000001
> (XEN)    4003a180 00000000 bbff47ff 00000000 67faf200 00000000 4003a000 
> 40027f20
> (XEN)    4003a438 40027f1c 00260edc 002f0110 40027f58 40028000 4003a000 
> 0000013b
> (XEN)    40028000 002f0280 00000090 40027f58 67faf200 93820006 67faf200 
> 00000000
> (XEN)    00000000 40027f54 0026b6ac 93820006 0022a748 00000001 00000004 
> 67faf200
> (XEN)    00000000 00000000 00000000 00000000 ffffffff 68000000 400001d3 
> 40027f58
> (XEN)    00201870 60000000 67601324 67faf200 00000000 00000013 00000000 
> 00000000
> (XEN)    ffffffff 68000000 400001d3 00000000 00000000 00000000 ffffffff 
> 00000000
> (XEN)    67601074 000001d3 93820006 00000000 00000000 00000000 00000000 
> 67601008
> (XEN)    00000000 00000000 00000000 00000000 00000000 00000000 00000000 
> 00000000
> (XEN)    00000000 00000000 00000000 400001d3 00000000 00000000 00000000 
> 00000000
> (XEN)    00000000 00000000 00000001
> (XEN) Xen call trace:
> (XEN)    [<002613b8>] try_fwd_ioserv+0x44/0x1bc (PC)
> (XEN)    [<00260edc>] try_handle_mmio+0x2b0/0x2f4 (LR)
> (XEN)    [<00260edc>] try_handle_mmio+0x2b0/0x2f4
> (XEN)    [<0026b6ac>] arch/arm/traps.c#do_trap_stage2_abort_guest+0x18c/0x34c
> (XEN)    [<00201870>] entry.o#return_from_trap+0/0x4
> (XEN)
> (XEN)
> (XEN) ****************************************
> (XEN) Panic on CPU 0:
> (XEN) CPU0: Unexpected Trap: Data Abort
> (XEN) ****************************************
> 
> The disassembled code is:
> 
> 00261374 <try_fwd_ioserv>:
>  261374:       e16d42f0        strd    r4, [sp, #-32]! ; 0xffffffe0
>  261378:       e1a04002        mov     r4, r2
>  26137c:       e1a05000        mov     r5, r0
>  261380:       e1cd60f8        strd    r6, [sp, #8]
>  261384:       e3a00000        mov     r0, #0
>  261388:       e1a06001        mov     r6, r1
>  26138c:       e1cd81f0        strd    r8, [sp, #16]
>  261390:       e3a01001        mov     r1, #1
>  261394:       e58db018        str     fp, [sp, #24]
>  261398:       e28db01c        add     fp, sp, #28
>  26139c:       e58de01c        str     lr, [sp, #28]
>  2613a0:       e24dd028        sub     sp, sp, #40     ; 0x28
>  2613a4:       e1c220d4        ldrd    r2, [r2, #4]
>  2613a8:       e50b0024        str     r0, [fp, #-36]  ; 0xffffffdc
>  2613ac:       e5d67a26        ldrb    r7, [r6, #2598] ; 0xa26
>  2613b0:       e14b24f4        strd    r2, [fp, #-68]  ; 0xffffffbc
>  2613b4:       e5d43000        ldrb    r3, [r4]
> * 2613b8:       e50b0021        str     r0, [fp, #-33]  ; 0xffffffdf
> 
> The problem is GCC [1] decided to use 'str' for accessing an address that is 
> not 32-bit aligned (fp - 33 = 0x40027e73). On arm32, we are forbidding 
> aligned access, hence why it crashed.
> 
> Looking online, it looks like GCC has an option to turned on/off the use of 
> unaligned access [2] and it is enabled by default on ARMv7 (I am not sure why 
> we didn't notice this before...).
> 
> I have rebuilt Xen with the option turn off and dom0 is now booting fine.
> 
> However, I am a bit puzzled because the C code didn't contain unaligned 
> access. It was all introduced by the compiler itself. This is breaking our 
> assumption that the compiler will not break down correctly naturally aligned 
> access.

Strictly speaking without the option the compiler does not say that it will not 
generate unaligned access so nothing forbids it to generate some.
So I doubt we could argue that the compiler did something wrong here (there 
might be a debate on why it did so as the C code is not doing one).

> 
> When using the new option, Xen size is increasing by 0.40% (about ~3KB) in my 
> setup. Nothing too concerning, but I would like to have some opinion first.
> 
> The alternative would be to allow unaligned access. That said, I think this 
> is much saner to have a strict enforcement as we can catch GCC trying to do 
> unaligned access when it is not expected.
> 
> There is also the argument that unaligned access can be slower on some 
> platform. So it is better to avoid them.
> 
> Any thoughts?

I think we need to be coherent: if we are not allowing unaligned access then we 
should explicitly ask the compiler not generate some, so here one way or the 
other we need to add the compiler option.

Now on arm32, unaligned access might be slower and seeing the size increase I 
would vote to stay as is to detect them and pass the compiler option to not do 
any.

Cheers
Bertrand

> 
> Cheers,
> 
> [1] gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-15)
> [2] https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/ARM-Options.html
> 
> -- 
> Julien Grall




 


Rackspace

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