From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::344; helo=mail-wm1-x344.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9D6C1208F60FC for ; Mon, 11 Feb 2019 06:41:50 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id x7so2070722wmj.0 for ; Mon, 11 Feb 2019 06:41:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1hqxYJsnk4m883Rr5nMZpl9lK0acBtrD+sjlTZGKiII=; b=dKP59AAXbvTwJ2w5CTlD0qiAT/4kKGHeD0VjjwVRkJaPIUDajLEQ39IfsmdDyf8KGe Eo/9+aeAIm0MwhKGKZWOAYhV+dx0RGdgz957TElEaFPEi9saj7e5aL+/68smASxy83nj xnuZDJzND/9o3ZKRm4GCIeqJiImBkvJLJAxDI7is4iqFNM4Pew7gUskeaizQUq9wrP2y i1ESW+V27w5bkBcBzuLrWunMfUTMhfqxukxD2kOhXRJNy5QP5PCSjKemgTnjhg8RHuTY eJl4segfjMcaO6QeAk7iRBoRTJ2BBfPMlF+KP+NzUhHJHlsduQNjPW8jGDIeCXiS5R+4 j2ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1hqxYJsnk4m883Rr5nMZpl9lK0acBtrD+sjlTZGKiII=; b=Kq+S+/rUhkBag44aJ4K+ERjYFGnA4nXqp72mpkIntqwUezb9EpskAFzyqZmNigb/B/ pEyfu8njcX1sY9H8wPsCeNH90kfMjcdSkfD4cuW4p++UVKQYM9bEWzFBlPb9vRIlSkG8 ByvkyAFHsDfHC17d1qZGHhTNn/wtbs0TqnfVr3xIOeuhIZDYhJc092oAJ6AUA2th1p3A itwQ1kVt/WtHazuRa8mifDfwbIlozUS3YsIiHgAGPsONJi9kNq627RcCLHWmi5Oldyk+ 47cmYae7ex2NMGHf08Qt8U4MjKQGKqX4oXFvQz3+d/f3ilAu0DqRe+FrPqJXO5F7V6Zd VPug== X-Gm-Message-State: AHQUAua3VLbvIiezvELwKGFfxTmTMXzBmchMALTTjhyslQQwMjXLEfUE lWx6CpeGzWQsvJJvU7xGFDtDdQ== X-Google-Smtp-Source: AHgI3IZYgXUO9y4bIUBrZ29GRBgIE3m4uqCUapuhvbLnyMQubxq1DLnWevK021HTS6a7aW9l7hYIWg== X-Received: by 2002:a1c:544f:: with SMTP id p15mr9627515wmi.37.1549896107600; Mon, 11 Feb 2019 06:41:47 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id y20sm23998915wra.51.2019.02.11.06.41.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Feb 2019 06:41:46 -0800 (PST) Date: Mon, 11 Feb 2019 14:41:44 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, liming.gao@intel.com, michael.d.kinney@intel.com Message-ID: <20190211144144.qt2hdupd3mmdghqb@bivouac.eciton.net> References: <20190206000822.577-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <20190206000822.577-1-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) 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:41:51 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 06, 2019 at 12:08:22AM +0000, Ard Biesheuvel wrote: > 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. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Patch looks fine. Reviewed-by: Leif Lindholm Question: do we expect performance impact to be sufficient to motivate a Pcd to be able to disable the barrier on unaffected processors? Regards, Leif > --- > 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(-) > > 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 IMPLIED. > +# > +##------------------------------------------------------------------------------ > + > +.text > +.p2align 2 > + > +GCC_ASM_EXPORT(SpeculationBarrier) > + > + > +#/** > +# Uses as a barrier to stop speculative execution. > +# > +# Ensures that no later instruction will execute speculatively, until all 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/MdePkg/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 IMPLIED. > +; > +;------------------------------------------------------------------------------ > + > + EXPORT SpeculationBarrier > + AREA BaseLib_LowLevel, CODE, READONLY > + > +;/** > +; Uses as a barrier to stop speculative execution. > +; > +; Ensures that no later instruction will execute speculatively, until all 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/Library/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 IMPLIED. > +# > +##------------------------------------------------------------------------------ > + > +.text > +.p2align 2 > + > +GCC_ASM_EXPORT(SpeculationBarrier) > + > + > +#/** > +# Uses as a barrier to stop speculative execution. > +# > +# Ensures that no later instruction will execute speculatively, until all 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/Library/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 IMPLIED. > +; > +;------------------------------------------------------------------------------ > + > + EXPORT SpeculationBarrier > + > + AREA MemoryBarriers, CODE, READONLY > + > +;/** > +; Uses as a barrier to stop speculative execution. > +; > +; Ensures that no later instruction will execute speculatively, until all 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/Library/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 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 IMPLIED. > - > -**/ > - > - > -/** > - Uses as a barrier to stop speculative execution. > - > - Ensures that no later instruction will execute speculatively, until all 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 > > @@ -564,6 +563,7 @@ > Arm/CpuPause.asm | RVCT > Arm/CpuBreakpoint.asm | RVCT > Arm/MemoryFence.asm | RVCT > + Arm/SpeculationBarrier.S | RVCT > > 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 > > 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 > > [Sources.AARCH64] > Arm/InternalSwitchStack.c > Arm/Unaligned.c > - Arm/SpeculationBarrier.c > Math64.c > > AArch64/MemoryFence.S | GCC > @@ -596,6 +597,7 @@ > AArch64/GetInterruptsState.S | GCC > AArch64/SetJumpLongJump.S | GCC > AArch64/CpuBreakpoint.S | GCC > + AArch64/SpeculationBarrier.S | GCC > > 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 > > [Packages] > MdePkg/MdePkg.dec > -- > 2.17.1 >