From: Dave Airlie <airlied@gmail.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Tiago Vignatti <tiago.vignatti@nokia.com>,
Jesse Barnes <jbarnes@virtuousgeek.org>,
Dave Airlie <airlied@redhat.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] vga: implements VGA arbitration on Linux
Date: Thu, 16 Jul 2009 14:25:55 +1000 [thread overview]
Message-ID: <21d7e9970907152125i52dc3f4dqd540f7d65667cfb5@mail.gmail.com> (raw)
In-Reply-To: <20090714153509.51bbec27@lxorguk.ukuu.org.uk>
Hi Alan,
some hopeful answers,
On Wed, Jul 15, 2009 at 12:35 AM, Alan Cox<alan@lxorguk.ukuu.org.uk> wrote:
>> +#ifndef __ARCH_HAS_VGA_ENABLE_RESOURCES
>> +static inline void vga_enable_resources(struct pci_dev *pdev,
>> + unsigned int rsrc)
>> +{
>> + struct pci_bus *bus;
>> + struct pci_dev *bridge;
>> + u16 cmd;
>> +
>> +#ifdef DEBUG
>> + printk(KERN_DEBUG "%s\n", __func__);
>> +#endif
>> + pci_read_config_word(pdev, PCI_COMMAND, &cmd);
>> + if (rsrc & (VGA_RSRC_LEGACY_IO | VGA_RSRC_NORMAL_IO))
>> + cmd |= PCI_COMMAND_IO;
>> + if (rsrc & (VGA_RSRC_LEGACY_MEM | VGA_RSRC_NORMAL_MEM))
>> + cmd |= PCI_COMMAND_MEMORY;
>> + pci_write_config_word(pdev, PCI_COMMAND, cmd);
>
> Locking question - what locks this lot against hotplug also touching
> bridge settings ?
well here we just bang on device config space registers which means we
can probably
race against lots of other things that rmw the PCI_COMMAND not just hotplug.
Perhaps we need some sort per device PCI command space lock,
granted this still means we race against anyone directly hacking it
behind our backs.
As for the bridge settings, it sounds like we need to have a per
bridge pci spinlock
if hotplug is also doing this.
>
>
>> + /* The one who calls us should check for this, but lets be sure... */
>> + if (pdev == NULL)
>> + pdev = vga_default_device();
>
> What if the BIOS provided device was hot unplugged ?
we just use the pdev as a cookie, if it was hot unplugged we'll
have gotten a callback to remove it from the VGA device list
and the lookup which happens 5 lines later inside the spinlock
will fail.
>
>> + conflict = __vga_tryget(vgadev, rsrc);
>> + spin_unlock_irqrestore(&vga_lock, flags);
>> + if (conflict == NULL)
>> + break;
>> +
>> +
>> + /* We have a conflict, we wait until somebody kicks the
>> + * work queue. Currently we have one work queue that we
>
> If two drivers own half the resources and both are waiting for the rest
> what handles the deadlock
>
>> + * kick each time some resources are released, but it would
>> + * be fairly easy to have a per device one so that we only
>> + * need to attach to the conflicting device
>> + */
>> + init_waitqueue_entry(&wait, current);
>> + add_wait_queue(&vga_wait_queue, &wait);
>> + set_current_state(interruptible ?
>> + TASK_INTERRUPTIBLE :
>> + TASK_UNINTERRUPTIBLE);
>> + if (signal_pending(current)) {
>> + rc = -EINTR;
>> + break;
>> + }
>> + schedule();
>> + remove_wait_queue(&vga_wait_queue, &wait);
>> + set_current_state(TASK_RUNNING);
>
> Seems a very long winded way to write
>
> wait_event_interruptible(...)
Is it? it looks close to wait_event_interruptible(vga_wait_queue, 1);
maybe __wait_even_interruptible(vga_wait_queue, 1)
maybe we can restructure the whole locking above to make it
more like a simple condition.
>
>
>> + /* Allocate structure */
>> + vgadev = kmalloc(sizeof(struct vga_device), GFP_KERNEL);
>> + if (vgadev == NULL) {
>> + /* What to do on allocation failure ? For now, let's
>> + * just do nothing, I'm not sure there is anything saner
>> + * to be done
>> + */
>
> If this is an "oh dear" moment then at least printk something
>
Cool, fixed that one.
>>
>> + /* Set the client' lists of locks */
>> + priv->target = vga_default_device(); /* Maybe this is still null! */
>
> PCI device refcounting ?
Again its just used a cookie for a later lookup in our vgadev array,
its gone away it'll have been removed from the array,
We could use pci_dev_get/pci_dev_put I suppose but its only used as
a cookie so far.
Dave.
next prev parent reply other threads:[~2009-07-16 4:26 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-14 12:57 [PATCH 0/2] VGA arbiter implementation Tiago Vignatti
2009-07-14 12:57 ` [PATCH 1/2] vga: implements VGA arbitration on Linux Tiago Vignatti
2009-07-14 12:57 ` [PATCH 2/2] vga: drops a documentation regarding the VGA arbiter Tiago Vignatti
2009-07-18 11:48 ` Pavel Machek
2009-07-19 18:50 ` Vignatti Tiago (Nokia-D/Helsinki)
2009-07-14 14:35 ` [PATCH 1/2] vga: implements VGA arbitration on Linux Alan Cox
2009-07-15 4:43 ` Dave Airlie
2009-07-16 4:25 ` Dave Airlie [this message]
2009-07-16 8:48 ` Alan Cox
2009-07-16 10:38 ` Dave Airlie
2009-07-16 16:25 ` Jesse Barnes
2009-07-17 0:22 ` Benjamin Herrenschmidt
2009-07-17 0:20 ` Benjamin Herrenschmidt
2009-07-17 5:00 ` Dave Airlie
2009-07-17 5:12 ` Benjamin Herrenschmidt
2009-07-14 16:15 ` Greg KH
2009-07-16 3:54 ` Dave Airlie
2009-07-16 4:02 ` Greg KH
2009-07-16 4:06 ` Dave Airlie
2009-07-16 8:41 ` Alan Cox
2009-07-17 0:24 ` Benjamin Herrenschmidt
2009-07-17 0:23 ` Benjamin Herrenschmidt
2009-07-18 11:47 ` Pavel Machek
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=21d7e9970907152125i52dc3f4dqd540f7d65667cfb5@mail.gmail.com \
--to=airlied@gmail.com \
--cc=airlied@redhat.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=jbarnes@virtuousgeek.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=tiago.vignatti@nokia.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
all inboxes | Powered by JetHome®