* [PATCH] util/cacheinfo: fix crash when compiling with uClibc
@ 2019-10-17 12:37 casantos
2019-10-17 12:47 ` Peter Maydell
0 siblings, 1 reply; 6+ messages in thread
From: casantos @ 2019-10-17 12:37 UTC (permalink / raw)
To: qemu-devel; +Cc: Carlos Santos
From: Carlos Santos <casantos@redhat.com>
uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
but the corresponding sysconf calls returns -1, which is a valid result,
meaning that the limit is indeterminate.
Handle this situation using the fallback values instead of crashing due
to an assertion failure.
Signed-off-by: Carlos Santos <casantos@redhat.com>
---
util/cacheinfo.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/util/cacheinfo.c b/util/cacheinfo.c
index ea6f3e99bf..d94dc6adc8 100644
--- a/util/cacheinfo.c
+++ b/util/cacheinfo.c
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
static void sys_cache_info(int *isize, int *dsize)
{
# ifdef _SC_LEVEL1_ICACHE_LINESIZE
- *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+ int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+ if (tmp_isize > 0) {
+ *isize = tmp_isize;
+ }
# endif
# ifdef _SC_LEVEL1_DCACHE_LINESIZE
- *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ if (tmp_dsize > 0) {
+ *dsize = tmp_dsize;
+ }
# endif
}
#endif /* sys_cache_info */
--
2.18.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
2019-10-17 12:37 [PATCH] util/cacheinfo: fix crash when compiling with uClibc casantos
@ 2019-10-17 12:47 ` Peter Maydell
2019-10-17 23:06 ` Carlos Santos
0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2019-10-17 12:47 UTC (permalink / raw)
To: casantos; +Cc: QEMU Developers
On Thu, 17 Oct 2019 at 13:39, <casantos@redhat.com> wrote:
>
> From: Carlos Santos <casantos@redhat.com>
>
> uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
> but the corresponding sysconf calls returns -1, which is a valid result,
> meaning that the limit is indeterminate.
>
> Handle this situation using the fallback values instead of crashing due
> to an assertion failure.
>
> Signed-off-by: Carlos Santos <casantos@redhat.com>
> ---
> util/cacheinfo.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/util/cacheinfo.c b/util/cacheinfo.c
> index ea6f3e99bf..d94dc6adc8 100644
> --- a/util/cacheinfo.c
> +++ b/util/cacheinfo.c
> @@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
> static void sys_cache_info(int *isize, int *dsize)
> {
> # ifdef _SC_LEVEL1_ICACHE_LINESIZE
> - *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
> + int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
Do we need the cast here ?
> + if (tmp_isize > 0) {
> + *isize = tmp_isize;
> + }
> # endif
> # ifdef _SC_LEVEL1_DCACHE_LINESIZE
> - *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> + int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> + if (tmp_dsize > 0) {
> + *dsize = tmp_dsize;
> + }
> # endif
> }
> #endif /* sys_cache_info */
> --
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
2019-10-17 12:47 ` Peter Maydell
@ 2019-10-17 23:06 ` Carlos Santos
2019-12-16 11:18 ` Carlos Santos
0 siblings, 1 reply; 6+ messages in thread
From: Carlos Santos @ 2019-10-17 23:06 UTC (permalink / raw)
To: Peter Maydell; +Cc: QEMU Developers
On Thu, Oct 17, 2019 at 9:47 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Thu, 17 Oct 2019 at 13:39, <casantos@redhat.com> wrote:
> >
> > From: Carlos Santos <casantos@redhat.com>
> >
> > uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
> > but the corresponding sysconf calls returns -1, which is a valid result,
> > meaning that the limit is indeterminate.
> >
> > Handle this situation using the fallback values instead of crashing due
> > to an assertion failure.
> >
> > Signed-off-by: Carlos Santos <casantos@redhat.com>
> > ---
> > util/cacheinfo.c | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/util/cacheinfo.c b/util/cacheinfo.c
> > index ea6f3e99bf..d94dc6adc8 100644
> > --- a/util/cacheinfo.c
> > +++ b/util/cacheinfo.c
> > @@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
> > static void sys_cache_info(int *isize, int *dsize)
> > {
> > # ifdef _SC_LEVEL1_ICACHE_LINESIZE
> > - *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
> > + int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
>
> Do we need the cast here ?
It's there to remind the reader that a type coercion may occur, since
sysconf() returns a long and isize is an int.
> > + if (tmp_isize > 0) {
> > + *isize = tmp_isize;
> > + }
> > # endif
> > # ifdef _SC_LEVEL1_DCACHE_LINESIZE
> > - *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> > + int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> > + if (tmp_dsize > 0) {
> > + *dsize = tmp_dsize;
> > + }
> > # endif
> > }
> > #endif /* sys_cache_info */
> > --
>
> thanks
> -- PMM
--
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
casantos@redhat.com T: +55-11-3534-6186
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
2019-10-17 23:06 ` Carlos Santos
@ 2019-12-16 11:18 ` Carlos Santos
2020-01-17 0:04 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Carlos Santos @ 2019-12-16 11:18 UTC (permalink / raw)
To: Peter Maydell; +Cc: QEMU Developers
On Thu, Oct 17, 2019 at 8:06 PM Carlos Santos <casantos@redhat.com> wrote:
>
> On Thu, Oct 17, 2019 at 9:47 AM Peter Maydell <peter.maydell@linaro.org> wrote:
> >
> > On Thu, 17 Oct 2019 at 13:39, <casantos@redhat.com> wrote:
> > >
> > > From: Carlos Santos <casantos@redhat.com>
> > >
> > > uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
> > > but the corresponding sysconf calls returns -1, which is a valid result,
> > > meaning that the limit is indeterminate.
> > >
> > > Handle this situation using the fallback values instead of crashing due
> > > to an assertion failure.
> > >
> > > Signed-off-by: Carlos Santos <casantos@redhat.com>
> > > ---
> > > util/cacheinfo.c | 10 ++++++++--
> > > 1 file changed, 8 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/util/cacheinfo.c b/util/cacheinfo.c
> > > index ea6f3e99bf..d94dc6adc8 100644
> > > --- a/util/cacheinfo.c
> > > +++ b/util/cacheinfo.c
> > > @@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
> > > static void sys_cache_info(int *isize, int *dsize)
> > > {
> > > # ifdef _SC_LEVEL1_ICACHE_LINESIZE
> > > - *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
> > > + int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
> >
> > Do we need the cast here ?
>
> It's there to remind the reader that a type coercion may occur, since
> sysconf() returns a long and isize is an int.
>
> > > + if (tmp_isize > 0) {
> > > + *isize = tmp_isize;
> > > + }
> > > # endif
> > > # ifdef _SC_LEVEL1_DCACHE_LINESIZE
> > > - *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> > > + int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> > > + if (tmp_dsize > 0) {
> > > + *dsize = tmp_dsize;
> > > + }
> > > # endif
> > > }
> > > #endif /* sys_cache_info */
> > > --
> >
> > thanks
> > -- PMM
>
> --
> Carlos Santos
> Senior Software Maintenance Engineer
> Red Hat
> casantos@redhat.com T: +55-11-3534-6186
Hi,
Any chance to have this merged for Christmas? :-)
--
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
casantos@redhat.com T: +55-11-3534-6186
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
2019-12-16 11:18 ` Carlos Santos
@ 2020-01-17 0:04 ` Richard Henderson
2020-01-20 18:26 ` Carlos Santos
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2020-01-17 0:04 UTC (permalink / raw)
To: Carlos Santos, Peter Maydell; +Cc: QEMU Developers
On 12/16/19 1:18 AM, Carlos Santos wrote:
> On Thu, Oct 17, 2019 at 8:06 PM Carlos Santos <casantos@redhat.com> wrote:
>>
>> On Thu, Oct 17, 2019 at 9:47 AM Peter Maydell <peter.maydell@linaro.org> wrote:
>>>
>>> On Thu, 17 Oct 2019 at 13:39, <casantos@redhat.com> wrote:
>>>>
>>>> From: Carlos Santos <casantos@redhat.com>
>>>>
>>>> uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
>>>> but the corresponding sysconf calls returns -1, which is a valid result,
>>>> meaning that the limit is indeterminate.
>>>>
>>>> Handle this situation using the fallback values instead of crashing due
>>>> to an assertion failure.
>>>>
>>>> Signed-off-by: Carlos Santos <casantos@redhat.com>
>>>> ---
>>>> util/cacheinfo.c | 10 ++++++++--
>>>> 1 file changed, 8 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/util/cacheinfo.c b/util/cacheinfo.c
>>>> index ea6f3e99bf..d94dc6adc8 100644
>>>> --- a/util/cacheinfo.c
>>>> +++ b/util/cacheinfo.c
>>>> @@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
>>>> static void sys_cache_info(int *isize, int *dsize)
>>>> {
>>>> # ifdef _SC_LEVEL1_ICACHE_LINESIZE
>>>> - *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
>>>> + int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
>>>
>>> Do we need the cast here ?
>>
>> It's there to remind the reader that a type coercion may occur, since
>> sysconf() returns a long and isize is an int.
>>
>>>> + if (tmp_isize > 0) {
>>>> + *isize = tmp_isize;
>>>> + }
>>>> # endif
>>>> # ifdef _SC_LEVEL1_DCACHE_LINESIZE
>>>> - *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
>>>> + int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
>>>> + if (tmp_dsize > 0) {
>>>> + *dsize = tmp_dsize;
>>>> + }
>>>> # endif
>>>> }
>>>> #endif /* sys_cache_info */
>>>> --
>>>
>>> thanks
>>> -- PMM
>>
>> --
>> Carlos Santos
>> Senior Software Maintenance Engineer
>> Red Hat
>> casantos@redhat.com T: +55-11-3534-6186
>
> Hi,
>
> Any chance to have this merged for Christmas? :-)
No, but it's queued now. ;-)
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] util/cacheinfo: fix crash when compiling with uClibc
2020-01-17 0:04 ` Richard Henderson
@ 2020-01-20 18:26 ` Carlos Santos
0 siblings, 0 replies; 6+ messages in thread
From: Carlos Santos @ 2020-01-20 18:26 UTC (permalink / raw)
To: Richard Henderson; +Cc: Peter Maydell, QEMU Developers
On Thu, Jan 16, 2020 at 9:04 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 12/16/19 1:18 AM, Carlos Santos wrote:
> > On Thu, Oct 17, 2019 at 8:06 PM Carlos Santos <casantos@redhat.com> wrote:
> >>
> >> On Thu, Oct 17, 2019 at 9:47 AM Peter Maydell <peter.maydell@linaro.org> wrote:
> >>>
> >>> On Thu, 17 Oct 2019 at 13:39, <casantos@redhat.com> wrote:
> >>>>
> >>>> From: Carlos Santos <casantos@redhat.com>
> >>>>
> >>>> uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE
> >>>> but the corresponding sysconf calls returns -1, which is a valid result,
> >>>> meaning that the limit is indeterminate.
> >>>>
> >>>> Handle this situation using the fallback values instead of crashing due
> >>>> to an assertion failure.
> >>>>
> >>>> Signed-off-by: Carlos Santos <casantos@redhat.com>
> >>>> ---
> >>>> util/cacheinfo.c | 10 ++++++++--
> >>>> 1 file changed, 8 insertions(+), 2 deletions(-)
> >>>>
> >>>> diff --git a/util/cacheinfo.c b/util/cacheinfo.c
> >>>> index ea6f3e99bf..d94dc6adc8 100644
> >>>> --- a/util/cacheinfo.c
> >>>> +++ b/util/cacheinfo.c
> >>>> @@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
> >>>> static void sys_cache_info(int *isize, int *dsize)
> >>>> {
> >>>> # ifdef _SC_LEVEL1_ICACHE_LINESIZE
> >>>> - *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
> >>>> + int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
> >>>
> >>> Do we need the cast here ?
> >>
> >> It's there to remind the reader that a type coercion may occur, since
> >> sysconf() returns a long and isize is an int.
> >>
> >>>> + if (tmp_isize > 0) {
> >>>> + *isize = tmp_isize;
> >>>> + }
> >>>> # endif
> >>>> # ifdef _SC_LEVEL1_DCACHE_LINESIZE
> >>>> - *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> >>>> + int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
> >>>> + if (tmp_dsize > 0) {
> >>>> + *dsize = tmp_dsize;
> >>>> + }
> >>>> # endif
> >>>> }
> >>>> #endif /* sys_cache_info */
> >>>> --
> >>>
> >>> thanks
> >>> -- PMM
> >>
> >> --
> >> Carlos Santos
> >> Senior Software Maintenance Engineer
> >> Red Hat
> >> casantos@redhat.com T: +55-11-3534-6186
> >
> > Hi,
> >
> > Any chance to have this merged for Christmas? :-)
>
> No, but it's queued now. ;-)
>
>
> r~
>
Ah, Easter, perhaps. :-)
--
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
casantos@redhat.com T: +55-11-3534-6186
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-01-20 18:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17 12:37 [PATCH] util/cacheinfo: fix crash when compiling with uClibc casantos
2019-10-17 12:47 ` Peter Maydell
2019-10-17 23:06 ` Carlos Santos
2019-12-16 11:18 ` Carlos Santos
2020-01-17 0:04 ` Richard Henderson
2020-01-20 18:26 ` Carlos Santos
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).