public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Taku Izumi <izumi.taku@jp.fujitsu.com>
Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, acme@kernel.org,
	hpa@zytor.com, x86@kernel.org
Subject: Re: [PATCH v3] perf, x86: Fix multi-segment problem of perf_event_intel_uncore
Date: Thu, 10 Sep 2015 12:23:22 +0200	[thread overview]
Message-ID: <20150910102322.GV3644@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1441301316-17789-1-git-send-email-izumi.taku@jp.fujitsu.com>

On Fri, Sep 04, 2015 at 02:28:36AM +0900, Taku Izumi wrote:

> +struct pci2phy_map *__find_pci2phy_map(int segment)
> +{
> +	struct pci2phy_map *map;
> +
> +	lockdep_assert_held(&pci2phy_map_lock);
> +
> +	list_for_each_entry(map, &pci2phy_map_head, list) {
> +		if (map->segment == segment)
> +			return map;
> +	}
> +
> +	map = kmalloc(sizeof(struct pci2phy_map), GFP_ATOMIC);

So Ingo would really rather you didn't add a GFP_ATOMIC here; they are
rather fragile.

  http://lkml.kernel.org/r/20150901113147.GA11161@gmail.com

I figured you'd come up with something... :/

> +	if (map) {
> +		map->segment = segment;
> +		list_add_tail(&map->list, &pci2phy_map_head);
> +	}
> +
> +	return map;
> +}


Something like this might work; but please consider it carefully,
because I certainly didn't.

struct pci2phy_map *__find_pci2phy_map(int segment)
{
	struct pci2phy_map *map, *alloc = NULL;

	lockdep_assert_held(&pci2phy_map_lock);

retry:
	list_for_each_entry(map, &pci2phy_map_head, list) {
		if (map->segment == segment)
			goto done;
	}

	if (!alloc) {
		raw_spin_unlock(&pci2phy_map_lock);
		alloc = kmalloc(sizeof(struct pci2phy_map), GFP_KERNEL);
		raw_spin_lock(&pci2phy_map_lock);

		if (alloc)
			goto retry;

		return NULL;
	} else {
		map = alloc;
		alloc = NULL;
	}

	map->segment = segment;
	list_add_tail(&map->list, &pci2phy_map_head);

done:
	if (alloc)
		kfree(alloc);

	return map;
}


> @@ -1106,16 +1107,26 @@ static int snbep_pci2phy_map_init(int devid)
>  		err = pci_read_config_dword(ubox_dev, 0x54, &config);
>  		if (err)
>  			break;
> +
> +		segment = pci_domain_nr(ubox_dev->bus);
> +		raw_spin_lock(&pci2phy_map_lock);
> +		map = __find_pci2phy_map(segment);
> +		if (!map) {
> +			err = -ENOMEM;
> +			break;

And here you leak the lock..

> +		}
> +
>  		/*
>  		 * every three bits in the Node ID mapping register maps
>  		 * to a particular node.
>  		 */
>  		for (i = 0; i < 8; i++) {
>  			if (nodeid == ((config >> (3 * i)) & 0x7)) {
> -				uncore_pcibus_to_physid[bus] = i;
> +				map->pbus_to_physid[bus] = i;
>  				break;
>  			}
>  		}
> +		raw_spin_unlock(&pci2phy_map_lock);
>  	}

      reply	other threads:[~2015-09-10 10:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-03 17:28 [PATCH v3] perf, x86: Fix multi-segment problem of perf_event_intel_uncore Taku Izumi
2015-09-10 10:23 ` Peter Zijlstra [this message]

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=20150910102322.GV3644@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=hpa@zytor.com \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=x86@kernel.org \
    /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