From nobody Fri Apr 19 05:30:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+46911+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46911+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567698575; cv=none; d=zoho.com; s=zohoarc; b=BUPGNBtPdCQMNIgVvGECdtvVj2uAYAb28vkxTrULRxHU/79GKuuZ/4xP/FRftP6oUzawrzxSlz3sqluIiweUH2alqNY9YOBoi+bSMRUQDuTH2X1yA5MC+7I1PV3iivb8X8FMdIbrCldVCKQk9y8oSWEut4aSI2jlSjf7x22eXko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567698575; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=3wjVJGygIz37t3BK/BZFnozCRq1un4V+NMVHGypoO8A=; b=TfLhykpz1awzygz1QM0PKC505ffIQQ+CWUcwj0aa85a7VmHwaLIRUnNRUh/iaULEAKW4FBl1I/8bE/bEouRJm+DlW+Ca65hzG/AjJVTDq7WEfig4Gz9h8PmCA3ljOHaH466idJzqTG8DxJbtEyripNsvgqju5gRJJI2MAjOrX3c= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46911+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1567698575887218.135888669084; Thu, 5 Sep 2019 08:49:35 -0700 (PDT) Return-Path: X-Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Thu, 05 Sep 2019 08:49:34 -0700 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5AB23007C30; Thu, 5 Sep 2019 15:49:33 +0000 (UTC) X-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 C7FF360127; Thu, 5 Sep 2019 15:49:28 +0000 (UTC) From: "Igor Mammedov" To: qemu-devel@nongnu.org Cc: yingwen.chen@intel.com, devel@edk2.groups.io, phillip.goerl@oracle.com, lersek@redhat.com, alex.williamson@redhat.com, jiewen.yao@intel.com, jun.nakajima@intel.com, michael.d.kinney@intel.com, pbonzini@redhat.com, boris.ostrovsky@oracle.com, rfc@edk2.groups.io, joao.m.martins@oracle.com Subject: [edk2-devel] [PATCH] q35: lpc: allow to lock down 128K RAM at default SMBASE address Date: Thu, 5 Sep 2019 11:49:25 -0400 Message-Id: <20190905154925.30478-1-imammedo@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 05 Sep 2019 15:49:34 +0000 (UTC) Precedence: Bulk List-Unsubscribe: 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,imammedo@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1567698575; bh=xblduGkqqPiZt/vBA/Yj4lNof/sGw1/rBpLIWSoDPyw=; h=Cc:Date:From:Reply-To:Subject:To; b=s3+oKowdPaKWMyFtHcyrgLkIXDZxK9GwEXv3lSaBvsUaBpmSWcd4uM+2AlQzVTRD6QR JAg2xewaZMJJ1fNUreFBikydg4pfxA9baTehKXAtHo6PnPq8L892qCaMc955tg5o3hmXO h3aMi7C0TnN+XKwr9JPrjqZ2ynFWzJaguqg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" lpc already has SMI negotiation feature, extend it by adding optin ICH9_LPC_SMI_F_LOCKED_SMBASE_BIT to supported features. Writing this bit into "etc/smi/requested-features" fw_cfg file, tells QEMU to alias 0x30000,128K RAM range into SMRAM address space and mask this region from normal RAM address space (reads return 0xff and writes are ignored, i.e. guest code should be able to deal with not usable 0x30000,128K RAM range once ICH9_LPC_SMI_F_LOCKED_SMBASE_BIT is activated). To make negotiated change effective, guest should read "etc/smi/features-ok" fw_cfg file, which activates negotiated features and locks down negotiating capabilities until hard reset. Flow for initializing SMI handler on guest side: 1. set SMI handler entry point at default SMBASE location 2. check that host supports ICH9_LPC_SMI_F_LOCKED_SMBASE_BIT in "etc/smi/supported-features" and set if supported set it in "etc/smi/requested-features" 3. read "etc/smi/features-ok", if returned value is 1 negotiated at step 2 features are activated successfully. Signed-off-by: Igor Mammedov --- include/hw/i386/ich9.h | 11 ++++++-- hw/i386/pc.c | 4 ++- hw/i386/pc_q35.c | 3 ++- hw/isa/lpc_ich9.c | 58 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h index 72e803f6e2..c28685b753 100644 --- a/include/hw/i386/ich9.h +++ b/include/hw/i386/ich9.h @@ -12,11 +12,14 @@ #include "hw/acpi/acpi.h" #include "hw/acpi/ich9.h" #include "hw/pci/pci_bus.h" +#include "qemu/units.h" =20 void ich9_lpc_set_irq(void *opaque, int irq_num, int level); int ich9_lpc_map_irq(PCIDevice *pci_dev, int intx); PCIINTxRoute ich9_route_intx_pin_to_irq(void *opaque, int pirq_pin); -void ich9_lpc_pm_init(PCIDevice *pci_lpc, bool smm_enabled); +void ich9_lpc_pm_init(PCIDevice *pci_lpc, bool smm_enabled, + MemoryRegion *system_memory, MemoryRegion *ram, + MemoryRegion *smram); I2CBus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base); =20 void ich9_generate_smi(void); @@ -71,6 +74,8 @@ typedef struct ICH9LPCState { uint8_t smi_features_ok; /* guest-visible, read-only; selecti= ng it * triggers feature lockdown */ uint64_t smi_negotiated_features; /* guest-invisible, host endian */ + MemoryRegion smbase_blackhole; + MemoryRegion smbase_window; =20 /* isa bus */ ISABus *isa_bus; @@ -248,5 +253,7 @@ typedef struct ICH9LPCState { =20 /* bit positions used in fw_cfg SMI feature negotiation */ #define ICH9_LPC_SMI_F_BROADCAST_BIT 0 - +#define ICH9_LPC_SMI_F_LOCKED_SMBASE_BIT 1 +#define ICH9_LPC_SMBASE_ADDR 0x30000 +#define ICH9_LPC_SMBASE_RAM_SIZE (128 * KiB) #endif /* HW_ICH9_H */ diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c14ed86439..99a98303eb 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -119,7 +119,9 @@ struct hpet_fw_config hpet_cfg =3D {.count =3D UINT8_MA= X}; /* Physical Address of PVH entry point read from kernel ELF NOTE */ static size_t pvh_start_addr; =20 -GlobalProperty pc_compat_4_1[] =3D {}; +GlobalProperty pc_compat_4_1[] =3D { + { "ICH9-LPC", "x-smi-locked-smbase", "off" }, +}; const size_t pc_compat_4_1_len =3D G_N_ELEMENTS(pc_compat_4_1); =20 GlobalProperty pc_compat_4_0[] =3D {}; diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index d4e8a1cb9f..50462686a0 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -292,7 +292,8 @@ static void pc_q35_init(MachineState *machine) 0xff0104); =20 /* connect pm stuff to lpc */ - ich9_lpc_pm_init(lpc, pc_machine_is_smm_enabled(pcms)); + ich9_lpc_pm_init(lpc, pc_machine_is_smm_enabled(pcms), get_system_memo= ry(), + ram_memory, MEMORY_REGION(object_resolve_path("/machine/smram", NU= LL))); =20 if (pcms->sata_enabled) { /* ahci and SATA device, for q35 1 ahci controller is built-in */ diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c index 17c292e306..17a8cd1b51 100644 --- a/hw/isa/lpc_ich9.c +++ b/hw/isa/lpc_ich9.c @@ -359,6 +359,38 @@ static void ich9_set_sci(void *opaque, int irq_num, in= t level) } } =20 +static uint64_t smbase_blackhole_read(void *ptr, hwaddr reg, unsigned size) +{ + return 0xffffffff; +} + +static void smbase_blackhole_write(void *opaque, hwaddr addr, uint64_t val, + unsigned width) +{ + /* nothing */ +} + +static const MemoryRegionOps smbase_blackhole_ops =3D { + .read =3D smbase_blackhole_read, + .write =3D smbase_blackhole_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid.min_access_size =3D 1, + .valid.max_access_size =3D 4, + .impl.min_access_size =3D 4, + .impl.max_access_size =3D 4, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +static void ich9_lpc_smbase_locked_update(ICH9LPCState *lpc) +{ + bool en =3D lpc->smi_negotiated_features & ICH9_LPC_SMI_F_LOCKED_SMBAS= E_BIT; + + memory_region_transaction_begin(); + memory_region_set_enabled(&lpc->smbase_blackhole, en); + memory_region_set_enabled(&lpc->smbase_window, en); + memory_region_transaction_commit(); +} + static void smi_features_ok_callback(void *opaque) { ICH9LPCState *lpc =3D opaque; @@ -379,9 +411,13 @@ static void smi_features_ok_callback(void *opaque) /* valid feature subset requested, lock it down, report success */ lpc->smi_negotiated_features =3D guest_features; lpc->smi_features_ok =3D 1; + + ich9_lpc_smbase_locked_update(lpc); } =20 -void ich9_lpc_pm_init(PCIDevice *lpc_pci, bool smm_enabled) +void ich9_lpc_pm_init(PCIDevice *lpc_pci, bool smm_enabled, + MemoryRegion *system_memory, MemoryRegion *ram, + MemoryRegion *smram) { ICH9LPCState *lpc =3D ICH9_LPC_DEVICE(lpc_pci); qemu_irq sci_irq; @@ -413,6 +449,20 @@ void ich9_lpc_pm_init(PCIDevice *lpc_pci, bool smm_ena= bled) &lpc->smi_features_ok, sizeof lpc->smi_features_ok, true); + + memory_region_init_io(&lpc->smbase_blackhole, OBJECT(lpc), + &smbase_blackhole_ops, NULL, + "smbase-blackhole", ICH9_LPC_SMBASE_RAM_SIZE= ); + memory_region_set_enabled(&lpc->smbase_blackhole, false); + memory_region_add_subregion_overlap(system_memory, ICH9_LPC_SMBASE= _ADDR, + &lpc->smbase_blackhole, 1); + + + memory_region_init_alias(&lpc->smbase_window, OBJECT(lpc), + "smbase-window", ram, + ICH9_LPC_SMBASE_ADDR, ICH9_LPC_SMBASE_RAM_SIZE); + memory_region_set_enabled(&lpc->smbase_window, false); + memory_region_add_subregion(smram, 0x30000, &lpc->smbase_window); } =20 ich9_lpc_reset(DEVICE(lpc)); @@ -508,6 +558,7 @@ static int ich9_lpc_post_load(void *opaque, int version= _id) ich9_lpc_pmbase_sci_update(lpc); ich9_lpc_rcba_update(lpc, 0 /* disabled ICH9_LPC_RCBA_EN */); ich9_lpc_pmcon_update(lpc); + ich9_lpc_smbase_locked_update(lpc); return 0; } =20 @@ -567,6 +618,8 @@ static void ich9_lpc_reset(DeviceState *qdev) memset(lpc->smi_guest_features_le, 0, sizeof lpc->smi_guest_features_l= e); lpc->smi_features_ok =3D 0; lpc->smi_negotiated_features =3D 0; + + ich9_lpc_smbase_locked_update(lpc); } =20 /* root complex register block is mapped into memory space */ @@ -697,6 +750,7 @@ static void ich9_lpc_realize(PCIDevice *d, Error **errp) qdev_init_gpio_out_named(dev, lpc->gsi, ICH9_GPIO_GSI, GSI_NUM_PINS); =20 isa_bus_irqs(isa_bus, lpc->gsi); + } =20 static bool ich9_rst_cnt_needed(void *opaque) @@ -764,6 +818,8 @@ static Property ich9_lpc_properties[] =3D { DEFINE_PROP_BOOL("noreboot", ICH9LPCState, pin_strap.spkr_hi, true), DEFINE_PROP_BIT64("x-smi-broadcast", ICH9LPCState, smi_host_features, ICH9_LPC_SMI_F_BROADCAST_BIT, true), + DEFINE_PROP_BIT64("x-smi-locked-smbase", ICH9LPCState, smi_host_featur= es, + ICH9_LPC_SMI_F_LOCKED_SMBASE_BIT, true), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.18.1 -=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 (#46911): https://edk2.groups.io/g/devel/message/46911 Mute This Topic: https://groups.io/mt/33154821/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-