Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1828477pxb; Fri, 5 Feb 2021 02:28:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLNYNt7lZb+oL4KmzCvV5JeXvENBzGfrcMgtLVhqUKS4NRye1qsvRKM9yQWauSwTfA4UWo X-Received: by 2002:a17:906:d118:: with SMTP id b24mr3406350ejz.457.1612520891256; Fri, 05 Feb 2021 02:28:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612520891; cv=none; d=google.com; s=arc-20160816; b=rFtKpDtuG1k6i2oyjaMK4AfS8H3ilZsE0emOpMPz9HDCm6TrBOJG3pKrZRezD+JKJD UmxSEcuPDs6tls7+7qa+p0ifB4llVK1Rqm7hukTyox3IofyIIMDGmE6LI+vKL3Mr+QPA pkY5E+PQBWFL2OK8jXizMClJC6lPSCLUtSeMAY9n0hstAF/JtRFGzZIT8wmpvLVUkzxW EwxC+laO7gyh2xKac2dft9do9a/u94tWcdtFLqe0QR9mUEmfINNK3QhW5j+zkh20i3RT 7TVy/dcQPnEcKloyWoa/rRu3/ITCew4tpbh46eBxaPM5dpWB8kcd23oQSKPi4Dk9y3Tq D+/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=2yuIYIxM1r0vjPBHPxM2y+AxnaXi3F039H0I6fPXB2Y=; b=t0KCm90IdZApDyeTnZdrSQ0BTDNGNhKLmgg5XzJYW5UoFWmHgnNQY9lDeyoLidf5Ex ErdUwDZJpsomMXk4MLPySDBZ8tIGXwXrk4xv9Grdfad9aFJwk3YyUEx+7yTkVFWDXQ9/ jOYv58eCIPh2/+lUam8VA6JAeTl10+fpWOJMWondp3/kT3DCXF5Vf5WLrkLIk52/6Xz0 2YkGUXXtUtEJ0bo4DoXSImgGZmt5nLAEPycGMzr2Z7tI+uv5KBHX1M5M5zLU1lm3hour Gyw+0F8UA5zdVz/7O932/12rI4IsaabwLogwP7L9Yp/+sA21LcLe4a6Wvx0VG7rcSy4t T3aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=A9phunMo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si4927730ejw.275.2021.02.05.02.27.46; Fri, 05 Feb 2021 02:28:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=A9phunMo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231253AbhBEK0Q (ORCPT + 99 others); Fri, 5 Feb 2021 05:26:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbhBEKSI (ORCPT ); Fri, 5 Feb 2021 05:18:08 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEE3DC061793 for ; Fri, 5 Feb 2021 02:16:11 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id u66so4981846oig.9 for ; Fri, 05 Feb 2021 02:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=2yuIYIxM1r0vjPBHPxM2y+AxnaXi3F039H0I6fPXB2Y=; b=A9phunMoX2b9Gt5n9T0V20jIQdwPW9aWuFUt+j26fGARowppocLfwynGYKZKR1TvHP oDYM6GO84zr2GTWpNTRjpDKbTn3MIDB8fM+hrnpLGfiUf/l+iVMugdoRIPgQX8kZ1Hta jlDlzgJ4kNiRVRoNbZAav0p3u3jbhCwhdDh2k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=2yuIYIxM1r0vjPBHPxM2y+AxnaXi3F039H0I6fPXB2Y=; b=L/dvkCJwioBEUqB+c9OFHBf89PtepDYinvDRFW5wxluRcWkUcPGHCQgGrldG9ZE1hl i5WXSEv4FXjAUTZPfEpUCw7168hWmiMWuTbZNkUBEr8W0g+vXLiP+FT2t4ppScizGPu4 nPjyhFF0maHy1rZXp+jpmwbR5MjXQfAFamGnHY+ZfZf3Ws+4HWAZ+pw4TZV90p9g3Dma 5N0PUbpibnOh1VpDxxZ+So+2Mz2KQabg4IZLIyuCcIdPs2IN/FUYDoBq/8U2Ydw97wYN iEK4/w/joDnPXN3urCIC3buEJXiKfbKY3EpRFTrKN/KF8i0+U4ul3546xoJG404lwIwc 8s2A== X-Gm-Message-State: AOAM531Hedgb2Z85pACkr0JA+hZrRO2u+C7i0s8t7AqcrTODFs4Hfzjs SB9nQ6eOYNUB9oFzqCm7btA++qyFlpm/brljdU/ysg== X-Received: by 2002:aca:df42:: with SMTP id w63mr2582638oig.128.1612520171119; Fri, 05 Feb 2021 02:16:11 -0800 (PST) MIME-Version: 1.0 References: <20210204165831.2703772-2-daniel.vetter@ffwll.ch> <20210204215019.GA104698@bjorn-Precision-5520> <20210204222407.pkx7wvmcvugdwqdd@pali> <20210205100449.w2vzqozgnolxqh4h@pali> In-Reply-To: <20210205100449.w2vzqozgnolxqh4h@pali> From: Daniel Vetter Date: Fri, 5 Feb 2021 11:16:00 +0100 Message-ID: Subject: Re: [PATCH 1/2] PCI: also set up legacy files only after sysfs init To: =?UTF-8?Q?Pali_Roh=C3=A1r?= Cc: Bjorn Helgaas , LKML , Stephen Rothwell , linux-samsung-soc , Jan Kara , Kees Cook , Greg Kroah-Hartman , Linux PCI , Linux MM , Jason Gunthorpe , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Bjorn Helgaas , Daniel Vetter , Dan Williams , Andrew Morton , Linux ARM , "open list:DMA BUFFER SHARING FRAMEWORK" , "Oliver O'Halloran" , =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 5, 2021 at 11:04 AM Pali Roh=C3=A1r wrote: > > On Friday 05 February 2021 10:59:50 Daniel Vetter wrote: > > On Thu, Feb 4, 2021 at 11:24 PM Pali Roh=C3=A1r wrote= : > > > > > > On Thursday 04 February 2021 15:50:19 Bjorn Helgaas wrote: > > > > [+cc Oliver, Pali, Krzysztof] > > > > > > Just to note that extending or using sysfs_initialized introduces > > > another race condition into kernel code which results in PCI fatal > > > errors. Details are in email discussion which Bjorn already sent. > > > > Yeah I wondered why this doesn't race. > > It races, but with smaller probability. I have not seen this race > condition on x86. But I was able to reproduce it with native PCIe > drivers on ARM64 (Marvell Armada 3720; pci-aardvark). In mentioned > discussion I wrote when this race condition happen. But I understand > that it is hard to simulate it. btw I looked at your patch, and isn't that just reducing the race window? I think we have a very similar problem in drm, where the drm_dev_register() for the overall device (which also registers all drm_connector) can race with the hotplug of an individual connector in drm_connector_register() which is hotplugged at runtime. I went with a per-connector registered boolean + a lock to make sure that really only one of the two call paths can end up registering the connector. Part of registering connectors is setting up sysfs files, so I think it's exactly the same problem as here. Cheers, Daniel > > > but since the history goes back > > to pre-git times I figured it would have been addressed somehow > > already if it indeed does race. > > -Daniel > > > > > > s/also/Also/ in subject > > > > > > > > On Thu, Feb 04, 2021 at 05:58:30PM +0100, Daniel Vetter wrote: > > > > > We are already doing this for all the regular sysfs files on PCI > > > > > devices, but not yet on the legacy io files on the PCI buses. Thu= s far > > > > > now problem, but in the next patch I want to wire up iomem revoke > > > > > support. That needs the vfs up an running already to make so that > > > > > iomem_get_mapping() works. > > > > > > > > s/now problem/no problem/ > > > > s/an running/and running/ > > > > s/so that/sure that/ ? > > > > > > > > iomem_get_mapping() doesn't exist; I don't know what that should be= . > > > > > > > > > Wire it up exactly like the existing code. Note that > > > > > pci_remove_legacy_files() doesn't need a check since the one for > > > > > pci_bus->legacy_io is sufficient. > > > > > > > > I'm not sure exactly what you mean by "the existing code." I could > > > > probably figure it out, but it would save time to mention the exist= ing > > > > function here. > > > > > > > > This looks like another instance where we should really apply Olive= r's > > > > idea of converting these to attribute_groups [1]. > > > > > > > > The cover letter mentions options discussed with Greg in [2], but I > > > > don't think the "sysfs_initialized" hack vs attribute_groups was pa= rt > > > > of that discussion. > > > > > > > > It's not absolutely a show-stopper, but it *is* a shame to extend t= he > > > > sysfs_initialized hack if attribute_groups could do this more clean= ly > > > > and help solve more than one issue. > > > > > > > > Bjorn > > > > > > > > [1] https://lore.kernel.org/r/CAOSf1CHss03DBSDO4PmTtMp0tCEu5kScn704= ZEwLKGXQzBfqaA@mail.gmail.com > > > > [2] https://lore.kernel.org/dri-devel/CAKMK7uGrdDrbtj0OyzqQc0CGrQwc= 2F3tFJU9vLfm2jjufAZ5YQ@mail.gmail.com/ > > > > > > > > > Signed-off-by: Daniel Vetter > > > > > Cc: Stephen Rothwell > > > > > Cc: Jason Gunthorpe > > > > > Cc: Kees Cook > > > > > Cc: Dan Williams > > > > > Cc: Andrew Morton > > > > > Cc: John Hubbard > > > > > Cc: J=C3=A9r=C3=B4me Glisse > > > > > Cc: Jan Kara > > > > > Cc: Dan Williams > > > > > Cc: Greg Kroah-Hartman > > > > > Cc: linux-mm@kvack.org > > > > > Cc: linux-arm-kernel@lists.infradead.org > > > > > Cc: linux-samsung-soc@vger.kernel.org > > > > > Cc: linux-media@vger.kernel.org > > > > > Cc: Bjorn Helgaas > > > > > Cc: linux-pci@vger.kernel.org > > > > > --- > > > > > drivers/pci/pci-sysfs.c | 7 +++++++ > > > > > 1 file changed, 7 insertions(+) > > > > > > > > > > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c > > > > > index fb072f4b3176..0c45b4f7b214 100644 > > > > > --- a/drivers/pci/pci-sysfs.c > > > > > +++ b/drivers/pci/pci-sysfs.c > > > > > @@ -927,6 +927,9 @@ void pci_create_legacy_files(struct pci_bus *= b) > > > > > { > > > > > int error; > > > > > > > > > > + if (!sysfs_initialized) > > > > > + return; > > > > > + > > > > > b->legacy_io =3D kcalloc(2, sizeof(struct bin_attribute), > > > > > GFP_ATOMIC); > > > > > if (!b->legacy_io) > > > > > @@ -1448,6 +1451,7 @@ void pci_remove_sysfs_dev_files(struct pci_= dev *pdev) > > > > > static int __init pci_sysfs_init(void) > > > > > { > > > > > struct pci_dev *pdev =3D NULL; > > > > > + struct pci_bus *pbus =3D NULL; > > > > > int retval; > > > > > > > > > > sysfs_initialized =3D 1; > > > > > @@ -1459,6 +1463,9 @@ static int __init pci_sysfs_init(void) > > > > > } > > > > > } > > > > > > > > > > + while ((pbus =3D pci_find_next_bus(pbus))) > > > > > + pci_create_legacy_files(pbus); > > > > > + > > > > > return 0; > > > > > } > > > > > late_initcall(pci_sysfs_init); > > > > > -- > > > > > 2.30.0 > > > > > > > > > > > > > > > _______________________________________________ > > > > > linux-arm-kernel mailing list > > > > > linux-arm-kernel@lists.infradead.org > > > > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > > > > > > > > -- > > Daniel Vetter > > Software Engineer, Intel Corporation > > http://blog.ffwll.ch --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch