Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp596964yba; Wed, 15 May 2019 06:49:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7VIso8tlwtyDGkZeRssU3zwYXbx3T3/MOSeuDFKH1weCAbpS0W0/V+WThmiYZF2Mk9Xfl X-Received: by 2002:a17:902:868c:: with SMTP id g12mr26591514plo.323.1557928191850; Wed, 15 May 2019 06:49:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557928191; cv=none; d=google.com; s=arc-20160816; b=wi0SclwqRAy8a0YZqo84NuBFXJssXRIdUb0JaAvs5Lmmnm+lGrt8iE/4QwaLsey2cq NCMuLH2JlODu0wJBA5m2/oXVRelOn/uWtOuJzOF+L4KXfhRUBN7eQJyPG2xMAEgnanBE sYkSGchz3JtFDtkkKwc7iGae9kXaraDEjnS8b9iovnu0LYAQJ0kFs3pdvnSh6cQIG0tl rOee0xXg9Y7loriu4RxCm86RmGvOYhi7jBvXYVsutl21azI7TnWHf8uF7i2CCNqogWJf 3Ada3fgwDUrf46rvW6nEeQgpzB3sgKSSfkOc5ieWPN1lq40t5vH8we6FehaaUhLihQwM oWWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p5yzJN+uQCvOHSSRz2qO10uSVTsd9TOZD2wH8snlydI=; b=rTr32FSnUSkYdlSVdXmRdZuRxrnP4RXX8NofKFhxxQW/d4EvT5pi4L3t1U4vlQ3km1 uRns0qCED/HRe59jgW/zcW93hIAVAPVIZDdPGQyxL/cH4uX6wHhy0HjI++mEsNRqF3Vm yH48xWsQ4ay4iQ0wGZ7BnV59oqNQGa9ptTTKTXkXusKI0l2MfQ902+a8W5QTTN2p7zPH Tt2osJnoIOkPmuiZgg4AspiMSBvDaSmxc5lTJwzRVte3SQmqYVNhsgctr1jtCkIN8WYG yKb4t0VGrcEecX8tRjB6995do4pgnzP5m/2/JN+xPILHnrVlCn4icAoLWK7ijq9G1yZ3 DaBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kinvolk.io header.s=google header.b=iMDh53PL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id go17si1796988plb.357.2019.05.15.06.49.37; Wed, 15 May 2019 06:49:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kinvolk.io header.s=google header.b=iMDh53PL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727943AbfEONs0 (ORCPT + 99 others); Wed, 15 May 2019 09:48:26 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53379 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727627AbfEONsZ (ORCPT ); Wed, 15 May 2019 09:48:25 -0400 Received: by mail-wm1-f67.google.com with SMTP id 198so108987wme.3 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=m+Boz0g1mqyV3tBPqb33CSa4pgNDCLbx7UMB+xyBkKMHq7mSNsK23NAwH1Pay/uNid LkNpMTXjQEHLS2KudLapTSoNvOIGRRfNANgLjVKD50u0SCYPFQwb4i1OPkwbELuCpqEU KqFBfakTybepWwIXbC1hISw9LY9iqBLnnUzsEX4sMRZ3OzW6kY7VDRnbWmJUbECE2ytv qLJx2u/10GiNlBBYFkfDeaK+FA0lCPXqJ78WBGvi0zQlmb+/Oef0FrglJzNYGtx/u+4v rY2lQVP97MIFBWArWeShUODQEAC4hYB1kE/R3AkRYFsjhAXeVY0+YGtr/qwxLX4BW8Ws AU/Q== X-Gm-Message-State: APjAAAWqsgIiMB7igprBroKLpqOVLS5UEehiet6rYdnEDdfvEODYfoFu TUVrQ97UGzwecG6ZBUdC3f//Pg== 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, +}, -- 2.20.1