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=-14.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 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 3B7A4C4338F for ; Tue, 24 Aug 2021 12:58:39 +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 01B996127B for ; Tue, 24 Aug 2021 12:58:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 01B996127B 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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SJnfBLXWrzb+Icn+SNIb3FjdB3tmMlOk3DaeRkrNiBo=; b=T85fgGcDMrJy9i EAue7zsdnvU49voDS0zQu1OjJSCsbPqbpxyD/GmWgYSVTdiz1NLftUHHUWh6jIFFtn7TkiHN6xbmj KFvbwAjiG8FtyDlX6LB4K0Zo9osA+AJ5NCPEUts3x7KwLfKsZnZRnlbsm+EDGFX9A/8WdGnfXwer4 lifuyF4Q4GWKi5wixs82NFDyeKtgDS+JQofaokMPCmqCPcLsn7tFjfqMoImLbKizn1YUtErwqszfq PnIVP9On38FLx4bSpiCpPSiJMBASCFFeowx69cAP0zYD6u8MKXNus+vJ2f9dpLympY7oILuhoZTOR hZqI/bNsclNOe45YJKtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIVyk-00380E-RS; Tue, 24 Aug 2021 12:56:35 +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 1mIVyh-0037zM-DJ for linux-arm-kernel@lists.infradead.org; Tue, 24 Aug 2021 12:56:32 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0C6F61371 for ; Tue, 24 Aug 2021 12:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629809790; bh=ZvGYzpv/nqQVRlZy87gbZQ2dnP1ufQ3BMtU9BEKxOh0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=F3apc18Q3u+a88I//F9kzp2EurBCXXwHrj22LBB2ni5W8SSu5hL4g7yd6fjGQVO6x 9+ha4yEU8o/YERaKB3SxSUyd7di7hU9pej/bEZlLG8pUa8SPzZ8flIWGWnrUjm/dQ0 VmWm9SMh6bzEC0lVyw/spzsdg+zMTw5cZnglLPw6Zh6Zd9FqrnQradDSusJmsyp/w3 GVqWVS6Ea44X8eZ0OJDYsYa6qmUugS6VFed1YsvQEH54LfbvFv+46H2gJtqWaSQizu 1KMFqAd/fy9dSqn5RV/2OojQmA1XlatBHyrmEg9AMuBwkKzJ41+iKbHosvDrlfkvTV YAQ/D/c0puRFA== Received: by mail-oo1-f50.google.com with SMTP id m11-20020a056820034b00b0028bb60b551fso6457148ooe.5 for ; Tue, 24 Aug 2021 05:56:30 -0700 (PDT) X-Gm-Message-State: AOAM533JvEq8w+MVqr4w7GAqNlYI/itjGwa2W4NLYTK3/pJtwtQgEIwA wxR3QLYD0hXlmI+U0jGIAddQoKSXpZ3JqdZFz0w= X-Google-Smtp-Source: ABdhPJxD8jdBpxfs9q2vthPuMGWYkzZpyvVUwC+oikgA2zXC+PQPCkaouuzKiOsS5m05GYI6Mx8vbAI0NP81JGWds3M= X-Received: by 2002:a4a:d752:: with SMTP id h18mr29935826oot.13.1629809790005; Tue, 24 Aug 2021 05:56:30 -0700 (PDT) MIME-Version: 1.0 References: <20210810161244.84231-1-ardb@kernel.org> <20210824105920.GB22752@willie-the-truck> In-Reply-To: <20210824105920.GB22752@willie-the-truck> From: Ard Biesheuvel Date: Tue, 24 Aug 2021 14:56:22 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH] arm64: mm: limit linear region to 51 bits for KVM in nVHE mode To: Will Deacon Cc: Linux ARM , Catalin Marinas , Mark Rutland , Marc Zyngier , Anshuman Khandual , Steve Capper X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_055631_531319_1CBC85E5 X-CRM114-Status: GOOD ( 31.98 ) 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 On Tue, 24 Aug 2021 at 12:59, Will Deacon wrote: > > On Tue, Aug 10, 2021 at 06:12:44PM +0200, Ard Biesheuvel wrote: > > 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 > > --- > > NOTE: build tested only > > > > 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..542dad13e2fc 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_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 = BIT(51); > > + } > > Slight nit, but to avoid having to think about PAGE_END I think this would > be a little clearer as: > > if (IS_ENABLED(CONFIG_KVM) && !is_kernel_in_hyp_mode()) > linear_region_size = min_t(u64, linear_region_size, BIT(51)); > Fair enough. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel