2 # sim: --skb-data-offset=0x20
3 # output: pass\nexit 0 (0x0)\n
5 ;;; Tests for non-generic BPF load instructions in simulator.
6 ;;; These instructions (ld{abs,ind}{b,h,w,dw}) are used to access
7 ;;; kernel socket data from BPF programs for high performance filters.
9 ;;; Register r6 is an implicit input holding a pointer to a struct sk_buff.
10 ;;; Register r0 is an implicit output, holding the fetched data.
14 ;;; r0 = ntohl (*(u32 *) (((struct sk_buff *)r6)->data + imm32))
17 ;;; r0 = ntohl (*(u32 *) (((struct sk_buff *)r6)->data + src_reg + imm32))
19 .include "testutils.inc"
25 ;; R6 holds a pointer to a struct sk_buff, which we pretend
29 ;; We configure skb-data-offset=0x20
30 ;; This specifies offsetof(struct sk_buff, data), where the field 'data'
31 ;; is a pointer a data buffer, in this case at 0x2000
32 stw [%r6+0x20], 0x2000
34 ;; Write the value 0x7eadbeef into memory at 0x2004
35 ;; i.e. offset 4 within the data buffer pointed to by
36 ;; ((struct sk_buff *)r6)->data
37 stw [%r6+0x1004], 0xdeadbeef
39 ;; Now load data[4] into r0 using the ldabsw instruction
42 ;; ...and compare to what we expect
43 fail_ne32 %r0, 0xdeadbeef
45 ;; Repeat for a half-word (2-bytes)
46 sth [%r6+0x1008], 0x1234
50 ;; Repeat for a single byte
51 stb [%r6+0x1010], 0x5a
55 ;; Repeat for a double-word (8-byte)
56 ;; (note: fail_ne macro uses r0, so copy to another r1 to compare)
57 lddw %r2, 0x1234deadbeef5678
58 stxdw [%r6+0x1018], %r2
61 fail_ne %r1, 0x1234deadbeef5678
63 ;; Now, we do the same for the indirect loads
65 stw [%r6+0x1100], 0xfeedbeef
68 fail_ne32 %r0, 0xfeedbeef
71 sth [%r6+0x1104], 0x6789
76 stb [%r6+0x1108], 0x5f
81 lddw %r2, 0xcafe12345678d00d
82 stxdw [%r6+0x1110], %r2
85 fail_ne %r1, 0xcafe12345678d00d