2022-02-19 00:55:06

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH 02/29] x86/module: Fix the paravirt vs alternative order

Ever since commit 4e6292114c741 ("x86/paravirt: Add new features for
paravirt patching") there is an ordering dependency between patching
paravirt ops and patching alternatives, the module loader still
violates this.

Fixes: 4e6292114c741 ("x86/paravirt: Add new features for paravirt patching")
Cc: Juergen Gross <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
arch/x86/kernel/module.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -272,6 +272,10 @@ int module_finalize(const Elf_Ehdr *hdr,
retpolines = s;
}

+ if (para) {
+ void *pseg = (void *)para->sh_addr;
+ apply_paravirt(pseg, pseg + para->sh_size);
+ }
if (retpolines) {
void *rseg = (void *)retpolines->sh_addr;
apply_retpolines(rseg, rseg + retpolines->sh_size);
@@ -289,11 +293,6 @@ int module_finalize(const Elf_Ehdr *hdr,
tseg, tseg + text->sh_size);
}

- if (para) {
- void *pseg = (void *)para->sh_addr;
- apply_paravirt(pseg, pseg + para->sh_size);
- }
-
/* make jump label nops */
jump_label_apply_nops(me);




2022-02-19 02:21:58

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH 02/29] x86/module: Fix the paravirt vs alternative order

On Fri, Feb 18, 2022 at 10:22:46PM +0100, Peter Zijlstra wrote:
> On Fri, Feb 18, 2022 at 12:28:20PM -0800, Josh Poimboeuf wrote:
> > On Fri, Feb 18, 2022 at 05:49:04PM +0100, Peter Zijlstra wrote:
> > > Ever since commit 4e6292114c741 ("x86/paravirt: Add new features for
> > > paravirt patching") there is an ordering dependency between patching
> > > paravirt ops and patching alternatives, the module loader still
> > > violates this.
> > >
> > > Fixes: 4e6292114c741 ("x86/paravirt: Add new features for paravirt patching")
> > > Cc: Juergen Gross <[email protected]>
> > > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> >
> > Probably a good idea to put the 'para' and 'alt' clauses next to each
> > other and add a comment that the ordering is necessary.
>
> Can't, retpolines must be in between, but I'll add a comment to check
> alternative.c for ordering constraints.

Ah, even more justification for a comment then ;-)

--
Josh

2022-02-19 21:57:05

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH 02/29] x86/module: Fix the paravirt vs alternative order

On Fri, Feb 18, 2022 at 05:49:04PM +0100, Peter Zijlstra wrote:
> Ever since commit 4e6292114c741 ("x86/paravirt: Add new features for
> paravirt patching") there is an ordering dependency between patching
> paravirt ops and patching alternatives, the module loader still
> violates this.
>
> Fixes: 4e6292114c741 ("x86/paravirt: Add new features for paravirt patching")
> Cc: Juergen Gross <[email protected]>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>

Probably a good idea to put the 'para' and 'alt' clauses next to each
other and add a comment that the ordering is necessary.

> ---
> arch/x86/kernel/module.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> --- a/arch/x86/kernel/module.c
> +++ b/arch/x86/kernel/module.c
> @@ -272,6 +272,10 @@ int module_finalize(const Elf_Ehdr *hdr,
> retpolines = s;
> }
>
> + if (para) {
> + void *pseg = (void *)para->sh_addr;
> + apply_paravirt(pseg, pseg + para->sh_size);
> + }
> if (retpolines) {
> void *rseg = (void *)retpolines->sh_addr;
> apply_retpolines(rseg, rseg + retpolines->sh_size);
> @@ -289,11 +293,6 @@ int module_finalize(const Elf_Ehdr *hdr,
> tseg, tseg + text->sh_size);
> }
>
> - if (para) {
> - void *pseg = (void *)para->sh_addr;
> - apply_paravirt(pseg, pseg + para->sh_size);
> - }
> -
> /* make jump label nops */
> jump_label_apply_nops(me);
>
>
>

--
Josh

2022-02-21 09:07:49

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 02/29] x86/module: Fix the paravirt vs alternative order

On Fri, Feb 18, 2022 at 12:28:20PM -0800, Josh Poimboeuf wrote:
> On Fri, Feb 18, 2022 at 05:49:04PM +0100, Peter Zijlstra wrote:
> > Ever since commit 4e6292114c741 ("x86/paravirt: Add new features for
> > paravirt patching") there is an ordering dependency between patching
> > paravirt ops and patching alternatives, the module loader still
> > violates this.
> >
> > Fixes: 4e6292114c741 ("x86/paravirt: Add new features for paravirt patching")
> > Cc: Juergen Gross <[email protected]>
> > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
>
> Probably a good idea to put the 'para' and 'alt' clauses next to each
> other and add a comment that the ordering is necessary.

Can't, retpolines must be in between, but I'll add a comment to check
alternative.c for ordering constraints.