From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F121E606A320 for ; Mon, 30 Nov 2026 16:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hySoeSsy; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=p8SV45OC DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=NZXHktSiU13CFX2zr2tTX819KepmV1s0VYKm93Ltb/0=; b=hySoeSsy+Q0xeXwtzTttxfUPjt UJB5uvfXG9wMjPcK2aRn/39ZrAkxgqmwFQmjeVm9i8DhJobLpiEDW5SnD30kcCGRch3kXF7LNOjry aeRhUS0kgSMCXYCNdQ8Lk+CTeQspSO9xtnApxkcL3bnYeeeZ5xlDsbiX1LsNZEdPEjOFo+LbHzByK XbgJFaRXcS9n54gzRP12RIX86tXVejldVUAupy6Yku+IHuY5tk9WQ9YyjI1afy00BjzeVPqNxXuLV uuzHaYcJ5l/j4I01EIjfeKMSvzL9kraP3CjsjH7XCo4NRmJfWVvUiE77D8SM7YSWXE9+FmdvQOkFD bXoHtOnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3rh-00000005AuZ-4Bdh; Mon, 30 Nov 2026 16:04:30 +0000 Received: from mail-wm1-x345.google.com ([2a00:1450:4864:20::345]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3lF-000000057nh-17dW for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 15:57:53 +0000 Received: by mail-wm1-x345.google.com with SMTP id 5b1f17b1804b1-4a4654add56so73961005e9.2 for ; Mon, 30 Nov 2026 07:57:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796054261; x=1796659061; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NZXHktSiU13CFX2zr2tTX819KepmV1s0VYKm93Ltb/0=; b=p8SV45OCCA0KNWbw2+b5gaRhGKz0cOt6qUiC3/Vio2FB/4aDeMgkf9Xqg0EnzDt0ky ERrqmA1Sc4+fDpowopPpdNZ20MOaaG2736U8B8wbg6rCkZp6Px17G32JFPEoVicw9dqV 7yPfVKYdB3waLcuhvSo/jXy3l+md4tSR/9n28eJZVxR6TVcV2rZOkfYo9zNpgJGnerei WxR/I24moeIh6xV0W+3J0yFtcSLLpVmd7qKcASSxyEOyZp4W1zUZd/fjM1Iqukv6jGR0 8ymPokimA/h8rJRlZ7hIxScnhsX807qIClsNpwABkH7H6T6NT+XCIE79FhHy3+KeOZlA oUig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796054261; x=1796659061; h=content-type: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:content-type; bh=NZXHktSiU13CFX2zr2tTX819KepmV1s0VYKm93Ltb/0=; b=brgjnIzWfqq7LDrFGj2aoomXhSIcB736djTRJkm3bf6CvXrJsclRgs3qcz+z4NpfDK v8HWX0EaJglOxukOqMg4a12W5l/ya/VeWmndoNo7qpHOJozuW5FxKseQE8ENQwv9nUX4 khO0AGFTh0sbRp9bCvZEBqz8mjcFDjhqaFJblfCTZAMsiv6V4e4N/QC+xcZzRbMLXjRX BVPE+Ji/GOgtFvVrHbuFXyp9FCJRexrO1bvOmKR2zpa8d1QyrggXNw6QSLYxtg8KkBoo vFmC25xnCaRqvTG9U1+fvV9rJ8JTuGKHQzQ/C/bNaksDLrUvpRAYSiA1VG228l6hesNS s1yQ== X-Forwarded-Encrypted: i=1; AL+hErHqDpNmb9sWs0FRSG8XKElYc/MQnypQitycW4agj5kKNvC1iwY5YSBM92sJLMlk/MFkhhHp2L1ka1leQDYtAiE4@lists.infradead.org X-Gm-Message-State: APuU4Z8TvBm4fCiRv1iumgYdgzGTonLJTWjMC4cHkDMm2f6mtnwyOLMK 6VKYEh+4gXYr++50zuF6Y9U1eX5zkO8So14skCMOVIdj7XyYvfTvHgBcRQk1ayob9c2zkyyxuTu SvKnhGYTFo9uLPKEsuR5OoQ== X-Received: from wmro9.prod.google.com ([2002:a05:600c:3789:b0:4a1:ae53:2fe9]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1d86:b0:4a1:fa27:df7c with SMTP id 5b1f17b1804b1-4bb88922972mr713526115e9.34.1796054260721; Mon, 30 Nov 2026 07:57:40 -0800 (PST) Date: Mon, 30 Nov 2026 15:56:57 +0000 In-Reply-To: <20261130155710.2371874-1-vdonnefort@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261130155710.2371874-1-vdonnefort@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130155710.2371874-14-vdonnefort@google.com> Subject: [PATCH v5 13/25] KVM: arm64: Handle huge mappings in __pkvm_host_force_reclaim_page_guest() From: Vincent Donnefort To: maz@kernel.org, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, kernel-team@android.com, fuad.tabba@linux.dev, qperret@google.com, weilin.chang@arm.com, Vincent Donnefort Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_075749_733810_38F7E9EE X-CRM114-Status: GOOD ( 15.83 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 In preparation for supporting stage-2 huge mappings for protected VMs, allow __pkvm_host_force_reclaim_page_guest() to work with PMD_SIZE mappings. As this HVC is called from a non-preemptible context, it is not possible to rely on the host pkvm_mappings tree to get the mapping size. Instead, use the actual host stage-2 mapping size and compare it with the guest stage-2. Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 33 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index d9b67b4ca581..da5aa3bbca72 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -1340,7 +1340,7 @@ static void hyp_poison_range(phys_addr_t phys, u64 size) __apply_guest_page(__hyp_va(phys), size, __hyp_poison_page); } -static int host_stage2_get_guest_info(phys_addr_t phys, struct pkvm_hyp_vm **vm, +static int host_stage2_get_guest_info(phys_addr_t phys, u64 *size, struct pkvm_hyp_vm **vm, u64 *gfn) { enum pkvm_page_state state; @@ -1368,34 +1368,43 @@ static int host_stage2_get_guest_info(phys_addr_t phys, struct pkvm_hyp_vm **vm, if (ret) return ret; - if (WARN_ON(level != KVM_PGTABLE_LAST_LEVEL)) - return -EINVAL; + /* We only support either PAGE_SIZE or PMD_SIZE */ + if (level < KVM_PGTABLE_LAST_LEVEL - 1) + return -E2BIG; - return host_stage2_decode_gfn_meta(pte, vm, gfn); + ret = host_stage2_decode_gfn_meta(pte, vm, gfn); + if (ret) + return ret; + + *size = kvm_granule_size(level); + + return 0; } int __pkvm_host_force_reclaim_page_guest(phys_addr_t phys) { + u64 gfn, ipa, pa, size; struct pkvm_hyp_vm *vm; - u64 gfn, ipa, pa; kvm_pte_t pte; int ret; - phys &= PAGE_MASK; - hyp_spin_lock(&vm_table_lock); host_lock_component(); - ret = host_stage2_get_guest_info(phys, &vm, &gfn); + ret = host_stage2_get_guest_info(phys, &size, &vm, &gfn); if (ret) goto unlock_host; ipa = hyp_pfn_to_phys(gfn); + guest_lock_component(vm); - ret = get_valid_guest_pte(vm, ipa, PAGE_SIZE, &pte, &pa); + ret = get_valid_guest_pte(vm, ipa, size, &pte, &pa); if (ret) goto unlock_guest; + phys = ALIGN_DOWN(phys, size); + pa = ALIGN_DOWN(pa, size); + WARN_ON(pa != phys); if (guest_get_page_state(pte, ipa) != PKVM_PAGE_OWNED) { ret = -EPERM; @@ -1403,14 +1412,14 @@ int __pkvm_host_force_reclaim_page_guest(phys_addr_t phys) } /* We really shouldn't be allocating, so don't pass a memcache */ - ret = kvm_pgtable_stage2_annotate(&vm->pgt, ipa, PAGE_SIZE, NULL, + ret = kvm_pgtable_stage2_annotate(&vm->pgt, ipa, size, NULL, KVM_GUEST_INVALID_PTE_TYPE_POISONED, 0); if (ret) goto unlock_guest; - hyp_poison_range(phys, PAGE_SIZE); - WARN_ON(host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HOST)); + hyp_poison_range(phys, size); + WARN_ON(host_stage2_set_owner_locked(phys, size, PKVM_ID_HOST)); unlock_guest: guest_unlock_component(vm); unlock_host: -- 2.56.1.839.g22a8290db9-goog