From nobody Fri May 17 06:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113717+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113717+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705059486; cv=none; d=zohomail.com; s=zohoarc; b=APW+TqSoro8pTbhQxFaDKvyUiDL+yYa5x+4+gbCasV3pVcPQZkntyuYSLYGdSZty1B0d3p7/I0tl8jpN5S03OI0J0Fci8oW4hFThWNu8iQ/myeU21/qGd7IuUAiusnalKV47C/Do8jo0C09P4zjo9cOeeqVbA1xiLPOGD6egETA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705059486; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=QkZkbOnh3SODUO3T2NSUAo+yyNzVqVnXpeIc9FF9HGo=; b=Fovdeg8KCi9ZEMfV5sg9I7sr+0kkiSr09DwwQWHV0DYktRlBMMwF9WMPZwb3oRfYCh+Pjiah94NpLjaBopoMHV/BNLZV+Up3aqvqVb2oLAjMZ89CBubF5UAeMC8vNH4imdl2KE4Vzl32rB2DBhuzOmI6eGPvfPb75aeAeyoRcTU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113717+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705059486274198.77977211432164; Fri, 12 Jan 2024 03:38:06 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=+5YEFTevwlKS9b41QeVvP8kcsoC+SnlyPCnCzDNKDPE=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705059485; v=1; b=uhFLr3RdSpwqVYzHfsuWqnrKxChXqdQysNWbHqguWDXRV9Uz9FWSuADNxWSt7gHhrVkmMTZF 2X89GDZ3WGAwof2A06963S8o/9EQEcUmtCN56QvztjTiW8sI5d/crYcVRxKeizhs7ctQq/ggCJt ewAcoIqQlmQB48ZJZ6lKAPDQ= X-Received: by 127.0.0.2 with SMTP id qRxsYY1788612xX1AggV0zLs; Fri, 12 Jan 2024 03:38:05 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.5199.1705059480029729323 for ; Fri, 12 Jan 2024 03:38:00 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-5-bSU2PUXmOROv96-jlZaxWg-1; Fri, 12 Jan 2024 06:37:56 -0500 X-MC-Unique: bSU2PUXmOROv96-jlZaxWg-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EDB75106D060; Fri, 12 Jan 2024 11:37:55 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.194.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6920C1D369; Fri, 12 Jan 2024 11:37:55 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 839ECABB7E; Fri, 12 Jan 2024 12:37:54 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Laszlo Ersek , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , oliver@redhat.com Subject: [edk2-devel] [PATCH 1/4] OvmfPkg/VirtNorFlashDxe: fix shadowbuffer reads Date: Fri, 12 Jan 2024 12:37:51 +0100 Message-ID: <20240112113754.14710-2-kraxel@redhat.com> In-Reply-To: <20240112113754.14710-1-kraxel@redhat.com> References: <20240112113754.14710-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: dO1ojztdDpndRHKKPQSQEDWRx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705059488185100019 Content-Type: text/plain; charset="utf-8"; x-default="true" In some cases (specifically when the flash update region is small but crosses a multiple of P30_MAX_BUFFER_SIZE_IN_BYTES) NorFlashWriteSingleBlock reads only one instead of two P30_MAX_BUFFER_SIZE_IN_BYTES blocks into the shadow buffer. That leads to random crap being written to the second block, which in turn can corrupt both the variable store and the FTW work space. One observed corruption pattern is finding 0xaf (aka PcdDebugClearMemoryValue) right after the last entry in the FTW log. This should have been 0xff. This patch fixes the calculation. Signed-off-by: Gerd Hoffmann Reviewed-by: Ard Biesheuvel --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 1afd60ce66eb..cdc809d75e3d 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -566,7 +566,7 @@ NorFlashWriteSingleBlock ( Instance, Lba, Offset & ~BOUNDARY_OF_32_WORDS, - (*NumBytes | BOUNDARY_OF_32_WORDS) + 1, + (((Offset & BOUNDARY_OF_32_WORDS) + *NumBytes) | BOUNDARY_O= F_32_WORDS) + 1, Instance->ShadowBuffer ); if (EFI_ERROR (Status)) { --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113717): https://edk2.groups.io/g/devel/message/113717 Mute This Topic: https://groups.io/mt/103680932/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 06:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113716+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113716+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705059480; cv=none; d=zohomail.com; s=zohoarc; b=kJ6lJ81o7YPh2d2EBtkd+BXrlzmH+zje3e5Y2xnoeprryXWVY+UPibXras4rzSExozf/DfZBK9itnvJ/QslmsAD6J3mj12bsZxd1I+P5GbmKk2q02vf8OTaOpLL6JdwwLtOTxTgKz0/F5rZcb61zn6j+W2f/lyA8dDHtGAa2ZeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705059480; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=CXWFNATyGv5uu5cW6wfoKIo7iSwO+qK0RXve+8ypEZY=; b=RNAdFblwoiagaB/qOG9pAcVDRFzfUpzG1gLCHjDqXYy72Mwq8UMMMCtGEEg9CeiWg7cjWzdowtY5NMXFoCWDQXyMaO4jSdRmWvXjUmH+bPWYGu7QLSdzb73xPmm+biC4m4gmBDCTXyhcSCxJi7txccXE9WHVG+3QXMrv2sOQGNo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113716+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705059480828592.5308481645087; Fri, 12 Jan 2024 03:38:00 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=SnDbnOMz/YMPf1IblvFq31yLCKbGkYGZ2vyIaC9yOxg=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705059480; v=1; b=MFRZUxLNCHkPtkYwXaBBvFj/yFsqDXM2fte5zkIfOACNCT/w9FwEeZJzQr9YoAdqifbAvZA2 eI0kYb0mYAu7pX9nKBYSgijEABrf3OWlSqxlXOGgFweeHVZRvql0TgAK+KUHULEog7hTLq9OKYJ YEUx9dz+orD7t2Zuu10mEOP0= X-Received: by 127.0.0.2 with SMTP id 1DAcYY1788612xiqCGYkLiiG; Fri, 12 Jan 2024 03:38:00 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.5198.1705059479863286290 for ; Fri, 12 Jan 2024 03:38:00 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-0bg-FkzgPcyLJV2IxCrtxQ-1; Fri, 12 Jan 2024 06:37:57 -0500 X-MC-Unique: 0bg-FkzgPcyLJV2IxCrtxQ-1 X-Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E57C280A9AC; Fri, 12 Jan 2024 11:37:57 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.194.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26CF32166B31; Fri, 12 Jan 2024 11:37:57 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 85824ABB80; Fri, 12 Jan 2024 12:37:54 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Laszlo Ersek , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , oliver@redhat.com Subject: [edk2-devel] [PATCH 2/4] OvmfPkg/VirtNorFlashDxe: clarify block write logic Date: Fri, 12 Jan 2024 12:37:52 +0100 Message-ID: <20240112113754.14710-3-kraxel@redhat.com> In-Reply-To: <20240112113754.14710-1-kraxel@redhat.com> References: <20240112113754.14710-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: rFisOCu07QhlRatog5fgIF0Ax1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705059482275100006 Content-Type: text/plain; charset="utf-8"; x-default="true" Introduce Start and End variables to make it easier to follow the logic and code flow. Also replace the two NorFlashWriteBuffer calls with a loop containing one call. With the changes in place the code is able to handle updates larger than two P30_MAX_BUFFER_SIZE_IN_BYTES blocks, even though the patch does not actually change the size limit. Signed-off-by: Gerd Hoffmann Reviewed-by: Ard Biesheuvel --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 31 +++++++++++++------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index cdc809d75e3d..90db12716a4c 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -560,13 +560,18 @@ NorFlashWriteSingleBlock ( // If the destination bits are only changing from 1s to 0s we can just= write. // After a block is erased all bits in the block is set to 1. // If any byte requires us to erase we just give up and rewrite all of= it. + UINTN Start, End; + UINT32 Index, Count; + + Start =3D Offset & ~BOUNDARY_OF_32_WORDS; + End =3D (Offset + *NumBytes + BOUNDARY_OF_32_WORDS) & ~BOUNDARY_OF_3= 2_WORDS; =20 // Read the old version of the data into the shadow buffer Status =3D NorFlashRead ( Instance, Lba, - Offset & ~BOUNDARY_OF_32_WORDS, - (((Offset & BOUNDARY_OF_32_WORDS) + *NumBytes) | BOUNDARY_O= F_32_WORDS) + 1, + Start, + End - Start, Instance->ShadowBuffer ); if (EFI_ERROR (Status)) { @@ -599,25 +604,19 @@ NorFlashWriteSingleBlock ( goto Exit; } =20 - Status =3D NorFlashWriteBuffer ( - Instance, - BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), - P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer - ); - if (EFI_ERROR (Status)) { - goto Exit; - } - - if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) > P30_MAX_BUFFER_SIZ= E_IN_BYTES) { - BlockAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES; - + for (Index =3D 0, Count =3D (End - Start) / P30_MAX_BUFFER_SIZE_IN_BYT= ES; + Index < Count; + Index++, BlockAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES) + { Status =3D NorFlashWriteBuffer ( Instance, BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES + Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES * I= ndex ); + if (EFI_ERROR (Status)) { + goto Exit; + } } =20 Exit: --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113716): https://edk2.groups.io/g/devel/message/113716 Mute This Topic: https://groups.io/mt/103680931/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 06:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113718+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113718+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705059481; cv=none; d=zohomail.com; s=zohoarc; b=DDYuczEhE93i/mIvtUZG+A9Jcs2neVfdWGMnungVOZrw2Skzc3EPFYuG/imlyP5AkVkjpyI8DhWktaFXNiHkyXq1FAyUxP76EXm/Gffb7JCdCM2pwGQWMSVS22MiJ/RpBWAzjPsukn4bfVpfwg3Pa7aad2qGu7Kc8Cdgy4fT3nA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705059481; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ShKA22huAa3wCshnpO3xn8W5IY63nUqaYnAqjsDbNho=; b=CiugoiK16FqEpgnDtqfBvIa5NAgw1rOkk5C4klBw4DT0hbRkSyD5Kj1DQVtc9IZ4TpodxNMrp84kNebpZGqHdQsPhgPj0KWT5enP/xc5HFmTUvrsJklb894KhX/kyqDjOY1AOi6rX3uafUHKTGJtvFi4NePLXEnS89bnP6DzM/E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113718+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705059481874228.23571746989876; Fri, 12 Jan 2024 03:38:01 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=UremwZtqPIyX21qTsPDe+vBkr1WbvJgKzyOSYsUWIQI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705059481; v=1; b=fRmFJ/V4L2VZmM7YOD80vAvarUtZe6FDgVCWmJbIpOLL12fECJy7u19sISvo5g/MmqW3Sijw av7KlzjrsI/kutFB/RZneTPzfFKXROQMXG9tXLi/yLu05NRvkAsXoa7kLfILvYrzZ76ZGqw7Y/e iFn8N0vSlxxhQCHsdNZWG0rQ= X-Received: by 127.0.0.2 with SMTP id HzhCYY1788612xJHCxVWouO1; Fri, 12 Jan 2024 03:38:01 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.5236.1705059480833919809 for ; Fri, 12 Jan 2024 03:38:01 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-312-tsU0PfzlO065nKFKe6_osA-1; Fri, 12 Jan 2024 06:37:57 -0500 X-MC-Unique: tsU0PfzlO065nKFKe6_osA-1 X-Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 62BA1106D061; Fri, 12 Jan 2024 11:37:57 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.194.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 271A040C6EB9; Fri, 12 Jan 2024 11:37:57 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 87871ABB82; Fri, 12 Jan 2024 12:37:54 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Laszlo Ersek , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , oliver@redhat.com Subject: [edk2-devel] [PATCH 3/4] OvmfPkg/VirtNorFlashDxe: allow larger writes without block erase Date: Fri, 12 Jan 2024 12:37:53 +0100 Message-ID: <20240112113754.14710-4-kraxel@redhat.com> In-Reply-To: <20240112113754.14710-1-kraxel@redhat.com> References: <20240112113754.14710-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: zgxxgVvN4v7SbSmJwiAQXN4Nx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705059482276100007 Content-Type: text/plain; charset="utf-8"; x-default="true" Raise the limit for writes without block erase from two to four P30_MAX_BUFFER_SIZE_IN_BYTES blocks. With this in place almost all efi variable updates are handled without block erase. With the old limit some variable updates (with device paths) took the block erase code path. Signed-off-by: Gerd Hoffmann Reviewed-by: Ard Biesheuvel --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 90db12716a4c..c631ffd3a62d 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -555,7 +555,7 @@ NorFlashWriteSingleBlock ( // To avoid pathological cases were a 2 byte write is disregarded becaus= e it // occurs right at a 128 byte buffered write alignment boundary, permit = up to // twice the max buffer size, and perform two writes if needed. - if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) <=3D (2 * P30_MAX_BUFF= ER_SIZE_IN_BYTES)) { + if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) <=3D (4 * P30_MAX_BUFF= ER_SIZE_IN_BYTES)) { // Check to see if we need to erase before programming the data into N= OR. // If the destination bits are only changing from 1s to 0s we can just= write. // After a block is erased all bits in the block is set to 1. --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113718): https://edk2.groups.io/g/devel/message/113718 Mute This Topic: https://groups.io/mt/103680934/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 17 06:54:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113719+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113719+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705059484; cv=none; d=zohomail.com; s=zohoarc; b=Vw1orqTOb2B+GXzrfDxc1tV5xZJGidjcJI7nqxHw8ufrZNVBMKSmH65D3HO1Ji94R7EZ837lrJmEBTAQuPzPMfNHuRf80srHh4hLVDgvJobshwidUv5CMONFUgjZOgFNb7JpJZiOXXYalDQJv0A2QE41u5L4ksO5lwXJ1b3HdmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705059484; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=hzdDa1kSCEtoGvefuedj+U+hRuxgON+MjQid/CVDUXE=; b=FbsUzIq2FKpcgWdxc+8eTKI8Avmx311QMaUnH2k3XKrGSqeds6dIlTi1TudJ4hXpSXd0Dtidq3VmYeQD+N3MKLwLPxhACDlHaV7c9kOVZddLjkAqCzzOQVZVIu2tTQjcU3t8WLW0GIvgId5Nhxl84jlBC5QUzHV7Pj4ZWezVmSQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113719+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1705059484063180.83299957392796; Fri, 12 Jan 2024 03:38:04 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=nsQnUTVEV+ma+VBAUhTMcQkLklmxD7ybJ0ll0OGEQqQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705059483; v=1; b=iHENdnuryjHCFc/YpfY/jUcKlzu336q4/NXhikXxu5uUJiQ8dkafNbYJfkMhO/GEKwWVN9zB 2AldZ1e+ncCrWBOdtIGLWH1rOo9p2wg2CTnh0wLSEmwonCop24FQ2PJ/hMi6Jo0HKBH43X6l+Bi 9blM427KKRPDPbM7/9L92pp0= X-Received: by 127.0.0.2 with SMTP id ECiPYY1788612xCxYOe2CK6H; Fri, 12 Jan 2024 03:38:03 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.5239.1705059483085844652 for ; Fri, 12 Jan 2024 03:38:03 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-Nt2IqbnhPxyozPzrxSeZTw-1; Fri, 12 Jan 2024 06:37:59 -0500 X-MC-Unique: Nt2IqbnhPxyozPzrxSeZTw-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BBD273C00097; Fri, 12 Jan 2024 11:37:58 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.194.144]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C13FC1D368; Fri, 12 Jan 2024 11:37:58 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id 88FEFABB84; Fri, 12 Jan 2024 12:37:54 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Laszlo Ersek , Gerd Hoffmann , Ard Biesheuvel , Jiewen Yao , oliver@redhat.com Subject: [edk2-devel] [PATCH 4/4] OvmfPkg/VirtNorFlashDxe: ValidateFvHeader: unwritten state is EOL too Date: Fri, 12 Jan 2024 12:37:54 +0100 Message-ID: <20240112113754.14710-5-kraxel@redhat.com> In-Reply-To: <20240112113754.14710-1-kraxel@redhat.com> References: <20240112113754.14710-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Kpx3zPPrtwl0rY2c9WgpVDRtx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705059486185100015 Content-Type: text/plain; charset="utf-8"; x-default="true" It is possible to find variable entries with State being 0xff, i.e. not updated since flash block erase. This indicates the header write was not completed (and therefore State was not set to VAR_HEADER_VALID_ONLY). Treat this as additional "end of variable list" condition. Signed-off-by: Gerd Hoffmann --- OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c b/OvmfPkg/VirtNorFla= shDxe/VirtNorFlashFvb.c index 8fcd999ac6df..c8b5e0be1379 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlashFvb.c @@ -302,6 +302,11 @@ ValidateFvHeader ( break; } =20 + if (VarHeader->State =3D=3D 0xff) { + DEBUG ((DEBUG_INFO, "%a: end of var list (unwritten state)\n", __fun= c__)); + break; + } + VarName =3D NULL; switch (VarHeader->State) { // usage: State =3D VAR_HEADER_VALID_ONLY --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113719): https://edk2.groups.io/g/devel/message/113719 Mute This Topic: https://groups.io/mt/103680936/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-