Re: [PATCH] samples/ftrace: mark my_tramp[12]? global

2020-11-16 Thread Sami Tolvanen
On Mon, Nov 16, 2020 at 12:38 PM Steven Rostedt  wrote:
>
> On Mon, 16 Nov 2020 12:10:10 -0800
> Sami Tolvanen  wrote:
>
> > On Mon, Nov 16, 2020 at 8:39 AM Steven Rostedt  wrote:
> > >
> > > On Fri, 13 Nov 2020 10:34:14 -0800
> > > Sami Tolvanen  wrote:
> > >
> > > > my_tramp[12]? are declared as global functions in C, but they are not
> > > > marked global in the inline assembly definition. This mismatch confuses
> > > > Clang's Control-Flow Integrity checking. Fix the definitions by adding
> > > > .globl.
> > > >
> > >
> > > Actually, since that function is not really global, would it work if you
> > > removed the "extern" from the my_tramp declaration?
> >
> > Unfortunately not, removing the "extern" doesn't seem to change anything.
> >
> > > In other words, is there a way to tell C that a function is declared in an
> > > inline assembly block?
> >
> > I'm not sure if there's a way to tell C that a static function is
> > declared in inline assembly. At least I couldn't find a way that would
> > make the compiler happy.
>
> I'm trying to see the warning. What option makes clang trigger a warning on
> this?

Clang doesn't warn about this as we're building a module, it just
generates a reference to a non-existing global "my_tramp" symbol,
because the one defined in inline assembly has a local binding:

$ readelf --symbols --wide ftrace-direct.lto.o | grep my_tramp
16: 13 FUNCLOCAL  DEFAULT1 my_tramp
33:  0 NOTYPE  GLOBAL DEFAULT  UND my_tramp
42:  8 FUNCGLOBAL HIDDEN 8 my_tramp.cfi_jt

This would prevent the module from loading, which modpost catches:

ERROR: modpost: "my_tramp" [samples/ftrace/ftrace-direct.ko] undefined!

> From user space, I'm just using the following file:

As this error happens only with Control-Flow Integrity, we need to
take the address of the "test" function to force the compiler to
generate a jump table entry for it. Here's a slightly tweaked
stand-alone reproducer:

https://godbolt.org/z/GnzjE4

Sami


Re: [PATCH v41 11/24] x86/sgx: Add SGX misc driver interface

2020-11-16 Thread Dave Hansen
On 11/14/20 8:01 PM, Hillf Danton wrote:
> On Fri, 13 Nov 2020 00:01:22 +0200 Jarkko Sakkinen wrote:
> +
> +static unsigned long sgx_get_unmapped_area(struct file *file,
> +unsigned long addr,
> +unsigned long len,
> +unsigned long pgoff,
> +unsigned long flags)
> +{
> + if ((flags & MAP_TYPE) == MAP_PRIVATE)
> + return -EINVAL;
> +
> + if (flags & MAP_FIXED)
> + return addr;
> +
> MAP_FIXED is checked in arch_get_unmapped_area() along with others,
> so better to check it always there.

In the whole tangle of get_unmapped_area() functions, it wasn't patently
obvious to me that MAP_FIXED functionality is guaranteed to be present
in the higher-level functions.

There are also a fair number of these fops->get_unmapped_area()
instances that have the same MAP_FIXED line.  Are in need of fixups too?
 Or are you suggesting that since SGX is x86-only, it can depend on the
x86 arch_get_unmapped_area() code to continue to have this MAP_FIXED
functionality?


[tip: core/entry] seccomp: Migrate to use SYSCALL_WORK flag

2020-11-16 Thread tip-bot2 for Gabriel Krisman Bertazi
The following commit has been merged into the core/entry branch of tip:

Commit-ID: 23d67a54857a768acdb0804cdd6037c324a50ecd
Gitweb:
https://git.kernel.org/tip/23d67a54857a768acdb0804cdd6037c324a50ecd
Author:Gabriel Krisman Bertazi 
AuthorDate:Mon, 16 Nov 2020 12:42:00 -05:00
Committer: Thomas Gleixner 
CommitterDate: Mon, 16 Nov 2020 21:53:15 +01:00

seccomp: Migrate to use SYSCALL_WORK flag

On architectures using the generic syscall entry code the architecture
independent syscall work is moved to flags in thread_info::syscall_work.
This removes architecture dependencies and frees up TIF bits.

Define SYSCALL_WORK_SECCOMP, use it in the generic entry code and convert
the code which uses the TIF specific helper functions to use the new
*_syscall_work() helpers which either resolve to the new mode for users of
the generic entry code or to the TIF based functions for the other
architectures.

Signed-off-by: Gabriel Krisman Bertazi 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Andy Lutomirski 
Link: https://lore.kernel.org/r/20201116174206.2639648-5-kris...@collabora.com
---
 include/asm-generic/syscall.h | 2 +-
 include/linux/entry-common.h  | 8 ++--
 include/linux/seccomp.h   | 2 +-
 include/linux/thread_info.h   | 6 ++
 kernel/entry/common.c | 2 +-
 kernel/fork.c | 2 +-
 kernel/seccomp.c  | 6 +++---
 7 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h
index f3135e7..524d8e6 100644
--- a/include/asm-generic/syscall.h
+++ b/include/asm-generic/syscall.h
@@ -135,7 +135,7 @@ void syscall_set_arguments(struct task_struct *task, struct 
pt_regs *regs,
  * Returns the AUDIT_ARCH_* based on the system call convention in use.
  *
  * It's only valid to call this when @task is stopped on entry to a system
- * call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or %TIF_SECCOMP.
+ * call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or 
%SYSCALL_WORK_SECCOMP.
  *
  * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
  * provide an implementation of this.
diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index 3fe8f86..fa3cdb1 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -21,10 +21,6 @@
 # define _TIF_SYSCALL_TRACEPOINT   (0)
 #endif
 
-#ifndef _TIF_SECCOMP
-# define _TIF_SECCOMP  (0)
-#endif
-
 #ifndef _TIF_SYSCALL_AUDIT
 # define _TIF_SYSCALL_AUDIT(0)
 #endif
@@ -49,7 +45,7 @@
 #endif
 
 #define SYSCALL_ENTER_WORK \
-   (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP |   \
+   (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT  | \
 _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU |   \
 ARCH_SYSCALL_ENTER_WORK)
 
@@ -64,7 +60,7 @@
(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT |  \
 _TIF_SYSCALL_TRACEPOINT | ARCH_SYSCALL_EXIT_WORK)
 
-#define SYSCALL_WORK_ENTER (0)
+#define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP)
 #define SYSCALL_WORK_EXIT  (0)
 
 /*
diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
index 02aef28..47763f3 100644
--- a/include/linux/seccomp.h
+++ b/include/linux/seccomp.h
@@ -42,7 +42,7 @@ struct seccomp {
 extern int __secure_computing(const struct seccomp_data *sd);
 static inline int secure_computing(void)
 {
-   if (unlikely(test_thread_flag(TIF_SECCOMP)))
+   if (unlikely(test_syscall_work(SECCOMP)))
return  __secure_computing(NULL);
return 0;
 }
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 0e9fb15..a308ba4 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -35,6 +35,12 @@ enum {
GOOD_STACK,
 };
 
+enum syscall_work_bit {
+   SYSCALL_WORK_BIT_SECCOMP,
+};
+
+#define SYSCALL_WORK_SECCOMP   BIT(SYSCALL_WORK_BIT_SECCOMP)
+
 #include 
 
 #ifdef __KERNEL__
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index e7a11e3..5747a6e 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -54,7 +54,7 @@ static long syscall_trace_enter(struct pt_regs *regs, long 
syscall,
}
 
/* Do seccomp after ptrace, to catch any tracer changes. */
-   if (ti_work & _TIF_SECCOMP) {
+   if (work & SYSCALL_WORK_SECCOMP) {
ret = __secure_computing(NULL);
if (ret == -1L)
return ret;
diff --git a/kernel/fork.c b/kernel/fork.c
index 32083db..bc5b109 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1625,7 +1625,7 @@ static void copy_seccomp(struct task_struct *p)
 * to manually enable the seccomp thread flag here.
 */
if (p->seccomp.mode != SECCOMP_MODE_DISABLED)
-   set_tsk_thread_flag(p, TIF_SECCOMP);
+   set_task_syscall_work(p, SECCOMP);
 #endif
 }
 
diff 

Re: [PATCH] arm64: kexec: Use smp_send_stop in machine_shutdown

2020-11-16 Thread Henry Willard

James

Thanks for taking the time to review this and the pointers.

On 11/11/20 10:11 AM, James Morse wrote:

Hi Henry,

On 06/11/2020 23:25, Henry Willard wrote:

machine_shutdown() is called by kernel_kexec() to shutdown
the non-boot CPUs prior to starting the new kernel. The
implementation of machine_shutdown() varies by architecture.
Many make an interprocessor call, such as smp_send_stop(),
to stop the non-boot CPUs. On some architectures the CPUs make
some sort of firmware call to stop the CPU. On some architectures
without the necessary firmware support to stop the CPU, the CPUs
go into a disabled loop, which is not suitable for supporting
kexec. On Arm64 systems that support PSCI, CPUs can be stopped
with a PSCI CPU_OFF call.

All this variation is because we want to to get the CPU back in a sane state, 
as if we'd
just come from cold boot. Without the platform firmware doing its 
initialisation, the only
way we have of doing this is to run the cpuhp callbacks to take the CPU offline 
cleanly.
If it is unsafe to call cpu_ops.cpu_die (or cpu_die) on Arm except from 
cpuhp shouldn't something detect that?




Arm64 machine_shutdown() uses the CPU hotplug infrastructure via
smp_shutdown_nonboot_cpus() to stop each CPU. This is relatively
slow and takes a best case of .02 to .03 seconds per CPU which are
stopped sequentially.

Hmmm, looks like cpuhp doesn't have a way to run the callbacks in parallel...



This can take the better part of a second for
all the CPUs to be stopped depending on how many CPUs are present.
If for some reason the CPUs are busy at the time of the kexec reboot,
it can take several seconds to shut them all down.

Busy doing what?

Executing user code


I assume the problem is CPUs starting work on behalf of user-space, which is now
pointless, which prevents them from scheduling into the cpuhp work quickly.

Does hoisting kexec's conditional call to freeze_processes() above the #ifdef - 
so that
user-space threads are no longer schedule-able improve things here?

It might help the worst cases, but even on an idle system it takes a while.




Each CPU shuts itself down by calling PSCI CPU_OFF.
In some applications such as embedded systems, which need a very
fast reboot (less than a second), this may be too slow.

Where does this requirement come from? Surely kexec is part of a software 
update, not
regular operation.
The requirement comes from the owner of the larger environment of which 
this embedded system is a part. So, yes, this is part of software 
maintenance of a component during regular operation.

This patch reverts to using smp_send_stop() to signal all
CPUs to stop immediately. Currently smp_send_stop() causes each cpu
to call local_cpu_stop(), which goes into a disabled loop. This patch
modifies local_cpu_stop() to call cpu_die() when kexec_in_progress
is true, so that the CPU calls PSCI CPU_OFF just as in the case of
smp_shutdown_nonboot_cpus().

This is appropriate for panic(), as we accept it may fail.

For Kexec(), the CPU must go offline, otherwise we can't overwrite the code it 
was
running. The arch code can't just call CPU_OFF in any context. See 5.5 CPU_OFF' 
of
https://developer.arm.com/documentation/den0022/d

5.5.2 describes what the OS must do first, in particular interrupts must be 
migrated away
from the CPU calling CPU_OFF. Currently the cpuhp notifiers do this, which 
after this
patch, no longer run.
I believe this is done by irq_migrate_all_off_this_cpu(), which is 
called by take_cpu_down() scheduled on the processor to be shutdown by 
stop_machine_cpuslocked(). I missed that. While take_cpu_down() is 
running on the target processor the boot CPU is waiting, which is part 
of the reason for the latency.


You're going to need some duct-tape here, but I recall the proposed
'ARCH_OFFLINE_CPUS_ON_REBOOT', which would help, but isn't a complete thing. 
From the
discussion:
https://lore.kernel.org/lkml/87h80vwta7@nanos.tec.linutronix.de/
https://lore.kernel.org/lkml/alpine.deb.2.21.1908201321200.2...@nanos.tec.linutronix.de/

using cpuhp to offline these CPUs is the right thing to do.
If the problem is its too slow, can we tackled that instead?
I think it is relatively slow because the CPUs are shutdown 
sequentially. Besides ia64, most of the architectures that support 
kexec, appear to kill them all at once. I will try again. Thanks for the 
pointers.




Using smp_send_stop() instead of
smp_shutdown_nonboot_cpus() reduces the shutdown time for 23 CPUs
from about .65 seconds on an idle system to less than 5 msecs. On a
busy system smp_shutdown_nonboot_cpus() may take several seconds,
while smp_send_stop() needs only the 5 msecs.
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 4784011cecac..2568452a2417 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -142,12 +143,22 @@ void arch_cpu_idle_dead(void)
   * This must completely disable all secondary CPUs; simply causing those CPUs
   * to 

[tip: core/entry] entry: Expose helpers to migrate TIF to SYSCALL_WORK flags

2020-11-16 Thread tip-bot2 for Gabriel Krisman Bertazi
The following commit has been merged into the core/entry branch of tip:

Commit-ID: 3136b93c3fb2b7c19e853e049203ff8f2b9dd2cd
Gitweb:
https://git.kernel.org/tip/3136b93c3fb2b7c19e853e049203ff8f2b9dd2cd
Author:Gabriel Krisman Bertazi 
AuthorDate:Mon, 16 Nov 2020 12:41:58 -05:00
Committer: Thomas Gleixner 
CommitterDate: Mon, 16 Nov 2020 21:53:15 +01:00

entry: Expose helpers to migrate TIF to SYSCALL_WORK flags

With the goal to split the syscall work related flags into a separate
field that is architecture independent, expose transitional helpers that
resolve to either the TIF flags or to the corresponding SYSCALL_WORK
flags.  This will allow architectures to migrate only when they port to
the generic syscall entry code.

Signed-off-by: Gabriel Krisman Bertazi 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Andy Lutomirski 
Link: https://lore.kernel.org/r/20201116174206.2639648-3-kris...@collabora.com


---
 include/linux/thread_info.h | 32 
 1 file changed, 32 insertions(+)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index e93e249..0e9fb15 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -97,6 +97,38 @@ static inline int test_ti_thread_flag(struct thread_info 
*ti, int flag)
 #define test_thread_flag(flag) \
test_ti_thread_flag(current_thread_info(), flag)
 
+#ifdef CONFIG_GENERIC_ENTRY
+#define set_syscall_work(fl) \
+   set_bit(SYSCALL_WORK_BIT_##fl, _thread_info()->syscall_work)
+#define test_syscall_work(fl) \
+   test_bit(SYSCALL_WORK_BIT_##fl, _thread_info()->syscall_work)
+#define clear_syscall_work(fl) \
+   clear_bit(SYSCALL_WORK_BIT_##fl, _thread_info()->syscall_work)
+
+#define set_task_syscall_work(t, fl) \
+   set_bit(SYSCALL_WORK_BIT_##fl, _thread_info(t)->syscall_work)
+#define test_task_syscall_work(t, fl) \
+   test_bit(SYSCALL_WORK_BIT_##fl, _thread_info(t)->syscall_work)
+#define clear_task_syscall_work(t, fl) \
+   clear_bit(SYSCALL_WORK_BIT_##fl, _thread_info(t)->syscall_work)
+
+#else /* CONFIG_GENERIC_ENTRY */
+
+#define set_syscall_work(fl)   \
+   set_ti_thread_flag(current_thread_info(), SYSCALL_WORK_##fl)
+#define test_syscall_work(fl) \
+   test_ti_thread_flag(current_thread_info(), SYSCALL_WORK_##fl)
+#define clear_syscall_work(fl) \
+   clear_ti_thread_flag(current_thread_info(), SYSCALL_WORK_##fl)
+
+#define set_task_syscall_work(t, fl) \
+   set_ti_thread_flag(task_thread_info(t), TIF_##fl)
+#define test_task_syscall_work(t, fl) \
+   test_ti_thread_flag(task_thread_info(t), TIF_##fl)
+#define clear_task_syscall_work(t, fl) \
+   clear_ti_thread_flag(task_thread_info(t), TIF_##fl)
+#endif /* !CONFIG_GENERIC_ENTRY */
+
 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
 
 #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES


[tip: core/entry] tracepoints: Migrate to use SYSCALL_WORK flag

2020-11-16 Thread tip-bot2 for Gabriel Krisman Bertazi
The following commit has been merged into the core/entry branch of tip:

Commit-ID: 524666cb5de7c38a1925e7401a6e59d68682dd8c
Gitweb:
https://git.kernel.org/tip/524666cb5de7c38a1925e7401a6e59d68682dd8c
Author:Gabriel Krisman Bertazi 
AuthorDate:Mon, 16 Nov 2020 12:42:01 -05:00
Committer: Thomas Gleixner 
CommitterDate: Mon, 16 Nov 2020 21:53:15 +01:00

tracepoints: Migrate to use SYSCALL_WORK flag

On architectures using the generic syscall entry code the architecture
independent syscall work is moved to flags in thread_info::syscall_work.
This removes architecture dependencies and frees up TIF bits.

Define SYSCALL_WORK_SYSCALL_TRACEPOINT, use it in the generic entry code
and convert the code which uses the TIF specific helper functions to use
the new *_syscall_work() helpers which either resolve to the new mode for
users of the generic entry code or to the TIF based functions for the other
architectures.

Signed-off-by: Gabriel Krisman Bertazi 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Andy Lutomirski 
Link: https://lore.kernel.org/r/20201116174206.2639648-6-kris...@collabora.com
---
 include/linux/entry-common.h | 13 +
 include/linux/thread_info.h  |  2 ++
 include/trace/syscall.h  |  6 +++---
 kernel/entry/common.c|  4 ++--
 kernel/trace/trace_events.c  |  8 
 kernel/tracepoint.c  |  4 ++--
 6 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index fa3cdb1..2a01eee 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -17,10 +17,6 @@
 # define _TIF_SYSCALL_EMU  (0)
 #endif
 
-#ifndef _TIF_SYSCALL_TRACEPOINT
-# define _TIF_SYSCALL_TRACEPOINT   (0)
-#endif
-
 #ifndef _TIF_SYSCALL_AUDIT
 # define _TIF_SYSCALL_AUDIT(0)
 #endif
@@ -46,7 +42,7 @@
 
 #define SYSCALL_ENTER_WORK \
(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT  | \
-_TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU |   \
+_TIF_SYSCALL_EMU | \
 ARCH_SYSCALL_ENTER_WORK)
 
 /*
@@ -58,10 +54,11 @@
 
 #define SYSCALL_EXIT_WORK  \
(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT |  \
-_TIF_SYSCALL_TRACEPOINT | ARCH_SYSCALL_EXIT_WORK)
+ARCH_SYSCALL_EXIT_WORK)
 
-#define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP)
-#define SYSCALL_WORK_EXIT  (0)
+#define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP | \
+SYSCALL_WORK_SYSCALL_TRACEPOINT)
+#define SYSCALL_WORK_EXIT  (SYSCALL_WORK_SYSCALL_TRACEPOINT)
 
 /*
  * TIF flags handled in exit_to_user_mode_loop()
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index a308ba4..c232043 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -37,9 +37,11 @@ enum {
 
 enum syscall_work_bit {
SYSCALL_WORK_BIT_SECCOMP,
+   SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT,
 };
 
 #define SYSCALL_WORK_SECCOMP   BIT(SYSCALL_WORK_BIT_SECCOMP)
+#define SYSCALL_WORK_SYSCALL_TRACEPOINT
BIT(SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT)
 
 #include 
 
diff --git a/include/trace/syscall.h b/include/trace/syscall.h
index dc8ac27..8e193f3 100644
--- a/include/trace/syscall.h
+++ b/include/trace/syscall.h
@@ -37,10 +37,10 @@ struct syscall_metadata {
 #if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
 static inline void syscall_tracepoint_update(struct task_struct *p)
 {
-   if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
-   set_tsk_thread_flag(p, TIF_SYSCALL_TRACEPOINT);
+   if (test_syscall_work(SYSCALL_TRACEPOINT))
+   set_task_syscall_work(p, SYSCALL_TRACEPOINT);
else
-   clear_tsk_thread_flag(p, TIF_SYSCALL_TRACEPOINT);
+   clear_task_syscall_work(p, SYSCALL_TRACEPOINT);
 }
 #else
 static inline void syscall_tracepoint_update(struct task_struct *p)
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 5747a6e..f651967 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -63,7 +63,7 @@ static long syscall_trace_enter(struct pt_regs *regs, long 
syscall,
/* Either of the above might have changed the syscall number */
syscall = syscall_get_nr(current, regs);
 
-   if (unlikely(ti_work & _TIF_SYSCALL_TRACEPOINT))
+   if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, syscall);
 
syscall_enter_audit(regs, syscall);
@@ -233,7 +233,7 @@ static void syscall_exit_work(struct pt_regs *regs, 
unsigned long ti_work,
 
audit_syscall_exit(regs);
 
-   if (ti_work & _TIF_SYSCALL_TRACEPOINT)
+   if (work & SYSCALL_WORK_SYSCALL_TRACEPOINT)
trace_sys_exit(regs, syscall_get_return_value(current, regs));
 

[tip: core/entry] ptrace: Migrate TIF_SYSCALL_EMU to use SYSCALL_WORK flag

2020-11-16 Thread tip-bot2 for Gabriel Krisman Bertazi
The following commit has been merged into the core/entry branch of tip:

Commit-ID: 64eb35f701f04b30706e21d1b02636b5d31a37d2
Gitweb:
https://git.kernel.org/tip/64eb35f701f04b30706e21d1b02636b5d31a37d2
Author:Gabriel Krisman Bertazi 
AuthorDate:Mon, 16 Nov 2020 12:42:03 -05:00
Committer: Thomas Gleixner 
CommitterDate: Mon, 16 Nov 2020 21:53:16 +01:00

ptrace: Migrate TIF_SYSCALL_EMU to use SYSCALL_WORK flag

On architectures using the generic syscall entry code the architecture
independent syscall work is moved to flags in thread_info::syscall_work.
This removes architecture dependencies and frees up TIF bits.

Define SYSCALL_WORK_SYSCALL_EMU, use it in the generic entry code and
convert the code which uses the TIF specific helper functions to use the
new *_syscall_work() helpers which either resolve to the new mode for users
of the generic entry code or to the TIF based functions for the other
architectures.

Signed-off-by: Gabriel Krisman Bertazi 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Andy Lutomirski 
Link: https://lore.kernel.org/r/20201116174206.2639648-8-kris...@collabora.com
---
 include/linux/entry-common.h |  8 ++--
 include/linux/thread_info.h  |  2 ++
 include/linux/tracehook.h|  2 +-
 kernel/entry/common.c| 19 ++-
 kernel/fork.c|  4 ++--
 kernel/ptrace.c  | 10 +-
 6 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index ae426ab..b30f82b 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -13,10 +13,6 @@
  * Define dummy _TIF work flags if not defined by the architecture or for
  * disabled functionality.
  */
-#ifndef _TIF_SYSCALL_EMU
-# define _TIF_SYSCALL_EMU  (0)
-#endif
-
 #ifndef _TIF_SYSCALL_AUDIT
 # define _TIF_SYSCALL_AUDIT(0)
 #endif
@@ -42,7 +38,6 @@
 
 #define SYSCALL_ENTER_WORK \
(_TIF_SYSCALL_AUDIT  |  \
-_TIF_SYSCALL_EMU | \
 ARCH_SYSCALL_ENTER_WORK)
 
 /*
@@ -58,7 +53,8 @@
 
 #define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP | \
 SYSCALL_WORK_SYSCALL_TRACEPOINT |  \
-SYSCALL_WORK_SYSCALL_TRACE)
+SYSCALL_WORK_SYSCALL_TRACE |   \
+SYSCALL_WORK_SYSCALL_EMU)
 #define SYSCALL_WORK_EXIT  (SYSCALL_WORK_SYSCALL_TRACEPOINT |  \
 SYSCALL_WORK_SYSCALL_TRACE)
 
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index 761a459..85b8a42 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -39,11 +39,13 @@ enum syscall_work_bit {
SYSCALL_WORK_BIT_SECCOMP,
SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT,
SYSCALL_WORK_BIT_SYSCALL_TRACE,
+   SYSCALL_WORK_BIT_SYSCALL_EMU,
 };
 
 #define SYSCALL_WORK_SECCOMP   BIT(SYSCALL_WORK_BIT_SECCOMP)
 #define SYSCALL_WORK_SYSCALL_TRACEPOINT
BIT(SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT)
 #define SYSCALL_WORK_SYSCALL_TRACE BIT(SYSCALL_WORK_BIT_SYSCALL_TRACE)
+#define SYSCALL_WORK_SYSCALL_EMU   BIT(SYSCALL_WORK_BIT_SYSCALL_EMU)
 
 #include 
 
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index 3f20368..54b9252 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -84,7 +84,7 @@ static inline int ptrace_report_syscall(struct pt_regs *regs,
  * @regs:  user register state of current task
  *
  * This will be called if %SYSCALL_WORK_SYSCALL_TRACE or
- * %TIF_SYSCALL_EMU have been set, when the current task has just
+ * %SYSCALL_WORK_SYSCALL_EMU have been set, when the current task has just
  * entered the kernel for a system call.  Full user register state is
  * available here.  Changing the values in @regs can affect the system
  * call number and arguments to be tried.  It is safe to block here,
diff --git a/kernel/entry/common.c b/kernel/entry/common.c
index 917328a..90533f3 100644
--- a/kernel/entry/common.c
+++ b/kernel/entry/common.c
@@ -47,9 +47,9 @@ static long syscall_trace_enter(struct pt_regs *regs, long 
syscall,
long ret = 0;
 
/* Handle ptrace */
-   if (work & SYSCALL_WORK_SYSCALL_TRACE || ti_work & _TIF_SYSCALL_EMU) {
+   if (work & (SYSCALL_WORK_SYSCALL_TRACE | SYSCALL_WORK_SYSCALL_EMU)) {
ret = arch_syscall_enter_tracehook(regs);
-   if (ret || (ti_work & _TIF_SYSCALL_EMU))
+   if (ret || (work & SYSCALL_WORK_SYSCALL_EMU))
return -1L;
}
 
@@ -208,21 +208,22 @@ static void exit_to_user_mode_prepare(struct pt_regs 
*regs)
 }
 
 #ifndef _TIF_SINGLESTEP
-static inline bool report_single_step(unsigned long ti_work)
+static inline bool 

[tip: core/entry] x86: Reclaim unused x86 TI flags

2020-11-16 Thread tip-bot2 for Gabriel Krisman Bertazi
The following commit has been merged into the core/entry branch of tip:

Commit-ID: 51af3f23063946344330a77a7d1dece6fc6bb5d8
Gitweb:
https://git.kernel.org/tip/51af3f23063946344330a77a7d1dece6fc6bb5d8
Author:Gabriel Krisman Bertazi 
AuthorDate:Mon, 16 Nov 2020 12:42:06 -05:00
Committer: Thomas Gleixner 
CommitterDate: Mon, 16 Nov 2020 21:53:16 +01:00

x86: Reclaim unused x86 TI flags

Reclaim TI flags that were migrated to syscall_work flags.

Signed-off-by: Gabriel Krisman Bertazi 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Andy Lutomirski 
Link: https://lore.kernel.org/r/20201116174206.2639648-11-kris...@collabora.com

---
 arch/x86/include/asm/thread_info.h | 10 --
 1 file changed, 10 deletions(-)

diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index 0da5d58..0d751d5 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -75,15 +75,11 @@ struct thread_info {
  * - these are process state flags that various assembly files
  *   may need to access
  */
-#define TIF_SYSCALL_TRACE  0   /* syscall trace active */
 #define TIF_NOTIFY_RESUME  1   /* callback before returning to user */
 #define TIF_SIGPENDING 2   /* signal pending */
 #define TIF_NEED_RESCHED   3   /* rescheduling necessary */
 #define TIF_SINGLESTEP 4   /* reenable singlestep on user return*/
 #define TIF_SSBD   5   /* Speculative store bypass disable */
-#define TIF_SYSCALL_EMU6   /* syscall emulation active */
-#define TIF_SYSCALL_AUDIT  7   /* syscall auditing active */
-#define TIF_SECCOMP8   /* secure computing */
 #define TIF_SPEC_IB9   /* Indirect branch speculation 
mitigation */
 #define TIF_SPEC_FORCE_UPDATE  10  /* Force speculation MSR update in 
context switch */
 #define TIF_USER_RETURN_NOTIFY 11  /* notify kernel of userspace return */
@@ -100,18 +96,13 @@ struct thread_info {
 #define TIF_FORCED_TF  24  /* true if TF in eflags artificially */
 #define TIF_BLOCKSTEP  25  /* set when we want DEBUGCTLMSR_BTF */
 #define TIF_LAZY_MMU_UPDATES   27  /* task is updating the mmu lazily */
-#define TIF_SYSCALL_TRACEPOINT 28  /* syscall tracepoint instrumentation */
 #define TIF_ADDR32 29  /* 32-bit address space on 64 bits */
 
-#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
 #define _TIF_SIGPENDING(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED  (1 << TIF_NEED_RESCHED)
 #define _TIF_SINGLESTEP(1 << TIF_SINGLESTEP)
 #define _TIF_SSBD  (1 << TIF_SSBD)
-#define _TIF_SYSCALL_EMU   (1 << TIF_SYSCALL_EMU)
-#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP   (1 << TIF_SECCOMP)
 #define _TIF_SPEC_IB   (1 << TIF_SPEC_IB)
 #define _TIF_SPEC_FORCE_UPDATE (1 << TIF_SPEC_FORCE_UPDATE)
 #define _TIF_USER_RETURN_NOTIFY(1 << TIF_USER_RETURN_NOTIFY)
@@ -127,7 +118,6 @@ struct thread_info {
 #define _TIF_FORCED_TF (1 << TIF_FORCED_TF)
 #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
 #define _TIF_LAZY_MMU_UPDATES  (1 << TIF_LAZY_MMU_UPDATES)
-#define _TIF_SYSCALL_TRACEPOINT(1 << TIF_SYSCALL_TRACEPOINT)
 #define _TIF_ADDR32(1 << TIF_ADDR32)
 
 /* flags to check in __switch_to() */


Re: [PATCH] compiler.h: Fix barrier_data() on clang

2020-11-16 Thread Andreas Schwab
On Nov 16 2020, Nick Desaulniers wrote:

> A lot of VDSO's reset KBUILD_CFLAGS or use a new variable for their
> compiler flags.  As such, they're missing `-include` command line flag
> that injects include/linux/compiler_types.h,

It's not missing here.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [PATCH v4] Add power/gpu_frequency tracepoint.

2020-11-16 Thread Steven Rostedt
On Mon, 16 Nov 2020 12:55:29 -0800
Peiyong Lin  wrote:

> Hi there,
> 
> May I ask whether the merge window has passed? If so is it possible to
> ask for a review?

This is up to the maintainers of power management to accept this.

Rafael?

-- Steve


Re: [PATCH] bpf: don't fail kmalloc while releasing raw_tp

2020-11-16 Thread Steven Rostedt
On Mon, 16 Nov 2020 16:02:18 -0500
Steven Rostedt  wrote:

> + if (new) {
> + for (i = 0; old[i].func; i++)
> + if (old[i].func != tp_func->func
> + || old[i].data != tp_func->data)
> + new[j++] = old[i];

Oops, need to check for old[i].func != tp_stub_func here too.

-- Steve

> + new[nr_probes - nr_del].func = NULL;
> + } else {


[PATCH] ubifs: wbuf: Don't leak kernel memory to flash

2020-11-16 Thread Richard Weinberger
Write buffers use a kmalloc()'ed buffer, they can leak
up to seven bytes of kernel memory to flash if writes are not
aligned.
So use ubifs_pad() to fill these gaps with padding bytes.
This was never a problem while scanning because the scanner logic
manually aligns node lengths and skips over these gaps.

Cc: 
Fixes: 1e51764a3c2ac05a2 ("UBIFS: add new flash file system")
Signed-off-by: Richard Weinberger 
---
 fs/ubifs/io.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
index 7e4bfaf2871f..eae9cf5a57b0 100644
--- a/fs/ubifs/io.c
+++ b/fs/ubifs/io.c
@@ -319,7 +319,7 @@ void ubifs_pad(const struct ubifs_info *c, void *buf, int 
pad)
 {
uint32_t crc;
 
-   ubifs_assert(c, pad >= 0 && !(pad & 7));
+   ubifs_assert(c, pad >= 0);
 
if (pad >= UBIFS_PAD_NODE_SZ) {
struct ubifs_ch *ch = buf;
@@ -764,6 +764,10 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void 
*buf, int len)
 * write-buffer.
 */
memcpy(wbuf->buf + wbuf->used, buf, len);
+   if (aligned_len > len) {
+   ubifs_assert(c, aligned_len - len < 8);
+   ubifs_pad(c, wbuf->buf + wbuf->used + len, aligned_len 
- len);
+   }
 
if (aligned_len == wbuf->avail) {
dbg_io("flush jhead %s wbuf to LEB %d:%d",
@@ -856,13 +860,18 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void 
*buf, int len)
}
 
spin_lock(>lock);
-   if (aligned_len)
+   if (aligned_len) {
/*
 * And now we have what's left and what does not take whole
 * max. write unit, so write it to the write-buffer and we are
 * done.
 */
memcpy(wbuf->buf, buf + written, len);
+   if (aligned_len > len) {
+   ubifs_assert(c, aligned_len - len < 8);
+   ubifs_pad(c, wbuf->buf + len, aligned_len - len);
+   }
+   }
 
if (c->leb_size - wbuf->offs >= c->max_write_size)
wbuf->size = c->max_write_size;
-- 
2.26.2



Re: [PATCH v1] spi: fix client driver breakages when using GPIO descriptors

2020-11-16 Thread Mark Brown
On Wed, Nov 11, 2020 at 02:36:07PM +0100, Linus Walleij wrote:
> On Wed, Nov 11, 2020 at 1:33 PM Mark Brown  wrote:
> > On Wed, Nov 11, 2020 at 02:05:19AM +0100, Linus Walleij wrote:

> > This is not clear to me, most of these settings are things that are
> > constant for the device so it's not clear that they should be being set
> > by the device tree in the first place.

> This was added initially with some two properties
> in drivers/of/of_spi.c in 2008:
> commit 284b01897340974000bcc84de87a4e1becc8a83d
> "spi: Add OF binding support for SPI busses"

> This was around the time ARM was first starting to migrate
> to device tree, so I suppose it made sense to them/us back
> then.

That's from PowerPC days, not ARM, and frankly a lot of DT conversions
were just fairly mechanical conversions of what was in platform data to
DT so they may not have been especially considered.

> compatible-string. It was later that especially Rob pointed out that
> random properties on device nodes was overused and that simply
> knowing the compatible is often enough.

I've been pushing this since forever as well, as far as I remember it's
been a thing since we started doing this.

> I don't know if we ever formalized it, there is nowadays a rule akin to

> "if a property can be determined from the compatible-string, and if the
>  compatible-string is identifying the variant of the electronic component,
>  then do not add this property to the device tree description. Just
>  deduce it from the compatible-string, assign it with code to the device
>  model of the operating system and handle it inside the operating system."

> I think this, while clear and intuitive, wasn't at all clear and intuitive in
> the recent past.

I think the main push in the other direction has always been people who
want to not have to write a driver at all and put absolutely everything
into DT which has scaling issues :/


signature.asc
Description: PGP signature


[PATCH v2] memfd_secret.2: New page describing memfd_secret() system call

2020-11-16 Thread Alejandro Colomar
From: Mike Rapoport 

Signed-off-by: Mike Rapoport 
Cowritten-by: Alejandro Colomar 
Acked-by: Alejandro Colomar 
Signed-off-by: Alejandro Colomar 
---

Hi Mike,

I added that note about not having a wrapper,
fixed a few minor formatting and wording issues,
and sorted ERRORS alphabetically.

Cheers,

Alex

 man2/memfd_secret.2 | 178 
 1 file changed, 178 insertions(+)
 create mode 100644 man2/memfd_secret.2

diff --git a/man2/memfd_secret.2 b/man2/memfd_secret.2
new file mode 100644
index 0..4e617aa0e
--- /dev/null
+++ b/man2/memfd_secret.2
@@ -0,0 +1,178 @@
+.\" Copyright (c) 2020, IBM Corporation.
+.\" Written by Mike Rapoport 
+.\"
+.\" Based on memfd_create(2) man page
+.\" Copyright (C) 2014 Michael Kerrisk 
+.\" and Copyright (C) 2014 David Herrmann 
+.\"
+.\" %%%LICENSE_START(GPLv2+)
+.\"
+.\" This program is free software; you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation; either version 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" This program is distributed in the hope that it will be useful,
+.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public
+.\" License along with this manual; if not, see
+.\" .
+.\" %%%LICENSE_END
+.\"
+.TH MEMFD_SECRET 2 2020-08-02 Linux "Linux Programmer's Manual"
+.SH NAME
+memfd_secret \- create an anonymous file to map secret memory regions
+.SH SYNOPSIS
+.nf
+.B #include 
+.PP
+.BI "int memfd_secret(unsigned long " flags ");"
+.fi
+.PP
+.IR Note :
+There is no glibc wrapper for this system call; see NOTES.
+.SH DESCRIPTION
+.BR memfd_secret ()
+creates an anonymous file and returns a file descriptor that refers to it.
+The file can only be memory-mapped;
+the memory in such mapping
+will have stronger protection than usual memory mapped files,
+and so it can be used to store application secrets.
+Unlike a regular file, a file created with
+.BR memfd_secret ()
+lives in RAM and has a volatile backing storage.
+Once all references to the file are dropped, it is automatically released.
+The initial size of the file is set to 0.
+Following the call, the file size should be set using
+.BR ftruncate (2).
+.PP
+The memory areas obtained with
+.BR mmap (2)
+from the file descriptor are exclusive to the owning context.
+These areas are removed from the kernel page tables
+and only the page table of the process holding the file descriptor
+maps the corresponding physical memory.
+.PP
+The following values may be bitwise ORed in
+.IR flags
+to control the behavior of
+.BR memfd_secret (2):
+.TP
+.BR FD_CLOEXEC
+Set the close-on-exec flag on the new file descriptor.
+See the description of the
+.B O_CLOEXEC
+flag in
+.BR open (2)
+for reasons why this may be useful.
+.PP
+.TP
+.BR SECRETMEM_UNCACHED
+In addition to excluding memory areas from the kernel page tables,
+mark the memory mappings uncached in the page table of the owning process.
+Such mappings can be used to prevent speculative loads
+and cache-based side channels.
+This mode of
+.BR memfd_secret ()
+is not supported on all architectures.
+.PP
+See also NOTES below.
+.PP
+As its return value,
+.BR memfd_secret ()
+returns a new file descriptor that can be used to refer to an anonymous file.
+This file descriptor is opened for both reading and writing
+.RB ( O_RDWR )
+and
+.B O_LARGEFILE
+is set for the file descriptor.
+.PP
+With respect to
+.BR fork (2)
+and
+.BR execve (2),
+the usual semantics apply for the file descriptor created by
+.BR memfd_secret ().
+A copy of the file descriptor is inherited by the child produced by
+.BR fork (2)
+and refers to the same file.
+The file descriptor is preserved across
+.BR execve (2),
+unless the close-on-exec flag has been set.
+.PP
+The memory regions backed with
+.BR memfd_secret ()
+are locked in the same way as
+.BR mlock (2),
+however the implementation will not try to
+populate the whole range during the
+.BR mmap ()
+call.
+The amount of memory allowed for memory mappings
+of the file descriptor obeys the same rules as
+.BR mlock (2)
+and cannot exceed
+.BR RLIMIT_MEMLOCK .
+.SH RETURN VALUE
+On success,
+.BR memfd_secret ()
+returns a new file descriptor.
+On error, \-1 is returned and
+.I errno
+is set to indicate the error.
+.SH ERRORS
+.TP
+.B EINVAL
+.I flags
+included unknown bits.
+.TP
+.B EMFILE
+The per-process limit on the number of open file descriptors has been reached.
+.TP
+.B EMFILE
+The system-wide limit on the total number of open files has been reached.
+.TP
+.B ENOMEM
+There was insufficient memory to create a new anonymous file.
+.TP
+.B ENOSYS
+.BR memfd_secret ()
+is not implemented on this architecture.
+.SH VERSIONS
+The
+.BR memfd_secret (2)

Re: [FIX bpf,perf] bpf,perf: return EOPNOTSUPP for bpf handler on PERF_COUNT_SW_DUMMY

2020-11-16 Thread Martin KaFai Lau
On Mon, Nov 16, 2020 at 07:37:52PM +0100, Florian Lehner wrote:
> bpf handlers for perf events other than tracepoints, kprobes or uprobes
> are attached to the overflow_handler of the perf event.
> 
> Perf events of type software/dummy are placeholder events. So when
> attaching a bpf handle to an overflow_handler of such an event, the bpf
> handler will not be triggered.
> 
> This fix returns the error EOPNOTSUPP to indicate that attaching a bpf
> handler to a perf event of type software/dummy is not supported.
> 
> Signed-off-by: Florian Lehner 
It is missing a Fixes tag.


Re: [PATCH] bpf: don't fail kmalloc while releasing raw_tp

2020-11-16 Thread Steven Rostedt
On Mon, 16 Nov 2020 15:44:37 -0500
Steven Rostedt  wrote:

> If you use a stub function, it shouldn't affect anything. And the worse
> that would happen is that you have a slight overhead of calling the stub
> until you can properly remove the callback.

Something like this:

(haven't compiled it yet, I'm about to though).

-- Steve

diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 3f659f855074..8eab40f9d388 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -53,10 +53,16 @@ struct tp_probes {
struct tracepoint_func probes[];
 };
 
-static inline void *allocate_probes(int count)
+/* Called in removal of a func but failed to allocate a new tp_funcs */
+static void tp_stub_func(void)
+{
+   return;
+}
+
+static inline void *allocate_probes(int count, gfp_t extra_flags)
 {
struct tp_probes *p  = kmalloc(struct_size(p, probes, count),
-  GFP_KERNEL);
+  GFP_KERNEL | extra_flags);
return p == NULL ? NULL : p->probes;
 }
 
@@ -150,7 +156,7 @@ func_add(struct tracepoint_func **funcs, struct 
tracepoint_func *tp_func,
}
}
/* + 2 : one for new probe, one for NULL func */
-   new = allocate_probes(nr_probes + 2);
+   new = allocate_probes(nr_probes + 2, 0);
if (new == NULL)
return ERR_PTR(-ENOMEM);
if (old) {
@@ -188,8 +194,9 @@ static void *func_remove(struct tracepoint_func **funcs,
/* (N -> M), (N > 1, M >= 0) probes */
if (tp_func->func) {
for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
-   if (old[nr_probes].func == tp_func->func &&
-old[nr_probes].data == tp_func->data)
+   if ((old[nr_probes].func == tp_func->func &&
+old[nr_probes].data == tp_func->data) ||
+   old[nr_probes].func == tp_stub_func)
nr_del++;
}
}
@@ -207,15 +214,20 @@ static void *func_remove(struct tracepoint_func **funcs,
int j = 0;
/* N -> M, (N > 1, M > 0) */
/* + 1 for NULL */
-   new = allocate_probes(nr_probes - nr_del + 1);
-   if (new == NULL)
-   return ERR_PTR(-ENOMEM);
-   for (i = 0; old[i].func; i++)
-   if (old[i].func != tp_func->func
-   || old[i].data != tp_func->data)
-   new[j++] = old[i];
-   new[nr_probes - nr_del].func = NULL;
-   *funcs = new;
+   new = allocate_probes(nr_probes - nr_del + 1, __GFP_NOFAIL);
+   if (new) {
+   for (i = 0; old[i].func; i++)
+   if (old[i].func != tp_func->func
+   || old[i].data != tp_func->data)
+   new[j++] = old[i];
+   new[nr_probes - nr_del].func = NULL;
+   } else {
+   for (i = 0; old[i].func; i++)
+   if (old[i].func == tp_func->func &&
+   old[i].data == tp_func->data)
+   old[i].func = tp_stub_func;
+   }
+   *funcs = old;
}
debug_print_probes(*funcs);
return old;
@@ -300,6 +312,10 @@ static int tracepoint_remove_func(struct tracepoint *tp,
return PTR_ERR(old);
}
 
+   if (tp_funcs == old)
+   /* Failed allocating new tp_funcs, replaced func with stub */
+   return 0;
+
if (!tp_funcs) {
/* Removed last function */
if (tp->unregfunc && static_key_enabled(>key))


Re: [PATCH] PCI: Disable PTM during suspend on Intel PCI bridges

2020-11-16 Thread David E. Box
On Mon, 2020-11-16 at 13:23 -0600, Bjorn Helgaas wrote:
> On Mon, Nov 16, 2020 at 06:53:09PM +0100, Rafael J. Wysocki wrote:
> > On Wed, Oct 7, 2020 at 7:10 PM Bjorn Helgaas 
> > wrote:
> > > On Wed, Oct 07, 2020 at 06:53:16PM +0200, Rafael J. Wysocki
> > > wrote:
> > > > On Wed, Oct 7, 2020 at 6:49 PM David E. Box <
> > > > david.e@linux.intel.com> wrote:
> > > > > On Intel Platform Controller Hubs (PCH) since Cannon Lake,
> > > > > the Precision
> > > > > Time Measurement (PTM) capability can prevent PCIe root ports
> > > > > from power
> > > > > gating during suspend-to-idle, causing increased power
> > > > > consumption on
> > > > > systems that suspend using Low Power S0 Idle [1]. The issue
> > > > > is yet to be
> > > > > root caused but believed to be coming from a race condition
> > > > > in the suspend
> > > > > flow as the incidence rate varies for different platforms on
> > > > > Linux but the
> > > > > issue does not occur at all in other operating systems. For
> > > > > now, disable
> > > > > the feature on suspend on all Intel root ports and enable
> > > > > again on resume.
> > > > 
> > > > IMV it should also be noted that there is no particular reason
> > > > why PTM
> > > > would need to be enabled while the whole system is
> > > > suspended.  At
> > > > least it doesn't seem to be particularly useful in that state.
> > > 
> > > Is this a hardware erratum?  If not, and this is working as
> > > designed,
> > > it sounds like we'd need to apply this quirk to every device that
> > > supports PTM.  That's not really practical.
> > 
> > Why not?
> 
> My objection was that the original patch is a quirk that applies only
> to Intel devices.
> 
> If this is a generic thing that should be done for *all* devices that
> support PTM, that's fine, but it should not be a quirk, and it should
> not involve a list of Vendor or Device IDs.
> 
> > It looks like the capability should be saved by pci_save_state()
> > (it
> > isn't ATM, which appears to be a mistake) and restored by
> > pci_restore_state(), so if that is implemented, the saving can be
> > combined with the disabling in principle.
> 
> Yup, looks like a mistake.  Maybe David can fix that at the same time
> (probably a separate patch, though).  I don't have a way to test it,
> but he probably does.

Yes, I can test save/restore of the PTM capability and submit a patch.

> 
> > > The bugzilla says "there is no erratum as this does not affect
> > > Windows," but that doesn't answer the question.  What I want to
> > > know
> > > is whether this is a *hardware* defect and whether it will be
> > > fixed in
> > > future hardware.
> > 
> > I cannot answer this question, sorry.
> > 
> > ATM we only know that certain SoCs may not enter the deepest idle
> > state if PTM is enabled on some PCIe root ports during suspend.
> > 
> > Disabling PTM on those ports while suspending helps and hence the
> > patch.
> > 
> > It doesn't appear to qualify as a "hardware defect".
> > 
> > > If it's a "wont-fix" hardware issue, we can just disable PTM
> > > completely on Intel hardware and we won't have to worry about it
> > > during suspend.
> > 
> > I'm not following the logic here, sorry again.
> > 
> > First of all, there are systems that never suspend, so why would
> > they
> > be affected by the remedy (whatever it is)?
> > 
> > Second, it is not about the suspend failing entirely.  It's about
> > being able to make the system draw less power while suspended.
> > 
> > Generally, if someone said "I can make the system draw less power
> > while suspended if I disable PCIe feature X during suspend", would
> > you
> > disregard that?
> 
> My questions were all prompted by the Intel-specific nature of the
> original patch, which suggests an ongoing maintenance burden.  If it
> can be done generically, I have no problem with it.

Okay. I'll add this to the save/restore patch then with the comment
that it saves power on some Intel platforms.

David



Re: [PATCH rdma-next v1 0/7] Use ib_umem_find_best_pgsz() for all umems

2020-11-16 Thread Jason Gunthorpe
On Sun, Nov 15, 2020 at 01:43:04PM +0200, Leon Romanovsky wrote:
> From: Leon Romanovsky 
> 
> Changelog:
> v1:
>  * Added patch for raw QP
>  * Fixed commit messages
> v0: https://lore.kernel.org/lkml/20201026132635.1337663-1-l...@kernel.org
> 
> -
> >From Jason:
> 
> Move the remaining cases working with umems to use versions of
> ib_umem_find_best_pgsz() tailored to the calculations the devices
> requires.
> 
> Unlike a MR there is no IOVA, instead a page offset from the starting page
> is possible, with various restrictions.
> 
> Compute the best page size to meet the page_offset restrictions.
> 
> Thanks
> 
> Jason Gunthorpe (7):
>   RDMA/mlx5: Use ib_umem_find_best_pgoff() for SRQ
>   RDMA/mlx5: Use mlx5_umem_find_best_quantized_pgoff() for WQ
>   RDMA/mlx5: Directly compute the PAS list for raw QP RQ's
>   RDMA/mlx5: Use mlx5_umem_find_best_quantized_pgoff() for QP
>   RDMA/mlx5: mlx5_umem_find_best_quantized_pgoff() for CQ
>   RDMA/mlx5: Use ib_umem_find_best_pgsz() for devx
>   RDMA/mlx5: Lower setting the umem's PAS for SRQ

Applied to for-next

Jason


Re: [PATCH v2 3/6] bus: mhi: core: Add support to stop or start channel data transfers

2020-11-16 Thread Bhaumik Bhatt

Hi Mani,

On 2020-11-16 04:43, Manivannan Sadhasivam wrote:

On Wed, Nov 11, 2020 at 11:21:10AM -0800, Bhaumik Bhatt wrote:

Some MHI client drivers may want to request a pause or halt of
data transfer activity on their channels. Support for this does
not exist and must be introduced, wherein the channel context is
not reset or cleared but only the STOP channel command is issued.
This would need to be paired with an API that allows resuming the
data transfer activity on channels by use of the START channel
command. This API assumes that the context information is already
setup. Enable this using two new APIs, mhi_start_transfer() and
mhi_stop_transfer().

Signed-off-by: Bhaumik Bhatt 
---
 drivers/bus/mhi/core/main.c | 41 
+

 include/linux/mhi.h | 19 +++
 2 files changed, 60 insertions(+)

diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c
index 1226933..1a969f4 100644
--- a/drivers/bus/mhi/core/main.c
+++ b/drivers/bus/mhi/core/main.c
@@ -1560,6 +1560,47 @@ void mhi_unprepare_from_transfer(struct 
mhi_device *mhi_dev)

 }
 EXPORT_SYMBOL_GPL(mhi_unprepare_from_transfer);

+static int mhi_update_transfer_state(struct mhi_device *mhi_dev,
+enum mhi_ch_state_type to_state)
+{
+   struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
+   struct mhi_chan *mhi_chan;
+   int dir, ret;
+
+   for (dir = 0; dir < 2; dir++) {
+   mhi_chan = dir ? mhi_dev->ul_chan : mhi_dev->dl_chan;
+
+   if (!mhi_chan)
+   continue;
+
+   /*
+* Bail out if one of the channels fail as client will reset
+* both upon failure
+*/
+   mutex_lock(_chan->mutex);


Hmm. The documentation about wait_for_completion*() used in
mhi_update_channel_state()says below,

"As all variants of wait_for_completion() can (obviously) block for a 
long
time depending on the nature of the activity they are waiting for, so 
in

most cases you probably don't want to call this with held mutexes."

Yes, that is understood. The mhi_chan->mutex is only used to lock any 
channel
enable/start/stop/disable type operations, since these have to be in 
order, it
is essential that we wait for one of the operations to finish before the 
next

one.

Also we avoid a race, for example, at a time when a device crash forces 
a driver
"remove" call, while an operation to start/stop a channel is already 
going on.

+   ret = mhi_update_channel_state(mhi_cntrl, mhi_chan, to_state);
+   if (ret) {
+   mutex_unlock(_chan->mutex);
+   return ret;
+   }
+   mutex_unlock(_chan->mutex);
+   }
+
+   return 0;
+}
+
+int mhi_stop_transfer(struct mhi_device *mhi_dev)
+{
+   return mhi_update_transfer_state(mhi_dev, MHI_CH_STATE_TYPE_STOP);
+}
+EXPORT_SYMBOL_GPL(mhi_stop_transfer);
+
+int mhi_start_transfer(struct mhi_device *mhi_dev)
+{
+   return mhi_update_transfer_state(mhi_dev, MHI_CH_STATE_TYPE_START);
+}
+EXPORT_SYMBOL_GPL(mhi_start_transfer);
+
 int mhi_poll(struct mhi_device *mhi_dev, u32 budget)
 {
struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
diff --git a/include/linux/mhi.h b/include/linux/mhi.h
index 52b3c60..aee8494 100644
--- a/include/linux/mhi.h
+++ b/include/linux/mhi.h
@@ -702,6 +702,25 @@ int mhi_prepare_for_transfer(struct mhi_device 
*mhi_dev);

 void mhi_unprepare_from_transfer(struct mhi_device *mhi_dev);

 /**
+ * mhi_stop_transfer - Pauses ongoing channel activity by issuing the 
STOP
+ * channel command to both UL and DL channels. 
This command
+ * does not reset the channel context and the 
client drivers
+ * can issue mhi_start_transfer to resume 
activity.

+ * @mhi_dev: Device associated with the channels
+ */
+int mhi_stop_transfer(struct mhi_device *mhi_dev);
+
+/**
+ * mhi_start_transfer - Resumes channel activity by issuing the START 
channel
+ *  command to both UL and DL channels. This 
command assumes
+ *  the channel context is already setup and the 
client
+ *  drivers can issue mhi_stop_transfer to pause 
activity if

+ *  required.
+ * @mhi_dev: Device associated with the channels
+ */
+int mhi_start_transfer(struct mhi_device *mhi_dev);
+
+/**


Align the comment header properly.

So I am trying to follow the documentation style for other functions in 
the same

file. Is there any particular format you want me to refer to?

I use all spaces for the lines after the first one to align them just 
like the

rest of them.


Thanks,
Mani


  * mhi_poll - Poll for any available data in DL direction
  * @mhi_dev: Device associated with the channels
  * @budget: # of events to process
--
The Qualcomm Innovation Center, Inc. is a member of the Code 

Re: [PATCH v4] Add power/gpu_frequency tracepoint.

2020-11-16 Thread Peiyong Lin
On Thu, Oct 22, 2020 at 10:34 AM Peiyong Lin  wrote:
>
> Historically there is no common trace event for GPU frequency, in
> downstream Android each different hardware vendor implements their own
> way to expose GPU frequency, for example as a debugfs node.  This patch
> standardize it as a common trace event in upstream linux kernel to help
> the ecosystem have a common implementation across hardware vendors.
> Toolings in the Linux ecosystem will benefit from this especially in the
> downstream Android, where this information is critical to graphics
> developers.
>
> Signed-off-by: Peiyong Lin 
> ---
>
> Changelog since v3:
>  - Correct copyright title.
>
> Changelog since v2:
>  - Add more comments to indicate when the event should be emitted.
>  - Change state to frequency.
>
> Changelog since v1:
>  - Use %u in TP_printk
>
>  drivers/gpu/Makefile|  1 +
>  drivers/gpu/trace/Kconfig   |  3 +++
>  drivers/gpu/trace/Makefile  |  1 +
>  drivers/gpu/trace/trace_gpu_frequency.c | 13 ++
>  include/trace/events/power.h| 33 +
>  5 files changed, 51 insertions(+)
>  create mode 100644 drivers/gpu/trace/trace_gpu_frequency.c
>
> diff --git a/drivers/gpu/Makefile b/drivers/gpu/Makefile
> index 835c88318cec..f289a47eb031 100644
> --- a/drivers/gpu/Makefile
> +++ b/drivers/gpu/Makefile
> @@ -6,3 +6,4 @@ obj-$(CONFIG_TEGRA_HOST1X)  += host1x/
>  obj-y  += drm/ vga/
>  obj-$(CONFIG_IMX_IPUV3_CORE)   += ipu-v3/
>  obj-$(CONFIG_TRACE_GPU_MEM)+= trace/
> +obj-$(CONFIG_TRACE_GPU_FREQUENCY)  += trace/
> diff --git a/drivers/gpu/trace/Kconfig b/drivers/gpu/trace/Kconfig
> index c24e9edd022e..ac4aec8d5845 100644
> --- a/drivers/gpu/trace/Kconfig
> +++ b/drivers/gpu/trace/Kconfig
> @@ -2,3 +2,6 @@
>
>  config TRACE_GPU_MEM
> bool
> +
> +config TRACE_GPU_FREQUENCY
> +   bool
> diff --git a/drivers/gpu/trace/Makefile b/drivers/gpu/trace/Makefile
> index b70fbdc5847f..2b7ae69327d6 100644
> --- a/drivers/gpu/trace/Makefile
> +++ b/drivers/gpu/trace/Makefile
> @@ -1,3 +1,4 @@
>  # SPDX-License-Identifier: GPL-2.0
>
>  obj-$(CONFIG_TRACE_GPU_MEM) += trace_gpu_mem.o
> +obj-$(CONFIG_TRACE_GPU_FREQUENCY) += trace_gpu_frequency.o
> diff --git a/drivers/gpu/trace/trace_gpu_frequency.c 
> b/drivers/gpu/trace/trace_gpu_frequency.c
> new file mode 100644
> index ..668fabd6b77a
> --- /dev/null
> +++ b/drivers/gpu/trace/trace_gpu_frequency.c
> @@ -0,0 +1,13 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * GPU frequency trace points
> + *
> + * Copyright (C) 2020 Google LLC
> + */
> +
> +#include 
> +
> +#define CREATE_TRACE_POINTS
> +#include 
> +
> +EXPORT_TRACEPOINT_SYMBOL(gpu_frequency);
> diff --git a/include/trace/events/power.h b/include/trace/events/power.h
> index af5018aa9517..343825a76953 100644
> --- a/include/trace/events/power.h
> +++ b/include/trace/events/power.h
> @@ -500,6 +500,39 @@ DEFINE_EVENT(dev_pm_qos_request, 
> dev_pm_qos_remove_request,
>
> TP_ARGS(name, type, new_value)
>  );
> +
> +/**
> + * gpu_frequency - Reports the GPU frequency in GPU clock domains.
> + *
> + * This event should be emitted whenever there's a GPU frequency change 
> happens,
> + * or a GPU goes from idle state to active state, or vice versa.
> + *
> + * When the GPU goes from idle state to active state, this event should 
> report
> + * the GPU frequency of the active state. When the GPU goes from active 
> state to
> + * idle state, this event should report a zero frequency value.
> + *
> + * @frequency:  New frequency (in KHz)
> + * @gpu_id: Id for each GPU clock domain
> + */
> +TRACE_EVENT(gpu_frequency,
> +
> +   TP_PROTO(unsigned int frequency, unsigned int gpu_id),
> +
> +   TP_ARGS(frequency, gpu_id),
> +
> +   TP_STRUCT__entry(
> +   __field(unsigned int, frequency)
> +   __field(unsigned int, gpu_id)
> +   ),
> +
> +   TP_fast_assign(
> +   __entry->frequency = frequency;
> +   __entry->gpu_id = gpu_id;
> +   ),
> +
> +   TP_printk("frequency=%u gpu_id=%u",
> +   __entry->frequency, __entry->gpu_id)
> +);
>  #endif /* _TRACE_POWER_H */
>
>  /* This part must be outside protection */
> --
> 2.29.0.rc1.297.gfa9743e501-goog
>

Hi there,

May I ask whether the merge window has passed? If so is it possible to
ask for a review?

Thanks,
Peiyong


Re: Error: invalid switch -me200

2020-11-16 Thread Segher Boessenkool
On Mon, Nov 16, 2020 at 02:27:12PM -0600, Scott Wood wrote:
> On Fri, 2020-11-13 at 18:50 -0600, Segher Boessenkool wrote:
> > All the others work fine (and are needed afaics), it is only -me200 that
> > doesn't exist (in mainline binutils).  Perhaps -me5500 will work for it
> > instead.
> 
> According to Wikipedia e200 is from mpc55xx (for which I don't see any
> platform support having ever been added).  e5500 is completely different (64-
> bit version of e500mc).

Ah yes, confusing processor numbers :-(  That explains, sorry.


Segher


Re: [PATCH 29/42] drm/selftests/test-drm_dp_mst_helper: Place 'struct drm_dp_sideband_msg_req_body' onto the heap

2020-11-16 Thread Lyude Paul
Huh-could have sworn I had reviewed this one already.

Reviewed-by: Lyude Paul 

On Mon, 2020-11-16 at 17:40 +, Lee Jones wrote:
> The stack is too full.
> 
> Fixes the following W=1 kernel build warning(s):
> 
>  drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c: In function
> ‘sideband_msg_req_encode_decode’:
>  drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c:161:1: warning: the
> frame size of 1176 bytes is larger than 1024 bytes [-Wframe-larger-than=]
> 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Lyude Paul 
> Cc: David Francis 
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 
> ---
>  .../drm/selftests/test-drm_dp_mst_helper.c    | 31 ---
>  1 file changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c
> b/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c
> index 1d696ec001cff..e00bdc557f880 100644
> --- a/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c
> +++ b/drivers/gpu/drm/selftests/test-drm_dp_mst_helper.c
> @@ -120,44 +120,53 @@ sideband_msg_req_equal(const struct
> drm_dp_sideband_msg_req_body *in,
>  static bool
>  sideband_msg_req_encode_decode(struct drm_dp_sideband_msg_req_body *in)
>  {
> -   struct drm_dp_sideband_msg_req_body out = {0};
> +   struct drm_dp_sideband_msg_req_body *out;
> struct drm_printer p = drm_err_printer(PREFIX_STR);
> struct drm_dp_sideband_msg_tx txmsg;
> int i, ret;
> +   bool result = true;
> +
> +   out = kzalloc(sizeof(*out), GFP_KERNEL);
> +   if (!out)
> +   return false;
>  
> drm_dp_encode_sideband_req(in, );
> -   ret = drm_dp_decode_sideband_req(, );
> +   ret = drm_dp_decode_sideband_req(, out);
> if (ret < 0) {
> drm_printf(, "Failed to decode sideband request: %d\n",
>    ret);
> -   return false;
> +   result = false;
> +   goto out;
> }
>  
> -   if (!sideband_msg_req_equal(in, )) {
> +   if (!sideband_msg_req_equal(in, out)) {
> drm_printf(, "Encode/decode failed, expected:\n");
> drm_dp_dump_sideband_msg_req_body(in, 1, );
> drm_printf(, "Got:\n");
> -   drm_dp_dump_sideband_msg_req_body(, 1, );
> -   return false;
> +   drm_dp_dump_sideband_msg_req_body(out, 1, );
> +   result = false;
> +   goto out;
> }
>  
> switch (in->req_type) {
> case DP_REMOTE_DPCD_WRITE:
> -   kfree(out.u.dpcd_write.bytes);
> +   kfree(out->u.dpcd_write.bytes);
> break;
> case DP_REMOTE_I2C_READ:
> -   for (i = 0; i < out.u.i2c_read.num_transactions; i++)
> -   kfree(out.u.i2c_read.transactions[i].bytes);
> +   for (i = 0; i < out->u.i2c_read.num_transactions; i++)
> +   kfree(out->u.i2c_read.transactions[i].bytes);
> break;
> case DP_REMOTE_I2C_WRITE:
> -   kfree(out.u.i2c_write.bytes);
> +   kfree(out->u.i2c_write.bytes);
> break;
> }
>  
> /* Clear everything but the req_type for the input */
> memset(>u, 0, sizeof(in->u));
>  
> -   return true;
> +out:
> +   kfree(out);
> +   return result;
>  }
>  
>  int igt_dp_mst_sideband_msg_req_decode(void *unused)

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat



Re: [PATCH 01/42] drm/amd/amdgpu/atombios_encoders: Remove set but unused variable 'backlight_level'

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:41 PM Lee Jones  wrote:
>
> Also removing the call to 
> amdgpu_atombios_encoder_get_backlight_level_from_reg()
> since, according to Alex Deucher, "We call it again below indirectly".
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/amd/amdgpu/atombios_encoders.c: In function 
> ‘amdgpu_atombios_encoder_init_backlight’:
>  drivers/gpu/drm/amd/amdgpu/atombios_encoders.c:174:5: warning: variable 
> ‘backlight_level’ set but not used [-Wunused-but-set-variable]
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Luben Tuikov 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/amd/amdgpu/atombios_encoders.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c 
> b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
> index fa817ebff9804..6134ed9640279 100644
> --- a/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
> +++ b/drivers/gpu/drm/amd/amdgpu/atombios_encoders.c
> @@ -171,7 +171,6 @@ void amdgpu_atombios_encoder_init_backlight(struct 
> amdgpu_encoder *amdgpu_encode
> struct backlight_properties props;
> struct amdgpu_backlight_privdata *pdata;
> struct amdgpu_encoder_atom_dig *dig;
> -   u8 backlight_level;
> char bl_name[16];
>
> /* Mac laptops with multiple GPUs use the gmux driver for backlight
> @@ -207,8 +206,6 @@ void amdgpu_atombios_encoder_init_backlight(struct 
> amdgpu_encoder *amdgpu_encode
>
> pdata->encoder = amdgpu_encoder;
>
> -   backlight_level = 
> amdgpu_atombios_encoder_get_backlight_level_from_reg(adev);
> -
> dig = amdgpu_encoder->enc_priv;
> dig->bl_dev = bd;
>
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 43/43] drm/radeon/radeon_drv: Move 'radeon_gem_prime_import_sg_table()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/radeon_prime.c:43:24: warning: no previous prototype 
> for ‘radeon_gem_prime_import_sg_table’ [-Wmissing-prototypes]
>  43 | struct drm_gem_object *radeon_gem_prime_import_sg_table(struct 
> drm_device *dev,
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Gareth Hughes 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/radeon_drv.c   | 4 +---
>  drivers/gpu/drm/radeon/radeon_prime.h | 3 +++
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_drv.c 
> b/drivers/gpu/drm/radeon/radeon_drv.c
> index 211932d73b191..7a0989b397da1 100644
> --- a/drivers/gpu/drm/radeon/radeon_drv.c
> +++ b/drivers/gpu/drm/radeon/radeon_drv.c
> @@ -55,6 +55,7 @@
>  #include "radeon_ttm.h"
>  #include "radeon.h"
>  #include "radeon_device.h"
> +#include "radeon_prime.h"
>
>  /*
>   * KMS wrapper.
> @@ -129,9 +130,6 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
>  int radeon_mode_dumb_create(struct drm_file *file_priv,
> struct drm_device *dev,
> struct drm_mode_create_dumb *args);
> -struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device 
> *dev,
> -   struct 
> dma_buf_attachment *,
> -   struct sg_table *sg);
>
>  /* atpx handler */
>  #if defined(CONFIG_VGA_SWITCHEROO)
> diff --git a/drivers/gpu/drm/radeon/radeon_prime.h 
> b/drivers/gpu/drm/radeon/radeon_prime.h
> index 11b7f80987834..24ddfd4b48a6d 100644
> --- a/drivers/gpu/drm/radeon/radeon_prime.h
> +++ b/drivers/gpu/drm/radeon/radeon_prime.h
> @@ -35,5 +35,8 @@ int radeon_gem_prime_pin(struct drm_gem_object *obj);
>  void radeon_gem_prime_unpin(struct drm_gem_object *obj);
>  void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
>  void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
> +struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device 
> *dev,
> +   struct 
> dma_buf_attachment *,
> +   struct sg_table *sg);
>
>  #endif /* __RADEON_PRIME_H__ */
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] Fix warning for static const char * array in audio_manager_module.c

2020-11-16 Thread Emmanouil Perselis
On 11/15/20 9:17 AM, Greg Kroah-Hartman wrote:
> On Sun, Nov 15, 2020 at 03:53:16PM +0100, Emmanouil Perselis wrote:
>> This patch fixes the warning "static const char * array should
>> probably be static const char * const" in
>> drivers/staging/greybus/audio_manager_module.c

>> I think Greg's patch bot is telling you that you need
>> to carbon-copy the mailing list on your patch submission,
>> not just address it to the maintainers.

Added addresses to carbon copy.

>>  -Alex

>>
>> Signed-off-by: Emmanouil Perselis 
>> ---
>>   drivers/staging/greybus/audio_manager_module.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/greybus/audio_manager_module.c 
>> b/drivers/staging/greybus/audio_manager_module.c
>> index 2bfd804183c4..6ef7381f4e85 100644
>> --- a/drivers/staging/greybus/audio_manager_module.c
>> +++ b/drivers/staging/greybus/audio_manager_module.c
>> @@ -158,7 +158,7 @@ static void send_add_uevent(struct 
>> gb_audio_manager_module *module)
>>  char ip_devices_string[64];
>>  char op_devices_string[64];
>>   
>> -char *envp[] = {
>> +static const char * const envp[] = {
>>  name_string,
>>  vid_string,
>>  pid_string,
>> -- 
>> 2.20.1
>>
> 
> Hi,
> 
> This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
> a patch that has triggered this response.  He used to manually respond
> to these common problems, but in order to save his sanity (he kept
> writing the same thing over and over, yet to different people), I was
> created.  Hopefully you will not take offence and will fix the problem
> in your patch and resubmit it so that it can be accepted into the Linux
> kernel tree.
> 
> You are receiving this message because of the following common error(s)
> as indicated below:
> 
> - Your patch was sent privately to Greg.  Kernel development is done in
>public, please always cc: a public mailing list with a patch
>submission.  Using the tool, scripts/get_maintainer.pl on the patch
>will tell you what mailing list to cc.
> 
> - You did not specify a description of why the patch is needed, or
>possibly, any description at all, in the email body.  Please read the
>section entitled "The canonical patch format" in the kernel file,
>Documentation/SubmittingPatches for what is needed in order to
>properly describe the change.
> 
> - You did not write a descriptive Subject: for the patch, allowing Greg,
>and everyone else, to know what this patch is all about.  Please read
>the section entitled "The canonical patch format" in the kernel file,
>Documentation/SubmittingPatches for what a proper Subject: line should
>look like.
> 
> If you wish to discuss this problem further, or you have questions about
> how to resolve this issue, please feel free to respond to this email and
> Greg will reply once he has dug out from the pending patches received
> from other developers.
> 
> thanks,
> 
> greg k-h's patch email bot
> 


Signed-off-by: Emmanouil Perselis 
---
 drivers/staging/greybus/audio_manager_module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/audio_manager_module.c 
b/drivers/staging/greybus/audio_manager_module.c
index 2bfd804183c4..6ef7381f4e85 100644
--- a/drivers/staging/greybus/audio_manager_module.c
+++ b/drivers/staging/greybus/audio_manager_module.c
@@ -158,7 +158,7 @@ static void send_add_uevent(struct gb_audio_manager_module 
*module)
char ip_devices_string[64];
char op_devices_string[64];
 
-   char *envp[] = {
+   static const char * const envp[] = {
name_string,
vid_string,
pid_string,
-- 
2.20.1



Re: [PATCH 42/43] drm/radeon/radeon_audio: Move 'r600_*' prototypes into shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/r600_hdmi.c:177:6: warning: no previous prototype for 
> ‘r600_hdmi_update_acr’ [-Wmissing-prototypes]
>  177 | void r600_hdmi_update_acr(struct drm_encoder *encoder, long offset,
>  | ^~~~
>  drivers/gpu/drm/radeon/r600_hdmi.c:217:6: warning: no previous prototype for 
> ‘r600_set_avi_packet’ [-Wmissing-prototypes]
>  217 | void r600_set_avi_packet(struct radeon_device *rdev, u32 offset,
>  | ^~~
>  drivers/gpu/drm/radeon/r600_hdmi.c:314:6: warning: no previous prototype for 
> ‘r600_hdmi_audio_set_dto’ [-Wmissing-prototypes]
>  314 | void r600_hdmi_audio_set_dto(struct radeon_device *rdev,
>  | ^~~
>  drivers/gpu/drm/radeon/r600_hdmi.c:340:6: warning: no previous prototype for 
> ‘r600_set_vbi_packet’ [-Wmissing-prototypes]
>  340 | void r600_set_vbi_packet(struct drm_encoder *encoder, u32 offset)
>  | ^~~
>  drivers/gpu/drm/radeon/r600_hdmi.c:351:6: warning: no previous prototype for 
> ‘r600_set_audio_packet’ [-Wmissing-prototypes]
>  351 | void r600_set_audio_packet(struct drm_encoder *encoder, u32 offset)
>  | ^
>  drivers/gpu/drm/radeon/r600_hdmi.c:393:6: warning: no previous prototype for 
> ‘r600_set_mute’ [-Wmissing-prototypes]
>  393 | void r600_set_mute(struct drm_encoder *encoder, u32 offset, bool mute)
>  | ^
>  drivers/gpu/drm/radeon/r600_hdmi.c:469:6: warning: no previous prototype for 
> ‘r600_hdmi_enable’ [-Wmissing-prototypes]
>  469 | void r600_hdmi_enable(struct drm_encoder *encoder, bool enable)
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/r600.h | 17 +
>  drivers/gpu/drm/radeon/r600_hdmi.c|  1 +
>  drivers/gpu/drm/radeon/radeon_audio.c | 13 +
>  3 files changed, 19 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/r600.h b/drivers/gpu/drm/radeon/r600.h
> index dbdff4568516b..22db13b256195 100644
> --- a/drivers/gpu/drm/radeon/r600.h
> +++ b/drivers/gpu/drm/radeon/r600.h
> @@ -30,12 +30,29 @@
>
>  struct radeon_bo_list;
>  struct radeon_cs_parser;
> +struct r600_audio_pin;
> +struct radeon_crtc;
>  struct radeon_device;
> +struct radeon_hdmi_acr;
>
>  u32 r600_gpu_check_soft_reset(struct radeon_device *rdev);
>  int r600_ih_ring_alloc(struct radeon_device *rdev);
>  void r600_ih_ring_fini(struct radeon_device *rdev);
>
> +void r600_audio_enable(struct radeon_device *rdev, struct r600_audio_pin 
> *pin,
> +  u8 enable_mask);
> +void r600_set_audio_packet(struct drm_encoder *encoder, u32 offset);
> +void r600_set_mute(struct drm_encoder *encoder, u32 offset, bool mute);
> +void r600_hdmi_audio_set_dto(struct radeon_device *rdev,
> +struct radeon_crtc *crtc, unsigned int clock);
> +void r600_set_avi_packet(struct radeon_device *rdev, u32 offset,
> +unsigned char *buffer, size_t size);
> +void r600_hdmi_update_acr(struct drm_encoder *encoder, long offset,
> + const struct radeon_hdmi_acr *acr);
> +void r600_set_vbi_packet(struct drm_encoder *encoder, u32 offset);
> +void r600_hdmi_enable(struct drm_encoder *encoder, bool enable);
> +
>  int r600_dma_cs_next_reloc(struct radeon_cs_parser *p,
>struct radeon_bo_list **cs_reloc);
> +
>  #endif /* __R600_H__ */
> diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c 
> b/drivers/gpu/drm/radeon/r600_hdmi.c
> index c09549d785b54..f3551ebaa2f08 100644
> --- a/drivers/gpu/drm/radeon/r600_hdmi.c
> +++ b/drivers/gpu/drm/radeon/r600_hdmi.c
> @@ -30,6 +30,7 @@
>  #include "radeon.h"
>  #include "radeon_asic.h"
>  #include "radeon_audio.h"
> +#include "r600.h"
>  #include "r600d.h"
>  #include "atom.h"
>
> diff --git a/drivers/gpu/drm/radeon/radeon_audio.c 
> b/drivers/gpu/drm/radeon/radeon_audio.c
> index 785c23cb30589..7c5e80d03fc90 100644
> --- a/drivers/gpu/drm/radeon/radeon_audio.c
> +++ b/drivers/gpu/drm/radeon/radeon_audio.c
> @@ -29,28 +29,17 @@
>  #include "evergreen_hdmi.h"
>  #include "radeon.h"
>  #include "atom.h"
> +#include "r600.h"
>  #include "radeon_audio.h"
>
> -void r600_audio_enable(struct radeon_device *rdev, struct r600_audio_pin 
> *pin,
> -   u8 enable_mask);
>  void dce6_audio_enable(struct radeon_device *rdev, struct r600_audio_pin 
> *pin,
> u8 enable_mask);
>  struct r600_audio_pin* r600_audio_get_pin(struct radeon_device *rdev);
>  struct r600_audio_pin* dce6_audio_get_pin(struct radeon_device *rdev);
> -void r600_hdmi_audio_set_dto(struct radeon_device *rdev,
> -   struct radeon_crtc *crtc, unsigned int clock);
> -void 

Re: [PATCH 41/43] drm/radeon/evergreen_cs: Move 'r600_dma_cs_next_reloc()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/r600_cs.c:2343:5: warning: no previous prototype for 
> ‘r600_dma_cs_next_reloc’ [-Wmissing-prototypes]
>  2343 | int r600_dma_cs_next_reloc(struct radeon_cs_parser *p,
>  | ^~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/evergreen_cs.c | 3 +--
>  drivers/gpu/drm/radeon/r600.h | 4 
>  drivers/gpu/drm/radeon/r600_cs.c  | 1 +
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/evergreen_cs.c 
> b/drivers/gpu/drm/radeon/evergreen_cs.c
> index 53b75cf201958..0de79f3a7e3ff 100644
> --- a/drivers/gpu/drm/radeon/evergreen_cs.c
> +++ b/drivers/gpu/drm/radeon/evergreen_cs.c
> @@ -28,6 +28,7 @@
>
>  #include "radeon.h"
>  #include "radeon_asic.h"
> +#include "r600.h"
>  #include "evergreend.h"
>  #include "evergreen_reg_safe.h"
>  #include "cayman_reg_safe.h"
> @@ -37,8 +38,6 @@
>
>  #define REG_SAFE_BM_SIZE ARRAY_SIZE(evergreen_reg_safe_bm)
>
> -int r600_dma_cs_next_reloc(struct radeon_cs_parser *p,
> -  struct radeon_bo_list **cs_reloc);
>  struct evergreen_cs_track {
> u32 group_size;
> u32 nbanks;
> diff --git a/drivers/gpu/drm/radeon/r600.h b/drivers/gpu/drm/radeon/r600.h
> index e66ef58706cd8..dbdff4568516b 100644
> --- a/drivers/gpu/drm/radeon/r600.h
> +++ b/drivers/gpu/drm/radeon/r600.h
> @@ -28,10 +28,14 @@
>  #ifndef __R600_H__
>  #define __R600_H__
>
> +struct radeon_bo_list;
> +struct radeon_cs_parser;
>  struct radeon_device;
>
>  u32 r600_gpu_check_soft_reset(struct radeon_device *rdev);
>  int r600_ih_ring_alloc(struct radeon_device *rdev);
>  void r600_ih_ring_fini(struct radeon_device *rdev);
>
> +int r600_dma_cs_next_reloc(struct radeon_cs_parser *p,
> +  struct radeon_bo_list **cs_reloc);
>  #endif /* __R600_H__ */
> diff --git a/drivers/gpu/drm/radeon/r600_cs.c 
> b/drivers/gpu/drm/radeon/r600_cs.c
> index f20b619466816..dc68e538d5a97 100644
> --- a/drivers/gpu/drm/radeon/r600_cs.c
> +++ b/drivers/gpu/drm/radeon/r600_cs.c
> @@ -29,6 +29,7 @@
>
>  #include "radeon.h"
>  #include "radeon_asic.h"
> +#include "r600.h"
>  #include "r600d.h"
>  #include "r600_reg_safe.h"
>
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 14/24] kvm: arm64: Forward safe PSCI SMCs coming from host

2020-11-16 Thread David Brazdil
Forward the following PSCI SMCs issued by host to EL3 as they do not
require the hypervisor's intervention. This assumes that EL3 correctly
implements the PSCI specification.

Only function IDs implemented in Linux are included.

Where both 32-bit and 64-bit variants exist, it is assumed that the host
will always use the 64-bit variant.

 * SMCs that only return information about the system
   * PSCI_VERSION- PSCI version implemented by EL3
   * PSCI_FEATURES   - optional features supported by EL3
   * AFFINITY_INFO   - power state of core/cluster
   * MIGRATE_INFO_TYPE   - whether Trusted OS can be migrated
   * MIGRATE_INFO_UP_CPU - resident core of Trusted OS
 * operations which do not affect the hypervisor
   * MIGRATE - migrate Trusted OS to a different core
   * SET_SUSPEND_MODE- toggle OS-initiated mode
 * system shutdown/reset
   * SYSTEM_OFF
   * SYSTEM_RESET
   * SYSTEM_RESET2

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/psci-relay.c | 43 +++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c 
b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
index 1583b63322c4..7542de8bd679 100644
--- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c
+++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
@@ -55,14 +55,51 @@ static bool is_psci_call(u64 func_id)
}
 }
 
+static unsigned long psci_call(unsigned long fn, unsigned long arg0,
+  unsigned long arg1, unsigned long arg2)
+{
+   struct arm_smccc_res res;
+
+   arm_smccc_1_1_smc(fn, arg0, arg1, arg2, );
+   return res.a0;
+}
+
+static unsigned long psci_forward(struct kvm_cpu_context *host_ctxt)
+{
+   return psci_call(host_ctxt->regs.regs[0], host_ctxt->regs.regs[1],
+host_ctxt->regs.regs[2], host_ctxt->regs.regs[3]);
+}
+
+static __noreturn unsigned long psci_forward_noreturn(struct kvm_cpu_context 
*host_ctxt)
+{
+   psci_forward(host_ctxt);
+   hyp_panic(); /* unreachable */
+}
+
 static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context 
*host_ctxt)
 {
-   return PSCI_RET_NOT_SUPPORTED;
+   if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF])
+   return psci_forward(host_ctxt);
+   else if (func_id == kvm_host_psci_function_id[PSCI_FN_MIGRATE])
+   return psci_forward(host_ctxt);
+   else
+   return PSCI_RET_NOT_SUPPORTED;
 }
 
 static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context 
*host_ctxt)
 {
switch (func_id) {
+   case PSCI_0_2_FN_PSCI_VERSION:
+   case PSCI_0_2_FN_CPU_OFF:
+   case PSCI_0_2_FN64_AFFINITY_INFO:
+   case PSCI_0_2_FN64_MIGRATE:
+   case PSCI_0_2_FN_MIGRATE_INFO_TYPE:
+   case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU:
+   return psci_forward(host_ctxt);
+   case PSCI_0_2_FN_SYSTEM_OFF:
+   case PSCI_0_2_FN_SYSTEM_RESET:
+   psci_forward_noreturn(host_ctxt);
+   unreachable();
default:
return PSCI_RET_NOT_SUPPORTED;
}
@@ -71,6 +108,10 @@ static unsigned long psci_0_2_handler(u64 func_id, struct 
kvm_cpu_context *host_
 static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context 
*host_ctxt)
 {
switch (func_id) {
+   case PSCI_1_0_FN_PSCI_FEATURES:
+   case PSCI_1_0_FN_SET_SUSPEND_MODE:
+   case PSCI_1_1_FN64_SYSTEM_RESET2:
+   return psci_forward(host_ctxt);
default:
return psci_0_2_handler(func_id, host_ctxt);
}
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 07/24] kvm: arm64: Refactor handle_trap to use a switch

2020-11-16 Thread David Brazdil
Small refactor so that nVHE's handle_trap uses a switch on the Exception
Class value of ESR_EL2 in preparation for adding a handler of SMC32/64.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c 
b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 411b0f652417..19332c20fcde 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -16,9 +16,9 @@
 
 DEFINE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
 
-static void handle_host_hcall(unsigned long func_id,
- struct kvm_cpu_context *host_ctxt)
+static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 {
+   unsigned long func_id = host_ctxt->regs.regs[0];
unsigned long ret = 0;
 
switch (func_id) {
@@ -109,11 +109,12 @@ static void handle_host_hcall(unsigned long func_id,
 void handle_trap(struct kvm_cpu_context *host_ctxt)
 {
u64 esr = read_sysreg_el2(SYS_ESR);
-   unsigned long func_id;
 
-   if (ESR_ELx_EC(esr) != ESR_ELx_EC_HVC64)
+   switch (ESR_ELx_EC(esr)) {
+   case ESR_ELx_EC_HVC64:
+   handle_host_hcall(host_ctxt);
+   break;
+   default:
hyp_panic();
-
-   func_id = host_ctxt->regs.regs[0];
-   handle_host_hcall(func_id, host_ctxt);
+   }
 }
-- 
2.29.2.299.gdc1121823c-goog



Re: [PATCH] bpf: don't fail kmalloc while releasing raw_tp

2020-11-16 Thread Steven Rostedt
On Mon, 16 Nov 2020 15:37:27 -0500 (EST)
Mathieu Desnoyers  wrote:
> > 
> > Mathieu,
> > 
> > Can't we do something that would still allow to unregister a probe even if
> > a new probe array fails to allocate? We could kick off a irq work to try to
> > clean up the probe at a later time, but still, the unregister itself should
> > not fail due to memory failure.  
> 
> Currently, the fast path iteration looks like:
> 
> struct tracepoint_func *it_func_ptr;
> void *it_func;
> 
> it_func_ptr =   \
> rcu_dereference_raw((&__tracepoint_##_name)->funcs); \
> do {\
> it_func = (it_func_ptr)->func;  \
> __data = (it_func_ptr)->data;   \
> ((void(*)(void *, proto))(it_func))(__data, args); \
> } while ((++it_func_ptr)->func); 
> 
> So we RCU dereference the array, and iterate on the array until we find a NULL
> func. So you could not use NULL to skip items, but you could perhaps reserve
> a (void *)0x1UL tombstone for this.

Actually, you could just set it to a stub callback that does nothing. then
you don't even need to touch the above macro. Not sure why I didn't
recommend this to begin with, because that's exactly what the function
tracer does with ftrace_stub.


> 
> It should ideally be an unlikely branch, and it would be good to benchmark the
> change when multiple tracing probes are attached to figure out whether the
> overhead is significant when tracing is enabled.

If you use a stub function, it shouldn't affect anything. And the worse
that would happen is that you have a slight overhead of calling the stub
until you can properly remove the callback.

> 
> I wonder whether we really mind that much about using slightly more memory
> than required after a failed reallocation due to ENOMEM. Perhaps the irq work
> is not even needed. Chances are that the irq work would fail again and again 
> if
> it's in low memory conditions. So maybe it's better to just keep the tombstone
> in place until the next successful callback array reallocation.
> 

True. If we just replace the function with a stub on memory failure (always
using __GFP_NOFAIL, and if it fails to reallocate a new array, just replace
the callback with the stub and be done with it. It may require some more
accounting to make sure the tracepoint.c code can handle these stubs, and
remove them on new additions to the code. Heck, if a stub exists, you could
just swap it with a new item. But on any new changes to the list, the stubs
should be purged.


-- Steve


Re: [PATCH 40/43] drm/radeon/cik: Move 'vce_v2_0_enable_mgcg()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/vce_v2_0.c:111:6: warning: no previous prototype for 
> ‘vce_v2_0_enable_mgcg’ [-Wmissing-prototypes]
>  111 | void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable)
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Sumit Semwal 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Cc: linux-me...@vger.kernel.org
> Cc: linaro-mm-...@lists.linaro.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/cik.c  | 2 +-
>  drivers/gpu/drm/radeon/vce.h  | 1 +
>  drivers/gpu/drm/radeon/vce_v2_0.c | 1 +
>  3 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
> index 2af76463906ad..8b7a4f7b75766 100644
> --- a/drivers/gpu/drm/radeon/cik.c
> +++ b/drivers/gpu/drm/radeon/cik.c
> @@ -41,6 +41,7 @@
>  #include "radeon_audio.h"
>  #include "radeon_ucode.h"
>  #include "si.h"
> +#include "vce.h"
>
>  #define SH_MEM_CONFIG_GFX_DEFAULT \
> ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED)
> @@ -129,7 +130,6 @@ MODULE_FIRMWARE("radeon/mullins_rlc.bin");
>  MODULE_FIRMWARE("radeon/mullins_sdma.bin");
>
>  static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 
> sh);
> -extern void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable);
>  static void cik_rlc_stop(struct radeon_device *rdev);
>  static void cik_pcie_gen3_enable(struct radeon_device *rdev);
>  static void cik_program_aspm(struct radeon_device *rdev);
> diff --git a/drivers/gpu/drm/radeon/vce.h b/drivers/gpu/drm/radeon/vce.h
> index 1eb4f5715202e..ccc9c00f0d02c 100644
> --- a/drivers/gpu/drm/radeon/vce.h
> +++ b/drivers/gpu/drm/radeon/vce.h
> @@ -30,5 +30,6 @@
>  struct radeon_device;
>
>  void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
> +void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable);
>
>  #endif /* __VCE_H__ */
> diff --git a/drivers/gpu/drm/radeon/vce_v2_0.c 
> b/drivers/gpu/drm/radeon/vce_v2_0.c
> index d6fde3659e65f..163c9bfc03da8 100644
> --- a/drivers/gpu/drm/radeon/vce_v2_0.c
> +++ b/drivers/gpu/drm/radeon/vce_v2_0.c
> @@ -30,6 +30,7 @@
>  #include "radeon.h"
>  #include "radeon_asic.h"
>  #include "cikd.h"
> +#include "vce.h"
>
>  #define VCE_V2_0_FW_SIZE   (256 * 1024)
>  #define VCE_V2_0_STACK_SIZE(64 * 1024)
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] mfd: cpcap: Fix interrupt regression with regmap clear_ack

2020-11-16 Thread Tim Harvey
On Sun, Nov 15, 2020 at 12:43 AM Tony Lindgren  wrote:
>
> * Tim Harvey  [201113 22:07]:
> > 3a6f0fb7b8eb ("regmap: irq: Add support to clear ack registers")
> > appears to not only add the new clear_ack case it also attempts to
> > resolve the long standing ack_invert issue with this change:
> >
> > - ret = regmap_write(map, reg, data->status_buf[i]);
> > + if (chip->ack_invert)
> > +  ret = regmap_write(map, reg,
> > +  ~data->status_buf[i]);
> > + else
> > + ret = regmap_write(map, reg,
> > + data->status_buf[i]);
>
> Yes that's what I noticed too. And that's why cpcap was working for
> me with ack_invert and without it earlier.
>
> > However, this still doesn't resolve the issue I have with my
> > device/driver because it ends up writing 1's to all the other bits in
> > the ack register which keeps my device's interrupt from de-asserting.
> > Perhaps that's a strange behavior of my device that it allows you to
> > 'set' interrupt source bits which causes the interrupt to stay
> > asserted? I'm also wondering if my issue is that I currently have the
> > interrupt registered as such:
> >
> > ret = devm_regmap_add_irq_chip(dev, gsc->regmap, client->irq,
> > IRQF_ONESHOT | IRQF_SHARED | IRQF_TRIGGER_FALLING, 0, _irq_chip,
> > _data);
> >
> > Perhaps this should be IRQF_TRIGGER_LOW as the device will not
> > de-assert its IRQ# until all source bits are cleared.
>
> Yes could be. For cpcap, we have IRQ_TYPE_LEVEL_HIGH configured in the
> motorola-cpcap-mapphone.dtsi file.
>
> > Tony, I thought that your pcap issue was that it truly did not have an
> > inverted ack and the fact that ack_invert did not work was why you
> > never noticed any issue. If this is true I would think you would want
> > to disable ack_invert but not necessarily enable clear_ack. Did your
> > testing show it needed to toggle the ack to clear it?
>
> Well I looked at the v3.0.8 Motorola Linux Android kernel, it actually
> does clear_ack. So I'd rather keep the same logic as we have no proper
> documentation for cpcap. I also confirmed still works without ack_invert
> too while ack_invert now is broken. But using clear_ack now that we
> have it working seems safer.
>
> Regards,
>
> Tony

Tony,

Ok - sounds like the right thing for your device.

Reviewed-By: Tim Harvey 

Tim


Re: [PATCH] [v7] wireless: Initial driver submission for pureLiFi STA devices

2020-11-16 Thread Joe Perches
On Mon, 2020-11-16 at 14:52 +0530, Srinivasan Raju wrote:
> This introduces the pureLiFi LiFi driver for LiFi-X, LiFi-XC
> and LiFi-XL USB devices.
> 
> This driver implementation has been based on the zd1211rw driver.
> 
> Driver is based on 802.11 softMAC Architecture and uses
> native 802.11 for configuration and management.
> 
> The driver is compiled and tested in ARM, x86 architectures and
> compiled in powerpc architecture.
> 
> Signed-off-by: Srinivasan Raju 

trivial notes and some style and content defects:
(I stopped reading after awhile)

Commonly this changelog would go below the --- separator line.

> 
> Changes v6->v7:
> - Magic numbers removed and used IEEE80211 macors
> - usb.c is split into two files firmware.c and dbgfs.c
> - Other code style and timer function fixes (mod_timer)
> Changes v5->v6:
> - Code style fix patch from Joe Perches
> Changes v4->v5:
> - Code refactoring for clarity and redundnacy removal
> - Fix warnings from kernel test robot
> Changes v3->v4:
> - Code refactoring based on kernel code guidelines
> - Remove multi level macors and use kernel debug macros
> Changes v2->v3:
> - Code style fixes kconfig fix
> Changes v1->v2:
> - v1 was submitted to staging, v2 submitted to wireless-next
> - Code style fixes and copyright statement fix
> ---
>  MAINTAINERS  |5 +

[]

> diff --git a/MAINTAINERS b/MAINTAINERS
[]
> @@ -14108,6 +14108,11 @@ T:   git git://linuxtv.org/media_tree.git
[]
> +PUREILIFI USB DRIVER
> +M:   Srinivasan Raju 
> +S:   Maintained

If you are employed there and are paid to maintain this code the
more common S: marking is "Supported"

> diff --git a/drivers/net/wireless/purelifi/Kconfig 
> b/drivers/net/wireless/purelifi/Kconfig
[]
> +++ b/drivers/net/wireless/purelifi/Kconfig
> @@ -0,0 +1,27 @@
> +# SPDX-License-Identifier: GPL-2.0

For clarity, I think it'd be nicer to use GPL-2.0-only here and elsewhere.

> diff --git a/drivers/net/wireless/purelifi/chip.c 
> b/drivers/net/wireless/purelifi/chip.c
[]
> +int purelifi_set_beacon_interval(struct purelifi_chip *chip, u16 interval,
> +  u8 dtim_period, int type)
> +{
> + if (!interval || (chip->beacon_set &&
> +   chip->beacon_interval == interval)) {
> + return 0;
> + }

It's ddd that checkpatch isn't complaining about single statement uses
with braces.  I would write this like the below, but there isn't really
anything wrong with what you did either.

if (!interval ||
(chip->beacon_set && chip->beacon_interval == interval))
return 0;

> +void purelifi_chip_disable_rxtx(struct purelifi_chip *chip)
> +{
> + u8 value;
> +
> + value = 0;

why not make this:

static const u8 value = 0;

> + usb_write_req((const u8 *), sizeof(value), USB_REQ_RXTX_WR);

so this is doesn't need a cast

usb_write_req(, sizeof(value), USB_REQ_RXTX_WR);

> +int purelifi_chip_set_rate(struct purelifi_chip *chip, u8 rate)
> +{
> + int r;
> +
> + if (!chip)
> + return -EINVAL;
> +
> + r = usb_write_req((const u8 *), sizeof(rate), USB_REQ_RATE_WR);

why is the cast needed here?

> +static inline void purelifi_mc_add_addr(struct purelifi_mc_hash *hash,
> + u8 *addr
> + )

Odd close parenthesis location

> diff --git a/drivers/net/wireless/purelifi/dbgfs.c 
> b/drivers/net/wireless/purelifi/dbgfs.c
[]
> +ssize_t purelifi_store_frequency(struct device *dev,
> +  struct device_attribute *attr,
> +  const char *buf,
> +  size_t len)
> +{
[]
> + if (valid) {
> + usr_input[0] = (char)predivider;
> + usr_input[1] = (char)feedback_divider;
> + usr_input[2] = (char)output_div_0;
> + usr_input[3] = (char)output_div_1;
> + usr_input[4] = (char)output_div_2;
> + usr_input[5] = (char)clkout3_phase;
> +
> + dev_err(dev, "options IP_DIV: %d VCO_MULT: %d OP_DIV_PHY: %d",
> + usr_input[0], usr_input[1], usr_input[2]);
> + dev_err(dev, "OP_DIV_CPU: %d OP_DIV_USB: %d CLK3_PH: %d\n",
> + usr_input[3], usr_input[4], usr_input[5]);

why is this dev_err?  It's not an error.
Shouldn't this be dev_notice or dev_info?

> +ssize_t purelifi_show_sysfs(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + return 0;
> +}

This doesn't seem useful.

> +ssize_t purelifi_show_modulation(struct device *dev,
> +  struct device_attribute *attr,
> +  char *buf)
> +{
> + return 0;
> +}

This either.

> diff --git a/drivers/net/wireless/purelifi/firmware.c 
> b/drivers/net/wireless/purelifi/firmware.c
[]
> +int download_fpga(struct usb_interface *intf)
> +{
[]
> +  

[PATCH v2 16/24] kvm: arm64: Extract __do_hyp_init into a helper function

2020-11-16 Thread David Brazdil
In preparation for adding a CPU entry point in nVHE hyp code, extract
most of __do_hyp_init hypervisor initialization code into a common
helper function. This will be invoked by the entry point to install KVM
on the newly booted CPU.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/hyp-init.S | 39 +-
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S 
b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
index 67342cc9930f..d4a71ac34254 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
@@ -68,16 +68,35 @@ __do_hyp_init:
mov x0, #SMCCC_RET_NOT_SUPPORTED
eret
 
-1: ldr x0, [x1, #NVHE_INIT_TPIDR_EL2]
-   msr tpidr_el2, x0
+1: mov x0, x1
+   mov x4, lr
+   bl  ___kvm_hyp_init
+   mov lr, x4
 
-   ldr x0, [x1, #NVHE_INIT_VECTOR_HYP_VA]
-   msr vbar_el2, x0
+   /* Hello, World! */
+   mov x0, #SMCCC_RET_SUCCESS
+   eret
+SYM_CODE_END(__kvm_hyp_init)
+
+/*
+ * Initialize the hypervisor in EL2.
+ *
+ * Only uses x0..x3 so as to not clobber callee-saved SMCCC registers
+ * and leave x4 for the caller.
+ *
+ * x0: struct kvm_nvhe_init_params PA
+ */
+SYM_CODE_START(___kvm_hyp_init)
+   ldr x1, [x0, #NVHE_INIT_TPIDR_EL2]
+   msr tpidr_el2, x1
+
+   ldr x1, [x0, #NVHE_INIT_VECTOR_HYP_VA]
+   msr vbar_el2, x1
 
-   ldr x0, [x1, #NVHE_INIT_STACK_HYP_VA]
-   mov sp, x0
+   ldr x1, [x0, #NVHE_INIT_STACK_HYP_VA]
+   mov sp, x1
 
-   ldr x1, [x1, #NVHE_INIT_PGD_PA]
+   ldr x1, [x0, #NVHE_INIT_PGD_PA]
phys_to_ttbr x0, x1
 alternative_if ARM64_HAS_CNP
orr x0, x0, #TTBR_CNP_BIT
@@ -137,10 +156,8 @@ alternative_else_nop_endif
msr sctlr_el2, x0
isb
 
-   /* Hello, World! */
-   mov x0, #SMCCC_RET_SUCCESS
-   eret
-SYM_CODE_END(__kvm_hyp_init)
+   ret
+SYM_CODE_END(___kvm_hyp_init)
 
 SYM_CODE_START(__kvm_handle_stub_hvc)
cmp x0, #HVC_SOFT_RESTART
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 22/24] kvm: arm64: Keep nVHE EL2 vector installed

2020-11-16 Thread David Brazdil
KVM by default keeps the stub vector installed and installs the nVHE
vector only briefly for init and later on demand. Change this policy
to install the vector at init and then never uninstall it if the kernel
was given the protected KVM command line parameter.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/arm.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 49d2474f2a80..45bc7a6b9e0b 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1443,7 +1443,8 @@ static void _kvm_arch_hardware_disable(void *discard)
 
 void kvm_arch_hardware_disable(void)
 {
-   _kvm_arch_hardware_disable(NULL);
+   if (!is_protected_kvm_enabled())
+   _kvm_arch_hardware_disable(NULL);
 }
 
 #ifdef CONFIG_CPU_PM
@@ -1486,11 +1487,13 @@ static struct notifier_block hyp_init_cpu_pm_nb = {
 
 static void __init hyp_cpu_pm_init(void)
 {
-   cpu_pm_register_notifier(_init_cpu_pm_nb);
+   if (!is_protected_kvm_enabled())
+   cpu_pm_register_notifier(_init_cpu_pm_nb);
 }
 static void __init hyp_cpu_pm_exit(void)
 {
-   cpu_pm_unregister_notifier(_init_cpu_pm_nb);
+   if (!is_protected_kvm_enabled())
+   cpu_pm_unregister_notifier(_init_cpu_pm_nb);
 }
 #else
 static inline void hyp_cpu_pm_init(void)
@@ -1575,7 +1578,8 @@ static int init_subsystems(void)
kvm_coproc_table_init();
 
 out:
-   on_each_cpu(_kvm_arch_hardware_disable, NULL, 1);
+   if (err || !is_protected_kvm_enabled())
+   on_each_cpu(_kvm_arch_hardware_disable, NULL, 1);
 
return err;
 }
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 03/24] arm64: Make cpu_logical_map() take unsigned int

2020-11-16 Thread David Brazdil
CPU index should never be negative. Change the signature of
(set_)cpu_logical_map to take an unsigned int.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/smp.h | 4 ++--
 arch/arm64/kernel/setup.c| 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index 2e7f529ec5a6..bcb01ca15325 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -46,9 +46,9 @@ DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
  * Logical CPU mapping.
  */
 extern u64 __cpu_logical_map[NR_CPUS];
-extern u64 cpu_logical_map(int cpu);
+extern u64 cpu_logical_map(unsigned int cpu);
 
-static inline void set_cpu_logical_map(int cpu, u64 hwid)
+static inline void set_cpu_logical_map(unsigned int cpu, u64 hwid)
 {
__cpu_logical_map[cpu] = hwid;
 }
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 133257ffd859..2f2973bc67c7 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -276,7 +276,7 @@ arch_initcall(reserve_memblock_reserved_regions);
 
 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
 
-u64 cpu_logical_map(int cpu)
+u64 cpu_logical_map(unsigned int cpu)
 {
return __cpu_logical_map[cpu];
 }
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 15/24] kvm: arm64: Extract parts of el2_setup into a macro

2020-11-16 Thread David Brazdil
When the a CPU is booted in EL2, the kernel checks for VHE support and
initializes the CPU core accordingly. For nVHE it also installs the stub
vectors and drops down to EL1.

Once KVM gains the ability to boot cores without going through the
kernel entry point, it will need to initialize the CPU the same way.
Extract the relevant bits of el2_setup into an init_el2_state macro
with an argument specifying whether to initialize for VHE or nVHE.

No functional change. Size of el2_setup increased by 148 bytes due
to duplication.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/el2_setup.h | 185 +
 arch/arm64/kernel/head.S   | 144 +++---
 2 files changed, 201 insertions(+), 128 deletions(-)
 create mode 100644 arch/arm64/include/asm/el2_setup.h

diff --git a/arch/arm64/include/asm/el2_setup.h 
b/arch/arm64/include/asm/el2_setup.h
new file mode 100644
index ..e5026e0aa878
--- /dev/null
+++ b/arch/arm64/include/asm/el2_setup.h
@@ -0,0 +1,185 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2012,2013 - ARM Ltd
+ * Author: Marc Zyngier 
+ */
+
+#ifndef __ARM_KVM_INIT_H__
+#define __ARM_KVM_INIT_H__
+
+#ifndef __ASSEMBLY__
+#error Assembly-only header
+#endif
+
+#ifdef CONFIG_ARM_GIC_V3
+#include 
+#endif
+
+#include 
+#include 
+#include 
+
+.macro __init_el2_sctlr
+   mov_q   x0, (SCTLR_EL2_RES1 | ENDIAN_SET_EL2)
+   msr sctlr_el2, x0
+   isb
+.endm
+
+/*
+ * Allow Non-secure EL1 and EL0 to access physical timer and counter.
+ * This is not necessary for VHE, since the host kernel runs in EL2,
+ * and EL0 accesses are configured in the later stage of boot process.
+ * Note that when HCR_EL2.E2H == 1, CNTHCTL_EL2 has the same bit layout
+ * as CNTKCTL_EL1, and CNTKCTL_EL1 accessing instructions are redefined
+ * to access CNTHCTL_EL2. This allows the kernel designed to run at EL1
+ * to transparently mess with the EL0 bits via CNTKCTL_EL1 access in
+ * EL2.
+ */
+.macro __init_el2_timers mode
+.ifeqs "\mode", "nvhe"
+   mrs x0, cnthctl_el2
+   orr x0, x0, #3  // Enable EL1 physical timers
+   msr cnthctl_el2, x0
+.endif
+   msr cntvoff_el2, xzr// Clear virtual offset
+.endm
+
+.macro __init_el2_debug mode
+   mrs x1, id_aa64dfr0_el1
+   sbfxx0, x1, #ID_AA64DFR0_PMUVER_SHIFT, #4
+   cmp x0, #1
+   b.lt1f  // Skip if no PMU present
+   mrs x0, pmcr_el0// Disable debug access traps
+   ubfxx0, x0, #11, #5 // to EL2 and allow access to
+1:
+   cselx2, xzr, x0, lt // all PMU counters from EL1
+
+   /* Statistical profiling */
+   ubfxx0, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4
+   cbz x0, 3f  // Skip if SPE not present
+
+.ifeqs "\mode", "nvhe"
+   mrs_s   x0, SYS_PMBIDR_EL1  // If SPE available at EL2,
+   and x0, x0, #(1 << SYS_PMBIDR_EL1_P_SHIFT)
+   cbnzx0, 2f  // then permit sampling of 
physical
+   mov x0, #(1 << SYS_PMSCR_EL2_PCT_SHIFT | \
+ 1 << SYS_PMSCR_EL2_PA_SHIFT)
+   msr_s   SYS_PMSCR_EL2, x0   // addresses and physical 
counter
+2:
+   mov x0, #(MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT)
+   orr x2, x2, x0  // If we don't have VHE, then
+   // use EL1&0 translation.
+.else
+   orr x2, x2, #MDCR_EL2_TPMS  // For VHE, use EL2 translation
+   // and disable access from EL1
+.endif
+
+3:
+   msr mdcr_el2, x2// Configure debug traps
+.endm
+
+/* LORegions */
+.macro __init_el2_lor
+   mrs x1, id_aa64mmfr1_el1
+   ubfxx0, x1, #ID_AA64MMFR1_LOR_SHIFT, 4
+   cbz x0, 1f
+   msr_s   SYS_LORC_EL1, xzr
+1:
+.endm
+
+/* Stage-2 translation */
+.macro __init_el2_stage2
+   msr vttbr_el2, xzr
+.endm
+
+/* GICv3 system register access */
+#ifdef CONFIG_ARM_GIC_V3
+.macro __init_el2_gicv3
+   mrs x0, id_aa64pfr0_el1
+   ubfxx0, x0, #ID_AA64PFR0_GIC_SHIFT, #4
+   cbz x0, 1f
+
+   mrs_s   x0, SYS_ICC_SRE_EL2
+   orr x0, x0, #ICC_SRE_EL2_SRE// Set ICC_SRE_EL2.SRE==1
+   orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1
+   msr_s   SYS_ICC_SRE_EL2, x0
+   isb // Make sure SRE is now set
+   mrs_s   x0, SYS_ICC_SRE_EL2 // Read SRE back,
+   tbz x0, #0, 1f  // and check that it sticks
+   msr_s   SYS_ICH_HCR_EL2, xzr// Reset ICC_HCR_EL2 to defaults
+1:
+.endm
+#endif
+
+/* Virtual CPU ID registers */
+.macro __init_el2_nvhe_idregs
+   mrs x0, midr_el1
+   mrs x1, mpidr_el1
+   msr 

Re: [PATCH] powerpc: Drop -me200 addition to build flags

2020-11-16 Thread Scott Wood
On Mon, 2020-11-16 at 23:09 +1100, Michael Ellerman wrote:
> Currently a build with CONFIG_E200=y will fail with:
> 
>   Error: invalid switch -me200
>   Error: unrecognized option -me200
> 
> Upstream binutils has never supported an -me200 option. Presumably it
> was supported at some point by either a fork or Freescale internal
> binutils.
> 
> We can't support code that we can't even build test, so drop the
> addition of -me200 to the build flags, so we can at least build with
> CONFIG_E200=y.
> 
> Reported-by: Németh Márton 
> Reported-by: kernel test robot 
> Signed-off-by: Michael Ellerman 
> ---
> 
> More discussion: 
> https://lore.kernel.org/lkml/202011131146.g8dplqdd-...@intel.com
> ---
>  arch/powerpc/Makefile | 1 -
>  1 file changed, 1 deletion(-)

Acked-by: Scott Wood 

I'd go further and remove E200 code entirely, unless someone with the hardware
can claim that it actually works.  There doesn't appear to be any actual
platform support for an e200-based system.  It seems to be a long-abandoned
work in progress.

-Scott




[PATCH v2 24/24] kvm: arm64: Fix EL2 mode availability checks

2020-11-16 Thread David Brazdil
With protected nVHE hyp code interception host's PSCI CPU_ON/SUSPEND
SMCs, the host starts seeing new CPUs boot in EL1 instead of EL2. The
kernel logic that keeps track of the boot mode needs to be adjusted.

Add a static key enabled if KVM protected nVHE initialization is
successful.

When the key is enabled, is_hyp_mode_available continues to report
`true` because its users either treat it as a check whether KVM will be
/ was initialized, or whether stub HVCs can be made (eg. hibernate).

is_hyp_mode_mismatched is changed to report `false` when the key is
enabled. That's because all cores' modes matched at the point of KVM
init and KVM will not allow cores not present at init to boot. That
said, the function is never used after KVM is initialized.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/virt.h | 18 ++
 arch/arm64/kvm/arm.c  | 10 +++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h
index 2fde1186b962..f7cf3f0e5297 100644
--- a/arch/arm64/include/asm/virt.h
+++ b/arch/arm64/include/asm/virt.h
@@ -65,9 +65,19 @@ extern u32 __boot_cpu_mode[2];
 void __hyp_set_vectors(phys_addr_t phys_vector_base);
 void __hyp_reset_vectors(void);
 
+DECLARE_STATIC_KEY_FALSE(kvm_protected_mode_initialized);
+
 /* Reports the availability of HYP mode */
 static inline bool is_hyp_mode_available(void)
 {
+   /*
+* If KVM protected mode is initialized, all CPUs must have been booted
+* in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1.
+*/
+   if (IS_ENABLED(CONFIG_KVM) &&
+   static_branch_likely(_protected_mode_initialized))
+   return true;
+
return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
__boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
 }
@@ -75,6 +85,14 @@ static inline bool is_hyp_mode_available(void)
 /* Check if the bootloader has booted CPUs in different modes */
 static inline bool is_hyp_mode_mismatched(void)
 {
+   /*
+* If KVM protected mode is initialized, all CPUs must have been booted
+* in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1.
+*/
+   if (IS_ENABLED(CONFIG_KVM) &&
+   static_branch_likely(_protected_mode_initialized))
+   return false;
+
return __boot_cpu_mode[0] != __boot_cpu_mode[1];
 }
 
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 45bc7a6b9e0b..b86d0b38f30b 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -47,6 +47,8 @@
 __asm__(".arch_extension   virt");
 #endif
 
+DEFINE_STATIC_KEY_FALSE(kvm_protected_mode_initialized);
+
 DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector);
 
 static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page);
@@ -1837,12 +1839,14 @@ int kvm_arch_init(void *opaque)
if (err)
goto out_hyp;
 
-   if (is_protected_kvm_enabled())
+   if (is_protected_kvm_enabled()) {
+   static_branch_enable(_protected_mode_initialized);
kvm_info("Protected nVHE mode initialized successfully\n");
-   else if (in_hyp_mode)
+   } else if (in_hyp_mode) {
kvm_info("VHE mode initialized successfully\n");
-   else
+   } else {
kvm_info("Hyp mode initialized successfully\n");
+   }
 
return 0;
 
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 04/24] arm64: Move MAIR_EL1_SET to asm/memory.h

2020-11-16 Thread David Brazdil
KVM currently initializes MAIR_EL2 to the value of MAIR_EL1. In
preparation for initializing MAIR_EL2 before MAIR_EL1, move the constant
into a shared header file. Since it is used for EL1 and EL2, rename to
MAIR_ELx_SET.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/memory.h | 29 ++---
 arch/arm64/include/asm/sysreg.h | 30 ++
 arch/arm64/mm/proc.S| 15 +--
 3 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index cd61239bae8c..8ae8fd883a0c 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * Size of the PCI I/O space. This must remain a power of two so that
@@ -124,21 +125,6 @@
  */
 #define SEGMENT_ALIGN  SZ_64K
 
-/*
- * Memory types available.
- *
- * IMPORTANT: MT_NORMAL must be index 0 since vm_get_page_prot() may 'or' in
- *   the MT_NORMAL_TAGGED memory type for PROT_MTE mappings. Note
- *   that protection_map[] only contains MT_NORMAL attributes.
- */
-#define MT_NORMAL  0
-#define MT_NORMAL_TAGGED   1
-#define MT_NORMAL_NC   2
-#define MT_NORMAL_WT   3
-#define MT_DEVICE_nGnRnE   4
-#define MT_DEVICE_nGnRE5
-#define MT_DEVICE_GRE  6
-
 /*
  * Memory types for Stage-2 translation
  */
@@ -152,6 +138,19 @@
 #define MT_S2_FWB_NORMAL   6
 #define MT_S2_FWB_DEVICE_nGnRE 1
 
+/*
+ * Default MAIR_EL1. MT_NORMAL_TAGGED is initially mapped as Normal memory and
+ * changed during __cpu_setup to Normal Tagged if the system supports MTE.
+ */
+#define MAIR_ELx_SET   \
+   (MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRnE, MT_DEVICE_nGnRnE) |  \
+MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRE, MT_DEVICE_nGnRE) |\
+MAIR_ATTRIDX(MAIR_ATTR_DEVICE_GRE, MT_DEVICE_GRE) |\
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL_NC, MT_NORMAL_NC) |  \
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL) |\
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL_WT, MT_NORMAL_WT) |  \
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL_TAGGED))
+
 #ifdef CONFIG_ARM64_4K_PAGES
 #define IOREMAP_MAX_ORDER  (PUD_SHIFT)
 #else
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index e2ef4c2edf06..24e773414cb4 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -635,6 +635,34 @@
 /* Position the attr at the correct index */
 #define MAIR_ATTRIDX(attr, idx)((attr) << ((idx) * 8))
 
+/*
+ * Memory types available.
+ *
+ * IMPORTANT: MT_NORMAL must be index 0 since vm_get_page_prot() may 'or' in
+ *   the MT_NORMAL_TAGGED memory type for PROT_MTE mappings. Note
+ *   that protection_map[] only contains MT_NORMAL attributes.
+ */
+#define MT_NORMAL  0
+#define MT_NORMAL_TAGGED   1
+#define MT_NORMAL_NC   2
+#define MT_NORMAL_WT   3
+#define MT_DEVICE_nGnRnE   4
+#define MT_DEVICE_nGnRE5
+#define MT_DEVICE_GRE  6
+
+/*
+ * Default MAIR_ELx. MT_NORMAL_TAGGED is initially mapped as Normal memory and
+ * changed during __cpu_setup to Normal Tagged if the system supports MTE.
+ */
+#define MAIR_ELx_SET   \
+   (MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRnE, MT_DEVICE_nGnRnE) |  \
+MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRE, MT_DEVICE_nGnRE) |\
+MAIR_ATTRIDX(MAIR_ATTR_DEVICE_GRE, MT_DEVICE_GRE) |\
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL_NC, MT_NORMAL_NC) |  \
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL) |\
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL_WT, MT_NORMAL_WT) |  \
+MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL_TAGGED))
+
 /* id_aa64isar0 */
 #define ID_AA64ISAR0_RNDR_SHIFT60
 #define ID_AA64ISAR0_TLB_SHIFT 56
@@ -992,6 +1020,7 @@
 /* Safe value for MPIDR_EL1: Bit31:RES1, Bit30:U:0, Bit24:MT:0 */
 #define SYS_MPIDR_SAFE_VAL (BIT(31))
 
+#ifndef LINKER_SCRIPT
 #ifdef __ASSEMBLY__
 
.irp
num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
@@ -1109,5 +1138,6 @@
 })
 
 #endif
+#endif /* LINKER_SCRIPT */
 
 #endif /* __ASM_SYSREG_H */
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 23c326a06b2d..e3b9aa372b96 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -45,19 +45,6 @@
 #define TCR_KASAN_FLAGS 0
 #endif
 
-/*
- * Default MAIR_EL1. MT_NORMAL_TAGGED is initially mapped as Normal memory and
- * changed during __cpu_setup to Normal Tagged if the system supports MTE.
- */
-#define MAIR_EL1_SET   \
-   (MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRnE, MT_DEVICE_nGnRnE) |  \
-

[PATCH v2 17/24] kvm: arm64: Add CPU entry point in nVHE hyp

2020-11-16 Thread David Brazdil
When nVHE hyp starts interception host's PSCI CPU_ON SMCs, it will need
to install KVM on the newly booted CPU before returning to the host. Add
an entry point which expects the same kvm_nvhe_init_params struct as the
__kvm_hyp_init HVC in the CPU_ON context argument (x0).

The entry point initializes EL2 state with the same init_el2_state macro
used by the kernel's entry point. It then initializes KVM using the same
helper function used in the __kvm_hyp_init HVC.

When done, the entry point branches to a function provided in the init
params.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/kvm_asm.h   |  1 +
 arch/arm64/kernel/asm-offsets.c|  1 +
 arch/arm64/kvm/hyp/nvhe/hyp-init.S | 32 ++
 3 files changed, 34 insertions(+)

diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index 01904e88cead..109867fb76f6 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -154,6 +154,7 @@ struct kvm_nvhe_init_params {
unsigned long tpidr_el2;
unsigned long vector_hyp_va;
unsigned long stack_hyp_va;
+   unsigned long entry_hyp_va;
phys_addr_t pgd_pa;
 };
 
diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index 4435ad8be938..9752100bf01f 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -113,6 +113,7 @@ int main(void)
   DEFINE(NVHE_INIT_TPIDR_EL2,  offsetof(struct kvm_nvhe_init_params, 
tpidr_el2));
   DEFINE(NVHE_INIT_VECTOR_HYP_VA,  offsetof(struct kvm_nvhe_init_params, 
vector_hyp_va));
   DEFINE(NVHE_INIT_STACK_HYP_VA,   offsetof(struct kvm_nvhe_init_params, 
stack_hyp_va));
+  DEFINE(NVHE_INIT_ENTRY_HYP_VA,   offsetof(struct kvm_nvhe_init_params, 
entry_hyp_va));
   DEFINE(NVHE_INIT_PGD_PA, offsetof(struct kvm_nvhe_init_params, pgd_pa));
 #endif
 #ifdef CONFIG_CPU_PM
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S 
b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
index d4a71ac34254..6d8202d2bdfb 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -159,6 +160,37 @@ alternative_else_nop_endif
ret
 SYM_CODE_END(___kvm_hyp_init)
 
+SYM_CODE_START(__kvm_hyp_cpu_entry)
+   msr SPsel, #1   // We want to use SP_EL{1,2}
+
+   /* Check that the core was booted in EL2. */
+   mrs x1, CurrentEL
+   cmp x1, #CurrentEL_EL2
+   b.eq2f
+
+   /* The core booted in EL1. KVM cannot be initialized on it. */
+1: wfe
+   wfi
+   b   1b
+
+   /* Initialize EL2 CPU state to sane values. */
+2: mov x29, x0
+   init_el2_state nvhe
+   mov x0, x29
+
+   /*
+* Load hyp VA of C entry function. Must do so before switching on the
+* MMU because the struct pointer is PA and not identity-mapped in hyp.
+*/
+   ldr x29, [x0, #NVHE_INIT_ENTRY_HYP_VA]
+
+   /* Enable MMU, set vectors and stack. */
+   bl  ___kvm_hyp_init
+
+   /* Leave idmap. */
+   br  x29
+SYM_CODE_END(__kvm_hyp_cpu_entry)
+
 SYM_CODE_START(__kvm_handle_stub_hvc)
cmp x0, #HVC_SOFT_RESTART
b.ne1f
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 06/24] kvm: arm64: Move hyp-init params to a per-CPU struct

2020-11-16 Thread David Brazdil
Once we start initializing KVM on newly booted cores before the rest of
the kernel, parameters to __do_hyp_init will need to be provided by EL2
rather than EL1. At that point it will not be possible to pass its four
arguments directly because PSCI_CPU_ON only supports one context
argument.

Refactor __do_hyp_init to accept its parameters in a struct. This
prepares the code for KVM booting cores as well as removes any limits on
the number of __do_hyp_init arguments.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/kvm_asm.h   |  7 +++
 arch/arm64/include/asm/kvm_hyp.h   |  4 
 arch/arm64/kernel/asm-offsets.c|  4 
 arch/arm64/kvm/arm.c   | 26 ++
 arch/arm64/kvm/hyp/nvhe/hyp-init.S | 21 ++---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c |  2 ++
 6 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index 54387ccd1ab2..01904e88cead 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -150,6 +150,13 @@ extern void *__vhe_undefined_symbol;
 
 #endif
 
+struct kvm_nvhe_init_params {
+   unsigned long tpidr_el2;
+   unsigned long vector_hyp_va;
+   unsigned long stack_hyp_va;
+   phys_addr_t pgd_pa;
+};
+
 /* Translate a kernel address @ptr into its equivalent linear mapping */
 #define kvm_ksym_ref(ptr)  \
({  \
diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
index 6b664de5ec1f..a3289071f3d8 100644
--- a/arch/arm64/include/asm/kvm_hyp.h
+++ b/arch/arm64/include/asm/kvm_hyp.h
@@ -15,6 +15,10 @@
 DECLARE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt);
 DECLARE_PER_CPU(unsigned long, kvm_hyp_vector);
 
+#ifdef __KVM_NVHE_HYPERVISOR__
+DECLARE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
+#endif
+
 #define read_sysreg_elx(r,nvh,vh)  \
({  \
u64 reg;\
diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index 7d32fc959b1a..4435ad8be938 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -110,6 +110,10 @@ int main(void)
   DEFINE(CPU_APGAKEYLO_EL1,offsetof(struct kvm_cpu_context, 
sys_regs[APGAKEYLO_EL1]));
   DEFINE(HOST_CONTEXT_VCPU,offsetof(struct kvm_cpu_context, 
__hyp_running_vcpu));
   DEFINE(HOST_DATA_CONTEXT,offsetof(struct kvm_host_data, host_ctxt));
+  DEFINE(NVHE_INIT_TPIDR_EL2,  offsetof(struct kvm_nvhe_init_params, 
tpidr_el2));
+  DEFINE(NVHE_INIT_VECTOR_HYP_VA,  offsetof(struct kvm_nvhe_init_params, 
vector_hyp_va));
+  DEFINE(NVHE_INIT_STACK_HYP_VA,   offsetof(struct kvm_nvhe_init_params, 
stack_hyp_va));
+  DEFINE(NVHE_INIT_PGD_PA, offsetof(struct kvm_nvhe_init_params, pgd_pa));
 #endif
 #ifdef CONFIG_CPU_PM
   DEFINE(CPU_CTX_SP,   offsetof(struct cpu_suspend_ctx, sp));
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index c0ffb019ca8b..4838556920fb 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -50,6 +50,7 @@ DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector);
 
 static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page);
 unsigned long kvm_arm_hyp_percpu_base[NR_CPUS];
+DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
 
 /* The VMID used in the VTTBR */
 static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
@@ -1347,10 +1348,7 @@ static int kvm_map_vectors(void)
 
 static void cpu_init_hyp_mode(void)
 {
-   phys_addr_t pgd_ptr;
-   unsigned long hyp_stack_ptr;
-   unsigned long vector_ptr;
-   unsigned long tpidr_el2;
+   struct kvm_nvhe_init_params *params = 
this_cpu_ptr_nvhe_sym(kvm_init_params);
struct arm_smccc_res res;
 
/* Switch from the HYP stub to our own HYP init vector */
@@ -1361,13 +1359,18 @@ static void cpu_init_hyp_mode(void)
 * kernel's mapping to the linear mapping, and store it in tpidr_el2
 * so that we can use adr_l to access per-cpu variables in EL2.
 */
-   tpidr_el2 = (unsigned long)this_cpu_ptr_nvhe_sym(__per_cpu_start) -
-   (unsigned 
long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start));
+   params->tpidr_el2 = (unsigned 
long)this_cpu_ptr_nvhe_sym(__per_cpu_start) -
+   (unsigned 
long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start));
 
-   pgd_ptr = kvm_mmu_get_httbr();
-   hyp_stack_ptr = __this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE;
-   hyp_stack_ptr = kern_hyp_va(hyp_stack_ptr);
-   vector_ptr = (unsigned 
long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_host_vector));
+   params->vector_hyp_va = (unsigned 
long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_host_vector));
+   params->stack_hyp_va = 

Re: [PATCH 39/43] drm/radeon/si_dpm: Move 'vce_v1_0_enable_mgcg()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/vce_v1_0.c:102:6: warning: no previous prototype for 
> ‘vce_v1_0_enable_mgcg’ [-Wmissing-prototypes]
>  102 | void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable)
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/si_dpm.c  |  3 +--
>  drivers/gpu/drm/radeon/trinity_dpm.c |  2 +-
>  drivers/gpu/drm/radeon/vce.h | 34 
>  drivers/gpu/drm/radeon/vce_v1_0.c|  1 +
>  4 files changed, 37 insertions(+), 3 deletions(-)
>  create mode 100644 drivers/gpu/drm/radeon/vce.h
>
> diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
> index b4581392fbce9..cd07b06301b44 100644
> --- a/drivers/gpu/drm/radeon/si_dpm.c
> +++ b/drivers/gpu/drm/radeon/si_dpm.c
> @@ -35,6 +35,7 @@
>  #include "si_dpm.h"
>  #include "si.h"
>  #include "sid.h"
> +#include "vce.h"
>
>  #define MC_CG_ARB_FREQ_F0   0x0a
>  #define MC_CG_ARB_FREQ_F1   0x0b
> @@ -1721,8 +1722,6 @@ static const struct si_powertune_data 
> powertune_data_hainan =
> true
>  };
>
> -extern void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
> -
>  static int si_populate_voltage_value(struct radeon_device *rdev,
>  const struct atom_voltage_table *table,
>  u16 value, SISLANDS_SMC_VOLTAGE_VALUE 
> *voltage);
> diff --git a/drivers/gpu/drm/radeon/trinity_dpm.c 
> b/drivers/gpu/drm/radeon/trinity_dpm.c
> index e005c18aac00e..08ea1c864cb23 100644
> --- a/drivers/gpu/drm/radeon/trinity_dpm.c
> +++ b/drivers/gpu/drm/radeon/trinity_dpm.c
> @@ -29,6 +29,7 @@
>  #include "radeon_asic.h"
>  #include "trinity_dpm.h"
>  #include "trinityd.h"
> +#include "vce.h"
>
>  #define TRINITY_MAX_DEEPSLEEP_DIVIDER_ID 5
>  #define TRINITY_MINIMUM_ENGINE_CLOCK 800
> @@ -293,7 +294,6 @@ static const u32 trinity_override_mgpg_sequences[] =
> 0x0204, 0x,
>  };
>
> -extern void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
>  static void trinity_program_clk_gating_hw_sequence(struct radeon_device 
> *rdev,
>const u32 *seq, u32 count);
>  static void trinity_override_dynamic_mg_powergating(struct radeon_device 
> *rdev);
> diff --git a/drivers/gpu/drm/radeon/vce.h b/drivers/gpu/drm/radeon/vce.h
> new file mode 100644
> index 0..1eb4f5715202e
> --- /dev/null
> +++ b/drivers/gpu/drm/radeon/vce.h
> @@ -0,0 +1,34 @@
> +/* vce.h -- Private header for radeon driver -*- linux-c -*-
> + *
> + * Copyright 2013 Advanced Micro Devices, Inc.
> + * All Rights Reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sub license, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY 
> CLAIM,
> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> + * USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial portions
> + * of the Software.
> + */
> +
> +#ifndef __VCE_H__
> +#define __VCE_H__
> +
> +struct radeon_device;
> +
> +void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
> +
> +#endif /* __VCE_H__ */
> diff --git a/drivers/gpu/drm/radeon/vce_v1_0.c 
> b/drivers/gpu/drm/radeon/vce_v1_0.c
> index bd75bbcf5bf63..70c5da2141d75 100644
> --- a/drivers/gpu/drm/radeon/vce_v1_0.c
> +++ b/drivers/gpu/drm/radeon/vce_v1_0.c
> @@ -30,6 +30,7 @@
>  #include "radeon.h"
>  #include "radeon_asic.h"
>  #include "sid.h"
> +#include "vce.h"
>
>  #define VCE_V1_0_FW_SIZE   (256 * 1024)
>  #define VCE_V1_0_STACK_SIZE(64 * 1024)
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 18/24] kvm: arm64: Add function to enter host from KVM nVHE hyp code

2020-11-16 Thread David Brazdil
All nVHE hyp code is currently executed as handlers of host's HVCs. This
will change as nVHE starts intercepting host's PSCI CPU_ON SMCs. The
newly booted CPU will need to initialize EL2 state and then enter the
host. Add __host_enter function that branches into the existing
host state-restoring code after the trap handler would have returned.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/host.S | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S
index 52dae5cd5a28..170d6f6376ae 100644
--- a/arch/arm64/kvm/hyp/nvhe/host.S
+++ b/arch/arm64/kvm/hyp/nvhe/host.S
@@ -41,6 +41,7 @@ SYM_FUNC_START(__host_exit)
bl  handle_trap
 
/* Restore host regs x0-x17 */
+__host_enter_restore_full:
ldp x0, x1,   [x29, #CPU_XREG_OFFSET(0)]
ldp x2, x3,   [x29, #CPU_XREG_OFFSET(2)]
ldp x4, x5,   [x29, #CPU_XREG_OFFSET(4)]
@@ -63,6 +64,14 @@ __host_enter_without_restoring:
sb
 SYM_FUNC_END(__host_exit)
 
+/*
+ * void __noreturn __host_enter(struct kvm_cpu_context *host_ctxt);
+ */
+SYM_FUNC_START(__host_enter)
+   mov x29, x0
+   b   __host_enter_restore_full
+SYM_FUNC_END(__host_enter)
+
 /*
  * void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 
par);
  */
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 08/24] kvm: arm64: Add SMC handler in nVHE EL2

2020-11-16 Thread David Brazdil
Add handler of host SMCs in KVM nVHE trap handler. Forward all SMCs to
EL3 and propagate the result back to EL1. This is done in preparation
for validating host SMCs in KVM nVHE protected mode.

The implementation assumes that firmware uses SMCCC v1.2 or older. That
means x0-x17 can be used both for arguments and results, other GPRs are
preserved.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/host.S | 38 ++
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 26 
 2 files changed, 64 insertions(+)

diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S
index ed27f06a31ba..52dae5cd5a28 100644
--- a/arch/arm64/kvm/hyp/nvhe/host.S
+++ b/arch/arm64/kvm/hyp/nvhe/host.S
@@ -183,3 +183,41 @@ SYM_CODE_START(__kvm_hyp_host_vector)
invalid_host_el1_vect   // FIQ 32-bit EL1
invalid_host_el1_vect   // Error 32-bit EL1
 SYM_CODE_END(__kvm_hyp_host_vector)
+
+/*
+ * Forward SMC with arguments in struct kvm_cpu_context, and
+ * store the result into the same struct. Assumes SMCCC 1.2 or older.
+ *
+ * x0: struct kvm_cpu_context*
+ */
+SYM_CODE_START(__kvm_hyp_host_forward_smc)
+   /*
+* Use x18 to keep a pointer to the host context because x18
+* is callee-saved SMCCC but not in AAPCS64.
+*/
+   mov x18, x0
+
+   ldp x0, x1,   [x18, #CPU_XREG_OFFSET(0)]
+   ldp x2, x3,   [x18, #CPU_XREG_OFFSET(2)]
+   ldp x4, x5,   [x18, #CPU_XREG_OFFSET(4)]
+   ldp x6, x7,   [x18, #CPU_XREG_OFFSET(6)]
+   ldp x8, x9,   [x18, #CPU_XREG_OFFSET(8)]
+   ldp x10, x11, [x18, #CPU_XREG_OFFSET(10)]
+   ldp x12, x13, [x18, #CPU_XREG_OFFSET(12)]
+   ldp x14, x15, [x18, #CPU_XREG_OFFSET(14)]
+   ldp x16, x17, [x18, #CPU_XREG_OFFSET(16)]
+
+   smc #0
+
+   stp x0, x1,   [x18, #CPU_XREG_OFFSET(0)]
+   stp x2, x3,   [x18, #CPU_XREG_OFFSET(2)]
+   stp x4, x5,   [x18, #CPU_XREG_OFFSET(4)]
+   stp x6, x7,   [x18, #CPU_XREG_OFFSET(6)]
+   stp x8, x9,   [x18, #CPU_XREG_OFFSET(8)]
+   stp x10, x11, [x18, #CPU_XREG_OFFSET(10)]
+   stp x12, x13, [x18, #CPU_XREG_OFFSET(12)]
+   stp x14, x15, [x18, #CPU_XREG_OFFSET(14)]
+   stp x16, x17, [x18, #CPU_XREG_OFFSET(16)]
+
+   ret
+SYM_CODE_END(__kvm_hyp_host_forward_smc)
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c 
b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 19332c20fcde..71a17af05953 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -16,6 +16,8 @@
 
 DEFINE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
 
+extern void __kvm_hyp_host_forward_smc(struct kvm_cpu_context *host_ctxt);
+
 static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 {
unsigned long func_id = host_ctxt->regs.regs[0];
@@ -106,6 +108,27 @@ static void handle_host_hcall(struct kvm_cpu_context 
*host_ctxt)
host_ctxt->regs.regs[1] = ret;
 }
 
+static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt)
+{
+   __kvm_hyp_host_forward_smc(host_ctxt);
+}
+
+static void skip_host_instruction(void)
+{
+   write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR);
+}
+
+static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
+{
+   default_host_smc_handler(host_ctxt);
+
+   /*
+* Unlike HVC, the return address of an SMC is the instruction's PC.
+* Move the return address past the instruction.
+*/
+   skip_host_instruction();
+}
+
 void handle_trap(struct kvm_cpu_context *host_ctxt)
 {
u64 esr = read_sysreg_el2(SYS_ESR);
@@ -114,6 +137,9 @@ void handle_trap(struct kvm_cpu_context *host_ctxt)
case ESR_ELx_EC_HVC64:
handle_host_hcall(host_ctxt);
break;
+   case ESR_ELx_EC_SMC64:
+   handle_host_smc(host_ctxt);
+   break;
default:
hyp_panic();
}
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 12/24] kvm: arm64: Bootstrap PSCI SMC handler in nVHE EL2

2020-11-16 Thread David Brazdil
Add a handler of PSCI SMCs in nVHE hyp code. The handler is initialized
with the version used by the host's PSCI driver and the function IDs it
was configured with. If the SMC function ID matches one of the
configured PSCI calls (for v0.1) or falls into the PSCI function ID
range (for v0.2+), the SMC is handled by the PSCI handler. For now, all
SMCs return PSCI_RET_NOT_SUPPORTED.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/kvm_hyp.h |   4 ++
 arch/arm64/kvm/arm.c |  14 
 arch/arm64/kvm/hyp/nvhe/Makefile |   2 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c   |   6 +-
 arch/arm64/kvm/hyp/nvhe/psci-relay.c | 104 +++
 5 files changed, 128 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm64/kvm/hyp/nvhe/psci-relay.c

diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h
index a3289071f3d8..95a2bbbcc7e1 100644
--- a/arch/arm64/include/asm/kvm_hyp.h
+++ b/arch/arm64/include/asm/kvm_hyp.h
@@ -96,6 +96,10 @@ void deactivate_traps_vhe_put(void);
 
 u64 __guest_enter(struct kvm_vcpu *vcpu);
 
+#ifdef __KVM_NVHE_HYPERVISOR__
+bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt);
+#endif
+
 void __noreturn hyp_panic(void);
 #ifdef __KVM_NVHE_HYPERVISOR__
 void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par);
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index cdd7981ea560..7d2270eeecfb 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define CREATE_TRACE_POINTS
@@ -1514,6 +1515,18 @@ static void init_cpu_logical_map(void)
CHOOSE_NVHE_SYM(__cpu_logical_map)[cpu] = cpu_logical_map(cpu);
 }
 
+static void init_psci_relay(void)
+{
+   extern u32 kvm_nvhe_sym(kvm_host_psci_version);
+   extern u32 kvm_nvhe_sym(kvm_host_psci_function_id)[PSCI_FN_MAX];
+   int i;
+
+   CHOOSE_NVHE_SYM(kvm_host_psci_version) = psci_ops.get_version
+   ? psci_ops.get_version() : PSCI_VERSION(0, 0);
+   for (i = 0; i < PSCI_FN_MAX; ++i)
+   CHOOSE_NVHE_SYM(kvm_host_psci_function_id)[i] = 
psci_get_function_id(i);
+}
+
 static int init_common_resources(void)
 {
return kvm_set_ipa_limit();
@@ -1693,6 +1706,7 @@ static int init_hyp_mode(void)
}
 
init_cpu_logical_map();
+   init_psci_relay();
 
return 0;
 
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
index 2d842e009a40..bf62c8e42ab2 100644
--- a/arch/arm64/kvm/hyp/nvhe/Makefile
+++ b/arch/arm64/kvm/hyp/nvhe/Makefile
@@ -7,7 +7,7 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__
 ccflags-y := -D__KVM_NVHE_HYPERVISOR__
 
 obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
-hyp-main.o hyp-smp.o
+hyp-main.o hyp-smp.o psci-relay.o
 obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
 ../fpsimd.o ../hyp-entry.o
 
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c 
b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 71a17af05953..df4acb40dd39 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -120,7 +120,11 @@ static void skip_host_instruction(void)
 
 static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
 {
-   default_host_smc_handler(host_ctxt);
+   bool handled;
+
+   handled = kvm_host_psci_handler(host_ctxt);
+   if (!handled)
+   default_host_smc_handler(host_ctxt);
 
/*
 * Unlike HVC, the return address of an SMC is the instruction's PC.
diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c 
b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
new file mode 100644
index ..d75d3f896bfd
--- /dev/null
+++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020 - Google LLC
+ * Author: David Brazdil 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Config options set by the host. */
+u32 __ro_after_init kvm_host_psci_version = PSCI_VERSION(0, 0);
+u32 __ro_after_init kvm_host_psci_function_id[PSCI_FN_MAX];
+
+static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt)
+{
+   return host_ctxt->regs.regs[0];
+}
+
+static bool is_psci_0_1_call(u64 func_id)
+{
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(kvm_host_psci_function_id); ++i) {
+   if (func_id == kvm_host_psci_function_id[i])
+   return true;
+   }
+   return false;
+}
+
+static bool is_psci_0_2_call(u64 func_id)
+{
+   /* SMCCC reserves IDs 0x00-1F with the given 32/64-bit base for PSCI. */
+   return (PSCI_0_2_FN(0) <= func_id && func_id <= PSCI_0_2_FN(31)) ||
+  (PSCI_0_2_FN64(0) <= func_id && func_id <= PSCI_0_2_FN64(31));
+}
+
+static bool is_psci_call(u64 func_id)
+{
+   switch (kvm_host_psci_version) {
+   case PSCI_VERSION(0, 0):
+   

[PATCH v2 23/24] kvm: arm64: Trap host SMCs in protected mode.

2020-11-16 Thread David Brazdil
While protected nVHE KVM is installed, start trapping all host SMCs.
By default, these are simply forwarded to EL3, but PSCI SMCs are
validated first.

Create new constant HCR_HOST_NVHE_PROTECTED_FLAGS with the new set of HCR
flags to use while the nVHE vector is installed when the kernel was
booted with the protected flag enabled. Switch back to the default HCR
flags when switching back to the stub vector.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/kvm_arm.h   |  1 +
 arch/arm64/kvm/hyp/nvhe/hyp-init.S | 12 
 arch/arm64/kvm/hyp/nvhe/switch.c   |  5 -
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 64ce29378467..4e90c2debf70 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -80,6 +80,7 @@
 HCR_FMO | HCR_IMO | HCR_PTW )
 #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF)
 #define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA)
+#define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC)
 #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
 
 /* TCR_EL2 Registers bits */
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S 
b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
index 6d8202d2bdfb..8f3602f320ac 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
@@ -88,6 +88,12 @@ SYM_CODE_END(__kvm_hyp_init)
  * x0: struct kvm_nvhe_init_params PA
  */
 SYM_CODE_START(___kvm_hyp_init)
+alternative_if ARM64_PROTECTED_KVM
+   mov_q   x1, HCR_HOST_NVHE_PROTECTED_FLAGS
+   msr hcr_el2, x1
+   isb
+alternative_else_nop_endif
+
ldr x1, [x0, #NVHE_INIT_TPIDR_EL2]
msr tpidr_el2, x1
 
@@ -224,6 +230,12 @@ reset:
msr sctlr_el2, x5
isb
 
+alternative_if ARM64_PROTECTED_KVM
+   mov_q   x5, HCR_HOST_NVHE_FLAGS
+   msr hcr_el2, x5
+   isb
+alternative_else_nop_endif
+
/* Install stub vectors */
adr_l   x5, __hyp_stub_vectors
msr vbar_el2, x5
diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index 8ae8160bc93a..e1f8e0797144 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -96,7 +96,10 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT;
 
write_sysreg(mdcr_el2, mdcr_el2);
-   write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2);
+   if (is_protected_kvm_enabled())
+   write_sysreg(HCR_HOST_NVHE_PROTECTED_FLAGS, hcr_el2);
+   else
+   write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2);
write_sysreg(CPTR_EL2_DEFAULT, cptr_el2);
write_sysreg(__kvm_hyp_host_vector, vbar_el2);
 }
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 21/24] kvm: arm64: Add kvm-arm.protected early kernel parameter

2020-11-16 Thread David Brazdil
Add an early parameter that allows users to opt into protected KVM mode
when using the nVHE hypervisor. In this mode, guest state will be kept
private from the host. This will primarily involve enabling stage-2
address translation for the host, restricting DMA to host memory, and
filtering host SMCs.

Capability ARM64_PROTECTED_KVM is set if the param is passed, CONFIG_KVM
is enabled and the kernel was not booted with VHE.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/cpucaps.h |  3 ++-
 arch/arm64/include/asm/virt.h|  8 
 arch/arm64/kernel/cpufeature.c   | 29 +
 arch/arm64/kvm/arm.c | 10 +-
 4 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
index e7d98997c09c..ac075f70b2e4 100644
--- a/arch/arm64/include/asm/cpucaps.h
+++ b/arch/arm64/include/asm/cpucaps.h
@@ -66,7 +66,8 @@
 #define ARM64_HAS_TLB_RANGE56
 #define ARM64_MTE  57
 #define ARM64_WORKAROUND_1508412   58
+#define ARM64_PROTECTED_KVM59
 
-#define ARM64_NCAPS59
+#define ARM64_NCAPS60
 
 #endif /* __ASM_CPUCAPS_H */
diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h
index 6069be50baf9..2fde1186b962 100644
--- a/arch/arm64/include/asm/virt.h
+++ b/arch/arm64/include/asm/virt.h
@@ -97,6 +97,14 @@ static __always_inline bool has_vhe(void)
return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN);
 }
 
+static __always_inline bool is_protected_kvm_enabled(void)
+{
+   if (is_vhe_hyp_code())
+   return false;
+   else
+   return cpus_have_final_cap(ARM64_PROTECTED_KVM);
+}
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* ! __ASM__VIRT_H */
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 6f36c4f62f69..dd5bc0f0cf0d 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1709,6 +1709,29 @@ static void cpu_enable_mte(struct arm64_cpu_capabilities 
const *cap)
 }
 #endif /* CONFIG_ARM64_MTE */
 
+#ifdef CONFIG_KVM
+static bool enable_protected_kvm;
+
+static bool has_protected_kvm(const struct arm64_cpu_capabilities *entry, int 
__unused)
+{
+   if (!enable_protected_kvm)
+   return false;
+
+   if (is_kernel_in_hyp_mode()) {
+   pr_warn("Protected KVM not available with VHE\n");
+   return false;
+   }
+
+   return true;
+}
+
+static int __init early_protected_kvm_cfg(char *buf)
+{
+   return strtobool(buf, _protected_kvm);
+}
+early_param("kvm-arm.protected", early_protected_kvm_cfg);
+#endif /* CONFIG_KVM */
+
 /* Internal helper functions to match cpu capability type */
 static bool
 cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap)
@@ -1822,6 +1845,12 @@ static const struct arm64_cpu_capabilities 
arm64_features[] = {
.field_pos = ID_AA64PFR0_EL1_SHIFT,
.min_field_value = ID_AA64PFR0_EL1_32BIT_64BIT,
},
+   {
+   .desc = "Protected KVM",
+   .capability = ARM64_PROTECTED_KVM,
+   .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+   .matches = has_protected_kvm,
+   },
 #endif
{
.desc = "Kernel page table isolation (KPTI)",
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index c76a8e5bd19c..49d2474f2a80 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1796,6 +1796,12 @@ int kvm_arch_init(void *opaque)
return -ENODEV;
}
 
+   /* The PROTECTED_KVM cap should not have been enabled for VHE. */
+   if (in_hyp_mode && is_protected_kvm_enabled()) {
+   kvm_pr_unimpl("VHE protected mode unsupported, not 
initializing\n");
+   return -ENODEV;
+   }
+
if (cpus_have_final_cap(ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE) ||
cpus_have_final_cap(ARM64_WORKAROUND_1508412))
kvm_info("Guests without required CPU erratum workarounds can 
deadlock system!\n" \
@@ -1827,7 +1833,9 @@ int kvm_arch_init(void *opaque)
if (err)
goto out_hyp;
 
-   if (in_hyp_mode)
+   if (is_protected_kvm_enabled())
+   kvm_info("Protected nVHE mode initialized successfully\n");
+   else if (in_hyp_mode)
kvm_info("VHE mode initialized successfully\n");
else
kvm_info("Hyp mode initialized successfully\n");
-- 
2.29.2.299.gdc1121823c-goog



Re: [PATCH] mfd: cpcap: Fix interrupt regression with regmap clear_ack

2020-11-16 Thread Tim Harvey
On Mon, Nov 16, 2020 at 10:59 AM Mark Brown  wrote:
>
> On Fri, Nov 13, 2020 at 02:06:29PM -0800, Tim Harvey wrote:
>
> > asserted? I'm also wondering if my issue is that I currently have the
> > interrupt registered as such:
>
> > ret = devm_regmap_add_irq_chip(dev, gsc->regmap, client->irq,
> > IRQF_ONESHOT | IRQF_SHARED | IRQF_TRIGGER_FALLING, 0, _irq_chip,
> > _data);
>
> > Perhaps this should be IRQF_TRIGGER_LOW as the device will not
> > de-assert its IRQ# until all source bits are cleared.
>
> That's clearly an active low interrupt, it will break things if it's
> registered as edge triggered.

Mark,

Agreed - I will post a fix for my driver that changes it to IRQF_TRIGGER_LOW

What are your thoughts regarding the issue of  regmap_irq_sync_unlock
ack_invert ack'ing by writing ~d->mask_buf[i] which ends up setting
all the other bits not trying to be awk'd? I would say that the device
allowing an interrupt status to be 'set' and keeping it from releasing
its IRQ is strange/broken for sure, but I'll need to work around it
somehow.

Best Regards,

Tim


[PATCH v2 00/24] Opt-in always-on nVHE hypervisor

2020-11-16 Thread David Brazdil
As we progress towards being able to keep guest state private to the
host running nVHE hypervisor, this series allows the hypervisor to
install itself on newly booted CPUs before the host is allowed to run
on them.

All functionality described below is opt-in, guarded by an early param
'kvm-arm.protected'. Future patches specific to the new "protected" mode
should be hidden behind the same param.

The hypervisor starts trapping host SMCs and intercepting host's PSCI
CPU_ON/SUSPEND calls. It replaces the host's entry point with its own,
initializes the EL2 state of the new CPU and installs the nVHE hyp vector
before ERETing to the host's entry point.

The kernel checks new cores' features against the finalized system
capabilities. To avoid the need to move this code/data to EL2, the
implementation only allows to boot cores that were online at the time of
KVM initialization and therefore had been checked already.

Other PSCI SMCs are forwarded to EL3, though only the known set of SMCs
implemented in the kernel is allowed. Non-PSCI SMCs are also forwarded
to EL3. Future changes will need to ensure the safety of all SMCs wrt.
private guests.

The host is still allowed to reset EL2 back to the stub vector, eg. for
hibernation or kexec, but will not disable nVHE when there are no VMs.

Tested on Rock Pi 4b, based on 5.10-rc4.

changes since v1:
  * early param sets a capability instead of a static key
  * assume SMCCC v1.2 for host SMC forwarding
  * fix reserved SMC ID range for PSCI
  * split init_el2_state into smaller macros, move to el2_setup.h
  * many small cleanups

changes since RFC:
  * add early param to make features opt-in
  * simplify CPU_ON/SUSPEND implementation
  * replace spinlocks with CAS atomic
  * make cpu_logical_map ro_after_init

David Brazdil (24):
  psci: Support psci_ops.get_version for v0.1
  psci: Accessor for configured PSCI function IDs
  arm64: Make cpu_logical_map() take unsigned int
  arm64: Move MAIR_EL1_SET to asm/memory.h
  kvm: arm64: Initialize MAIR_EL2 using a constant
  kvm: arm64: Move hyp-init params to a per-CPU struct
  kvm: arm64: Refactor handle_trap to use a switch
  kvm: arm64: Add SMC handler in nVHE EL2
  kvm: arm64: Add .hyp.data..ro_after_init ELF section
  kvm: arm64: Support per_cpu_ptr in nVHE hyp code
  kvm: arm64: Create nVHE copy of cpu_logical_map
  kvm: arm64: Bootstrap PSCI SMC handler in nVHE EL2
  kvm: arm64: Add offset for hyp VA <-> PA conversion
  kvm: arm64: Forward safe PSCI SMCs coming from host
  kvm: arm64: Extract parts of el2_setup into a macro
  kvm: arm64: Extract __do_hyp_init into a helper function
  kvm: arm64: Add CPU entry point in nVHE hyp
  kvm: arm64: Add function to enter host from KVM nVHE hyp code
  kvm: arm64: Intercept host's PSCI_CPU_ON SMCs
  kvm: arm64: Intercept host's CPU_SUSPEND PSCI SMCs
  kvm: arm64: Add kvm-arm.protected early kernel parameter
  kvm: arm64: Keep nVHE EL2 vector installed
  kvm: arm64: Trap host SMCs in protected mode.
  kvm: arm64: Fix EL2 mode availability checks

 arch/arm64/include/asm/cpucaps.h |   3 +-
 arch/arm64/include/asm/el2_setup.h   | 185 +
 arch/arm64/include/asm/kvm_arm.h |   1 +
 arch/arm64/include/asm/kvm_asm.h |  16 +-
 arch/arm64/include/asm/kvm_hyp.h |   8 +
 arch/arm64/include/asm/memory.h  |  29 ++-
 arch/arm64/include/asm/percpu.h  |   6 +
 arch/arm64/include/asm/sections.h|   1 +
 arch/arm64/include/asm/smp.h |   4 +-
 arch/arm64/include/asm/sysreg.h  |  30 +++
 arch/arm64/include/asm/virt.h|  26 +++
 arch/arm64/kernel/asm-offsets.c  |   5 +
 arch/arm64/kernel/cpufeature.c   |  29 +++
 arch/arm64/kernel/head.S | 144 ++---
 arch/arm64/kernel/image-vars.h   |   3 +
 arch/arm64/kernel/setup.c|   2 +-
 arch/arm64/kernel/vmlinux.lds.S  |  10 +
 arch/arm64/kvm/arm.c |  94 +++--
 arch/arm64/kvm/hyp/nvhe/Makefile |   3 +-
 arch/arm64/kvm/hyp/nvhe/host.S   |  47 +
 arch/arm64/kvm/hyp/nvhe/hyp-init.S   |  90 +++--
 arch/arm64/kvm/hyp/nvhe/hyp-main.c   |  47 -
 arch/arm64/kvm/hyp/nvhe/hyp-smp.c|  40 
 arch/arm64/kvm/hyp/nvhe/hyp.lds.S|   1 +
 arch/arm64/kvm/hyp/nvhe/psci-relay.c | 289 +++
 arch/arm64/kvm/hyp/nvhe/switch.c |   5 +-
 arch/arm64/kvm/va_layout.c   |  30 ++-
 arch/arm64/mm/proc.S |  15 +-
 drivers/firmware/psci/psci.c |  21 +-
 include/linux/psci.h |  10 +
 30 files changed, 977 insertions(+), 217 deletions(-)
 create mode 100644 arch/arm64/include/asm/el2_setup.h
 create mode 100644 arch/arm64/kvm/hyp/nvhe/hyp-smp.c
 create mode 100644 arch/arm64/kvm/hyp/nvhe/psci-relay.c

--
2.29.2.299.gdc1121823c-goog


[PATCH v2 02/24] psci: Accessor for configured PSCI function IDs

2020-11-16 Thread David Brazdil
Function IDs used by PSCI are configurable for v0.1 via DT/APCI. If the
host is using PSCI v0.1, KVM's host PSCI proxy needs to use the same IDs.
Expose the array holding the information with a read-only accessor.

Signed-off-by: David Brazdil 
---
 drivers/firmware/psci/psci.c | 14 ++
 include/linux/psci.h | 10 ++
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
index 213c68418a65..d835f3d8b121 100644
--- a/drivers/firmware/psci/psci.c
+++ b/drivers/firmware/psci/psci.c
@@ -58,16 +58,14 @@ typedef unsigned long (psci_fn)(unsigned long, unsigned 
long,
unsigned long, unsigned long);
 static psci_fn *invoke_psci_fn;
 
-enum psci_function {
-   PSCI_FN_CPU_SUSPEND,
-   PSCI_FN_CPU_ON,
-   PSCI_FN_CPU_OFF,
-   PSCI_FN_MIGRATE,
-   PSCI_FN_MAX,
-};
-
 static u32 psci_function_id[PSCI_FN_MAX];
 
+u32 psci_get_function_id(enum psci_function fn)
+{
+   WARN_ON(fn >= PSCI_FN_MAX);
+   return psci_function_id[fn];
+}
+
 #define PSCI_0_2_POWER_STATE_MASK  \
(PSCI_0_2_POWER_STATE_ID_MASK | \
PSCI_0_2_POWER_STATE_TYPE_MASK | \
diff --git a/include/linux/psci.h b/include/linux/psci.h
index 2a1bfb890e58..5b49a5c82d6f 100644
--- a/include/linux/psci.h
+++ b/include/linux/psci.h
@@ -21,6 +21,16 @@ bool psci_power_state_is_valid(u32 state);
 int psci_set_osi_mode(bool enable);
 bool psci_has_osi_support(void);
 
+enum psci_function {
+   PSCI_FN_CPU_SUSPEND,
+   PSCI_FN_CPU_ON,
+   PSCI_FN_CPU_OFF,
+   PSCI_FN_MIGRATE,
+   PSCI_FN_MAX,
+};
+
+u32 psci_get_function_id(enum psci_function fn);
+
 struct psci_operations {
u32 (*get_version)(void);
int (*cpu_suspend)(u32 state, unsigned long entry_point);
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 20/24] kvm: arm64: Intercept host's CPU_SUSPEND PSCI SMCs

2020-11-16 Thread David Brazdil
Add a handler of CPU_SUSPEND host PSCI SMCs. The SMC can either enter
a sleep state indistinguishable from a WFI or a deeper sleep state that
behaves like a CPU_OFF+CPU_ON.

The handler saves r0,pc of the host and makes the same call to EL3 with
the hyp CPU entry point. It either returns back to the handler and then
back to the host, or wakes up into the entry point and initializes EL2
state before dropping back to EL1.

There is a simple atomic lock around the reset state struct to protect
from races with CPU_ON. A well-behaved host should never run CPU_ON
against an already online core, and the kernel indeed does not allow
that, so if the core sees its reset state struct locked, it will return
a non-spec error code PENDING_ON. This protects the hypervisor state and
avoids the need for more complicated locking and/or tracking power state
of individual cores.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/psci-relay.c | 39 +++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c 
b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
index 2daf52b59846..313ef42f0eab 100644
--- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c
+++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
@@ -121,6 +121,39 @@ static void release_reset_state(struct kvm_host_psci_state 
*cpu_state)
atomic_set_release(_state->pending_on, 0);
 }
 
+static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt)
+{
+   u64 power_state = host_ctxt->regs.regs[1];
+   unsigned long pc = host_ctxt->regs.regs[2];
+   unsigned long r0 = host_ctxt->regs.regs[3];
+   struct kvm_host_psci_state *cpu_state;
+   struct kvm_nvhe_init_params *cpu_params;
+   int ret;
+
+   cpu_state = this_cpu_ptr(_host_psci_state);
+   cpu_params = this_cpu_ptr(_init_params);
+
+   /*
+* Lock the reset state struct. This fails if the host has concurrently
+* called CPU_ON with this CPU as target. The kernel keeps track of
+* online CPUs, so that should never happen. If it does anyway, return
+* a non-spec error. This avoids the need for spinlocks.
+*/
+   if (!try_acquire_reset_state(cpu_state, pc, r0))
+   return PSCI_RET_ALREADY_ON;
+
+   /*
+* Will either return if shallow sleep state, or wake up into the entry
+* point if it is a deep sleep state.
+*/
+   ret = psci_call(func_id, power_state,
+   __hyp_pa(hyp_symbol_addr(__kvm_hyp_cpu_entry)),
+   __hyp_pa(cpu_params));
+
+   release_reset_state(cpu_state);
+   return ret;
+}
+
 static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt)
 {
u64 mpidr = host_ctxt->regs.regs[1];
@@ -178,7 +211,9 @@ asmlinkage void __noreturn __kvm_hyp_psci_cpu_entry(void)
 
 static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context 
*host_ctxt)
 {
-   if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF])
+   if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_SUSPEND])
+   return psci_cpu_suspend(func_id, host_ctxt);
+   else if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF])
return psci_forward(host_ctxt);
else if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_ON])
return psci_cpu_on(func_id, host_ctxt);
@@ -202,6 +237,8 @@ static unsigned long psci_0_2_handler(u64 func_id, struct 
kvm_cpu_context *host_
case PSCI_0_2_FN_SYSTEM_RESET:
psci_forward_noreturn(host_ctxt);
unreachable();
+   case PSCI_0_2_FN64_CPU_SUSPEND:
+   return psci_cpu_suspend(func_id, host_ctxt);
case PSCI_0_2_FN64_CPU_ON:
return psci_cpu_on(func_id, host_ctxt);
default:
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 05/24] kvm: arm64: Initialize MAIR_EL2 using a constant

2020-11-16 Thread David Brazdil
MAIR_EL2 is currently initialized to the value of MAIR_EL1, which itself
is set to a constant MAIR_ELx_SET.

Initialize MAIR_EL2 to MAIR_ELx_SET directly in preparation of allowing
KVM to start CPU cores itself and not initializing itself before ERETing
to EL1. In that case, MAIR_EL2 will be initialized before MAIR_EL1.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/hyp-init.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S 
b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
index b11a9d7db677..17b58dbc3a2f 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
@@ -111,7 +111,7 @@ alternative_else_nop_endif
 
msr tcr_el2, x0
 
-   mrs x0, mair_el1
+   mov_q   x0, MAIR_ELx_SET
msr mair_el2, x0
isb
 
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 01/24] psci: Support psci_ops.get_version for v0.1

2020-11-16 Thread David Brazdil
KVM's host PSCI SMC filter needs to be aware of the PSCI version of the
system but currently it is impossible to distinguish between v0.1 and
PSCI disabled because both have get_version == NULL.

Populate get_version for v0.1 with a function that returns a constant.

psci_opt.get_version is currently unused so this has no effect on
existing functionality.

Signed-off-by: David Brazdil 
---
 drivers/firmware/psci/psci.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
index 00af99b6f97c..213c68418a65 100644
--- a/drivers/firmware/psci/psci.c
+++ b/drivers/firmware/psci/psci.c
@@ -146,6 +146,11 @@ static int psci_to_linux_errno(int errno)
return -EINVAL;
 }
 
+static u32 psci_get_version_0_1(void)
+{
+   return PSCI_VERSION(0, 1);
+}
+
 static u32 psci_get_version(void)
 {
return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
@@ -514,6 +519,8 @@ static int __init psci_0_1_init(struct device_node *np)
 
pr_info("Using PSCI v0.1 Function IDs from DT\n");
 
+   psci_ops.get_version = psci_get_version_0_1;
+
if (!of_property_read_u32(np, "cpu_suspend", )) {
psci_function_id[PSCI_FN_CPU_SUSPEND] = id;
psci_ops.cpu_suspend = psci_cpu_suspend;
-- 
2.29.2.299.gdc1121823c-goog



Re: Error: invalid switch -me200

2020-11-16 Thread Scott Wood
On Fri, 2020-11-13 at 18:50 -0600, Segher Boessenkool wrote:
> On Fri, Nov 13, 2020 at 04:37:38PM -0800, Fāng-ruì Sòng wrote:
> > On Fri, Nov 13, 2020 at 4:23 PM Segher Boessenkool
> >  wrote:
> > > On Fri, Nov 13, 2020 at 12:14:18PM -0800, Nick Desaulniers wrote:
> > > > > > > Error: invalid switch -me200
> > > > > > > Error: unrecognized option -me200
> > > > > > 
> > > > > > 251 cpu-as-$(CONFIG_E200)   += -Wa,-me200
> > > > > > 
> > > > > > Are those all broken configs, or is Kconfig messed up such that
> > > > > > randconfig can select these when it should not?
> > > > > 
> > > > > Hmmm, looks like this flag does not exist in mainline binutils?
> > > > > There is
> > > > > a thread in 2010 about this that Segher commented on:
> > > > > 
> > > > > 
https://lore.kernel.org/linuxppc-dev/9859e645-954d-4d07-8003-ffcd2391a...@kernel.crashing.org/
> > > > > 
> > > > > Guess this config should be eliminated?
> > > 
> > > The help text for this config options says that e200 is used in 55xx,
> > > and there *is* an -me5500 GAS flag (which probably does this same
> > > thing, too).  But is any of this tested, or useful, or wanted?
> > > 
> > > Maybe Christophe knows, cc:ed.
> > 
> > CC Alan Modra, a binutils global maintainer.
> > 
> > Alan, can the few -Wa,-m* options deleted from arch/powerpc/Makefile ?
> 
> All the others work fine (and are needed afaics), it is only -me200 that
> doesn't exist (in mainline binutils).  Perhaps -me5500 will work for it
> instead.

According to Wikipedia e200 is from mpc55xx (for which I don't see any
platform support having ever been added).  e5500 is completely different (64-
bit version of e500mc).

-Scott




[PATCH v2 19/24] kvm: arm64: Intercept host's PSCI_CPU_ON SMCs

2020-11-16 Thread David Brazdil
Add a handler of the CPU_ON PSCI call from host. When invoked, it looks
up the logical CPU ID corresponding to the provided MPIDR and populates
the state struct of the target CPU with the provided x0, pc. It then
calls CPU_ON itself, with an entry point in hyp that initializes EL2
state before returning ERET to the provided PC in EL1.

There is a simple atomic lock around the reset state struct. If it is
already locked, CPU_ON will return PENDING_ON error code.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/kvm_asm.h |   8 ++-
 arch/arm64/kvm/arm.c |   1 +
 arch/arm64/kvm/hyp/nvhe/psci-relay.c | 104 +++
 3 files changed, 110 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index 109867fb76f6..2e36ba4be748 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -175,9 +175,11 @@ struct kvm_s2_mmu;
 DECLARE_KVM_NVHE_SYM(__kvm_hyp_init);
 DECLARE_KVM_NVHE_SYM(__kvm_hyp_host_vector);
 DECLARE_KVM_HYP_SYM(__kvm_hyp_vector);
-#define __kvm_hyp_init CHOOSE_NVHE_SYM(__kvm_hyp_init)
-#define __kvm_hyp_host_vector  CHOOSE_NVHE_SYM(__kvm_hyp_host_vector)
-#define __kvm_hyp_vector   CHOOSE_HYP_SYM(__kvm_hyp_vector)
+DECLARE_KVM_NVHE_SYM(__kvm_hyp_psci_cpu_entry);
+#define __kvm_hyp_init CHOOSE_NVHE_SYM(__kvm_hyp_init)
+#define __kvm_hyp_host_vector  CHOOSE_NVHE_SYM(__kvm_hyp_host_vector)
+#define __kvm_hyp_vector   CHOOSE_HYP_SYM(__kvm_hyp_vector)
+#define __kvm_hyp_psci_cpu_entry   
CHOOSE_NVHE_SYM(__kvm_hyp_psci_cpu_entry)
 
 extern unsigned long kvm_arm_hyp_percpu_base[NR_CPUS];
 DECLARE_KVM_NVHE_SYM(__per_cpu_start);
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 7d2270eeecfb..c76a8e5bd19c 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1365,6 +1365,7 @@ static void cpu_init_hyp_mode(void)
 
params->vector_hyp_va = (unsigned 
long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_host_vector));
params->stack_hyp_va = 
kern_hyp_va(__this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE);
+   params->entry_hyp_va = (unsigned 
long)kern_hyp_va(kvm_ksym_ref(__kvm_hyp_psci_cpu_entry));
params->pgd_pa = kvm_mmu_get_httbr();
 
/*
diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c 
b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
index 7542de8bd679..2daf52b59846 100644
--- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c
+++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
@@ -9,10 +9,15 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
+#define INVALID_CPU_ID UINT_MAX
+
+extern char __kvm_hyp_cpu_entry[];
+
 /* Config options set by the host. */
 u32 __ro_after_init kvm_host_psci_version = PSCI_VERSION(0, 0);
 u32 __ro_after_init kvm_host_psci_function_id[PSCI_FN_MAX];
@@ -20,6 +25,14 @@ s64 __ro_after_init hyp_physvirt_offset;
 
 #define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset)
 
+struct kvm_host_psci_state {
+   atomic_t pending_on;
+   unsigned long pc;
+   unsigned long r0;
+};
+
+static DEFINE_PER_CPU(struct kvm_host_psci_state, kvm_host_psci_state);
+
 static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt)
 {
return host_ctxt->regs.regs[0];
@@ -76,10 +89,99 @@ static __noreturn unsigned long 
psci_forward_noreturn(struct kvm_cpu_context *ho
hyp_panic(); /* unreachable */
 }
 
+static unsigned int find_cpu_id(u64 mpidr)
+{
+   int i;
+
+   if (mpidr != INVALID_HWID) {
+   for (i = 0; i < NR_CPUS; i++) {
+   if (cpu_logical_map(i) == mpidr)
+   return i;
+   }
+   }
+
+   return INVALID_CPU_ID;
+}
+
+static bool try_acquire_reset_state(struct kvm_host_psci_state *cpu_state,
+   unsigned long pc, unsigned long r0)
+{
+   if (atomic_cmpxchg_acquire(_state->pending_on, 0, 1) != 0)
+   return false;
+
+   cpu_state->pc = pc;
+   cpu_state->r0 = r0;
+   wmb();
+
+   return true;
+}
+
+static void release_reset_state(struct kvm_host_psci_state *cpu_state)
+{
+   atomic_set_release(_state->pending_on, 0);
+}
+
+static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt)
+{
+   u64 mpidr = host_ctxt->regs.regs[1];
+   unsigned long pc = host_ctxt->regs.regs[2];
+   unsigned long r0 = host_ctxt->regs.regs[3];
+   unsigned int cpu_id;
+   struct kvm_host_psci_state *cpu_state;
+   struct kvm_nvhe_init_params *cpu_params;
+   int ret;
+
+   /*
+* Find the logical CPU ID for the given MPIDR. The search set is
+* the set of CPUs that were online at the point of KVM initialization.
+* Booting other CPUs is rejected because their cpufeatures were not
+* checked against the finalized capabilities. This could be relaxed
+* by doing the feature checks in hyp.
+*/
+   cpu_id = 

[PATCH v2 13/24] kvm: arm64: Add offset for hyp VA <-> PA conversion

2020-11-16 Thread David Brazdil
Add a host-initialized constant to KVM nVHE hyp code for converting
between EL2 linear map virtual addresses and physical addresses.
Also add `__hyp_pa` macro that performs the conversion.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/hyp/nvhe/psci-relay.c |  3 +++
 arch/arm64/kvm/va_layout.c   | 30 +---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c 
b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
index d75d3f896bfd..1583b63322c4 100644
--- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c
+++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
@@ -16,6 +16,9 @@
 /* Config options set by the host. */
 u32 __ro_after_init kvm_host_psci_version = PSCI_VERSION(0, 0);
 u32 __ro_after_init kvm_host_psci_function_id[PSCI_FN_MAX];
+s64 __ro_after_init hyp_physvirt_offset;
+
+#define __hyp_pa(x) ((phys_addr_t)((x)) + hyp_physvirt_offset)
 
 static u64 get_psci_func_id(struct kvm_cpu_context *host_ctxt)
 {
diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c
index e0404bcab019..744a0d998ad3 100644
--- a/arch/arm64/kvm/va_layout.c
+++ b/arch/arm64/kvm/va_layout.c
@@ -22,6 +22,30 @@ static u8 tag_lsb;
 static u64 tag_val;
 static u64 va_mask;
 
+/*
+ * Compute HYP VA by using the same computation as kern_hyp_va().
+ */
+static u64 __early_kern_hyp_va(u64 addr)
+{
+   addr &= va_mask;
+   addr |= tag_val << tag_lsb;
+   return addr;
+}
+
+/*
+ * Store a hyp VA <-> PA offset into a hyp-owned variable.
+ */
+static void init_hyp_physvirt_offset(void)
+{
+   extern s64 kvm_nvhe_sym(hyp_physvirt_offset);
+   u64 kern_va, hyp_va;
+
+   /* Compute the offset from the hyp VA and PA of a random symbol. */
+   kern_va = (u64)kvm_ksym_ref(__hyp_text_start);
+   hyp_va = __early_kern_hyp_va(kern_va);
+   CHOOSE_NVHE_SYM(hyp_physvirt_offset) = (s64)__pa(kern_va) - (s64)hyp_va;
+}
+
 /*
  * We want to generate a hyp VA with the following format (with V ==
  * vabits_actual):
@@ -53,6 +77,8 @@ __init void kvm_compute_layout(void)
tag_val |= get_random_long() & GENMASK_ULL(vabits_actual - 2, 
tag_lsb);
}
tag_val >>= tag_lsb;
+
+   init_hyp_physvirt_offset();
 }
 
 static u32 compute_instruction(int n, u32 rd, u32 rn)
@@ -150,9 +176,7 @@ void kvm_patch_vector_branch(struct alt_instr *alt,
/*
 * Compute HYP VA by using the same computation as kern_hyp_va()
 */
-   addr = (uintptr_t)kvm_ksym_ref(__kvm_hyp_vector);
-   addr &= va_mask;
-   addr |= tag_val << tag_lsb;
+   addr = __early_kern_hyp_va((u64)kvm_ksym_ref(__kvm_hyp_vector));
 
/* Use PC[10:7] to branch to the same vector in KVM */
addr |= ((u64)origptr & GENMASK_ULL(10, 7));
-- 
2.29.2.299.gdc1121823c-goog



Re: [PATCH 38/43] drm/radeon/cik: Move 'Move 'cik_sdma_*()'s prototypes to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/cik_sdma.c:331:6: warning: no previous prototype for 
> ‘cik_sdma_enable’ [-Wmissing-prototypes]
>  331 | void cik_sdma_enable(struct radeon_device *rdev, bool enable)
>  | ^~~
>  drivers/gpu/drm/radeon/cik_sdma.c:528:5: warning: no previous prototype for 
> ‘cik_sdma_resume’ [-Wmissing-prototypes]
>  528 | int cik_sdma_resume(struct radeon_device *rdev)
>  | ^~~
>  drivers/gpu/drm/radeon/cik_sdma.c:557:6: warning: no previous prototype for 
> ‘cik_sdma_fini’ [-Wmissing-prototypes]
>  557 | void cik_sdma_fini(struct radeon_device *rdev)
>  | ^
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Sumit Semwal 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Cc: linux-me...@vger.kernel.org
> Cc: linaro-mm-...@lists.linaro.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/cik.c | 3 ---
>  drivers/gpu/drm/radeon/cik.h | 3 +++
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
> index cef0f3111cd3a..2af76463906ad 100644
> --- a/drivers/gpu/drm/radeon/cik.c
> +++ b/drivers/gpu/drm/radeon/cik.c
> @@ -129,9 +129,6 @@ MODULE_FIRMWARE("radeon/mullins_rlc.bin");
>  MODULE_FIRMWARE("radeon/mullins_sdma.bin");
>
>  static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 
> sh);
> -extern int cik_sdma_resume(struct radeon_device *rdev);
> -extern void cik_sdma_enable(struct radeon_device *rdev, bool enable);
> -extern void cik_sdma_fini(struct radeon_device *rdev);
>  extern void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable);
>  static void cik_rlc_stop(struct radeon_device *rdev);
>  static void cik_pcie_gen3_enable(struct radeon_device *rdev);
> diff --git a/drivers/gpu/drm/radeon/cik.h b/drivers/gpu/drm/radeon/cik.h
> index 420207d19de52..d1bf541da5923 100644
> --- a/drivers/gpu/drm/radeon/cik.h
> +++ b/drivers/gpu/drm/radeon/cik.h
> @@ -34,4 +34,7 @@ void cik_init_cp_pg_table(struct radeon_device *rdev);
>  u32 cik_get_csb_size(struct radeon_device *rdev);
>  void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
>
> +int cik_sdma_resume(struct radeon_device *rdev);
> +void cik_sdma_enable(struct radeon_device *rdev, bool enable);
> +void cik_sdma_fini(struct radeon_device *rdev);
>  #endif /* __CIK_H__ */
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v2 11/24] kvm: arm64: Create nVHE copy of cpu_logical_map

2020-11-16 Thread David Brazdil
When KVM starts validating host's PSCI requests, it will need to map
MPIDR back to the CPU ID. To this end, copy cpu_logical_map into nVHE
hyp memory when KVM is initialized.

Only copy the information for CPUs that are online at the point of KVM
initialization so that KVM rejects CPUs whose features were not checked
against the finalized capabilities.

Signed-off-by: David Brazdil 
---
 arch/arm64/kvm/arm.c  | 17 +
 arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 16 
 2 files changed, 33 insertions(+)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 97af6c285f84..cdd7981ea560 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1499,6 +1499,21 @@ static inline void hyp_cpu_pm_exit(void)
 }
 #endif
 
+static void init_cpu_logical_map(void)
+{
+   extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS];
+   int cpu;
+
+   /*
+* Copy the MPIDR <-> logical CPU ID mapping to hyp.
+* Only copy the set of online CPUs whose features have been chacked
+* against the finalized system capabilities. The hypervisor will not
+* allow any other CPUs from the `possible` set to boot.
+*/
+   for_each_online_cpu(cpu)
+   CHOOSE_NVHE_SYM(__cpu_logical_map)[cpu] = cpu_logical_map(cpu);
+}
+
 static int init_common_resources(void)
 {
return kvm_set_ipa_limit();
@@ -1677,6 +1692,8 @@ static int init_hyp_mode(void)
}
}
 
+   init_cpu_logical_map();
+
return 0;
 
 out_err:
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c 
b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c
index 7b0363b4857f..cbab0c6246e2 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c
@@ -8,6 +8,22 @@
 #include 
 #include 
 
+/*
+ * nVHE copy of data structures tracking available CPU cores.
+ * Only entries for CPUs that were online at KVM init are populated.
+ * Other CPUs should not be allowed to boot because their features were
+ * not checked against the finalized system capabilities.
+ */
+u64 __ro_after_init __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = 
INVALID_HWID };
+
+u64 cpu_logical_map(unsigned int cpu)
+{
+   if (cpu >= ARRAY_SIZE(__cpu_logical_map))
+   hyp_panic();
+
+   return __cpu_logical_map[cpu];
+}
+
 unsigned long __hyp_per_cpu_offset(unsigned int cpu)
 {
unsigned long *cpu_base_array;
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 10/24] kvm: arm64: Support per_cpu_ptr in nVHE hyp code

2020-11-16 Thread David Brazdil
When compiling with __KVM_NVHE_HYPERVISOR__ redefine per_cpu_offset() to
__hyp_per_cpu_offset() which looks up the base of the nVHE per-CPU
region of the given cpu and computes its offset from the
.hyp.data..percpu section.

This enables use of per_cpu_ptr() helpers in nVHE hyp code. Until now
only this_cpu_ptr() was supported by setting TPIDR_EL2.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/percpu.h   |  6 ++
 arch/arm64/kernel/image-vars.h|  3 +++
 arch/arm64/kvm/hyp/nvhe/Makefile  |  3 ++-
 arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 24 
 4 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/kvm/hyp/nvhe/hyp-smp.c

diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percpu.h
index 1599e17379d8..8f1661603b78 100644
--- a/arch/arm64/include/asm/percpu.h
+++ b/arch/arm64/include/asm/percpu.h
@@ -239,6 +239,12 @@ PERCPU_RET_OP(add, add, ldadd)
 #define this_cpu_cmpxchg_8(pcp, o, n)  \
_pcp_protect_return(cmpxchg_relaxed, pcp, o, n)
 
+#ifdef __KVM_NVHE_HYPERVISOR__
+extern unsigned long __hyp_per_cpu_offset(unsigned int cpu);
+#define __per_cpu_offset
+#define per_cpu_offset(cpu)__hyp_per_cpu_offset((cpu))
+#endif
+
 #include 
 
 /* Redefine macros for nVHE hyp under DEBUG_PREEMPT to avoid its dependencies. 
*/
diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
index c615b285ff5b..78a42a7cdb72 100644
--- a/arch/arm64/kernel/image-vars.h
+++ b/arch/arm64/kernel/image-vars.h
@@ -103,6 +103,9 @@ KVM_NVHE_ALIAS(gic_nonsecure_priorities);
 KVM_NVHE_ALIAS(__start___kvm_ex_table);
 KVM_NVHE_ALIAS(__stop___kvm_ex_table);
 
+/* Array containing bases of nVHE per-CPU memory regions. */
+KVM_NVHE_ALIAS(kvm_arm_hyp_percpu_base);
+
 #endif /* CONFIG_KVM */
 
 #endif /* __ARM64_KERNEL_IMAGE_VARS_H */
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
index ddde15fe85f2..2d842e009a40 100644
--- a/arch/arm64/kvm/hyp/nvhe/Makefile
+++ b/arch/arm64/kvm/hyp/nvhe/Makefile
@@ -6,7 +6,8 @@
 asflags-y := -D__KVM_NVHE_HYPERVISOR__
 ccflags-y := -D__KVM_NVHE_HYPERVISOR__
 
-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o 
hyp-main.o
+obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
+hyp-main.o hyp-smp.o
 obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
 ../fpsimd.o ../hyp-entry.o
 
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c 
b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c
new file mode 100644
index ..7b0363b4857f
--- /dev/null
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020 - Google LLC
+ * Author: David Brazdil 
+ */
+
+#include 
+#include 
+#include 
+
+unsigned long __hyp_per_cpu_offset(unsigned int cpu)
+{
+   unsigned long *cpu_base_array;
+   unsigned long this_cpu_base;
+   unsigned long elf_base;
+
+   if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base))
+   hyp_panic();
+
+   cpu_base_array = (unsigned long 
*)hyp_symbol_addr(kvm_arm_hyp_percpu_base);
+   this_cpu_base = kern_hyp_va(cpu_base_array[cpu]);
+   elf_base = (unsigned long)hyp_symbol_addr(__per_cpu_start);
+   return this_cpu_base - elf_base;
+}
-- 
2.29.2.299.gdc1121823c-goog



[PATCH v2 09/24] kvm: arm64: Add .hyp.data..ro_after_init ELF section

2020-11-16 Thread David Brazdil
Add rules for renaming the .data..ro_after_init ELF section in KVM nVHE
object files to .hyp.data..ro_after_init, linking it into the kernel
and mapping it in hyp at runtime.

The section is RW to the host, then mapped RO in hyp. The expectation is
that the host populates the variables in the section and they are never
changed by hyp afterwards.

Signed-off-by: David Brazdil 
---
 arch/arm64/include/asm/sections.h |  1 +
 arch/arm64/kernel/vmlinux.lds.S   | 10 ++
 arch/arm64/kvm/arm.c  |  8 
 arch/arm64/kvm/hyp/nvhe/hyp.lds.S |  1 +
 4 files changed, 20 insertions(+)

diff --git a/arch/arm64/include/asm/sections.h 
b/arch/arm64/include/asm/sections.h
index 3994169985ef..8ff579361731 100644
--- a/arch/arm64/include/asm/sections.h
+++ b/arch/arm64/include/asm/sections.h
@@ -11,6 +11,7 @@ extern char __alt_instructions[], __alt_instructions_end[];
 extern char __hibernate_exit_text_start[], __hibernate_exit_text_end[];
 extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[];
 extern char __hyp_text_start[], __hyp_text_end[];
+extern char __hyp_data_ro_after_init_start[], __hyp_data_ro_after_init_end[];
 extern char __idmap_text_start[], __idmap_text_end[];
 extern char __initdata_begin[], __initdata_end[];
 extern char __inittext_begin[], __inittext_end[];
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 1bda604f4c70..4382b5d0645d 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -30,6 +30,13 @@ jiffies = jiffies_64;
*(__kvm_ex_table)   \
__stop___kvm_ex_table = .;
 
+#define HYPERVISOR_DATA_SECTIONS   \
+   HYP_SECTION_NAME(.data..ro_after_init) : {  \
+   __hyp_data_ro_after_init_start = .; \
+   *(HYP_SECTION_NAME(.data..ro_after_init))   \
+   __hyp_data_ro_after_init_end = .;   \
+   }
+
 #define HYPERVISOR_PERCPU_SECTION  \
. = ALIGN(PAGE_SIZE);   \
HYP_SECTION_NAME(.data..percpu) : { \
@@ -37,6 +44,7 @@ jiffies = jiffies_64;
}
 #else /* CONFIG_KVM */
 #define HYPERVISOR_EXTABLE
+#define HYPERVISOR_DATA_SECTIONS
 #define HYPERVISOR_PERCPU_SECTION
 #endif
 
@@ -234,6 +242,8 @@ SECTIONS
_sdata = .;
RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
 
+   HYPERVISOR_DATA_SECTIONS
+
/*
 * Data written with the MMU off but read with the MMU on requires
 * cache lines to be invalidated, discarding up to a Cache Writeback
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 4838556920fb..97af6c285f84 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1620,6 +1620,14 @@ static int init_hyp_mode(void)
goto out_err;
}
 
+   err = create_hyp_mappings(kvm_ksym_ref(__hyp_data_ro_after_init_start),
+ kvm_ksym_ref(__hyp_data_ro_after_init_end),
+ PAGE_HYP_RO);
+   if (err) {
+   kvm_err("Cannot map .hyp.data..ro_after_init section\n");
+   goto out_err;
+   }
+
err = create_hyp_mappings(kvm_ksym_ref(__start_rodata),
  kvm_ksym_ref(__end_rodata), PAGE_HYP_RO);
if (err) {
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S 
b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
index bb2d986ff696..5d76ff2ba63e 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S
@@ -16,4 +16,5 @@ SECTIONS {
HYP_SECTION_NAME(.data..percpu) : {
PERCPU_INPUT(L1_CACHE_BYTES)
}
+   HYP_SECTION(.data..ro_after_init)
 }
-- 
2.29.2.299.gdc1121823c-goog



Re: drivers/accessibility/speakup/serialio.c:48:19: warning: variable 'quot' set but not used

2020-11-16 Thread Ben Hutchings
On Mon, 2020-11-16 at 21:33 +0100, Samuel Thibault wrote:
> Ben Hutchings, le lun. 16 nov. 2020 19:51:23 +, a ecrit:
> > On Mon, 2020-11-16 at 20:01 +0100, Samuel Thibault wrote:
> > > Perhaps we should rather use
> > > 
> > > depends on ISA || (X86 && COMPILE_TEST)
> > > 
> > > ?
> > > so that we have compile testing on x86 only (where the inb/outb macros
> > > always behave fine) to avoid such issues on other archs?
> > 
> > That seems reasonable though unusual.
> > 
> > > Or we tell the architecture maintainers to fix their out macros into
> > > consuming their parameters?
> > [...]
> > 
> > It does seem odd for parisc to define the I/O functions this way.  I
> > don't know if it's really a bug.
> 
> Sorry I wasn't clear: the problem here is when CONFIG_EISA is disabled,
> the eisa_in/out calls are replaced by BUG() stubs, and the stubs do not
> consume their input:

Yes, I did see that.

Ben.

> arch/parisc/include/asm/io.h
> 
> #if defined(CONFIG_PCI)
> extern void outb(unsigned char b, int addr);
> #elif defined(CONFIG_EISA)
> #define outb eisa_out8
> #else
> #define outb(x, y)BUG()
> #endif
> 
> Samuel
-- 
Ben Hutchings
Everything should be made as simple as possible, but not simpler.
  - Albert Einstein




signature.asc
Description: This is a digitally signed message part


[PATCH v6 0/3] Add support for VBUS detection

2020-11-16 Thread Guru Das Srinagesh
[REQUEST]

Thanks Rob for reviewing the dt patches.

Would it be possible for the maintainers and reviewers to review the code as
well? 

[COVER LETTER]

Add support to enable VBUS detection in the pm8941 extcon driver.

Changes from v5:
- Gathered Rob H's Acked-by for the dt-bindings patch.

Changes from v4:
- Drop addition of new compatible string in both bindings and driver.

Changes from v3:
- Split bindings into direct conversion of txt file, and addition of VBUS
  detection support.

Changes from v2:
- Fix YAML errors in dt binding document.

Changes from v1:
- Change bindings from txt to YAML.



Anirudh Ghayal (1):
  extcon: qcom-spmi: Add support for VBUS detection

Guru Das Srinagesh (2):
  bindings: pm8941-misc: Convert bindings to YAML
  bindings: pm8941-misc: Add support for VBUS detection

 .../bindings/extcon/qcom,pm8941-misc.txt   | 41 -
 .../bindings/extcon/qcom,pm8941-misc.yaml  | 62 ++
 drivers/extcon/extcon-qcom-spmi-misc.c | 99 +-
 3 files changed, 142 insertions(+), 60 deletions(-)
 delete mode 100644 
Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.txt
 create mode 100644 
Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH] samples/ftrace: mark my_tramp[12]? global

2020-11-16 Thread Steven Rostedt
On Mon, 16 Nov 2020 12:10:10 -0800
Sami Tolvanen  wrote:

> On Mon, Nov 16, 2020 at 8:39 AM Steven Rostedt  wrote:
> >
> > On Fri, 13 Nov 2020 10:34:14 -0800
> > Sami Tolvanen  wrote:
> >  
> > > my_tramp[12]? are declared as global functions in C, but they are not
> > > marked global in the inline assembly definition. This mismatch confuses
> > > Clang's Control-Flow Integrity checking. Fix the definitions by adding
> > > .globl.
> > >  
> >
> > Actually, since that function is not really global, would it work if you
> > removed the "extern" from the my_tramp declaration?  
> 
> Unfortunately not, removing the "extern" doesn't seem to change anything.
> 
> > In other words, is there a way to tell C that a function is declared in an
> > inline assembly block?  
> 
> I'm not sure if there's a way to tell C that a static function is
> declared in inline assembly. At least I couldn't find a way that would
> make the compiler happy.

I'm trying to see the warning. What option makes clang trigger a warning on
this?

>From user space, I'm just using the following file:

#include 

void my_direct_func(char *str)
{
printf("%s\n", str);
}

int test(char *str);

asm (
"   .pushsection.text, \"ax\", @progbits\n"
"   .type   test, @function\n"
"   test:"
"   pushq %rbp\n"
"   movq %rsp, %rbp\n"
"   pushq %rdi\n"
"   call my_direct_func\n"
"   popq %rdi\n"
"   leave\n"
"   ret\n"
"   .size   test, .-test\n"
"   .popsection\n"
);

int main (int argc, char **argv)
{
test("hello");
return 0;
}



[PATCH v6 2/3] bindings: pm8941-misc: Add support for VBUS detection

2020-11-16 Thread Guru Das Srinagesh
Add interrupt support for reporting VBUS detection status that can be
detected via a dedicated PMIC pin.

Signed-off-by: Anirudh Ghayal 
Signed-off-by: Guru Das Srinagesh 
Reviewed-by: Rob Herring 
---
 Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml 
b/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml
index e8eea83..6a9c96f 100644
--- a/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml
+++ b/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml
@@ -22,11 +22,14 @@ properties:
 maxItems: 1
 
   interrupts:
-maxItems: 1
+minItems: 1
+maxItems: 2
 
   interrupt-names:
+minItems: 1
 items:
   - const: usb_id
+  - const: usb_vbus
 
 required:
   - compatible
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v6 1/3] bindings: pm8941-misc: Convert bindings to YAML

2020-11-16 Thread Guru Das Srinagesh
Convert bindings from txt to YAML.

Signed-off-by: Guru Das Srinagesh 
Reviewed-by: Rob Herring 
---
 .../bindings/extcon/qcom,pm8941-misc.txt   | 41 ---
 .../bindings/extcon/qcom,pm8941-misc.yaml  | 59 ++
 2 files changed, 59 insertions(+), 41 deletions(-)
 delete mode 100644 
Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.txt
 create mode 100644 
Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml

diff --git a/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.txt 
b/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.txt
deleted file mode 100644
index 35383adb..000
--- a/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.txt
+++ /dev/null
@@ -1,41 +0,0 @@
-Qualcomm's PM8941 USB ID Extcon device
-
-Some Qualcomm PMICs have a "misc" module that can be used to detect when
-the USB ID pin has been pulled low or high.
-
-PROPERTIES
-
-- compatible:
-Usage: required
-Value type: 
-Definition: Should contain "qcom,pm8941-misc";
-
-- reg:
-Usage: required
-Value type: 
-Definition: Should contain the offset to the misc address space
-
-- interrupts:
-Usage: required
-Value type: 
-Definition: Should contain the usb id interrupt
-
-- interrupt-names:
-Usage: required
-Value type: 
-Definition: Should contain the string "usb_id" for the usb id interrupt
-
-Example:
-
-   pmic {
-   usb_id: misc@900 {
-   compatible = "qcom,pm8941-misc";
-   reg = <0x900>;
-   interrupts = <0x0 0x9 0 IRQ_TYPE_EDGE_BOTH>;
-   interrupt-names = "usb_id";
-   };
-   }
-
-   usb-controller {
-   extcon = <_id>;
-   };
diff --git a/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml 
b/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml
new file mode 100644
index 000..e8eea83
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/qcom,pm8941-misc.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/extcon/qcom,pm8941-misc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies, Inc. PM8941 USB ID Extcon device
+
+maintainers:
+  - Guru Das Srinagesh 
+
+description: |
+  Some Qualcomm PMICs have a "misc" module that can be used to detect when
+  the USB ID pin has been pulled low or high.
+
+properties:
+  compatible:
+items:
+  - const: qcom,pm8941-misc
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  interrupt-names:
+items:
+  - const: usb_id
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+
+pmic {
+#address-cells = <1>;
+#size-cells = <0>;
+interrupt-controller;
+#interrupt-cells = <4>;
+
+usb_id: misc@900 {
+compatible = "qcom,pm8941-misc";
+reg = <0x900>;
+interrupts = <0x0 0x9 0 IRQ_TYPE_EDGE_BOTH>;
+interrupt-names = "usb_id";
+};
+};
+
+usb-controller {
+   extcon = <_id>;
+};
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v6 3/3] extcon: qcom-spmi: Add support for VBUS detection

2020-11-16 Thread Guru Das Srinagesh
From: Anirudh Ghayal 

VBUS can be detected via a dedicated PMIC pin. Add support
for reporting the VBUS status.

Signed-off-by: Anirudh Ghayal 
Signed-off-by: Kavya Nunna 
Signed-off-by: Guru Das Srinagesh 
---
 drivers/extcon/extcon-qcom-spmi-misc.c | 99 +++---
 1 file changed, 80 insertions(+), 19 deletions(-)

diff --git a/drivers/extcon/extcon-qcom-spmi-misc.c 
b/drivers/extcon/extcon-qcom-spmi-misc.c
index 6b836ae..9e8ccfb 100644
--- a/drivers/extcon/extcon-qcom-spmi-misc.c
+++ b/drivers/extcon/extcon-qcom-spmi-misc.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /**
  * extcon-qcom-spmi-misc.c - Qualcomm USB extcon driver to support USB ID
- * detection based on extcon-usb-gpio.c.
+ * and VBUS detection based on extcon-usb-gpio.c.
  *
  * Copyright (C) 2016 Linaro, Ltd.
  * Stephen Boyd 
@@ -21,30 +21,56 @@
 
 struct qcom_usb_extcon_info {
struct extcon_dev *edev;
-   int irq;
+   int id_irq;
+   int vbus_irq;
struct delayed_work wq_detcable;
unsigned long debounce_jiffies;
 };
 
 static const unsigned int qcom_usb_extcon_cable[] = {
+   EXTCON_USB,
EXTCON_USB_HOST,
EXTCON_NONE,
 };
 
 static void qcom_usb_extcon_detect_cable(struct work_struct *work)
 {
-   bool id;
+   bool state = false;
int ret;
+   union extcon_property_value val;
struct qcom_usb_extcon_info *info = container_of(to_delayed_work(work),
struct qcom_usb_extcon_info,
wq_detcable);
 
-   /* check ID and update cable state */
-   ret = irq_get_irqchip_state(info->irq, IRQCHIP_STATE_LINE_LEVEL, );
-   if (ret)
-   return;
+   if (info->id_irq > 0) {
+   /* check ID and update cable state */
+   ret = irq_get_irqchip_state(info->id_irq,
+   IRQCHIP_STATE_LINE_LEVEL, );
+   if (ret)
+   return;
+
+   if (!state) {
+   val.intval = true;
+   extcon_set_property(info->edev, EXTCON_USB_HOST,
+   EXTCON_PROP_USB_SS, val);
+   }
+   extcon_set_state_sync(info->edev, EXTCON_USB_HOST, !state);
+   }
 
-   extcon_set_state_sync(info->edev, EXTCON_USB_HOST, !id);
+   if (info->vbus_irq > 0) {
+   /* check VBUS and update cable state */
+   ret = irq_get_irqchip_state(info->vbus_irq,
+   IRQCHIP_STATE_LINE_LEVEL, );
+   if (ret)
+   return;
+
+   if (state) {
+   val.intval = true;
+   extcon_set_property(info->edev, EXTCON_USB,
+   EXTCON_PROP_USB_SS, val);
+   }
+   extcon_set_state_sync(info->edev, EXTCON_USB, state);
+   }
 }
 
 static irqreturn_t qcom_usb_irq_handler(int irq, void *dev_id)
@@ -79,21 +105,48 @@ static int qcom_usb_extcon_probe(struct platform_device 
*pdev)
return ret;
}
 
+   ret = extcon_set_property_capability(info->edev,
+   EXTCON_USB, EXTCON_PROP_USB_SS);
+   ret |= extcon_set_property_capability(info->edev,
+   EXTCON_USB_HOST, EXTCON_PROP_USB_SS);
+   if (ret) {
+   dev_err(dev, "failed to register extcon props rc=%d\n",
+   ret);
+   return ret;
+   }
+
info->debounce_jiffies = msecs_to_jiffies(USB_ID_DEBOUNCE_MS);
INIT_DELAYED_WORK(>wq_detcable, qcom_usb_extcon_detect_cable);
 
-   info->irq = platform_get_irq_byname(pdev, "usb_id");
-   if (info->irq < 0)
-   return info->irq;
+   info->id_irq = platform_get_irq_byname(pdev, "usb_id");
+   if (info->id_irq > 0) {
+   ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+   qcom_usb_irq_handler,
+   IRQF_TRIGGER_RISING |
+   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+   pdev->name, info);
+   if (ret < 0) {
+   dev_err(dev, "failed to request handler for ID IRQ\n");
+   return ret;
+   }
+   }
 
-   ret = devm_request_threaded_irq(dev, info->irq, NULL,
+   info->vbus_irq = platform_get_irq_byname(pdev, "usb_vbus");
+   if (info->vbus_irq > 0) {
+   ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL,
qcom_usb_irq_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
 

Re: [PATCH v4 06/17] PCI: add SIOV and IMS capability detection

2020-11-16 Thread Thomas Gleixner
On Mon, Nov 16 2020 at 14:02, Jason Gunthorpe wrote:
> On Mon, Nov 16, 2020 at 06:56:33PM +0100, Thomas Gleixner wrote:
>> On Mon, Nov 16 2020 at 11:46, Jason Gunthorpe wrote:
>> 
>> > On Mon, Nov 16, 2020 at 07:31:49AM +, Tian, Kevin wrote:
>> >
>> >> > The subdevices require PASID & IOMMU in native, but inside the guest 
>> >> > there
>> >> > is no
>> >> > need for IOMMU unless you want to build SVM on top. subdevices work
>> >> > without
>> >> > any vIOMMU or hypercall in the guest. Only because they look like normal
>> >> > PCI devices we could map interrupts to legacy MSIx.
>> >> 
>> >> Guest managed subdevices on PF/VF requires vIOMMU. 
>> >
>> > Why? I've never heard we need vIOMMU for our existing SRIOV flows in
>> > VMs??
>> 
>> Handing PF/VF into the guest does not require it.
>> 
>> But if the PF/VF driver in the guest wants to create and manage the
>> magic mdev subdevices which require PASID support then you surely need
>> it.
>
> 'magic mdevs' are only one reason to use IMS in a guest. On mlx5 we
> might want to use IMS for VPDA devices. mlx5 can spawn a VDPA device
> in a guest, against a 'ADI', without ever requiring an IOMMU to do it.
>
> We don't even need IOMMU in the hypervisor to create the ADI, mlx5 has
> an internal secure IOMMU that can be used instead of the platform
> IOMMU.
>
> Not saying this is a major use case, or a reason not to link things to
> IOMMU detection, but lets be clear that a hard need for IOMMU is a
> another IDXD thing, not general.

Fair enough.

Thanks,

tglx


Re: linux-next: build warning after merge of the ftrace tree

2020-11-16 Thread Steven Rostedt
On Mon, 16 Nov 2020 13:29:29 -0700
Jonathan Corbet  wrote:

> > Would something like the below work? I think I fixed the other places with
> > issues and for consistency, replaced the ".. code-block:: c" with just "::"
> > usage throughout the file.  
> 
> That will work.  It will also have the effect of removing C syntax
> highlighting from the formatted output; that is fine with me, but others
> are more attached to it.

Is there a way to set a default highlighting to be C syntax?

Otherwise I'll just put it back and add the code-block statements back in,
even though there are those that will complain about the added mark up ;-)

-- Steve


Re: [PATCH V3 05/10] x86/entry: Pass irqentry_state_t by reference

2020-11-16 Thread Thomas Gleixner
Ira,

On Mon, Nov 16 2020 at 10:49, Ira Weiny wrote:
> On Sun, Nov 15, 2020 at 07:58:52PM +0100, Thomas Gleixner wrote:
>> > Currently struct irqentry_state_t only contains a single bool value
>> > which makes passing it by value is reasonable.  However, future patches
>> > propose to add information to this struct, for example the PKRS
>> > register/thread state.
>> >
>> > Adding information to irqentry_state_t makes passing by value less
>> > efficient.  Therefore, change the entry/exit calls to pass irq_state by
>> > reference.
>> 
>> The PKRS muck needs to add an u32 to that struct. So how is that a
>> problem?
>
> There are more fields to be added for the kmap/pmem support.  So this will be
> needed eventually.  Even though it is not strictly necessary in the next 
> patch.

if you folks could start to write coherent changelogs with proper
explanations why something is needed and why it's going beyond the
immediate use case in the next patch, then getting stuff sorted would be
way easier.

Sorry my crystalball got lost years ago and I'm just not able to keep up
with the flurry of patch sets which have dependencies in one way or the
other.

>> The resulting struct still fits into 64bit which is by far more
>> efficiently passed by value than by reference. So which problem are you
>> solving here?
>
> I'm getting ahead of myself a bit.  I will be adding more fields for the
> kmap/pmem tracking.
>
> Would you accept just a clean up for the variable names in this patch?  I 
> could
> then add the pass by reference when I add the new fields later.  Or would an
> update to the commit message be ok to land this now?

Can you provide a coherent explanation for the full set of things which
needs to be added here first please?

Thanks,

tglx


Re: [PATCH] bpf: don't fail kmalloc while releasing raw_tp

2020-11-16 Thread Mathieu Desnoyers
- On Nov 16, 2020, at 12:19 PM, rostedt rost...@goodmis.org wrote:

> On Sat, 14 Nov 2020 21:52:55 -0800
> Matt Mullins  wrote:
> 
>> bpf_link_free is always called in process context, including from a
>> workqueue and from __fput.  Neither of these have the ability to
>> propagate an -ENOMEM to the caller.
>> 
> 
> Hmm, I think the real fix is to not have unregistering a tracepoint probe
> fail because of allocation. We are removing a probe, perhaps we could just
> inject NULL pointer that gets checked via the DO_TRACE loop?
> 
> I bet failing an unregister because of an allocation failure causes
> problems elsewhere than just BPF.
> 
> Mathieu,
> 
> Can't we do something that would still allow to unregister a probe even if
> a new probe array fails to allocate? We could kick off a irq work to try to
> clean up the probe at a later time, but still, the unregister itself should
> not fail due to memory failure.

Currently, the fast path iteration looks like:

struct tracepoint_func *it_func_ptr;
void *it_func;

it_func_ptr =   \
rcu_dereference_raw((&__tracepoint_##_name)->funcs); \
do {\
it_func = (it_func_ptr)->func;  \
__data = (it_func_ptr)->data;   \
((void(*)(void *, proto))(it_func))(__data, args); \
} while ((++it_func_ptr)->func); 

So we RCU dereference the array, and iterate on the array until we find a NULL
func. So you could not use NULL to skip items, but you could perhaps reserve
a (void *)0x1UL tombstone for this.

It should ideally be an unlikely branch, and it would be good to benchmark the
change when multiple tracing probes are attached to figure out whether the
overhead is significant when tracing is enabled.

I wonder whether we really mind that much about using slightly more memory
than required after a failed reallocation due to ENOMEM. Perhaps the irq work
is not even needed. Chances are that the irq work would fail again and again if
it's in low memory conditions. So maybe it's better to just keep the tombstone
in place until the next successful callback array reallocation.

Thoughts ?

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


Re: [PATCH 32/42] drm/ttm/ttm_tt: Demote kernel-doc header format abuses

2020-11-16 Thread Christian König

Am 16.11.20 um 18:41 schrieb Lee Jones:

Fixes the following W=1 kernel build warning(s):

  drivers/gpu/drm/ttm/ttm_tt.c:45: warning: Function parameter or member 'bo' 
not described in 'ttm_tt_create'
  drivers/gpu/drm/ttm/ttm_tt.c:45: warning: Function parameter or member 
'zero_alloc' not described in 'ttm_tt_create'
  drivers/gpu/drm/ttm/ttm_tt.c:83: warning: Function parameter or member 'ttm' 
not described in 'ttm_tt_alloc_page_directory'


Couldn't we rather describe the missing parameters? Shouldn't be much work.

Regards,
Christian.



Cc: Christian Koenig 
Cc: Huang Rui 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-de...@lists.freedesktop.org
Signed-off-by: Lee Jones 
---
  drivers/gpu/drm/ttm/ttm_tt.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index cfd633c7e7643..da9eeffe0c6d7 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -38,7 +38,7 @@
  #include 
  #include 
  
-/**

+/*
   * Allocates a ttm structure for the given BO.
   */
  int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc)
@@ -73,7 +73,7 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool 
zero_alloc)
return 0;
  }
  
-/**

+/*
   * Allocates storage for pointers to the pages that back the ttm.
   */
  static int ttm_tt_alloc_page_directory(struct ttm_tt *ttm)




Re: [PATCH 33/42] drm/ttm/ttm_range_manager: Demote non-conformant kernel-doc header

2020-11-16 Thread Christian König

Am 16.11.20 um 18:41 schrieb Lee Jones:

Fixes the following W=1 kernel build warning(s):

  drivers/gpu/drm/ttm/ttm_range_manager.c:46: warning: cannot understand 
function prototype: 'struct ttm_range_manager '

Cc: Christian Koenig 
Cc: Huang Rui 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: dri-de...@lists.freedesktop.org
Signed-off-by: Lee Jones 


Reviewed-by: Christian König 


---
  drivers/gpu/drm/ttm/ttm_range_manager.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c 
b/drivers/gpu/drm/ttm/ttm_range_manager.c
index ea77919569a2e..e0952444cea93 100644
--- a/drivers/gpu/drm/ttm/ttm_range_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_range_manager.c
@@ -37,7 +37,7 @@
  #include 
  #include 
  
-/**

+/*
   * Currently we use a spinlock for the lock, but a mutex *may* be
   * more appropriate to reduce scheduling latency if the range manager
   * ends up with very fragmented allocation patterns.




Re: drivers/accessibility/speakup/serialio.c:48:19: warning: variable 'quot' set but not used

2020-11-16 Thread Samuel Thibault
Ben Hutchings, le lun. 16 nov. 2020 19:51:23 +, a ecrit:
> On Mon, 2020-11-16 at 20:01 +0100, Samuel Thibault wrote:
> > Perhaps we should rather use
> > 
> > depends on ISA || (X86 && COMPILE_TEST)
> > 
> > ?
> > so that we have compile testing on x86 only (where the inb/outb macros
> > always behave fine) to avoid such issues on other archs?
> 
> That seems reasonable though unusual.
> 
> > Or we tell the architecture maintainers to fix their out macros into
> > consuming their parameters?
> [...]
> 
> It does seem odd for parisc to define the I/O functions this way.  I
> don't know if it's really a bug.

Sorry I wasn't clear: the problem here is when CONFIG_EISA is disabled,
the eisa_in/out calls are replaced by BUG() stubs, and the stubs do not
consume their input:

arch/parisc/include/asm/io.h

#if defined(CONFIG_PCI)
extern void outb(unsigned char b, int addr);
#elif defined(CONFIG_EISA)
#define outb eisa_out8
#else
#define outb(x, y)  BUG()
#endif

Samuel


Re: [PATCH 31/42] drm/ttm/ttm_bo: Fix one function header - demote lots of kernel-doc abuses

2020-11-16 Thread Christian König

Am 16.11.20 um 18:41 schrieb Lee Jones:

Fixes the following W=1 kernel build warning(s):

  drivers/gpu/drm/ttm/ttm_bo.c:51: warning: Function parameter or member 
'ttm_global_mutex' not described in 'DEFINE_MUTEX'
  drivers/gpu/drm/ttm/ttm_bo.c:286: warning: Function parameter or member 'bo' 
not described in 'ttm_bo_cleanup_memtype_use'
  drivers/gpu/drm/ttm/ttm_bo.c:359: warning: Function parameter or member 'bo' 
not described in 'ttm_bo_cleanup_refs'
  drivers/gpu/drm/ttm/ttm_bo.c:359: warning: Function parameter or member 
'interruptible' not described in 'ttm_bo_cleanup_refs'
  drivers/gpu/drm/ttm/ttm_bo.c:359: warning: Function parameter or member 
'no_wait_gpu' not described in 'ttm_bo_cleanup_refs'
  drivers/gpu/drm/ttm/ttm_bo.c:359: warning: Function parameter or member 
'unlock_resv' not described in 'ttm_bo_cleanup_refs'
  drivers/gpu/drm/ttm/ttm_bo.c:424: warning: Function parameter or member 
'bdev' not described in 'ttm_bo_delayed_delete'
  drivers/gpu/drm/ttm/ttm_bo.c:424: warning: Function parameter or member 
'remove_all' not described in 'ttm_bo_delayed_delete'
  drivers/gpu/drm/ttm/ttm_bo.c:635: warning: Function parameter or member 'bo' 
not described in 'ttm_bo_evict_swapout_allowable'
  drivers/gpu/drm/ttm/ttm_bo.c:635: warning: Function parameter or member 'ctx' 
not described in 'ttm_bo_evict_swapout_allowable'
  drivers/gpu/drm/ttm/ttm_bo.c:635: warning: Function parameter or member 
'locked' not described in 'ttm_bo_evict_swapout_allowable'
  drivers/gpu/drm/ttm/ttm_bo.c:635: warning: Function parameter or member 
'busy' not described in 'ttm_bo_evict_swapout_allowable'
  drivers/gpu/drm/ttm/ttm_bo.c:769: warning: Function parameter or member 'bo' 
not described in 'ttm_bo_add_move_fence'
  drivers/gpu/drm/ttm/ttm_bo.c:769: warning: Function parameter or member 'man' 
not described in 'ttm_bo_add_move_fence'
  drivers/gpu/drm/ttm/ttm_bo.c:769: warning: Function parameter or member 'mem' 
not described in 'ttm_bo_add_move_fence'
  drivers/gpu/drm/ttm/ttm_bo.c:769: warning: Function parameter or member 
'no_wait_gpu' not described in 'ttm_bo_add_move_fence'
  drivers/gpu/drm/ttm/ttm_bo.c:806: warning: Function parameter or member 'bo' 
not described in 'ttm_bo_mem_force_space'
  drivers/gpu/drm/ttm/ttm_bo.c:806: warning: Function parameter or member 
'place' not described in 'ttm_bo_mem_force_space'
  drivers/gpu/drm/ttm/ttm_bo.c:806: warning: Function parameter or member 'mem' 
not described in 'ttm_bo_mem_force_space'
  drivers/gpu/drm/ttm/ttm_bo.c:806: warning: Function parameter or member 'ctx' 
not described in 'ttm_bo_mem_force_space'
  drivers/gpu/drm/ttm/ttm_bo.c:872: warning: Function parameter or member 'bo' 
not described in 'ttm_bo_mem_space'
  drivers/gpu/drm/ttm/ttm_bo.c:872: warning: Function parameter or member 
'placement' not described in 'ttm_bo_mem_space'
  drivers/gpu/drm/ttm/ttm_bo.c:872: warning: Function parameter or member 'mem' 
not described in 'ttm_bo_mem_space'
  drivers/gpu/drm/ttm/ttm_bo.c:872: warning: Function parameter or member 'ctx' 
not described in 'ttm_bo_mem_space'
  drivers/gpu/drm/ttm/ttm_bo.c:1387: warning: Function parameter or member 
'ctx' not described in 'ttm_bo_swapout'

Cc: Christian Koenig 
Cc: Huang Rui 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: Sumit Semwal 
Cc: dri-de...@lists.freedesktop.org
Cc: linux-me...@vger.kernel.org
Cc: linaro-mm-...@lists.linaro.org
Signed-off-by: Lee Jones 


Reviewed-by: Christian König 

Going to pick that one up for upstreaming.

Thanks,
Christian.


---
  drivers/gpu/drm/ttm/ttm_bo.c | 23 ---
  1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index e6bcbfe530ecc..9a03c7834b1ed 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -45,7 +45,7 @@
  
  static void ttm_bo_global_kobj_release(struct kobject *kobj);
  
-/**

+/*
   * ttm_global_mutex - protecting the global BO state
   */
  DEFINE_MUTEX(ttm_global_mutex);
@@ -278,7 +278,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object 
*bo,
return ret;
  }
  
-/**

+/*
   * Call bo::reserved.
   * Will release GPU memory type usage on destruction.
   * This is the place to put in driver specific hooks to release
@@ -352,9 +352,10 @@ static void ttm_bo_flush_all_fences(struct 
ttm_buffer_object *bo)
   * Must be called with lru_lock and reservation held, this function
   * will drop the lru lock and optionally the reservation lock before 
returning.
   *
- * @interruptible Any sleeps should occur interruptibly.
- * @no_wait_gpu   Never wait for gpu. Return -EBUSY instead.
- * @unlock_resv   Unlock the reservation lock as well.
+ * @bo:The buffer object to clean-up
+ * @interruptible: Any sleeps should occur interruptibly.
+ * @no_wait_gpu:   Never wait for gpu. Return -EBUSY instead.
+ * @unlock_resv:   Unlock the reservation lock as well.
   

Re: [PATCH 1/3] x86/quirks: Scan all busses for early PCI quirks

2020-11-16 Thread Guilherme G. Piccoli
First of all, thanks everybody for the great insights/discussion! This
thread ended-up being a great learning for (at least) me.

Given the big amount of replies and intermixed comments, I wouldn't be
able to respond inline to all, so I'll try another approach below.


>From Bjorn:
"I think [0] proposes using early_quirks() to disable MSIs at boot-time.
That doesn't seem like a robust solution because (a) the problem affects
all arches but early_quirks() is x86-specific and (b) even on x86
early_quirks() only works for PCI segment 0 because it relies on the
0xCF8/0xCFC I/O ports."

Ah. I wasn't aware of that limitation, I thought enhancing the
early_quirks() search to go through all buses would fix that, thanks for
the clarification! And again, worth to clarify that this is not a
problem affecting all arches _in practice_ - PowerPC for example has the
FW primitives allowing a powerful PCI controller (out-of-band) reset,
preventing this kind of issue usually.

[0]
https://lore.kernel.org/linux-pci/20181018183721.27467-1-gpicc...@canonical.com


>From Bjorn:
"A crash_device_shutdown() could do something at the host bridge level
if that's possible, or reset/disable bus mastering/disable MSI/etc on
individual PCI devices if necessary."

>From Lukas:
"Guilherme's original patches from 2018 iterate over all 256 PCI buses.
That might impact boot time negatively.  The reason he has to do that is
because the crashing kernel doesn't know which devices exist and which
have interrupts enabled.  However the crashing kernel has that
information.  It should either disable interrupts itself or pass the
necessary information to the crashing kernel as setup_data or whatever.

Guilherme's patches add a "clearmsi" command line parameter.  I guess
the idea is that the parameter is always passed to the crash kernel but
the patches don't do that, which seems odd."

Very good points Lukas, thanks! The reason of not adding the clearmsi
thing as a default kdump procedure is kinda related to your first point:
it impacts a bit boot-time, also it's an additional logic in the kdump
kernel, which we know is (sometimes) the last resort in gathering
additional data to debug a potentially complex issue. That said, I'd not
like to enforce this kind of "policy" to everybody, so my implementation
relies on having it as a parameter, and the kdump userspace counter-part
could then have a choice in adding or not such mechanism to the kdump
kernel parameter list.

About passing the data to next kernel, this is very interesting, we
could do something like that either through setup_data (as you said) or
using a new proposal, the PKRAM thing [a].
This way we wouldn't need a crash_device_shutdown(), but instead when
kernel is loading a crash kernel (through kexec -p) we can collect all
the necessary information that'll be passed to the crash kernel
(obviously that if we are collecting PCI topology information, we need
callbacks in the PCI hotplug add/del path to update this information).

[a]
https://lore.kernel.org/lkml/1588812129-8596-1-git-send-email-anthony.yzn...@oracle.com/

Below, inline reply to Eric's last message.


On 15/11/2020 17:46, Eric W. Biederman wrote:
>> [...]
>> An MSI interrupt is a (DMA) write to the local APIC base address
>> 0xfeex which has the target CPU and control bits encoded in the
>> lower bits. The written data is the vector and more control bits.
>>
>> The only way to stop that is to shut it up at the PCI device level.
> 
> Or to write to magic chipset registers that will stop transforming DMA
> writes to 0xfeex into x86 interrupts.  With an IOMMU I know x86 has
> such registers (because the point of the IOMMU is to limit the problems
> rogue devices can cause).  Without an IOMMU I don't know if x86 has any
> such registers.  I remember that other platforms have an interrupt
> controller that does provide some level of control.  That x86 does not
> is what makes this an x86 specific problem.
> [...]
> Looking at patch 3/3 what this patchset does is an early disable of
> of the msi registers.  Which is mostly reasonable.  Especially as has
> been pointed out the only location the x86 vector and x86 cpu can
> be found is in the msi configuration registers.
> 
> That also seems reasonable.  But Bjorn's concern about not finding all
> devices in all domains does seem real.
> [...]
> So if we can safely and reliably disable DMA and MSI at the generic PCI
> device level during boot up I am all for it.
> 
> 
> How difficult would it be to tell the IOMMUs to stop passing traffic
> through in an early pci quirk?  The problem setup was apparently someone
> using the device directly from a VM.  So I presume there is an IOMMU
> in that configuration.

This is a good idea I think - we considered something like that in
theory while working the problem back in 2018, but given I'm even less
expert in IOMMU that I already am in PCI, the option was to go with the
PCI approach. And you are right, the original problem is a 

Re: [PATCH 37/43] drm/radeon/ci_dpm: Move 'si_*()'s prototypes to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/si_dpm.c:3802:4: warning: no previous prototype for 
> ‘si_get_ddr3_mclk_frequency_ratio’ [-Wmissing-prototypes]
>  3802 | u8 si_get_ddr3_mclk_frequency_ratio(u32 memory_clock)
>  | ^~~~
>  drivers/gpu/drm/radeon/si_dpm.c:3815:4: warning: no previous prototype for 
> ‘si_get_mclk_frequency_ratio’ [-Wmissing-prototypes]
>  3815 | u8 si_get_mclk_frequency_ratio(u32 memory_clock, bool strobe_mode)
>  | ^~~
>  drivers/gpu/drm/radeon/si_dpm.c:3897:6: warning: no previous prototype for 
> ‘si_trim_voltage_table_to_fit_state_table’ [-Wmissing-prototypes]
>  3897 | void si_trim_voltage_table_to_fit_state_table(struct radeon_device 
> *rdev,
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/ci_dpm.c | 6 +-
>  drivers/gpu/drm/radeon/si_dpm.h | 5 +
>  2 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/ci_dpm.c b/drivers/gpu/drm/radeon/ci_dpm.c
> index a9fc0a552736c..0dfb0ed9af89d 100644
> --- a/drivers/gpu/drm/radeon/ci_dpm.c
> +++ b/drivers/gpu/drm/radeon/ci_dpm.c
> @@ -33,6 +33,7 @@
>  #include "radeon.h"
>  #include "radeon_asic.h"
>  #include "radeon_ucode.h"
> +#include "si_dpm.h"
>
>  #define MC_CG_ARB_FREQ_F0   0x0a
>  #define MC_CG_ARB_FREQ_F1   0x0b
> @@ -153,11 +154,6 @@ static const struct ci_pt_config_reg didt_config_ci[] =
>  extern u8 rv770_get_memory_module_index(struct radeon_device *rdev);
>  extern int ni_copy_and_switch_arb_sets(struct radeon_device *rdev,
>u32 arb_freq_src, u32 arb_freq_dest);
> -extern u8 si_get_ddr3_mclk_frequency_ratio(u32 memory_clock);
> -extern u8 si_get_mclk_frequency_ratio(u32 memory_clock, bool strobe_mode);
> -extern void si_trim_voltage_table_to_fit_state_table(struct radeon_device 
> *rdev,
> -u32 max_voltage_steps,
> -struct 
> atom_voltage_table *voltage_table);
>  static int ci_get_std_voltage_value_sidd(struct radeon_device *rdev,
>  struct atom_voltage_table_entry 
> *voltage_table,
>  u16 *std_voltage_hi_sidd, u16 
> *std_voltage_lo_sidd);
> diff --git a/drivers/gpu/drm/radeon/si_dpm.h b/drivers/gpu/drm/radeon/si_dpm.h
> index 1032a68be792b..aa857906ef93d 100644
> --- a/drivers/gpu/drm/radeon/si_dpm.h
> +++ b/drivers/gpu/drm/radeon/si_dpm.h
> @@ -234,5 +234,10 @@ struct si_power_info {
>  #define SISLANDS_CGULVPARAMETER_DFLT0x00040035
>  #define SISLANDS_CGULVCONTROL_DFLT  0x1f007550
>
> +u8 si_get_ddr3_mclk_frequency_ratio(u32 memory_clock);
> +u8 si_get_mclk_frequency_ratio(u32 memory_clock, bool strobe_mode);
> +void si_trim_voltage_table_to_fit_state_table(struct radeon_device *rdev,
> + u32 max_voltage_steps,
> + struct atom_voltage_table 
> *voltage_table);
>
>  #endif
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v4 bpf-next 3/5] kbuild: build kernel module BTFs if BTF is enabled and pahole supports it

2020-11-16 Thread Andrii Nakryiko
On Mon, Nov 16, 2020 at 11:55 AM Allan, Bruce W  wrote:
>
> > -Original Message-
> > From: Song Liu 
> > Sent: Tuesday, November 10, 2020 5:05 PM
> > To: Andrii Nakryiko 
> > Cc: bpf ; Networking ;
> > Starovoitov, Alexei ; Daniel Borkmann ;
> > Kernel Team ; open list  > ker...@vger.kernel.org>; raf...@kernel.org; j...@kernel.org; Arnaldo
> > Carvalho de Melo ; Greg Kroah-Hartman
> > ; Masahiro Yamada
> > 
> > Subject: Re: [PATCH v4 bpf-next 3/5] kbuild: build kernel module BTFs if 
> > BTF is
> > enabled and pahole supports it
> >
> >
> >
> > > On Nov 9, 2020, at 5:19 PM, Andrii Nakryiko  wrote:
> >
> > [...]
> >
> > > SPLIT BTF
> > > =
> > >
> > > $ for f in $(find . -name '*.ko'); do size -A -d $f | grep BTF | awk 
> > > '{print $2}';
> > done | awk '{ s += $1 } END { print s }'
> > > 5194047
> > >
> > > $ for f in $(find . -name '*.ko'); do printf "%s %d\n" $f $(size -A -d $f 
> > > | grep
> > BTF | awk '{print $2}'); done | sort -nr -k2 | head -n10
> > > ./drivers/gpu/drm/i915/i915.ko 293206
> > > ./drivers/gpu/drm/radeon/radeon.ko 282103
> > > ./fs/xfs/xfs.ko 222150
> > > ./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko 198503
> > > ./drivers/infiniband/hw/mlx5/mlx5_ib.ko 198356
> > > ./drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko 113444
> > > ./fs/cifs/cifs.ko 109379
> > > ./arch/x86/kvm/kvm.ko 100225
> > > ./drivers/gpu/drm/drm.ko 94827
> > > ./drivers/infiniband/core/ib_core.ko 91188
> > >
> > > Cc: Masahiro Yamada 
> > > Signed-off-by: Andrii Nakryiko 
> >
> > Acked-by: Song Liu 
>
> This change, commit 5f9ae91f7c0d ("kbuild: Build kernel module BTFs if BTF is 
> enabled and pahole
> supports it") currently in net-next, linux-next, etc. breaks the use-case of 
> compiling only a specific
> kernel module (both in-tree and out-of-tree, e.g. 'make 
> M=drivers/net/ethernet/intel/ice') after
> first doing a 'make modules_prepare'.  Previously, that use-case would result 
> in a warning noting
> "Symbol info of vmlinux is missing. Unresolved symbol check will be entirely 
> skipped" but now it
> errors out after noting "No rule to make target 'vmlinux', needed by 
> '<...>.ko'.  Stop."
>
> Is that intentional?

I wasn't aware of such a use pattern, so definitely not intentional.
But vmlinux is absolutely necessary to generate the module BTF. So I'm
wondering what's the proper fix here? Leave it as is (that error
message is actually surprisingly descriptive, btw)? Force vmlinux
build? Or skip BTF generation for that module?

>
> Thanks,
> Bruce.


Re: [PATCH 34/43] drm/radeon/evergreen: Move 'si_get_csb_*()'s prototypes to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:37 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/si.c:5678:5: warning: no previous prototype for 
> ‘si_get_csb_size’ [-Wmissing-prototypes]
>  5678 | u32 si_get_csb_size(struct radeon_device *rdev)
>  | ^~~
>  drivers/gpu/drm/radeon/si.c:5710:6: warning: no previous prototype for 
> ‘si_get_csb_buffer’ [-Wmissing-prototypes]
>  5710 | void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 
> *buffer)
>  | ^
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/evergreen.c | 3 +--
>  drivers/gpu/drm/radeon/si.h| 2 ++
>  2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/evergreen.c 
> b/drivers/gpu/drm/radeon/evergreen.c
> index 8fb0b8c3db5b5..4575e448e59df 100644
> --- a/drivers/gpu/drm/radeon/evergreen.c
> +++ b/drivers/gpu/drm/radeon/evergreen.c
> @@ -41,6 +41,7 @@
>  #include "radeon_asic.h"
>  #include "radeon_audio.h"
>  #include "radeon_ucode.h"
> +#include "si.h"
>
>  #define DC_HPDx_CONTROL(x)(DC_HPD1_CONTROL + (x * 0xc))
>  #define DC_HPDx_INT_CONTROL(x)(DC_HPD1_INT_CONTROL + (x * 0xc))
> @@ -218,8 +219,6 @@ void evergreen_pcie_gen2_enable(struct radeon_device 
> *rdev);
>  void evergreen_program_aspm(struct radeon_device *rdev);
>  void cik_init_cp_pg_table(struct radeon_device *rdev);
>
> -extern u32 si_get_csb_size(struct radeon_device *rdev);
> -extern void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 
> *buffer);
>  extern u32 cik_get_csb_size(struct radeon_device *rdev);
>  extern void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 
> *buffer);
>
> diff --git a/drivers/gpu/drm/radeon/si.h b/drivers/gpu/drm/radeon/si.h
> index f483a64d17050..310c58376f927 100644
> --- a/drivers/gpu/drm/radeon/si.h
> +++ b/drivers/gpu/drm/radeon/si.h
> @@ -32,5 +32,7 @@ u32 si_gpu_check_soft_reset(struct radeon_device *rdev);
>  void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
>  void si_rlc_reset(struct radeon_device *rdev);
>  void si_init_uvd_internal_cg(struct radeon_device *rdev);
> +u32 si_get_csb_size(struct radeon_device *rdev);
> +void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
>
>  #endif /* __SI_H__ */
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 35/43] drm/radeon/cik_sdma: Move 'amdgpu_cik_gpu_check_soft_reset()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/cik.c:4845:5: warning: no previous prototype for 
> ‘cik_gpu_check_soft_reset’ [-Wmissing-prototypes]
>  4845 | u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/cik.h  | 1 +
>  drivers/gpu/drm/radeon/cik_sdma.c | 3 +--
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/cik.h b/drivers/gpu/drm/radeon/cik.h
> index 297b3c1ff804f..6630b9da9e7aa 100644
> --- a/drivers/gpu/drm/radeon/cik.h
> +++ b/drivers/gpu/drm/radeon/cik.h
> @@ -29,5 +29,6 @@ void cik_enter_rlc_safe_mode(struct radeon_device *rdev);
>  void cik_exit_rlc_safe_mode(struct radeon_device *rdev);
>  int ci_mc_load_microcode(struct radeon_device *rdev);
>  void cik_update_cg(struct radeon_device *rdev, u32 block, bool enable);
> +u32 cik_gpu_check_soft_reset(struct radeon_device *rdev);
>
>  #endif /* __CIK_H__ */
> diff --git a/drivers/gpu/drm/radeon/cik_sdma.c 
> b/drivers/gpu/drm/radeon/cik_sdma.c
> index 3c709ebe8d1ab..919b14845c3c7 100644
> --- a/drivers/gpu/drm/radeon/cik_sdma.c
> +++ b/drivers/gpu/drm/radeon/cik_sdma.c
> @@ -27,14 +27,13 @@
>  #include "radeon_ucode.h"
>  #include "radeon_asic.h"
>  #include "radeon_trace.h"
> +#include "cik.h"
>  #include "cikd.h"
>
>  /* sdma */
>  #define CIK_SDMA_UCODE_SIZE 1050
>  #define CIK_SDMA_UCODE_VERSION 64
>
> -u32 cik_gpu_check_soft_reset(struct radeon_device *rdev);
> -
>  /*
>   * sDMA - System DMA
>   * Starting with CIK, the GPU has new asynchronous
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 36/43] drm/radeon/evergreen: Move 'cik_*()'s prototypes to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/cik.c:6413:6: warning: no previous prototype for 
> ‘cik_init_cp_pg_table’ [-Wmissing-prototypes]
>  6413 | void cik_init_cp_pg_table(struct radeon_device *rdev)
>  | ^~~~
>  drivers/gpu/drm/radeon/cik.c:6670:5: warning: no previous prototype for 
> ‘cik_get_csb_size’ [-Wmissing-prototypes]
>  6670 | u32 cik_get_csb_size(struct radeon_device *rdev)
>  | ^~~~
>  drivers/gpu/drm/radeon/cik.c:6702:6: warning: no previous prototype for 
> ‘cik_get_csb_buffer’ [-Wmissing-prototypes]
>  6702 | void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 
> *buffer)
>  | ^~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex


> ---
>  drivers/gpu/drm/radeon/cik.h   | 3 +++
>  drivers/gpu/drm/radeon/evergreen.c | 5 +
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/cik.h b/drivers/gpu/drm/radeon/cik.h
> index 6630b9da9e7aa..420207d19de52 100644
> --- a/drivers/gpu/drm/radeon/cik.h
> +++ b/drivers/gpu/drm/radeon/cik.h
> @@ -30,5 +30,8 @@ void cik_exit_rlc_safe_mode(struct radeon_device *rdev);
>  int ci_mc_load_microcode(struct radeon_device *rdev);
>  void cik_update_cg(struct radeon_device *rdev, u32 block, bool enable);
>  u32 cik_gpu_check_soft_reset(struct radeon_device *rdev);
> +void cik_init_cp_pg_table(struct radeon_device *rdev);
> +u32 cik_get_csb_size(struct radeon_device *rdev);
> +void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
>
>  #endif /* __CIK_H__ */
> diff --git a/drivers/gpu/drm/radeon/evergreen.c 
> b/drivers/gpu/drm/radeon/evergreen.c
> index 4575e448e59df..8e9e88bf1f43d 100644
> --- a/drivers/gpu/drm/radeon/evergreen.c
> +++ b/drivers/gpu/drm/radeon/evergreen.c
> @@ -31,6 +31,7 @@
>
>  #include "atom.h"
>  #include "avivod.h"
> +#include "cik.h"
>  #include "ni.h"
>  #include "rv770.h"
>  #include "evergreen.h"
> @@ -217,10 +218,6 @@ static void evergreen_gpu_init(struct radeon_device 
> *rdev);
>  void evergreen_fini(struct radeon_device *rdev);
>  void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
>  void evergreen_program_aspm(struct radeon_device *rdev);
> -void cik_init_cp_pg_table(struct radeon_device *rdev);
> -
> -extern u32 cik_get_csb_size(struct radeon_device *rdev);
> -extern void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 
> *buffer);
>
>  static const u32 evergreen_golden_registers[] =
>  {
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 31/43] drm/radeon/cik: Move 'si_*()'s prototypes to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/si.c:4186:6: warning: no previous prototype for 
> ‘si_vram_gtt_location’ [-Wmissing-prototypes]
>  4186 | void si_vram_gtt_location(struct radeon_device *rdev,
>  | ^~~~
>  drivers/gpu/drm/radeon/si.c:5186:6: warning: no previous prototype for 
> ‘si_init_uvd_internal_cg’ [-Wmissing-prototypes]
>  5186 | void si_init_uvd_internal_cg(struct radeon_device *rdev)
>  | ^~~
>  drivers/gpu/drm/radeon/si.c:5801:6: warning: no previous prototype for 
> ‘si_rlc_reset’ [-Wmissing-prototypes]
>  5801 | void si_rlc_reset(struct radeon_device *rdev)
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Sumit Semwal 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Cc: linux-me...@vger.kernel.org
> Cc: linaro-mm-...@lists.linaro.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/cik.c | 4 +---
>  drivers/gpu/drm/radeon/si.h  | 4 
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
> index ae020ad7b3185..cef0f3111cd3a 100644
> --- a/drivers/gpu/drm/radeon/cik.c
> +++ b/drivers/gpu/drm/radeon/cik.c
> @@ -40,6 +40,7 @@
>  #include "radeon_asic.h"
>  #include "radeon_audio.h"
>  #include "radeon_ucode.h"
> +#include "si.h"
>
>  #define SH_MEM_CONFIG_GFX_DEFAULT \
> ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED)
> @@ -127,9 +128,6 @@ MODULE_FIRMWARE("radeon/mullins_mec.bin");
>  MODULE_FIRMWARE("radeon/mullins_rlc.bin");
>  MODULE_FIRMWARE("radeon/mullins_sdma.bin");
>
> -extern void si_vram_gtt_location(struct radeon_device *rdev, struct 
> radeon_mc *mc);
> -extern void si_rlc_reset(struct radeon_device *rdev);
> -extern void si_init_uvd_internal_cg(struct radeon_device *rdev);
>  static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 
> sh);
>  extern int cik_sdma_resume(struct radeon_device *rdev);
>  extern void cik_sdma_enable(struct radeon_device *rdev, bool enable);
> diff --git a/drivers/gpu/drm/radeon/si.h b/drivers/gpu/drm/radeon/si.h
> index a1751ae560f02..f483a64d17050 100644
> --- a/drivers/gpu/drm/radeon/si.h
> +++ b/drivers/gpu/drm/radeon/si.h
> @@ -25,8 +25,12 @@
>  #define __SI_H__
>
>  struct radeon_device;
> +struct radeon_mc;
>
>  int si_mc_load_microcode(struct radeon_device *rdev);
>  u32 si_gpu_check_soft_reset(struct radeon_device *rdev);
> +void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
> +void si_rlc_reset(struct radeon_device *rdev);
> +void si_init_uvd_internal_cg(struct radeon_device *rdev);
>
>  #endif /* __SI_H__ */
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 32/43] drm/radeon/btc_dpm: Move 'evergreen_get_pi's prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/rv770_dpm.c:62:30: warning: no previous prototype for 
> ‘evergreen_get_pi’ [-Wmissing-prototypes]
>  62 | struct evergreen_power_info *evergreen_get_pi(struct radeon_device 
> *rdev)
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/btc_dpm.c | 3 +--
>  drivers/gpu/drm/radeon/cypress_dpm.c | 3 +--
>  drivers/gpu/drm/radeon/evergreen.h   | 2 ++
>  drivers/gpu/drm/radeon/ni_dpm.c  | 3 +--
>  drivers/gpu/drm/radeon/rv770_dpm.c   | 1 +
>  drivers/gpu/drm/radeon/si_dpm.c  | 3 +--
>  6 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/btc_dpm.c 
> b/drivers/gpu/drm/radeon/btc_dpm.c
> index 018949668536e..4e64ed38c439f 100644
> --- a/drivers/gpu/drm/radeon/btc_dpm.c
> +++ b/drivers/gpu/drm/radeon/btc_dpm.c
> @@ -29,6 +29,7 @@
>  #include "btc_dpm.h"
>  #include "btcd.h"
>  #include "cypress_dpm.h"
> +#include "evergreen.h"
>  #include "r600_dpm.h"
>  #include "rv770.h"
>  #include "radeon.h"
> @@ -49,8 +50,6 @@
>  #ifndef BTC_MGCG_SEQUENCE
>  #define BTC_MGCG_SEQUENCE  300
>
> -struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
> -
>  extern int ni_mc_load_microcode(struct radeon_device *rdev);
>
>  //* BARTS **//
> diff --git a/drivers/gpu/drm/radeon/cypress_dpm.c 
> b/drivers/gpu/drm/radeon/cypress_dpm.c
> index 6d3690bcca2d2..fdddbbaecbb74 100644
> --- a/drivers/gpu/drm/radeon/cypress_dpm.c
> +++ b/drivers/gpu/drm/radeon/cypress_dpm.c
> @@ -26,6 +26,7 @@
>
>  #include "atom.h"
>  #include "cypress_dpm.h"
> +#include "evergreen.h"
>  #include "evergreend.h"
>  #include "r600_dpm.h"
>  #include "rv770.h"
> @@ -44,8 +45,6 @@
>  #define MC_CG_SEQ_YCLK_SUSPEND  0x04
>  #define MC_CG_SEQ_YCLK_RESUME   0x0a
>
> -struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
> -
>  static void cypress_enable_bif_dynamic_pcie_gen2(struct radeon_device *rdev,
>  bool enable)
>  {
> diff --git a/drivers/gpu/drm/radeon/evergreen.h 
> b/drivers/gpu/drm/radeon/evergreen.h
> index f8d772e612a48..a829deb8b078a 100644
> --- a/drivers/gpu/drm/radeon/evergreen.h
> +++ b/drivers/gpu/drm/radeon/evergreen.h
> @@ -29,6 +29,7 @@
>  #define __RADEON_EVERGREEN_H__
>
>  struct evergreen_mc_save;
> +struct evergreen_power_info;
>  struct radeon_device;
>
>  bool evergreen_is_display_hung(struct radeon_device *rdev);
> @@ -49,5 +50,6 @@ u32 evergreen_get_number_of_dram_channels(struct 
> radeon_device *rdev);
>  void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
>  u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev);
>  int evergreen_rlc_resume(struct radeon_device *rdev);
> +struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
>
>  #endif /* __RADEON_EVERGREEN_H__ */
> diff --git a/drivers/gpu/drm/radeon/ni_dpm.c b/drivers/gpu/drm/radeon/ni_dpm.c
> index d39bbd9793cc2..dd5ef64937230 100644
> --- a/drivers/gpu/drm/radeon/ni_dpm.c
> +++ b/drivers/gpu/drm/radeon/ni_dpm.c
> @@ -26,6 +26,7 @@
>  #include 
>
>  #include "atom.h"
> +#include "evergreen.h"
>  #include "ni_dpm.h"
>  #include "nid.h"
>  #include "r600_dpm.h"
> @@ -720,8 +721,6 @@ static const u32 cayman_sysls_enable[] =
>  };
>  #define CAYMAN_SYSLS_ENABLE_LENGTH sizeof(cayman_sysls_enable) / (3 * 
> sizeof(u32))
>
> -struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
> -
>  extern int ni_mc_load_microcode(struct radeon_device *rdev);
>
>  struct ni_power_info *ni_get_pi(struct radeon_device *rdev)
> diff --git a/drivers/gpu/drm/radeon/rv770_dpm.c 
> b/drivers/gpu/drm/radeon/rv770_dpm.c
> index badd8ac6e038f..ef2f1a048cfed 100644
> --- a/drivers/gpu/drm/radeon/rv770_dpm.c
> +++ b/drivers/gpu/drm/radeon/rv770_dpm.c
> @@ -30,6 +30,7 @@
>  #include "rv770_dpm.h"
>  #include "cypress_dpm.h"
>  #include "atom.h"
> +#include "evergreen.h"
>  #include 
>
>  #define MC_CG_ARB_FREQ_F0   0x0a
> diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
> index 32b697965c064..b4581392fbce9 100644
> --- a/drivers/gpu/drm/radeon/si_dpm.c
> +++ b/drivers/gpu/drm/radeon/si_dpm.c
> @@ -26,6 +26,7 @@
>  #include 
>
>  #include "atom.h"
> +#include "evergreen.h"
>  #include "r600_dpm.h"
>  #include "rv770.h"
>  #include "radeon.h"
> @@ -1720,8 +1721,6 @@ static const struct si_powertune_data 
> powertune_data_hainan =
> true
>  };
>
> -struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
> -
>  extern void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
>
>  static int si_populate_voltage_value(struct radeon_device *rdev,
> --

Re: linux-next: build warning after merge of the ftrace tree

2020-11-16 Thread Jonathan Corbet
On Mon, 16 Nov 2020 15:25:52 -0500
Steven Rostedt  wrote:

> On Mon, 16 Nov 2020 12:24:32 -0700
> Jonathan Corbet  wrote:
> 
> > The problem is those literal blocks.  The easiest fix will be to just use
> > the double-colon notation to indicate a literal block, so the paragraph
> > above would end with "...start your code with::".  Note that there's a few
> > of them to fix.  
> 
> Would something like the below work? I think I fixed the other places with
> issues and for consistency, replaced the ".. code-block:: c" with just "::"
> usage throughout the file.

That will work.  It will also have the effect of removing C syntax
highlighting from the formatted output; that is fine with me, but others
are more attached to it.

jon


Re: [PATCH 33/43] drm/radeon/radeon_audio: Move 'dce6_*()'s prototypes to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/dce6_afmt.c:32:5: warning: no previous prototype for 
> ‘dce6_endpoint_rreg’ [-Wmissing-prototypes]
>  32 | u32 dce6_endpoint_rreg(struct radeon_device *rdev,
>  | ^~
>  drivers/gpu/drm/radeon/dce6_afmt.c:46:6: warning: no previous prototype for 
> ‘dce6_endpoint_wreg’ [-Wmissing-prototypes]
>  46 | void dce6_endpoint_wreg(struct radeon_device *rdev,
>  | ^~
>  drivers/gpu/drm/radeon/dce6_afmt.c:110:6: warning: no previous prototype for 
> ‘dce6_afmt_select_pin’ [-Wmissing-prototypes]
>  110 | void dce6_afmt_select_pin(struct drm_encoder *encoder)
>  | ^~~~
>  drivers/gpu/drm/radeon/dce6_afmt.c:123:6: warning: no previous prototype for 
> ‘dce6_afmt_write_latency_fields’ [-Wmissing-prototypes]
>  123 | void dce6_afmt_write_latency_fields(struct drm_encoder *encoder,
>  | ^~
>  drivers/gpu/drm/radeon/dce6_afmt.c:152:6: warning: no previous prototype for 
> ‘dce6_afmt_hdmi_write_speaker_allocation’ [-Wmissing-prototypes]
>  152 | void dce6_afmt_hdmi_write_speaker_allocation(struct drm_encoder 
> *encoder,
>  | ^~~
>  drivers/gpu/drm/radeon/dce6_afmt.c:177:6: warning: no previous prototype for 
> ‘dce6_afmt_dp_write_speaker_allocation’ [-Wmissing-prototypes]
>  177 | void dce6_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
>  | ^
>  drivers/gpu/drm/radeon/dce6_afmt.c:202:6: warning: no previous prototype for 
> ‘dce6_afmt_write_sad_regs’ [-Wmissing-prototypes]
>  202 | void dce6_afmt_write_sad_regs(struct drm_encoder *encoder,
>  | ^~~~
>  drivers/gpu/drm/radeon/dce6_afmt.c:268:6: warning: no previous prototype for 
> ‘dce6_hdmi_audio_set_dto’ [-Wmissing-prototypes]
>  268 | void dce6_hdmi_audio_set_dto(struct radeon_device *rdev,
>  | ^~~
>  drivers/gpu/drm/radeon/dce6_afmt.c:287:6: warning: no previous prototype for 
> ‘dce6_dp_audio_set_dto’ [-Wmissing-prototypes]
>  287 | void dce6_dp_audio_set_dto(struct radeo_device *rdev,
>  | ^
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Slava Grigorev 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex


> ---
>  drivers/gpu/drm/radeon/dce6_afmt.c|  1 +
>  drivers/gpu/drm/radeon/dce6_afmt.h| 52 +++
>  drivers/gpu/drm/radeon/radeon_audio.c | 17 +
>  3 files changed, 54 insertions(+), 16 deletions(-)
>  create mode 100644 drivers/gpu/drm/radeon/dce6_afmt.h
>
> diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c 
> b/drivers/gpu/drm/radeon/dce6_afmt.c
> index eec5d7a627388..4a1d5447eac17 100644
> --- a/drivers/gpu/drm/radeon/dce6_afmt.c
> +++ b/drivers/gpu/drm/radeon/dce6_afmt.c
> @@ -22,6 +22,7 @@
>   */
>  #include 
>
> +#include "dce6_afmt.h"
>  #include "radeon.h"
>  #include "radeon_audio.h"
>  #include "sid.h"
> diff --git a/drivers/gpu/drm/radeon/dce6_afmt.h 
> b/drivers/gpu/drm/radeon/dce6_afmt.h
> new file mode 100644
> index 0..176a538664a27
> --- /dev/null
> +++ b/drivers/gpu/drm/radeon/dce6_afmt.h
> @@ -0,0 +1,52 @@
> +/* dce6_afmt.h -- Private header for radeon driver -*- linux-c -*-
> + *
> + * Copyright 2013 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + *
> + */
> +
> +#ifndef __DCE6_AFMT_H__
> +#define __DCE6_AFMT_H__
> +
> +struct cea_sad;
> +struct drm_connector;
> +struct drm_display_mode;
> +struct drm_encoder;
> +struct radeon_crtc;
> +struct radeon_device;
> +
> +u32 dce6_endpoint_rreg(struct radeon_device *rdev, u32 offset, u32 reg);
> +void dce6_endpoint_wreg(struct radeon_device *rdev, u32 offset, u32 reg, u32 
> v);
> +void 

Re: drivers/accessibility/speakup/serialio.c:48:19: warning: variable 'quot' set but not used

2020-11-16 Thread Ben Hutchings
On Mon, 2020-11-16 at 20:01 +0100, Samuel Thibault wrote:
> Hello Ben,
> 
> A long time ago you added a dependency for speakup drivers on
> CONFIG_ISA, and you also added || COMPILE_TEST as an alternative.
> 
> It seems that some platform portability tests then think they should
> be able to build it, even if they don't enable ISA, but then we are
> getting warnings, or even errors, depending on the compatibility macros
> in  in the !ISA case (here, the parisc compatibility macros do
> not consume their parameter).
> 
> Perhaps we should rather use
> 
> depends on ISA || (X86 && COMPILE_TEST)
> 
> ?
> so that we have compile testing on x86 only (where the inb/outb macros
> always behave fine) to avoid such issues on other archs?

That seems reasonable though unusual.

> Or we tell the architecture maintainers to fix their out macros into
> consuming their parameters?
[...]

It does seem odd for parisc to define the I/O functions this way.  I
don't know if it's really a bug.

Ben.

-- 
Ben Hutchings
Everything should be made as simple as possible, but not simpler.
  - Albert Einstein




signature.asc
Description: This is a digitally signed message part


Re: [PATCH 30/43] drm/radeon/si_dma: Move 'si_gpu_check_soft_reset()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/si.c:3768:5: warning: no previous prototype for 
> ‘si_gpu_check_soft_reset’ [-Wmissing-prototypes]
>  3768 | u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
>  | ^~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/si.h | 1 +
>  drivers/gpu/drm/radeon/si_dma.c | 3 +--
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/si.h b/drivers/gpu/drm/radeon/si.h
> index 0a5018ef166e2..a1751ae560f02 100644
> --- a/drivers/gpu/drm/radeon/si.h
> +++ b/drivers/gpu/drm/radeon/si.h
> @@ -27,5 +27,6 @@
>  struct radeon_device;
>
>  int si_mc_load_microcode(struct radeon_device *rdev);
> +u32 si_gpu_check_soft_reset(struct radeon_device *rdev);
>
>  #endif /* __SI_H__ */
> diff --git a/drivers/gpu/drm/radeon/si_dma.c b/drivers/gpu/drm/radeon/si_dma.c
> index d2fa302a5be9f..645897d1bfc31 100644
> --- a/drivers/gpu/drm/radeon/si_dma.c
> +++ b/drivers/gpu/drm/radeon/si_dma.c
> @@ -25,10 +25,9 @@
>  #include "radeon.h"
>  #include "radeon_asic.h"
>  #include "radeon_trace.h"
> +#include "si.h"
>  #include "sid.h"
>
> -u32 si_gpu_check_soft_reset(struct radeon_device *rdev);
> -
>  /**
>   * si_dma_is_lockup - Check if the DMA engine is locked up
>   *
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: linux-next: build warning after merge of the ftrace tree

2020-11-16 Thread Steven Rostedt
On Mon, 16 Nov 2020 12:24:32 -0700
Jonathan Corbet  wrote:

> The problem is those literal blocks.  The easiest fix will be to just use
> the double-colon notation to indicate a literal block, so the paragraph
> above would end with "...start your code with::".  Note that there's a few
> of them to fix.

Would something like the below work? I think I fixed the other places with
issues and for consistency, replaced the ".. code-block:: c" with just "::"
usage throughout the file.

-- Steve

diff --git a/Documentation/trace/ftrace-uses.rst 
b/Documentation/trace/ftrace-uses.rst
index 5981d5691745..f21464538fa0 100644
--- a/Documentation/trace/ftrace-uses.rst
+++ b/Documentation/trace/ftrace-uses.rst
@@ -43,9 +43,7 @@ as well as what protections the callback will perform and not 
require
 ftrace to handle.
 
 There is only one field that is needed to be set when registering
-an ftrace_ops with ftrace:
-
-.. code-block:: c
+an ftrace_ops with ftrace::
 
  struct ftrace_ops ops = {
.func   = my_callback_func,
@@ -82,9 +80,7 @@ may take some time to finish.
 The callback function
 =
 
-The prototype of the callback function is as follows (as of v4.14):
-
-.. code-block:: c
+The prototype of the callback function is as follows (as of v4.14)::
 
void callback_func(unsigned long ip, unsigned long parent_ip,
   struct ftrace_ops *op, struct pt_regs *regs);
@@ -114,7 +110,7 @@ Protect your callback
 As functions can be called from anywhere, and it is possible that a function
 called by a callback may also be traced, and call that same callback,
 recursion protection must be used. There are two helper functions that
-can help in this regard. If you start your code with:
+can help in this regard. If you start your code with::
 
int bit;
 
@@ -122,7 +118,7 @@ can help in this regard. If you start your code with:
if (bit < 0)
return;
 
-and end it with:
+and end it with::
 
ftrace_test_recursion_unlock(bit);
 
@@ -143,7 +139,7 @@ function call.
 If your callback accesses any data or critical section that requires RCU
 protection, it is best to make sure that RCU is "watching", otherwise
 that data or critical section will not be protected as expected. In this
-case add:
+case add::
 
if (!rcu_is_watching())
return;
@@ -249,9 +245,7 @@ match a specific pattern.
 
 See Filter Commands in :file:`Documentation/trace/ftrace.rst`.
 
-To just trace the schedule function:
-
-.. code-block:: c
+To just trace the schedule function::
 
ret = ftrace_set_filter(, "schedule", strlen("schedule"), 0);
 
@@ -259,17 +253,13 @@ To add more functions, call the ftrace_set_filter() more 
than once with the
 @reset parameter set to zero. To remove the current filter set and replace it
 with new functions defined by @buf, have @reset be non-zero.
 
-To remove all the filtered functions and trace all functions:
-
-.. code-block:: c
+To remove all the filtered functions and trace all functions::
 
ret = ftrace_set_filter(, NULL, 0, 1);
 
 
 Sometimes more than one function has the same name. To trace just a specific
-function in this case, ftrace_set_filter_ip() can be used.
-
-.. code-block:: c
+function in this case, ftrace_set_filter_ip() can be used::
 
ret = ftrace_set_filter_ip(, ip, 0, 0);
 
@@ -284,9 +274,7 @@ two lists are non-empty and contain the same functions, the 
callback will not
 be called by any function.
 
 An empty "notrace" list means to allow all functions defined by the filter
-to be traced.
-
-.. code-block:: c
+to be traced::
 
int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
   int len, int reset);
@@ -298,9 +286,7 @@ filter list, and this function does not modify the filter 
list.
 A non-zero @reset will clear the "notrace" list before adding functions
 that match @buf to it.
 
-Clearing the "notrace" list is the same as clearing the filter list
-
-.. code-block:: c
+Clearing the "notrace" list is the same as clearing the filter list::
 
   ret = ftrace_set_notrace(, NULL, 0, 1);
 
@@ -311,9 +297,7 @@ has been registered.
 
 If a filter is in place, and the @reset is non-zero, and @buf contains a
 matching glob to functions, the switch will happen during the time of
-the ftrace_set_filter() call. At no time will all functions call the callback.
-
-.. code-block:: c
+the ftrace_set_filter() call. At no time will all functions call the callback::
 
ftrace_set_filter(, "schedule", strlen("schedule"), 1);
 
@@ -323,9 +307,7 @@ the ftrace_set_filter() call. At no time will all functions 
call the callback.
 
ftrace_set_filter(, "try_to_wake_up", strlen("try_to_wake_up"), 1);
 
-is not the same as:
-
-.. code-block:: c
+is not the same as::
 
ftrace_set_filter(, "schedule", strlen("schedule"), 1);
 


[tip: core/mm] xtensa/mm/highmem: Make generic kmap_atomic() work correctly

2020-11-16 Thread tip-bot2 for Thomas Gleixner
The following commit has been merged into the core/mm branch of tip:

Commit-ID: 1eb0616c2df5b78c301eaa7bd2ee859f43915001
Gitweb:
https://git.kernel.org/tip/1eb0616c2df5b78c301eaa7bd2ee859f43915001
Author:Thomas Gleixner 
AuthorDate:Mon, 16 Nov 2020 11:32:53 -08:00
Committer: Thomas Gleixner 
CommitterDate: Mon, 16 Nov 2020 21:19:24 +01:00

xtensa/mm/highmem: Make generic kmap_atomic() work correctly

The conversion to the generic kmap_atomic() implementation missed the fact
that xtensa's fixmap works bottom up while all other implementations work
top down. There is no real reason why xtensa needs to work that way.

Cure it by:

  - Using the generic fix_to_virt()/virt_to_fix() functions which work top
down
  - Adjusting the mapping defines
  - Using the generic index calculation for the non cache aliasing case
  - Making the cache colour offset reverse so the effective index is correct

While at it, remove the outdated and misleading comment above the fixmap
enum which originates from the initial copy of this code from i386.

[ Max: Fixed the off by one in the index calculation ]

Fixes: 629ed3f7dad2 ("xtensa/mm/highmem: Switch to generic kmap atomic")
Reported-by: Max Filippov 
Signed-off-by: Thomas Gleixner 
Signed-off-by: Max Filippov 
Signed-off-by: Thomas Gleixner 
Tested-by: Max Filippov 
Link: https://lore.kernel.org/r/20201116193253.23875-1-jcmvb...@gmail.com

---
 arch/xtensa/include/asm/fixmap.h  | 55 +++---
 arch/xtensa/include/asm/highmem.h | 15 
 arch/xtensa/mm/highmem.c  | 18 ++
 arch/xtensa/mm/init.c |  4 +-
 arch/xtensa/mm/mmu.c  |  3 +-
 5 files changed, 31 insertions(+), 64 deletions(-)

diff --git a/arch/xtensa/include/asm/fixmap.h b/arch/xtensa/include/asm/fixmap.h
index 92049b6..1c65dc1 100644
--- a/arch/xtensa/include/asm/fixmap.h
+++ b/arch/xtensa/include/asm/fixmap.h
@@ -17,63 +17,22 @@
 #include 
 #include 
 #include 
-#endif
 
-/*
- * Here we define all the compile-time 'special' virtual
- * addresses. The point is to have a constant address at
- * compile time, but to set the physical address only
- * in the boot process. We allocate these special addresses
- * from the start of the consistent memory region upwards.
- * Also this lets us do fail-safe vmalloc(), we
- * can guarantee that these special addresses and
- * vmalloc()-ed addresses never overlap.
- *
- * these 'compile-time allocated' memory buffers are
- * fixed-size 4k pages. (or larger if used with an increment
- * higher than 1) use fixmap_set(idx,phys) to associate
- * physical memory with fixmap indices.
- */
+/* The map slots for temporary mappings via kmap_atomic/local(). */
 enum fixed_addresses {
-#ifdef CONFIG_HIGHMEM
-   /* reserved pte's for temporary kernel mappings */
FIX_KMAP_BEGIN,
FIX_KMAP_END = FIX_KMAP_BEGIN +
(KM_MAX_IDX * NR_CPUS * DCACHE_N_COLORS) - 1,
-#endif
__end_of_fixed_addresses
 };
 
-#define FIXADDR_TOP (XCHAL_KSEG_CACHED_VADDR - PAGE_SIZE)
+#define FIXADDR_END (XCHAL_KSEG_CACHED_VADDR - PAGE_SIZE)
 #define FIXADDR_SIZE   (__end_of_fixed_addresses << PAGE_SHIFT)
-#define FIXADDR_START  ((FIXADDR_TOP - FIXADDR_SIZE) & PMD_MASK)
+/* Enforce that FIXADDR_START is PMD aligned to handle cache aliasing */
+#define FIXADDR_START  ((FIXADDR_END - FIXADDR_SIZE) & PMD_MASK)
+#define FIXADDR_TOP(FIXADDR_START + FIXADDR_SIZE - PAGE_SIZE)
 
-#define __fix_to_virt(x)   (FIXADDR_START + ((x) << PAGE_SHIFT))
-#define __virt_to_fix(x)   (((x) - FIXADDR_START) >> PAGE_SHIFT)
-
-#ifndef __ASSEMBLY__
-/*
- * 'index to address' translation. If anyone tries to use the idx
- * directly without translation, we catch the bug with a NULL-deference
- * kernel oops. Illegal ranges of incoming indices are caught too.
- */
-static __always_inline unsigned long fix_to_virt(const unsigned int idx)
-{
-   /* Check if this memory layout is broken because fixmap overlaps page
-* table.
-*/
-   BUILD_BUG_ON(FIXADDR_START <
-TLBTEMP_BASE_1 + TLBTEMP_SIZE);
-   BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
-   return __fix_to_virt(idx);
-}
-
-static inline unsigned long virt_to_fix(const unsigned long vaddr)
-{
-   BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
-   return __virt_to_fix(vaddr);
-}
-
-#endif
+#include 
 
+#endif /* CONFIG_HIGHMEM */
 #endif
diff --git a/arch/xtensa/include/asm/highmem.h 
b/arch/xtensa/include/asm/highmem.h
index 0fc3b1c..34b8b62 100644
--- a/arch/xtensa/include/asm/highmem.h
+++ b/arch/xtensa/include/asm/highmem.h
@@ -12,6 +12,7 @@
 #ifndef _XTENSA_HIGHMEM_H
 #define _XTENSA_HIGHMEM_H
 
+#ifdef CONFIG_HIGHMEM
 #include 
 #include 
 #include 
@@ -58,6 +59,13 @@ static inline wait_queue_head_t 
*get_pkmap_wait_queue_head(unsigned int color)
 {
return pkmap_map_wait_arr + color;
 }
+
+enum fixed_addresses kmap_local_map_idx(int type, unsigned long pfn);

Re: [PATCH 28/43] drm/radeon/ci_dpm: Move 'ci_*()'s prototypes to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/cik.c:1868:5: warning: no previous prototype for 
> ‘ci_mc_load_microcode’ [-Wmissing-prototypes]
>  1868 | int ci_mc_load_microcode(struct radeon_device *rdev)
>  | ^~~~
>  drivers/gpu/drm/radeon/cik.c:5847:6: warning: no previous prototype for 
> ‘cik_enter_rlc_safe_mode’ [-Wmissing-prototypes]
>  5847 | void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
>  | ^~~
>  drivers/gpu/drm/radeon/cik.c:5868:6: warning: no previous prototype for 
> ‘cik_exit_rlc_safe_mode’ [-Wmissing-prototypes]
>  5868 | void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
>  | ^~
>  drivers/gpu/drm/radeon/cik.c:6286:6: warning: no previous prototype for 
> ‘cik_update_cg’ [-Wmissing-prototypes]
>  6286 | void cik_update_cg(struct radeon_device *rdev,
>  | ^
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/ci_dpm.c |  7 +--
>  drivers/gpu/drm/radeon/cik.c|  1 +
>  drivers/gpu/drm/radeon/cik.h| 33 +
>  3 files changed, 35 insertions(+), 6 deletions(-)
>  create mode 100644 drivers/gpu/drm/radeon/cik.h
>
> diff --git a/drivers/gpu/drm/radeon/ci_dpm.c b/drivers/gpu/drm/radeon/ci_dpm.c
> index 8324aca5fd006..a9fc0a552736c 100644
> --- a/drivers/gpu/drm/radeon/ci_dpm.c
> +++ b/drivers/gpu/drm/radeon/ci_dpm.c
> @@ -27,6 +27,7 @@
>
>  #include "atom.h"
>  #include "ci_dpm.h"
> +#include "cik.h"
>  #include "cikd.h"
>  #include "r600_dpm.h"
>  #include "radeon.h"
> @@ -157,12 +158,6 @@ extern u8 si_get_mclk_frequency_ratio(u32 memory_clock, 
> bool strobe_mode);
>  extern void si_trim_voltage_table_to_fit_state_table(struct radeon_device 
> *rdev,
>  u32 max_voltage_steps,
>  struct 
> atom_voltage_table *voltage_table);
> -extern void cik_enter_rlc_safe_mode(struct radeon_device *rdev);
> -extern void cik_exit_rlc_safe_mode(struct radeon_device *rdev);
> -extern int ci_mc_load_microcode(struct radeon_device *rdev);
> -extern void cik_update_cg(struct radeon_device *rdev,
> - u32 block, bool enable);
> -
>  static int ci_get_std_voltage_value_sidd(struct radeon_device *rdev,
>  struct atom_voltage_table_entry 
> *voltage_table,
>  u16 *std_voltage_hi_sidd, u16 
> *std_voltage_lo_sidd);
> diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
> index 980b50d046cbc..ae020ad7b3185 100644
> --- a/drivers/gpu/drm/radeon/cik.c
> +++ b/drivers/gpu/drm/radeon/cik.c
> @@ -32,6 +32,7 @@
>  #include "atom.h"
>  #include "evergreen.h"
>  #include "cik_blit_shaders.h"
> +#include "cik.h"
>  #include "cikd.h"
>  #include "clearstate_ci.h"
>  #include "r600.h"
> diff --git a/drivers/gpu/drm/radeon/cik.h b/drivers/gpu/drm/radeon/cik.h
> new file mode 100644
> index 0..297b3c1ff804f
> --- /dev/null
> +++ b/drivers/gpu/drm/radeon/cik.h
> @@ -0,0 +1,33 @@
> +/* cik.h -- Private header for radeon driver -*- linux-c -*-
> + * Copyright 2012 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef __CIK_H__
> +#define __CIK_H__
> +
> +struct radeon_device;
> +
> +void cik_enter_rlc_safe_mode(struct radeon_device *rdev);
> +void cik_exit_rlc_safe_mode(struct radeon_device *rdev);
> +int ci_mc_load_microcode(struct radeon_device *rdev);
> +void cik_update_cg(struct radeon_device *rdev, u32 block, bool enable);
> +
> +#endif /* __CIK_H__ */
> --
> 2.25.1

Re: [PATCH 29/43] drm/radeon/si_dpm: Move 'si_mc_load_microcode()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/si.c:1570:5: warning: no previous prototype for 
> ‘si_mc_load_microcode’ [-Wmissing-prototypes]
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/si.c |  1 +
>  drivers/gpu/drm/radeon/si.h | 31 +++
>  drivers/gpu/drm/radeon/si_dpm.c |  2 +-
>  3 files changed, 33 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/radeon/si.h
>
> diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
> index d0407145c07b5..88731b79c8f57 100644
> --- a/drivers/gpu/drm/radeon/si.c
> +++ b/drivers/gpu/drm/radeon/si.c
> @@ -39,6 +39,7 @@
>  #include "radeon_audio.h"
>  #include "radeon_ucode.h"
>  #include "si_blit_shaders.h"
> +#include "si.h"
>  #include "sid.h"
>
>
> diff --git a/drivers/gpu/drm/radeon/si.h b/drivers/gpu/drm/radeon/si.h
> new file mode 100644
> index 0..0a5018ef166e2
> --- /dev/null
> +++ b/drivers/gpu/drm/radeon/si.h
> @@ -0,0 +1,31 @@
> +/* si.h -- Private header for radeon driver -*- linux-c -*-
> + *
> + * Copyright 2011 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef __SI_H__
> +#define __SI_H__
> +
> +struct radeon_device;
> +
> +int si_mc_load_microcode(struct radeon_device *rdev);
> +
> +#endif /* __SI_H__ */
> diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
> index c68ab2fb1ac23..32b697965c064 100644
> --- a/drivers/gpu/drm/radeon/si_dpm.c
> +++ b/drivers/gpu/drm/radeon/si_dpm.c
> @@ -32,6 +32,7 @@
>  #include "radeon_asic.h"
>  #include "ni_dpm.h"
>  #include "si_dpm.h"
> +#include "si.h"
>  #include "sid.h"
>
>  #define MC_CG_ARB_FREQ_F0   0x0a
> @@ -1721,7 +1722,6 @@ static const struct si_powertune_data 
> powertune_data_hainan =
>
>  struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
>
> -extern int si_mc_load_microcode(struct radeon_device *rdev);
>  extern void vce_v1_0_enable_mgcg(struct radeon_device *rdev, bool enable);
>
>  static int si_populate_voltage_value(struct radeon_device *rdev,
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-16 Thread Borislav Petkov
On Mon, Nov 16, 2020 at 03:47:36PM +0100, Alexandre Chartre wrote:
> Deferring CR3 switch to C code means that we need to run more of the
> kernel entry code with the user page-table. To do so, we need to:
> 
>  - map more syscall, interrupt and exception entry code into the user
>page-table (map all noinstr code);
> 
>  - map additional data used in the entry code (such as stack canary);
> 
>  - run more entry code on the trampoline stack (which is mapped both
>in the kernel and in the user page-table) until we switch to the
>kernel page-table and then switch to the kernel stack;

So PTI was added exactly to *not* have kernel memory mapped in the user
page table. You're partially reversing that...

>  - have a per-task trampoline stack instead of a per-cpu trampoline
>stack, so the task can be scheduled out while it hasn't switched
>to the kernel stack.

per-task? How much more memory is that per task?

-- 
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette


Re: [PATCH 27/43] drm/radeon/radeon_encoders: Move 'radeon_atom_backlight_init's prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:37 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/atombios_encoders.c:186:6: warning: no previous 
> prototype for ‘radeon_atom_backlight_init’ [-Wmissing-prototypes]
>  186 | void radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder,
>  | ^~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/radeon_atombios.h | 4 
>  drivers/gpu/drm/radeon/radeon_encoders.c | 6 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_atombios.h 
> b/drivers/gpu/drm/radeon/radeon_atombios.h
> index a895a7002c3d3..fd03755e6fa2c 100644
> --- a/drivers/gpu/drm/radeon/radeon_atombios.h
> +++ b/drivers/gpu/drm/radeon/radeon_atombios.h
> @@ -28,14 +28,18 @@
>  #ifndef __RADEON_ATOMBIOS_H__
>  #define __RADEON_ATOMBIOS_H__
>
> +struct drm_connector;
>  struct drm_device;
>  struct drm_display_mode;
>  struct radeon_device;
> +struct radeon_encoder;
>
>  bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
> struct drm_display_mode *mode);
>  void radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
>  uint32_t supported_device, u16 caps);
> +void radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder,
> +   struct drm_connector *drm_connector);
>
>
>  #endif /* __RADEON_ATOMBIOS_H__ */
> diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c 
> b/drivers/gpu/drm/radeon/radeon_encoders.c
> index b60a373d3ead3..46549d5179ee9 100644
> --- a/drivers/gpu/drm/radeon/radeon_encoders.c
> +++ b/drivers/gpu/drm/radeon/radeon_encoders.c
> @@ -31,14 +31,10 @@
>  #include 
>
>  #include "radeon.h"
> +#include "radeon_atombios.h"
>  #include "radeon_legacy_encoders.h"
>  #include "atom.h"
>
> -extern void
> -radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder,
> -  struct drm_connector *drm_connector);
> -
> -
>  static uint32_t radeon_encoder_clones(struct drm_encoder *encoder)
>  {
> struct drm_device *dev = encoder->dev;
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RFC][PATCH v2 11/21] x86/pti: Extend PTI user mappings

2020-11-16 Thread Alexandre Chartre



On 11/16/20 8:48 PM, Andy Lutomirski wrote:

On Mon, Nov 16, 2020 at 6:49 AM Alexandre Chartre
 wrote:


Extend PTI user mappings so that more kernel entry code can be executed
with the user page-table. To do so, we need to map syscall and interrupt
entry code, per cpu offsets (__per_cpu_offset, which is used some in
entry code), the stack canary, and the PTI stack (which is defined per
task).


Does anything unmap the PTI stack?  Mapping is easy, and unmapping
could be a pretty big mess.



No, there's no unmap. The mapping exists as long as the task page-table
does (i.e. as long as the task mm exits). I assume that the task stack
and mm are freed at the same time but that's not something I have checked.

alex.


Re: [PATCH 24/43] drm/radeon/r600: Move 'evergreen_rlc_resume()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/evergreen.c:4380:5: warning: no previous prototype 
> for ‘evergreen_rlc_resume’ [-Wmissing-prototypes]
>  4380 | int evergreen_rlc_resume(struct radeon_device *rdev)
>  | ^~~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/evergreen.h | 1 +
>  drivers/gpu/drm/radeon/r600.c  | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/evergreen.h 
> b/drivers/gpu/drm/radeon/evergreen.h
> index eb46ac7776951..f8d772e612a48 100644
> --- a/drivers/gpu/drm/radeon/evergreen.h
> +++ b/drivers/gpu/drm/radeon/evergreen.h
> @@ -48,5 +48,6 @@ void evergreen_gpu_pci_config_reset(struct radeon_device 
> *rdev);
>  u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev);
>  void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
>  u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev);
> +int evergreen_rlc_resume(struct radeon_device *rdev);
>
>  #endif /* __RADEON_EVERGREEN_H__ */
> diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
> index 94e8815e5067d..b44e0c607b1b1 100644
> --- a/drivers/gpu/drm/radeon/r600.c
> +++ b/drivers/gpu/drm/radeon/r600.c
> @@ -39,6 +39,7 @@
>
>  #include "atom.h"
>  #include "avivod.h"
> +#include "evergreen.h"
>  #include "r600.h"
>  #include "r600d.h"
>  #include "rv770.h"
> @@ -113,7 +114,6 @@ static void r600_gpu_init(struct radeon_device *rdev);
>  void r600_fini(struct radeon_device *rdev);
>  void r600_irq_disable(struct radeon_device *rdev);
>  static void r600_pcie_gen2_enable(struct radeon_device *rdev);
> -extern int evergreen_rlc_resume(struct radeon_device *rdev);
>
>  /*
>   * Indirect registers accessor
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [RFC][PATCH v2 00/21] x86/pti: Defer CR3 switch to C code

2020-11-16 Thread Borislav Petkov
On Mon, Nov 16, 2020 at 03:47:36PM +0100, Alexandre Chartre wrote:
> This RFC proposes to defer the PTI CR3 switch until we reach C code.
> The benefit is that this simplifies the assembly entry code, and make
> the PTI CR3 switch code easier to understand. This also paves the way
> for further possible projects such an easier integration of Address
> Space Isolation (ASI), or the possibilily to execute some selected
> syscall or interrupt handlers without switching to the kernel page-table

What for? What is this going to be used for in the end?

> (and thus avoid the PTI page-table switch overhead).

Overhead of how much? Why do we care?

What is the big picture justfication for this diffstat

>  21 files changed, 874 insertions(+), 314 deletions(-)

and the diffstat for the ASI enablement?

Thx.

-- 
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette


Re: [PATCH 26/43] drm/radeon/radeon_atombios: Move 'radeon_add_atom_encoder()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:38 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/atombios_encoders.c:2721:1: warning: no previous 
> prototype for ‘radeon_add_atom_encoder’ [-Wmissing-prototypes]
>  2721 | radeon_add_atom_encoder(struct drm_device *dev,
>  | ^~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/radeon_atombios.c | 4 
>  drivers/gpu/drm/radeon/radeon_atombios.h | 4 
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c 
> b/drivers/gpu/drm/radeon/radeon_atombios.c
> index cc80651b25773..be96d9b64e43b 100644
> --- a/drivers/gpu/drm/radeon/radeon_atombios.c
> +++ b/drivers/gpu/drm/radeon/radeon_atombios.c
> @@ -37,10 +37,6 @@
>  #include "radeon_atombios.h"
>  #include "radeon_legacy_encoders.h"
>
> -extern void
> -radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
> -   uint32_t supported_device, u16 caps);
> -
>  union atom_supported_devices {
> struct _ATOM_SUPPORTED_DEVICES_INFO info;
> struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
> diff --git a/drivers/gpu/drm/radeon/radeon_atombios.h 
> b/drivers/gpu/drm/radeon/radeon_atombios.h
> index b7c76920feb7d..a895a7002c3d3 100644
> --- a/drivers/gpu/drm/radeon/radeon_atombios.h
> +++ b/drivers/gpu/drm/radeon/radeon_atombios.h
> @@ -28,10 +28,14 @@
>  #ifndef __RADEON_ATOMBIOS_H__
>  #define __RADEON_ATOMBIOS_H__
>
> +struct drm_device;
>  struct drm_display_mode;
>  struct radeon_device;
>
>  bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
> struct drm_display_mode *mode);
> +void radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
> +uint32_t supported_device, u16 caps);
> +
>
>  #endif /* __RADEON_ATOMBIOS_H__ */
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 25/43] drm/radeon/ni_dma: Move 'cayman_gpu_check_soft_reset()'s prototype to shared header

2020-11-16 Thread Alex Deucher
On Mon, Nov 16, 2020 at 12:37 PM Lee Jones  wrote:
>
> Fixes the following W=1 kernel build warning(s):
>
>  drivers/gpu/drm/radeon/ni.c:1733:5: warning: no previous prototype for 
> ‘cayman_gpu_check_soft_reset’ [-Wmissing-prototypes]
>  1733 | u32 cayman_gpu_check_soft_reset(struct radeon_device *rdev)
>  | ^~~
>
> Cc: Alex Deucher 
> Cc: "Christian König" 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: amd-...@lists.freedesktop.org
> Cc: dri-de...@lists.freedesktop.org
> Signed-off-by: Lee Jones 

Applied.  Thanks!

Alex

> ---
>  drivers/gpu/drm/radeon/ni.h | 1 +
>  drivers/gpu/drm/radeon/ni_dma.c | 3 +--
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/ni.h b/drivers/gpu/drm/radeon/ni.h
> index d63be1c88c0f1..9a5f31a05e68f 100644
> --- a/drivers/gpu/drm/radeon/ni.h
> +++ b/drivers/gpu/drm/radeon/ni.h
> @@ -34,5 +34,6 @@ void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
>   int ring, u32 cp_int_cntl);
>  void cayman_vm_decode_fault(struct radeon_device *rdev,
> u32 status, u32 addr);
> +u32 cayman_gpu_check_soft_reset(struct radeon_device *rdev);
>
>  #endif /* __NI_H__ */
> diff --git a/drivers/gpu/drm/radeon/ni_dma.c b/drivers/gpu/drm/radeon/ni_dma.c
> index c56136848360e..bd515ad4fe4cc 100644
> --- a/drivers/gpu/drm/radeon/ni_dma.c
> +++ b/drivers/gpu/drm/radeon/ni_dma.c
> @@ -25,10 +25,9 @@
>  #include "radeon.h"
>  #include "radeon_asic.h"
>  #include "radeon_trace.h"
> +#include "ni.h"
>  #include "nid.h"
>
> -u32 cayman_gpu_check_soft_reset(struct radeon_device *rdev);
> -
>  /*
>   * DMA
>   * Starting with R600, the GPU has an asynchronous
> --
> 2.25.1
>
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v2] xtensa/mm/highmem: Make generic kmap_atomic() work correctly

2020-11-16 Thread Thomas Gleixner
On Mon, Nov 16 2020 at 11:32, Max Filippov wrote:
> From: Thomas Gleixner 
>
> The conversion to the generic kmap_atomic() implementation missed the fact
> that xtensa's fixmap works bottom up while all other implementations work
> top down. There is no real reason why xtensa needs to work that way.
>
> Cure it by:
>
>   - Using the generic fix_to_virt()/virt_to_fix() functions which work top
> down
>   - Adjusting the mapping defines
>   - Using the generic index calculation for the non cache aliasing case
>   - Making the cache colour offset reverse so the effective index is correct
>
> While at it, remove the outdated and misleading comment above the fixmap
> enum which originates from the initial copy of this code from i386.
>
> Reported-by: Max Filippov 
> Fixes: 629ed3f7dad2 ("xtensa/mm/highmem: Switch to generic kmap atomic")
> Signed-off-by: Thomas Gleixner 
> Signed-off-by: Max Filippov 
> Tested-by: Max Filippov 
> ---
> Changes v1->v2:
> - fix off-by-one error in kmap_idx calculation

Duh. Indeed.

Thanks for following up and helping with this. Much appreciated!

 tglx


Re: [PATCH net-next v2 5/6] net/lapb: support netdev events

2020-11-16 Thread Xie He
On Mon, Nov 16, 2020 at 6:01 AM Martin Schiller  wrote:
>
> This makes it possible to handle carrier loss and detection.
> In case of Carrier Loss, layer 2 is terminated
> In case of Carrier Detection, we start timer t1 on a DCE interface,
> and on a DTE interface we change to state LAPB_STATE_1 and start
> sending SABM(E).

> +   lapb_dbg(0, "(%p): Carrier detected: %s\n",
> +dev, dev->name);
> +   if (lapb->mode & LAPB_DCE) {
> +   lapb_start_t1timer(lapb);
> +   } else {
> +   if (lapb->state == LAPB_STATE_0) {
> +   lapb->state = LAPB_STATE_1;
> +   
> lapb_establish_data_link(lapb);
> +   }
> +   }

Do you mean we will now automatically establish LAPB connections
without upper layers instructing us to do so?

If that is the case, is the one-byte header for instructing the LAPB
layer to connect / disconnect no longer needed?


<    1   2   3   4   5   6   7   8   9   10   >