From: Jakub Kicinski <kuba@kernel.org>
To: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Cc: netdev@vger.kernel.org, dev@openvswitch.org, pshelar@ovn.org,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
ptikhomirov@virtuozzo.com, alexander.mikhalitsyn@virtuozzo.com,
avagin@google.com, brauner@kernel.org, mark.d.gray@redhat.com,
i.maximets@ovn.org, aconole@redhat.com
Subject: Re: [PATCH net-next v2 1/3] openvswitch: allow specifying ifindex of new interfaces
Date: Mon, 22 Aug 2022 18:37:15 -0700 [thread overview]
Message-ID: <20220822183715.0bf77c40@kernel.org> (raw)
In-Reply-To: <20220819153044.423233-2-andrey.zhadchenko@virtuozzo.com>
On Fri, 19 Aug 2022 18:30:42 +0300 Andrey Zhadchenko wrote:
> CRIU is preserving ifindexes of net devices after restoration. However,
> current Open vSwitch API does not allow to target ifindex, so we cannot
> correctly restore OVS configuration.
>
> Use ovs_header->dp_ifindex during OVS_DP_CMD_NEW as desired ifindex.
> Use OVS_VPORT_ATTR_IFINDEX during OVS_VPORT_CMD_NEW to specify new netdev
> ifindex.
> --- a/net/openvswitch/datapath.c
> +++ b/net/openvswitch/datapath.c
> @@ -1739,6 +1739,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
> struct vport *vport;
> struct ovs_net *ovs_net;
> int err;
> + struct ovs_header *ovs_header = info->userhdr;
>
> err = -EINVAL;
> if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
> @@ -1779,6 +1780,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
> parms.dp = dp;
> parms.port_no = OVSP_LOCAL;
> parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID];
> + parms.desired_ifindex = ovs_header->dp_ifindex;
Are you 100% sure that all user space making this call initializes
dp_ifindex to 0? There is no validation in the kernel today that
the field is not garbage as far as I can tell.
If you are sure, please add the appropriate analysis to the commit msg.
> /* So far only local changes have been made, now need the lock. */
> ovs_lock();
> @@ -2199,7 +2201,10 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
> if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
> !a[OVS_VPORT_ATTR_UPCALL_PID])
> return -EINVAL;
> - if (a[OVS_VPORT_ATTR_IFINDEX])
> +
> + parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
> +
> + if (a[OVS_VPORT_ATTR_IFINDEX] && parms.type != OVS_VPORT_TYPE_INTERNAL)
> return -EOPNOTSUPP;
>
> port_no = a[OVS_VPORT_ATTR_PORT_NO]
> @@ -2236,12 +2241,19 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
> }
>
> parms.name = nla_data(a[OVS_VPORT_ATTR_NAME]);
> - parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
> parms.options = a[OVS_VPORT_ATTR_OPTIONS];
> parms.dp = dp;
> parms.port_no = port_no;
> parms.upcall_portids = a[OVS_VPORT_ATTR_UPCALL_PID];
>
> + if (parms.type == OVS_VPORT_TYPE_INTERNAL) {
> + if (a[OVS_VPORT_ATTR_IFINDEX])
You already validated that type must be internal for ifindex
to be specified, so the outer if is unnecessary.
It's pretty common in netlink handling code to validate first
then act assuming validation has passed.
> + parms.desired_ifindex =
> + nla_get_u32(a[OVS_VPORT_ATTR_IFINDEX]);
> + else
> + parms.desired_ifindex = 0;
> + }
> +
> vport = new_vport(&parms);
> err = PTR_ERR(vport);
> if (IS_ERR(vport)) {
> diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
> index 9de5030d9801..24e1cba2f1ac 100644
> --- a/net/openvswitch/vport.h
> +++ b/net/openvswitch/vport.h
> @@ -98,6 +98,8 @@ struct vport_parms {
> enum ovs_vport_type type;
> struct nlattr *options;
>
> + int desired_ifindex;
Any chance this field would make sense somewhere else? you're adding
a 4B field between two pointers it will result in a padding.
Also you're missing kdoc for this field.
> /* For ovs_vport_alloc(). */
> struct datapath *dp;
> u16 port_no;
next prev parent reply other threads:[~2022-08-23 1:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-19 15:30 [PATCH net-next v2 0/3] openvswitch: allow specifying ifindex of new interfaces Andrey Zhadchenko
2022-08-19 15:30 ` [PATCH net-next v2 1/3] " Andrey Zhadchenko
2022-08-22 8:06 ` Christian Brauner
2022-08-23 1:37 ` Jakub Kicinski [this message]
2022-08-23 13:50 ` Andrey Zhadchenko
2022-08-23 19:15 ` Jakub Kicinski
2022-08-19 15:30 ` [PATCH net-next v2 2/3] openvswitch: fix memory leak at failed datapath creation Andrey Zhadchenko
2022-08-22 12:53 ` Aaron Conole
2022-08-23 1:38 ` Jakub Kicinski
2022-08-19 15:30 ` [PATCH net-next v2 3/3] openvswitch: add OVS_DP_ATTR_PER_CPU_PIDS to get requests Andrey Zhadchenko
2022-08-23 1:41 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220822183715.0bf77c40@kernel.org \
--to=kuba@kernel.org \
--cc=aconole@redhat.com \
--cc=alexander.mikhalitsyn@virtuozzo.com \
--cc=andrey.zhadchenko@virtuozzo.com \
--cc=avagin@google.com \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=dev@openvswitch.org \
--cc=edumazet@google.com \
--cc=i.maximets@ovn.org \
--cc=mark.d.gray@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pshelar@ovn.org \
--cc=ptikhomirov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).