mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yijing Wang <wangyijing@huawei.com>
To: Oliver Neukum <oneukum@suse.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	<linux-kernel@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	Hanjun Guo <guohanjun@huawei.com>
Subject: Re: [PATCH part1 v5 5/7] PCI: Add pci_dummy_ops to isolate pci device temporarily
Date: Tue, 11 Feb 2014 09:49:53 +0800	[thread overview]
Message-ID: <52F981C1.8010706@huawei.com> (raw)
In-Reply-To: <1392026834.2082.10.camel@linux-fkkt.site>

>>>> +	spin_lock_irqsave(&pci_freeze_lock, flags);
>>>> +	ops = pci_bus_set_ops(bus, &pci_dummy_ops);
>>>> +	bus->save_ops = ops;
>>>> +	spin_unlock_irqrestore(&pci_freeze_lock, flags);
>>>
>>> Against what exactly are you locking here?
>>
>> I want to use this spin lock to serialize freeze device and unfreeze device.
> 
> Yes, but against what? I am sorry I should have been more explicit.
> You are using these functions only in pci_scan_single_device()


Hi Oliver, thanks very much for your detailed analysis. My original intention to use
pci_freeze_lock to serialize pci_bus_freeze_device() and pci_bus_unfreeze_device(),
because I think these two functions maybe used in other places, although currently
only used in pci_scan_single_device().
Like:

CPU A         					         CPU B
pci_bus_freeze_device()                                pci_bus_unfreeze_device()
  pci_bus_set_ops(bus, &pci_dummy_ops);
  							 pci_bus_set_ops(bus, bus->save_ops);   ---> here, save_ops is NULL, it's bad.
  bus->save_ops = ops;


> 
> 
> CPU A					CPU B
> pci_bus_freeze_device()			wait
> bus->save_ops = ops {valid}		wait
> ...					pci_bus_freeze_device()
> wait					bus->save_ops = ops
> 					{pci_dummy_ops !}
> pci_bus_unfreeze_device()		wait
> pci_bus_set_ops(bus, bus->save_ops)
> 
> You see the problem?
> 

Yes, this is a issue, good catch. I should add a refcount to avoid this situation.

> If this function ever races with itself, the locking is useless.
> If it doesn't race with itself, the locking is not needed.
> If this function can really race with itself, you need a refcount
> for freezing.

Thanks again!




> 
> 
> 
> .
> 


-- 
Thanks!
Yijing


  reply	other threads:[~2014-02-11  1:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-10  4:04 [PATCH part1 v5 0/7] Introduce PCIe Device Serial Number capability support Yijing Wang
2014-02-10  4:04 ` [PATCH part1 v5 1/7] PCI: rework pci_find_next_ext_capability() Yijing Wang
2014-02-10  4:04 ` [PATCH part1 v5 2/7] PCI: introduce pci_bus_find_ext_capability() Yijing Wang
2014-02-10  4:04 ` [PATCH part1 v5 3/7] PCI: Add support for Device Serial Number capability Yijing Wang
2014-02-10 10:21   ` Oliver Neukum
2014-02-11  1:55     ` Yijing Wang
2014-02-10  4:04 ` [PATCH part1 v5 4/7] PCI: Introduce pci_serial_number_changed() Yijing Wang
2014-02-10  4:04 ` [PATCH part1 v5 5/7] PCI: Add pci_dummy_ops to isolate pci device temporarily Yijing Wang
2014-02-10  6:56   ` Oliver Neukum
2014-02-10  7:59     ` Yijing Wang
2014-02-10 10:07       ` Oliver Neukum
2014-02-11  1:49         ` Yijing Wang [this message]
2014-02-10  4:04 ` [PATCH part1 v5 6/7] PCI: Check pci device serial number when scan device Yijing Wang
2014-02-10  4:04 ` [PATCH part1 v5 7/7] PCI: pciehp: Don't enable/disable slot on resume unless status changed Yijing Wang

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=52F981C1.8010706@huawei.com \
    --to=wangyijing@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=guohanjun@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=oneukum@suse.de \
    /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

all inboxes | Powered by JetHome®