Commit 37d318d7 authored by Aleksandr Loktionov's avatar Aleksandr Loktionov Committed by Jeff Kirsher

i40e: Remove scheduling while atomic possibility

In some occasions task held spinlock (mac_filter_hash_lock),
while being rescheduled due to admin queue mutex_lock.  The struct
i40e_spinlock asq_spinlock, which later expands to struct mutex
spinlock.  Moved i40e_aq_set_vsi_multicast_promiscuous(),
i40e_aq_set_vsi_unicast_promiscuous(),
i40e_aq_set_vsi_mc_promisc_on_vlan(), and
i40e_aq_set_vsi_uc_promisc_on_vlan() outside of atomic context.  Without
this patch there is a race condition, which might result in scheduling
while in atomic context.  The race condition is between the thread, which
holds mac_filter_hash_lock, while trying to acquire an admin queue mutex
and a thread, which already has said admin queue mutex. The thread, which
holds spinlock, fails to acquire the mutex, which causes this thread to
sleep.
Signed-off-by: default avatarArkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Signed-off-by: default avatarAleksandr Loktionov <aleksandr.loktionov@intel.com>
Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 3dbdd6c2
...@@ -1106,39 +1106,81 @@ static int i40e_quiesce_vf_pci(struct i40e_vf *vf) ...@@ -1106,39 +1106,81 @@ static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
return -EIO; return -EIO;
} }
static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi); /**
* i40e_getnum_vf_vsi_vlan_filters
* @vsi: pointer to the vsi
*
* called to get the number of VLANs offloaded on this VF
**/
static int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
{
struct i40e_mac_filter *f;
int num_vlans = 0, bkt;
hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
num_vlans++;
}
return num_vlans;
}
/** /**
* i40e_config_vf_promiscuous_mode * i40e_get_vlan_list_sync
* @vf: pointer to the VF info * @vsi: pointer to the VSI
* @vsi_id: VSI id * @num_vlans: number of VLANs in mac_filter_hash, returned to caller
* @allmulti: set MAC L2 layer multicast promiscuous enable/disable * @vlan_list: list of VLANs present in mac_filter_hash, returned to caller.
* @alluni: set MAC L2 layer unicast promiscuous enable/disable * This array is allocated here, but has to be freed in caller.
* *
* Called from the VF to configure the promiscuous mode of * Called to get number of VLANs and VLAN list present in mac_filter_hash.
* VF vsis and from the VF reset path to reset promiscuous mode.
**/ **/
static i40e_status i40e_config_vf_promiscuous_mode(struct i40e_vf *vf, static void i40e_get_vlan_list_sync(struct i40e_vsi *vsi, int *num_vlans,
u16 vsi_id, s16 **vlan_list)
bool allmulti,
bool alluni)
{ {
struct i40e_pf *pf = vf->pf;
struct i40e_hw *hw = &pf->hw;
struct i40e_mac_filter *f; struct i40e_mac_filter *f;
i40e_status aq_ret = 0; int i = 0;
struct i40e_vsi *vsi;
int bkt; int bkt;
vsi = i40e_find_vsi_from_id(pf, vsi_id); spin_lock_bh(&vsi->mac_filter_hash_lock);
if (!i40e_vc_isvalid_vsi_id(vf, vsi_id) || !vsi) *num_vlans = i40e_getnum_vf_vsi_vlan_filters(vsi);
return I40E_ERR_PARAM; *vlan_list = kcalloc(*num_vlans, sizeof(**vlan_list), GFP_ATOMIC);
if (!(*vlan_list))
goto err;
if (vf->port_vlan_id) { hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, vsi->seid, if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
allmulti, continue;
vf->port_vlan_id, (*vlan_list)[i++] = f->vlan;
NULL); }
err:
spin_unlock_bh(&vsi->mac_filter_hash_lock);
}
/**
* i40e_set_vsi_promisc
* @vf: pointer to the VF struct
* @seid: VSI number
* @multi_enable: set MAC L2 layer multicast promiscuous enable/disable
* for a given VLAN
* @unicast_enable: set MAC L2 layer unicast promiscuous enable/disable
* for a given VLAN
* @vl: List of VLANs - apply filter for given VLANs
* @num_vlans: Number of elements in @vl
**/
static i40e_status
i40e_set_vsi_promisc(struct i40e_vf *vf, u16 seid, bool multi_enable,
bool unicast_enable, s16 *vl, int num_vlans)
{
struct i40e_pf *pf = vf->pf;
struct i40e_hw *hw = &pf->hw;
i40e_status aq_ret;
int i;
/* No VLAN to set promisc on, set on VSI */
if (!num_vlans || !vl) {
aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, seid,
multi_enable,
NULL);
if (aq_ret) { if (aq_ret) {
int aq_err = pf->hw.aq.asq_last_status; int aq_err = pf->hw.aq.asq_last_status;
...@@ -1147,13 +1189,14 @@ static i40e_status i40e_config_vf_promiscuous_mode(struct i40e_vf *vf, ...@@ -1147,13 +1189,14 @@ static i40e_status i40e_config_vf_promiscuous_mode(struct i40e_vf *vf,
vf->vf_id, vf->vf_id,
i40e_stat_str(&pf->hw, aq_ret), i40e_stat_str(&pf->hw, aq_ret),
i40e_aq_str(&pf->hw, aq_err)); i40e_aq_str(&pf->hw, aq_err));
return aq_ret; return aq_ret;
} }
aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, vsi->seid, aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, seid,
alluni, unicast_enable,
vf->port_vlan_id, NULL, true);
NULL);
if (aq_ret) { if (aq_ret) {
int aq_err = pf->hw.aq.asq_last_status; int aq_err = pf->hw.aq.asq_last_status;
...@@ -1163,68 +1206,84 @@ static i40e_status i40e_config_vf_promiscuous_mode(struct i40e_vf *vf, ...@@ -1163,68 +1206,84 @@ static i40e_status i40e_config_vf_promiscuous_mode(struct i40e_vf *vf,
i40e_stat_str(&pf->hw, aq_ret), i40e_stat_str(&pf->hw, aq_ret),
i40e_aq_str(&pf->hw, aq_err)); i40e_aq_str(&pf->hw, aq_err));
} }
return aq_ret; return aq_ret;
} else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) { }
hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
continue;
aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw,
vsi->seid,
allmulti,
f->vlan,
NULL);
if (aq_ret) {
int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, for (i = 0; i < num_vlans; i++) {
"Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n", aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, seid,
f->vlan, multi_enable,
i40e_stat_str(&pf->hw, aq_ret), vl[i], NULL);
i40e_aq_str(&pf->hw, aq_err)); if (aq_ret) {
} int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev,
"VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
vf->vf_id,
i40e_stat_str(&pf->hw, aq_ret),
i40e_aq_str(&pf->hw, aq_err));
}
aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, seid,
vsi->seid, unicast_enable,
alluni, vl[i], NULL);
f->vlan, if (aq_ret) {
NULL); int aq_err = pf->hw.aq.asq_last_status;
if (aq_ret) {
int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, dev_err(&pf->pdev->dev,
"Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n", "VF %d failed to set unicast promiscuous mode err %s aq_err %s\n",
f->vlan, vf->vf_id,
i40e_stat_str(&pf->hw, aq_ret), i40e_stat_str(&pf->hw, aq_ret),
i40e_aq_str(&pf->hw, aq_err)); i40e_aq_str(&pf->hw, aq_err));
}
} }
return aq_ret;
} }
aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, allmulti, return aq_ret;
NULL); }
if (aq_ret) {
int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, /**
"VF %d failed to set multicast promiscuous mode err %s aq_err %s\n", * i40e_config_vf_promiscuous_mode
vf->vf_id, * @vf: pointer to the VF info
i40e_stat_str(&pf->hw, aq_ret), * @vsi_id: VSI id
i40e_aq_str(&pf->hw, aq_err)); * @allmulti: set MAC L2 layer multicast promiscuous enable/disable
* @alluni: set MAC L2 layer unicast promiscuous enable/disable
*
* Called from the VF to configure the promiscuous mode of
* VF vsis and from the VF reset path to reset promiscuous mode.
**/
static i40e_status i40e_config_vf_promiscuous_mode(struct i40e_vf *vf,
u16 vsi_id,
bool allmulti,
bool alluni)
{
i40e_status aq_ret = I40E_SUCCESS;
struct i40e_pf *pf = vf->pf;
struct i40e_vsi *vsi;
int num_vlans;
s16 *vl;
vsi = i40e_find_vsi_from_id(pf, vsi_id);
if (!i40e_vc_isvalid_vsi_id(vf, vsi_id) || !vsi)
return I40E_ERR_PARAM;
if (vf->port_vlan_id) {
aq_ret = i40e_set_vsi_promisc(vf, vsi->seid, allmulti,
alluni, &vf->port_vlan_id, 1);
return aq_ret; return aq_ret;
} } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
i40e_get_vlan_list_sync(vsi, &num_vlans, &vl);
aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid, alluni, if (!vl)
NULL, true); return I40E_ERR_NO_MEMORY;
if (aq_ret) {
int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, aq_ret = i40e_set_vsi_promisc(vf, vsi->seid, allmulti, alluni,
"VF %d failed to set unicast promiscuous mode err %s aq_err %s\n", vl, num_vlans);
vf->vf_id, kfree(vl);
i40e_stat_str(&pf->hw, aq_ret), return aq_ret;
i40e_aq_str(&pf->hw, aq_err));
} }
/* no VLANs to set on, set on VSI */
aq_ret = i40e_set_vsi_promisc(vf, vsi->seid, allmulti, alluni,
NULL, 0);
return aq_ret; return aq_ret;
} }
...@@ -1972,25 +2031,6 @@ static void i40e_vc_reset_vf_msg(struct i40e_vf *vf) ...@@ -1972,25 +2031,6 @@ static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
i40e_reset_vf(vf, false); i40e_reset_vf(vf, false);
} }
/**
* i40e_getnum_vf_vsi_vlan_filters
* @vsi: pointer to the vsi
*
* called to get the number of VLANs offloaded on this VF
**/
static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
{
struct i40e_mac_filter *f;
int num_vlans = 0, bkt;
hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
num_vlans++;
}
return num_vlans;
}
/** /**
* i40e_vc_config_promiscuous_mode_msg * i40e_vc_config_promiscuous_mode_msg
* @vf: pointer to the VF info * @vf: pointer to the VF info
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment