Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1657160rwd; Thu, 8 Jun 2023 23:37:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7JCcLT8vs0tv/xdM5gdRtD4oui9JSug35Fn0ZD9rCwKIOYiZK55q9wUBV5y4OxUSIgBDy5 X-Received: by 2002:a05:6808:114f:b0:39a:522c:55c1 with SMTP id u15-20020a056808114f00b0039a522c55c1mr769729oiu.8.1686292628488; Thu, 08 Jun 2023 23:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686292628; cv=none; d=google.com; s=arc-20160816; b=uHf1He8NdCgmkxjbff+23CTHxZSzc3MW2CMFpYdVMhPhCNE8CdIuM7GQ/i8AcEkNlD bh+efWiR3kDZp6A3uanMyd1s4gXmaxVQRU+6W14N+9z+lNFyNx9ykFPdYe7OPRNJ5I/a honaTvSvdvmrkYZaCuSA1aBT2JUpfemZZ2KyfOrveN9NLV1fsiv2emRwvaRwXnUhdk70 Vm23KDTs7SZ8cHuPiMdTG72gS56tfbLYT78KhTlJfgDJpZ7WvyJqRgzTVnMBCQKqt5ZE TDeuKNxc+tediruNynxT7WxYFoulLTH/7m01+8mp6l+FwpdAiHQZy7N4bkRz7mbI0F07 wPQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Bmtdu3k1i1OeXWL8XKff6EKx2D7QZz6gEJ3lO/MRnec=; b=e93lPgq3vH1VxcRIcF9AUOiFNl6bEfwDhrhI54Ufbmo02XftWPJ1T95uIi19jP18hB o8+GawhHn0xUToMJWkMSjIQ3ictmcO8eAiLkJdfyfsJiTkL0HVyaPv2cfyaByBiH7/Uq ArAM5ivL3pH5ap2jn1aSltmUD1lk/oM4fGYiQGSGbHHRXpIUEuLhVSsTTaH5ukNdV/Zc qO2O1V3+mb1cHfQ5mRPxZ4BhSipQMNGz2Ruz3w9WqI/fgSDWQe+Tb7IgztUpmxsPs88U Y0BcuLoYrI/BUFf5EauFHFHf5/IzTW2aIpbdPtdy4i07IlMuSk1OK2iMC7zu9nsFYRMT jQAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tTlMUimO; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a17090a0bc100b0024e33c63ed5si3811607pjd.15.2023.06.08.23.36.55; Thu, 08 Jun 2023 23:37:08 -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=@linuxfoundation.org header.s=korg header.b=tTlMUimO; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236269AbjFIGUB (ORCPT + 99 others); Fri, 9 Jun 2023 02:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237714AbjFIGT5 (ORCPT ); Fri, 9 Jun 2023 02:19:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B31201FE6; Thu, 8 Jun 2023 23:19:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 39FEC61F4D; Fri, 9 Jun 2023 06:19:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22F74C433D2; Fri, 9 Jun 2023 06:19:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686291594; bh=rYenQZcJ00i17NHmowq8OR4nZ3oLcojXfyMw7FepXj0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tTlMUimOBD6RM7QFRTDo/wB8rf6G9d8Z/wZ42CaPO3yJMTu6HX5uZjb6ghGSdpGSf WH927+9XmwqtpCrBvTzTrerP84U+dPjAPisC1I6jMW6cWRvve+3vMe5Zd9EnGAzzST p7IisharJdAwvl6Fc35v1W+wHzZaS/5EVYeDrt/g= Date: Fri, 9 Jun 2023 08:19:51 +0200 From: Greg KH To: Dennis Zhou Cc: Ulf Hansson , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij Subject: Re: [PATCH v2] mmc: inline the first mmc_scan() on mmc_start_host() Message-ID: <2023060930-uphold-collie-3ec5@gregkh> References: <20230329202148.71107-1-dennis@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 08, 2023 at 01:49:00PM -0700, Dennis Zhou wrote: > On Fri, May 12, 2023 at 01:42:51PM +0200, Ulf Hansson wrote: > > + Linus, > > > > Hi Dennis, > > > > On Mon, 3 Apr 2023 at 11:50, Ulf Hansson wrote: > > > > > > On Fri, 31 Mar 2023 at 20:23, Dennis Zhou wrote: > > > > > > > > Hi Ulf, > > > > > > > > On Fri, Mar 31, 2023 at 02:43:10PM +0200, Ulf Hansson wrote: > > > > > On Thu, 30 Mar 2023 at 01:48, Dennis Zhou wrote: > > > > > > > > > > > > When using dm-verity with a data partition on an emmc device, dm-verity > > > > > > races with the discovery of attached emmc devices. This is because mmc's > > > > > > probing code sets up the host data structure then a work item is > > > > > > scheduled to do discovery afterwards. To prevent this race on init, > > > > > > let's inline the first call to detection, __mm_scan(), and let > > > > > > subsequent detect calls be handled via the workqueue. > > > > > > > > > > In principle, I don't mind the changes in $subject patch, as long as > > > > > it doesn't hurt the overall initialization/boot time. Especially, we > > > > > may have more than one mmc-slot being used, so this needs to be well > > > > > tested. > > > > > > > > > > > > > I unfortunately don't have a device with multiple mmcs available. Is > > > > this something you could help me with? > > > > > > Yes, I can help to test. Allow me a few days to see what I can do. > > > > > > Note that, just having one eMMC and one SD card should work too. It > > > doesn't have to be multiple eMMCs. > > > > > > > > > > > > Although, more importantly, I fail to understand how this is going to > > > > > solve the race condition. Any I/O request to an eMMC or SD requires > > > > > the mmc block device driver to be up and running too, which is getting > > > > > probed from a separate module/driver that's not part of mmc_rescan(). > > > > > > > > I believe the call chain is something like this: > > > > > > > > __mmc_rescan() > > > > mmc_rescan_try_freq() > > > > mmc_attach_mmc() > > > > mmc_add_card() > > > > device_add() > > > > bus_probe_device() > > > > mmc_blk_probe() > > > > > > > > The initial calling of this is the host probe. So effectively if there > > > > is a card attached, we're inlining the device_add() call for the card > > > > attached rather than waiting for the workqueue item to kick off. > > > > > > > > dm is a part of late_initcall() while mmc is a module_init(), when built > > > > in becoming a device_initcall(). So this solves a race via the initcall > > > > chain. In the current state, device_initcall() finishes and we move onto > > > > the late_initcall() phase. But now, dm is racing with the workqueue to > > > > init the attached emmc device. > > > > > > You certainly have a point! > > > > > > This should work when the mmc blk module is built-in. Even if that > > > doesn't solve the entire problem, it should be a step in the right > > > direction. > > > > > > I will give it some more thinking and run some tests at my side, then > > > I will get back to you again. > > > > > > Kind regards > > > Uffe > > > > > > > > > > > > > > > > > > > > Signed-off-by: Dennis Zhou > > > > > > --- > > > > > > Sigh.. fix missing static declaration. > > > > > > > > > > > > drivers/mmc/core/core.c | 15 +++++++++++---- > > > > > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > > > > > > > > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > > > > > > index 368f10405e13..fda7ee57dee3 100644 > > > > > > --- a/drivers/mmc/core/core.c > > > > > > +++ b/drivers/mmc/core/core.c > > > > > > @@ -2185,10 +2185,8 @@ int mmc_card_alternative_gpt_sector(struct mmc_card *card, sector_t *gpt_sector) > > > > > > } > > > > > > EXPORT_SYMBOL(mmc_card_alternative_gpt_sector); > > > > > > > > > > > > -void mmc_rescan(struct work_struct *work) > > > > > > +static void __mmc_rescan(struct mmc_host *host) > > > > > > { > > > > > > - struct mmc_host *host = > > > > > > - container_of(work, struct mmc_host, detect.work); > > > > > > int i; > > > > > > > > > > > > if (host->rescan_disable) > > > > > > @@ -2249,6 +2247,14 @@ void mmc_rescan(struct work_struct *work) > > > > > > mmc_schedule_delayed_work(&host->detect, HZ); > > > > > > } > > > > > > > > > > > > +void mmc_rescan(struct work_struct *work) > > > > > > +{ > > > > > > + struct mmc_host *host = > > > > > > + container_of(work, struct mmc_host, detect.work); > > > > > > + > > > > > > + __mmc_rescan(host); > > > > > > +} > > > > > > + > > > > > > void mmc_start_host(struct mmc_host *host) > > > > > > { > > > > > > host->f_init = max(min(freqs[0], host->f_max), host->f_min); > > > > > > @@ -2261,7 +2267,8 @@ void mmc_start_host(struct mmc_host *host) > > > > > > } > > > > > > > > > > > > mmc_gpiod_request_cd_irq(host); > > > > > > - _mmc_detect_change(host, 0, false); > > > > > > + host->detect_change = 1; > > > > > > + __mmc_rescan(host); > > > > > > } > > > > > > > > > > > > void __mmc_stop_host(struct mmc_host *host) > > > > > > -- > > > > > > 2.40.0 > > > > > > > > > > My apologies for the long delay. I finally managed to test this. > > > > I decided to pick an old arm32 based platform. An ST-Ericsson HREF, > > based upon the ux500 SoC. It's quite good to use for these types of > > tests as it has two eMMCs soldered, an embedded SDIO (for WiFi) and an > > SD-card slot. So in total there are 4 devices that get probed. > > > > The SDIO card isn't detected properly, but always fails in the similar > > way (thus I left it out from the below data). I tested both with and > > without an SD card inserted during boot, to get some more data to > > compare. These are the summary from my tests: > > > > v6.4-rc1 without SD card: > > ~2.18s - MMC1 (eMMC) > > ~3.33s - MMC3 (eMMC) > > ~5.91s - kernel boot complete > > > > v6.4-rc1 with an SD card: > > ~2.18s - MMC1 (eMMC) > > ~3.45s - MMC3 (eMMC) > > ~3.57s - MMC2 (SD) > > ~5.76s - kernel boot complete > > > > v6.4-rc1 + patch without SD card: > > ~2.24s - MMC1 (eMMC) > > ~3.58s - MMC3 (eMMC) > > ~5.96s - kernel boot complete > > > > v6.4-rc1 + patch with an SD card: > > ~2.24s - MMC1 (eMMC) > > ~3.73s - MMC2 (SD) > > ~3.98s - MMC3 (eMMC) > > ~6.73s - kernel boot complete > > > > By looking at these results, I was kind of surprised. I was thinking > > that the asynchronous probe should address the parallelism problem. > > Then I discovered that it in fact, hasn't been enabled for the mmci > > driver that is being used for this platform. Huh, I was under the > > assumption that it has been enabled for all mmc hosts by now. :-) > > > > Okay, so I am going to run another round of tests, with async probe > > enabled for the mmci driver too. I will let you know the results as > > soon as I can. > > > > Kind regards > > Uffe > > Hi Uffe, > > Kindly this has been way too long for review. It's been over 3 months. > What's going on here? > > I think there's a misunderstanding too. Without this fix, the machine > doesn't even boot. I'm not sure why perf is the blocking question here. Well you can not degrade performance of existing machines that work today, right? That would be a regression and it seems that you are doing that if I read the numbers above correctly. > Greg, is there another tree I can run this through? Why would you want to route around a maintainer just to get a patch that would have to be reverted applied? :) thanks, greg k-h