Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1430502 > unrolled thread

[PATCH v3 1/2] xen-pciback: return proper values during BAR sizing

Started by"Jan Beulich" <JBeulich@suse.com>
First post2016-06-24 11:20 +0200
Last post2016-06-24 16:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v3 1/2] xen-pciback: return proper values during BAR  sizing "Jan Beulich" <JBeulich@suse.com> - 2016-06-24 11:20 +0200
    Re: [Xen-devel] [PATCH v3 1/2] xen-pciback: return proper values  during BAR sizing David Vrabel <dvrabel@cantab.net> - 2016-06-24 16:10 +0200

#1430502 — [PATCH v3 1/2] xen-pciback: return proper values during BAR sizing

From"Jan Beulich" <JBeulich@suse.com>
Date2016-06-24 11:20 +0200
Subject[PATCH v3 1/2] xen-pciback: return proper values during BAR sizing
Message-ID<rNvrk-6dp-7@gated-at.bofh.it>
Reads following writes with all address bits set to 1 should return all
changeable address bits as one, not the BAR size (nor, as was the case
for the upper half of 64-bit BARs, the high half of the region's end
address). Presumably this didn't cause any problems so far because
consumers use the value to calculate the size (usually via val & -val),
and do nothing else with it.

But also consider the exception here: Unimplemented BARs should always
return all zeroes.

And finally, the check for whether to return the sizing address on read
for the ROM BAR should ignore all non-address bits, not just the ROM
Enable one.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
v3: Use ~0U in rom_write(), to account for PCI_ROM_ADDRESS_MASK being
    of unsigned long type (relevant on 64-bit). (Note: Patch 2 is
    unchanged, and hence not being re-sent. I hope that, despite this
    being a bug fix from v2, retaining the R-b is okay.)
---
 drivers/xen/xen-pciback/conf_space_header.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

--- 4.7-rc4-xen-pciback-BAR.orig/drivers/xen/xen-pciback/conf_space_header.c
+++ 4.7-rc4-xen-pciback-BAR/drivers/xen/xen-pciback/conf_space_header.c
@@ -145,7 +145,7 @@ static int rom_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 == ~PCI_ROM_ADDRESS_ENABLE)
+	if ((value | ~PCI_ROM_ADDRESS_MASK) == ~0U)
 		bar->which = 1;
 	else {
 		u32 tmpval;
@@ -225,38 +225,42 @@ static inline void read_dev_bar(struct p
 			   (PCI_BASE_ADDRESS_SPACE_MEMORY |
 				PCI_BASE_ADDRESS_MEM_TYPE_64))) {
 			bar_info->val = res[pos - 1].start >> 32;
-			bar_info->len_val = res[pos - 1].end >> 32;
+			bar_info->len_val = -resource_size(&res[pos - 1]) >> 32;
 			return;
 		}
 	}
 
+	if (!res[pos].flags ||
+	    (res[pos].flags & (IORESOURCE_DISABLED | IORESOURCE_UNSET |
+			       IORESOURCE_BUSY)))
+		return;
+
 	bar_info->val = res[pos].start |
 			(res[pos].flags & PCI_REGION_FLAG_MASK);
-	bar_info->len_val = resource_size(&res[pos]);
+	bar_info->len_val = -resource_size(&res[pos]) |
+			    (res[pos].flags & PCI_REGION_FLAG_MASK);
 }
 
 static void *bar_init(struct pci_dev *dev, int offset)
 {
-	struct pci_bar_info *bar = kmalloc(sizeof(*bar), GFP_KERNEL);
+	struct pci_bar_info *bar = kzalloc(sizeof(*bar), GFP_KERNEL);
 
 	if (!bar)
 		return ERR_PTR(-ENOMEM);
 
 	read_dev_bar(dev, bar, offset, ~0);
-	bar->which = 0;
 
 	return bar;
 }
 
 static void *rom_init(struct pci_dev *dev, int offset)
 {
-	struct pci_bar_info *bar = kmalloc(sizeof(*bar), GFP_KERNEL);
+	struct pci_bar_info *bar = kzalloc(sizeof(*bar), GFP_KERNEL);
 
 	if (!bar)
 		return ERR_PTR(-ENOMEM);
 
 	read_dev_bar(dev, bar, offset, ~PCI_ROM_ADDRESS_ENABLE);
-	bar->which = 0;
 
 	return bar;
 }

[toc] | [next] | [standalone]


#1430685 — Re: [Xen-devel] [PATCH v3 1/2] xen-pciback: return proper values during BAR sizing

FromDavid Vrabel <dvrabel@cantab.net>
Date2016-06-24 16:10 +0200
SubjectRe: [Xen-devel] [PATCH v3 1/2] xen-pciback: return proper values during BAR sizing
Message-ID<rNzXX-DY-1@gated-at.bofh.it>
In reply to#1430502
On 24/06/16 10:13, Jan Beulich wrote:
> Reads following writes with all address bits set to 1 should return all
> changeable address bits as one, not the BAR size (nor, as was the case
> for the upper half of 64-bit BARs, the high half of the region's end
> address). Presumably this didn't cause any problems so far because
> consumers use the value to calculate the size (usually via val & -val),
> and do nothing else with it.
> 
> But also consider the exception here: Unimplemented BARs should always
> return all zeroes.
> 
> And finally, the check for whether to return the sizing address on read
> for the ROM BAR should ignore all non-address bits, not just the ROM
> Enable one.

Applied to for-linus-4.7b, thanks.

David

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web