From nobody Tue Feb 10 16:22:13 2026 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=1686781877; cv=none; d=zohomail.com; s=zohoarc; b=VrPks8foCuE+K9qOPxFlXpHTVpw2zQhY8VdrfCwYrV3n6HzdKdHg/xf00EIPuyxdm4uLVDN1f+oHW0TeBT5jGNl7ZnwVTd0dj616pEKRgZzuQeHXL9NEuTXZhVJ0TY7FFieGkIH+JoNjZArAol5CrGa9cRqFdUhVTZO+HQ4JkDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686781877; 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=q8y2m75WdRAUoOVZlVFJT6+Q63GoENOy7L83c/HzsBo=; b=cbo/n/z7n5bXe9no1yhKZZbb0JmI3YjKfb3cN75xdzSVN8cWxP2BKADAtw+Japso929Efgr4KsBWZmHzqfihpp6TqiB4KvrMEbDaC3xgIF92YQaKuHBkAwsYOAhpEgQ3Mo2NI05t9PaQSXXPeQp49KjTSlpc37TvDPt8RxtEBQI= 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 1686781877778403.98571707522706; Wed, 14 Jun 2023 15:31:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q9Z02-00043B-Us; Wed, 14 Jun 2023 18:29:58 -0400 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 1q9Z01-00042a-47 for qemu-devel@nongnu.org; Wed, 14 Jun 2023 18:29:57 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q9Yzz-0001Fr-D4 for qemu-devel@nongnu.org; Wed, 14 Jun 2023 18:29:56 -0400 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f64fb05a8aso9536736e87.0 for ; Wed, 14 Jun 2023 15:29:55 -0700 (PDT) Received: from localhost.localdomain ([46.98.110.34]) by smtp.gmail.com with ESMTPSA id x8-20020ac24888000000b004f39837204fsm2279483lfc.85.2023.06.14.15.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 15:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1686781794; x=1689373794; 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=q8y2m75WdRAUoOVZlVFJT6+Q63GoENOy7L83c/HzsBo=; b=p+0WEryF8pb+iDtFcQ2kEeYdT0nmijBpne0eAZbsXp0TYY4lK1ueM5PC60xCHD95yU YBPWpBxeUYR5mZEcIOESR9+bHvqVl54pp8WdcE9w/nntgTTrfTUOAsE9pKPBtMg6yAXm y9hvlafPMCP6hS+HVB17P40uLD6aJsulOPrMm5nDA7bkiTH//hfYef08WJDZCFWchzrq g0hBWwzH5B7Ta0f4hxXQNSvHYBYmIkU0nhO0RFPOexyo8I5AwqA29xFBD1J4rSZk7SmJ zcXnhBGfRwGsErBN2ytkHjMavYDq5vm3ZvD+GhtjyvlV0/jnJkE0ibFCeE9QUxdH61fh GN5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686781794; x=1689373794; 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=q8y2m75WdRAUoOVZlVFJT6+Q63GoENOy7L83c/HzsBo=; b=UYZmwya6MVygMbofQEr8kxy6WNkAs7/nhdgPQ/RneDOf7vD3FUhI5nNYYHaHl8jyYh UK45ss5wUjdZ2Cl8RZKxr8Kd+DV9fnqCZBZsSJ8Jp56BSxwd5aAkJnK6sZq15wvevQ5y 42stFsMlQ4B+2Z+tNjVWZCSWKIWxxrKgHr8FT3fqOgcpM0npNW82yukCtNAFLRK3Vf85 mivtLjwRC5nUEIpa0nXI5Pi0vSLH3sqldjFmmICJ93rnFoNuztCPVkUFc/Ew+wh2EoRi bep7yBeyD3EJ2srpian9h6UidTdj2UvenuAaf/6ATlHpPLuTQvdnI0+71P7uFimp1PzZ msgw== X-Gm-Message-State: AC+VfDwszk6T/lyFj5o4mJTCRzJ4E/5qyAY7sA9TgZmPwZfIwQ+Z3tS5 IUQQehr2/EhYyHDTPPpCGcXlFw== X-Google-Smtp-Source: ACHHUZ6rKHVNCL8pv4CA2lFjf0CQ3rqv5meeaZfbQNxa2nd63YksW/qutp+vCZEo67ymKUPPcgL3oA== X-Received: by 2002:ac2:5616:0:b0:4f6:2a65:8087 with SMTP id v22-20020ac25616000000b004f62a658087mr8844402lfd.25.1686781793801; Wed, 14 Jun 2023 15:29:53 -0700 (PDT) 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 Subject: [PATCH v3 3/6] virtio-net: Added property to load eBPF RSS with fds. Date: Thu, 15 Jun 2023 01:10:23 +0300 Message-Id: <20230614221026.56950-4-andrew@daynix.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230614221026.56950-1-andrew@daynix.com> References: <20230614221026.56950-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::130; envelope-from=andrew@daynix.com; helo=mail-lf1-x130.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.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1686781878020100001 Content-Type: text/plain; charset="utf-8" eBPF RSS program and maps may now be passed during initialization. Initially was implemented for libvirt to launch qemu without permissions, and initialized eBPF program through the helper. Signed-off-by: Andrew Melnychenko Reviewed-by: Daniel P. Berrang=C3=A9 --- hw/net/virtio-net.c | 55 ++++++++++++++++++++++++++++++---- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6df6b7329d2..9a5443aaef1 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -42,6 +42,7 @@ #include "sysemu/sysemu.h" #include "trace.h" #include "monitor/qdev.h" +#include "monitor/monitor.h" #include "hw/pci/pci_device.h" #include "net_rx_pkt.h" #include "hw/virtio/vhost.h" @@ -1304,14 +1305,55 @@ static void virtio_net_detach_epbf_rss(VirtIONet *n) virtio_net_attach_ebpf_to_backend(n->nic, -1); } =20 -static bool virtio_net_load_ebpf(VirtIONet *n) +static bool virtio_net_load_ebpf_fds(VirtIONet *n, Error **errp) { - if (!virtio_net_attach_ebpf_to_backend(n->nic, -1)) { - /* backend does't support steering ebpf */ - return false; + int fds[EBPF_RSS_MAX_FDS] =3D { [0 ... EBPF_RSS_MAX_FDS - 1] =3D -1}; + int nfds =3D 0; + int ret =3D true; + int i =3D 0; + g_auto(GStrv) fds_strs =3D g_strsplit(n->ebpf_rss_fds, ":", 0); + + ERRP_GUARD(); + + if (g_strv_length(fds_strs) !=3D EBPF_RSS_MAX_FDS) { + error_setg(errp, + "Expected %d file descriptors but got %d", + EBPF_RSS_MAX_FDS, g_strv_length(fds_strs)); + return false; + } + + for (i =3D 0; i < nfds; i++) { + fds[i] =3D monitor_fd_param(monitor_cur(), fds_strs[i], errp); + if (*errp) { + ret =3D false; + goto exit; + } + } + + ret =3D ebpf_rss_load_fds(&n->ebpf_rss, fds[0], fds[1], fds[2], fds[3]= ); + +exit: + if (!ret || *errp) { + for (i =3D 0; i < nfds && fds[i] !=3D -1; i++) { + close(fds[i]); + } } =20 - return ebpf_rss_load(&n->ebpf_rss); + return ret; +} + +static bool virtio_net_load_ebpf(VirtIONet *n, Error **errp) +{ + bool ret =3D false; + + if (virtio_net_attach_ebpf_to_backend(n->nic, -1)) { + if (!(n->ebpf_rss_fds + && virtio_net_load_ebpf_fds(n, errp))) { + ret =3D ebpf_rss_load(&n->ebpf_rss); + } + } + + return ret; } =20 static void virtio_net_unload_ebpf(VirtIONet *n) @@ -3741,7 +3783,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) net_rx_pkt_init(&n->rx_pkt); =20 if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { - virtio_net_load_ebpf(n); + virtio_net_load_ebpf(n, errp); } } =20 @@ -3903,6 +3945,7 @@ static Property virtio_net_properties[] =3D { VIRTIO_NET_F_RSS, false), DEFINE_PROP_BIT64("hash", VirtIONet, host_features, VIRTIO_NET_F_HASH_REPORT, false), + DEFINE_PROP_STRING("ebpf_rss_fds", VirtIONet, ebpf_rss_fds), DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features, VIRTIO_NET_F_RSC_EXT, false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout, diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index ef234ffe7ef..e10ce88f918 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -219,6 +219,7 @@ struct VirtIONet { VirtioNetRssData rss_data; struct NetRxPkt *rx_pkt; struct EBPFRSSContext ebpf_rss; + char *ebpf_rss_fds; }; =20 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, --=20 2.39.1