Received: by 2002:a05:7208:70d5:b0:7f:5597:fa5c with SMTP id q21csp89753rba; Wed, 20 Mar 2024 11:49:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUq3OB2pAX/B0mlzrEdevVXxMLriOeoOjZWZJtPK2+IxUe++XSFOzBe4oC4hhdlb8IRK/G3r1Gj38Pl5y/HQ44uEHY8Ojt9UhF1xU0zJg== X-Google-Smtp-Source: AGHT+IG8wd3wj8E9JdKBwcy2HsnV8UTTjjH/HICu7GMJh8b3aNvUOkDeW5BVz1Yqaa6NSRVSa8/p X-Received: by 2002:ac8:5fce:0:b0:430:f228:5f87 with SMTP id k14-20020ac85fce000000b00430f2285f87mr5056645qta.31.1710960595400; Wed, 20 Mar 2024 11:49:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710960595; cv=pass; d=google.com; s=arc-20160816; b=PP5IDdAnxcouS5x6+bIaKjyHxIfuZq9mSiWRbKJ13CGfnLJ0twZ/ZOlJGo2nwaHN1U nVqSlRcd51Aul1npXNE1sWKJe3g/sG+ryJvwAJCsFemAmsbw4tZp6qIUzNQBhOBjSlMz jw0pAIDU5/eqzzpSj3BnjeYsgxJof6l1xzjShkIdGBJ5akjU0GDkrUI+uBthK8oj/EGM 0S+hUDLVy43bsHY2AIMKhgkVqPUK6rFvyP9Ch3sYM1KDge9uVUDAWFZR6KZmv6qKzx3K hGQ+jJWyJ9ZSTTXJwYYOoZQfFHFu098nV1HHvCNXjUqlwgOLCa1n9eGZntomCC35Q7CK zklA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=u/6GqkjPOt5AuNa00QQu4/cbRqN6+CxnNjLor0+61AA=; fh=cZ0pQj0gfnIzfSrD4acEszNw58lcj8DsI017uhDo/HI=; b=mksMgj6aznsLQvNodD/H8SHP+TIg7UotTDAtVSWebeQretvwNRXZrB4sNwJ18BwU5P p13R0UN/ExyDlUaGKDfrojSosoTIPlq7Kk+PtJe2WUCgFEWkFP+AIMDnV2SUQbd03ym0 g9CLXubtJT1haCnnGGoJpbrnjPjAJPKZrzLkwPeLucvAZsI1hXQ71X08WDrS7HCe5Lwj 0FNY4dIlC2y/tNNh9q8xuhFtP9zAIY2mgdEF2nwyPnCwIxa3uE2QO2vfuJrQTlJynQKM 7xBiGcTaoZ0PAEZefjDEDp5B2Pedz++Ny7XvsUkmc9f9C5HJMqNOW2uUSjzMXDwRR7Pm PzVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=tukaani.org); spf=pass (google.com: domain of linux-kernel+bounces-109317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109317-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d7-20020a05622a05c700b0043114a9c1d1si1288094qtb.371.2024.03.20.11.49.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 11:49:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=tukaani.org); spf=pass (google.com: domain of linux-kernel+bounces-109317-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109317-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2ACA71C218FB for ; Wed, 20 Mar 2024 18:49:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC4158562E; Wed, 20 Mar 2024 18:49:14 +0000 (UTC) Received: from mailscanner09.zoner.fi (mailscanner09.zoner.fi [5.44.246.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DCD485623 for ; Wed, 20 Mar 2024 18:49:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.44.246.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710960554; cv=none; b=SgDwIC4JT2jqbnIV5Eu/BykbzQHfqds9HnknT2oTZ8bkRsG/GvbWSXVfeXhkvrYrHKBn2LSDKbeHy2W1/uR5L4RW/ZWIKC9lrGjQ55fPpwATGhmYA5cXo9ASbHdwEnNBpSw8T6Mb9cjNrxTMkOuilgAPXOBFX1b3bORBoApyvNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710960554; c=relaxed/simple; bh=ByoVqAuRdD1oD3TBj0N5QxLkM+fd/TEn0WNYkz4c3B0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K3/lONLuUwx12vz/L/Om0skqGmAf9ZnmLwWZOMw9bUaw1v0SKcMM42GFoEsmAwMhBifIqhN220fp9eE4ozELF5/RZgkHYPpop/qVEAKsXTJNIuJWLk6xUxlrx20fmSmSpBMeVjTvFPklifyOe57uDQ8SZQ4sbT1dUsFYlK9QywU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tukaani.org; spf=pass smtp.mailfrom=tukaani.org; arc=none smtp.client-ip=5.44.246.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tukaani.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tukaani.org Received: from www25.zoner.fi (www25.zoner.fi [84.34.147.45]) by mailscanner09.zoner.fi (Postfix) with ESMTPS id CC5652108E; Wed, 20 Mar 2024 20:39:26 +0200 (EET) Received: from mail.zoner.fi ([84.34.147.244]) by www25.zoner.fi with esmtp (Exim 4.96.1-7-g79877b70e) (envelope-from ) id 1rn0qU-0001dW-23; Wed, 20 Mar 2024 20:39:26 +0200 From: Lasse Collin To: Andrew Morton Cc: Lasse Collin , Jia Tan , linux-kernel@vger.kernel.org Subject: [PATCH 08/11] xz: Add ARM64 BCJ filter Date: Wed, 20 Mar 2024 20:38:41 +0200 Message-ID: <20240320183846.19475-9-lasse.collin@tukaani.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320183846.19475-1-lasse.collin@tukaani.org> References: <20240320183846.19475-1-lasse.collin@tukaani.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Also omit a duplicated check for XZ_DEC_ARM in xz_private.h. This filter can be used by Squashfs without modifications to the Squashfs kernel code (only needs support in userspace Squashfs-tools). Reviewed-by: Jia Tan Signed-off-by: Lasse Collin --- Notes: Compared to the first patch I submitted on 2023-11-08 (see ), this has a minor tweak to make the for-loop condition faster. Squashfs-tools Git repository already has support for creating file systems that use the ARM64 filter. lib/xz/Kconfig | 5 +++++ lib/xz/xz_dec_bcj.c | 52 ++++++++++++++++++++++++++++++++++++++++++++- lib/xz/xz_private.h | 7 ++++-- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/lib/xz/Kconfig b/lib/xz/Kconfig index 6b80453d8f54..1166627a87dc 100644 --- a/lib/xz/Kconfig +++ b/lib/xz/Kconfig @@ -30,6 +30,11 @@ config XZ_DEC_ARMTHUMB default y select XZ_DEC_BCJ +config XZ_DEC_ARM64 + bool "ARM64 BCJ filter decoder" if EXPERT + default y + select XZ_DEC_BCJ + config XZ_DEC_SPARC bool "SPARC BCJ filter decoder" if EXPERT default y diff --git a/lib/xz/xz_dec_bcj.c b/lib/xz/xz_dec_bcj.c index e0b4bf4999c0..941198a8a55b 100644 --- a/lib/xz/xz_dec_bcj.c +++ b/lib/xz/xz_dec_bcj.c @@ -23,7 +23,8 @@ struct xz_dec_bcj { BCJ_IA64 = 6, /* Big or little endian */ BCJ_ARM = 7, /* Little endian only */ BCJ_ARMTHUMB = 8, /* Little endian only */ - BCJ_SPARC = 9 /* Big or little endian */ + BCJ_SPARC = 9, /* Big or little endian */ + BCJ_ARM64 = 10 /* AArch64 */ } type; /* @@ -346,6 +347,47 @@ static size_t bcj_sparc(struct xz_dec_bcj *s, uint8_t *buf, size_t size) } #endif +#ifdef XZ_DEC_ARM64 +static size_t bcj_arm64(struct xz_dec_bcj *s, uint8_t *buf, size_t size) +{ + size_t i; + uint32_t instr; + uint32_t addr; + + size &= ~(size_t)3; + + for (i = 0; i < size; i += 4) { + instr = get_unaligned_le32(buf + i); + + if ((instr >> 26) == 0x25) { + /* BL instruction */ + addr = instr - ((s->pos + (uint32_t)i) >> 2); + instr = 0x94000000 | (addr & 0x03FFFFFF); + put_unaligned_le32(instr, buf + i); + + } else if ((instr & 0x9F000000) == 0x90000000) { + /* ADRP instruction */ + addr = ((instr >> 29) & 3) | ((instr >> 3) & 0x1FFFFC); + + /* Only convert values in the range +/-512 MiB. */ + if ((addr + 0x020000) & 0x1C0000) + continue; + + addr -= (s->pos + (uint32_t)i) >> 12; + + instr &= 0x9000001F; + instr |= (addr & 3) << 29; + instr |= (addr & 0x03FFFC) << 3; + instr |= (0U - (addr & 0x020000)) & 0xE00000; + + put_unaligned_le32(instr, buf + i); + } + } + + return i; +} +#endif + /* * Apply the selected BCJ filter. Update *pos and s->pos to match the amount * of data that got filtered. @@ -392,6 +434,11 @@ static void bcj_apply(struct xz_dec_bcj *s, case BCJ_SPARC: filtered = bcj_sparc(s, buf, size); break; +#endif +#ifdef XZ_DEC_ARM64 + case BCJ_ARM64: + filtered = bcj_arm64(s, buf, size); + break; #endif default: /* Never reached but silence compiler warnings. */ @@ -565,6 +612,9 @@ XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id) #endif #ifdef XZ_DEC_SPARC case BCJ_SPARC: +#endif +#ifdef XZ_DEC_ARM64 + case BCJ_ARM64: #endif break; diff --git a/lib/xz/xz_private.h b/lib/xz/xz_private.h index 811add814ae4..307e0de8c260 100644 --- a/lib/xz/xz_private.h +++ b/lib/xz/xz_private.h @@ -36,6 +36,9 @@ # ifdef CONFIG_XZ_DEC_SPARC # define XZ_DEC_SPARC # endif +# ifdef CONFIG_XZ_DEC_ARM64 +# define XZ_DEC_ARM64 +# endif # ifdef CONFIG_XZ_DEC_MICROLZMA # define XZ_DEC_MICROLZMA # endif @@ -97,9 +100,9 @@ */ #ifndef XZ_DEC_BCJ # if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \ - || defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \ + || defined(XZ_DEC_IA64) \ || defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \ - || defined(XZ_DEC_SPARC) + || defined(XZ_DEC_SPARC) || defined(XZ_DEC_ARM64) # define XZ_DEC_BCJ # endif #endif -- 2.44.0