From patchwork Wed Apr 24 10:40:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13641710 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.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 0517815959B for ; Wed, 24 Apr 2024 10:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955264; cv=none; b=lTGBf5Y6ohthzK7XGKu6q1AXMiaCM5hvn2TrS6ftjuIoPiIGD/7DVTh6U8JaE3jOkfMc18nBRcZRq+Q60lSGfe4Bhjh7FCk0QxnmCMm9jGit7tluNxUb32WLsFDujY9LpUcFQZqa2qcyV9IKjTLXHAxhMImX31Cn/EjNkwxROJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955264; c=relaxed/simple; bh=qfjhZRPSIDFEHkF0+Ey2KyFTSBc+VIloSshdY4zph9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AY1ldmjQfZSuJDMG7QTKZkzNidQjmeqs5+0ns1o162pPmcSjTDm4aeTNDTKMJrHu39RbaCkgwUi+1JhDegaxlb/xsPMPlcPx0oBB1b/Mgomx74UexxMCLWptHyEjLTyl688zD10AjhjrKbtbrTYeyjPGHxh3UNt9aywgs1GYYzk= 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=2oqBOZrN; arc=none smtp.client-ip=209.85.167.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="2oqBOZrN" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-516d3a470d5so8397895e87.3 for ; Wed, 24 Apr 2024 03:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713955261; x=1714560061; 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=mMwAZbgWT8eHv9XMembRg/Yv4gwBDl3pohLK/0POGkw=; b=2oqBOZrN2ObsOM3fAkPLXGas8i5douzZoGVqqYPIakRwR/qjilrWcVWrV9xGJ2Y0YP ShvoMnDh4u9Y383Tz3xqYf+dzoUt2Q5MFdemTaCobQqNZaFuG8DGmkP0Db4bHpODdBhU RTBIOjwmBU7wxKtuh/1oIlmNL+GRBBXuGkffrtOIFz8Nk+miu4fVrToIMH0eXVx5r7Z9 0JKyQeR1OxhgpQvOc43kUKe55+VLEa8cfB06d6mx6jKfbybargnTYT5dtA+nmwO/81/v U0uixlFCeUOeMVoBLfvcqx7U8L+O2qthmOcwJfvGeAnH406lsGy2MGZ+1fqWBc4Z2Cmc 4H0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713955261; x=1714560061; 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=mMwAZbgWT8eHv9XMembRg/Yv4gwBDl3pohLK/0POGkw=; b=QkV9LdJWAUAnPjnoIzjiB3I1s7WFtQnu25AmbsmJzSc6xPLPqOvhD1csuYfvjVzhSl YSs4SNEmiXD5NAB0uEgytRzdCVJTKk8eUT0bE+kmQlfZRz0+3ueenfm3nPtOfPt2nGGg Fr9UJ5TrwQfyMyxWZG4zgL6ToPo6tYw8kE2uvQb2qPSar8VaeDPTV42/LFAPTtBz/wtC v6THPyOsoTfyT/BAuKwN5asLQ8y8Wmpqvpw5VkJjLl2s96PpzCjP6t1hGlbR9EfYnRCE ixdwuMnBHTnB+PaQ91/AhOmOVl6lZMqsM/IGT6nedKITGy49wN5UnJMY2Z19C9tv9ubY 6Nig== X-Gm-Message-State: AOJu0YxNfilg4y7cMDXES8MORwfxwslYrj9q3fVtut8DSl4rBoovim4/ HLwG14sSnTGD1K+OhnbHLEx7WO6qG/YM03s5hpKSHPI5j5qwm7t1uIFEYzRt2tirCBnT/c4TY47 P6CA= X-Google-Smtp-Source: AGHT+IEwQNqXm9wYEQDHIY/tZS0Iz5lA+l9Qq1Sg181V9bRQefVbJxqwCJMBPaF0XzMLWvgnIavLOg== X-Received: by 2002:ac2:46f1:0:b0:51a:d7a5:ca9a with SMTP id q17-20020ac246f1000000b0051ad7a5ca9amr1451186lfo.39.1713955260885; Wed, 24 Apr 2024 03:41:00 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id x21-20020a1709060a5500b00a521891f8cbsm8231154ejf.224.2024.04.24.03.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 03:41:00 -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 v6 1/5] virtio: add debugfs infrastructure to allow to debug virtio features Date: Wed, 24 Apr 2024 12:40:45 +0200 Message-ID: <20240424104049.3935572-2-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424104049.3935572-1-jiri@resnulli.us> References: <20240424104049.3935572-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 Acked-by: Michael S. Tsirkin --- 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 Wed Apr 24 10:40:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13641711 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 560A7159579 for ; Wed, 24 Apr 2024 10:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955269; cv=none; b=og27BCVPoCTr/WjpX+Ha4B/JOWXkyxJ0FmRyvNUHQ2jUV2owKxJZOvVpQCFnxYWFoMh+K9EU1eYbl2Bn4s+bSNR+076Jvy5jKEOPit3b9er9F7YdStM0h4R4qdhFDnZaoaUcRCv6WsmAQdukOdlk+2b60cunHg8M8WQ/Lbz8Kb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955269; c=relaxed/simple; bh=KaPtkaLJNQOUy4iNERAIFKq6ktm9TFozVxBCBQD6Z0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PENzA5loVUTwYDvYsMJqO35wHahtE+DKQH6aPU2SYlWD01y+3B8HK4+e4oOz3e5xOZDvfUUTFWRlLhkb6UcGSixxbTYuYs6K3fcE1QRDI0gay4SgqVud1rYt2oH021zHZMKLKgjrFBAO+ZqxxlJ4mOgTkML1PqnogjhG9z0BGxY= 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=1AHEfYIw; arc=none smtp.client-ip=209.85.208.43 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="1AHEfYIw" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-57230faeb81so300443a12.0 for ; Wed, 24 Apr 2024 03:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713955267; x=1714560067; 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=1AHEfYIwVQbiAbISrBKIbyLZNQ664MmjYKQBEoX1LUr9n8a1c+SgovDAX/46QbA2+7 6w2OrYwXNPeDAPBAfjXhkvRW1ShBpWC900s3qTxwGdGQTM/uVQzXIw638L1Z0Mqa/2qR 1hNyMwNlWWJerniURhooOeJ/LngPfTNVWfli2vEI9U7P/Ur3xo1Hui6yZwlRgczKspUL OaMgG19+KlYyex7lzHihpkmEhDWOuVzbtHifspO1RMUDq8NI7pjNkjjsgSJSN2RqWK5O /KyBdwxGoPEngXopgrvgP7JZoRLsOsCi3UX/u+Hime13pLGTwTqaIY7uyD37wkD1/Syu J1lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713955267; x=1714560067; 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=G9/NSlcYhr+amglpR/vvGVSvBkh7nbR+fObUWQuJfpM2JaKUMg8agk6Kusd3T/3F3x zBeyA62EKso1gI3TG4SqojHHomSAGzKBqg/Vv4rXp6MF6GnicTZLqWmRBntfenqwhW52 fowqeNzlwGeh8hfh0mn5Kjs8wTZ5lg/nKzkFODeES0L05cldt3S21kpY2CBhmZSZ2X+y L80y8tIRjfKAC0SKHE+Fk//cV2atJsTB0aizsSyAQEM5Pt6hn7qPL2pJ8085JyLcwrMt 0ehgGQAPGgVLM53sMkfqL1t9+oJJl+ZPtIqC/dswmwNXQ9N2/v9T5hk6QbQtqXiZiOl7 DZPQ== X-Gm-Message-State: AOJu0YwvJ2pzpbpfpBiCZ4uM4xbQjUV7zM+iVclO5jwXzxLww0BBPWwX 7eT21KmU52AYB34+/G5U9EpemheUFsCIaPVILUA49c9Y912fyQoy07AW4s1kDcE05rGXnYlKD4a WRf0= X-Google-Smtp-Source: AGHT+IEcmmnN/LjVFLpWsyWulmkkwyLqo6DLvHVQYSvdmQmglzk6LQD8NgEQmHuc0kODNIK/8lCHYw== X-Received: by 2002:a50:8716:0:b0:568:c6a2:f411 with SMTP id i22-20020a508716000000b00568c6a2f411mr1528361edb.32.1713955266379; Wed, 24 Apr 2024 03:41:06 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id u20-20020aa7d994000000b005700fa834acsm7686627eds.45.2024.04.24.03.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 03:41:05 -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 v6 2/5] selftests: forwarding: add ability to assemble NETIFS array by driver name Date: Wed, 24 Apr 2024 12:40:46 +0200 Message-ID: <20240424104049.3935572-3-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424104049.3935572-1-jiri@resnulli.us> References: <20240424104049.3935572-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 Reviewed-by: Benjamin Poirier --- 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 Wed Apr 24 10:40:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13641712 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 5CC2F15957D for ; Wed, 24 Apr 2024 10:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955275; cv=none; b=CXad2t2EDU+kLfSd/OcGwTDjsJ/czUdVwh6apYf/DnLb0BO2cvcU4Cq64umewd3wV/fjyL2NjnLLAPuZY3/97toT2RUleqzx3sinBlgJ30a21QNva0mPpfX28K/l4N0GBLacqE2SDoL/8Fm6gjzOiQeVaqRGyCeGuFxaFi8G5tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955275; c=relaxed/simple; bh=WvA9mi8zp8l2a6WFa91lX57zesLhrvAgkOfsOsQeM1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZrDQ2befErLlU/2l4rA9+5Pj1LlUGRHpcDvk1poRDlQG0aP12V4cCm24bUzEuTqGpY7jYeeb0KNtqscRmQ+BtuXfmwjQxAhlZeQ5pS4JiW8aMgGX229G6iuuWLqpn1UZW5DHw6xcwnUoWUE21xTq+7d80Un7XPk5rIeCDxbnqxI= 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=ija7vE0T; arc=none smtp.client-ip=209.85.208.47 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="ija7vE0T" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-572347c2c16so134847a12.2 for ; Wed, 24 Apr 2024 03:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713955273; x=1714560073; 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=yUHI9zilGVXMHsT3cMVzO8EqmG06SAbRC2e4DxW8mYI=; b=ija7vE0TOg6K9Ox/RhAyc8EcJsY08/+j943LP0yRiAeegcQOAqyAfWaB8AOn+gvAlN OWAbWAYYUYSaujWw90A6ZK69dea7EOEj07XKh6ta3CBfdXDGcxpePJNGeRUgG1q6OtTN 5vlDzqjxcNTTAhm0zqVVCiAkaRpSz0Szava7qCnQPJDS4DisW4E8mGDeaNJEdxY462a6 yrnnVFSQRwyvJ0A0U+iI7ImCQldkDhk/Rnl5TjEy8XJpKD2nKSLk58E+d2rF7F8NzaJi ID05hJHrBH7w3d/YJStFt4rP6HTD42YtGGYeKN1Jakz6ov3o+QvMCZvn3mUhbE+i+X/a XELg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713955273; x=1714560073; 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=yUHI9zilGVXMHsT3cMVzO8EqmG06SAbRC2e4DxW8mYI=; b=D7c49qsfBXXOgEK3UqxCN3Nl1ismszgjAis5NBuaniHeH5hHwqAXPW7DLKDhD10VzU z6X5eXx3L3sR4mlMFOCUWLpa/NidHvg9+BAWLjHALBvbTydmQqdMdrXECcm993jIx0go 3dEXEJAk2z5bjNuemHFMui79sdr4wO+/XRa3/sjy3GhlzfSQlSMEl69u8H5RfJUFrsSa 9WGXhAyFBAlxHKKfHTL6wh/IqwHP6YEy5PDJkJ+JafxVGBeEo7Ak84hZ35jJXv8oo1oN ezs4X6M8YqDdvEqczTKb4pXl8xugGxwdjkZqWuCPmUdUjAxKSafpk4R2inNACroISMO+ 5AtQ== X-Gm-Message-State: AOJu0Yxtw//5ur2I+/4jnz3ehqBfwhIx1yfUccQTTlNQnjhikMkMuoWN A0457f4SWzoRtJrHiuQ8zfy4vVSafpDi4h2/lkRwLDUFIUn8gV1Ib7eSmEcOyaf39d57/Mq75wv UB+Q= X-Google-Smtp-Source: AGHT+IGE6LlafpU2Qxf9I6d9LJDd/D3TjhCV5n4qDef0tJciUVv5gQJnoUrU9VRAEN9NDhSSUuMJoQ== X-Received: by 2002:a17:907:6d16:b0:a55:63de:9aa9 with SMTP id sa22-20020a1709076d1600b00a5563de9aa9mr1644449ejc.49.1713955272680; Wed, 24 Apr 2024 03:41:12 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id h2-20020a170906398200b00a4df061728fsm8181230eje.83.2024.04.24.03.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 03:41:11 -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 v6 3/5] selftests: forwarding: add check_driver() helper Date: Wed, 24 Apr 2024 12:40:47 +0200 Message-ID: <20240424104049.3935572-4-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424104049.3935572-1-jiri@resnulli.us> References: <20240424104049.3935572-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: Benjamin Poirier --- v5->v6: - removed the root check removal, that was a rebase mistake --- tools/testing/selftests/net/forwarding/lib.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 9d6802c6c023..2d57912d3973 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -283,6 +283,18 @@ if [[ "$(id -u)" -ne 0 ]]; then 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 fi From patchwork Wed Apr 24 10:40:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13641713 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 1076A158D79 for ; Wed, 24 Apr 2024 10:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955280; cv=none; b=AF0oVvKExCujosIH70rOUl4d+fj2cKloCDI5/fJCcZt/bbxgXl+WoJzCCA4ndmTroNxQhBxhY3wJsDpg6LsNSfLNBYR1TfZmkDXKdWK8HuYQ0CvzjoXLfCJlroSsl4HTUO/ZkuWICnvBsH+0nrTEjwUvVRkd8S5eS2n/44AWSUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955280; c=relaxed/simple; bh=B/zxzQcql6baNzn7gSc3PVV0UgMdGK4IKuqEzi13oS0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iEWrhLkcz5hdf3c0/yf/Ixv0TWajwr3X5rpJkQolplETFoFWXF3FwkY0e7JTAwdOVvUB1S1vrupVvMWUOkWOYqeKfFsGGSNwkPvisLrq49sLhsT/x8vZikxJlhoumiP2z0UK3AjoolEKkHfP0hw5cP34O93HjfHdBdguRzWSU4A= 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=y/ZgGSy9; arc=none smtp.client-ip=209.85.208.43 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="y/ZgGSy9" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-56e78970853so1407642a12.0 for ; Wed, 24 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=1713955277; x=1714560077; 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=N/Z3z4Yi1jKKF2F7DPvPW7KYbmtrDxuE/DmY57trBRo=; b=y/ZgGSy98JGesRp2MfcRQ3Rrl4BPOlDsQCG5IyX9Sq6/wlZlMpIZkeItCGhHKgdZe+ nEdefpG9JZmRyKUsL/M/NOAPHzg6S1ydXEqCMmTryQENvWyzd9fs4rRPDThWhheCaqYd I9U1HSUuPSAGey1NOpR24wR8rujL7PLRUKwsE96pcQx75UyiZQ2FvdTKcH/4hKvVl1hu OXoZElCw2f5D1BQPx296uZnLVArSxV+5h9ZPnuwqA7w9h0/e6mrYF3SNPRg7zmPRDxj9 XfkGAdX6Rh0L5ODzsiDVe6UEquNeMYbsJ41GhOujqnRK6Legr/f9ILBHM9cmYZ9uZ0AG A2mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713955277; x=1714560077; 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=N/Z3z4Yi1jKKF2F7DPvPW7KYbmtrDxuE/DmY57trBRo=; b=S76v8vcmM7BkziChdGJYPqFv9w8w8R0l0youyXYMw2wZWWqtMPNqShYPBKftMWMPzR RmDEF22Ei6ofIk3qxTe1fFEE+YooB589WwS2p9OU3SK7xScNrJbjw4XTwjV6qNKUGb4m jFTbhjbfvXzrbj76LbvoeP0WowvDABqVrFfG2zUkxqjmya/ADsv/wwMnsGMT/uVhqQMT Q4z3loNu86RxRnG4y6XyE9M2uOm53k3ofYpk4aph6bLg9W1JqE0ZjsL8Q1WReUH/aUIx Maakvwwz4NIIZSS3HLUnfrZYairgSBPrVlnn8kjJ31PHZmsqnwZZbYl1axnIr6jmy+M9 C9oA== X-Gm-Message-State: AOJu0YzeJjw0xzy74UOjSdRmGFUGMuWXoeTGFjEXm6Qk0cOoFuSu1Vfd Wh4yvzvGZPlB4xFqRU4yc2keKEoJ7hDXLc9nGMAEBzXxMd9t1Bee6o6MAKFh3JdKJlFbvNTPlsg uqyQ= X-Google-Smtp-Source: AGHT+IHZZv1xVt6E3oyEe3yq9SW4nf/htg+PGNeigdjf8TVoO1Gvpm6evcpk2261/trhL4oabGxdmg== X-Received: by 2002:a05:6402:40cf:b0:572:218e:1676 with SMTP id z15-20020a05640240cf00b00572218e1676mr5950886edb.4.1713955277277; Wed, 24 Apr 2024 03:41:17 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id p36-20020a056402502400b0056e064a6d2dsm7872600eda.2.2024.04.24.03.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 03:41:16 -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 v6 4/5] selftests: forwarding: add wait_for_dev() helper Date: Wed, 24 Apr 2024 12:40:48 +0200 Message-ID: <20240424104049.3935572-5-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424104049.3935572-1-jiri@resnulli.us> References: <20240424104049.3935572-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 Reviewed-by: Benjamin Poirier --- 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 2d57912d3973..3353a1745946 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -738,6 +738,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 Wed Apr 24 10:40:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13641714 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 15D01159570 for ; Wed, 24 Apr 2024 10:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955286; cv=none; b=WHMaCE/OGbZA2m0KqG2ZUJvOBMdh3L1SRiGl7HxueyaAYnWcGAuODcpmq0cLa/CxkZnkuLi7V93/mJT8E4iNGKv7PDqh/0LgVzEqLvHtIwlaxiPwi8Uaxdab9YU69pKUkB43tTHXnVwb0AKPkPasroR8uRZTrivTHxRk0/t4DWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713955286; c=relaxed/simple; bh=PpoLD1H94rA4TRptICasS4LawZkbS6b4uI7xKmspqoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wr3OeiaYjyq+HgK+FkwrTaPVBtdaGGJd3NNF4aIX4s65e+5WTtRwck8Qjhtgub80rwTaUp5OmJB+GayIx9IG12fLe5RfyTEqm9QVmqQfWOwgY40hhZwdUm1lFx4E45yxktxFnnMsq/V4u4VTaybFdFR2/eWrrWVNNjv2AXZ76xg= 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=a1CtwMn5; arc=none smtp.client-ip=209.85.167.49 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="a1CtwMn5" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5194cebd6caso8033904e87.0 for ; Wed, 24 Apr 2024 03:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713955283; x=1714560083; 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=a1CtwMn56WZILHU3auIWDZ9nP8IhYLXTVFP8X3gVFf75Kpnt7zj50lynOsfAq62s/6 iNHAUV42qvtbXjThagftxbiSrhIl7hg52O3gsWDAX5lNYa2KR2K0ZKPvosdtngVmrbGq 89pCKYIMmw6LJIsqlA48Vo5xb/dKt+zI2GnSigM+g1gBsmwcF0zYRV6QzcyXmtG0L4ZL EPvm/W/i0AU4SG3FD/cXgUNnSzpKHnI+snF3N7UPsOa9GIQzgiAypCEmigWkBgDu6+bi 1/yI21LafNjqz0rBW13XU3Ny7eYrx8ET8aSIDhhlVT55Px25bwpJJBL66wOlq3dyPEzc FEwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713955283; x=1714560083; 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=AEe139g+J3dwHQER3dde8trDFiFB7M3HJNzFF3m67//0UpJaH66Z1M5970xtD7wH1n Ox1Fv7H5YcwbOy5F7qyMKsOWNRw47NAMKmLwzr9nrhJaH/EpSVS0ri7WB7B7BQvNSsjT NEapprqT2tH99o/FHbSqg1HhgmlTbmbCaDg8zVJXnnF5WBpPg/vMKquB4na2PxI/NE9B XTNrKoGeObIfuFHaff1xgFAw+L2yN7HHQG5EBbbyOT5jVUyQRTtSDcCNachePZB2W3+X E3hKEgD15WjjIcSbr0IJCqiHiTXEq7W4PTxcr58gRz3kt1d7K8W0AH2IHKM2PbVT/zhY xxxA== X-Gm-Message-State: AOJu0YwzgM4Qclyt2uTBvNJJV6YyTfx3HGXLjfWi1r4D1aB7GHhCx4D+ 9X+PbMufn3pjdH7PRs+jjJx+ivXJ3qDvW0ySUmd9uafJTNLPl4AEyn+QkUOZBs/jES3AVAGqvV3 Ie18= X-Google-Smtp-Source: AGHT+IGaogySD1f4nC8D1vIgtV+AdS2WLaxPFkP5EDirzh6ZrDMCBJ/g/KwUfg/+nNW4ehaHzzpuZg== X-Received: by 2002:a05:6512:33d2:b0:51b:fdaf:9f8c with SMTP id d18-20020a05651233d200b0051bfdaf9f8cmr647580lfg.69.1713955282945; Wed, 24 Apr 2024 03:41:22 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id i12-20020a170906698c00b00a4e58c74c9fsm8207922ejr.6.2024.04.24.03.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 03:41:22 -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 v6 5/5] selftests: virtio_net: add initial tests Date: Wed, 24 Apr 2024 12:40:49 +0200 Message-ID: <20240424104049.3935572-6-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424104049.3935572-1-jiri@resnulli.us> References: <20240424104049.3935572-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 Tested-by: Benjamin Poirier --- 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 +}