Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2326944imm; Fri, 7 Sep 2018 14:43:47 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda83rUU1Mja7upchYxXY8NG48uOpb6iD2Pcphi2a4NrTqs30gu4pMmrNdIFYF0FlIW4TseI X-Received: by 2002:a17:902:20c6:: with SMTP id v6-v6mr10256850plg.228.1536356627282; Fri, 07 Sep 2018 14:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536356627; cv=none; d=google.com; s=arc-20160816; b=r0POlxo96EaI36M84/iEMMICJKsxjZ2V52hXw1Ae4Iy/dzDMxe2W4/u+xA8J15PsYA GUJvIL8ChCiKQyZyZjKeHSdAwBwcvpKhOY9ITlhy5kd+aA2G0e7uewzDFBOdh5jh4yPh c0YjidJ2iz38rITNn24Lwpe5fOVU3oOS/vnZlXQsSNCJT764TWs5LaIdKsANioyZf8qA ggnTcbqWS7XEkFTFTndqNO/Wvqiptcd4MVQRLjRrz74RdwYq75vp6ntbEuG7elsIhcIj TdaxsS1PKBdPik9vfEYifCjmRBDc8g2JjOgEZf9P8Qltj3f7Gd/V8r1XR+3e1vblxv4D mrAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=joqvvsSFTjime50bAsocxHF0anIX+QiAH7cQP3678XQ=; b=xTCw7lnTmxKMDr4mvUJy4YWIFnmf9SsmmYieRe99gZE86CpNCLRrmmAYq2l9qZvdIN 4iQjwrJMjSayCF5Eb8ikDJE6qETbah6EEfm40tkwvg4HQhCA3aK2RpJylLqmGVF5iDzk eMSMasw5NO6RziJ00x9treIeljW+W9R/nRqbQse4iKfK/F360oFWPdJ2si6Yb95cRJq3 pqWwWybi7uQihsOuOXCqd/n0xKxC7uRltqKaD17kFSwcp7ism/oa548u36uWym4ul8Nh e8GdT8rVUALuyfIA+Pr4DnkrIH5GaVbCLjaKZdy0iCHqLbNt4um4YozelU27GPqi79Oj sROA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=ul91v0eL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6-v6si9673850pgh.50.2018.09.07.14.43.32; Fri, 07 Sep 2018 14:43:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=ul91v0eL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730609AbeIHCZZ (ORCPT + 99 others); Fri, 7 Sep 2018 22:25:25 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:26485 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729715AbeIHCZZ (ORCPT ); Fri, 7 Sep 2018 22:25:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1536356549; x=1567892549; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=joqvvsSFTjime50bAsocxHF0anIX+QiAH7cQP3678XQ=; b=ul91v0eLqa00XrhfYIHBbPDr9IeOOsZpcV66tXZXnItzW2rQ5lOuYNH2 HZInBN1oV1Eao5bqHCWgvlhVAn0mO860FUPCy/IWYhkWT8BnKJ2xd929U MgWG722juxy1rWKWV5Rva5Qh0R7Xl/fANzqgbUkVFBgW7VEwr0AHStcIr 8=; X-IronPort-AV: E=Sophos;i="5.53,343,1531785600"; d="scan'208";a="696509969" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-16acd5e0.us-east-1.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 07 Sep 2018 21:42:29 +0000 Received: from u7588a65da6b65f.ant.amazon.com (iad7-ws-svc-lb50-vlan2.amazon.com [10.0.93.210]) by email-inbound-relay-1a-16acd5e0.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w87LgOeJ021423 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 7 Sep 2018 21:42:26 GMT Received: from u7588a65da6b65f.ant.amazon.com (localhost [127.0.0.1]) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTPS id w87LgMYt027541 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 7 Sep 2018 23:42:23 +0200 Received: (from jschoenh@localhost) by u7588a65da6b65f.ant.amazon.com (8.15.2/8.15.2/Submit) id w87LgLM1027537; Fri, 7 Sep 2018 23:42:21 +0200 From: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= To: Ingo Molnar , Peter Zijlstra Cc: =?UTF-8?q?Jan=20H=2E=20Sch=C3=B6nherr?= , linux-kernel@vger.kernel.org Subject: [RFC 35/60] cosched: Adjust rq_lock() functions to work with hierarchical runqueues Date: Fri, 7 Sep 2018 23:40:22 +0200 Message-Id: <20180907214047.26914-36-jschoenh@amazon.de> X-Mailer: git-send-email 2.9.3.1.gcba166c.dirty In-Reply-To: <20180907214047.26914-1-jschoenh@amazon.de> References: <20180907214047.26914-1-jschoenh@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Locks within the runqueue hierarchy are always taken from bottom to top to avoid deadlocks. Let the lock validator know about this by declaring different runqueue levels as distinct lock classes. Signed-off-by: Jan H. Schönherr --- kernel/sched/sched.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 594eb9489f3d..bc3631b8b955 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2083,11 +2083,26 @@ task_rq_unlock(struct rq *rq, struct task_struct *p, struct rq_flags *rf) raw_spin_unlock_irqrestore(&p->pi_lock, rf->flags); } +#ifdef CONFIG_COSCHEDULING +/* + * The hierarchical runqueues have locks which are taken from bottom to + * top. For lock validation, we use the level to calculate the subclass. + * As it is sometimes necessary to take two locks on the same level, we + * leave some space in the subclass values for that purpose. + */ +#define RQ_LOCK_SUBCLASS(rq) (2 * (rq)->sdrq_data.level) +#define RQ_LOCK_SUBCLASS_NESTED(rq) (2 * (rq)->sdrq_data.level + 1) +#else +#define RQ_LOCK_SUBCLASS(rq) 0 +#define RQ_LOCK_SUBCLASS_NESTED(rq) SINGLE_DEPTH_NESTING +#endif + static inline void rq_lock_irqsave(struct rq *rq, struct rq_flags *rf) __acquires(rq->lock) { - raw_spin_lock_irqsave(&rq->lock, rf->flags); + raw_spin_lock_irqsave_nested(&rq->lock, rf->flags, + RQ_LOCK_SUBCLASS(rq)); rq_pin_lock(rq, rf); } @@ -2095,6 +2110,14 @@ static inline void rq_lock_irq(struct rq *rq, struct rq_flags *rf) __acquires(rq->lock) { + /* + * There's no raw_spin_lock_irq_nested(). This is probably fine, as at + * most the first lock should be acquired this way. There might be some + * false negatives, though, if we start with a non-bottom lock and + * classify it incorrectly. + */ + SCHED_WARN_ON(RQ_LOCK_SUBCLASS(rq)); + raw_spin_lock_irq(&rq->lock); rq_pin_lock(rq, rf); } @@ -2103,7 +2126,7 @@ static inline void rq_lock(struct rq *rq, struct rq_flags *rf) __acquires(rq->lock) { - raw_spin_lock(&rq->lock); + raw_spin_lock_nested(&rq->lock, RQ_LOCK_SUBCLASS(rq)); rq_pin_lock(rq, rf); } @@ -2111,7 +2134,7 @@ static inline void rq_relock(struct rq *rq, struct rq_flags *rf) __acquires(rq->lock) { - raw_spin_lock(&rq->lock); + raw_spin_lock_nested(&rq->lock, RQ_LOCK_SUBCLASS(rq)); rq_repin_lock(rq, rf); } -- 2.9.3.1.gcba166c.dirty