linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
@ 2021-11-17 17:48 Ilie Halip
  2021-11-19  1:10 ` Nick Desaulniers
  0 siblings, 1 reply; 9+ messages in thread
From: Ilie Halip @ 2021-11-17 17:48 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ilie Halip, Nick Desaulniers, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, Alexander Gordeev, Nathan Chancellor,
	Mete Durlu, Sven Schnelle, linux-s390, llvm

Building with clang & LLVM_IAS=1 leads to an error:
    arch/s390/lib/test_unwind.c:179:4: error: invalid register pair
                        "       mvcl    %%r1,%%r1\n"
                        ^

The test creates an invalid instruction that would trap at runtime, but the
LLVM inline assembler tries to validate it at compile time too.

Use the raw instruction opcode instead.

Link: https://github.com/ClangBuiltLinux/linux/issues/1421
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
---
 arch/s390/lib/test_unwind.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/lib/test_unwind.c b/arch/s390/lib/test_unwind.c
index cfc5f5557c06..d342bc884b94 100644
--- a/arch/s390/lib/test_unwind.c
+++ b/arch/s390/lib/test_unwind.c
@@ -176,7 +176,7 @@ static noinline int unwindme_func4(struct unwindme *u)
 		 * trigger specification exception
 		 */
 		asm volatile(
-			"	mvcl	%%r1,%%r1\n"
+			"	.insn e,0x0e11\n"	/* mvcl	%%r1,%%r1" */
 			"0:	nopr	%%r7\n"
 			EX_TABLE(0b, 0b)
 			:);
-- 
2.25.1


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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-17 17:48 [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction Ilie Halip
@ 2021-11-19  1:10 ` Nick Desaulniers
  2021-11-19  9:39   ` Christian Borntraeger
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Desaulniers @ 2021-11-19  1:10 UTC (permalink / raw)
  To: Ilie Halip
  Cc: linux-kernel, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, Alexander Gordeev, Nathan Chancellor,
	Mete Durlu, Sven Schnelle, linux-s390, llvm, Ulrich Weigand

On Wed, Nov 17, 2021 at 9:48 AM Ilie Halip <ilie.halip@gmail.com> wrote:
>
> Building with clang & LLVM_IAS=1 leads to an error:
>     arch/s390/lib/test_unwind.c:179:4: error: invalid register pair
>                         "       mvcl    %%r1,%%r1\n"
>                         ^
>
> The test creates an invalid instruction that would trap at runtime, but the
> LLVM inline assembler tries to validate it at compile time too.
>
> Use the raw instruction opcode instead.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1421
> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Ilie Halip <ilie.halip@gmail.com>

Ilie, thanks for the patch!

So if I understand
https://sourceware.org/binutils/docs/as/s390-Directives.html#s390-Directives
https://sourceware.org/binutils/docs/as/s390-Formats.html
that `e,` prefix is for 16B opcodes?

LGTM, thanks again.
Suggested-by: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

I triple checked that GAS, clang, and GNU objdump are in agreement in
terms of encoding here.

> ---
>  arch/s390/lib/test_unwind.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/s390/lib/test_unwind.c b/arch/s390/lib/test_unwind.c
> index cfc5f5557c06..d342bc884b94 100644
> --- a/arch/s390/lib/test_unwind.c
> +++ b/arch/s390/lib/test_unwind.c
> @@ -176,7 +176,7 @@ static noinline int unwindme_func4(struct unwindme *u)
>                  * trigger specification exception
>                  */
>                 asm volatile(
> -                       "       mvcl    %%r1,%%r1\n"
> +                       "       .insn e,0x0e11\n"       /* mvcl %%r1,%%r1" */
>                         "0:     nopr    %%r7\n"
>                         EX_TABLE(0b, 0b)
>                         :);
> --
> 2.25.1
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-19  1:10 ` Nick Desaulniers
@ 2021-11-19  9:39   ` Christian Borntraeger
  2021-11-19  9:44     ` Christian Borntraeger
  2021-11-19 10:54     ` Heiko Carstens
  0 siblings, 2 replies; 9+ messages in thread
From: Christian Borntraeger @ 2021-11-19  9:39 UTC (permalink / raw)
  To: Nick Desaulniers, Ilie Halip
  Cc: linux-kernel, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Nathan Chancellor, Mete Durlu, Sven Schnelle, linux-s390, llvm,
	Ulrich Weigand



Am 19.11.21 um 02:10 schrieb Nick Desaulniers:
> On Wed, Nov 17, 2021 at 9:48 AM Ilie Halip <ilie.halip@gmail.com> wrote:
>>
>> Building with clang & LLVM_IAS=1 leads to an error:
>>      arch/s390/lib/test_unwind.c:179:4: error: invalid register pair
>>                          "       mvcl    %%r1,%%r1\n"
>>                          ^
>>
>> The test creates an invalid instruction that would trap at runtime, but the
>> LLVM inline assembler tries to validate it at compile time too.
>>
>> Use the raw instruction opcode instead.
>>
>> Link: https://github.com/ClangBuiltLinux/linux/issues/1421
>> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
>> Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
> 
> Ilie, thanks for the patch!
> 
> So if I understand
> https://sourceware.org/binutils/docs/as/s390-Directives.html#s390-Directives
> https://sourceware.org/binutils/docs/as/s390-Formats.html
> that `e,` prefix is for 16B opcodes?

e is an instruction format as specified by the architecture.
See http://publibfp.dhe.ibm.com/epubs/pdf/a227832c.pdf
without any parameters.
Normally RR would be the right thing for MVCL, but since
we try to build an invalid opcode without the assembler
noticing (ab)using e seem like a safer approach.

> 
> LGTM, thanks again.
> Suggested-by: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

added those and added my RB. applied to the s390 tree. Thanks


> 
> I triple checked that GAS, clang, and GNU objdump are in agreement in
> terms of encoding here.
> 
>> ---
>>   arch/s390/lib/test_unwind.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/s390/lib/test_unwind.c b/arch/s390/lib/test_unwind.c
>> index cfc5f5557c06..d342bc884b94 100644
>> --- a/arch/s390/lib/test_unwind.c
>> +++ b/arch/s390/lib/test_unwind.c
>> @@ -176,7 +176,7 @@ static noinline int unwindme_func4(struct unwindme *u)
>>                   * trigger specification exception
>>                   */
>>                  asm volatile(
>> -                       "       mvcl    %%r1,%%r1\n"
>> +                       "       .insn e,0x0e11\n"       /* mvcl %%r1,%%r1" */
>>                          "0:     nopr    %%r7\n"
>>                          EX_TABLE(0b, 0b)
>>                          :);
>> --
>> 2.25.1
>>
> 
> 

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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-19  9:39   ` Christian Borntraeger
@ 2021-11-19  9:44     ` Christian Borntraeger
  2021-11-19 10:54     ` Heiko Carstens
  1 sibling, 0 replies; 9+ messages in thread
From: Christian Borntraeger @ 2021-11-19  9:44 UTC (permalink / raw)
  To: Nick Desaulniers, Ilie Halip
  Cc: linux-kernel, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Nathan Chancellor, Mete Durlu, Sven Schnelle, linux-s390, llvm,
	Ulrich Weigand



Am 19.11.21 um 10:39 schrieb Christian Borntraeger:
> 
> 
> Am 19.11.21 um 02:10 schrieb Nick Desaulniers:
>> On Wed, Nov 17, 2021 at 9:48 AM Ilie Halip <ilie.halip@gmail.com> wrote:
>>>
>>> Building with clang & LLVM_IAS=1 leads to an error:
>>>      arch/s390/lib/test_unwind.c:179:4: error: invalid register pair
>>>                          "       mvcl    %%r1,%%r1\n"
>>>                          ^
>>>
>>> The test creates an invalid instruction that would trap at runtime, but the
>>> LLVM inline assembler tries to validate it at compile time too.
>>>
>>> Use the raw instruction opcode instead.
>>>
>>> Link: https://github.com/ClangBuiltLinux/linux/issues/1421
>>> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
>>> Signed-off-by: Ilie Halip <ilie.halip@gmail.com>
>>
>> Ilie, thanks for the patch!
>>
>> So if I understand
>> https://sourceware.org/binutils/docs/as/s390-Directives.html#s390-Directives
>> https://sourceware.org/binutils/docs/as/s390-Formats.html
>> that `e,` prefix is for 16B opcodes?
> 
> e is an instruction format as specified by the architecture.
> See http://publibfp.dhe.ibm.com/epubs/pdf/a227832c.pdf

(page 5-3 for the instruction formats and page 7-289 for MVCL)

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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-19  9:39   ` Christian Borntraeger
  2021-11-19  9:44     ` Christian Borntraeger
@ 2021-11-19 10:54     ` Heiko Carstens
  2021-11-19 10:57       ` Christian Borntraeger
  1 sibling, 1 reply; 9+ messages in thread
From: Heiko Carstens @ 2021-11-19 10:54 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Nick Desaulniers, Ilie Halip, linux-kernel, Vasily Gorbik,
	Alexander Gordeev, Nathan Chancellor, Mete Durlu, Sven Schnelle,
	linux-s390, llvm, Ulrich Weigand

On Fri, Nov 19, 2021 at 10:39:15AM +0100, Christian Borntraeger wrote:
> > So if I understand
> > https://sourceware.org/binutils/docs/as/s390-Directives.html#s390-Directives
> > https://sourceware.org/binutils/docs/as/s390-Formats.html
> > that `e,` prefix is for 16B opcodes?
> 
> e is an instruction format as specified by the architecture.
> See http://publibfp.dhe.ibm.com/epubs/pdf/a227832c.pdf
> without any parameters.
> Normally RR would be the right thing for MVCL, but since
> we try to build an invalid opcode without the assembler
> noticing (ab)using e seem like a safer approach.
> > 
> > LGTM, thanks again.
> > Suggested-by: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> 
> added those and added my RB. applied to the s390 tree. Thanks
..
> > > diff --git a/arch/s390/lib/test_unwind.c b/arch/s390/lib/test_unwind.c
> > > index cfc5f5557c06..d342bc884b94 100644
> > > --- a/arch/s390/lib/test_unwind.c
> > > +++ b/arch/s390/lib/test_unwind.c
> > > @@ -176,7 +176,7 @@ static noinline int unwindme_func4(struct unwindme *u)
> > >                   * trigger specification exception
> > >                   */
> > >                  asm volatile(
> > > -                       "       mvcl    %%r1,%%r1\n"
> > > +                       "       .insn e,0x0e11\n"       /* mvcl %%r1,%%r1" */

Sorry, I disagree with this. As you said above rr would be the correct
format for this instruction. If we go for the e format then we should
also use an instruction with e format.
Which in this case would simply be an illegal opcode, which would be
sufficient for what this code is good for: ".insn e,0x0000".

Plus a fixup of the comment above, since this would generate an
operation insteand of a specification exception. Just a generic
"exception" would be good enough for the comment.

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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-19 10:54     ` Heiko Carstens
@ 2021-11-19 10:57       ` Christian Borntraeger
  2021-11-19 11:09         ` Heiko Carstens
  0 siblings, 1 reply; 9+ messages in thread
From: Christian Borntraeger @ 2021-11-19 10:57 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Nick Desaulniers, Ilie Halip, linux-kernel, Vasily Gorbik,
	Alexander Gordeev, Nathan Chancellor, Mete Durlu, Sven Schnelle,
	linux-s390, llvm, Ulrich Weigand



Am 19.11.21 um 11:54 schrieb Heiko Carstens:
> On Fri, Nov 19, 2021 at 10:39:15AM +0100, Christian Borntraeger wrote:
>>> So if I understand
>>> https://sourceware.org/binutils/docs/as/s390-Directives.html#s390-Directives
>>> https://sourceware.org/binutils/docs/as/s390-Formats.html
>>> that `e,` prefix is for 16B opcodes?
>>
>> e is an instruction format as specified by the architecture.
>> See http://publibfp.dhe.ibm.com/epubs/pdf/a227832c.pdf
>> without any parameters.
>> Normally RR would be the right thing for MVCL, but since
>> we try to build an invalid opcode without the assembler
>> noticing (ab)using e seem like a safer approach.
>>>
>>> LGTM, thanks again.
>>> Suggested-by: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
>>> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>>
>> added those and added my RB. applied to the s390 tree. Thanks
> ..
>>>> diff --git a/arch/s390/lib/test_unwind.c b/arch/s390/lib/test_unwind.c
>>>> index cfc5f5557c06..d342bc884b94 100644
>>>> --- a/arch/s390/lib/test_unwind.c
>>>> +++ b/arch/s390/lib/test_unwind.c
>>>> @@ -176,7 +176,7 @@ static noinline int unwindme_func4(struct unwindme *u)
>>>>                    * trigger specification exception
>>>>                    */
>>>>                   asm volatile(
>>>> -                       "       mvcl    %%r1,%%r1\n"
>>>> +                       "       .insn e,0x0e11\n"       /* mvcl %%r1,%%r1" */
> 
> Sorry, I disagree with this. As you said above rr would be the correct
> format for this instruction. If we go for the e format then we should
> also use an instruction with e format.
> Which in this case would simply be an illegal opcode, which would be
> sufficient for what this code is good for: ".insn e,0x0000".

Why not simply use .short then?

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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-19 10:57       ` Christian Borntraeger
@ 2021-11-19 11:09         ` Heiko Carstens
  2021-11-19 14:12           ` Christian Borntraeger
  0 siblings, 1 reply; 9+ messages in thread
From: Heiko Carstens @ 2021-11-19 11:09 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Nick Desaulniers, Ilie Halip, linux-kernel, Vasily Gorbik,
	Alexander Gordeev, Nathan Chancellor, Mete Durlu, Sven Schnelle,
	linux-s390, llvm, Ulrich Weigand

On Fri, Nov 19, 2021 at 11:57:05AM +0100, Christian Borntraeger wrote:
> > > > > -                       "       mvcl    %%r1,%%r1\n"
> > > > > +                       "       .insn e,0x0e11\n"       /* mvcl %%r1,%%r1" */
> > 
> > Sorry, I disagree with this. As you said above rr would be the correct
> > format for this instruction. If we go for the e format then we should
> > also use an instruction with e format.
> > Which in this case would simply be an illegal opcode, which would be
> > sufficient for what this code is good for: ".insn e,0x0000".
> 
> Why not simply use .short then?

.short bypasses all sanity checks while .insn does not, so I think
that should be preferred. But I don't care too much.

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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-19 11:09         ` Heiko Carstens
@ 2021-11-19 14:12           ` Christian Borntraeger
  2021-11-19 15:15             ` Heiko Carstens
  0 siblings, 1 reply; 9+ messages in thread
From: Christian Borntraeger @ 2021-11-19 14:12 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Nick Desaulniers, Ilie Halip, linux-kernel, Vasily Gorbik,
	Alexander Gordeev, Nathan Chancellor, Mete Durlu, Sven Schnelle,
	linux-s390, llvm, Ulrich Weigand



Am 19.11.21 um 12:09 schrieb Heiko Carstens:
> On Fri, Nov 19, 2021 at 11:57:05AM +0100, Christian Borntraeger wrote:
>>>>>> -                       "       mvcl    %%r1,%%r1\n"
>>>>>> +                       "       .insn e,0x0e11\n"       /* mvcl %%r1,%%r1" */
>>>
>>> Sorry, I disagree with this. As you said above rr would be the correct
>>> format for this instruction. If we go for the e format then we should
>>> also use an instruction with e format.
>>> Which in this case would simply be an illegal opcode, which would be
>>> sufficient for what this code is good for: ".insn e,0x0000".
>>
>> Why not simply use .short then?
> 
> .short bypasses all sanity checks while .insn does not, so I think
> that should be preferred. But I don't care too much.

Heiko,
I am fine with ".insn e,0x0000" and the a changed comment that changes "specification exception" to "operation exception".
Do you want Ilie to resend or simply fixup?

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

* Re: [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction
  2021-11-19 14:12           ` Christian Borntraeger
@ 2021-11-19 15:15             ` Heiko Carstens
  0 siblings, 0 replies; 9+ messages in thread
From: Heiko Carstens @ 2021-11-19 15:15 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: Nick Desaulniers, Ilie Halip, linux-kernel, Vasily Gorbik,
	Alexander Gordeev, Nathan Chancellor, Mete Durlu, Sven Schnelle,
	linux-s390, llvm, Ulrich Weigand

On Fri, Nov 19, 2021 at 03:12:03PM +0100, Christian Borntraeger wrote:
> Am 19.11.21 um 12:09 schrieb Heiko Carstens:
> > On Fri, Nov 19, 2021 at 11:57:05AM +0100, Christian Borntraeger wrote:
> > > > > > > -                       "       mvcl    %%r1,%%r1\n"
> > > > > > > +                       "       .insn e,0x0e11\n"       /* mvcl %%r1,%%r1" */
> > > > 
> > > > Sorry, I disagree with this. As you said above rr would be the correct
> > > > format for this instruction. If we go for the e format then we should
> > > > also use an instruction with e format.
> > > > Which in this case would simply be an illegal opcode, which would be
> > > > sufficient for what this code is good for: ".insn e,0x0000".
> > > 
> > > Why not simply use .short then?
> > 
> > .short bypasses all sanity checks while .insn does not, so I think
> > that should be preferred. But I don't care too much.
> 
> Heiko,
> I am fine with ".insn e,0x0000" and the a changed comment that
> changes "specification exception" to "operation exception".  Do you
> want Ilie to resend or simply fixup?

I'll simply change it. Let's don't spend more time on this.

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

end of thread, other threads:[~2021-11-19 15:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 17:48 [PATCH] s390/test_unwind: use raw opcode instead of invalid instruction Ilie Halip
2021-11-19  1:10 ` Nick Desaulniers
2021-11-19  9:39   ` Christian Borntraeger
2021-11-19  9:44     ` Christian Borntraeger
2021-11-19 10:54     ` Heiko Carstens
2021-11-19 10:57       ` Christian Borntraeger
2021-11-19 11:09         ` Heiko Carstens
2021-11-19 14:12           ` Christian Borntraeger
2021-11-19 15:15             ` Heiko Carstens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).