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 2E69B10ED679 for ; Fri, 27 Mar 2026 14:01:50 +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=4dwi5pCAg/MZTNDHoKdZDmYR5Cl5fK1dAgs4M7cLrNQ=; b=GJJGWc6jt1xUuBFhNKHDuCo+nD C8siHqJ0Umt6B6jYT1ieVhioMNTqt7MoxaFPFRNl30ADeIzfue0WrjxCXuDlsldq7AhVFEeNDZPQL bluOS+/O8V0ySP1YPYBIMO0sv7QqDpyD8i+IPcricFAvVy3RnH1a9LbU5yKeJJE/TEFY1auXvXHs/ s0AKlvddlERax8a+KC2IsRJSIuJPp7MZleIk0XYa75KsEwVmAf0GsowjDDcNUvLonr0jq5+/Lkzco K3dbE1OqaKvQ15A3j27irpxt7HmkAdbbIQYOeYBODICz8s37S7438ya3Vo6LVq7bPFOWCq+vSRu8g 8NPHPAHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w67kq-00000007VtO-2qlB; Fri, 27 Mar 2026 14:01:40 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w67ka-00000007Vh4-1tPk for linux-arm-kernel@lists.infradead.org; Fri, 27 Mar 2026 14:01:25 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 2A69D42A21; Fri, 27 Mar 2026 14:01:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54259C2BC87; Fri, 27 Mar 2026 14:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774620084; bh=kupY+rUTW2UPV/U5cwqqP9hhXbxo6oWLqyy18kOdLqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j3CyJB6XuH1QxZ3XVr7pF5zKDjbprLRpmHGlayNlpMp7fpXR4gUwKbjpQMJOZviJY /fkX6whX1aUKfgz7B9+1vm0GwrmUJ0ZvhY+HY4UXYck729EV8HconQGOth14Tp3Hot Ge6YCwasgM0uJ7p+OvNcmQh5NTbUSTvObFUMa3Wwqh2LVHzyE/C7vvhQ2+wOez7DZp J03BWY5JfcMPbeHcOgyMKCVvmhnV9awi42y1NtNnidmp8LeirQAAHYp/2LtXUbJVLw rBtCEIzd+ZuYIaTwNUeGVwb7WsN1DDvaHm14yE3lRQWlckS7DdcZibNdIv2HGcWkEc ytaXD5tZZUUPA== 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 v4 10/38] KVM: arm64: Ignore -EAGAIN when mapping in pages for the pKVM host Date: Fri, 27 Mar 2026 14:00:09 +0000 Message-ID: <20260327140039.21228-11-will@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260327140039.21228-1-will@kernel.org> References: <20260327140039.21228-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260327_070124_532299_24F53497 X-CRM114-Status: GOOD ( 15.43 ) 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 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. Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Tested-by: Mostafa Saleh 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 d815265bd374..7d22893ab1dc 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.1018.g2bb0e51243-goog