From nobody Mon Feb 9 06:34:16 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=1640016596; cv=none; d=zohomail.com; s=zohoarc; b=NrEEnhq2U1adI3zgYvaVrrVf/MPX5Fb2tOAtUyuVfqEuYoeUycvgJUo0bovTsje1qHq4ghxz0J5KaRGrkJlFMRABaTohmuMUSPzfz88lNpBg7ikQ9JtgDPAZ4g2YIyCd4DF1G6KyKdCXARQ1z2XA8XX1FAKIvx1oKBVO9Zb0ews= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640016596; 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=2zdQgzlV0Lz7UQXRFdnEwu37UxJwIePFbmpJgrcmrrs=; b=YU5cO7yKc0sErm+ZmQXLKdJ2hYMB5NyLfISy0rdpvPzFlDElinGFY5bvONxhZcbf/gI8Z+REKUwegSU1+uq4ITycbQzvjqD2yN9KOCS9Io2fHBJgWFUWTF9SWyFJz0NX+UyF6tT5o5TGkhwpsCZvDDCv7pigyqcl/vrUViQSiuA= 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 1640016596616531.6148116876444; Mon, 20 Dec 2021 08:09:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.249883.430392 (Exim 4.92) (envelope-from ) id 1mzLEF-0003LZ-A4; Mon, 20 Dec 2021 16:09:35 +0000 Received: by outflank-mailman (output) from mailman id 249883.430392; Mon, 20 Dec 2021 16:09:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzLEF-0003LS-78; Mon, 20 Dec 2021 16:09:35 +0000 Received: by outflank-mailman (input) for mailman id 249883; Mon, 20 Dec 2021 16:09:33 +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 1mzLCG-00055x-Mv for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 16:07:32 +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 e99c05da-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 0B0E61F3B3; Mon, 20 Dec 2021 16:07:21 +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 D252713D6B; Mon, 20 Dec 2021 16:07:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kBDxMTiqwGEUTAAAMHmgww (envelope-from ); Mon, 20 Dec 2021 16:07:20 +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: e99c05da-61ae-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640016441; 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=2zdQgzlV0Lz7UQXRFdnEwu37UxJwIePFbmpJgrcmrrs=; b=cIrE1NZbVnDGYkqyRper8jcEWCZAJdk3Br9r1GRzza5OM5fPT4kXfv0ngZHUl4fn0iZ6tW h+sq6ZsGnP6RsLm13byTnCo1CZ/lDlcTRnxfrTeHnM0uZeZ0+Vt8185UPLyFFrxJrZ/wCp aTJZL567BK5Z4U1aCMcRfCtgiowLuQA= 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 10/10] mini-os: modify grant mappings to work in PVH mode Date: Mon, 20 Dec 2021 17:07:16 +0100 Message-Id: <20211220160716.4159-11-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: 1640016598256100001 Content-Type: text/plain; charset="utf-8" For being able to use the grant mapping interface in PVH mode some changes are required, as the guest needs to specify a physical address in the hypercall interface. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- gntmap.c | 81 ++++++++++++++++++++++++++++++++++-------------- include/gntmap.h | 1 + 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/gntmap.c b/gntmap.c index 7ae8fe6..126b04f 100644 --- a/gntmap.c +++ b/gntmap.c @@ -32,6 +32,7 @@ =20 #include #include +#include #include #include #include @@ -97,11 +98,42 @@ gntmap_set_max_grants(struct gntmap *map, int count) if (map->entries =3D=3D NULL) return -ENOMEM; =20 +#ifndef CONFIG_PARAVIRT + map->start_pfn =3D e820_get_reserved_pfns(count); +#endif + memset(map->entries, 0, sizeof(struct gntmap_entry) * count); map->nentries =3D count; return 0; } =20 +static int +_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; + +#ifdef CONFIG_PARAVIRT + op.host_addr =3D (uint64_t) entry->host_addr; +#else + op.host_addr =3D (uint64_t)(map->start_pfn + idx) << PAGE_SHIFT; +#endif + op.dev_bus_addr =3D 0; + op.handle =3D entry->handle; + + rc =3D HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); + if (rc !=3D 0 || op.status !=3D GNTST_okay) { + printk("GNTTABOP_unmap_grant_ref failed: " + "returned %d, status %" PRId16 "\n", + rc, op.status); + return rc !=3D 0 ? rc : op.status; + } + + entry->host_addr =3D 0; + return 0; +} + static int _gntmap_map_grant_ref(struct gntmap *map, int idx, unsigned long host_addr, @@ -112,10 +144,17 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, struct gntmap_entry *entry =3D map->entries + idx; struct gnttab_map_grant_ref op; int rc; +#ifndef CONFIG_PARAVIRT + unsigned long pfn =3D map->start_pfn + idx; +#endif =20 op.ref =3D (grant_ref_t) ref; op.dom =3D (domid_t) domid; +#ifdef CONFIG_PARAVIRT op.host_addr =3D (uint64_t) host_addr; +#else + op.host_addr =3D (uint64_t)pfn << PAGE_SHIFT;=20 +#endif op.flags =3D GNTMAP_host_map; if (!writable) op.flags |=3D GNTMAP_readonly; @@ -128,31 +167,18 @@ _gntmap_map_grant_ref(struct gntmap *map, int idx, return rc !=3D 0 ? rc : op.status; } =20 - entry->host_addr =3D host_addr; - entry->handle =3D op.handle; - return 0; -} - -static int -_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; - - op.host_addr =3D (uint64_t) entry->host_addr; - op.dev_bus_addr =3D 0; - op.handle =3D entry->handle; - - rc =3D HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); - if (rc !=3D 0 || op.status !=3D GNTST_okay) { - printk("GNTTABOP_unmap_grant_ref failed: " - "returned %d, status %" PRId16 "\n", - rc, op.status); - return rc !=3D 0 ? rc : op.status; +#ifndef CONFIG_PARAVIRT + rc =3D do_map_frames(host_addr, &pfn, 1, 0, 0, DOMID_SELF, NULL, + writable ? L1_PROT : L1_PROT_RO); + if ( rc ) + { + _gntmap_unmap_grant_ref(map, idx); + return rc; } +#endif =20 - entry->host_addr =3D 0; + entry->host_addr =3D host_addr; + entry->handle =3D op.handle; return 0; } =20 @@ -165,6 +191,10 @@ gntmap_munmap(struct gntmap *map, unsigned long start_= address, int count) DEBUG("(map=3D%p, start_address=3D%lx, count=3D%d)", map, start_address, count); =20 +#ifndef CONFIG_PARAVIRT + unmap_frames(start_address, count); +#endif + for (i =3D 0; i < count; i++) { idx =3D gntmap_find_entry(map, start_address + PAGE_SIZE * i); if (idx < 0) { @@ -242,6 +272,11 @@ gntmap_fini(struct gntmap *map) (void) _gntmap_unmap_grant_ref(map, i); } =20 +#ifndef CONFIG_PARAVIRT + e820_put_reserved_pfns(map->start_pfn, map->nentries); + map->start_pfn =3D 0; +#endif + xfree(map->entries); map->entries =3D NULL; map->nentries =3D 0; diff --git a/include/gntmap.h b/include/gntmap.h index fde53f3..d3d7e88 100644 --- a/include/gntmap.h +++ b/include/gntmap.h @@ -10,6 +10,7 @@ struct gntmap { int nentries; struct gntmap_entry *entries; + unsigned long start_pfn; }; =20 int --=20 2.26.2