Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp948698pxb; Thu, 21 Apr 2022 14:17:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykdj63yGv4ZM+LLLfnRhzL4SVobbrH5rE8pFYvE+BygE0lQBUSvo5p6eEfg2CEeYxhR8yJ X-Received: by 2002:a05:6402:331c:b0:41d:9354:97c2 with SMTP id e28-20020a056402331c00b0041d935497c2mr1586278eda.300.1650575845970; Thu, 21 Apr 2022 14:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650575845; cv=none; d=google.com; s=arc-20160816; b=l/WJWIWzWA2sODByaZnK4ijff5ovGaPENWUrf4THVf7a1PsQlIeR42vy8KJyMvpNOL 6w70V74r4SzTTrYepZEw/MycIjnvVu0HHpXswMmTtYyL5U5CI7UGpyJcwmKB3ExVdUsL jilVSLE7Sl7orzXa1dSp3Xa1VMblfh43QjKnnm+JwtCnzo7h3F9QzEN5busy7jNQN7sN B4Sa1tF8trM0CPIeLSWpKbKqEg+wATYA/AhGjMgRjuJQ5LBxqdv5+TBJ+QQHIUiGq/2m kJmd2UKBdSGDEtrFgrG9twOZ+E+GrVhjj6LGnj3ej1BQ1Jinh7OXh5ja8TPOwx45rytq 2lxw== 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 :dkim-signature; bh=rS2oog3eO5CDVH6MLeAPYqGuTIVoniasbiUdyIVQinI=; b=IYIqdI+ccEpdRjUNi5YAVlsL6WAaGvSj+dZrYteuW/2NLA/j+Ae+MLxAXz4F33Cfrf BPXFEfLRPuE4XdUtoQCwwyHua38rQ7HSK0AUmBpwWGlgAyYxzv8Y1subMY3TxBqNd97g RCZPajX09yPlmSb4ML7BxTAS+6SC8qNrIbdP1z/5I+LJkraAbvxorF58NJGCIH2Equ8T LaGY0F0M4WKlEZn6Ai5XcOm8J3m3ozN1lei/zVJcLfFYRAtyT+2CbSgzDeAmoec50vNa WgP1UwdIxruHXI0Hek7JwM/D1V27KgpAD1hfcKR56GE5+lwuYYBPUTgtY34ETihEBVAW jNdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c9cPC2jR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a1709062b8400b006e8c0b19a3dsi5637755ejg.42.2022.04.21.14.17.00; Thu, 21 Apr 2022 14:17:25 -0700 (PDT) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c9cPC2jR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388975AbiDUOK6 (ORCPT + 99 others); Thu, 21 Apr 2022 10:10:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388921AbiDUOKr (ORCPT ); Thu, 21 Apr 2022 10:10:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C113BCEC for ; Thu, 21 Apr 2022 07:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650550076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rS2oog3eO5CDVH6MLeAPYqGuTIVoniasbiUdyIVQinI=; b=c9cPC2jRwKtp6pVMODy+l870zYtfwtPzNKaf65xpnsHF1G6MnGCX4slbPiwGlDy90OfTXE 6osel0Rap/PT4+rsvaw8aTS9tSm9dE1WgTU6M09MNWZWS2e5UjwMPp1Pxdgaj9+SR6E9i2 OZ7TLoGnEY1dwdqSJorbSxvdDkMBByE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-MWsIkoWSN2CW2BDWJmDDwg-1; Thu, 21 Apr 2022 10:07:55 -0400 X-MC-Unique: MWsIkoWSN2CW2BDWJmDDwg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04CAC38107A6; Thu, 21 Apr 2022 14:07:55 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.194.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5D5E40EC002; Thu, 21 Apr 2022 14:07:52 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires Subject: [RFC bpf-next v4 4/7] btf: Add a new kfunc set which allows to mark a function to be sleepable Date: Thu, 21 Apr 2022 16:07:37 +0200 Message-Id: <20220421140740.459558-5-benjamin.tissoires@redhat.com> In-Reply-To: <20220421140740.459558-1-benjamin.tissoires@redhat.com> References: <20220421140740.459558-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 This allows to declare a kfunc as sleepable and prevents its use in a non sleepable program. Signed-off-by: Benjamin Tissoires --- new in v4 --- include/linux/btf.h | 2 ++ kernel/bpf/btf.c | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index 76a3ff48ae2a..b8b83dcf86bf 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -17,6 +17,7 @@ enum btf_kfunc_type { BTF_KFUNC_TYPE_ACQUIRE, BTF_KFUNC_TYPE_RELEASE, BTF_KFUNC_TYPE_RET_NULL, + BTF_KFUNC_TYPE_SLEEPABLE, BTF_KFUNC_TYPE_MAX, }; @@ -35,6 +36,7 @@ struct btf_kfunc_id_set { struct btf_id_set *acquire_set; struct btf_id_set *release_set; struct btf_id_set *ret_null_set; + struct btf_id_set *sleepable_set; }; struct btf_id_set *sets[BTF_KFUNC_TYPE_MAX]; }; diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 22e6e3cdc7ee..bf6a82461c58 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -5889,7 +5889,7 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, const struct btf_type *t, *ref_t; const struct btf_param *args; int ref_regno = 0, ret; - bool rel = false; + bool rel = false, sleepable = false; t = btf_type_by_id(btf, func_id); if (!t || !btf_type_is_func(t)) { @@ -5915,10 +5915,13 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, return -EINVAL; } - /* Only kfunc can be release func */ - if (is_kfunc) + /* Only kfunc can be release or sleepable func */ + if (is_kfunc) { rel = btf_kfunc_id_set_contains(btf, resolve_prog_type(env->prog), BTF_KFUNC_TYPE_RELEASE, func_id); + sleepable = btf_kfunc_id_set_contains(btf, resolve_prog_type(env->prog), + BTF_KFUNC_TYPE_SLEEPABLE, func_id); + } /* check that BTF function arguments match actual types that the * verifier sees. */ @@ -6092,6 +6095,13 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, func_name); return -EINVAL; } + + if (sleepable && !env->prog->aux->sleepable) { + bpf_log(log, "kernel function %s is sleepable but the program is not\n", + func_name); + return -EINVAL; + } + /* returns argument register number > 0 in case of reference release kfunc */ return rel ? ref_regno : 0; } -- 2.35.1