Description:
                The /sys/power/suspend_stats/last_failed_step file contains
                the last failed step in the suspend/resume path.
+
+What:          /sys/power/sync_on_suspend
+Date:          October 2019
+Contact:       Jonas Meurer <jonas@freesources.org>
+Description:
+               This file controls whether or not the kernel will sync()
+               filesystems during system suspend (after freezing user space
+               and before suspending devices).
+
+               Writing a "1" to this file enables the sync() and writing a "0"
+               disables it.  Reads from the file return the current value.
+               The default is "1" if the build-time "SUSPEND_SKIP_SYNC" config
+               flag is unset, or "0" otherwise.
 
 extern void arch_suspend_enable_irqs(void);
 
 extern int pm_suspend(suspend_state_t state);
+extern bool sync_on_suspend_enabled;
 #else /* !CONFIG_SUSPEND */
 #define suspend_valid_only_mem NULL
 
 
 static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
+static inline bool sync_on_suspend_enabled(void) { return true; }
 static inline bool idle_should_enter_s2idle(void) { return false; }
 static inline void __init pm_states_init(void) {}
 static inline void s2idle_set_ops(const struct platform_s2idle_ops *ops) {}
 
          Skip the kernel sys_sync() before freezing user processes.
          Some systems prefer not to pay this cost on every invocation
          of suspend, or they are content with invoking sync() from
-         user-space before invoking suspend.  Say Y if that's your case.
+         user-space before invoking suspend.  There's a run-time switch
+         at '/sys/power/sync_on_suspend' to configure this behaviour.
+         This setting changes the default for the run-tim switch. Say Y
+         to change the default to disable the kernel sys_sync().
 
 config HIBERNATE_CALLBACKS
        bool
 
 }
 
 power_attr(mem_sleep);
+
+/*
+ * sync_on_suspend: invoke ksys_sync_helper() before suspend.
+ *
+ * show() returns whether ksys_sync_helper() is invoked before suspend.
+ * store() accepts 0 or 1.  0 disables ksys_sync_helper() and 1 enables it.
+ */
+bool sync_on_suspend_enabled = !IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC);
+
+static ssize_t sync_on_suspend_show(struct kobject *kobj,
+                                  struct kobj_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", sync_on_suspend_enabled);
+}
+
+static ssize_t sync_on_suspend_store(struct kobject *kobj,
+                                   struct kobj_attribute *attr,
+                                   const char *buf, size_t n)
+{
+       unsigned long val;
+
+       if (kstrtoul(buf, 10, &val))
+               return -EINVAL;
+
+       if (val > 1)
+               return -EINVAL;
+
+       sync_on_suspend_enabled = !!val;
+       return n;
+}
+
+power_attr(sync_on_suspend);
 #endif /* CONFIG_SUSPEND */
 
 #ifdef CONFIG_PM_SLEEP_DEBUG
        &wakeup_count_attr.attr,
 #ifdef CONFIG_SUSPEND
        &mem_sleep_attr.attr,
+       &sync_on_suspend_attr.attr,
 #endif
 #ifdef CONFIG_PM_AUTOSLEEP
        &autosleep_attr.attr,
 
        if (state == PM_SUSPEND_TO_IDLE)
                s2idle_begin();
 
-       if (!IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) {
+       if (sync_on_suspend_enabled) {
                trace_suspend_resume(TPS("sync_filesystems"), 0, true);
                ksys_sync_helper();
                trace_suspend_resume(TPS("sync_filesystems"), 0, false);