Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2094100rdb; Mon, 9 Oct 2023 12:16:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4i074PTx9j2eQDxQ+hEwNd/yREqvWIfZq8WoFb3ylqnJ/qZswBts+TQcJLIFLTwLjU2Yz X-Received: by 2002:a05:6830:1db7:b0:6b8:8f20:4cbc with SMTP id z23-20020a0568301db700b006b88f204cbcmr14200457oti.13.1696879008525; Mon, 09 Oct 2023 12:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696879008; cv=none; d=google.com; s=arc-20160816; b=x726HbZmDl7ZIFbymQ31QvG4ycF54mmfxZFAXzyCBoQx1qn4Na00lB8a5BMtSrgXbc iKLBEHWDriaZkQ1arqspM1WvWzVHIEO25Glq8kW9jrqVasN1aFVrz+2A+Cg/ZhWgpdBc Vj+7+yGuhDWBdf4axMatNZRuTNlpmSxcyfhFxI406c4VBfoshGFQ1s+YjWhLqmsi2ba6 Neir7Ul0IuPmXT7yEgN4Qi/Xd6WSPOQKoqdFBztS0eOoHsNm4BtLDQar1hgoqvzHcQJK TrCOUhBRqqIHuPsVkWAZnGsEMIg/FZhNWQdn/puH6DqxetYw00UFzmr8EQDihncsvaFy +TEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Q/JoZb1bMZtb0icZrnjC3JiKSCEMlYExwLf1yuoTDUk=; fh=KsSnbSd4wIcmjaecy1qG3zuRI7Pc5yzK5LYpQr37A+U=; b=xaLkjakr6r1b7rObOnIbxNLXrOlGKpFEGVzYx+Qt4W6IWXMS3OekDHiKFrLZidQnMo LZ+uVbhLJXTpqnxoBpB2U6N8lrDKSrZGJi7loIxwLuVclI+y9ZqSxXO14cy799zp6K/G txzZpd7m+UW9bvw4QMCwv9NzHAAo3xxeLbg+7eM6qKTMkKFMAV4HRd0HnCj2Nmo6PRo/ RU6My9Hf23mc2LDGsr0EVWKG+Z0AL21WZ+G522FtHDrQ20si7nP+Q500x2l9bTHfZWOQ e83jKCJ38AFleKWVvRlHAVvb71Hq6Zxm2A5zVZWLE19xYFDiYydM8/miJ1CZcRNHMdbl m0kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B4vYKkib; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id a26-20020a63705a000000b0053074c54c3fsi10699822pgn.868.2023.10.09.12.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 12:16:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B4vYKkib; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id B77718087FFC; Mon, 9 Oct 2023 12:16:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378363AbjJITQa (ORCPT + 99 others); Mon, 9 Oct 2023 15:16:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378331AbjJITQ2 (ORCPT ); Mon, 9 Oct 2023 15:16:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0E7A109 for ; Mon, 9 Oct 2023 12:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696878941; 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; bh=Q/JoZb1bMZtb0icZrnjC3JiKSCEMlYExwLf1yuoTDUk=; b=B4vYKkibOcG/fFvyTY6KI7Fp5vVIjYXSyzo62+fGBqKs1r1BMcnC5Bwp3uW4EeGpqrzJlY YjBI+JDY8SegbIhhIanDwBSzCBxzQIcqvmXNeSsSsnyOBGPkI1nFx9sBs1KdupfYqEDPJb PajKe+mfaU0DHmI+a4bObGTXJx44uM8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-tfTbnEuOMASg9DT2tUA3gA-1; Mon, 09 Oct 2023 15:15:35 -0400 X-MC-Unique: tfTbnEuOMASg9DT2tUA3gA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D21E5805B32; Mon, 9 Oct 2023 19:15:34 +0000 (UTC) Received: from llong.com (unknown [10.22.33.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9B0B10F1BEA; Mon, 9 Oct 2023 19:15:33 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Juri Lelli , Peter Zijlstra , Ingo Molnar , Qais Yousef , Hao Luo , Dietmar Eggemann , Steven Rostedt , Waiman Long , Xia Fukun Subject: [PATCH] cgroup/cpuset: Change nr_deadline_tasks to an atomic_t value Date: Mon, 9 Oct 2023 15:15:15 -0400 Message-Id: <20231009191515.3262292-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 09 Oct 2023 12:16:42 -0700 (PDT) X-Spam-Level: ** The nr_deadline_tasks field in cpuset structure was introduced by commit 6c24849f5515 ("sched/cpuset: Keep track of SCHED_DEADLINE task in cpusets"). Unlike nr_migrate_dl_tasks which is only modified under cpuset_mutex, nr_deadline_tasks can be updated in various contexts under different locks. As a result, data races may happen that cause incorrect value to be stored in nr_deadline_tasks leading to incorrect exit from dl_update_tasks_root_domain(). Fix that data race problem by making nr_deadline_tasks an atomic_t value. Fixes: 6c24849f5515 ("sched/cpuset: Keep track of SCHED_DEADLINE task in cpusets") Reported-by: Xia Fukun Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 58ec88efa4f8..3f3da468f058 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -174,7 +174,7 @@ struct cpuset { * number of SCHED_DEADLINE tasks attached to this cpuset, so that we * know when to rebuild associated root domain bandwidth information. */ - int nr_deadline_tasks; + atomic_t nr_deadline_tasks; int nr_migrate_dl_tasks; u64 sum_migrate_dl_bw; @@ -234,14 +234,14 @@ void inc_dl_tasks_cs(struct task_struct *p) { struct cpuset *cs = task_cs(p); - cs->nr_deadline_tasks++; + atomic_inc(&cs->nr_deadline_tasks); } void dec_dl_tasks_cs(struct task_struct *p) { struct cpuset *cs = task_cs(p); - cs->nr_deadline_tasks--; + atomic_dec(&cs->nr_deadline_tasks); } /* bits in struct cpuset flags field */ @@ -1071,7 +1071,7 @@ static void dl_update_tasks_root_domain(struct cpuset *cs) struct css_task_iter it; struct task_struct *task; - if (cs->nr_deadline_tasks == 0) + if (atomic_read(&cs->nr_deadline_tasks) == 0) return; css_task_iter_start(&cs->css, 0, &it); @@ -2721,8 +2721,8 @@ static void cpuset_attach(struct cgroup_taskset *tset) cs->old_mems_allowed = cpuset_attach_nodemask_to; if (cs->nr_migrate_dl_tasks) { - cs->nr_deadline_tasks += cs->nr_migrate_dl_tasks; - oldcs->nr_deadline_tasks -= cs->nr_migrate_dl_tasks; + atomic_add(cs->nr_migrate_dl_tasks, &cs->nr_deadline_tasks); + atomic_sub(cs->nr_migrate_dl_tasks, &oldcs->nr_deadline_tasks); reset_migrate_dl_data(cs); } -- 2.39.3