Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3530397pxf; Mon, 15 Mar 2021 11:36:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXpUW7BBqaPw6yeWCnaQpsA3htI/DeZeQ6bn2FJAsP9xFlYdEeXz0QcaP5LnVm2J+ybOAe X-Received: by 2002:a17:907:4cf:: with SMTP id vz15mr24865251ejb.113.1615833403106; Mon, 15 Mar 2021 11:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833403; cv=none; d=google.com; s=arc-20160816; b=gxBgeAONjBxKfAz8uY+kXtIqwA49575FyjQBM0b8CaFA9OPo4BF9oKD8qPdesFhmdY 5pZFeUz4db7hv+zb6tq729aBNOL0EnEkRivfgMCqe2K0Ka1gb5/1WK7+iXMRd5sjUrD0 BH5n9Jg9n6pdE0ua4mW8Hok6WwuW32FJjLSQEVmYSFHHWggIJJNkUhu1vavTws/P3ReU 76GVn8B2KMIFEfS+LzR8ObSp13ynSb94pcZLpRDY6wHYkc9auS5Tixelvd+gZW7Q3OB6 NXw8h18sqkJBKvXsCxiCjrjOhfJqr4TKhMRM7ZVjvDQP4DmBosjg/6hSiAcrnirWqVnM O7Dw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FODDcLbtZR5PD9pRIhjOQJSyxHNIzNZCLCxBvjugnjQ=; b=FrP0XNKHx7SsBMA5tHUzUhUmYEpG5rP1whs1efrvWZUSfO/NfNJKpeDzq0+OO04Npa ZTTxLldCdyYRx0hATG3bGkqPrqbKvkF9wWXdTMIVruwiW8HJ9ORrO4o3B5wn7iLVi8IK PxDcS7E09utDOwV1Bb/GLbNJoV2uWPnHXHikTko9z3xXw8uKUyt36XdN8DAxrGgUdMik 22JSb5QNYJ0uuyJKdhEcEzPkh3v1dN1pyV8SfEOQCWxMyEr+iDYoYG2dvBP1okYX+9Ma b1BfEFqolP+gxGmHnNNabAk4PU5LqkmqLOyOwY6xgvNbGAzqzxNH157XPMaI1iDFMUl+ eZGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lkfdOJxx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a26si10499619edx.539.2021.03.15.11.36.20; Mon, 15 Mar 2021 11:36:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lkfdOJxx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241047AbhCOOsX (ORCPT + 99 others); Mon, 15 Mar 2021 10:48:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:50058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234481AbhCOODp (ORCPT ); Mon, 15 Mar 2021 10:03:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1746B64EF1; Mon, 15 Mar 2021 14:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817024; bh=WtmMRBEZ6HyeP+mdN5x/IA7nqV4P4wPW+6UIcR7l5l8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lkfdOJxx6ZKa9B+EQe92wda+ULiKdzTdrqkzKd3mb7Lr8PhTtsPBSWw77vKE6Y0RT D+QnIWay3Y4uXmvP8CD5RvlGVkvaqAN1+Hx5UlTvWHNKDOHiWhM+wPny0+vlqtjXNg Kio9Ej1oWIf2Z29eQHBWpPXTMMboEwO3fP6WD0Yw= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Salter , Ard Biesheuvel , Will Deacon , Sasha Levin Subject: [PATCH 5.10 252/290] arm64: mm: use a 48-bit ID map when possible on 52-bit VA builds Date: Mon, 15 Mar 2021 14:55:45 +0100 Message-Id: <20210315135550.534088596@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Ard Biesheuvel [ Upstream commit 7ba8f2b2d652cd8d8a2ab61f4be66973e70f9f88 ] 52-bit VA kernels can run on hardware that is only 48-bit capable, but configure the ID map as 52-bit by default. This was not a problem until recently, because the special T0SZ value for a 52-bit VA space was never programmed into the TCR register anwyay, and because a 52-bit ID map happens to use the same number of translation levels as a 48-bit one. This behavior was changed by commit 1401bef703a4 ("arm64: mm: Always update TCR_EL1 from __cpu_set_tcr_t0sz()"), which causes the unsupported T0SZ value for a 52-bit VA to be programmed into TCR_EL1. While some hardware simply ignores this, Mark reports that Amberwing systems choke on this, resulting in a broken boot. But even before that commit, the unsupported idmap_t0sz value was exposed to KVM and used to program TCR_EL2 incorrectly as well. Given that we already have to deal with address spaces being either 48-bit or 52-bit in size, the cleanest approach seems to be to simply default to a 48-bit VA ID map, and only switch to a 52-bit one if the placement of the kernel in DRAM requires it. This is guaranteed not to happen unless the system is actually 52-bit VA capable. Fixes: 90ec95cda91a ("arm64: mm: Introduce VA_BITS_MIN") Reported-by: Mark Salter Link: http://lore.kernel.org/r/20210310003216.410037-1-msalter@redhat.com Signed-off-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20210310171515.416643-2-ardb@kernel.org Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/include/asm/mmu_context.h | 5 +---- arch/arm64/kernel/head.S | 2 +- arch/arm64/mm/mmu.c | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 0672236e1aea..4e2ba9477845 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -65,10 +65,7 @@ extern u64 idmap_ptrs_per_pgd; static inline bool __cpu_uses_extended_idmap(void) { - if (IS_ENABLED(CONFIG_ARM64_VA_BITS_52)) - return false; - - return unlikely(idmap_t0sz != TCR_T0SZ(VA_BITS)); + return unlikely(idmap_t0sz != TCR_T0SZ(vabits_actual)); } /* diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index e7550a5289fe..78cdd6b24172 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -334,7 +334,7 @@ SYM_FUNC_START_LOCAL(__create_page_tables) */ adrp x5, __idmap_text_end clz x5, x5 - cmp x5, TCR_T0SZ(VA_BITS) // default T0SZ small enough? + cmp x5, TCR_T0SZ(VA_BITS_MIN) // default T0SZ small enough? b.ge 1f // .. then skip VA range extension adr_l x6, idmap_t0sz diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index f0125bb09fa3..6aabf1eced31 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -40,7 +40,7 @@ #define NO_BLOCK_MAPPINGS BIT(0) #define NO_CONT_MAPPINGS BIT(1) -u64 idmap_t0sz = TCR_T0SZ(VA_BITS); +u64 idmap_t0sz = TCR_T0SZ(VA_BITS_MIN); u64 idmap_ptrs_per_pgd = PTRS_PER_PGD; u64 __section(".mmuoff.data.write") vabits_actual; -- 2.30.1