From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H. Peter Anvin" Subject: Re: [PATCH v4] eal_common_cpuflags: Fix %rbx corruption, and simplify the code Date: Tue, 25 Mar 2014 10:37:18 -0700 Message-ID: <5331BECE.3070601@linux.intel.com> References: <20140320163921.GC7721@hmsreliant.think-freely.org> <1395767000-28709-1-git-send-email-nhorman@tuxdriver.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit To: Neil Horman , dev-VfR2kkLFssw@public.gmane.org Return-path: In-Reply-To: <1395767000-28709-1-git-send-email-nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" On 03/25/2014 10:03 AM, Neil Horman wrote: > int > rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature) > { > - int value; > + const struct feature_entry *feat; > + cpuid_registers_t regs; > + static uint32_t max_leaf = 0; > + > + if (!max_leaf) { > + /* Get the max input leaf for this processor */ > + rte_cpu_get_features(0, 0, regs); > + max_leaf = regs[REG_EAX]; > + } > > if (feature >= RTE_CPUFLAG_NUMFLAGS) > /* Flag does not match anything in the feature tables */ > return -ENOENT; > > - /* get value of the register containing the desired feature */ > - value = rte_cpu_get_features(cpu_feature_table[feature].params); > + feat = &cpu_feature_table[feature]; > + > + if (!feat->leaf) > + /* This entry in the table wasn't filled out! */ > + return -EFAULT; > + if (feat->leaf > max_leaf) > + return -EINVAL; This doesn't quite work. The max_leaf is per CPUID "group", i.e. the 8000xxxx CPUID leaves have a different limit than 0000xxxx leaves. So I would just do this as: rte_cpu_get_features(feat->leaf & 0xffff0000, 0, regs); if (((regs[REG_EAX] ^ feat->leaf) & 0xffff0000) || regs[REG_EAX] < feat->leaf) return 0; Returning 0 is the right thing, because this is a legitimate instance of "this feature is not supported." The first part is a sanity check that the CPUID leaf group is supported at all; the second part is the actual limit check. -hpa