From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3285E2459FE for ; Thu, 14 Aug 2025 03:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755142074; cv=none; b=l6oGwDbuJs4gSzTqnzE7BhxDYT8T4uRQ0kVf47nQLB8GWAFswCUlRspVVImX/fAbM3+AERDmaRdAHUH9113d9atjW1yiu0K/AQr6zyCsmDk2ixmAbknzRTsLC/K9BucJoLgQ56Gq1Q2eMHzM6TKPUGZhdV+Ni3iyz+kjsGvF+yY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755142074; c=relaxed/simple; bh=mdXgPJSAFLczjgL1pMydByQ+6QZayJAaU58a8KbOSSE=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=RdGVjqkWYWzMZDYTP1R9bIv71iTIhkQsvE1PX2Sja462eafqaIoosQUykffVYBaAmbK/sj2wjJCRUJ7oOKnLdHpPJI/K04fcc6HLgbipJRoc51i+6C0/FU5uWKrulKwRz+Fu7l0fi8iTdSS1gw/MTD0DmlYhtD0wf3+5eWyYcRQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DuN7P9aE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DuN7P9aE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755142071; 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=59+2AJKoXTwjmtAk2DQHHWr6SdM3QLz8zeRy+8bR4r4=; b=DuN7P9aEW+O8Lb0v0345+S8SmFfrBqVOFjC5Zug5UbE8kVjrClzM+HSL4NrkgzbU6g+Fo6 v6FFyaHBPypDTMTsogFS4p7g8f+4XkDbytDUrnlWNbI6aS2UCwyE8bCmrrgrI7z9rnuaH+ T2EMQkiHJOsET5Jtk2BD9optSX3tTMc= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-552-gHROx0-6PPC3rmLMOLO_ug-1; Wed, 13 Aug 2025 23:27:49 -0400 X-MC-Unique: gHROx0-6PPC3rmLMOLO_ug-1 X-Mimecast-MFC-AGG-ID: gHROx0-6PPC3rmLMOLO_ug_1755142069 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4b109bccebaso13778251cf.2 for ; Wed, 13 Aug 2025 20:27:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755142069; x=1755746869; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=59+2AJKoXTwjmtAk2DQHHWr6SdM3QLz8zeRy+8bR4r4=; b=dc2fF0g9FLG3H5ZQbwxVtUP0It80YHXffgCQyyBEl3J+sgrSUp6CjfoURWM2mDidW0 KtKDIwbs0uk2ZdYt11xidurVrl9eEVtXIMokWZGtNmm5oiPF9zL5bbD2gzZYWzBP4HJt W+1uXQ0LKASAprouqCq+24cBBRzncxwPx5OxFk2nYzKyg4V2uZC1BlJ2BSC6AsaeCqxO xUZFj+Fw90P2rP0+13JTvpwtklQrUEOvZhdIicYtZfugP6n+ojU5hK+Elu+qqwAbjWXm uP8RHESa5BGp2UcGe/J0DVqp8aiwd6dEnTm/+VtG8t9cvbBWHG4YSmQD+vltpzlp5+3h sCkw== X-Gm-Message-State: AOJu0YznQeay9zsd+yqhfz7uCB6cGZKioND/A1gZhO0Nda2u8yXpDd/o 9uMogpyDbE0UAxP3SLTmlK7+BL03trl1IFBh7/jfRs2G/xZzt/cBQxrLYrvAQJz37aZzmzqVJhD pO1pQhSC0QD9xVOkw0sOqAKcTjMAMaP2HG0pr5qw17OSPS29NPmBc/ipBO+E= X-Gm-Gg: ASbGncsTlcNtKtwVTD2WGI++IxfyWrSeEkfLvCXZTzInl+aVZuX+1uyyqKnLemXIhTt M6PdDAWne38ZqVWqoaDuPoRmD9z7uWVJVbbCI6MrmV/fpGvydi+xZK/LRx5/HKVYsZ2ndJaMxtc rcVVKQ1c/5BSW930juq02kitbB9LJ3VkUJ7iKEs/rgk36hLqRcB+Y63GmZFO+ZeyYECXGI41DQA LbG1+BAxwTcF6k5Kvb5+G3WYIUaHkFuLL3L+JACsyUvVx87KBmc5oIWBf7CoZ3dQjCmPQKRp2BE ZtmGCYCDeMxtDb9z+lOlRSxtSQ0sEoPTzgc680hHolS5acIkIbgdcLpBDMsYWNXb2qM8+n+rips Atmqd5pyWug== X-Received: by 2002:a05:622a:149:b0:4b0:da5c:e250 with SMTP id d75a77b69052e-4b10c5fa96fmr13493731cf.59.1755142069102; Wed, 13 Aug 2025 20:27:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESk1/DttNu6iz8CxDSplgxOB5v0RkzObYtmeSlNLDBymBrq3Udoku8HCQ3q7jolK4rRJ50Aw== X-Received: by 2002:a05:622a:149:b0:4b0:da5c:e250 with SMTP id d75a77b69052e-4b10c5fa96fmr13493581cf.59.1755142068677; Wed, 13 Aug 2025 20:27:48 -0700 (PDT) Received: from ?IPV6:2601:188:c180:4250:ecbe:130d:668d:951d? ([2601:188:c180:4250:ecbe:130d:668d:951d]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4afb76dcadfsm159725941cf.19.2025.08.13.20.27.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Aug 2025 20:27:48 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: Date: Wed, 13 Aug 2025 23:27:46 -0400 Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [-next v2 4/4] cpuset: add helpers for cpus read and cpuset_mutex locks To: Waiman Long , Chen Ridong , tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, lujialin4@huawei.com, chenridong@huawei.com, christophe.jaillet@wanadoo.fr References: <20250813082904.1091651-1-chenridong@huaweicloud.com> <20250813082904.1091651-5-chenridong@huaweicloud.com> <750ac0bd-42f9-47fa-8274-0ff4e4a7fa3d@huaweicloud.com> <93e37ccf-8ac8-40f5-840f-2f221f58131e@redhat.com> Content-Language: en-US In-Reply-To: <93e37ccf-8ac8-40f5-840f-2f221f58131e@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/13/25 11:13 PM, Waiman Long wrote: > On 8/13/25 8:44 PM, Chen Ridong wrote: >> >> On 2025/8/14 4:09, Waiman Long wrote: >>> On 8/13/25 4:29 AM, Chen Ridong wrote: >>>> From: Chen Ridong >>>> >>>> cpuset: add helpers for cpus_read_lock and cpuset_mutex >>>> >>>> Replace repetitive locking patterns with new helpers: >>>> - cpus_read_cpuset_lock() >>>> - cpus_read_cpuset_unlock() >>>> >>>> This makes the code cleaner and ensures consistent lock ordering. >>>> >>>> Signed-off-by: Chen Ridong >>>> --- >>>>    kernel/cgroup/cpuset-internal.h |  2 ++ >>>>    kernel/cgroup/cpuset-v1.c       | 12 +++------ >>>>    kernel/cgroup/cpuset.c          | 48 >>>> +++++++++++++++------------------ >>>>    3 files changed, 28 insertions(+), 34 deletions(-) >>>> >>>> diff --git a/kernel/cgroup/cpuset-internal.h >>>> b/kernel/cgroup/cpuset-internal.h >>>> index 75b3aef39231..6fb00c96044d 100644 >>>> --- a/kernel/cgroup/cpuset-internal.h >>>> +++ b/kernel/cgroup/cpuset-internal.h >>>> @@ -276,6 +276,8 @@ int cpuset_update_flag(cpuset_flagbits_t bit, >>>> struct cpuset *cs, int turning_on) >>>>    ssize_t cpuset_write_resmask(struct kernfs_open_file *of, >>>>                        char *buf, size_t nbytes, loff_t off); >>>>    int cpuset_common_seq_show(struct seq_file *sf, void *v); >>>> +void cpus_read_cpuset_lock(void); >>>> +void cpus_read_cpuset_unlock(void); >>> The names are not intuitive. I would prefer just extend the >>> cpuset_lock/unlock to include >>> cpus_read_lock/unlock and we use cpuset_lock/unlock consistently in >>> the cpuset code. Also, there is >>> now no external user of cpuset_lock/unlock, we may as well remove >>> them from include/linux/cpuset.h. >>> >>> Cheers, >>> Longman >> I like the idea and have considered it. >> However, I noticed that cpuset_locked is being used in >> __sched_setscheduler. > > Right, I overloooked the cpuset_lock() call in kernel/sched/syscall.c. > So we can't remove it from include/linux/cpuset.h. > > This call is invoked to ensure cpusets information is stable. However, > it doesn't hurt if the cpus_read_lock() is also acquired as a result. > Alternatively, we can use a name like cpuset_full_lock() to include > cpus_read_lock(). I have a correction. According to commit d74b27d63a8b ("cgroup/cpuset: Change cpuset_rwsem and hotplug lock order") , sched_scheduler() can be called while holding cpus_hotplug_lock. So we should keep cpuset_lock() as it is. Cheers, Longman