live-patching.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: linux-next: Tree for May 21 (objtool warnings)
       [not found]       ` <20200526140113.ppjywpx7uir3vrlj@treble>
@ 2020-05-26 16:39         ` Miroslav Benes
  2020-05-27  8:57           ` Martin Jambor
  0 siblings, 1 reply; 3+ messages in thread
From: Miroslav Benes @ 2020-05-26 16:39 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Randy Dunlap, Stephen Rothwell, Linux Next Mailing List,
	Linux Kernel Mailing List, Peter Zijlstra, mjambor, mliska,
	pmladek, live-patching

On Tue, 26 May 2020, Josh Poimboeuf wrote:

> On Mon, May 25, 2020 at 01:07:27PM +0200, Miroslav Benes wrote:
> > > I'll try to find out which optimization does this, because it is a 
> > > slightly different scenario than hiding __noreturn from the callees. 
> > > Probably -fno-ipa-pure-const again.
> > 
> > And it is indeed -fno-ipa-pure-const again.
> 
> It still seems odd to me that GCC's dead end detection seems to break
> with -fno-ipa-pure-const.  Do you know if these issues can be fixed on
> the GCC side?

It is odd. I asked Martin and Martin about that yesterday (CCed). It could 
be possible to enable just noreturn propagation for -flive-patching if I 
understood correctly. The attribute would need to be preserved in a 
patched function then, but that should be manageable.

Marking functions as __noreturn is one thing (I think it is useful on its 
own as mentioned in the older thread about -flive-patching), but 
__always_inline solution in this case is really arbitrary. I don't like 
this neverending "battle" with compilers much, so it would be nice to have 
some kind of generic solution (and I currently have no idea about that). 
Of course, declaring -flive-patching a failed experiment is an option if 
there is not a better way to deal with a dead end detection either in GCC 
or in objtool. I would not like it, but you're right that if there are 
more and more problems like this appearing, we'll have to deal with 
maintainers all over the place and ask them to maintain odd fixes just for 
the sake of -flive-patching. I don't know what the current numbers are 
though. We'd have to approach the problem of GCC optimizations from a 
different angle. Petr CCed (we talked about it yesterday as well).

But first, let's try to find a way with -flive-patching.

Reduced test case follows (courtesty of Martin Liska):

$ cat open.i
int global;

void
break_deleg_wait()
{
  asm(".byte 15, 0x0b");
  __builtin_unreachable();
}

void chmod_common_delegated_inode(int arg)
{
retry_deleg:
  if (arg)
    break_deleg_wait(global);
  else
    return;
  goto retry_deleg;
}

$ gcc open.i -c -Os -fno-omit-frame-pointer -fno-ipa-pure-const && ./tools/objtool/objtool check open.o
open.o: warning: objtool: chmod_common_delegated_inode()+0x18: unreachable instruction

$ gcc open.i -c -Os -fno-omit-frame-pointer && ./tools/objtool/objtool check open.o
[OK]
---

So it is a similar problem. There is no noreturn attribute anywhere 
(nothing to propagate from a caller to a callee). Here, the information 
about an unreachable code is not propagated to the caller 
(chmod_common_delegated_inode()).

Martins, would it be possible to extend -flive-patching to deal with this?

Miroslav

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

* Re: linux-next: Tree for May 21 (objtool warnings)
  2020-05-26 16:39         ` linux-next: Tree for May 21 (objtool warnings) Miroslav Benes
@ 2020-05-27  8:57           ` Martin Jambor
  2020-05-27 15:09             ` Josh Poimboeuf
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Jambor @ 2020-05-27  8:57 UTC (permalink / raw)
  To: Miroslav Benes, Josh Poimboeuf
  Cc: Randy Dunlap, Stephen Rothwell, Linux Next Mailing List,
	Peter Zijlstra, mliska, pmladek, live-patching, Jan Hubicka

Hi,

On Tue, May 26 2020, Miroslav Benes wrote:
> On Tue, 26 May 2020, Josh Poimboeuf wrote:
>
>> On Mon, May 25, 2020 at 01:07:27PM +0200, Miroslav Benes wrote:
>> > > I'll try to find out which optimization does this, because it is a 
>> > > slightly different scenario than hiding __noreturn from the callees. 
>> > > Probably -fno-ipa-pure-const again.
>> > 
>> > And it is indeed -fno-ipa-pure-const again.
>> 
>> It still seems odd to me that GCC's dead end detection seems to break
>> with -fno-ipa-pure-const.  Do you know if these issues can be fixed on
>> the GCC side?
>
> It is odd. I asked Martin and Martin about that yesterday (CCed). It could 
> be possible to enable just noreturn propagation for -flive-patching if I 
> understood correctly. The attribute would need to be preserved in a 
> patched function then, but that should be manageable.
>
> Marking functions as __noreturn is one thing (I think it is useful on its 
> own as mentioned in the older thread about -flive-patching), but 
> __always_inline solution in this case is really arbitrary.

Noreturn functions generally tend to be very cold ones and so you do not
really want to inline them.

> I don't like 
> this neverending "battle" with compilers much, so it would be nice to have 
> some kind of generic solution (and I currently have no idea about that). 
> Of course, declaring -flive-patching a failed experiment is an option if 
> there is not a better way to deal with a dead end detection either in GCC 
> or in objtool. I would not like it, but you're right that if there are 
> more and more problems like this appearing, we'll have to deal with 
> maintainers all over the place and ask them to maintain odd fixes just for 
> the sake of -flive-patching. I don't know what the current numbers are 
> though. We'd have to approach the problem of GCC optimizations from a 
> different angle. Petr CCed (we talked about it yesterday as well).
>
> But first, let's try to find a way with -flive-patching.
>
> Reduced test case follows (courtesty of Martin Liska):
>
> $ cat open.i
> int global;
>
> void
> break_deleg_wait()
> {
>   asm(".byte 15, 0x0b");
>   __builtin_unreachable();
> }
>
> void chmod_common_delegated_inode(int arg)
> {
> retry_deleg:
>   if (arg)
>     break_deleg_wait(global);
>   else
>     return;
>   goto retry_deleg;
> }
>
> $ gcc open.i -c -Os -fno-omit-frame-pointer -fno-ipa-pure-const && ./tools/objtool/objtool check open.o
> open.o: warning: objtool: chmod_common_delegated_inode()+0x18: unreachable instruction
>
> $ gcc open.i -c -Os -fno-omit-frame-pointer && ./tools/objtool/objtool check open.o
> [OK]
> ---
>
> So it is a similar problem. There is no noreturn attribute anywhere 
> (nothing to propagate from a caller to a callee). Here, the information 
> about an unreachable code is not propagated to the caller 
> (chmod_common_delegated_inode()).
>
> Martins, would it be possible to extend -flive-patching to deal with
> this?

I think we could allow -fipa-pure-const with -flive-patching but make it
dump all the attributes it has assigned to all functions in some format
similar to what it does for all the internal clones GCC creates.  You
would then need to explicitely annotate functions in live patches with
these attributes - and of course make sure you do not violate them.

If this is too difficult for the full set of attributes, we can restrict
the pass to just propagate the noreturn attribute, but I think it's not
going to be necessary.

Martin

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

* Re: linux-next: Tree for May 21 (objtool warnings)
  2020-05-27  8:57           ` Martin Jambor
@ 2020-05-27 15:09             ` Josh Poimboeuf
  0 siblings, 0 replies; 3+ messages in thread
From: Josh Poimboeuf @ 2020-05-27 15:09 UTC (permalink / raw)
  To: Martin Jambor
  Cc: Miroslav Benes, Randy Dunlap, Stephen Rothwell,
	Linux Next Mailing List, Peter Zijlstra, mliska, pmladek,
	live-patching, Jan Hubicka

On Wed, May 27, 2020 at 10:57:53AM +0200, Martin Jambor wrote:
> Hi,
> 
> On Tue, May 26 2020, Miroslav Benes wrote:
> > On Tue, 26 May 2020, Josh Poimboeuf wrote:
> >
> >> On Mon, May 25, 2020 at 01:07:27PM +0200, Miroslav Benes wrote:
> >> > > I'll try to find out which optimization does this, because it is a 
> >> > > slightly different scenario than hiding __noreturn from the callees. 
> >> > > Probably -fno-ipa-pure-const again.
> >> > 
> >> > And it is indeed -fno-ipa-pure-const again.
> >> 
> >> It still seems odd to me that GCC's dead end detection seems to break
> >> with -fno-ipa-pure-const.  Do you know if these issues can be fixed on
> >> the GCC side?
> >
> > It is odd. I asked Martin and Martin about that yesterday (CCed). It could 
> > be possible to enable just noreturn propagation for -flive-patching if I 
> > understood correctly. The attribute would need to be preserved in a 
> > patched function then, but that should be manageable.
> >
> > Marking functions as __noreturn is one thing (I think it is useful on its 
> > own as mentioned in the older thread about -flive-patching), but 
> > __always_inline solution in this case is really arbitrary.
> 
> Noreturn functions generally tend to be very cold ones and so you do not
> really want to inline them.

The issue here is that with -fno-ipa-pure-const, GCC no longer
automatically detects that the static inline function is noreturn, so it
emits unreachable instructions after a call to it.

-- 
Josh


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

end of thread, other threads:[~2020-05-27 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200522001209.07c19400@canb.auug.org.au>
     [not found] ` <22332d9b-5e9f-5474-adac-9b3e39861aee@infradead.org>
     [not found]   ` <alpine.LSU.2.21.2005251101030.24984@pobox.suse.cz>
     [not found]     ` <alpine.LSU.2.21.2005251303430.24984@pobox.suse.cz>
     [not found]       ` <20200526140113.ppjywpx7uir3vrlj@treble>
2020-05-26 16:39         ` linux-next: Tree for May 21 (objtool warnings) Miroslav Benes
2020-05-27  8:57           ` Martin Jambor
2020-05-27 15:09             ` Josh Poimboeuf

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).