Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] Part of the commit message is wrong.
- [Low] The comment on the new ovs_dp_set_user_features() says the field
  is written with a single WRITE_ONCE() so that "a reader on the receive…

--

net: openvswitch: do not record user features when the change fails

This patch moves the store to dp->user_features in ovs_dp_change() so it
happens after the per-cpu upcall port ID update. A failed request then no
longer leaves the TC_RECIRC_SHARING bit out of step with the tc skb
extension reference. A new helper, ovs_dp_set_user_features(), keeps the
bit and the reference in step. It is used from the reset path, the
ovs_dp_cmd_new() error path and __dp_destroy().

Link: 
https://lore.kernel.org/netdev/[email protected]/

> Two of those places leaked a reference: a datapath that fails after
> ovs_dp_change() enabled the key was freed without a disable, and
> ovs_dp_reset_user_features() cleared the bit without one. The reset runs
> when an outdated user space instance sends OVS_DP_CMD_NEW for a name that
> already exists, and after it the datapath's packets no longer share the tc
> skb extension.

[Severity: Low]
Is the last sentence accurate? No packet path in net/openvswitch reads the
per-datapath OVS_DP_F_TC_RECIRC_SHARING bit. ovs_flow_key_extract() checks
only the global static key:

net/openvswitch/flow.c:ovs_flow_key_extract() {
    ...
#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
        if (tc_skb_ext_tc_enabled()) {
                tc_ext = skb_ext_find(skb, TC_SKB_EXT);
    ...
}

In net/sched/cls_api.c, tc_skb_ext_tc_enable() and tc_skb_ext_tc_disable()
increment and decrement the single global tc_skb_ext_tc key. cls_flower and
every other OVS datapath hold references to the same key.

Clearing the bit in ovs_dp_reset_user_features() drops this datapath's
reference, which used to leak. The datapath's packets still use the tc skb
extension as long as any other holder keeps the key enabled.

Could the commit message describe this as a reference counting fix rather
than a change in how this datapath handles packets?

> diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
> index 96baa2488c266..74e78a954b705 100644
> --- a/net/openvswitch/datapath.c
> +++ b/net/openvswitch/datapath.c
> @@ -1712,6 +1712,36 @@ static struct datapath *lookup_datapath(struct net 
> *net,
>       return dp ? dp : ERR_PTR(-ENODEV);
>  }
>  
> +/* Called with ovs_mutex, which every writer holds. The field is a single
> + * WRITE_ONCE() so a reader on the receive path, which takes no lock, never
> + * sees a value stitched together from two stores; this helper reads it with
> + * READ_ONCE() for the same reason. The store happens before the reference is
> + * taken or dropped, the order ovs_dp_change() used.
> + */
> +static void ovs_dp_set_user_features(struct datapath *dp, u32 features)
> +{
> +     u32 previous = READ_ONCE(dp->user_features);
> +     bool was = previous & OVS_DP_F_TC_RECIRC_SHARING;
> +     bool now = features & OVS_DP_F_TC_RECIRC_SHARING;
> +
> +     WRITE_ONCE(dp->user_features, features);

[Severity: Low]
This comment says the lockless readers are covered by this WRITE_ONCE(). Is
that true for most of them?

queue_userspace_packet() uses READ_ONCE(), which came from the earlier
series patch "net: openvswitch: read the datapath features once when
sending an upcall". These lockless readers still use plain loads:

net/openvswitch/datapath.c:ovs_dp_process_packet() {
    ...
                else if (dp->user_features & OVS_DP_F_DISPATCH_UPCALL_PER_CPU)
    ...
}

net/openvswitch/actions.c:output_userspace() {
    ...
                        else if (dp->user_features &
                                 OVS_DP_F_DISPATCH_UPCALL_PER_CPU)
    ...
}

net/openvswitch/vport.c:ovs_vport_get_upcall_portids() {
    ...
        if (vport->dp->user_features & OVS_DP_F_VPORT_PIDS)
    ...
}

The last one is reached from ovs_vport_cmd_get() and ovs_vport_cmd_dump(),
which hold only rcu_read_lock().

Under the kernel memory model, a WRITE_ONCE() that races with a plain load
is still a data race, so KCSAN could report these readers.

The patch also adds a store on a live datapath. __dp_destroy() used to
only read the field. It now writes dp->user_features through
ovs_dp_clear_recirc_sharing() while the datapath is still on the list and
its ports are still attached.

Each of these readers loads an aligned u32 once and tests one bit, so no
functional failure is expected.

Should the remaining lockless readers switch to READ_ONCE()? Otherwise,
could this comment and the @user_features kernel-doc in struct datapath be
narrowed to match what is actually marked?

[ ... ]

-- 
Sashiko AI review · 
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124145033.627044-1-houminxi%40gmail.com
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to