From patchwork Thu Dec 14 22:56:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 178957 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8909975dys; Thu, 14 Dec 2023 15:07:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHfert/EbEenhsS9q/d8Nzq8+2tdXIFMwPhOVj3uJUY85Flk78ZZAi5nJB3eGyJTgAS/uc X-Received: by 2002:a05:622a:118d:b0:421:b9cb:933b with SMTP id m13-20020a05622a118d00b00421b9cb933bmr14455865qtk.11.1702595239643; Thu, 14 Dec 2023 15:07:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702595239; cv=none; d=google.com; s=arc-20160816; b=AnUoWSR1f1ntt9M5jjGoXn4tIPKYiAfm7KGVWN7aIjfsPqsELWHtBczHQ5gSIsuL1n LucJTlZSvVORWlGpOooHjAwcbcYldB13n0Lxfal3Agw7KqF3Fdrr3li3PZ+/JdE3hpi9 7cqmyVUTfWfjtC93AKYf8htq78PzA7dXgq1mwRkxYmwqKoCzWenoaMur65bUMMdxHdJR 5zUdI5vNDg+CODWSq7RHrwgXMchZKqnRwRE8uy42C5htZHaR68vVMpszgVsmVQopu7aD rZk/eityFl1G+UTvi/X0FEXUgT3M8CqwXvXZ8GxfNq0JYJYa28G97ArVehy/1UdoheaN 8sgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=j9Ha1GrnJezE3gDkgIKe3fTLm5nM7RqyU/VzWdgR9ds=; fh=3CWBmkB5wxfh6YrfuJ3FPvxy/EilyKmPeGBn7G5ubmI=; b=xSkDnzBup7jzdANv3bWmeVNvF/EFpC3NC9OtGHLtx/2l5iqdJ2KexKVjcoEh9GXlL6 eiPbSDCJNEf2rFt8QnLZNtWbdbkvTsVmI0fEvTfe44ivV4/cKwTwoyakr/kyKHcnI+p+ aF3Fx2y7M2W4iHM/sFrCHdd2BFGtRmuOXyIdGV1wmGu7IYnvcz+OnIXuFqefTRQMqXsq Cfifss92+LTjqVYjUvOu8+Z3qlX4jze33FDtE7SbtOsvcZp9eTHiQzdHV8P/3mjc+YR5 397T4hL1/RZ8MRHgKAlIgkagPzovRNXlJgg2SEchvJN2OtiR6ydX9i7xw8A9WS+JdBnQ oNYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=qw1HvdCM; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZDZ1H6Gk; spf=pass (google.com: domain of linux-kernel+bounces-220-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-220-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ew11-20020a05622a514b00b0042588de578dsi17678892qtb.91.2023.12.14.15.07.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 15:07:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-220-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=qw1HvdCM; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZDZ1H6Gk; spf=pass (google.com: domain of linux-kernel+bounces-220-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-220-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6E4801C21E86 for ; Thu, 14 Dec 2023 23:07:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86F326FCE3; Thu, 14 Dec 2023 23:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="qw1HvdCM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZDZ1H6Gk" X-Original-To: linux-kernel@vger.kernel.org Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7741F66AA2; Thu, 14 Dec 2023 23:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id A3EC43200AC7; Thu, 14 Dec 2023 17:56:42 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 14 Dec 2023 17:56:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1702594602; x= 1702681002; bh=j9Ha1GrnJezE3gDkgIKe3fTLm5nM7RqyU/VzWdgR9ds=; b=q w1HvdCMhxFqoIWiBQ7RqO5XhjutACfA9pn5Sp3DAShbPXJmO/iOY4ZnKwx49xeoz sCs4mI27pihMqKGADLlYZBit+2QJpRkD5i3V2rm4T2Ln975py8J4PZB9YROndd79 00l9fIi4zcjmLPc0jOsSXh8dzWZVeCAwJD8F8IxVreFOBvsjQd1/XiPA+y1z6Bo2 dPcA/m+CxMEONWV7KxNaBVpzCByBRCTn+c8GyiYgXJDS4nJlCMK3E5K8u8959xqO ax0eg5iveTRk2G0Q8g9u/XOJkBFimGobyC79Vi6zdC62yA9lviD+xmJdMpDpYUOM kAuHii98CtC4AhnU7Hsxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1702594602; x= 1702681002; bh=j9Ha1GrnJezE3gDkgIKe3fTLm5nM7RqyU/VzWdgR9ds=; b=Z DZ1H6Gk/IvJofYnIfaaitzCwf/JQXlJ/MlPeBGwXS/8TWgRkNQxP/njPMK+lOWpc 3vtTx4MFuz0Nbe4fQG2vvlVYuBbC3pk10tbRTSrBy2czyM+8BcWPAv9QjmJSoKCB awmLoaYH5lUqSL0hbUCUjx0CkfFAiBIZ2EhdUcWlJE3aqATESwhMlvVurxsrkCZ1 3VSxH6zgI+pbT6J1NKOz5kxB5+go/ITKRxn5yY5wlI6LbuFNDMOjshjSCXEZrLPL 02kOPKJK9c7jpUuPo/jaNUzAAB5+nnZB8B0d+N4nJmfo+r9kWD+GmTN2TsDCSmQZ muTIB/u/JHDRKyfpOO/RQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddttddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Dec 2023 17:56:40 -0500 (EST) From: Daniel Xu To: hawk@kernel.org, ast@kernel.org, daniel@iogearbox.net, kuba@kernel.org, john.fastabend@gmail.com, andrii@kernel.org, davem@davemloft.net, memxor@gmail.com Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH bpf-next 1/3] bpf: xdp: Register generic_kfunc_set with XDP programs Date: Thu, 14 Dec 2023 15:56:25 -0700 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785300506264964412 X-GMAIL-MSGID: 1785300506264964412 Registering generic_kfunc_set with XDP programs enables some of the newer BPF features inside XDP -- namely tree based data structures and BPF exceptions. The current motivation for this commit is to enable assertions inside XDP bpf progs. Assertions are a standard and useful tool to encode intent. Signed-off-by: Daniel Xu --- kernel/bpf/helpers.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index b3be5742d6f1..b0b485126a76 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2630,6 +2630,7 @@ static int __init kfunc_init(void) ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &generic_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &generic_kfunc_set); + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &generic_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &generic_kfunc_set); ret = ret ?: register_btf_id_dtor_kfuncs(generic_dtors, ARRAY_SIZE(generic_dtors), From patchwork Thu Dec 14 22:56:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 178958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8910303dys; Thu, 14 Dec 2023 15:07:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpDV4JdazLCWdmnFn5wym1MmibkVuUzJQ1hG48N0CJ2qALOkIO218QeZvq0yPyXfcauZof X-Received: by 2002:a17:90b:5106:b0:28a:ea44:21a5 with SMTP id sc6-20020a17090b510600b0028aea4421a5mr1750610pjb.75.1702595272708; Thu, 14 Dec 2023 15:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702595272; cv=none; d=google.com; s=arc-20160816; b=lIq7EG44fs5JvUifsGhvsSZjcTfughfiUusiPatcAca/daQZ6cf0KpCDabKs5ZAWL0 ojUlW8m77hEVctXeZuXmjyw77G0y2QBOX0eyEwqTkOytYktKMxuWTUkMKScsPg2P12w7 jfsFln/bAzFF45YZ9tBqLRIdnHSGQ0KAGwPb5oqw95OLDJvUibgiQ4nuw/WKT9/Qqstj 7/BtVQOEbYohoFm01IzrS/Z2oy8MFLUzonBOl7iLDuoiIU+yD2VzoOlGDckcGoUfZRxX gRDWdKjpl9XwKwcyJcDlxFbL+sw5UG0AJkCIJqkApXPGKHePtIrUzO6WQcNGsPEv5ttC ljmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=XQshBmyjBQf6RY2CAow1bMPPx+5T2NN0wUXPXm8LOKg=; fh=Iyz4N0rd80otmtpELiHwE+ewbE+OO3Ozi0R6wDL/Ymk=; b=i66lkHqZZ3PHDdP1VJzABIANeIFYBh48gD7vUb/Flh/Vwih2GlXN13/1J96KBh1c7R DmF7XtQQeNOXCW2XefQVF2jd3KKuVhVaVCWT7NnlGvq2SZvE8jpRqx0+xR2ms/6cWUXp ID4t4cUT+zSQYpJrw/QzB/i9FzIoAhKSb9RWeMq9g0YwZsfQNJmPdmVXi6XqZaaoWfQL Hn0UZMw7o0QLIsSBqgcb7O6YCOU54IGagzdOHd5G4l31D8Bw0dPKTyUPUie/QY5BYQ0o c7ihP5a9AdR8m4M0f0dSyafILfGtVlx5OIUu7IgOOtdeVG3QFAXi3Ze6RvbwhhKQoRrq MEng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=ZaqCIeQG; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="HL2/33ak"; spf=pass (google.com: domain of linux-kernel+bounces-222-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-222-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id o24-20020a17090ac09800b0028af5757d1asi2697624pjs.95.2023.12.14.15.07.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 15:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-222-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=ZaqCIeQG; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="HL2/33ak"; spf=pass (google.com: domain of linux-kernel+bounces-222-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-222-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 3815DB21EFF for ; Thu, 14 Dec 2023 23:07:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 121D26FCF4; Thu, 14 Dec 2023 23:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="ZaqCIeQG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HL2/33ak" X-Original-To: linux-kernel@vger.kernel.org Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 773BF671E0; Thu, 14 Dec 2023 23:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 5C4013200B63; Thu, 14 Dec 2023 17:56:46 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 14 Dec 2023 17:56:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1702594605; x= 1702681005; bh=XQshBmyjBQf6RY2CAow1bMPPx+5T2NN0wUXPXm8LOKg=; b=Z aqCIeQGurRCTM7hZ4iasVKc9O2LQIFe3ei2Nwew2C94utMf/LqvJBaqQXRpSIEgk foprlzpuWhEp05gaiT8q4QVRqDiM6QbVuznut8EaFBCbDcwa8LiQGzSWcVoJbbuQ sy8mNs4TkSXXZ5zyzzDJaW55lyeB3GpHckAZFYJAYDrm89soUw9wbdmPGTVy85Lm XbeF5Y711R6W/m5BFmkkWusaW+xxEmFr7wZz6eOs4UaAlJ9BU/LPSlG/eKojVhwi alqplz4xrwzNmSkgWGMBu1kslSoOxh6QR1m9w4biCkIRAHxSPVmnTOzC+jaiELjh DJ01GHj9SQwi7cwyFDc4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1702594605; x= 1702681005; bh=XQshBmyjBQf6RY2CAow1bMPPx+5T2NN0wUXPXm8LOKg=; b=H L2/33akpJKh8LYF5lXkV20iIT64GK82zts3RPdoHgfTXn5QEyoRgN3kypilVZl3e 4JweKZNSf8eixcUGwZG+eRfpGCa4XREDl8EBUhitaDT9AVHJINRpy3lompY2rFjx fW6fuMPKTbh2Xy8yEl6YZmsm4UbmAfkcPGVonCcRSZsPXu4iyIGaEjz00pbmalWD bO3RtbRkM5a2S8zRlcksHCR6ObFTon5rNTPwDEuyYjh0qPsN5JYqXe0+eGkN4bCh d4ZOTq+yUXhPbKnveTHHHL253UHad5815ixrPY+Ilq17j2DLSQqqIPRjR+oNqIzY Vx4tGA+buvC+HzYrpUvTg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddttddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Dec 2023 17:56:44 -0500 (EST) From: Daniel Xu To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, shuah@kernel.org, memxor@gmail.com Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/3] bpf: selftests: Add bpf_assert_if() and bpf_assert_with_if() macros Date: Thu, 14 Dec 2023 15:56:26 -0700 Message-ID: <97ada80f3aaaeb16bf97e31a8fc204513b4fb6a9.1702594357.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785300540602354714 X-GMAIL-MSGID: 1785300540602354714 These macros are a temporary stop-gap until bpf exceptions support unwinding acquired entities. Basically these macros act as if they take a callback which only get executed if the assertion fails. Signed-off-by: Daniel Xu --- .../testing/selftests/bpf/bpf_experimental.h | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index 1386baf9ae4a..d63f415bef26 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -263,6 +263,17 @@ extern void bpf_throw(u64 cookie) __ksym; */ #define bpf_assert(cond) if (!(cond)) bpf_throw(0); +/* Description + * Assert that a conditional expression is true. If false, runs code in the + * body before throwing. + * Returns + * Void. + * Throws + * An exception with the value zero when the assertion fails. + */ +#define bpf_assert_if(cond) \ + for (int ___i = 0, ___j = !!(cond); !(___j) && !___i; bpf_throw(0), ___i++) + /* Description * Assert that a conditional expression is true. * Returns @@ -272,6 +283,17 @@ extern void bpf_throw(u64 cookie) __ksym; */ #define bpf_assert_with(cond, value) if (!(cond)) bpf_throw(value); +/* Description + * Assert that a conditional expression is true. If false, runs code in the + * body before throwing. + * Returns + * Void. + * Throws + * An exception with the given value when the assertion fails. + */ +#define bpf_assert_with_if(cond, value) \ + for (int ___i = 0, ___j = !!(cond); !(___j) && !___i; bpf_throw(value), ___i++) + /* Description * Assert that LHS is equal to RHS. This statement updates the known value * of LHS during verification. Note that RHS must be a constant value, and From patchwork Thu Dec 14 22:56:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 178956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8909966dys; Thu, 14 Dec 2023 15:07:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IG59rokTJp8+wiU9vpYxZQdfBoLzm8MX3DqoHKO5n/GONZixk8gBOaGvsq1uJyKXgCJFqmG X-Received: by 2002:a05:6a00:2789:b0:6ce:1108:9777 with SMTP id bd9-20020a056a00278900b006ce11089777mr6288882pfb.27.1702595239371; Thu, 14 Dec 2023 15:07:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702595239; cv=none; d=google.com; s=arc-20160816; b=iV3kdAXI5Bio9V38ye0JRd0tMDy/rE1oGW9CjniS+KhVmsMACmnzCP7qBRQFCYrnYf fiIhkLL/FfcgyZFGevxnH071ncLLFa4XZOM0WGonFH96WVMc/iQuXzbXT8oKKo+9HchV lYQTwU3TbhSXe08HUOsVWHBIu8JawpyMmxubmCAmjSEGg+Gt8d3rq4SjJt5B0CnhJH5g A41ud+cqJ/br+IRPBFDJzvMjhxYQ9kCjwVE4tLWPv7oh+cZpn8f5/t3ttQ96uskciI3S XoS5UEm448lcOXvXkrvvw1oFxBzVGnP9InRHqS+G5MaYbVOiwW2oIch+1oa9g0aVmOXc in5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=L/0CxpH+ItkIN3jpcTP0mXpLYvcBH1FSKHM4RQL+UFM=; fh=hj0UBKVp01kEiC02FrnhWQdSORjR11W+sfuTgpArQjU=; b=wbllg2UPsyFFNAgY9LLFqN7oBm9Ln0jV51ccFgUX2jZq53Jz5W6Jo5LA5+Wm8Xatgd dZTNB9wYkLn0aWbEASlglDmRIiG4FW7Py8LvumHMBERZJ6XulRGUF9KIWlSlqZCqWWi+ ZGXQvZRu/vFYRrzopbRbhIYEUnm7EOUu0q5gzqKHpUAkHf4zSDRWM5jnk4lZMoHWQyHw 3Gay2KJKgtnmiNOg0nZWk0CULtCN9L0DY4ecTaVmYrLIJ6qqJd1wfuv54c7yvXTQC/1o zlQmEtdSpWenrUlQoL/uV9a0RH9QLRt/frepxo4iUOlEjvSBkaJOpFeyMQWqmP9SgMSp qJcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=Ylob5p1y; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Z8QNha96; spf=pass (google.com: domain of linux-kernel+bounces-221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-221-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b4-20020a056a000cc400b006ce789c5378si11905755pfv.373.2023.12.14.15.07.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 15:07:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=Ylob5p1y; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Z8QNha96; spf=pass (google.com: domain of linux-kernel+bounces-221-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-221-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 97CDC283BD7 for ; Thu, 14 Dec 2023 23:07:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 768CA6FCE0; Thu, 14 Dec 2023 23:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="Ylob5p1y"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z8QNha96" X-Original-To: linux-kernel@vger.kernel.org Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7749266AA4; Thu, 14 Dec 2023 23:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 3FEE73200B6C; Thu, 14 Dec 2023 17:56:50 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 14 Dec 2023 17:56:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1702594609; x= 1702681009; bh=L/0CxpH+ItkIN3jpcTP0mXpLYvcBH1FSKHM4RQL+UFM=; b=Y lob5p1y1K4j5mjBFalFycAkqaKaqz1FROzRP7NWkpEROFzy1e6SUuDGfMro/YXW7 FhjzgdFCa70PDXuds5aDqFaw53gjddDbSraAF+MhTKm+OBFDkEqWZYP1r6c891Eu FJWJVU5C7/K2myRzOSiegHkravmvJMcDxiaXJ6CkUOmpjIBvUWg+7vPkUaNfMEKM FuKCwOHLdM13dBAyjrwKm8RnC2fZ1umgcmm8JCbTaVGb3pocHmib/cVoNatQ+/Vz vXFOKXun5v8LjJFAJfq/UncZ12je4stK9I/h1Nmdxj7tnM88vWM/U1eLll66IDan 9utJ5oH21kB+ke8oFAjbQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1702594609; x= 1702681009; bh=L/0CxpH+ItkIN3jpcTP0mXpLYvcBH1FSKHM4RQL+UFM=; b=Z 8QNha96yOnxWRQSSo1nDSWCFHxIJmkn9MYYFdco3NpHSKLe7MimAxTTHpGymneOn 6MLJI4IF8TJ8zEAsdWP2cfpFR/ZM0Ylfphy0HLodutXTIGujX395+upYWsL81wjN x4X1XBmlD06f2OGrC8XYdP/an6b2s7OxfZT2O0Tb4tc+slGTmn1JDgj3YXKCMSes MmZy09onNnLpBo7i0Ymd/NPcL3o/jfSlfa/sSXXYhk5lntMpOwlYrHqd/HDTcvj2 dfV8Vt2frgzhmGOpTJc64fq1jV/Yfp5O90iOOTlcLZKNa3ErJgfCC8YgNbjUJNea G6x1YfFa1llnZqwqWOQ9g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddttddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgepudenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Dec 2023 17:56:48 -0500 (EST) From: Daniel Xu To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, shuah@kernel.org, memxor@gmail.com Cc: mykolal@fb.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 3/3] bpf: selftests: Test bpf_assert_if() and bpf_assert_with_if() Date: Thu, 14 Dec 2023 15:56:27 -0700 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785300505379298688 X-GMAIL-MSGID: 1785300505379298688 Add some positive and negative test cases that exercise the "callback" semantics. Signed-off-by: Daniel Xu --- .../selftests/bpf/prog_tests/exceptions.c | 5 ++ .../testing/selftests/bpf/progs/exceptions.c | 61 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/exceptions.c b/tools/testing/selftests/bpf/prog_tests/exceptions.c index 516f4a13013c..a41113d72d0d 100644 --- a/tools/testing/selftests/bpf/prog_tests/exceptions.c +++ b/tools/testing/selftests/bpf/prog_tests/exceptions.c @@ -83,6 +83,11 @@ static void test_exceptions_success(void) RUN_SUCCESS(exception_assert_range_with, 1); RUN_SUCCESS(exception_bad_assert_range, 0); RUN_SUCCESS(exception_bad_assert_range_with, 10); + RUN_SUCCESS(exception_assert_if_body_not_executed, 2); + RUN_SUCCESS(exception_bad_assert_if_body_executed, 1); + RUN_SUCCESS(exception_bad_assert_if_throws, 0); + RUN_SUCCESS(exception_assert_with_if_body_not_executed, 3); + RUN_SUCCESS(exception_bad_assert_with_if_body_executed, 2); #define RUN_EXT(load_ret, attach_err, expr, msg, after_link) \ { \ diff --git a/tools/testing/selftests/bpf/progs/exceptions.c b/tools/testing/selftests/bpf/progs/exceptions.c index 2811ee842b01..e61cb794a305 100644 --- a/tools/testing/selftests/bpf/progs/exceptions.c +++ b/tools/testing/selftests/bpf/progs/exceptions.c @@ -365,4 +365,65 @@ int exception_bad_assert_range_with(struct __sk_buff *ctx) return 1; } +SEC("tc") +int exception_assert_if_body_not_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + + bpf_assert_if(time != 0) { + return 1; + } + + return 2; +} + +SEC("tc") +int exception_bad_assert_if_body_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + + bpf_assert_if(time == 0) { + return 1; + } + + return 2; +} + +SEC("tc") +int exception_bad_assert_if_throws(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + + bpf_assert_if(time == 0) { + } + + return 2; +} + +SEC("tc") +int exception_assert_with_if_body_not_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + int ret = 1; + + bpf_assert_with_if(time != 0, ret) { + ret = 2; + } + + return 3; +} + +SEC("tc") +int exception_bad_assert_with_if_body_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + int ret = 1; + + bpf_assert_with_if(time == 0, ret) { + ret = 2; + } + + return 3; +} + char _license[] SEC("license") = "GPL";