Skip to contentSkip to conversation

A couple of SR-IOV-related patches

PATCH In review Boris Ostrovsky 2 participants 10 messages Feb 12, 2014 – Feb 18, 2014

lore
Share & tools
lore
#0 lore raw

cover A couple of SR-IOV-related patches

The first patch fixes a bug in calculating offset to the Virtual Function's memory space. It may be worth taking it to 4.4.

The second patch is removal of what seems to be a redundant check in computing VF number.

Boris Ostrovsky (2):
x86/pci: Store VF's memory space displacement in a 64-bit value x86/pci: Remove unnecessary check in VF value computation

 xen/arch/x86/msi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/2 x86/pci: Store VF's memory space displacement in a 64-bit value

VF's memory space offset can be greater than 4GB and therefore needs to be stored in a 64-bit variable.

---
 xen/arch/x86/msi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/msi.c +2 -1
index 284042e..1aaceeb 100644
@@ -610,7 +610,8 @@ static int msi_capability_init(struct pci_dev *dev,
 static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 func, u8 bir, int vf)
 {
     u8 limit;
-    u32 addr, base = PCI_BASE_ADDRESS_0, disp = 0;
+    u32 addr, base = PCI_BASE_ADDRESS_0;
+    u64 disp = 0;
 
     if ( vf >= 0 )
     {
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/2 x86/pci: Remove unnecessary check in VF value computation

In reply to Boris Ostrovsky

This test is already performed a couple of lines above.

---
 xen/arch/x86/msi.c | 4 ----
 1 file changed, 4 deletions(-)
xen/arch/x86/msi.c +0 -4
index 1aaceeb..27e47c3 100644
@@ -639,11 +639,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 func, u8 bir, int vf)
         if ( vf < 0 || (vf && vf % stride) )
             return 0;
         if ( stride )
-        {
-            if ( vf % stride )
-                return 0;
             vf /= stride;
-        }
         if ( vf >= num_vf )
             return 0;
         BUILD_BUG_ON(ARRAY_SIZE(pdev->vf_rlen) != PCI_SRIOV_NUM_BARS);
Signature · 1 line
1.8.1.4
#3 lore raw

Re: [PATCH 2/2] x86/pci: Remove unnecessary check in VF value computation

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

This test is already performed a couple of lines above.

Except that it's the wrong code you remove:

Review static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 func, u8 bir, int vf) · line 646

Quoted 9 lines
(quoted diff) +0 -4
@@ -639,11 +639,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 func, u8 bir, int vf)
         if ( vf < 0 || (vf && vf % stride) )
             return 0;
         if ( stride )
-        {
-            if ( vf % stride )
-                return 0;
             vf /= stride;
-        }

Note how this second check carefully avoids a division by zero.

Quoted 1 line

From what I can tell I think that I simply forgot to remove the

right side of the earlier || after having converted it to the safer variant inside the if(). Hence I think we instead want:

x86/MSI: don't risk division by zero

The check in question is redundant with the one in the immediately following if(), where dividing by zero gets carefully avoided.

xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 
             return 0;
         base = pos + PCI_SRIOV_BAR;
         vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
             return 0;
         if ( stride )
         {

x86/MSI: don't risk division by zero

The check in question is redundant with the one in the immediately following if(), where dividing by zero gets carefully avoided.

xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 
             return 0;
         base = pos + PCI_SRIOV_BAR;
         vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
             return 0;
         if ( stride )
         {

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

#4 lore raw

Re: [PATCH 2/2] x86/pci: Remove unnecessary check in VF value computation

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line · Boris Ostrovsky

This test is already performed a couple of lines above.

Except that it's the wrong code you remove:

No opinion on this alternative at all?

Jan

Quoted 35 lines

Review static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8

Quoted 1 line
(quoted diff) +0 -0
@@ -639,11 +639,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 

func, u8 bir, int vf)

Review static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 · line 646

Quoted 8 lines
(quoted diff) +0 -4
         if ( vf < 0 || (vf && vf % stride) )
             return 0;
         if ( stride )
-        {
-            if ( vf % stride )
-                return 0;
             vf /= stride;
-        }

Note how this second check carefully avoids a division by zero. From what I can tell I think that I simply forgot to remove the right side of the earlier || after having converted it to the safer variant inside the if(). Hence I think we instead want:

x86/MSI: don't risk division by zero

The check in question is redundant with the one in the immediately following if(), where dividing by zero gets carefully avoided.

xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 
             return 0;
         base = pos + PCI_SRIOV_BAR;
         vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
             return 0;
         if ( stride )
         {
author Reviewed-by
#5 lore raw

Re: [PATCH 2/2] x86/pci: Remove unnecessary check in VF value computation

Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line · Boris Ostrovsky

This test is already performed a couple of lines above.

Except that it's the wrong code you remove:

No opinion on this alternative at all?

Sorry Jan, I didn't realize you were waiting for me on this.

Yes, your version is fine although to be honest I don't see how the original patch had any issues with division by zero since we'd still be inside the 'if (stride)' clause.

But as I said, either version is OK with me so you can add

-boris

Quoted 39 lines

Jan

Quoted 34 lines

Review static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8

Quoted 1 line
(quoted diff) +0 -0
@@ -639,11 +639,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8

func, u8 bir, int vf)

Review static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 · line 646

Quoted 8 lines
(quoted diff) +0 -4
          if ( vf < 0 || (vf && vf % stride) )
              return 0;
          if ( stride )
-        {
-            if ( vf % stride )
-                return 0;
              vf /= stride;
-        }

Note how this second check carefully avoids a division by zero.
From what I can tell I think that I simply forgot to remove the
right side of the earlier || after having converted it to the safer variant inside the if(). Hence I think we instead want:

x86/MSI: don't risk division by zero

The check in question is redundant with the one in the immediately following if(), where dividing by zero gets carefully avoided.

xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8
              return 0;
          base = pos + PCI_SRIOV_BAR;
          vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
              return 0;
          if ( stride )
          {
#6 lore raw

Re: [PATCH 2/2] x86/pci: Remove unnecessary check in VF value computation

Quoted 5 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line · Boris Ostrovsky

This test is already performed a couple of lines above.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

Except that it's the wrong code you remove:

No opinion on this alternative at all?

Sorry Jan, I didn't realize you were waiting for me on this.

Yes, your version is fine although to be honest I don't see how the original patch had any issues with division by zero since we'd still be inside the 'if (stride)' clause.

It's the very division that this patch removes:

Quoted 11 lines
Quoted 11 lines

xen/arch/x86/msi.c static u64 read_pci_mem_bar(u16 seg, u8 · line 641

Quoted 11 lines
xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8
              return 0;
          base = pos + PCI_SRIOV_BAR;
          vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
              return 0;
          if ( stride )
          {

Which isn't inside the if(stride).

Jan

#7 lore raw

Re: [PATCH 2/2] x86/pci: Remove unnecessary check in VF value computation

Quoted 14 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line · Boris Ostrovsky
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

This test is already performed a couple of lines above.

Except that it's the wrong code you remove:

No opinion on this alternative at all?

Sorry Jan, I didn't realize you were waiting for me on this.

Yes, your version is fine although to be honest I don't see how the original patch had any issues with division by zero since we'd still be inside the 'if (stride)' clause.

It's the very division that this patch removes:

Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

xen/arch/x86/msi.c static u64 read_pci_mem_bar(u16 seg, u8 · line 641

Quoted 11 lines
xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8
               return 0;
           base = pos + PCI_SRIOV_BAR;
           vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
               return 0;
           if ( stride )
           {

Which isn't inside the if(stride).

Yes, I see it now. I was staring at a wrong line.

This actually now looks like a bug. You do check above for '(num_vf > 1 && !stride) ' but presumably if things are really messed up num_vf can be 1 but vf is 0. And then if stride is zero too then we are not doing particularly well.

So probably this should go into 4.4 as well?

-boris

#8 lore raw

Re: [PATCH 2/2] x86/pci: Remove unnecessary check in VF value computation

Quoted 30 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 14 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line · Boris Ostrovsky
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

This test is already performed a couple of lines above.

Except that it's the wrong code you remove:

No opinion on this alternative at all?

Sorry Jan, I didn't realize you were waiting for me on this.

Yes, your version is fine although to be honest I don't see how the original patch had any issues with division by zero since we'd still be inside the 'if (stride)' clause.

It's the very division that this patch removes:

Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

xen/arch/x86/msi.c static u64 read_pci_mem_bar(u16 seg, u8 · line 641

Quoted 11 lines
xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8
               return 0;
           base = pos + PCI_SRIOV_BAR;
           vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
               return 0;
           if ( stride )
           {

Which isn't inside the if(stride).

Quoted 3 lines

Yes, I see it now. I was staring at a wrong line.

This actually now looks like a bug.

You mean the old code looks wrong or the new one?

Quoted 6 lines

You do check above for '(num_vf > 1
&& !stride) ' but presumably if things are really messed up num_vf can be 1 but vf is 0. And then if stride is zero too then we are not doing particularly well.

So probably this should go into 4.4 as well?

We've done with this unfixed quite fine so far, so it's generally okay to leave as is until 4.4.1 (read: not a regression). I personally wouldn't mind pushing it in, but only if other similar not too high priority bug fixes would also go in.

Jan

#9 lore raw

Re: [PATCH 2/2] x86/pci: Remove unnecessary check in VF value computation

Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 26 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line · Boris Ostrovsky
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

This test is already performed a couple of lines above.

Except that it's the wrong code you remove:

No opinion on this alternative at all?

Sorry Jan, I didn't realize you were waiting for me on this.

Yes, your version is fine although to be honest I don't see how the original patch had any issues with division by zero since we'd still be inside the 'if (stride)' clause.

It's the very division that this patch removes:

Quoted 11 lines
Quoted 11 lines

xen/arch/x86/msi.c static u64 read_pci_mem_bar(u16 seg, u8 · line 641

Quoted 11 lines
xen/arch/x86/msi.c +1 -1
@@ -635,7 +635,7 @@ static u64 read_pci_mem_bar(u16 seg, u8
                return 0;
            base = pos + PCI_SRIOV_BAR;
            vf -= PCI_BDF(bus, slot, func) + offset;
-        if ( vf < 0 || (vf && vf % stride) )
+        if ( vf < 0 )
                return 0;
            if ( stride )
            {

Which isn't inside the if(stride).

Quoted 4 lines
Quoted 3 lines

Yes, I see it now. I was staring at a wrong line.

This actually now looks like a bug.

You mean the old code looks wrong or the new one?

The old one. Your patch fixes it.

Quoted 6 lines
Quoted 6 lines

You do check above for '(num_vf > 1
&& !stride) ' but presumably if things are really messed up num_vf can be 1 but vf is 0. And then if stride is zero too then we are not doing particularly well.

Quoted 6 lines
Quoted 1 line

So probably this should go into 4.4 as well?

We've done with this unfixed quite fine so far, so it's generally okay to leave as is until 4.4.1 (read: not a regression). I personally wouldn't mind pushing it in, but only if other similar not too high priority bug fixes would also go in.

OK.

-boris