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 84DC33A961E for ; Thu, 5 Mar 2026 14:44:42 +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=1772721882; cv=none; b=kpHna7gAgn7zZz+zuA/VVDyoJiz8mXPF55ikpC/6/V1Wis7W83DDLR2W5pigWy8PsP3pxzaM2ZnR7+cdO/oQ6eTL9E+wgzhI18q0S5AKAsgJ8wfWz6ZmPwB0+0nLmpHgOSqmELlJScT52K7ZERBA6tqfxreHy1Nn2fybni7vu9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772721882; c=relaxed/simple; bh=A98jBFfJ0Zw8odIv9cujR5a6XKhnf74/r1VWTBluNWU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VtVAB5mIyRLZLHkmtl1GJsRfliXPIGs2jSR2hICKRbkQKEcbAPEYoqzHP59K6JGZbNmqDzuCONCCtLaPqklzLykJ3mIC+WjaBSmt0wIfoTadag0g3YPalukJ6C2P3ZWTNkXb+pwW5Z2CKQ129NBoa4bpjTp892LXaB2POToOrRY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UGMcUolr; 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="UGMcUolr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49AE5C116C6; Thu, 5 Mar 2026 14:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772721882; bh=A98jBFfJ0Zw8odIv9cujR5a6XKhnf74/r1VWTBluNWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UGMcUolr9sRhY8akUwGcfiaq0SmE6b+jSfPDHR5YoLTLAPt7Fep3zIl5L7Z6HCvrU XRJhT1L3CS47R2uOm7taehQIKj4KdK45VCtCLMEx9ACImYlaWR4P8WCzZakKKLkGic ddzfFET6ZHHY16voHtNH15A8NJttx7iPEmRVVbuEo4u/U7Nf81uir0CZfKZIOLxWOE xvX11t6BvSQyQ2y6weRNdipt768j+XBSbwqHhl3J2KMXBI59J1/F0dwE/UXYHw0axC s5XFbmtjM7a2eo8/ykfXo22uALsw7EMbPKH1vU3/A0JAXNYU1zSExpirefyFMGM4D1 q0WfGiF3+VSZw== 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 09/36] KVM: arm64: Ignore -EAGAIN when mapping in pages for the pKVM host Date: Thu, 5 Mar 2026 14:43:22 +0000 Message-ID: <20260305144351.17071-10-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 If the host takes a stage-2 translation fault on two CPUs at the same time, one of them will get back -EAGAIN from the page-table mapping code when it runs into the mapping installed by the other. Rather than handle this explicitly in handle_host_mem_abort(), pass the new KVM_PGTABLE_WALK_IGNORE_EAGAIN flag to kvm_pgtable_stage2_map() from __host_stage2_idmap() and return -EEXIST if host_stage2_adjust_range() finds a valid pte. This will avoid having to test for -EAGAIN on the reclaim path in subsequent patches. Signed-off-by: Will Deacon --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 38f66a56a766..7b0f8ad7b20f 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -461,8 +461,15 @@ static bool range_is_memory(u64 start, u64 end) static inline int __host_stage2_idmap(u64 start, u64 end, enum kvm_pgtable_prot prot) { + /* + * We don't make permission changes to the host idmap after + * initialisation, so we can squash -EAGAIN to save callers + * having to treat it like success in the case that they try to + * map something that is already mapped. + */ return kvm_pgtable_stage2_map(&host_mmu.pgt, start, end - start, start, - prot, &host_s2_pool, 0); + prot, &host_s2_pool, + KVM_PGTABLE_WALK_IGNORE_EAGAIN); } /* @@ -504,7 +511,7 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range) return ret; if (kvm_pte_valid(pte)) - return -EAGAIN; + return -EEXIST; if (pte) { WARN_ON(addr_is_memory(addr) && @@ -609,7 +616,6 @@ void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt) { struct kvm_vcpu_fault_info fault; u64 esr, addr; - int ret = 0; esr = read_sysreg_el2(SYS_ESR); if (!__get_fault_info(esr, &fault)) { @@ -628,8 +634,13 @@ void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt) BUG_ON(!(fault.hpfar_el2 & HPFAR_EL2_NS)); addr = FIELD_GET(HPFAR_EL2_FIPA, fault.hpfar_el2) << 12; - ret = host_stage2_idmap(addr); - BUG_ON(ret && ret != -EAGAIN); + switch (host_stage2_idmap(addr)) { + case -EEXIST: + case 0: + break; + default: + BUG(); + } } struct check_walk_data { -- 2.53.0.473.g4a7958ca14-goog