From nobody Tue Nov 11 13:18:02 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1560900124; cv=none; d=zoho.com; s=zohoarc; b=cz6NPNbQHh1w6LMM20LiITgA/re6B9FPBtSZA6ZrAmrYKL5cpYtSRWJPs9QUeqh6hVqu6o5i9WQce4bRmIsMocgq2cCkFFZusH57edyG6WHLcI5cHshXSyBKBXeVReo8d6QIyZVv9Rfb3oZnn32H/ixkFDKlpi+tp8lTgJSHqOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560900124; h=Content-Type: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:ARC-Authentication-Results; bh=5/IT2qyynt9WTDaekYEv+S5Blpu7NwabU+P8zLEmfsE=; b=CXsKFcBuTbci3DEG0Df2iveNNuW2xQSdUvW6ylj0uxkX4Sfy/T2HVvOpjTr511jE/9wc+PGZkOBkaNumvsUW9plevp/qLx2UAOwtgIqcg5U6yvMTm22NXkQpib/jUTFnkNlZoawWy1pDO9St4EGJt4TxYRrwhjj6B4wsnouZswY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1560900124209942.6891150808989; Tue, 18 Jun 2019 16:22:04 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOu-0004sh-HA; Tue, 18 Jun 2019 23:20:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hdNOt-0004s1-1r for xen-devel@lists.xenproject.org; Tue, 18 Jun 2019 23:20:27 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a723a48a-921f-11e9-8118-f3a670875dcd; Tue, 18 Jun 2019 23:20:26 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F9C1214AF; Tue, 18 Jun 2019 23:20:25 +0000 (UTC) X-Inumbo-ID: a723a48a-921f-11e9-8118-f3a670875dcd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560900025; bh=HkXCY7hv5J3WXPS9KxQulFJeApct47ijpI8oixCxGVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hxqafs8npeMOI045aBD8L80jhBhH2Hn/JV2Pe4h1hGXsiBQIWk8eqeq5gax5V1LKR KjaMsHkxO+0nK8N48S3eZ11LDTyt2cB43u+BuOujczy3UHJApWw+MdR9Fg5Z1UvYw1 76X7cStgtHRPYyvQV8wTzJLuFjDDCQvKoVYR1ljU= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Tue, 18 Jun 2019 16:20:18 -0700 Message-Id: <20190618232019.26425-4-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 4/5] libxl/xl: add memory policy option to iomem X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , julien.grall@arm.com, sstabellini@kernel.org, ian.jackson@eu.citrix.com, wei.liu2@citrix.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 - x86_UC_minus: uncachable memory, the default on x86 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 CC: ian.jackson@eu.citrix.com CC: wei.liu2@citrix.com --- Andrew suggested to remove MEMORY_POLICY_X86_UC_MINUS and x86_UC_minus completely. If that's the consensus I am happy to respin the series removing code. 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 | 9 +++++++++ tools/libxl/libxl_x86.c | 12 ++++++++++++ tools/xl/xl_parse.c | 22 +++++++++++++++++++++- 8 files changed, 83 insertions(+), 4 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index c99d40307e..fbb9e43e9e 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 ra= nge, e.g. C<2f8-2ff> It is recommended to only use this option for trusted VMs under administrator's control. =20 -=3Ditem B +=3Ditem B =20 Allow auto-translated domains to access specific hardware I/O memory pages. =20 @@ -1233,6 +1233,14 @@ B is not specified, the mapping will be perform= ed using B 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 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 can be for x86 platforms: + - "x86_UC_minus" for Uncachable Memory, the default on x86 =20 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 =20 +/* + * 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 fi= elds: * - unique_id; diff --git a/tools/libxl/libxl_arch.h b/tools/libxl/libxl_arch.h index d624159e53..9c858b06ce 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); =20 +_hidden +int libxl__memory_policy_to_xc(libxl_memory_policy c); + #if defined(__i386__) || defined(__x86_64__) =20 #define LAPIC_BASE_ADDRESS 0xfee00000 diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index 141e159043..6354b852dc 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); } =20 +int libxl__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..84da6406d0 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, libx= l__multidev *multidev, =20 for (i =3D 0; i < d_config->b_info.num_iomem; i++) { libxl_iomem_range *io =3D &d_config->b_info.iomem[i]; + int memory_policy; =20 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, lib= xl__multidev *multidev, ret =3D ERROR_FAIL; goto error_out; } - ret =3D xc_domain_memory_mapping(CTX->xch, domid, + memory_policy =3D libxl__memory_policy_to_xc(io->memory_policy); + if (memory_policy < 0) { + LOGED(ERROR, domid, + "invalid memory policy %u", io->memory_policy); + ret =3D ERROR_FAIL; + goto error_out; + } + ret =3D 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..bd791d338d 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -272,6 +272,13 @@ libxl_ioport_range =3D Struct("ioport_range", [ ("number", uint32), ]) =20 +libxl_memory_policy =3D Enumeration("memory_policy", [ + (0, "default"), + (1, "ARM_Dev_nGnRE"), + (2, "ARM_Mem_WB"), + (3, "x86_UC_MINUS"), + ], init_val =3D "LIBXL_MEMORY_POLICY_DEFAULT") + libxl_iomem_range =3D Struct("iomem_range", [ # start host frame number to be mapped to the guest ("start", uint64), @@ -279,6 +286,8 @@ libxl_iomem_range =3D 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), ]) =20 libxl_vga_interface_info =3D Struct("vga_interface_info", [ diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index c0f88a7eaa..c7c0ad9218 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -631,6 +631,18 @@ void libxl__arch_domain_build_info_setdefault(libxl__g= c *gc, libxl_defbool_setdefault(&b_info->acpi, true); } =20 +int libxl__memory_policy_to_xc(libxl_memory_policy c) +{ + switch (c) { + case LIBXL_MEMORY_POLICY_X86_UC_MINUS: + return MEMORY_POLICY_X86_UC_MINUS; + 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..46525f40f5 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 =3D 0; i < num_iomem; i++) { int used; + const char *mempolicy; =20 buf =3D 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] !=3D '\0') { + if (ret < 2) { fprintf(stderr, "xl: Invalid argument parsing iomem: %s\n", buf); exit(1); } + mempolicy =3D &buf[used]; + if (strlen(mempolicy) > 1) { + mempolicy++; + if (!strcmp(mempolicy, "arm_dev_nGnRE")) + b_info->iomem[i].memory_policy =3D + LIBXL_MEMORY_POLICY_ARM_DEV_NGNRE; + else if (!strcmp(mempolicy, "x86_UC_minus")) + b_info->iomem[i].memory_policy =3D + LIBXL_MEMORY_POLICY_X86_UC_MINUS; + else if (!strcmp(mempolicy, "arm_mem_WB")) + b_info->iomem[i].memory_policy =3D + LIBXL_MEMORY_POLICY_ARM_MEM_WB; + else { + fprintf(stderr, + "xl: Invalid iomem memory policy parameter: %s= \n", + mempolicy); + exit(1); + } + } } } =20 --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel