From nobody Mon Apr 29 15:45:51 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=1627637215; cv=none; d=zohomail.com; s=zohoarc; b=TshuYADFGWuPuUnqYTXpKLaNRJn57+PfTv1jFbtUSepOm7oEY9PPqGBDT1yb3msVIYs7XZvEYHBdbTK5lCM6xGcUZX4UJbs/vMTEU5TnYL0Z/LqdM3TiBHWptxb/gGUNLNHFnv6CYyTxUbTs1Mtb9OZpVhoq7qEhSae/teRlwVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627637215; 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=lW2pCPIM4lkygbLbwGLWABzG2cZ+/JhuOV4NXj3t6fM=; b=BlZ07NrqmmQQdk7GXYpZbn/Grkh64Ih4Hoo3UeqzYBj37ZbaM/pO6sk6lBErg013D/jufMVzXuXAYToSTP9kIDdd1yzI6npppy6bpoTdtOvOHGKn9XeWDMHtXdQbnDybVh9VWB9ZcKt1nXhWFiSSLxvnZf86aJp2INKJnlajAEQ= 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 1627637215078412.16410835401484; Fri, 30 Jul 2021 02:26:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.162415.297864 (Exim 4.92) (envelope-from ) id 1m9Omj-0007KU-0d; Fri, 30 Jul 2021 09:26:29 +0000 Received: by outflank-mailman (output) from mailman id 162415.297864; Fri, 30 Jul 2021 09:26:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m9Omi-0007KN-Tx; Fri, 30 Jul 2021 09:26:28 +0000 Received: by outflank-mailman (input) for mailman id 162415; Fri, 30 Jul 2021 09:26:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m9Omh-000738-Fz for xen-devel@lists.xenproject.org; Fri, 30 Jul 2021 09:26:27 +0000 Received: from smtp-out2.suse.de (unknown [195.135.220.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 364d00f8-f118-11eb-988f-12813bfff9fa; Fri, 30 Jul 2021 09:26:26 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 87F3E2021E; Fri, 30 Jul 2021 09:26:25 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 3CE7313748; Fri, 30 Jul 2021 09:26:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id KNeODcHFA2GeIwAAGKfGzw (envelope-from ); Fri, 30 Jul 2021 09:26:25 +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: 364d00f8-f118-11eb-988f-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1627637185; 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=lW2pCPIM4lkygbLbwGLWABzG2cZ+/JhuOV4NXj3t6fM=; b=ds4Q914sXEHoQze6n+6web45Hx/QT2RBD7lWXXbaqKASz3CCwlhuto+m6zphSRvkdNnbVp P5ZTquFXRO2Jtc+H4WB6rmyh/3gFa0AdN3pdg5iL3M+fL27oMsl5rFPuJmCQ+aqoBPdN6p CWDFOKRcHk6eV1+KUfFmLeLHKB1XO38= From: Juergen Gross To: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , stable@vger.kernel.org, Jan Beulich Subject: [PATCH v2 1/2] xen: fix setting of max_pfn in shared_info Date: Fri, 30 Jul 2021 11:26:21 +0200 Message-Id: <20210730092622.9973-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210730092622.9973-1-jgross@suse.com> References: <20210730092622.9973-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1627637217215100003 Content-Type: text/plain; charset="utf-8" Xen PV guests are specifying the highest used PFN via the max_pfn field in shared_info. This value is used by the Xen tools when saving or migrating the guest. Unfortunately this field is misnamed, as in reality it is specifying the number of pages (including any memory holes) of the guest, so it is the highest used PFN + 1. Renaming isn't possible, as this is a public Xen hypervisor interface which needs to be kept stable. The kernel will set the value correctly initially at boot time, but when adding more pages (e.g. due to memory hotplug or ballooning) a real PFN number is stored in max_pfn. This is done when expanding the p2m array, and the PFN stored there is even possibly wrong, as it should be the last possible PFN of the just added P2M frame, and not one which led to the P2M expansion. Fix that by setting shared_info->max_pfn to the last possible PFN + 1. Fixes: 98dd166ea3a3c3 ("x86/xen/p2m: hint at the last populated P2M entry") Cc: stable@vger.kernel.org Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- arch/x86/xen/p2m.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index ac06ca32e9ef..5e6e236977c7 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -618,8 +618,8 @@ int xen_alloc_p2m_entry(unsigned long pfn) } =20 /* Expanded the p2m? */ - if (pfn > xen_p2m_last_pfn) { - xen_p2m_last_pfn =3D pfn; + if (pfn >=3D xen_p2m_last_pfn) { + xen_p2m_last_pfn =3D ALIGN(pfn + 1, P2M_PER_PAGE); HYPERVISOR_shared_info->arch.max_pfn =3D xen_p2m_last_pfn; } =20 --=20 2.26.2 From nobody Mon Apr 29 15:45:51 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=1627637214; cv=none; d=zohomail.com; s=zohoarc; b=XvrFdFnW8zGyUUPDqZC1EpfrB2mNl98OwbLd3Df8/dcV66MVgEzPS0pDHfhANEVBUr0vG5hydCT/jRHE9VapwMTnUX+9zeJsn3HP4cpqNIPzPwMmW/rbZ6byjS5rZZjLg6IYe6P78zFwj0CxPylrOxdPx7IwcGgcX2m7i5nlTP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627637214; 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=3qVuz5gWClPtgxEZQpa8+8C1kUk+SDB64ahqtgECpn8=; b=TVrCVpncl0yeOcSJRRpblcRUQtTX1Nta3K0UwtN/vQBolME4Gtw0Wit9AkGVGOtYf534w0BNZyFoZ//RLmrlqdnVP+eK6QSbn6mKNHsE7QchaPAz0GS37+0EzF0gdt+Vtq9ByiG+ohg6KwZyrZ7+PaODlCU+EogS26onIuQKuu0= 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 1627637214161974.1050023936949; Fri, 30 Jul 2021 02:26:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.162416.297877 (Exim 4.92) (envelope-from ) id 1m9Omo-0007g5-9k; Fri, 30 Jul 2021 09:26:34 +0000 Received: by outflank-mailman (output) from mailman id 162416.297877; Fri, 30 Jul 2021 09:26:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m9Omo-0007fp-6G; Fri, 30 Jul 2021 09:26:34 +0000 Received: by outflank-mailman (input) for mailman id 162416; Fri, 30 Jul 2021 09:26:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m9Omm-000738-DG for xen-devel@lists.xenproject.org; Fri, 30 Jul 2021 09:26:32 +0000 Received: from smtp-out1.suse.de (unknown [195.135.220.28]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 36792886-f118-11eb-988f-12813bfff9fa; Fri, 30 Jul 2021 09:26:26 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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-out1.suse.de (Postfix) with ESMTPS id D026F2240A; Fri, 30 Jul 2021 09:26:25 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 8EE9913748; Fri, 30 Jul 2021 09:26:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id YG2xIcHFA2GeIwAAGKfGzw (envelope-from ); Fri, 30 Jul 2021 09:26:25 +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: 36792886-f118-11eb-988f-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1627637185; 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=3qVuz5gWClPtgxEZQpa8+8C1kUk+SDB64ahqtgECpn8=; b=SebqX/TBG+6Jymm7zXT/FeRAPxnYMQdDVRARBH4DcJiYOhL0X4uZAL0pQJwzRsl3s1ylp4 Rz8+w4zHs50hoNWDj7sk/wZURGfrsc08XKmH08ku/zs+EKEscpD9gYAdivzCxCeeZQhDZF mVcTNcsTFKrY5hajqFS4F7RCZo/8Ajw= From: Juergen Gross To: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: [PATCH v2 2/2] xen: rename wrong named pfn related variables Date: Fri, 30 Jul 2021 11:26:22 +0200 Message-Id: <20210730092622.9973-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210730092622.9973-1-jgross@suse.com> References: <20210730092622.9973-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1627637215148100001 Content-Type: text/plain; charset="utf-8" There are some variables in Xen specific coding which names imply them holding a PFN, while in reality they are containing numbers of PFNs. Rename them accordingly. Signed-off-by: Juergen Gross --- V2: - adjust comment (Jan Beulich) --- arch/x86/include/asm/xen/page.h | 4 ++-- arch/x86/xen/p2m.c | 33 ++++++++++++++++++--------------- arch/x86/xen/setup.c | 2 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/pag= e.h index 1a162e559753..3590d6bf42c7 100644 --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h @@ -51,7 +51,7 @@ extern unsigned long *machine_to_phys_mapping; extern unsigned long machine_to_phys_nr; extern unsigned long *xen_p2m_addr; extern unsigned long xen_p2m_size; -extern unsigned long xen_max_p2m_pfn; +extern unsigned long xen_p2m_max_size; =20 extern int xen_alloc_p2m_entry(unsigned long pfn); =20 @@ -144,7 +144,7 @@ static inline unsigned long __pfn_to_mfn(unsigned long = pfn) =20 if (pfn < xen_p2m_size) mfn =3D xen_p2m_addr[pfn]; - else if (unlikely(pfn < xen_max_p2m_pfn)) + else if (unlikely(pfn < xen_p2m_max_size)) return get_phys_to_machine(pfn); else return IDENTITY_FRAME(pfn); diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 5e6e236977c7..d75d9e077d13 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -95,8 +95,8 @@ unsigned long *xen_p2m_addr __read_mostly; EXPORT_SYMBOL_GPL(xen_p2m_addr); unsigned long xen_p2m_size __read_mostly; EXPORT_SYMBOL_GPL(xen_p2m_size); -unsigned long xen_max_p2m_pfn __read_mostly; -EXPORT_SYMBOL_GPL(xen_max_p2m_pfn); +unsigned long xen_p2m_max_size __read_mostly; +EXPORT_SYMBOL_GPL(xen_p2m_max_size); =20 #ifdef CONFIG_XEN_MEMORY_HOTPLUG_LIMIT #define P2M_LIMIT CONFIG_XEN_MEMORY_HOTPLUG_LIMIT @@ -120,8 +120,10 @@ static pte_t *p2m_identity_pte; * Used to set HYPERVISOR_shared_info->arch.max_pfn so the toolstack * can avoid scanning the whole P2M (which may be sized to account for * hotplugged memory). + * + * All populated P2M entries have an index lower than xen_p2m_pfn_limit. */ -static unsigned long xen_p2m_last_pfn; +static unsigned long xen_p2m_pfn_limit; =20 static inline unsigned p2m_top_index(unsigned long pfn) { @@ -239,7 +241,7 @@ void __ref xen_build_mfn_list_list(void) p2m_mid_mfn_init(p2m_mid_missing_mfn, p2m_missing); } =20 - for (pfn =3D 0; pfn < xen_max_p2m_pfn && pfn < MAX_P2M_PFN; + for (pfn =3D 0; pfn < xen_p2m_max_size && pfn < MAX_P2M_PFN; pfn +=3D P2M_PER_PAGE) { topidx =3D p2m_top_index(pfn); mididx =3D p2m_mid_index(pfn); @@ -284,7 +286,7 @@ void xen_setup_mfn_list_list(void) else HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =3D virt_to_mfn(p2m_top_mfn); - HYPERVISOR_shared_info->arch.max_pfn =3D xen_p2m_last_pfn; + HYPERVISOR_shared_info->arch.max_pfn =3D xen_p2m_pfn_limit; HYPERVISOR_shared_info->arch.p2m_generation =3D 0; HYPERVISOR_shared_info->arch.p2m_vaddr =3D (unsigned long)xen_p2m_addr; HYPERVISOR_shared_info->arch.p2m_cr3 =3D @@ -302,7 +304,7 @@ void __init xen_build_dynamic_phys_to_machine(void) for (pfn =3D xen_start_info->nr_pages; pfn < xen_p2m_size; pfn++) xen_p2m_addr[pfn] =3D INVALID_P2M_ENTRY; =20 - xen_max_p2m_pfn =3D xen_p2m_size; + xen_p2m_max_size =3D xen_p2m_size; } =20 #define P2M_TYPE_IDENTITY 0 @@ -353,7 +355,7 @@ static void __init xen_rebuild_p2m_list(unsigned long *= p2m) pfn_pte(PFN_DOWN(__pa(p2m_identity)), PAGE_KERNEL_RO)); } =20 - for (pfn =3D 0; pfn < xen_max_p2m_pfn; pfn +=3D chunk) { + for (pfn =3D 0; pfn < xen_p2m_max_size; pfn +=3D chunk) { /* * Try to map missing/identity PMDs or p2m-pages if possible. * We have to respect the structure of the mfn_list_list @@ -413,21 +415,22 @@ void __init xen_vmalloc_p2m_tree(void) static struct vm_struct vm; unsigned long p2m_limit; =20 - xen_p2m_last_pfn =3D xen_max_p2m_pfn; + xen_p2m_pfn_limit =3D xen_p2m_max_size; =20 p2m_limit =3D (phys_addr_t)P2M_LIMIT * 1024 * 1024 * 1024 / PAGE_SIZE; vm.flags =3D VM_ALLOC; - vm.size =3D ALIGN(sizeof(unsigned long) * max(xen_max_p2m_pfn, p2m_limit), + vm.size =3D ALIGN(sizeof(unsigned long) * + max(xen_p2m_max_size, p2m_limit), PMD_SIZE * PMDS_PER_MID_PAGE); vm_area_register_early(&vm, PMD_SIZE * PMDS_PER_MID_PAGE); pr_notice("p2m virtual area at %p, size is %lx\n", vm.addr, vm.size); =20 - xen_max_p2m_pfn =3D vm.size / sizeof(unsigned long); + xen_p2m_max_size =3D vm.size / sizeof(unsigned long); =20 xen_rebuild_p2m_list(vm.addr); =20 xen_p2m_addr =3D vm.addr; - xen_p2m_size =3D xen_max_p2m_pfn; + xen_p2m_size =3D xen_p2m_max_size; =20 xen_inv_extra_mem(); } @@ -438,7 +441,7 @@ unsigned long get_phys_to_machine(unsigned long pfn) unsigned int level; =20 if (unlikely(pfn >=3D xen_p2m_size)) { - if (pfn < xen_max_p2m_pfn) + if (pfn < xen_p2m_max_size) return xen_chk_extra_mem(pfn); =20 return IDENTITY_FRAME(pfn); @@ -618,9 +621,9 @@ int xen_alloc_p2m_entry(unsigned long pfn) } =20 /* Expanded the p2m? */ - if (pfn >=3D xen_p2m_last_pfn) { - xen_p2m_last_pfn =3D ALIGN(pfn + 1, P2M_PER_PAGE); - HYPERVISOR_shared_info->arch.max_pfn =3D xen_p2m_last_pfn; + if (pfn >=3D xen_p2m_pfn_limit) { + xen_p2m_pfn_limit =3D ALIGN(pfn + 1, P2M_PER_PAGE); + HYPERVISOR_shared_info->arch.max_pfn =3D xen_p2m_pfn_limit; } =20 return 0; diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 8bfc10330107..1caddd3fa0e1 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -816,7 +816,7 @@ char * __init xen_memory_setup(void) n_pfns =3D PFN_DOWN(addr + chunk_size) - pfn_s; extra_pages -=3D n_pfns; xen_add_extra_mem(pfn_s, n_pfns); - xen_max_p2m_pfn =3D pfn_s + n_pfns; + xen_p2m_max_size =3D pfn_s + n_pfns; } else discard =3D true; } --=20 2.26.2