From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=35.162.73.231 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336050; b=whvC/g/k0/EF2U5dsy07vLvH/WYfrB0tWoHG/JC9P8wjAuLcoZ1FG/EZNOBVBXqVcRGz 4g2D/U2rU8zFreC1MxRQ7hB60UQdCHdrWxdv+tISuQjMsz2ftVduhBLYdSR/AOYzxTIyH VF41RUeiyW0jdWnHFbu4+dUIHrn7JiyYdskkaQFOVH7Z8IcVHSJRy+qjpb1G4WlgUlrJf kwFwLbPXYOORBNtFWw/ba4/rQxrmQ0nCsoDH1AAYqcTyIA4s5+Mxmd0dr2StEW08hyiQK dgSSISbtB9ImMHa6uJw7LXKC4RWwfB1FJGQlGYuEitAMLIqqvMh4X169t7gRLzJFS6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336050; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=PCat+jJG0uXBSFaxAhTA6U8pB3zgSiXaUwxkq+ouM/4=; b=gRC2F5MA6VCaVx+k9huoyWe22zFkYJEfGa2Lyti2Aeenhcf38sFFoo7g0stFo5EZrfKB KjOausqn37lBtDW9UObm7+T3Pi9vD6TTe4zfuDrcuopkxz3O4WbL50P1PXPp3fzGwxfwU K7vJlPv0qAYuFLs7tq7ON/A0mLJTuSoDl8aKe0AA7gUIlRvN3WTbyjtM2Lkq4m2hjabCu ym3VZ6eSFtHpmPZCEMUMd74JAuq+oNGMe00UVT5GK2d0cMGT6RZzRF4KDtRhNu7SXarO+ Vyre/70cA/CP1Hg3er4sMs6+1LBtuds65MANQbSPKdfp5bN0+WmtBA1f+rGgM4f/xNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b=Aec+j+d6; arc=none smtp.remote-ip=35.162.73.231 Received: from pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com [35.162.73.231]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36382606A322; Thu, 3 Dec 2026 22:14:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36382606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b=Aec+j+d6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1796336050; x=1827872050; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PCat+jJG0uXBSFaxAhTA6U8pB3zgSiXaUwxkq+ouM/4=; b=Aec+j+d6rIOWkbeTSa68cNyDUXG0sd+GjIcETCghJ9EZuuYOZ874xyKs ZSTDfIUvouqAkqv5r7wVao5eQ9oi6OXMP4oKl56XAwMd7EUpa2inunW93 2dvkju61y306oUsqat7UYlMVOoFO9rkBeJkdSWP19dyqLoxgPYHzcHc8b rIrKrhpBTtQcoAcJVVJImVjzb+9dH5n3bsnXIaY25PzcXjDWGQwuWDpqn Ax2oE1B5gk9SJO5MdG1CqBjsKRLpNR09+o8yuB89MTd8oeWvyTF06EYEQ cQrGARXU4wlmbr4LFW462ELy1VUxEPgPifMBj4QttN7D7fNrvy0t44IFi Q==; X-CSE-ConnectionGUID: KKFsCAODRw66PRVTs1BTAw== X-CSE-MsgGUID: olpgah7/TyOi+FR0YNODbw== X-IronPort-AV: E=Sophos;i="6.29,77,1794873600"; d="scan'208";a="35701435" Received: from ip-10-5-0-115.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.0.115]) by internal-pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:14:01 +0000 Received: from EX19MTAUWA002.ant.amazon.com [205.251.233.178:25547] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.48.218:2525] with esmtp (Farcaster) id 5199fe53-8e68-46c9-83d4-37650efd3372; Thu, 3 Dec 2026 22:14:01 +0000 (UTC) X-Farcaster-Flow-ID: 5199fe53-8e68-46c9-83d4-37650efd3372 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:14:01 +0000 Received: from dev-dsk-araoof-1b-23e02486.eu-west-1.amazon.com (10.253.65.187) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:13:58 +0000 From: Ahmed Abdelraoof To: Ingo Molnar , Peter Zijlstra CC: Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , "Mel Gorman" , Valentin Schneider , "K Prateek Nayak" , Jonathan Corbet , Shuah Khan , Randy Dunlap , , , Ahmed Abdelraoof , Anselm Busse Subject: [PATCH 2/4] sched/core: Nest the isolation unit rq locks under one lock for lockdep Date: Thu, 3 Dec 2026 22:13:05 +0000 Message-ID: <20261203221307.86078-3-araoof@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203221307.86078-1-araoof@amazon.de> References: <20261203221307.86078-1-araoof@amazon.de> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWA002.ant.amazon.com (10.13.139.96) To EX19D001UWA001.ant.amazon.com (10.13.138.214) From: Ahmed Abdelraoof Lockdep does not properly handle nested locking of more than 8 locks of the same class using subclasses. This showed up when testing L2-cache-based core scheduling policies in QEMU with custom topologies. To work around this limitation, take the rq lock of the unit's first CPU as a subclass of its own and nest the other rq locks under it. The idea of using a nest lock to work around the 8-subclass limit is inspired by commit e4a454ced74c ("KVM: add kvm_lock_all_vcpus and kvm_trylock_all_vcpus"), where they did the trick using an already existing lock. The idea of splitting the first lock into a subclass of its own is inspired by commit 566c09c53455 ("raid5: relieve lock contention in get_active_stripe()"). Co-developed-by: Anselm Busse Signed-off-by: Anselm Busse Signed-off-by: Ahmed Abdelraoof --- kernel/sched/core.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index cdd944bb274d..b62716094445 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -429,16 +429,26 @@ static DEFINE_MUTEX(sched_core_mutex); static atomic_t sched_core_count; static struct cpumask sched_core_mask; +/* + * The rq locks of a unit share one lockdep class, and a subclass per CPU + * would overflow MAX_LOCKDEP_SUBCLASSES on units wider than eight CPUs. So + * nest them under the first CPU's rq lock, taken as a subclass of its own. + */ +#define SCHED_CORE_NEST_SUBCLASS (SINGLE_DEPTH_NESTING + 1) + static void sched_core_lock(int cpu, unsigned long *flags) __context_unsafe(/* acquires multiple */) __acquires(&runqueues.__lock) /* overapproximation */ { const struct cpumask *isolation_mask = sched_core_isolation_mask(cpu); - int t, i = 0; + struct rq *first = cpu_rq(cpumask_first(isolation_mask)); + int t; - local_irq_save(*flags); - for_each_cpu(t, isolation_mask) - raw_spin_lock_nested(&cpu_rq(t)->__lock, i++); + raw_spin_lock_irqsave_nested(&first->__lock, *flags, SCHED_CORE_NEST_SUBCLASS); + for_each_cpu(t, isolation_mask) { + if (cpu_rq(t) != first) + raw_spin_lock_nest_lock(&cpu_rq(t)->__lock, &first->__lock); + } } static void sched_core_unlock(int cpu, unsigned long *flags) @@ -446,11 +456,14 @@ static void sched_core_unlock(int cpu, unsigned long *flags) __releases(&runqueues.__lock) /* overapproximation */ { const struct cpumask *isolation_mask = sched_core_isolation_mask(cpu); + struct rq *first = cpu_rq(cpumask_first(isolation_mask)); int t; - for_each_cpu(t, isolation_mask) - raw_spin_unlock(&cpu_rq(t)->__lock); - local_irq_restore(*flags); + for_each_cpu(t, isolation_mask) { + if (cpu_rq(t) != first) + raw_spin_unlock(&cpu_rq(t)->__lock); + } + raw_spin_unlock_irqrestore(&first->__lock, *flags); } static void __sched_core_flip(bool enabled) -- 2.47.3