openvswitch: Fix ovs_flow_key_update()
Subsystems (3)
PATCH 1/1 openvswitch: Fix ovs_flow_key_update()
ovs_flow_key_update() is called when the flow key is invalid, and it is used to update and revalidate the flow key. Commit 329f45bc4f19 ("openvswitch: add mac_proto field to the flow key") introduces mac_proto field to flow key and use it to determine whether the flow key is valid. However, the commit does not update the code path in ovs_flow_key_update() to revalidate the flow key which may cause BUG_ON() on execute_recirc(). This patch addresses the aforementioned issue.
--- net/openvswitch/flow.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/openvswitch/flow.c +9 -0
@@ -53,6 +53,8 @@#include "flow_netlink.h" #include "vport.h" +static int key_extract_mac_proto (struct sk_buff *skb); +u64 ovs_flow_used_time (unsigned long flow_jiffies) {struct timespec cur_ts;
@@ -745,6 +747,13 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)int ovs_flow_key_update (struct sk_buff *skb,struct sw_flow_key *key) { +int res; + + res =key_extract_mac_proto (skb); +if (res <0 ) +return res; + key->mac_proto = res; +return key_extract (skb, key); }
Signature · 1 line
2.7.4
Quoted 7 lines · Yi-Hung Wei
ovs_flow_key_update()is called when the flow key is invalid, and it is used to update and revalidate the flow key. Commit329f45bc4f19("openvswitch: addmac_protofield to the flow key") introducesmac_protofield to flow key and use it to determine whether the flow key is valid. However, the commit does not update the code path inovs_flow_key_update()to revalidate the flow key which may causeBUG_ON()onexecute_recirc(). This patch addresses the aforementioned issue.
Good catch.
net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 758
Quoted 11 lines
int
ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key){net/openvswitch/flow.c +7
-0+int res; + + res =key_extract_mac_proto (skb); +if (res <0 ) +return res; + key->mac_proto = res; +return key_extract (skb, key); }
But this should just reset the SW_FLOW_KEY_INVALID flag, there's no need to recompute mac_proto.
Something like this:
int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key) {
- return key_extract(skb, key);
+ int res;
+
+ res = key_extract(skb, key);
+ if (!res)
+ key->mac_proto &= ~SW_FLOW_KEY_INVALID;
+ return res;
}
Thanks,
Jiri
Quoted 30 lines · Jiri Benc
Quoted 7 lines · Yi-Hung Wei
ovs_flow_key_update()is called when the flow key is invalid, and it is used to update and revalidate the flow key. Commit329f45bc4f19("openvswitch: addmac_protofield to the flow key") introducesmac_protofield to flow key and use it to determine whether the flow key is valid. However, the commit does not update the code path inovs_flow_key_update()to revalidate the flow key which may causeBUG_ON()onexecute_recirc(). This patch addresses the aforementioned issue.Good catch.
net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 758
Quoted 11 lines
int
ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key){net/openvswitch/flow.c +7
-0+int res; + + res =key_extract_mac_proto (skb); +if (res <0 ) +return res; + key->mac_proto = res; +return key_extract (skb, key); }But this should just reset the
SW_FLOW_KEY_INVALIDflag, there's no need to recomputemac_proto.Something like this:
int
ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key){
net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 758
Quoted 8 lines
net/openvswitch/flow.c +6
-1-return key_extract (skb, key); +int res; + + res =key_extract (skb, key); +if (!res) + key->mac_proto &= ~SW_FLOW_KEY_INVALID ; +return res; }
Hi Jiri,
One case that I worry is that key_extract() currently relies on mac_proto to decide whether to process the link layer. So if we update key->mac_proto after key_extract(), wouldn't we run into a problem like the following?
If we invalidate a flow key of a L3 packet, the flow's mac_proto is like this (MAC_PROTO_NONE | SW_FLOW_KEY_INVALID), then key_extract() will process the link layer of this L3 packet since mac_proto !=MAC_PROTO_NONE?
In this case, shall we update key_extract() like this static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
/* Link layer. */
clear_vlan(key);
- if (key->mac_proto == MAC_PROTO_NONE) {
+ if (key->mac_proto & MAC_PROTO_NONE) {
if (unlikely(eth_type_vlan(skb->protocol)))
return -EINVAL;Thanks,
-Yi-Hung
Quoted 4 lines
Thanks,
Jiri
Review
Quoted 11 lines · Yi-Hung Wei
If we invalidate a flow key of a L3 packet, the flow's
mac_protois like this (MAC_PROTO_NONE|SW_FLOW_KEY_INVALID), thenkey_extract()will process the link layer of this L3 packet sincemac_proto!=MAC_PROTO_NONE?In this case, shall we update
key_extract()like this static intkey_extract(struct sk_buff *skb, struct sw_flow_key *key)/* Link layer. */ clear_vlan(key);(quoted diff) +1
-1- if (key->mac_proto == MAC_PROTO_NONE) { + if (key->mac_proto & MAC_PROTO_NONE) {
Use ovs_key_mac_proto(key) == MAC_PROTO_NONE.
Jiri