mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net: make struct bootp __packed to prevent unaligned store on MIPS
@ 2017-12-25 18:37 Antony Pavlov
  2017-12-26 13:23 ` Oleksij Rempel
  2018-01-05 14:53 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Antony Pavlov @ 2017-12-25 18:37 UTC (permalink / raw)
  To: barebox

How to repropduce the unaligned store problem

    qemu-system-mips -nodefaults -M malta -m 256 \
                     -nographic -serial stdio -monitor null \
                     -bios barebox-flash-image \
                     -net user -net nic,model=rtl8139

    ...

    barebox:/ dhcp

    Ooops, address error on store!

    $ 0   : 00000000 00000000 01010600 697f2a2e
    $ 4   : a0850000 00000000 0000001c a040c1b8
    $ 8   : 00000000 00000002 00000002 00000000
    $12   : 00000000 00000040 00000100 00000001
    $16   : a040bba0 a0850000 a0850000 a0850000
    $20   : 00000000 00000075 00000076 a040ba20
    $24   : 00000002 a080f210
    $28   : 00000000 a03ffce0 fffffffd a0833b8c
    Hi    : 000154f8
    Lo    : 20000000
    epc   : a0833b84
    ra    : a0833b8c
    Status: 00000002
    Cause : 80000414
    Config: 80008482

    ### ERROR ### Please RESET the board ###

The unaligned store instruction is located in the bootp_request() from net/dhcp.c:

a0833b50 <bootp_request>:
..
a0833b7c:       3c020101        lui     v0,0x101
a0833b80:       24420600        addiu   v0,v0,1536 /* 0x1010600 -> v0 */
a0833b84:       0c20024a        jal     a0800928 <get_time_ns>
a0833b88:       ae02002a        sw      v0,42(s0) /* store 0x1010600 to addr s0 + 42 */

This assembler code is generated by mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
from this:

    bp = (struct bootp *)payload;
    bp->bp_op = OP_BOOTREQUEST; /* 0x01 */
    bp->bp_htype = HWT_ETHER; /* 0x01 */
    bp->bp_hlen = HWL_ETHER; /* 0x06 */
    bp->bp_hops = 0;

Compiler replaces four 'store byte' instruction by one 'store 32-bit word'
instruction. Alas sometimes this leads to unaligned store situation.

Making struct bootp __packed prevents this optimization and fixes the problem.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 net/dhcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index c5386fe942..4177220410 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -45,7 +45,7 @@ struct bootp {
 	char		bp_sname[64];	/* Server host name			*/
 	char		bp_file[128];	/* Boot file name			*/
 	char		bp_vend[0];	/* Vendor information			*/
-};
+} __packed;
 
 /* DHCP States */
 typedef enum {
-- 
2.15.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: make struct bootp __packed to prevent unaligned store on MIPS
  2017-12-25 18:37 [PATCH] net: make struct bootp __packed to prevent unaligned store on MIPS Antony Pavlov
@ 2017-12-26 13:23 ` Oleksij Rempel
  2018-01-05 14:53 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2017-12-26 13:23 UTC (permalink / raw)
  To: barebox


[-- Attachment #1.1.1: Type: text/plain, Size: 2640 bytes --]

Am 25.12.2017 um 19:37 schrieb Antony Pavlov:
> How to repropduce the unaligned store problem
> 
>     qemu-system-mips -nodefaults -M malta -m 256 \
>                      -nographic -serial stdio -monitor null \
>                      -bios barebox-flash-image \
>                      -net user -net nic,model=rtl8139
> 
>     ...
> 
>     barebox:/ dhcp
> 
>     Ooops, address error on store!
> 
>     $ 0   : 00000000 00000000 01010600 697f2a2e
>     $ 4   : a0850000 00000000 0000001c a040c1b8
>     $ 8   : 00000000 00000002 00000002 00000000
>     $12   : 00000000 00000040 00000100 00000001
>     $16   : a040bba0 a0850000 a0850000 a0850000
>     $20   : 00000000 00000075 00000076 a040ba20
>     $24   : 00000002 a080f210
>     $28   : 00000000 a03ffce0 fffffffd a0833b8c
>     Hi    : 000154f8
>     Lo    : 20000000
>     epc   : a0833b84
>     ra    : a0833b8c
>     Status: 00000002
>     Cause : 80000414
>     Config: 80008482
> 
>     ### ERROR ### Please RESET the board ###
> 
> The unaligned store instruction is located in the bootp_request() from net/dhcp.c:
> 
> a0833b50 <bootp_request>:
> ..
> a0833b7c:       3c020101        lui     v0,0x101
> a0833b80:       24420600        addiu   v0,v0,1536 /* 0x1010600 -> v0 */
> a0833b84:       0c20024a        jal     a0800928 <get_time_ns>
> a0833b88:       ae02002a        sw      v0,42(s0) /* store 0x1010600 to addr s0 + 42 */
> 
> This assembler code is generated by mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
> from this:
> 
>     bp = (struct bootp *)payload;
>     bp->bp_op = OP_BOOTREQUEST; /* 0x01 */
>     bp->bp_htype = HWT_ETHER; /* 0x01 */
>     bp->bp_hlen = HWL_ETHER; /* 0x06 */
>     bp->bp_hops = 0;
> 
> Compiler replaces four 'store byte' instruction by one 'store 32-bit word'
> instruction. Alas sometimes this leads to unaligned store situation.
> 
> Making struct bootp __packed prevents this optimization and fixes the problem.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>

Tested-by: Oleksij Rempel <linux@rempel-privat.de>

This patch solves similar crash on Atheros AR9331.


> ---
>  net/dhcp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/dhcp.c b/net/dhcp.c
> index c5386fe942..4177220410 100644
> --- a/net/dhcp.c
> +++ b/net/dhcp.c
> @@ -45,7 +45,7 @@ struct bootp {
>  	char		bp_sname[64];	/* Server host name			*/
>  	char		bp_file[128];	/* Boot file name			*/
>  	char		bp_vend[0];	/* Vendor information			*/
> -};
> +} __packed;
>  
>  /* DHCP States */
>  typedef enum {
> 


-- 
Regards,
Oleksij


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: make struct bootp __packed to prevent unaligned store on MIPS
  2017-12-25 18:37 [PATCH] net: make struct bootp __packed to prevent unaligned store on MIPS Antony Pavlov
  2017-12-26 13:23 ` Oleksij Rempel
@ 2018-01-05 14:53 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2018-01-05 14:53 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Mon, Dec 25, 2017 at 09:37:58PM +0300, Antony Pavlov wrote:
> How to repropduce the unaligned store problem
> 
>     qemu-system-mips -nodefaults -M malta -m 256 \
>                      -nographic -serial stdio -monitor null \
>                      -bios barebox-flash-image \
>                      -net user -net nic,model=rtl8139
> 
>     ...
> 
>     barebox:/ dhcp
> 
>     Ooops, address error on store!
> 
>     $ 0   : 00000000 00000000 01010600 697f2a2e
>     $ 4   : a0850000 00000000 0000001c a040c1b8
>     $ 8   : 00000000 00000002 00000002 00000000
>     $12   : 00000000 00000040 00000100 00000001
>     $16   : a040bba0 a0850000 a0850000 a0850000
>     $20   : 00000000 00000075 00000076 a040ba20
>     $24   : 00000002 a080f210
>     $28   : 00000000 a03ffce0 fffffffd a0833b8c
>     Hi    : 000154f8
>     Lo    : 20000000
>     epc   : a0833b84
>     ra    : a0833b8c
>     Status: 00000002
>     Cause : 80000414
>     Config: 80008482
> 
>     ### ERROR ### Please RESET the board ###
> 
> The unaligned store instruction is located in the bootp_request() from net/dhcp.c:
> 
> a0833b50 <bootp_request>:
> ..
> a0833b7c:       3c020101        lui     v0,0x101
> a0833b80:       24420600        addiu   v0,v0,1536 /* 0x1010600 -> v0 */
> a0833b84:       0c20024a        jal     a0800928 <get_time_ns>
> a0833b88:       ae02002a        sw      v0,42(s0) /* store 0x1010600 to addr s0 + 42 */
> 
> This assembler code is generated by mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
> from this:
> 
>     bp = (struct bootp *)payload;
>     bp->bp_op = OP_BOOTREQUEST; /* 0x01 */
>     bp->bp_htype = HWT_ETHER; /* 0x01 */
>     bp->bp_hlen = HWL_ETHER; /* 0x06 */
>     bp->bp_hops = 0;
> 
> Compiler replaces four 'store byte' instruction by one 'store 32-bit word'
> instruction. Alas sometimes this leads to unaligned store situation.
> 
> Making struct bootp __packed prevents this optimization and fixes the problem.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>

Applied to master, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2018-01-05 14:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-25 18:37 [PATCH] net: make struct bootp __packed to prevent unaligned store on MIPS Antony Pavlov
2017-12-26 13:23 ` Oleksij Rempel
2018-01-05 14:53 ` Sascha Hauer

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