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.129.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 17D4C1DF754 for ; Mon, 6 Jan 2025 19:14:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190846; cv=none; b=HrqiUe5/BTtj9cdi6jg+YOqWHdW1CTveAJCJUHonTW7JUmApg0hXkg9IXyRr8TaX00WGrYxxBp3u5Nl4eDuYVBmJGuRtHc+S3sAx7RcFRjl72mb0Mb41qNwaD+a/CvGTuBZYb+2OLlwb395bK1DbXTSzdTJmjaPZp9CZwpMMCaM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190846; c=relaxed/simple; bh=rb7IzNnPb33vb6OF+xVIe3rRRRWnJr851l/gpdvIsJM=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=RDNEqbL6hjHAbJE8rGmyYL1Uno3xQuVeHoJRz+an6580wFuIwAFwGX33cyIMAxeU6rmkWfnXq5cvO28QAvvymvqf1+k7/RFDglp4zXGXGgxCVEjeGOmPDz1f2rN6217xX8oJbWZkahzcjKLbeICbkOqNbUdc69V+sBH01i7vSYQ= 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=KgfiR5hW; arc=none smtp.client-ip=170.10.129.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="KgfiR5hW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736190844; 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=0BFdn8OKI48tlD9a9ioulqWfSY1ZiomBkFHF/k7GC7w=; b=KgfiR5hWj3DHO6ovpUmGMZKxOHTQmMfPhrSiR2bFbG4GMKhuTOhIZ9fLNgChqMNjjsi+2K RzrYqJ1tX6ehi9YjMyLgJ8HFIdACEoICXPDtv5gGhIbNRFrHg1y8FlSv0M6d6oXwQSJsYG TUUgtQtNzfp2Hf9UyLCCgnZdsLRyuoo= 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-393-INw8mT_aP1yoDZYyD3U-eg-1; Mon, 06 Jan 2025 14:14:00 -0500 X-MC-Unique: INw8mT_aP1yoDZYyD3U-eg-1 X-Mimecast-MFC-AGG-ID: INw8mT_aP1yoDZYyD3U-eg Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6d8eb5ea994so171159786d6.1 for ; Mon, 06 Jan 2025 11:14:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736190840; x=1736795640; 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=0BFdn8OKI48tlD9a9ioulqWfSY1ZiomBkFHF/k7GC7w=; b=ksb1IyAT28uv9HPxBfPqVCA3cq2JwTN/1sKD2tlH6uGgI8SBiVTNfzXt3MUm8S2LJr r59vQlfNHayM5auEvgMHpn0VlcdHk4gesvGM7rseEvxTMjYNlYi2qk9v3S2WbKiw4M8f TbUz0IsgVgOxSsKDQ6HeqiChfVQPzN37ze0Ab5Yau8PeqUhPmSkki+U8IyP3ctZq+6LU bZfoyinGry6UlZwzU0mMmocJa4VK8wtVweL0CzprR40/g8IOmZCrWU5JEFsSnuxiH5FX QYmo+3TQVstcyOyOGKr4bgglGrUUWCvUKwXe75OVNR2HHCfi4XK+N10tl+0rU/y9KBsh u2Yw== X-Gm-Message-State: AOJu0YxipJOD1ThtVfhD2kHrnhJ1vzyW/ZINdYId5IN+2D9O6v2BVBoh dg3zQfqlDVzX/+DK990JCIqNo6xYjyzvGVMe/jtpnHxep4vpA6REQubk/wLWVrBc6tjN3hc1i8i hy7BfA4dbMLRgY3hDBabeBeNfbDrIwxux77UP9BWc6Pq35FHvZM6Wf79DBSK4AA== X-Gm-Gg: ASbGncsUlRVSti7shQs9TOJNZzdjfQ5mWgoyL6tcIzNufHpApdzRd8v2i7xVQT8+ROg kSxwwWHeJeAuR6IaOIBl7ouSg484hFd4JdtrGIVdvnjd3u+zYXwPisKOGAHZyFdMD+oBjE9toPN HNZvGCJln0Y8KBrVyvFADZc62BzUXmR8t+wuxBvfQf+Mp01hFbdy9vs5rQi/ksGABMm4DdTmJ/U hV2iC244Milkg4ZKap42z0ljNzc2Wc/Y+MHpPQompfYjHYLJM3DdhShDT/Y1vpXnVFypC+zxw0e JJEQP27Izgsmiw7dWAzK+GCo X-Received: by 2002:a05:6214:20aa:b0:6d8:963e:b4d1 with SMTP id 6a1803df08f44-6dd2332d670mr1066291756d6.18.1736190840401; Mon, 06 Jan 2025 11:14:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHV8JVMbJEpqD470qQ9WMIt7T0Gj8y+WTHTQwZNt6c2ki8eC2y4vOMb2ESemoIJsUl1GCoOwQ== X-Received: by 2002:a05:6214:20aa:b0:6d8:963e:b4d1 with SMTP id 6a1803df08f44-6dd2332d670mr1066291396d6.18.1736190840047; Mon, 06 Jan 2025 11:14:00 -0800 (PST) Received: from ?IPV6:2601:188:ca00:a00:f844:fad5:7984:7bd7? ([2601:188:ca00:a00:f844:fad5:7984:7bd7]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd181d52c2sm172706506d6.113.2025.01.06.11.13.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Jan 2025 11:13:59 -0800 (PST) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: Date: Mon, 6 Jan 2025 14:13:57 -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] lockdep: Fix wait context check on softirq for PREEMPT_RT To: Ryo Takakura , bigeasy@linutronix.de, boqun.feng@gmail.com, clrkwllms@kernel.org, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, tglx@linutronix.de, will@kernel.org Cc: linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev References: <20241227040824.83626-1-ryotkkr98@gmail.com> Content-Language: en-US In-Reply-To: <20241227040824.83626-1-ryotkkr98@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/26/24 11:08 PM, Ryo Takakura wrote: > Since commit 0c1d7a2c2d32 ("lockdep: Remove softirq accounting on > PREEMPT_RT."), the wait context test for mutex usage within > "in softirq context" fails as it references @softirq_context. > > [ 0.184549] | wait context tests | > [ 0.184549] -------------------------------------------------------------------------- > [ 0.184549] | rcu | raw | spin |mutex | > [ 0.184549] -------------------------------------------------------------------------- > [ 0.184550] in hardirq context: ok | ok | ok | ok | > [ 0.185083] in hardirq context (not threaded): ok | ok | ok | ok | > [ 0.185606] in softirq context: ok | ok | ok |FAILED| > > As a fix, add lockdep map for BH disabled section. This fixes the > issue by letting us catch cases when local_bh_disable() gets called > with preemption disabled where local_lock doesn't get acquired. > In the case of "in softirq context" selftest, local_bh_disable() was > being called with preemption disable as it's early in the boot. > > Signed-off-by: Ryo Takakura > --- > > Hi! > > This version fixes the issue by adding lockdep map for BH disabled > section. Thanks Boqun for the suggestion! > > Changes since v1: > https://lore.kernel.org/lkml/20241202012017.14910-1-ryotkkr98@gmail.com/ > > - Fix the issue by adding lockdep map for BH disabled section. > This let us catch mutex usage within "in softirq context" selftest > as it disables BH section. > > Also, may I add Boqun as tag? > > --- > include/linux/bottom_half.h | 8 ++++++++ > kernel/softirq.c | 12 ++++++++++++ > 2 files changed, 20 insertions(+) > > diff --git a/include/linux/bottom_half.h b/include/linux/bottom_half.h > index fc53e0ad5..f77dc746c 100644 > --- a/include/linux/bottom_half.h > +++ b/include/linux/bottom_half.h > @@ -4,6 +4,7 @@ > > #include > #include > +#include > > #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_TRACE_IRQFLAGS) > extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt); > @@ -15,8 +16,13 @@ static __always_inline void __local_bh_disable_ip(unsigned long ip, unsigned int > } > #endif > > +#ifdef CONFIG_LOCKDEP > +extern struct lockdep_map bh_lock_map; > +#endif > + > static inline void local_bh_disable(void) > { > + lock_map_acquire_read(&bh_lock_map); > __local_bh_disable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET); > } > > @@ -25,11 +31,13 @@ extern void __local_bh_enable_ip(unsigned long ip, unsigned int cnt); > > static inline void local_bh_enable_ip(unsigned long ip) > { > + lock_map_release(&bh_lock_map); > __local_bh_enable_ip(ip, SOFTIRQ_DISABLE_OFFSET); > } > > static inline void local_bh_enable(void) > { > + lock_map_release(&bh_lock_map); > __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET); > } > > diff --git a/kernel/softirq.c b/kernel/softirq.c > index 4dae6ac2e..a8211ba9a 100644 > --- a/kernel/softirq.c > +++ b/kernel/softirq.c > @@ -1073,3 +1073,15 @@ unsigned int __weak arch_dynirq_lower_bound(unsigned int from) > { > return from; > } > + > +#ifdef CONFIG_LOCKDEP > +static struct lock_class_key bh_lock_key; > +struct lockdep_map bh_lock_map = { > + .name = "local_bh", > + .key = &bh_lock_key, > + .wait_type_outer = LD_WAIT_FREE, > + .wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. */ > + .lock_type = LD_LOCK_PERCPU, > +}; > +EXPORT_SYMBOL_GPL(bh_lock_map); > +#endif All the locking code use CONFIG_DEBUG_LOCK_ALLOC to determine if lockdep_map should be used. Should you also use CONFIG_DEBUG_LOCK_ALLOC instead of CONFIG_LOCKDEP to be consistent with the others? Cheers, Longman