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 X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 186A9C432BE for ; Thu, 26 Aug 2021 16:58:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CFC1260F42 for ; Thu, 26 Aug 2021 16:58:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CFC1260F42 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=xzPX9ZXnGUWNBiVysv9BBA47qYPTIYh/XLzK+BzGFhc=; b=nakEaM4LKQb+cG o7vjSziwqjF4huGEnVTex0rBQfzcZAV7n2IPDL9GPih0RnPGO0AzORmeTRLxikZeML2gJG+CdSdCO WD1N0/6/K+XxjSu26McJ+XL0qEAfkQbUw8txtSQyu3G3qxsdhmaW0GE5SSxJKaOOpVY2nm/axWpZo qdtZa1pWW/fUWqG9M0dkpPq5CR0zUpq9yH2Xmbv7MffpB0W1NOhWc7G+YOYsHKGKK5MxCDSIwhB08 8hcMEn/rg52oF1KT+0BCzJeP0QElXMmpXnmvckzTdslwtLU+zIz48GhfSPP/XmgsXhpY6FusF38tm qY0cu0eVRYg9K3ufvdAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJIg1-00Ac2A-HJ; Thu, 26 Aug 2021 16:56:29 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJIfx-00Ac1p-1j for linux-arm-kernel@lists.infradead.org; Thu, 26 Aug 2021 16:56:26 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0ACBA60F42; Thu, 26 Aug 2021 16:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629996984; bh=c6pWoRaQnBta9tdJoa+i7+BX7PC9UYSIDAP9Q5VWOzk=; h=From:To:Cc:Subject:Date:From; b=HDp22XqHKRrunpxxpS0sHIfvqOAtBHkbPeA+WmWPAfYy/IyXiKMPFRc9NO3bivm96 NrEzdw9TmsSVG0GNF2i57lYloOSyFQxnghnvSOCgiYTycf3er/5oxdLaRb0KZtjU7m J7fNd6ZHFvhk4BLsxdMV7oovcyTPHvn0pPdRoiXmXvsBVRIUYvUGbEd71l4jtiFJ3M ZJItpMTw+/5U1NXN1YT8EXIRuUcEL+3WqbGes1mxxFek2vbp+xgxp6HHT8x601mAmA TnP7N7Ak4/Eips/7aEGT6IiTNv9yzyHZrn9YWgYlkenGbvTKJZQVuPzxUMma7j79rO V3EVS91FSFxkw== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, maz@kernel.org, anshuman.khandual@arm.com, steve.capper@arm.com, Ard Biesheuvel Subject: [PATCH v2] arm64: mm: limit linear region to 51 bits for KVM in nVHE mode Date: Thu, 26 Aug 2021 18:56:13 +0200 Message-Id: <20210826165613.60774-1-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210826_095625_148019_FEF6CD37 X-CRM114-Status: GOOD ( 15.71 ) 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 KVM in nVHE mode divides up its VA space into two equal halves, and picks the half that does not conflict with the HYP ID map to map its linear region. This worked fine when the kernel's linear map itself was guaranteed to cover precisely as many bits of VA space, but this was changed by commit f4693c2716b35d08 ("arm64: mm: extend linear region for 52-bit VA configurations"). The result is that, depending on the placement of the ID map, kernel-VA to hyp-VA translations may produce addresses that either conflict with other HYP mappings (including the ID map itself) or generate addresses outside of the 52-bit addressable range, neither of which is likely to lead to anything useful. Given that 52-bit capable cores are guaranteed to implement VHE, this only affects configurations such as pKVM where we opt into non-VHE mode even if the hardware is VHE capable. So just for these configurations, let's limit the kernel linear map to 51 bits and work around the problem. Fixes:f4693c2716b35d08 ("arm64: mm: extend linear region for 52-bit VA configurations") Signed-off-by: Ard Biesheuvel --- v2: - take min() of prior value of linear_region_size and BIT(51) to avoid surprises - check is_hyp_mode_available() so that the exception is only applied to KVM hosts arch/arm64/mm/init.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 8490ed2917ff..2b28d77e29a0 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -282,7 +282,21 @@ static void __init fdt_enforce_memory_region(void) void __init arm64_memblock_init(void) { - const s64 linear_region_size = PAGE_END - _PAGE_OFFSET(vabits_actual); + s64 linear_region_size = PAGE_END - _PAGE_OFFSET(vabits_actual); + + /* + * Corner case: 52-bit VA capable systems running KVM in nVHE mode may + * be limited in their ability to support a linear map that exceeds 51 + * bits of VA space, depending on the placement of the ID map. Given + * that the placement of the ID map may be randomized, let's simply + * limit the kernel's linear map to 51 bits as well if we detect this + * configuration. + */ + if (IS_ENABLED(CONFIG_KVM) && vabits_actual == 52 && + is_hyp_mode_available() && !is_kernel_in_hyp_mode()) { + pr_info("Capping linear region to 51 bits for KVM in nVHE mode on LVA capable hardware.\n"); + linear_region_size = min_t(u64, linear_region_size, BIT(51)); + } /* Handle linux,usable-memory-range property */ fdt_enforce_memory_region(); -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel