exec: Add RISC-V WorldGuard WID field to MemTxAttrs
PATCH 1/1 exec: Add RISC-V WorldGuard WID field to MemTxAttrs
RISC-V WorldGuard [1] will add 5-bit world_id (WID) to the each memory transaction on the bus. The wgChecker in front of RAM or peripherals MMIO could do the access control based on the WID. It is similar to ARM TrustZone NS bit, but the WID is a 5-bit value.
WID is usually implemented in AXI AxUSER signal (user-defined signals) in the AXI transaction. As we have a secure bit in MemTxAttrs to emulate the TrustZone NS bit, which is implemented in AXI AxPROT[1] signal, I'd like to propose to add world_id field into MemTxAttrs struct.
Since the '_reserved*' fields in MemTxAttr are for padding the struct to be 8-byte [2], we change the reserved fields from 3 to 2 bytes when adding 5-bit world_id field.
[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/
[2] Commit 5014e33b1e00d330f13df33c09a3932ac88f8d94
Link: https://lore.kernel.org/r/[email protected]
--- include/exec/memattrs.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
include/exec/memattrs.h +6 -2
@@ -57,6 +57,11 @@ typedef struct MemTxAttrs {/* PCI - IOMMU operations, see PCIAddressType */ unsigned int address_type:1; +/* +* RISC-V WorldGuard: the 5-bit WID field of memory access. +*/ + unsigned int world_id:5; +/* * Bus masters which don't specify any attributes will get this * (via the MEMTXATTRS_UNSPECIFIED constant), so that we can
@@ -66,8 +71,7 @@ typedef struct MemTxAttrs {*/ bool unspecified; -uint8_t _reserved1; -uint16_t _reserved2; +uint16_t _reserved1; } MemTxAttrs;QEMU_BUILD_BUG_ON (sizeof (MemTxAttrs) >8 );
Signature · 1 line
2.43.0
Quoted 47 lines · Jim Shu
RISC-V WorldGuard [1] will add 5-bit
world_id(WID) to the each memory transaction on the bus. The wgChecker in front of RAM or peripherals MMIO could do the access control based on the WID. It is similar to ARM TrustZone NS bit, but the WID is a 5-bit value.WID is usually implemented in AXI AxUSER signal (user-defined signals) in the AXI transaction. As we have a secure bit in MemTxAttrs to emulate the TrustZone NS bit, which is implemented in AXI AxPROT[1] signal, I'd like to propose to add
world_idfield into MemTxAttrs struct.Since the '_reserved*' fields in MemTxAttr are for padding the struct to be 8-byte [2], we change the reserved fields from 3 to 2 bytes when adding 5-bit
world_idfield.[1] RISC-V WG:
https://patchew.org/QEMU/[email protected]/[2] Commit
5014e33b1e00d330f13df33c09a3932ac88f8d94Link: https://lore.kernel.org/r/[email protected]Cc Paolo Bonzini <[email protected]>Cc Peter Xu <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Daniel Henrique Barboza <[email protected]>Signed-off-by Jim Shu <[email protected]>--- include/exec/memattrs.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)include/exec/memattrs.h +5
-0@@ -57,6 +57,11 @@ typedef struct MemTxAttrs {/* PCI - IOMMU operations, see PCIAddressType */ unsigned int address_type:1; +/* +* RISC-V WorldGuard: the 5-bit WID field of memory access. +*/ + unsigned int world_id:5; +/* * Bus masters which don't specify any attributes will get this * (via the MEMTXATTRS_UNSPECIFIED constant), so that we can
include/exec/memattrs.h typedef struct MemTxAttrs { · line 75
Quoted 7 lines
include/exec/memattrs.h +1
-2@@ -66,8 +71,7 @@ typedef struct MemTxAttrs {*/ bool unspecified; -uint8_t _reserved1; -uint16_t _reserved2; +uint16_t _reserved1; } MemTxAttrs;
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user, requester_id, pid).
I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Time to paint the bikeshed again?
r~
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...
Quoted 11 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Time to paint the bikeshed again?
I can union the 'secure' and 'world_id' fields, as they are not used together. However, I have no idea about the 'space' fields.
I have seen CPUTLBEntryFull has the extra union to support ARM-specific members. Another idea is that also adding the extra union to MemTxAttrs to place the RISC-V worid_id.
We can use this extra union to as SoC-specific signals in the bus, like AXI AxUSER signal.
Do you think it is suitable?
Thanks,
Jim
Quoted 13 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 10 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/
(see also a suggestion in https://lore.kernel.org/qemu-devel/[email protected]/)
Quoted 16 lines
Quoted 1 line
I can union the 'secure' and '
world_id' fields, as they are not used together. However, I have no idea about the 'space' fields.I have seen CPUTLBEntryFull has the extra union to support ARM-specific members. Another idea is that also adding the extra union to MemTxAttrs to place the RISC-V
worid_id.
We can use this extra union to as SoC-specific signals in the bus, like AXI AxUSER signal.
Do you think it is suitable?Thanks,
Jim
Hi all,
I'd like to discuss this issue again.
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 1 line
Hmm. This really overlaps the secure and space fields from arm, and
possibly some of the
Quoted 3 lines
Quoted 3 lines
others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would
be nice to not keep
Quoted 1 line
Quoted 1 line
expanding the count of these sorts of fields that somehow specify the
originator, but
Quoted 2 lines
Quoted 2 lines
clearly cannot overlap.
Quoted 9 lines
Quoted 1 line
Quoted 1 line
I'm reasonably sure we've had this discussion before, but nothing has
come of it.
Quoted 2 lines
Quoted 2 lines
Time to paint the bikeshed again?
Last discussion IIRC:
Follow the idea in the above thread. I'd plan to add the 'src_cpu_id' field to 'MemTxAttr', so we can get the CPUState from MemTxAttr. Thus, we can retrieve the RISC-V world_id from CPU and we don't need to add world_id to 'MemTxAttr'. If other security attributes are stored in CPU states, they can also reuse this w/o adding more data to 'MemTxAttr'.
The whole plan is to add the following 2 fields
::
unsigned int src_is_cpu:1;
uint16_t src_cpu_id;src_cpu_id is the CPU ID from 'CPUState->cpu_index'. src_is_cpu is a boolean flag to check if the transaction is from CPU.
Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like world_id. We can also add src_device field to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-use requester_id as DMA device ID is another possible method to support this.
(p.s. DMA transactions world_id is NOT covered by my current patchset. I just explain this concept for the discussion.)
Does anyone think it is an acceptable plan? Any feedback is welcome.
In the next series, I will implement this plan to add the cpu_id instead of world_id if there is no problem about it.
Regards,
Jim
Quoted 23 lines
(see also a suggestion in
https://lore.kernel.org/qemu-devel/[email protected]/)Quoted 3 lines
Quoted 1 line
I can union the 'secure' and '
world_id' fields, as they are not usedtogether.
Quoted 3 lines
However, I have no idea about the 'space' fields.
I have seen CPUTLBEntryFull has the extra union to support ARM-specific
members.
Quoted 10 lines
Another idea is that also adding the extra union to MemTxAttrs to place the RISC-V
worid_id.
We can use this extra union to as SoC-specific signals in the bus, like AXI AxUSER signal.
Do you think it is suitable?Thanks,
Jim
Quoted 20 lines · Jim Shu
Hi all,
I'd like to discuss this issue again.
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 9 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/Follow the idea in the above thread. I'd plan to add the '
src_cpu_id' field to 'MemTxAttr', so we can get the CPUState from MemTxAttr. Thus, we can retrieve the RISC-Vworld_idfrom CPU and we don't need to addworld_idto 'MemTxAttr'. If other security attributes are stored in CPU states, they can also reuse this w/o adding more data to 'MemTxAttr'.
We already have a requester_id field, which is basically "what is the thing that is sending this request?". We shouldn't have memory transactions that happen to be from CPUs indicate the source in a totally different way.
Quoted 8 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.
I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
I think we would do better to follow the way the hardware does this to the extent that that's reasonable. On hardware the bus/fabric is going to provide the world ID as a signal along with the memory transaction, and we should accordingly put it into the MemTxAttrs. The question for QEMU is then how we organize our MemTxAttrs fields so that we can share between different architectures the fields that are basically doing a similar job, just with different terminology or semantics, so that we keep the overall size of the type small.
thanks
-- PMM
Quoted 63 lines · Peter Maydell
Quoted 20 lines · Jim Shu
Hi all,
I'd like to discuss this issue again.
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 9 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/Follow the idea in the above thread. I'd plan to add the '
src_cpu_id' field to 'MemTxAttr', so we can get the CPUState from MemTxAttr. Thus, we can retrieve the RISC-Vworld_idfrom CPU and we don't need to addworld_idto 'MemTxAttr'. If other security attributes are stored in CPU states, they can also reuse this w/o adding more data to 'MemTxAttr'.We already have a
requester_idfield, which is basically "what is the thing that is sending this request?". We shouldn't have memory transactions that happen to be from CPUs indicate the source in a totally different way.Quoted 8 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
I think we would do better to follow the way the hardware does this to the extent that that's reasonable. On hardware the bus/fabric is going to provide the world ID as a signal along with the memory transaction, and we should accordingly put it into the MemTxAttrs. The question for QEMU is then how we organize our MemTxAttrs fields so that we can share between different architectures the fields that are basically doing a similar job, just with different terminology or semantics, so that we keep the overall size of the type small.
thanks
-- PMM
Quoted 41 lines · Jim Shu
Quoted 34 lines · Peter Maydell
Quoted 20 lines · Jim Shu
Hi all,
I'd like to discuss this issue again.
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 9 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/Follow the idea in the above thread. I'd plan to add the '
src_cpu_id' field to 'MemTxAttr', so we can get the CPUState from MemTxAttr. Thus, we can retrieve the RISC-Vworld_idfrom CPU and we don't need to addworld_idto 'MemTxAttr'. If other security attributes are stored in CPU states, they can also reuse this w/o adding more data to 'MemTxAttr'.We already have a
requester_idfield, which is basically "what is the thing that is sending this request?". We shouldn't have memory transactions that happen to be from CPUs indicate the source in a totally different way.
Thanks for mentioning it! I think re-use requester_id is better. Then, I think we only need a boolean flag src_is_cpu and we can rename it to requester_is_cpu to match the naming of requester_id.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
OK, I think store the DMA device ID in the requester_id is another way to keep the small size.
However, IIUC, the current SysbusDevice doesn't have the concept of a device ID. We need to add an additional device ID to the device to support this idea.
Quoted 10 lines
Quoted 10 lines
I think we would do better to follow the way the hardware does this to the extent that that's reasonable. On hardware the bus/fabric is going to provide the world ID as a signal along with the memory transaction, and we should accordingly put it into the MemTxAttrs. The question for QEMU is then how we organize our MemTxAttrs fields so that we can share between different architectures the fields that are basically doing a similar job, just with different terminology or semantics, so that we keep the overall size of the type small.
OK. if we prefer to keep world_id / secure / space bits in MemTxAttrs and conbine them together for smaller size instead of adding cpu_id, I will try to plan for it.
Thanks for the feedback!
Quoted 3 lines
Quoted 3 lines
thanks
-- PMM
Thanks
Jim
Quoted 39 lines · Jim Shu
Quoted 37 lines · Jim Shu
Quoted 30 lines · Peter Maydell
Quoted 27 lines · Jim Shu
Hi all,
I'd like to discuss this issue again.
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 7 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/Follow the idea in the above thread. I'd plan to add the '
src_cpu_id' field to 'MemTxAttr', so we can get the CPUState from MemTxAttr. Thus, we can retrieve the RISC-Vworld_idfrom CPU and we don't need to addworld_idto 'MemTxAttr'. If other security attributes are stored in CPU states, they can also reuse this w/o adding more data to 'MemTxAttr'.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
We already have a
requester_idfield, which is basically "what is the thing that is sending this request?". We shouldn't have memory transactions that happen to be from CPUs indicate the source in a totally different way.Thanks for mentioning it! I think re-use
requester_idis better. Then, I think we only need a boolean flagsrc_is_cpuand we can rename it torequester_is_cputo match the naming ofrequester_id.
But, what do you now want it for? If we put the world ID in the MemTxAttrs, do you still need a CPU ID? (There are some situations where it might be useful, but if we don't need it right now we shouldn't put doing that rework in the path of implementing the worldguard work you want to do.)
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
Quoted 5 lines
OK, I think store the DMA device ID in the
requester_idis another way to keep the small size.
However, IIUC, the current SysbusDevice doesn't have the concept of a device ID. We need to add an additional device ID to the device to support this idea.
What exactly is it that you need a device ID for? Earlier you suggest that you would want it to get the world ID -- but we should just put the world ID directly in the MemTxAttrs.
thanks
-- PMM
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Jim Shu
Thanks for mentioning it! I think re-use
requester_idis better. Then, I think we only need a boolean flagsrc_is_cpuand we can rename it torequester_is_cputo match the naming ofrequester_id.
Quoted 5 lines
But, what do you now want it for? If we put the world ID in the MemTxAttrs, do you still need a CPU ID? (There are some situations where it might be useful, but if we don't need it right now we shouldn't put doing that rework in the path of implementing the worldguard work you want to do.)
Yes, Adding the world ID to MemTxAttrs is totally enough for me and the worldguard patch series.
I just explain the idea if someone still wants to use CPU ID. Sorry for the confusion.
I will try to add a field that combines ARM secure/space and RISC-V World ID bits in the next series.
Quoted 22 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
Quoted 5 lines
OK, I think store the DMA device ID in the
requester_idis another way to keep the small size.
However, IIUC, the current SysbusDevice doesn't have the concept of a device ID. We need to add an additional device ID to the device to support this idea.
Quoted 3 lines
What exactly is it that you need a device ID for? Earlier you suggest that you would want it to get the world ID -- but we should just put the world ID directly in the MemTxAttrs.
Same as previous responce. Adding the world ID is enough for me. Sorry for the confusion.
Thanks,
Jim
Hi everyone,
Sorry for arriving 5 months late. From what I read from these discussions this patch has no blockers and all we need is probably a rebase and a resend as soon as the next merge window opens. Is this a fair understanding?
Thanks,
Daniel
Quoted 55 lines · Jim Shu
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Jim Shu
Thanks for mentioning it! I think re-use
requester_idis better. Then, I think we only need a boolean flagsrc_is_cpuand we can rename it torequester_is_cputo match the naming ofrequester_id.Quoted 5 lines
But, what do you now want it for? If we put the world ID in the MemTxAttrs, do you still need a CPU ID? (There are some situations where it might be useful, but if we don't need it right now we shouldn't put doing that rework in the path of implementing the worldguard work you want to do.)
Yes, Adding the world ID to MemTxAttrs is totally enough for me and the worldguard patch series.
I just explain the idea if someone still wants to use CPU ID. Sorry for the confusion.
I will try to add a field that combines ARM secure/space and RISC-V World ID bits in the next series.Quoted 22 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
Quoted 5 lines
OK, I think store the DMA device ID in the
requester_idis another way to keep the small size.
However, IIUC, the current SysbusDevice doesn't have the concept of a device ID. We need to add an additional device ID to the device to support this idea.Quoted 3 lines
What exactly is it that you need a device ID for? Earlier you suggest that you would want it to get the world ID -- but we should just put the world ID directly in the MemTxAttrs.
Same as previous responce. Adding the world ID is enough for me. Sorry for the confusion.
Thanks,
Jim
Quoted 6 lines · Daniel Henrique Barboza
Hi everyone,
Sorry for arriving 5 months late. From what I read from these discussions this patch has no blockers and all we need is probably a rebase and a resend as soon as the next merge window opens. Is this a fair understanding?
I think the general idea is ok, did you get a chance to look at my previous approach that I mentioned up-thread?
Quoted 63 lines
Thanks,
DanielQuoted 57 lines · Jim Shu
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Jim Shu
Thanks for mentioning it! I think re-use
requester_idis better. Then, I think we only need a boolean flagsrc_is_cpuand we can rename it torequester_is_cputo match the naming ofrequester_id.Quoted 5 lines
But, what do you now want it for? If we put the world ID in the MemTxAttrs, do you still need a CPU ID? (There are some situations where it might be useful, but if we don't need it right now we shouldn't put doing that rework in the path of implementing the worldguard work you want to do.)
Yes, Adding the world ID to MemTxAttrs is totally enough for me and the worldguard patch series.
I just explain the idea if someone still wants to use CPU ID. Sorry for the confusion.
I will try to add a field that combines ARM secure/space and RISC-V World ID bits in the next series.Quoted 28 lines
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.Quoted 6 lines
Quoted 6 lines
I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
Quoted 5 lines
OK, I think store the DMA device ID in the
requester_idis another way to keep the small size.
However, IIUC, the current SysbusDevice doesn't have the concept of a device ID. We need to add an additional device ID to the device to support this idea.Quoted 3 lines
What exactly is it that you need a device ID for? Earlier you suggest that you would want it to get the world ID -- but we should just put the world ID directly in the MemTxAttrs.
Same as previous responce. Adding the world ID is enough for me. Sorry for the confusion.
Thanks,
Jim
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 11 lines · Alex Bennée
Quoted 6 lines · Daniel Henrique Barboza
Hi everyone,
Sorry for arriving 5 months late. From what I read from these discussions this patch has no blockers and all we need is probably a rebase and a resend as soon as the next merge window opens. Is this a fair understanding?
I think the general idea is ok, did you get a chance to look at my previous approach that I mentioned up-thread?
I did. Seems like we can use that MemTxRequesterType approach, or something close to it, to handle this WorldGuard requirement. Jim, care to comment?
Cheers,
Daniel
Quoted 65 lines
Quoted 64 lines
Thanks,
DanielQuoted 57 lines · Jim Shu
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Jim Shu
Thanks for mentioning it! I think re-use
requester_idis better. Then, I think we only need a boolean flagsrc_is_cpuand we can rename it torequester_is_cputo match the naming ofrequester_id.Quoted 5 lines
But, what do you now want it for? If we put the world ID in the MemTxAttrs, do you still need a CPU ID? (There are some situations where it might be useful, but if we don't need it right now we shouldn't put doing that rework in the path of implementing the worldguard work you want to do.)
Yes, Adding the world ID to MemTxAttrs is totally enough for me and the worldguard patch series.
I just explain the idea if someone still wants to use CPU ID. Sorry for the confusion.
I will try to add a field that combines ARM secure/space and RISC-V World ID bits in the next series.Quoted 28 lines
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
The whole plan is to add the following 2 fields
::unsigned int src_is_cpu:1; uint16_t src_cpu_id;
src_cpu_idis the CPU ID from 'CPUState->cpu_index'.src_is_cpuis a boolean flag to check if the transaction is from CPU.Moreover, I think this idea is extensible. DMA device transactions can also have security attributes like
world_id. We can also addsrc_devicefield to 'MemTxAttr' to store the 'DeviceState *', so we can get the DeviceState from MemTxAttr to get security attributes. If 'DeviceState *' is too large to add to 'MemTxAttr', re-userequester_idas DMA device ID is another possible method to support this.Quoted 6 lines
Quoted 6 lines
I don't think that having the thing that receives the memory transaction get or get hold of a pointer to the source of the transaction that it then uses to get the world ID is a good idea. (Especially not putting a DeviceState* into MemTxAttrs: the size of the type needs to be kept small so we can conveniently pass it around by value: we currently assert that it is 8 bytes.)
Quoted 5 lines
OK, I think store the DMA device ID in the
requester_idis another way to keep the small size.
However, IIUC, the current SysbusDevice doesn't have the concept of a device ID. We need to add an additional device ID to the device to support this idea.Quoted 3 lines
What exactly is it that you need a device ID for? Earlier you suggest that you would want it to get the world ID -- but we should just put the world ID directly in the MemTxAttrs.
Same as previous responce. Adding the world ID is enough for me. Sorry for the confusion.
Thanks,
Jim
Quoted 13 lines · Daniel Henrique Barboza
Quoted 9 lines · Alex Bennée
Quoted 6 lines · Daniel Henrique Barboza
Hi everyone,
Sorry for arriving 5 months late. From what I read from these discussions this patch has no blockers and all we need is probably a rebase and a resend as soon as the next merge window opens. Is this a fair understanding?
Quoted 5 lines
Quoted 2 lines
I think the general idea is ok, did you get a chance to look at my previous approach that I mentioned up-thread?
I did. Seems like we can use that MemTxRequesterType approach, or something close to it, to handle this WorldGuard requirement. Jim, care to comment?
No, that doesn't sound right to me. Alex's MemTxRequesterType is for disambiguating different uses of the requester_id field (i.e. "who is sending this transaction?". The WorldGuard information is more like the existing Arm "space" field, it is "what are the rights this transaction has (what can it see)?". If you need to expand the use of requester_id then we should work on the general lines Alex suggests, but my impression from the thread was that you don't need that. If you don't need it then we shouldn't block the functionality you do need behind reworking something that's not really related/required.
thanks
-- PMM
Quoted 21 lines · Peter Maydell
Quoted 13 lines · Daniel Henrique Barboza
Quoted 9 lines · Alex Bennée
Quoted 6 lines · Daniel Henrique Barboza
Hi everyone,
Sorry for arriving 5 months late. From what I read from these discussions this patch has no blockers and all we need is probably a rebase and a resend as soon as the next merge window opens. Is this a fair understanding?
Quoted 5 lines
Quoted 2 lines
I think the general idea is ok, did you get a chance to look at my previous approach that I mentioned up-thread?
I did. Seems like we can use that MemTxRequesterType approach, or something close to it, to handle this WorldGuard requirement. Jim, care to comment?
Quoted 10 lines
No, that doesn't sound right to me. Alex's MemTxRequesterType is for disambiguating different uses of the
requester_idfield (i.e. "who is sending this transaction?". The WorldGuard information is more like the existing Arm "space" field, it is "what are the rights this transaction has (what can it see)?". If you need to expand the use ofrequester_idthen we should work on the general lines Alex suggests, but my impression from the thread was that you don't need that. If you don't need it then we shouldn't block the functionality you do need behind reworking something that's not really related/required.
I believe you're correct. The original commit msg says:
"RISC-V WorldGuard [1] will add 5-bit world_id (WID) to the each memory transaction on the bus. The wgChecker in front of RAM or peripherals MMIO could do the access control based on the WID. It is similar to ARM TrustZone NS bit, but the WID is a 5-bit value."
Thus we don't need to necessarily expand the use of requester_id and adding world_id in MemTxAttrs is enough. So I guess what we're missing here is a rebase/resend.
Jim, you also mentioned in the thread:
"I will try to add a field that combines ARM secure/space and RISC-V World ID bits in the next series."
I am not sure whether this is something you already sent and I missed or this is an idea for a future follow-up. Either way I think we should take care of this patch first.
Thanks,
Daniel
Quoted 3 lines
thanks
-- PMM
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 9 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/(see also a suggestion in
https://lore.kernel.org/qemu-devel/[email protected]/)
Also somewhat related:
Message-Id: <[email protected]>
Date: Fri, 11 Nov 2022 18:25:15 +0000
Subject: [PATCH for 8.0 v5 00/20] use MemTxAttrs to avoid current_cpu in hw/
Another case that was mentioned in a Core Collective meeting was handling MMIO devices with IOMMUs (currently requester_id is tied to PCI). I guess the WorldGuard WID field is a similar thing.
Quoted 14 lines
Quoted 14 lines
Quoted 2 lines
I can union the 'secure' and '
world_id' fields, as they are not used together.
However, I have no idea about the 'space' fields.
I have seen CPUTLBEntryFull has the extra union to support ARM-specific members.
Another idea is that also adding the extra union to MemTxAttrs to place the RISC-Vworid_id.
We can use this extra union to as SoC-specific signals in the bus, like AXI AxUSER signal.
Do you think it is suitable?
Thanks,
Jim
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 26 lines · Alex Bennée
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 9 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/(see also a suggestion in
https://lore.kernel.org/qemu-devel/[email protected]/)Also somewhat related:
Quoted 7 lines
Message-Id: <[email protected]>
Date: Fri, 11 Nov 2022 18:25:15 +0000
Subject: [PATCH for 8.0 v5 00/20] use MemTxAttrs to avoidcurrent_cpuin hw/Another case that was mentioned in a Core Collective meeting was handling MMIO devices with IOMMUs (currently
requester_idis tied to PCI). I guess the WorldGuard WID field is a similar thing.
The worldguard ID is more like the Arm security space field, as I understand it -- it encodes what the request should or should not be able to access, and multiple different transaction masters might be able to send with the same worldguard ID. A requester_id on the other hand is intended to identify a unique sender. (In AXI these things turn up in different signals.)
I think the trick with requester_id is that we need to identify what we need to encode here and make sure we don't confuse things. (e.g. a CPU needs to not be able to emit something that looks like a PCI request by accident, because some devices need to be able to tell "this really did come from a PCI device" from "this is a CPU doing a normal load/store insn"). So we probably want some kind of "this is what the requester_id is" enum rather than just a convention.
thanks
-- PMM
Quoted 42 lines · Peter Maydell
Quoted 26 lines · Alex Bennée
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Jim Shu
On Tue, Feb 10, 2026 at 8:25 AM Richard Henderson
<[email protected]> wrote:
...Quoted 9 lines
Hmm. This really overlaps the secure and space fields from arm, and possibly some of the others as well (e.g. user,
requester_id, pid).I don't really have a good suggestion for that right now, but it would be nice to not keep expanding the count of these sorts of fields that somehow specify the originator, but clearly cannot overlap.
I'm reasonably sure we've had this discussion before, but nothing has come of it.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Time to paint the bikeshed again?
Last discussion IIRC:
https://lore.kernel.org/qemu-devel/CAFEAcA8vKNkfKgp_Yymo9NA1=E2XJYXAMTgO3z6q6DHgqkAwRw@mail.gmail.com/(see also a suggestion in
https://lore.kernel.org/qemu-devel/[email protected]/)Also somewhat related:
Quoted 7 lines
Message-Id: <[email protected]>
Date: Fri, 11 Nov 2022 18:25:15 +0000
Subject: [PATCH for 8.0 v5 00/20] use MemTxAttrs to avoidcurrent_cpuin hw/Another case that was mentioned in a Core Collective meeting was handling MMIO devices with IOMMUs (currently
requester_idis tied to PCI). I guess the WorldGuard WID field is a similar thing.The worldguard ID is more like the Arm security space field, as I understand it -- it encodes what the request should or should not be able to access, and multiple different transaction masters might be able to send with the same worldguard ID. A
requester_idon the other hand is intended to identify a unique sender. (In AXI these things turn up in different signals.)
Quoted 8 lines
I think the trick with
requester_idis that we need to identify what we need to encode here and make sure we don't confuse things. (e.g. a CPU needs to not be able to emit something that looks like a PCI request by accident, because some devices need to be able to tell "this really did come from a PCI device" from "this is a CPU doing a normal load/store insn"). So we probably want some kind of "this is what therequester_idis" enum rather than just a convention.
Yeah I had a type:
/**
* typedef MemTxRequesterType - source of memory transaction *
* Every memory transaction comes from a specific place which defines
* how requester_id should be handled if at all.
*
* UNSPECIFIED: the default for otherwise undefined MemTxAttrs
* CPU: requester_id is the global cpu_index
* This needs further processing if you need to work out which
* socket or complex it comes from
* PCI: indicates the requester_id is a PCI id
* MACHINE: indicates a machine specific encoding
* This will require further processing to decode into its
* constituent parts.
*/
typedef enum MemTxRequesterType {
MTRT_UNSPECIFIED = 0,
MTRT_CPU,
MTRT_PCI,
MTRT_MACHINE
} MemTxRequesterType;
/**
* typedef MemTxAttrs - attributes of a memory transaction *
* 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
* bus (such as the ARM Secure/NonSecure bit). We define them
* all as non-overlapping bitfields in a single struct to avoid
* confusion if different parts of QEMU used the same bit for
* different semantics.
*/
typedef struct MemTxAttrs {
/* Requester type (e.g. CPU or PCI MSI) */
MemTxRequesterType requester_type:2;
/* Requester ID */
unsigned int requester_id:16;
/*
* ARM/AMBA: TrustZone Secure access
* x86: System Management Mode access
*/
unsigned int secure:1;
/*
* ARM: ArmSecuritySpace. This partially overlaps secure, but it is
* easier to have both fields to assist code that does not understand
* ARMv9 RME, or no specific knowledge of ARM at all (e.g. pflash).
*/
unsigned int space:2;
/* Memory access is usermode (unprivileged) */
unsigned int user:1;
/*
* Bus interconnect and peripherals can access anything (memories,
* devices) by default. By setting the 'memory' bit, bus transaction
* are restricted to "normal" memories (per the AMBA documentation)
* versus devices. Access to devices will be logged and rejected
* (see MEMTX_ACCESS_ERROR).
*/
unsigned int memory:1;
/* Debug access that can even write to ROM. */
unsigned int debug:1;
/*
* PID (PCI PASID) support: Limited to 8 bits process identifier.
*/
unsigned int pid:8;
/* PCI - IOMMU operations, see PCIAddressType */
unsigned int address_type:1;
uint8_t _reserved1;
uint16_t _reserved2;} MemTxAttrs;
But I suspect MTRT_MACHINE might be a bit too much of a blunt instrument. I never used in my series but the idea is it would call back to the machine to work out how it interpreted requester_id.
Quoted 3 lines
thanks
-- PMM
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro