From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DAB6C43331 for ; Wed, 13 Nov 2019 11:51:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D1B12245C for ; Wed, 13 Nov 2019 11:51:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=arrikto-com.20150623.gappssmtp.com header.i=@arrikto-com.20150623.gappssmtp.com header.b="zP4PL6GG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727923AbfKMLvF (ORCPT ); Wed, 13 Nov 2019 06:51:05 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35740 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727567AbfKMLvF (ORCPT ); Wed, 13 Nov 2019 06:51:05 -0500 Received: by mail-lj1-f195.google.com with SMTP id r7so2249663ljg.2 for ; Wed, 13 Nov 2019 03:51:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arrikto-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=F3ba3fPaNjj6mlJHz6ZNFQ1Kt4UtZpzpsGyGcMEsfIQ=; b=zP4PL6GGMs7Kj1scjhgJHt2sVT3/NC5Acea4ch+a+0FuOqO5MOtgX0w4hMuz/ja5Iy Gt38FE9o1dloB4Z5+S0lVOSLOYCqD0+IJh1Cl6Yhz32Thzkp0P4qCXoyAyDjW+OQLaEB DhAU7qFnVX/Z+8DM1kYLOww9SLjFRtV3GPwa+UQeqQyJWfmp3RAPAV5MuOtOAol3wuyH o+tQBc3FZzL+aIBxqkJy6JaxIuTDoCf0Exg0gAuugREZVVM2CWvOuB8Dn5vUZVDipNJY Ci26/iXyMUHacFU2dBbl/GnTQwRMzj039b9UmINh2AoUz3NT3tAiuDVVU+uEGQ0U7DuO id0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=F3ba3fPaNjj6mlJHz6ZNFQ1Kt4UtZpzpsGyGcMEsfIQ=; b=n9w3NkqvIAXt4IG20Kqa19ctLBoEndWxTsyImZSxFdWR8S9hpsAqF+MIyBuo7OP5ex Xu/OSZ6sa/Rt47VE0tDWTZGYksyNS6LBhQUBUqpDKufq9OB61rSE4+HMKuugnX5LzFcV 7LPKWkxhPtE1VgnQ9gkM9ioHfAjjoy3oDBai4I3qMF40sbm2XlJyFjLJQ+eDAqgeQnHj hnV7wwVitk3oXd+c0GpLYRjWML9zVLvYkh9YeVg8J4DXt8o+Lpnh+RRwePXMpMbs5VFJ AXIJKrKkSQuHkzpCR2jQeAgM56DjDMaZNf/6gqegwX9mJc9Tfh6SK11gCI90saKUHmmm YlOg== X-Gm-Message-State: APjAAAUnXmUIJYPpvopR0F7mR1TzXKHlJ7UAnTKFnCP2Ay1sYYkyuLdJ KZTB+9wsIALr3VIj9aUKMcXP2A== X-Google-Smtp-Source: APXvYqzKYvomWMYyrqmUw0GA6R5IG9gdUX23Ot2rzD6JQd1DJwcOXpb4Rwcb+3ZDxTO+fAwaPzJErA== X-Received: by 2002:a2e:7204:: with SMTP id n4mr2215410ljc.139.1573645863283; Wed, 13 Nov 2019 03:51:03 -0800 (PST) Received: from [10.94.250.119] ([31.177.62.212]) by smtp.gmail.com with ESMTPSA id q124sm789120ljq.93.2019.11.13.03.51.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Nov 2019 03:51:02 -0800 (PST) Subject: Re: [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked To: Mikulas Patocka Cc: tglx@linutronix.de, linux-rt-users@vger.kernel.org, Mike Snitzer , Scott Wood , Ilias Tsitsimpis , dm-devel@redhat.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Daniel Wagner , Sebastian Andrzej Siewior References: <335dafcb-5e07-63ed-b288-196516170bde@arrikto.com> From: Nikos Tsironis Message-ID: <7020d479-e8c7-7249-c6cd-c6d01b01c92a@arrikto.com> Date: Wed, 13 Nov 2019 13:50:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org On 11/13/19 1:16 PM, Mikulas Patocka wrote: > > > On Wed, 13 Nov 2019, Nikos Tsironis wrote: > >> On 11/12/19 6:16 PM, Mikulas Patocka wrote: >>> list_bl would crash with BUG() if we used it without locking. dm-snapshot >>> uses its own locking on realtime kernels (it can't use list_bl because >>> list_bl uses raw spinlock and dm-snapshot takes other non-raw spinlocks >>> while holding bl_lock). >>> >>> To avoid this BUG, we must set LIST_BL_LOCKMASK = 0. >>> >>> This patch is intended only for the realtime kernel patchset, not for the >>> upstream kernel. >>> >>> Signed-off-by: Mikulas Patocka >>> >>> Index: linux-rt-devel/include/linux/list_bl.h >>> =================================================================== >>> --- linux-rt-devel.orig/include/linux/list_bl.h 2019-11-07 14:01:51.000000000 +0100 >>> +++ linux-rt-devel/include/linux/list_bl.h 2019-11-08 10:12:49.000000000 +0100 >>> @@ -19,7 +19,7 @@ >>> * some fast and compact auxiliary data. >>> */ >>> >>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) >>> +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defined(CONFIG_PREEMPT_RT_BASE) >>> #define LIST_BL_LOCKMASK 1UL >>> #else >>> #define LIST_BL_LOCKMASK 0UL >>> @@ -161,9 +161,6 @@ static inline void hlist_bl_lock(struct >>> bit_spin_lock(0, (unsigned long *)b); >>> #else >>> raw_spin_lock(&b->lock); >>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) >>> - __set_bit(0, (unsigned long *)b); >>> -#endif >>> #endif >>> } >>> >> >> Hi Mikulas, >> >> I think removing __set_bit()/__clear_bit() breaks hlist_bl_is_locked(), >> which is used by the RCU variant of list_bl. >> >> Nikos > > OK. so I can remove this part of the patch. > I think this causes another problem. LIST_BL_LOCKMASK is used in various functions to set/clear the lock bit, e.g. in hlist_bl_first(). So, if we lock the list through hlist_bl_lock(), thus setting the lock bit with __set_bit(), and then call hlist_bl_first() to get the first element, the returned pointer will be invalid. As LIST_BL_LOCKMASK is zero the least significant bit of the pointer will be 1. I think for dm-snapshot to work using its own locking, and without list_bl complaining, the following is sufficient: --- a/include/linux/list_bl.h +++ b/include/linux/list_bl.h @@ -25,7 +25,7 @@ #define LIST_BL_LOCKMASK 0UL #endif -#ifdef CONFIG_DEBUG_LIST +#if defined(CONFIG_DEBUG_LIST) && !defined(CONFIG_PREEMPT_RT_BASE) #define LIST_BL_BUG_ON(x) BUG_ON(x) #else #define LIST_BL_BUG_ON(x) Nikos > Mikulas > >>> @@ -172,9 +169,6 @@ static inline void hlist_bl_unlock(struc >>> #ifndef CONFIG_PREEMPT_RT_BASE >>> __bit_spin_unlock(0, (unsigned long *)b); >>> #else >>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) >>> - __clear_bit(0, (unsigned long *)b); >>> -#endif >>> raw_spin_unlock(&b->lock); >>> #endif >>> } >>> >> >