From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2790D2BEC4E for ; Thu, 21 Aug 2025 21:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810051; cv=none; b=RKjFTvsqaNcjYr5g9hgvD7dhnMVq29cdkt1Lqr6Q7vpPcxgluUIbOBeuKsUK7DYnvxGZQE4wQhu1TYkWspve7nLsVhA6o5V7smdymho6LtIUn5cawZiW5K9Guo0pEWwPPqxCZl2eGDuqKBqSy3tL7Vr1dcqho2WUPKCqHVYv9O4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810051; c=relaxed/simple; bh=XIPH6D7OK9e9Nk/anEV/qb0UKnQEM3J9OnJTOv3j/hE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cLcEzM5wR4A7ILwhB8RtvSTuP4efsORnoWdMGmGmdhP67AEepzaAqNGX/OaLM+bnhXrvB1X9JHuedYDLU+oXsRDLx+jfD+i9udPwE5G74M/MQTHYiySroIIs/JjAan2CnwzWTJV7GKdgmPbm/X6W1n4DIbIfNxTkOsylXI6xuUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1Bq1+19S; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1Bq1+19S" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b471757d82fso1136197a12.3 for ; Thu, 21 Aug 2025 14:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810047; x=1756414847; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=etQsx3Bjkyo2W+FnvyouolCpcLbOwVVqYYIcKcKxQxw=; b=1Bq1+19S7B0g7Z8tXChURM2aaVaMo7V7FhDA80qNCeTXIsXVfFxjSfij3UUv6Nopft 15t79HeHGtWA58KEbSYT9/xBvhMQdbWNdYYipX41UiMBWocl40n1vEd9BoPOi1RIyzvf rC6mzoC8v2H41eejVDHUr6gztiZHK96qBqvnGuk57YnN3ICyxtNTsOrzVc2EBQvx1MRA tUxxL95D15aMDvT0TmkkPKXeKRdk9EtQVuOxlMnrhtuQnkBvbj8sIvipH23CfR03Ge2C 3quEw9r+Qg2zzwDCF3abGfYV/28wycdmZ0yu51mh0yMqycqBb/zK9RtDBjn0xZyIGMMU TEAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810047; x=1756414847; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=etQsx3Bjkyo2W+FnvyouolCpcLbOwVVqYYIcKcKxQxw=; b=daCcYtufD/iATvYvPHYGO4uoVeK+2hYDkthajvmmSxGCAxlxJh6481w2qLZBTjVwjl NYi1J3jfmtnVCbyCLpYZx3vqC4BS0gtihp0aAM6x5Ec40zJPLT0SuUH1cqfdAM4tl4KT yFrnhakMpUW1JNzDIhvXShgv6AmxbT1BP+q5NTQscRKGpcjsHi7ET+r1+YWrPtE45t/5 QmteLu0UqH63Hm46yUInrccujyjHc9mb3RRQLuvNTspeIe+GDyTQZsjHEBcTjra1f7Ky JKKsqVRXBoND53mISNwEq/oLAy5etbDS5+VnL1MIs2kemZXStkzxzd1wqOeOtQ11T1oe HreQ== X-Forwarded-Encrypted: i=1; AJvYcCXDNuaF7nTHTUc8EsTpzufdG31dGXB71MTYPo9HvHc8uMeF/YYRv9hlZpvwEv1PWuZX8owOLObaOV/c7Mw=@vger.kernel.org X-Gm-Message-State: AOJu0YxkDhbQg/vpwJVPKyYNUbXKgaotgWs3RgpPP3BLeYypyQ1C5OKf EeIUAD7XikMCCBJyT+Q2sWc4DshE6J9O8SMbQv0850AX7iH/om8ZkDDZagwaSqszZgSXeEY7cQY X+yJLFg== X-Google-Smtp-Source: AGHT+IG+AbHEFENih72v8s75m7PziM02RS9Hkp0sUk/+ACGLaOQo6n0X4YmQa5UYgK3E6VY5WcrGDki7bAU= X-Received: from pfqn26.prod.google.com ([2002:aa7:985a:0:b0:76b:b0c5:347c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2446:b0:243:755:58b8 with SMTP id adf61e73a8af0-24340d9268cmr736072637.57.1755810047367; Thu, 21 Aug 2025 14:00:47 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:27 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-2-seanjc@google.com> Subject: [RFC PATCH 01/16] KVM: arm64: Drop nested "esr" to eliminate variable shadowing From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop a local "esr" variable in kvm_handle_guest_abort() that's used as a very temporary scratch variable when injecting nested stage-2 faults, to avoid creating a shadow of the function's overall "esr", which holds the original state provided by hardware. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 1c78864767c5..dc3aa58e2ea5 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1904,19 +1904,15 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) */ if (kvm_is_nested_s2_mmu(vcpu->kvm,vcpu->arch.hw_mmu) && vcpu->arch.hw_mmu->nested_stage2_enabled) { - u32 esr; - ret =3D kvm_walk_nested_s2(vcpu, fault_ipa, &nested_trans); if (ret) { - esr =3D kvm_s2_trans_esr(&nested_trans); - kvm_inject_s2_fault(vcpu, esr); + kvm_inject_s2_fault(vcpu, kvm_s2_trans_esr(&nested_trans)); goto out_unlock; } =20 ret =3D kvm_s2_handle_perm_fault(vcpu, &nested_trans); if (ret) { - esr =3D kvm_s2_trans_esr(&nested_trans); - kvm_inject_s2_fault(vcpu, esr); + kvm_inject_s2_fault(vcpu, kvm_s2_trans_esr(&nested_trans)); goto out_unlock; } =20 --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C26B32C0292 for ; Thu, 21 Aug 2025 21:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810051; cv=none; b=o6HmPeXCnGnu3IqjmOnu9Q0wca+1VTWGWFJ+g4DcoESNNuEpjNvjxwAN/1GVaqTYvqbWp3Tmqa9ogzbNUY392vEUWCwZeTUmOi/jA+y6q7Wvq0w0mBZZQKUyAwfxa8TZtb1Q4+X0cJNMcZh5zwSTtBOkM1GMIMmXxDZXkfzCT+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810051; c=relaxed/simple; bh=cB2wU+VwA6nMuFS3kEdqkJ7/CjrceUGCWlda84QouGM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IPrT2ie2SW2MN/mE5e+D0Iyw5Ecrf6+LO4dQwFmvjBeVIlDSF/pUfMFdYYT5bLftV8qyKjFGa0JfSqlG88FpUb0gVkl2nbh6rSc5NuLuGswGB0iHJDH2+Uv9axYTbL4q3TvY+Fx4wqCYedUlEUKEMU9kAdlgc9tABXAo5B5IHTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lsr9lqNg; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lsr9lqNg" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-76e2eb787f2so1601090b3a.3 for ; Thu, 21 Aug 2025 14:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810049; x=1756414849; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=8p7YeBTxxS/VBPTvK9WSiN+wfsnNOjaE+88NekfQ6+E=; b=lsr9lqNgEjKlvmUPopkoLBMh9W8ybx1XUxyC/3ObGwar1fo4Z6J2o6amNIfNbaGDYF +OukaoOJdeBWt159xUtRXkbbdCIxJECGBbUjUHgottYWjseeOU/EEtF/MMC8ZN5sqC7Z qoQO421MHeCaWDEpR0N+5JfGCZsqDbRpRExr3Onza8SDnXvyKB2Nhp0NuHidFrhgfuiH btO4p49mIxCNduBmRSbvYVYiM7QmZZ0HUFHB1myT0ByGWErgpHzrCHQ86NYjrhL6GrTo vJyUCyMXuBt9Kij5xF6osOjc3xSX8Bp0fHBWoZygUF1bif+roAcRalr2Y/t4TY86v5Cs vJoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810049; x=1756414849; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8p7YeBTxxS/VBPTvK9WSiN+wfsnNOjaE+88NekfQ6+E=; b=TtUxnX/+48k5QmNQ3kxvQaAm824FdPPcUN0AAHsoXFSYX0OIWzQxo8bEXebHrARWKs EJnEzgmUjJcnGp/+k4jH0c1d2F5MveVOxb24d8rEHw4EsL0my3eSKanl0ZyUXumNX8QU bOUlnBsrXMq3dbm0NgiToZaMJbiw6+6PeB63Be10X42QK7Qb+Z/m7Bvnc9pNF0VvIt+Y 3FR531fFLaoaeGfLdPhOeyqb3DvRjAiOqQOg1cpq5iNjv4/+oeXdPxNCTrP991kp57IP +i6jncFzIWFJVeIyCUTvcdyv4zSfZBCvEUdep14Rsi/7JC6KCU/pM2H0jvEv/L8mVqM+ qU6A== X-Forwarded-Encrypted: i=1; AJvYcCXLI0wS5APErRze8OQF3mv4XlERjXlwh0K3mj4mT0ZnHTTfsZX6xuUAoNoLuvnvnwSJchZobyBHgrH7Xtw=@vger.kernel.org X-Gm-Message-State: AOJu0YwmTq6Ei7jwuS03usw9yWgKPapinA/5zV3Ip3QN/VCBlpG7RCbW Kchl85Ky401EXbkYIuNHqSjSaBVHKksGm7hMx1Fmy/80jwnMMzJBdD9NN/mCmAQP/sVCqnS/2uQ tmNPmhg== X-Google-Smtp-Source: AGHT+IGt2jvAqXlXksEez/FBRFt8Sle4R/dEKQftz/3BlDA59KSR9+VVS2FqW+adpYm0FOfYkSzrZkam6NE= X-Received: from pfbbq19.prod.google.com ([2002:a05:6a00:e13:b0:76c:2dcd:fdde]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a8e:b0:76c:1eae:fd30 with SMTP id d2e1a72fcca58-7702fa02d0fmr1050269b3a.12.1755810049097; Thu, 21 Aug 2025 14:00:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:28 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-3-seanjc@google.com> Subject: [RFC PATCH 02/16] KVM: arm64: Get iabt status on-demand From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Query if an abort was due to instruction execution only when necessary in anticipation of factoring out the SRCU-protected portion of abort handling to a separate helper. The happy path doesn't need to check for IAB, and eliminating the local variable will avoid having to pass a large pile of booleans to the inner helper. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index dc3aa58e2ea5..1e3ac283c519 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1830,7 +1830,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) phys_addr_t ipa; /* Always the IPA in the L1 guest phys space */ struct kvm_memory_slot *memslot; unsigned long hva; - bool is_iabt, write_fault, writable; + bool write_fault, writable; gfn_t gfn; int ret, idx; =20 @@ -1856,8 +1856,6 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) if (KVM_BUG_ON(ipa =3D=3D INVALID_GPA, vcpu->kvm)) return -EFAULT; =20 - is_iabt =3D kvm_vcpu_trap_is_iabt(vcpu); - if (esr_fsc_is_translation_fault(esr)) { /* Beyond sanitised PARange (which is the IPA limit) */ if (fault_ipa >=3D BIT_ULL(get_kvm_ipa_limit())) { @@ -1869,7 +1867,8 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) if (fault_ipa >=3D BIT_ULL(VTCR_EL2_IPA(vcpu->arch.hw_mmu->vtcr))) { fault_ipa |=3D kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0); =20 - return kvm_inject_sea(vcpu, is_iabt, fault_ipa); + return kvm_inject_sea(vcpu, kvm_vcpu_trap_is_iabt(vcpu), + fault_ipa); } } =20 @@ -1931,7 +1930,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) * anything about this (there's no syndrome for a start), so * re-inject the abort back into the guest. */ - if (is_iabt) { + if (kvm_vcpu_trap_is_iabt(vcpu)) { ret =3D -ENOEXEC; goto out; } --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70BD02D3ECD for ; Thu, 21 Aug 2025 21:00:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810053; cv=none; b=hFpLKobG/ccF0g2ILPQKjvpiDriwbm+ntVcyC0QJrQR40iZ8+eNz+1gNFKBJdlJ/9OlSu24e13kd3d2pdS5qyB/bLL1/O6d3sU5vHrCrgJ3ScC3kGoTkWWBgYmYBgKqwJ6o+8yYg0fkWr4O1cPHMY7TdM+GcQAK9R5tPRsmYZZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810053; c=relaxed/simple; bh=j602bYy7T//lg/va0rJT1q0ixQZt9Mt92VBF3wJ5dKc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KfLq//Al8hp5fLs2a3vf73fKAwoUMTGagS0199gqKFmHz9wwJNqdq9+VbUcMbQo/Ghc/dm/FJ86HVIRwY9/J7HtlrT55ccvbSPcnQMStKFTcyTZrKmRgmXiReYL4riL8+umfX1aVA/cAfdeOXXeg74hmB5m64gXS0Kmu+46SVMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MRhNyptJ; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MRhNyptJ" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b471758845dso1240273a12.3 for ; Thu, 21 Aug 2025 14:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810051; x=1756414851; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=Z1Z7dlZxBw5nHn1FPuYZbn+Y0LXB1yXFMLEbzmKHn2A=; b=MRhNyptJR5FOJz5b7Di3OcwPn6PJbe9/Yfnr54UzSoNJol5O/s7zLBJGKkDenH+o8D Mdj0FqCqx+KhYNj2v45Ddw5RnuPU8S4nRzr9eiJy75TkvwId3FC+ILaLsSGI1ncTzr9p Z+45WSAdRVhiOCC6TjBT5UvPVY71Xw3rifHt+5Nvs21wa4cnM/tO32nDAe+Fy0OC1MRv XEbDKKGclLJvuGCG3mHOXbyLw27YLU1s8/m/eCLIfyvyCdE1Oc67OeluUm3MzB1Km6T7 YIeS1s1fKfQyePQx6afVRRW68MC+7A+9cMvToGUD/u3voKTG6lA4ALLueQWAxZ2ry8il sXrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810051; x=1756414851; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z1Z7dlZxBw5nHn1FPuYZbn+Y0LXB1yXFMLEbzmKHn2A=; b=WcaX+UzNMCzXmYu8YnaDjznmgHls5WHJES3qHE3vxwmlJD+cgpkp4nLzHnTQuFjwSx YwCpRHc5HJ5gyTmCgszLe2tiHOBDq9oaR8OZ1L92TBLGmufYpVxuKEy3+YqpjSupJXen wOkTjNpq49Z+d1U31hvDHWsOmSPNMRlMQbGmwAwLtAcQCDDjot0lEJVhVj2pmo6UNZHP QCGHgEdfHCtYbtInyO1snIa8EU6a/02cUqLn3fhuGGFWpnPxTH0lRzUiNm/IkmBFDJXK aB/14XY9ml0HKgdHwJRwNfpf2qLTKMdmRXle/GN7ZDbSqKN3FHkYnt3oYhx4t/6jNpSb cZJQ== X-Forwarded-Encrypted: i=1; AJvYcCUwTv4NNuIPiING9jNC7wpiU79jXI9YF1BjMeJT35XYLEQI2Pg2sUj3XTsB77LKy0cagRctyrHL3i7aGtw=@vger.kernel.org X-Gm-Message-State: AOJu0YztouqjdYUqed2uJxs8xUxKtOM7jNCWdb/EdslWYPx7IIxYstgF 7xksu8RLQW7cTNP8hXv7LruaeLOo3L/9PcTszvICnIn5wAKyKBYXDinB0INJSa/v08cUiDbMtfu mOV+DNg== X-Google-Smtp-Source: AGHT+IFM0DDRKUEvT6bUujvJ11ucFjwG7bXTKg/FynvNfyXGnyLk/rw/50Ds3R7JLyodH6b8OqA5quCXy9I= X-Received: from pfbfj2.prod.google.com ([2002:a05:6a00:3a02:b0:76b:c53c:7184]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:5483:b0:240:11b3:bf2e with SMTP id adf61e73a8af0-24340b5b48bmr715813637.16.1755810050610; Thu, 21 Aug 2025 14:00:50 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:29 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-4-seanjc@google.com> Subject: [RFC PATCH 03/16] KVM: arm64: Move SRCU-protected region of kvm_handle_guest_abort() to helper From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the SRCU-protected portion of the abort handler to a separate helper in anticipation of adding "struct kvm_page_fault" to track state related to resolving the fault. Using a separate helper will allow making several fields in kvm_page_fault "const", without having to do something funky like create a temporary copy in the middle of kvm_handle_guest_abort(). No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 172 ++++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 84 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 1e3ac283c519..de028471b9eb 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1811,82 +1811,16 @@ static void handle_access_fault(struct kvm_vcpu *vc= pu, phys_addr_t fault_ipa) read_unlock(&vcpu->kvm->mmu_lock); } =20 -/** - * kvm_handle_guest_abort - handles all 2nd stage aborts - * @vcpu: the VCPU pointer - * - * Any abort that gets to the host is almost guaranteed to be caused by a - * missing second stage translation table entry, which can mean that eithe= r the - * guest simply needs more memory and we must allocate an appropriate page= or it - * can mean that the guest tried to access I/O memory, which is emulated b= y user - * space. The distinction is based on the IPA causing the fault and whethe= r this - * memory region has been registered as standard RAM by user space. - */ -int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) +static int __kvm_handle_guest_abort(struct kvm_vcpu *vcpu, phys_addr_t fau= lt_ipa, + unsigned long esr) { struct kvm_s2_trans nested_trans, *nested =3D NULL; - unsigned long esr; - phys_addr_t fault_ipa; /* The address we faulted on */ - phys_addr_t ipa; /* Always the IPA in the L1 guest phys space */ struct kvm_memory_slot *memslot; - unsigned long hva; bool write_fault, writable; + unsigned long hva; + phys_addr_t ipa; /* Always the IPA in the L1 guest phys space */ gfn_t gfn; - int ret, idx; - - /* Synchronous External Abort? */ - if (kvm_vcpu_abt_issea(vcpu)) { - /* - * For RAS the host kernel may handle this abort. - * There is no need to pass the error into the guest. - */ - if (kvm_handle_guest_sea()) - return kvm_inject_serror(vcpu); - - return 1; - } - - esr =3D kvm_vcpu_get_esr(vcpu); - - /* - * The fault IPA should be reliable at this point as we're not dealing - * with an SEA. - */ - ipa =3D fault_ipa =3D kvm_vcpu_get_fault_ipa(vcpu); - if (KVM_BUG_ON(ipa =3D=3D INVALID_GPA, vcpu->kvm)) - return -EFAULT; - - if (esr_fsc_is_translation_fault(esr)) { - /* Beyond sanitised PARange (which is the IPA limit) */ - if (fault_ipa >=3D BIT_ULL(get_kvm_ipa_limit())) { - kvm_inject_size_fault(vcpu); - return 1; - } - - /* Falls between the IPA range and the PARange? */ - if (fault_ipa >=3D BIT_ULL(VTCR_EL2_IPA(vcpu->arch.hw_mmu->vtcr))) { - fault_ipa |=3D kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0); - - return kvm_inject_sea(vcpu, kvm_vcpu_trap_is_iabt(vcpu), - fault_ipa); - } - } - - trace_kvm_guest_fault(*vcpu_pc(vcpu), kvm_vcpu_get_esr(vcpu), - kvm_vcpu_get_hfar(vcpu), fault_ipa); - - /* Check the stage-2 fault is trans. fault or write fault */ - if (!esr_fsc_is_translation_fault(esr) && - !esr_fsc_is_permission_fault(esr) && - !esr_fsc_is_access_flag_fault(esr)) { - kvm_err("Unsupported FSC: EC=3D%#x xFSC=3D%#lx ESR_EL2=3D%#lx\n", - kvm_vcpu_trap_get_class(vcpu), - (unsigned long)kvm_vcpu_trap_get_fault(vcpu), - (unsigned long)kvm_vcpu_get_esr(vcpu)); - return -EFAULT; - } - - idx =3D srcu_read_lock(&vcpu->kvm->srcu); + int ret; =20 /* * We may have faulted on a shadow stage 2 page table if we are @@ -1906,13 +1840,13 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) ret =3D kvm_walk_nested_s2(vcpu, fault_ipa, &nested_trans); if (ret) { kvm_inject_s2_fault(vcpu, kvm_s2_trans_esr(&nested_trans)); - goto out_unlock; + return ret; } =20 ret =3D kvm_s2_handle_perm_fault(vcpu, &nested_trans); if (ret) { kvm_inject_s2_fault(vcpu, kvm_s2_trans_esr(&nested_trans)); - goto out_unlock; + return ret; } =20 ipa =3D kvm_s2_trans_output(&nested_trans); @@ -1935,10 +1869,8 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) goto out; } =20 - if (kvm_vcpu_abt_iss1tw(vcpu)) { - ret =3D kvm_inject_sea_dabt(vcpu, kvm_vcpu_get_hfar(vcpu)); - goto out_unlock; - } + if (kvm_vcpu_abt_iss1tw(vcpu)) + return kvm_inject_sea_dabt(vcpu, kvm_vcpu_get_hfar(vcpu)); =20 /* * Check for a cache maintenance operation. Since we @@ -1952,8 +1884,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) */ if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) { kvm_incr_pc(vcpu); - ret =3D 1; - goto out_unlock; + return 1; } =20 /* @@ -1963,8 +1894,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) * of the page size. */ ipa |=3D kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0); - ret =3D io_mem_abort(vcpu, ipa); - goto out_unlock; + return io_mem_abort(vcpu, ipa); } =20 /* Userspace should not be able to register out-of-bounds IPAs */ @@ -1972,8 +1902,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) =20 if (esr_fsc_is_access_flag_fault(esr)) { handle_access_fault(vcpu, fault_ipa); - ret =3D 1; - goto out_unlock; + return 1; } =20 ret =3D user_mem_abort(vcpu, fault_ipa, nested, memslot, hva, @@ -1983,7 +1912,82 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) out: if (ret =3D=3D -ENOEXEC) ret =3D kvm_inject_sea_iabt(vcpu, kvm_vcpu_get_hfar(vcpu)); -out_unlock: + return ret; +} + +/** + * kvm_handle_guest_abort - handles all 2nd stage aborts + * @vcpu: the VCPU pointer + * + * Any abort that gets to the host is almost guaranteed to be caused by a + * missing second stage translation table entry, which can mean that eithe= r the + * guest simply needs more memory and we must allocate an appropriate page= or it + * can mean that the guest tried to access I/O memory, which is emulated b= y user + * space. The distinction is based on the IPA causing the fault and whethe= r this + * memory region has been registered as standard RAM by user space. + */ +int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) +{ + unsigned long esr; + phys_addr_t fault_ipa; /* The address we faulted on */ + int ret, idx; + + /* Synchronous External Abort? */ + if (kvm_vcpu_abt_issea(vcpu)) { + /* + * For RAS the host kernel may handle this abort. + * There is no need to pass the error into the guest. + */ + if (kvm_handle_guest_sea()) + return kvm_inject_serror(vcpu); + + return 1; + } + + esr =3D kvm_vcpu_get_esr(vcpu); + + /* + * The fault IPA should be reliable at this point as we're not dealing + * with an SEA. + */ + fault_ipa =3D kvm_vcpu_get_fault_ipa(vcpu); + if (KVM_BUG_ON(fault_ipa =3D=3D INVALID_GPA, vcpu->kvm)) + return -EFAULT; + + if (esr_fsc_is_translation_fault(esr)) { + /* Beyond sanitised PARange (which is the IPA limit) */ + if (fault_ipa >=3D BIT_ULL(get_kvm_ipa_limit())) { + kvm_inject_size_fault(vcpu); + return 1; + } + + /* Falls between the IPA range and the PARange? */ + if (fault_ipa >=3D BIT_ULL(VTCR_EL2_IPA(vcpu->arch.hw_mmu->vtcr))) { + fault_ipa |=3D kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0); + + return kvm_inject_sea(vcpu, kvm_vcpu_trap_is_iabt(vcpu), + fault_ipa); + } + } + + trace_kvm_guest_fault(*vcpu_pc(vcpu), kvm_vcpu_get_esr(vcpu), + kvm_vcpu_get_hfar(vcpu), fault_ipa); + + /* Check the stage-2 fault is trans. fault or write fault */ + if (!esr_fsc_is_translation_fault(esr) && + !esr_fsc_is_permission_fault(esr) && + !esr_fsc_is_access_flag_fault(esr)) { + kvm_err("Unsupported FSC: EC=3D%#x xFSC=3D%#lx ESR_EL2=3D%#lx\n", + kvm_vcpu_trap_get_class(vcpu), + (unsigned long)kvm_vcpu_trap_get_fault(vcpu), + (unsigned long)kvm_vcpu_get_esr(vcpu)); + return -EFAULT; + } + + idx =3D srcu_read_lock(&vcpu->kvm->srcu); + + ret =3D __kvm_handle_guest_abort(vcpu, fault_ipa, esr); + srcu_read_unlock(&vcpu->kvm->srcu, idx); return ret; } --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 435B42E92DC for ; Thu, 21 Aug 2025 21:00:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810054; cv=none; b=aZVNMWK/SuE/Nsy/qE1reLUQ7Uso0OQySDweBulvZ+DZfqhs5m7CEYB2jmD+pbI4Li7umP8dq9hcHmyzVwjspvWIUv+3s+rdNdsTgE10lpVSVyUmhprBh5dAgjWECu7fHFjNJgv1vLSv9VSB7mlzeLRJkbGZxzNUbzci0hCwHNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810054; c=relaxed/simple; bh=H8VFs2vZlQmG1JGjKINVH+XiNDz8nXmxoTY7lDJ7m5g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oQWX1DjHgVv+75BRLBTLJVZ0VEWPKbQPms7RSNFelGoxp9fb0XAnjNB84u3jICXbN0gB2a4Qeoo/l5nDCpjbMzpln4ZSQrCJl2EjWtwMazOQi5al9jxFPWxEhDnulLStJcI/W/5xWoF00H9fvxvko4BA24I8oOqtceuX43+p8A8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=esaOrxLd; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="esaOrxLd" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2461c537540so8457135ad.0 for ; Thu, 21 Aug 2025 14:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810052; x=1756414852; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=X5D34uO9hhnDzIV0eQsNJj+iG1O4AZl7/xnqUAlhc2A=; b=esaOrxLd7BOO1sxSHQo/kDOfUMwgoHJEws1X3UJa9Siy4pq3VxH7W6cRbq1uEDpMZ9 ApP9Iwkyn97TiEtI2FsqTBHm0rlzqjIsO8kd8ji8H7hW4IwhY/X/Uics01XB/6TD62JW Ob74D8dKA8yC9I07tL1NYqPgVLttlF7aNRZ7mYJ/PsazHWLgY9gA1BQ3R1qwwmUAaefS +RyGpMr80xkp56HCFiOE6JHvRdGpHbGoCVeD5HMVKUlsTfHTuzIgQrVwpuwc4G7bu9xQ y9Im3K2fYEnqf1540gjAHbv9Bm5XHA3K7562+bCJTL+U0HmQcmCtECmB3tXUTK5b9KGM 5erA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810052; x=1756414852; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X5D34uO9hhnDzIV0eQsNJj+iG1O4AZl7/xnqUAlhc2A=; b=HKkSLcrj0ZI6bWKphbTDTfsMWBpwekNMrNryMCeb5541by8G2St2kQaXcJH4LXH+7l DjF7TYFMZWrAgWgN/BT9OiH5ZxHfDkbEqNgJYdtOvXTIGuRLnkevd5X0YZVKK2+z4Nvt +KvA5yd90ImWCNIP4IIiGGKZYlE7S5iLgmJytQWGytqXKBwP76KCOCdIgrglOWGJL3bn D/kADj/8yGpoN/N8Y6dcWTBRU0rKLbE9PBV9Bhc2xymdUnZEzvkD27YrFG5QGb+wzseA gMJRgne7ZLU1JSiJXW7PQK6Px2JfrcB3mOZZ7Dr41ghkudYDNX1HaLWVYVAKss/yjI/Q gtAQ== X-Forwarded-Encrypted: i=1; AJvYcCVBFEJ9nMm4FBINm4BksWhATFHkSpA1bSkqfQqczLEudI5GafHqyMwwfxa2Lg8hsAbErZ9AcA26iZIfXtY=@vger.kernel.org X-Gm-Message-State: AOJu0Yygy4arU9fKnydJj1EENDFMlDPKUnVvy/jjhxEPBC4UQYPZD1pt bB4Bf/wGEfjkLdNjbSxBoBJWjV27pzsficJZh5iB9aWGelB2mCrqZT78w1b8BMy9gKtEQrYXoWk Y/wXSZw== X-Google-Smtp-Source: AGHT+IGd2anZ06gtV+U6bVFsbbPnzA1ZdvlYu/bGmJdbd8hlQ/26jHjvFuQxiH/8Yk00e7KNqc/bTBAWfHw= X-Received: from pjbsd14.prod.google.com ([2002:a17:90b:514e:b0:321:78e7:57fb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:da92:b0:246:2e9c:3400 with SMTP id d9443c01a7336-2462ee5917fmr11005625ad.16.1755810052479; Thu, 21 Aug 2025 14:00:52 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:30 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-5-seanjc@google.com> Subject: [RFC PATCH 04/16] KVM: arm64: Use guard(srcu) in kvm_handle_guest_abort() From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use a guard() to acquire/release SRCU when handling guest aborts to simplify the code a bit. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index de028471b9eb..49ce6bf623f7 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1930,7 +1930,6 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) { unsigned long esr; phys_addr_t fault_ipa; /* The address we faulted on */ - int ret, idx; =20 /* Synchronous External Abort? */ if (kvm_vcpu_abt_issea(vcpu)) { @@ -1984,12 +1983,9 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) return -EFAULT; } =20 - idx =3D srcu_read_lock(&vcpu->kvm->srcu); + guard(srcu)(&vcpu->kvm->srcu); =20 - ret =3D __kvm_handle_guest_abort(vcpu, fault_ipa, esr); - - srcu_read_unlock(&vcpu->kvm->srcu, idx); - return ret; + return __kvm_handle_guest_abort(vcpu, fault_ipa, esr); } =20 bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8F7D2C0297 for ; Thu, 21 Aug 2025 21:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810058; cv=none; b=fRh2kSIu2o9mLPXN/uA1t4T+cNkgUpUxQXHY5MX5s5SgJrV56DH9cn/wV/uzUbPiz8WoFNOSZzys68d94fJtvJvVzewbuliCugEWiEwF4DbqralAmVd0ezrORj6Hq5N8KvEY5+nH3hFrGu5renMtXHyjlXSmpUZEFJoVhk/X7nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810058; c=relaxed/simple; bh=Y+ltfZALifuJ1zLKcXiJdcTMewn8FXFncz1GJqx929M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZhEatdtnelrAXIxHW4rPcTTKOkFVuZsGQzeDrVoSEDaHeL+Qh/9ubfh6DgDP4Ia5Pi0yTNBHA20flZCv6cuIMvTYLJfjla6u/MLpWwjJGy9ximl1CoWNvYK9fXUVhZ7rN/LOv5mGnwGW9CtZLvsFHDQjzY1T4Cqvnyy2Ab1ESjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OiNY8cWg; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OiNY8cWg" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-245fb4c8789so18068565ad.0 for ; Thu, 21 Aug 2025 14:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810054; x=1756414854; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=+0mq+aZ8FiVuglcge/zbddfw9AWlhCmxeevWfZs8Ufk=; b=OiNY8cWghqtXOuGEiSBXZ57VyUN5Lurv6938mNmDZonOgfABhNOcaqiRtKELWChW+k zrwylhRXKYb0wxAAWF/C3yCKxwavLl8OQ9icUWdQGQyw7zdm6lj1wRhcxM8BLPsHAAVC Ct1bJyZk8HvzPg34IuyqDIxVysIWxcHHpoJiygYuiuC/0HuKj8xgtDnvj6A1FHu4oYtP RDn77d1yaWf9RAxge1d7tWY+0hWjEH/z7TSxoT+PtLsKwOdytr5XLcO7vUb7elV/hYeD h6mRmbyVrix8MxoKkBsIOSt4LkYOwsGxx8oyVFOcjiH/Yfsl3CLF+bVSvEYbRmRNZKNs DNBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810054; x=1756414854; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+0mq+aZ8FiVuglcge/zbddfw9AWlhCmxeevWfZs8Ufk=; b=j0l0y7AD0oh//Va9iyufai3Z/u/I2FOGDPNgeaSh8KQ4MKSbDfF/oeHrF6jcBAC0YY csF1iMtbkwzIeK88LQjw8UpGRDpblm0p7qtvkcJQKotRwup9mmeX2BI3VxLMJ76kN4c1 EFncWoZZjCTPNYy6irz10OqDmu/vrGcR95n0zny3+xU8AJlhUcdo4LSSKAczjFaeyix3 V7546okfYXPwhI0NDs0EvoNi3tRG9jOytthIyaBAq8tPI8QtJRYzE8rCrALkbOCkcS6X 6vu/zSk3NUTysgv+93bcN/zf7UXlyPCi7vZkHTiEKM1a9OiTQY5NNZQjvBQdK7niyrAE w4Og== X-Forwarded-Encrypted: i=1; AJvYcCWMI8BfR8FLJSn68LygpmGCfGSy+PxLiaVv3ZXNxJ9WXYehBxAm0+mhvmP/49r2Lbh8yG26tFxLWOGMCFQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzoaXlgb7StwXDo4HyIv+3Uskw6CUsnxL9kkpQ9fnIj3Q6W/KtY gcFgg3Vqds5BlnhfQYIT3axAftUN9MPpqnWTupDSQn1zZkU7AhdwDdYSLuPTKYkidaVZvmVe/Uv QMWnnBg== X-Google-Smtp-Source: AGHT+IGtL8cs3Nlow7DOdUj6noypYWB7mEAPGYg2neHXfT0CwVRf3Tt3Ig6UudknxiqaomdBF2z+yZTd9eo= X-Received: from plcx18.prod.google.com ([2002:a17:903:d2:b0:23f:df55:cf6f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d2c5:b0:246:570:2d91 with SMTP id d9443c01a7336-2462efcb0bemr7750285ad.61.1755810054013; Thu, 21 Aug 2025 14:00:54 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:31 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-6-seanjc@google.com> Subject: [RFC PATCH 05/16] KVM: arm64: Introduce "struct kvm_page_fault" for tracking abort state From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add and use a kvm_page_fault structure to track state when handling a guest abort. Collecting everything in a single structure will enable a variety of cleanups (reduce the number of params passed to helpers), and will pave the way toward using "struct kvm_page_fault" in arch-neutral KVM code, e.g. to consolidate logic for KVM_EXIT_MEMORY_FAULT. No functional change intended. Cc: James Houghton Link: https://lore.kernel.org/all/20250618042424.330664-1-jthoughton@google= .com Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 18 ++++ arch/arm64/kvm/mmu.c | 143 ++++++++++++++---------------- 2 files changed, 87 insertions(+), 74 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index 2f2394cce24e..4623cbc1edf4 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -413,6 +413,24 @@ struct kvm_vcpu_fault_info { u64 disr_el1; /* Deferred [SError] Status Register */ }; =20 +struct kvm_page_fault { + const u64 esr; + const bool exec; + const bool write; + const bool is_perm; + + phys_addr_t fault_ipa; /* The address we faulted on */ + phys_addr_t ipa; /* Always the IPA in the L1 guest phys space */ + + struct kvm_s2_trans *nested; + + gfn_t gfn; + struct kvm_memory_slot *slot; + unsigned long hva; + kvm_pfn_t pfn; + struct page *page; +}; + /* * VNCR() just places the VNCR_capable registers in the enum after * __VNCR_START__, and the value (after correction) to be an 8-byte offset diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 49ce6bf623f7..ca98778989b2 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1477,38 +1477,29 @@ static bool kvm_vma_is_cacheable(struct vm_area_str= uct *vma) } } =20 -static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, - struct kvm_s2_trans *nested, - struct kvm_memory_slot *memslot, unsigned long hva, - bool fault_is_perm) +static int user_mem_abort(struct kvm_vcpu *vcpu, struct kvm_page_fault *fa= ult) { int ret =3D 0; - bool write_fault, writable, force_pte =3D false; - bool exec_fault, mte_allowed, is_vma_cacheable; + bool writable, force_pte =3D false; + bool mte_allowed, is_vma_cacheable; bool s2_force_noncacheable =3D false, vfio_allow_any_uc =3D false; unsigned long mmu_seq; - phys_addr_t ipa =3D fault_ipa; struct kvm *kvm =3D vcpu->kvm; struct vm_area_struct *vma; short vma_shift; void *memcache; - gfn_t gfn; - kvm_pfn_t pfn; - bool logging_active =3D memslot_is_logging(memslot); + bool logging_active =3D memslot_is_logging(fault->slot); long vma_pagesize, fault_granule; enum kvm_pgtable_prot prot =3D KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; - struct page *page; vm_flags_t vm_flags; enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_HANDLE_FAULT | KVM= _PGTABLE_WALK_SHARED; =20 - if (fault_is_perm) + if (fault->is_perm) fault_granule =3D kvm_vcpu_trap_get_perm_fault_granule(vcpu); - write_fault =3D kvm_is_write_fault(vcpu); - exec_fault =3D kvm_vcpu_trap_is_exec_fault(vcpu); - VM_BUG_ON(write_fault && exec_fault); + VM_BUG_ON(fault->write && fault->exec); =20 - if (fault_is_perm && !write_fault && !exec_fault) { + if (fault->is_perm && !fault->write && !fault->exec) { kvm_err("Unexpected L2 read permission error\n"); return -EFAULT; } @@ -1524,7 +1515,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys= _addr_t fault_ipa, * only exception to this is when dirty logging is enabled at runtime * and a write fault needs to collapse a block entry into a table. */ - if (!fault_is_perm || (logging_active && write_fault)) { + if (!fault->is_perm || (logging_active && fault->write)) { int min_pages =3D kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu); =20 if (!is_protected_kvm_enabled()) @@ -1541,9 +1532,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys= _addr_t fault_ipa, * get block mapping for device MMIO region. */ mmap_read_lock(current->mm); - vma =3D vma_lookup(current->mm, hva); + vma =3D vma_lookup(current->mm, fault->hva); if (unlikely(!vma)) { - kvm_err("Failed to find VMA for hva 0x%lx\n", hva); + kvm_err("Failed to find VMA for hva 0x%lx\n", fault->hva); mmap_read_unlock(current->mm); return -EFAULT; } @@ -1556,13 +1547,13 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, force_pte =3D true; vma_shift =3D PAGE_SHIFT; } else { - vma_shift =3D get_vma_page_shift(vma, hva); + vma_shift =3D get_vma_page_shift(vma, fault->hva); } =20 switch (vma_shift) { #ifndef __PAGETABLE_PMD_FOLDED case PUD_SHIFT: - if (fault_supports_stage2_huge_mapping(memslot, hva, PUD_SIZE)) + if (fault_supports_stage2_huge_mapping(fault->slot, fault->hva, PUD_SIZE= )) break; fallthrough; #endif @@ -1570,7 +1561,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys= _addr_t fault_ipa, vma_shift =3D PMD_SHIFT; fallthrough; case PMD_SHIFT: - if (fault_supports_stage2_huge_mapping(memslot, hva, PMD_SIZE)) + if (fault_supports_stage2_huge_mapping(fault->slot, fault->hva, PMD_SIZE= )) break; fallthrough; case CONT_PTE_SHIFT: @@ -1585,19 +1576,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, =20 vma_pagesize =3D 1UL << vma_shift; =20 - if (nested) { + if (fault->nested) { unsigned long max_map_size; =20 max_map_size =3D force_pte ? PAGE_SIZE : PUD_SIZE; =20 - ipa =3D kvm_s2_trans_output(nested); + WARN_ON_ONCE(fault->ipa !=3D kvm_s2_trans_output(fault->nested)); =20 /* * If we're about to create a shadow stage 2 entry, then we * can only create a block mapping if the guest stage 2 page * table uses at least as big a mapping. */ - max_map_size =3D min(kvm_s2_trans_size(nested), max_map_size); + max_map_size =3D min(kvm_s2_trans_size(fault->nested), max_map_size); =20 /* * Be careful that if the mapping size falls between @@ -1618,11 +1609,11 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, * place. */ if (vma_pagesize =3D=3D PMD_SIZE || vma_pagesize =3D=3D PUD_SIZE) { - fault_ipa &=3D ~(vma_pagesize - 1); - ipa &=3D ~(vma_pagesize - 1); + fault->fault_ipa &=3D ~(vma_pagesize - 1); + fault->ipa &=3D ~(vma_pagesize - 1); } =20 - gfn =3D ipa >> PAGE_SHIFT; + fault->gfn =3D fault->ipa >> PAGE_SHIFT; mte_allowed =3D kvm_vma_mte_allowed(vma); =20 vfio_allow_any_uc =3D vma->vm_flags & VM_ALLOW_ANY_UNCACHED; @@ -1645,20 +1636,21 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, mmu_seq =3D vcpu->kvm->mmu_invalidate_seq; mmap_read_unlock(current->mm); =20 - pfn =3D __kvm_faultin_pfn(memslot, gfn, write_fault ? FOLL_WRITE : 0, - &writable, &page); - if (pfn =3D=3D KVM_PFN_ERR_HWPOISON) { - kvm_send_hwpoison_signal(hva, vma_shift); + fault->pfn =3D __kvm_faultin_pfn(fault->slot, fault->gfn, + fault->write ? FOLL_WRITE : 0, + &writable, &fault->page); + if (fault->pfn =3D=3D KVM_PFN_ERR_HWPOISON) { + kvm_send_hwpoison_signal(fault->hva, vma_shift); return 0; } - if (is_error_noslot_pfn(pfn)) + if (is_error_noslot_pfn(fault->pfn)) return -EFAULT; =20 /* * Check if this is non-struct page memory PFN, and cannot support * CMOs. It could potentially be unsafe to access as cachable. */ - if (vm_flags & (VM_PFNMAP | VM_MIXEDMAP) && !pfn_is_map_memory(pfn)) { + if (vm_flags & (VM_PFNMAP | VM_MIXEDMAP) && !pfn_is_map_memory(fault->pfn= )) { if (is_vma_cacheable) { /* * Whilst the VMA owner expects cacheable mapping to this @@ -1687,7 +1679,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys= _addr_t fault_ipa, */ s2_force_noncacheable =3D true; } - } else if (logging_active && !write_fault) { + } else if (logging_active && !fault->write) { /* * Only actually map the page as writable if this was a write * fault. @@ -1695,7 +1687,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys= _addr_t fault_ipa, writable =3D false; } =20 - if (exec_fault && s2_force_noncacheable) + if (fault->exec && s2_force_noncacheable) return -ENOEXEC; =20 /* @@ -1709,12 +1701,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, * used to limit the invalidation scope if a TTL hint or a range * isn't provided. */ - if (nested) { - writable &=3D kvm_s2_trans_writable(nested); - if (!kvm_s2_trans_readable(nested)) + if (fault->nested) { + writable &=3D kvm_s2_trans_writable(fault->nested); + if (!kvm_s2_trans_readable(fault->nested)) prot &=3D ~KVM_PGTABLE_PROT_R; =20 - prot |=3D kvm_encode_nested_level(nested); + prot |=3D kvm_encode_nested_level(fault->nested); } =20 kvm_fault_lock(kvm); @@ -1729,12 +1721,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, * backed by a THP and thus use block mapping if possible. */ if (vma_pagesize =3D=3D PAGE_SIZE && !(force_pte || s2_force_noncacheable= )) { - if (fault_is_perm && fault_granule > PAGE_SIZE) + if (fault->is_perm && fault_granule > PAGE_SIZE) vma_pagesize =3D fault_granule; else - vma_pagesize =3D transparent_hugepage_adjust(kvm, memslot, - hva, &pfn, - &fault_ipa); + vma_pagesize =3D transparent_hugepage_adjust(kvm, fault->slot, + fault->hva, &fault->pfn, + &fault->fault_ipa); =20 if (vma_pagesize < 0) { ret =3D vma_pagesize; @@ -1742,10 +1734,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, } } =20 - if (!fault_is_perm && !s2_force_noncacheable && kvm_has_mte(kvm)) { + if (!fault->is_perm && !s2_force_noncacheable && kvm_has_mte(kvm)) { /* Check the VMM hasn't introduced a new disallowed VMA */ if (mte_allowed) { - sanitise_mte_tags(kvm, pfn, vma_pagesize); + sanitise_mte_tags(kvm, fault->pfn, vma_pagesize); } else { ret =3D -EFAULT; goto out_unlock; @@ -1755,7 +1747,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys= _addr_t fault_ipa, if (writable) prot |=3D KVM_PGTABLE_PROT_W; =20 - if (exec_fault) + if (fault->exec) prot |=3D KVM_PGTABLE_PROT_X; =20 if (s2_force_noncacheable) { @@ -1764,7 +1756,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys= _addr_t fault_ipa, else prot |=3D KVM_PGTABLE_PROT_DEVICE; } else if (cpus_have_final_cap(ARM64_HAS_CACHE_DIC) && - (!nested || kvm_s2_trans_executable(nested))) { + (!fault->nested || kvm_s2_trans_executable(fault->nested))) { prot |=3D KVM_PGTABLE_PROT_X; } =20 @@ -1773,26 +1765,26 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, ph= ys_addr_t fault_ipa, * permissions only if vma_pagesize equals fault_granule. Otherwise, * kvm_pgtable_stage2_map() should be called to change block size. */ - if (fault_is_perm && vma_pagesize =3D=3D fault_granule) { + if (fault->is_perm && vma_pagesize =3D=3D fault_granule) { /* * Drop the SW bits in favour of those stored in the * PTE, which will be preserved. */ prot &=3D ~KVM_NV_GUEST_MAP_SZ; - ret =3D KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, fault_ipa, prot,= flags); + ret =3D KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, fault->fault_ipa= , prot, flags); } else { - ret =3D KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, fault_ipa, vma_pagesize, - __pfn_to_phys(pfn), prot, + ret =3D KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, fault->fault_ipa, vma_pa= gesize, + __pfn_to_phys(fault->pfn), prot, memcache, flags); } =20 out_unlock: - kvm_release_faultin_page(kvm, page, !!ret, writable); + kvm_release_faultin_page(kvm, fault->page, !!ret, writable); kvm_fault_unlock(kvm); =20 /* Mark the page dirty only if the fault is handled successfully */ if (writable && !ret) - mark_page_dirty_in_slot(kvm, memslot, gfn); + mark_page_dirty_in_slot(kvm, fault->slot, fault->gfn); =20 return ret !=3D -EAGAIN ? ret : 0; } @@ -1814,12 +1806,17 @@ static void handle_access_fault(struct kvm_vcpu *vc= pu, phys_addr_t fault_ipa) static int __kvm_handle_guest_abort(struct kvm_vcpu *vcpu, phys_addr_t fau= lt_ipa, unsigned long esr) { - struct kvm_s2_trans nested_trans, *nested =3D NULL; - struct kvm_memory_slot *memslot; - bool write_fault, writable; - unsigned long hva; - phys_addr_t ipa; /* Always the IPA in the L1 guest phys space */ - gfn_t gfn; + struct kvm_page_fault fault =3D { + .fault_ipa =3D fault_ipa, + .esr =3D esr, + .ipa =3D fault_ipa, + + .write =3D kvm_is_write_fault(vcpu), + .exec =3D kvm_vcpu_trap_is_exec_fault(vcpu), + .is_perm =3D esr_fsc_is_permission_fault(esr), + }; + struct kvm_s2_trans nested_trans; + bool writable; int ret; =20 /* @@ -1849,15 +1846,14 @@ static int __kvm_handle_guest_abort(struct kvm_vcpu= *vcpu, phys_addr_t fault_ipa return ret; } =20 - ipa =3D kvm_s2_trans_output(&nested_trans); - nested =3D &nested_trans; + fault.ipa =3D kvm_s2_trans_output(&nested_trans); + fault.nested =3D &nested_trans; } =20 - gfn =3D ipa >> PAGE_SHIFT; - memslot =3D gfn_to_memslot(vcpu->kvm, gfn); - hva =3D gfn_to_hva_memslot_prot(memslot, gfn, &writable); - write_fault =3D kvm_is_write_fault(vcpu); - if (kvm_is_error_hva(hva) || (write_fault && !writable)) { + fault.gfn =3D fault.ipa >> PAGE_SHIFT; + fault.slot =3D gfn_to_memslot(vcpu->kvm, fault.gfn); + fault.hva =3D gfn_to_hva_memslot_prot(fault.slot, fault.gfn, &writable); + if (kvm_is_error_hva(fault.hva) || (fault.write && !writable)) { /* * The guest has put either its instructions or its page-tables * somewhere it shouldn't have. Userspace won't be able to do @@ -1882,7 +1878,7 @@ static int __kvm_handle_guest_abort(struct kvm_vcpu *= vcpu, phys_addr_t fault_ipa * So let's assume that the guest is just being * cautious, and skip the instruction. */ - if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) { + if (kvm_is_error_hva(fault.hva) && kvm_vcpu_dabt_is_cm(vcpu)) { kvm_incr_pc(vcpu); return 1; } @@ -1893,20 +1889,19 @@ static int __kvm_handle_guest_abort(struct kvm_vcpu= *vcpu, phys_addr_t fault_ipa * faulting VA. This is always 12 bits, irrespective * of the page size. */ - ipa |=3D kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0); - return io_mem_abort(vcpu, ipa); + fault.ipa |=3D kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0); + return io_mem_abort(vcpu, fault.ipa); } =20 /* Userspace should not be able to register out-of-bounds IPAs */ - VM_BUG_ON(ipa >=3D kvm_phys_size(vcpu->arch.hw_mmu)); + VM_BUG_ON(fault.ipa >=3D kvm_phys_size(vcpu->arch.hw_mmu)); =20 if (esr_fsc_is_access_flag_fault(esr)) { - handle_access_fault(vcpu, fault_ipa); + handle_access_fault(vcpu, fault.fault_ipa); return 1; } =20 - ret =3D user_mem_abort(vcpu, fault_ipa, nested, memslot, hva, - esr_fsc_is_permission_fault(esr)); + ret =3D user_mem_abort(vcpu, &fault); if (ret =3D=3D 0) ret =3D 1; out: --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEFB128315A for ; Thu, 21 Aug 2025 21:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810058; cv=none; b=WmEdATBU73/DonHFyhCTuvrSl2UBo935ATqYv3Ji0Chx3Ffz7WEGoIjL3skDE4cqO2TWRPCUXjS4Av9qJlndbguVLP8UTlQtKZ8pp9yFBbgNcEgB0fh/7w4mkVkMJyWFwTtwZUawCQysOHhQkjlsuIvmxSJMvJnCrwWPokVWGpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810058; c=relaxed/simple; bh=O97tgp5t9/0u9T/cM2oyRaSjhATuyjcKvcGSgt6Pzfo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HUz7fzWZK1UNQs0biMHc2rBK0incGCHGsR33DOAfSybouZQxu48JkanrCgRb1mH6NXpOjxOBM7g0pIOaEpVZgPJDwJm2rNR/bxcrV+qA7HRiy5AkUWLpGTPKc7GCI14xuenEdB5djka2/Vk7eCTsi5/EbDqDtiarhye3qgugdOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CKuJLkJw; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CKuJLkJw" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b474d5ff588so1094945a12.2 for ; Thu, 21 Aug 2025 14:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810056; x=1756414856; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=vioVXt2ZZgg7NeYPZVOuYjJyML9DfewAFD4Lo8ICLyI=; b=CKuJLkJwxzQnFYwcRtGNVXmrptdLEW+6CL0hBpmFML1mFvcSs4b8rcsgFGMRRZwhmN lxrY0n4EfDi9LhO8QPrG0F/jN+J5wOOHvhV6pU5w6o64vsuYXzWhE0oFVOhslHnYcf8i Na5JxWdJSUp8QzmfLboCDTScDLgWgjXTLQ+LRlJR1wnisEwgZ7njhZtOZyIxoAXxt+JK ZwsUtRYG69ccEADYoZF508eAD5FL5ZbEFzSQLRdlI5rCNBwOLyW9JcWpVn7HVE2kvsOM d6y4D8f+Zn3yiS5RCCE9mZrRwvPOevAjcwij5Oo2tyDFSkvhdqI98LV3MMdmNPIVvgpn 6S9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810056; x=1756414856; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vioVXt2ZZgg7NeYPZVOuYjJyML9DfewAFD4Lo8ICLyI=; b=A3iDHt7AQw/Z3qxrd18YtXp/i8VNnAE1FAcRusVMbgCeHg5esHwQfCN1byYYpLLsNm p9ch6lP4TscPfNPLHyBjqvJmnXUvlc4RZq1gF4V0VMgMlLHty8MOcwTjCbH4yw8Jrorr aI6Az+t/VeIxzQdHOPXb4Lee5sgn/bY9yr7o2vou+JicrOuxm9vkHLwAeFm3r5YPAWfQ p/OJPRCEPyh65CnsSpS60sECs6ikeEorzDuzBjRsF68G7SmQInENowYNPUfDz0OnDHJy qeDh1bY+pFHKQpcVhFoxHnFK3FXGIvb0UsAP6PiEPrMvpyhzD4tM9wqF7nDIKBf+bwh9 TZCg== X-Forwarded-Encrypted: i=1; AJvYcCWKjsPA6lO9h/Jf774HXKrt8jMYz2adu88sU75ln2N341Si4NV7JTXgXcz5DRZzhfnr2emBXPMl1IQBADU=@vger.kernel.org X-Gm-Message-State: AOJu0YxI312X3PwE+UZjNnX6zlWy+n/prZdzs+KVdCZnJoovykKmM/Q3 Cvxm9CMuc8yqNSA2vcm1qzpBZVnjVQCoZMLG730Uyqn6fIf8L2VfVkKy0ZHz1MeHirDPYS+76bX Cvw0lrQ== X-Google-Smtp-Source: AGHT+IFMAoySLGWaBGxxLE7EGe5/JK70vfGurcQkwXtR0YxVIkKbRYcB3XHf65NsmmZ5Hb+78WjJ0WrD9XU= X-Received: from pjbee15.prod.google.com ([2002:a17:90a:fc4f:b0:321:c3cc:2574]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4c45:b0:324:e96a:2ada with SMTP id 98e67ed59e1d1-3251774ac2emr940105a91.21.1755810055944; Thu, 21 Aug 2025 14:00:55 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:32 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-7-seanjc@google.com> Subject: [RFC PATCH 06/16] KVM: arm64: Pass kvm_page_fault pointer to transparent_hugepage_adjust() From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the local kvm_page_fault structure to adjust for transparent hugepages when resolving guest aborts, to reduce the number of parameters from 5=3D>2, and to eliminate the less-than-pleasant pointer dereferences. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index ca98778989b2..047aba00388c 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1361,19 +1361,15 @@ static bool fault_supports_stage2_huge_mapping(stru= ct kvm_memory_slot *memslot, * Returns the size of the mapping. */ static long -transparent_hugepage_adjust(struct kvm *kvm, struct kvm_memory_slot *memsl= ot, - unsigned long hva, kvm_pfn_t *pfnp, - phys_addr_t *ipap) +transparent_hugepage_adjust(struct kvm *kvm, struct kvm_page_fault *fault) { - kvm_pfn_t pfn =3D *pfnp; - /* * Make sure the adjustment is done only for THP pages. Also make * sure that the HVA and IPA are sufficiently aligned and that the * block map is contained within the memslot. */ - if (fault_supports_stage2_huge_mapping(memslot, hva, PMD_SIZE)) { - int sz =3D get_user_mapping_size(kvm, hva); + if (fault_supports_stage2_huge_mapping(fault->slot, fault->hva, PMD_SIZE)= ) { + int sz =3D get_user_mapping_size(kvm, fault->hva); =20 if (sz < 0) return sz; @@ -1381,10 +1377,8 @@ transparent_hugepage_adjust(struct kvm *kvm, struct = kvm_memory_slot *memslot, if (sz < PMD_SIZE) return PAGE_SIZE; =20 - *ipap &=3D PMD_MASK; - pfn &=3D ~(PTRS_PER_PMD - 1); - *pfnp =3D pfn; - + fault->ipa &=3D PMD_MASK; + fault->pfn &=3D ~(PTRS_PER_PMD - 1); return PMD_SIZE; } =20 @@ -1724,9 +1718,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) if (fault->is_perm && fault_granule > PAGE_SIZE) vma_pagesize =3D fault_granule; else - vma_pagesize =3D transparent_hugepage_adjust(kvm, fault->slot, - fault->hva, &fault->pfn, - &fault->fault_ipa); + vma_pagesize =3D transparent_hugepage_adjust(kvm, fault); =20 if (vma_pagesize < 0) { ret =3D vma_pagesize; --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C49662EB5C1 for ; Thu, 21 Aug 2025 21:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810060; cv=none; b=jKIVKbVXSh2tbdaNLcf3oQuYSW1RGkfp1weMNcTZ0VILT1lSzlD8rhIADMKYJpWgyNM/FLUtz5sywrkLgzZdPN++uY6gBACycG5P/NwddsDvmCfAYNJtKm/grbLQJIx0Rmvaq8ymhswt6aairSsGLpa5QjMaQmhleQI931PJRCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810060; c=relaxed/simple; bh=n2xHKJwW4GBGQxPu8+45mca9yh0HIcvMkQScT1xXiwY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iPlbsdkaHJ1RqBsYQTH1zL8MD4Y61uloFmzH4waSnueVZL6R1IocUUxWHmFb+2yvIa0qOuzGMEVUOtmmLBLygL1LMkVGXhav1RN5K99Kfc/PONAs2+jZfaG0EJOuLumctgJDonOhz3fOI7Yn7Nb1tj2JpDQCuvwg1Uc5ZACJCcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KCt+FlwH; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KCt+FlwH" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-325228e9bedso98120a91.1 for ; Thu, 21 Aug 2025 14:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810058; x=1756414858; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=rIYjUyPKKDdCEejXmfDWcQPbYLUJJKvCpdBRdQ8wgkk=; b=KCt+FlwH6VXzt0dpgSqkbvSf/1t7MEFsfE4bf1+QBOwfMFeEkpungqKo95kdp0HgKE R9zU1km7MqPzvlrOJID6aWx8ufyjukPWa5OW1sBkruBuVi/oPpfn05z/MneCQ9PsoBPg DgEymskxfvXt8jrr7lgtWNS3jM+H+3xx8OkKPqwdc/qRfM0vRWmjCXs2wiihaAdghkLs oL3sINNbEmhKoXMBNxewfX3MYH55nsKbYfPgxVlN4cfMZaGUzyTqjtBjR3qgNrkRFih7 Pd6pXw16kqbOIA5/yH9/U0/ZXH+hN9Bgcr4qAb7GFC0dFRyQVFcKFNZ/7K065EyFVNtm qTmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810058; x=1756414858; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rIYjUyPKKDdCEejXmfDWcQPbYLUJJKvCpdBRdQ8wgkk=; b=va3/grU5S38jnV5oGDXj1/Qn2aPUwy1LQnZPmjJRuV3hk+7zxX/bIo4L0Lqdnop67r cXH2Mnhf14aFYGks9Z8bkq4zkjenPl/g3eWxCBBgPHs3Km2MI44bFlcO6t7HXG7P9SnZ 63FSq59UiXnubJzQmM0LzJRlzwCL8GgOk2k4nKHMS1u5XxLyoctZICEbGyolXBBFUWD/ N8ICzOhwLdngNjCr3X491fk3nYmMce2LDwkWXcN4ogaLG86fW3E7dN11tkq1VpJ3eJuj jb8Pcyv0zVqG+jY5mbSioiUXcgu8Dn7VLvWEciwsQCEFZmCe8ybE1+0Ze2vZAy+eqFA+ +AjA== X-Forwarded-Encrypted: i=1; AJvYcCVJw9kgE3cBvqG4YpbekFCswTYA5jidJdpO0zboCaTnL/z0Hw30FWZawv8EeXyAeXH70EIA5PXTJ9blO/c=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3wwDirJo/itlXBDb/u8T5haiGWcrt9/3+jOpBTIi9DOnEbKT2 lUWTPFRBwH1qf5IBstuV62cZkA1hZxcTMnMaISvI88iOaHxjy24t4VFgdOL71GswQE8jhEzsjLt TUQqm0A== X-Google-Smtp-Source: AGHT+IGevG4sJg+U1oYZiyIkXuxzC5L9OjooNDxBFWaxTZvDjCA0pb211437o2pCDdf6DI+kKvb4PRBSGWk= X-Received: from pjbrr6.prod.google.com ([2002:a17:90b:2b46:b0:323:247f:7f59]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d610:b0:31f:762c:bc40 with SMTP id 98e67ed59e1d1-32515e54409mr1117649a91.16.1755810058080; Thu, 21 Aug 2025 14:00:58 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:33 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-8-seanjc@google.com> Subject: [RFC PATCH 07/16] KVM: arm64: Pass @fault to fault_supports_stage2_huge_mapping() From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass the full kvm_page_fault object when querying if a fault supports a hugepage mapping instead of passing the separate slot+address pair. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 047aba00388c..c6aadd8baa18 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1287,10 +1287,10 @@ static void kvm_send_hwpoison_signal(unsigned long = address, short lsb) send_sig_mceerr(BUS_MCEERR_AR, (void __user *)address, lsb, current); } =20 -static bool fault_supports_stage2_huge_mapping(struct kvm_memory_slot *mem= slot, - unsigned long hva, +static bool fault_supports_stage2_huge_mapping(struct kvm_page_fault *faul= t, unsigned long map_size) { + struct kvm_memory_slot *memslot =3D fault->slot; gpa_t gpa_start; hva_t uaddr_start, uaddr_end; size_t size; @@ -1348,8 +1348,8 @@ static bool fault_supports_stage2_huge_mapping(struct= kvm_memory_slot *memslot, * userspace_addr or the base_gfn, as both are equally aligned (per * the check above) and equally sized. */ - return (hva & ~(map_size - 1)) >=3D uaddr_start && - (hva & ~(map_size - 1)) + map_size <=3D uaddr_end; + return (fault->hva & ~(map_size - 1)) >=3D uaddr_start && + (fault->hva & ~(map_size - 1)) + map_size <=3D uaddr_end; } =20 /* @@ -1368,7 +1368,7 @@ transparent_hugepage_adjust(struct kvm *kvm, struct k= vm_page_fault *fault) * sure that the HVA and IPA are sufficiently aligned and that the * block map is contained within the memslot. */ - if (fault_supports_stage2_huge_mapping(fault->slot, fault->hva, PMD_SIZE)= ) { + if (fault_supports_stage2_huge_mapping(fault, PMD_SIZE)) { int sz =3D get_user_mapping_size(kvm, fault->hva); =20 if (sz < 0) @@ -1547,7 +1547,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) switch (vma_shift) { #ifndef __PAGETABLE_PMD_FOLDED case PUD_SHIFT: - if (fault_supports_stage2_huge_mapping(fault->slot, fault->hva, PUD_SIZE= )) + if (fault_supports_stage2_huge_mapping(fault, PUD_SIZE)) break; fallthrough; #endif @@ -1555,7 +1555,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) vma_shift =3D PMD_SHIFT; fallthrough; case PMD_SHIFT: - if (fault_supports_stage2_huge_mapping(fault->slot, fault->hva, PMD_SIZE= )) + if (fault_supports_stage2_huge_mapping(fault, PMD_SIZE)) break; fallthrough; case CONT_PTE_SHIFT: --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 666CD393DC1 for ; Thu, 21 Aug 2025 21:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810061; cv=none; b=ppmLyfYDAOuug6+lLTg05b3BLWIiWlCk4tz+MjkjWQZPeEqQZ7jkp1WZMSgjOrELfBQOeA2TF61sz0BPivm4iBWlcd+CHRc/IkooczOQBKzOAmcT9D7+a2yDPc8istojVeG531hrGR4NahJGcdKCUKLL1GnzNSuaMFVZZ13snMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810061; c=relaxed/simple; bh=ABhvefXpoIuEQ5mRvyqgcnHqEvoUbf3IKbz3Y8+eKrc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OHtzK/xMUrR5gYxjK+X+63osuY0sWVXX9IosQfecZoaZDIrG2k/A/4MAV0d8cpr6hM/CPCdaeOo6OL18E4P+dhdnwBVBcYRv9BZRA8PS4iTPzRj0xah/hVkfOoX7C180IhkugOARVD92KceK670IGeffvX9l/QdKetMy9uXJ6FU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NYtWLudv; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NYtWLudv" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-24457f54bb2so37582555ad.0 for ; Thu, 21 Aug 2025 14:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810060; x=1756414860; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=qF0NqksTmsFEMXYPOijW2W+Po4z2kEGBRHxGZcBCgsM=; b=NYtWLudv3YsFzR/EfmOeSQ+hRqUY7Q9sWOoHEC3Dw2LoIFSVv8FY+qCDhhv09y+49Z CqT+LgwE9IQtGzbVYj4UnhRsMI/0W5uTPXLyIqTrrR7BT4CGz81tKujRklszhYqp+zUl pnaSAsIHEOfgu79o5qpMeQmcUJsUTYBotw29HrXbj8KVb3yi/lKNnk2Wgi7ETmXiApcV Q6pv1PhZjTpi55Amu1SAhUMXNfEA4TrDzJS3GMjZgZbDeRanFUtuApZ+B2ifAIICuBQQ sZHEEaHjZXSXoIMrP4Bhu5kVxrSPQy9uM2/BKFWvQh42+tTBWHJGaet01CInCvCUXpFS n3Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810060; x=1756414860; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qF0NqksTmsFEMXYPOijW2W+Po4z2kEGBRHxGZcBCgsM=; b=s9+LwPrUpGEGuR7wk045yDqzix2OzjaJJlQqORkhx/XbocnageGGYh0hhrXRU1F74d n3jVfou/I5bE9kyLnDHTAEGt2eFIHzRViJUCEwOMX8jb5Oox6EiRvtXQXG1qqUuTsc6W A+8fcR0mZTqwlZ1kLRS8lnULt46pjRN/OwSRHT1i7W56qiPr6ufhlsh9IJCBGvhTrzCG R3uCtkD3QmUI8DBrGPgGuu7yLWz2cvoAdaslu3gUOvf/Qt0+C+BMiOsO/lxlVK8TLws7 2qNNea2ugQtwuMCVJ6BmUpaf9EIB40j7mtQrFtKeUR+FYyG9qxKc6yoqokhLiE5PBJGi 0S5w== X-Forwarded-Encrypted: i=1; AJvYcCWifxQfJJYlnzlLo172iTd16zwwBY24fPp/XMKE/wxMuLXaf88hCJ8A9hJy7YlHwQ3Gzqu7OqBDt7MB3T8=@vger.kernel.org X-Gm-Message-State: AOJu0YydH4mWcIHQJpuB3T18vifsCowPXfdDu46Ib+glSF6V5UtMHQxa mJ5F/DcLiI1j0Y0gvsL9N1Y9PEk6aV5pIhoOyj79jyCZD6lvMjjeqNfSL2qmT7dSLtveBM7cgpm zMGyQTQ== X-Google-Smtp-Source: AGHT+IG5Izpq2Sl1N9Hzv50wRfJpmndOfATaks3Z+gYK79D4NeWWn/zwR5Uaz/7EA8M4H+pgD0lOKvSxa0c= X-Received: from plgv17.prod.google.com ([2002:a17:902:e8d1:b0:23c:7695:dcc5]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce01:b0:240:52c8:2556 with SMTP id d9443c01a7336-2462ef44433mr9049685ad.39.1755810059747; Thu, 21 Aug 2025 14:00:59 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:34 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-9-seanjc@google.com> Subject: [RFC PATCH 08/16] KVM: arm64: Add helper to get permission fault granule from ESR From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extract KVM's code for getting the granule for a permission fault into a standalone API that takes in a raw ESR, so that KVM can get the granule from a local copy of the ESR instead of re-retrieving the value from the vCPU. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/esr.h | 6 ++++++ arch/arm64/include/asm/kvm_emulate.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h index e1deed824464..5bb99cfd184a 100644 --- a/arch/arm64/include/asm/esr.h +++ b/arch/arm64/include/asm/esr.h @@ -8,6 +8,7 @@ #define __ASM_ESR_H =20 #include +#include #include =20 #define ESR_ELx_EC_UNKNOWN UL(0x00) @@ -478,6 +479,11 @@ static inline bool esr_fsc_is_permission_fault(unsigne= d long esr) (esr =3D=3D ESR_ELx_FSC_PERM_L(0)); } =20 +static inline u64 esr_fsc_perm_fault_granule(unsigned long esr) +{ + return BIT(ARM64_HW_PGTABLE_LEVEL_SHIFT(esr & ESR_ELx_FSC_LEVEL)); +} + static inline bool esr_fsc_is_access_flag_fault(unsigned long esr) { esr =3D esr & ESR_ELx_FSC; diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/= kvm_emulate.h index fa8a08a1ccd5..8065f54927cb 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -455,7 +455,7 @@ u64 kvm_vcpu_trap_get_perm_fault_granule(const struct k= vm_vcpu *vcpu) unsigned long esr =3D kvm_vcpu_get_esr(vcpu); =20 BUG_ON(!esr_fsc_is_permission_fault(esr)); - return BIT(ARM64_HW_PGTABLE_LEVEL_SHIFT(esr & ESR_ELx_FSC_LEVEL)); + return esr_fsc_perm_fault_granule(esr); } =20 static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu) --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 316F52EB850 for ; Thu, 21 Aug 2025 21:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810063; cv=none; b=PMUBxATU17gtfgf26pqhz1UTc/JED/oTiACHnd+Uq3VqjRDt/vNFXZ9LF5pFNMHGIZqc9J4+B6JGSmBRtAnZL+AfMC8oDKMPFwDLhm/XfcGBaX0tcH3MoZ7+is/vo8pusuUnMZdp0omoBFcdnHwtUCIoAYHhokqNH3WFL1UXQrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810063; c=relaxed/simple; bh=0R29yrVz5jzSSmRWFh2gn4ID37EkSuIqGvyigwjoDgA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aX8R4IPCfOkEDZ1T2f9+4xaM7G3AVH/aVp5/+k2rKu9EodZ446fCjg30+x00WJjoc6TLyuA5R++NwUBQCqvzCOZwfneRd5XPpjh0p2TlIA+MTMyJTywBl+yXFSX+1T3Vc/Itar3Ecckpd6DoN7eyGKISjWNKV7j2jay96YY2Hhs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cwKJD32e; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cwKJD32e" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-76e2ead3b51so2634907b3a.2 for ; Thu, 21 Aug 2025 14:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810061; x=1756414861; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=nw5kiI6YvAO2RXGdtpyjseVagbE32KnshmO9YLBiZhk=; b=cwKJD32eDxl4KrLcFaPwH0YY7f+s5Pel07H5WP0Hs5sf/t8VnVNw9Kcl8NZFO9Ulgg R1y46ltsjgQFnmIrKIyY2jOZMpnr6PcxugcHn5nLrNj2MyAtMnAx96ItTUarlgil1da4 4JT9n/fFGrKZbmBrJ+rxMjw5uG8S/7W6J/Y1RXUUGBSDeoqAQl1rq19mQolAgPIAfHMq BgF65J6rRkEtITPqJlzq/pG2rXbIeUmEs7KvHvq2JY7rHSQGojauAcro8QSGvsDF4RQ7 RuWooBVXy/NowH9aslCzyK9Xyj+sDHbJOsPHjDL0kqrEvmbAA6IBeqT1b/TcAsqOKBht OEsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810061; x=1756414861; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nw5kiI6YvAO2RXGdtpyjseVagbE32KnshmO9YLBiZhk=; b=D2ejpxujF+Comlp71nHjnj2m8/OIggjx3fnFVTWMxWEP1V1Nqg1GiuY5DuZ+AlGfoj eL2ytJoDe0lyWR0odeHhPqkjwUgr80o1Ohx8xjaYLCYGJQ3c0yRtILMrl9cd50tsCzey 0RanBmJU42nTOwhKUHO1BFOds227P8bHMuB/7npOETfuywuJl57aMe+vgfL/XEX/jAkd RA5mRhVUBGnmjG5aEOJmjNpPLO8brZL7d5e4RYF2JvgjbOYkqOi1wuBypWsD37YdKQt9 Vk/Kwkml0xQmFf2Uq3ChkcKVj64tY6Wq2UgrmYqK+4DoMrfPncY6IK7tYud3S3Cp1WG3 zZvQ== X-Forwarded-Encrypted: i=1; AJvYcCWfLAKmKmPjBU+pHqQbXBPHSpSmYY3Bq86bBipiNPKZgv+C2CmjqcPhcQnLhX0BtQiN+ofqkVYpm+PgGxU=@vger.kernel.org X-Gm-Message-State: AOJu0YwJUFnKxlLtUARPpwZYuIbok4PN3uN8KZOPMY13gFzJnqDTyCAH qWlvSnukPFEhBReRfi4m3nLtkYKoaePADWiXx7HdZZ81QfLr6YPbCIBlL9FmeXFRZC5I5U5lLDZ zUvQmKg== X-Google-Smtp-Source: AGHT+IGle6xFEs66cx8IStkT7ygYTzBQ/CVc9BMQ/qOuDjmd3FaQf765ZcadOYjVlZz3dCJkQZna0ErFQAI= X-Received: from pgww17.prod.google.com ([2002:a05:6a02:2c91:b0:b42:189a:ccf8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:1582:b0:240:9126:2bde with SMTP id adf61e73a8af0-24340d5e4cemr792496637.46.1755810061454; Thu, 21 Aug 2025 14:01:01 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:35 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-10-seanjc@google.com> Subject: [RFC PATCH 09/16] KVM: arm64: Track perm fault granule in "struct kvm_page_fault" From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add permission fault granule information to "struct kvm_page_fault", to help capture that the granule is a property of the fault, and to make the information readily available, e.g. without needing to be explicitly passed if it's needed by a helper. Opportunistically drop kvm_vcpu_trap_get_perm_fault_granule() and simply grab the granule from the passed-in ESR. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_emulate.h | 9 --------- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/mmu.c | 13 ++++++------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/= kvm_emulate.h index 8065f54927cb..93e7a0bad0fb 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -449,15 +449,6 @@ bool kvm_vcpu_trap_is_translation_fault(const struct k= vm_vcpu *vcpu) return esr_fsc_is_translation_fault(kvm_vcpu_get_esr(vcpu)); } =20 -static inline -u64 kvm_vcpu_trap_get_perm_fault_granule(const struct kvm_vcpu *vcpu) -{ - unsigned long esr =3D kvm_vcpu_get_esr(vcpu); - - BUG_ON(!esr_fsc_is_permission_fault(esr)); - return esr_fsc_perm_fault_granule(esr); -} - static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu) { switch (kvm_vcpu_trap_get_fault(vcpu)) { diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index 4623cbc1edf4..ec6473007fb9 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -418,6 +418,7 @@ struct kvm_page_fault { const bool exec; const bool write; const bool is_perm; + const u64 granule; =20 phys_addr_t fault_ipa; /* The address we faulted on */ phys_addr_t ipa; /* Always the IPA in the L1 guest phys space */ diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index c6aadd8baa18..10c73494d505 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1483,14 +1483,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, st= ruct kvm_page_fault *fault) short vma_shift; void *memcache; bool logging_active =3D memslot_is_logging(fault->slot); - long vma_pagesize, fault_granule; + long vma_pagesize; enum kvm_pgtable_prot prot =3D KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; vm_flags_t vm_flags; enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_HANDLE_FAULT | KVM= _PGTABLE_WALK_SHARED; =20 - if (fault->is_perm) - fault_granule =3D kvm_vcpu_trap_get_perm_fault_granule(vcpu); VM_BUG_ON(fault->write && fault->exec); =20 if (fault->is_perm && !fault->write && !fault->exec) { @@ -1715,8 +1713,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) * backed by a THP and thus use block mapping if possible. */ if (vma_pagesize =3D=3D PAGE_SIZE && !(force_pte || s2_force_noncacheable= )) { - if (fault->is_perm && fault_granule > PAGE_SIZE) - vma_pagesize =3D fault_granule; + if (fault->is_perm && fault->granule > PAGE_SIZE) + vma_pagesize =3D fault->granule; else vma_pagesize =3D transparent_hugepage_adjust(kvm, fault); =20 @@ -1754,10 +1752,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, st= ruct kvm_page_fault *fault) =20 /* * Under the premise of getting a FSC_PERM fault, we just need to relax - * permissions only if vma_pagesize equals fault_granule. Otherwise, + * permissions only if vma_pagesize equals fault->granule. Otherwise, * kvm_pgtable_stage2_map() should be called to change block size. */ - if (fault->is_perm && vma_pagesize =3D=3D fault_granule) { + if (fault->is_perm && vma_pagesize =3D=3D fault->granule) { /* * Drop the SW bits in favour of those stored in the * PTE, which will be preserved. @@ -1806,6 +1804,7 @@ static int __kvm_handle_guest_abort(struct kvm_vcpu *= vcpu, phys_addr_t fault_ipa .write =3D kvm_is_write_fault(vcpu), .exec =3D kvm_vcpu_trap_is_exec_fault(vcpu), .is_perm =3D esr_fsc_is_permission_fault(esr), + .granule =3D esr_fsc_is_permission_fault(esr) ? esr_fsc_perm_fault_granu= le(esr) : 0, }; struct kvm_s2_trans nested_trans; bool writable; --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C84AE2EBDE3 for ; Thu, 21 Aug 2025 21:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810065; cv=none; b=Q9sZduKDWj8IbaySwIYIovd9ah5BtC+SYfFM9Sgdis6Yz9nNlMK/QhTj899+OlWsfeBVMkoEvB63sU+i1vs+XMrhstesBKokpMYuEzETrWUrjhvvnW6J2gMlyvfOk1cQSKrqERG26WByeY7BQjb9OCCiCqLF5APBfrhj0j59G2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810065; c=relaxed/simple; bh=+61MIfhB12OoqxvOVjd5E5G1e4moY0EeyCZxMuVXI2c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=M7VaJvdQ5l6qWbq0U14OvBS9ZFmlbws+LvstM0JgLOBKIFhYBTLz0srfpsslvY3Po38PbYyBVHYwAZHqS6mtLcs3JQrS9eFMTvPZh9//ZkSeqwtgiyKmn8yOwCE2TOhHVPlENML6Eb0ZqdktrYlylxPIANVOY1rrXJFuizzI7DY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R5XsgzO9; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R5XsgzO9" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-323267915ebso2927568a91.1 for ; Thu, 21 Aug 2025 14:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810063; x=1756414863; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=AynODOx7TIbccej4ZjLdZ9RTKEuSncfsehCPn6XLS1g=; b=R5XsgzO9H4uNNwkJ8wrNoLeMkTtiRX93cbSF67qMrObobIlWvZ42vo8e6REG5IqW2O fO2RDue0jUL0+oNZMjS0JD0PhBO4ZPGLlFv6H2OP1lO62oSrIo+qEPuwdIBpK0klsRX5 6KC0Ghn+YZ2TAYJHsWe0VFq2yE2yLdun2xZPEInA6E+F5cZDYCz7amWm6LiWc870lm9a 27xOM/HX5nb2i9popNJnyjwoeI8yyUACLmrn4VLDxiKeHLSUl5jmboazZm3gYl8IBiOA TnQGFLaDVCnOnPfxmgPUk5l5EbO2irwKD5ogFB2dc3EyS6sbUJqAyd0INX5ojDTW5QRT fohg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810063; x=1756414863; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AynODOx7TIbccej4ZjLdZ9RTKEuSncfsehCPn6XLS1g=; b=xUoHa50RUNx9qQN+MITyorLAKLnSUYqDsl96oLyZ3aTFoMR9yIhBaEMi8em8S/JVQI PSPfrdmPE+bT3OkCqOjSOxy4ibxuHU8FLLstFODCMvWNwC3NorkqCo7TDdd/aIFelrDe arjZZKZx5xzCjp9tEakZZDeBRJCyQuOYPVI8jsiW7XwunRkR5XBk3kOWFEom0BzTfOVs lGx2OmQVUVZNkdr037U5sFbsffkFPQanZSRTolPPS+IhrNh7goBwvcg9Kk0IhEegL1I7 o6dxcsRYH33rzO80Pkooo1bc1bx1QuUeJUOjkURBLZGgZEYHUzpsojLGE0rw0uT9oLJ0 5PQQ== X-Forwarded-Encrypted: i=1; AJvYcCXm7vuKfk7wcyhXMtmJeQA/7Wr4rxNeXDKpkIVnIbpuGDcSUngU11F006vojGFPfyfTYnE+Dz7/Uhi9IMY=@vger.kernel.org X-Gm-Message-State: AOJu0YyIm7vbltT00TrPFcu95VVes7wzog7FfE56NYRWHWTQjhizHLjS NaOadCtO58GP7xBPvBvCQxrJfA9CeTV+X7NpCNTb7jWnNy99+8y3jPV33y5ONqt1HQkXGCWjxIl 1J/Md+A== X-Google-Smtp-Source: AGHT+IEVYwl5YEkw1vqENiDixKFNtOSSF5og6sdGONTLhDTmarsazTWsy/GXacXJvdeMD+BKnVg4vh8e0tk= X-Received: from pjbsd14.prod.google.com ([2002:a17:90b:514e:b0:321:78e7:57fb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1b4c:b0:31e:d929:5ca5 with SMTP id 98e67ed59e1d1-32515e2230emr1041388a91.1.1755810063041; Thu, 21 Aug 2025 14:01:03 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:36 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-11-seanjc@google.com> Subject: [RFC PATCH 10/16] KVM: arm64: Drop local vfio_allow_any_uc, use vm_flags snapshot From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop user_mem_abort()'s local vfio_allow_any_uc variable and instead use the vm_flags snapshot. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 10c73494d505..e1375296940b 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1476,7 +1476,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) int ret =3D 0; bool writable, force_pte =3D false; bool mte_allowed, is_vma_cacheable; - bool s2_force_noncacheable =3D false, vfio_allow_any_uc =3D false; + bool s2_force_noncacheable =3D false; unsigned long mmu_seq; struct kvm *kvm =3D vcpu->kvm; struct vm_area_struct *vma; @@ -1608,8 +1608,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) fault->gfn =3D fault->ipa >> PAGE_SHIFT; mte_allowed =3D kvm_vma_mte_allowed(vma); =20 - vfio_allow_any_uc =3D vma->vm_flags & VM_ALLOW_ANY_UNCACHED; - vm_flags =3D vma->vm_flags; =20 is_vma_cacheable =3D kvm_vma_is_cacheable(vma); @@ -1741,7 +1739,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) prot |=3D KVM_PGTABLE_PROT_X; =20 if (s2_force_noncacheable) { - if (vfio_allow_any_uc) + if (vm_flags & VM_ALLOW_ANY_UNCACHED) prot |=3D KVM_PGTABLE_PROT_NORMAL_NC; else prot |=3D KVM_PGTABLE_PROT_DEVICE; --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71FB62ECD2E for ; Thu, 21 Aug 2025 21:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810067; cv=none; b=k+50tU3s1WiLzYZogMXNeHXsZcXz6PmG5mfmoKUhh4A73AwYtKgEudQcVUdLyg6ulR86cnGtUudS01b64NVU//GHzHmYTct/6oMyXcVAgYoULb9Tbux1NVt+k214srCpxQqU9d62f7HNlzUBbiHNGrpepZkgug2e7grY8/HEOfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810067; c=relaxed/simple; bh=6TQp1XTfTlSOYUWOIWGmda/8IL4quEzAyAn5KTiu3gY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W6AMA/qOHx5BIYA6orFEegzky/04sWze35Xbs/lgxitiDK+6P9z4YtN3LiKCChkLrj84STzdrdNNBPYKkdzdl0r03ZciTDmzbvTDbOPe0o/P4sFd3YU+SsLmaXxEeUzGc2NtLyVic7x/FSQ9dNuh7Vf552lU6IYpcqDrem4PVMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ReqCBufE; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ReqCBufE" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-324e349ef5fso1576930a91.3 for ; Thu, 21 Aug 2025 14:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810065; x=1756414865; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=l3aBAqBLvvziXAff3l7qHBrH3ii9s2uHCbYHv1XlpUE=; b=ReqCBufEBL+WAS3niF0MGbH5VOX7BmmiO2G2jtbbk2aWb594Y7a0AosIGfQ+f8D9ZC aMQs1VflvZ7fgDgf62xs0h9sPz8DvmXJ9AHQ5GW5R7LzKFAWUjVZs8wN5cHqHTgaPuiW nFM08jBBbDBNIwXwhQ9wz7g34PUIQ8kB6VL7pHZbZQe6WaU+c/AdIolcIi9DZSZ9cH+w aCof68ZJTTKk0jTyxiQV/x+eeiWa5Iub3Z1eucH96MxUxvjPpeEcjpPv+p8s4elil2ht 6wVIY5HARim2kDas9E1+H2Uw6wd5+uVxI4hE//Xc2WefZCWYO+L0zh81X2N4Eh4GVg81 P+9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810065; x=1756414865; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=l3aBAqBLvvziXAff3l7qHBrH3ii9s2uHCbYHv1XlpUE=; b=WLpjU9AnHKuG/xpd4FFUJ4X87Q1A6j0iSDh87VNs2msSF+yEXrypgWG25NM9FNaI86 MhC6hBTnRp4ooP0nsHS298WD6DOB5/uQtlke66FeGlyGUfdunzuwyDO6aNPRP2EQzyhU Mon/Wtpxdk4FtS5c0FPQ/k7p54+2FHDCdnFvm2JqGb7mNKoBp9uYNV/vk+DUUHeHhmj5 Bhv9AVADLQ5Bv+aYqfkRHP7knXGM0hLCvpiYhjyQ+xPmiVg5Hi6MYV7t0qG08dGhor24 9npNF1kcgndwfmGnJjfZ5DcnElnMQa/q3jlNNvF5Oxg4jlmtoulrl3ooiyShjoFRFFpo j4PQ== X-Forwarded-Encrypted: i=1; AJvYcCWgr7FThhXud9Ja4588hWcD7jTPXNE6bu8IeClQTUUxVFk1tzsNt3BDTtVZsNRndy92CnuAt0IKLoPDg3c=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+9rsWM484LqHGtmfIOCq6IzWZd3bPSDlU/Le2tdmduS935Im9 wyi+ncQTNftq9OgDaZLBLqXmOEB4w8RLeKbiDQddta63QTc5Xdj+5eYeEU0j14RmUuHI2YsqyKY I0WaF3w== X-Google-Smtp-Source: AGHT+IHyv2vSy5H3gPx/CMXMIii4nN/TDg0JEF0C1pJibiyBy90Nx8cGqdPBlytbuWHgL7DJUzJnyJ3Kweo= X-Received: from pjbee11.prod.google.com ([2002:a17:90a:fc4b:b0:312:187d:382d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2c87:b0:324:ec53:1385 with SMTP id 98e67ed59e1d1-32515e36b2emr1212430a91.10.1755810064638; Thu, 21 Aug 2025 14:01:04 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:37 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-12-seanjc@google.com> Subject: [RFC PATCH 11/16] KVM: arm64: Drop local mte_allowed, use vm_flags snapshot From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop user_mem_abort()'s local mte_allowed and instead use the vm_flags snapshot. The redundant variables aren't problematic per se, but will be quite awkward when a future change moves the vm_flags snapshot into "struct kvm_page_fault". Opportunistically drop kvm_vma_mte_allowed() and open code the vm_flags check in the memslot preparation code, as there's little value in hiding VM_MTE_ALLOWED (arguably negative "value), and the fault path can't use the VMA-based helper (because looking at the VMA outside of mmap_lock is unsafe). No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index e1375296940b..b85968019dd4 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1454,11 +1454,6 @@ static void sanitise_mte_tags(struct kvm *kvm, kvm_p= fn_t pfn, } } =20 -static bool kvm_vma_mte_allowed(struct vm_area_struct *vma) -{ - return vma->vm_flags & VM_MTE_ALLOWED; -} - static bool kvm_vma_is_cacheable(struct vm_area_struct *vma) { switch (FIELD_GET(PTE_ATTRINDX_MASK, pgprot_val(vma->vm_page_prot))) { @@ -1475,7 +1470,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) { int ret =3D 0; bool writable, force_pte =3D false; - bool mte_allowed, is_vma_cacheable; + bool is_vma_cacheable; bool s2_force_noncacheable =3D false; unsigned long mmu_seq; struct kvm *kvm =3D vcpu->kvm; @@ -1606,7 +1601,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) } =20 fault->gfn =3D fault->ipa >> PAGE_SHIFT; - mte_allowed =3D kvm_vma_mte_allowed(vma); =20 vm_flags =3D vma->vm_flags; =20 @@ -1724,7 +1718,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) =20 if (!fault->is_perm && !s2_force_noncacheable && kvm_has_mte(kvm)) { /* Check the VMM hasn't introduced a new disallowed VMA */ - if (mte_allowed) { + if (vm_flags & VM_MTE_ALLOWED) { sanitise_mte_tags(kvm, fault->pfn, vma_pagesize); } else { ret =3D -EFAULT; @@ -2215,7 +2209,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, if (!vma) break; =20 - if (kvm_has_mte(kvm) && !kvm_vma_mte_allowed(vma)) { + if (kvm_has_mte(kvm) && !(vma->vm_flags & VM_MTE_ALLOWED)) { ret =3D -EINVAL; break; } --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24C782ECEA7 for ; Thu, 21 Aug 2025 21:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810068; cv=none; b=lV16HhQL47ENc5VhQZDYTMoEeRl/nR5ILXCYsKkwW4W2UX95zm9MIyy9ijkL8l48qoeFADpU0DUaJFE82kULKuF+hj1y7CeWpTrMtSk4tX4ezKMTvsWwfoCKfy8mSGme9E5XNaxIV/oRZNmqYimH1q1/WoQQwyy/lREH2H969yU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810068; c=relaxed/simple; bh=nhSJVCmpiZAnQ9J/ToSaIbV5daafVSbDeh26hRnQmc4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JcYV5b98MVCTGttwBVB8PE6b4MT17K0co5UNkdA/YU2XtqRes14sRVyQUaqeN8K7YUV9D4K0aODDOtshmMkg6hHfS3UdWgnMmiUZ1RhxdEpTIrfT7KMuicDI0j4gJL6owGwbBmyVgSKf//UP3iA58rbjJhXnprNmj5BBFOrYDu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bLwIujHE; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bLwIujHE" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-323267b6c8eso2697159a91.1 for ; Thu, 21 Aug 2025 14:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810066; x=1756414866; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=t56KCQK2GXd4bcu8tEhPvChuR1HmDcWVAdoQ7kOw4Pg=; b=bLwIujHEQxjuhODJHMKxNJYRe00I4zBqyfKpsaKuSrhOXivLwTl/YTbF9b8OrczvKx k5cLCRP4OOP9AwMcUbMNX0psQzvOk/+pwKFGIcmegqQ/8sb4xwOOuyHY+Nwum91ZHvFN BAUOwtryUMlLjww1lIizsKzXf8+Qi8YoKTJn64GDTePzH+aiIih08AOZexT6md8E2k1X rswwSFIV28NYDwKweEL6oIRPAO+dA9lPWFAR6AwHdeXeUQH4cKiPoZsENMgMeCHGiFgX o+QT0LOQupS77lVTMzJTd/FqYw+053HplpkLSbVscNPzXgY3yAj/sgQ3owA+iXqG/rAp itqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810066; x=1756414866; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t56KCQK2GXd4bcu8tEhPvChuR1HmDcWVAdoQ7kOw4Pg=; b=VYxGoJMdF67aGMrjNHnDbGUb4FNLonc5sjScN5HHbgbO6TSRKaWL+O2i88lTpVwj+D fnvllkiQi2kJDVGLcHJLCaTYL0ooEeCRQDUZTXr0OVyCcuoZhNOWn4eopLWKdVQ5IPLG trp2oa64b9U6teeYJF4J5c5RD8bKJ8wvxZd6VN+t3Si85gce/d2jQxHvf0U0uNw/t1in UtbM/dXX8h4e5S7n8K/ttEb6Dddc+jzDImFuxYuBV9e6WMQvnq9qEgR+c3javAPbloQc cYL6kly7qwHhFzGEyrEXbrXlsbxejpovuClsKZ2d+DvC1qZFZ+iov4tqcR6UFKKfDN2W co7Q== X-Forwarded-Encrypted: i=1; AJvYcCV5a+1e8uX+o9ngwYh0Dwf1GRIKhUj0sY+IpQ3qtF0eyLTT4wyFM2S9GlCg2FHnB1nlR7kymlUl732I0fE=@vger.kernel.org X-Gm-Message-State: AOJu0YztJtiMCSfrMFOF0wxMdS88TEmp79FexA6bSQiBv8BXWNpochgb NBUOXQj1I3rDtpCv3MRI3tTMx7poUYhsoFBoNMlSgccHqHmDKzMndBQ0k0or5aNl971SXMFADrL FxEZoaw== X-Google-Smtp-Source: AGHT+IHw3LANQDrDBKlkNtf6KJxEKR/eCogvGRPA0UduHlT9s+jfszYqmwrEB+leKuJDHCpQZAg5jVQxoNk= X-Received: from pjbof13.prod.google.com ([2002:a17:90b:39cd:b0:31f:6a10:6ea6]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:17d2:b0:311:f684:d3cd with SMTP id 98e67ed59e1d1-32515ef7240mr1204526a91.12.1755810066413; Thu, 21 Aug 2025 14:01:06 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:38 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-13-seanjc@google.com> Subject: [RFC PATCH 12/16] KVM: arm64: Move VMA-related information into "struct kvm_page_fault" From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Stash the "outputs" from parsing the VMA associated with an abort in kvm_page_fault. This will allow moving the mmap_lock-protected section to a separate helper without needing a pile of out-parameters. Deliberately place "pagesize" outside of the "vma" sub-structure, as KVM manipulates (restricts) the pagesize based on other state, i.e. it's not a strict representation of the VMA. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 9 +++++ arch/arm64/kvm/mmu.c | 67 +++++++++++++++---------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index ec6473007fb9..4d131be08d8d 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -430,6 +430,15 @@ struct kvm_page_fault { unsigned long hva; kvm_pfn_t pfn; struct page *page; + + struct { + vm_flags_t vm_flags; + short pageshift; + + bool is_cacheable; + } vma; + + long pagesize; }; =20 /* diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index b85968019dd4..aa6ee72bef51 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1470,18 +1470,14 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, st= ruct kvm_page_fault *fault) { int ret =3D 0; bool writable, force_pte =3D false; - bool is_vma_cacheable; bool s2_force_noncacheable =3D false; unsigned long mmu_seq; struct kvm *kvm =3D vcpu->kvm; struct vm_area_struct *vma; - short vma_shift; void *memcache; bool logging_active =3D memslot_is_logging(fault->slot); - long vma_pagesize; enum kvm_pgtable_prot prot =3D KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; - vm_flags_t vm_flags; enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_HANDLE_FAULT | KVM= _PGTABLE_WALK_SHARED; =20 VM_BUG_ON(fault->write && fault->exec); @@ -1532,12 +1528,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, st= ruct kvm_page_fault *fault) */ if (logging_active) { force_pte =3D true; - vma_shift =3D PAGE_SHIFT; + fault->vma.pageshift =3D PAGE_SHIFT; } else { - vma_shift =3D get_vma_page_shift(vma, fault->hva); + fault->vma.pageshift =3D get_vma_page_shift(vma, fault->hva); } =20 - switch (vma_shift) { + switch (fault->vma.pageshift) { #ifndef __PAGETABLE_PMD_FOLDED case PUD_SHIFT: if (fault_supports_stage2_huge_mapping(fault, PUD_SIZE)) @@ -1545,23 +1541,23 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, st= ruct kvm_page_fault *fault) fallthrough; #endif case CONT_PMD_SHIFT: - vma_shift =3D PMD_SHIFT; + fault->vma.pageshift =3D PMD_SHIFT; fallthrough; case PMD_SHIFT: if (fault_supports_stage2_huge_mapping(fault, PMD_SIZE)) break; fallthrough; case CONT_PTE_SHIFT: - vma_shift =3D PAGE_SHIFT; + fault->vma.pageshift =3D PAGE_SHIFT; force_pte =3D true; fallthrough; case PAGE_SHIFT: break; default: - WARN_ONCE(1, "Unknown vma_shift %d", vma_shift); + WARN_ONCE(1, "Unknown VMA page shift %d", fault->vma.pageshift); } =20 - vma_pagesize =3D 1UL << vma_shift; + fault->pagesize =3D 1UL << fault->vma.pageshift; =20 if (fault->nested) { unsigned long max_map_size; @@ -1587,7 +1583,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) max_map_size =3D PAGE_SIZE; =20 force_pte =3D (max_map_size =3D=3D PAGE_SIZE); - vma_pagesize =3D min(vma_pagesize, (long)max_map_size); + fault->pagesize =3D min(fault->pagesize, (long)max_map_size); } =20 /* @@ -1595,16 +1591,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, st= ruct kvm_page_fault *fault) * ensure we find the right PFN and lay down the mapping in the right * place. */ - if (vma_pagesize =3D=3D PMD_SIZE || vma_pagesize =3D=3D PUD_SIZE) { - fault->fault_ipa &=3D ~(vma_pagesize - 1); - fault->ipa &=3D ~(vma_pagesize - 1); + if (fault->pagesize =3D=3D PMD_SIZE || fault->pagesize =3D=3D PUD_SIZE) { + fault->fault_ipa &=3D ~(fault->pagesize - 1); + fault->ipa &=3D ~(fault->pagesize - 1); } =20 fault->gfn =3D fault->ipa >> PAGE_SHIFT; =20 - vm_flags =3D vma->vm_flags; - - is_vma_cacheable =3D kvm_vma_is_cacheable(vma); + fault->vma.vm_flags =3D vma->vm_flags; + fault->vma.is_cacheable =3D kvm_vma_is_cacheable(vma); =20 /* Don't use the VMA after the unlock -- it may have vanished */ vma =3D NULL; @@ -1624,7 +1619,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) fault->write ? FOLL_WRITE : 0, &writable, &fault->page); if (fault->pfn =3D=3D KVM_PFN_ERR_HWPOISON) { - kvm_send_hwpoison_signal(fault->hva, vma_shift); + kvm_send_hwpoison_signal(fault->hva, fault->vma.pageshift); return 0; } if (is_error_noslot_pfn(fault->pfn)) @@ -1634,8 +1629,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) * Check if this is non-struct page memory PFN, and cannot support * CMOs. It could potentially be unsafe to access as cachable. */ - if (vm_flags & (VM_PFNMAP | VM_MIXEDMAP) && !pfn_is_map_memory(fault->pfn= )) { - if (is_vma_cacheable) { + if (fault->vma.vm_flags & (VM_PFNMAP | VM_MIXEDMAP) && + !pfn_is_map_memory(fault->pfn)) { + if (fault->vma.is_cacheable) { /* * Whilst the VMA owner expects cacheable mapping to this * PFN, hardware also has to support the FWB and CACHE DIC @@ -1653,9 +1649,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) } else { /* * If the page was identified as device early by looking at - * the VMA flags, vma_pagesize is already representing the + * the VMA flags, fualt->pagesize is already representing the * largest quantity we can map. If instead it was mapped - * via __kvm_faultin_pfn(), vma_pagesize is set to PAGE_SIZE + * via __kvm_faultin_pfn(), fualt->pagesize is set to PAGE_SIZE * and must not be upgraded. * * In both cases, we don't let transparent_hugepage_adjust() @@ -1704,22 +1700,22 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, st= ruct kvm_page_fault *fault) * If we are not forced to use page mapping, check if we are * backed by a THP and thus use block mapping if possible. */ - if (vma_pagesize =3D=3D PAGE_SIZE && !(force_pte || s2_force_noncacheable= )) { + if (fault->pagesize =3D=3D PAGE_SIZE && !(force_pte || s2_force_noncachea= ble)) { if (fault->is_perm && fault->granule > PAGE_SIZE) - vma_pagesize =3D fault->granule; + fault->pagesize =3D fault->granule; else - vma_pagesize =3D transparent_hugepage_adjust(kvm, fault); + fault->pagesize =3D transparent_hugepage_adjust(kvm, fault); =20 - if (vma_pagesize < 0) { - ret =3D vma_pagesize; + if (fault->pagesize < 0) { + ret =3D fault->pagesize; goto out_unlock; } } =20 if (!fault->is_perm && !s2_force_noncacheable && kvm_has_mte(kvm)) { /* Check the VMM hasn't introduced a new disallowed VMA */ - if (vm_flags & VM_MTE_ALLOWED) { - sanitise_mte_tags(kvm, fault->pfn, vma_pagesize); + if (fault->vma.vm_flags & VM_MTE_ALLOWED) { + sanitise_mte_tags(kvm, fault->pfn, fault->pagesize); } else { ret =3D -EFAULT; goto out_unlock; @@ -1733,7 +1729,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) prot |=3D KVM_PGTABLE_PROT_X; =20 if (s2_force_noncacheable) { - if (vm_flags & VM_ALLOW_ANY_UNCACHED) + if (fault->vma.vm_flags & VM_ALLOW_ANY_UNCACHED) prot |=3D KVM_PGTABLE_PROT_NORMAL_NC; else prot |=3D KVM_PGTABLE_PROT_DEVICE; @@ -1747,7 +1743,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) * permissions only if vma_pagesize equals fault->granule. Otherwise, * kvm_pgtable_stage2_map() should be called to change block size. */ - if (fault->is_perm && vma_pagesize =3D=3D fault->granule) { + if (fault->is_perm && fault->pagesize =3D=3D fault->granule) { /* * Drop the SW bits in favour of those stored in the * PTE, which will be preserved. @@ -1755,9 +1751,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, str= uct kvm_page_fault *fault) prot &=3D ~KVM_NV_GUEST_MAP_SZ; ret =3D KVM_PGT_FN(kvm_pgtable_stage2_relax_perms)(pgt, fault->fault_ipa= , prot, flags); } else { - ret =3D KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, fault->fault_ipa, vma_pa= gesize, - __pfn_to_phys(fault->pfn), prot, - memcache, flags); + ret =3D KVM_PGT_FN(kvm_pgtable_stage2_map)(pgt, fault->fault_ipa, + fault->pagesize, + __pfn_to_phys(fault->pfn), + prot, memcache, flags); } =20 out_unlock: --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07CAC2FC019 for ; Thu, 21 Aug 2025 21:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810070; cv=none; b=dhIwCV0FBrZ3tsWhuZKUQPUcoxVPCF7sWW6Z3pRYPjih7Tjr0mhee8+14eP7WTeFfll2Dk4gj4ZeEZa/jgxgMcDrw4InJxzXUHZa1MOiM7A+CjaNlzuwuB50rjTK3uTqu3YCQQNpsALTMAXUHjBZgVo+nrKcohBg1CWkjyUzywc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810070; c=relaxed/simple; bh=/rGauErIcEbTihd1kj9EqXKbfxEybfai2HJzASnlsiA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XsNqPojaDLsDa3fRWG3fXtFSqV+vI10+iJY4LFnFOYWumPm/LLcH6ZphywE0IMOZ5cupwdX+nqqTsawFsh9GJ2pRTxeeOtAvGPRgD0HIxQJ/raTMal/EVb6EqUDfnMtJSBCp6gc4mHQ43GIeSvZ/WlXEMCJ95f54kznn28iPvpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=C8kRdhxr; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="C8kRdhxr" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2430c5d4d73so30800355ad.1 for ; Thu, 21 Aug 2025 14:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810068; x=1756414868; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=icfTHb8SQC6RmkA9MWOb7kih1+f1PvZwwwoiEq7I/xQ=; b=C8kRdhxr1I3j6M52akPXOoBvk5YsSCvMpvVl6rEz78vkoi7O0Q/dkK/9ovnumw3D8j sADmJjjaOO7emsvod2l6ax91NqFTns3L0NWBHCw66dy8GDgWtKWfHrfBa8XqTv40aoug dPrf3K3ZZAAR3AjIoW/1joHY9tvAqzxtLbWfoRjqkrMplw0vO1LT3J0D9ZzCNDmo9rBq UBjZpVqC/KlNe5ez5DUssmksons4BO+GJI2aoXcBKUOFRLTwschi8MoTt/DPu/S0e92l 2WGvNbHDdZXc986Uird38U6sfwkizHHeRVsKag28vkTimhPVMmmIzAO9YQcnpmWQxcQx l8Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810068; x=1756414868; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=icfTHb8SQC6RmkA9MWOb7kih1+f1PvZwwwoiEq7I/xQ=; b=bmeIkQrVNKJ08Hs5YK7ORwsqGrUJAx+g0+hRZNGcbPd/NXxYtyydHAtOfq1A4tJc41 AvvAEwwwJLvwD6wFeX00GrbxY7jXgkwEWDIlOiuv6pN0ReHINMGEUf/WgJiSkrA+rBFw d6gz6tm+QqToIpye5bRajuF1LB4U0en2JpIdLAHil6KHB4oDMwQ03X6HfcZ5cidy9G98 sFnjta02h1gi1U/8yopp8wSqnlq4uUVRwhCmQXxVPaG10vm/QA8fae/2R7PW5GO6bYq3 j2xwluSCz+HA4guSU+waCl6zRGH44/b1kF5i32FlwezAUl1l28mFLrmJJ3akC1J052vF oJAA== X-Forwarded-Encrypted: i=1; AJvYcCVL4PFPFpWOEewznKamb8qxeIJA3BFiQ80DHTCZcjD3jLqwPGxxzaU2ZM5hLArtHgLwDZ0bWzdHvn6WA6k=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9wKy5h5B2URetMTju95d5A1YJrj+yFlnG3rJ7Zi8qiOjc57QX LX+CqZpWnqokMHJhnYE6USU/mh5LHGhqZe5tQbNaWyt2NaLTvDu3rPimrXeJhK8FvmBxix8Qwq/ 6DEkb6A== X-Google-Smtp-Source: AGHT+IGG1PqwX+83Kz6lqMiL38vZquJagXjtigRLo1tbtN6yx1WhHPa1mZrTLmDFk+AuwMqOxdw4+SZNGP8= X-Received: from pjx7.prod.google.com ([2002:a17:90b:5687:b0:311:ef56:7694]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1a68:b0:233:d3e7:6fd6 with SMTP id d9443c01a7336-2460248450emr47706545ad.19.1755810068184; Thu, 21 Aug 2025 14:01:08 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:39 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-14-seanjc@google.com> Subject: [RFC PATCH 13/16] KVM: arm64: Stash "mmu_seq" in "struct kvm_page_fault" From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Track the MMU notifier sequence count snapshot in "struct kvm_page_fault" in anticipation of moving the mmap_lock-protected code to a separate helper. Attaching mmu_seq to the fault could also prove useful in the future, e.g. for additional refactorings. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/mmu.c | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index 4d131be08d8d..6a99f7fa065d 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -430,6 +430,7 @@ struct kvm_page_fault { unsigned long hva; kvm_pfn_t pfn; struct page *page; + unsigned long mmu_seq; =20 struct { vm_flags_t vm_flags; diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index aa6ee72bef51..575a4f9f2583 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1471,7 +1471,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) int ret =3D 0; bool writable, force_pte =3D false; bool s2_force_noncacheable =3D false; - unsigned long mmu_seq; struct kvm *kvm =3D vcpu->kvm; struct vm_area_struct *vma; void *memcache; @@ -1612,7 +1611,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) * Rely on mmap_read_unlock() for an implicit smp_rmb(), which pairs * with the smp_wmb() in kvm_mmu_invalidate_end(). */ - mmu_seq =3D vcpu->kvm->mmu_invalidate_seq; + fault->mmu_seq =3D vcpu->kvm->mmu_invalidate_seq; mmap_read_unlock(current->mm); =20 fault->pfn =3D __kvm_faultin_pfn(fault->slot, fault->gfn, @@ -1691,7 +1690,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) =20 kvm_fault_lock(kvm); pgt =3D vcpu->arch.hw_mmu->pgt; - if (mmu_invalidate_retry(kvm, mmu_seq)) { + if (mmu_invalidate_retry(kvm, fault->mmu_seq)) { ret =3D -EAGAIN; goto out_unlock; } --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A85C2C026D for ; Thu, 21 Aug 2025 21:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810072; cv=none; b=UY93mBaXyWXIm5E8yn4D32JiHN2pDKCNWD+Ocb5ESaID49ItvQfMj7z14w9tUZmsTGUApO0OAQhv1inv9vdvyfWS5qu7ygSYvEuAf8tNRKmOfbsrl8X6+pO3HlSjV/6CLpK2tQ/ba+6VU21PNHoGfpBRGpBJjQzh2xLJPjhjW2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810072; c=relaxed/simple; bh=AoW4m6UY7aQpJgkdXNQBDrHg3vmPuYVWlkUo96wIdqA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HBudtytopkt3Aa5TTeg+9Tz6KJD2MFEArn2IIgoX+m2A/fpJR6DJYp5CXXRV0RF1E5qgS7O8TRqjuwbOPnKLvidJKnYcrmobfP6QA206L3QQ9YkqALo6KAUOdpWrJLH6ueXQP7Aw8w4c1BFIyGHSTG1R3lwAWugHC8Q7aQaCrBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nJo7NxJ/; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nJo7NxJ/" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-76e2e614889so1444369b3a.0 for ; Thu, 21 Aug 2025 14:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810070; x=1756414870; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=fxt6rTMqHrWA9f8ahxcPmdPJmqaCbIUP8K6s+gPHJdY=; b=nJo7NxJ/bsOTzL5lzquvb6MWEF1YuFVvCgvSItY//GWwt0d7apAHT46qD70qaDMBQY 7bi3VIfMzfNPfX69qZtlwgUc8hlTMOtWyeYf5dtqebg4Yh0s0EvDkp8rl6rDYXudhVMK i3q5NAwK0NbliM/gPzuoeznHeIIydZ7iF0ktmoLTx0G882NbIyWP5aloDCt1+W/jkYSq G+Dp9EHUUnzctbO3IMJSUdvQtlC8CfT4819kc101qAvEYPAmE4pnTyuCtNzUUZ4u4/16 t+WQGupAcHNjDkACcktbqgO/WxNjte5rkJ37m3q590ly7609Mla8Dmf2ZsDRlen18U9K 02kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810070; x=1756414870; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fxt6rTMqHrWA9f8ahxcPmdPJmqaCbIUP8K6s+gPHJdY=; b=iFIecWWSSZf/1uiRV9lHVWppC39S6bLkin7NoZBlqbJxTAgxOsUWBR8Mmvhol/AyAM 8pPJaa62w5qU7p1SZ9pOAv/GA9p3/5PfHOeoc5CKdpYBvv4gfvsC9Ke6QF6Jv55gNRsN 4a1CcAG6jqo9fy9qjxIlLVRXk9XqjQ+D+1OI40rhTNqo1HpVtCc9dlGzppSWFxjysQw4 E55AILD/UUmJsmjYkcJozkqEpUX5QaHX5/FBY84ZovI1+o9g931XVOJjquId7VUbxLko L1CfzPOyHu6nA4FlI23oTo8Kjl73VBkP5mHrpVNYA06tc2wL+XPoFenPL4vigaD9zRrB 5Y4w== X-Forwarded-Encrypted: i=1; AJvYcCXY4X0KCV4Mfh4L/0F6Rb3CmoNFkZFIlb7mpvoCgBU0JyvEf5c5fDfYiOl4pDkEvOZkiYEOn6vQRnQsP6o=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4ZslReGy2xKQteJ/C0i9xd9A98BcY3Fn4YJ+a0ybVUlgXV0JK uiiNK8R1YzfrJt+aVYpv+sWpZdZQkpv2uCs84IyWgJevzlnWl3y8hxpeppD/oyW4fUyDCKuFSQY f44ilaA== X-Google-Smtp-Source: AGHT+IFn+EYj/FE0ePzblUKFMdEC+BFGAdYI0PBx7I9mvhQoZZjMBZ5mHJyHtUrO2Tk/q3sQHu7NuwUXWEg= X-Received: from pfbbd13.prod.google.com ([2002:a05:6a00:278d:b0:76e:8abf:185a]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7489:b0:240:130e:d781 with SMTP id adf61e73a8af0-24340c10ac7mr756815637.17.1755810069751; Thu, 21 Aug 2025 14:01:09 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:40 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-15-seanjc@google.com> Subject: [RFC PATCH 14/16] KVM: arm64: Track "forced" information in "struct kvm_page_fault" From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the abort handler's local "force_pte" and "s2_force_noncacheable" variables into "struct kvm_page_fault" in anticipation of moving the mmap_lock-protected code to a separate helper. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/mmu.c | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index 6a99f7fa065d..fa52546bf870 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -440,6 +440,9 @@ struct kvm_page_fault { } vma; =20 long pagesize; + + bool force_pte; + bool s2_force_noncacheable; }; =20 /* diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 575a4f9f2583..fec3a6aeabd0 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1469,8 +1469,7 @@ static bool kvm_vma_is_cacheable(struct vm_area_struc= t *vma) static int user_mem_abort(struct kvm_vcpu *vcpu, struct kvm_page_fault *fa= ult) { int ret =3D 0; - bool writable, force_pte =3D false; - bool s2_force_noncacheable =3D false; + bool writable; struct kvm *kvm =3D vcpu->kvm; struct vm_area_struct *vma; void *memcache; @@ -1526,7 +1525,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) * memslots. */ if (logging_active) { - force_pte =3D true; + fault->force_pte =3D true; fault->vma.pageshift =3D PAGE_SHIFT; } else { fault->vma.pageshift =3D get_vma_page_shift(vma, fault->hva); @@ -1548,7 +1547,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) fallthrough; case CONT_PTE_SHIFT: fault->vma.pageshift =3D PAGE_SHIFT; - force_pte =3D true; + fault->force_pte =3D true; fallthrough; case PAGE_SHIFT: break; @@ -1561,7 +1560,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) if (fault->nested) { unsigned long max_map_size; =20 - max_map_size =3D force_pte ? PAGE_SIZE : PUD_SIZE; + max_map_size =3D fault->force_pte ? PAGE_SIZE : PUD_SIZE; =20 WARN_ON_ONCE(fault->ipa !=3D kvm_s2_trans_output(fault->nested)); =20 @@ -1581,7 +1580,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) else if (max_map_size >=3D PAGE_SIZE && max_map_size < PMD_SIZE) max_map_size =3D PAGE_SIZE; =20 - force_pte =3D (max_map_size =3D=3D PAGE_SIZE); + fault->force_pte =3D (max_map_size =3D=3D PAGE_SIZE); fault->pagesize =3D min(fault->pagesize, (long)max_map_size); } =20 @@ -1656,7 +1655,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) * In both cases, we don't let transparent_hugepage_adjust() * change things at the last minute. */ - s2_force_noncacheable =3D true; + fault->s2_force_noncacheable =3D true; } } else if (logging_active && !fault->write) { /* @@ -1666,7 +1665,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) writable =3D false; } =20 - if (fault->exec && s2_force_noncacheable) + if (fault->exec && fault->s2_force_noncacheable) return -ENOEXEC; =20 /* @@ -1699,7 +1698,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) * If we are not forced to use page mapping, check if we are * backed by a THP and thus use block mapping if possible. */ - if (fault->pagesize =3D=3D PAGE_SIZE && !(force_pte || s2_force_noncachea= ble)) { + if (fault->pagesize =3D=3D PAGE_SIZE && + !(fault->force_pte || fault->s2_force_noncacheable)) { if (fault->is_perm && fault->granule > PAGE_SIZE) fault->pagesize =3D fault->granule; else @@ -1711,7 +1711,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) } } =20 - if (!fault->is_perm && !s2_force_noncacheable && kvm_has_mte(kvm)) { + if (!fault->is_perm && !fault->s2_force_noncacheable && kvm_has_mte(kvm))= { /* Check the VMM hasn't introduced a new disallowed VMA */ if (fault->vma.vm_flags & VM_MTE_ALLOWED) { sanitise_mte_tags(kvm, fault->pfn, fault->pagesize); @@ -1727,7 +1727,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, stru= ct kvm_page_fault *fault) if (fault->exec) prot |=3D KVM_PGTABLE_PROT_X; =20 - if (s2_force_noncacheable) { + if (fault->s2_force_noncacheable) { if (fault->vma.vm_flags & VM_ALLOW_ANY_UNCACHED) prot |=3D KVM_PGTABLE_PROT_NORMAL_NC; else --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72A4B30F80C for ; Thu, 21 Aug 2025 21:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810074; cv=none; b=aZrqWfkuTs4yCyT9PUTL73uDkkE0NK4hUfuD+C9xvwKMDtE2O+mJQReFKCA31OP8W26kzlwP3nQ9qsI/MfBGt+bIowXNsljy+QW8jkXKNAyekzCd/hHzZ13YU05TcAcwLy02C4GChsWa5bOSOFau5FcgriiH9fw4qYxaygwdjp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810074; c=relaxed/simple; bh=wzbsuKcJ4wvLXzApjrI6i7l0No25qC4BNkAFtcIBLxk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aGLpXq0y17t/w++EMwx3Mfo9rvxeRJHWtSVSL/ObYhosfFby5xNQkc5MZcxDNUrsIFt9xeoT/k4znqEncVWywAxw2tMqL0bK0uAo49ZoHVi5W3zc2nicthet7Dwof98ffR9iIFRkSrh5BkDtMFBFEi99RqHvlgAv1z5pEMyFhMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aJuGlz9I; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aJuGlz9I" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-76e364afb44so1171111b3a.3 for ; Thu, 21 Aug 2025 14:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810071; x=1756414871; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=WFOpvpsT1MnunRLl4T+BHRi0vN/i3KJyyI1xXmPrPlw=; b=aJuGlz9I6KiwYRC4JE4wLOGUF8Y1U08JgUYzOvgQzWr1U4pyrjVsLuqwlqXHiHiLoU k4ea5wcq+vY2bie+gYNMDPl1eZJJdHRoL7VunLVuW2DsP82ZmsOUKxaZjMb4T9RBCXuY gVoyDAcfZzstNl5LyxJCmckW8e/nWQvUDxzRjKLiXXdBne9GnHK5vB0v5zMD14EdJ9GA Oe3q7QjsYF7rQhz11UVHgy84GL4xMRvLbwlJdxdQOLUzS3Ty1Esv4oKLSSaxcDYDqlp+ yJnICt0Ae703tV0dfsvGAeohRkkFOk/X9YDkcN55yFmwyCffsfCYmLJUtmZBz8hj0sH8 /JBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810071; x=1756414871; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WFOpvpsT1MnunRLl4T+BHRi0vN/i3KJyyI1xXmPrPlw=; b=wEoy3IQfGYug4JYPMrT3leJDZ0P5coP4du2o9rkofFwWLd3zFsOVvFTbRletRk0L8U 4AJkm99x91HGxvsrjN5mrmQ2AbL6mJtFqCCEp915uc3kuyfPLV3PGIRnvda1vDpoqXhH iYD1+wo6ns6KhE2k10ZMMUxQLygUEYAHXLJHNJ7naSwZJRY0qlOTsngUqhWmw+/E+aKo fQ2rl4SNfbl30RfR8F0a8DTM+ayALSFBhq9VapxKxnxbDOBUHLwVXhW8qFk0HUU/C3D2 ZDtk4L2lesLBjmX82AQKKJMfrtMiebCEjMyyTGi2jlwpgX0GxjyUJbdAMSbftbipek0J XTNg== X-Forwarded-Encrypted: i=1; AJvYcCVv+cig8w6nHzoNue8ddr5UMFy+ibdc3RMZp311B8gBBwJTcBaa5dTM1YaCeQf9h5RTDMDctzmcjBzDd0U=@vger.kernel.org X-Gm-Message-State: AOJu0YwcCSiPdc+ZwHZ7QwEbgclsWMgxlKGWYcITRV/BVuuG1wGFOtYl CLA401f31cPaQVacqilblj3jToYJfcsRlqF/Hauob+iqejGEdcCp3pFIgKMalLIaGbwHz8l9BNl dA3D/dw== X-Google-Smtp-Source: AGHT+IH2D5yvxXbQMYKp9CQ1/YsbKvTYEoUYMROb+eewLnOLV2mjTAu7kJckUk9DqMy3wtdy3hZnzxFFxu8= X-Received: from pghz18.prod.google.com ([2002:a63:e112:0:b0:b42:8a4c:7b14]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2446:b0:240:1fb6:d335 with SMTP id adf61e73a8af0-24340db0419mr735886637.37.1755810071501; Thu, 21 Aug 2025 14:01:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:41 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-16-seanjc@google.com> Subject: [RFC PATCH 15/16] KVM: arm64: Extract mmap_lock-protected code to helper for user mem aborts From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out the mmap_lock-protected portion of user_mem_abort() to a new helper, partly to make user_mem_abort() easier to follow, but mostly so that the scope of the mmap_lock-protected code is more explicitly bounded. No functional change intended. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 96 ++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index fec3a6aeabd0..ea326d66f027 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1466,47 +1466,10 @@ static bool kvm_vma_is_cacheable(struct vm_area_str= uct *vma) } } =20 -static int user_mem_abort(struct kvm_vcpu *vcpu, struct kvm_page_fault *fa= ult) +static int kvm_gather_fault_vma_info(struct kvm_vcpu *vcpu, + struct kvm_page_fault *fault) { - int ret =3D 0; - bool writable; - struct kvm *kvm =3D vcpu->kvm; struct vm_area_struct *vma; - void *memcache; - bool logging_active =3D memslot_is_logging(fault->slot); - enum kvm_pgtable_prot prot =3D KVM_PGTABLE_PROT_R; - struct kvm_pgtable *pgt; - enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_HANDLE_FAULT | KVM= _PGTABLE_WALK_SHARED; - - VM_BUG_ON(fault->write && fault->exec); - - if (fault->is_perm && !fault->write && !fault->exec) { - kvm_err("Unexpected L2 read permission error\n"); - return -EFAULT; - } - - if (!is_protected_kvm_enabled()) - memcache =3D &vcpu->arch.mmu_page_cache; - else - memcache =3D &vcpu->arch.pkvm_memcache; - - /* - * Permission faults just need to update the existing leaf entry, - * and so normally don't require allocations from the memcache. The - * only exception to this is when dirty logging is enabled at runtime - * and a write fault needs to collapse a block entry into a table. - */ - if (!fault->is_perm || (logging_active && fault->write)) { - int min_pages =3D kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu); - - if (!is_protected_kvm_enabled()) - ret =3D kvm_mmu_topup_memory_cache(memcache, min_pages); - else - ret =3D topup_hyp_memcache(memcache, min_pages); - - if (ret) - return ret; - } =20 /* * Let's check if we will get back a huge page backed by hugetlbfs, or @@ -1520,11 +1483,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, str= uct kvm_page_fault *fault) return -EFAULT; } =20 - /* - * logging_active is guaranteed to never be true for VM_PFNMAP - * memslots. - */ - if (logging_active) { + /* Logging is guaranteed to never be active for VM_PFNMAP memslots. */ + if (memslot_is_logging(fault->slot)) { fault->force_pte =3D true; fault->vma.pageshift =3D PAGE_SHIFT; } else { @@ -1613,6 +1573,54 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, str= uct kvm_page_fault *fault) fault->mmu_seq =3D vcpu->kvm->mmu_invalidate_seq; mmap_read_unlock(current->mm); =20 + return 0; +} + +static int user_mem_abort(struct kvm_vcpu *vcpu, struct kvm_page_fault *fa= ult) +{ + int ret =3D 0; + bool writable; + struct kvm *kvm =3D vcpu->kvm; + void *memcache; + bool logging_active =3D memslot_is_logging(fault->slot); + enum kvm_pgtable_prot prot =3D KVM_PGTABLE_PROT_R; + struct kvm_pgtable *pgt; + enum kvm_pgtable_walk_flags flags =3D KVM_PGTABLE_WALK_HANDLE_FAULT | KVM= _PGTABLE_WALK_SHARED; + + VM_BUG_ON(fault->write && fault->exec); + + if (fault->is_perm && !fault->write && !fault->exec) { + kvm_err("Unexpected L2 read permission error\n"); + return -EFAULT; + } + + if (!is_protected_kvm_enabled()) + memcache =3D &vcpu->arch.mmu_page_cache; + else + memcache =3D &vcpu->arch.pkvm_memcache; + + /* + * Permission faults just need to update the existing leaf entry, + * and so normally don't require allocations from the memcache. The + * only exception to this is when dirty logging is enabled at runtime + * and a write fault needs to collapse a block entry into a table. + */ + if (!fault->is_perm || (logging_active && fault->write)) { + int min_pages =3D kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu); + + if (!is_protected_kvm_enabled()) + ret =3D kvm_mmu_topup_memory_cache(memcache, min_pages); + else + ret =3D topup_hyp_memcache(memcache, min_pages); + + if (ret) + return ret; + } + + ret =3D kvm_gather_fault_vma_info(vcpu, fault); + if (ret) + return ret; + fault->pfn =3D __kvm_faultin_pfn(fault->slot, fault->gfn, fault->write ? FOLL_WRITE : 0, &writable, &fault->page); --=20 2.51.0.261.g7ce5a0a67e-goog From nobody Sat Oct 4 00:31:20 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00B153126AE for ; Thu, 21 Aug 2025 21:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810075; cv=none; b=lFUXMc9EiJTle1HzyPqKpz3cbPsBiepizMW0glV/IRQLUS0K/9BytxmelK/aBpalGS8CN6bsedORzGR3K3TgNq/LQ4BBajVbdEzaVMnLnbm8qvxBw9JXDAKPx5ZUXd76qUpKETuCQdewSGamKOJ7McudEQgXzMctQBSptKTHc/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755810075; c=relaxed/simple; bh=ztqVo6NA34foMRWPPxfCFK7i38/nXKR/2OW2xBZ5Cz4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SHzrjVJORoiQw1UYYLsGP5QwHUICmJwQEsyewtPSN5VrlZ9BYAa/+0AN9AE0Q3XdA1AHZ8IUMxtvzvIpeH4+6t9v8tg0leT4WMcFaLQENgeySpOPJfUA1EzSkBouZbyxxRQsvwjZP3D/QHI/3RCUFFMZ5EiFiX3jrQKXa2ZJKog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WNucqRXA; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WNucqRXA" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-324e6a1a414so2224694a91.1 for ; Thu, 21 Aug 2025 14:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755810073; x=1756414873; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=raIzGhW7lpJoGFirZ1c9kEw1ZuKCVqeLv2nD/b2/YKU=; b=WNucqRXA+D/NmIVcXqr1r4b1+BoTMlp5hocSDfx9f72/l5BzLshX3diuS60yz5eeij WDPm/EfFz+3gg2t/YU0brOd4Wp+uvVlLGs2hYaU70vErJDWxcJMA892TayE0lcCc6iMd 1Zsji/Bc8bs6s5ZIhxf1Gu0zFg+HsABd9nTksN7Q40KOsIEifT8GM2Hyso+vumo5T9Fm djsuSlSIjTtwJbrShWqpBzKZ0kxBgV+HUajFIKh9I8nvAI5izVfPijDcGQgzUcC+KK6m k8zHFRl0MrzYe6xFi6WHlsFvQcFxsxA7ihfRGRxo7+YLCPaxteejfAbZW+URJGH+DtXw +SdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755810073; x=1756414873; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=raIzGhW7lpJoGFirZ1c9kEw1ZuKCVqeLv2nD/b2/YKU=; b=LQhgpGrPkIb1hKXCBYe217Np6zJu/P1sP6eoF8Tr+N9jp7eVt2nSpa32jaPMexlYww /aWo262/3Gk7cxAcb7gbKQUM6tdWCfpmjQ0u/Yv3twEP/Fim1mMk+gxTqzZUr9ZOrJ3j KAasH258OoQxCqPNIqntwZYTFi6JgDkhtvZFVBf/kOYZGi6XFS9WumXqpYQ8LehKsAIP Ov1WNcmgdL5v2iyE20NXnUyfSmgVn3TGgHJtjFwCJibcLERDxareqCLr3K8OAtYidf8D jHysnDfe4ODi9zzmY+Ph72A8P5jeUMeOknIimSYBq2jIEgmzkInXgMQGTBYk6aDgythS AgWQ== X-Forwarded-Encrypted: i=1; AJvYcCXIHRJwYfL8FNV+WJDwZsY1xtZBSJmpBfgTPRVyyoXNHEdXiLQ7UMWXWii9hEzNZQp+Bk9ZaEw36zrigfY=@vger.kernel.org X-Gm-Message-State: AOJu0Yyc5/IV7+oiQaU5FVjcDw5zvF5K1R7rKPFOdnxFGPbig4jt60rl aaIi/DYDLRImQgksoD0OzxtsTZtZJXV+/0u10HOXoeO7lXruKllZXi6+gkSUY1NOXQt1plp8WPc Jne5Adw== X-Google-Smtp-Source: AGHT+IFblgzDSGtA8EPOlO44N2jRty+RipPpxQzb/XSsK78s9IItTWN33FoV1VAgZIXu+UmzYrewPt9GIfA= X-Received: from pjgg5.prod.google.com ([2002:a17:90b:57c5:b0:321:76a2:947c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1d4e:b0:321:1348:4438 with SMTP id 98e67ed59e1d1-324eed210damr5152464a91.7.1755810073194; Thu, 21 Aug 2025 14:01:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 21 Aug 2025 14:00:42 -0700 In-Reply-To: <20250821210042.3451147-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250821210042.3451147-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.261.g7ce5a0a67e-goog Message-ID: <20250821210042.3451147-17-seanjc@google.com> Subject: [RFC PATCH 16/16] KVM: arm64: Don't bother nullifying "vma" in mem abort path From: Sean Christopherson To: Marc Zyngier , Oliver Upton Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Sean Christopherson , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the local "vma" in kvm_gather_fault_vma_info() will naturally go out of scope when mmap_lock is dropped, don't bother nullifying the variable. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index ea326d66f027..435582e997ce 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1559,9 +1559,6 @@ static int kvm_gather_fault_vma_info(struct kvm_vcpu = *vcpu, fault->vma.vm_flags =3D vma->vm_flags; fault->vma.is_cacheable =3D kvm_vma_is_cacheable(vma); =20 - /* Don't use the VMA after the unlock -- it may have vanished */ - vma =3D NULL; - /* * Read mmu_invalidate_seq so that KVM can detect if the results of * vma_lookup() or __kvm_faultin_pfn() become stale prior to --=20 2.51.0.261.g7ce5a0a67e-goog