Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp2415185pjr; Tue, 19 May 2020 14:49:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtdCFI2+XDzwVrMdbLzoontpJx01SlzFVdiiDov/tdGqI16fncxIeCYMpHfLbmPrbHxzDx X-Received: by 2002:a17:906:b5c1:: with SMTP id ep1mr1107807ejb.528.1589924979344; Tue, 19 May 2020 14:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589924979; cv=none; d=google.com; s=arc-20160816; b=MGA/Ivr6ldUD9sep2Rt3YLOsEhpuJ2wY/ibwawDJJ7xlN+fPcNKErFVonXB+Vr40uI mPgiCuu4WTCYomXmIvGezt+EchWcIl4xA0PMuqtgMtKSzp0EtidVxPd/uBsm6Q3dvCPV Nw7x0rgvx2CVS4P39GBwl1C2aTz9l3+9Jsni5TWXg/elSxyH8D7QLYYTjIQ+LWYNCLAg 5jgHpSOFmpA7C5gXGxR+tCHOZQhYavG87grsHHjtaa1ah3CdlHfy6y6p9zZg6h+3u4Am ekgieQjc96UrL7ZX/pHRM+y0v+WvSvMaXqQ8ltEAjEZSHf3boZwvmBVm3rbFiXWZ4zBf u3ug== 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; bh=GSi6hcFbQsyRLd6lK+flHZPRQKACdV2GO0WIXjMRGOs=; b=RPoWfGP8sxirUebwSrL6zop/3usr7+7cjPWaw7f2RIehFwJUZB7+zs66lExiLd2JaV LTMLPmWakSb2RYARM6K4qHyhowUwNau0ih+cb6ZSDTfRNjJ40VMelOPNGmB/TCpEzxtJ BossUPTDH9bFRe5Pe9UTDnOw3zIjdVnUuLIq5LXKebJPSviG1Fn8RNPRCA+B1AtDxApb dIop9ilCTCQtj0xiQiePgKAxPafXLc2M8hneu5eW8wg9mJ/31dIyc2b9kRI9ZSYYZ3AC ljrhctaaceBJ2c+LQBGQSGk9jDS6u/10X9/cDAyzAwfck0y8TINo6ngslxBBxO3llm6D atsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si380717edx.300.2020.05.19.14.49.16; Tue, 19 May 2020 14:49:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727918AbgESVrV (ORCPT + 99 others); Tue, 19 May 2020 17:47:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728361AbgESVrT (ORCPT ); Tue, 19 May 2020 17:47:19 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35DE4C08C5C0 for ; Tue, 19 May 2020 14:47:19 -0700 (PDT) Received: from [5.158.153.53] (helo=debian-buster-darwi.lab.linutronix.de.) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1jbA4h-0002ll-Nr; Tue, 19 May 2020 23:46:59 +0200 From: "Ahmed S. Darwish" To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , "Ahmed S. Darwish" , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman Subject: [PATCH v1 14/25] sched: tasks: Use sequence counter with associated spinlock Date: Tue, 19 May 2020 23:45:36 +0200 Message-Id: <20200519214547.352050-15-a.darwish@linutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200519214547.352050-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A sequence counter write side critical section must be protected by some form of locking to serialize writers. A plain seqcount_t does not contain the information of which lock must be held when entering a write side critical section. Use the new seqcount_spinlock_t data type, which allows to associate a spinlock with the sequence counter. This enables lockdep to verify that the spinlock used for writer serialization is held when the write side critical section is entered. If lockdep is disabled this lock association is compiled out and has neither storage size nor runtime overhead. Signed-off-by: Ahmed S. Darwish --- include/linux/sched.h | 2 +- init/init_task.c | 3 ++- kernel/fork.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 4418f5cb8324..a9ce6fbeb735 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1046,7 +1046,7 @@ struct task_struct { /* Protected by ->alloc_lock: */ nodemask_t mems_allowed; /* Seqence number to catch updates: */ - seqcount_t mems_allowed_seq; + seqcount_spinlock_t mems_allowed_seq; int cpuset_mem_spread_rotor; int cpuset_slab_spread_rotor; #endif diff --git a/init/init_task.c b/init/init_task.c index bd403ed3e418..94bf4aea8293 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -142,7 +142,8 @@ struct task_struct init_task .rcu_tasks_idle_cpu = -1, #endif #ifdef CONFIG_CPUSETS - .mems_allowed_seq = SEQCNT_ZERO(init_task.mems_allowed_seq), + .mems_allowed_seq = SEQCNT_SPINLOCK_ZERO(init_task.mems_allowed_seq, + &init_task.alloc_lock), #endif #ifdef CONFIG_RT_MUTEXES .pi_waiters = RB_ROOT_CACHED, diff --git a/kernel/fork.c b/kernel/fork.c index 8c700f881d92..a0fde1f17e0a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2019,7 +2019,7 @@ static __latent_entropy struct task_struct *copy_process( #ifdef CONFIG_CPUSETS p->cpuset_mem_spread_rotor = NUMA_NO_NODE; p->cpuset_slab_spread_rotor = NUMA_NO_NODE; - seqcount_init(&p->mems_allowed_seq); + seqcount_spinlock_init(&p->mems_allowed_seq, &p->alloc_lock); #endif #ifdef CONFIG_TRACE_IRQFLAGS p->irq_events = 0; -- 2.20.1