From mboxrd@z Thu Jan 1 00:00:00 1970 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 3634C1061B07 for ; Mon, 30 Mar 2026 14:50:23 +0000 (UTC) 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-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+6zb5pMqXsUxzgfMgRUFvHEkkKKRmYwiibXMKLvzHDY=; b=qVROkD/RRNvwdBihb+hNWb0/c1 V++iezOQpg89YHAllEoGwEL0EBzEfUzRiEYZn4SrQSNctqYDLjnAp8zIl5JXETLA/X2BdAIF+wkUc Lfr/WZQP1P/FL0fO3VB2e0XDLSEFXxyMUSXkDCV6jTxoCaCzRE9U1FMu8HE/ARDs7lG4IDRmNx31Y 0bnejQh1kkSa90igs7E+lfwp5SDpX7oYjFPEmgkiQrxP6peENjOrBJGevIwpvvwbPnZzAwMNprt/t ssZI6rG8vpQsIrj1r6lQQgcRtSmhmutlL40zq9HN3Juh8oJTvFxuVE2Qcu5alrCChqPyOGBKkvvsA uhYKa3Gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7DwT-0000000BTmZ-23Rp; Mon, 30 Mar 2026 14:50:13 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7DwE-0000000BTXU-1E3T for linux-arm-kernel@lists.infradead.org; Mon, 30 Mar 2026 14:49:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id A563160127; Mon, 30 Mar 2026 14:49:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E669C4CEF7; Mon, 30 Mar 2026 14:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774882197; bh=7j8yBkqQI9cz054zxle+5jUI341HVt5dkS3HCJOIz8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cT9sizgJPQ7mSotul7kpay4TCwtpMTyPnHuUMuiStrLo4qefSP+6OCi+hrXnlx6iK +n2qYmCRxmEQY7Dk7NUV/xTPUxiF+cYDsPLh3wM++0/snpEeZJ+NKJVMI6AAX+JUhb JxlHOt4rPJl4nvhu6xvHImkIxgwYe3xD1QP7tTdiSythrdElBILgAp1PsWnCV4Z4LW SY4vejQSa1ll4jRx96whcEphreAidj5KN9U8iYwgWrY5dVkjaEBzRss727kX4MP3nJ KQaObQXZoDeaKBrLJ8S/0rgZzdMdw4wfksd78nv5JmScuWH3uMq5Ju5AHuCzHk+STq 7X3+vaWQAr22w== From: Will Deacon To: kvmarm@lists.linux.dev Cc: linux-arm-kernel@lists.infradead.org, Will Deacon , Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Quentin Perret , Fuad Tabba , Vincent Donnefort , Mostafa Saleh , Alexandru Elisei Subject: [PATCH v5 20/38] KVM: arm64: Avoid pointless annotation when mapping host-owned pages Date: Mon, 30 Mar 2026 15:48:21 +0100 Message-ID: <20260330144841.26181-21-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260330144841.26181-1-will@kernel.org> References: <20260330144841.26181-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 When a page is transitioned to host ownership, we can eagerly map it into the host stage-2 page-table rather than going via the convoluted step of a faulting annotation to trigger the mapping. Call host_stage2_idmap_locked() directly when transitioning a page to be owned by the host. Tested-by: Fuad Tabba Tested-by: Mostafa Saleh Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 0e57dc1881e0..bf5102594fc8 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -551,23 +551,27 @@ static void __host_update_page_state(phys_addr_t addr, u64 size, enum pkvm_page_ int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id) { - int ret; + int ret = -EINVAL; if (!range_is_memory(addr, addr + size)) return -EPERM; - ret = host_stage2_try(kvm_pgtable_stage2_set_owner, &host_mmu.pgt, - addr, size, &host_s2_pool, owner_id); - if (ret) - return ret; + switch (owner_id) { + case PKVM_ID_HOST: + ret = host_stage2_idmap_locked(addr, size, PKVM_HOST_MEM_PROT); + if (!ret) + __host_update_page_state(addr, size, PKVM_PAGE_OWNED); + break; + case PKVM_ID_GUEST: + case PKVM_ID_HYP: + ret = host_stage2_try(kvm_pgtable_stage2_set_owner, &host_mmu.pgt, + addr, size, &host_s2_pool, owner_id); + if (!ret) + __host_update_page_state(addr, size, PKVM_NOPAGE); + break; + } - /* Don't forget to update the vmemmap tracking for the host */ - if (owner_id == PKVM_ID_HOST) - __host_update_page_state(addr, size, PKVM_PAGE_OWNED); - else - __host_update_page_state(addr, size, PKVM_NOPAGE); - - return 0; + return ret; } static bool host_stage2_force_pte_cb(u64 addr, u64 end, enum kvm_pgtable_prot prot) -- 2.53.0.1018.g2bb0e51243-goog