From nobody Tue Nov 26 16:29:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1706188092; cv=none; d=zohomail.com; s=zohoarc; b=CE4JeofymU9Z/+07wtSzXw9bDjp1BAS6STKH1fvUwCU8+OMxzL0hpusnB01PjqqeMAcetd6omODKor/w51cg1HIXDPyd29G0tAXYtvHtSlBm0PwTO18I9fv8na6nlQ94Ky/DdUhyZfstU5zJJWwNzUT/luNV+2FQwRPsbJyVyxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706188092; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qs4io9fLdT3cAG7lBct+y78n0jaTZdDvmWX1yYHA+NE=; b=IrlfTNWEn+cD3fhFEtg900wiyUTPc2DRs6yYu6dtRKv9xj9sYyotKqWcI60j8hM2k1otKl3DGLX1o8oJCPCyHIfzWsbPSPV7GDzKOrdX50mqawtiWBDjjYgNn/nH69ggSsPAp6OYvE4RkY1qz8yJ1zR1TNciZ7yN6i8489WEdjY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706188092385642.3876781263873; Thu, 25 Jan 2024 05:08:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSzRx-0005Lu-V3; Thu, 25 Jan 2024 08:07:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSzRq-0005CE-2T for qemu-devel@nongnu.org; Thu, 25 Jan 2024 08:07:14 -0500 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rSzRl-0001l5-Ln for qemu-devel@nongnu.org; Thu, 25 Jan 2024 08:07:12 -0500 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-55a50649ff6so7422175a12.3 for ; Thu, 25 Jan 2024 05:07:06 -0800 (PST) Received: from navi.cosmonova.net.ua ([95.67.24.131]) by smtp.gmail.com with ESMTPSA id er25-20020a056402449900b0055a829811ddsm6558709edb.48.2024.01.25.05.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 05:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1706188025; x=1706792825; darn=nongnu.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=qs4io9fLdT3cAG7lBct+y78n0jaTZdDvmWX1yYHA+NE=; b=F20ofYxkLDUNjzuCTdAPrgbSBEiDYj57htf65E/d9XDrtzyAKsU1FP+WPltkFGBKBQ XZJmul4bhQaK6xlLk4TKZeegrGDOSk8kU15f6o2G7orpzDHrwm0i2V+OCEhRa3uPHHJF KDJonBeklEebFsJ2NP5exqcygfokq1Qc/SFZjZ3JFbQwPl+AAv/i0Wu0AKxj0CYU7w7d vE+ynk0Zek5ppW/4Qbx2cP8uXY7Y5ikI0hFAXhB81TUXWqssCvX+aVSWCmDj71QJ3y9u 2+/wUg8cxDbS0XRatlgqYMEI2AolCs4obb9OamJRuuHP2r3kcftdiWphxzWFADISdkor 354w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706188025; x=1706792825; 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=qs4io9fLdT3cAG7lBct+y78n0jaTZdDvmWX1yYHA+NE=; b=YC8rZC03tkId4LY+JDHqX9PRUasKKNO/CiBBFAfn3TkQ6+ZX3h+XpzAWsq+cf6tkkV 2dNHNrX+sfz7fFleBSWWS71tqKB3dcA4m9QIRomdfgazGDSjJtY6vkp0JDEloFGXrhwq L9OyHq+ESgz7HxTUmFYdtcR365M+jai5Odv7asrPFRklQRjDDQXHxItpirkTd4Xnq649 CNXwT6Zze3cApcaqk36z/xgGwwcmckPdU6P00gt4vs1MfeCjFuyD4qcgFmbnwkyffEW5 baT0GFoy3jMkD5ZLfiIOBb09ktjeHf7/Pesg1qW4KfYH1VS2mjo9BUlBV++4dkDLD/99 Q0Pg== X-Gm-Message-State: AOJu0YzWTJ/JcBN0liwyvorWDw7lz8v7ZLF6etKPQWGmdomM5mUBjQfx 20AAJ6pLv46K6A1Jrfb/PtEhKCxaci0H+k6rZvyP4wIeEb9gON1oojFBDjQjNHw/fQ6x0Igch0b l X-Google-Smtp-Source: AGHT+IETVsUtJ7Q1t+vuLYFtxuMZaYqFyNM+r7x25ssjq7tuZfbtUp/z3E/pNgw0Yj7d/Py4IHiwyA== X-Received: by 2002:aa7:c343:0:b0:55a:61a0:b9dc with SMTP id j3-20020aa7c343000000b0055a61a0b9dcmr582228edr.35.1706188025284; Thu, 25 Jan 2024 05:07:05 -0800 (PST) From: Andrew Melnychenko To: jasowang@redhat.com, mst@redhat.com, armbru@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com Cc: yuri.benditovich@daynix.com, yan@daynix.com, akihiko.odaki@daynix.com Subject: [PATCH v8 2/5] ebpf: Added eBPF initialization by fds. Date: Thu, 25 Jan 2024 15:06:51 +0200 Message-ID: <20240125130656.425607-3-andrew@daynix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240125130656.425607-1-andrew@daynix.com> References: <20240125130656.425607-1-andrew@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::536; envelope-from=andrew@daynix.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1706188094155100007 Content-Type: text/plain; charset="utf-8" It allows using file descriptors of eBPF provided outside of QEMU. QEMU may be run without capabilities for eBPF and run RSS program provided by management tool(g.e. libvirt). Signed-off-by: Andrew Melnychenko --- ebpf/ebpf_rss-stub.c | 9 +++++++-- ebpf/ebpf_rss.c | 27 +++++++++++++++++++++++++++ ebpf/ebpf_rss.h | 5 +++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c index e71e229190..1c158b6e06 100644 --- a/ebpf/ebpf_rss-stub.c +++ b/ebpf/ebpf_rss-stub.c @@ -6,8 +6,7 @@ * Authors: * Yuri Benditovich * - * This work is licensed under the terms of the GNU GPL, version 2. See - * the COPYING file in the top-level directory. + * SPDX-License-Identifier: GPL-2.0-or-later */ =20 #include "qemu/osdep.h" @@ -28,6 +27,12 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx) return false; } =20 +bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, + int config_fd, int toeplitz_fd, int table_fd) +{ + return false; +} + bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *co= nfig, uint16_t *indirections_table, uint8_t *toeplitz_key) { diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c index c6e10265a7..20c44f2baa 100644 --- a/ebpf/ebpf_rss.c +++ b/ebpf/ebpf_rss.c @@ -145,6 +145,33 @@ error: return false; } =20 +bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, + int config_fd, int toeplitz_fd, int table_fd) +{ + if (ebpf_rss_is_loaded(ctx)) { + return false; + } + + if (program_fd < 0 || config_fd < 0 || toeplitz_fd < 0 || table_fd < 0= ) { + return false; + } + + ctx->program_fd =3D program_fd; + ctx->map_configuration =3D config_fd; + ctx->map_toeplitz_key =3D toeplitz_fd; + ctx->map_indirections_table =3D table_fd; + + if (!ebpf_rss_mmap(ctx)) { + ctx->program_fd =3D -1; + ctx->map_configuration =3D -1; + ctx->map_toeplitz_key =3D -1; + ctx->map_indirections_table =3D -1; + return false; + } + + return true; +} + static bool ebpf_rss_set_config(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config) { diff --git a/ebpf/ebpf_rss.h b/ebpf/ebpf_rss.h index 404cf53613..39646aff6f 100644 --- a/ebpf/ebpf_rss.h +++ b/ebpf/ebpf_rss.h @@ -13,6 +13,8 @@ #ifndef QEMU_EBPF_RSS_H #define QEMU_EBPF_RSS_H =20 +#define EBPF_RSS_MAX_FDS 4 + struct EBPFRSSContext { void *obj; int program_fd; @@ -40,6 +42,9 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx); =20 bool ebpf_rss_load(struct EBPFRSSContext *ctx); =20 +bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, + int config_fd, int toeplitz_fd, int table_fd); + bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *co= nfig, uint16_t *indirections_table, uint8_t *toeplitz_key); =20 --=20 2.43.0