--- /dev/null
+From c9e716eb9b3455a83ed7c5f5a81256a3da779a95 Mon Sep 17 00:00:00 2001
+From: Andreas Dilger <adilger@dilger.ca>
+Date: Thu, 14 Feb 2019 17:52:18 -0500
+Subject: ext4: don't update s_rev_level if not required
+
+From: Andreas Dilger <adilger@dilger.ca>
+
+commit c9e716eb9b3455a83ed7c5f5a81256a3da779a95 upstream.
+
+Don't update the superblock s_rev_level during mount if it isn't
+actually necessary, only if superblock features are being set by
+the kernel. This was originally added for ext3 since it always
+set the INCOMPAT_RECOVER and HAS_JOURNAL features during mount,
+but this is not needed since no journal mode was added to ext4.
+
+That will allow Geert to mount his 20-year-old ext2 rev 0.0 m68k
+filesystem, as a testament of the backward compatibility of ext4.
+
+Fixes: 0390131ba84f ("ext4: Allow ext4 to run without a journal")
+Signed-off-by: Andreas Dilger <adilger@dilger.ca>
+Signed-off-by: Theodore Ts'o <tytso@mit.edu>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/ext4/ext4.h | 6 +++++-
+ fs/ext4/inode.c | 1 -
+ fs/ext4/super.c | 1 -
+ 3 files changed, 5 insertions(+), 3 deletions(-)
+
+--- a/fs/ext4/ext4.h
++++ b/fs/ext4/ext4.h
+@@ -1670,6 +1670,8 @@ static inline void ext4_clear_state_flag
+ #define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */
+ #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000
+
++extern void ext4_update_dynamic_rev(struct super_block *sb);
++
+ #define EXT4_FEATURE_COMPAT_FUNCS(name, flagname) \
+ static inline bool ext4_has_feature_##name(struct super_block *sb) \
+ { \
+@@ -1678,6 +1680,7 @@ static inline bool ext4_has_feature_##na
+ } \
+ static inline void ext4_set_feature_##name(struct super_block *sb) \
+ { \
++ ext4_update_dynamic_rev(sb); \
+ EXT4_SB(sb)->s_es->s_feature_compat |= \
+ cpu_to_le32(EXT4_FEATURE_COMPAT_##flagname); \
+ } \
+@@ -1695,6 +1698,7 @@ static inline bool ext4_has_feature_##na
+ } \
+ static inline void ext4_set_feature_##name(struct super_block *sb) \
+ { \
++ ext4_update_dynamic_rev(sb); \
+ EXT4_SB(sb)->s_es->s_feature_ro_compat |= \
+ cpu_to_le32(EXT4_FEATURE_RO_COMPAT_##flagname); \
+ } \
+@@ -1712,6 +1716,7 @@ static inline bool ext4_has_feature_##na
+ } \
+ static inline void ext4_set_feature_##name(struct super_block *sb) \
+ { \
++ ext4_update_dynamic_rev(sb); \
+ EXT4_SB(sb)->s_es->s_feature_incompat |= \
+ cpu_to_le32(EXT4_FEATURE_INCOMPAT_##flagname); \
+ } \
+@@ -2679,7 +2684,6 @@ do { \
+
+ #endif
+
+-extern void ext4_update_dynamic_rev(struct super_block *sb);
+ extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb,
+ __u32 compat);
+ extern int ext4_update_rocompat_feature(handle_t *handle,
+--- a/fs/ext4/inode.c
++++ b/fs/ext4/inode.c
+@@ -5324,7 +5324,6 @@ static int ext4_do_update_inode(handle_t
+ err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
+ if (err)
+ goto out_brelse;
+- ext4_update_dynamic_rev(sb);
+ ext4_set_feature_large_file(sb);
+ ext4_handle_sync(handle);
+ err = ext4_handle_dirty_super(handle, sb);
+--- a/fs/ext4/super.c
++++ b/fs/ext4/super.c
+@@ -2259,7 +2259,6 @@ static int ext4_setup_super(struct super
+ es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
+ le16_add_cpu(&es->s_mnt_count, 1);
+ ext4_update_tstamp(es, s_mtime);
+- ext4_update_dynamic_rev(sb);
+ if (sbi->s_journal)
+ ext4_set_feature_journal_needs_recovery(sb);
+
--- /dev/null
+From 170417c8c7bb2cbbdd949bf5c443c0c8f24a203b Mon Sep 17 00:00:00 2001
+From: Theodore Ts'o <tytso@mit.edu>
+Date: Wed, 15 May 2019 00:51:19 -0400
+Subject: ext4: fix block validity checks for journal inodes using indirect blocks
+
+From: Theodore Ts'o <tytso@mit.edu>
+
+commit 170417c8c7bb2cbbdd949bf5c443c0c8f24a203b upstream.
+
+Commit 345c0dbf3a30 ("ext4: protect journal inode's blocks using
+block_validity") failed to add an exception for the journal inode in
+ext4_check_blockref(), which is the function used by ext4_get_branch()
+for indirect blocks. This caused attempts to read from the ext3-style
+journals to fail with:
+
+[ 848.968550] EXT4-fs error (device sdb7): ext4_get_branch:171: inode #8: block 30343695: comm jbd2/sdb7-8: invalid block
+
+Fix this by adding the missing exception check.
+
+Fixes: 345c0dbf3a30 ("ext4: protect journal inode's blocks using block_validity")
+Reported-by: Arthur Marsh <arthur.marsh@internode.on.net>
+Signed-off-by: Theodore Ts'o <tytso@mit.edu>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/ext4/block_validity.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+--- a/fs/ext4/block_validity.c
++++ b/fs/ext4/block_validity.c
+@@ -276,6 +276,11 @@ int ext4_check_blockref(const char *func
+ __le32 *bref = p;
+ unsigned int blk;
+
++ if (ext4_has_feature_journal(inode->i_sb) &&
++ (inode->i_ino ==
++ le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_journal_inum)))
++ return 0;
++
+ while (bref < p+max) {
+ blk = le32_to_cpu(*bref++);
+ if (blk &&
--- /dev/null
+From ddccb6dbe780d68133191477571cb7c69e17bb8c Mon Sep 17 00:00:00 2001
+From: "zhangyi (F)" <yi.zhang@huawei.com>
+Date: Thu, 21 Feb 2019 11:29:10 -0500
+Subject: ext4: fix compile error when using BUFFER_TRACE
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: zhangyi (F) <yi.zhang@huawei.com>
+
+commit ddccb6dbe780d68133191477571cb7c69e17bb8c upstream.
+
+Fix compile error below when using BUFFER_TRACE.
+
+fs/ext4/inode.c: In function ‘ext4_expand_extra_isize’:
+fs/ext4/inode.c:5979:19: error: request for member ‘bh’ in something not a structure or union
+ BUFFER_TRACE(iloc.bh, "get_write_access");
+
+Fixes: c03b45b853f58 ("ext4, project: expand inode extra size if possible")
+Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
+Signed-off-by: Theodore Ts'o <tytso@mit.edu>
+Reviewed-by: Jan Kara <jack@suse.cz>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/ext4/inode.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/fs/ext4/inode.c
++++ b/fs/ext4/inode.c
+@@ -5975,7 +5975,7 @@ int ext4_expand_extra_isize(struct inode
+
+ ext4_write_lock_xattr(inode, &no_expand);
+
+- BUFFER_TRACE(iloc.bh, "get_write_access");
++ BUFFER_TRACE(iloc->bh, "get_write_access");
+ error = ext4_journal_get_write_access(handle, iloc->bh);
+ if (error) {
+ brelse(iloc->bh);
--- /dev/null
+From fbbbbd2f28aec991f3fbc248df211550fbdfd58c Mon Sep 17 00:00:00 2001
+From: Colin Ian King <colin.king@canonical.com>
+Date: Fri, 10 May 2019 22:06:38 -0400
+Subject: ext4: unsigned int compared against zero
+
+From: Colin Ian King <colin.king@canonical.com>
+
+commit fbbbbd2f28aec991f3fbc248df211550fbdfd58c upstream.
+
+There are two cases where u32 variables n and err are being checked
+for less than zero error values, the checks is always false because
+the variables are not signed. Fix this by making the variables ints.
+
+Addresses-Coverity: ("Unsigned compared against 0")
+Fixes: 345c0dbf3a30 ("ext4: protect journal inode's blocks using block_validity")
+Signed-off-by: Colin Ian King <colin.king@canonical.com>
+Signed-off-by: Theodore Ts'o <tytso@mit.edu>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/ext4/block_validity.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+--- a/fs/ext4/block_validity.c
++++ b/fs/ext4/block_validity.c
+@@ -142,7 +142,8 @@ static int ext4_protect_reserved_inode(s
+ struct inode *inode;
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+ struct ext4_map_blocks map;
+- u32 i = 0, err = 0, num, n;
++ u32 i = 0, num;
++ int err = 0, n;
+
+ if ((ino < EXT4_ROOT_INO) ||
+ (ino > le32_to_cpu(sbi->s_es->s_inodes_count)))
--- /dev/null
+From 6daef95b8c914866a46247232a048447fff97279 Mon Sep 17 00:00:00 2001
+From: Eric Dumazet <edumazet@google.com>
+Date: Tue, 26 Feb 2019 10:42:39 -0800
+Subject: iov_iter: optimize page_copy_sane()
+
+From: Eric Dumazet <edumazet@google.com>
+
+commit 6daef95b8c914866a46247232a048447fff97279 upstream.
+
+Avoid cache line miss dereferencing struct page if we can.
+
+page_copy_sane() mostly deals with order-0 pages.
+
+Extra cache line miss is visible on TCP recvmsg() calls dealing
+with GRO packets (typically 45 page frags are attached to one skb).
+
+Bringing the 45 struct pages into cpu cache while copying the data
+is not free, since the freeing of the skb (and associated
+page frags put_page()) can happen after cache lines have been evicted.
+
+Signed-off-by: Eric Dumazet <edumazet@google.com>
+Cc: Al Viro <viro@zeniv.linux.org.uk>
+Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
+Cc: Matthew Wilcox <willy@infradead.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ lib/iov_iter.c | 17 +++++++++++++++--
+ 1 file changed, 15 insertions(+), 2 deletions(-)
+
+--- a/lib/iov_iter.c
++++ b/lib/iov_iter.c
+@@ -817,8 +817,21 @@ EXPORT_SYMBOL(_copy_from_iter_full_nocac
+
+ static inline bool page_copy_sane(struct page *page, size_t offset, size_t n)
+ {
+- struct page *head = compound_head(page);
+- size_t v = n + offset + page_address(page) - page_address(head);
++ struct page *head;
++ size_t v = n + offset;
++
++ /*
++ * The general case needs to access the page order in order
++ * to compute the page size.
++ * However, we mostly deal with order-0 pages and thus can
++ * avoid a possible cache line miss for requests that fit all
++ * page orders.
++ */
++ if (n <= v && v <= PAGE_SIZE)
++ return true;
++
++ head = compound_head(page);
++ v += (page - head) << PAGE_SHIFT;
+
+ if (likely(n <= v && v <= (PAGE_SIZE << compound_order(head))))
+ return true;
--- /dev/null
+From d2f8ae0e4c5c754f1b2a7b8388d19a1a977e698a Mon Sep 17 00:00:00 2001
+From: Masahiro Yamada <yamada.masahiro@socionext.com>
+Date: Sun, 12 May 2019 11:13:48 +0900
+Subject: kbuild: turn auto.conf.cmd into a mandatory include file
+
+From: Masahiro Yamada <yamada.masahiro@socionext.com>
+
+commit d2f8ae0e4c5c754f1b2a7b8388d19a1a977e698a upstream.
+
+syncconfig is responsible for keeping auto.conf up-to-date, so if it
+fails for any reason, the build must be terminated immediately.
+
+However, since commit 9390dff66a52 ("kbuild: invoke syncconfig if
+include/config/auto.conf.cmd is missing"), Kbuild continues running
+even after syncconfig fails.
+
+You can confirm this by intentionally making syncconfig error out:
+
+# diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
+# index 08ba146..307b9de 100644
+# --- a/scripts/kconfig/confdata.c
+# +++ b/scripts/kconfig/confdata.c
+# @@ -1023,6 +1023,9 @@ int conf_write_autoconf(int overwrite)
+# FILE *out, *tristate, *out_h;
+# int i;
+#
+# + if (overwrite)
+# + return 1;
+# +
+# if (!overwrite && is_present(autoconf_name))
+# return 0;
+
+Then, syncconfig fails, but Make would not stop:
+
+ $ make -s mrproper allyesconfig defconfig
+ $ make
+ scripts/kconfig/conf --syncconfig Kconfig
+
+ *** Error during sync of the configuration.
+
+ make[2]: *** [scripts/kconfig/Makefile;69: syncconfig] Error 1
+ make[1]: *** [Makefile;557: syncconfig] Error 2
+ make: *** [include/config/auto.conf.cmd] Deleting file 'include/config/tristate.conf'
+ make: Failed to remake makefile 'include/config/auto.conf'.
+ SYSTBL arch/x86/include/generated/asm/syscalls_32.h
+ SYSHDR arch/x86/include/generated/asm/unistd_32_ia32.h
+ SYSHDR arch/x86/include/generated/asm/unistd_64_x32.h
+ SYSTBL arch/x86/include/generated/asm/syscalls_64.h
+ [ continue running ... ]
+
+The reason is in the behavior of a pattern rule with multi-targets.
+
+ %/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG)
+ $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
+
+GNU Make knows this rule is responsible for making all the three files
+simultaneously. As far as examined, auto.conf.cmd is the target in
+question when this rule is invoked. It is probably because auto.conf.cmd
+is included below the inclusion of auto.conf.
+
+The inclusion of auto.conf is mandatory, while that of auto.conf.cmd
+is optional. GNU Make does not care about the failure in the process
+of updating optional include files.
+
+I filed this issue (https://savannah.gnu.org/bugs/?56301) in case this
+behavior could be improved somehow in future releases of GNU Make.
+Anyway, it is quite easy to fix our Makefile.
+
+Given that auto.conf is already a mandatory include file, there is no
+reason to stick auto.conf.cmd optional. Make it mandatory as well.
+
+Cc: linux-stable <stable@vger.kernel.org> # 5.0+
+Fixes: 9390dff66a52 ("kbuild: invoke syncconfig if include/config/auto.conf.cmd is missing")
+Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
+[commented out diff above to keep patch happy - gregkh]
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ Makefile | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/Makefile
++++ b/Makefile
+@@ -623,7 +623,7 @@ ifeq ($(may-sync-config),1)
+ # Read in dependencies to all Kconfig* files, make sure to run syncconfig if
+ # changes are detected. This should be included after arch/$(SRCARCH)/Makefile
+ # because some architectures define CROSS_COMPILE there.
+--include include/config/auto.conf.cmd
++include include/config/auto.conf.cmd
+
+ # To avoid any implicit rule to kick in, define an empty command
+ $(KCONFIG_CONFIG): ;
--- /dev/null
+From c4703ce11c23423d4b46e3d59aef7979814fd608 Mon Sep 17 00:00:00 2001
+From: Dan Williams <dan.j.williams@intel.com>
+Date: Tue, 30 Apr 2019 21:51:21 -0700
+Subject: libnvdimm/namespace: Fix label tracking error
+
+From: Dan Williams <dan.j.williams@intel.com>
+
+commit c4703ce11c23423d4b46e3d59aef7979814fd608 upstream.
+
+Users have reported intermittent occurrences of DIMM initialization
+failures due to duplicate allocations of address capacity detected in
+the labels, or errors of the form below, both have the same root cause.
+
+ nd namespace1.4: failed to track label: 0
+ WARNING: CPU: 17 PID: 1381 at drivers/nvdimm/label.c:863
+
+ RIP: 0010:__pmem_label_update+0x56c/0x590 [libnvdimm]
+ Call Trace:
+ ? nd_pmem_namespace_label_update+0xd6/0x160 [libnvdimm]
+ nd_pmem_namespace_label_update+0xd6/0x160 [libnvdimm]
+ uuid_store+0x17e/0x190 [libnvdimm]
+ kernfs_fop_write+0xf0/0x1a0
+ vfs_write+0xb7/0x1b0
+ ksys_write+0x57/0xd0
+ do_syscall_64+0x60/0x210
+
+Unfortunately those reports were typically with a busy parallel
+namespace creation / destruction loop making it difficult to see the
+components of the bug. However, Jane provided a simple reproducer using
+the work-in-progress sub-section implementation.
+
+When ndctl is reconfiguring a namespace it may take an existing defunct
+/ disabled namespace and reconfigure it with a new uuid and other
+parameters. Critically namespace_update_uuid() takes existing address
+resources and renames them for the new namespace to use / reconfigure as
+it sees fit. The bug is that this rename only happens in the resource
+tracking tree. Existing labels with the old uuid are not reaped leading
+to a scenario where multiple active labels reference the same span of
+address range.
+
+Teach namespace_update_uuid() to flag any references to the old uuid for
+reaping at the next label update attempt.
+
+Cc: <stable@vger.kernel.org>
+Fixes: bf9bccc14c05 ("libnvdimm: pmem label sets and namespace instantiation")
+Link: https://github.com/pmem/ndctl/issues/91
+Reported-by: Jane Chu <jane.chu@oracle.com>
+Reported-by: Jeff Moyer <jmoyer@redhat.com>
+Reported-by: Erwin Tsaur <erwin.tsaur@oracle.com>
+Cc: Johannes Thumshirn <jthumshirn@suse.de>
+Signed-off-by: Dan Williams <dan.j.williams@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/nvdimm/label.c | 29 ++++++++++++++++-------------
+ drivers/nvdimm/namespace_devs.c | 15 +++++++++++++++
+ drivers/nvdimm/nd.h | 4 ++++
+ 3 files changed, 35 insertions(+), 13 deletions(-)
+
+--- a/drivers/nvdimm/label.c
++++ b/drivers/nvdimm/label.c
+@@ -623,6 +623,17 @@ static const guid_t *to_abstraction_guid
+ return &guid_null;
+ }
+
++static void reap_victim(struct nd_mapping *nd_mapping,
++ struct nd_label_ent *victim)
++{
++ struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
++ u32 slot = to_slot(ndd, victim->label);
++
++ dev_dbg(ndd->dev, "free: %d\n", slot);
++ nd_label_free_slot(ndd, slot);
++ victim->label = NULL;
++}
++
+ static int __pmem_label_update(struct nd_region *nd_region,
+ struct nd_mapping *nd_mapping, struct nd_namespace_pmem *nspm,
+ int pos, unsigned long flags)
+@@ -630,9 +641,9 @@ static int __pmem_label_update(struct nd
+ struct nd_namespace_common *ndns = &nspm->nsio.common;
+ struct nd_interleave_set *nd_set = nd_region->nd_set;
+ struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
+- struct nd_label_ent *label_ent, *victim = NULL;
+ struct nd_namespace_label *nd_label;
+ struct nd_namespace_index *nsindex;
++ struct nd_label_ent *label_ent;
+ struct nd_label_id label_id;
+ struct resource *res;
+ unsigned long *free;
+@@ -701,18 +712,10 @@ static int __pmem_label_update(struct nd
+ list_for_each_entry(label_ent, &nd_mapping->labels, list) {
+ if (!label_ent->label)
+ continue;
+- if (memcmp(nspm->uuid, label_ent->label->uuid,
+- NSLABEL_UUID_LEN) != 0)
+- continue;
+- victim = label_ent;
+- list_move_tail(&victim->list, &nd_mapping->labels);
+- break;
+- }
+- if (victim) {
+- dev_dbg(ndd->dev, "free: %d\n", slot);
+- slot = to_slot(ndd, victim->label);
+- nd_label_free_slot(ndd, slot);
+- victim->label = NULL;
++ if (test_and_clear_bit(ND_LABEL_REAP, &label_ent->flags)
++ || memcmp(nspm->uuid, label_ent->label->uuid,
++ NSLABEL_UUID_LEN) == 0)
++ reap_victim(nd_mapping, label_ent);
+ }
+
+ /* update index */
+--- a/drivers/nvdimm/namespace_devs.c
++++ b/drivers/nvdimm/namespace_devs.c
+@@ -1248,12 +1248,27 @@ static int namespace_update_uuid(struct
+ for (i = 0; i < nd_region->ndr_mappings; i++) {
+ struct nd_mapping *nd_mapping = &nd_region->mapping[i];
+ struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
++ struct nd_label_ent *label_ent;
+ struct resource *res;
+
+ for_each_dpa_resource(ndd, res)
+ if (strcmp(res->name, old_label_id.id) == 0)
+ sprintf((void *) res->name, "%s",
+ new_label_id.id);
++
++ mutex_lock(&nd_mapping->lock);
++ list_for_each_entry(label_ent, &nd_mapping->labels, list) {
++ struct nd_namespace_label *nd_label = label_ent->label;
++ struct nd_label_id label_id;
++
++ if (!nd_label)
++ continue;
++ nd_label_gen_id(&label_id, nd_label->uuid,
++ __le32_to_cpu(nd_label->flags));
++ if (strcmp(old_label_id.id, label_id.id) == 0)
++ set_bit(ND_LABEL_REAP, &label_ent->flags);
++ }
++ mutex_unlock(&nd_mapping->lock);
+ }
+ kfree(*old_uuid);
+ out:
+--- a/drivers/nvdimm/nd.h
++++ b/drivers/nvdimm/nd.h
+@@ -113,8 +113,12 @@ struct nd_percpu_lane {
+ spinlock_t lock;
+ };
+
++enum nd_label_flags {
++ ND_LABEL_REAP,
++};
+ struct nd_label_ent {
+ struct list_head list;
++ unsigned long flags;
+ struct nd_namespace_label *label;
+ };
+
--- /dev/null
+From 416031653eb55f844e3547fb8f8576399a800da0 Mon Sep 17 00:00:00 2001
+From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
+Date: Wed, 17 Oct 2018 03:13:55 -0700
+Subject: pstore: Allocate compression during late_initcall()
+
+From: Joel Fernandes (Google) <joel@joelfernandes.org>
+
+commit 416031653eb55f844e3547fb8f8576399a800da0 upstream.
+
+ramoops's call of pstore_register() was recently moved to run during
+late_initcall() because the crypto backend may not have been ready during
+postcore_initcall(). This meant early-boot crash dumps were not getting
+caught by pstore any more.
+
+Instead, lets allow calls to pstore_register() earlier, and once crypto
+is ready we can initialize the compression.
+
+Reported-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
+Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
+Tested-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
+Fixes: cb3bee0369bc ("pstore: Use crypto compress API")
+[kees: trivial rebase]
+Signed-off-by: Kees Cook <keescook@chromium.org>
+Tested-by: Guenter Roeck <groeck@chromium.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/pstore/platform.c | 10 +++++++++-
+ fs/pstore/ram.c | 2 +-
+ 2 files changed, 10 insertions(+), 2 deletions(-)
+
+--- a/fs/pstore/platform.c
++++ b/fs/pstore/platform.c
+@@ -786,13 +786,21 @@ static int __init pstore_init(void)
+
+ pstore_choose_compression();
+
++ /*
++ * Check if any pstore backends registered earlier but did not
++ * initialize compression because crypto was not ready. If so,
++ * initialize compression now.
++ */
++ if (psinfo && !tfm)
++ allocate_buf_for_compression();
++
+ ret = pstore_init_fs();
+ if (ret)
+ return ret;
+
+ return 0;
+ }
+-module_init(pstore_init)
++late_initcall(pstore_init);
+
+ static void __exit pstore_exit(void)
+ {
+--- a/fs/pstore/ram.c
++++ b/fs/pstore/ram.c
+@@ -956,7 +956,7 @@ static int __init ramoops_init(void)
+
+ return ret;
+ }
+-late_initcall(ramoops_init);
++postcore_initcall(ramoops_init);
+
+ static void __exit ramoops_exit(void)
+ {
--- /dev/null
+From cb095afd44768bf495894b9ad063bd078e4bb201 Mon Sep 17 00:00:00 2001
+From: Kees Cook <keescook@chromium.org>
+Date: Thu, 18 Oct 2018 11:17:42 -0700
+Subject: pstore: Centralize init/exit routines
+
+From: Kees Cook <keescook@chromium.org>
+
+commit cb095afd44768bf495894b9ad063bd078e4bb201 upstream.
+
+In preparation for having additional actions during init/exit, this moves
+the init/exit into platform.c, centralizing the logic to make call outs
+to the fs init/exit.
+
+Signed-off-by: Kees Cook <keescook@chromium.org>
+Tested-by: Guenter Roeck <groeck@chromium.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/pstore/inode.c | 11 ++---------
+ fs/pstore/internal.h | 5 +++--
+ fs/pstore/platform.c | 23 +++++++++++++++++++++++
+ 3 files changed, 28 insertions(+), 11 deletions(-)
+
+--- a/fs/pstore/inode.c
++++ b/fs/pstore/inode.c
+@@ -482,12 +482,10 @@ static struct file_system_type pstore_fs
+ .kill_sb = pstore_kill_sb,
+ };
+
+-static int __init init_pstore_fs(void)
++int __init pstore_init_fs(void)
+ {
+ int err;
+
+- pstore_choose_compression();
+-
+ /* Create a convenient mount point for people to access pstore */
+ err = sysfs_create_mount_point(fs_kobj, "pstore");
+ if (err)
+@@ -500,14 +498,9 @@ static int __init init_pstore_fs(void)
+ out:
+ return err;
+ }
+-module_init(init_pstore_fs)
+
+-static void __exit exit_pstore_fs(void)
++void __exit pstore_exit_fs(void)
+ {
+ unregister_filesystem(&pstore_fs_type);
+ sysfs_remove_mount_point(fs_kobj, "pstore");
+ }
+-module_exit(exit_pstore_fs)
+-
+-MODULE_AUTHOR("Tony Luck <tony.luck@intel.com>");
+-MODULE_LICENSE("GPL");
+--- a/fs/pstore/internal.h
++++ b/fs/pstore/internal.h
+@@ -37,7 +37,8 @@ extern bool pstore_is_mounted(void);
+ extern void pstore_record_init(struct pstore_record *record,
+ struct pstore_info *psi);
+
+-/* Called during module_init() */
+-extern void __init pstore_choose_compression(void);
++/* Called during pstore init/exit. */
++int __init pstore_init_fs(void);
++void __exit pstore_exit_fs(void);
+
+ #endif
+--- a/fs/pstore/platform.c
++++ b/fs/pstore/platform.c
+@@ -780,8 +780,31 @@ void __init pstore_choose_compression(vo
+ }
+ }
+
++static int __init pstore_init(void)
++{
++ int ret;
++
++ pstore_choose_compression();
++
++ ret = pstore_init_fs();
++ if (ret)
++ return ret;
++
++ return 0;
++}
++module_init(pstore_init)
++
++static void __exit pstore_exit(void)
++{
++ pstore_exit_fs();
++}
++module_exit(pstore_exit)
++
+ module_param(compress, charp, 0444);
+ MODULE_PARM_DESC(compress, "Pstore compression to use");
+
+ module_param(backend, charp, 0444);
+ MODULE_PARM_DESC(backend, "Pstore backend to use");
++
++MODULE_AUTHOR("Tony Luck <tony.luck@intel.com>");
++MODULE_LICENSE("GPL");
--- /dev/null
+From 95047b0519c17a28e09df5f38750f5354e3db4c4 Mon Sep 17 00:00:00 2001
+From: Kees Cook <keescook@chromium.org>
+Date: Wed, 17 Oct 2018 14:00:12 -0700
+Subject: pstore: Refactor compression initialization
+
+From: Kees Cook <keescook@chromium.org>
+
+commit 95047b0519c17a28e09df5f38750f5354e3db4c4 upstream.
+
+This refactors compression initialization slightly to better handle
+getting potentially called twice (via early pstore_register() calls
+and later pstore_init()) and improves the comments and reporting to be
+more verbose.
+
+Signed-off-by: Kees Cook <keescook@chromium.org>
+Tested-by: Guenter Roeck <groeck@chromium.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/pstore/platform.c | 48 +++++++++++++++++++++++++++++++++---------------
+ 1 file changed, 33 insertions(+), 15 deletions(-)
+
+--- a/fs/pstore/platform.c
++++ b/fs/pstore/platform.c
+@@ -274,36 +274,56 @@ static int pstore_decompress(void *in, v
+
+ static void allocate_buf_for_compression(void)
+ {
++ struct crypto_comp *ctx;
++ int size;
++ char *buf;
++
++ /* Skip if not built-in or compression backend not selected yet. */
+ if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend)
+ return;
+
++ /* Skip if no pstore backend yet or compression init already done. */
++ if (!psinfo || tfm)
++ return;
++
+ if (!crypto_has_comp(zbackend->name, 0, 0)) {
+- pr_err("No %s compression\n", zbackend->name);
++ pr_err("Unknown compression: %s\n", zbackend->name);
+ return;
+ }
+
+- big_oops_buf_sz = zbackend->zbufsize(psinfo->bufsize);
+- if (big_oops_buf_sz <= 0)
++ size = zbackend->zbufsize(psinfo->bufsize);
++ if (size <= 0) {
++ pr_err("Invalid compression size for %s: %d\n",
++ zbackend->name, size);
+ return;
++ }
+
+- big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
+- if (!big_oops_buf) {
+- pr_err("allocate compression buffer error!\n");
++ buf = kmalloc(size, GFP_KERNEL);
++ if (!buf) {
++ pr_err("Failed %d byte compression buffer allocation for: %s\n",
++ size, zbackend->name);
+ return;
+ }
+
+- tfm = crypto_alloc_comp(zbackend->name, 0, 0);
+- if (IS_ERR_OR_NULL(tfm)) {
+- kfree(big_oops_buf);
+- big_oops_buf = NULL;
+- pr_err("crypto_alloc_comp() failed!\n");
++ ctx = crypto_alloc_comp(zbackend->name, 0, 0);
++ if (IS_ERR_OR_NULL(ctx)) {
++ kfree(buf);
++ pr_err("crypto_alloc_comp('%s') failed: %ld\n", zbackend->name,
++ PTR_ERR(ctx));
+ return;
+ }
++
++ /* A non-NULL big_oops_buf indicates compression is available. */
++ tfm = ctx;
++ big_oops_buf_sz = size;
++ big_oops_buf = buf;
++
++ pr_info("Using compression: %s\n", zbackend->name);
+ }
+
+ static void free_buf_for_compression(void)
+ {
+- if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && !IS_ERR_OR_NULL(tfm))
++ if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm)
+ crypto_free_comp(tfm);
+ kfree(big_oops_buf);
+ big_oops_buf = NULL;
+@@ -774,7 +794,6 @@ void __init pstore_choose_compression(vo
+ for (step = zbackends; step->name; step++) {
+ if (!strcmp(compress, step->name)) {
+ zbackend = step;
+- pr_info("using %s compression\n", zbackend->name);
+ return;
+ }
+ }
+@@ -791,8 +810,7 @@ static int __init pstore_init(void)
+ * initialize compression because crypto was not ready. If so,
+ * initialize compression now.
+ */
+- if (psinfo && !tfm)
+- allocate_buf_for_compression();
++ allocate_buf_for_compression();
+
+ ret = pstore_init_fs();
+ if (ret)
jbd2-fix-potential-double-free.patch
kvm-x86-skip-efer-vs.-guest-cpuid-checks-for-host-initiated-writes.patch
kvm-lapic-busy-wait-for-timer-to-expire-when-using-hv_timer.patch
+kbuild-turn-auto.conf.cmd-into-a-mandatory-include-file.patch
+xen-pvh-set-xen_domain_type-to-hvm-in-xen_pvh_init.patch
+libnvdimm-namespace-fix-label-tracking-error.patch
+iov_iter-optimize-page_copy_sane.patch
+pstore-centralize-init-exit-routines.patch
+pstore-allocate-compression-during-late_initcall.patch
+pstore-refactor-compression-initialization.patch
+ext4-unsigned-int-compared-against-zero.patch
+ext4-fix-block-validity-checks-for-journal-inodes-using-indirect-blocks.patch
+ext4-fix-compile-error-when-using-buffer_trace.patch
+ext4-don-t-update-s_rev_level-if-not-required.patch
--- /dev/null
+From c9f804d64bb93c8dbf957df1d7e9de11380e522d Mon Sep 17 00:00:00 2001
+From: Roger Pau Monne <roger.pau@citrix.com>
+Date: Tue, 23 Apr 2019 15:04:15 +0200
+Subject: xen/pvh: set xen_domain_type to HVM in xen_pvh_init
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Roger Pau Monne <roger.pau@citrix.com>
+
+commit c9f804d64bb93c8dbf957df1d7e9de11380e522d upstream.
+
+Or else xen_domain() returns false despite xen_pvh being set.
+
+Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
+Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
+Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
+Cc: stable@vger.kernel.org # 4.19+
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ arch/x86/xen/enlighten_pvh.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/arch/x86/xen/enlighten_pvh.c
++++ b/arch/x86/xen/enlighten_pvh.c
+@@ -97,6 +97,7 @@ void __init xen_prepare_pvh(void)
+ }
+
+ xen_pvh = 1;
++ xen_domain_type = XEN_HVM_DOMAIN;
+ xen_start_flags = pvh_start_info.flags;
+
+ msr = cpuid_ebx(xen_cpuid_base() + 2);