* [edk2-devel] RFC: SetVariable callbacks
@ 2023-09-20 20:27 Girish Mahadevan via groups.io
2023-09-21 7:41 ` Nhi Pham via groups.io
0 siblings, 1 reply; 4+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-09-20 20:27 UTC (permalink / raw)
To: Hao A Wu, Liming Gao, devel@edk2.groups.io; +Cc: Jeff Brasen, Ashish Singhal
Hello
We have a requirement to monitor setVariable calls, we'd like to get a
callback before and after the variable update.
Similar to VarCheckLib, except that VarCheckLib's set callbacks are
called after endOfDxe.
We were thinking of doing something like:
===============
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -2853,6 +2853,11 @@ VariableServiceSetVariable (
return Status;
}
+ Status = VarPreSetVariableCallback (VariableName, VendorGuid,
Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
mRequestSource);^M
+ if (EFI_ERROR (Status)) {^M
+ return Status;^M
+ }^M
+^M
AcquireLockOnlyAtBootTime
(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
//
@@ -2917,6 +2922,8 @@ Done:
InterlockedDecrement
(&mVariableModuleGlobal->VariableGlobal.ReentrantState);
ReleaseLockOnlyAtBootTime
(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
+ Status = VarPostSetVariableCallback (VariableName, VendorGuid,
Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
mRequestSource);^M
+^M
==========================
We were thinking of 4 options:
1. A new Library, platforms can include the Null implementation if they
don't need this.
2. A new protocol that is called from the Variable driver (similar to
the Fvb protocol, we let the Smm/Dxe Variable drivers get this protocol)
3. Expand the existing VarCheckLib to include these new callbacks.
(which can be called before end of dxe)
4. Something we don't know about (please let us know)
We are leaning toward option 1. Let us know your thoughts.
Best Regards
Girish
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108929): https://edk2.groups.io/g/devel/message/108929
Mute This Topic: https://groups.io/mt/101487036/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] RFC: SetVariable callbacks
2023-09-20 20:27 [edk2-devel] RFC: SetVariable callbacks Girish Mahadevan via groups.io
@ 2023-09-21 7:41 ` Nhi Pham via groups.io
2023-09-21 15:58 ` Girish Mahadevan via groups.io
0 siblings, 1 reply; 4+ messages in thread
From: Nhi Pham via groups.io @ 2023-09-21 7:41 UTC (permalink / raw)
To: devel, gmahadevan, Hao A Wu, Liming Gao; +Cc: Jeff Brasen, Ashish Singhal
Can we write a DXE_RUNTIME driver to override the pointers of UEFI
Runtime Get/SetVariable() services? Then, we can add platform specific
or custom implementation before/after calling the original
Get/SetVariable()?
Regards,
Nhi
On 9/21/2023 3:27 AM, Girish Mahadevan via groups.io wrote:
> Hello
>
> We have a requirement to monitor setVariable calls, we'd like to get a
> callback before and after the variable update.
>
> Similar to VarCheckLib, except that VarCheckLib's set callbacks are
> called after endOfDxe.
>
> We were thinking of doing something like:
>
> ===============
>
> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
> @@ -2853,6 +2853,11 @@ VariableServiceSetVariable (
> return Status;
> }
>
> + Status = VarPreSetVariableCallback (VariableName, VendorGuid,
> Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
> mRequestSource);^M
> + if (EFI_ERROR (Status)) {^M
> + return Status;^M
> + }^M
> +^M
> AcquireLockOnlyAtBootTime
> (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
>
> //
> @@ -2917,6 +2922,8 @@ Done:
> InterlockedDecrement
> (&mVariableModuleGlobal->VariableGlobal.ReentrantState);
> ReleaseLockOnlyAtBootTime
> (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
>
> + Status = VarPostSetVariableCallback (VariableName, VendorGuid,
> Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
> mRequestSource);^M
> +^M
>
> ==========================
>
>
> We were thinking of 4 options:
> 1. A new Library, platforms can include the Null implementation if they
> don't need this.
> 2. A new protocol that is called from the Variable driver (similar to
> the Fvb protocol, we let the Smm/Dxe Variable drivers get this protocol)
> 3. Expand the existing VarCheckLib to include these new callbacks.
> (which can be called before end of dxe)
> 4. Something we don't know about (please let us know)
>
> We are leaning toward option 1. Let us know your thoughts.
>
> Best Regards
> Girish
>
>
>
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108936): https://edk2.groups.io/g/devel/message/108936
Mute This Topic: https://groups.io/mt/101487036/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] RFC: SetVariable callbacks
2023-09-21 7:41 ` Nhi Pham via groups.io
@ 2023-09-21 15:58 ` Girish Mahadevan via groups.io
2023-10-20 3:56 ` Nhi Pham via groups.io
0 siblings, 1 reply; 4+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-09-21 15:58 UTC (permalink / raw)
To: devel, nhi, Hao A Wu, Liming Gao; +Cc: Jeff Brasen, Ashish Singhal
Hello Nhi,
On 9/21/2023 1:41 AM, Nhi Pham via groups.io wrote:
> External email: Use caution opening links or attachments
>
>
> Can we write a DXE_RUNTIME driver to override the pointers of UEFI
> Runtime Get/SetVariable() services? Then, we can add platform specific
> or custom implementation before/after calling the original
> Get/SetVariable()?
>
Thanks for the suggestion. This doesn't work for us, we need the
notifications in StMM, also we'd prefer to get these callbacks from
VariableServiceSetVariable() itself after the basic checks for the set
var are done (similar to how VarCheckLib is called)
Best Regards
Girish
> Regards,
> Nhi
>
> On 9/21/2023 3:27 AM, Girish Mahadevan via groups.io wrote:
>> Hello
>>
>> We have a requirement to monitor setVariable calls, we'd like to get a
>> callback before and after the variable update.
>>
>> Similar to VarCheckLib, except that VarCheckLib's set callbacks are
>> called after endOfDxe.
>>
>> We were thinking of doing something like:
>>
>> ===============
>>
>> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>> @@ -2853,6 +2853,11 @@ VariableServiceSetVariable (
>> return Status;
>> }
>>
>> + Status = VarPreSetVariableCallback (VariableName, VendorGuid,
>> Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
>> mRequestSource);^M
>> + if (EFI_ERROR (Status)) {^M
>> + return Status;^M
>> + }^M
>> +^M
>> AcquireLockOnlyAtBootTime
>> (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
>>
>> //
>> @@ -2917,6 +2922,8 @@ Done:
>> InterlockedDecrement
>> (&mVariableModuleGlobal->VariableGlobal.ReentrantState);
>> ReleaseLockOnlyAtBootTime
>> (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
>>
>> + Status = VarPostSetVariableCallback (VariableName, VendorGuid,
>> Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
>> mRequestSource);^M
>> +^M
>>
>> ==========================
>>
>>
>> We were thinking of 4 options:
>> 1. A new Library, platforms can include the Null implementation if they
>> don't need this.
>> 2. A new protocol that is called from the Variable driver (similar to
>> the Fvb protocol, we let the Smm/Dxe Variable drivers get this protocol)
>> 3. Expand the existing VarCheckLib to include these new callbacks.
>> (which can be called before end of dxe)
>> 4. Something we don't know about (please let us know)
>>
>> We are leaning toward option 1. Let us know your thoughts.
>>
>> Best Regards
>> Girish
>>
>>
>>
>>
>>
>
>
>
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108947): https://edk2.groups.io/g/devel/message/108947
Mute This Topic: https://groups.io/mt/101487036/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] RFC: SetVariable callbacks
2023-09-21 15:58 ` Girish Mahadevan via groups.io
@ 2023-10-20 3:56 ` Nhi Pham via groups.io
0 siblings, 0 replies; 4+ messages in thread
From: Nhi Pham via groups.io @ 2023-10-20 3:56 UTC (permalink / raw)
To: Girish Mahadevan, devel, Hao A Wu, Liming Gao; +Cc: Jeff Brasen, Ashish Singhal
Hi Girish,
I missed your reply. Sorry if I chime in very late, and you started to
develop toward option 1. There are some cases that we can leverage your
work here.
Please see inline...
On 9/21/2023 10:58 PM, Girish Mahadevan wrote:
> Hello Nhi,
>
> On 9/21/2023 1:41 AM, Nhi Pham via groups.io wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> Can we write a DXE_RUNTIME driver to override the pointers of UEFI
>> Runtime Get/SetVariable() services? Then, we can add platform specific
>> or custom implementation before/after calling the original
>> Get/SetVariable()?
>>
>
> Thanks for the suggestion. This doesn't work for us, we need the
> notifications in StMM, also we'd prefer to get these callbacks from
> VariableServiceSetVariable() itself after the basic checks for the set
> var are done (similar to how VarCheckLib is called)
That makes sense. Thanks!
>
> Best Regards
> Girish
>
>> Regards,
>> Nhi
>>
>> On 9/21/2023 3:27 AM, Girish Mahadevan via groups.io wrote:
>>> Hello
>>>
>>> We have a requirement to monitor setVariable calls, we'd like to get a
>>> callback before and after the variable update.
>>>
>>> Similar to VarCheckLib, except that VarCheckLib's set callbacks are
>>> called after endOfDxe.
>>>
>>> We were thinking of doing something like:
>>>
>>> ===============
>>>
>>> --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>> +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
>>> @@ -2853,6 +2853,11 @@ VariableServiceSetVariable (
>>> return Status;
>>> }
>>>
>>> + Status = VarPreSetVariableCallback (VariableName, VendorGuid,
>>> Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
>>> mRequestSource);^M
>>> + if (EFI_ERROR (Status)) {^M
>>> + return Status;^M
>>> + }^M
>>> +^M
>>> AcquireLockOnlyAtBootTime
>>> (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
>>>
>>> //
>>> @@ -2917,6 +2922,8 @@ Done:
>>> InterlockedDecrement
>>> (&mVariableModuleGlobal->VariableGlobal.ReentrantState);
>>> ReleaseLockOnlyAtBootTime
>>> (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
>>>
>>> + Status = VarPostSetVariableCallback (VariableName, VendorGuid,
>>> Attributes, PayloadSize, (VOID *)((UINTN)Data + DataSize - PayloadSize),
>>> mRequestSource);^M
>>> +^M
>>>
>>> ==========================
>>>
>>>
>>> We were thinking of 4 options:
>>> 1. A new Library, platforms can include the Null implementation if they
>>> don't need this.
>>> 2. A new protocol that is called from the Variable driver (similar to
>>> the Fvb protocol, we let the Smm/Dxe Variable drivers get this protocol)
This option seems to be able to accommodate more scenarios. For example,
a platform wants to hook their platform specific implementation based on
the RT Get/Set Variable services. The feature can reuse the UEFI RT
service as an interface for Operating System to communicate with UEFI or
StandaloneMM.
Regards,
Nhi
>>> 3. Expand the existing VarCheckLib to include these new callbacks.
>>> (which can be called before end of dxe)
>>> 4. Something we don't know about (please let us know)
>>>
>>> We are leaning toward option 1. Let us know your thoughts.
>>>
>>> Best Regards
>>> Girish
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#109822): https://edk2.groups.io/g/devel/message/109822
Mute This Topic: https://groups.io/mt/101487036/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-20 3:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-20 20:27 [edk2-devel] RFC: SetVariable callbacks Girish Mahadevan via groups.io
2023-09-21 7:41 ` Nhi Pham via groups.io
2023-09-21 15:58 ` Girish Mahadevan via groups.io
2023-10-20 3:56 ` Nhi Pham via groups.io
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox