linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Xenia Ragiadakou <burzalodowa@gmail.com>,
	Sarah Sharp <sarah.a.sharp@linux.intel.com>,
	USB list <linux-usb@vger.kernel.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: Re: [PATCH] xhci: fix write to USB3_PSSEN and XUSB2PRM pci config registers
Date: Mon, 23 Sep 2013 14:49:07 -0700	[thread overview]
Message-ID: <20130923214907.GA21695@kroah.com> (raw)
In-Reply-To: <CAErSpo7_obVo0nLNBzv7c=ZxPzdzJaDiatDjOfVRS+CbF7rc-A@mail.gmail.com>

On Mon, Sep 23, 2013 at 04:38:22PM -0500, Bjorn Helgaas wrote:
> On Mon, Sep 23, 2013 at 3:49 PM, Greg KH <greg@kroah.com> wrote:
> > On Mon, Sep 23, 2013 at 09:06:54PM +0300, Xenia Ragiadakou wrote:
> >> On 09/23/2013 07:45 PM, Sarah Sharp wrote:
> >> >On Fri, Sep 20, 2013 at 07:45:53PM +0300, Xenia Ragiadakou wrote:
> >> >>The function pci_write_config_dword() sets the appropriate byteordering
> >> >>internally so the value argument should not be converted to little-endian.
> >> >>This bug was found by sparse.
> >> >Can you give the exact error or warning message that sparse gave?
> >>
> >> Yes, sure.
> >>
> >> drivers/usb/host/pci-quirks.c:802:25: warning: incorrect type in
> >> argument 3 (different base types)
> >> drivers/usb/host/pci-quirks.c:802:25:    expected unsigned int
> >> [unsigned] [usertype] val
> >> drivers/usb/host/pci-quirks.c:802:25:    got restricted __le32
> >> [usertype] <noident>
> >> drivers/usb/host/pci-quirks.c:824:25: warning: incorrect type in
> >> argument 3 (different base types)
> >> drivers/usb/host/pci-quirks.c:824:25:    expected unsigned int
> >> [unsigned] [usertype] val
> >> drivers/usb/host/pci-quirks.c:824:25:    got restricted __le32
> >> [usertype] <noident>
> >>
> >> >
> >> >I ask because this description sounded odd to Greg and I when we met
> >> >last week at LinuxCon North America.  I've tried to track this down to
> >> >see where the code might be converting the value from CPU format to
> >> >little endian, and I don't see it.
> >> >
> >> >AFAICT, pci_write_config_dword() is defined in include/linux/pci.h, and
> >> >calls pci_bus_write_config_dword():
> >> >
> >> >static inline int pci_write_config_dword(const struct pci_dev *dev, int where,
> >> >                                          u32 val)
> >> >{
> >> >         return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
> >> >}
> >> >
> >> >pci_bus_write_config_dword is defined as a macro in drivers/pci/access.h:
> >> >
> >> >#define PCI_OP_WRITE(size,type,len) \
> >> >int pci_bus_write_config_##size \
> >> >         (struct pci_bus *bus, unsigned int devfn, int pos, type value)  \
> >> >{                                                                       \
> >> >         int res;                                                        \
> >> >         unsigned long flags;                                            \
> >> >         if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER;       \
> >> >         raw_spin_lock_irqsave(&pci_lock, flags);                        \
> >> >         res = bus->ops->write(bus, devfn, pos, len, value);             \
> >> >         raw_spin_unlock_irqrestore(&pci_lock, flags);           \
> >> >         return res;                                                     \
> >> >}
> >> >
> >> >That macro simply calls the write function for whatever PCI bus driver
> >> >is installed.  Note that bus driver can be different than the standard
> >> >bus driver.  I don't see any conversion to little endian here, so that
> >> >means each bus driver would have to convert it.
> >> >
> >> >I can dig deeper into each .write function, but if the conversion isn't
> >> >done at the upper layers, it's possible someone will create a .write
> >> >function without the conversion to little endian.
> >> >
> >> >Am I missing something?
> >>
> >> I had in mind that the pci_ops .read and .write defined by the PCI
> >> driver will take care of consistent byteorder access to the
> >> configuration registers. At least, that was what i understood after
> >> reading the
> >> chapter on PCI of Linux Device Drivers (more specifically for
> >> pci_write_config_* functions, it states that "The word and dword
> >> functions convert the value to little-endian before writing to the
> >> peripheral device.").
> >
> > Hm, I wrote that paragraph (or at least I think I did), but I sure
> > didn't remember this at all...
> >
> > Hm, wait, I do see this happening for the PowerPC cell PCI code, so it
> > might happen somewhere burried in the platform-specific code for
> > different arches.  You will not see it happen on x86 as there's no need
> > to swap any bytes around.
> 
> Greg, with regard to Xenia's patch, is this an ack or a nack?  Since
> you didn't include an "Acked-by" line, I assume you think Xenia's
> patch is unnecessary.  In that case, is there any way to shut sparse
> up so it doesn't complain about this?

At this point in time, I don't remember what the original patch looked
like, and as it's an xhci patch, Sarah needs to ack it, not me :)

thanks,

greg k-h

  reply	other threads:[~2013-09-23 21:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1379695553-5891-1-git-send-email-burzalodowa@gmail.com>
2013-09-23 16:45 ` [PATCH] xhci: fix write to USB3_PSSEN and XUSB2PRM pci config registers Sarah Sharp
2013-09-23 18:06   ` Xenia Ragiadakou
2013-09-23 20:49     ` Greg KH
2013-09-23 21:38       ` Bjorn Helgaas
2013-09-23 21:49         ` Greg KH [this message]
2013-09-24  0:23           ` Sarah Sharp
2013-09-24  3:01             ` Greg KH

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=20130923214907.GA21695@kroah.com \
    --to=greg@kroah.com \
    --cc=bhelgaas@google.com \
    --cc=burzalodowa@gmail.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sarah.a.sharp@linux.intel.com \
    --cc=stern@rowland.harvard.edu \
    /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;
as well as URLs for NNTP newsgroup(s).