From patchwork Wed Oct 12 23:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 13005518 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 CD920C4332F for ; Wed, 12 Oct 2022 23:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbiJLXUb (ORCPT ); Wed, 12 Oct 2022 19:20:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbiJLXUa (ORCPT ); Wed, 12 Oct 2022 19:20:30 -0400 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772A8B8C0E; Wed, 12 Oct 2022 16:20:29 -0700 (PDT) Received: by mail-qt1-f177.google.com with SMTP id z8so67985qtv.5; Wed, 12 Oct 2022 16:20:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=S9b28V7P/p+ltszS+L5057qYj43+A9hBHY9xbUGqv+o=; b=yv1OaDzw5DkrGqsmOQApbeWlNd73zvUkSDGuOt2cWE9bAoEWMgijgQuobmQYte+A2C 1BYKFLC/F7+rf+ztRU+LNLKc6G3TCxEbrh03/++FKUJj4+b5KGuPlylfgSRY7knTQL+4 lOLxoy+6fvF1HdQFg28chV3f2JfeDC59H3pusEkAH2JV/thTp8jUulAsnUMOPn+hW7Ba PSCd+nTpIYH8vaKKLkafOzmLZvdmx6EqmQmmgv2OtcHDNqKtQPu8FRN3rB51DBMqpcTO qkigFuDdUPGVXHWjmeEGaWr9V+YQusb1wf015bsLWteIh85uWBxToC3Pxolf5eeEp0OT Fa4A== X-Gm-Message-State: ACrzQf1+efxgCn1XmYoAZswLNhIEZ+TEFT2iSb198RS9FCmx/dfQN/SJ jbWqAvnGhUJAAA6Wlu6kk5/FCN9VWzPiFQ== X-Google-Smtp-Source: AMsMyM7FEK8MYS+xJIppJ6NGURsKtXSO8Fz1EqGg29JqrkiB7B73plRSv1iXRxm6XT9/Iy7Miggmcw== X-Received: by 2002:a05:622a:1047:b0:35c:c042:194c with SMTP id f7-20020a05622a104700b0035cc042194cmr25971495qte.484.1665616828428; Wed, 12 Oct 2022 16:20:28 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1a0b]) by smtp.gmail.com with ESMTPSA id l13-20020ac84ccd000000b00399edda03dfsm7856014qtv.67.2022.10.12.16.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 16:20:28 -0700 (PDT) From: David Vernet To: bpf@vger.kernel.org Cc: andrii@kernel.org, ast@kernel.org, martin.lau@linux.dev, daniel@iogearbox.net, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/2] bpf: Allow bpf_user_ringbuf_drain() callbacks to return 1 Date: Wed, 12 Oct 2022 18:20:14 -0500 Message-Id: <20221012232015.1510043-2-void@manifault.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221012232015.1510043-1-void@manifault.com> References: <20221012232015.1510043-1-void@manifault.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The bpf_user_ringbuf_drain() helper function allows a BPF program to specify a callback that is invoked when draining entries from a BPF_MAP_TYPE_USER_RINGBUF ring buffer map. The API is meant to allow the callback to return 0 if it wants to continue draining samples, and 1 if it's done draining. Unfortunately, bpf_user_ringbuf_drain() landed shortly after commit 1bfe26fb0827 ("bpf: Add verifier support for custom callback return range"), which changed the default behavior of callbacks to only support returning 0. This patch corrects that oversight by allowing bpf_user_ringbuf_drain() callbacks to return 0 or 1. A follow-on patch will update the user_ringbuf selftests to also return 1 from a bpf_user_ringbuf_drain() callback to prevent this from regressing in the future. Fixes: 205715673844 ("bpf: Add bpf_user_ringbuf_drain() helper") Signed-off-by: David Vernet --- kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 6f6d2d511c06..9ab7188d8f68 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -6946,6 +6946,7 @@ static int set_user_ringbuf_callback_state(struct bpf_verifier_env *env, __mark_reg_not_init(env, &callee->regs[BPF_REG_5]); callee->in_callback_fn = true; + callee->callback_ret_range = tnum_range(0, 1); return 0; } From patchwork Wed Oct 12 23:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 13005519 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 2C998C4332F for ; Wed, 12 Oct 2022 23:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229557AbiJLXUk (ORCPT ); Wed, 12 Oct 2022 19:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbiJLXUg (ORCPT ); Wed, 12 Oct 2022 19:20:36 -0400 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13A2412C8AD; Wed, 12 Oct 2022 16:20:33 -0700 (PDT) Received: by mail-qv1-f50.google.com with SMTP id de14so277956qvb.5; Wed, 12 Oct 2022 16:20:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=5RI+uFM46qF/V3OLGAUZkNuVPUk2lR5v43Hgy7iN+90=; b=DUwkiUstHOFr1bFFLSdFHoz4CCOxIKKu/kpOklCyBCwSjNgYPwQhCfX3RpxzCIJSpi WBpLZBdKqLWKcQNkI5ePxT2n1rw9oF+xTVohGwIfHB7p0iBx5+ws9BvcrIGn7fW8Jc2g k5HVZpN3G7VjPAXtJELpGe/NJieGFjHevdzZMh4gUr+GjOJaI9lp4XNCT94DZRi/7yNN yNj56v5+sM3EE33zvhM+nwukv/mLhwRJmKNmdSmn2knaMMaT2fMRTTwkr4XqnoAUtmvz M/3Drkw/imh57TFYjy7FZxD4uMudnBLD/QFrlp9rwgrhgcUZfa1hUrr4EFyNVS1OHoUM tFjA== X-Gm-Message-State: ACrzQf32znjon7w2Ll8BSmMZdgyUo95KFSBwG30jX9nbUpARWdayDTEH kk+mZbnEUxqzmjLP2XlgeszglpZmid0UpA== X-Google-Smtp-Source: AMsMyM7TRUZ7Cy1Fykzqh6Qox21zRu2D42eDG4tegWq+D6ercUhHdQDQbXIUA7DDKLnOetqsyMIv8A== X-Received: by 2002:a05:6214:2a8e:b0:4b1:c79e:d58 with SMTP id jr14-20020a0562142a8e00b004b1c79e0d58mr25392643qvb.113.1665616832574; Wed, 12 Oct 2022 16:20:32 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1a0b]) by smtp.gmail.com with ESMTPSA id t12-20020a37aa0c000000b006eeb25369e9sm894730qke.25.2022.10.12.16.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 16:20:32 -0700 (PDT) From: David Vernet To: bpf@vger.kernel.org Cc: andrii@kernel.org, ast@kernel.org, martin.lau@linux.dev, daniel@iogearbox.net, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/2] selftests/bpf: Make bpf_user_ringbuf_drain() selftest callback return 1 Date: Wed, 12 Oct 2022 18:20:15 -0500 Message-Id: <20221012232015.1510043-3-void@manifault.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221012232015.1510043-1-void@manifault.com> References: <20221012232015.1510043-1-void@manifault.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net In commit 1bfe26fb0827 ("bpf: Add verifier support for custom callback return range"), the verifier was updated to require callbacks to BPF helpers to explicitly specify the range of values that can be returned. bpf_user_ringbuf_drain() was merged after this in commit 205715673844 ("bpf: Add bpf_user_ringbuf_drain() helper"), and this change in default behavior was missed. This patch updates the BPF_MAP_TYPE_USER_RINGBUF selftests to also return 1 from a bpf_user_ringbuf_drain() callback so as to properly test this going forward. Signed-off-by: David Vernet --- tools/testing/selftests/bpf/progs/user_ringbuf_success.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/user_ringbuf_success.c b/tools/testing/selftests/bpf/progs/user_ringbuf_success.c index 099c23d9aa21..b39093dd5715 100644 --- a/tools/testing/selftests/bpf/progs/user_ringbuf_success.c +++ b/tools/testing/selftests/bpf/progs/user_ringbuf_success.c @@ -47,14 +47,14 @@ record_sample(struct bpf_dynptr *dynptr, void *context) if (status) { bpf_printk("bpf_dynptr_read() failed: %d\n", status); err = 1; - return 0; + return 1; } } else { sample = bpf_dynptr_data(dynptr, 0, sizeof(*sample)); if (!sample) { bpf_printk("Unexpectedly failed to get sample\n"); err = 2; - return 0; + return 1; } stack_sample = *sample; }