From nobody Mon May 6 08:02:42 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=1588778244; cv=none; d=zohomail.com; s=zohoarc; b=NLngbXgpVd7kg0qNxnEiA2FaYWj6k7U7G5laacpFxnIkChyDLN2jMQDadOwYQmCOekWKg01tL84n1TAqiGcCz8xryD65btJ15uhL0ZWTKZ3+7sFZdVQiV7t99Sy8MUKQhuBV1rhkR0eYonie1F14rwemJaqjcKrRXQcBQgZaOX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588778244; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=VAwT3DnuWV4xM2QQE5ib0JjZPyRlivx9IrJduov9r+k=; b=UmkPkEOZrNLX0B4RUY/fxJ0eDqFtLFnj9ts37RdFEFNL3K1htr/7cf0cNLx5+R7fl/4RSQPvtR7bpexFZcRbEeOHfFcb2XXUz5vSHSAz/f8o5kUyy5NtE6FOQVH57rE1MrN/Gb1LtKwyPmJR996S0MZbepvlhNunflZoEB60upk= 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 1588778244737748.3766791544571; Wed, 6 May 2020 08:17: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 1jWLnA-0003SJ-JC; Wed, 06 May 2020 15:17:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jWLn9-0003SE-FW for xen-devel@lists.xenproject.org; Wed, 06 May 2020 15:16:59 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a0b6ffda-8fac-11ea-ae69-bc764e2007e4; Wed, 06 May 2020 15:16:58 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 57E58AE07; Wed, 6 May 2020 15:17:00 +0000 (UTC) X-Inumbo-ID: a0b6ffda-8fac-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] xen/sched: always modify vcpu pause flags atomically Date: Wed, 6 May 2020 17:16:55 +0200 Message-Id: <20200506151655.26445-1-jgross@suse.com> X-Mailer: git-send-email 2.26.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Type: text/plain; charset="utf-8" credit2 is currently modifying the pause flags of vcpus non-atomically via sched_set_pause_flags() and sched_clear_pause_flags(). This is dangerous as there are cases where the paus flags are modified without any lock held. So drop the non-atomic pause flag modification functions and rename the atomic ones dropping the _atomic suffix. Fixes: a76255b4266516 ("xen/sched: make credit2 scheduler vcpu agnostic.") Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- It should be noted that this issue wasn't introduced by core scheduling as even before credit2 was using the non-atomic __set_bit() and __clear_bit() variants. --- xen/common/sched/credit.c | 4 ++-- xen/common/sched/private.h | 22 +--------------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/xen/common/sched/credit.c b/xen/common/sched/credit.c index 93d89da278..d0aa017c64 100644 --- a/xen/common/sched/credit.c +++ b/xen/common/sched/credit.c @@ -453,7 +453,7 @@ static inline void __runq_tickle(const struct csched_un= it *new) SCHED_UNIT_STAT_CRANK(cur, kicked_away); SCHED_UNIT_STAT_CRANK(cur, migrate_r); SCHED_STAT_CRANK(migrate_kicked_away); - sched_set_pause_flags_atomic(cur->unit, _VPF_migrating= ); + sched_set_pause_flags(cur->unit, _VPF_migrating); } /* Tickle cpu anyway, to let new preempt cur. */ SCHED_STAT_CRANK(tickled_busy_cpu); @@ -973,7 +973,7 @@ csched_unit_acct(struct csched_private *prv, unsigned i= nt cpu) { SCHED_UNIT_STAT_CRANK(svc, migrate_r); SCHED_STAT_CRANK(migrate_running); - sched_set_pause_flags_atomic(currunit, _VPF_migrating); + sched_set_pause_flags(currunit, _VPF_migrating); /* * As we are about to tickle cpu, we should clear its bit in * idlers. But, if we are here, it means there is someone runn= ing diff --git a/xen/common/sched/private.h b/xen/common/sched/private.h index 367811a12f..b9a5b4c01c 100644 --- a/xen/common/sched/private.h +++ b/xen/common/sched/private.h @@ -172,7 +172,7 @@ static inline void sched_set_pause_flags(struct sched_u= nit *unit, struct vcpu *v; =20 for_each_sched_unit_vcpu ( unit, v ) - __set_bit(bit, &v->pause_flags); + set_bit(bit, &v->pause_flags); } =20 /* Clear a bit in pause_flags of all vcpus of a unit. */ @@ -181,26 +181,6 @@ static inline void sched_clear_pause_flags(struct sche= d_unit *unit, { struct vcpu *v; =20 - for_each_sched_unit_vcpu ( unit, v ) - __clear_bit(bit, &v->pause_flags); -} - -/* Set a bit in pause_flags of all vcpus of a unit via atomic updates. */ -static inline void sched_set_pause_flags_atomic(struct sched_unit *unit, - unsigned int bit) -{ - struct vcpu *v; - - for_each_sched_unit_vcpu ( unit, v ) - set_bit(bit, &v->pause_flags); -} - -/* Clear a bit in pause_flags of all vcpus of a unit via atomic updates. */ -static inline void sched_clear_pause_flags_atomic(struct sched_unit *unit, - unsigned int bit) -{ - struct vcpu *v; - for_each_sched_unit_vcpu ( unit, v ) clear_bit(bit, &v->pause_flags); } --=20 2.26.1