From patchwork Tue Jan 26 09:48:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12046005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26BAEC433DB for ; Tue, 26 Jan 2021 09:48:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B494F2255F for ; Tue, 26 Jan 2021 09:48:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B494F2255F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.74702.134252 (Exim 4.92) (envelope-from ) id 1l4Kxk-00083Z-7e; Tue, 26 Jan 2021 09:48:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 74702.134252; Tue, 26 Jan 2021 09:48:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l4Kxk-00083S-4r; Tue, 26 Jan 2021 09:48:40 +0000 Received: by outflank-mailman (input) for mailman id 74702; Tue, 26 Jan 2021 09:48:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l4Kxi-00083J-M6 for xen-devel@lists.xenproject.org; Tue, 26 Jan 2021 09:48:38 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a388354e-e6a0-4e78-94f2-546165a81326; Tue, 26 Jan 2021 09:48:37 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 233FBAC4F; Tue, 26 Jan 2021 09:48:37 +0000 (UTC) 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: a388354e-e6a0-4e78-94f2-546165a81326 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1611654517; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6LNszWFUAzLqr7lzoTEEIij7QH8NvHbiS55vXjywYvs=; b=TbIMgSUJi8H5jOVhyJV7dPdh87gLkGgplEA9OOswTALic7olkcUOIpoZJtzuvKnlTwsKM+ KrAygWQEAkzJn1mKJ1YwpoQO7XcEp5x+ZXO4OIS9XvXjEmb4RxoWanXo5/F0aU2Ye1rh7N RyBwBTPKNq7YpbHal6j8rXJNx2PyJSI= Subject: [PATCH v3 01/15] libxenguest: add get_unaligned_le32() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu References: <2db91183-a7de-0c43-2fef-feb3523ed19b@suse.com> Message-ID: Date: Tue, 26 Jan 2021 10:48:37 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <2db91183-a7de-0c43-2fef-feb3523ed19b@suse.com> Content-Language: en-US Abstract xc_dom_check_gzip()'s reading of the uncompressed size into a helper re-usable, in particular, by other decompressor code. Sadly in the mini-os case this conflicts with other functions of the same name (and purpose), which can't be easily replaced individually. Yet it was requested that no full set of helpers be introduced at this point in the release cycle. Hence the awkward XG_NEED_UNALIGNED. Requested-by: Ian Jackson Signed-off-by: Jan Beulich Reviewed-by: Ian Jackson --- v3: New. --- a/tools/libs/guest/xg_dom_core.c +++ b/tools/libs/guest/xg_dom_core.c @@ -31,6 +31,7 @@ #include #include +#define XG_NEED_UNALIGNED #include "xg_private.h" #include "_paths.h" @@ -325,7 +326,6 @@ int xc_dom_kernel_check_size(struct xc_d size_t xc_dom_check_gzip(xc_interface *xch, void *blob, size_t ziplen) { - unsigned char *gzlen; size_t unziplen; if ( ziplen < 6 ) @@ -337,8 +337,7 @@ size_t xc_dom_check_gzip(xc_interface *x /* not gzipped */ return 0; - gzlen = blob + ziplen - 4; - unziplen = (size_t)gzlen[3] << 24 | gzlen[2] << 16 | gzlen[1] << 8 | gzlen[0]; + unziplen = get_unaligned_le32(blob + ziplen - 4); if ( unziplen > XC_DOM_DECOMPRESS_MAX ) { xc_dom_printf --- a/tools/libs/guest/xg_dom_decompress_lz4.c +++ b/tools/libs/guest/xg_dom_decompress_lz4.c @@ -3,6 +3,7 @@ #include #include +#define XG_NEED_UNALIGNED #include "xg_private.h" #include "xg_dom_decompress.h" --- a/tools/libs/guest/xg_private.h +++ b/tools/libs/guest/xg_private.h @@ -62,6 +62,15 @@ char *xc_inflate_buffer(xc_interface *xc unsigned long in_size, unsigned long *out_size); +#if !defined(__MINIOS__) || defined(XG_NEED_UNALIGNED) + +static inline unsigned int get_unaligned_le32(const uint8_t *buf) +{ + return ((unsigned int)buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; +} + +#endif /* !__MINIOS__ || XG_NEED_UNALIGNED */ + unsigned long csum_page (void * page); #define _PAGE_PRESENT 0x001 --- a/xen/common/lz4/defs.h +++ b/xen/common/lz4/defs.h @@ -18,11 +18,6 @@ static inline u16 get_unaligned_le16(con return le16_to_cpup(p); } -static inline u32 get_unaligned_le32(const void *p) -{ - return le32_to_cpup(p); -} - #endif /*