--- /dev/null
+From d1d787bcebfe122a5bd443ae565696661e2e9656 Mon Sep 17 00:00:00 2001
+From: Corentin Labbe <clabbe.montjoie@gmail.com>
+Date: Thu, 14 Nov 2019 13:58:49 +0100
+Subject: crypto: sun4i-ss - fix big endian issues
+
+From: Corentin Labbe <clabbe.montjoie@gmail.com>
+
+commit d1d787bcebfe122a5bd443ae565696661e2e9656 upstream.
+
+When testing BigEndian kernel, the sun4i-ss was failling all crypto
+tests.
+This patch fix endian issues with it.
+
+Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
+Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
+Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/crypto/sunxi-ss/sun4i-ss-hash.c | 21 +++++++++++----------
+ 1 file changed, 11 insertions(+), 10 deletions(-)
+
+--- a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
++++ b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
+@@ -179,7 +179,7 @@ static int sun4i_hash(struct ahash_reque
+ */
+ unsigned int i = 0, end, fill, min_fill, nwait, nbw = 0, j = 0, todo;
+ unsigned int in_i = 0;
+- u32 spaces, rx_cnt = SS_RX_DEFAULT, bf[32] = {0}, wb = 0, v, ivmode = 0;
++ u32 spaces, rx_cnt = SS_RX_DEFAULT, bf[32] = {0}, v, ivmode = 0;
+ struct sun4i_req_ctx *op = ahash_request_ctx(areq);
+ struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
+ struct sun4i_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
+@@ -188,6 +188,7 @@ static int sun4i_hash(struct ahash_reque
+ struct sg_mapping_iter mi;
+ int in_r, err = 0;
+ size_t copied = 0;
++ __le32 wb = 0;
+
+ dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x wl=%u h0=%0x",
+ __func__, crypto_tfm_alg_name(areq->base.tfm),
+@@ -399,7 +400,7 @@ hash_final:
+
+ nbw = op->len - 4 * nwait;
+ if (nbw) {
+- wb = *(u32 *)(op->buf + nwait * 4);
++ wb = cpu_to_le32(*(u32 *)(op->buf + nwait * 4));
+ wb &= GENMASK((nbw * 8) - 1, 0);
+
+ op->byte_count += nbw;
+@@ -408,7 +409,7 @@ hash_final:
+
+ /* write the remaining bytes of the nbw buffer */
+ wb |= ((1 << 7) << (nbw * 8));
+- bf[j++] = wb;
++ bf[j++] = le32_to_cpu(wb);
+
+ /*
+ * number of space to pad to obtain 64o minus 8(size) minus 4 (final 1)
+@@ -427,13 +428,13 @@ hash_final:
+
+ /* write the length of data */
+ if (op->mode == SS_OP_SHA1) {
+- __be64 bits = cpu_to_be64(op->byte_count << 3);
+- bf[j++] = lower_32_bits(bits);
+- bf[j++] = upper_32_bits(bits);
++ __be64 *bits = (__be64 *)&bf[j];
++ *bits = cpu_to_be64(op->byte_count << 3);
++ j += 2;
+ } else {
+- __le64 bits = op->byte_count << 3;
+- bf[j++] = lower_32_bits(bits);
+- bf[j++] = upper_32_bits(bits);
++ __le64 *bits = (__le64 *)&bf[j];
++ *bits = cpu_to_le64(op->byte_count << 3);
++ j += 2;
+ }
+ writesl(ss->base + SS_RXFIFO, bf, j);
+
+@@ -475,7 +476,7 @@ hash_final:
+ }
+ } else {
+ for (i = 0; i < 4; i++) {
+- v = readl(ss->base + SS_MD0 + i * 4);
++ v = cpu_to_le32(readl(ss->base + SS_MD0 + i * 4));
+ memcpy(areq->result + i * 4, &v, 4);
+ }
+ }
--- /dev/null
+From f068435d9bb2d825d59e3c101bc579f09315ee01 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Thu, 14 Nov 2019 10:46:45 -0300
+Subject: perf map: No need to adjust the long name of modules
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit f068435d9bb2d825d59e3c101bc579f09315ee01 upstream.
+
+At some point in the past we needed to make sure we would get the long
+name of modules and not just what we get from /proc/modules, but that
+need, as described in the cset that introduced the adjustment function:
+
+Fixes: c03d5184f0e9 ("perf machine: Adjust dso->long_name for offline module")
+
+Without using the buildid-cache:
+
+ # lsmod | grep trusted
+ # insmod trusted.ko
+ # lsmod | grep trusted
+ trusted 24576 0
+ # strace -e open,openat perf probe -m ./trusted.ko key_seal |& grep trusted
+ openat(AT_FDCWD, "/sys/module/trusted/notes/.note.gnu.build-id", O_RDONLY) = 4
+ openat(AT_FDCWD, "/sys/module/trusted/notes/.note.gnu.build-id", O_RDONLY) = 7
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/.debug/root/trusted.ko/dd3d355d567394d540f527e093e0f64b95879584/probes", O_RDWR|O_CREAT, 0644) = 3
+ openat(AT_FDCWD, "/usr/lib/debug/root/trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/usr/lib/debug/root/trusted.ko", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/.debug/trusted.ko", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, ".debug/trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 4
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ probe:key_seal (on key_seal in trusted)
+ # perf probe -l
+ probe:key_seal (on key_seal in trusted)
+ #
+
+No attempt at opening '[trusted]'.
+
+Now using the build-id cache:
+
+ # rmmod trusted
+ # perf buildid-cache --add ./trusted.ko
+ # insmod trusted.ko
+ # strace -e open,openat perf probe -m ./trusted.ko key_seal |& grep trusted
+ openat(AT_FDCWD, "/sys/module/trusted/notes/.note.gnu.build-id", O_RDONLY) = 4
+ openat(AT_FDCWD, "/sys/module/trusted/notes/.note.gnu.build-id", O_RDONLY) = 7
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/.debug/root/trusted.ko/dd3d355d567394d540f527e093e0f64b95879584/probes", O_RDWR|O_CREAT, 0644) = 3
+ openat(AT_FDCWD, "/usr/lib/debug/root/trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/usr/lib/debug/root/trusted.ko", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/.debug/trusted.ko", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, ".debug/trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "trusted.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 4
+ openat(AT_FDCWD, "/root/trusted.ko", O_RDONLY) = 3
+ #
+
+Again, no attempt at reading '[trusted]'.
+
+Finally, adding a probe to that function and then using:
+
+[root@quaco ~]# perf trace -e probe_perf:*/max-stack=16/ --max-events=2
+ 0.000 perf/13456 probe_perf:dso__adjust_kmod_long_name(__probe_ip: 5492263)
+ dso__adjust_kmod_long_name (/home/acme/bin/perf)
+ machine__process_kernel_mmap_event (/home/acme/bin/perf)
+ machine__process_mmap_event (/home/acme/bin/perf)
+ perf_event__process_mmap (/home/acme/bin/perf)
+ machines__deliver_event (/home/acme/bin/perf)
+ perf_session__deliver_event (/home/acme/bin/perf)
+ perf_session__process_event (/home/acme/bin/perf)
+ process_simple (/home/acme/bin/perf)
+ reader__process_events (/home/acme/bin/perf)
+ __perf_session__process_events (/home/acme/bin/perf)
+ perf_session__process_events (/home/acme/bin/perf)
+ process_buildids (/home/acme/bin/perf)
+ record__finish_output (/home/acme/bin/perf)
+ __cmd_record (/home/acme/bin/perf)
+ cmd_record (/home/acme/bin/perf)
+ run_builtin (/home/acme/bin/perf)
+ 0.055 perf/13456 probe_perf:dso__adjust_kmod_long_name(__probe_ip: 5492263)
+ dso__adjust_kmod_long_name (/home/acme/bin/perf)
+ machine__process_kernel_mmap_event (/home/acme/bin/perf)
+ machine__process_mmap_event (/home/acme/bin/perf)
+ perf_event__process_mmap (/home/acme/bin/perf)
+ machines__deliver_event (/home/acme/bin/perf)
+ perf_session__deliver_event (/home/acme/bin/perf)
+ perf_session__process_event (/home/acme/bin/perf)
+ process_simple (/home/acme/bin/perf)
+ reader__process_events (/home/acme/bin/perf)
+ __perf_session__process_events (/home/acme/bin/perf)
+ perf_session__process_events (/home/acme/bin/perf)
+ process_buildids (/home/acme/bin/perf)
+ record__finish_output (/home/acme/bin/perf)
+ __cmd_record (/home/acme/bin/perf)
+ cmd_record (/home/acme/bin/perf)
+ run_builtin (/home/acme/bin/perf)
+ #
+
+This was the only path I could find using the perf tools that reach at this
+function, then as of november/2019, if we put a probe in the line where the
+actuall setting of the dso->long_name is done:
+
+ # perf trace -e probe_perf:*
+ ^C[root@quaco ~]
+ # perf stat -e probe_perf:* -I 2000
+ 2.000404265 0 probe_perf:dso__adjust_kmod_long_name
+ 4.001142200 0 probe_perf:dso__adjust_kmod_long_name
+ 6.001704120 0 probe_perf:dso__adjust_kmod_long_name
+ 8.002398316 0 probe_perf:dso__adjust_kmod_long_name
+ 10.002984010 0 probe_perf:dso__adjust_kmod_long_name
+ 12.003597851 0 probe_perf:dso__adjust_kmod_long_name
+ 14.004113303 0 probe_perf:dso__adjust_kmod_long_name
+ 16.004582773 0 probe_perf:dso__adjust_kmod_long_name
+ 18.005176373 0 probe_perf:dso__adjust_kmod_long_name
+ 20.005801605 0 probe_perf:dso__adjust_kmod_long_name
+ 22.006467540 0 probe_perf:dso__adjust_kmod_long_name
+ ^C 23.683261941 0 probe_perf:dso__adjust_kmod_long_name
+
+ #
+
+Its not being used at all.
+
+To further test this I used kvm.ko as the offline module, i.e. removed
+if from the buildid-cache by nuking it completely (rm -rf ~/.debug) and
+moved it from the normal kernel distro path, removed the modules, stoped
+the kvm guest, and then installed it manually, etc.
+
+ # rmmod kvm-intel
+ # rmmod kvm
+ # lsmod | grep kvm
+ # modprobe kvm-intel
+ modprobe: ERROR: ctx=0x55d3b1722260 path=/lib/modules/5.3.8-200.fc30.x86_64/kernel/arch/x86/kvm/kvm.ko.xz error=No such file or directory
+ modprobe: ERROR: ctx=0x55d3b1722260 path=/lib/modules/5.3.8-200.fc30.x86_64/kernel/arch/x86/kvm/kvm.ko.xz error=No such file or directory
+ modprobe: ERROR: could not insert 'kvm_intel': Unknown symbol in module, or unknown parameter (see dmesg)
+ # insmod ./kvm.ko
+ # modprobe kvm-intel
+ modprobe: ERROR: ctx=0x562f34026260 path=/lib/modules/5.3.8-200.fc30.x86_64/kernel/arch/x86/kvm/kvm.ko.xz error=No such file or directory
+ modprobe: ERROR: ctx=0x562f34026260 path=/lib/modules/5.3.8-200.fc30.x86_64/kernel/arch/x86/kvm/kvm.ko.xz error=No such file or directory
+ # lsmod | grep kvm
+ kvm_intel 299008 0
+ kvm 765952 1 kvm_intel
+ irqbypass 16384 1 kvm
+ #
+ # perf probe -x ~/bin/perf machine__findnew_module_map:12 mname=m.name:string filename=filename:string 'dso_long_name=map->dso->long_name:string' 'dso_name=map->dso->name:string'
+ # perf probe -l
+ probe_perf:machine__findnew_module_map (on machine__findnew_module_map:12@util/machine.c in /home/acme/bin/perf with mname filename dso_long_name dso_name)
+ # perf record
+ ^C[ perf record: Woken up 2 times to write data ]
+ [ perf record: Captured and wrote 3.416 MB perf.data (33956 samples) ]
+ # perf trace -e probe_perf:machine*
+ <SNIP>
+ 6.322 perf/23099 probe_perf:machine__findnew_module_map(__probe_ip: 5492493, mname: "[salsa20_generic]", filename: "/lib/modules/5.3.8-200.fc30.x86_64/kernel/crypto/salsa20_generic.ko.xz", dso_long_name: "/lib/modules/5.3.8-200.fc30.x86_64/kernel/crypto/salsa20_generic.ko.xz", dso_name: "[salsa20_generic]")
+ 6.375 perf/23099 probe_perf:machine__findnew_module_map(__probe_ip: 5492493, mname: "[kvm]", filename: "[kvm]", dso_long_name: "[kvm]", dso_name: "[kvm]")
+ <SNIP>
+
+The filename doesn't come with the path, no point in trying to set the dso->long_name.
+
+ [root@quaco ~]# strace -e open,openat perf probe -m ./kvm.ko kvm_apic_local_deliver |& egrep 'open.*kvm'
+ openat(AT_FDCWD, "/sys/module/kvm_intel/notes/.note.gnu.build-id", O_RDONLY) = 4
+ openat(AT_FDCWD, "/sys/module/kvm/notes/.note.gnu.build-id", O_RDONLY) = 4
+ openat(AT_FDCWD, "/lib/modules/5.3.8-200.fc30.x86_64/kernel/arch/x86/kvm", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 7
+ openat(AT_FDCWD, "/sys/module/kvm_intel/notes/.note.gnu.build-id", O_RDONLY) = 8
+ openat(AT_FDCWD, "/root/kvm.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/.debug/root/kvm.ko/5955f426cb93f03f30f3e876814be2db80ab0b55/probes", O_RDWR|O_CREAT, 0644) = 3
+ openat(AT_FDCWD, "/usr/lib/debug/root/kvm.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/usr/lib/debug/root/kvm.ko", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/.debug/kvm.ko", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/kvm.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "kvm.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, ".debug/kvm.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "kvm.ko.debug", O_RDONLY) = -1 ENOENT (No such file or directory)
+ openat(AT_FDCWD, "/root/kvm.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/kvm.ko", O_RDONLY) = 3
+ openat(AT_FDCWD, "/root/kvm.ko", O_RDONLY) = 4
+ openat(AT_FDCWD, "/root/kvm.ko", O_RDONLY) = 3
+ [root@quaco ~]#
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: Andi Kleen <ak@linux.intel.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: https://lkml.kernel.org/n/tip-jlfew3lyb24d58egrp0o72o2@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/machine.c | 27 +--------------------------
+ 1 file changed, 1 insertion(+), 26 deletions(-)
+
+--- a/tools/perf/util/machine.c
++++ b/tools/perf/util/machine.c
+@@ -681,24 +681,6 @@ int machine__process_switch_event(struct
+ return 0;
+ }
+
+-static void dso__adjust_kmod_long_name(struct dso *dso, const char *filename)
+-{
+- const char *dup_filename;
+-
+- if (!filename || !dso || !dso->long_name)
+- return;
+- if (dso->long_name[0] != '[')
+- return;
+- if (!strchr(filename, '/'))
+- return;
+-
+- dup_filename = strdup(filename);
+- if (!dup_filename)
+- return;
+-
+- dso__set_long_name(dso, dup_filename, true);
+-}
+-
+ struct map *machine__findnew_module_map(struct machine *machine, u64 start,
+ const char *filename)
+ {
+@@ -710,15 +692,8 @@ struct map *machine__findnew_module_map(
+ return NULL;
+
+ map = map_groups__find_by_name(&machine->kmaps, m.name);
+- if (map) {
+- /*
+- * If the map's dso is an offline module, give dso__load()
+- * a chance to find the file path of that module by fixing
+- * long_name.
+- */
+- dso__adjust_kmod_long_name(map->dso, filename);
++ if (map)
+ goto out;
+- }
+
+ dso = machine__findnew_module_dso(machine, &m, filename);
+ if (dso == NULL)