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 1CE7845FD8; Fri, 3 Jan 2025 15:41:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1410040278; Fri, 3 Jan 2025 15:41:38 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 766D74021E for ; Fri, 3 Jan 2025 15:41:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735915295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dxNFAQ6xU6XL4WBtkn38E3/cJUWJNnVFqJhjRknyydU=; b=OquoaECfIggvYRAOs6ngNYQvnMg1M4LSdDSXjrcbxKV4pVYd9r36OEq5qDCfRv2fGhylEB noeHxOqT+8dv3aQCSIL3Hn9SAVqyLpvpeQYXVr2KH0dmxT7Av9M7kkDFsDkKldxzJsnXI5 1rMNYVC09q3+YSf9/saNFlIdwf2jUXI= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-10-xgML3m5tPkScu1RHFQGn3Q-1; Fri, 03 Jan 2025 09:41:32 -0500 X-MC-Unique: xgML3m5tPkScu1RHFQGn3Q-1 X-Mimecast-MFC-AGG-ID: xgML3m5tPkScu1RHFQGn3Q Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6758A1955F0A; Fri, 3 Jan 2025 14:41:31 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.26]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C2D319560AA; Fri, 3 Jan 2025 14:41:29 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [RFC] net/virtio-user: implement MAC setting for Vhost-kernel Date: Fri, 3 Jan 2025 15:41:27 +0100 Message-ID: <20250103144127.1438904-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: eV41UxpXHcVsNUFY0hhQTQVqYhbJcSuqr7DWcdCbvp0_1735915291 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=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 This patch implements MAC address setting with Vhost-kernel backends. With this, it is possible to set the TAP interface MAC address using the Ethdev API. Signed-off-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/vhost_kernel.c | 23 +++++++++++++++++++ .../net/virtio/virtio_user/vhost_kernel_tap.c | 2 +- .../net/virtio/virtio_user/vhost_kernel_tap.h | 2 +- .../net/virtio/virtio_user/virtio_user_dev.c | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index e42bb35935..4ff47c2327 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -12,6 +12,7 @@ #include #include "vhost.h" +#include "virtio.h" #include "virtio_user_dev.h" #include "vhost_kernel_tap.h" @@ -152,6 +153,9 @@ vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features) if (tap_flags & IFF_MULTI_QUEUE) *features |= (1ull << VIRTIO_NET_F_MQ); + /* vhost_kernel supports setting tap MAC address. */ + *features |= (1ull << VIRTIO_NET_F_MAC); + return 0; } @@ -371,6 +375,24 @@ vhost_kernel_set_status(struct virtio_user_dev *dev __rte_unused, uint8_t status return -ENOTSUP; } +static int +vhost_kernel_set_config(struct virtio_user_dev *dev, + const uint8_t *data, uint32_t off, uint32_t len) +{ + struct vhost_kernel_data *backend_data = dev->backend_data; + + if (off == offsetof(struct virtio_net_config, mac)) { + if (len != RTE_ETHER_ADDR_LEN) { + PMD_DRV_LOG(ERR, "Invalid MAC address length"); + return -EINVAL; + } + + return tap_set_mac(backend_data->tapfds[0], data); + } + + return -ENOTSUP; +} + /** * Set up environment to talk with a vhost kernel backend. * @@ -613,6 +635,7 @@ struct virtio_user_backend_ops virtio_ops_kernel = { .set_vring_addr = vhost_kernel_set_vring_addr, .get_status = vhost_kernel_get_status, .set_status = vhost_kernel_set_status, + .set_config = vhost_kernel_set_config, .enable_qp = vhost_kernel_enable_queue_pair, .update_link_state = vhost_kernel_update_link_state, .get_intr_fd = vhost_kernel_get_intr_fd, diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c index 611e2e25ec..3e13f8f65b 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c @@ -112,7 +112,7 @@ tap_get_flags(int tapfd, unsigned int *tap_flags) } int -tap_set_mac(int tapfd, uint8_t *mac) +tap_set_mac(int tapfd, const uint8_t *mac) { struct ifreq ifr; diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h index 636a0481be..0b9258dcb7 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h @@ -40,6 +40,6 @@ int tap_support_features(unsigned int *tap_features); int tap_open(const char *ifname, unsigned int r_flags, bool multi_queue); int tap_get_name(int tapfd, char **ifname); int tap_get_flags(int tapfd, unsigned int *tap_flags); -int tap_set_mac(int tapfd, uint8_t *mac); +int tap_set_mac(int tapfd, const uint8_t *mac); #endif diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 2997d2bd26..d1b3f986ef 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -789,7 +789,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues, if (!packed_vq) dev->unsupported_features |= (1ull << VIRTIO_F_RING_PACKED); - if (dev->mac_specified) + if (dev->mac_specified || (dev->device_features & (1ull << VIRTIO_NET_F_MAC))) dev->frontend_features |= (1ull << VIRTIO_NET_F_MAC); else dev->unsupported_features |= (1ull << VIRTIO_NET_F_MAC); -- 2.47.1