Skip to contentSkip to conversation

tools/libxenguest: Fix max_extd_leaf calculation for legacy restore

PATCH In review Andrew Cooper 3 participants 4 messages Jul 2, 2021 – Jul 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxenguest: Fix max_extd_leaf calculation for legacy restore

0x1c is lower than any value which will actually be observed in p->extd.max_leaf, but higher than the logical 9 leaves worth of extended data on Intel systems, causing x86_cpuid_copy_to_buffer() to fail with -ENOBUFS.

Correct the calculation.

The problem was first noticed in c/s 34990446ca9 "libxl: don't ignore the return value from xc_cpuid_apply_policy" but introduced earlier.

Fixes 34990446ca91 ("libxl: don't ignore the return value from xc_cpuid_apply_policy")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Olaf Hering <[email protected]>

Olaf - as I've changed the fix, I haven't included your T-by tag, but I'm confident that this will suitably address the issue.

---
 tools/libs/guest/xg_cpuid_x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libs/guest/xg_cpuid_x86.c +1 -1
index e01d657e0394..0c9c4fefc1ef 100644
@@ -513,7 +513,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
         /* Clamp maximum leaves to the ones supported on 4.12. */
         p->basic.max_leaf = min(p->basic.max_leaf, 0xdu);
         p->feat.max_subleaf = 0;
-        p->extd.max_leaf = min(p->extd.max_leaf, 0x1cu);
+        p->extd.max_leaf = min(p->extd.max_leaf, 0x8000001c);
     }
 
     if ( featureset )
Signature · 1 line
2.11.0
#1 lore raw

Am Fri, 2 Jul 2021 20:03:34 +0100
schrieb Andrew Cooper <[email protected]>:

Quoted 1 line
Fixes 34990446ca91 ("libxl: don't ignore the return value from xc_cpuid_apply_policy")

I think it fixes 111c8c33a8a18588f3da3c5dbb7f5c63ddb98ce5 ("x86/cpuid: do not expand max leaves on restore"), 34990446ca91 just revealed the bug?

Either way, this new variant is what I had tested last week. But with a trailing "u" for the constant. This detail may not make a difference in practice.

Olaf

#2 lore raw
Quoted 5 lines · Olaf Hering

Am Fri, 2 Jul 2021 20:03:34 +0100
schrieb Andrew Cooper <[email protected]>:

Quoted 1 line
Fixes 34990446ca91 ("libxl: don't ignore the return value from xc_cpuid_apply_policy")

I think it fixes 111c8c33a8a18588f3da3c5dbb7f5c63ddb98ce5 ("x86/cpuid: do not expand max leaves on restore"), 34990446ca91 just revealed the bug?

Urgh... That's what I intended to write here.  I'll fix up.

Quoted 1 line

Either way, this new variant is what I had tested last week. But with a trailing "u" for the constant. This detail may not make a difference in practice.

The trailing u doesn't matter in this case.  Furthermore, the way min() is written, the compiler will object if it were to be wrong.

~Andrew

Reviewed-by on v1 1/1
#3 lore raw
In reply to Andrew Cooper
Quoted 4 lines · Andrew Cooper

0x1c is lower than any value which will actually be observed in p->extd.max_leaf, but higher than the logical 9 leaves worth of extended data on Intel systems, causing x86_cpuid_copy_to_buffer() to fail with -ENOBUFS.

Quoted 8 lines

Correct the calculation.

The problem was first noticed in c/s 34990446ca9 "libxl: don't ignore the return value from xc_cpuid_apply_policy" but introduced earlier.

Fixes 34990446ca91 ("libxl: don't ignore the return value from xc_cpuid_apply_policy")

perhaps with, as suggested by Olaf, the Fixes: line changed.

Jan