All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Komlodi <komlodi@google.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, peterx@redhat.com, david@redhat.com,
	 peter.maydell@linaro.org, marcel.apfelbaum@gmail.com,
	mst@redhat.com,  philmd@linaro.org, roqueh@google.com,
	slongfield@google.com,  komlodi@google.com
Subject: [RFC PATCH 1/5] target/arm: Add requester ID to memattrs
Date: Tue, 27 Feb 2024 22:24:13 +0000	[thread overview]
Message-ID: <20240227222417.929367-2-komlodi@google.com> (raw)
In-Reply-To: <20240227222417.929367-1-komlodi@google.com>

I've seen a few different instances where a CPU or a memory region is
behind some sort of IOMMU, and the IOMMU translates (or denies) accesses
based on the requester ID of the CPU.

This patch only does it on ARM CPUs, because I did not see CPU-agnostic
code that added CPU attributes when creating TLBs. Similarly, we add the
requester ID during PTW, while populating the rest of the memory
attributes.

We add the requester ID during GPC and descriptor grabbing as well as
PTWs.

Signed-off-by: Joe Komlodi <komlodi@google.com>
---
 target/arm/cpu.c | 4 ++++
 target/arm/cpu.h | 6 ++++++
 target/arm/ptw.c | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 5fa86bc8d5..9cfbba10c2 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -2402,6 +2402,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
         }
     }
 
+    /* For MemTxAttrs. */
+    env->requester_id = cpu->requester_id;
+
     qemu_init_vcpu(cs);
     cpu_reset(cs);
 
@@ -2439,6 +2442,7 @@ static Property arm_cpu_properties[] = {
                         mp_affinity, ARM64_AFFINITY_INVALID),
     DEFINE_PROP_INT32("node-id", ARMCPU, node_id, CPU_UNSET_NUMA_NODE_ID),
     DEFINE_PROP_INT32("core-count", ARMCPU, core_count, -1),
+    DEFINE_PROP_UINT16("requester-id", ARMCPU, requester_id, 0),
     DEFINE_PROP_END_OF_LIST()
 };
 
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 63f31e0d98..5fc572e077 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -774,6 +774,9 @@ typedef struct CPUArchState {
     /* Linux syscall tagged address support */
     bool tagged_addr_enable;
 #endif
+
+    /* For MemTxAttrs. */
+    uint16_t requester_id;
 } CPUARMState;
 
 static inline void set_feature(CPUARMState *env, int feature)
@@ -1091,6 +1094,9 @@ struct ArchCPU {
 
     /* Generic timer counter frequency, in Hz */
     uint64_t gt_cntfrq_hz;
+
+    /* Requester ID, used in MemTxAttrs. */
+    uint16_t requester_id;
 };
 
 typedef struct ARMCPUInfo {
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 5eb3577bcd..148af3a000 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -287,6 +287,7 @@ static bool granule_protection_check(CPUARMState *env, uint64_t paddress,
     MemTxAttrs attrs = {
         .secure = true,
         .space = ARMSS_Root,
+        .requester_id = env->requester_id,
     };
     ARMCPU *cpu = env_archcpu(env);
     uint64_t gpccr = env->cp15.gpccr_el3;
@@ -638,6 +639,7 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw,
         MemTxAttrs attrs = {
             .space = ptw->out_space,
             .secure = arm_space_is_secure(ptw->out_space),
+            .requester_id = env->requester_id,
         };
         AddressSpace *as = arm_addressspace(cs, attrs);
         MemTxResult result = MEMTX_OK;
@@ -684,6 +686,7 @@ static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw,
         MemTxAttrs attrs = {
             .space = ptw->out_space,
             .secure = arm_space_is_secure(ptw->out_space),
+            .requester_id = env->requester_id,
         };
         AddressSpace *as = arm_addressspace(cs, attrs);
         MemTxResult result = MEMTX_OK;
@@ -3306,6 +3309,8 @@ static bool get_phys_addr_nogpc(CPUARMState *env, S1Translate *ptw,
     result->f.attrs.space = ptw->in_space;
     result->f.attrs.secure = arm_space_is_secure(ptw->in_space);
 
+    result->f.attrs.requester_id = env->requester_id;
+
     switch (mmu_idx) {
     case ARMMMUIdx_Phys_S:
     case ARMMMUIdx_Phys_NS:
-- 
2.44.0.rc0.258.g7320e95886-goog



  reply	other threads:[~2024-02-27 22:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 22:24 [RFC PATCH 0/5] memattrs: target/arm: add user-defined and requester ID memattrs Joe Komlodi
2024-02-27 22:24 ` Joe Komlodi [this message]
2024-02-27 22:24 ` [RFC PATCH 2/5] memattrs: Fix target_tlb_bit whitespace Joe Komlodi
2024-02-27 22:24 ` [RFC PATCH 3/5] memattrs: Add user-defined attribute Joe Komlodi
2024-02-28 11:47   ` Alex Bennée
2024-02-27 22:24 ` [RFC PATCH 4/5] target/arm: Add user-defined memattrs Joe Komlodi
2024-02-27 22:24 ` [RFC PATCH 5/5] hw/pci: " Joe Komlodi
2024-02-28 14:21 ` [RFC PATCH 0/5] memattrs: target/arm: add user-defined and requester ID memattrs Peter Maydell
2024-02-29  4:52   ` Joe Komlodi
2024-02-29  9:57     ` Peter Maydell
2024-02-29 17:15       ` Joe Komlodi

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=20240227222417.929367-2-komlodi@google.com \
    --to=komlodi@google.com \
    --cc=david@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=roqueh@google.com \
    --cc=slongfield@google.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.