Commit 4e4df559 authored by Jesse Brandeburg's avatar Jesse Brandeburg Committed by Tony Nguyen

virtchnl: do structure hardening

The virtchnl interface can have a bunch of "soft" defined structures
hardened by using explicit sizes for declarations, and then referring to
the enum type that uses them in a comment. None of these changes should
change any of the structure sizes.

Also, remove a duplicate line in a switch statement and let two cases
uses the same code.
Signed-off-by: default avatarJesse Brandeburg <jesse.brandeburg@intel.com>
Tested-by: default avatarMarek Szlosek <marek.szlosek@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent 43fc70a2
...@@ -214,7 +214,9 @@ enum virtchnl_vsi_type { ...@@ -214,7 +214,9 @@ enum virtchnl_vsi_type {
struct virtchnl_vsi_resource { struct virtchnl_vsi_resource {
u16 vsi_id; u16 vsi_id;
u16 num_queue_pairs; u16 num_queue_pairs;
enum virtchnl_vsi_type vsi_type;
/* see enum virtchnl_vsi_type */
s32 vsi_type;
u16 qset_handle; u16 qset_handle;
u8 default_mac_addr[ETH_ALEN]; u8 default_mac_addr[ETH_ALEN];
}; };
...@@ -303,7 +305,9 @@ struct virtchnl_rxq_info { ...@@ -303,7 +305,9 @@ struct virtchnl_rxq_info {
u8 rxdid; u8 rxdid;
u8 pad1[2]; u8 pad1[2];
u64 dma_ring_addr; u64 dma_ring_addr;
enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */
/* see enum virtchnl_rx_hsplit; deprecated with AVF 1.0 */
s32 rx_split_pos;
u32 pad2; u32 pad2;
}; };
...@@ -955,8 +959,12 @@ enum virtchnl_flow_type { ...@@ -955,8 +959,12 @@ enum virtchnl_flow_type {
struct virtchnl_filter { struct virtchnl_filter {
union virtchnl_flow_spec data; union virtchnl_flow_spec data;
union virtchnl_flow_spec mask; union virtchnl_flow_spec mask;
enum virtchnl_flow_type flow_type;
enum virtchnl_action action; /* see enum virtchnl_flow_type */
s32 flow_type;
/* see enum virtchnl_action */
s32 action;
u32 action_meta; u32 action_meta;
u8 field_flags; u8 field_flags;
u8 pad[3]; u8 pad[3];
...@@ -984,7 +992,8 @@ enum virtchnl_event_codes { ...@@ -984,7 +992,8 @@ enum virtchnl_event_codes {
#define PF_EVENT_SEVERITY_CERTAIN_DOOM 255 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255
struct virtchnl_pf_event { struct virtchnl_pf_event {
enum virtchnl_event_codes event; /* see enum virtchnl_event_codes */
s32 event;
union { union {
/* If the PF driver does not support the new speed reporting /* If the PF driver does not support the new speed reporting
* capabilities then use link_event else use link_event_adv to * capabilities then use link_event else use link_event_adv to
...@@ -997,6 +1006,7 @@ struct virtchnl_pf_event { ...@@ -997,6 +1006,7 @@ struct virtchnl_pf_event {
struct { struct {
enum virtchnl_link_speed link_speed; enum virtchnl_link_speed link_speed;
bool link_status; bool link_status;
u8 pad[3];
} link_event; } link_event;
struct { struct {
/* link_speed provided in Mbps */ /* link_speed provided in Mbps */
...@@ -1006,7 +1016,7 @@ struct virtchnl_pf_event { ...@@ -1006,7 +1016,7 @@ struct virtchnl_pf_event {
} link_event_adv; } link_event_adv;
} event_data; } event_data;
int severity; s32 severity;
}; };
VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event); VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event);
...@@ -1097,7 +1107,7 @@ enum virtchnl_rss_algorithm { ...@@ -1097,7 +1107,7 @@ enum virtchnl_rss_algorithm {
#define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \ #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \
(((hdr)->type) >> PROTO_HDR_SHIFT) (((hdr)->type) >> PROTO_HDR_SHIFT)
#define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \ #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \
((hdr)->type == ((val) >> PROTO_HDR_SHIFT)) ((hdr)->type == ((s32)((val) >> PROTO_HDR_SHIFT)))
#define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \ #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \
(VIRTCHNL_TEST_PROTO_HDR_TYPE((hdr), (val)) && \ (VIRTCHNL_TEST_PROTO_HDR_TYPE((hdr), (val)) && \
VIRTCHNL_TEST_PROTO_HDR_FIELD((hdr), (val))) VIRTCHNL_TEST_PROTO_HDR_FIELD((hdr), (val)))
...@@ -1193,7 +1203,8 @@ enum virtchnl_proto_hdr_field { ...@@ -1193,7 +1203,8 @@ enum virtchnl_proto_hdr_field {
}; };
struct virtchnl_proto_hdr { struct virtchnl_proto_hdr {
enum virtchnl_proto_hdr_type type; /* see enum virtchnl_proto_hdr_type */
s32 type;
u32 field_selector; /* a bit mask to select field for header type */ u32 field_selector; /* a bit mask to select field for header type */
u8 buffer[64]; u8 buffer[64];
/** /**
...@@ -1223,15 +1234,18 @@ VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs); ...@@ -1223,15 +1234,18 @@ VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs);
struct virtchnl_rss_cfg { struct virtchnl_rss_cfg {
struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */ struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */
enum virtchnl_rss_algorithm rss_algorithm; /* RSS algorithm type */
u8 reserved[128]; /* reserve for future */ /* see enum virtchnl_rss_algorithm; rss algorithm type */
s32 rss_algorithm;
u8 reserved[128]; /* reserve for future */
}; };
VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg); VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg);
/* action configuration for FDIR */ /* action configuration for FDIR */
struct virtchnl_filter_action { struct virtchnl_filter_action {
enum virtchnl_action type; /* see enum virtchnl_action type */
s32 type;
union { union {
/* used for queue and qgroup action */ /* used for queue and qgroup action */
struct { struct {
...@@ -1319,7 +1333,9 @@ struct virtchnl_fdir_add { ...@@ -1319,7 +1333,9 @@ struct virtchnl_fdir_add {
u16 validate_only; /* INPUT */ u16 validate_only; /* INPUT */
u32 flow_id; /* OUTPUT */ u32 flow_id; /* OUTPUT */
struct virtchnl_fdir_rule rule_cfg; /* INPUT */ struct virtchnl_fdir_rule rule_cfg; /* INPUT */
enum virtchnl_fdir_prgm_status status; /* OUTPUT */
/* see enum virtchnl_fdir_prgm_status; OUTPUT */
s32 status;
}; };
VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add); VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add);
...@@ -1332,7 +1348,9 @@ struct virtchnl_fdir_del { ...@@ -1332,7 +1348,9 @@ struct virtchnl_fdir_del {
u16 vsi_id; /* INPUT */ u16 vsi_id; /* INPUT */
u16 pad; u16 pad;
u32 flow_id; /* INPUT */ u32 flow_id; /* INPUT */
enum virtchnl_fdir_prgm_status status; /* OUTPUT */
/* see enum virtchnl_fdir_prgm_status; OUTPUT */
s32 status;
}; };
VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del); VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del);
...@@ -1351,7 +1369,7 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, ...@@ -1351,7 +1369,7 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
u8 *msg, u16 msglen) u8 *msg, u16 msglen)
{ {
bool err_msg_format = false; bool err_msg_format = false;
int valid_len = 0; u32 valid_len = 0;
/* Validate message length. */ /* Validate message length. */
switch (v_opcode) { switch (v_opcode) {
...@@ -1492,8 +1510,6 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, ...@@ -1492,8 +1510,6 @@ virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode,
case VIRTCHNL_OP_DISABLE_CHANNELS: case VIRTCHNL_OP_DISABLE_CHANNELS:
break; break;
case VIRTCHNL_OP_ADD_CLOUD_FILTER: case VIRTCHNL_OP_ADD_CLOUD_FILTER:
valid_len = sizeof(struct virtchnl_filter);
break;
case VIRTCHNL_OP_DEL_CLOUD_FILTER: case VIRTCHNL_OP_DEL_CLOUD_FILTER:
valid_len = sizeof(struct virtchnl_filter); valid_len = sizeof(struct virtchnl_filter);
break; break;
......
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