Hi Sandeep,
Here are a few more details.
The reasoning differs when considering pre-Armv8.4 platforms (1) vs Armv8.4 platforms onwards with secure virtualization enabled (2).
Case (1):
EHF framework unifies EL3 exceptions delivered via different vectors and allows them to be handled in a common way. It is also allowing exception delegation handling to lower secure ELs. This framework although primarily used for RAS, is also used for SDEI and platform EL3 interrupts. EL3's role in this case is about trapping and routing the event to appropriate the component (when the interrupt/exception is not handled solely at EL3).
The interoperability between EHF and a Trusted OS is not accurately defined apart from this guidance in EHF documentation:
"In order for S-EL1 software to handle Non-secure interrupts while having EHF enabled, the dispatcher must adopt a model where Non-secure interrupts are received at EL3, but are then synchronously handled over to S-EL1."
Until then for the specific RAS handling scenario, this was delegated to a StandaloneMM partition running at S-EL0 (through the SPM-MM implementation) and not necessarily delegated to a TOS.
In order to better help you, we would need more information on the scenario you intend to achieve, and the environment (Arm architecture version and extensions, GIC version).
Or maybe your question was out of curiosity for the longer term approach (2) as described below?
Case (2):
As a general rule, it is preferred that EL3 reduces its footprint and minimises platform specific handling code.
EHF framework would most probably not be enabled at all.
The priority logic provided by the GIC PMR register to mask NS interrupts cannot really work as before because all of trusted EL3/S-EL2 and untrusted S-EL1 SPs can manipulate this register.
Any secure/non-secure interrupt triggered while running SEL1/SEL0 is trapped first by the S-EL2 firmware (or the so-called SPMC). This translates into SCR_EL3.FIQ/IRQ=0 in the secure world.
Group1NS interrupts are redirected to SPMD for routing to NWd.
A Group0 interrupt is possibly redirected to a platform driver into an S-EL1 secure partition (e.g. a RAS handling service).
Hence it does no longer hold true that Group0 interrupts are necessarily qualified as "EL3 interrupts".
It is still possible to redirect Group0 interrupts from S-EL2 to EL3 and be handled there, but as said, this is a less preferred approach.
Either way when NWd runs (with SCR_EL3.FIQ=1/IRQ=0), a Group1S/Group0 secure interrupt is trapped at EL3 and routed to SPMD then SPMC.
The SPMC can take the decision to resume the secure partition which registered the corresponding secure INTID.
This design does mean that SDEI interrupt handling would need SPMC and BL31 collaboration and this is something we are working on.
Hope this helps.
Regards,
Olivier.
________________________________________
From: TF-A <tf-a-bounces(a)lists.trustedfirmware.org> on behalf of Olivier Deprez via TF-A <tf-a(a)lists.trustedfirmware.org>
Sent: 28 September 2020 14:01
To: Sandeep Tripathy; Soby Mathew
Cc: tf-a(a)lists.trustedfirmware.org; nd
Subject: Re: [TF-A] Query SPD/SPMD behavior with EHF
Hi Sandeep,
Your question is very valid and we're discussing options internally.
We will come back to you with a consolidated answer shortly.
Regards,
Olivier.
________________________________________
From: Sandeep Tripathy
Sent: Monday, September 28, 2020 05:28
To: Soby Mathew
Cc: Dan Handley; tf-a(a)lists.trustedfirmware.org; nd; Olivier Deprez
Subject: Re: [TF-A] Query SPD/SPMD behavior with EHF
Thanks Soby and Dan for confirmation on TSPD. I can see a few more gaps
in the related area.
"The EL3 interrupts (G0 interrupts) should be able to pre-empt Fast
SMC i.e. any execution context for that matter ".
This should apply to all SPDs including SPMD. However I learned from
@Oliver that SPMD/SPMC design traps FIQs to S_EL2.
In that case a RAS interrupt can be masked by S_EL2 software (eg:
Hafnium). Probably by design it will be ensured that S_EL2 will never
mask the physical FIQ ?
S_EL2 FIQ handler will exit to EL3/SPMD by SMC call. And depending on
the pending interrupt type either it can exit to NWd OR invoke el3 fiq
vector handler synchronously ?
Are there limitations if we trap fiq to EL3 instead ?
Thanks
Sandeep
On Fri, Sep 18, 2020 at 6:26 PM Soby Mathew <Soby.Mathew(a)arm.com> wrote:
>
> Hi Sandeep
>
> > Except during yielding SMC ‘disable_intr_rm_local(INTR_TYPE_NS, SECUE);’ is in effect. Intention is to avoid NS interrupt preempt secure execution (Fast SMC).
> > But I think that will also disable G0 interrupt as both NS interrupt and G0 interrupt are on FIQ.
> > EHF already ensures this by GIC PMR adjustment. So disabling routing model seems unnecessary in this case.
> > This is my understanding from the code please confirm if this is correct.
>
> The EL3 interrupts (G0 interrupts) should be able to pre-empt Fast SMC. Hence the usage of GIC PMR to mask the NS interrupts. As Dan says, the TSP_NS_INTR_ASYNC_PREEMPT predates the EHF design and it seems there is a problem as you describe.
>
> > EHF already ensures this by GIC PMR adjustment. So disabling routing model seems unnecessary in this case.
> > This is my understanding from the code please confirm if this is correct.
>
> You are right. Routing model manipulation is not required when EL3 interrupts are present as GIC PMR manipulation should take care of the required behaviour for yielding vs atomic SMC. You also need to ensure it works as expected when EL3 interrupts are not enabled and when EHF is disabled.
>
> Best Regards
> Soby Mathew
>
> > -----Original Message-----
> > From: TF-A <tf-a-bounces(a)lists.trustedfirmware.org> On Behalf Of Sandeep
> > Tripathy via TF-A
> > Sent: 17 September 2020 16:53
> > To: Dan Handley <Dan.Handley(a)arm.com>
> > Cc: tf-a(a)lists.trustedfirmware.org
> > Subject: Re: [TF-A] Query TSPD behavior with EHF
> >
> > Hi Dan,
> > I am not sure if this is mentioned anywhere in any documents but I think
> > EHF handlers should be able to preempt all execution contexts at lower ELs
> > and lower ELs should never be able to mask such interrupts.
> > If the behavioral expectation is set the implementation can be fixed.
> >
> > Thanks
> > Sandeep
> >
> > On Thu, Sep 17, 2020 at 7:57 PM Dan Handley via TF-A <tf-
> > a(a)lists.trustedfirmware.org> wrote:
> > >
> > > A correction...
> > >
> > > > -----Original Message-----
> > > > From: TF-A <tf-a-bounces(a)lists.trustedfirmware.org> On Behalf Of Dan
> > > > Handley via TF-A
> > > > Sent: 17 September 2020 15:14
> > > > > >
> > > > > > I want to handle something similar in OP-TEED along with EHF
> > > > > > depending on
> > > > > what is the expected behavior.
> > > > > >
> > > > Hmm, I thought OP-TEED was more like the
> > TSP_NS_INTR_ASYNC_PREEMPT=0
> > > > case, where NS interrupts are routed to S-EL1 while processing a
> > > > yielding SMC in S- EL1? Perhaps that's a better TSPD config for you to
> > follow?
> > > >
> > > Sorry, if EL3_EXCEPTION_HANDLING=1 then obviously NS interrupts are
> > routed to EL3 first, but the TSPD re-enables NS interrupts before handing
> > over to the TSP to handle yielding calls, via a call to
> > ehf_allow_ns_preemption.
> > >
> >
> > Right, that is the case for yielding SMC handling where both NS interrupts
> > and EL3/G0 interrupts can preempt the S_EL1/S_EL2 context.
> > But I would expect the same routing model even for 'Fast SMC' unlike what is
> > happening in TSPD.
> >
> > > Dan.
> > >
> > > --
> > > TF-A mailing list
> > > TF-A(a)lists.trustedfirmware.org
> > > https://lists.trustedfirmware.org/mailman/listinfo/tf-a
> > --
> > TF-A mailing list
> > TF-A(a)lists.trustedfirmware.org
> > https://lists.trustedfirmware.org/mailman/listinfo/tf-a
--
TF-A mailing list
TF-A(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-a
Hi,
Please find the latest report on new defect(s) introduced to ARM-software/arm-trusted-firmware found with Coverity Scan.
3 new defect(s) introduced to ARM-software/arm-trusted-firmware found with Coverity Scan.
1 defect(s), reported by Coverity Scan earlier, were marked fixed in the recent build analyzed by Coverity Scan.
New defect(s) Reported-by: Coverity Scan
Showing 3 of 3 defect(s)
** CID 362943: Insecure data handling (TAINTED_SCALAR)
________________________________________________________________________________________________________
*** CID 362943: Insecure data handling (TAINTED_SCALAR)
/common/fdt_fixup.c: 437 in fdt_adjust_gic_redist()
431
432 /*
433 * The redistributor is described in the second "reg" entry.
434 * So we have to skip one address and one size cell, then another
435 * address cell to get to the second size cell.
436 */
>>> CID 362943: Insecure data handling (TAINTED_SCALAR)
>>> Passing tainted variable "sc * 4" to a tainted sink.
437 return fdt_setprop_inplace_namelen_partial(dtb, offset, "reg", 3,
438 (ac + sc + ac) * 4,
439 val, sc * 4);
** CID 362942: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
/common/fdt_fixup.c: 428 in fdt_adjust_gic_redist()
________________________________________________________________________________________________________
*** CID 362942: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
/common/fdt_fixup.c: 428 in fdt_adjust_gic_redist()
422 }
423
424 if (sc == 1) {
425 redist_size_32 = cpu_to_fdt32(nr_cores * gicr_frame_size);
426 val = &redist_size_32;
427 } else {
>>> CID 362942: Integer handling issues (OVERFLOW_BEFORE_WIDEN)
>>> Potentially overflowing expression "nr_cores * gicr_frame_size" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned).
428 redist_size_64 = cpu_to_fdt64(nr_cores * gicr_frame_size);
429 val = &redist_size_64;
430 }
431
432 /*
433 * The redistributor is described in the second "reg" entry.
** CID 362941: Integer handling issues (BAD_SHIFT)
/mbedtls/library/bignum.c: 1713 in mbedtls_int_div_int()
________________________________________________________________________________________________________
*** CID 362941: Integer handling issues (BAD_SHIFT)
/mbedtls/library/bignum.c: 1713 in mbedtls_int_div_int()
1707 * Normalize the divisor, d, and dividend, u0, u1
1708 */
1709 s = mbedtls_clz( d );
1710 d = d << s;
1711
1712 u1 = u1 << s;
>>> CID 362941: Integer handling issues (BAD_SHIFT)
>>> In expression "u0 >> 64UL - s", right shifting by more than 63 bits has undefined behavior. The shift amount, "64UL - s", is 64.
1713 u1 |= ( u0 >> ( biL - s ) ) & ( -(mbedtls_mpi_sint)s >> ( biL - 1 ) );
1714 u0 = u0 << s;
1715
1716 d1 = d >> biH;
1717 d0 = d & uint_halfword_mask;
1718
________________________________________________________________________________________________________
To view the defects in Coverity Scan visit, https://u15810271.ct.sendgrid.net/ls/click?upn=HRESupC-2F2Czv4BOaCWWCy7my0P…