|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v1.1 2/3] xen/sched: fix theoretical races accessing vcpu->dirty_cpu
Hi Juergen,They are less theoritical than we would want. :/ There was a great series of article on lwn [1] about compiler optimization last year. There is at least a few TOCTOU in the code where you could end up with cpumask_of(VCPU_CPU_CLEAN). On 30/04/2020 16:28, Juergen Gross wrote: The dirty_cpu field of struct vcpu denotes which cpu still holds data of a vcpu. All accesses to this field should be atomic in case the vcpu could just be running, as it is accessed without any lock held in most cases. Looking at the patch below, I am not sure why the issue is happening only when running. For instance, in the case of context_switch(), 'next' should not be running. Instead, I think, the race would happen if the vCPU state is synchronized (__sync_local_execstate()) at the same time as time context_switch(). Am I correct? There are some instances where accesses are not atomically done, and even worse where multiple accesses are done when a single one would be mandated. Correct that in order to avoid potential problems. Add some assertions to verify dirty_cpu is handled properly. Signed-off-by: Juergen Gross <jgross@xxxxxxxx> --- xen/arch/x86/domain.c | 14 ++++++++++---- xen/include/xen/sched.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index a4428190d5..f0579a56d1 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1769,6 +1769,7 @@ static void __context_switch(void)if ( !is_idle_domain(pd) ) Is the cast necessary? }void vcpu_block(void); Cheers, [1] https://lwn.net/Articles/793253/ -- Julien Grall
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |