Skip to contentSkip to conversation

xenpt: Properly handle 64-bit bar with more than 4G size

PATCH In review Feng Wu 4 participants 8 messages Aug 5, 2015 – Aug 12, 2015

lore
Share & tools
lore

Feng Wu

author
#0 lore raw

PATCH 1/1 xenpt: Properly handle 64-bit bar with more than 4G size

This patch corrects a logic error when handling 64-bt bar with more than 4G size.

With 64-bit Bar, it has two items in PCIDevice: io_regions[x] and io_regions[x+1], io_regions[x] has all the informations for this BAR, while io_regions[x+1] contains nothing, so we need to get the size from io_regions[x] when handling XEN_PT_BAR_FLAG_UPPER.

---
I cannot test this patch sicne I don't have such a device, if someone have it, it would be highly appreicated if he can help to verfiy this patch.

 hw/xen/xen_pt_config_init.c |   22 +++-------------------
 1 files changed, 3 insertions(+), 19 deletions(-)
hw/xen/xen_pt_config_init.c +3 -19
index dd37be3..6fcef66 100644
@@ -326,23 +326,6 @@ static int xen_pt_cmd_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,
 #define XEN_PT_BAR_IO_RO_MASK     0x00000003  /* BAR ReadOnly mask(I/O) */
 #define XEN_PT_BAR_IO_EMU_MASK    0xFFFFFFFC  /* BAR emul mask(I/O) */
 
-static bool is_64bit_bar(PCIIORegion *r)
-{
-    return !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
-}
-
-static uint64_t xen_pt_get_bar_size(PCIIORegion *r)
-{
-    if (is_64bit_bar(r)) {
-        uint64_t size64;
-        size64 = (r + 1)->size;
-        size64 <<= 32;
-        size64 += r->size;
-        return size64;
-    }
-    return r->size;
-}
-
 static XenPTBarFlag xen_pt_bar_reg_parse(XenPCIPassthroughState *s,
                                          int index)
 {
@@ -365,7 +348,7 @@ static XenPTBarFlag xen_pt_bar_reg_parse(XenPCIPassthroughState *s,
 
     /* check unused BAR */
     r = &d->io_regions[index];
-    if (!xen_pt_get_bar_size(r)) {
+    if (r->size == 0) {
         return XEN_PT_BAR_FLAG_UNUSED;
     }
 
@@ -491,8 +474,9 @@ static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];
         bar_emu_mask = XEN_PT_BAR_ALLF;
-        bar_ro_mask = r_size ? r_size - 1 : 0;
+        bar_ro_mask = (r->size - 1) >> 32;
         break;
     default:
         break;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 7 lines · Feng Wu

This patch corrects a logic error when handling 64-bt bar with more than 4G size.

With 64-bit Bar, it has two items in PCIDevice: io_regions[x] and io_regions[x+1], io_regions[x] has all the informations for this BAR, while io_regions[x+1] contains nothing, so we need to get the size from io_regions[x] when handling XEN_PT_BAR_FLAG_UPPER.

That's because of the way io_regions are populated by xen_host_pci_get_resource, right?

Quoted 5 lines

---
I cannot test this patch sicne I don't have such a device, if someone have it, it would be highly appreicated if he can help to verfiy this patch.

I would very much appreciate if somebody could properly validate this patch with the right device before I actually commit it

Quoted 40 lines
 hw/xen/xen_pt_config_init.c |   22 +++-------------------
 1 files changed, 3 insertions(+), 19 deletions(-)
hw/xen/xen_pt_config_init.c +1 -18
index dd37be3..6fcef66 100644
@@ -326,23 +326,6 @@ static int xen_pt_cmd_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,
 #define XEN_PT_BAR_IO_RO_MASK     0x00000003  /* BAR ReadOnly mask(I/O) */
 #define XEN_PT_BAR_IO_EMU_MASK    0xFFFFFFFC  /* BAR emul mask(I/O) */
 
-static bool is_64bit_bar(PCIIORegion *r)
-{
-    return !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
-}
-
-static uint64_t xen_pt_get_bar_size(PCIIORegion *r)
-{
-    if (is_64bit_bar(r)) {
-        uint64_t size64;
-        size64 = (r + 1)->size;
-        size64 <<= 32;
-        size64 += r->size;
-        return size64;
-    }
-    return r->size;
-}
-
 static XenPTBarFlag xen_pt_bar_reg_parse(XenPCIPassthroughState *s,
                                          int index)
 {
@@ -365,7 +348,7 @@ static XenPTBarFlag xen_pt_bar_reg_parse(XenPCIPassthroughState *s,
 
     /* check unused BAR */
     r = &d->io_regions[index];
-    if (!xen_pt_get_bar_size(r)) {
+    if (r->size == 0) {
         return XEN_PT_BAR_FLAG_UNUSED;
     }

hw/xen/xen_pt_config_init.c static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry, · line 482

Quoted 10 lines
hw/xen/xen_pt_config_init.c +2 -1
@@ -491,8 +474,9 @@ static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];
         bar_emu_mask = XEN_PT_BAR_ALLF;
-        bar_ro_mask = r_size ? r_size - 1 : 0;
+        bar_ro_mask = (r->size - 1) >> 32;
         break;
     default:
         break;

The changes look correct

author
#2 lore raw
Quoted 15 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: Thursday, August 06, 2015 6:43 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1] xenpt: Properly handle 64-bit bar with more than 4G size

Quoted 3 lines · Feng Wu

This patch corrects a logic error when handling 64-bt bar with more than 4G size.

Quoted 7 lines
Quoted 4 lines

With 64-bit Bar, it has two items in PCIDevice: io_regions[x] and io_regions[x+1], io_regions[x] has all the informations for this BAR, while io_regions[x+1] contains nothing, so we need to get the size from io_regions[x] when handling XEN_PT_BAR_FLAG_UPPER.

That's because of the way io_regions are populated by xen_host_pci_get_resource, right?

Yes, xen_host_pci_get_resouce() is the source of the BAR information.

Thanks,
Feng

Quoted 69 lines
Quoted 7 lines

---
I cannot test this patch sicne I don't have such a device, if someone have it, it would be highly appreicated if he can help to verfiy this patch.

I would very much appreciate if somebody could properly validate this patch with the right device before I actually commit it

hw/xen/xen_pt_config_init.c static int

Quoted 8 lines
 hw/xen/xen_pt_config_init.c |   22 +++-------------------
 1 files changed, 3 insertions(+), 19 deletions(-)
hw/xen/xen_pt_config_init.c +0 -0
index dd37be3..6fcef66 100644
@@ -326,23 +326,6 @@ static int

xen_pt_cmd_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,

hw/xen/xen_pt_config_init.c static int · line 326

Quoted 1 line
hw/xen/xen_pt_config_init.c +0 -0
 #define XEN_PT_BAR_IO_RO_MASK     0x00000003  /* BAR ReadOnly

mask(I/O) */

hw/xen/xen_pt_config_init.c static int · line 327

Quoted 1 line
hw/xen/xen_pt_config_init.c +0 -0
 #define XEN_PT_BAR_IO_EMU_MASK    0xFFFFFFFC  /* BAR emul

mask(I/O) */

hw/xen/xen_pt_config_init.c static XenPTBarFlag

Quoted 22 lines
hw/xen/xen_pt_config_init.c +0 -17
-static bool is_64bit_bar(PCIIORegion *r)
-{
-    return !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
-}
-
-static uint64_t xen_pt_get_bar_size(PCIIORegion *r)
-{
-    if (is_64bit_bar(r)) {
-        uint64_t size64;
-        size64 = (r + 1)->size;
-        size64 <<= 32;
-        size64 += r->size;
-        return size64;
-    }
-    return r->size;
-}
-
 static XenPTBarFlag xen_pt_bar_reg_parse(XenPCIPassthroughState *s,
                                          int index)
 {
@@ -365,7 +348,7 @@ static XenPTBarFlag

xen_pt_bar_reg_parse(XenPCIPassthroughState *s,

hw/xen/xen_pt_config_init.c static int

Quoted 8 lines
hw/xen/xen_pt_config_init.c +1 -1
     /* check unused BAR */
     r = &d->io_regions[index];
-    if (!xen_pt_get_bar_size(r)) {
+    if (r->size == 0) {
         return XEN_PT_BAR_FLAG_UNUSED;
     }
@@ -491,8 +474,9 @@ static int

xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,

hw/xen/xen_pt_config_init.c static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry, · line 482

Quoted 10 lines
hw/xen/xen_pt_config_init.c +2 -1
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];
         bar_emu_mask = XEN_PT_BAR_ALLF;
-        bar_ro_mask = r_size ? r_size - 1 : 0;
+        bar_ro_mask = (r->size - 1) >> 32;
         break;
     default:
         break;

The changes look correct

#3 lore raw
In reply to Feng Wu

hw/xen/xen_pt_config_init.c static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry, · line 477

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 04:02, <[email protected]> wrote:
hw/xen/xen_pt_config_init.c +1 -0
@@ -491,8 +474,9 @@ static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];

Perhaps worth an assert(index > 0)?

Jan

author
#4 lore raw
Quoted 14 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: Wednesday, August 12, 2015 2:59 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [Xen-devel] [PATCH v1] xenpt: Properly handle 64-bit bar with more than 4G size

Quoted 1 line
Quoted 1 line
Quoted 1 line · On 05.08.15 at 04:02, <[email protected]> wrote:
Quoted 8 lines

Review static int

Quoted 1 line
(quoted diff) +0 -0
@@ -491,8 +474,9 @@ static int

xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,

hw/xen/xen_pt_config_init.c static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry, · line 477

Quoted 4 lines
hw/xen/xen_pt_config_init.c +1 -0
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];

Perhaps worth an assert(index > 0)?

No problem, I will add it. BTW, do you have any other comments about this patch? If no, I am going to send out the new version with this changes.

Thanks,
Feng

Quoted 3 lines

Jan

#5 lore raw
Quoted 22 lines
Quoted 22 lines
Quoted 1 line · On 12.08.15 at 09:10, <[email protected]> wrote:

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: Wednesday, August 12, 2015 2:59 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [Xen-devel] [PATCH v1] xenpt: Properly handle 64-bit bar with more than 4G size

Review static int

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 04:02, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -491,8 +474,9 @@ static int

xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,

Quoted 4 lines
hw/xen/xen_pt_config_init.c +1 -0
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];
Quoted 5 lines
Quoted 1 line

Perhaps worth an assert(index > 0)?

No problem, I will add it. BTW, do you have any other comments about this patch? If no, I am
going to send out the new version with this changes.

No - everything else looks to make sense (but continues to need testing).

Jan

author
#6 lore raw
Quoted 34 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, August 12, 2015 4:43 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [Qemu-devel] [Xen-devel] [PATCH v1] xenpt: Properly handle 64-bit bar with more than 4G size

Quoted 12 lines
Quoted 12 lines
Quoted 1 line · On 12.08.15 at 09:10, <[email protected]> wrote:

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: Wednesday, August 12, 2015 2:59 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [Xen-devel] [PATCH v1] xenpt: Properly handle

64-bit

Quoted 10 lines
Quoted 10 lines

bar with more than 4G size

Review static int

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 04:02, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -491,8 +474,9 @@ static int

xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,

Quoted 4 lines
hw/xen/xen_pt_config_init.c +1 -0
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];
Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Perhaps worth an assert(index > 0)?

No problem, I will add it. BTW, do you have any other comments about this patch? If no, I am
going to send out the new version with this changes.

No - everything else looks to make sense (but continues to need testing).

I don't have such a device in hand. Can anybody who has such a device help to test this patch? It would be highly appreciated!

Thanks,
Feng

Quoted 1 line

Jan

#7 lore raw
Quoted 40 lines · Feng
Quoted 40 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, August 12, 2015 4:43 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [Qemu-devel] [Xen-devel] [PATCH v1] xenpt: Properly handle 64-bit bar with more than 4G size

Quoted 12 lines
Quoted 12 lines
Quoted 1 line · On 12.08.15 at 09:10, <[email protected]> wrote:

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: Wednesday, August 12, 2015 2:59 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [Xen-devel] [PATCH v1] xenpt: Properly handle

64-bit

Quoted 15 lines
Quoted 11 lines

bar with more than 4G size

Review static int

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 04:02, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -491,8 +474,9 @@ static int

xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry,

hw/xen/xen_pt_config_init.c static int xen_pt_bar_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_entry, · line 477

Quoted 4 lines
hw/xen/xen_pt_config_init.c +1 -0
         bar_ro_mask = XEN_PT_BAR_IO_RO_MASK | (r_size - 1);
         break;
     case XEN_PT_BAR_FLAG_UPPER:
+        r = &d->io_regions[index-1];

Perhaps worth an assert(index > 0)?

No problem, I will add it. BTW, do you have any other comments about this patch? If no, I am
going to send out the new version with this changes.

Quoted 6 lines
Quoted 3 lines

No - everything else looks to make sense (but continues to need testing).

I don't have such a device in hand. Can anybody who has such a device help to test this patch? It would be highly appreciated!

Um, 4GB MMIO bars? Wouldn't the Nvidia Quadro K6000 12GB GDDR do it? I am sure that Intel would be OK expensing $4K of hardware :-)

Quoted 11 lines

Thanks,
Feng

Quoted 1 line

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel