2019-08-28 14:35:10

by Thomas Gleixner

[permalink] [raw]
Subject: [patch 2/2] x86/mm/pti: Do not invoke PTI functions when PTI is disabled

When PTI is disabled at boot time either because the CPU is not affected or
PTI has been disabled on the command line, the boot code still calls into
pti_finalize() which then unconditionally invokes:

pti_clone_entry_text()
pti_clone_kernel_text()

pti_clone_kernel_text() was called unconditionally before the 32bit support
was added and 32bit added the call to pti_clone_entry_text().

The call has no side effects as cloning the page tables into the available
second one, which was allocated for PTI does not create damage. But it does
not make sense either and in case that this functionality would be extended
later this might actually lead to hard to diagnose issue.

Neither function should be called when PTI is runtime disabled. Make the
invocation conditional.

Signed-off-by: Thomas Gleixner <[email protected]>
---
arch/x86/mm/pti.c | 2 ++
1 file changed, 2 insertions(+)

--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -668,6 +668,8 @@ void __init pti_init(void)
*/
void pti_finalize(void)
{
+ if (!boot_cpu_has(X86_FEATURE_PTI))
+ return;
/*
* We need to clone everything (again) that maps parts of the
* kernel image.



2019-08-28 15:49:29

by Dave Hansen

[permalink] [raw]
Subject: Re: [patch 2/2] x86/mm/pti: Do not invoke PTI functions when PTI is disabled

On 8/28/19 7:24 AM, Thomas Gleixner wrote:
> Neither function should be called when PTI is runtime disabled. Make the
> invocation conditional.

Thanks for sending that out. My impressions from a look through it
matched your changelog.

Reviewed-by: Dave Hansen <[email protected]>

2019-08-28 17:52:38

by Song Liu

[permalink] [raw]
Subject: Re: [patch 2/2] x86/mm/pti: Do not invoke PTI functions when PTI is disabled



> On Aug 28, 2019, at 7:24 AM, Thomas Gleixner <[email protected]> wrote:
>
> When PTI is disabled at boot time either because the CPU is not affected or
> PTI has been disabled on the command line, the boot code still calls into
> pti_finalize() which then unconditionally invokes:
>
> pti_clone_entry_text()
> pti_clone_kernel_text()
>
> pti_clone_kernel_text() was called unconditionally before the 32bit support
> was added and 32bit added the call to pti_clone_entry_text().
>
> The call has no side effects as cloning the page tables into the available
> second one, which was allocated for PTI does not create damage. But it does
> not make sense either and in case that this functionality would be extended
> later this might actually lead to hard to diagnose issue.
>
> Neither function should be called when PTI is runtime disabled. Make the
> invocation conditional.
>
> Signed-off-by: Thomas Gleixner <[email protected]>

Acked-by: Song Liu <[email protected]>

2019-08-28 19:01:30

by Ingo Molnar

[permalink] [raw]
Subject: Re: [patch 2/2] x86/mm/pti: Do not invoke PTI functions when PTI is disabled


* Thomas Gleixner <[email protected]> wrote:

> When PTI is disabled at boot time either because the CPU is not affected or
> PTI has been disabled on the command line, the boot code still calls into
> pti_finalize() which then unconditionally invokes:
>
> pti_clone_entry_text()
> pti_clone_kernel_text()
>
> pti_clone_kernel_text() was called unconditionally before the 32bit support
> was added and 32bit added the call to pti_clone_entry_text().
>
> The call has no side effects as cloning the page tables into the available
> second one, which was allocated for PTI does not create damage. But it does
> not make sense either and in case that this functionality would be extended
> later this might actually lead to hard to diagnose issue.

s/issue/issues

> Neither function should be called when PTI is runtime disabled. Make the
> invocation conditional.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---
> arch/x86/mm/pti.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> --- a/arch/x86/mm/pti.c
> +++ b/arch/x86/mm/pti.c
> @@ -668,6 +668,8 @@ void __init pti_init(void)
> */
> void pti_finalize(void)
> {
> + if (!boot_cpu_has(X86_FEATURE_PTI))
> + return;
> /*
> * We need to clone everything (again) that maps parts of the
> * kernel image.

Acked-by: Ingo Molnar <[email protected]>

Thanks,

Ingo

Subject: [tip: x86/pti] x86/mm/pti: Do not invoke PTI functions when PTI is disabled

The following commit has been merged into the x86/pti branch of tip:

Commit-ID: 990784b57731192b7d90c8d4049e6318d81e887d
Gitweb: https://git.kernel.org/tip/990784b57731192b7d90c8d4049e6318d81e887d
Author: Thomas Gleixner <[email protected]>
AuthorDate: Wed, 28 Aug 2019 16:24:47 +02:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Thu, 29 Aug 2019 20:52:53 +02:00

x86/mm/pti: Do not invoke PTI functions when PTI is disabled

When PTI is disabled at boot time either because the CPU is not affected or
PTI has been disabled on the command line, the boot code still calls into
pti_finalize() which then unconditionally invokes:

pti_clone_entry_text()
pti_clone_kernel_text()

pti_clone_kernel_text() was called unconditionally before the 32bit support
was added and 32bit added the call to pti_clone_entry_text().

The call has no side effects as cloning the page tables into the available
second one, which was allocated for PTI does not create damage. But it does
not make sense either and in case that this functionality would be extended
later this might actually lead to hard to diagnose issues.

Neither function should be called when PTI is runtime disabled. Make the
invocation conditional.

Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Dave Hansen <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Acked-by: Song Liu <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]

---
arch/x86/mm/pti.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index a24487b..7f21404 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -668,6 +668,8 @@ void __init pti_init(void)
*/
void pti_finalize(void)
{
+ if (!boot_cpu_has(X86_FEATURE_PTI))
+ return;
/*
* We need to clone everything (again) that maps parts of the
* kernel image.

2019-08-30 10:26:33

by Jörg Rödel

[permalink] [raw]
Subject: Re: [patch 2/2] x86/mm/pti: Do not invoke PTI functions when PTI is disabled

On Wed, Aug 28, 2019 at 04:24:47PM +0200, Thomas Gleixner wrote:
> --- a/arch/x86/mm/pti.c
> +++ b/arch/x86/mm/pti.c
> @@ -668,6 +668,8 @@ void __init pti_init(void)
> */
> void pti_finalize(void)
> {
> + if (!boot_cpu_has(X86_FEATURE_PTI))
> + return;
> /*
> * We need to clone everything (again) that maps parts of the
> * kernel image.
>

Reviewed-by: Joerg Roedel <[email protected]>