Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8820914rwb; Thu, 24 Nov 2022 04:53:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf72QQKZcp5Vo0ZjiQlHKozS5FSMnr1DWSvdGmZ12qiIrk076+GxJEhFcmjbKNR6ht06P6GC X-Received: by 2002:a17:902:7042:b0:186:7fce:5ec9 with SMTP id h2-20020a170902704200b001867fce5ec9mr16971523plt.48.1669294402438; Thu, 24 Nov 2022 04:53:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669294402; cv=none; d=google.com; s=arc-20160816; b=oxcRm1NvL86X0KbDRnveDrnGQF7OjwiPcV61nQzBnXOrTQdWYaBxN9u4Yco5b1Eefc wBIR8BH0CXvYG4gsw8OLZjEIoLY8mOvEnqTpwUMOjlU5PDwk07wR87u6i3/ZdoXg71lg 8CUAsE2ROWe+NaWpABE8gpZ2OPXIbRHR2LQ3SUCezovDWMzuHLtgSGWYDdPGa7UjXCFX ztohO6AMFyqwklaY+j3Jz9NDrZ4JM/+xqRSpL3dikx3cHD7DWRgrYAXdMLyjJz3hOiXQ fYs6dgbIx+7c8qHy/1iYW5P2r/ysKv64i2dEXPD3Xt085vSY1clJctZP+B0FrJdufszU iZ6Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020a17090aa00200b00212b9a2d735si4233910pjp.121.2022.11.24.04.53.10; Thu, 24 Nov 2022 04:53:22 -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 + 87 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 Content-Transfer-Encoding: 8bit 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 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) -- 2.38.1.584.g0f3c55d4c2-goog