hv: vmbus: add fuzz testing to hv device
Subsystems (2)
v2 cover hv: vmbus: add fuzz testing to hv device
This patchset introduces a testing framework for Hyper-V drivers. This framework allows us to introduce delays in the packet receive path on a per-device basis. While the current code only supports introducing arbitrary delays in the host/guest communication path, we intend to expand this to support error injection in the future.
Changes in v2:
Patch 1: As per Vitaly's suggestion, wrapped the test code under an
#ifdef and updated the Kconfig file, so that the test code will only be used when the config option is set to true. (default is false).
Updated hyperv_vmbus header to contain new #ifdef with new new functions for the test code.
Patch 2: Moved code from under sysfs to debugfs and wrapped it under
the new ifdef.
Updated MAINTAINERS file with new debugfs-hyperv file under the section for hyperv.
Patch 3: Updated testing tool with new debugfs location.
Branden Bonaby (3):
drivers: hv: vmbus: Introduce latency testing
drivers: hv: vmbus: add fuzz test attributes to debugfs
tools: hv: add vmbus testing tool
Documentation/ABI/testing/debugfs-hyperv | 21 ++ MAINTAINERS | 1 + drivers/hv/Kconfig | 7 + drivers/hv/connection.c | 3 + drivers/hv/hyperv_vmbus.h | 20 ++ drivers/hv/ring_buffer.c | 7 + drivers/hv/vmbus_drv.c | 167 ++++++++++++ include/linux/hyperv.h | 21 ++ tools/hv/vmbus_testing | 334 +++++++++++++++++++++++ 9 files changed, 581 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-hyperv create mode 100644 tools/hv/vmbus_testing
Signature · 1 line
2.17.1
PATCH v2 1/3 drivers: hv: vmbus: Introduce latency testing
Introduce user specified latency in the packet reception path.
---
Changes in v2:
- Add #ifdef in Kconfig file so test code will not interfere with non-test code.
- Move test code functions for delay to hyperv_vmbus header file.
- Wrap test code under #ifdef statement.
drivers/hv/Kconfig | 7 +++++++ drivers/hv/connection.c | 3 +++ drivers/hv/hyperv_vmbus.h | 20 ++++++++++++++++++++ drivers/hv/ring_buffer.c | 7 +++++++ include/linux/hyperv.h | 21 +++++++++++++++++++++ 5 files changed, 58 insertions(+)
drivers/hv/Kconfig +7 -0
@@ -29,4 +29,11 @@ config HYPERV_BALLOON help Select this option to enable Hyper-V Balloon driver. +config HYPERV_TESTING + bool "Hyper-V testing" + default n + depends on HYPERV && DEBUG_FS + help + Select this option to enable Hyper-V vmbus testing. + endmenu
drivers/hv/connection.c +3 -0
@@ -357,6 +357,9 @@ void vmbus_on_event(unsigned long data)trace_vmbus_on_event (channel); +#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,INTERRUPT_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ do { void (*callback_fn)(void *);
drivers/hv/hyperv_vmbus.h +20 -0
@@ -357,4 +357,24 @@ enum hvutil_device_state { HVUTIL_DEVICE_DYING, /* driver unload is in progress */ }; +#ifdef CONFIG_HYPERV_TESTING +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/err.h> +#define TESTING "hyperv" + +enum delay { +INTERRUPT_DELAY =0 , +MESSAGE_DELAY =1 , +}; + +int hv_debug_delay_files (struct hv_device *dev,struct dentry *root); +int hv_debug_add_dev_dir (struct hv_device *dev); +void hv_debug_rm_dev_dir (struct hv_device *dev); +void hv_debug_rm_all_dir (void ); +void hv_debug_set_dir_dentry (struct hv_device *dev,struct dentry *root); +void hv_debug_delay_test (struct vmbus_channel *channel,enum delay delay_type); + +#endif /* CONFIG_HYPERV_TESTING */ +#endif /* _HYPERV_VMBUS_H */
drivers/hv/ring_buffer.c +7 -0
@@ -396,6 +396,10 @@ struct vmpacket_descriptor *hv_pkt_iter_first(struct vmbus_channel *channel)struct hv_ring_buffer_info *rbi = &channel->inbound;struct vmpacket_descriptor *desc; +#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,MESSAGE_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ +if (hv_pkt_iter_avail (rbi) <sizeof (struct vmpacket_descriptor ))return NULL ;
@@ -421,6 +425,9 @@ __hv_pkt_iter_next(struct vmbus_channel *channel,u32 packetlen = desc->len8 <<3 ;u32 dsize = rbi->ring_datasize; +#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,MESSAGE_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ /* bump offset to next potential packet */ rbi->priv_read_index += packetlen +VMBUS_PKT_TRAILER ;if (rbi->priv_read_index >= dsize)
include/linux/hyperv.h +21 -0
@@ -926,6 +926,21 @@ struct vmbus_channel {* full outbound ring buffer. */ u64 out_full_first; + +#ifdef CONFIG_HYPERV_TESTING +/* enabling/disabling fuzz testing on the channel (default is false)*/ +bool fuzz_testing_state; + +/* Interrupt delay will delay the guest from emptying the ring buffer +* for a specific amount of time. The delay is in microseconds and will +* be between 1 to a maximum of 1000, its default is 0 (no delay). +* The Message delay will delay guest reading on a per message basis +* in microseconds between 1 to 1000 with the default being 0 +* (no delay). +*/ +u32 fuzz_testing_interrupt_delay; +u32 fuzz_testing_message_delay; +#endif /* CONFIG_HYPERV_TESTING */ };static inline bool is_hvsock_channel (const struct vmbus_channel *c)
@@ -1166,6 +1181,12 @@ struct hv_device {struct vmbus_channel *channel;struct kset *channels_kset; + +#ifdef CONFIG_HYPERV_TESTING +/* place holder to keep track of the dir for hv device in debugfs */ +struct dentry *debug_dir; +#endif /* CONFIG_HYPERV_TESTING */ + };
Signature · 1 line
2.17.1
RE: [PATCH v2 1/3] drivers: hv: vmbus: Introduce latency testing
From: Branden Bonaby <[email protected]> Sent: Monday, August 19, 2019 7:45 PM
Quoted 40 lines
Introduce user specified latency in the packet reception path.
Signed-off-by Branden Bonaby <[email protected]>---
Changes in v2:
- Add #ifdef inKconfigfile so test code will not interfere with non-test code.
- Move test code functions for delay tohyperv_vmbusheader file.
- Wrap test code under #ifdef statement.drivers/hv/Kconfig | 7 +++++++ drivers/hv/connection.c | 3 +++ drivers/hv/hyperv_vmbus.h | 20 ++++++++++++++++++++ drivers/hv/ring_buffer.c | 7 +++++++ include/linux/hyperv.h | 21 +++++++++++++++++++++ 5 files changed, 58 insertions(+)drivers/hv/Kconfig +7
-0@@ -29,4 +29,11 @@ config HYPERV_BALLOON help Select this option to enable Hyper-V Balloon driver. +config HYPERV_TESTING + bool "Hyper-V testing" + default n + depends on HYPERV && DEBUG_FS + help + Select this option to enable Hyper-V vmbus testing. + endmenudrivers/hv/connection.c +0
-0
drivers/hv/connection.c void vmbus_on_event(unsigned long data) · line 362
Quoted 6 lines
drivers/hv/connection.c +3
-0@@ -357,6 +357,9 @@ void vmbus_on_event(unsigned long data)trace_vmbus_on_event (channel); +#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,INTERRUPT_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */
You are following Vitaly's suggestion to use #ifdef's so no code is generated when HYPERV_TESTING is not enabled. However, this direct approach to using #ifdef's really clutters the code and makes it harder to read and follow. The better approach is to use the #ifdef in the include file where the functions are defined. If HYPERV_TESTING is not enabled, provide a #else that defines the function with an empty implementation for which the compiler
will generate no code. An as example, see the function definition
for hyperv_init() in arch/x86/include/asm/mshyperv.h. There are several functions treated similarly in that include file.
Quoted 8 lines
drivers/hv/connection.c +0
-0do { void (*callback_fn)(void *);drivers/hv/hyperv_vmbus.h +0
-0
drivers/hv/hyperv_vmbus.h enum hvutil_device_state { · line 363
Quoted 7 lines
drivers/hv/hyperv_vmbus.h +4
-0@@ -357,4 +357,24 @@ enum hvutil_device_state { HVUTIL_DEVICE_DYING, /* driver unload is in progress */ }; +#ifdef CONFIG_HYPERV_TESTING +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/err.h>
Generally #include files should go at the top of the file, even if they are only needed conditionally.
drivers/hv/hyperv_vmbus.h enum hvutil_device_state { · line 364
Quoted 1 line
drivers/hv/hyperv_vmbus.h +1
-0+#define TESTING "hyperv"
I'm not seeing what this line is for, or how it is used.
drivers/hv/hyperv_vmbus.h enum hvutil_device_state { · line 377
Quoted 13 lines
drivers/hv/hyperv_vmbus.h +13
-0+ +enum delay { +INTERRUPT_DELAY =0 , +MESSAGE_DELAY =1 , +}; + +int hv_debug_delay_files (struct hv_device *dev,struct dentry *root); +int hv_debug_add_dev_dir (struct hv_device *dev); +void hv_debug_rm_dev_dir (struct hv_device *dev); +void hv_debug_rm_all_dir (void ); +void hv_debug_set_dir_dentry (struct hv_device *dev,struct dentry *root); +void hv_debug_delay_test (struct vmbus_channel *channel,enum delay delay_type); +
This is where you could put a #else and the null implementation of the above functions.
Quoted 42 lines
drivers/hv/hyperv_vmbus.h +2
-0+#endif /* CONFIG_HYPERV_TESTING */ +#endif /* _HYPERV_VMBUS_H */ drivers/hv/ring_buffer.c +7
-0@@ -396,6 +396,10 @@ struct vmpacket_descriptor *hv_pkt_iter_first(struct vmbus_channel *channel)struct hv_ring_buffer_info *rbi = &channel->inbound;struct vmpacket_descriptor *desc; +#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,MESSAGE_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ +if (hv_pkt_iter_avail (rbi) <sizeof (struct vmpacket_descriptor ))return NULL ;@@ -421,6 +425,9 @@ __hv_pkt_iter_next(struct vmbus_channel *channel,u32 packetlen = desc->len8 <<3 ;u32 dsize = rbi->ring_datasize; +#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,MESSAGE_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ /* bump offset to next potential packet */ rbi->priv_read_index += packetlen +VMBUS_PKT_TRAILER ;if (rbi->priv_read_index >= dsize)include/linux/hyperv.h +5
-0@@ -926,6 +926,21 @@ struct vmbus_channel {* full outbound ring buffer. */ u64 out_full_first; + +#ifdef CONFIG_HYPERV_TESTING +/* enabling/disabling fuzz testing on the channel (default is false)*/ +bool fuzz_testing_state; +
include/linux/hyperv.h struct vmbus_channel { · line 943
Quoted 10 lines
include/linux/hyperv.h +10
-0+/* Interrupt delay will delay the guest from emptying the ring buffer +* for a specific amount of time. The delay is in microseconds and will +* be between 1 to a maximum of 1000, its default is 0 (no delay). +* The Message delay will delay guest reading on a per message basis +* in microseconds between 1 to 1000 with the default being 0 +* (no delay). +*/ +u32 fuzz_testing_interrupt_delay; +u32 fuzz_testing_message_delay; +#endif /* CONFIG_HYPERV_TESTING */
For fields in a data structure like this, you don't have much choice but to put the #ifdef directly inline. However, for small fields like this and where the data structure isn't size sensitive, you could consider omitting the #ifdef and just always including the fields even when HYPERV_TESTING is not enabled. I don't have a strong preference either way.
include/linux/hyperv.h struct hv_device { · line 1188
Quoted 12 lines
include/linux/hyperv.h +5
-0};static inline bool is_hvsock_channel (const struct vmbus_channel *c)@@ -1166,6 +1181,12 @@ struct hv_device {struct vmbus_channel *channel;struct kset *channels_kset; + +#ifdef CONFIG_HYPERV_TESTING +/* place holder to keep track of the dir for hv device in debugfs */ +struct dentry *debug_dir; +#endif /* CONFIG_HYPERV_TESTING */
Same here.
Michael
Quoted 6 lines
include/linux/hyperv.h +1
-1+ }; --2.17.1
Re: [PATCH v2 1/3] drivers: hv: vmbus: Introduce latency testing
Quoted 9 lines
Quoted 9 lines
endmenu
drivers/hv/connection.c +0
-0@@ -357,6 +357,9 @@ void vmbus_on_event(unsigned long data)trace_vmbus_on_event (channel);
Quoted 15 lines
drivers/hv/connection.c void vmbus_on_event(unsigned long data) · line 362
Quoted 3 lines
drivers/hv/connection.c +3
-0+#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,INTERRUPT_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ You are following Vitaly's suggestion to use #ifdef's so no code is generated when
HYPERV_TESTINGis not enabled. However, this direct approach to using #ifdef's really clutters the code and makes it harder to read and follow. The better approach is to use the #ifdef in the include file where the functions are defined. IfHYPERV_TESTINGis not enabled, provide a #else that defines the function with an empty implementation for which the compiler
will generate no code. An as example, see the function definition
forhyperv_init()inarch/x86/include/asm/mshyperv.h. There are several functions treated similarly in that include file.
I checked out the code in arch/x86/include/asm/mshyperv.h, after thinking about it, I'm wondering if it would be better just to have two files one called hv_debugfs.c and the other hyperv_debugfs.h. I could put the code definitions in hv_debugfs.c and at the top include the hyperv_debugfs.h file which would house the declarations of these functions under the ifdef. Then like you alluded too use an #else statement that would have the null implementations of the above functions. Then put an #include "hyperv_debugfs.h" in the hyperv_vmbus.h file. I figured instead of putting the code directly into the vmbus_drv.c file it might be best to put them in a seperate file like hv_debugfs.c. This way when we start adding more tests we don't bloat the vmbus_drv.c file unnecessarily. The hv_debugfs.c file would have the #ifdef CONFIG_HYPERV_TESTING at the top so if its not enabled those null implementations in "hyperv_debugfs.h" woud kick in anywhere that included the hyperv_vmbus.h file which is what we want.
what do you think?
Quoted 12 lines
Quoted 12 lines
drivers/hv/connection.c +0
-0do { void (*callback_fn)(void *);drivers/hv/hyperv_vmbus.h +0
-0@@ -357,4 +357,24 @@ enum hvutil_device_state { HVUTIL_DEVICE_DYING, /* driver unload is in progress */ };
Quoted 8 lines
drivers/hv/hyperv_vmbus.h enum hvutil_device_state { · line 363
Quoted 4 lines
drivers/hv/hyperv_vmbus.h +4
-0+#ifdef CONFIG_HYPERV_TESTING +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/err.h> Generally #include files should go at the top of the file, even if they are only needed conditionally.
I see , will change
Quoted 3 lines
drivers/hv/hyperv_vmbus.h enum hvutil_device_state { · line 364
Quoted 1 line
drivers/hv/hyperv_vmbus.h +1
-0+#define TESTING "hyperv"I'm not seeing what this line is for, or how it is used.
I used it as the top level name for the dentry that would appear in debugfs but now I realize its actually not needed, so i'll remove this.
Quoted 20 lines
Quoted 20 lines
include/linux/hyperv.h +14
-0@@ -926,6 +926,21 @@ struct vmbus_channel {* full outbound ring buffer. */ u64 out_full_first; + +#ifdef CONFIG_HYPERV_TESTING +/* enabling/disabling fuzz testing on the channel (default is false)*/ +bool fuzz_testing_state; + +/* Interrupt delay will delay the guest from emptying the ring buffer +* for a specific amount of time. The delay is in microseconds and will +* be between 1 to a maximum of 1000, its default is 0 (no delay). +* The Message delay will delay guest reading on a per message basis +* in microseconds between 1 to 1000 with the default being 0 +* (no delay). +*/ +u32 fuzz_testing_interrupt_delay; +u32 fuzz_testing_message_delay;
Quoted 9 lines
include/linux/hyperv.h struct vmbus_channel { · line 943
Quoted 1 line
include/linux/hyperv.h +1
-0+#endif /* CONFIG_HYPERV_TESTING */ For fields in a data structure like this, you don't have much choice but to put the #ifdef directly inline. However, for small fields like this and where the data structure isn't size sensitive, you could consider omitting the #ifdef and just always including the fields even when
HYPERV_TESTINGis not enabled. I don't have a strong preference either way.
I'll take the ifdefs out since the fields aren't too big
RE: [PATCH v2 1/3] drivers: hv: vmbus: Introduce latency testing
From: Branden Bonaby <[email protected]> Sent: Thursday, August 22, 2019 8:39 PM
Quoted 41 lines
Quoted 8 lines
Quoted 8 lines
drivers/hv/connection.c +0
-0@@ -357,6 +357,9 @@ void vmbus_on_event(unsigned long data)trace_vmbus_on_event (channel);Quoted 15 lines
drivers/hv/connection.c void vmbus_on_event(unsigned long data) · line 362
Quoted 3 lines
drivers/hv/connection.c +3
-0+#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,INTERRUPT_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ You are following Vitaly's suggestion to use #ifdef's so no code is generated when
HYPERV_TESTINGis not enabled. However, this direct approach to using #ifdef's really clutters the code and makes it harder to read and follow. The better approach is to use the #ifdef in the include file where the functions are defined. IfHYPERV_TESTINGis not enabled, provide a #else that defines the function with an empty implementation for which the compiler
will generate no code. An as example, see the function definition
forhyperv_init()inarch/x86/include/asm/mshyperv.h. There are several functions treated similarly in that include file.I checked out the code in
arch/x86/include/asm/mshyperv.h, after thinking about it, I'm wondering if it would be better just to have two files one calledhv_debugfs.cand the otherhyperv_debugfs.h. I could put the code definitions inhv_debugfs.cand at the top include thehyperv_debugfs.hfile which would house the declarations of these functions under the ifdef. Then like you alluded too use an #else statement that would have the null implementations of the above functions. Then put an #include "hyperv_debugfs.h" in thehyperv_vmbus.hfile. I figured instead of putting the code directly into thevmbus_drv.cfile it might be best to put them in a seperate file likehv_debugfs.c. This way when we start adding more tests we don't bloat thevmbus_drv.cfile unnecessarily. Thehv_debugfs.cfile would have the #ifdefCONFIG_HYPERV_TESTINGat the top so if its not enabled those null implementations in "hyperv_debugfs.h" woud kick in anywhere that included thehyperv_vmbus.hfile which is what we want.
Quoted 2 lines
what do you think?
I'll preface my comments by saying that how code gets structured into files is always a bit of a judgment call. The goal is to group code into sensible chunks to make it easy to understand and to make it easy to modify and extend later. The latter is a prediction about the
future, which may or may not be accurate. For the former, what's
"easy to understand," is often in the eye of the beholder. So you may get different opinions from different reviewers.
That said, I like the idea of a separate hv_debugfs.c file to contain the implementation of the various functions you have added to
provide the fuzzing capability. I'm less convinced about the value
of a separate hyperv_debugfs.h file. I think you have one big
#ifdef CONFIG_HYPERV_TESTING followed by the declarations of the functions in hv_debugfs.c, followed by #else and null implementations of those functions. This is 20 lines of code or so, and could easily go in hyperv_vmbus.h.
For the new hv_debugfs.c, you can avoid the need for
#ifdef CONFIG_HYPERV_TESTING by modifying the Makefile in drivers/hv so that hv_debugfs.o is built only if CONFIG_HYPERV_TESTING is defined. Look at the current Makefile to see how this is done with CONFIG_HYPERV_UTILS and CONFIG_HYPERV_BALLOON.
Michael
Re: [PATCH v2 1/3] drivers: hv: vmbus: Introduce latency testing
Quoted 62 lines · Michael Kelley
From: Branden Bonaby <[email protected]> Sent: Thursday, August 22, 2019 8:39 PM
Quoted 41 lines
Quoted 8 lines
Quoted 8 lines
drivers/hv/connection.c +0
-0@@ -357,6 +357,9 @@ void vmbus_on_event(unsigned long data)trace_vmbus_on_event (channel);Quoted 15 lines
drivers/hv/connection.c void vmbus_on_event(unsigned long data) · line 362
Quoted 3 lines
drivers/hv/connection.c +3
-0+#ifdef CONFIG_HYPERV_TESTING +hv_debug_delay_test (channel,INTERRUPT_DELAY ); +#endif /* CONFIG_HYPERV_TESTING */ You are following Vitaly's suggestion to use #ifdef's so no code is generated when
HYPERV_TESTINGis not enabled. However, this direct approach to using #ifdef's really clutters the code and makes it harder to read and follow. The better approach is to use the #ifdef in the include file where the functions are defined. IfHYPERV_TESTINGis not enabled, provide a #else that defines the function with an empty implementation for which the compiler
will generate no code. An as example, see the function definition
forhyperv_init()inarch/x86/include/asm/mshyperv.h. There are several functions treated similarly in that include file.I checked out the code in
arch/x86/include/asm/mshyperv.h, after thinking about it, I'm wondering if it would be better just to have two files one calledhv_debugfs.cand the otherhyperv_debugfs.h. I could put the code definitions inhv_debugfs.cand at the top include thehyperv_debugfs.hfile which would house the declarations of these functions under the ifdef. Then like you alluded too use an #else statement that would have the null implementations of the above functions. Then put an #include "hyperv_debugfs.h" in thehyperv_vmbus.hfile. I figured instead of putting the code directly into thevmbus_drv.cfile it might be best to put them in a seperate file likehv_debugfs.c. This way when we start adding more tests we don't bloat thevmbus_drv.cfile unnecessarily. Thehv_debugfs.cfile would have the #ifdefCONFIG_HYPERV_TESTINGat the top so if its not enabled those null implementations in "hyperv_debugfs.h" woud kick in anywhere that included thehyperv_vmbus.hfile which is what we want.Quoted 2 lines
what do you think?
I'll preface my comments by saying that how code gets structured into files is always a bit of a judgment call. The goal is to group code into sensible chunks to make it easy to understand and to make it easy to modify and extend later. The latter is a prediction about the
future, which may or may not be accurate. For the former, what's
"easy to understand," is often in the eye of the beholder. So you may get different opinions from different reviewers.That said, I like the idea of a separate
hv_debugfs.cfile to contain the implementation of the various functions you have added to
provide the fuzzing capability. I'm less convinced about the value
of a separatehyperv_debugfs.hfile. I think you have one big
#ifdefCONFIG_HYPERV_TESTINGfollowed by the declarations of the functions inhv_debugfs.c, followed by #else and null implementations of those functions. This is 20 lines of code or so, and could easily go inhyperv_vmbus.h.
Quoted 8 lines
For the new
hv_debugfs.c, you can avoid the need for
#ifdefCONFIG_HYPERV_TESTINGby modifying theMakefileindrivers/hvso that hv_debugfs.o is built only ifCONFIG_HYPERV_TESTINGis defined. Look at the currentMakefileto see how this is done withCONFIG_HYPERV_UTILSandCONFIG_HYPERV_BALLOON.Michael
I see, that does make sense, I'll go ahead and add these changes.
thanks
branden bonaby
PATCH v2 2/3 drivers: hv: vmbus: add test attributes to debugfs
In reply to Branden BonabyExpose the test parameters as part of the debugfs channel attributes. We will control the testing state via these attributes.
---
Changes in v2:
- Move test attributes to debugfs.
- Wrap test code under #ifdef statements.
- Add new documentation file under Documentation/ABI/testing.
- Make commit message reflect the change from from sysfs to debugfs.
Documentation/ABI/testing/debugfs-hyperv | 21 +++ MAINTAINERS | 1 + drivers/hv/vmbus_drv.c | 167 +++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-hyperv
Documentation/ABI/testing/debugfs-hyperv new file +21 -0
@@ -0,0 +1,21 @@ +What: /sys/kernel/debug/hyperv/<UUID>/fuzz_test_state +Date: August 2019 +KernelVersion: 5.3 +Contact: Branden Bonaby <[email protected]> +Description: Fuzz testing status of a vmbus device, whether its in an ON + state or a OFF state +Users: Debugging tools + +What: /sys/kernel/debug/hyperv/<UUID>/delay/fuzz_test_buffer_interrupt_delay +Date: August 2019 +KernelVersion: 5.3 +Contact: Branden Bonaby <[email protected]> +Description: Fuzz testing buffer delay value between 0 - 1000 +Users: Debugging tools + +What: /sys/kernel/debug/hyperv/<UUID>/delay/fuzz_test_message_delay +Date: August 2019 +KernelVersion: 5.3 +Contact: Branden Bonaby <[email protected]> +Description: Fuzz testing message delay value between 0 - 1000 +Users: Debugging tools
MAINTAINERS +1 -0
@@ -7460,6 +7460,7 @@ F: include/uapi/linux/hyperv.h F: include/asm-generic/mshyperv.h F: tools/hv/ F: Documentation/ABI/stable/sysfs-bus-vmbus +F: Documentation/ABI/testing/debugfs-hyperv HYPERBUS SUPPORT M: Vignesh Raghavendra <[email protected]>
drivers/hv/vmbus_drv.c +167 -0
197 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 2/3] drivers: hv: vmbus: add test attributes to debugfs
Quoted 12 lines · Branden Bonaby
Expose the test parameters as part of the debugfs channel attributes. We will control the testing state via these attributes.
Signed-off-by Branden Bonaby <[email protected]>---
Changes in v2:
- Move test attributes to debugfs.
- Wrap test code under #ifdef statements.
- Add new documentation file underDocumentation/ABI/testing.
- Make commit message reflect the change from from sysfs to debugfs.
drivers/hv/vmbus_drv.c static void hv_crash_handler(struct pt_regs *regs) · line 2188
Quoted 5 lines
drivers/hv/vmbus_drv.c +5
-0+if (IS_ERR_OR_NULL (dev_root)) { +pr_debug ("debugfs_hyperv: %s/%s/ not created\n" , +TESTING , device); +return PTR_ERR (dev_root); + }
Whoops, that single IS_ERR_OR_NULL shouldn't be there, it should just be IS_ERR I'll change and resend the patch.
PATCH v2 3/3 tools: hv: add vmbus testing tool
In reply to Branden BonabyThis is a userspace tool to drive the testing. Currently it supports introducing user specified delay in the host to guest communication path on a per-channel basis.
---
Changes in v2:
- Move testing location to new location in debugfs.
tools/hv/vmbus_testing | 334 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 tools/hv/vmbus_testing
tools/hv/vmbus_testing new file +334 -0
@@ -0,0 +1,334 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# +#Program to allow users to fuzz test Hyper-V drivers +#by interfacing with Hyper-V debugfs directories +#author: Branden Bonaby + +import os +import cmd +import argparse +from collections import defaultdict +from argparse import RawDescriptionHelpFormatter + +#debugfs paths for vmbus must exist (same as in lsvmbus) +debugfs_sys_path = '/sys/kernel/debug/hyperv' +if not os.path.isdir(debugfs_sys_path): + print("{} doesn't exist/check permissions".format(debugfs_sys_path)) + exit(-1) +#Do not change unless, you change the debugfs attributes +#in "/sys/kernel/debug/hyperv/<UUID>/". All fuzz testing +#attributes will start with "fuzz_test". +pathlen = len(debugfs_sys_path) +fuzz_state_location = "fuzz_test_state" +fuzz_states = {0 : "Disable", 1 : "Enable"} +fuzz_methods ={1 : "Delay_testing"} +fuzz_delay_types = {1 : "fuzz_test_buffer_interrupt_delay", 2 :"fuzz_test_message_delay"} + +def parse_args(): + parser = argparse.ArgumentParser(description = "vmbus_testing "\ + "[-s] [0|1] [-q] [-p] <debugfs-path>\n""vmbus_testing [-s]"\ + " [0|1] [-q][-p] <debugfs-path> delay [-d] [val][val] [-E|-D]\n" + "vmbus_testing [-q] disable-all\n" + "vmbus_testing [-q] view [-v|-V]\n"\ + "vmbus_testing --version", + epilog = "Current testing options {}".format(fuzz_methods), + prog = 'vmbus_testing', + formatter_class = RawDescriptionHelpFormatter) + subparsers = parser.add_subparsers(dest="action") + parser.add_argument('--version', action='version',\ + version = '%(prog)s 1.0') + parser.add_argument("-q","--quiet",action = "store_true",\ + help = "silence none important test messages") + parser.add_argument("-s","--state",metavar = "", type = int,\ + choices = range(0,2),\ + help = "Turn testing ON or OFF for a single device."\ + " The value (1) will turn testing ON. The value"\ + " of (0) will turn testing OFF with the default set"\ + " to (0).") + parser.add_argument("-p","--path", metavar = "",\ + help = "Refers to the debugfs path to a vmbus device." + " If the path is not a valid path to a vmbus device,"\ + " the program will exit. The path must be the"\ + " absolute path; use the lsvmbus command to find"\ + " the path.") + parser_delay = subparsers.add_parser("delay",\ + help = "Delay buffer/message reads in microseconds.", + description = "vmbus_testing -s [0|1] [-q] -p "\ + "<debugfs-path> delay -d "\ + "[buffer-delay-value] [message-delay-value]\n" + "vmbus_testing [-q] delay [buffer-delay-value] "\ + "[message-delay-value] -E\n" + "vmbus_testing [-q] delay [buffer-delay-value] "\ + "[message-delay-value] -D", + formatter_class = RawDescriptionHelpFormatter) + delay_group = parser_delay.add_mutually_exclusive_group() + delay_group.add_argument("-E","--en-all-delay", action = "store_true",\ + help = "Enable Buffer/Message Delay testing on ALL"\ + " devices. Use -d option with this to set the values"\ + " for both the buffer delay and the message delay. No"\ + " value can be (0) or less than (-1). If testing is"\ + " disabled on a device prior to running this command,"\ + " testing will be enabled on the device as a result"\ + " of this command.") + delay_group.add_argument("-D","--dis-all-delay", action="store_true",\ + help = "Disable Buffer/Message delay testing on ALL"\ + " devices. A value equal to (-1) will keep the"\ + " current delay value, and a value equal to (0) will"\ + " remove delay testing for the specfied delay column."\ + " only values (-1) and (0) will be accepted but at"\ + " least one value must be a (0) or a (-1).") + parser_delay.add_argument("-d","--delay-time", metavar="", nargs=2,\ + type = check_range, default =[0,0], required = (True),\ + help = "Buffer/message delay time. A value of (0) will"\ + "disable delay testing on the specified delay column,"\ + " while a value of (-1) will ignore the specified"\ + " delay column. The default values are [0] & [0]."\ + " The first column represents the buffer delay value"\ + " and the second represents the message delay value."\ + " Value constraints: -1 <= value <= 1000.") + parser_dis_all = subparsers.add_parser("disable-all",\ + help = "Disable ALL testing on all vmbus devices.", + description = "vmbus_testing disable-all", + formatter_class = RawDescriptionHelpFormatter) + parser_view = subparsers.add_parser("view",\ + help = "View testing on vmbus devices.", + description = "vmbus_testing view -V\n" + "vmbus_testing -p <debugfs-path> view -v", + formatter_class = RawDescriptionHelpFormatter) + view_group = parser_view.add_mutually_exclusive_group() + view_group.add_argument("-V","--view-all-states",action = "store_true",\ + help = "View the test status for all vmbus devices.") + view_group.add_argument("-v","--view-single-device",\ + action = "store_true",help = "View test values for a"\ + " single vmbus device.") + + return parser.parse_args() + +#value checking for range checking input in parser +def check_range(arg1): + try: + val = int(arg1) + except ValueError as err: + raise argparse.ArgumentTypeError(str(err)) + if val < -1 or val > 1000: + message = ("\n\nError, Expected -1 <= value <= 1000, got value"\ + " {}\n").format(val) + raise argparse.ArgumentTypeError(message) + return val + +def main(): + try: + dev_list = [] + for dir in os.listdir(debugfs_sys_path):\ + dev_list.append(os.path.join(debugfs_sys_path,dir)) + #key value, pairs + #key = debugfs device path + #value = list of fuzz testing attributes. + device_and_files = defaultdict(list) + for dev in dev_list: + path = os.path.join(dev,"delay") + for f in os.listdir(path): + if (f.startswith("fuzz_test")): + device_and_files[path].append(f) + + device_and_files.default_factory = None + args = parse_args() + path = args.path + state = args.state + quiet = args.quiet + if (not quiet): + print("*** Use lsvmbus to get vmbus device type"\ + " information.*** ") + if (state is not None and validate_args_path(path,dev_list)): + if (state is not get_test_state(path)): + change_test_state(path,quiet) + state = get_test_state(path) + if (state is 0 and path is not None): + disable_testing_single_device(path,0,quiet) + return + #Use subparsers as the key for different fuzz testing methods + if (args.action == "delay"): + delay = args.delay_time + if (validate_delay_values(args,delay)): + delay_test_all_devices(dev_list,delay,quiet) + elif (validate_args_path(path,dev_list)): + if(get_test_state(path) is 1): + delay_test_store(path,delay,quiet) + return + print("device testing OFF, use -s 1 to turn ON") + elif (args.action == "disable-all"): + disable_all_testing(dev_list,quiet) + elif (args.action == "view"): + if (args.view_all_states): + all_devices_test_status(dev_list) + elif (args.view_single_device): + if (validate_args_path(path,dev_list)): + device_test_values(device_and_files,\ + path) + return + print("Error,(check path) usage: -p"\ + " <debugfs device path> view -v") + except AttributeError: + print("check usage, 1 or more elements not provided") + exit(-1) + +#Validate delay values to make sure they are acceptable to +#to either enable all delays on a device or disable all +#delays on a device +def validate_delay_values(args,delay): + if (args.en_all_delay): + for i in delay: + if (i < -1 or i == 0): + print("\nError, Values must be"\ + " equal to -1 or be > 0, use"\ + " -d option") + exit(-1) + return True + elif (args.dis_all_delay): + for i in delay: + if (i < -1 or i > 0): + print("\nError, at least 1 value" + " is not a (0) or a (-1)") + exit(-1) + return True + else: + return False + + +#Validate argument path +def validate_args_path(path,dev_list): + if (path in dev_list): + return True + else: + return False + +#display Testing status of single device +def device_test_values(device_and_files,path): + + delay_path = os.path.join(path,'delay') + for test in device_and_files.get(delay_path): + print("{}".format(test), end = '') + print((" value = {}")\ + .format(read_test_files(os.path.join(delay_path,test)))) + +#display Testing state of devices +def all_devices_test_status(dev_list): + for device in dev_list: + if (get_test_state(device) is 1): + print("Testing = ON for: {}".format(device.split("/")[5])) + else: + print("Testing = OFF for: {}".format(device.split("/")[5])) + +#read the vmbus device files, path must be absolute path before calling +def read_test_files(path): + try: + with open(path,"r") as f: + state = f.readline().strip() + if (state == 'N'): + state = 0 + elif (state == 'Y'): + state = 1 + return int(state) + + except IOError as e: + errno, strerror = e.args + print("I/O error({0}): {1} on file {2}"\ + .format(errno,strerror,path)) + exit(-1) + except ValueError: + print ("Element to int conversion error in: \n{}".format(path)) + exit(-1) + +#writing to vmbus device files, path must be absolute path before calling +def write_test_files(path,value): + try: + with open(path,"w") as f: + f.write("{}".format(value)) + except IOError as e: + errno, strerror = e.args + print("I/O error({0}): {1} on file {2}"\ + .format(errno,strerror,path)) + exit(-1) + +#change testing state of device +def change_test_state(device,quiet): + state_path = os.path.join(device,fuzz_state_location) + if (get_test_state(device) is 0): + write_test_files(state_path,1) + if (not quiet): + print("Testing = ON for device: {}"\ + .format(state_path.split("/")[5])) + else: + write_test_files(state_path,0) + if (not quiet): + print("Testing = OFF for device: {}"\ + .format(state_path.split("/")[5])) + +#get testing state of device +def get_test_state(device): + #state == 1 - test = ON + #state == 0 - test = OFF + return read_test_files(os.path.join(device,fuzz_state_location)) + +#Enter 1 - 1000 microseconds, into a single device using the +#fuzz_test_buffer_interrupt_delay and fuzz_test_message_delay +#debugfs attributes +def delay_test_store(device,delay_length,quiet): + + try: + # delay[0]- buffer delay, delay[1]- message delay + buff_test = os.path.join(os.path.sep,device,'delay', + fuzz_delay_types.get(1)) + mess_test = os.path.join(os.path.sep,device,'delay', + fuzz_delay_types.get(2)) + + if (delay_length[0] >= 0): + write_test_files(buff_test,delay_length[0]) + if (delay_length[1] >= 0): + write_test_files(mess_test,delay_length[1]) + if (not quiet): + print("Buffer delay testing = {} for: {}"\ + .format(read_test_files(buff_test),\ + buff_test.split("/")[5])) + print("Message delay testing = {} for: {}"\ + .format(read_test_files(mess_test),\ + mess_test.split("/")[5])) + except IOError as e: + errno, strerror = e.args + print("I/O error({0}): {1} on files {2}{3}"\ + .format(errno,strerror,buff_test,mess_test)) + exit(-1) + +#enabling/disabling delay testing on all devices +def delay_test_all_devices(dev_list,delay,quiet): + + for device in (dev_list): + if (get_test_state(device) is 0): + change_test_state(device,quiet) + delay_test_store(device,delay,quiet) + +#disabling testing on single device +def disable_testing_single_device(device,test_type,quiet): + + #test_type represents corresponding key + #delay method in delay_methods dict. + #special type 0 , used to disable all + #testing on SINGLE device. + + if (test_type is 1 or test_type is 0): + #disable list [buffer,message] + disable_delay = [0,0] + if (get_test_state(device) is 1): + change_test_state(device,quiet) + delay_test_store(device,disable_delay,quiet) + +#disabling testing on ALL devices +def disable_all_testing(dev_list,quiet): + + #delay disable list [buffer,message] + for device in dev_list: + disable_testing_single_device(device,0,quiet) + +if __name__ == "__main__": + main()
Signature · 1 line
2.17.1