From: Oleksandr Tyshchenko <olekstysh@gmail.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
"Ian Jackson" <iwj@xenproject.org>, "Wei Liu" <wl@xen.org>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH for-4.15] tools/tests: Introduce a test for acquire_resource
Date: Thu, 4 Feb 2021 15:29:52 +0200 [thread overview]
Message-ID: <CAPD2p-nPr_OD7cMT-Ny6vyGsY4nMXuENgrqv0pfYRYtE5srnkQ@mail.gmail.com> (raw)
In-Reply-To: <20210202190937.30206-1-andrew.cooper3@citrix.com>
[-- Attachment #1: Type: text/plain, Size: 8391 bytes --]
Hi Andrew.
[Sorry for the possible format issues]
On Tue, Feb 2, 2021 at 9:10 PM Andrew Cooper <andrew.cooper3@citrix.com>
wrote:
> For now, simply try to map 40 frames of grant table. This catches most of
> the
> basic errors with resource sizes found and fixed through the 4.15 dev
> window.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Ian Jackson <iwj@xenproject.org>
> CC: Wei Liu <wl@xen.org>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Wei Liu <wl@xen.org>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
> CC: Oleksandr <olekstysh@gmail.com>
>
> Fails against current staging:
>
> XENMEM_acquire_resource tests
> Test x86 PV
> d7: grant table
> Fail: Map 7 - Argument list too long
> Test x86 PVH
> d8: grant table
> Fail: Map 7 - Argument list too long
>
> The fix has already been posted:
> [PATCH v9 01/11] xen/memory: Fix mapping grant tables with
> XENMEM_acquire_resource
>
> and the fixed run is:
>
> XENMEM_acquire_resource tests
> Test x86 PV
> d7: grant table
> Test x86 PVH
> d8: grant table
>
> ARM folk: would you mind testing this? I'm pretty sure the create
> parameters
> are suitable, but I don't have any way to test this.
>
Yes, as it was agreed on IRC, I will test this today's evening and inform
about the results)
>
> I've got more plans for this, but insufficient time right now.
> ---
> tools/tests/Makefile | 1 +
> tools/tests/resource/.gitignore | 1 +
> tools/tests/resource/Makefile | 40 ++++++++++
> tools/tests/resource/test-resource.c | 138
> +++++++++++++++++++++++++++++++++++
> 4 files changed, 180 insertions(+)
> create mode 100644 tools/tests/resource/.gitignore
> create mode 100644 tools/tests/resource/Makefile
> create mode 100644 tools/tests/resource/test-resource.c
>
> diff --git a/tools/tests/Makefile b/tools/tests/Makefile
> index fc9b715951..c45b5fbc1d 100644
> --- a/tools/tests/Makefile
> +++ b/tools/tests/Makefile
> @@ -2,6 +2,7 @@ XEN_ROOT = $(CURDIR)/../..
> include $(XEN_ROOT)/tools/Rules.mk
>
> SUBDIRS-y :=
> +SUBDIRS-y := resource
> SUBDIRS-$(CONFIG_X86) += cpu-policy
> SUBDIRS-$(CONFIG_X86) += mce-test
> ifneq ($(clang),y)
> diff --git a/tools/tests/resource/.gitignore
> b/tools/tests/resource/.gitignore
> new file mode 100644
> index 0000000000..4872e97d4b
> --- /dev/null
> +++ b/tools/tests/resource/.gitignore
> @@ -0,0 +1 @@
> +test-resource
> diff --git a/tools/tests/resource/Makefile b/tools/tests/resource/Makefile
> new file mode 100644
> index 0000000000..8a3373e786
> --- /dev/null
> +++ b/tools/tests/resource/Makefile
> @@ -0,0 +1,40 @@
> +XEN_ROOT = $(CURDIR)/../../..
> +include $(XEN_ROOT)/tools/Rules.mk
> +
> +TARGET := test-resource
> +
> +.PHONY: all
> +all: $(TARGET)
> +
> +.PHONY: run
> +run: $(TARGET)
> + ./$(TARGET)
> +
> +.PHONY: clean
> +clean:
> + $(RM) -f -- *.o .*.d .*.d2 $(TARGET)
> +
> +.PHONY: distclean
> +distclean: clean
> + $(RM) -f -- *~
> +
> +.PHONY: install
> +install: all
> +
> +.PHONY: uninstall
> +uninstall:
> +
> +CFLAGS += -Werror -D__XEN_TOOLS__
> +CFLAGS += $(CFLAGS_xeninclude)
> +CFLAGS += $(CFLAGS_libxenctrl)
> +CFLAGS += $(CFLAGS_libxenforeginmemory)
> +CFLAGS += $(APPEND_CFLAGS)
> +
> +LDFLAGS += $(LDLIBS_libxenctrl)
> +LDFLAGS += $(LDLIBS_libxenforeignmemory)
> +LDFLAGS += $(APPEND_LDFLAGS)
> +
> +test-resource: test-resource.o
> + $(CC) $(LDFLAGS) -o $@ $<
> +
> +-include $(DEPS_INCLUDE)
> diff --git a/tools/tests/resource/test-resource.c
> b/tools/tests/resource/test-resource.c
> new file mode 100644
> index 0000000000..81a2a5cd12
> --- /dev/null
> +++ b/tools/tests/resource/test-resource.c
> @@ -0,0 +1,138 @@
> +#include <err.h>
> +#include <errno.h>
> +#include <error.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <sys/mman.h>
> +
> +#include <xenctrl.h>
> +#include <xenforeignmemory.h>
> +#include <xendevicemodel.h>
> +#include <xen-tools/libs.h>
> +
> +static unsigned int nr_failures;
> +#define fail(fmt, ...) \
> +({ \
> + nr_failures++; \
> + (void)printf(fmt, ##__VA_ARGS__); \
> +})
> +
> +static xc_interface *xch;
> +static xenforeignmemory_handle *fh;
> +static xendevicemodel_handle *dh;
> +
> +static void test_gnttab(uint32_t domid, unsigned int nr_frames)
> +{
> + xenforeignmemory_resource_handle *res;
> + void *addr = NULL;
> + size_t size;
> + int rc;
> +
> + printf(" d%u: grant table\n", domid);
> +
> + rc = xenforeignmemory_resource_size(
> + fh, domid, XENMEM_resource_grant_table,
> + XENMEM_resource_grant_table_id_shared, &size);
> + if ( rc )
> + return fail(" Fail: Get size: %d - %s\n", errno,
> strerror(errno));
> +
> + if ( (size >> XC_PAGE_SHIFT) != nr_frames )
> + return fail(" Fail: Get size: expected %u frames, got %zu\n",
> + nr_frames, size >> XC_PAGE_SHIFT);
> +
> + 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);
> + if ( !res )
> + return fail(" Fail: Map %d - %s\n", errno, strerror(errno));
> +
> + rc = xenforeignmemory_unmap_resource(fh, res);
> + if ( rc )
> + return fail(" Fail: Unmap %d - %s\n", errno, strerror(errno));
> +}
> +
> +static void test_domain_configurations(void)
> +{
> + static struct test {
> + const char *name;
> + struct xen_domctl_createdomain create;
> + } tests[] = {
> +#if defined(__x86_64__) || defined(__i386__)
> + {
> + .name = "x86 PV",
> + .create = {
> + .max_vcpus = 2,
> + .max_grant_frames = 40,
> + },
> + },
> + {
> + .name = "x86 PVH",
> + .create = {
> + .flags = XEN_DOMCTL_CDF_hvm,
> + .max_vcpus = 2,
> + .max_grant_frames = 40,
> + .arch = {
> + .emulation_flags = XEN_X86_EMU_LAPIC,
> + },
> + },
> + },
> +#elif defined(__aarch64__) || defined(__arm__)
> + {
> + .name = "ARM",
> + .create = {
> + .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap,
> + .max_vcpus = 2,
> + .max_grant_frames = 40,
> + },
> + },
> +#endif
> + };
> +
> + for ( unsigned int i = 0; i < ARRAY_SIZE(tests); ++i )
> + {
> + struct test *t = &tests[i];
> + uint32_t domid = 0;
> + int rc;
> +
> + printf("Test %s\n", t->name);
> +
> + rc = xc_domain_create(xch, &domid, &t->create);
> + if ( rc )
> + {
> + if ( errno == EINVAL || errno == EOPNOTSUPP )
> + printf(" Skip: %d - %s\n", errno, strerror(errno));
> + else
> + fail(" Domain create failure: %d - %s\n",
> + errno, strerror(errno));
> + continue;
> + }
> +
> + test_gnttab(domid, t->create.max_grant_frames);
> +
> + rc = xc_domain_destroy(xch, domid);
> + if ( rc )
> + fail(" Failed to destroy domain: %d - %s\n",
> + errno, strerror(errno));
> + }
> +}
> +
> +int main(int argc, char **argv)
> +{
> + printf("XENMEM_acquire_resource tests\n");
> +
> + xch = xc_interface_open(NULL, NULL, 0);
> + fh = xenforeignmemory_open(NULL, 0);
> + dh = xendevicemodel_open(NULL, 0);
> +
> + if ( !xch )
> + err(1, "xc_interface_open");
> + if ( !fh )
> + err(1, "xenforeignmemory_open");
> + if ( !dh )
> + err(1, "xendevicemodel_open");
> +
> + test_domain_configurations();
> +
> + return !!nr_failures;
> +}
> --
> 2.11.0
>
>
--
Regards,
Oleksandr Tyshchenko
[-- Attachment #2: Type: text/html, Size: 11270 bytes --]
next prev parent reply other threads:[~2021-02-04 13:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 19:09 [PATCH for-4.15] tools/tests: Introduce a test for acquire_resource Andrew Cooper
2021-02-04 11:48 ` Ian Jackson
2021-02-04 13:29 ` Oleksandr Tyshchenko [this message]
2021-02-04 15:38 ` Oleksandr
2021-02-04 15:44 ` Andrew Cooper
2021-02-04 16:33 ` Oleksandr
2021-02-04 16:39 ` Andrew Cooper
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=CAPD2p-nPr_OD7cMT-Ny6vyGsY4nMXuENgrqv0pfYRYtE5srnkQ@mail.gmail.com \
--to=olekstysh@gmail.com \
--cc=JBeulich@suse.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=iwj@xenproject.org \
--cc=julien@xen.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).