From patchwork Tue Apr 23 10:41:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13639761 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A73575802 for ; Tue, 23 Apr 2024 10:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868880; cv=none; b=NV6nd8BtriK1etBOu+ZTHruVjiCFww5BPe0YdQ52aM/xCRLQ0gt/KLN5tw3ChS1N5vpu++kNeIcXc6ImcX0HNd03aWFOSae6GsH+XC2GliYjjMDC2ZAvt7/Jz/25kM88WMOEgzqRenkaUmojO/EUOQSbr3twMAuF3EtCCuug7gY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868880; c=relaxed/simple; bh=6+cdGuSohVVcZsEtEaB+WUeWNhRp735twxzPhawYX2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PhaZ8x2kyXhXoBP2ZZFmGG7CqXLyIcuy15wbi7XDqEjO5YD6zOu2tPs/sH1obwU/5iq7peRymixHddn/+IgyjKjh4jIl+s0RTpcZCoWQYQvIMTY3uDDgO4wG1Zi9xzFfXAbl/tG+yPZdvfIeE4Xydob/xAjgbD4K11UK1gdb7DA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b=p4oE/O5F; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="p4oE/O5F" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a557044f2ddso604275666b.2 for ; Tue, 23 Apr 2024 03:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713868876; x=1714473676; darn=vger.kernel.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=vIem1pG4tCyS+CC0IvtQjtNP5aTmhFvjHO5o/QyAp+k=; b=p4oE/O5FmezdJwNBmdTLAR98Tbm5AqcogyUyfT3W5x2F6SGGKcXTnnes8A+pCDkQhB yLyH0MD5+Ax5Izb8qyiSpXWWmL8MUxGYuUSht+aNMu7BTY72rJYPepDjj/yJ9m7njBgb YbQTSwkpDdnsVEGsE5zPMbdx/x/HaMIrVWujaVSDaePBekxdy1RJFk29LWu1dcr927sI +Fy1YNHGcb0HTeAhxSCMp0kX1GJlBuggYPQr2QZaoRSbNXAUwqdF3fJvZoF3aEOjEAn3 V9f7IScplENBKt+5dxeIgerOLadmK6gLQws/eHipQ4WtrziC6ODFW+6nqQn43ZvSnag7 nEag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713868876; x=1714473676; 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=vIem1pG4tCyS+CC0IvtQjtNP5aTmhFvjHO5o/QyAp+k=; b=ORfEAdKo/oI4L1+I600ulV5kII2WgVSo8RL06/5O6zmgaVCWMo1pHkqJZ4I9aawvDu 4uxd4eGMz6Y7HCvOiwnHNykHPrezi4W5VQjIb/JZ1UtCAGMboPQCWzugYlBLPzCCKH+h 6bc2hXU4kydoWXy4k9MUppJlpHr8zDvHzyfpPk1inDyXbgX3EoeEMjkx+UELCJl3prlX Z6J58q+OR2JkXGjFnqB8EXUP4rx7hdWza2XOcYImuqsGPVdZ+fpcZ7KTq7NvYB+Ubjf4 0nEjOpu06P+wjXO1W1POunnS9ciGasoEPNIWn7Y54Iaolnbj8Y9OHyY5ccw0BPM2FSyY ZlRg== X-Gm-Message-State: AOJu0YyUspYkwEtMkpkJ3cedkVc3VKJR3rELV1XTTjKzYdp9tlJgl20w Eu13PDWtxR+be0800/4Nc6oowNyQflxZN8O/+kTDwm8w6K2I57JcibsUjaQtD2w2vdb53s4Pi8J i X-Google-Smtp-Source: AGHT+IHjeDuPAaOV0jcKax6AfPSCrin/KVoZ3J4C4kw2DxcV76sXDsmxsEQE2SlHmnIHrLboHOhYYA== X-Received: by 2002:a17:906:3196:b0:a51:b3cb:cdca with SMTP id 22-20020a170906319600b00a51b3cbcdcamr9428625ejy.26.1713868876199; Tue, 23 Apr 2024 03:41:16 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id z15-20020a170906668f00b00a51d073da7esm6856212ejo.82.2024.04.23.03.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 03:41:14 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, parav@nvidia.com, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com, vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com, virtualization@lists.linux.dev Subject: [patch net-next v5 repost 1/5] virtio: add debugfs infrastructure to allow to debug virtio features Date: Tue, 23 Apr 2024 12:41:05 +0200 Message-ID: <20240423104109.3880713-2-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423104109.3880713-1-jiri@resnulli.us> References: <20240423104109.3880713-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Currently there is no way for user to set what features the driver should obey or not, it is hard wired in the code. In order to be able to debug the device behavior in case some feature is disabled, introduce a debugfs infrastructure with couple of files allowing user to see what features the device advertises and to set filter for features used by driver. Example: $cat /sys/bus/virtio/devices/virtio0/features 1110010111111111111101010000110010000000100000000000000000000000 $ echo "5" >/sys/kernel/debug/virtio/virtio0/filter_feature_add $ cat /sys/kernel/debug/virtio/virtio0/filter_features 5 $ echo "virtio0" > /sys/bus/virtio/drivers/virtio_net/unbind $ echo "virtio0" > /sys/bus/virtio/drivers/virtio_net/bind $ cat /sys/bus/virtio/devices/virtio0/features 1110000111111111111101010000110010000000100000000000000000000000 Note that sysfs "features" now already exists, this patch does not touch it. Signed-off-by: Jiri Pirko --- v4->v5: - added exported symbols, adjusted Kconfig a bit (whitespace) v3->v4: - s/know/now/ typo fix in description v2->v3: - added missing kdoc for debugfs_filter_features struct field --- drivers/virtio/Kconfig | 10 +++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio.c | 8 +++ drivers/virtio/virtio_debug.c | 114 ++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 35 +++++++++++ 5 files changed, 168 insertions(+) create mode 100644 drivers/virtio/virtio_debug.c diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index c17193544268..6284538a8184 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -178,4 +178,14 @@ config VIRTIO_DMA_SHARED_BUFFER This option adds a flavor of dma buffers that are backed by virtio resources. +config VIRTIO_DEBUG + bool "Debug facilities" + depends on VIRTIO + help + Enable this to expose debug facilities over debugfs. + This allows to debug features, to see what features the device + advertises and to set filter for features used by driver. + + If unsure, say N. + endif # VIRTIO_MENU diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile index 73ace62af440..58b2b0489fc9 100644 --- a/drivers/virtio/Makefile +++ b/drivers/virtio/Makefile @@ -13,3 +13,4 @@ obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o obj-$(CONFIG_VIRTIO_VDPA) += virtio_vdpa.o obj-$(CONFIG_VIRTIO_MEM) += virtio_mem.o obj-$(CONFIG_VIRTIO_DMA_SHARED_BUFFER) += virtio_dma_buf.o +obj-$(CONFIG_VIRTIO_DEBUG) += virtio_debug.o diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 9510c551dce8..b968b2aa5f4d 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -274,6 +274,9 @@ static int virtio_dev_probe(struct device *_d) else dev->features = driver_features_legacy & device_features; + /* When debugging, user may filter some features by hand. */ + virtio_debug_device_filter_features(dev); + /* Transport features always preserved to pass to finalize_features. */ for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) if (device_features & (1ULL << i)) @@ -465,6 +468,8 @@ int register_virtio_device(struct virtio_device *dev) /* Acknowledge that we've seen the device. */ virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE); + virtio_debug_device_init(dev); + /* * device_add() causes the bus infrastructure to look for a matching * driver. @@ -496,6 +501,7 @@ void unregister_virtio_device(struct virtio_device *dev) int index = dev->index; /* save for after device release */ device_unregister(&dev->dev); + virtio_debug_device_exit(dev); ida_free(&virtio_index_ida, index); } EXPORT_SYMBOL_GPL(unregister_virtio_device); @@ -590,11 +596,13 @@ static int virtio_init(void) { if (bus_register(&virtio_bus) != 0) panic("virtio bus registration failed"); + virtio_debug_init(); return 0; } static void __exit virtio_exit(void) { + virtio_debug_exit(); bus_unregister(&virtio_bus); ida_destroy(&virtio_index_ida); } diff --git a/drivers/virtio/virtio_debug.c b/drivers/virtio/virtio_debug.c new file mode 100644 index 000000000000..95c8fc7705bb --- /dev/null +++ b/drivers/virtio/virtio_debug.c @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include + +static struct dentry *virtio_debugfs_dir; + +static int virtio_debug_device_features_show(struct seq_file *s, void *data) +{ + struct virtio_device *dev = s->private; + u64 device_features; + unsigned int i; + + device_features = dev->config->get_features(dev); + for (i = 0; i < BITS_PER_LONG_LONG; i++) { + if (device_features & (1ULL << i)) + seq_printf(s, "%u\n", i); + } + return 0; +} +DEFINE_SHOW_ATTRIBUTE(virtio_debug_device_features); + +static int virtio_debug_filter_features_show(struct seq_file *s, void *data) +{ + struct virtio_device *dev = s->private; + unsigned int i; + + for (i = 0; i < BITS_PER_LONG_LONG; i++) { + if (dev->debugfs_filter_features & (1ULL << i)) + seq_printf(s, "%u\n", i); + } + return 0; +} +DEFINE_SHOW_ATTRIBUTE(virtio_debug_filter_features); + +static int virtio_debug_filter_features_clear(void *data, u64 val) +{ + struct virtio_device *dev = data; + + if (val == 1) + dev->debugfs_filter_features = 0; + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(virtio_debug_filter_features_clear_fops, NULL, + virtio_debug_filter_features_clear, "%llu\n"); + +static int virtio_debug_filter_feature_add(void *data, u64 val) +{ + struct virtio_device *dev = data; + + if (val >= BITS_PER_LONG_LONG) + return -EINVAL; + dev->debugfs_filter_features |= BIT_ULL_MASK(val); + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(virtio_debug_filter_feature_add_fops, NULL, + virtio_debug_filter_feature_add, "%llu\n"); + +static int virtio_debug_filter_feature_del(void *data, u64 val) +{ + struct virtio_device *dev = data; + + if (val >= BITS_PER_LONG_LONG) + return -EINVAL; + dev->debugfs_filter_features &= ~BIT_ULL_MASK(val); + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(virtio_debug_filter_feature_del_fops, NULL, + virtio_debug_filter_feature_del, "%llu\n"); + +void virtio_debug_device_init(struct virtio_device *dev) +{ + dev->debugfs_dir = debugfs_create_dir(dev_name(&dev->dev), + virtio_debugfs_dir); + debugfs_create_file("device_features", 0400, dev->debugfs_dir, dev, + &virtio_debug_device_features_fops); + debugfs_create_file("filter_features", 0400, dev->debugfs_dir, dev, + &virtio_debug_filter_features_fops); + debugfs_create_file("filter_features_clear", 0200, dev->debugfs_dir, dev, + &virtio_debug_filter_features_clear_fops); + debugfs_create_file("filter_feature_add", 0200, dev->debugfs_dir, dev, + &virtio_debug_filter_feature_add_fops); + debugfs_create_file("filter_feature_del", 0200, dev->debugfs_dir, dev, + &virtio_debug_filter_feature_del_fops); +} +EXPORT_SYMBOL_GPL(virtio_debug_device_init); + +void virtio_debug_device_filter_features(struct virtio_device *dev) +{ + dev->features &= ~dev->debugfs_filter_features; +} +EXPORT_SYMBOL_GPL(virtio_debug_device_filter_features); + +void virtio_debug_device_exit(struct virtio_device *dev) +{ + debugfs_remove_recursive(dev->debugfs_dir); +} +EXPORT_SYMBOL_GPL(virtio_debug_device_exit); + +void virtio_debug_init(void) +{ + virtio_debugfs_dir = debugfs_create_dir("virtio", NULL); +} +EXPORT_SYMBOL_GPL(virtio_debug_init); + +void virtio_debug_exit(void) +{ + debugfs_remove_recursive(virtio_debugfs_dir); +} +EXPORT_SYMBOL_GPL(virtio_debug_exit); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 26c4325aa373..96fea920873b 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -126,6 +126,8 @@ struct virtio_admin_cmd { * @vqs: the list of virtqueues for this device. * @features: the features supported by both driver and device. * @priv: private pointer for the driver's use. + * @debugfs_dir: debugfs directory entry. + * @debugfs_filter_features: features to be filtered set by debugfs. */ struct virtio_device { int index; @@ -141,6 +143,10 @@ struct virtio_device { struct list_head vqs; u64 features; void *priv; +#ifdef CONFIG_VIRTIO_DEBUG + struct dentry *debugfs_dir; + u64 debugfs_filter_features; +#endif }; #define dev_to_virtio(_dev) container_of_const(_dev, struct virtio_device, dev) @@ -237,4 +243,33 @@ void virtqueue_dma_sync_single_range_for_cpu(struct virtqueue *_vq, dma_addr_t a void virtqueue_dma_sync_single_range_for_device(struct virtqueue *_vq, dma_addr_t addr, unsigned long offset, size_t size, enum dma_data_direction dir); + +#ifdef CONFIG_VIRTIO_DEBUG +void virtio_debug_device_init(struct virtio_device *dev); +void virtio_debug_device_exit(struct virtio_device *dev); +void virtio_debug_device_filter_features(struct virtio_device *dev); +void virtio_debug_init(void); +void virtio_debug_exit(void); +#else +static inline void virtio_debug_device_init(struct virtio_device *dev) +{ +} + +static inline void virtio_debug_device_exit(struct virtio_device *dev) +{ +} + +static inline void virtio_debug_device_filter_features(struct virtio_device *dev) +{ +} + +static inline void virtio_debug_init(void) +{ +} + +static inline void virtio_debug_exit(void) +{ +} +#endif + #endif /* _LINUX_VIRTIO_H */ From patchwork Tue Apr 23 10:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13639762 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDE1477F13 for ; Tue, 23 Apr 2024 10:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868882; cv=none; b=U/irb8MBMYCu5K29mlIvdWKmt08tAdGdulu9OXY0YbN12bxlixRi4So12mtQRt8e5h8n7BNGNb2merYHySm7TnxZ4bRzoDyPnVoIjycs5ai02qocMy48bZar0G7sk8gatqtck0R2jkpaw01+8oNOH96z0CxZjWAJob/E5Ok9AYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868882; c=relaxed/simple; bh=KaPtkaLJNQOUy4iNERAIFKq6ktm9TFozVxBCBQD6Z0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IYAQhusrLt1xwpqp3lEcVzCYyfcveKL4pJY7dEl59/6pONyScGpHIXrcJeLomqs5L14HyW3eUWn+hSxo/N2DAX2HkiCc3FjDIaRb6zaucDTh+4e4jnXy+ytZyxegbh2MSSGGkNZYXD+rBYB5yQVTaAO17eDMF80TwUEENJXLJwo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b=Kp1AzMvu; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="Kp1AzMvu" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-571e3f40e31so2811949a12.2 for ; Tue, 23 Apr 2024 03:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713868879; x=1714473679; darn=vger.kernel.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=SQl5qEwVKE01f/9GRHQkz4a3z973Yhrxj9l6Q9lKgg8=; b=Kp1AzMvuqhhY07uIXIOVE5GcEQHbQOz9BNLrkzuoHiiZsw9+a57xBjPdCtxuSn1PXZ pgpPi6/Vb0BpVZgKYSs2WP+E/O3C4NKvxSMGTRj7KyWSmCYkVCINGTXHjiHBsTnkaYd8 phJJKOQrfbGpKSNtn3e+/d+NOhlWLS7Xj/M5s2dOz00VVzULXEsbnpuXuRAmTwqhAyGW rttHH/JyFZp5iqZpBxn6CnvtAxE6LXcUwfE0bAAyU48T4uuqfLJSj4ElfnimjS3he3f+ eZqM6JQ+x+jG29f2ATU7XY43lK5m48jFjiqrgVsWtAQkhGpn+B38UlZ1IB8DHP27zvZ8 xLWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713868879; x=1714473679; 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=SQl5qEwVKE01f/9GRHQkz4a3z973Yhrxj9l6Q9lKgg8=; b=KsotOvTtuRUeXtwfK1B1mxoTAxurf4VKySmaL/pUy5lrwDCLhyuJKNyiiBFKeeS9Cw /8YcL+z8rFFHmHnfmB4aGQTLNR5YbZCLr5H9tbOXE4Gb/kZ564TIl3zUr7ZNDElSqi07 wQpzStQNwaJWWK8C60p4VdHt9rqdqiZm/2lnhaGwJD/OtPAv3MZLQOSozyA16gIlMDaZ JD6/sVfAZ23pJY7bHnzXTIH+0Svlg6FcESyLu0k5sajA/GCTvL0vL3lRmupTn6BIxoE4 8XYexqp4f6Zq5zXDmcAL+lZ+hNoIeC6V4WdGDgezDbWqVHUGewBhvi2UUZskEbJDc4tp W1FA== X-Gm-Message-State: AOJu0YzzKJjviKLv2tpiBYGpCakSwSVdY8MB19dMYl0j0CS84YCncZ5C TaZFoIpAbD9TApqJgN3ddmqbhu8shS7UM5HfyKtzpkeyXiYSEXzEMCr4zXpC8MF3ejc+ymElqNu c X-Google-Smtp-Source: AGHT+IG+hOv6ETUr4XWph6lySqZB5qDDYJRKGSSrZIIlVz00gQt3waHz4MI2qIsvPg0J/EZVG/jMqQ== X-Received: by 2002:a17:906:b105:b0:a55:75f6:ce0f with SMTP id u5-20020a170906b10500b00a5575f6ce0fmr7297845ejy.13.1713868879171; Tue, 23 Apr 2024 03:41:19 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id v16-20020a170906b01000b00a522c69f28asm6879534ejy.216.2024.04.23.03.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 03:41:18 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, parav@nvidia.com, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com, vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com, virtualization@lists.linux.dev Subject: [patch net-next v5 repost 2/5] selftests: forwarding: add ability to assemble NETIFS array by driver name Date: Tue, 23 Apr 2024 12:41:06 +0200 Message-ID: <20240423104109.3880713-3-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423104109.3880713-1-jiri@resnulli.us> References: <20240423104109.3880713-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Allow driver tests to work without specifying the netdevice names. Introduce a possibility to search for available netdevices according to set driver name. Allow test to specify the name by setting NETIF_FIND_DRIVER variable. Note that user overrides this either by passing netdevice names on the command line or by declaring NETIFS array in custom forwarding.config configuration file. Signed-off-by: Jiri Pirko Reviewed-by: Petr Machata --- v4->v5: - rebased on top of previous patch removal v3->v4: - rebased on top of changes in patch #2 - reworded NETIF_FIND_DRIVER comment to explicitly refer to "importer" - simplified driver_name_get() avoiding else branch - s/find_netif/netif_find_driver/ v1->v2: - removed unnecessary "-p" and "-e" options - removed unnecessary "! -z" from the check - moved NETIF_FIND_DRIVER declaration from the config options --- tools/testing/selftests/net/forwarding/lib.sh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 7913c6ee418d..9d6802c6c023 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -84,6 +84,43 @@ declare -A NETIFS=( # e.g. a low-power board. : "${KSFT_MACHINE_SLOW:=no}" +############################################################################## +# Find netifs by test-specified driver name + +driver_name_get() +{ + local dev=$1; shift + local driver_path="/sys/class/net/$dev/device/driver" + + if [[ -L $driver_path ]]; then + basename `realpath $driver_path` + fi +} + +netif_find_driver() +{ + local ifnames=`ip -j link show | jq -r ".[].ifname"` + local count=0 + + for ifname in $ifnames + do + local driver_name=`driver_name_get $ifname` + if [[ ! -z $driver_name && $driver_name == $NETIF_FIND_DRIVER ]]; then + count=$((count + 1)) + NETIFS[p$count]="$ifname" + fi + done +} + +# Whether to find netdevice according to the driver speficied by the importer +: "${NETIF_FIND_DRIVER:=}" + +if [[ $NETIF_FIND_DRIVER ]]; then + unset NETIFS + declare -A NETIFS + netif_find_driver +fi + net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") if [[ -f $net_forwarding_dir/forwarding.config ]]; then From patchwork Tue Apr 23 10:41:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13639763 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A45BE78C6E for ; Tue, 23 Apr 2024 10:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868885; cv=none; b=VVImlAY2v65GcGsewvTsryvr2axeNR4exjOoVWKqpevxOtuRjN5fFw++AC91lp5BZRIyrcmnoczBZqn18eVUGLq1WJtdmZKWLgsg9wO53ZBJDkb7MrpEFWjHJXI+ItQSGS9BQZajdIOEO4WF0MEdC64iDOoptk5GiUfd7sEfTvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868885; c=relaxed/simple; bh=skJZVZU2JBI8WGJ+4NhCiFRl3ZLQsAGK0b5U2Pn3qOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lJ0RSzukkadq8PmuKidZ2Ek5a4ochqUftvNo5Fimh9HpQX0qrXbaTw3hNZF2v2cwwEU/Mfx6+/+Z1dhSVRHn2wfTDrwc08FGAVk1iV2MjO06Sa7h/lxMcvVqs6/0XGMDUpmKWUpfMBqQfDVVAlwDBo0zaFzoGptH7YR+blheNdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b=nVjyfESX; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="nVjyfESX" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-56e56ee8d5cso6797099a12.2 for ; Tue, 23 Apr 2024 03:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713868882; x=1714473682; darn=vger.kernel.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=+PEW2sq1fZZcUdcYFCd5NXPg9CZPy+bkUUV4EmPfc9U=; b=nVjyfESXLzD5Hes5/NvdYJMR5ViTaKJFJ8iFACf+rL49uhf//viY7xDlGVgg3+4XNq Sdj8F3Iw6npMySiegLm5UweInDINOrdNH9CE8Ukro0I7DJfxE9eLo+sRy+adCCXAygvN 0F+5cbr2vydS52R2FMyvV5EHyD0vL1buZxXgPaLBc77axy0ehniv1fWWnVL5tOFsYUin 99fsYiWbQ/iFbZuMqP3ZbNFJDqzXCBfev5fzQ1ipaPU1zEUa4eatub8m6exI+WW11DTb S9DEAZVk7ECX4ugY/ZuXunIxuk9XxA35o/6v6SE4baWq3YwxrpZ8ObMWsZNQHVTGUcWv RTpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713868882; x=1714473682; 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=+PEW2sq1fZZcUdcYFCd5NXPg9CZPy+bkUUV4EmPfc9U=; b=wBKhZR3S/me5A4GQZmlnZ/6MXI6IMuZhkvvcju6YLP6MezqXOFQPH7IbheKzuCR3UN kD17ehZwH9RxXaFheUofNpKqWhIISIWqz3JazFjWN4MU7SuXh4Cm+6Xl9BIQw1H51sZv smzZ1A6CAvPctfu+lqPmRMVMD38drlpvMruNCBJlhBiqdWHIG+ijdZ6lpA43LwFXAhtU FFagRCJ2TMgZYrkXuO2UJRhWqSrBsoA9YiSUyN+IqVlm58rCbeBf62Zr3Dn5cPWYX3n/ zsYVG3tVCUxLO0HrEJRAtSntjuEIULy4xu0VlcbWLtu4df6+cWUmgbKgh1Dn1EQPXhIp 4FqA== X-Gm-Message-State: AOJu0YybBM7CLfV/ebqn3GbQEer7fSbkp3jsx4tSiQZW9HCNBjzxALCf VnHq9k4o0xUlVPvp4CYT7HB8XWDfj+r2+09P2p0DFH5SXrIajOxupER3FjAFbuJUy8uca9vdMz5 C X-Google-Smtp-Source: AGHT+IH9gXunuU/J5xzGqAVceintwfiAZYNFxqLDRge/NzifRKTF5QZg7qXyi6QexPnSbsuTD1icXA== X-Received: by 2002:a50:8717:0:b0:570:34c:91cb with SMTP id i23-20020a508717000000b00570034c91cbmr9656056edb.32.1713868881992; Tue, 23 Apr 2024 03:41:21 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id g1-20020a056402428100b00571bbaa1c45sm6428717edc.1.2024.04.23.03.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 03:41:20 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, parav@nvidia.com, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com, vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com, virtualization@lists.linux.dev Subject: [patch net-next v5 repost 3/5] selftests: forwarding: add check_driver() helper Date: Tue, 23 Apr 2024 12:41:07 +0200 Message-ID: <20240423104109.3880713-4-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423104109.3880713-1-jiri@resnulli.us> References: <20240423104109.3880713-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Add a helper to be used to check if the netdevice is backed by specified driver. Signed-off-by: Jiri Pirko Reviewed-by: Petr Machata --- tools/testing/selftests/net/forwarding/lib.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 9d6802c6c023..00e089dd951d 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -278,10 +278,17 @@ check_port_mab_support() fi } -if [[ "$(id -u)" -ne 0 ]]; then - echo "SKIP: need root privileges" - exit $ksft_skip -fi +check_driver() +{ + local dev=$1; shift + local expected=$1; shift + local driver_name=`driver_name_get $dev` + + if [[ $driver_name != $expected ]]; then + echo "SKIP: expected driver $expected for $dev, got $driver_name instead" + exit $ksft_skip + fi +} if [[ "$CHECK_TC" = "yes" ]]; then check_tc_version From patchwork Tue Apr 23 10:41:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13639764 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C32FA78C6E for ; Tue, 23 Apr 2024 10:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868888; cv=none; b=CM/EQZhch/7u2WzbUqI2/YPlLoZnYrKUE+8QAhaY9GTcbpZGSzwPMIWHmX0LOG/S+NAPKwy3h/7/26Op/aPLwkc2NAquZI68Z7EVpwjp/zv8cvjy6fjx7fiZXBWTZKtQaVcHD1w/LTkJzj8T6/1L1AVU+5ezWqdTvIzP5QUgY8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868888; c=relaxed/simple; bh=b3s3lonKXCUontl27cidtmw2bRxAlU6LH2RDIq6KhXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JSwF+I9cf1s8R+LFDZY2i/dD5xn/5bbr2fkk0qG4UkThmbuPqmo5F2yBQ7djGWyAgxXyKk0ctLaAhUErf8og7YhoukjHmPGLPeUM31JRMrxfqOO/fbleleMR4nLKGjRcuzIL688Lq1ktpcXrHmK7hiXE9/Jr6RuGPXij3i9kAA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b=e7YI6zNu; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="e7YI6zNu" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-572242ed990so334027a12.0 for ; Tue, 23 Apr 2024 03:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713868885; x=1714473685; darn=vger.kernel.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=l+SvETYZqEpQzbp95WnLsYBk6au1WM6Aqn9bo14n4zs=; b=e7YI6zNupUnNpY+C8iiB1f6b2tJ1KEtIt2JQ//4g8UZDjPk/ainyqQ3rhXbhCX5XBI e0PlVc5EA/APkToWUcD25LnxDIcMOgSP+RacBG32bgGl/HohpItFQ8Eux7+6lbPCuEN0 j66ZhL3YMPXcexpN+Cv7usX63kdeGtdiRry+c174ya4/v9qpDtnU7t9YYokb1GCn4Vlr +MLnvHgNAqbrOS6xDCFJ9eVLnmCHRKa9pa6M7tltYZmmzHLBJ0h1JQHLpxONp38OzoxA WW1Njt2C04xNfucCAG1zc/ZcJqZA8KNH/aKPpqfKcizxhc2WMIV92CwnZKdZlYJfVvAC Wc+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713868885; x=1714473685; 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=l+SvETYZqEpQzbp95WnLsYBk6au1WM6Aqn9bo14n4zs=; b=xDum4+Lkq+QDAxGiqHSw1b2N7yZ8AIR/K6S1LVfWuIr3ajWcSuHZad+pYIH6ILS+PE 3/32qubIJ5tHV7ORza9xsdkS5iet2ocNgFqBtFBnyMYL8CZB1rG6FnHjfNuj+sFCZitJ 4WYiBWrdImlm1c8X3XojyfDo1xU7BYyWyHeF5hSuL6wDOy853oCWtzFBJ7EhURmnYU+s V7BxQ2aMgqkfBYnwufKAlxAfcGQFnHMFsM6kbTPN1l9BJz5zoXak6TeqZUTdgpWYxfK+ 2kLVDI8IB+xK5aO1urd+vpz+4+m7wfgDVND0FpzggNt4MKGYJCchyrly8YkB7CDxu4Ta Cigw== X-Gm-Message-State: AOJu0YwJmbXb7xMf78Bst8jfR1FdxbfCDLlq7a6I4Ktnxa9jjjRca6Gr Qxc4lnTQ/Y7JOePPecphSYTStYWMZIRiz3kUXp8EBK0T5uWE8O62hoon/FKe9DymyK62uUt0fya c X-Google-Smtp-Source: AGHT+IF7EqsjRddLl+xv2aOwVOeKqbSfjmJfPOqlEpNdTPkVykzo0NuULllrdLvuLp28jrt9xZ4x3g== X-Received: by 2002:a50:d682:0:b0:56b:9029:dd48 with SMTP id r2-20020a50d682000000b0056b9029dd48mr9614396edi.5.1713868885302; Tue, 23 Apr 2024 03:41:25 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id p23-20020aa7cc97000000b0056fede24155sm6500516edt.89.2024.04.23.03.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 03:41:24 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, parav@nvidia.com, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com, vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com, virtualization@lists.linux.dev Subject: [patch net-next v5 repost 4/5] selftests: forwarding: add wait_for_dev() helper Date: Tue, 23 Apr 2024 12:41:08 +0200 Message-ID: <20240423104109.3880713-5-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423104109.3880713-1-jiri@resnulli.us> References: <20240423104109.3880713-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The existing setup_wait*() helper family check the status of the interface to be up. Introduce wait_for_dev() to wait for the netdevice to appear, for example after test script does manual device bind. Signed-off-by: Jiri Pirko Reviewed-by: Petr Machata --- v3->v4: - removed "up" from ip link command line v1->v2: - reworked wait_for_dev() helper to use slowwait() helper --- tools/testing/selftests/net/forwarding/lib.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 00e089dd951d..94751993321c 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -733,6 +733,19 @@ setup_wait() sleep $WAIT_TIME } +wait_for_dev() +{ + local dev=$1; shift + local timeout=${1:-$WAIT_TIMEOUT}; shift + + slowwait $timeout ip link show dev $dev &> /dev/null + if (( $? )); then + check_err 1 + log_test wait_for_dev "Interface $dev did not appear." + exit $EXIT_STATUS + fi +} + cmd_jq() { local cmd=$1 From patchwork Tue Apr 23 10:41:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13639765 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78FB77E567 for ; Tue, 23 Apr 2024 10:41:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868891; cv=none; b=JUgDB6oPceOBj6bxX/xdllnjCFcGFS2us6BgWbuojKDiFYoQC7PX4t7ZGXqJAQdoeGW31MJKH175VZkUTjSa5lthdNUtFOSJXrRSHg5sxo90E5ULALj54rHAx20viyYeUQ6SolJcDdpC5BNnY5uPzmLwWPOfhOV4fDoCHvkaDq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713868891; c=relaxed/simple; bh=PpoLD1H94rA4TRptICasS4LawZkbS6b4uI7xKmspqoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DLahAUdYZvH6sTI9m+FMG5X/ZvxiJp7CDKHElDj1kSqr/WD8u7129Uh1t1+kDHzRb58yRAkimCtdFigjopAEJ3ECoQO52NUQVw33fnc6XDLLFpfcnkNov3KMOVc6RoBetPNitnPw3/Swy5rlnTpN/T//BYrWKq0EnyNUn2jyBas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b=JO3fwCTz; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="JO3fwCTz" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-56e48d0a632so8143641a12.2 for ; Tue, 23 Apr 2024 03:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713868888; x=1714473688; darn=vger.kernel.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=p5/4hfw3aEXqovOlUV3Xw0f3iNJbck2TFHBWGrv3tv8=; b=JO3fwCTzY9GMAe73DxTZgQiHgsKg6CSIaNKeDcEwnIcwnVexiTPljErL72RaGR/F+Y GTu3WJuA95PxRpt61K3o7BE5nUCbNzJKLdWai2UNV31Wr/QEJPVXHfKXI3+VDhvjIXEg OBgPpGJX4j8Yd0pHRezZtIn4Zu0Sae8oUfWL80XnzVKyTpyOObPb00bex82CfNwC0bho Ksd3a0JRULs0CCQ6Q96EgyfTdQ+SSph8q//Jhkhw7AzdO8xqvlWk4eITkyy6g1H6umhh gEsjnUbqqsoTv4/bGrqKuHiLADRfq/O0SGEIZLkA4oRUvqyp5n3uqJxQAisB4j72R1Vo Vbxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713868888; x=1714473688; 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=p5/4hfw3aEXqovOlUV3Xw0f3iNJbck2TFHBWGrv3tv8=; b=Q2BQ97s5JSCqf/Hi2eGp0BXd/spOe2ldvIov+C+ulB5bWXKWVsBl3ZknY0FOg1icWu smLQcF9753xI6m9y5WB6mVb98VLYp3iOvQxB5qHuxbNBmPWT6WTvZvNHZOM1JRePduzN v8RMnNGdgdUPO8PaO0WDfaTjdW2Kkx4kqDcUHpTiYv3g8P8xvp6/k9u5kALPOjCYtreI 8n5K5o5E4ufXr+30Izj1eYDE6kUp1PVG6MnQsEm0GwUGd9CFDr9qrjeinz1oTGdNLQgo Pn7Lz8Kftuzk3ZFu7p9iXncId5kwg7m7fms8qHUXaBV0NWmJny64o2leJPXkwk/8zVhM h6jw== X-Gm-Message-State: AOJu0Yx78xeooZBdn/6n7dCz2WSsSEELrzGiZ/s2XeJ9g65EFVxdmEHJ SP36BaeJpmsa1Mcn08uBkULdeRLvsfSOQYtWU4Gd56Jn+EGlQgRAMoWxbcIEJW0Y1pQ208N5aA7 e X-Google-Smtp-Source: AGHT+IHM2a/cViMZbiHyLuSKrK/mEmAZ8iLW2Q2j/pksoi1UHxHBmXTqOXB4MFswM49VR7x2JXWqyg== X-Received: by 2002:a17:906:5592:b0:a58:7c50:84e4 with SMTP id y18-20020a170906559200b00a587c5084e4mr1734441ejp.2.1713868887783; Tue, 23 Apr 2024 03:41:27 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id qy34-20020a17090768a200b00a55a59c629fsm3421147ejc.121.2024.04.23.03.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 03:41:26 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, parav@nvidia.com, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com, vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com, virtualization@lists.linux.dev Subject: [patch net-next v5 repost 5/5] selftests: virtio_net: add initial tests Date: Tue, 23 Apr 2024 12:41:09 +0200 Message-ID: <20240423104109.3880713-6-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423104109.3880713-1-jiri@resnulli.us> References: <20240423104109.3880713-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Introduce initial tests for virtio_net driver. Focus on feature testing leveraging previously introduced debugfs feature filtering infrastructure. Add very basic ping and F_MAC feature tests. To run this, do: $ make -C tools/testing/selftests/ TARGETS=drivers/net/virtio_net/ run_tests Run it on a system with 2 virtio_net devices connected back-to-back on the hypervisor. Signed-off-by: Jiri Pirko Reviewed-by: Petr Machata --- v3->v4: - s/cleanup/setup_cleanup/ - moved pre_cleanup call to cleanup() to be called only once on exit v1->v2: - added TEST_FILES and TEST_INCLUDES in the Makefile - fixed directory name in selftests/Makefile - added MAINTAINERS entry - added config file with kernel config options --- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + .../selftests/drivers/net/virtio_net/Makefile | 15 ++ .../drivers/net/virtio_net/basic_features.sh | 131 ++++++++++++++++++ .../selftests/drivers/net/virtio_net/config | 2 + .../net/virtio_net/virtio_net_common.sh | 99 +++++++++++++ 6 files changed, 249 insertions(+) create mode 100644 tools/testing/selftests/drivers/net/virtio_net/Makefile create mode 100755 tools/testing/selftests/drivers/net/virtio_net/basic_features.sh create mode 100644 tools/testing/selftests/drivers/net/virtio_net/config create mode 100644 tools/testing/selftests/drivers/net/virtio_net/virtio_net_common.sh diff --git a/MAINTAINERS b/MAINTAINERS index c0bfad334623..f7ae6de3e334 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23448,6 +23448,7 @@ F: include/linux/virtio*.h F: include/linux/vringh.h F: include/uapi/linux/virtio_*.h F: tools/virtio/ +F: tools/testing/selftests/drivers/net/virtio_net/ VIRTIO CRYPTO DRIVER M: Gonglei diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index c785b6256a45..2c940e9c4ced 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -20,6 +20,7 @@ TARGETS += drivers/s390x/uvdevice TARGETS += drivers/net TARGETS += drivers/net/bonding TARGETS += drivers/net/team +TARGETS += drivers/net/virtio_net TARGETS += dt TARGETS += efivarfs TARGETS += exec diff --git a/tools/testing/selftests/drivers/net/virtio_net/Makefile b/tools/testing/selftests/drivers/net/virtio_net/Makefile new file mode 100644 index 000000000000..7ec7cd3ab2cc --- /dev/null +++ b/tools/testing/selftests/drivers/net/virtio_net/Makefile @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0+ OR MIT + +TEST_PROGS = basic_features.sh \ + # + +TEST_FILES = \ + virtio_net_common.sh \ + # + +TEST_INCLUDES = \ + ../../../net/forwarding/lib.sh \ + ../../../net/lib.sh \ + # + +include ../../../lib.mk diff --git a/tools/testing/selftests/drivers/net/virtio_net/basic_features.sh b/tools/testing/selftests/drivers/net/virtio_net/basic_features.sh new file mode 100755 index 000000000000..cf8cf816ed48 --- /dev/null +++ b/tools/testing/selftests/drivers/net/virtio_net/basic_features.sh @@ -0,0 +1,131 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# See virtio_net_common.sh comments for more details about assumed setup + +ALL_TESTS=" + initial_ping_test + f_mac_test +" + +source virtio_net_common.sh + +lib_dir=$(dirname "$0") +source "$lib_dir"/../../../net/forwarding/lib.sh + +h1=${NETIFS[p1]} +h2=${NETIFS[p2]} + +h1_create() +{ + simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64 +} + +h1_destroy() +{ + simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64 +} + +h2_create() +{ + simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64 +} + +h2_destroy() +{ + simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64 +} + +initial_ping_test() +{ + setup_cleanup + setup_prepare + ping_test $h1 $H2_IPV4 " simple" +} + +f_mac_test() +{ + RET=0 + local test_name="mac feature filtered" + + virtio_feature_present $h1 $VIRTIO_NET_F_MAC + if [ $? -ne 0 ]; then + log_test_skip "$test_name" "Device $h1 is missing feature $VIRTIO_NET_F_MAC." + return 0 + fi + virtio_feature_present $h1 $VIRTIO_NET_F_MAC + if [ $? -ne 0 ]; then + log_test_skip "$test_name" "Device $h2 is missing feature $VIRTIO_NET_F_MAC." + return 0 + fi + + setup_cleanup + setup_prepare + + grep -q 0 /sys/class/net/$h1/addr_assign_type + check_err $? "Permanent address assign type for $h1 is not set" + grep -q 0 /sys/class/net/$h2/addr_assign_type + check_err $? "Permanent address assign type for $h2 is not set" + + setup_cleanup + virtio_filter_feature_add $h1 $VIRTIO_NET_F_MAC + virtio_filter_feature_add $h2 $VIRTIO_NET_F_MAC + setup_prepare + + grep -q 0 /sys/class/net/$h1/addr_assign_type + check_fail $? "Permanent address assign type for $h1 is set when F_MAC feature is filtered" + grep -q 0 /sys/class/net/$h2/addr_assign_type + check_fail $? "Permanent address assign type for $h2 is set when F_MAC feature is filtered" + + ping_do $h1 $H2_IPV4 + check_err $? "Ping failed" + + log_test "$test_name" +} + +setup_prepare() +{ + virtio_device_rebind $h1 + virtio_device_rebind $h2 + wait_for_dev $h1 + wait_for_dev $h2 + + vrf_prepare + + h1_create + h2_create +} + +setup_cleanup() +{ + h2_destroy + h1_destroy + + vrf_cleanup + + virtio_filter_features_clear $h1 + virtio_filter_features_clear $h2 + virtio_device_rebind $h1 + virtio_device_rebind $h2 + wait_for_dev $h1 + wait_for_dev $h2 +} + +cleanup() +{ + pre_cleanup + setup_cleanup +} + +check_driver $h1 "virtio_net" +check_driver $h2 "virtio_net" +check_virtio_debugfs $h1 +check_virtio_debugfs $h2 + +trap cleanup EXIT + +setup_prepare + +tests_run + +exit "$EXIT_STATUS" diff --git a/tools/testing/selftests/drivers/net/virtio_net/config b/tools/testing/selftests/drivers/net/virtio_net/config new file mode 100644 index 000000000000..f35de0542b60 --- /dev/null +++ b/tools/testing/selftests/drivers/net/virtio_net/config @@ -0,0 +1,2 @@ +CONFIG_VIRTIO_NET=y +CONFIG_VIRTIO_DEBUG=y diff --git a/tools/testing/selftests/drivers/net/virtio_net/virtio_net_common.sh b/tools/testing/selftests/drivers/net/virtio_net/virtio_net_common.sh new file mode 100644 index 000000000000..57bd8055e2e5 --- /dev/null +++ b/tools/testing/selftests/drivers/net/virtio_net/virtio_net_common.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# This assumes running on a host with two virtio interfaces connected +# back to back. Example script to do such wire-up of tap devices would +# look like this: +# +# ======================================================================================================= +# #!/bin/bash +# +# DEV1="$1" +# DEV2="$2" +# +# sudo tc qdisc add dev $DEV1 clsact +# sudo tc qdisc add dev $DEV2 clsact +# sudo tc filter add dev $DEV1 ingress protocol all pref 1 matchall action mirred egress redirect dev $DEV2 +# sudo tc filter add dev $DEV2 ingress protocol all pref 1 matchall action mirred egress redirect dev $DEV1 +# sudo ip link set $DEV1 up +# sudo ip link set $DEV2 up +# ======================================================================================================= + +REQUIRE_MZ="no" +NETIF_CREATE="no" +NETIF_FIND_DRIVER="virtio_net" +NUM_NETIFS=2 + +H1_IPV4="192.0.2.1" +H2_IPV4="192.0.2.2" +H1_IPV6="2001:db8:1::1" +H2_IPV6="2001:db8:1::2" + +VIRTIO_NET_F_MAC=5 + +virtio_device_get() +{ + local dev=$1; shift + local device_path="/sys/class/net/$dev/device/" + + basename `realpath $device_path` +} + +virtio_device_rebind() +{ + local dev=$1; shift + local device=`virtio_device_get $dev` + + echo "$device" > /sys/bus/virtio/drivers/virtio_net/unbind + echo "$device" > /sys/bus/virtio/drivers/virtio_net/bind +} + +virtio_debugfs_get() +{ + local dev=$1; shift + local device=`virtio_device_get $dev` + + echo /sys/kernel/debug/virtio/$device/ +} + +check_virtio_debugfs() +{ + local dev=$1; shift + local debugfs=`virtio_debugfs_get $dev` + + if [ ! -f "$debugfs/device_features" ] || + [ ! -f "$debugfs/filter_feature_add" ] || + [ ! -f "$debugfs/filter_feature_del" ] || + [ ! -f "$debugfs/filter_features" ] || + [ ! -f "$debugfs/filter_features_clear" ]; then + echo "SKIP: not possible to access debugfs for $dev" + exit $ksft_skip + fi +} + +virtio_feature_present() +{ + local dev=$1; shift + local feature=$1; shift + local debugfs=`virtio_debugfs_get $dev` + + cat $debugfs/device_features |grep "^$feature$" &> /dev/null + return $? +} + +virtio_filter_features_clear() +{ + local dev=$1; shift + local debugfs=`virtio_debugfs_get $dev` + + echo "1" > $debugfs/filter_features_clear +} + +virtio_filter_feature_add() +{ + local dev=$1; shift + local feature=$1; shift + local debugfs=`virtio_debugfs_get $dev` + + echo "$feature" > $debugfs/filter_feature_add +}