Skip to content

Commit 0384d05

Browse files
committed
Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue
Tony Nguyen says: ==================== ice: refactor mailbox overflow detection Jake Keller says: The primary motivation of this series is to cleanup and refactor the mailbox overflow detection logic such that it will work with Scalable IOV. In addition a few other minor cleanups are done while I was working on the code in the area. First, the mailbox overflow functions in ice_vf_mbx.c are refactored to store the data per-VF as an embedded structure in struct ice_vf, rather than stored separately as a fixed-size array which only works with Single Root IOV. This reduces the overall memory footprint when only a handful of VFs are used. The overflow detection functions are also cleaned up to reduce the need for multiple separate calls to determine when to report a VF as potentially malicious. Finally, the ice_is_malicious_vf function is cleaned up and moved into ice_virtchnl.c since it is not Single Root IOV specific, and thus does not belong in ice_sriov.c I could probably have done this in fewer patches, but I split pieces out to hopefully aid in reviewing the overall sequence of changes. This does cause some additional thrash as it results in intermediate versions of the refactor, but I think its worth it for making each step easier to understand. * '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue: ice: call ice_is_malicious_vf() from ice_vc_process_vf_msg() ice: move ice_is_malicious_vf() to ice_virtchnl.c ice: print message if ice_mbx_vf_state_handler returns an error ice: pass mbxdata to ice_is_malicious_vf() ice: remove unnecessary &array[0] and just use array ice: always report VF overflowing mailbox even without PF VSI ice: declare ice_vc_process_vf_msg in ice_virtchnl.h ice: initialize mailbox snapshot earlier in PF init ice: merge ice_mbx_report_malvf with ice_mbx_vf_state_handler ice: remove ice_mbx_deinit_snapshot ice: move VF overflow message count into struct ice_mbx_vf_info ice: track malicious VFs in new ice_mbx_vf_info structure ice: convert ice_mbx_clear_malvf to void and use WARN ice: re-order ice_mbx_reset_snapshot function ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 543c143 + be96815 commit 0384d05

File tree

10 files changed

+164
-297
lines changed

10 files changed

+164
-297
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,8 @@ static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf)
13931393
wake_up(&pf->aq_wait_queue);
13941394
}
13951395

1396+
#define ICE_MBX_OVERFLOW_WATERMARK 64
1397+
13961398
/**
13971399
* __ice_clean_ctrlq - helper function to clean controlq rings
13981400
* @pf: ptr to struct ice_pf
@@ -1483,6 +1485,7 @@ static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
14831485
return 0;
14841486

14851487
do {
1488+
struct ice_mbx_data data = {};
14861489
u16 opcode;
14871490
int ret;
14881491

@@ -1509,8 +1512,12 @@ static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
15091512
ice_vf_lan_overflow_event(pf, &event);
15101513
break;
15111514
case ice_mbx_opc_send_msg_to_pf:
1512-
if (!ice_is_malicious_vf(pf, &event, i, pending))
1513-
ice_vc_process_vf_msg(pf, &event);
1515+
data.num_msg_proc = i;
1516+
data.num_pending_arq = pending;
1517+
data.max_num_msgs_mbx = hw->mailboxq.num_rq_entries;
1518+
data.async_watermark_val = ICE_MBX_OVERFLOW_WATERMARK;
1519+
1520+
ice_vc_process_vf_msg(pf, &event, &data);
15141521
break;
15151522
case ice_aqc_opc_fw_logging:
15161523
ice_output_fw_log(hw, &event.desc, event.msg_buf);
@@ -3891,6 +3898,7 @@ static int ice_init_pf(struct ice_pf *pf)
38913898

38923899
mutex_init(&pf->vfs.table_lock);
38933900
hash_init(pf->vfs.table);
3901+
ice_mbx_init_snapshot(&pf->hw);
38943902

38953903
return 0;
38963904
}

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

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ void ice_free_vfs(struct ice_pf *pf)
204204
}
205205

206206
/* clear malicious info since the VF is getting released */
207-
if (ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
208-
ICE_MAX_SRIOV_VFS, vf->vf_id))
209-
dev_dbg(dev, "failed to clear malicious VF state for VF %u\n",
210-
vf->vf_id);
207+
list_del(&vf->mbx_info.list_entry);
211208

212209
mutex_unlock(&vf->cfg_lock);
213210
}
@@ -1017,7 +1014,6 @@ int ice_sriov_configure(struct pci_dev *pdev, int num_vfs)
10171014
if (!num_vfs) {
10181015
if (!pci_vfs_assigned(pdev)) {
10191016
ice_free_vfs(pf);
1020-
ice_mbx_deinit_snapshot(&pf->hw);
10211017
if (pf->lag)
10221018
ice_enable_lag(pf->lag);
10231019
return 0;
@@ -1027,15 +1023,9 @@ int ice_sriov_configure(struct pci_dev *pdev, int num_vfs)
10271023
return -EBUSY;
10281024
}
10291025

1030-
err = ice_mbx_init_snapshot(&pf->hw, num_vfs);
1031-
if (err)
1032-
return err;
1033-
10341026
err = ice_pci_sriov_ena(pf, num_vfs);
1035-
if (err) {
1036-
ice_mbx_deinit_snapshot(&pf->hw);
1027+
if (err)
10371028
return err;
1038-
}
10391029

10401030
if (pf->lag)
10411031
ice_disable_lag(pf->lag);
@@ -1787,66 +1777,3 @@ void ice_restore_all_vfs_msi_state(struct pci_dev *pdev)
17871777
}
17881778
}
17891779
}
1790-
1791-
/**
1792-
* ice_is_malicious_vf - helper function to detect a malicious VF
1793-
* @pf: ptr to struct ice_pf
1794-
* @event: pointer to the AQ event
1795-
* @num_msg_proc: the number of messages processed so far
1796-
* @num_msg_pending: the number of messages peinding in admin queue
1797-
*/
1798-
bool
1799-
ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
1800-
u16 num_msg_proc, u16 num_msg_pending)
1801-
{
1802-
s16 vf_id = le16_to_cpu(event->desc.retval);
1803-
struct device *dev = ice_pf_to_dev(pf);
1804-
struct ice_mbx_data mbxdata;
1805-
bool malvf = false;
1806-
struct ice_vf *vf;
1807-
int status;
1808-
1809-
vf = ice_get_vf_by_id(pf, vf_id);
1810-
if (!vf)
1811-
return false;
1812-
1813-
if (test_bit(ICE_VF_STATE_DIS, vf->vf_states))
1814-
goto out_put_vf;
1815-
1816-
mbxdata.num_msg_proc = num_msg_proc;
1817-
mbxdata.num_pending_arq = num_msg_pending;
1818-
mbxdata.max_num_msgs_mbx = pf->hw.mailboxq.num_rq_entries;
1819-
#define ICE_MBX_OVERFLOW_WATERMARK 64
1820-
mbxdata.async_watermark_val = ICE_MBX_OVERFLOW_WATERMARK;
1821-
1822-
/* check to see if we have a malicious VF */
1823-
status = ice_mbx_vf_state_handler(&pf->hw, &mbxdata, vf_id, &malvf);
1824-
if (status)
1825-
goto out_put_vf;
1826-
1827-
if (malvf) {
1828-
bool report_vf = false;
1829-
1830-
/* if the VF is malicious and we haven't let the user
1831-
* know about it, then let them know now
1832-
*/
1833-
status = ice_mbx_report_malvf(&pf->hw, pf->vfs.malvfs,
1834-
ICE_MAX_SRIOV_VFS, vf_id,
1835-
&report_vf);
1836-
if (status)
1837-
dev_dbg(dev, "Error reporting malicious VF\n");
1838-
1839-
if (report_vf) {
1840-
struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
1841-
1842-
if (pf_vsi)
1843-
dev_warn(dev, "VF MAC %pM on PF MAC %pM is generating asynchronous messages and may be overflowing the PF message queue. Please see the Adapter User Guide for more information\n",
1844-
&vf->dev_lan_addr[0],
1845-
pf_vsi->netdev->dev_addr);
1846-
}
1847-
}
1848-
1849-
out_put_vf:
1850-
ice_put_vf(vf);
1851-
return malvf;
1852-
}

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ int
3333
ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi);
3434

3535
void ice_free_vfs(struct ice_pf *pf);
36-
void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event);
3736
void ice_restore_all_vfs_msi_state(struct pci_dev *pdev);
38-
bool
39-
ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,
40-
u16 num_msg_proc, u16 num_msg_pending);
4137

4238
int
4339
ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
@@ -68,22 +64,11 @@ ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto);
6864
static inline void ice_process_vflr_event(struct ice_pf *pf) { }
6965
static inline void ice_free_vfs(struct ice_pf *pf) { }
7066
static inline
71-
void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event) { }
72-
static inline
7367
void ice_vf_lan_overflow_event(struct ice_pf *pf, struct ice_rq_event_info *event) { }
7468
static inline void ice_print_vfs_mdd_events(struct ice_pf *pf) { }
7569
static inline void ice_print_vf_rx_mdd_event(struct ice_vf *vf) { }
7670
static inline void ice_restore_all_vfs_msi_state(struct pci_dev *pdev) { }
7771

78-
static inline bool
79-
ice_is_malicious_vf(struct ice_pf __always_unused *pf,
80-
struct ice_rq_event_info __always_unused *event,
81-
u16 __always_unused num_msg_proc,
82-
u16 __always_unused num_msg_pending)
83-
{
84-
return false;
85-
}
86-
8772
static inline int
8873
ice_sriov_configure(struct pci_dev __always_unused *pdev,
8974
int __always_unused num_vfs)

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,22 +784,23 @@ struct ice_mbx_snap_buffer_data {
784784
u16 max_num_msgs_mbx;
785785
};
786786

787-
/* Structure to track messages sent by VFs on mailbox:
788-
* 1. vf_cntr: a counter array of VFs to track the number of
789-
* asynchronous messages sent by each VF
790-
* 2. vfcntr_len: number of entries in VF counter array
787+
/* Structure used to track a single VF's messages on the mailbox:
788+
* 1. list_entry: linked list entry node
789+
* 2. msg_count: the number of asynchronous messages sent by this VF
790+
* 3. malicious: whether this VF has been detected as malicious before
791791
*/
792-
struct ice_mbx_vf_counter {
793-
u32 *vf_cntr;
794-
u32 vfcntr_len;
792+
struct ice_mbx_vf_info {
793+
struct list_head list_entry;
794+
u32 msg_count;
795+
u8 malicious : 1;
795796
};
796797

797798
/* Structure to hold data relevant to the captured static snapshot
798799
* of the PF-VF mailbox.
799800
*/
800801
struct ice_mbx_snapshot {
801802
struct ice_mbx_snap_buffer_data mbx_buf;
802-
struct ice_mbx_vf_counter mbx_vf;
803+
struct list_head mbx_vf;
803804
};
804805

805806
/* Structure to hold data to be used for capturing or updating a

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,7 @@ 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-
if (ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
500-
ICE_MAX_SRIOV_VFS, vf->vf_id))
501-
dev_dbg(dev, "failed to clear malicious VF state for VF %u\n",
502-
vf->vf_id);
499+
ice_mbx_clear_malvf(&vf->mbx_info);
503500

504501
/* If VFs have been disabled, there is no need to reset */
505502
if (test_and_set_bit(ICE_VF_DIS, pf->state)) {
@@ -601,12 +598,10 @@ int ice_reset_vf(struct ice_vf *vf, u32 flags)
601598
struct ice_pf *pf = vf->pf;
602599
struct ice_vsi *vsi;
603600
struct device *dev;
604-
struct ice_hw *hw;
605601
int err = 0;
606602
bool rsd;
607603

608604
dev = ice_pf_to_dev(pf);
609-
hw = &pf->hw;
610605

611606
if (flags & ICE_VF_RESET_NOTIFY)
612607
ice_notify_vf_reset(vf);
@@ -705,10 +700,7 @@ int ice_reset_vf(struct ice_vf *vf, u32 flags)
705700
ice_eswitch_replay_vf_mac_rule(vf);
706701

707702
/* if the VF has been reset allow it to come up again */
708-
if (ice_mbx_clear_malvf(&hw->mbx_snapshot, pf->vfs.malvfs,
709-
ICE_MAX_SRIOV_VFS, vf->vf_id))
710-
dev_dbg(dev, "failed to clear malicious VF state for VF %u\n",
711-
vf->vf_id);
703+
ice_mbx_clear_malvf(&vf->mbx_info);
712704

713705
out_unlock:
714706
if (flags & ICE_VF_RESET_LOCK)
@@ -764,6 +756,9 @@ void ice_initialize_vf_entry(struct ice_vf *vf)
764756
ice_vf_ctrl_invalidate_vsi(vf);
765757
ice_vf_fdir_init(vf);
766758

759+
/* Initialize mailbox info for this VF */
760+
ice_mbx_init_vf_info(&pf->hw, &vf->mbx_info);
761+
767762
mutex_init(&vf->cfg_lock);
768763
}
769764

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;

0 commit comments

Comments
 (0)