From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1168056AbcKAIqr (ORCPT ); Tue, 1 Nov 2016 04:46:47 -0400 Received: from mail.skyhub.de ([78.46.96.112]:54734 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1168038AbcKAIqo (ORCPT ); Tue, 1 Nov 2016 04:46:44 -0400 Date: Tue, 1 Nov 2016 09:46:41 +0100 From: Borislav Petkov To: He Chen Cc: Paolo Bonzini , "Luc, Piotr" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "tglx@linutronix.de" , "x86@kernel.org" , "hpa@zytor.com" , "mingo@redhat.com" , "Kang, Luwei" , "rkrcmar@redhat.com" Subject: Re: [PATCH] x86/cpuid: expose AVX512_4VNNIW and AVX512_4FMAPS features to kvm guest Message-ID: <20161101084641.2a66qov3itzfbmnt@pd.tnic> References: <20161028122123.24i3synevehn6r3p@pd.tnic> <425702906.9319122.1477743677017.JavaMail.zimbra@redhat.com> <1477905033.32008.5.camel@intel.com> <20161031095312.dzv3rj2fqgjjsy7w@pd.tnic> <1477908811.32008.20.camel@intel.com> <20161031103050.k7b2l64blhmv33mw@pd.tnic> <48ef617f-c438-cfcf-6f0c-1eb3b59820ff@redhat.com> <20161031110549.ukajhnawxw6mftor@pd.tnic> <6cb0bdc3-69f6-1c17-5576-82fbe42e5457@redhat.com> <20161101074850.GA11430@he> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20161101074850.GA11430@he> User-Agent: NeoMutt/20161014 (1.7.1) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 01, 2016 at 03:48:50PM +0800, He Chen wrote: > Before sending a patch, let me check if my understanding is right... > I will add a helper in scattered.c like: > > unsigned int get_scattered_cpuid_features(unsigned int level, > unsigned int sub_leaf, enum cpuid_regs reg) > { > u32 val = 0; > const struct cpuid_bit *cb; > > for (cb = cpuid_bits; cb->feature; cb++) { Right, we can improve that by keeping cpuid_bit.level sorted so that you can break out early if the level is exceeded. For that please sort it and add a comment stating that the leaf should be kept sorted ontop of it. And then you do something like this: u32 get_scattered_cpuid_leaf(unsigned int level, unsigned int sub_leaf, enum cpuid_regs reg) { u32 cpuid_val = 0; for (cb = cpuid_bits; cb->feature; cb++) { if (level < cb->level) continue; if (level > cb->level) break; if (cb->reg == reg && sub_leaf == cb->sub_leaf) { if (cpu_has(cb->feature)) cpuid_val |= BIT(cb->bit); } } return cpuid_val; } Completely untested, of course. -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply.