[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] libs/light: use the cpuid feature names from cpufeatureset.h


  • To: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 13 Jun 2023 13:01:47 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YMwdBqaoEcIUxdHwAO9oIQE1YEouS7LZTFXu/dIPxD8=; b=PHr4oulHzsmqLqjifu0YNsn2pEDN+Kposwf/QNgoZP2Kqi9uMQ8x6PWFpgAAuyctzcGhvJP6ArqjIau+IPFS9xg5zIR7ypqU8B5B3e6osRkJ4Bg8mZzPnwkJ4d+TUFIOtqJ7gQT32aqr3uKhxxskos+iRzialiDMk8rTvmoAmbUoQ/Iz5qpPLvAYql7G5GQCgq82OHZQtRY3GqX5QWcRU37hAUCPiyHonI+WGbwbij3JyYejJ9mxjSo5gyeKHo9NgeJ70C8g5mZ/uH1wZg6XGn1fY/LNyYIZR2SKqRZKCj4YsnaEnNXCDa6/xCG1W00OqBtOaBC1HcBHW0PW2gvttw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ErxQRWYI3NU4h6TpySeaaHEQnB4fV4DqFBJsmvIizImXAuhQYwxL2E9x7CYeg0jkg1yaNLZIC9+rk+lfVYft9ZOInIMO+65XS3rvYvjVAQQKXEb3zF40caD/Bj0VYFL9FwhuNcZARuX938M6K/HbyRFOv/tHyf3pbsSP6g9dboy7PnWnoG2bwdV1sgp4DehDOZl4HNQmEstxVXa0aUYx1aj7nosZSCNggh88U56g4Ms/3InALqibfQA8h707t7PRZBIBIrTpFEhV1rudHOLJQZpZuzt5zr2ERX0QI2tzLHKjjoe+qioCUjhd5hpm3XhPXh9tL1HrG66q8QXq4yH88g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, andrew.cooper3@xxxxxxxxxx, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Tue, 13 Jun 2023 11:02:03 +0000
  • Ironport-data: A9a23:z/kTYqPHPQG5viDvrR2ClsFynXyQoLVcMsEvi/4bfWQNrUpx1zVWz jZLC2GPPaqCMTT9fIslbIu0oR4H65HQn4RjGgto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGjxSs/rrRC9H5qyo42tG5wdmPJingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0uhMDyZ// KAKEh8UMRWA187n8Kq2UuY506zPLOGzVG8ekldJ6GiDSNoDH9XESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+PtxujeKpOBy+OGF3N79YNuFSN8Thk+Fj mnH4374ElcRM9n3JT+tqyv22rCRzX+nMG4UPLvg9fUtnmDK+jdQVBk4eGCfqNuGtmfrDrqzL GRRoELCt5Ma5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWbkAbShZRZdpgs9U5LRQo2 UWOhMjBHiF0vfueTnf1y1uPhTa7OCxQIWpcYyYBFFEB+4O6/9h1iQ/TRNF+FqLzlsfyBTz73 zGNqm45mqkXiskIka68+Dgrng6Rm3QAdSZtji2/Y45vxlklDGJ5T+REMWTm0Ms=
  • Ironport-hdrordr: A9a23:K9Nauq13Q18vwtrCfcZfJQqjBNEkLtp133Aq2lEZdPU1SKylfq WV98jzuiWYtN98YhsdcLO7WZVoP0myyXcd2+B4AV7IZmXbUQWTQr1f0Q==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Jun 13, 2023 at 11:44:51AM +0100, Anthony PERARD wrote:
> On Mon, Jun 05, 2023 at 12:36:57PM +0200, Roger Pau Monne wrote:
> > The current implementation in libxl_cpuid_parse_config() requires
> > keeping a list of cpuid feature bits that should be mostly in sync
> > with the contents of cpufeatureset.h.
> > 
> > Avoid such duplication by using the automatically generated list of
> > cpuid features in INIT_FEATURE_NAMES in order to map feature names to
> > featureset bits, and then translate from featureset bits into cpuid
> > leaf, subleaf, register tuple.
> > 
> > Note that the full contents of the previous cpuid translation table
> > can't be removed.  That's because some feature names allowed by libxl
> > are not described in the featuresets, or because naming has diverged
> > and the previous nomenclature is preserved for compatibility reasons.
> > 
> > Should result in no functional change observed by callers, albeit some
> > new cpuid features will be available as a result of the change.
> 
> I've looked at the removed lists, and some cpuid flag name might be
> missing with this patch.
> 
> When looking in "libxl_cpuid.c" and
> tools/include/xen/lib/x86/cpuid-autogen.h (INIT_FEATURE_NAMES), I found
> that some flags removed from libxl_cpuid.c seems to be missing with this
> patch:
>     "sse4_1"
>     "sse4_2"
>     "tsc_adjust"
>     "cmt"

Hm, I got confused with the _ vs - notation, and with cmt I wrongly
deleted it I guess.

> I did the same with the list removed from the man page, and those
> flags are missing (some were probably also missing before, so probably
> not a problem:
>     "avx512ifma"
>     "avx512vbmi"

Those two where already missing, so I'm not planning to add those.

>     "cmt"
>     "sse4_1"
>     "sse4_2"
>     "tsc_adjust"

Those are an oversight and will be added back to cpuid_flags array.

> 
> So, at least for the first list, is it a problem? Or did I failed to
> check them properly?
> (It seems that "cmt" or "tsc_adjust" for example comes from libvirt,
> 90b2a267c19c ("libxl: add more cpuid flags handling"))
> 
> > While there constify cpuid_flags name field.
> > 
> > Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> > ---
> > diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in
> > index 24ac92718288..c5c5b8716521 100644
> > --- a/docs/man/xl.cfg.5.pod.in
> > +++ b/docs/man/xl.cfg.5.pod.in
> > @@ -2010,24 +2010,12 @@ proccount procpkg stepping
> >  
> >  =back
> >  
> > -List of keys taking a character:
> > +List of keys taking a character can be found in the public header file
> > +L<arch-x86/cpufeatureset.h|http://xenbits.xen.org/docs/unstable/hypercall/x86_64/include,public,arch-x86,cpufeatureset.h.html>
> 
> https:// ;-)
> 
> And this probably want to be "xenbits.xenproject.org"
> 
> Also, I think there's maybe an issue with this link. Maybe someone can
> assume that "TM1" takes a character, but that flags I think would get
> rejected, issue with upper case vs lower case. Then, if we deal with
> the casing, we still have feature like "AVX512_IFMA", which would only
> be recognize if written "avx512-ifma", so issue with "-" vs "_".

Right, it's not perfect, but I don't see much better way if we want to
keep the documentation in sync.

> > diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c
> > index f5ce9f97959c..0c7ffff416fe 100644
> > --- a/tools/libs/light/libxl_cpuid.c
> > +++ b/tools/libs/light/libxl_cpuid.c
> > @@ -342,6 +214,28 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list 
> > *cpuid, const char* str)
> >          if(!strncmp(str, flag->name, sep - str) && flag->name[sep - str] 
> > == 0)
> >              break;
> >      }
> > +    if (flag->name == NULL) {
> > +        const struct feature_name *feat;
> > +        /* Provide a NUL terminated feature name to the search helper. */
> > +        char *name = strndup(str, sep - str);
> > +
> > +        if (name == NULL)
> > +            return 4;
> 
> out-of-memory are usually fatal in libxl. Any reason to use `strndup`
> instead of `libxl__strndup`? I guess we don't have any libxl_ctx, so we
> can't use the libxl function.

Yes, even NO_GC requires a CTX.

> So, instead of returning an arbitrary integer that isn't returned yet by
> the function, could you return ERROR_NOMEM?

That would be my preference, but the function already returns
(arbitrary) integers as error codes, so I'm not sure whether
ERROR_NOMEM won't alias with one of the existing error codes.

> I wonder if it would be possible to use a buffer on the stack instead,
> but it might not be worth the effort to find the right size.

Hm, I could in theory try to do that, as feature names tend to be
small, however I think the implementation would be fragile, as the
length of the feature name is based on user input (iow: we would do an
alloca() using a user provided size).

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.