From patchwork Wed Feb 14 12:29:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13556555 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 0CC91C48BEE for ; Wed, 14 Feb 2024 13:46:10 +0000 (UTC) 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:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=MojlkTuoESdXjtRMi0uIikY9+21pnFVI5Yo7TuFCtOI=; b=DZUjv5YbTX2KXNHmlj3JhYzoz3 Fx+Ez2yIu62N8oOAVwxSpvwo+PItXNRKRf457FhGQMRJhesyq2rSfyYCihDcsfJ6unDSJ6Pc4L5VY gcPLVAz9HPDIgGGJQDbJw5LhjXMlcflCmnH+P9pW8l/F5GI1EIYFnzlkmozJyiyzf6bPqKR/LAF9Y 8eWbAuZauCDC03aSCNbvXNsUj00vBIZM7o3vBBZZgMDcHSRF/ytl0Q4vXQXI7TzEytP6W1x+XWgUh vmGjSPG5t09RlqSxHU3LbwG7hH1P0x1k1x2ut1uiDBxNlINPkh4yV3EItWVw0D36ftk/oFjGyYCVH hvo4kkEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raFaG-0000000D3nv-1joL; Wed, 14 Feb 2024 13:45:56 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEPu-0000000Cp6u-0Y33 for linux-arm-kernel@lists.infradead.org; Wed, 14 Feb 2024 12:31:24 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6047a047f4cso138170147b3.3 for ; Wed, 14 Feb 2024 04:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707913868; x=1708518668; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zEHrKJHHdGBSEF5kWmEoE5hindUcwiKdKN6yKAgIVcg=; b=eINUh+L5UZ8EN3Q0iEHydQ7SchikV8LrwY0FOKnEZ2F9GzbJOAkzxtGwfVNPKDxzF6 GfCXTmQjiTh9ePsugBBExH9rxKxipZXB/MAOYaDB94/BKpSMiAyOtBY1v539q4yRNsFY 3VHsCAausE77hr0AnKAS9Nz07t93Pcxj7B+ZKnIu4HIr9whjH7PYozAgqOHPmG8Tr2tV BK0JXOL1ayP4jfGYWLs3HQgjYe4+GuW8xS1onilslvrqP8p2qwxLSu/iYPUmSakyPvPC HTTZ2jWbKvrWIcHiFngQP2kEkWg4Bf+7OC+YWB3fh4b4EI/QYvaLNf5Ov2D50HGjWXZL IhNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707913868; x=1708518668; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zEHrKJHHdGBSEF5kWmEoE5hindUcwiKdKN6yKAgIVcg=; b=Q/xygZs5hsQidDT+1exCv/P4aUGKJJ3yI+1dXQPu605lDYaAYiFc06tMBITTr+sIKF 1xPx5WDXxDqe6twQ0V8yawYO3F22+iCZvv6BWD8B2+7PJUufySAQrc29qJHmeRR11pxj rq8nEMGGLcvqxx80cRPWBYbl4pp36W22r8jYTHqZbLrp4+yQVS4j+h9sOo60Lm+uIhLu Qgc3QANT/YSzmk0ZKDMik/tW7a+zw+t6OyNxkEvxAyne91waNzFVWtKOnFtupzgdv1G7 lN/bG6J6+RFos9h/0b/XU2ObR2a6oKcJFW4zNBYqh6XuZ5ozjZmCPCwM/kDybyKZu0g1 hDyw== X-Gm-Message-State: AOJu0YyAZ8ml7Kn1JAyfmn8GWArZnLTz7eOpBLSRCXe2q7tapPXdgNjS qz+7Wv+86F+VWnRtHP+PUDwstN1jYFxd+Ub+24ESf8SooLTdJ/t5WSS+DyabIhumNV0llyIdn6t 3h/lT3qKONKlYNdiO85cxKS0iM73Mu9bZqWzSzH0LmaJ+Fv0yS+jj8t6uFDgTIZHaV84qEYGUsW vJYc4GDob9vT6wtuVq7WOHJ4UyFffJ00mGXcad40Eh X-Google-Smtp-Source: AGHT+IHn9H1f2wkIrn2GAVpRVZK/42A8A9Khe1TF7loeMrPf0NK1J/MzkS156JrjX4H66X38UTJdvYL+ X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:72c:b0:dc7:53a0:83ad with SMTP id l12-20020a056902072c00b00dc753a083admr554670ybt.5.1707913868587; Wed, 14 Feb 2024 04:31:08 -0800 (PST) Date: Wed, 14 Feb 2024 13:29:25 +0100 In-Reply-To: <20240214122845.2033971-45-ardb+git@google.com> Mime-Version: 1.0 References: <20240214122845.2033971-45-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1120; i=ardb@kernel.org; h=from:subject; bh=M9K6TCvADFrSQrq3imVxSRn39wrusa5LSxXwXi7bCXI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXMJo1DDcs80gXO5Mjav5iievB8GhffF72k9jXck0zeu Ehueq/fUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACYSdpbhn82jsFsyO5S2vppc zT45dx/3LAZn9ptzvRx9Vfjjo3T43Rj+ezgc2v6oq81ooeleQaaTy8yW/u8/3xsWU3Hzcr/fZsY SfgA= X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240214122845.2033971-84-ardb+git@google.com> Subject: [PATCH v8 39/43] arm64: kvm: avoid CONFIG_PGTABLE_LEVELS for runtime levels From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240214_043110_441802_8B9A597D X-CRM114-Status: GOOD ( 12.81 ) 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 From: Ard Biesheuvel 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. Acked-by: Marc Zyngier Acked-by: Oliver Upton 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 6fa9e816df40..cd9456a03e38 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -805,7 +805,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_LAST_LEVEL - - CONFIG_PGTABLE_LEVELS + 1), + ARM64_HW_PGTABLE_LEVELS(pgt.ia_bits) + 1), .mm_ops = &kvm_user_mm_ops, }; unsigned long flags;