From patchwork Fri Apr 12 15:13:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13627977 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 55CCA1487E8 for ; Fri, 12 Apr 2024 15:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934805; cv=none; b=uLDD74GNL23ZR+CehRaHLDJo5pAeiAbsvxsQceXHxufP0ZbR6kZU13GQ9hEBPkeJ85blHa5tWp4V6KIXYQYUH7xjl2vd4Om3RcrGsPg7iUWAY0/wd3RzjSxCJj6eyT5ugbVAWRzTHyUkffgoZbegMjdXrewIjf8JcwnL4yJClg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934805; c=relaxed/simple; bh=H3pjtAzG8pQcFoMfgL2Fil38d0Ryh7wHYYt0AdNSf3U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ovOf72nRREBfVghOqn0nlJFiOpGMijFq05dPB3B6tOcf9s3ZaexWw8/8zsWYIo7Vsrs1L2KofnPddw7axHz77N4iraJpGwV65bnFsLoZoGaXRKMYbTYfASTPvFI9kxH6QDfhKoN4z06oINhZjuHBYQggW4C2lX2Ydvv+MMkKrq8= 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=h82lNE8z; arc=none smtp.client-ip=209.85.208.180 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="h82lNE8z" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2d886f17740so21741691fa.1 for ; Fri, 12 Apr 2024 08:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1712934801; x=1713539601; 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=h82lNE8zQbcNKRyMQamPJefpqlUpLW+dQIB2ntzRXsiifBo2IKA+3pxpJYDlwjLzVy d1n7/aQ3DU1S64eFnU56lpittnyIKdp9yqi3GCpw1apVMoWxeOkFJo3AxCHvAT9ACGQ2 YpSEbeimb+QWFv9A66Y8c/SJArJVH7k/dNgbmbqnxyPVKJE5jcOShZU5AkSupq1ruy6f tyW/RhhsejGjUPHP/thHymSy5fCwtAH1es7Uw2XUwfNhvcRuvoBU3JkOrEFHYLz2zPnG 0oQmxbnP6OWI1vFmDlUWghDgypEB0MCbzpvjq+eJP/Y98f1Ginw9QbGseCcecakq0Z6j Zxkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712934801; x=1713539601; 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=kMIfpqxpCU6wsgLcMGr5JIHnWR7WmwwIG98E/zAXlXeKrxv3BR48BT/VL8I135ZfNt LMguoKpJuIVPl6W5qZ5s/wmplKaAykaB+09djal5Zzxt6BTkCrtazk9hGN8cpybm+dkF ID7dp1zYcoqTKKcKdyQIDLPgFHPsUSHo+hI9jee476wKR77YLYupZE7UgMKb/9reHx4W wKceXrYNLjRKh4dlYY5xMrRmtwvkKJrhnHjNCVJgmH1PpiC8AjXnLlN7jfrftq3Xm7ym m4ZyEptzBsXPkYZnIJzAOu+ko96qaUzN2R0A7Ygtn3k6jmf9geb4Te4TNn3hheRXEdWs JvKg== X-Gm-Message-State: AOJu0Ywv/vEkJUC82o5/JmBrgqQnXnpS0eN9xt08RyD9AvWoS1/hTDL2 HjHXJg81m/ZFZ1kRNHznGUHOLV7pH3MsDJcRsH5WvOf44tI7EZzRHRxnQPKx+82J2RT1m367bpW f X-Google-Smtp-Source: AGHT+IF5xmjOkt+mt8whN9TEMlmNYz0RdgWHOIS/bCJOWvnRIOASdyC/CnLVmXdaKFeEDcTznXuFTg== X-Received: by 2002:a2e:8783:0:b0:2d8:bda5:2d81 with SMTP id n3-20020a2e8783000000b002d8bda52d81mr1846865lji.19.1712934801088; Fri, 12 Apr 2024 08:13:21 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id n9-20020a05651c000900b002d2697570fcsm526278lja.93.2024.04.12.08.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 08:13:20 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, parav@nvidia.com, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com, vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com, virtualization@lists.linux.dev Subject: [patch net-next 1/6] virtio: add debugfs infrastructure to allow to debug virtio features Date: Fri, 12 Apr 2024 17:13:09 +0200 Message-ID: <20240412151314.3365034-2-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412151314.3365034-1-jiri@resnulli.us> References: <20240412151314.3365034-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 Fri Apr 12 15:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13627978 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 816AE1487CC for ; Fri, 12 Apr 2024 15:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934807; cv=none; b=YPcG0Lspw5FqMwXwBAOepbAxNA1EhX9ubUwvC2zM3iMgV6dZY1BN+K3WMEzjjrQinno+rp0xLdUWnW48A9hR5rIrTci687dudZhQy94XlAfOa5hC2DVLefRJo87zXBK4ZY7oSakyMQO9uKEM/dosYjPHxQUBEstmFf3dZmThVBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934807; c=relaxed/simple; bh=j2PzpeP++wEtCimj6PizZGaulOFqRwTLU39GbwROnR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gOCnrkWR9vOuIzMNXJs+ngsGjFFqpUg3LiFzyxweWToUYxO1OpjBihkxzxn4cGmBqqR2yrs9f3sd/vIyOb2bXx028wMvyE1QaAjoS19N/1fcJAL1raeD8f8stI4Nr+zWUvc0maWPqBHq8bRAieeS8x+AzQSxTS9m/QbdIWvI2Sg= 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=m3KqIfN1; arc=none smtp.client-ip=209.85.208.176 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="m3KqIfN1" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2da0b3f7ad2so10480681fa.2 for ; Fri, 12 Apr 2024 08:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1712934804; x=1713539604; 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=m3KqIfN11/Q9mhKJJZIkGmf+SHpvlvnYZk4EbJ0z8hhFdsck+TYQOKKRs+sPdaCz5G lZAaz74K9SJgFLgmOW+2oqy7v7f44h0BxXUO4FMI7EfOqCqHb0wLPBVdZJRtmZ26u4Zn kuBEYmPWB/Z1D6Y5w1LQ561+pVZXY2l0g4ufcoCcmysv5pBbm74AFaz1xDxdJuzsf5KP WYSrieVJLID5oNLmP7pMijE/IQhr3epmTn4qDnmlZdV9H43WxEiDLAwaadX5TdHhVNC9 kc/3jurx7S50IfehTHub80Kmn0Xf33FKraplK7qG2twBmeUxclL3UqfxcLEmcenWqDax 2YkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712934804; x=1713539604; 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=NMRBtorpQpwZHoF+iF+XenVrCX08EsicoC/4FtH9a6+iTE0f9XtpQ0+X2vmmT5Rf+6 zDcCNLQqXq1rrRRtdVEwlJ9A1PY9zWXlBELFhkLXgubLdE8E4iCJb2M6ANpWPomcqi5d B5TOdbKuhMydFQSuCF1M9qsqOfM6qL8IUu2FTRUkZF5F+Y9U28FDMZWSIBMM52RAyEwm ylypYiYjtJnyLL/y+QuKkRjCMj2QxS1l9udzoo0vvnNtM7HMV6BA1HPz49GXdGKAc1/9 fZP8ZNcv4zxpM/3mVPJ206zo+9C011u3KtlG41tX3U6JKmBMH5+PcNpEJdsYcGXuLHwE BAsw== X-Gm-Message-State: AOJu0YymhrWViI+bX9ujbtdwN64wcSAbEVQzZ13PtPghAGFA0zxIjTS1 BKeDpauaFrPCtgyJn2SQYmTCQk6H1/HLi/OzULYZVRqIkm5PHzBhsCDMuGj2xg2NUmesm1hjAlu V X-Google-Smtp-Source: AGHT+IHFdKzw5NH68XHyEiCdbiwMKDRkLvCxllBdJm1UClw0RzjlT/6YxQPbu8l9bViiRw+3UWrtAg== X-Received: by 2002:a05:651c:2124:b0:2d8:3a46:8ab6 with SMTP id a36-20020a05651c212400b002d83a468ab6mr1894565ljq.17.1712934803774; Fri, 12 Apr 2024 08:13:23 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id b43-20020a05651c0b2b00b002d82bbf7862sm528050ljr.25.2024.04.12.08.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 08:13:23 -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 2/6] selftests: forwarding: move couple of initial check to the beginning Date: Fri, 12 Apr 2024 17:13:10 +0200 Message-ID: <20240412151314.3365034-3-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412151314.3365034-1-jiri@resnulli.us> References: <20240412151314.3365034-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 Fri Apr 12 15:13:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13627979 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 D767514A4EE for ; Fri, 12 Apr 2024 15:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934810; cv=none; b=U6GjRSoYmIn5Z0jSdF/qNmqypi+cnOQpWaf84iFIVOygoZpilBH6LHd0G71H5NzlivOYkw2VoZWRZkKRjjp92Y/3vCMBGHw9bYLbuxuI8v4cckLdrorOPIu6X9Ho835Bv2deQ4tiSD54e563VnGmVbBEhjYOm62XPhUDycpfXoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934810; c=relaxed/simple; bh=79Zpumn/yTRAxDTkzsf7dlFSKMtuRYIWNxG+eUi60Jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WvbajNTFfrTASsFXXsDeGpwIGe226bfJgQMqqvSLMRbuq2VlYRH9JIF2eS7daRQJeNLlELjIYzW3j+hP6yWA0JwBZiFrEN3EJUHCQXirCq7rr3Wna9vTYho1njdCUlyV+1gXmMlkz50uNmfMz/0KdCMdrPQNJoIezgw2UtDfiKc= 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=MU0r2yvm; arc=none smtp.client-ip=209.85.208.182 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="MU0r2yvm" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d47a92cfefso11865541fa.1 for ; Fri, 12 Apr 2024 08:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1712934807; x=1713539607; 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=nSc1knfmuuKWVaRerlL6rWyI43/6CD3p6tfuDkKbsf0=; b=MU0r2yvmnbAeNNUm9dMW0CKdRI5C8QS9AjuOGF5pV28miwiXKSc6bHBwUFptbakvno q+sM7RRB4NZxOfUDOyuK/TbStg1ZjIa6Vg+UvIkzzySK02JXDbfkBJnH0OjoloeI7N77 fNrJB0NyRqcaj8UltT2rImcaNYN9FAMgOnj1a3d4ruv/GyUQWObvUpaCAEAqqVvRmS5B HRlTYr9vKm3fKXufkcFf/sxAtYkiyYWAObA1PBf5rPzSOMO1V+JVdLq347CmuZ5P23hs abyVsCDCRI+mxKh1WK6e0gzB7tAGFAPD1LfNo4Y82fYB9ivVThKP6vcgrw7ea6yVJn6v P3sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712934807; x=1713539607; 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=nSc1knfmuuKWVaRerlL6rWyI43/6CD3p6tfuDkKbsf0=; b=sfrO50bONnkZx+wYUaaDnuCm4UDTrRPWi/2LPDPRwT01RqAr8myy1Zsp2qcNL4frmp eBj0NMpNzFNVAvDi6zOj7Z1foqqh0xMCFnssKG2xDFwJyuPEyW7g5vIvjj/Z9fU4Ho+j RuzaZZVHx5umOeLfBgwtbD+Q/K76PBYu5kARxeoEllduWMZb4oVfXEDHKeCLk/7Q/Q4i i2O+8N+Ovy6y3gkWoacIW1/avV24sHH6xvhj/7gHG+BcYT8EAzYIl3VXQa4BxTrccer/ 5P8SCZH1JiKwPxF/wKAHKYC77y63WG/MxxwCAZT3HcC2CdF5M0cAOFKiNiDjY302cCBM S5Nw== X-Gm-Message-State: AOJu0Yx/mo5PtDdoJF//1AZuim2sWzs/oJoNQUuJBQ8vKEmdB/qE8hsm sqa0AHdpCf+L2QqkIrgRPv9yTd1nohaXornbfK9NH5q/Xh3qs4sYJM4z2uXasmf52RLx5t6Zmrn r X-Google-Smtp-Source: AGHT+IG6s9o/5tFXaogDJI5ZYHJzmyIXl+4HeYCIRLyWTTBODB8qVVhF87Iesf1NL4Tbyh0b4rfvPA== X-Received: by 2002:a05:651c:620:b0:2d9:f68a:d82c with SMTP id k32-20020a05651c062000b002d9f68ad82cmr1699020lje.41.1712934806885; Fri, 12 Apr 2024 08:13:26 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id u15-20020a05651c140f00b002d834cb0400sm546450lje.17.2024.04.12.08.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 08:13:26 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, parav@nvidia.com, mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, shuah@kernel.org, petrm@nvidia.com, liuhangbin@gmail.com, vladimir.oltean@nxp.com, bpoirier@nvidia.com, idosch@nvidia.com, virtualization@lists.linux.dev Subject: [patch net-next 3/6] selftests: forwarding: add ability to assemble NETIFS array by driver name Date: Fri, 12 Apr 2024 17:13:11 +0200 Message-ID: <20240412151314.3365034-4-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412151314.3365034-1-jiri@resnulli.us> References: <20240412151314.3365034-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 --- 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..06633518b3aa 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -55,6 +55,9 @@ declare -A NETIFS=( : "${NETIF_CREATE:=yes}" : "${NETIF_TYPE:=veth}" +# Whether to find netdevice according to the specified driver. +: "${NETIF_FIND_DRIVER:=}" + # Constants for ping tests: # How many packets should be sent. : "${PING_COUNT:=10}" @@ -94,6 +97,42 @@ 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 -p link show | jq -e -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 +} + +if [[ ! -z $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 Fri Apr 12 15:13:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13627980 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCA5914C5BF for ; Fri, 12 Apr 2024 15:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934813; cv=none; b=kuJuwaAoOt45m6539C624P0cH2QFeAFaPHas5h/cMqCGCF764uBlFLmTTIf2O2UjR9ichdMEHroci1X7+FcfeUDpocrsuQ2choWCn5Fs24WBYQHSOaxCvC107bbNY/mCxhx7YAwzz8g8NxRiuM2AjX+TvIlNktVTal5Mm7YaaeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934813; c=relaxed/simple; bh=QbEpVnMQr5FleQ181phGUo98xW1xM6Rbox9biz8EFFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GXMJ8UfE5WS/ysb1+MtuVoNzOgeI9HfKc4qn6LLfZva6/lWVeS7MesFgDLUAx/k5StzkyuRTnCWcOaxF1iR1Zk2mG2GbFfdutxt1bruZTXnu6zxUWwJTxm2W4WEDo8ISS8A3HCISRBTjWTCIwoG/22PaQLjJVxJ/a6qg8nOjo9Q= 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=AtS9ua0p; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="AtS9ua0p" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-516cdb21b34so1295336e87.1 for ; Fri, 12 Apr 2024 08:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1712934810; x=1713539610; 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=yRzBFs7nWe4OmdpxKyecIOsORdsbkwk80rMj+0LzMLM=; b=AtS9ua0pbd5zMq41JGEPg+D6WmayrRaLeTGoJMqqrvCk0GHdrUU+8uz0jmk5by70Y/ sEB/lzMJL6OJyWEizS+G/R2tGN5IgLA8EdlDdSy7qpOykX315LIYVu+2q6Fg3eqlyp7c nR2xO/whVatlU6Me7n60MxARfH7nY8i9J8+4iPQpldTNrbESG6PCx3hguaVwLzZsKVlF lCQpJr1ZQTLiNYfwsWInmtIei1TkyoOve6LHdy0rb+IgeSs1/xwAiFkhAm+vFV6Lsj/E PZkGvH6iBRw7WKzHBBsqgHMUCXYTsA84M9GDzcjhhB5MC3KcxBEzv+AMiU60QuGxUaND el0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712934810; x=1713539610; 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=yRzBFs7nWe4OmdpxKyecIOsORdsbkwk80rMj+0LzMLM=; b=Bc8yhG8VPfUowPXWa2esiea+/7WGqczHkeXNvNeQqBGdDlwtOQTdwFQYarvwWQfL23 LAjItcD5hJ3/QHDBrRReWYyMxLDYx9ka+4CHBRav8iJYkjzCqLFGDByKw5YUr8douNDl twAb6qioHlbRf6jfNc46H1+fLwkg7Vgr3szM2iXqYYXjS6oB3DVdrrcig1y0C219ubiG v0gF7NB3NkryYsAWstZ3Ci6sP88SpNDc6q1vJK7vwWGvwUwIr07Zx405CN3g25U3Rudj ggr+nXsTlRZJd+5n061BSsSWcI+/e8gIYs3uluNH4q0XjKo0LlwGGfuO3F1UgVcM/I8M c+TQ== X-Gm-Message-State: AOJu0Yyht72vwUEMyOX8zkUHltXmAceoW/Uy/ownbjHyjVoOfxg4a3jX CzsElxMvnQAodccqS6ov3n2xNguvKwMoHhEhfBSflcqDcZxKA0tVwD9GabKngY5nEkVbGUoyjJF O X-Google-Smtp-Source: AGHT+IHjo69PdEvYDcnQbXnMCraCmXWHrBnaH7QnmydQNhJdAHZPMhXzQ804UbbE+RnVcalObrgcHA== X-Received: by 2002:a2e:b8c4:0:b0:2d8:10d3:1a0b with SMTP id s4-20020a2eb8c4000000b002d810d31a0bmr2023490ljp.39.1712934809842; Fri, 12 Apr 2024 08:13:29 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id k8-20020a05651c0a0800b002d85452f55csm536220ljq.47.2024.04.12.08.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 08:13:29 -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 4/6] selftests: forwarding: add check_driver() helper Date: Fri, 12 Apr 2024 17:13:12 +0200 Message-ID: <20240412151314.3365034-5-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412151314.3365034-1-jiri@resnulli.us> References: <20240412151314.3365034-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 06633518b3aa..959183b516ce 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 Fri Apr 12 15:13:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13627981 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.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 6662514900B for ; Fri, 12 Apr 2024 15:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934815; cv=none; b=PViOs5jRfD1q9n1hOPC4JekS0+rqec2XRXKkQHfHJS4UDkxPB6W0XFaC938bxlGZlsvpEK/2M3agmfj+hLp4A9Sz+5ZFqLc6kHm5kPCbwIjJjMaODkKHvIaUhldfQn3nZDTV+M1JI0eEyIdjrOTcV3DdDrQF/jDnIEB3a/BDo78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934815; c=relaxed/simple; bh=y4OsWKbOLTtBRExU+Hq2EPu4xoFPTa3O/91wuGNyqUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FVOOpvVp1lSY5zuiLd4CJbfBmeLLfjLtTp5oZamE+td3Zea+lMi2gyBFITQVXeAwC7dfhxg/uQ8MDPZjkhT+K5TAdoraDb3qbLHRc1rKmUGkIjZGWz+yqImVc7p71j0KN846m+OtsqH7TmFxVP308+RFq1TGQsFEUPtg5Jsob58= 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=RHrb8Tjt; arc=none smtp.client-ip=209.85.167.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="RHrb8Tjt" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-518872fcb89so762290e87.3 for ; Fri, 12 Apr 2024 08:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1712934812; x=1713539612; 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=8sErkhIGmhf5usWez5Xl4XZ9oQzpvBj57cN4AShWReY=; b=RHrb8TjtgX9SYa4fyq5/UOKyQCUTIy/CvC27LXQO4YmjwzPQj7kYw2vw8/N4Om6w6x w5JyQVdg2iHTWQkNl9VFayxDGBMVwUPb5ys4zWsbYNfdUhjUW/pSRvCDmrHb7zm127E8 lvOKYWOD6Zj4JIHqnTPPMImFicxcuASDctkEhR/s+DhApp35klsUhBWWak3POHQZIRVs KRe5zhjMEz/DJXQFC9jzCxEyO/BuZWyN/M8CMOP/+qLL+GVP5EyegnmUMmPpumwE4aJd wH0o9JoahtN3VGICEvtKoVGy2ELXE5y+jM5kIWU400IdlPLL/5HQ4Pf0uHAs0SkBgCnp sM9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712934812; x=1713539612; 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=8sErkhIGmhf5usWez5Xl4XZ9oQzpvBj57cN4AShWReY=; b=Paa/L0PXtXRGmbwlVrtDNYC0lnG+AMxRMh3smYqnJ0UnHysHI0Lqw713ziy893i3sh yaKNqtszHLAA0TmRbC6fBTWZKIJR8uP4Wc1+MGngdhaPq7tqAlhOJhE0l4SuyJYji3rx 4qsl9aSd0Pm7/wRg04XqWTk1WxMHJcvkvaqKs+MxjkAVtbosuZ01Yr7kMNZHM0hm+Opa qM+AQ7RSOz89hw7WU3Q/qSiH02ybhG5QqZhj4jji+YZ1vDI+/wdWT5T5qi0T/yl+T6Ip pEx/ti0kWE7ixgZi+EhrSnsR4qJjmpntIHwkgUrRc98B7R14slGdTrpYClZt2omslfFu FHVw== X-Gm-Message-State: AOJu0Yzpcy24ssYSqCKTPJDPKSxV/pfOFal1d9Acb5723sJWxPpOLcUO VwM6/ijvVJgYS97it8QouChbhp5bc1G5cJMcI+mS+ke1tHeYignnQ0H0kTfQkIn0tSlmgr1zUcm q X-Google-Smtp-Source: AGHT+IHwWGW3bNG9GA57M2WThwmdHi3AxEYStvc4TMRAgXH1eI+v60ijR149hFgbWIu61VtE9NGtsA== X-Received: by 2002:ac2:5502:0:b0:515:bf51:a533 with SMTP id j2-20020ac25502000000b00515bf51a533mr1829013lfk.23.1712934812639; Fri, 12 Apr 2024 08:13:32 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id u5-20020a056512094500b00516dabfa3ffsm532393lft.145.2024.04.12.08.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 08:13:32 -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 5/6] selftests: forwarding: add wait_for_dev() helper Date: Fri, 12 Apr 2024 17:13:13 +0200 Message-ID: <20240412151314.3365034-6-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412151314.3365034-1-jiri@resnulli.us> References: <20240412151314.3365034-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 --- tools/testing/selftests/net/forwarding/lib.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 959183b516ce..74859f969997 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -746,6 +746,25 @@ setup_wait() sleep $WAIT_TIME } +wait_for_dev() +{ + local dev=$1; shift + local timeout=${1:-$WAIT_TIMEOUT}; shift + local max_iterations=$(($timeout * 10)) + + for ((i = 1; i <= $max_iterations; ++i)); do + ip link show dev $dev up &> /dev/null + if [[ $? -ne 0 ]]; then + sleep 0.1 + else + return 0 + fi + done + + log_test wait_for_dev ": Interface $dev did not appear." + exit 1 +} + cmd_jq() { local cmd=$1 From patchwork Fri Apr 12 15:13:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13627982 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 4749914900B for ; Fri, 12 Apr 2024 15:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934819; cv=none; b=k1pS2O65OX+7MzRb+aJNaFDLwKIgT4Fh+8A9AujYAFGi9XZRv5H1CvyCKK39II2zmUrwpj9bqu284blDdDlnGkSlCEUN+6sEKdYtC2g1rOiZT08s3YCqujCMHKUJ0UZaiSK9naa28QpRsGimW88jFfyePUmclcf5U2qhmMoUrEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712934819; c=relaxed/simple; bh=vG/dFpiKplr0KjS27Xya8aAHKc92Q9+PvZTQfbvlf6w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C0wrYF9yHORXytKXOybtYqKkuZPrR1bajQynX6j/Ht5PuUjWBQiFTVRrNUSQXjPmQTwSE+vT0bDGMEHmW/pdKe6iVk5tzBRhgeYirUk5YokNu97FRlWF+GHBG6MSxeAo8hRoeaad/WpPlOgWlauTrAof+SIFLLVrjB77FVZlb00= 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=DOyJXDV8; arc=none smtp.client-ip=209.85.167.53 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="DOyJXDV8" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-516dbc36918so1336610e87.0 for ; Fri, 12 Apr 2024 08:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1712934815; x=1713539615; 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=WTunXC6x4034AG0WHitd+4hipFdLCF+F+A/dgWvIp8o=; b=DOyJXDV8mxtSBhtVOztke5wV1hegkpo7z+t6lR4Rr33pWEfl6ltz51fTLwhc+/ms1Y W5EZUwiFOykcbkmX3Ir1PP8GJDX+gXjVdMWr6BDg/2LQhdOU7vZgt5kZWGo4bGeNjqEK 8plhIVZJEIGR30JTSyH6eZ5v4B+hq4j6eEcb/Mba5zqgbgd/qhvGXJB8bfxQsK4MB5jm jFTgLQwUA8Oysxz2soCkKBYNmLYLAixetDkxDxFUxPpK8Isy2sUVOIK/dWpawi5AKigm 3nyzwTzJ1U+7fbkl/pIjbOjQhw+uy2QcUCyG+pYi9p+khQarVZTbPHDHtf7JscFtxeO0 7Pww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712934815; x=1713539615; 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=WTunXC6x4034AG0WHitd+4hipFdLCF+F+A/dgWvIp8o=; b=Wl4JpHyWMg/mcsTzi++WT/PfDk1JVfthJELt4v8Lu+Svw3st76oZ+1+kMqYTPMvw5Z 3BnfcthdBVIBlhp5GYA7kySJBOh9hEIUQpeeJPanhLR3Kg5Mf15sN9ieHiun5m9U5HjL VrqEimXxjx2aKzFrvKtdy8ZsnGl0AOABBasDPJ3cjOdONn1XRnhE58wi0DAYlywS9RJ9 cJkCk0Xi4DxrL6ccTA2N4b/RrklxHFYBRs71YQ5MOeisMONFYlRKbuIKW3HxIyoZ6TdA fuIo6kVDOXg7aNYqrOpOCNhAOiLrAqly7w8ep5S3Vr6memdLOcs5N0UPDORpHphloY3p bS5g== X-Gm-Message-State: AOJu0YwdDxBy+nXE5obeqI4txQqSM2lHdMW/6UEhMvsgXNUu6NZBPFmm CzLW7qy15hWDGtfImsJoSnTqShb/L2VCCymqzn/HpWZAMuKsYAPZ/lsPechlS9XI2mRsJccdQt2 I X-Google-Smtp-Source: AGHT+IEFA5gkQ0ib7+hUmRwuS1fmSH2StHxV6OdCj4Zff4iXBk/jIHEX9eBmv8UKr6k22h+0gOtUDA== X-Received: by 2002:a19:f80a:0:b0:513:d3c0:f66 with SMTP id a10-20020a19f80a000000b00513d3c00f66mr1903270lff.51.1712934815395; Fri, 12 Apr 2024 08:13:35 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id f30-20020a19381e000000b00517aaa8670csm544114lfa.276.2024.04.12.08.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 08:13:34 -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 6/6] selftests: virtio_net: add initial tests Date: Fri, 12 Apr 2024 17:13:14 +0200 Message-ID: <20240412151314.3365034-7-jiri@resnulli.us> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412151314.3365034-1-jiri@resnulli.us> References: <20240412151314.3365034-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 --- tools/testing/selftests/Makefile | 1 + .../selftests/drivers/net/virtio_net/Makefile | 5 + .../drivers/net/virtio_net/basic_features.sh | 127 ++++++++++++++++++ .../net/virtio_net/virtio_net_common.sh | 99 ++++++++++++++ 4 files changed, 232 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/virtio_net_common.sh diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 6dab886d6f7a..a8e40599c65f 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 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..c6edf5ddb0e4 --- /dev/null +++ b/tools/testing/selftests/drivers/net/virtio_net/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ OR MIT + +TEST_PROGS = basic_features.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/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 +}