From nobody Mon Feb 9 20:46:20 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=1638775449; cv=none; d=zohomail.com; s=zohoarc; b=EqUjuohYpupKcH4JX19rfBGxH4RRKyYAbCNyxGTicXlaDb/CUtgKZWhhMhd6FqwC59JuwYFm6BVGeGpqfY799bzs5Iyc/cQEKvdn1yxuoxRJuLH7b01kARbK23ZsFGB1pZkrSli1nZsOWlEflok+/ofK9Y2ovcIA1QI9Sw3OJdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638775449; 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=6ZwIQ/iqw4tJOJDbjhXNjxEyNK1FoP/fIru8GNLpj3E=; b=Rc+7wr2AESqUKGWXhdiW4L9VdOrcEjVuNzrHMw6LiFA0k3O528DA30uy0wBl1TQM6T9lwDNY4CyBCXOETXLkDtZWWpWE+ouuW0fp44Wur3kwX31naEU6+fhGkOXz3NQbxZ4qBw0xROtUBPU8IQ3EUtLcbVwv67y8Nh0cPXMecAo= 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 1638775449334850.528203184052; Sun, 5 Dec 2021 23:24:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238652.413692 (Exim 4.92) (envelope-from ) id 1mu8Lp-0001uJ-AP; Mon, 06 Dec 2021 07:23:53 +0000 Received: by outflank-mailman (output) from mailman id 238652.413692; Mon, 06 Dec 2021 07:23:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mu8Lo-0001sz-TC; Mon, 06 Dec 2021 07:23:52 +0000 Received: by outflank-mailman (input) for mailman id 238652; Mon, 06 Dec 2021 07:23:50 +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 1mu8Ll-0008Mk-PV for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 07:23:49 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 702d5e8a-5665-11ec-8a4d-196798b21f7b; Mon, 06 Dec 2021 08:23:41 +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-out1.suse.de (Postfix) with ESMTPS id 67E9A21940; Mon, 6 Dec 2021 07:23:41 +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 3F43413A9C; Mon, 6 Dec 2021 07:23:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eKQ0Dn26rWHVdAAAMHmgww (envelope-from ); Mon, 06 Dec 2021 07:23:41 +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: 702d5e8a-5665-11ec-8a4d-196798b21f7b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1638775421; 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=6ZwIQ/iqw4tJOJDbjhXNjxEyNK1FoP/fIru8GNLpj3E=; b=Dx4H9mkwe6zA3efQNNiTwU8kUNk9Ej8hkMBKut7osjyQ2cr7rnD6CpIA0Nj0RHtFNQgcyg TXfAw58DejxvNQ7ZkIyHrNSxZegZP9MrQRcqoeaTzRwkxZaq5qsws8rpYRbWhG91FY5ejP Q0+4ad5Lmp4I657Xw5k2xxfGMqbAuks= 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 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Date: Mon, 6 Dec 2021 08:23:36 +0100 Message-Id: <20211206072337.9517-10-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211206072337.9517-1-jgross@suse.com> References: <20211206072337.9517-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1638775451341100011 Content-Type: text/plain; charset="utf-8" Instead of passing the pointer of a grantmap entry to the _gntmap_[un]map_grant_ref() sub-functions use the map pointer and the entry index instead. This will be needed for PVH mode usage. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- gntmap.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/gntmap.c b/gntmap.c index f6ab3ad..7ae8fe6 100644 --- a/gntmap.c +++ b/gntmap.c @@ -55,36 +55,34 @@ struct gntmap_entry { }; =20 static inline int -gntmap_entry_used(struct gntmap_entry *entry) +gntmap_entry_used(struct gntmap *map, int idx) { - return entry->host_addr !=3D 0; + return map->entries[idx].host_addr !=3D 0; } =20 -static struct gntmap_entry* -gntmap_find_free_entry(struct gntmap *map) +static int gntmap_find_free_entry(struct gntmap *map) { int i; =20 for (i =3D 0; i < map->nentries; i++) { - if (!gntmap_entry_used(&map->entries[i])) - return &map->entries[i]; + if (!gntmap_entry_used(map, i)) + return i; } =20 DEBUG("(map=3D%p): all %d entries full", map, map->nentries); - return NULL; + return -1; } =20 -static struct gntmap_entry* -gntmap_find_entry(struct gntmap *map, unsigned long addr) +static int gntmap_find_entry(struct gntmap *map, unsigned long addr) { int i; =20 for (i =3D 0; i < map->nentries; i++) { if (map->entries[i].host_addr =3D=3D addr) - return &map->entries[i]; + return i; } - return NULL; + return -1; } =20 int @@ -105,12 +103,13 @@ gntmap_set_max_grants(struct gntmap *map, int count) } =20 static int -_gntmap_map_grant_ref(struct gntmap_entry *entry,=20 +_gntmap_map_grant_ref(struct gntmap *map, int idx, unsigned long host_addr, uint32_t domid, uint32_t ref, int writable) { + struct gntmap_entry *entry =3D map->entries + idx; struct gnttab_map_grant_ref op; int rc; =20 @@ -135,8 +134,9 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry, } =20 static int -_gntmap_unmap_grant_ref(struct gntmap_entry *entry) +_gntmap_unmap_grant_ref(struct gntmap *map, int idx) { + struct gntmap_entry *entry =3D map->entries + idx; struct gnttab_unmap_grant_ref op; int rc; =20 @@ -160,19 +160,19 @@ int gntmap_munmap(struct gntmap *map, unsigned long start_address, int count) { int i, rc; - struct gntmap_entry *ent; + int idx; =20 DEBUG("(map=3D%p, start_address=3D%lx, count=3D%d)", map, start_address, count); =20 for (i =3D 0; i < count; i++) { - ent =3D gntmap_find_entry(map, start_address + PAGE_SIZE * i); - if (ent =3D=3D NULL) { + idx =3D gntmap_find_entry(map, start_address + PAGE_SIZE * i); + if (idx < 0) { printk("gntmap: tried to munmap unknown page\n"); return -EINVAL; } =20 - rc =3D _gntmap_unmap_grant_ref(ent); + rc =3D _gntmap_unmap_grant_ref(map, idx); if (rc !=3D 0) return rc; } @@ -189,7 +189,7 @@ gntmap_map_grant_refs(struct gntmap *map, int writable) { unsigned long addr; - struct gntmap_entry *ent; + int idx; int i; =20 DEBUG("(map=3D%p, count=3D%" PRIu32 ", " @@ -206,9 +206,9 @@ gntmap_map_grant_refs(struct gntmap *map, return NULL; =20 for (i =3D 0; i < count; i++) { - ent =3D gntmap_find_free_entry(map); - if (ent =3D=3D NULL || - _gntmap_map_grant_ref(ent, + idx =3D gntmap_find_free_entry(map); + if (idx < 0 || + _gntmap_map_grant_ref(map, idx, addr + PAGE_SIZE * i, domids[i * domids_stride], refs[i], @@ -233,15 +233,13 @@ gntmap_init(struct gntmap *map) void gntmap_fini(struct gntmap *map) { - struct gntmap_entry *ent; int i; =20 DEBUG("(map=3D%p)", map); =20 for (i =3D 0; i < map->nentries; i++) { - ent =3D &map->entries[i]; - if (gntmap_entry_used(ent)) - (void) _gntmap_unmap_grant_ref(ent); + if (gntmap_entry_used(map, i)) + (void) _gntmap_unmap_grant_ref(map, i); } =20 xfree(map->entries); --=20 2.26.2