Re: [PATCH v6 3/6] powerpc/fadump: reorganize /sys/kernel/fadump_* sysfs files

2020-01-08 Thread Michal Suchánek
On Wed, Dec 11, 2019 at 09:39:07PM +0530, Sourabh Jain wrote:
> As the number of FADump sysfs files increases it is hard to manage all of
> them inside /sys/kernel directory. It's better to have all the FADump
> related sysfs files in a dedicated directory /sys/kernel/fadump. But in
> order to maintain backward compatibility a symlink has been added for every
> sysfs that has moved to new location.

Patched this series into my test kernel and the sysfs sfiles look OK.

Tested-by: Michal Suchanek 

Thanks

Michal


[PATCH v6 3/6] powerpc/fadump: reorganize /sys/kernel/fadump_* sysfs files

2019-12-11 Thread Sourabh Jain
As the number of FADump sysfs files increases it is hard to manage all of
them inside /sys/kernel directory. It's better to have all the FADump
related sysfs files in a dedicated directory /sys/kernel/fadump. But in
order to maintain backward compatibility a symlink has been added for every
sysfs that has moved to new location.

As the FADump sysfs files are now part of a dedicated directory there is no
need to prefix their name with fadump_, hence sysfs file names are also
updated. For example fadump_enabled sysfs file is now referred as enabled.

Also consolidate ABI documentation for all the FADump sysfs files in a
single file Documentation/ABI/testing/sysfs-kernel-fadump.

Signed-off-by: Sourabh Jain 
---
 Documentation/ABI/testing/sysfs-kernel-fadump |  33 +
 arch/powerpc/kernel/fadump.c  | 118 +-
 2 files changed, 117 insertions(+), 34 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-fadump

diff --git a/Documentation/ABI/testing/sysfs-kernel-fadump 
b/Documentation/ABI/testing/sysfs-kernel-fadump
new file mode 100644
index ..5d988b919e81
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-fadump
@@ -0,0 +1,33 @@
+What:  /sys/kernel/fadump/*
+Date:  Dec 2019
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:
+   The /sys/kernel/fadump/* is a collection of FADump sysfs
+   file provide information about the configuration status
+   of Firmware Assisted Dump (FADump).
+
+What:  /sys/kernel/fadump/enabled
+Date:  Dec 2019
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   read only
+   Primarily used to identify whether the FADump is enabled in
+   the kernel or not.
+User:  Kdump service
+
+What:  /sys/kernel/fadump/registered
+Date:  Dec 2019
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   read/write
+   Helps to control the dump collect feature from userspace.
+   Setting 1 to this file enables the system to collect the
+   dump and 0 to disable it.
+User:  Kdump service
+
+What:  /sys/kernel/fadump/release_mem
+Date:  Dec 2019
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   write only
+   This is a special sysfs file and only available when
+   the system is booted to capture the vmcore using FADump.
+   It is used to release the memory reserved by FADump to
+   save the crash dump.
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index ed59855430b9..23f15bfea512 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -36,6 +36,8 @@ static struct fw_dump fw_dump;
 
 static void __init fadump_reserve_crash_area(u64 base);
 
+struct kobject *fadump_kobj;
+
 #ifndef CONFIG_PRESERVE_FA_DUMP
 static DEFINE_MUTEX(fadump_mutex);
 struct fadump_mrange_info crash_mrange_info = { "crash", NULL, 0, 0, 0 };
@@ -1323,9 +1325,9 @@ static void fadump_invalidate_release_mem(void)
fw_dump.ops->fadump_init_mem_struct(_dump);
 }
 
-static ssize_t fadump_release_memory_store(struct kobject *kobj,
-   struct kobj_attribute *attr,
-   const char *buf, size_t count)
+static ssize_t release_mem_store(struct kobject *kobj,
+struct kobj_attribute *attr,
+const char *buf, size_t count)
 {
int input = -1;
 
@@ -1350,23 +1352,33 @@ static ssize_t fadump_release_memory_store(struct 
kobject *kobj,
return count;
 }
 
-static ssize_t fadump_enabled_show(struct kobject *kobj,
-   struct kobj_attribute *attr,
-   char *buf)
+/* Release the reserved memory and disable the FADump */
+static void unregister_fadump(void)
+{
+   fadump_cleanup();
+   fadump_release_memory(fw_dump.reserve_dump_area_start,
+ fw_dump.reserve_dump_area_size);
+   fw_dump.fadump_enabled = 0;
+   kobject_put(fadump_kobj);
+}
+
+static ssize_t enabled_show(struct kobject *kobj,
+   struct kobj_attribute *attr,
+   char *buf)
 {
return sprintf(buf, "%d\n", fw_dump.fadump_enabled);
 }
 
-static ssize_t fadump_register_show(struct kobject *kobj,
-   struct kobj_attribute *attr,
-   char *buf)
+static ssize_t registered_show(struct kobject *kobj,
+  struct kobj_attribute *attr,
+  char *buf)
 {
return sprintf(buf, "%d\n", fw_dump.dump_registered);
 }
 
-static ssize_t fadump_register_store(struct kobject *kobj,
-   struct kobj_attribute *attr,
-