Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1789351ybc; Wed, 13 Nov 2019 04:27:20 -0800 (PST) X-Google-Smtp-Source: APXvYqyA7CNMj73qNB4Bxh7mgxgYFDEBJGKbBvVPSPYYPUCe66tzx87fGzxAsNisDEuYhK9Y4bAd X-Received: by 2002:a05:6402:7cd:: with SMTP id u13mr3138932edy.246.1573648040569; Wed, 13 Nov 2019 04:27:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573648040; cv=none; d=google.com; s=arc-20160816; b=B55HCXyW4NZP1A6JVzp7bwmxYtBlobHDW79t9v21OiLHzNrd1o2GaU7y2Ua+och8F+ tBGUc6Q7jCC+goMqGw1dA2KL2MiPcB1335EMrDzRPl9n4kNwfQHlxTg3rAMJH1ARrjTG 8Wp1PERrPIMC+10lrRhxuF9MI2UHTWrOMt4pBB8abARTZHzlRKbFkBz8VKzBYzWbqaeL 0Kgk+rGUVjrbSFvJnIHQ7ICu+eCO6jWJjPXRMyZm3H+n0dxbbt+xwMOp1AclV2T7yfgW fSTpHmC+8mEhuKk+ph6s6czD/ZSYldRpIzrAxZ81enyxAHnZdM/CPaxTrLedQ0sfEVp+ QIWw== 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:mime-version :user-agent:references:message-id:in-reply-to:subject:cc:to:from :date:dkim-signature; bh=yLFHitioaaxpC6mZgafz141WkUvCAGQV3scdUsoDeAY=; b=OVkVi8MJycTbvv9p2SbfAyLqou11oLJfwH0VDQ9OhuSGmuYFhTpIhq50nlBeFCxtcc ehIwmZMILSPQoevgJPsddtZ5irUVPhcXQ0PMWKolTcHQGL8Io76+k/oWUMjbYEb4YSCy 18JMTAgiH8rQu9JAtFzeMb7hahotpuIx/f1qASYCh2dTljKAKKNvhc3MZuFhGPphItzl CjdgZlJCZZTMZYodXEAxp5I6QKh3S3zcV/XSXo79O8n4h5k25vWAtcVuXIaweRlvX+1R JOh1kIq1d6GZPJFN38BuAx2buw2aMELQHOD5TBl7oWYxYvNgxrGWF5tvt8r2V4kpLj+n Cc0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N+FRyO+6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n27si1094077ejl.272.2019.11.13.04.26.55; Wed, 13 Nov 2019 04:27:20 -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=@redhat.com header.s=mimecast20190719 header.b=N+FRyO+6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726409AbfKMMFr (ORCPT + 99 others); Wed, 13 Nov 2019 07:05:47 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45476 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726350AbfKMMFq (ORCPT ); Wed, 13 Nov 2019 07:05:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573646744; 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=yLFHitioaaxpC6mZgafz141WkUvCAGQV3scdUsoDeAY=; b=N+FRyO+6SPvvZdy2v4Dgikx93CPm5kM7kID0H5EDa8TD3amgSvFGCL+EiZgDEjQy+RijbT ZxL777Ym0gdgGWw39Ouhp2tNZyAtQFFpZhsiYUYUcmny0KJa6L+/h7U+/tmMiFphIJNwMO wTR8cs/76DKYkd39JhVjvnvlC9dlu/0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-wJ12IqlvPv6xGFp9FfA5vQ-1; Wed, 13 Nov 2019 07:05:41 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 784931852E21; Wed, 13 Nov 2019 12:05:39 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D51B56046C; Wed, 13 Nov 2019 12:05:36 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id xADC5aGd028404; Wed, 13 Nov 2019 07:05:36 -0500 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id xADC5aIo028400; Wed, 13 Nov 2019 07:05:36 -0500 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Wed, 13 Nov 2019 07:05:36 -0500 (EST) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Nikos Tsironis 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 Subject: Re: [PATCH RT 2/2 v2] list_bl: avoid BUG when the list is not locked In-Reply-To: <7020d479-e8c7-7249-c6cd-c6d01b01c92a@arrikto.com> Message-ID: References: <335dafcb-5e07-63ed-b288-196516170bde@arrikto.com> <7020d479-e8c7-7249-c6cd-c6d01b01c92a@arrikto.com> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: wJ12IqlvPv6xGFp9FfA5vQ-1 X-Mimecast-Spam-Score: 0 Content-Type: TEXT/PLAIN; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 13 Nov 2019, Nikos Tsironis wrote: > On 11/13/19 1:16 PM, Mikulas Patocka wrote: > >=20 > >=20 > > On Wed, 13 Nov 2019, Nikos Tsironis wrote: > >=20 > >> On 11/12/19 6:16 PM, Mikulas Patocka wrote: > >>> list_bl would crash with BUG() if we used it without locking. dm-snap= shot=20 > >>> uses its own locking on realtime kernels (it can't use list_bl becaus= e=20 > >>> list_bl uses raw spinlock and dm-snapshot takes other non-raw spinloc= ks=20 > >>> while holding bl_lock). > >>> > >>> To avoid this BUG, we must set LIST_BL_LOCKMASK =3D 0. > >>> > >>> This patch is intended only for the realtime kernel patchset, not for= the=20 > >>> upstream kernel. > >>> > >>> Signed-off-by: Mikulas Patocka > >>> > >>> Index: linux-rt-devel/include/linux/list_bl.h > >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >>> --- linux-rt-devel.orig/include/linux/list_bl.h=092019-11-07 14:01:51= .000000000 +0100 > >>> +++ linux-rt-devel/include/linux/list_bl.h=092019-11-08 10:12:49.0000= 00000 +0100 > >>> @@ -19,7 +19,7 @@ > >>> * some fast and compact auxiliary data. > >>> */ > >>> =20 > >>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) > >>> +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && !defi= ned(CONFIG_PREEMPT_RT_BASE) > >>> #define LIST_BL_LOCKMASK=091UL > >>> #else > >>> #define LIST_BL_LOCKMASK=090UL > >>> @@ -161,9 +161,6 @@ static inline void hlist_bl_lock(struct > >>> =09bit_spin_lock(0, (unsigned long *)b); > >>> #else > >>> =09raw_spin_lock(&b->lock); > >>> -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) > >>> -=09__set_bit(0, (unsigned long *)b); > >>> -#endif > >>> #endif > >>> } > >>> =20 > >> > >> 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 > >=20 > > OK. so I can remove this part of the patch. > >=20 >=20 > 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. >=20 > I think for dm-snapshot to work using its own locking, and without > list_bl complaining, the following is sufficient: >=20 > --- a/include/linux/list_bl.h > +++ b/include/linux/list_bl.h > @@ -25,7 +25,7 @@ > #define LIST_BL_LOCKMASK 0UL > #endif >=20 > -#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) >=20 > Nikos Yes - so, submit this. Reviewed-by: Mikulas Patocka Mikulas