All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Warner Losh" <imp@bsdimp.com>,
	qemu-devel@nongnu.org, "Kyle Evans" <kevans@freebsd.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [PATCH 2/3] bsd-user/mmap: use TSA_NO_TSA to suppress clang TSA warnings
Date: Wed, 18 Jan 2023 10:24:43 -0500	[thread overview]
Message-ID: <Y8gPO9NkppvnJA/y@fedora> (raw)
In-Reply-To: <c2c62083-1e04-b70c-baac-cf2bf1a21660@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4478 bytes --]

On Wed, Jan 18, 2023 at 04:12:09PM +0100, Emanuele Giuseppe Esposito wrote:
> 
> 
> Am 17/01/2023 um 18:17 schrieb Kevin Wolf:
> > Am 17.01.2023 um 17:43 hat Warner Losh geschrieben:
> >> On Tue, Jan 17, 2023 at 9:25 AM Kevin Wolf <kwolf@redhat.com> wrote:
> >>
> >>> Am 17.01.2023 um 17:16 hat Warner Losh geschrieben:
> >>>> On Tue, Jan 17, 2023 at 6:52 AM Emanuele Giuseppe Esposito <
> >>>> eesposit@redhat.com> wrote:
> >>>>
> >>>>> QEMU does not compile when enabling clang's thread safety analysis
> >>>>> (TSA),
> >>>>> because some functions create wrappers for pthread mutexes but do
> >>>>> not use any TSA macro. Therefore the compiler fails.
> >>>>>
> >>>>> In order to make the compiler happy and avoid adding all the
> >>>>> necessary macros to all callers (lock functions should use
> >>>>> TSA_ACQUIRE, while unlock TSA_RELEASE, and this applies to allusers of
> >>>>> pthread_mutex_lock/pthread_mutex_unlock),
> >>>>> simply use TSA_NO_TSA to supppress such warnings.
> >>>>
> >>>> I'm not sure I understand this quite right. Maybe a clarifying question
> >>>> will help me understand: Why is this needed for bsd-user but not
> >>>> linux-user? How are they different here?
> >>>
> >>> FreeBSD's pthread headers include TSA annotations for some functions
> >>> that force us to do something about them (for now: suppress the warnings
> >>> in their callers) before we can enable -Wthread-safety for the purposes
> >>> where we really want it. Without this, calling functions like
> >>> pthread_mutex_lock() would cause compiler errors.
> >>>
> >>> glibc's headers don't contain such annotations, so the same is not
> >>> necessary on Linux
> >>>
> >>
> >> Thanks Kevin. With that explanation, these patches and their explanation
> >> make perfect sense now. Often when there's a patch to bsd-user but not
> >> linux-user, it's because bsd-user needs to do more in some way (which I try
> >> to keep up on).
> >>
> >> In this case, it's because FreeBSD's libc is a bit ahead of the curve. So I
> >> understand why it's needed, and what I need to do next (though I think that
> >> I may have to wait for the rest of qemu to be annotated)...
> > 
> > I assume that the bsd-user part is actually sufficiently independent
> > that you could do proper annotations there if you want.
> > 
> > However, be aware that TSA has some serious limitations with C, so you
> > can't express certain things, and it isn't as strict as it could be (in
> > particular, function pointers bypass it). As long as you have global
> > locks (as opposed to locks in structs), it kind of works, though.
> > Certainly better than nothing.
> > 
> > But it probably means that some of the rest of QEMU may never get the
> > annotations. Also, our primary goal is protecting the block layer, so
> > someone else would have to work on other locks. With checks disabled on
> > individual functions like in this series, it should at least be possible
> > to work on it incrementally.
> > 
> >> It might be better, though, to put some of this information in the commit
> >> message so it isn't just on the mailing list.
> > 
> > Yes, I agree. We can tweak the commit messages before merging it.
> 
> New proposed commit message:
> 
> bsd-user/mmap: use TSA_NO_TSA to suppress clang TSA warnings in FreeBSD
> 
> FreeBSD implements pthread headers using TSA (thread safety analysis)
> annotations, therefore when an application is compiled with -Wthread-safety
> there are some locking/annotation requirements that the user of the
> pthread API has to follow.
> 
> This will also be the case in QEMU, since bsd-user/mmap.c uses the
> pthread API. Therefore when building it with -Wthread-safety the
> compiler will throw warnings because the functions are not properly
> annotated. We need TSA to be enabled because it ensures
> that the critical sections of an annotated variable are properly
> locked.
> 
> In order to make the compiler happy and avoid adding all the
> necessary macros to all callers (lock functions should use
> TSA_ACQUIRE, while unlock TSA_RELEASE, and this applies to all
> users of pthread_mutex_lock/pthread_mutex_unlock),
> simply use TSA_NO_TSA to supppress such warnings.
> 
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> 
> Same message could be applied to patch 1, substituting bsd-user/mmap
> with util/qemu-thread-posix.

Looks good to me.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2023-01-18 15:25 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 13:52 [PATCH 0/3] TSA: make sure QEMU compiles when using clang TSA Emanuele Giuseppe Esposito
2023-01-17 13:52 ` [PATCH 1/3] util/qemu-thread-posix: use TSA_NO_TSA to suppress clang TSA warnings Emanuele Giuseppe Esposito
2023-01-17 14:33   ` Philippe Mathieu-Daudé
2023-01-17 14:43     ` Emanuele Giuseppe Esposito
2023-01-17 15:49       ` Philippe Mathieu-Daudé
2023-01-17 13:52 ` [PATCH 2/3] bsd-user/mmap: " Emanuele Giuseppe Esposito
2023-01-17 16:16   ` Warner Losh
2023-01-17 16:21     ` Emanuele Giuseppe Esposito
2023-01-17 16:25     ` Kevin Wolf
2023-01-17 16:43       ` Warner Losh
2023-01-17 17:17         ` Kevin Wolf
2023-01-17 20:43           ` Stefan Hajnoczi
2023-01-18  9:14             ` Kevin Wolf
2023-01-18 12:31               ` Stefan Hajnoczi
2023-01-18 15:12           ` Emanuele Giuseppe Esposito
2023-01-18 15:24             ` Stefan Hajnoczi [this message]
2023-01-18 17:35             ` Warner Losh
2023-01-17 16:32   ` Stefan Hajnoczi
2023-01-17 13:52 ` [PATCH 3/3] configure: Enable -Wthread-safety if present Emanuele Giuseppe Esposito
2023-01-17 14:02   ` Daniel P. Berrangé
2023-01-17 14:41     ` Emanuele Giuseppe Esposito
2023-01-17 15:01       ` Daniel P. Berrangé
2023-01-17 15:59         ` Kevin Wolf
2023-01-17 16:22 ` [PATCH 0/3] TSA: make sure QEMU compiles when using clang TSA Stefan Hajnoczi
2023-02-13 10:44 ` Kevin Wolf

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=Y8gPO9NkppvnJA/y@fedora \
    --to=stefanha@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=eesposit@redhat.com \
    --cc=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.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 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.