From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 22D6C208AE9B7 for ; Mon, 11 Feb 2019 06:27:28 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2019 06:27:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,358,1544515200"; d="scan'208";a="114019727" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga007.jf.intel.com with ESMTP; 11 Feb 2019 06:27:27 -0800 Received: from fmsmsx156.amr.corp.intel.com (10.18.116.74) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 11 Feb 2019 06:27:27 -0800 Received: from shsmsx154.ccr.corp.intel.com (10.239.6.54) by fmsmsx156.amr.corp.intel.com (10.18.116.74) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 11 Feb 2019 06:27:27 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX154.ccr.corp.intel.com ([169.254.7.232]) with mapi id 14.03.0415.000; Mon, 11 Feb 2019 22:27:25 +0800 From: "Gao, Liming" To: Ard Biesheuvel , "edk2-devel@lists.01.org" CC: "leif.lindholm@linaro.org" , "Kinney, Michael D" Thread-Topic: [PATCH] MdePkg/BaseLib: implement SpeculationBarrier() for ARM and AArch64 Thread-Index: AQHUvbAdFtk/4Bn2IEGhsDUn5RO+yKXasCsQ Date: Mon, 11 Feb 2019 14:27:25 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3DB058@SHSMSX104.ccr.corp.intel.com> References: <20190206000822.577-1-ard.biesheuvel@linaro.org> In-Reply-To: <20190206000822.577-1-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDlkODQ0ZDAtNzM1ZC00MjI2LTlmNmYtYWNlNDk2ZWFiMTJlIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiaVV2Rk9qcmxLNzdXcCtIa1IwTkp5VUhCK002cUJHN3pLKytrbDdsVFhxWk10ZGI1YXA0YlU5ZlpaS2lnNldmOSJ9 dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdePkg/BaseLib: implement SpeculationBarrier() for ARM and AArch64 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: Mon, 11 Feb 2019 14:27:29 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ard: I have no comments on this patch. Reviewed-by: Liming Gao > -----Original Message----- > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] > Sent: Wednesday, February 6, 2019 8:08 AM > To: edk2-devel@lists.01.org > Cc: leif.lindholm@linaro.org; Gao, Liming ; Kinney,= Michael D ; Ard Biesheuvel > > Subject: [PATCH] MdePkg/BaseLib: implement SpeculationBarrier() for ARM a= nd AArch64 >=20 > Replace the dummy C implementation of SpeculationBarrier() with > implementations consisting of the recommended DSB SY + ISB sequence, > as recommended by ARM in the whitepaper "Cache Speculation Side-channels" > version 2.4, dated October 2018. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel > --- > MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S | 39 +++++++++++++= +++++++ > MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.asm | 38 +++++++++++++= ++++++ > MdePkg/Library/BaseLib/Arm/SpeculationBarrier.S | 39 +++++++++++++= +++++++ > MdePkg/Library/BaseLib/Arm/SpeculationBarrier.asm | 39 +++++++++++++= +++++++ > MdePkg/Library/BaseLib/Arm/SpeculationBarrier.c | 30 -------------= -- > MdePkg/Library/BaseLib/BaseLib.inf | 7 +++- > 6 files changed, 160 insertions(+), 32 deletions(-) >=20 > diff --git a/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S b/MdePkg= /Library/BaseLib/AArch64/SpeculationBarrier.S > new file mode 100644 > index 000000000000..500bdadca5d2 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S > @@ -0,0 +1,39 @@ > +##----------------------------------------------------------------------= -------- > +# > +# SpeculationBarrier() for AArch64 > +# > +# Copyright (c) 2019, Linaro Ltd. All rights reserved. > +# > +# This program and the accompanying materials > +# are licensed and made available under the terms and conditions of the = BSD License > +# which accompanies this distribution. The full text of the license may= be found at > +# http://opensource.org/licenses/bsd-license.php. > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR I= MPLIED. > +# > +##----------------------------------------------------------------------= -------- > + > +.text > +.p2align 2 > + > +GCC_ASM_EXPORT(SpeculationBarrier) > + > + > +#/** > +# Uses as a barrier to stop speculative execution. > +# > +# Ensures that no later instruction will execute speculatively, until a= ll prior > +# instructions have completed. > +# > +#**/ > +#VOID > +#EFIAPI > +#SpeculationBarrier ( > +# VOID > +# ); > +# > +ASM_PFX(SpeculationBarrier): > + dsb sy > + isb > + ret > diff --git a/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.asm b/MdeP= kg/Library/BaseLib/AArch64/SpeculationBarrier.asm > new file mode 100644 > index 000000000000..0c4b915b7798 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.asm > @@ -0,0 +1,38 @@ > +;-----------------------------------------------------------------------= ------- > +; > +; SpeculationBarrier() for AArch64 > +; > +; Copyright (c) 2019, Linaro Ltd. All rights reserved. > +; > +; This program and the accompanying materials > +; are licensed and made available under the terms and conditions of the = BSD License > +; which accompanies this distribution. The full text of the license may= be found at > +; http://opensource.org/licenses/bsd-license.php. > +; > +; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR I= MPLIED. > +; > +;-----------------------------------------------------------------------= ------- > + > + EXPORT SpeculationBarrier > + AREA BaseLib_LowLevel, CODE, READONLY > + > +;/** > +; Uses as a barrier to stop speculative execution. > +; > +; Ensures that no later instruction will execute speculatively, until a= ll prior > +; instructions have completed. > +; > +;**/ > +;VOID > +;EFIAPI > +;SpeculationBarrier ( > +; VOID > +; ); > +; > +SpeculationBarrier > + dsb sy > + isb > + ret > + > + END > diff --git a/MdePkg/Library/BaseLib/Arm/SpeculationBarrier.S b/MdePkg/Lib= rary/BaseLib/Arm/SpeculationBarrier.S > new file mode 100644 > index 000000000000..7857558aba17 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/Arm/SpeculationBarrier.S > @@ -0,0 +1,39 @@ > +##----------------------------------------------------------------------= -------- > +# > +# SpeculationBarrier() for AArch64 > +# > +# Copyright (c) 2019, Linaro Ltd. All rights reserved. > +# > +# This program and the accompanying materials > +# are licensed and made available under the terms and conditions of the = BSD License > +# which accompanies this distribution. The full text of the license may= be found at > +# http://opensource.org/licenses/bsd-license.php. > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR I= MPLIED. > +# > +##----------------------------------------------------------------------= -------- > + > +.text > +.p2align 2 > + > +GCC_ASM_EXPORT(SpeculationBarrier) > + > + > +#/** > +# Uses as a barrier to stop speculative execution. > +# > +# Ensures that no later instruction will execute speculatively, until a= ll prior > +# instructions have completed. > +# > +#**/ > +#VOID > +#EFIAPI > +#SpeculationBarrier ( > +# VOID > +# ); > +# > +ASM_PFX(SpeculationBarrier): > + dsb > + isb > + bx lr > diff --git a/MdePkg/Library/BaseLib/Arm/SpeculationBarrier.asm b/MdePkg/L= ibrary/BaseLib/Arm/SpeculationBarrier.asm > new file mode 100644 > index 000000000000..425cd3de9e22 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/Arm/SpeculationBarrier.asm > @@ -0,0 +1,39 @@ > +;-----------------------------------------------------------------------= ------- > +; > +; SpeculationBarrier() for AArch64 > +; > +; Copyright (c) 2019, Linaro Ltd. All rights reserved. > +; > +; This program and the accompanying materials > +; are licensed and made available under the terms and conditions of the = BSD License > +; which accompanies this distribution. The full text of the license may= be found at > +; http://opensource.org/licenses/bsd-license.php. > +; > +; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR I= MPLIED. > +; > +;-----------------------------------------------------------------------= ------- > + > + EXPORT SpeculationBarrier > + > + AREA MemoryBarriers, CODE, READONLY > + > +;/** > +; Uses as a barrier to stop speculative execution. > +; > +; Ensures that no later instruction will execute speculatively, until a= ll prior > +; instructions have completed. > +; > +;**/ > +;VOID > +;EFIAPI > +;SpeculationBarrier ( > +; VOID > +; ); > +; > +SpeculationBarrier > + dsb > + isb > + bx lr > + > + END > diff --git a/MdePkg/Library/BaseLib/Arm/SpeculationBarrier.c b/MdePkg/Lib= rary/BaseLib/Arm/SpeculationBarrier.c > deleted file mode 100644 > index 8a6165a10227..000000000000 > --- a/MdePkg/Library/BaseLib/Arm/SpeculationBarrier.c > +++ /dev/null > @@ -1,30 +0,0 @@ > -/** @file > - SpeculationBarrier() function for ARM. > - > - Copyright (C) 2018, Intel Corporation. All rights reserved.
> - > - This program and the accompanying materials are licensed and made avai= lable > - under the terms and conditions of the BSD License which accompanies th= is > - distribution. The full text of the license may be found at > - http://opensource.org/licenses/bsd-license.php. > - > - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, = WITHOUT > - WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > - > -**/ > - > - > -/** > - Uses as a barrier to stop speculative execution. > - > - Ensures that no later instruction will execute speculatively, until al= l prior > - instructions have completed. > - > -**/ > -VOID > -EFIAPI > -SpeculationBarrier ( > - VOID > - ) > -{ > -} > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/= BaseLib.inf > index d195c5417b2e..f25a067a2335 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -552,7 +552,6 @@ > [Sources.ARM] > Arm/InternalSwitchStack.c > Arm/Unaligned.c > - Arm/SpeculationBarrier.c > Math64.c | RVCT > Math64.c | MSFT >=20 > @@ -564,6 +563,7 @@ > Arm/CpuPause.asm | RVCT > Arm/CpuBreakpoint.asm | RVCT > Arm/MemoryFence.asm | RVCT > + Arm/SpeculationBarrier.S | RVCT >=20 > Arm/SwitchStack.asm | MSFT > Arm/SetJumpLongJump.asm | MSFT > @@ -573,6 +573,7 @@ > Arm/CpuPause.asm | MSFT > Arm/CpuBreakpoint.asm | MSFT > Arm/MemoryFence.asm | MSFT > + Arm/SpeculationBarrier.asm | MSFT >=20 > Arm/Math64.S | GCC > Arm/SwitchStack.S | GCC > @@ -582,11 +583,11 @@ > Arm/SetJumpLongJump.S | GCC > Arm/CpuBreakpoint.S | GCC > Arm/MemoryFence.S | GCC > + Arm/SpeculationBarrier.S | GCC >=20 > [Sources.AARCH64] > Arm/InternalSwitchStack.c > Arm/Unaligned.c > - Arm/SpeculationBarrier.c > Math64.c >=20 > AArch64/MemoryFence.S | GCC > @@ -596,6 +597,7 @@ > AArch64/GetInterruptsState.S | GCC > AArch64/SetJumpLongJump.S | GCC > AArch64/CpuBreakpoint.S | GCC > + AArch64/SpeculationBarrier.S | GCC >=20 > AArch64/MemoryFence.asm | MSFT > AArch64/SwitchStack.asm | MSFT > @@ -604,6 +606,7 @@ > AArch64/GetInterruptsState.asm | MSFT > AArch64/SetJumpLongJump.asm | MSFT > AArch64/CpuBreakpoint.asm | MSFT > + AArch64/SpeculationBarrier.asm | MSFT >=20 > [Packages] > MdePkg/MdePkg.dec > -- > 2.17.1