From nobody Fri Nov 22 03:55:11 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=1724142062; cv=none; d=zohomail.com; s=zohoarc; b=oLOEAlTJsWLLgJbbeFsqQyK8yXfl3QgDV1/L6u027EwQoYRspcaEvcupd2AIjr0qTqmZoerK8MMdXqiG7ikr+KkCV71Hqvr4F6X6wR8j+k1xTMbGm7hKHgBfZ0qrZaDo47ZmXbWPNpsPeOy1PAGjysmKwEup+2VTBiYzfCSE7Mc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724142062; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G5wKq9uWej36pPamlhNBBtzwPiEEwkAyaSi2VMAqres=; b=PXXbPCEL6wXZbvj5nUpHe1AIlmcHTOnl2jBbPfH0JT0n0OWKwk5DslFnON0tCenBgaWWXzs2naivNhdTYU9mYwXW5xt9lJuP9y9W4HBvi+L6t3yrvzpqaPPkUxlplKE+wLld0rPIp7fRSV/syRz8zsM8weAE2kzdXnRAIJ3G9Po= 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 1724142062575453.6029449364777; Tue, 20 Aug 2024 01:21:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.780129.1189754 (Exim 4.92) (envelope-from ) id 1sgK6h-0001HA-KE; Tue, 20 Aug 2024 08:20:47 +0000 Received: by outflank-mailman (output) from mailman id 780129.1189754; Tue, 20 Aug 2024 08:20:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sgK6h-0001H3-HF; Tue, 20 Aug 2024 08:20:47 +0000 Received: by outflank-mailman (input) for mailman id 780129; Tue, 20 Aug 2024 08:20:46 +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 1sgK6g-0006Rb-7U for xen-devel@lists.xenproject.org; Tue, 20 Aug 2024 08:20:46 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 188462a5-5ecd-11ef-8776-851b0ebba9a2; Tue, 20 Aug 2024 10:20:44 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3819222567; Tue, 20 Aug 2024 08:20:44 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DC18513A17; Tue, 20 Aug 2024 08:20:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id /gImNNtRxGbDKwAAD6G6ig (envelope-from ); Tue, 20 Aug 2024 08:20:43 +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: 188462a5-5ecd-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1724142044; 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=G5wKq9uWej36pPamlhNBBtzwPiEEwkAyaSi2VMAqres=; b=IuHw512q0MOlzyyLPfIIudjDfLAxM3WRlaVwZ041JY6jN40wpybB/smy0dyjAs62CSBhre lIzfw8Mv1KGkuPQOcaBF+AkD54Tw7lPk6h8L64WtPxLRrXYZHKu98q3CRLCTYvWik2eese kkVivwUSff3GzCWVH6ZwLUhB9Jl4OXk= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=IuHw512q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1724142044; 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=G5wKq9uWej36pPamlhNBBtzwPiEEwkAyaSi2VMAqres=; b=IuHw512q0MOlzyyLPfIIudjDfLAxM3WRlaVwZ041JY6jN40wpybB/smy0dyjAs62CSBhre lIzfw8Mv1KGkuPQOcaBF+AkD54Tw7lPk6h8L64WtPxLRrXYZHKu98q3CRLCTYvWik2eese kkVivwUSff3GzCWVH6ZwLUhB9Jl4OXk= From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , xen-devel@lists.xenproject.org Subject: [PATCH v2 5/7] xen: add capability to remap non-RAM pages to different PFNs Date: Tue, 20 Aug 2024 10:20:10 +0200 Message-ID: <20240820082012.31316-6-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820082012.31316-1-jgross@suse.com> References: <20240820082012.31316-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 3819222567 X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCPT_COUNT_SEVEN(0.00)[10]; R_RATELIMIT(0.00)[to_ip_from(RLkdkdrsxe9hqhhs5ask8616i6)]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1724142064477116600 Content-Type: text/plain; charset="utf-8" When running as a Xen PV dom0 it can happen that the kernel is being loaded to a guest physical address conflicting with the host memory map. In order to be able to resolve this conflict, add the capability to remap non-RAM areas to different guest PFNs. A function to use this remapping information for other purposes than doing the remap will be added when needed. As the number of conflicts should be rather low (currently only machines with max. 1 conflict are known), save the remap data in a small statically allocated array. Signed-off-by: Juergen Gross --- V2: - split off from patch 5 of V1 of the series - moved to p2m.c --- arch/x86/xen/p2m.c | 65 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/xen/xen-ops.h | 3 ++ 2 files changed, 68 insertions(+) diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index 7c735b730acd..bb55e0fe1a04 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -80,6 +80,7 @@ #include #include #include +#include =20 #include "xen-ops.h" =20 @@ -792,6 +793,70 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_gran= t_ref *unmap_ops, return ret; } =20 +/* Remapped non-RAM areas */ +#define NR_NONRAM_REMAP 4 +static struct nonram_remap { + phys_addr_t maddr; + phys_addr_t paddr; + unsigned long size; +} xen_nonram_remap[NR_NONRAM_REMAP]; +static unsigned int nr_nonram_remap; + +/* + * Do the real remapping of non-RAM regions as specified in the + * xen_nonram_remap[] array. + * In case of an error just crash the system. + */ +void __init xen_do_remap_nonram(void) +{ + unsigned int i; + unsigned int remapped =3D 0; + struct nonram_remap *remap =3D xen_nonram_remap; + unsigned long pfn, mfn, len; + + if (!nr_nonram_remap) + return; + + for (i =3D 0; i < nr_nonram_remap; i++) { + pfn =3D PFN_DOWN(remap->paddr); + mfn =3D PFN_DOWN(remap->maddr); + for (len =3D 0; len < remap->size; len +=3D PAGE_SIZE) { + if (!set_phys_to_machine(pfn, mfn)) { + pr_err("Failed to set p2m mapping for pfn=3D%ld mfn=3D%ld\n", + pfn, mfn); + BUG(); + } + + pfn++; + mfn++; + remapped++; + } + + remap++; + } + + pr_info("Remapped %u non-RAM page(s)\n", remapped); +} + +/* + * Add a new non-RAM remap entry. + * In case of no free entry found, just crash the system. + */ +void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr, + unsigned long size) +{ + if (nr_nonram_remap =3D=3D NR_NONRAM_REMAP) { + xen_raw_console_write("Number of required E820 entry remapping actions e= xceed maximum value\n"); + BUG(); + } + + xen_nonram_remap[nr_nonram_remap].maddr =3D maddr; + xen_nonram_remap[nr_nonram_remap].paddr =3D paddr; + xen_nonram_remap[nr_nonram_remap].size =3D size; + + nr_nonram_remap++; +} + #ifdef CONFIG_XEN_DEBUG_FS #include static int p2m_dump_show(struct seq_file *m, void *v) diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 9a27d1d653d3..e1b782e823e6 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -47,6 +47,9 @@ void xen_mm_unpin_all(void); #ifdef CONFIG_X86_64 void __init xen_relocate_p2m(void); #endif +void __init xen_do_remap_nonram(void); +void __init xen_add_remap_nonram(phys_addr_t maddr, phys_addr_t paddr, + unsigned long size); =20 void __init xen_chk_is_e820_usable(phys_addr_t start, phys_addr_t size, const char *component); --=20 2.43.0