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 75657D16261 for ; Mon, 14 Oct 2024 13:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3nrZRX6TfU/x+EEfp90rIVyosRBuV8WxY4dYQBhPLrg=; b=pI82QUPzd7r61lSqsyzpS4Txsb /E9ryweju4Ya3UsAs9ixvUkYWY1F8p/EGvdJikG6K40k47ZD9qO/+bJHIFWyUnr/lpyqTmrQi30K8 /Nho3YwZiImGlXn3377p4v/FcCciHzsDLJxXxXVvCZDBD+kW4/cUjf7l73ClK7q/olYfZaeXMyaO1 DmSD8YJqZrxxx67id3lGfajuHR8IJqNyMD03BJDwr2hukYtM7l41O1iyGGYUkNV9djqDnltJFUT02 mG/6KG/3Lb2BmZJERLSd9yqz/ow3Pbxehojl3OvdDak1TVLkDdvnF6SWGLfv6fyfstydX/YkmN11b yv0wkV5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0L1r-00000005FCn-2Ct0; Mon, 14 Oct 2024 13:22:31 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0JFX-00000004va2-1vxs for linux-arm-kernel@lists.infradead.org; Mon, 14 Oct 2024 11:28:42 +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 3BC401424; Mon, 14 Oct 2024 04:29:00 -0700 (PDT) Received: from [10.57.86.130] (unknown [10.57.86.130]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A9D33F51B; Mon, 14 Oct 2024 04:28:27 -0700 (PDT) Message-ID: Date: Mon, 14 Oct 2024 12:28:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 55/57] arm64: TRAMP_VALIAS is no longer compile-time constant Content-Language: en-GB To: Ard Biesheuvel Cc: Andrew Morton , Anshuman Khandual , Catalin Marinas , David Hildenbrand , Greg Marsden , Ivan Ivanov , Kalesh Singh , Marc Zyngier , Mark Rutland , Matthias Brugger , Miroslav Benes , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20241014105514.3206191-1-ryan.roberts@arm.com> <20241014105912.3207374-1-ryan.roberts@arm.com> <20241014105912.3207374-55-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241014_042831_640694_B51CC237 X-CRM114-Status: GOOD ( 20.80 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 14/10/2024 12:21, Ard Biesheuvel wrote: > Hi Ryan, > > On Mon, 14 Oct 2024 at 13:02, Ryan Roberts wrote: >> >> When boot-time page size is in operation, TRAMP_VALIAS is no longer a >> compile-time constant, because the VA of a fixmap slot depends upon >> PAGE_SIZE. >> >> Let's handle this by instead exporting the slot index, >> FIX_ENTRY_TRAMP_BEGIN,to assembly, then do the TRAMP_VALIAS calculation >> per page size and use alternatives to decide which variant to activate. >> >> Note that for the tramp_map_kernel case, we are one instruction short of >> space in the vector to have NOPs for all 3 page size variants. So we do >> if/else for 16K/64K and branch around it for the 4K case. This saves 2 >> instructions. >> >> Signed-off-by: Ryan Roberts >> --- >> >> ***NOTE*** >> Any confused maintainers may want to read the cover note here for context: >> https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/ >> >> arch/arm64/kernel/asm-offsets.c | 2 +- >> arch/arm64/kernel/entry.S | 50 ++++++++++++++++++++++++++------- >> 2 files changed, 41 insertions(+), 11 deletions(-) >> >> diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c >> index f32b8d7f00b2a..c45fa3e281884 100644 >> --- a/arch/arm64/kernel/asm-offsets.c >> +++ b/arch/arm64/kernel/asm-offsets.c >> @@ -172,7 +172,7 @@ int main(void) >> DEFINE(ARM64_FTR_SYSVAL, offsetof(struct arm64_ftr_reg, sys_val)); >> BLANK(); >> #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 >> - DEFINE(TRAMP_VALIAS, TRAMP_VALIAS); >> + DEFINE(FIX_ENTRY_TRAMP_BEGIN, FIX_ENTRY_TRAMP_BEGIN); >> #endif >> #ifdef CONFIG_ARM_SDE_INTERFACE >> DEFINE(SDEI_EVENT_INTREGS, offsetof(struct sdei_registered_event, interrupted_regs)); >> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S >> index 7ef0e127b149f..ba47dc8672c04 100644 >> --- a/arch/arm64/kernel/entry.S >> +++ b/arch/arm64/kernel/entry.S >> @@ -101,11 +101,27 @@ >> .org .Lventry_start\@ + 128 // Did we overflow the ventry slot? >> .endm >> >> +#define TRAMP_VALIAS(page_shift) (FIXADDR_TOP - (FIX_ENTRY_TRAMP_BEGIN << (page_shift))) >> + >> .macro tramp_alias, dst, sym >> - .set .Lalias\@, TRAMP_VALIAS + \sym - .entry.tramp.text >> - movz \dst, :abs_g2_s:.Lalias\@ >> - movk \dst, :abs_g1_nc:.Lalias\@ >> - movk \dst, :abs_g0_nc:.Lalias\@ >> +alternative_if ARM64_USE_PAGE_SIZE_4K >> + .set .Lalias4k\@, TRAMP_VALIAS(ARM64_PAGE_SHIFT_4K) + \sym - .entry.tramp.text >> + movz \dst, :abs_g2_s:.Lalias4k\@ >> + movk \dst, :abs_g1_nc:.Lalias4k\@ >> + movk \dst, :abs_g0_nc:.Lalias4k\@ >> +alternative_else_nop_endif >> +alternative_if ARM64_USE_PAGE_SIZE_16K >> + .set .Lalias16k\@, TRAMP_VALIAS(ARM64_PAGE_SHIFT_16K) + \sym - .entry.tramp.text >> + movz \dst, :abs_g2_s:.Lalias16k\@ >> + movk \dst, :abs_g1_nc:.Lalias16k\@ >> + movk \dst, :abs_g0_nc:.Lalias16k\@ >> +alternative_else_nop_endif >> +alternative_if ARM64_USE_PAGE_SIZE_64K >> + .set .Lalias64k\@, TRAMP_VALIAS(ARM64_PAGE_SHIFT_64K) + \sym - .entry.tramp.text >> + movz \dst, :abs_g2_s:.Lalias64k\@ >> + movk \dst, :abs_g1_nc:.Lalias64k\@ >> + movk \dst, :abs_g0_nc:.Lalias64k\@ >> +alternative_else_nop_endif > > Since you're changing these, might as well drop the middle movk as the > fixmap is now always in the top 2 GiB of the VA space. > > However, wouldn't it be better to reuse the existing callback > alternative stuff that Marc added for KVM? Yes, I agree. Mark suggested the same thing when we were talking the other day too. I'll definitely use the callbacks for next version, but I didn't want to hold up the RFC any further - I'd already spent way too much time polishing. > > Same applies below, I reckon. > >> .endm >> >> /* >> @@ -627,16 +643,30 @@ SYM_CODE_END(ret_to_user) >> bic \tmp, \tmp, #USER_ASID_FLAG >> msr ttbr1_el1, \tmp >> #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 >> -alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1003 >> +alternative_if_not ARM64_WORKAROUND_QCOM_FALKOR_E1003 >> + b .Lskip_falkor_e1003\@ >> +alternative_else_nop_endif >> /* ASID already in \tmp[63:48] */ >> - movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS >> 12) >> - movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS >> 12) >> - /* 2MB boundary containing the vectors, so we nobble the walk cache */ >> - movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS & ~(SZ_2M - 1)) >> 12) >> +alternative_if ARM64_USE_PAGE_SIZE_4K >> + movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS(ARM64_PAGE_SHIFT_4K) >> 12) >> + movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS(ARM64_PAGE_SHIFT_4K) >> 12) >> + movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS(ARM64_PAGE_SHIFT_4K) & ~(SZ_2M - 1)) >> 12) >> + b .Lfinish_falkor_e1003\@ >> +alternative_else_nop_endif >> +alternative_if ARM64_USE_PAGE_SIZE_16K >> + movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS(ARM64_PAGE_SHIFT_16K) >> 12) >> + movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS(ARM64_PAGE_SHIFT_16K) >> 12) >> + movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS(ARM64_PAGE_SHIFT_16K) & ~(SZ_2M - 1)) >> 12) >> +alternative_else /* ARM64_USE_PAGE_SIZE_64K */ >> + movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS(ARM64_PAGE_SHIFT_64K) >> 12) >> + movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS(ARM64_PAGE_SHIFT_64K) >> 12) >> + movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS(ARM64_PAGE_SHIFT_64K) & ~(SZ_2M - 1)) >> 12) >> +alternative_endif >> +.Lfinish_falkor_e1003\@: >> isb >> tlbi vae1, \tmp >> dsb nsh >> -alternative_else_nop_endif >> +.Lskip_falkor_e1003\@: >> #endif /* CONFIG_QCOM_FALKOR_ERRATUM_1003 */ >> .endm >> >> -- >> 2.43.0 >>