[PATCH v8 19/28] KVM: arm64: Support unaligned fixmap in the pKVM hyp

Vincent Donnefort posted 28 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v8 19/28] KVM: arm64: Support unaligned fixmap in the pKVM hyp
Posted by Vincent Donnefort 1 month, 1 week ago
Return the fixmap VA with the page offset, instead of the page base
address. This allows to use hyp_fixmap_map() seamlessly regardless of
the address alignment.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c
index ae8391baebc3..75014dc7d82e 100644
--- a/arch/arm64/kvm/hyp/nvhe/mm.c
+++ b/arch/arm64/kvm/hyp/nvhe/mm.c
@@ -239,7 +239,7 @@ static void *fixmap_map_slot(struct hyp_fixmap_slot *slot, phys_addr_t phys)
 	WRITE_ONCE(*ptep, pte);
 	dsb(ishst);
 
-	return (void *)slot->addr;
+	return (void *)slot->addr + offset_in_page(phys);
 }
 
 void *hyp_fixmap_map(phys_addr_t phys)
-- 
2.51.2.1041.gc1ab5b90ca-goog
Re: [PATCH v8 19/28] KVM: arm64: Support unaligned fixmap in the pKVM hyp
Posted by Marc Zyngier 1 month ago
On Fri, 07 Nov 2025 09:38:31 +0000,
Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> Return the fixmap VA with the page offset, instead of the page base
> address. This allows to use hyp_fixmap_map() seamlessly regardless of
> the address alignment.
> 
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> 
> diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c
> index ae8391baebc3..75014dc7d82e 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mm.c
> @@ -239,7 +239,7 @@ static void *fixmap_map_slot(struct hyp_fixmap_slot *slot, phys_addr_t phys)
>  	WRITE_ONCE(*ptep, pte);
>  	dsb(ishst);
>  
> -	return (void *)slot->addr;
> +	return (void *)slot->addr + offset_in_page(phys);
>  }
>  
>  void *hyp_fixmap_map(phys_addr_t phys)

This looks slightly odd. fixmap_map_slot() should return *a slot*, not
something in it. Can't hyp_fixmap_map() do that instead?

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.
Re: [PATCH v8 19/28] KVM: arm64: Support unaligned fixmap in the pKVM hyp
Posted by Vincent Donnefort 4 weeks, 1 day ago
Hi Marc,

Thanks for having a look at the series.


On Wed, Nov 19, 2025 at 03:38:32PM +0000, Marc Zyngier wrote:
> On Fri, 07 Nov 2025 09:38:31 +0000,
> Vincent Donnefort <vdonnefort@google.com> wrote:
> > 
> > Return the fixmap VA with the page offset, instead of the page base
> > address. This allows to use hyp_fixmap_map() seamlessly regardless of
> > the address alignment.
> > 
> > Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> > 
> > diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c
> > index ae8391baebc3..75014dc7d82e 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/mm.c
> > +++ b/arch/arm64/kvm/hyp/nvhe/mm.c
> > @@ -239,7 +239,7 @@ static void *fixmap_map_slot(struct hyp_fixmap_slot *slot, phys_addr_t phys)
> >  	WRITE_ONCE(*ptep, pte);
> >  	dsb(ishst);
> >  
> > -	return (void *)slot->addr;
> > +	return (void *)slot->addr + offset_in_page(phys);
> >  }
> >  
> >  void *hyp_fixmap_map(phys_addr_t phys)
> 
> This looks slightly odd. fixmap_map_slot() should return *a slot*, not
> something in it. Can't hyp_fixmap_map() do that instead?

That was fixing hyp_fixblock_map() at the same time. I will move the
offset_in_page() in both callers.

> 
> Thanks,
> 
> 	M.
> 
> -- 
> Without deviation from the norm, progress is not possible.