2021-08-19 17:08:48 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* Copyright (C) 2019-2021, Intel Corporation. */
|
|
|
|
|
|
|
|
#include "ice.h"
|
2021-08-19 17:08:54 -07:00
|
|
|
#include "ice_lib.h"
|
2021-08-19 17:08:48 -07:00
|
|
|
#include "ice_eswitch.h"
|
2021-08-19 17:08:54 -07:00
|
|
|
#include "ice_fltr.h"
|
|
|
|
#include "ice_repr.h"
|
2021-08-19 17:08:48 -07:00
|
|
|
#include "ice_devlink.h"
|
2021-08-06 10:49:06 +02:00
|
|
|
#include "ice_tc_lib.h"
|
2021-08-19 17:08:48 -07:00
|
|
|
|
2021-10-26 12:38:40 +02:00
|
|
|
/**
|
2023-04-07 18:52:19 +02:00
|
|
|
* ice_eswitch_add_vf_sp_rule - add adv rule with VF's VSI index
|
2021-10-26 12:38:40 +02:00
|
|
|
* @pf: pointer to PF struct
|
|
|
|
* @vf: pointer to VF struct
|
|
|
|
*
|
|
|
|
* This function adds advanced rule that forwards packets with
|
2023-04-07 18:52:19 +02:00
|
|
|
* VF's VSI index to the corresponding switchdev ctrl VSI queue.
|
2021-10-26 12:38:40 +02:00
|
|
|
*/
|
2023-04-07 18:52:19 +02:00
|
|
|
static int
|
|
|
|
ice_eswitch_add_vf_sp_rule(struct ice_pf *pf, struct ice_vf *vf)
|
2021-10-26 12:38:40 +02:00
|
|
|
{
|
|
|
|
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
|
|
|
|
struct ice_adv_rule_info rule_info = { 0 };
|
|
|
|
struct ice_adv_lkup_elem *list;
|
|
|
|
struct ice_hw *hw = &pf->hw;
|
|
|
|
const u16 lkups_cnt = 1;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
list = kcalloc(lkups_cnt, sizeof(*list), GFP_ATOMIC);
|
|
|
|
if (!list)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_rule_add_src_vsi_metadata(list);
|
2021-10-26 12:38:40 +02:00
|
|
|
|
2023-04-07 18:52:19 +02:00
|
|
|
rule_info.sw_act.flag = ICE_FLTR_TX;
|
2021-10-26 12:38:40 +02:00
|
|
|
rule_info.sw_act.vsi_handle = ctrl_vsi->idx;
|
|
|
|
rule_info.sw_act.fltr_act = ICE_FWD_TO_Q;
|
|
|
|
rule_info.sw_act.fwd_id.q_id = hw->func_caps.common_cap.rxq_first_id +
|
|
|
|
ctrl_vsi->rxq_map[vf->vf_id];
|
|
|
|
rule_info.flags_info.act |= ICE_SINGLE_ACT_LB_ENABLE;
|
|
|
|
rule_info.flags_info.act_valid = true;
|
2021-12-17 12:36:25 +01:00
|
|
|
rule_info.tun_type = ICE_SW_TUN_AND_NON_TUN;
|
2023-04-07 18:52:19 +02:00
|
|
|
rule_info.src_vsi = vf->lan_vsi_idx;
|
2021-10-26 12:38:40 +02:00
|
|
|
|
|
|
|
err = ice_add_adv_rule(hw, list, lkups_cnt, &rule_info,
|
2023-04-07 18:52:19 +02:00
|
|
|
&vf->repr->sp_rule);
|
2021-10-26 12:38:40 +02:00
|
|
|
if (err)
|
2023-04-07 18:52:19 +02:00
|
|
|
dev_err(ice_pf_to_dev(pf), "Unable to add VF slow-path rule in switchdev mode for VF %d",
|
2021-10-26 12:38:40 +02:00
|
|
|
vf->vf_id);
|
|
|
|
|
|
|
|
kfree(list);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-07 18:52:19 +02:00
|
|
|
* ice_eswitch_del_vf_sp_rule - delete adv rule with VF's VSI index
|
2021-10-26 12:38:40 +02:00
|
|
|
* @vf: pointer to the VF struct
|
|
|
|
*
|
2023-04-07 18:52:19 +02:00
|
|
|
* Delete the advanced rule that was used to forward packets with the VF's VSI
|
|
|
|
* index to the corresponding switchdev ctrl VSI queue.
|
2021-10-26 12:38:40 +02:00
|
|
|
*/
|
2023-04-07 18:52:19 +02:00
|
|
|
static void ice_eswitch_del_vf_sp_rule(struct ice_vf *vf)
|
2021-10-26 12:38:40 +02:00
|
|
|
{
|
2023-04-07 18:52:19 +02:00
|
|
|
if (!vf->repr)
|
2021-10-26 12:38:40 +02:00
|
|
|
return;
|
|
|
|
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_rem_adv_rule_by_id(&vf->pf->hw, &vf->repr->sp_rule);
|
2021-10-26 12:38:40 +02:00
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:54 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_setup_env - configure switchdev HW filters
|
|
|
|
* @pf: pointer to PF struct
|
|
|
|
*
|
|
|
|
* This function adds HW filters configuration specific for switchdev
|
|
|
|
* mode.
|
|
|
|
*/
|
|
|
|
static int ice_eswitch_setup_env(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
struct ice_vsi *uplink_vsi = pf->switchdev.uplink_vsi;
|
2021-10-26 17:46:28 +02:00
|
|
|
struct net_device *uplink_netdev = uplink_vsi->netdev;
|
2021-08-19 17:08:54 -07:00
|
|
|
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
|
2021-12-02 08:38:46 -08:00
|
|
|
struct ice_vsi_vlan_ops *vlan_ops;
|
2021-08-19 17:08:54 -07:00
|
|
|
bool rule_added = false;
|
|
|
|
|
2021-12-02 08:38:46 -08:00
|
|
|
vlan_ops = ice_get_compat_vsi_vlan_ops(ctrl_vsi);
|
|
|
|
if (vlan_ops->dis_stripping(ctrl_vsi))
|
|
|
|
return -ENODEV;
|
2021-08-19 17:08:54 -07:00
|
|
|
|
|
|
|
ice_remove_vsi_fltr(&pf->hw, uplink_vsi->idx);
|
|
|
|
|
2021-10-26 17:46:28 +02:00
|
|
|
netif_addr_lock_bh(uplink_netdev);
|
|
|
|
__dev_uc_unsync(uplink_netdev, NULL);
|
|
|
|
__dev_mc_unsync(uplink_netdev, NULL);
|
|
|
|
netif_addr_unlock_bh(uplink_netdev);
|
|
|
|
|
2021-12-02 08:38:40 -08:00
|
|
|
if (ice_vsi_add_vlan_zero(uplink_vsi))
|
2021-08-19 17:08:54 -07:00
|
|
|
goto err_def_rx;
|
|
|
|
|
2022-07-04 15:12:26 +02:00
|
|
|
if (!ice_is_dflt_vsi_in_use(uplink_vsi->port_info)) {
|
|
|
|
if (ice_set_dflt_vsi(uplink_vsi))
|
2021-08-19 17:08:54 -07:00
|
|
|
goto err_def_rx;
|
|
|
|
rule_added = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ice_vsi_update_security(uplink_vsi, ice_vsi_ctx_set_allow_override))
|
|
|
|
goto err_override_uplink;
|
|
|
|
|
|
|
|
if (ice_vsi_update_security(ctrl_vsi, ice_vsi_ctx_set_allow_override))
|
|
|
|
goto err_override_control;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_override_control:
|
|
|
|
ice_vsi_update_security(uplink_vsi, ice_vsi_ctx_clear_allow_override);
|
|
|
|
err_override_uplink:
|
|
|
|
if (rule_added)
|
2022-07-04 15:12:26 +02:00
|
|
|
ice_clear_dflt_vsi(uplink_vsi);
|
2021-08-19 17:08:54 -07:00
|
|
|
err_def_rx:
|
|
|
|
ice_fltr_add_mac_and_broadcast(uplink_vsi,
|
|
|
|
uplink_vsi->port_info->mac.perm_addr,
|
|
|
|
ICE_FWD_TO_VSI);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_remap_rings_to_vectors - reconfigure rings of switchdev ctrl VSI
|
|
|
|
* @pf: pointer to PF struct
|
|
|
|
*
|
|
|
|
* In switchdev number of allocated Tx/Rx rings is equal.
|
|
|
|
*
|
|
|
|
* This function fills q_vectors structures associated with representor and
|
|
|
|
* move each ring pairs to port representor netdevs. Each port representor
|
|
|
|
* will have dedicated 1 Tx/Rx ring pair, so number of rings pair is equal to
|
|
|
|
* number of VFs.
|
|
|
|
*/
|
|
|
|
static void ice_eswitch_remap_rings_to_vectors(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
struct ice_vsi *vsi = pf->switchdev.control_vsi;
|
|
|
|
int q_id;
|
|
|
|
|
|
|
|
ice_for_each_txq(vsi, q_id) {
|
2022-02-16 13:37:36 -08:00
|
|
|
struct ice_q_vector *q_vector;
|
|
|
|
struct ice_tx_ring *tx_ring;
|
|
|
|
struct ice_rx_ring *rx_ring;
|
|
|
|
struct ice_repr *repr;
|
|
|
|
struct ice_vf *vf;
|
|
|
|
|
2022-02-16 13:37:37 -08:00
|
|
|
vf = ice_get_vf_by_id(pf, q_id);
|
|
|
|
if (WARN_ON(!vf))
|
2022-02-16 13:37:36 -08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
repr = vf->repr;
|
|
|
|
q_vector = repr->q_vector;
|
|
|
|
tx_ring = vsi->tx_rings[q_id];
|
|
|
|
rx_ring = vsi->rx_rings[q_id];
|
2021-08-19 17:08:54 -07:00
|
|
|
|
|
|
|
q_vector->vsi = vsi;
|
|
|
|
q_vector->reg_idx = vsi->q_vectors[0]->reg_idx;
|
|
|
|
|
|
|
|
q_vector->num_ring_tx = 1;
|
2021-08-19 13:59:58 +02:00
|
|
|
q_vector->tx.tx_ring = tx_ring;
|
|
|
|
tx_ring->q_vector = q_vector;
|
|
|
|
tx_ring->next = NULL;
|
|
|
|
tx_ring->netdev = repr->netdev;
|
2021-08-19 17:08:54 -07:00
|
|
|
/* In switchdev mode, from OS stack perspective, there is only
|
|
|
|
* one queue for given netdev, so it needs to be indexed as 0.
|
|
|
|
*/
|
|
|
|
tx_ring->q_index = 0;
|
|
|
|
|
|
|
|
q_vector->num_ring_rx = 1;
|
2021-08-19 13:59:58 +02:00
|
|
|
q_vector->rx.rx_ring = rx_ring;
|
|
|
|
rx_ring->q_vector = q_vector;
|
|
|
|
rx_ring->next = NULL;
|
|
|
|
rx_ring->netdev = repr->netdev;
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
|
|
|
|
ice_put_vf(vf);
|
2021-08-19 17:08:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 13:37:28 -08:00
|
|
|
/**
|
|
|
|
* ice_eswitch_release_reprs - clear PR VSIs configuration
|
|
|
|
* @pf: poiner to PF struct
|
|
|
|
* @ctrl_vsi: pointer to switchdev control VSI
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
|
|
|
|
{
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2022-02-16 13:37:28 -08:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf) {
|
|
|
|
struct ice_vsi *vsi = vf->repr->src_vsi;
|
2022-02-16 13:37:28 -08:00
|
|
|
|
|
|
|
/* Skip VFs that aren't configured */
|
|
|
|
if (!vf->repr->dst)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
|
|
|
|
metadata_dst_free(vf->repr->dst);
|
|
|
|
vf->repr->dst = NULL;
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_eswitch_del_vf_sp_rule(vf);
|
2023-01-18 17:16:53 -08:00
|
|
|
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
|
2022-02-16 13:37:28 -08:00
|
|
|
ICE_FWD_TO_VSI);
|
|
|
|
|
|
|
|
netif_napi_del(&vf->repr->q_vector->napi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:54 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_setup_reprs - configure port reprs to run in switchdev mode
|
|
|
|
* @pf: pointer to PF struct
|
|
|
|
*/
|
|
|
|
static int ice_eswitch_setup_reprs(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
|
|
|
|
int max_vsi_num = 0;
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2021-08-19 17:08:54 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf) {
|
|
|
|
struct ice_vsi *vsi = vf->repr->src_vsi;
|
2021-08-19 17:08:54 -07:00
|
|
|
|
|
|
|
ice_remove_vsi_fltr(&pf->hw, vsi->idx);
|
|
|
|
vf->repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!vf->repr->dst) {
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
|
|
|
|
ICE_FWD_TO_VSI);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ice_eswitch_add_vf_sp_rule(pf, vf)) {
|
|
|
|
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
|
2021-08-19 17:08:54 -07:00
|
|
|
ICE_FWD_TO_VSI);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof)) {
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
|
2021-08-19 17:08:54 -07:00
|
|
|
ICE_FWD_TO_VSI);
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_eswitch_del_vf_sp_rule(vf);
|
2021-08-19 17:08:54 -07:00
|
|
|
metadata_dst_free(vf->repr->dst);
|
2022-02-16 13:37:28 -08:00
|
|
|
vf->repr->dst = NULL;
|
2021-08-19 17:08:54 -07:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-12-02 08:38:40 -08:00
|
|
|
if (ice_vsi_add_vlan_zero(vsi)) {
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
|
2021-08-19 17:08:54 -07:00
|
|
|
ICE_FWD_TO_VSI);
|
2023-04-07 18:52:19 +02:00
|
|
|
ice_eswitch_del_vf_sp_rule(vf);
|
2021-08-19 17:08:54 -07:00
|
|
|
metadata_dst_free(vf->repr->dst);
|
2022-02-16 13:37:28 -08:00
|
|
|
vf->repr->dst = NULL;
|
2021-08-19 17:08:54 -07:00
|
|
|
ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_vsi_num < vsi->vsi_num)
|
|
|
|
max_vsi_num = vsi->vsi_num;
|
|
|
|
|
2022-09-27 06:27:53 -07:00
|
|
|
netif_napi_add(vf->repr->netdev, &vf->repr->q_vector->napi,
|
|
|
|
ice_napi_poll);
|
2021-08-19 17:08:54 -07:00
|
|
|
|
|
|
|
netif_keep_dst(vf->repr->netdev);
|
|
|
|
}
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf) {
|
|
|
|
struct ice_repr *repr = vf->repr;
|
2021-08-19 17:08:54 -07:00
|
|
|
struct ice_vsi *vsi = repr->src_vsi;
|
|
|
|
struct metadata_dst *dst;
|
|
|
|
|
|
|
|
dst = repr->dst;
|
|
|
|
dst->u.port_info.port_id = vsi->vsi_num;
|
|
|
|
dst->u.port_info.lower_dev = repr->netdev;
|
|
|
|
ice_repr_set_traffic_vsi(repr, ctrl_vsi);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2022-02-16 13:37:28 -08:00
|
|
|
ice_eswitch_release_reprs(pf, ctrl_vsi);
|
2021-08-19 17:08:54 -07:00
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:56 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_update_repr - reconfigure VF port representor
|
|
|
|
* @vsi: VF VSI for which port representor is configured
|
|
|
|
*/
|
|
|
|
void ice_eswitch_update_repr(struct ice_vsi *vsi)
|
|
|
|
{
|
|
|
|
struct ice_pf *pf = vsi->back;
|
|
|
|
struct ice_repr *repr;
|
|
|
|
struct ice_vf *vf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!ice_is_switchdev_running(pf))
|
|
|
|
return;
|
|
|
|
|
2022-02-16 13:37:29 -08:00
|
|
|
vf = vsi->vf;
|
2021-08-19 17:08:56 -07:00
|
|
|
repr = vf->repr;
|
|
|
|
repr->src_vsi = vsi;
|
|
|
|
repr->dst->u.port_info.port_id = vsi->vsi_num;
|
|
|
|
|
|
|
|
ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
|
|
|
|
if (ret) {
|
2023-01-18 17:16:53 -08:00
|
|
|
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr, ICE_FWD_TO_VSI);
|
2022-02-16 13:37:29 -08:00
|
|
|
dev_err(ice_pf_to_dev(pf), "Failed to update VF %d port representor",
|
|
|
|
vsi->vf->vf_id);
|
2021-08-19 17:08:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:58 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_port_start_xmit - callback for packets transmit
|
|
|
|
* @skb: send buffer
|
|
|
|
* @netdev: network interface device structure
|
|
|
|
*
|
|
|
|
* Returns NETDEV_TX_OK if sent, else an error code
|
|
|
|
*/
|
|
|
|
netdev_tx_t
|
|
|
|
ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct ice_netdev_priv *np;
|
|
|
|
struct ice_repr *repr;
|
|
|
|
struct ice_vsi *vsi;
|
|
|
|
|
|
|
|
np = netdev_priv(netdev);
|
|
|
|
vsi = np->vsi;
|
|
|
|
|
2022-04-08 09:56:10 +02:00
|
|
|
if (ice_is_reset_in_progress(vsi->back->state) ||
|
|
|
|
test_bit(ICE_VF_DIS, vsi->back->state))
|
2021-08-19 17:08:58 -07:00
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
|
|
|
|
repr = ice_netdev_to_repr(netdev);
|
|
|
|
skb_dst_drop(skb);
|
|
|
|
dst_hold((struct dst_entry *)repr->dst);
|
|
|
|
skb_dst_set(skb, (struct dst_entry *)repr->dst);
|
|
|
|
skb->queue_mapping = repr->vf->vf_id;
|
|
|
|
|
|
|
|
return ice_start_xmit(skb, netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_set_target_vsi - set switchdev context in Tx context descriptor
|
|
|
|
* @skb: pointer to send buffer
|
|
|
|
* @off: pointer to offload struct
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ice_eswitch_set_target_vsi(struct sk_buff *skb,
|
|
|
|
struct ice_tx_offload_params *off)
|
|
|
|
{
|
|
|
|
struct metadata_dst *dst = skb_metadata_dst(skb);
|
|
|
|
u64 cd_cmd, dst_vsi;
|
|
|
|
|
|
|
|
if (!dst) {
|
|
|
|
cd_cmd = ICE_TX_CTX_DESC_SWTCH_UPLINK << ICE_TXD_CTX_QW1_CMD_S;
|
|
|
|
off->cd_qw1 |= (cd_cmd | ICE_TX_DESC_DTYPE_CTX);
|
|
|
|
} else {
|
|
|
|
cd_cmd = ICE_TX_CTX_DESC_SWTCH_VSI << ICE_TXD_CTX_QW1_CMD_S;
|
|
|
|
dst_vsi = ((u64)dst->u.port_info.port_id <<
|
|
|
|
ICE_TXD_CTX_QW1_VSI_S) & ICE_TXD_CTX_QW1_VSI_M;
|
|
|
|
off->cd_qw1 = cd_cmd | dst_vsi | ICE_TX_DESC_DTYPE_CTX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:54 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_release_env - clear switchdev HW filters
|
|
|
|
* @pf: pointer to PF struct
|
|
|
|
*
|
|
|
|
* This function removes HW filters configuration specific for switchdev
|
|
|
|
* mode and restores default legacy mode settings.
|
|
|
|
*/
|
|
|
|
static void ice_eswitch_release_env(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
struct ice_vsi *uplink_vsi = pf->switchdev.uplink_vsi;
|
|
|
|
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
|
|
|
|
|
|
|
|
ice_vsi_update_security(ctrl_vsi, ice_vsi_ctx_clear_allow_override);
|
|
|
|
ice_vsi_update_security(uplink_vsi, ice_vsi_ctx_clear_allow_override);
|
2022-07-04 15:12:26 +02:00
|
|
|
ice_clear_dflt_vsi(uplink_vsi);
|
2021-08-19 17:08:54 -07:00
|
|
|
ice_fltr_add_mac_and_broadcast(uplink_vsi,
|
|
|
|
uplink_vsi->port_info->mac.perm_addr,
|
|
|
|
ICE_FWD_TO_VSI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_vsi_setup - configure switchdev control VSI
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
* @pi: pointer to port_info structure
|
|
|
|
*/
|
|
|
|
static struct ice_vsi *
|
|
|
|
ice_eswitch_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
|
|
|
|
{
|
ice: refactor VSI setup to use parameter structure
The ice_vsi_setup function, ice_vsi_alloc, and ice_vsi_cfg functions have
grown a large number of parameters. These parameters are used to initialize
a new VSI, as well as re-configure an existing VSI
Any time we want to add a new parameter to this function chain, even if it
will usually be unset, we have to change many call sites due to changing
the function signature.
A future change is going to refactor ice_vsi_alloc and ice_vsi_cfg to move
the VSI configuration and initialization all into ice_vsi_cfg.
Before this, refactor the VSI setup flow to use a new ice_vsi_cfg_params
structure. This will contain the configuration (mainly pointers) used to
initialize a VSI.
Pass this from ice_vsi_setup into the related functions such as
ice_vsi_alloc, ice_vsi_cfg, and ice_vsi_cfg_def.
Introduce a helper, ice_vsi_to_params to convert an existing VSI to the
parameters used to initialize it. This will aid in the flows where we
rebuild an existing VSI.
Since we also pass the ICE_VSI_FLAG_INIT to more functions which do not
need (or cannot yet have) the VSI parameters, lets make this clear by
renaming the function parameter to vsi_flags and using a u32 instead of a
signed integer. The name vsi_flags also makes it clear that we may extend
the flags in the future.
This change will make it easier to refactor the setup flow in the future,
and will reduce the complexity required to add a new parameter for
configuration in the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2023-01-18 17:16:43 -08:00
|
|
|
struct ice_vsi_cfg_params params = {};
|
|
|
|
|
|
|
|
params.type = ICE_VSI_SWITCHDEV_CTRL;
|
|
|
|
params.pi = pi;
|
|
|
|
params.flags = ICE_VSI_FLAG_INIT;
|
|
|
|
|
|
|
|
return ice_vsi_setup(pf, ¶ms);
|
2021-08-19 17:08:54 -07:00
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:57 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_napi_del - remove NAPI handle for all port representors
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
static void ice_eswitch_napi_del(struct ice_pf *pf)
|
|
|
|
{
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2021-08-19 17:08:57 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf)
|
|
|
|
netif_napi_del(&vf->repr->q_vector->napi);
|
2021-08-19 17:08:57 -07:00
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:54 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_napi_enable - enable NAPI for all port representors
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
static void ice_eswitch_napi_enable(struct ice_pf *pf)
|
|
|
|
{
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2021-08-19 17:08:54 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf)
|
|
|
|
napi_enable(&vf->repr->q_vector->napi);
|
2021-08-19 17:08:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_napi_disable - disable NAPI for all port representors
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
static void ice_eswitch_napi_disable(struct ice_pf *pf)
|
|
|
|
{
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2021-08-19 17:08:54 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf)
|
|
|
|
napi_disable(&vf->repr->q_vector->napi);
|
2021-08-19 17:08:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_enable_switchdev - configure eswitch in switchdev mode
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
static int ice_eswitch_enable_switchdev(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
struct ice_vsi *ctrl_vsi;
|
|
|
|
|
|
|
|
pf->switchdev.control_vsi = ice_eswitch_vsi_setup(pf, pf->hw.port_info);
|
|
|
|
if (!pf->switchdev.control_vsi)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ctrl_vsi = pf->switchdev.control_vsi;
|
|
|
|
pf->switchdev.uplink_vsi = ice_get_main_vsi(pf);
|
|
|
|
if (!pf->switchdev.uplink_vsi)
|
|
|
|
goto err_vsi;
|
|
|
|
|
|
|
|
if (ice_eswitch_setup_env(pf))
|
|
|
|
goto err_vsi;
|
|
|
|
|
|
|
|
if (ice_repr_add_for_all_vfs(pf))
|
|
|
|
goto err_repr_add;
|
|
|
|
|
|
|
|
if (ice_eswitch_setup_reprs(pf))
|
|
|
|
goto err_setup_reprs;
|
|
|
|
|
|
|
|
ice_eswitch_remap_rings_to_vectors(pf);
|
|
|
|
|
|
|
|
if (ice_vsi_open(ctrl_vsi))
|
|
|
|
goto err_setup_reprs;
|
|
|
|
|
|
|
|
ice_eswitch_napi_enable(pf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_setup_reprs:
|
|
|
|
ice_repr_rem_from_all_vfs(pf);
|
|
|
|
err_repr_add:
|
|
|
|
ice_eswitch_release_env(pf);
|
|
|
|
err_vsi:
|
|
|
|
ice_vsi_release(ctrl_vsi);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_disable_switchdev - disable switchdev resources
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
static void ice_eswitch_disable_switchdev(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
|
|
|
|
|
|
|
|
ice_eswitch_napi_disable(pf);
|
|
|
|
ice_eswitch_release_env(pf);
|
|
|
|
ice_eswitch_release_reprs(pf, ctrl_vsi);
|
|
|
|
ice_vsi_release(ctrl_vsi);
|
|
|
|
ice_repr_rem_from_all_vfs(pf);
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:48 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_mode_set - set new eswitch mode
|
|
|
|
* @devlink: pointer to devlink structure
|
|
|
|
* @mode: eswitch mode to switch to
|
|
|
|
* @extack: pointer to extack structure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
{
|
|
|
|
struct ice_pf *pf = devlink_priv(devlink);
|
|
|
|
|
|
|
|
if (pf->eswitch_mode == mode)
|
|
|
|
return 0;
|
|
|
|
|
2022-02-16 13:37:37 -08:00
|
|
|
if (ice_has_vfs(pf)) {
|
2021-08-19 17:08:48 -07:00
|
|
|
dev_info(ice_pf_to_dev(pf), "Changing eswitch mode is allowed only if there is no VFs created");
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Changing eswitch mode is allowed only if there is no VFs created");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case DEVLINK_ESWITCH_MODE_LEGACY:
|
|
|
|
dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to legacy",
|
|
|
|
pf->hw.pf_id);
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
|
|
|
|
break;
|
|
|
|
case DEVLINK_ESWITCH_MODE_SWITCHDEV:
|
|
|
|
{
|
|
|
|
dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to switchdev",
|
|
|
|
pf->hw.pf_id);
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to switchdev");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pf->eswitch_mode = mode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_mode_get - get current eswitch mode
|
|
|
|
* @devlink: pointer to devlink structure
|
|
|
|
* @mode: output parameter for current eswitch mode
|
|
|
|
*/
|
|
|
|
int ice_eswitch_mode_get(struct devlink *devlink, u16 *mode)
|
|
|
|
{
|
|
|
|
struct ice_pf *pf = devlink_priv(devlink);
|
|
|
|
|
|
|
|
*mode = pf->eswitch_mode;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-08-19 17:08:54 -07:00
|
|
|
|
2021-08-19 17:08:56 -07:00
|
|
|
/**
|
|
|
|
* ice_is_eswitch_mode_switchdev - check if eswitch mode is set to switchdev
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*
|
|
|
|
* Returns true if eswitch mode is set to DEVLINK_ESWITCH_MODE_SWITCHDEV,
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
|
|
|
bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
return pf->eswitch_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV;
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:54 -07:00
|
|
|
/**
|
|
|
|
* ice_eswitch_release - cleanup eswitch
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
void ice_eswitch_release(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_LEGACY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ice_eswitch_disable_switchdev(pf);
|
|
|
|
pf->switchdev.is_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_configure - configure eswitch
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
int ice_eswitch_configure(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_LEGACY || pf->switchdev.is_running)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
status = ice_eswitch_enable_switchdev(pf);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
pf->switchdev.is_running = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-08-19 17:08:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_start_all_tx_queues - start Tx queues of all port representors
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
static void ice_eswitch_start_all_tx_queues(struct ice_pf *pf)
|
|
|
|
{
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2021-08-19 17:08:57 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2021-08-19 17:08:57 -07:00
|
|
|
if (test_bit(ICE_DOWN, pf->state))
|
|
|
|
return;
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf) {
|
|
|
|
if (vf->repr)
|
|
|
|
ice_repr_start_tx_queues(vf->repr);
|
2021-08-19 17:08:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_stop_all_tx_queues - stop Tx queues of all port representors
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf)
|
|
|
|
{
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2021-08-19 17:08:57 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2021-08-19 17:08:57 -07:00
|
|
|
if (test_bit(ICE_DOWN, pf->state))
|
|
|
|
return;
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf) {
|
|
|
|
if (vf->repr)
|
|
|
|
ice_repr_stop_tx_queues(vf->repr);
|
2021-08-19 17:08:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_eswitch_rebuild - rebuild eswitch
|
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
|
|
|
int ice_eswitch_rebuild(struct ice_pf *pf)
|
|
|
|
{
|
|
|
|
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
ice_eswitch_napi_disable(pf);
|
|
|
|
ice_eswitch_napi_del(pf);
|
|
|
|
|
|
|
|
status = ice_eswitch_setup_env(pf);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
status = ice_eswitch_setup_reprs(pf);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
ice_eswitch_remap_rings_to_vectors(pf);
|
|
|
|
|
2021-08-06 10:49:06 +02:00
|
|
|
ice_replay_tc_fltrs(pf);
|
|
|
|
|
2021-08-19 17:08:57 -07:00
|
|
|
status = ice_vsi_open(ctrl_vsi);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
ice_eswitch_napi_enable(pf);
|
|
|
|
ice_eswitch_start_all_tx_queues(pf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|