Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp381598rdg; Tue, 10 Oct 2023 13:07:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYr600phcg7Yprw82aquzoYPZo970H5WQsOxQqw0atAEwjvEOpuR7O2MbKnlC27IDPYRdB X-Received: by 2002:a17:902:c24d:b0:1bf:712:e4bd with SMTP id 13-20020a170902c24d00b001bf0712e4bdmr16096230plg.65.1696968427783; Tue, 10 Oct 2023 13:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696968427; cv=none; d=google.com; s=arc-20160816; b=mGyDetL74RESNpSpPhntW5Lkcgu0zDD83HcKuTLB2uJBq5krf2Abfqy6FfHZ4Y/X9F F9AjE+L1cWwWGOfAr0cKeE/Ll4VkdcPIQsmLe6tl5XjxFBGRNX+LLrFn5kr9YlfaFz6G UJ9Ki5YzcZbPxZ56Lr6pGQYNioRTuyggBMxr+60px8zP6UCv21/wg61y0rD1e3QKNlP9 nMqzTZUwQvvC7Vp1g+5tLos3mK/Lhr8Ker7Gdni+cpxaj6LgQJMOD/5BEzW6hS4Fdv4H 6YnngdHbtCHJJVPE7axl40LTE+zWroK4tGVSa78JEfUoqykN7ggO96S4gTq7DqvfWW5c a6Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=7Q1ao8fPZNUoCR6F1A4bfZDN3G9jXtzU1z74a4lCd3M=; fh=T3AfTD3QJ7vOtO4TlNhrGKB/GcHweyYl6IPxog5WHro=; b=fCb6U5n86qst+quBF3I21KOghobn3kpxTyVG+xWV3JqEodMWiQT5skgAv/LjLW12Aj jAWrmZPRYI0FA8gzBtUx3VMhayQ5KRAsm90A1W8Vvoe2l4o+Iprc0Ghd1JkcaUfF0U8F X4cUN5TMElw+Ox37OIxj4I9ifZEq+P1a7fu9L9X0Yh0bRzl5kY/bGcDv5q9gUpLLpM22 mQmEe1Z+akW3EWoh51rxjLE//21li2cSDHYdD+l6mwBpv5qI/O0O6hsro7WNGI0jbEqg MlhwXMrMrVfwbnov1y5MP96OTjZ+nfVyJ47VCEDCIJzrHTd0QMVURwTNAut2lnMmBrWZ VOnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=anM84us4; 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 d9-20020a170902cec900b001c9ad7b45easi2932847plg.526.2023.10.10.13.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:07:07 -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=anM84us4; 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 54B28807665A; Tue, 10 Oct 2023 13:06:50 -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 S1343861AbjJJUFu (ORCPT + 99 others); Tue, 10 Oct 2023 16:05:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234677AbjJJUEs (ORCPT ); Tue, 10 Oct 2023 16:04:48 -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 D5C0610F for ; Tue, 10 Oct 2023 13:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696968227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7Q1ao8fPZNUoCR6F1A4bfZDN3G9jXtzU1z74a4lCd3M=; b=anM84us4sY33rrPVCQ0CJ2l2ER8LZpKsZjfYh93mWi5pwZQiCz67ceIKs5KPL3GRgif1hb XONqki13j8bKbq+l7t4tbCpUCrWz/fYRWMjb0u6U7cm6vj31fgKu75vMbIZWtEjoL07BAT btFSq4fFUi7b+hS4YTYynXcHLrTg9ko= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-351-itfBRZr6PNm8GnfQyPjYJw-1; Tue, 10 Oct 2023 16:03:44 -0400 X-MC-Unique: itfBRZr6PNm8GnfQyPjYJw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 2B95B3801BCB; Tue, 10 Oct 2023 20:03:43 +0000 (UTC) Received: from [10.22.9.34] (unknown [10.22.9.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEB72492B04; Tue, 10 Oct 2023 20:03:41 +0000 (UTC) Message-ID: <31e06652-1dbd-e32f-3123-d17e178c5c27@redhat.com> Date: Tue, 10 Oct 2023 16:03:41 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH] cgroup/cpuset: Change nr_deadline_tasks to an atomic_t value Content-Language: en-US From: Waiman Long To: Juri Lelli Cc: Tejun Heo , Zefan Li , Johannes Weiner , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Qais Yousef , Hao Luo , Dietmar Eggemann , Steven Rostedt , Xia Fukun References: <20231009191515.3262292-1-longman@redhat.com> <6b769316-6434-5054-43f5-7933fc2bee01@redhat.com> In-Reply-To: <6b769316-6434-5054-43f5-7933fc2bee01@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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]); Tue, 10 Oct 2023 13:06:50 -0700 (PDT) On 10/10/23 15:44, Waiman Long wrote: > > On 10/10/23 01:34, Juri Lelli wrote: >> Hi, >> >> On 09/10/23 15:15, Waiman Long wrote: >>> 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 >> Could you please make an example of such data races? > > Since update to cs->nr_deadline_tasks is not protected by a single > lock, it is possible that multiple CPUs may try to modify it at the > same time.  It is possible that nr_deadline_tasks++ and > nr_deadline_tasks-- can be done in a single instruction like in x86 > and hence atomic. However, operation like "cs->nr_deadline_tasks += > cs->nr_migrate_dl_tasks" is likely a RMW operation and so is subjected > to racing. It is mostly theoretical, but probably not impossible. Sorry, even increment and decrement operators are not atomic. inc_dl_tasks_cs() is only called from switched_to_dl() in deadline.c which is protected by the rq_lock, but there are multiple rq's. dec_dl_tasks_cs() is called from switched_from_dl() in deadline.c and cgroup_exit() in cgroup.c. The later one is protected by css_set_lock. The other place where nr_deadline_tasks can be changed is in cpuset_attach() protected by cpuset_mutex. Cheers, Longman