Skip to contentSkip to conversation

xen: have a more generic unaligned.h header (take 2)

PATCH In review Juergen Gross 3 participants 6 messages Dec 12, 2023 – Dec 21, 2023 Zstd

lore
Share & tools
lore
#0 lore raw

cover xen: have a more generic unaligned.h header (take 2)

Second try for the generic unaligned.h approach.

This time including a fix for building stubdom with libxenguest, which is using a cruel hack to reuse the hypervisor's decompressing code.

Juergen Gross (2):
xen: make include/xen/unaligned.h usable on all architectures
xen: remove asm/unaligned.h

 .../guest/xg_dom_decompress_unsafe_zstd.c     |  2 +-
 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                   | 53 +++++++++++--------
 xen/lib/xxhash32.c                            |  2 +-
 xen/lib/xxhash64.c                            |  2 +-
 10 files changed, 38 insertions(+), 37 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/unaligned.h
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/2 xen: make include/xen/unaligned.h usable on all architectures

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.

Add the definition of __packed to xg_dom_decompress_unsafe_zstd.c in libxenguest as it is using a cruel hack to reuse the hypervisor's decompressing code for stubdom.

Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 803f4e1eab7a

---
 .../guest/xg_dom_decompress_unsafe_zstd.c     |  2 +-
 xen/include/xen/unaligned.h                   | 53 +++++++++++--------
 2 files changed, 31 insertions(+), 24 deletions(-)
tools/libs/guest/xg_dom_decompress_unsafe_zstd.c +1 -1
index 01eafaaaa6..7cd266444b 100644
@@ -26,13 +26,13 @@ typedef uint64_t __be64;
 #define __force
 #define always_inline
 #define noinline
+#define __packed __attribute__((__packed__))
 
 #undef ERROR
 
 #define __BYTEORDER_HAS_U64__
 #define __TYPES_H__ /* xen/types.h guard */
 #include "../../xen/include/xen/byteorder/little_endian.h"
-#define __ASM_UNALIGNED_H__ /* asm/unaligned.h guard */
 #include "../../xen/include/xen/unaligned.h"
 #include "../../xen/include/xen/xxhash.h"
 #include "../../xen/lib/xxhash64.c"
xen/include/xen/unaligned.h +30 -23

109 lines not on this page · raw message

Signature · 1 line
2.35.3
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xen: make include/xen/unaligned.h usable on all architectures

Quoted 13 lines · Juergen Gross

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.

Quoted 7 lines

Add the definition of __packed to xg_dom_decompress_unsafe_zstd.c in libxenguest as it is using a cruel hack to reuse the hypervisor's decompressing code for stubdom.

Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 803f4e1eab7a

#3 lore raw

PATCH 2/2 xen: remove asm/unaligned.h

In reply to Juergen Gross

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.

---
 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
xen/arch/x86/include/asm/unaligned.h deleted +0 -6
deleted file mode 100644
index 6070801d4a..0000000000
@@ -1,6 +0,0 @@
-#ifndef __ASM_UNALIGNED_H__
-#define __ASM_UNALIGNED_H__
-
-#include <xen/unaligned.h>
-
-#endif /* __ASM_UNALIGNED_H__ */
xen/common/lz4/defs.h +1 -1
index 10609f5a53..6d81113266 100644
@@ -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)
xen/common/lzo.c +1 -1
index a87c76dded..cc03f0f554 100644
@@ -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
xen/common/unlzo.c +1 -1
index 74056778eb..bdcefa95b3 100644
@@ -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)
xen/common/xz/private.h +1 -1
index e6814250e8..2299705378 100644
@@ -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)
xen/common/zstd/mem.h +1 -1
index 2acae6a8ed..ae1e305126 100644
@@ -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
 
 /*-****************************************
xen/lib/xxhash32.c +1 -1
index e8d403e5ce..32efa651c5 100644
@@ -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
xen/lib/xxhash64.c +1 -1
index 481e76fbcf..1858e236fe 100644
@@ -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
 
 /*-*************************************
Signature · 1 line
2.35.3
#4 lore raw
In reply to Juergen Gross
Quoted 21 lines · Juergen Gross

Second try for the generic unaligned.h approach.

This time including a fix for building stubdom with libxenguest, which is using a cruel hack to reuse the hypervisor's decompressing code.

Juergen Gross (2):
xen: make include/xen/unaligned.h usable on all architectures
xen: remove asm/unaligned.h

  .../guest/xg_dom_decompress_unsafe_zstd.c     |  2 +-
  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                   | 53 +++++++++++--------
  xen/lib/xxhash32.c                            |  2 +-
  xen/lib/xxhash64.c                            |  2 +-
  10 files changed, 38 insertions(+), 37 deletions(-)
Quoted 2 lines

delete mode 100644 xen/arch/x86/include/asm/unaligned.h

Is anything missing for this series to go in?

Juergen

#5 lore raw
Quoted 25 lines · Juergen Gross
Quoted 20 lines · Juergen Gross

Second try for the generic unaligned.h approach.

This time including a fix for building stubdom with libxenguest, which is using a cruel hack to reuse the hypervisor's decompressing code.

Juergen Gross (2):
   xen: make include/xen/unaligned.h usable on all architectures
   xen: remove asm/unaligned.h

  .../guest/xg_dom_decompress_unsafe_zstd.c     |  2 +- 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                   | 53 +++++++++++-------- xen/lib/xxhash32.c                            |  2 +- xen/lib/xxhash64.c                            |  2 +-

Quoted 3 lines
  10 files changed, 38 insertions(+), 37 deletions(-)

  delete mode 100644 xen/arch/x86/include/asm/unaligned.h

Quoted 1 line

Is anything missing for this series to go in?

Oh - I'd not spotted it.  Lemme throw it through a full Gitlab CI run just to be sure.

~Andrew