All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "John Snow" <jsnow@redhat.com>,
	qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
	kvm@vger.kernel.org,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Stefan Weil" <sw@weilnetz.de>, "Peter Xu" <peterx@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH v2 4/7] debug/mem: name pthreads
Date: Tue, 17 Nov 2026 13:47:45 +0000	[thread overview]
Message-ID: <avxbAf6FlGMthTCE@redhat.com> (raw)
In-Reply-To: <avxapBFgrHUV3rfp@redhat.com>

On Tue, Nov 17, 2026 at 01:46:12PM +0000, Daniel P. Berrangé wrote:
> On Mon, Nov 16, 2026 at 11:49:59AM -0500, John Snow wrote:
> > Signed-off-by: John Snow <jsnow@redhat.com>
> > ---
> >  meson.build              |  8 ++++++++
> >  util/qemu-thread-posix.c | 30 ++++++++++++++++++++++++++++++
> >  2 files changed, 38 insertions(+)
> > 
> > diff --git a/meson.build b/meson.build
> > index d7bcb581c18..ef961df2f64 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -2878,7 +2878,15 @@ config_host_data.set('CONFIG_PTHREAD_GET_NAME_NP', cc.links(osdep_prefix + '''
> >      pthread_get_name_np(pthread_self(), buf, sizeof(buf));
> >      return 0;
> >    }''', dependencies: threads))
> > +config_host_data.set('CONFIG_PTHREAD_GETATTR_NP', cc.links(osdep_prefix + '''
> > +  #include <pthread.h>
> >  
> > +  int main(void)
> > +  {
> > +    pthread_attr_t attr;
> > +    pthread_getattr_np(pthread_self(), &attr);
> > +    return 0;
> > +  }''', dependencies: threads))
> >  config_host_data.set('CONFIG_PTHREAD_CONDATTR_SETCLOCK', cc.links(osdep_prefix + '''
> >    #include <pthread.h>
> >  
> > diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> > index 089606c93fb..967e0f15f6d 100644
> > --- a/util/qemu-thread-posix.c
> > +++ b/util/qemu-thread-posix.c
> > @@ -17,6 +17,7 @@
> >  #include "qemu-thread-common.h"
> >  #include "qemu/tsan.h"
> >  #include "qemu/bitmap.h"
> > +#include "qemu/mmap-vma.h"
> >  
> >  #if defined(CONFIG_PTHREAD_SET_NAME_NP) || defined(CONFIG_PTHREAD_GET_NAME_NP)
> >  #include <pthread_np.h>
> > @@ -362,6 +363,13 @@ static void qemu_thread_atexit_notify(void *arg)
> >  
> >  void qemu_thread_set_name(const char *name)
> >  {
> > +# if defined(CONFIG_PTHREAD_GETATTR_NP)
> > +    pthread_attr_t real_attr;
> > +    void *pthread_addr;
> > +    size_t stacksize;
> > +    size_t guardsize;
> > +# endif
> > +
> >      /*
> >       * Attempt to set the thread name; note that this is for debug, so
> >       * we're not going to fail if we can't set it.
> > @@ -373,6 +381,28 @@ void qemu_thread_set_name(const char *name)
> >  # elif defined(CONFIG_PTHREAD_SET_NAME_NP)
> >      pthread_set_name_np(pthread_self(), name);
> >  # endif
> > +
> > +# if defined(CONFIG_PTHREAD_GETATTR_NP)
> > +    if (pthread_getattr_np(pthread_self(), &real_attr)) {
> > +        return;
> > +    }
> > +
> > +    if (pthread_attr_getguardsize(&real_attr, &guardsize)) {
> > +        goto cleanup;
> > +    }
> > +
> > +    if (pthread_attr_getstack(&real_attr, &pthread_addr, &stacksize)) {
> > +        goto cleanup;
> > +    }
> > +
> > +    /* Though there's a guard page, it isn't actually marked RO, so
> > +     * just label the entire region */
> > +    qemu_name_vma(pthread_addr - guardsize, stacksize + guardsize,
> > +                  "pthread (%s)", name);
> 
> On the one hand this code is pretty sketchy as it is making
> some assumptions about glibc allocating thread stack. On
> the other hand qemu_name_vma() is a no-op on non-Linux
> platforms, and we ignore fails, so we'll degrade nicely if
> any C libraries (musl) deal with thread stack differently.
> 
> I feel that glibc itself really ought to set the VMA name
> in response to pthread_set_name_np but I'm open to us doing
> this in QEMU though as I think it is safe enough.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  reply	other threads:[~2026-11-17 13:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:49 [PATCH v2 0/7] debug: add PR_SET_VMA_ANON_NAME support John Snow
2026-11-16 16:49 ` [PATCH v2 1/7] debug/mem: add utility to name anonymous memory mappings John Snow
2026-11-17 13:39   ` Daniel P. Berrangé
2026-11-17 17:59     ` John Snow
2026-11-16 16:49 ` [PATCH v2 2/7] debug/mem: add tracing to qemu_vname_vma() John Snow
2026-11-16 16:49 ` [PATCH v2 3/7] debug/mem: name <reserved> regions in mmap-alloc John Snow
2026-11-16 16:49 ` [PATCH v2 4/7] debug/mem: name pthreads John Snow
2026-11-17 13:46   ` Daniel P. Berrangé
2026-11-17 13:47     ` Daniel P. Berrangé [this message]
2026-11-17 17:52       ` John Snow
2026-11-16 16:50 ` [PATCH v2 5/7] debug/mem: name coroutine stacks John Snow
2026-11-17 13:47   ` Daniel P. Berrangé
2026-11-17 17:54     ` John Snow
2026-11-16 16:50 ` [PATCH v2 6/7] debug/mem: name qemu_anon_ram_alloc/qemu_ram_mmap pages John Snow
2026-11-16 16:50 ` [PATCH v2 7/7] debug/mem: HACK add qemu_name_buffer John Snow

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=avxbAf6FlGMthTCE@redhat.com \
    --to=berrange@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=dmitry.osipenko@collabora.com \
    --cc=farosas@suse.de \
    --cc=jsnow@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@oss.qualcomm.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sw@weilnetz.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.