From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.2535.1603130800967567639 for ; Mon, 19 Oct 2020 11:06:41 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GvkoOEK8; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603130800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9NqgDYq3wngukOQFXsrqBc+/Dz/w8gJWwlvTvqaXnHQ=; b=GvkoOEK8AEgm3S41lyxI8bFdO8wLs4XF82RnOElbLrNdVVn9gNtbePNiVg2oUF8FDWuOtb W+roxHaxoa+vjsRSqJbO809dTFxQdDwwHamPnJ5ztOREAUPKIy23OflaNPWldPnRbM8pOJ KV6NJ55+3/ZmrsYlwivXpek/hbX8kyI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-b48M5voxPniPGnpC4GMROA-1; Mon, 19 Oct 2020 14:06:37 -0400 X-MC-Unique: b48M5voxPniPGnpC4GMROA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77546AF9A4; Mon, 19 Oct 2020 18:06:36 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-137.ams2.redhat.com [10.36.113.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 514B96EF42; Mon, 19 Oct 2020 18:06:35 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v1 1/1] UefiCpuPkg: Clean up save state boundary checks and comments. From: "Laszlo Ersek" To: devel@edk2.groups.io, Mark.Wilson@amd.com Cc: Eric Dong , Ray Ni References: <20201015163243.364-1-Mark.Wilson@amd.com> <20201015163243.364-2-Mark.Wilson@amd.com> Message-ID: Date: Mon, 19 Oct 2020 20:06:34 +0200 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 10/19/20 20:03, Laszlo Ersek wrote: > Hi Mark, > > On 10/15/20 18:32, Mark Wilson wrote: >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2956 >> >> In functions ReadSaveStateRegisterByIndex and WriteSaveStateRegister: >> * check width > 4 instead of >= 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(-) > > I suggest separating the cosmetic changes (such as the whitespace fixes) > from the cleanups (comments etc) to different patches. > > Also, please run "BaseTools/Scripts/SetupGit.py" in your edk2 clone. Furthermore, I suggest a bit more specific subject: UefiCpuPkg/PiSmmCpuDxeSmm: clean up save state boundary checks and comments (I think this subject length, i.e. 75 characters, should still satisfy "PatchCheck.py".) Sorry about the piecemeal observations; trying to deal with a bit of a backlog. Thanks Laszlo >> >> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c >> index 661cc51f361a..4a872e400b7a 100644 >> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c >> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c >> @@ -297,8 +297,8 @@ ReadSaveStateRegisterByIndex ( >> // >> >> // Write return buffer >> >> // >> >> - ASSERT(CpuSaveState != NULL); >> >> - CopyMem(Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Width); >> >> + ASSERT (CpuSaveState != NULL); >> >> + CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Width); >> >> } else { >> >> // >> >> // If 64-bit mode width is zero, then the specified register can not be accessed >> >> @@ -315,14 +315,14 @@ ReadSaveStateRegisterByIndex ( >> } >> >> >> >> // >> >> - // Write lower 32-bits of return buffer >> >> + // Write at most 4 of the lower bytes of the return buffer >> >> // >> >> - CopyMem(Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, MIN(4, Width)); >> >> - if (Width >= 4) { >> >> + CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, MIN(4, Width)); >> >> + if (Width > 4) { >> >> // >> >> - // Write upper 32-bits of return buffer >> >> + // Write at most 4 of the upper bytes of the return buffer >> >> // >> >> - CopyMem((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4); >> >> + CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4); >> >> } >> >> } >> >> return EFI_SUCCESS; >> >> @@ -522,7 +522,7 @@ WriteSaveStateRegister ( >> // Write SMM State register >> >> // >> >> ASSERT (CpuSaveState != NULL); >> >> - CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Buffer, Width); >> >> + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Buffer, Width); >> >> } else { >> >> // >> >> // If 64-bit mode width is zero, then the specified register can not be accessed >> >> @@ -539,14 +539,14 @@ WriteSaveStateRegister ( >> } >> >> >> >> // >> >> - // Write lower 32-bits of SMM State register >> >> + // Write at most 4 of the lower bytes of SMM State register >> >> // >> >> - CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, Buffer, MIN (4, Width)); >> >> - if (Width >= 4) { >> >> + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, Buffer, MIN (4, Width)); >> >> + if (Width > 4) { >> >> // >> >> - // Write upper 32-bits of SMM State register >> >> + // Write at most 4 of the upper bytes of SMM State register >> >> // >> >> - CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, (UINT8 *)Buffer + 4, Width - 4); >> >> + CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, (UINT8 *)Buffer + 4, Width - 4); >> >> } >> >> } >> >> return EFI_SUCCESS; >> >