x86/Dom0: support zstd compressed kernels
cover x86/Dom0: support zstd compressed kernels
Linux has been offering this option of kernel compression for quite some time - about time for us to start supporting it. The series here covers Dom0 only; I simply didn't have time to see about also integrating this into libxenguest.
1: introduce unaligned.h
2: lib: introduce xxhash
3: x86/Dom0: support zstd compressed kernels
Jan
PATCH 1/3 introduce unaligned.h
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
No change in generated code.
---
Iirc use of include/asm-generic/ was disliked, hence the generic header goes into include/xen/.
xen/common/lz4/defs.h +6 -3
@@ -10,18 +10,21 @@#ifdef __XEN__#include <asm/byteorder.h> -#endif +#include <asm/unaligned.h> +#else -static inline u16 INIT get_unaligned_le16(const void *p) +static inline u16 get_unaligned_le16 (const void *p) {return le16_to_cpup (p); } -static inline u32 INIT get_unaligned_le32(const void *p) +static inline u32 get_unaligned_le32 (const void *p) {return le32_to_cpup (p); } +#endif +/* * Detects 64 bits mode */
xen/common/lzo.c +3 -4
@@ -97,13 +97,12 @@#ifdef __XEN__#include <xen/lib.h> #include <asm/byteorder.h> +#include <asm/unaligned.h> +#else +#define get_unaligned_le16 (_p) (*(u16 *)(_p))#endif #include <xen/lzo.h> -#define get_unaligned (_p) (*(_p)) -#define put_unaligned (_val,_p) (*(_p)=_val) -#define get_unaligned_le16 (_p) (*(u16 *)(_p)) -#define get_unaligned_le32 (_p) (*(u32 *)(_p))#include "decompress.h"
xen/common/unlzo.c +4 -15
@@ -34,30 +34,19 @@#ifdef __XEN__#include <asm/byteorder.h> -#endif +#include <asm/unaligned.h> +#else -#if 1 /* ndef CONFIG_??? */ -static inline u16 INIT get_unaligned_be16(void *p) +static inline u16 get_unaligned_be16 (const void *p) {return be16_to_cpup (p); } -static inline u32 INIT get_unaligned_be32(void *p) +static inline u32 get_unaligned_be32 (const void *p) {return be32_to_cpup (p); } -#else -#include <asm/unaligned.h> - -static inline u16 INIT get_unaligned_be16(void *p) -{ -return be16_to_cpu (__get_unaligned (p,2 )); -} -static inline u32 INIT get_unaligned_be32(void *p) -{ -return be32_to_cpu (__get_unaligned (p,4 )); -}#endif static const unsigned char lzop_magic[] = {
xen/common/xz/private.h +6 -17
@@ -13,34 +13,23 @@#ifdef __XEN__#include <xen/kernel.h> #include <asm/byteorder.h> -#endif - -#define get_le32 (p) le32_to_cpup((const uint32_t *)(p)) +#include <asm/unaligned.h> +#else -#if 1 /* ndef CONFIG_??? */ -static inline u32 INIT get_unaligned_le32(void *p) +static inline u32 get_unaligned_le32 (const void *p) {return le32_to_cpup (p); } -static inline void INIT put_unaligned_le32(u32 val, void *p) +static inline void put_unaligned_le32 (u32 val,void *p) { *(__force __le32 *)p =cpu_to_le32 (val); } -#else -#include <asm/unaligned.h> - -static inline u32 INIT get_unaligned_le32(void *p) -{ -return le32_to_cpu (__get_unaligned (p,4 )); -} -static inline void INIT put_unaligned_le32(u32 val, void *p) -{ -__put_unaligned (cpu_to_le32 (val), p,4 ); -}#endif +#define get_le32 (p) le32_to_cpup((const uint32_t *)(p)) +#define false 0#define true 1
xen/include/asm-x86/unaligned.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __ASM_UNALIGNED_H__ +#define __ASM_UNALIGNED_H__ + +#include <xen/unaligned.h> + +#endif /* __ASM_UNALIGNED_H__ */
xen/include/xen/unaligned.h new file +79 -0
79 lines not on this page · raw message
Re: [PATCH 1/3] introduce unaligned.h
Quoted 9 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
Quoted 6 lines
No change in generated code.
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.
Really? I think its going to be the only sane way of fixing up some of our header tangle.
This series probably isn't the right place to fix this argument, so
However, presumably we're going to want an ARM side of this imminently?
Re: [PATCH 1/3] introduce unaligned.h
Quoted 17 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
Quoted 6 lines
No change in generated code.
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.
Quoted 5 lines
Really? I think its going to be the only sane way of fixing up some of our header tangle.
This series probably isn't the right place to fix this argument, so
Acked-by Andrew Cooper <[email protected]>
Thanks.
Quoted 1 line
However, presumably we're going to want an ARM side of this imminently?
Why? It's only used (and going to be further used) by code not built for Arm. So while it certainly would be nice for such a header to also appear there (and the x86-special casing going away in patch 2), it's not a strict requirement at this point. Therefore I'd prefer to leave this to the Arm maintainers (and probably for 4.16).
Jan
Re: [PATCH 1/3] introduce unaligned.h
Quoted 26 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
Quoted 6 lines
No change in generated code.
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.Quoted 5 lines
Really? I think its going to be the only sane way of fixing up some of our header tangle.
This series probably isn't the right place to fix this argument, so
Acked-by Andrew Cooper <[email protected]>Thanks.
Quoted 8 lines
Quoted 1 line
However, presumably we're going to want an ARM side of this imminently?
Why? It's only used (and going to be further used) by code not built for Arm. So while it certainly would be nice for such a header to also appear there (and the x86-special casing going away in patch 2), it's not a strict requirement at this point. Therefore I'd prefer to leave this to the Arm maintainers (and probably for 4.16).
I was wrong here, when it comes to an Arm64 build with ACPI support enabled. xen/arch/arm/efi/efi-dom0.c has
#define XZ_EXTERN STATIC
#include "../../../common/xz/crc32.c"
in order to later do
xz_crc32_init();
efi_sys_tbl->Hdr.CRC32 = xz_crc32((uint8_t *)efi_sys_tbl,
efi_sys_tbl->Hdr.HeaderSize, 0);Urgh. Why in the world does xz code get re-used like this? If we need generic crc32 support, such should imo live in xen/lib/.
So we have two possible courses of action: Eliminate this unsuitable re-use of code, or introduce asm/unaligned.h for Arm (or at least Arm64, in case it makes a difference) right away.
Julien, Stefano?
Thanks, Jan
Re: [PATCH 1/3] introduce unaligned.h
Quoted 48 lines · Jan Beulich
Quoted 26 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
Quoted 6 lines
No change in generated code.
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.Quoted 5 lines
Really? I think its going to be the only sane way of fixing up some of our header tangle.
This series probably isn't the right place to fix this argument, so
Acked-by Andrew Cooper <[email protected]>Thanks.
Quoted 8 lines
Quoted 1 line
However, presumably we're going to want an ARM side of this imminently?
Why? It's only used (and going to be further used) by code not built for Arm. So while it certainly would be nice for such a header to also appear there (and the x86-special casing going away in patch 2), it's not a strict requirement at this point. Therefore I'd prefer to leave this to the Arm maintainers (and probably for 4.16).
I was wrong here, when it comes to an Arm64 build with ACPI support enabled.
xen/arch/arm/efi/efi-dom0.chas#define
XZ_EXTERNSTATIC
#include "../../../common/xz/crc32.c"in order to later do
xz_crc32_init(); efi_sys_tbl->Hdr.CRC32 = xz_crc32((uint8_t *)efi_sys_tbl, efi_sys_tbl->Hdr.HeaderSize, 0);
Quoted 8 lines
Urgh. Why in the world does xz code get re-used like this? If we need generic crc32 support, such should imo live in xen/lib/.
So we have two possible courses of action: Eliminate this unsuitable re-use of code, or introduce
asm/unaligned.hfor Arm (or at least Arm64, in case it makes a difference) right away.
There's an even easier 3rd option: Drop #include "private.h" from xz/crc32.c. I'll check all the various builds, but I don't foresee any problems. In case there indeed are none, this would be my preferred short-term workaround (which I'd fold right into this patch).
Jan
Re: [PATCH 1/3] introduce unaligned.h
In reply to Jan BeulichHi Jan,
Quoted 44 lines · Jan Beulich
Quoted 26 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
Quoted 6 lines
No change in generated code.
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.Quoted 5 lines
Really? I think its going to be the only sane way of fixing up some of our header tangle.
This series probably isn't the right place to fix this argument, so
Acked-by Andrew Cooper <[email protected]>Thanks.
Quoted 8 lines
Quoted 1 line
However, presumably we're going to want an ARM side of this imminently?
Why? It's only used (and going to be further used) by code not built for Arm. So while it certainly would be nice for such a header to also appear there (and the x86-special casing going away in patch 2), it's not a strict requirement at this point. Therefore I'd prefer to leave this to the Arm maintainers (and probably for 4.16).
I was wrong here, when it comes to an Arm64 build with ACPI support enabled.
xen/arch/arm/efi/efi-dom0.chas#define
XZ_EXTERNSTATIC
#include "../../../common/xz/crc32.c"in order to later do
Quoted 7 lines
xz_crc32_init(); efi_sys_tbl->Hdr.CRC32 = xz_crc32((uint8_t *)efi_sys_tbl, efi_sys_tbl->Hdr.HeaderSize, 0);Urgh. Why in the world does xz code get re-used like this? If we need generic crc32 support, such should imo live in xen/lib/.
I suspect this was in order to make the EFI stub completely independent to Xen (this is the case for Linux Arm). It turns out we now have an hybrid model as we re-use pass some information in the DT and other via variables.
Quoted 5 lines
So we have two possible courses of action: Eliminate this unsuitable re-use of code, or introduce
asm/unaligned.hfor Arm (or at least Arm64, in case it makes a difference) right away.
EFI stub is only supported for Arm64. So it should be sufficient to introduce the asm/unaligned.h on Arm64.
Note that on Arm32 we forbid unaligned access. So we may need two set of helpers (I haven't looked at what the header does).
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 1/3] introduce unaligned.h
Quoted 64 lines · Julien Grall
Quoted 44 lines · Jan Beulich
Quoted 26 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
Quoted 6 lines
No change in generated code.
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.Quoted 5 lines
Really? I think its going to be the only sane way of fixing up some of our header tangle.
This series probably isn't the right place to fix this argument, so
Acked-by Andrew Cooper <[email protected]>Thanks.
Quoted 8 lines
Quoted 1 line
However, presumably we're going to want an ARM side of this imminently?
Why? It's only used (and going to be further used) by code not built for Arm. So while it certainly would be nice for such a header to also appear there (and the x86-special casing going away in patch 2), it's not a strict requirement at this point. Therefore I'd prefer to leave this to the Arm maintainers (and probably for 4.16).
I was wrong here, when it comes to an Arm64 build with ACPI support enabled.
xen/arch/arm/efi/efi-dom0.chas#define
XZ_EXTERNSTATIC
#include "../../../common/xz/crc32.c"in order to later do
Quoted 7 lines
xz_crc32_init(); efi_sys_tbl->Hdr.CRC32 = xz_crc32((uint8_t *)efi_sys_tbl, efi_sys_tbl->Hdr.HeaderSize, 0);Urgh. Why in the world does xz code get re-used like this? If we need generic crc32 support, such should imo live in xen/lib/.
I suspect this was in order to make the EFI stub completely independent to Xen (this is the case for Linux Arm). It turns out we now have an hybrid model as we re-use pass some information in the DT and other via variables.
Quoted 5 lines
So we have two possible courses of action: Eliminate this unsuitable re-use of code, or introduce
asm/unaligned.hfor Arm (or at least Arm64, in case it makes a difference) right away.
Quoted 5 lines
EFI stub is only supported for Arm64. So it should be sufficient to introduce the
asm/unaligned.hon Arm64.Note that on Arm32 we forbid unaligned access. So we may need two set of helpers (I haven't looked at what the header does).
IOW it might be possible that Arm64 could re-use the x86 header. Unless the price of unaligned accesses is much higher there. But anyway, I'm about to commit the series with the issues addressed using the 3rd approach, outlined earlier in a separate reply.
Jan
Re: [PATCH 1/3] introduce unaligned.h
In reply to Andrew CooperQuoted 12 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
No change in generated code.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.Really? I think its going to be the only sane way of fixing up some of our header tangle.
Should have responded here too: It was me to suggest to put some header there when reviewing some patches a while ago, and iirc it was Julien who pushed back.
Jan
Re: [PATCH 1/3] introduce unaligned.h
Hi Jan,
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Rather than open-coding commonly used constructs in yet more places when pulling in zstd decompression support (and its xxhash prereq), pull out the custom bits into a commonly used header (for the hypervisor build; the tool stack and stubdom builds of libxenguest will still remain in need of similarly taking care of). For now this is limited to x86, where custom logic isn't needed (considering this is going to be used in init code only, even using alternatives patching to use MOVBE doesn't seem worthwhile).
No change in generated code.
Signed-off-by Jan Beulich <[email protected]>---
Iirc use ofinclude/asm-generic/was disliked, hence the generic header goes intoinclude/xen/.
Quoted 6 lines
Quoted 2 lines
Really? I think its going to be the only sane way of fixing up some of our header tangle.
Should have responded here too: It was me to suggest to put some header there when reviewing some patches a while ago, and iirc it was Julien who pushed back.
We had the discussion when I consolidated guest_access.h.
IIRC, your definition of each directory was:
- xen: Contain headers used by all the architectures
- asm-generic: Contain headers used by most of the architectures
As we only have two architectures (Arm and x86) the split between the two would just end up in bikeshedding (who really know how RISCv, PowerPC will support Xen?). Hence my push back.
Cheers,
Signature · 1 line
Julien Grall
PATCH 2/3 lib: introduce xxhash
In reply to Jan BeulichTaken from Linux at commit d89775fc929c ("lib/: replace HTTP links with HTTPS ones"), but split into separate 32-bit and 64-bit sources, since the immediate consumer (zstd) will need only the latter.
Note that the building of this code is restricted to x86 for now because of the need to sort asm/unaligned.h for Arm.
xen/include/xen/xxhash.h new file +259 -0
@@ -0,0 +1,259 @@ +/* +* xxHash - Extremely Fast Hash algorithm +* Copyright (C) 2012-2016, Yann Collet. +* +* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following disclaimer +* in the documentation and/or other materials provided with the +* distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. This program is dual-licensed; you may select +* either version 2 of the GNU General Public License ("GPL") or BSD license +* ("BSD"). +* +* You can contact the author at: +* - xxHash homepage: https://cyan4973.github.io/xxHash/ +* - xxHash source repository: https://github.com/Cyan4973/xxHash +*/ + +/* +* Notice extracted from xxHash homepage: +* +* xxHash is an extremely fast Hash algorithm, running at RAM speed limits. +* It also successfully passes all tests from the SMHasher suite. +* +* Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 +* Duo @3GHz) +* +* Name Speed Q.Score Author +* xxHash 5.4 GB/s 10 +* CrapWow 3.2 GB/s 2 Andrew +* MumurHash 3a 2.7 GB/s 10 Austin Appleby +* SpookyHash 2.0 GB/s 10 Bob Jenkins +* SBox 1.4 GB/s 9 Bret Mulvey +* Lookup3 1.2 GB/s 9 Bob Jenkins +* SuperFastHash 1.2 GB/s 1 Paul Hsieh +* CityHash64 1.05 GB/s 10 Pike & Alakuijala +* FNV 0.55 GB/s 5 Fowler, Noll, Vo +* CRC32 0.43 GB/s 9 +* MD5-32 0.33 GB/s 10 Ronald L. Rivest +* SHA1-32 0.28 GB/s 10 +* +* Q.Score is a measure of quality of the hash function. +* It depends on successfully passing SMHasher test set. +* 10 is a perfect score. +* +* A 64-bits version, named xxh64 offers much better speed, +* but for 64-bits applications only. +* Name Speed on 64 bits Speed on 32 bits +* xxh64 13.8 GB/s 1.9 GB/s +* xxh32 6.8 GB/s 6.0 GB/s +*/ + +#ifndef __XENXXHASH_H__ +#define __XENXXHASH_H__ + +#include <xen/types.h> + +/*-**************************** +* Simple Hash Functions +*****************************/ + +/** +* xxh32() - calculate the 32-bit hash of the input with a given seed. +* +* @input: The data to hash. +* @length: The length of the data to hash. +* @seed: The seed can be used to alter the result predictably. +* +* Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s +* +* Return: The 32-bit hash of the data. +*/ +uint32_t xxh32 (const void *input,size_t length,uint32_t seed); + +/** +* xxh64() - calculate the 64-bit hash of the input with a given seed. +* +* @input: The data to hash. +* @length: The length of the data to hash. +* @seed: The seed can be used to alter the result predictably. +* +* This function runs 2x faster on 64-bit systems, but slower on 32-bit systems. +* +* Return: The 64-bit hash of the data. +*/ +uint64_t xxh64 (const void *input,size_t length,uint64_t seed); + +/** +* xxhash() - calculate wordsize hash of the input with a given seed +* @input: The data to hash. +* @length: The length of the data to hash. +* @seed: The seed can be used to alter the result predictably. +* +* If the hash does not need to be comparable between machines with +* different word sizes, this function will call whichever of xxh32() +* or xxh64() is faster. +* +* Return: wordsize hash of the data. +*/ + +static inline unsigned long xxhash (const void *input,size_t length, +uint64_t seed) +{ +#if BITS_PER_LONG ==64 +return xxh64 (input, length, seed); +#else +return xxh32 (input, length, seed); +#endif +} + +/*-**************************** +* Streaming Hash Functions +*****************************/ + +/* +* These definitions are only meant to allow allocation of XXH state +* statically, on stack, or in a struct for example. +* Do not use members directly. +*/ + +/** +* struct xxh32_state - private xxh32 state, do not use members directly +*/ +struct xxh32_state { +uint32_t total_len_32; +uint32_t large_len; +uint32_t v1; +uint32_t v2; +uint32_t v3; +uint32_t v4; +uint32_t mem32[4 ]; +uint32_t memsize; +}; + +/** +* struct xxh32_state - private xxh64 state, do not use members directly +*/ +struct xxh64_state { +uint64_t total_len; +uint64_t v1; +uint64_t v2; +uint64_t v3; +uint64_t v4; +uint64_t mem64[4 ]; +uint32_t memsize; +}; + +/** +* xxh32_reset() - reset the xxh32 state to start a new hashing operation +* +* @state: The xxh32 state to reset. +* @seed: Initialize the hash state with this seed. +* +* Call this function on any xxh32_state to prepare for a new hashing operation. +*/ +void xxh32_reset (struct xxh32_state *state,uint32_t seed); + +/** +* xxh32_update() - hash the data given and update the xxh32 state +* +* @state: The xxh32 state to update. +* @input: The data to hash. +* @length: The length of the data to hash. +* +* After calling xxh32_reset() call xxh32_update() as many times as necessary. +* +* Return: Zero on success, otherwise an error code. +*/ +int xxh32_update (struct xxh32_state *state,const void *input,size_t length); + +/** +* xxh32_digest() - produce the current xxh32 hash +* +* @state: Produce the current xxh32 hash of this state. +* +* A hash value can be produced at any time. It is still possible to continue +* inserting input into the hash state after a call to xxh32_digest(), and +* generate new hashes later on, by calling xxh32_digest() again. +* +* Return: The xxh32 hash stored in the state. +*/ +uint32_t xxh32_digest (const struct xxh32_state *state); + +/** +* xxh64_reset() - reset the xxh64 state to start a new hashing operation +* +* @state: The xxh64 state to reset. +* @seed: Initialize the hash state with this seed. +*/ +void xxh64_reset (struct xxh64_state *state,uint64_t seed); + +/** +* xxh64_update() - hash the data given and update the xxh64 state +* @state: The xxh64 state to update. +* @input: The data to hash. +* @length: The length of the data to hash. +* +* After calling xxh64_reset() call xxh64_update() as many times as necessary. +* +* Return: Zero on success, otherwise an error code. +*/ +int xxh64_update (struct xxh64_state *state,const void *input,size_t length); + +/** +* xxh64_digest() - produce the current xxh64 hash +* +* @state: Produce the current xxh64 hash of this state. +* +* A hash value can be produced at any time. It is still possible to continue +* inserting input into the hash state after a call to xxh64_digest(), and +* generate new hashes later on, by calling xxh64_digest() again. +* +* Return: The xxh64 hash stored in the state. +*/ +uint64_t xxh64_digest (const struct xxh64_state *state); + +/*-************************** +* Utils +***************************/ + +/** +* xxh32_copy_state() - copy the source state into the destination state +* +* @src: The source xxh32 state. +* @dst: The destination xxh32 state. +*/ +void xxh32_copy_state (struct xxh32_state *dst,const struct xxh32_state *src); + +/** +* xxh64_copy_state() - copy the source state into the destination state +* +* @src: The source xxh64 state. +* @dst: The destination xxh64 state. +*/ +void xxh64_copy_state (struct xxh64_state *dst,const struct xxh64_state *src); + +#endif /* __XENXXHASH_H__ */
xen/lib/Makefile +2 -0
@@ -7,3 +7,5 @@ lib-y += list-sort.o lib-y += parse-size.o lib-y += rbtree.o lib-y += sort.o +lib-$(CONFIG_X86) += xxhash32.o +lib-$(CONFIG_X86) += xxhash64.o
xen/lib/xxhash32.c new file +259 -0
259 lines not on this page · raw message
xen/lib/xxhash64.c new file +294 -0
294 lines not on this page · raw message
Re: [PATCH 2/3] lib: introduce xxhash
Quoted 8 lines · Jan Beulich
Taken from Linux at commit
d89775fc929c("lib/: replace HTTP links with HTTPS ones"), but split into separate 32-bit and 64-bit sources, since the immediate consumer (zstd) will need only the latter.Note that the building of this code is restricted to x86 for now because of the need to sort
asm/unaligned.hfor Arm.Signed-off-by Jan Beulich <[email protected]>
I think we do need to sort ARM for 4.15, but it doesn't need to block this patch right now.
PATCH 3/3 x86/Dom0: support zstd compressed kernels
In reply to Jan BeulichTaken from Linux at commit 1c4dd334df3a ("lib: decompress_unzstd: Limit output size") for unzstd.c (renamed from decompress_unzstd.c) and 36f9ff9e03de ("lib: Fix fall-through warnings for Clang") for zstd/, with bits from linux/zstd.h merged into suitable other headers.
To limit the editing necessary, introduce ptrdiff_t.
xen/common/Makefile +1 -1
@@ -55,7 +55,7 @@ obj-bin-y += warning.init.o obj-$(CONFIG_XENOPROF) += xenoprof.o obj-y += xmalloc_tlsf.o -obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 earlycpio,$(n).init.o) +obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd earlycpio,$(n).init.o) obj-$(CONFIG_COMPAT) += $(addprefix compat/,domain.o kernel.o memory.o multicall.o xlat.o)
xen/common/decompress.c +3 -0
@@ -31,5 +31,8 @@ int __init decompress(void *inbuf, unsigif ( len >=2 && !memcmp (inbuf,"\x02\x21" ,2 ) )return unlz4 (inbuf, len,NULL ,NULL , outbuf,NULL , error); +if ( len >=4 && !memcmp (inbuf,"\x28\xb5\x2f\xfd" ,4 ) ) +return unzstd (inbuf, len,NULL ,NULL , outbuf,NULL , error); +return 1 ; }
xen/common/unzstd.c new file +308 -0
308 lines not on this page · raw message
xen/common/zstd/bitstream.h new file +380 -0
380 lines not on this page · raw message
xen/common/zstd/decompress.c new file +2496 -0
2,296 lines not on this page · raw message
xen/common/zstd/entropy_common.c new file +243 -0
243 lines not on this page · raw message
xen/common/zstd/error_private.h new file +110 -0
110 lines not on this page · raw message
xen/common/zstd/fse.h new file +575 -0
575 lines not on this page · raw message
xen/common/zstd/fse_decompress.c new file +324 -0
324 lines not on this page · raw message
xen/common/zstd/huf.h new file +212 -0
212 lines not on this page · raw message
xen/common/zstd/huf_decompress.c new file +960 -0
960 lines not on this page · raw message
xen/common/zstd/mem.h new file +151 -0
151 lines not on this page · raw message
xen/common/zstd/zstd_common.c new file +74 -0
74 lines not on this page · raw message
xen/common/zstd/zstd_internal.h new file +372 -0
372 lines not on this page · raw message
xen/include/xen/decompress.h +1 -1
Lines of this file are not shown. View the raw message.
xen/include/asm-arm/types.h +6 -0
Lines of this file are not shown. View the raw message.
xen/include/asm-x86/types.h +6 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 8 lines · Jan Beulich
Taken from Linux at commit
1c4dd334df3a("lib:decompress_unzstd: Limit output size") forunzstd.c(renamed fromdecompress_unzstd.c) and36f9ff9e03de("lib: Fix fall-through warnings for Clang") for zstd/, with bits fromlinux/zstd.hmerged into suitable other headers.To limit the editing necessary, introduce
ptrdiff_t.Signed-off-by Jan Beulich <[email protected]>