diff mbox

xen-pciback: relax BAR sizing write value check

Message ID 59C8D3DD020000780017F39A@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich Sept. 25, 2017, 8:01 a.m. UTC
Just like done in d2bd05d88d ("xen-pciback: return proper values during
BAR sizing") for the ROM BAR, ordinary ones also shouldn't compare the
written value directly against ~0, but consider the r/o bits at the
bottom (if any).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
 drivers/xen/xen-pciback/conf_space_header.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Roger Pau Monné Sept. 25, 2017, 11:27 a.m. UTC | #1
On Mon, Sep 25, 2017 at 08:01:01AM +0000, Jan Beulich wrote:
> Just like done in d2bd05d88d ("xen-pciback: return proper values during
> BAR sizing") for the ROM BAR, ordinary ones also shouldn't compare the
> written value directly against ~0, but consider the r/o bits at the
> bottom (if any).
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.
diff mbox

Patch

--- 4.14-rc2/drivers/xen/xen-pciback/conf_space_header.c
+++ 4.14-rc2-xen-pciback-BAR-sizing/drivers/xen/xen-pciback/conf_space_header.c
@@ -169,6 +169,9 @@  static int rom_write(struct pci_dev *dev
 static int bar_write(struct pci_dev *dev, int offset, u32 value, void *data)
 {
 	struct pci_bar_info *bar = data;
+	unsigned int pos = (offset - PCI_BASE_ADDRESS_0) / 4;
+	const struct resource *res = dev->resource;
+	u32 mask;
 
 	if (unlikely(!bar)) {
 		pr_warn(DRV_NAME ": driver data not found for %s\n",
@@ -179,7 +182,13 @@  static int bar_write(struct pci_dev *dev
 	/* A write to obtain the length must happen as a 32-bit write.
 	 * This does not (yet) support writing individual bytes
 	 */
-	if (value == ~0)
+	if (res[pos].flags & IORESOURCE_IO)
+		mask = ~PCI_BASE_ADDRESS_IO_MASK;
+	else if (pos && (res[pos - 1].flags & IORESOURCE_MEM_64))
+		mask = 0;
+	else
+		mask = ~PCI_BASE_ADDRESS_MEM_MASK;
+	if ((value | mask) == ~0U)
 		bar->which = 1;
 	else {
 		u32 tmpval;