From patchwork Wed Nov 6 09:45:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1190198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477M954s8Jz9sP6; Wed, 6 Nov 2019 20:45:45 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iSHsl-0002bv-3x; Wed, 06 Nov 2019 09:45:43 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsj-0002bV-0c for fwts-devel@lists.ubuntu.com; Wed, 06 Nov 2019 09:45:41 +0000 Received: from [106.104.115.126] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsh-00014U-Nu; Wed, 06 Nov 2019 09:45:40 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 4/5] uefirtvariable: add unsupported checking with RuntimeServicesSupported variable Date: Wed, 6 Nov 2019 17:45:15 +0800 Message-Id: <20191106094516.15762-5-ivan.hu@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191106094516.15762-1-ivan.hu@canonical.com> References: <20191106094516.15762-1-ivan.hu@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" UEFI spec 2.8 introduced the variable RuntimeServicesSupported, which is Bitmask of which calls are implemented by the firmware during runtime services. Add tests for checking variable services with RuntimeServicesSupported variable. Signed-off-by: Ivan Hu --- src/uefi/uefirtvariable/uefirtvariable.c | 180 +++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c index bb7c602..55a9b1d 100644 --- a/src/uefi/uefirtvariable/uefirtvariable.c +++ b/src/uefi/uefirtvariable/uefirtvariable.c @@ -2030,6 +2030,185 @@ static int uefirtvariable_test8(fwts_framework *fw) return FWTS_OK; } +static int uefirtvariable_test9(fwts_framework *fw) +{ + + bool getvar_supported; + uint32_t var_runtimeservicessupported; + + struct efi_getvariable getvariable; + struct efi_setvariable setvariable; + struct efi_getnextvariablename getnextvariablename; + struct efi_queryvariableinfo queryvariableinfo; + + EFI_GUID guid; + uint64_t status = ~0ULL; + uint8_t data = 1; + uint64_t datasize = 1; + uint64_t variablenamesize = MAX_DATA_LENGTH; + uint16_t *variablename; + uint64_t remvarstoragesize; + uint64_t maxvariablesize; + uint64_t maxvarstoragesize; + uint8_t testdata[MAX_DATA_LENGTH]; + uint64_t getdatasize = sizeof(testdata); + uint32_t attr; + + fwts_uefi_rt_support_status_get(fd, &getvar_supported, + &var_runtimeservicessupported); + + if (!getvar_supported || (var_runtimeservicessupported == 0xFFFF)) { + fwts_skipped(fw, "Cannot get the RuntimeServicesSupported " + "variable, maybe the runtime service " + "GetVariable is not supported or " + "RuntimeServicesSupported not provided by " + "firmware."); + return FWTS_SKIP; + } + + setvariable.VariableName = variablenametest; + setvariable.VendorGuid = >estguid1; + setvariable.Attributes = attributes; + setvariable.DataSize = datasize; + setvariable.Data = &data; + setvariable.status = &status; + + ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_VARIABLE) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable", + "Get the Setvariable runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI SetVariable runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_VARIABLE) || + (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI SetVariable runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable", + "Get the SetVariable runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + getvariable.VariableName = variablenametest; + getvariable.VendorGuid = >estguid1; + getvariable.Attributes = &attr; + getvariable.DataSize = &getdatasize; + getvariable.Data = testdata; + getvariable.status = &status; + + ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_VARIABLE) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetVariable", + "Get the GetVariable runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI GetVariable runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_VARIABLE) || + (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI GetVariable runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetVariable", + "Get the GetVariable runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + /* delete the variable which was set */ + setvariable.DataSize = 0; + status = ~0ULL; + ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable); + + variablename = malloc(sizeof(uint16_t) * variablenamesize); + if (!variablename) { + fwts_skipped(fw, "Unable to alloc memory for variable name"); + return FWTS_SKIP; + } + getnextvariablename.VariableNameSize = &variablenamesize; + getnextvariablename.VariableName = variablename; + getnextvariablename.VendorGuid = &guid; + getnextvariablename.status = &status; + + variablename[0] = '\0'; + status = ~0ULL; + ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVarName", + "Get the GetNextVarName runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI GetNextVarName runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI GetNextVarName runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVarName", + "Get the GetNextVarName runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + queryvariableinfo.Attributes = attributes; + queryvariableinfo.MaximumVariableStorageSize = &maxvarstoragesize; + queryvariableinfo.RemainingVariableStorageSize = &remvarstoragesize; + queryvariableinfo.MaximumVariableSize = &maxvariablesize; + queryvariableinfo.status = &status; + status = ~0ULL; + + ioctl(fd, EFI_RUNTIME_QUERY_VARIABLEINFO, &queryvariableinfo); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeQueryVarInfo", + "Get the QueryVarInfo runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI QueryVarInfo runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI QueryVarInfo runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeQueryVarInfo", + "Get the QueryVarInfo runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + + return FWTS_OK; + +} + static int options_check(fwts_framework *fw) { FWTS_UNUSED(fw); @@ -2101,6 +2280,7 @@ static fwts_framework_minor_test uefirtvariable_tests[] = { { uefirtvariable_test6, "Test UEFI RT service set variable interface stress test." }, { uefirtvariable_test7, "Test UEFI RT service query variable info interface stress test." }, { uefirtvariable_test8, "Test UEFI RT service get variable interface, invalid parameters." }, + { uefirtvariable_test9, "Test UEFI RT variable services supported status." }, { NULL, NULL } };