Message ID | 20230713055841.24815-1-mark-pk.tsai@mediatek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1627880vqm; Wed, 12 Jul 2023 23:35:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlGHGxUzjW2b3YR6Ph5p5Rfb/K/pHni2tIPLJ3YAcFDXbEbY/PPASE7MoJ0ZtPqrqtAwZC9Q X-Received: by 2002:a05:6870:a410:b0:19f:63d1:3d4e with SMTP id m16-20020a056870a41000b0019f63d13d4emr1046308oal.33.1689230140774; Wed, 12 Jul 2023 23:35:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689230140; cv=none; d=google.com; s=arc-20160816; b=l7ePg3P2Z7PI02jBk1E0zLTSW1yL6GxcW6/wnNtsDPnAoajOBQ06M0DV6TmaTrhKn6 KDX/gRq5Q3ziZHXkh9r+u1X32H36VD3Jl1qmynM068T/sqYPw8ePbBGN8SDBosgntc+Y 6nuAjbqesMhiy5zY27OgK1y8pNaKdFpa9uMx5MYtyetGZU9S+fKGIq5+uxxaMl6QfgoP LjrO1QnWJOrTVlDms2ujOfLk77pU54O5Au3UHGM+8SmpoNLK5ro8JvxTc415YhKZiPCz 5DmBNN0o3sDZngbd50Wm7Vj47yky6mofWUQLib5nxh4H3BEnsxkJIKZkkE5x4Rak9XAz fabg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=E2jkB6QuAT5TlLxmNf2eeEz1sQnQ+ByDeLjjrUTWBMw=; fh=lFoEWPwESjdbXOeIN2Im1fgkXBuzrE2g/H/4h+95Rb0=; b=STaEBVcH3VINZp4SaPyT2oO41LC7C7hwqSBEZfF7zqBz6Q9a7vLn7+xp1kkb2bu0Rw kwiHtIrDmVoMrYYW9srpnG2aeUk1iNl5uETiM8iADG/lFdS6SQ59p4eMinQu4RizOsn9 MGkaB84oCtAGX+/rt2EJvBRGmvsyB5K0KurIxmrcE2e6gKjNlKVJGVglZU2YOwmGy235 8JbFJsHH4UD5lIvfU+h5P/XDG4Q3EJ6h+ATYX28W7G5SXS5vbtK4LjIc3/GTn+8sYsks kFRmJHLlsE6bTOmXuOwOPAkGufZLqlwgRyA0j0mRi4ESD66UKa6CV+zm7lqwdNT4YF4I jeUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=hv3ckB1X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a654c0b000000b0053f479ef142si4428716pgq.124.2023.07.12.23.35.25; Wed, 12 Jul 2023 23:35:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=hv3ckB1X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233993AbjGMF7C (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Thu, 13 Jul 2023 01:59:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233753AbjGMF7A (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Jul 2023 01:59:00 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41BDE213E; Wed, 12 Jul 2023 22:58:46 -0700 (PDT) X-UUID: 53382e3e214211ee9cb5633481061a41-20230713 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=E2jkB6QuAT5TlLxmNf2eeEz1sQnQ+ByDeLjjrUTWBMw=; b=hv3ckB1Xns6N3GoUxMirUA0WCgMMx0un/B6rCi1RWMknilAc2TcARp/6okIsBFvfWq/8rkilxLFow7UL/yb/cINPjf1UlinkZo1QMoKrI+SHQYcomfPajL1eS4S7nW9AwyNYDDWtNymS8LYq+HVIjMKogHlQSZtXUFRA4ClXXEU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.28,REQID:7eafe7a2-2856-4ca2-bb0b-83f63bdac10f,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:176cd25,CLOUDID:1f782e0e-c22b-45ab-8a43-3004e9216b56,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO, DKR:0,DKP:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 53382e3e214211ee9cb5633481061a41-20230713 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw01.mediatek.com (envelope-from <mark-pk.tsai@mediatek.com>) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 953533169; Thu, 13 Jul 2023 13:58:44 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 13 Jul 2023 13:58:43 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 13 Jul 2023 13:58:43 +0800 From: Mark-PK Tsai <mark-pk.tsai@mediatek.com> To: Alasdair Kergon <agk@redhat.com>, Mike Snitzer <snitzer@redhat.com>, <dm-devel@redhat.com>, Jonathan Corbet <corbet@lwn.net>, Matthias Brugger <matthias.bgg@gmail.com> CC: <yj.chiang@mediatek.com>, Peter Korsgaard <peter@korsgaard.com>, Mike Snitzer <snitzer@kernel.org>, <stable@vger.kernel.org>, Mark-PK Tsai <mark-pk.tsai@mediatek.com>, <linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-mediatek@lists.infradead.org> Subject: [PATCH 5.15] dm init: add dm-mod.waitfor to wait for asynchronously probed block devices Date: Thu, 13 Jul 2023 13:58:37 +0800 Message-ID: <20230713055841.24815-1-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAY_BE_FORGED,SPF_HELO_PASS,T_SCC_BODY_TEXT_LINE, T_SPF_TEMPERROR,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771286184035997314 X-GMAIL-MSGID: 1771286184035997314 |
Series |
[5.15] dm init: add dm-mod.waitfor to wait for asynchronously probed block devices
|
|
Commit Message
Mark-PK Tsai (蔡沛剛)
July 13, 2023, 5:58 a.m. UTC
From: Peter Korsgaard <peter@korsgaard.com> Just calling wait_for_device_probe() is not enough to ensure that asynchronously probed block devices are available (E.G. mmc, usb), so add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get dm-init to explicitly wait for specific block devices before initializing the tables with logic similar to the rootwait logic that was introduced with commit cc1ed7542c8c ("init: wait for asynchronously scanned block devices"). E.G. with dm-verity on mmc using: dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" [ 0.671671] device-mapper: init: waiting for all devices to be available before creating mapped devices [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a ... [ 0.710695] mmc0: new HS200 MMC card at address 0001 [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, chardev (249:0) [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a ... [ 0.751306] device-mapper: init: all devices available [ 0.751683] device-mapper: verity: sha256 using implementation "sha256-generic" [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on device 254:0. Signed-off-by: Peter Korsgaard <peter@korsgaard.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> --- .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ drivers/md/dm-init.c | 22 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-)
Comments
On Thu, Jul 13, 2023 at 01:58:37PM +0800, Mark-PK Tsai wrote: > From: Peter Korsgaard <peter@korsgaard.com> > > Just calling wait_for_device_probe() is not enough to ensure that > asynchronously probed block devices are available (E.G. mmc, usb), so > add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get > dm-init to explicitly wait for specific block devices before > initializing the tables with logic similar to the rootwait logic that > was introduced with commit cc1ed7542c8c ("init: wait for > asynchronously scanned block devices"). > > E.G. with dm-verity on mmc using: > dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" > > [ 0.671671] device-mapper: init: waiting for all devices to be available before creating mapped devices > [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a ... > [ 0.710695] mmc0: new HS200 MMC card at address 0001 > [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB > [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB > [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB > [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, chardev (249:0) > [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 > [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a ... > [ 0.751306] device-mapper: init: all devices available > [ 0.751683] device-mapper: verity: sha256 using implementation "sha256-generic" > [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready > [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on device 254:0. > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > Signed-off-by: Mike Snitzer <snitzer@kernel.org> > Cc: stable@vger.kernel.org > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> > --- > .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ > drivers/md/dm-init.c | 22 ++++++++++++++++++- > 2 files changed, 29 insertions(+), 1 deletion(-) What is the git commit id of this change in Linus's tree? thanks, greg k-h
On Sun, Jul 16, 2023, 11:16 AM Greg KH <gregkh@linuxfoundation.org> wrote: > On Thu, Jul 13, 2023 at 01:58:37PM +0800, Mark-PK Tsai wrote: > > From: Peter Korsgaard <peter@korsgaard.com> > > > > Just calling wait_for_device_probe() is not enough to ensure that > > asynchronously probed block devices are available (E.G. mmc, usb), so > > add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get > > dm-init to explicitly wait for specific block devices before > > initializing the tables with logic similar to the rootwait logic that > > was introduced with commit cc1ed7542c8c ("init: wait for > > asynchronously scanned block devices"). > > > > E.G. with dm-verity on mmc using: > > dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" > > > > [ 0.671671] device-mapper: init: waiting for all devices to be > available before creating mapped devices > > [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a > ... > > [ 0.710695] mmc0: new HS200 MMC card at address 0001 > > [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB > > [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB > > [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB > > [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, > chardev (249:0) > > [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 > > [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a > ... > > [ 0.751306] device-mapper: init: all devices available > > [ 0.751683] device-mapper: verity: sha256 using implementation > "sha256-generic" > > [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready > > [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on > device 254:0. > > > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > > Signed-off-by: Mike Snitzer <snitzer@kernel.org> > > Cc: stable@vger.kernel.org > > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> > > --- > > .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ > > drivers/md/dm-init.c | 22 ++++++++++++++++++- > > 2 files changed, 29 insertions(+), 1 deletion(-) > > What is the git commit id of this change in Linus's tree? > > thanks, > > greg k-h > > Hey Greg, This change shouldn't be backported to stable@. It is a feature, if Mark-PK feels they need it older kernels they need to carry the change in their own tree. Or at a minimum they need to explain why this change is warranted in stable@. But to answer your original question the upstream commit is: 035641b01e72 dm init: add dm-mod.waitfor to wait for asynchronously probed block devices Thanks, Mike
On Sun, Jul 16, 2023 at 11:36:36AM -0400, Mike Snitzer wrote: > On Sun, Jul 16, 2023, 11:16 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > > On Thu, Jul 13, 2023 at 01:58:37PM +0800, Mark-PK Tsai wrote: > > > From: Peter Korsgaard <peter@korsgaard.com> > > > > > > Just calling wait_for_device_probe() is not enough to ensure that > > > asynchronously probed block devices are available (E.G. mmc, usb), so > > > add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get > > > dm-init to explicitly wait for specific block devices before > > > initializing the tables with logic similar to the rootwait logic that > > > was introduced with commit cc1ed7542c8c ("init: wait for > > > asynchronously scanned block devices"). > > > > > > E.G. with dm-verity on mmc using: > > > dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" > > > > > > [ 0.671671] device-mapper: init: waiting for all devices to be > > available before creating mapped devices > > > [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a > > ... > > > [ 0.710695] mmc0: new HS200 MMC card at address 0001 > > > [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB > > > [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB > > > [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB > > > [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, > > chardev (249:0) > > > [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 > > > [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a > > ... > > > [ 0.751306] device-mapper: init: all devices available > > > [ 0.751683] device-mapper: verity: sha256 using implementation > > "sha256-generic" > > > [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready > > > [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on > > device 254:0. > > > > > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > > > Signed-off-by: Mike Snitzer <snitzer@kernel.org> > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> > > > --- > > > .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ > > > drivers/md/dm-init.c | 22 ++++++++++++++++++- > > > 2 files changed, 29 insertions(+), 1 deletion(-) > > > > What is the git commit id of this change in Linus's tree? > > > > thanks, > > > > greg k-h > > > > > > Hey Greg, > > This change shouldn't be backported to stable@. It is a feature, if > Mark-PK feels they need it older kernels they need to carry the change > in their own tree. Or at a minimum they need to explain why this > change is warranted in stable@. Ok, I'll drop it from my queue. > But to answer your original question the upstream commit is: > > 035641b01e72 dm init: add dm-mod.waitfor to wait for asynchronously probed block devices Ah, showed up in 6.2, so we have to have a 6.1.y backport as well, I can't take patches for only older kernels, sorry. thanks, greg k-h
> On Sun, Jul 16, 2023, 11:16 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > > On Thu, Jul 13, 2023 at 01:58:37PM +0800, Mark-PK Tsai wrote: > > > From: Peter Korsgaard <peter@korsgaard.com> > > > > > > Just calling wait_for_device_probe() is not enough to ensure that > > > asynchronously probed block devices are available (E.G. mmc, usb), so > > > add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get > > > dm-init to explicitly wait for specific block devices before > > > initializing the tables with logic similar to the rootwait logic that > > > was introduced with commit cc1ed7542c8c ("init: wait for > > > asynchronously scanned block devices"). > > > > > > E.G. with dm-verity on mmc using: > > > dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" > > > > > > [ 0.671671] device-mapper: init: waiting for all devices to be > > available before creating mapped devices > > > [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a > > ... > > > [ 0.710695] mmc0: new HS200 MMC card at address 0001 > > > [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB > > > [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB > > > [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB > > > [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, > > chardev (249:0) > > > [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 > > > [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a > > ... > > > [ 0.751306] device-mapper: init: all devices available > > > [ 0.751683] device-mapper: verity: sha256 using implementation > > "sha256-generic" > > > [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready > > > [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on > > device 254:0. > > > > > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > > > Signed-off-by: Mike Snitzer <snitzer@kernel.org> > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> > > > --- > > > .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ > > > drivers/md/dm-init.c | 22 ++++++++++++++++++- > > > 2 files changed, 29 insertions(+), 1 deletion(-) > > > > What is the git commit id of this change in Linus's tree? > > > > thanks, > > > > greg k-h > > > > > > Hey Greg, > > This change shouldn't be backported to stable@. It is a feature, if > Mark-PK feels they need it older kernels they need to carry the change > in their own tree. Or at a minimum they need to explain why this > change is warranted in stable@. Thanks for your comment. The reason why we think this should be backported to stable kernel is that it actually fix the potential race condition when make block device probe async in stable kernel. And we'd like to fix this upstream rather than just take it in our custom tree. > > But to answer your original question the upstream commit is: > > 035641b01e72 dm init: add dm-mod.waitfor to wait for asynchronously probed block devices > > Thanks, > Mike
On Mon, Jul 17, 2023 at 09:57:28AM +0800, Mark-PK Tsai wrote: > > On Sun, Jul 16, 2023, 11:16 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > > > > On Thu, Jul 13, 2023 at 01:58:37PM +0800, Mark-PK Tsai wrote: > > > > From: Peter Korsgaard <peter@korsgaard.com> > > > > > > > > Just calling wait_for_device_probe() is not enough to ensure that > > > > asynchronously probed block devices are available (E.G. mmc, usb), so > > > > add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get > > > > dm-init to explicitly wait for specific block devices before > > > > initializing the tables with logic similar to the rootwait logic that > > > > was introduced with commit cc1ed7542c8c ("init: wait for > > > > asynchronously scanned block devices"). > > > > > > > > E.G. with dm-verity on mmc using: > > > > dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" > > > > > > > > [ 0.671671] device-mapper: init: waiting for all devices to be > > > available before creating mapped devices > > > > [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a > > > ... > > > > [ 0.710695] mmc0: new HS200 MMC card at address 0001 > > > > [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB > > > > [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB > > > > [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB > > > > [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, > > > chardev (249:0) > > > > [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 > > > > [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a > > > ... > > > > [ 0.751306] device-mapper: init: all devices available > > > > [ 0.751683] device-mapper: verity: sha256 using implementation > > > "sha256-generic" > > > > [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready > > > > [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on > > > device 254:0. > > > > > > > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > > > > Signed-off-by: Mike Snitzer <snitzer@kernel.org> > > > > Cc: stable@vger.kernel.org > > > > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> > > > > --- > > > > .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ > > > > drivers/md/dm-init.c | 22 ++++++++++++++++++- > > > > 2 files changed, 29 insertions(+), 1 deletion(-) > > > > > > What is the git commit id of this change in Linus's tree? > > > > > > thanks, > > > > > > greg k-h > > > > > > > > > > Hey Greg, > > > > This change shouldn't be backported to stable@. It is a feature, if > > Mark-PK feels they need it older kernels they need to carry the change > > in their own tree. Or at a minimum they need to explain why this > > change is warranted in stable@. > > Thanks for your comment. > The reason why we think this should be backported to stable kernel is > that it actually fix the potential race condition when make block > device probe async in stable kernel. > And we'd like to fix this upstream rather than just take it in > our custom tree. Potential race condition, is this actually able to be hit in real life? thanks, greg k-h
> On Mon, Jul 17, 2023 at 09:57:28AM +0800, Mark-PK Tsai wrote: > > > On Sun, Jul 16, 2023, 11:16 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > > > > > > On Thu, Jul 13, 2023 at 01:58:37PM +0800, Mark-PK Tsai wrote: > > > > > From: Peter Korsgaard <peter@korsgaard.com> > > > > > > > > > > Just calling wait_for_device_probe() is not enough to ensure that > > > > > asynchronously probed block devices are available (E.G. mmc, usb), so > > > > > add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get > > > > > dm-init to explicitly wait for specific block devices before > > > > > initializing the tables with logic similar to the rootwait logic that > > > > > was introduced with commit cc1ed7542c8c ("init: wait for > > > > > asynchronously scanned block devices"). > > > > > > > > > > E.G. with dm-verity on mmc using: > > > > > dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" > > > > > > > > > > [ 0.671671] device-mapper: init: waiting for all devices to be > > > > available before creating mapped devices > > > > > [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a > > > > ... > > > > > [ 0.710695] mmc0: new HS200 MMC card at address 0001 > > > > > [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB > > > > > [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB > > > > > [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB > > > > > [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, > > > > chardev (249:0) > > > > > [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 > > > > > [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a > > > > ... > > > > > [ 0.751306] device-mapper: init: all devices available > > > > > [ 0.751683] device-mapper: verity: sha256 using implementation > > > > "sha256-generic" > > > > > [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready > > > > > [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on > > > > device 254:0. > > > > > > > > > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > > > > > Signed-off-by: Mike Snitzer <snitzer@kernel.org> > > > > > Cc: stable@vger.kernel.org > > > > > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> > > > > > --- > > > > > .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ > > > > > drivers/md/dm-init.c | 22 ++++++++++++++++++- > > > > > 2 files changed, 29 insertions(+), 1 deletion(-) > > > > > > > > What is the git commit id of this change in Linus's tree? > > > > > > > > thanks, > > > > > > > > greg k-h > > > > > > > > > > > > > > Hey Greg, > > > > > > This change shouldn't be backported to stable@. It is a feature, if > > > Mark-PK feels they need it older kernels they need to carry the change > > > in their own tree. Or at a minimum they need to explain why this > > > change is warranted in stable@. > > > > Thanks for your comment. > > The reason why we think this should be backported to stable kernel is > > that it actually fix the potential race condition when make block > > device probe async in stable kernel. > > And we'd like to fix this upstream rather than just take it in > > our custom tree. > > Potential race condition, is this actually able to be hit in real life? Yes it hanppened, and it can lead the kernel init process stuck in the root wait loop. Below is the log. (I add 20 seconds delay in mtk_mci probe to quick reproduce it.) * Before apply this pactch [ 0.368594][ T1] device-mapper: init: waiting for all devices to be available before creating mapped devices [ 21.673047][ T45] probe of 1c660000.mtk-mmc-fcie returned 0 after 21541020 usecs [ 21.673061][ T45] mtk_mci 1c660000.mtk-mmc-fcie: driver mtk_mci async attach completed: 0 [ 21.680006][ T1] device-mapper: table: 254:0: verity: Data device lookup failed <--------------- start after mtk_mci probe done [ 21.680012][ T1] device-mapper: ioctl: error adding target to table <--------------------------- won't create /dev/dm-0 [ 21.680067][ T67] mmc0: new HS400 Enhanced strobe MMC card at address 0001 [ 21.680184][ T67] bus: 'mmc': __driver_probe_device: matched device mmc0:0001 with driver mmcblk [ 21.680192][ T67] bus: 'mmc': really_probe: probing driver mmcblk with device mmc0:0001 [ 21.680500][ T67] mmcblk0: mmc0:0001 016G01 14.5 GiB [ 21.683404][ T67] mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 [ 21.686152][ T67] mmcblk0boot0: mmc0:0001 016G01 8.00 MiB [ 21.687166][ T67] mmcblk0boot1: mmc0:0001 016G01 8.00 MiB [ 21.687955][ T67] mmcblk0rpmb: mmc0:0001 016G01 4.00 MiB, chardev (238:0) [ 21.687977][ T67] driver: 'mmcblk': driver_bound: bound to device 'mmc0:0001' [ 21.688004][ T67] bus: 'mmc': really_probe: bound device mmc0:0001 to driver mmcblk [ 21.688010][ T67] probe of mmc0:0001 returned 0 after 7819 usecs [ 21.688166][ T1] Waiting for root device /dev/dm-0... [ 41.023192][ T1] driver_probe_done: probe_count = 0 ... can't exit from the root wait loop * After apply this patch and add dm-mod.waitfor="PARTLABEL=rootfs" [ 0.368417][ T1] device-mapper: init: waiting for all devices to be available before creating mapped devices [ 21.672749][ T45] probe of 1c660000.mtk-mmc-fcie returned 0 after 21540992 usecs [ 21.672767][ T45] mtk_mci 1c660000.mtk-mmc-fcie: driver mtk_mci async attach completed: 0 [ 21.672774][ T1] device-mapper: init: waiting for device PARTLABEL=rootfs ... [ 21.672869][ T43] mtk_mci 1c660000.mtk-mmc-fcie: eMMC: HS400 5.1 200MHz [ 21.679743][ T43] mmc0: new HS400 Enhanced strobe MMC card at address 0001 [ 21.679852][ T43] bus: 'mmc': __driver_probe_device: matched device mmc0:0001 with driver mmcblk [ 21.679858][ T43] bus: 'mmc': really_probe: probing driver mmcblk with device mmc0:0001 [ 21.680204][ T43] mmcblk0: mmc0:0001 016G01 14.5 GiB [ 21.682866][ T43] mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 [ 21.685579][ T43] mmcblk0boot0: mmc0:0001 016G01 8.00 MiB [ 21.686631][ T43] mmcblk0boot1: mmc0:0001 016G01 8.00 MiB [ 21.687533][ T43] mmcblk0rpmb: mmc0:0001 016G01 4.00 MiB, chardev (238:0) [ 21.687559][ T43] driver: 'mmcblk': driver_bound: bound to device 'mmc0:0001' [ 21.687585][ T43] bus: 'mmc': really_probe: bound device mmc0:0001 to driver mmcblk [ 21.687591][ T43] probe of mmc0:0001 returned 0 after 7732 usecs [ 21.687838][ T1] device-mapper: init: all devices available <---------------------------------- start after PARTLABEL=rootfs is ready [ 21.688155][ T1] device-mapper: verity: sha1 using implementation "sha1-generic" [ 21.688975][ T1] device-mapper: ioctl: dm-0 (dm-verity) is ready > > thanks, > > greg k-h
On Fri, Jul 21, 2023 at 02:38:45PM +0800, Mark-PK Tsai wrote: > > On Mon, Jul 17, 2023 at 09:57:28AM +0800, Mark-PK Tsai wrote: > > > > On Sun, Jul 16, 2023, 11:16 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > > > > > > > > On Thu, Jul 13, 2023 at 01:58:37PM +0800, Mark-PK Tsai wrote: > > > > > > From: Peter Korsgaard <peter@korsgaard.com> > > > > > > > > > > > > Just calling wait_for_device_probe() is not enough to ensure that > > > > > > asynchronously probed block devices are available (E.G. mmc, usb), so > > > > > > add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get > > > > > > dm-init to explicitly wait for specific block devices before > > > > > > initializing the tables with logic similar to the rootwait logic that > > > > > > was introduced with commit cc1ed7542c8c ("init: wait for > > > > > > asynchronously scanned block devices"). > > > > > > > > > > > > E.G. with dm-verity on mmc using: > > > > > > dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" > > > > > > > > > > > > [ 0.671671] device-mapper: init: waiting for all devices to be > > > > > available before creating mapped devices > > > > > > [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a > > > > > ... > > > > > > [ 0.710695] mmc0: new HS200 MMC card at address 0001 > > > > > > [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB > > > > > > [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB > > > > > > [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB > > > > > > [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, > > > > > chardev (249:0) > > > > > > [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 > > > > > > [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a > > > > > ... > > > > > > [ 0.751306] device-mapper: init: all devices available > > > > > > [ 0.751683] device-mapper: verity: sha256 using implementation > > > > > "sha256-generic" > > > > > > [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready > > > > > > [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on > > > > > device 254:0. > > > > > > > > > > > > Signed-off-by: Peter Korsgaard <peter@korsgaard.com> > > > > > > Signed-off-by: Mike Snitzer <snitzer@kernel.org> > > > > > > Cc: stable@vger.kernel.org > > > > > > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> > > > > > > --- > > > > > > .../admin-guide/device-mapper/dm-init.rst | 8 +++++++ > > > > > > drivers/md/dm-init.c | 22 ++++++++++++++++++- > > > > > > 2 files changed, 29 insertions(+), 1 deletion(-) > > > > > > > > > > What is the git commit id of this change in Linus's tree? > > > > > > > > > > thanks, > > > > > > > > > > greg k-h > > > > > > > > > > > > > > > > > > Hey Greg, > > > > > > > > This change shouldn't be backported to stable@. It is a feature, if > > > > Mark-PK feels they need it older kernels they need to carry the change > > > > in their own tree. Or at a minimum they need to explain why this > > > > change is warranted in stable@. > > > > > > Thanks for your comment. > > > The reason why we think this should be backported to stable kernel is > > > that it actually fix the potential race condition when make block > > > device probe async in stable kernel. > > > And we'd like to fix this upstream rather than just take it in > > > our custom tree. > > > > Potential race condition, is this actually able to be hit in real life? > > Yes it hanppened, and it can lead the kernel init process stuck in > the root wait loop. > > Below is the log. > (I add 20 seconds delay in mtk_mci probe to quick reproduce it.) > > * Before apply this pactch > [ 0.368594][ T1] device-mapper: init: waiting for all devices to be available before creating mapped devices > [ 21.673047][ T45] probe of 1c660000.mtk-mmc-fcie returned 0 after 21541020 usecs > [ 21.673061][ T45] mtk_mci 1c660000.mtk-mmc-fcie: driver mtk_mci async attach completed: 0 > [ 21.680006][ T1] device-mapper: table: 254:0: verity: Data device lookup failed <--------------- start after mtk_mci probe done > [ 21.680012][ T1] device-mapper: ioctl: error adding target to table <--------------------------- won't create /dev/dm-0 > [ 21.680067][ T67] mmc0: new HS400 Enhanced strobe MMC card at address 0001 > [ 21.680184][ T67] bus: 'mmc': __driver_probe_device: matched device mmc0:0001 with driver mmcblk > [ 21.680192][ T67] bus: 'mmc': really_probe: probing driver mmcblk with device mmc0:0001 > [ 21.680500][ T67] mmcblk0: mmc0:0001 016G01 14.5 GiB > [ 21.683404][ T67] mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 > [ 21.686152][ T67] mmcblk0boot0: mmc0:0001 016G01 8.00 MiB > [ 21.687166][ T67] mmcblk0boot1: mmc0:0001 016G01 8.00 MiB > [ 21.687955][ T67] mmcblk0rpmb: mmc0:0001 016G01 4.00 MiB, chardev (238:0) > [ 21.687977][ T67] driver: 'mmcblk': driver_bound: bound to device 'mmc0:0001' > [ 21.688004][ T67] bus: 'mmc': really_probe: bound device mmc0:0001 to driver mmcblk > [ 21.688010][ T67] probe of mmc0:0001 returned 0 after 7819 usecs > [ 21.688166][ T1] Waiting for root device /dev/dm-0... > [ 41.023192][ T1] driver_probe_done: probe_count = 0 > ... can't exit from the root wait loop > > * After apply this patch and add dm-mod.waitfor="PARTLABEL=rootfs" > [ 0.368417][ T1] device-mapper: init: waiting for all devices to be available before creating mapped devices > [ 21.672749][ T45] probe of 1c660000.mtk-mmc-fcie returned 0 after 21540992 usecs > [ 21.672767][ T45] mtk_mci 1c660000.mtk-mmc-fcie: driver mtk_mci async attach completed: 0 > [ 21.672774][ T1] device-mapper: init: waiting for device PARTLABEL=rootfs ... > [ 21.672869][ T43] mtk_mci 1c660000.mtk-mmc-fcie: eMMC: HS400 5.1 200MHz > [ 21.679743][ T43] mmc0: new HS400 Enhanced strobe MMC card at address 0001 > [ 21.679852][ T43] bus: 'mmc': __driver_probe_device: matched device mmc0:0001 with driver mmcblk > [ 21.679858][ T43] bus: 'mmc': really_probe: probing driver mmcblk with device mmc0:0001 > [ 21.680204][ T43] mmcblk0: mmc0:0001 016G01 14.5 GiB > [ 21.682866][ T43] mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 > [ 21.685579][ T43] mmcblk0boot0: mmc0:0001 016G01 8.00 MiB > [ 21.686631][ T43] mmcblk0boot1: mmc0:0001 016G01 8.00 MiB > [ 21.687533][ T43] mmcblk0rpmb: mmc0:0001 016G01 4.00 MiB, chardev (238:0) > [ 21.687559][ T43] driver: 'mmcblk': driver_bound: bound to device 'mmc0:0001' > [ 21.687585][ T43] bus: 'mmc': really_probe: bound device mmc0:0001 to driver mmcblk > [ 21.687591][ T43] probe of mmc0:0001 returned 0 after 7732 usecs > [ 21.687838][ T1] device-mapper: init: all devices available <---------------------------------- start after PARTLABEL=rootfs is ready > [ 21.688155][ T1] device-mapper: verity: sha1 using implementation "sha1-generic" > [ 21.688975][ T1] device-mapper: ioctl: dm-0 (dm-verity) is ready > Ok, seems sane, I'll queue this up for 6.1.y and 5.15.y now. thanks, greg k-h
diff --git a/Documentation/admin-guide/device-mapper/dm-init.rst b/Documentation/admin-guide/device-mapper/dm-init.rst index e5242ff17e9b..981d6a907699 100644 --- a/Documentation/admin-guide/device-mapper/dm-init.rst +++ b/Documentation/admin-guide/device-mapper/dm-init.rst @@ -123,3 +123,11 @@ Other examples (per target): 0 1638400 verity 1 8:1 8:2 4096 4096 204800 1 sha256 fb1a5a0f00deb908d8b53cb270858975e76cf64105d412ce764225d53b8f3cfd 51934789604d1b92399c52e7cb149d1b3a1b74bbbcb103b2a0aaacbed5c08584 + +For setups using device-mapper on top of asynchronously probed block +devices (MMC, USB, ..), it may be necessary to tell dm-init to +explicitly wait for them to become available before setting up the +device-mapper tables. This can be done with the "dm-mod.waitfor=" +module parameter, which takes a list of devices to wait for:: + + dm-mod.waitfor=<device1>[,..,<deviceN>] diff --git a/drivers/md/dm-init.c b/drivers/md/dm-init.c index b0c45c6ebe0b..dc4381d68313 100644 --- a/drivers/md/dm-init.c +++ b/drivers/md/dm-init.c @@ -8,6 +8,7 @@ */ #include <linux/ctype.h> +#include <linux/delay.h> #include <linux/device.h> #include <linux/device-mapper.h> #include <linux/init.h> @@ -18,12 +19,17 @@ #define DM_MAX_DEVICES 256 #define DM_MAX_TARGETS 256 #define DM_MAX_STR_SIZE 4096 +#define DM_MAX_WAITFOR 256 static char *create; +static char *waitfor[DM_MAX_WAITFOR]; + /* * Format: dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+] * Table format: <start_sector> <num_sectors> <target_type> <target_args> + * Block devices to wait for to become available before setting up tables: + * dm-mod.waitfor=<device1>[,..,<deviceN>] * * See Documentation/admin-guide/device-mapper/dm-init.rst for dm-mod.create="..." format * details. @@ -266,7 +272,7 @@ static int __init dm_init_init(void) struct dm_device *dev; LIST_HEAD(devices); char *str; - int r; + int i, r; if (!create) return 0; @@ -286,6 +292,17 @@ static int __init dm_init_init(void) DMINFO("waiting for all devices to be available before creating mapped devices"); wait_for_device_probe(); + for (i = 0; i < ARRAY_SIZE(waitfor); i++) { + if (waitfor[i]) { + DMINFO("waiting for device %s ...", waitfor[i]); + while (!dm_get_dev_t(waitfor[i])) + msleep(5); + } + } + + if (waitfor[0]) + DMINFO("all devices available"); + list_for_each_entry(dev, &devices, list) { if (dm_early_create(&dev->dmi, dev->table, dev->target_args_array)) @@ -301,3 +318,6 @@ late_initcall(dm_init_init); module_param(create, charp, 0); MODULE_PARM_DESC(create, "Create a mapped device in early boot"); + +module_param_array(waitfor, charp, NULL, 0); +MODULE_PARM_DESC(waitfor, "Devices to wait for before setting up tables");