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 541148828 for ; Sun, 26 Jan 2025 02:21:21 +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=1737858084; cv=none; b=G62sRvp4P/LpN07udo8FzuhfUohbxdmbcBlrYNWGIlv3I5QgGik2hK1GZGR0b1nm9mC9BHCvaZZBz4azFChp4RVamNGb2A4Orvt0K9VwH337KTKd1nAcIJ9mH1kJdtZSbS3OMc6eQFlyi3WEJwfCpEGQjnqCShQ4+nXOSRCJNG4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737858084; c=relaxed/simple; bh=WUA1umUxWR1N9B8sZNOQD2vXASza+rQ0i1aDrEP77aU=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=U+0SKEzDmoYiNxupjzsjPKVl8gTsYdnm96L2vH9K57dM1D3bVuhOWfD4QIQ3InBNGt30N0inpKaHQ0BH7+rY2Dv9YXYJ+zJf8A2StIzO9NdPkMTHQ9ALH6ackOqZFcykbnNdFJfoKbUeg8mKez0SmmPoiFZyxRdEHrGel3J4WK4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=bk8u9Tmh; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="bk8u9Tmh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737858081; 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=U3c4XLByKR9lDoaHJoYmVfJ+eboI5gBxxzhfHNFwqKs=; b=bk8u9TmhyLcHLtW14UJX158RxLvs+eC+CNvxIxf//piKHRCOnwWdZzEsP9dVudZZpNKl+3 fYpYaMvJPLwiGFBBgzo0gf3BMpaGv58nzPlVro7GMI37BwdkqkbU/Ys7TZynaM7ZY1IGSV /qWuGq84Pg9f78WUUZKInKsd7/c1fys= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-IruWAeELOqCeUC_BdYH-Eg-1; Sat, 25 Jan 2025 21:21:19 -0500 X-MC-Unique: IruWAeELOqCeUC_BdYH-Eg-1 X-Mimecast-MFC-AGG-ID: IruWAeELOqCeUC_BdYH-Eg Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6d88833dffcso52650966d6.0 for ; Sat, 25 Jan 2025 18:21:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737858079; x=1738462879; 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=U3c4XLByKR9lDoaHJoYmVfJ+eboI5gBxxzhfHNFwqKs=; b=uDPmH6KieELLz3GLw/O2Tt0M9COdgFIE83ZFR3psPniGFb8PzxENmAaSVPX5ERFDyU gFbzp8617x7ILU3jxaHaVcvhc3fuNz+xweSCofW44YX4UvyVgwB7/cMVIsLTNfFboYQe 50ka3ncaJA7QEtGa0Xiy521sWzt7iTSlaLWB/HUTT9a9ts4X3Zm3Cid/BN5ToOHJ5RVC RQFtXvO5EB1w8a+JLfV46AUiJePESO7UL+UXSAveHlwM6ux5ZjKlp4ShZWHlVqhUu7HK fKQm9fzi+7acXywb8F2smy0O/H+1CJelcsvaL3XFUSzeI1fQIorpUDDzOILItzP9Goi6 NxZg== X-Gm-Message-State: AOJu0YxGmc3gkqferxzXhBzjfAojkEbvryUhW3fw54OFAfn58kzrshSR vbtlJ/DdiqAjjcZob8RThLNDMSZmXi6lo9alGSr7xcPUE0urbvGQ5aTVWSfzXQMS4cZw4gCD/qn 20n0IzaLJ5IZsf31PbIAubXBCvxX6X4ZiuIeTrdPymeuEMgHmEiKBfg2OTmBMUA== X-Gm-Gg: ASbGncsg7d0ZluyjCZlQAZ15yVPkpJ1EOY6QldeYZz1a0Kw78E58w6o9E/rjuB3G7Ln SYcATXEevIOcD3v1v1NIK7gPF5NPWxMfkS3IHcw19+4MiH/UbRr9Qh/bVONpRocf/KR+OA2ojCK nUYxdFB4WOG04PCrXgSR4i3xuowEFm5EZU06LrmfPHJnw+Z9JHfFnpikEtJH0twZV3pud7kvveR A0/c/z0SzvtZyLNFTfh2JccPsqFcH6l5MVZvKyIln82LKhgmxfc+Qg2CkFIdFQu9nZ8LoVRCZ+P ZeRGB1417ueje5UyQ8BY4N4smV5Nr6grvUKeM8mjKHCG X-Received: by 2002:a05:6214:e4f:b0:6d8:9074:a823 with SMTP id 6a1803df08f44-6e1b228ddc7mr452888406d6.45.1737858079036; Sat, 25 Jan 2025 18:21:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IHu1egRjifzphXMDF9Wig2qxJH5rN+Dr13lfTXTljd0hIt+qxAoZHddCGCXbTkWY6iFeY5xhw== X-Received: by 2002:a05:6214:e4f:b0:6d8:9074:a823 with SMTP id 6a1803df08f44-6e1b228ddc7mr452888236d6.45.1737858078720; Sat, 25 Jan 2025 18:21:18 -0800 (PST) Received: from [172.20.1.27] (syn-024-213-244-062.biz.spectrum.com. [24.213.244.62]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e2057a8df4sm22284356d6.69.2025.01.25.18.21.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 25 Jan 2025 18:21:17 -0800 (PST) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: Date: Sat, 25 Jan 2025 21:21:15 -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: [PATCH v2] locking/semaphore: Use wake_q to wake up processes outside lock critical section To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng Cc: linux-kernel@vger.kernel.org References: <20250122191742.3025187-1-longman@redhat.com> Content-Language: en-US In-Reply-To: <20250122191742.3025187-1-longman@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/22/25 2:17 PM, Waiman Long wrote: > A circular lock dependency splat has been seen involving down_trylock(). > > [ 4011.795602] ====================================================== > [ 4011.795603] WARNING: possible circular locking dependency detected > [ 4011.795607] 6.12.0-41.el10.s390x+debug > [ 4011.795612] ------------------------------------------------------ > [ 4011.795613] dd/32479 is trying to acquire lock: > [ 4011.795617] 0015a20accd0d4f8 ((console_sem).lock){-.-.}-{2:2}, at: down_trylock+0x26/0x90 > [ 4011.795636] > [ 4011.795636] but task is already holding lock: > [ 4011.795637] 000000017e461698 (&zone->lock){-.-.}-{2:2}, at: rmqueue_bulk+0xac/0x8f0 > > the existing dependency chain (in reverse order) is: > -> #4 (&zone->lock){-.-.}-{2:2}: > -> #3 (hrtimer_bases.lock){-.-.}-{2:2}: > -> #2 (&rq->__lock){-.-.}-{2:2}: > -> #1 (&p->pi_lock){-.-.}-{2:2}: > -> #0 ((console_sem).lock){-.-.}-{2:2}: > > The console_sem -> pi_lock dependency is due to calling try_to_wake_up() > while holding the console.sem raw_spinlock. This dependency can be broken > by using wake_q to do the wakeup instead of calling try_to_wake_up() > under the console_sem lock. This will also make the semaphore's > raw_spinlock become a terminal lock without taking any further locks > underneath it. > > The hrtimer_bases.lock -> zone->lock dependency is actually another > instance of raw_spinlock to spinlock nesting problem. > > [ 4011.795646] -> #4 (&zone->lock){-.-.}-{2:2}: > [ 4011.795650] __lock_acquire+0xe86/0x1cc0 > [ 4011.795655] lock_acquire.part.0+0x258/0x630 > [ 4011.795657] lock_acquire+0xb8/0xe0 > [ 4011.795659] _raw_spin_lock_irqsave+0xb4/0x120 > [ 4011.795663] rmqueue_bulk+0xac/0x8f0 > [ 4011.795665] __rmqueue_pcplist+0x580/0x830 > [ 4011.795667] rmqueue_pcplist+0xfc/0x470 > [ 4011.795669] rmqueue.isra.0+0xdec/0x11b0 > [ 4011.795671] get_page_from_freelist+0x2ee/0xeb0 > [ 4011.795673] __alloc_pages_noprof+0x2c2/0x520 > [ 4011.795676] alloc_pages_mpol_noprof+0x1fc/0x4d0 > [ 4011.795681] alloc_pages_noprof+0x8c/0xe0 > [ 4011.795684] allocate_slab+0x320/0x460 > [ 4011.795686] ___slab_alloc+0xa58/0x12b0 > [ 4011.795688] __slab_alloc.isra.0+0x42/0x60 > [ 4011.795690] kmem_cache_alloc_noprof+0x304/0x350 > [ 4011.795692] fill_pool+0xf6/0x450 > [ 4011.795697] debug_object_activate+0xfe/0x360 > [ 4011.795700] enqueue_hrtimer+0x34/0x190 > [ 4011.795703] __run_hrtimer+0x3c8/0x4c0 > [ 4011.795705] __hrtimer_run_queues+0x1b2/0x260 > [ 4011.795707] hrtimer_interrupt+0x316/0x760 > [ 4011.795709] do_IRQ+0x9a/0xe0 > [ 4011.795712] do_irq_async+0xf6/0x160 > > We will need to make some changes in debugobjects and/or hrtimer code > to address this problem and break the circular dependency. I check the v6.12 debugobjects code again and I saw static void debug_objects_fill_pool(void) {         /*          * On RT enabled kernels the pool refill must happen in preemptible          * context -- for !RT kernels we rely on the fact that spinlock_t and          * raw_spinlock_t are basically the same type and this lock-type          * inversion works just fine.          */         if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) {                 /*                  * Annotate away the spinlock_t inside raw_spinlock_t warning                  * by temporarily raising the wait-type to WAIT_SLEEP, matching                  * the preemptible() condition above.                  */                 static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_SLEEP);                 lock_map_acquire_try(&fill_pool_map);                 fill_pool();                 lock_map_release(&fill_pool_map);         } } It looks like it explicitly allows raw_spinlock to spinlock nesting for non-PREEMPT_RT kernel and disable the lockdep nested locking check. So the hrtimer_bases.lock -> zone->lock dependency is legit and expected. I will need to update my patch description again. Cheers, Longman