All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <stefanos@xilinx.com>,
	julien.grall@arm.com, sstabellini@kernel.org,
	ian.jackson@eu.citrix.com, wei.liu2@citrix.com
Subject: [Xen-devel] [PATCH v4 5/6] libxl/xl: add memory policy option to iomem
Date: Tue,  6 Aug 2019 17:23:10 -0700	[thread overview]
Message-ID: <20190807002311.9906-5-sstabellini@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.21.1908061708420.2451@sstabellini-ThinkPad-T480s>

Add a new memory policy option for the iomem parameter.
Possible values are:
- arm_dev_nGnRE, Device-nGnRE, the default on Arm
- arm_mem_WB, WB cachable memory
- default

Store the parameter in a new field in libxl_iomem_range.

Pass the memory policy option to xc_domain_mem_map_policy.

Do the libxl to libxc value conversion in per-arch functions so that we
can return error for x86 parameters on Arm architectures and vice versa.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
CC: ian.jackson@eu.citrix.com
CC: wei.liu2@citrix.com
---
Changes in v4:
- ARM -> Arm
- libxl__memory_policy_to_xc -> libxl__arch_memory_policy_to_xc
- keep Arm policies together

Changes in v3:
- s/nGRE/nGnRE/g
- s/LIBXL_MEMORY_POLICY_ARM_DEV_NGRE/LIBXL_MEMORY_POLICY_ARM_DEV_NGNRE/g
- s/arm_devmem/arm_dev_nGnRE/g
- s/arm_memory/arm_mem_WB/g
- improve commit message
- improve man page
- s/MEMORY_POLICY_X86_UC/MEMORY_POLICY_X86_UC_MINUS/g
- s/x86_uc/x86_UC_minus/g
- move security support clarification to a separate patch

Changes in v2:
- add #define LIBXL_HAVE_MEMORY_POLICY
- ability to part the memory policy parameter even if gfn is not passed
- rename cache_policy to memory policy
- rename MEMORY_POLICY_DEVMEM to MEMORY_POLICY_ARM_DEV_nGRE
- rename MEMORY_POLICY_MEMORY to MEMORY_POLICY_ARM_MEM_WB
- rename memory to arm_memory and devmem to arm_devmem
- expand the non-security support status to non device passthrough iomem
  configurations
- rename iomem options
- add x86 specific iomem option
---
 docs/man/xl.cfg.5.pod.in    | 10 +++++++++-
 tools/libxl/libxl.h         |  5 +++++
 tools/libxl/libxl_arch.h    |  3 +++
 tools/libxl/libxl_arm.c     | 14 ++++++++++++++
 tools/libxl/libxl_create.c  | 12 ++++++++++--
 tools/libxl/libxl_types.idl |  8 ++++++++
 tools/libxl/libxl_x86.c     | 10 ++++++++++
 tools/xl/xl_parse.c         | 22 +++++++++++++++++++++-
 8 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in
index c99d40307e..77df9c1bdb 100644
--- a/docs/man/xl.cfg.5.pod.in
+++ b/docs/man/xl.cfg.5.pod.in
@@ -1222,7 +1222,7 @@ is given in hexadecimal format and may either be a range, e.g. C<2f8-2ff>
 It is recommended to only use this option for trusted VMs under
 administrator's control.
 
-=item B<iomem=[ "IOMEM_START,NUM_PAGES[@GFN]", "IOMEM_START,NUM_PAGES[@GFN]", ...]>
+=item B<iomem=[ "IOMEM_START,NUM_PAGES[@GFN],MEMORY_POLICY", "IOMEM_START,NUM_PAGES[@GFN][,MEMORY_POLICY]", ...]>
 
 Allow auto-translated domains to access specific hardware I/O memory pages.
 
@@ -1233,6 +1233,14 @@ B<GFN> is not specified, the mapping will be performed using B<IOMEM_START>
 as a start in the guest's address space, therefore performing a 1:1 mapping
 by default.
 All of these values must be given in hexadecimal format.
+B<MEMORY_POLICY> for Arm platforms:
+  - "arm_dev_nGnRE" for Device-nGnRE (Device Memory on Armv7), the default on Arm
+  - "arm_mem_WB" for Outer Shareable Write-Back Cacheable Memory
+They select the stage-2 memory attributes, but note that the resulting
+memory attributes will be a combination of stage-2 and stage-1 memory
+attributes: it will be the strongest between the 2 stages attributes.
+B<MEMORY_POLICY> can be for both Arm and x86 platforms:
+  - "default" which is Uncachable Memory on x86, and arm_dev_nGnRE on Arm
 
 Note that the IOMMU won't be updated with the mappings specified with this
 option. This option therefore should not be used to pass through any
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 9bacfb97f0..cf12f1d3bd 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -378,6 +378,11 @@
 #define LIBXL_HAVE_BUILDINFO_BOOTLOADER 1
 #define LIBXL_HAVE_BUILDINFO_BOOTLOADER_ARGS 1
 
+/*
+ * Support specifying memory policy information for memory mappings.
+ */
+#define LIBXL_HAVE_MEMORY_POLICY 1
+
 /*
  * LIBXL_HAVE_EXTENDED_VKB indicates that libxl_device_vkb has extended fields:
  *  - unique_id;
diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h
index d624159e53..796c961568 100644
--- a/tools/libxl/libxl_arch.h
+++ b/tools/libxl/libxl_arch.h
@@ -77,6 +77,9 @@ int libxl__arch_extra_memory(libxl__gc *gc,
                              const libxl_domain_build_info *info,
                              uint64_t *out);
 
+_hidden
+int libxl__arch_memory_policy_to_xc(libxl_memory_policy c);
+
 #if defined(__i386__) || defined(__x86_64__)
 
 #define LAPIC_BASE_ADDRESS  0xfee00000
diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c
index 141e159043..6b8e7ddb06 100644
--- a/tools/libxl/libxl_arm.c
+++ b/tools/libxl/libxl_arm.c
@@ -1149,6 +1149,20 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc,
     libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PVH);
 }
 
+int libxl__arch_memory_policy_to_xc(libxl_memory_policy c)
+{
+    switch (c) {
+    case LIBXL_MEMORY_POLICY_ARM_MEM_WB:
+        return MEMORY_POLICY_ARM_MEM_WB;
+    case LIBXL_MEMORY_POLICY_ARM_DEV_NGNRE:
+        return MEMORY_POLICY_ARM_DEV_nGnRE;
+    case LIBXL_MEMORY_POLICY_DEFAULT:
+        return MEMORY_POLICY_DEFAULT;
+    default:
+        return ERROR_INVAL;
+    }
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 03ce166f4f..9b375cdf69 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1357,6 +1357,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
 
     for (i = 0; i < d_config->b_info.num_iomem; i++) {
         libxl_iomem_range *io = &d_config->b_info.iomem[i];
+        int memory_policy;
 
         LOGD(DEBUG, domid, "iomem %"PRIx64"-%"PRIx64,
              io->start, io->start + io->number - 1);
@@ -1370,9 +1371,16 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
             ret = ERROR_FAIL;
             goto error_out;
         }
-        ret = xc_domain_memory_mapping(CTX->xch, domid,
+        memory_policy = libxl__arch_memory_policy_to_xc(io->memory_policy);
+        if (memory_policy < 0) {
+            LOGED(ERROR, domid,
+                  "invalid memory policy %u", io->memory_policy);
+            ret = ERROR_FAIL;
+            goto error_out;
+        }
+        ret = xc_domain_mem_map_policy(CTX->xch, domid,
                                        io->gfn, io->start,
-                                       io->number, 1);
+                                       io->number, 1, memory_policy);
         if (ret < 0) {
             LOGED(ERROR, domid,
                   "failed to map to domain iomem range %"PRIx64"-%"PRIx64
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index b61399ce36..ad5d9cdae2 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -272,6 +272,12 @@ libxl_ioport_range = Struct("ioport_range", [
     ("number", uint32),
     ])
 
+libxl_memory_policy = Enumeration("memory_policy", [
+    (0, "default"),
+    (1, "ARM_Dev_nGnRE"),
+    (2, "ARM_Mem_WB"),
+    ], init_val = "LIBXL_MEMORY_POLICY_DEFAULT")
+
 libxl_iomem_range = Struct("iomem_range", [
     # start host frame number to be mapped to the guest
     ("start", uint64),
@@ -279,6 +285,8 @@ libxl_iomem_range = Struct("iomem_range", [
     ("number", uint64),
     # guest frame number used as a start for the mapping
     ("gfn", uint64, {'init_val': "LIBXL_INVALID_GFN"}),
+    # memory_policy of the memory region
+    ("memory_policy", libxl_memory_policy),
     ])
 
 libxl_vga_interface_info = Struct("vga_interface_info", [
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index c0f88a7eaa..32c211c3ae 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -631,6 +631,16 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc,
     libxl_defbool_setdefault(&b_info->acpi, true);
 }
 
+int libxl__arch_memory_policy_to_xc(libxl_memory_policy c)
+{
+    switch (c) {
+    case LIBXL_MEMORY_POLICY_DEFAULT:
+        return MEMORY_POLICY_DEFAULT;
+    default:
+        return ERROR_INVAL;
+    }
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index e105bda2bb..c019bca728 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -1883,6 +1883,7 @@ void parse_config_data(const char *config_source,
         }
         for (i = 0; i < num_iomem; i++) {
             int used;
+            const char *mempolicy;
 
             buf = xlu_cfg_get_listitem (iomem, i);
             if (!buf) {
@@ -1895,11 +1896,30 @@ void parse_config_data(const char *config_source,
                          &b_info->iomem[i].start,
                          &b_info->iomem[i].number, &used,
                          &b_info->iomem[i].gfn, &used);
-            if (ret < 2 || buf[used] != '\0') {
+            if (ret < 2) {
                 fprintf(stderr,
                         "xl: Invalid argument parsing iomem: %s\n", buf);
                 exit(1);
             }
+            mempolicy = &buf[used];
+            if (strlen(mempolicy) > 1) {
+                mempolicy++;
+                if (!strcmp(mempolicy, "arm_dev_nGnRE"))
+                    b_info->iomem[i].memory_policy =
+                        LIBXL_MEMORY_POLICY_ARM_DEV_NGNRE;
+                else if (!strcmp(mempolicy, "arm_mem_WB"))
+                    b_info->iomem[i].memory_policy =
+                        LIBXL_MEMORY_POLICY_ARM_MEM_WB;
+                else if (!strcmp(mempolicy, "default"))
+                    b_info->iomem[i].memory_policy =
+                        LIBXL_MEMORY_POLICY_DEFAULT;
+                else {
+                    fprintf(stderr,
+                            "xl: Invalid iomem memory policy parameter: %s\n",
+                            mempolicy);
+                    exit(1);
+                }
+            }
         }
     }
 
-- 
2.17.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-08-07  0:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07  0:23 [Xen-devel] [PATCH v4 0/6] iomem memory policy Stefano Stabellini
2019-08-07  0:23 ` [Xen-devel] [PATCH v4 1/6] xen/arm: introduce p2m_is_mmio Stefano Stabellini
2019-08-09 10:05   ` Julien Grall
2019-08-07  0:23 ` [Xen-devel] [PATCH v4 2/6] xen: add a p2mt parameter to map_mmio_regions Stefano Stabellini
2019-08-09 10:23   ` Julien Grall
2019-08-09 10:37     ` Jan Beulich
2019-08-09 10:51       ` Julien Grall
2019-08-09 11:07         ` Jan Beulich
2019-08-09 11:10   ` Jan Beulich
2019-08-07  0:23 ` [Xen-devel] [PATCH v4 3/6] xen: extend XEN_DOMCTL_memory_mapping to handle memory policy Stefano Stabellini
2019-08-09 11:25   ` Jan Beulich
2019-08-09 17:25   ` Julien Grall
2019-08-07  0:23 ` [Xen-devel] [PATCH v4 4/6] libxc: introduce xc_domain_mem_map_policy Stefano Stabellini
2019-08-07  0:23 ` Stefano Stabellini [this message]
2019-08-09 17:23   ` [Xen-devel] [PATCH v4 5/6] libxl/xl: add memory policy option to iomem Julien Grall
2019-08-07  0:23 ` [Xen-devel] [PATCH v4 6/6] xen/arm: clarify the support status of iomem configurations Stefano Stabellini
2019-08-07  9:08   ` Julien Grall
2019-08-07  9:16     ` Julien Grall

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=20190807002311.9906-5-sstabellini@kernel.org \
    --to=sstabellini@kernel.org \
    --cc=ian.jackson@eu.citrix.com \
    --cc=julien.grall@arm.com \
    --cc=stefanos@xilinx.com \
    --cc=wei.liu2@citrix.com \
    --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.