From nobody Sun May 19 04:55:56 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1655796226; cv=none; d=zohomail.com; s=zohoarc; b=aKOPKgvKKwoSWZFcS7vaUc+UZvBWwgKaHbRQ/Yl/J5m8lFNdJffBFKX8m4dtk7Nol+A3oG2ceAsh1lQKN7V0NmFic0p+iVHby9lc8O1hssViwadvCTQdMIVjx8kYirxK+wV9CSE7eWUAuXit2EQWc6XJsYUyDmtQFvtb/DWXKKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655796226; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5vH2NqyFMDYKMsu2Ud2YN8B9pnuLSEdOQPWCQhYC+kA=; b=Q74+i2Eu3qqGb+WhX9HVu1PKON7iIqKe930GDrXsolf54oKB+IpfzGvwPZVv2xpp348CobN0rH+EitC1vrsyLB/NQwDfgwkmy5mGgMQyMY7bToj5SzDY+Y/cJnXAlcD5bqwGTb2L21O9fXs7HVYcMOLccUL4Xhet+B8ZpjehvIE= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 165579622695178.8100989420459; Tue, 21 Jun 2022 00:23:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.353001.579910 (Exim 4.92) (envelope-from ) id 1o3YEL-0002AU-UA; Tue, 21 Jun 2022 07:23:21 +0000 Received: by outflank-mailman (output) from mailman id 353001.579910; Tue, 21 Jun 2022 07:23:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o3YEL-00029t-MX; Tue, 21 Jun 2022 07:23:21 +0000 Received: by outflank-mailman (input) for mailman id 353001; Tue, 21 Jun 2022 07:23:20 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o3YEK-0001Tv-0z for xen-devel@lists.xenproject.org; Tue, 21 Jun 2022 07:23:20 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 045eec7a-f133-11ec-b725-ed86ccbb4733; Tue, 21 Jun 2022 09:23:16 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4CA7B1FA5D; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 134A113638; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4LFqA+RxsWLDYwAAMHmgww (envelope-from ); Tue, 21 Jun 2022 07:23:16 +0000 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: 045eec7a-f133-11ec-b725-ed86ccbb4733 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1655796196; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5vH2NqyFMDYKMsu2Ud2YN8B9pnuLSEdOQPWCQhYC+kA=; b=Ji4OgDXCs3g7pOm0MGuTzpDGx1npbuTC62kRMt6Gxvr7skYlXuuXUJh/Cm1qLDKrwktTHq 01x+eS3hEqQc0AymmVZ96+E6bH8EPmy65pIK/8s9A347lkN4ri9T+Lk34VllN6b4xoDtHF xOeISvMnLfIO1emAV7Qy7f9FezSFd/s= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 1/4] mini-os: take newest version of arch-x86/hvm/start_info.h Date: Tue, 21 Jun 2022 09:23:11 +0200 Message-Id: <20220621072314.16382-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621072314.16382-1-jgross@suse.com> References: <20220621072314.16382-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1655796228913100005 Content-Type: text/plain; charset="utf-8" Update include/xen/arch-x86/hvm/start_info.h to the newest version from the Xen tree. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/xen/arch-x86/hvm/start_info.h | 63 ++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/include/xen/arch-x86/hvm/start_info.h b/include/xen/arch-x86/h= vm/start_info.h index 64841597..50af9ea2 100644 --- a/include/xen/arch-x86/hvm/start_info.h +++ b/include/xen/arch-x86/hvm/start_info.h @@ -33,7 +33,7 @@ * | magic | Contains the magic value XEN_HVM_START_MAGIC_VALUE * | | ("xEn3" with the 0x80 bit of the "E" set). * 4 +----------------+ - * | version | Version of this structure. Current version is 0. = New + * | version | Version of this structure. Current version is 1. = New * | | versions are guaranteed to be backwards-compatibl= e. * 8 +----------------+ * | flags | SIF_xxx flags. @@ -48,6 +48,15 @@ * 32 +----------------+ * | rsdp_paddr | Physical address of the RSDP ACPI data structure. * 40 +----------------+ + * | memmap_paddr | Physical address of the (optional) memory map. On= ly + * | | present in version 1 and newer of the structure. + * 48 +----------------+ + * | memmap_entries | Number of entries in the memory map table. Zero + * | | if there is no memory map being provided. Only + * | | present in version 1 and newer of the structure. + * 52 +----------------+ + * | reserved | Version 1 and newer only. + * 56 +----------------+ * * The layout of each entry in the module structure is the following: * @@ -62,13 +71,51 @@ * | reserved | * 32 +----------------+ * + * The layout of each entry in the memory map table is as follows: + * + * 0 +----------------+ + * | addr | Base address + * 8 +----------------+ + * | size | Size of mapping in bytes + * 16 +----------------+ + * | type | Type of mapping as defined between the hypervisor + * | | and guest. See XEN_HVM_MEMMAP_TYPE_* values below. + * 20 +----------------| + * | reserved | + * 24 +----------------+ + * * The address and sizes are always a 64bit little endian unsigned integer. * * NB: Xen on x86 will always try to place all the data below the 4GiB * boundary. + * + * Version numbers of the hvm_start_info structure have evolved like this: + * + * Version 0: Initial implementation. + * + * Version 1: Added the memmap_paddr/memmap_entries fields (plus 4 bytes = of + * padding) to the end of the hvm_start_info struct. These new + * fields can be used to pass a memory map to the guest. The + * memory map is optional and so guests that understand versio= n 1 + * of the structure must check that memmap_entries is non-zero + * before trying to read the memory map. */ #define XEN_HVM_START_MAGIC_VALUE 0x336ec578 =20 +/* + * The values used in the type field of the memory map table entries are + * defined below and match the Address Range Types as defined in the "Syst= em + * Address Map Interfaces" section of the ACPI Specification. Please refer= to + * section 15 in version 6.2 of the ACPI spec: http://uefi.org/specificati= ons + */ +#define XEN_HVM_MEMMAP_TYPE_RAM 1 +#define XEN_HVM_MEMMAP_TYPE_RESERVED 2 +#define XEN_HVM_MEMMAP_TYPE_ACPI 3 +#define XEN_HVM_MEMMAP_TYPE_NVS 4 +#define XEN_HVM_MEMMAP_TYPE_UNUSABLE 5 +#define XEN_HVM_MEMMAP_TYPE_DISABLED 6 +#define XEN_HVM_MEMMAP_TYPE_PMEM 7 + /* * C representation of the x86/HVM start info layout. * @@ -86,6 +133,13 @@ struct hvm_start_info { uint64_t cmdline_paddr; /* Physical address of the command line. = */ uint64_t rsdp_paddr; /* Physical address of the RSDP ACPI data = */ /* structure. = */ + /* All following fields only present in version 1 and newer */ + uint64_t memmap_paddr; /* Physical address of an array of = */ + /* hvm_memmap_table_entry. = */ + uint32_t memmap_entries; /* Number of entries in the memmap table. = */ + /* Value will be zero if there is no memor= y */ + /* map being provided. = */ + uint32_t reserved; /* Must be zero. = */ }; =20 struct hvm_modlist_entry { @@ -95,4 +149,11 @@ struct hvm_modlist_entry { uint64_t reserved; }; =20 +struct hvm_memmap_table_entry { + uint64_t addr; /* Base address of the memory region = */ + uint64_t size; /* Size of the memory region in bytes = */ + uint32_t type; /* Mapping type = */ + uint32_t reserved; /* Must be zero for Version 1. = */ +}; + #endif /* __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ */ --=20 2.35.3 From nobody Sun May 19 04:55:56 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1655796225; cv=none; d=zohomail.com; s=zohoarc; b=Gpq5Ew8TACCQtyzObEKsts7QTLGz2NjXLR9ER8Oi2aO+8pbOvb6JKrnfsOam+RkeCXQDTTGnEVEVNpsZ0pDxu9J/P38DhabLt8bqM2+cyudSOrzFeA6ueBfTzsJvF8pMQ1TK2lyUwJZRh1P+F18IxJPvkuFkfOJRPIQk7UqO49Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655796225; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sqQB2mee0jCv15NOcWCx6SVOgjnvvSzpgTYbgdXHN/4=; b=W/YNMXwY7d6aSWLg8g7HzC5QV2eccwQFaPNw7tltmDWIF7jvznbJAEmm/+SavTtltYSFxIoHOmVk9XJ7Ks3Q1vNUSl/uEb9aAiIEgMM1TxYkFfooTu+6tApwhtiQiXqzosTwH+yx1BlYAlUULi7Y0wmdj3K7hXUfzAqPH64likU= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1655796225956949.1514793045422; Tue, 21 Jun 2022 00:23:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.352998.579891 (Exim 4.92) (envelope-from ) id 1o3YEK-0001no-0Z; Tue, 21 Jun 2022 07:23:20 +0000 Received: by outflank-mailman (output) from mailman id 352998.579891; Tue, 21 Jun 2022 07:23:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o3YEJ-0001nh-TQ; Tue, 21 Jun 2022 07:23:19 +0000 Received: by outflank-mailman (input) for mailman id 352998; Tue, 21 Jun 2022 07:23:18 +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 1o3YEI-0001Tw-E6 for xen-devel@lists.xenproject.org; Tue, 21 Jun 2022 07:23:18 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04ad967a-f133-11ec-bd2d-47488cf2e6aa; Tue, 21 Jun 2022 09:23:16 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7FFF61FDE7; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 467B613AAA; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iLsBEORxsWLDYwAAMHmgww (envelope-from ); Tue, 21 Jun 2022 07:23:16 +0000 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: 04ad967a-f133-11ec-bd2d-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1655796196; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sqQB2mee0jCv15NOcWCx6SVOgjnvvSzpgTYbgdXHN/4=; b=R8+VFBmuL4/bHanaZhB9KH4TxeG5iLgiaOJ8U3o57yzJGOc0as9jZLbVigjvVcC4+0cbgl TSTReEqQZCWcw9xQCgLJi4zzqFL/jptDJ/dUnHi5EIwi3EG1czuqVXbSJiPAVbxf5IjkcV 2EGmoM4jmIVX9egQC/0YUF+hF4SquTk= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 2/4] mini-os: prefer memory map via start_info for PVH Date: Tue, 21 Jun 2022 09:23:12 +0200 Message-Id: <20220621072314.16382-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621072314.16382-1-jgross@suse.com> References: <20220621072314.16382-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1655796226980100001 Content-Type: text/plain; charset="utf-8" Since some time now a guest started in PVH mode will get the memory map from Xen via the start_info structure. Modify the PVH initialization to prefer this memory map over the one obtained via hypercall, as this will allow to add information to the memory map for a new kernel when supporting kexec. In case the start_info structure doesn't contain memory map information fall back to the hypercall. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- arch/x86/mm.c | 6 ++++++ e820.c | 25 +++++++++++++++++++++++++ include/e820.h | 4 ++++ 3 files changed, 35 insertions(+) diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 220c0b4d..41fcee67 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -45,6 +45,7 @@ #include #include #include +#include =20 #ifdef MM_DEBUG #define DEBUG(_f, _a...) \ @@ -108,6 +109,11 @@ void arch_mm_preinit(void *p) { long ret; domid_t domid =3D DOMID_SELF; + struct hvm_start_info *hsi =3D p; + + if ( hsi->version >=3D 1 && hsi->memmap_entries > 0 ) + e820_init_memmap((struct hvm_memmap_table_entry *)(unsigned long) + hsi->memmap_paddr, hsi->memmap_entries); =20 pt_base =3D page_table_base; first_free_pfn =3D PFN_UP(to_phys(&_end)); diff --git a/e820.c b/e820.c index 991ed382..ad91e00b 100644 --- a/e820.c +++ b/e820.c @@ -54,6 +54,7 @@ static char *e820_types[E820_TYPES] =3D { [E820_ACPI] =3D "ACPI", [E820_NVS] =3D "NVS", [E820_UNUSABLE] =3D "Unusable", + [E820_DISABLED] =3D "Disabled", [E820_PMEM] =3D "PMEM" }; =20 @@ -259,6 +260,30 @@ static void e820_get_memmap(void) e820_sanitize(); } =20 +void e820_init_memmap(struct hvm_memmap_table_entry *entry, unsigned int n= um) +{ + unsigned int i; + + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_RAM !=3D E820_RAM); + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_RESERVED !=3D E820_RESERVED); + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_ACPI !=3D E820_ACPI); + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_NVS !=3D E820_NVS); + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_UNUSABLE !=3D E820_UNUSABLE); + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_DISABLED !=3D E820_DISABLED); + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_PMEM !=3D E820_PMEM); + + for ( i =3D 0; i < num; i++ ) + { + e820_map[i].addr =3D entry[i].addr; + e820_map[i].size =3D entry[i].size; + e820_map[i].type =3D entry[i].type; + } + + e820_entries =3D num; + + e820_sanitize(); +} + void arch_print_memmap(void) { int i; diff --git a/include/e820.h b/include/e820.h index aaf2f2ca..5438a7c8 100644 --- a/include/e820.h +++ b/include/e820.h @@ -26,6 +26,8 @@ =20 #if defined(__arm__) || defined(__aarch64__) || defined(CONFIG_PARAVIRT) #define CONFIG_E820_TRIVIAL +#else +#include #endif =20 /* PC BIOS standard E820 types and structure. */ @@ -34,6 +36,7 @@ #define E820_ACPI 3 #define E820_NVS 4 #define E820_UNUSABLE 5 +#define E820_DISABLED 6 #define E820_PMEM 7 #define E820_TYPES 8 =20 @@ -54,6 +57,7 @@ unsigned long e820_get_max_contig_pages(unsigned long pfn= , unsigned long pages); #ifndef CONFIG_E820_TRIVIAL unsigned long e820_get_reserved_pfns(int pages); void e820_put_reserved_pfns(unsigned long start_pfn, int pages); +void e820_init_memmap(struct hvm_memmap_table_entry *entry, unsigned int n= um); #endif =20 #endif /*__E820_HEADER*/ --=20 2.35.3 From nobody Sun May 19 04:55:56 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1655796228; cv=none; d=zohomail.com; s=zohoarc; b=mx2CtV9oFgsvVQFoBm8B5AtTuqtjckf8TbplQJyvQl/bEomQKUpq6fbjKpgsWcoe8yCLW5f5eS8P1rlVy7KwoX0HU40DhgaRFgIGj8yMqGGRzFtEOWV0IJldefofTZJCREt74a8qlm6+FnqDsw3dWJt70B8DzjOw2RoOlV+SNfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655796228; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CgVNbVQGUCTaIYP+BHs4gAn3b+qv8h822SUhzQAjGoI=; b=HxAfepDrWoynknyaVIhFlvVsW4h//UTGOHDb8wPLMQFoIni2YYiCaRsRmUQ3ePugpTjSEklJag12GPLP5RTo0qRnP7HjW3jaN907QR/nU2zBVXM1k7Ryxoff5pXXN4m+DUa2n4ggVrNyJut6oc9S98QSGZXRr5+xAjPXASqO6yo= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1655796228681336.2275412763862; Tue, 21 Jun 2022 00:23:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.353004.579936 (Exim 4.92) (envelope-from ) id 1o3YEO-0002m4-I6; Tue, 21 Jun 2022 07:23:24 +0000 Received: by outflank-mailman (output) from mailman id 353004.579936; Tue, 21 Jun 2022 07:23:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o3YEO-0002lw-EQ; Tue, 21 Jun 2022 07:23:24 +0000 Received: by outflank-mailman (input) for mailman id 353004; Tue, 21 Jun 2022 07:23:22 +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 1o3YEM-0001Tw-EV for xen-devel@lists.xenproject.org; Tue, 21 Jun 2022 07:23:22 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04c46c7d-f133-11ec-bd2d-47488cf2e6aa; Tue, 21 Jun 2022 09:23:16 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A5F851FDEA; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7AE9E13638; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oPOpHORxsWLDYwAAMHmgww (envelope-from ); Tue, 21 Jun 2022 07:23:16 +0000 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: 04c46c7d-f133-11ec-bd2d-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1655796196; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CgVNbVQGUCTaIYP+BHs4gAn3b+qv8h822SUhzQAjGoI=; b=gKyS74dTKyHkB9YN22Xr6mm5x9q1uigRxKb8vhOFbIlWet23p//Z/HjjJq2HSZvQBVPUL7 Z/kfIrftMU9eVVZu249TT9mQ8NGohdfgpu/o2bDRNcCUzgkQ/x7CfbdPxz5TYZQgb4bEZA off+3BIq4riF5pNLFLzaK8KEPk3RzlU= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 3/4] mini-os: fix number of pages for PVH Date: Tue, 21 Jun 2022 09:23:13 +0200 Message-Id: <20220621072314.16382-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621072314.16382-1-jgross@suse.com> References: <20220621072314.16382-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1655796230720100008 Content-Type: text/plain; charset="utf-8" When getting the current allocation from Xen, this value includes the pages allocated in the MMIO area. Fix the highest available RAM page by subtracting the size of that area. This requires to read the E820 map before needing this value. Add two functions returning the current and the maximum number of RAM pages taking this correction into account. At the same time add the LAPIC page to the memory map in order to avoid reusing that PFN for internal purposes. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - make e820_initial_reserved_pfns static (Samuel Thibault) - add e820_get_current_pages() and e820_get_max_pages() V3: - change return type of e820_get_current_pages() and e820_get_max_pages() to unsigned long (Samuel Thibault) --- arch/x86/mm.c | 17 +++++-------- balloon.c | 16 +++--------- e820.c | 58 +++++++++++++++++++++++++++++++++++++------ include/e820.h | 2 ++ include/x86/arch_mm.h | 2 ++ 5 files changed, 65 insertions(+), 30 deletions(-) diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 41fcee67..cfc978f6 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -107,25 +107,20 @@ desc_ptr idt_ptr =3D =20 void arch_mm_preinit(void *p) { - long ret; - domid_t domid =3D DOMID_SELF; + unsigned int pages; struct hvm_start_info *hsi =3D p; =20 if ( hsi->version >=3D 1 && hsi->memmap_entries > 0 ) e820_init_memmap((struct hvm_memmap_table_entry *)(unsigned long) hsi->memmap_paddr, hsi->memmap_entries); + else + e820_init_memmap(NULL, 0); =20 pt_base =3D page_table_base; first_free_pfn =3D PFN_UP(to_phys(&_end)); - ret =3D HYPERVISOR_memory_op(XENMEM_current_reservation, &domid); - if ( ret < 0 ) - { - xprintk("could not get memory size\n"); - do_exit(); - } - - last_free_pfn =3D e820_get_maxpfn(ret); - balloon_set_nr_pages(ret, last_free_pfn); + pages =3D e820_get_current_pages(); + last_free_pfn =3D e820_get_maxpfn(pages); + balloon_set_nr_pages(pages, last_free_pfn); } #endif =20 diff --git a/balloon.c b/balloon.c index 9dc77c54..6ad07644 100644 --- a/balloon.c +++ b/balloon.c @@ -44,20 +44,12 @@ void balloon_set_nr_pages(unsigned long pages, unsigned= long pfn) =20 void get_max_pages(void) { - long ret; - domid_t domid =3D DOMID_SELF; - - ret =3D HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid); - if ( ret < 0 ) + nr_max_pages =3D e820_get_max_pages(); + if ( nr_max_pages ) { - printk("Could not get maximum pfn\n"); - return; + printk("Maximum memory size: %ld pages\n", nr_max_pages); + nr_max_pfn =3D e820_get_maxpfn(nr_max_pages); } - - nr_max_pages =3D ret; - printk("Maximum memory size: %ld pages\n", nr_max_pages); - - nr_max_pfn =3D e820_get_maxpfn(nr_max_pages); } =20 void mm_alloc_bitmap_remap(void) diff --git a/e820.c b/e820.c index ad91e00b..49b16878 100644 --- a/e820.c +++ b/e820.c @@ -29,6 +29,38 @@ #include #include =20 +static unsigned long e820_initial_reserved_pfns; + +unsigned long e820_get_current_pages(void) +{ + domid_t domid =3D DOMID_SELF; + long ret; + + ret =3D HYPERVISOR_memory_op(XENMEM_current_reservation, &domid); + if ( ret < 0 ) + { + xprintk("could not get memory size\n"); + do_exit(); + } + + return ret - e820_initial_reserved_pfns; +} + +unsigned long e820_get_max_pages(void) +{ + domid_t domid =3D DOMID_SELF; + long ret; + + ret =3D HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid); + if ( ret < 0 ) + { + printk("Could not get maximum pfn\n"); + return 0; + } + + return ret - e820_initial_reserved_pfns; +} + #ifdef CONFIG_E820_TRIVIAL struct e820entry e820_map[1] =3D { { @@ -40,10 +72,6 @@ struct e820entry e820_map[1] =3D { =20 unsigned e820_entries =3D 1; =20 -static void e820_get_memmap(void) -{ -} - #else struct e820entry e820_map[E820_MAX]; unsigned e820_entries; @@ -199,6 +227,7 @@ static void e820_sanitize(void) { int i; unsigned long end, start; + bool found_lapic =3D false; =20 /* Sanitize memory map in current form. */ e820_process_entries(); @@ -238,8 +267,20 @@ static void e820_sanitize(void) =20 /* Make remaining temporarily reserved entries permanently reserved. */ for ( i =3D 0; i < e820_entries; i++ ) + { if ( e820_map[i].type =3D=3D E820_TMP_RESERVED ) e820_map[i].type =3D E820_RESERVED; + if ( e820_map[i].type =3D=3D E820_RESERVED ) + { + e820_initial_reserved_pfns +=3D e820_map[i].size / PAGE_SIZE; + if ( e820_map[i].addr <=3D LAPIC_ADDRESS && + e820_map[i].addr + e820_map[i].size > LAPIC_ADDRESS ) + found_lapic =3D true; + } + } + + if ( !found_lapic ) + e820_insert_entry(LAPIC_ADDRESS, PAGE_SIZE, E820_RESERVED); } =20 static void e820_get_memmap(void) @@ -264,6 +305,12 @@ void e820_init_memmap(struct hvm_memmap_table_entry *e= ntry, unsigned int num) { unsigned int i; =20 + if ( !entry ) + { + e820_get_memmap(); + return; + } + BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_RAM !=3D E820_RAM); BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_RESERVED !=3D E820_RESERVED); BUILD_BUG_ON(XEN_HVM_MEMMAP_TYPE_ACPI !=3D E820_ACPI); @@ -365,9 +412,6 @@ unsigned long e820_get_maxpfn(unsigned long pages) int i; unsigned long pfns =3D 0, start =3D 0; =20 - if ( !e820_entries ) - e820_get_memmap(); - for ( i =3D 0; i < e820_entries; i++ ) { if ( e820_map[i].type !=3D E820_RAM ) diff --git a/include/e820.h b/include/e820.h index 5438a7c8..ffa15aa9 100644 --- a/include/e820.h +++ b/include/e820.h @@ -52,6 +52,8 @@ struct __packed e820entry { extern struct e820entry e820_map[]; extern unsigned e820_entries; =20 +unsigned long e820_get_current_pages(void); +unsigned long e820_get_max_pages(void); unsigned long e820_get_maxpfn(unsigned long pages); unsigned long e820_get_max_contig_pages(unsigned long pfn, unsigned long p= ages); #ifndef CONFIG_E820_TRIVIAL diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h index ffbec5a8..a1b975dc 100644 --- a/include/x86/arch_mm.h +++ b/include/x86/arch_mm.h @@ -207,6 +207,8 @@ typedef unsigned long pgentry_t; /* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) =20 +#define LAPIC_ADDRESS CONST(0xfee00000) + #ifndef __ASSEMBLY__ /* Definitions for machine and pseudophysical addresses. */ #ifdef __i386__ --=20 2.35.3 From nobody Sun May 19 04:55:56 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1655796225; cv=none; d=zohomail.com; s=zohoarc; b=Nrxv5DDngWWyG661Dj4bMZ3axudNHcjlM0E4W5157/2Br06BeHafCuOxLzpv36LA71CWySB1tICZig9j22usztaOB88TATRytkv8aYVy/sYM5B75ip4nzh3ZxxRXB6QpjxFzQ6gXXFaJ9KnjTtoTFzVOQP/d2MnZmORl2bcZVj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655796225; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iK4xpyO/24q/Du+ofA9DMrmGHYHqE1QdZ+2SGjY3+1E=; b=UGWhKvyedmaGrL4fRf5JxWIArd92Elj+e543UCBiMcrwB3zwBIQVNQN2WTEha08mkiR+GRZuY9lOT6C5LWd69iWTNh6AHm5/+o6yDbt9kUjtKXLeh+rRQLyzl4O+rj4szU1SM30PvN99F3NUKeEms3qZ0k4zJEf0XZOGnzuh5cE= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1655796225081653.2441073728899; Tue, 21 Jun 2022 00:23:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.353000.579906 (Exim 4.92) (envelope-from ) id 1o3YEL-000252-C4; Tue, 21 Jun 2022 07:23:21 +0000 Received: by outflank-mailman (output) from mailman id 353000.579906; Tue, 21 Jun 2022 07:23:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1o3YEL-00024v-8H; Tue, 21 Jun 2022 07:23:21 +0000 Received: by outflank-mailman (input) for mailman id 353000; Tue, 21 Jun 2022 07:23:19 +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 1o3YEJ-0001Tw-E4 for xen-devel@lists.xenproject.org; Tue, 21 Jun 2022 07:23:19 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04e57763-f133-11ec-bd2d-47488cf2e6aa; Tue, 21 Jun 2022 09:23:17 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D95C81FDE8; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AD8C613A8F; Tue, 21 Jun 2022 07:23:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KJkaKeRxsWLDYwAAMHmgww (envelope-from ); Tue, 21 Jun 2022 07:23:16 +0000 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: 04e57763-f133-11ec-bd2d-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1655796196; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iK4xpyO/24q/Du+ofA9DMrmGHYHqE1QdZ+2SGjY3+1E=; b=TLm0LLGu8RVX2fv2/nucY1GzNv04PipwpCSX20R8nj8u2d2/GfARxKo3E3i12mBoX3C118 AJo8fKEsKkVQ/dzJsvG2yVV2e85TyQydpxL8HBcVMQ4Ay2tzCscsIf0usqacKMU8nnkGoz /1lCFwCJKeqkZ4qT7cwGYYBMhQVlchE= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v3 4/4] mini-os: fix bug in ballooning on PVH Date: Tue, 21 Jun 2022 09:23:14 +0200 Message-Id: <20220621072314.16382-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621072314.16382-1-jgross@suse.com> References: <20220621072314.16382-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1655796227136100003 Content-Type: text/plain; charset="utf-8" There is a subtle bug in ballooning code for PVH: in case ballooning extends above a non-RAM area of the memory map, wrong pages will be used. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - new patch --- balloon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/balloon.c b/balloon.c index 6ad07644..55be8141 100644 --- a/balloon.c +++ b/balloon.c @@ -124,7 +124,7 @@ int balloon_up(unsigned long n_pages) for ( pfn =3D 0; pfn < rc; pfn++ ) { arch_pfn_add(start_pfn + pfn, balloon_frames[pfn]); - free_page(pfn_to_virt(nr_mem_pages + pfn)); + free_page(pfn_to_virt(start_pfn + pfn)); } =20 nr_mem_pages +=3D rc; --=20 2.35.3