From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>, "Kevin Wolf" <kwolf@redhat.com>,
qemu-block@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH 3/3] block/nvme: Align NVMeRegs structure to 4KiB and mark it packed
Date: Wed, 16 Sep 2020 22:40:04 +0200 [thread overview]
Message-ID: <20200916204004.1511985-4-philmd@redhat.com> (raw)
In-Reply-To: <20200916204004.1511985-1-philmd@redhat.com>
In commit e5ff22ba9fc we changed the doorbells register
declaration but forgot to mark the structure packed (as
MMIO registers), allowing the compiler to optimize it.
Fix by marking it packed, and align it to avoid:
block/nvme.c: In function ‘nvme_create_queue_pair’:
block/nvme.c:252:22: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
252 | q->sq.doorbell = &s->regs->doorbells[idx * s->doorbell_scale].sq_tail;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixes: e5ff22ba9fc ("block/nvme: Pair doorbell registers")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index be80ea1f410..2f9f560ccd5 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -12,6 +12,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/units.h"
#include <linux/vfio.h>
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
@@ -82,13 +83,15 @@ typedef struct {
} NVMeQueuePair;
/* Memory mapped registers */
-typedef struct {
+typedef struct QEMU_PACKED {
NvmeBar ctrl;
struct {
uint32_t sq_tail;
uint32_t cq_head;
} doorbells[];
-} NVMeRegs;
+} QEMU_ALIGNED(4 * KiB) NVMeRegs;
+
+QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells[1]) != 4096 + 8);
#define INDEX_ADMIN 0
#define INDEX_IO(n) (1 + n)
--
2.26.2
next prev parent reply other threads:[~2020-09-16 20:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-16 20:40 [PATCH 0/3] block/nvme: Fix NVMeRegs alignment/packing and use atomic operations Philippe Mathieu-Daudé
2020-09-16 20:40 ` [PATCH 1/3] block/nvme: Initialize constant values with const_le32() Philippe Mathieu-Daudé
2020-09-17 9:55 ` Stefan Hajnoczi
2020-09-17 13:52 ` Philippe Mathieu-Daudé
2020-09-16 20:40 ` [PATCH 2/3] block/nvme: Use atomic operations instead of 'volatile' keyword Philippe Mathieu-Daudé
2020-09-17 10:42 ` Stefan Hajnoczi
2020-09-16 20:40 ` Philippe Mathieu-Daudé [this message]
2020-09-17 11:07 ` [PATCH 3/3] block/nvme: Align NVMeRegs structure to 4KiB and mark it packed Stefan Hajnoczi
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=20200916204004.1511985-4-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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 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).