Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5504969rwe; Tue, 18 Apr 2023 07:45:06 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1drqKppgamTSPIYDA0UrBLENhHeeYyYqR5LduBaNpLVF766Uko9T5MbuRYlIyBJ3721p7 X-Received: by 2002:a17:902:d40c:b0:19f:3b86:4715 with SMTP id b12-20020a170902d40c00b0019f3b864715mr2097657ple.8.1681829106357; Tue, 18 Apr 2023 07:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681829106; cv=none; d=google.com; s=arc-20160816; b=WbL8ytuisWYoWl06J9x18MnksDQDe5CKgHZp0Ovf2MOb9y/lfoaHNNXvsRcXp/vc+Q 55ygOm7qkyVTyihZUgxyQcEG13Z1CHEoyz4RctNagP3g2YXWTTrU1zUNSu2sYmvq17pi 7mzYCF/xbCy7GIuaBvQqFL5YaFAYmAtM3kwratbAQWFPH/cJfuf0b7kKVDin/jGUo8zv NwIXRV6J46nsXWeV243BtH/ptPMpqyscrT7isOHezI0MuQI/mIp1wgnyqewZuP69pFmA UpR/V8YHLK5zSux42iXjCzMgjiNtcTfPYv2z6A+yLQZ1IsR6Bm0dm+sWPd7XaOmjVZvS pMjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=ujLDE/yC/FjKRpp+K7flZoqtD7sFn5B38o1/h41uTJc=; b=GOTAzeRpcE/i52Ci7CKBbslt7F5rKcsVrmi8JyNv/gfyjkbxofn+4nzs6zMiO7Q/S6 yW1NNNgkBT+zTwKJ6Fu/C7uk1KKo/ug5guY9H3seVMIV5V0pHeOWpBDA1D5JBMaXG9fc vIniNIG3bL1nBH74bQaf9CU1WIEGpNF2saarzYin/5mdm1XwPniMrSXxYNGOiHU6mGer Yad47NnqTsmO2aA+FkOHkfd8+aBv0cRRUVZiZfFobgrLLIsBFw+att9jS3HYuDF3nLxN YiznwAh84PKIukryw/VnQ0Q+u67FfZgcpW7EfQw0XuOXjtGZ+3Hndr80M+DgKUVgAr58 cqWw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020a170903245200b001a6492cdf2bsi15067233pls.343.2023.04.18.07.44.54; Tue, 18 Apr 2023 07:45:06 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbjDRO34 (ORCPT + 99 others); Tue, 18 Apr 2023 10:29:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232326AbjDRO3x (ORCPT ); Tue, 18 Apr 2023 10:29:53 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DFBA0C676 for ; Tue, 18 Apr 2023 07:29:48 -0700 (PDT) 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 65F971684; Tue, 18 Apr 2023 07:30:32 -0700 (PDT) Received: from [10.1.27.157] (C02CF1NRLVDN.cambridge.arm.com [10.1.27.157]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 86F483F587; Tue, 18 Apr 2023 07:29:47 -0700 (PDT) Message-ID: Date: Tue, 18 Apr 2023 15:29:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH v3 55/60] arm64: kvm: avoid CONFIG_PGTABLE_LEVELS for runtime levels Content-Language: en-US To: Ard Biesheuvel , linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Anshuman Khandual , Kees Cook References: <20230307140522.2311461-1-ardb@kernel.org> <20230307140522.2311461-56-ardb@kernel.org> From: Ryan Roberts In-Reply-To: <20230307140522.2311461-56-ardb@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On 07/03/2023 14:05, Ard Biesheuvel wrote: > get_user_mapping_size() uses vabits_actual and CONFIG_PGTABLE_LEVELS to > provide the starting point for a table walk. This is fine for LVA, as > the number of translation levels is the same regardless of whether LVA > is enabled. However, with LPA2, this will no longer be the case, so > let's derive the number of levels from the number of VA bits directly. > > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/kvm/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index d64be7b5f6692e8b..4e7c0f9a9c286c09 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -663,7 +663,7 @@ static int get_user_mapping_size(struct kvm *kvm, u64 addr) > .pgd = (kvm_pteref_t)kvm->mm->pgd, > .ia_bits = vabits_actual, > .start_level = (KVM_PGTABLE_MAX_LEVELS - > - CONFIG_PGTABLE_LEVELS), > + ARM64_HW_PGTABLE_LEVELS(pgt.ia_bits)), > .mm_ops = &kvm_user_mm_ops, > }; > kvm_pte_t pte = 0; /* Keep GCC quiet... */ You have the problem here that the KVM library (which isn't LPA2 aware) is walking a kernel page table, which may now be in LPA2 format. I think this works out ok as long as there are no physical addresses above 48 bits in the page table. But otherwise, I doubt it works out very well...