[v3,2/3] eal: fix unckeck pipe

Message ID 20250402122454.2148612-3-huangdengdui@huawei.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series fix the problem of dma-perf infinite loop |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dengdui Huang April 2, 2025, 12:24 p.m. UTC
The communication pipe may be unavailable, for example,
when the lcore role is ROLE_OFF or ROLE_NON_EAL.
So check whether the pipe is available before using it.

Fixes: a95d70547c57 ("eal: factorize lcore main loop")
Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
 lib/eal/unix/eal_unix_thread.c | 3 +++
 lib/eal/windows/eal_thread.c   | 3 +++
 2 files changed, 6 insertions(+)
  

Comments

Morten Brørup April 2, 2025, 2:45 p.m. UTC | #1
> From: Dengdui Huang [mailto:huangdengdui@huawei.com]
> Sent: Wednesday, 2 April 2025 14.25
> 
> The communication pipe may be unavailable, for example,
> when the lcore role is ROLE_OFF or ROLE_NON_EAL.
> So check whether the pipe is available before using it.
> 
> Fixes: a95d70547c57 ("eal: factorize lcore main loop")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
> ---
>  lib/eal/unix/eal_unix_thread.c | 3 +++
>  lib/eal/windows/eal_thread.c   | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/lib/eal/unix/eal_unix_thread.c
> b/lib/eal/unix/eal_unix_thread.c
> index ef6cbff0ee..103571cabf 100644
> --- a/lib/eal/unix/eal_unix_thread.c
> +++ b/lib/eal/unix/eal_unix_thread.c
> @@ -17,6 +17,9 @@ eal_thread_wake_worker(unsigned int worker_id)
>  	char c = 0;
>  	int n;
> 
> +	if (m2w == 0 || w2m == 0)
> +		return -EINVAL;
> +
>  	do {
>  		n = write(m2w, &c, 1);
>  	} while (n == 0 || (n < 0 && errno == EINTR));
> diff --git a/lib/eal/windows/eal_thread.c
> b/lib/eal/windows/eal_thread.c
> index 9e3df200b9..82bb974868 100644
> --- a/lib/eal/windows/eal_thread.c
> +++ b/lib/eal/windows/eal_thread.c
> @@ -24,6 +24,9 @@ eal_thread_wake_worker(unsigned int worker_id)
>  	char c = 0;
>  	int n;
> 
> +	if (m2w == 0 || w2m == 0)
> +		return -EINVAL;
> +
>  	do {
>  		n = _write(m2w, &c, 1);
>  	} while (n == 0 || (n < 0 && errno == EINTR));
> --
> 2.33.0

This internal function eal_thread_wake_worker() is only called from rte_eal_remote_launch().
It would be better to check the lcore role there.

References:
https://elixir.bootlin.com/dpdk/v25.03-rc2/A/ident/eal_thread_wake_worker
https://elixir.bootlin.com/dpdk/v25.03-rc2/source/lib/eal/common/eal_common_launch.c#L52

Furthermore, in theory, file descriptor 0 is a valid file descriptor; if "stdin" has been closed, a newly opened file (or pipe) may be assigned file descriptor 0.
  
Dengdui Huang April 3, 2025, 8:12 a.m. UTC | #2
On 2025/4/2 22:45, Morten Brørup wrote:
>> From: Dengdui Huang [mailto:huangdengdui@huawei.com]
>> Sent: Wednesday, 2 April 2025 14.25
>>
>> The communication pipe may be unavailable, for example,
>> when the lcore role is ROLE_OFF or ROLE_NON_EAL.
>> So check whether the pipe is available before using it.
>>
>> Fixes: a95d70547c57 ("eal: factorize lcore main loop")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
>> ---
>>  lib/eal/unix/eal_unix_thread.c | 3 +++
>>  lib/eal/windows/eal_thread.c   | 3 +++
>>  2 files changed, 6 insertions(+)
>>
>> diff --git a/lib/eal/unix/eal_unix_thread.c
>> b/lib/eal/unix/eal_unix_thread.c
>> index ef6cbff0ee..103571cabf 100644
>> --- a/lib/eal/unix/eal_unix_thread.c
>> +++ b/lib/eal/unix/eal_unix_thread.c
>> @@ -17,6 +17,9 @@ eal_thread_wake_worker(unsigned int worker_id)
>>  	char c = 0;
>>  	int n;
>>
>> +	if (m2w == 0 || w2m == 0)
>> +		return -EINVAL;
>> +
>>  	do {
>>  		n = write(m2w, &c, 1);
>>  	} while (n == 0 || (n < 0 && errno == EINTR));
>> diff --git a/lib/eal/windows/eal_thread.c
>> b/lib/eal/windows/eal_thread.c
>> index 9e3df200b9..82bb974868 100644
>> --- a/lib/eal/windows/eal_thread.c
>> +++ b/lib/eal/windows/eal_thread.c
>> @@ -24,6 +24,9 @@ eal_thread_wake_worker(unsigned int worker_id)
>>  	char c = 0;
>>  	int n;
>>
>> +	if (m2w == 0 || w2m == 0)
>> +		return -EINVAL;
>> +
>>  	do {
>>  		n = _write(m2w, &c, 1);
>>  	} while (n == 0 || (n < 0 && errno == EINTR));
>> --
>> 2.33.0
> 
> This internal function eal_thread_wake_worker() is only called from rte_eal_remote_launch().
> It would be better to check the lcore role there.
> 

Is it better to check lcore roles in rte_eal_remote_launch() instead?
Only Role_RTE and Role_SERVICE lcore can be woken up through rte_eal_remote_launch().

> References:
> https://elixir.bootlin.com/dpdk/v25.03-rc2/A/ident/eal_thread_wake_worker
> https://elixir.bootlin.com/dpdk/v25.03-rc2/source/lib/eal/common/eal_common_launch.c#L52
> 
> Furthermore, in theory, file descriptor 0 is a valid file descriptor; if "stdin" has been closed, a newly opened file (or pipe) may be assigned file descriptor 0.
> 
>
  

Patch

diff --git a/lib/eal/unix/eal_unix_thread.c b/lib/eal/unix/eal_unix_thread.c
index ef6cbff0ee..103571cabf 100644
--- a/lib/eal/unix/eal_unix_thread.c
+++ b/lib/eal/unix/eal_unix_thread.c
@@ -17,6 +17,9 @@  eal_thread_wake_worker(unsigned int worker_id)
 	char c = 0;
 	int n;
 
+	if (m2w == 0 || w2m == 0)
+		return -EINVAL;
+
 	do {
 		n = write(m2w, &c, 1);
 	} while (n == 0 || (n < 0 && errno == EINTR));
diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c
index 9e3df200b9..82bb974868 100644
--- a/lib/eal/windows/eal_thread.c
+++ b/lib/eal/windows/eal_thread.c
@@ -24,6 +24,9 @@  eal_thread_wake_worker(unsigned int worker_id)
 	char c = 0;
 	int n;
 
+	if (m2w == 0 || w2m == 0)
+		return -EINVAL;
+
 	do {
 		n = _write(m2w, &c, 1);
 	} while (n == 0 || (n < 0 && errno == EINTR));