diff mbox series

[v3,04/18] arm64: assembler: user_alt label optional

Message ID 20210520124406.2731873-5-tabba@google.com (mailing list archive)
State New, archived
Headers show
Series Tidy up cache.S | expand

Commit Message

Fuad Tabba May 20, 2021, 12:43 p.m. UTC
Make the label for the extable entry in user_alt optional, only
generating an extable entry if provided.

This is needed later in the series, to avoid instruction
duplication in the assembly code.

While at it, clean up the label used to be globally unique using
\@ as for other macros.

Signed-off-by: Fuad Tabba <tabba@google.com>
---
 arch/arm64/include/asm/alternative-macros.h | 9 ++++++---
 arch/arm64/mm/cache.S                       | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

Comments

Mark Rutland May 20, 2021, 12:57 p.m. UTC | #1
On Thu, May 20, 2021 at 01:43:52PM +0100, Fuad Tabba wrote:
> Make the label for the extable entry in user_alt optional, only
> generating an extable entry if provided.
> 
> This is needed later in the series, to avoid instruction
> duplication in the assembly code.
> 
> While at it, clean up the label used to be globally unique using
> \@ as for other macros.

Nice; thanks for cleaning up the labels too!

> 
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
>  arch/arm64/include/asm/alternative-macros.h | 9 ++++++---
>  arch/arm64/mm/cache.S                       | 2 +-
>  2 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h
> index 8a078fc662ac..01ef954c9b2d 100644
> --- a/arch/arm64/include/asm/alternative-macros.h
> +++ b/arch/arm64/include/asm/alternative-macros.h
> @@ -197,9 +197,12 @@ alternative_endif
>  #define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...)	\
>  	alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)
>  
> -.macro user_alt, label, oldinstr, newinstr, cond
> -9999:	alternative_insn "\oldinstr", "\newinstr", \cond
> -	_asm_extable 9999b, \label
> +.macro user_alt, oldinstr, newinstr, cond, label
> +.Lextable_\@:
> +	alternative_insn "\oldinstr", "\newinstr", \cond
> +	.ifnc \label,
> +	_asm_extable .Lextable_\@, \label
> +	.endif
>  .endm

We can use _cond_extable here to simplify this to:

| .macro user_alt, oldinstr, newinstr, cond, label
| .Lextable_\@:
| 	alternative_insn "\oldinstr", "\newinstr", \cond
| 	_cond_extable .Lextable_\@, \label
| .endm

However, since we only use user_alt in __flush_icache_range /
__flush_cache_user_range, I reckon it would be simpler overall to have
those use alternative_insn and _cond_extable directly. Then that would
align with the style of the *_by_line macros, and we could delete
user_alt.

Either way, this looks good, so:

Acked-by: Mark Rutland <mark.rutland@arm.com>

>  
>  #endif  /*  __ASSEMBLY__  */
> diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S
> index 2d881f34dd9d..5ff8dfa86975 100644
> --- a/arch/arm64/mm/cache.S
> +++ b/arch/arm64/mm/cache.S
> @@ -47,7 +47,7 @@ alternative_else_nop_endif
>  	sub	x3, x2, #1
>  	bic	x4, x0, x3
>  1:
> -user_alt 9f, "dc cvau, x4",  "dc civac, x4",  ARM64_WORKAROUND_CLEAN_CACHE
> +user_alt "dc cvau, x4",  "dc civac, x4",  ARM64_WORKAROUND_CLEAN_CACHE, 9f
>  	add	x4, x4, x2
>  	cmp	x4, x1
>  	b.lo	1b
> -- 
> 2.31.1.751.gd2f1c929bd-goog
>
Fuad Tabba May 21, 2021, 11:46 a.m. UTC | #2
Hi Mark,

On Thu, May 20, 2021 at 1:57 PM Mark Rutland <mark.rutland@arm.com> wrote:
>
> On Thu, May 20, 2021 at 01:43:52PM +0100, Fuad Tabba wrote:
> > Make the label for the extable entry in user_alt optional, only
> > generating an extable entry if provided.
> >
> > This is needed later in the series, to avoid instruction
> > duplication in the assembly code.
> >
> > While at it, clean up the label used to be globally unique using
> > \@ as for other macros.
>
> Nice; thanks for cleaning up the labels too!
>
> >
> > Signed-off-by: Fuad Tabba <tabba@google.com>
> > ---
> >  arch/arm64/include/asm/alternative-macros.h | 9 ++++++---
> >  arch/arm64/mm/cache.S                       | 2 +-
> >  2 files changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h
> > index 8a078fc662ac..01ef954c9b2d 100644
> > --- a/arch/arm64/include/asm/alternative-macros.h
> > +++ b/arch/arm64/include/asm/alternative-macros.h
> > @@ -197,9 +197,12 @@ alternative_endif
> >  #define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...)        \
> >       alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)
> >
> > -.macro user_alt, label, oldinstr, newinstr, cond
> > -9999:        alternative_insn "\oldinstr", "\newinstr", \cond
> > -     _asm_extable 9999b, \label
> > +.macro user_alt, oldinstr, newinstr, cond, label
> > +.Lextable_\@:
> > +     alternative_insn "\oldinstr", "\newinstr", \cond
> > +     .ifnc \label,
> > +     _asm_extable .Lextable_\@, \label
> > +     .endif
> >  .endm
>
> We can use _cond_extable here to simplify this to:
>
> | .macro user_alt, oldinstr, newinstr, cond, label
> | .Lextable_\@:
> |       alternative_insn "\oldinstr", "\newinstr", \cond
> |       _cond_extable .Lextable_\@, \label
> | .endm
>
> However, since we only use user_alt in __flush_icache_range /
> __flush_cache_user_range, I reckon it would be simpler overall to have
> those use alternative_insn and _cond_extable directly. Then that would
> align with the style of the *_by_line macros, and we could delete
> user_alt.

Thanks for this, and for the comments on the other patches in this
series. I'll rebase this series on rc3 when it comes out, apply your
suggestions, and send it out.

Cheers,
/fuad


>
> Either way, this looks good, so:
>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
>
> >
> >  #endif  /*  __ASSEMBLY__  */
> > diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S
> > index 2d881f34dd9d..5ff8dfa86975 100644
> > --- a/arch/arm64/mm/cache.S
> > +++ b/arch/arm64/mm/cache.S
> > @@ -47,7 +47,7 @@ alternative_else_nop_endif
> >       sub     x3, x2, #1
> >       bic     x4, x0, x3
> >  1:
> > -user_alt 9f, "dc cvau, x4",  "dc civac, x4",  ARM64_WORKAROUND_CLEAN_CACHE
> > +user_alt "dc cvau, x4",  "dc civac, x4",  ARM64_WORKAROUND_CLEAN_CACHE, 9f
> >       add     x4, x4, x2
> >       cmp     x4, x1
> >       b.lo    1b
> > --
> > 2.31.1.751.gd2f1c929bd-goog
> >
Mark Rutland May 21, 2021, 1:05 p.m. UTC | #3
On Fri, May 21, 2021 at 12:46:14PM +0100, Fuad Tabba wrote:
> I'll rebase this series on rc3 when it comes out, apply your
> suggestions, and send it out.

Great!

When that's out I'd be happy to throw my arm64 Syzkaller instance at it.

Mark.
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/alternative-macros.h b/arch/arm64/include/asm/alternative-macros.h
index 8a078fc662ac..01ef954c9b2d 100644
--- a/arch/arm64/include/asm/alternative-macros.h
+++ b/arch/arm64/include/asm/alternative-macros.h
@@ -197,9 +197,12 @@  alternative_endif
 #define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...)	\
 	alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)
 
-.macro user_alt, label, oldinstr, newinstr, cond
-9999:	alternative_insn "\oldinstr", "\newinstr", \cond
-	_asm_extable 9999b, \label
+.macro user_alt, oldinstr, newinstr, cond, label
+.Lextable_\@:
+	alternative_insn "\oldinstr", "\newinstr", \cond
+	.ifnc \label,
+	_asm_extable .Lextable_\@, \label
+	.endif
 .endm
 
 #endif  /*  __ASSEMBLY__  */
diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S
index 2d881f34dd9d..5ff8dfa86975 100644
--- a/arch/arm64/mm/cache.S
+++ b/arch/arm64/mm/cache.S
@@ -47,7 +47,7 @@  alternative_else_nop_endif
 	sub	x3, x2, #1
 	bic	x4, x0, x3
 1:
-user_alt 9f, "dc cvau, x4",  "dc civac, x4",  ARM64_WORKAROUND_CLEAN_CACHE
+user_alt "dc cvau, x4",  "dc civac, x4",  ARM64_WORKAROUND_CLEAN_CACHE, 9f
 	add	x4, x4, x2
 	cmp	x4, x1
 	b.lo	1b