public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: platform-driver-x86@vger.kernel.org,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Lukas Wunner" <lukas@wunner.de>,
	linux-pci@vger.kernel.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH v1] platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe
Date: Thu, 21 Dec 2023 18:52:26 +0200	[thread overview]
Message-ID: <ZYRtSuo1yLKyJASP@smile.fi.intel.com> (raw)
In-Reply-To: <20231221093936.1523908-1-shinichiro.kawasaki@wdc.com>

On Thu, Dec 21, 2023 at 06:39:36PM +0900, Shin'ichiro Kawasaki wrote:
> p2sb_bar() unhides P2SB device to get resources from the device. It
> guards the operation by locking pci_rescan_remove_lock so that parallel
> rescans do not find the P2SB device. However, this lock causes deadlock
> when PCI bus rescan is triggered by /sys/bus/pci/rescan. The rescan
> locks pci_rescan_remove_lock and probes PCI devices. When PCI devices
> call p2sb_bar() during probe, it locks pci_rescan_remove_lock again.
> Hence the deadlock.
> 
> To avoid the deadlock, do not lock pci_rescan_remove_lock in p2sb_bar().
> Instead, do the lock at fs_initcall. Introduce p2sb_cache_resources()
> for fs_initcall which gets and caches the P2SB resources. At p2sb_bar(),
> refer the cache and return to the caller.

Thank you for the update!
My comments below.

...

> +/*
> + * Cache BAR0 of P2SB device functions 0 to 7
> + * TODO: Move this definition to pci.h together with same other definitions

Missing periods at the end of sentences.

> + */
> +#define NR_P2SB_RES_CACHE 8

...

> +static bool p2sb_valid_resource(struct resource *res)
> +{
> +	return res->flags;
> +}

So, now if you look at this, there is no point in having the function.
But see below.

...

> +	if (!p2sb_valid_resource(pci_resource_n(pdev, 0)))
> +		return -ENOENT;

As per above (i.e. see below).

...

> +	ret = p2sb_scan_and_cache_devfn(bus, devfn);
> +	if (ret || PCI_FUNC(devfn) != 0)
> +		return ret;

This hides the fact that we don't scan functions if P2SB is not 0.

	if (ret)
		return ret;

	/* ...add a comment like above... */
	if (PCI_FUNC(devfn) != 0)
		return 0;


> +	/*
> +	 * When function number of the P2SB device is zero, scan other function

The first part will become the comment above. So, you may drop it from here.

> +	 * numbers. If devices are available, cache their BAR0.
> +	 */

...

> +		pci_bus_write_config_dword(p2sb_bus, devfn_p2sb, P2SBC,
> +					   P2SBC_HIDE);

Having it on one line is fine.

...

> +	if (!bus)
> +		bus = p2sb_bus;

Hmm... Maybe

static struct pci_bus *p2sb_get_bus(bus)
{
	static struct pci_bus *p2sb_bus;

	bus = bus ?: p2sb_bus;
	if (bus)
		return bus;

	p2sb_bus = ...;
	return p2sb_bus;
}

?

...

> +	if (!devfn) {

Maybe move this check to the callee?

> +		ret = p2sb_get_devfn(&devfn);
> +		if (ret)
> +			return ret;
> +	}

...

> +	cache = &p2sb_resources[PCI_FUNC(devfn)];
> +	if (!p2sb_valid_resource(&cache->res) ||
> +	    cache->bus_dev_id != bus->dev.id)
>  		return -ENODEV;

I don't remember if I mentioned in the last email(s), but I think what you want is

static int p2sb_valid_resource(struct resource *res)
{
	return res->flags ? 0 : -ENOENT;
}
	...
	cache = &p2sb_resources[PCI_FUNC(devfn)];
	if (cache->bus_dev_id != bus->dev.id)
		return -ENODEV;

	ret = p2sb_valid_resource(&cache->res);
	if (ret)
		return ret;

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-12-21 16:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21  9:39 [PATCH v1] platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe Shin'ichiro Kawasaki
2023-12-21 16:52 ` Andy Shevchenko [this message]
2023-12-22  4:20   ` Shinichiro Kawasaki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZYRtSuo1yLKyJASP@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=shinichiro.kawasaki@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox