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 CCB85D80078 for ; Tue, 15 Aug 2023 15:35:24 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=a2iA2Tk+KzrjbTqLaxeRkgiPfl7l4Fd5xM0eJK49KwM=; 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=1692113723; v=1; b=HZlH+16risrxmdQEd82kVhjmsncBsp0GZU1/ZifiqSZ9yxteSXarYSaVUzNz+M0tr/YomcGs 72SBDrowwB9NJUpnWzWepmG5ZZrkjvoNKPMtmNX2IzrWVWqe5vCfsjp0CE8xKexECGrdcVktYgy s7mbQrgu8aYVONNmaSZW/HZk= X-Received: by 127.0.0.2 with SMTP id b1hfYY7687511xZvQHIE6Lip; Tue, 15 Aug 2023 08:35:23 -0700 X-Received: from mail-vs1-f53.google.com (mail-vs1-f53.google.com [209.85.217.53]) by mx.groups.io with SMTP id smtpd.web11.137380.1692113722979015303 for ; Tue, 15 Aug 2023 08:35:23 -0700 X-Received: by mail-vs1-f53.google.com with SMTP id ada2fe7eead31-44ac277f2fbso157034137.3 for ; Tue, 15 Aug 2023 08:35:22 -0700 (PDT) X-Gm-Message-State: kw0y57G3YGibVzdrqv4i6yzfx7686176AA= X-Google-Smtp-Source: AGHT+IHkbrpxNQ3ZKEcsSVxuSLs1E8k1eEu8OwNHJ7bnxfLCeSPiToCVSncazdMKdFn+PpTvUhNcMAc3ZBGwrml3apc= X-Received: by 2002:a67:f28f:0:b0:44a:c461:e34c with SMTP id m15-20020a67f28f000000b0044ac461e34cmr1144372vsk.10.1692113721858; Tue, 15 Aug 2023 08:35:21 -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: "Pedro Falcato" Date: Tue, 15 Aug 2023 16:35:10 +0100 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,pedro.falcato@gmail.com 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=HZlH+16r; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none) On Tue, Aug 15, 2023 at 9:20=E2=80=AFAM 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. There isn't any. Actual use cases in something like a kernel are heavily vetted and read-protected as soon as possible. > > 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. > > 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. FYI, poking instructions willy-nilly is unsafe and unreliable (except on x86 due to kludges, but then it's slow). > > 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 you're going to use inline assembly, just expose them directly? I don't see the problem there, I don't expect loongarch to be picked up by visual studio any time soon. > > > Choice 2: > > Use SMC. > > > Choice 3: > > Write a lot of similar CSR functions. You /could/ use a GAS macro. .macro csr_write csr .global CsrWrite\csr CsrWrite\csr: csrw a0, \csr ret (this is riscv pseudo-asm but I know your arch is similar enough) --=20 Pedro -=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 (#107767): https://edk2.groups.io/g/devel/message/107767 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-