Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp31979ybh; Mon, 20 Jul 2020 09:36:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmgCiekdf60KDQMNY9o8OQOl6oBaNvolcjEHmPmsuJRPsJdZhTGgDSC1PXPK9lNrtbNF2k X-Received: by 2002:a17:906:26c3:: with SMTP id u3mr20919968ejc.483.1595263000071; Mon, 20 Jul 2020 09:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595263000; cv=none; d=google.com; s=arc-20160816; b=GKiWj0OVbFWGxoJ8L+dLjo1jhs8Wz7LwtQS2g3Q9zE4K74IfJPh6t0gANEXAoTl0VK K9JGAiSGwzHQJGKtLK1jSHN3pBkJQh+SM588FCcqrFxzQMuOJjXAU67aS0wbF2B8GDwh ClCk7mH3QsJuN5zcTm4VYi7Y1ir5U7QeRh2Ng3OZqAB1PZJDLwyhO4K4nIcVoHrePDlY bZMcSZZxUZscv/4RzDwhQhVi8CSA+CBYd39HZVrQUUWz5ot/llD5Q95q8dLmyN/lMMPm rYWFqPpmVnWfn8BQThlG+sBX2z7pRKGOLqqWpgwYcPdLja2BH8z+jH1HNZYG0vDt+buA 85ow== 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:dkim-signature :dkim-signature:from; bh=2ibnEuLlWkcgCJuuCSAjE3qOy+g2tj8o5DrfPGmZmRc=; b=MLWYSzHaNzk0rJdzl0EKf8CWPrQXL6DZuQgATi/Qm8L34+Z840vGWMlnZFy2uXfd/i sJDDHvhcnMpjZghBsLHjShuo6LdL8fZu9nT4qgVMioHAMPNRBUECZWK/A361Tcq/zAb7 1p/EOaVloowfLVAKQUmcao5MHiZ+8VfDglw6eI5ftyH4yVJe1YkyAG3TuH0IY/fKXZxF tEi7WSmhCeoMchut7GeaxftEAEMMAUHsmlpPvfd0pK754BJWcgm2Lfq3jrTRUn7GZ+Hy BnEbVuc1ROJ617bxNJsGB0LdI+/4rE+8DdH+7WQx6ZWffBKBb/akveVlV+aR6XkqYJys xYog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UvGi3z0t; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt3si10383222ejc.325.2020.07.20.09.36.17; Mon, 20 Jul 2020 09:36:40 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UvGi3z0t; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388895AbgGTQcp (ORCPT + 99 others); Mon, 20 Jul 2020 12:32:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730992AbgGTP4f (ORCPT ); Mon, 20 Jul 2020 11:56:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D2F5C061794 for ; Mon, 20 Jul 2020 08:56:35 -0700 (PDT) From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595260593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2ibnEuLlWkcgCJuuCSAjE3qOy+g2tj8o5DrfPGmZmRc=; b=UvGi3z0tDcFCO1CP1C+IISAQBVtEzONYOzBrKEVxhIw+MRNVBdcyeKlxjD7A98aS2A7f+P ocUOhyqRuTdnQeBisonc9TGcFnAPdhr05+1ChRsgK87VGOCqv5/8lqmsA1fFRlW3/jQ2K4 4dVzezziMH87l+dw5sXbdJxKyRZobBAmrBAsaMhN0f8jB6C+jNmbsxlv711EafFa2fHJbq N9m10+HNNL6uicJXxnwH6xtL/jVS9LwS5sKa627hXEnf85OnFC5g+dvCxPQH4t28MKd6ON LTIXo1xjd8VRxSeb4Hrppy0jaWgUho5VFALwo+BHXHv6AvkMUpewxd8nw8u4Fw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595260593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2ibnEuLlWkcgCJuuCSAjE3qOy+g2tj8o5DrfPGmZmRc=; b=Y5UkKKqcJ7mr9m9lYH7b60QSNLSEbBByqZTHJXvji4occvABn2TpQ5UfA5Hc4LZ9BmqbtP 6td+ymMRIcl7wtDw== 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 , Al Viro Subject: [PATCH v4 13/24] sched: tasks: Use sequence counter with associated spinlock Date: Mon, 20 Jul 2020 17:55:19 +0200 Message-Id: <20200720155530.1173732-14-a.darwish@linutronix.de> In-Reply-To: <20200720155530.1173732-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200720155530.1173732-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 3903a9500926..02b7fbd17bf6 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1054,7 +1054,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 15089d15010a..94fe3ba1bb60 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -154,7 +154,8 @@ struct task_struct init_task .trc_holdout_list = LIST_HEAD_INIT(init_task.trc_holdout_list), #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 70d9d0a4de2a..fc72f09a61b2 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2032,7 +2032,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