From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.164059.1673867470983743988 for ; Mon, 16 Jan 2023 03:11:11 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QDTSDkIZ; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EEC4260F4D for ; Mon, 16 Jan 2023 11:11:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 618A9C433F1 for ; Mon, 16 Jan 2023 11:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673867469; bh=jLmVeoj7yOxci7LhFmZrj2oMO73nAOQUSqYLp8zl3+U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QDTSDkIZ69A/u1gi2b4TpSS+8le7BVkEXh3nNaEUQMW8wtn3IskFZVyviC3K/VOUK jh8Za/B7jid8/HtFwnSmysUBm9br12k6AKijVIdQf2xaz0HE+BXI2tyjrGN1r8QtPP QDDBZvZTVr6QMIwKVDJe/3rg39gJpDUAJfMBG6jOW8GzWXElfwihwoWk+qh/zaaeNG vzQGueTGwy3JfSN1dQvaA3cDrr4qoCzGG+T4Q0PNn9fiP9gULHd++563gEvbN5aAww fkwFIePsUm5otUYct7f6C00Rw0bPZpwH1fBzdBpYexX6jcNTTggr5ZcgtjOsqkNoEa 9Bs4AdSAZzkVA== Received: by mail-lf1-f48.google.com with SMTP id m6so42207654lfj.11 for ; Mon, 16 Jan 2023 03:11:09 -0800 (PST) X-Gm-Message-State: AFqh2krySbZEq6ncLbRiSL61h+FesPfLoBEG3KMAxOo8HPxBV7VExmPl P2MK1Ox44+5kosIv922BzifZ6Tr2MVZVRROasD0= X-Google-Smtp-Source: AMrXdXszgBlVahjYyd6Y6qTKcTFKvJmdw3Gu/5PEc9vBkcp75dD6lgb6u0jke9Apc/Ro2ZH7n/VTfEujlntLFPGogM4= X-Received: by 2002:a05:6512:15a3:b0:4bc:bdf5:f163 with SMTP id bp35-20020a05651215a300b004bcbdf5f163mr4582958lfb.583.1673867467359; Mon, 16 Jan 2023 03:11:07 -0800 (PST) MIME-Version: 1.0 References: <20230116094639.255314-1-kraxel@redhat.com> In-Reply-To: <20230116094639.255314-1-kraxel@redhat.com> From: "Ard Biesheuvel" Date: Mon, 16 Jan 2023 12:10:56 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH 1/1] ArmVirt: don't use unaligned CopyMem () on NOR flash To: devel@edk2.groups.io, kraxel@redhat.com Cc: Oliver Steffen , Leif Lindholm , Pawel Polawski , Ard Biesheuvel , Sami Mujawar Content-Type: text/plain; charset="UTF-8" On Mon, 16 Jan 2023 at 10:46, Gerd Hoffmann wrote: > > Fixes: e5ec3ba409b5 ("OvmfPkg/VirtNorFlashDxe: map flash memory as uncacheable") > Signed-off-by: Gerd Hoffmann Thanks Gerd. I'll tweak the fixes line and the commit log a bit: Commit 789a72328553 reclassified the NOR flash region as EFI_MEMORY_WC in the OS visible EFI memory map, and dropped the explicit aligned CopyMem() implementation, in the assumption that EFI_MEMORY_WC will be honored by the OS, and that the region will be mapped in a way that tolerates misaligned accesses. However, Linux today uses device attributes for all EFI MMIO regions, in spite of the memory type attributes, and so using misaligned accesses is never safe. So instead, switch to the generic CopyMem() implementation entirely, just like we already did for VariableRuntimeDxe. Fixes: 789a72328553 ("OvmfPkg/VirtNorFlashDxe: use EFI_MEMORY_WC and drop AlignedCopyMem()") > --- > ArmVirtPkg/ArmVirtKvmTool.dsc | 6 +++++- > ArmVirtPkg/ArmVirtQemu.dsc | 6 +++++- > ArmVirtPkg/ArmVirtQemuKernel.dsc | 6 +++++- > 3 files changed, 15 insertions(+), 3 deletions(-) > > diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc > index 2ba00bd08ff1..d0afe1b49e25 100644 > --- a/ArmVirtPkg/ArmVirtKvmTool.dsc > +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc > @@ -296,7 +296,11 @@ [Components.common] > NULL|ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf > } > > - OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf > + OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf { > + > + # don't use unaligned CopyMem () on the UEFI varstore NOR flash region > + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf > + } > > MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf > > diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc > index 5dd8b6104cca..0f1c6395488a 100644 > --- a/ArmVirtPkg/ArmVirtQemu.dsc > +++ b/ArmVirtPkg/ArmVirtQemu.dsc > @@ -428,7 +428,11 @@ [Components.common] > > NULL|ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf > } > - OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf > + OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf { > + > + # don't use unaligned CopyMem () on the UEFI varstore NOR flash region > + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf > + } > MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf > > # > diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc > index f5db3ac432f3..807c85d48285 100644 > --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc > +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc > @@ -331,7 +331,11 @@ [Components.common] > > NULL|ArmVirtPkg/Library/ArmVirtTimerFdtClientLib/ArmVirtTimerFdtClientLib.inf > } > - OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf > + OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf { > + > + # don't use unaligned CopyMem () on the UEFI varstore NOR flash region > + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf > + } > MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf > > # > -- > 2.39.0 > > > > > >