From patchwork Wed Feb 6 00:08:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 157544 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5786502jaa; Tue, 5 Feb 2019 16:08:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ5Xq5QHrUeF80vVRw6mKqi0Yg3Euh+D25pCyPkHX68VWunxaZfdzJKp7TTtw2KP37b9vmj X-Received: by 2002:a62:5f07:: with SMTP id t7mr7658969pfb.108.1549411712645; Tue, 05 Feb 2019 16:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549411712; cv=none; d=google.com; s=arc-20160816; b=SQn1jvINE3kBNspE4atnl7Y5i7Tm9oL36oBEnuE+HQrPgUW+kPWtiUwgglqjbJcGGf gsf34JdaBsAMJlCVD7PqpyN7KRtgIht3ZilMB/n/kwCgRDPNkVrdCWEwwFFEq+uFqJKu RSYHcinWVHzi15pqU+S84gPHCBpMDXt6ou3+sBKVBbrvdgnCNs4Fwoynbn758n2LA2rp RjViiU0NbYHqJRSfhCgWLf6iire4j8V7AKLOfvIYUej5sDjUhvhzAD1BMUNV0DAMXVsr 6YHnXQbmfF980+xHkam+BlstH9ZcGbBZly+q9yJYKa6uCgGNn+ji3vITdkQNbYa6ymnP Itpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=bOiJ3jVxCt+Wzs27X4uaJnGpPKwPE779xGL921PVqIM=; b=FKf/5t/Vhi/gcgtj0TRsNmR96skRSlurNXjDYP76c99vLS6kfkA6dtuNY9THwRhsYG D/yRvcqd7e/Boc1L7HVBh0GEW7HpuGZxULSoAzVb9wUPrG9SN9JpPo5F0xZQv3dwYSEU c8Yo7bRuDWv8ym+BdQ9j2osgx4vUK8DPvu1i/PaLo94MTGKfvXl4rjN2t/m58iBakhvd UUlfgSjOHejfh5YPtAHAxipzjWweqVKBbFeQUiMLo2vjueqbUjGU3GRB70bECdyCFQ8+ 13IdnFf5jOqgOI7dX/pC+NntqcDQeTSPNoR1HV2qM+kxzvoGZNV2szdWPUu1AdJWtG+p wxSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=SYuNqm9s; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id c1si913218pls.326.2019.02.05.16.08.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 16:08:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=SYuNqm9s; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0E65021A02937; Tue, 5 Feb 2019 16:08:31 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::443; helo=mail-wr1-x443.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (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 963C0211C3F70 for ; Tue, 5 Feb 2019 16:08:28 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id z3so5693329wrv.3 for ; Tue, 05 Feb 2019 16:08:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=UettderxuHZVdwFASokWFS3Cf+gEe14/chsnAimrDrg=; b=SYuNqm9sueaK3NA5N6OrCwqArT5vTlp9dGogrryaTb3pCaZd6Ttxh5SlRFIEP1AzrU 3AcPrq+e/rl/IJPEHjSNcSE3LLborWy5vjIPy64L+/NUNUh8VxsgC7l+biPG22YbA30q +MlG8FXlwlF8SMpVJqnTTIuBePUve4DOoJgaVO7pMoDEue88FoJTdtxFh5mgJ+KgWsSD LP8xNB2bJlOj6JYO8d/fEm1WLQN9z914mFK18XSw3MGWRGFTJo9VrIXrSmwnYWbUwAJ3 KO9szi7RO7+u1eDsu66I68WxWEvM2bQ6BjpQyQGQEzInDFkxp8OfxUclhrEiRUszHp1h Rr/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UettderxuHZVdwFASokWFS3Cf+gEe14/chsnAimrDrg=; b=MSj/FPD6Px8rqkGF3pM0fjDWoO4Ifmgk472ew0g4atBGLiudr/qicG1dE3VmsDu0ko lw68W9UZnzGKQW2P1ek8Q8Q6FbPNwfKYbebP02w03+1541dauyUaMOHyD7JX3GswYFFU sDZFVPdFsB6fGr5SEpxWoy4IVDalpUkEcQLC/2DLLN+3BgNZM3OEBVxjHpcJUMRnXsk8 XSGd1alG37p5NtIlqQ7zqqYxi3qbTWIVNLhSd+bfkTIvsQdt4zlYOlVU5teHImsi8a3M odcRm/rl93DlfG2Z/qnTDSJIyBpEfwDGbb1meCeS+L+6Yl8SlRIG0BpVUDoKWKqzXHID ehhw== X-Gm-Message-State: AHQUAuZH5L5XANeTtT5jilHZcnm09L8Z2YhSNU4/3SbA0lW9y3yrrUMe DF7/6zLIGMwl23Xkhy7XcmsN7WR7rtIkGg== X-Received: by 2002:adf:ae1a:: with SMTP id x26mr5434748wrc.0.1549411706296; Tue, 05 Feb 2019 16:08:26 -0800 (PST) Received: from mba13.c.hoisthospitality.com ([135.196.99.211]) by smtp.gmail.com with ESMTPSA id y20sm21645877wra.51.2019.02.05.16.08.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 16:08:24 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Wed, 6 Feb 2019 00:08:22 +0000 Message-Id: <20190206000822.577-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Subject: [edk2] [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: , Cc: michael.d.kinney@intel.com, liming.gao@intel.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- 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(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm 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