All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
Cc: samuel.thibault@ens-lyon.org, wl@xen.org,
	Juergen Gross <jgross@suse.com>
Subject: [PATCH 09/10] mini-os: prepare grantmap entry interface for use by PVH mode
Date: Mon,  6 Dec 2021 08:23:36 +0100	[thread overview]
Message-ID: <20211206072337.9517-10-jgross@suse.com> (raw)
In-Reply-To: <20211206072337.9517-1-jgross@suse.com>

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 <jgross@suse.com>
---
 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 {
 };
 
 static inline int
-gntmap_entry_used(struct gntmap_entry *entry)
+gntmap_entry_used(struct gntmap *map, int idx)
 {
-    return entry->host_addr != 0;
+    return map->entries[idx].host_addr != 0;
 }
 
-static struct gntmap_entry*
-gntmap_find_free_entry(struct gntmap *map)
+static int gntmap_find_free_entry(struct gntmap *map)
 {
     int i;
 
     for (i = 0; i < map->nentries; i++) {
-        if (!gntmap_entry_used(&map->entries[i]))
-            return &map->entries[i];
+        if (!gntmap_entry_used(map, i))
+            return i;
     }
 
     DEBUG("(map=%p): all %d entries full",
            map, map->nentries);
-    return NULL;
+    return -1;
 }
 
-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;
 
     for (i = 0; i < map->nentries; i++) {
         if (map->entries[i].host_addr == addr)
-            return &map->entries[i];
+            return i;
     }
-    return NULL;
+    return -1;
 }
 
 int
@@ -105,12 +103,13 @@ gntmap_set_max_grants(struct gntmap *map, int count)
 }
 
 static int
-_gntmap_map_grant_ref(struct gntmap_entry *entry, 
+_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 = map->entries + idx;
     struct gnttab_map_grant_ref op;
     int rc;
 
@@ -135,8 +134,9 @@ _gntmap_map_grant_ref(struct gntmap_entry *entry,
 }
 
 static int
-_gntmap_unmap_grant_ref(struct gntmap_entry *entry)
+_gntmap_unmap_grant_ref(struct gntmap *map, int idx)
 {
+    struct gntmap_entry *entry = map->entries + idx;
     struct gnttab_unmap_grant_ref op;
     int rc;
 
@@ -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;
 
     DEBUG("(map=%p, start_address=%lx, count=%d)",
            map, start_address, count);
 
     for (i = 0; i < count; i++) {
-        ent = gntmap_find_entry(map, start_address + PAGE_SIZE * i);
-        if (ent == NULL) {
+        idx = gntmap_find_entry(map, start_address + PAGE_SIZE * i);
+        if (idx < 0) {
             printk("gntmap: tried to munmap unknown page\n");
             return -EINVAL;
         }
 
-        rc = _gntmap_unmap_grant_ref(ent);
+        rc = _gntmap_unmap_grant_ref(map, idx);
         if (rc != 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;
 
     DEBUG("(map=%p, count=%" PRIu32 ", "
@@ -206,9 +206,9 @@ gntmap_map_grant_refs(struct gntmap *map,
         return NULL;
 
     for (i = 0; i < count; i++) {
-        ent = gntmap_find_free_entry(map);
-        if (ent == NULL ||
-            _gntmap_map_grant_ref(ent,
+        idx = 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;
 
     DEBUG("(map=%p)", map);
 
     for (i = 0; i < map->nentries; i++) {
-        ent = &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);
     }
 
     xfree(map->entries);
-- 
2.26.2



  parent reply	other threads:[~2021-12-06  7:24 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06  7:23 [PATCH 00/10] mini-os: add missing PVH features Juergen Gross
2021-12-06  7:23 ` [PATCH 01/10] mini-os: split e820 map handling into new source file Juergen Gross
2021-12-11 23:56   ` Samuel Thibault
2021-12-06  7:23 ` [PATCH 02/10] mini-os: sort and sanitize e820 memory map Juergen Gross
2021-12-12  0:05   ` Samuel Thibault
2021-12-13 14:56     ` Juergen Gross
2021-12-13 21:19       ` Samuel Thibault
2021-12-14  6:33         ` Juergen Gross
2021-12-06  7:23 ` [PATCH 03/10] mini-os: don't assume contiguous RAM when initializing in PVH mode Juergen Gross
2021-12-12  0:15   ` Samuel Thibault
2021-12-13 14:58     ` Juergen Gross
2021-12-13 21:22       ` Samuel Thibault
2021-12-14  6:35         ` Juergen Gross
2021-12-14  7:40           ` Samuel Thibault
2021-12-06  7:23 ` [PATCH 04/10] mini-os: respect memory map when ballooning up Juergen Gross
2021-12-12  0:26   ` Samuel Thibault
2021-12-13 15:05     ` Juergen Gross
2021-12-06  7:23 ` [PATCH 05/10] mini-os: don't repeat definition available via header file Juergen Gross
2021-12-12  0:27   ` Samuel Thibault
2021-12-06  7:23 ` [PATCH 06/10] mini-os: add memory map service functions Juergen Gross
2021-12-12  0:37   ` Samuel Thibault
2021-12-06  7:23 ` [PATCH 07/10] mini-os: move x86 specific gnttab coding into arch/x86/gnttab.c Juergen Gross
2021-12-12  0:41   ` Samuel Thibault
2021-12-06  7:23 ` [PATCH 08/10] mini-os: add proper pvh grant table handling Juergen Gross
2021-12-12  0:43   ` Samuel Thibault
2021-12-06  7:23 ` Juergen Gross [this message]
2021-12-12  0:50   ` [PATCH 09/10] mini-os: prepare grantmap entry interface for use by PVH mode Samuel Thibault
2021-12-06  7:23 ` [PATCH 10/10] mini-os: modify grant mappings to work in " Juergen Gross
2021-12-12  0:51   ` Samuel Thibault
2021-12-06 12:46 ` [PATCH] mini-os: support event channel 0 for console Juergen Gross
2021-12-06 13:24   ` Jan Beulich
2021-12-06 13:30     ` Juergen Gross
2021-12-06 14:17     ` Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211206072337.9517-10-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=minios-devel@lists.xenproject.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.