Message ID | 20231214062434.3565630-3-menglong8.dong@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8352027dys; Wed, 13 Dec 2023 22:29:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEP3T6EfpyBGCT6hS5whreXl/zImMsWrql6IXBgN6/Lkn88iWQXmGsqIN+gOnbwUPVG9BTC X-Received: by 2002:a05:6808:1493:b0:3b8:b063:824e with SMTP id e19-20020a056808149300b003b8b063824emr11499631oiw.80.1702535343797; Wed, 13 Dec 2023 22:29:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702535343; cv=none; d=google.com; s=arc-20160816; b=Ur6/KsihMyfmktBIzWobOD5KUpcAXGYOeu5JuilwsRremncYgtCR1f9notdnnvlKAJ P+0gXLBZGBuXxmn8DuECH2gSQJFg611aH4/WmCtb1jWnmdewm2riUmV1b6Ii/G8Bha9R P2EV8QemfoJ/YzMJnAQ31CC1l7GsRm7q4wbCY6lPEGgTzMPCuNpH8/TlBtSdpElOry6W D1FBQrYWZ9kBZtR8VJ8UOO8UICxsMUDTuPzhOK7ROj+pho/h/gtFyTqKYZSXBDoCf3+6 Aog3iQHCax5VBMcgoMntd475RXBZgAbL4uop8uIOJPkg4o6ppEDeisEPkbPNAGBKQLsn P78A== 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=lsGm+j7nwlGOQcDgyTd4xbThNMw0KWzAWGGOI0U9NQE=; fh=rPJbZScTIF17zj42fTggn0VkysdYB+Rmhzv8OjYTIeQ=; b=0cCa5+O9ZxH01V4hQkeNpvHAEj8FFL8IHAsVWNJDlmQ1YLQsj2Y0j+HrP5moLq3qo+ yCQsqi2uMCPu+rC394Qy8tHYrKKHrxwUqSz/AE1S1taaoOQYlH0Czl+CxZ5ohQFQmPBK wTDEXbeH4x50laJbRcPW4rhht9OOXZkkrqrZ5GnLPaTKttN0V6rvuEoEEP8bRsPFJd38 YBcJP1ROLzJ3FN5UN/7LbUpOh5Y95rcX1KI9lwgFggMCrPFRxpgCgjM9tX8JgdAZ/opH qLiXYeGHr85DBqekHM8HOkBrLQV2E+lzqDHTLf3yKJxVufdcmLO/oM/lYN25IllPlPRu spXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="ajXqj6/e"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id cb7-20020a056a02070700b005b90b2d9178si11065361pgb.796.2023.12.13.22.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 22:29:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="ajXqj6/e"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 162DA82D7560; Wed, 13 Dec 2023 22:29:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234272AbjLNG2l (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Thu, 14 Dec 2023 01:28:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234298AbjLNG2j (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 14 Dec 2023 01:28:39 -0500 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F1D4F4; Wed, 13 Dec 2023 22:28:46 -0800 (PST) Received: by mail-io1-xd42.google.com with SMTP id ca18e2360f4ac-7b45ab9e084so325200139f.2; Wed, 13 Dec 2023 22:28:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702535325; x=1703140125; darn=vger.kernel.org; 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=lsGm+j7nwlGOQcDgyTd4xbThNMw0KWzAWGGOI0U9NQE=; b=ajXqj6/eyuXW9Yvdyq1mzAlxNtyZ+Oq1xYBRrLe5mITwB3lO7mEWxLiaGqNTNyIVj+ T0eng5GwntVkJpNrM5InQMkmKE0SQrL4754u8NLuqIrDNOn+uuGB2KVbZSQqhcn2dkce CJRyRtAxCxxuIrRbbZUWBMdh0mrvdwpSHu5SIFvP/SVOCmz3mTNOna5ufuF3n2kVn+Q0 Lzbm+K/S7ZCdBqgF6apWMt7zC6w462qwBHHP7OW/KmbrSPphQyiIwslZF1OCgI738zxm N6TuvDd4uPNG3c6vmZqHfUKT7GgpiLoson7BVAxcvX/ljjgPHJuLW26cUfatKup3nR0t aukQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702535325; x=1703140125; 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=lsGm+j7nwlGOQcDgyTd4xbThNMw0KWzAWGGOI0U9NQE=; b=o4tMOSK0DVdKkboRAHDODeBiFjcl5o2jYpr8m0WN8gZLOv1TdlYpVF5rsnJy1DHpnJ /wiu69b5oiHW8rQ76fuE0XEqsjv4phmvcRYneQa5wyvb8KdAK08KZZ+UEVw7KbK697Ek WMfObou4Qj18FoyruWTdwz2ApznLythmFnHUSQ+ZyBBwRib2dYkc/H+IsbFZAzFOOEy9 ecE4HZJ6OZ81J+JlBgA9sLnH/+sF0yvrDk2TVSva23xWw8GN9G/BOYCeHj9PoSV22Kp9 IJZ0env/jkujnL/3tBzCLgfslimalVC7nQwYuz0ngTP2uqdgt382xv5h20Dy7+r6n2x/ XSuw== X-Gm-Message-State: AOJu0YyL5HYXcLBRG5ScM2OP/6p6EZDi9sEdXgO8hk8fVxEqJqfiRXhR gx1Qo9y6DXUJBx25zMlEha0= X-Received: by 2002:a05:6e02:1a44:b0:35d:59a2:332b with SMTP id u4-20020a056e021a4400b0035d59a2332bmr13251059ilv.47.1702535325386; Wed, 13 Dec 2023 22:28:45 -0800 (PST) Received: from localhost.localdomain ([43.129.244.20]) by smtp.gmail.com with ESMTPSA id z7-20020a63e107000000b005af08f65227sm10744770pgh.80.2023.12.13.22.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 22:28:45 -0800 (PST) From: Menglong Dong <menglong8.dong@gmail.com> To: andrii@kernel.org, eddyz87@gmail.com, yonghong.song@linux.dev Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong <menglong8.dong@gmail.com> Subject: [PATCH bpf-next v3 2/2] selftests/bpf: activate the OP_NE login in range_cond() Date: Thu, 14 Dec 2023 14:24:34 +0800 Message-Id: <20231214062434.3565630-3-menglong8.dong@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214062434.3565630-1-menglong8.dong@gmail.com> References: <20231214062434.3565630-1-menglong8.dong@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 22:29:01 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785237700837717099 X-GMAIL-MSGID: 1785237700837717099 |
Series |
bpf: support to track BPF_JNE
|
|
Commit Message
Menglong Dong
Dec. 14, 2023, 6:24 a.m. UTC
The edge range checking for the registers is supported by the verifier
now, so we can activate the extended login in
tools/testing/selftests/bpf/prog_tests/reg_bounds.c/range_cond() to test
such logic.
Besides, I added some cases to the "crafted_cases" array for this logic.
These cases are mainly used to test the edge of the src reg and dst reg.
Signed-off-by: Menglong Dong <menglong8.dong@gmail.com>
---
v2:
- add some cases to the "crafted_cases"
---
.../selftests/bpf/prog_tests/reg_bounds.c | 25 ++++++++++++++-----
1 file changed, 19 insertions(+), 6 deletions(-)
Comments
On Wed, Dec 13, 2023 at 10:28 PM Menglong Dong <menglong8.dong@gmail.com> wrote: > > The edge range checking for the registers is supported by the verifier > now, so we can activate the extended login in > tools/testing/selftests/bpf/prog_tests/reg_bounds.c/range_cond() to test > such logic. > > Besides, I added some cases to the "crafted_cases" array for this logic. > These cases are mainly used to test the edge of the src reg and dst reg. > > Signed-off-by: Menglong Dong <menglong8.dong@gmail.com> > --- > v2: > - add some cases to the "crafted_cases" > --- > .../selftests/bpf/prog_tests/reg_bounds.c | 25 ++++++++++++++----- > 1 file changed, 19 insertions(+), 6 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c > index 0c9abd279e18..53b8711cfd2d 100644 > --- a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c > +++ b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c > @@ -590,12 +590,7 @@ static void range_cond(enum num_t t, struct range x, struct range y, > *newy = range(t, max_t(t, x.a, y.a), min_t(t, x.b, y.b)); > break; > case OP_NE: > - /* generic case, can't derive more information */ > - *newx = range(t, x.a, x.b); > - *newy = range(t, y.a, y.b); > - break; > - > - /* below extended logic is not supported by verifier just yet */ > + /* below logic is supported by the verifier now */ > if (x.a == x.b && x.a == y.a) { > /* X is a constant matching left side of Y */ > *newx = range(t, x.a, x.b); > @@ -2101,6 +2096,24 @@ static struct subtest_case crafted_cases[] = { > {S32, S64, {(u32)(s32)S32_MIN, (u32)(s32)-255}, {(u32)(s32)-2, 0}}, > {S32, S64, {0, 1}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, > {S32, U32, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, > + > + /* edge overlap testings for BPF_NE */ > + {U64, U64, {1, 1}, {1, 0x80000000}}, > + {U64, S64, {1, 1}, {1, 0x80000000}}, > + {U64, U32, {1, 1}, {1, 0x80000000}}, > + {U64, S32, {1, 1}, {1, 0x80000000}}, > + {U64, U64, {0x80000000, 0x80000000}, {1, 0x80000000}}, > + {U64, S64, {0x80000000, 0x80000000}, {1, 0x80000000}}, > + {U64, U32, {0x80000000, 0x80000000}, {1, 0x80000000}}, > + {U64, S32, {0x80000000, 0x80000000}, {1, 0x80000000}}, > + {U64, U64, {1, 0x80000000}, {1, 1}}, > + {U64, S64, {1, 0x80000000}, {1, 1}}, > + {U64, U32, {1, 0x80000000}, {1, 1}}, > + {U64, S32, {1, 0x80000000}, {1, 1}}, > + {U64, U64, {1, 0x80000000}, {0x80000000, 0x80000000}}, > + {U64, S64, {1, 0x80000000}, {0x80000000, 0x80000000}}, > + {U64, U32, {1, 0x80000000}, {0x80000000, 0x80000000}}, > + {U64, S32, {1, 0x80000000}, {0x80000000, 0x80000000}}, JNE and JEQ are sign-agnostic, so there is no need to use both U64 and S64 variants for comparison. As for the choice of values. Wouldn't it make sense to use really a boundary conditions: 0, 0xffffffffffffffff, and 0x80000000000000 for 64-bit and 0, 0xffffffff, and 0x80000000 for 32-bit? For this one use U32 as the init type? BTW, all these cases should be tested with auto-generated tests, so please make sure to run sudo SLOW_TESTS=1 ./test_progs -t reg_bounds_gen -j locally. It will take a bit of time, but should help to get confidence in that everything is working and nothing regressed. > }; > > /* Go over crafted hard-coded cases. This is fast, so we do it as part of > -- > 2.39.2 >
On Fri, Dec 15, 2023 at 7:24 AM Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote: > > On Wed, Dec 13, 2023 at 10:28 PM Menglong Dong <menglong8.dong@gmail.com> wrote: > > > > The edge range checking for the registers is supported by the verifier > > now, so we can activate the extended login in > > tools/testing/selftests/bpf/prog_tests/reg_bounds.c/range_cond() to test > > such logic. > > > > Besides, I added some cases to the "crafted_cases" array for this logic. > > These cases are mainly used to test the edge of the src reg and dst reg. > > > > Signed-off-by: Menglong Dong <menglong8.dong@gmail.com> > > --- > > v2: > > - add some cases to the "crafted_cases" > > --- > > .../selftests/bpf/prog_tests/reg_bounds.c | 25 ++++++++++++++----- > > 1 file changed, 19 insertions(+), 6 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c > > index 0c9abd279e18..53b8711cfd2d 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c > > +++ b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c > > @@ -590,12 +590,7 @@ static void range_cond(enum num_t t, struct range x, struct range y, > > *newy = range(t, max_t(t, x.a, y.a), min_t(t, x.b, y.b)); > > break; > > case OP_NE: > > - /* generic case, can't derive more information */ > > - *newx = range(t, x.a, x.b); > > - *newy = range(t, y.a, y.b); > > - break; > > - > > - /* below extended logic is not supported by verifier just yet */ > > + /* below logic is supported by the verifier now */ > > if (x.a == x.b && x.a == y.a) { > > /* X is a constant matching left side of Y */ > > *newx = range(t, x.a, x.b); > > @@ -2101,6 +2096,24 @@ static struct subtest_case crafted_cases[] = { > > {S32, S64, {(u32)(s32)S32_MIN, (u32)(s32)-255}, {(u32)(s32)-2, 0}}, > > {S32, S64, {0, 1}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, > > {S32, U32, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, > > + > > + /* edge overlap testings for BPF_NE */ > > + {U64, U64, {1, 1}, {1, 0x80000000}}, > > + {U64, S64, {1, 1}, {1, 0x80000000}}, > > + {U64, U32, {1, 1}, {1, 0x80000000}}, > > + {U64, S32, {1, 1}, {1, 0x80000000}}, > > + {U64, U64, {0x80000000, 0x80000000}, {1, 0x80000000}}, > > + {U64, S64, {0x80000000, 0x80000000}, {1, 0x80000000}}, > > + {U64, U32, {0x80000000, 0x80000000}, {1, 0x80000000}}, > > + {U64, S32, {0x80000000, 0x80000000}, {1, 0x80000000}}, > > + {U64, U64, {1, 0x80000000}, {1, 1}}, > > + {U64, S64, {1, 0x80000000}, {1, 1}}, > > + {U64, U32, {1, 0x80000000}, {1, 1}}, > > + {U64, S32, {1, 0x80000000}, {1, 1}}, > > + {U64, U64, {1, 0x80000000}, {0x80000000, 0x80000000}}, > > + {U64, S64, {1, 0x80000000}, {0x80000000, 0x80000000}}, > > + {U64, U32, {1, 0x80000000}, {0x80000000, 0x80000000}}, > > + {U64, S32, {1, 0x80000000}, {0x80000000, 0x80000000}}, > > JNE and JEQ are sign-agnostic, so there is no need to use both U64 and > S64 variants for comparison. As for the choice of values. Wouldn't it > make sense to use really a boundary conditions: > > 0, 0xffffffffffffffff, and 0x80000000000000 for 64-bit and > 0, 0xffffffff, and 0x80000000 for 32-bit? For this one use U32 as the init type? > Yeah, this makes sense. > BTW, all these cases should be tested with auto-generated tests, so > please make sure to run > > sudo SLOW_TESTS=1 ./test_progs -t reg_bounds_gen -j > > locally. It will take a bit of time, but should help to get confidence > in that everything is working and nothing regressed. > I have already run the slow testing (it indeed takes some time) and everything works well. I'll add the test results to the commit log in the next version too. Thanks! Menglong Dong > > }; > > > > /* Go over crafted hard-coded cases. This is fast, so we do it as part of > > -- > > 2.39.2 > >
diff --git a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c index 0c9abd279e18..53b8711cfd2d 100644 --- a/tools/testing/selftests/bpf/prog_tests/reg_bounds.c +++ b/tools/testing/selftests/bpf/prog_tests/reg_bounds.c @@ -590,12 +590,7 @@ static void range_cond(enum num_t t, struct range x, struct range y, *newy = range(t, max_t(t, x.a, y.a), min_t(t, x.b, y.b)); break; case OP_NE: - /* generic case, can't derive more information */ - *newx = range(t, x.a, x.b); - *newy = range(t, y.a, y.b); - break; - - /* below extended logic is not supported by verifier just yet */ + /* below logic is supported by the verifier now */ if (x.a == x.b && x.a == y.a) { /* X is a constant matching left side of Y */ *newx = range(t, x.a, x.b); @@ -2101,6 +2096,24 @@ static struct subtest_case crafted_cases[] = { {S32, S64, {(u32)(s32)S32_MIN, (u32)(s32)-255}, {(u32)(s32)-2, 0}}, {S32, S64, {0, 1}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, {S32, U32, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}, {(u32)(s32)S32_MIN, (u32)(s32)S32_MIN}}, + + /* edge overlap testings for BPF_NE */ + {U64, U64, {1, 1}, {1, 0x80000000}}, + {U64, S64, {1, 1}, {1, 0x80000000}}, + {U64, U32, {1, 1}, {1, 0x80000000}}, + {U64, S32, {1, 1}, {1, 0x80000000}}, + {U64, U64, {0x80000000, 0x80000000}, {1, 0x80000000}}, + {U64, S64, {0x80000000, 0x80000000}, {1, 0x80000000}}, + {U64, U32, {0x80000000, 0x80000000}, {1, 0x80000000}}, + {U64, S32, {0x80000000, 0x80000000}, {1, 0x80000000}}, + {U64, U64, {1, 0x80000000}, {1, 1}}, + {U64, S64, {1, 0x80000000}, {1, 1}}, + {U64, U32, {1, 0x80000000}, {1, 1}}, + {U64, S32, {1, 0x80000000}, {1, 1}}, + {U64, U64, {1, 0x80000000}, {0x80000000, 0x80000000}}, + {U64, S64, {1, 0x80000000}, {0x80000000, 0x80000000}}, + {U64, U32, {1, 0x80000000}, {0x80000000, 0x80000000}}, + {U64, S32, {1, 0x80000000}, {0x80000000, 0x80000000}}, }; /* Go over crafted hard-coded cases. This is fast, so we do it as part of