public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* Communicate with soft-smi-handler with uefi-application question.
@ 2018-01-10  7:43 krishnaLee
  2018-01-10  9:26 ` Zeng, Star
  0 siblings, 1 reply; 3+ messages in thread
From: krishnaLee @ 2018-01-10  7:43 UTC (permalink / raw)
  To: edk2-devel

Hi,
I'm learning  to write and register some soft-Smi-Handler in smm-mode;
then using QEMU to boot my ovmf.fd,run into uefi shell;
then write uefi-application using EFI_SMM_COMMUNICATION_PROTOCOL to Communicate to my Smi-Handler,but failed when run my uefi-application,the log show error.
I don't know why,maybe I do not full understand uefi-smm,but how to communicate to my smi handler?


//error-message
[Security] 3rd party image[0] can be loaded after EndOfDxe: PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\mytestsmm.efi.
InstallProtocolInterface: 5B1B31A1-9562-11D2-8E3F-00A0C969723B 65FC4A8
Loading driver at 0x000062B0000 EntryPoint=0x000062B10F5 mytestsmm.efi
InstallProtocolInterface: BC62157E-3E33-4FEC-9920-2D3B36D750DF 65FCB10
ProtectUefiImageCommon - 0x65FC4A8
  - 0x00000000062B0000 - 0x0000000000007000
InstallProtocolInterface: 752F3136-4E16-4FDC-A22A-E5F46812F4CA 7700CFC
InstallProtocolInterface: 4C8A2451-C207-405B-9694-99EA13251341 62B40B0
Locate EfiSmmCommunicationProtocol success
SmmIsBufferOutsideSmmValid: Not in ValidCommunicationRegion: Buffer (0x7700C94) - Length (0x2A), ASSERT [PiSmmCore] d:\edk2-vudk2017\MdePkg\Library\SmmMemLib\SmmMemLib.c(178): ((BOOLEAN)(0==1))
//error-message-end


//my register-smi-handler code:
//edk2-vUDK2017\MdeModulePkg\Universal\LockBox\SmmLockBox\SmmLockBox.c

EFI_STATUS

EFIAPI

MyTestSmmHandler (

IN EFI_HANDLE DispatchHandle,

IN CONST VOID *Context OPTIONAL,

IN OUT VOID *CommBuffer OPTIONAL,

IN OUT UINTN *CommBufferSize OPTIONAL

)

{

DEBUG ((DEBUG_INFO, "My Test Smm Handler Enter\n"));

DEBUG ((DEBUG_INFO, "My Test Smm Handler exit\n"));

return EFI_SUCCESS;

}




EFI_STATUS

EFIAPI

SmmLockBoxEntryPoint (

IN EFI_HANDLE ImageHandle,

IN EFI_SYSTEM_TABLE *SystemTable

)

{��

//Register My Test Smm handler

Status = gSmst->SmiHandlerRegister (

MyTestSmmHandler,

&gEfiMyTestSmmGuid,

&DispatchHandle

);

ASSERT_EFI_ERROR (Status);

��

}



//the uefi-application code
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication;
EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader;
UINT8 *buffer;
UINTN bufferSize;


bufferSize=sizeof(EFI_SMM_COMMUNICATE_HEADER)*2;
gBS->AllocatePool (EfiRuntimeServicesData,bufferSize,&buffer);
if(buffer==NULL)
{
Print(L"EFI_OUT_OF_RESOURCES, return\n");
return EFI_OUT_OF_RESOURCES;
}


SmmCommunicateHeader=(EFI_SMM_COMMUNICATE_HEADER*)buffer;
CopyGuid(&SmmCommunicateHeader->HeaderGuid,&gEfiMyTestSmmGuid);
SmmCommunicateHeader->MessageLength=sizeof(EFI_SMM_COMMUNICATE_HEADER);


Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);
if(Status==EFI_SUCCESS)
{
Print(L"Locate EfiSmmCommunicationProtocol success\n");
}else
{
Print(L"Locate EfiSmmCommunicationProtocol failed return\n");
return EFI_SUCCESS;
}


Status=mSmmCommunication->Communicate(mSmmCommunication,&buffer,&bufferSize);
if(Status==EFI_SUCCESS)
{
Print(L"Communication success\n");
}else
{
Print(L"Communication failed\n");
return EFI_SUCCESS;
}


gBS->FreePool(buffer);


return EFI_SUCCESS;
}


any help will be appreciated!
by krishna


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Communicate with soft-smi-handler with uefi-application question.
  2018-01-10  7:43 Communicate with soft-smi-handler with uefi-application question krishnaLee
@ 2018-01-10  9:26 ` Zeng, Star
  2018-01-11  0:38   ` krishnaLee
  0 siblings, 1 reply; 3+ messages in thread
From: Zeng, Star @ 2018-01-10  9:26 UTC (permalink / raw)
  To: krishnaLee, edk2-devel@lists.01.org; +Cc: Zeng, Star

The trusted smm communication buffer needs to be allocated as EfiReservedMemoryType, EfiACPIMemoryNVS, or EfiRuntimeServicesData before EndOfDxe.
There is a generic smm communication buffer can be used if MdeModulePkg\Universal\SmmCommunicationBufferDxe is included in dsc and fdf.

You can refer https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c#L90 to know how it be used.


Thanks,
Star
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of krishnaLee
Sent: Wednesday, January 10, 2018 3:44 PM
To: edk2-devel@lists.01.org
Subject: [edk2] Communicate with soft-smi-handler with uefi-application question.

Hi,
I'm learning  to write and register some soft-Smi-Handler in smm-mode; then using QEMU to boot my ovmf.fd,run into uefi shell; then write uefi-application using EFI_SMM_COMMUNICATION_PROTOCOL to Communicate to my Smi-Handler,but failed when run my uefi-application,the log show error.
I don't know why,maybe I do not full understand uefi-smm,but how to communicate to my smi handler?


//error-message
[Security] 3rd party image[0] can be loaded after EndOfDxe: PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\mytestsmm.efi.
InstallProtocolInterface: 5B1B31A1-9562-11D2-8E3F-00A0C969723B 65FC4A8 Loading driver at 0x000062B0000 EntryPoint=0x000062B10F5 mytestsmm.efi
InstallProtocolInterface: BC62157E-3E33-4FEC-9920-2D3B36D750DF 65FCB10 ProtectUefiImageCommon - 0x65FC4A8
  - 0x00000000062B0000 - 0x0000000000007000
InstallProtocolInterface: 752F3136-4E16-4FDC-A22A-E5F46812F4CA 7700CFC
InstallProtocolInterface: 4C8A2451-C207-405B-9694-99EA13251341 62B40B0 Locate EfiSmmCommunicationProtocol success
SmmIsBufferOutsideSmmValid: Not in ValidCommunicationRegion: Buffer (0x7700C94) - Length (0x2A), ASSERT [PiSmmCore] d:\edk2-vudk2017\MdePkg\Library\SmmMemLib\SmmMemLib.c(178): ((BOOLEAN)(0==1)) //error-message-end


//my register-smi-handler code:
//edk2-vUDK2017\MdeModulePkg\Universal\LockBox\SmmLockBox\SmmLockBox.c

EFI_STATUS

EFIAPI

MyTestSmmHandler (

IN EFI_HANDLE DispatchHandle,

IN CONST VOID *Context OPTIONAL,

IN OUT VOID *CommBuffer OPTIONAL,

IN OUT UINTN *CommBufferSize OPTIONAL

)

{

DEBUG ((DEBUG_INFO, "My Test Smm Handler Enter\n"));

DEBUG ((DEBUG_INFO, "My Test Smm Handler exit\n"));

return EFI_SUCCESS;

}




EFI_STATUS

EFIAPI

SmmLockBoxEntryPoint (

IN EFI_HANDLE ImageHandle,

IN EFI_SYSTEM_TABLE *SystemTable

)

{...

//Register My Test Smm handler

Status = gSmst->SmiHandlerRegister (

MyTestSmmHandler,

&gEfiMyTestSmmGuid,

&DispatchHandle

);

ASSERT_EFI_ERROR (Status);

...

}



//the uefi-application code
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication; EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader;
UINT8 *buffer;
UINTN bufferSize;


bufferSize=sizeof(EFI_SMM_COMMUNICATE_HEADER)*2;
gBS->AllocatePool (EfiRuntimeServicesData,bufferSize,&buffer);
if(buffer==NULL)
{
Print(L"EFI_OUT_OF_RESOURCES, return\n"); return EFI_OUT_OF_RESOURCES; }


SmmCommunicateHeader=(EFI_SMM_COMMUNICATE_HEADER*)buffer;
CopyGuid(&SmmCommunicateHeader->HeaderGuid,&gEfiMyTestSmmGuid);
SmmCommunicateHeader->MessageLength=sizeof(EFI_SMM_COMMUNICATE_HEADER);


Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);
if(Status==EFI_SUCCESS)
{
Print(L"Locate EfiSmmCommunicationProtocol success\n"); }else { Print(L"Locate EfiSmmCommunicationProtocol failed return\n"); return EFI_SUCCESS; }


Status=mSmmCommunication->Communicate(mSmmCommunication,&buffer,&bufferSize);
if(Status==EFI_SUCCESS)
{
Print(L"Communication success\n");
}else
{
Print(L"Communication failed\n");
return EFI_SUCCESS;
}


gBS->FreePool(buffer);


return EFI_SUCCESS;
}


any help will be appreciated!
by krishna

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Communicate with soft-smi-handler with uefi-application question.
  2018-01-10  9:26 ` Zeng, Star
@ 2018-01-11  0:38   ` krishnaLee
  0 siblings, 0 replies; 3+ messages in thread
From: krishnaLee @ 2018-01-11  0:38 UTC (permalink / raw)
  To: Zeng, Star; +Cc: edk2-devel@lists.01.org

Hi,Star:
Yes,that's what I needed,now I understand the buffer has some restriction.
 
thank you very much!
by krishna





At 2018-01-10 17:26:28, "Zeng, Star" <star.zeng@intel.com> wrote:
>The trusted smm communication buffer needs to be allocated as EfiReservedMemoryType, EfiACPIMemoryNVS, or EfiRuntimeServicesData before EndOfDxe.
>There is a generic smm communication buffer can be used if MdeModulePkg\Universal\SmmCommunicationBufferDxe is included in dsc and fdf.
>
>You can refer https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c#L90 to know how it be used.
>
>
>Thanks,
>Star
>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of krishnaLee
>Sent: Wednesday, January 10, 2018 3:44 PM
>To: edk2-devel@lists.01.org
>Subject: [edk2] Communicate with soft-smi-handler with uefi-application question.
>
>Hi,
>I'm learning  to write and register some soft-Smi-Handler in smm-mode; then using QEMU to boot my ovmf.fd,run into uefi shell; then write uefi-application using EFI_SMM_COMMUNICATION_PROTOCOL to Communicate to my Smi-Handler,but failed when run my uefi-application,the log show error.
>I don't know why,maybe I do not full understand uefi-smm,but how to communicate to my smi handler?
>
>
>//error-message
>[Security] 3rd party image[0] can be loaded after EndOfDxe: PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)/HD(1,MBR,0xBE1AFDFA,0x3F,0xFBFC1)/\mytestsmm.efi.
>InstallProtocolInterface: 5B1B31A1-9562-11D2-8E3F-00A0C969723B 65FC4A8 Loading driver at 0x000062B0000 EntryPoint=0x000062B10F5 mytestsmm.efi
>InstallProtocolInterface: BC62157E-3E33-4FEC-9920-2D3B36D750DF 65FCB10 ProtectUefiImageCommon - 0x65FC4A8
>  - 0x00000000062B0000 - 0x0000000000007000
>InstallProtocolInterface: 752F3136-4E16-4FDC-A22A-E5F46812F4CA 7700CFC
>InstallProtocolInterface: 4C8A2451-C207-405B-9694-99EA13251341 62B40B0 Locate EfiSmmCommunicationProtocol success
>SmmIsBufferOutsideSmmValid: Not in ValidCommunicationRegion: Buffer (0x7700C94) - Length (0x2A), ASSERT [PiSmmCore] d:\edk2-vudk2017\MdePkg\Library\SmmMemLib\SmmMemLib.c(178): ((BOOLEAN)(0==1)) //error-message-end
>
>
>//my register-smi-handler code:
>//edk2-vUDK2017\MdeModulePkg\Universal\LockBox\SmmLockBox\SmmLockBox.c
>
>EFI_STATUS
>
>EFIAPI
>
>MyTestSmmHandler (
>
>IN EFI_HANDLE DispatchHandle,
>
>IN CONST VOID *Context OPTIONAL,
>
>IN OUT VOID *CommBuffer OPTIONAL,
>
>IN OUT UINTN *CommBufferSize OPTIONAL
>
>)
>
>{
>
>DEBUG ((DEBUG_INFO, "My Test Smm Handler Enter\n"));
>
>DEBUG ((DEBUG_INFO, "My Test Smm Handler exit\n"));
>
>return EFI_SUCCESS;
>
>}
>
>
>
>
>EFI_STATUS
>
>EFIAPI
>
>SmmLockBoxEntryPoint (
>
>IN EFI_HANDLE ImageHandle,
>
>IN EFI_SYSTEM_TABLE *SystemTable
>
>)
>
>{...
>
>//Register My Test Smm handler
>
>Status = gSmst->SmiHandlerRegister (
>
>MyTestSmmHandler,
>
>&gEfiMyTestSmmGuid,
>
>&DispatchHandle
>
>);
>
>ASSERT_EFI_ERROR (Status);
>
>...
>
>}
>
>
>
>//the uefi-application code
>EFI_STATUS
>EFIAPI
>UefiMain (
>IN EFI_HANDLE ImageHandle,
>IN EFI_SYSTEM_TABLE *SystemTable
>)
>{
>EFI_STATUS Status;
>EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication; EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader;
>UINT8 *buffer;
>UINTN bufferSize;
>
>
>bufferSize=sizeof(EFI_SMM_COMMUNICATE_HEADER)*2;
>gBS->AllocatePool (EfiRuntimeServicesData,bufferSize,&buffer);
>if(buffer==NULL)
>{
>Print(L"EFI_OUT_OF_RESOURCES, return\n"); return EFI_OUT_OF_RESOURCES; }
>
>
>SmmCommunicateHeader=(EFI_SMM_COMMUNICATE_HEADER*)buffer;
>CopyGuid(&SmmCommunicateHeader->HeaderGuid,&gEfiMyTestSmmGuid);
>SmmCommunicateHeader->MessageLength=sizeof(EFI_SMM_COMMUNICATE_HEADER);
>
>
>Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);
>if(Status==EFI_SUCCESS)
>{
>Print(L"Locate EfiSmmCommunicationProtocol success\n"); }else { Print(L"Locate EfiSmmCommunicationProtocol failed return\n"); return EFI_SUCCESS; }
>
>
>Status=mSmmCommunication->Communicate(mSmmCommunication,&buffer,&bufferSize);
>if(Status==EFI_SUCCESS)
>{
>Print(L"Communication success\n");
>}else
>{
>Print(L"Communication failed\n");
>return EFI_SUCCESS;
>}
>
>
>gBS->FreePool(buffer);
>
>
>return EFI_SUCCESS;
>}
>
>
>any help will be appreciated!
>by krishna
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-11  0:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-10  7:43 Communicate with soft-smi-handler with uefi-application question krishnaLee
2018-01-10  9:26 ` Zeng, Star
2018-01-11  0:38   ` krishnaLee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox