Skip to content

Commit c0dcaa5

Browse files
mswiatkoanguy11
authored andcommitted
ice: Allow ignoring opcodes on specific VF
Declare bitmap of allowed commands on VF. Initialize default opcodes list that should be always supported. Declare array of supported opcodes for each caps used in virtchnl code. Change allowed bitmap by setting or clearing corresponding bit to allowlist (bit set) or denylist (bit clear). Signed-off-by: Michal Swiatkowski <michal.swiatkowski@intel.com> Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 0891c89 commit c0dcaa5

6 files changed

Lines changed: 199 additions & 0 deletions

File tree

‎drivers/net/ethernet/intel/ice/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ice-y := ice_main.o \
2626
ice_fw_update.o \
2727
ice_lag.o \
2828
ice_ethtool.o
29+
ice-$(CONFIG_PCI_IOV) += ice_virtchnl_allowlist.o
2930
ice-$(CONFIG_PCI_IOV) += ice_virtchnl_pf.o ice_sriov.o ice_virtchnl_fdir.o
3031
ice-$(CONFIG_DCB) += ice_dcb.o ice_dcb_nl.o ice_dcb_lib.o
3132
ice-$(CONFIG_RFS_ACCEL) += ice_arfs.o
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (C) 2021, Intel Corporation. */
3+
4+
#include "ice_virtchnl_allowlist.h"
5+
6+
/* Purpose of this file is to share functionality to allowlist or denylist
7+
* opcodes used in PF <-> VF communication. Group of opcodes:
8+
* - default -> should be always allowed after creating VF,
9+
* default_allowlist_opcodes
10+
* - opcodes needed by VF to work correctly, but not associated with caps ->
11+
* should be allowed after successful VF resources allocation,
12+
* working_allowlist_opcodes
13+
* - opcodes needed by VF when caps are activated
14+
*
15+
* Caps that don't use new opcodes (no opcodes should be allowed):
16+
* - VIRTCHNL_VF_OFFLOAD_RSS_AQ
17+
* - VIRTCHNL_VF_OFFLOAD_RSS_REG
18+
* - VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
19+
* - VIRTCHNL_VF_OFFLOAD_CRC
20+
* - VIRTCHNL_VF_OFFLOAD_RX_POLLING
21+
* - VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
22+
* - VIRTCHNL_VF_OFFLOAD_ENCAP
23+
* - VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
24+
* - VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM
25+
* - VIRTCHNL_VF_OFFLOAD_USO
26+
*/
27+
28+
/* default opcodes to communicate with VF */
29+
static const u32 default_allowlist_opcodes[] = {
30+
VIRTCHNL_OP_GET_VF_RESOURCES, VIRTCHNL_OP_VERSION, VIRTCHNL_OP_RESET_VF,
31+
};
32+
33+
/* opcodes supported after successful VIRTCHNL_OP_GET_VF_RESOURCES */
34+
static const u32 working_allowlist_opcodes[] = {
35+
VIRTCHNL_OP_CONFIG_TX_QUEUE, VIRTCHNL_OP_CONFIG_RX_QUEUE,
36+
VIRTCHNL_OP_CONFIG_VSI_QUEUES, VIRTCHNL_OP_CONFIG_IRQ_MAP,
37+
VIRTCHNL_OP_ENABLE_QUEUES, VIRTCHNL_OP_DISABLE_QUEUES,
38+
VIRTCHNL_OP_GET_STATS, VIRTCHNL_OP_EVENT,
39+
};
40+
41+
/* VIRTCHNL_VF_OFFLOAD_L2 */
42+
static const u32 l2_allowlist_opcodes[] = {
43+
VIRTCHNL_OP_ADD_ETH_ADDR, VIRTCHNL_OP_DEL_ETH_ADDR,
44+
VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
45+
};
46+
47+
/* VIRTCHNL_VF_OFFLOAD_REQ_QUEUES */
48+
static const u32 req_queues_allowlist_opcodes[] = {
49+
VIRTCHNL_OP_REQUEST_QUEUES,
50+
};
51+
52+
/* VIRTCHNL_VF_OFFLOAD_VLAN */
53+
static const u32 vlan_allowlist_opcodes[] = {
54+
VIRTCHNL_OP_ADD_VLAN, VIRTCHNL_OP_DEL_VLAN,
55+
VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
56+
};
57+
58+
/* VIRTCHNL_VF_OFFLOAD_RSS_PF */
59+
static const u32 rss_pf_allowlist_opcodes[] = {
60+
VIRTCHNL_OP_CONFIG_RSS_KEY, VIRTCHNL_OP_CONFIG_RSS_LUT,
61+
VIRTCHNL_OP_GET_RSS_HENA_CAPS, VIRTCHNL_OP_SET_RSS_HENA,
62+
};
63+
64+
/* VIRTCHNL_VF_OFFLOAD_FDIR_PF */
65+
static const u32 fdir_pf_allowlist_opcodes[] = {
66+
VIRTCHNL_OP_ADD_FDIR_FILTER, VIRTCHNL_OP_DEL_FDIR_FILTER,
67+
};
68+
69+
struct allowlist_opcode_info {
70+
const u32 *opcodes;
71+
size_t size;
72+
};
73+
74+
#define BIT_INDEX(caps) (HWEIGHT((caps) - 1))
75+
#define ALLOW_ITEM(caps, list) \
76+
[BIT_INDEX(caps)] = { \
77+
.opcodes = list, \
78+
.size = ARRAY_SIZE(list) \
79+
}
80+
static const struct allowlist_opcode_info allowlist_opcodes[] = {
81+
ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_L2, l2_allowlist_opcodes),
82+
ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_REQ_QUEUES, req_queues_allowlist_opcodes),
83+
ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_VLAN, vlan_allowlist_opcodes),
84+
ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_RSS_PF, rss_pf_allowlist_opcodes),
85+
ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_FDIR_PF, fdir_pf_allowlist_opcodes),
86+
};
87+
88+
/**
89+
* ice_vc_is_opcode_allowed - check if this opcode is allowed on this VF
90+
* @vf: pointer to VF structure
91+
* @opcode: virtchnl opcode
92+
*
93+
* Return true if message is allowed on this VF
94+
*/
95+
bool ice_vc_is_opcode_allowed(struct ice_vf *vf, u32 opcode)
96+
{
97+
if (opcode >= VIRTCHNL_OP_MAX)
98+
return false;
99+
100+
return test_bit(opcode, vf->opcodes_allowlist);
101+
}
102+
103+
/**
104+
* ice_vc_allowlist_opcodes - allowlist selected opcodes
105+
* @vf: pointer to VF structure
106+
* @opcodes: array of opocodes to allowlist
107+
* @size: size of opcodes array
108+
*
109+
* Function should be called to allowlist opcodes on VF.
110+
*/
111+
static void
112+
ice_vc_allowlist_opcodes(struct ice_vf *vf, const u32 *opcodes, size_t size)
113+
{
114+
unsigned int i;
115+
116+
for (i = 0; i < size; i++)
117+
set_bit(opcodes[i], vf->opcodes_allowlist);
118+
}
119+
120+
/**
121+
* ice_vc_clear_allowlist - clear all allowlist opcodes
122+
* @vf: pointer to VF structure
123+
*/
124+
static void ice_vc_clear_allowlist(struct ice_vf *vf)
125+
{
126+
bitmap_zero(vf->opcodes_allowlist, VIRTCHNL_OP_MAX);
127+
}
128+
129+
/**
130+
* ice_vc_set_default_allowlist - allowlist default opcodes for VF
131+
* @vf: pointer to VF structure
132+
*/
133+
void ice_vc_set_default_allowlist(struct ice_vf *vf)
134+
{
135+
ice_vc_clear_allowlist(vf);
136+
ice_vc_allowlist_opcodes(vf, default_allowlist_opcodes,
137+
ARRAY_SIZE(default_allowlist_opcodes));
138+
}
139+
140+
/**
141+
* ice_vc_set_working_allowlist - allowlist opcodes needed to by VF to work
142+
* @vf: pointer to VF structure
143+
*
144+
* allowlist opcodes that aren't associated with specific caps, but
145+
* are needed by VF to work.
146+
*/
147+
void ice_vc_set_working_allowlist(struct ice_vf *vf)
148+
{
149+
ice_vc_allowlist_opcodes(vf, working_allowlist_opcodes,
150+
ARRAY_SIZE(working_allowlist_opcodes));
151+
}
152+
153+
/**
154+
* ice_vc_set_caps_allowlist - allowlist VF opcodes according caps
155+
* @vf: pointer to VF structure
156+
*/
157+
void ice_vc_set_caps_allowlist(struct ice_vf *vf)
158+
{
159+
unsigned long caps = vf->driver_caps;
160+
unsigned int i;
161+
162+
for_each_set_bit(i, &caps, ARRAY_SIZE(allowlist_opcodes))
163+
ice_vc_allowlist_opcodes(vf, allowlist_opcodes[i].opcodes,
164+
allowlist_opcodes[i].size);
165+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (C) 2021, Intel Corporation. */
3+
4+
#ifndef _ICE_VIRTCHNL_ALLOWLIST_H_
5+
#define _ICE_VIRTCHNL_ALLOWLIST_H_
6+
#include "ice.h"
7+
8+
bool ice_vc_is_opcode_allowed(struct ice_vf *vf, u32 opcode);
9+
10+
void ice_vc_set_default_allowlist(struct ice_vf *vf);
11+
void ice_vc_set_working_allowlist(struct ice_vf *vf);
12+
void ice_vc_set_caps_allowlist(struct ice_vf *vf);
13+
#endif /* _ICE_VIRTCHNL_ALLOWLIST_H_ */

‎drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ice_base.h"
66
#include "ice_lib.h"
77
#include "ice_fltr.h"
8+
#include "ice_virtchnl_allowlist.h"
89

910
/**
1011
* ice_validate_vf_id - helper to check if VF ID is valid
@@ -1314,6 +1315,9 @@ bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr)
13141315
ice_for_each_vf(pf, v) {
13151316
vf = &pf->vf[v];
13161317

1318+
vf->driver_caps = 0;
1319+
ice_vc_set_default_allowlist(vf);
1320+
13171321
ice_vf_fdir_exit(vf);
13181322
/* clean VF control VSI when resetting VFs since it should be
13191323
* setup only when VF creates its first FDIR rule.
@@ -1418,6 +1422,9 @@ bool ice_reset_vf(struct ice_vf *vf, bool is_vflr)
14181422
usleep_range(10, 20);
14191423
}
14201424

1425+
vf->driver_caps = 0;
1426+
ice_vc_set_default_allowlist(vf);
1427+
14211428
/* Display a warning if VF didn't manage to reset in time, but need to
14221429
* continue on with the operation.
14231430
*/
@@ -1625,6 +1632,7 @@ static void ice_set_dflt_settings_vfs(struct ice_pf *pf)
16251632
set_bit(ICE_VIRTCHNL_VF_CAP_L2, &vf->vf_caps);
16261633
vf->spoofchk = true;
16271634
vf->num_vf_qs = pf->num_qps_per_vf;
1635+
ice_vc_set_default_allowlist(vf);
16281636

16291637
/* ctrl_vsi_idx will be set to a valid value only when VF
16301638
* creates its first fdir rule.
@@ -2127,6 +2135,9 @@ static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
21272135
/* match guest capabilities */
21282136
vf->driver_caps = vfres->vf_cap_flags;
21292137

2138+
ice_vc_set_caps_allowlist(vf);
2139+
ice_vc_set_working_allowlist(vf);
2140+
21302141
set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
21312142

21322143
err:
@@ -3840,6 +3851,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
38403851
err = -EINVAL;
38413852
}
38423853

3854+
if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
3855+
ice_vc_send_msg_to_vf(vf, v_opcode,
3856+
VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
3857+
0);
3858+
return;
3859+
}
3860+
38433861
error_handler:
38443862
if (err) {
38453863
ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,

‎drivers/net/ethernet/intel/ice/ice_virtchnl_pf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct ice_vf {
103103
u16 num_vf_qs; /* num of queue configured per VF */
104104
struct ice_mdd_vf_events mdd_rx_events;
105105
struct ice_mdd_vf_events mdd_tx_events;
106+
DECLARE_BITMAP(opcodes_allowlist, VIRTCHNL_OP_MAX);
106107
};
107108

108109
#ifdef CONFIG_PCI_IOV

‎include/linux/avf/virtchnl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ enum virtchnl_ops {
139139
/* opcode 34 - 46 are reserved */
140140
VIRTCHNL_OP_ADD_FDIR_FILTER = 47,
141141
VIRTCHNL_OP_DEL_FDIR_FILTER = 48,
142+
VIRTCHNL_OP_MAX,
142143
};
143144

144145
/* These macros are used to generate compilation errors if a structure/union

0 commit comments

Comments
 (0)