From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jordan.l.justen@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C2D4620886F49 for ; Tue, 19 Feb 2019 15:58:51 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2019 15:58:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,388,1544515200"; d="scan'208";a="144870736" Received: from mmdandap-mobl1.amr.corp.intel.com (HELO localhost) ([10.254.8.66]) by fmsmga002.fm.intel.com with ESMTP; 19 Feb 2019 15:58:50 -0800 MIME-Version: 1.0 In-Reply-To: <39b584b5-7ab8-83b4-3e44-a861a7ef6491@hpe.com> References: <20190218041141.21363-1-jordan.l.justen@intel.com> <20190218041141.21363-7-jordan.l.justen@intel.com> <155048090465.22654.1079629797155553207@jljusten-skl> <39b584b5-7ab8-83b4-3e44-a861a7ef6491@hpe.com> From: Jordan Justen Cc: Anthony Perard , "edk2-devel@lists.01.org" , Laszlo Ersek To: "Brian J. Johnson" , Ard Biesheuvel Message-ID: <155062072977.10341.3494347347839485408@jljusten-skl> User-Agent: alot/0.8 Date: Tue, 19 Feb 2019 15:58:49 -0800 Subject: Re: [PATCH 06/10] OvmfPkg/Sec: Disable optimizations for TemporaryRamMigration X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2019 23:58:52 -0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On 2019-02-19 14:50:13, Brian J. Johnson wrote: > On 2/18/19 3:32 AM, Ard Biesheuvel wrote: > > On Mon, 18 Feb 2019 at 10:08, Jordan Justen = wrote: > >> > >> On 2019-02-17 23:53:01, Ard Biesheuvel wrote: > >>> On Mon, 18 Feb 2019 at 05:12, Jordan Justen wrote: > >>>> > >>> > >>> This needs an explanation why optimization needs to be disabled. > >> > >> I'm not sure this is required. The reason I added these patches is to > >> hopefully prevent the compiler from removing the frame pointer. We > >> adjust the frame pointer in the code, and that is a little sketchy if > >> the frame pointer isn't being used. > >> > >> Unfortunately, it can reasonably be argued that the > >> TemporaryRamSupport PPI definition ultimately makes it unsafe to write > >> the migration code in C. > >> > >> I tried reverting both the EmulatorPkg and OvmfPkg patches for > >> disabling the optimizations, and with my setup there was no impact. I > >> think there is a good change that we'd be pretty safe to just drop > >> these two patches to wait and see if someone encounters a situation > >> that requires it. > >> > >> Ok, so based on this explanation, do you think I should add info to > >> the commit message and keep the patches, or just drop them? > >> > >=20 > > I think 'little sketchy' is an understatement here (as is > > setjmp/longjmp in general), but it is the reality we have to deal with > > when writing startup code in C. Looking at the code, I agree that the > > fact that [re]bp is assigned directly implies that we should not > > permit it to be used as a general purpose register, especially when > > you throw LTO into the mix, which could produce all kinds of > > surprising results when it decides to inline functions being called > > from here. > >=20 > > For GCC/Clang, I don't think it is correct to assume that changing the > > optimization level will result in -fno-omit-frame-pointer to be set, > > so I'd prefer setting that option directly, either via the pragma, or > > for the whole file. > >=20 > > For MSVC, I have no idea how to tweak the compiler to force it to emit > > frame pointers. > >=20 >=20 > https://docs.microsoft.com/en-us/cpp/build/reference/oy-frame-pointer-omi= ssion?view=3Dvs-2017 Hmm, and based on: https://docs.microsoft.com/en-us/cpp/preprocessor/optimize?view=3Dvs-2017 #pragma optimize ("", off) ...includes the "y" option. This 2nd page seems a little confused, as it documents "y" as "Generate frame pointers on the program stack", while the 1st page says "Suppresses creation of frame pointers on the call stack". I think the "suppress" is more accurate as it makes more sense that suppressing the frame pointer gives better optimization opportunities. Anyway, I think that means that `#pragma optimize ("", off)` does what we want on MSVC to force frame pointers to be used. -Jordan