All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] xen: have a more generic unaligned.h header
@ 2023-12-06  7:10 Juergen Gross
  2023-12-06  7:10 ` [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32 Juergen Gross
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Juergen Gross @ 2023-12-06  7:10 UTC (permalink / raw)
  To: xen-devel
  Cc: Juergen Gross, Stefano Stabellini, Julien Grall,
	Bertrand Marquis, Michal Orzel, Volodymyr Babchuk, Andrew Cooper,
	George Dunlap, Jan Beulich, Wei Liu, Roger Pau Monné

Update Xen's unaligned.h header to support all architectures, allowing
to remove the architecture specific variants (x86 only until now).

Changes in V2:
- new patch 1 (Julien Grall)
- adjusted patch 2 (Jan Beulich)

Juergen Gross (3):
  xen/arm: set -mno-unaligned-access compiler option for Arm32
  xen: make include/xen/unaligned.h usable on all architectures
  xen: remove asm/unaligned.h

 xen/arch/arm/arch.mk                 |  1 +
 xen/arch/x86/include/asm/unaligned.h |  6 ---
 xen/common/lz4/defs.h                |  2 +-
 xen/common/lzo.c                     |  2 +-
 xen/common/unlzo.c                   |  2 +-
 xen/common/xz/private.h              |  2 +-
 xen/common/zstd/mem.h                |  2 +-
 xen/include/xen/unaligned.h          | 77 +++++++++++++++-------------
 xen/lib/xxhash32.c                   |  2 +-
 xen/lib/xxhash64.c                   |  2 +-
 10 files changed, 50 insertions(+), 48 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/unaligned.h

-- 
2.35.3



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32
  2023-12-06  7:10 [PATCH v2 0/3] xen: have a more generic unaligned.h header Juergen Gross
@ 2023-12-06  7:10 ` Juergen Gross
  2023-12-06  8:44   ` Jan Beulich
  2023-12-06  7:10 ` [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures Juergen Gross
  2023-12-06  7:10 ` [PATCH v2 3/3] xen: remove asm/unaligned.h Juergen Gross
  2 siblings, 1 reply; 16+ messages in thread
From: Juergen Gross @ 2023-12-06  7:10 UTC (permalink / raw)
  To: xen-devel
  Cc: Juergen Gross, Stefano Stabellini, Julien Grall,
	Bertrand Marquis, Michal Orzel, Volodymyr Babchuk

As the hypervisor is disabling unaligned accesses for Arm32, set the
-mno-unaligned-access compiler option for building. This will prohibit
unaligned accesses when e.g. accessing 2- or 4-byte data items in
packed data structures.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- new patch
---
 xen/arch/arm/arch.mk | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xen/arch/arm/arch.mk b/xen/arch/arm/arch.mk
index 58db76c4e1..022dcda192 100644
--- a/xen/arch/arm/arch.mk
+++ b/xen/arch/arm/arch.mk
@@ -7,6 +7,7 @@ $(call cc-option-add,CFLAGS,CC,-Wnested-externs)
 # Prevent floating-point variables from creeping into Xen.
 CFLAGS-$(CONFIG_ARM_32) += -msoft-float
 CFLAGS-$(CONFIG_ARM_32) += -mcpu=cortex-a15
+CFLAGS-$(CONFIG_ARM_32) += -mno-unaligned-access
 
 CFLAGS-$(CONFIG_ARM_64) += -mcpu=generic
 CFLAGS-$(CONFIG_ARM_64) += -mgeneral-regs-only # No fp registers etc
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06  7:10 [PATCH v2 0/3] xen: have a more generic unaligned.h header Juergen Gross
  2023-12-06  7:10 ` [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32 Juergen Gross
@ 2023-12-06  7:10 ` Juergen Gross
  2023-12-06  8:46   ` Jan Beulich
  2023-12-06 10:59   ` Andrew Cooper
  2023-12-06  7:10 ` [PATCH v2 3/3] xen: remove asm/unaligned.h Juergen Gross
  2 siblings, 2 replies; 16+ messages in thread
From: Juergen Gross @ 2023-12-06  7:10 UTC (permalink / raw)
  To: xen-devel
  Cc: Juergen Gross, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Stefano Stabellini, Wei Liu, Arnd Bergmann

Instead of defining get_unaligned() and put_unaligned() in a way that
is only supporting architectures allowing unaligned accesses, use the
same approach as the Linux kernel and let the compiler do the
decision how to generate the code for probably unaligned data accesses.

Update include/xen/unaligned.h from include/asm-generic/unaligned.h of
the Linux kernel.

The generated code has been checked to be the same on x86.

Modify the Linux variant to not use underscore prefixed identifiers,
avoid unneeded parentheses and drop the 24-bit accessors.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 803f4e1eab7a
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- drop 24-bit accessors (Jan Beulich)
- avoid underscore prefixed identifiers (Jan Beulich)
- drop unneeded parentheses (Jan Beulich)
---
 xen/include/xen/unaligned.h | 77 ++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 35 deletions(-)

diff --git a/xen/include/xen/unaligned.h b/xen/include/xen/unaligned.h
index 0a2b16d05d..0ceb06a2bb 100644
--- a/xen/include/xen/unaligned.h
+++ b/xen/include/xen/unaligned.h
@@ -1,12 +1,4 @@
-/*
- * This header can be used by architectures where unaligned accesses work
- * without faulting, and at least reasonably efficiently.  Other architectures
- * will need to have a custom asm/unaligned.h.
- */
-#ifndef __ASM_UNALIGNED_H__
-#error "xen/unaligned.h should not be included directly - include asm/unaligned.h instead"
-#endif
-
+/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __XEN_UNALIGNED_H__
 #define __XEN_UNALIGNED_H__
 
@@ -15,67 +7,82 @@
 #include <asm/byteorder.h>
 #endif
 
-#define get_unaligned(p) (*(p))
-#define put_unaligned(val, p) (*(p) = (val))
+/*
+ * This is the most generic implementation of unaligned accesses
+ * and should work almost anywhere.
+ */
+
+#define get_unaligned_t_(type, ptr) ({					\
+	const struct { type x; } __packed *ptr_ = (typeof(ptr_))(ptr);	\
+	ptr_->x;							\
+})
+
+#define put_unaligned_t_(type, val, ptr) do {				\
+	struct { type x; } __packed *ptr_ = (typeof(ptr_))(ptr);	\
+	ptr_->x = val;							\
+} while (0)
+
+#define get_unaligned(ptr)	get_unaligned_t_(typeof(*(ptr)), ptr)
+#define put_unaligned(val, ptr) put_unaligned_t_(typeof(*(ptr)), val, ptr)
 
-static inline uint16_t get_unaligned_be16(const void *p)
+static inline u16 get_unaligned_le16(const void *p)
 {
-	return be16_to_cpup(p);
+	return le16_to_cpu(get_unaligned_t_(__le16, p));
 }
 
-static inline void put_unaligned_be16(uint16_t val, void *p)
+static inline u32 get_unaligned_le32(const void *p)
 {
-	*(__force __be16*)p = cpu_to_be16(val);
+	return le32_to_cpu(get_unaligned_t_(__le32, p));
 }
 
-static inline uint32_t get_unaligned_be32(const void *p)
+static inline u64 get_unaligned_le64(const void *p)
 {
-	return be32_to_cpup(p);
+	return le64_to_cpu(get_unaligned_t_(__le64, p));
 }
 
-static inline void put_unaligned_be32(uint32_t val, void *p)
+static inline void put_unaligned_le16(u16 val, void *p)
 {
-	*(__force __be32*)p = cpu_to_be32(val);
+	put_unaligned_t_(__le16, cpu_to_le16(val), p);
 }
 
-static inline uint64_t get_unaligned_be64(const void *p)
+static inline void put_unaligned_le32(u32 val, void *p)
 {
-	return be64_to_cpup(p);
+	put_unaligned_t_(__le32, cpu_to_le32(val), p);
 }
 
-static inline void put_unaligned_be64(uint64_t val, void *p)
+static inline void put_unaligned_le64(u64 val, void *p)
 {
-	*(__force __be64*)p = cpu_to_be64(val);
+	put_unaligned_t_(__le64, cpu_to_le64(val), p);
 }
 
-static inline uint16_t get_unaligned_le16(const void *p)
+static inline u16 get_unaligned_be16(const void *p)
 {
-	return le16_to_cpup(p);
+	return be16_to_cpu(get_unaligned_t_(__be16, p));
 }
 
-static inline void put_unaligned_le16(uint16_t val, void *p)
+static inline u32 get_unaligned_be32(const void *p)
 {
-	*(__force __le16*)p = cpu_to_le16(val);
+	return be32_to_cpu(get_unaligned_t_(__be32, p));
 }
 
-static inline uint32_t get_unaligned_le32(const void *p)
+static inline u64 get_unaligned_be64(const void *p)
 {
-	return le32_to_cpup(p);
+	return be64_to_cpu(get_unaligned_t_(__be64, p));
 }
 
-static inline void put_unaligned_le32(uint32_t val, void *p)
+static inline void put_unaligned_be16(u16 val, void *p)
 {
-	*(__force __le32*)p = cpu_to_le32(val);
+	put_unaligned_t_(__be16, cpu_to_be16(val), p);
 }
 
-static inline uint64_t get_unaligned_le64(const void *p)
+static inline void put_unaligned_be32(u32 val, void *p)
 {
-	return le64_to_cpup(p);
+	put_unaligned_t_(__be32, cpu_to_be32(val), p);
 }
 
-static inline void put_unaligned_le64(uint64_t val, void *p)
+static inline void put_unaligned_be64(u64 val, void *p)
 {
-	*(__force __le64*)p = cpu_to_le64(val);
+	put_unaligned_t_(__be64, cpu_to_be64(val), p);
 }
 
 #endif /* __XEN_UNALIGNED_H__ */
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/3] xen: remove asm/unaligned.h
  2023-12-06  7:10 [PATCH v2 0/3] xen: have a more generic unaligned.h header Juergen Gross
  2023-12-06  7:10 ` [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32 Juergen Gross
  2023-12-06  7:10 ` [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures Juergen Gross
@ 2023-12-06  7:10 ` Juergen Gross
  2 siblings, 0 replies; 16+ messages in thread
From: Juergen Gross @ 2023-12-06  7:10 UTC (permalink / raw)
  To: xen-devel
  Cc: Juergen Gross, Jan Beulich, Andrew Cooper, Roger Pau Monné,
	Wei Liu, George Dunlap, Julien Grall, Stefano Stabellini

With include/xen/unaligned.h now dealing properly with unaligned
accesses for all architectures, asm/unaligned.h can be removed and
users can be switched to include xen/unaligned.h instead.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/x86/include/asm/unaligned.h | 6 ------
 xen/common/lz4/defs.h                | 2 +-
 xen/common/lzo.c                     | 2 +-
 xen/common/unlzo.c                   | 2 +-
 xen/common/xz/private.h              | 2 +-
 xen/common/zstd/mem.h                | 2 +-
 xen/lib/xxhash32.c                   | 2 +-
 xen/lib/xxhash64.c                   | 2 +-
 8 files changed, 7 insertions(+), 13 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/unaligned.h

diff --git a/xen/arch/x86/include/asm/unaligned.h b/xen/arch/x86/include/asm/unaligned.h
deleted file mode 100644
index 6070801d4a..0000000000
--- a/xen/arch/x86/include/asm/unaligned.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __ASM_UNALIGNED_H__
-#define __ASM_UNALIGNED_H__
-
-#include <xen/unaligned.h>
-
-#endif /* __ASM_UNALIGNED_H__ */
diff --git a/xen/common/lz4/defs.h b/xen/common/lz4/defs.h
index 10609f5a53..6d81113266 100644
--- a/xen/common/lz4/defs.h
+++ b/xen/common/lz4/defs.h
@@ -10,7 +10,7 @@
 
 #ifdef __XEN__
 #include <asm/byteorder.h>
-#include <asm/unaligned.h>
+#include <xen/unaligned.h>
 #else
 
 static inline u16 get_unaligned_le16(const void *p)
diff --git a/xen/common/lzo.c b/xen/common/lzo.c
index a87c76dded..cc03f0f554 100644
--- a/xen/common/lzo.c
+++ b/xen/common/lzo.c
@@ -97,7 +97,7 @@
 #ifdef __XEN__
 #include <xen/lib.h>
 #include <asm/byteorder.h>
-#include <asm/unaligned.h>
+#include <xen/unaligned.h>
 #else
 #define get_unaligned_le16(_p) (*(u16 *)(_p))
 #endif
diff --git a/xen/common/unlzo.c b/xen/common/unlzo.c
index 74056778eb..bdcefa95b3 100644
--- a/xen/common/unlzo.c
+++ b/xen/common/unlzo.c
@@ -34,7 +34,7 @@
 
 #ifdef __XEN__
 #include <asm/byteorder.h>
-#include <asm/unaligned.h>
+#include <xen/unaligned.h>
 #else
 
 static inline u16 get_unaligned_be16(const void *p)
diff --git a/xen/common/xz/private.h b/xen/common/xz/private.h
index e6814250e8..2299705378 100644
--- a/xen/common/xz/private.h
+++ b/xen/common/xz/private.h
@@ -13,7 +13,7 @@
 #ifdef __XEN__
 #include <xen/kernel.h>
 #include <asm/byteorder.h>
-#include <asm/unaligned.h>
+#include <xen/unaligned.h>
 #else
 
 static inline u32 get_unaligned_le32(const void *p)
diff --git a/xen/common/zstd/mem.h b/xen/common/zstd/mem.h
index 2acae6a8ed..ae1e305126 100644
--- a/xen/common/zstd/mem.h
+++ b/xen/common/zstd/mem.h
@@ -23,7 +23,7 @@
 #ifdef __XEN__
 #include <xen/string.h> /* memcpy */
 #include <xen/types.h>  /* size_t, ptrdiff_t */
-#include <asm/unaligned.h>
+#include <xen/unaligned.h>
 #endif
 
 /*-****************************************
diff --git a/xen/lib/xxhash32.c b/xen/lib/xxhash32.c
index e8d403e5ce..32efa651c5 100644
--- a/xen/lib/xxhash32.c
+++ b/xen/lib/xxhash32.c
@@ -42,7 +42,7 @@
 #include <xen/errno.h>
 #include <xen/string.h>
 #include <xen/xxhash.h>
-#include <asm/unaligned.h>
+#include <xen/unaligned.h>
 
 /*-*************************************
  * Macros
diff --git a/xen/lib/xxhash64.c b/xen/lib/xxhash64.c
index 481e76fbcf..1858e236fe 100644
--- a/xen/lib/xxhash64.c
+++ b/xen/lib/xxhash64.c
@@ -43,7 +43,7 @@
 #include <xen/errno.h>
 #include <xen/string.h>
 #include <xen/xxhash.h>
-#include <asm/unaligned.h>
+#include <xen/unaligned.h>
 #endif
 
 /*-*************************************
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32
  2023-12-06  7:10 ` [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32 Juergen Gross
@ 2023-12-06  8:44   ` Jan Beulich
  2023-12-06 10:00     ` Juergen Gross
  0 siblings, 1 reply; 16+ messages in thread
From: Jan Beulich @ 2023-12-06  8:44 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Stefano Stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
	Volodymyr Babchuk, xen-devel

On 06.12.2023 08:10, Juergen Gross wrote:
> As the hypervisor is disabling unaligned accesses for Arm32, set the
> -mno-unaligned-access compiler option for building. This will prohibit
> unaligned accesses when e.g. accessing 2- or 4-byte data items in
> packed data structures.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Assuming this will want backporting, should it have some Fixes: tag?

Jan


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06  7:10 ` [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures Juergen Gross
@ 2023-12-06  8:46   ` Jan Beulich
  2023-12-06 10:02     ` Juergen Gross
  2023-12-06 10:52     ` Andrew Cooper
  2023-12-06 10:59   ` Andrew Cooper
  1 sibling, 2 replies; 16+ messages in thread
From: Jan Beulich @ 2023-12-06  8:46 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini,
	Wei Liu, Arnd Bergmann, xen-devel

On 06.12.2023 08:10, Juergen Gross wrote:
> Instead of defining get_unaligned() and put_unaligned() in a way that
> is only supporting architectures allowing unaligned accesses, use the
> same approach as the Linux kernel and let the compiler do the
> decision how to generate the code for probably unaligned data accesses.
> 
> Update include/xen/unaligned.h from include/asm-generic/unaligned.h of
> the Linux kernel.
> 
> The generated code has been checked to be the same on x86.
> 
> Modify the Linux variant to not use underscore prefixed identifiers,
> avoid unneeded parentheses and drop the 24-bit accessors.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 803f4e1eab7a
> Signed-off-by: Juergen Gross <jgross@suse.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

Nevertheless ...

> @@ -15,67 +7,82 @@
>  #include <asm/byteorder.h>
>  #endif
>  
> -#define get_unaligned(p) (*(p))
> -#define put_unaligned(val, p) (*(p) = (val))
> +/*
> + * This is the most generic implementation of unaligned accesses
> + * and should work almost anywhere.
> + */
> +
> +#define get_unaligned_t_(type, ptr) ({					\

..., do we need the trailing underscores here in addition to the already
sufficiently clear _t suffixes? (Leaving aside that ..._t generally is to
denote types, not macros or functions.)

Jan


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32
  2023-12-06  8:44   ` Jan Beulich
@ 2023-12-06 10:00     ` Juergen Gross
  2023-12-06 10:57       ` Julien Grall
  0 siblings, 1 reply; 16+ messages in thread
From: Juergen Gross @ 2023-12-06 10:00 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Stefano Stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
	Volodymyr Babchuk, xen-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 773 bytes --]

On 06.12.23 09:44, Jan Beulich wrote:
> On 06.12.2023 08:10, Juergen Gross wrote:
>> As the hypervisor is disabling unaligned accesses for Arm32, set the
>> -mno-unaligned-access compiler option for building. This will prohibit
>> unaligned accesses when e.g. accessing 2- or 4-byte data items in
>> packed data structures.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> Assuming this will want backporting, should it have some Fixes: tag?

IMHO this might not be needed, but the Arm maintainers should have the
final say.

This option is especially important after the whole series has been
applied, as get_unaligned() and put_unaligned() can then be used in Arm32
code, too. And without the added option this could cause crashes.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06  8:46   ` Jan Beulich
@ 2023-12-06 10:02     ` Juergen Gross
  2023-12-06 11:02       ` Jan Beulich
  2023-12-06 10:52     ` Andrew Cooper
  1 sibling, 1 reply; 16+ messages in thread
From: Juergen Gross @ 2023-12-06 10:02 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini,
	Wei Liu, Arnd Bergmann, xen-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1566 bytes --]

On 06.12.23 09:46, Jan Beulich wrote:
> On 06.12.2023 08:10, Juergen Gross wrote:
>> Instead of defining get_unaligned() and put_unaligned() in a way that
>> is only supporting architectures allowing unaligned accesses, use the
>> same approach as the Linux kernel and let the compiler do the
>> decision how to generate the code for probably unaligned data accesses.
>>
>> Update include/xen/unaligned.h from include/asm-generic/unaligned.h of
>> the Linux kernel.
>>
>> The generated code has been checked to be the same on x86.
>>
>> Modify the Linux variant to not use underscore prefixed identifiers,
>> avoid unneeded parentheses and drop the 24-bit accessors.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 803f4e1eab7a
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> Acked-by: Jan Beulich <jbeulich@suse.com>
> 
> Nevertheless ...
> 
>> @@ -15,67 +7,82 @@
>>   #include <asm/byteorder.h>
>>   #endif
>>   
>> -#define get_unaligned(p) (*(p))
>> -#define put_unaligned(val, p) (*(p) = (val))
>> +/*
>> + * This is the most generic implementation of unaligned accesses
>> + * and should work almost anywhere.
>> + */
>> +
>> +#define get_unaligned_t_(type, ptr) ({					\
> 
> ..., do we need the trailing underscores here in addition to the already
> sufficiently clear _t suffixes? (Leaving aside that ..._t generally is to
> denote types, not macros or functions.)

Maybe we should just name it get_unaligned_type()?


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06  8:46   ` Jan Beulich
  2023-12-06 10:02     ` Juergen Gross
@ 2023-12-06 10:52     ` Andrew Cooper
  1 sibling, 0 replies; 16+ messages in thread
From: Andrew Cooper @ 2023-12-06 10:52 UTC (permalink / raw)
  To: Jan Beulich, Juergen Gross
  Cc: George Dunlap, Julien Grall, Stefano Stabellini, Wei Liu,
	Arnd Bergmann, xen-devel

On 06/12/2023 8:46 am, Jan Beulich wrote:
> On 06.12.2023 08:10, Juergen Gross wrote:
>> Instead of defining get_unaligned() and put_unaligned() in a way that
>> is only supporting architectures allowing unaligned accesses, use the
>> same approach as the Linux kernel and let the compiler do the
>> decision how to generate the code for probably unaligned data accesses.
>>
>> Update include/xen/unaligned.h from include/asm-generic/unaligned.h of
>> the Linux kernel.
>>
>> The generated code has been checked to be the same on x86.
>>
>> Modify the Linux variant to not use underscore prefixed identifiers,
>> avoid unneeded parentheses and drop the 24-bit accessors.
>>
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 803f4e1eab7a
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> Acked-by: Jan Beulich <jbeulich@suse.com>
>
> Nevertheless ...
>
>> @@ -15,67 +7,82 @@
>>  #include <asm/byteorder.h>
>>  #endif
>>  
>> -#define get_unaligned(p) (*(p))
>> -#define put_unaligned(val, p) (*(p) = (val))
>> +/*
>> + * This is the most generic implementation of unaligned accesses
>> + * and should work almost anywhere.
>> + */
>> +
>> +#define get_unaligned_t_(type, ptr) ({					\
> ..., do we need the trailing underscores here in addition to the already
> sufficiently clear _t suffixes? (Leaving aside that ..._t generally is to
> denote types, not macros or functions.)

_t is fine.  It's what we use for {min,max}_t() and friends too.

~Andrew


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32
  2023-12-06 10:00     ` Juergen Gross
@ 2023-12-06 10:57       ` Julien Grall
  2023-12-06 19:32         ` Julien Grall
  0 siblings, 1 reply; 16+ messages in thread
From: Julien Grall @ 2023-12-06 10:57 UTC (permalink / raw)
  To: Juergen Gross, Jan Beulich
  Cc: Stefano Stabellini, Bertrand Marquis, Michal Orzel,
	Volodymyr Babchuk, xen-devel

Hi Juergen,

On 06/12/2023 10:00, Juergen Gross wrote:
> On 06.12.23 09:44, Jan Beulich wrote:
>> On 06.12.2023 08:10, Juergen Gross wrote:
>>> As the hypervisor is disabling unaligned accesses for Arm32, set the
>>> -mno-unaligned-access compiler option for building. This will prohibit
>>> unaligned accesses when e.g. accessing 2- or 4-byte data items in
>>> packed data structures.
>>>
>>> Signed-off-by: Juergen Gross <jgross@suse.com>
>>
>> Assuming this will want backporting, should it have some Fixes: tag?
> 
> IMHO this might not be needed

You probably miss the discussion between Arnd and I where I pointed out 
that this should fix [1]. I haven't yet tested to confirm.

[1] 
https://lore.kernel.org/xen-devel/c71163f6-2646-6fae-cb22-600eb0486539@xen.org/

> 
> 
> Juergen

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06  7:10 ` [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures Juergen Gross
  2023-12-06  8:46   ` Jan Beulich
@ 2023-12-06 10:59   ` Andrew Cooper
  2023-12-06 11:33     ` Andrew Cooper
  2023-12-06 11:40     ` Juergen Gross
  1 sibling, 2 replies; 16+ messages in thread
From: Andrew Cooper @ 2023-12-06 10:59 UTC (permalink / raw)
  To: Juergen Gross, xen-devel
  Cc: George Dunlap, Jan Beulich, Julien Grall, Stefano Stabellini,
	Wei Liu, Arnd Bergmann

On 06/12/2023 7:10 am, Juergen Gross wrote:
> diff --git a/xen/include/xen/unaligned.h b/xen/include/xen/unaligned.h
> index 0a2b16d05d..0ceb06a2bb 100644
> --- a/xen/include/xen/unaligned.h
> +++ b/xen/include/xen/unaligned.h
> @@ -1,12 +1,4 @@
>
> -static inline uint16_t get_unaligned_be16(const void *p)
> +static inline u16 get_unaligned_le16(const void *p)

I've done some cleanup for you.

You swapped away from using stdint types, and shuffled the order of
functions, which made the diff basically illegible.

https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=commitdiff;h=1d448a845ee4ad74cab76563b3a2552b10953186
is a much shorter diff.

~Andrew


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06 10:02     ` Juergen Gross
@ 2023-12-06 11:02       ` Jan Beulich
  0 siblings, 0 replies; 16+ messages in thread
From: Jan Beulich @ 2023-12-06 11:02 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini,
	Wei Liu, Arnd Bergmann, xen-devel

On 06.12.2023 11:02, Juergen Gross wrote:
> On 06.12.23 09:46, Jan Beulich wrote:
>> On 06.12.2023 08:10, Juergen Gross wrote:
>>> @@ -15,67 +7,82 @@
>>>   #include <asm/byteorder.h>
>>>   #endif
>>>   
>>> -#define get_unaligned(p) (*(p))
>>> -#define put_unaligned(val, p) (*(p) = (val))
>>> +/*
>>> + * This is the most generic implementation of unaligned accesses
>>> + * and should work almost anywhere.
>>> + */
>>> +
>>> +#define get_unaligned_t_(type, ptr) ({					\
>>
>> ..., do we need the trailing underscores here in addition to the already
>> sufficiently clear _t suffixes? (Leaving aside that ..._t generally is to
>> denote types, not macros or functions.)
> 
> Maybe we should just name it get_unaligned_type()?

I wouldn't mind, but Andrew mentioning min_t() / max_t() suggests the
present naming might be okay, too. (Still those two macros signal
something quite different with their _t suffixes.)

Jan


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06 10:59   ` Andrew Cooper
@ 2023-12-06 11:33     ` Andrew Cooper
  2023-12-06 11:43       ` Juergen Gross
  2023-12-06 11:40     ` Juergen Gross
  1 sibling, 1 reply; 16+ messages in thread
From: Andrew Cooper @ 2023-12-06 11:33 UTC (permalink / raw)
  To: Juergen Gross, xen-devel
  Cc: George Dunlap, Jan Beulich, Julien Grall, Stefano Stabellini,
	Wei Liu, Arnd Bergmann

On 06/12/2023 10:59 am, Andrew Cooper wrote:
> On 06/12/2023 7:10 am, Juergen Gross wrote:
>> diff --git a/xen/include/xen/unaligned.h b/xen/include/xen/unaligned.h
>> index 0a2b16d05d..0ceb06a2bb 100644
>> --- a/xen/include/xen/unaligned.h
>> +++ b/xen/include/xen/unaligned.h
>> @@ -1,12 +1,4 @@
>>
>> -static inline uint16_t get_unaligned_be16(const void *p)
>> +static inline u16 get_unaligned_le16(const void *p)
> I've done some cleanup for you.
>
> You swapped away from using stdint types, and shuffled the order of
> functions, which made the diff basically illegible.
>
> https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=commitdiff;h=1d448a845ee4ad74cab76563b3a2552b10953186
> is a much shorter diff.

Oh, and the Origin link ought to be

https://git.kernel.org/torvalds/c/803f4e1eab7a8938ba3a3c30dd4eb5e9eeef5e63

which is shorter and also lets people on the web view it.

~Andrew


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06 10:59   ` Andrew Cooper
  2023-12-06 11:33     ` Andrew Cooper
@ 2023-12-06 11:40     ` Juergen Gross
  1 sibling, 0 replies; 16+ messages in thread
From: Juergen Gross @ 2023-12-06 11:40 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel
  Cc: George Dunlap, Jan Beulich, Julien Grall, Stefano Stabellini,
	Wei Liu, Arnd Bergmann


[-- Attachment #1.1.1: Type: text/plain, Size: 774 bytes --]

On 06.12.23 11:59, Andrew Cooper wrote:
> On 06/12/2023 7:10 am, Juergen Gross wrote:
>> diff --git a/xen/include/xen/unaligned.h b/xen/include/xen/unaligned.h
>> index 0a2b16d05d..0ceb06a2bb 100644
>> --- a/xen/include/xen/unaligned.h
>> +++ b/xen/include/xen/unaligned.h
>> @@ -1,12 +1,4 @@
>>
>> -static inline uint16_t get_unaligned_be16(const void *p)
>> +static inline u16 get_unaligned_le16(const void *p)
> 
> I've done some cleanup for you.
> 
> You swapped away from using stdint types, and shuffled the order of
> functions, which made the diff basically illegible.
> 
> https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=commitdiff;h=1d448a845ee4ad74cab76563b3a2552b10953186
> is a much shorter diff.

Works for me.


Juergen


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures
  2023-12-06 11:33     ` Andrew Cooper
@ 2023-12-06 11:43       ` Juergen Gross
  0 siblings, 0 replies; 16+ messages in thread
From: Juergen Gross @ 2023-12-06 11:43 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel
  Cc: George Dunlap, Jan Beulich, Julien Grall, Stefano Stabellini,
	Wei Liu, Arnd Bergmann


[-- Attachment #1.1.1: Type: text/plain, Size: 1154 bytes --]

On 06.12.23 12:33, Andrew Cooper wrote:
> On 06/12/2023 10:59 am, Andrew Cooper wrote:
>> On 06/12/2023 7:10 am, Juergen Gross wrote:
>>> diff --git a/xen/include/xen/unaligned.h b/xen/include/xen/unaligned.h
>>> index 0a2b16d05d..0ceb06a2bb 100644
>>> --- a/xen/include/xen/unaligned.h
>>> +++ b/xen/include/xen/unaligned.h
>>> @@ -1,12 +1,4 @@
>>>
>>> -static inline uint16_t get_unaligned_be16(const void *p)
>>> +static inline u16 get_unaligned_le16(const void *p)
>> I've done some cleanup for you.
>>
>> You swapped away from using stdint types, and shuffled the order of
>> functions, which made the diff basically illegible.
>>
>> https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=commitdiff;h=1d448a845ee4ad74cab76563b3a2552b10953186
>> is a much shorter diff.
> 
> Oh, and the Origin link ought to be
> 
> https://git.kernel.org/torvalds/c/803f4e1eab7a8938ba3a3c30dd4eb5e9eeef5e63
> 
> which is shorter and also lets people on the web view it.

Then we should update docs/process/sending-patches.pandoc to reflect that
possibility to reference a commit (I wouldn't like that change, though).


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32
  2023-12-06 10:57       ` Julien Grall
@ 2023-12-06 19:32         ` Julien Grall
  0 siblings, 0 replies; 16+ messages in thread
From: Julien Grall @ 2023-12-06 19:32 UTC (permalink / raw)
  To: Juergen Gross, Jan Beulich, Stefano Stabellini
  Cc: Stefano Stabellini, Michal Orzel, Volodymyr Babchuk, xen-devel



On 06/12/2023 10:57, Julien Grall wrote:
> Hi Juergen,
> 
> On 06/12/2023 10:00, Juergen Gross wrote:
>> On 06.12.23 09:44, Jan Beulich wrote:
>>> On 06.12.2023 08:10, Juergen Gross wrote:
>>>> As the hypervisor is disabling unaligned accesses for Arm32, set the
>>>> -mno-unaligned-access compiler option for building. This will prohibit
>>>> unaligned accesses when e.g. accessing 2- or 4-byte data items in
>>>> packed data structures.
>>>>
>>>> Signed-off-by: Juergen Gross <jgross@suse.com>
>>>
>>> Assuming this will want backporting, should it have some Fixes: tag?
>>
>> IMHO this might not be needed
> 
> You probably miss the discussion between Arnd and I where I pointed out 
> that this should fix [1]. I haven't yet tested to confirm.

I can't find the GCC binaries I was using anymore :(. But I still think 
it is a good idea to backport it.

@Stefano can you add it in your list?

Acked-by: Julien Grall <jgrall@amazon.com>

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-12-06 19:33 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06  7:10 [PATCH v2 0/3] xen: have a more generic unaligned.h header Juergen Gross
2023-12-06  7:10 ` [PATCH v2 1/3] xen/arm: set -mno-unaligned-access compiler option for Arm32 Juergen Gross
2023-12-06  8:44   ` Jan Beulich
2023-12-06 10:00     ` Juergen Gross
2023-12-06 10:57       ` Julien Grall
2023-12-06 19:32         ` Julien Grall
2023-12-06  7:10 ` [PATCH v2 2/3] xen: make include/xen/unaligned.h usable on all architectures Juergen Gross
2023-12-06  8:46   ` Jan Beulich
2023-12-06 10:02     ` Juergen Gross
2023-12-06 11:02       ` Jan Beulich
2023-12-06 10:52     ` Andrew Cooper
2023-12-06 10:59   ` Andrew Cooper
2023-12-06 11:33     ` Andrew Cooper
2023-12-06 11:43       ` Juergen Gross
2023-12-06 11:40     ` Juergen Gross
2023-12-06  7:10 ` [PATCH v2 3/3] xen: remove asm/unaligned.h Juergen Gross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.