From patchwork Wed May 15 13:47:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzesimir Nowak X-Patchwork-Id: 10944831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 336711395 for ; Wed, 15 May 2019 13:48:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22B29289D7 for ; Wed, 15 May 2019 13:48:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 172A028A48; Wed, 15 May 2019 13:48:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B957F28A5B for ; Wed, 15 May 2019 13:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727892AbfEONsZ (ORCPT ); Wed, 15 May 2019 09:48:25 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50675 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727857AbfEONsZ (ORCPT ); Wed, 15 May 2019 09:48:25 -0400 Received: by mail-wm1-f67.google.com with SMTP id f204so131218wme.0 for ; Wed, 15 May 2019 06:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kinvolk.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p5yzJN+uQCvOHSSRz2qO10uSVTsd9TOZD2wH8snlydI=; b=iMDh53PLA//kuvDf60EoF5DO6lg5ZOFCwCIEm72JxVyO2HvdX0hdLeE/BfiaT9mplr ICKoDR6mmjODIZ6bHtnZxksT56RhBAJU/9jN5ZetIHshOM1e4ttrczjlifK1UGJYxlZn PAM+x/7SXvHl/NrKuZqmda+p4PRbSQWgZbXEQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p5yzJN+uQCvOHSSRz2qO10uSVTsd9TOZD2wH8snlydI=; b=ituTN/wu2EMBXKK2v8dgUkPXyyUy6+6fCORWFgVTvRjH1KV7Qu6IFzsyG5bRWUp2/+ wkA6mrwNLhznfKeGOjxv+qCzhEzkpTSb7W+PkkaCDtBB+Y957mUAd5q9FTIbyO19yzi8 PjPE7eZKeuDzJeAAfJ/dhslXSe9IzEEh4f7bmmhPSXJ0Te/VfUOoq8k9vQAAGuEqM2Ki 1CxQ01hgKRfixhpKHLkr1K98pHkp6DUcTeQETu9QgXp2GWH4tfmkSRY8Rg0teYumMcbd h/Duftg5w1eMhMaoyc1NgA4BpwXEs1LFnMk7IMVmfEeE8SCVJDncoObV8deeJB3WyzXf Ou1A== X-Gm-Message-State: APjAAAU/sVnYTiyyV46Ctac9l+4LMNbo66WTBb1MK5e+j8dS56TPeQrI kZ3rV97AI7K1hws+ScyWz7SqkQ== X-Google-Smtp-Source: APXvYqzWjGrtCnZ493pnT5MtkPv074A0nEYcFLTFgf/9DkbA6WOseK1zVOlUxJOJDyZDwxQ8ZnP01w== X-Received: by 2002:a7b:c549:: with SMTP id j9mr823322wmk.114.1557928103209; Wed, 15 May 2019 06:48:23 -0700 (PDT) Received: from localhost.localdomain (ip5f5aea35.dynamic.kabel-deutschland.de. [95.90.234.53]) by smtp.gmail.com with ESMTPSA id v5sm4498506wra.83.2019.05.15.06.48.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2019 06:48:22 -0700 (PDT) From: Krzesimir Nowak To: bpf@vger.kernel.org Cc: iago@kinvolk.io, alban@kinvolk.io, Krzesimir Nowak , Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrey Ignatov , Jiong Wang , Jakub Kicinski , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf v1 1/3] selftests/bpf: Test correctness of narrow 32bit read on 64bit field Date: Wed, 15 May 2019 15:47:26 +0200 Message-Id: <20190515134731.12611-2-krzesimir@kinvolk.io> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190515134731.12611-1-krzesimir@kinvolk.io> References: <20190515134731.12611-1-krzesimir@kinvolk.io> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Test the correctness of the 32bit narrow reads by reading both halves of the 64 bit field and doing a binary or on them to see if we get the original value. This isn't really tested - the program is not being run, because BPF_PROG_TYPE_PERF_EVENT is not supported by bpf_test_run_prog. Signed-off-by: Krzesimir Nowak --- tools/testing/selftests/bpf/verifier/var_off.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/bpf/verifier/var_off.c b/tools/testing/selftests/bpf/verifier/var_off.c index 8504ac937809..2668819dcc85 100644 --- a/tools/testing/selftests/bpf/verifier/var_off.c +++ b/tools/testing/selftests/bpf/verifier/var_off.c @@ -246,3 +246,18 @@ .result = ACCEPT, .prog_type = BPF_PROG_TYPE_LWT_IN, }, +{ + "32bit loads of a 64bit field (both least and most significant words)", + .insns = { + BPF_LDX_MEM(BPF_W, BPF_REG_4, BPF_REG_1, offsetof(struct bpf_perf_event_data, sample_period)), + BPF_LDX_MEM(BPF_W, BPF_REG_5, BPF_REG_1, offsetof(struct bpf_perf_event_data, sample_period) + 4), + BPF_LDX_MEM(BPF_DW, BPF_REG_6, BPF_REG_1, offsetof(struct bpf_perf_event_data, sample_period)), + BPF_ALU64_IMM(BPF_LSH, BPF_REG_4, 32), + BPF_ALU64_REG(BPF_OR, BPF_REG_4, BPF_REG_5), + BPF_ALU64_REG(BPF_XOR, BPF_REG_4, BPF_REG_6), + BPF_MOV64_REG(BPF_REG_0, BPF_REG_4), + BPF_EXIT_INSN(), + }, + .result = ACCEPT, + .prog_type = BPF_PROG_TYPE_PERF_EVENT, +},