From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (NAM02-BL2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.16645.1602779580961104462 for ; Thu, 15 Oct 2020 09:33:02 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=zXnpbte5; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: mark.wilson@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aVsCVdMymDs8AMfBmP9PyTubxuByRfozWTKZrmJhIFW0Tfu3ixRn691FiXA/ceVesvQjdDtjvnQtzPSPaEOdqERIL3MDNRhIKpo/19Fzr4pjV6+OULAkmTuy1oRNjHllTVcnvrC0RRQmPVJhKlW3dCls6CWRpucO7xgRfCrCq2jLh7gJn8uW684JQiGuGsFnFaDPFq+94VWDmfuWgaQzTuS4pNIixVZh7I75qyG28icsso8GBC3uL4jZd+SHUHe0XHersvVtbH72gHb4DJNeOan/CIn/1ktK6UBrA+S7z7DT2hDEbHG5IAiPrKCbPthisgTRsb+94ocXzbpHZmj1LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cHv3zjoTmgtYu1Fxn2Qbj9cFaCxCaamJvZvGBQw43vg=; b=VBwAPhtdHEkzZZV63Fnh5dZ6h4LOa6ZAeukjXr8mSNWsGFOVTyqGKPVniPL2lmL9xnHIKhNaoVJfopkRd6qqEEYWWZ01dyZ/MkI3tb5ddK0Uf10efKWmZY7v39Dew5DlUiEJbuLRbogsGJm1iuJupecvT4dMpZXKBRhldYPzqh7LK1ydczT0uPk7Y7AEg+xV/KcYvd723Zo70Pa8/GmXT/AOclimjhUs5PZrZS8UzqYrrJvjyXy9BMHllPn0GHFjA2un0zMJqwCKQ9j7647IMSEOeTTwcwyeujPk71jeJJUx+aaC+9iCMdBFU13+MBBZhemLimjd9LbiGf9QDB8fhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cHv3zjoTmgtYu1Fxn2Qbj9cFaCxCaamJvZvGBQw43vg=; b=zXnpbte5f6pY8CzsCc7AmWzxLEDaIEWqQhCsAFUQxfAqin9tlJWsS9MZehFABbblcML8DrN8Jc11j5cMVC7hNCB5DMUdyEcJzuMPHLPjN/M4rI7oVPtsKBozbzBCmwd5/R4RDYE4d/+4gSMfQSHxk0W4xiUZ/sMd/wz0v7uXbiw= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB3484.namprd12.prod.outlook.com (2603:10b6:5:3c::15) by DM6PR12MB4974.namprd12.prod.outlook.com (2603:10b6:5:1bb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Thu, 15 Oct 2020 16:32:59 +0000 Received: from DM6PR12MB3484.namprd12.prod.outlook.com ([fe80::448b:c790:cbdd:d479]) by DM6PR12MB3484.namprd12.prod.outlook.com ([fe80::448b:c790:cbdd:d479%3]) with mapi id 15.20.3477.021; Thu, 15 Oct 2020 16:32:59 +0000 From: Mark Wilson To: devel@edk2.groups.io Cc: Mark Wilson , Eric Dong , Ray Ni Subject: [PATCH v1 1/1] UefiCpuPkg: Clean up save state boundary checks and comments. Date: Thu, 15 Oct 2020 11:32:43 -0500 Message-Id: <20201015163243.364-2-Mark.Wilson@amd.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20201015163243.364-1-Mark.Wilson@amd.com> References: <20201015163243.364-1-Mark.Wilson@amd.com> X-Originating-IP: [2605:6000:1023:847e::43a4] X-ClientProxiedBy: DM5PR21CA0046.namprd21.prod.outlook.com (2603:10b6:3:ed::32) To DM6PR12MB3484.namprd12.prod.outlook.com (2603:10b6:5:3c::15) Return-Path: Mark.Wilson@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from MSDN-MARWILSO.amd.com (2605:6000:1023:847e::43a4) by DM5PR21CA0046.namprd21.prod.outlook.com (2603:10b6:3:ed::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.3 via Frontend Transport; Thu, 15 Oct 2020 16:32:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e9727e4e-3d58-41bd-3dc7-08d87127fa30 X-MS-TrafficTypeDiagnostic: DM6PR12MB4974: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UzmsrrlZ33boS6vmSJRvL+AqaoXhiKZwmEr0Tg/E1jEqKh9U2wAtIhj64Jdk+SjeDg1CpjJXrnQzGH719FC/JDTaPtS7zRzfVdACeQmv+NuVLB7awRqFDacjdoJyg635QkIfX1jg+eEj1Zg6cTsBbPy2EGGCY6PWbNIRchBQNvKb+GzDvMEci9yqfUopm/hTapMvoWKRV3WMt7ptXxZvNY3oL9dJ0yQawkHIS5SHqKV2fLfisgVTS8RU8cjpOaGosYbd5KoRWuaiI1PrMspWUZU1YEk//ylgCZNeDEQlL6BAdRfL0PZWchYmR3rcqqJVTEZ1HICvhqmfwdvS5U+MfCfO7GpbgFJGDLhkbcFH8vdG0g9dQh7PKdMT+K/f8XS+CcTwLuhrkN6VV1kwvZUVETPUl20aVB+aPlD09Yi9YhxgvyWUUs6KrCDKk0cMPDinLz5ORc6cWNbguV3GvNlVDg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3484.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(52116002)(8936002)(66556008)(5660300002)(66946007)(8676002)(966005)(66476007)(7696005)(2616005)(83380400001)(186003)(6666004)(34490700002)(16526019)(54906003)(2906002)(498600001)(6486002)(4326008)(1076003)(36756003)(6916009)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: e0jnpoUfLxZanbJxAgzQ7l5WWVNOx2W7cdCM+3vr5OOPpJfvD70HPvabWiSEUWtMl6mPQ7tAsv24PnuP9MBTyez7jHLbsl76V2mN8ZnBvtHg7GObgm4K/rut2Sq92gm8ODs7AMSAJTbRmlgRkico6L+fvLpkEVi3XzAieRhADuxp68rdkvaOpmrRrcOhr8vGnQj25s3lBWGn+zm+UuFFIAZWwOXSx8WA0ouTtu3EYTtm33/mcyL+RPFivRBdEswlMnKl/EIFuxUJrDNiTkCk7pG5Bwl5WhvBDCIjmaF3Zyzw6jxAxSZTy/aZNpF/5hnvre0cSyhnDjHrL8urAkqXcfgyUhisvXfMKpBlXSs+HXEXw/G1IAqVuhGw7hChnzU1kWXbZpTWlu9qnFN7JkcdmyPgQCC8UP3LQE6WhYocPnpQyCRvM4swnI3lUmeGOqYYPtj0tHG/E2Lqkif/TH2ORCFOQh+tIgJqXS3lCQHlE82m04jbMLOc5g3X1lNl0XLJ+WWUGqNBbhCH/9UEOJGrzIX8zjdCV0nhPFYcKRNZQT8KTAy9XH+fn4nAOPjiBJhTxBnMeaDH7DeFd87rCCye26LptkgeKQ76jGUmLKgbv220dQHM4xdeHejijMs8cGzOf6mYyOaz9DjFoWSx8JKcwx+cub85ZsuGZImnWGYw9hE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e9727e4e-3d58-41bd-3dc7-08d87127fa30 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3484.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2020 16:32:59.0652 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jAOZ089u0qRcf0vTlxfX+6b3AYT6uJ+1l6YuHK1PvnVyB397hJxJZjX5MYm0X5UT5ZzTQs/kfN3o0FZzMlutJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4974 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2956 In functions ReadSaveStateRegisterByIndex and WriteSaveStateRegister: * check width > 4 instead of >=3D 4 when writing upper 32 bytes. - This improves the code but will not affect functionality. * Update related comments to better describe code. Cc: Eric Dong Cc: Ray Ni Signed-off-by: Mark Wilson --- UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmC= puDxeSmm/SmramSaveState.c index 661cc51f361a..4a872e400b7a 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c @@ -297,8 +297,8 @@ ReadSaveStateRegisterByIndex ( //=0D // Write return buffer=0D //=0D - ASSERT(CpuSaveState !=3D NULL);=0D - CopyMem(Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterInd= ex].Offset32, Width);=0D + ASSERT (CpuSaveState !=3D NULL);=0D + CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIn= dex].Offset32, Width);=0D } else {=0D //=0D // If 64-bit mode width is zero, then the specified register can not b= e accessed=0D @@ -315,14 +315,14 @@ ReadSaveStateRegisterByIndex ( }=0D =0D //=0D - // Write lower 32-bits of return buffer=0D + // Write at most 4 of the lower bytes of the return buffer=0D //=0D - CopyMem(Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterInd= ex].Offset64Lo, MIN(4, Width));=0D - if (Width >=3D 4) {=0D + CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIn= dex].Offset64Lo, MIN(4, Width));=0D + if (Width > 4) {=0D //=0D - // Write upper 32-bits of return buffer=0D + // Write at most 4 of the upper bytes of the return buffer=0D //=0D - CopyMem((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOff= set[RegisterIndex].Offset64Hi, Width - 4);=0D + CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOf= fset[RegisterIndex].Offset64Hi, Width - 4);=0D }=0D }=0D return EFI_SUCCESS;=0D @@ -522,7 +522,7 @@ WriteSaveStateRegister ( // Write SMM State register=0D //=0D ASSERT (CpuSaveState !=3D NULL);=0D - CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offs= et32, Buffer, Width);=0D + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Off= set32, Buffer, Width);=0D } else {=0D //=0D // If 64-bit mode width is zero, then the specified register can not b= e accessed=0D @@ -539,14 +539,14 @@ WriteSaveStateRegister ( }=0D =0D //=0D - // Write lower 32-bits of SMM State register=0D + // Write at most 4 of the lower bytes of SMM State register=0D //=0D - CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offs= et64Lo, Buffer, MIN (4, Width));=0D - if (Width >=3D 4) {=0D + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Off= set64Lo, Buffer, MIN (4, Width));=0D + if (Width > 4) {=0D //=0D - // Write upper 32-bits of SMM State register=0D + // Write at most 4 of the upper bytes of SMM State register=0D //=0D - CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Of= fset64Hi, (UINT8 *)Buffer + 4, Width - 4);=0D + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].O= ffset64Hi, (UINT8 *)Buffer + 4, Width - 4);=0D }=0D }=0D return EFI_SUCCESS;=0D --=20 2.27.0.windows.1