Skip to content

Commit 3fecdf4

Browse files
author
Herton R. Krzesinski
committed
Merge: ovs: backports P1 for 9.2
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1489 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2134560 Signed-off-by: Antoine Tenart <atenart@redhat.com> Approved-by: Jarod Wilson <jarod@redhat.com> Approved-by: Eelco Chaudron <echaudro@redhat.com> Approved-by: Marcelo Ricardo Leitner <mleitner@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 616a974 + 7c58a58 commit 3fecdf4

File tree

7 files changed

+61
-26
lines changed

7 files changed

+61
-26
lines changed

include/uapi/linux/openvswitch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ enum ovs_datapath_cmd {
7676
* datapath. Always present in notifications.
7777
* @OVS_DP_ATTR_MEGAFLOW_STATS: Statistics about mega flow masks usage for the
7878
* datapath. Always present in notifications.
79+
* @OVS_DP_ATTR_IFINDEX: Interface index for a new datapath netdev. Only
80+
* valid for %OVS_DP_CMD_NEW requests.
7981
*
8082
* These attributes follow the &struct ovs_header within the Generic Netlink
8183
* payload for %OVS_DP_* commands.
@@ -92,6 +94,7 @@ enum ovs_datapath_attr {
9294
OVS_DP_ATTR_PER_CPU_PIDS, /* Netlink PIDS to receive upcalls in
9395
* per-cpu dispatch mode
9496
*/
97+
OVS_DP_ATTR_IFINDEX,
9598
__OVS_DP_ATTR_MAX
9699
};
97100

net/openvswitch/conntrack.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
10151015
* connections which we will commit, we may need to attach
10161016
* the helper here.
10171017
*/
1018-
if (info->commit && info->helper && !nfct_help(ct)) {
1018+
if (!nf_ct_is_confirmed(ct) && info->commit &&
1019+
info->helper && !nfct_help(ct)) {
10191020
int err = __nf_ct_try_assign_helper(ct, info->ct,
10201021
GFP_ATOMIC);
10211022
if (err)
@@ -1982,7 +1983,8 @@ static int ovs_ct_limit_set_zone_limit(struct nlattr *nla_zone_limit,
19821983
} else {
19831984
struct ovs_ct_limit *ct_limit;
19841985

1985-
ct_limit = kmalloc(sizeof(*ct_limit), GFP_KERNEL);
1986+
ct_limit = kmalloc(sizeof(*ct_limit),
1987+
GFP_KERNEL_ACCOUNT);
19861988
if (!ct_limit)
19871989
return -ENOMEM;
19881990

@@ -2252,14 +2254,16 @@ static int ovs_ct_limit_cmd_get(struct sk_buff *skb, struct genl_info *info)
22522254
static const struct genl_small_ops ct_limit_genl_ops[] = {
22532255
{ .cmd = OVS_CT_LIMIT_CMD_SET,
22542256
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2255-
.flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
2256-
* privilege. */
2257+
.flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN
2258+
* privilege.
2259+
*/
22572260
.doit = ovs_ct_limit_cmd_set,
22582261
},
22592262
{ .cmd = OVS_CT_LIMIT_CMD_DEL,
22602263
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2261-
.flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
2262-
* privilege. */
2264+
.flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN
2265+
* privilege.
2266+
*/
22632267
.doit = ovs_ct_limit_cmd_del,
22642268
},
22652269
{ .cmd = OVS_CT_LIMIT_CMD_GET,

net/openvswitch/datapath.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,17 @@ void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key)
252252

253253
upcall.mru = OVS_CB(skb)->mru;
254254
error = ovs_dp_upcall(dp, skb, key, &upcall, 0);
255-
if (unlikely(error))
256-
kfree_skb(skb);
257-
else
255+
switch (error) {
256+
case 0:
257+
case -EAGAIN:
258+
case -ERESTARTSYS:
259+
case -EINTR:
258260
consume_skb(skb);
261+
break;
262+
default:
263+
kfree_skb(skb);
264+
break;
265+
}
259266
stats_counter = &stats->n_missed;
260267
goto out;
261268
}
@@ -551,8 +558,9 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
551558
out:
552559
if (err)
553560
skb_tx_error(skb);
554-
kfree_skb(user_skb);
555-
kfree_skb(nskb);
561+
consume_skb(user_skb);
562+
consume_skb(nskb);
563+
556564
return err;
557565
}
558566

@@ -1515,6 +1523,7 @@ static size_t ovs_dp_cmd_msg_size(void)
15151523
msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_megaflow_stats));
15161524
msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */
15171525
msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_MASKS_CACHE_SIZE */
1526+
msgsize += nla_total_size(sizeof(u32) * nr_cpu_ids); /* OVS_DP_ATTR_PER_CPU_PIDS */
15181527

15191528
return msgsize;
15201529
}
@@ -1526,7 +1535,8 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
15261535
struct ovs_header *ovs_header;
15271536
struct ovs_dp_stats dp_stats;
15281537
struct ovs_dp_megaflow_stats dp_megaflow_stats;
1529-
int err;
1538+
struct dp_nlsk_pids *pids = ovsl_dereference(dp->upcall_portids);
1539+
int err, pids_len;
15301540

15311541
ovs_header = genlmsg_put(skb, portid, seq, &dp_datapath_genl_family,
15321542
flags, cmd);
@@ -1556,6 +1566,12 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
15561566
ovs_flow_tbl_masks_cache_size(&dp->table)))
15571567
goto nla_put_failure;
15581568

1569+
if (dp->user_features & OVS_DP_F_DISPATCH_UPCALL_PER_CPU && pids) {
1570+
pids_len = min(pids->n_pids, nr_cpu_ids) * sizeof(u32);
1571+
if (nla_put(skb, OVS_DP_ATTR_PER_CPU_PIDS, pids_len, &pids->pids))
1572+
goto nla_put_failure;
1573+
}
1574+
15591575
genlmsg_end(skb, ovs_header);
15601576
return 0;
15611577

@@ -1779,6 +1795,8 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
17791795
parms.dp = dp;
17801796
parms.port_no = OVSP_LOCAL;
17811797
parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID];
1798+
parms.desired_ifindex = a[OVS_DP_ATTR_IFINDEX]
1799+
? nla_get_u32(a[OVS_DP_ATTR_IFINDEX]) : 0;
17821800

17831801
/* So far only local changes have been made, now need the lock. */
17841802
ovs_lock();
@@ -1802,7 +1820,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
18021820
ovs_dp_reset_user_features(skb, info);
18031821
}
18041822

1805-
goto err_unlock_and_destroy_meters;
1823+
goto err_destroy_portids;
18061824
}
18071825

18081826
err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
@@ -1817,6 +1835,8 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
18171835
ovs_notify(&dp_datapath_genl_family, reply, info);
18181836
return 0;
18191837

1838+
err_destroy_portids:
1839+
kfree(rcu_dereference_raw(dp->upcall_portids));
18201840
err_unlock_and_destroy_meters:
18211841
ovs_unlock();
18221842
ovs_meters_exit(dp);
@@ -1996,6 +2016,7 @@ static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = {
19962016
[OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 },
19972017
[OVS_DP_ATTR_MASKS_CACHE_SIZE] = NLA_POLICY_RANGE(NLA_U32, 0,
19982018
PCPU_MIN_UNIT_SIZE / sizeof(struct mask_cache_entry)),
2019+
[OVS_DP_ATTR_IFINDEX] = {.type = NLA_U32 },
19992020
};
20002021

20012022
static const struct genl_small_ops dp_datapath_genl_ops[] = {
@@ -2199,7 +2220,10 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
21992220
if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
22002221
!a[OVS_VPORT_ATTR_UPCALL_PID])
22012222
return -EINVAL;
2202-
if (a[OVS_VPORT_ATTR_IFINDEX])
2223+
2224+
parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
2225+
2226+
if (a[OVS_VPORT_ATTR_IFINDEX] && parms.type != OVS_VPORT_TYPE_INTERNAL)
22032227
return -EOPNOTSUPP;
22042228

22052229
port_no = a[OVS_VPORT_ATTR_PORT_NO]
@@ -2236,11 +2260,12 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
22362260
}
22372261

22382262
parms.name = nla_data(a[OVS_VPORT_ATTR_NAME]);
2239-
parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
22402263
parms.options = a[OVS_VPORT_ATTR_OPTIONS];
22412264
parms.dp = dp;
22422265
parms.port_no = port_no;
22432266
parms.upcall_portids = a[OVS_VPORT_ATTR_UPCALL_PID];
2267+
parms.desired_ifindex = a[OVS_VPORT_ATTR_IFINDEX]
2268+
? nla_get_u32(a[OVS_VPORT_ATTR_IFINDEX]) : 0;
22442269

22452270
vport = new_vport(&parms);
22462271
err = PTR_ERR(vport);

net/openvswitch/flow_netlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3275,7 +3275,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
32753275

32763276
/* Disallow subsequent L2.5+ set actions and mpls_pop
32773277
* actions once the last MPLS label in the packet is
3278-
* is popped as there is no check here to ensure that
3278+
* popped as there is no check here to ensure that
32793279
* the new eth type is valid and thus set actions could
32803280
* write off the end of the packet or otherwise corrupt
32813281
* it.

net/openvswitch/meter.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a)
343343
return ERR_PTR(-EINVAL);
344344

345345
/* Allocate and set up the meter before locking anything. */
346-
meter = kzalloc(struct_size(meter, bands, n_bands), GFP_KERNEL);
346+
meter = kzalloc(struct_size(meter, bands, n_bands), GFP_KERNEL_ACCOUNT);
347347
if (!meter)
348348
return ERR_PTR(-ENOMEM);
349349

@@ -687,9 +687,9 @@ static const struct genl_small_ops dp_meter_genl_ops[] = {
687687
},
688688
{ .cmd = OVS_METER_CMD_SET,
689689
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
690-
.flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
691-
* privilege.
692-
*/
690+
.flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN
691+
* privilege.
692+
*/
693693
.doit = ovs_meter_cmd_set,
694694
},
695695
{ .cmd = OVS_METER_CMD_GET,
@@ -699,9 +699,9 @@ static const struct genl_small_ops dp_meter_genl_ops[] = {
699699
},
700700
{ .cmd = OVS_METER_CMD_DEL,
701701
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
702-
.flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN
703-
* privilege.
704-
*/
702+
.flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN
703+
* privilege.
704+
*/
705705
.doit = ovs_meter_cmd_del
706706
},
707707
};

net/openvswitch/vport-internal_dev.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int internal_dev_stop(struct net_device *netdev)
6565
static void internal_dev_getinfo(struct net_device *netdev,
6666
struct ethtool_drvinfo *info)
6767
{
68-
strlcpy(info->driver, "openvswitch", sizeof(info->driver));
68+
strscpy(info->driver, "openvswitch", sizeof(info->driver));
6969
}
7070

7171
static const struct ethtool_ops internal_dev_ethtool_ops = {
@@ -147,6 +147,7 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)
147147
}
148148

149149
dev_net_set(vport->dev, ovs_dp_get_net(vport->dp));
150+
dev->ifindex = parms->desired_ifindex;
150151
internal_dev = internal_dev_priv(vport->dev);
151152
internal_dev->vport = vport;
152153

@@ -189,7 +190,7 @@ static void internal_dev_destroy(struct vport *vport)
189190
rtnl_unlock();
190191
}
191192

192-
static netdev_tx_t internal_dev_recv(struct sk_buff *skb)
193+
static int internal_dev_recv(struct sk_buff *skb)
193194
{
194195
struct net_device *netdev = skb->dev;
195196

net/openvswitch/vport.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ struct vport {
9090
* @type: New vport's type.
9191
* @options: %OVS_VPORT_ATTR_OPTIONS attribute from Netlink message, %NULL if
9292
* none was supplied.
93+
* @desired_ifindex: New vport's ifindex.
9394
* @dp: New vport's datapath.
9495
* @port_no: New vport's port number.
9596
*/
9697
struct vport_parms {
9798
const char *name;
9899
enum ovs_vport_type type;
100+
int desired_ifindex;
99101
struct nlattr *options;
100102

101103
/* For ovs_vport_alloc(). */
@@ -130,7 +132,7 @@ struct vport_ops {
130132
int (*set_options)(struct vport *, struct nlattr *);
131133
int (*get_options)(const struct vport *, struct sk_buff *);
132134

133-
netdev_tx_t (*send) (struct sk_buff *skb);
135+
int (*send)(struct sk_buff *skb);
134136
struct module *owner;
135137
struct list_head list;
136138
};

0 commit comments

Comments
 (0)