Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796054272; b=Cq2lWQTvkOphghsgIkR+LxXFKVbZq6msxkWD61i6dg6trB/0MaywxxnRWTxV+ojKr94F IRPyQI/+M2LpMcV1kbi7GkoUp6XxYD7yp2iTIfEo3Kzcf0LR8nAjCve65Q9u9uk0YEcuu YO1ott1HVuxpiEfN8ZV8xAYqaWTcO34x+iJ8J30JvygX+YrMd6Tp+G5myPl4jHr0GydL7 c9tbDxJjQsXo28HLJ5LB+NdSXf1Ow60pJmfCTXl5r1LloC4OUv1u513YsN+PW1krMJOII 3Q0dzkQs/bQ9qB+xGrUNXAhJIpaMPiK+h5L1rpRtCjTlS+AJ4F/grbCQDSX7AwswvBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054272; 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=FdDpcUHKpSBcVyY5nxK7yOLCAcI475a6Oms9eHhg+ZA=; b=JHmSW6n5UlMms9XQt7AzeAMDiOhUToS9Ds3iEdp00Sy9L8qycBF23HdwETXINwrRj3u+ STwq/mLEppk5nmfxNZQQfJODZUGeSwcohzdbj8xtg3KWA/ek1oPZy4DcSu09tlUif/ji3 oXtW+CfZBn6n/L1BmTaMkTK2/J+59heRiiXSpH6EhZrtTki/u6OD3ROc91WkzbGP1U+sG O9wR88nwO1KQzx9MvG49cTNIOskttT9SKS6jwL6Rjj+DYx4stqtVHFSbMdZ0hfEEbDm8Y UFBWQq2YmALdaJJFAMb5+GMWY7fyzkbAzRvffvM1kKY1z4+tfo8pz/I5yUTFRiqb1NA== 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="S+/Xeo/r"; arc=none smtp.remote-ip=209.85.221.70 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.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 5CE88606A31C for ; Mon, 30 Nov 2026 15:57:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5CE88606A31C 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=S+/Xeo/r Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4aae099f5baso5311965f8f.1 for ; Mon, 30 Nov 2026 07:57:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796054271; x=1796659071; 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=FdDpcUHKpSBcVyY5nxK7yOLCAcI475a6Oms9eHhg+ZA=; b=S+/Xeo/r0P3RjZiUwHe/7Dze3A7eXB64F2fcCghxRGKtA6HM+Vg4aHOMRw0pOznb3x G4Xhos8oSmnuNB7odDdi7pMDzgPajrfVZb9E2oaIIP5mm1sjH72wKU9qGY51plTyKTZ6 /HtF+JUhqwgDatoIQQK0z/6HmTNWuQPyZr3SRP3zw0UzgVi57KsQj+lMUBSmT9V61SqW bYW1HbgJzoOyBcunAdx8wSwWyIE13ciqPhxssaSSV3s159JGo/qxX5DJt2LLd+EBjvXj JwwjCpy10CO9Wg7uzYx1y67YT08YeBQBk2phRWj5u3+MgEgpWYSJfFMEQa+uC0+QNOAC kk1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796054271; x=1796659071; 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=FdDpcUHKpSBcVyY5nxK7yOLCAcI475a6Oms9eHhg+ZA=; b=KX0+tXIAvTpophgKogNlha3SUtZxDbxFnITHJwt1tExOJ/2EcoIeyce5xDwpDmG0Am p2rt4AaVea8ziAtIp1AhlNi6lms5ns1qRzT/dQZS1MNFYxZGhtXePDeq9S1bomn6leAl Kl70A4rTJTZvWpcOyFGJOSO3F/+NrorwD+Vsc25BFgdY29AheYXviFvCpxWTbRV/GDbS fQgHgrk5Zq54W6esp33IM7R1cJlhdMPzYiOdV0f+s16vu4kpjxMCo+2zte4lYXFCX9Db UKKBKis1Zw2cclE09PkayB3spRxocc3FrBLtpJhupkwpguAQ1z+B/azNDBnC67jA62OS peiA== X-Forwarded-Encrypted: i=1; AL+hErE6X+0GgNoqI11ueSbKUryP1rTuVlFeQVXa5s5hKzF3DGXpnM1FMFNlcMlJ0Pk1qmMzkwQ5jnk=@lists.linux.dev X-Gm-Message-State: APuU4Z+zgHuRF1TgBSFNRZJQsEfCXfY87q3eCsJifn5FjM3jwT2Ml8EW jZ4CylNqIT1Zol9XImBdD8e8ewZeKHXZg+khAoqKZYSZFW2ZITZPrQ3FqzLvyftpUZ8k8mfhvYI 3HN9m50A7f0gjaHb2qVEDvA== X-Received: from wrup5.prod.google.com ([2002:a5d:6385:0:b0:49e:f4c:b427]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5f88:0:b0:4a9:b6e8:7c6 with SMTP id ffacd0b85a97d-4abab02c3bfmr62754713f8f.8.1796054270685; Mon, 30 Nov 2026 07:57:50 -0800 (PST) Date: Mon, 30 Nov 2026 15:57:06 +0000 In-Reply-To: <20261130155710.2371874-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: <20261130155710.2371874-1-vdonnefort@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130155710.2371874-23-vdonnefort@google.com> Subject: [PATCH v5 22/25] KVM: arm64: Extend pKVM page ownership selftests to cover guest block split 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" Extend the pKVM page ownership selftests to test the split of a guest stage-2 block and the per-page reclaim of that same block. Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 118f92472299..c2635d8c4131 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -2129,6 +2129,47 @@ int __pkvm_ownership_selftest(u64 pfn, u64 nr_pages, u64 pgtable_pfn, assert_transition_res(-EPERM, __pkvm_host_donate_guest, pfn, gfn, nr_pages, vcpu); assert_transition_res(-EPERM, __pkvm_host_share_guest, pfn, gfn, nr_pages, vcpu, prot); + if (size == PMD_SIZE) { + /* [gfn, gfn + nr_pages) was poisoned. Skip it */ + gfn += nr_pages; + + selftest_state.host = PKVM_NOPAGE; + selftest_state.guest[1] = PKVM_PAGE_OWNED; + assert_transition_res(0, __pkvm_host_donate_guest, pfn, gfn, nr_pages, vcpu); + assert_transition_res(-E2BIG, __pkvm_host_reclaim_guest, gfn, 1, vm); + assert_transition_res(-E2BIG, __pkvm_guest_share_host, vcpu, gfn, 1); + assert_transition_res(0, __pkvm_host_split_guest, gfn, nr_pages, vcpu); + + assert_transition_res(-E2BIG, __pkvm_host_split_guest, gfn, nr_pages, vcpu); + assert_transition_res(-E2BIG, __pkvm_host_reclaim_guest, gfn, nr_pages, vm); + assert_transition_res(-E2BIG, __pkvm_guest_share_host, vcpu, gfn, nr_pages); + + for (int i = 0; i < nr_pages; i++) { + WARN_ON(__pkvm_guest_share_host(vcpu, gfn + i, 1)); + WARN_ON(__pkvm_guest_unshare_host(vcpu, gfn + i, 1)); + } + assert_page_state(); + + for (int i = 0; i < nr_pages; i++) + WARN_ON(__pkvm_host_reclaim_guest(gfn + i, 1, vm)); + + selftest_state.host = PKVM_PAGE_OWNED; + selftest_state.guest[1] = PKVM_NOPAGE; + assert_page_state(); + + selftest_state.host = PKVM_NOPAGE; + selftest_state.guest[1] = PKVM_PAGE_OWNED; + assert_transition_res(0, __pkvm_host_donate_guest, pfn, gfn, nr_pages, vcpu); + assert_transition_res(0, __pkvm_host_split_guest, gfn, nr_pages, vcpu); + + for (int i = 0; i < nr_pages; i++) + WARN_ON(__pkvm_host_force_reclaim_page_guest(phys + i * PAGE_SIZE)); + + selftest_state.host = PKVM_PAGE_OWNED; + selftest_state.guest[1] = PKVM_POISON; + assert_page_state(); + } + selftest_state.host = PKVM_NOPAGE; selftest_state.hyp = PKVM_PAGE_OWNED; assert_transition_res(0, __pkvm_host_donate_hyp, pfn, nr_pages); -- 2.56.1.839.g22a8290db9-goog