From patchwork Mon Jan 23 23:22:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 47469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1871650wrn; Mon, 23 Jan 2023 15:41:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXvceXCdiEAzle846cqbWQRe9vH1MMJC5hg9FEXQlqGQXEWzZjDh4Aihff09ml6rsGkB6Xlb X-Received: by 2002:a17:902:e5c9:b0:194:d0ad:53f0 with SMTP id u9-20020a170902e5c900b00194d0ad53f0mr22864135plf.9.1674517277303; Mon, 23 Jan 2023 15:41:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674517277; cv=none; d=google.com; s=arc-20160816; b=ejCHZiuGDmMJxBur36RAFBzvRHt/TD8EzOZPEsO4e3CKGG/fkD/BA2+pZUD2SZBZ8c mALMGOzfskUEatAQqjD9evlVmLLeM79bag4nbmnEbBLjoSN3H/bYOtBzM8VkPh/pwAU3 /MROz1UOjox/zeAiSmEsgCeuM9oNLmiUuhd1vr5iCISqiROGY13s+8Y+9ww7xz3XWKxA r3HfVqkemPSRMohvzJo/cM7On6szlI0m0PgQ0ISCp+79PAH+EPCleLxnh2bPHWqg3Ynx i5DBClnUnz/wbOGegyVtWEljd6BA+bfEQ5FzrTrkP79FpjNIYAMn1bJngUkymFi748FR NyhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fb0Dqesrjqwtr/7go0R3yUjkHNdnkEwFdWq9cAVf5Uk=; b=d03VYdCeNXNtZ1FGOtFRV+YAEnMncsPfeiC8Fx4R1otvISUYbi0TiAiL8+QZPbzkQH L2EqWdf/RtYEnNejQNrVg+OriMNqjVZC2/Y5wuTiHftbjsmMV31/GxI1S2vkf/2g9m+b BClQHV97cbdrq/0NH+zBMXWgAPqqKUuMkkvDy1B70//ct2fk3cht7HuJaiYZGKAnP9Pz jyJHpQszqf+gD6LOS5K4/72mgTqXyx/AiTKAvKiOIMUwERC5HYQbSfL4+a33B1ncdQam sbbuUhf/OJvqGz1bXbNB0aCSCFEExdQ4HCxagLoAjcR4lM828m9UjqwqjvQnC5/1mNJk Ri3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a170902d19500b001898141f0edsi647522plb.159.2023.01.23.15.41.04; Mon, 23 Jan 2023 15:41:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231822AbjAWXWj (ORCPT + 99 others); Mon, 23 Jan 2023 18:22:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231788AbjAWXWi (ORCPT ); Mon, 23 Jan 2023 18:22:38 -0500 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D27917CF7; Mon, 23 Jan 2023 15:22:37 -0800 (PST) Received: by mail-qv1-f41.google.com with SMTP id g10so10453138qvo.6; Mon, 23 Jan 2023 15:22:37 -0800 (PST) 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=fb0Dqesrjqwtr/7go0R3yUjkHNdnkEwFdWq9cAVf5Uk=; b=DM68hg6h1fvo+mCt78/6PKBa0zRsAhHJzN1cbxTnrVDUoP838v7PDiUwJurObGK/+/ qt71BfyO0kyUYQeViphQKllao3f+B1aOy/ScOCsCXwbsVZieUffI0fPC5WOnTw3y0DB/ ANS8dLfMq5OtoAmAKJKDCWlsNqb3CMUBAbdBVa253xSm7bpSS5EEnKoxMcJtJsP2VlJc 6pkqWCLbBwstmqMOL44M/6g4a3IsQOmHHVyHIHuLBBqgWP+I/Wo3fLjcrk5+Mf8eK22z /sfvTvPLU8y/08B+Sq9bzoanyy9kcBlzcWdE4+DBte58A9bqgfhJg7S9SkzhjGrqyWOI VSHg== X-Gm-Message-State: AFqh2koS9GOChDbex0AHmoBHPP/YAutXl0cj6dCjAjJ0wfvPIwRzXZih qYLz+o5w8fsPD3V38rKekyMiLWlGmA0cYS53 X-Received: by 2002:ad4:4d4d:0:b0:532:1d4b:b93c with SMTP id m13-20020ad44d4d000000b005321d4bb93cmr61073908qvm.31.1674516155757; Mon, 23 Jan 2023 15:22:35 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:93a0]) by smtp.gmail.com with ESMTPSA id j10-20020a05620a0a4a00b00706a452c074sm342086qka.104.2023.01.23.15.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 15:22:35 -0800 (PST) From: David Vernet To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@meta.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, tj@kernel.org, memxor@gmail.com Subject: [PATCH bpf-next 1/3] bpf: Allow BPF_PROG_TYPE_STRUCT_OPS programs to be sleepable Date: Mon, 23 Jan 2023 17:22:26 -0600 Message-Id: <20230123232228.646563-2-void@manifault.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123232228.646563-1-void@manifault.com> References: <20230123232228.646563-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755858628444499618?= X-GMAIL-MSGID: =?utf-8?q?1755858628444499618?= BPF struct_ops programs currently cannot be marked as sleepable. This need not be the case -- struct_ops programs could be sleepable, and e.g. invoke kfuncs that export the KF_SLEEPABLE flag. So as to allow future struct_ops programs to invoke such kfuncs, this patch updates the verifier to allow struct_ops programs to be sleepable. A follow-on patch will update the dummy_st_ops selftest suite to also validate sleepable struct_ops behavior. Signed-off-by: David Vernet --- kernel/bpf/verifier.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index ecf7fed7881c..6b8dcd542950 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17030,7 +17030,8 @@ static bool can_be_sleepable(struct bpf_prog *prog) } } return prog->type == BPF_PROG_TYPE_LSM || - prog->type == BPF_PROG_TYPE_KPROBE; /* only for uprobes */ + prog->type == BPF_PROG_TYPE_KPROBE /* only for uprobes */ || + prog->type == BPF_PROG_TYPE_STRUCT_OPS; } static int check_attach_btf_id(struct bpf_verifier_env *env) @@ -17052,7 +17053,7 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) } if (prog->aux->sleepable && !can_be_sleepable(prog)) { - verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter and uprobe programs can be sleepable\n"); + verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter, uprobe, and struct_ops programs can be sleepable\n"); return -EINVAL; }