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 D029E606A32A 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=1x/IbJm6; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=otg0TTkb 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=U3iz2LmWKdSdfaXFckNT1fHf3GJiNENh4fp9qxxA9Tg=; b=1x/IbJm6PGgdruYlZa2sr2gorV 7ddM7CxlpPvLUJgnROoTmMp1hsZfrAK52rdxnyNbeUZ1Sju2LnqdlbfScx1o2RS9h3iuRaOwJC6LS FCQCMF8koKhNyk4mTJ5mnqCtN3WS4YcOnurc6SkX0VbWIbd/6aZF3i3708TfqDGodzjMphEXsLbRo alKyEbjCTD42OZGPSmlHzDg+kgoXy+EUBcoS1n4T5qtenyLp98564lvsYNa72U84+syvd+FUNAsHn mn9iyM/7igcZNALIK0ZaHa4PkSaDUla0WMv3YxgMwk9jCF0F0c6jLpoV9vRNcOXEXHfIIOpKrau8q YJIP3HVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3re-00000005AnA-2c0K; Mon, 30 Nov 2026 16:04:26 +0000 Received: from mail-wr1-x446.google.com ([2a00:1450:4864:20::446]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY3l5-000000057an-1vps for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 15:57:49 +0000 Received: by mail-wr1-x446.google.com with SMTP id ffacd0b85a97d-4a799d93bc3so5055841f8f.1 for ; Mon, 30 Nov 2026 07:57:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796054257; x=1796659057; 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=U3iz2LmWKdSdfaXFckNT1fHf3GJiNENh4fp9qxxA9Tg=; b=otg0TTkbkvcO8AO5ocgznDBJ/M8an6rwNNx5uJlwAJs/Kk3WlIElextM2RiAYpBfbY bCqahP+7wQmZ5CDYEOsgSxQvaZf88mcIErWINcrzMIlbOCo00BRxhCq2JbYaTmMDIfuy FNW7Vn+EdhwMmKtCs7XS4+jHkYCdcaZ8eaJ69yF6Qsgj9+gnGH0S8bpvpNuVmHOYzIp8 vh7EQwVkTYiinNZ2tru57dUDlAZUCoMMh3BhPsBhOM06Gq4nqlIyOpm3z/fo0789q3Ym fJxRwevEmP31YGoTdkPMDBySeDWfhimzBelQ1mzHtqRQrhpgjcFP7QXsqI3VML7qayys sCzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796054257; x=1796659057; 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=U3iz2LmWKdSdfaXFckNT1fHf3GJiNENh4fp9qxxA9Tg=; b=urk5bc3Al/Zo0u2EBpxe2CnpE5KP2xSr5tdD8qon6024txdCGYtBoFqSfwLZJxJEqF bhvhI+gsbSD3AUfueRD9k5mPFRxIJTdylraRqp92CH+MPqn4Sm7My2o+G2UlrkcqIrlq zK7wXv9QbFY0H+G8XiqrFMRCR2/dRkYpDowyEY+jKX6+2qJuIl25yjQ90hQGZ0Orx+tU F7DYB3yMNf5dWXZgeW6441ZctFG+5bw5SazK8rx5nMvdQpQFpiLHqjZ89Dcu7P91B7Ty d6Fi8ImDkzbHU3rVVaryLufb9FFrK5S0LVcYPb+v+8eR2wJxyVdnbwxsMJ3vbT/gNmOd QSiQ== X-Forwarded-Encrypted: i=1; AL+hErF/edYocXvaqQQZBFXmycE/920V4obSRfBwFavGg7vmPDdxLSihtfB3/wrNQB6OhdRkBhD9N7BxOfBN1Ce56GMt@lists.infradead.org X-Gm-Message-State: APuU4Z80iIuauxcpNjTmU/wzIrTyayL/N7o/eZSo8wogGuSxMRnr7gdd dZLcP2wea6+vUbtZd2ib+Zu83bd5YN6Fm9P1KgYcGCRQkIZZW2fsowPzeeB2vm391dNvOnoBR+c jB+zsvu0PeVIXoqvdtaMt7g== X-Received: from wrme18.prod.google.com ([2002:adf:e392:0:b0:4a5:83f6:49f1]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:400b:b0:4a8:dbbd:69ab with SMTP id ffacd0b85a97d-4abb4f58c75mr65368832f8f.27.1796054256383; Mon, 30 Nov 2026 07:57:36 -0800 (PST) Date: Mon, 30 Nov 2026 15:56:53 +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-10-vdonnefort@google.com> Subject: [PATCH v5 09/25] KVM: arm64: Add a range to hyp_poison_page() 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_075739_607314_CC3A3F02 X-CRM114-Status: GOOD ( 14.86 ) 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, add a nr_pages argument to the memory poisoning mechanism. Use the existing __apply_guest_page() helper which speeds up the process by using a PMD_SIZE fixmap when possible. Also, rename the function to hyp_poison_range() to reflect the new capability. Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index f14bcc1b0de9..555566bbb9c2 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -1299,11 +1299,9 @@ static int __guest_check_transition_size(u64 phys, u64 ipa, u64 nr_pages, u64 *s return 0; } -static void hyp_poison_page(phys_addr_t phys) +static void __hyp_poison_page(void *addr, size_t size) { - void *addr = hyp_fixmap_map(phys); - - memset(addr, 0, PAGE_SIZE); + memset(addr, 0, size); /* * Prefer kvm_flush_dcache_to_poc() over __clean_dcache_guest_page() * here as the latter may elide the CMO under the assumption that FWB @@ -1311,8 +1309,12 @@ static void hyp_poison_page(phys_addr_t phys) * host stage-2 and would otherwise lead to a malicious host potentially * being able to read the contents of newly reclaimed guest pages. */ - kvm_flush_dcache_to_poc(addr, PAGE_SIZE); - hyp_fixmap_unmap(); + kvm_flush_dcache_to_poc(addr, size); +} + +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, @@ -1384,7 +1386,7 @@ int __pkvm_host_force_reclaim_page_guest(phys_addr_t phys) if (ret) goto unlock_guest; - hyp_poison_page(phys); + hyp_poison_range(phys, PAGE_SIZE); WARN_ON(host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HOST)); unlock_guest: guest_unlock_component(vm); @@ -1412,7 +1414,7 @@ int __pkvm_host_reclaim_page_guest(u64 gfn, struct pkvm_hyp_vm *vm) switch (guest_get_page_state(pte, ipa)) { case PKVM_PAGE_OWNED: WARN_ON(__host_check_page_state_range(phys, PAGE_SIZE, PKVM_NOPAGE)); - hyp_poison_page(phys); + hyp_poison_range(phys, PAGE_SIZE); break; case PKVM_PAGE_SHARED_OWNED: WARN_ON(__host_check_page_state_range(phys, PAGE_SIZE, PKVM_PAGE_SHARED_BORROWED)); -- 2.56.1.839.g22a8290db9-goog