All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts
@ 2020-07-06 16:42 Sebastian Andrzej Siewior
  2020-08-12 14:39 ` Thomas Gleixner
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2020-07-06 16:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Sebastian Andrzej Siewior

The pte lock is never acquired from an IRQ-off region so it does not
require the interrupts to be disabled.
RT complains here because the spinlock_t must not be acquired with
disabled interrupts.

use_temporary_mm() expects interrupts to be off because it invokes
switch_mm_irqs_off() and uses per-CPU (current active mm) data.

Move local_irq_save() after the the pte lock has been acquired. Move
local_irq_restore() after the pte lock has been released.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/kernel/alternative.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 8fd39ff74a499..7c59a87ebbde8 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -872,8 +872,6 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 	 */
 	BUG_ON(!pages[0] || (cross_page_boundary && !pages[1]));
 
-	local_irq_save(flags);
-
 	/*
 	 * Map the page without the global bit, as TLB flushing is done with
 	 * flush_tlb_mm_range(), which is intended for non-global PTEs.
@@ -890,6 +888,8 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 	 */
 	VM_BUG_ON(!ptep);
 
+	local_irq_save(flags);
+
 	pte = mk_pte(pages[0], pgprot);
 	set_pte_at(poking_mm, poking_addr, ptep, pte);
 
@@ -939,8 +939,8 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 	 */
 	BUG_ON(memcmp(addr, opcode, len));
 
-	pte_unmap_unlock(ptep, ptl);
 	local_irq_restore(flags);
+	pte_unmap_unlock(ptep, ptl);
 	return addr;
 }
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts
  2020-07-06 16:42 [PATCH] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts Sebastian Andrzej Siewior
@ 2020-08-12 14:39 ` Thomas Gleixner
  2020-08-13 10:47   ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Gleixner @ 2020-08-12 14:39 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin,
	Sebastian Andrzej Siewior

Sebastian,

Sebastian Andrzej Siewior <bigeasy@linutronix.de> writes:

sorry this fell through the cracks ...

> The pte lock is never acquired from an IRQ-off region so it does not
> require the interrupts to be disabled.

I doubt that this is true. It surely is acquired within other locks
which might be taken with spin_lock_irq(). Which is completely fine on
RT.

But that's not the point. The point is that pte_lock() does not require
to be taken with interrupts disabled.

Please be precise about these kind of things. Handwavy descriptions
cause more problems than they solve.

> RT complains here because the spinlock_t must not be acquired with
> disabled interrupts.
>
> use_temporary_mm() expects interrupts to be off because it invokes
> switch_mm_irqs_off() and uses per-CPU (current active mm) data.
>
> Move local_irq_save() after the the pte lock has been acquired. Move
> local_irq_restore() after the pte lock has been released.

While part 1 is correct, part 2 is the exact opposite of what the patch
does.

  Move the PTE lock handling outside the interrupt disabled region.

describes precisely what this is about without any gory details which
can be seen in the patch itself. Hmm?

Thanks,

        tglx


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts
  2020-08-12 14:39 ` Thomas Gleixner
@ 2020-08-13 10:47   ` Sebastian Andrzej Siewior
  2020-08-13 10:50     ` [PATCH v2] " Sebastian Andrzej Siewior
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2020-08-13 10:47 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin

On 2020-08-12 16:39:41 [+0200], Thomas Gleixner wrote:
> Sebastian,
Hi tglx,

> Sebastian Andrzej Siewior <bigeasy@linutronix.de> writes:
> 
> > The pte lock is never acquired from an IRQ-off region so it does not
> > require the interrupts to be disabled.
> 
> I doubt that this is true. It surely is acquired within other locks
> which might be taken with spin_lock_irq(). Which is completely fine on
> RT.
> 
> But that's not the point. The point is that pte_lock() does not require
> to be taken with interrupts disabled.

The IRQ-off vs in-IRQ working was chosen poorly.

> Please be precise about these kind of things. Handwavy descriptions
> cause more problems than they solve.
> 
> > RT complains here because the spinlock_t must not be acquired with
> > disabled interrupts.
> >
> > use_temporary_mm() expects interrupts to be off because it invokes
> > switch_mm_irqs_off() and uses per-CPU (current active mm) data.
> >
> > Move local_irq_save() after the the pte lock has been acquired. Move
> > local_irq_restore() after the pte lock has been released.
> 
> While part 1 is correct, part 2 is the exact opposite of what the patch
> does.
> 
>   Move the PTE lock handling outside the interrupt disabled region.
> 
> describes precisely what this is about without any gory details which
> can be seen in the patch itself. Hmm?

Oki reworded.

> Thanks,
> 
>         tglx

Sebastian

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts
  2020-08-13 10:47   ` Sebastian Andrzej Siewior
@ 2020-08-13 10:50     ` Sebastian Andrzej Siewior
  2020-08-13 11:13       ` peterz
  2020-08-13 12:15       ` [tip: x86/urgent] x86/alternatives: Acquire pte lock with interrupts enabled tip-bot2 for Sebastian Andrzej Siewior
  0 siblings, 2 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2020-08-13 10:50 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin

The pte lock is never acquired in-IRQ context so it does not require the
interrupts to be disabled.

RT complains here because the spinlock_t must not be acquired with
disabled interrupts.

use_temporary_mm() expects interrupts to be off because it invokes
switch_mm_irqs_off() and uses per-CPU (current active mm) data.

Move the PTE lock handling outside the interrupt disabled region.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v1…v2: Reword the patch description.

 arch/x86/kernel/alternative.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -875,8 +875,6 @@ static void *__text_poke(void *addr, con
 	 */
 	BUG_ON(!pages[0] || (cross_page_boundary && !pages[1]));
 
-	local_irq_save(flags);
-
 	/*
 	 * Map the page without the global bit, as TLB flushing is done with
 	 * flush_tlb_mm_range(), which is intended for non-global PTEs.
@@ -893,6 +891,8 @@ static void *__text_poke(void *addr, con
 	 */
 	VM_BUG_ON(!ptep);
 
+	local_irq_save(flags);
+
 	pte = mk_pte(pages[0], pgprot);
 	set_pte_at(poking_mm, poking_addr, ptep, pte);
 
@@ -942,8 +942,8 @@ static void *__text_poke(void *addr, con
 	 */
 	BUG_ON(memcmp(addr, opcode, len));
 
-	pte_unmap_unlock(ptep, ptl);
 	local_irq_restore(flags);
+	pte_unmap_unlock(ptep, ptl);
 	return addr;
 }
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts
  2020-08-13 10:50     ` [PATCH v2] " Sebastian Andrzej Siewior
@ 2020-08-13 11:13       ` peterz
  2020-08-13 12:15       ` [tip: x86/urgent] x86/alternatives: Acquire pte lock with interrupts enabled tip-bot2 for Sebastian Andrzej Siewior
  1 sibling, 0 replies; 7+ messages in thread
From: peterz @ 2020-08-13 11:13 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Thomas Gleixner, linux-kernel, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin

On Thu, Aug 13, 2020 at 12:50:26PM +0200, Sebastian Andrzej Siewior wrote:
> The pte lock is never acquired in-IRQ context so it does not require the
> interrupts to be disabled.
> 
> RT complains here because the spinlock_t must not be acquired with
> disabled interrupts.
> 
> use_temporary_mm() expects interrupts to be off because it invokes
> switch_mm_irqs_off() and uses per-CPU (current active mm) data.
> 
> Move the PTE lock handling outside the interrupt disabled region.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Agreed, this should be fine.

Acked-by; Peter Zijlstra (Intel) <peterz@infradead.org>

> ---
> v1…v2: Reword the patch description.
> 
>  arch/x86/kernel/alternative.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -875,8 +875,6 @@ static void *__text_poke(void *addr, con
>  	 */
>  	BUG_ON(!pages[0] || (cross_page_boundary && !pages[1]));
>  
> -	local_irq_save(flags);
> -
>  	/*
>  	 * Map the page without the global bit, as TLB flushing is done with
>  	 * flush_tlb_mm_range(), which is intended for non-global PTEs.
> @@ -893,6 +891,8 @@ static void *__text_poke(void *addr, con
>  	 */
>  	VM_BUG_ON(!ptep);
>  
> +	local_irq_save(flags);
> +
>  	pte = mk_pte(pages[0], pgprot);
>  	set_pte_at(poking_mm, poking_addr, ptep, pte);
>  
> @@ -942,8 +942,8 @@ static void *__text_poke(void *addr, con
>  	 */
>  	BUG_ON(memcmp(addr, opcode, len));
>  
> -	pte_unmap_unlock(ptep, ptl);
>  	local_irq_restore(flags);
> +	pte_unmap_unlock(ptep, ptl);
>  	return addr;
>  }
>  

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: x86/urgent] x86/alternatives: Acquire pte lock with interrupts enabled
  2020-08-13 10:50     ` [PATCH v2] " Sebastian Andrzej Siewior
  2020-08-13 11:13       ` peterz
@ 2020-08-13 12:15       ` tip-bot2 for Sebastian Andrzej Siewior
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2020-08-13 12:15 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Sebastian Andrzej Siewior, Thomas Gleixner, x86, LKML

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

Commit-ID:     a6d996cbd38b42341ad3fce74506b9fdc280e395
Gitweb:        https://git.kernel.org/tip/a6d996cbd38b42341ad3fce74506b9fdc280e395
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Thu, 13 Aug 2020 12:50:26 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 13 Aug 2020 14:11:54 +02:00

x86/alternatives: Acquire pte lock with interrupts enabled

pte lock is never acquired in-IRQ context so it does not require interrupts
to be disabled. The lock is a regular spinlock which cannot be acquired
with interrupts disabled on RT.

RT complains about pte_lock() in __text_poke() because it's invoked after
disabling interrupts.

__text_poke() has to disable interrupts as use_temporary_mm() expects
interrupts to be off because it invokes switch_mm_irqs_off() and uses
per-CPU (current active mm) data.

Move the PTE lock handling outside the interrupt disabled region.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by; Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20200813105026.bvugytmsso6muljw@linutronix.de

---
 arch/x86/kernel/alternative.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index c826cdd..34a1b85 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -874,8 +874,6 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 	 */
 	BUG_ON(!pages[0] || (cross_page_boundary && !pages[1]));
 
-	local_irq_save(flags);
-
 	/*
 	 * Map the page without the global bit, as TLB flushing is done with
 	 * flush_tlb_mm_range(), which is intended for non-global PTEs.
@@ -892,6 +890,8 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 	 */
 	VM_BUG_ON(!ptep);
 
+	local_irq_save(flags);
+
 	pte = mk_pte(pages[0], pgprot);
 	set_pte_at(poking_mm, poking_addr, ptep, pte);
 
@@ -941,8 +941,8 @@ static void *__text_poke(void *addr, const void *opcode, size_t len)
 	 */
 	BUG_ON(memcmp(addr, opcode, len));
 
-	pte_unmap_unlock(ptep, ptl);
 	local_irq_restore(flags);
+	pte_unmap_unlock(ptep, ptl);
 	return addr;
 }
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts
@ 2020-07-06 21:24 kernel test robot
  0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2020-07-06 21:24 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 14646 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200706164215.2502730-1-bigeasy@linutronix.de>
References: <20200706164215.2502730-1-bigeasy@linutronix.de>
TO: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
TO: linux-kernel(a)vger.kernel.org
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: x86(a)kernel.org
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Hi Sebastian,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tip/auto-latest]
[also build test WARNING on tip/x86/core linux/master linus/master v5.8-rc4 next-20200706]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use  as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Sebastian-Andrzej-Siewior/x86-alternatives-Let-__text_poke-acquire-the-pte-lock-with-enabled-interrupts/20200707-004337
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 1c14587141a0687e6550a7015b862904654cc9e0
:::::: branch date: 5 hours ago
:::::: commit date: 5 hours ago
config: x86_64-randconfig-s022-20200706 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-14-g8fce3d7a-dirty
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)

>> arch/x86/kernel/alternative.c:892:9: sparse: sparse: context imbalance in '__text_poke' - different lock contexts for basic block

# https://github.com/0day-ci/linux/commit/e7ef425f7ea312c70df464066b8b6b82eb48aeb5
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout e7ef425f7ea312c70df464066b8b6b82eb48aeb5
vim +/__text_poke +892 arch/x86/kernel/alternative.c

4fc19708b165c1 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-26  843  
e836673c9b4966 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  844  static void *__text_poke(void *addr, const void *opcode, size_t len)
e587cadd8f47e2 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-03-06  845  {
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  846  	bool cross_page_boundary = offset_in_page(addr) + len > PAGE_SIZE;
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  847  	struct page *pages[2] = {NULL};
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  848  	temp_mm_state_t prev;
78ff7fae04554b arch/x86/kernel/alternative.c  Masami Hiramatsu          2009-03-06  849  	unsigned long flags;
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  850  	pte_t pte, *ptep;
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  851  	spinlock_t *ptl;
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  852  	pgprot_t pgprot;
e587cadd8f47e2 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-03-06  853  
6fffacb30349e0 arch/x86/kernel/alternative.c  Pavel Tatashin            2018-07-19  854  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  855  	 * While boot memory allocator is running we cannot use struct pages as
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  856  	 * they are not yet initialized. There is no way to recover.
6fffacb30349e0 arch/x86/kernel/alternative.c  Pavel Tatashin            2018-07-19  857  	 */
6fffacb30349e0 arch/x86/kernel/alternative.c  Pavel Tatashin            2018-07-19  858  	BUG_ON(!after_bootmem);
6fffacb30349e0 arch/x86/kernel/alternative.c  Pavel Tatashin            2018-07-19  859  
b7b66baa8bc3f8 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-04-24  860  	if (!core_kernel_text((unsigned long)addr)) {
b7b66baa8bc3f8 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-04-24  861  		pages[0] = vmalloc_to_page(addr);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  862  		if (cross_page_boundary)
b7b66baa8bc3f8 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-04-24  863  			pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
b7b66baa8bc3f8 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-04-24  864  	} else {
b7b66baa8bc3f8 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-04-24  865  		pages[0] = virt_to_page(addr);
00c6b2d5d7b241 arch/x86/kernel/alternative.c  Ingo Molnar               2008-04-25  866  		WARN_ON(!PageReserved(pages[0]));
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  867  		if (cross_page_boundary)
b7b66baa8bc3f8 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-04-24  868  			pages[1] = virt_to_page(addr + PAGE_SIZE);
b7b66baa8bc3f8 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-04-24  869  	}
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  870  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  871  	 * If something went wrong, crash and burn since recovery paths are not
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  872  	 * implemented.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  873  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  874  	BUG_ON(!pages[0] || (cross_page_boundary && !pages[1]));
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  875  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  876  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  877  	 * Map the page without the global bit, as TLB flushing is done with
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  878  	 * flush_tlb_mm_range(), which is intended for non-global PTEs.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  879  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  880  	pgprot = __pgprot(pgprot_val(PAGE_KERNEL) & ~_PAGE_GLOBAL);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  881  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  882  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  883  	 * The lock is not really needed, but this allows to avoid open-coding.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  884  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  885  	ptep = get_locked_pte(poking_mm, poking_addr, &ptl);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  886  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  887  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  888  	 * This must not fail; preallocated in poking_init().
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  889  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  890  	VM_BUG_ON(!ptep);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  891  
e7ef425f7ea312 arch/x86/kernel/alternative.c  Sebastian Andrzej Siewior 2020-07-06 @892  	local_irq_save(flags);
e7ef425f7ea312 arch/x86/kernel/alternative.c  Sebastian Andrzej Siewior 2020-07-06  893  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  894  	pte = mk_pte(pages[0], pgprot);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  895  	set_pte_at(poking_mm, poking_addr, ptep, pte);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  896  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  897  	if (cross_page_boundary) {
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  898  		pte = mk_pte(pages[1], pgprot);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  899  		set_pte_at(poking_mm, poking_addr + PAGE_SIZE, ptep + 1, pte);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  900  	}
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  901  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  902  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  903  	 * Loading the temporary mm behaves as a compiler barrier, which
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  904  	 * guarantees that the PTE will be set at the time memcpy() is done.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  905  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  906  	prev = use_temporary_mm(poking_mm);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  907  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  908  	kasan_disable_current();
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  909  	memcpy((u8 *)poking_addr + offset_in_page(addr), opcode, len);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  910  	kasan_enable_current();
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  911  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  912  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  913  	 * Ensure that the PTE is only cleared after the instructions of memcpy
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  914  	 * were issued by using a compiler barrier.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  915  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  916  	barrier();
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  917  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  918  	pte_clear(poking_mm, poking_addr, ptep);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  919  	if (cross_page_boundary)
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  920  		pte_clear(poking_mm, poking_addr + PAGE_SIZE, ptep + 1);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  921  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  922  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  923  	 * Loading the previous page-table hierarchy requires a serializing
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  924  	 * instruction that already allows the core to see the updated version.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  925  	 * Xen-PV is assumed to serialize execution in a similar manner.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  926  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  927  	unuse_temporary_mm(prev);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  928  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  929  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  930  	 * Flushing the TLB might involve IPIs, which would require enabled
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  931  	 * IRQs, but not if the mm is not used, as it is in this point.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  932  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  933  	flush_tlb_mm_range(poking_mm, poking_addr, poking_addr +
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  934  			   (cross_page_boundary ? 2 : 1) * PAGE_SIZE,
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  935  			   PAGE_SHIFT, false);
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  936  
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  937  	/*
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  938  	 * If the text does not match what we just wrote then something is
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  939  	 * fundamentally screwy; there's nothing we can really do about that.
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  940  	 */
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  941  	BUG_ON(memcmp(addr, opcode, len));
b3fd8e83ada0d5 arch/x86/kernel/alternative.c  Nadav Amit                2019-04-25  942  
7cf49427042400 arch/x86/kernel/alternative.c  Masami Hiramatsu          2009-03-09  943  	local_irq_restore(flags);
e7ef425f7ea312 arch/x86/kernel/alternative.c  Sebastian Andrzej Siewior 2020-07-06  944  	pte_unmap_unlock(ptep, ptl);
e587cadd8f47e2 arch/x86/kernel/alternative.c  Mathieu Desnoyers         2008-03-06  945  	return addr;
19d36ccdc34f5e arch/i386/kernel/alternative.c Andi Kleen                2007-07-22  946  }
3d55cc8a058ee9 arch/x86/kernel/alternative.c  Masami Hiramatsu          2010-02-25  947  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 35335 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-08-13 12:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 16:42 [PATCH] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts Sebastian Andrzej Siewior
2020-08-12 14:39 ` Thomas Gleixner
2020-08-13 10:47   ` Sebastian Andrzej Siewior
2020-08-13 10:50     ` [PATCH v2] " Sebastian Andrzej Siewior
2020-08-13 11:13       ` peterz
2020-08-13 12:15       ` [tip: x86/urgent] x86/alternatives: Acquire pte lock with interrupts enabled tip-bot2 for Sebastian Andrzej Siewior
2020-07-06 21:24 [PATCH] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.