Re: [PATCH 1/3] xen: add generic fault injection facility
On 04/20/18 12:59, Juergen Gross wrote: On 20/04/18 12:47, Stanislav Kinsburskii wrote: diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig index c1f98f3..483fc16 100644 --- a/arch/x86/xen/Kconfig +++ b/arch/x86/xen/Kconfig @@ -77,3 +77,10 @@ config XEN_PVH bool "Support for running as a PVH guest" depends on XEN && XEN_PVHVM && ACPI def_bool n + +config XEN_FAULT_INJECTION + bool "Enable Xen fault injection" + depends on FAULT_INJECTION_DEBUG_FS + default n + help + Enable Xen fault injection facility Why for x86 only? I'd rather add this under drivers/xen Sure. diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile index d83cb54..3158fe1 100644 --- a/arch/x86/xen/Makefile +++ b/arch/x86/xen/Makefile @@ -34,3 +34,4 @@ obj-$(CONFIG_XEN_DOM0)+= vga.o obj-$(CONFIG_SWIOTLB_XEN) += pci-swiotlb-xen.o obj-$(CONFIG_XEN_EFI) += efi.o obj-$(CONFIG_XEN_PVH) += xen-pvh.o +obj-$(CONFIG_XEN_FAULT_INJECTION) += fault_inject.o diff --git a/arch/x86/xen/fault_inject.c b/arch/x86/xen/fault_inject.c new file mode 100644 index 000..ecf0f7c --- /dev/null +++ b/arch/x86/xen/fault_inject.c @@ -0,0 +1,109 @@ +/* + * Fauit injection interface for Xen virtual block devices + * + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: Please use the appropriate SPDX header instead of the full GPL2 boilerplate. Ditto. Juergen Amazon Development Center Germany GmbH Berlin - Dresden - Aachen main office: Krausenstr. 38, 10117 Berlin Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger Ust-ID: DE289237879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Re: [PATCH 1/3] xen: add generic fault injection facility
On 20/04/18 12:47, Stanislav Kinsburskii wrote: > The overall idea of this patch is to add a generic fault injection facility > to Xen, which later can be used in various places by different Xen parts. > > Core implementation ideas: > > - The facility build is controlled by boolean config > CONFIG_XEN_FAULT_INJECTION option ("N" by default). > > - All fault injection logic is located in an optionally compiled separated > file. > > - Fault injection attribute and control directory creation and destruction > are wrapped with helpers, producing and accepting a pointer to an opaque > object thus making all the rest of code independent on fault injection > engine. > > When enabled Xen root fault injection directory appears: > > - /sys/kernel/debug/xen/fault_inject/ > > The falicity provides the following helpers (exported to be accessible in > modules): > > - xen_fi_add(name) - adds fault injection control directory "name" to Xen > root fault injection directory > > - xen_fi_dir_create(name) - allows to create a subdirectory "name" in Xen > root fault injection directory. > > - xen_fi_dir_add(dir, name) - adds fault injection control directory "name" > to directory "dir" > > - xen_should_fail(fi) - check whether fi hav to fail. > > Signed-off-by: Stanislav Kinsburskii> CC: Boris Ostrovsky > CC: Juergen Gross > CC: Thomas Gleixner > CC: Ingo Molnar > CC: "H. Peter Anvin" > CC: x...@kernel.org > CC: xen-de...@lists.xenproject.org > CC: linux-ker...@vger.kernel.org > CC: Stanislav Kinsburskii > CC: David Woodhouse > --- > arch/x86/xen/Kconfig|7 +++ > arch/x86/xen/Makefile |1 > arch/x86/xen/fault_inject.c | 109 > +++ > include/xen/fault_inject.h | 45 ++ > 4 files changed, 162 insertions(+) > create mode 100644 arch/x86/xen/fault_inject.c > create mode 100644 include/xen/fault_inject.h > > diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig > index c1f98f3..483fc16 100644 > --- a/arch/x86/xen/Kconfig > +++ b/arch/x86/xen/Kconfig > @@ -77,3 +77,10 @@ config XEN_PVH > bool "Support for running as a PVH guest" > depends on XEN && XEN_PVHVM && ACPI > def_bool n > + > +config XEN_FAULT_INJECTION > + bool "Enable Xen fault injection" > + depends on FAULT_INJECTION_DEBUG_FS > + default n > + help > + Enable Xen fault injection facility Why for x86 only? I'd rather add this under drivers/xen > diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile > index d83cb54..3158fe1 100644 > --- a/arch/x86/xen/Makefile > +++ b/arch/x86/xen/Makefile > @@ -34,3 +34,4 @@ obj-$(CONFIG_XEN_DOM0) += vga.o > obj-$(CONFIG_SWIOTLB_XEN)+= pci-swiotlb-xen.o > obj-$(CONFIG_XEN_EFI)+= efi.o > obj-$(CONFIG_XEN_PVH)+= xen-pvh.o > +obj-$(CONFIG_XEN_FAULT_INJECTION)+= fault_inject.o > diff --git a/arch/x86/xen/fault_inject.c b/arch/x86/xen/fault_inject.c > new file mode 100644 > index 000..ecf0f7c > --- /dev/null > +++ b/arch/x86/xen/fault_inject.c > @@ -0,0 +1,109 @@ > +/* > + * Fauit injection interface for Xen virtual block devices > + * > + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License version 2 > + * as published by the Free Software Foundation; or, when distributed > + * separately from the Linux kernel or incorporated into other > + * software packages, subject to the following license: Please use the appropriate SPDX header instead of the full GPL2 boilerplate. Juergen
[PATCH 1/3] xen: add generic fault injection facility
The overall idea of this patch is to add a generic fault injection facility to Xen, which later can be used in various places by different Xen parts. Core implementation ideas: - The facility build is controlled by boolean config CONFIG_XEN_FAULT_INJECTION option ("N" by default). - All fault injection logic is located in an optionally compiled separated file. - Fault injection attribute and control directory creation and destruction are wrapped with helpers, producing and accepting a pointer to an opaque object thus making all the rest of code independent on fault injection engine. When enabled Xen root fault injection directory appears: - /sys/kernel/debug/xen/fault_inject/ The falicity provides the following helpers (exported to be accessible in modules): - xen_fi_add(name) - adds fault injection control directory "name" to Xen root fault injection directory - xen_fi_dir_create(name) - allows to create a subdirectory "name" in Xen root fault injection directory. - xen_fi_dir_add(dir, name) - adds fault injection control directory "name" to directory "dir" - xen_should_fail(fi) - check whether fi hav to fail. Signed-off-by: Stanislav KinsburskiiCC: Boris Ostrovsky CC: Juergen Gross CC: Thomas Gleixner CC: Ingo Molnar CC: "H. Peter Anvin" CC: x...@kernel.org CC: xen-de...@lists.xenproject.org CC: linux-ker...@vger.kernel.org CC: Stanislav Kinsburskii CC: David Woodhouse --- arch/x86/xen/Kconfig|7 +++ arch/x86/xen/Makefile |1 arch/x86/xen/fault_inject.c | 109 +++ include/xen/fault_inject.h | 45 ++ 4 files changed, 162 insertions(+) create mode 100644 arch/x86/xen/fault_inject.c create mode 100644 include/xen/fault_inject.h diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig index c1f98f3..483fc16 100644 --- a/arch/x86/xen/Kconfig +++ b/arch/x86/xen/Kconfig @@ -77,3 +77,10 @@ config XEN_PVH bool "Support for running as a PVH guest" depends on XEN && XEN_PVHVM && ACPI def_bool n + +config XEN_FAULT_INJECTION + bool "Enable Xen fault injection" + depends on FAULT_INJECTION_DEBUG_FS + default n + help + Enable Xen fault injection facility diff --git a/arch/x86/xen/Makefile b/arch/x86/xen/Makefile index d83cb54..3158fe1 100644 --- a/arch/x86/xen/Makefile +++ b/arch/x86/xen/Makefile @@ -34,3 +34,4 @@ obj-$(CONFIG_XEN_DOM0)+= vga.o obj-$(CONFIG_SWIOTLB_XEN) += pci-swiotlb-xen.o obj-$(CONFIG_XEN_EFI) += efi.o obj-$(CONFIG_XEN_PVH) += xen-pvh.o +obj-$(CONFIG_XEN_FAULT_INJECTION) += fault_inject.o diff --git a/arch/x86/xen/fault_inject.c b/arch/x86/xen/fault_inject.c new file mode 100644 index 000..ecf0f7c --- /dev/null +++ b/arch/x86/xen/fault_inject.c @@ -0,0 +1,109 @@ +/* + * Fauit injection interface for Xen virtual block devices + * + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + +#include + +#include "debugfs.h" + +static struct dentry *d_fi_debug; + +static DECLARE_FAULT_ATTR(template_attr); + +struct xen_fi { + struct dentry *dir; + struct fault_attr attr; +}; + +struct xen_fi *xen_fi_dir_add(struct dentry *parent, const char *name) +{ + struct xen_fi *fi; + struct dentry *dir; + + fi = kzalloc(sizeof(*fi), GFP_KERNEL); + if (!fi) +