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

Re: [PATCH] x86/cpuid: Calculate FEATURESET_NR_ENTRIES more helpfully


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 15 May 2023 09:46:57 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=r4s3gTU5b46ruyQ52PiBJHNQaP6RsxtFLi8QL1fpfaY=; b=CYrmISoSJIKVbnn6Ll7dA7l7DdCYQRz8FtMSKJ6MvEuehwXBe3r6ndgwBUWWJW9OxxViTRfmnYCWHmxsgPYAI2kQK7nZBzWj263Unr/fAggo2DEpWUeCJyJAhkEteiqMBrtKU+RRbOSqZNP3FJaflK3RoyujuOOaHPyl6xQaW3USYBoYVNcbI1gmJ3ea/ObZ/47/++n0xFJ1IMgZ98g5xkO4b+Do4chWsQt7YQdNSNHxfFc/i5N3AA1RYKzSsY1HuKfMAjIgdIxjocVOIjVqVdw6JscpuxeOqxJY69UCu47CeMGbW311fg9Dx9brciZq3fyuDzWLFoL1Bb8qPotxfQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IAqaAcranOCHYApk8yRxSAMSNnO12Xi8y7C/Q/j4MFdyNf/C4eJb9+c5vvC0khuGbSClzrfMtuy337L4m+Wm0M6Ecg7KugPLZAfe0K/NBgHWiwnA72PTiTm3i3tGzo492tbRzLdVOKGx0ek5waunfEH9ch0ILBw5JW9FN83VZTWYjPvkws9FMrur889b/OLbROAu6AGm583rIVl+6+0SzCrbke/8oIfRbV0uy6uBbxqAOr5hCwHBhVP02sZE1t2+Arq+M0zQONqGlOo4ZvnPcenu/4RdW8e8kyrN+v6IDVbtB8FUcMm1os4Bcwb1AIrafFImJ1eaGBIVzqCEvdF91A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 15 May 2023 07:47:33 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 12.05.2023 14:45, Andrew Cooper wrote:
> When adding new featureset words, it is convenient to split the work into
> several patches.  However, GCC 12 spotted that the way we prefer to split the
> work results in a real (transient) breakage whereby the policy <-> featureset
> helpers perform out-of-bounds accesses on the featureset array.
> 
> Fix this by having gen-cpuid.py calculate FEATURESET_NR_ENTRIES from the
> comments describing the word blocks, rather than from the XEN_CPUFEATURE()
> with the greatest value.
> 
> For simplicty, require that the word blocks appear in order.  This can be
> revisted if we find a good reason to have blocks out of order.
> 
> No functional change.
> 
> Reported-by: Jan Beulich <jbeulich@xxxxxxxx>
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

As far as my Python goes:
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
Just one remark further down.

> This supercedes the entire "x86: Fix transient build breakage with featureset
> additions" series, but doesn't really feel as if it ought to be labelled v2

Thank you for re-doing this altogether. I think it's more safe this way,
and it now being less intrusive is imo also beneficial.

> --- a/xen/tools/gen-cpuid.py
> +++ b/xen/tools/gen-cpuid.py
> @@ -50,13 +50,37 @@ def parse_definitions(state):
>          "\s+([\s\d]+\*[\s\d]+\+[\s\d]+)\)"
>          "\s+/\*([\w!]*) .*$")
>  
> +    word_regex = re.compile(
> +        r"^/\* .* word (\d*) \*/$")
> +    last_word = -1
> +
>      this = sys.modules[__name__]
>  
>      for l in state.input.readlines():
> -        # Short circuit the regex...
> -        if not l.startswith("XEN_CPUFEATURE("):
> +
> +        # Short circuit the regexes...
> +        if not (l.startswith("XEN_CPUFEATURE(") or
> +                l.startswith("/* ")):
>              continue
>  
> +        # Handle /* ... word $N */ lines
> +        if l.startswith("/* "):
> +
> +            res = word_regex.match(l)
> +            if res is None:
> +                continue # Some other comment
> +
> +            word = int(res.groups()[0])
> +
> +            if word != last_word + 1:
> +                raise Fail("Featureset word %u out of order (last word %u)"
> +                           % (word, last_word))
> +
> +            last_word = word
> +            state.nr_entries = word + 1
> +            continue
> +
> +        # Handle XEN_CPUFEATURE( lines
>          res = feat_regex.match(l)
>  
>          if res is None:
> @@ -94,6 +118,15 @@ def parse_definitions(state):
>      if len(state.names) == 0:
>          raise Fail("No features found")
>  
> +    if state.nr_entries == 0:
> +        raise Fail("No featureset word info found")
> +
> +    max_val = max(state.names.keys())
> +    if (max_val >> 5) + 1 > state.nr_entries:

Maybe

    if (max_val >> 5) >= state.nr_entries:

?

Jan



 


Rackspace

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