From patchwork Thu Nov 24 12:39:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 25507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3372040wrr; Thu, 24 Nov 2022 04:42:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf7xAlC8rYs6GH/xzzA5pU5S24ibKFwcvqGnNC6ObJutt8WVVbihNZlYdkndWMzUPxXrSvAk X-Received: by 2002:a17:902:e009:b0:186:f934:30af with SMTP id o9-20020a170902e00900b00186f93430afmr14274608plo.126.1669293750933; Thu, 24 Nov 2022 04:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669293750; cv=none; d=google.com; s=arc-20160816; b=Os5E5jHKTk5PtPjL+mrDDBEV3tSW1+npAdFMWAhZMPfSEIQJZMlYLR9lWia66v8m34 kpaHheCfon91grszoPbcVGCQjEOVVuihsgUd/0uxFPIirlObxSp8E9j8WEYLjX0BdowS d7dKO3UxVdTL9R+KiBmJk8KlCT3A60s4bf1LZstQSGiMwXcOQpMWv6+cKXrbLoWv9FEV SqQqKdn8Nt7cHVN7wMK+/dKU5t4xfkGU7Tzc1nqT72p1D2IwcmD5YvtfcHCxpZsIYLch /QCyDKo0F7pPLP73a/aTatMDsk9ECgZ0o6eWEuDqmrFl3CAXQwVvtr4GLgn/7yuEA22e 1mVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wMM4PNHomPxKIkSikNyQvbmojaiFll9TRLmQo4Q8tWw=; b=J23Av/53YMjAS422kDWQG99zaA4BZNLjW3T0TH5Jx/DKwcn9x+/iVez2pBmzsr3FgY /Ay/BajGJXu2tnQ3hIj64PlBa5UR4T4tioTyxMsRGiS19zbUbJybARaYAuPxS0IfuaP5 u/7Wl64hk4e/ZFCV56ATduUwMeCMK6a9LHp9mFAAGbJYGk8aRSdVAEennG9U7oxL/w+V F5SCSi/XWnV1F0ySant4LbRafPtLFomcpsGy530Biurgstbj2l+lnEqrJemFMDqFp+ym EtwbQhC9WSzi1ReE4iMjazA7srXoPhyj6U1LyE5n2qzAtBoQnUbJ+S9P+Yry75tBX1E5 1y5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jjTwBiy7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t7-20020a654b87000000b00476e9807c53si1064556pgq.50.2022.11.24.04.42.17; Thu, 24 Nov 2022 04:42:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jjTwBiy7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229936AbiKXMks (ORCPT + 99 others); Thu, 24 Nov 2022 07:40:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbiKXMka (ORCPT ); Thu, 24 Nov 2022 07:40:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D18D98245 for ; Thu, 24 Nov 2022 04:39:55 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A1FC962119 for ; Thu, 24 Nov 2022 12:39:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45D70C43147; Thu, 24 Nov 2022 12:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669293594; bh=ncTuy2wGTIYIRDuDgupcnhxQcFcwTch9Wfg3k1aZ64w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjTwBiy76tw/z8GXhzp7QGLMPYjOTQ4GUipQ+LY3vcZbJjAoMAQyoCyr4buSbQM6G hvXp4kr/JgTjB/tzfWuLZQ9PEYxy9K5aRN7XDx3A/HvTSo7pko+gL1famGfEhxxYv8 yu8VpBT1nF1YTjEOgDcalRx7UoYrefJRVJuB32L4sWx/B/f5XPLMWdi9lnYjL/jvQX t44w/FTdSzMR6051hi4NUn3NOzBlWnfa8ovv6hVgDVxODyL6GlNEJ/5hSDcW2wLn2h Sq8Vf8xYARV42Y6Hz+Tx+GhplGi4WVfHs3kGiWfkNIsWRX/vm24xg1KsCs2ErJmeEG eaurHt8JaA/nA== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown , Anshuman Khandual , Richard Henderson , Ryan Roberts , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/19] arm64/mm: Simplify and document pte_to_phys() for 52 bit addresses Date: Thu, 24 Nov 2022 13:39:14 +0100 Message-Id: <20221124123932.2648991-2-ardb@kernel.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221124123932.2648991-1-ardb@kernel.org> References: <20221124123932.2648991-1-ardb@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750381364214297731?= X-GMAIL-MSGID: =?utf-8?q?1750381364214297731?= From: Anshuman Khandual pte_to_phys() assembly definition does multiple bits field transformations to derive physical address, embedded inside a page table entry. Unlike its C counter part i.e __pte_to_phys(), pte_to_phys() is not very apparent. It simplifies these operations via a new macro PTE_ADDR_HIGH_SHIFT indicating how far the pte encoded higher address bits need to be left shifted. While here, this also updates __pte_to_phys() and __phys_to_pte_val(). Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Cc: Mark Rutland Cc: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Ard Biesheuvel Suggested-by: Ard Biesheuvel Signed-off-by: Anshuman Khandual Link: https://lore.kernel.org/r/20221107141753.2938621-1-anshuman.khandual@arm.com Signed-off-by: Will Deacon --- arch/arm64/include/asm/assembler.h | 8 +++----- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/include/asm/pgtable.h | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index e5957a53be39..89038067ef34 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -660,12 +660,10 @@ alternative_endif .endm .macro pte_to_phys, phys, pte -#ifdef CONFIG_ARM64_PA_BITS_52 - ubfiz \phys, \pte, #(48 - 16 - 12), #16 - bfxil \phys, \pte, #16, #32 - lsl \phys, \phys, #16 -#else and \phys, \pte, #PTE_ADDR_MASK +#ifdef CONFIG_ARM64_PA_BITS_52 + orr \phys, \phys, \phys, lsl #PTE_ADDR_HIGH_SHIFT + and \phys, \phys, GENMASK_ULL(PHYS_MASK_SHIFT - 1, PAGE_SHIFT) #endif .endm diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 5ab8d163198f..f658aafc47df 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -159,6 +159,7 @@ #ifdef CONFIG_ARM64_PA_BITS_52 #define PTE_ADDR_HIGH (_AT(pteval_t, 0xf) << 12) #define PTE_ADDR_MASK (PTE_ADDR_LOW | PTE_ADDR_HIGH) +#define PTE_ADDR_HIGH_SHIFT 36 #else #define PTE_ADDR_MASK PTE_ADDR_LOW #endif diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 71a1af42f0e8..daedd6172227 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -77,11 +77,11 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]; static inline phys_addr_t __pte_to_phys(pte_t pte) { return (pte_val(pte) & PTE_ADDR_LOW) | - ((pte_val(pte) & PTE_ADDR_HIGH) << 36); + ((pte_val(pte) & PTE_ADDR_HIGH) << PTE_ADDR_HIGH_SHIFT); } static inline pteval_t __phys_to_pte_val(phys_addr_t phys) { - return (phys | (phys >> 36)) & PTE_ADDR_MASK; + return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PTE_ADDR_MASK; } #else #define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_MASK)