x86/ucode: Cleanup - Part 2/n
cover x86/ucode: Cleanup - Part 2/n
Two minor bugfixes, and two minor cleanups with minor benefits to other code as well.
There is no dependency on the remaining pieces of the Part 1 series.
Andrew Cooper (4):
x86/ucode/amd: Fix assertion in compare_patch()
x86/ucode: Fix error paths in apply_microcode()
xen: Drop raw_smp_processor_id()
xen: Introduce a xmemdup_bytes() helper
xen/arch/x86/cpu/microcode/amd.c | 27 +++++++++++---------------- xen/arch/x86/cpu/microcode/intel.c | 29 +++++++++++++---------------- xen/include/asm-arm/smp.h | 2 +- xen/include/asm-x86/smp.h | 2 +- xen/include/xen/smp.h | 2 -- xen/include/xen/xmalloc.h | 11 +++++++++++ 6 files changed, 37 insertions(+), 36 deletions(-)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/4 x86/ucode/amd: Fix assertion in compare_patch()
This is clearly a typo.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/cpu/microcode/amd.c +1 -1
@@ -222,7 +222,7 @@ static enum microcode_match_result compare_patch(/* Both patches to compare are supposed to be applicable to local CPU. */ ASSERT (microcode_fits (new->mc_amd) !=MIS_UCODE ); -ASSERT (microcode_fits (new->mc_amd) !=MIS_UCODE ); +ASSERT (microcode_fits (old->mc_amd) !=MIS_UCODE );return compare_header (new_header, old_header); }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/4] x86/ucode/amd: Fix assertion in compare_patch()
Quoted 4 lines · Andrew Cooper
This is clearly a typo.
Fixes 9da23943ccd "microcode: introduce a global cache of ucode patch"Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/4 x86/ucode: Fix error paths in apply_microcode()
In reply to Andrew CooperIn the unlikley case that patch application completes, but the resutling revision isn't expected, sig->rev doesn't get updated to match reality.
It will get adjusted the next time collect_cpu_info() gets called, but in the meantime Xen might operate on a state value. Nothing good will come of this.
Rewrite the logic to always update the stashed revision, before worring about whether the attempt was a success or failure.
Take the opportunity to make the printk() messages as consistent as possible.
---
-CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/cpu/microcode/amd.c | 14 +++++++------- xen/arch/x86/cpu/microcode/intel.c | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-)
xen/arch/x86/cpu/microcode/amd.c +7 -7
@@ -229,11 +229,11 @@ static enum microcode_match_result compare_patch(static int apply_microcode (const struct microcode_patch *patch) { -uint32_t rev;int hw_err;unsigned int cpu =smp_processor_id ();struct cpu_signature *sig = &per_cpu (cpu_sig, cpu);const struct microcode_header_amd *hdr; +uint32_t rev, old_rev = sig->rev;if ( !patch )return -ENOENT ;
@@ -249,6 +249,7 @@ static int apply_microcode(const struct microcode_patch *patch)/* get patch id after patching */ rdmsrl (MSR_AMD_PATCHLEVEL , rev); + sig->rev = rev;/* * Some processors leave the ucode blob mapping as UC after the update.
@@ -259,15 +260,14 @@ static int apply_microcode(const struct microcode_patch *patch)/* check current patch id and patch's id for match */ if ( hw_err || (rev != hdr->patch_id) ) { -printk (KERN_ERR "microcode: CPU%d update from revision " -"%#x to %#x failed\n" , cpu, rev, hdr->patch_id); +printk (XENLOG_ERR +"microcode: CPU%u update rev %#x to %#x failed, result %#x\n" , + cpu, old_rev, hdr->patch_id, rev);return -EIO ; } -printk (KERN_WARNING "microcode: CPU%d updated from revision %#x to %#x\n" , - cpu, sig->rev, hdr->patch_id); - - sig->rev = rev; +printk (XENLOG_WARNING "microcode: CPU%u updated from revision %#x to %#x\n" , + cpu, old_rev, hdr->patch_id);return 0 ; }
xen/arch/x86/cpu/microcode/intel.c +11 -11
@@ -278,10 +278,10 @@ static enum microcode_match_result compare_patch(static int apply_microcode (const struct microcode_patch *patch) {uint64_t msr_content; -unsigned int val[2 ]; -unsigned int cpu_num =raw_smp_processor_id (); +unsigned int cpu =smp_processor_id ();struct cpu_signature *sig = &this_cpu (cpu_sig);const struct microcode_intel *mc_intel; +uint32_t rev, old_rev = sig->rev;if ( !patch )return -ENOENT ;
@@ -302,20 +302,20 @@ static int apply_microcode(const struct microcode_patch *patch)/* get the current revision from MSR 0x8B */ rdmsrl (MSR_IA32_UCODE_REV , msr_content); - val[1 ] = (uint32_t )(msr_content >>32 ); + sig->rev = rev = msr_content >>32 ; -if ( val[1 ] != mc_intel->hdr.rev ) +if ( rev != mc_intel->hdr.rev ) { -printk (KERN_ERR "microcode: CPU%d update from revision " -"%#x to %#x failed. Resulting revision is %#x.\n" , cpu_num, - sig->rev, mc_intel->hdr.rev, val[1 ]); +printk (XENLOG_ERR +"microcode: CPU%u update rev %#x to %#x failed, result %#x\n" , + cpu, old_rev, mc_intel->hdr.rev, rev);return -EIO ; } -printk (KERN_INFO "microcode: CPU%d updated from revision " -"%#x to %#x, date = %04x-%02x-%02x\n" , - cpu_num, sig->rev, val[1 ], mc_intel->hdr.year, + +printk (XENLOG_WARNING +"microcode: CPU%u updated from revision %#x to %#x, date = %04x-%02x-%02x\n" , + cpu, old_rev, rev, mc_intel->hdr.year, mc_intel->hdr.month, mc_intel->hdr.day); - sig->rev = val[1 ];return 0 ; }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/4] x86/ucode: Fix error paths in apply_microcode()
Actually CC Jan
Quoted 5 lines · Andrew Cooper
In the unlikley case that patch application completes, but the resutling revision isn't expected,
sig->revdoesn't get updated to match reality.It will get adjusted the next time
collect_cpu_info()gets called, but in the meantime Xen might operate on a state value. Nothing good will come of this.
state -> stale
Quoted 2 lines
Rewrite the logic to always update the stashed revision, before worring about
worring -> worrying
Quoted 5 lines
whether the attempt was a success or failure.
Take the opportunity to make the
printk()messages as consistent as possible.Signed-off-by Andrew Cooper <[email protected]>
Quoted 105 lines
---
-CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>--- xen/arch/x86/cpu/microcode/amd.c | 14 +++++++------- xen/arch/x86/cpu/microcode/intel.c | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-)xen/arch/x86/cpu/microcode/amd.c +7
-7@@ -229,11 +229,11 @@ static enum microcode_match_result compare_patch(static int apply_microcode (const struct microcode_patch *patch) { -uint32_t rev;int hw_err;unsigned int cpu =smp_processor_id ();struct cpu_signature *sig = &per_cpu (cpu_sig, cpu);const struct microcode_header_amd *hdr; +uint32_t rev, old_rev = sig->rev;if ( !patch )return -ENOENT ;@@ -249,6 +249,7 @@ static int apply_microcode(const struct microcode_patch *patch)/* get patch id after patching */ rdmsrl (MSR_AMD_PATCHLEVEL , rev); + sig->rev = rev;/* * Some processors leave the ucode blob mapping as UC after the update. @@ -259,15 +260,14 @@ static int apply_microcode(const struct microcode_patch *patch)/* check current patch id and patch's id for match */ if ( hw_err || (rev != hdr->patch_id) ) { -printk (KERN_ERR "microcode: CPU%d update from revision " -"%#x to %#x failed\n" , cpu, rev, hdr->patch_id); +printk (XENLOG_ERR +"microcode: CPU%u update rev %#x to %#x failed, result %#x\n" , + cpu, old_rev, hdr->patch_id, rev);return -EIO ; } -printk (KERN_WARNING "microcode: CPU%d updated from revision %#x to %#x\n" , - cpu, sig->rev, hdr->patch_id); - - sig->rev = rev; +printk (XENLOG_WARNING "microcode: CPU%u updated from revision %#x to %#x\n" , + cpu, old_rev, hdr->patch_id);return 0 ; }xen/arch/x86/cpu/microcode/intel.c +11
-11@@ -278,10 +278,10 @@ static enum microcode_match_result compare_patch(static int apply_microcode (const struct microcode_patch *patch) {uint64_t msr_content; -unsigned int val[2 ]; -unsigned int cpu_num =raw_smp_processor_id (); +unsigned int cpu =smp_processor_id ();struct cpu_signature *sig = &this_cpu (cpu_sig);const struct microcode_intel *mc_intel; +uint32_t rev, old_rev = sig->rev;if ( !patch )return -ENOENT ;@@ -302,20 +302,20 @@ static int apply_microcode(const struct microcode_patch *patch)/* get the current revision from MSR 0x8B */ rdmsrl (MSR_IA32_UCODE_REV , msr_content); - val[1 ] = (uint32_t )(msr_content >>32 ); + sig->rev = rev = msr_content >>32 ; -if ( val[1 ] != mc_intel->hdr.rev ) +if ( rev != mc_intel->hdr.rev ) { -printk (KERN_ERR "microcode: CPU%d update from revision " -"%#x to %#x failed. Resulting revision is %#x.\n" , cpu_num, - sig->rev, mc_intel->hdr.rev, val[1 ]); +printk (XENLOG_ERR +"microcode: CPU%u update rev %#x to %#x failed, result %#x\n" , + cpu, old_rev, mc_intel->hdr.rev, rev);return -EIO ; } -printk (KERN_INFO "microcode: CPU%d updated from revision " -"%#x to %#x, date = %04x-%02x-%02x\n" , - cpu_num, sig->rev, val[1 ], mc_intel->hdr.year, + +printk (XENLOG_WARNING +"microcode: CPU%u updated from revision %#x to %#x, date = %04x-%02x-%02x\n" , + cpu, old_rev, rev, mc_intel->hdr.year, mc_intel->hdr.month, mc_intel->hdr.day); - sig->rev = val[1 ];return 0 ; }Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/4] x86/ucode: Fix error paths in apply_microcode()
In reply to Andrew CooperQuoted 8 lines · Andrew Cooper
xen/arch/x86/cpu/microcode/amd.c +2
-2@@ -259,15 +260,14 @@ static int apply_microcode(const struct microcode_patch *patch)/* check current patch id and patch's id for match */ if ( hw_err || (rev != hdr->patch_id) ) { -printk (KERN_ERR "microcode: CPU%d update from revision " -"%#x to %#x failed\n" , cpu, rev, hdr->patch_id); + printk(XENLOG_ERR + "microcode: CPU%u update rev %#x to %#x failed, result %#x\n",
xen/arch/x86/cpu/microcode/amd.c static int apply_microcode(const struct microcode_patch *patch) · line 270
Quoted 10 lines
xen/arch/x86/cpu/microcode/amd.c +3
-4+ cpu, old_rev, hdr->patch_id, rev);return -EIO ; } -printk (KERN_WARNING "microcode: CPU%d updated from revision %#x to %#x\n" , - cpu, sig->rev, hdr->patch_id); - - sig->rev = rev; +printk (XENLOG_WARNING "microcode: CPU%u updated from revision %#x to %#x\n" , + cpu, old_rev, hdr->patch_id);
Prefer the local variable here over hdr->patch_id, just like you do on the Intel side?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/4 xen: Drop raw_smp_processor_id()
In reply to Andrew CooperThere is only a single user of raw_smp_processor_id() left in the tree (and it is unconditionally compiled out). Drop the alias from all architectures.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
--- xen/arch/x86/cpu/microcode/amd.c | 2 +- xen/include/asm-arm/smp.h | 2 +- xen/include/asm-x86/smp.h | 2 +- xen/include/xen/smp.h | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-)
xen/arch/x86/cpu/microcode/amd.c +1 -1
@@ -306,7 +306,7 @@ static int get_ucode_from_buffer_amd(memcpy (mc_amd->mpb, mpbuf->data, mpbuf->len);pr_debug ("microcode: CPU%d size %zu, block size %u offset %zu equivID %#x rev %#x\n" , -raw_smp_processor_id (), bufsize, mpbuf->len, *offset, +smp_processor_id (), bufsize, mpbuf->len, *offset, ((struct microcode_header_amd *)mc_amd->mpb)->processor_rev_id, ((struct microcode_header_amd *)mc_amd->mpb)->patch_id);
xen/include/asm-arm/smp.h +1 -1
@@ -12,7 +12,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask);#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu)) -#define raw_smp_processor_id () (get_processor_id()) +#define smp_processor_id () get_processor_id()/* * Do we, for platform reasons, need to actually keep CPUs online when we
xen/include/asm-x86/smp.h +1 -1
@@ -53,7 +53,7 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm);* from the initial startup. We map APIC_BASE very early in page_setup(), * so this is correct in the x86 case. */ -#define raw_smp_processor_id () (get_processor_id()) +#define smp_processor_id () get_processor_id()void __stop_this_cpu (void );
xen/include/xen/smp.h +0 -2
@@ -65,8 +65,6 @@ void smp_call_function_interrupt(void);void smp_send_call_function_mask (const cpumask_t *mask); -#define smp_processor_id () raw_smp_processor_id() -int alloc_cpu_id (void );extern void *stack_base[NR_CPUS ];
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/4] xen: Drop raw_smp_processor_id()
Quoted 4 lines · Andrew Cooper
There is only a single user of
raw_smp_processor_id()left in the tree (and it is unconditionally compiled out). Drop the alias from all architectures.Signed-off-by Andrew Cooper <[email protected]>
Cheers,
Quoted 67 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>--- xen/arch/x86/cpu/microcode/amd.c | 2 +- xen/include/asm-arm/smp.h | 2 +- xen/include/asm-x86/smp.h | 2 +- xen/include/xen/smp.h | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-)xen/arch/x86/cpu/microcode/amd.c +1
-1@@ -306,7 +306,7 @@ static int get_ucode_from_buffer_amd(memcpy (mc_amd->mpb, mpbuf->data, mpbuf->len);pr_debug ("microcode: CPU%d size %zu, block size %u offset %zu equivID %#x rev %#x\n" , -raw_smp_processor_id (), bufsize, mpbuf->len, *offset, +smp_processor_id (), bufsize, mpbuf->len, *offset, ((struct microcode_header_amd *)mc_amd->mpb)->processor_rev_id, ((struct microcode_header_amd *)mc_amd->mpb)->patch_id);xen/include/asm-arm/smp.h +1
-1@@ -12,7 +12,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask);#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu)) -#define raw_smp_processor_id () (get_processor_id()) +#define smp_processor_id () get_processor_id()/* * Do we, for platform reasons, need to actually keep CPUs online when we xen/include/asm-x86/smp.h +1
-1@@ -53,7 +53,7 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm);* from the initial startup. We map APIC_BASE very early in page_setup(), * so this is correct in the x86 case. */ -#define raw_smp_processor_id () (get_processor_id()) +#define smp_processor_id () get_processor_id()void __stop_this_cpu (void );xen/include/xen/smp.h +0
-2@@ -65,8 +65,6 @@ void smp_call_function_interrupt(void);void smp_send_call_function_mask (const cpumask_t *mask); -#define smp_processor_id () raw_smp_processor_id() -int alloc_cpu_id (void );extern void *stack_base[NR_CPUS ];
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/4] xen: Drop raw_smp_processor_id()
In reply to Andrew CooperQuoted 4 lines · Andrew Cooper
There is only a single user of
raw_smp_processor_id()left in the tree (and it is unconditionally compiled out). Drop the alias from all architectures.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/4 xen: Introduce a xmemdup_bytes() helper
In reply to Andrew CooperUse it to simplify the x86 microcode logic, taking the opportunity to drop the -ENOMEM printks.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/cpu/microcode/amd.c | 9 ++------- xen/arch/x86/cpu/microcode/intel.c | 7 ++----- xen/include/xen/xmalloc.h | 11 +++++++++++ 3 files changed, 15 insertions(+), 12 deletions(-)
xen/arch/x86/cpu/microcode/amd.c +2 -7
@@ -299,11 +299,10 @@ static int get_ucode_from_buffer_amd(return -EINVAL ; } - mc_amd->mpb =xmalloc_bytes (mpbuf->len); + mc_amd->mpb =xmemdup_bytes (mpbuf->data, mpbuf->len);if ( !mc_amd->mpb )return -ENOMEM ; mc_amd->mpb_size = mpbuf->len; -memcpy (mc_amd->mpb, mpbuf->data, mpbuf->len); pr_debug("microcode: CPU%d size %zu, block size %u offset %zu equivID %#x rev %#x\n", smp_processor_id(), bufsize, mpbuf->len, *offset,
@@ -336,14 +335,10 @@ static int install_equiv_cpu_table(return -EINVAL ; } - mc_amd->equiv_cpu_table =xmalloc_bytes (mpbuf->len); + mc_amd->equiv_cpu_table =xmemdup_bytes (mpbuf->data, mpbuf->len);if ( !mc_amd->equiv_cpu_table ) - { -printk (KERN_ERR "microcode: Cannot allocate memory for equivalent cpu table\n" );return -ENOMEM ; - } -memcpy (mc_amd->equiv_cpu_table, mpbuf->data, mpbuf->len); mc_amd->equiv_cpu_table_size = mpbuf->len;return 0 ;
xen/arch/x86/cpu/microcode/intel.c +2 -5
@@ -339,13 +339,10 @@ static long get_next_ucode_from_buffer(struct microcode_intel **mc,return -EINVAL ; } - *mc =xmalloc_bytes (total_size); + *mc =xmemdup_bytes (mc_header, total_size);if ( *mc ==NULL ) - { -printk (KERN_ERR "microcode: error! Can not allocate memory\n" );return -ENOMEM ; - } -memcpy (*mc, (const void *)(buf + offset), total_size); +return offset + total_size; }
xen/include/xen/xmalloc.h +11 -0
@@ -51,6 +51,17 @@#define xmalloc_bytes (_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)#define xzalloc_bytes (_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES) +/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes (_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \ + \ + if ( dst_ ) \ + memcpy(dst_, _src, nr_); \ + dst_; \ + }) +/* Free any of the above. */ extern void xfree (void *);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper
Quoted 4 lines · Andrew Cooper
Use it to simplify the x86 microcode logic, taking the opportunity to drop the
-ENOMEMprintks.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper
In reply to Andrew CooperHi Andrew,
Quoted 5 lines · Andrew Cooper
Use it to simplify the x86 microcode logic, taking the opportunity to drop the
-ENOMEMprintks.Signed-off-by Andrew Cooper <[email protected]>
Quoted 8 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>--- xen/arch/x86/cpu/microcode/amd.c | 9 ++------- xen/arch/x86/cpu/microcode/intel.c | 7 ++----- xen/include/xen/xmalloc.h | 11 +++++++++++
I did notice a few times in the past months where only the x86 folks where CCed even when there are changes in common code. Even if I am mostly likely going to be happy with the changes, you should at least give the other maintainers an opportunity to object/comment.
May I ask to CC all the relevant maintainers in the future? scripts/add_maintainers.pl should do the job for you.
Quoted 60 lines
3 files changed, 15 insertions(+), 12 deletions(-)xen/arch/x86/cpu/microcode/amd.c +2
-7@@ -299,11 +299,10 @@ static int get_ucode_from_buffer_amd(return -EINVAL ; } - mc_amd->mpb =xmalloc_bytes (mpbuf->len); + mc_amd->mpb =xmemdup_bytes (mpbuf->data, mpbuf->len);if ( !mc_amd->mpb )return -ENOMEM ; mc_amd->mpb_size = mpbuf->len; -memcpy (mc_amd->mpb, mpbuf->data, mpbuf->len); pr_debug("microcode: CPU%d size %zu, block size %u offset %zu equivID %#x rev %#x\n", smp_processor_id(), bufsize, mpbuf->len, *offset,@@ -336,14 +335,10 @@ static int install_equiv_cpu_table(return -EINVAL ; } - mc_amd->equiv_cpu_table =xmalloc_bytes (mpbuf->len); + mc_amd->equiv_cpu_table =xmemdup_bytes (mpbuf->data, mpbuf->len);if ( !mc_amd->equiv_cpu_table ) - { -printk (KERN_ERR "microcode: Cannot allocate memory for equivalent cpu table\n" );return -ENOMEM ; - } -memcpy (mc_amd->equiv_cpu_table, mpbuf->data, mpbuf->len); mc_amd->equiv_cpu_table_size = mpbuf->len;return 0 ;xen/arch/x86/cpu/microcode/intel.c +2
-5@@ -339,13 +339,10 @@ static long get_next_ucode_from_buffer(struct microcode_intel **mc,return -EINVAL ; } - *mc =xmalloc_bytes (total_size); + *mc =xmemdup_bytes (mc_header, total_size);if ( *mc ==NULL ) - { -printk (KERN_ERR "microcode: error! Can not allocate memory\n" );return -ENOMEM ; - } -memcpy (*mc, (const void *)(buf + offset), total_size); +return offset + total_size; }xen/include/xen/xmalloc.h +0
-0
xen/include/xen/xmalloc.h line 58
Quoted 8 lines
xen/include/xen/xmalloc.h +5
-0@@ -51,6 +51,17 @@#define xmalloc_bytes (_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)#define xzalloc_bytes (_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES) +/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes (_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \
The nr_ vs _nr is really confusing to read. Could you re-implement the function as a static inline?
Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper
Quoted 7 lines · Julien Grall
Quoted 6 lines · Andrew Cooper
xen/include/xen/xmalloc.h +0
-0@@ -51,6 +51,17 @@#define xmalloc_bytes (_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)#define xzalloc_bytes (_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES)
Quoted 8 lines
xen/include/xen/xmalloc.h line 58
Quoted 5 lines
xen/include/xen/xmalloc.h +5
-0+/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes (_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \The
nr_vs_nris really confusing to read. Could you re-implement the function as a static inline?
And even if that wouldn't work out - what's the point of having macro argument names with leading underscores? This isn't any better standard-wise (afaict) than other uses of leading underscores for identifiers which aren't CU-scope.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper
Quoted 15 lines · Jan Beulich
Quoted 7 lines · Julien Grall
Quoted 6 lines · Andrew Cooper
xen/include/xen/xmalloc.h +0
-0@@ -51,6 +51,17 @@#define xmalloc_bytes (_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)#define xzalloc_bytes (_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES)Quoted 7 lines
xen/include/xen/xmalloc.h line 58
Quoted 5 lines
xen/include/xen/xmalloc.h +5
-0+/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes (_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \The
nr_vs_nris really confusing to read. Could you re-implement the function as a static inline?
Quoted 2 lines
And even if that wouldn't work out - what's the point of having macro argument names with leading underscores?
Consistency with all the other code in this file.
Quoted 3 lines
This isn't any
better standard-wise (afaict) than other uses of leading underscores for identifiers which aren't CU-scope.
It is a parameter describing textural replacement within the body. There is 0 interaction with external namespacing standards.
~Andrew
Re: [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper
Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Julien Grall
xen/include/xen/xmalloc.h line 58
Quoted 11 lines · Andrew Cooper
xen/include/xen/xmalloc.h +5
-0@@ -51,6 +51,17 @@#define xmalloc_bytes (_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)#define xzalloc_bytes (_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES) +/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes (_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \The
nr_vs_nris really confusing to read. Could you re-implement the function as a static inline?
Quoted 4 lines
Quoted 2 lines
And even if that wouldn't work out - what's the point of having macro argument names with leading underscores?
Consistency with all the other code in this file.
I value consistency quite high, but then please consistent with something that properly follows other rules.
Quoted 6 lines
Quoted 3 lines
This isn't any
better standard-wise (afaict) than other uses of leading underscores for identifiers which aren't CU-scope.It is a parameter describing textural replacement within the body. There is 0 interaction with external namespacing standards.
Please forgive me saying so, but a typical reply I might get back from you would be: And?
I'm not going to insist nor nak the patch, but I don't welcome widening existing issues we have.
Jan
Re: [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper
In reply to Julien GrallQuoted 8 lines · Julien Grall
Quoted 8 lines
xen/include/xen/xmalloc.h +0
-0@@ -51,6 +51,17 @@#define xmalloc_bytes (_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)#define xzalloc_bytes (_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES)
Quoted 7 lines
xen/include/xen/xmalloc.h line 58
Quoted 5 lines
xen/include/xen/xmalloc.h +5
-0+/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes (_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \The
nr_vs_nris really confusing to read. Could you re-implement the function as a static inline?
I'd really prefer to, but sadly not.
That requires untangling headers sufficiently so we can include string.h, to be able to use memcpy. I don't have time at the moment to sort that out.
~Andrew
Julien Grall
Acked-byRe: [Xen-devel] [PATCH 4/4] xen: Introduce a xmemdup_bytes() helper
Hi Andrew,
Quoted 17 lines · Andrew Cooper
Quoted 8 lines · Julien Grall
Quoted 8 lines
xen/include/xen/xmalloc.h +0
-0@@ -51,6 +51,17 @@#define xmalloc_bytes (_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)#define xzalloc_bytes (_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES)Quoted 7 lines
xen/include/xen/xmalloc.h line 58
Quoted 5 lines
xen/include/xen/xmalloc.h +5
-0+/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes (_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \The
nr_vs_nris really confusing to read. Could you re-implement the function as a static inline?
Quoted 5 lines
I'd really prefer to, but sadly not.
That requires untangling headers sufficiently so we can include
string.h, to be able to use memcpy. I don't have time at the moment to sort that out.
Ok :(. We will have to live with the macro for the time being then.
Cheers,
Signature · 1 line
Julien Grall
Quoted 9 lines · Andrew Cooper
Two minor bugfixes, and two minor cleanups with minor benefits to other code as well.
There is no dependency on the remaining pieces of the Part 1 series.
Andrew Cooper (4):
x86/ucode/amd: Fix assertion incompare_patch()
x86/ucode: Fix error paths inapply_microcode()
xen: Dropraw_smp_processor_id()
FAOD feel free to throw in with Wei's R-b, ideally with the small adjustment suggested for patch 2.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel