Skip to content

Commit e4eaf89

Browse files
jacob-kelleranguy11
authored andcommitted
ice: track malicious VFs in new ice_mbx_vf_info structure
Currently the PF tracks malicious VFs in a malvfs bitmap which is used by the ice_mbx_clear_malvf and ice_mbx_report_malvf functions. This bitmap is used to ensure that we only report a VF as malicious once rather than continuously spamming the event log. This mechanism of storage for the malicious indication works well enough for SR-IOV. However, it will not work with Scalable IOV. This is because Scalable IOV VFs can be allocated dynamically and might change VF ID when their underlying VSI changes. To support this, the mailbox overflow logic will need to be refactored. First, introduce a new ice_mbx_vf_info structure which will be used to store data about a VF. Embed this structure in the struct ice_vf, and ensure it gets initialized when a new VF is created. For now this only stores the malicious indicator bit. Pass a pointer to the VF's mbx_info structure instead of using a bitmap to keep track of these bits. A future change will extend this structure and the rest of the logic associated with the overflow detection. Signed-off-by: Jacob Keller <[email protected]> Reviewed-by: Michal Swiatkowski <[email protected]> Tested-by: Marek Szlosek <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 28756d9 commit e4eaf89

File tree

6 files changed

+53
-53
lines changed

6 files changed

+53
-53
lines changed

drivers/net/ethernet/intel/ice/ice_sriov.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ void ice_free_vfs(struct ice_pf *pf)
204204
}
205205

206206
/* clear malicious info since the VF is getting released */
207-
ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
208-
ICE_MAX_SRIOV_VFS, vf->vf_id);
207+
ice_mbx_clear_malvf(&hw->mbx_snapshot, vf->vf_id,
208+
&vf->mbx_info);
209209

210210
mutex_unlock(&vf->cfg_lock);
211211
}
@@ -1828,8 +1828,7 @@ ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
18281828
/* if the VF is malicious and we haven't let the user
18291829
* know about it, then let them know now
18301830
*/
1831-
status = ice_mbx_report_malvf(&pf->hw, pf->vfs.malvfs,
1832-
ICE_MAX_SRIOV_VFS, vf_id,
1831+
status = ice_mbx_report_malvf(&pf->hw, &vf->mbx_info,
18331832
&report_vf);
18341833
if (status)
18351834
dev_dbg(dev, "Error reporting malicious VF\n");

drivers/net/ethernet/intel/ice/ice_type.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,13 @@ struct ice_mbx_vf_counter {
794794
u32 vfcntr_len;
795795
};
796796

797+
/* Structure used to track a single VF's messages on the mailbox:
798+
* 1. malicious: whether this VF has been detected as malicious before
799+
*/
800+
struct ice_mbx_vf_info {
801+
u8 malicious : 1;
802+
};
803+
797804
/* Structure to hold data relevant to the captured static snapshot
798805
* of the PF-VF mailbox.
799806
*/

drivers/net/ethernet/intel/ice/ice_vf_lib.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,8 @@ void ice_reset_all_vfs(struct ice_pf *pf)
496496

497497
/* clear all malicious info if the VFs are getting reset */
498498
ice_for_each_vf(pf, bkt, vf)
499-
ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
500-
ICE_MAX_SRIOV_VFS, vf->vf_id);
499+
ice_mbx_clear_malvf(&hw->mbx_snapshot, vf->vf_id,
500+
&vf->mbx_info);
501501

502502
/* If VFs have been disabled, there is no need to reset */
503503
if (test_and_set_bit(ICE_VF_DIS, pf->state)) {
@@ -703,8 +703,7 @@ int ice_reset_vf(struct ice_vf *vf, u32 flags)
703703
ice_eswitch_replay_vf_mac_rule(vf);
704704

705705
/* if the VF has been reset allow it to come up again */
706-
ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
707-
ICE_MAX_SRIOV_VFS, vf->vf_id);
706+
ice_mbx_clear_malvf(&hw->mbx_snapshot, vf->vf_id, &vf->mbx_info);
708707

709708
out_unlock:
710709
if (flags & ICE_VF_RESET_LOCK)
@@ -760,6 +759,9 @@ void ice_initialize_vf_entry(struct ice_vf *vf)
760759
ice_vf_ctrl_invalidate_vsi(vf);
761760
ice_vf_fdir_init(vf);
762761

762+
/* Initialize mailbox info for this VF */
763+
ice_mbx_init_vf_info(&pf->hw, &vf->mbx_info);
764+
763765
mutex_init(&vf->cfg_lock);
764766
}
765767

drivers/net/ethernet/intel/ice/ice_vf_lib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ struct ice_vfs {
7474
u16 num_qps_per; /* number of queue pairs per VF */
7575
u16 num_msix_per; /* number of MSI-X vectors per VF */
7676
unsigned long last_printed_mdd_jiffies; /* MDD message rate limit */
77-
DECLARE_BITMAP(malvfs, ICE_MAX_SRIOV_VFS); /* malicious VF indicator */
7877
};
7978

8079
/* VF information structure */
@@ -105,6 +104,7 @@ struct ice_vf {
105104
DECLARE_BITMAP(rxq_ena, ICE_MAX_RSS_QS_PER_VF);
106105
struct ice_vlan port_vlan_info; /* Port VLAN ID, QoS, and TPID */
107106
struct virtchnl_vlan_caps vlan_v2_caps;
107+
struct ice_mbx_vf_info mbx_info;
108108
u8 pf_set_mac:1; /* VF MAC address set by VMM admin */
109109
u8 trusted:1;
110110
u8 spoofchk:1;

drivers/net/ethernet/intel/ice/ice_vf_mbx.c

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -345,69 +345,48 @@ ice_mbx_vf_state_handler(struct ice_hw *hw,
345345
/**
346346
* ice_mbx_report_malvf - Track and note malicious VF
347347
* @hw: pointer to the HW struct
348-
* @all_malvfs: all malicious VFs tracked by PF
349-
* @bitmap_len: length of bitmap in bits
350-
* @vf_id: relative virtual function ID of the malicious VF
348+
* @vf_info: the mailbox tracking info structure for a VF
351349
* @report_malvf: boolean to indicate if malicious VF must be reported
352350
*
353-
* This function will update a bitmap that keeps track of the malicious
354-
* VFs attached to the PF. A malicious VF must be reported only once if
355-
* discovered between VF resets or loading so the function checks
356-
* the input vf_id against the bitmap to verify if the VF has been
357-
* detected in any previous mailbox iterations.
351+
* This function updates the malicious indicator bit in the VF mailbox
352+
* tracking structure. A malicious VF must be reported only once if discovered
353+
* between VF resets or loading so the function first checks if the VF has
354+
* already been detected in any previous mailbox iterations.
358355
*/
359356
int
360-
ice_mbx_report_malvf(struct ice_hw *hw, unsigned long *all_malvfs,
361-
u16 bitmap_len, u16 vf_id, bool *report_malvf)
357+
ice_mbx_report_malvf(struct ice_hw *hw, struct ice_mbx_vf_info *vf_info,
358+
bool *report_malvf)
362359
{
363-
if (!all_malvfs || !report_malvf)
364-
return -EINVAL;
365-
366-
*report_malvf = false;
367-
368-
if (bitmap_len < hw->mbx_snapshot.mbx_vf.vfcntr_len)
360+
if (!report_malvf)
369361
return -EINVAL;
370362

371-
if (vf_id >= bitmap_len)
372-
return -EIO;
373-
374-
/* If the vf_id is found in the bitmap set bit and boolean to true */
375-
if (!test_and_set_bit(vf_id, all_malvfs))
376-
*report_malvf = true;
363+
*report_malvf = !vf_info->malicious;
364+
vf_info->malicious = 1;
377365

378366
return 0;
379367
}
380368

381369
/**
382370
* ice_mbx_clear_malvf - Clear VF bitmap and counter for VF ID
383371
* @snap: pointer to the mailbox snapshot structure
384-
* @all_malvfs: all malicious VFs tracked by PF
385-
* @bitmap_len: length of bitmap in bits
386372
* @vf_id: relative virtual function ID of the malicious VF
373+
* @vf_info: mailbox tracking structure for this VF
387374
*
388-
* In case of a VF reset, this function can be called to clear
389-
* the bit corresponding to the VF ID in the bitmap tracking all
390-
* malicious VFs attached to the PF. The function also clears the
391-
* VF counter array at the index of the VF ID. This is to ensure
392-
* that the new VF loaded is not considered malicious before going
393-
* through the overflow detection algorithm.
394-
*/
375+
* In case of a VF reset, this function shall be called to clear the VF's
376+
* current mailbox tracking state.
377+
*/
395378
void
396-
ice_mbx_clear_malvf(struct ice_mbx_snapshot *snap, unsigned long *all_malvfs,
397-
u16 bitmap_len, u16 vf_id)
379+
ice_mbx_clear_malvf(struct ice_mbx_snapshot *snap, u16 vf_id,
380+
struct ice_mbx_vf_info *vf_info)
398381
{
399-
if (WARN_ON(!snap || !all_malvfs))
400-
return;
401-
402-
if (WARN_ON(bitmap_len < snap->mbx_vf.vfcntr_len))
382+
if (WARN_ON(!snap))
403383
return;
404384

405385
/* Ensure VF ID value is not larger than bitmap or VF counter length */
406-
if (WARN_ON(vf_id >= bitmap_len || vf_id >= snap->mbx_vf.vfcntr_len))
386+
if (WARN_ON(vf_id >= snap->mbx_vf.vfcntr_len))
407387
return;
408388

409-
/* Clear VF ID bit in the bitmap tracking malicious VFs attached to PF */
410-
clear_bit(vf_id, all_malvfs);
389+
vf_info->malicious = 0;
411390

412391
/* Clear the VF counter in the mailbox snapshot structure for that VF ID.
413392
* This is to ensure that if a VF is unloaded and a new one brought back
@@ -418,6 +397,18 @@ ice_mbx_clear_malvf(struct ice_mbx_snapshot *snap, unsigned long *all_malvfs,
418397
snap->mbx_vf.vf_cntr[vf_id] = 0;
419398
}
420399

400+
/**
401+
* ice_mbx_init_vf_info - Initialize a new VF mailbox tracking info
402+
* @hw: pointer to the hardware structure
403+
* @vf_info: the mailbox tracking info structure for a VF
404+
*
405+
* Initialize a VF mailbox tracking info structure.
406+
*/
407+
void ice_mbx_init_vf_info(struct ice_hw *hw, struct ice_mbx_vf_info *vf_info)
408+
{
409+
vf_info->malicious = 0;
410+
}
411+
421412
/**
422413
* ice_mbx_init_snapshot - Initialize mailbox snapshot structure
423414
* @hw: pointer to the hardware structure

drivers/net/ethernet/intel/ice/ice_vf_mbx.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ int
2323
ice_mbx_vf_state_handler(struct ice_hw *hw, struct ice_mbx_data *mbx_data,
2424
u16 vf_id, bool *is_mal_vf);
2525
void
26-
ice_mbx_clear_malvf(struct ice_mbx_snapshot *snap, unsigned long *all_malvfs,
27-
u16 bitmap_len, u16 vf_id);
26+
ice_mbx_clear_malvf(struct ice_mbx_snapshot *snap, u16 vf_id,
27+
struct ice_mbx_vf_info *vf_info);
28+
void ice_mbx_init_vf_info(struct ice_hw *hw, struct ice_mbx_vf_info *vf_info);
2829
int ice_mbx_init_snapshot(struct ice_hw *hw, u16 vf_count);
2930
void ice_mbx_deinit_snapshot(struct ice_hw *hw);
3031
int
31-
ice_mbx_report_malvf(struct ice_hw *hw, unsigned long *all_malvfs,
32-
u16 bitmap_len, u16 vf_id, bool *report_malvf);
32+
ice_mbx_report_malvf(struct ice_hw *hw, struct ice_mbx_vf_info *vf_info,
33+
bool *report_malvf);
3334
#else /* CONFIG_PCI_IOV */
3435
static inline int
3536
ice_aq_send_msg_to_vf(struct ice_hw __always_unused *hw,

0 commit comments

Comments
 (0)