[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-4.16 v2] tests/resource: Extend to check that the grant frames are mapped correctly


  • To: Jane Malalane <jane.malalane@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 12 Nov 2021 16:16:37 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=01TsVJttcEE28fZMFYHSqXA/Q7x5Gh7HZbQvT6tp0EE=; b=miELO1fy66rF1RIjaG61Fxvk9AqgNElq6/QG/f9J/1QlqfMGp5cyZGIB1OCwrbF++hTTGpeyt4usTxH7gz+Hqm3Y3SsqNj34ZqbHBkchyn+G1LvYvLxaYfQ4VFVguAMlnpbTXdsQ15NinbR7aX2FjmooFmc4SsJCqSJWmpUGGzjJMg8ggdluUjzndu2R4LhqECRz9CvvEhpvj91O9zfaYm0Jnyb0Ao0pjCVRF1org2wfFrbpYJv3dkmI58S5ZkyIj/2nHBft9ha9MkKRd9e64IQtaGEoL5qCFzfnYUPQYJxWmRgZwMhMu1B9wjkb53gnr6vmu4gPCDW20drcHvJ7Pw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=no+K2o0xl9KTy7FGeJ6yd5P/mdD8GrIWfxkAytrQzHtM5bR6jnjjFoo4eBpsMgdIpS31QlH7MOA3Mnla7fWhpQqM1x2lbb90S8csNFgAiGfUv7dVGHG6uXLqqpmsKzZHM2y2Qqixq6L9fYPs67g/9ZoCFz2GXhvgMt41jZF27oaAmx+6ddi0q9tkb42nJL85LMSfjLw4daIAFDZg4LBWWOkowfMKcQE97AdfTH/GsmttLsJSW0DzusgY6bboJHxajIE5kVyvjYaoW45oV85gnWmrC6/72BPbcgSyy+dMYsDF49VodEYueYzYwl1cBRy0IjM3yu5wvnLuNdoD2UVIng==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 12 Nov 2021 15:17:09 +0000
  • Ironport-data: A9a23:ZqR8RaIZqbyw8NYuFE+RD5IlxSXFcZb7ZxGr2PjKsXjdYENS1GcGn WofWTuEb/jZYWanLt4nbo3i9hgEv8Tdy4diTAJlqX01Q3x08seUXt7xwmUcns+xwm8vaGo9s q3yv/GZdJhcokcxIn5BC5C5xZVG/fjgqoHUVaiUZUideSc+EH140Es6wbZj6mJVqYPR7z2l6 IuaT/L3YDdJ6xYsWo7Dw/vewP/HlK2aVAIw5jTSV9gS1LPtvyB94KYkDbOwNxPFrrx8RYZWc QphIIaRpQs19z91Yj+sfy2SnkciGtY+NiDW4pZatjTLbrGvaUXe345iXMfwZ3u7hB2jxPBV8 /JHvKePCgIPFYvjndYgVwhhRnQW0a1uoNcrIFC6uM2XiUbHb2Ht07NlC0Re0Y8wo7gtRzsUr LpBdW5LPkvra+GemdpXTsF2gcsuNo/zNZ43sXB81zDJS/0hRPgvRo2XuoUChWtt2qiiG97Be JdFR2I/NSjlRCxuMFdNE49kkd+B0yyXnzpw9wvO+PtfD3Lo5BN1+KjgNpzSYNPibcRKnG6Iq 2Te5WP7DxoGctuFxlKt4n+qw+PCgy7/cIYTD6GjsO5nhkWJwW4eAwFQUkG0ycRVkWbnBYgZc RZNvHNz8+5iryRHU+URQTWS+16ghTkWUuFvUOgcwyeiz5jp5xegUz1soiF6VPQqs8o/RDoP3 1CPns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2Ihz0JezpzeXcGPTWua6BJc6 Z1saF81kSdkDksH4mGL0hAe9KGi8zAlZrgbxJDLxk76DOWhTftzLLhCRCX0joXTjsKmN4ZgC f4uj28wp/mn+Cwyxfa2WOWx5NKmOH5wt8GIMCXkMAaJhjllw7tToV8XL+puiwzvYiUmRoXue iJhy1lE9V46nvXcG3wiRzx2zP42DJr0HPmwU/wuwqqneXJABYBT+ZRj4NQdRXUr2A6ustn7a 5N12WF87JKEBLphk3Glpj1fiAvsnDxjWspkOYVgXAae5AZcqVtoYsW+14QOIscHRj99JssHI BVfYDhDc5tABGnhk3izyxSKITGZAV2Iv7GeDlNhiWt6UkUoJgjpHFog/D2nR87hdsAotd/lq L5259T5cRzp/ktHNRA7dc6MLmK41P2MGbx2UKpUB/a/fI8SjjwQ6Ce2sRD2AjtQu1Q8KcP
  • Ironport-sdr: Bn7dxd84E29Wb2QmdYIiBsDI3KnGvRF2jjOU7ynaP158AR1dvURDy/NvSmkIew78YdVZmMlrNL dAETN95uus/MHvNy1YeEPHx91gildvqB3QMg5ZVFbpqjxxDImkR+3CQeOrZM6r4IzgiIwq4Y6W qt9CNb5WuwFjA9Y0+qMgQ+hsvAnjRFUN2Zh/qExYqXnr+PqCmNuPGxeG/+Swh0osHOHENWPwuH D1r0I29aIAQLWVcTiScE1WVmZLiFGC3iDAx6n4oVzyuEmGEKQKSltRNxidmsMhtmNE/qSkoUOq 0rJ7P0GoiCYw/iAswHVctfpE
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Nov 12, 2021 at 02:48:21PM +0000, Jane Malalane wrote:
> 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 <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Jane Malalane <jane.malalane@xxxxxxxxxx>
> Release-Acked-by: Ian Jackson <iwj@xxxxxxxxxxxxxx>

LGTM:

Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

There are a couple of lines that exceed the 80 column limit that we
have for other pieces of code, not sure if there's some kind of
exception for tests. If so it might be easy to either resend or fix at
commit.

> ---
> CC: Ian Jackson <iwj@xxxxxxxxxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> 
> 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 += -Werror
>  CFLAGS += $(CFLAGS_xeninclude)
>  CFLAGS += $(CFLAGS_libxenctrl)
>  CFLAGS += $(CFLAGS_libxenforeginmemory)
> +CFLAGS += $(CFLAGS_libxengnttab)
>  CFLAGS += $(APPEND_CFLAGS)
>  
>  LDFLAGS += $(LDLIBS_libxenctrl)
>  LDFLAGS += $(LDLIBS_libxenforeignmemory)
> +LDFLAGS += $(LDLIBS_libxengnttab)
>  LDFLAGS += $(APPEND_LDFLAGS)
>  
>  %.o: Makefile
> diff --git a/tools/tests/resource/test-resource.c 
> b/tools/tests/resource/test-resource.c
> index 1caaa60e62..286d338c1f 100644
> --- a/tools/tests/resource/test-resource.c
> +++ b/tools/tests/resource/test-resource.c
> @@ -6,6 +6,7 @@
>  
>  #include <xenctrl.h>
>  #include <xenforeignmemory.h>
> +#include <xengnttab.h>
>  #include <xen-tools/libs.h>
>  
>  static unsigned int nr_failures;
> @@ -17,13 +18,16 @@ static unsigned int nr_failures;
>  
>  static xc_interface *xch;
>  static xenforeignmemory_handle *fh;
> +static xengnttab_handle *gh;
>  
> -static void test_gnttab(uint32_t domid, unsigned int nr_frames)
> +static void test_gnttab(uint32_t domid, unsigned int nr_frames, unsigned 
> long gfn)

Nit: i think this line exceeds the 80 column limit.

>  {
>      xenforeignmemory_resource_handle *res;
> -    void *addr = NULL;
> +    grant_entry_v1_t *gnttab;
>      size_t size;
>      int rc;
> +    uint32_t refs[nr_frames], domids[nr_frames];
> +    void *grants;
>  
>      printf("  Test grant table\n");
>  
> @@ -51,18 +55,53 @@ static void test_gnttab(uint32_t domid, unsigned int 
> nr_frames)
>      res = 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);
>  
>      /*
>       * 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));

Likewise.

>  
> +    /* Put each gref at a unique offset in its frame. */
> +    for ( unsigned int i = 0; i < nr_frames; i++ )
> +    {
> +        unsigned int gref = i * (XC_PAGE_SIZE / sizeof(*gnttab)) + i;
> +
> +        refs[i] = gref;
> +        domids[i] = domid;
> +
> +        gnttab[gref].domid = 0;
> +        gnttab[gref].frame = gfn;
> +        gnttab[gref].flags = GTF_permit_access;
> +    }
> +
> +    /* Map grants. */
> +    grants = xengnttab_map_grant_refs(gh, nr_frames, domids, refs, PROT_READ 
> | PROT_WRITE);

Here.

> +
> +    /*
> +     * 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 == NULL )
> +    {
> +        fail("    Fail: Map grants %d - %s\n", errno, strerror(errno));
> +        goto out;
> +    }
> +
> +    /* Unmap grants. */
> +    rc = xengnttab_unmap(gh, grants, nr_frames);
> +
> +    if ( rc )
> +        fail("    Fail: Unmap grants %d - %s\n", errno, strerror(errno));
> +
> +    /* Unmap grant table. */
> + out:
>      rc = 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, 
> strerror(errno));

Here.

>  }
>  
>  static void test_domain_configurations(void)
> @@ -107,6 +146,7 @@ static void test_domain_configurations(void)
>          struct test *t = &tests[i];
>          uint32_t domid = 0;
>          int rc;
> +        xen_pfn_t ram[1] = { 0 };
>  
>          printf("Test %s\n", t->name);
>  
> @@ -123,8 +163,25 @@ static void test_domain_configurations(void)
>  
>          printf("  Created d%u\n", domid);
>  
> -        test_gnttab(domid, t->create.max_grant_frames);
> +        rc = 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 = xc_domain_populate_physmap_exact(xch, domid, ARRAY_SIZE(ram), 
> 0, 0, ram);

And here also.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.