]> git.proxmox.com Git - mirror_edk2.git/commit
OvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop
authorArd Biesheuvel <ardb@kernel.org>
Mon, 24 Oct 2022 15:58:07 +0000 (17:58 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 27 Oct 2022 16:52:01 +0000 (16:52 +0000)
commit25589c4a76e7e3668fd6f794dd1827e958b6719c
tree35d36586176f36bd0acebb39482803fa79135478
parentca01e6216a8d1a26c69018e216d1dc3f88a819a4
OvmfPkg/VirtNorFlashDxe: avoid switching between modes in a tight loop

Currently, when dealing with small updates that can be written out
directly (i.e., if they only involve clearing bits and not setting bits,
as the latter requires a block level erase), we iterate over the data
one word at a time, read the old value, compare it, write the new value,
and repeat, unless we encountered a value that we cannot write (0->1
transition), in which case we fall back to a block level operation.

This is inefficient for two reasons:
- reading and writing a word at a time involves switching between array
and programming mode for every word of data, which is
disproportionately costly when running under KVM;
- we end up writing some data twice, as we may not notice that a block
erase is needed until after some data has been written to flash.

So replace this sequence with a single read of up to twice the buffered
write maximum size, followed by one or two buffered writes if the data
can be written directly. Otherwise, fall back to the existing block
level sequence, but without writing out part of the data twice.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
OvmfPkg/VirtNorFlashDxe/VirtNorFlash.c