[edk2-devel] RFC: SetVariable callbacks

Girish Mahadevan via groups.io posted 1 patch 7 months, 2 weeks ago
Failed in applying to current master (apply log)
[edk2-devel] RFC: SetVariable callbacks
Posted by Girish Mahadevan via groups.io 7 months, 2 weeks ago
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/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] RFC: SetVariable callbacks
Posted by Nhi Pham via groups.io 7 months, 2 weeks ago
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/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] RFC: SetVariable callbacks
Posted by Girish Mahadevan via groups.io 7 months, 1 week ago
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/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] RFC: SetVariable callbacks
Posted by Nhi Pham via groups.io 6 months, 2 weeks ago
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/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-