From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 9ADC3C25B77 for ; Fri, 17 May 2024 13:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=h8MZyqICcq4OG9frDpuEg2NmQhKyMajbQfJhJdxoQ/o=; b=crU8uBY7CdI6qE fpVwxtlmbir81Aa4HvIDQaPtpM2YOVYXg/a17Mvnz+LcrUtC4W9/dDo/X9QSQ1xjS4/nkk3xkYsn4 EXid8JzsV5bgxMFBK1Y1pTeIQQ0Q0uV9xuqtDZefdbRFgz+Fk/cULGCxodby9TyOCq0jwTqQjmaRL MTkL9vrIQ5qpEeSRQru4Aho0eH28YIUUg0J7QvQu2Q3JGLAvHSCwj+oXlEhbV1aJ072woGbJJ49rp q2GGhIja09d226aGbnvWXL0BAe5AXRq1XGFzZXYUku2weijbOxlIeV8wUuC+2bglp4cbrrv/qjxPW /MVbdSUTz//PTeHp5sWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7xZs-00000007wTe-3YTB; Fri, 17 May 2024 13:24:53 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7xZp-00000007wTB-2Wet for linux-arm-kernel@lists.infradead.org; Fri, 17 May 2024 13:24:51 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 166571424; Fri, 17 May 2024 06:25:08 -0700 (PDT) Received: from e116581.blr.arm.com (e116581.arm.com [10.162.43.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 41DFA3F641; Fri, 17 May 2024 06:24:39 -0700 (PDT) From: Dev Jain To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org Cc: ardb@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, suzuki.poulose@arm.com, broonie@kernel.org, James.Morse@arm.com, Anshuman.Khandual@arm.com, Dev Jain Subject: [PATCH] arm64: kernel: Replace manual computation with macro Date: Fri, 17 May 2024 18:54:21 +0530 Message-Id: <20240517132421.285667-1-dev.jain@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240517_062449_719248_7F7A3662 X-CRM114-Status: GOOD ( 10.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use macro from pgtable-hwdef.h for better readability. I have boot tested this patch on all page table level configs, including LVA/LPA/LPA2 configurations, and forced 52 bit userspace VA. - Claim: There should be no functional change after applying this patch. Proof: lshift is being used only for computing lmask and tbl. It suffices to prove that lmask and tbl remain invariant. Let s = PAGE_SHIFT, l = level. new_lshift ---> (expand macro) = (s - 3) * (4 - l) + 3 = 4s - sl - 12 + 3l + 3 = 4s - sl + 3l - 9 = (3s - sl + 3l - 9) + s = s(3 - l) + 3(l - 3) + s = (3 - l) * (s - 3) + s = old_lshift + s Hence, new_lshift = old_lshift + PAGE_SHIFT. => tbl is invariant. Noting that old_lmask = (PAGE_SIZE << old_lshift) = ((1 << PAGE_SHIFT) << old_lshift) = (1 << (PAGE_SHIFT + old_lshift)) = (1 << new_lshift) = new_lmask, we are done. Q.E.D Signed-off-by: Dev Jain --- arch/arm64/kernel/pi/map_range.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/pi/map_range.c b/arch/arm64/kernel/pi/map_range.c index 5410b2cac590..4b145be7f846 100644 --- a/arch/arm64/kernel/pi/map_range.c +++ b/arch/arm64/kernel/pi/map_range.c @@ -31,14 +31,14 @@ void __init map_range(u64 *pte, u64 start, u64 end, u64 pa, pgprot_t prot, { u64 cmask = (level == 3) ? CONT_PTE_SIZE - 1 : U64_MAX; u64 protval = pgprot_val(prot) & ~PTE_TYPE_MASK; - int lshift = (3 - level) * (PAGE_SHIFT - 3); - u64 lmask = (PAGE_SIZE << lshift) - 1; + int lshift = ARM64_HW_PGTABLE_LEVEL_SHIFT(level); + u64 lmask = ((u64)1 << lshift) - 1; start &= PAGE_MASK; pa &= PAGE_MASK; /* Advance tbl to the entry that covers start */ - tbl += (start >> (lshift + PAGE_SHIFT)) % PTRS_PER_PTE; + tbl += (start >> lshift) % PTRS_PER_PTE; /* * Set the right block/page bits for this level unless we are -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel