From: Ian Campbell Date: Tue, 2 Feb 2016 15:34:26 +0000 (+0000) Subject: libxendevicemodel: add support for marking memory R/O or R/W X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c38b4d78219b63f875c81b9d33324c3b35474068;p=people%2Fliuw%2Flibxenctrl-split%2Fxen.git libxendevicemodel: add support for marking memory R/O or R/W XXX underlying hypercall is not stable. Note this with the version of @@UNSTABLE. Also in order to build need to define __XEN_TOOLS__, use a separate source file to avoid accidentally poluting the stable bits of the library. TBD replace hypercall with a stable variant and move to core.c + version as @@1.0 Signed-off-by: Ian Campbell --- diff --git a/tools/libs/devicemodel/core_unstable.c b/tools/libs/devicemodel/core_unstable.c index af9e0bc9a2..4c72f51609 100644 --- a/tools/libs/devicemodel/core_unstable.c +++ b/tools/libs/devicemodel/core_unstable.c @@ -49,6 +49,50 @@ int xendevicemodel_mark_memory_region_dirty(xendevicemodel_handle *dm, return ret; } +static int set_mem_type(xendevicemodel_handle *dm, + xen_pfn_t start_gpfn, size_t nr_pages, + hvmmem_type_t mem_type) +{ + xen_hvm_set_mem_type_t *arg; + int ret = -1; + + arg = xencall_alloc_buffer(dm->call, sizeof(*arg)); + if ( arg == NULL ) + { + LOGE(ERROR, "unable to allocate memory for set mem type hypercall"); + goto err; + } + + arg->domid = dm->domid; + arg->hvmmem_type = mem_type; + arg->first_pfn = start_gpfn; + arg->nr = nr_pages; + + ret = xencall2(dm->call, __HYPERVISOR_hvm_op, + HVMOP_set_mem_type, + (uintptr_t)arg); + + if ( ret ) + LOGE(ERROR, "set mem type hypercall failed"); + + xencall_free_buffer(dm->call, arg); + + err: + return ret; +} + +int xendevicemodel_make_ram_region_rw(xendevicemodel_handle *dm, + xen_pfn_t start_gpfn, size_t nr_pages) +{ + return set_mem_type(dm, start_gpfn, nr_pages, HVMMEM_ram_rw); +} + +int xendevicemodel_make_ram_region_ro(xendevicemodel_handle *dm, + xen_pfn_t start_gpfn, size_t nr_pages) +{ + return set_mem_type(dm, start_gpfn, nr_pages, HVMMEM_ram_ro); +} + /* * Local variables: * mode: C diff --git a/tools/libs/devicemodel/include/xendevicemodel.h b/tools/libs/devicemodel/include/xendevicemodel.h index 0858d68e9f..d410a3aafd 100644 --- a/tools/libs/devicemodel/include/xendevicemodel.h +++ b/tools/libs/devicemodel/include/xendevicemodel.h @@ -156,6 +156,19 @@ int xendevicemodel_inject_msi(xendevicemodel_handle *dm, int xendevicemodel_mark_memory_region_dirty(xendevicemodel_handle *dm, xen_pfn_t start, xen_pfn_t nr); +/* + * Make a region of guest physical address space r/w or r/o from the + * guests point of view. + * + * Note that privileged mappings of such regions made by the device + * model are always writeable even if they are r/o to the guest. + * XXX TRUTH? + */ +int xendevicemodel_make_ram_region_rw(xendevicemodel_handle *dm, + xen_pfn_t start_gpfn, size_t nr_pages); +int xendevicemodel_make_ram_region_ro(xendevicemodel_handle *dm, + xen_pfn_t start_gpfn, size_t nr_pages); + /* * IOREQ Servers * ============= diff --git a/tools/libs/devicemodel/libxendevicemodel.map b/tools/libs/devicemodel/libxendevicemodel.map index ea183c0903..763c89fb1f 100644 --- a/tools/libs/devicemodel/libxendevicemodel.map +++ b/tools/libs/devicemodel/libxendevicemodel.map @@ -11,6 +11,8 @@ UNSTABLE { xendevicemodel_destroy_ioreq_server; xendevicemodel_mark_memory_region_dirty; + xendevicemodel_make_ram_region_ro; + xendevicemodel_make_ram_region_rw; xendevicemodel_inject_msi; };