* [PATCH] i386/cpu: mark CPU properties as const
@ 2026-11-19 18:08 John Snow
2026-11-19 18:40 ` Peter Maydell
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: John Snow @ 2026-11-19 18:08 UTC (permalink / raw)
To: qemu-devel; +Cc: Zhao Liu, Paolo Bonzini, kvm, Marcelo Tosatti, John Snow
Currently, these large property tables are loaded in the read-write
`.data` segment; by marking them as const they can be loaded as part
of `.rodata` instead, where these tables can be shared between multiple
instances of QEMU as RssFile memory instead of RssAnon memory.
Signed-off-by: John Snow <jsnow@redhat.com>
---
target/i386/cpu-internal.h | 2 +-
target/i386/cpu-system.c | 2 +-
target/i386/cpu.c | 30 +++++++++++++++---------------
target/i386/kvm/tdx.c | 2 +-
4 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/target/i386/cpu-internal.h b/target/i386/cpu-internal.h
index 7f234cfd1b7..fbe767ca906 100644
--- a/target/i386/cpu-internal.h
+++ b/target/i386/cpu-internal.h
@@ -53,7 +53,7 @@ typedef struct FeatureWordInfo {
uint64_t no_autoenable_flags;
} FeatureWordInfo;
-extern FeatureWordInfo feature_word_info[];
+extern const FeatureWordInfo feature_word_info[];
void x86_cpu_expand_features(X86CPU *cpu, Error **errp);
diff --git a/target/i386/cpu-system.c b/target/i386/cpu-system.c
index c03cece7bd8..50de1170447 100644
--- a/target/i386/cpu-system.c
+++ b/target/i386/cpu-system.c
@@ -62,7 +62,7 @@ static QDict *x86_cpu_static_props(void)
}
for (w = 0; w < FEATURE_WORDS; w++) {
- FeatureWordInfo *fi = &feature_word_info[w];
+ const FeatureWordInfo *fi = &feature_word_info[w];
int bit;
for (bit = 0; bit < 64; bit++) {
if (!fi->feat_names[bit]) {
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index eab0d5a4d4a..988193207f8 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -78,7 +78,7 @@ struct CPUID2CacheDescriptorInfo {
* TLB, prefetch and sectored cache related descriptors are not included.
* From Intel SDM Volume 2A, CPUID instruction
*/
-struct CPUID2CacheDescriptorInfo cpuid2_cache_descriptors[] = {
+const struct CPUID2CacheDescriptorInfo cpuid2_cache_descriptors[] = {
[0x06] = { .level = 1, .type = INSTRUCTION_CACHE, .size = 8 * KiB,
.associativity = 4, .line_size = 32, },
[0x08] = { .level = 1, .type = INSTRUCTION_CACHE, .size = 16 * KiB,
@@ -241,7 +241,7 @@ static uint8_t cpuid2_cache_descriptor(CPUCacheInfo *cache, bool *unmacthed)
assert(cache->line_size > 0);
assert(cache->associativity > 0);
for (i = 0; i < ARRAY_SIZE(cpuid2_cache_descriptors); i++) {
- struct CPUID2CacheDescriptorInfo *d = &cpuid2_cache_descriptors[i];
+ const struct CPUID2CacheDescriptorInfo *d = &cpuid2_cache_descriptors[i];
if (d->level == cache->level && d->type == cache->type &&
d->size == cache->size && d->line_size == cache->line_size &&
d->associativity == cache->associativity) {
@@ -1047,7 +1047,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
CPUID_8000_0021_EAX_NULL_SEL_CLR_BASE | \
CPUID_8000_0021_EAX_KERNEL_FEATURES)
-FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
+const FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
[FEAT_1_EDX] = {
.type = CPUID_FEATURE_WORD,
.feat_names = {
@@ -1879,7 +1879,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
bool is_feature_word_cpuid(uint32_t feature, uint32_t index, int reg)
{
- FeatureWordInfo *wi;
+ const FeatureWordInfo *wi;
FeatureWord w;
for (w = 0; w < FEATURE_WORDS; w++) {
@@ -2223,7 +2223,7 @@ static inline uint64_t x86_cpu_xsave_xss_components(X86CPU *cpu)
*/
static uint64_t x86_cpu_get_migratable_flags(X86CPU *cpu, FeatureWord w)
{
- FeatureWordInfo *wi = &feature_word_info[w];
+ const FeatureWordInfo *wi = &feature_word_info[w];
CPUX86State *env = &cpu->env;
uint64_t r = 0;
int i;
@@ -2458,7 +2458,7 @@ static const CPUCaches epyc_cache_info = {
},
};
-static CPUCaches epyc_v4_cache_info = {
+static const CPUCaches epyc_v4_cache_info = {
.l1d_cache = &(CPUCacheInfo) {
.type = DATA_CACHE,
.level = 1,
@@ -2512,7 +2512,7 @@ static CPUCaches epyc_v4_cache_info = {
},
};
-static CPUCaches epyc_v5_cache_info = {
+static const CPUCaches epyc_v5_cache_info = {
.l1d_cache = &(CPUCacheInfo) {
.type = DATA_CACHE,
.level = 1,
@@ -7422,7 +7422,7 @@ static const TypeInfo max_x86_cpu_type_info = {
.class_init = max_x86_cpu_class_init,
};
-static char *feature_word_description(FeatureWordInfo *f)
+static char *feature_word_description(const FeatureWordInfo *f)
{
assert(f->type == CPUID_FEATURE_WORD || f->type == MSR_FEATURE_WORD);
@@ -7463,7 +7463,7 @@ void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask,
const char *verbose_prefix)
{
CPUX86State *env = &cpu->env;
- FeatureWordInfo *f = &feature_word_info[w];
+ const FeatureWordInfo *f = &feature_word_info[w];
int i;
g_autofree char *feat_word_str = feature_word_description(f);
@@ -7491,7 +7491,7 @@ void mark_forced_on_features(X86CPU *cpu, FeatureWord w, uint64_t mask,
const char *verbose_prefix)
{
CPUX86State *env = &cpu->env;
- FeatureWordInfo *f = &feature_word_info[w];
+ const FeatureWordInfo *f = &feature_word_info[w];
int i;
if (!cpu->force_features) {
@@ -7794,7 +7794,7 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v,
X86CPUFeatureWordInfoList *list = NULL;
for (w = 0; w < FEATURE_WORDS; w++) {
- FeatureWordInfo *wi = &feature_word_info[w];
+ const FeatureWordInfo *wi = &feature_word_info[w];
/*
* We didn't have MSR features when "feature-words" was
* introduced. Therefore skipped other type entries.
@@ -8111,7 +8111,7 @@ static void x86_cpu_list(void)
names = NULL;
for (i = 0; i < ARRAY_SIZE(feature_word_info); i++) {
- FeatureWordInfo *fw = &feature_word_info[i];
+ const FeatureWordInfo *fw = &feature_word_info[i];
for (j = 0; j < 64; j++) {
if (fw->feat_names[j]) {
names = g_list_append(names, (gpointer)fw->feat_names[j]);
@@ -8214,7 +8214,7 @@ static uint8_t x86_cpu_get_host_avx10_version(void)
uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w)
{
- FeatureWordInfo *wi = &feature_word_info[w];
+ const FeatureWordInfo *wi = &feature_word_info[w];
uint64_t r = 0;
uint64_t unavail = 0;
@@ -9617,7 +9617,7 @@ static void x86_cpu_adjust_level(X86CPU *cpu, uint32_t *min, uint32_t value)
static void x86_cpu_adjust_feat_level(X86CPU *cpu, FeatureWord w)
{
CPUX86State *env = &cpu->env;
- FeatureWordInfo *fi = &feature_word_info[w];
+ const FeatureWordInfo *fi = &feature_word_info[w];
uint32_t eax = fi->cpuid.eax;
uint32_t region = eax & 0xF0000000;
@@ -10497,7 +10497,7 @@ static void x86_cpu_register_feature_bit_props(X86CPUClass *xcc,
FeatureWord w,
int bitnr)
{
- FeatureWordInfo *fi = &feature_word_info[w];
+ const FeatureWordInfo *fi = &feature_word_info[w];
const char *name = fi->feat_names[bitnr];
if (!name) {
diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c
index 52bb2ec6ced..ec38e3625a6 100644
--- a/target/i386/kvm/tdx.c
+++ b/target/i386/kvm/tdx.c
@@ -885,7 +885,7 @@ static int tdx_check_features(X86ConfidentialGuest *cg, CPUState *cs)
struct kvm_cpuid_entry2 *entry;
X86CPU *cpu = X86_CPU(cs);
CPUX86State *env = &cpu->env;
- FeatureWordInfo *wi;
+ const FeatureWordInfo *wi;
FeatureWord w;
bool mismatch = false;
int r = -1;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i386/cpu: mark CPU properties as const
2026-11-19 18:08 [PATCH] i386/cpu: mark CPU properties as const John Snow
@ 2026-11-19 18:40 ` Peter Maydell
2026-11-19 18:55 ` Richard Henderson
2026-11-20 9:58 ` Zhao Liu
2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2026-11-19 18:40 UTC (permalink / raw)
To: John Snow; +Cc: qemu-devel, Zhao Liu, Paolo Bonzini, kvm, Marcelo Tosatti
On Thu, 19 Nov 2026 at 18:09, John Snow <jsnow@redhat.com> wrote:
>
> Currently, these large property tables are loaded in the read-write
> `.data` segment; by marking them as const they can be loaded as part
> of `.rodata` instead, where these tables can be shared between multiple
> instances of QEMU as RssFile memory instead of RssAnon memory.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> target/i386/cpu-internal.h | 2 +-
> target/i386/cpu-system.c | 2 +-
> target/i386/cpu.c | 30 +++++++++++++++---------------
> target/i386/kvm/tdx.c | 2 +-
> 4 files changed, 18 insertions(+), 18 deletions(-)
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i386/cpu: mark CPU properties as const
2026-11-19 18:08 [PATCH] i386/cpu: mark CPU properties as const John Snow
2026-11-19 18:40 ` Peter Maydell
@ 2026-11-19 18:55 ` Richard Henderson
2026-11-20 9:58 ` Zhao Liu
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2026-11-19 18:55 UTC (permalink / raw)
To: John Snow, qemu-devel; +Cc: Zhao Liu, Paolo Bonzini, kvm, Marcelo Tosatti
On 11/19/26 10:08, John Snow wrote:
> Currently, these large property tables are loaded in the read-write
> `.data` segment; by marking them as const they can be loaded as part
> of `.rodata` instead, where these tables can be shared between multiple
> instances of QEMU as RssFile memory instead of RssAnon memory.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> target/i386/cpu-internal.h | 2 +-
> target/i386/cpu-system.c | 2 +-
> target/i386/cpu.c | 30 +++++++++++++++---------------
> target/i386/kvm/tdx.c | 2 +-
> 4 files changed, 18 insertions(+), 18 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i386/cpu: mark CPU properties as const
2026-11-19 18:08 [PATCH] i386/cpu: mark CPU properties as const John Snow
2026-11-19 18:40 ` Peter Maydell
2026-11-19 18:55 ` Richard Henderson
@ 2026-11-20 9:58 ` Zhao Liu
2 siblings, 0 replies; 4+ messages in thread
From: Zhao Liu @ 2026-11-20 9:58 UTC (permalink / raw)
To: John Snow; +Cc: qemu-devel, Paolo Bonzini, kvm, Marcelo Tosatti, Zhao Liu
Hi John,
On Thu, Nov 19, 2026 at 01:08:59PM -0500, John Snow wrote:
> Date: Thu, 19 Nov 2026 13:08:59 -0500
> From: John Snow <jsnow@redhat.com>
> Subject: [PATCH] i386/cpu: mark CPU properties as const
>
> Currently, these large property tables are loaded in the read-write
> `.data` segment; by marking them as const they can be loaded as part
> of `.rodata` instead, where these tables can be shared between multiple
> instances of QEMU as RssFile memory instead of RssAnon memory.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> target/i386/cpu-internal.h | 2 +-
> target/i386/cpu-system.c | 2 +-
> target/i386/cpu.c | 30 +++++++++++++++---------------
> target/i386/kvm/tdx.c | 2 +-
> 4 files changed, 18 insertions(+), 18 deletions(-)
I'm fine with the "const" change, but it seems only
cpuid2_cache_descriptors can move to .rodata:
$ objdump -t build/libqemu-x86_64-softmmu.a.p/target_i386_cpu.c.o | grep -wE 'feature_word_info|cpuid2_cache_descriptors|epyc_v5_cache_info|epyc_v4_cache_info'
0000000000005fa0 l O .data.rel.ro.local 0000000000000020 epyc_v4_cache_info
0000000000005f80 l O .data.rel.ro.local 0000000000000020 epyc_v5_cache_info
0000000000000d20 g O .rodata 0000000000001284 cpuid2_cache_descriptors
00000000000060a0 g O .data.rel.ro.local 0000000000006a80 feature_word_info
I think it's because FeatureWordInfo and CPUCaches have pointer fields.
So with the commit message fixed:
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
...
Futhermore, for CPUCaches, it could embed the cache info by value:
typedef struct CPUCaches {
CPUCacheInfo l1d_cache;
CPUCacheInfo l1i_cache;
CPUCacheInfo l2_cache;
CPUCacheInfo l3_cache;
} CPUCaches;
although the cache info will be stored in .rodata, this would also give
each vCPU its own copy, so smp-cache would no longer modify the global
tables. The cost is that CPUX86State grows per vCPU (from 4 pointers to
4 full CPUCacheInfo). So, maybe there’s room for further optimization,
but that’s a separate issue, not a blocker for this patch.
For FeatureWordInfo, what I can think of right now is to make the
feature name array a fixed length like:
#define FEAT_NAME_SIZE 36 /* strlen("vmx-invept-single-context-noglobals") + 1 */
typedef struct FeatureWordInfo {
FeatureWordType type;
char feat_names[64][FEAT_NAME_SIZE];
...
} FeatureWordInfo;
Thanks,
Zhao
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 9:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 18:08 [PATCH] i386/cpu: mark CPU properties as const John Snow
2026-11-19 18:40 ` Peter Maydell
2026-11-19 18:55 ` Richard Henderson
2026-11-20 9:58 ` Zhao Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox