From nobody Sat May 4 13:11:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565954828; cv=none; d=zoho.com; s=zohoarc; b=AF8v1oVioezTUnmdmgL94c0F68iBdqAHh7TWkUkXMW3/Av3TqWleZZJRxN06QjSXO7Jw5aCUMaFmuHYaY7zqmbPesKa+YVeQ129GiDnYlOI2FtTbO6RT3qCNjRaIqm0D3oa+i8ZjpzpoN5wJGPNp2BzXOinBA8fF5MBrxv2Ar7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565954828; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=SbKMG9jIraR9thMGinlUOaJz/U3opgebKVGP2lxd26A=; b=djsVGikhLQhfuodiYYqW6OuTSh/q0ZK/P8oD2zneMSjcHNjOMeH4rgGiSYnU1vos2vcJLV8r5bYZmlkx+73TGuzVpqQl9I9YVzGHaiOlroNDpq0Uu5fWNU8pmEYgkDFrLyCCeZV1U825yGskH1+1gXpv/E7DhWQx4dkpDwEEDFs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565954828077213.2757133641253; Fri, 16 Aug 2019 04:27:08 -0700 (PDT) Received: from localhost ([::1]:54080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyaNv-0002X1-1N for importer@patchew.org; Fri, 16 Aug 2019 07:27:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47939) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyaLF-0008KI-Ap for qemu-devel@nongnu.org; Fri, 16 Aug 2019 07:24:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyaLE-0008Ha-1Z for qemu-devel@nongnu.org; Fri, 16 Aug 2019 07:24:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59568) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyaLD-0008H5-Q9 for qemu-devel@nongnu.org; Fri, 16 Aug 2019 07:24:19 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1709AC0272DE; Fri, 16 Aug 2019 11:24:19 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B9B943FEA; Fri, 16 Aug 2019 11:24:16 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 16 Aug 2019 07:24:07 -0400 Message-Id: <20190816112407.28180-3-imammedo@redhat.com> In-Reply-To: <20190816112407.28180-1-imammedo@redhat.com> References: <20190816112407.28180-1-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 16 Aug 2019 11:24:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [POC Seabios PATCH] seabios: use isolated SMM address space for relocation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Chen, Yingwen" , edk2-devel-groups-io , Phillip Goerl , "Yao, Jiewen" , "Nakajima, Jun" , pbonzini@redhat.com, Boris Ostrovsky , edk2-rfc-groups-io , Laszlo Ersek , Joao Marcal Lemos Martins Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" for purpose of demo SMRAM (at 0x30000) is aliased at a0000 in system addres= s space for easy initialization of SMI entry point. Here is resulting debug output showing that RAM at 0x30000 is not affected by SMM and only RAM in SMM adderss space is modified: init smm smm_relocate: before relocaten smm_relocate: RAM codeentry 0 smm_relocate: RAM cpu.i64.smm_base 0 smm_relocate: SMRAM codeentry f000c831eac88c smm_relocate: SMRAM cpu.i64.smm_base 0 handle_smi cmd=3D0 smbase=3D0x00030000 smm_relocate: after relocaten smm_relocate: RAM codeentry 0 smm_relocate: RAM cpu.i64.smm_base 0 smm_relocate: SMRAM codeentry f000c831eac88c smm_relocate: SMRAM cpu.i64.smm_base a0000 Patch depends on QEMU POC patch that adds SMRAM at 0x30000 in SMM address s= pace PS: configure bios with level 9 debugging and debug port Signed-off-by: Igor Mammedov --- src/fw/smm.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/fw/smm.c b/src/fw/smm.c index d90e43a9..27f9747e 100644 --- a/src/fw/smm.c +++ b/src/fw/smm.c @@ -140,21 +140,22 @@ extern void entry_smi(void); | ((u64)((u32)entry_smi - BUILD_BIOS_ADDR) << 24)) =20 static void -smm_save_and_copy(void) +smm_relocate(void) { - // save original memory content struct smm_layout *initsmm =3D (void*)BUILD_SMM_INIT_ADDR; struct smm_layout *smm =3D (void*)BUILD_SMM_ADDR; - memcpy(&smm->cpu, &initsmm->cpu, sizeof(smm->cpu)); - memcpy(&smm->codeentry, &initsmm->codeentry, sizeof(smm->codeentry)); =20 - // Setup code entry point. - initsmm->codeentry =3D SMI_INSN; -} + dprintf(3, "smm_relocate: before relocaten\n"); + dprintf(3, "smm_relocate: RAM codeentry %llx\n", initsmm->codeentry); + dprintf(3, "smm_relocate: RAM cpu.i64.smm_base %lx\n", initsmm->cpu.= i64.smm_base); + + + /* BUILD_SMM_ADDR aliased to BUILD_SMM_INIT_ADDR in SMM AS + * so we could set SMI entry point there */ + smm->codeentry =3D SMI_INSN; + dprintf(3, "smm_relocate: SMRAM codeentry %llx\n", smm->codeentry); + dprintf(3, "smm_relocate: SMRAM cpu.i64.smm_base %lx\n", smm->cpu.i6= 4.smm_base); =20 -static void -smm_relocate_and_restore(void) -{ /* init APM status port */ outb(0x01, PORT_SMI_STATUS); =20 @@ -165,15 +166,13 @@ smm_relocate_and_restore(void) while (inb(PORT_SMI_STATUS) !=3D 0x00) ; =20 - /* restore original memory content */ - struct smm_layout *initsmm =3D (void*)BUILD_SMM_INIT_ADDR; - struct smm_layout *smm =3D (void*)BUILD_SMM_ADDR; - memcpy(&initsmm->cpu, &smm->cpu, sizeof(initsmm->cpu)); - memcpy(&initsmm->codeentry, &smm->codeentry, sizeof(initsmm->codeentry= )); - - // Setup code entry point. - smm->codeentry =3D SMI_INSN; wbinvd(); + + dprintf(3, "smm_relocate: after relocaten\n"); + dprintf(3, "smm_relocate: RAM codeentry %llx\n", initsmm->codeentry); + dprintf(3, "smm_relocate: RAM cpu.i64.smm_base %lx\n", initsmm->cpu.= i64.smm_base); + dprintf(3, "smm_relocate: SMRAM codeentry %llx\n", smm->codeentry); + dprintf(3, "smm_relocate: SMRAM cpu.i64.smm_base %lx\n", smm->cpu.i6= 4.smm_base); } =20 // This code is hardcoded for PIIX4 Power Management device. @@ -187,8 +186,6 @@ static void piix4_apmc_smm_setup(int isabdf, int i440_b= df) /* enable the SMM memory window */ pci_config_writeb(i440_bdf, I440FX_SMRAM, 0x02 | 0x48); =20 - smm_save_and_copy(); - /* enable SMI generation when writing to the APMC register */ pci_config_writel(isabdf, PIIX_DEVACTB, value | PIIX_DEVACTB_APMC_EN); =20 @@ -196,7 +193,7 @@ static void piix4_apmc_smm_setup(int isabdf, int i440_b= df) value =3D inl(acpi_pm_base + PIIX_PMIO_GLBCTL); outl(value | PIIX_PMIO_GLBCTL_SMI_EN, acpi_pm_base + PIIX_PMIO_GLBCTL); =20 - smm_relocate_and_restore(); + smm_relocate(); =20 /* close the SMM memory window and enable normal SMM */ pci_config_writeb(i440_bdf, I440FX_SMRAM, 0x02 | 0x08); @@ -213,8 +210,6 @@ void ich9_lpc_apmc_smm_setup(int isabdf, int mch_bdf) /* enable the SMM memory window */ pci_config_writeb(mch_bdf, Q35_HOST_BRIDGE_SMRAM, 0x02 | 0x48); =20 - smm_save_and_copy(); - /* enable SMI generation when writing to the APMC register */ outl(value | ICH9_PMIO_SMI_EN_APMC_EN | ICH9_PMIO_SMI_EN_GLB_SMI_EN, acpi_pm_base + ICH9_PMIO_SMI_EN); @@ -224,7 +219,7 @@ void ich9_lpc_apmc_smm_setup(int isabdf, int mch_bdf) pci_config_writel(isabdf, ICH9_LPC_GEN_PMCON_1, value | ICH9_LPC_GEN_PMCON_1_SMI_LOCK); =20 - smm_relocate_and_restore(); + smm_relocate(); =20 /* close the SMM memory window and enable normal SMM */ pci_config_writeb(mch_bdf, Q35_HOST_BRIDGE_SMRAM, 0x02 | 0x08); --=20 2.18.1