--- /dev/null
+From 47caf685a6854593348f216e0b489b71c10cbe03 Mon Sep 17 00:00:00 2001
+From: Johannes Berg <johannes.berg@intel.com>
+Date: Wed, 19 Aug 2020 10:46:48 +0200
+Subject: cfg80211: regulatory: reject invalid hints
+
+From: Johannes Berg <johannes.berg@intel.com>
+
+commit 47caf685a6854593348f216e0b489b71c10cbe03 upstream.
+
+Reject invalid hints early in order to not cause a kernel
+WARN later if they're restored to or similar.
+
+Reported-by: syzbot+d451401ffd00a60677ee@syzkaller.appspotmail.com
+Link: https://syzkaller.appspot.com/bug?extid=d451401ffd00a60677ee
+Link: https://lore.kernel.org/r/20200819084648.13956-1-johannes@sipsolutions.net
+Signed-off-by: Johannes Berg <johannes.berg@intel.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ net/wireless/reg.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/net/wireless/reg.c
++++ b/net/wireless/reg.c
+@@ -2944,6 +2944,9 @@ int regulatory_hint_user(const char *alp
+ if (WARN_ON(!alpha2))
+ return -EINVAL;
+
++ if (!is_world_regdom(alpha2) && !is_an_alpha2(alpha2))
++ return -EINVAL;
++
+ request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
+ if (!request)
+ return -ENOMEM;
--- /dev/null
+From 13e45417cedbfc44b1926124b1846f5ee8c6ba4a Mon Sep 17 00:00:00 2001
+From: Mrinal Pandey <mrinalmni@gmail.com>
+Date: Fri, 4 Sep 2020 16:35:52 -0700
+Subject: checkpatch: fix the usage of capture group ( ... )
+
+From: Mrinal Pandey <mrinalmni@gmail.com>
+
+commit 13e45417cedbfc44b1926124b1846f5ee8c6ba4a upstream.
+
+The usage of "capture group (...)" in the immediate condition after `&&`
+results in `$1` being uninitialized. This issues a warning "Use of
+uninitialized value $1 in regexp compilation at ./scripts/checkpatch.pl
+line 2638".
+
+I noticed this bug while running checkpatch on the set of commits from
+v5.7 to v5.8-rc1 of the kernel on the commits with a diff content in
+their commit message.
+
+This bug was introduced in the script by commit e518e9a59ec3
+("checkpatch: emit an error when there's a diff in a changelog"). It
+has been in the script since then.
+
+The author intended to store the match made by capture group in variable
+`$1`. This should have contained the name of the file as `[\w/]+`
+matched. However, this couldn't be accomplished due to usage of capture
+group and `$1` in the same regular expression.
+
+Fix this by placing the capture group in the condition before `&&`.
+Thus, `$1` can be initialized to the text that capture group matches
+thereby setting it to the desired and required value.
+
+Fixes: e518e9a59ec3 ("checkpatch: emit an error when there's a diff in a changelog")
+Signed-off-by: Mrinal Pandey <mrinalmni@gmail.com>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Tested-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
+Reviewed-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
+Cc: Joe Perches <joe@perches.com>
+Link: https://lkml.kernel.org/r/20200714032352.f476hanaj2dlmiot@mrinalpandey
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ scripts/checkpatch.pl | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/scripts/checkpatch.pl
++++ b/scripts/checkpatch.pl
+@@ -2636,8 +2636,8 @@ sub process {
+
+ # Check if the commit log has what seems like a diff which can confuse patch
+ if ($in_commit_log && !$commit_log_has_diff &&
+- (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
+- $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
++ (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
++ $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
+ $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
+ $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
+ ERROR("DIFF_IN_COMMIT_MSG",
--- /dev/null
+From a73fbfce2cc28883f659414d598e6e60ca2214b4 Mon Sep 17 00:00:00 2001
+From: Randy Dunlap <rdunlap@infradead.org>
+Date: Wed, 26 Aug 2020 14:21:43 -0700
+Subject: kconfig: streamline_config.pl: check defined(ENV variable) before using it
+
+From: Randy Dunlap <rdunlap@infradead.org>
+
+commit a73fbfce2cc28883f659414d598e6e60ca2214b4 upstream.
+
+A user reported:
+'Use of uninitialized value $ENV{"LMC_KEEP"} in split at
+ ./scripts/kconfig/streamline_config.pl line 596.'
+
+so first check that $ENV{LMC_KEEP} is defined before trying
+to use it.
+
+Fixes: c027b02d89fd ("streamline_config.pl: add LMC_KEEP to preserve some kconfigs")
+Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
+Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ scripts/kconfig/streamline_config.pl | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+--- a/scripts/kconfig/streamline_config.pl
++++ b/scripts/kconfig/streamline_config.pl
+@@ -593,7 +593,10 @@ while ($repeat) {
+ }
+
+ my %setconfigs;
+-my @preserved_kconfigs = split(/:/,$ENV{LMC_KEEP});
++my @preserved_kconfigs;
++if (defined($ENV{'LMC_KEEP'})) {
++ @preserved_kconfigs = split(/:/,$ENV{LMC_KEEP});
++}
+
+ sub in_preserved_kconfigs {
+ my $kconfig = $config2kfile{$_[0]};
--- /dev/null
+From 17743798d81238ab13050e8e2833699b54e15467 Mon Sep 17 00:00:00 2001
+From: Muchun Song <songmuchun@bytedance.com>
+Date: Fri, 4 Sep 2020 16:36:13 -0700
+Subject: mm/hugetlb: fix a race between hugetlb sysctl handlers
+
+From: Muchun Song <songmuchun@bytedance.com>
+
+commit 17743798d81238ab13050e8e2833699b54e15467 upstream.
+
+There is a race between the assignment of `table->data` and write value
+to the pointer of `table->data` in the __do_proc_doulongvec_minmax() on
+the other thread.
+
+ CPU0: CPU1:
+ proc_sys_write
+ hugetlb_sysctl_handler proc_sys_call_handler
+ hugetlb_sysctl_handler_common hugetlb_sysctl_handler
+ table->data = &tmp; hugetlb_sysctl_handler_common
+ table->data = &tmp;
+ proc_doulongvec_minmax
+ do_proc_doulongvec_minmax sysctl_head_finish
+ __do_proc_doulongvec_minmax unuse_table
+ i = table->data;
+ *i = val; // corrupt CPU1's stack
+
+Fix this by duplicating the `table`, and only update the duplicate of
+it. And introduce a helper of proc_hugetlb_doulongvec_minmax() to
+simplify the code.
+
+The following oops was seen:
+
+ BUG: kernel NULL pointer dereference, address: 0000000000000000
+ #PF: supervisor instruction fetch in kernel mode
+ #PF: error_code(0x0010) - not-present page
+ Code: Bad RIP value.
+ ...
+ Call Trace:
+ ? set_max_huge_pages+0x3da/0x4f0
+ ? alloc_pool_huge_page+0x150/0x150
+ ? proc_doulongvec_minmax+0x46/0x60
+ ? hugetlb_sysctl_handler_common+0x1c7/0x200
+ ? nr_hugepages_store+0x20/0x20
+ ? copy_fd_bitmaps+0x170/0x170
+ ? hugetlb_sysctl_handler+0x1e/0x20
+ ? proc_sys_call_handler+0x2f1/0x300
+ ? unregister_sysctl_table+0xb0/0xb0
+ ? __fd_install+0x78/0x100
+ ? proc_sys_write+0x14/0x20
+ ? __vfs_write+0x4d/0x90
+ ? vfs_write+0xef/0x240
+ ? ksys_write+0xc0/0x160
+ ? __ia32_sys_read+0x50/0x50
+ ? __close_fd+0x129/0x150
+ ? __x64_sys_write+0x43/0x50
+ ? do_syscall_64+0x6c/0x200
+ ? entry_SYSCALL_64_after_hwframe+0x44/0xa9
+
+Fixes: e5ff215941d5 ("hugetlb: multiple hstates for multiple page sizes")
+Signed-off-by: Muchun Song <songmuchun@bytedance.com>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
+Cc: Andi Kleen <ak@linux.intel.com>
+Link: http://lkml.kernel.org/r/20200828031146.43035-1-songmuchun@bytedance.com
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ mm/hugetlb.c | 26 ++++++++++++++++++++------
+ 1 file changed, 20 insertions(+), 6 deletions(-)
+
+--- a/mm/hugetlb.c
++++ b/mm/hugetlb.c
+@@ -3480,6 +3480,22 @@ static unsigned int cpuset_mems_nr(unsig
+ }
+
+ #ifdef CONFIG_SYSCTL
++static int proc_hugetlb_doulongvec_minmax(struct ctl_table *table, int write,
++ void *buffer, size_t *length,
++ loff_t *ppos, unsigned long *out)
++{
++ struct ctl_table dup_table;
++
++ /*
++ * In order to avoid races with __do_proc_doulongvec_minmax(), we
++ * can duplicate the @table and alter the duplicate of it.
++ */
++ dup_table = *table;
++ dup_table.data = out;
++
++ return proc_doulongvec_minmax(&dup_table, write, buffer, length, ppos);
++}
++
+ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
+ struct ctl_table *table, int write,
+ void *buffer, size_t *length, loff_t *ppos)
+@@ -3491,9 +3507,8 @@ static int hugetlb_sysctl_handler_common
+ if (!hugepages_supported())
+ return -EOPNOTSUPP;
+
+- table->data = &tmp;
+- table->maxlen = sizeof(unsigned long);
+- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
++ ret = proc_hugetlb_doulongvec_minmax(table, write, buffer, length, ppos,
++ &tmp);
+ if (ret)
+ goto out;
+
+@@ -3536,9 +3551,8 @@ int hugetlb_overcommit_handler(struct ct
+ if (write && hstate_is_gigantic(h))
+ return -EINVAL;
+
+- table->data = &tmp;
+- table->maxlen = sizeof(unsigned long);
+- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
++ ret = proc_hugetlb_doulongvec_minmax(table, write, buffer, length, ppos,
++ &tmp);
+ if (ret)
+ goto out;
+
--- /dev/null
+From 953f064aa6b29debcc211869b60bd59f26d19c34 Mon Sep 17 00:00:00 2001
+From: Li Xinhai <lixinhai.lxh@gmail.com>
+Date: Fri, 4 Sep 2020 16:36:10 -0700
+Subject: mm/hugetlb: try preferred node first when alloc gigantic page from cma
+
+From: Li Xinhai <lixinhai.lxh@gmail.com>
+
+commit 953f064aa6b29debcc211869b60bd59f26d19c34 upstream.
+
+Since commit cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic
+hugepages using cma"), the gigantic page would be allocated from node
+which is not the preferred node, although there are pages available from
+that node. The reason is that the nid parameter has been ignored in
+alloc_gigantic_page().
+
+Besides, the __GFP_THISNODE also need be checked if user required to
+alloc only from the preferred node.
+
+After this patch, the preferred node is tried first before other allowed
+nodes, and don't try to allocate from other nodes if __GFP_THISNODE is
+specified. If user don't specify the preferred node, the current node
+will be used as preferred node, which makes sure consistent behavior of
+allocating gigantic and non-gigantic hugetlb page.
+
+Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages using cma")
+Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
+Acked-by: Michal Hocko <mhocko@suse.com>
+Cc: Roman Gushchin <guro@fb.com>
+Link: https://lkml.kernel.org/r/20200902025016.697260-1-lixinhai.lxh@gmail.com
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ mm/hugetlb.c | 23 +++++++++++++++++------
+ 1 file changed, 17 insertions(+), 6 deletions(-)
+
+--- a/mm/hugetlb.c
++++ b/mm/hugetlb.c
+@@ -1251,21 +1251,32 @@ static struct page *alloc_gigantic_page(
+ int nid, nodemask_t *nodemask)
+ {
+ unsigned long nr_pages = 1UL << huge_page_order(h);
++ if (nid == NUMA_NO_NODE)
++ nid = numa_mem_id();
+
+ #ifdef CONFIG_CMA
+ {
+ struct page *page;
+ int node;
+
+- for_each_node_mask(node, *nodemask) {
+- if (!hugetlb_cma[node])
+- continue;
+-
+- page = cma_alloc(hugetlb_cma[node], nr_pages,
+- huge_page_order(h), true);
++ if (hugetlb_cma[nid]) {
++ page = cma_alloc(hugetlb_cma[nid], nr_pages,
++ huge_page_order(h), true);
+ if (page)
+ return page;
+ }
++
++ if (!(gfp_mask & __GFP_THISNODE)) {
++ for_each_node_mask(node, *nodemask) {
++ if (node == nid || !hugetlb_cma[node])
++ continue;
++
++ page = cma_alloc(hugetlb_cma[node], nr_pages,
++ huge_page_order(h), true);
++ if (page)
++ return page;
++ }
++ }
+ }
+ #endif
+
--- /dev/null
+From e5a59d308f52bb0052af5790c22173651b187465 Mon Sep 17 00:00:00 2001
+From: David Howells <dhowells@redhat.com>
+Date: Fri, 4 Sep 2020 16:36:16 -0700
+Subject: mm/khugepaged.c: fix khugepaged's request size in collapse_file
+
+From: David Howells <dhowells@redhat.com>
+
+commit e5a59d308f52bb0052af5790c22173651b187465 upstream.
+
+collapse_file() in khugepaged passes PAGE_SIZE as the number of pages to
+be read to page_cache_sync_readahead(). The intent was probably to read
+a single page. Fix it to use the number of pages to the end of the
+window instead.
+
+Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
+Signed-off-by: David Howells <dhowells@redhat.com>
+Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
+Acked-by: Song Liu <songliubraving@fb.com>
+Acked-by: Yang Shi <shy828301@gmail.com>
+Acked-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
+Cc: Eric Biggers <ebiggers@google.com>
+Link: https://lkml.kernel.org/r/20200903140844.14194-2-willy@infradead.org
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ mm/khugepaged.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/mm/khugepaged.c
++++ b/mm/khugepaged.c
+@@ -1709,7 +1709,7 @@ static void collapse_file(struct mm_stru
+ xas_unlock_irq(&xas);
+ page_cache_sync_readahead(mapping, &file->f_ra,
+ file, index,
+- PAGE_SIZE);
++ end - index);
+ /* drain pagevecs to help isolate_lru_page() */
+ lru_add_drain();
+ page = find_lock_page(mapping, index);
--- /dev/null
+From ebdf8321eeeb623aed60f7ed16f7445363230118 Mon Sep 17 00:00:00 2001
+From: Alistair Popple <alistair@popple.id.au>
+Date: Fri, 4 Sep 2020 16:35:58 -0700
+Subject: mm/migrate: fixup setting UFFD_WP flag
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Alistair Popple <alistair@popple.id.au>
+
+commit ebdf8321eeeb623aed60f7ed16f7445363230118 upstream.
+
+Commit f45ec5ff16a75 ("userfaultfd: wp: support swap and page migration")
+introduced support for tracking the uffd wp bit during page migration.
+However the non-swap PTE variant was used to set the flag for zone device
+private pages which are a type of swap page.
+
+This leads to corruption of the swap offset if the original PTE has the
+uffd_wp flag set.
+
+Fixes: f45ec5ff16a75 ("userfaultfd: wp: support swap and page migration")
+Signed-off-by: Alistair Popple <alistair@popple.id.au>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Reviewed-by: Peter Xu <peterx@redhat.com>
+Cc: Jérôme Glisse <jglisse@redhat.com>
+Cc: John Hubbard <jhubbard@nvidia.com>
+Cc: Ralph Campbell <rcampbell@nvidia.com>
+Link: https://lkml.kernel.org/r/20200825064232.10023-1-alistair@popple.id.au
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ mm/migrate.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/mm/migrate.c
++++ b/mm/migrate.c
+@@ -251,7 +251,7 @@ static bool remove_migration_pte(struct
+ entry = make_device_private_entry(new, pte_write(pte));
+ pte = swp_entry_to_pte(entry);
+ if (pte_swp_uffd_wp(*pvmw.pte))
+- pte = pte_mkuffd_wp(pte);
++ pte = pte_swp_mkuffd_wp(pte);
+ }
+ }
+
--- /dev/null
+From a092b7233f0e000cc6f2c71a49e2ecc6f917a5fc Mon Sep 17 00:00:00 2001
+From: Himadri Pandya <himadrispandya@gmail.com>
+Date: Thu, 27 Aug 2020 12:23:55 +0530
+Subject: net: usb: Fix uninit-was-stored issue in asix_read_phy_addr()
+
+From: Himadri Pandya <himadrispandya@gmail.com>
+
+commit a092b7233f0e000cc6f2c71a49e2ecc6f917a5fc upstream.
+
+The buffer size is 2 Bytes and we expect to receive the same amount of
+data. But sometimes we receive less data and run into uninit-was-stored
+issue upon read. Hence modify the error check on the return value to match
+with the buffer size as a prevention.
+
+Reported-and-tested by: syzbot+a7e220df5a81d1ab400e@syzkaller.appspotmail.com
+Signed-off-by: Himadri Pandya <himadrispandya@gmail.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/net/usb/asix_common.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/net/usb/asix_common.c
++++ b/drivers/net/usb/asix_common.c
+@@ -296,7 +296,7 @@ int asix_read_phy_addr(struct usbnet *de
+
+ netdev_dbg(dev->net, "asix_get_phy_addr()\n");
+
+- if (ret < 0) {
++ if (ret < 2) {
+ netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
+ goto out;
+ }
--- /dev/null
+From a060c1f12b525ba828f871eff3127dabf8daa1e6 Mon Sep 17 00:00:00 2001
+From: Wei Li <liwei391@huawei.com>
+Date: Wed, 19 Aug 2020 11:19:47 +0800
+Subject: perf record: Correct the help info of option "--no-bpf-event"
+
+From: Wei Li <liwei391@huawei.com>
+
+commit a060c1f12b525ba828f871eff3127dabf8daa1e6 upstream.
+
+The help info of option "--no-bpf-event" is wrongly described as "record
+bpf events", correct it.
+
+Committer testing:
+
+ $ perf record -h bpf
+
+ Usage: perf record [<options>] [<command>]
+ or: perf record [<options>] -- <command> [<options>]
+
+ --clang-opt <clang options>
+ options passed to clang when compiling BPF scriptlets
+ --clang-path <clang path>
+ clang binary to use for compiling BPF scriptlets
+ --no-bpf-event do not record bpf events
+
+ $
+
+Fixes: 71184c6ab7e6 ("perf record: Replace option --bpf-event with --no-bpf-event")
+Signed-off-by: Wei Li <liwei391@huawei.com>
+Acked-by: Song Liu <songliubraving@fb.com>
+Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
+Cc: Hanjun Guo <guohanjun@huawei.com>
+Cc: Jiri Olsa <jolsa@redhat.com>
+Cc: Li Bin <huawei.libin@huawei.com>
+Cc: Mark Rutland <mark.rutland@arm.com>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Link: http://lore.kernel.org/lkml/20200819031947.12115-1-liwei391@huawei.com
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/builtin-record.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/builtin-record.c
++++ b/tools/perf/builtin-record.c
+@@ -2417,7 +2417,7 @@ static struct option __record_options[]
+ OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize,
+ "synthesize non-sample events at the end of output"),
+ OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
+- OPT_BOOLEAN(0, "no-bpf-event", &record.opts.no_bpf_event, "record bpf events"),
++ OPT_BOOLEAN(0, "no-bpf-event", &record.opts.no_bpf_event, "do not record bpf events"),
+ OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq,
+ "Fail if the specified frequency can't be used"),
+ OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'",
--- /dev/null
+From 8048822bac01936fda2c7b924a52131da81e6198 Mon Sep 17 00:00:00 2001
+From: Sowjanya Komatineni <skomatineni@nvidia.com>
+Date: Thu, 27 Aug 2020 10:21:01 -0700
+Subject: sdhci: tegra: Add missing TMCLK for data timeout
+
+From: Sowjanya Komatineni <skomatineni@nvidia.com>
+
+commit 8048822bac01936fda2c7b924a52131da81e6198 upstream.
+
+commit b5a84ecf025a ("mmc: tegra: Add Tegra210 support")
+
+Tegra210 and later has a separate sdmmc_legacy_tm (TMCLK) used by Tegra
+SDMMC hawdware for data timeout to achive better timeout than using
+SDCLK and using TMCLK is recommended.
+
+USE_TMCLK_FOR_DATA_TIMEOUT bit in Tegra SDMMC register
+SDHCI_TEGRA_VENDOR_SYS_SW_CTRL can be used to choose either TMCLK or
+SDCLK for data timeout.
+
+Default USE_TMCLK_FOR_DATA_TIMEOUT bit is set to 1 and TMCLK is used
+for data timeout by Tegra SDMMC hardware and having TMCLK not enabled
+is not recommended.
+
+So, this patch adds quirk NVQUIRK_HAS_TMCLK for SoC having separate
+timeout clock and keeps TMCLK enabled all the time.
+
+Fixes: b5a84ecf025a ("mmc: tegra: Add Tegra210 support")
+Cc: stable <stable@vger.kernel.org> # 5.4
+Tested-by: Jon Hunter <jonathanh@nvidia.com>
+Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
+Acked-by: Adrian Hunter <adrian.hunter@intel.com>
+Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
+Link: https://lore.kernel.org/r/1598548861-32373-8-git-send-email-skomatineni@nvidia.com
+Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/mmc/host/sdhci-tegra.c | 53 +++++++++++++++++++++++++++++++++++++++--
+ 1 file changed, 51 insertions(+), 2 deletions(-)
+
+--- a/drivers/mmc/host/sdhci-tegra.c
++++ b/drivers/mmc/host/sdhci-tegra.c
+@@ -101,6 +101,12 @@
+ #define NVQUIRK_DIS_CARD_CLK_CONFIG_TAP BIT(8)
+ #define NVQUIRK_CQHCI_DCMD_R1B_CMD_TIMING BIT(9)
+
++/*
++ * NVQUIRK_HAS_TMCLK is for SoC's having separate timeout clock for Tegra
++ * SDMMC hardware data timeout.
++ */
++#define NVQUIRK_HAS_TMCLK BIT(10)
++
+ /* SDMMC CQE Base Address for Tegra Host Ver 4.1 and Higher */
+ #define SDHCI_TEGRA_CQE_BASE_ADDR 0xF000
+
+@@ -131,6 +137,7 @@ struct sdhci_tegra_autocal_offsets {
+ struct sdhci_tegra {
+ const struct sdhci_tegra_soc_data *soc_data;
+ struct gpio_desc *power_gpio;
++ struct clk *tmclk;
+ bool ddr_signaling;
+ bool pad_calib_required;
+ bool pad_control_available;
+@@ -1424,7 +1431,8 @@ static const struct sdhci_tegra_soc_data
+ NVQUIRK_HAS_PADCALIB |
+ NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
+ NVQUIRK_ENABLE_SDR50 |
+- NVQUIRK_ENABLE_SDR104,
++ NVQUIRK_ENABLE_SDR104 |
++ NVQUIRK_HAS_TMCLK,
+ .min_tap_delay = 106,
+ .max_tap_delay = 185,
+ };
+@@ -1462,6 +1470,7 @@ static const struct sdhci_tegra_soc_data
+ NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
+ NVQUIRK_ENABLE_SDR50 |
+ NVQUIRK_ENABLE_SDR104 |
++ NVQUIRK_HAS_TMCLK |
+ NVQUIRK_CQHCI_DCMD_R1B_CMD_TIMING,
+ .min_tap_delay = 84,
+ .max_tap_delay = 136,
+@@ -1474,7 +1483,8 @@ static const struct sdhci_tegra_soc_data
+ NVQUIRK_HAS_PADCALIB |
+ NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
+ NVQUIRK_ENABLE_SDR50 |
+- NVQUIRK_ENABLE_SDR104,
++ NVQUIRK_ENABLE_SDR104 |
++ NVQUIRK_HAS_TMCLK,
+ .min_tap_delay = 96,
+ .max_tap_delay = 139,
+ };
+@@ -1602,6 +1612,43 @@ static int sdhci_tegra_probe(struct plat
+ goto err_power_req;
+ }
+
++ /*
++ * Tegra210 has a separate SDMMC_LEGACY_TM clock used for host
++ * timeout clock and SW can choose TMCLK or SDCLK for hardware
++ * data timeout through the bit USE_TMCLK_FOR_DATA_TIMEOUT of
++ * the register SDHCI_TEGRA_VENDOR_SYS_SW_CTRL.
++ *
++ * USE_TMCLK_FOR_DATA_TIMEOUT bit default is set to 1 and SDMMC uses
++ * 12Mhz TMCLK which is advertised in host capability register.
++ * With TMCLK of 12Mhz provides maximum data timeout period that can
++ * be achieved is 11s better than using SDCLK for data timeout.
++ *
++ * So, TMCLK is set to 12Mhz and kept enabled all the time on SoC's
++ * supporting separate TMCLK.
++ */
++
++ if (soc_data->nvquirks & NVQUIRK_HAS_TMCLK) {
++ clk = devm_clk_get(&pdev->dev, "tmclk");
++ if (IS_ERR(clk)) {
++ rc = PTR_ERR(clk);
++ if (rc == -EPROBE_DEFER)
++ goto err_power_req;
++
++ dev_warn(&pdev->dev, "failed to get tmclk: %d\n", rc);
++ clk = NULL;
++ }
++
++ clk_set_rate(clk, 12000000);
++ rc = clk_prepare_enable(clk);
++ if (rc) {
++ dev_err(&pdev->dev,
++ "failed to enable tmclk: %d\n", rc);
++ goto err_power_req;
++ }
++
++ tegra_host->tmclk = clk;
++ }
++
+ clk = devm_clk_get(mmc_dev(host->mmc), NULL);
+ if (IS_ERR(clk)) {
+ rc = PTR_ERR(clk);
+@@ -1645,6 +1692,7 @@ err_add_host:
+ err_rst_get:
+ clk_disable_unprepare(pltfm_host->clk);
+ err_clk_get:
++ clk_disable_unprepare(tegra_host->tmclk);
+ err_power_req:
+ err_parse_dt:
+ sdhci_pltfm_free(pdev);
+@@ -1662,6 +1710,7 @@ static int sdhci_tegra_remove(struct pla
+ reset_control_assert(tegra_host->rst);
+ usleep_range(2000, 4000);
+ clk_disable_unprepare(pltfm_host->clk);
++ clk_disable_unprepare(tegra_host->tmclk);
+
+ sdhci_pltfm_free(pdev);
+
mm-madvise-fix-vma-user-after-free.patch
mm-rmap-fixup-copying-of-soft-dirty-and-uffd-ptes.patch
io_uring-no-read-write-retry-on-eagain-error-and-o_nonblock-marked-file.patch
+perf-record-correct-the-help-info-of-option-no-bpf-event.patch
+kconfig-streamline_config.pl-check-defined-env-variable-before-using-it.patch
+sdhci-tegra-add-missing-tmclk-for-data-timeout.patch
+checkpatch-fix-the-usage-of-capture-group.patch
+mm-migrate-fixup-setting-uffd_wp-flag.patch
+mm-hugetlb-try-preferred-node-first-when-alloc-gigantic-page-from-cma.patch
+mm-hugetlb-fix-a-race-between-hugetlb-sysctl-handlers.patch
+mm-khugepaged.c-fix-khugepaged-s-request-size-in-collapse_file.patch
+cfg80211-regulatory-reject-invalid-hints.patch
+net-usb-fix-uninit-was-stored-issue-in-asix_read_phy_addr.patch