linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	maz@kernel.org, oliver.upton@linux.dev, will@kernel.org,
	joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com,
	catalin.marinas@arm.com, vladimir.murzin@arm.com
Subject: Re: [PATCH v2 5/5] KVM: arm64: Define FAR_MASK for fault IPA offset
Date: Fri, 7 Nov 2025 15:12:17 -0800	[thread overview]
Message-ID: <aQ580W6SU1lGbd_D@kernel.org> (raw)
In-Reply-To: <20251106144418.2847443-6-tabba@google.com>

On Thu, Nov 06, 2025 at 02:44:17PM +0000, Fuad Tabba wrote:
> This 12-bit FAR mask is hard-coded as 'GENMASK(11, 0)' in several places
> to reconstruct the full fault IPA.
> 
> Define FAR_MASK for this value in the shared header and replace all
> open-coded instances to improve readability.
> 
> No functional change intended.
> 
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
>  arch/arm64/include/asm/kvm_arm.h         | 2 ++
>  arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 2 +-
>  arch/arm64/kvm/inject_fault.c            | 2 +-
>  arch/arm64/kvm/mmu.c                     | 4 ++--
>  4 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
> index 1da290aeedce..e995e9b3a0c4 100644
> --- a/arch/arm64/include/asm/kvm_arm.h
> +++ b/arch/arm64/include/asm/kvm_arm.h
> @@ -343,6 +343,8 @@
>  #define PAR_TO_HPFAR(par)		\
>  	(((par) & GENMASK_ULL(52 - 1, 12)) >> 8)
>  
> +#define FAR_MASK GENMASK_ULL(11, 0)
> +

This seems really confusing to me, since FAR_MASK sounds like it
represents the meaningful bits of FAR_ELx. Perhaps something like the
following would better represent intent:

#define FAR_TO_FIPA_OFFSET(far)	((far) & GENMASK_ULL(11, 0))

Thanks,
Oliver

>  #define ECN(x) { ESR_ELx_EC_##x, #x }
>  
>  #define kvm_arm_exception_class \
> diff --git a/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c b/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
> index 78579b31a420..22898ed4dd6f 100644
> --- a/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
> +++ b/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
> @@ -44,7 +44,7 @@ int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
>  
>  	/* Build the full address */
>  	fault_ipa  = kvm_vcpu_get_fault_ipa(vcpu);
> -	fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
> +	fault_ipa |= kvm_vcpu_get_hfar(vcpu) & FAR_MASK;
>  
>  	/* If not for GICV, move on */
>  	if (fault_ipa <  vgic->vgic_cpu_base ||
> diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c
> index dfcd66c65517..8ef3453696a2 100644
> --- a/arch/arm64/kvm/inject_fault.c
> +++ b/arch/arm64/kvm/inject_fault.c
> @@ -258,7 +258,7 @@ void kvm_inject_size_fault(struct kvm_vcpu *vcpu)
>  	unsigned long addr, esr;
>  
>  	addr  = kvm_vcpu_get_fault_ipa(vcpu);
> -	addr |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
> +	addr |= kvm_vcpu_get_hfar(vcpu) & FAR_MASK;
>  
>  	__kvm_inject_sea(vcpu, kvm_vcpu_trap_is_iabt(vcpu), addr);
>  
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 7cc964af8d30..21a9442f9b1e 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -1959,7 +1959,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
>  
>  		/* Falls between the IPA range and the PARange? */
>  		if (fault_ipa >= BIT_ULL(VTCR_EL2_IPA(vcpu->arch.hw_mmu->vtcr))) {
> -			fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
> +			fault_ipa |= kvm_vcpu_get_hfar(vcpu) & FAR_MASK;
>  
>  			return kvm_inject_sea(vcpu, is_iabt, fault_ipa);
>  		}
> @@ -2059,7 +2059,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
>  		 * faulting VA. This is always 12 bits, irrespective
>  		 * of the page size.
>  		 */
> -		ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
> +		ipa |= kvm_vcpu_get_hfar(vcpu) & FAR_MASK;
>  		ret = io_mem_abort(vcpu, ipa);
>  		goto out_unlock;
>  	}
> -- 
> 2.51.2.1041.gc1ab5b90ca-goog
> 


  reply	other threads:[~2025-11-07 23:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06 14:44 [PATCH v2 0/5] KVM: arm64: Fixes for guest CPU feature trapping and enabling Fuad Tabba
2025-11-06 14:44 ` [PATCH v2 1/5] KVM: arm64: Fix Trace Buffer trapping for protected VMs Fuad Tabba
2025-11-06 16:28   ` Suzuki K Poulose
2025-11-06 14:44 ` [PATCH v2 2/5] KVM: arm64: Fix Trace Buffer trap polarity " Fuad Tabba
2025-11-06 14:44 ` [PATCH v2 3/5] KVM: arm64: Fix MTE flag initialization " Fuad Tabba
2025-11-06 14:44 ` [PATCH v2 4/5] KVM: arm64: Prevent host from managing timer offsets " Fuad Tabba
2025-11-07 23:21   ` Oliver Upton
2025-11-09 19:51     ` Fuad Tabba
2025-11-06 14:44 ` [PATCH v2 5/5] KVM: arm64: Define FAR_MASK for fault IPA offset Fuad Tabba
2025-11-07 23:12   ` Oliver Upton [this message]
2025-11-09 19:51     ` Fuad Tabba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aQ580W6SU1lGbd_D@kernel.org \
    --to=oupton@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=vladimir.murzin@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).