From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C5A0144009; Sun, 12 May 2024 08:00:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B2C484067C; Sun, 12 May 2024 08:00:55 +0200 (CEST) Received: from mail-ej1-f98.google.com (mail-ej1-f98.google.com [209.85.218.98]) by mails.dpdk.org (Postfix) with ESMTP id EDE3540268 for ; Sun, 12 May 2024 08:00:53 +0200 (CEST) Received: by mail-ej1-f98.google.com with SMTP id a640c23a62f3a-a5a552c8cbaso158908066b.2 for ; Sat, 11 May 2024 23:00:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715493653; x=1716098453; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QtZza/OADrWcPYu67OUkwk6XcfsXdLL/4R0W++zpl0I=; b=mEBkQBCqIh557eZB8WdRxUkbimEk3Vzeq/1dK49kJQEq46mp6S5n7SZsQofX0/oIW+ 7pcjTvwo0FLJddaAmQNrhTelhk5r+6gFOMMEUo4Jcny95Tbu3Oe4M5aUF22E8j/dwGpP /QRgCf7y7vG7f8yYQsb+1uVX26L8bEtEogSx1id/CVn78jgLKFVOXSUR+sSUKgEGQ+sd 3CL2YBEQlGB6GYPIpQ9Xx3swUo+rsc5BvhYh2H/vp6x5tx7353LYfsad+/ZuiGTMPn8c kL6nyVr6s+j0cmGaACKdTSG7y+YG2FarAHrKDzW/ATCrqMA7vqEmO08NCTh2YS4EWCwk 6UCQ== X-Gm-Message-State: AOJu0YzkCoFh7pvcSRuAFzR6/0ZuMw5GgVOf48+ZdeZ74EozIlRxuuRj UTMuu2DQvCoYy+N8KgkxXulSIRW0tCZKm04gBDNaZx9HwkW2uF0gjUHN8tcatLxPRniBsYi4/pw vq3k2j3ZGwXRbkL4xfugOi5W/P61QvFF3SRxcBQTz X-Google-Smtp-Source: AGHT+IEYua3aaueW86m0kVwLq1p3NdAC/LfSNAtpNJiTuEw3o8RCwv8Oals6smgEAMWHlz9rCOSkd2XIbgmN X-Received: by 2002:a50:a6dc:0:b0:572:6ee9:5a37 with SMTP id 4fb4d7f45d1cf-5734d5cec64mr4885530a12.11.1715493653680; Sat, 11 May 2024 23:00:53 -0700 (PDT) Received: from claroty.com ([31.186.239.8]) by smtp-relay.gmail.com with ESMTPS id 4fb4d7f45d1cf-5733c22d379sm186041a12.38.2024.05.11.23.00.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 23:00:53 -0700 (PDT) X-Relaying-Domain: claroty.com Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-34d7a7585d7so2197424f8f.2 for ; Sat, 11 May 2024 23:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=claroty.com; s=google; t=1715493652; x=1716098452; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QtZza/OADrWcPYu67OUkwk6XcfsXdLL/4R0W++zpl0I=; b=dE1WRSWMppjcFp2cFBMylRUMi3oXIJKSVGpr43CP1cENj7NIYU2ajw2KetI2u/7BXy LTyXL/RwFzITenhOEGcqWLr6jQwPw19omWy5dlAyGMdwIm67nXC7uVxvyqSzHaYuN0TB wiC7eoxbUKZJ+h6P6SYb63aCw3k6Pjnaj+VWFhmr4DYxTaJ3nyzt9xgflxzmma4EOVyy qydwpOvAHHWeiK9poDWGTDef/1rq9LuuvFvkRxKq18ftB8MU7g66QWxEK0WAIhSTS/7Q dtUBlT1bQxFpvJ2SJ74vGz+vOC42Ng4G7K99SvQnXBSFYoInayjs8jalLEi+OlLH2Bi8 A5YA== X-Received: by 2002:a05:600c:4513:b0:41f:df08:5ef7 with SMTP id 5b1f17b1804b1-41feac5a4a7mr49080665e9.28.1715493652526; Sat, 11 May 2024 23:00:52 -0700 (PDT) X-Received: by 2002:a05:600c:4513:b0:41f:df08:5ef7 with SMTP id 5b1f17b1804b1-41feac5a4a7mr49080545e9.28.1715493652207; Sat, 11 May 2024 23:00:52 -0700 (PDT) Received: from localhost.localdomain ([94.188.185.10]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccfe15b6sm114420375e9.47.2024.05.11.23.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 23:00:52 -0700 (PDT) From: Yoav Winstein To: dev@dpdk.org Cc: Yoav Winstein , Konstantin Ananyev Subject: [PATCH] bpf: don't verify classic bpfs Date: Sun, 12 May 2024 09:00:41 +0300 Message-Id: <20240512060041.100723-1-yoav.w@claroty.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit x-netskope-inspected: true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When classic BPFs with lots of branching instructions are compiled, __rte_bpf_bpf_validate runs way too slow. A simple bpf such as: 'ether host a0:38:6d:af:17:eb or b3:a3:ff:b6:c1:ef or ...' 12 times results in ~1 minute of bpf validation. This patch makes __rte_bpf_bpf_validate be aware of bpf_prm originating from classic BPF, allowing to safely skip over the validation. Signed-off-by: Yoav Winstein --- app/test/test_bpf.c | 2 ++ lib/bpf/bpf_convert.c | 1 + lib/bpf/bpf_load.c | 4 +++- lib/bpf/rte_bpf.h | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c index 53e3a31123..7aae290c1a 100644 --- a/app/test/test_bpf.c +++ b/app/test/test_bpf.c @@ -3407,6 +3407,8 @@ static const char * const sample_filters[] = { " and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4 + 1] = 0x03)" " and (tcp[((tcp[12] & 0xF0) >> 4 ) * 4 + 2] < 0x04)" " and ((ip[2:2] - 4 * (ip[0] & 0x0F) - 4 * ((tcp[12] & 0xF0) >> 4) > 69))", + /* Performance */ + "ether host a0:38:6d:af:17:eb or b3:a3:ff:b6:c1:ef or 4a:e8:e7:5b:76:ce or 0d:87:fa:7a:a6:6d or bb:fd:c6:4b:bc:ae or 4e:28:dc:f1:1c:f6 or 3d:f2:b7:99:54:55 or 1c:5a:90:4b:82:ce or a7:28:08:ea:c9:84 or 1f:c0:2f:2f:0a:01 or c6:64:91:e9:78:f2 or 5b:cc:3f:90:39:ae or 4c:38:8f:ed:16:5c or cb:89:cb:54:0f:4f or 1e:0d:d7:b2:21:84 or 91:07:2b:88:e0:96 or 6c:ca:cf:bf:cf:3e or b9:df:f1:d6:dd:11 or ea:34:0b:b3:96:9e or 70:e5:18:9f:22:93", /* Other */ "len = 128", }; diff --git a/lib/bpf/bpf_convert.c b/lib/bpf/bpf_convert.c index d7ff2b4325..bc3c9a5d8e 100644 --- a/lib/bpf/bpf_convert.c +++ b/lib/bpf/bpf_convert.c @@ -567,6 +567,7 @@ rte_bpf_convert(const struct bpf_program *prog) /* Classic BPF programs use mbufs */ prm->prog_arg.type = RTE_BPF_ARG_PTR_MBUF; prm->prog_arg.size = sizeof(struct rte_mbuf); + prm->skip_verification = true; return prm; } diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c index de43347405..024e8dbc29 100644 --- a/lib/bpf/bpf_load.c +++ b/lib/bpf/bpf_load.c @@ -108,7 +108,9 @@ rte_bpf_load(const struct rte_bpf_prm *prm) return NULL; } - rc = __rte_bpf_validate(bpf); + if (!prm->skip_verification) + rc = __rte_bpf_validate(bpf); + if (rc == 0) { __rte_bpf_jit(bpf); if (mprotect(bpf, bpf->sz, PROT_READ) != 0) diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h index 80ebb0210f..6f3b4e3c31 100644 --- a/lib/bpf/rte_bpf.h +++ b/lib/bpf/rte_bpf.h @@ -94,6 +94,7 @@ struct rte_bpf_prm { /**< array of external symbols that eBPF code is allowed to reference */ uint32_t nb_xsym; /**< number of elements in xsym */ struct rte_bpf_arg prog_arg; /**< eBPF program input arg description */ + bool skip_verification; /**< should skip eBPF verification before load */ }; /** -- 2.34.1