From nobody Mon Apr 29 15:45:22 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1636728583; cv=none; d=zohomail.com; s=zohoarc; b=S4YYaPvM5SPOVOzkmNMU2u9xyRbTqungfELw5HDwmd42NstzansBzRkS6bTirkFrpQgCs/4AdHci5kYnaTpluKYJzRK6VYK8fpq5cJ4rpBmVUK5IWy0xLcxhQf79ysUaSnxCi01MLA9lkoaT6/FLKmDRIhovqOYybUHG+zsab9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636728583; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=pFZqa00xXgzdE0vcqv+vxPC6Aa0NQmKL7praf/lhxk4=; b=NI0wyVtil4WoYFQ2kYK0wAXLKqGOX88GTx/L3jY7XQZM4osWfhdQlYibuUvTUziDWyDzHOfHWIh/FaKkOEypFrDQWPxauZNFhlOXS9wazwmB+Alu/bY3xhosiYj7m/WPDh6skhofF7IRfKuW7zK+G/if9q00Yjgf4nM2zA9KWYY= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1636728583584309.0258952690416; Fri, 12 Nov 2021 06:49:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.225282.389038 (Exim 4.92) (envelope-from ) id 1mlXrc-000179-6Z; Fri, 12 Nov 2021 14:49:12 +0000 Received: by outflank-mailman (output) from mailman id 225282.389038; Fri, 12 Nov 2021 14:49:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mlXrc-000172-3Y; Fri, 12 Nov 2021 14:49:12 +0000 Received: by outflank-mailman (input) for mailman id 225282; Fri, 12 Nov 2021 14:49:10 +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 1mlXra-00016v-KZ for xen-devel@lists.xenproject.org; Fri, 12 Nov 2021 14:49:10 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id af1007a7-43c7-11ec-9787-a32c541c8605; Fri, 12 Nov 2021 15:49:08 +0100 (CET) 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: af1007a7-43c7-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1636728548; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=VhZDuLVZjU9aDCkZMQRVgwJGPF9zi+h/hgwLm11lo6c=; b=EihusLzUIhgjK9rEEz4ZE+yUJu4+uG6lvwjzOPdeNbMw+xet3L7vOyJg 2/Fy88cBhLyVk/SJlDTVbbYD2J0UMnDAq2N1AdH0CuwTAro+bGzGjEUHh bHOyPHPyU5Lu/pqLCG755BmI7j2b94TCyxojIxqBx/s8O/KfGbtQJUH4A Q=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: YbnqWo8DVksOAowrftBEVOEPjEaGRjteYHDblWbf/VblW43xEU4JnisTeHUnnxvyYU1kV2Etmv xAKkP98yiDzCwzmGrygSZxcJ6/PHFe+jUki1gB17vHhcnbqHr3VNHutox1VPh8KicE3ABBFKlO 7jifavn3QtZxhLuRM5j/QWJxHtEiIDnVED3bBPjfWc4/hM+oZarHSfJpAaZyWSnGBtcYc6a0l9 SvDGFNhCKNYNcEn/t6WeG/02ekAD0pVPNMO1hIxjfaiXl3FulsgR3TrR9e1f49bTDP6YF27vES zrUSlh7IHXOFplG1LZeQ4Bo+ X-SBRS: 5.1 X-MesageID: 57217265 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:yL+J96oIwuR3af+RDnEr31Og60teBmLVYhIvgKrLsJaIsI4StFCzt garIBmFPauJZzCnLYp0YYiz9xsBsJeGy942SAFqqCg3RHhG8ZuZCYyVIHmrMnLJJKUvbq7GA +byyDXkBJppJpMJjk71atANlZT4vE2xbuKU5NTsY0idfic5Dnd+4f5fs7Rh2Ncx2IHjW1nlV e7a+KUzBnf0g1aYDUpMg06zgEsHUCPa4W5wUvQWPJinjXeG/5UnJMt3yZKZdhMUdrJ8DO+iL 9sv+Znilo/vE7XBPfv++lrzWhVirrc/pmFigFIOM0SpqkAqSiDfTs/XnRfTAKtao2zhojx/9 DlCnZOBRFg4MrySo+c2SBYFKCYjbKBKpKCSdBBTseTLp6HHW37lwvEoB0AqJ4wIvO1wBAmi9 9RBdmpLNErawbvrnvTrEYGAhex6RCXvFKEWvHwm6DjdBPIvR53rSKTW/95Imjw3g6iiGN6DO JBANmAxMXwsZTVVEH1KGMswudunn33ZagV5kQ+c+qcetj27IAtZj+G2bYu9lsaxbdpRtlaVo CTB5WuRKhAFNvSPx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hwISY1TiX+rb HJoB17726StN9/YgBCpTntAsa9qBDnhPpICOsqTNWftWDd0QPCRuwP0WKL+UyYJ8SUzI5gPM lbHZSWcOeAaGRHsQ== X-IronPort-AV: E=Sophos;i="5.87,229,1631592000"; d="scan'208";a="57217265" From: Jane Malalane To: Xen-devel CC: Jane Malalane , Ian Jackson , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH for-4.16 v2] tests/resource: Extend to check that the grant frames are mapped correctly Date: Fri, 12 Nov 2021 14:48:21 +0000 Message-ID: <20211112144821.987-1-jane.malalane@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1636728584958100003 Previously, we checked that we could map 40 pages with nothing complaining. Now we're adding extra logic to check that those 40 frames are "correct". Suggested-by: Andrew Cooper Signed-off-by: Jane Malalane Release-Acked-by: Ian Jackson Reviewed-by: Roger Pau Monn=C3=A9 --- CC: Ian Jackson CC: Roger Pau Monn=C3=A9 CC: Wei Liu v2: * Cast the gnttab pointer to the correct type (void **) * Fixed comment style --- tools/tests/resource/Makefile | 2 + tools/tests/resource/test-resource.c | 82 ++++++++++++++++++++++++++++++++= +--- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/tools/tests/resource/Makefile b/tools/tests/resource/Makefile index 1c3aee4ff7..b3cd70c06d 100644 --- a/tools/tests/resource/Makefile +++ b/tools/tests/resource/Makefile @@ -31,10 +31,12 @@ CFLAGS +=3D -Werror CFLAGS +=3D $(CFLAGS_xeninclude) CFLAGS +=3D $(CFLAGS_libxenctrl) CFLAGS +=3D $(CFLAGS_libxenforeginmemory) +CFLAGS +=3D $(CFLAGS_libxengnttab) CFLAGS +=3D $(APPEND_CFLAGS) =20 LDFLAGS +=3D $(LDLIBS_libxenctrl) LDFLAGS +=3D $(LDLIBS_libxenforeignmemory) +LDFLAGS +=3D $(LDLIBS_libxengnttab) LDFLAGS +=3D $(APPEND_LDFLAGS) =20 %.o: Makefile diff --git a/tools/tests/resource/test-resource.c b/tools/tests/resource/te= st-resource.c index 1caaa60e62..286d338c1f 100644 --- a/tools/tests/resource/test-resource.c +++ b/tools/tests/resource/test-resource.c @@ -6,6 +6,7 @@ =20 #include #include +#include #include =20 static unsigned int nr_failures; @@ -17,13 +18,16 @@ static unsigned int nr_failures; =20 static xc_interface *xch; static xenforeignmemory_handle *fh; +static xengnttab_handle *gh; =20 -static void test_gnttab(uint32_t domid, unsigned int nr_frames) +static void test_gnttab(uint32_t domid, unsigned int nr_frames, unsigned l= ong gfn) { xenforeignmemory_resource_handle *res; - void *addr =3D NULL; + grant_entry_v1_t *gnttab; size_t size; int rc; + uint32_t refs[nr_frames], domids[nr_frames]; + void *grants; =20 printf(" Test grant table\n"); =20 @@ -51,18 +55,53 @@ static void test_gnttab(uint32_t domid, unsigned int nr= _frames) res =3D xenforeignmemory_map_resource( fh, domid, XENMEM_resource_grant_table, XENMEM_resource_grant_table_id_shared, 0, size >> XC_PAGE_SHIFT, - &addr, PROT_READ | PROT_WRITE, 0); + (void **)&gnttab, PROT_READ | PROT_WRITE, 0); =20 /* * Failure here with E2BIG indicates Xen is missing the bugfix to map * resources larger than 32 frames. */ if ( !res ) - return fail(" Fail: Map %d - %s\n", errno, strerror(errno)); + return fail(" Fail: Map grant table %d - %s\n", errno, strerror= (errno)); =20 + /* Put each gref at a unique offset in its frame. */ + for ( unsigned int i =3D 0; i < nr_frames; i++ ) + { + unsigned int gref =3D i * (XC_PAGE_SIZE / sizeof(*gnttab)) + i; + + refs[i] =3D gref; + domids[i] =3D domid; + + gnttab[gref].domid =3D 0; + gnttab[gref].frame =3D gfn; + gnttab[gref].flags =3D GTF_permit_access; + } + + /* Map grants. */ + grants =3D xengnttab_map_grant_refs(gh, nr_frames, domids, refs, PROT_= READ | PROT_WRITE); + + /* + * Failure here indicates either that the frames were not mapped + * in the correct order or xenforeignmemory_map_resource() didn't + * give us the frames we asked for to begin with. + */ + if ( grants =3D=3D NULL ) + { + fail(" Fail: Map grants %d - %s\n", errno, strerror(errno)); + goto out; + } + + /* Unmap grants. */ + rc =3D xengnttab_unmap(gh, grants, nr_frames); + + if ( rc ) + fail(" Fail: Unmap grants %d - %s\n", errno, strerror(errno)); + + /* Unmap grant table. */ + out: rc =3D xenforeignmemory_unmap_resource(fh, res); if ( rc ) - return fail(" Fail: Unmap %d - %s\n", errno, strerror(errno)); + return fail(" Fail: Unmap grant table %d - %s\n", errno, strerr= or(errno)); } =20 static void test_domain_configurations(void) @@ -107,6 +146,7 @@ static void test_domain_configurations(void) struct test *t =3D &tests[i]; uint32_t domid =3D 0; int rc; + xen_pfn_t ram[1] =3D { 0 }; =20 printf("Test %s\n", t->name); =20 @@ -123,8 +163,25 @@ static void test_domain_configurations(void) =20 printf(" Created d%u\n", domid); =20 - test_gnttab(domid, t->create.max_grant_frames); + rc =3D xc_domain_setmaxmem(xch, domid, -1); + if ( rc ) + { + fail(" Failed to set max memory for domain: %d - %s\n", + errno, strerror(errno)); + goto test_done; + } + + rc =3D xc_domain_populate_physmap_exact(xch, domid, ARRAY_SIZE(ram= ), 0, 0, ram); + if ( rc ) + { + fail(" Failed to populate physmap domain: %d - %s\n", + errno, strerror(errno)); + goto test_done; + } + + test_gnttab(domid, t->create.max_grant_frames, ram[0]); =20 + test_done: rc =3D xc_domain_destroy(xch, domid); if ( rc ) fail(" Failed to destroy domain: %d - %s\n", @@ -138,13 +195,26 @@ int main(int argc, char **argv) =20 xch =3D xc_interface_open(NULL, NULL, 0); fh =3D xenforeignmemory_open(NULL, 0); + gh =3D xengnttab_open(NULL, 0); =20 if ( !xch ) err(1, "xc_interface_open"); if ( !fh ) err(1, "xenforeignmemory_open"); + if ( !gh ) + err(1, "xengnttab_open"); =20 test_domain_configurations(); =20 return !!nr_failures; } + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.11.0