From nobody Fri May 17 02:03:03 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+113828+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+113828+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705334394; cv=none; d=zohomail.com; s=zohoarc; b=jCFkNMAu/I1i5c9+8PK2CNgKCHBbWsIKyZ5pb68pWmZ7ZTBSaNpBgGKwS6aYD3jpQ1bcQxMYSWiBr7qopXNoEKFbeBX9vVzUiqpvVOXz7LgaPNK31CAAliBj4Q6N5br71RjIkMCzGRc/llWkD5vUEjojyWr8Md3SxY2o47tWD9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705334394; 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=K6NtJ5NNL50E2f5J7RYk9h+gMLJJVvhG1Ez4C/6gx7Y=; b=c3h9y2m4zd6sEajaIqOTG8+au9Khi9Ysb+JunSsEgbxeVh0N/2fmf5RaQ56HzyC1/I0qkKqweP0zVtF18jRycbkEfwYBz4lWzo2aGDk1or+y4gRUZadiMgZ7ELp452aNcknR8k/+boeHQf9CZ1viChAaCzCmlnilfCjDM/Az5Wk= 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+113828+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 1705334394774831.5357876860002; Mon, 15 Jan 2024 07:59:54 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=cxB1KpceN2JXitP38fMIOWkjiS/cshXCS8yE4WXizyU=; 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-Type:Content-Transfer-Encoding; s=20140610; t=1705334394; v=1; b=nIh4ZLp8SwL4k/yEKxDjY4J58Nitjl64ZZfUwq0WUj8jnycDEg5Tt1SOsYXZk+x4YS1NM0KM RBjyLMFsruwweCDp9I7WwV0Bb8xsKnJ8Qp1L1u87gACWX9XjyhnkM7VLaMWI6r5a27LR3UKeFPv a5BcVWUs5BtpTaQIrvZG9M7Y= X-Received: by 127.0.0.2 with SMTP id bD2YYY1788612xxnLlNKqHj0; Mon, 15 Jan 2024 07:59:54 -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.85164.1705334393569359496 for ; Mon, 15 Jan 2024 07:59:53 -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-518-ZwDFBk_dPXu8FyozHkMcBA-1; Mon, 15 Jan 2024 10:59:51 -0500 X-MC-Unique: ZwDFBk_dPXu8FyozHkMcBA-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 32484863062 for ; Mon, 15 Jan 2024 15:59:51 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.193.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EFB3140C6EB9; Mon, 15 Jan 2024 15:59:50 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id D2552AC984; Mon, 15 Jan 2024 16:59:48 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann , =?UTF-8?q?L=C3=A1szl=C3=B3=20=C3=89rsek?= Subject: [edk2-devel] [PATCH v2 1/6] OvmfPkg/VirtNorFlashDxe: add casts to UINTN and UINT32 Date: Mon, 15 Jan 2024 16:59:43 +0100 Message-ID: <20240115155948.136499-2-kraxel@redhat.com> In-Reply-To: <20240115155948.136499-1-kraxel@redhat.com> References: <20240115155948.136499-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: tL6WeTmIdDP6b6dMMShsELhCx1787277AA= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705334395919100006 This is needed to avoid bit operations being applied to signed integers. Suggested-by: L=C3=A1szl=C3=B3 =C3=89rsek Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h | 2 +- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.h index b7f5d208b236..455eafacc2cf 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.h @@ -61,7 +61,7 @@ #define P30_MAX_BUFFER_SIZE_IN_BYTES ((UINTN)128) #define P30_MAX_BUFFER_SIZE_IN_WORDS (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINT= N)4)) #define MAX_BUFFERED_PROG_ITERATIONS 10000000 -#define BOUNDARY_OF_32_WORDS 0x7F +#define BOUNDARY_OF_32_WORDS ((UINTN)0x7F) =20 // CFI Addresses #define P30_CFI_ADDR_QUERY_UNIQUE_QRY 0x10 diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 1afd60ce66eb..7f4743b00399 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -581,7 +581,7 @@ NorFlashWriteSingleBlock ( // contents, while checking whether the old version had any bits clear= ed // that we want to set. In that case, we will need to erase the block = first. for (CurOffset =3D 0; CurOffset < *NumBytes; CurOffset++) { - if (~OrigData[CurOffset] & Buffer[CurOffset]) { + if (~(UINT32)OrigData[CurOffset] & (UINT32)Buffer[CurOffset]) { goto DoErase; } =20 --=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 (#113828): https://edk2.groups.io/g/devel/message/113828 Mute This Topic: https://groups.io/mt/103741662/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 02:03:03 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+113833+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+113833+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705334399; cv=none; d=zohomail.com; s=zohoarc; b=kRpFATthw1pNSwKEjdEYFljXFPMoW1N7aCDMO/mju4ygKleHgZoc+HahZw+zV5j8cqJGDqu9ul43a7pj9BTiDdxRzHdecAQ3SZQraQ5ILJTtDmyFlVra5u3Urd1s31MVHkS2WOuErcqg9cfB+QkG5GwDay/+/ZyyVHiIcco68Ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705334399; 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=dGvEj4x11imUGPdcGotsajfxadcKACWDIXehfCvQq6A=; b=Azsq616uP3cGub1SFmOLodXN6eUVeqd7Sq2BkMhYC+IB60WCuSDyh6th6jSQ+RTrmx0Sh4OJs9Johanlb58tiEwgIDG1yEGaTXgcjG2duB5SqH40fTi+KWwznc9Ka5Xk2Un5xy9R9eS8dv/oMCDV729G+JwZMIpwyzSMIyVyanU= 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+113833+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 1705334399894628.0945282515396; Mon, 15 Jan 2024 07:59:59 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=StK1Aav6+javWogciEZFIzmL9JTWjR22lHtg+tUuPSE=; 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=1705334399; v=1; b=XApZ+ILy/jO3jYH3/vujQ+4nL0d2fnT+4Vsc5XNMreZMxbrjgQns9DBUb96XShll89lvEIXm mgYwCeIzSP8fH62UvINnltM/BCCQZpxddb2BtuZH//SB/PN1lweysJ1QWQw043rNvj7Qi0uSbDd RDJh1eHB02YIuqChzMxleGPo= X-Received: by 127.0.0.2 with SMTP id Dd97YY1788612x9Yi2g1qQHQ; Mon, 15 Jan 2024 07:59:59 -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.web11.84616.1705334398958410449 for ; Mon, 15 Jan 2024 07:59:59 -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-32-DqWPYZWdNIWSV3roUtD8KQ-1; Mon, 15 Jan 2024 10:59:51 -0500 X-MC-Unique: DqWPYZWdNIWSV3roUtD8KQ-1 X-Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 74CD5863064 for ; Mon, 15 Jan 2024 15:59:51 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.193.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25E5F492BFA; Mon, 15 Jan 2024 15:59:51 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id D35BBAC986; Mon, 15 Jan 2024 16:59:48 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 2/6] OvmfPkg/VirtNorFlashDxe: clarify block write logic & fix shadowbuffer reads Date: Mon, 15 Jan 2024 16:59:44 +0100 Message-ID: <20240115155948.136499-3-kraxel@redhat.com> In-Reply-To: <20240115155948.136499-1-kraxel@redhat.com> References: <20240115155948.136499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 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: 1zsuIS9Z86nHplmEXreaOawwx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705334401887100027 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 add a ascii art diagram (based on a suggestion by Laszlo). This also fixes the 'Size' calculation for the NorFlashRead() call. Without this patch the code will read only one instead of two P30_MAX_BUFFER_SIZE_IN_BYTES blocks in case '*NumBytes' is smaller than P30_MAX_BUFFER_SIZE_IN_BYTES but 'Offset + *NumBytes' is not, i.e. the update range crosses a P30_MAX_BUFFER_SIZE_IN_BYTES boundary. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 35 ++++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 7f4743b00399..54251633d0ee 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -520,6 +520,7 @@ NorFlashWriteSingleBlock ( UINTN BlockSize; UINTN BlockAddress; UINT8 *OrigData; + UINTN Start, End; =20 DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=3D%ld, Of= fset=3D0x%x, *NumBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes,= Buffer)); =20 @@ -555,7 +556,27 @@ 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)) { + // + // 0 128 256 + // [----------------|----------------] + // ^ ^ ^ ^ + // | | | | + // | | | End, the next "word" boundary bey= ond + // | | | the (logical) update + // | | | + // | | (Offset & 0x7F) + NumBytes; i.e., the Offset inside + // | | (or just past) the *double-word* such that Offset = is + // | | the *exclusive* end of the (logical) update. + // | | + // | Offset & BOUNDARY_OF_32_WORDS; i.e., Offset within the "= word"; + // | this is where the (logical) update is supposed to start + // | + // Start =3D Offset & ~BOUNDARY_OF_32_WORDS; i.e., Offset truncated t= o "word" boundary + + Start =3D Offset & ~BOUNDARY_OF_32_WORDS; + End =3D ALIGN_VALUE (Offset + *NumBytes, P30_MAX_BUFFER_SIZE_IN_BYTES); + + if ((End - Start) <=3D (2 * P30_MAX_BUFFER_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. @@ -565,8 +586,8 @@ NorFlashWriteSingleBlock ( Status =3D NorFlashRead ( Instance, Lba, - Offset & ~BOUNDARY_OF_32_WORDS, - (*NumBytes | BOUNDARY_OF_32_WORDS) + 1, + Start, + End - Start, Instance->ShadowBuffer ); if (EFI_ERROR (Status)) { @@ -601,7 +622,7 @@ NorFlashWriteSingleBlock ( =20 Status =3D NorFlashWriteBuffer ( Instance, - BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), + BlockAddress + Start, P30_MAX_BUFFER_SIZE_IN_BYTES, Instance->ShadowBuffer ); @@ -609,12 +630,10 @@ NorFlashWriteSingleBlock ( goto Exit; } =20 - if ((*NumBytes + (Offset & BOUNDARY_OF_32_WORDS)) > P30_MAX_BUFFER_SIZ= E_IN_BYTES) { - BlockAddress +=3D P30_MAX_BUFFER_SIZE_IN_BYTES; - + if ((End - Start) > P30_MAX_BUFFER_SIZE_IN_BYTES) { Status =3D NorFlashWriteBuffer ( Instance, - BlockAddress + (Offset & ~BOUNDARY_OF_32_WORDS), + BlockAddress + Start + P30_MAX_BUFFER_SIZE_IN_BYTES, P30_MAX_BUFFER_SIZE_IN_BYTES, Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES ); --=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 (#113833): https://edk2.groups.io/g/devel/message/113833 Mute This Topic: https://groups.io/mt/103741669/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 02:03:03 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+113829+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+113829+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705334395; cv=none; d=zohomail.com; s=zohoarc; b=KmZ4siVweS94xYcMVl1o+VbglVc4zFNwBCfXUUbHfMNmoZqmFFxRAwi0JOCmdvMgE47aS4c25yclHT8L/AW1DDTfbwAZipH/9Gd7uFAnpwwLZDW9NXxNcIkE/SMTd27byHDeQy4w9NAEzhBTYFff2j0fxLYRf8OiTOX9mCHiacQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705334395; 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=C5kJNWnXEczedaaaVd1yi2wNu7YfHWm6TGnbFRpnAtk=; b=gsJYZsltuIZOPsLVzk3Z3xTNHWjQ5FgUj5ByM0yDiJjPPY2crFnlY8x/DxrDoLJ49qbNy59aTGpLjKiAWpMJMVmHaCiELtTLmyuoEphg0UyFpqCuAvjd6fJcoTLVE2tLotfGMdh5/JGX5QeVWnQo8I83z4P0Az+V/cLS9eCcGSY= 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+113829+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 1705334395695355.5960546868969; Mon, 15 Jan 2024 07:59:55 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=jxTWsDLdT/5j9FhUlm5lCD51AAo/3/kZaLcvsRB4Sc0=; 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=1705334395; v=1; b=S+Nf51WPSOJ0z8gFDnBpqe59XMZEj3JHo40V98xq4R49Ad/JE3szOsOHrv7pKPq2/UGl+QzJ jORxXx3OeXtyE5wLpJVYdckyuVkrU+k/rTHPcB6DpQWs4QDeZNO0Y8VC4xeB0NiA3nnQWSLbgzB cnCFr0vYy9K+zaXpOWJj//So= X-Received: by 127.0.0.2 with SMTP id vPmBYY1788612xHbD4gSgGFg; Mon, 15 Jan 2024 07:59:55 -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.85165.1705334394654893281 for ; Mon, 15 Jan 2024 07:59:54 -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-677-78nU2lN9ObaJIBeNYKt3mQ-1; Mon, 15 Jan 2024 10:59:52 -0500 X-MC-Unique: 78nU2lN9ObaJIBeNYKt3mQ-1 X-Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 5394A3813F22 for ; Mon, 15 Jan 2024 15:59:52 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.193.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 257BF1121306; Mon, 15 Jan 2024 15:59:52 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id D4FFAAC988; Mon, 15 Jan 2024 16:59:48 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 3/6] OvmfPkg/VirtNorFlashDxe: add a loop for NorFlashWriteBuffer calls. Date: Mon, 15 Jan 2024 16:59:45 +0100 Message-ID: <20240115155948.136499-4-kraxel@redhat.com> In-Reply-To: <20240115155948.136499-1-kraxel@redhat.com> References: <20240115155948.136499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 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: dNtVMy91qgrA7D6xR8ElB9nXx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705334397818100013 Content-Type: text/plain; charset="utf-8"; x-default="true" Replace the two NorFlashWriteBuffer() calls with a loop containing a single NorFlashWriteBuffer() 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: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 54251633d0ee..67610d6920f7 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -521,6 +521,7 @@ NorFlashWriteSingleBlock ( UINTN BlockAddress; UINT8 *OrigData; UINTN Start, End; + UINT32 Index, Count; =20 DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=3D%ld, Of= fset=3D0x%x, *NumBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes,= Buffer)); =20 @@ -620,23 +621,17 @@ NorFlashWriteSingleBlock ( goto Exit; } =20 - Status =3D NorFlashWriteBuffer ( - Instance, - BlockAddress + Start, - P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer - ); - if (EFI_ERROR (Status)) { - goto Exit; - } - - if ((End - Start) > P30_MAX_BUFFER_SIZE_IN_BYTES) { + Count =3D (End - Start) / P30_MAX_BUFFER_SIZE_IN_BYTES; + for (Index =3D 0; Index < Count; Index++) { Status =3D NorFlashWriteBuffer ( Instance, - BlockAddress + Start + P30_MAX_BUFFER_SIZE_IN_BYTES, + BlockAddress + Start + Index * P30_MAX_BUFFER_SIZE_IN_BYT= ES, P30_MAX_BUFFER_SIZE_IN_BYTES, - Instance->ShadowBuffer + P30_MAX_BUFFER_SIZE_IN_BYTES + Instance->ShadowBuffer + Index * P30_MAX_BUFFER_SIZE_IN_B= YTES ); + 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 (#113829): https://edk2.groups.io/g/devel/message/113829 Mute This Topic: https://groups.io/mt/103741663/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 02:03:03 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+113830+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+113830+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705334396; cv=none; d=zohomail.com; s=zohoarc; b=MpjI5JRLOLyJ2fif2ZGOJEJKY/vUFHNNMos4Oasou4LtushHYeqUq12UnFMZiUrRAfKp+1OFNrvshMlgNAzqOsczLoONIbIxoKbOd/aaQ33BZZ9jNMnxTVv0Ts+zIMh+7lI9jcYCrFE8HsUbU6shiSHKgInAk8meqSc0Ecgpz0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705334396; 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=Buf2Uu3nZmJhTAWsdnnIHK6TXj+lP9yVXYvQGtsIq0E=; b=RueEXskkLyqJfFzhWv5R9b/NmoL8Jsq14x6wYXXM3hkDD7xLp2146gQ2mrzoEjqzVbthv4mX5C/AbRDJSoh0YZaZY5EJjBO7lznE4pd/ChnBBCc/eNHZki7g2oJMkUjQfpSl1IadJ3+1Hu4T4E4lqLjnA21G29auWQ3jdPRsca0= 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+113830+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 1705334396140634.980050241987; Mon, 15 Jan 2024 07:59:56 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wCMcJaFVMciKph5Fnggi6qptwtngix0lmSSyZzDx4ME=; 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=1705334395; v=1; b=tPey/8XBlBhGW8XHQlxM0VAe39/M3jeiceY3j7iylwTANWnnSAgZx70q8BSBIS0v/EyzaTYp mgEXS8etGcJcV81pFLC87czummCL4r87IDTochA5678rP2zKXY40Ub7IQoqhz76DU/cTgHf4zIx Mb/h6rtjFDX5dJVDVu5QnCMo= X-Received: by 127.0.0.2 with SMTP id ZDrVYY1788612xLwEiSLdG93; Mon, 15 Jan 2024 07:59:55 -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.84613.1705334394909481221 for ; Mon, 15 Jan 2024 07:59:55 -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-677-ZUezoRaMM7ipFvJTouS9fA-1; Mon, 15 Jan 2024 10:59:52 -0500 X-MC-Unique: ZUezoRaMM7ipFvJTouS9fA-1 X-Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 95CB98371C9 for ; Mon, 15 Jan 2024 15:59:52 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.193.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 67585107BE; Mon, 15 Jan 2024 15:59:52 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id D6AA3AC98A; Mon, 15 Jan 2024 16:59:48 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 4/6] OvmfPkg/VirtNorFlashDxe: allow larger writes without block erase Date: Mon, 15 Jan 2024 16:59:46 +0100 Message-ID: <20240115155948.136499-5-kraxel@redhat.com> In-Reply-To: <20240115155948.136499-1-kraxel@redhat.com> References: <20240115155948.136499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: YxNQQvKr909tc5A0f1TDglAfx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705334397826100014 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: Laszlo Ersek --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index 67610d6920f7..d80e9f0a2f3a 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -550,13 +550,15 @@ NorFlashWriteSingleBlock ( return EFI_BAD_BUFFER_SIZE; } =20 - // Pick P30_MAX_BUFFER_SIZE_IN_BYTES (=3D=3D 128 bytes) as a good start = for word - // operations as opposed to erasing the block and writing the data regar= dless - // if an erase is really needed. It looks like most individual NV varia= ble - // writes are smaller than 128 bytes. - // 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. + // Pick 4 * P30_MAX_BUFFER_SIZE_IN_BYTES (=3D=3D 512 bytes) as a good + // start for word operations as opposed to erasing the block and + // writing the data regardless if an erase is really needed. + // + // Many NV variable updates are small enough for a a single + // P30_MAX_BUFFER_SIZE_IN_BYTES block write. In case the update is + // larger than a single block, or the update crosses a + // P30_MAX_BUFFER_SIZE_IN_BYTES boundary (as shown in the diagram + // below), or both, we might have to write two or more blocks. // // 0 128 256 // [----------------|----------------] @@ -577,7 +579,7 @@ NorFlashWriteSingleBlock ( Start =3D Offset & ~BOUNDARY_OF_32_WORDS; End =3D ALIGN_VALUE (Offset + *NumBytes, P30_MAX_BUFFER_SIZE_IN_BYTES); =20 - if ((End - Start) <=3D (2 * P30_MAX_BUFFER_SIZE_IN_BYTES)) { + if ((End - Start) <=3D (4 * P30_MAX_BUFFER_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 (#113830): https://edk2.groups.io/g/devel/message/113830 Mute This Topic: https://groups.io/mt/103741664/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 02:03:03 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+113832+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+113832+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705334397; cv=none; d=zohomail.com; s=zohoarc; b=fg1iyojtliwCp5ZaBSQUCfUTldznhGGu3liLw+41L/JDhsf1TFHXjmMB7aYS1b8G8CDY3bu4U4Y8XGaBj91neJn2YBOw7TqJTiKtR/xtVfEIQbSIPOFRejgo9hGrQ8TBsDT7BOR88ZXoYX8eCrmfWYix2rHb/A8QR3RXTwOCBmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705334397; 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=hvjKRY735S6xXU3b9/oCynIrz9arxzc/eGeBZPzw2qQ=; b=GofBMdvgDWXvkhfZz7Enl0mMc6ajETXyGGMLKLCRnDfAfo3vHp/gVi7y3ANXt41rFrpLQOjr64qXt4AOK9AsbQp49TcgZL3Rdh5vmyP9PPu97/uGwVcaYH9C/qTt1/olmn+uEQVX6JyqKFPtHKnc3K6sm9l6ZsQbIsGqXYSs7Nk= 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+113832+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 1705334397532170.5392234215268; Mon, 15 Jan 2024 07:59:57 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=CeKMslpW8wGx+2P67A3hJcaRIXFDAPxC3f6U1z12XZo=; 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=1705334397; v=1; b=bGMJZZKoJPzznx1POqp/9fNqC/ftLeNf364wMNpG9zkwMl6hCV3yGck2yE37DMkfiATdAGyn onUhAOe4GwCS/9GqdCFHVzx1Lz108sX7OUtCBX0OdP3f/aCXQYk0JxNIYUbavEgmQ4+oFrlgJ8a Nh7riMan+wQT7VADCbsi3vF4= X-Received: by 127.0.0.2 with SMTP id 0IDHYY1788612xvcPIhy6Lyr; Mon, 15 Jan 2024 07:59:57 -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.85167.1705334396500369058 for ; Mon, 15 Jan 2024 07:59:56 -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-368-uZu5w3ErMIqzteTYo8KscQ-1; Mon, 15 Jan 2024 10:59:53 -0500 X-MC-Unique: uZu5w3ErMIqzteTYo8KscQ-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 7B19E3C0EAD0 for ; Mon, 15 Jan 2024 15:59:53 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.193.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4546E1C060B2; Mon, 15 Jan 2024 15:59:53 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id D851FAC98C; Mon, 15 Jan 2024 16:59:48 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 5/6] OvmfPkg/VirtNorFlashDxe: ValidateFvHeader: unwritten state is EOL too Date: Mon, 15 Jan 2024 16:59:47 +0100 Message-ID: <20240115155948.136499-6-kraxel@redhat.com> In-Reply-To: <20240115155948.136499-1-kraxel@redhat.com> References: <20240115155948.136499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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: alROtbXcSUq8OxUMQBTXUdjux1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705334399808100023 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 variable driver could not complete the header write while appending a new entry, and therefore State was not set to VAR_HEADER_VALID_ONLY. This can only happen at the end of the variable list, so treat this as additional "end of variable list" condition. Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- 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 (#113832): https://edk2.groups.io/g/devel/message/113832 Mute This Topic: https://groups.io/mt/103741666/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 02:03:03 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+113831+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+113831+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705334397; cv=none; d=zohomail.com; s=zohoarc; b=RxPhffJp2AzmEktsr9xwOAXSOWC2Dn8U1gBtv84fNpUHXP8fpt2fvoMuXAeqQgrMhPHP52WK2upsVPGFjqekeGikoDn0Ce5SIhQoppyh6bg859p2v+KX+dojEGqWDC+2ALmA/7xFZTt7Bo3ELQnK5Y9UCD+w76Tr1ZC5q0WhJmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705334397; 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=+MSexDa7L8nTZ+NWhpkfEQsOFqjZ/k67PNwzFJegEzo=; b=dpuoC78UuBOclUHaQa1wECjolw4urbyFSedDJYkkrQrAKRAU1h4bryKYu80M69f4jC4S3OnIF7Nre4iF6ectg16Hu1dBPjNEe4orfnvSabiY9q6+0S2y0C8GFLignV+F5z/LbsbYLFjR0/EgxpUJXgPfjR9o0rlJ9FZ/hYIkn5s= 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+113831+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 1705334397090940.1687622266782; Mon, 15 Jan 2024 07:59:57 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=51C49LELlUGE3lBIdNftO0ETQsDdYCmlo0Le+Ccar9M=; 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=1705334396; v=1; b=DRuPuiw02N6B/waGc5AMqNBDkTAiv+pYwU2fWL+/9KgT75rBDB0d0K0rdN1kaaVLocQnacpJ zBwuluvYsalYWRVNLklOWpiz9EU+D6FSz7fCGIvE77li5I4hDcOGrcUgGAXpAgmo4b4CMsu80fG DUCWqKB9xfK019nBiaYbcjV4= X-Received: by 127.0.0.2 with SMTP id 0i5oYY1788612xQ6IsGIrmtF; Mon, 15 Jan 2024 07:59:56 -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.web11.84614.1705334396086788396 for ; Mon, 15 Jan 2024 07:59:56 -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-368-ZtkD2ZVyOz2sE7NNdwTP0w-1; Mon, 15 Jan 2024 10:59:53 -0500 X-MC-Unique: ZtkD2ZVyOz2sE7NNdwTP0w-1 X-Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 B289C185A781 for ; Mon, 15 Jan 2024 15:59:53 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.193.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 872F2107BE; Mon, 15 Jan 2024 15:59:53 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id D9E99AC98E; Mon, 15 Jan 2024 16:59:48 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: oliver@redhat.com, Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 6/6] OvmfPkg/VirtNorFlashDxe: move DoErase code block into new function Date: Mon, 15 Jan 2024 16:59:48 +0100 Message-ID: <20240115155948.136499-7-kraxel@redhat.com> In-Reply-To: <20240115155948.136499-1-kraxel@redhat.com> References: <20240115155948.136499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: R7Nebv8zGUhVeMvi3VSECP2ux1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1705334397832100015 Content-Type: text/plain; charset="utf-8"; x-default="true" Move the DoErase code block into a separate function, call the function instead of jumping around with goto. Signed-off-by: Gerd Hoffmann --- OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 76 +++++++++++++++++--------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashD= xe/VirtNorFlash.c index d80e9f0a2f3a..203bd64f2bdf 100644 --- a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c +++ b/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c @@ -502,6 +502,37 @@ NorFlashRead ( return EFI_SUCCESS; } =20 +STATIC EFI_STATUS +NorFlashWriteSingleBlockWithErase ( + IN NOR_FLASH_INSTANCE *Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + EFI_STATUS Status; + + // Read NOR Flash data into shadow buffer + Status =3D NorFlashReadBlocks (Instance, Lba, Instance->BlockSize, Insta= nce->ShadowBuffer); + if (EFI_ERROR (Status)) { + // Return one of the pre-approved error statuses + return EFI_DEVICE_ERROR; + } + + // Put the data at the appropriate location inside the buffer area + CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumB= ytes); + + // Write the modified buffer back to the NorFlash + Status =3D NorFlashWriteBlocks (Instance, Lba, Instance->BlockSize, Inst= ance->ShadowBuffer); + if (EFI_ERROR (Status)) { + // Return one of the pre-approved error statuses + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} + /* Write a full or portion of a block. It must not span block boundaries; t= hat is, Offset + *NumBytes <=3D Instance->BlockSize. @@ -606,7 +637,14 @@ NorFlashWriteSingleBlock ( // that we want to set. In that case, we will need to erase the block = first. for (CurOffset =3D 0; CurOffset < *NumBytes; CurOffset++) { if (~(UINT32)OrigData[CurOffset] & (UINT32)Buffer[CurOffset]) { - goto DoErase; + Status =3D NorFlashWriteSingleBlockWithErase ( + Instance, + Lba, + Offset, + NumBytes, + Buffer + ); + goto Exit; } =20 OrigData[CurOffset] =3D Buffer[CurOffset]; @@ -635,33 +673,21 @@ NorFlashWriteSingleBlock ( goto Exit; } } + } else { + Status =3D NorFlashWriteSingleBlockWithErase ( + Instance, + Lba, + Offset, + NumBytes, + Buffer + ); + } =20 Exit: - // Put device back into Read Array mode - SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); + // Put device back into Read Array mode + SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY); =20 - return Status; - } - -DoErase: - // Read NOR Flash data into shadow buffer - Status =3D NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->Shado= wBuffer); - if (EFI_ERROR (Status)) { - // Return one of the pre-approved error statuses - return EFI_DEVICE_ERROR; - } - - // Put the data at the appropriate location inside the buffer area - CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumB= ytes); - - // Write the modified buffer back to the NorFlash - Status =3D NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->Shad= owBuffer); - if (EFI_ERROR (Status)) { - // Return one of the pre-approved error statuses - return EFI_DEVICE_ERROR; - } - - return EFI_SUCCESS; + return Status; } =20 EFI_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 (#113831): https://edk2.groups.io/g/devel/message/113831 Mute This Topic: https://groups.io/mt/103741665/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-