From patchwork Tue Nov 17 08:26:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 11911705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A7A8C2D0E4 for ; Tue, 17 Nov 2020 08:27:11 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 89A4724655 for ; Tue, 17 Nov 2020 08:27:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="a8z8GHGE"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RSih97Qg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89A4724655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TuH2NuBjfVX0q8U93DjkqEkKHBLmCyokAM7QECWSJwc=; b=a8z8GHGEar5fvD7Qmin7ww5Uo Pzs/mcUvS/5OehUjS4Sy3M9uN3V5X0uD2Hr/9HZjx0t99JyozD+5ZpK6+++xcrXd7lfUIIAGyK0w7 TIECl5uV5xzKgLW8p33L2k1HV6WaJznALe/Np8g16BQ4dMYTSCy1/k3LH4BGnudclRKblXMUtQH96 rgucxAKoMVCibtxETn/mx2zn6aXKNkrck+CKhTNXmHCOcqsBNQthy4kS7w5JYXYcklNOvjJwE8U3w Vr3q7uQPlUlIxNdSp3sni6NpbVecqQnUgQTRKRZBe7ZW5lM1NvMTgkFtDiagQgwFDJCmO1vP2Am2M ABvr1trfA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kewKO-0008Tj-UC; Tue, 17 Nov 2020 08:27:05 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kewKL-0008Sz-Pr for linux-riscv@lists.infradead.org; Tue, 17 Nov 2020 08:27:02 +0000 Received: by mail-pg1-x541.google.com with SMTP id i13so15663684pgm.9 for ; Tue, 17 Nov 2020 00:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=thC0vwUoC+dS5Z/fyfQ4HgfqnUUZ2rF5Qe//4cJ/e/s=; b=RSih97Qg5lNmEj0m87IY+niwHqXQAIC0ruEFGfQ30wLErhKzhrQ/CxWBfri5UoFeld Gim6tHlV6PtmyWAhIqA3IPrcXvEuQKObM42h1lCx3Ig5eMwhemVLyVXlXGYPNlv+QtiW GP7RbKgbLDoi34rHR4sn6rA7LydveHF5Ct2mJ/nlCJNyjvJTbn+BsihXINkZVHhsJgU9 DdU6Nu5+Q7G8KvUDixsnqLHkbTbvc3dzrf8XHGmYNMhdC+b1DsvkI6Nq9N3om+PMNOKr tsAg+hvHCONXRTybQAwlqJ2ZlFGlzw4zs7UWeCJsor4+3V60Ud6WRhs1epEDwUYt916a i1qg== 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=thC0vwUoC+dS5Z/fyfQ4HgfqnUUZ2rF5Qe//4cJ/e/s=; b=MAJDqZUFi6Anq6spMF016uLuSqf3Etzi5KHVNtrSBCXihE11veRi2PA1qBMEqo7epf 66wISrMIXdwoAumVrC+mMdEJU7M56bI4GE/+LlHJwwFGafPJ3e1HFtYYa95aPo/SBKAA 5LV8pxAthTHpcjMxmwq52f/g5qxdSpPOp4dmu+8ibac5+kfkpfSP/VDokTb+Z7tuDT4f 5Qaiyk+bH4eK11VcS5NbRCwH3jZdbhOc0CEpwmdR2UxzVX3ZwUUlrA2+aoqZ/eNb6HFv Px0hBfYvz7dgJ8PINodGa6nYQ1umsrUgcnGNFnEuU6KYgTWUAyjCq2u4ECWEGbzFsN7u 2BBQ== X-Gm-Message-State: AOAM533LdoIeSCtG3x+telxH951AO9YaNdPB9/a0ZaHExQs9MJqNgBWr PQi0mUW7t2EyHDRKuZLMXGg= X-Google-Smtp-Source: ABdhPJwHbpYcDC4CrF1mzIpvea+B1cveoQuoSptG8JPZ/wuGPZ8c47r1CEbwD7dwW7n1FDA6IsIGyQ== X-Received: by 2002:a65:5948:: with SMTP id g8mr2607912pgu.51.1605601619614; Tue, 17 Nov 2020 00:26:59 -0800 (PST) Received: from btopel-mobl.ger.intel.com ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id c12sm2251671pjs.8.2020.11.17.00.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 00:26:58 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next 1/3] selftests/bpf: Fix broken riscv build Date: Tue, 17 Nov 2020 09:26:36 +0100 Message-Id: <20201117082638.43675-2-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201117082638.43675-1-bjorn.topel@gmail.com> References: <20201117082638.43675-1-bjorn.topel@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201117_032702_113929_CDB09418 X-CRM114-Status: GOOD ( 10.58 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, xi.wang@gmail.com, luke.r.nels@gmail.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The selftests/bpf Makefile includes system include directories from the host, when building BPF programs. On RISC-V glibc requires that __riscv_xlen is defined. This is not the case for "clang -target bpf", which messes up __WORDSIZE (errno.h -> ... -> wordsize.h) and breaks the build. By explicitly defining __risc_xlen correctly for riscv, we can workaround this. Fixes: 167381f3eac0 ("selftests/bpf: Makefile fix "missing" headers on build with -idirafter") Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index c1708ffa6b1c..9d48769ad268 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -219,7 +219,8 @@ $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids \ # build would have failed anyways. define get_sys_includes $(shell $(1) -v -E - &1 \ - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ + $(shell $(1) -dM -E - X-Patchwork-Id: 11911707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C673C5519F for ; Tue, 17 Nov 2020 08:27:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 02F8B24655 for ; Tue, 17 Nov 2020 08:27:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pIMJ5dxH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F/JGC0VA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02F8B24655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Cx31eV8fxK5X4hdBlUnUcbraUkCG8qHtK5oYg+7uW8s=; b=pIMJ5dxHgl7aL/1lNBDVtvXLf i144lnyeLDAFZ4dvujINnCieiJ7oXp6EdcI1VVSGEYPs5leSEhg6JMTqyFcwKx45FBj4Q0lSnj6Gc 0mDUWPy8PIESBii0uUEbLbFnkrRVDKAcp47rKtFQeTVlMCCd9l/BjPJuJGo3rv5+ue5pNUZ/syoI+ qQkmPa0VrGpI8FJapgRDrMIKfdzMKNs9OQG1T7inIPHHUtc1IZI1JIvg0UgXyWJr9c+f51Y5gGx3f NiAkka82KSgF6S8Y5xXZu0LDSd8Df5fSpW6/9qU5HxrvrEiUNRiEpp0hU4OkDpjzKujmahA4jta1e A+pMV9iJw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kewKT-0008Up-IP; Tue, 17 Nov 2020 08:27:09 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kewKR-0008Tw-4I for linux-riscv@lists.infradead.org; Tue, 17 Nov 2020 08:27:07 +0000 Received: by mail-pj1-x1041.google.com with SMTP id js21so45543pjb.0 for ; Tue, 17 Nov 2020 00:27:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4RoQLFT/+eItTFwja6y027jS+o5vx3tn2+htvfb2XHI=; b=F/JGC0VADO/Zkv17DSC1GpV8jvX6fOTghRA7nki52tR9Bvi9uy666TwzjJsxx0nD4A EEuPltsjDVJ8otN1fS/idx+z49ZybWtexgfmTcCL6WLufsl8d1viun33dYPO22wfW7z+ C94awmkBY0tOqczBNpMBcp9N+g0i1LJ7LxzYH0gJkI7hPUqgUYbN4UBEuQG3nzJnrXn6 p7puBQ6ZOIWcuXtTTKmsEAEXwwhWQXvTsFtGo32CznUIhoHaeHSd7NB1Ea/3zLv3dUT4 Vpta0jVsHA2cOtpkUb//dOV2r6keIv2kPdg7j7W4WXVp3wtYYbPlrdO6OKC/EabDOcSA iYmA== 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=4RoQLFT/+eItTFwja6y027jS+o5vx3tn2+htvfb2XHI=; b=j6jAW27/OWr/1QFF2m1lSShIDCqYQA4h2kvh08dCIAhQzy+Ey6t3uzYjX8n6jQR0JH 6WrzqZ4EXp7USL1q+UU/iV9HdZaMxYwufNRw+RCrDbbjUZbB+MgJyt3wQQeA63Yv2trx t1AjGwXvx+OAjXVQeVTf2plGElsLioAh40rhIscdeTn5tiLdEyZUgTiBFuIVvemsF5B+ ADep7Zj6Y94PdC74qTsVivg4aLPRnyZmwgHx7Ix+h/E79S9/nW7q3/F4BoLbEuKlABX2 TtLMNWn5zFkLZUa7Et0mLPZviiGo3rElk+MLrP8jCnJh5fFbIJXb8CtDFskl2Ri55Yp5 Q6Wg== X-Gm-Message-State: AOAM530rnd+KF+lIjF3VNHfEAN3a4t2vYoOiOAHLPYByI2MwI6swmlQg zX7huq3uqBQAfqvDiHcNOs8= X-Google-Smtp-Source: ABdhPJzqgTFOxPVF4aRIqK+S7JI590qSI1cXqhmcFDMyexvmvVG50FTocYDPRQKCwW2vNkmhOQ20bg== X-Received: by 2002:a17:902:9a84:b029:d6:eaef:4806 with SMTP id w4-20020a1709029a84b02900d6eaef4806mr16375125plp.82.1605601624721; Tue, 17 Nov 2020 00:27:04 -0800 (PST) Received: from btopel-mobl.ger.intel.com ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id c12sm2251671pjs.8.2020.11.17.00.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 00:27:03 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next 2/3] selftests/bpf: Avoid running unprivileged tests with alignment requirements Date: Tue, 17 Nov 2020 09:26:37 +0100 Message-Id: <20201117082638.43675-3-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201117082638.43675-1-bjorn.topel@gmail.com> References: <20201117082638.43675-1-bjorn.topel@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201117_032707_245283_B89595F4 X-CRM114-Status: GOOD ( 13.15 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, xi.wang@gmail.com, luke.r.nels@gmail.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Some architectures have strict alignment requirements. In that case, the BPF verifier detects if a program has unaligned accesses and rejects them. A user can pass BPF_F_ANY_ALIGNMENT to a program to override this check. That, however, will only work when a privileged user loads a program. A unprivileged user loading a program with this flag will be rejected prior entering the verifier. Hence, it does not make sense to load unprivileged programs without strict alignment when testing the verifier. This patch avoids exactly that. Signed-off-by: Björn Töpel --- tools/testing/selftests/bpf/test_verifier.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 9be395d9dc64..2075f6a98813 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -1152,9 +1152,15 @@ static void get_unpriv_disabled() static bool test_as_unpriv(struct bpf_test *test) { - return !test->prog_type || - test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER || - test->prog_type == BPF_PROG_TYPE_CGROUP_SKB; + bool req_aligned = false; + +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS + req_aligned = test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS; +#endif + return (!test->prog_type || + test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER || + test->prog_type == BPF_PROG_TYPE_CGROUP_SKB) && + !req_aligned; } static int do_test(bool unpriv, unsigned int from, unsigned int to) From patchwork Tue Nov 17 08:26:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 11911709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4005CC2D0E4 for ; Tue, 17 Nov 2020 08:27:21 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CB55424655 for ; Tue, 17 Nov 2020 08:27:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="d0lRmEfT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vl4FdewX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB55424655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=miT42r11PutkbHvmK2Ctzop5lbQi67/9BHJkQ7/n/ps=; b=d0lRmEfTABBi3Bu5Yn7FjLWaO F0Qmg3mURp2PwLIRhdEo5hXiMqp/ZANtNXcbgRvpD4/u3Y+dvUum0hbCKHHyIQkjPKZ7kjNW0KOZ8 4dt7tcoTFuefMT6Y1YApxphcLbXximmtpt+HQ0dkOqnhcGXhCIxsAQ/Gfi6ZOcvDhiuAihrh2d0U3 Q2DNzS4I6W51aXW0uQE5O6WLla6pmxtrtsCtiH9EfWgujdnifeETC3+wW0irel8iACJ1g3b6Rwwsy 7YFxSh3Ts8Nkzj4WCWVZal4Ahu4+OFt6fINDrX9Vy2dq0jmbe4S8Iub7l3MUib9BUdmWT2ZxNUdB8 D7vFTrnoA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kewKZ-00005D-3S; Tue, 17 Nov 2020 08:27:15 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kewKV-0008VC-WA for linux-riscv@lists.infradead.org; Tue, 17 Nov 2020 08:27:13 +0000 Received: by mail-pl1-x62f.google.com with SMTP id l11so73669plt.1 for ; Tue, 17 Nov 2020 00:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0w+Bq27/X0GIM1BI/NmY3YCnW8k8aSVxxtLiS5VSHa4=; b=Vl4FdewX3/qjsY+5i8oCei0lR1IhFvHmLxRKBQdOvYK/A1LBq73lxnEW0aMdhSRyhQ ZJXTzWbPyGQAu5e7eb9LyiymBuZ5rFVqzyH5FGaW7M/3YWhcbR+QmseDLrmtqkKA+MAf jbzI7OIews82d9lXzcAlpOLksHU2A1qs8twFVSwmnVNDjHYtfN1cb2kAiuDKYgGjDRMg aDulsNkjtPjIPtNN0dhcd2A+91OlcbWcQqgjTUxeJvN5GdyLSG4uXiCK1k3YLYDHiYTo x+MCXum3b/tKQhXSxF/0EMuy9j0joq0dbI5ramufU7hNvD1NGgaUqUP8kBu5oGM5KpnA EDFA== 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=0w+Bq27/X0GIM1BI/NmY3YCnW8k8aSVxxtLiS5VSHa4=; b=MUuVqLEBEF+FwB7PUcS9f7T0b/689R/Y9/3LrVZks+nasYOsTgdfxPWA7o+kz5ejXZ lNxz8qp3TMn0wwk3uTIJkNOkBGxwJKtF5sC5FSWvEGMuE542FFa6o8Oe6lauhE+BO5uK Jn2va+DCgQZufAaFeRb38984ayyQK4qRl2y+A5RzrYNx8cQHlB6wHNnr/tZ/5kaEyRqq 0KDSRqdV/oDYsucM68XpqElef9m8wNfIVXdrWGnMToXZoljHSLRnMv8H6jXKLd7zlUni TGJ/eSfrb42x2hPiZADpdU7mfQ1WvWjEAW16QJU2hXOpwhx83Ge4tKvSbHysXNiYearK clgA== X-Gm-Message-State: AOAM533aZ27wstHRz6OuzmWJcB6PYRcnVh8ki3ZvEWDUg01UGia8MiiA AiVxr4omEzZKC6QV5G2p7S8= X-Google-Smtp-Source: ABdhPJyfa0OkA1HWcJiLXPFp5EdZ5ns95AOY+lu07uAWijQqDgGlmiHAiCac0tIGDqtfSe7yIGujKQ== X-Received: by 2002:a17:90b:3506:: with SMTP id ls6mr3424114pjb.202.1605601629510; Tue, 17 Nov 2020 00:27:09 -0800 (PST) Received: from btopel-mobl.ger.intel.com ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id c12sm2251671pjs.8.2020.11.17.00.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 00:27:08 -0800 (PST) From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next 3/3] selftests/bpf: Mark tests that require unaligned memory access Date: Tue, 17 Nov 2020 09:26:38 +0100 Message-Id: <20201117082638.43675-4-bjorn.topel@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201117082638.43675-1-bjorn.topel@gmail.com> References: <20201117082638.43675-1-bjorn.topel@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201117_032712_123877_831D8B29 X-CRM114-Status: GOOD ( 14.23 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, xi.wang@gmail.com, luke.r.nels@gmail.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org A lot of tests require unaligned memory access to work. Mark the tests as such, so that they can be avoided on unsupported architectures such as RISC-V. Signed-off-by: Björn Töpel --- .../selftests/bpf/verifier/ctx_sk_lookup.c | 7 +++ .../bpf/verifier/direct_value_access.c | 3 ++ .../testing/selftests/bpf/verifier/map_ptr.c | 1 + .../selftests/bpf/verifier/raw_tp_writable.c | 1 + .../selftests/bpf/verifier/ref_tracking.c | 4 ++ .../testing/selftests/bpf/verifier/regalloc.c | 8 ++++ .../selftests/bpf/verifier/wide_access.c | 46 +++++++++++-------- 7 files changed, 52 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c b/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c index 2ad5f974451c..fb13ca2d5606 100644 --- a/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c +++ b/tools/testing/selftests/bpf/verifier/ctx_sk_lookup.c @@ -266,6 +266,7 @@ .result = REJECT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "invalid 8-byte read from bpf_sk_lookup remote_ip4 field", @@ -292,6 +293,7 @@ .result = REJECT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "invalid 8-byte read from bpf_sk_lookup remote_port field", @@ -305,6 +307,7 @@ .result = REJECT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "invalid 8-byte read from bpf_sk_lookup local_ip4 field", @@ -331,6 +334,7 @@ .result = REJECT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "invalid 8-byte read from bpf_sk_lookup local_port field", @@ -344,6 +348,7 @@ .result = REJECT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, /* invalid 1,2,4-byte reads from 8-byte fields in bpf_sk_lookup */ { @@ -410,6 +415,7 @@ .result = REJECT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "invalid 4-byte unaligned read from bpf_sk_lookup at even offset", @@ -422,6 +428,7 @@ .result = REJECT, .prog_type = BPF_PROG_TYPE_SK_LOOKUP, .expected_attach_type = BPF_SK_LOOKUP, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, /* in-bound and out-of-bound writes to bpf_sk_lookup */ { diff --git a/tools/testing/selftests/bpf/verifier/direct_value_access.c b/tools/testing/selftests/bpf/verifier/direct_value_access.c index 988f46a1a4c7..c0648dc009b5 100644 --- a/tools/testing/selftests/bpf/verifier/direct_value_access.c +++ b/tools/testing/selftests/bpf/verifier/direct_value_access.c @@ -69,6 +69,7 @@ .fixup_map_array_48b = { 1 }, .result = REJECT, .errstr = "R1 min value is outside of the allowed memory range", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "direct map access, write test 7", @@ -195,6 +196,7 @@ .fixup_map_array_48b = { 1, 3 }, .result = REJECT, .errstr = "invalid access to map value, value_size=48 off=47 size=2", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "direct map access, write test 17", @@ -209,6 +211,7 @@ .fixup_map_array_48b = { 1, 3 }, .result = REJECT, .errstr = "invalid access to map value, value_size=48 off=47 size=2", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "direct map access, write test 18", diff --git a/tools/testing/selftests/bpf/verifier/map_ptr.c b/tools/testing/selftests/bpf/verifier/map_ptr.c index 637f9293bda8..b117bdd3806d 100644 --- a/tools/testing/selftests/bpf/verifier/map_ptr.c +++ b/tools/testing/selftests/bpf/verifier/map_ptr.c @@ -44,6 +44,7 @@ .errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN", .result = REJECT, .errstr = "cannot access ptr member ops with moff 0 in struct bpf_map with off 1 size 4", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "bpf_map_ptr: read ops field accepted", diff --git a/tools/testing/selftests/bpf/verifier/raw_tp_writable.c b/tools/testing/selftests/bpf/verifier/raw_tp_writable.c index 95b5d70a1dc1..2978fb5a769d 100644 --- a/tools/testing/selftests/bpf/verifier/raw_tp_writable.c +++ b/tools/testing/selftests/bpf/verifier/raw_tp_writable.c @@ -31,4 +31,5 @@ .fixup_map_hash_8b = { 1, }, .prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, .errstr = "R6 invalid variable buffer offset: off=0, var_off=(0x0; 0xffffffff)", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, diff --git a/tools/testing/selftests/bpf/verifier/ref_tracking.c b/tools/testing/selftests/bpf/verifier/ref_tracking.c index 006b5bd99c08..3b6ee009c00b 100644 --- a/tools/testing/selftests/bpf/verifier/ref_tracking.c +++ b/tools/testing/selftests/bpf/verifier/ref_tracking.c @@ -675,6 +675,7 @@ .prog_type = BPF_PROG_TYPE_SCHED_CLS, .result = REJECT, .errstr = "invalid mem access", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "reference tracking: use ptr from bpf_sk_fullsock() after release", @@ -698,6 +699,7 @@ .prog_type = BPF_PROG_TYPE_SCHED_CLS, .result = REJECT, .errstr = "invalid mem access", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "reference tracking: use ptr from bpf_sk_fullsock(tp) after release", @@ -725,6 +727,7 @@ .prog_type = BPF_PROG_TYPE_SCHED_CLS, .result = REJECT, .errstr = "invalid mem access", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "reference tracking: use sk after bpf_sk_release(tp)", @@ -747,6 +750,7 @@ .prog_type = BPF_PROG_TYPE_SCHED_CLS, .result = REJECT, .errstr = "invalid mem access", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "reference tracking: use ptr from bpf_get_listener_sock() after bpf_sk_release(sk)", diff --git a/tools/testing/selftests/bpf/verifier/regalloc.c b/tools/testing/selftests/bpf/verifier/regalloc.c index 4ad7e05de706..bb0dd89dd212 100644 --- a/tools/testing/selftests/bpf/verifier/regalloc.c +++ b/tools/testing/selftests/bpf/verifier/regalloc.c @@ -21,6 +21,7 @@ .fixup_map_hash_48b = { 4 }, .result = ACCEPT, .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc negative", @@ -71,6 +72,7 @@ .fixup_map_hash_48b = { 4 }, .result = ACCEPT, .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc src_reg negative", @@ -97,6 +99,7 @@ .result = REJECT, .errstr = "invalid access to map value, value_size=48 off=44 size=8", .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc and spill", @@ -126,6 +129,7 @@ .fixup_map_hash_48b = { 4 }, .result = ACCEPT, .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc and spill negative", @@ -156,6 +160,7 @@ .result = REJECT, .errstr = "invalid access to map value, value_size=48 off=48 size=8", .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc three regs", @@ -182,6 +187,7 @@ .fixup_map_hash_48b = { 4 }, .result = ACCEPT, .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc after call", @@ -210,6 +216,7 @@ .fixup_map_hash_48b = { 4 }, .result = ACCEPT, .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc in callee", @@ -240,6 +247,7 @@ .fixup_map_hash_48b = { 4 }, .result = ACCEPT, .prog_type = BPF_PROG_TYPE_TRACEPOINT, + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "regalloc, spill, JEQ", diff --git a/tools/testing/selftests/bpf/verifier/wide_access.c b/tools/testing/selftests/bpf/verifier/wide_access.c index ccade9312d21..55af248efa93 100644 --- a/tools/testing/selftests/bpf/verifier/wide_access.c +++ b/tools/testing/selftests/bpf/verifier/wide_access.c @@ -1,4 +1,4 @@ -#define BPF_SOCK_ADDR_STORE(field, off, res, err) \ +#define BPF_SOCK_ADDR_STORE(field, off, res, err, flgs) \ { \ "wide store to bpf_sock_addr." #field "[" #off "]", \ .insns = { \ @@ -11,31 +11,36 @@ .prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \ .expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \ .errstr = err, \ + .flags = flgs, \ } /* user_ip6[0] is u64 aligned */ BPF_SOCK_ADDR_STORE(user_ip6, 0, ACCEPT, - NULL), + NULL, 0), BPF_SOCK_ADDR_STORE(user_ip6, 1, REJECT, - "invalid bpf_context access off=12 size=8"), + "invalid bpf_context access off=12 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), BPF_SOCK_ADDR_STORE(user_ip6, 2, ACCEPT, - NULL), + NULL, 0), BPF_SOCK_ADDR_STORE(user_ip6, 3, REJECT, - "invalid bpf_context access off=20 size=8"), + "invalid bpf_context access off=20 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), /* msg_src_ip6[0] is _not_ u64 aligned */ BPF_SOCK_ADDR_STORE(msg_src_ip6, 0, REJECT, - "invalid bpf_context access off=44 size=8"), + "invalid bpf_context access off=44 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), BPF_SOCK_ADDR_STORE(msg_src_ip6, 1, ACCEPT, - NULL), + NULL, 0), BPF_SOCK_ADDR_STORE(msg_src_ip6, 2, REJECT, - "invalid bpf_context access off=52 size=8"), + "invalid bpf_context access off=52 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT, - "invalid bpf_context access off=56 size=8"), + "invalid bpf_context access off=56 size=8", 0), #undef BPF_SOCK_ADDR_STORE -#define BPF_SOCK_ADDR_LOAD(field, off, res, err) \ +#define BPF_SOCK_ADDR_LOAD(field, off, res, err, flgs) \ { \ "wide load from bpf_sock_addr." #field "[" #off "]", \ .insns = { \ @@ -48,26 +53,31 @@ BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT, .prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \ .expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \ .errstr = err, \ + .flags = flgs, \ } /* user_ip6[0] is u64 aligned */ BPF_SOCK_ADDR_LOAD(user_ip6, 0, ACCEPT, - NULL), + NULL, 0), BPF_SOCK_ADDR_LOAD(user_ip6, 1, REJECT, - "invalid bpf_context access off=12 size=8"), + "invalid bpf_context access off=12 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), BPF_SOCK_ADDR_LOAD(user_ip6, 2, ACCEPT, - NULL), + NULL, 0), BPF_SOCK_ADDR_LOAD(user_ip6, 3, REJECT, - "invalid bpf_context access off=20 size=8"), + "invalid bpf_context access off=20 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), /* msg_src_ip6[0] is _not_ u64 aligned */ BPF_SOCK_ADDR_LOAD(msg_src_ip6, 0, REJECT, - "invalid bpf_context access off=44 size=8"), + "invalid bpf_context access off=44 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), BPF_SOCK_ADDR_LOAD(msg_src_ip6, 1, ACCEPT, - NULL), + NULL, 0), BPF_SOCK_ADDR_LOAD(msg_src_ip6, 2, REJECT, - "invalid bpf_context access off=52 size=8"), + "invalid bpf_context access off=52 size=8", + F_NEEDS_EFFICIENT_UNALIGNED_ACCESS), BPF_SOCK_ADDR_LOAD(msg_src_ip6, 3, REJECT, - "invalid bpf_context access off=56 size=8"), + "invalid bpf_context access off=56 size=8", 0), #undef BPF_SOCK_ADDR_LOAD