Skip to contentSkip to conversation

netlink: specs: fill in the missing ovs operations

PATCH Superseded Minxi Hou 1 participant 5 messages Nov 3 – Nov 7

Subsystems (4)

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Minxi Hou

author
#0 lore raw

v5 cover netlink: specs: fill in the missing ovs operations

The ovs specs describe get and new but not the set and del commands the kernel has registered since the families were added. This series adds them and names the attributes each handler reads. Nothing here changes how the kernel behaves.

v5:
https://lore.kernel.org/netdev/[email protected]/
- ovs_flow dump gets a request list of its own with ufid-flags. It shared the get list, which offered a key and a ufid the kernel ignores on a dump. The reply is unchanged.
- The key, actions and ufid docs no longer claim those attributes are always present, and say what the exceptions are: a ufid-identified flow sends no key or actions when the request asked for them to be left out, a dump leaves the actions out when they do not fit, and a dump ignores the ufid. The same sentences in include/uapi/linux/openvswitch.h are updated to match, since the spec text was copied from there.
- The key doc now says a get and a set need a key or a ufid, that a new request needs a key, and that a del carrying neither flushes the data path.
- The ovs_datapath new and set docs say per-cpu-pids takes effect only when the same request sets OVS_DP_F_DISPATCH_UPCALL_PER_CPU in user-features.
- The ovs_vport set doc says the vport is picked by name or by port number, names the rejections in the order the kernel checks them, and says upcall-pid is the only attribute that changes state.
- Rebased onto current net-next after the merge window.

v4:
https://lore.kernel.org/netdev/[email protected]/
- ovs_vport set lists port-no and ifindex. lookup_vport() finds a vport by name or by port number, and returns -EOPNOTSUPP as soon as it sees an ifindex, before the type or the options are looked at.
- ovs_datapath new lists masks-cache-size, per-cpu-pids and ifindex. new calls ovs_dp_change(), which reads the first two, and reads ifindex itself.
- ovs_flow get lists probe. ovs_flow_cmd_get() reads it to decide whether to log.
- The key attribute doc now says a new request needs a key even when it finds an existing flow and replaces its actions, and that a dump reads neither the key nor the ufid. A del with neither flushes the data path, and the del operation doc says so too.

v3:
https://lore.kernel.org/netdev/[email protected]/
- no change since v2.

v2:
https://lore.kernel.org/netdev/[email protected]/
- ovs_flow new lists ufid-flags and probe, which ovs_flow_cmd_new() reads.
- The commit message now says probe changes from binary to flag, and that new needs CAP_NET_ADMIN.
- The key attribute doc no longer says a key is required for every request except a dump. get, set and del accept a ufid with no key, and only a new flow needs a key. A set that replaces the actions still needs a key.

Minxi Hou (2):
netlink: specs: add ovs_flow del and set operations
netlink: specs: add ovs datapath and vport set operations

 Documentation/netlink/specs/ovs_datapath.yaml | 27 ++++++-
 Documentation/netlink/specs/ovs_flow.yaml     | 76 +++++++++++++++----
 Documentation/netlink/specs/ovs_vport.yaml    | 22 ++++++
 include/uapi/linux/openvswitch.h              | 17 +++--
 4 files changed, 123 insertions(+), 19 deletions(-)

base-commit: 7b6ab4dbc156e2f96419715130b3d5738a306c93

Signature · 1 line
2.56.0
author
#1 lore raw

PATCH v5 1/2 netlink: specs: add ovs_flow del and set operations

The ovs_flow spec described get and new only, so a YNL client could not delete or modify a flow. Both commands have been in the kernel since the family was added: del flushes the data path when a request carries neither a key nor a ufid, and set looks a flow up by key or by ufid.

List the attributes each command reads. new reads ufid-flags and probe as well as the key, so those go in its request list. new, del and set need CAP_NET_ADMIN.

A dump reads ufid-flags and nothing else. It shared the get request list, which let a client send a key and a ufid the kernel ignores, so give it a request list of its own. The reply stays the same as for get.

probe was binary while the kernel policy is NLA_FLAG. A YNL client leaves out a false flag, where it sent an empty binary attribute before.

The key and the actions docs called those attributes always present in notifications. A flow identified by a ufid sends neither when the request asked for it to be left out, and a get reply follows the same rule. A dump also leaves the actions out when they do not fit in the message.

The key doc said a key is required for every request except a dump. The kernel accepts a ufid with no key, but a get and a set need one of the two, and a set that replaces the actions needs a key. A new request needs a key, including one that finds an existing flow and replaces its actions, and a del that carries neither flushes the data path. The ufid doc says a dump ignores that attribute.

Fix the same sentences in the uapi header. The spec text was copied from there, and the two descriptions disagreed once this patch changed the spec.

---
 Documentation/netlink/specs/ovs_flow.yaml | 76 +++++++++++++++++++----
 include/uapi/linux/openvswitch.h          | 17 +++--
 2 files changed, 75 insertions(+), 18 deletions(-)
Documentation/netlink/specs/ovs_flow.yaml +63 -13
index 951837b72e1d..bbfa2c1b7466 100644
@@ -383,19 +383,27 @@ attribute-sets:
         type: nest
         nested-attributes: key-attrs
         doc: |
-          Nested attributes specifying the flow key. Always present in
-          notifications. Required for all requests (except dumps).
+          Nested attributes specifying the flow key. Present in replies and
+          notifications, except for a flow identified by a ufid when the
+          request asked for the key to be left out. A get, set or del may
+          carry a ufid instead of a key; a get and a set need one of the
+          two, and a set that replaces the actions needs a key. A new
+          request needs a key, including one that finds an existing flow and
+          replaces its actions. A dump reads neither the key nor the ufid. A
+          del that carries neither flushes the data path.
       -
         name: actions
         type: nest
         nested-attributes: action-attrs
         doc: |
           Nested attributes specifying the actions to take for packets that
-          match the key. Always present in notifications. Required for
-          OVS_FLOW_CMD_NEW requests, optional for OVS_FLOW_CMD_SET requests.  An
-          OVS_FLOW_CMD_SET without OVS_FLOW_ATTR_ACTIONS will not modify the
-          actions.  To clear the actions, an OVS_FLOW_ATTR_ACTIONS without any
-          nested attributes must be given.
+          match the key. Present in replies and notifications, except when
+          the request asked for the actions to be left out, and in a dump
+          when they do not fit in the message. Required for
+          OVS_FLOW_CMD_NEW requests, optional for OVS_FLOW_CMD_SET requests.
+          An OVS_FLOW_CMD_SET without OVS_FLOW_ATTR_ACTIONS will not modify
+          the actions. To clear the actions, an OVS_FLOW_ATTR_ACTIONS
+          without any nested attributes must be given.
       -
         name: stats
         type: binary
@@ -438,7 +446,7 @@ attribute-sets:
           are exact match bits.
       -
         name: probe
-        type: binary
+        type: flag
         doc: |
           Flow operation is a feature probe, error logging should be suppressed.
       -
@@ -448,8 +456,8 @@ attribute-sets:
           A value between 1-16 octets specifying a unique identifier for the
           flow. Causes the flow to be indexed by this value rather than the
           value of the OVS_FLOW_ATTR_KEY attribute. Optional for all
-          requests. Present in notifications if the flow was created with this
-          attribute.
+          requests. Present in notifications if the flow was created with
+          this attribute. Ignored in a dump.
         display-hint: uuid
       -
         name: ufid-flags
@@ -969,25 +977,31 @@ operations:
       doc: Get / dump OVS flow configuration and state
       value: 3
       attribute-set: flow-attrs
-      do: &flow-get-op
+      do:
         request:
           attributes:
             - key
             - ufid
             - ufid-flags
-        reply:
+            - probe
+        reply: &flow-get-reply
           attributes:
             - key
             - ufid
             - mask
             - stats
             - actions
-      dump: *flow-get-op
+      dump:
+        request:
+          attributes:
+            - ufid-flags
+        reply: *flow-get-reply
     -
       name: new
       doc: Create OVS flow configuration in a data path
       value: 1
       attribute-set: flow-attrs
+      flags: [uns-admin-perm]
       do:
         request:
           attributes:
@@ -995,6 +1009,42 @@ operations:
             - ufid
             - mask
             - actions
+            - ufid-flags
+            - probe
+    -
+      name: del
+      doc: |
+        Delete one flow, or every flow in the data path. A request with
+        neither a key nor a ufid flushes the data path.
+      value: 2
+      attribute-set: flow-attrs
+      flags: [uns-admin-perm]
+      do:
+        request:
+          attributes:
+            - key
+            - ufid
+            - ufid-flags
+            - probe
+    -
+      name: set
+      doc: |
+        Modify an existing flow. The kernel rejects the request with
+        -EINVAL when it carries neither a key nor a ufid. Replacing the
+        actions also needs a key: a ufid on its own is not enough.
+      value: 4
+      attribute-set: flow-attrs
+      flags: [uns-admin-perm]
+      do:
+        request:
+          attributes:
+            - key
+            - ufid
+            - mask
+            - actions
+            - ufid-flags
+            - clear
+            - probe
 
 mcast-groups:
   list:
include/uapi/linux/openvswitch.h +12 -5
index 440825e65837..318209873e26 100644
@@ -624,11 +624,18 @@ struct ovs_nsh_key_md1 {
 /**
  * enum ovs_flow_attr - attributes for %OVS_FLOW_* commands.
  * @OVS_FLOW_ATTR_KEY: Nested %OVS_KEY_ATTR_* attributes specifying the flow
- * key.  Always present in notifications.  Required for all requests (except
- * dumps).
+ * key.  Present in replies and notifications, except for a flow identified
+ * by a ufid when the request asked for the key to be left out.  A get, set
+ * or del may carry a ufid instead of a key; a get and a set need one of the
+ * two, and a set that replaces the actions needs a key.  A new request needs
+ * a key, including one that finds an existing flow and replaces its
+ * actions.  A dump reads neither of the two, and a del carrying neither
+ * flushes the data path.
  * @OVS_FLOW_ATTR_ACTIONS: Nested %OVS_ACTION_ATTR_* attributes specifying
- * the actions to take for packets that match the key.  Always present in
- * notifications.  Required for %OVS_FLOW_CMD_NEW requests, optional for
+ * the actions to take for packets that match the key.  Present in replies
+ * and notifications, except when the request asked for the actions to be
+ * left out, and in a dump when they do not fit in the message.  Required
+ * for %OVS_FLOW_CMD_NEW requests, optional for
  * %OVS_FLOW_CMD_SET requests.  An %OVS_FLOW_CMD_SET without
  * %OVS_FLOW_ATTR_ACTIONS will not modify the actions.  To clear the actions,
  * an %OVS_FLOW_ATTR_ACTIONS without any nested attributes must be given.
@@ -657,7 +664,7 @@ struct ovs_nsh_key_md1 {
  * identifier for the flow. Causes the flow to be indexed by this value rather
  * than the value of the %OVS_FLOW_ATTR_KEY attribute. Optional for all
  * requests. Present in notifications if the flow was created with this
- * attribute.
+ * attribute. Ignored in a dump.
  * @OVS_FLOW_ATTR_UFID_FLAGS: A 32-bit value of OR'd %OVS_UFID_F_*
  * flags that provide alternative semantics for flow installation and
  * retrieval. Optional for all requests.
Signature · 1 line
2.56.0
author
#2 lore raw

PATCH v5 2/2 netlink: specs: add ovs datapath and vport set operations

In reply to Minxi Hou

Both families register a SET command that the spec never described, so a YNL client could not change an existing datapath or vport. The datapath NEW command also gains the masks cache size, the per-cpu upcall pids and the ifindex, which its handler reads. new, del and set take CAP_NET_ADMIN, which is GENL_UNS_ADMIN_PERM in the kernel.

The datapath SET command changes the user features, the masks cache size and the per-cpu upcall pids. A request that leaves out user-features is read as zero, which clears the features set earlier. per-cpu-pids takes effect only when the same request sets OVS_DP_F_DISPATCH_UPCALL_PER_CPU in user-features; without that bit the pids are dropped and the request still succeeds. The new operation reads per-cpu-pids the same way, so its doc says so too.

The vport SET command changes the upcall pid. It finds the vport by name or by port number, and rejects an ifindex with -EOPNOTSUPP before it looks at the type or the options. A type that differs from the vport's type is rejected with -EINVAL, and options with -EOPNOTSUPP.

---
 Documentation/netlink/specs/ovs_datapath.yaml | 27 ++++++++++++++++++-
 Documentation/netlink/specs/ovs_vport.yaml    | 22 +++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
Documentation/netlink/specs/ovs_datapath.yaml +26 -1
index f7b3671991e6..8a8adf3820e6 100644
@@ -135,24 +135,49 @@ operations:
       dump: *dp-get-op
     -
       name: new
-      doc: Create new OVS data path
+      doc: |
+        Create new OVS data path. per-cpu-pids takes effect only when
+        user-features in the same request sets
+        OVS_DP_F_DISPATCH_UPCALL_PER_CPU.
       value: 1
       attribute-set: datapath
+      flags: [uns-admin-perm]
       do:
         request:
           attributes:
             - name
             - upcall-pid
             - user-features
+            - masks-cache-size
+            - per-cpu-pids
+            - ifindex
     -
       name: del
       doc: Delete existing OVS data path
       value: 2
       attribute-set: datapath
+      flags: [uns-admin-perm]
       do:
         request:
           attributes:
             - name
+    -
+      name: set
+      doc: |
+        Modify an existing OVS data path. The kernel treats a missing
+        user-features attribute as zero and clears the previously set
+        features. per-cpu-pids takes effect only when the same request
+        sets OVS_DP_F_DISPATCH_UPCALL_PER_CPU in user-features.
+      value: 4
+      attribute-set: datapath
+      flags: [uns-admin-perm]
+      do:
+        request:
+          attributes:
+            - name
+            - user-features
+            - masks-cache-size
+            - per-cpu-pids
 
 mcast-groups:
   list:
Documentation/netlink/specs/ovs_vport.yaml +22 -0
index fa975f8821b6..e3971bbab4c5 100644
@@ -128,6 +128,7 @@ operations:
       name: new
       doc: Create a new OVS vport
       attribute-set: vport
+      flags: [uns-admin-perm]
       do:
         request:
           attributes:
@@ -140,6 +141,7 @@ operations:
       name: del
       doc: Delete existing OVS vport from a data path
       attribute-set: vport
+      flags: [uns-admin-perm]
       do:
         request:
           attributes:
@@ -165,6 +167,26 @@ operations:
             - netnsid
             - upcall-stats
       dump: *vport-get-op
+    -
+      name: set
+      doc: |
+        Modify an existing OVS vport. The vport is picked by name or by
+        port number. The kernel rejects an ifindex with -EOPNOTSUPP, before
+        it looks at the type or the options. It rejects a type that differs
+        from the vport's type with -EINVAL, and rejects options with
+        -EOPNOTSUPP. The only attribute that changes state is upcall-pid.
+      value: 4
+      attribute-set: vport
+      flags: [uns-admin-perm]
+      do:
+        request:
+          attributes:
+            - name
+            - type
+            - options
+            - upcall-pid
+            - port-no
+            - ifindex
 
 mcast-groups:
   list:
Signature · 1 line
2.56.0
author
#3 lore raw
In reply to Minxi Hou

Adding the Open vSwitch maintainers, who I left off the original posting.

The series now touches include/uapi/linux/openvswitch.h, which MAINTAINERS lists under OPENVSWITCH. Earlier versions only changed the YNL specs, and that entry does not match those paths, so my CC list stayed the same and I did not rerun get_maintainer.pl after adding the header.

No change to the patches.

author
#4 lore raw
In reply to Minxi Hou

Sashiko reviewed v5 and raised four things. Answers below.

The ufid length one stands. get_ufid_len() returns 0 for a ufid shorter than 1 byte or longer than 16, and ovs_nla_get_ufid() then reports it as absent, so a del with no key and an invalid ufid does flush the data path. I will say that in the del and key docs, and give the attribute the range the kernel enforces. A new flow that carries an invalid ufid is indexed by its unmasked key instead, so the ufid doc needs the same qualification.

ifindex is u32 in the spec and signed in the kernel, and no datapath request used the attribute before this series, so it went unnoticed. v6 declares it s32 with a minimum of 0.

dont-validate is missing. These ops carry GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, so new, del and set in both specs should say so, the way fou and team do.

The last one is a real bug and it is older than this series. ovs_dp_change() stores the new features in dp->user_features before calling ovs_dp_set_upcall_portids(), and that call fails on an empty per-cpu-pids. The request returns an error with the TC_RECIRC_SHARING bit already recorded and tc_skb_ext_tc_enable() not run, so the next request that clears the bit calls tc_skb_ext_tc_disable() for an enable that never happened. The same key is shared with cls_flower. I will send a fix separately rather than mix kernel code into a spec series.