Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3314450ybt; Mon, 29 Jun 2020 22:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrAq+mjUMvow7k/KnzuuG6IpjWfFioMAlJ1DlV5hGDyU69e2wqEkIp6Ydk+KEtTFHJt1ER X-Received: by 2002:aa7:d1c8:: with SMTP id g8mr20747037edp.337.1593496005074; Mon, 29 Jun 2020 22:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593496005; cv=none; d=google.com; s=arc-20160816; b=HAX+743H/9S6hoMGVNKKZ9LNs0fElDTucWPuvamH3ovpgd7MmtWb4hFQMj61pDBsu/ vYNXr9eIYdUbKJWHZnAPw5dNsLT1Ma4N9aovi2X0NAKzGIA1tgN6AEryUDeqKc31V3zC ahCBCqsaelN8lPcPfVaNVCC+W27M4xHl5ojwiClZFgVaLplNrJX2XOceYE4OdQjsc5p+ 8iztqARKTXP9d+6DQTEG7RR4P8ZCERrYu8BM3Uctu6sg/IDmjIFzFjUChRVH1Bn4hFWo lDtEutbjnZovVUB5AJxFxX5Wn5O5c+kz5kXUJ6cFqWiwRHbYzNHh0DiphgxkBZEKY3jV LN+g== 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=NZtLnEh/8Ggo1oSNGaCwKiFVpXV3Gu22apdwju3+xHU=; b=W1oHY2W3pwUj9tEn3THIZ6OiG7QXr4YuST5Om83uKIoRe7ZbJzngEkIl0c23895IXZ nvq+m9Ys+7WM2BAKq9NxiXysVw6KGWtc/+CufcYkyaNYuir6vIwLshjJyuc/I3Xdi3Bi P0u6re9La6eg6XoEQyP3+ifKz+XJJWp9QaWnenprPQqkAJOKPjwDW06PCJSanxMMx616 pehg1CasUodSl3cxFIcQFu7RgMolhg/ul9rfOVUIulYRJ88F7NxT38PTXgSqATpZ10xX xoFSRCiQK53BMto1xhDbLeUDFMcvHnUs2ICwKiX+ZTFy75AqUin0XZyQGsYDawWQ3iWt sCkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Ba9A/7hH"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=OBX1YqwE; 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 h17si1071063ejd.655.2020.06.29.22.46.22; Mon, 29 Jun 2020 22:46:45 -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="Ba9A/7hH"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=OBX1YqwE; 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 S1729879AbgF3Fpk (ORCPT + 99 others); Tue, 30 Jun 2020 01:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729852AbgF3Fpj (ORCPT ); Tue, 30 Jun 2020 01:45:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3401AC061755 for ; Mon, 29 Jun 2020 22:45:39 -0700 (PDT) From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1593495936; 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=NZtLnEh/8Ggo1oSNGaCwKiFVpXV3Gu22apdwju3+xHU=; b=Ba9A/7hHQxrkLXf0rvCy47Zkw+9B2hPA5CmF9GYaxFpYfUYK37bKRc8ldMzYgGxMPYmjWC pRLhmR/+2tkRSPl5iSTACEMOizob6b5+ztZ8mhRxCe9yxXVphmuGcRwxjbWFp/u60qZgs4 CNPr3+LkYu7lWC/d0OgqkgPJTnJitx8QtOl4fLbUPWF5lRkmJa2ShoYYqUH2K5mVwNTGV5 Ib1soCjGt57cMLr5xhAsghUVLoa0IBHDOuultpdgFtsNhtr1fqZRxfC2fgfaCQFLFHbutP nEBENJIUxWRip4zj8tK+VbAYaOfthQ7KRJkgU+PZaXvpXes7I2fn7FCM4IRBfA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1593495936; 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=NZtLnEh/8Ggo1oSNGaCwKiFVpXV3Gu22apdwju3+xHU=; b=OBX1YqwEJi7iGB0pX3HuWQwxwNqWtIyXA/f7x0tg57fieF+pY6ixJ3isrm4hKlWw1lKTHi VL3zGoM/rJLTGLDg== 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 , Al Viro Subject: [PATCH v3 09/20] sched: tasks: Use sequence counter with associated spinlock Date: Tue, 30 Jun 2020 07:44:41 +0200 Message-Id: <20200630054452.3675847-10-a.darwish@linutronix.de> In-Reply-To: <20200630054452.3675847-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200630054452.3675847-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 03403ca6e44e..1b4e6b8dc523 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1055,7 +1055,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 f44d70307210..eb260c6bdb8b 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