kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Moger, Babu" <Babu.Moger@amd.com>
To: Jim Mattson <jmattson@google.com>
Cc: Andy Lutomirski <luto@kernel.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"bp@alien8.de" <bp@alien8.de>, "hpa@zytor.com" <hpa@zytor.com>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"rkrcmar@redhat.com" <rkrcmar@redhat.com>,
	"sean.j.christopherson@intel.com"
	<sean.j.christopherson@intel.com>,
	"vkuznets@redhat.com" <vkuznets@redhat.com>,
	"wanpengli@tencent.com" <wanpengli@tencent.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"zohar@linux.ibm.com" <zohar@linux.ibm.com>,
	"yamada.masahiro@socionext.com" <yamada.masahiro@socionext.com>,
	"nayna@linux.ibm.com" <nayna@linux.ibm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: RE: [PATCH 2/4] kvm: svm: Enable UMIP feature on AMD
Date: Sat, 2 Nov 2019 19:23:45 +0000	[thread overview]
Message-ID: <DM5PR12MB2471947F435B18CBC1F68142957D0@DM5PR12MB2471.namprd12.prod.outlook.com> (raw)
In-Reply-To: <CALMp9eRWjj1b7bPdiJO3ZT2xDCyV=Ypf6GUcQLkXnqr7YrXDRg@mail.gmail.com>



> -----Original Message-----
> From: kvm-owner@vger.kernel.org <kvm-owner@vger.kernel.org> On Behalf
> Of Jim Mattson
> Sent: Friday, November 1, 2019 3:08 PM
> To: Moger, Babu <Babu.Moger@amd.com>
> Cc: Andy Lutomirski <luto@kernel.org>; tglx@linutronix.de;
> mingo@redhat.com; bp@alien8.de; hpa@zytor.com; pbonzini@redhat.com;
> rkrcmar@redhat.com; sean.j.christopherson@intel.com; vkuznets@redhat.com;
> wanpengli@tencent.com; x86@kernel.org; joro@8bytes.org;
> zohar@linux.ibm.com; yamada.masahiro@socionext.com;
> nayna@linux.ibm.com; linux-kernel@vger.kernel.org; kvm@vger.kernel.org
> Subject: Re: [PATCH 2/4] kvm: svm: Enable UMIP feature on AMD
> 
> On Fri, Nov 1, 2019 at 1:04 PM Moger, Babu <Babu.Moger@amd.com> wrote:
> >
> >
> >
> > On 11/1/19 2:24 PM, Andy Lutomirski wrote:
> > > On Fri, Nov 1, 2019 at 12:20 PM Moger, Babu <Babu.Moger@amd.com>
> wrote:
> > >>
> > >>
> > >>
> > >> On 11/1/19 1:29 PM, Jim Mattson wrote:
> > >>> On Fri, Nov 1, 2019 at 10:33 AM Moger, Babu <Babu.Moger@amd.com>
> wrote:
> > >>>>
> > >>>> AMD 2nd generation EPYC processors support UMIP (User-Mode
> Instruction
> > >>>> Prevention) feature. The UMIP feature prevents the execution of certain
> > >>>> instructions if the Current Privilege Level (CPL) is greater than 0.
> > >>>> If any of these instructions are executed with CPL > 0 and UMIP
> > >>>> is enabled, then kernel reports a #GP exception.
> > >>>>
> > >>>> The idea is taken from articles:
> > >>>> https://lwn.net/Articles/738209/
> > >>>> https://lwn.net/Articles/694385/
> > >>>>
> > >>>> Enable the feature if supported on bare metal and emulate instructions
> > >>>> to return dummy values for certain cases.
> > >>>>
> > >>>> Signed-off-by: Babu Moger <babu.moger@amd.com>
> > >>>> ---
> > >>>>  arch/x86/kvm/svm.c |   21 ++++++++++++++++-----
> > >>>>  1 file changed, 16 insertions(+), 5 deletions(-)
> > >>>>
> > >>>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> > >>>> index 4153ca8cddb7..79abbdeca148 100644
> > >>>> --- a/arch/x86/kvm/svm.c
> > >>>> +++ b/arch/x86/kvm/svm.c
> > >>>> @@ -2533,6 +2533,11 @@ static void
> svm_decache_cr4_guest_bits(struct kvm_vcpu *vcpu)
> > >>>>  {
> > >>>>  }
> > >>>>
> > >>>> +static bool svm_umip_emulated(void)
> > >>>> +{
> > >>>> +       return boot_cpu_has(X86_FEATURE_UMIP);
> > >>>> +}
> > >>>
> > >>> This makes no sense to me. If the hardware actually supports UMIP,
> > >>> then it doesn't have to be emulated.
> > >> My understanding..
> > >>
> > >> If the hardware supports the UMIP, it will generate the #GP fault when
> > >> these instructions are executed at CPL > 0. Purpose of the emulation is to
> > >> trap the GP and return a dummy value. Seems like this required in certain
> > >> legacy OSes running in protected and virtual-8086 modes. In long mode no
> > >> need to emulate. Here is the bit explanation
> https://lwn.net/Articles/738209/
> > >>
> > >
> > > Indeed.  Again, what does this have to do with your patch?
> > >
> > >>
> > >>>
> > >>> To the extent that kvm emulates UMIP on Intel CPUs without hardware
> > >>> UMIP (i.e. smsw is still allowed at CPL>0), we can always do the same
> > >>> emulation on AMD, because SVM has always offered intercepts of sgdt,
> > >>> sidt, sldt, and str. So, if you really want to offer this emulation on
> > >>> pre-EPYC 2 CPUs, this function should just return true. But, I have to
> > >>> ask, "why?"
> > >>
> > >>
> > >> Trying to support UMIP feature only on EPYC 2 hardware. No intention to
> > >> support pre-EPYC 2.
> > >>
> > >
> > > I think you need to totally rewrite your changelog to explain what you
> > > are doing.
> > >
> > > As I understand it, there are a couple of things KVM can do:
> > >
> > > 1. If the underlying hardware supports UMIP, KVM can expose UMIP to
> > > the guest.  SEV should be irrelevant here.
> > >
> > > 2. Regardless of whether the underlying hardware supports UMIP, KVM
> > > can try to emulate UMIP in the guest.  This may be impossible if SEV
> > > is enabled.
> > >
> > > Which of these are you doing?
> > >
> > My intention was to do 1.  Let me go back and think about this again.
> 
> (1) already works.

That’s right. Thanks Jim and Andy.
How about updating the Kconfig (patch #4) and update it to CONFIG_X86_UMIP (instead of CONFIG_X86_INTEL_UMIP).
Right now, it appears it is supported on only Intel.

  reply	other threads:[~2019-11-02 19:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01 17:33 [PATCH 0/4] Emulate and enable UMIP feature on AMD Moger, Babu
2019-11-01 17:33 ` [PATCH 1/4] kvm: x86: Dont set UMIP feature bit unconditionally Moger, Babu
2019-11-01 18:35   ` Jim Mattson
2019-11-01 19:39     ` Moger, Babu
2019-11-01 19:42       ` Jim Mattson
2019-11-01 17:33 ` [PATCH 2/4] kvm: svm: Enable UMIP feature on AMD Moger, Babu
2019-11-01 18:24   ` Andy Lutomirski
2019-11-01 18:38     ` Moger, Babu
2019-11-01 19:09       ` Andy Lutomirski
2019-11-01 18:29   ` Jim Mattson
2019-11-01 19:20     ` Moger, Babu
2019-11-01 19:24       ` Andy Lutomirski
2019-11-01 20:04         ` Moger, Babu
2019-11-01 20:08           ` Jim Mattson
2019-11-02 19:23             ` Moger, Babu [this message]
2019-11-03 11:45               ` Borislav Petkov
2019-11-04 18:46                 ` Moger, Babu
2019-11-04 11:54   ` Paolo Bonzini
2019-11-04 18:45     ` Moger, Babu
2019-11-01 17:33 ` [PATCH 3/4] kvm: svm: Emulate UMIP instructions on non SEV guest Moger, Babu
2019-11-01 17:34 ` [PATCH 4/4] x86/Kconfig: Rename UMIP config parameter Moger, Babu

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=DM5PR12MB2471947F435B18CBC1F68142957D0@DM5PR12MB2471.namprd12.prod.outlook.com \
    --to=babu.moger@amd.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nayna@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    --cc=yamada.masahiro@socionext.com \
    --cc=zohar@linux.ibm.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).