From patchwork Wed Apr 17 16:45:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13633620 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10D16171070 for ; Wed, 17 Apr 2024 16:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372362; cv=none; b=aX3WmGuvw2RvYYeVkylvMbHEeRS4fbMbwhbXkReQsxdsKjbvacxFxw6bgOdZHCE9G3hbsyBS8xfGaGGEq19tdWujoT+jQys1oaWCejgaGGFxTmeKJ2LS2VYXbx/nre5BovpfMVgCL/8FmpMCxRTLsbEWQ+yIrCuh/R4Yj+bx+r4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372362; c=relaxed/simple; bh=Z1jeF7qulVW1TKjqXw6uzDM0QuhOgT0g9J8apBaAcXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZGU/263tua067hiOMAEMXoK2Nm5u//+QZKtI1YoHMI+9OgLCcqE6v+jSVeyuXHdawAhgFJI+7/uq/yRq2IH0Vg5eIxtQDPJQP83DkYkNDW5skg/dnUQN0O1BD33i5ov+S9eID+EHIUdUutOShbOOUPZlhlTS6qSdMRkC80qsIGo= 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=qmJAnksk; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="qmJAnksk" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-518a56cdc03so5377237e87.1 for ; Wed, 17 Apr 2024 09:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713372358; x=1713977158; 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=5ZJaM2/V0pnubO2BGW86GHU/5TxU4Qdi1H/FL0P6KP4=; b=qmJAnksk6ZPB9ue41zsOF0pIVAmIUa7i/7soZxGvi7h+XA+EaGL3fltM5dlsexCKCs 8csRNZM6pBlN3c9po0j57uiCiIOi+3AC80wv9kakC6TlyiTxnPgYZ0GBy3fPtcYQ1kvP jMNOAPuRZ73wdxi+74O79eht5yHHshvn1Z1veaZGGJwlzP+Hm4BqEuN7wqF4it1NOS3+ uxx4wXl88IL+XXl4FHMrThUOh+tXqnyR21Us1N7OVsNw5zO+l6c1lcFk6KqqCesgHWyd vpYDARM2IymtTYIG5VhfLeHoqy4+U8Qspkwfq1P7HesNWjOHRGRG/bXBb748IrC3z0Sh sWvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713372358; x=1713977158; 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=5ZJaM2/V0pnubO2BGW86GHU/5TxU4Qdi1H/FL0P6KP4=; b=aP4QA+ewaT8SQ6C5LIqy4bxO/WJ9cbqGh9fGoJ3dTxoMEOYIiEnHLqDIoYe6nurD7i nAwPlSQi/Noqwzq5PUonSJ4nece7OjFb77Q8oQc2EsmO3xIXgDR3/suqkyr3F+m7t/0y NbVnFb+jYW2suTfFJ8HspLSuHaAeafknmjezLIblwAeWOLZUvIh2fMcgTFBYKM/eficg 9Wz8+LO8SfQpXTK5D6HaNYdrQYQ+gi1oTNdLZ2PFbm4NWZ41Nwxc5uC13KXVkcHBfoIs T/ViA0NNAk72LL/qLilpBtgHHUQrUjaQXxlqwsqj2DVXd8k0b6WPShJtD+tjc1lv62hC c1Tg== X-Gm-Message-State: AOJu0YwGcrfudevzzUeaGIogTBo+YIKbrcrQ4Fql9y/pu0EgughphIbz TBUNRrneNWkLVY5PakQTwd/i+R8F+q5SFoyvrDf1f9JIyVon/d4ePGbfABScytVlTlODfMwv/8q D X-Google-Smtp-Source: AGHT+IFJRy4WGVC99gUa+NMpTN/n+ZnaXpnDdQSDf7b49mSyGVi+4F9pz0oQ6VVETvmFdL+w8DRctw== X-Received: by 2002:ac2:4906:0:b0:518:f2f8:edc6 with SMTP id n6-20020ac24906000000b00518f2f8edc6mr5025571lfi.63.1713372357840; Wed, 17 Apr 2024 09:45:57 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id h14-20020a1709070b0e00b00a518c69c4e3sm8261964ejl.23.2024.04.17.09.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:45:57 -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 v3 1/6] virtio: add debugfs infrastructure to allow to debug virtio features Date: Wed, 17 Apr 2024 18:45:49 +0200 Message-ID: <20240417164554.3651321-2-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417164554.3651321-1-jiri@resnulli.us> References: <20240417164554.3651321-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 --- 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 Wed Apr 17 16:45:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13633621 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.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 BE62317107F for ; Wed, 17 Apr 2024 16:46:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372364; cv=none; b=CVdYRh0sRHgHNr04zy3AxENzgYXu/Ye6ffeN5vMmCYkVQcOqIR1KglQX45K6FZfOaFcimmrv7rxiBJheUzx9vqQdXtb4hg/iX5WyQWAjNFNMRtKHBhiCVWF1D68ren55BQrR1vXKfDxY2SrHOrGaG2IL7GecHZcuMtoiObQ3nrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372364; c=relaxed/simple; bh=PcbDhpd6BnODpMOwqMAwtZG4dOefUKnbanAitXMinJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aqYNB5l/vd2Z8qW8cmYjV/SZPzZ9VEmi2lp3BfciysCOr+rPWpnV//4G4WAzjQe/6IOjmeT8JUM8JfOV7WxStCopDZ/WoLmR/6bj57jxRwUHGNjwobgAWY1xmFVut2d8bJKcUVPKUK+hqufGd5r3Znxwwph2PHM88T6led30yI4= 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=k1ujupkC; arc=none smtp.client-ip=209.85.208.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="k1ujupkC" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56c5d05128dso6453237a12.0 for ; Wed, 17 Apr 2024 09:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713372360; x=1713977160; 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=wxLxMgGy2MXM/swv+tfB8dexSsgyjH3G44Q6iWAtDNs=; b=k1ujupkCMYETr1+fzf4jbX0mz22faOD376f+2jAN3VLyUlJ/zv+u2JKXCztradFeyl jZYCAULq7LTrdqVNn2nrHjDaSxC/wSZZ0C2UJjJStL6owVIQleUl1Znq3gHdNCr9noFk sPyXvAGaaeO5LbrjldjBt2309LIWO7692P0+Mv6n1vu0c+99SxGHelt1jx8BahkG21Xh s+uEo5wEnGFlfEwtd71aXODfggmIq3baJbQuKwj9DP1h2N0Hfx1Sdhf7zB6kYkFvAvmc anujt1ibDMTFc5ULaK3eP9+BdMIVYaMmf4Xi3YtjpsLri2GuSdCr1bOaYiMY5MuMRd+8 zqBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713372360; x=1713977160; 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=wxLxMgGy2MXM/swv+tfB8dexSsgyjH3G44Q6iWAtDNs=; b=YhXuwj0NulnXcjB82YeXtFU7lNHWFRUcbz6nA1AUowqFsg5AHfUah3vV7/9QLZ9Ivt 0A2wNqO5JaBg5HirTVLaAb81boCEiIDfwFXr4hZkuFs5+/b7HkTKHTyuT+BvJlscR3FA Mn5WIWyFUafhNeHUp/Ew2yfb/5krPpw5oxet6HdWlyW7sxSyWrDFIPDatVIB5x/iZ1Xm grCto9sdE8Mu8Ind+CghdCVqGLKY7KKWtrklvtoe616cCOlE7Ev5xZwk1d21NsiW6h84 kR60CeX3MpBAoFCwBtlzxyHqByNLmyAGrverUnMAJNdBmg6pij7ztUjj7QKNC0DuL281 aDQQ== X-Gm-Message-State: AOJu0YxSJvLYdNbVYm0wZ6YuHhYjUejGqx0Tot1GkMf5Eoa20mcZTXDF /a6bsq9gvZ7fE0mKh1naux3umQLuyEbc0Cb3llkW45U7I5UBS13CLrYh2vQ7KTEY+HxmWLVMs0G F X-Google-Smtp-Source: AGHT+IFkVraWXUhT1L9urSkAmtQ2ZYqLl6CkHWvRgjNYeqKxUh5RvxFXQWBk/gVZZhnmdXBrETcE0Q== X-Received: by 2002:a50:9f43:0:b0:570:5215:d29c with SMTP id b61-20020a509f43000000b005705215d29cmr112439edf.4.1713372359844; Wed, 17 Apr 2024 09:45:59 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id t6-20020a056402020600b0057030326144sm3381448edv.47.2024.04.17.09.45.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:45: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 v3 2/6] selftests: forwarding: move couple of initial check to the beginning Date: Wed, 17 Apr 2024 18:45:50 +0200 Message-ID: <20240417164554.3651321-3-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417164554.3651321-1-jiri@resnulli.us> References: <20240417164554.3651321-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 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 7913c6ee418d..2e7695b94b6b 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 @@ -241,11 +251,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 Wed Apr 17 16:45:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13633622 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 3CA1B171066 for ; Wed, 17 Apr 2024 16:46:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372365; cv=none; b=a/AGdWg36th6Y+bSIPrseWBpVCuVVpV2d5IR2kAHj1Zxykkx37JPlafYpGt0+lZtYXFieuRxJWSS983M0uJ2g4UkQO95z4e/6esSro+EIItS5d2pmLee0s5PxGfrdp6SCDvR215z7LakaiqY2hDPI9bSJkWNpV8Io0jWL86fxcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372365; c=relaxed/simple; bh=ywpHm7bmooFCjvprfvVd/Cbc8wvTaPUxL+QMQivo5Q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ly4kEs82Vk7KxM40QZa2D4m2M6Lt444LAk+IreZarYlzr+MGOvMaQ8+6G3hgeTTYFOrPYDbZCcu2N8Wpv7iCrFDY0H1hQUcqBcpiZCpogF7/DLGP20Zy2sOM4EJcmg87KHJsikocMeWn45sNr3tcCbPmgvdiZhyR9M+S40WMpgg= 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=SoRJQLjY; arc=none smtp.client-ip=209.85.208.41 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="SoRJQLjY" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-56e477db7fbso9655398a12.3 for ; Wed, 17 Apr 2024 09:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713372361; x=1713977161; 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=lwpy2d8VdZTGzMFmGo4R2LG9kH0oGH0sJNWRTRWY9s0=; b=SoRJQLjYMnLOwnD4iGCQyDRUrUv5zpGsh0Kv/DhIsjbQHJ4+dOFqmpOhSnsUCZffem X2zq0jddW9OyOEwcQ6bdtVvTgKBZmqxMJm0pH2hV6OzTeeFhlmP/PlZ8G8VfWcwfEKCw Ydx9a8XXOl9ryjteP0HCFgtuBHjohd8Sy9qYtY/VmpPKn/bRQvyOU6Y5ETseWVALX6rf c0mNbjmWGdx/36z25OXYQhjJ4yB7PGYealfEFuIptsDQJt9jg316N4GGHBc59WqUpFSV GJ7g2R3gPThK5pH4V2dWjB8RbUQ4og/FwFY8QRVZD1XTOhjEHiSnyUmbqj5CWU+c/1HL XnFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713372361; x=1713977161; 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=lwpy2d8VdZTGzMFmGo4R2LG9kH0oGH0sJNWRTRWY9s0=; b=iAbqui2ksHX8U0VsLj6s28cx6prdgOvDXBYPIwWuNK+BFZt67K6zLRWqKruO8byhFq wG9nDyz8DOYKQ7S8kj1kzxAAUkLSHpzjLK9/t6HgyRkR8VY2MZnPPxJcqBZxJhAWeMLb gkwSXp2Rz4YctcQmzsF5RzKX/a5TJM2K2FonDzIFrtEIdXslXUgTsOx9QrkxhG+l1JHx QNyNvemnwqMJCo3J5uZldgoglZvQI6fVEOoroWnSmUoCCxypOeBR5/ldFpzRXiQM83rK 0s7G4SdLDZxAIlzqNKto5A3Xow1/qqv4QFUhadONql459e3dvNgE8aEbFDyLd76wRy6v tQmw== X-Gm-Message-State: AOJu0YzJyTmN+Mi6fWN36hKlQYGinpAJ2Qp1RbvHG2lcj67zrLxp7lOG eKfrMfcsaEREM6lCkqQQA5djscb3KfpgapZm3JwtXZOsR/ZjkE5Xz8P0ABqNnEqgDGfgr0fsJFF k X-Google-Smtp-Source: AGHT+IG3Me+F0oYiJTCQwHguq194JAhZMF1Uoe5DU2QB6YsaeleSbRyFK+AQwlYwjcC3c8OqOgA3VQ== X-Received: by 2002:a50:d655:0:b0:56e:64a:2a47 with SMTP id c21-20020a50d655000000b0056e064a2a47mr90004edj.42.1713372361527; Wed, 17 Apr 2024 09:46:01 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id b73-20020a509f4f000000b005705e7ee65esm876158edf.56.2024.04.17.09.46.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:46:01 -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 v3 3/6] selftests: forwarding: add ability to assemble NETIFS array by driver name Date: Wed, 17 Apr 2024 18:45:51 +0200 Message-ID: <20240417164554.3651321-4-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417164554.3651321-1-jiri@resnulli.us> References: <20240417164554.3651321-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 2e7695b94b6b..b3fd0f052d71 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 Wed Apr 17 16:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13633623 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 2430817164F for ; Wed, 17 Apr 2024 16:46:05 +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=1713372366; cv=none; b=ldOgZYmG5BEJ70eABr0He6HQZrrS3CRCVWPDLPu6qPS1wEx9GEKypIpkNqh9s6hdONk9PnuxrssQsszLeKDxiZnjsNXe1zrnf32nNXZpLbXCeOOzfpBtJG+4kh0VFuYYmj40e5QuXCzgvjCSgj9bxJ6I2j5dCLvDGIMGREI5mdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372366; c=relaxed/simple; bh=NArpel64x6HJ2BR6Xpz3gBx1vpaFxO5gSoTpsKJXupk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R95u/zh8JJt+x2yiML+PoTXRdYa9BQl+ceU3LhfFS+IpUnH7b3dWWcTMo47AM8oix9U8D9FZxkYYQFB+E2wuLDs5UiuN3tLU9y4/7z3w0WQDwgIOdvWpuvqG+/+C4CKmAM2uvTVyvBOEoYZq81h3c78s0i3b+RoYQHLbg6QK+Ww= 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=fGy5HfPH; 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="fGy5HfPH" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a5568bef315so14495466b.1 for ; Wed, 17 Apr 2024 09:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713372363; x=1713977163; 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=7iDSoNx4io0wz5kFgpirLfiENKR8M2isWO5Sk2gRu9I=; b=fGy5HfPH1M9w1lUQ8nnCCr5yPAgRAliYDYnHjedxz5yeRSUoYJ+rFx1Q1gcpxEwWBI W9nN9tuZHX9KklOIqeQljYfz3Mx/gUOoLKX+cbQ0CxzSp3UeimtD/ddstPvGyTd6o50M oN7YD4a3SdPloa5fk+qWqsvBeKHAi3O9NGI96Oc/AOd3k+RqGIjOQZsA57mu1r3dkpK7 nxyMpEQG6PdjCMQy1Ha5ypsQ651FWym0uyrxownmBw/AvCOonSUPn62kv2yT3TPKO5iC IoKM9Z/ru8ipG3olMSenqgnoJMTwQSFMx4G3NbHtx20Spcy3qzP3JeDzf8zOy/fKnVIV yBQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713372363; x=1713977163; 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=7iDSoNx4io0wz5kFgpirLfiENKR8M2isWO5Sk2gRu9I=; b=lndOT8Txptwy+ETFOH68/u7tOSD40N1m+XtT9TZc/VYiHkIEOo8OELQ5oawhA5iyBb V3WLQI2s84/7+cIFCwSSDOmGYAiKJru1l3PY7dJHDKZNxeJXKfOLWFZgXQinxT6sntDF 67FarihFZoCklsRTiIrZKicZHydc2wom/fzGyRQQ1WSlKbbiKZP4Lqown/4nfzuMWoc+ tLwpLZXIdzh7OvfTrJFHSgZtwmHGKk2I17FpycMjIniNPJ2X4wvh178fEHuDcYvtaRCt X9gcxMqE91KCU4cBEgvLETwSBX9JzbkUObYSRAGU0BvZQoyR0ZWcohh+r0NQU7iJf19/ j8MQ== X-Gm-Message-State: AOJu0Yw881GRGjXoMXmWl7D5CMHkUZyafYnf3eRzDiXC8uIYIVgfxKMZ C6jJZVkaeEConD0ZHaR3sJbf2auPiNz+KmHoHML2QjAcDB6g63Ow6Z4qLtWOQxTclMtQfy1yOPY i X-Google-Smtp-Source: AGHT+IHZlMqMIGtxRS4VPRipmPp6ctstGqWnjPeHHS6MRuX7c9jXyizMoNyEw4tsWSDIIz4pcqv8hg== X-Received: by 2002:a17:907:985:b0:a51:b49e:473e with SMTP id bf5-20020a170907098500b00a51b49e473emr5476534ejc.19.1713372363586; Wed, 17 Apr 2024 09:46:03 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id ox2-20020a170907100200b00a522bef9f06sm7720607ejb.181.2024.04.17.09.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:46:02 -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 v3 4/6] selftests: forwarding: add check_driver() helper Date: Wed, 17 Apr 2024 18:45:52 +0200 Message-ID: <20240417164554.3651321-5-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417164554.3651321-1-jiri@resnulli.us> References: <20240417164554.3651321-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 b3fd0f052d71..edaec12c0575 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -290,6 +290,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 Wed Apr 17 16:45:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13633624 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 24E2217107E for ; Wed, 17 Apr 2024 16:46:10 +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=1713372371; cv=none; b=LYzNqRSovEWSCkRfuDRUztFoaXK3Tdim/Vr9MUsl/iZfKv9/Qh4E/UXVaMtk/5WEoAh0x2xdndhISyf8Z+eEkELpgJltUJwAidkUg0L3N0TDAt4L2fD4LmKvqXfInHi1bx5wAhjh9wFHybiuJxhefR6YSnJwx892ciATgiq04Ns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372371; c=relaxed/simple; bh=cYWBkuVz2OqTjZZvkAAucx9ew5P7UCkfTJr6g5UPk0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y/b096RdkHBp4+VS+KUwat2ueoRjdmVJFCqPyg0K0pXtMvza1z+/hrp5xdV+byC+x2Udrgz9DfHYct0dYPyVAJ+taBD46O/1ngQ/UVrS0C0qVj72deUNvk/m1dwRm9h3zrFviHDkTpVWKxAY25hF/qaNFEipW8E6N6TGmUsZYh4= 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=afnkKwPE; 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="afnkKwPE" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-565c6cf4819so1882227a12.1 for ; Wed, 17 Apr 2024 09:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713372368; x=1713977168; 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=REEmA/tIzrZxHwQ+eJVrb/dkT1DH8bvTei1p22/X+z0=; b=afnkKwPEev2KmLa9k5V7222k3hPq1MU5DupicMJJSPG4YGEqiamMi9i/IPbGDJgRZh 0rl1dpIn5qs8FijXKfKPISP6aIe8m1NckHUnM3c3nUh4IMfp6lIOo2cA3MS6V7W4diUz w03FIHUIYcXUjj9odEzeF/hf1PoSiOpJUP30QC3E5DzAMleDs0RpErghGeTlyPzw1Wxk SDQrQ4JOMJFbq9yMCcOGCiAFRPpDzg2W4e5e6a0JrN5X6A6uFbhkmAlCLsKysoJM4UX6 QtZgnHEH/wLRMKXaNw6aRH47DL1QjpmgyXepKnnKnKCVJ1tZpIJQ2r5mZNo/GkJgp6K7 FdMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713372368; x=1713977168; 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=REEmA/tIzrZxHwQ+eJVrb/dkT1DH8bvTei1p22/X+z0=; b=eAkol2c9LWXKkDwKekI83Ockz/1x0DQ2t8wL3IA+5l7dMuE+jTtVMBvDcyv6qwLR9j JL0h8CU2zRSwELnqX6n3U7PUPI/urahd0rB39fbdvcAvinTb6Mx32ucS0AYlDgpHVMyJ hA4E5fYdiIKHt/XwvAJAQzmb6FY8k0pcdmGAe7SZeNYV7qDxpEjO5eNHbrIqCHxsYOMS iXDbAYMj8xVvTnNYFPxojgWwqR/NMD2sjwBFl8rM+89vj6DqaKuEk4bevL4Na8k3dLK5 RRkY1BEsZ50ak05MgvoESTobpKCKtMyt3f3IN1FCDZz62DspcjEmM8qXMzFHZPfatc6z bpvQ== X-Gm-Message-State: AOJu0YzyVc+d/X8IHzdMhNoimwgKoOX8EiLrXOVc9hbNmtP3Uj2mBJbo aHgddTYSmEXzdF68EvhOZtykN2LBOQ0lRxCuPwO/sQussdngK8rkBcl5Vlpru8oAyLSUSkJQ5km y X-Google-Smtp-Source: AGHT+IGPBnih1hbsQxAuPoauf1NR1vbfkoyGDLPTYY+zGlT9YkwztfAahhP8SZeYG4YKDO26lfsOCA== X-Received: by 2002:a17:906:554:b0:a52:30d4:20e6 with SMTP id k20-20020a170906055400b00a5230d420e6mr4536310eja.10.1713372368374; Wed, 17 Apr 2024 09:46:08 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id l9-20020a1709066b8900b00a526a99ccecsm4161102ejr.42.2024.04.17.09.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:46:07 -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 v3 5/6] selftests: forwarding: add wait_for_dev() helper Date: Wed, 17 Apr 2024 18:45:53 +0200 Message-ID: <20240417164554.3651321-6-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417164554.3651321-1-jiri@resnulli.us> References: <20240417164554.3651321-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 edaec12c0575..41c0b0ed430b 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -745,6 +745,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 Wed Apr 17 16:45:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13633625 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 D40ED17166A for ; Wed, 17 Apr 2024 16:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372373; cv=none; b=qfHv/EIG6pY0y2y4MmQiMMwRPuaXoZZBiotQnvJ4ejjr/LSPe1QsL5lWG8m6yHuNa7xoDDsqq9rUjKJmVQphqRHzCqN+NKyn62vMGlwgHOVW4vAL8b9aVjI+YFppLNu7MSyO2wlNAARNg/7CK1wBPco8QoezC18+XKBdLgnWLNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372373; c=relaxed/simple; bh=0H/vjaQNmYH3GF4YhFbd93FGwox9U+b0fRkfa5doB5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lFUhJ8VvHyBn7B4cFraVOI/Nvk458sow8cBUWyMlTg7Lp+RO9yeMngLpblOreGbp2+ITyDSnvc0cmLfr+Mhyt8W9IZvAQYQ8zrF3mbCs5oHT3S0OxmEEWEsMolOKGZul1Xr+M/Af7D0cuwSdTcy7b1fQQ2LgtprQZVHKZPXPl2A= 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=aYGEBgqg; arc=none smtp.client-ip=209.85.218.48 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="aYGEBgqg" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a555b203587so105156566b.3 for ; Wed, 17 Apr 2024 09:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713372370; x=1713977170; 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=6GseBsN1q0bdHXbiUKHMINZDqk1bayHyPFFMBfv8P5c=; b=aYGEBgqgPcOMVDsq22eGqjWncwrWkO3Ah8yjKJ2J5FeD7JZ6gkIce3Nau+s0w/iOaA QTUsdmOxLt6V3MVCmHLNfwkb5STeQpJRxYce9ye4Tcg7uZrHf9XQ6i8guFlfx870PIh1 3RetC422TZSiFQ8sIahXK7MVON+ILkw3Bpbl3L9+RKItww6/4gtZezAOmoEddokE5gCc lp/EG2BzybXoCt6UtiBuEPj8gBG4HAdf6Q37FZvA+eRA6bm451SBFxwtzYuQKw640M/L FPmHu6d97CgsspVAvR18gztirwOp1VLmpmhbDSNcO+zRsb5LfeL4tqufxVg/oj/8Pne9 hFvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713372370; x=1713977170; 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=6GseBsN1q0bdHXbiUKHMINZDqk1bayHyPFFMBfv8P5c=; b=ucxeb/kI+LkWuA1JzafeUydh/6DmnvIvHTfOMDpu1Sj6GkexwKn8tgcx/k9W+XI7XN BT7gwhVqmSCfsj86TGzDWMtVVS8BfEXIOcLeTQLbPSyDPnOTbRWpasDIIIDo5d5hxuxj z/OmfYBaeJvt+YHQ7DCxS8vn7sF+Z/PL+3TniVTA6SVKG5QSUa8PPLtZrDnesCZgSR9E gSFTH2aQ1lI9hHVnuE78Km2LzX6YDR6k0UpidP6+4h2gInAoDvSkWh4sx/0ZarbA/kKx 9PUh8TnCSgVpYYTjmbgzUi/5c4zALM2w5r2ap9HElt3IdlsdmE07evHV+7UsR5EZ6r8N lhHA== X-Gm-Message-State: AOJu0Yz0AoEOmHEJDHYGxnHYDMfiXk+TxhiMG5G77kz8asmF8wsMdEO9 D6PgU+lUG5NNJ2CSqmmEw3MEDMk2D+cpwJCyHpZbC/smVV60XBAjOem2FeKDW2fPYAZGM2f0TYw P X-Google-Smtp-Source: AGHT+IE4TduzrmMU67mJ9eaY8RMcPBvKsaxFK5cqcv2dr69+laIDIKIa2YTJMVf7Btwo7Vuks2Iqgw== X-Received: by 2002:a17:906:19d3:b0:a46:cef3:4aba with SMTP id h19-20020a17090619d300b00a46cef34abamr38360ejd.75.1713372370171; Wed, 17 Apr 2024 09:46:10 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id ht8-20020a170907608800b00a525669000csm5474091ejc.154.2024.04.17.09.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:46:09 -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 v3 6/6] selftests: virtio_net: add initial tests Date: Wed, 17 Apr 2024 18:45:54 +0200 Message-ID: <20240417164554.3651321-7-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417164554.3651321-1-jiri@resnulli.us> References: <20240417164554.3651321-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 --- 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 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..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 +}