From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id C3E46AC0CBA for ; Tue, 15 Aug 2023 08:28:29 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=uF7FDkze0LvDSYEG4qi85rjKDm4gZu5eAfUHWhl9Bgo=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1692088108; v=1; b=uXjaF7OG5lE9wijWnS6FZMarTHkQZKGUsk4UW6J/X8iY/tJdUa5v+kE3o4i5+ZGuvbv78Be3 g3I2yz0Mq4ADSfSE5ArRhWrHhGkwhWn3tJ21Ck4/LeuLDCxILvnGV7BuN4VHoC/UmsGRzsjCooo hO5U+4dlAmbSxSrmpcbWy+6o= X-Received: by 127.0.0.2 with SMTP id B18SYY7687511xyGpNrTFJLM; Tue, 15 Aug 2023 01:28:28 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.129957.1692088107710166125 for ; Tue, 15 Aug 2023 01:28:27 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 276EC65110 for ; Tue, 15 Aug 2023 08:28:27 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51D98C433C7 for ; Tue, 15 Aug 2023 08:28:26 +0000 (UTC) X-Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2b9b5ee9c5aso80243161fa.1 for ; Tue, 15 Aug 2023 01:28:26 -0700 (PDT) X-Gm-Message-State: Va9SHW1A4tMLykrjcIj4raAqx7686176AA= X-Google-Smtp-Source: AGHT+IGmSOyuhR+lTa8gNYc5IwJwRDAJWE2IF4TNz5tIhO6xVFz1z4U7rcLoM3WfDmeVzQOGTHYljHWgVKZJfu6gz9w= X-Received: by 2002:a2e:84c6:0:b0:2b9:3883:a765 with SMTP id q6-20020a2e84c6000000b002b93883a765mr8026531ljh.31.1692088104343; Tue, 15 Aug 2023 01:28:24 -0700 (PDT) MIME-Version: 1.0 References: <22642530-3177-d5d9-426a-d5a68ebfe8c6@loongson.cn> <4EB062B0-6C13-480F-A2CC-95C715A08ECD@apple.com> In-Reply-To: From: "Ard Biesheuvel" Date: Tue, 15 Aug 2023 10:28:13 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] About EDK2 supports Self Modifying Code To: devel@edk2.groups.io, lichao@loongson.cn Cc: "Andrew (EFI) Fish" , Liming Gao , Bob Feng , Yuwei Chen Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=uXjaF7OG; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On Tue, 15 Aug 2023 at 10:20, Chao Li wrote: > > Hi Andrew, > > Yes, you are right, I also think that SMC is a bit flawed in terms of sec= urity, but can we use some security mechanism to protect the SMC, like encr= yption and decryption? Sorry, I'm not consider mature enough about SMC secu= rity. > > I can tell you real problem, there are some CSR instructions in LoongArch= 64 that can only accept immediate value, for example: `csrrd $a0, 0x1`, the= 0x1 is the selection of CSR register number, it can't use the registers to= select. This operation should be in the MdePkg base library. > That is *not* a good reason for using self modifying code. If the CSR register number is known at build time, it should be emitted into the binary at build time in one way or another. > I know that .c or .h files in MdePkg shouldn't depend on a single compile= r feature, so I can't use the GNU AT&T style inline ASM function(AT&T style= inline supports input parameters being immedite value, use "i" option). In= this case, I think using SMC can handle this, that is use register transfe= r the CSR registers selection, and dynamically modify CSR instructions duri= ng execution phase with reference to transfer register value, this way is d= epend on the .text section or target memory is executable and writable. > > The problem of immediate values can only be handled by preprocessing stag= e or using SMC, otherwise I can only write a lot of similar functions and u= se `switch case` to call them. This method will cause the program size to e= xpand a lot. > > So, I think I have following choice: > > Choice 1: > > Use AT&T style inline function, and create a file named: CsrOperationGcc.= c, and other future compiler feature-dependent files will be named: CsrOper= ationClang.c, CsrOperationXlang.c and so on. > If the only currently supported compiler (GCC?) has a syntax that permits emitting this as inline asm, it is perfectly fine to use this in your implementation. Once other compiler support is introduced, we can think about how to address the difference, but I suspect that Clang will just work with the GCC notation. -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107763): https://edk2.groups.io/g/devel/message/107763 Mute This Topic: https://groups.io/mt/100751724/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-