From nobody Tue May 7 22:50:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1588259779; cv=none; d=zohomail.com; s=zohoarc; b=KDO4ra0Fmln3zih7cnKtIGoXo7QzzGk2cuY8W9/E9GiSUUExJeWwDN7KoGzN0SCS2qVjoZa1+thhP5VW/y6O/izMSSC2AMhjDvwWPuFtLkTsON+MX1XU5d+XcDmN6nqtj02u19yUOH7Q2SBmPrYW7wynr+YGnfdyl/gPwy67lWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588259779; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=eoF5MgE3NqHWQM0dBKH+bWvXROHzetJG/BdxGxq1PcY=; b=cn4VRUNrgBAxvAfXdKBZPmLr49Yg4vfVNpOCCgM7sNSV/8mrwtb5tl+tp3BLT7JjaA2t4W22TPEjFaBhNdHgq7wtIwHK2IPTkc0ku7tb6Wsd//6+7lvXZaB0UFJ20vJvCegKOgr16Ugo8FmQQXaeMAvdO/7tDAXrAe67CtWbhLQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1588259779809578.0700376194959; Thu, 30 Apr 2020 08:16:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAuy-0007OP-Ue; Thu, 30 Apr 2020 15:16:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAux-0007OA-Ou for xen-devel@lists.xenproject.org; Thu, 30 Apr 2020 15:16:03 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 81319f00-8af5-11ea-ae69-bc764e2007e4; Thu, 30 Apr 2020 15:16:03 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4981FAD31; Thu, 30 Apr 2020 15:16:01 +0000 (UTC) X-Inumbo-ID: 81319f00-8af5-11ea-ae69-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Subject: [PATCH 1/3] xen/sched: allow rcu work to happen when syncing cpus in core scheduling Date: Thu, 30 Apr 2020 17:15:57 +0200 Message-Id: <20200430151559.1464-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200430151559.1464-1-jgross@suse.com> References: <20200430151559.1464-1-jgross@suse.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Dario Faggioli , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With RCU barriers moved from tasklets to normal RCU processing cpu offlining in core scheduling might deadlock due to cpu synchronization required by RCU processing and core scheduling concurrently. Fix that by bailing out from core scheduling synchronization in case of pending RCU work. Additionally the RCU softirq is now required to be of higher priority than the scheduling softirqs in order to do RCU processing before entering the scheduler again, as bailing out from the core scheduling synchronization requires to raise another softirq SCHED_SLAVE, which would bypass RCU processing again. Reported-by: Sergey Dyasli Tested-by: Sergey Dyasli Signed-off-by: Juergen Gross Acked-by: Dario Faggioli --- xen/common/sched/core.c | 10 +++++++--- xen/include/xen/softirq.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index d94b95285f..a099e37b0f 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -2457,13 +2457,17 @@ static struct sched_unit *sched_wait_rendezvous_in(= struct sched_unit *prev, v =3D unit2vcpu_cpu(prev, cpu); } /* - * Coming from idle might need to do tasklet work. + * Check for any work to be done which might need cpu synchronizat= ion. + * This is either pending RCU work, or tasklet work when coming fr= om + * idle. * In order to avoid deadlocks we can't do that here, but have to - * continue the idle loop. + * schedule the previous vcpu again, which will lead to the desired + * processing to be done. * Undo the rendezvous_in_cnt decrement and schedule another call = of * sched_slave(). */ - if ( is_idle_unit(prev) && sched_tasklet_check_cpu(cpu) ) + if ( rcu_pending(cpu) || + (is_idle_unit(prev) && sched_tasklet_check_cpu(cpu)) ) { struct vcpu *vprev =3D current; =20 diff --git a/xen/include/xen/softirq.h b/xen/include/xen/softirq.h index b4724f5c8b..1f6c4783da 100644 --- a/xen/include/xen/softirq.h +++ b/xen/include/xen/softirq.h @@ -4,10 +4,10 @@ /* Low-latency softirqs come first in the following list. */ enum { TIMER_SOFTIRQ =3D 0, + RCU_SOFTIRQ, SCHED_SLAVE_SOFTIRQ, SCHEDULE_SOFTIRQ, NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, - RCU_SOFTIRQ, TASKLET_SOFTIRQ, NR_COMMON_SOFTIRQS }; --=20 2.16.4 From nobody Tue May 7 22:50:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1588259784; cv=none; d=zohomail.com; s=zohoarc; b=GPH4hMACYdP+AluIymHrBwRKGR1bNeXHEQCGXEFXZ4BmnFG7fxTtf2B0Cjaawls6OqR1FWm/i03QmLIfWFBUrteyO7SAgJc8QcPRI1xMxlsbkT6Gv6ZHeeH8ggeWNbI80FGl8TWLsccbnViG1uxCzy5d5jApdxiSE7Dmt1Zn/8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588259784; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=qh+PebWsGwiQs5LhsWZy/Pv9i/n3VJ/XDLykn4j7aRw=; b=DKiu8iZXFn4NNYCk89SfOZSG0cwIU58QbKRUzsmTGASQPTrjr1E7eyYY+udQcIzUZCenQHeHBEsnijDZ5Wx7ce1pT3i7KW1KYiGjzZfYbG8XR5kPzqqe5ME/gxSQ+EEfKw7EY/xbtMoxu0DMOAUORt9wf8Vc7B4z89UDhFigr3o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1588259784437804.5657632023565; Thu, 30 Apr 2020 08:16:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAv4-0007Qi-KQ; Thu, 30 Apr 2020 15:16:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAv2-0007QH-Qs for xen-devel@lists.xenproject.org; Thu, 30 Apr 2020 15:16:08 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 81432d56-8af5-11ea-9887-bc764e2007e4; Thu, 30 Apr 2020 15:16:03 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 62BACADCD; Thu, 30 Apr 2020 15:16:01 +0000 (UTC) X-Inumbo-ID: 81432d56-8af5-11ea-9887-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Subject: [PATCH 2/3] xen/sched: fix theoretical races accessing vcpu->dirty_cpu Date: Thu, 30 Apr 2020 17:15:58 +0200 Message-Id: <20200430151559.1464-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200430151559.1464-1-jgross@suse.com> References: <20200430151559.1464-1-jgross@suse.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. 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 --- 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) =20 if ( !is_idle_domain(pd) ) { + ASSERT(read_atomic(&p->dirty_cpu) =3D=3D cpu); memcpy(&p->arch.user_regs, stack_regs, CTXT_SWITCH_STACK_BYTES); vcpu_save_fpu(p); pd->arch.ctxt_switch->from(p); @@ -1832,7 +1833,7 @@ void context_switch(struct vcpu *prev, struct vcpu *n= ext) { unsigned int cpu =3D smp_processor_id(); const struct domain *prevd =3D prev->domain, *nextd =3D next->domain; - unsigned int dirty_cpu =3D next->dirty_cpu; + unsigned int dirty_cpu =3D read_atomic(&next->dirty_cpu); =20 ASSERT(prev !=3D next); ASSERT(local_irq_is_enabled()); @@ -1844,6 +1845,7 @@ void context_switch(struct vcpu *prev, struct vcpu *n= ext) { /* Remote CPU calls __sync_local_execstate() from flush IPI handle= r. */ flush_mask(cpumask_of(dirty_cpu), FLUSH_VCPU_STATE); + ASSERT(read_atomic(&next->dirty_cpu) =3D=3D VCPU_CPU_CLEAN); } =20 _update_runstate_area(prev); @@ -1956,13 +1958,17 @@ void sync_local_execstate(void) =20 void sync_vcpu_execstate(struct vcpu *v) { - if ( v->dirty_cpu =3D=3D smp_processor_id() ) + unsigned int dirty_cpu =3D read_atomic(&v->dirty_cpu); + + if ( dirty_cpu =3D=3D smp_processor_id() ) sync_local_execstate(); - else if ( vcpu_cpu_dirty(v) ) + else if ( is_vcpu_dirty_cpu(dirty_cpu) ) { /* Remote CPU calls __sync_local_execstate() from flush IPI handle= r. */ - flush_mask(cpumask_of(v->dirty_cpu), FLUSH_VCPU_STATE); + flush_mask(cpumask_of(dirty_cpu), FLUSH_VCPU_STATE); } + ASSERT(read_atomic(&v->dirty_cpu) !=3D dirty_cpu || + dirty_cpu =3D=3D VCPU_CPU_CLEAN); } =20 static int relinquish_memory( diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 195e7ee583..008d3c8861 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -844,7 +844,7 @@ static inline bool is_vcpu_dirty_cpu(unsigned int cpu) =20 static inline bool vcpu_cpu_dirty(const struct vcpu *v) { - return is_vcpu_dirty_cpu(v->dirty_cpu); + return is_vcpu_dirty_cpu(read_atomic(&v->dirty_cpu)); } =20 void vcpu_block(void); --=20 2.16.4 From nobody Tue May 7 22:50:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1588259789; cv=none; d=zohomail.com; s=zohoarc; b=S9+XIu478P/nWON/pImOcvj9OTqXvHvBDngc6Rqj6F8XDzZK9HMVWPOMm/yax8l2vVtY0bmWvxS4ME6O+sMoHqHeD39pI1Vpf4aDQ8+5yWJi4YTH4G4d9+eCURhVkYGx89/A8qwZj7h2LobeI/Ef+ahm3Ae70p75V8A57iB40QY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588259789; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ny1M/drX4m3QII0hZRIWJJo1CHlVve5zzZTi1INaUm4=; b=MFGzNfaDBgv80n7BcNVuMJ4RQMEbHiK1n7yHVwWM6gisYZAQsz7hsaIF/1H8EJbKqPqF3eMgvNw5P0KRr56mbshhlqFSNyvy+jl2MkfnxzLWU45Saq6o9kTKpw3KILMGLGeDCmFX1WHgYh+T2XH/hVc5SDTG/dqP2+0B1GlcXKU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1588259789044689.7187631261121; Thu, 30 Apr 2020 08:16:29 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAv5-0007Rd-U3; Thu, 30 Apr 2020 15:16:11 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jUAv4-0007R4-Um for xen-devel@lists.xenproject.org; Thu, 30 Apr 2020 15:16:10 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 811ec43f-8af5-11ea-9a67-12813bfff9fa; Thu, 30 Apr 2020 15:16:03 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7ECE7AF4C; Thu, 30 Apr 2020 15:16:01 +0000 (UTC) X-Inumbo-ID: 811ec43f-8af5-11ea-9a67-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Subject: [PATCH 3/3] xen/cpupool: fix removing cpu from a cpupool Date: Thu, 30 Apr 2020 17:15:59 +0200 Message-Id: <20200430151559.1464-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200430151559.1464-1-jgross@suse.com> References: <20200430151559.1464-1-jgross@suse.com> X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , George Dunlap , Dario Faggioli Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit cb563d7665f2 ("xen/sched: support core scheduling for moving cpus to/from cpupools") introduced a regression when trying to remove an offline cpu from a cpupool, as the system would crash in this situation. Fix that by testing the cpu to be online. Fixes: cb563d7665f2 ("xen/sched: support core scheduling for moving cpus to= /from cpupools") Signed-off-by: Juergen Gross Acked-by: Dario Faggioli --- xen/common/sched/cpupool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xen/common/sched/cpupool.c b/xen/common/sched/cpupool.c index d40345b585..de9e25af84 100644 --- a/xen/common/sched/cpupool.c +++ b/xen/common/sched/cpupool.c @@ -520,6 +520,9 @@ static int cpupool_unassign_cpu(struct cpupool *c, unsi= gned int cpu) debugtrace_printk("cpupool_unassign_cpu(pool=3D%d,cpu=3D%d)\n", c->cpupool_id, cpu); =20 + if ( !cpu_online(cpu) ) + return -EINVAL; + master_cpu =3D sched_get_resource_cpu(cpu); ret =3D cpupool_unassign_cpu_start(c, master_cpu); if ( ret ) --=20 2.16.4