Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1754755ybc; Wed, 13 Nov 2019 03:55:11 -0800 (PST) X-Google-Smtp-Source: APXvYqyKZMxZNUNImNjcZnM3YJy6RL+PVoY+hDAfeML0Ymnl9NJ2Qm9YMI+yMWzjA4jZk64gjfbQ X-Received: by 2002:aa7:c048:: with SMTP id k8mr3004638edo.254.1573646111042; Wed, 13 Nov 2019 03:55:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573646111; cv=none; d=google.com; s=arc-20160816; b=RqecrB03ZphLP6d2kwDHebrf2Uiv1F3T1CmdnNRb9K6q2HSU0B92M2u0fkINUTUg3y oDXP6W37prxwlgo5oXzhAvKfcH3osYW7qIlLDxxlAw0j4FMByClMUzM7NuXZor08ZFUn pyaDZj+dVn3/KNkGhUcgiGbF2FwV2ow+gzMZYrD3+Bupwt2HCn3CytlWh6b77qCS8pR3 oIkAyw6K4SL8D1hPgK+mgsrtDg7MNKMWs2yMT7B3QRgj0s8oYltwFm+3U+c9qb/XMwes 5fos7JQ7TfcEpFy7EJ52KXRavueRkGNBAt5G/O8pXZ/ac2RWuytmCPq1tZAEV5A+rGwy g0Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=F3ba3fPaNjj6mlJHz6ZNFQ1Kt4UtZpzpsGyGcMEsfIQ=; b=s0Ya8cXS28wvwgTjKXUMSPfD08WR9RACoI/XnHet0EeucR5w+3T7c/2ZhTRnvrT46R 0AdJ1XvTiHVl2bnfIBR5lOcCAFSBUUr0NwttIROTyAutv8uCzTAV2jl0nekkTWpj/vRZ nbae6ob5leyLXksah5wmUmiLvNR+ny5IzJpbjaVRETPCCjHIlw9PpSVB4sSfzjty4/s4 Pa/3ZBCrIXj+Dxm4xpn4VnmSstQXJMyflVyD6/fKfrD9sW9KHYgjMDCC9tJGMAZTG7Mz ugRD9TbEp3OcIkj81y+Vy01LStwPbn+i54HoBqs8325/uJ/Ryk6Nxw6niHAiTxEkVCt7 Pq1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arrikto-com.20150623.gappssmtp.com header.s=20150623 header.b=zP4PL6GG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l42si1181558edc.309.2019.11.13.03.54.46; Wed, 13 Nov 2019 03:55:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arrikto-com.20150623.gappssmtp.com header.s=20150623 header.b=zP4PL6GG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbfKMLvG (ORCPT + 99 others); Wed, 13 Nov 2019 06:51:06 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:40676 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727845AbfKMLvF (ORCPT ); Wed, 13 Nov 2019 06:51:05 -0500 Received: by mail-lj1-f193.google.com with SMTP id q2so2219308ljg.7 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=CsNelrIM8NKwAXgf7cGHvMGVBn4pfRHb6qsrMe5tiUUU/E3zrKd0DfotX1rJkC8w1+ iCo5J8fwtc7bJO/cISkjYvLJAFIMzB7cWevATYPLGojsseItMP/dKr+52vi1OBOFaSmi KqalhaTY4VQPySZrN4FA2wzpCO2W10VDEsoNraCYdVeulJsn1sn78WXgEaphyfMCv+Oe PZhXEQqhcVbpt0FX8S8pgCVOze0RFFhyPHxGNOUj8WiNohIxf8dy3getYiTAUIOrA9fS o2S6ZXID3xhQ4Gqa4h3O43EwurIFq6MJKR9ra3YEmUe28XdykD2pcO5lSO3ZhH9sNSZF qnSw== X-Gm-Message-State: APjAAAVUhR0YvbbSfpAjF2fafcMnGIv/etcT0hpsKLAvoKk5llg2S/QZ uJfHukZClOxoECzhCY+FYSlRsg== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 >>> } >>> >> >