All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	qemu-devel@nongnu.org, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH] migration/rdma: clang compilation fix
Date: Mon, 4 Mar 2019 18:18:27 +0000	[thread overview]
Message-ID: <20190304181827.GD2596@work-vm> (raw)
In-Reply-To: <550bead8-a9a5-d9f4-1204-a6130f8c8e14@redhat.com>

* Eric Blake (eblake@redhat.com) wrote:
> On 3/4/19 2:42 AM, Marcel Apfelbaum wrote:
> > Configuring QEMU with:
> >          ../configure --cc=clang --enable-rdma
> > 
> > Leads to compilation error:
> > 
> >    CC      migration/rdma.o
> >    CC      migration/block.o
> >    qemu/migration/rdma.c:3615:58: error: taking address of packed member 'rkey' of class or structure
> >        'RDMARegisterResult' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
> >                              (uintptr_t)host_addr, NULL, &reg_result->rkey,
> >                                                           ^~~~~~~~~~~~~~~~
> > 
> > This is a false warning; even if RDMARegisterResult is "packed", rkey
> > is the first field so is guaranteed to be aligned.
> 
> Not so. If you packed struct, gcc is free to abut that struct next to some
> other unaligned field in a larger struct:
> 
> https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg06743.html
> 
> > 
> > Fix it by disabling the warning only for this instance.
> 
> Ignoring the bug is not the same as fixing the bug.  You need to rework
> this, as the compiler warning is not a false negative.

In this case it is, however, I think it's easy enough to work around;
all we need is something like:

  uint23_t tmp_rkey;
                  if (qemu_rdma_register_and_get_keys(rdma, block,
                            (uintptr_t)host_addr, NULL, &tmp_rkey,
                            chunk, chunk_start, chunk_end)) {
                    error_report("cannot get rkey");
                    ret = -EINVAL;
                    goto out;
                  }
                  reg_result->rkey = tmp_rkey

Note that I think the structure pointed to by reg_result is
visible over the wire, so we can't change it's (unfortunate) layout.

Dave

> > 
> > Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
> > ---
> >   migration/rdma.c | 3 +++
> >   1 file changed, 3 insertions(+)
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.           +1-919-301-3226
> Virtualization:  qemu.org | libvirt.org
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2019-03-04 18:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-04  8:42 [Qemu-devel] [PATCH] migration/rdma: clang compilation fix Marcel Apfelbaum
2019-03-04 18:11 ` Eric Blake
2019-03-04 18:18   ` Dr. David Alan Gilbert [this message]
2019-03-04 18:27     ` Marcel Apfelbaum
2019-03-04 18:30   ` Marcel Apfelbaum

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=20190304181827.GD2596@work-vm \
    --to=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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.