Skip to contentSkip to conversation

igb: Add Function Level Reset to PF and VF

PATCH In review Cédric Le Goater 3 participants 12 messages May 26, 2023 – May 30, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")
---
 hw/net/igb.c   | 3 +++
 hw/net/igbvf.c | 3 +++
 2 files changed, 6 insertions(+)
hw/net/igb.c +3 -0
index 1c989d767725..08e389338dca 100644
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, uint32_t addr,
 
     trace_igb_write_config(addr, val, len);
     pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 
     if (range_covers_byte(addr, len, PCI_COMMAND) &&
         (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
@@ -427,6 +428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
     }
 
     /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
     if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) {
         hw_error("Failed to initialize AER capability");
     }
hw/net/igbvf.c +3 -0
index 284ea611848b..0a58dad06802 100644
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev, uint32_t addr, uint32_t val,
 {
     trace_igbvf_write_config(addr, val, len);
     pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 }
 
 static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **errp)
         hw_error("Failed to initialize PCIe capability");
     }
 
+    pcie_cap_flr_init(dev);
+
     if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
         hw_error("Failed to initialize AER capability");
     }
Signature · 1 line
2.40.1
#1 lore raw
Quoted 56 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")
---
 hw/net/igb.c   | 3 +++
 hw/net/igbvf.c | 3 +++
 2 files changed, 6 insertions(+)
hw/net/igb.c index 1c989d767725..08e389338dca renamed from hw/net/igb.c +0 -0

100644

hw/net/igb.c +1 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, uint32_t
 addr,
 
     trace_igb_write_config(addr, val, len);
     pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 
     if (range_covers_byte(addr, len, PCI_COMMAND) &&
         (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -427,6
+428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
     }

     /* PCIe extended capabilities (in order) */
hw/net/igb.c +2 -0
+    pcie_cap_flr_init(pci_dev);
+
     if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) {
         hw_error("Failed to initialize AER capability");
     }
hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
     trace_igbvf_write_config(addr, val, len);
     pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 }
 
 static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)

hw/net/igbvf.c static void igbvf_pci_realize(PCIDevice *dev, Error · line 271

Quoted 5 lines
hw/net/igbvf.c +1 -0
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
 **errp)
         hw_error("Failed to initialize PCIe capability");
     }
 
+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

Quoted 6 lines
hw/net/igbvf.c +1 -0
+
     if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
         hw_error("Failed to initialize AER capability");
     }

--
2.40.1

#2 lore raw
Quoted 76 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Sriram Yagnaraman
Sent: Sunday, 28 May 2023 12:51
To: Cédric Le Goater <[email protected]>; [email protected]
Cc: Akihiko Odaki <[email protected]>; Jason Wang <[email protected]>
Subject: RE: [PATCH] igb: Add Function Level Reset to PF and VF

Quoted 6 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>;

Cédric

Quoted 5 lines

Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device

model.

Quoted 22 lines
Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")
---
 hw/net/igb.c   | 3 +++
 hw/net/igbvf.c | 3 +++
 2 files changed, 6 insertions(+)
hw/net/igb.c index renamed from hw/net/igb.c +0 -0

1c989d767725..08e389338dca
100644

hw/net/igb.c +1 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev,
 uint32_t addr,
 
     trace_igb_write_config(addr, val, len);
     pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 
     if (range_covers_byte(addr, len, PCI_COMMAND) &&
Quoted 1 line
         (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -

427,6

Quoted 28 lines

+428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error

hw/net/igb.c +3 -0
+**errp)
     }
 
     /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
     if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) {
         hw_error("Failed to initialize AER capability");
     }
hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
     trace_igbvf_write_config(addr, val, len);
     pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 }
 
 static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned

size) @@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
**errp)

         hw_error("Failed to initialize PCIe capability");
     }
Quoted 7 lines
Quoted 1 line

+ pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

Something like this perhaps? Not compile tested, just an idea.

hw/net/igbvf.c +10 -0
index 284ea61184..9f07983bc9 100644
@@ -283,9 +283,17 @@ static void igbvf_pci_uninit(PCIDevice *dev)
     msix_uninit(dev, &s->msix, &s->msix);
 }
 
+static void igbvf_qdev_reset_hold(Object *obj)
+{
+    trace_e1000e_cb_qdev_reset_hold();
+
+    igbvf_mmio_write(obj, E1000_CTRL, E1000_CTRL_RST, 0x4); /* Write to VTCTRL to trigger VF reset */
+}
+
 static void igbvf_class_init(ObjectClass *class, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(class);
+    ResettableClass *rc = RESETTABLE_CLASS(class);
     PCIDeviceClass *c = PCI_DEVICE_CLASS(class);
 
     c->realize = igbvf_pci_realize;
@@ -295,6 +303,8 @@ static void igbvf_class_init(ObjectClass *class, void *data)
     c->revision = 1;
     c->class_id = PCI_CLASS_NETWORK_ETHERNET;
 
+    rc->phases.hold = igbvf_qdev_reset_hold;
+
     dc->desc = "Intel 82576 Virtual Function";
     dc->user_creatable = false;
 
Quoted 6 lines
Quoted 6 lines

+

     if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
         hw_error("Failed to initialize AER capability");
     }

--
2.40.1

#3 lore raw
In reply to Sriram Yagnaraman
Quoted 60 lines · Sriram Yagnaraman
Quoted 60 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")
---
  hw/net/igb.c   | 3 +++
  hw/net/igbvf.c | 3 +++
  2 files changed, 6 insertions(+)
hw/net/igb.c index 1c989d767725..08e389338dca renamed from hw/net/igb.c +0 -0

100644

hw/net/igb.c +1 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, uint32_t
 addr,
 
      trace_igb_write_config(addr, val, len);
      pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 
      if (range_covers_byte(addr, len, PCI_COMMAND) &&
          (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -427,6
+428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
      }

      /* PCIe extended capabilities (in order) */
hw/net/igb.c +2 -0
+    pcie_cap_flr_init(pci_dev);
+
      if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) {
          hw_error("Failed to initialize AER capability");
      }
hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
      trace_igbvf_write_config(addr, val, len);
      pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
  }
 
  static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
 **errp)
          hw_error("Failed to initialize PCIe capability");
      }
 
Quoted 3 lines

hw/net/igbvf.c static void igbvf_pci_realize(PCIDevice *dev, Error **errp) · line 270

Quoted 1 line
hw/net/igbvf.c +1 -0
+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

Quoted 8 lines
Quoted 7 lines
hw/net/igbvf.c +1 -0
+
      if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
          hw_error("Failed to initialize AER capability");
      }

--
2.40.1

#4 lore raw
Quoted 61 lines · Akihiko Odaki
Quoted 60 lines · Sriram Yagnaraman
Quoted 60 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")

---
  hw/net/igb.c   | 3 +++
  hw/net/igbvf.c | 3 +++

  2 files changed, 6 insertions(+)
hw/net/igb.c index 1c989d767725..08e389338dca renamed from hw/net/igb.c +0 -0

100644

hw/net/igb.c +1 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, uint32_t
 addr,
 
       trace_igb_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 

      if (range_covers_byte(addr, len, PCI_COMMAND) && (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -427,6 +428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp) }

      /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
      if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
       trace_igbvf_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
   }
 
   static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
 **errp)
           hw_error("Failed to initialize PCIe capability");
       }
 
Quoted 3 lines
Quoted 3 lines

hw/net/igbvf.c static void igbvf_pci_realize(PCIDevice *dev, Error **errp) · line 270

Quoted 1 line
hw/net/igbvf.c +1 -0
+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

It does through the VTCTRL registers.

Quoted 1 line

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

I am not sure a VF needs more really, since it is all controlled by the PF.

C.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
hw/net/igbvf.c +1 -0
+
       if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
           hw_error("Failed to initialize AER capability");

      }

Signature · 1 line
2.40.1
#5 lore raw
Quoted 67 lines · Cédric Le Goater
Quoted 62 lines · Akihiko Odaki
Quoted 61 lines · Sriram Yagnaraman
Quoted 61 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")

---
  hw/net/igb.c   | 3 +++
  hw/net/igbvf.c | 3 +++

  2 files changed, 6 insertions(+)
hw/net/igb.c index 1c989d767725..08e389338dca renamed from hw/net/igb.c +0 -0

100644

hw/net/igb.c +0 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, 

uint32_t
addr,

      trace_igb_write_config(addr, val, len); pci_default_write_config(dev, addr, val, len); +    pcie_cap_flr_write_config(dev, addr, val, len);

      if (range_covers_byte(addr, len, PCI_COMMAND) && (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -427,6 +428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp) }

      /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
      if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
       trace_igbvf_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
   }
 
   static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
 **errp)
           hw_error("Failed to initialize PCIe capability");
       }
 
Quoted 3 lines
Quoted 3 lines

hw/net/igbvf.c static void igbvf_pci_realize(PCIDevice *dev, Error **errp) · line 270

Quoted 1 line
hw/net/igbvf.c +1 -0
+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

Quoted 8 lines

It does through the VTCTRL registers.

Quoted 1 line

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

They should be equivalent according to the datasheet, but unfortunately current igbvf implementation does nothing when reset. What Sriram proposes is to add code to actually write VTCTRL when FLR occurred and make FLR and software reset equivalent. And I think that should be done before this change; you should advertise FLR capability after the reset is actually implemented.

Regards,
Akihiko Odaki

Quoted 16 lines

I am not sure a VF needs more really, since it is all controlled by the PF. >
C.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
hw/net/igbvf.c +1 -0
+
       if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
           hw_error("Failed to initialize AER capability");

      }

Signature · 1 line
2.40.1
#6 lore raw
Quoted 69 lines · Akihiko Odaki
Quoted 68 lines · Cédric Le Goater
Quoted 61 lines · Akihiko Odaki
Quoted 60 lines · Sriram Yagnaraman
Quoted 60 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")

---
  hw/net/igb.c   | 3 +++
  hw/net/igbvf.c | 3 +++

  2 files changed, 6 insertions(+)
hw/net/igb.c index 1c989d767725..08e389338dca renamed from hw/net/igb.c +0 -0

100644

hw/net/igb.c +1 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, uint32_t
 addr,
 
       trace_igb_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 

      if (range_covers_byte(addr, len, PCI_COMMAND) && (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -427,6 +428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp) }

      /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
      if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
       trace_igbvf_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
   }
 
   static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
 **errp)
           hw_error("Failed to initialize PCIe capability");
       }
 
Quoted 3 lines
Quoted 3 lines

hw/net/igbvf.c static void igbvf_pci_realize(PCIDevice *dev, Error **errp) · line 270

Quoted 1 line
hw/net/igbvf.c +1 -0
+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

It does through the VTCTRL registers.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

They should be equivalent according to the datasheet, but unfortunately current igbvf implementation does nothing when reset. What Sriram proposes is to add code to actually write VTCTRL when FLR occurred and make FLR and software reset equivalent. And I think that should be done before this change; you should advertise FLR capability after the reset is actually implemented.

AFAICT, the VFs are reset correctly by the OS when created or probed and by QEMU when they are passthrough in a nested guest OS (with this patch). igb_vf_reset() is clearly called in QEMU, see routine e1000_reset_hw_vf() in Linux.

I don't think a reset op is necessary because VFs are software constructs but I don't mind really. If so, then, I wouldn't mimic what the OS does by writing the RST bit in the CTRL register of the VF, I would simply install igb_vf_reset() as a reset handler.

Thanks,

C.

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

I am not sure a VF needs more really, since it is all controlled by the PF. >
C.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
hw/net/igbvf.c +1 -0
+
       if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
           hw_error("Failed to initialize AER capability");

      }

Signature · 1 line
2.40.1
#7 lore raw
Quoted 81 lines · Cédric Le Goater
Quoted 80 lines · Akihiko Odaki
Quoted 78 lines · Cédric Le Goater
Quoted 65 lines · Akihiko Odaki
Quoted 64 lines · Sriram Yagnaraman
Quoted 64 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")

---
  hw/net/igb.c   | 3 +++
  hw/net/igbvf.c | 3 +++

  2 files changed, 6 insertions(+)
hw/net/igb.c index 1c989d767725..08e389338dca renamed from hw/net/igb.c +0 -0

100644

hw/net/igb.c +0 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, 

uint32_t
addr,

      trace_igb_write_config(addr, val, len); pci_default_write_config(dev, addr, val, len); +    pcie_cap_flr_write_config(dev, addr, val, len);

      if (range_covers_byte(addr, len, PCI_COMMAND) && (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -427,6
+428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
      }

      /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
      if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
       trace_igbvf_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
   }
 
   static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, 

Error
**errp)
          hw_error("Failed to initialize PCIe capability"); }

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

It does through the VTCTRL registers.

Quoted 1 line

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

Quoted 7 lines
Quoted 1 line

They should be equivalent according to the datasheet, but unfortunately current igbvf implementation does nothing when reset. What Sriram proposes is to add code to actually write VTCTRL when FLR occurred and make FLR and software reset equivalent. And I think that should be done before this change; you should advertise FLR capability after the reset is actually implemented.

AFAICT, the VFs are reset correctly by the OS when created or probed and by QEMU when they are passthrough in a nested guest OS (with this patch). igb_vf_reset() is clearly called in QEMU, see routine e1000_reset_hw_vf() in Linux.

I don't think this patch makes difference for e1000_reset_hw_vf() as it does not rely on FLR.

Quoted 5 lines

I don't think a reset op is necessary because VFs are software constructs but I don't mind really. If so, then, I wouldn't mimic what the OS does by writing the RST bit in the CTRL register of the VF, I would simply install igb_vf_reset() as a reset handler.

Thinking about the reason why VFIO performs FLR, probably VFIO expects the FLR clears all of states the kernel set to prevent the VF from leaking kernel addresses or addresses of other user space which the VF was assigned to in the past, for example.

Implementing the reset operation is not necessary to make it function but to make it secure, particularly we promise the guest that we clear the VF state by advertising FLR.

Regards,
Akihiko Odaki

Quoted 29 lines

Thanks,

C.

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

I am not sure a VF needs more really, since it is all controlled by the PF. >
C.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

+
      if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

Signature · 1 line
2.40.1
#8 lore raw
Quoted 128 lines

-----Original Message-----
From: Akihiko Odaki <[email protected]>
Sent: Tuesday, 30 May 2023 04:02
To: Cédric Le Goater <[email protected]>; Sriram Yagnaraman <[email protected]>; [email protected]
Cc: Jason Wang <[email protected]>
Subject: Re: [PATCH] igb: Add Function Level Reset to PF and VF

Quoted 11 lines · Cédric Le Goater
Quoted 10 lines · Akihiko Odaki
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines · Akihiko Odaki
Quoted 7 lines · Sriram Yagnaraman
Quoted 7 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang

<[email protected]>;

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")

---
  hw/net/igb.c   | 3 +++
  hw/net/igbvf.c | 3 +++

  2 files changed, 6 insertions(+)
hw/net/igb.c index renamed from hw/net/igb.c +0 -0

1c989d767725..08e389338dca
100644

hw/net/igb.c +0 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev,
 uint32_t addr,
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/net/igb.c +1 -0
       trace_igb_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 

      if (range_covers_byte(addr, len, PCI_COMMAND) && (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {

@@

Quoted 55 lines
Quoted 47 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

-427,6
+428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
      }

      /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
      if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice
 *dev, uint32_t addr, uint32_t val,  {
       trace_igbvf_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
   }
 
   static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr,

unsigned size) @@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
**errp)
          hw_error("Failed to initialize PCIe capability"); }

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

It does through the VTCTRL registers.

Quoted 8 lines
Quoted 3 lines

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

Quoted 6 lines

They should be equivalent according to the datasheet, but unfortunately current igbvf implementation does nothing when reset. What Sriram proposes is to add code to actually write VTCTRL when FLR occurred and make FLR and software reset equivalent. And I think that should be done before this change; you should advertise FLR capability after the reset is actually implemented.

Quoted 2 lines

AFAICT, the VFs are reset correctly by the OS when created or probed and by QEMU when they are passthrough in a nested guest OS (with this

patch).

Quoted 2 lines

igb_vf_reset() is clearly called in QEMU, see routine e1000_reset_hw_vf() in Linux.

I don't think this patch makes difference for e1000_reset_hw_vf() as it does not rely on FLR.

Quoted 5 lines

I don't think a reset op is necessary because VFs are software constructs but I don't mind really. If so, then, I wouldn't mimic what the OS does by writing the RST bit in the CTRL register of the VF, I would simply install igb_vf_reset() as a reset handler.

Thinking about the reason why VFIO performs FLR, probably VFIO expects the FLR clears all of states the kernel set to prevent the VF from leaking kernel addresses or addresses of other user space which the VF was assigned to in the past, for example.

Quoted 7 lines

Implementing the reset operation is not necessary to make it function but to make it secure, particularly we promise the guest that we clear the VF state by advertising FLR.

Regards,
Akihiko Odaki

I did some digging, and I can see that the linux igbvf device driver registers for FLR and performs a SW reset anyhow.
https://lore.kernel.org/all/[email protected]/
I have not checked what the other drivers do though, I can send a patch if you think it is worth having a reset operation on the igbvf device.

Quoted 28 lines
Quoted 28 lines

Thanks,

C.

Quoted 20 lines

Regards,
Akihiko Odaki

Quoted 15 lines

I am not sure a VF needs more really, since it is all controlled by the PF. > C.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

+
      if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }
--
2.40.1

#9 lore raw
Quoted 132 lines · Sriram Yagnaraman
Quoted 132 lines

-----Original Message-----
From: Akihiko Odaki <[email protected]>
Sent: Tuesday, 30 May 2023 04:02
To: Cédric Le Goater <[email protected]>; Sriram Yagnaraman <[email protected]>; [email protected]
Cc: Jason Wang <[email protected]>
Subject: Re: [PATCH] igb: Add Function Level Reset to PF and VF

Quoted 11 lines · Cédric Le Goater
Quoted 10 lines · Akihiko Odaki
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines · Akihiko Odaki
Quoted 7 lines · Sriram Yagnaraman
Quoted 7 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang

<[email protected]>;

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")
---
   hw/net/igb.c   | 3 +++
   hw/net/igbvf.c | 3 +++
   2 files changed, 6 insertions(+)
hw/net/igb.c index renamed from hw/net/igb.c +0 -0

1c989d767725..08e389338dca
100644

hw/net/igb.c +0 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev,
 uint32_t addr,
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/net/igb.c +1 -0
       trace_igb_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 
       if (range_covers_byte(addr, len, PCI_COMMAND) &&

          (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {

@@

Quoted 55 lines
Quoted 47 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

-427,6
+428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
      }

      /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);

hw/net/igb.c +1 -0
+
       if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) {
           hw_error("Failed to initialize AER capability");
       }
hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice
 *dev, uint32_t addr, uint32_t val,  {
       trace_igbvf_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
   }
 
   static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr,

unsigned size) @@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
**errp)
          hw_error("Failed to initialize PCIe capability"); }

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

It does through the VTCTRL registers.

Quoted 8 lines
Quoted 3 lines

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

Quoted 6 lines

They should be equivalent according to the datasheet, but unfortunately current igbvf implementation does nothing when reset. What Sriram proposes is to add code to actually write VTCTRL when FLR occurred and make FLR and software reset equivalent. And I think that should be done before this change; you should advertise FLR capability after the reset is actually implemented.

Quoted 2 lines

AFAICT, the VFs are reset correctly by the OS when created or probed and by QEMU when they are passthrough in a nested guest OS (with this

patch).

Quoted 2 lines

igb_vf_reset() is clearly called in QEMU, see routine e1000_reset_hw_vf() in Linux.

I don't think this patch makes difference for e1000_reset_hw_vf() as it does not rely on FLR.

Quoted 5 lines

I don't think a reset op is necessary because VFs are software constructs but I don't mind really. If so, then, I wouldn't mimic what the OS does by writing the RST bit in the CTRL register of the VF, I would simply install igb_vf_reset() as a reset handler.

Thinking about the reason why VFIO performs FLR, probably VFIO expects the FLR clears all of states the kernel set to prevent the VF from leaking kernel addresses or addresses of other user space which the VF was assigned to in the past, for example.

Implementing the reset operation is not necessary to make it function but to make it secure, particularly we promise the guest that we clear the VF state by advertising FLR.

Quoted 6 lines
Quoted 3 lines

Regards,
Akihiko Odaki

I did some digging, and I can see that the linux igbvf device driver registers for FLR and performs a SW reset anyhow.
https://lore.kernel.org/all/[email protected]/

The register function in the Linux driver should be considered as something different from FLR. FLR we have discussed is a PCIe capability that the hardware advertises.

Quoted 1 line

I have not checked what the other drivers do though, I can send a patch if you think it is worth having a reset operation on the igbvf device.

I think it's better if Cédric writes such a patch and place it before the patch to advertise FLR in a series. It will be easier to make the patches in order this way.

Regards,
Akihiko Odaki

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

Thanks,

C.

Quoted 20 lines

Regards,
Akihiko Odaki

Quoted 15 lines

I am not sure a VF needs more really, since it is all controlled by the PF. > C.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

+
      if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }
--
2.40.1

#10 lore raw
Quoted 137 lines · Akihiko Odaki
Quoted 136 lines · Sriram Yagnaraman
Quoted 135 lines

-----Original Message-----
From: Akihiko Odaki <[email protected]>
Sent: Tuesday, 30 May 2023 04:02
To: Cédric Le Goater <[email protected]>; Sriram Yagnaraman <[email protected]>; [email protected]
Cc: Jason Wang <[email protected]>
Subject: Re: [PATCH] igb: Add Function Level Reset to PF and VF

Quoted 11 lines · Cédric Le Goater
Quoted 10 lines · Akihiko Odaki
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines · Akihiko Odaki
Quoted 7 lines · Sriram Yagnaraman
Quoted 7 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang

<[email protected]>;

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")

---
   hw/net/igb.c   | 3 +++
   hw/net/igbvf.c | 3 +++

   2 files changed, 6 insertions(+)
hw/net/igb.c index renamed from hw/net/igb.c +0 -0

1c989d767725..08e389338dca
100644

hw/net/igb.c +0 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev,
 uint32_t addr,
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/net/igb.c +1 -0
        trace_igb_write_config(addr, val, len);
        pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 

       if (range_covers_byte(addr, len, PCI_COMMAND) && (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {

@@

Quoted 55 lines
Quoted 47 lines
Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

-427,6
+428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp)
       }

       /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
       if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice
 *dev, uint32_t addr, uint32_t val,  {
        trace_igbvf_write_config(addr, val, len);
        pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
    }
 
    static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr,

unsigned size) @@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
**errp)
           hw_error("Failed to initialize PCIe capability"); }

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

It does through the VTCTRL registers.

Quoted 8 lines
Quoted 3 lines

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

Quoted 6 lines

They should be equivalent according to the datasheet, but unfortunately current igbvf implementation does nothing when reset. What Sriram proposes is to add code to actually write VTCTRL when FLR occurred and make FLR and software reset equivalent. And I think that should be done before this change; you should advertise FLR capability after the reset is actually implemented.

Quoted 2 lines

AFAICT, the VFs are reset correctly by the OS when created or probed and by QEMU when they are passthrough in a nested guest OS (with this

patch).

Quoted 2 lines

igb_vf_reset() is clearly called in QEMU, see routine e1000_reset_hw_vf() in Linux.

I don't think this patch makes difference for e1000_reset_hw_vf() as it does not rely on FLR.

Quoted 5 lines

I don't think a reset op is necessary because VFs are software constructs but I don't mind really. If so, then, I wouldn't mimic what the OS does by writing the RST bit in the CTRL register of the VF, I would simply install igb_vf_reset() as a reset handler.

Thinking about the reason why VFIO performs FLR, probably VFIO expects the FLR clears all of states the kernel set to prevent the VF from leaking kernel addresses or addresses of other user space which the VF was assigned to in the past, for example.

Implementing the reset operation is not necessary to make it function but to make it secure, particularly we promise the guest that we clear the VF state by advertising FLR.

Regards,
Akihiko Odaki

Quoted 8 lines
Quoted 2 lines

I did some digging, and I can see that the linux igbvf device driver registers for FLR and performs a SW reset anyhow.
https://lore.kernel.org/all/[email protected]/

The register function in the Linux driver should be considered as something different from FLR. FLR we have discussed is a PCIe capability that the hardware advertises.

Quoted 1 line

I have not checked what the other drivers do though, I can send a patch if you think it is worth having a reset operation on the igbvf device.

I think it's better if Cédric writes such a patch and place it before the patch to advertise FLR in a series. It will be easier to make the patches in order this way.

ok. Will do.

Thanks,

C.

#11 lore raw
In reply to Akihiko Odaki
Quoted 89 lines · Akihiko Odaki
Quoted 77 lines · Cédric Le Goater
Quoted 76 lines · Akihiko Odaki
Quoted 74 lines · Cédric Le Goater
Quoted 61 lines · Akihiko Odaki
Quoted 60 lines · Sriram Yagnaraman
Quoted 60 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Friday, 26 May 2023 19:31
To: [email protected]
Cc: Akihiko Odaki <[email protected]>; Sriram Yagnaraman <[email protected]>; Jason Wang <[email protected]>; Cédric Le Goater <[email protected]>
Subject: [PATCH] igb: Add Function Level Reset to PF and VF

The Intel 82576EB GbE Controller say that the Physical and Virtual Functions support Function Level Reset. Add the capability to each device model.

Cc Akihiko Odaki <[email protected]>
Fixes 3a977deebe6b ("Intrdocue igb device emulation")

---
  hw/net/igb.c   | 3 +++
  hw/net/igbvf.c | 3 +++

  2 files changed, 6 insertions(+)
hw/net/igb.c index 1c989d767725..08e389338dca renamed from hw/net/igb.c +0 -0

100644

hw/net/igb.c +1 -0
@@ -101,6 +101,7 @@ static void igb_write_config(PCIDevice *dev, uint32_t
 addr,
 
       trace_igb_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
 

      if (range_covers_byte(addr, len, PCI_COMMAND) && (dev->config[PCI_COMMAND] & PCI_COMMAND_MASTER)) { @@ -427,6 +428,8 @@ static void igb_pci_realize(PCIDevice *pci_dev, Error **errp) }

      /* PCIe extended capabilities (in order) */
+    pcie_cap_flr_init(pci_dev);
+
      if (pcie_aer_init(pci_dev, 1, 0x100, 0x40, errp) < 0) { hw_error("Failed to initialize AER capability"); }

hw/net/igbvf.c index renamed from hw/net/igbvf.c +0 -0

284ea611848b..0a58dad06802 100644

hw/net/igbvf.c +1 -0
@@ -204,6 +204,7 @@ static void igbvf_write_config(PCIDevice *dev,
 uint32_t addr, uint32_t val,  {
       trace_igbvf_write_config(addr, val, len);
       pci_default_write_config(dev, addr, val, len);
+    pcie_cap_flr_write_config(dev, addr, val, len);
   }
 
   static uint64_t igbvf_mmio_read(void *opaque, hwaddr addr, unsigned size)
@@ -266,6 +267,8 @@ static void igbvf_pci_realize(PCIDevice *dev, Error
 **errp)
           hw_error("Failed to initialize PCIe capability");
       }
 
Quoted 3 lines
Quoted 3 lines

hw/net/igbvf.c static void igbvf_pci_realize(PCIDevice *dev, Error · line 271

Quoted 1 line
hw/net/igbvf.c +1 -0
+    pcie_cap_flr_init(dev);

Sorry for my naive question, and perhaps not related to your patch, IGBVF device class doesn't seem to have any reset functions registered via igbvf_class_init(). So, I am guessing an FLR will not trigger igb_vf_reset(), which is probably what we want.

It does through the VTCTRL registers.

Quoted 1 line

You're right. Advertising FLR capability without implementing it can confuse the guest though such probability is quite a low in practice. The reset should be implemented first.

I was looking at an issue from a VFIO perspective which does a FLR on a device when pass through. Software and FLR are equivalent for a VF.

Quoted 7 lines
Quoted 1 line

They should be equivalent according to the datasheet, but unfortunately current igbvf implementation does nothing when reset. What Sriram proposes is to add code to actually write VTCTRL when FLR occurred and make FLR and software reset equivalent. And I think that should be done before this change; you should advertise FLR capability after the reset is actually implemented.

AFAICT, the VFs are reset correctly by the OS when created or probed and by QEMU when they are passthrough in a nested guest OS (with this patch). igb_vf_reset() is clearly called in QEMU, see routine e1000_reset_hw_vf() in Linux.

I don't think this patch makes difference for e1000_reset_hw_vf() as it does not rely on FLR.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

I don't think a reset op is necessary because VFs are software constructs but I don't mind really. If so, then, I wouldn't mimic what the OS does by writing the RST bit in the CTRL register of the VF, I would simply install igb_vf_reset() as a reset handler.

Thinking about the reason why VFIO performs FLR, probably VFIO expects the FLR clears all of states the kernel set to prevent the VF from leaking kernel addresses or addresses of other user space which the VF was assigned to in the past, for example.

yes and if the FLR cap is not present, VFIO tries to do a custom bus reset which fails in an ugly way since the PF can not be reset.

Thanks

C.

Quoted 36 lines

Implementing the reset operation is not necessary to make it function but to make it secure, particularly we promise the guest that we clear the VF state by advertising FLR.

Regards,
Akihiko Odaki

Quoted 29 lines

Thanks,

C.

Quoted 21 lines

Regards,
Akihiko Odaki

Quoted 16 lines

I am not sure a VF needs more really, since it is all controlled by the PF. >
C.

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
hw/net/igbvf.c +1 -0
+
       if (pcie_aer_init(dev, 1, 0x100, 0x40, errp) < 0) {
           hw_error("Failed to initialize AER capability");

      }

Signature · 1 line
2.40.1