From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id AE1ED432E4
	for <public@inbox.dpdk.org>; Thu,  9 Nov 2023 12:13:11 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 9210F40267;
	Thu,  9 Nov 2023 12:13:11 +0100 (CET)
Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151])
 by mails.dpdk.org (Postfix) with ESMTP id AB4C04021F;
 Thu,  9 Nov 2023 12:13:09 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1699528390; x=1731064390;
 h=date:from:to:cc:subject:message-id:references:
 in-reply-to:mime-version;
 bh=G1XOcy7J6N3g/PHOycmNodQVd309fHGSvrGVTJS6hb0=;
 b=n+kH/+a7CW5NL0qDtaUhUre6GbmdXq6+rIiOlWRAFS8qAmGj/OGeF+LI
 s0Mh4GRFDx18bIRdBpA/PZABygB0ng5PrM8MYOsYK4Tt7Ax5CAqWSoIFP
 jDbf1PZjqoUyzEdoeJRGqKyp32S+R0b+jJAsaf19v2z19k8jTty4FPKjB
 cJO6qe8V/D7oeOX9baAYhqjYrMeLqOND0kgoRxb74mCeVLpeNO1fn4Euf
 eghRdK/f4ms7uJKrvTplBZ4xgBRKUlUUyG9lEJhPNG+1xmuq9JkYl0ewA
 B2WsmHyQD/pT2mrklo2MsJCiTMNXiKHvs3NK1aXXG3bw1NnCXks2DPDfC Q==;
X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="370166498"
X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="370166498"
Received: from fmviesa001.fm.intel.com ([10.60.135.141])
 by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 09 Nov 2023 03:13:08 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="11505177"
Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82])
 by fmviesa001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384;
 09 Nov 2023 03:13:08 -0800
Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by
 fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.2507.34; Thu, 9 Nov 2023 03:13:08 -0800
Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by
 fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.2507.34 via Frontend Transport; Thu, 9 Nov 2023 03:13:08 -0800
Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169)
 by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.1.2507.34; Thu, 9 Nov 2023 03:13:07 -0800
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=Y0J3H10rg9PzlW4k1g0/AJxcWRioyn6ZbPXFLsvDDxfxLEcA7VvjaeUoD7iVNZCOByeyGzoi9jfdclfJ/L8eNacCGThwUSCwXdnonhEmq1Wc9OvnwZFsavnNOoT7WE/ojXSBWN6KhSmfLwQNHBbcFu6Lp5x1OhQC2tNHi5tY8cEsI1HVFyiNj29QLyvp0YwxysliTWFblmRCzT99Kf9KS4TNcOWrRVQ1NetwlbBJ1YeN7hYtwcif2tVEGyIiaOw3O6xDae6ysmUzpJd+Bzy6RYovW0n5Ul27rBG12dbV1FB0A2JeD1nYG8S6DH4UodiuXvrbB4/V5QuONx71yIO64Q==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=kHxsb/SPMNFJ2N/Trt+NMyckrxc2hApfNkxfg3xaLzg=;
 b=XEoEUYcgzYBPdojKvzvUUrz9jRtsEcNu1Fi7hcoO99m2r5TLLTpEaBkMKpMtcSLldqx82udxmFiuA6bkvzbKYpXEQ38sQ42fcDYy4BkFFzW4Png+lrjoM97NCxg2wJpDOZz8sEirFcNOwNXtoufghHM+NlKQ3E1JAXIQx23/47gLUC0jBTfIh0mevwjrAmzJ/yI/uP6NLrB+b615GZHmRyIpJSMgi5NQHpt80VHettbGm/au7PPnlzb0/Cls8AUF2SMu1tKwMVLLY1Cr+KMiqAI932qRdXEqqkNJ9hhBTLNEwRdzCZVlziSK+8hiV96G8Kgf0M6hEPa+dbtmMv1rLw==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
Authentication-Results: dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=intel.com;
Received: from DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17)
 by SA1PR11MB5803.namprd11.prod.outlook.com (2603:10b6:806:23e::8) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.29; Thu, 9 Nov
 2023 11:13:06 +0000
Received: from DS0PR11MB7309.namprd11.prod.outlook.com
 ([fe80::8645:d921:ce8a:12ba]) by DS0PR11MB7309.namprd11.prod.outlook.com
 ([fe80::8645:d921:ce8a:12ba%5]) with mapi id 15.20.6954.028; Thu, 9 Nov 2023
 11:13:06 +0000
Date: Thu, 9 Nov 2023 11:13:01 +0000
From: Bruce Richardson <bruce.richardson@intel.com>
To: Mingjin Ye <mingjinx.ye@intel.com>
CC: <dev@dpdk.org>, <qiming.yang@intel.com>, <yidingx.zhou@intel.com>,
 <stable@dpdk.org>
Subject: Re: [PATCH v4] app/test: append 'allow' parameters to secondary
 processes
Message-ID: <ZUy+vWgif1vAzoTE@bricha3-MOBL.ger.corp.intel.com>
References: <20230925094240.2122544-1-mingjinx.ye@intel.com>
 <20230927034204.2279012-1-mingjinx.ye@intel.com>
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <20230927034204.2279012-1-mingjinx.ye@intel.com>
X-ClientProxiedBy: DUZPR01CA0047.eurprd01.prod.exchangelabs.com
 (2603:10a6:10:469::16) To DS0PR11MB7309.namprd11.prod.outlook.com
 (2603:10b6:8:13e::17)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|SA1PR11MB5803:EE_
X-MS-Office365-Filtering-Correlation-Id: 11b6c0c5-b2bf-456f-39a5-08dbe114d8dc
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: KljBcw0zqq1cwVTrVKc/mbsvNxZVw8O1LCQThftXMhzMj4g//ubTtMWwOxWCRDCMW1ekFrzjSMNuFutdrgyh/l2rDvANc+B+1ODM1jYZlPad91V1UtEtfCIO8X7VPmJsZGWWYJqMYqQshur5clIEyUaczv7IiyYngD6zfXyWZ1WrFRhVsV0vTYgo2b5D/0he8F0SGgRcFoa9P9PMp8An1OMzwNtbi4eYv8b9EIOnfnHcYCJDi9CQSZqR0LOUyhKcQDAGwsJOZDCPuT+DBHktuM1Br1VF15e4g312YahKs4v5AUJCfEt+we+eJZA/sJo6qSoaxsEIzFlCF4oBu1klpp8hZmoUwOVbQ2FqRkm0vGahIGxajU+TDCs2jO8g6arqOYEi9VlVErmdJIwSUi1twwK5ugMEpSRu7yDuYhBITghmubuwoswz6z9KQKGP+4qzx9y19Wybhe0QZNv4Gq8MqRHMURsmTy8fFtVNXughQQ6VSY6CZk0aHsEgzeJLzuUwqr9/1F12LXzK1RIwn0VwUOM3HiyTfAq7PlgCXbsjUnrdpYcEhZMg/l0W4a9NpVBJiaUjcbTG+m9moqb8Pm2BB1FhfQeDX2JSKxrSARlZ96g=
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE;
 SFS:(13230031)(366004)(396003)(136003)(376002)(346002)(39860400002)(230922051799003)(451199024)(186009)(1800799009)(64100799003)(6666004)(6512007)(478600001)(6486002)(6506007)(38100700002)(86362001)(82960400001)(2906002)(5660300002)(66476007)(44832011)(66946007)(66556008)(83380400001)(26005)(41300700001)(316002)(6862004)(8936002)(8676002)(6636002)(4326008)(450100002)(67856001);
 DIR:OUT; SFP:1102; 
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?NsIvlFraGXIvZWSVPEICNPBjeQrVD/3hnirD0NOkCAoH7LlmnqN2QURwHdLD?=
 =?us-ascii?Q?rSH1XfuseZvzhJuS2Pqy/gJk3ZdLlPWLidCGQdXCFKxYJiPa/U66jbWhk8Rl?=
 =?us-ascii?Q?8JEUCv9xWDC6OQhNtGi967yp5Xfjij01RPQyJpOy2vrdp2PoMBMC9YSnDqjm?=
 =?us-ascii?Q?uhewA7PU3jQq0vgxD+je57Tfs7sq609mQ/KChFfTWvAhb43sBqk2mNVJhgjo?=
 =?us-ascii?Q?++kHG7WAiYkmzz5i3nFd9r+IV4tHLoBfM5wY+za0B9bbjXh3mWhrqbKGBF8y?=
 =?us-ascii?Q?jD5FdQ9Y4ImD8lSTXt60tLn525pJH/eiWGZ/x8925qT3Zv6+7mJPivw3hBeS?=
 =?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4RVo0mSJ5gfg5jaJhyGlKCofpVCTzfvHRZG/Z7IjzA71nJLyIUSRli?=
 =?us-ascii?Q?WGzfRw+o1k8fK3zweQJfGJ9cp3OQl+WcIyNOl3Je3PPXPAY8vwfiyK9QyuFS?=
 =?us-ascii?Q?TXTvs4Cv/44r9V/qtgrzt+6gH3YPj0fMv05+jDcsNj6qKaYl6ORwE0kB12rD?=
 =?us-ascii?Q?nhnzFFwMDgKzRJYHQVIJVsgUuJNyBo7YKIkE9TDrV5bGfs+rFA+eqX6pqbya?=
 =?us-ascii?Q?uVm/sOEkNCvsmPy1g9QWCDTsRNLlBJNp9vRVhBIYYyna+EbzC3GyMyj4tpAl?=
 =?us-ascii?Q?RtllinwCGYtYtA+lQ4OC3ykWLypZ6v2/26U9PAWffOYno4phpMaJYnhJVbzE?=
 =?us-ascii?Q?7vUIt599zA0obMTSxUoxBeMYZXBoK+PebWgQR9Aolko7GJhgNp/vdPjzgdW/?=
 =?us-ascii?Q?Kw=3D=3D?=
X-MS-Exchange-CrossTenant-Network-Message-Id: 11b6c0c5-b2bf-456f-39a5-08dbe114d8dc
X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Nov 2023 11:13:05.9300 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: fx64LY1B61iImCYgKMsunOmuIEha6WJDMT4PVIQiHWVPRzzyGwUV95L4gvkeljfLsK5iEEYgIUZ/ejaaq+tV5n/u2HF00rdZsm+v/rEzNB4=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR11MB5803
X-OriginatorOrg: intel.com
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org

On Wed, Sep 27, 2023 at 03:42:04AM +0000, Mingjin Ye wrote:
> The 'allow' parameters are not passed to the secondary process, and all
> devices will be loaded by default. When the primary process specifies
> the 'allow' parameters and does not specify all devices that use the
> vfio-pci driver, the secondary process will not load the devices as
> expected, which will return incorrect test results.
> 
> This patch fixes this issue by appending the 'allow' parameters to the
> secondary process.
> 
> Fixes: 086eb64db39e ("test/pdump: add unit test for pdump library")
> Fixes: 148f963fb532 ("xen: core library changes")
> Fixes: af75078fece3 ("first public release")
> Fixes: b8d5e544e73e ("test: add procfs error message for multi-process launch")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Mingjin Ye <mingjinx.ye@intel.com>
> ---
> v4: Resolve patch conflicts and optimize code.

No issue with the idea of this fix, some impovement suggestions inline below.
Once addressed:

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

> ---
>  app/test/process.h | 60 +++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 57 insertions(+), 3 deletions(-)
> 
> diff --git a/app/test/process.h b/app/test/process.h
> index af7bc3e0de..1cdf28752e 100644
> --- a/app/test/process.h
> +++ b/app/test/process.h
> @@ -18,6 +18,8 @@
>  
>  #include <rte_string_fns.h> /* strlcpy */
>  
> +#include <rte_devargs.h>
> +
>  #ifdef RTE_EXEC_ENV_FREEBSD
>  #define self "curproc"
>  #define exe "file"
> @@ -34,6 +36,47 @@ extern uint16_t flag_for_send_pkts;
>  #endif
>  #endif
>  
> +#define PREFIX_ALLOW "--allow"
> +
> +static int
> +add_parameter_allow(char **argv, int max_capacity)
> +{
> +	struct rte_devargs *devargs;
> +	int count = 0;
> +	int name_length, data_length;
> +	char *dev;
> +	int malloc_size;
> +
> +	RTE_EAL_DEVARGS_FOREACH(NULL, devargs) {
> +		if (count >= max_capacity)

Since you need two slots for each element, you need to check that count+1 <
max_capacity.

However, a better solution is to have just one flag for each dev-args. So
instead of returning an array with e.g.

["--allow", "a8:00.0", "--allow", "b8:00.0"]

instead use the "--allow=" syntax to merge elements, returning:

["--allow=a8:00.0", "--allow=b8:00.0"]

this would make your capacity check correct.

> +			return count;
> +
> +		name_length = strlen(devargs->name);
> +		if (name_length == 0)
> +			continue;
> +
> +		if (devargs->data != NULL)
> +			data_length = strlen(devargs->data);
> +		else
> +			data_length = 0;

Minor suggestion. Rather than having an else leg here, just move the
definitions of name_length and data_length inside the loop, so you can
zero-initialize it each time.

An even simpler option might be to just use a single malloc_size variable
as you don't need the others:

	malloc_size = strlen(devargs->name) + 1;
	if (malloc_size == 0)
		continue;

	malloc_size += strlen(PREFIX_ALLOW); /* which now has the "=" */
	if (devargs->data != NULL)
		malloc_size += strlen(devargs->data)

> +
> +		malloc_size = name_length + data_length + 1;
> +		dev = malloc(malloc_size);
> +
Check for NULL return from malloc.

> +		memcpy(dev, devargs->name, name_length);
> +		if (data_length > 0)
> +			memcpy(dev + name_length, devargs->data, data_length);
> +		memset(dev + malloc_size - 1, 0, 1);
> +
> +		*(argv + count) =  strdup(PREFIX_ALLOW);
> +		count++;
> +
> +		*(argv + count) = dev;
> +		count++;
> +	}
> +	return count;
> +}
> +
>  /*
>   * launches a second copy of the test process using the given argv parameters,
>   * which should include argv[0] as the process name. To identify in the
> @@ -44,7 +87,9 @@ static inline int
>  process_dup(const char *const argv[], int numargs, const char *env_value)
>  {
>  	int num;
> -	char *argv_cpy[numargs + 1];
> +	char **argv_cpy;
> +	unsigned int allow_num;
> +	unsigned int argv_num;
>  	int i, status;
>  	char path[32];
>  #ifdef RTE_LIB_PDUMP
> @@ -58,12 +103,15 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
>  	if (pid < 0)
>  		return -1;
>  	else if (pid == 0) {
> +		allow_num = rte_devargs_type_count(RTE_DEVTYPE_ALLOWED);
> +		argv_num = numargs + allow_num * 2 + 1;
> +		argv_cpy = malloc(argv_num * sizeof(char *));
>  		/* make a copy of the arguments to be passed to exec */
>  		for (i = 0; i < numargs; i++)
>  			argv_cpy[i] = strdup(argv[i]);
> -		argv_cpy[i] = NULL;
>  		num = numargs;
> -
> +		num += add_parameter_allow(&argv_cpy[i], allow_num * 2);

If merging flags, you can remove the *2 here and in the argv_num = line.

> +		argv_cpy[argv_num - 1] = NULL;
>  #ifdef RTE_EXEC_ENV_LINUX
>  		{
>  			const char *procdir = "/proc/" self "/fd/";
> @@ -131,6 +179,12 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
>  			}
>  			rte_panic("Cannot exec: %s\n", strerror(errno));
>  		}
> +
> +		for (i = 0; i < num; i++) {
> +			if (argv_cpy[i] != NULL)
> +				free(argv_cpy[i]);
> +		}
> +		free(argv_cpy);
>  	}
>  	/* parent process does a wait */
>  #ifdef RTE_LIB_PDUMP
> -- 
> 2.25.1
>