From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Li Zhijian" <lizhijian@cn.fujitsu.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Alexey Kardashevskiy" <aik@ozlabs.ru>,
"Jason Wang" <jasowang@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Peter Xu" <peterx@redhat.com>,
"Tony Nguyen" <tony.nguyen@bt.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <rth@twiddle.net>
Subject: [RFC PATCH 2/2] exec/memory: Emit warning when MemTxResult is ignored
Date: Sun, 17 May 2020 18:48:17 +0200 [thread overview]
Message-ID: <20200517164817.5371-3-f4bug@amsat.org> (raw)
In-Reply-To: <20200517164817.5371-1-f4bug@amsat.org>
When a function from the memory subsystem return a MemTxResult
to indicate that the transaction failed, this return value
must not be ignored by the caller. Mark all these functions
with the QEMU_WARN_UNUSED_RESULT attribute, to prevent users
to ignore possible failed transactions.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
RFC because it doesn't build. But before going thru each caller,
let's talk on the list if this change makes sense.
---
include/exec/memory.h | 39 +++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 5e8c009169..95668d1628 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -161,12 +161,14 @@ struct MemoryRegionOps {
hwaddr addr,
uint64_t *data,
unsigned size,
- MemTxAttrs attrs);
+ MemTxAttrs attrs)
+ QEMU_WARN_UNUSED_RESULT;
MemTxResult (*write_with_attrs)(void *opaque,
hwaddr addr,
uint64_t data,
unsigned size,
- MemTxAttrs attrs);
+ MemTxAttrs attrs)
+ QEMU_WARN_UNUSED_RESULT;
enum device_endian endianness;
/* Guest-visible constraints: */
@@ -1989,7 +1991,8 @@ MemTxResult memory_region_dispatch_read(MemoryRegion *mr,
hwaddr addr,
uint64_t *pval,
MemOp op,
- MemTxAttrs attrs);
+ MemTxAttrs attrs)
+ QEMU_WARN_UNUSED_RESULT;
/**
* memory_region_dispatch_write: perform a write directly to the specified
* MemoryRegion.
@@ -2004,7 +2007,8 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
hwaddr addr,
uint64_t data,
MemOp op,
- MemTxAttrs attrs);
+ MemTxAttrs attrs)
+ QEMU_WARN_UNUSED_RESULT;
/**
* address_space_init: initializes an address space
@@ -2053,7 +2057,8 @@ void address_space_remove_listeners(AddressSpace *as);
*/
MemTxResult address_space_rw(AddressSpace *as, hwaddr addr,
MemTxAttrs attrs, void *buf,
- hwaddr len, bool is_write);
+ hwaddr len, bool is_write)
+ QEMU_WARN_UNUSED_RESULT;
/**
* address_space_write: write to address space.
@@ -2070,7 +2075,8 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr,
*/
MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
MemTxAttrs attrs,
- const void *buf, hwaddr len);
+ const void *buf, hwaddr len)
+ QEMU_WARN_UNUSED_RESULT;
/**
* address_space_write_rom: write to address space, including ROM.
@@ -2096,7 +2102,8 @@ MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
*/
MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,
MemTxAttrs attrs,
- const void *buf, hwaddr len);
+ const void *buf, hwaddr len)
+ QEMU_WARN_UNUSED_RESULT;
/* address_space_ld*: load from an address space
* address_space_st*: store to an address space
@@ -2334,20 +2341,24 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
/* Internal functions, part of the implementation of address_space_read. */
MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr,
- MemTxAttrs attrs, void *buf, hwaddr len);
+ MemTxAttrs attrs, void *buf, hwaddr len)
+ QEMU_WARN_UNUSED_RESULT;
MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr,
MemTxAttrs attrs, void *buf,
hwaddr len, hwaddr addr1, hwaddr l,
- MemoryRegion *mr);
+ MemoryRegion *mr)
+ QEMU_WARN_UNUSED_RESULT;
void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);
/* Internal functions, part of the implementation of address_space_read_cached
* and address_space_write_cached. */
MemTxResult address_space_read_cached_slow(MemoryRegionCache *cache,
- hwaddr addr, void *buf, hwaddr len);
+ hwaddr addr, void *buf, hwaddr len)
+ QEMU_WARN_UNUSED_RESULT;
MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache,
hwaddr addr, const void *buf,
- hwaddr len);
+ hwaddr len)
+ QEMU_WARN_UNUSED_RESULT;
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
{
@@ -2373,7 +2384,7 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
* @buf: buffer with the data transferred
* @len: length of the data transferred
*/
-static inline __attribute__((__always_inline__))
+static inline __attribute__((__always_inline__)) QEMU_WARN_UNUSED_RESULT
MemTxResult address_space_read(AddressSpace *as, hwaddr addr,
MemTxAttrs attrs, void *buf,
hwaddr len)
@@ -2412,7 +2423,7 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr,
* @buf: buffer with the data transferred
* @len: length of the data transferred
*/
-static inline MemTxResult
+static inline MemTxResult QEMU_WARN_UNUSED_RESULT
address_space_read_cached(MemoryRegionCache *cache, hwaddr addr,
void *buf, hwaddr len)
{
@@ -2433,7 +2444,7 @@ address_space_read_cached(MemoryRegionCache *cache, hwaddr addr,
* @buf: buffer with the data transferred
* @len: length of the data transferred
*/
-static inline MemTxResult
+static inline MemTxResult QEMU_WARN_UNUSED_RESULT
address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
const void *buf, hwaddr len)
{
--
2.21.3
next prev parent reply other threads:[~2020-05-17 16:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-17 16:48 [PATCH 0/2] exec/memory: Enforce checking MemTxResult values Philippe Mathieu-Daudé
2020-05-17 16:48 ` [PATCH 1/2] exec/memory: Let address_space_read/write_cached() propagate MemTxResult Philippe Mathieu-Daudé
2020-05-21 15:37 ` Paolo Bonzini
2020-05-17 16:48 ` Philippe Mathieu-Daudé [this message]
2020-05-17 18:06 ` [PATCH 0/2] exec/memory: Enforce checking MemTxResult values no-reply
2020-05-17 18:13 ` no-reply
2020-05-17 18:19 ` no-reply
2020-05-18 9:46 ` Peter Maydell
2020-05-18 11:20 ` Philippe Mathieu-Daudé
2020-05-18 12:33 ` Peter Maydell
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=20200517164817.5371-3-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=aik@ozlabs.ru \
--cc=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=tony.nguyen@bt.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).