[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xsm/flask: Fix build with Clang 13


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 26 Apr 2022 09:20:34 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AfWdct7/ks7y+3bhXjDQexMqtYWIYdzZ67UZ2gVJpfw=; b=WLWNIWNc2pomhcATlniS4L/Bnhd81CFY8b6BUEk1PAac+8xZfkRTjsgR1D5xBluNuv9epd7H8OUhEJPIdq33qt0ZYTtoABPZ1z0TsPeW53+wx0ddhcF+xJCGIWOEiUPckLNrfNqBTLl2cI2I8kWiJk6pJuAUSPYkXZoxU5II43Yx0sLOhRO+G/7X2+UsVPZbtEPsS9wPMfH5chT9CsgOLMCQ6RTI3bexMJtg6DRoDiKxUF1bAhV6Mo30gfmo/WrHchqgW7dHNE8DPSG0yFow8VKnpfZ1u0hqftId3WaQQ1VklHdE+nRy0D4q8A0+GWaMSU1D/FO/IbfBlzho33Bjlg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d7JL5PFtHyngTFD1dF1zSHA/TqyAvKgIwg9NLZEoFyWB576Ns5zzUtTnyft+MvJzTX9nYSk9bVhibd8toPtQNRcuwdlTBPFzPHw9byavSaUqY9UOx09KevKHn38N2VJH+oZGKaLLT/f3RSFMjyPQxhqd0mzodS4bbsMeKZA+IEu8UhYiNMx3SprQqhSX8qWjiJV//rTmGEG9gluwUJV+EHZU3hYPcr4zOBG1d1RJRhPUu8YYjcOPTv1Api71IWkZkq1tFuQH5fbn+RM5Itj6VDgGJ2RlwNAtrOzR2a/q/x6Dtfqj3kHEENrrhDwWqJ2e9CUdLjhORqIg+uVmaRcHww==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>, Daniel Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 26 Apr 2022 07:20:46 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 25.04.2022 20:07, Andrew Cooper wrote:
> Clang 13 chokes with:
> 
>   In file included from xsm/flask/flask_op.c:780:
>   xsm/flask/flask_op.c:698:33: error: passing 4-byte aligned argument to
>   8-byte aligned parameter 1 of 'flask_ocontext_add' may result in an
>   unaligned pointer access [-Werror,-Walign-mismatch]
>           rv = flask_ocontext_add(&op.u.ocontext);
>                                   ^
> 
> and the same for flask_ocontext_del().  It isn't a problem in practice,
> because the union always starts 8 bytes into {xen,compat}_flask_op_t, but the
> diagnostic is based on type alignment alone.
> 
> struct xen_flask_ocontext has the same layout between native and compat, but
> does change alignment because of uint64_t, and there is only a native
> implementation of flask_ocontext_add().
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
> CC: Daniel Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
> CC: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
> CC: Jan Beulich <JBeulich@xxxxxxxx>
> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> CC: Julien Grall <julien@xxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> 
> Slightly RFC because there don't appear to be any good options here.

We cannot address this by altering the public header. Besides us having
previously agreed to avoid the use of extensions outside of tools-only
parts of these headers (or else you could simply use uint64_aligned_t),
you're also altering the ABI for compat guests by changing the alignment.

On irc yesterday we had

18:12:06 - jbeulich: With alignof() == 4 the compiler could put the variable on 
the stack, but not 8-byte aligned (if something else occupies another 32-bit 
slot).
18:13:34 - andyhhp: well - it can't in this case
18:13:37 - andyhhp: I agree it can in principle

which I don't understand, but which I'd like to understand in this
context: Why would the compiler not be allowed to place
compat_flask_op()'s op variable 4-but-not-8-byte aligned on the stack?
Then, if forcing 8-byte alignment of op, the compiler still issuing a
diagnostic would be a (minor) bug imo, as taking into account variable
alignment and offset into the structure would be enough to know that
_this instance_ of the struct cannot be misaligned. (Of course this
wouldn't help us, as we'd still need to work around the deficiency.)

One possible way to deal with the problem that I can see (without
having actually tried it) is to make the two functions take a parameter
of compat_flask_ocontext_t *. That's type-compatible with struct
xen_flask_ocontext *, but has reduced alignment. Of course this will
require ugly #ifdef-ary because the type won't be available without
CONFIG_COMPAT. Otoh any approach avoiding #ifdef-ary (like introducing
yet another typedef matching that of compat_flask_ocontext_t, just
without reference to struct compat_flask_ocontext) would needlessly
impact !COMPAT builds.

Jan




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.