From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.27960.1685616972186934961 for ; Thu, 01 Jun 2023 03:56:12 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ZZryngto; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: yong.li@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685616972; x=1717152972; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VKiXO7bsLUjku6EL0WAjaDKlNwHvV3ZejrSqD4O6VTs=; b=ZZryngtoEvpig7IvkZh0mE77nD5wlRpdOr6avAmZEb8RgXVSyBTXkMg0 5mdzfJj81Yj9esfjr9jXyBT43zWxXcBXqKxHvQHVuQe9owDIrxHIXtw9v 4wQ4+4hWg8rUs9Ag89LmpfAeauDBrFM6ES3X3BS5o+vklgGeE6LCjTAjd rjn81NG6YxoaN5NjmIULV4bAiJSVhY7UD1qzW7zMRzBhv3BZcsg/orZcP tbn1MAsVPpha9y0+v1HodhE7MUd3hBUDsBgcXpXnVLDIBH/e2A1iPZRu9 MsASO5duBhU9AwG6BXc2pCu+jaV34Inv8egUjrwCHrJnJmTRPxh8Sez61 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10727"; a="335141850" X-IronPort-AV: E=Sophos;i="6.00,209,1681196400"; d="scan'208";a="335141850" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2023 03:56:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10727"; a="710461065" X-IronPort-AV: E=Sophos;i="6.00,209,1681196400"; d="scan'208";a="710461065" Received: from intel-optiplex-7090.sh.intel.com ([10.239.159.128]) by fmsmga007.fm.intel.com with ESMTP; 01 Jun 2023 03:56:10 -0700 From: "Li, Yong" To: devel@edk2.groups.io Cc: Yong Li , Andrei Warkentin , Evan Chai , Sunil V L , Tuan Phan Subject: [PATCH v2 1/1] MdePkg/BaseLib: Add SpeculationBarrier implementation for RiscV64 Date: Thu, 1 Jun 2023 18:56:05 +0800 Message-Id: <5105ea68520e82932c4253e087438db53546ea6d.1685616822.git.yong.li@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Implement the SpeculationBarrier with implementations consisting of fence instruction which provides finer-grain memory orderings. Perform Data Barrier in RiscV: fence rw,rw Perform Instruction Barrier in RiscV: fence.i; fence r,r More detail is in Appendix A: RVWMO Explanatory Material in https://github.com/riscv/riscv-isa-manual This API is first introduced in the below commits for IA32 and x64 https://github.com/tianocore/edk2/commit/d9f1cac51bd354507e880e614d11a1dc160d38a3 https://github.com/tianocore/edk2/commit/e83d841fdc2878959185c4c6cc38a7a1e88377a4 and below the commit for ARM and AArch64 implementation https://github.com/tianocore/edk2/commit/c0959b4426b2da45cdb8146a5116bb4fd9b86534 This commit is to add the RiscV64 implementation which will be used by variable service under Variable/RuntimeDxe Cc: Andrei Warkentin Cc: Evan Chai Cc: Sunil V L Cc: Tuan Phan Signed-off-by: Yong Li --- MdePkg/Library/BaseLib/BaseLib.inf | 1 + .../BaseLib/RiscV64/SpeculationBarrier.S | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 MdePkg/Library/BaseLib/RiscV64/SpeculationBarrier.S diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf index 3a48492b1a01..03c7b02e828b 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -404,6 +404,7 @@ [Sources.RISCV64] RiscV64/CpuScratch.S | GCC RiscV64/ReadTimer.S | GCC RiscV64/RiscVMmu.S | GCC + RiscV64/SpeculationBarrier.S | GCC [Sources.LOONGARCH64] Math64.c diff --git a/MdePkg/Library/BaseLib/RiscV64/SpeculationBarrier.S b/MdePkg/Library/BaseLib/RiscV64/SpeculationBarrier.S new file mode 100644 index 000000000000..581a7653996f --- /dev/null +++ b/MdePkg/Library/BaseLib/RiscV64/SpeculationBarrier.S @@ -0,0 +1,34 @@ +##------------------------------------------------------------------------------ +# +# SpeculationBarrier() for RISCV64 +# +# Copyright (c) 2023, Intel Corporation. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +##------------------------------------------------------------------------------ + +.text +.p2align 2 + +ASM_GLOBAL ASM_PFX(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): + fence rw,rw + fence.i + fence r,r + ret -- 2.25.1