lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 3 Apr 2018 13:40:51 -0700
From:   Florian Fainelli <f.fainelli@...il.com>
To:     Al Viro <viro@...IV.linux.org.uk>,
        David Miller <davem@...emloft.net>
Cc:     netdev@...r.kernel.org, opendmb@...il.com,
        linux-kernel@...r.kernel.org
Subject: [PATCH net 1/2] net: bcmgenet: Fix sparse warnings in
 bcmgenet_put_tx_csum()

On 04/03/2018 09:45 AM, Al Viro wrote:
> On Tue, Apr 03, 2018 at 12:33:05PM -0400, David Miller wrote:
> 
>> Yes Al, however the pattern choosen here is probably cheaper on little endian:
>>
>> 	__beXX val = x;
>> 	switch (val) {
>> 	case htons(ETH_P_FOO):
>> 	 ...
>> 	}
>>
>> This way only the compiler byte swaps the constants at compile time,
>> no code is actually generated to do it.
> 
> That's not obvious, actually - depends upon how sparse the switch ends
> up being.  You can easily lose more than a single byteswap insn on
> worse cascase of comparisons.

David is right though here and this is used primarily on LE hosts, the
code produced with your suggested change does fix the sparse warning and
is functional, but results in less efficient code with a rev16
instruction being used. If you would prefer me to use __constant_htons()
to make that clearer, I don't have any objection to that.

172 instructions including a rev16

00002da8 <bcmgenet_insert_status>:
    2da8:       e1d038b8        ldrh    r3, [r0, #136]  ; 0x88
    2dac:       e92d4070        push    {r4, r5, r6, lr}
    2db0:       e6bf3fb3        rev16   r3, r3			<==============
    2db4:       e6ff3073        uxth    r3, r3
    2db8:       e3530b02        cmp     r3, #2048       ; 0x800
    2dbc:       0a000020        beq     2e44 <bcmgenet_insert_status+0x9c>
    2dc0:       e30826dd        movw    r2, #34525      ; 0x86dd
    2dc4:       e1530002        cmp     r3, r2
    2dc8:       1a00001c        bne     2e40 <bcmgenet_insert_status+0x98>
    2dcc:       e5906098        ldr     r6, [r0, #152]  ; 0x98
    2dd0:       e1d028bc        ldrh    r2, [r0, #140]  ; 0x8c
    2dd4:       e0862002        add     r2, r6, r2
    2dd8:       e5d22006        ldrb    r2, [r2, #6]
    2ddc:       e242e011        sub     lr, r2, #17
    2de0:       e1d0c6b4        ldrh    ip, [r0, #100]  ; 0x64
    2de4:       e16fef1e        clz     lr, lr
    2de8:       e590509c        ldr     r5, [r0, #156]  ; 0x9c
    2dec:       e1d046b6        ldrh    r4, [r0, #102]  ; 0x66
    2df0:       e1a0e2ae        lsr     lr, lr, #5
    2df4:       e3520006        cmp     r2, #6
    2df8:       11a0200e        movne   r2, lr
    2dfc:       038e2001        orreq   r2, lr, #1
    2e00:       e3520000        cmp     r2, #0
    2e04:       0a00000b        beq     2e38 <bcmgenet_insert_status+0x90>
    2e08:       e0455006        sub     r5, r5, r6
    2e0c:       e3530b02        cmp     r3, #2048       ; 0x800
    2e10:       13a0e000        movne   lr, #0
    2e14:       020ee001        andeq   lr, lr, #1
    2e18:       e04c3005        sub     r3, ip, r5
    2e1c:       e35e0000        cmp     lr, #0
    2e20:       e2433040        sub     r3, r3, #64     ; 0x40
    2e24:       e6ff3073        uxth    r3, r3
    2e28:       e0844003        add     r4, r4, r3
    2e2c:       e1842803        orr     r2, r4, r3, lsl #16
    2e30:       e3822102        orr     r2, r2, #-2147483648    ; 0x80000000
    2e34:       13822902        orrne   r2, r2, #32768  ; 0x8000
    2e38:       e5812030        str     r2, [r1, #48]   ; 0x30
    2e3c:       e8bd8070        pop     {r4, r5, r6, pc}
    2e40:       e8bd8070        pop     {r4, r5, r6, pc}
    2e44:       e5906098        ldr     r6, [r0, #152]  ; 0x98
    2e48:       e1d028bc        ldrh    r2, [r0, #140]  ; 0x8c
    2e4c:       e0862002        add     r2, r6, r2
    2e50:       e5d22009        ldrb    r2, [r2, #9]
    2e54:       eaffffe0        b       2ddc <bcmgenet_insert_status+0x34>


Whereas my changes result in:

164 instructions, and no rev* since everything is resolved at compile time.

00000810 <bcmgenet_insert_status>:
     810:       e92d4070        push    {r4, r5, r6, lr}
     814:       e1d0e8b8        ldrh    lr, [r0, #136]  ; 0x88
     818:       e35e0008        cmp     lr, #8
     81c:       0a000020        beq     8a4 <bcmgenet_insert_status+0x94>
     820:       e30d3d86        movw    r3, #56710      ; 0xdd86
     824:       e15e0003        cmp     lr, r3
     828:       1a00001c        bne     8a0 <bcmgenet_insert_status+0x90>
     82c:       e5906098        ldr     r6, [r0, #152]  ; 0x98
     830:       e1d038bc        ldrh    r3, [r0, #140]  ; 0x8c
     834:       e0863003        add     r3, r6, r3
     838:       e5d33006        ldrb    r3, [r3, #6]
     83c:       e2434011        sub     r4, r3, #17
     840:       e1d0c6b4        ldrh    ip, [r0, #100]  ; 0x64
     844:       e16f4f14        clz     r4, r4
     848:       e590209c        ldr     r2, [r0, #156]  ; 0x9c
     84c:       e1d056b6        ldrh    r5, [r0, #102]  ; 0x66
     850:       e1a042a4        lsr     r4, r4, #5
     854:       e3530006        cmp     r3, #6
     858:       11a03004        movne   r3, r4
     85c:       03843001        orreq   r3, r4, #1
     860:       e3530000        cmp     r3, #0
     864:       0a00000b        beq     898 <bcmgenet_insert_status+0x88>
     868:       e0422006        sub     r2, r2, r6
     86c:       e35e0008        cmp     lr, #8
     870:       13a0e000        movne   lr, #0
     874:       0204e001        andeq   lr, r4, #1
     878:       e04c2002        sub     r2, ip, r2
     87c:       e35e0000        cmp     lr, #0
     880:       e2422040        sub     r2, r2, #64     ; 0x40
     884:       e6ff2072        uxth    r2, r2
     888:       e0855002        add     r5, r5, r2
     88c:       e1853802        orr     r3, r5, r2, lsl #16
     890:       e3833102        orr     r3, r3, #-2147483648    ; 0x80000000
     894:       13833902        orrne   r3, r3, #32768  ; 0x8000
     898:       e5813030        str     r3, [r1, #48]   ; 0x30
     89c:       e8bd8070        pop     {r4, r5, r6, pc}
     8a0:       e8bd8070        pop     {r4, r5, r6, pc}
     8a4:       e5906098        ldr     r6, [r0, #152]  ; 0x98
     8a8:       e1d038bc        ldrh    r3, [r0, #140]  ; 0x8c
     8ac:       e0863003        add     r3, r6, r3
     8b0:       e5d33009        ldrb    r3, [r3, #9]
     8b4:       eaffffe0        b       83c <bcmgenet_insert_status+0x2c>

-- 
Florian


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ