xentrace: handle sparse cpu ids correctly in xen trace buffer handling
PATCH 1/1 xentrace: handle sparse cpu ids correctly in xen trace buffer handling
The per-cpu buffers for Xentrace are addressed by cpu-id, but the info array for the buffers is sized only by number of online cpus. This might lead to crashes when using Xentrace with smt=0.
The t_info structure has to be sized based on nr_cpu_ids.
--- tools/xentrace/xentrace.c | 2 +- xen/common/trace.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-)
tools/xentrace/xentrace.c +1 -1
@@ -594,7 +594,7 @@ static unsigned int get_num_cpus(void)exit (EXIT_FAILURE ); } -return physinfo.nr_cpus; +return physinfo.max_cpu_id +1 ; }/**
xen/common/trace.c +7 -7
@@ -113,7 +113,7 @@ static int calculate_tbuf_size(unsigned int pages, uint16_t t_info_first_offset)struct t_info dummy_pages; typeof(dummy_pages.tbuf_size) max_pages; typeof(dummy_pages.mfn_offset[0]) max_mfn_offset; -unsigned int max_cpus =num_online_cpus (); +unsigned int max_cpus = nr_cpu_ids;unsigned int t_info_words;/* force maximum value for an unsigned type */
@@ -151,11 +151,11 @@ static int calculate_tbuf_size(unsigned int pages, uint16_t t_info_first_offset)* NB this calculation is correct, because t_info_first_offset is * in words, not bytes, not bytes */ - t_info_words =num_online_cpus () * pages + t_info_first_offset; + t_info_words = nr_cpu_ids * pages + t_info_first_offset; t_info_pages =PFN_UP (t_info_words *sizeof (uint32_t ));printk (XENLOG_INFO "xentrace: requesting %u t_info pages " "for %u trace pages on %u cpus\n" , - t_info_pages, pages,num_online_cpus ()); + t_info_pages, pages, nr_cpu_ids);return pages; }
@@ -202,7 +202,7 @@ static int alloc_trace_bufs(unsigned int pages)* Allocate buffers for all of the cpus. * If any fails, deallocate what you have so far and exit. */ -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) { offset = t_info_first_offset + (cpu * pages); t_info->mfn_offset[cpu] = offset;
@@ -224,7 +224,7 @@ static int alloc_trace_bufs(unsigned int pages)/* * Initialize buffers for all of the cpus. */ -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) {struct t_buf *buf;
@@ -261,7 +261,7 @@ static int alloc_trace_bufs(unsigned int pages)return 0 ; out_dealloc: -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) { offset = t_info->mfn_offset[cpu];if ( !offset )
@@ -418,7 +418,7 @@ int tb_control(struct xen_sysctl_tbuf_op *tbc)/* Clear any lost-record info so we don't get phantom lost records next time we * start tracing. Grab the lock to make sure we're not racing anyone. After this * hypercall returns, no more records should be placed into the buffers. */ -for_each_online_cpu (i) +for_each_present_cpu (i) {unsigned long flags;spin_lock_irqsave (&per_cpu (t_lock, i), flags);
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
xen/common/trace.c static int alloc_trace_bufs(unsigned int pages) · line 208
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.08.18 at 09:52, <[email protected]> wrote:
xen/common/trace.c +1
-1@@ -202,7 +202,7 @@ static int alloc_trace_bufs(unsigned int pages)* Allocate buffers for all of the cpus. * If any fails, deallocate what you have so far and exit. */ -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) { offset = t_info_first_offset + (cpu * pages); t_info->mfn_offset[cpu] = offset;
Doesn't this go a little too far? Why would you allocate buffers for CPUs which can never be brought online? There ought to be a middle ground, where online-able CPUs have buffers allocated, but non-online-able ones won't. On larger systems I guess the difference may be quite noticable.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Jan Beulich
xen/common/trace.c static int alloc_trace_bufs(unsigned int pages) · line 208
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.08.18 at 09:52, <[email protected]> wrote:
xen/common/trace.c +1
-1@@ -202,7 +202,7 @@ static int alloc_trace_bufs(unsigned int pages)* Allocate buffers for all of the cpus. * If any fails, deallocate what you have so far and exit. */ -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) { offset = t_info_first_offset + (cpu * pages); t_info->mfn_offset[cpu] = offset;Doesn't this go a little too far? Why would you allocate buffers for CPUs which can never be brought online? There ought to be a middle ground, where online-able CPUs have buffers allocated, but non-online-able ones won't. On larger systems I guess the difference may be quite noticable.
According to the comments in include/xen/cpumask.h cpu_present_map represents the populated cpus.
I know that currently there is no support for onlining a parked cpu again, but I think having to think about Xentrace buffer allocation in case onlining of parked cpus is added would be a nearly 100% chance to introduce a bug.
Xentrace is used for testing purposes only. So IMHO allocating some more memory is acceptable.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Juergen Gross
Quoted 15 lines · Jan Beulich
xen/common/trace.c static int alloc_trace_bufs(unsigned int pages) · line 208
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.08.18 at 09:52, <[email protected]> wrote:
xen/common/trace.c +1
-1@@ -202,7 +202,7 @@ static int alloc_trace_bufs(unsigned int pages)* Allocate buffers for all of the cpus. * If any fails, deallocate what you have so far and exit. */ -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) { offset = t_info_first_offset + (cpu * pages); t_info->mfn_offset[cpu] = offset;Doesn't this go a little too far? Why would you allocate buffers for CPUs which can never be brought online? There ought to be a middle ground, where online-able CPUs have buffers allocated, but non-online-able ones won't. On larger systems I guess the difference may be quite noticable.
According to the comments in
include/xen/cpumask.hcpu_present_maprepresents the populated cpus.
Quoted 7 lines
I know that currently there is no support for onlining a parked cpu again, but I think having to think about Xentrace buffer allocation in case onlining of parked cpus is added would be a nearly 100% chance to introduce a bug.
Xentrace is used for testing purposes only. So IMHO allocating some more memory is acceptable.
Are you fine with my reasoning or do you still want me to avoid buffer allocation for offline cpus?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 10.09.18 at 13:34, <[email protected]> wrote:
Quoted 25 lines · Juergen Gross
Quoted 15 lines · Jan Beulich
xen/common/trace.c static int alloc_trace_bufs(unsigned int pages) · line 208
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.08.18 at 09:52, <[email protected]> wrote:
xen/common/trace.c +1
-1@@ -202,7 +202,7 @@ static int alloc_trace_bufs(unsigned int pages)* Allocate buffers for all of the cpus. * If any fails, deallocate what you have so far and exit. */ -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) { offset = t_info_first_offset + (cpu * pages); t_info->mfn_offset[cpu] = offset;Doesn't this go a little too far? Why would you allocate buffers for CPUs which can never be brought online? There ought to be a middle ground, where online-able CPUs have buffers allocated, but non-online-able ones won't. On larger systems I guess the difference may be quite noticable.
According to the comments in
include/xen/cpumask.hcpu_present_maprepresents the populated cpus.I know that currently there is no support for onlining a parked cpu again, but I think having to think about Xentrace buffer allocation in case onlining of parked cpus is added would be a nearly 100% chance to introduce a bug.
Quoted 5 lines
Quoted 2 lines
Xentrace is used for testing purposes only. So IMHO allocating some more memory is acceptable.
Are you fine with my reasoning or do you still want me to avoid buffer allocation for offline cpus?
I don't object to it, but I'm also not overly happy. IOW - I'd like to leave it to George as the maintainer of the code (who in turn might leave it to you).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines · Juergen Gross
Quoted 15 lines · Jan Beulich
xen/common/trace.c static int alloc_trace_bufs(unsigned int pages) · line 208
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.08.18 at 09:52, <[email protected]> wrote:
xen/common/trace.c +1
-1@@ -202,7 +202,7 @@ static int alloc_trace_bufs(unsigned int pages)* Allocate buffers for all of the cpus. * If any fails, deallocate what you have so far and exit. */ -for_each_online_cpu (cpu) +for_each_present_cpu (cpu) { offset = t_info_first_offset + (cpu * pages); t_info->mfn_offset[cpu] = offset;Doesn't this go a little too far? Why would you allocate buffers for CPUs which can never be brought online? There ought to be a middle ground, where online-able CPUs have buffers allocated, but non-online-able ones won't. On larger systems I guess the difference may be quite noticable.
According to the comments in
include/xen/cpumask.hcpu_present_maprepresents the populated cpus.
Quoted 7 lines
I know that currently there is no support for onlining a parked cpu again, but I think having to think about Xentrace buffer allocation in case onlining of parked cpus is added would be a nearly 100% chance to introduce a bug.
Xentrace is used for testing purposes only. So IMHO allocating some more memory is acceptable.
On the other hand, size of buffers can be a significant factor in whether you can manage to catch the behavior you want or whether there will be gaps due to dropped records; anything that can make those allocations go farther will be helpful.
Anyone bringing a parked cpu back up should have to go through all instances of per_cpu() and figure out if they need to do something; that should catch this issue, if it happens.
So although it's a bit of a tough decision, I'd leave this for_each_online_cpu(), as Jan suggests.
Thanks,
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel