From nobody Tue Feb 10 20:09:33 2026 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1623233256; cv=none; d=zohomail.com; s=zohoarc; b=msZlcotH16m8ZkQYcVshXS/WpOU45ulHDuHGp/C6UFvYR36obGln1tAHkJej69aMxHKH7ITjA+3iaqAV9+9fqXbRmfBnVprxCfTh3vCgyCyy6Nzia2MZT3bc4kHc0Mz2ujPD61iux09Fsp+We+BfkDqsVbJc4OWB5EBaQOxF+Rc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623233256; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zDjdmfF5W2tPz/BdMjDQWwRdeLRUFtNW7LLUnye9n/s=; b=T3t2wVuGGJtHN9vs7bgOazFjbioWFCs4LGinIewtIB6dbLlv80OPSI39BoVBBabImj9cpVm5G2D30U+Hg9UbHKVEwguQq4YgmwDo4tKtlarTW+5dZygGHa9Bxc5hUbnW7kc+B31zNyCdi+UsBktIU0/DVeUJGVh6oSnZhtxSi6A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=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 1623233256626408.8394718228526; Wed, 9 Jun 2021 03:07:36 -0700 (PDT) Received: from localhost ([::1]:51374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqv7X-0003FX-JY for importer2@patchew.org; Wed, 09 Jun 2021 06:07:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqv5G-0000Lw-FV for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:14 -0400 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]:41746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqv5D-0006tM-8L for qemu-devel@nongnu.org; Wed, 09 Jun 2021 06:05:14 -0400 Received: by mail-lf1-x12c.google.com with SMTP id j20so7812097lfe.8 for ; Wed, 09 Jun 2021 03:05:10 -0700 (PDT) Received: from navi.cosmonova.net.ua ([95.67.24.131]) by smtp.gmail.com with ESMTPSA id l12sm333590lfk.10.2021.06.09.03.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 03:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zDjdmfF5W2tPz/BdMjDQWwRdeLRUFtNW7LLUnye9n/s=; b=SU1sSngvAC17c6KusTyJXkfrccBkxleILzVV7lds4iDftKbTpCkQohTtsMqjS0ZHlP 5cyVwWBKCeRK73yjb63uJGPhaOzIeiqLDnH+ojc+hN1vFZHMC2lBKMObBPHxpITrW0uE lubpCvTYhf4ZSBa3v345cqrqcbu+cCpnrVdbnJIyBTzqrtmqxXDRoXYWpUjFjVSMHGQ+ TUXmAFk0FjsGN+5MEQFuRn4/I5c0TeYaghRpUYYEryNNsK1HgSYuOPcwObUgm/Q2dNTN JymX9X9OV+00Ux5vSX9y4OlQHRhY2Ef9BhhkVANH8eL7/tP4qWu2RNIoixFObrCMIjp9 BqNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zDjdmfF5W2tPz/BdMjDQWwRdeLRUFtNW7LLUnye9n/s=; b=YokJZwKOwpqSjM1aM/IrRJLrb+Tcp3lO2OgXLKCjbKlYxVLHzEOQifCI4wcAMUi1mB p7FdA1AwWuZcVwJeehRf0BwFCT1Jb5C+3j8kHP36WwpoRfdPVGC/5a6erfbttrenRxHI YbFcRdwhRvOe4gGEgqhhh0GylAlLdUXY/ExmSV+S1LK8IPkxFbGC7dNluLWvERRcTggW KPLpBM9lcn4ZllaUN/WfSSnHhXCJwIn44HQudYjUJ6sKj/ZK9YSdekLQ20zNx8V+M31E BHeUWqdM8t+BOyKAedo8Rs4aASyWabPDVRmtQcHZ1IKQpvSmGUf6KRs1AKMpIlaP0zuO okYA== X-Gm-Message-State: AOAM531AGUJ+MOcCrPVDgbM1V63LE8J+JM/ehg6nwNJKL1Og53r4x3PO 15J2MtjHwe6FlNHB7tHsRPnefA== X-Google-Smtp-Source: ABdhPJyxSBJPJ5B8vgm/AHMlKszteU+SP8CJUtec49W/iWGjA89DP/et5rhXDOQJmnvZgQV7I9bZtg== X-Received: by 2002:a05:6512:507:: with SMTP id o7mr2795921lfb.453.1623233109030; Wed, 09 Jun 2021 03:05:09 -0700 (PDT) From: Andrew Melnychenko To: mst@redhat.com, yuri.benditovich@daynix.com, jasowang@redhat.com, armbru@redhat.com, eblake@redhat.com, berrange@redhat.com Subject: [RFC PATCH 3/5] ebpf_rss_helper: Added helper for eBPF RSS. Date: Wed, 9 Jun 2021 13:04:55 +0300 Message-Id: <20210609100457.142570-4-andrew@daynix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210609100457.142570-1-andrew@daynix.com> References: <20210609100457.142570-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::12c; envelope-from=andrew@daynix.com; helo=mail-lf1-x12c.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Helper program. Loads eBPF RSS program and maps and passes them through uni= x socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net. Signed-off-by: Andrew Melnychenko --- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 8 +++ 2 files changed, 138 insertions(+) create mode 100644 ebpf/qemu-ebpf-rss-helper.c diff --git a/ebpf/qemu-ebpf-rss-helper.c b/ebpf/qemu-ebpf-rss-helper.c new file mode 100644 index 0000000000..f0379dddf2 --- /dev/null +++ b/ebpf/qemu-ebpf-rss-helper.c @@ -0,0 +1,130 @@ +/* + * eBPF RSS Helper + * + * Developed by Daynix Computing LTD (http://www.daynix.com) + * + * Authors: + * Andrew Melnychenko + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Description: This is helper program for libvirtd. + * It loads eBPF RSS program and passes fds through unix sock= et. + * Built by meson, target - 'qemu-ebpf-rss-helper'. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ebpf_rss.h" + +static int send_fds(int socket, int *fds, int n) +{ + struct msghdr msg =3D {}; + struct cmsghdr *cmsg =3D NULL; + char buf[CMSG_SPACE(n * sizeof(int))]; + char dummy_buffer =3D 0; + struct iovec io =3D { .iov_base =3D &dummy_buffer, + .iov_len =3D sizeof(dummy_buffer) }; + + memset(buf, 0, sizeof(buf)); + + msg.msg_iov =3D &io; + msg.msg_iovlen =3D 1; + msg.msg_control =3D buf; + msg.msg_controllen =3D sizeof(buf); + + cmsg =3D CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level =3D SOL_SOCKET; + cmsg->cmsg_type =3D SCM_RIGHTS; + cmsg->cmsg_len =3D CMSG_LEN(n * sizeof(int)); + + memcpy(CMSG_DATA(cmsg), fds, n * sizeof(int)); + + return sendmsg(socket, &msg, 0); +} + +static void print_help_and_exit(const char *prog, int exitcode) +{ + fprintf(stderr, "%s - load eBPF RSS program for qemu and pass eBPF fds" + " through unix socket.\n", prog); + fprintf(stderr, "\t--fd , -f - unix socket file descriptor" + " used to pass eBPF fds.\n"); + fprintf(stderr, "\t--help, -h - this help.\n"); + exit(exitcode); +} + +int main(int argc, char **argv) +{ + char *fd_string =3D NULL; + int unix_fd =3D 0; + struct EBPFRSSContext ctx =3D {}; + int fds[EBPF_RSS_MAX_FDS] =3D {}; + int ret =3D -1; + + for (;;) { + int c; + static struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"fd", required_argument, 0, 'f'}, + {0, 0, 0, 0} + }; + c =3D getopt_long(argc, argv, "hf:", + long_options, NULL); + + if (c =3D=3D -1) { + break; + } + + switch (c) { + case 'f': + fd_string =3D optarg; + break; + case 'h': + default: + print_help_and_exit(argv[0], + c =3D=3D 'h' ? EXIT_SUCCESS : EXIT_FAILURE); + } + } + + if (!fd_string) { + fprintf(stderr, "Unix file descriptor not present.\n"); + print_help_and_exit(argv[0], EXIT_FAILURE); + } + + fprintf(stderr, "FD %s\n", fd_string); + + unix_fd =3D atoi(fd_string); + + if (!unix_fd) { + fprintf(stderr, "Unix file descriptor is invalid.\n"); + return EXIT_FAILURE; + } + + ebpf_rss_init(&ctx); + if (!ebpf_rss_load(&ctx)) { + fprintf(stderr, "Can't load ebpf.\n"); + return EXIT_FAILURE; + } + fds[0] =3D ctx.program_fd; + fds[1] =3D ctx.map_configuration; + fds[2] =3D ctx.map_toeplitz_key; + fds[3] =3D ctx.map_indirections_table; + + ret =3D send_fds(unix_fd, fds, EBPF_RSS_MAX_FDS); + if (ret < 0) { + fprintf(stderr, "Issue while sending fds: %s.\n", strerror(errno)); + } + + ebpf_rss_unload(&ctx); + + return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} + diff --git a/meson.build b/meson.build index 626cf932c1..ce26bddead 100644 --- a/meson.build +++ b/meson.build @@ -2413,6 +2413,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif =20 if 'CONFIG_IVSHMEM' in config_host --=20 2.31.1