lkml.org 
[lkml]   [2019]   [Dec]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH RFC 03/15] KVM: Add build-time error check on kvm_run size
On Mon, Dec 02, 2019 at 11:30:27AM -0800, Sean Christopherson wrote:
> On Fri, Nov 29, 2019 at 04:34:53PM -0500, Peter Xu wrote:
> > It's already going to reach 2400 Bytes (which is over half of page
> > size on 4K page archs), so maybe it's good to have this build-time
> > check in case it overflows when adding new fields.
>
> Please explain why exceeding PAGE_SIZE is a bad thing. I realize it's
> almost absurdly obvious when looking at the code, but a) the patch itself
> does not provide that context and b) the changelog should hold up on its
> own,

Right, I'll enhance the commit message.

> e.g. in a mostly hypothetical case where the allocation of vcpu->run
> were changed to something else.

And that's why I added BUILD_BUG_ON right beneath that allocation. :)

It's just a helper for developers when adding new kvm_run fields, not
a risk for anyone who wants to start allocating more pages for it.

Thanks,

>
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > virt/kvm/kvm_main.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index 8f8940cc4b84..681452d288cd 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -352,6 +352,8 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
> > }
> > vcpu->run = page_address(page);
> >
> > + BUILD_BUG_ON(sizeof(struct kvm_run) > PAGE_SIZE);
> > +
> > kvm_vcpu_set_in_spin_loop(vcpu, false);
> > kvm_vcpu_set_dy_eligible(vcpu, false);
> > vcpu->preempted = false;
> > --
> > 2.21.0
> >
>

--
Peter Xu

\
 
 \ /
  Last update: 2019-12-02 21:53    [W:0.085 / U:8.608 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site