-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MemoryProtectionTestApp: Separate Reset Method Init to Arch Specific …
…Files (#376) ## Description The reset test method is not supported on ARM platforms currently (support will be added later, but it's not high priority because this test method often takes 40+ minutes). This PR separates the initialization of this testing method to architecture specific logic so the test method is not attempted on ARM platforms. This also fixes a build error on ARM platforms caused by DefaultExceptionHandlerLib being included (which does not support UEFI_APPLICATION without a MU override). - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Running the updated test app on Q35 and SBSA ## Integration Instructions N/A
- Loading branch information
1 parent
7309048
commit b814597
Showing
8 changed files
with
185 additions
and
114 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/AArch64/AArch64Functions.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** @file | ||
Copyright (C) Microsoft Corporation. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Uefi.h> | ||
|
||
#include <Library/DebugLib.h> | ||
#include <Library/UnitTestLib.h> | ||
|
||
/** | ||
Registers the interrupt handler which will be invoked when a page fault occurs. | ||
@retval EFI_SUCCESS Interrupt handler successfully installed | ||
@retval EFI_UNSUPPORTED Installing the interrupt handler is not supported. | ||
@retval others Error occurred during installation. | ||
**/ | ||
EFI_STATUS | ||
EFIAPI | ||
RegisterMemoryProtectionTestAppInterruptHandler ( | ||
VOID | ||
) | ||
{ | ||
// TODO: Add support for reset test method on Arm | ||
return EFI_UNSUPPORTED; | ||
} | ||
|
||
/** | ||
Checks if the hardware NX protection is enabled. | ||
@param[in] Context The unit test context. | ||
@retval UNIT_TEST_PASSED Hardware NX protection is enabled. | ||
@retval others Hardware NX protection is not enabled. | ||
**/ | ||
UNIT_TEST_STATUS | ||
EFIAPI | ||
UefiHardwareNxProtectionEnabled ( | ||
IN UNIT_TEST_CONTEXT Context | ||
) | ||
{ | ||
// ARM UEFI only has Stage 1 translation, so the FEAT XNX configuration bit does not apply. | ||
return UNIT_TEST_PASSED; | ||
} |
39 changes: 39 additions & 0 deletions
39
UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/ArchSpecificFunctions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** @file -- ArchSpecificFunctions.h | ||
Shared definition of the method between x64 and ARM. | ||
Copyright (C) Microsoft Corporation. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef ARCH_SPECIFIC_FUNCTIONS_H_ | ||
#define ARCH_SPECIFIC_FUNCTIONS_H_ | ||
|
||
/** | ||
Registers the interrupt handler which will be invoked when a page fault occurs. | ||
@retval EFI_SUCCESS Interrupt handler successfully installed | ||
@retval EFI_UNSUPPORTED Installing the interrupt handler is not supported. | ||
@retval others Error occurred during installation. | ||
**/ | ||
EFI_STATUS | ||
EFIAPI | ||
RegisterMemoryProtectionTestAppInterruptHandler ( | ||
VOID | ||
); | ||
|
||
/** | ||
Checks if the hardware NX protection is enabled. | ||
@param[in] Context The unit test context. | ||
@retval UNIT_TEST_PASSED Hardware NX protection is enabled. | ||
@retval others Hardware NX protection is not enabled. | ||
**/ | ||
UNIT_TEST_STATUS | ||
EFIAPI | ||
UefiHardwareNxProtectionEnabled ( | ||
IN UNIT_TEST_CONTEXT Context | ||
); | ||
|
||
#endif // ARCH_SPECIFIC_FUNCTIONS_H_ |
21 changes: 0 additions & 21 deletions
21
UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/Arm/UefiHardwareNxProtection.c
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/UefiHardwareNxProtectionStub.h
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/X64/UefiHardwareNxProtection.c
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
UefiTestingPkg/FunctionalSystemTests/MemoryProtectionTest/App/X64/X64Functions.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** @file | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <Uefi.h> | ||
|
||
#include <Library/BaseLib.h> | ||
#include <Library/DebugLib.h> | ||
#include <Register/ArchitecturalMsr.h> | ||
#include <Library/UnitTestLib.h> | ||
#include <Library/ResetSystemLib.h> | ||
#include <Protocol/Cpu.h> | ||
#include <Library/UefiBootServicesTableLib.h> | ||
|
||
/** | ||
Resets the system on interrupt | ||
@param InterruptType Defines the type of interrupt or exception that | ||
occurred on the processor.This parameter is processor architecture specific. | ||
@param SystemContext A pointer to the processor context when | ||
the interrupt occurred on the processor. | ||
**/ | ||
VOID | ||
EFIAPI | ||
InterruptHandler ( | ||
IN EFI_EXCEPTION_TYPE InterruptType, | ||
IN EFI_SYSTEM_CONTEXT SystemContext | ||
) | ||
{ | ||
// Avoid using runtime services to reset the system because doing so will raise the TPL level | ||
// when it is already on TPL_HIGH. HwResetSystemLib is used here instead to perform a bare-metal reset | ||
// and sidestep this issue. | ||
ResetWarm (); | ||
} | ||
|
||
/** | ||
Registers the interrupt handler which will be invoked when a page fault occurs. | ||
@retval EFI_SUCCESS Interrupt handler successfully installed | ||
@retval EFI_UNSUPPORTED Installing the interrupt handler is not supported. | ||
@retval others Error occurred during installation. | ||
**/ | ||
EFI_STATUS | ||
EFIAPI | ||
RegisterMemoryProtectionTestAppInterruptHandler ( | ||
VOID | ||
) | ||
{ | ||
EFI_CPU_ARCH_PROTOCOL *CpuProtocol = NULL; | ||
EFI_STATUS Status; | ||
|
||
// Find the CPU Architecture Protocol | ||
Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuProtocol); | ||
|
||
if (EFI_ERROR (Status)) { | ||
DEBUG ((DEBUG_ERROR, "Failed to locate gEfiCpuArchProtocolGuid. Status = %r\n", Status)); | ||
return EFI_INVALID_PARAMETER; | ||
} | ||
|
||
// Uninstall the existing page fault handler | ||
CpuProtocol->RegisterInterruptHandler (CpuProtocol, EXCEPT_IA32_PAGE_FAULT, NULL); | ||
|
||
return CpuProtocol->RegisterInterruptHandler (CpuProtocol, EXCEPT_IA32_PAGE_FAULT, InterruptHandler); | ||
} | ||
|
||
/** | ||
Checks if the hardware NX protection is enabled. | ||
@param[in] Context The unit test context. | ||
@retval UNIT_TEST_PASSED Hardware NX protection is enabled. | ||
@retval others Hardware NX protection is not enabled. | ||
**/ | ||
UNIT_TEST_STATUS | ||
EFIAPI | ||
UefiHardwareNxProtectionEnabled ( | ||
IN UNIT_TEST_CONTEXT Context | ||
) | ||
{ | ||
MSR_IA32_EFER_REGISTER Efer; | ||
|
||
Efer.Uint64 = AsmReadMsr64 (MSR_IA32_EFER); | ||
if (Efer.Bits.NXE == 1) { | ||
return UNIT_TEST_PASSED; | ||
} | ||
|
||
UT_LOG_WARNING ("Efer set as 0x%x\n", Efer); | ||
return UNIT_TEST_ERROR_TEST_FAILED; | ||
} |