From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824407; cv=none; d=zohomail.com; s=zohoarc; b=d2m78PQVc61ogqcbb48pPwPCvLCia7sergUIbH7ekQoc6tWGvcqm9T9QfO/mIDFsvhXtL2nLzymtF77jYo9nd1zS1KEy+nuo48s6x1SNoI8eRoiJ/RKxiz6vhFOc4xip7xI1/5g51bNAtO/zZmGjamg7QDnryoBsdRZLP2sar7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824407; 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; bh=sq9FFb5aE+/IiMlVeguENCUMCQ8VCOnFTO/apdVoO2I=; b=a2Zx/zMzF92v0MvBCAEEiUnX+qtSD1fhefuwKs/zHYx23XTI1q2MxAwqRpBmkLgwg3XrnVOpdH6JxHR6exhPrRI7ODjsqQIf7wIxXQ+0t4ZlLGCDaeG8SnLKpGzsY0B3p+JHdFauUyV6nckCDyqDG6NX7CyMTWElMbXuRfL6kJ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657824407256277.64019954790865; Thu, 14 Jul 2022 11:46:47 -0700 (PDT) Received: from localhost ([::1]:49284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3rJ-0002Ti-Av for importer@patchew.org; Thu, 14 Jul 2022 14:46:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aD-0006DO-Mt for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:07 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:59698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3a4-00086W-6E for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:01 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EFs7Bt000894; Thu, 14 Jul 2022 18:28:49 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71xrp10a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:28:49 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGrM8022615; Thu, 14 Jul 2022 18:28:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465jbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:28:48 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiA9017868; Thu, 14 Jul 2022 18:28:48 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-2; Thu, 14 Jul 2022 18:28:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=sq9FFb5aE+/IiMlVeguENCUMCQ8VCOnFTO/apdVoO2I=; b=rLB/ShGxQXRZ7zWHaoPSescBYLerVqn8gdjIr5YXncpELx6EikGRilKtbKECPXDl77UX OHA5Q8ASagYNK1lxlNec3+P3A6mCMEQwM44oHRrQ1ZAIO/MaBcyC2W/8/MD0X8uvUe7/ 2yPBjJ61TGQsZHOmJDObu5mFbu21MsCau7t95zGjvO0UEfaomgztIOs2fdKuqg6+d02C mtRnUIw03PeBdvgXHf3nIOZtxmvdYaUgX8TzUdl8JZP3BEjVcHkzGLDuXZb/nT3SkuwI hgRDYvUKQOWAAYW5R2VVDojfT+GtF/6canx0twGrn0H3UAggt5hwje12YfCJr8ehO/ml Rw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins Subject: [PATCH v7 01/10] hw/i386: add 4g boundary start to X86MachineState Date: Thu, 14 Jul 2022 19:28:11 +0100 Message-Id: <20220714182820.30970-2-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-GUID: oXm1b7mXJPFVfnKMIJU8NoEn8sKbz3UH X-Proofpoint-ORIG-GUID: oXm1b7mXJPFVfnKMIJU8NoEn8sKbz3UH Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824409272100003 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rather than hardcoding the 4G boundary everywhere, introduce a X86MachineState field @above_4g_mem_start and use it accordingly. This is in preparation for relocating ram-above-4g to be dynamically start at 1T on AMD platforms. Signed-off-by: Joao Martins Reviewed-by: Igor Mammedov --- hw/i386/acpi-build.c | 2 +- hw/i386/pc.c | 11 ++++++----- hw/i386/sgx.c | 2 +- hw/i386/x86.c | 1 + include/hw/i386/x86.h | 3 +++ 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index cad6f5ac41e9..0355bd3ddaad 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2024,7 +2024,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, Ma= chineState *machine) build_srat_memory(table_data, mem_base, mem_len, i - 1, MEM_AFFINITY_ENABLED); } - mem_base =3D 1ULL << 32; + mem_base =3D x86ms->above_4g_mem_start; mem_len =3D next_base - x86ms->below_4g_mem_size; next_base =3D mem_base + mem_len; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8d68295fdaff..1660684d12fd 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -850,9 +850,10 @@ void pc_memory_init(PCMachineState *pcms, machine->ram, x86ms->below_4g_mem_size, x86ms->above_4g_mem_size); - memory_region_add_subregion(system_memory, 0x100000000ULL, + memory_region_add_subregion(system_memory, x86ms->above_4g_mem_sta= rt, ram_above_4g); - e820_add_entry(0x100000000ULL, x86ms->above_4g_mem_size, E820_RAM); + e820_add_entry(x86ms->above_4g_mem_start, x86ms->above_4g_mem_size, + E820_RAM); } =20 if (pcms->sgx_epc.size !=3D 0) { @@ -893,7 +894,7 @@ void pc_memory_init(PCMachineState *pcms, machine->device_memory->base =3D sgx_epc_above_4g_end(&pcms->s= gx_epc); } else { machine->device_memory->base =3D - 0x100000000ULL + x86ms->above_4g_mem_size; + x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; } =20 machine->device_memory->base =3D @@ -927,7 +928,7 @@ void pc_memory_init(PCMachineState *pcms, } else if (pcms->sgx_epc.size !=3D 0) { cxl_base =3D sgx_epc_above_4g_end(&pcms->sgx_epc); } else { - cxl_base =3D 0x100000000ULL + x86ms->above_4g_mem_size; + cxl_base =3D x86ms->above_4g_mem_start + x86ms->above_4g_mem_s= ize; } =20 e820_add_entry(cxl_base, cxl_size, E820_RESERVED); @@ -1035,7 +1036,7 @@ uint64_t pc_pci_hole64_start(void) } else if (pcms->sgx_epc.size !=3D 0) { hole64_start =3D sgx_epc_above_4g_end(&pcms->sgx_epc); } else { - hole64_start =3D 0x100000000ULL + x86ms->above_4g_mem_size; + hole64_start =3D x86ms->above_4g_mem_start + x86ms->above_4g_mem_s= ize; } =20 return ROUND_UP(hole64_start, 1 * GiB); diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c index a44d66ba2afc..09d9c7c73d9f 100644 --- a/hw/i386/sgx.c +++ b/hw/i386/sgx.c @@ -295,7 +295,7 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms) return; } =20 - sgx_epc->base =3D 0x100000000ULL + x86ms->above_4g_mem_size; + sgx_epc->base =3D x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; =20 memory_region_init(&sgx_epc->mr, OBJECT(pcms), "sgx-epc", UINT64_MAX); memory_region_add_subregion(get_system_memory(), sgx_epc->base, diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 6003b4b2dfea..029264c54fe2 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1373,6 +1373,7 @@ static void x86_machine_initfn(Object *obj) x86ms->oem_id =3D g_strndup(ACPI_BUILD_APPNAME6, 6); x86ms->oem_table_id =3D g_strndup(ACPI_BUILD_APPNAME8, 8); x86ms->bus_lock_ratelimit =3D 0; + x86ms->above_4g_mem_start =3D 4 * GiB; } =20 static void x86_machine_class_init(ObjectClass *oc, void *data) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 9089bdd99c3a..df82c5fd4252 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -56,6 +56,9 @@ struct X86MachineState { /* RAM information (sizes, addresses, configuration): */ ram_addr_t below_4g_mem_size, above_4g_mem_size; =20 + /* Start address of the initial RAM above 4G */ + uint64_t above_4g_mem_start; + /* CPU and apic information: */ bool apic_xrupt_override; unsigned pci_irq_mask; --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824871; cv=none; d=zohomail.com; s=zohoarc; b=HhWIqV2avz2ij0CMPcmuolRXotU6Rc9tIX7hvcZeWgBrEXCZLOOTtItxqGx5GiBzzh0zo+cXCypceQLjaGC55SyPzes/wxayD3G25YsTT29WlDWJT9+bnfGkbeRPI1WrzzguQGGkkbo2Xwa/9vJoazel6DPgeb7UMumxyI+YYz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824871; 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; bh=fRUaM6BoTCnpEt8yk7mTglXXc901MlgM1s5jUyNf8tE=; b=Smud08PYrih8gUzPoZSnLfqgxOiPyV0XldTwvMV+7TlVge0w51qQqao6sDFToRp07onCYQ1GYYq9mfyPaKYhVoohy0NZt/MfDVtj88SsbVUN7qImWcmjGtgdKAiPPxi5jnoDO20dXfbugx+rXqJNO7J6PBggDMX6JaTBldAIHog= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657824871422762.6080784418289; Thu, 14 Jul 2022 11:54:31 -0700 (PDT) Received: from localhost ([::1]:39602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3yo-0007WY-DE for importer@patchew.org; Thu, 14 Jul 2022 14:54:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3a9-00069p-T3 for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:01 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:3542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3a5-00088E-MO for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:00 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EG4vFl026665; Thu, 14 Jul 2022 18:28:52 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71r1dhwn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:28:52 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGrK2022598; Thu, 14 Jul 2022 18:28:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465je5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:28:51 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAB017868; Thu, 14 Jul 2022 18:28:51 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-3; Thu, 14 Jul 2022 18:28:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=fRUaM6BoTCnpEt8yk7mTglXXc901MlgM1s5jUyNf8tE=; b=cZ8g0RPulytWFY0CI+RvG+8whvh0sHpnogdDJEtrQaEV6A38lFLCwIXV6cNjXg8dWMjf QGrbwUaZG5yhJ9ndutbJNxK6M+9IPcRBxZVxYHkXQA9mvtgVgnuFPj+0re1QfoUUpvQN upUw5aJjsyDzweY/QgR/hGSEeuUI8vitbecqPMrcjukbGFg82jr88qEmVyoXDhbBfvHa GkWzfCOIW0sGZ6JRvn6DWkLR0k4zYq74dPfOuvpU2dMi7f1dAJ6yxmdZ/h7qcwi1pfyk MvboahKj0/g8Bu6H2jzNDYDW9WeTlrRxbfwHYOvCGgluOHrkeeuqYPkcTVxmqOS1vxvR kA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins Subject: [PATCH v7 02/10] i386/pc: create pci-host qdev prior to pc_memory_init() Date: Thu, 14 Jul 2022 19:28:12 +0100 Message-Id: <20220714182820.30970-3-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-ORIG-GUID: hLQ4kczwlNhMvYDLusi1YVoGO89y00P4 X-Proofpoint-GUID: hLQ4kczwlNhMvYDLusi1YVoGO89y00P4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824873549100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" At the start of pc_memory_init() we usually pass a range of 0..UINT64_MAX as pci_memory, when really its 2G (i440fx) or 32G (q35). To get the real user value, we need to get pci-host passed property for default pci_hole64_size. Thus to get that, create the qdev prior to memory init to better make estimations on max used/phys addr. This is in preparation to determine that host-phys-bits are enough and also for pci-hole64-size to be considered to relocate ram-above-4g to be at 1T (on AMD platforms). Signed-off-by: Joao Martins Reviewed-by: Igor Mammedov --- hw/i386/pc_piix.c | 7 +++++-- hw/i386/pc_q35.c | 6 +++--- hw/pci-host/i440fx.c | 5 ++--- include/hw/pci-host/i440fx.h | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index a234989ac363..6186a1473755 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -91,6 +91,7 @@ static void pc_init1(MachineState *machine, MemoryRegion *pci_memory; MemoryRegion *rom_memory; ram_addr_t lowmem; + DeviceState *i440fx_host; =20 /* * Calculate ram split, for memory below and above 4G. It's a bit @@ -164,9 +165,11 @@ static void pc_init1(MachineState *machine, pci_memory =3D g_new(MemoryRegion, 1); memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); rom_memory =3D pci_memory; + i440fx_host =3D qdev_new(host_type); } else { pci_memory =3D NULL; rom_memory =3D system_memory; + i440fx_host =3D NULL; } =20 pc_guest_info_init(pcms); @@ -200,8 +203,8 @@ static void pc_init1(MachineState *machine, const char *type =3D xen_enabled() ? TYPE_PIIX3_XEN_DEVICE : TYPE_PIIX3_DEVICE; =20 - pci_bus =3D i440fx_init(host_type, - pci_type, + pci_bus =3D i440fx_init(pci_type, + i440fx_host, system_memory, system_io, machine->ram_size, x86ms->below_4g_mem_size, x86ms->above_4g_mem_size, diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index f96cbd04e284..46ea89e564de 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -203,12 +203,12 @@ static void pc_q35_init(MachineState *machine) pcms->smbios_entry_point_type); } =20 - /* allocate ram and load rom/bios */ - pc_memory_init(pcms, get_system_memory(), rom_memory, &ram_memory); - /* create pci host bus */ q35_host =3D Q35_HOST_DEVICE(qdev_new(TYPE_Q35_HOST_DEVICE)); =20 + /* allocate ram and load rom/bios */ + pc_memory_init(pcms, get_system_memory(), rom_memory, &ram_memory); + object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host)); object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_RAM_MEM, OBJECT(ram_memory), NULL); diff --git a/hw/pci-host/i440fx.c b/hw/pci-host/i440fx.c index 1c5ad5f918a2..d5426ef4a53c 100644 --- a/hw/pci-host/i440fx.c +++ b/hw/pci-host/i440fx.c @@ -237,7 +237,8 @@ static void i440fx_realize(PCIDevice *dev, Error **errp) } } =20 -PCIBus *i440fx_init(const char *host_type, const char *pci_type, +PCIBus *i440fx_init(const char *pci_type, + DeviceState *dev, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, @@ -246,7 +247,6 @@ PCIBus *i440fx_init(const char *host_type, const char *= pci_type, MemoryRegion *pci_address_space, MemoryRegion *ram_memory) { - DeviceState *dev; PCIBus *b; PCIDevice *d; PCIHostState *s; @@ -254,7 +254,6 @@ PCIBus *i440fx_init(const char *host_type, const char *= pci_type, unsigned i; I440FXState *i440fx; =20 - dev =3D qdev_new(host_type); s =3D PCI_HOST_BRIDGE(dev); b =3D pci_root_bus_new(dev, NULL, pci_address_space, address_space_io, 0, TYPE_PCI_BUS); diff --git a/include/hw/pci-host/i440fx.h b/include/hw/pci-host/i440fx.h index 52518dbf08e6..d02bf1ed6b93 100644 --- a/include/hw/pci-host/i440fx.h +++ b/include/hw/pci-host/i440fx.h @@ -35,7 +35,8 @@ struct PCII440FXState { =20 #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX" =20 -PCIBus *i440fx_init(const char *host_type, const char *pci_type, +PCIBus *i440fx_init(const char *pci_type, + DeviceState *dev, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824701; cv=none; d=zohomail.com; s=zohoarc; b=Nus41y8H51JF62vMKSbHN1fNtq7rAkofTHXCUOeblFCzwZm7RWIhWb13nXI22xPqa+xvfvrKtEa6FRCR6unrpUjz9DmiJ4RVzFJrgEl6DqHqVEBnOgEQytwPqXzOP/S09TxwJM++BkLZQPPG3Z4vkvpHd8/34B63N2PfgxVA7i8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824701; 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; bh=RyPoFbt3mAI749wa3ojwpKVtkxfRL5XMP85RSHN+/wg=; b=FoNJVGZ858I7gvIi3aIYRJdHWqGw/9F4gynDc7rpm7RhZiCyQZEE8wQ95QeLkGlrdn1nuvmeIHMORJb03+WRyx8uO81qNaQkB9ouxhN0V4jE3E9gvz7W1xhSnuisZ1qpsVMm0dAfoZPprWInuZEsKcRa/suC1yCfqB93m4fkuOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657824701031852.1379088622166; Thu, 14 Jul 2022 11:51:41 -0700 (PDT) Received: from localhost ([::1]:57574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3w3-0000NE-VC for importer@patchew.org; Thu, 14 Jul 2022 14:51:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aH-0006EE-JL for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:10 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:57582) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aD-00088k-3c for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:08 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EHe1cx022662; Thu, 14 Jul 2022 18:28:56 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71rg5uj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:28:56 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGr4i022620; Thu, 14 Jul 2022 18:28:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465jh3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:28:55 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAD017868; Thu, 14 Jul 2022 18:28:54 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-4; Thu, 14 Jul 2022 18:28:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=RyPoFbt3mAI749wa3ojwpKVtkxfRL5XMP85RSHN+/wg=; b=elhwgDwbnJYh9gOgokJAkWOHWViMHrGixxb3qy6aJk1YDFYMdjuk1fWDE+hRVZam8Kzw LJP+aNwjCUYphBm49BHay9qawDu1yusrvQGrBB2TDpo0SJwAYDaRcxa/sSnXDynE4Fk+ /FBOgFS5FTYHlvRQBs5FTOoJzIY/XJ4v8las04cDaMzLi8zBaceNO4HEvXhZzgwb49fv 7eTyYvPEqQ4qe+pvNlSgaD0K4dLMB6vbNwgEKAi33lmCMGL8n8zIi68jodCWImVp5YW/ g7Btlit4ftcdf0nc1mVMDRj0JaczADo1h9169taAL/amLxJDikbdcoknM1H5Xddlepn3 +A== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins Subject: [PATCH v7 03/10] i386/pc: pass pci_hole64_size to pc_memory_init() Date: Thu, 14 Jul 2022 19:28:13 +0100 Message-Id: <20220714182820.30970-4-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-GUID: Iu9kOrR_xqNAGf2pJ98jgMa0LkzLbQSP X-Proofpoint-ORIG-GUID: Iu9kOrR_xqNAGf2pJ98jgMa0LkzLbQSP Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824702648100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use the pre-initialized pci-host qdev and fetch the pci-hole64-size into pc_memory_init() newly added argument. Use PCI_HOST_PROP_PCI_HOLE64_SIZE pci-host property for fetching pci-hole64-size. This is in preparation to determine that host-phys-bits are enough and for pci-hole64-size to be considered to relocate ram-above-4g to be at 1T (on AMD platforms). Signed-off-by: Joao Martins Reviewed-by: Igor Mammedov --- hw/i386/pc.c | 3 ++- hw/i386/pc_piix.c | 7 ++++++- hw/i386/pc_q35.c | 10 +++++++++- include/hw/i386/pc.h | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 1660684d12fd..e952dc62a12e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -817,7 +817,8 @@ void xen_load_linux(PCMachineState *pcms) void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, - MemoryRegion **ram_memory) + MemoryRegion **ram_memory, + uint64_t pci_hole64_size) { int linux_boot, i; MemoryRegion *option_rom_mr; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 6186a1473755..2a483e8666b4 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -91,6 +91,7 @@ static void pc_init1(MachineState *machine, MemoryRegion *pci_memory; MemoryRegion *rom_memory; ram_addr_t lowmem; + uint64_t hole64_size; DeviceState *i440fx_host; =20 /* @@ -166,10 +167,14 @@ static void pc_init1(MachineState *machine, memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); rom_memory =3D pci_memory; i440fx_host =3D qdev_new(host_type); + hole64_size =3D object_property_get_uint(OBJECT(i440fx_host), + PCI_HOST_PROP_PCI_HOLE64_SI= ZE, + &error_abort); } else { pci_memory =3D NULL; rom_memory =3D system_memory; i440fx_host =3D NULL; + hole64_size =3D 0; } =20 pc_guest_info_init(pcms); @@ -186,7 +191,7 @@ static void pc_init1(MachineState *machine, /* allocate ram and load rom/bios */ if (!xen_enabled()) { pc_memory_init(pcms, system_memory, - rom_memory, &ram_memory); + rom_memory, &ram_memory, hole64_size); } else { pc_system_flash_cleanup_unused(pcms); if (machine->kernel_filename !=3D NULL) { diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 46ea89e564de..99ed75371c67 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -138,6 +138,7 @@ static void pc_q35_init(MachineState *machine) MachineClass *mc =3D MACHINE_GET_CLASS(machine); bool acpi_pcihp; bool keep_pci_slot_hpc; + uint64_t pci_hole64_size =3D 0; =20 /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping @@ -206,8 +207,15 @@ static void pc_q35_init(MachineState *machine) /* create pci host bus */ q35_host =3D Q35_HOST_DEVICE(qdev_new(TYPE_Q35_HOST_DEVICE)); =20 + if (pcmc->pci_enabled) { + pci_hole64_size =3D object_property_get_uint(OBJECT(q35_host), + PCI_HOST_PROP_PCI_HOLE6= 4_SIZE, + &error_abort); + } + /* allocate ram and load rom/bios */ - pc_memory_init(pcms, get_system_memory(), rom_memory, &ram_memory); + pc_memory_init(pcms, get_system_memory(), rom_memory, &ram_memory, + pci_hole64_size); =20 object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host)); object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_RAM_MEM, diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index b7735dccfc81..568c226d3034 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -159,7 +159,8 @@ void xen_load_linux(PCMachineState *pcms); void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, - MemoryRegion **ram_memory); + MemoryRegion **ram_memory, + uint64_t pci_hole64_size); uint64_t pc_pci_hole64_start(void); DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); void pc_basic_device_init(struct PCMachineState *pcms, --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824897; cv=none; d=zohomail.com; s=zohoarc; b=U9Q1vcR4ZXDRPfIwn3jCKaJek38flkvlEhkmvVv7X+jkQzh0C6TOxD5mols7oT5lIJ0zwYt5j7l2TZE4NQN+2z9kYn0jxW6wwvx7j2hkelQF4ojIOYUs0uuezIhypkgSsvx6G1RJ2c+ZiZBfVI5/JSbdmyqyXz17PY5Wvm26m0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824897; 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; bh=jJoSn1HmBEMdNOoauqZixXNzsONSuXugygiibVftDf4=; b=izYLqelu9aJIgVEe1vzStOgRiBmW5t8FtNfTbAg3HKHKmerxGxlIG0DowcjN887oGrZCHHjSHT+SH5PypsAI2JIbLSb8rtFqXn2w4xLWYKeJ5vKI+ghuPQ7UL79t89LUHB7bt8rpHP4oWJRMpboSz9B69jqCFbhMjBVccMz0xak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16578248975261006.960108711816; Thu, 14 Jul 2022 11:54:57 -0700 (PDT) Received: from localhost ([::1]:41840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3zE-0000gn-CV for importer@patchew.org; Thu, 14 Jul 2022 14:54:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aH-0006EF-KR for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:10 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:20198) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aF-00089Y-91 for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:09 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EG79YJ026610; Thu, 14 Jul 2022 18:29:03 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71r1dhxd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:02 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGrMG022615; Thu, 14 Jul 2022 18:29:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465jpk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:02 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAF017868; Thu, 14 Jul 2022 18:29:01 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-5; Thu, 14 Jul 2022 18:29:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=jJoSn1HmBEMdNOoauqZixXNzsONSuXugygiibVftDf4=; b=IYaiLgFYCXoI0uhPZuVP5NnEgG5WZev7x0tiGXDrcG5N9b5R0hXbvoAKcGB4Vz6E8xZ8 d+jbjqqFAHaTP2SXpqCHuO75+lysBIys+F2ggedudDG2Lj6PomI7qmgfhfjbh5T8/qNO kiheZs4AKpeQefPwcL0zVq4uBhs8F4F8YibyzzO0fU8T4i41Nw8fuj2t84dYwRZtzs27 oxz9+T143DyQpix3fEtKkQDXpMmQLXORE3IBF5ZQyKclRJQiVX7Y10oxAfJHE+WwZIPd +SRBiepkRd9fcdsWn5atr+1waqfWRj29qMsozR7WCqhHOs38YM5dNFN7tTNfQsdOuTgR 3w== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins Subject: [PATCH v7 04/10] i386/pc: factor out above-4g end to an helper Date: Thu, 14 Jul 2022 19:28:14 +0100 Message-Id: <20220714182820.30970-5-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-ORIG-GUID: aLvKWUC8jWlfb7sSU-bBydsoxYnSYNa2 X-Proofpoint-GUID: aLvKWUC8jWlfb7sSU-bBydsoxYnSYNa2 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824899699100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There's a couple of places that seem to duplicate this calculation of RAM size above the 4G boundary. Move all those to a helper function. Signed-off-by: Joao Martins Reviewed-by: Igor Mammedov --- hw/i386/pc.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e952dc62a12e..216e38da938e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -814,6 +814,17 @@ void xen_load_linux(PCMachineState *pcms) #define PC_ROM_ALIGN 0x800 #define PC_ROM_SIZE (PC_ROM_MAX - PC_ROM_MIN_VGA) =20 +static hwaddr pc_above_4g_end(PCMachineState *pcms) +{ + X86MachineState *x86ms =3D X86_MACHINE(pcms); + + if (pcms->sgx_epc.size !=3D 0) { + return sgx_epc_above_4g_end(&pcms->sgx_epc); + } + + return x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; +} + void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, @@ -891,15 +902,8 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 - if (pcms->sgx_epc.size !=3D 0) { - machine->device_memory->base =3D sgx_epc_above_4g_end(&pcms->s= gx_epc); - } else { - machine->device_memory->base =3D - x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; - } - machine->device_memory->base =3D - ROUND_UP(machine->device_memory->base, 1 * GiB); + ROUND_UP(pc_above_4g_end(pcms), 1 * GiB); =20 if (pcmc->enforce_aligned_dimm) { /* size device region assuming 1G page max alignment per slot = */ @@ -929,7 +933,7 @@ void pc_memory_init(PCMachineState *pcms, } else if (pcms->sgx_epc.size !=3D 0) { cxl_base =3D sgx_epc_above_4g_end(&pcms->sgx_epc); } else { - cxl_base =3D x86ms->above_4g_mem_start + x86ms->above_4g_mem_s= ize; + cxl_base =3D pc_above_4g_end(pcms); } =20 e820_add_entry(cxl_base, cxl_size, E820_RESERVED); @@ -1016,7 +1020,6 @@ uint64_t pc_pci_hole64_start(void) PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); MachineState *ms =3D MACHINE(pcms); - X86MachineState *x86ms =3D X86_MACHINE(pcms); uint64_t hole64_start =3D 0; =20 if (pcms->cxl_devices_state.host_mr.addr) { @@ -1034,10 +1037,8 @@ uint64_t pc_pci_hole64_start(void) if (!pcmc->broken_reserved_end) { hole64_start +=3D memory_region_size(&ms->device_memory->mr); } - } else if (pcms->sgx_epc.size !=3D 0) { - hole64_start =3D sgx_epc_above_4g_end(&pcms->sgx_epc); } else { - hole64_start =3D x86ms->above_4g_mem_start + x86ms->above_4g_mem_s= ize; + hole64_start =3D pc_above_4g_end(pcms); } =20 return ROUND_UP(hole64_start, 1 * GiB); --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657825096; cv=none; d=zohomail.com; s=zohoarc; b=mLhQ75eCcOJGBG6eDqQz7xwATRVXgQJCJWtSxSteprKYif9KfsrXiJbYYCYSjvG3E0L98c09ffyPhzePmLdkGVVHf6MPd5aPFNXn8hNU0375im+7Tw/dDL1fJ4yZB2971K52dYpxKMIxcv1O18WNzbQBFqGyfkt31b/mTA1+cUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657825096; 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; bh=hq5mJURNPywV3PpDv35HVSjIBFNdwdX9ZcaGHJwDSZE=; b=eXXeAMVSsRsMEAYVLon+xSuBlrOMnyb1tpxGIiiK8yXiTaeoXalD0nHYurYCqIqkwWfUB7W4oYP3iko6GR1KfM5gBLoqk5X9+d7284IXAa3xv5NiWNg/4QIdwhPS95xRNFZz1q6QvZvn7AHoC7AGrgnlGjsMcaOaXd0P39TAnoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657825096778360.26667997250263; Thu, 14 Jul 2022 11:58:16 -0700 (PDT) Received: from localhost ([::1]:50334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC42R-0006Wi-GD for importer@patchew.org; Thu, 14 Jul 2022 14:58:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aP-0006IU-Dg for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:17 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:36196) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aN-0008AE-5L for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:17 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EIO5sl008512; Thu, 14 Jul 2022 18:29:07 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71sce55b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:07 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGx2E022921; Thu, 14 Jul 2022 18:29:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465jrw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:05 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAH017868; Thu, 14 Jul 2022 18:29:05 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-6; Thu, 14 Jul 2022 18:29:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=hq5mJURNPywV3PpDv35HVSjIBFNdwdX9ZcaGHJwDSZE=; b=U9z8EFDoCyinutnZ+KCajtxpUm/aZ96PtdOo0J2hr6xM2ZqooMPZujhwbF/WK5wHdCLa iZWzSpcSre5ofIHsnJdZRppG471qujrRCJEw4bP+VRfPxNEqPBTJ0Zu9/6EkIhvTJOB1 u8aPzB0U21XdUSKZO26IqruMhSf8RVGzsVLBsev3hEl5Gk5CD4URdVo2NluDcIareec7 QnpMvA5yvAw025vw0z/HhPahsbrV4xBLRjmuHJJ+sM79c5p9LAMlSMlVKV4rSBIsa3Rt nC6u8UOdmYNcaUVkw1kMyMVXWYdIoCReDaa2RPdJCgwMIsLKlCFrBMfpcBtyAOp5yUTQ Uw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins , Jonathan Cameron Subject: [PATCH v7 05/10] i386/pc: factor out cxl range end to helper Date: Thu, 14 Jul 2022 19:28:15 +0100 Message-Id: <20220714182820.30970-6-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-GUID: IRgR1Xz2MocJ2mqvh-NjjIJMwbZ3CI0V X-Proofpoint-ORIG-GUID: IRgR1Xz2MocJ2mqvh-NjjIJMwbZ3CI0V Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657825098878100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move calculation of CXL memory region end to separate helper. This is in preparation to a future change that removes CXL range dependency on the CXL memory region, with the goal of allowing pc_pci_hole64_start() to be called before any memory region are initialized. Cc: Jonathan Cameron Signed-off-by: Joao Martins --- hw/i386/pc.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 216e38da938e..1f42f194d7b7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -825,6 +825,25 @@ static hwaddr pc_above_4g_end(PCMachineState *pcms) return x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; } =20 +static uint64_t pc_get_cxl_range_end(PCMachineState *pcms) +{ + uint64_t start =3D 0; + + if (pcms->cxl_devices_state.host_mr.addr) { + start =3D pcms->cxl_devices_state.host_mr.addr + + memory_region_size(&pcms->cxl_devices_state.host_mr); + if (pcms->cxl_devices_state.fixed_windows) { + GList *it; + for (it =3D pcms->cxl_devices_state.fixed_windows; it; it =3D = it->next) { + CXLFixedWindow *fw =3D it->data; + start =3D fw->mr.addr + memory_region_size(&fw->mr); + } + } + } + + return start; +} + void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, @@ -1022,16 +1041,8 @@ uint64_t pc_pci_hole64_start(void) MachineState *ms =3D MACHINE(pcms); uint64_t hole64_start =3D 0; =20 - if (pcms->cxl_devices_state.host_mr.addr) { - hole64_start =3D pcms->cxl_devices_state.host_mr.addr + - memory_region_size(&pcms->cxl_devices_state.host_mr); - if (pcms->cxl_devices_state.fixed_windows) { - GList *it; - for (it =3D pcms->cxl_devices_state.fixed_windows; it; it =3D = it->next) { - CXLFixedWindow *fw =3D it->data; - hole64_start =3D fw->mr.addr + memory_region_size(&fw->mr); - } - } + if (pcms->cxl_devices_state.is_enabled) { + hole64_start =3D pc_get_cxl_range_end(pcms); } else if (pcmc->has_reserved_memory && ms->device_memory->base) { hole64_start =3D ms->device_memory->base; if (!pcmc->broken_reserved_end) { --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657825292; cv=none; d=zohomail.com; s=zohoarc; b=QnQuraMd7lR94xB+kpr5wcShjfXs7y6bL4ukEqrhNBBF5Zoqip/1nJD3wJI9nWYPbW5EoV09wHqcPYR9LF74zgJyuXR5u0r5zZ/FJZOZ4LF5XRd7a6xKz5TFiim7irmvk+6shrmEqpDHG9lMGlGGVHJbtmz/yg6sMJxWv+p/dK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657825292; 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; bh=dZJg5Qqp7i7DCTW/Km8ltqv0w9oagbAspbdK2T1L0Hs=; b=LLkpzG3jZuAXostO68besAVQBdtu1FlwkxwmjRoAucUAIHmGl9+6pUEpHtxCnz+8lTfD+t+XuXwM/PR4ZwxUaTbjlfeQt9K+8lMFZ1vN7psnEwXk4jh5cUAxdnDw1BGgCvy5VyEoDDuY10icFpCKCJDhjUVV40Yw68scXBJbczE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16578252925631011.1899306963649; Thu, 14 Jul 2022 12:01:32 -0700 (PDT) Received: from localhost ([::1]:58890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC45b-0003th-K5 for importer@patchew.org; Thu, 14 Jul 2022 15:01:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aQ-0006O7-OY for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:18 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:39002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aO-0008AN-VG for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:18 -0400 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EFtIbW008504; Thu, 14 Jul 2022 18:29:10 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71sce55s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:09 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGs5e022671; Thu, 14 Jul 2022 18:29:09 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465juq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:09 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAJ017868; Thu, 14 Jul 2022 18:29:08 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-7; Thu, 14 Jul 2022 18:29:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=dZJg5Qqp7i7DCTW/Km8ltqv0w9oagbAspbdK2T1L0Hs=; b=SCHV40wBfQvkrJt9UmXi8O6AA4FuL2RVPNyZvUtO9jRM+oC3I0iCwGMu++yaY1XcIKyK V9+9P3K7Ew63KgCvyfDUSUGIcOEPZbhHp5RUPghNyo5hnhoyTwA9zButXVK185OiK3Y/ LDPazbBmN9r/YBUvYBJTf7pcHKKF8Zccks/QUD74Wi/S8KE/xG07bBcab0aMjaWJJQEx 5CwNlYco3ovg1AGy4s2Wdz3l4zvZHKPVbqwNanmEmVEuBNAyOPOzozNWpgVca09x0dNL XvlkgtQaUI9pFPlo7Bw0dlX1fiRwsOOz+6wpDYpPxJhIf49EN3PKczrOmjuxghmt3Qtb XA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins , Jonathan Cameron Subject: [PATCH v7 06/10] i386/pc: factor out cxl range start to helper Date: Thu, 14 Jul 2022 19:28:16 +0100 Message-Id: <20220714182820.30970-7-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-GUID: obMRcVsA4SHoIgGgjBgGTIfyIRcWv3b9 X-Proofpoint-ORIG-GUID: obMRcVsA4SHoIgGgjBgGTIfyIRcWv3b9 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657825292996100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Factor out the calculation of the base address of the memory region. It will be used later on for the cxl range end counterpart calculation and as well in pc_memory_init() CXL memory region initialization, thus avoiding duplication. Cc: Jonathan Cameron Signed-off-by: Joao Martins --- hw/i386/pc.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 1f42f194d7b7..3fdcab4bb4f3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -825,6 +825,22 @@ static hwaddr pc_above_4g_end(PCMachineState *pcms) return x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; } =20 +static uint64_t pc_get_cxl_range_start(PCMachineState *pcms) +{ + PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); + MachineState *machine =3D MACHINE(pcms); + hwaddr cxl_base; + + if (pcmc->has_reserved_memory && machine->device_memory->base) { + cxl_base =3D machine->device_memory->base + + memory_region_size(&machine->device_memory->mr); + } else { + cxl_base =3D pc_above_4g_end(pcms); + } + + return cxl_base; +} + static uint64_t pc_get_cxl_range_end(PCMachineState *pcms) { uint64_t start =3D 0; @@ -946,15 +962,7 @@ void pc_memory_init(PCMachineState *pcms, MemoryRegion *mr =3D &pcms->cxl_devices_state.host_mr; hwaddr cxl_size =3D MiB; =20 - if (pcmc->has_reserved_memory && machine->device_memory->base) { - cxl_base =3D machine->device_memory->base - + memory_region_size(&machine->device_memory->mr); - } else if (pcms->sgx_epc.size !=3D 0) { - cxl_base =3D sgx_epc_above_4g_end(&pcms->sgx_epc); - } else { - cxl_base =3D pc_above_4g_end(pcms); - } - + cxl_base =3D pc_get_cxl_range_start(pcms); e820_add_entry(cxl_base, cxl_size, E820_RESERVED); memory_region_init(mr, OBJECT(machine), "cxl_host_reg", cxl_size); memory_region_add_subregion(system_memory, cxl_base, mr); --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824261; cv=none; d=zohomail.com; s=zohoarc; b=mJlJ9g5dE/BgxDva5+ikavPJ2bMATJmX8YyhkhPDinZzJDE8QPpq+smb58VtgUxZITIoIHdjjldvhDGWsaQrk+0TvEwWQ6leeDLteKTuDR/eUtuQB7EqQAmcIRZQBX3HcGhH95EldzqjpIYkvR19wiQvuMgmCaHP3xa8UpuBFUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824261; 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; bh=QMNe8ckb12GEwHvHx5t8fcVVzc8ilxAjIE96wJm3nAE=; b=dhi1DNcN98wTgjBs7J52qlHhk5Ak6KARS212k0kvTqOpBKXEV8rIYEIHxay0bR3CMeXILMK8+r9ecJhf6QRtaPUk/WJs+DvJ97N3MCqeNN4We4y8O90UHqgYDb5Trnnqh9PfplNeh7ChPEvDUF0natJIDWIy1oJcKTiLcq+mDJk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657824261040930.2053625149911; Thu, 14 Jul 2022 11:44:21 -0700 (PDT) Received: from localhost ([::1]:47504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3ox-0001Cz-VT for importer@patchew.org; Thu, 14 Jul 2022 14:44:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aU-0006UJ-1B for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:23 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:45932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aS-0008Ah-FB for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:21 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EG79YR026610; Thu, 14 Jul 2022 18:29:13 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71r1dhy7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:13 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGsEZ022699; Thu, 14 Jul 2022 18:29:13 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465jxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:13 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAL017868; Thu, 14 Jul 2022 18:29:12 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-8; Thu, 14 Jul 2022 18:29:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=QMNe8ckb12GEwHvHx5t8fcVVzc8ilxAjIE96wJm3nAE=; b=EHUKcQdasr5resjdYI0fU7fTKTMXJbFuc/LKiLrf0vp7WwmtJJWbEVI7UXZXzIfuTonu sKnuHnBpmlJWj20f08g8a4l5hwTSDwLQF0aIvV0mQE/0JcR0gxaq9xUfmYC/h2SiSd0K qcEavpSZHvMbd1/N6m9sFdLaKvW32Q9npT0vq86cIcXibpkoJQMSjje7zuiP4wos5V7G n6jG4w70V4Bt+det0v46ju1AvvGBKgWyQ/K11d4HRomzX99AJqSBTAQN2XnncOT4g3hm URFqMXog2qJrhWHrFAzPgUdDg6Cgk0O7GWA+Tck7OjVqW2zW5Yct/Tan1/8MJpMnTBog Iw== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins , Jonathan Cameron Subject: [PATCH v7 07/10] i386/pc: handle unitialized mr in pc_get_cxl_range_end() Date: Thu, 14 Jul 2022 19:28:17 +0100 Message-Id: <20220714182820.30970-8-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-ORIG-GUID: m22fcFL5xFBiaX5Nggr0E2tOtdKJYIYm X-Proofpoint-GUID: m22fcFL5xFBiaX5Nggr0E2tOtdKJYIYm Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824261884100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Remove pc_get_cxl_range_end() dependency on the CXL memory region, and replace with one that does not require the CXL host_mr to determine the start of CXL start. This in preparation to allow pc_pci_hole64_start() to be called early in pc_memory_init(), handle CXL memory region end when its underlying memory region isn't yet initialized. Cc: Jonathan Cameron Signed-off-by: Joao Martins --- hw/i386/pc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 3fdcab4bb4f3..c654be6cf0bd 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -843,17 +843,15 @@ static uint64_t pc_get_cxl_range_start(PCMachineState= *pcms) =20 static uint64_t pc_get_cxl_range_end(PCMachineState *pcms) { - uint64_t start =3D 0; + uint64_t start =3D pc_get_cxl_range_start(pcms) + MiB; =20 - if (pcms->cxl_devices_state.host_mr.addr) { - start =3D pcms->cxl_devices_state.host_mr.addr + - memory_region_size(&pcms->cxl_devices_state.host_mr); - if (pcms->cxl_devices_state.fixed_windows) { - GList *it; - for (it =3D pcms->cxl_devices_state.fixed_windows; it; it =3D = it->next) { - CXLFixedWindow *fw =3D it->data; - start =3D fw->mr.addr + memory_region_size(&fw->mr); - } + if (pcms->cxl_devices_state.fixed_windows) { + GList *it; + + start =3D ROUND_UP(start, 256 * MiB); + for (it =3D pcms->cxl_devices_state.fixed_windows; it; it =3D it->= next) { + CXLFixedWindow *fw =3D it->data; + start +=3D fw->size; } } =20 --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824628; cv=none; d=zohomail.com; s=zohoarc; b=f8yRHHR9usD57IwtEXWzk7lD6zj0yKIWRRh7HRUz5xAJGj0fn6zQj+teGfmytaY1c9vLleFvHNottmyexYhi4wTWuBPCcps5Ffp4Mfj/gJnXcfaCLZOAHL5sw6YAMBRN1iI2qUEBe+qiKRxoTx8BivOsrC5Xt7N89eK3In059d4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824628; 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; bh=FIBpiDX4j9bmOfAGrzs/qcReNbLF1JTIooWk6DwGGY0=; b=f49LrgzTg88vphcyqUvpACJIr1T9pkYOZANafg2hGxxZTFCNPz2Uot4XorhKgjZB4Rrj24MnuWGEhN6KwXNMYzSyZwpb/uN+bXTDXGnr4oQ8BvD9muNQhxRtRZzHe+XL3HzqnjByLU1TuxjkqXz8s0/0mrbCygWOF4OnEtzzb1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657824628702955.8115095835738; Thu, 14 Jul 2022 11:50:28 -0700 (PDT) Received: from localhost ([::1]:55844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3us-0007Tm-Kt for importer@patchew.org; Thu, 14 Jul 2022 14:50:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aX-0006YQ-PS for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:26 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:51574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aV-0008B9-25 for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:24 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EFs7CB000894; Thu, 14 Jul 2022 18:29:17 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71xrp127-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:16 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGrBo022632; Thu, 14 Jul 2022 18:29:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465k0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:16 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAN017868; Thu, 14 Jul 2022 18:29:15 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-9; Thu, 14 Jul 2022 18:29:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=FIBpiDX4j9bmOfAGrzs/qcReNbLF1JTIooWk6DwGGY0=; b=lZ6P1KsTV3bvkFEokAYdk8aUzzMMueWurcfhtJY/RVe9baMI7XJOYuG2BOhdb8M2LofN diD8Ypg2u9qY4NzqLH2hYe8WcN7J8c2lurjVk8NSL787cSd9YO9qP+eq0b6O5ZDuBD+M XOg3+6VfU34svTZfnOZtU6VP3Njxiujz983qN7Nuz9gAAUMC5XePoxYC43iQH9waieoE 3LIBw61uluP0KPyUt1xU51NJILZB+7ggnpFNEOLRdW8DwdBetThXG42tznzRWo0jn4yV HfzegF8hMby3jCKCPFBGoUO7lYBTm35BEqas6uBCC/MQCwvi/dXsTWo//dBrxnSeRHvm uA== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins , Jonathan Cameron Subject: [PATCH v7 08/10] i386/pc: factor out device_memory base/size to helper Date: Thu, 14 Jul 2022 19:28:18 +0100 Message-Id: <20220714182820.30970-9-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-GUID: MLCcyy9E6NB6jwFB__pUmkJPI0xFGBkH X-Proofpoint-ORIG-GUID: MLCcyy9E6NB6jwFB__pUmkJPI0xFGBkH Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824630370100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move obtaining hole64_start from device_memory memory region base/size into an helper alongside correspondent getters in pc_memory_init() when the hotplug range is unitialized. While doing that remove the memory region based logic from this newly added helper. This is the final step that allows pc_pci_hole64_start() to be callable at the beginning of pc_memory_init() before any memory regions are initialized. Cc: Jonathan Cameron Signed-off-by: Joao Martins --- hw/i386/pc.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c654be6cf0bd..cda435e3baeb 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -825,15 +825,37 @@ static hwaddr pc_above_4g_end(PCMachineState *pcms) return x86ms->above_4g_mem_start + x86ms->above_4g_mem_size; } =20 -static uint64_t pc_get_cxl_range_start(PCMachineState *pcms) +static void pc_get_device_memory_range(PCMachineState *pcms, + hwaddr *base, + ram_addr_t *device_mem_size) { PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); MachineState *machine =3D MACHINE(pcms); + ram_addr_t size; + hwaddr addr; + + size =3D machine->maxram_size - machine->ram_size; + addr =3D ROUND_UP(pc_above_4g_end(pcms), 1 * GiB); + + if (pcmc->enforce_aligned_dimm) { + /* size device region assuming 1G page max alignment per slot */ + size +=3D (1 * GiB) * machine->ram_slots; + } + + *base =3D addr; + *device_mem_size =3D size; +} + + +static uint64_t pc_get_cxl_range_start(PCMachineState *pcms) +{ + PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); hwaddr cxl_base; + ram_addr_t size; =20 - if (pcmc->has_reserved_memory && machine->device_memory->base) { - cxl_base =3D machine->device_memory->base - + memory_region_size(&machine->device_memory->mr); + if (pcmc->has_reserved_memory) { + pc_get_device_memory_range(pcms, &cxl_base, &size); + cxl_base +=3D size; } else { cxl_base =3D pc_above_4g_end(pcms); } @@ -920,7 +942,7 @@ void pc_memory_init(PCMachineState *pcms, /* initialize device memory address space */ if (pcmc->has_reserved_memory && (machine->ram_size < machine->maxram_size)) { - ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; + ram_addr_t device_mem_size; =20 if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { error_report("unsupported amount of memory slots: %"PRIu64, @@ -935,13 +957,7 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 - machine->device_memory->base =3D - ROUND_UP(pc_above_4g_end(pcms), 1 * GiB); - - if (pcmc->enforce_aligned_dimm) { - /* size device region assuming 1G page max alignment per slot = */ - device_mem_size +=3D (1 * GiB) * machine->ram_slots; - } + pc_get_device_memory_range(pcms, &machine->device_memory->base, &d= evice_mem_size); =20 if ((machine->device_memory->base + device_mem_size) < device_mem_size) { @@ -1046,13 +1062,14 @@ uint64_t pc_pci_hole64_start(void) PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); MachineState *ms =3D MACHINE(pcms); uint64_t hole64_start =3D 0; + ram_addr_t size =3D 0; =20 if (pcms->cxl_devices_state.is_enabled) { hole64_start =3D pc_get_cxl_range_end(pcms); - } else if (pcmc->has_reserved_memory && ms->device_memory->base) { - hole64_start =3D ms->device_memory->base; + } else if (pcmc->has_reserved_memory && (ms->ram_size < ms->maxram_siz= e)) { + pc_get_device_memory_range(pcms, &hole64_start, &size); if (!pcmc->broken_reserved_end) { - hole64_start +=3D memory_region_size(&ms->device_memory->mr); + hole64_start +=3D size; } } else { hole64_start =3D pc_above_4g_end(pcms); --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657824838; cv=none; d=zohomail.com; s=zohoarc; b=IHCsUbN8um2tfArmsL1Qe5BnjUi59dzujkcVUGnfEqMecrNklfP8rDcOaIHFESofSTzt/UsnPf/w0wAvlcuxNVnaIZ3oxu0HR8IDNJGFxSSLO1q3sjKs88nUPnU/X8KCzF2BsTr3UD3VsEuuJ96vxn9tlHwW6ZzubAXgwCRaooQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657824838; 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; bh=JSXGpwgrvy55zX/uH/pYIejBEgnsU2Bb1t2fGKxAR/I=; b=JCYt87Dx+VwovS2HQrkmTCPTqMWxJpFUUe9o2dN1HBh4eyLjJmLAnNtIi0PNfS1m8Q6jh4sRMOqfKtxK+wEgCdiLGfbfwGaLWDd933iFa+CyV64+x4f4OYE0EADui7nSfJ/3rkIH9pdH3XRm042IlTCFbfmCkZNvHxTrfniBE/I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657824838414506.99211697646956; Thu, 14 Jul 2022 11:53:58 -0700 (PDT) Received: from localhost ([::1]:38086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC3yH-0006SD-Dx for importer@patchew.org; Thu, 14 Jul 2022 14:53:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3ab-0006aR-Cw for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:30 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:43586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3aY-0008Bb-FJ for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:28 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EG69Os026590; Thu, 14 Jul 2022 18:29:21 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71sgwatf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:21 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGrfx022626; Thu, 14 Jul 2022 18:29:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465k2u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:19 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAP017868; Thu, 14 Jul 2022 18:29:19 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-10; Thu, 14 Jul 2022 18:29:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=JSXGpwgrvy55zX/uH/pYIejBEgnsU2Bb1t2fGKxAR/I=; b=W5b3goYH28Zn3f3Eo86i+PZBQWFCXBnOzYGZzfjo4fkkuszukd/edi/PX0gfOjAKgWlk BW3gfue8yQRgzhIAGhMelhBpCvM3xwwmBk6D1YV8HgqS7yyO++7SplbZJ3Xom2Yatu+t k+vIggePrI1WJloiswSbOeR9rFxzIPL9G6P/BTy4VMC+hiFBwA2u31nFQoCF5tIB3FbZ KEeRjU4fnGp7BUMvswkEomjxUsjBPvl88VlD3P81tIcZRaDqwgyJbt/DjGKEejqvjvYu stvEg62k6y9oCaQ4ANJbGwjWSotsoSK/Pgd6Dx7sXHCrjuPGCHbyEs+qZgbMkMgf5HxD Fg== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins Subject: [PATCH v7 09/10] i386/pc: relocate 4g start to 1T where applicable Date: Thu, 14 Jul 2022 19:28:19 +0100 Message-Id: <20220714182820.30970-10-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-GUID: E49Exw6nnHWTXzP6g5TuSbL3oHrhrknE X-Proofpoint-ORIG-GUID: E49Exw6nnHWTXzP6g5TuSbL3oHrhrknE Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657824839564100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is assumed that the whole GPA space is available to be DMA addressable, within a given address space limit, except for a tiny region before the 4G. Since Linux v5.4, VFIO validates whether the selected GPA is indeed valid i.e. not reserved by IOMMU on behalf of some specific devices or platform-defined restrictions, and thus failing the ioctl(VFIO_DMA_MAP) with -EINVAL. AMD systems with an IOMMU are examples of such platforms and particularly may only have these ranges as allowed: 0000000000000000 - 00000000fedfffff (0 .. 3.982G) 00000000fef00000 - 000000fcffffffff (3.983G .. 1011.9G) 0000010000000000 - ffffffffffffffff (1Tb .. 16Pb[*]) We already account for the 4G hole, albeit if the guest is big enough we will fail to allocate a guest with >1010G due to the ~12G hole at the 1Tb boundary, reserved for HyperTransport (HT). [*] there is another reserved region unrelated to HT that exists in the 256T boundary in Fam 17h according to Errata #1286, documeted also in "Open-Source Register Reference for AMD Family 17h Processors (PUB)" When creating the region above 4G, take into account that on AMD platforms the HyperTransport range is reserved and hence it cannot be used either as GPAs. On those cases rather than establishing the start of ram-above-4g to be 4G, relocate instead to 1Tb. See AMD IOMMU spec, section 2.1.2 "IOMMU Logical Topology", for more information on the underlying restriction of IOVAs. After accounting for the 1Tb hole on AMD hosts, mtree should look like: 0000000000000000-000000007fffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-000000007fffffff 0000010000000000-000001ff7fffffff (prio 0, i/o): alias ram-above-4g @pc.ram 0000000080000000-000000ffffffffff If the relocation is done or the address space covers it, we also add the the reserved HT e820 range as reserved. Default phys-bits on Qemu is TCG_PHYS_ADDR_BITS (40) which is enough to address 1Tb (0xff ffff ffff). On AMD platforms, if a ram-above-4g relocation may be desired and the CPU wasn't configured with a big enough phys-bits, print an error message to the user and do not make the relocation of the above-4g-region if phys-bits is too low. Suggested-by: Igor Mammedov Signed-off-by: Joao Martins --- hw/i386/pc.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index cda435e3baeb..17613974163e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -880,6 +880,52 @@ static uint64_t pc_get_cxl_range_end(PCMachineState *p= cms) return start; } =20 +static hwaddr pc_max_used_gpa(PCMachineState *pcms, uint64_t pci_hole64_si= ze) +{ + X86CPU *cpu =3D X86_CPU(first_cpu); + + /* 32-bit systems don't have hole64 thus return max CPU address */ + if (cpu->phys_bits <=3D 32) { + return ((hwaddr)1 << cpu->phys_bits) - 1; + } + + return pc_pci_hole64_start() + pci_hole64_size - 1; +} + +/* + * AMD systems with an IOMMU have an additional hole close to the + * 1Tb, which are special GPAs that cannot be DMA mapped. Depending + * on kernel version, VFIO may or may not let you DMA map those ranges. + * Starting Linux v5.4 we validate it, and can't create guests on AMD mach= ines + * with certain memory sizes. It's also wrong to use those IOVA ranges + * in detriment of leading to IOMMU INVALID_DEVICE_REQUEST or worse. + * The ranges reserved for Hyper-Transport are: + * + * FD_0000_0000h - FF_FFFF_FFFFh + * + * The ranges represent the following: + * + * Base Address Top Address Use + * + * FD_0000_0000h FD_F7FF_FFFFh Reserved interrupt address space + * FD_F800_0000h FD_F8FF_FFFFh Interrupt/EOI IntCtl + * FD_F900_0000h FD_F90F_FFFFh Legacy PIC IACK + * FD_F910_0000h FD_F91F_FFFFh System Management + * FD_F920_0000h FD_FAFF_FFFFh Reserved Page Tables + * FD_FB00_0000h FD_FBFF_FFFFh Address Translation + * FD_FC00_0000h FD_FDFF_FFFFh I/O Space + * FD_FE00_0000h FD_FFFF_FFFFh Configuration + * FE_0000_0000h FE_1FFF_FFFFh Extended Configuration/Device Messages + * FE_2000_0000h FF_FFFF_FFFFh Reserved + * + * See AMD IOMMU spec, section 2.1.2 "IOMMU Logical Topology", + * Table 3: Special Address Controls (GPA) for more information. + */ +#define AMD_HT_START 0xfd00000000UL +#define AMD_HT_END 0xffffffffffUL +#define AMD_ABOVE_1TB_START (AMD_HT_END + 1) +#define AMD_HT_SIZE (AMD_ABOVE_1TB_START - AMD_HT_START) + void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, @@ -894,13 +940,49 @@ void pc_memory_init(PCMachineState *pcms, MachineClass *mc =3D MACHINE_GET_CLASS(machine); PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); X86MachineState *x86ms =3D X86_MACHINE(pcms); + hwaddr maxphysaddr, maxusedaddr; hwaddr cxl_base, cxl_resv_end =3D 0; + X86CPU *cpu =3D X86_CPU(first_cpu); =20 assert(machine->ram_size =3D=3D x86ms->below_4g_mem_size + x86ms->above_4g_mem_size); =20 linux_boot =3D (machine->kernel_filename !=3D NULL); =20 + /* + * The HyperTransport range close to the 1T boundary is unique to AMD + * hosts with IOMMUs enabled. Restrict the ram-above-4g relocation + * to above 1T to AMD vCPUs only. + */ + if (IS_AMD_CPU(&cpu->env)) { + /* Bail out if max possible address does not cross HT range */ + if (pc_max_used_gpa(pcms, pci_hole64_size) >=3D AMD_HT_START) { + x86ms->above_4g_mem_start =3D AMD_ABOVE_1TB_START; + } + + /* + * Advertise the HT region if address space covers the reserved + * region or if we relocate. + */ + if (cpu->phys_bits >=3D 40) { + e820_add_entry(AMD_HT_START, AMD_HT_SIZE, E820_RESERVED); + } + } + + /* + * Relocating ram-above-4G requires more than TCG_PHYS_ADDR_BITS (40). + * So make sure phys-bits is required to be appropriately sized in ord= er + * to proceed with the above-4g-region relocation and thus boot. + */ + maxusedaddr =3D pc_max_used_gpa(pcms, pci_hole64_size); + maxphysaddr =3D ((hwaddr)1 << cpu->phys_bits) - 1; + if (maxphysaddr < maxusedaddr) { + error_report("Address space limit 0x%"PRIx64" < 0x%"PRIx64 + " phys-bits too low (%u)", + maxphysaddr, maxusedaddr, cpu->phys_bits); + exit(EXIT_FAILURE); + } + /* * Split single memory region and use aliases to address portions of i= t, * done for backwards compatibility with older qemus. --=20 2.17.2 From nobody Mon Feb 9 15:47:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1657825459; cv=none; d=zohomail.com; s=zohoarc; b=nptsEOkjWcThVd7QoT9E0H2W5obDXhwsOCSS7mg1aVvoeQ4rC/63CBOugwUdaS52thbEW7I2UZYikYG2CWYdQMoaAAhnvW8vBsaK+rQuibEtiwleXJnfWjtjK2cmgpKcA+Sxs6qJNhia+BFGin2EOeenDe1pWUc2jBz+meDjYmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657825459; 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; bh=lbzGY+jIADZtZw967IbA4yLh8WEOgvAyZfxf5ZTRYkU=; b=IW3L3e4O0JJhyNsfCJX9RYgYFwpDe//0nN9kttvSFVyu3JfXnfKXcRwY5RUGgq+fi3WIqlf6SCtHKj0DMOJFRRpbqjnXgwTmxoOFiDqXwdP2tydPlWbQv/AzWgUxK4/MaJ/rv0dgy4n+a7zMMliszUSRAOV7mbdv8Cxj/Lki8kY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1657825459673550.9303084181233; Thu, 14 Jul 2022 12:04:19 -0700 (PDT) Received: from localhost ([::1]:35636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oC48I-0007JA-A2 for importer@patchew.org; Thu, 14 Jul 2022 15:04:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3ad-0006bW-8x for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:34 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:62330) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oC3ab-0008Bn-43 for qemu-devel@nongnu.org; Thu, 14 Jul 2022 14:29:30 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26EGBmsp026608; Thu, 14 Jul 2022 18:29:23 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71r1dj05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:23 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26EIGssL022689; Thu, 14 Jul 2022 18:29:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465k61-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 18:29:22 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 26EISiAR017868; Thu, 14 Jul 2022 18:29:22 GMT Received: from paddy.uk.oracle.com (dhcp-10-175-172-165.vpn.oracle.com [10.175.172.165]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70465j62-11; Thu, 14 Jul 2022 18:29:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2021-07-09; bh=lbzGY+jIADZtZw967IbA4yLh8WEOgvAyZfxf5ZTRYkU=; b=QKfllkMWBpFneAJz3bidxaAJgALAUGv8rnMdC1YpQGBND99/POeM4Bq/hcgQ+j72D7J9 5ncKBoz2Cv3in/eWMSCY/tQ/uI9KuNQ4RR6H2GMeMRRzkidNom6ctvpNZg6T8SG5EkWJ Tzc9EHH2mXwOOghZG65xWfUy8Bu1nQLKzXP0eN7yohnwcARKAALoT6IPQ4LFYQLapjWH NBdJfERR5mzFCNrwLtfdZvXJ3gVZJyV7QEUklAg//Ue9jp22nQ9LqRP6g0mEzGuCwBzL qIQhjsqgMnKASiW4JId6qrSJ//wX2ubEKKpGzHEp5eDzPS2NFr/94vqSPabGtc8hyBD4 Qg== From: Joao Martins To: qemu-devel@nongnu.org Cc: Igor Mammedov , Eduardo Habkost , "Michael S. Tsirkin" , Richard Henderson , Alex Williamson , Paolo Bonzini , Ani Sinha , Marcel Apfelbaum , "Dr. David Alan Gilbert" , Suravee Suthikulpanit , Joao Martins Subject: [PATCH v7 10/10] i386/pc: restrict AMD only enforcing of 1Tb hole to new machine type Date: Thu, 14 Jul 2022 19:28:20 +0100 Message-Id: <20220714182820.30970-11-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220714182820.30970-1-joao.m.martins@oracle.com> References: <20220714182820.30970-1-joao.m.martins@oracle.com> X-Proofpoint-ORIG-GUID: JPM34qy5rz7g83pNq3KrOtzT8KPxduf0 X-Proofpoint-GUID: JPM34qy5rz7g83pNq3KrOtzT8KPxduf0 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.177.32; envelope-from=joao.m.martins@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1657825462005100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The added enforcing is only relevant in the case of AMD where the range right before the 1TB is restricted and cannot be DMA mapped by the kernel consequently leading to IOMMU INVALID_DEVICE_REQUEST or possibly other kinds of IOMMU events in the AMD IOMMU. Although, there's a case where it may make sense to disable the IOVA relocation/validation when migrating from a non-amd-1tb-aware qemu to one that supports it. Relocating RAM regions to after the 1Tb hole has consequences for guest ABI because we are changing the memory mapping, so make sure that only new machine enforce but not older ones. Signed-off-by: Joao Martins Acked-by: Dr. David Alan Gilbert Acked-by: Igor Mammedov --- hw/i386/pc.c | 6 ++++-- hw/i386/pc_piix.c | 2 ++ hw/i386/pc_q35.c | 2 ++ include/hw/i386/pc.h | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 17613974163e..d13a77025054 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -952,9 +952,10 @@ void pc_memory_init(PCMachineState *pcms, /* * The HyperTransport range close to the 1T boundary is unique to AMD * hosts with IOMMUs enabled. Restrict the ram-above-4g relocation - * to above 1T to AMD vCPUs only. + * to above 1T to AMD vCPUs only. @enforce_amd_1tb_hole is only false = in + * older machine types (<=3D 7.0) for compatibility purposes. */ - if (IS_AMD_CPU(&cpu->env)) { + if (IS_AMD_CPU(&cpu->env) && pcmc->enforce_amd_1tb_hole) { /* Bail out if max possible address does not cross HT range */ if (pc_max_used_gpa(pcms, pci_hole64_size) >=3D AMD_HT_START) { x86ms->above_4g_mem_start =3D AMD_ABOVE_1TB_START; @@ -1904,6 +1905,7 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) pcmc->has_reserved_memory =3D true; pcmc->kvmclock_enabled =3D true; pcmc->enforce_aligned_dimm =3D true; + pcmc->enforce_amd_1tb_hole =3D true; /* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K rep= orted * to be used at the moment, 32K should be enough for a while. */ pcmc->acpi_data_size =3D 0x20000 + 0x8000; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 2a483e8666b4..074571bc03a8 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -446,9 +446,11 @@ DEFINE_I440FX_MACHINE(v7_1, "pc-i440fx-7.1", NULL, =20 static void pc_i440fx_7_0_machine_options(MachineClass *m) { + PCMachineClass *pcmc =3D PC_MACHINE_CLASS(m); pc_i440fx_7_1_machine_options(m); m->alias =3D NULL; m->is_default =3D false; + pcmc->enforce_amd_1tb_hole =3D false; compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len); compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len); } diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 99ed75371c67..f3aa4694a299 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -383,8 +383,10 @@ DEFINE_Q35_MACHINE(v7_1, "pc-q35-7.1", NULL, =20 static void pc_q35_7_0_machine_options(MachineClass *m) { + PCMachineClass *pcmc =3D PC_MACHINE_CLASS(m); pc_q35_7_1_machine_options(m); m->alias =3D NULL; + pcmc->enforce_amd_1tb_hole =3D false; compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len); compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len); } diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 568c226d3034..9cc3f5d33805 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -118,6 +118,7 @@ struct PCMachineClass { bool has_reserved_memory; bool enforce_aligned_dimm; bool broken_reserved_end; + bool enforce_amd_1tb_hole; =20 /* generate legacy CPU hotplug AML */ bool legacy_cpu_hotplug; --=20 2.17.2