From patchwork Thu Apr 18 16:08:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13635070 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 0AFC716F8F4 for ; Thu, 18 Apr 2024 16:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456522; cv=none; b=nsw94xsdseex1DrLoECj9ImSxNKWxwQbAk1UXbjEWP8SMpxifMhrTCRVtj/PLGB53YTYzfCJTDBCEBnNHoPtqZgQTBZ8rm3mfUQI3FiNozKdNc3Cf2Isv5J1IgkpjacHtwU/azJ7XgW+O0AYQqidlOD3DaDJa0u1BwwHHk/LExc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456522; c=relaxed/simple; bh=b8SbnTJNAxEwHqdPFfy47aseeYIGa8kn5dqA9KiMX0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K/SmYyKk8VrKPrPmB2SamRE3TLz9+D4bD7fcJXW6v+mj61Hruu4smq9mqZWnzgP1xVtE+7EDHrVU9+0iyzKYctrR3Z0Sc3wssW/6VSGFzSo1q8mEY9kFxJUid8ynkyGblMcRhQZYbMqGnEhByGvriUG1B/PufwXCO3cutHhn5cA= 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=1pXVPi33; arc=none smtp.client-ip=209.85.218.46 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="1pXVPi33" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a5252e5aa01so132383266b.1 for ; Thu, 18 Apr 2024 09:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713456519; x=1714061319; 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=DBfQWUMtNb18nO6cukLxA1YJchWET3qC/zOTsZ5Ac7o=; b=1pXVPi33dMBp3deVAK2b3Q6OwqXOz9/2TyzS8N2rjF+PW7un2FcWU3f4W0BiriqyTr EXCfnW2pdgdnJnKdstx2e9BDaBGmlw3mDSv9S2Z0Bm1SyGdcYQdvAI+ogwl7jvFEi2Ht o8oTj2NlueZXzVO46BBOVD+bNt0myGjtePqKxVSDT0CZm0wVTjrrcdLG217M902hEX39 HAY2yen4Ft22kyNzOIxuLUaxs61jRX52quzdXCjNrbz10Ls4JvaPg3c/F/TMy6GDcZzX xeF28P7XXd2t3LX7gJ4gf68p+K8Setc//uuIFdB/tqRyyW9ezyCFsnrP8CKSNW0n2MWl SxEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456519; x=1714061319; 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=DBfQWUMtNb18nO6cukLxA1YJchWET3qC/zOTsZ5Ac7o=; b=mskTTvpo8p4LFuB/J6RuwctBOSNry5aML+9wCK2LOwzpOCPc0teuaon5tlwzJs+QAd TuogQFwsrU7DVRzQEpWwCuF0cSN/5w3PWG93lugwTD1RSi6jv6r7atMkbPA949sPj08P UWiG+E6Bv6PFXSx6bMLJ0HAzrIUKhvk5zV2iUiJ3BHWJUpGaGJHFgNe2go3a2W00y6pl LR+zCFlTRGUIyXIgwmtwg7U381BO/0gfA/W8sGSaOHO+9hw978jqLkkqu69ATxsNupF8 Q9Xi1h2mCLoDORAs278xt1RX9n1mMWWSStiy3OBhEObM1vL6M796udgSblcjVWBc7rxS ecXw== X-Gm-Message-State: AOJu0YyTiP5bFEZkt/sw5dVh7e4VFj9IAVtdGBlWDWDLxBp7cJJcJM2U T2l6j07n2kW3/RrAjh+ftOazCGgMHsQr+pCRncTAj4MIL38LYNM5aKQ93XWRi33SUbu+BNVzRrb vxx4= X-Google-Smtp-Source: AGHT+IFMdnS7RW0Jez6i3Fd/kXYoG6KX/jN9BmdOH23Tp4m1p+IaK1CJXuIIValKIkqvM7GjhNbIvQ== X-Received: by 2002:a17:907:7845:b0:a51:a09c:16a5 with SMTP id lb5-20020a170907784500b00a51a09c16a5mr1954930ejc.23.1713456518989; Thu, 18 Apr 2024 09:08:38 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id gf16-20020a170906e21000b00a526fe5ac61sm1068690ejb.209.2024.04.18.09.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:08:38 -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 v4 1/6] virtio: add debugfs infrastructure to allow to debug virtio features Date: Thu, 18 Apr 2024 18:08:25 +0200 Message-ID: <20240418160830.3751846-2-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418160830.3751846-1-jiri@resnulli.us> References: <20240418160830.3751846-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 --- v3->v4: - s/know/now/ typo fix in description v2->v3: - added missing kdoc for debugfs_filter_features struct field --- drivers/virtio/Kconfig | 9 +++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio.c | 8 +++ drivers/virtio/virtio_debug.c | 109 ++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 35 +++++++++++ 5 files changed, 162 insertions(+) create mode 100644 drivers/virtio/virtio_debug.c diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index c17193544268..fc839a354958 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -178,4 +178,13 @@ 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" + 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 f173587893cb..8d9871145e28 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)) @@ -463,6 +466,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. @@ -494,6 +499,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); @@ -588,11 +594,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..28cf30948939 --- /dev/null +++ b/drivers/virtio/virtio_debug.c @@ -0,0 +1,109 @@ +// 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); +} + +void virtio_debug_device_filter_features(struct virtio_device *dev) +{ + dev->features &= ~dev->debugfs_filter_features; +} + +void virtio_debug_device_exit(struct virtio_device *dev) +{ + debugfs_remove_recursive(dev->debugfs_dir); +} + +void virtio_debug_init(void) +{ + virtio_debugfs_dir = debugfs_create_dir("virtio", NULL); +} + +void virtio_debug_exit(void) +{ + debugfs_remove_recursive(virtio_debugfs_dir); +} diff --git a/include/linux/virtio.h b/include/linux/virtio.h index b0201747a263..c5f363b9f4d8 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) @@ -234,4 +240,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 Thu Apr 18 16:08:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13635071 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (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 911FE16F8F5 for ; Thu, 18 Apr 2024 16:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456526; cv=none; b=lx3OjOr7OjrGJUHdCblgzM28NvW3lIl2ZReTSAfA0K0Lk8EYlIR+21bml0Dl9DzSYTTYlR7N1m65VVfWJJ/jZNViVngLHeioPTvq9X6Tf/jeC2tExQchr/w+XGcockRphJtwXWOCHl8HMPZIP+DWb6qRdTWd8Fg2LZJeu3OUtzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456526; c=relaxed/simple; bh=O2CXlE7WbZEsGwfjpXKOeRNmpABi1eqbjqUq5VnToZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jh4ZZaxxgKO2TvVUoKsC+AQTa1oleLCzsCmIcYV1jmsU6hN7Q24BgW1vZX3j6+vmipg+FLQynxQilIl8D2XTu+MbGxqkWhzVR6y+eLfANhndLDTdiDEZTmggPitvFHuoDQXF2Ro0d5Zfr+ATJBGx0gjprAMfFdaBmBzJO4SQ/HY= 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=eikkMqQY; arc=none smtp.client-ip=209.85.208.45 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="eikkMqQY" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-56e2c1650d8so1105323a12.0 for ; Thu, 18 Apr 2024 09:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713456523; x=1714061323; 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=spywciv4H/4k+WYAUPcD4YDC9twSB1M/aeoXVh94Uao=; b=eikkMqQYP2Glu93TCWP9JYpkyI7mI5c8Jt08460a0fHOTucUyS3ev5mamN1sR+p0da 1raniup5c7+DRJWvMCWnAiLQlNWqvX95AZ2Tn+syv0WrhyjJXPwfBfWJa0hWzNmkkC8P 3i3XCyUfW4GMgivveJqfty0M5akR5w7LVPcfd2FmQ1P/tRHgE6qSPpab7PeHKrp9MbIz 4AqNEun3NfE5pgoXNGn2QdlBexGDWVlH/iJpRl8gwWNwd0kmT0piYCYtqKoTji2nhTN1 qJ/tyMvWYvVnvMZTerUwzN9KZeDTanAZmbTDUrXyTx8Oa1FieFZDhPxWiAVngnbt/tlV 24EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456523; x=1714061323; 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=spywciv4H/4k+WYAUPcD4YDC9twSB1M/aeoXVh94Uao=; b=oRsHleHUpqoKH/3iUyUrPNLjUbZ42mAGEm6wjY8S5U2VmO82mzkOgoH8sdOwY+xJNN xo1dij4WiR8Et5iFUFEh+QnNkvVY4H/yef2QzV6nZVsw0de/AitNSCw6dF6VyYLjgeWv ezVwuRXbT9/jHxq4P54361ELsPmYeVP7BJNoJidr5L9VjGAQUgjajYivJmIoXo7hwk4f FWt6o1IJHJr+gufRW3KmMBMTtKAwFw6Z5Urf//7JKFAl2poHbZ1SzRRvQHvWSyFleOQV W9QKvHpEksFn27N1uKgJ4fXhrOC38feQ7Lqoq1BpEM8b9PLnXrw80ZiZaSdRWFLFO/Ou XF5A== X-Gm-Message-State: AOJu0Yww/FLqjlTo+j4ylgERoXXuAzN1en+HeaUOoRSHEs9PhrPj6n+o Ov/veD3ugGTmOsFRARUc7t/BdAYPkk8oZyCzgojDYykaMV6DqeB07GzsMEioqG/xOqVc2m4tt3N E944= X-Google-Smtp-Source: AGHT+IHqXWzlT9OXQCwTPdM0t4BTG9sgRzPtxKjEdbuLI/IWPbpqLaWrsM82W6TAJ+ud4ZdH7G7QDg== X-Received: by 2002:a50:8a90:0:b0:56e:2d93:3f84 with SMTP id j16-20020a508a90000000b0056e2d933f84mr2027411edj.4.1713456522576; Thu, 18 Apr 2024 09:08:42 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id m15-20020aa7c2cf000000b00571c2712539sm424083edp.81.2024.04.18.09.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:08:41 -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 v4 2/6] selftests: forwarding: move initial root check to the beginning Date: Thu, 18 Apr 2024 18:08:26 +0200 Message-ID: <20240418160830.3751846-3-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418160830.3751846-1-jiri@resnulli.us> References: <20240418160830.3751846-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 This check can be done at the very beginning of the script. As the follow up patch needs to add early code that needs to be executed after the check, move it. Signed-off-by: Jiri Pirko Reviewed-by: Petr Machata --- v3->v4: - removed NUM_NETIFS mode, rephrased the patch subject and description accordingly --- tools/testing/selftests/net/forwarding/lib.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 7913c6ee418d..b63a5866ce97 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -84,6 +84,11 @@ declare -A NETIFS=( # e.g. a low-power board. : "${KSFT_MACHINE_SLOW:=no}" +if [[ "$(id -u)" -ne 0 ]]; then + echo "SKIP: need root privileges" + exit $ksft_skip +fi + net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") if [[ -f $net_forwarding_dir/forwarding.config ]]; then @@ -241,11 +246,6 @@ check_port_mab_support() fi } -if [[ "$(id -u)" -ne 0 ]]; then - echo "SKIP: need root privileges" - exit $ksft_skip -fi - if [[ "$CHECK_TC" = "yes" ]]; then check_tc_version fi From patchwork Thu Apr 18 16:08:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13635072 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 DCE4416F8EB for ; Thu, 18 Apr 2024 16:08:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456530; cv=none; b=IBbzt6tM7tmPWIrVnrlms0o/L2XNL8jbKBck/cL8acFOK0mYkAOpPeTz1lTbOlFcqhK7YXPW6a1Qvp3CqrD2QBC7ka7+opT2+XhcZ7Bpm3eQQhabkgcKfIT6J06p1FelO7XUPDBPsCqw2lB7im1bwkbKw/zhxUJHnc5nJzjFVX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456530; c=relaxed/simple; bh=ODc2bT3Tgy1hAl/eXH6/NifpgPwvNvOsQzDYDnBF6ng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OnAFguqbJrgcYejmK61dCL0wFzHAHCwNEjT1Oglib4xIFSI+rtt/93e/hpuShoqS8vDoJJKTzt1GNa2+SPtv6wLBhnu76FQRFX95TVrzy2gjhsUAIYTsGiPQc5R+QxbbCig3+Zq3HDrMtaISmFGx9jaag9p9fv1eSNHB2F/9dpI= 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=NF8R86L0; arc=none smtp.client-ip=209.85.218.50 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="NF8R86L0" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a51ddc783e3so119595566b.0 for ; Thu, 18 Apr 2024 09:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713456527; x=1714061327; 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=w3kdsnr+4DRfl3oY8QVhe9j08BHEG8XpCARPL+ULDq0=; b=NF8R86L0gtkp3UMqNP/NaT5Q99GVCXsnmdZMjEKsdPEHDGD8T6rqm9tvX2i7caZoOv eP5qjJRRhJ0vqQomjLixBUChg1rVvJnlFuP2JjFNidgaMDALVF5TN3ZRccsgovMF31YH N4CjLaahm31r9szlkynIyNKYL4jpBp1q9/vVyQ/SMFQ8NlWffY3HmKq/sclhvT6wd/Ec os4ciolrRtO3GkenaqNnGIuQwGViZ18L5cSlcjf5ZAEJbsEigrMmNmmIcG0BZtgQ3nT+ dD1ME/1LO1B4gd6BCdSymG9wmSnFWvmU3N4T//FlFaWVg+v+Dm1Og2xLvrj7OzgwvADy Lx1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456527; x=1714061327; 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=w3kdsnr+4DRfl3oY8QVhe9j08BHEG8XpCARPL+ULDq0=; b=HpDp85lwNjb4SMC551jlCoP12fSh3gYxgxMh6KiQf8je+HaPCj0QDn/k1wMrwbrLIH tgsUeaEz4KOmDdKf0GSLsYu67dNyhnFPGLFVfrRLlZ+TkIgzA1P7UXL/b7+/+h6My2EV nGvEkiyeHSNT6Uhu5f3W2KjtwFYRiUHvsx/M1sSt4oPA0l0U+OUPUp+cfa6uIOUQ/Fz0 CdMQCqHzd8IQCCOv6qaZ8OC9uBGf+12ns4GojdDPiHHF19qnQBKYDE9x0FQirECVuRfG 1T//Gzx1uuriCTUGCtAByq3zSB6zzs48hIg/1JRj9mDfLJnkot9QzCJV6UmO4xypJfN0 JzfA== X-Gm-Message-State: AOJu0Yy0WBkJAgSiuYYib0RPuUI1GY274tFg20WSFV+ukHBJuBP0oUay L/KiFmrtQTRllpFpYJHSE1B3LVzkt7MisuI/tik/OMWdaqag8bXzcrBmxXWeQy0qn/udtAG0ufh DKtA= X-Google-Smtp-Source: AGHT+IECj0h1cFA9hl40JSPqLgCZoPju1GzoIrhuIDwBt2vpPWd0Qkgb6sqDhRdsWNEcVAVC2+4bzQ== X-Received: by 2002:a17:906:470c:b0:a52:5a74:13f4 with SMTP id y12-20020a170906470c00b00a525a7413f4mr2185075ejq.12.1713456527053; Thu, 18 Apr 2024 09:08:47 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id t21-20020a17090616d500b00a51a5c8ea6fsm1081695ejd.193.2024.04.18.09.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:08:46 -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 v4 3/6] selftests: forwarding: add ability to assemble NETIFS array by driver name Date: Thu, 18 Apr 2024 18:08:27 +0200 Message-ID: <20240418160830.3751846-4-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418160830.3751846-1-jiri@resnulli.us> References: <20240418160830.3751846-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 --- 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 b63a5866ce97..d49b97edb886 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -89,6 +89,43 @@ if [[ "$(id -u)" -ne 0 ]]; then exit $ksft_skip fi +############################################################################## +# 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 Thu Apr 18 16:08:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13635073 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.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 2801016C68F for ; Thu, 18 Apr 2024 16:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456534; cv=none; b=RwKde1tAzd/kxaWeyMYxqf2TjzMSQqr8RaV7CgMCxOlzPjcm9E7uAHBMMrO6FRmEvGfOYHa0tUuLAHsXtNn8mc71xnLRnzpFJyxyZb7Cg6YX5wccOfLrcaBbPHxz6XzUiK4+tv/rRScB8bT0aC1FAGekszkQM9AZ7vnZOOZydho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456534; c=relaxed/simple; bh=2jQPPr9mkTqJV56LvL7E1XGifU9BFqf1rQjL05mNI0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NvtLk0DbjqmdExobHneYQ3NlW1RonUchyC1ypElHm5moR5UGmGqwXcJQlySxkoZf6VApoioYvcwpEYZLrJmrdOYE7euIXqzxeekoa7jb82zINUhIljEQjziK+LnZmdfFBbb9RIqDGkQhBPKvKrBfjBAdVlnXF6FKwQ8oTiOY2e8= 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=BBJVsYH0; arc=none smtp.client-ip=209.85.218.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="BBJVsYH0" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a524ecaf215so120214166b.2 for ; Thu, 18 Apr 2024 09:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713456531; x=1714061331; 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=nSQx0/+CrkjLLqkpLado9VHrrZwCAyIq3CNsBoHFJwI=; b=BBJVsYH0zHjHjiLegWSlQuQg53xJk+uX+UhQ8WzRm4Q6keBl1e1fjc/bC1VjuXZqS+ oZmNZUBUuAMA77hGqix3kanC/QPWLe37LxRhceeHaf2baemQ70U5UHZVIUiO+1wjVFoC sPcA7HPtDdTB3PGiJMhuXQYmDuQ93SoNh2Q9hDcIvLqCapWX7VEbkqrfx4l6P1Wc/pLp zWs6UTH3xU36xrwUUvmFxQoDNCdtFIdctnIDXxTILovZitnj8Y3z7yXX3z7Ax1jkKFvV jIhre8qZJGZnwUHV2M0YIqB7Um3eDguIamURYKCZ6tCLBnUoRNEySkY5JZdGisXOG58z df7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456531; x=1714061331; 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=nSQx0/+CrkjLLqkpLado9VHrrZwCAyIq3CNsBoHFJwI=; b=Vh6t18//twWDj/uHEg7sFPtoUEcodZwK53kVj3YtK6+8Q+YsWA6EeDZoK7plTBAl0C iPVmO4VvCz8jj/vKHQ1VRngwZ1kROBvbdhyjDP2MjXyAdd5xSH5n//6bhnsYy1fDbKVf 4MX0qVKrRHtogRcFbnJYLn3+d+GbJuDRzlwR0newTxNEjYz1EY8fsALBAtYrJRs1gL5H EeYl3IuucWYkaDDeWYR1w1zuz75ad7EC1uhEwNvtkPjvSLSA/xiw4iEIxo1O+gggGxQS ASyL11fSSl2feU/GPDTy6sl6txDJNCym1/LtRO28XtYMr+wvEpIjE8/5/1yQpM1p4FHn +/RQ== X-Gm-Message-State: AOJu0YxNgsPlFH+vrO54LHkvGvTf8CTlDB96IfCqy5PLznMfDsQ4SF+b yV3e7Voyhvyx4eG6/xVvevxLAsST2PTx6fe76gKyg+0GtbDiHD0twJwQLH1XNRgVAB9Zb3o2iyk CntA= X-Google-Smtp-Source: AGHT+IHiaBm2LKsHV2qQHTiD3aikXdD7pxY2WNALoqBcP1UifeUoqdQS7+b2n5gVV7we9OrzlrQ6pA== X-Received: by 2002:a17:907:9724:b0:a55:766f:ce59 with SMTP id jg36-20020a170907972400b00a55766fce59mr1826260ejc.75.1713456531339; Thu, 18 Apr 2024 09:08:51 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id k9-20020a17090666c900b00a52274ee0a7sm1079280ejp.171.2024.04.18.09.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:08:50 -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 v4 4/6] selftests: forwarding: add check_driver() helper Date: Thu, 18 Apr 2024 18:08:28 +0200 Message-ID: <20240418160830.3751846-5-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418160830.3751846-1-jiri@resnulli.us> References: <20240418160830.3751846-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 | 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 d49b97edb886..17f8b6b9ab9f 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -283,6 +283,18 @@ check_port_mab_support() 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 Thu Apr 18 16:08:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13635074 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.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 99F48249ED for ; Thu, 18 Apr 2024 16:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456539; cv=none; b=FSEd3gLclns8xDcS2lUqJPY4sdEjvGqKTGRzXgUXhyxM7llXd2AliP5CnsEJ4i0LmgZKFBn3RObOyTU/+rtHAQlVuznXS9oE6QRpBleDu2WGPVvsw7hg1EJF87WtDpqdJDdRQ3cEcm9pMplB61vQSg5xMZXNJG26E/1NrXjEACE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456539; c=relaxed/simple; bh=b0IPPzC2gZPsxNRT1JsNB/IxxUT5lL5pQHIYy4fkYB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KsiEOyXsQXjtXApGpmrJBV3ikZEknQ1Dq7FP51N42eYRWWPZnF5wPUP+9wFBi2A/p9NiXhdusK0cQwG79Brg9AIOAt8LpnTS9NaPkyhZwek8TPl2veLCoiXckW4D9eWdDcrv13D+aOsVMT5+2dEQFm09iOTVc8jwRyH78D8nFvk= 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=GHK945kr; arc=none smtp.client-ip=209.85.167.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="GHK945kr" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-51aa6a8e49aso424908e87.3 for ; Thu, 18 Apr 2024 09:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713456536; x=1714061336; 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=4iDht4R3VqRW+yPNRz+ghqd2WBxn7y+zWhn1SiVJ1ZI=; b=GHK945krI2vEQIhTBmqvLPLg+kzAUCJKnQSxcqN5jlsdY7AQdPNsX8woDKt/X4rnnJ s6W0RO2y+PFMx6CWcLU8jW5oAp8rKbDq6W/3nXlbdOb+zacyNre/qyXt8xCUfLUQYCrl kvbnWL7tWH3PC42VP3DSloc3vAuwMm8PgdTLgDnmqc51xffvwQrq2CmbXufeppRoah3y qyQyQnXX0Fw8F14xFaonToawD38UlNf4EEfwLpgbVCPdv8JkaTsaerV2idnNxxnpc4bE eUCI5HP0Wa86nTPtHgq/FQj/Xqgf9xCuo7iceM7yhFemyyfUT7k++HdCACKuhEEmdpFd xyrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456536; x=1714061336; 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=4iDht4R3VqRW+yPNRz+ghqd2WBxn7y+zWhn1SiVJ1ZI=; b=v7wws785loy9l/i3kxIc7r/2Afagzl26OWRayztR+foue1G5THCNOa/WJH/k8B1GIv TeHkmqIwMJm9mYoH6dXOoi9qcRvZpMLrzAGo58aiQbK9n0DxNQNvsp4lxKcXwL+fpkRf QXGC72yY50GzI9GtZVUdyrAkv7TYUJ1io3AwbHV/JfOgKagUseMFEvHNC5eQNFb4ldrN vM5JUmTzG6SHaAgTp1H3T2jadccMlvBnJ6jbLUG5OT330MFNa30yMwZv4L8eqF9FEMpc SqVqQoEbQ8u5W7QP/LXHIxMFX3Rhh3yT2/ZXc+nRqLXkbcphkvxewGr9rFCL4Hw/+QAo MHVA== X-Gm-Message-State: AOJu0YwbKLXpyFK7e8emlzb4ynrluGWvz50YcJNVotK93B/WUv4efWcv h4cxT3PxWM7xy08WRqi2cZg+3IXwv9X/+4m1LUGt3+s4j0ywD8bX8IAPgfL/COd5SZVodTqhSoG 5jbU= X-Google-Smtp-Source: AGHT+IHN1LuBKkkhmIVKUWQfuW1mI3eS+gdV3HtAN4KpyOxEft8HB8VKerh5b0bPC/3GBlEH8c1Y+A== X-Received: by 2002:a19:7707:0:b0:518:d079:ffd9 with SMTP id s7-20020a197707000000b00518d079ffd9mr1878748lfc.13.1713456535870; Thu, 18 Apr 2024 09:08:55 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id l20-20020a170906795400b00a466af74ef2sm1077572ejo.2.2024.04.18.09.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:08:55 -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 v4 5/6] selftests: forwarding: add wait_for_dev() helper Date: Thu, 18 Apr 2024 18:08:29 +0200 Message-ID: <20240418160830.3751846-6-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418160830.3751846-1-jiri@resnulli.us> References: <20240418160830.3751846-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 17f8b6b9ab9f..e81507686870 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 Thu Apr 18 16:08:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13635075 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.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 57E8C16F90B for ; Thu, 18 Apr 2024 16:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456544; cv=none; b=TXJP3bggI9Bvb4bCaeee5U6IvISr51M+DjXWpcgZa6duswbte2oWe32CuMJBtEC6GZ8wXAzNEnBr5TdPRaJ25DKofl9uT2p/F7EuCtWmRw0VZyB26s1keFnqdirC8r+TiTicYDn+bq+9s8p62UK+HvFWu9YUn0klZjg8dfm8BRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713456544; c=relaxed/simple; bh=iaWNrh24nqZc9pYnieoq726QZmpfdpBdYZQKiS7PUr0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=COyp6ImaYjQRgMIbxU8PlwSU4Ses1ZN+reFOznkXpLBJ+bDY0eDCeV7xZ1OyGzIDhrWOtp+fiB3m7HE1oI8XVd7rydPufORwSIpegxTiFjLlMwhNeEWY/pbDWlfr/t7rUKvCSEsX7L7ErdXIDJ6jnKF2NIzyIRNC6IZGktF5g8A= 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=H9JnXbql; arc=none smtp.client-ip=209.85.167.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="H9JnXbql" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-516d487659bso1220895e87.2 for ; Thu, 18 Apr 2024 09:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713456540; x=1714061340; 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=GbQQKTOc2Dd2SDG5X0E70w6+TkbO55QMG305rwdw+l8=; b=H9JnXbqlqQvnljQBtSRrIyIGWUTVG+xu2nzDQ31a2/L0oE07ZEsmzupWgrayXEFnWv jrTIywNItvbprCzuvvuW73rsOGwFL/HH/EDCilYMhgwFgfysw5LB2BAeQB8IFAJ0EJsO q/Yz5tT+5FmcHD/RuI9QfnRgZ1vmfY1crh4FsQAzEUj3108lPk4rLROtn2gwJKyFeVmI aPalTxna3+c2uM4x95zLgO3FaaUezTn9by2UItXxGaY51Oda7aLdqPcZpI5RLZBI7Kls 4q6vgSZaN7JEUu6gKIoey26uKilMgaA6UjTVF1KKOsGQUuE2SbH3YAAxEbkM44yexJJT wJoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713456540; x=1714061340; 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=GbQQKTOc2Dd2SDG5X0E70w6+TkbO55QMG305rwdw+l8=; b=a4QMlEPVqcoFy0zMKk8Yc9Um65PFgm7Qd5AiZPihGszD7QJkWyhIK0zV7Gca9l2Nrp +Q+yvcE/ren94H6l59mXg4zG1DJ/PYsgWljsx0zD/iwZQeCuZQS+AlERmXlEhBlRpzMd n4VNjHe7COIsHB+LS8nnU7oaSUUoy1Z8OUfjVDoAcLzh8SoYmYq5rAInAfHm3wMNl2EK dq8yDqhTJXd2fwXKughN6k83o+4I3Bw5x1826AYbD4scdrQyGKvhyP3u3i4KLsl5Ye4j 64uWo9CS+p5oiwijb6u0cnbjZaNxkX9qb27h6olU6wJexVf5H30Tg36QpF1e9w4DCqgJ rPxw== X-Gm-Message-State: AOJu0YzymNkRoYBcevmkq6KC1d646A1RLrVZrIkbEpQqQRf+sLzF97jc awZmvkODuJKRD2Bz4Eq5KWu5ssJh6eypbGEjWg8eLtx3mJry8wxufEK8Wg/fNUs+sLUAO4bKTMn UEJk= X-Google-Smtp-Source: AGHT+IE/ovW0YoLY3D/J75a2QLXFTJHxiE2QBsrQR4xSiTMiCJxc/V0hJE9FGCT986Ggjq6We2/9mQ== X-Received: by 2002:a19:7516:0:b0:516:d219:3779 with SMTP id y22-20020a197516000000b00516d2193779mr1881237lfe.58.1713456540345; Thu, 18 Apr 2024 09:09:00 -0700 (PDT) Received: from localhost ([193.47.165.251]) by smtp.gmail.com with ESMTPSA id ek5-20020a056402370500b005701eb9441fsm1044816edb.75.2024.04.18.09.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:08:59 -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 v4 6/6] selftests: virtio_net: add initial tests Date: Thu, 18 Apr 2024 18:08:30 +0200 Message-ID: <20240418160830.3751846-7-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418160830.3751846-1-jiri@resnulli.us> References: <20240418160830.3751846-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 f22698a7859f..5655fc89f3e5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23450,6 +23450,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 +}