Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298778; b=RWrXPCMj6DzrL9LqbmjpAFjBAwgyguVaEEQKCC7nSxW5s9h4v9d7QhmGrM0V4mtYBHoz KT0c5OVDrxTeCHfOfwFf0b+93GMDwDZxkgC/zfLgv8kn7pyuqad5isznXatUTAjqY8NIz l1LMCduGichBN+aJ75bWW9j4XeJePxeuK7U7PlkEZeBRaPSM2CFxmvr9AzlfIJOUMmex8 O6lkKKtYYg63fXaNO0+C6et5E6AMAyW3BFEIWFjVY06d6OWwfZ/HwfMqUbK0H74CJpsFg L5tZ1j6pnk43yKZcB15seX5zh1w9FZRAEpiJxHYy9qUWdiUoe+gVVh4uRTdH+M0ugiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298778; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=n1ptU30tF8l7KAm7NBTl/Q7UxpCd1QnydwhgqHpcj18=; b=Y6ZDTg9DuxCe1elPbvkkF2ypXDyM/UrFHMGWVL51bZhW234eqlMJ4QNNTpWYGJxk4UjY mc7hDx/IrAV9lRq2Q0TaltXEQyW36bJ3TdLI+19Jc4qwzKI4f+Xx3dCj7y4ik0JLtEJ9d fLcKTXaLP3+heBgKPpLm8Huy2NC82Ypm9ZMQVabtiuA6W84WjT3REZR/fa67QVz1Jwagq 173dIzQufco8Gm/RDLTxx4XBnCZsDSdwZEFj7ZUqh/DjrLoptA2twYvCRlwIFNM9vrgtq fsfWNgkHzG2HknIlmgvZGRW4yrIMhv/1VjJBWSlL2MT1npEavQlefBsZprqsiG5sDGg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Pr69jIqF; arc=none smtp.remote-ip=209.85.128.70 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 671BF606A322 for ; Thu, 3 Dec 2026 11:52:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 671BF606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Pr69jIqF Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4bb68d624baso105583205e9.2 for ; Thu, 03 Dec 2026 03:52:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796298777; x=1796903577; darn=lists.linux.dev; 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=n1ptU30tF8l7KAm7NBTl/Q7UxpCd1QnydwhgqHpcj18=; b=Pr69jIqF9Gz5NIBBFR45ePz9OcRZEWyIQ+bKrKipnWjCbepT3MytknDjzYOImHrCgk tdwblLuoGgBev+uCPeNaZ3Ihq6B1HJBiaY3aj3c6HkBqb1OvSOLjh1cfAlgF+W8KqxEX iq+PQskz681H7aFrwBkbKrQ+INm1IL98863GY6XQYbg8d1vmGxU07oVPLNrpQr5aNeaq wwN6CQqHeQq8mYNSFG9ImBm75yqqheEiEJwzokoQd+J+dBmVK0VNxziw7G93wYmDfRPS MDoyDoqEkcm0yGHGBHdejAbgRkxxS283DU0ea4DxvDSj9ljWOttwAVyoiLsFZFa0jjJH p4lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796298777; x=1796903577; 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=n1ptU30tF8l7KAm7NBTl/Q7UxpCd1QnydwhgqHpcj18=; b=rErcPNE0HWChmxj0+U3zEMDtCkPbHFDQiBapUHi9wfEju/qDS5Bie/+c1Xeil4qnKP fob0m7zYBzjhtafblU9UxV2+iw3gn2RMogomRSqyUbBzlyivhGCWu9isJ7COnlHvpnTB 0FKrUjJIDoCC7aVPWj7cc1HD4YjwCPVDiLgyM6A8uI31YEPq++9zvurGV2EwHt5ogtN/ CE5MIk57JGtvunxOCAHDrypiZUdNQLEJx4ka//7QliN49ILjaMX4muVZzqGtwY2NvDM/ h+ocsk22+9C0eVkuS1fz6Cntx2iVRtHOyHSpCtA/1vXUT/DR7zZiQSuPuCDNC00tFow+ g8kA== X-Forwarded-Encrypted: i=1; AL+hErGd1B8jgQ9/kvu5yOuuoZt/4+NaVF/x1U/jOLJGtoZUMlyuyNUVIbd8tdtPAyZMbh6/P72Wz2Y=@lists.linux.dev X-Gm-Message-State: APuU4Z8M/X5+LFuPYf6moLcT3PZcXxjShl5tNN9c40Sh0QaBGDoPz0Cx MAkNM+ZDu8xJSRiexWq1Ko3/Iwsz9SaCXzUAFHrYo9SeECU1WpHQlI/spziMibFkWKBysg0ns0c sXv0RtveRDts4iixzay8Yew== X-Received: from wmdd17.prod.google.com ([2002:a05:600c:a211:b0:4a1:e925:1a39]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:c173:b0:4a1:813f:2a60 with SMTP id 5b1f17b1804b1-4bb88800134mr839897425e9.11.1796298776825; Thu, 03 Dec 2026 03:52:56 -0800 (PST) Date: Thu, 3 Dec 2026 11:51:58 +0000 In-Reply-To: <20261203115209.1690207-1-vdonnefort@google.com> X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261203115209.1690207-1-vdonnefort@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261203115209.1690207-14-vdonnefort@google.com> Subject: [PATCH v6 13/24] 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" 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.911.g883d8bcb20-goog