qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Marlies Ruck" <marlies.ruck@gmail.com>,
	"Riku Voipio" <riku.voipio@iki.fi>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Aleksandar Markovic" <aleksandar.markovic@rt-rk.com>,
	"Josh Kunz" <jkz@google.com>,
	"Taylor Simpson" <tsimpson@quicinc.com>,
	"Matus Kysel" <mkysel@tachyum.com>,
	"Miloš Stojanović" <milos.stojanovic@rt-rk.com>
Subject: Re: [PATCH v2 4/4] linux-user: fix use of SIGRTMIN
Date: Tue, 11 Feb 2020 18:19:49 +0100	[thread overview]
Message-ID: <bd17f315-19b0-ab7a-7625-185e8de1b90c@vivier.eu> (raw)
In-Reply-To: <CAFEAcA_9BGGr7uCqjT7R2jKSWXd6dZkxhtFvgEe4pGOXVbpW_Q@mail.gmail.com>

Thank you Peter,

I will address you comments and send a new version of the series.

Laurent

Le 11/02/2020 à 18:05, Peter Maydell a écrit :
> On Tue, 4 Feb 2020 at 17:11, Laurent Vivier <laurent@vivier.eu> wrote:
>>
>> Some RT signals can be in use by glibc,
>> it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32).
>>
>> So SIGRTMIN cannot be mapped to TARGET_SIGRTMIN.
>>
>> Instead of swapping only SIGRTMIN and SIGRTMAX, map all the
>> range [TARGET_SIGRTMIN ... TARGET_SIGRTMAX - X] to
>>       [__SIGRTMIN + X ... SIGRTMAX ]
>> (SIGRTMIN is __SIGRTMIN + X).
>>
>> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
>> ---
> 
> In general I think this is a good approach to trying to deal
> with this long-standing issue in a pragmatic and not too
> complicated way, so thanks for writing this patchset. I have
> some fairly minor comments on the code below.
> 
>>
>> Notes:
>>     v2: ignore error when target sig <= TARGET_NSIG but host sig > SIGRTMAX
>>         replace i, j by target_sig, host_sig
>>         update signal_table_init() trace message
>>
>>  linux-user/signal.c     | 37 ++++++++++++++++++++++++++++++-------
>>  linux-user/trace-events |  3 +++
>>  2 files changed, 33 insertions(+), 7 deletions(-)
>>
>> diff --git a/linux-user/signal.c b/linux-user/signal.c
>> index c1e664f97a7c..e7e5581a016f 100644
>> --- a/linux-user/signal.c
>> +++ b/linux-user/signal.c
>> @@ -498,18 +498,23 @@ static int core_dump_signal(int sig)
>>
>>  static void signal_table_init(void)
>>  {
>> -    int host_sig, target_sig;
>> +    int host_sig, target_sig, count;
>>
>>      /*
>> -     * Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with
>> -     * host libpthread signals.  This assumes no one actually uses SIGRTMAX :-/
>> -     * To fix this properly we need to do manual signal delivery multiplexed
>> -     * over a single host signal.
>> +     * some RT signals can be in use by glibc,
>> +     * it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32)
>>       */
>> -    host_to_target_signal_table[__SIGRTMIN] = __SIGRTMAX;
>> -    host_to_target_signal_table[__SIGRTMAX] = __SIGRTMIN;
>> +    for (host_sig = SIGRTMIN; host_sig <= SIGRTMAX; host_sig++) {
>> +        target_sig = host_sig - SIGRTMIN + TARGET_SIGRTMIN;
>> +        if (target_sig <= TARGET_NSIG) {
>> +            host_to_target_signal_table[host_sig] = target_sig;
>> +        }
>> +    }
> 
> So the effect of this is that we now support target signals
> starting from TARGET_SIGRTMIN and going up until we run out
> of host realtime signals that the host libc hasn't reserved ?
> That seems reasonable, since glibc at least uses only the
> lower 2 rt signals and probably nobody's using the upper ones.
> But this would be a good place to have a comment explaining
> the limitation (and that if it needed to be fixed we'd have
> to multiplex guest signals onto a single host signal). You
> could also mention that attempts to configure the "missing"
> signals via sigaction will be silently ignored.
> 
>>      /* generate signal conversion tables */
>> +    for (target_sig = 1; target_sig <= TARGET_NSIG; target_sig++) {
>> +        target_to_host_signal_table[target_sig] = _NSIG; /* poison */
>> +    }
>>      for (host_sig = 1; host_sig < _NSIG; host_sig++) {
>>          if (host_to_target_signal_table[host_sig] == 0) {
>>              host_to_target_signal_table[host_sig] = host_sig;
>> @@ -519,6 +524,15 @@ static void signal_table_init(void)
>>              target_to_host_signal_table[target_sig] = host_sig;
>>          }
>>      }
>> +
>> +    if (TRACE_SIGNAL_TABLE_INIT_BACKEND_DSTATE()) {
> 
> This isn't the right way to conditionalize expensive stuff
> that's only used in trace events. You want to use
> trace_event_get_state_backends() (see docs/devel/tracing.txt
> for details).
> 
>> +        for (target_sig = 1, count = 0; target_sig <= TARGET_NSIG; target_sig++) {
>> +            if (target_to_host_signal_table[target_sig] == _NSIG) {
>> +                count++;
>> +            }
>> +        }
>> +        trace_signal_table_init(count);
>> +    }
>>  }
>>
>>  void signal_init(void)
>> @@ -817,6 +831,8 @@ int do_sigaction(int sig, const struct target_sigaction *act,
>>      int host_sig;
>>      int ret = 0;
>>
>> +    trace_signal_do_sigaction_guest(sig, TARGET_NSIG);
>> +
>>      if (sig < 1 || sig > TARGET_NSIG || sig == TARGET_SIGKILL || sig == TARGET_SIGSTOP) {
>>          return -TARGET_EINVAL;
>>      }
>> @@ -847,6 +863,13 @@ int do_sigaction(int sig, const struct target_sigaction *act,
>>
>>          /* we update the host linux signal state */
>>          host_sig = target_to_host_signal(sig);
>> +        trace_signal_do_sigaction_host(host_sig, TARGET_NSIG);
>> +        if (host_sig > SIGRTMAX) {
>> +            /* we don't have enough host signals to map all target signals */
>> +            qemu_log_mask(LOG_UNIMP, "Unsupported target signal #%d, ignored\n",
>> +                          sig);
>> +            return 0;
> 
> We should have a comment here mentioning why we don't return
> an error code here (and explicitly noting that the Go runtime
> is the major one which we don't want to upset).
> 
>> +        }
>>          if (host_sig != SIGSEGV && host_sig != SIGBUS) {
>>              sigfillset(&act1.sa_mask);
>>              act1.sa_flags = SA_SIGINFO;
>> diff --git a/linux-user/trace-events b/linux-user/trace-events
>> index f6de1b8befc0..0296133daeb6 100644
>> --- a/linux-user/trace-events
>> +++ b/linux-user/trace-events
>> @@ -1,6 +1,9 @@
>>  # See docs/devel/tracing.txt for syntax documentation.
>>
>>  # signal.c
>> +signal_table_init(int i) "number of unavailable signals: %d"
>> +signal_do_sigaction_guest(int sig, int max) "target signal %d (MAX %d)"
>> +signal_do_sigaction_host(int sig, int max) "host signal %d (MAX %d)"
>>  # */signal.c
>>  user_setup_frame(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64
>>  user_setup_rt_frame(void *env, uint64_t frame_addr) "env=%p frame_addr=0x%"PRIx64
> 
> thanks
> -- PMM
> 



  reply	other threads:[~2020-02-11 17:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-04 17:10 [PATCH v2 0/4] linux-user: fix use of SIGRTMIN Laurent Vivier
2020-02-04 17:10 ` [PATCH v2 1/4] linux-user: add missing TARGET_SIGRTMIN for hppa Laurent Vivier
2020-02-11 16:38   ` Peter Maydell
2020-02-11 16:55   ` Peter Maydell
2020-02-04 17:10 ` [PATCH v2 2/4] linux-user: cleanup signal.c Laurent Vivier
2020-02-04 17:56   ` Philippe Mathieu-Daudé
2020-02-11 16:39   ` Peter Maydell
2020-02-04 17:10 ` [PATCH v2 3/4] linux-user: fix TARGET_NSIG and _NSIG uses Laurent Vivier
2020-02-11 16:47   ` Peter Maydell
2020-02-11 16:59     ` Laurent Vivier
2020-02-11 17:17       ` Peter Maydell
2020-02-04 17:10 ` [PATCH v2 4/4] linux-user: fix use of SIGRTMIN Laurent Vivier
2020-02-05 22:32   ` Taylor Simpson
2020-02-11 17:05   ` Peter Maydell
2020-02-11 17:19     ` Laurent Vivier [this message]
2020-02-11 15:40 ` [PATCH v2 0/4] " Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bd17f315-19b0-ab7a-7625-185e8de1b90c@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=aleksandar.markovic@rt-rk.com \
    --cc=jkz@google.com \
    --cc=marlies.ruck@gmail.com \
    --cc=milos.stojanovic@rt-rk.com \
    --cc=mkysel@tachyum.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    --cc=tsimpson@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).