[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 3/5] exec/memattrs: Introduce MemTxAttrs::bus_perm field
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH v2 3/5] exec/memattrs: Introduce MemTxAttrs::bus_perm field |
Date: |
Mon, 23 Aug 2021 18:41:55 +0200 |
Add the 'direct_access' bit to the memory attributes to restrict
bus master access to ROM/RAM.
Have read/write accessors return MEMTX_BUS_ERROR if an access is
restricted and the region is not ROM/RAM ('direct').
Add corresponding trace events.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
include/exec/memattrs.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h
index 95f2d20d55b..7a94ee75a88 100644
--- a/include/exec/memattrs.h
+++ b/include/exec/memattrs.h
@@ -14,6 +14,13 @@
#ifndef MEMATTRS_H
#define MEMATTRS_H
+/* Permission to restrict bus memory accesses. See MemTxAttrs::bus_perm */
+enum {
+ MEMTXPERM_UNSPECIFIED = 0,
+ MEMTXPERM_UNRESTRICTED = 1,
+ MEMTXPERM_RAM_DEVICE = 2,
+};
+
/* Every memory transaction has associated with it a set of
* attributes. Some of these are generic (such as the ID of
* the bus master); some are specific to a particular kind of
@@ -35,6 +42,19 @@ typedef struct MemTxAttrs {
unsigned int secure:1;
/* Memory access is usermode (unprivileged) */
unsigned int user:1;
+ /*
+ * Bus memory access permission.
+ *
+ * Some devices (such DMA) might be restricted to only access
+ * some type of device, such RAM devices. By default memory
+ * accesses are unspecified (MEMTXPERM_UNSPECIFIED), but could be
+ * unrestricted (MEMTXPERM_UNRESTRICTED, similar to an allow list)
+ * or restricted to a type of devices (similar to a deny list).
+ * Currently only RAM devices can be restricted (MEMTXPERM_RAM_DEVICE).
+ *
+ * Memory accesses to restricted addresses return MEMTX_BUS_ERROR.
+ */
+ unsigned int bus_perm:2;
/* Requester ID (for MSI for example) */
unsigned int requester_id:16;
/* Invert endianness for this page */
@@ -66,6 +86,7 @@ typedef struct MemTxAttrs {
#define MEMTX_OK 0
#define MEMTX_ERROR (1U << 0) /* device returned an error */
#define MEMTX_DECODE_ERROR (1U << 1) /* nothing at that address */
+#define MEMTX_BUS_ERROR (1U << 2) /* bus returned an error */
typedef uint32_t MemTxResult;
#endif
--
2.31.1
- [RFC PATCH v2 1/5] softmmu/physmem: Simplify flatview_write and address_space_access_valid, (continued)