RE: [PATCH v2 09/25] KVM: VMX: Switch FRED RSP0 between host and guest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > > > E.g. if it's somewhere in task_struct, then kvm_on_user_return()
> > > > would restore the current task's desired RSP0.
> > >
> > > So you're suggesting to extend the framework to allow per task constants?
> >
> > Yeah, or more likely, special case MSR_IA32_FRED_RSP0.  If KVM didn't
> > already have the user return framework, I wouldn't suggest this as I
> > doubt avoiding WRMSR when switching between vCPU tasks will be very
> > meaningful, but it's easy to handle FRED_RSP0, so why not.
> 
> Great, I will take the patch.

I tried to make this work, however because FRED RSP0 is per task and
keeps changing during context switch[1], we lose track of FRED RSP0
values from both host and guest, thus we need to:

1) *always* save guest FRED RSP0 in vmx_prepare_switch_to_host().

2) *always* restore guest FRED RSP0 in vmx_prepare_switch_to_guest(),
   because sometimes context switches happen but the CPU does NOT
   return to user mode thus the user return framework detects no change.

So it essentially becomes the same as what the original patch does.

I guess It's probably not worth the change, how do you think?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9356c4b8886c4f7d3436c3f7fe31715bdcf1c79e


> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index
> > 1783986d8626..ebecb205e5de 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -352,6 +352,7 @@ static void kvm_on_user_return(struct
> > user_return_notifier *urn)
> >                 = container_of(urn, struct kvm_user_return_msrs, urn);
> >         struct kvm_user_return_msr_values *values;
> >         unsigned long flags;
> > +       u64 host_val;
> >
> >         /*
> >          * Disabling irqs at this point since the following code could
> > be @@ -365,9
> > +366,15 @@ static void kvm_on_user_return(struct user_return_notifier
> > +*urn)
> >         local_irq_restore(flags);
> >         for (slot = 0; slot < kvm_nr_uret_msrs; ++slot) {
> >                 values = &msrs->values[slot];
> > -               if (values->host != values->curr) {
> > -                       wrmsrl(kvm_uret_msrs_list[slot], values->host);
> > -                       values->curr = values->host;
> > +
> > +               if (kvm_uret_msrs_list[slot] == MSR_IA32_FRED_RSP0)
> > +                       host_val = get_current_fred_rsp0();
> > +               else
> > +                       host_val = values->host;
> > +
> > +               if (host_val != values->curr) {
> > +                       wrmsrl(kvm_uret_msrs_list[slot], host_val);
> > +                       values->curr = host_val;
> >                 }
> >         }
> >  }






[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux