From nobody Fri May 17 16:06:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1710344851; cv=none; d=zohomail.com; s=zohoarc; b=Hb4Xai13Rfz6rcV8oQtLR2LUyTYdPpFkHwDHpzKUhF6zINzphM1c9M9I8QAuVyICNuSFxZ6yQFMAbsHWVzOm6wWUQtoEtGp86t7vF7OyS6quj+z6E7j5e86q/nprz1DSIlZJju5fF6j1XLtTe7xLYIlZ+X7YH5/kRlmyh/lzOIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710344851; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hRQqdzncpSGt6fbxgjyMV5po9/h6eRl9V9eIxuTQ6WM=; b=EA/bO0Y/4lVqRI5yZOtatrUPyPBjbkL6CCcnai+lyKiqbKTdGQ/PkAOf62kughgPzXA6dtviEwijvM3Qq6MMmjMVhUeyEI0KpEyMr8jqm3jIZkc/w50EyIBDct7HFdaCIzqYxFvSQJG1HLXu5TXLkuqqJBRVXiCTZYdXWUDiLiw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710344851760613.6498727005178; Wed, 13 Mar 2024 08:47:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692584.1079889 (Exim 4.92) (envelope-from ) id 1rkQon-0001Oj-Br; Wed, 13 Mar 2024 15:47:01 +0000 Received: by outflank-mailman (output) from mailman id 692584.1079889; Wed, 13 Mar 2024 15:47:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkQon-0001Oc-8v; Wed, 13 Mar 2024 15:47:01 +0000 Received: by outflank-mailman (input) for mailman id 692584; Wed, 13 Mar 2024 15:35:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkQdQ-0007MK-Ms for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 15:35:16 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 49d8cea8-e14f-11ee-afdd-a90da7624cb6; Wed, 13 Mar 2024 16:35:15 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a466a256726so11207066b.1 for ; Wed, 13 Mar 2024 08:35:15 -0700 (PDT) Received: from EMEAENGAAD91498.citrite.net ([217.156.233.157]) by smtp.gmail.com with ESMTPSA id lt9-20020a170906fa8900b00a45c4d3ee11sm4930248ejb.123.2024.03.13.08.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 08:35:14 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 49d8cea8-e14f-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1710344114; x=1710948914; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hRQqdzncpSGt6fbxgjyMV5po9/h6eRl9V9eIxuTQ6WM=; b=bl4Dt/huZinBzY2e1nMqXFh7DdwOewEBuT3hRQdi2P3QH/LxBQFO/Os6gyzcLtfZP7 RTJ2k2f3D+KLb0lxPhBNE592gL7WDQGY+AjVyjaEcdNsvkOjZTSVRtlsLETJzcFSCcS2 niGyuvdEHK3IthqumxO0IKJpGzLXmJJSWEUPM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710344114; x=1710948914; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hRQqdzncpSGt6fbxgjyMV5po9/h6eRl9V9eIxuTQ6WM=; b=J18TOK0ThQhkE1F8AIpTlIi8md+PMPz/+KAIgfSqA2xqA0BuNTdoSOgbLWd2LpCJgZ haGxT0fi+unuNv2FVl4W8G0ss6lK1aIWeu60ffF3rn4s96OU+ybTsqqGHnFVJcGn5k6/ 7xN1vuwhiI7uR+2JN6qFlapVePvBlL8sHJ0tMvnbLKMRSQSX9BPBLisieCwBHUunh8oV eEXZ3PsPjscN3wkZt2irhwfRAVZv7GP9pbfTMlZKcfeZaUzWVoBR9G2TM3kH57Apw6Qv t+Mkpmyf/B10FAl5w2I+P3w2+6tj2yOHVhZQ9gGNBXHvUSBvp56FHOE0+N4hCnJFwEEI 7F4A== X-Gm-Message-State: AOJu0YymwlMxOyRp7tQ7jbm67OjQagGdHQO58kTDgWXhcci7Qx0M4G6R TLyCZKHQ1ndb/fyhaKDwuJneL/NA/gjONJ1snTtb6XyNiA3wxx28hK5fwetetx9c5oc3Jwdk1Fg LjSY= X-Google-Smtp-Source: AGHT+IEwiuP76hhoS6jiTUnmlM0RhWgGzAerXqT9OvHGPPKxYJR3T319S28euVfQtzUbbgmooWxizQ== X-Received: by 2002:a17:907:2da2:b0:a46:4bd4:df86 with SMTP id gt34-20020a1709072da200b00a464bd4df86mr3359956ejc.3.1710344114354; Wed, 13 Mar 2024 08:35:14 -0700 (PDT) From: Matthew Barnes To: Xen-devel Cc: Matthew Barnes , Jan Beulich , Wei Liu , Anthony PERARD Subject: [XEN PATCH] tools: add x2APIC entries in MADT based on APIC ID Date: Wed, 13 Mar 2024 15:35:11 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1710344852483100001 Content-Type: text/plain; charset="utf-8" libacpi is a tool that is used by libxl (for PVH guests) and hvmloader (for HVM guests) to construct ACPI tables for guests. Currently, libacpi only uses APIC entries to enumerate processors for guests in the MADT. The APIC ID field in APIC entries is an octet big, which is fine for xAPIC IDs, but not so for sufficiently large x2APIC IDs. This patch scans each APIC ID before constructing the MADT, and uses the x2APIC entry for each vCPU whose APIC ID exceeds the size limit imposed by regular APIC entries. Signed-off-by: Matthew Barnes --- tools/libacpi/acpi2_0.h | 13 +++++++ tools/libacpi/build.c | 75 ++++++++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/tools/libacpi/acpi2_0.h b/tools/libacpi/acpi2_0.h index 6dfa939a8c0c..10e567686fe6 100644 --- a/tools/libacpi/acpi2_0.h +++ b/tools/libacpi/acpi2_0.h @@ -344,6 +344,7 @@ struct acpi_20_waet { #define ACPI_IO_SAPIC 0x06 #define ACPI_PROCESSOR_LOCAL_SAPIC 0x07 #define ACPI_PLATFORM_INTERRUPT_SOURCES 0x08 +#define ACPI_PROCESSOR_LOCAL_X2APIC 0x09 =20 /* * APIC Structure Definitions. @@ -360,6 +361,18 @@ struct acpi_20_madt_lapic { uint32_t flags; }; =20 +/* + * Processor Local x2APIC Structure Definition. + */ +struct acpi_20_madt_x2apic { + uint8_t type; /* Must refer to x2APIC type (0x09) */ + uint8_t length; /* Must be length of x2APIC struct in byte= s (0x10) */ + uint16_t reserved; /* Must be zero */ + uint32_t apic_id; /* Processor's local x2APIC ID */ + uint32_t flags; /* Same as Local APIC flags */ + uint32_t acpi_processor_id; /* Refers to a processor device used to as= sociate the X2APIC structure with */ +}; + /* * Local APIC Flags. All other bits are reserved and must be 0. */ diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c index 2f29863db154..5b0fd6584b30 100644 --- a/tools/libacpi/build.c +++ b/tools/libacpi/build.c @@ -63,6 +63,27 @@ static void set_checksum( p[checksum_offset] =3D -sum; } =20 +static unsigned calculate_madt_size(const struct acpi_config *config) +{ + uint32_t apic_id; + unsigned i, size; + + size =3D sizeof(struct acpi_20_madt); + size +=3D sizeof(struct acpi_20_madt_intsrcovr) * 16; + size +=3D sizeof(struct acpi_20_madt_ioapic); + + for ( i =3D 0; i < config->hvminfo->nr_vcpus; i++ ) + { + apic_id =3D config->lapic_id(i); + if ( apic_id < 255 ) + size +=3D sizeof(struct acpi_20_madt_lapic); + else + size +=3D sizeof(struct acpi_20_madt_x2apic); + } + + return size; +} + static struct acpi_20_madt *construct_madt(struct acpi_ctxt *ctxt, const struct acpi_config *confi= g, struct acpi_info *info) @@ -70,18 +91,14 @@ static struct acpi_20_madt *construct_madt(struct acpi_= ctxt *ctxt, struct acpi_20_madt *madt; struct acpi_20_madt_intsrcovr *intsrcovr; struct acpi_20_madt_ioapic *io_apic; - struct acpi_20_madt_lapic *lapic; + void *apicid_entry; const struct hvm_info_table *hvminfo =3D config->hvminfo; - int i, sz; + unsigned i, sz; =20 if ( config->lapic_id =3D=3D NULL ) return NULL; =20 - sz =3D sizeof(struct acpi_20_madt); - sz +=3D sizeof(struct acpi_20_madt_intsrcovr) * 16; - sz +=3D sizeof(struct acpi_20_madt_ioapic); - sz +=3D sizeof(struct acpi_20_madt_lapic) * hvminfo->nr_vcpus; - + sz =3D calculate_madt_size(config); madt =3D ctxt->mem_ops.alloc(ctxt, sz, 16); if (!madt) return NULL; =20 @@ -134,27 +151,45 @@ static struct acpi_20_madt *construct_madt(struct acp= i_ctxt *ctxt, io_apic->ioapic_id =3D config->ioapic_id; io_apic->ioapic_addr =3D config->ioapic_base_address; =20 - lapic =3D (struct acpi_20_madt_lapic *)(io_apic + 1); + apicid_entry =3D io_apic + 1; } else - lapic =3D (struct acpi_20_madt_lapic *)(madt + 1); + apicid_entry =3D madt + 1; =20 info->nr_cpus =3D hvminfo->nr_vcpus; - info->madt_lapic0_addr =3D ctxt->mem_ops.v2p(ctxt, lapic); + info->madt_lapic0_addr =3D ctxt->mem_ops.v2p(ctxt, apicid_entry); for ( i =3D 0; i < hvminfo->nr_vcpus; i++ ) { - memset(lapic, 0, sizeof(*lapic)); - lapic->type =3D ACPI_PROCESSOR_LOCAL_APIC; - lapic->length =3D sizeof(*lapic); - /* Processor ID must match processor-object IDs in the DSDT. */ - lapic->acpi_processor_id =3D i; - lapic->apic_id =3D config->lapic_id(i); - lapic->flags =3D (test_bit(i, hvminfo->vcpu_online) - ? ACPI_LOCAL_APIC_ENABLED : 0); - lapic++; + uint32_t apic_id =3D config->lapic_id(i); + if ( apic_id < 255 ) + { + struct acpi_20_madt_lapic *lapic =3D apicid_entry; + memset(lapic, 0, sizeof(*lapic)); + lapic->type =3D ACPI_PROCESSOR_LOCAL_APIC; + lapic->length =3D sizeof(*lapic); + /* Processor ID must match processor-object IDs in the DSDT. */ + lapic->acpi_processor_id =3D i; + lapic->apic_id =3D apic_id; + lapic->flags =3D (test_bit(i, hvminfo->vcpu_online) + ? ACPI_LOCAL_APIC_ENABLED : 0); + apicid_entry =3D lapic + 1; + } + else + { + struct acpi_20_madt_x2apic *x2apic =3D apicid_entry; + memset(x2apic, 0, sizeof(*x2apic)); + x2apic->type =3D ACPI_PROCESSOR_LOCAL_X2APIC; + x2apic->length =3D sizeof(*x2apic); + x2apic->apic_id =3D apic_id; + x2apic->flags =3D (test_bit(i, hvminfo->vcpu_online) + ? ACPI_LOCAL_APIC_ENABLED : 0); + /* Processor ID must match processor-object IDs in the DSDT. */ + x2apic->acpi_processor_id =3D i; + apicid_entry =3D x2apic + 1; + } } =20 - madt->header.length =3D (unsigned char *)lapic - (unsigned char *)madt; + madt->header.length =3D (unsigned char *)apicid_entry - (unsigned char= *)madt; set_checksum(madt, offsetof(struct acpi_header, checksum), madt->header.length); info->madt_csum_addr =3D --=20 2.34.1