mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC] Coverity 1128445 - Reliance on integer endianness
@ 2013-11-12 14:19 Geyslan Gregório Bem
  2013-11-12 14:30 ` Peter Zijlstra
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Geyslan Gregório Bem @ 2013-11-12 14:19 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, Ingo Molnar, acme; +Cc: kernel-br, LKML

Hi,

Coverity detected in 'arch/x86/kernel/cpu/perf_event_intel_uncore.c' a
possible reliance on integer endianness. Is that a positive one?

static u64 ivt_uncore_irp_read_counter(struct intel_uncore_box *box,
struct perf_event *event)
1369{
1370        struct pci_dev *pdev = box->pci_dev;
1371        struct hw_perf_event *hwc = &event->hw;
1372        u64 count = 0;
1373

CID 1128445 (#1 of 1): Reliance on integer endianness
(INCOMPATIBLE_CAST)incompatible_cast: Pointer "&count" points to an
object whose effective type is "unsigned long long" (64 bits,
unsigned) but is dereferenced as a narrower "unsigned int" (32 bits,
unsigned). This may lead to unexpected results depending on machine
endianness.[show details]

1374        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx],
(u32 *)&count);
1375        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx]
+ 4, (u32 *)&count + 1);
1376
1377        return count;
1378}

-- 
Regards,

Geyslan G. Bem
hackingbits.com

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

* Re: [RFC] Coverity 1128445 - Reliance on integer endianness
  2013-11-12 14:19 [RFC] Coverity 1128445 - Reliance on integer endianness Geyslan Gregório Bem
@ 2013-11-12 14:30 ` Peter Zijlstra
  2013-11-12 14:33 ` Peter Zijlstra
  2013-11-12 14:36 ` Måns Rullgård
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Zijlstra @ 2013-11-12 14:30 UTC (permalink / raw)
  To: Geyslan Gregório Bem; +Cc: paulus, Ingo Molnar, acme, kernel-br, LKML

On Tue, Nov 12, 2013 at 12:19:13PM -0200, Geyslan Gregório Bem wrote:
> Hi,
> 
> Coverity detected in 'arch/x86/kernel/cpu/perf_event_intel_uncore.c' a
> possible reliance on integer endianness. Is that a positive one?
> 
> static u64 ivt_uncore_irp_read_counter(struct intel_uncore_box *box,
> struct perf_event *event)
> 1369{
> 1370        struct pci_dev *pdev = box->pci_dev;
> 1371        struct hw_perf_event *hwc = &event->hw;
> 1372        u64 count = 0;
> 1373
> 
> CID 1128445 (#1 of 1): Reliance on integer endianness
> (INCOMPATIBLE_CAST)incompatible_cast: Pointer "&count" points to an
> object whose effective type is "unsigned long long" (64 bits,
> unsigned) but is dereferenced as a narrower "unsigned int" (32 bits,
> unsigned). This may lead to unexpected results depending on machine
> endianness.[show details]
> 
> 1374        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx],
> (u32 *)&count);
> 1375        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx]
> + 4, (u32 *)&count + 1);
> 1376
> 1377        return count;
> 1378}

Right, its a bit ugly but since its all arch code (x86) we can indeed
assume endianness (little).

So yes Coverity is right but we can also ignore it since machine
endianness is fixed here.

The code loads the u64 in two pci dword reads and assumes the high dword
lives at the higher address, this is correct for little endian.

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

* Re: [RFC] Coverity 1128445 - Reliance on integer endianness
  2013-11-12 14:19 [RFC] Coverity 1128445 - Reliance on integer endianness Geyslan Gregório Bem
  2013-11-12 14:30 ` Peter Zijlstra
@ 2013-11-12 14:33 ` Peter Zijlstra
  2013-11-12 14:39   ` Geyslan Gregório Bem
  2013-11-12 14:36 ` Måns Rullgård
  2 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2013-11-12 14:33 UTC (permalink / raw)
  To: Geyslan Gregório Bem; +Cc: paulus, Ingo Molnar, acme, LKML

On Tue, Nov 12, 2013 at 12:19:13PM -0200, Geyslan Gregório Bem wrote:

Cc: kernel-br@googlegroups.com

Don't cross-post to lists that don't allow public posts, and very much
don't cross-post to lists that bounce in incomprehensible gibberish :/


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

* Re: [RFC] Coverity 1128445 - Reliance on integer endianness
  2013-11-12 14:19 [RFC] Coverity 1128445 - Reliance on integer endianness Geyslan Gregório Bem
  2013-11-12 14:30 ` Peter Zijlstra
  2013-11-12 14:33 ` Peter Zijlstra
@ 2013-11-12 14:36 ` Måns Rullgård
  2013-11-12 14:38   ` Geyslan Gregório Bem
  2 siblings, 1 reply; 6+ messages in thread
From: Måns Rullgård @ 2013-11-12 14:36 UTC (permalink / raw)
  To: Geyslan Gregório Bem
  Cc: a.p.zijlstra, paulus, Ingo Molnar, acme, kernel-br, LKML

Geyslan Gregório Bem <geyslan@gmail.com> writes:

> Hi,
>
> Coverity detected in 'arch/x86/kernel/cpu/perf_event_intel_uncore.c' a
> possible reliance on integer endianness. Is that a positive one?

No, x86 is always little endian.

> static u64 ivt_uncore_irp_read_counter(struct intel_uncore_box *box,
> struct perf_event *event)
> 1369{
> 1370        struct pci_dev *pdev = box->pci_dev;
> 1371        struct hw_perf_event *hwc = &event->hw;
> 1372        u64 count = 0;
> 1373
>
> CID 1128445 (#1 of 1): Reliance on integer endianness
> (INCOMPATIBLE_CAST)incompatible_cast: Pointer "&count" points to an
> object whose effective type is "unsigned long long" (64 bits,
> unsigned) but is dereferenced as a narrower "unsigned int" (32 bits,
> unsigned). This may lead to unexpected results depending on machine
> endianness.[show details]
>
> 1374        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx],
> (u32 *)&count);
> 1375        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx]
> + 4, (u32 *)&count + 1);
> 1376
> 1377        return count;
> 1378}

This looks intentional and correct apart from possible strict aliasing
issues.

-- 
Måns Rullgård
mans@mansr.com

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

* Re: [RFC] Coverity 1128445 - Reliance on integer endianness
  2013-11-12 14:36 ` Måns Rullgård
@ 2013-11-12 14:38   ` Geyslan Gregório Bem
  0 siblings, 0 replies; 6+ messages in thread
From: Geyslan Gregório Bem @ 2013-11-12 14:38 UTC (permalink / raw)
  To: Måns Rullgård
  Cc: a.p.zijlstra, paulus, Ingo Molnar, acme, kernel-br, LKML

2013/11/12 Måns Rullgård <mans@mansr.com>:
> Geyslan Gregório Bem <geyslan@gmail.com> writes:
>
>> Hi,
>>
>> Coverity detected in 'arch/x86/kernel/cpu/perf_event_intel_uncore.c' a
>> possible reliance on integer endianness. Is that a positive one?
>
> No, x86 is always little endian.
>
>> static u64 ivt_uncore_irp_read_counter(struct intel_uncore_box *box,
>> struct perf_event *event)
>> 1369{
>> 1370        struct pci_dev *pdev = box->pci_dev;
>> 1371        struct hw_perf_event *hwc = &event->hw;
>> 1372        u64 count = 0;
>> 1373
>>
>> CID 1128445 (#1 of 1): Reliance on integer endianness
>> (INCOMPATIBLE_CAST)incompatible_cast: Pointer "&count" points to an
>> object whose effective type is "unsigned long long" (64 bits,
>> unsigned) but is dereferenced as a narrower "unsigned int" (32 bits,
>> unsigned). This may lead to unexpected results depending on machine
>> endianness.[show details]
>>
>> 1374        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx],
>> (u32 *)&count);
>> 1375        pci_read_config_dword(pdev, ivt_uncore_irp_ctrs[hwc->idx]
>> + 4, (u32 *)&count + 1);
>> 1376
>> 1377        return count;
>> 1378}
>
> This looks intentional and correct apart from possible strict aliasing
> issues.
>
> --
> Måns Rullgård
> mans@mansr.com

All right. Thanks.

-- 
Regards,

Geyslan G. Bem
hackingbits.com

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

* Re: [RFC] Coverity 1128445 - Reliance on integer endianness
  2013-11-12 14:33 ` Peter Zijlstra
@ 2013-11-12 14:39   ` Geyslan Gregório Bem
  0 siblings, 0 replies; 6+ messages in thread
From: Geyslan Gregório Bem @ 2013-11-12 14:39 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: paulus, Ingo Molnar, acme, LKML

2013/11/12 Peter Zijlstra <peterz@infradead.org>:
> On Tue, Nov 12, 2013 at 12:19:13PM -0200, Geyslan Gregório Bem wrote:
>
> Cc: kernel-br@googlegroups.com
>
> Don't cross-post to lists that don't allow public posts, and very much
> don't cross-post to lists that bounce in incomprehensible gibberish :/
>

Ok. No more.

-- 
Regards,

Geyslan G. Bem
hackingbits.com

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

end of thread, other threads:[~2013-11-12 14:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-12 14:19 [RFC] Coverity 1128445 - Reliance on integer endianness Geyslan Gregório Bem
2013-11-12 14:30 ` Peter Zijlstra
2013-11-12 14:33 ` Peter Zijlstra
2013-11-12 14:39   ` Geyslan Gregório Bem
2013-11-12 14:36 ` Måns Rullgård
2013-11-12 14:38   ` Geyslan Gregório Bem

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®