mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests
@ 2023-03-06 12:32 Juergen Gross
  2023-03-06 14:08 ` Dave Hansen
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Juergen Gross @ 2023-03-06 12:32 UTC (permalink / raw)
  To: linux-kernel, x86
  Cc: Juergen Gross, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, H. Peter Anvin

Normally __swp_entry_to_pte() is never called with a value translating
to a valid PTE. The only known exception is pte_swap_tests(), resulting
in a WARN splat in Xen PV guests, as __pte_to_swp_entry() did
translate the PFN of the valid PTE to a guest local PFN, while
__swp_entry_to_pte() doesn't do the opposite translation.

Fix that by using __pte() in __swp_entry_to_pte() instead of open
coding the native variant of it.

For correctness do the similar conversion for __swp_entry_to_pmd().

Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features")
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/include/asm/pgtable_64.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 7929327abe00..a629b1b9f65a 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -237,8 +237,8 @@ static inline void native_pgd_clear(pgd_t *pgd)
 
 #define __pte_to_swp_entry(pte)		((swp_entry_t) { pte_val((pte)) })
 #define __pmd_to_swp_entry(pmd)		((swp_entry_t) { pmd_val((pmd)) })
-#define __swp_entry_to_pte(x)		((pte_t) { .pte = (x).val })
-#define __swp_entry_to_pmd(x)		((pmd_t) { .pmd = (x).val })
+#define __swp_entry_to_pte(x)		(__pte((x).val))
+#define __swp_entry_to_pmd(x)		(__pmd((x).val))
 
 extern void cleanup_highmap(void);
 
-- 
2.35.3


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

* Re: [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests
  2023-03-06 12:32 [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests Juergen Gross
@ 2023-03-06 14:08 ` Dave Hansen
  2023-03-06 14:25   ` Juergen Gross
  2023-03-27 14:26 ` Juergen Gross
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Dave Hansen @ 2023-03-06 14:08 UTC (permalink / raw)
  To: Juergen Gross, linux-kernel, x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin

On 3/6/23 04:32, Juergen Gross wrote:
> Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features")
> Signed-off-by: Juergen Gross <jgross@suse.com>

This looks sane.  Any reason this shouldn't be cc:stable@?

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

* Re: [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests
  2023-03-06 14:08 ` Dave Hansen
@ 2023-03-06 14:25   ` Juergen Gross
  0 siblings, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2023-03-06 14:25 UTC (permalink / raw)
  To: Dave Hansen, linux-kernel, x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin


[-- Attachment #1.1.1: Type: text/plain, Size: 609 bytes --]

On 06.03.23 15:08, Dave Hansen wrote:
> On 3/6/23 04:32, Juergen Gross wrote:
>> Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features")
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> This looks sane.  Any reason this shouldn't be cc:stable@?

It wasn't missed for several years now, and production kernels will
probably not have CONFIG_DEBUG_VM_PGTABLE set.

In the end I don't mind either way. It was just a bug I stumbled over
during development of my MTRR series (someone mentioned a problem and
I enabled said config option).


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

* Re: [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests
  2023-03-06 12:32 [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests Juergen Gross
  2023-03-06 14:08 ` Dave Hansen
@ 2023-03-27 14:26 ` Juergen Gross
  2023-04-25  8:32 ` Juergen Gross
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2023-03-27 14:26 UTC (permalink / raw)
  To: linux-kernel, x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin


[-- Attachment #1.1.1: Type: text/plain, Size: 792 bytes --]

On 06.03.23 13:32, Juergen Gross wrote:
> Normally __swp_entry_to_pte() is never called with a value translating
> to a valid PTE. The only known exception is pte_swap_tests(), resulting
> in a WARN splat in Xen PV guests, as __pte_to_swp_entry() did
> translate the PFN of the valid PTE to a guest local PFN, while
> __swp_entry_to_pte() doesn't do the opposite translation.
> 
> Fix that by using __pte() in __swp_entry_to_pte() instead of open
> coding the native variant of it.
> 
> For correctness do the similar conversion for __swp_entry_to_pmd().
> 
> Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features")
> Signed-off-by: Juergen Gross <jgross@suse.com>

Any further comments (apart from "It looks sane")?


Juergen


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

* Re: [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests
  2023-03-06 12:32 [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests Juergen Gross
  2023-03-06 14:08 ` Dave Hansen
  2023-03-27 14:26 ` Juergen Gross
@ 2023-04-25  8:32 ` Juergen Gross
  2023-05-08 12:23 ` Juergen Gross
  2023-05-08 13:41 ` [tip: x86/mm] x86/mm: Fix " tip-bot2 for Juergen Gross
  4 siblings, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2023-04-25  8:32 UTC (permalink / raw)
  To: linux-kernel, x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin


[-- Attachment #1.1.1: Type: text/plain, Size: 1568 bytes --]

Ping?

On 06.03.23 13:32, Juergen Gross wrote:
> Normally __swp_entry_to_pte() is never called with a value translating
> to a valid PTE. The only known exception is pte_swap_tests(), resulting
> in a WARN splat in Xen PV guests, as __pte_to_swp_entry() did
> translate the PFN of the valid PTE to a guest local PFN, while
> __swp_entry_to_pte() doesn't do the opposite translation.
> 
> Fix that by using __pte() in __swp_entry_to_pte() instead of open
> coding the native variant of it.
> 
> For correctness do the similar conversion for __swp_entry_to_pmd().
> 
> Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features")
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>   arch/x86/include/asm/pgtable_64.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
> index 7929327abe00..a629b1b9f65a 100644
> --- a/arch/x86/include/asm/pgtable_64.h
> +++ b/arch/x86/include/asm/pgtable_64.h
> @@ -237,8 +237,8 @@ static inline void native_pgd_clear(pgd_t *pgd)
>   
>   #define __pte_to_swp_entry(pte)		((swp_entry_t) { pte_val((pte)) })
>   #define __pmd_to_swp_entry(pmd)		((swp_entry_t) { pmd_val((pmd)) })
> -#define __swp_entry_to_pte(x)		((pte_t) { .pte = (x).val })
> -#define __swp_entry_to_pmd(x)		((pmd_t) { .pmd = (x).val })
> +#define __swp_entry_to_pte(x)		(__pte((x).val))
> +#define __swp_entry_to_pmd(x)		(__pmd((x).val))
>   
>   extern void cleanup_highmap(void);
>   


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

* Re: [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests
  2023-03-06 12:32 [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests Juergen Gross
                   ` (2 preceding siblings ...)
  2023-04-25  8:32 ` Juergen Gross
@ 2023-05-08 12:23 ` Juergen Gross
  2023-05-08 13:41 ` [tip: x86/mm] x86/mm: Fix " tip-bot2 for Juergen Gross
  4 siblings, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2023-05-08 12:23 UTC (permalink / raw)
  To: linux-kernel, x86
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin


[-- Attachment #1.1.1: Type: text/plain, Size: 1726 bytes --]

PING (3rd one, after 2 months of getting no feedback)!

I'm inclined to carry it just via the Xen tree if x86 maintainers continue
to ignore it ...


Juergen

On 06.03.23 13:32, Juergen Gross wrote:
> Normally __swp_entry_to_pte() is never called with a value translating
> to a valid PTE. The only known exception is pte_swap_tests(), resulting
> in a WARN splat in Xen PV guests, as __pte_to_swp_entry() did
> translate the PFN of the valid PTE to a guest local PFN, while
> __swp_entry_to_pte() doesn't do the opposite translation.
> 
> Fix that by using __pte() in __swp_entry_to_pte() instead of open
> coding the native variant of it.
> 
> For correctness do the similar conversion for __swp_entry_to_pmd().
> 
> Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features")
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>   arch/x86/include/asm/pgtable_64.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
> index 7929327abe00..a629b1b9f65a 100644
> --- a/arch/x86/include/asm/pgtable_64.h
> +++ b/arch/x86/include/asm/pgtable_64.h
> @@ -237,8 +237,8 @@ static inline void native_pgd_clear(pgd_t *pgd)
>   
>   #define __pte_to_swp_entry(pte)		((swp_entry_t) { pte_val((pte)) })
>   #define __pmd_to_swp_entry(pmd)		((swp_entry_t) { pmd_val((pmd)) })
> -#define __swp_entry_to_pte(x)		((pte_t) { .pte = (x).val })
> -#define __swp_entry_to_pmd(x)		((pmd_t) { .pmd = (x).val })
> +#define __swp_entry_to_pte(x)		(__pte((x).val))
> +#define __swp_entry_to_pmd(x)		(__pmd((x).val))
>   
>   extern void cleanup_highmap(void);
>   


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

* [tip: x86/mm] x86/mm: Fix __swp_entry_to_pte() for Xen PV guests
  2023-03-06 12:32 [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests Juergen Gross
                   ` (3 preceding siblings ...)
  2023-05-08 12:23 ` Juergen Gross
@ 2023-05-08 13:41 ` tip-bot2 for Juergen Gross
  4 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Juergen Gross @ 2023-05-08 13:41 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Juergen Gross, Borislav Petkov (AMD), x86, linux-kernel

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

Commit-ID:     0f88130e8a6fd185b0aeb5d8e286083735f2585a
Gitweb:        https://git.kernel.org/tip/0f88130e8a6fd185b0aeb5d8e286083735f2585a
Author:        Juergen Gross <jgross@suse.com>
AuthorDate:    Mon, 06 Mar 2023 13:32:59 +01:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 08 May 2023 15:25:24 +02:00

x86/mm: Fix __swp_entry_to_pte() for Xen PV guests

Normally __swp_entry_to_pte() is never called with a value translating
to a valid PTE. The only known exception is pte_swap_tests(), resulting
in a WARN splat in Xen PV guests, as __pte_to_swp_entry() did
translate the PFN of the valid PTE to a guest local PFN, while
__swp_entry_to_pte() doesn't do the opposite translation.

Fix that by using __pte() in __swp_entry_to_pte() instead of open
coding the native variant of it.

For correctness do the similar conversion for __swp_entry_to_pmd().

Fixes: 05289402d717 ("mm/debug_vm_pgtable: add tests validating arch helpers for core MM features")
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20230306123259.12461-1-jgross@suse.com
---
 arch/x86/include/asm/pgtable_64.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 7929327..a629b1b 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -237,8 +237,8 @@ static inline void native_pgd_clear(pgd_t *pgd)
 
 #define __pte_to_swp_entry(pte)		((swp_entry_t) { pte_val((pte)) })
 #define __pmd_to_swp_entry(pmd)		((swp_entry_t) { pmd_val((pmd)) })
-#define __swp_entry_to_pte(x)		((pte_t) { .pte = (x).val })
-#define __swp_entry_to_pmd(x)		((pmd_t) { .pmd = (x).val })
+#define __swp_entry_to_pte(x)		(__pte((x).val))
+#define __swp_entry_to_pmd(x)		(__pmd((x).val))
 
 extern void cleanup_highmap(void);
 

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

end of thread, other threads:[~2023-05-08 13:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 12:32 [PATCH] x86/mm: fix __swp_entry_to_pte() for Xen PV guests Juergen Gross
2023-03-06 14:08 ` Dave Hansen
2023-03-06 14:25   ` Juergen Gross
2023-03-27 14:26 ` Juergen Gross
2023-04-25  8:32 ` Juergen Gross
2023-05-08 12:23 ` Juergen Gross
2023-05-08 13:41 ` [tip: x86/mm] x86/mm: Fix " tip-bot2 for Juergen Gross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®