Skip to contentSkip to conversation

FF-A notifications

PATCH Superseded Jens Wiklander 3 participants 21 messages Apr 22, 2024 – Apr 24, 2024

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover FF-A notifications

Hi,

This patch set adds support for FF-A notifications. We only support global notifications, per vCPU notifications remain unsupported.

The first three patches are further cleanup and can be merged before the rest if desired.

A physical SGI is used to make Xen aware of pending FF-A notifications. The physical SGI is selected by the SPMC in the secure world. Since it must not already be used by Xen the SPMC is in practice forced to donate one of the secure SGIs, but that's normally not a problem. The SGI handling in Xen is updated to support registration of handlers for SGIs that aren't statically assigned, that is, SGI IDs above GIC_SGI_MAX.

Thanks,
Jens

v1->v2:
- "xen/arm: ffa: support notification" and
"xen/arm: allow dynamically assigned SGI handlers" updated as requestsed, details in each patch.
- Added Bertrands R-B for "xen/arm: ffa: refactor ffa_handle_call()", "xen/arm: ffa: use ACCESS_ONCE()", and
"xen/arm: ffa: simplify ffa_handle_mem_share()"

Jens Wiklander (5):
xen/arm: ffa: refactor ffa_handle_call() xen/arm: ffa: use ACCESS_ONCE()
xen/arm: ffa: simplify ffa_handle_mem_share() xen/arm: allow dynamically assigned SGI handlers xen/arm: ffa: support notification

 xen/arch/arm/gic.c              |   5 +-
 xen/arch/arm/irq.c              |   7 +-
 xen/arch/arm/tee/Makefile       |   1 +
 xen/arch/arm/tee/ffa.c          |  83 +++++---
 xen/arch/arm/tee/ffa_notif.c    | 331 ++++++++++++++++++++++++++++++++
 xen/arch/arm/tee/ffa_partinfo.c |   9 +-
 xen/arch/arm/tee/ffa_private.h  |  68 ++++++-
 xen/arch/arm/tee/ffa_shm.c      |  33 ++--
 8 files changed, 488 insertions(+), 49 deletions(-)
 create mode 100644 xen/arch/arm/tee/ffa_notif.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/5 xen/arm: ffa: refactor ffa_handle_call()

Refactors the large switch block in ffa_handle_call() to use common code for the simple case where it's either an error code or success with no further parameters.

---
 xen/arch/arm/tee/ffa.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
xen/arch/arm/tee/ffa.c +10 -20
index 8665201e34a9..5209612963e1 100644
@@ -273,18 +273,10 @@ static bool ffa_handle_call(struct cpu_user_regs *regs)
     case FFA_RXTX_MAP_64:
         e = ffa_handle_rxtx_map(fid, get_user_reg(regs, 1),
 				get_user_reg(regs, 2), get_user_reg(regs, 3));
-        if ( e )
-            ffa_set_regs_error(regs, e);
-        else
-            ffa_set_regs_success(regs, 0, 0);
-        return true;
+        break;
     case FFA_RXTX_UNMAP:
         e = ffa_handle_rxtx_unmap();
-        if ( e )
-            ffa_set_regs_error(regs, e);
-        else
-            ffa_set_regs_success(regs, 0, 0);
-        return true;
+        break;
     case FFA_PARTITION_INFO_GET:
         e = ffa_handle_partition_info_get(get_user_reg(regs, 1),
                                           get_user_reg(regs, 2),
@@ -299,11 +291,7 @@ static bool ffa_handle_call(struct cpu_user_regs *regs)
         return true;
     case FFA_RX_RELEASE:
         e = ffa_handle_rx_release();
-        if ( e )
-            ffa_set_regs_error(regs, e);
-        else
-            ffa_set_regs_success(regs, 0, 0);
-        return true;
+        break;
     case FFA_MSG_SEND_DIRECT_REQ_32:
     case FFA_MSG_SEND_DIRECT_REQ_64:
         handle_msg_send_direct_req(regs, fid);
@@ -316,17 +304,19 @@ static bool ffa_handle_call(struct cpu_user_regs *regs)
         e = ffa_handle_mem_reclaim(regpair_to_uint64(get_user_reg(regs, 2),
                                                      get_user_reg(regs, 1)),
                                    get_user_reg(regs, 3));
-        if ( e )
-            ffa_set_regs_error(regs, e);
-        else
-            ffa_set_regs_success(regs, 0, 0);
-        return true;
+        break;
 
     default:
         gprintk(XENLOG_ERR, "ffa: unhandled fid 0x%x\n", fid);
         ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED);
         return true;
     }
+
+    if ( e )
+        ffa_set_regs_error(regs, e);
+    else
+        ffa_set_regs_success(regs, 0, 0);
+    return true;
 }
 
 static int ffa_domain_init(struct domain *d)
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/5 xen/arm: ffa: use ACCESS_ONCE()

In reply to Jens Wiklander

Replace read_atomic() with ACCESS_ONCE() to match the intended use, that is, to prevent the compiler from (via optimization) reading shared memory more than once.

---
 xen/arch/arm/tee/ffa_shm.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
xen/arch/arm/tee/ffa_shm.c +8 -7
index eed9ad2d2986..75a5b66aeb4c 100644
@@ -7,6 +7,7 @@
 #include <xen/sizes.h>
 #include <xen/types.h>
 #include <xen/mm.h>
+#include <xen/lib.h>
 #include <xen/list.h>
 #include <xen/spinlock.h>
 
@@ -171,8 +172,8 @@ static int get_shm_pages(struct domain *d, struct ffa_shm_mem *shm,
 
     for ( n = 0; n < range_count; n++ )
     {
-        page_count = read_atomic(&range[n].page_count);
-        addr = read_atomic(&range[n].address);
+        page_count = ACCESS_ONCE(range[n].page_count);
+        addr = ACCESS_ONCE(range[n].address);
         for ( m = 0; m < page_count; m++ )
         {
             if ( pg_idx >= shm->page_count )
@@ -527,13 +528,13 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
         goto out_unlock;
 
     mem_access = ctx->tx + trans.mem_access_offs;
-    if ( read_atomic(&mem_access->access_perm.perm) != FFA_MEM_ACC_RW )
+    if ( ACCESS_ONCE(mem_access->access_perm.perm) != FFA_MEM_ACC_RW )
     {
         ret = FFA_RET_NOT_SUPPORTED;
         goto out_unlock;
     }
 
-    region_offs = read_atomic(&mem_access->region_offs);
+    region_offs = ACCESS_ONCE(mem_access->region_offs);
     if ( sizeof(*region_descr) + region_offs > frag_len )
     {
         ret = FFA_RET_NOT_SUPPORTED;
@@ -541,8 +542,8 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
     }
 
     region_descr = ctx->tx + region_offs;
-    range_count = read_atomic(&region_descr->address_range_count);
-    page_count = read_atomic(&region_descr->total_page_count);
+    range_count = ACCESS_ONCE(region_descr->address_range_count);
+    page_count = ACCESS_ONCE(region_descr->total_page_count);
 
     if ( !page_count )
     {
@@ -557,7 +558,7 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
         goto out_unlock;
     }
     shm->sender_id = trans.sender_id;
-    shm->ep_id = read_atomic(&mem_access->access_perm.endpoint_id);
+    shm->ep_id = ACCESS_ONCE(mem_access->access_perm.endpoint_id);
 
     /*
      * Check that the Composite memory region descriptor fits.
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/5 xen/arm: ffa: simplify ffa_handle_mem_share()

In reply to Jens Wiklander

Simplify ffa_handle_mem_share() by removing the start_page_idx and last_page_idx parameters from get_shm_pages() and check that the number of pages matches expectations at the end of get_shm_pages().

---
 xen/arch/arm/tee/ffa_shm.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
xen/arch/arm/tee/ffa_shm.c +6 -12
index 75a5b66aeb4c..370d83ec5cf8 100644
@@ -159,10 +159,9 @@ static int32_t ffa_mem_reclaim(uint32_t handle_lo, uint32_t handle_hi,
  */
 static int get_shm_pages(struct domain *d, struct ffa_shm_mem *shm,
                          const struct ffa_address_range *range,
-                         uint32_t range_count, unsigned int start_page_idx,
-                         unsigned int *last_page_idx)
+                         uint32_t range_count)
 {
-    unsigned int pg_idx = start_page_idx;
+    unsigned int pg_idx = 0;
     gfn_t gfn;
     unsigned int n;
     unsigned int m;
@@ -191,7 +190,9 @@ static int get_shm_pages(struct domain *d, struct ffa_shm_mem *shm,
         }
     }
 
-    *last_page_idx = pg_idx;
+    /* The ranges must add up */
+    if ( pg_idx < shm->page_count )
+            return FFA_RET_INVALID_PARAMETERS;
 
     return FFA_RET_OK;
 }
@@ -460,7 +461,6 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
     struct domain *d = current->domain;
     struct ffa_ctx *ctx = d->arch.tee;
     struct ffa_shm_mem *shm = NULL;
-    unsigned int last_page_idx = 0;
     register_t handle_hi = 0;
     register_t handle_lo = 0;
     int ret = FFA_RET_DENIED;
@@ -570,15 +570,9 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs)
         goto out;
     }
 
-    ret = get_shm_pages(d, shm, region_descr->address_range_array, range_count,
-                        0, &last_page_idx);
+    ret = get_shm_pages(d, shm, region_descr->address_range_array, range_count);
     if ( ret )
         goto out;
-    if ( last_page_idx != shm->page_count )
-    {
-        ret = FFA_RET_INVALID_PARAMETERS;
-        goto out;
-    }
 
     /* Note that share_shm() uses our tx buffer */
     spin_lock(&ffa_tx_buffer_lock);
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 4/5 xen/arm: allow dynamically assigned SGI handlers

In reply to Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they are always edge triggered.

gic_interrupt() is updated to route the dynamically assigned SGIs to do_IRQ() instead of do_sgi(). The latter still handles the statically assigned SGI handlers like for instance GIC_SGI_CALL_FUNCTION.

---
v1->v2
- Update patch description as requested

---
 xen/arch/arm/gic.c | 5 +++--
 xen/arch/arm/irq.c | 7 +++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +3 -2
index 44c40e86defe..e9aeb7138455 100644
@@ -117,7 +117,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)
 
     desc->handler = gic_hw_ops->gic_host_irq_type;
 
-    gic_set_irq_type(desc, desc->arch.type);
+    if ( desc->irq >= NR_GIC_SGI)
+        gic_set_irq_type(desc, desc->arch.type);
     gic_set_irq_priority(desc, priority);
 }
 
@@ -375,7 +376,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)
         /* Reading IRQ will ACK it */
         irq = gic_hw_ops->read_irq();
 
-        if ( likely(irq >= 16 && irq < 1020) )
+        if ( likely(irq >= GIC_SGI_MAX && irq < 1020) )
         {
             isb();
             do_IRQ(regs, irq, is_fiq);
xen/arch/arm/irq.c +5 -2
index bcce80a4d624..fdb214560978 100644
@@ -224,9 +224,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
     perfc_incr(irqs);
 
-    ASSERT(irq >= 16); /* SGIs do not come down this path */
+    /* Statically assigned SGIs do not come down this path */
+    ASSERT(irq >= GIC_SGI_MAX);
 
-    if ( irq < 32 )
+    if ( irq < NR_GIC_SGI )
+        perfc_incr(ipis);
+    else if ( irq < NR_GIC_LOCAL_IRQS )
         perfc_incr(ppis);
     else
         perfc_incr(spis);
Signature · 1 line
2.34.1
#5 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

Quoted 8 lines

gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they are always edge triggered.

gic_interrupt() is updated to route the dynamically assigned SGIs to do_IRQ() instead of do_sgi(). The latter still handles the statically assigned SGI handlers like for instance GIC_SGI_CALL_FUNCTION.

Quoted 7 lines

---
v1->v2
- Update patch description as requested

---
  xen/arch/arm/gic.c | 5 +++--
  xen/arch/arm/irq.c | 7 +++++--

I am not sure where to write the comment. But I think the comment on top of irq_set_affinity() in setup_irq() should also be updated.

xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority) · line 121

Quoted 13 lines
  2 files changed, 8 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +2 -1
index 44c40e86defe..e9aeb7138455 100644
@@ -117,7 +117,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)
 
      desc->handler = gic_hw_ops->gic_host_irq_type;
 
-    gic_set_irq_type(desc, desc->arch.type);
+    if ( desc->irq >= NR_GIC_SGI)
+        gic_set_irq_type(desc, desc->arch.type);

So above, you say that the SGIs are always edge-triggered interrupt. So I assume desc->arch.type. So are you skipping the call because it is unnessary or it could do the wrong thing?

Ideally, the outcome of the answer be part of the comment on top of the check.

xen/arch/arm/gic.c void gic_interrupt(struct cpu_user_regs *regs, int is_fiq) · line 379

Quoted 9 lines
xen/arch/arm/gic.c +1 -1
      gic_set_irq_priority(desc, priority);
  }
 
@@ -375,7 +376,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)
          /* Reading IRQ will ACK it */
          irq = gic_hw_ops->read_irq();
 
-        if ( likely(irq >= 16 && irq < 1020) )
+        if ( likely(irq >= GIC_SGI_MAX && irq < 1020) )

This check is now rather confusing as one could think that do_IRQ() would still not be reached for dynamic SGI. I think it would be clearer GIC_SGI_MAX needs to be renamed to GIC_SGI_STATIC_MAX and do_sgi() to do_static_sgi().

Quoted 8 lines
xen/arch/arm/gic.c +0 -0
          {
              isb();
              do_IRQ(regs, irq, is_fiq);
xen/arch/arm/irq.c +0 -0
index bcce80a4d624..fdb214560978 100644

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 228

Quoted 6 lines
xen/arch/arm/irq.c +2 -1
@@ -224,9 +224,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
      perfc_incr(irqs);
 
-    ASSERT(irq >= 16); /* SGIs do not come down this path */
+    /* Statically assigned SGIs do not come down this path */
+    ASSERT(irq >= GIC_SGI_MAX);

With this change, I think the path with vgic_inject_irq() now needs to gain an ASSERT(irq >= NR_GIC_SGI) because the path is not supposed to be taken for SGIs.

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 235

Quoted 8 lines
xen/arch/arm/irq.c +3 -1
-    if ( irq < 32 )
+    if ( irq < NR_GIC_SGI )
+        perfc_incr(ipis);
+    else if ( irq < NR_GIC_LOCAL_IRQS )
          perfc_incr(ppis);
      else
          perfc_incr(spis);

Cheers,

Signature · 1 line
Julien Grall
#6 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

Hi Julien,

Quoted 9 lines · Julien Grall

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

Quoted 6 lines

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

The firmware decides the SGI number. Given that the firmware doesn't know which SGIs Xen is using it typically needs to donate one of the secure SGIs, but that is transparent to Xen.

Quoted 38 lines
Quoted 9 lines

gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they are always edge triggered.

gic_interrupt() is updated to route the dynamically assigned SGIs to do_IRQ() instead of do_sgi(). The latter still handles the statically assigned SGI handlers like for instance GIC_SGI_CALL_FUNCTION.

Quoted 7 lines

---
v1->v2
- Update patch description as requested

---
  xen/arch/arm/gic.c | 5 +++--
  xen/arch/arm/irq.c | 7 +++++--

I am not sure where to write the comment. But I think the comment on top of irq_set_affinity() in setup_irq() should also be updated.

xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority) · line 121

Quoted 13 lines
  2 files changed, 8 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +2 -1
index 44c40e86defe..e9aeb7138455 100644
@@ -117,7 +117,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)
 
      desc->handler = gic_hw_ops->gic_host_irq_type;
 
-    gic_set_irq_type(desc, desc->arch.type);
+    if ( desc->irq >= NR_GIC_SGI)
+        gic_set_irq_type(desc, desc->arch.type);

So above, you say that the SGIs are always edge-triggered interrupt. So I assume desc->arch.type. So are you skipping the call because it is unnessary or it could do the wrong thing?

Quoted 2 lines

Ideally, the outcome of the answer be part of the comment on top of the check.

gic_set_irq_type() has an assert "ASSERT(type != IRQ_TYPE_INVALID)" which is triggered without this check.
So it's both unnecessary and wrong. I suppose we could update the bookkeeping of all SGIs to be edge-triggered instead of IRQ_TYPE_INVALID. It would still be unnecessary though. What do you suggest?

Quoted 8 lines
Quoted 8 lines
xen/arch/arm/gic.c +0 -0
      gic_set_irq_priority(desc, priority);
  }
 
@@ -375,7 +376,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)
          /* Reading IRQ will ACK it */
          irq = gic_hw_ops->read_irq();
 
Quoted 7 lines

xen/arch/arm/gic.c void gic_interrupt(struct cpu_user_regs *regs, int is_fiq) · line 379

Quoted 2 lines
xen/arch/arm/gic.c +1 -1
-        if ( likely(irq >= 16 && irq < 1020) )
+        if ( likely(irq >= GIC_SGI_MAX && irq < 1020) )

This check is now rather confusing as one could think that do_IRQ() would still not be reached for dynamic SGI. I think it would be clearer GIC_SGI_MAX needs to be renamed to GIC_SGI_STATIC_MAX and do_sgi() to do_static_sgi().

Thanks, I'll update.

Quoted 12 lines
Quoted 12 lines
xen/arch/arm/gic.c +0 -0
          {
              isb();
              do_IRQ(regs, irq, is_fiq);
xen/arch/arm/irq.c +0 -0
index bcce80a4d624..fdb214560978 100644
@@ -224,9 +224,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
      perfc_incr(irqs);
 
Quoted 8 lines

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 228

Quoted 3 lines
xen/arch/arm/irq.c +2 -1
-    ASSERT(irq >= 16); /* SGIs do not come down this path */
+    /* Statically assigned SGIs do not come down this path */
+    ASSERT(irq >= GIC_SGI_MAX);

With this change, I think the path with vgic_inject_irq() now needs to gain an ASSERT(irq >= NR_GIC_SGI) because the path is not supposed to be taken for SGIs.

I'm sorry, I don't see the connection. If I add ASSERT(virq >= NR_GIC_SGI);
at the top of vgic_inject_irq() it will panic when injecting a Schedule Receiver or Notification Pending Interrupt for a guest.

Quoted 10 lines

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 235

Quoted 9 lines
xen/arch/arm/irq.c +3 -1
-    if ( irq < 32 )
+    if ( irq < NR_GIC_SGI )
+        perfc_incr(ipis);
+    else if ( irq < NR_GIC_LOCAL_IRQS )
          perfc_incr(ppis);
      else
          perfc_incr(spis);

Thanks,
Jens

#7 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

Quoted 1 line · Jens Wiklander

Hi Julien,

Hi Jens,

Quoted 13 lines · Julien Grall
Quoted 12 lines

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

Quoted 7 lines
Quoted 3 lines

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

The firmware decides the SGI number. Given that the firmware doesn't know which SGIs Xen is using it typically needs to donate one of the secure SGIs, but that is transparent to Xen.

Right this is my concern. The firmware decides the number, but at the same time Xen thinks that all the SGIs are available (AFAIK there is only one set).

What I would like to see is some wording from a spec indicating that the SGIs ID reserved by the firmware will not be clashing with the one used by Xen.

Quoted 43 lines
Quoted 40 lines
Quoted 11 lines

gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they are always edge triggered.

gic_interrupt() is updated to route the dynamically assigned SGIs to do_IRQ() instead of do_sgi(). The latter still handles the statically assigned SGI handlers like for instance GIC_SGI_CALL_FUNCTION.

Quoted 7 lines

---
v1->v2
- Update patch description as requested

---
   xen/arch/arm/gic.c | 5 +++--
   xen/arch/arm/irq.c | 7 +++++--

I am not sure where to write the comment. But I think the comment on top of irq_set_affinity() in setup_irq() should also be updated.

xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority) · line 121

Quoted 13 lines
   2 files changed, 8 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +2 -1
index 44c40e86defe..e9aeb7138455 100644
@@ -117,7 +117,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)
 
       desc->handler = gic_hw_ops->gic_host_irq_type;
 
-    gic_set_irq_type(desc, desc->arch.type);
+    if ( desc->irq >= NR_GIC_SGI)
+        gic_set_irq_type(desc, desc->arch.type);

So above, you say that the SGIs are always edge-triggered interrupt. So I assume desc->arch.type. So are you skipping the call because it is unnessary or it could do the wrong thing?

Quoted 2 lines

Ideally, the outcome of the answer be part of the comment on top of the check.

Quoted 6 lines

gic_set_irq_type() has an assert "ASSERT(type != IRQ_TYPE_INVALID)" which is triggered without this check.
So it's both unnecessary and wrong. I suppose we could update the bookkeeping of all SGIs to be edge-triggered instead of IRQ_TYPE_INVALID. It would still be unnecessary though. What do you suggest?

I would rather prefer if we update the book-keeping for all the SGIs.

[...]

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/gic.c +0 -0
           {
               isb();
               do_IRQ(regs, irq, is_fiq);
xen/arch/arm/irq.c +0 -0
index bcce80a4d624..fdb214560978 100644
@@ -224,9 +224,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
       perfc_incr(irqs);
 
Quoted 8 lines

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 228

Quoted 3 lines
xen/arch/arm/irq.c +2 -1
-    ASSERT(irq >= 16); /* SGIs do not come down this path */
+    /* Statically assigned SGIs do not come down this path */
+    ASSERT(irq >= GIC_SGI_MAX);

With this change, I think the path with vgic_inject_irq() now needs to gain an ASSERT(irq >= NR_GIC_SGI) because the path is not supposed to be taken for SGIs.

Quoted 4 lines

I'm sorry, I don't see the connection. If I add ASSERT(virq >= NR_GIC_SGI);
at the top of vgic_inject_irq() it will panic when injecting a Schedule Receiver or Notification Pending Interrupt for a guest.

If you look at do_IRQ(), we have the following code:

    if ( test_bit(_IRQ_GUEST, &desc->status) )
    {
        struct irq_guest *info = irq_get_guest_info(desc);

        perfc_incr(guest_irqs);
        desc->handler->end(desc);

        set_bit(_IRQ_INPROGRESS, &desc->status);

        /*
         * The irq cannot be a PPI, we only support delivery of SPIs to
         * guests.
         */
        vgic_inject_irq(info->d, NULL, info->virq, true);
        goto out_no_end;
    }

What I suggesting is to add an ASSERT(irq >= NR_GIC_SGI) just before the call because now do_IRQ() can be called with SGIs yet we don't allow HW SGIs to assigned to a guest.

Cheers,

Signature · 1 line
Julien Grall
#8 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

Hi Julien,

Quoted 25 lines · Julien Grall
Quoted 1 line · Jens Wiklander

Hi Julien,

Hi Jens,

Quoted 16 lines · Julien Grall
Quoted 15 lines

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

Quoted 7 lines
Quoted 3 lines

The firmware decides the SGI number. Given that the firmware doesn't know which SGIs Xen is using it typically needs to donate one of the secure SGIs, but that is transparent to Xen.

Right this is my concern. The firmware decides the number, but at the same time Xen thinks that all the SGIs are available (AFAIK there is only one set).

What I would like to see is some wording from a spec indicating that the SGIs ID reserved by the firmware will not be clashing with the one used by Xen.

The idea is that the only SGI reserved for secure are used by the secure world (in fact it is the SPMC in the secure world who tells us which SGI it will generate). So in theory that means it will always use an SGI between 8 and 15.

Now it could make sense in fact to check that the number returned by the firmware (or SPMC) is not clashing with Xen as it is a recommendation in the spec and in fact an implementation might do something different.

Right now there is no spec that will say that it will never clash with the one used by Xen as the FF-A spec is not enforcing anything here so it would be a good idea to check and disable FF-A with a proper error message if this happens.

Cheers
Bertrand

Quoted 102 lines
Quoted 39 lines
Quoted 39 lines
Quoted 10 lines

gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they are always edge triggered.

gic_interrupt() is updated to route the dynamically assigned SGIs to do_IRQ() instead of do_sgi(). The latter still handles the statically assigned SGI handlers like for instance GIC_SGI_CALL_FUNCTION.

Quoted 7 lines

---
v1->v2
- Update patch description as requested

---
  xen/arch/arm/gic.c | 5 +++--
  xen/arch/arm/irq.c | 7 +++++--

I am not sure where to write the comment. But I think the comment on top of irq_set_affinity() in setup_irq() should also be updated.

xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority) · line 121

Quoted 13 lines
  2 files changed, 8 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +2 -1
index 44c40e86defe..e9aeb7138455 100644
@@ -117,7 +117,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)
 
      desc->handler = gic_hw_ops->gic_host_irq_type;
 
-    gic_set_irq_type(desc, desc->arch.type);
+    if ( desc->irq >= NR_GIC_SGI)
+        gic_set_irq_type(desc, desc->arch.type);

So above, you say that the SGIs are always edge-triggered interrupt. So I assume desc->arch.type. So are you skipping the call because it is unnessary or it could do the wrong thing?

Quoted 8 lines
Quoted 2 lines

Ideally, the outcome of the answer be part of the comment on top of the check.

gic_set_irq_type() has an assert "ASSERT(type != IRQ_TYPE_INVALID)" which is triggered without this check.
So it's both unnecessary and wrong. I suppose we could update the bookkeeping of all SGIs to be edge-triggered instead of IRQ_TYPE_INVALID. It would still be unnecessary though. What do you suggest?

I would rather prefer if we update the book-keeping for all the SGIs.

[...]

Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
xen/arch/arm/gic.c +0 -0
          {
              isb();
              do_IRQ(regs, irq, is_fiq);
xen/arch/arm/irq.c +0 -0
index bcce80a4d624..fdb214560978 100644
@@ -224,9 +224,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
      perfc_incr(irqs);
 
Quoted 8 lines

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 228

Quoted 3 lines
xen/arch/arm/irq.c +2 -1
-    ASSERT(irq >= 16); /* SGIs do not come down this path */
+    /* Statically assigned SGIs do not come down this path */
+    ASSERT(irq >= GIC_SGI_MAX);

With this change, I think the path with vgic_inject_irq() now needs to gain an ASSERT(irq >= NR_GIC_SGI) because the path is not supposed to be taken for SGIs.

Quoted 4 lines

I'm sorry, I don't see the connection. If I add ASSERT(virq >= NR_GIC_SGI);
at the top of vgic_inject_irq() it will panic when injecting a Schedule Receiver or Notification Pending Interrupt for a guest.

If you look at do_IRQ(), we have the following code:

   if ( test_bit(_IRQ_GUEST, &desc->status) )
   {
       struct irq_guest *info = irq_get_guest_info(desc);
       perfc_incr(guest_irqs);
       desc->handler->end(desc);

       set_bit(_IRQ_INPROGRESS, &desc->status);

       /*
        * The irq cannot be a PPI, we only support delivery of SPIs to
        * guests.
        */
       vgic_inject_irq(info->d, NULL, info->virq, true);
       goto out_no_end;

}

What I suggesting is to add an ASSERT(irq >= NR_GIC_SGI) just before the call because now do_IRQ() can be called with SGIs yet we don't allow HW SGIs to assigned to a guest.

Cheers,

Signature · 1 line
Julien Grall
#9 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

Hi Julien,

Quoted 37 lines · Bertrand Marquis

Hi Julien,

Quoted 25 lines · Julien Grall
Quoted 1 line · Jens Wiklander

Hi Julien,

Hi Jens,

Quoted 16 lines · Julien Grall
Quoted 15 lines

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

Quoted 7 lines
Quoted 3 lines

The firmware decides the SGI number. Given that the firmware doesn't know which SGIs Xen is using it typically needs to donate one of the secure SGIs, but that is transparent to Xen.

Right this is my concern. The firmware decides the number, but at the same time Xen thinks that all the SGIs are available (AFAIK there is only one set).

What I would like to see is some wording from a spec indicating that the SGIs ID reserved by the firmware will not be clashing with the one used by Xen.

Quoted 8 lines

The idea is that the only SGI reserved for secure are used by the secure world (in fact it is the SPMC in the secure world who tells us which SGI it will generate). So in theory that means it will always use an SGI between 8 and 15.

Now it could make sense in fact to check that the number returned by the firmware (or SPMC) is not clashing with Xen as it is a recommendation in the spec and in fact an implementation might do something different.

Right now there is no spec that will say that it will never clash with the one used by Xen as the FF-A spec is not enforcing anything here so it would be a good idea to check and disable FF-A with a proper error message if this happens.

After some more digging here is what is recommended by Arm in the Arm Base System Architecture v1.0C [1]:

"The system shall implement at least eight Non-secure SGIs, assigned to interrupt IDs 0-7."

So basically as long as Xen is using SGIs 0-7 it is safe as those shall never be used by the secure world. Now i do agree that we should check that whatever is returned by the firmware is not conflicting with what is used by Xen.

Cheers
Bertrand

[1] https://developer.arm.com/documentation/den0094/

#10 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

Hi Bertrand,

Quoted 45 lines · Bertrand Marquis

Hi Julien,

Quoted 43 lines · Bertrand Marquis

Hi Julien,

Quoted 25 lines · Julien Grall
Quoted 1 line · Jens Wiklander

Hi Julien,

Hi Jens,

Quoted 16 lines · Julien Grall
Quoted 15 lines

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

Quoted 7 lines
Quoted 3 lines

The firmware decides the SGI number. Given that the firmware doesn't know which SGIs Xen is using it typically needs to donate one of the secure SGIs, but that is transparent to Xen.

Right this is my concern. The firmware decides the number, but at the same time Xen thinks that all the SGIs are available (AFAIK there is only one set).

What I would like to see is some wording from a spec indicating that the SGIs ID reserved by the firmware will not be clashing with the one used by Xen.

The idea is that the only SGI reserved for secure are used by the secure world (in fact it is the SPMC in the secure world who tells us which SGI it will generate). So in theory that means it will always use an SGI between 8 and 15.

Now it could make sense in fact to check that the number returned by the firmware (or SPMC) is not clashing with Xen as it is a recommendation in the spec and in fact an implementation might do something different.

Quoted 7 lines
Quoted 2 lines

Right now there is no spec that will say that it will never clash with the one used by Xen as the FF-A spec is not enforcing anything here so it would be a good idea to check and disable FF-A with a proper error message if this happens.

After some more digging here is what is recommended by Arm in the Arm Base System Architecture v1.0C [1]:

"The system shall implement at least eight Non-secure SGIs, assigned to interrupt IDs 0-7."

Thanks! Can we provide a link to the specification in the commit message?

Quoted 4 lines

So basically as long as Xen is using SGIs 0-7 it is safe as those shall never be used by the secure world. Now i do agree that we should check that whatever is returned by the firmware is not conflicting with what is used by Xen.

+1.

Cheers,

Signature · 1 line
Julien Grall
#11 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

Hi,

Quoted 53 lines · Julien Grall

Hi Bertrand,

Quoted 49 lines · Bertrand Marquis

Hi Julien,

Quoted 45 lines · Bertrand Marquis

Hi Julien,

Quoted 25 lines · Julien Grall
Quoted 1 line · Jens Wiklander

Hi Julien,

Hi Jens,

Quoted 16 lines · Julien Grall
Quoted 15 lines

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

Quoted 7 lines
Quoted 3 lines

The firmware decides the SGI number. Given that the firmware doesn't know which SGIs Xen is using it typically needs to donate one of the secure SGIs, but that is transparent to Xen.

Right this is my concern. The firmware decides the number, but at the same time Xen thinks that all the SGIs are available (AFAIK there is only one set).

What I would like to see is some wording from a spec indicating that the SGIs ID reserved by the firmware will not be clashing with the one used by Xen.

The idea is that the only SGI reserved for secure are used by the secure world (in fact it is the SPMC in the secure world who tells us which SGI it will generate). So in theory that means it will always use an SGI between 8 and 15.

Now it could make sense in fact to check that the number returned by the firmware (or SPMC) is not clashing with Xen as it is a recommendation in the spec and in fact an implementation might do something different.

Right now there is no spec that will say that it will never clash with the one used by Xen as the FF-A spec is not enforcing anything here so it would be a good idea to check and disable FF-A with a proper error message if this happens.

Quoted 5 lines
Quoted 3 lines

After some more digging here is what is recommended by Arm in the Arm Base System Architecture v1.0C [1]:

"The system shall implement at least eight Non-secure SGIs, assigned to interrupt IDs 0-7."

Thanks! Can we provide a link to the specification in the commit message?

Sure, I'll add a link.

Quoted 6 lines
Quoted 5 lines

So basically as long as Xen is using SGIs 0-7 it is safe as those shall never be used by the secure world. Now i do agree that we should check that whatever is returned by the firmware is not conflicting with what is used by Xen.

+1.

That makes sense, I'll add a check.

Thanks,
Jens

#12 lore raw

Re: [XEN PATCH v2 4/5] xen/arm: allow dynamically assigned SGI handlers

In reply to Julien Grall
Quoted 80 lines · Julien Grall
Quoted 1 line · Jens Wiklander

Hi Julien,

Hi Jens,

Quoted 13 lines · Julien Grall
Quoted 12 lines

Hi Jens,

Quoted 4 lines · Jens Wiklander

Updates so request_irq() can be used with a dynamically assigned SGI irq as input. This prepares for a later patch where an FF-A schedule receiver interrupt handler is installed for an SGI generated by the secure world.

I would like to understand the use-case a bit more. Who is responsible to decide the SGI number? Is it Xen or the firmware?

Quoted 7 lines
Quoted 3 lines

If the later, how can we ever guarantee the ID is not going to clash with what the OS/hypervisor is using? Is it described in a specification? If so, please give a pointer.

The firmware decides the SGI number. Given that the firmware doesn't know which SGIs Xen is using it typically needs to donate one of the secure SGIs, but that is transparent to Xen.

Right this is my concern. The firmware decides the number, but at the same time Xen thinks that all the SGIs are available (AFAIK there is only one set).

What I would like to see is some wording from a spec indicating that the SGIs ID reserved by the firmware will not be clashing with the one used by Xen.

Quoted 43 lines
Quoted 42 lines
Quoted 11 lines

gic_route_irq_to_xen() don't gic_set_irq_type() for SGIs since they are always edge triggered.

gic_interrupt() is updated to route the dynamically assigned SGIs to do_IRQ() instead of do_sgi(). The latter still handles the statically assigned SGI handlers like for instance GIC_SGI_CALL_FUNCTION.

Quoted 7 lines

---
v1->v2
- Update patch description as requested

---
   xen/arch/arm/gic.c | 5 +++--
   xen/arch/arm/irq.c | 7 +++++--

I am not sure where to write the comment. But I think the comment on top of irq_set_affinity() in setup_irq() should also be updated.

xen/arch/arm/gic.c void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority) · line 121

Quoted 13 lines
   2 files changed, 8 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +2 -1
index 44c40e86defe..e9aeb7138455 100644
@@ -117,7 +117,8 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)
 
       desc->handler = gic_hw_ops->gic_host_irq_type;
 
-    gic_set_irq_type(desc, desc->arch.type);
+    if ( desc->irq >= NR_GIC_SGI)
+        gic_set_irq_type(desc, desc->arch.type);

So above, you say that the SGIs are always edge-triggered interrupt. So I assume desc->arch.type. So are you skipping the call because it is unnessary or it could do the wrong thing?

Ideally, the outcome of the answer be part of the comment on top of the check.

Quoted 8 lines
Quoted 6 lines

gic_set_irq_type() has an assert "ASSERT(type != IRQ_TYPE_INVALID)" which is triggered without this check.
So it's both unnecessary and wrong. I suppose we could update the bookkeeping of all SGIs to be edge-triggered instead of IRQ_TYPE_INVALID. It would still be unnecessary though. What do you suggest?

I would rather prefer if we update the book-keeping for all the SGIs.

I'll update the code.

Quoted 48 lines

[...]

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
           {
               isb();
               do_IRQ(regs, irq, is_fiq);
xen/arch/arm/irq.c +0 -0
index bcce80a4d624..fdb214560978 100644
@@ -224,9 +224,12 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
       perfc_incr(irqs);
 
Quoted 8 lines

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 228

Quoted 3 lines
xen/arch/arm/irq.c +2 -1
-    ASSERT(irq >= 16); /* SGIs do not come down this path */
+    /* Statically assigned SGIs do not come down this path */
+    ASSERT(irq >= GIC_SGI_MAX);

With this change, I think the path with vgic_inject_irq() now needs to gain an ASSERT(irq >= NR_GIC_SGI) because the path is not supposed to be taken for SGIs.

Quoted 4 lines

I'm sorry, I don't see the connection. If I add ASSERT(virq >= NR_GIC_SGI);
at the top of vgic_inject_irq() it will panic when injecting a Schedule Receiver or Notification Pending Interrupt for a guest.

If you look at do_IRQ(), we have the following code:

     if ( test_bit(_IRQ_GUEST, &desc->status) )
     {
         struct irq_guest *info = irq_get_guest_info(desc);

         perfc_incr(guest_irqs);
         desc->handler->end(desc);

         set_bit(_IRQ_INPROGRESS, &desc->status);

         /*
          * The irq cannot be a PPI, we only support delivery of SPIs to
          * guests.
          */
         vgic_inject_irq(info->d, NULL, info->virq, true);
         goto out_no_end;
     }
Quoted 3 lines

What I suggesting is to add an ASSERT(irq >= NR_GIC_SGI) just before the call because now do_IRQ() can be called with SGIs yet we don't allow HW SGIs to assigned to a guest.

Got it, thanks for the explanation. I'll add the assert.

Thanks,
Jens

#13 lore raw

PATCH v2 5/5 xen/arm: ffa: support notification

In reply to Jens Wiklander

Add support for FF-A notifications, currently limited to an SP (Secure Partition) sending an asynchronous notification to a guest.

Guests and Xen itself are made aware of pending notifications with an interrupt. The interrupt handler retrieves the notifications using the FF-A ABI and deliver them to their destinations.

Update ffa_partinfo_domain_init() to return error code like ffa_notif_domain_init().

---
v1->v2:
- Addressing review comments
- Change ffa_handle_notification_{bind,unbind,set}() to take struct cpu_user_regs *regs as argument.
- Update ffa_partinfo_domain_init() and ffa_notif_domain_init() to return an error code.
- Fixing a bug in handle_features() for FFA_FEATURE_SCHEDULE_RECV_INTR.

---
 xen/arch/arm/tee/Makefile       |   1 +
 xen/arch/arm/tee/ffa.c          |  55 +++++-
 xen/arch/arm/tee/ffa_notif.c    | 331 ++++++++++++++++++++++++++++++++
 xen/arch/arm/tee/ffa_partinfo.c |   9 +-
 xen/arch/arm/tee/ffa_private.h  |  68 ++++++-
 5 files changed, 457 insertions(+), 7 deletions(-)
 create mode 100644 xen/arch/arm/tee/ffa_notif.c
xen/arch/arm/tee/Makefile +1 -0
index f0112a2f922d..7c0f46f7f446 100644
@@ -2,5 +2,6 @@ obj-$(CONFIG_FFA) += ffa.o
 obj-$(CONFIG_FFA) += ffa_shm.o
 obj-$(CONFIG_FFA) += ffa_partinfo.o
 obj-$(CONFIG_FFA) += ffa_rxtx.o
+obj-$(CONFIG_FFA) += ffa_notif.o
 obj-y += tee.o
 obj-$(CONFIG_OPTEE) += optee.o
xen/arch/arm/tee/ffa.c +52 -3

104 lines not on this page · raw message

xen/arch/arm/tee/ffa_notif.c new file +331 -0

331 lines not on this page · raw message

xen/arch/arm/tee/ffa_partinfo.c +6 -3
index dc1059584828..93a03c6bc672 100644
@@ -306,7 +306,7 @@ static void vm_destroy_bitmap_init(struct ffa_ctx *ctx,
     }
 }
 
-bool ffa_partinfo_domain_init(struct domain *d)
+int ffa_partinfo_domain_init(struct domain *d)
 {
     unsigned int count = BITS_TO_LONGS(subscr_vm_destroyed_count);
     struct ffa_ctx *ctx = d->arch.tee;
@@ -315,7 +315,7 @@ bool ffa_partinfo_domain_init(struct domain *d)
 
     ctx->vm_destroy_bitmap = xzalloc_array(unsigned long, count);
     if ( !ctx->vm_destroy_bitmap )
-        return false;
+        return -ENOMEM;
 
     for ( n = 0; n < subscr_vm_created_count; n++ )
     {
@@ -330,7 +330,10 @@ bool ffa_partinfo_domain_init(struct domain *d)
     }
     vm_destroy_bitmap_init(ctx, n);
 
-    return n == subscr_vm_created_count;
+    if ( n != subscr_vm_created_count )
+        return -EIO;
+
+    return 0;
 }
 
 bool ffa_partinfo_domain_destroy(struct domain *d)
xen/arch/arm/tee/ffa_private.h +67 -1

116 lines not on this page · raw message

Signature · 1 line
2.34.1
#14 lore raw

Re: [XEN PATCH v2 5/5] xen/arm: ffa: support notification

Hi Jens,

This is not a full review of the code. I will let Bertrand doing it.

Quoted 8 lines · Jens Wiklander
xen/arch/arm/tee/ffa_notif.c new file +8 -0
+void ffa_notif_init(void)
+{
+    const struct arm_smccc_1_2_regs arg = {
+        .a0 = FFA_FEATURES,
+        .a1 = FFA_FEATURE_SCHEDULE_RECV_INTR,
+    };
+    struct arm_smccc_1_2_regs resp;
+    unsigned int irq;

xen/arch/arm/tee/ffa_notif.c line 298

Quoted 10 lines
xen/arch/arm/tee/ffa_notif.c new file +10 -0
+    int ret;
+
+    arm_smccc_1_2_smc(&arg, &resp);
+    if ( resp.a0 != FFA_SUCCESS_32 )
+        return;
+
+    irq = resp.a2;
+    if ( irq >= NR_GIC_SGI )
+        irq_set_type(irq, IRQ_TYPE_EDGE_RISING);
+    ret = request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL);

If I am not mistaken, ffa_notif_init() is only called once on the boot CPU. However, request_irq() needs to be called on every CPU so the callback is registered every where and the interrupt enabled.

I know the name of the function is rather confusing. So can you confirm this is what you expected?

[...]

Quoted 13 lines
xen/arch/arm/tee/ffa_private.h +1 -0
index 98236cbf14a3..ef8ffd4526bd 100644
@@ -25,6 +25,7 @@
  #define FFA_RET_DENIED                  -6
  #define FFA_RET_RETRY                   -7
  #define FFA_RET_ABORTED                 -8
+#define FFA_RET_NO_DATA                 -9
 
  /* FFA_VERSION helpers */
  #define FFA_VERSION_MAJOR_SHIFT         16U

xen/arch/arm/tee/ffa_private.h line 103

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +3 -0
@@ -97,6 +98,18 @@
   */
  #define FFA_MAX_SHM_COUNT               32
 
+/*
+ * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely
+ * unused, but that may change.

Are the value below intended for the guests? If so, can they be moved in public/arch-arm.h along with the others guest interrupts?

xen/arch/arm/tee/ffa_private.h line 108

Quoted 5 lines
xen/arch/arm/tee/ffa_private.h +5 -0
+ *
+ * SGI is the preferred delivery mechanism. SGIs 8-15 are normally not used
+ * by a guest as they in a non-virtualized system typically are assigned to
+ * the secure world. Here we're free to use SGI 8-15 since they are virtual
+ * and have nothing to do with the secure world.

Do you have a pointer to the specification?

[...]

Cheers,

Signature · 1 line
Julien Grall
#15 lore raw

Re: [XEN PATCH v2 5/5] xen/arm: ffa: support notification

Hi Julien,

Quoted 43 lines · Julien Grall

Hi Jens,

This is not a full review of the code. I will let Bertrand doing it.

Quoted 8 lines · Jens Wiklander
xen/arch/arm/tee/ffa_notif.c new file +8 -0
+void ffa_notif_init(void)
+{
+    const struct arm_smccc_1_2_regs arg = {
+        .a0 = FFA_FEATURES,
+        .a1 = FFA_FEATURE_SCHEDULE_RECV_INTR,
+    };
+    struct arm_smccc_1_2_regs resp;
+    unsigned int irq;

xen/arch/arm/tee/ffa_notif.c line 298

Quoted 10 lines
xen/arch/arm/tee/ffa_notif.c new file +10 -0
+    int ret;
+
+    arm_smccc_1_2_smc(&arg, &resp);
+    if ( resp.a0 != FFA_SUCCESS_32 )
+        return;
+
+    irq = resp.a2;
+    if ( irq >= NR_GIC_SGI )
+        irq_set_type(irq, IRQ_TYPE_EDGE_RISING);
+    ret = request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL);

If I am not mistaken, ffa_notif_init() is only called once on the boot CPU. However, request_irq() needs to be called on every CPU so the callback is registered every where and the interrupt enabled.

I know the name of the function is rather confusing. So can you confirm this is what you expected?

[...]

Quoted 11 lines
xen/arch/arm/tee/ffa_private.h +1 -0
index 98236cbf14a3..ef8ffd4526bd 100644
@@ -25,6 +25,7 @@
 #define FFA_RET_DENIED                  -6
 #define FFA_RET_RETRY                   -7
 #define FFA_RET_ABORTED                 -8
+#define FFA_RET_NO_DATA                 -9
   /* FFA_VERSION helpers */
 #define FFA_VERSION_MAJOR_SHIFT         16U
Quoted 8 lines

xen/arch/arm/tee/ffa_private.h line 102

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +2 -0
@@ -97,6 +98,18 @@
  */
 #define FFA_MAX_SHM_COUNT               32
 +/*
+ * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely
+ * unused, but that may change.

Are the value below intended for the guests? If so, can they be moved in public/arch-arm.h along with the others guest interrupts?

The values are to be used by the guest but they will discover them through the FFA_FEATURES ABI so I do not think those should belong the public headers.

Cheers
Bertrand

Quoted 15 lines

xen/arch/arm/tee/ffa_private.h line 108

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +5 -0
+ *
+ * SGI is the preferred delivery mechanism. SGIs 8-15 are normally not used
+ * by a guest as they in a non-virtualized system typically are assigned to
+ * the secure world. Here we're free to use SGI 8-15 since they are virtual
+ * and have nothing to do with the secure world.

Do you have a pointer to the specification?

[...]

Cheers,

Signature · 1 line
Julien Grall
#16 lore raw

Re: [XEN PATCH v2 5/5] xen/arm: ffa: support notification

Hi Bertrand,

Quoted 54 lines · Bertrand Marquis

Hi Julien,

Quoted 43 lines · Julien Grall

Hi Jens,

This is not a full review of the code. I will let Bertrand doing it.

Quoted 8 lines · Jens Wiklander
xen/arch/arm/tee/ffa_notif.c new file +8 -0
+void ffa_notif_init(void)
+{
+    const struct arm_smccc_1_2_regs arg = {
+        .a0 = FFA_FEATURES,
+        .a1 = FFA_FEATURE_SCHEDULE_RECV_INTR,
+    };
+    struct arm_smccc_1_2_regs resp;
+    unsigned int irq;

xen/arch/arm/tee/ffa_notif.c line 298

Quoted 10 lines
xen/arch/arm/tee/ffa_notif.c new file +10 -0
+    int ret;
+
+    arm_smccc_1_2_smc(&arg, &resp);
+    if ( resp.a0 != FFA_SUCCESS_32 )
+        return;
+
+    irq = resp.a2;
+    if ( irq >= NR_GIC_SGI )
+        irq_set_type(irq, IRQ_TYPE_EDGE_RISING);
+    ret = request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL);

If I am not mistaken, ffa_notif_init() is only called once on the boot CPU. However, request_irq() needs to be called on every CPU so the callback is registered every where and the interrupt enabled.

I know the name of the function is rather confusing. So can you confirm this is what you expected?

[...]

Quoted 11 lines
xen/arch/arm/tee/ffa_private.h +1 -0
index 98236cbf14a3..ef8ffd4526bd 100644
@@ -25,6 +25,7 @@
  #define FFA_RET_DENIED                  -6
  #define FFA_RET_RETRY                   -7
  #define FFA_RET_ABORTED                 -8
+#define FFA_RET_NO_DATA                 -9
    /* FFA_VERSION helpers */
  #define FFA_VERSION_MAJOR_SHIFT         16U
Quoted 8 lines

xen/arch/arm/tee/ffa_private.h line 102

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +2 -0
@@ -97,6 +98,18 @@
   */
  #define FFA_MAX_SHM_COUNT               32
  +/*
+ * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely
+ * unused, but that may change.

Are the value below intended for the guests? If so, can they be moved in public/arch-arm.h along with the others guest interrupts?

Quoted 2 lines

The values are to be used by the guest but they will discover them through the FFA_FEATURES ABI so I do not think those should belong the public headers.

Sorry I should have been clearer. The values in the public headers are not meant for the guest. They are meant for a common understanding between the toolstack and Xen of the guest layout (memory + interrupts).

I know that some of the guests started to rely on it. But this is against our policy:

* These are defined for consistency between the tools and the
* hypervisor. Guests must not rely on these hardcoded values but
* should instead use the FDT.

In this case, even if this is only used by Xen (today), I would argue they should defined at the same place because it is easier to understand the layout if it is in one place.

Cheers,

Signature · 1 line
Julien Grall
#17 lore raw

Re: [XEN PATCH v2 5/5] xen/arm: ffa: support notification

Hi Julien,

Quoted 62 lines · Julien Grall

Hi Bertrand,

Quoted 52 lines · Bertrand Marquis

Hi Julien,

Quoted 43 lines · Julien Grall

Hi Jens,

This is not a full review of the code. I will let Bertrand doing it.

Quoted 8 lines · Jens Wiklander
xen/arch/arm/tee/ffa_notif.c new file +8 -0
+void ffa_notif_init(void)
+{
+    const struct arm_smccc_1_2_regs arg = {
+        .a0 = FFA_FEATURES,
+        .a1 = FFA_FEATURE_SCHEDULE_RECV_INTR,
+    };
+    struct arm_smccc_1_2_regs resp;
+    unsigned int irq;

xen/arch/arm/tee/ffa_notif.c line 298

Quoted 10 lines
xen/arch/arm/tee/ffa_notif.c new file +10 -0
+    int ret;
+
+    arm_smccc_1_2_smc(&arg, &resp);
+    if ( resp.a0 != FFA_SUCCESS_32 )
+        return;
+
+    irq = resp.a2;
+    if ( irq >= NR_GIC_SGI )
+        irq_set_type(irq, IRQ_TYPE_EDGE_RISING);
+    ret = request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL);

If I am not mistaken, ffa_notif_init() is only called once on the boot CPU. However, request_irq() needs to be called on every CPU so the callback is registered every where and the interrupt enabled.

I know the name of the function is rather confusing. So can you confirm this is what you expected?

[...]

Quoted 11 lines
xen/arch/arm/tee/ffa_private.h +1 -0
index 98236cbf14a3..ef8ffd4526bd 100644
@@ -25,6 +25,7 @@
 #define FFA_RET_DENIED                  -6
 #define FFA_RET_RETRY                   -7
 #define FFA_RET_ABORTED                 -8
+#define FFA_RET_NO_DATA                 -9
   /* FFA_VERSION helpers */
 #define FFA_VERSION_MAJOR_SHIFT         16U
Quoted 8 lines

xen/arch/arm/tee/ffa_private.h line 102

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +2 -0
@@ -97,6 +98,18 @@
  */
 #define FFA_MAX_SHM_COUNT               32
 +/*
+ * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely
+ * unused, but that may change.

Are the value below intended for the guests? If so, can they be moved in public/arch-arm.h along with the others guest interrupts?

Quoted 2 lines

The values are to be used by the guest but they will discover them through the FFA_FEATURES ABI so I do not think those should belong the public headers.

Sorry I should have been clearer. The values in the public headers are not meant for the guest. They are meant for a common understanding between the toolstack and Xen of the guest layout (memory + interrupts).

Quoted 7 lines

I know that some of the guests started to rely on it. But this is against our policy:

* These are defined for consistency between the tools and the
* hypervisor. Guests must not rely on these hardcoded values but
* should instead use the FDT.

In this case, even if this is only used by Xen (today), I would argue they should defined at the same place because it is easier to understand the layout if it is in one place.

I see, that makes sense then to add them there.

Cheers
Bertrand

Quoted 5 lines

Cheers,

Signature · 1 line
Julien Grall
#18 lore raw

Re: [XEN PATCH v2 5/5] xen/arm: ffa: support notification

In reply to Julien Grall

Hi Julien,

Quoted 29 lines · Julien Grall

Hi Jens,

This is not a full review of the code. I will let Bertrand doing it.

Quoted 8 lines · Jens Wiklander
xen/arch/arm/tee/ffa_notif.c new file +8 -0
+void ffa_notif_init(void)
+{
+    const struct arm_smccc_1_2_regs arg = {
+        .a0 = FFA_FEATURES,
+        .a1 = FFA_FEATURE_SCHEDULE_RECV_INTR,
+    };
+    struct arm_smccc_1_2_regs resp;
+    unsigned int irq;

xen/arch/arm/tee/ffa_notif.c line 298

Quoted 10 lines
xen/arch/arm/tee/ffa_notif.c new file +10 -0
+    int ret;
+
+    arm_smccc_1_2_smc(&arg, &resp);
+    if ( resp.a0 != FFA_SUCCESS_32 )
+        return;
+
+    irq = resp.a2;
+    if ( irq >= NR_GIC_SGI )
+        irq_set_type(irq, IRQ_TYPE_EDGE_RISING);
+    ret = request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL);

If I am not mistaken, ffa_notif_init() is only called once on the boot CPU. However, request_irq() needs to be called on every CPU so the callback is registered every where and the interrupt enabled.

Quoted 2 lines

I know the name of the function is rather confusing. So can you confirm this is what you expected?

Good catch, no this wasn't what I expected. I'll need to change this.

Quoted 19 lines

[...]

Quoted 16 lines
xen/arch/arm/tee/ffa_private.h +1 -0
index 98236cbf14a3..ef8ffd4526bd 100644
@@ -25,6 +25,7 @@
  #define FFA_RET_DENIED                  -6
  #define FFA_RET_RETRY                   -7
  #define FFA_RET_ABORTED                 -8
+#define FFA_RET_NO_DATA                 -9
 
  /* FFA_VERSION helpers */
  #define FFA_VERSION_MAJOR_SHIFT         16U
@@ -97,6 +98,18 @@
   */
  #define FFA_MAX_SHM_COUNT               32
 
Quoted 6 lines

xen/arch/arm/tee/ffa_private.h line 103

Quoted 3 lines
xen/arch/arm/tee/ffa_private.h +3 -0
+/*
+ * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely
+ * unused, but that may change.

Are the value below intended for the guests? If so, can they be moved in public/arch-arm.h along with the others guest interrupts?

Yes, I'll move it.

Quoted 8 lines

xen/arch/arm/tee/ffa_private.h line 108

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +5 -0
+ *
+ * SGI is the preferred delivery mechanism. SGIs 8-15 are normally not used
+ * by a guest as they in a non-virtualized system typically are assigned to
+ * the secure world. Here we're free to use SGI 8-15 since they are virtual
+ * and have nothing to do with the secure world.

Do you have a pointer to the specification?

There's one at the top of arch/arm/tee/ffa.c,
https://developer.arm.com/documentation/den0077/e
Do you want the link close to the defines when I've moved them to public/arch-arm.h?
Or is it perhaps better to give a link to "Arm Base System Architecture v1.0C", https://developer.arm.com/documentation/den0094/
instead?

Thanks,
Jens

#19 lore raw

Re: [XEN PATCH v2 5/5] xen/arm: ffa: support notification

Hi Jens,

Quoted 76 lines · Jens Wiklander

Hi Julien,

Quoted 29 lines · Julien Grall

Hi Jens,

This is not a full review of the code. I will let Bertrand doing it.

Quoted 8 lines · Jens Wiklander
xen/arch/arm/tee/ffa_notif.c new file +8 -0
+void ffa_notif_init(void)
+{
+    const struct arm_smccc_1_2_regs arg = {
+        .a0 = FFA_FEATURES,
+        .a1 = FFA_FEATURE_SCHEDULE_RECV_INTR,
+    };
+    struct arm_smccc_1_2_regs resp;
+    unsigned int irq;

xen/arch/arm/tee/ffa_notif.c line 298

Quoted 10 lines
xen/arch/arm/tee/ffa_notif.c new file +10 -0
+    int ret;
+
+    arm_smccc_1_2_smc(&arg, &resp);
+    if ( resp.a0 != FFA_SUCCESS_32 )
+        return;
+
+    irq = resp.a2;
+    if ( irq >= NR_GIC_SGI )
+        irq_set_type(irq, IRQ_TYPE_EDGE_RISING);
+    ret = request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL);

If I am not mistaken, ffa_notif_init() is only called once on the boot CPU. However, request_irq() needs to be called on every CPU so the callback is registered every where and the interrupt enabled.

Quoted 2 lines

I know the name of the function is rather confusing. So can you confirm this is what you expected?

Good catch, no this wasn't what I expected. I'll need to change this.

Quoted 19 lines

[...]

Quoted 16 lines
xen/arch/arm/tee/ffa_private.h +1 -0
index 98236cbf14a3..ef8ffd4526bd 100644
@@ -25,6 +25,7 @@
 #define FFA_RET_DENIED                  -6
 #define FFA_RET_RETRY                   -7
 #define FFA_RET_ABORTED                 -8
+#define FFA_RET_NO_DATA                 -9
 
 /* FFA_VERSION helpers */
 #define FFA_VERSION_MAJOR_SHIFT         16U
@@ -97,6 +98,18 @@
  */
 #define FFA_MAX_SHM_COUNT               32
 
Quoted 6 lines

xen/arch/arm/tee/ffa_private.h line 103

Quoted 3 lines
xen/arch/arm/tee/ffa_private.h +3 -0
+/*
+ * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely
+ * unused, but that may change.

Are the value below intended for the guests? If so, can they be moved in public/arch-arm.h along with the others guest interrupts?

Yes, I'll move it.

Quoted 8 lines

xen/arch/arm/tee/ffa_private.h line 108

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +5 -0
+ *
+ * SGI is the preferred delivery mechanism. SGIs 8-15 are normally not used
+ * by a guest as they in a non-virtualized system typically are assigned to
+ * the secure world. Here we're free to use SGI 8-15 since they are virtual
+ * and have nothing to do with the secure world.

Do you have a pointer to the specification?

Quoted 7 lines

There's one at the top of arch/arm/tee/ffa.c,
https://developer.arm.com/documentation/den0077/e
Do you want the link close to the defines when I've moved them to public/arch-arm.h?
Or is it perhaps better to give a link to "Arm Base System Architecture v1.0C", https://developer.arm.com/documentation/den0094/
instead?

I would say we need the link to Arm Base System Architecture in arch-arm.

Regards
Bertrand

Quoted 3 lines

Thanks,
Jens

#20 lore raw

Re: [XEN PATCH v2 5/5] xen/arm: ffa: support notification

Hi Bertrand & Jens,

Quoted 86 lines · Bertrand Marquis

Hi Jens,

Quoted 76 lines · Jens Wiklander

Hi Julien,

Quoted 29 lines · Julien Grall

Hi Jens,

This is not a full review of the code. I will let Bertrand doing it.

Quoted 8 lines · Jens Wiklander
xen/arch/arm/tee/ffa_notif.c new file +8 -0
+void ffa_notif_init(void)
+{
+    const struct arm_smccc_1_2_regs arg = {
+        .a0 = FFA_FEATURES,
+        .a1 = FFA_FEATURE_SCHEDULE_RECV_INTR,
+    };
+    struct arm_smccc_1_2_regs resp;
+    unsigned int irq;

xen/arch/arm/tee/ffa_notif.c line 298

Quoted 10 lines
xen/arch/arm/tee/ffa_notif.c new file +10 -0
+    int ret;
+
+    arm_smccc_1_2_smc(&arg, &resp);
+    if ( resp.a0 != FFA_SUCCESS_32 )
+        return;
+
+    irq = resp.a2;
+    if ( irq >= NR_GIC_SGI )
+        irq_set_type(irq, IRQ_TYPE_EDGE_RISING);
+    ret = request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL);

If I am not mistaken, ffa_notif_init() is only called once on the boot CPU. However, request_irq() needs to be called on every CPU so the callback is registered every where and the interrupt enabled.

Quoted 2 lines

I know the name of the function is rather confusing. So can you confirm this is what you expected?

Good catch, no this wasn't what I expected. I'll need to change this.

Quoted 19 lines

[...]

Quoted 16 lines
xen/arch/arm/tee/ffa_private.h +1 -0
index 98236cbf14a3..ef8ffd4526bd 100644
@@ -25,6 +25,7 @@
  #define FFA_RET_DENIED                  -6
  #define FFA_RET_RETRY                   -7
  #define FFA_RET_ABORTED                 -8
+#define FFA_RET_NO_DATA                 -9
 
  /* FFA_VERSION helpers */
  #define FFA_VERSION_MAJOR_SHIFT         16U
@@ -97,6 +98,18 @@
   */
  #define FFA_MAX_SHM_COUNT               32
 
Quoted 6 lines

xen/arch/arm/tee/ffa_private.h line 103

Quoted 3 lines
xen/arch/arm/tee/ffa_private.h +3 -0
+/*
+ * TODO How to manage the available SGIs? SGI 8-15 seem to be entirely
+ * unused, but that may change.

Are the value below intended for the guests? If so, can they be moved in public/arch-arm.h along with the others guest interrupts?

Yes, I'll move it.

Quoted 8 lines

xen/arch/arm/tee/ffa_private.h line 108

Quoted 6 lines
xen/arch/arm/tee/ffa_private.h +5 -0
+ *
+ * SGI is the preferred delivery mechanism. SGIs 8-15 are normally not used
+ * by a guest as they in a non-virtualized system typically are assigned to
+ * the secure world. Here we're free to use SGI 8-15 since they are virtual
+ * and have nothing to do with the secure world.

Do you have a pointer to the specification?

Quoted 7 lines

There's one at the top of arch/arm/tee/ffa.c,
https://developer.arm.com/documentation/den0077/e
Do you want the link close to the defines when I've moved them to public/arch-arm.h?
Or is it perhaps better to give a link to "Arm Base System Architecture v1.0C", https://developer.arm.com/documentation/den0094/
instead?

Quoted 1 line

I would say we need the link to Arm Base System Architecture in arch-arm.

+1

Cheers,

Signature · 1 line
Julien Grall