From patchwork Wed May 10 00:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rafa=C3=ABl_Kooi?= X-Patchwork-Id: 13236448 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91013C7EE25 for ; Wed, 10 May 2023 05:14:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.532611.828876 (Exim 4.92) (envelope-from ) id 1pwc9N-0001Ey-KY; Wed, 10 May 2023 05:14:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 532611.828876; Wed, 10 May 2023 05:14:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pwc9N-0001Ek-EU; Wed, 10 May 2023 05:14:05 +0000 Received: by outflank-mailman (input) for mailman id 532611; Wed, 10 May 2023 00:18:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pwXXS-0004li-Si for xen-devel@lists.xenproject.org; Wed, 10 May 2023 00:18:39 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02olkn20822.outbound.protection.outlook.com [2a01:111:f400:fe13::822]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 358ca281-eec8-11ed-b229-6b7b168915f2; Wed, 10 May 2023 02:18:38 +0200 (CEST) Received: from DU0P192MB1700.EURP192.PROD.OUTLOOK.COM (2603:10a6:10:3bf::6) by AM9P192MB0871.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:1fb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 00:18:36 +0000 Received: from DU0P192MB1700.EURP192.PROD.OUTLOOK.COM ([fe80::5056:b334:c71f:b047]) by DU0P192MB1700.EURP192.PROD.OUTLOOK.COM ([fe80::5056:b334:c71f:b047%6]) with mapi id 15.20.6363.033; Wed, 10 May 2023 00:18:36 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 358ca281-eec8-11ed-b229-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mOEebGwVICUAf+35vIFZxHWtEeFJhyzGW5z1UKCJ0K/+KmFyo5xg+Pv4KR6HTKN9rzisSUl/sp29JXcW4JjNhyubBNDoQ0D5bmfHYwMAz3M4N3Ts8RL7bO8Af6jhJ7HK4Z33xo+poLIEKYBz8qZPFc69UT027pDW+NuOTRh7o+EMYkyj+8zDiCR9Vd9t1t7eD1teuFQ8qORT+MYzpyz7ahXKYhE/YQihP65Lv6heUJy8wEswqApBcWEqA1x2EG8YNuY8uhEMWejt5biyJbt0z8TwvnQRQfzqGT2kqvmXvLOb3Gui4gezsGI8HY5cIH+7cp5REs6/OXuyg1UOfOGoDA== 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=ET36M7cTJdg4CJ6NvtMlwqnICtej3ldCzYBd3kr2cj0=; b=YuLCM9JoFlMUB4UQNDkDR5C/o9F6Fi8AFSrnxJG8Et0jIZsGB9NpQ9kX/43nZydoBJzupohR3Ghtk108K5o9cSvWkhS0+OSYqLweuuaRfKvOD60tnnLVhrtdmj+HRlNY1JhxDRSuQmJ9SBP6f856BPe48kIDgW6qadct+gVMieiEQ00qQdDYS4mylhkFQP7p+HnL6ynJX0y7OG8M17k19bzPw9af6c7+QJtl3mIXXJ5CncPvN8Iz8O0ZczKLOsXJ43RYhDl9wt+OFpmiFbIIKdOvI4oGPVaswufpX3DpreizKSgyvYjSMLupbZWixJL4iP0UjKpd2tqRjKBnVxXcMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ET36M7cTJdg4CJ6NvtMlwqnICtej3ldCzYBd3kr2cj0=; b=oNExkE8UPjaq1+li7g+wT2UsONIAiV3UH9MAdKqTBTw17wIGc4GUznLazP7RlaQ6wUIQgxZ0TFL67QmaXGpT25Wr1HnM3dtzpzLOUDBh1mhmsxMxrnvGJ5rdf4WoSpXTVwoj3qVFAKUMgQrywV8cb4MlKITx/pZ5ZvdPFXKRVaNlmbRlFXJZQiT6brrn2HKJnpMQZcp/SOOItnq6I5OCalhIXJo6uQCcAduR1mfPbfXPIJTL3ZQYcDf44oiFzC0EQj9vkIOKc2WGn//KYe1PRJroLHaNZmW9pznxOEW5FYlqT1pusP6Xhlj7RMA6r0KpFIENlWhpo5NtdFOLUipkvw== From: =?utf-8?q?Rafa=C3=ABl_Kooi?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Rafa=C3=ABl_Kooi?= , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [XEN PATCH 1/2] xen/decompress: Add a user pointer for book keeping in the callbacks Date: Wed, 10 May 2023 02:18:21 +0200 Message-ID: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: X-TMN: [tSTPrSG+RMNi4PjUJiX8cv+iUoVEEwY8OMWFWNwu3UdjJOU6en9lzcwWbm24R6GF] X-ClientProxiedBy: LO2P265CA0052.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::16) To DU0P192MB1700.EURP192.PROD.OUTLOOK.COM (2603:10a6:10:3bf::6) X-Microsoft-Original-Message-ID: <06c6d6eb57f2dffa036af44ac8d9cc3e9df6aad0.1683673598.git.rafael_andreas@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0P192MB1700:EE_|AM9P192MB0871:EE_ X-MS-Office365-Filtering-Correlation-Id: c2488a15-447a-4104-3ccb-08db50ec18a7 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9Xmr6PcyLpofOFOY3OlYay91HJ3b9A+qmOPqQ9CxHjkFPP1tLatAmAKdGQVd0HMcrjUdFNDgYpjaMXKkNxlStevtGtWd8KtZf0Dxbhg3Xy9biPvwPr5+6EIHO3jy1tL4xUY3PR/QyPGct+KjDz47IqDKDzrMWEmI5IhRh1ddq66GtJ6ewGpFH07Js9OC6KOCB0RM8YTyjrp/3OFM+R9ay6kcha0Mr+DMJ/WqqZEKclNqmtEbVAYXEg2iexGV+7yiJy7IhF3G5MsmoN+WRsYYVWjConbbGhbDSbDkiDlR+v5Uu3ZQZ1HJDD+r6z4q5SYyuL5ZKIyIROy2h5K34UzrQAH7rlUb9vIYss7V7OsHA3V1pW/p27mbEZSnfgEICluj0UhcNwgxdMatZHofwE5LH5IEOybhzx7ph29ckd0WDMa6xXRe24zkYD5In0sUsaYjJZs6p1RxIoA7urgTbDRbF4RlX4FCQfqMkgXxnWdX+mWQ3CG/1YggpRbsp1tCxavF4LZhdRcGxDGddgmZSxKq1mfUsQH3tb42c8ox63dLNLzBFvkcalJ3bDEzmEx5FRCNUJY3IzsuTpulRQLhG68uvALqw1YXuVTXR1sW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UGzqcMRYkuQVQlSqu?= =?utf-8?q?revx2DVQbszCW9im2KMtwJTMEnX9oXvKe5eJNIHxHAZFQoenUEqEKrQZC/oxYKU+h?= =?utf-8?q?TNzuUkrmBujnTNeh56lg3CjrYjAK5va9n6L3cB52WjtjQOa5l4VKUSjOMdJ7VvvnV?= =?utf-8?q?ZsV9pLvGZsBWMRJP0WapFAQcWhzsfuvJQCAQ9XCopckwtyR91X2ctIGzdpigZ0KWx?= =?utf-8?q?FrfuPckHxDAb4iHuSnE6WYY3JCsj1G3TjB22W8T+fZRZ24vXXbu4o1BlYhVA=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-fb43a.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: c2488a15-447a-4104-3ccb-08db50ec18a7 X-MS-Exchange-CrossTenant-AuthSource: DU0P192MB1700.EURP192.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 00:18:36.3371 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9P192MB0871 Before this change the callbacks either needed to be completely stateless or use global state for book keeping. In the case where book keeping is needed we can't use global state in decompress.c because the linker disallows the existence of the .data and .bss segments. This change allows for localized book keeping with the user pointer. Signed-off-by: Rafaël Kooi --- xen/common/bunzip2.c | 23 +++++++++++++---------- xen/common/unlz4.c | 15 ++++++++------- xen/common/unlzma.c | 30 ++++++++++++++++++------------ xen/common/unlzo.c | 13 +++++++------ xen/common/unxz.c | 11 ++++++----- xen/common/unzstd.c | 13 +++++++------ xen/include/xen/decompress.h | 10 +++++++--- 7 files changed, 66 insertions(+), 49 deletions(-) diff --git a/xen/common/bunzip2.c b/xen/common/bunzip2.c index 4466426941..a854046524 100644 --- a/xen/common/bunzip2.c +++ b/xen/common/bunzip2.c @@ -1,4 +1,4 @@ -/* vi: set sw = 4 ts = 4: */ +/* vi: set sw=4 ts=4: */ /* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net). Based on bzip2 decompression code by Julian R Seward (jseward@acm.org), @@ -86,7 +86,7 @@ struct bunzip_data { /* State for interrupting output loop */ int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent; /* I/O tracking data (file handles, buffers, positions, etc.) */ - int (*fill)(void*, unsigned int); + int (*fill)(void*, unsigned int, void*); int inbufCount, inbufPos /*, outbufPos*/; unsigned char *inbuf /*,*outbuf*/; unsigned int inbufBitCount, inbufBits; @@ -99,6 +99,7 @@ struct bunzip_data { unsigned char selectors[32768]; /* nSelectors = 15 bits */ struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */ int io_error; /* non-zero if we have IO error */ + void *userptr; /* user pointer to pass to fill */ }; @@ -117,7 +118,7 @@ static unsigned int __init get_bits(struct bunzip_data *bd, char bits_wanted) if (bd->inbufPos == bd->inbufCount) { if (bd->io_error) return 0; - bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE); + bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE, bd->userptr); if (bd->inbufCount <= 0) { bd->io_error = RETVAL_UNEXPECTED_INPUT_EOF; return 0; @@ -612,7 +613,7 @@ decode_next_byte: goto decode_next_byte; } -static int __init cf_check nofill(void *buf, unsigned int len) +static int __init cf_check nofill(void *buf, unsigned int len, void *userptr) { return -1; } @@ -621,7 +622,7 @@ static int __init cf_check nofill(void *buf, unsigned int len) a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are ignored, and data is read from file handle into temporary buffer. */ static int __init start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, - int (*fill)(void*, unsigned int)) + int (*fill)(void*, unsigned int, void*), void *userptr) { struct bunzip_data *bd; unsigned int i, j, c; @@ -644,6 +645,7 @@ static int __init start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, bd->fill = fill; else bd->fill = nofill; + bd->userptr = userptr; /* Init the CRC32 table (big endian) */ for (i = 0; i < 256; i++) { @@ -671,10 +673,11 @@ static int __init start_bunzip(struct bunzip_data **bdp, void *inbuf, int len, /* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip2 data, not end of file.) */ int __init bunzip2(unsigned char *buf, unsigned int len, - int(*fill)(void*, unsigned int), - int(*flush)(void*, unsigned int), + int(*fill)(void*, unsigned int, void*), + int(*flush)(void*, unsigned int, void*), unsigned char *outbuf, unsigned int *pos, - void(*error)(const char *x)) + void(*error)(const char *x), + void *userptr) { struct bunzip_data *bd; int i = -1; @@ -696,7 +699,7 @@ int __init bunzip2(unsigned char *buf, unsigned int len, i = RETVAL_OUT_OF_MEMORY; goto exit_0; } - i = start_bunzip(&bd, inbuf, len, fill); + i = start_bunzip(&bd, inbuf, len, fill, userptr); if (!i) { for (;;) { i = read_bunzip(bd, outbuf, BZIP2_IOBUF_SIZE); @@ -705,7 +708,7 @@ int __init bunzip2(unsigned char *buf, unsigned int len, if (!flush) outbuf += i; else - if (i != flush(outbuf, i)) { + if (i != flush(outbuf, i, userptr)) { i = RETVAL_UNEXPECTED_OUTPUT_EOF; break; } diff --git a/xen/common/unlz4.c b/xen/common/unlz4.c index 2096b98f36..00c179732e 100644 --- a/xen/common/unlz4.c +++ b/xen/common/unlz4.c @@ -23,10 +23,11 @@ #define ARCHIVE_MAGICNUMBER 0x184C2102 int __init unlz4(unsigned char *input, unsigned int in_len, - int (*fill)(void *, unsigned int), - int (*flush)(void *, unsigned int), + int (*fill)(void *, unsigned int, void*), + int (*flush)(void *, unsigned int, void*), unsigned char *output, unsigned int *posp, - void (*error)(const char *x)) + void (*error)(const char *x), + void *userptr) { int ret = -1; size_t chunksize = 0; @@ -75,7 +76,7 @@ int __init unlz4(unsigned char *input, unsigned int in_len, *posp = 0; if (fill) - fill(inp, 4); + fill(inp, 4, userptr); chunksize = get_unaligned_le32(inp); if (chunksize == ARCHIVE_MAGICNUMBER) { @@ -92,7 +93,7 @@ int __init unlz4(unsigned char *input, unsigned int in_len, for (;;) { if (fill) - fill(inp, 4); + fill(inp, 4, userptr); chunksize = get_unaligned_le32(inp); if (chunksize == ARCHIVE_MAGICNUMBER) { @@ -113,7 +114,7 @@ int __init unlz4(unsigned char *input, unsigned int in_len, error("chunk length is longer than allocated"); goto exit_2; } - fill(inp, chunksize); + fill(inp, chunksize, userptr); } #if defined(__XEN__) || defined(__MINIOS__) if (out_len >= uncomp_chunksize) { @@ -133,7 +134,7 @@ int __init unlz4(unsigned char *input, unsigned int in_len, } ret = -1; - if (flush && flush(outp, dest_len) != dest_len) + if (flush && flush(outp, dest_len, userptr) != dest_len) goto exit_2; if (output) outp += dest_len; diff --git a/xen/common/unlzma.c b/xen/common/unlzma.c index 6cd99023ad..d5dbc44881 100644 --- a/xen/common/unlzma.c +++ b/xen/common/unlzma.c @@ -59,7 +59,7 @@ static long long __init read_int(unsigned char *ptr, int size) #define LZMA_IOBUF_SIZE 0x10000 struct rc { - int (*fill)(void*, unsigned int); + int (*fill)(void*, unsigned int, void*); uint8_t *ptr; uint8_t *buffer; uint8_t *buffer_end; @@ -68,6 +68,7 @@ struct rc { uint32_t range; uint32_t bound; void (*error)(const char *); + void *userptr; }; @@ -76,7 +77,7 @@ struct rc { #define RC_MODEL_TOTAL_BITS 11 -static int __init cf_check nofill(void *buffer, unsigned int len) +static int __init cf_check nofill(void *buffer, unsigned int len, void *userptr) { return -1; } @@ -84,7 +85,7 @@ static int __init cf_check nofill(void *buffer, unsigned int len) /* Called twice: once at startup and once in rc_normalize() */ static void __init rc_read(struct rc *rc) { - rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE); + rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE, rc->userptr); if (rc->buffer_size <= 0) rc->error("unexpected EOF"); rc->ptr = rc->buffer; @@ -93,8 +94,9 @@ static void __init rc_read(struct rc *rc) /* Called once */ static inline void __init rc_init(struct rc *rc, - int (*fill)(void*, unsigned int), - unsigned char *buffer, int buffer_size) + int (*fill)(void*, unsigned int, void*), + unsigned char *buffer, int buffer_size, + void *userptr) { if (fill) rc->fill = fill; @@ -104,6 +106,7 @@ static inline void __init rc_init(struct rc *rc, rc->buffer_size = buffer_size; rc->buffer_end = rc->buffer + rc->buffer_size; rc->ptr = rc->buffer; + rc->userptr = userptr; rc->code = 0; rc->range = 0xFFFFFFFF; @@ -274,8 +277,9 @@ struct writer { size_t buffer_pos; int bufsize; size_t global_pos; - int(*flush)(void*, unsigned int); + int(*flush)(void*, unsigned int, void*); struct lzma_header *header; + void *userptr; }; struct cstate { @@ -313,7 +317,7 @@ static inline int __init write_byte(struct writer *wr, uint8_t byte) if (wr->flush && wr->buffer_pos == wr->header->dict_size) { wr->buffer_pos = 0; wr->global_pos += wr->header->dict_size; - if (wr->flush((char *)wr->buffer, wr->header->dict_size) + if (wr->flush((char *)wr->buffer, wr->header->dict_size, wr->userptr) != wr->header->dict_size) return -1; } @@ -529,10 +533,11 @@ static inline int __init process_bit1(struct writer *wr, struct rc *rc, int __init unlzma(unsigned char *buf, unsigned int in_len, - int(*fill)(void*, unsigned int), - int(*flush)(void*, unsigned int), + int(*fill)(void*, unsigned int, void*), + int(*flush)(void*, unsigned int, void*), unsigned char *output, unsigned int *posp, - void(*error)(const char *x)) + void(*error)(const char *x), + void *userptr) { struct lzma_header header; int lc, pb, lp; @@ -566,8 +571,9 @@ int __init unlzma(unsigned char *buf, unsigned int in_len, wr.global_pos = 0; wr.previous_byte = 0; wr.buffer_pos = 0; + wr.userptr = userptr; - rc_init(&rc, fill, inbuf, in_len); + rc_init(&rc, fill, inbuf, in_len, userptr); for (i = 0; i < sizeof(header); i++) { if (rc.ptr >= rc.buffer_end) @@ -644,7 +650,7 @@ int __init unlzma(unsigned char *buf, unsigned int in_len, if (posp) *posp = rc.ptr-rc.buffer; - if (!wr.flush || wr.flush(wr.buffer, wr.buffer_pos) == wr.buffer_pos) + if (!wr.flush || wr.flush(wr.buffer, wr.buffer_pos, wr.userptr) == wr.buffer_pos) ret = 0; exit_3: large_free(p); diff --git a/xen/common/unlzo.c b/xen/common/unlzo.c index 74056778eb..8908790425 100644 --- a/xen/common/unlzo.c +++ b/xen/common/unlzo.c @@ -115,10 +115,11 @@ static int __init parse_header(u8 *input, int *skip, int in_len) } int __init unlzo(unsigned char *input, unsigned int in_len, - int (*fill) (void *, unsigned int), - int (*flush) (void *, unsigned int), + int (*fill) (void *, unsigned int, void*), + int (*flush) (void *, unsigned int, void*), unsigned char *output, unsigned int *posp, - void (*error) (const char *x)) + void (*error) (const char *x), + void *userptr) { u8 r = 0; int skip = 0; @@ -161,7 +162,7 @@ int __init unlzo(unsigned char *input, unsigned int in_len, *posp = 0; if (fill) - fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE), userptr); if (!parse_header(input, &skip, in_len)) { error("invalid header"); @@ -227,7 +228,7 @@ int __init unlzo(unsigned char *input, unsigned int in_len, } } - if (flush && flush(out_buf, dst_len) != dst_len) + if (flush && flush(out_buf, dst_len, userptr) != dst_len) goto exit_2; if (output) out_buf += dst_len; @@ -235,7 +236,7 @@ int __init unlzo(unsigned char *input, unsigned int in_len, *posp += src_len + 12; if (fill) { in_buf = in_buf_save; - fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE)); + fill(in_buf, lzo1x_worst_compress(LZO_BLOCK_SIZE), userptr); } else { in_buf += src_len; in_len -= src_len; diff --git a/xen/common/unxz.c b/xen/common/unxz.c index 17aead0adf..6f005170d3 100644 --- a/xen/common/unxz.c +++ b/xen/common/unxz.c @@ -158,10 +158,11 @@ * fill() and flush() won't be used. */ int __init unxz(unsigned char *in, unsigned int in_size, - int (*fill)(void *dest, unsigned int size), - int (*flush)(void *src, unsigned int size), + int (*fill)(void *dest, unsigned int size, void *userptr), + int (*flush)(void *src, unsigned int size, void *userptr), unsigned char *out, unsigned int *in_used, - void (*error)(const char *x)) + void (*error)(const char *x), + void *userptr) { struct xz_buf b; struct xz_dec *s; @@ -213,7 +214,7 @@ int __init unxz(unsigned char *in, unsigned int in_size, b.in_pos = 0; - in_size = fill(in, XZ_IOBUF_SIZE); + in_size = fill(in, XZ_IOBUF_SIZE, userptr); if ((int) in_size < 0) { /* * This isn't an optimal error code @@ -236,7 +237,7 @@ int __init unxz(unsigned char *in, unsigned int in_size, * returned by xz_dec_run(), but probably * it's not too bad. */ - if (flush(b.out, b.out_pos) != (int)b.out_pos) + if (flush(b.out, b.out_pos, userptr) != (int)b.out_pos) ret = XZ_BUF_ERROR; b.out_pos = 0; diff --git a/xen/common/unzstd.c b/xen/common/unzstd.c index 47073dd3e3..09e8fdef04 100644 --- a/xen/common/unzstd.c +++ b/xen/common/unzstd.c @@ -143,10 +143,11 @@ out: } int __init unzstd(unsigned char *in_buf, unsigned int in_len, - int (*fill)(void*, unsigned int), - int (*flush)(void*, unsigned int), + int (*fill)(void*, unsigned int, void*), + int (*flush)(void*, unsigned int, void*), unsigned char *out_buf, unsigned int *in_pos, - void (*error)(const char *x)) + void (*error)(const char *x), + void *userptr) { ZSTD_inBuffer in; ZSTD_outBuffer out; @@ -190,7 +191,7 @@ int __init unzstd(unsigned char *in_buf, unsigned int in_len, } /* Read the first chunk, since we need to decode the frame header. */ if (fill != NULL) - in_len = fill(in_buf, ZSTD_IOBUF_SIZE); + in_len = fill(in_buf, ZSTD_IOBUF_SIZE, userptr); if ((int)in_len < 0) { error("ZSTD-compressed data is truncated"); err = -1; @@ -267,7 +268,7 @@ int __init unzstd(unsigned char *in_buf, unsigned int in_len, if (in.pos == in.size) { if (in_pos != NULL) *in_pos += in.pos; - in_len = fill ? fill(in_buf, ZSTD_IOBUF_SIZE) : -1; + in_len = fill ? fill(in_buf, ZSTD_IOBUF_SIZE, userptr) : -1; if ((int)in_len < 0) { error("ZSTD-compressed data is truncated"); err = -1; @@ -283,7 +284,7 @@ int __init unzstd(unsigned char *in_buf, unsigned int in_len, goto out; /* Flush all of the data produced if using flush(). */ if (flush != NULL && out.pos > 0) { - if (out.pos != flush(out.dst, out.pos)) { + if (out.pos != flush(out.dst, out.pos, userptr)) { error("Failed to flush()"); err = -1; goto out; diff --git a/xen/include/xen/decompress.h b/xen/include/xen/decompress.h index f5bc17f2b6..804dbca963 100644 --- a/xen/include/xen/decompress.h +++ b/xen/include/xen/decompress.h @@ -2,10 +2,11 @@ #define __XEN_GENERIC_H typedef int decompress_fn(unsigned char *inbuf, unsigned int len, - int (*fill)(void*, unsigned int), - int (*flush)(void*, unsigned int), + int (*fill)(void*, unsigned int, void*), + int (*flush)(void*, unsigned int, void*), unsigned char *outbuf, unsigned int *posp, - void (*error)(const char *x)); + void (*error)(const char *x), + void *userptr); /* inbuf - input buffer * len - len of pre-read data in inbuf @@ -15,6 +16,7 @@ typedef int decompress_fn(unsigned char *inbuf, unsigned int len, * posp - if non-null, input position (number of bytes read) will be * returned here * error - error reporting function + * userptr - user pointer to pass to flush and fill * * If len != 0, inbuf should contain all the necessary input data, and fill * should be NULL @@ -29,6 +31,8 @@ typedef int decompress_fn(unsigned char *inbuf, unsigned int len, * decompressor (outbuf = NULL), and the flush function will be called to * flush the output buffer at the appropriate time (decompressor and stream * dependent). + * + * Flush and fill's third argument is a user pointer for book keeping purposes. */ decompress_fn bunzip2, unxz, unlzma, unlzo, unlz4, unzstd; From patchwork Wed May 10 00:18:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rafa=C3=ABl_Kooi?= X-Patchwork-Id: 13236446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCFDEC77B7C for ; Wed, 10 May 2023 05:14:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.532612.828882 (Exim 4.92) (envelope-from ) id 1pwc9N-0001Mk-WD; Wed, 10 May 2023 05:14:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 532612.828882; Wed, 10 May 2023 05:14:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pwc9N-0001Lj-Oo; Wed, 10 May 2023 05:14:05 +0000 Received: by outflank-mailman (input) for mailman id 532612; Wed, 10 May 2023 00:18:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pwXXT-0004li-Sy for xen-devel@lists.xenproject.org; Wed, 10 May 2023 00:18:39 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02olkn20822.outbound.protection.outlook.com [2a01:111:f400:fe13::822]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 36252708-eec8-11ed-b229-6b7b168915f2; Wed, 10 May 2023 02:18:38 +0200 (CEST) Received: from DU0P192MB1700.EURP192.PROD.OUTLOOK.COM (2603:10a6:10:3bf::6) by AM9P192MB0871.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:1fb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Wed, 10 May 2023 00:18:38 +0000 Received: from DU0P192MB1700.EURP192.PROD.OUTLOOK.COM ([fe80::5056:b334:c71f:b047]) by DU0P192MB1700.EURP192.PROD.OUTLOOK.COM ([fe80::5056:b334:c71f:b047%6]) with mapi id 15.20.6363.033; Wed, 10 May 2023 00:18:38 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 36252708-eec8-11ed-b229-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JpxuxsysUsDSy+raGfwZoQG51JT6QRIdG++XXpcSoUesQw9F8jwVr0CgyxdY5R1VWVm5xIdvfHI3sWj6Z0zJJQVYrvodrggawSqPEizDJuK7Jnrj8qjgZhvnW4eb8YyOOcvawrzlq6Hzk/idD2yl1nWTqFB4j3yphKgZ+G3GHeahTanKOZ9jhTI5OZPRvtzbUuBuUFyz4tx2uI6vdxgj+JtpecFWHwvtaQ9dGM7L55c88nhG0qC6TVGbyCDBr1ZetSQnlkrB25+06IgTPZP7cUxjU59sMb0EWsMq5qpe5Akaaj/zFEQDctr5asjw4mPRl1HJG60hHHzmkr+IBo9+LQ== 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=Co0A8XpUzSdvSffHfW1JcfS0NgGlehxe6pGZTt39HIE=; b=T5BOE9bB0TEiD5VWiQpmV7JGoup47DkMRhy1Y6WnVG6R2Nz1dioJx3xrlqr1RpOh3FRtFmDx0gBOiksojwbH5dXSMEqhHvL8Kh0gJ7fNogjiTh/s9lIWBkABKx4fkgKywqHX3q0V8Boavg0lJXNNgQAVHYwvEuBIux+5J9L71X51i9v0TbF2pBXAUZIR5ClNSc9LK/zUtly9yxCA7QHxbVeyAxg0OK0qusSGVfSQtsZujKowVj5SFYkEMs701RmSmruWKJDz+6+Rmmp23tTVDq2OuwMfIzrllGOmbp4eZV7Sn648HQa/x43ojBic33Omlf6dOCsLZpEL0EKEKRpYgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Co0A8XpUzSdvSffHfW1JcfS0NgGlehxe6pGZTt39HIE=; b=RIat4IdLGcLGFwu7+3bnNxBZdsF8F5KYs7DP+LXUPfgq9THaa7pZ3Os8sFfsjAwB5fdvJH8a97htQNrNib0c/qCJjmclRDcHntrpmJEHkBlK7ucGLq2HUTK6M35AbXNY/AOYFub+JqqhpiCH22WjkJxEB2ArhChsMEZK7HZ89DCHKfykWiRH7syXrbPvpQs8lN3Th/iDFcumvSTmhVFoZr4zjg0zHcOv1H8loSrUPA51+ZRWKsJMSo2ZS6Km0ofGotSrUD/OfWCesFINzSX1+3omg2HMZRW2oOhwnZ2Be6bFTaf8SqGtF6gcBCz3l8hMe5Z6ar0poKpGVNYgUppsmA== From: =?utf-8?q?Rafa=C3=ABl_Kooi?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Rafa=C3=ABl_Kooi?= , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [XEN PATCH 2/2] x86/Dom0: Use streaming decompression for ZSTD compressed kernels Date: Wed, 10 May 2023 02:18:22 +0200 Message-ID: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: X-TMN: [HcumDLXUQx2Ka6y8dbImpEzA8tER5uiK1S3VfeyYV5wT2Hi4Nw5fZ9XqlsqI5KUK] X-ClientProxiedBy: LO2P265CA0052.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::16) To DU0P192MB1700.EURP192.PROD.OUTLOOK.COM (2603:10a6:10:3bf::6) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0P192MB1700:EE_|AM9P192MB0871:EE_ X-MS-Office365-Filtering-Correlation-Id: 91a01a52-a7fb-4686-ab79-08db50ec19c7 X-MS-Exchange-SLBlob-MailProps: ZILSnhm0P3k2XayEnZ/FXgv66CsfMCS1d7vfnlsnkxPz9PUXJadlSovgYnwo3lJ6PxRKlGP/SxcNROzPIHNCRtP3M+1kuBI/U+oo7Dpgd+Cwj1g1PGktYMMwagUf+Fjl1181pDhQnaVi/teLqHASkpl1GFzJW0BraS7JuIUeP2gOtW5TRGOYoiZbWtidRWc/NYabT2xh+8CWAfawcyO751KLlO+DDiFD8fo3sPVzPiFeHju87Lu126nUFDfVAnRWdxvr/TZaiZqEVKUEQEohD0UYOHjqDDJ7pePb0jY3qFbHK6TxMrCQYycSpVsASUuuoPPsQMG52S/tDRs2Jk5kKcNPCVKtBZ1iez8uVDvf30oRt+KPzvxcD3hDlWqPXIDd1VVL3kAE1Nh/zllFkiujAt8NOPLwJJPO03XhzLoJlGzBaDUBIYFSN4hFpvshdp4zpkfny5Ksv52QXI6KJKv9X38f5uskkhQ60EVXVzSTglTsFdjcarpU573Thb8ezfJ97eWc8ER6TAFxzAc1FBPI81N2QfEByfP4FfKnfk3ee6VjwkXptZDjGd+hfl9Qi2qUPG1Oym80RH//ULTm1WL4/LTpz9cyIBB2KPi6Hnf+ca9C0bxJwy182OxXb1KnM0Ri15/D81jvL2biMVcBWPkpwRoVSDni8iuB1SXRhJ37Spoe4Rcb6Yo9qPkZFt80WagRwOqCuin9ejZHacIp3uQ0ZkoGM6YPzlVvJK03GLNndk3+54cGbPV2+hIH6ZUHa1O2Q0apHGOImIIjRJYBZ4RjjNpXuy8+YQLV X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W5pC3f03pX93RXyqnro6AjJ8bptsX7vbdbLudov9rnBmZnW4pJtG5Z3hUX7qylEk6zEYu5mOu6Hq/ZLU7WrkoTFMb2H50RAfAIDWRLf8U+pW1w/Ez7DRmObRgD+2q7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I=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-fb43a.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 91a01a52-a7fb-4686-ab79-08db50ec19c7 X-MS-Exchange-CrossTenant-AuthSource: DU0P192MB1700.EURP192.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2023 00:18:38.1978 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9P192MB0871 On Arch Linux kernel decompression will fail when Xen has been unified with the kernel and initramfs as a single binary. This change works for both streaming and non-streaming ZSTD content. Signed-off-by: Rafaël Kooi Reviewed-by: tag - you can only add such tags once they were offered to --- xen/common/decompress.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/xen/common/decompress.c b/xen/common/decompress.c index 989336983f..cde754ffb1 100644 --- a/xen/common/decompress.c +++ b/xen/common/decompress.c @@ -3,11 +3,26 @@ #include #include +typedef struct _ZSTD_state +{ + void *write_buf; + unsigned int write_pos; +} ZSTD_state; + static void __init cf_check error(const char *msg) { printk("%s\n", msg); } +static int __init cf_check ZSTD_flush(void *buf, unsigned int pos, + void *userptr) +{ + ZSTD_state *state = (ZSTD_state*)userptr; + memcpy(state->write_buf + state->write_pos, buf, pos); + state->write_pos += pos; + return pos; +} + int __init decompress(void *inbuf, unsigned int len, void *outbuf) { #if 0 /* Not needed here yet. */ @@ -17,22 +32,32 @@ int __init decompress(void *inbuf, unsigned int len, void *outbuf) #endif if ( len >= 3 && !memcmp(inbuf, "\x42\x5a\x68", 3) ) - return bunzip2(inbuf, len, NULL, NULL, outbuf, NULL, error); + return bunzip2(inbuf, len, NULL, NULL, outbuf, NULL, error, NULL); if ( len >= 6 && !memcmp(inbuf, "\3757zXZ", 6) ) - return unxz(inbuf, len, NULL, NULL, outbuf, NULL, error); + return unxz(inbuf, len, NULL, NULL, outbuf, NULL, error, NULL); if ( len >= 2 && !memcmp(inbuf, "\135\000", 2) ) - return unlzma(inbuf, len, NULL, NULL, outbuf, NULL, error); + return unlzma(inbuf, len, NULL, NULL, outbuf, NULL, error, NULL); if ( len >= 5 && !memcmp(inbuf, "\x89LZO", 5) ) - return unlzo(inbuf, len, NULL, NULL, outbuf, NULL, error); + return unlzo(inbuf, len, NULL, NULL, outbuf, NULL, error, NULL); if ( len >= 2 && !memcmp(inbuf, "\x02\x21", 2) ) - return unlz4(inbuf, len, NULL, NULL, outbuf, NULL, error); + return unlz4(inbuf, len, NULL, NULL, outbuf, NULL, error, NULL); if ( len >= 4 && !memcmp(inbuf, "\x28\xb5\x2f\xfd", 4) ) - return unzstd(inbuf, len, NULL, NULL, outbuf, NULL, error); + { + // NOTE (Rafaël): On Arch Linux the kernel is compressed in a way + // that requires streaming ZSTD decompression. Otherwise decompression + // will fail when using a unified EFI binary. Somehow decompression + // works when not using a unified EFI binary, I suspect this is the + // kernel self decompressing. Or there is a code path that I am not + // aware of that takes care of the use case properly. + + ZSTD_state state = (ZSTD_state){ outbuf, 0 }; + return unzstd(inbuf, len, NULL, ZSTD_flush, NULL, NULL, error, &state); + } return 1; }