From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CB181A8F84 for ; Thu, 5 Mar 2026 14:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772721924; cv=none; b=L3ivENXCYJhZopCTU/hn3qtDtgQJWhhSqdSjJ3ZM0LJ9DbMRAP2mOjo5fAh5E4M/uf4zHO/AswMhBLHJqa819cKnwzfrqGQSFCoU9aQHdfMrIhjUhzmbvnno1gbqintoVs9zLmrvVv+AlxkjHe5Scins6C12CTc6vGIVy92ZDtA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772721924; c=relaxed/simple; bh=5tzTDA/7up9FIAkii32jSMaz9AezpyfrV8bQYy76e9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f7wcezcTiQWNjBAP45PiGpug2jpB+cHn3iHWARoHHPUCha8XguSu4cn0fdEg0l/7e2w4BFLA6zRi99BCKvY4AkDOpZUrGUFGei9vS35h8vo8KwPQnAHK2e3bfrt+kJx9EEbeXrzg2D9aCUsVdGsoJBJAcR9TJW1o64UtzJ4ksKA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AQNUEXtC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AQNUEXtC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBEA1C116C6; Thu, 5 Mar 2026 14:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772721923; bh=5tzTDA/7up9FIAkii32jSMaz9AezpyfrV8bQYy76e9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AQNUEXtCdZiSexapGSw48oKE4vGuoH70v7ReBRq90gAao0OdDJ/+8LsQmfo49pAk0 7hJ7AusrTiC3nLuK+qKs+hGdDvgm7iB/T67Fy3QrJD/OZ8x396UP6qukjxzZCMxFdd bTnAbO2bf/7fXZNAweakQCheN9ldrwcvCOb1PImwfDmI1FfRdiyY8wveybAt383Vyk XpMUtMWvafJVl9D+Ys8r9dL7kqy8SpSVeuaT92hljsbFsspzuPTfzV3oCd7vpOPIBo ++i+c3QjQd9Bx4hszQYN1VUvG2yUcyj/HNNzc+H4iOOUY8o8hIIqiPLz+N0VzZUUk7 aY41z5fqSRGfw== 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 v3 21/36] KVM: arm64: Introduce host_stage2_set_owner_metadata_locked() Date: Thu, 5 Mar 2026 14:43:34 +0000 Message-ID: <20260305144351.17071-22-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260305144351.17071-1-will@kernel.org> References: <20260305144351.17071-1-will@kernel.org> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Rework host_stage2_set_owner_locked() to add a new helper function, host_stage2_set_owner_metadata_locked(), which will allow us to store additional metadata alongside a 3-bit owner ID for invalid host stage-2 entries. Signed-off-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 2 -- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 47 ++++++++++++++++++--------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index e36c2908bdb2..2df22640833c 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -99,8 +99,6 @@ typedef u64 kvm_pte_t; KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ KVM_PTE_LEAF_ATTR_HI_S2_XN) -#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) - /* pKVM invalid pte encodings */ #define KVM_INVALID_PTE_TYPE_MASK GENMASK(63, 60) #define KVM_INVALID_PTE_ANNOT_MASK ~(KVM_PTE_VALID | \ diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index b4c2ca86e5b3..ed540ccd1595 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -549,37 +549,54 @@ static void __host_update_page_state(phys_addr_t addr, u64 size, enum pkvm_page_ set_host_state(page, state); } -static kvm_pte_t kvm_init_invalid_leaf_owner(u8 owner_id) -{ - return FIELD_PREP(KVM_INVALID_PTE_OWNER_MASK, owner_id); -} - -int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id) +#define KVM_HOST_DONATION_PTE_OWNER_MASK GENMASK(3, 1) +#define KVM_HOST_DONATION_PTE_EXTRA_MASK GENMASK(59, 4) +static int host_stage2_set_owner_metadata_locked(phys_addr_t addr, u64 size, + u8 owner_id, u64 meta) { kvm_pte_t annotation; - int ret = -EINVAL; + int ret; - if (!FIELD_FIT(KVM_INVALID_PTE_OWNER_MASK, owner_id)) + if (owner_id == PKVM_ID_HOST) return -EINVAL; if (!range_is_memory(addr, addr + size)) return -EPERM; + if (!FIELD_FIT(KVM_HOST_DONATION_PTE_OWNER_MASK, owner_id)) + return -EINVAL; + + if (!FIELD_FIT(KVM_HOST_DONATION_PTE_EXTRA_MASK, meta)) + return -EINVAL; + + annotation = FIELD_PREP(KVM_HOST_DONATION_PTE_OWNER_MASK, owner_id) | + FIELD_PREP(KVM_HOST_DONATION_PTE_EXTRA_MASK, meta); + ret = host_stage2_try(kvm_pgtable_stage2_annotate, &host_mmu.pgt, + addr, size, &host_s2_pool, + KVM_HOST_INVALID_PTE_TYPE_DONATION, annotation); + if (!ret) + __host_update_page_state(addr, size, PKVM_NOPAGE); + + return ret; +} + +int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id) +{ + int ret = -EINVAL; + switch (owner_id) { case PKVM_ID_HOST: + if (!range_is_memory(addr, addr + size)) + return -EPERM; + 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: - annotation = kvm_init_invalid_leaf_owner(owner_id); - ret = host_stage2_try(kvm_pgtable_stage2_annotate, &host_mmu.pgt, - addr, size, &host_s2_pool, - KVM_HOST_INVALID_PTE_TYPE_DONATION, - annotation); - if (!ret) - __host_update_page_state(addr, size, PKVM_NOPAGE); + ret = host_stage2_set_owner_metadata_locked(addr, size, + owner_id, 0); break; } -- 2.53.0.473.g4a7958ca14-goog