Skip to contentSkip to conversation

xen/pass-through: ROM BAR handling adjustments

PATCH Superseded Jan Beulich 2 participants 13 messages May 15, 2015 – Jun 8, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/pass-through: ROM BAR handling adjustments

Expecting the ROM BAR to be written with an all ones value when sizing the region is wrong - the low bit has another meaning (enable/disable) and bits 1..10 are reserved. The PCI spec also mandates writing all ones to just the address portion of the register.

Use suitable constants also for initializing the ROM BAR register field description.

hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != XEN_PT_BAR_ALLF) &&
         (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
         XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                     "Register. (addr: 0x%02x, len: %d)\n", addr, len);
hw/xen/xen_pt_config_init.c +2 -2
@@ -726,8 +726,8 @@ static XenPTRegInfo xen_pt_emu_reg_heade
         .offset     = PCI_ROM_ADDRESS,
         .size       = 4,
         .init_val   = 0x00000000,
-        .ro_mask    = 0x000007FE,
-        .emu_mask   = 0xFFFFF800,
+        .ro_mask    = ~PCI_ROM_ADDRESS_MASK & ~PCI_ROM_ADDRESS_ENABLE,
+        .emu_mask   = (uint32_t)PCI_ROM_ADDRESS_MASK,
         .init       = xen_pt_bar_reg_init,
         .u.dw.read  = xen_pt_long_reg_read,
         .u.dw.write = xen_pt_exp_rom_bar_reg_write,
#1 lore raw

Ping: [PATCH] xen/pass-through: ROM BAR handling adjustments

Ping?

Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 15.05.15 at 14:41, <[email protected]> wrote:

Expecting the ROM BAR to be written with an all ones value when sizing the region is wrong - the low bit has another meaning (enable/disable) and bits 1..10 are reserved. The PCI spec also mandates writing all ones to just the address portion of the register.

Use suitable constants also for initializing the ROM BAR register field description.

hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != 

XEN_PT_BAR_ALLF) &&
(s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) { XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address
"

                     "Register. (addr: 0x%02x, len: %d)\n", addr, len);
hw/xen/xen_pt_config_init.c +2 -2
@@ -726,8 +726,8 @@ static XenPTRegInfo xen_pt_emu_reg_heade
         .offset     = PCI_ROM_ADDRESS,
         .size       = 4,
         .init_val   = 0x00000000,
-        .ro_mask    = 0x000007FE,
-        .emu_mask   = 0xFFFFF800,
+        .ro_mask    = ~PCI_ROM_ADDRESS_MASK & ~PCI_ROM_ADDRESS_ENABLE,
+        .emu_mask   = (uint32_t)PCI_ROM_ADDRESS_MASK,
         .init       = xen_pt_bar_reg_init,
         .u.dw.read  = xen_pt_long_reg_read,
         .u.dw.write = xen_pt_exp_rom_bar_reg_write,

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

#2 lore raw

[Qemu-devel] Ping: [PATCH] xen/pass-through: ROM BAR handling adjustments

In reply to Jan Beulich

Ping?

Quoted 47 lines
Quoted 1 line
Quoted 1 line · On 15.05.15 at 14:41, <[email protected]> wrote:

Expecting the ROM BAR to be written with an all ones value when sizing the region is wrong - the low bit has another meaning (enable/disable) and bits 1..10 are reserved. The PCI spec also mandates writing all ones to just the address portion of the register.

Use suitable constants also for initializing the ROM BAR register field description.

hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != 

XEN_PT_BAR_ALLF) &&
(s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) { XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address
"

                     "Register. (addr: 0x%02x, len: %d)\n", addr, len);
hw/xen/xen_pt_config_init.c +2 -2
@@ -726,8 +726,8 @@ static XenPTRegInfo xen_pt_emu_reg_heade
         .offset     = PCI_ROM_ADDRESS,
         .size       = 4,
         .init_val   = 0x00000000,
-        .ro_mask    = 0x000007FE,
-        .emu_mask   = 0xFFFFF800,
+        .ro_mask    = ~PCI_ROM_ADDRESS_MASK & ~PCI_ROM_ADDRESS_ENABLE,
+        .emu_mask   = (uint32_t)PCI_ROM_ADDRESS_MASK,
         .init       = xen_pt_bar_reg_init,
         .u.dw.read  = xen_pt_long_reg_read,
         .u.dw.write = xen_pt_exp_rom_bar_reg_write,

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

#3 lore raw
In reply to Jan Beulich
Quoted 13 lines · Jan Beulich

Expecting the ROM BAR to be written with an all ones value when sizing the region is wrong - the low bit has another meaning (enable/disable) and bits 1..10 are reserved. The PCI spec also mandates writing all ones to just the address portion of the register.

Use suitable constants also for initializing the ROM BAR register field description.

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 7 lines
hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != XEN_PT_BAR_ALLF) &&

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

hw/xen/xen_pt_config_init.c static XenPTRegInfo xen_pt_emu_reg_heade · line 730

Quoted 13 lines
hw/xen/xen_pt.c +0 -0
         (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
         XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                     "Register. (addr: 0x%02x, len: %d)\n", addr, len);
hw/xen/xen_pt_config_init.c +2 -2
@@ -726,8 +726,8 @@ static XenPTRegInfo xen_pt_emu_reg_heade
         .offset     = PCI_ROM_ADDRESS,
         .size       = 4,
         .init_val   = 0x00000000,
-        .ro_mask    = 0x000007FE,
-        .emu_mask   = 0xFFFFF800,
+        .ro_mask    = ~PCI_ROM_ADDRESS_MASK & ~PCI_ROM_ADDRESS_ENABLE,
+        .emu_mask   = (uint32_t)PCI_ROM_ADDRESS_MASK,

There is no need for the explicit cast, is there?

Quoted 6 lines
hw/xen/xen_pt_config_init.c +0 -0
         .init       = xen_pt_bar_reg_init,
         .u.dw.read  = xen_pt_long_reg_read,
         .u.dw.write = xen_pt_exp_rom_bar_reg_write,
#4 lore raw
In reply to Jan Beulich
Quoted 13 lines · Jan Beulich

Expecting the ROM BAR to be written with an all ones value when sizing the region is wrong - the low bit has another meaning (enable/disable) and bits 1..10 are reserved. The PCI spec also mandates writing all ones to just the address portion of the register.

Use suitable constants also for initializing the ROM BAR register field description.

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 7 lines
hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != XEN_PT_BAR_ALLF) &&

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

hw/xen/xen_pt_config_init.c static XenPTRegInfo xen_pt_emu_reg_heade · line 730

Quoted 13 lines
hw/xen/xen_pt.c +0 -0
         (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
         XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                     "Register. (addr: 0x%02x, len: %d)\n", addr, len);
hw/xen/xen_pt_config_init.c +2 -2
@@ -726,8 +726,8 @@ static XenPTRegInfo xen_pt_emu_reg_heade
         .offset     = PCI_ROM_ADDRESS,
         .size       = 4,
         .init_val   = 0x00000000,
-        .ro_mask    = 0x000007FE,
-        .emu_mask   = 0xFFFFF800,
+        .ro_mask    = ~PCI_ROM_ADDRESS_MASK & ~PCI_ROM_ADDRESS_ENABLE,
+        .emu_mask   = (uint32_t)PCI_ROM_ADDRESS_MASK,

There is no need for the explicit cast, is there?

Quoted 6 lines
hw/xen/xen_pt_config_init.c +0 -0
         .init       = xen_pt_bar_reg_init,
         .u.dw.read  = xen_pt_long_reg_read,
         .u.dw.write = xen_pt_exp_rom_bar_reg_write,
#5 lore raw
Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +0 -0
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
Quoted 9 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 6 lines
hw/xen/xen_pt.c +3 -1
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != XEN_PT_BAR_ALLF) &&

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Quoted 4 lines
Quoted 4 lines
hw/xen/xen_pt_config_init.c +0 -0
@@ -726,8 +726,8 @@ static XenPTRegInfo xen_pt_emu_reg_heade
         .offset     = PCI_ROM_ADDRESS,
Quoted 8 lines

hw/xen/xen_pt_config_init.c static XenPTRegInfo xen_pt_emu_reg_heade · line 730

Quoted 6 lines
hw/xen/xen_pt_config_init.c +2 -2
         .size       = 4,
         .init_val   = 0x00000000,
-        .ro_mask    = 0x000007FE,
-        .emu_mask   = 0xFFFFF800,
+        .ro_mask    = ~PCI_ROM_ADDRESS_MASK & ~PCI_ROM_ADDRESS_ENABLE,
+        .emu_mask   = (uint32_t)PCI_ROM_ADDRESS_MASK,

There is no need for the explicit cast, is there?

There is - PCI_ROM_ADDRESS_MASK being wider than 32 bits the assignment could cause compiler warning otherwise (which I think I actually ran into.

Jan

#6 lore raw
In reply to Stefano Stabellini
Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +0 -0
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
Quoted 9 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 6 lines
hw/xen/xen_pt.c +3 -1
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != XEN_PT_BAR_ALLF) &&

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Quoted 4 lines
Quoted 4 lines
hw/xen/xen_pt_config_init.c +0 -0
@@ -726,8 +726,8 @@ static XenPTRegInfo xen_pt_emu_reg_heade
         .offset     = PCI_ROM_ADDRESS,
Quoted 8 lines

hw/xen/xen_pt_config_init.c static XenPTRegInfo xen_pt_emu_reg_heade · line 730

Quoted 6 lines
hw/xen/xen_pt_config_init.c +2 -2
         .size       = 4,
         .init_val   = 0x00000000,
-        .ro_mask    = 0x000007FE,
-        .emu_mask   = 0xFFFFF800,
+        .ro_mask    = ~PCI_ROM_ADDRESS_MASK & ~PCI_ROM_ADDRESS_ENABLE,
+        .emu_mask   = (uint32_t)PCI_ROM_ADDRESS_MASK,

There is no need for the explicit cast, is there?

There is - PCI_ROM_ADDRESS_MASK being wider than 32 bits the assignment could cause compiler warning otherwise (which I think I actually ran into.

Jan

#7 lore raw
Quoted 15 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +0 -0
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
Quoted 9 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 6 lines
hw/xen/xen_pt.c +3 -1
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != XEN_PT_BAR_ALLF) &&

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

Quoted 2 lines

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Would you be OK if I rewrote the statement as follows?

    if ((index >= 0) && (val != 0)) {
        uint32_t vu;
        
        if (index == PCI_ROM_SLOT) {
            vu = val | (uint32_t)~PCI_ROM_ADDRESS_MASK;
        } else {
            vu = val;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
            (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
            XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                    "Register. (addr: 0x%02x, len: %d)\n", addr, len);
        }
    }
#8 lore raw
In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +0 -0
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
Quoted 9 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 6 lines
hw/xen/xen_pt.c +3 -1
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != XEN_PT_BAR_ALLF) &&

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

Quoted 2 lines

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Would you be OK if I rewrote the statement as follows?

    if ((index >= 0) && (val != 0)) {
        uint32_t vu;
        
        if (index == PCI_ROM_SLOT) {
            vu = val | (uint32_t)~PCI_ROM_ADDRESS_MASK;
        } else {
            vu = val;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
            (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
            XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                    "Register. (addr: 0x%02x, len: %d)\n", addr, len);
        }
    }
#9 lore raw
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 05.06.15 at 18:41, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 11 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != 

XEN_PT_BAR_ALLF) &&

Quoted 6 lines
Quoted 3 lines

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Would you be OK if I rewrote the statement as follows?

Quoted 15 lines
    if ((index >= 0) && (val != 0)) {
        uint32_t vu;
        
        if (index == PCI_ROM_SLOT) {
            vu = val | (uint32_t)~PCI_ROM_ADDRESS_MASK;
        } else {
            vu = val;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
            (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
            XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                    "Register. (addr: 0x%02x, len: %d)\n", addr, len);
        }
    }

Actually I agree that this indeed looks better. If I were to make the change, I'd do

    if ((index >= 0) && (val != 0)) {
        uint32_t vu = val;
        
        if (index == PCI_ROM_SLOT) {
            vu |= (uint32_t)~PCI_ROM_ADDRESS_MASK;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
        ...

though. But if you're going to do the edit without wanting me to re-submit, I'll certainly leave this to you. Just let me know which way you prefer it to be handled.

Jan

#10 lore raw
In reply to Stefano Stabellini
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 05.06.15 at 18:41, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 11 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != 

XEN_PT_BAR_ALLF) &&

Quoted 6 lines
Quoted 3 lines

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Would you be OK if I rewrote the statement as follows?

Quoted 15 lines
    if ((index >= 0) && (val != 0)) {
        uint32_t vu;
        
        if (index == PCI_ROM_SLOT) {
            vu = val | (uint32_t)~PCI_ROM_ADDRESS_MASK;
        } else {
            vu = val;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
            (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
            XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                    "Register. (addr: 0x%02x, len: %d)\n", addr, len);
        }
    }

Actually I agree that this indeed looks better. If I were to make the change, I'd do

    if ((index >= 0) && (val != 0)) {
        uint32_t vu = val;
        
        if (index == PCI_ROM_SLOT) {
            vu |= (uint32_t)~PCI_ROM_ADDRESS_MASK;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
        ...

though. But if you're going to do the edit without wanting me to re-submit, I'll certainly leave this to you. Just let me know which way you prefer it to be handled.

Jan

#11 lore raw
Quoted 52 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 05.06.15 at 18:41, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 11 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != 

XEN_PT_BAR_ALLF) &&

Quoted 6 lines
Quoted 3 lines

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Would you be OK if I rewrote the statement as follows?

Quoted 15 lines
    if ((index >= 0) && (val != 0)) {
        uint32_t vu;
        
        if (index == PCI_ROM_SLOT) {
            vu = val | (uint32_t)~PCI_ROM_ADDRESS_MASK;
        } else {
            vu = val;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
            (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
            XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                    "Register. (addr: 0x%02x, len: %d)\n", addr, len);
        }
    }

Actually I agree that this indeed looks better. If I were to make the change, I'd do

    if ((index >= 0) && (val != 0)) {
        uint32_t vu = val;
        
        if (index == PCI_ROM_SLOT) {
            vu |= (uint32_t)~PCI_ROM_ADDRESS_MASK;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
        ...
Quoted 3 lines

though. But if you're going to do the edit without wanting me to re-submit, I'll certainly leave this to you. Just let me know which way you prefer it to be handled.

I prefer if you resubmit, thanks!

#12 lore raw
In reply to Jan Beulich
Quoted 52 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 05.06.15 at 18:41, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines

hw/xen/xen_pt.c static void xen_pt_pci_write_config(PCID · line 253

Quoted 11 lines
Quoted 1 line · On 05.06.15 at 13:32, <[email protected]> wrote:
hw/xen/xen_pt.c +3 -1
@@ -248,7 +248,9 @@ static void xen_pt_pci_write_config(PCID
 
     /* check unused BAR register */
     index = xen_pt_bar_offset_to_index(addr);
-    if ((index >= 0) && (val > 0 && val < XEN_PT_BAR_ALLF) &&
+    if ((index >= 0) && (val != 0) &&
+        (((index != PCI_ROM_SLOT) ?
+          val : (val | (uint32_t)~PCI_ROM_ADDRESS_MASK)) != 

XEN_PT_BAR_ALLF) &&

Quoted 6 lines
Quoted 3 lines

The change seems looks good and in line with the commit message. But this if statement looks like acrobatic circus to me now.

I think the alternative of splitting it up into multiple if()-s would not be any better readable.

Would you be OK if I rewrote the statement as follows?

Quoted 15 lines
    if ((index >= 0) && (val != 0)) {
        uint32_t vu;
        
        if (index == PCI_ROM_SLOT) {
            vu = val | (uint32_t)~PCI_ROM_ADDRESS_MASK;
        } else {
            vu = val;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
            (s->bases[index].bar_flag == XEN_PT_BAR_FLAG_UNUSED)) {
            XEN_PT_WARN(d, "Guest attempt to set address to unused Base Address "
                    "Register. (addr: 0x%02x, len: %d)\n", addr, len);
        }
    }

Actually I agree that this indeed looks better. If I were to make the change, I'd do

    if ((index >= 0) && (val != 0)) {
        uint32_t vu = val;
        
        if (index == PCI_ROM_SLOT) {
            vu |= (uint32_t)~PCI_ROM_ADDRESS_MASK;
        }

        if ((vu != XEN_PT_BAR_ALLF) &&
        ...
Quoted 3 lines

though. But if you're going to do the edit without wanting me to re-submit, I'll certainly leave this to you. Just let me know which way you prefer it to be handled.

I prefer if you resubmit, thanks!