From patchwork Mon Apr 15 16:25: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: 13630293 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.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 1A53980C03 for ; Mon, 15 Apr 2024 16:25:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198342; cv=none; b=Kn62MQTBGsr4pGChAE6o2vBYw8qA9Avt4uEFpuV7aUZWh6iwktIA6RXbMPK6FG5v2kgLQ5guTYziLRPou6WnEd1xsH/HHTSZQ744JOoDrF+DYYL8Le32nKmkVBzmF9x6FiM9SwxHqth9/59cb7p999iHls0aK4HbeOVlWz84bT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198342; c=relaxed/simple; bh=H3pjtAzG8pQcFoMfgL2Fil38d0Ryh7wHYYt0AdNSf3U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Er235WzHs/WHWWcMIqMNy5+zZqbzQ3HqtW8kLvEUFHxY6dVBcp35HhsjLHso2jGZUtb3wC5nGmR6MapZ4JWk87z5us9HS8Zxu1j2v6duHq2n/+gbHtIB06ow/3t/c713xpb0CPr7hntElGWmQdlqapKJSBTfSR8C/arf43jA96o= 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=LkBU9nNm; arc=none smtp.client-ip=209.85.208.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="LkBU9nNm" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5701de9e971so1676813a12.1 for ; Mon, 15 Apr 2024 09:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713198338; x=1713803138; 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=oxBkGe7SdmsJXy9vmp58aQDE3BF9aWZY5P/z4wlEcJY=; b=LkBU9nNmHFbLE+nwdI5PYT00Oh90EHD0y2kbZUaNBA2GuHmoPqTNOWUHYGj+OT9Nwu 5qC0bnlaiOEhNqMfkpEhUylg8lsuQlXzRN2dC+dpzsf3l+VZF0SdyXCvzomovdIcGLER vVwwoXqbH/nJy4qQWvXMlV8LKr6donfYpoLM2xUpeAehcndvTcCeENmd3b8HVQxYpaTA jyecMx9O4jz9XuYAdwwbExHu2G0MLNm7T/0Pbws4Oqj6rn8872x34/ABUo1Tlbi6Y9SV CwONFIuKIxcy0d4KGAgwesSwVs91Lqb13QIiy+UhHPilmrX0BWFsNO6ysNUPGDI5QJfE dWYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713198338; x=1713803138; 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=oxBkGe7SdmsJXy9vmp58aQDE3BF9aWZY5P/z4wlEcJY=; b=LMJccz8I8aLsLWtmj8gVTZ3ATX28bEnhlGsOLVmCZIKpgUJs4mfZ4PNXwf168freuG m6C/8lYIFgMUyZ4IEwBIXdf5eOcMq3DODceFdoWk/Ohsk9DdXoNyqtsf0ig2lCTuiWih x61S/Iq3csIL7OhFoxKJvJK7M3bfg8lFZXgbtGTG1uwBmw4CHYh8ENoGXs7DtuWp/elz CJ3c2RswLpfk2zhOrX/yDFN0dc1SbuQoauBfG2vseDRs6u+aqR8oONofzBCLPcTGZSk5 D5ADwB+0F2grjgr6/pRXEY7w1wlAtlBQwTR0fEB1YRXa1FDGS9dTy/hTzgb6/2rJuQT8 z7yQ== X-Gm-Message-State: AOJu0YxW9gcg1zn/+MPnPKnIuYs2x+pJd+NhH/Y9BDCylvUAoK3Q0Ife ypj2F5I7868cSyqJdlx3YVp6nC5YDRpW02pPHjh3GySkdpyUteFcpigRZvfFi/u7i6Enb7318hH 2 X-Google-Smtp-Source: AGHT+IEafLM3OBi1Kh3R8pGDCh1rQ1+aO4Z3tp7LQrYp//KbR28f9IwLSGyt4rGxRCauKWQSjR6NUA== X-Received: by 2002:a17:907:6088:b0:a52:1e58:4e0f with SMTP id ht8-20020a170907608800b00a521e584e0fmr8554550ejc.55.1713198338111; Mon, 15 Apr 2024 09:25:38 -0700 (PDT) Received: from localhost (37-48-2-146.nat.epc.tmcz.cz. [37.48.2.146]) by smtp.gmail.com with ESMTPSA id k21-20020a17090666d500b00a518bcb41c1sm5628404ejp.126.2024.04.15.09.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:25:37 -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 v2 1/6] virtio: add debugfs infrastructure to allow to debug virtio features Date: Mon, 15 Apr 2024 18:25:25 +0200 Message-ID: <20240415162530.3594670-2-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415162530.3594670-1-jiri@resnulli.us> References: <20240415162530.3594670-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" know already exists, this patch does not touch it. Signed-off-by: Jiri Pirko --- drivers/virtio/Kconfig | 9 +++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio.c | 8 +++ drivers/virtio/virtio_debug.c | 109 ++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 34 +++++++++++ 5 files changed, 161 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..ab3f36c39686 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -126,6 +126,7 @@ 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. */ struct virtio_device { int index; @@ -141,6 +142,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 +239,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 Mon Apr 15 16:25: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: 13630294 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 5A8C87F7D3 for ; Mon, 15 Apr 2024 16:25:43 +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=1713198344; cv=none; b=lu7l9rsfeFrX/NE45dUbqW+4tZknlwJK7udiOoc9z33K1tHwrqrByc9U7rpepis4t9P5//kuHu2RoVHXD6q6hb220NKKaZLfYwP2C1M1+fqJaf0Itd0N7JJ2JELYF2W1dAtWllftBNUOfL/ElUf1FZqgc4iiwHDc9J3T/RCsMQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198344; c=relaxed/simple; bh=j2PzpeP++wEtCimj6PizZGaulOFqRwTLU39GbwROnR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lPBxog9Lg1sirrrHl287qQickn95kCh7eXS5FrnbS6ok+zrb3Y1CXl2yXVZw/dcLIvcgZw85uL08qw8M4jrBF6cLBbRiCYo1jS3Syv2cy+XnvIYDLvgr9FTNaUjwmNwDsVCunNimP5BU4+ylvZgZEuuDRCc6EC+ttst2AAlWj5c= 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=NjTu9WG+; 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="NjTu9WG+" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-56c5d05128dso3569708a12.0 for ; Mon, 15 Apr 2024 09:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713198342; x=1713803142; 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=PX/Tsfwpe953mO8yyC/qEHw3fIQWpZrg0eDPY2EH2gg=; b=NjTu9WG+Z+nHN6++zW0ynpQa+Zlz6QDaXTNQ16//Xa7nBSgsGPAqT9bAHS8CyFu4Mm Nq5sOGKSgMf7Fu6f4sbUw7JSr3qMyepwuTR8m0t/LpM0342hZsovyTF7JQYhP4uQ7eut XAHz+8Xt5lgiFQlvruYY2KfYPfOxqybbV/s2XNHSxgE7bWpVj+FMCnUap/QiBh9Eo5MZ W2ajLKa6A9jsXhw+0t5qGiS0ELadnCfjcx7Nhf2xn0Y8+BJ0rJiqLnJR2ZG6hffGpGpL Oim6zmM/0BK94VPmPt75wPiKrKgmDW53fXGB5Q4DBkY6ZMs37yjl/w6/zhH+nS4eH94D KKnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713198342; x=1713803142; 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=PX/Tsfwpe953mO8yyC/qEHw3fIQWpZrg0eDPY2EH2gg=; b=JFr+jdtgfcRNIVnzAbSsLBzkUOB8A7Hos/igSc72Zl8DLT8B0nXZCd7LMxJRpKnYME Lt5PozAjBay5Sr/ql5zrA/UHmaGiYYnn3yaK5+hf9es3+1QI8P6C4z0R5CoioQ7G6uEt 6U6/sPP4RHNHLkf19FoiByEsHA8U3G8/ZSUlJj536KGccFxgKBfX+0e0rze+Ru2on+ZI JZRRQ8ptU/3PvT2yrCxRVoX6oVPa4agV5mlzz/Tj5kkhcAmFxUiiChbBZSEeJNAbeWBR CFm56BROoSsAHbQARyHbJEyfltc0inYgDshBBCqrc3L3CSWOx4GK2hyCfq5xW6BDOBOh paHA== X-Gm-Message-State: AOJu0Yw+fPqjrdlEBHd8TTrV3IRzjI5/crvaocu9UajtTEiXLOEBNZ6l ui0eEnCv+F/pKKGUUS9KjeCXPLHzNkRBNcxkKVlXjvjTkYJ54URhOvRGYIvwpgA49q3wAl+tNDg 3 X-Google-Smtp-Source: AGHT+IE3qEYePTUANR+0lWo36Ejjsqj0/fD1LifZooLG26Irc7ZuYxn+NRnblHf3EFxVGbz2a6489Q== X-Received: by 2002:a50:9506:0:b0:56e:77a8:93d6 with SMTP id u6-20020a509506000000b0056e77a893d6mr6698185eda.3.1713198341676; Mon, 15 Apr 2024 09:25:41 -0700 (PDT) Received: from localhost (37-48-2-146.nat.epc.tmcz.cz. [37.48.2.146]) by smtp.gmail.com with ESMTPSA id ck16-20020a0564021c1000b0056ff510c327sm4381535edb.94.2024.04.15.09.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:25: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 v2 2/6] selftests: forwarding: move couple of initial check to the beginning Date: Mon, 15 Apr 2024 18:25:26 +0200 Message-ID: <20240415162530.3594670-3-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415162530.3594670-1-jiri@resnulli.us> References: <20240415162530.3594670-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 These two check can be done at he very beginning of the script. As the follow up patch needs to add early code that needs to be executed after the checks, move them. Signed-off-by: Jiri Pirko --- tools/testing/selftests/net/forwarding/lib.sh | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 4103ed7afcde..6f6a0f13465f 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -84,6 +84,16 @@ 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 + +if [[ ! -v NUM_NETIFS ]]; then + echo "SKIP: importer does not define \"NUM_NETIFS\"" + exit $ksft_skip +fi + net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") if [[ -f $net_forwarding_dir/forwarding.config ]]; then @@ -259,11 +269,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 @@ -291,11 +296,6 @@ if [[ "$REQUIRE_MTOOLS" = "yes" ]]; then require_command mreceive fi -if [[ ! -v NUM_NETIFS ]]; then - echo "SKIP: importer does not define \"NUM_NETIFS\"" - exit $ksft_skip -fi - ############################################################################## # Command line options handling From patchwork Mon Apr 15 16:25: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: 13630295 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.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 F07FA8062B for ; Mon, 15 Apr 2024 16:25:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198349; cv=none; b=pjlrLDvUkeStjzICa9Qhj1QPtxvpdJRq3HYzbUJ/yf9YF33xq21L5hTsBhMoxcDd64PHUsgpbaQKRuuQy5DKDXkY5ZK93RFtAaKg6FIPBAeX5waHen/hVnCrlRzfzx3ANH62ZQsENV9gjJxGstLXQkgsMM84am9O8hGqyOrSe08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198349; c=relaxed/simple; bh=wxFoEQXGXgP9lAoXIJl4FH/A6/EA6g2XPjytbEI7kbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jom7541hdht0UByadwKPF03fDvUp+T/KJwU6b8R5p/B+i0nH1RN8pnkkoRCpYSY4rfVLpzZJ/lt+mzK3r3kVpqgPl72lrKoMbWBLWrIuwTlt+cqd0AdNWgGnGbeP981vE/uykNAPcnac5Cx5DpI6lrWuJ4kIJAOvcadomFtYhgQ= 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=pmOVHKYZ; arc=none smtp.client-ip=209.85.208.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="pmOVHKYZ" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-57013379e17so1931922a12.0 for ; Mon, 15 Apr 2024 09:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713198345; x=1713803145; 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=BOjc7RskPi7a/HeDwvwVOXTy5sL+YjkDPnBm1m5pAYk=; b=pmOVHKYZj+5gozRpHQbw+8EDgsGkpN125mLhRi+kC9ZhhVSY3pDJazzdxE48aMjqpw oX65KPWy6We9Uk5gTgyzKVD8HKshqB5U6LDKeXCd/H/Exbx5ZAGWEaAQzPmHsPW1YXBI wJJ1Qp0W/zas3w07L3kBKCmU6/4libm4H/bAYPnHuKepcRGDp1f78eO90zc3RbmbtcC6 KMPlfeNj2KzkqzyBxu6KAABPvpTxvtS2/rYH83NzaW1y3bWlsNd34iHn88H+3vKH/q5L Tt7Dse50WQ4Y28PIFv6BkZQPTMC2zRefzGQtpBKVg0jlrC2qb6PCenkp4nv9xOJ71xRV 2sxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713198345; x=1713803145; 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=BOjc7RskPi7a/HeDwvwVOXTy5sL+YjkDPnBm1m5pAYk=; b=ik79azOsZi+R9QwHg9DOiPFvLUuek6pM3bOm0l4L9xZP+BjZrC/iCfDMImWaHDmqx5 33+1bzN4aPsvKyX5vj/q+X1Upc1KW/EDksEMv3dDqa7gWcH1yVhenRx4BxrJTxl8r8Mo n1rYuGBBLyJIMxJqZHAfR46q/q1Jj5v5ZfuYp3mvtJoT3HrMQLirO53mg++tdJRVxbEO q8+oDD8m2NbOt+F1dsuHYbJR2xsB8aFH+q6Lq8xUvSL2KLdbxgh1i1zxDKoVhUWzNGdz 2B+aK0A9EYYushk2gDkMda+hNINKIBy0WPIyoRdOf3FIrxBx/7XopWuNDkGohRHrejI4 FlYA== X-Gm-Message-State: AOJu0YwRN99cFbcDkM+ifcBh3aj0f6cTJ+z/O5IjXjiyjuzrPHyhsMT4 7QaXM/jetiV/m/UwpZ9gQYKo+J+cbcnNPOAqg0Dw8Y/HTFE/3Vo2MY+2+K3r7JmNsDZLswvSogJ A X-Google-Smtp-Source: AGHT+IGsktiI0fRNTkM866z5w/QeMx2+qxChxXe2b1H+SAiQI3oyutgFmZXAflo3H33P1t2i05fsmA== X-Received: by 2002:a50:9543:0:b0:56e:2b1c:d013 with SMTP id v3-20020a509543000000b0056e2b1cd013mr7749568eda.21.1713198345074; Mon, 15 Apr 2024 09:25:45 -0700 (PDT) Received: from localhost (37-48-2-146.nat.epc.tmcz.cz. [37.48.2.146]) by smtp.gmail.com with ESMTPSA id i8-20020a05640200c800b00562d908daf4sm5016938edu.84.2024.04.15.09.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:25:44 -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 v2 3/6] selftests: forwarding: add ability to assemble NETIFS array by driver name Date: Mon, 15 Apr 2024 18:25:27 +0200 Message-ID: <20240415162530.3594670-4-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415162530.3594670-1-jiri@resnulli.us> References: <20240415162530.3594670-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 --- 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 | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 6f6a0f13465f..cc94de89bda3 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -94,6 +94,45 @@ if [[ ! -v NUM_NETIFS ]]; 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 + echo "" + else + basename `realpath $driver_path` + fi +} + +find_netif() +{ + 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 specified driver. +: "${NETIF_FIND_DRIVER:=}" + +if [[ $NETIF_FIND_DRIVER ]]; then + unset NETIFS + declare -A NETIFS + find_netif +fi + net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") if [[ -f $net_forwarding_dir/forwarding.config ]]; then From patchwork Mon Apr 15 16:25: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: 13630296 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 30DBA81AC4 for ; Mon, 15 Apr 2024 16:25:50 +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=1713198354; cv=none; b=bkbUTdvzOhOfhxdWHp75AH7Pvinrr6XijxjI3bJfx/eKYZ17PJjq9kHp35KhDHnR5qb1bBehwYcIj0qL3OKrhTf3sBTeoJt5RfnmFzbYX2QeXlCnwiqKuJCCXRxcrloQ3g4GgRxMZHc7aPZKyposQ3b5vC1pNm4aTIwCornuGPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198354; c=relaxed/simple; bh=6AWPtYIUVkIYogf/lFsvz7tOLfgL9m/gvfqRIzDJe9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k+zN7y7NfpcpP9B3T/zpjVeEwPrMWlwKKigEPG2PKFGp/xazEaBLQgEQzMx0jAkF3er+Jzd9FYHr/6uQCB+BtXQFOnDBdtGEIQs3wXrDjUgBHpe17w+s2wE6rWf5lBRAQM/oBXcpKxiuMp4FJahjkERkAMCthQEDwfuGRGJ23vM= 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=nf8xJFwc; 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="nf8xJFwc" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-518931f8d23so2407217e87.3 for ; Mon, 15 Apr 2024 09:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713198349; x=1713803149; 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=VClqDAQzBaKyJ8klxTyXU7hsV/mjaxzL9AK6EWM/QRo=; b=nf8xJFwcVLcZwYwHTBSY7jpPr6Gy9RhfoIpwgNmlYVgOEnfa3N5TB6Uc1fYlhQmMgk gX3xdn1xkY6M5NZO/0AfjMQB4w0OQBRTLvcql16xgLK7duYdZXbSW6W5fEGqE8MLcRDU Hsyq7t2yrtyjfY9xUn1zwj5hxr7uLtCN9hxDwEge4z4+aJyZXXc123CujOF4A5OjliIM JeQ3D6bvWY39N3vAlwwQ5XLKB0o2aBOTLFFCe6qpuNGTI9YjxjrtNvrixydk+gzXwZi4 s0faH7DTdHSA8/xiF88Znqiec0Akswi/yH8vuj6+pLNyx4hwSljGdxwRtsz3m3rGe1SN SEgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713198349; x=1713803149; 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=VClqDAQzBaKyJ8klxTyXU7hsV/mjaxzL9AK6EWM/QRo=; b=GJUm5lc7X90kLHEyFh0EtFFt2Z5Ol6ZY50DXC/2WkT3SwjEsglsZhQyCPTgFkYHca4 Ii6OcoY6GopXpmVBcpwqF1brNIiy6Ef741Skza++bRfgMj4GohjzwmaX3oHNbflXDDQy +zOUhg9VSNYGslejlJPQ9R4gsLI4AODkp+o069otgBUqWdFtkZ3IdooOr8Q+ivgygGFQ S2T8d6jj9OM+M33u7eD0lAkBCehCrls5Dj5MoEiD1w2zlLN43gM9srJWrdp4uPEsuaHe 9Nk9Xq8/hF3jd83Cp6n3I3vwA/b3Xcv5Xo7e5YuaA+JxoWfPj8VyNgk/NSL/7F+fsO6t GHnQ== X-Gm-Message-State: AOJu0Ywe6nPPaFyGhvz7q5jWcZGdpB9U6iK0AH1D/CbL1O9ymGifMAug q4Syfuq9itw/nDsg3olvkc8HXWWpHuAGGCkyiXlxS5R8eFCqtgPJMbHXUJ8nodDmRafE5tr8too 5 X-Google-Smtp-Source: AGHT+IEuucDhgvoXqySP3PjfT1QnbG5b75B2FPNdroFY03N44M1rruzD375UtJNVfLZzTmoq8qHT1A== X-Received: by 2002:ac2:520d:0:b0:516:c9a7:82de with SMTP id a13-20020ac2520d000000b00516c9a782demr5949139lfl.38.1713198349145; Mon, 15 Apr 2024 09:25:49 -0700 (PDT) Received: from localhost (37-48-2-146.nat.epc.tmcz.cz. [37.48.2.146]) by smtp.gmail.com with ESMTPSA id b9-20020a1709063f8900b00a522e8740ecsm4847924ejj.139.2024.04.15.09.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:25:48 -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 v2 4/6] selftests: forwarding: add check_driver() helper Date: Mon, 15 Apr 2024 18:25:28 +0200 Message-ID: <20240415162530.3594670-5-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415162530.3594670-1-jiri@resnulli.us> References: <20240415162530.3594670-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 --- 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 cc94de89bda3..254698c6ba56 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -308,6 +308,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 Mon Apr 15 16:25: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: 13630297 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 3653B8175E for ; Mon, 15 Apr 2024 16:25:53 +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=1713198355; cv=none; b=bl2enlqP2389fVSoAjufuc4WilRc2G6TzLczY5B4R5QNA9KytGpNfMPLhLn+x5IDqvQvgQskol7CL0hQFZ4T7g3p4BZa6xjOeX6p6+1JycddV6Kc8xiEOKOz6as9L5BF14m0PVjpoTTEdtcpUhr7Wcd9QacyujUiQqY2omznMZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198355; c=relaxed/simple; bh=28bGfo/k1xHZ3BBi63D5YJEOeJXQ0EzebP5KwrPOH6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mWlYRtqfzLz9z1rYaRvlosSBUXtryvFshTVwdL4v0CDEnEEFs1e94ucmiY/BCt0YaDNj1k/Dj0kiTQPDC5w80sRKWiYLVcFTFndWyBuZfj/UvCXSOuEFIcIOzxGnVVEkK8AtLLKDDHsDiQwZErLHApAFw7Tg8jUSSA71pZ4nW0Q= 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=bQ7MWLxF; 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="bQ7MWLxF" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a52aa665747so130421766b.2 for ; Mon, 15 Apr 2024 09:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713198352; x=1713803152; 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=Hobzl0UFhcxWwRJMKvUjC2bqwhgf84pG3unrWYn5GIY=; b=bQ7MWLxFKpVNc0cavT65wnt5uHM3AWPV6CyljFJjse+pWztCej0LDw18mFOIeKnAq8 FsEsIVUVLOt3kPkLgJOpu/wRuOMXgllSB2g3i+YRqpOsCSC2N+8KSl43WIUWJJGu4lTa LhMbKmH11ZkLpC/qtk8XccIb6t4hRO7FwlWzmehpXOwILjkGxLktgib7R6UPLSHuoESS n0myfmezVrhimC2oPthJt2Yn7jjFRPOxQdgduxmOC3L6fKvePj03jw5vyLSYh63WEeie 5u1/U7GAGxeonNU1BMBmW4u1egh+2Zr0tdotilbvoMYrel2gw8Kw1yomyiz30bBApA90 Jeww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713198352; x=1713803152; 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=Hobzl0UFhcxWwRJMKvUjC2bqwhgf84pG3unrWYn5GIY=; b=dDD4Y4DQxWIf78KmE4f2ds/SFhyzfB8qWJCH0OleHcpuRUR6BsJb/cYRg1ufM9fRzS v7aozLJtWCaFW5hDckGZzUp/Uir9CcO/JmhMfkTbzm9N5UrTroa51jtr+JrC28nQbQKH sKcJQi/0ygZYRU4LDhVCfamE1paUQxR8oE1/y4A6CWlaOp5etx/Zs2hi6XZcO7pkElb5 cfU7SKZpDip1MXTOiAk2c59n+HMjcck7hpIh3m2UB6dG1/mMMyCLmYJTR/XcSjWb/MLX c+DZdLvUCUCCpUJ26ZeFfX5xMWiNPeiFXxkDZgG9g3EoYGrSldc8j5C1EgY3UQ59jlip DKVg== X-Gm-Message-State: AOJu0YzgHxUILAdgupeTjQZHdmydpYH6GQkifHqtRm2K/h/8hyQ2uH1n 9TfZNG6hXOzWZbwDkDgbe6u64MwdaY6UH5bFbfDn9tONdGPb4Nf8ySzEh+4EzrRjl6QPh+jsx18 j X-Google-Smtp-Source: AGHT+IEoJb53bXVvb5Gi0iF9qZqsarg9CG4MfATrcj7oQ02oHBYqjagcwajf+AKPvrZpdhRvj2MvBQ== X-Received: by 2002:a17:907:360d:b0:a55:201f:75a with SMTP id bk13-20020a170907360d00b00a55201f075amr1301928ejc.33.1713198352533; Mon, 15 Apr 2024 09:25:52 -0700 (PDT) Received: from localhost (37-48-2-146.nat.epc.tmcz.cz. [37.48.2.146]) by smtp.gmail.com with ESMTPSA id ci23-20020a170907267700b00a52431b57e4sm3766497ejc.121.2024.04.15.09.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:25:51 -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 v2 5/6] selftests: forwarding: add wait_for_dev() helper Date: Mon, 15 Apr 2024 18:25:29 +0200 Message-ID: <20240415162530.3594670-6-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415162530.3594670-1-jiri@resnulli.us> References: <20240415162530.3594670-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 --- 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 254698c6ba56..e85b361dc85d 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -746,6 +746,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 up &> /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 Mon Apr 15 16:25: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: 13630298 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 1C0467FBA3 for ; Mon, 15 Apr 2024 16:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198359; cv=none; b=EiIcGX3RwKYtPrELlggTjjC+UDmW13MRpI0gyZCYYKJ/pPNQtYX+QJtkj2YNSNONx10l4/Hji7MSb/EmrOEgbYTTfgtpDdvdX3cZYaK5+lRNwig77slX15uiPiTUCuP/4ZHOgv2urQB+8CrlrhxacWCwZB3e5p+MnHeClvipl60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713198359; c=relaxed/simple; bh=5ugBvBh4+K8amR6hoy+zdFReyEtjtYmliBgN9MsbXBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BQy/cYMcYIhvIjcyqAz9HQ5fSzXZ44a42bU5YvxeR5GnOJZHxtJ7jIvaVJyaJjsZE14aqfqGbetaMEfC4fwV4PHgMt8ka4aEsbgX5krxGgcu4ahELYTV7pK/XZD9xvk/TcLkM0brZxYjvqBtffu/Z0u6PHaA0e1SGVgNrIyivU8= 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=bPMFfCOE; arc=none smtp.client-ip=209.85.208.51 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="bPMFfCOE" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5701f175201so258206a12.1 for ; Mon, 15 Apr 2024 09:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713198356; x=1713803156; 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=zUW8tLHX8n1G7xVxJNinYwceULd1UTqmr8OBZ77Ysok=; b=bPMFfCOEax0qGJ2g13Y1tI1CkEHVf5RGtMKDwRXr5FV6kbHnKqs5TS8o7ae1LnB55g KeLXCkjmMU4xPSI8inBmVhoGjySRbXgYMTlSULf7ZoB28fchEaYCuujXZsiTlu3HLCz+ QxScWtmjnmWEEXotdMonrotNGmePZqqA7W+RNZzzYBGF0L7fc+jAHU6za8w6I4V8whyM ULe5deg0f3wlexic55vJZDEfExTieCJDGTO1HZ9nVVTM1GEctTLViSLkAfEtr012kz6W /mGfvrrR4IF7bb89I5BSbBSazgJuvX5R+3LVVDlj1eo7TM7buECsbNt+blQl9nKPjreJ +uJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713198356; x=1713803156; 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=zUW8tLHX8n1G7xVxJNinYwceULd1UTqmr8OBZ77Ysok=; b=JmsFapdAdU2OWb66D/z1OTslHFAQpDmMfpDxOe6G9cF+VMYomwmGjOebTcpQB1CQTf 89p9mkLKhBgazOFLJTMCZs3bgPANyWQwYPL3kyRn2Ta6vSgpAZPZwhLKNSvIgn6GfBTw EH0N4tgNURO179DaWUyNqm1ez5VieK9lhfSH5HusyK772QWQRETAkHEhJiFeSZwE4h1/ qdjfknz2QW633+GyV905b9l9wgRW4BzNonoGpSVRMI7dM6wFSyb+8rgxi12NXEugZz1i 6ltU4ygmGkQUTdd9TVo1K+HNLb0szUu8pZVswbIB7nkoxorsTRhEX9DMsR6x+S9ovWeW s0OQ== X-Gm-Message-State: AOJu0YxxZHIaY9723vvsl9saevW5Utmy6xbnBy1FwmVg4z+ZrSi0io2t opz9QywK0T/vYCyJJdbp9uuMpoczUZXGJVj9Z1rvGiTQQ+jvsvK+8/hsHmuwEqY2WArJU257CLa Q X-Google-Smtp-Source: AGHT+IFNtsLqAU9tmWSaD5bdY1theU2QrGOEdud9Bbx/Tj+7R2Jyg6Afaj5VluKIYbgoUX1GMM0eMw== X-Received: by 2002:a50:cdd5:0:b0:56b:d1c2:9b42 with SMTP id h21-20020a50cdd5000000b0056bd1c29b42mr9640464edj.29.1713198356482; Mon, 15 Apr 2024 09:25:56 -0700 (PDT) Received: from localhost (37-48-2-146.nat.epc.tmcz.cz. [37.48.2.146]) by smtp.gmail.com with ESMTPSA id et5-20020a056402378500b005701eaa2023sm2224178edb.72.2024.04.15.09.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:25:56 -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 v2 6/6] selftests: virtio_net: add initial tests Date: Mon, 15 Apr 2024 18:25:30 +0200 Message-ID: <20240415162530.3594670-7-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240415162530.3594670-1-jiri@resnulli.us> References: <20240415162530.3594670-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 --- 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 | 127 ++++++++++++++++++ .../selftests/drivers/net/virtio_net/config | 2 + .../net/virtio_net/virtio_net_common.sh | 99 ++++++++++++++ 6 files changed, 245 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 5ba3fe6ac09c..510b2115dae0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23443,6 +23443,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 6dab886d6f7a..7873ad2f4800 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..b9047299b510 --- /dev/null +++ b/tools/testing/selftests/drivers/net/virtio_net/basic_features.sh @@ -0,0 +1,127 @@ +#!/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() +{ + 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 + + 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" + + 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 +} + +cleanup() +{ + pre_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 +} + +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 +}