Add E800 live migration driver
Subsystems (6)
v3 cover Add E800 live migration driver
This series adds vfio live migration support for Intel E810 VF devices based on the v2 migration protocol definition series discussed here[0].
Steps to test:
1. Bind one or more E810 VF devices to the module ice_vfio_pci.ko
2. Assign the VFs to the virtual machine and enable device live migration
3. Run a workload using IAVF inside the VM, for example, iperf.
4. Migrate the VM from the source node to a destination node.
Thanks,
Yahui
[0] https://lore.kernel.org/kvm/[email protected]/
Change log:
v2 --> v3: link [2]
- Add P2P support in vfio driver (Jason)
- Remove source/destination check in vfio driver (Jason)
- Restructure PF exported API with proper types and layering (Jason)
- Change patchset email sender.
- Reword commit message and comments to be more reviewer-friendly (Kevin)
- Add s-o-b for Patch01 (Kevin)
- Merge Patch08 into Patch04 and merge Patch13 into Patch06 (Kevin)
- Remove uninit() in VF destroy stage for Patch 05 (Kevin)
- change migration_active to migration_enabled (Kevin)
- Add total_size in devstate to greatly simplify the various checks for Patch07 (Kevin)
- Add magic and version in device state for Patch07 (Kevin)
- Fix rx head init issue in Patch10 (Kevin)
- Remove DMA access for Guest Memory at device resume stage and deprecate the approach to restore TX head in VF space, instead restore TX head in PF space and then switch context back to VF space which is transparent to Guest for Patch11 (Jason, Kevin)
- Use non-interrupt mode instead of VF MSIX vector to restore TX head for Patch11 (Kevin)
- Move VF pci mmio save/restore from vfio driver into PF driver
- Add configuration match check at device resume stage (Kevin)
- Remove sleep before stopping queue at device suspend stage (Kevin)
- Let PF respond failure to VF if virtual channel messages logging failed (Kevin)
- Add migration setup and description in cover letter
[2] https://lore.kernel.org/intel-wired-lan/[email protected]/
v1 --> v2: link [1]
- clarified comments and commit message
[1] https://lore.kernel.org/intel-wired-lan/[email protected]/
---
Lingyu Liu (9):
ice: Introduce VF state ICE_VF_STATE_REPLAYING_VC for migration
ice: Add fundamental migration init and exit function
ice: Log virtual channel messages in PF
ice: Add device state save/restore function for migration
ice: Fix VSI id in virtual channel message for migration
ice: Save and restore RX Queue head
ice: Save and restore TX Queue head
ice: Add device suspend function for migration vfio/ice: Implement vfio_pci driver for E800 devices
Xu Ting (1):
ice: Fix missing legacy 32byte RXDID in the supported bitmap
Yahui Cao (3):
ice: Add function to get RX queue context
ice: Add function to get and set TX queue context
ice: Save and restore mmio registers
MAINTAINERS | 7 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 3 + drivers/net/ethernet/intel/ice/ice_common.c | 484 +++++- drivers/net/ethernet/intel/ice/ice_common.h | 11 + .../net/ethernet/intel/ice/ice_hw_autogen.h | 23 + .../net/ethernet/intel/ice/ice_lan_tx_rx.h | 3 + drivers/net/ethernet/intel/ice/ice_main.c | 15 + .../net/ethernet/intel/ice/ice_migration.c | 1344 +++++++++++++++++ .../intel/ice/ice_migration_private.h | 44 + drivers/net/ethernet/intel/ice/ice_vf_lib.c | 4 + drivers/net/ethernet/intel/ice/ice_vf_lib.h | 10 + drivers/net/ethernet/intel/ice/ice_virtchnl.c | 267 ++-- drivers/net/ethernet/intel/ice/ice_virtchnl.h | 15 +- .../ethernet/intel/ice/ice_virtchnl_fdir.c | 28 +- drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/ice/Kconfig | 10 + drivers/vfio/pci/ice/Makefile | 4 + drivers/vfio/pci/ice/ice_vfio_pci.c | 707 +++++++++ include/linux/net/intel/ice_migration.h | 42 + 21 files changed, 2916 insertions(+), 112 deletions(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_migration.c create mode 100644 drivers/net/ethernet/intel/ice/ice_migration_private.h create mode 100644 drivers/vfio/pci/ice/Kconfig create mode 100644 drivers/vfio/pci/ice/Makefile create mode 100644 drivers/vfio/pci/ice/ice_vfio_pci.c create mode 100644 include/linux/net/intel/ice_migration.h
Signature · 1 line
2.34.1
PATCH v3 1/13 ice: Fix missing legacy 32byte RXDID in the supported bitmap
From: Xu Ting <[email protected]>
32byte legacy descriptor format is preassigned.
Commit e753df8fbca5 ("ice: Add support Flex RXD") created a supported RXDIDs bitmap according to DDP package. But it missed the legacy 32byte RXDID since it is not listed in the package. Mark 32byte legacy descriptor format as supported in the supported RXDIDs flags.
--- drivers/net/ethernet/intel/ice/ice_virtchnl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_virtchnl.c +6 -3
@@ -2657,10 +2657,13 @@ static int ice_vc_query_rxdid(struct ice_vf *vf)/* Read flexiflag registers to determine whether the * corresponding RXDID is configured and supported or not. -* Since Legacy 16byte descriptor format is not supported, -* start from Legacy 32byte descriptor. +* But the legacy 32byte RXDID is not listed in DDP package, +* add it in the bitmap manually and skip check for it in the loop. +* Legacy 16byte descriptor is not supported. */ -for (i =ICE_RXDID_LEGACY_1 ; i <ICE_FLEX_DESC_RXDID_MAX_NUM ; i++) { + rxdid->supported_rxdids |=BIT (ICE_RXDID_LEGACY_1 ); + +for (i =ICE_RXDID_FLEX_NIC ; i <ICE_FLEX_DESC_RXDID_MAX_NUM ; i++) { regval =rd32 (hw,GLFLXP_RXDID_FLAGS (i,0 ));if ((regval >>GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S ) &GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M )
Signature · 1 line
2.34.1
PATCH v3 2/13 ice: Add function to get RX queue context
In reply to Yahui CaoExport RX queue context get function which is consumed by linux live migration driver to save and load device state.
--- drivers/net/ethernet/intel/ice/ice_common.c | 268 ++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_common.h | 5 + 2 files changed, 273 insertions(+)
drivers/net/ethernet/intel/ice/ice_common.c +268 -0
@@ -1217,6 +1217,34 @@ ice_copy_rxq_ctx_to_hw(struct ice_hw *hw, u8 *ice_rxq_ctx, u32 rxq_index)return 0 ; } +/** +* ice_copy_rxq_ctx_from_hw - Copy rxq context register from HW +* @hw: pointer to the hardware structure +* @ice_rxq_ctx: pointer to the rxq context +* @rxq_index: the index of the Rx queue +* +* Copy rxq context from HW register space to dense structure +*/ +static int +ice_copy_rxq_ctx_from_hw (struct ice_hw *hw,u8 *ice_rxq_ctx,u32 rxq_index) +{ +u8 i; + +if (!ice_rxq_ctx || rxq_index >QRX_CTRL_MAX_INDEX ) +return -EINVAL ; + +/* Copy each dword separately from HW */ +for (i =0 ; i <ICE_RXQ_CTX_SIZE_DWORDS ; i++) { +u32 *ctx = (u32 *)(ice_rxq_ctx + (i *sizeof (u32))); + + *ctx =rd32 (hw,QRX_CONTEXT (i, rxq_index)); + +ice_debug (hw,ICE_DBG_QCTX ,"qrxdata[%d]: %08X\n" , i, *ctx); + } + +return 0 ; +} +/* LAN Rx Queue Context */ static const struct ice_ctx_ele ice_rlan_ctx_info[] = {/* Field Width LSB */
@@ -1268,6 +1296,32 @@ ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,return ice_copy_rxq_ctx_to_hw (hw, ctx_buf, rxq_index); } +/** +* ice_read_rxq_ctx - Read rxq context from HW +* @hw: pointer to the hardware structure +* @rlan_ctx: pointer to the rxq context +* @rxq_index: the index of the Rx queue +* +* Read rxq context from HW register space and then converts it from dense +* structure to sparse +*/ +int +ice_read_rxq_ctx (struct ice_hw *hw,struct ice_rlan_ctx *rlan_ctx, +u32 rxq_index) +{ +u8 ctx_buf[ICE_RXQ_CTX_SZ ] = {0 }; +int status; + +if (!rlan_ctx) +return -EINVAL ; + + status =ice_copy_rxq_ctx_from_hw (hw, ctx_buf, rxq_index); +if (status) +return status; + +return ice_get_ctx (ctx_buf, (u8 *)rlan_ctx, ice_rlan_ctx_info); +} +/* LAN Tx Queue Context */ const struct ice_ctx_ele ice_tlan_ctx_info[] = {/* Field Width LSB */
@@ -4443,6 +4497,220 @@ ice_set_ctx(struct ice_hw *hw, u8 *src_ctx, u8 *dest_ctx,return 0 ; } +/** +* ice_read_byte - read context byte into struct +* @src_ctx: the context structure to read from +* @dest_ctx: the context to be written to +* @ce_info: a description of the struct to be filled +*/ +static void +ice_read_byte (u8 *src_ctx,u8 *dest_ctx,const struct ice_ctx_ele *ce_info) +{ +u8 dest_byte, mask; +u8 *src, *target; +u16 shift_width; + +/* prepare the bits and mask */ + shift_width = ce_info->lsb %8 ; + mask = (u8)(BIT (ce_info->width) -1 ); + +/* shift to correct alignment */ + mask <<= shift_width; + +/* get the current bits from the src bit string */ + src = src_ctx + (ce_info->lsb /8 ); + +memcpy (&dest_byte, src,sizeof (dest_byte)); + + dest_byte &= mask; + + dest_byte >>= shift_width; + +/* get the address from the struct field */ + target = dest_ctx + ce_info->offset; + +/* put it back in the struct */ +memcpy (target, &dest_byte,sizeof (dest_byte)); +} + +/** +* ice_read_word - read context word into struct +* @src_ctx: the context structure to read from +* @dest_ctx: the context to be written to +* @ce_info: a description of the struct to be filled +*/ +static void +ice_read_word (u8 *src_ctx,u8 *dest_ctx,const struct ice_ctx_ele *ce_info) +{ +u16 dest_word, mask; +u8 *src, *target; +__le16 src_word; +u16 shift_width; + +/* prepare the bits and mask */ + shift_width = ce_info->lsb %8 ; + mask =BIT (ce_info->width) -1 ; + +/* shift to correct alignment */ + mask <<= shift_width; + +/* get the current bits from the src bit string */ + src = src_ctx + (ce_info->lsb /8 ); + +memcpy (&src_word, src,sizeof (src_word)); + +/* the data in the memory is stored as little endian so mask it +* correctly +*/ + src_word &=cpu_to_le16 (mask); + +/* get the data back into host order before shifting */ + dest_word =le16_to_cpu (src_word); + + dest_word >>= shift_width; + +/* get the address from the struct field */ + target = dest_ctx + ce_info->offset; + +/* put it back in the struct */ +memcpy (target, &dest_word,sizeof (dest_word)); +} + +/** +* ice_read_dword - read context dword into struct +* @src_ctx: the context structure to read from +* @dest_ctx: the context to be written to +* @ce_info: a description of the struct to be filled +*/ +static void +ice_read_dword (u8 *src_ctx,u8 *dest_ctx,const struct ice_ctx_ele *ce_info) +{ +u32 dest_dword, mask; +__le32 src_dword; +u8 *src, *target; +u16 shift_width; + +/* prepare the bits and mask */ + shift_width = ce_info->lsb %8 ; + +/* if the field width is exactly 32 on an x86 machine, then the shift +* operation will not work because the SHL instructions count is masked +* to 5 bits so the shift will do nothing +*/ +if (ce_info->width <32 ) + mask =BIT (ce_info->width) -1 ; +else + mask = (u32 )~0 ; + +/* shift to correct alignment */ + mask <<= shift_width; + +/* get the current bits from the src bit string */ + src = src_ctx + (ce_info->lsb /8 ); + +memcpy (&src_dword, src,sizeof (src_dword)); + +/* the data in the memory is stored as little endian so mask it +* correctly +*/ + src_dword &=cpu_to_le32 (mask); + +/* get the data back into host order before shifting */ + dest_dword =le32_to_cpu (src_dword); + + dest_dword >>= shift_width; + +/* get the address from the struct field */ + target = dest_ctx + ce_info->offset; + +/* put it back in the struct */ +memcpy (target, &dest_dword,sizeof (dest_dword)); +} + +/** +* ice_read_qword - read context qword into struct +* @src_ctx: the context structure to read from +* @dest_ctx: the context to be written to +* @ce_info: a description of the struct to be filled +*/ +static void +ice_read_qword (u8 *src_ctx,u8 *dest_ctx,const struct ice_ctx_ele *ce_info) +{ +u64 dest_qword, mask; +__le64 src_qword; +u8 *src, *target; +u16 shift_width; + +/* prepare the bits and mask */ + shift_width = ce_info->lsb %8 ; + +/* if the field width is exactly 64 on an x86 machine, then the shift +* operation will not work because the SHL instructions count is masked +* to 6 bits so the shift will do nothing +*/ +if (ce_info->width <64 ) + mask =BIT_ULL (ce_info->width) -1 ; +else + mask = (u64 )~0 ; + +/* shift to correct alignment */ + mask <<= shift_width; + +/* get the current bits from the src bit string */ + src = src_ctx + (ce_info->lsb /8 ); + +memcpy (&src_qword, src,sizeof (src_qword)); + +/* the data in the memory is stored as little endian so mask it +* correctly +*/ + src_qword &=cpu_to_le64 (mask); + +/* get the data back into host order before shifting */ + dest_qword =le64_to_cpu (src_qword); + + dest_qword >>= shift_width; + +/* get the address from the struct field */ + target = dest_ctx + ce_info->offset; + +/* put it back in the struct */ +memcpy (target, &dest_qword,sizeof (dest_qword)); +} + +/** +* ice_get_ctx - extract context bits from a packed structure +* @src_ctx: pointer to a generic packed context structure +* @dest_ctx: pointer to a generic non-packed context structure +* @ce_info: a description of the structure to be read from +*/ +int +ice_get_ctx (u8 *src_ctx,u8 *dest_ctx,const struct ice_ctx_ele *ce_info) +{ +int i; + +for (i =0 ; ce_info[i].width; i++) { +switch (ce_info[i].size_of) { +case 1 : +ice_read_byte (src_ctx, dest_ctx, &ce_info[i]); +break ; +case 2 : +ice_read_word (src_ctx, dest_ctx, &ce_info[i]); +break ; +case 4 : +ice_read_dword (src_ctx, dest_ctx, &ce_info[i]); +break ; +case 8 : +ice_read_qword (src_ctx, dest_ctx, &ce_info[i]); +break ; +default : +return -EINVAL ; + } + } + +return 0 ; +} +/** * ice_get_lan_q_ctx - get the LAN queue context for the given VSI and TC * @hw: pointer to the HW struct
drivers/net/ethernet/intel/ice/ice_common.h +5 -0
@@ -55,6 +55,9 @@ void ice_set_safe_mode_caps(struct ice_hw *hw);int ice_write_rxq_ctx (struct ice_hw *hw,struct ice_rlan_ctx *rlan_ctx,u32 rxq_index); +int +ice_read_rxq_ctx (struct ice_hw *hw,struct ice_rlan_ctx *rlan_ctx, +u32 rxq_index);int ice_aq_get_rss_lut (struct ice_hw *hw,struct ice_aq_get_set_rss_lut_params *get_params);
@@ -74,6 +77,8 @@ extern const struct ice_ctx_ele ice_tlan_ctx_info[];int ice_set_ctx (struct ice_hw *hw,u8 *src_ctx,u8 *dest_ctx,const struct ice_ctx_ele *ce_info); +int +ice_get_ctx (u8 *src_ctx,u8 *dest_ctx,const struct ice_ctx_ele *ce_info);extern struct mutex ice_global_cfg_lock_sw;
Signature · 1 line
2.34.1
PATCH v3 3/13 ice: Add function to get and set TX queue context
In reply to Yahui CaoExport TX queue context get and set function which is consumed by linux live migration driver to save and load device state.
TX queue context contains static fields which does not change during TX traffic and dynamic fields which may change during TX traffic.
--- drivers/net/ethernet/intel/ice/ice_common.c | 216 +++++++++++++++++- drivers/net/ethernet/intel/ice/ice_common.h | 6 + .../net/ethernet/intel/ice/ice_hw_autogen.h | 15 ++ .../net/ethernet/intel/ice/ice_lan_tx_rx.h | 3 + 4 files changed, 239 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_common.c +215 -1
@@ -1322,7 +1322,10 @@ ice_read_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,return ice_get_ctx (ctx_buf, (u8 *)rlan_ctx, ice_rlan_ctx_info); } -/* LAN Tx Queue Context */ +/* LAN Tx Queue Context used for set Tx config by ice_aqc_opc_add_txqs, +* Bit[0-175] is valid +*/ +const struct ice_ctx_ele ice_tlan_ctx_info[] = {/* Field Width LSB */ ICE_CTX_STORE (ice_tlan_ctx, base,57 ,0 ),
@@ -1356,6 +1359,217 @@ const struct ice_ctx_ele ice_tlan_ctx_info[] = { { 0 } }; +/* LAN Tx Queue Context used for get Tx config from QTXCOMM_CNTX data, +* Bit[0-292] is valid, including internal queue state. Since internal +* queue state is dynamic field, its value will be cleared once queue +* is disabled +*/ +static const struct ice_ctx_ele ice_tlan_ctx_data_info[] = { +/* Field Width LSB */ +ICE_CTX_STORE (ice_tlan_ctx, base,57 ,0 ), +ICE_CTX_STORE (ice_tlan_ctx, port_num,3 ,57 ), +ICE_CTX_STORE (ice_tlan_ctx, cgd_num,5 ,60 ), +ICE_CTX_STORE (ice_tlan_ctx, pf_num,3 ,65 ), +ICE_CTX_STORE (ice_tlan_ctx, vmvf_num,10 ,68 ), +ICE_CTX_STORE (ice_tlan_ctx, vmvf_type,2 ,78 ), +ICE_CTX_STORE (ice_tlan_ctx, src_vsi,10 ,80 ), +ICE_CTX_STORE (ice_tlan_ctx, tsyn_ena,1 ,90 ), +ICE_CTX_STORE (ice_tlan_ctx, internal_usage_flag,1 ,91 ), +ICE_CTX_STORE (ice_tlan_ctx, alt_vlan,1 ,92 ), +ICE_CTX_STORE (ice_tlan_ctx, cpuid,8 ,93 ), +ICE_CTX_STORE (ice_tlan_ctx, wb_mode,1 ,101 ), +ICE_CTX_STORE (ice_tlan_ctx, tphrd_desc,1 ,102 ), +ICE_CTX_STORE (ice_tlan_ctx, tphrd,1 ,103 ), +ICE_CTX_STORE (ice_tlan_ctx, tphwr_desc,1 ,104 ), +ICE_CTX_STORE (ice_tlan_ctx, cmpq_id,9 ,105 ), +ICE_CTX_STORE (ice_tlan_ctx, qnum_in_func,14 ,114 ), +ICE_CTX_STORE (ice_tlan_ctx, itr_notification_mode,1 ,128 ), +ICE_CTX_STORE (ice_tlan_ctx, adjust_prof_id,6 ,129 ), +ICE_CTX_STORE (ice_tlan_ctx, qlen,13 ,135 ), +ICE_CTX_STORE (ice_tlan_ctx, quanta_prof_idx,4 ,148 ), +ICE_CTX_STORE (ice_tlan_ctx, tso_ena,1 ,152 ), +ICE_CTX_STORE (ice_tlan_ctx, tso_qnum,11 ,153 ), +ICE_CTX_STORE (ice_tlan_ctx, legacy_int,1 ,164 ), +ICE_CTX_STORE (ice_tlan_ctx, drop_ena,1 ,165 ), +ICE_CTX_STORE (ice_tlan_ctx, cache_prof_idx,2 ,166 ), +ICE_CTX_STORE (ice_tlan_ctx, pkt_shaper_prof_idx,3 ,168 ), +ICE_CTX_STORE (ice_tlan_ctx, tail,13 ,184 ), + {0 } +}; + +/** +* ice_copy_txq_ctx_from_hw - Copy txq context register from HW +* @hw: pointer to the hardware structure +* @ice_txq_ctx: pointer to the txq context +* +* Copy txq context from HW register space to dense structure +*/ +static int +ice_copy_txq_ctx_from_hw (struct ice_hw *hw,u8 *ice_txq_ctx) +{ +u8 i; + +if (!ice_txq_ctx) +return -EINVAL ; + +/* Copy each dword separately from HW */ +for (i =0 ; i <ICE_TXQ_CTX_SIZE_DWORDS ; i++) { +u32 *ctx = (u32 *)(ice_txq_ctx + (i *sizeof (u32))); + + *ctx =rd32 (hw,GLCOMM_QTX_CNTX_DATA (i)); + +ice_debug (hw,ICE_DBG_QCTX ,"qtxdata[%d]: %08X\n" , i, *ctx); + } + +return 0 ; +} + +/** +* ice_copy_txq_ctx_to_hw - Copy txq context register into HW +* @hw: pointer to the hardware structure +* @ice_txq_ctx: pointer to the txq context +* +* Copy txq context from dense structure to HW register space +*/ +static int +ice_copy_txq_ctx_to_hw (struct ice_hw *hw,u8 *ice_txq_ctx) +{ +u8 i; + +if (!ice_txq_ctx) +return -EINVAL ; + +/* Copy each dword separately to HW */ +for (i =0 ; i <ICE_TXQ_CTX_SIZE_DWORDS ; i++) { +u32 *ctx = (u32 *)(ice_txq_ctx + (i *sizeof (u32))); + +wr32 (hw,GLCOMM_QTX_CNTX_DATA (i), *ctx); + +ice_debug (hw,ICE_DBG_QCTX ,"qtxdata[%d]: %08X\n" , i, *ctx); + } + +return 0 ; +} + +/* Configuration access to tx ring context(from PF) is done via indirect +* interface, GLCOMM_QTX_CNTX_CTL/DATA registers. However, there registers +* are shared by all the PFs with single PCI card. So multiplied PF may +* access there registers simultaneously, causing access conflicts. Then +* card-level grained locking is required to protect these registers from +* being competed by PF devices within the same card. However, there is no +* such kind of card-level locking supported. So introduce a coarse grained +* global lock which is shared by all the PF driver. +* +* The overall flow is to acquire the lock, read/write TXQ context through +* GLCOMM_QTX_CNTX_CTL/DATA indirect interface and release the lock once +* access is completed. In this way, only one PF can have access to TXQ +* context safely. +*/ +static DEFINE_MUTEX (ice_global_txq_ctx_lock); + +/** +* ice_read_txq_ctx - Read txq context from HW +* @hw: pointer to the hardware structure +* @tlan_ctx: pointer to the txq context +* @txq_index: the index of the Tx queue +* +* Read txq context from HW register space and then converts it from dense +* structure to sparse +*/ +int +ice_read_txq_ctx (struct ice_hw *hw,struct ice_tlan_ctx *tlan_ctx, +u32 txq_index) +{ +u8 ctx_buf[ICE_TXQ_CTX_SZ ] = {0 }; +int status; +u32 txq_base; +u32 cmd, reg; + +if (!tlan_ctx) +return -EINVAL ; + +if (txq_index >QTX_COMM_HEAD_MAX_INDEX ) +return -EINVAL ; + +/* Get TXQ base within card space */ + txq_base =rd32 (hw,PFLAN_TX_QALLOC (hw->pf_id)); + txq_base = (txq_base &PFLAN_TX_QALLOC_FIRSTQ_M ) >> +PFLAN_TX_QALLOC_FIRSTQ_S ; + + cmd = (GLCOMM_QTX_CNTX_CTL_CMD_READ + <<GLCOMM_QTX_CNTX_CTL_CMD_S ) &GLCOMM_QTX_CNTX_CTL_CMD_M ; + reg = cmd |GLCOMM_QTX_CNTX_CTL_CMD_EXEC_M | + (((txq_base + txq_index) <<GLCOMM_QTX_CNTX_CTL_QUEUE_ID_S ) & +GLCOMM_QTX_CNTX_CTL_QUEUE_ID_M ); + +mutex_lock (&ice_global_txq_ctx_lock); + +wr32 (hw,GLCOMM_QTX_CNTX_CTL , reg); +ice_flush (hw); + + status =ice_copy_txq_ctx_from_hw (hw, ctx_buf); +if (status) { +mutex_unlock (&ice_global_txq_ctx_lock); +return status; + } + +mutex_unlock (&ice_global_txq_ctx_lock); + +return ice_get_ctx (ctx_buf, (u8 *)tlan_ctx, ice_tlan_ctx_data_info); +} + +/** +* ice_write_txq_ctx - Write txq context from HW +* @hw: pointer to the hardware structure +* @tlan_ctx: pointer to the txq context +* @txq_index: the index of the Tx queue +* +* Convert txq context from sparse to dense structure and then writes +* it to HW register space +*/ +int +ice_write_txq_ctx (struct ice_hw *hw,struct ice_tlan_ctx *tlan_ctx, +u32 txq_index) +{ +u8 ctx_buf[ICE_TXQ_CTX_SZ ] = {0 }; +int status; +u32 txq_base; +u32 cmd, reg; + +if (!tlan_ctx) +return -EINVAL ; + +if (txq_index >QTX_COMM_HEAD_MAX_INDEX ) +return -EINVAL ; + +ice_set_ctx (hw, (u8 *)tlan_ctx, ctx_buf, ice_tlan_ctx_info); + +/* Get TXQ base within card space */ + txq_base =rd32 (hw,PFLAN_TX_QALLOC (hw->pf_id)); + txq_base = (txq_base &PFLAN_TX_QALLOC_FIRSTQ_M ) >> +PFLAN_TX_QALLOC_FIRSTQ_S ; + + cmd = (GLCOMM_QTX_CNTX_CTL_CMD_WRITE_NO_DYN + <<GLCOMM_QTX_CNTX_CTL_CMD_S ) &GLCOMM_QTX_CNTX_CTL_CMD_M ; + reg = cmd |GLCOMM_QTX_CNTX_CTL_CMD_EXEC_M | + (((txq_base + txq_index) <<GLCOMM_QTX_CNTX_CTL_QUEUE_ID_S ) & +GLCOMM_QTX_CNTX_CTL_QUEUE_ID_M ); + +mutex_lock (&ice_global_txq_ctx_lock); + + status =ice_copy_txq_ctx_to_hw (hw, ctx_buf); +if (status) { +mutex_lock (&ice_global_txq_ctx_lock); +return status; + } + +wr32 (hw,GLCOMM_QTX_CNTX_CTL , reg); +ice_flush (hw); + +mutex_unlock (&ice_global_txq_ctx_lock); + +return 0 ; +}/* Sideband Queue command wrappers */ /**
drivers/net/ethernet/intel/ice/ice_common.h +6 -0
@@ -58,6 +58,12 @@ ice_write_rxq_ctx(struct ice_hw *hw, struct ice_rlan_ctx *rlan_ctx,int ice_read_rxq_ctx (struct ice_hw *hw,struct ice_rlan_ctx *rlan_ctx,u32 rxq_index); +int +ice_read_txq_ctx (struct ice_hw *hw,struct ice_tlan_ctx *tlan_ctx, +u32 txq_index); +int +ice_write_txq_ctx (struct ice_hw *hw,struct ice_tlan_ctx *tlan_ctx, +u32 txq_index);int ice_aq_get_rss_lut (struct ice_hw *hw,struct ice_aq_get_set_rss_lut_params *get_params);
drivers/net/ethernet/intel/ice/ice_hw_autogen.h +15 -0
@@ -8,6 +8,7 @@#define QTX_COMM_DBELL (_DBQM) (0x002C0000 + ((_DBQM) * 4))#define QTX_COMM_HEAD (_DBQM) (0x000E0000 + ((_DBQM) * 4)) +#define QTX_COMM_HEAD_MAX_INDEX 16383#define QTX_COMM_HEAD_HEAD_S 0#define QTX_COMM_HEAD_HEAD_M ICE_M(0x1FFF, 0)#define PF_FW_ARQBAH 0x00080180
@@ -258,6 +259,9 @@#define VPINT_ALLOC_PCI_VALID_M BIT(31)#define VPINT_MBX_CTL (_VSI) (0x0016A000 + ((_VSI) * 4))#define VPINT_MBX_CTL_CAUSE_ENA_M BIT(30) +#define PFLAN_TX_QALLOC (_PF) (0x001D2580 + ((_PF) * 4)) +#define PFLAN_TX_QALLOC_FIRSTQ_S 0 +#define PFLAN_TX_QALLOC_FIRSTQ_M ICE_M(0x3FFF, 0)#define GLLAN_RCTL_0 0x002941F8#define QRX_CONTEXT (_i, _QRX) (0x00280000 + ((_i) * 8192 + (_QRX) * 4))#define QRX_CTRL (_QRX) (0x00120000 + ((_QRX) * 4))
@@ -352,6 +356,17 @@#define GLNVM_ULD_POR_DONE_1_M BIT(8)#define GLNVM_ULD_PCIER_DONE_2_M BIT(9)#define GLNVM_ULD_PE_DONE_M BIT(10) +#define GLCOMM_QTX_CNTX_CTL 0x002D2DC8/* Reset Source: CORER */ +#define GLCOMM_QTX_CNTX_CTL_QUEUE_ID_S 0 +#define GLCOMM_QTX_CNTX_CTL_QUEUE_ID_M ICE_M(0x3FFF, 0) +#define GLCOMM_QTX_CNTX_CTL_CMD_S 16 +#define GLCOMM_QTX_CNTX_CTL_CMD_M ICE_M(0x7, 16) +#define GLCOMM_QTX_CNTX_CTL_CMD_READ 0 +#define GLCOMM_QTX_CNTX_CTL_CMD_WRITE 1 +#define GLCOMM_QTX_CNTX_CTL_CMD_RESET 3 +#define GLCOMM_QTX_CNTX_CTL_CMD_WRITE_NO_DYN 4 +#define GLCOMM_QTX_CNTX_CTL_CMD_EXEC_M BIT(19) +#define GLCOMM_QTX_CNTX_DATA (_i) (0x002D2D40 + ((_i) * 4))/* _i=0...9 */ #define GLPCI_CNF2 0x000BE004#define GLPCI_CNF2_CACHELINE_SIZE_M BIT(1)#define PF_FUNC_RID 0x0009E880
drivers/net/ethernet/intel/ice/ice_lan_tx_rx.h +3 -0
@@ -431,6 +431,8 @@ enum ice_rx_flex_desc_status_error_1_bits {#define ICE_RXQ_CTX_SIZE_DWORDS 8#define ICE_RXQ_CTX_SZ (ICE_RXQ_CTX_SIZE_DWORDS * sizeof(u32)) +#define ICE_TXQ_CTX_SIZE_DWORDS 10 +#define ICE_TXQ_CTX_SZ (ICE_TXQ_CTX_SIZE_DWORDS * sizeof(u32))#define ICE_TX_CMPLTNQ_CTX_SIZE_DWORDS 22#define ICE_TX_DRBELL_Q_CTX_SIZE_DWORDS 5#define GLTCLAN_CQ_CNTX (i,CQ ) (GLTCLAN_CQ_CNTX0(CQ) + ((i) * 0x0800))
@@ -649,6 +651,7 @@ struct ice_tlan_ctx {u8 cache_prof_idx;u8 pkt_shaper_prof_idx;u8 int_q_state;/* width not needed - internal - DO NOT WRITE!!! */ +u16 tail; };/* The ice_ptype_lkup table is used to convert from the 10-bit ptype in the
Signature · 1 line
2.34.1
PATCH v3 4/13 ice: Introduce VF state ICE_VF_STATE_REPLAYING_VC for migration
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
During migration device resume stage, part of device state is loaded by replaying logged virtual channel message. By default, once virtual channel message is processed successfully, PF will send message to VF.
In addition, PF will notify VF about link state while handling virtual channel message GET_VF_RESOURCE and ENABLE_QUEUES. And VF driver will print link state change info once receiving notification from PF.
However, device resume stage does not need PF to send messages to VF for the above cases. So stop PF from sending messages to VF while VF is in replay state.
--- drivers/net/ethernet/intel/ice/ice_vf_lib.h | 1 + drivers/net/ethernet/intel/ice/ice_virtchnl.c | 185 ++++++++++-------- drivers/net/ethernet/intel/ice/ice_virtchnl.h | 8 +- .../ethernet/intel/ice/ice_virtchnl_fdir.c | 28 +-- 4 files changed, 124 insertions(+), 98 deletions(-)
drivers/net/ethernet/intel/ice/ice_vf_lib.h +1 -0
@@ -37,6 +37,7 @@ enum ice_vf_states {ICE_VF_STATE_DIS ,ICE_VF_STATE_MC_PROMISC ,ICE_VF_STATE_UC_PROMISC , +ICE_VF_STATE_REPLAYING_VC , ICE_VF_STATES_NBITS };
drivers/net/ethernet/intel/ice/ice_virtchnl.c +105 -80
402 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_virtchnl.h +4 -4
@@ -60,8 +60,8 @@ void ice_vc_notify_vf_link_state(struct ice_vf *vf);void ice_vc_notify_link_state (struct ice_pf *pf);void ice_vc_notify_reset (struct ice_pf *pf);int -ice_vc_send_msg_to_vf (struct ice_vf *vf,u32 v_opcode, -enum virtchnl_status_code v_retval,u8 *msg,u16 msglen); +ice_vc_respond_to_vf (struct ice_vf *vf,u32 v_opcode, +enum virtchnl_status_code v_retval,u8 *msg,u16 msglen);bool ice_vc_isvalid_vsi_id (struct ice_vf *vf,u16 vsi_id);void ice_vc_process_vf_msg (struct ice_pf *pf,struct ice_rq_event_info *event,struct ice_mbx_data *mbxdata);
@@ -73,8 +73,8 @@ static inline void ice_vc_notify_link_state(struct ice_pf *pf) { }static inline void ice_vc_notify_reset (struct ice_pf *pf) { }static inline int -ice_vc_send_msg_to_vf (struct ice_vf *vf,u32 v_opcode, -enum virtchnl_status_code v_retval,u8 *msg,u16 msglen) +ice_vc_respond_to_vf (struct ice_vf *vf,u32 v_opcode, +enum virtchnl_status_code v_retval,u8 *msg,u16 msglen) {return -EOPNOTSUPP ; }
drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c +14 -14
@@ -1571,8 +1571,8 @@ ice_vc_add_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx, resp->flow_id = conf->flow_id; vf->fdir.fdir_fltr_cnt[conf->input.flow_type][is_tun]++; - ret =ice_vc_send_msg_to_vf (vf, ctx->v_opcode, v_ret, - (u8 *)resp, len); + ret =ice_vc_respond_to_vf (vf, ctx->v_opcode, v_ret, + (u8 *)resp, len);kfree (resp); dev_dbg(dev, "VF %d: flow_id:0x%X, FDIR %s success!\n",
@@ -1587,8 +1587,8 @@ ice_vc_add_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,ice_vc_fdir_remove_entry (vf, conf, conf->flow_id);devm_kfree (dev, conf); - ret =ice_vc_send_msg_to_vf (vf, ctx->v_opcode, v_ret, - (u8 *)resp, len); + ret =ice_vc_respond_to_vf (vf, ctx->v_opcode, v_ret, + (u8 *)resp, len);kfree (resp);return ret; }
@@ -1635,8 +1635,8 @@ ice_vc_del_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,ice_vc_fdir_remove_entry (vf, conf, conf->flow_id); vf->fdir.fdir_fltr_cnt[conf->input.flow_type][is_tun]--; - ret =ice_vc_send_msg_to_vf (vf, ctx->v_opcode, v_ret, - (u8 *)resp, len); + ret =ice_vc_respond_to_vf (vf, ctx->v_opcode, v_ret, + (u8 *)resp, len);kfree (resp); dev_dbg(dev, "VF %d: flow_id:0x%X, FDIR %s success!\n",
@@ -1652,8 +1652,8 @@ ice_vc_del_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,if (success)devm_kfree (dev, conf); - ret =ice_vc_send_msg_to_vf (vf, ctx->v_opcode, v_ret, - (u8 *)resp, len); + ret =ice_vc_respond_to_vf (vf, ctx->v_opcode, v_ret, + (u8 *)resp, len);kfree (resp);return ret; }
@@ -1850,8 +1850,8 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg) v_ret =VIRTCHNL_STATUS_SUCCESS ; stat->status =VIRTCHNL_FDIR_SUCCESS ;devm_kfree (dev, conf); - ret =ice_vc_send_msg_to_vf (vf,VIRTCHNL_OP_ADD_FDIR_FILTER , - v_ret, (u8 *)stat, len); + ret =ice_vc_respond_to_vf (vf,VIRTCHNL_OP_ADD_FDIR_FILTER , + v_ret, (u8 *)stat, len); goto exit; }
@@ -1909,8 +1909,8 @@ int ice_vc_add_fdir_fltr(struct ice_vf *vf, u8 *msg) err_free_conf:devm_kfree (dev, conf); err_exit: - ret =ice_vc_send_msg_to_vf (vf,VIRTCHNL_OP_ADD_FDIR_FILTER , v_ret, - (u8 *)stat, len); + ret =ice_vc_respond_to_vf (vf,VIRTCHNL_OP_ADD_FDIR_FILTER , v_ret, + (u8 *)stat, len);kfree (stat);return ret; }
@@ -1993,8 +1993,8 @@ int ice_vc_del_fdir_fltr(struct ice_vf *vf, u8 *msg) err_del_tmr:ice_vc_fdir_clear_irq_ctx (vf); err_exit: - ret =ice_vc_send_msg_to_vf (vf,VIRTCHNL_OP_DEL_FDIR_FILTER , v_ret, - (u8 *)stat, len); + ret =ice_vc_respond_to_vf (vf,VIRTCHNL_OP_DEL_FDIR_FILTER , v_ret, + (u8 *)stat, len);kfree (stat);return ret; }
Signature · 1 line
2.34.1
PATCH v3 5/13 ice: Add fundamental migration init and exit function
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
Add basic entry point for live migration functionality initialization, uninitialization and add helper function for vfio driver to reach pf driver data.
--- drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 3 + drivers/net/ethernet/intel/ice/ice_main.c | 15 ++++ .../net/ethernet/intel/ice/ice_migration.c | 83 +++++++++++++++++++ .../intel/ice/ice_migration_private.h | 21 +++++ drivers/net/ethernet/intel/ice/ice_vf_lib.c | 4 + drivers/net/ethernet/intel/ice/ice_vf_lib.h | 1 + include/linux/net/intel/ice_migration.h | 25 ++++++ 8 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_migration.c create mode 100644 drivers/net/ethernet/intel/ice/ice_migration_private.h create mode 100644 include/linux/net/intel/ice_migration.h
drivers/net/ethernet/intel/ice/Makefile +2 -1
@@ -50,4 +50,5 @@ ice-$(CONFIG_DCB) += ice_dcb.o ice_dcb_nl.o ice_dcb_lib.o ice-$(CONFIG_RFS_ACCEL) += ice_arfs.o ice-$(CONFIG_XDP_SOCKETS) += ice_xsk.o ice-$(CONFIG_ICE_SWITCHDEV) += ice_eswitch.o ice_eswitch_br.o -ice-$(CONFIG_GNSS) += ice_gnss.o +ice-$(CONFIG_GNSS) += ice_gnss.o +ice-$(CONFIG_ICE_VFIO_PCI) += ice_migration.o
drivers/net/ethernet/intel/ice/ice.h +3 -0
@@ -55,6 +55,7 @@#include <net/vxlan.h> #include <net/gtp.h> #include <linux/ppp_defs.h> +#include <linux/net/intel/ice_migration.h> #include "ice_devids.h" #include "ice_type.h" #include "ice_txrx.h"
@@ -76,6 +77,7 @@#include "ice_vsi_vlan_ops.h" #include "ice_gnss.h" #include "ice_irq.h" +#include "ice_migration_private.h" #define ICE_BAR0 0#define ICE_REQ_DESC_MULTIPLE 32
@@ -962,6 +964,7 @@ int ice_stop(struct net_device *netdev);void ice_service_task_schedule (struct ice_pf *pf);int ice_load (struct ice_pf *pf);void ice_unload (struct ice_pf *pf); +struct ice_pf *ice_get_pf_from_vf_pdev (struct pci_dev *pdev);/** * ice_set_rdma_cap - enable RDMA support
drivers/net/ethernet/intel/ice/ice_main.c +15 -0
@@ -9327,3 +9327,18 @@ static const struct net_device_ops ice_netdev_ops = { .ndo_xdp_xmit = ice_xdp_xmit, .ndo_xsk_wakeup = ice_xsk_wakeup, }; + +/** +* ice_get_pf_from_vf_pdev - Get PF structure from PCI device +* @pdev: pointer to PCI device +* +* Return pointer to ice PF structure, NULL for failure +*/ +struct ice_pf *ice_get_pf_from_vf_pdev (struct pci_dev *pdev) +{ +struct ice_pf *pf; + + pf =pci_iov_get_pf_drvdata (pdev, &ice_driver); + +return !IS_ERR (pf) ? pf :NULL ; +}
drivers/net/ethernet/intel/ice/ice_migration.c new file +83 -0
83 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_migration_private.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2018-2023 Intel Corporation */ + +#ifndef _ICE_MIGRATION_PRIVATE_H_ +#define _ICE_MIGRATION_PRIVATE_H_ + +/* This header file is for exposing functions in ice_migration.c to +* files which will be compiled in ice.ko. +* Functions which may be used by other files which will be compiled +* in ice-vfio-pic.ko should be exposed as part of ice_migration.h. +*/ + +#if IS_ENABLED (CONFIG_ICE_VFIO_PCI ) +void ice_migration_init_vf (struct ice_vf *vf); +void ice_migration_uninit_vf (struct ice_vf *vf); +#else +static inline void ice_migration_init_vf (struct ice_vf *vf) { } +static inline void ice_migration_uninit_vf (struct ice_vf *vf) { } +#endif /* CONFIG_ICE_VFIO_PCI */ + +#endif /* _ICE_MIGRATION_PRIVATE_H_ */
drivers/net/ethernet/intel/ice/ice_vf_lib.c +4 -0
@@ -241,6 +241,10 @@ static void ice_vf_pre_vsi_rebuild(struct ice_vf *vf)if (vf->vf_ops->irq_close) vf->vf_ops->irq_close (vf); +if (vf->migration_enabled) { +ice_migration_uninit_vf (vf); +ice_migration_init_vf (vf); + }ice_vf_clear_counters (vf); vf->vf_ops->clear_reset_trigger (vf); }
drivers/net/ethernet/intel/ice/ice_vf_lib.h +1 -0
@@ -137,6 +137,7 @@ struct ice_vf {/* devlink port data */ struct devlink_port devlink_port; +bool migration_enabled; };/* Flags for controlling behavior of ice_reset_vf */
include/linux/net/intel/ice_migration.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2018-2023 Intel Corporation */ + +#ifndef _ICE_MIGRATION_H_ +#define _ICE_MIGRATION_H_ + +#if IS_ENABLED (CONFIG_ICE_VFIO_PCI ) + +struct ice_pf ; + +struct ice_pf *ice_migration_get_pf (struct pci_dev *pdev); +int ice_migration_init_dev (struct ice_pf *pf,int vf_id); +void ice_migration_uninit_dev (struct ice_pf *pf,int vf_id); + +#else +static inline struct ice_pf *ice_migration_get_pf (struct pci_dev *pdev) +{ +return NULL ; +} + +static inline int ice_migration_init_dev (struct ice_pf *pf,int vf_id) { } +static inline void ice_migration_uninit_dev (struct ice_pf *pf,int vf_id) { } +#endif /* CONFIG_ICE_VFIO_PCI */ + +#endif /* _ICE_MIGRATION_H_ */
Signature · 1 line
2.34.1
PATCH v3 6/13 ice: Log virtual channel messages in PF
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
Save the virtual channel messages sent by VF on the source side during runtime. The logged virtchnl messages will be transferred and loaded into the device on the destination side during the device resume stage.
For the feature which can not be migrated yet, it must be disabled or blocked to prevent from being abused by VF. Otherwise, it may introduce functional and security issue. Mask unsupported VF capability flags in the VF-PF negotiaion stage.
--- .../net/ethernet/intel/ice/ice_migration.c | 167 ++++++++++++++++++ .../intel/ice/ice_migration_private.h | 12 ++ drivers/net/ethernet/intel/ice/ice_vf_lib.h | 5 + drivers/net/ethernet/intel/ice/ice_virtchnl.c | 29 +++ 4 files changed, 213 insertions(+)
drivers/net/ethernet/intel/ice/ice_migration.c +167 -0
@@ -3,6 +3,17 @@#include "ice.h" +struct ice_migration_virtchnl_msg_slot { +u32 opcode; +u16 msg_len; +char msg_buffer[]; +}; + +struct ice_migration_virtchnl_msg_listnode { +struct list_head node; +struct ice_migration_virtchnl_msg_slot msg_slot; +}; +/** * ice_migration_get_pf - Get ice PF structure pointer by pdev * @pdev: pointer to ice vfio pci VF pdev structure
@@ -22,6 +33,9 @@ EXPORT_SYMBOL(ice_migration_get_pf);void ice_migration_init_vf (struct ice_vf *vf) { vf->migration_enabled = true; +INIT_LIST_HEAD (&vf->virtchnl_msg_list); + vf->virtchnl_msg_num =0 ; + vf->virtchnl_msg_size =0 ; }/**
@@ -30,10 +44,24 @@ void ice_migration_init_vf(struct ice_vf *vf)*/ void ice_migration_uninit_vf (struct ice_vf *vf) { +struct ice_migration_virtchnl_msg_listnode *msg_listnode; +struct ice_migration_virtchnl_msg_listnode *dtmp; +if (!vf->migration_enabled)return ; vf->migration_enabled = false; + +if (list_empty (&vf->virtchnl_msg_list)) +return ; +list_for_each_entry_safe (msg_listnode, dtmp, + &vf->virtchnl_msg_list, + node) { +list_del (&msg_listnode->node); +kfree (msg_listnode); + } + vf->virtchnl_msg_num =0 ; + vf->virtchnl_msg_size =0 ; }/**
@@ -81,3 +109,142 @@ void ice_migration_uninit_dev(struct ice_pf *pf, int vf_id)ice_put_vf (vf); }EXPORT_SYMBOL (ice_migration_uninit_dev); + +/** +* ice_migration_is_loggable_msg - is this message loggable or not +* @v_opcode: virtchnl message operation code +* +* Return 1 for true, return 0 for false +*/ +static inline int ice_migration_is_loggable_msg (u32 v_opcode) +{ +switch (v_opcode) { +case VIRTCHNL_OP_VERSION : +case VIRTCHNL_OP_GET_VF_RESOURCES : +case VIRTCHNL_OP_CONFIG_VSI_QUEUES : +case VIRTCHNL_OP_CONFIG_IRQ_MAP : +case VIRTCHNL_OP_ADD_ETH_ADDR : +case VIRTCHNL_OP_DEL_ETH_ADDR : +case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE : +case VIRTCHNL_OP_ENABLE_QUEUES : +case VIRTCHNL_OP_DISABLE_QUEUES : +case VIRTCHNL_OP_ADD_VLAN : +case VIRTCHNL_OP_DEL_VLAN : +case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING : +case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING : +case VIRTCHNL_OP_CONFIG_RSS_KEY : +case VIRTCHNL_OP_CONFIG_RSS_LUT : +case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS : +return 1 ; +default : +return 0 ; + } +} + +/** +* ice_migration_log_vf_msg - Log request message from VF +* @vf: pointer to the VF structure +* @event: pointer to the AQ event +* +* Log VF message for later restore during live migration +* +* Return 0 for success, negative for error +*/ +int ice_migration_log_vf_msg (struct ice_vf *vf, +struct ice_rq_event_info *event) +{ +struct ice_migration_virtchnl_msg_listnode *msg_listnode; +u32 v_opcode =le32_to_cpu (event->desc.cookie_high); +struct device *dev =ice_pf_to_dev (vf->pf); +u16 msglen = event->msg_len; +u8 *msg = event->msg_buf; + +if (!ice_migration_is_loggable_msg (v_opcode)) +return 0 ; + +if (vf->virtchnl_msg_num >=VIRTCHNL_MSG_MAX ) { +dev_warn (dev,"VF %d has maximum number virtual channel commands\n" , + vf->vf_id); +return -ENOMEM ; + } + + msg_listnode = (struct ice_migration_virtchnl_msg_listnode *) +kzalloc (struct_size (msg_listnode, + msg_slot.msg_buffer, + msglen), +GFP_KERNEL ); +if (!msg_listnode) { +dev_err (dev,"VF %d failed to allocate memory for msg listnode\n" , + vf->vf_id); +return -ENOMEM ; + } +dev_dbg (dev,"VF %d save virtual channel command, op code: %d, len: %d\n" , + vf->vf_id, v_opcode, msglen); + msg_listnode->msg_slot.opcode = v_opcode; + msg_listnode->msg_slot.msg_len = msglen; +memcpy (msg_listnode->msg_slot.msg_buffer, msg, msglen); +list_add_tail (&msg_listnode->node, &vf->virtchnl_msg_list); + vf->virtchnl_msg_num++; + vf->virtchnl_msg_size +=struct_size (&msg_listnode->msg_slot, + msg_buffer, + msglen); +return 0 ; +} + +/** +* ice_migration_unlog_vf_msg - revert logged message +* @vf: pointer to the VF structure +* @v_opcode: virtchnl message operation code +* +* Remove the virtual channel message logged by ice_migration_log_vf_msg() +* before. +*/ +void ice_migration_unlog_vf_msg (struct ice_vf *vf,u32 v_opcode) +{ +struct ice_migration_virtchnl_msg_listnode *msg_listnode; + +if (!ice_migration_is_loggable_msg (v_opcode)) +return ; + +if (WARN_ON_ONCE (list_empty (&vf->virtchnl_msg_list))) +return ; + + msg_listnode =list_last_entry (&vf->virtchnl_msg_list, + struct ice_migration_virtchnl_msg_listnode, + node); +if (WARN_ON_ONCE (msg_listnode->msg_slot.opcode != v_opcode)) +return ; + +list_del (&msg_listnode->node); +kfree (msg_listnode); + vf->virtchnl_msg_num--; + vf->virtchnl_msg_size -=struct_size (&msg_listnode->msg_slot, + msg_buffer, + msg_listnode->msg_slot.msg_len); +} + +#define VIRTCHNL_VF_MIGRATION_SUPPORT_FEATURE \ + (VIRTCHNL_VF_OFFLOAD_L2 | \ + VIRTCHNL_VF_OFFLOAD_RSS_PF | \ + VIRTCHNL_VF_OFFLOAD_RSS_AQ | \ + VIRTCHNL_VF_OFFLOAD_RSS_REG | \ + VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 | \ + VIRTCHNL_VF_OFFLOAD_ENCAP | \ + VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM | \ + VIRTCHNL_VF_OFFLOAD_RX_POLLING | \ + VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | \ + VIRTCHNL_VF_CAP_ADV_LINK_SPEED | \ + VIRTCHNL_VF_OFFLOAD_VLAN | \ + VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC | \ + VIRTCHNL_VF_OFFLOAD_USO) + +/** +* ice_migration_supported_caps - get migration supported VF capabilities +* +* When migration is activated, some VF capabilities are not supported. +* So unmask those capability flags for VF resources. +*/ +u32 ice_migration_supported_caps (void ) +{ +return VIRTCHNL_VF_MIGRATION_SUPPORT_FEATURE ; +}
drivers/net/ethernet/intel/ice/ice_migration_private.h +12 -0
@@ -13,9 +13,21 @@#if IS_ENABLED (CONFIG_ICE_VFIO_PCI )void ice_migration_init_vf (struct ice_vf *vf);void ice_migration_uninit_vf (struct ice_vf *vf); +int ice_migration_log_vf_msg (struct ice_vf *vf, +struct ice_rq_event_info *event); +void ice_migration_unlog_vf_msg (struct ice_vf *vf,u32 v_opcode); +u32 ice_migration_supported_caps (void );#else static inline void ice_migration_init_vf (struct ice_vf *vf) { }static inline void ice_migration_uninit_vf (struct ice_vf *vf) { } +static inline void +ice_migration_save_vf_msg (struct ice_vf *vf, +struct ice_rq_event_info *event) { } +static inline u32 +ice_migration_supported_caps (void ) +{ +return 0xFFFFFFFF ; +}#endif /* CONFIG_ICE_VFIO_PCI */ #endif /* _ICE_MIGRATION_PRIVATE_H_ */
drivers/net/ethernet/intel/ice/ice_vf_lib.h +5 -0
@@ -77,6 +77,7 @@ struct ice_vfs {unsigned long last_printed_mdd_jiffies;/* MDD message rate limit */ }; +#define VIRTCHNL_MSG_MAX 1000/* VF information structure */ struct ice_vf {struct hlist_node entry;
@@ -138,6 +139,10 @@ struct ice_vf {/* devlink port data */ struct devlink_port devlink_port;bool migration_enabled; +struct list_head virtchnl_msg_list; +u64 virtchnl_msg_num; +u64 virtchnl_msg_size; +u32 virtchnl_retval; };/* Flags for controlling behavior of ice_reset_vf */
drivers/net/ethernet/intel/ice/ice_virtchnl.c +29 -0
@@ -338,6 +338,12 @@ ice_vc_respond_to_vf(struct ice_vf *vf, u32 v_opcode,return -EIO ; } +/* v_retval will not be returned in this function, store it in the +* per VF field to be used by migration logging logic later. +*/ +if (vf->migration_enabled) + vf->virtchnl_retval = v_retval; +return ice_vc_send_response_to_vf (vf, v_opcode, v_retval, msg, msglen); }
@@ -470,6 +476,8 @@ static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)VIRTCHNL_VF_OFFLOAD_RSS_REG |VIRTCHNL_VF_OFFLOAD_VLAN ; +if (vf->migration_enabled) + vf->driver_caps &=ice_migration_supported_caps (); vfres->vf_cap_flags =VIRTCHNL_VF_OFFLOAD_L2 ; vsi =ice_get_vf_vsi (vf);if (!vsi) {
@@ -4026,6 +4034,15 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event, goto finish; } +if (vf->migration_enabled) { +if (ice_migration_log_vf_msg (vf, event)) { + err =ice_vc_respond_to_vf (vf, v_opcode, +VIRTCHNL_STATUS_ERR_NO_MEMORY , +NULL ,0 ); + goto finish; + } + } +switch (v_opcode) {case VIRTCHNL_OP_VERSION : err = ops->get_ver_msg (vf, msg);
@@ -4145,6 +4162,18 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event, vf_id, v_opcode, err); } +/* All of the loggable virtual channel messages are logged by +* ice_migration_unlog_vf_msg() before they are processed. +* +* Two kinds of error may happen, virtual channel message's result +* is failure after processed by PF or message is not sent to VF +* successfully. If error happened, fallback here by reverting logged +* messages. +*/ +if (vf->migration_enabled && + (vf->virtchnl_retval !=VIRTCHNL_STATUS_SUCCESS || err)) +ice_migration_unlog_vf_msg (vf, v_opcode); + finish:mutex_unlock (&vf->cfg_lock);ice_put_vf (vf);
Signature · 1 line
2.34.1
PATCH v3 7/13 ice: Add device state save/restore function for migration
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
Add device state save/restore function to adapter vfio migration stack when device is in stop-copy/resume stage.
Device state saving handler is called by vfio driver in device stop copy stage. It snapshots the device state, translates device state into device specific data and fills the data into migration buffer.
Device state restoring handler is called by vfio driver in device resume stage. It gets device specific data from the migration buffer, translates the data into the device state and recover the device with the state.
Currently only the virtual channel messages are handled.
--- .../net/ethernet/intel/ice/ice_migration.c | 222 ++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_virtchnl.c | 26 +- drivers/net/ethernet/intel/ice/ice_virtchnl.h | 7 +- include/linux/net/intel/ice_migration.h | 12 + 4 files changed, 258 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/ice/ice_migration.c +222 -0
@@ -3,6 +3,9 @@#include "ice.h" +#define ICE_MIG_DEVSTAT_MAGIC 0xE8000001 +#define ICE_MIG_DEVSTAT_VERSION 0x1 +struct ice_migration_virtchnl_msg_slot {u32 opcode;u16 msg_len;
@@ -14,6 +17,17 @@ struct ice_migration_virtchnl_msg_listnode {struct ice_migration_virtchnl_msg_slot msg_slot; }; +struct ice_migration_dev_state { +u32 magic; +u32 version; +u64 total_size; +u32 vf_caps; +u16 num_txq; +u16 num_rxq; + +u8 virtchnl_msgs[]; +}__aligned(8) ; +/** * ice_migration_get_pf - Get ice PF structure pointer by pdev * @pdev: pointer to ice vfio pci VF pdev structure
@@ -248,3 +262,211 @@ u32 ice_migration_supported_caps(void) {return VIRTCHNL_VF_MIGRATION_SUPPORT_FEATURE ; } + +/** +* ice_migration_save_devstate - save device state to migration buffer +* @pf: pointer to PF of migration device +* @vf_id: VF index of migration device +* @buf: pointer to VF msg in migration buffer +* @buf_sz: size of migration buffer +* +* Return 0 for success, negative for error +*/ +int ice_migration_save_devstate (struct ice_pf *pf,int vf_id,u8 *buf,u64 buf_sz) +{ +struct ice_migration_virtchnl_msg_listnode *msg_listnode; +struct ice_migration_virtchnl_msg_slot *dummy_op; +struct ice_migration_dev_state *devstate; +struct device *dev =ice_pf_to_dev (pf); +struct ice_vsi *vsi; +struct ice_vf *vf; +u64 total_sz; +int ret =0 ; + + vf =ice_get_vf_by_id (pf, vf_id); +if (!vf) { +dev_err (dev,"Unable to locate VF from VF ID%d\n" , vf_id); +return -EINVAL ; + } + + vsi =ice_get_vf_vsi (vf); +if (!vsi) { +dev_err (dev,"VF %d VSI is NULL\n" , vf->vf_id); + ret = -EINVAL ; + goto out_put_vf; + } + +/* Reserve space to store device state */ + total_sz =sizeof (struct ice_migration_dev_state ) + + vf->virtchnl_msg_size +sizeof (*dummy_op); +if (total_sz > buf_sz) { +dev_err (dev,"Insufficient buffer to store device state for VF %d\n" , + vf->vf_id); + ret = -ENOBUFS ; + goto out_put_vf; + } + + devstate = (struct ice_migration_dev_state *)buf; + devstate->magic =ICE_MIG_DEVSTAT_MAGIC ; + devstate->version =ICE_MIG_DEVSTAT_VERSION ; + devstate->total_size = total_sz; + devstate->vf_caps =ice_migration_supported_caps (); + devstate->num_txq = vsi->num_txq; + devstate->num_rxq = vsi->num_rxq; + buf = devstate->virtchnl_msgs; + +list_for_each_entry (msg_listnode, &vf->virtchnl_msg_list, node) { +struct ice_migration_virtchnl_msg_slot *msg_slot; +u64 slot_size; + + msg_slot = &msg_listnode->msg_slot; + slot_size =struct_size (msg_slot, msg_buffer, + msg_slot->msg_len); +dev_dbg (dev,"VF %d copy virtchnl message to migration buffer op: %d, len: %d\n" , + vf->vf_id, msg_slot->opcode, msg_slot->msg_len); +memcpy (buf, msg_slot, slot_size); + buf += slot_size; + } + +/* Use op code unknown to mark end of vc messages */ + dummy_op = (struct ice_migration_virtchnl_msg_slot *)buf; + dummy_op->opcode =VIRTCHNL_OP_UNKNOWN ; + +out_put_vf: +ice_put_vf (vf); +return ret; +} +EXPORT_SYMBOL (ice_migration_save_devstate); + +/** +* ice_migration_check_match - check if configuration is matched or not +* @pf: pointer to VF +* @buf: pointer to device state buffer +* @buf_sz: size of buffer +* +* Return 0 for success, negative for error +*/ +static int ice_migration_check_match (struct ice_vf *vf,const u8 *buf,u64 buf_sz) +{ +u32 supported_caps =ice_migration_supported_caps (); +struct device *dev =ice_pf_to_dev (vf->pf); +struct ice_migration_dev_state *devstate; +struct ice_vsi *vsi; + + vsi =ice_get_vf_vsi (vf); +if (!vsi) { +dev_err (dev,"VF %d VSI is NULL\n" , vf->vf_id); +return -EINVAL ; + } + +if (sizeof (struct ice_migration_dev_state ) > buf_sz) { +dev_err (dev,"VF %d devstate header exceeds buffer size\n" , + vf->vf_id); +return -EINVAL ; + } + + devstate = (struct ice_migration_dev_state *)buf; +if (devstate->magic !=ICE_MIG_DEVSTAT_MAGIC ) { +dev_err (dev,"VF %d devstate has invalid magic 0x%x\n" , + vf->vf_id, devstate->magic); +return -EINVAL ; + } + +if (devstate->version !=ICE_MIG_DEVSTAT_VERSION ) { +dev_err (dev,"VF %d devstate has invalid version 0x%x\n" , + vf->vf_id, devstate->version); +return -EINVAL ; + } + +if (devstate->num_txq != vsi->num_txq) { +dev_err (dev,"Failed to match VF %d tx queue number, request %d, support %d\n" , + vf->vf_id, devstate->num_txq, vsi->num_txq); +return -EINVAL ; + } + +if (devstate->num_rxq != vsi->num_rxq) { +dev_err (dev,"Failed to match VF %d rx queue number, request %d, support %d\n" , + vf->vf_id, devstate->num_rxq, vsi->num_rxq); +return -EINVAL ; + } + +if ((devstate->vf_caps & supported_caps) != devstate->vf_caps) { +dev_err (dev,"Failed to match VF %d caps, request 0x%x, support 0x%x\n" , + vf->vf_id, devstate->vf_caps, supported_caps); +return -EINVAL ; + } + +if (devstate->total_size > buf_sz) { +dev_err (dev,"VF %d devstate exceeds buffer size\n" , + vf->vf_id); +return -EINVAL ; + } + +return 0 ; +} + +/** +* ice_migration_restore_devstate - restore device state at dst +* @pf: pointer to PF of migration device +* @vf_id: VF index of migration device +* @buf: pointer to device state buf in migration buffer +* @buf_sz: size of migration buffer +* +* This function uses the device state saved in migration buffer +* to restore device state at dst VM +* +* Return 0 for success, negative for error +*/ +int ice_migration_restore_devstate (struct ice_pf *pf,int vf_id,const u8 *buf,u64 buf_sz) +{ +struct ice_migration_virtchnl_msg_slot *msg_slot; +struct ice_migration_dev_state *devstate; +struct device *dev =ice_pf_to_dev (pf); +struct ice_vf *vf; +int ret =0 ; + +if (!buf) +return -EINVAL ; + + vf =ice_get_vf_by_id (pf, vf_id); +if (!vf) { +dev_err (dev,"Unable to locate VF from VF ID%d\n" , vf_id); +return -EINVAL ; + } + + ret =ice_migration_check_match (vf, buf, buf_sz); +if (ret) + goto out_put_vf; + + devstate = (struct ice_migration_dev_state *)buf; + msg_slot = (struct ice_migration_virtchnl_msg_slot *)devstate->virtchnl_msgs; +set_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states); + +while (msg_slot->opcode !=VIRTCHNL_OP_UNKNOWN ) { +struct ice_rq_event_info event; +u64 slot_sz; + + slot_sz =struct_size (msg_slot, msg_buffer, msg_slot->msg_len); +dev_dbg (dev,"VF %d replay virtchnl message op code: %d, msg len: %d\n" , + vf->vf_id, msg_slot->opcode, msg_slot->msg_len); + event.desc.cookie_high = msg_slot->opcode; + event.msg_len = msg_slot->msg_len; + event.desc.retval = vf->vf_id; + event.msg_buf = (unsigned char *)msg_slot->msg_buffer; + ret =ice_vc_process_vf_msg (vf->pf, &event,NULL ); +if (ret) { +dev_err (dev,"VF %d failed to replay virtchnl message op code: %d\n" , + vf->vf_id, msg_slot->opcode); + goto out_clear_replay; + } + event.msg_buf =NULL ; + msg_slot = (struct ice_migration_virtchnl_msg_slot *) + ((char *)msg_slot + slot_sz); + } +out_clear_replay: +clear_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states); +out_put_vf: +ice_put_vf (vf); +return ret; +} +EXPORT_SYMBOL (ice_migration_restore_devstate);
drivers/net/ethernet/intel/ice/ice_virtchnl.c +20 -6
@@ -3971,11 +3971,24 @@ ice_is_malicious_vf(struct ice_vf *vf, struct ice_mbx_data *mbxdata)* @event: pointer to the AQ event * @mbxdata: information used to detect VF attempting mailbox overflow * -* called from the common asq/arq handler to -* process request from VF +* This function will be called from: +* 1. the common asq/arq handler to process request from VF +* +* The return value is ignored, as the command handler will send the status +* of the request as a response to the VF. This flow sets the mbxdata to +* a non-NULL value and must call ice_is_malicious_vf to determine if this +* VF might be attempting to overflow the PF message queue. +* +* 2. replay virtual channel commamds during live migration +* +* The return value is used to indicate failure to replay vc commands and +* that the migration failed. This flow sets mbxdata to NULL and skips the +* ice_is_malicious_vf checks which are unnecessary during replay. +* +* Return 0 if success, negative for failure. */ -void ice_vc_process_vf_msg (struct ice_pf *pf,struct ice_rq_event_info *event, -struct ice_mbx_data *mbxdata) +int ice_vc_process_vf_msg (struct ice_pf *pf,struct ice_rq_event_info *event, +struct ice_mbx_data *mbxdata) {u32 v_opcode =le32_to_cpu (event->desc.cookie_high);s16 vf_id =le16_to_cpu (event->desc.retval);
@@ -3992,13 +4005,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,if (!vf) {dev_err (dev,"Unable to locate VF for message from VF ID %d, opcode %d, len %d\n" , vf_id, v_opcode, msglen); -return ; +return -EINVAL ; }mutex_lock (&vf->cfg_lock);/* Check if the VF is trying to overflow the mailbox */ -if (ice_is_malicious_vf (vf, mbxdata)) +if (!test_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states) &&ice_is_malicious_vf (vf, mbxdata)) goto finish;/* Check if VF is disabled. */
@@ -4177,4 +4190,5 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event, finish:mutex_unlock (&vf->cfg_lock);ice_put_vf (vf); +return err; }
drivers/net/ethernet/intel/ice/ice_virtchnl.h +4 -3
@@ -63,8 +63,8 @@ int ice_vc_respond_to_vf(struct ice_vf *vf, u32 v_opcode, enum virtchnl_status_code v_retval, u8 *msg, u16 msglen);bool ice_vc_isvalid_vsi_id (struct ice_vf *vf,u16 vsi_id); -void ice_vc_process_vf_msg (struct ice_pf *pf,struct ice_rq_event_info *event, -struct ice_mbx_data *mbxdata); +int ice_vc_process_vf_msg (struct ice_pf *pf,struct ice_rq_event_info *event, +struct ice_mbx_data *mbxdata);#else /* CONFIG_PCI_IOV */ static inline void ice_virtchnl_set_dflt_ops (struct ice_vf *vf) { }static inline void ice_virtchnl_set_repr_ops (struct ice_vf *vf) { }
@@ -84,10 +84,11 @@ static inline bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id) return false; } -static inline void +static inline int ice_vc_process_vf_msg (struct ice_pf *pf,struct ice_rq_event_info *event,struct ice_mbx_data *mbxdata) { +return -EOPNOTSUPP ; }#endif /* !CONFIG_PCI_IOV */
include/linux/net/intel/ice_migration.h +12 -0
@@ -11,6 +11,8 @@ struct ice_pf;struct ice_pf *ice_migration_get_pf (struct pci_dev *pdev);int ice_migration_init_dev (struct ice_pf *pf,int vf_id);void ice_migration_uninit_dev (struct ice_pf *pf,int vf_id); +int ice_migration_save_devstate (struct ice_pf *pf,int vf_id,u8 *buf,u64 buf_sz); +int ice_migration_restore_devstate (struct ice_pf *pf,int vf_id,const u8 *buf,u64 buf_sz);#else static inline struct ice_pf *ice_migration_get_pf (struct pci_dev *pdev)
@@ -20,6 +22,16 @@ static inline struct ice_pf *ice_migration_get_pf(struct pci_dev *pdev)static inline int ice_migration_init_dev (struct ice_pf *pf,int vf_id) { }static inline void ice_migration_uninit_dev (struct ice_pf *pf,int vf_id) { } +static inline int ice_migration_save_devstate (struct ice_pf *pf,int vf_id,u8 *buf,u64 buf_sz) +{ +return 0 ; +} + +static inline int ice_migration_restore_devstate (struct ice_pf *pf,int vf_id, +const u8 *buf,u64 buf_sz) +{ +return 0 ; +}#endif /* CONFIG_ICE_VFIO_PCI */ #endif /* _ICE_MIGRATION_H_ */
Signature · 6 lines
2.34.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH v3 8/13 ice: Fix VSI id in virtual channel message for migration
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
VSI id is a resource id for each VF and it is an absolute hardware id per PCI card. It is exposed to VF driver through virtual channel messages at the VF-PF negotiation stage. It is constant during the whole device lifecycle unless driver re-init.
Almost all of the virtual channel messages will contain the VSI id. Once PF receives message, it will check if VSI id in the message is equal to the VF's VSI id for security and other reason. If a VM backed by VF VSI A is migrated to a VM backed by VF with VSI B, while in messages replaying stage, all the messages will be rejected by PF due to the invalid VSI id. Even after migration, VM runtime will get failure as well.
Fix this gap by modifying the VSI id in the virtual channel message at migration device resuming stage and VM runtime stage. In most cases the VSI id will vary between migration source and destination side. And this is a slow path anyway.
--- .../net/ethernet/intel/ice/ice_migration.c | 96 +++++++++++++++++++ .../intel/ice/ice_migration_private.h | 4 + drivers/net/ethernet/intel/ice/ice_vf_lib.h | 1 + drivers/net/ethernet/intel/ice/ice_virtchnl.c | 1 + 4 files changed, 102 insertions(+)
drivers/net/ethernet/intel/ice/ice_migration.c +96 -0
@@ -25,6 +25,7 @@ struct ice_migration_dev_state {u16 num_txq;u16 num_rxq; +u16 vsi_id;u8 virtchnl_msgs[]; }__aligned(8) ;
@@ -50,6 +51,7 @@ void ice_migration_init_vf(struct ice_vf *vf)INIT_LIST_HEAD (&vf->virtchnl_msg_list); vf->virtchnl_msg_num =0 ; vf->virtchnl_msg_size =0 ; + vf->vm_vsi_num = vf->lan_vsi_num; }/**
@@ -314,6 +316,7 @@ int ice_migration_save_devstate(struct ice_pf *pf, int vf_id, u8 *buf, u64 buf_s devstate->num_txq = vsi->num_txq; devstate->num_rxq = vsi->num_rxq; buf = devstate->virtchnl_msgs; + devstate->vsi_id = vf->vm_vsi_num;list_for_each_entry (msg_listnode, &vf->virtchnl_msg_list, node) {struct ice_migration_virtchnl_msg_slot *msg_slot;
@@ -439,6 +442,8 @@ int ice_migration_restore_devstate(struct ice_pf *pf, int vf_id, const u8 *buf, goto out_put_vf; devstate = (struct ice_migration_dev_state *)buf; + vf->vm_vsi_num = devstate->vsi_id; +dev_dbg (dev,"VF %d vm vsi num is:%d\n" , vf->vf_id, vf->vm_vsi_num); msg_slot = (struct ice_migration_virtchnl_msg_slot *)devstate->virtchnl_msgs;set_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states);
@@ -470,3 +475,94 @@ int ice_migration_restore_devstate(struct ice_pf *pf, int vf_id, const u8 *buf,return ret; }EXPORT_SYMBOL (ice_migration_restore_devstate); + +/** +* ice_migration_fix_msg_vsi - change virtual channel msg VSI id +* +* @vf: pointer to the VF structure +* @v_opcode: virtchnl message operation code +* @msg: pointer to the virtual channel message +* +* After migration, the VSI id of virtual channel message is still +* migration src VSI id. Some virtual channel commands will fail +* due to unmatch VSI id. +* Change virtual channel message payload VSI id to real VSI id. +*/ +void ice_migration_fix_msg_vsi (struct ice_vf *vf,u32 v_opcode,u8 *msg) +{ +if (!vf->migration_enabled) +return ; + +switch (v_opcode) { +case VIRTCHNL_OP_ADD_ETH_ADDR : +case VIRTCHNL_OP_DEL_ETH_ADDR : +case VIRTCHNL_OP_ENABLE_QUEUES : +case VIRTCHNL_OP_DISABLE_QUEUES : +case VIRTCHNL_OP_CONFIG_RSS_KEY : +case VIRTCHNL_OP_CONFIG_RSS_LUT : +case VIRTCHNL_OP_GET_STATS : +case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE : +case VIRTCHNL_OP_ADD_FDIR_FILTER : +case VIRTCHNL_OP_DEL_FDIR_FILTER : +case VIRTCHNL_OP_ADD_VLAN : +case VIRTCHNL_OP_DEL_VLAN : { +/* Read the beginning two bytes of message for VSI id */ +u16 *vsi_id = (u16 *)msg; + +/* For VM runtime stage, vsi_id in the virtual channel message +* should be equal to the PF logged vsi_id and vsi_id is +* replaced by VF's VSI id to guarantee that messages are +* processed successfully. If vsi_id is not equal to the PF +* logged vsi_id, then this message must be sent by malicious +* VF and no replacement is needed. Just let virtual channel +* handler to fail this message. +* +* For virtual channel replaying stage, all of the PF logged +* virtual channel messages are trusted and vsi_id is replaced +* anyway to guarantee the messages are processed successfully. +*/ +if (*vsi_id == vf->vm_vsi_num || +test_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states)) + *vsi_id = vf->lan_vsi_num; +break ; + } +case VIRTCHNL_OP_CONFIG_IRQ_MAP : { +struct virtchnl_irq_map_info *irqmap_info; +u16 num_q_vectors_mapped; +int i; + + irqmap_info = (struct virtchnl_irq_map_info *)msg; + num_q_vectors_mapped = irqmap_info->num_vectors; +for (i =0 ; i < num_q_vectors_mapped; i++) { +struct virtchnl_vector_map *map; + + map = &irqmap_info->vecmap[i]; +if (map->vsi_id == vf->vm_vsi_num || +test_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states)) + map->vsi_id = vf->lan_vsi_num; + } +break ; + } +case VIRTCHNL_OP_CONFIG_VSI_QUEUES : { +struct virtchnl_vsi_queue_config_info *qci; + + qci = (struct virtchnl_vsi_queue_config_info *)msg; +if (qci->vsi_id == vf->vm_vsi_num || +test_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states)) { +int i; + + qci->vsi_id = vf->lan_vsi_num; +for (i =0 ; i < qci->num_queue_pairs; i++) { +struct virtchnl_queue_pair_info *qpi; + + qpi = &qci->qpair[i]; + qpi->txq.vsi_id = vf->lan_vsi_num; + qpi->rxq.vsi_id = vf->lan_vsi_num; + } + } +break ; + } +default : +break ; + } +}
drivers/net/ethernet/intel/ice/ice_migration_private.h +4 -0
@@ -17,6 +17,7 @@ int ice_migration_log_vf_msg(struct ice_vf *vf, struct ice_rq_event_info *event);void ice_migration_unlog_vf_msg (struct ice_vf *vf,u32 v_opcode);u32 ice_migration_supported_caps (void ); +void ice_migration_fix_msg_vsi (struct ice_vf *vf,u32 v_opcode,u8 *msg);#else static inline void ice_migration_init_vf (struct ice_vf *vf) { }static inline void ice_migration_uninit_vf (struct ice_vf *vf) { }
@@ -28,6 +29,9 @@ ice_migration_supported_caps(void) {return 0xFFFFFFFF ; } + +static inline void +ice_migration_fix_msg_vsi (struct ice_vf *vf,u32 v_opcode,u8 *msg) { }#endif /* CONFIG_ICE_VFIO_PCI */ #endif /* _ICE_MIGRATION_PRIVATE_H_ */
drivers/net/ethernet/intel/ice/ice_vf_lib.h +1 -0
@@ -143,6 +143,7 @@ struct ice_vf {u64 virtchnl_msg_num;u64 virtchnl_msg_size;u32 virtchnl_retval; +u16 vm_vsi_num; };/* Flags for controlling behavior of ice_reset_vf */
drivers/net/ethernet/intel/ice/ice_virtchnl.c +1 -0
@@ -4048,6 +4048,7 @@ int ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event, }if (vf->migration_enabled) { +ice_migration_fix_msg_vsi (vf, v_opcode, msg);if (ice_migration_log_vf_msg (vf, event)) { err = ice_vc_respond_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_NO_MEMORY,
Signature · 6 lines
2.34.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH v3 9/13 ice: Save and restore RX Queue head
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
RX Queue head is a fundamental dma ring context which determines the next RX descriptor to be fetched. However, RX Queue head is not visible to VF while it is only visible in PF. As a result, PF needs to save and restore RX Queue Head explicitly.
Since network packets may come in at any time once RX Queue is enabled, RX Queue head needs to be restored before Queue is enabled.
RX Queue head restoring handler is implemented by reading and then overwriting queue context with specific HEAD value.
--- .../net/ethernet/intel/ice/ice_migration.c | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+)
drivers/net/ethernet/intel/ice/ice_migration.c +125 -0
@@ -2,9 +2,11 @@/* Copyright (C) 2018-2023 Intel Corporation */ #include "ice.h" +#include "ice_base.h" #define ICE_MIG_DEVSTAT_MAGIC 0xE8000001#define ICE_MIG_DEVSTAT_VERSION 0x1 +#define ICE_MIG_VF_QRX_TAIL_MAX 256struct ice_migration_virtchnl_msg_slot {u32 opcode;
@@ -26,6 +28,8 @@ struct ice_migration_dev_state {u16 num_rxq;u16 vsi_id; +/* next RX desc index to be processed by the device */ +u16 rx_head[ICE_MIG_VF_QRX_TAIL_MAX ];u8 virtchnl_msgs[]; }__aligned(8) ;
@@ -265,6 +269,54 @@ u32 ice_migration_supported_caps(void)return VIRTCHNL_VF_MIGRATION_SUPPORT_FEATURE ; } +/** +* ice_migration_save_rx_head - save rx head into device state buffer +* @vf: pointer to VF structure +* @devstate: pointer to migration buffer +* +* Return 0 for success, negative for error +*/ +static int +ice_migration_save_rx_head (struct ice_vf *vf, +struct ice_migration_dev_state *devstate) +{ +struct device *dev =ice_pf_to_dev (vf->pf); +struct ice_vsi *vsi; +int i; + + vsi =ice_get_vf_vsi (vf); +if (!vsi) { +dev_err (dev,"VF %d VSI is NULL\n" , vf->vf_id); +return -EINVAL ; + } + +ice_for_each_rxq (vsi, i) { +struct ice_rx_ring *rx_ring = vsi->rx_rings[i]; +struct ice_rlan_ctx rlan_ctx = {}; +struct ice_hw *hw = &vf->pf->hw; +u16 rxq_index; +int status; + +if (WARN_ON_ONCE (!rx_ring)) +return -EINVAL ; + + devstate->rx_head[i] =0 ; +if (!test_bit (i, vf->rxq_ena)) +continue ; + + rxq_index = rx_ring->reg_idx; + status =ice_read_rxq_ctx (hw, &rlan_ctx, rxq_index); +if (status) { +dev_err (dev,"Failed to read RXQ[%d] context, err=%d\n" , + rx_ring->q_index, status); +return -EIO ; + } + devstate->rx_head[i] = rlan_ctx.head; + } + +return 0 ; +} +/** * ice_migration_save_devstate - save device state to migration buffer * @pf: pointer to PF of migration device
@@ -318,6 +370,12 @@ int ice_migration_save_devstate(struct ice_pf *pf, int vf_id, u8 *buf, u64 buf_s buf = devstate->virtchnl_msgs; devstate->vsi_id = vf->vm_vsi_num; + ret =ice_migration_save_rx_head (vf, devstate); +if (ret) { +dev_err (dev,"VF %d failed to save rxq head\n" , vf->vf_id); + goto out_put_vf; + } +list_for_each_entry (msg_listnode, &vf->virtchnl_msg_list, node) {struct ice_migration_virtchnl_msg_slot *msg_slot;u64 slot_size;
@@ -408,6 +466,57 @@ static int ice_migration_check_match(struct ice_vf *vf, const u8 *buf, u64 buf_sreturn 0 ; } +/** +* ice_migration_restore_rx_head - restore rx head from device state buffer +* @vf: pointer to VF structure +* @devstate: pointer to migration device state +* +* Return 0 for success, negative for error +*/ +static int +ice_migration_restore_rx_head (struct ice_vf *vf, +struct ice_migration_dev_state *devstate) +{ +struct device *dev =ice_pf_to_dev (vf->pf); +struct ice_vsi *vsi; +int i; + + vsi =ice_get_vf_vsi (vf); +if (!vsi) { +dev_err (dev,"VF %d VSI is NULL\n" , vf->vf_id); +return -EINVAL ; + } + +ice_for_each_rxq (vsi, i) { +struct ice_rx_ring *rx_ring = vsi->rx_rings[i]; +struct ice_rlan_ctx rlan_ctx = {}; +struct ice_hw *hw = &vf->pf->hw; +u16 rxq_index; +int status; + +if (WARN_ON_ONCE (!rx_ring)) +return -EINVAL ; + + rxq_index = rx_ring->reg_idx; + status =ice_read_rxq_ctx (hw, &rlan_ctx, rxq_index); +if (status) { +dev_err (dev,"Failed to read RXQ[%d] context, err=%d\n" , + rx_ring->q_index, status); +return -EIO ; + } + + rlan_ctx.head = devstate->rx_head[i]; + status =ice_write_rxq_ctx (hw, &rlan_ctx, rxq_index); +if (status) { +dev_err (dev,"Failed to set LAN RXQ[%d] context, err=%d\n" , + rx_ring->q_index, status); +return -EIO ; + } + } + +return 0 ; +} +/** * ice_migration_restore_devstate - restore device state at dst * @pf: pointer to PF of migration device
@@ -464,6 +573,22 @@ int ice_migration_restore_devstate(struct ice_pf *pf, int vf_id, const u8 *buf, vf->vf_id, msg_slot->opcode); goto out_clear_replay; } + +/* Once RX Queue is enabled, network traffic may come in at any +* time. As a result, RX Queue head needs to be restored before +* RX Queue is enabled. +* For simplicity and integration, overwrite RX head just after +* RX ring context is configured. +*/ +if (msg_slot->opcode ==VIRTCHNL_OP_CONFIG_VSI_QUEUES ) { + ret =ice_migration_restore_rx_head (vf, devstate); +if (ret) { +dev_err (dev,"VF %d failed to restore rx head\n" , + vf->vf_id); + goto out_clear_replay; + } + } + event.msg_buf =NULL ; msg_slot = (struct ice_migration_virtchnl_msg_slot *) ((char *)msg_slot + slot_sz);
Signature · 6 lines
2.34.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
PATCH v3 10/13 ice: Save and restore TX Queue head
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
TX Queue head is a fundamental DMA ring context which determines the next TX descriptor to be fetched. However, TX Queue head is not visible to VF while it is only visible in PF. As a result, PF needs to save and restore TX Queue head explicitly.
Unfortunately, due to HW limitation, TX Queue head can't be recovered through writing mmio registers.
Since sending one packet will make TX head advanced by 1 index, TX Queue head can be advanced by N index through sending N packets. So filling in DMA ring with NOP descriptors and bumping doorbell can be used to change TX Queue head indirectly. And this method has no side effects except changing TX head value.
To advance TX Head queue, HW needs to touch memory by DMA. But directly touching VM's memory to advance TX Queue head does not follow vfio migration protocol design, because vIOMMU state is not defined by the protocol. Even this may introduce functional and security issue under hostile guest circumstances.
In order not to touch any VF memory or IO page table, TX Queue head restore is using PF managed memory and PF isolation domain. This will also introduce another dependency that while switching TX Queue between PF space and VF space, TX Queue head value is not changed. HW provides an indirect context access so that head value can be kept while switching context.
In virtual channel model, VF driver only send TX queue ring base and length info to PF, while rest of the TX queue context are managed by PF. TX queue length must be verified by PF during virtual channel message processing. When PF uses dummy descriptors to advance TX head, it will configure the TX ring base as the new address managed by PF itself. As a result, all of the TX queue context is taken control of by PF and this method won't generate any attacking vulnerability
The overall steps for TX head restoring handler are:
1. Backup TX context, switch TX queue context as PF space and PF DMA ring base with interrupt disabled
2. Fill the DMA ring with dummy descriptors and bump doorbell to advance TX head. Once kicking doorbell, HW will issue DMA and send PCI upstream memory transaction tagged by PF BDF. Since ring base is PF's managed DMA buffer, DMA can work successfully and TX Head is advanced as expected.
3. Overwrite TX context by the backup context in step 1. Since TX queue head value is not changed while context switch, TX queue head is successfully restored.
Since everything is happening inside PF context, it is transparent to vfio driver and has no effects outside of PF.
--- .../net/ethernet/intel/ice/ice_migration.c | 277 ++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_virtchnl.c | 17 ++ 2 files changed, 294 insertions(+)
drivers/net/ethernet/intel/ice/ice_migration.c +277 -0
@@ -3,10 +3,14 @@#include "ice.h" #include "ice_base.h" +#include "ice_txrx_lib.h" #define ICE_MIG_DEVSTAT_MAGIC 0xE8000001#define ICE_MIG_DEVSTAT_VERSION 0x1#define ICE_MIG_VF_QRX_TAIL_MAX 256 +#define QTX_HEAD_RESTORE_DELAY_MAX 100 +#define QTX_HEAD_RESTORE_DELAY_SLEEP_US_MIN 10 +#define QTX_HEAD_RESTORE_DELAY_SLEEP_US_MAX 10struct ice_migration_virtchnl_msg_slot {u32 opcode;
@@ -30,6 +34,8 @@ struct ice_migration_dev_state {u16 vsi_id;/* next RX desc index to be processed by the device */ u16 rx_head[ICE_MIG_VF_QRX_TAIL_MAX ]; +/* next TX desc index to be processed by the device */ +u16 tx_head[ICE_MIG_VF_QRX_TAIL_MAX ];u8 virtchnl_msgs[]; }__aligned(8) ;
@@ -317,6 +323,62 @@ ice_migration_save_rx_head(struct ice_vf *vf,return 0 ; } +/** +* ice_migration_save_tx_head - save tx head in migration region +* @vf: pointer to VF structure +* @devstate: pointer to migration device state +* +* Return 0 for success, negative for error +*/ +static int +ice_migration_save_tx_head (struct ice_vf *vf, +struct ice_migration_dev_state *devstate) +{ +struct ice_vsi *vsi =ice_get_vf_vsi (vf); +struct ice_pf *pf = vf->pf; +struct device *dev; +int i =0 ; + + dev =ice_pf_to_dev (pf); + +if (!vsi) { +dev_err (dev,"VF %d VSI is NULL\n" , vf->vf_id); +return -EINVAL ; + } + +ice_for_each_txq (vsi, i) { +u16 tx_head; +u32 reg; + + devstate->tx_head[i] =0 ; +if (!test_bit (i, vf->txq_ena)) +continue ; + + reg =rd32 (&pf->hw,QTX_COMM_HEAD (vsi->txq_map[i])); + tx_head = (reg &QTX_COMM_HEAD_HEAD_M ) + >>QTX_COMM_HEAD_HEAD_S ; + +/* 1. If TX head is QTX_COMM_HEAD_HEAD_M marker, which means +* it is the value written by software and there are no +* descriptors write back happened, then there are no +* packets sent since queue enabled. +* 2. If TX head is ring length minus 1, then it just returns +* to the start of the ring. +*/ +if (tx_head ==QTX_COMM_HEAD_HEAD_M || + tx_head == (vsi->tx_rings[i]->count -1 )) + tx_head =0 ; +else +/* Add compensation since value read from TX Head +* register is always the real TX head minus 1 +*/ + tx_head++; + + devstate->tx_head[i] = tx_head; + } +return 0 ; +} +/** * ice_migration_save_devstate - save device state to migration buffer * @pf: pointer to PF of migration device
@@ -376,6 +438,12 @@ int ice_migration_save_devstate(struct ice_pf *pf, int vf_id, u8 *buf, u64 buf_s goto out_put_vf; } + ret =ice_migration_save_tx_head (vf, devstate); +if (ret) { +dev_err (dev,"VF %d failed to save txq head\n" , vf->vf_id); + goto out_put_vf; + } +list_for_each_entry (msg_listnode, &vf->virtchnl_msg_list, node) {struct ice_migration_virtchnl_msg_slot *msg_slot;u64 slot_size;
@@ -517,6 +585,205 @@ ice_migration_restore_rx_head(struct ice_vf *vf,return 0 ; } +/** +* ice_migration_init_dummy_desc - init dma ring by dummy descriptor +* @ice_tx_desc: tx ring descriptor array +* @len: array length +* @tx_pkt_dma: dummy packet dma address +*/ +static inline void +ice_migration_init_dummy_desc (struct ice_tx_desc *tx_desc, +u16 len, +dma_addr_t tx_pkt_dma) +{ +int i; + +/* Init ring with dummy descriptors */ +for (i =0 ; i < len; i++) { +u32 td_cmd; + + td_cmd =ICE_TXD_LAST_DESC_CMD |ICE_TX_DESC_CMD_DUMMY ; + tx_desc[i].cmd_type_offset_bsz = +ice_build_ctob (td_cmd,0 ,SZ_256 ,0 ); + tx_desc[i].buf_addr =cpu_to_le64 (tx_pkt_dma); + } +} + +/** +* ice_migration_inject_dummy_desc - inject dummy descriptors +* @vf: pointer to VF structure +* @tx_ring: tx ring instance +* @head: tx head to be restored +* @tx_desc_dma:tx descriptor ring base dma address +* +* For each TX queue, restore the TX head by following below steps: +* 1. Backup TX context, switch TX queue context as PF space and PF +* DMA ring base with interrupt disabled +* 2. Fill the DMA ring with dummy descriptors and bump doorbell to +* advance TX head. Once kicking doorbell, HW will issue DMA and +* send PCI upstream memory transaction tagged by PF BDF. Since +* ring base is PF's managed DMA buffer, DMA can work successfully +* and TX Head is advanced as expected. +* 3. Overwrite TX context by the backup context in step 1. Since TX +* queue head value is not changed while context switch, TX queue +* head is successfully restored. +* +* Return 0 for success, negative for error. +*/ +static int +ice_migration_inject_dummy_desc (struct ice_vf *vf,struct ice_tx_ring *tx_ring, +u16 head,dma_addr_t tx_desc_dma) +{ +struct ice_tlan_ctx tlan_ctx, tlan_ctx_orig; +struct device *dev =ice_pf_to_dev (vf->pf); +struct ice_hw *hw = &vf->pf->hw; +u32 reg_dynctl_orig; +u32 reg_tqctl_orig; +u32 tx_head; +int status; +int i; + +/* 1.1 Backup TX Queue context */ + status =ice_read_txq_ctx (hw, &tlan_ctx, tx_ring->reg_idx); +if (status) { +dev_err (dev,"Failed to read TXQ[%d] context, err=%d\n" , + tx_ring->q_index, status); +return -EIO ; + } +memcpy (&tlan_ctx_orig, &tlan_ctx,sizeof (tlan_ctx)); + reg_tqctl_orig =rd32 (hw,QINT_TQCTL (tx_ring->reg_idx)); +if (tx_ring->q_vector) + reg_dynctl_orig =rd32 (hw,GLINT_DYN_CTL (tx_ring->q_vector->reg_idx)); + +/* 1.2 switch TX queue context as PF space and PF DMA ring base */ + tlan_ctx.vmvf_type =ICE_TLAN_CTX_VMVF_TYPE_PF ; + tlan_ctx.vmvf_num =0 ; + tlan_ctx.base = tx_desc_dma >>ICE_TLAN_CTX_BASE_S ; + status =ice_write_txq_ctx (hw, &tlan_ctx, tx_ring->reg_idx); +if (status) { +dev_err (dev,"Failed to write TXQ[%d] context, err=%d\n" , + tx_ring->q_index, status); +return -EIO ; + } + +/* 1.3 Disable TX queue interrupt */ +wr32 (hw,QINT_TQCTL (tx_ring->reg_idx),QINT_TQCTL_ITR_INDX_M ); + +/* To disable tx queue interrupt during run time, software should +* write mmio to trigger a MSIX interrupt. +*/ +if (tx_ring->q_vector) +wr32 (hw,GLINT_DYN_CTL (tx_ring->q_vector->reg_idx), + (ICE_ITR_NONE <<GLINT_DYN_CTL_ITR_INDX_S ) | +GLINT_DYN_CTL_SWINT_TRIG_M | +GLINT_DYN_CTL_INTENA_M ); + +/* Force memory writes to complete before letting h/w know there +* are new descriptors to fetch. +*/ +wmb (); + +/* 2.1 Bump doorbell to advance TX Queue head */ +writel (head, tx_ring->tail); + +/* 2.2 Wait until TX Queue head move to expected place */ + tx_head =rd32 (hw,QTX_COMM_HEAD (tx_ring->reg_idx)); + tx_head = (tx_head &QTX_COMM_HEAD_HEAD_M ) + >>QTX_COMM_HEAD_HEAD_S ; +for (i =0 ; i <QTX_HEAD_RESTORE_DELAY_MAX && tx_head != (head -1 ); i++) { +usleep_range (QTX_HEAD_RESTORE_DELAY_SLEEP_US_MIN , +QTX_HEAD_RESTORE_DELAY_SLEEP_US_MAX ); + tx_head =rd32 (hw,QTX_COMM_HEAD (tx_ring->reg_idx)); + tx_head = (tx_head &QTX_COMM_HEAD_HEAD_M ) + >>QTX_COMM_HEAD_HEAD_S ; + } +if (i ==QTX_HEAD_RESTORE_DELAY_MAX ) { +dev_err (dev,"VF %d txq[%d] head restore timeout\n" , + vf->vf_id, tx_ring->q_index); +return -EIO ; + } + +/* 3. Overwrite TX Queue context with backup context */ + status =ice_write_txq_ctx (hw, &tlan_ctx_orig, tx_ring->reg_idx); +if (status) { +dev_err (dev,"Failed to write TXQ[%d] context, err=%d\n" , + tx_ring->q_index, status); +return -EIO ; + } +wr32 (hw,QINT_TQCTL (tx_ring->reg_idx), reg_tqctl_orig); +if (tx_ring->q_vector) +wr32 (hw,GLINT_DYN_CTL (tx_ring->q_vector->reg_idx), reg_dynctl_orig); + +return 0 ; +} + +/** +* ice_migration_restore_tx_head - restore tx head at dst +* @vf: pointer to VF structure +* @devstate: pointer to migration device state +* +* Return 0 for success, negative for error +*/ +static int +ice_migration_restore_tx_head (struct ice_vf *vf, +struct ice_migration_dev_state *devstate) +{ +struct device *dev =ice_pf_to_dev (vf->pf); +u16 max_ring_len =ICE_MAX_NUM_DESC ; +dma_addr_t tx_desc_dma, tx_pkt_dma; +struct ice_tx_desc *tx_desc; +struct ice_vsi *vsi; +char *tx_pkt; +int ret =0 ; +int i =0 ; + + vsi =ice_get_vf_vsi (vf); +if (!vsi) { +dev_err (dev,"VF %d VSI is NULL\n" , vf->vf_id); +return -EINVAL ; + } + +/* Allocate DMA ring and descriptor by PF */ + tx_desc =dma_alloc_coherent (dev, max_ring_len *sizeof (struct ice_tx_desc ), + &tx_desc_dma,GFP_KERNEL | __GFP_ZERO); + tx_pkt =dma_alloc_coherent (dev,SZ_4K , &tx_pkt_dma,GFP_KERNEL | __GFP_ZERO); +if (!tx_desc || !tx_pkt) { +dev_err (dev,"PF failed to allocate memory for VF %d\n" , vf->vf_id); + ret = -ENOMEM ; + goto err; + } + +ice_for_each_txq (vsi, i) { +struct ice_tx_ring *tx_ring = vsi->tx_rings[i]; +u16 *tx_heads = devstate->tx_head; + +/* 1. Skip if TX Queue is not enabled */ +if (!test_bit (i, vf->txq_ena) || tx_heads[i] ==0 ) +continue ; + +if (tx_heads[i] >= tx_ring->count) { +dev_err (dev,"VF %d: invalid tx ring length to restore\n" , + vf->vf_id); + ret = -EINVAL ; + goto err; + } + +/* Dummy descriptors must be re-initialized after use, since +* it may be written back by HW +*/ +ice_migration_init_dummy_desc (tx_desc, max_ring_len, tx_pkt_dma); + ret =ice_migration_inject_dummy_desc (vf, tx_ring, tx_heads[i], tx_desc_dma); +if (ret) + goto err; + } + +err: +dma_free_coherent (dev, max_ring_len *sizeof (struct ice_tx_desc ), tx_desc, tx_desc_dma); +dma_free_coherent (dev,SZ_4K , tx_pkt, tx_pkt_dma); + +return ret; +} +/** * ice_migration_restore_devstate - restore device state at dst * @pf: pointer to PF of migration device
@@ -593,6 +860,16 @@ int ice_migration_restore_devstate(struct ice_pf *pf, int vf_id, const u8 *buf, msg_slot = (struct ice_migration_virtchnl_msg_slot *) ((char *)msg_slot + slot_sz); } + +/* Only do the TX Queue head restore after rest of device state is +* loaded successfully. +*/ + ret =ice_migration_restore_tx_head (vf, devstate); +if (ret) { +dev_err (dev,"VF %d failed to restore rx head\n" , vf->vf_id); + goto out_clear_replay; + } + out_clear_replay:clear_bit (ICE_VF_STATE_REPLAYING_VC , vf->vf_states); out_put_vf:
drivers/net/ethernet/intel/ice/ice_virtchnl.c +17 -0
@@ -1341,6 +1341,23 @@ static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)continue ;ice_vf_ena_txq_interrupt (vsi, vf_q_id); + +/* TX head register is a shadow copy of on-die TX head which +* maintains the accurate location. And TX head register is +* updated only after a packet is sent. If nothing is sent +* after the queue is enabled, then the value is the one +* updated last time and out-of-date. +* +* QTX_COMM_HEAD.HEAD rang value from 0x1fe0 to 0x1fff is +* reserved and will never be used by HW. Manually write a +* reserved value into TX head and use this as a marker for +* the case that there's no packets sent. +* +* This marker is only used in live migration use case. +*/ +if (vf->migration_enabled) +wr32 (&vsi->back->hw,QTX_COMM_HEAD (vsi->txq_map[vf_q_id]), +QTX_COMM_HEAD_HEAD_M );set_bit (vf_q_id, vf->txq_ena); }
Signature · 1 line
2.34.1
PATCH v3 11/13 ice: Add device suspend function for migration
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
Device suspend handler is called by vfio driver before saving device state. Typical operation includes stopping TX/RX queue.
--- .../net/ethernet/intel/ice/ice_migration.c | 70 +++++++++++++++++++ include/linux/net/intel/ice_migration.h | 5 ++ 2 files changed, 75 insertions(+)
drivers/net/ethernet/intel/ice/ice_migration.c +70 -0
@@ -2,6 +2,8 @@/* Copyright (C) 2018-2023 Intel Corporation */ #include "ice.h" +#include "ice_lib.h" +#include "ice_fltr.h" #include "ice_base.h" #include "ice_txrx_lib.h"
@@ -275,6 +277,74 @@ u32 ice_migration_supported_caps(void)return VIRTCHNL_VF_MIGRATION_SUPPORT_FEATURE ; } +/** +* ice_migration_suspend_dev - suspend device on src +* @pf: pointer to PF of migration device +* @vf_id: VF index of migration device +* +* Return 0 for success, negative for error +*/ +int ice_migration_suspend_dev (struct ice_pf *pf,int vf_id) +{ +struct device *dev =ice_pf_to_dev (pf); +struct ice_vsi *vsi; +struct ice_vf *vf; +int ret; + + vf =ice_get_vf_by_id (pf, vf_id); +if (!vf) { +dev_err (dev,"Unable to locate VF from VF ID%d\n" , vf_id); +return -EINVAL ; + } + +if (!test_bit (ICE_VF_STATE_QS_ENA , vf->vf_states)) { +ice_put_vf (vf); +return 0 ; + } + + dev =ice_pf_to_dev (pf); +if (vf->virtchnl_msg_num >VIRTCHNL_MSG_MAX ) { +dev_err (dev,"SR-IOV live migration disabled on VF %d. Migration buffer exceeded\n" , + vf->vf_id); + ret = -EIO ; + goto out_put_vf; + } + + vsi =ice_get_vf_vsi (vf); +if (!vsi) { +dev_err (dev,"VF %d VSI is NULL\n" , vf->vf_id); + ret = -EINVAL ; + goto out_put_vf; + } + +/* Prevent VSI from queuing incoming packets by removing all filters */ +ice_fltr_remove_all (vsi); + +/* MAC based filter rule is disabled at this point. Set MAC to zero +* to keep consistency with VF mac address info shown by ip link +*/ +eth_zero_addr (vf->hw_lan_addr); +eth_zero_addr (vf->dev_lan_addr); + + ret =ice_vsi_stop_lan_tx_rings (vsi,ICE_NO_RESET , vf->vf_id); +if (ret) { +dev_err (dev,"VF %d failed to stop tx rings\n" , vf->vf_id); + ret = -EIO ; + goto out_put_vf; + } + ret =ice_vsi_stop_all_rx_rings (vsi); +if (ret) { +dev_err (dev,"VF %d failed to stop rx rings\n" , vf->vf_id); + ret = -EIO ; + goto out_put_vf; + } + +out_put_vf: +ice_put_vf (vf); +return ret; +} +EXPORT_SYMBOL (ice_migration_suspend_dev); +/** * ice_migration_save_rx_head - save rx head into device state buffer * @vf: pointer to VF structure
include/linux/net/intel/ice_migration.h +5 -0
@@ -11,6 +11,7 @@ struct ice_pf;struct ice_pf *ice_migration_get_pf (struct pci_dev *pdev);int ice_migration_init_dev (struct ice_pf *pf,int vf_id);void ice_migration_uninit_dev (struct ice_pf *pf,int vf_id); +int ice_migration_suspend_dev (struct ice_pf *pf,int vf_id);int ice_migration_save_devstate (struct ice_pf *pf,int vf_id,u8 *buf,u64 buf_sz);int ice_migration_restore_devstate (struct ice_pf *pf,int vf_id,const u8 *buf,u64 buf_sz);
@@ -22,6 +23,10 @@ static inline struct ice_pf *ice_migration_get_pf(struct pci_dev *pdev)static inline int ice_migration_init_dev (struct ice_pf *pf,int vf_id) { }static inline void ice_migration_uninit_dev (struct ice_pf *pf,int vf_id) { } +static inline int ice_migration_suspend_dev (struct ice_pf *pf,int vf_id) +{ +return 0 ; +}static inline int ice_migration_save_devstate (struct ice_pf *pf,int vf_id,u8 *buf,u64 buf_sz) {return 0 ;
Signature · 1 line
2.34.1
PATCH v3 12/13 ice: Save and restore mmio registers
In reply to Yahui CaoIn E800 device model, VF takes direct control over the context of AdminQ, irq ctrl, TX tail and RX tail by accessing VF pci mmio. Rest of all the state can only be setup by PF and the procedure is that VF sends all these configuration to PF through virtual channel messages to setup the rest of the state.
To migrate AdminQ/irq context successfully, only AdminQ/irq register needs to be restored, rest of the part like generic msix is handled by migration stack.
To migrate RX dma ring successfully, RX ring base, length(setup via virtual channel messages) and tail register (setup via VF pci mmio) must be restored before RX queue is enabled.
To migrate TX dma ring successfully, TX ring base and length(setup via virtual channel messages) must be restored before TX queue is enabled, and TX tail(setup via VF pci mmio) doesn't need to be restored since TX queue is drained before migration and TX tail is stateless.
For simplicity, just restore all the VF pci mmio before virtual channel messages are replayed so that all the TX/RX ring context are restored before queue is enabled.
However, there are 2 corner cases which need to be taken care of:
- During device suspenion, irq register may be dirtied when stopping queue. So save irq register into internal pre-saved area before queue is stopped and fetch the pre-saved irq register value at device saving stage.
- When PF processes virtual channel VIRTCHNL_OP_CONFIG_VSI_QUEUES, irq register may be dirtied. So restore the affacted irq register after virtual channel messages are replayed.
--- .../net/ethernet/intel/ice/ice_hw_autogen.h | 8 + .../net/ethernet/intel/ice/ice_migration.c | 304 ++++++++++++++++++ .../intel/ice/ice_migration_private.h | 7 + drivers/net/ethernet/intel/ice/ice_vf_lib.h | 2 + 4 files changed, 321 insertions(+)
drivers/net/ethernet/intel/ice/ice_hw_autogen.h +8 -0
@@ -31,8 +31,16 @@#define PF_FW_ATQLEN_ATQVFE_M BIT(28)#define PF_FW_ATQLEN_ATQOVFL_M BIT(29)#define PF_FW_ATQLEN_ATQCRIT_M BIT(30) +#define VF_MBX_ARQBAH (_VF) (0x0022B800 + ((_VF) * 4)) +#define VF_MBX_ARQBAL (_VF) (0x0022B400 + ((_VF) * 4)) +#define VF_MBX_ARQH (_VF) (0x0022C000 + ((_VF) * 4))#define VF_MBX_ARQLEN (_VF) (0x0022BC00 + ((_VF) * 4)) +#define VF_MBX_ARQT (_VF) (0x0022C400 + ((_VF) * 4)) +#define VF_MBX_ATQBAH (_VF) (0x0022A400 + ((_VF) * 4)) +#define VF_MBX_ATQBAL (_VF) (0x0022A000 + ((_VF) * 4)) +#define VF_MBX_ATQH (_VF) (0x0022AC00 + ((_VF) * 4))#define VF_MBX_ATQLEN (_VF) (0x0022A800 + ((_VF) * 4)) +#define VF_MBX_ATQT (_VF) (0x0022B000 + ((_VF) * 4))#define PF_FW_ATQLEN_ATQENABLE_M BIT(31)#define PF_FW_ATQT 0x00080400#define PF_MBX_ARQBAH 0x0022E400
drivers/net/ethernet/intel/ice/ice_migration.c +304 -0
358 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_migration_private.h +7 -0
@@ -10,6 +10,13 @@* in ice-vfio-pic.ko should be exposed as part of ice_migration.h. */ +#define ICE_MIG_VF_MSIX_MAX 65 +#define ICE_MIG_VF_ITR_NUM 4 +struct ice_migration_dirtied_regs { +u32 int_dyn_ctl[ICE_MIG_VF_MSIX_MAX ]; +u32 int_intr[ICE_MIG_VF_ITR_NUM ][ICE_MIG_VF_MSIX_MAX ]; +}; +#if IS_ENABLED (CONFIG_ICE_VFIO_PCI )void ice_migration_init_vf (struct ice_vf *vf);void ice_migration_uninit_vf (struct ice_vf *vf);
drivers/net/ethernet/intel/ice/ice_vf_lib.h +2 -0
@@ -14,6 +14,7 @@#include "ice_type.h" #include "ice_virtchnl_fdir.h" #include "ice_vsi_vlan_ops.h" +#include "ice_migration_private.h" #define ICE_MAX_SRIOV_VFS 256
@@ -144,6 +145,7 @@ struct ice_vf {u64 virtchnl_msg_size;u32 virtchnl_retval;u16 vm_vsi_num; +struct ice_migration_dirtied_regs dirtied_regs; };/* Flags for controlling behavior of ice_reset_vf */
Signature · 1 line
2.34.1
PATCH v3 13/13 vfio/ice: Implement vfio_pci driver for E800 devices
In reply to Yahui CaoFrom: Lingyu Liu <[email protected]>
Add a vendor-specific vfio_pci driver for E800 devices.
It uses vfio_pci_core to register to the VFIO subsystem and then implements the E800 specific logic to support VF live migration.
It implements the device state transition flow for live migration.
--- MAINTAINERS | 7 + drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/ice/Kconfig | 10 + drivers/vfio/pci/ice/Makefile | 4 + drivers/vfio/pci/ice/ice_vfio_pci.c | 707 ++++++++++++++++++++++++++++ 6 files changed, 732 insertions(+) create mode 100644 drivers/vfio/pci/ice/Kconfig create mode 100644 drivers/vfio/pci/ice/Makefile create mode 100644 drivers/vfio/pci/ice/ice_vfio_pci.c
MAINTAINERS +7 -0
@@ -22608,6 +22608,13 @@ L: [email protected] S: Maintained F: drivers/vfio/pci/mlx5/ +VFIO ICE PCI DRIVER +M: Yahui Cao <[email protected]> +M: Lingyu Liu <[email protected]> +L: [email protected] +S: Maintained +F: drivers/vfio/pci/ice/ + VFIO PCI DEVICE SPECIFIC DRIVERS R: Jason Gunthorpe <[email protected]> R: Yishai Hadas <[email protected]>
drivers/vfio/pci/Kconfig +2 -0
@@ -65,4 +65,6 @@ source "drivers/vfio/pci/hisilicon/Kconfig" source "drivers/vfio/pci/pds/Kconfig" +source "drivers/vfio/pci/ice/Kconfig" + endmenu
drivers/vfio/pci/Makefile +2 -0
@@ -13,3 +13,5 @@ obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/ obj-$(CONFIG_HISI_ACC_VFIO_PCI) += hisilicon/ obj-$(CONFIG_PDS_VFIO_PCI) += pds/ + +obj-$(CONFIG_ICE_VFIO_PCI) += ice/
drivers/vfio/pci/ice/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +config ICE_VFIO_PCI + tristate "VFIO support for Intel(R) Ethernet Connection E800 Series" + depends on ICE + depends on VFIO_PCI_CORE + help + This provides migration support for Intel(R) Ethernet connection E800 + series devices using the VFIO framework. + + If you don't know what to do here, say N.
drivers/vfio/pci/ice/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_ICE_VFIO_PCI) += ice-vfio-pci.o +ice-vfio-pci-y := ice_vfio_pci.o +
drivers/vfio/pci/ice/ice_vfio_pci.c new file +707 -0
707 lines not on this page · raw message
Signature · 6 lines
2.34.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Re: [PATCH iwl-next v3 13/13] vfio/ice: Implement vfio_pci driver for E800 devices
Quoted 12 lines · On Mon, 18 Sep 2023 06:25:46 +0000 Yahui Cao <[email protected]> wrote:
From: Lingyu Liu <[email protected]>
Add a vendor-specific
vfio_pcidriver for E800 devices.It uses
vfio_pci_coreto register to the VFIO subsystem and then implements the E800 specific logic to support VF live migration.It implements the device state transition flow for live migration.
Signed-off-by Lingyu Liu <[email protected]>Signed-off-by Yahui Cao <[email protected]>
Quoted 11 lines
--- MAINTAINERS | 7 + drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/ice/Kconfig | 10 + drivers/vfio/pci/ice/Makefile | 4 + drivers/vfio/pci/ice/ice_vfio_pci.c | 707 ++++++++++++++++++++++++++++ 6 files changed, 732 insertions(+) create mode 100644 drivers/vfio/pci/ice/Kconfig create mode 100644 drivers/vfio/pci/ice/Makefile create mode 100644 drivers/vfio/pci/ice/ice_vfio_pci.c
The prerequisite ice core driver support (ie. patches 1-12) should be supplied as a branch to allow this variant driver to be merged through the vfio tree.
Quoted 45 lines
MAINTAINERS +7
-0@@ -22608,6 +22608,13 @@ L: [email protected] S: Maintained F: drivers/vfio/pci/mlx5/ +VFIO ICE PCI DRIVER +M: Yahui Cao <[email protected]> +M: Lingyu Liu <[email protected]> +L: [email protected] +S: Maintained +F: drivers/vfio/pci/ice/ + VFIO PCI DEVICE SPECIFIC DRIVERS R: Jason Gunthorpe <[email protected]> R: Yishai Hadas <[email protected]>drivers/vfio/pci/Kconfig +2
-0@@ -65,4 +65,6 @@ source "drivers/vfio/pci/hisilicon/Kconfig" source "drivers/vfio/pci/pds/Kconfig" +source "drivers/vfio/pci/ice/Kconfig" + endmenudrivers/vfio/pci/Makefile +2
-0@@ -13,3 +13,5 @@ obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/ obj-$(CONFIG_HISI_ACC_VFIO_PCI) += hisilicon/ obj-$(CONFIG_PDS_VFIO_PCI) += pds/ + +obj-$(CONFIG_ICE_VFIO_PCI) += ice/drivers/vfio/pci/ice/Kconfig new file +0
-0
drivers/vfio/pci/ice/Kconfig line 5
Quoted 5 lines
drivers/vfio/pci/ice/Kconfig new file +5
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +config ICE_VFIO_PCI + tristate "VFIO support for Intel(R) Ethernet Connection E800 Series" + depends on ICE + depends on VFIO_PCI_CORE
s/depends on/select/
drivers/vfio/pci/ice/ice_vfio_pci.c
Quoted 20 lines
drivers/vfio/pci/ice/Kconfig new file +5
-0+ help + This provides migration support for Intel(R) Ethernet connection E800 + series devices using the VFIO framework. + + If you don't know what to do here, say N.drivers/vfio/pci/ice/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_ICE_VFIO_PCI) += ice-vfio-pci.o +ice-vfio-pci-y := ice_vfio_pci.o +drivers/vfio/pci/ice/ice_vfio_pci.c new file +0
-0
Suggest renaming this to main.c
Quoted 42 lines
drivers/vfio/pci/ice/ice_vfio_pci.c new file +41
-0@@ -0,0 +1,707 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2018-2023 Intel Corporation */ + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/types.h> +#include <linux/file.h> +#include <linux/pci.h> +#include <linux/vfio_pci_core.h> +#include <linux/net/intel/ice_migration.h> +#include <linux/anon_inodes.h> + +#define DRIVER_DESC "ICE VFIO PCI - User Level meta-driver for Intel E800 device family" + +struct ice_vfio_pci_migration_file { +struct file *filp; +struct mutex lock;/* protect migration file access */ +bool disabled; + +u8 mig_data[SZ_128K ]; +size_t total_length; +}; + +struct ice_vfio_pci_core_device { +struct vfio_pci_core_device core_device; +u8 deferred_reset:1 ; +struct mutex state_mutex;/* protect migration state */ +enum vfio_device_mig_state mig_state; +/* protect the reset_done flow */ +spinlock_t reset_lock; +struct ice_vfio_pci_migration_file *resuming_migf; +struct ice_vfio_pci_migration_file *saving_migf; +struct vfio_device_migration_info mig_info; +u8 *mig_data; +u8 __iomem *io_base; +struct ice_pf *pf; +int vf_id; +}; + +/** +* ice_vfio_pci_load_state - VFIO device state reloading
drivers/vfio/pci/ice/ice_vfio_pci.c line 51
Quoted 10 lines
drivers/vfio/pci/ice/ice_vfio_pci.c new file +10
-0+* @ice_vdev: pointer to ice vfio pci core device structure +* +* Load device state and restore it. This function is called when the VFIO uAPI +* consumer wants to load the device state info from VFIO migration region and +* restore them into the device. This function should make sure all the device +* state info is loaded and restored successfully. As a result, return value is +* mandatory to be checked. +* +* Return 0 for success, negative value for failure. +*/
Kudos on the kernel-doc comments throughout, nice!
This appears to be a substantial improvement from the comments I see on v2, I'm curious where Kevin and Jason stand on this now. Thanks,
Alex
Quoted 656 lines
drivers/vfio/pci/ice/ice_vfio_pci.c new file +656
-0+static int __must_check +ice_vfio_pci_load_state (struct ice_vfio_pci_core_device *ice_vdev) +{ +struct ice_vfio_pci_migration_file *migf = ice_vdev->resuming_migf; + +return ice_migration_restore_devstate (ice_vdev->pf, + ice_vdev->vf_id, + migf->mig_data, +SZ_128K ); +} + +/** +* ice_vfio_pci_save_state - VFIO device state saving +* @ice_vdev: pointer to ice vfio pci core device structure +* @migf: pointer to migration file +* +* Snapshot the device state and save it. This function is called when the +* VFIO uAPI consumer wants to snapshot the current device state and saves +* it into the VFIO migration region. This function should make sure all +* of the device state info is collectted and saved successfully. As a +* result, return value is mandatory to be checked. +* +* Return 0 for success, negative value for failure. +*/ +static int __must_check +ice_vfio_pci_save_state (struct ice_vfio_pci_core_device *ice_vdev, +struct ice_vfio_pci_migration_file *migf) +{ + migf->total_length =SZ_128K ; + +return ice_migration_save_devstate (ice_vdev->pf, + ice_vdev->vf_id, + migf->mig_data, +SZ_128K ); +} + +/** +* ice_vfio_migration_init - Initialization for live migration function +* @ice_vdev: pointer to ice vfio pci core device structure +* +* Returns 0 on success, negative value on error +*/ +static int ice_vfio_migration_init (struct ice_vfio_pci_core_device *ice_vdev) +{ +struct pci_dev *pdev = ice_vdev->core_device.pdev; +int ret =0 ; + + ice_vdev->pf =ice_migration_get_pf (pdev); +if (!ice_vdev->pf) +return -EFAULT ; + + ice_vdev->vf_id =pci_iov_vf_id (pdev); +if (ice_vdev->vf_id <0 ) +return -EINVAL ; + + ret =ice_migration_init_dev (ice_vdev->pf, ice_vdev->vf_id); +if (ret) +return ret; + + ice_vdev->io_base = (u8 __iomem *)pci_iomap (pdev,0 ,0 ); +if (!ice_vdev->io_base) +return -EFAULT ; + +return 0 ; +} + +/** +* ice_vfio_migration_uninit - Cleanup for live migration function +* @ice_vdev: pointer to ice vfio pci core device structure +*/ +static void ice_vfio_migration_uninit (struct ice_vfio_pci_core_device *ice_vdev) +{ +pci_iounmap (ice_vdev->core_device.pdev, ice_vdev->io_base); +ice_migration_uninit_dev (ice_vdev->pf, ice_vdev->vf_id); +} + +/** +* ice_vfio_pci_disable_fd - Close migration file +* @migf: pointer to ice vfio pci migration file +*/ +static void ice_vfio_pci_disable_fd (struct ice_vfio_pci_migration_file *migf) +{ +mutex_lock (&migf->lock); + migf->disabled = true; + migf->total_length =0 ; + migf->filp->f_pos =0 ; +mutex_unlock (&migf->lock); +} + +/** +* ice_vfio_pci_disable_fds - Close migration files of ice vfio pci device +* @ice_vdev: pointer to ice vfio pci core device structure +*/ +static void ice_vfio_pci_disable_fds (struct ice_vfio_pci_core_device *ice_vdev) +{ +if (ice_vdev->resuming_migf) { +ice_vfio_pci_disable_fd (ice_vdev->resuming_migf); +fput (ice_vdev->resuming_migf->filp); + ice_vdev->resuming_migf =NULL ; + } +if (ice_vdev->saving_migf) { +ice_vfio_pci_disable_fd (ice_vdev->saving_migf); +fput (ice_vdev->saving_migf->filp); + ice_vdev->saving_migf =NULL ; + } +} + +/* +* This function is called in all state_mutex unlock cases to +* handle a 'deferred_reset' if exists. +* @ice_vdev: pointer to ice vfio pci core device structure +*/ +static void +ice_vfio_pci_state_mutex_unlock (struct ice_vfio_pci_core_device *ice_vdev) +{ +again: +spin_lock (&ice_vdev->reset_lock); +if (ice_vdev->deferred_reset) { + ice_vdev->deferred_reset = false; +spin_unlock (&ice_vdev->reset_lock); + ice_vdev->mig_state =VFIO_DEVICE_STATE_RUNNING ; +ice_vfio_pci_disable_fds (ice_vdev); + goto again; + } +mutex_unlock (&ice_vdev->state_mutex); +spin_unlock (&ice_vdev->reset_lock); +} + +static void ice_vfio_pci_reset_done (struct pci_dev *pdev) +{ +struct ice_vfio_pci_core_device *ice_vdev = + (struct ice_vfio_pci_core_device *)dev_get_drvdata (&pdev->dev); + +/* +* As the higher VFIO layers are holding locks across reset and using +* those same locks with the mm_lock we need to prevent ABBA deadlock +* with the state_mutex and mm_lock. +* In case the state_mutex was taken already we defer the cleanup work +* to the unlock flow of the other running context. +*/ +spin_lock (&ice_vdev->reset_lock); + ice_vdev->deferred_reset = true; +if (!mutex_trylock (&ice_vdev->state_mutex)) { +spin_unlock (&ice_vdev->reset_lock); +return ; + } +spin_unlock (&ice_vdev->reset_lock); +ice_vfio_pci_state_mutex_unlock (ice_vdev); +} + +/** +* ice_vfio_pci_open_device - Called when a vfio device is probed by VFIO UAPI +* @core_vdev: the vfio device to open +* +* Initialization of the vfio device +* +* Returns 0 on success, negative value on error +*/ +static int ice_vfio_pci_open_device (struct vfio_device *core_vdev) +{ +struct ice_vfio_pci_core_device *ice_vdev =container_of (core_vdev, + struct ice_vfio_pci_core_device, core_device.vdev); +struct vfio_pci_core_device *vdev = &ice_vdev->core_device; +int ret; + + ret =vfio_pci_core_enable (vdev); +if (ret) +return ret; + + ret =ice_vfio_migration_init (ice_vdev); +if (ret) { +vfio_pci_core_disable (vdev); +return ret; + } + ice_vdev->mig_state =VFIO_DEVICE_STATE_RUNNING ; +vfio_pci_core_finish_enable (vdev); + +return 0 ; +} + +/** +* ice_vfio_pci_close_device - Called when a vfio device fd is closed +* @core_vdev: the vfio device to close +*/ +static void ice_vfio_pci_close_device (struct vfio_device *core_vdev) +{ +struct ice_vfio_pci_core_device *ice_vdev =container_of (core_vdev, + struct ice_vfio_pci_core_device, core_device.vdev); + +ice_vfio_pci_disable_fds (ice_vdev); +vfio_pci_core_close_device (core_vdev); +ice_vfio_migration_uninit (ice_vdev); +} + +/** +* ice_vfio_pci_release_file - release ice vfio pci migration file +* @inode: pointer to inode +* @filp: pointer to the file to release +* +* Return 0 for success, negative for error +*/ +static int ice_vfio_pci_release_file (struct inode *inode,struct file *filp) +{ +struct ice_vfio_pci_migration_file *migf = filp->private_data; + +ice_vfio_pci_disable_fd (migf); +mutex_destroy (&migf->lock); +kfree (migf); +return 0 ; +} + +/** +* ice_vfio_pci_save_read - save migration file data to user space +* @filp: pointer to migration file +* @buf: pointer to user space buffer +* @len: data length to be saved +* @pos: should be 0 +* +* Return len of saved data, negative for error +*/ +static ssize_t ice_vfio_pci_save_read (struct file *filp,char __user *buf, +size_t len,loff_t *pos) +{ +struct ice_vfio_pci_migration_file *migf = filp->private_data; +loff_t *off = &filp->f_pos; +ssize_t done =0 ; +int ret; + +if (pos) +return -ESPIPE ; + +mutex_lock (&migf->lock); +if (*off > migf->total_length) { + done = -EINVAL ; + goto out_unlock; + } + +if (migf->disabled) { + done = -ENODEV ; + goto out_unlock; + } + + len =min_t (size_t, migf->total_length - *off, len); +if (len) { + ret =copy_to_user (buf, migf->mig_data + *off, len); +if (ret) { + done = -EFAULT ; + goto out_unlock; + } + *off += len; + done = len; + } +out_unlock: +mutex_unlock (&migf->lock); +return done; +} + +static const struct file_operations ice_vfio_pci_save_fops = { + .owner =THIS_MODULE , + .read = ice_vfio_pci_save_read, + .release = ice_vfio_pci_release_file, + .llseek = no_llseek, +}; + +/** +* ice_vfio_pci_stop_copy - create migration file and save migration state to it +* @ice_vdev: pointer to ice vfio pci core device structure +* +* Return migration file handler +*/ +static struct ice_vfio_pci_migration_file * +ice_vfio_pci_stop_copy (struct ice_vfio_pci_core_device *ice_vdev) +{ +struct ice_vfio_pci_migration_file *migf; +int ret; + + migf =kzalloc (sizeof (*migf),GFP_KERNEL ); +if (!migf) +return ERR_PTR (-ENOMEM ); + + migf->filp =anon_inode_getfile ("ice_vfio_pci_mig" , + &ice_vfio_pci_save_fops, migf, +O_RDONLY ); +if (IS_ERR (migf->filp)) { +int err =PTR_ERR (migf->filp); + +kfree (migf); +return ERR_PTR (err); + } + +stream_open (migf->filp->f_inode, migf->filp); +mutex_init (&migf->lock); + + ret =ice_vfio_pci_save_state (ice_vdev, migf); +if (ret) { +fput (migf->filp); +kfree (migf); +return ERR_PTR (ret); + } + +return migf; +} + +/** +* ice_vfio_pci_resume_write- copy migration file data from user space +* @filp: pointer to migration file +* @buf: pointer to user space buffer +* @len: data length to be copied +* @pos: should be 0 +* +* Return len of saved data, negative for error +*/ +static ssize_t +ice_vfio_pci_resume_write (struct file *filp,const char __user *buf, +size_t len,loff_t *pos) +{ +struct ice_vfio_pci_migration_file *migf = filp->private_data; +loff_t *off = &filp->f_pos; +loff_t requested_length; +ssize_t done =0 ; +int ret; + +if (pos) +return -ESPIPE ; + +if (*off <0 || +check_add_overflow ((loff_t )len, *off, &requested_length)) +return -EINVAL ; + +if (requested_length >sizeof (migf->mig_data)) +return -ENOMEM ; + +mutex_lock (&migf->lock); +if (migf->disabled) { + done = -ENODEV ; + goto out_unlock; + } + + ret =copy_from_user (migf->mig_data + *off, buf, len); +if (ret) { + done = -EFAULT ; + goto out_unlock; + } + *off += len; + done = len; + migf->total_length += len; +out_unlock: +mutex_unlock (&migf->lock); +return done; +} + +static const struct file_operations ice_vfio_pci_resume_fops = { + .owner =THIS_MODULE , + .write = ice_vfio_pci_resume_write, + .release = ice_vfio_pci_release_file, + .llseek = no_llseek, +}; + +/** +* ice_vfio_pci_resume - create resuming migration file +* @ice_vdev: pointer to ice vfio pci core device structure +* +* Return migration file handler, negative value for failure +*/ +static struct ice_vfio_pci_migration_file * +ice_vfio_pci_resume (struct ice_vfio_pci_core_device *ice_vdev) +{ +struct ice_vfio_pci_migration_file *migf; + + migf =kzalloc (sizeof (*migf),GFP_KERNEL ); +if (!migf) +return ERR_PTR (-ENOMEM ); + + migf->filp =anon_inode_getfile ("ice_vfio_pci_mig" , + &ice_vfio_pci_resume_fops, migf, +O_WRONLY ); +if (IS_ERR (migf->filp)) { +int err =PTR_ERR (migf->filp); + +kfree (migf); +return ERR_PTR (err); + } + +stream_open (migf->filp->f_inode, migf->filp); +mutex_init (&migf->lock); +return migf; +} + +/** +* ice_vfio_pci_step_device_state_locked - process device state change +* @ice_vdev: pointer to ice vfio pci core device structure +* @new: new device state +* @final: final device state +* +* Return migration file handler or NULL for success, negative value for failure +*/ +static struct file * +ice_vfio_pci_step_device_state_locked (struct ice_vfio_pci_core_device *ice_vdev, +u32 new,u32 final) +{ +u32 cur = ice_vdev->mig_state; +int ret; + +if (cur ==VFIO_DEVICE_STATE_RUNNING && new ==VFIO_DEVICE_STATE_RUNNING_P2P ) { +ice_migration_suspend_dev (ice_vdev->pf, ice_vdev->vf_id); +return NULL ; + } + +if (cur ==VFIO_DEVICE_STATE_RUNNING_P2P && new ==VFIO_DEVICE_STATE_STOP ) +return NULL ; + +if (cur ==VFIO_DEVICE_STATE_STOP && new ==VFIO_DEVICE_STATE_STOP_COPY ) { +struct ice_vfio_pci_migration_file *migf; + + migf =ice_vfio_pci_stop_copy (ice_vdev); +if (IS_ERR (migf)) +return ERR_CAST (migf); +get_file (migf->filp); + ice_vdev->saving_migf = migf; +return migf->filp; + } + +if (cur ==VFIO_DEVICE_STATE_STOP_COPY && new ==VFIO_DEVICE_STATE_STOP ) { +ice_vfio_pci_disable_fds (ice_vdev); +return NULL ; + } + +if (cur ==VFIO_DEVICE_STATE_STOP && new ==VFIO_DEVICE_STATE_RESUMING ) { +struct ice_vfio_pci_migration_file *migf; + + migf =ice_vfio_pci_resume (ice_vdev); +if (IS_ERR (migf)) +return ERR_CAST (migf); +get_file (migf->filp); + ice_vdev->resuming_migf = migf; +return migf->filp; + } + +if (cur ==VFIO_DEVICE_STATE_RESUMING && new ==VFIO_DEVICE_STATE_STOP ) +return NULL ; + +if (cur ==VFIO_DEVICE_STATE_STOP && new ==VFIO_DEVICE_STATE_RUNNING_P2P ) { + ret =ice_vfio_pci_load_state (ice_vdev); +if (ret) +return ERR_PTR (ret); +ice_vfio_pci_disable_fds (ice_vdev); +return NULL ; + } + +if (cur ==VFIO_DEVICE_STATE_RUNNING_P2P && new ==VFIO_DEVICE_STATE_RUNNING ) +return NULL ; + +/* +* vfio_mig_get_next_state() does not use arcs other than the above +*/ +WARN_ON (true); +return ERR_PTR (-EINVAL ); +} + +/** +* ice_vfio_pci_set_device_state - Config device state +* @vdev: pointer to vfio pci device +* @new_state: device state +* +* Return 0 for success, negative value for failure. +*/ +static struct file * +ice_vfio_pci_set_device_state (struct vfio_device *vdev, +enum vfio_device_mig_state new_state) +{ +struct ice_vfio_pci_core_device *ice_vdev =container_of (vdev, + struct ice_vfio_pci_core_device, + core_device.vdev); +enum vfio_device_mig_state next_state; +struct file *res =NULL ; +int ret; + +mutex_lock (&ice_vdev->state_mutex); +while (new_state != ice_vdev->mig_state) { + ret =vfio_mig_get_next_state (vdev, ice_vdev->mig_state, + new_state, &next_state); +if (ret) { + res =ERR_PTR (ret); +break ; + } + res =ice_vfio_pci_step_device_state_locked (ice_vdev, next_state, + new_state); +if (IS_ERR (res)) +break ; + ice_vdev->mig_state = next_state; +if (WARN_ON (res && new_state != ice_vdev->mig_state)) { +fput (res); + res =ERR_PTR (-EINVAL ); +break ; + } + } +ice_vfio_pci_state_mutex_unlock (ice_vdev); +return res; +} + +/** +* ice_vfio_pci_get_device_state - get device state +* @vdev: pointer to vfio pci device +* @curr_state: device state +* +* Return 0 for success +*/ +static int ice_vfio_pci_get_device_state (struct vfio_device *vdev, +enum vfio_device_mig_state *curr_state) +{ +struct ice_vfio_pci_core_device *ice_vdev = + container_of(vdev, struct ice_vfio_pci_core_device, core_device.vdev); + +mutex_lock (&ice_vdev->state_mutex); + *curr_state = ice_vdev->mig_state; +ice_vfio_pci_state_mutex_unlock (ice_vdev); +return 0 ; +} + +/** +* ice_vfio_pci_get_data_size - get migration data size +* @vdev: pointer to vfio pci device +* @stop_copy_length: migration data size +* +* Return 0 for success +*/ +static int +ice_vfio_pci_get_data_size (struct vfio_device *vdev, +unsigned long *stop_copy_length) +{ + *stop_copy_length =SZ_128K ; +return 0 ; +} + +static const struct vfio_migration_ops ice_vfio_pci_migrn_state_ops = { + .migration_set_state = ice_vfio_pci_set_device_state, + .migration_get_state = ice_vfio_pci_get_device_state, + .migration_get_data_size = ice_vfio_pci_get_data_size, +}; + +/** +* ice_vfio_pci_core_init_dev - initialize vfio device +* @core_vdev: pointer to vfio device +* +* Return 0 for success +*/ +static int ice_vfio_pci_core_init_dev (struct vfio_device *core_vdev) +{ +struct ice_vfio_pci_core_device *ice_vdev =container_of (core_vdev, + struct ice_vfio_pci_core_device, core_device.vdev); + +mutex_init (&ice_vdev->state_mutex); +spin_lock_init (&ice_vdev->reset_lock); + + core_vdev->migration_flags =VFIO_MIGRATION_STOP_COPY |VFIO_MIGRATION_P2P ; + core_vdev->mig_ops = &ice_vfio_pci_migrn_state_ops; + +return vfio_pci_core_init_dev (core_vdev); +} + +static const struct vfio_device_ops ice_vfio_pci_ops = { + .name ="ice-vfio-pci" , + .init = ice_vfio_pci_core_init_dev, + .release = vfio_pci_core_release_dev, + .open_device = ice_vfio_pci_open_device, + .close_device = ice_vfio_pci_close_device, + .device_feature = vfio_pci_core_ioctl_feature, + .read = vfio_pci_core_read, + .write = vfio_pci_core_write, + .ioctl = vfio_pci_core_ioctl, + .mmap = vfio_pci_core_mmap, + .request = vfio_pci_core_request, + .match = vfio_pci_core_match, + .bind_iommufd = vfio_iommufd_physical_bind, + .unbind_iommufd = vfio_iommufd_physical_unbind, + .attach_ioas = vfio_iommufd_physical_attach_ioas, + .detach_ioas = vfio_iommufd_physical_detach_ioas, +}; + +/** +* ice_vfio_pci_probe - Device initialization routine +* @pdev: PCI device information struct +* @id: entry in ice_vfio_pci_table +* +* Returns 0 on success, negative on failure +*/ +static int +ice_vfio_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +struct ice_vfio_pci_core_device *ice_vdev; +int ret; + + ice_vdev =vfio_alloc_device (ice_vfio_pci_core_device, core_device.vdev, + &pdev->dev, &ice_vfio_pci_ops); +if (!ice_vdev) +return -ENOMEM ; + +dev_set_drvdata (&pdev->dev, &ice_vdev->core_device); + + ret =vfio_pci_core_register_device (&ice_vdev->core_device); +if (ret) + goto out_free; + +return 0 ; + +out_free: +vfio_put_device (&ice_vdev->core_device.vdev); +return ret; +} + +/** +* ice_vfio_pci_remove - Device removal routine +* @pdev: PCI device information struct +*/ +static void ice_vfio_pci_remove (struct pci_dev *pdev) +{ +struct ice_vfio_pci_core_device *ice_vdev = + (struct ice_vfio_pci_core_device *)dev_get_drvdata (&pdev->dev); + +vfio_pci_core_unregister_device (&ice_vdev->core_device); +vfio_put_device (&ice_vdev->core_device.vdev); +} + +/* ice_pci_tbl - PCI Device ID Table +* +* Wildcard entries (PCI_ANY_ID) should come last +* Last entry must be all 0s +* +* { Vendor ID, Device ID, SubVendor ID, SubDevice ID, +* Class, Class Mask, private data (not used) } +*/ +static const struct pci_device_id ice_vfio_pci_table[] = { + {PCI_DRIVER_OVERRIDE_DEVICE_VFIO (PCI_VENDOR_ID_INTEL ,0x1889 ) }, + {} +}; +MODULE_DEVICE_TABLE (pci, ice_vfio_pci_table); + +static const struct pci_error_handlers ice_vfio_pci_core_err_handlers = { + .reset_done = ice_vfio_pci_reset_done, + .error_detected = vfio_pci_core_aer_err_detected, +}; + +static struct pci_driver ice_vfio_pci_driver = { + .name ="ice-vfio-pci" , + .id_table = ice_vfio_pci_table, + .probe = ice_vfio_pci_probe, + .remove = ice_vfio_pci_remove, + .err_handler = &ice_vfio_pci_core_err_handlers, + .driver_managed_dma = true, +}; + +module_pci_driver (ice_vfio_pci_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Intel Corporation, <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC );
Jason Gunthorpe
reviewerRe: [PATCH iwl-next v3 13/13] vfio/ice: Implement vfio_pci driver for E800 devices
Quoted 13 lines · Alex Williamson
Quoted 4 lines
+/**
+ *ice_vfio_pci_load_state- VFIO device state reloading
+ * @ice_vdev: pointer to ice vfio pci core device structure
+ *Quoted 8 lines
+ * Load device state and restore it. This function is called when the VFIO uAPI
+ * consumer wants to load the device state info from VFIO migration region and
+ * restore them into the device. This function should make sure all the device
+ * state info is loaded and restored successfully. As a result, return value is
+ * mandatory to be checked.
+ *
+ * Return 0 for success, negative value for failure.
+ */
Quoted 4 lines
Kudos on the kernel-doc comments throughout, nice!
This appears to be a substantial improvement from the comments I see on v2, I'm curious where Kevin and Jason stand on this now. Thanks,
It is on my todo list, but I haven't been able to look
Did the fundamental issue with operating the VF from the VFIO driver get fully fixed?
Jason
Re: [PATCH iwl-next v3 13/13] vfio/ice: Implement vfio_pci driver for E800 devices
Quoted 16 lines · Jason Gunthorpe
Quoted 14 lines · Alex Williamson
Quoted 4 lines
+/**
+ *ice_vfio_pci_load_state- VFIO device state reloading
+ * @ice_vdev: pointer to ice vfio pci core device structure
+ *Quoted 8 lines
+ * Load device state and restore it. This function is called when the VFIO uAPI
+ * consumer wants to load the device state info from VFIO migration region and
+ * restore them into the device. This function should make sure all the device
+ * state info is loaded and restored successfully. As a result, return value is
+ * mandatory to be checked.
+ *
+ * Return 0 for success, negative value for failure.
+ */Kudos on the kernel-doc comments throughout, nice!
Quoted 8 lines
Quoted 2 lines
This appears to be a substantial improvement from the comments I see on v2, I'm curious where Kevin and Jason stand on this now. Thanks,
It is on my todo list, but I haven't been able to look
Did the fundamental issue with operating the VF from the VFIO driver get fully fixed?
Jason
Yes, I think so. In this version, with Kevin's guidance and help, there is not DMA read/write guest memory any more. VFIO driver will not operate VF and guest memory.
You can refer to Patch10 for more details.
Thanks.
Yahui.
Re: [PATCH iwl-next v3 13/13] vfio/ice: Implement vfio_pci driver for E800 devices
In reply to Alex WilliamsonQuoted 26 lines · Alex Williamson
Quoted 20 lines · On Mon, 18 Sep 2023 06:25:46 +0000 Yahui Cao <[email protected]> wrote:
From: Lingyu Liu <[email protected]>
Add a vendor-specific
vfio_pcidriver for E800 devices.It uses
vfio_pci_coreto register to the VFIO subsystem and then implements the E800 specific logic to support VF live migration.It implements the device state transition flow for live migration.
Signed-off-by Lingyu Liu <[email protected]>Signed-off-by Yahui Cao <[email protected]>--- MAINTAINERS | 7 + drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/ice/Kconfig | 10 + drivers/vfio/pci/ice/Makefile | 4 + drivers/vfio/pci/ice/ice_vfio_pci.c | 707 ++++++++++++++++++++++++++++ 6 files changed, 732 insertions(+)Quoted 3 lines
create mode 100644
drivers/vfio/pci/ice/Kconfigcreate mode 100644drivers/vfio/pci/ice/Makefilecreate mode 100644drivers/vfio/pci/ice/ice_vfio_pci.c
Quoted 3 lines
The prerequisite ice core driver support (ie. patches 1-12) should be supplied as a branch to allow this variant driver to be merged through the vfio tree.
Tony, are you the right one who can help on deal with ice driver and variant driver merging dependency ?
Quoted 38 lines
Quoted 38 lines
MAINTAINERS +7
-0@@ -22608,6 +22608,13 @@ L: [email protected] S: Maintained F: drivers/vfio/pci/mlx5/ +VFIO ICE PCI DRIVER +M: Yahui Cao <[email protected]> +M: Lingyu Liu <[email protected]> +L: [email protected] +S: Maintained +F: drivers/vfio/pci/ice/ + VFIO PCI DEVICE SPECIFIC DRIVERS R: Jason Gunthorpe <[email protected]> R: Yishai Hadas <[email protected]>drivers/vfio/pci/Kconfig +2
-0@@ -65,4 +65,6 @@ source "drivers/vfio/pci/hisilicon/Kconfig" source "drivers/vfio/pci/pds/Kconfig" +source "drivers/vfio/pci/ice/Kconfig" + endmenudrivers/vfio/pci/Makefile +0
-0@@ -13,3 +13,5 @@ obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/ obj-$(CONFIG_HISI_ACC_VFIO_PCI) += hisilicon/
Quoted 15 lines
Quoted 9 lines
drivers/vfio/pci/Makefile +2
-0obj-$(CONFIG_PDS_VFIO_PCI) += pds/ + +obj-$(CONFIG_ICE_VFIO_PCI) += ice/drivers/vfio/pci/ice/Kconfig new file +0
-0drivers/vfio/pci/ice/Kconfig line 5
Quoted 5 lines
drivers/vfio/pci/ice/Kconfig new file +5
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +config ICE_VFIO_PCI + tristate "VFIO support for Intel(R) Ethernet Connection E800 Series" + depends on ICE + depends on VFIO_PCI_COREs/depends on/select/
Sure. Will change to select VFIO_PCI_CORE
Quoted 14 lines
Quoted 14 lines
drivers/vfio/pci/ice/Kconfig new file +5
-0+ help + This provides migration support for Intel(R) Ethernet connection E800 + series devices using the VFIO framework. + + If you don't know what to do here, say N.drivers/vfio/pci/ice/Makefile new file +2
-0@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_ICE_VFIO_PCI) += ice-vfio-pci.o
Quoted 8 lines
drivers/vfio/pci/ice/ice_vfio_pci.c
Quoted 7 lines
drivers/vfio/pci/ice/Makefile new file +2
-0+ice-vfio-pci-y := ice_vfio_pci.o +drivers/vfio/pci/ice/ice_vfio_pci.c new file +0
-0Suggest renaming this to
main.c
If changing this to drivers/vfio/pci/ice/main.c, it may cause some naming conflict with networking driver file drivers/net/ethernet/intel/ice/ice_main.c and confusion.
Could we still use ice_vfio_pci.c ? Since this variant driver only has single c source file( like hisilicon variant driver )
Thanks.
Yahui.
Tian, Kevin
reviewerRE: [PATCH iwl-next v3 13/13] vfio/ice: Implement vfio_pci driver for E800 devices
In reply to Yahui CaoQuoted 19 lines
From: Cao, Yahui <[email protected]>
Sent: Monday, September 18, 2023 2:26 PM(quoted diff) +2
-0+static struct file * +ice_vfio_pci_step_device_state_locked(struct ice_vfio_pci_core_device
*ice_vdev,drivers/vfio/pci/ice/ice_vfio_pci.c new file +6
-0+ u32 new, u32 final) +{ + u32 cur = ice_vdev->mig_state; + int ret; + + if (cur == VFIO_DEVICE_STATE_RUNNING && new ==
VFIO_DEVICE_STATE_RUNNING_P2P) {drivers/vfio/pci/ice/ice_vfio_pci.c new file +5
-0+ice_migration_suspend_dev (ice_vdev->pf, ice_vdev->vf_id); +return NULL ; + } + + if (cur == VFIO_DEVICE_STATE_RUNNING_P2P && new ==
VFIO_DEVICE_STATE_STOP)
Review
Quoted 2 lines
(quoted diff) +2
-0+ return NULL; +
Jason, above is one open which your clarification is appreciated.
From my talk with Yahui this device can drain/stop outgoing traffic but has no interface to stop incoming request.
is it OK to do nothing for RUNNING_P2P->STOP transition like above?
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Jason Gunthorpe
reviewerRe: [PATCH iwl-next v3 13/13] vfio/ice: Implement vfio_pci driver for E800 devices
Quoted 24 lines · Kevin
Quoted 19 lines
From: Cao, Yahui <[email protected]>
Sent: Monday, September 18, 2023 2:26 PM(quoted diff) +2
-0+static struct file * +ice_vfio_pci_step_device_state_locked(struct ice_vfio_pci_core_device
*ice_vdev,drivers/vfio/pci/ice/ice_vfio_pci.c new file +6
-0+ u32 new, u32 final) +{ + u32 cur = ice_vdev->mig_state; + int ret; + + if (cur == VFIO_DEVICE_STATE_RUNNING && new ==
VFIO_DEVICE_STATE_RUNNING_P2P) {drivers/vfio/pci/ice/ice_vfio_pci.c new file +5
-0+ice_migration_suspend_dev (ice_vdev->pf, ice_vdev->vf_id); +return NULL ; + } + + if (cur == VFIO_DEVICE_STATE_RUNNING_P2P && new ==
VFIO_DEVICE_STATE_STOP)Review
Quoted 2 lines
(quoted diff) +2
-0+ return NULL; +Jason, above is one open which your clarification is appreciated.
Quoted 4 lines
From my talk with Yahui this device can drain/stop outgoing traffic but has no interface to stop incoming request.
is it OK to do nothing for
RUNNING_P2P->STOPtransition like above?
Yes.
The purpose of RUNNING_P2P->STOP is to allow the device to do anything it may need to stop internal autonomous operations prior to doing a get_state. If the device does not have such a concept then a NOP is fine.
Jason
Tian, Kevin
reviewerRE: [PATCH iwl-next v3 13/13] vfio/ice: Implement vfio_pci driver for E800 devices
Quoted 31 lines
From: Jason Gunthorpe <[email protected]>
Sent: Friday, October 13, 2023 10:08 PMQuoted 26 lines · Kevin
Quoted 19 lines
From: Cao, Yahui <[email protected]>
Sent: Monday, September 18, 2023 2:26 PM(quoted diff) +2
-0+static struct file * +ice_vfio_pci_step_device_state_locked(struct ice_vfio_pci_core_device
*ice_vdev,drivers/vfio/pci/ice/ice_vfio_pci.c new file +6
-0+ u32 new, u32 final) +{ + u32 cur = ice_vdev->mig_state; + int ret; + + if (cur == VFIO_DEVICE_STATE_RUNNING && new ==
VFIO_DEVICE_STATE_RUNNING_P2P) {drivers/vfio/pci/ice/ice_vfio_pci.c new file +5
-0+ice_migration_suspend_dev (ice_vdev->pf, ice_vdev->vf_id); +return NULL ; + } + + if (cur == VFIO_DEVICE_STATE_RUNNING_P2P && new ==
VFIO_DEVICE_STATE_STOP)Review
Quoted 2 lines
(quoted diff) +2
-0+ return NULL; +Jason, above is one open which your clarification is appreciated.
From my talk with Yahui this device can drain/stop outgoing traffic but has no interface to stop incoming request.
Quoted 9 lines
Quoted 1 line
is it OK to do nothing for
RUNNING_P2P->STOPtransition like above?Yes.
The purpose of
RUNNING_P2P->STOPis to allow the device to do anything it may need to stop internal autonomous operations prior to doing aget_state. If the device does not have such a concept then a NOP is fine.
Thanks. this is clear then.
Quoted 9 lines · Yahui Cao
This series adds vfio live migration support for Intel E810 VF devices based on the v2 migration protocol definition series discussed here[0].
Steps to test:
1. Bind one or more E810 VF devices to the module ice_vfio_pci.ko
2. Assign the VFs to the virtual machine and enable device live migration
3. Run a workload using IAVF inside the VM, for example, iperf.
4. Migrate the VM from the source node to a destination node.
Quoted 4 lines
Thanks,
Yahui
[0] https://lore.kernel.org/kvm/[email protected]/
The series fails to compile cleanly at each stage if CONFIG_ICE_VFIO_PCI is disabled.
Additionally I noticed that the earlier patches depend on CONFIG_ICE_VFIO_PCI (the config option is checked in the headers) but its not added to the Kconfig until near the end of the series
Quoted 9 lines
In file included from
drivers/net/ethernet/intel/ice/ice.h:58,
fromdrivers/net/ethernet/intel/ice/ice_main.c:9:./include/linux/net/intel/ice_migration.h: In function ‘ice_migration_init_dev’:./include/linux/net/intel/ice_migration.h:24:49: error: no return statement in function returning non-void [-Werror=return-type]
24 | static inline intice_migration_init_dev(struct ice_pf *pf, int vf_id){ }
| ^~~~~~
In file included fromdrivers/net/ethernet/intel/ice/ice.h:58,
fromdrivers/net/ethernet/intel/ice/ice_lib.c:4:
Quoted 8 lines
make[7]: *** [
scripts/Makefile.build:243:drivers/net/ethernet/intel/ice/ice_fltr.o] Error 1
cc1: some warnings being treated as errors
cc1: some warnings being treated as errorsdrivers/net/ethernet/intel/ice/ice_virtchnl.c:4145:17: error: implicit declaration of function ‘ice_migration_unlog_vf_msg’; did you mean ‘ice_migration_save_vf_msg’? [-Werror=implicit-function-declaration]4145 | ice_migration_unlog_vf_msg(vf, v_opcode); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | ice_migration_save_vf_msgcc1: some warnings being treated as errors
Please fix these issues.
Thanks,
Jake
Quoted 76 lines
Change log:
v2 --> v3: link [2]
- Add P2P support in vfio driver (Jason)
- Remove source/destination check in vfio driver (Jason)
- Restructure PF exported API with proper types and layering (Jason)
- Change patchset email sender.
- Reword commit message and comments to be more reviewer-friendly (Kevin)
- Add s-o-b for Patch01 (Kevin)
- Merge Patch08 into Patch04 and merge Patch13 into Patch06 (Kevin)
- Removeuninit()in VF destroy stage for Patch 05 (Kevin)
- changemigration_activetomigration_enabled(Kevin)
- Addtotal_sizein devstate to greatly simplify the various checks for Patch07 (Kevin)
- Add magic and version in device state for Patch07 (Kevin)
- Fix rx head init issue in Patch10 (Kevin)
- Remove DMA access for Guest Memory at device resume stage and deprecate the approach to restore TX head in VF space, instead restore TX head in PF space and then switch context back to VF space which is transparent to Guest for Patch11 (Jason, Kevin)
- Use non-interrupt mode instead of VF MSIX vector to restore TX head for Patch11 (Kevin)
- Move VF pci mmio save/restore from vfio driver into PF driver
- Add configuration match check at device resume stage (Kevin)
- Remove sleep before stopping queue at device suspend stage (Kevin)
- Let PF respond failure to VF if virtual channel messages logging failed (Kevin)
- Add migration setup and description in cover letter[2] https://lore.kernel.org/intel-wired-lan/[email protected]/
v1 --> v2: link [1]
- clarified comments and commit message[1] https://lore.kernel.org/intel-wired-lan/[email protected]/
---
Lingyu Liu (9):
ice: Introduce VF stateICE_VF_STATE_REPLAYING_VCfor migration
ice: Add fundamental migration init and exit function
ice: Log virtual channel messages in PF
ice: Add device state save/restore function for migration
ice: Fix VSI id in virtual channel message for migration
ice: Save and restore RX Queue head
ice: Save and restore TX Queue head
ice: Add device suspend function for migration vfio/ice: Implementvfio_pcidriver for E800 devicesXu Ting (1):
ice: Fix missing legacy 32byte RXDID in the supported bitmapYahui Cao (3):
ice: Add function to get RX queue context
ice: Add function to get and set TX queue context
ice: Save and restore mmio registersMAINTAINERS | 7 + drivers/net/ethernet/intel/ice/Makefile | 3 +- drivers/net/ethernet/intel/ice/ice.h | 3 + drivers/net/ethernet/intel/ice/ice_common.c | 484 +++++- drivers/net/ethernet/intel/ice/ice_common.h | 11 + .../net/ethernet/intel/ice/ice_hw_autogen.h | 23 + .../net/ethernet/intel/ice/ice_lan_tx_rx.h | 3 + drivers/net/ethernet/intel/ice/ice_main.c | 15 + .../net/ethernet/intel/ice/ice_migration.c | 1344 +++++++++++++++++ .../intel/ice/ice_migration_private.h | 44 + drivers/net/ethernet/intel/ice/ice_vf_lib.c | 4 + drivers/net/ethernet/intel/ice/ice_vf_lib.h | 10 + drivers/net/ethernet/intel/ice/ice_virtchnl.c | 267 ++-- drivers/net/ethernet/intel/ice/ice_virtchnl.h | 15 +- .../ethernet/intel/ice/ice_virtchnl_fdir.c | 28 +- drivers/vfio/pci/Kconfig | 2 + drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/ice/Kconfig | 10 + drivers/vfio/pci/ice/Makefile | 4 + drivers/vfio/pci/ice/ice_vfio_pci.c | 707 +++++++++
Quoted 9 lines
include/linux/net/intel/ice_migration.h | 42 + 21 files changed, 2916 insertions(+), 112 deletions(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_migration.c create mode 100644 drivers/net/ethernet/intel/ice/ice_migration_private.h create mode 100644 drivers/vfio/pci/ice/Kconfig create mode 100644 drivers/vfio/pci/ice/Makefile create mode 100644 drivers/vfio/pci/ice/ice_vfio_pci.c create mode 100644 include/linux/net/intel/ice_migration.h
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Jason Gunthorpe
reviewerQuoted 8 lines · Yahui Cao
This series adds vfio live migration support for Intel E810 VF devices based on the v2 migration protocol definition series discussed here[0].
Steps to test:
1. Bind one or more E810 VF devices to the module ice_vfio_pci.ko
2. Assign the VFs to the virtual machine and enable device live migration
3. Run a workload using IAVF inside the VM, for example, iperf.
4. Migrate the VM from the source node to a destination node.
It looked better that the previous versions, I wanted to take a closer look but the series didn't apply to v6.6-rc6. When you send v4 with the compilation fixed include a git link please
Jason
Quoted 9 lines · Jason Gunthorpe
Quoted 8 lines · Yahui Cao
This series adds vfio live migration support for Intel E810 VF devices based on the v2 migration protocol definition series discussed here[0].
Steps to test:
1. Bind one or more E810 VF devices to the module ice_vfio_pci.ko
2. Assign the VFs to the virtual machine and enable device live migration
3. Run a workload using IAVF inside the VM, for example, iperf.
4. Migrate the VM from the source node to a destination node.
Quoted 5 lines
It looked better that the previous versions, I wanted to take a closer look but the series didn't apply to v6.6-rc6. When you send v4 with the compilation fixed include a git link please
Jason
Sure. I'll send next version with compilation fixed and a git link.
Thanks.
Yahui.