[dpdk-dev] [PATCH v2] examples/client_server_mp: check port ownership
Matan Azrad
matan at mellanox.com
Sun Jul 7 07:44:55 CEST 2019
Hi Stephen
From: Stephen Hemminger
> From: Stephen Hemminger <sthemmin at microsoft.com>
>
> The mp_server would accept a port mask that included hidden (owned)
> ports and which later caused either lost packets or failed initialization.
>
> This fixes explicitly checks for ownership when parsing the port mask.
>
> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
> Signed-off-by: Stephen Hemminger <sthemmin at microsoft.com>
> ---
> v2 - fix checkpatch complains about return and else
>
> .../client_server_mp/mp_server/args.c | 35 +++++++++++++------
> 1 file changed, 24 insertions(+), 11 deletions(-)
>
> diff --git a/examples/multi_process/client_server_mp/mp_server/args.c
> b/examples/multi_process/client_server_mp/mp_server/args.c
> index b0d8d7665c85..72cb85008c39 100644
> --- a/examples/multi_process/client_server_mp/mp_server/args.c
> +++ b/examples/multi_process/client_server_mp/mp_server/args.c
> @@ -10,6 +10,7 @@
> #include <errno.h>
>
> #include <rte_memory.h>
> +#include <rte_ethdev.h>
> #include <rte_string_fns.h>
>
> #include "common.h"
> @@ -45,27 +46,39 @@ parse_portmask(uint8_t max_ports, const char
> *portmask) {
> char *end = NULL;
> unsigned long pm;
> - uint16_t count = 0;
> + uint16_t count;
>
> if (portmask == NULL || *portmask == '\0')
> return -1;
>
> /* convert parameter to a number and verify */
> pm = strtoul(portmask, &end, 16);
> - if (end == NULL || *end != '\0' || pm == 0)
> + if (end == NULL || *end != '\0' || pm > UINT16_MAX || pm == 0)
> return -1;
>
> /* loop through bits of the mask and mark ports */
> - while (pm != 0){
> - if (pm & 0x01){ /* bit is set in mask, use port */
> - if (count >= max_ports)
> - printf("WARNING: requested port %u not
> present"
> - " - ignoring\n", (unsigned)count);
> - else
> - ports->id[ports->num_ports++] = count;
> + for (count = 0; pm != 0; pm >>= 1, ++count) {
> + struct rte_eth_dev_owner owner;
> +
> + if ((pm & 0x1) == 0)
> + continue;
> +
> + if (count >= max_ports) {
> + printf("WARNING: requested port %u not present -
> ignoring\n",
> + count);
> + continue;
> + }
> + if (rte_eth_dev_owner_get(count, &owner) < 0) {
> + printf("ERROR: can not find port %u owner\n",
> count);
What if some entity will take ownership later?
If you want the app will be ownership aware:
if you sure that you want this port to be owned by this application you need to take ownership on it.
else:
the port is hidden by RTE_ETH_FOREACH_DEV if it is owned by some entity.
see how it was done in testpmd function: port_id_is_invalid().
> + return -1;
> }
> - pm = (pm >> 1);
> - count++;
> + if (owner.id != RTE_ETH_DEV_NO_OWNER) {
> + printf("ERROR: requested port %u is owned by
> device %s\n",
> + count, owner.name);
> + return -1;
> + }
> +
> + ports->id[ports->num_ports++] = count;
> }
>
> return 0;
> --
More information about the dev
mailing list