* [PATCH RFC] kvm: x86: AVX512_BF16 feature support
@ 2019-06-20 11:21 Jing Liu
2019-06-20 11:21 ` [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest Jing Liu
0 siblings, 1 reply; 7+ messages in thread
From: Jing Liu @ 2019-06-20 11:21 UTC (permalink / raw)
To: pbonzini, kvm; +Cc: linux-kernel, jing2.liu, jing2.liu
The patch focuses on a new instruction AVX512_BF16 support for kvm guest, defined
as CPUID.(EAX=7,ECX=1):EAX[bit 5], see spec[1].
The kvm implementation depends on kernel patch[2] which is in lkml discussion.
References:
[1] https://software.intel.com/sites/default/files/managed/c5/15/\
architecture-instruction-set-extensions-programming-reference.pdf
[2] https://lkml.org/lkml/2019/6/19/912
Jing Liu (1):
kvm: x86: Expose AVX512_BF16 feature to guest
arch/x86/kvm/cpuid.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest 2019-06-20 11:21 [PATCH RFC] kvm: x86: AVX512_BF16 feature support Jing Liu @ 2019-06-20 11:21 ` Jing Liu 2019-06-20 12:16 ` Paolo Bonzini 0 siblings, 1 reply; 7+ messages in thread From: Jing Liu @ 2019-06-20 11:21 UTC (permalink / raw) To: pbonzini, kvm; +Cc: linux-kernel, jing2.liu, jing2.liu AVX512 BFLOAT16 instructions support 16-bit BFLOAT16 floating-point format (BF16) for deep learning optimization. Intel adds AVX512 BFLOAT16 feature in CooperLake, which is CPUID.7.1.EAX[5]. Detailed information of the CPUID bit can be found here, https://software.intel.com/sites/default/files/managed/c5/15/\ architecture-instruction-set-extensions-programming-reference.pdf. Signed-off-by: Jing Liu <jing2.liu@linux.intel.com> --- arch/x86/kvm/cpuid.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index e18a9f9..10be53f 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -484,6 +484,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, entry->edx = 0; break; case 7: { + int i, times = entry->eax; entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; /* Mask ebx against host capability word 9 */ if (index == 0) { @@ -507,12 +508,23 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, * if the host doesn't support it. */ entry->edx |= F(ARCH_CAPABILITIES); - } else { + } else if (index > times) { + entry->eax = 0; entry->ebx = 0; entry->ecx = 0; entry->edx = 0; } - entry->eax = 0; + for (i = 1; i <= times; i++) { + if (*nent >= maxnent) + goto out; + do_cpuid_1_ent(&entry[i], function, i); + entry[i].eax &= F(AVX512_BF16); + entry[i].ebx = 0; + entry[i].ecx = 0; + entry[i].edx = 0; + entry[i].flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + ++*nent; + } break; } case 9: -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest 2019-06-20 11:21 ` [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest Jing Liu @ 2019-06-20 12:16 ` Paolo Bonzini 2019-06-20 15:09 ` Liu, Jing2 0 siblings, 1 reply; 7+ messages in thread From: Paolo Bonzini @ 2019-06-20 12:16 UTC (permalink / raw) To: Jing Liu, kvm; +Cc: linux-kernel, jing2.liu On 20/06/19 13:21, Jing Liu wrote: > + for (i = 1; i <= times; i++) { > + if (*nent >= maxnent) > + goto out; > + do_cpuid_1_ent(&entry[i], function, i); > + entry[i].eax &= F(AVX512_BF16); > + entry[i].ebx = 0; > + entry[i].ecx = 0; > + entry[i].edx = 0; > + entry[i].flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; > + ++*nent; This woud be wrong for i > 1, so instead make this if (entry->eax >= 1) and define F(AVX512_BF16) as a new constant kvm_cpuid_7_1_eax_features. Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest 2019-06-20 12:16 ` Paolo Bonzini @ 2019-06-20 15:09 ` Liu, Jing2 2019-06-24 3:10 ` Jing Liu 0 siblings, 1 reply; 7+ messages in thread From: Liu, Jing2 @ 2019-06-20 15:09 UTC (permalink / raw) To: Paolo Bonzini, kvm; +Cc: linux-kernel, jing2.liu Hi Paolo, On 6/20/2019 8:16 PM, Paolo Bonzini wrote: > On 20/06/19 13:21, Jing Liu wrote: >> + for (i = 1; i <= times; i++) { >> + if (*nent >= maxnent) >> + goto out; >> + do_cpuid_1_ent(&entry[i], function, i); >> + entry[i].eax &= F(AVX512_BF16); >> + entry[i].ebx = 0; >> + entry[i].ecx = 0; >> + entry[i].edx = 0; >> + entry[i].flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; >> + ++*nent; > > This woud be wrong for i > 1, so instead make this > > if (entry->eax >= 1) > I am confused about the @index parameter. @index seems not used for every case except 0x07. Since the caller function only has @index=0, so all other cases except 0x07 put cpuid info from subleaf=0 to max subleaf. What do you think about @index in current function? Does it mean, we need put cpuid from index to max subleaf to @entry[i]? If so, the logic seems as follows, if (index == 0) { // Put subleaf 0 into @entry // Put subleaf 1 into @entry[1] } else if (index < entry->eax) { // Put subleaf 1 into @entry } else { // Put all zero into @entry } But this seems not identical with other cases, for current caller function. Or we can simply ignore @index in 0x07 and just put all possible subleaf info back? > and define F(AVX512_BF16) as a new constant kvm_cpuid_7_1_eax_features. > Got it. Thanks, Jing > Paolo > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest 2019-06-20 15:09 ` Liu, Jing2 @ 2019-06-24 3:10 ` Jing Liu 2019-06-24 8:33 ` Paolo Bonzini 0 siblings, 1 reply; 7+ messages in thread From: Jing Liu @ 2019-06-24 3:10 UTC (permalink / raw) To: Paolo Bonzini, kvm; +Cc: linux-kernel, jing2.liu Hi Paolo, After thinking more, I found way to satisfy all cases in a easy way. How about things like this? @@ -507,12 +510,26 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 fu * if the host doesn't support it. */ entry->edx |= F(ARCH_CAPABILITIES); + } else if (index == 1) { + entry->eax &= kvm_cpuid_7_1_eax_x86_features; + entry->ebx = 0; + entry->ecx = 0; + entry->edx = 0; } else { + entry->eax = 0; entry->ebx = 0; entry->ecx = 0; entry->edx = 0; } - entry->eax = 0; + + if (index == 0 && entry->eax >= 1) { + entry[1].eax &= kvm_cpuid_7_1_eax_x86_features; + entry[1].ebx = 0; + entry[1].ecx = 0; + entry[1].edx = 0; + entry[1].flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + ++*nent; + } break; } Or you prefer that I update this into another version later? Thanks! Jing On 6/20/2019 11:09 PM, Liu, Jing2 wrote: > Hi Paolo, > > On 6/20/2019 8:16 PM, Paolo Bonzini wrote: >> On 20/06/19 13:21, Jing Liu wrote: >>> + for (i = 1; i <= times; i++) { >>> + if (*nent >= maxnent) >>> + goto out; >>> + do_cpuid_1_ent(&entry[i], function, i); >>> + entry[i].eax &= F(AVX512_BF16); >>> + entry[i].ebx = 0; >>> + entry[i].ecx = 0; >>> + entry[i].edx = 0; >>> + entry[i].flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; >>> + ++*nent; >> >> This woud be wrong for i > 1, so instead make this >> >> if (entry->eax >= 1) >> > > I am confused about the @index parameter. @index seems not used for > every case except 0x07. Since the caller function only has @index=0, so > all other cases except 0x07 put cpuid info from subleaf=0 to max subleaf. > > What do you think about @index in current function? Does it mean, we > need put cpuid from index to max subleaf to @entry[i]? If so, the logic > seems as follows, > > if (index == 0) { > // Put subleaf 0 into @entry > // Put subleaf 1 into @entry[1] > } else if (index < entry->eax) { > // Put subleaf 1 into @entry > } else { > // Put all zero into @entry > } > > But this seems not identical with other cases, for current caller > function. Or we can simply ignore @index in 0x07 and just put all possible > subleaf info back? > >> and define F(AVX512_BF16) as a new constant kvm_cpuid_7_1_eax_features. >> > Got it. > > > Thanks, > Jing > >> Paolo >> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest 2019-06-24 3:10 ` Jing Liu @ 2019-06-24 8:33 ` Paolo Bonzini 2019-06-24 12:06 ` Jing Liu 0 siblings, 1 reply; 7+ messages in thread From: Paolo Bonzini @ 2019-06-24 8:33 UTC (permalink / raw) To: Jing Liu, kvm; +Cc: linux-kernel, jing2.liu On 24/06/19 05:10, Jing Liu wrote: >> What do you think about @index in current function? Does it mean, we >> need put cpuid from index to max subleaf to @entry[i]? If so, the logic >> seems as follows, >> >> if (index == 0) { >> // Put subleaf 0 into @entry >> // Put subleaf 1 into @entry[1] >> } else if (index < entry->eax) { >> // Put subleaf 1 into @entry >> } else { >> // Put all zero into @entry >> } >> >> But this seems not identical with other cases, for current caller >> function. Or we can simply ignore @index in 0x07 and just put all >> possible subleaf info back? There are indeed quite some cleanups to be made there. Let me post a series as soon as possible, and you can base your work on it. Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest 2019-06-24 8:33 ` Paolo Bonzini @ 2019-06-24 12:06 ` Jing Liu 0 siblings, 0 replies; 7+ messages in thread From: Jing Liu @ 2019-06-24 12:06 UTC (permalink / raw) To: Paolo Bonzini, kvm; +Cc: linux-kernel, jing2.liu Hi Paolo, On 6/24/2019 4:33 PM, Paolo Bonzini wrote: > On 24/06/19 05:10, Jing Liu wrote: >>> What do you think about @index in current function? Does it mean, we >>> need put cpuid from index to max subleaf to @entry[i]? If so, the logic >>> seems as follows, >>> >>> if (index == 0) { >>> // Put subleaf 0 into @entry >>> // Put subleaf 1 into @entry[1] >>> } else if (index < entry->eax) { >>> // Put subleaf 1 into @entry >>> } else { >>> // Put all zero into @entry >>> } >>> >>> But this seems not identical with other cases, for current caller >>> function. Or we can simply ignore @index in 0x07 and just put all >>> possible subleaf info back? > > There are indeed quite some cleanups to be made there. Let me post a > series as soon as possible, and you can base your work on it. > Thanks. I just had another mail (replying you in this serial) appending some codes to deal with case 7. If you prefer to firstly cleanup, I can wait for the patch then. :) Thanks, Jing > Paolo > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-06-24 12:06 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-06-20 11:21 [PATCH RFC] kvm: x86: AVX512_BF16 feature support Jing Liu 2019-06-20 11:21 ` [PATCH RFC] kvm: x86: Expose AVX512_BF16 feature to guest Jing Liu 2019-06-20 12:16 ` Paolo Bonzini 2019-06-20 15:09 ` Liu, Jing2 2019-06-24 3:10 ` Jing Liu 2019-06-24 8:33 ` Paolo Bonzini 2019-06-24 12:06 ` Jing Liu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox