From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1DAC0D81164 for ; Fri, 12 Jan 2024 11:26:16 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Dhds0UMcc6OgXmwpgTV8yAvEa84hv5YUb5aPZPQVkhc=; c=relaxed/simple; d=groups.io; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Disposition; s=20140610; t=1705058775; v=1; b=n7sKWnsNC5xhD9PbXYHFjkLASHnQ+Pf6VcKkiksJBqOufW/MV9/Xo2Rc4SbWyrTpxZ4KI0n6 Ijn4/tDQbEx2sPxMgx7+dGUW+sefC9Avy1MiywoSIEJNXKO4BXm2V3gIQ2KBo2+FczerRPvcY0B 8b0v9se7yoPw3Md7xUEwHkrs= X-Received: by 127.0.0.2 with SMTP id 9iSQYY7687511xdD4i93dUVn; Fri, 12 Jan 2024 03:26:15 -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.5046.1705058775188568584 for ; Fri, 12 Jan 2024 03:26:15 -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-422-wpx_QBwpP4SdPATizijolQ-1; Fri, 12 Jan 2024 06:26:12 -0500 X-MC-Unique: wpx_QBwpP4SdPATizijolQ-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 827D1106D060; Fri, 12 Jan 2024 11:26:12 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.233]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54D393C25; Fri, 12 Jan 2024 11:26:12 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1E27D180079A; Fri, 12 Jan 2024 12:26:11 +0100 (CET) Date: Fri, 12 Jan 2024 12:26:11 +0100 From: "Gerd Hoffmann" To: Laszlo Ersek Cc: devel@edk2.groups.io, oliver@redhat.com, Jiewen Yao , Ard Biesheuvel Subject: Re: [edk2-devel] [PATCH 1/1] OvmfPkg/VirtNorFlashDxe: fix shadowbuffer reads Message-ID: References: <20240111133627.156839-1-kraxel@redhat.com> <0ccd39db-ce5c-e7c7-192e-d67f939b5dad@redhat.com> MIME-Version: 1.0 In-Reply-To: <0ccd39db-ce5c-e7c7-192e-d67f939b5dad@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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: aeWdc62J62Qm4vHrXM5bFGkxx7686176AA= Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=n7sKWnsN; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none) On Fri, Jan 12, 2024 at 10:47:43AM +0100, Laszlo Ersek wrote: > On 1/11/24 14:36, Gerd Hoffmann wrote: > > 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. > > > > This patch fixes the calculation. > > > > Signed-off-by: Gerd Hoffmann > > --- > > OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c b/OvmfPkg/VirtNorFlashDxe/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_OF_32_WORDS) + 1, > > Instance->ShadowBuffer > > ); > > if (EFI_ERROR (Status)) { > > This patch looks like the output of an excellent bug analysis. I'll need > more time to review this. If you have a ticket with the analysis > captured (actual numbers, debugging logs, a concrete backtrace / call > chain triggering the issue, etc), I'd appreciate a reference. Yea, that was a few days browsing through the flash and Ftw code, sprinkling in debug logging, learning how all this works. Have a shell script resetting a VM in a loop with slowly increasing delay, to trigger the code paths recovering from interrupted flash writes. Finding 0xaf (aka PcdDebugClearMemoryValue) in not-yet used places of the ftw log (which should have been 0xff) was the bit of information which finally made me find the root cause of the flash corruption. I have some followup patches I'll send out as patch series in a moment, one of them adds variables here to make the whole logic easier to understand. stay tuned & take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113711): https://edk2.groups.io/g/devel/message/113711 Mute This Topic: https://groups.io/mt/103661868/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-