Re: [PATCH] KVM: Fix kvm_vcpu_map[_readonly]() function prototypes

From: Fang, Peter

Date: Fri Apr 03 2026 - 06:21:25 EST


On Thu, Apr 02, 2026 at 04:52:24PM -0700, Sean Christopherson wrote:
> On Tue, Mar 31, 2026, Peter Fang wrote:
> > On Tue, Mar 31, 2026 at 02:22:47AM +0000, Yosry Ahmed wrote:
> > >
> > > Most callers are converting a GPA to a GFN, I wonder if we should make
>
> Not most, all. The two outliers just do "gpa >> PAGE_SHIFT" instead of
> using gpa_to_gfn().
>
> > > the function take in a GPA instead? But then we'll need to the GPA not
> > > being aligned to a page boundary (either do gpa_to_gfn() in
> > > __kvm_vcpu_map() or fail if it's not aligned).
>
> Just do gpa_to_pfn(). If someone gets confused, we can add a comment explaining
> that kvm_vcpu_map() maps the entire page containing the gpa, but that should really
> go without saying...
>
> > Thanks for the feedback!
> >
> > Mapping guest memory into the host feels more like a GFN-based operation
> > to me. struct kvm_host_map is also designed around GFNs/PFNs so I think
> > using gfn_t in the function prototypes seems more natural. The caller
> > can handle the offset-in-page cases without creating a lot of complexity
> > in the APIs. But I'm happy to rework this if there's a desire to make
> > them more GPA-friendly.
>
> I vote to rework the APIs (after first fixing the prototypes) to take a GPA.
> I agree that mapping a page at a given gfn is conceptually more natural, but
> as Yosry points out, requiring literally every caller to convert to a gfn doesn't
> make a whole lot of sense from a code maintenance perspective.

Thanks! I'll prepare a v2 series to clean up the call sites as well.