Skip to contentSkip to conversation

ixgbe: support MDD events

PATCH Superseded Michal Swiatkowski 2 participants 9 messages Feb 12, 2025 – Feb 13, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ixgbe: support MDD events

Hi,

This patchset is adding support for MDD (malicious driver detection) for ixgbe driver. It can catch the error on VF side and reset malicious VF.

An MDD event can be triggered for example by sending from VF a TSO packet with segment number set to 0.

Add checking for Tx hang in case of MDD is unhandled. It will prevent VF from staying in Tx hang state.

v1 --> v2: [1]
(All from Simon review, thanks)
* change wqbr variable type in patch 1 to fix -Warray-bounds build
* fix indend to be done by space to follow existing style (patch 3)
* move e_warn() to be in one line because it fit (patch 3)

[1] https://lore.kernel.org/netdev/[email protected]/

Don Skidmore (1):
ixgbe: check for MDD events

Paul Greenwalt (1):
ixgbe: add MDD support

Radoslaw Tyl (1):
ixgbe: turn off MDD while modifying SRRCTL

Slawomir Mrozowicz (1):
ixgbe: add Tx hang detection unhandled MDD

 drivers/net/ethernet/intel/ixgbe/ixgbe.h      |   5 +
 .../net/ethernet/intel/ixgbe/ixgbe_sriov.h    |   1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  42 +++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h |   5 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c |   4 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c  |   3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 223 ++++++++++++++++--
 .../net/ethernet/intel/ixgbe/ixgbe_sriov.c    |  50 ++++
 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c | 120 ++++++++++
 9 files changed, 430 insertions(+), 23 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH v2 1/4 ixgbe: add MDD support

From: Paul Greenwalt <[email protected]>

Add malicious driver detection. Support enabling MDD, disabling MDD, handling a MDD event, and restoring a MDD VF.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  28 ++++
 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h |   5 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c |   4 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c | 120 ++++++++++++++++++
 4 files changed, 157 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_type.h +28 -0
index 5fdf32d79d82..d446c375335a 100644
@@ -2746,6 +2746,28 @@ enum ixgbe_fdir_pballoc_type {
 #define FW_PHY_INFO_ID_HI_MASK		0xFFFF0000u
 #define FW_PHY_INFO_ID_LO_MASK		0x0000FFFFu
 
+/* There are only 3 options for VFs creation on this device:
+ * 16 VFs pool with 8 queues each
+ * 32 VFs pool with 4 queues each
+ * 64 VFs pool with 2 queues each
+ *
+ * That means reading some VF registers that map VF to queue depending on
+ * chosen option. Define values that help dealing with each scenario.
+ */
+/* Number of queues based on VFs pool */
+#define IXGBE_16VFS_QUEUES		8
+#define IXGBE_32VFS_QUEUES		4
+#define IXGBE_64VFS_QUEUES		2
+/* Mask for getting queues bits based on VFs pool */
+#define IXGBE_16VFS_BITMASK		GENMASK(IXGBE_16VFS_QUEUES - 1, 0)
+#define IXGBE_32VFS_BITMASK		GENMASK(IXGBE_32VFS_QUEUES - 1, 0)
+#define IXGBE_64VFS_BITMASK		GENMASK(IXGBE_64VFS_QUEUES - 1, 0)
+/* Convert queue index to register number.
+ * We have 4 registers with 32 queues in each.
+ */
+#define IXGBE_QUEUES_PER_REG		32
+#define IXGBE_QUEUES_REG_AMOUNT		4
+
 /* Host Interface Command Structures */
 struct ixgbe_hic_hdr {
 	u8 cmd;
@@ -3534,6 +3556,12 @@ struct ixgbe_mac_operations {
 	int (*dmac_config_tcs)(struct ixgbe_hw *hw);
 	int (*read_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32 *);
 	int (*write_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32);
+
+	/* MDD events */
+	void (*enable_mdd)(struct ixgbe_hw *hw);
+	void (*disable_mdd)(struct ixgbe_hw *hw);
+	void (*restore_mdd_vf)(struct ixgbe_hw *hw, u32 vf);
+	void (*handle_mdd)(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
 };
 
 struct ixgbe_phy_operations {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h +5 -0
index 3e4092f8da3e..2a11147fb1bc 100644
@@ -17,4 +17,9 @@ void ixgbe_set_source_address_pruning_x550(struct ixgbe_hw *hw,
 void ixgbe_set_ethertype_anti_spoofing_x550(struct ixgbe_hw *hw,
 					    bool enable, int vf);
 
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf);
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
+
 #endif /* _IXGBE_X550_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c +4 -0
index cb07ecd8937d..788f3372ebf1 100644
@@ -2630,6 +2630,10 @@ static const struct ixgbe_mac_operations mac_ops_e610 = {
 	.prot_autoc_write		= prot_autoc_write_generic,
 	.setup_fc			= ixgbe_setup_fc_e610,
 	.fc_autoneg			= ixgbe_fc_autoneg_e610,
+	.enable_mdd			= ixgbe_enable_mdd_x550,
+	.disable_mdd			= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf			= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd			= ixgbe_handle_mdd_x550,
 };
 
 static const struct ixgbe_phy_operations phy_ops_e610 = {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +120 -0

132 lines not on this page · raw message

Signature · 1 line
2.42.0
#2 lore raw

Re: [Intel-wired-lan] [iwl-next v2 1/4] ixgbe: add MDD support

Dear Michal, dear Paul,

Thank you for your patch. For the summary/title you could use:

ixgbe: Support Malicious Driver Detection (MDD)

Am 12.02.25 um 08:57 schrieb Michal Swiatkowski:

Quoted 4 lines

From: Paul Greenwalt <[email protected]>

Add malicious driver detection. Support enabling MDD, disabling MDD, handling a MDD event, and restoring a MDD VF.

a*n* MDD

Could you please elaborate? List the commands to enable/disable MDD?

Also, please include a reference to the datasheet section for this feature. I am a little confused, as the Linux driver should never be “malicious”, shouldn’t it? So what is this feature?

Which devices support this? From the diff it looks like X550? Please add that.

How did you test it?

How are the events logged?

Quoted 165 lines
---
  drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  28 ++++
  drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h |   5 +
  drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c |   4 +
  drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c | 120 ++++++++++++++++++
  4 files changed, 157 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_type.h +28 -0
index 5fdf32d79d82..d446c375335a 100644
@@ -2746,6 +2746,28 @@ enum ixgbe_fdir_pballoc_type {
  #define FW_PHY_INFO_ID_HI_MASK		0xFFFF0000u
  #define FW_PHY_INFO_ID_LO_MASK		0x0000FFFFu
 
+/* There are only 3 options for VFs creation on this device:
+ * 16 VFs pool with 8 queues each
+ * 32 VFs pool with 4 queues each
+ * 64 VFs pool with 2 queues each
+ *
+ * That means reading some VF registers that map VF to queue depending on
+ * chosen option. Define values that help dealing with each scenario.
+ */
+/* Number of queues based on VFs pool */
+#define IXGBE_16VFS_QUEUES		8
+#define IXGBE_32VFS_QUEUES		4
+#define IXGBE_64VFS_QUEUES		2
+/* Mask for getting queues bits based on VFs pool */
+#define IXGBE_16VFS_BITMASK		GENMASK(IXGBE_16VFS_QUEUES - 1, 0)
+#define IXGBE_32VFS_BITMASK		GENMASK(IXGBE_32VFS_QUEUES - 1, 0)
+#define IXGBE_64VFS_BITMASK		GENMASK(IXGBE_64VFS_QUEUES - 1, 0)
+/* Convert queue index to register number.
+ * We have 4 registers with 32 queues in each.
+ */
+#define IXGBE_QUEUES_PER_REG		32
+#define IXGBE_QUEUES_REG_AMOUNT		4
+
  /* Host Interface Command Structures */
  struct ixgbe_hic_hdr {
  	u8 cmd;
@@ -3534,6 +3556,12 @@ struct ixgbe_mac_operations {
  	int (*dmac_config_tcs)(struct ixgbe_hw *hw);
  	int (*read_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32 *);
  	int (*write_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32);
+
+	/* MDD events */
+	void (*enable_mdd)(struct ixgbe_hw *hw);
+	void (*disable_mdd)(struct ixgbe_hw *hw);
+	void (*restore_mdd_vf)(struct ixgbe_hw *hw, u32 vf);
+	void (*handle_mdd)(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
  };
 
  struct ixgbe_phy_operations {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h +5 -0
index 3e4092f8da3e..2a11147fb1bc 100644
@@ -17,4 +17,9 @@ void ixgbe_set_source_address_pruning_x550(struct ixgbe_hw *hw,
  void ixgbe_set_ethertype_anti_spoofing_x550(struct ixgbe_hw *hw,
  					    bool enable, int vf);
 
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf);
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
+
  #endif /* _IXGBE_X550_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c +4 -0
index cb07ecd8937d..788f3372ebf1 100644
@@ -2630,6 +2630,10 @@ static const struct ixgbe_mac_operations mac_ops_e610 = {
  	.prot_autoc_write		= prot_autoc_write_generic,
  	.setup_fc			= ixgbe_setup_fc_e610,
  	.fc_autoneg			= ixgbe_fc_autoneg_e610,
+	.enable_mdd			= ixgbe_enable_mdd_x550,
+	.disable_mdd			= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf			= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd			= ixgbe_handle_mdd_x550,
  };
 
  static const struct ixgbe_phy_operations phy_ops_e610 = {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +70 -0
index 277ceaf8a793..b5cbfd1f71fd 100644
@@ -3800,6 +3800,122 @@ static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
  	return status;
  }
 
+static void ixgbe_set_mdd_x550(struct ixgbe_hw *hw, bool ena)
+{
+	u32 reg_dma, reg_rdr;
+
+	reg_dma = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
+	reg_rdr = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
+
+	if (ena) {
+		reg_dma |= (IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr |= (IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	} else {
+		reg_dma &= ~(IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr &= ~(IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	}
+
+	IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_dma);
+	IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg_rdr);
+}
+
+/**
+ * ixgbe_enable_mdd_x550 - enable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, true);
+}
+
+/**
+ * ixgbe_disable_mdd_x550 - disable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, false);
+}
+
+/**
+ * ixgbe_restore_mdd_vf_x550 - restore VF that was disabled during MDD event
+ * @hw: pointer to hardware structure
+ * @vf: vf index
+ */
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf)
+{
+	u32 idx, reg, val, num_qs, start_q, bitmask;
+
+	/* Map VF to queues */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		num_qs = IXGBE_16VFS_QUEUES;
+		bitmask = IXGBE_16VFS_BITMASK;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		num_qs = IXGBE_32VFS_QUEUES;
+		bitmask = IXGBE_32VFS_BITMASK;
+		break;
+	default:
+		num_qs = IXGBE_64VFS_QUEUES;
+		bitmask = IXGBE_64VFS_BITMASK;
+		break;
+	}
+	start_q = vf * num_qs;
+
+	/* Release vf's queues by clearing WQBR_TX and WQBR_RX (RW1C) */
+	idx = start_q / IXGBE_QUEUES_PER_REG;
+	val = bitmask << (start_q % IXGBE_QUEUES_PER_REG);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_TX(idx), val);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_RX(idx), val);

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr, · line 3882

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +10 -0
+}
+
+/**
+ * ixgbe_handle_mdd_x550 - handle malicious driver detection event
+ * @hw: pointer to hardware structure
+ * @vf_bitmap: output vf bitmap of malicious vfs
+ */
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap)
+{
+	u32 i, j, reg, q, div, vf;

Why fix the length of the count variables?

Quoted 40 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +36 -0
+	unsigned long wqbr;
+
+	/* figure out pool size for mapping to vf's */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		div = IXGBE_16VFS_QUEUES;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		div = IXGBE_32VFS_QUEUES;
+		break;
+	default:
+		div = IXGBE_64VFS_QUEUES;
+		break;
+	}
+
+	/* Read WQBR_TX and WQBR_RX and check for malicious queues */
+	for (i = 0; i < IXGBE_QUEUES_REG_AMOUNT; i++) {
+		wqbr = IXGBE_READ_REG(hw, IXGBE_WQBR_TX(i)) |
+		       IXGBE_READ_REG(hw, IXGBE_WQBR_RX(i));
+		if (!wqbr)
+			continue;
+
+		/* Get malicious queue */
+		for_each_set_bit(j, (unsigned long *)&wqbr,
+				 IXGBE_QUEUES_PER_REG) {
+			/* Get queue from bitmask */
+			q = j + (i * IXGBE_QUEUES_PER_REG);
+			/* Map queue to vf */
+			vf = q / div;
+			set_bit(vf, vf_bitmap);
+		}
+	}
+}
+
  #define X550_COMMON_MAC \
  	.init_hw			= &ixgbe_init_hw_generic, \
  	.start_hw			= &ixgbe_start_hw_X540, \

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static const struct ixgbe_mac_operations mac_ops_X550 = { · line 3988

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +4 -0
@@ -3863,6 +3979,10 @@ static const struct ixgbe_mac_operations mac_ops_X550 = {
  	.prot_autoc_write	= prot_autoc_write_generic,
  	.setup_fc		= ixgbe_setup_fc_generic,
  	.fc_autoneg		= ixgbe_fc_autoneg,
+	.enable_mdd		= ixgbe_enable_mdd_x550,
+	.disable_mdd		= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf		= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd		= ixgbe_handle_mdd_x550,
  };
 
  static const struct ixgbe_mac_operations mac_ops_X550EM_x = {

Kind regards,

Paul

#3 lore raw

Re: [Intel-wired-lan] [iwl-next v2 1/4] ixgbe: add MDD support

Quoted 21 lines · Paul Menzel

Dear Michal, dear Paul,

Thank you for your patch. For the summary/title you could use:

ixgbe: Support Malicious Driver Detection (MDD)

Am 12.02.25 um 08:57 schrieb Michal Swiatkowski:

Quoted 4 lines

From: Paul Greenwalt <[email protected]>

Add malicious driver detection. Support enabling MDD, disabling MDD, handling a MDD event, and restoring a MDD VF.

a*n* MDD

Could you please elaborate? List the commands to enable/disable MDD?

Also, please include a reference to the datasheet section for this feature. I am a little confused, as the Linux driver should never be “malicious”, shouldn’t it? So what is this feature?

Quoted 6 lines

Which devices support this? From the diff it looks like X550? Please add that.

How did you test it?

How are the events logged?

Hi,

I will elaborate it in the commit message if it is needed. The VF created on X550 device can use malicious driver for example. I tested it by changing Tx descriptor to be invalid (TSO on, with invalid length in descriptor, but any type of invalid descriptor should cause MDD).

It is enabled all time. Simple netif_warn() is called with more information about MDD. After 4 events on the same VF the link status is force to be down to turn off malicious VF.

Quoted 165 lines
Quoted 165 lines
---
  drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  28 ++++
  drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h |   5 +
  drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c |   4 +
  drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c | 120 ++++++++++++++++++
  4 files changed, 157 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_type.h +28 -0
index 5fdf32d79d82..d446c375335a 100644
@@ -2746,6 +2746,28 @@ enum ixgbe_fdir_pballoc_type {
  #define FW_PHY_INFO_ID_HI_MASK		0xFFFF0000u
  #define FW_PHY_INFO_ID_LO_MASK		0x0000FFFFu
+/* There are only 3 options for VFs creation on this device:
+ * 16 VFs pool with 8 queues each
+ * 32 VFs pool with 4 queues each
+ * 64 VFs pool with 2 queues each
+ *
+ * That means reading some VF registers that map VF to queue depending on
+ * chosen option. Define values that help dealing with each scenario.
+ */
+/* Number of queues based on VFs pool */
+#define IXGBE_16VFS_QUEUES		8
+#define IXGBE_32VFS_QUEUES		4
+#define IXGBE_64VFS_QUEUES		2
+/* Mask for getting queues bits based on VFs pool */
+#define IXGBE_16VFS_BITMASK		GENMASK(IXGBE_16VFS_QUEUES - 1, 0)
+#define IXGBE_32VFS_BITMASK		GENMASK(IXGBE_32VFS_QUEUES - 1, 0)
+#define IXGBE_64VFS_BITMASK		GENMASK(IXGBE_64VFS_QUEUES - 1, 0)
+/* Convert queue index to register number.
+ * We have 4 registers with 32 queues in each.
+ */
+#define IXGBE_QUEUES_PER_REG		32
+#define IXGBE_QUEUES_REG_AMOUNT		4
+
  /* Host Interface Command Structures */
  struct ixgbe_hic_hdr {
  	u8 cmd;
@@ -3534,6 +3556,12 @@ struct ixgbe_mac_operations {
  	int (*dmac_config_tcs)(struct ixgbe_hw *hw);
  	int (*read_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32 *);
  	int (*write_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32);
+
+	/* MDD events */
+	void (*enable_mdd)(struct ixgbe_hw *hw);
+	void (*disable_mdd)(struct ixgbe_hw *hw);
+	void (*restore_mdd_vf)(struct ixgbe_hw *hw, u32 vf);
+	void (*handle_mdd)(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
  };
  struct ixgbe_phy_operations {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h +5 -0
index 3e4092f8da3e..2a11147fb1bc 100644
@@ -17,4 +17,9 @@ void ixgbe_set_source_address_pruning_x550(struct ixgbe_hw *hw,
  void ixgbe_set_ethertype_anti_spoofing_x550(struct ixgbe_hw *hw,
  					    bool enable, int vf);
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf);
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
+
  #endif /* _IXGBE_X550_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c +4 -0
index cb07ecd8937d..788f3372ebf1 100644
@@ -2630,6 +2630,10 @@ static const struct ixgbe_mac_operations mac_ops_e610 = {
  	.prot_autoc_write		= prot_autoc_write_generic,
  	.setup_fc			= ixgbe_setup_fc_e610,
  	.fc_autoneg			= ixgbe_fc_autoneg_e610,
+	.enable_mdd			= ixgbe_enable_mdd_x550,
+	.disable_mdd			= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf			= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd			= ixgbe_handle_mdd_x550,
  };
  static const struct ixgbe_phy_operations phy_ops_e610 = {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +74 -0
index 277ceaf8a793..b5cbfd1f71fd 100644
@@ -3800,6 +3800,122 @@ static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
  	return status;
  }
+static void ixgbe_set_mdd_x550(struct ixgbe_hw *hw, bool ena)
+{
+	u32 reg_dma, reg_rdr;
+
+	reg_dma = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
+	reg_rdr = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
+
+	if (ena) {
+		reg_dma |= (IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr |= (IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	} else {
+		reg_dma &= ~(IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr &= ~(IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	}
+
+	IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_dma);
+	IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg_rdr);
+}
+
+/**
+ * ixgbe_enable_mdd_x550 - enable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, true);
+}
+
+/**
+ * ixgbe_disable_mdd_x550 - disable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, false);
+}
+
+/**
+ * ixgbe_restore_mdd_vf_x550 - restore VF that was disabled during MDD event
+ * @hw: pointer to hardware structure
+ * @vf: vf index
+ */
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf)
+{
+	u32 idx, reg, val, num_qs, start_q, bitmask;
+
+	/* Map VF to queues */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		num_qs = IXGBE_16VFS_QUEUES;
+		bitmask = IXGBE_16VFS_BITMASK;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		num_qs = IXGBE_32VFS_QUEUES;
+		bitmask = IXGBE_32VFS_BITMASK;
+		break;
+	default:
+		num_qs = IXGBE_64VFS_QUEUES;
+		bitmask = IXGBE_64VFS_BITMASK;
+		break;
+	}
+	start_q = vf * num_qs;
+
+	/* Release vf's queues by clearing WQBR_TX and WQBR_RX (RW1C) */
+	idx = start_q / IXGBE_QUEUES_PER_REG;
+	val = bitmask << (start_q % IXGBE_QUEUES_PER_REG);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_TX(idx), val);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_RX(idx), val);
+}
+
+/**
+ * ixgbe_handle_mdd_x550 - handle malicious driver detection event
Quoted 9 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr, · line 3882

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +6 -0
+ * @hw: pointer to hardware structure
+ * @vf_bitmap: output vf bitmap of malicious vfs
+ */
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap)
+{
+	u32 i, j, reg, q, div, vf;

Why fix the length of the count variables?

Do you mean why u32 insted of int?

Quoted 54 lines
Quoted 40 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +36 -0
+	unsigned long wqbr;
+
+	/* figure out pool size for mapping to vf's */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		div = IXGBE_16VFS_QUEUES;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		div = IXGBE_32VFS_QUEUES;
+		break;
+	default:
+		div = IXGBE_64VFS_QUEUES;
+		break;
+	}
+
+	/* Read WQBR_TX and WQBR_RX and check for malicious queues */
+	for (i = 0; i < IXGBE_QUEUES_REG_AMOUNT; i++) {
+		wqbr = IXGBE_READ_REG(hw, IXGBE_WQBR_TX(i)) |
+		       IXGBE_READ_REG(hw, IXGBE_WQBR_RX(i));
+		if (!wqbr)
+			continue;
+
+		/* Get malicious queue */
+		for_each_set_bit(j, (unsigned long *)&wqbr,
+				 IXGBE_QUEUES_PER_REG) {
+			/* Get queue from bitmask */
+			q = j + (i * IXGBE_QUEUES_PER_REG);
+			/* Map queue to vf */
+			vf = q / div;
+			set_bit(vf, vf_bitmap);
+		}
+	}
+}
+
  #define X550_COMMON_MAC \
  	.init_hw			= &ixgbe_init_hw_generic, \
  	.start_hw			= &ixgbe_start_hw_X540, \

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static const struct ixgbe_mac_operations mac_ops_X550 = { · line 3987

Quoted 9 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +4 -0
@@ -3863,6 +3979,10 @@ static const struct ixgbe_mac_operations mac_ops_X550 = {
  	.prot_autoc_write	= prot_autoc_write_generic,
  	.setup_fc		= ixgbe_setup_fc_generic,
  	.fc_autoneg		= ixgbe_fc_autoneg,
+	.enable_mdd		= ixgbe_enable_mdd_x550,
+	.disable_mdd		= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf		= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd		= ixgbe_handle_mdd_x550,
  };
  static const struct ixgbe_mac_operations mac_ops_X550EM_x = {

Kind regards,

Paul

#4 lore raw

Re: [Intel-wired-lan] [iwl-next v2 1/4] ixgbe: add MDD support

Dear Michal,

Am 12.02.25 um 13:59 schrieb Michal Swiatkowski:

Quoted 23 lines · Paul Menzel
Quoted 22 lines

Thank you for your patch. For the summary/title you could use:

ixgbe: Support Malicious Driver Detection (MDD)

Am 12.02.25 um 08:57 schrieb Michal Swiatkowski:

Quoted 4 lines

From: Paul Greenwalt <[email protected]>

Add malicious driver detection. Support enabling MDD, disabling MDD, handling a MDD event, and restoring a MDD VF.

a*n* MDD

Could you please elaborate? List the commands to enable/disable MDD?

Also, please include a reference to the datasheet section for this feature. I am a little confused, as the Linux driver should never be “malicious”, shouldn’t it? So what is this feature?

Which devices support this? From the diff it looks like X550? Please add that.

Quoted 6 lines
Quoted 3 lines

How did you test it?

How are the events logged?

I will elaborate it in the commit message if it is needed. The VF created on X550 device can use malicious driver for example.

I guess, I still do not know, what “driver” refers to here exactly.

Quoted 3 lines

I tested it by
changing Tx descriptor to be invalid (TSO on, with invalid length in descriptor, but any type of invalid descriptor should cause MDD).

Could these invalid(?) values be prevented from being set in the first place?

Quoted 3 lines

It is enabled all time. Simple netif_warn() is called with more information about MDD. After 4 events on the same VF the link status is force to be down to turn off malicious VF.

Thank you for elaborating. It’d be great if you updated the commit message, and also pasted one of these log lines, and maybe a test script how to trigger the MDD.

Quoted 173 lines
Quoted 164 lines
Quoted 164 lines
---
   drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  28 ++++
   drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h |   5 +
   drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c |   4 +
   drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c | 120 ++++++++++++++++++
   4 files changed, 157 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_type.h +28 -0
index 5fdf32d79d82..d446c375335a 100644
@@ -2746,6 +2746,28 @@ enum ixgbe_fdir_pballoc_type {
   #define FW_PHY_INFO_ID_HI_MASK		0xFFFF0000u
   #define FW_PHY_INFO_ID_LO_MASK		0x0000FFFFu
+/* There are only 3 options for VFs creation on this device:
+ * 16 VFs pool with 8 queues each
+ * 32 VFs pool with 4 queues each
+ * 64 VFs pool with 2 queues each
+ *
+ * That means reading some VF registers that map VF to queue depending on
+ * chosen option. Define values that help dealing with each scenario.
+ */
+/* Number of queues based on VFs pool */
+#define IXGBE_16VFS_QUEUES		8
+#define IXGBE_32VFS_QUEUES		4
+#define IXGBE_64VFS_QUEUES		2
+/* Mask for getting queues bits based on VFs pool */
+#define IXGBE_16VFS_BITMASK		GENMASK(IXGBE_16VFS_QUEUES - 1, 0)
+#define IXGBE_32VFS_BITMASK		GENMASK(IXGBE_32VFS_QUEUES - 1, 0)
+#define IXGBE_64VFS_BITMASK		GENMASK(IXGBE_64VFS_QUEUES - 1, 0)
+/* Convert queue index to register number.
+ * We have 4 registers with 32 queues in each.
+ */
+#define IXGBE_QUEUES_PER_REG		32
+#define IXGBE_QUEUES_REG_AMOUNT		4
+
   /* Host Interface Command Structures */
   struct ixgbe_hic_hdr {
   	u8 cmd;
@@ -3534,6 +3556,12 @@ struct ixgbe_mac_operations {
   	int (*dmac_config_tcs)(struct ixgbe_hw *hw);
   	int (*read_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32 *);
   	int (*write_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32);
+
+	/* MDD events */
+	void (*enable_mdd)(struct ixgbe_hw *hw);
+	void (*disable_mdd)(struct ixgbe_hw *hw);
+	void (*restore_mdd_vf)(struct ixgbe_hw *hw, u32 vf);
+	void (*handle_mdd)(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
   };
   struct ixgbe_phy_operations {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h +5 -0
index 3e4092f8da3e..2a11147fb1bc 100644
@@ -17,4 +17,9 @@ void ixgbe_set_source_address_pruning_x550(struct ixgbe_hw *hw,
   void ixgbe_set_ethertype_anti_spoofing_x550(struct ixgbe_hw *hw,
   					    bool enable, int vf);
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf);
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
+
   #endif /* _IXGBE_X550_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c +4 -0
index cb07ecd8937d..788f3372ebf1 100644
@@ -2630,6 +2630,10 @@ static const struct ixgbe_mac_operations mac_ops_e610 = {
   	.prot_autoc_write		= prot_autoc_write_generic,
   	.setup_fc			= ixgbe_setup_fc_e610,
   	.fc_autoneg			= ixgbe_fc_autoneg_e610,
+	.enable_mdd			= ixgbe_enable_mdd_x550,
+	.disable_mdd			= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf			= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd			= ixgbe_handle_mdd_x550,
   };
   static const struct ixgbe_phy_operations phy_ops_e610 = {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +74 -0
index 277ceaf8a793..b5cbfd1f71fd 100644
@@ -3800,6 +3800,122 @@ static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
   	return status;
   }
+static void ixgbe_set_mdd_x550(struct ixgbe_hw *hw, bool ena)
+{
+	u32 reg_dma, reg_rdr;
+
+	reg_dma = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
+	reg_rdr = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
+
+	if (ena) {
+		reg_dma |= (IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr |= (IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	} else {
+		reg_dma &= ~(IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr &= ~(IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	}
+
+	IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_dma);
+	IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg_rdr);
+}
+
+/**
+ * ixgbe_enable_mdd_x550 - enable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, true);
+}
+
+/**
+ * ixgbe_disable_mdd_x550 - disable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, false);
+}
+
+/**
+ * ixgbe_restore_mdd_vf_x550 - restore VF that was disabled during MDD event
+ * @hw: pointer to hardware structure
+ * @vf: vf index
+ */
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf)
+{
+	u32 idx, reg, val, num_qs, start_q, bitmask;
+
+	/* Map VF to queues */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		num_qs = IXGBE_16VFS_QUEUES;
+		bitmask = IXGBE_16VFS_BITMASK;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		num_qs = IXGBE_32VFS_QUEUES;
+		bitmask = IXGBE_32VFS_BITMASK;
+		break;
+	default:
+		num_qs = IXGBE_64VFS_QUEUES;
+		bitmask = IXGBE_64VFS_BITMASK;
+		break;
+	}
+	start_q = vf * num_qs;
+
+	/* Release vf's queues by clearing WQBR_TX and WQBR_RX (RW1C) */
+	idx = start_q / IXGBE_QUEUES_PER_REG;
+	val = bitmask << (start_q % IXGBE_QUEUES_PER_REG);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_TX(idx), val);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_RX(idx), val);
+}
+
+/**
+ * ixgbe_handle_mdd_x550 - handle malicious driver detection event
Quoted 8 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr, · line 3882

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +6 -0
+ * @hw: pointer to hardware structure
+ * @vf_bitmap: output vf bitmap of malicious vfs
+ */
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap)
+{
+	u32 i, j, reg, q, div, vf;

Why fix the length of the count variables?

Quoted 1 line

Do you mean why u32 insted of int?

Yes, that is my question.

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +36 -0
+	unsigned long wqbr;
+
+	/* figure out pool size for mapping to vf's */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		div = IXGBE_16VFS_QUEUES;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		div = IXGBE_32VFS_QUEUES;
+		break;
+	default:
+		div = IXGBE_64VFS_QUEUES;
+		break;
+	}
+
+	/* Read WQBR_TX and WQBR_RX and check for malicious queues */
+	for (i = 0; i < IXGBE_QUEUES_REG_AMOUNT; i++) {
+		wqbr = IXGBE_READ_REG(hw, IXGBE_WQBR_TX(i)) |
+		       IXGBE_READ_REG(hw, IXGBE_WQBR_RX(i));
+		if (!wqbr)
+			continue;
+
+		/* Get malicious queue */
+		for_each_set_bit(j, (unsigned long *)&wqbr,
+				 IXGBE_QUEUES_PER_REG) {
+			/* Get queue from bitmask */
+			q = j + (i * IXGBE_QUEUES_PER_REG);
+			/* Map queue to vf */
+			vf = q / div;
+			set_bit(vf, vf_bitmap);
+		}
+	}
+}
+
   #define X550_COMMON_MAC \
   	.init_hw			= &ixgbe_init_hw_generic, \
   	.start_hw			= &ixgbe_start_hw_X540, \
@@ -3863,6 +3979,10 @@ static const struct ixgbe_mac_operations mac_ops_X550 = {
   	.prot_autoc_write	= prot_autoc_write_generic,
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static const struct ixgbe_mac_operations mac_ops_X550 = { · line 3988

Quoted 8 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +4 -0
   	.setup_fc		= ixgbe_setup_fc_generic,
   	.fc_autoneg		= ixgbe_fc_autoneg,
+	.enable_mdd		= ixgbe_enable_mdd_x550,
+	.disable_mdd		= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf		= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd		= ixgbe_handle_mdd_x550,
   };
   static const struct ixgbe_mac_operations mac_ops_X550EM_x = {

Kind regards,

Paul

#5 lore raw

Re: [Intel-wired-lan] [iwl-next v2 1/4] ixgbe: add MDD support

Quoted 27 lines · Paul Menzel

Dear Michal,

Am 12.02.25 um 13:59 schrieb Michal Swiatkowski:

Quoted 23 lines · Paul Menzel
Quoted 22 lines

Thank you for your patch. For the summary/title you could use:

ixgbe: Support Malicious Driver Detection (MDD)

Am 12.02.25 um 08:57 schrieb Michal Swiatkowski:

Quoted 4 lines

From: Paul Greenwalt <[email protected]>

Add malicious driver detection. Support enabling MDD, disabling MDD, handling a MDD event, and restoring a MDD VF.

a*n* MDD

Could you please elaborate? List the commands to enable/disable MDD?

Also, please include a reference to the datasheet section for this feature. I am a little confused, as the Linux driver should never be “malicious”, shouldn’t it? So what is this feature?

Which devices support this? From the diff it looks like X550? Please add that.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

How did you test it?

How are the events logged?

I will elaborate it in the commit message if it is needed. The VF created on X550 device can use malicious driver for example.

I guess, I still do not know, what “driver” refers to here exactly.

From PF side (the one that will find MDD) it is ixgbe. Modified for causing MDD can be VF driver loaded on the ixgbe VFs.

Quoted 6 lines
Quoted 3 lines

I tested it by
changing Tx descriptor to be invalid (TSO on, with invalid length in descriptor, but any type of invalid descriptor should cause MDD).

Could these invalid(?) values be prevented from being set in the first place?

Let me explain that. The PF driver is the ixgbe driver, these invalid values are checked and can't cause Tx hang. When you create a VFs you have to assume that user in VM can load any driver that he want. In this driver someone can on purpose set invalid parameters to hang Tx. PF driver need to know about this and the way to inform the PF driver is by using the MDD events.

Quoted 8 lines
Quoted 4 lines

It is enabled all time. Simple netif_warn() is called with more information about MDD. After 4 events on the same VF the link status is force to be down to turn off malicious VF.

Thank you for elaborating. It’d be great if you updated the commit message, and also pasted one of these log lines, and maybe a test script how to trigger the MDD.

There can be a problem with test script, because it needs modified driver or but crafted frame in DPDK. I will write about it.

Thanks,
Michal

Quoted 174 lines
Quoted 174 lines
Quoted 173 lines
Quoted 161 lines
---
   drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  28 ++++
   drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h |   5 +
   drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c |   4 +
   drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c | 120 ++++++++++++++++++
   4 files changed, 157 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_type.h +28 -0
index 5fdf32d79d82..d446c375335a 100644
@@ -2746,6 +2746,28 @@ enum ixgbe_fdir_pballoc_type {
   #define FW_PHY_INFO_ID_HI_MASK		0xFFFF0000u
   #define FW_PHY_INFO_ID_LO_MASK		0x0000FFFFu
+/* There are only 3 options for VFs creation on this device:
+ * 16 VFs pool with 8 queues each
+ * 32 VFs pool with 4 queues each
+ * 64 VFs pool with 2 queues each
+ *
+ * That means reading some VF registers that map VF to queue depending on
+ * chosen option. Define values that help dealing with each scenario.
+ */
+/* Number of queues based on VFs pool */
+#define IXGBE_16VFS_QUEUES		8
+#define IXGBE_32VFS_QUEUES		4
+#define IXGBE_64VFS_QUEUES		2
+/* Mask for getting queues bits based on VFs pool */
+#define IXGBE_16VFS_BITMASK		GENMASK(IXGBE_16VFS_QUEUES - 1, 0)
+#define IXGBE_32VFS_BITMASK		GENMASK(IXGBE_32VFS_QUEUES - 1, 0)
+#define IXGBE_64VFS_BITMASK		GENMASK(IXGBE_64VFS_QUEUES - 1, 0)
+/* Convert queue index to register number.
+ * We have 4 registers with 32 queues in each.
+ */
+#define IXGBE_QUEUES_PER_REG		32
+#define IXGBE_QUEUES_REG_AMOUNT		4
+
   /* Host Interface Command Structures */
   struct ixgbe_hic_hdr {
   	u8 cmd;
@@ -3534,6 +3556,12 @@ struct ixgbe_mac_operations {
   	int (*dmac_config_tcs)(struct ixgbe_hw *hw);
   	int (*read_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32 *);
   	int (*write_iosf_sb_reg)(struct ixgbe_hw *, u32, u32, u32);
+
+	/* MDD events */
+	void (*enable_mdd)(struct ixgbe_hw *hw);
+	void (*disable_mdd)(struct ixgbe_hw *hw);
+	void (*restore_mdd_vf)(struct ixgbe_hw *hw, u32 vf);
+	void (*handle_mdd)(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
   };
   struct ixgbe_phy_operations {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.h +5 -0
index 3e4092f8da3e..2a11147fb1bc 100644
@@ -17,4 +17,9 @@ void ixgbe_set_source_address_pruning_x550(struct ixgbe_hw *hw,
   void ixgbe_set_ethertype_anti_spoofing_x550(struct ixgbe_hw *hw,
   					    bool enable, int vf);
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw);
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf);
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap);
+
   #endif /* _IXGBE_X550_H_ */
drivers/net/ethernet/intel/ixgbe/ixgbe_e610.c +4 -0
index cb07ecd8937d..788f3372ebf1 100644
@@ -2630,6 +2630,10 @@ static const struct ixgbe_mac_operations mac_ops_e610 = {
   	.prot_autoc_write		= prot_autoc_write_generic,
   	.setup_fc			= ixgbe_setup_fc_e610,
   	.fc_autoneg			= ixgbe_fc_autoneg_e610,
+	.enable_mdd			= ixgbe_enable_mdd_x550,
+	.disable_mdd			= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf			= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd			= ixgbe_handle_mdd_x550,
   };
   static const struct ixgbe_phy_operations phy_ops_e610 = {
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +70 -0
index 277ceaf8a793..b5cbfd1f71fd 100644
@@ -3800,6 +3800,122 @@ static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
   	return status;
   }
+static void ixgbe_set_mdd_x550(struct ixgbe_hw *hw, bool ena)
+{
+	u32 reg_dma, reg_rdr;
+
+	reg_dma = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
+	reg_rdr = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
+
+	if (ena) {
+		reg_dma |= (IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr |= (IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	} else {
+		reg_dma &= ~(IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
+		reg_rdr &= ~(IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
+	}
+
+	IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_dma);
+	IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg_rdr);
+}
+
+/**
+ * ixgbe_enable_mdd_x550 - enable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_enable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, true);
+}
+
+/**
+ * ixgbe_disable_mdd_x550 - disable malicious driver detection
+ * @hw: pointer to hardware structure
+ */
+void ixgbe_disable_mdd_x550(struct ixgbe_hw *hw)
+{
+	ixgbe_set_mdd_x550(hw, false);
+}
+
+/**
+ * ixgbe_restore_mdd_vf_x550 - restore VF that was disabled during MDD event
+ * @hw: pointer to hardware structure
+ * @vf: vf index
+ */
+void ixgbe_restore_mdd_vf_x550(struct ixgbe_hw *hw, u32 vf)
+{
+	u32 idx, reg, val, num_qs, start_q, bitmask;
+
+	/* Map VF to queues */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		num_qs = IXGBE_16VFS_QUEUES;
+		bitmask = IXGBE_16VFS_BITMASK;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		num_qs = IXGBE_32VFS_QUEUES;
+		bitmask = IXGBE_32VFS_BITMASK;
+		break;
+	default:
+		num_qs = IXGBE_64VFS_QUEUES;
+		bitmask = IXGBE_64VFS_BITMASK;
+		break;
+	}
+	start_q = vf * num_qs;
+
+	/* Release vf's queues by clearing WQBR_TX and WQBR_RX (RW1C) */
+	idx = start_q / IXGBE_QUEUES_PER_REG;
+	val = bitmask << (start_q % IXGBE_QUEUES_PER_REG);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_TX(idx), val);
+	IXGBE_WRITE_REG(hw, IXGBE_WQBR_RX(idx), val);

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static int ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr, · line 3881

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +10 -0
+}
+
+/**
+ * ixgbe_handle_mdd_x550 - handle malicious driver detection event
+ * @hw: pointer to hardware structure
+ * @vf_bitmap: output vf bitmap of malicious vfs
+ */
+void ixgbe_handle_mdd_x550(struct ixgbe_hw *hw, unsigned long *vf_bitmap)
+{
+	u32 i, j, reg, q, div, vf;

Why fix the length of the count variables?

Quoted 4 lines
Quoted 1 line

Do you mean why u32 insted of int?

Yes, that is my question.

Is it a difference in this case? I am using only positive values, so no reasone other than "it is usually int". I received comment in one review that I should use unsigned when signed isn't needed. Personaly I think it is about preference in such case.

I can go with int if you want.

Quoted 53 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +36 -0
+	unsigned long wqbr;
+
+	/* figure out pool size for mapping to vf's */
+	reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
+	switch (reg & IXGBE_MRQC_MRQE_MASK) {
+	case IXGBE_MRQC_VMDQRT8TCEN:
+		div = IXGBE_16VFS_QUEUES;
+		break;
+	case IXGBE_MRQC_VMDQRSS32EN:
+	case IXGBE_MRQC_VMDQRT4TCEN:
+		div = IXGBE_32VFS_QUEUES;
+		break;
+	default:
+		div = IXGBE_64VFS_QUEUES;
+		break;
+	}
+
+	/* Read WQBR_TX and WQBR_RX and check for malicious queues */
+	for (i = 0; i < IXGBE_QUEUES_REG_AMOUNT; i++) {
+		wqbr = IXGBE_READ_REG(hw, IXGBE_WQBR_TX(i)) |
+		       IXGBE_READ_REG(hw, IXGBE_WQBR_RX(i));
+		if (!wqbr)
+			continue;
+
+		/* Get malicious queue */
+		for_each_set_bit(j, (unsigned long *)&wqbr,
+				 IXGBE_QUEUES_PER_REG) {
+			/* Get queue from bitmask */
+			q = j + (i * IXGBE_QUEUES_PER_REG);
+			/* Map queue to vf */
+			vf = q / div;
+			set_bit(vf, vf_bitmap);
+		}
+	}
+}
+
   #define X550_COMMON_MAC \
   	.init_hw			= &ixgbe_init_hw_generic, \
   	.start_hw			= &ixgbe_start_hw_X540, \
@@ -3863,6 +3979,10 @@ static const struct ixgbe_mac_operations mac_ops_X550 = {
   	.prot_autoc_write	= prot_autoc_write_generic,
Quoted 8 lines
Quoted 8 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c static const struct ixgbe_mac_operations mac_ops_X550 = { · line 3988

Quoted 8 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c +4 -0
   	.setup_fc		= ixgbe_setup_fc_generic,
   	.fc_autoneg		= ixgbe_fc_autoneg,
+	.enable_mdd		= ixgbe_enable_mdd_x550,
+	.disable_mdd		= ixgbe_disable_mdd_x550,
+	.restore_mdd_vf		= ixgbe_restore_mdd_vf_x550,
+	.handle_mdd		= ixgbe_handle_mdd_x550,
   };
   static const struct ixgbe_mac_operations mac_ops_X550EM_x = {

Kind regards,

Paul

#6 lore raw

PATCH v2 2/4 ixgbe: check for MDD events

In reply to Michal Swiatkowski

From: Don Skidmore <[email protected]>

When an event is detected it is logged and, for the time being, the queue is immediately re-enabled. This is due to the lack of an API to the hypervisor so it could deal with it as it chooses.

---
 .../net/ethernet/intel/ixgbe/ixgbe_sriov.h    |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  2 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  3 ++
 .../net/ethernet/intel/ixgbe/ixgbe_sriov.c    | 50 +++++++++++++++++++
 4 files changed, 56 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h +1 -0
index 0690ecb8dfa3..bc4cab976bf9 100644
@@ -15,6 +15,7 @@
 #ifdef CONFIG_PCI_IOV
 void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter);
 #endif
+bool ixgbe_check_mdd_event(struct ixgbe_adapter *adapter);
 void ixgbe_msg_task(struct ixgbe_adapter *adapter);
 int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask);
 void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter);
drivers/net/ethernet/intel/ixgbe/ixgbe_type.h +2 -0
index d446c375335a..aa3b498558bc 100644
@@ -402,6 +402,8 @@ struct ixgbe_nvm_version {
 #define IXGBE_MRCTL(_i)      (0x0F600 + ((_i) * 4))
 #define IXGBE_VMRVLAN(_i)    (0x0F610 + ((_i) * 4))
 #define IXGBE_VMRVM(_i)      (0x0F630 + ((_i) * 4))
+#define IXGBE_LVMMC_RX	     0x2FA8
+#define IXGBE_LVMMC_TX	     0x8108
 #define IXGBE_WQBR_RX(_i)    (0x2FB0 + ((_i) * 4)) /* 4 total */
 #define IXGBE_WQBR_TX(_i)    (0x8130 + ((_i) * 4)) /* 4 total */
 #define IXGBE_L34T_IMIR(_i)  (0x0E800 + ((_i) * 4)) /*128 of these (0-127)*/
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -0
index 467f81239e12..3ff48207165c 100644
@@ -7959,6 +7959,9 @@ static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
 	netif_carrier_on(netdev);
 	ixgbe_check_vf_rate_limit(adapter);
 
+	if (adapter->num_vfs && hw->mac.ops.enable_mdd)
+		hw->mac.ops.enable_mdd(hw);
+
 	/* enable transmits */
 	netif_tx_wake_all_queues(adapter->netdev);
 
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +50 -0

74 lines not on this page · raw message

Signature · 1 line
2.42.0
#7 lore raw

PATCH v2 3/4 ixgbe: add Tx hang detection unhandled MDD

In reply to Michal Swiatkowski

From: Slawomir Mrozowicz <[email protected]>

Add Tx Hang detection due to an unhandled MDD Event.

Previously, a malicious VF could disable the entire port causing TX to hang on the E610 card.
Those events that caused PF to freeze were not detected as an MDD event and usually required a Tx Hang watchdog timer to catch the suspension, and perform a physical function reset.

Implement flows in the affected PF driver in such a way to check the cause of the hang, detect it as an MDD event and log an entry of the malicious VF that caused the Hang.

The PF blocks the malicious VF, if it continues to be the source of several MDD events.

---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h      |   5 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  12 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c  |   3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 211 ++++++++++++++++--
 4 files changed, 209 insertions(+), 22 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +5 -0
index e6a380d4929b..81ccb4c591ba 100644
@@ -427,6 +427,10 @@ enum ixgbe_ring_f_enum {
 #define IXGBE_BAD_L2A_QUEUE		3
 #define IXGBE_MAX_MACVLANS		63
 
+#define IXGBE_MAX_TX_QUEUES		128
+#define IXGBE_MAX_TX_DESCRIPTORS	40
+#define IXGBE_MAX_TX_VF_HANGS		4
+
 DECLARE_STATIC_KEY_FALSE(ixgbe_xdp_locking_key);
 
 struct ixgbe_ring_feature {
@@ -798,6 +802,7 @@ struct ixgbe_adapter {
 	u32 timer_event_accumulator;
 	u32 vferr_refcount;
 	struct ixgbe_mac_addr *mac_table;
+	u8 tx_hang_count[IXGBE_MAX_TX_QUEUES];
 	struct kobject *info_kobj;
 	u16 lse_mask;
 #ifdef CONFIG_IXGBE_HWMON
drivers/net/ethernet/intel/ixgbe/ixgbe_type.h +11 -1
index aa3b498558bc..783e76c0e8a2 100644
@@ -1044,6 +1044,7 @@ struct ixgbe_nvm_version {
 #define IXGBE_GCR_EXT_VT_MODE_16        0x00000001
 #define IXGBE_GCR_EXT_VT_MODE_32        0x00000002
 #define IXGBE_GCR_EXT_VT_MODE_64        0x00000003
+#define IXGBE_GCR_EXT_VT_MODE_MASK      0x00000003
 #define IXGBE_GCR_EXT_SRIOV             (IXGBE_GCR_EXT_MSIX_EN | \
 					 IXGBE_GCR_EXT_VT_MODE_64)
 
@@ -2935,6 +2936,13 @@ struct ixgbe_adv_tx_context_desc {
 	__le32 mss_l4len_idx;
 };
 
+enum {
+	IXGBE_VLAN_MACIP_LENS_REG	= 0,
+	IXGBE_FCEOF_SAIDX_REG		= 1,
+	IXGBE_TYPE_TUCMD_MLHL		= 2,
+	IXGBE_MSS_L4LEN_IDX		= 3,
+};
+
 /* Adv Transmit Descriptor Config Masks */
 #define IXGBE_ADVTXD_DTALEN_MASK      0x0000FFFF /* Data buf length(bytes) */
 #define IXGBE_ADVTXD_MAC_LINKSEC      0x00040000 /* Insert LinkSec */
@@ -2942,7 +2950,7 @@ struct ixgbe_adv_tx_context_desc {
 #define IXGBE_ADVTXD_IPSEC_SA_INDEX_MASK   0x000003FF /* IPSec SA index */
 #define IXGBE_ADVTXD_IPSEC_ESP_LEN_MASK    0x000001FF /* IPSec ESP length */
 #define IXGBE_ADVTXD_DTYP_MASK  0x00F00000 /* DTYP mask */
-#define IXGBE_ADVTXD_DTYP_CTXT  0x00200000 /* Advanced Context Desc */
+#define IXGBE_ADVTXD_DTYP_CTXT	0x2 /* Advanced Context Desc */
 #define IXGBE_ADVTXD_DTYP_DATA  0x00300000 /* Advanced Data Descriptor */
 #define IXGBE_ADVTXD_DCMD_EOP   IXGBE_TXD_CMD_EOP  /* End of Packet */
 #define IXGBE_ADVTXD_DCMD_IFCS  IXGBE_TXD_CMD_IFCS /* Insert FCS */
@@ -2991,6 +2999,8 @@ struct ixgbe_adv_tx_context_desc {
 #define IXGBE_ADVTXD_FCOEF_EOF_MASK  (3u << 10)  /* FC EOF index */
 #define IXGBE_ADVTXD_L4LEN_SHIFT     8  /* Adv ctxt L4LEN shift */
 #define IXGBE_ADVTXD_MSS_SHIFT       16  /* Adv ctxt MSS shift */
+#define IXGBE_ADVTXD_MSS_MASK		GENMASK(31, IXGBE_ADVTXD_MSS_SHIFT)
+#define IXGBE_ADVTXD_HEADER_LEN_MASK	GENMASK(8, 0)
 
 /* Autonegotiation advertised speeds */
 typedef u32 ixgbe_autoneg_advertised;
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +2 -1
index 336d47ffb95a..54d75cf94cc1 100644
@@ -1293,7 +1293,8 @@ void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
 	tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
 
 	/* set bits to identify this as an advanced context descriptor */
-	type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
+	type_tucmd |= IXGBE_TXD_CMD_DEXT |
+		FIELD_PREP(IXGBE_ADVTXD_DTYP_MASK, IXGBE_ADVTXD_DTYP_CTXT);
 
 	context_desc->vlan_macip_lens	= cpu_to_le32(vlan_macip_lens);
 	context_desc->fceof_saidx	= cpu_to_le32(fceof_saidx);
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +191 -20

235 lines not on this page · raw message

Signature · 1 line
2.42.0
#8 lore raw

PATCH v2 4/4 ixgbe: turn off MDD while modifying SRRCTL

In reply to Michal Swiatkowski

From: Radoslaw Tyl <[email protected]>

Modifying SRRCTL register can generate MDD event.

Turn MDD off during SRRCTL register write to prevent generating MDD.

Fix RCT in ixgbe_set_rx_drop_en().

---
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +8 -1
index 22148e65e596..873b46d21042 100644
@@ -4099,8 +4099,12 @@ void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
 #endif
 {
-	int i;
 	bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
+	struct ixgbe_hw *hw = &adapter->hw;
+	int i;
+
+	if (hw->mac.ops.disable_mdd)
+		hw->mac.ops.disable_mdd(hw);
 
 	if (adapter->ixgbe_ieee_pfc)
 		pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
@@ -4122,6 +4126,9 @@ static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
 		for (i = 0; i < adapter->num_rx_queues; i++)
 			ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
 	}
+
+	if (hw->mac.ops.enable_mdd)
+		hw->mac.ops.enable_mdd(hw);
 }
 
 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Signature · 1 line
2.42.0