public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "Gao, Liming" <liming.gao@intel.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Jagadeesh Ujja <jagadeesh.ujja@arm.com>,
	"Leif Lindholm" <leif.lindholm@linaro.org>
Cc: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	"Zhang, Chao B" <chao.b.zhang@intel.com>
Subject: Re: [PATCH 05/13] MdePkg/Library/BaseLib/AArch64: Add AsmLfence function
Date: Mon, 17 Dec 2018 03:29:09 +0000	[thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503F457847@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E38D42E@SHSMSX104.ccr.corp.intel.com>

I think we have below definition.
-- MemoryFence: Serialize load and store operations.
-- LoadFence: Serialize load operations.
-- StoreFence: Serialize store operations.

According to IA32 SDM, Intel has MFENCE, LFENCE and SFENCE.
If ARM only has DMB, it is possible to use DMB for MemoryFence, LoadFence or StoreFence.

Maybe it is better to use LoadFence, instead of AsmLFence?
Then we can align with MemoryFence.

Thank you
Yao Jiewen


> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Gao, Liming
> Sent: Monday, December 17, 2018 10:04 AM
> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Jagadeesh Ujja
> <jagadeesh.ujja@arm.com>; Leif Lindholm <leif.lindholm@linaro.org>
> Cc: edk2-devel@lists.01.org; Zhang, Chao B <chao.b.zhang@intel.com>
> Subject: Re: [edk2] [PATCH 05/13] MdePkg/Library/BaseLib/AArch64: Add
> AsmLfence function
> 
> Ard:
>   My first comment is to suggest updating the caller code for the arch
> specific code.  But, there are two drivers that have the same usage. This
> way will introduce the duplicated code logic. So, I suggest another way to
> extend  AsmLfence() API scope for the different ARCHs. If you think it brings
> the confuse, I just think another way to resolve this case in the caller code.
> 
> #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
> AsmLfence();
> #else
> MemoryFence()
> #endif
> 
> Thanks
> Liming
> >-----Original Message-----
> >From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> >Sent: Friday, December 14, 2018 9:54 PM
> >To: Jagadeesh Ujja <jagadeesh.ujja@arm.com>; Leif Lindholm
> ><leif.lindholm@linaro.org>
> >Cc: edk2-devel@lists.01.org; Gao, Liming <liming.gao@intel.com>; Zhang,
> >Chao B <chao.b.zhang@intel.com>
> >Subject: Re: [PATCH 05/13] MdePkg/Library/BaseLib/AArch64: Add
> >AsmLfence function
> >
> >On Fri, 14 Dec 2018 at 13:13, Jagadeesh Ujja <jagadeesh.ujja@arm.com>
> >wrote:
> >>
> >> Variable service driver includes a call to AsmLfence. To reuse this
> >> driver on AArch64 based platforms, add an implementation of AsmLfence
> >> that acts as a wrapper on the AArch64 specific MemoryFence function.
> >>
> >> Contributed-under: TianoCore Contribution Agreement 1.1
> >> Signed-off-by: Jagadeesh Ujja <jagadeesh.ujja@arm.com>
> >> ---
> >>  MdePkg/Include/Library/BaseLib.h             | 33 +++++++++------
> >>  MdePkg/Library/BaseLib/AArch64/AsmLfence.S   | 42
> >++++++++++++++++++++
> >>  MdePkg/Library/BaseLib/AArch64/AsmLfence.asm | 41
> >+++++++++++++++++++
> >>  MdePkg/Library/BaseLib/BaseLib.inf           |  2 +
> >>  4 files changed, 105 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/MdePkg/Include/Library/BaseLib.h
> >b/MdePkg/Include/Library/BaseLib.h
> >> index 8cc0869..ca961ee 100644
> >> --- a/MdePkg/Include/Library/BaseLib.h
> >> +++ b/MdePkg/Include/Library/BaseLib.h
> >> @@ -7697,19 +7697,6 @@ AsmWriteTr (
> >>    );
> >>
> >>  /**
> >> -  Performs a serializing operation on all load-from-memory instructions
> that
> >> -  were issued prior the AsmLfence function.
> >> -
> >> -  Executes a LFENCE instruction. This function is only available on IA-32
> and
> >x64.
> >> -
> >> -**/
> >> -VOID
> >> -EFIAPI
> >> -AsmLfence (
> >> -  VOID
> >> -  );
> >> -
> >> -/**
> >>    Patch the immediate operand of an IA32 or X64 instruction such that
> the
> >byte,
> >>    word, dword or qword operand is encoded at the end of the
> instruction's
> >>    binary representation.
> >> @@ -7752,4 +7739,24 @@ PatchInstructionX86 (
> >>    );
> >>
> >>  #endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
> >> +
> >> +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) || defined
> >(MDE_CPU_AARCH64)
> >> +
> >> +/**
> >> +  Performs a serializing operation on all load-from-memory instructions
> that
> >> +  were issued prior the AsmLfence function.
> >> +
> >> +  In case of IA-32 and x64, Executes a LFENCE instruction.
> >> +
> >> +  In case of AArch64 this acts as a wrapper on the AArch64
> >> +  specific MemoryFence function
> >> +
> >> +**/
> >> +VOID
> >> +EFIAPI
> >> +AsmLfence (
> >> +  VOID
> >> +  );
> >> +
> >> +#endif  // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) ||
> >defined (MDE_CPU_AARCH64)
> >>  #endif // !defined (__BASE_LIB__)
> >> diff --git a/MdePkg/Library/BaseLib/AArch64/AsmLfence.S
> >b/MdePkg/Library/BaseLib/AArch64/AsmLfence.S
> >> new file mode 100644
> >> index 0000000..2fd804b
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseLib/AArch64/AsmLfence.S
> >> @@ -0,0 +1,42 @@
> >> +##------------------------------------------------------------------------------
> >> +#
> >> +# AsmLfence() for AArch64
> >> +#
> >> +# Copyright (c) 2013-2018, ARM 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(AsmLfence)
> >> +
> >> +# IMPORT
> >> +GCC_ASM_IMPORT(MemoryFence)
> >> +
> >> +#/**
> >> +#  Used to serialize load and store operations.
> >> +#
> >> +#  All loads and stores that proceed calls to this function are
> guaranteed to
> >be
> >> +#  globally visible when this function returns.
> >> +#
> >> +#**/
> >> +#VOID
> >> +#EFIAPI
> >> +#AsmLfence (
> >> +#  VOID
> >> +#  );
> >> +#
> >> +ASM_PFX(AsmLfence):
> >> +    stp   x29, x30, [sp, #-16]!
> >> +    bl MemoryFence
> >> +    ldp   x29, x30, [sp], #0x10
> >> +    ret
> >
> >Any reason we can't simply do
> >
> >b MemoryFence
> >
> >here?
> >
> >Also, why I understand the rationale, I still think it would be better
> >to change callers of the [x86 specific] AsmLfence() than to introduce
> >an alias of MemoryFence() for architectures where Lfence is not
> >defined.
> >
> >This is not only about tidiness, but also about potentially having
> >different semantics, which we can't provide in general on ARM, but
> >only in particular cases [such as the code that is modified in this
> >series]
> >
> >In other words, newly introduced occurrences of AsmLfence() now have
> >to be audited for being appropriate on AArc64 if they are added to
> >generic code.
> >
> >
> >> diff --git a/MdePkg/Library/BaseLib/AArch64/AsmLfence.asm
> >b/MdePkg/Library/BaseLib/AArch64/AsmLfence.asm
> >> new file mode 100644
> >> index 0000000..7dd5659
> >> --- /dev/null
> >> +++ b/MdePkg/Library/BaseLib/AArch64/AsmLfence.asm
> >> @@ -0,0 +1,41 @@
> >> +;------------------------------------------------------------------------------
> >> +;
> >> +; AsmLfence() for AArch64
> >> +;
> >> +; Copyright (c) 2013-2018, ARM 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 AsmLfence
> >> +  AREA BaseLib_LowLevel, CODE, READONLY
> >> +  # IMPORT
> >> +  GCC_ASM_IMPORT(MemoryFence)
> >> +
> >> +;/**
> >> +;  Used to serialize load and store operations.
> >> +;
> >> +;  All loads and stores that proceed calls to this function are guaranteed
> to
> >be
> >> +;  globally visible when this function returns.
> >> +;
> >> +;**/
> >> +;VOID
> >> +;EFIAPI
> >> +;AsmLfence (
> >> +;  VOID
> >> +;  );
> >> +;
> >> +AsmLfence
> >> +    stp   x29, x30, [sp, #-16]!
> >> +    bl MemoryFence
> >> +    ldp   x29, x30, [sp], #0x10
> >> +    ret
> >> +
> >> +  END
> >> diff --git a/MdePkg/Library/BaseLib/BaseLib.inf
> >b/MdePkg/Library/BaseLib/BaseLib.inf
> >> index b84e583..b7d7bcb 100644
> >> --- a/MdePkg/Library/BaseLib/BaseLib.inf
> >> +++ b/MdePkg/Library/BaseLib/BaseLib.inf
> >> @@ -585,6 +585,7 @@
> >>    Math64.c
> >>
> >>    AArch64/MemoryFence.S             | GCC
> >> +  AArch64/AsmLfence.S               | GCC
> >>    AArch64/SwitchStack.S             | GCC
> >>    AArch64/EnableInterrupts.S        | GCC
> >>    AArch64/DisableInterrupts.S       | GCC
> >> @@ -593,6 +594,7 @@
> >>    AArch64/CpuBreakpoint.S           | GCC
> >>
> >>    AArch64/MemoryFence.asm           | MSFT
> >> +  AArch64/AsmLfence.asm             | MSFT
> >>    AArch64/SwitchStack.asm           | MSFT
> >>    AArch64/EnableInterrupts.asm      | MSFT
> >>    AArch64/DisableInterrupts.asm     | MSFT
> >> --
> >> 2.7.4
> >>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  reply	other threads:[~2018-12-17  3:29 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-14 12:13 [PATCH 00/13] Extend secure variable service to be usable from Standalone MM Jagadeesh Ujja
2018-12-14 12:13 ` [PATCH 01/13] StandaloneMmPkg: Pull in additonal libraries from staging branch Jagadeesh Ujja
2018-12-21  8:58   ` Ard Biesheuvel
2018-12-14 12:13 ` [PATCH 02/13] MdePkg: Add a PCD that indicates presence of Standalone MM mode Jagadeesh Ujja
2018-12-21  9:13   ` Ard Biesheuvel
2018-12-14 12:13 ` [PATCH 03/13] MdeModulePkg: Add a PCD to indicate Standalone MM supports secure variable Jagadeesh Ujja
2018-12-21  9:13   ` Ard Biesheuvel
2018-12-14 12:13 ` [PATCH 04/13] MdePkg/Include: add StandaloneMmServicesTableLib header file Jagadeesh Ujja
2018-12-14 12:13 ` [PATCH 05/13] MdePkg/Library/BaseLib/AArch64: Add AsmLfence function Jagadeesh Ujja
2018-12-14 13:53   ` Ard Biesheuvel
2018-12-17  2:04     ` Gao, Liming
2018-12-17  3:29       ` Yao, Jiewen [this message]
2018-12-17  7:45         ` Ard Biesheuvel
2018-12-17  8:10           ` Ard Biesheuvel
2018-12-17  8:24             ` Yao, Jiewen
2018-12-17  8:30               ` Yao, Jiewen
2018-12-17  8:35                 ` Ard Biesheuvel
2018-12-17  8:44                   ` Yao, Jiewen
2018-12-17  9:27                     ` Ard Biesheuvel
2018-12-18  2:08                       ` Yao, Jiewen
2018-12-18  2:12                         ` Gao, Liming
2018-12-18  2:19                           ` Yao, Jiewen
2018-12-20  9:00                         ` Jagadeesh Ujja
2018-12-20  9:10                           ` Ard Biesheuvel
2018-12-14 12:13 ` [PATCH 06/13] MdePkg/Library: Add StandaloneMmRuntimeDxe library Jagadeesh Ujja
2018-12-14 12:13 ` [PATCH 07/13] MdeModulePkg/FaultTolerantWriteDxe: allow reusability as a MM driver Jagadeesh Ujja
2018-12-14 12:13 ` [PATCH 08/13] MdeModulePkg/Variable/RuntimeDxe: adapt for usability with MM Standalone Jagadeesh Ujja
2018-12-14 12:13 ` [PATCH 09/13] MdeModulePkg/Variable/RuntimeDxe: adapt as a MM Standalone driver Jagadeesh Ujja
2018-12-14 12:13 ` [PATCH 10/13] MdeModulePkg/VarCheckLib: allow MM_STANDALONE drivers to use this library Jagadeesh Ujja
2019-01-02 13:05   ` Ard Biesheuvel
2019-01-02 13:23     ` Gao, Liming
2019-01-02 14:23       ` Ard Biesheuvel
2019-01-02 16:54         ` Ard Biesheuvel
2019-01-02 13:27     ` Jagadeesh Ujja
2018-12-14 12:13 ` [PATCH 11/13] ArmPlatformPkg/NorFlashDxe: allow reusability as a MM driver Jagadeesh Ujja
2018-12-21 11:07   ` Ard Biesheuvel
2018-12-14 12:13 ` [PATCH 12/13] SecurityPkg/AuthVariableLib: allow MM_STANDALONE drivers to use this library Jagadeesh Ujja
2019-01-02 13:05   ` Ard Biesheuvel
2018-12-14 12:13 ` [PATCH 13/13] CryptoPkg/BaseCryptLib: " Jagadeesh Ujja
2018-12-21 10:13   ` Ard Biesheuvel
2018-12-17  1:45 ` [PATCH 00/13] Extend secure variable service to be usable from Standalone MM Gao, Liming
2018-12-17 11:46   ` Jagadeesh Ujja
2018-12-18  4:37     ` Gao, Liming
2018-12-18 11:19       ` Jagadeesh Ujja
2018-12-20 14:23         ` Gao, Liming
2019-01-02 17:15           ` Ard Biesheuvel
2019-01-03  7:43             ` Jagadeesh Ujja
2019-01-03  9:52               ` Ard Biesheuvel
2019-01-03 10:35                 ` Ard Biesheuvel
2018-12-21  2:57 ` Wang, Jian J
2019-01-02 13:19   ` Jagadeesh Ujja
2019-01-03  2:37     ` Wang, Jian J

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74D8A39837DF1E4DA445A8C0B3885C503F457847@shsmsx102.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox