From nobody Mon Feb 9 03:13:42 2026 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=1640016468; cv=none; d=zohomail.com; s=zohoarc; b=AFILIhXGBlesLbR5U9XW9067cpXFKUD0nbI5q85ycXDq5H6+3wQKrFDtUCDCzD5g3XZYYIQZcdpzdS4VEp9Do9VK8pPmU5K8PiUwVgY4BKyRw1jtkqfJax/JCVdfkDf/geAukCU4nSwKDkNLU2AatcL5cELhUMkvqjiW2D3Ip2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016468; 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=0KigAZz9hYluMyaBKPARA/gJpt6ihPK6ZX8SoZiA/8c=; b=MjrPqVbEVhsj9ZtpPCDrkriXheYPDyiISI8gRvvJX6NgIhDZ0wK+znDuPij+/NuSeswqyqK9ERQs75/W5cNA5IUeAcB1WcT1e9R7HfhnJgyB8djewgkilkN2vrnHlbW6nkRaYb4+QrNAnHrRi+MTK5cB9s129e9ivS5CZkZXMSQ= 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 1640016468225190.1737083167768; Mon, 20 Dec 2021 08:07:48 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249855.430281 (Exim 4.92) (envelope-from ) id 1mzLCA-0005uJ-3P; Mon, 20 Dec 2021 16:07:26 +0000 Received: by outflank-mailman (output) from mailman id 249855.430281; Mon, 20 Dec 2021 16:07:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLC9-0005so-Rw; Mon, 20 Dec 2021 16:07:25 +0000 Received: by outflank-mailman (input) for mailman id 249855; Mon, 20 Dec 2021 16:07:23 +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 1mzLC7-00055x-LQ for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:23 +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 e8f9097a-61ae-11ec-9e60-abaf8a552007; Mon, 20 Dec 2021 17:07:21 +0100 (CET) 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 2F11D1F3B0; Mon, 20 Dec 2021 16:07:20 +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 026CA13D6B; Mon, 20 Dec 2021 16:07:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eIh+OjeqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:19 +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: e8f9097a-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016440; 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=0KigAZz9hYluMyaBKPARA/gJpt6ihPK6ZX8SoZiA/8c=; b=BGZCu+VhIL6E6RPcvOccUnBg36tJGuE8MKAUkblyrPPxIhFgMUC38Vgxam65yTOA/6etGK 1FUXdp7oY5jJHkWxYtQhUDTxHM39/P+EDR++VaRNe4xOm49JXsEe9ojD4wWqCTrJmz3XsL +rS9zMb5p5OENE6OL0+w6RPfCDe3EvY= 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 v2 06/10] mini-os: add memory map service functions Date: Mon, 20 Dec 2021 17:07:12 +0100 Message-Id: <20211220160716.4159-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211220160716.4159-1-jgross@suse.com> References: <20211220160716.4159-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1640016469140100001 Content-Type: text/plain; charset="utf-8" Add two functions for adding reserved areas to the memory map and for removing them again. Those will be needed for proper grant table/mapping support in PVH mode. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - fix e820_put_reserved_pfns() (Samuel Thibault) --- e820.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/e820.h | 4 ++++ 2 files changed, 54 insertions(+) diff --git a/e820.c b/e820.c index 659f71c..25e2f9d 100644 --- a/e820.c +++ b/e820.c @@ -283,6 +283,56 @@ void arch_print_memmap(void) printk("%012lx-%012lx: %s\n", from, to, type); } } + +unsigned long e820_get_reserved_pfns(int pages) +{ + int i; + unsigned long last =3D 0, needed =3D (long)pages << PAGE_SHIFT; + + for ( i =3D 0; i < e820_entries && e820_map[i].addr < last + needed; i= ++ ) + last =3D e820_map[i].addr + e820_map[i].size; + + if ( i =3D=3D 0 || e820_map[i - 1].type !=3D E820_RESERVED ) + e820_insert_entry_at(i, last, needed, E820_RESERVED); + else + e820_map[i - 1].size +=3D needed; + + return last >> PAGE_SHIFT; +} + +void e820_put_reserved_pfns(unsigned long start_pfn, int pages) +{ + int i; + unsigned long addr =3D start_pfn << PAGE_SHIFT; + unsigned long size =3D (long)pages << PAGE_SHIFT; + + for ( i =3D 0; + i < e820_entries && addr >=3D e820_map[i].addr + e820_map[i].siz= e; + i++ ); + + BUG_ON(i =3D=3D e820_entries || e820_map[i].type !=3D E820_RESERVED || + addr + size > e820_map[i].addr + e820_map[i].size); + + if ( addr =3D=3D e820_map[i].addr ) + { + e820_map[i].addr +=3D size; + e820_map[i].size -=3D size; + if ( e820_map[i].size =3D=3D 0 ) + e820_remove_entry(i); + return; + } + + if ( addr + size =3D=3D e820_map[i].addr + e820_map[i].size ) + { + e820_map[i].size -=3D size; + return; + } + + e820_insert_entry_at(i + 1, addr + size, + e820_map[i].addr + e820_map[i].size - addr - size, + E820_RESERVED); + e820_map[i].size =3D addr - e820_map[i].addr; +} #endif =20 unsigned long e820_get_maxpfn(unsigned long pages) diff --git a/include/e820.h b/include/e820.h index 8d4d371..aaf2f2c 100644 --- a/include/e820.h +++ b/include/e820.h @@ -51,5 +51,9 @@ extern unsigned e820_entries; =20 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 +unsigned long e820_get_reserved_pfns(int pages); +void e820_put_reserved_pfns(unsigned long start_pfn, int pages); +#endif =20 #endif /*__E820_HEADER*/ --=20 2.26.2