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

Re: [PATCH v2] xen/arm: set CPSR Z bit when creating aarch32 guests


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Wed, 23 Mar 2022 12:36:06 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=zkWRf2qNvZGX3PK4pKDgbGQUFAsVK8mVCexAGI9THbE=; b=KBQqMgbZ4aFoRiKhGZ3GHER6/K0dtZZvPE8YJEy3U3rteU8uMQVLFozSl5GnyD5hhodl8Hs/7FkA3QLvuXrO6zYS6M2dT4Ums4AjwjBlOk6XG8ab2lnhIlj08f6Aqd8Cm0e9iOYFFk8ugfNod0dpwsLkf+m/1+k7zTjnzmpDO38REvEvF8ZlvPHL4RFyUgujFOEa5l4PbMIagmWF3OuT4+A+FH15yyvN0y7tjKWZVjLTH7Suh/FNfP+TzWMxduIDmBZ5v7PKY/MmyfRyuJsUBZ8PhGXWvaGpvu1A3k+8uI0Eac/pL6MLnJRvVu1EhCKQgQtx7od8Cku+HbILxeEiYw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bng6SWTF9odq10gMErdQOLCgak/C6SS2s0AKEzxW1G60jsRVXmAVwzxsi1MGPcSKtZdDTBO4KB57AFkgU4KQ3ELCZQ5wACisO+pe5EmBQ8GZ5i6wTvVoDgyYUyjvjtpwDj4kYocs/FX3YHoDVcjEm7OPB/vAksnvdNyrx9+of5y0txxTAyra89DYZU/HH+tDzrD4SDv0dWYXh6hn0XuzAezAf68jhTG0qtHxSKIg0fjZHzb92F9rtB5hj/jJhbGfmUudzZiZdO+hvJEUqHAnjcz9gzS2r725nu7l8PTTorkwMMcrZ9ElS+vhiYPmjyzUtrFfCHU0nSCZp5q3kSowKQ==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "julien@xxxxxxx" <julien@xxxxxxx>, "bertrand.marquis@xxxxxxx" <bertrand.marquis@xxxxxxx>, "Volodymyr_Babchuk@xxxxxxxx" <Volodymyr_Babchuk@xxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 23 Mar 2022 12:36:31 +0000
  • Ironport-data: A9a23:lfISJquxQlBb4vOM2BX+a+PXSefnVKZeMUV32f8akzHdYApBsoF/q tZmKWGCa67eYGL9LdsiO96ypx8OsJHUzIJjQFQ6+XgzE3sb+JbJXdiXEBz9bniYRiHhoOOLz Cm8hv3odp1coqr0/0/1WlTZhSAgk/nOHNIQMcacUsxLbVYMpBwJ1FQyw4bVvqYy2YLjW1jX4 ouryyHiEATNNwBcYzp8B52r8HuDjNyq0N/PlgVjDRzjlAa2e0g9VPrzF4noR5fLatA88tqBb /TC1NmEElbxpH/BPD8HfoHTKSXmSpaKVeSHZ+E/t6KK2nCurQRquko32WZ1he66RFxlkvgoo Oihu6BcRi8GDqnnx7smSyJdPBBbAqpJxfiAMXGG5Jn7I03uKxMAwt1rBUAye4YZ5vx2ESdF8 vlwxDIlN07ZwbjsmfTiF7cq1p9LwMrDZevzvllJyz3DAOlgapfEW6jQvvdT3Ssqh9AIFvHbD yYcQWQxPUmdOUEXUrsRIJUHuNi2hlXjSjZz9EjLt/cQ2XbX6BMkhdABN/KKI4fXFK25hH2wr G/c437wBB1cMdWF0CeE6VqlnOqJliT+MKosE7m/+u9vkUek7GUZAx0LVnO2ufC8zEW5Xrp3M FAZ9CMoqu4p6EWhQ935Xhu5iG6Fuh8aS5xbFOhSwBqW1qPe7gKdB24FZj1MctorsIkxXzNC/ k+EmZblCCJitJWRSGmB7fGEoDWqIy8XIGQeIygeQmMt4cTnoYw1pgLCSJBkCqHdszHuMWium XbQ9nF43uhNy55Qv0mmwbzZqx2corOWETUt3QD4b0ea6QxEI8m1brX9vDA38s18BIqeS1CAu l0NlM6f8P0CAPmxqcCdfAkeNOr3vqjYaVUwlXYqRsB8rGr1pxZPaKgKuFlDyFFV3tHokNMDS Gvaoktv6ZBaJxNGhocnMtvqW6zGIUUNfOkJt8w4jPITOvCdlyfdpUmCgHJ8OUi0wSDAdollZ f+mnT6EVypyNEie5GPeqx0h+bEq3Dsi4mjYWIr2yR+quZLHOiLKGOheYQvTMrtmhE9hnOkz2 4wCXydt408CONASnwGNqdJDRbz0BSZT6W/KRzx/KbfYf1sO9JAJAP7N27IxE7GJbIwO/tokC kqVAxcCoHKm3CWvAVzTNhhLNeO+Nb4i/ClTFXF9Yj6VN40LPN/HAFE3LMBsI9HKNYVLkJZJc hXyU57ZU6oVFWifpWh1gFuUhNUKSSlHTDmmZkKNSDM+Y4RhV0rO/NrldRHo7y4AEmy8ss5Wn lFq/lqzrUYrL+i6MPvrVQ==
  • Ironport-hdrordr: A9a23:0XzXIa5X9B9z7SCNKwPXwMzXdLJyesId70hD6qkXc20zTiX4rb HLoB1/73TJYVkqNE3I9eruBEDiexPhHPxOj7X5VI3KNGOKhILCFuBfxLqn7zr8GzDvss5xvJ 0QFpSW0eeAbmSSW/yKgjWFLw==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYPittYWCwptKqXU+Nvu1B7Q61VazM6MoA
  • Thread-topic: [PATCH v2] xen/arm: set CPSR Z bit when creating aarch32 guests

On 22/03/2022 20:28, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>
>
> The first 32 bytes of zImage are NOPs. When CONFIG_EFI is enabled in the
> kernel, certain versions of Linux will use an UNPREDICATABLE NOP
> encoding, sometimes resulting in an unbootable kernel. Whether the
> resulting kernel is bootable or not depends on the processor. See commit
> a92882a4d270 in the Linux kernel for all the details.
>
> All kernel releases starting from Linux 4.9 without commit a92882a4d270
> are affected.
>
> Fortunately there is a simple workaround: setting the "Z" bit in CPSR
> make it so those invalid NOP instructions are never executed. That is
> because the instruction is conditional (not equal). So, on QEMU at
> least, the instruction will end up to be ignored and not generate an
> exception. Setting the "Z" bit makes those kernel versions bootable
> again and it is harmless in the other cases.
>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>

A discussion relevant to this came up with XTF/ARM.

There is not currently a written ABI for the start state of vCPUs, and
there needs to be.  I know x86 is in a poor shape too, but we do at
least have some scraps of docs littered around and a plan to write some
proper Sphinx docs.

(A separate conversation was about booting from plain ELF files.  Linux
ARM Zimage is entirely undocumented for 32bit, and discussions with RMK
suggest that we've got bugs, while 64bit has insufficient documentation
to demonstrate that our logic is correct.)

In particular...

> ---
> Changes in v2:
> - improve commit message
> - add in-code comment
> - move PSR_Z to the beginning
> ---
>  xen/include/public/arch-arm.h | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
> index 94b31511dd..81cee95f14 100644
> --- a/xen/include/public/arch-arm.h
> +++ b/xen/include/public/arch-arm.h
> @@ -361,6 +361,7 @@ typedef uint64_t xen_callback_t;
>  #define PSR_DBG_MASK    (1<<9)        /* arm64: Debug Exception mask */
>  #define PSR_IT_MASK     (0x0600fc00)  /* Thumb If-Then Mask */
>  #define PSR_JAZELLE     (1<<24)       /* Jazelle Mode */
> +#define PSR_Z           (1<<30)       /* Zero condition flag */
>  
>  /* 32 bit modes */
>  #define PSR_MODE_USR 0x10
> @@ -383,7 +384,12 @@ typedef uint64_t xen_callback_t;
>  #define PSR_MODE_EL1t 0x04
>  #define PSR_MODE_EL0t 0x00
>  
> -#define PSR_GUEST32_INIT  
> (PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_SVC)
> +/*
> + * We set PSR_Z to be able to boot Linux kernel versions with an invalid
> + * encoding of the first 8 NOP instructions. See commit a92882a4d270 in
> + * Linux.
> + */
> +#define PSR_GUEST32_INIT  
> (PSR_Z|PSR_ABT_MASK|PSR_FIQ_MASK|PSR_IRQ_MASK|PSR_MODE_SVC)

... this change is either breaking the ABI, or demonstrates that these
values must not be in a public header file to begin with.

~Andrew

 


Rackspace

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