From patchwork Fri Oct 4 09:31:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1171651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46l4Qy1tQsz9sPq for ; Fri, 4 Oct 2019 19:32:22 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BB0333C228E for ; Fri, 4 Oct 2019 11:32:14 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 29F553C2266 for ; Fri, 4 Oct 2019 11:32:12 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id A4957200B19 for ; Fri, 4 Oct 2019 11:32:10 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 08359B03E; Fri, 4 Oct 2019 09:32:08 +0000 (UTC) From: Richard Palethorpe To: ltp@lists.linux.it Date: Fri, 4 Oct 2019 11:31:22 +0200 Message-Id: <20191004093122.25799-1-rpalethorpe@suse.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH] bpf_prog02: Correct index on big endian architectures X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gary Ching-Pang Lin , Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The array index is only 4 bytes, but we store an 8 byte double word on the stack. This is OK on LE where the upper 4 bytes are ignored. However on BE the lower 4 bytes are ignored and we therefor get an index of zero each time. So we have switch to just using a single word (32bits) to store the index. Idea-by: Gary Ching-Pang Lin Signed-off-by: Richard Palethorpe --- include/lapi/bpf.h | 1 + testcases/kernel/syscalls/bpf/bpf_prog02.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/lapi/bpf.h b/include/lapi/bpf.h index 03073b45e..5582e344a 100644 --- a/include/lapi/bpf.h +++ b/include/lapi/bpf.h @@ -24,6 +24,7 @@ #define BPF_JMP 0x05 #define BPF_SIZE(code) ((code) & 0x18) +#define BPF_W 0x00 /* 32-bit */ #define BPF_DW 0x18 /* double word (64-bit) */ #define BPF_MODE(code) ((code) & 0xe0) diff --git a/testcases/kernel/syscalls/bpf/bpf_prog02.c b/testcases/kernel/syscalls/bpf/bpf_prog02.c index acb28e98e..fb8f3f781 100644 --- a/testcases/kernel/syscalls/bpf/bpf_prog02.c +++ b/testcases/kernel/syscalls/bpf/bpf_prog02.c @@ -43,8 +43,8 @@ static int load_prog(int fd) BPF_LD_MAP_FD(BPF_REG_1, fd), /* 1: r1 = &fd */ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), /* 3: r2 = fp */ - BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8), /* 4: r2 = r2 - 8 */ - BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0), /* 5: *r2 = 0 */ + BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -4), /* 4: r2 = r2 - 4 */ + BPF_ST_MEM(BPF_W, BPF_REG_2, 0, 0), /* 5: *r2 = 0 */ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),/* 6: map_lookup_elem */ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 17), /* 7: if(!r0) goto 25 */ BPF_MOV64_REG(BPF_REG_3, BPF_REG_0), /* 8: r3 = r0 */ @@ -54,8 +54,8 @@ static int load_prog(int fd) BPF_LD_MAP_FD(BPF_REG_1, fd), /* 13: r1 = &fd */ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), /* 15: r2 = fp */ - BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8), /* 16: r2 = r2 - 8 */ - BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 1), /* 17: *r2 = 1 */ + BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -4), /* 16: r2 = r2 - 4 */ + BPF_ST_MEM(BPF_W, BPF_REG_2, 0, 1), /* 17: *r2 = 1 */ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),/* 18: map_lookup_elem */ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5), /* 19: if(!r0) goto 25 */ BPF_MOV64_REG(BPF_REG_3, BPF_REG_0), /* 20: r3 = r0 */