From: "Sunil V L" <sunilvl@ventanamicro.com>
To: Michael Brown <mcb30@ipxe.org>
Cc: devel@edk2.groups.io, Eric Dong <eric.dong@intel.com>,
Ray Ni <ray.ni@intel.com>, Rahul Kumar <rahul1.kumar@intel.com>,
Daniel Schaefer <git@danielschaefer.me>,
Gerd Hoffmann <kraxel@redhat.com>,
Abner Chang <abner.chang@amd.com>
Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 05/20] UefiCpuPkg: Add CpuTimerDxe module
Date: Thu, 9 Feb 2023 15:58:00 +0530 [thread overview]
Message-ID: <Y+TKsLcG1hgWnV1x@sunil-laptop> (raw)
In-Reply-To: <0102018635ae8953-b7e0dd96-6282-4365-a8da-f3696a61a20c-000000@eu-west-1.amazonses.com>
On Thu, Feb 09, 2023 at 10:17:56AM +0000, Michael Brown wrote:
> > +/**
> > + Timer Interrupt Handler.
> > +
> > + @param InterruptType The type of interrupt that occured
> > + @param SystemContext A pointer to the system context when the interrupt occured
> > +**/
> > +VOID
> > +EFIAPI
> > +TimerInterruptHandler (
> > + IN EFI_EXCEPTION_TYPE InterruptType,
> > + IN EFI_SYSTEM_CONTEXT SystemContext
> > + )
> > +{
> > + EFI_TPL OriginalTPL;
> > + UINT64 RiscvTimer;
> > +
> > + OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
> > + if (mTimerNotifyFunction != NULL) {
> > + mTimerNotifyFunction (mTimerPeriod);
> > + }
> > +
> > + RiscVDisableTimerInterrupt (); // Disable SMode timer int
> > + RiscVClearPendingTimerInterrupt ();
> > + if (mTimerPeriod == 0) {
> > + gBS->RestoreTPL (OriginalTPL);
> > + RiscVDisableTimerInterrupt (); // Disable SMode timer int
> > + return;
> > + }
> > +
> > + RiscvTimer = RiscVReadTimer ();
> > + SbiSetTimer (RiscvTimer += mTimerPeriod);
> > + gBS->RestoreTPL (OriginalTPL);
> > + RiscVEnableTimerInterrupt (); // enable SMode timer int
> > +}
>
> This design looks as though it does not support nested timer interrupts.
> The call to RestoreTPL() may invoke callbacks that may themselves include
> delay loops that wait upon further timer interrupts. With the above code,
> those timer interrupts will never arrive since the timer interrupt is
> disabled at the point that you call RestoreTPL().
>
> This will break device drivers such as those for USB network devices that
> rely on nested timer interrupts.
>
>
Hi Michael!,
Thanks a lot for this feedback and background. We are aware of few issues
in this module. Currently, it is mostly porting what exists today in
edk2-platforms repo. We want to add all these additional fixes after
this basic thing is merged. That way we will have git history instead of
combining all fixes single commit. Andrei has a patch ready and waiting
for this to get merged. We can either combine this with his patch or
create one more.
Would that strategy be fine with you?
Thanks!
Sunil
> The easiest fix is to use NestedTimerInterruptLib and change the code as
> follows:
>
> Add at the start of the function:
>
> STATIC NESTED_INTERRUPT_STATE NestedInterruptState;
>
> Change:
>
> OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
>
> to
>
> OriginalTPL = NestedInterruptRaiseTPL ();
>
> Change:
>
> gBS->RestoreTPL (OriginalTPL);
> RiscVEnableTimerInterrupt (); // enable SMode timer int
>
> to
>
> RiscVEnableTimerInterrupt (); // enable SMode timer int
> NestedInterruptRestoreTPL (OriginalTpl, SystemContext,
> &NestedInterruptState);
>
> Note that the timer interrupt is then correctly re-enabled before the call
> to NestedInterruptRestoreTPL(). NestedInterruptTplLib takes care of the
> mess required behind the scenes to make this all provably safe.
>
>
> You'll also need to extend Library/NestedInterruptTplLib/Iret.c to support
> MDE_CPU_RISCV64: it should be fairly obvious what's needed there.
>
>
> See commit https://github.com/tianocore/edk2/commit/a086f4a63b for the
> equivalent fix being applied to OVMF.
>
>
> You can find the background leading up to the creation of
> NestedInterruptTplLib at:
>
> https://bugzilla.tianocore.org/show_bug.cgi?id=4162
> https://github.com/tianocore/edk2/commit/9bf473da4c
> https://github.com/tianocore/edk2/commit/a24fbd6061
> https://github.com/tianocore/edk2/commit/a086f4a63b
>
> Thanks,
>
> Michael
>
next prev parent reply other threads:[~2023-02-09 10:28 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-28 19:17 [edk2-staging/RiscV64QemuVirt PATCH V7 00/20] Add support for RISC-V virt machine Sunil V L
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 01/20] MdePkg/Register: Add register definition header files for RISC-V Sunil V L
2023-02-06 15:44 ` [edk2-devel] " Andrei Warkentin
2023-02-09 1:44 ` Michael D Kinney
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 02/20] MdePkg/BaseLib: RISC-V: Add few more helper functions Sunil V L
2023-02-06 15:46 ` [edk2-devel] " Andrei Warkentin
2023-02-09 1:43 ` Michael D Kinney
2023-02-09 7:21 ` Sunil V L
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 03/20] MdePkg: Add BaseRiscVSbiLib Library for RISC-V Sunil V L
2023-02-06 15:47 ` [edk2-devel] " Andrei Warkentin
2023-02-09 1:45 ` Michael D Kinney
2023-02-09 7:18 ` [edk2-devel] " Sunil V L
2023-02-09 15:47 ` Michael D Kinney
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 04/20] UefiCpuPkg: Add RISCV_EFI_BOOT_PROTOCOL related definitions Sunil V L
2023-02-06 15:47 ` [edk2-devel] " Andrei Warkentin
2023-02-09 5:16 ` Ni, Ray
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 05/20] UefiCpuPkg: Add CpuTimerDxe module Sunil V L
2023-02-08 18:02 ` [edk2-devel] " Michael D Kinney
2023-02-08 18:12 ` Sunil V L
2023-02-09 5:21 ` Ni, Ray
2023-02-09 10:17 ` Michael Brown
2023-02-09 10:28 ` Sunil V L [this message]
2023-02-09 10:30 ` Michael Brown
2023-02-09 10:37 ` Sunil V L
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 06/20] UefiCpuPkg/CpuExceptionHandlerLib: Add RISC-V instance Sunil V L
2023-02-09 5:24 ` [edk2-devel] " Ni, Ray
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 07/20] UefiCpuPkg/CpuDxe: " Sunil V L
2023-02-06 15:58 ` [edk2-devel] " Andrei Warkentin
2023-02-08 5:05 ` Sunil V L
2023-02-09 5:43 ` Ni, Ray
2023-02-09 5:49 ` Sunil V L
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 08/20] UefiCpuPkg/CpuTimerLib: " Sunil V L
2023-01-30 11:07 ` [edk2-devel] " dhaval
2023-01-30 13:08 ` Sunil V L
2023-02-06 16:00 ` Andrei Warkentin
2023-02-09 5:37 ` Ni, Ray
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 09/20] UefiCpuPkg/UefiCpuPkg.ci.yaml: Ignore RISC-V file Sunil V L
2023-02-06 16:00 ` [edk2-devel] " Andrei Warkentin
2023-02-09 1:50 ` Michael D Kinney
2023-02-09 5:38 ` Ni, Ray
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 10/20] EmbeddedPkg: Enable PcdPrePiCpuIoSize for RISC-V Sunil V L
2023-02-06 16:00 ` [edk2-devel] " Andrei Warkentin
2023-02-09 1:51 ` Michael D Kinney
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 11/20] ArmVirtPkg/PlatformHasAcpiDtDxe: Move to OvmfPkg Sunil V L
2023-02-06 16:01 ` [edk2-devel] " Andrei Warkentin
2023-01-28 19:17 ` [edk2-staging/RiscV64QemuVirt PATCH V7 12/20] ArmVirtPkg: Fix up the location of PlatformHasAcpiDtDxe Sunil V L
2023-02-06 16:01 ` [edk2-devel] " Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 13/20] OvmfPkg/RiscVVirt: Add PlatformBootManagerLib library Sunil V L
2023-02-06 16:01 ` [edk2-devel] " Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 14/20] OvmfPkg/RiscVVirt: Add PrePiHobListPointerLib library Sunil V L
2023-02-06 16:01 ` [edk2-devel] " Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 15/20] OvmfPkg/RiscVVirt: Add ResetSystemLib library Sunil V L
2023-02-06 16:01 ` [edk2-devel] " Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 16/20] OvmfPkg/RiscVVirt: Add VirtNorFlashPlatformLib library Sunil V L
2023-02-06 16:02 ` [edk2-devel] " Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 17/20] OvmfPkg/RiscVVirt: Add PciCpuIo2Dxe module Sunil V L
2023-01-30 10:12 ` [edk2-devel] " dhaval
2023-01-30 13:05 ` Sunil V L
2023-01-30 14:33 ` dhaval
2023-02-06 16:02 ` Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 18/20] OvmfPkg/RiscVVirt: Add SEC module Sunil V L
2023-01-30 5:17 ` [edk2-devel] " dhaval
2023-01-30 6:00 ` Sunil V L
2023-02-06 16:03 ` Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 19/20] OvmfPkg/RiscVVirt: Add build files for Qemu Virt platform Sunil V L
2023-02-06 16:03 ` [edk2-devel] " Andrei Warkentin
2023-01-28 19:18 ` [edk2-staging/RiscV64QemuVirt PATCH V7 20/20] Maintainers.txt: Add entry for OvmfPkg/RiscVVirt Sunil V L
2023-02-06 16:04 ` [edk2-devel] " Andrei Warkentin
2023-02-09 1:51 ` Michael D Kinney
2023-02-09 3:32 ` [edk2-devel] " Yao, Jiewen
2023-02-09 4:34 ` Sunil V L
2023-02-09 5:07 ` Yao, Jiewen
2023-02-09 5:15 ` Chang, Abner
2023-02-09 14:05 ` Yao, Jiewen
2023-02-09 15:19 ` Sunil V L
2023-02-09 15:21 ` Yao, Jiewen
[not found] ` <173E8F29CD0D02D8.27165@groups.io>
2023-01-30 13:43 ` [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 11/20] ArmVirtPkg/PlatformHasAcpiDtDxe: Move to OvmfPkg Sunil V L
2023-02-03 12:29 ` Ard Biesheuvel
[not found] ` <173E8F254E9BED62.27165@groups.io>
2023-02-02 14:35 ` [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 03/20] MdePkg: Add BaseRiscVSbiLib Library for RISC-V Sunil V L
[not found] ` <173E8F293E682CB4.27165@groups.io>
2023-02-03 9:46 ` [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 10/20] EmbeddedPkg: Enable PcdPrePiCpuIoSize " Sunil V L
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-list 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=Y+TKsLcG1hgWnV1x@sunil-laptop \
--to=devel@edk2.groups.io \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox