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

Re: [Xen-devel] [PATCH v3 38/38] arm/p2m: Add test of xc_altp2m_change_gfn



Hi Wei,


On 08/24/2016 02:27 PM, Wei Liu wrote:
> On Wed, Aug 17, 2016 at 12:17:14AM +0200, Sergej Proskurin wrote:
>> This commit extends xen-access by a simple test of the functionality
>> provided by "xc_altp2m_change_gfn". The idea is to dynamically remap a
>> trapping gfn to another mfn, which holds the same content as the
>> original mfn. On success, the guest will continue to run. Subsequent
>> altp2m access violations will trap into Xen and be forced by xen-access
>> to switch to the default view (altp2m[0]) as before. The introduced test
>> can be invoked by providing the argument "altp2m_remap".
>>
>> Signed-off-by: Sergej Proskurin <proskurin@xxxxxxxxxxxxx>
>> ---
>> Cc: Razvan Cojocaru <rcojocaru@xxxxxxxxxxxxxxx>
>> Cc: Tamas K Lengyel <tamas@xxxxxxxxxxxxx>
>> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
>> Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
>> ---
>> v3: Cosmetic fixes in "xenaccess_copy_gfn" and "xenaccess_change_gfn".
>>
>>     Added munmap in "copy_gfn" in the second error case.
>>
>>     Added option "altp2m_remap" selecting the altp2m-remap test.
>> ---
>>  tools/tests/xen-access/xen-access.c | 162 
>> +++++++++++++++++++++++++++++++++++-
>>  1 file changed, 158 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/tests/xen-access/xen-access.c 
>> b/tools/tests/xen-access/xen-access.c
>> index eafd7d6..5909a8a 100644
>> --- a/tools/tests/xen-access/xen-access.c
>> +++ b/tools/tests/xen-access/xen-access.c
>> @@ -38,6 +38,7 @@
>>  #include <sys/mman.h>
>>  #include <sys/poll.h>
>>  
>> +#define XC_WANT_COMPAT_MAP_FOREIGN_API
> I know Razvan already acked this, but general you shouldn't use the
> COMPAT APIs. You should use libs/foreignmemory library, which is a
> stable library.

Alright, I will adapt the implementation accordingly. Thanks for the hint.

>>  #include <xenctrl.h>
>>  #include <xenevtchn.h>
>>  #include <xen/vm_event.h>
>> @@ -49,6 +50,8 @@
>>  #define START_PFN 0ULL
>>  #endif
>>  
>> +#define INVALID_GFN ~(0UL)
>> +
>>  #define DPRINTF(a, b...) fprintf(stderr, a, ## b)
>>  #define ERROR(a, b...) fprintf(stderr, a "\n", ## b)
>>  #define PERROR(a, b...) fprintf(stderr, a ": %s\n", ## b, strerror(errno))
>> @@ -72,9 +75,14 @@ typedef struct xenaccess {
>>      xen_pfn_t max_gpfn;
>>  
>>      vm_event_t vm_event;
>> +
>> +    unsigned int ap2m_idx;
>> +    xen_pfn_t gfn_old;
>> +    xen_pfn_t gfn_new;
>>  } xenaccess_t;
>>  
>>  static int interrupted;
>> +static int gfn_changed = 0;
>>  bool evtchn_bind = 0, evtchn_open = 0, mem_access_enable = 0;
>>  
>>  static void close_handler(int sig)
>> @@ -82,6 +90,100 @@ static void close_handler(int sig)
>>      interrupted = sig;
>>  }
>>  
>> +static int xenaccess_copy_gfn(xc_interface *xch,
>> +                              domid_t domain_id,
>> +                              xen_pfn_t dst_gfn,
>> +                              xen_pfn_t src_gfn)
>> +{
>> +    void *src_vaddr = NULL;
>> +    void *dst_vaddr = NULL;
>> +
>> +    src_vaddr = xc_map_foreign_range(xch, domain_id, XC_PAGE_SIZE,
>> +                                     PROT_READ, src_gfn);
>> +    if ( src_vaddr == MAP_FAILED || src_vaddr == NULL)
>> +        return -1;
>> +
>> +    dst_vaddr = xc_map_foreign_range(xch, domain_id, XC_PAGE_SIZE,
>> +                                     PROT_WRITE, dst_gfn);
> You can have a look at libxc/xc_foreign_memory.c for how to replace this
> legacy call with the new function.

Will do, thanks.

Cheers,
~Sergej

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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