Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Moger, Babu



> -Original Message-
> From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> Sent: Wednesday, June 13, 2018 1:49 PM
> To: Moger, Babu 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> Denemark 
> Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> On Wed, Jun 13, 2018 at 06:21:58PM +, Moger, Babu wrote:
> >
> >
> > > -Original Message-
> > > From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> > > Sent: Wednesday, June 13, 2018 1:18 PM
> > > To: Moger, Babu 
> > > Cc: m...@redhat.com; marcel.apfelb...@gmail.com;
> pbonz...@redhat.com;
> > > r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> > > k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> > > Denemark 
> > > Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> > > CPU
> > >
> > > On Wed, Jun 13, 2018 at 06:10:30PM +, Moger, Babu wrote:
> > > > > -Original Message-
> > > > > From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> > > > > Sent: Wednesday, June 13, 2018 12:18 PM
> > > > > To: Moger, Babu 
> > > > > Cc: m...@redhat.com; marcel.apfelb...@gmail.com;
> > > pbonz...@redhat.com;
> > > > > r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> > > > > k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com;
> Jiri
> > > > > Denemark 
> > > > > Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD
> EPYC
> > > > > CPU
> > > > >
> > > > > On Wed, Jun 13, 2018 at 04:52:18PM +, Moger, Babu wrote:
> > > > > [...]
> > > > > > > What do you think our options are here?
> > > > > >
> > > > > > Should we drop automatic topoext completely and move forward?
> > > > > > What are your thoughts?
> > > > >
> > > > > Let's drop automatic topoext by now, and see if we find solutions
> > > > > later.  I don't want to hold the rest of the patches because of
> > > > > this.
> > > >
> > > > Ok. I will drop topoext.
> > > >
> > > > >
> > > > > I'm thinking we could simply make kvm_arch_get_supported_cpuid()
> > > > > always return TOPOEXT on AMD CPUs, because the feature flag don't
> > > > > really depend on any KVM code to work (is that correct?).
> > > >
> > > > Yes, that is correct. I don't see any dependent code on TOPOEXT in
> KVM
> > > driver.
> > > >
> > > > Ok. Let me add TOPOEXT flag for all the AMD cpus and see how it goes.
> > >
> > > Hmm, this could actually solve all of our problems, then:
> > >
> > > We can forget about auto-topoext: just add TOPOEXT in
> > > kvm_arch_get_supported_cpuid(), add TOPOEXT unconditionally to
> > > the CPU models where you are interested into (EPYC only?), and
> > > add topoext=off to pc-2.12 compat_props.
> > >
> >
> > Ok Sure.
> 
> Sorry, I forgot we still need to decide what to do if TOPOEXT is
> enabled in the CPU model (or command-line) but the -smp options
> are not compatible with it.

Yes.  I have kept that check.  But, I had to implement 
topology_supports_topoext bit differently.
Reason for this is we need to disable this feature before the  
x86_cpu_expand_features.
But problem is nr_cores and nr_threads are not populated at this time. It is 
populated in qemu_init_vcpus.
Please take a look at topology_supports_topoext again.
> 
> In other words, what should guest see on CPUID if using:
> 
> "-machine pc-q35-3.0 -cpu EPYC -smp 64,cores=64"
> or:
> "-machine pc-q35-3.0 -cpu Opteron_G5,+topoext -smp 64,cores=64"
> 
Tested both these cases. It works fine with some warning messages.

> I wonder what would happen if we just return zeroes on
> CPUID[0x81E] if !topology_supports_topoext(), instead of
> trying to clear/set TOPOEXT depending on the -smp option?  It
> would make things much simpler for QEMU and libvirt.

I did not see that difference in behavior if we clear the bit versus return 0s.
Sending new patches now. Please review.
One note: I will going on vacation from June 20th for couple of weeks.
 If possible I would like to close this feature. If we cannot that is fine. 
Just an FYI.

> 
> --
> Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Eduardo Habkost
On Wed, Jun 13, 2018 at 06:21:58PM +, Moger, Babu wrote:
> 
> 
> > -Original Message-
> > From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> > Sent: Wednesday, June 13, 2018 1:18 PM
> > To: Moger, Babu 
> > Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> > r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> > k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> > Denemark 
> > Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> > CPU
> > 
> > On Wed, Jun 13, 2018 at 06:10:30PM +, Moger, Babu wrote:
> > > > -Original Message-
> > > > From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> > > > Sent: Wednesday, June 13, 2018 12:18 PM
> > > > To: Moger, Babu 
> > > > Cc: m...@redhat.com; marcel.apfelb...@gmail.com;
> > pbonz...@redhat.com;
> > > > r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> > > > k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> > > > Denemark 
> > > > Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> > > > CPU
> > > >
> > > > On Wed, Jun 13, 2018 at 04:52:18PM +, Moger, Babu wrote:
> > > > [...]
> > > > > > What do you think our options are here?
> > > > >
> > > > > Should we drop automatic topoext completely and move forward?
> > > > > What are your thoughts?
> > > >
> > > > Let's drop automatic topoext by now, and see if we find solutions
> > > > later.  I don't want to hold the rest of the patches because of
> > > > this.
> > >
> > > Ok. I will drop topoext.
> > >
> > > >
> > > > I'm thinking we could simply make kvm_arch_get_supported_cpuid()
> > > > always return TOPOEXT on AMD CPUs, because the feature flag don't
> > > > really depend on any KVM code to work (is that correct?).
> > >
> > > Yes, that is correct. I don't see any dependent code on TOPOEXT in KVM
> > driver.
> > >
> > > Ok. Let me add TOPOEXT flag for all the AMD cpus and see how it goes.
> > 
> > Hmm, this could actually solve all of our problems, then:
> > 
> > We can forget about auto-topoext: just add TOPOEXT in
> > kvm_arch_get_supported_cpuid(), add TOPOEXT unconditionally to
> > the CPU models where you are interested into (EPYC only?), and
> > add topoext=off to pc-2.12 compat_props.
> > 
> 
> Ok Sure.

Sorry, I forgot we still need to decide what to do if TOPOEXT is
enabled in the CPU model (or command-line) but the -smp options
are not compatible with it.

In other words, what should guest see on CPUID if using:

"-machine pc-q35-3.0 -cpu EPYC -smp 64,cores=64"
or:
"-machine pc-q35-3.0 -cpu Opteron_G5,+topoext -smp 64,cores=64"

I wonder what would happen if we just return zeroes on
CPUID[0x81E] if !topology_supports_topoext(), instead of
trying to clear/set TOPOEXT depending on the -smp option?  It
would make things much simpler for QEMU and libvirt.

-- 
Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Moger, Babu



> -Original Message-
> From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> Sent: Wednesday, June 13, 2018 1:18 PM
> To: Moger, Babu 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> Denemark 
> Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> On Wed, Jun 13, 2018 at 06:10:30PM +, Moger, Babu wrote:
> > > -Original Message-
> > > From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> > > Sent: Wednesday, June 13, 2018 12:18 PM
> > > To: Moger, Babu 
> > > Cc: m...@redhat.com; marcel.apfelb...@gmail.com;
> pbonz...@redhat.com;
> > > r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> > > k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> > > Denemark 
> > > Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> > > CPU
> > >
> > > On Wed, Jun 13, 2018 at 04:52:18PM +, Moger, Babu wrote:
> > > [...]
> > > > > What do you think our options are here?
> > > >
> > > > Should we drop automatic topoext completely and move forward?
> > > > What are your thoughts?
> > >
> > > Let's drop automatic topoext by now, and see if we find solutions
> > > later.  I don't want to hold the rest of the patches because of
> > > this.
> >
> > Ok. I will drop topoext.
> >
> > >
> > > I'm thinking we could simply make kvm_arch_get_supported_cpuid()
> > > always return TOPOEXT on AMD CPUs, because the feature flag don't
> > > really depend on any KVM code to work (is that correct?).
> >
> > Yes, that is correct. I don't see any dependent code on TOPOEXT in KVM
> driver.
> >
> > Ok. Let me add TOPOEXT flag for all the AMD cpus and see how it goes.
> 
> Hmm, this could actually solve all of our problems, then:
> 
> We can forget about auto-topoext: just add TOPOEXT in
> kvm_arch_get_supported_cpuid(), add TOPOEXT unconditionally to
> the CPU models where you are interested into (EPYC only?), and
> add topoext=off to pc-2.12 compat_props.
> 

Ok Sure.

> Sorry for not noticing that before.  I was incorrectly assuming

No problem.

> that TOPOEXT was safe to enable only if it was returned by
> GET_SUPPORTED_CPUID.
> 
> --
> Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Eduardo Habkost
On Wed, Jun 13, 2018 at 06:10:30PM +, Moger, Babu wrote:
> > -Original Message-
> > From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> > Sent: Wednesday, June 13, 2018 12:18 PM
> > To: Moger, Babu 
> > Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> > r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> > k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> > Denemark 
> > Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> > CPU
> > 
> > On Wed, Jun 13, 2018 at 04:52:18PM +, Moger, Babu wrote:
> > [...]
> > > > What do you think our options are here?
> > >
> > > Should we drop automatic topoext completely and move forward?
> > > What are your thoughts?
> > 
> > Let's drop automatic topoext by now, and see if we find solutions
> > later.  I don't want to hold the rest of the patches because of
> > this.
> 
> Ok. I will drop topoext.
> 
> > 
> > I'm thinking we could simply make kvm_arch_get_supported_cpuid()
> > always return TOPOEXT on AMD CPUs, because the feature flag don't
> > really depend on any KVM code to work (is that correct?).
> 
> Yes, that is correct. I don't see any dependent code on TOPOEXT in KVM driver.
> 
> Ok. Let me add TOPOEXT flag for all the AMD cpus and see how it goes.

Hmm, this could actually solve all of our problems, then:

We can forget about auto-topoext: just add TOPOEXT in
kvm_arch_get_supported_cpuid(), add TOPOEXT unconditionally to
the CPU models where you are interested into (EPYC only?), and
add topoext=off to pc-2.12 compat_props.

Sorry for not noticing that before.  I was incorrectly assuming
that TOPOEXT was safe to enable only if it was returned by
GET_SUPPORTED_CPUID.

-- 
Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Moger, Babu



> -Original Message-
> From: kvm-ow...@vger.kernel.org [mailto:kvm-ow...@vger.kernel.org]
> On Behalf Of Moger, Babu
> Sent: Wednesday, June 13, 2018 1:11 PM
> To: Eduardo Habkost 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> Denemark 
> Subject: RE: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> 
> > -Original Message-
> > From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> > Sent: Wednesday, June 13, 2018 12:18 PM
> > To: Moger, Babu 
> > Cc: m...@redhat.com; marcel.apfelb...@gmail.com;
> pbonz...@redhat.com;
> > r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> > k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> > Denemark 
> > Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> > CPU
> >
> > On Wed, Jun 13, 2018 at 04:52:18PM +, Moger, Babu wrote:
> > [...]
> > > > What do you think our options are here?
> > >
> > > Should we drop automatic topoext completely and move forward?
> > > What are your thoughts?
> >
> > Let's drop automatic topoext by now, and see if we find solutions
> > later.  I don't want to hold the rest of the patches because of
> > this.
> 
> Ok. I will drop topoext.

Sorry, I mean automatic topoext.

> 
> >
> > I'm thinking we could simply make kvm_arch_get_supported_cpuid()
> > always return TOPOEXT on AMD CPUs, because the feature flag don't
> > really depend on any KVM code to work (is that correct?).
> 
> Yes, that is correct. I don't see any dependent code on TOPOEXT in KVM
> driver.
> 
> Ok. Let me add TOPOEXT flag for all the AMD cpus and see how it goes.
> 
> >
> > --
> > Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Moger, Babu


> -Original Message-
> From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> Sent: Wednesday, June 13, 2018 12:18 PM
> To: Moger, Babu 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> Denemark 
> Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> On Wed, Jun 13, 2018 at 04:52:18PM +, Moger, Babu wrote:
> [...]
> > > What do you think our options are here?
> >
> > Should we drop automatic topoext completely and move forward?
> > What are your thoughts?
> 
> Let's drop automatic topoext by now, and see if we find solutions
> later.  I don't want to hold the rest of the patches because of
> this.

Ok. I will drop topoext.

> 
> I'm thinking we could simply make kvm_arch_get_supported_cpuid()
> always return TOPOEXT on AMD CPUs, because the feature flag don't
> really depend on any KVM code to work (is that correct?).

Yes, that is correct. I don't see any dependent code on TOPOEXT in KVM driver.

Ok. Let me add TOPOEXT flag for all the AMD cpus and see how it goes.

> 
> --
> Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Eduardo Habkost
On Wed, Jun 13, 2018 at 04:52:18PM +, Moger, Babu wrote:
[...]
> > What do you think our options are here?
> 
> Should we drop automatic topoext completely and move forward?
> What are your thoughts?

Let's drop automatic topoext by now, and see if we find solutions
later.  I don't want to hold the rest of the patches because of
this.

I'm thinking we could simply make kvm_arch_get_supported_cpuid()
always return TOPOEXT on AMD CPUs, because the feature flag don't
really depend on any KVM code to work (is that correct?).

-- 
Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-13 Thread Moger, Babu


> -Original Message-
> From: kvm-ow...@vger.kernel.org [mailto:kvm-ow...@vger.kernel.org]
> On Behalf Of Babu Moger
> Sent: Tuesday, June 12, 2018 2:47 PM
> To: Eduardo Habkost 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> Denemark 
> Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> 
> 
> On 06/12/2018 02:05 PM, Eduardo Habkost wrote:
> > On Tue, Jun 12, 2018 at 06:38:08PM +, Moger, Babu wrote:
> > [...]
> >>> I'm starting to think that enabling TOPOEXT automatically is
> >>> adding too much complexity and compatibility problems, and it's
> >>> better to leave this task to management software.
> >>>
> >>> The main problem here is:
> >>>
> >>> This works today with QEMU 2.12 + Linux <= 4.15:
> >>>$ $QEMU -machine pc -cpu EPYC,enforce -smp
> >>> 8,sockets=2,cores=2,threads=2"
> >>> and must keep working with QEMU 3.0 and Linux <= 4.15.
> >>>
> >>> In addition to that, the results for:
> >>>$ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
> >>> must be deterministic and expose exactly the same CPUID data even
> >>> if host hardware or software changes, as long as the QEMU
> >>> command-line is the same.
> >>>
> >>> Do you see a way to fulfill those two constraints while making
> >>> "-machine pc-q35-3.0 -cpu EPYC" enable TOPOEXT automatically?
> >>>
> >> Now(setting feature before x86_cpu_expand_features), enabling
> >> TOPOEXT appears to work fine.
> > What about the above constraints?  Are you really fulfilling
> > them?
> >
> > This one is tricky:
> >
> > ] This works today with QEMU 2.12 + Linux <= 4.15:
> > ]   $ $QEMU -machine pc -cpu EPYC,enforce -smp
> 8,sockets=2,cores=2,threads=2"
> > ] and must keep working with QEMU 3.0 and Linux <= 4.15.
>   This works fine on kernel <= 4.15 with some warnings(-smp
> 8,sockets=2,cores=2,threads=2 -cpu EPYC).
> 
> qemu-system-x86_64: warning: host doesn't support requested feature:
> CPUID.8001H:EDX.rdtscp [bit 27]
> qemu-system-x86_64: warning: host doesn't support requested feature:
> CPUID.8001H:ECX.topoext [bit 22]
> qemu-system-x86_64: This family of AMD CPU doesn't support
> hyperthreading(2). Please configure -smp options properly or try
> enabling topoext feature.
> continues..
> >
> > If we enable TOPOEXT unconditionally, the command-line won't work
> > with Linux <= 4.15.
> >
> > If we enable TOPOEXT only if the kernel returns TOPOEXT on
> > GET_SUPPORTED_CPUID, we break the second constraint:
> >
> > ] The results for:
> > ]   $ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
> > ] must be deterministic and expose exactly the same CPUID data even
> > ] if host hardware or software changes, as long as the QEMU
> > ] command-line is the same.
> >
> This fails on kernel  <= 4.15 with following messages((-smp
> 8,sockets=2,cores=2,threads=2 -cpu EPYC,enforce).
> qemu-system-x86_64: warning: host doesn't support requested feature:
> CPUID.8001H:EDX.rdtscp [bit 27]
> qemu-system-x86_64: warning: host doesn't support requested feature:
> CPUID.8001H:ECX.topoext [bit 22]
> qemu-system-x86_64: Host doesn't support requested features
> exits..
> 
> What do you think our options are here?

Should we drop automatic topoext completely and move forward? What are your 
thoughts?



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-12 Thread Babu Moger




On 06/12/2018 02:05 PM, Eduardo Habkost wrote:

On Tue, Jun 12, 2018 at 06:38:08PM +, Moger, Babu wrote:
[...]

I'm starting to think that enabling TOPOEXT automatically is
adding too much complexity and compatibility problems, and it's
better to leave this task to management software.

The main problem here is:

This works today with QEMU 2.12 + Linux <= 4.15:
   $ $QEMU -machine pc -cpu EPYC,enforce -smp
8,sockets=2,cores=2,threads=2"
and must keep working with QEMU 3.0 and Linux <= 4.15.

In addition to that, the results for:
   $ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
must be deterministic and expose exactly the same CPUID data even
if host hardware or software changes, as long as the QEMU
command-line is the same.

Do you see a way to fulfill those two constraints while making
"-machine pc-q35-3.0 -cpu EPYC" enable TOPOEXT automatically?


Now(setting feature before x86_cpu_expand_features), enabling
TOPOEXT appears to work fine.

What about the above constraints?  Are you really fulfilling
them?

This one is tricky:

] This works today with QEMU 2.12 + Linux <= 4.15:
]   $ $QEMU -machine pc -cpu EPYC,enforce -smp 8,sockets=2,cores=2,threads=2"
] and must keep working with QEMU 3.0 and Linux <= 4.15.
 This works fine on kernel <= 4.15 with some warnings(-smp 
8,sockets=2,cores=2,threads=2 -cpu EPYC).


qemu-system-x86_64: warning: host doesn't support requested feature: 
CPUID.8001H:EDX.rdtscp [bit 27]
qemu-system-x86_64: warning: host doesn't support requested feature: 
CPUID.8001H:ECX.topoext [bit 22]
qemu-system-x86_64: This family of AMD CPU doesn't support 
hyperthreading(2). Please configure -smp options properly or try 
enabling topoext feature.

continues..


If we enable TOPOEXT unconditionally, the command-line won't work
with Linux <= 4.15.

If we enable TOPOEXT only if the kernel returns TOPOEXT on
GET_SUPPORTED_CPUID, we break the second constraint:

] The results for:
]   $ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
] must be deterministic and expose exactly the same CPUID data even
] if host hardware or software changes, as long as the QEMU
] command-line is the same.

This fails on kernel  <= 4.15 with following messages((-smp 
8,sockets=2,cores=2,threads=2 -cpu EPYC,enforce).
qemu-system-x86_64: warning: host doesn't support requested feature: 
CPUID.8001H:EDX.rdtscp [bit 27]
qemu-system-x86_64: warning: host doesn't support requested feature: 
CPUID.8001H:ECX.topoext [bit 22]

qemu-system-x86_64: Host doesn't support requested features
exits..

What do you think our options are here?





Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-12 Thread Eduardo Habkost
On Tue, Jun 12, 2018 at 06:38:08PM +, Moger, Babu wrote:
[...]
> > I'm starting to think that enabling TOPOEXT automatically is
> > adding too much complexity and compatibility problems, and it's
> > better to leave this task to management software.
> > 
> > The main problem here is:
> > 
> > This works today with QEMU 2.12 + Linux <= 4.15:
> >   $ $QEMU -machine pc -cpu EPYC,enforce -smp
> > 8,sockets=2,cores=2,threads=2"
> > and must keep working with QEMU 3.0 and Linux <= 4.15.
> > 
> > In addition to that, the results for:
> >   $ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
> > must be deterministic and expose exactly the same CPUID data even
> > if host hardware or software changes, as long as the QEMU
> > command-line is the same.
> > 
> > Do you see a way to fulfill those two constraints while making
> > "-machine pc-q35-3.0 -cpu EPYC" enable TOPOEXT automatically?
> > 
> 
> Now(setting feature before x86_cpu_expand_features), enabling
> TOPOEXT appears to work fine.

What about the above constraints?  Are you really fulfilling
them?

This one is tricky:

] This works today with QEMU 2.12 + Linux <= 4.15:
]   $ $QEMU -machine pc -cpu EPYC,enforce -smp 8,sockets=2,cores=2,threads=2"
] and must keep working with QEMU 3.0 and Linux <= 4.15.

If we enable TOPOEXT unconditionally, the command-line won't work
with Linux <= 4.15.

If we enable TOPOEXT only if the kernel returns TOPOEXT on
GET_SUPPORTED_CPUID, we break the second constraint:

] The results for:
]   $ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
] must be deterministic and expose exactly the same CPUID data even
] if host hardware or software changes, as long as the QEMU
] command-line is the same.

-- 
Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-12 Thread Moger, Babu



> -Original Message-
> From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> Sent: Tuesday, June 12, 2018 12:40 PM
> To: Moger, Babu 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> Denemark 
> Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> On Tue, Jun 12, 2018 at 04:29:25PM +, Moger, Babu wrote:
> > > [...]
> > > > > +/* TOPOEXT feature requires 0x801E */
> > > > > +if (env->features[FEAT_8000_0001_ECX] &
> CPUID_EXT3_TOPOEXT)
> > > {
> > > > > +x86_cpu_adjust_level(cpu, >cpuid_min_xlevel,
> > > 0x801E);
> > > > > +}
> > > >
> > > > I suggest moving this hunk to a separate patch.  I'm not 100%
> > > > sure yet if this will require compat_props code to disable
> > > > auto-xlevel-increase on older machine-types.
> > >
> > > The problem here is that:
> > >   $QEMU -machine pc-i440fx-1.3 -cpu Opteron_G4,+topoext
> > > currently results in xlevel=0x801A, since QEMU 1.3.
> > >
> > > (The same applies to all machine-types between 1.3 and 2.12)
> > >
> > > I was hoping that we could declare topoext as non-migration-safe,
> > > but I believe libvirt will already include "topoext" when using
> > > "host-model" if the host CPU supports TOPOEXT.  Jiri, can you
> > > confirm that?
> > >
> > > We can address that with a "x-topoext-auto-xlevel" property, set
> > > to true on all CPU models by default, and disabled by
> > > PC_COMPAT_2_12.
> > >
> > > The code would become:
> > >
> > > if (cpu->topoext_auto_xlevel && env-
> >features[FEAT_8000_0001_ECX] &
> > > CPUID_EXT3_TOPOEXT) {
> > > x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> > > }
> > >
> > > Or, we could simply declare that "-cpu Opteron_G4,+topoext" will
> > > never increase xlevel automatically (on any machine-type), and
> > > change the code above to:
> > >
> > > if (cpu->auto_topoext && env->features[FEAT_8000_0001_ECX] &
> > > CPUID_EXT3_TOPOEXT) {
> > > x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> > > }
> >
> > I was going to do this.  But there is one problem.  We don't
> > set the CPUID_EXT3_TOPOEXT in CPU model table. So this won't
> > work.
> 
> Won't this work if the auto_topoext handling is done before
> x86_cpu_expand_features() is called?

Yes. That works. We can go with this approach.

> 
> 
> > One more thing I noticed that feature setting should happen
> > much before x86_cpu_realizefn.
> 
> Why?

I was wrong here.  It should be done before x86_cpu_expand_features.

> 
> >
> > Couple of options.
> > First option.
> > 1. Set both feature and xlevel here(in x86_cpu_expand_features).
> >  if (cpu->x_auto_topoext {
> > env->features[FEAT_8000_0001_ECX]  |= CPUID_EXT3_TOPOEXT;
> > x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> >  }
> > 2. And remove feature setting in x86_cpu_realizefn.
> 
> This would make TOPOEXT be included in 'query-cpu-model-expansion
> model=EPYC', which would be incorrect because TOPOEXT won't
> always be enabled when using EPYC.
> 
> 
> >
> > Or
> >
> > Second option
> > 1.Set the feature bit in CPU model table.
> > 2. Set xlevel in x86_cpu_expand_features using cpu->x_auto_topoext
> > 3. And remove feature setting in x86_cpu_realizefn.
> >
> > I  prefer the second option.
> 
> Same here: TOPOEXT would be included in
> 'query-cpu-model-expansion model=EPYC', and this would be
> incorrect.
> 
> 
> I'm starting to think that enabling TOPOEXT automatically is
> adding too much complexity and compatibility problems, and it's
> better to leave this task to management software.
> 
> The main problem here is:
> 
> This works today with QEMU 2.12 + Linux <= 4.15:
>   $ $QEMU -machine pc -cpu EPYC,enforce -smp
> 8,sockets=2,cores=2,threads=2"
> and must keep working with QEMU 3.0 and Linux <= 4.15.
> 
> In addition to that, the results for:
>   $ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
> must be deterministic and expose exactly the same CPUID data even
> if host hardware or software changes, as long as the QEMU
> command-line is the same.
> 
> Do you see a way to fulfill those two constraints while making
> "-machine pc-q35-3.0 -cpu EPYC" enable TOPOEXT automatically?
> 

Now(setting feature before x86_cpu_expand_features), enabling TOPOEXT appears 
to work fine.

> --
> Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-12 Thread Eduardo Habkost
On Tue, Jun 12, 2018 at 04:29:25PM +, Moger, Babu wrote:
> > [...]
> > > > +/* TOPOEXT feature requires 0x801E */
> > > > +if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT)
> > {
> > > > +x86_cpu_adjust_level(cpu, >cpuid_min_xlevel,
> > 0x801E);
> > > > +}
> > >
> > > I suggest moving this hunk to a separate patch.  I'm not 100%
> > > sure yet if this will require compat_props code to disable
> > > auto-xlevel-increase on older machine-types.
> > 
> > The problem here is that:
> >   $QEMU -machine pc-i440fx-1.3 -cpu Opteron_G4,+topoext
> > currently results in xlevel=0x801A, since QEMU 1.3.
> > 
> > (The same applies to all machine-types between 1.3 and 2.12)
> > 
> > I was hoping that we could declare topoext as non-migration-safe,
> > but I believe libvirt will already include "topoext" when using
> > "host-model" if the host CPU supports TOPOEXT.  Jiri, can you
> > confirm that?
> > 
> > We can address that with a "x-topoext-auto-xlevel" property, set
> > to true on all CPU models by default, and disabled by
> > PC_COMPAT_2_12.
> > 
> > The code would become:
> > 
> > if (cpu->topoext_auto_xlevel && env->features[FEAT_8000_0001_ECX] &
> > CPUID_EXT3_TOPOEXT) {
> > x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> > }
> > 
> > Or, we could simply declare that "-cpu Opteron_G4,+topoext" will
> > never increase xlevel automatically (on any machine-type), and
> > change the code above to:
> > 
> > if (cpu->auto_topoext && env->features[FEAT_8000_0001_ECX] &
> > CPUID_EXT3_TOPOEXT) {
> > x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> > }
> 
> I was going to do this.  But there is one problem.  We don't
> set the CPUID_EXT3_TOPOEXT in CPU model table. So this won't
> work.

Won't this work if the auto_topoext handling is done before
x86_cpu_expand_features() is called?


> One more thing I noticed that feature setting should happen
> much before x86_cpu_realizefn.

Why?

> 
> Couple of options. 
> First option.
> 1. Set both feature and xlevel here(in x86_cpu_expand_features).
>  if (cpu->x_auto_topoext {
> env->features[FEAT_8000_0001_ECX]  |= CPUID_EXT3_TOPOEXT;
> x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
>  }
> 2. And remove feature setting in x86_cpu_realizefn.

This would make TOPOEXT be included in 'query-cpu-model-expansion
model=EPYC', which would be incorrect because TOPOEXT won't
always be enabled when using EPYC.


> 
> Or 
> 
> Second option
> 1.Set the feature bit in CPU model table.
> 2. Set xlevel in x86_cpu_expand_features using cpu->x_auto_topoext
> 3. And remove feature setting in x86_cpu_realizefn.
>  
> I  prefer the second option. 

Same here: TOPOEXT would be included in
'query-cpu-model-expansion model=EPYC', and this would be
incorrect.


I'm starting to think that enabling TOPOEXT automatically is
adding too much complexity and compatibility problems, and it's
better to leave this task to management software.

The main problem here is:

This works today with QEMU 2.12 + Linux <= 4.15:
  $ $QEMU -machine pc -cpu EPYC,enforce -smp 8,sockets=2,cores=2,threads=2"
and must keep working with QEMU 3.0 and Linux <= 4.15.

In addition to that, the results for:
  $ $QEMU -machine pc-q35-3.0 -cpu EPYC,enforce [...]
must be deterministic and expose exactly the same CPUID data even
if host hardware or software changes, as long as the QEMU
command-line is the same.

Do you see a way to fulfill those two constraints while making
"-machine pc-q35-3.0 -cpu EPYC" enable TOPOEXT automatically?

-- 
Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-12 Thread Moger, Babu



> -Original Message-
> From: kvm-ow...@vger.kernel.org [mailto:kvm-ow...@vger.kernel.org]
> On Behalf Of Eduardo Habkost
> Sent: Monday, June 11, 2018 4:10 PM
> To: Moger, Babu 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com; Jiri
> Denemark 
> Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> On Mon, Jun 11, 2018 at 05:50:30PM -0300, Eduardo Habkost wrote:
> [...]
> > > +/* TOPOEXT feature requires 0x801E */
> > > +if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT)
> {
> > > +x86_cpu_adjust_level(cpu, >cpuid_min_xlevel,
> 0x801E);
> > > +}
> >
> > I suggest moving this hunk to a separate patch.  I'm not 100%
> > sure yet if this will require compat_props code to disable
> > auto-xlevel-increase on older machine-types.
> 
> The problem here is that:
>   $QEMU -machine pc-i440fx-1.3 -cpu Opteron_G4,+topoext
> currently results in xlevel=0x801A, since QEMU 1.3.
> 
> (The same applies to all machine-types between 1.3 and 2.12)
> 
> I was hoping that we could declare topoext as non-migration-safe,
> but I believe libvirt will already include "topoext" when using
> "host-model" if the host CPU supports TOPOEXT.  Jiri, can you
> confirm that?
> 
> We can address that with a "x-topoext-auto-xlevel" property, set
> to true on all CPU models by default, and disabled by
> PC_COMPAT_2_12.
> 
> The code would become:
> 
> if (cpu->topoext_auto_xlevel && env->features[FEAT_8000_0001_ECX] &
> CPUID_EXT3_TOPOEXT) {
> x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> }
> 
> Or, we could simply declare that "-cpu Opteron_G4,+topoext" will
> never increase xlevel automatically (on any machine-type), and
> change the code above to:
> 
> if (cpu->auto_topoext && env->features[FEAT_8000_0001_ECX] &
> CPUID_EXT3_TOPOEXT) {
> x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> }

I was going to do this.  But there is one problem.  We don't set the 
CPUID_EXT3_TOPOEXT in CPU model table. So this won't work.
One more thing I noticed that feature setting should happen much before 
x86_cpu_realizefn.

Couple of options. 
First option.
1. Set both feature and xlevel here(in x86_cpu_expand_features).
 if (cpu->x_auto_topoext {
env->features[FEAT_8000_0001_ECX]  |= CPUID_EXT3_TOPOEXT;
x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
 }
2. And remove feature setting in x86_cpu_realizefn.

Or 

Second option
1.Set the feature bit in CPU model table.
2. Set xlevel in x86_cpu_expand_features using cpu->x_auto_topoext
3. And remove feature setting in x86_cpu_realizefn.
 
I  prefer the second option. 

> 
> --
> Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-11 Thread Eduardo Habkost
On Mon, Jun 11, 2018 at 05:50:30PM -0300, Eduardo Habkost wrote:
[...]
> > +/* TOPOEXT feature requires 0x801E */
> > +if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) {
> > +x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> > +}
> 
> I suggest moving this hunk to a separate patch.  I'm not 100%
> sure yet if this will require compat_props code to disable
> auto-xlevel-increase on older machine-types.

The problem here is that:
  $QEMU -machine pc-i440fx-1.3 -cpu Opteron_G4,+topoext
currently results in xlevel=0x801A, since QEMU 1.3.

(The same applies to all machine-types between 1.3 and 2.12)

I was hoping that we could declare topoext as non-migration-safe,
but I believe libvirt will already include "topoext" when using
"host-model" if the host CPU supports TOPOEXT.  Jiri, can you
confirm that?

We can address that with a "x-topoext-auto-xlevel" property, set
to true on all CPU models by default, and disabled by
PC_COMPAT_2_12.

The code would become:

if (cpu->topoext_auto_xlevel && env->features[FEAT_8000_0001_ECX] & 
CPUID_EXT3_TOPOEXT) {
x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
}

Or, we could simply declare that "-cpu Opteron_G4,+topoext" will
never increase xlevel automatically (on any machine-type), and
change the code above to:

if (cpu->auto_topoext && env->features[FEAT_8000_0001_ECX] & 
CPUID_EXT3_TOPOEXT) {
x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
}

-- 
Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-11 Thread Moger, Babu



> -Original Message-
> From: Eduardo Habkost [mailto:ehabk...@redhat.com]
> Sent: Monday, June 11, 2018 3:51 PM
> To: Moger, Babu 
> Cc: m...@redhat.com; marcel.apfelb...@gmail.com; pbonz...@redhat.com;
> r...@twiddle.net; mtosa...@redhat.com; qemu-devel@nongnu.org;
> k...@vger.kernel.org; k...@tripleback.net; ge...@hostfission.com
> Subject: Re: [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> On Fri, Jun 08, 2018 at 06:56:19PM -0400, Babu Moger wrote:
> > Enable TOPOEXT feature on EPYC CPU. This is required to support
> > hyperthreading on VM guests. Also extend xlevel to 0x801E.
> >
> > TOPOEXT feature is disabled for legacy machines.
> >
> > Signed-off-by: Babu Moger 
> > ---
> >  target/i386/cpu.c | 7 +++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> > index d3411ed..4dd9a82 100644
> > --- a/target/i386/cpu.c
> > +++ b/target/i386/cpu.c
> > @@ -2574,6 +2574,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
> >  .xlevel = 0x800A,
> >  .model_id = "AMD EPYC Processor",
> >  .cache_info = _cache_info,
> > +.auto_topoext = 1,
> >  },
> >  {
> >  .name = "EPYC-IBPB",
> > @@ -2621,6 +2622,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
> >  .xlevel = 0x800A,
> >  .model_id = "AMD EPYC Processor (with IBPB)",
> >  .cache_info = _cache_info,
> > +.auto_topoext = 1,
> >  },
> >  };
> >
> > @@ -4672,6 +4674,11 @@ static void x86_cpu_expand_features(X86CPU
> *cpu, Error **errp)
> >  x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x800A);
> >  }
> >
> > +/* TOPOEXT feature requires 0x801E */
> > +if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) {
> > +x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> > +}
> 
> I suggest moving this hunk to a separate patch.  I'm not 100%

Sure. Will move it to separate patch.

> sure yet if this will require compat_props code to disable
> auto-xlevel-increase on older machine-types.
> 
> --
> Eduardo



Re: [Qemu-devel] [PATCH v13 3/5] i386: Enable TOPOEXT feature on AMD EPYC CPU

2018-06-11 Thread Eduardo Habkost
On Fri, Jun 08, 2018 at 06:56:19PM -0400, Babu Moger wrote:
> Enable TOPOEXT feature on EPYC CPU. This is required to support
> hyperthreading on VM guests. Also extend xlevel to 0x801E.
> 
> TOPOEXT feature is disabled for legacy machines.
> 
> Signed-off-by: Babu Moger 
> ---
>  target/i386/cpu.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index d3411ed..4dd9a82 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -2574,6 +2574,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
>  .xlevel = 0x800A,
>  .model_id = "AMD EPYC Processor",
>  .cache_info = _cache_info,
> +.auto_topoext = 1,
>  },
>  {
>  .name = "EPYC-IBPB",
> @@ -2621,6 +2622,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
>  .xlevel = 0x800A,
>  .model_id = "AMD EPYC Processor (with IBPB)",
>  .cache_info = _cache_info,
> +.auto_topoext = 1,
>  },
>  };
>  
> @@ -4672,6 +4674,11 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error 
> **errp)
>  x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x800A);
>  }
>  
> +/* TOPOEXT feature requires 0x801E */
> +if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) {
> +x86_cpu_adjust_level(cpu, >cpuid_min_xlevel, 0x801E);
> +}

I suggest moving this hunk to a separate patch.  I'm not 100%
sure yet if this will require compat_props code to disable
auto-xlevel-increase on older machine-types.

-- 
Eduardo