From patchwork Thu Apr 20 23:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13219283 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C482CC77B78 for ; Thu, 20 Apr 2023 23:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232852AbjDTXYe (ORCPT ); Thu, 20 Apr 2023 19:24:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232354AbjDTXYd (ORCPT ); Thu, 20 Apr 2023 19:24:33 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDEED3AB5 for ; Thu, 20 Apr 2023 16:24:31 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4edc114c716so1007103e87.1 for ; Thu, 20 Apr 2023 16:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682033070; x=1684625070; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5g9NI7uSmY9Z7i5CsMM46mgnhfsWo738KkWe3w1sOT0=; b=F56zEiGNSqqREEo3rorROdX961Kzmr9kZqWRWKzfjTWncWJPe9l3SLFoB+43lNNUqt u67/V1Yb9nHC44NFo+vwy0AkZmHZ/xB5DJE4xMFTweFSYx+twB/hWMyU5ibkFfSHeRIU rSreV0E/cG6DlVBDUpDJW/6YpLT5uAY0+Ys1ZVjpm1uxpHzZoVl60TDMPuCyDVJLOJX6 qn/d/IkvmTJ5gjW9gtnalX8+iO26ecdzVjlX2Vg7rkbFV0Bj50XKbZ6oS9MDUlFYAFK3 klYTRfPhvuhF65/Y06sQGhaApTjqysn4j/nICBTj/rXuZ9yWaboegVZGzw4YdyxCIQNU IEtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682033070; x=1684625070; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5g9NI7uSmY9Z7i5CsMM46mgnhfsWo738KkWe3w1sOT0=; b=XehRXKf3qfEbVuLsqz092qMlbg6j2nyj91sKt2ssjqe0HUSVF9WtZUhglzOBTbqaHs sm+bg72sxIvbxTfjvpR2eK7bGubZvTWh7gz0dX/UT5tjNchqdRX90PjlMKYbrHapAea0 dfDg6I9jaa/YLythcpGuaNgQxMGMLjtC8TobzwjjrmdXCHLJopKV2pSXgwSkvnnAZh4g pLX3OKIDRw1GfLUdeh9eUdJHKIHZQCkUfTKHCm+6E1mrvwLEsNBVMf2zpi076eKvESFl 91uBbDsX7cfzR0jXzPLILm4QwI8ozJ2CKjj7D8cF3Sq177naFGknZonTd4pZpkeJlFcX 3OBQ== X-Gm-Message-State: AAQBX9cANvso6zX7RUHyxwp51Y2FgxkG842ZZlgoMnqNWZy8HvpVIwYG +nkh8Rtnp3BN+JnLd2Ty16XJcuX4v8UoLw== X-Google-Smtp-Source: AKy350bSB8P2IgUuRlLiRfRbxk4tyiHG0Y+gVJKKjpVj7CBK4I0plaLDICqVVpaZZK8A1We+2RaWXw== X-Received: by 2002:a19:7613:0:b0:4ec:809c:c64c with SMTP id c19-20020a197613000000b004ec809cc64cmr829646lff.20.1682033069826; Thu, 20 Apr 2023 16:24:29 -0700 (PDT) Received: from bigfoot.. (host-176-36-0-241.b024.la.net.ua. [176.36.0.241]) by smtp.gmail.com with ESMTPSA id z2-20020ac25de2000000b004ec89c94f04sm360227lfq.155.2023.04.20.16.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 16:24:29 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yhs@fb.com, Eduard Zingerman , Florian Westphal Subject: [PATCH bpf-next 1/4] selftests/bpf: disable program test run for progs/refcounted_kptr.c Date: Fri, 21 Apr 2023 02:23:14 +0300 Message-Id: <20230420232317.2181776-2-eddyz87@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420232317.2181776-1-eddyz87@gmail.com> References: <20230420232317.2181776-1-eddyz87@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Florian Westphal found a bug in test_loader.c processing of __retval tag. Because of this bug the function test_loader.c:do_prog_test_run() never executed and all __retval test tags were ignored. This hid an issue with progs/refcounted_kptr.c tests. When __retval tag bug is fixed and refcounted_kptr.c tests are run kernel reports various issues and eventually hangs. Shortest reproducer is the following command run a few times: $ for i in $(seq 1 4); do (./test_progs --allow=refcounted_kptr &); done Commenting out __retval tags for these tests until this issue is resolved. Reported-by: Florian Westphal Link: https://lore.kernel.org/bpf/f4c4aee644425842ee6aa8edf1da68f0a8260e7c.camel@gmail.com/T/ Signed-off-by: Eduard Zingerman --- tools/testing/selftests/bpf/progs/refcounted_kptr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/refcounted_kptr.c b/tools/testing/selftests/bpf/progs/refcounted_kptr.c index 1d348a225140..b6b2d4f97b19 100644 --- a/tools/testing/selftests/bpf/progs/refcounted_kptr.c +++ b/tools/testing/selftests/bpf/progs/refcounted_kptr.c @@ -219,7 +219,7 @@ static long __read_from_unstash(int idx) #define INSERT_READ_BOTH(rem_tree, rem_list, desc) \ SEC("tc") \ __description(desc) \ -__success __retval(579) \ +__success /* __retval(579) temporarily disabled */ \ long insert_and_remove_tree_##rem_tree##_list_##rem_list(void *ctx) \ { \ long err, tree_data, list_data; \ @@ -258,7 +258,7 @@ INSERT_READ_BOTH(false, true, "insert_read_both: remove from list"); #define INSERT_READ_BOTH(rem_tree, rem_list, desc) \ SEC("tc") \ __description(desc) \ -__success __retval(579) \ +__success /* __retval(579) temporarily disabled */ \ long insert_and_remove_lf_tree_##rem_tree##_list_##rem_list(void *ctx) \ { \ long err, tree_data, list_data; \ @@ -296,7 +296,7 @@ INSERT_READ_BOTH(false, true, "insert_read_both_list_first: remove from list"); #define INSERT_DOUBLE_READ_AND_DEL(read_fn, read_root, desc) \ SEC("tc") \ __description(desc) \ -__success __retval(-1) \ +__success /* temporarily __retval(-1) disabled */ \ long insert_double_##read_fn##_and_del_##read_root(void *ctx) \ { \ long err, list_data; \ @@ -329,7 +329,7 @@ INSERT_DOUBLE_READ_AND_DEL(__read_from_list, head, "insert_double_del: 2x read-a #define INSERT_STASH_READ(rem_tree, desc) \ SEC("tc") \ __description(desc) \ -__success __retval(84) \ +__success /* __retval(84) temporarily disabled */ \ long insert_rbtree_and_stash__del_tree_##rem_tree(void *ctx) \ { \ long err, tree_data, map_data; \ From patchwork Thu Apr 20 23:23:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13219282 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98DF7C7618E for ; Thu, 20 Apr 2023 23:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230304AbjDTXYf (ORCPT ); Thu, 20 Apr 2023 19:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232942AbjDTXYe (ORCPT ); Thu, 20 Apr 2023 19:24:34 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415F51BCE for ; Thu, 20 Apr 2023 16:24:33 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4ec9c7c6986so994546e87.0 for ; Thu, 20 Apr 2023 16:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682033071; x=1684625071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HzWSdXs5P+bPGi5Kwi+OhAIz+8fFAUMm/RT7jUF+fqY=; b=VeTUnl3biuY+gePiCG6fs6Zho5Sk97cyaC4qfMpbZHalUC3zw0oubLEBfzn76rM/HK 6wKTu4wORgDOSzJ6csRTJhnEcGjYcVDVMFFLQcBahCDjLZPjnvz9LcL7sP5z/VMfLb79 eDRQizwQCkRz57ESBEeMtTKlb193oLldTdJeTYi3dm8+FWvJWYNfqtdnFBFYgndSL86D cEYqbEzY2NLYgR6KOiZ0i5GuII7uYkDDFvWncmsg1a/dkrrFQZJPUfZkGLLxtQO9ASNX bm2fX6qg4jQdP7eLuW4vPHLgOxZtlerco4Xhf8wvuMgaEeTyRVkYiow7p0dui0HbPlIp NvzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682033071; x=1684625071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HzWSdXs5P+bPGi5Kwi+OhAIz+8fFAUMm/RT7jUF+fqY=; b=HLkPWwuW3/a7eqFcpDJ7X1crcNeuyOUcyE0qG8xQyrfSvFgAarewsE8dNp/TgBSs0q pAarg4RzO0PaBtMgV32tzdgIMmQMm5dOb3TJSJXezPoxGANnGgjhbL7xeLJbDqAUKVJ7 UUehXqdcBPZgbcZrvXLthgiBgzmV5ARagISHLU1CNlWj/X+R5qvl9KYqTv51ANHCPr7l DvPrtwswA1JgXtw0rgJTzkQKcBhXxRg4V7v4YhK6Y8uyT8X3I5B6C9DDqND6WdWjH46Q b/Im/bokvLhnjxXNONt3fatMs991NDhCTvAixTB2+16hBqwE/PSaiddX7ud2Mjdln8VQ nFPA== X-Gm-Message-State: AAQBX9d8B6GyTs9YblPkpn/Y4lRO2wiIfXXN9FAybBjIP90S38hlWJC/ M4eO48SCnfzMQpJufjEf+sOc5BauBn675Q== X-Google-Smtp-Source: AKy350Yv4KSoNd7kniMhyZO5myt+SIJdBccj5Kk9SfIzTuhD8veOCQcsYmkyXVcpy2JfGiRYdaJjrw== X-Received: by 2002:ac2:5df0:0:b0:4ea:f636:6d02 with SMTP id z16-20020ac25df0000000b004eaf6366d02mr940382lfq.18.1682033071036; Thu, 20 Apr 2023 16:24:31 -0700 (PDT) Received: from bigfoot.. (host-176-36-0-241.b024.la.net.ua. [176.36.0.241]) by smtp.gmail.com with ESMTPSA id z2-20020ac25de2000000b004ec89c94f04sm360227lfq.155.2023.04.20.16.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 16:24:30 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yhs@fb.com, Eduard Zingerman , Florian Westphal Subject: [PATCH bpf-next 2/4] selftests/bpf: fix __retval() being always ignored Date: Fri, 21 Apr 2023 02:23:15 +0300 Message-Id: <20230420232317.2181776-3-eddyz87@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420232317.2181776-1-eddyz87@gmail.com> References: <20230420232317.2181776-1-eddyz87@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Florian Westphal found a bug in and suggested a fix for test_loader.c processing of __retval tag. Because of this bug the function test_loader.c:do_prog_test_run() never executed and all __retval test tags were ignored. If this bug is fixed a number of test cases from progs/verifier_array_access.c fail with retval not matching the expected value. This test was recently converted to use test_loader.c and inline assembly in [1]. When doing the conversion I missed the important detail of test_verifier.c operation: when it creates fixup_map_array_ro, fixup_map_array_wo and fixup_map_array_small it populates these maps with a dummy record. Disabling the __retval checks for the affected verifier_array_access in this commit to avoid false-postivies in any potential bisects. The issue is addressed in the next patch. I verified that the __retval tags are now respected by changing expected return values for all tests annotated with __retval, and checking that these tests started to fail. [1] https://lore.kernel.org/bpf/20230325025524.144043-1-eddyz87@gmail.com/ Fixes: 19a8e06f5f91 ("selftests/bpf: Tests execution support for test_loader.c") Reported-by: Florian Westphal Link: https://lore.kernel.org/bpf/f4c4aee644425842ee6aa8edf1da68f0a8260e7c.camel@gmail.com/T/ Signed-off-by: Eduard Zingerman --- tools/testing/selftests/bpf/progs/verifier_array_access.c | 4 ++-- tools/testing/selftests/bpf/test_loader.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/verifier_array_access.c b/tools/testing/selftests/bpf/progs/verifier_array_access.c index 95d7ecc12963..fceeeef78721 100644 --- a/tools/testing/selftests/bpf/progs/verifier_array_access.c +++ b/tools/testing/selftests/bpf/progs/verifier_array_access.c @@ -330,7 +330,7 @@ l0_%=: exit; \ SEC("socket") __description("valid read map access into a read-only array 1") -__success __success_unpriv __retval(28) +__success __success_unpriv /* __retval(28) temporarily disable */ __naked void a_read_only_array_1_1(void) { asm volatile (" \ @@ -351,7 +351,7 @@ l0_%=: exit; \ SEC("tc") __description("valid read map access into a read-only array 2") -__success __retval(65507) +__success /* __retval(65507) temporarily disable */ __naked void a_read_only_array_2_1(void) { asm volatile (" \ diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c index 47e9e076bc8f..e2a1bdc5a570 100644 --- a/tools/testing/selftests/bpf/test_loader.c +++ b/tools/testing/selftests/bpf/test_loader.c @@ -587,7 +587,7 @@ void run_subtest(struct test_loader *tester, /* For some reason test_verifier executes programs * with all capabilities restored. Do the same here. */ - if (!restore_capabilities(&caps)) + if (restore_capabilities(&caps)) goto tobj_cleanup; do_prog_test_run(bpf_program__fd(tprog), &retval); From patchwork Thu Apr 20 23:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13219284 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCBF0C77B76 for ; Thu, 20 Apr 2023 23:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232942AbjDTXYg (ORCPT ); Thu, 20 Apr 2023 19:24:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232354AbjDTXYf (ORCPT ); Thu, 20 Apr 2023 19:24:35 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B0DD2697 for ; Thu, 20 Apr 2023 16:24:34 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4ec8149907aso1008193e87.1 for ; Thu, 20 Apr 2023 16:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682033072; x=1684625072; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hpLh1YPaAj9o+5fwNYt3O9O1Ii34BKqLkycFi7e+Xos=; b=U2DgZR7lReBFwdPXwVR7okvu/r+vD6Li0gaIdFcKKGiCKeRb3Pv7V4cVUCkGoispX/ ciit5J+5NsGx4xIKYpTWf8aPOwQoi3I5Dam0LY8rcugLGJyaDpPbCJCstm/lgIDFiEh3 0IqZ+NY4ETonvitd5pwW06mcGSmvriLthlGMj+ZyHRfgdOsIMBgP9rO7prCcrT/mfL6s iP1svJ1kxDof7nkXWxaht3rtU0OGHu4WeffMWLOAvg+xFIzMeCTfSPuB1Bn6ZyO05utT 0VKhomY9Cbjcj6nzec5A6qx6ptF4j/9ekfT4tgIzsIdqHLEeypUV4qVcXajfS4sdULMD JQtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682033072; x=1684625072; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hpLh1YPaAj9o+5fwNYt3O9O1Ii34BKqLkycFi7e+Xos=; b=MzqbfJwi0scsidZh36xRCniXbuf4JD3XVfx/kOawld0uhp1wHKMbqValOcmondLfk/ 0RU8ZAKIOynQSOwBFgMhUcH3ehue8EfyGWMV20eMcaooHDKyRuB1pEqsOOD0YnC8uHrQ /OomStbFcvyGYXjZWJaahGSeANoqsd56IKc7wbsT6Hk2zjXrBlv9peE9bvoW4RHNZunp pY4tInq7xHrRDnZEyyB9JF3PKggTE8PCTIf2coZuoAjs6zVxfU2QbdED5jB4zfXSF2mw 02nCeBES3/U58QNtwnmFfy0sADG2sJhN2vuB6u2wt2RIRoB/qB8LUs+po8dMME7O5UxI GB7w== X-Gm-Message-State: AAQBX9de313RbXV2lG9K46Ex9jjoTof1OZvjuxFVlLH5zU9VEKIOVOMW TjJFiYL2GomJ/TIQZsqGE+2/7t0Dn7Q= X-Google-Smtp-Source: AKy350YF1njc1OWl1l9mOgleYY9HuNpEyIYUJhFgLmIcwf04fuPhx3Iz4RL6gTu4Cqt4KW3rb7fEkg== X-Received: by 2002:ac2:4314:0:b0:4eb:7e:1fa5 with SMTP id l20-20020ac24314000000b004eb007e1fa5mr654815lfh.8.1682033072597; Thu, 20 Apr 2023 16:24:32 -0700 (PDT) Received: from bigfoot.. (host-176-36-0-241.b024.la.net.ua. [176.36.0.241]) by smtp.gmail.com with ESMTPSA id z2-20020ac25de2000000b004ec89c94f04sm360227lfq.155.2023.04.20.16.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 16:24:31 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yhs@fb.com, Eduard Zingerman Subject: [PATCH bpf-next 3/4] selftests/bpf: add pre bpf_prog_test_run_opts() callback for test_loader Date: Fri, 21 Apr 2023 02:23:16 +0300 Message-Id: <20230420232317.2181776-4-eddyz87@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420232317.2181776-1-eddyz87@gmail.com> References: <20230420232317.2181776-1-eddyz87@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net When a test case is annotated with __retval tag the test_loader engine would use libbpf's bpf_prog_test_run_opts() to do a test run of the program and compare retvals. This commit allows to perform arbitrary actions on bpf object right before test loader invokes bpf_prog_test_run_opts(). This could be used to setup some state for program execution, e.g. fill some maps. Signed-off-by: Eduard Zingerman --- tools/testing/selftests/bpf/test_loader.c | 8 ++++++++ tools/testing/selftests/bpf/test_progs.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c index e2a1bdc5a570..40c9b7d532c4 100644 --- a/tools/testing/selftests/bpf/test_loader.c +++ b/tools/testing/selftests/bpf/test_loader.c @@ -590,6 +590,14 @@ void run_subtest(struct test_loader *tester, if (restore_capabilities(&caps)) goto tobj_cleanup; + if (tester->pre_execution_cb) { + err = tester->pre_execution_cb(tobj); + if (err) { + PRINT_FAIL("pre_execution_cb failed: %d\n", err); + goto tobj_cleanup; + } + } + do_prog_test_run(bpf_program__fd(tprog), &retval); if (retval != subspec->retval && subspec->retval != POINTER_VALUE) { PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval); diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h index 10ba43250668..0ed3134333d4 100644 --- a/tools/testing/selftests/bpf/test_progs.h +++ b/tools/testing/selftests/bpf/test_progs.h @@ -424,14 +424,23 @@ int get_bpf_max_tramp_links(void); #define BPF_TESTMOD_TEST_FILE "/sys/kernel/bpf_testmod" +typedef int (*pre_execution_cb)(struct bpf_object *obj); + struct test_loader { char *log_buf; size_t log_buf_sz; size_t next_match_pos; + pre_execution_cb pre_execution_cb; struct bpf_object *obj; }; +static inline void test_loader__set_pre_execution_cb(struct test_loader *tester, + pre_execution_cb cb) +{ + tester->pre_execution_cb = cb; +} + typedef const void *(*skel_elf_bytes_fn)(size_t *sz); extern void test_loader__run_subtests(struct test_loader *tester, From patchwork Thu Apr 20 23:23:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Zingerman X-Patchwork-Id: 13219285 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57EC0C77B7F for ; Thu, 20 Apr 2023 23:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232960AbjDTXYi (ORCPT ); Thu, 20 Apr 2023 19:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232354AbjDTXYh (ORCPT ); Thu, 20 Apr 2023 19:24:37 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8EFA4EEF for ; Thu, 20 Apr 2023 16:24:35 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4ec816c9b62so993253e87.2 for ; Thu, 20 Apr 2023 16:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682033074; x=1684625074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DAuXggJ3lgOocGa5UKypiuaKvz2jibuoBb0WOXcW4xQ=; b=MJsY2zv+8LFKzlj1qDlMZUknNPeaRdEWvJOV52Hs+XwokA1d6qhk87JKjZbhswn8zj p8cPnRuzfj21rzc74XQui3Dm+XIvASLdPH2ln+zPkE6AqHNYAIs0hFRqz1IHg1fOLTms 17sU9yCrAVKoHgOgdU8Pl3r+Kgy8XUFOHY5DdIvWmEzpgcL1koH1tnbeQtfRdrVOBn9C wrenlWyd2mQOh2v5NmxV5FpzKU6TUcMrxfmJdlXSPTmw3MVw8TfsoZ7ZlHOwOxx53/01 Y0WPis/N4HEfVNJ7B1SzguXG7QGirdPGLt+mFmPS4knmx2VTWh1vp6Yscm7e9b16Nlmc 18dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682033074; x=1684625074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DAuXggJ3lgOocGa5UKypiuaKvz2jibuoBb0WOXcW4xQ=; b=lbIHqB2a5duNVbj0PB56VP/gJam0Hjr2vb3c63HwpLVI1Z6pgFMEHyjWgUGZjonkb0 +/GdQXTm6ljrggPr3YQC/KMw4zOSE8nZ86DlzYD18Z5ER+7S4gawWLPUx5MYnffsdef5 eNZTRMmFll82lczsxRerrNgV8slTu8m5x1Vjw6TMq8OjQfH2jviUsJcOdFN+nNLLhOWX aKdj9o9yPBBQuSbuE91YU4Pp4GXyXXOnw5mwNYs0Vpw0UpLiV1ia8+Fu3hqaRTn2+arD 8dgTSEvVvTU+livgJP+M9bIARmRivF/GuT9VCtWlx8ZWsNqNzMDrmfe9kov2Z8rJWtzB LjWQ== X-Gm-Message-State: AAQBX9dxa0fOBhofeGuKjMcGQIUvfVzmN1sbEhuR9j7v+B2YV3MCGOJ9 BXdKcZzsqVr8/fAxnM3QHJj346+dONM= X-Google-Smtp-Source: AKy350Zz3RQxQtlqfkiW/IS8v5Fb7uEVBiDs/+ieqj4d4bY4uOqHMOetyknJaOPpBjIHDeI6coV4tA== X-Received: by 2002:ac2:490e:0:b0:4eb:2d47:603 with SMTP id n14-20020ac2490e000000b004eb2d470603mr834079lfi.47.1682033073864; Thu, 20 Apr 2023 16:24:33 -0700 (PDT) Received: from bigfoot.. (host-176-36-0-241.b024.la.net.ua. [176.36.0.241]) by smtp.gmail.com with ESMTPSA id z2-20020ac25de2000000b004ec89c94f04sm360227lfq.155.2023.04.20.16.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 16:24:33 -0700 (PDT) From: Eduard Zingerman To: bpf@vger.kernel.org, ast@kernel.org Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com, yhs@fb.com, Eduard Zingerman Subject: [PATCH bpf-next 4/4] selftests/bpf: populate map_array_ro map for verifier_array_access test Date: Fri, 21 Apr 2023 02:23:17 +0300 Message-Id: <20230420232317.2181776-5-eddyz87@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420232317.2181776-1-eddyz87@gmail.com> References: <20230420232317.2181776-1-eddyz87@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Two test cases: - "valid read map access into a read-only array 1" and - "valid read map access into a read-only array 2" Expect that map_array_ro map is filled with mock data. This logic was not taken into acount during initial test conversion. This commit modifies prog_tests/verifier.c entry point for this test to fill the map. Fixes: a3c830ae0209 ("selftests/bpf: verifier/array_access.c converted to inline assembly") Signed-off-by: Eduard Zingerman --- .../selftests/bpf/prog_tests/verifier.c | 42 +++++++++++++++++-- .../bpf/progs/verifier_array_access.c | 4 +- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c index 25bc8958dbfe..7c68d78da9ea 100644 --- a/tools/testing/selftests/bpf/prog_tests/verifier.c +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c @@ -44,8 +44,17 @@ #include "verifier_xdp.skel.h" #include "verifier_xdp_direct_packet_access.skel.h" +#define MAX_ENTRIES 11 + +struct test_val { + unsigned int index; + int foo[MAX_ENTRIES]; +}; + __maybe_unused -static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory) +static void run_tests_aux(const char *skel_name, + skel_elf_bytes_fn elf_bytes_factory, + pre_execution_cb pre_execution_cb) { struct test_loader tester = {}; __u64 old_caps; @@ -58,6 +67,7 @@ static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_fac return; } + test_loader__set_pre_execution_cb(&tester, pre_execution_cb); test_loader__run_subtests(&tester, skel_name, elf_bytes_factory); test_loader_fini(&tester); @@ -66,10 +76,9 @@ static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_fac PRINT_FAIL("failed to restore CAP_SYS_ADMIN: %i, %s\n", err, strerror(err)); } -#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes) +#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL) void test_verifier_and(void) { RUN(verifier_and); } -void test_verifier_array_access(void) { RUN(verifier_array_access); } void test_verifier_basic_stack(void) { RUN(verifier_basic_stack); } void test_verifier_bounds_deduction(void) { RUN(verifier_bounds_deduction); } void test_verifier_bounds_deduction_non_const(void) { RUN(verifier_bounds_deduction_non_const); } @@ -108,3 +117,30 @@ void test_verifier_var_off(void) { RUN(verifier_var_off); } void test_verifier_xadd(void) { RUN(verifier_xadd); } void test_verifier_xdp(void) { RUN(verifier_xdp); } void test_verifier_xdp_direct_packet_access(void) { RUN(verifier_xdp_direct_packet_access); } + +static int init_array_access_maps(struct bpf_object *obj) +{ + struct bpf_map *array_ro; + struct test_val value = { + .index = (6 + 1) * sizeof(int), + .foo[6] = 0xabcdef12, + }; + int err, key = 0; + + array_ro = bpf_object__find_map_by_name(obj, "map_array_ro"); + if (!ASSERT_OK_PTR(array_ro, "lookup map_array_ro")) + return -EINVAL; + + err = bpf_map_update_elem(bpf_map__fd(array_ro), &key, &value, 0); + if (!ASSERT_OK(err, "map_array_ro update")) + return err; + + return 0; +} + +void test_verifier_array_access(void) +{ + run_tests_aux("verifier_array_access", + verifier_array_access__elf_bytes, + init_array_access_maps); +} diff --git a/tools/testing/selftests/bpf/progs/verifier_array_access.c b/tools/testing/selftests/bpf/progs/verifier_array_access.c index fceeeef78721..95d7ecc12963 100644 --- a/tools/testing/selftests/bpf/progs/verifier_array_access.c +++ b/tools/testing/selftests/bpf/progs/verifier_array_access.c @@ -330,7 +330,7 @@ l0_%=: exit; \ SEC("socket") __description("valid read map access into a read-only array 1") -__success __success_unpriv /* __retval(28) temporarily disable */ +__success __success_unpriv __retval(28) __naked void a_read_only_array_1_1(void) { asm volatile (" \ @@ -351,7 +351,7 @@ l0_%=: exit; \ SEC("tc") __description("valid read map access into a read-only array 2") -__success /* __retval(65507) temporarily disable */ +__success __retval(65507) __naked void a_read_only_array_2_1(void) { asm volatile (" \