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 7339723B63E for ; Mon, 24 Nov 2025 02:24:24 +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=1763951066; cv=none; b=LUg8MxprL3Q3eEnDFBCs1i7E5joMw0qe7qHquw6sahCwk53xirmLmhR5fC8aEzEt8EsPS4rvpbGp0YgBvFgUtSOogOILbaNWCghEUOs7eiyRm5i2mOxvTrOVI0bj2LB7DJ766qV1wvZeGg2yzWoObjR9vAiaXueWNAWG22wXF6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763951066; c=relaxed/simple; bh=900Sfp1hzF5CcbuAK4GiePcM90Q5so7iZULEH9cUa+0=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=LQ2kUzOpBP2s5nbXtC7DHZdW71IfJruYq80KseYxxjMtTnPd8ghVVOzOiB7Y7gpdK6eD2D4aE2dlqkHxwWanivlCghTReaCiJJGJS0yljF5XVll1UayoqrolpXsnkW+3oIxyzgaHiqRrT17QWVbrFI3Dz9CZFUivzcGIXnlghHg= 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=Rzmqj4vR; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=iQCIMDzM; 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="Rzmqj4vR"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="iQCIMDzM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763951063; 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=WcR/nkcfm7wSPXlaMxzmRamYfx6Iq5pdz/pa+StL5CQ=; b=Rzmqj4vRdJaK99nTUTv6rn2/kp0L7QuYvc2lKldmnUlszSToZZ1ZtRUO8LEtnDdvXTwsPN LUEo6dAAfnC4T53ZH2IvSZ1mdc3lRHIpfj/mYmdkRqzXF3GS0b5+0l1/58ZAGolLCBTZpA RHiQqEzfnz8NAPetOf7Sf+NeV0jXUDc= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-tU7hmgKSOMetruj9d0DgEw-1; Sun, 23 Nov 2025 21:24:21 -0500 X-MC-Unique: tU7hmgKSOMetruj9d0DgEw-1 X-Mimecast-MFC-AGG-ID: tU7hmgKSOMetruj9d0DgEw_1763951061 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-882529130acso111224056d6.2 for ; Sun, 23 Nov 2025 18:24:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763951061; x=1764555861; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:from:to :cc:subject:date:message-id:reply-to; bh=WcR/nkcfm7wSPXlaMxzmRamYfx6Iq5pdz/pa+StL5CQ=; b=iQCIMDzMAVTGxG5O9KUNhV4utG4ntM6lSgDJsikQGb1UgMNOQd37Nj9dQFUSEBnDEE QxWsdngKbs8K/8w+e1ZoxFboES/9HGGOuwYX2lbuhL9WCaW6Lm8KKNKw2l24txehTSOg wU3NsxNC+9vbR9pdaPNmW/usZZ0iFuRKnaEEQcJLMM4KvPLymWpT35NLe9tgae5l3Hi0 /JKN8CONm5GtdTaoiRF1d3kkRrORihLzr/xGGk+ZMftcI2NiqGytFbdMxgsnhDWTe/Nx QarPDZWOhzmRnbfdgc8mJoAEwv6D1JTnR55WPC5PP+QHmYrLZstWJirRpB4bti5MpjVd ROWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763951061; x=1764555861; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WcR/nkcfm7wSPXlaMxzmRamYfx6Iq5pdz/pa+StL5CQ=; b=ixqwzYMvaVX//UTWhovey5iGqA3dbs8c08kCKeQKrvRs8Uhp/XiwGrMnL5FQvP46DB +GMPzGPlHSpd7Wd5bGOZ/+HZQhH39e58XgAA4Z7bKgI5SJz77xCKKVBn6vEb+CwHWri+ djRa8bVokfswM6uNu86KBVO3ujasIoTkJml4YKoJ9Ea5dOI77Im+yqYaD/jlB4rlJmNL 60wypg0WTWkOjMH9dPoip8MxoD9hwrosbWarR0kkLoalbIl2n9YehHoXVnuIR3Uq1GBD 4CFcyy5IZbcsenfEp9cHWftpsqzwKSvia41Fp8/g3blfHL3PTJeE/tusN+qSwLI0jPVL nklQ== X-Gm-Message-State: AOJu0Yzrc0Jdzs4bSbKjs6Lunpv3qbODUs+2Qj0dFCFA61HlsfHTh4hi VxcfW1qwqid9A83SS7m/CI3sIqL5iZ6bxfRM8LJipLc9txf7/997s2xCGEC09vTxFDsxVqCeN/T /qthcndw0brfQOCfe+gmToy0qkcMibpSenEmoFpXxoHLiUZzjDlJ9TUuFvjKhl4vNgQ== X-Gm-Gg: ASbGncuM/s3MXbU/dBUKKdkgGURl37lGPC/ltQO8teAXU30XXVb3IKjXZNgNcVuUFy0 7cuSYSdGejZsUCcUHxIYV4XUCz2ZLh8sFrSmvV9x3SrwP6QP8Eu5pd3wSVm/k8IHwGxsJUK3BSQ PYcphgF8ieG+ZPUV7cd8s1WfP+fzhD/U/gerYrTNtrgHxeJe/RdkumgIDZNgXTP4IJCjbNVH6Iy SM9EPSIAR6000fGJXnNhSgORyxDjbRUah8YZ0QiWco+LgatMNS2aP/vkniixr68UZDyCn0q6is7 zu4EtZ2OKPYRRFvYqHGv3vVOwGu7qNy5vtc8kI1Sx2D2ZGSmSRUPngs3qUhDnGPNc+u+lvSbbL3 U08lKJpYP/CSA3NiJNI5gdxYZyQcbgtV1jSF1eQWjL9xUhD5a6/5uJzmA X-Received: by 2002:a05:6214:3f8e:b0:884:5bc7:6590 with SMTP id 6a1803df08f44-8847c50f9aemr140390616d6.43.1763951061315; Sun, 23 Nov 2025 18:24:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGI1zJdrML7Zjg5pst6G+o5fDE+e9zB8X/Rn75a/ex3F0dm7Zb8njamQFEjliPqCXwKIg+fRQ== X-Received: by 2002:a05:6214:3f8e:b0:884:5bc7:6590 with SMTP id 6a1803df08f44-8847c50f9aemr140390386d6.43.1763951060891; Sun, 23 Nov 2025 18:24:20 -0800 (PST) Received: from ?IPV6:2601:188:c102:b180:1f8b:71d0:77b1:1f6e? ([2601:188:c102:b180:1f8b:71d0:77b1:1f6e]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8846e47115bsm90484536d6.21.2025.11.23.18.24.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Nov 2025 18:24:20 -0800 (PST) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: <0f57e7df-c45b-4c25-856b-4dd240f8d717@redhat.com> Date: Sun, 23 Nov 2025 21:24:18 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv7 2/2] sched/deadline: Walk up cpuset hierarchy to decide root domain when hot-unplug To: Pingfan Liu , Juri Lelli Cc: linux-kernel@vger.kernel.org, Chen Ridong , Peter Zijlstra , Pierre Gondois , Ingo Molnar , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Tejun Heo , Johannes Weiner , mkoutny@suse.com References: <20251119095525.12019-1-piliu@redhat.com> <20251119095525.12019-3-piliu@redhat.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/23/25 8:45 PM, Pingfan Liu wrote: > On Fri, Nov 21, 2025 at 02:05:31PM +0100, Juri Lelli wrote: >> Hi! >> >> On 19/11/25 17:55, Pingfan Liu wrote: >> >> ... >> >>> +/* Access rule: must be called on local CPU with preemption disabled */ >>> static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl); >> ... >> >>> +/* The caller should hold cpuset_mutex */ >> Maybe we can add a lockdep explicit check? >> > Currently, all cpuset locks are encapsulated in > kernel/cgroup/cpuset-internal.h. I'm not sure if it's appropriate to > expose them. If exposing them is acceptable, > cpuset_callback_lock_irq()/cpuset_callback_unlock_irq() would be > preferable to cpuset_mutex assertion. > > @Waiman, @Ridong, could you kindly share your opinion? The cpuset_cpus_allowed_locked() already has a "lockdep_assert_held(&cpuset_mutex)"  call to make sure that cpuset_mutex is held, or a warning will be printed by the debug kernel. So a check is there, it is just not in the deadline.c code. The dl_add_task_root_domain() is called indirectly from dl_rebuild_rd_accounting() in cpuset.c which does have an assertion on cpuset_mutex. There is an external visible cpuset_lock/unlock() to acquire and release the cpuset_mutex. However, there is no public API to assert that cpuset_mutex is held. There is another set of patch series that is going to add that in the near future. At this point, I don't think we need to have such an API yet. I will suggest adding comment to cpuset_cpus_allowed_locked() that it will warn if cpuset_mutex isn't held. Providing a cpuset_callback_{lock|unlock}_irq() helpers may not be helpful because we are back to the problem that callback_lock isn't a raw_spinlock_t. Cheers, Longman > >>> void dl_add_task_root_domain(struct task_struct *p) >>> { >>> struct rq_flags rf; >>> struct rq *rq; >>> struct dl_bw *dl_b; >>> + unsigned int cpu; >>> + struct cpumask *msk = this_cpu_cpumask_var_ptr(local_cpu_mask_dl); >> Can this corrupt local_cpu_mask_dl? >> >> Without preemption being disabled, the following race can occur: >> >> 1. Thread calls dl_add_task_root_domain() on CPU 0 >> 2. Gets pointer to CPU 0's local_cpu_mask_dl >> 3. Thread is preempted and migrated to CPU 1 >> 4. Thread continues using CPU 0's local_cpu_mask_dl >> 5. Meanwhile, the scheduler on CPU 0 calls find_later_rq() which also >> uses local_cpu_mask_dl (with preemption properly disabled) >> 6. Both contexts now corrupt the same per-CPU buffer concurrently >> > Oh, that is definitely an issue. Thanks for pointing it out. > >>> >>> raw_spin_lock_irqsave(&p->pi_lock, rf.flags); >> It's safe to get the pointer after this point. >> > Yes. >>> if (!dl_task(p) || dl_entity_is_special(&p->dl)) { >>> @@ -2919,16 +2952,25 @@ void dl_add_task_root_domain(struct task_struct *p) >>> return; >>> } >>> >>> - rq = __task_rq_lock(p, &rf); >>> - >>> + /* >>> + * Get an active rq, whose rq->rd traces the correct root >>> + * domain. >>> + * Ideally this would be under cpuset reader lock until rq->rd is >>> + * fetched. However, sleepable locks cannot nest inside pi_lock, so we >>> + * rely on the caller of dl_add_task_root_domain() holds 'cpuset_mutex' >>> + * to guarantee the CPU stays in the cpuset. >>> + */ >>> + dl_get_task_effective_cpus(p, msk); >>> + cpu = cpumask_first_and(cpu_active_mask, msk); >>> + BUG_ON(cpu >= nr_cpu_ids); >>> + rq = cpu_rq(cpu); >>> dl_b = &rq->rd->dl_bw; >>> - raw_spin_lock(&dl_b->lock); >>> + /* End of fetching rd */ >> Not sure we need this comment above. :) >> > OK, I can remove them to keep the code neat. > > > Thanks, > > Pingfan >