All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [lttng-dev] [PATCH urcu] fix: handle EINTR correctly in get_cpu_mask_from_sysfs
@ 2024-05-01 23:42 Benjamin Marzinski via lttng-dev
  2024-05-02 13:54 ` Mathieu Desnoyers via lttng-dev
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Marzinski via lttng-dev @ 2024-05-01 23:42 UTC (permalink / raw
  To: lttng-dev

If the read() in get_cpu_mask_from_sysfs() fails with EINTR, the code is
supposed to retry, but the while loop condition has (bytes_read > 0),
which is false when read() fails with EINTR. The result is that the code
exits the loop, having only read part of the string.

Use (bytes_read != 0) in the while loop condition instead, since the
(bytes_read < 0) case is already handled in the loop.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 src/compat-smp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/compat-smp.h b/src/compat-smp.h
index 31fa979..075a332 100644
--- a/src/compat-smp.h
+++ b/src/compat-smp.h
@@ -164,7 +164,7 @@ static inline int get_cpu_mask_from_sysfs(char *buf, size_t max_bytes, const cha
 
 		total_bytes_read += bytes_read;
 		assert(total_bytes_read <= max_bytes);
-	} while (max_bytes > total_bytes_read && bytes_read > 0);
+	} while (max_bytes > total_bytes_read && bytes_read != 0);
 
 	/*
 	 * Make sure the mask read is a null terminated string.
-- 
2.44.0

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [lttng-dev] [PATCH urcu] fix: handle EINTR correctly in get_cpu_mask_from_sysfs
  2024-05-01 23:42 [lttng-dev] [PATCH urcu] fix: handle EINTR correctly in get_cpu_mask_from_sysfs Benjamin Marzinski via lttng-dev
@ 2024-05-02 13:54 ` Mathieu Desnoyers via lttng-dev
  2024-05-02 14:32   ` Michael Jeanson via lttng-dev
  0 siblings, 1 reply; 4+ messages in thread
From: Mathieu Desnoyers via lttng-dev @ 2024-05-02 13:54 UTC (permalink / raw
  To: Benjamin Marzinski, lttng-dev, Michael Jeanson

On 2024-05-01 19:42, Benjamin Marzinski via lttng-dev wrote:
> If the read() in get_cpu_mask_from_sysfs() fails with EINTR, the code is
> supposed to retry, but the while loop condition has (bytes_read > 0),
> which is false when read() fails with EINTR. The result is that the code
> exits the loop, having only read part of the string.
> 
> Use (bytes_read != 0) in the while loop condition instead, since the
> (bytes_read < 0) case is already handled in the loop.

Thanks for the fix ! It is indeed the right thing to do.

I would like to integrate this fix into the librseq and libside
projects as well though, but I notice the the copy in liburcu
is LGPLv2.1 whereas the copy in librseq and libside are
MIT.

Michael, should we first relicense the liburcu src/compat-smp.h
implementation to MIT so it matches the license of the copies
in librseq and libside ?

Thanks,

Mathieu

> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>   src/compat-smp.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/compat-smp.h b/src/compat-smp.h
> index 31fa979..075a332 100644
> --- a/src/compat-smp.h
> +++ b/src/compat-smp.h
> @@ -164,7 +164,7 @@ static inline int get_cpu_mask_from_sysfs(char *buf, size_t max_bytes, const cha
>   
>   		total_bytes_read += bytes_read;
>   		assert(total_bytes_read <= max_bytes);
> -	} while (max_bytes > total_bytes_read && bytes_read > 0);
> +	} while (max_bytes > total_bytes_read && bytes_read != 0);
>   
>   	/*
>   	 * Make sure the mask read is a null terminated string.

-- 
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lttng-dev] [PATCH urcu] fix: handle EINTR correctly in get_cpu_mask_from_sysfs
  2024-05-02 13:54 ` Mathieu Desnoyers via lttng-dev
@ 2024-05-02 14:32   ` Michael Jeanson via lttng-dev
  2024-05-02 14:34     ` Mathieu Desnoyers via lttng-dev
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Jeanson via lttng-dev @ 2024-05-02 14:32 UTC (permalink / raw
  To: Mathieu Desnoyers, Benjamin Marzinski, lttng-dev

On 2024-05-02 09:54, Mathieu Desnoyers wrote:
> On 2024-05-01 19:42, Benjamin Marzinski via lttng-dev wrote:
>> If the read() in get_cpu_mask_from_sysfs() fails with EINTR, the code is
>> supposed to retry, but the while loop condition has (bytes_read > 0),
>> which is false when read() fails with EINTR. The result is that the code
>> exits the loop, having only read part of the string.
>>
>> Use (bytes_read != 0) in the while loop condition instead, since the
>> (bytes_read < 0) case is already handled in the loop.
> 
> Thanks for the fix ! It is indeed the right thing to do.
> 
> I would like to integrate this fix into the librseq and libside
> projects as well though, but I notice the the copy in liburcu
> is LGPLv2.1 whereas the copy in librseq and libside are
> MIT.
> 
> Michael, should we first relicense the liburcu src/compat-smp.h
> implementation to MIT so it matches the license of the copies
> in librseq and libside ?

Sure, please go ahead.

> Thanks,
> 
> Mathieu
> 
>>
>> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
>> ---
>>   src/compat-smp.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/compat-smp.h b/src/compat-smp.h
>> index 31fa979..075a332 100644
>> --- a/src/compat-smp.h
>> +++ b/src/compat-smp.h
>> @@ -164,7 +164,7 @@ static inline int get_cpu_mask_from_sysfs(char *buf, 
>> size_t max_bytes, const cha
>>           total_bytes_read += bytes_read;
>>           assert(total_bytes_read <= max_bytes);
>> -    } while (max_bytes > total_bytes_read && bytes_read > 0);
>> +    } while (max_bytes > total_bytes_read && bytes_read != 0);
>>       /*
>>        * Make sure the mask read is a null terminated string.
> 

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [lttng-dev] [PATCH urcu] fix: handle EINTR correctly in get_cpu_mask_from_sysfs
  2024-05-02 14:32   ` Michael Jeanson via lttng-dev
@ 2024-05-02 14:34     ` Mathieu Desnoyers via lttng-dev
  0 siblings, 0 replies; 4+ messages in thread
From: Mathieu Desnoyers via lttng-dev @ 2024-05-02 14:34 UTC (permalink / raw
  To: Michael Jeanson, Benjamin Marzinski, lttng-dev

On 2024-05-02 10:32, Michael Jeanson wrote:
> On 2024-05-02 09:54, Mathieu Desnoyers wrote:
>> On 2024-05-01 19:42, Benjamin Marzinski via lttng-dev wrote:
>>> If the read() in get_cpu_mask_from_sysfs() fails with EINTR, the code is
>>> supposed to retry, but the while loop condition has (bytes_read > 0),
>>> which is false when read() fails with EINTR. The result is that the code
>>> exits the loop, having only read part of the string.
>>>
>>> Use (bytes_read != 0) in the while loop condition instead, since the
>>> (bytes_read < 0) case is already handled in the loop.
>>
>> Thanks for the fix ! It is indeed the right thing to do.
>>
>> I would like to integrate this fix into the librseq and libside
>> projects as well though, but I notice the the copy in liburcu
>> is LGPLv2.1 whereas the copy in librseq and libside are
>> MIT.
>>
>> Michael, should we first relicense the liburcu src/compat-smp.h
>> implementation to MIT so it matches the license of the copies
>> in librseq and libside ?
> 
> Sure, please go ahead.

For the records, we also have a copy of this code in lttng-ust,
also under MIT license. So liburcu's copy is the only outlier
there.

Thanks,

Mathieu

> 
>> Thanks,
>>
>> Mathieu
>>
>>>
>>> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
>>> ---
>>>   src/compat-smp.h | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/compat-smp.h b/src/compat-smp.h
>>> index 31fa979..075a332 100644
>>> --- a/src/compat-smp.h
>>> +++ b/src/compat-smp.h
>>> @@ -164,7 +164,7 @@ static inline int get_cpu_mask_from_sysfs(char 
>>> *buf, size_t max_bytes, const cha
>>>           total_bytes_read += bytes_read;
>>>           assert(total_bytes_read <= max_bytes);
>>> -    } while (max_bytes > total_bytes_read && bytes_read > 0);
>>> +    } while (max_bytes > total_bytes_read && bytes_read != 0);
>>>       /*
>>>        * Make sure the mask read is a null terminated string.
>>
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-02 14:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-01 23:42 [lttng-dev] [PATCH urcu] fix: handle EINTR correctly in get_cpu_mask_from_sysfs Benjamin Marzinski via lttng-dev
2024-05-02 13:54 ` Mathieu Desnoyers via lttng-dev
2024-05-02 14:32   ` Michael Jeanson via lttng-dev
2024-05-02 14:34     ` Mathieu Desnoyers via lttng-dev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.