[Xen-devel] [ovmf test] 113481: all pass - PUSHED

2017-09-15 Thread osstest service owner
flight 113481 ovmf real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113481/

Perfect :-)
All tests in this flight passed as required
version targeted for testing:
 ovmf 2f16993c255ca27bd3e8fa42489e8395d5308c3b
baseline version:
 ovmf 11b4463e096523fe03ac840472d483652ae93904

Last test of basis   113462  2017-09-15 03:26:03 Z1 days
Testing same since   113481  2017-09-15 16:16:56 Z0 days1 attempts


People who touched revisions under test:
  Evan Lloyd 
  Sami Mujawar 

jobs:
 build-amd64-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-i386   pass
 build-amd64-libvirt  pass
 build-i386-libvirt   pass
 build-amd64-pvopspass
 build-i386-pvops pass
 test-amd64-amd64-xl-qemuu-ovmf-amd64 pass
 test-amd64-i386-xl-qemuu-ovmf-amd64  pass



sg-report-flight on osstest.test-lab.xenproject.org
logs: /home/logs/logs
images: /home/logs/images

Logs, config files, etc. are available at
http://logs.test-lab.xenproject.org/osstest/logs

Explanation of these reports, and of osstest in general, is at
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README.email;hb=master
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README;hb=master

Test harness code can be found at
http://xenbits.xen.org/gitweb?p=osstest.git;a=summary


Pushing revision :

+ branch=ovmf
+ revision=2f16993c255ca27bd3e8fa42489e8395d5308c3b
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.
 PERLLIB=.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x '!=' x/home/osstest/repos/lock ']'
++ OSSTEST_REPOS_LOCK_LOCKED=/home/osstest/repos/lock
++ exec with-lock-ex -w /home/osstest/repos/lock ./ap-push ovmf 
2f16993c255ca27bd3e8fa42489e8395d5308c3b
+ branch=ovmf
+ revision=2f16993c255ca27bd3e8fa42489e8395d5308c3b
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.:.
 PERLLIB=.:.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x/home/osstest/repos/lock '!=' x/home/osstest/repos/lock ']'
+ . ./cri-common
++ . ./cri-getconfig
+++ export PERLLIB=.:.:.:.
+++ PERLLIB=.:.:.:.
++ umask 002
+ select_xenbranch
+ case "$branch" in
+ tree=ovmf
+ xenbranch=xen-unstable
+ '[' xovmf = xlinux ']'
+ linuxbranch=
+ '[' x = x ']'
+ qemuubranch=qemu-upstream-unstable
+ select_prevxenbranch
++ ./cri-getprevxenbranch xen-unstable
+ prevxenbranch=xen-4.9-testing
+ '[' x2f16993c255ca27bd3e8fa42489e8395d5308c3b = x ']'
+ : tested/2.6.39.x
+ . ./ap-common
++ : osst...@xenbits.xen.org
+++ getconfig OsstestUpstream
+++ perl -e '
use Osstest;
readglobalconfig();
print $c{"OsstestUpstream"} or die $!;
'
++ :
++ : git://xenbits.xen.org/xen.git
++ : osst...@xenbits.xen.org:/home/xen/git/xen.git
++ : git://xenbits.xen.org/qemu-xen-traditional.git
++ : git://git.kernel.org
++ : git://git.kernel.org/pub/scm/linux/kernel/git
++ : git
++ : git://xenbits.xen.org/xtf.git
++ : osst...@xenbits.xen.org:/home/xen/git/xtf.git
++ : git://xenbits.xen.org/xtf.git
++ : git://xenbits.xen.org/libvirt.git
++ : osst...@xenbits.xen.org:/home/xen/git/libvirt.git
++ : git://xenbits.xen.org/libvirt.git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/rumprun.git
++ : git://git.seabios.org/seabios.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/seabios.git
++ : git://xenbits.xen.org/osstest/seabios.git
++ : https://github.com/tianocore/edk2.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/ovmf.git
++ : git://xenbits.xen.org/osstest/ovmf.git
++ : git://xenbits.xen.org/osstest/linux-firmware.git
++ : 

[Xen-devel] [linux-linus test] 113472: regressions - FAIL

2017-09-15 Thread osstest service owner
flight 113472 linux-linus real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113472/

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-i386-xl-qemut-win7-amd64 16 guest-localmigrate/x10 fail REGR. vs. 
113423

Regressions which are regarded as allowable (not blocking):
 test-amd64-amd64-rumprun-amd64 17 rumprun-demo-xenstorels/xenstorels.repeat 
fail REGR. vs. 113423
 test-amd64-amd64-xl-qemuu-win7-amd64 17 guest-stop   fail REGR. vs. 113423
 test-armhf-armhf-xl-rtds 12 guest-start  fail REGR. vs. 113423

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-xl-qemut-win7-amd64 18 guest-start/win.repeat fail blocked in 
113423
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail  like 113423
 test-amd64-i386-xl-qemuu-win7-amd64 17 guest-stop fail like 113423
 test-armhf-armhf-libvirt-xsm 14 saverestore-support-checkfail  like 113423
 test-amd64-amd64-xl-rtds 10 debian-install   fail  like 113423
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail  like 113423
 test-amd64-amd64-xl-qemut-ws16-amd64 10 windows-installfail never pass
 test-amd64-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt-qcow2 12 migrate-support-checkfail  never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-armhf-armhf-xl-arndale  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  14 saverestore-support-checkfail   never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-cubietruck 13 migrate-support-checkfail never pass
 test-armhf-armhf-xl-cubietruck 14 saverestore-support-checkfail never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 13 guest-saverestore   fail never pass
 test-amd64-amd64-xl-qemuu-ws16-amd64 10 windows-installfail never pass
 test-amd64-i386-xl-qemut-ws16-amd64 13 guest-saverestore   fail never pass
 test-armhf-armhf-xl-credit2  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit2  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-multivcpu 13 migrate-support-checkfail  never pass
 test-armhf-armhf-xl-multivcpu 14 saverestore-support-checkfail  never pass
 test-armhf-armhf-xl-vhd  12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  13 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  14 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-win10-i386 10 windows-install fail never pass
 test-amd64-amd64-xl-qemuu-win10-i386 10 windows-installfail never pass
 test-amd64-amd64-xl-qemut-win10-i386 10 windows-installfail never pass
 test-amd64-i386-xl-qemut-win10-i386 10 windows-install fail never pass
 test-armhf-armhf-libvirt-raw 12 migrate-support-checkfail   never pass

version targeted for testing:
 linux711aab1dbb324d321e3d84368a435a78908c7bce
baseline version:
 linux46c1e79fee417f151547aa46fae04ab06cb666f4

Last test of basis   113423  2017-09-13 21:17:10 Z2 days
Failing since113453  2017-09-14 20:24:30 Z1 days2 attempts
Testing same since   113472  2017-09-15 09:50:39 Z0 days1 attempts


People who touched revisions under test:
  Al Viro 
  Andrew Jeffery 
  Andrew Morton 
  Anton Vasilyev 
  Arnd Bergmann 
  Arvind Yadav 
  Bart Van Assche 
  Bartlomiej Zolnierkiewicz 
  Bhumika Goyal 
  Byungchul Park 
  Chris Mason 
  Christoph Hellwig 
  Christopher Bostic 
  Chuck Lever 
  Colin Ian King 
  Dan Carpenter 

[Xen-devel] [linux-next test] 113469: regressions - FAIL

2017-09-15 Thread osstest service owner
flight 113469 linux-next real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113469/

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-i386-libvirt-qcow2 17 guest-start/debian.repeat fail REGR. vs. 
113453
 test-amd64-i386-xl-qemut-win7-amd64 16 guest-localmigrate/x10 fail REGR. vs. 
113453
 test-amd64-amd64-xl-qemuu-win7-amd64 16 guest-localmigrate/x10 fail REGR. vs. 
113453
 test-armhf-armhf-xl-credit2  10 debian-install   fail REGR. vs. 113453
 test-armhf-armhf-libvirt-xsm 10 debian-install   fail REGR. vs. 113453
 test-armhf-armhf-xl-multivcpu 10 debian-install  fail REGR. vs. 113453

Tests which did not succeed, but are not blocking:
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail  like 113453
 test-armhf-armhf-xl-rtds 16 guest-start/debian.repeatfail  like 113453
 test-amd64-i386-xl-qemuu-win7-amd64 16 guest-localmigrate/x10 fail like 113453
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail  like 113453
 test-amd64-amd64-xl-qemut-win7-amd64 16 guest-localmigrate/x10 fail like 113453
 test-amd64-amd64-xl-qemuu-ws16-amd64 10 windows-installfail never pass
 test-amd64-amd64-xl-qemut-ws16-amd64 10 windows-installfail never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-armhf-armhf-xl-arndale  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  14 saverestore-support-checkfail   never pass
 test-amd64-i386-libvirt-qcow2 12 migrate-support-checkfail  never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 13 guest-saverestore   fail never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-armhf-armhf-xl-rtds 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-cubietruck 13 migrate-support-checkfail never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-cubietruck 14 saverestore-support-checkfail never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemut-ws16-amd64 13 guest-saverestore   fail never pass
 test-armhf-armhf-libvirt-raw 12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  13 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-win10-i386 10 windows-install fail never pass
 test-amd64-i386-xl-qemut-win10-i386 10 windows-install fail never pass
 test-amd64-amd64-xl-qemuu-win10-i386 10 windows-installfail never pass
 test-amd64-amd64-xl-qemut-win10-i386 10 windows-installfail never pass

version targeted for testing:
 linux1f183459b5144384e2669a3f757d36bacab108cf
baseline version:
 linux7a95bdb092c66b6473aa2fc848862ae557ab08f7

Last test of basis  (not found) 
Failing since   (not found) 
Testing same since   113469  2017-09-15 09:43:57 Z0 days1 attempts

jobs:
 build-amd64-xsm  pass
 build-armhf-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-armhf  pass
 build-i386   pass
 build-amd64-libvirt  pass
 build-armhf-libvirt  pass
 build-i386-libvirt   pass
 build-amd64-pvopspass
 build-armhf-pvopspass
 build-i386-pvops pass
 build-amd64-rumprun  pass
 build-i386-rumprun   

Re: [Xen-devel] [PATCH v2 15/24] xen/arm: page: Prefix memory types with MT_

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> This will avoid confusion in the code when using them.
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Reviewed-by: Stefano Stabellini 


> ---
> 
> Changes in v2:
> - Add Andre's reviewed-by
> ---
>  xen/arch/arm/kernel.c |  2 +-
>  xen/arch/arm/mm.c | 28 ++--
>  xen/arch/arm/platforms/vexpress.c |  2 +-
>  xen/drivers/video/arm_hdlcd.c |  2 +-
>  xen/include/asm-arm/page.h| 38 +++---
>  5 files changed, 36 insertions(+), 36 deletions(-)
> 
> diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
> index 7403ec0c0e..9c183f96da 100644
> --- a/xen/arch/arm/kernel.c
> +++ b/xen/arch/arm/kernel.c
> @@ -54,7 +54,7 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned 
> long len)
>  s = paddr & (PAGE_SIZE-1);
>  l = min(PAGE_SIZE - s, len);
>  
> -set_fixmap(FIXMAP_MISC, maddr_to_mfn(paddr), BUFFERABLE);
> +set_fixmap(FIXMAP_MISC, maddr_to_mfn(paddr), MT_BUFFERABLE);
>  memcpy(dst, src + s, l);
>  clean_dcache_va_range(dst, l);
>  
> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index 5716ef1123..7ffeb36bfa 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -290,7 +290,7 @@ static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned 
> attr)
>  
>  switch ( attr )
>  {
> -case BUFFERABLE:
> +case MT_BUFFERABLE:
>  /*
>   * ARM ARM: Overlaying the shareability attribute (DDI
>   * 0406C.b B3-1376 to 1377)
> @@ -305,8 +305,8 @@ static inline lpae_t mfn_to_xen_entry(mfn_t mfn, unsigned 
> attr)
>   */
>  e.pt.sh = LPAE_SH_OUTER;
>  break;
> -case UNCACHED:
> -case DEV_SHARED:
> +case MT_UNCACHED:
> +case MT_DEV_SHARED:
>  /*
>   * Shareability is ignored for non-Normal memory, Outer is as
>   * good as anything.
> @@ -369,7 +369,7 @@ static void __init create_mappings(lpae_t *second,
>  
>  count = nr_mfns / LPAE_ENTRIES;
>  p = second + second_linear_offset(virt_offset);
> -pte = mfn_to_xen_entry(_mfn(base_mfn), WRITEALLOC);
> +pte = mfn_to_xen_entry(_mfn(base_mfn), MT_WRITEALLOC);
>  if ( granularity == 16 * LPAE_ENTRIES )
>  pte.pt.contig = 1;  /* These maps are in 16-entry contiguous chunks. 
> */
>  for ( i = 0; i < count; i++ )
> @@ -422,7 +422,7 @@ void *map_domain_page(mfn_t mfn)
>  else if ( map[slot].pt.avail == 0 )
>  {
>  /* Commandeer this 2MB slot */
> -pte = mfn_to_xen_entry(_mfn(slot_mfn), WRITEALLOC);
> +pte = mfn_to_xen_entry(_mfn(slot_mfn), MT_WRITEALLOC);
>  pte.pt.avail = 1;
>  write_pte(map + slot, pte);
>  break;
> @@ -543,7 +543,7 @@ static inline lpae_t pte_of_xenaddr(vaddr_t va)
>  {
>  paddr_t ma = va + phys_offset;
>  
> -return mfn_to_xen_entry(maddr_to_mfn(ma), WRITEALLOC);
> +return mfn_to_xen_entry(maddr_to_mfn(ma), MT_WRITEALLOC);
>  }
>  
>  /* Map the FDT in the early boot page table */
> @@ -652,7 +652,7 @@ void __init setup_pagetables(unsigned long 
> boot_phys_offset, paddr_t xen_paddr)
>  /* Initialise xen second level entries ... */
>  /* ... Xen's text etc */
>  
> -pte = mfn_to_xen_entry(maddr_to_mfn(xen_paddr), WRITEALLOC);
> +pte = mfn_to_xen_entry(maddr_to_mfn(xen_paddr), MT_WRITEALLOC);
>  pte.pt.xn = 0;/* Contains our text mapping! */
>  xen_second[second_table_offset(XEN_VIRT_START)] = pte;
>  
> @@ -669,7 +669,7 @@ void __init setup_pagetables(unsigned long 
> boot_phys_offset, paddr_t xen_paddr)
>  
>  /* ... Boot Misc area for xen relocation */
>  dest_va = BOOT_RELOC_VIRT_START;
> -pte = mfn_to_xen_entry(maddr_to_mfn(xen_paddr), WRITEALLOC);
> +pte = mfn_to_xen_entry(maddr_to_mfn(xen_paddr), MT_WRITEALLOC);
>  /* Map the destination in xen_second. */
>  xen_second[second_table_offset(dest_va)] = pte;
>  /* Map the destination in boot_second. */
> @@ -700,7 +700,7 @@ void __init setup_pagetables(unsigned long 
> boot_phys_offset, paddr_t xen_paddr)
>  unsigned long va = XEN_VIRT_START + (i << PAGE_SHIFT);
>  if ( !is_kernel(va) )
>  break;
> -pte = mfn_to_xen_entry(mfn, WRITEALLOC);
> +pte = mfn_to_xen_entry(mfn, MT_WRITEALLOC);
>  pte.pt.table = 1; /* 4k mappings always have this bit set */
>  if ( is_kernel_text(va) || is_kernel_inittext(va) )
>  {
> @@ -771,7 +771,7 @@ int init_secondary_pagetables(int cpu)
>  for ( i = 0; i < DOMHEAP_SECOND_PAGES; i++ )
>  {
>  pte = mfn_to_xen_entry(virt_to_mfn(domheap+i*LPAE_ENTRIES),
> -   WRITEALLOC);
> +   MT_WRITEALLOC);
>  pte.pt.table = 1;
>  
> 

Re: [Xen-devel] [PATCH v2 12/24] xen/arm: Replace ioremap_attr(PAGE_HYPERVISOR_NOCACHE) call by ioremap_nocache

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> ioremap_cache is a wrapper of ioremap_attr(...).
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Reviewed-by: Stefano Stabellini 


> ---
> 
> Changes in v2:
> - Add Andre's reviewed-by
> ---
>  xen/arch/arm/platforms/exynos5.c | 2 +-
>  xen/arch/arm/platforms/omap5.c   | 6 ++
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/xen/arch/arm/platforms/exynos5.c 
> b/xen/arch/arm/platforms/exynos5.c
> index 2ae5fa66e0..95d6581d33 100644
> --- a/xen/arch/arm/platforms/exynos5.c
> +++ b/xen/arch/arm/platforms/exynos5.c
> @@ -62,7 +62,7 @@ static int exynos5_init_time(void)
>  dprintk(XENLOG_INFO, "mct_base_addr: %016llx size: %016llx\n",
>  mct_base_addr, size);
>  
> -mct = ioremap_attr(mct_base_addr, size, PAGE_HYPERVISOR_NOCACHE);
> +mct = ioremap_nocache(mct_base_addr, size);
>  if ( !mct )
>  {
>  dprintk(XENLOG_ERR, "Unable to map MCT\n");
> diff --git a/xen/arch/arm/platforms/omap5.c b/xen/arch/arm/platforms/omap5.c
> index 1e1f9fa970..7dbba95756 100644
> --- a/xen/arch/arm/platforms/omap5.c
> +++ b/xen/arch/arm/platforms/omap5.c
> @@ -51,8 +51,7 @@ static int omap5_init_time(void)
>  unsigned int sys_clksel;
>  unsigned int num, den, frac1, frac2;
>  
> -ckgen_prm_base = ioremap_attr(OMAP5_CKGEN_PRM_BASE,
> -  0x20, PAGE_HYPERVISOR_NOCACHE);
> +ckgen_prm_base = ioremap_nocache(OMAP5_CKGEN_PRM_BASE, 0x20);
>  if ( !ckgen_prm_base )
>  {
>  dprintk(XENLOG_ERR, "%s: PRM_BASE ioremap failed\n", __func__);
> @@ -64,8 +63,7 @@ static int omap5_init_time(void)
>  
>  iounmap(ckgen_prm_base);
>  
> -rt_ct_base = ioremap_attr(REALTIME_COUNTER_BASE,
> -  0x20, PAGE_HYPERVISOR_NOCACHE);
> +rt_ct_base = ioremap_nocache(REALTIME_COUNTER_BASE, 0x20);
>  if ( !rt_ct_base )
>  {
>  dprintk(XENLOG_ERR, "%s: REALTIME_COUNTER_BASE ioremap failed\n", 
> __func__);
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 11/24] xen/arm: traps: Improve logging for data/prefetch abort fault

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> Walk the hypervisor page table for data/prefetch abort fault to help
> diagnostics error in the page tables.
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Acked-by: Stefano Stabellini 

> ---
> Andre, I assumed you were happy with changes you suggested, so I
> kept your reviewed-by.
> 
> Changes in v2:
> - Add Andre's reviewed-by
> - Simplify condition check
> - Update warning message
> ---
>  xen/arch/arm/traps.c | 19 +++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
> index 2e48089d61..0b856fb4fd 100644
> --- a/xen/arch/arm/traps.c
> +++ b/xen/arch/arm/traps.c
> @@ -2986,7 +2986,26 @@ void do_trap_hyp_sync(struct cpu_user_regs *regs)
>  do_trap_brk(regs, hsr);
>  break;
>  #endif
> +case HSR_EC_DATA_ABORT_CURR_EL:
> +case HSR_EC_INSTR_ABORT_CURR_EL:
> +{
> +bool is_data = (hsr.ec == HSR_EC_DATA_ABORT_CURR_EL);
> +const char *fault = (is_data) ? "Data Abort" : "Instruction Abort";
> +
> +printk("%s Trap. Syndrome=%#x\n", fault, hsr.iss);
> +/*
> + * FAR may not be valid for a Synchronous External abort other
> + * than translation table walk.
> + */
> +if ( hsr.xabt.fsc == FSC_SEA && hsr.xabt.fnv )
> +printk("Invalid FAR, not walking the hypervisor tables\n");
> +else
> +dump_hyp_walk(get_hfar(is_data));
> +
> +do_unexpected_trap(fault, regs);
>  
> +break;
> +}
>  default:
>  printk("Hypervisor Trap. HSR=0x%x EC=0x%x IL=%x 
> Syndrome=0x%"PRIx32"\n",
> hsr.bits, hsr.ec, hsr.len, hsr.iss);
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 10/24] xen/arm: traps: Introduce a helper to read the hypersivor fault register

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> While ARM32 has 2 distinct registers for the hypervisor fault register
> (one for prefetch abort, the other for data abort), AArch64 has only
> one.
> 
> Currently, the logic is open-code but a follow-up patch will require to
> read it too. So move the logic in a separate helper and use it instead
> of open-coding it.
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Reviewed-by: Stefano Stabellini 


> ---
> Changes in v2:
> - Add Andre's reviewed-by
> ---
>  xen/arch/arm/traps.c | 35 +--
>  1 file changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
> index 967bfea4ed..2e48089d61 100644
> --- a/xen/arch/arm/traps.c
> +++ b/xen/arch/arm/traps.c
> @@ -2549,6 +2549,28 @@ done:
>  if (first) unmap_domain_page(first);
>  }
>  
> +/*
> + * Return the value of the hypervisor fault address register.
> + *
> + * On ARM32, the register will be different depending whether the
> + * fault is a prefetch abort or data abort.
> + */
> +static inline vaddr_t get_hfar(bool is_data)
> +{
> +vaddr_t gva;
> +
> +#ifdef CONFIG_ARM_32
> +if ( is_data )
> +gva = READ_CP32(HDFAR);
> +else
> +gva = READ_CP32(HIFAR);
> +#else
> +gva =  READ_SYSREG(FAR_EL2);
> +#endif
> +
> +return gva;
> +}
> +
>  static inline paddr_t get_faulting_ipa(vaddr_t gva)
>  {
>  register_t hpfar = READ_SYSREG(HPFAR_EL2);
> @@ -2584,11 +2606,7 @@ static void do_trap_instr_abort_guest(struct 
> cpu_user_regs *regs,
>  paddr_t gpa;
>  mfn_t mfn;
>  
> -#ifdef CONFIG_ARM_32
> -gva = READ_CP32(HIFAR);
> -#else
> -gva = READ_SYSREG64(FAR_EL2);
> -#endif
> +gva = get_hfar(false /* is_data */);
>  
>  /*
>   * If this bit has been set, it means that this instruction abort is 
> caused
> @@ -2730,11 +2748,8 @@ static void do_trap_data_abort_guest(struct 
> cpu_user_regs *regs,
>  return __do_trap_serror(regs, true);
>  
>  info.dabt = dabt;
> -#ifdef CONFIG_ARM_32
> -info.gva = READ_CP32(HDFAR);
> -#else
> -info.gva = READ_SYSREG64(FAR_EL2);
> -#endif
> +
> +info.gva = get_hfar(true /* is_data */);
>  
>  if ( hpfar_is_valid(dabt.s1ptw, fsc) )
>  info.gpa = get_faulting_ipa(info.gva);
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 09/24] xen/arm: Introduce hsr_xabt to gather common bits between hsr_dabt and

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> This will allow to consolidate some part of the data abort and prefetch
> abort handling in a single function later on.
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 
> 
> ---
> Changes in v2:
> - Add Andre's reviewed-by
> ---
>  xen/include/asm-arm/processor.h | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
> index b6432b6bf4..51e1c92665 100644
> --- a/xen/include/asm-arm/processor.h
> +++ b/xen/include/asm-arm/processor.h
> @@ -615,6 +615,19 @@ union hsr {
>  unsigned long ec:6;/* Exception Class */
>  } dabt; /* HSR_EC_DATA_ABORT_* */
>  
> +/* Contain the common bits between DABT and IABT */
> +struct hsr_xabt {
> +unsigned long fsc:6;/* Fault status code */
> +unsigned long pad1:1;

Could you please add a comment like: /* Not common */ on the side of
pad1


> +unsigned long s1ptw:1;  /* Stage 2 fault during stage 1 translation 
> */
> +unsigned long pad2:1;

same here


> +unsigned long eat:1;/* External abort type */
> +unsigned long fnv:1;/* FAR not Valid */
> +unsigned long pad3:14;

same here


> +unsigned long len:1;/* Instruction length */
> +unsigned long ec:6; /* Exception Class */
> +} xabt;
> +
>  #ifdef CONFIG_ARM_64
>  struct hsr_brk {
>  unsigned long comment:16;   /* Comment */
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 08/24] xen/arm: Add FnV field in hsr_*abt

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> FnV (FAR not Valid) bit was introduced by ARMv8 in both AArch32 and
> AArch64 (See D7-2275, D7-2277, G6-4958, G6-4962 in ARM DDI 0487B.a).
> 
> Note the new revision of ARMv8 defined more bits in HSR. They haven't
> been added at the moment because we have no use of them in Xen.
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Acked-by: Stefano Stabellini 


> ---
> 
> Changes in v2:
> - Expand the commit message to explain why the other bits have
> not been added.
> - Add Andre's reviewed-by
> ---
>  xen/include/asm-arm/processor.h | 8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
> index bea4a56190..b6432b6bf4 100644
> --- a/xen/include/asm-arm/processor.h
> +++ b/xen/include/asm-arm/processor.h
> @@ -587,7 +587,8 @@ union hsr {
>  unsigned long s1ptw:1; /* Stage 2 fault during stage 1 translation */
>  unsigned long res1:1;  /* RES0 */
>  unsigned long eat:1;   /* External abort type */
> -unsigned long res2:15;
> +unsigned long fnv:1;   /* FAR not Valid */
> +unsigned long res2:14;
>  unsigned long len:1;   /* Instruction length */
>  unsigned long ec:6;/* Exception Class */
>  } iabt; /* HSR_EC_INSTR_ABORT_* */
> @@ -598,10 +599,11 @@ union hsr {
>  unsigned long s1ptw:1; /* Stage 2 fault during stage 1 translation */
>  unsigned long cache:1; /* Cache Maintenance */
>  unsigned long eat:1;   /* External Abort Type */
> +unsigned long fnv:1;   /* FAR not Valid */
>  #ifdef CONFIG_ARM_32
> -unsigned long sbzp0:6;
> +unsigned long sbzp0:5;
>  #else
> -unsigned long sbzp0:4;
> +unsigned long sbzp0:3;
>  unsigned long ar:1;/* Acquire Release */
>  unsigned long sf:1;/* Sixty Four bit register */
>  #endif
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 04/24] xen/arm: mm: Redefine mfn_to_virt to use typesafe

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> This add a bit more safety in the memory subsystem code.
> 
> Signed-off-by: Julien Grall 
> ---
>  xen/arch/arm/mm.c | 16 +---
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index 965d0573a4..5716ef1123 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -47,6 +47,8 @@ struct domain *dom_xen, *dom_io, *dom_cow;
>  /* Override macros from asm/page.h to make them work with mfn_t */
>  #undef virt_to_mfn
>  #define virt_to_mfn(va) _mfn(__virt_to_mfn(va))
> +#undef mfn_to_virt
> +#define mfn_to_virt(mfn) __mfn_to_virt(mfn_x(mfn))
>  
>  /* Static start-of-day pagetables that we use before the allocators
>   * are up. These are used by all CPUs during bringup before switching
> @@ -837,7 +839,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn,
>   * Virtual address aligned to previous 1GB to match physical
>   * address alignment done above.
>   */
> -vaddr = (vaddr_t)mfn_to_virt(base_mfn) & FIRST_MASK;
> +vaddr = (vaddr_t)__mfn_to_virt(base_mfn) & FIRST_MASK;

Don't you think it would be better to do mfn_to_virt(_mfn(base_mfn)) in
this patch? This is just bike-shedding, but I think it would be more
obviously consistent. Other than that, it looks good.


>  while ( mfn < end_mfn )
>  {
> @@ -849,7 +851,7 @@ void __init setup_xenheap_mappings(unsigned long base_mfn,
>  /* mfn_to_virt is not valid on the 1st 1st mfn, since it
>   * is not within the xenheap. */
>  first = slot == xenheap_first_first_slot ?
> -xenheap_first_first : mfn_to_virt(p->pt.base);
> +xenheap_first_first : __mfn_to_virt(p->pt.base);
>  }
>  else if ( xenheap_first_first_slot == -1)
>  {
> @@ -866,11 +868,11 @@ void __init setup_xenheap_mappings(unsigned long 
> base_mfn,
>  {
>  mfn_t first_mfn = alloc_boot_pages(1, 1);
>  
> -clear_page(mfn_to_virt(mfn_x(first_mfn)));
> +clear_page(mfn_to_virt(first_mfn));
>  pte = mfn_to_xen_entry(first_mfn, WRITEALLOC);
>  pte.pt.table = 1;
>  write_pte(p, pte);
> -first = mfn_to_virt(mfn_x(first_mfn));
> +first = mfn_to_virt(first_mfn);
>  }
>  
>  pte = mfn_to_xen_entry(_mfn(mfn), WRITEALLOC);
> @@ -909,10 +911,10 @@ void __init setup_frametable_mappings(paddr_t ps, 
> paddr_t pe)
>  /* Compute the number of second level pages. */
>  nr_second = ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT;
>  second_base = alloc_boot_pages(nr_second, 1);
> -second = mfn_to_virt(mfn_x(second_base));
> +second = mfn_to_virt(second_base);
>  for ( i = 0; i < nr_second; i++ )
>  {
> -clear_page(mfn_to_virt(mfn_x(mfn_add(second_base, i;
> +clear_page(mfn_to_virt(mfn_add(second_base, i)));
>  pte = mfn_to_xen_entry(mfn_add(second_base, i), WRITEALLOC);
>  pte.pt.table = 1;
>  write_pte(_first[first_table_offset(FRAMETABLE_VIRT_START)+i], 
> pte);
> @@ -1005,7 +1007,7 @@ static int create_xen_entries(enum xenmap_operation op,
>  
>  BUG_ON(!lpae_valid(*entry));
>  
> -third = mfn_to_virt(entry->pt.base);
> +third = __mfn_to_virt(entry->pt.base);
>  entry = [third_table_offset(addr)];
>  
>  switch ( op ) {
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 07/24] xen/arm: arm32: Don't define FAR_EL1

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> Aliasing FAR_EL1 to IFAR is wrong because on ARMv8 FAR_EL1[31:0] is
> architecturally mapped to DFAR and FAR_EL1[63:32] to IFAR.
> 
> As FAR_EL1 is not currently used in ARM32 code, remove it.
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Acked-by: Stefano Stabellini 


> ---
> Changes in v2:
> - Fix register name in the commit message
> - Add Andre's reviewed-by
> ---
>  xen/include/asm-arm/cpregs.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/xen/include/asm-arm/cpregs.h b/xen/include/asm-arm/cpregs.h
> index 1889d7cbfb..9e138489f0 100644
> --- a/xen/include/asm-arm/cpregs.h
> +++ b/xen/include/asm-arm/cpregs.h
> @@ -306,7 +306,6 @@
>  #define DACR32_EL2  DACR
>  #define ESR_EL1 DFSR
>  #define ESR_EL2 HSR
> -#define FAR_EL1 HIFAR
>  #define HCR_EL2 HCR
>  #define HPFAR_EL2   HPFAR
>  #define HSTR_EL2HSTR
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 06/24] xen/arm: traps: Don't define FAR_EL2 for ARM32

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> Aliasing FAR_EL2 to HIFAR makes the code confusing because on ARMv8
> FAR_EL2[31:0] is architecturally mapped to HDFAR and FAR_EL2[63:32] to
> HIFAR. See D7.2.30 in ARM DDI 0487B.a. Open-code the alias instead.
> 
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Acked-by: Stefano Stabellini 


> ---
> Changes in v2:
> - Fix register name in the commit message
> - Add Andre's reviewed-by
> ---
>  xen/arch/arm/traps.c | 8 +++-
>  xen/include/asm-arm/cpregs.h | 1 -
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
> index 7f6ec15b5e..967bfea4ed 100644
> --- a/xen/arch/arm/traps.c
> +++ b/xen/arch/arm/traps.c
> @@ -2579,11 +2579,17 @@ static void do_trap_instr_abort_guest(struct 
> cpu_user_regs *regs,
>const union hsr hsr)
>  {
>  int rc;
> -register_t gva = READ_SYSREG(FAR_EL2);
> +register_t gva;
>  uint8_t fsc = hsr.iabt.ifsc & ~FSC_LL_MASK;
>  paddr_t gpa;
>  mfn_t mfn;
>  
> +#ifdef CONFIG_ARM_32
> +gva = READ_CP32(HIFAR);
> +#else
> +gva = READ_SYSREG64(FAR_EL2);
> +#endif
> +
>  /*
>   * If this bit has been set, it means that this instruction abort is 
> caused
>   * by a guest external abort. We can handle this instruction abort as 
> guest
> diff --git a/xen/include/asm-arm/cpregs.h b/xen/include/asm-arm/cpregs.h
> index af45ec7a65..1889d7cbfb 100644
> --- a/xen/include/asm-arm/cpregs.h
> +++ b/xen/include/asm-arm/cpregs.h
> @@ -307,7 +307,6 @@
>  #define ESR_EL1 DFSR
>  #define ESR_EL2 HSR
>  #define FAR_EL1 HIFAR
> -#define FAR_EL2 HIFAR
>  #define HCR_EL2 HCR
>  #define HPFAR_EL2   HPFAR
>  #define HSTR_EL2HSTR
> -- 
> 2.11.0
> 

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


[Xen-devel] [xen-unstable-smoke test] 113493: tolerable all pass - PUSHED

2017-09-15 Thread osstest service owner
flight 113493 xen-unstable-smoke real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113493/

Failures :-/ but no regressions.

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass

version targeted for testing:
 xen  abd91b2a2bcd05618a71f7e5fe571dd10a5727bc
baseline version:
 xen  64a00683edcd2ad5b2abcd57783393836dda3110

Last test of basis   113480  2017-09-15 16:01:27 Z0 days
Testing same since   113493  2017-09-15 22:01:37 Z0 days1 attempts


People who touched revisions under test:
  Oleksandr Tyshchenko 
  Stefano Stabellini 

jobs:
 build-amd64  pass
 build-armhf  pass
 build-amd64-libvirt  pass
 test-armhf-armhf-xl  pass
 test-amd64-amd64-xl-qemuu-debianhvm-i386 pass
 test-amd64-amd64-libvirt pass



sg-report-flight on osstest.test-lab.xenproject.org
logs: /home/logs/logs
images: /home/logs/images

Logs, config files, etc. are available at
http://logs.test-lab.xenproject.org/osstest/logs

Explanation of these reports, and of osstest in general, is at
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README.email;hb=master
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README;hb=master

Test harness code can be found at
http://xenbits.xen.org/gitweb?p=osstest.git;a=summary


Pushing revision :

+ branch=xen-unstable-smoke
+ revision=abd91b2a2bcd05618a71f7e5fe571dd10a5727bc
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.
 PERLLIB=.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x '!=' x/home/osstest/repos/lock ']'
++ OSSTEST_REPOS_LOCK_LOCKED=/home/osstest/repos/lock
++ exec with-lock-ex -w /home/osstest/repos/lock ./ap-push xen-unstable-smoke 
abd91b2a2bcd05618a71f7e5fe571dd10a5727bc
+ branch=xen-unstable-smoke
+ revision=abd91b2a2bcd05618a71f7e5fe571dd10a5727bc
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.:.
 PERLLIB=.:.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x/home/osstest/repos/lock '!=' x/home/osstest/repos/lock ']'
+ . ./cri-common
++ . ./cri-getconfig
+++ export PERLLIB=.:.:.:.
+++ PERLLIB=.:.:.:.
++ umask 002
+ select_xenbranch
+ case "$branch" in
+ tree=xen
+ xenbranch=xen-unstable-smoke
+ qemuubranch=qemu-upstream-unstable
+ '[' xxen = xlinux ']'
+ linuxbranch=
+ '[' xqemu-upstream-unstable = x ']'
+ select_prevxenbranch
++ ./cri-getprevxenbranch xen-unstable-smoke
+ prevxenbranch=xen-4.9-testing
+ '[' xabd91b2a2bcd05618a71f7e5fe571dd10a5727bc = x ']'
+ : tested/2.6.39.x
+ . ./ap-common
++ : osst...@xenbits.xen.org
+++ getconfig OsstestUpstream
+++ perl -e '
use Osstest;
readglobalconfig();
print $c{"OsstestUpstream"} or die $!;
'
++ :
++ : git://xenbits.xen.org/xen.git
++ : osst...@xenbits.xen.org:/home/xen/git/xen.git
++ : git://xenbits.xen.org/qemu-xen-traditional.git
++ : git://git.kernel.org
++ : git://git.kernel.org/pub/scm/linux/kernel/git
++ : git
++ : git://xenbits.xen.org/xtf.git
++ : osst...@xenbits.xen.org:/home/xen/git/xtf.git
++ : git://xenbits.xen.org/xtf.git
++ : git://xenbits.xen.org/libvirt.git
++ : osst...@xenbits.xen.org:/home/xen/git/libvirt.git
++ : git://xenbits.xen.org/libvirt.git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/rumprun.git
++ : git://git.seabios.org/seabios.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/seabios.git
++ : git://xenbits.xen.org/osstest/seabios.git
++ : https://github.com/tianocore/edk2.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/ovmf.git
++ : 

Re: [Xen-devel] [PATCH v2 05/24] xen/arm: hsr_iabt: Document RES0 field

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> Signed-off-by: Julien Grall 
> Reviewed-by: Andre Przywara 

Acked-by: Stefano Stabellini 


> ---
> 
> Note that the missing FnV bits present ARMv8 will be added in a
> follow-up patch.
> 
> Changes in v2:
> - Add Andre's reviewed-by
> ---
>  xen/include/asm-arm/processor.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h
> index 9f7a42f86b..bea4a56190 100644
> --- a/xen/include/asm-arm/processor.h
> +++ b/xen/include/asm-arm/processor.h
> @@ -583,9 +583,9 @@ union hsr {
>  
>  struct hsr_iabt {
>  unsigned long ifsc:6;  /* Instruction fault status code */
> -unsigned long res0:1;
> +unsigned long res0:1;  /* RES0 */
>  unsigned long s1ptw:1; /* Stage 2 fault during stage 1 translation */
> -unsigned long res1:1;
> +unsigned long res1:1;  /* RES0 */
>  unsigned long eat:1;   /* External abort type */
>  unsigned long res2:15;
>  unsigned long len:1;   /* Instruction length */

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


Re: [Xen-devel] [PATCH v2 03/24] xen/mm: Use __virt_to_mfn in map_domain_page instead of virt_to_mfn

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> virt_to_mfn may by overridden by the source files, for improving locally
> typesafe.
> 
> Therefore map_domain_page has to use __virt_to_mfn to prevent any
> compilation issue in sources files that override the helper.
> 
> Signed-off-by: Julien Grall 
> Acked-by: Jan Beulich 

Acked-by: Stefano Stabellini 


> ---
> 
> Changes in v2:
> - Add Jan's acked-by
> 
> Cc: Stefano Stabellini 
> Cc: Andrew Cooper 
> Cc: George Dunlap 
> Cc: Ian Jackson 
> Cc: Jan Beulich 
> Cc: Konrad Rzeszutek Wilk 
> Cc: Tim Deegan 
> Cc: Wei Liu 
> ---
>  xen/include/asm-arm/mm.h  | 3 ++-
>  xen/include/xen/domain_page.h | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
> index 7de2f32f58..cd6dfb54b9 100644
> --- a/xen/include/asm-arm/mm.h
> +++ b/xen/include/asm-arm/mm.h
> @@ -281,7 +281,7 @@ static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, 
> unsigned int flags)
>  
>  /* Convert between Xen-heap virtual addresses and machine frame numbers. */
>  #define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT)
> -#define mfn_to_virt(mfn)  (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
> +#define __mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
>  
>  /*
>   * We define non-underscored wrappers for above conversion functions.
> @@ -291,6 +291,7 @@ static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, 
> unsigned int flags)
>  #define mfn_to_page(mfn)__mfn_to_page(mfn)
>  #define page_to_mfn(pg) __page_to_mfn(pg)
>  #define virt_to_mfn(va) __virt_to_mfn(va)
> +#define mfn_to_virt(mfn)__mfn_to_virt(mfn)
>  
>  /* Convert between Xen-heap virtual addresses and page-info structures. */
>  static inline struct page_info *virt_to_page(const void *v)
> diff --git a/xen/include/xen/domain_page.h b/xen/include/xen/domain_page.h
> index 93f2a5aaf7..890bae5b9c 100644
> --- a/xen/include/xen/domain_page.h
> +++ b/xen/include/xen/domain_page.h
> @@ -53,7 +53,7 @@ static inline void *__map_domain_page_global(const struct 
> page_info *pg)
>  
>  #else /* !CONFIG_DOMAIN_PAGE */
>  
> -#define map_domain_page(mfn)mfn_to_virt(mfn_x(mfn))
> +#define map_domain_page(mfn)__mfn_to_virt(mfn_x(mfn))
>  #define __map_domain_page(pg)   page_to_virt(pg)
>  #define unmap_domain_page(va)   ((void)(va))
>  #define domain_page_map_to_mfn(va)  virt_to_mfn((unsigned long)(va))
> -- 
> 2.11.0
> 

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


Re: [Xen-devel] [PATCH v2 02/24] xen/mm: Use typesafe MFN for alloc_boot_pages return

2017-09-15 Thread Stefano Stabellini
On Tue, 12 Sep 2017, Julien Grall wrote:
> At the moment, most of the callers will have to use mfn_x. However
> follow-up patches will remove some of them by propagating the typesafe a
> bit further.
> 
> Signed-off-by: Julien Grall 

Reviewed-by: Stefano Stabellini 


> ---
> 
> Changes in v2:
> - Push down a bit some mfn_t to convert some unsigned long local
> variables to mfn_t.
> 
> Cc: Stefano Stabellini 
> Cc: Andrew Cooper 
> Cc: George Dunlap 
> Cc: Ian Jackson 
> Cc: Jan Beulich 
> Cc: Konrad Rzeszutek Wilk 
> Cc: Tim Deegan 
> Cc: Wei Liu 
> ---
>  xen/arch/arm/mm.c   | 26 ++
>  xen/arch/arm/setup.c|  4 ++--
>  xen/arch/x86/mm.c   |  7 ---
>  xen/arch/x86/numa.c |  2 +-
>  xen/arch/x86/srat.c |  5 +++--
>  xen/common/page_alloc.c |  7 +++
>  xen/drivers/acpi/osl.c  |  2 +-
>  xen/include/xen/mm.h|  3 +--
>  8 files changed, 29 insertions(+), 27 deletions(-)
> 
> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index b39677eac9..965d0573a4 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -864,13 +864,13 @@ void __init setup_xenheap_mappings(unsigned long 
> base_mfn,
>  }
>  else
>  {
> -unsigned long first_mfn = alloc_boot_pages(1, 1);
> +mfn_t first_mfn = alloc_boot_pages(1, 1);
>  
> -clear_page(mfn_to_virt(first_mfn));
> -pte = mfn_to_xen_entry(_mfn(first_mfn), WRITEALLOC);
> +clear_page(mfn_to_virt(mfn_x(first_mfn)));
> +pte = mfn_to_xen_entry(first_mfn, WRITEALLOC);
>  pte.pt.table = 1;
>  write_pte(p, pte);
> -first = mfn_to_virt(first_mfn);
> +first = mfn_to_virt(mfn_x(first_mfn));
>  }
>  
>  pte = mfn_to_xen_entry(_mfn(mfn), WRITEALLOC);
> @@ -891,11 +891,12 @@ void __init setup_frametable_mappings(paddr_t ps, 
> paddr_t pe)
>  unsigned long nr_pages = (pe - ps) >> PAGE_SHIFT;
>  unsigned long nr_pdxs = pfn_to_pdx(nr_pages);
>  unsigned long frametable_size = nr_pdxs * sizeof(struct page_info);
> -unsigned long base_mfn;
> +mfn_t base_mfn;
>  const unsigned long mapping_size = frametable_size < MB(32) ? MB(2) : 
> MB(32);
>  #ifdef CONFIG_ARM_64
>  lpae_t *second, pte;
> -unsigned long nr_second, second_base;
> +unsigned long nr_second;
> +mfn_t second_base;
>  int i;
>  #endif
>  
> @@ -908,18 +909,19 @@ void __init setup_frametable_mappings(paddr_t ps, 
> paddr_t pe)
>  /* Compute the number of second level pages. */
>  nr_second = ROUNDUP(frametable_size, FIRST_SIZE) >> FIRST_SHIFT;
>  second_base = alloc_boot_pages(nr_second, 1);
> -second = mfn_to_virt(second_base);
> +second = mfn_to_virt(mfn_x(second_base));
>  for ( i = 0; i < nr_second; i++ )
>  {
> -clear_page(mfn_to_virt(second_base + i));
> -pte = mfn_to_xen_entry(_mfn(second_base + i), WRITEALLOC);
> +clear_page(mfn_to_virt(mfn_x(mfn_add(second_base, i;
> +pte = mfn_to_xen_entry(mfn_add(second_base, i), WRITEALLOC);
>  pte.pt.table = 1;
>  write_pte(_first[first_table_offset(FRAMETABLE_VIRT_START)+i], 
> pte);
>  }
> -create_mappings(second, 0, base_mfn, frametable_size >> PAGE_SHIFT, 
> mapping_size);
> +create_mappings(second, 0, mfn_x(base_mfn), frametable_size >> 
> PAGE_SHIFT,
> +mapping_size);
>  #else
> -create_mappings(xen_second, FRAMETABLE_VIRT_START,
> -base_mfn, frametable_size >> PAGE_SHIFT, mapping_size);
> +create_mappings(xen_second, FRAMETABLE_VIRT_START, mfn_x(base_mfn),
> +frametable_size >> PAGE_SHIFT, mapping_size);
>  #endif
>  
>  memset(_table[0], 0, nr_pdxs * sizeof(struct page_info));
> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> index 92f173be0c..b00eebd96e 100644
> --- a/xen/arch/arm/setup.c
> +++ b/xen/arch/arm/setup.c
> @@ -561,7 +561,7 @@ static void __init setup_mm(unsigned long dtb_paddr, 
> size_t dtb_size)
>  init_boot_pages(pfn_to_paddr(boot_mfn_start), 
> pfn_to_paddr(boot_mfn_end));
>  
>  /* Copy the DTB. */
> -fdt = mfn_to_virt(alloc_boot_pages(dtb_pages, 1));
> +fdt = mfn_to_virt(mfn_x(alloc_boot_pages(dtb_pages, 1)));
>  copy_from_paddr(fdt, dtb_paddr, dtb_size);
>  device_tree_flattened = fdt;
>  
> @@ -671,7 +671,7 @@ static void __init setup_mm(unsigned long dtb_paddr, 
> size_t dtb_size)
>  dtb_pages = (dtb_size + PAGE_SIZE-1) >> PAGE_SHIFT;
>  
>  /* Copy the DTB. */
> -fdt = mfn_to_virt(alloc_boot_pages(dtb_pages, 1));
> +fdt = mfn_to_virt(mfn_x(alloc_boot_pages(dtb_pages, 1)));
>  copy_from_paddr(fdt, dtb_paddr, dtb_size);
>  

[Xen-devel] [PATCH v4 06/13] xen/pvcalls: implement bind command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_BIND to the backend. Introduce a new structure, part of
struct sock_mapping, to store information specific to passive sockets.

Introduce a status field to keep track of the status of the passive
socket.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 68 +
 drivers/xen/pvcalls-front.h |  3 ++
 2 files changed, 71 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index ef511b6..50b6588 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -72,6 +72,13 @@ struct sock_mapping {
 
wait_queue_head_t inflight_conn_req;
} active;
+   struct {
+   /* Socket status */
+#define PVCALLS_STATUS_UNINITALIZED  0
+#define PVCALLS_STATUS_BIND  1
+#define PVCALLS_STATUS_LISTEN2
+   uint8_t status;
+   } passive;
};
 };
 
@@ -346,6 +353,67 @@ int pvcalls_front_connect(struct socket *sock, struct 
sockaddr *addr,
return ret;
 }
 
+int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int 
addr_len)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) {
+   pvcalls_exit;
+   return -ENOTSUPP;
+   }
+   bedata = dev_get_drvdata(_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (map == NULL) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   spin_lock(>socket_lock);
+   ret = get_request(bedata, _id);
+   if (ret < 0) {
+   spin_unlock(>socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   req = RING_GET_REQUEST(>ring, req_id);
+   req->req_id = req_id;
+   map->sock = sock;
+   req->cmd = PVCALLS_BIND;
+   req->u.bind.id = (uint64_t) map;
+   memcpy(req->u.bind.addr, addr, sizeof(*addr));
+   req->u.bind.len = addr_len;
+
+   init_waitqueue_head(>passive.inflight_accept_req);
+
+   map->active_socket = false;
+
+   bedata->ring.req_prod_pvt++;
+   RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(>ring, notify);
+   spin_unlock(>socket_lock);
+   if (notify)
+   notify_remote_via_irq(bedata->irq);
+
+   wait_event(bedata->inflight_req,
+  READ_ONCE(bedata->rsp[req_id].req_id) == req_id);
+
+   map->passive.status = PVCALLS_STATUS_BIND;
+   ret = bedata->rsp[req_id].ret;
+   /* read ret, then set this rsp slot to be reused */
+   smp_mb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID);
+   pvcalls_exit;
+   return 0;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index 63b0417..8b0a274 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -6,5 +6,8 @@
 int pvcalls_front_socket(struct socket *sock);
 int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr,
  int addr_len, int flags);
+int pvcalls_front_bind(struct socket *sock,
+  struct sockaddr *addr,
+  int addr_len);
 
 #endif
-- 
1.9.1


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


[Xen-devel] [PATCH v4 02/13] xen/pvcalls: implement frontend disconnect

2017-09-15 Thread Stefano Stabellini
Introduce a data structure named pvcalls_bedata. It contains pointers to
the command ring, the event channel, a list of active sockets and a list
of passive sockets. Lists accesses are protected by a spin_lock.

Introduce a waitqueue to allow waiting for a response on commands sent
to the backend.

Introduce an array of struct xen_pvcalls_response to store commands
responses.

pvcalls_refcount is used to keep count of the outstanding pvcalls users.
Only remove connections once the refcount is zero.

Implement pvcalls frontend removal function. Go through the list of
active and passive sockets and free them all, one at a time.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 63 +
 1 file changed, 63 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index a8d38c2..67c8337 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -20,6 +20,42 @@
 #include 
 #include 
 
+#define PVCALLS_INVALID_ID UINT_MAX
+#define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
+#define PVCALLS_NR_REQ_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE)
+
+struct pvcalls_bedata {
+   struct xen_pvcalls_front_ring ring;
+   grant_ref_t ref;
+   int irq;
+
+   struct list_head socket_mappings;
+   struct list_head socketpass_mappings;
+   spinlock_t socket_lock;
+
+   wait_queue_head_t inflight_req;
+   struct xen_pvcalls_response rsp[PVCALLS_NR_REQ_PER_RING];
+};
+static struct xenbus_device *pvcalls_front_dev;
+static atomic_t pvcalls_refcount;
+
+/* first increment refcount, then proceed */
+#define pvcalls_enter { \
+   atomic_inc(_refcount);  \
+   smp_mb();   \
+}
+
+/* first complete other operations, then decrement refcount */
+#define pvcalls_exit {  \
+   smp_mb();   \
+   atomic_dec(_refcount);  \
+}
+
+static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
+{
+   return IRQ_HANDLED;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
@@ -27,6 +63,33 @@
 
 static int pvcalls_front_remove(struct xenbus_device *dev)
 {
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL, *n;
+
+   bedata = dev_get_drvdata(_front_dev->dev);
+   dev_set_drvdata(>dev, NULL);
+   pvcalls_front_dev = NULL;
+   if (bedata->irq >= 0)
+   unbind_from_irqhandler(bedata->irq, dev);
+
+   smp_mb();
+   while (atomic_read(_refcount) > 0)
+   cpu_relax();
+   list_for_each_entry_safe(map, n, >socket_mappings, list) {
+   pvcalls_front_free_map(bedata, map);
+   kfree(map);
+   }
+   list_for_each_entry_safe(map, n, >socketpass_mappings, list) {
+   spin_lock(>socket_lock);
+   list_del_init(>list);
+   spin_unlock(>socket_lock);
+   kfree(map);
+   }
+   if (bedata->ref >= 0)
+   gnttab_end_foreign_access(bedata->ref, 0, 0);
+   kfree(bedata->ring.sring);
+   kfree(bedata);
+   xenbus_switch_state(dev, XenbusStateClosed);
return 0;
 }
 
-- 
1.9.1


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


[Xen-devel] [PATCH v4 04/13] xen/pvcalls: implement socket command and handle events

2017-09-15 Thread Stefano Stabellini
Send a PVCALLS_SOCKET command to the backend, use the masked
req_prod_pvt as req_id. This way, req_id is guaranteed to be between 0
and PVCALLS_NR_REQ_PER_RING. We already have a slot in the rsp array
ready for the response, and there cannot be two outstanding responses
with the same req_id.

Wait for the response by waiting on the inflight_req waitqueue and
check for the req_id field in rsp[req_id]. Use atomic accesses and
barriers to read the field. Note that the barriers are simple smp
barriers (as opposed to virt barriers) because they are for internal
frontend synchronization, not frontend<->backend communication.

Once a response is received, clear the corresponding rsp slot by setting
req_id to PVCALLS_INVALID_ID. Note that PVCALLS_INVALID_ID is invalid
only from the frontend point of view. It is not part of the PVCalls
protocol.

pvcalls_front_event_handler is in charge of copying responses from the
ring to the appropriate rsp slot. It is done by copying the body of the
response first, then by copying req_id atomically. After the copies,
wake up anybody waiting on waitqueue.

socket_lock protects accesses to the ring.

Create a new struct sock_mapping and convert the pointer into an
uint64_t and use it as id for the new socket to pass to the backend. The
struct will be fully initialized later on connect or bind. In this patch
the struct sock_mapping is empty, the fields will be added by the next
patch.

sock->sk->sk_send_head is not used for ip sockets: reuse the field to
store a pointer to the struct sock_mapping corresponding to the socket.
This way, we can easily get the struct sock_mapping from the struct
socket.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 135 
 drivers/xen/pvcalls-front.h |   8 +++
 2 files changed, 143 insertions(+)
 create mode 100644 drivers/xen/pvcalls-front.h

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index ffbbcd1..1bad1b1 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 
+#include "pvcalls-front.h"
+
 #define PVCALLS_INVALID_ID UINT_MAX
 #define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
 #define PVCALLS_NR_REQ_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE)
@@ -51,11 +53,144 @@ struct pvcalls_bedata {
atomic_dec(_refcount);  \
 }
 
+struct sock_mapping {
+   bool active_socket;
+   struct list_head list;
+   struct socket *sock;
+};
+
+static inline int get_request(struct pvcalls_bedata *bedata, int *req_id)
+{
+   *req_id = bedata->ring.req_prod_pvt & (RING_SIZE(>ring) - 1);
+   if (RING_FULL(>ring) ||
+   READ_ONCE(bedata->rsp[*req_id].req_id) != PVCALLS_INVALID_ID)
+   return -EAGAIN;
+   return 0;
+}
+
 static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
 {
+   struct xenbus_device *dev = dev_id;
+   struct pvcalls_bedata *bedata;
+   struct xen_pvcalls_response *rsp;
+   uint8_t *src, *dst;
+   int req_id = 0, more = 0, done = 0;
+
+   if (dev == NULL)
+   return IRQ_HANDLED;
+
+   pvcalls_enter;
+   bedata = dev_get_drvdata(>dev);
+   if (bedata == NULL) {
+   pvcalls_exit;
+   return IRQ_HANDLED;
+   }
+
+again:
+   while (RING_HAS_UNCONSUMED_RESPONSES(>ring)) {
+   rsp = RING_GET_RESPONSE(>ring, bedata->ring.rsp_cons);
+
+   req_id = rsp->req_id;
+   dst = (uint8_t *)>rsp[req_id] + sizeof(rsp->req_id);
+   src = (uint8_t *)rsp + sizeof(rsp->req_id);
+   memcpy(dst, src, sizeof(*rsp) - sizeof(rsp->req_id));
+   /*
+* First copy the rest of the data, then req_id. It is
+* paired with the barrier when accessing bedata->rsp.
+*/
+   smp_wmb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, rsp->req_id);
+
+   done = 1;
+   bedata->ring.rsp_cons++;
+   }
+
+   RING_FINAL_CHECK_FOR_RESPONSES(>ring, more);
+   if (more)
+   goto again;
+   if (done)
+   wake_up(>inflight_req);
+   pvcalls_exit;
return IRQ_HANDLED;
 }
 
+int pvcalls_front_socket(struct socket *sock)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -EACCES;
+   }
+   /*
+* PVCalls only supports domain AF_INET,
+* type SOCK_STREAM and protocol 0 sockets for now.
+*
+* Check socket type here, AF_INET and protocol checks are done
+* by the caller.
+*/
+   if (sock->type != SOCK_STREAM) {
+   pvcalls_exit;
+ 

[Xen-devel] [PATCH v4 08/13] xen/pvcalls: implement accept command

2017-09-15 Thread Stefano Stabellini
Introduce a waitqueue to allow only one outstanding accept command at
any given time and to implement polling on the passive socket. Introduce
a flags field to keep track of in-flight accept and poll commands.

Send PVCALLS_ACCEPT to the backend. Allocate a new active socket. Make
sure that only one accept command is executed at any given time by
setting PVCALLS_FLAG_ACCEPT_INFLIGHT and waiting on the
inflight_accept_req waitqueue.

Convert the new struct sock_mapping pointer into an uint64_t and use it
as id for the new socket to pass to the backend.

Check if the accept call is non-blocking: in that case after sending the
ACCEPT command to the backend store the sock_mapping pointer of the new
struct and the inflight req_id then return -EAGAIN (which will respond
only when there is something to accept). Next time accept is called,
we'll check if the ACCEPT command has been answered, if so we'll pick up
where we left off, otherwise we return -EAGAIN again.

Note that, differently from the other commands, we can use
wait_event_interruptible (instead of wait_event) in the case of accept
as we are able to track the req_id of the ACCEPT response that we are
waiting.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 135 
 drivers/xen/pvcalls-front.h |   3 +
 2 files changed, 138 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 4ecc1e5..414eafd 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -78,6 +78,16 @@ struct sock_mapping {
 #define PVCALLS_STATUS_BIND  1
 #define PVCALLS_STATUS_LISTEN2
uint8_t status;
+   /*
+* Internal state-machine flags.
+* Only one accept operation can be inflight for a socket.
+* Only one poll operation can be inflight for a given socket.
+*/
+#define PVCALLS_FLAG_ACCEPT_INFLIGHT 0
+   uint8_t flags;
+   uint32_t inflight_req_id;
+   struct sock_mapping *accept_map;
+   wait_queue_head_t inflight_accept_req;
} passive;
};
 };
@@ -470,6 +480,131 @@ int pvcalls_front_listen(struct socket *sock, int backlog)
return ret;
 }
 
+int pvcalls_front_accept(struct socket *sock, struct socket *newsock, int 
flags)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   struct sock_mapping *map2 = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret, evtchn, nonblock;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   if (map->passive.status != PVCALLS_STATUS_LISTEN) {
+   pvcalls_exit;
+   return -EINVAL;
+   }
+
+   nonblock = flags & SOCK_NONBLOCK;
+   /*
+* Backend only supports 1 inflight accept request, will return
+* errors for the others
+*/
+   if (test_and_set_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
+(void *)>passive.flags)) {
+   req_id = READ_ONCE(map->passive.inflight_req_id);
+   if (req_id != PVCALLS_INVALID_ID &&
+   READ_ONCE(bedata->rsp[req_id].req_id) == req_id) {
+   map2 = map->passive.accept_map;
+   goto received;
+   }
+   if (nonblock) {
+   pvcalls_exit;
+   return -EAGAIN;
+   }
+   if (wait_event_interruptible(map->passive.inflight_accept_req,
+   !test_and_set_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
+ (void *)>passive.flags))) {
+   pvcalls_exit;
+   return -EINTR;
+   }
+   }
+
+   spin_lock(>socket_lock);
+   ret = get_request(bedata, _id);
+   if (ret < 0) {
+   spin_unlock(>socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   map2 = kzalloc(sizeof(*map2), GFP_KERNEL);
+   if (map2 == NULL) {
+   spin_unlock(>socket_lock);
+   pvcalls_exit;
+   return -ENOMEM;
+   }
+   ret =  create_active(map2, );
+   if (ret < 0) {
+   kfree(map2);
+   spin_unlock(>socket_lock);
+   pvcalls_exit;
+   return -ENOMEM;
+   }
+   list_add_tail(>list, >socket_mappings);
+
+   req = RING_GET_REQUEST(>ring, req_id);
+   req->req_id = req_id;
+   req->cmd = PVCALLS_ACCEPT;

[Xen-devel] [PATCH v4 11/13] xen/pvcalls: implement poll command

2017-09-15 Thread Stefano Stabellini
For active sockets, check the indexes and use the inflight_conn_req
waitqueue to wait.

For passive sockets if an accept is outstanding
(PVCALLS_FLAG_ACCEPT_INFLIGHT), check if it has been answered by looking
at bedata->rsp[req_id]. If so, return POLLIN.  Otherwise use the
inflight_accept_req waitqueue.

If no accepts are inflight, send PVCALLS_POLL to the backend. If we have
outstanding POLL requests awaiting for a response use the inflight_req
waitqueue: inflight_req is awaken when a new response is received; on
wakeup we check whether the POLL response is arrived by looking at the
PVCALLS_FLAG_POLL_RET flag. We set the flag from
pvcalls_front_event_handler, if the response was for a POLL command.

In pvcalls_front_event_handler, get the struct sock_mapping from the
poll id (we previously converted struct sock_mapping* to uint64_t and
used it as id).

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 144 +---
 drivers/xen/pvcalls-front.h |   3 +
 2 files changed, 138 insertions(+), 9 deletions(-)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 01a5a69..8a90213 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -85,6 +85,8 @@ struct sock_mapping {
 * Only one poll operation can be inflight for a given socket.
 */
 #define PVCALLS_FLAG_ACCEPT_INFLIGHT 0
+#define PVCALLS_FLAG_POLL_INFLIGHT   1
+#define PVCALLS_FLAG_POLL_RET2
uint8_t flags;
uint32_t inflight_req_id;
struct sock_mapping *accept_map;
@@ -155,15 +157,32 @@ static irqreturn_t pvcalls_front_event_handler(int irq, 
void *dev_id)
rsp = RING_GET_RESPONSE(>ring, bedata->ring.rsp_cons);
 
req_id = rsp->req_id;
-   dst = (uint8_t *)>rsp[req_id] + sizeof(rsp->req_id);
-   src = (uint8_t *)rsp + sizeof(rsp->req_id);
-   memcpy(dst, src, sizeof(*rsp) - sizeof(rsp->req_id));
-   /*
-* First copy the rest of the data, then req_id. It is
-* paired with the barrier when accessing bedata->rsp.
-*/
-   smp_wmb();
-   WRITE_ONCE(bedata->rsp[req_id].req_id, rsp->req_id);
+   if (rsp->cmd == PVCALLS_POLL) {
+   struct sock_mapping *map = (struct sock_mapping *)
+  rsp->u.poll.id;
+
+   set_bit(PVCALLS_FLAG_POLL_RET,
+   (void *)>passive.flags);
+   /*
+* Set RET, then clear INFLIGHT. It pairs with
+* the checks at the beginning of
+* pvcalls_front_poll_passive.
+*/
+   smp_wmb();
+   clear_bit(PVCALLS_FLAG_POLL_INFLIGHT,
+ (void *)>passive.flags);
+   } else {
+   dst = (uint8_t *)>rsp[req_id] +
+ sizeof(rsp->req_id);
+   src = (uint8_t *)rsp + sizeof(rsp->req_id);
+   memcpy(dst, src, sizeof(*rsp) - sizeof(rsp->req_id));
+   /*
+* First copy the rest of the data, then req_id. It is
+* paired with the barrier when accessing bedata->rsp.
+*/
+   smp_wmb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, rsp->req_id);
+   }
 
done = 1;
bedata->ring.rsp_cons++;
@@ -834,6 +853,113 @@ int pvcalls_front_accept(struct socket *sock, struct 
socket *newsock, int flags)
return ret;
 }
 
+static unsigned int pvcalls_front_poll_passive(struct file *file,
+  struct pvcalls_bedata *bedata,
+  struct sock_mapping *map,
+  poll_table *wait)
+{
+   int notify, req_id, ret;
+   struct xen_pvcalls_request *req;
+
+   if (test_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT,
+(void *)>passive.flags)) {
+   uint32_t req_id = READ_ONCE(map->passive.inflight_req_id);
+
+   if (req_id != PVCALLS_INVALID_ID &&
+   READ_ONCE(bedata->rsp[req_id].req_id) == req_id)
+   return POLLIN | POLLRDNORM;
+
+   poll_wait(file, >passive.inflight_accept_req, wait);
+   return 0;
+   }
+
+   if (test_and_clear_bit(PVCALLS_FLAG_POLL_RET,
+  (void *)>passive.flags))
+   return POLLIN | POLLRDNORM;
+
+   /*
+* First check RET, then INFLIGHT. No barriers necessary to
+* ensure 

[Xen-devel] [PATCH v4 13/13] xen: introduce a Kconfig option to enable the pvcalls frontend

2017-09-15 Thread Stefano Stabellini
Also add pvcalls-front to the Makefile.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/Kconfig  | 9 +
 drivers/xen/Makefile | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 4545561..0b2c828 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -196,6 +196,15 @@ config XEN_PCIDEV_BACKEND
 
  If in doubt, say m.
 
+config XEN_PVCALLS_FRONTEND
+   tristate "XEN PV Calls frontend driver"
+   depends on INET && XEN
+   help
+ Experimental frontend for the Xen PV Calls protocol
+ (https://xenbits.xen.org/docs/unstable/misc/pvcalls.html). It
+ sends a small set of POSIX calls to the backend, which
+ implements them.
+
 config XEN_PVCALLS_BACKEND
bool "XEN PV Calls backend driver"
depends on INET && XEN && XEN_BACKEND
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 480b928..afb9e03 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_XEN_EFI) += efi.o
 obj-$(CONFIG_XEN_SCSI_BACKEND) += xen-scsiback.o
 obj-$(CONFIG_XEN_AUTO_XLATE)   += xlate_mmu.o
 obj-$(CONFIG_XEN_PVCALLS_BACKEND)  += pvcalls-back.o
+obj-$(CONFIG_XEN_PVCALLS_FRONTEND) += pvcalls-front.o
 xen-evtchn-y   := evtchn.o
 xen-gntdev-y   := gntdev.o
 xen-gntalloc-y := gntalloc.o
-- 
1.9.1


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


[Xen-devel] [PATCH v4 07/13] xen/pvcalls: implement listen command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_LISTEN to the backend.

Signed-off-by: Stefano Stabellini 
Reviewed-by: Boris Ostrovsky 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 56 +
 drivers/xen/pvcalls-front.h |  1 +
 2 files changed, 57 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 50b6588..4ecc1e5 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -414,6 +414,62 @@ int pvcalls_front_bind(struct socket *sock, struct 
sockaddr *addr, int addr_len)
return 0;
 }
 
+int pvcalls_front_listen(struct socket *sock, int backlog)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   if (map->passive.status != PVCALLS_STATUS_BIND) {
+   pvcalls_exit;
+   return -EOPNOTSUPP;
+   }
+
+   spin_lock(>socket_lock);
+   ret = get_request(bedata, _id);
+   if (ret < 0) {
+   spin_unlock(>socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   req = RING_GET_REQUEST(>ring, req_id);
+   req->req_id = req_id;
+   req->cmd = PVCALLS_LISTEN;
+   req->u.listen.id = (uint64_t) map;
+   req->u.listen.backlog = backlog;
+
+   bedata->ring.req_prod_pvt++;
+   RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(>ring, notify);
+   spin_unlock(>socket_lock);
+   if (notify)
+   notify_remote_via_irq(bedata->irq);
+
+   wait_event(bedata->inflight_req,
+  READ_ONCE(bedata->rsp[req_id].req_id) == req_id);
+
+   map->passive.status = PVCALLS_STATUS_LISTEN;
+   ret = bedata->rsp[req_id].ret;
+   /* read ret, then set this rsp slot to be reused */
+   smp_mb();
+   WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID);
+   pvcalls_exit;
+   return ret;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index 8b0a274..aa8fe10 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -9,5 +9,6 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr 
*addr,
 int pvcalls_front_bind(struct socket *sock,
   struct sockaddr *addr,
   int addr_len);
+int pvcalls_front_listen(struct socket *sock, int backlog);
 
 #endif
-- 
1.9.1


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


[Xen-devel] [PATCH v4 09/13] xen/pvcalls: implement sendmsg

2017-09-15 Thread Stefano Stabellini
Send data to an active socket by copying data to the "out" ring. Take
the active socket out_mutex so that only one function can access the
ring at any given time.

If not enough room is available on the ring, rather than returning
immediately or sleep-waiting, spin for up to 5000 cycles. This small
optimization turns out to improve performance significantly.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 119 
 drivers/xen/pvcalls-front.h |   3 ++
 2 files changed, 122 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 414eafd..2907e85 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -29,6 +29,7 @@
 #define PVCALLS_INVALID_ID UINT_MAX
 #define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
 #define PVCALLS_NR_REQ_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE)
+#define PVCALLS_FRONT_MAX_SPIN 5000
 
 struct pvcalls_bedata {
struct xen_pvcalls_front_ring ring;
@@ -101,6 +102,22 @@ static inline int get_request(struct pvcalls_bedata 
*bedata, int *req_id)
return 0;
 }
 
+static bool pvcalls_front_write_todo(struct sock_mapping *map)
+{
+   struct pvcalls_data_intf *intf = map->active.ring;
+   RING_IDX cons, prod, size = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+   int32_t error;
+
+   cons = intf->out_cons;
+   prod = intf->out_prod;
+   error = intf->out_error;
+   if (error == -ENOTCONN)
+   return false;
+   if (error != 0)
+   return true;
+   return !!(size - pvcalls_queued(prod, cons, size));
+}
+
 static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
 {
struct xenbus_device *dev = dev_id;
@@ -363,6 +380,108 @@ int pvcalls_front_connect(struct socket *sock, struct 
sockaddr *addr,
return ret;
 }
 
+static int __write_ring(struct pvcalls_data_intf *intf,
+   struct pvcalls_data *data,
+   struct iov_iter *msg_iter,
+   int len)
+{
+   RING_IDX cons, prod, size, masked_prod, masked_cons;
+   RING_IDX array_size = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+   int32_t error;
+
+   error = intf->out_error;
+   if (error < 0)
+   return error;
+   cons = intf->out_cons;
+   prod = intf->out_prod;
+   /* read indexes before continuing */
+   virt_mb();
+
+   size = pvcalls_queued(prod, cons, array_size);
+   if (size >= array_size)
+   return 0;
+   if (len > array_size - size)
+   len = array_size - size;
+
+   masked_prod = pvcalls_mask(prod, array_size);
+   masked_cons = pvcalls_mask(cons, array_size);
+
+   if (masked_prod < masked_cons) {
+   copy_from_iter(data->out + masked_prod, len, msg_iter);
+   } else {
+   if (len > array_size - masked_prod) {
+   copy_from_iter(data->out + masked_prod,
+  array_size - masked_prod, msg_iter);
+   copy_from_iter(data->out,
+  len - (array_size - masked_prod),
+  msg_iter);
+   } else {
+   copy_from_iter(data->out + masked_prod, len, msg_iter);
+   }
+   }
+   /* write to ring before updating pointer */
+   virt_wmb();
+   intf->out_prod += len;
+
+   return len;
+}
+
+int pvcalls_front_sendmsg(struct socket *sock, struct msghdr *msg,
+ size_t len)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   int sent, tot_sent = 0;
+   int count = 0, flags;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   flags = msg->msg_flags;
+   if (flags & (MSG_CONFIRM|MSG_DONTROUTE|MSG_EOR|MSG_OOB)) {
+   pvcalls_exit;
+   return -EOPNOTSUPP;
+   }
+
+   mutex_lock(>active.out_mutex);
+   if ((flags & MSG_DONTWAIT) && !pvcalls_front_write_todo(map)) {
+   mutex_unlock(>active.out_mutex);
+   pvcalls_exit;
+   return -EAGAIN;
+   }
+   if (len > INT_MAX)
+   len = INT_MAX;
+
+again:
+   count++;
+   sent = __write_ring(map->active.ring,
+   >active.data, >msg_iter,
+   len);
+   if (sent > 0) {
+   len -= sent;
+   tot_sent += sent;
+   notify_remote_via_irq(map->active.irq);
+   }
+   if (sent >= 0 && len > 0 && count < 

[Xen-devel] [PATCH v4 05/13] xen/pvcalls: implement connect command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_CONNECT to the backend. Allocate a new ring and evtchn for
the active socket.

Introduce fields in struct sock_mapping to keep track of active sockets.
Introduce a waitqueue to allow the frontend to wait on data coming from
the backend on the active socket (recvmsg command).

Two mutexes (one of reads and one for writes) will be used to protect
the active socket in and out rings from concurrent accesses.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 163 
 drivers/xen/pvcalls-front.h |   2 +
 2 files changed, 165 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 1bad1b1..ef511b6 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -13,6 +13,10 @@
  */
 
 #include 
+#include 
+#include 
+
+#include 
 
 #include 
 #include 
@@ -57,6 +61,18 @@ struct sock_mapping {
bool active_socket;
struct list_head list;
struct socket *sock;
+   union {
+   struct {
+   int irq;
+   grant_ref_t ref;
+   struct pvcalls_data_intf *ring;
+   struct pvcalls_data data;
+   struct mutex in_mutex;
+   struct mutex out_mutex;
+
+   wait_queue_head_t inflight_conn_req;
+   } active;
+   };
 };
 
 static inline int get_request(struct pvcalls_bedata *bedata, int *req_id)
@@ -114,6 +130,18 @@ static irqreturn_t pvcalls_front_event_handler(int irq, 
void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t pvcalls_front_conn_handler(int irq, void *sock_map)
+{
+   struct sock_mapping *map = sock_map;
+
+   if (map == NULL)
+   return IRQ_HANDLED;
+
+   wake_up_interruptible(>active.inflight_conn_req);
+
+   return IRQ_HANDLED;
+}
+
 int pvcalls_front_socket(struct socket *sock)
 {
struct pvcalls_bedata *bedata;
@@ -191,6 +219,133 @@ int pvcalls_front_socket(struct socket *sock)
return ret;
 }
 
+static int create_active(struct sock_mapping *map, int *evtchn)
+{
+   void *bytes;
+   int ret = -ENOMEM, irq = -1, i;
+
+   *evtchn = -1;
+   init_waitqueue_head(>active.inflight_conn_req);
+
+   map->active.ring = (struct pvcalls_data_intf *)
+   __get_free_page(GFP_KERNEL | __GFP_ZERO);
+   if (map->active.ring == NULL)
+   goto out_error;
+   map->active.ring->ring_order = PVCALLS_RING_ORDER;
+   bytes = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+   PVCALLS_RING_ORDER);
+   if (bytes == NULL)
+   goto out_error;
+   for (i = 0; i < (1 << PVCALLS_RING_ORDER); i++)
+   map->active.ring->ref[i] = gnttab_grant_foreign_access(
+   pvcalls_front_dev->otherend_id,
+   pfn_to_gfn(virt_to_pfn(bytes) + i), 0);
+
+   map->active.ref = gnttab_grant_foreign_access(
+   pvcalls_front_dev->otherend_id,
+   pfn_to_gfn(virt_to_pfn((void *)map->active.ring)), 0);
+
+   map->active.data.in = bytes;
+   map->active.data.out = bytes +
+   XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+
+   ret = xenbus_alloc_evtchn(pvcalls_front_dev, evtchn);
+   if (ret)
+   goto out_error;
+   irq = bind_evtchn_to_irqhandler(*evtchn, pvcalls_front_conn_handler,
+   0, "pvcalls-frontend", map);
+   if (irq < 0) {
+   ret = irq;
+   goto out_error;
+   }
+
+   map->active.irq = irq;
+   map->active_socket = true;
+   mutex_init(>active.in_mutex);
+   mutex_init(>active.out_mutex);
+
+   return 0;
+
+out_error:
+   if (irq >= 0)
+   unbind_from_irqhandler(irq, map);
+   else if (*evtchn >= 0)
+   xenbus_free_evtchn(pvcalls_front_dev, *evtchn);
+   kfree(map->active.data.in);
+   kfree(map->active.ring);
+   return ret;
+}
+
+int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr,
+   int addr_len, int flags)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map = NULL;
+   struct xen_pvcalls_request *req;
+   int notify, req_id, ret, evtchn;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENETUNREACH;
+   }
+   if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) {
+   pvcalls_exit;
+   return -ENOTSUPP;
+   }
+
+   bedata = dev_get_drvdata(_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   spin_lock(>socket_lock);
+   ret = 

[Xen-devel] [PATCH v4 10/13] xen/pvcalls: implement recvmsg

2017-09-15 Thread Stefano Stabellini
Implement recvmsg by copying data from the "in" ring. If not enough data
is available and the recvmsg call is blocking, then wait on the
inflight_conn_req waitqueue. Take the active socket in_mutex so that
only one function can access the ring at any given time.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 110 
 drivers/xen/pvcalls-front.h |   4 ++
 2 files changed, 114 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 2907e85..01a5a69 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -118,6 +118,20 @@ static bool pvcalls_front_write_todo(struct sock_mapping 
*map)
return !!(size - pvcalls_queued(prod, cons, size));
 }
 
+static bool pvcalls_front_read_todo(struct sock_mapping *map)
+{
+   struct pvcalls_data_intf *intf = map->active.ring;
+   RING_IDX cons, prod;
+   int32_t error;
+
+   cons = intf->in_cons;
+   prod = intf->in_prod;
+   error = intf->in_error;
+   return (error != 0 ||
+   pvcalls_queued(prod, cons,
+  XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER)) != 0);
+}
+
 static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
 {
struct xenbus_device *dev = dev_id;
@@ -482,6 +496,102 @@ int pvcalls_front_sendmsg(struct socket *sock, struct 
msghdr *msg,
return tot_sent;
 }
 
+static int __read_ring(struct pvcalls_data_intf *intf,
+  struct pvcalls_data *data,
+  struct iov_iter *msg_iter,
+  size_t len, int flags)
+{
+   RING_IDX cons, prod, size, masked_prod, masked_cons;
+   RING_IDX array_size = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+   int32_t error;
+
+   cons = intf->in_cons;
+   prod = intf->in_prod;
+   error = intf->in_error;
+   /* get pointers before reading from the ring */
+   virt_rmb();
+   if (error < 0)
+   return error;
+
+   size = pvcalls_queued(prod, cons, array_size);
+   masked_prod = pvcalls_mask(prod, array_size);
+   masked_cons = pvcalls_mask(cons, array_size);
+
+   if (size == 0)
+   return 0;
+
+   if (len > size)
+   len = size;
+
+   if (masked_prod > masked_cons) {
+   copy_to_iter(data->in + masked_cons, len, msg_iter);
+   } else {
+   if (len > (array_size - masked_cons)) {
+   copy_to_iter(data->in + masked_cons,
+array_size - masked_cons, msg_iter);
+   copy_to_iter(data->in,
+len - (array_size - masked_cons),
+msg_iter);
+   } else {
+   copy_to_iter(data->in + masked_cons, len, msg_iter);
+   }
+   }
+   /* read data from the ring before increasing the index */
+   virt_mb();
+   if (!(flags & MSG_PEEK))
+   intf->in_cons += len;
+
+   return len;
+}
+
+int pvcalls_front_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
+int flags)
+{
+   struct pvcalls_bedata *bedata;
+   int ret;
+   struct sock_mapping *map;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -ENOTCONN;
+   }
+   bedata = dev_get_drvdata(_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (!map) {
+   pvcalls_exit;
+   return -ENOTSOCK;
+   }
+
+   if (flags & (MSG_CMSG_CLOEXEC|MSG_ERRQUEUE|MSG_OOB|MSG_TRUNC)) {
+   pvcalls_exit;
+   return -EOPNOTSUPP;
+   }
+
+   mutex_lock(>active.in_mutex);
+   if (len > XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER))
+   len = XEN_FLEX_RING_SIZE(PVCALLS_RING_ORDER);
+
+   while (!(flags & MSG_DONTWAIT) && !pvcalls_front_read_todo(map)) {
+   wait_event_interruptible(map->active.inflight_conn_req,
+pvcalls_front_read_todo(map));
+   }
+   ret = __read_ring(map->active.ring, >active.data,
+ >msg_iter, len, flags);
+
+   if (ret > 0)
+   notify_remote_via_irq(map->active.irq);
+   if (ret == 0)
+   ret = -EAGAIN;
+   if (ret == -ENOTCONN)
+   ret = 0;
+
+   mutex_unlock(>active.in_mutex);
+   pvcalls_exit;
+   return ret;
+}
+
 int pvcalls_front_bind(struct socket *sock, struct sockaddr *addr, int 
addr_len)
 {
struct pvcalls_bedata *bedata;
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index d937c24..de24041 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -16,5 +16,9 @@ int pvcalls_front_accept(struct socket *sock,
 

[Xen-devel] [PATCH v4 12/13] xen/pvcalls: implement release command

2017-09-15 Thread Stefano Stabellini
Send PVCALLS_RELEASE to the backend and wait for a reply. Take both
in_mutex and out_mutex to avoid concurrent accesses. Then, free the
socket.

For passive sockets, check whether we have already pre-allocated an
active socket for the purpose of being accepted. If so, free that as
well.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 104 
 drivers/xen/pvcalls-front.h |   1 +
 2 files changed, 105 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 8a90213..5f8e94a 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -209,6 +209,24 @@ static irqreturn_t pvcalls_front_conn_handler(int irq, 
void *sock_map)
return IRQ_HANDLED;
 }
 
+static void pvcalls_front_free_map(struct pvcalls_bedata *bedata,
+  struct sock_mapping *map)
+{
+   int i;
+
+   unbind_from_irqhandler(map->active.irq, map);
+
+   spin_lock(>socket_lock);
+   if (!list_empty(>list))
+   list_del_init(>list);
+   spin_unlock(>socket_lock);
+
+   for (i = 0; i < (1 << PVCALLS_RING_ORDER); i++)
+   gnttab_end_foreign_access(map->active.ring->ref[i], 0, 0);
+   gnttab_end_foreign_access(map->active.ref, 0, 0);
+   free_page((unsigned long)map->active.ring);
+}
+
 int pvcalls_front_socket(struct socket *sock)
 {
struct pvcalls_bedata *bedata;
@@ -960,6 +978,92 @@ unsigned int pvcalls_front_poll(struct file *file, struct 
socket *sock,
return ret;
 }
 
+int pvcalls_front_release(struct socket *sock)
+{
+   struct pvcalls_bedata *bedata;
+   struct sock_mapping *map;
+   int req_id, notify, ret;
+   struct xen_pvcalls_request *req;
+
+   pvcalls_enter;
+   if (!pvcalls_front_dev) {
+   pvcalls_exit;
+   return -EIO;
+   }
+   if (sock->sk == NULL) {
+   pvcalls_exit;
+   return 0;
+   }
+
+   bedata = dev_get_drvdata(_front_dev->dev);
+
+   map = (struct sock_mapping *) sock->sk->sk_send_head;
+   if (map == NULL) {
+   pvcalls_exit;
+   return 0;
+   }
+
+   spin_lock(>socket_lock);
+   ret = get_request(bedata, _id);
+   if (ret < 0) {
+   spin_unlock(>socket_lock);
+   pvcalls_exit;
+   return ret;
+   }
+   sock->sk->sk_send_head = NULL;
+
+   req = RING_GET_REQUEST(>ring, req_id);
+   req->req_id = req_id;
+   req->cmd = PVCALLS_RELEASE;
+   req->u.release.id = (uint64_t)map;
+
+   bedata->ring.req_prod_pvt++;
+   RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(>ring, notify);
+   spin_unlock(>socket_lock);
+   if (notify)
+   notify_remote_via_irq(bedata->irq);
+
+   wait_event(bedata->inflight_req,
+  READ_ONCE(bedata->rsp[req_id].req_id) == req_id);
+
+   if (map->active_socket) {
+   /*
+* Set in_error and wake up inflight_conn_req to force
+* recvmsg waiters to exit.
+*/
+   map->active.ring->in_error = -EBADF;
+   wake_up_interruptible(>active.inflight_conn_req);
+
+   /*
+* Wait until there are no more waiters on the mutexes.
+* We know that no new waiters can be added because sk_send_head
+* is set to NULL -- we only need to wait for the existing
+* waiters to return.
+*/
+   while (!mutex_trylock(>active.in_mutex) ||
+  !mutex_trylock(>active.out_mutex))
+   cpu_relax();
+
+   pvcalls_front_free_map(bedata, map);
+   kfree(map);
+   } else {
+   spin_lock(>socket_lock);
+   if (READ_ONCE(map->passive.inflight_req_id) !=
+   PVCALLS_INVALID_ID) {
+   pvcalls_front_free_map(bedata,
+  map->passive.accept_map);
+   kfree(map->passive.accept_map);
+   }
+   list_del_init(>list);
+   kfree(map);
+   spin_unlock(>socket_lock);
+   }
+   WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID);
+
+   pvcalls_exit;
+   return 0;
+}
+
 static const struct xenbus_device_id pvcalls_front_ids[] = {
{ "pvcalls" },
{ "" }
diff --git a/drivers/xen/pvcalls-front.h b/drivers/xen/pvcalls-front.h
index 25e05b8..3332978 100644
--- a/drivers/xen/pvcalls-front.h
+++ b/drivers/xen/pvcalls-front.h
@@ -23,5 +23,6 @@ int pvcalls_front_recvmsg(struct socket *sock,
 unsigned int pvcalls_front_poll(struct file *file,
struct socket *sock,
poll_table *wait);
+int pvcalls_front_release(struct socket 

[Xen-devel] [PATCH v4 00/13] introduce the Xen PV Calls frontend

2017-09-15 Thread Stefano Stabellini
Hi all,

this series introduces the frontend for the newly introduced PV Calls
procotol.

PV Calls is a paravirtualized protocol that allows the implementation of
a set of POSIX functions in a different domain. The PV Calls frontend
sends POSIX function calls to the backend, which implements them and
returns a value to the frontend and acts on the function call.

For more information about PV Calls, please read:

https://xenbits.xen.org/docs/unstable/misc/pvcalls.html

This patch series only implements the frontend driver. It doesn't
attempt to redirect POSIX calls to it. The functions exported in
pvcalls-front.h are meant to be used for that. A separate patch series
will be sent to use them and hook them into the system.



Changes in v4:

In this version of the series I introduced a global refcount to keep
track of outstanding users of the pvcalls functions. refcount is
increased on entering a pvcalls frontend function and is decreased on
returning from it. This is necessary to figure out the right time to
deallocate pvcalls frontend resources in pvcalls_front_remove.

A similar, more limited, issue affects pvcalls_front_release: it needs
to find out the right time to free a single active socket mapping. The
outstanding users are sendmsg and recvmsg. Instead of adding another
refcount, I am reusing the existing in_mutex and out_mutex to find out
if there are outstanding users of the socket mapping. It is safe because
we know that there cannot be any new sendmsg and recvmsg callers not
already waiting for one of the two mutexes.

- introduce pvcalls_refcount to avoid removing data structs that are
  still in-use
- set pvcalls_front_dev to NULL first in pvcalls_front_remove
- use mutex_trylock to check the state of in_mutex and out_mutex before
  freeing a map in pvcalls_front_release
- rename pvcallss_lock to socket_lock
- add a comment on XENBUS_FUNCTIONS_CALLS
- fix the irq check to >= 0
- initialize socket_mappings in pvcalls_front_probe so that
  pvcalls_front_remove can deal with it properly
- use IPPROTO_IP
- free new mapping in pvcalls_front_socket in case of errors
- no need to zero map->active.ring twice
- use PVCALLS_RING_ORDER instead of map->active.ring->ring_order
- set *evtchn to -1 at the beginning of create_active
- don't free map in create_active in case of errors, it should be freed
  by a release command
- add reviewed-bys
- free map2 in case of errors in pvcalls_front_accept
- properly unlock in error paths in pvcalls_front_accept
- make pvcalls_front_write_todo return bool
- move the error check before the barrier in __write_ring
- add a check "len >= INT_MAX" in pvcalls_front_sendmsg
- make the len parameter of __write_ring an int
- don't initialize sent in pvcalls_front_sendmsg
- make the error value for sk_send_head being zero consistent
- don't initialize ret in pvcalls_front_recvmsg
- unbind_from_irqhandler before doing anything else in
  pvcalls_front_free_map
- move the "sock->sk == NULL" check before bedata access in
  pvcalls_front_release
- no need to use READ/WRITE_ONCE to access sk_send_head


Stefano Stabellini (13):
  xen/pvcalls: introduce the pvcalls xenbus frontend
  xen/pvcalls: implement frontend disconnect
  xen/pvcalls: connect to the backend
  xen/pvcalls: implement socket command and handle events
  xen/pvcalls: implement connect command
  xen/pvcalls: implement bind command
  xen/pvcalls: implement listen command
  xen/pvcalls: implement accept command
  xen/pvcalls: implement sendmsg
  xen/pvcalls: implement recvmsg
  xen/pvcalls: implement poll command
  xen/pvcalls: implement release command
  xen: introduce a Kconfig option to enable the pvcalls frontend

 drivers/xen/Kconfig |9 +
 drivers/xen/Makefile|1 +
 drivers/xen/pvcalls-front.c | 1273 +++
 drivers/xen/pvcalls-front.h |   28 +
 4 files changed, 1311 insertions(+)
 create mode 100644 drivers/xen/pvcalls-front.c
 create mode 100644 drivers/xen/pvcalls-front.h

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


[Xen-devel] [PATCH v4 01/13] xen/pvcalls: introduce the pvcalls xenbus frontend

2017-09-15 Thread Stefano Stabellini
Introduce a xenbus frontend for the pvcalls protocol, as defined by
https://xenbits.xen.org/docs/unstable/misc/pvcalls.html.

This patch only adds the stubs, the code will be added by the following
patches.

Signed-off-by: Stefano Stabellini 
Reviewed-by: Boris Ostrovsky 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 61 +
 1 file changed, 61 insertions(+)
 create mode 100644 drivers/xen/pvcalls-front.c

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
new file mode 100644
index 000..a8d38c2
--- /dev/null
+++ b/drivers/xen/pvcalls-front.c
@@ -0,0 +1,61 @@
+/*
+ * (c) 2017 Stefano Stabellini 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const struct xenbus_device_id pvcalls_front_ids[] = {
+   { "pvcalls" },
+   { "" }
+};
+
+static int pvcalls_front_remove(struct xenbus_device *dev)
+{
+   return 0;
+}
+
+static int pvcalls_front_probe(struct xenbus_device *dev,
+ const struct xenbus_device_id *id)
+{
+   return 0;
+}
+
+static void pvcalls_front_changed(struct xenbus_device *dev,
+   enum xenbus_state backend_state)
+{
+}
+
+static struct xenbus_driver pvcalls_front_driver = {
+   .ids = pvcalls_front_ids,
+   .probe = pvcalls_front_probe,
+   .remove = pvcalls_front_remove,
+   .otherend_changed = pvcalls_front_changed,
+};
+
+static int __init pvcalls_frontend_init(void)
+{
+   if (!xen_domain())
+   return -ENODEV;
+
+   pr_info("Initialising Xen pvcalls frontend driver\n");
+
+   return xenbus_register_frontend(_front_driver);
+}
+
+module_init(pvcalls_frontend_init);
-- 
1.9.1


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


[Xen-devel] [PATCH v4 03/13] xen/pvcalls: connect to the backend

2017-09-15 Thread Stefano Stabellini
Implement the probe function for the pvcalls frontend. Read the
supported versions, max-page-order and function-calls nodes from
xenstore.

Only one frontend<->backend connection is supported at any given time
for a guest. Store the active frontend device to a static pointer.

Introduce a stub functions for the event handler.

Signed-off-by: Stefano Stabellini 
CC: boris.ostrov...@oracle.com
CC: jgr...@suse.com
---
 drivers/xen/pvcalls-front.c | 133 
 1 file changed, 133 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 67c8337..ffbbcd1 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -96,12 +96,145 @@ static int pvcalls_front_remove(struct xenbus_device *dev)
 static int pvcalls_front_probe(struct xenbus_device *dev,
  const struct xenbus_device_id *id)
 {
+   int ret = -ENOMEM, evtchn, i;
+   unsigned int max_page_order, function_calls, len;
+   char *versions;
+   grant_ref_t gref_head = 0;
+   struct xenbus_transaction xbt;
+   struct pvcalls_bedata *bedata = NULL;
+   struct xen_pvcalls_sring *sring;
+
+   if (pvcalls_front_dev != NULL) {
+   dev_err(>dev, "only one PV Calls connection supported\n");
+   return -EINVAL;
+   }
+
+   versions = xenbus_read(XBT_NIL, dev->otherend, "versions", );
+   if (!len)
+   return -EINVAL;
+   if (strcmp(versions, "1")) {
+   kfree(versions);
+   return -EINVAL;
+   }
+   kfree(versions);
+   max_page_order = xenbus_read_unsigned(dev->otherend,
+ "max-page-order", 0);
+   if (max_page_order < PVCALLS_RING_ORDER)
+   return -ENODEV;
+   function_calls = xenbus_read_unsigned(dev->otherend,
+ "function-calls", 0);
+   /* See XENBUS_FUNCTIONS_CALLS in pvcalls.h */
+   if (function_calls != 1)
+   return -ENODEV;
+   pr_info("%s max-page-order is %u\n", __func__, max_page_order);
+
+   bedata = kzalloc(sizeof(struct pvcalls_bedata), GFP_KERNEL);
+   if (!bedata)
+   return -ENOMEM;
+
+   dev_set_drvdata(>dev, bedata);
+   pvcalls_front_dev = dev;
+   init_waitqueue_head(>inflight_req);
+   INIT_LIST_HEAD(>socket_mappings);
+   INIT_LIST_HEAD(>socketpass_mappings);
+   spin_lock_init(>socket_lock);
+   bedata->irq = -1;
+   bedata->ref = -1;
+
+   for (i = 0; i < PVCALLS_NR_REQ_PER_RING; i++)
+   bedata->rsp[i].req_id = PVCALLS_INVALID_ID;
+
+   sring = (struct xen_pvcalls_sring *) __get_free_page(GFP_KERNEL |
+__GFP_ZERO);
+   if (!sring)
+   goto error;
+   SHARED_RING_INIT(sring);
+   FRONT_RING_INIT(>ring, sring, XEN_PAGE_SIZE);
+
+   ret = xenbus_alloc_evtchn(dev, );
+   if (ret)
+   goto error;
+
+   bedata->irq = bind_evtchn_to_irqhandler(evtchn,
+   pvcalls_front_event_handler,
+   0, "pvcalls-frontend", dev);
+   if (bedata->irq < 0) {
+   ret = bedata->irq;
+   goto error;
+   }
+
+   ret = gnttab_alloc_grant_references(1, _head);
+   if (ret < 0)
+   goto error;
+   bedata->ref = gnttab_claim_grant_reference(_head);
+   if (bedata->ref < 0) {
+   ret = bedata->ref;
+   goto error;
+   }
+   gnttab_grant_foreign_access_ref(bedata->ref, dev->otherend_id,
+   virt_to_gfn((void *)sring), 0);
+
+ again:
+   ret = xenbus_transaction_start();
+   if (ret) {
+   xenbus_dev_fatal(dev, ret, "starting transaction");
+   goto error;
+   }
+   ret = xenbus_printf(xbt, dev->nodename, "version", "%u", 1);
+   if (ret)
+   goto error_xenbus;
+   ret = xenbus_printf(xbt, dev->nodename, "ring-ref", "%d", bedata->ref);
+   if (ret)
+   goto error_xenbus;
+   ret = xenbus_printf(xbt, dev->nodename, "port", "%u",
+   evtchn);
+   if (ret)
+   goto error_xenbus;
+   ret = xenbus_transaction_end(xbt, 0);
+   if (ret) {
+   if (ret == -EAGAIN)
+   goto again;
+   xenbus_dev_fatal(dev, ret, "completing transaction");
+   goto error;
+   }
+   xenbus_switch_state(dev, XenbusStateInitialised);
+
return 0;
+
+ error_xenbus:
+   xenbus_transaction_end(xbt, 1);
+   xenbus_dev_fatal(dev, ret, "writing xenstore");
+ error:
+   pvcalls_front_remove(dev);
+   return ret;
 }
 
 static void pvcalls_front_changed(struct xenbus_device *dev,
enum xenbus_state 

Re: [Xen-devel] [PATCH v1 0/2] Misc fixes regarding releasing resources on ARM

2017-09-15 Thread Stefano Stabellini
On Mon, 28 Aug 2017, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko 

Thanks for the fixes, I committed the two patches.


> Oleksandr Tyshchenko (2):
>   xen/arm: vgic: Check for vgic handler to be initialized before
> dereferencing it
>   xen/arm: p2m: Check for p2m->domain to be initialized before releasing
> resources
> 
>  xen/arch/arm/p2m.c  | 13 -
>  xen/arch/arm/vgic.c |  3 ++-
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> -- 
> 2.7.4
> 

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


Re: [Xen-devel] [PATCH v1 2/2] xen/arm: p2m: Check for p2m->domain to be initialized before releasing resources

2017-09-15 Thread Stefano Stabellini
On Mon, 28 Aug 2017, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko 
> 
> Since p2m_teardown() can be called when p2m_init() haven't executed yet
> we might deal with unitialized list "p2m->pages" which leads to crash.
> To avoid this use back pointer to domain as end-of-initialization indicator.
> 
> Signed-off-by: Oleksandr Tyshchenko 
> ---
>  xen/arch/arm/p2m.c | 13 -
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index c484469..141ae7e 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -1219,6 +1219,9 @@ void p2m_teardown(struct domain *d)
>  struct p2m_domain *p2m = p2m_get_hostp2m(d);
>  struct page_info *pg;

The patch looks good. I'll add a comment saying "p2m not actually
initialized" here.

Reviewed-by: Stefano Stabellini 


> +if ( !p2m->domain )
> +return;
> +
>  while ( (pg = page_list_remove_head(>pages)) )
>  free_domheap_page(pg);
>  
> @@ -1230,6 +1233,8 @@ void p2m_teardown(struct domain *d)
>  p2m_free_vmid(d);
>  
>  radix_tree_destroy(>mem_access_settings, NULL);
> +
> +p2m->domain = NULL;
>  }
>  
>  int p2m_init(struct domain *d)
> @@ -1247,7 +1252,6 @@ int p2m_init(struct domain *d)
>  if ( rc != 0 )
>  return rc;
>  
> -p2m->domain = d;
>  p2m->max_mapped_gfn = _gfn(0);
>  p2m->lowest_mapped_gfn = _gfn(ULONG_MAX);
>  
> @@ -1276,6 +1280,13 @@ int p2m_init(struct domain *d)
>  for_each_possible_cpu(cpu)
> p2m->last_vcpu_ran[cpu] = INVALID_VCPU_ID;
>  
> +/*
> + * Besides getting a domain when we only have the p2m in hand,
> + * the back pointer to domain is also used in p2m_teardown()
> + * as an end-of-initialization indicator.
> + */
> +p2m->domain = d;
> +
>  return rc;
>  }
>  
> -- 
> 2.7.4
> 

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


Re: [Xen-devel] [PATCH v1 1/2] xen/arm: vgic: Check for vgic handler to be initialized before dereferencing it

2017-09-15 Thread Stefano Stabellini
On Mon, 28 Aug 2017, Oleksandr Tyshchenko wrote:
> From: Oleksandr Tyshchenko 
> 
> Since domain_vgic_free() can be called when the vgic_ops haven't been
> initialised yet, always check that d->arch.vgic.handler is not a null.
> 
> Signed-off-by: Oleksandr Tyshchenko 

There is a code style problem, but I'll fix on commit.

Signed-off-by: Stefano Stabellini 


> ---
>  xen/arch/arm/vgic.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
> index 7a4e3cd..6cf947c 100644
> --- a/xen/arch/arm/vgic.c
> +++ b/xen/arch/arm/vgic.c
> @@ -187,7 +187,8 @@ void domain_vgic_free(struct domain *d)
>  }
>  }
>  
> -d->arch.vgic.handler->domain_free(d);
> +if ( d->arch.vgic.handler )
> +   d->arch.vgic.handler->domain_free(d);
>  xfree(d->arch.vgic.shared_irqs);
>  xfree(d->arch.vgic.pending_irqs);
>  xfree(d->arch.vgic.allocated_irqs);
> -- 
> 2.7.4
> 

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


[Xen-devel] [seabios test] 113466: regressions - FAIL

2017-09-15 Thread osstest service owner
flight 113466 seabios real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113466/

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-i386-xl-qemuu-win7-amd64 16 guest-localmigrate/x10 fail REGR. vs. 
113452

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-xl-qemuu-win7-amd64 18 guest-start/win.repeat fail blocked in 
113452
 test-amd64-amd64-xl-qemuu-ws16-amd64 10 windows-installfail never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 13 guest-saverestore   fail never pass
 test-amd64-i386-xl-qemuu-win10-i386 10 windows-install fail never pass
 test-amd64-amd64-xl-qemuu-win10-i386 10 windows-installfail never pass

version targeted for testing:
 seabios  ec6cb17f89498bcd6123e50a0368a414e6e85d82
baseline version:
 seabios  1ef72ab2f89ae61dcdb3f01323bd0a7dc978c2b9

Last test of basis   113452  2017-09-14 19:47:09 Z1 days
Testing same since   113466  2017-09-15 07:06:10 Z0 days1 attempts


People who touched revisions under test:
  Aleksandr Bezzubikov 

jobs:
 build-amd64-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-i386   pass
 build-amd64-libvirt  pass
 build-i386-libvirt   pass
 build-amd64-pvopspass
 build-i386-pvops pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm   pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsmpass
 test-amd64-amd64-xl-qemuu-debianhvm-amd64-xsmpass
 test-amd64-i386-xl-qemuu-debianhvm-amd64-xsm pass
 test-amd64-amd64-qemuu-nested-amdfail
 test-amd64-i386-qemuu-rhel6hvm-amd   pass
 test-amd64-amd64-xl-qemuu-debianhvm-amd64pass
 test-amd64-i386-xl-qemuu-debianhvm-amd64 pass
 test-amd64-amd64-xl-qemuu-win7-amd64 fail
 test-amd64-i386-xl-qemuu-win7-amd64  fail
 test-amd64-amd64-xl-qemuu-ws16-amd64 fail
 test-amd64-i386-xl-qemuu-ws16-amd64  fail
 test-amd64-amd64-xl-qemuu-win10-i386 fail
 test-amd64-i386-xl-qemuu-win10-i386  fail
 test-amd64-amd64-qemuu-nested-intel  pass
 test-amd64-i386-qemuu-rhel6hvm-intel pass



sg-report-flight on osstest.test-lab.xenproject.org
logs: /home/logs/logs
images: /home/logs/images

Logs, config files, etc. are available at
http://logs.test-lab.xenproject.org/osstest/logs

Explanation of these reports, and of osstest in general, is at
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README.email;hb=master
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README;hb=master

Test harness code can be found at
http://xenbits.xen.org/gitweb?p=osstest.git;a=summary


Not pushing.


commit ec6cb17f89498bcd6123e50a0368a414e6e85d82
Author: Aleksandr Bezzubikov 
Date:   Fri Aug 18 02:33:21 2017 +0300

pci: enable RedHat PCI bridges to reserve additional resources on PCI init

In case of Red Hat Generic PCIE Root Port reserve additional buses
and/or IO/MEM/PREF space, which values are provided in a vendor-specific 
capability.

Signed-off-by: Aleksandr Bezzubikov 
Reviewed-by: Marcel Apfelbaum 

commit 4c1f7272b41df5ceec0f41c6c14ca4c68a8638ee
Author: Aleksandr Bezzubikov 
Date:   Fri Aug 18 02:33:20 2017 +0300

pci: add QEMU-specific PCI capability structure

On PCI init PCI bridge devices may need some
extra info about bus number to reserve, IO, memory and
prefetchable memory limits. QEMU can provide this
with special vendor-specific PCI capability.

This capability is intended to be used only
for Red Hat PCI bridges, i.e. QEMU cooperation.

Signed-off-by: Aleksandr Bezzubikov 
Reviewed-by: Marcel Apfelbaum 

commit 

Re: [Xen-devel] CONFIG_SCRUB_DEBUG=y + arm64 + livepatch = Xen BUG at page_alloc.c:738

2017-09-15 Thread Julien Grall

Hi,

On 15/09/2017 20:50, Konrad Rzeszutek Wilk wrote:

.snip..

(XEN) Loading dom0 DTB to 0x17e0-0x17e08265
(XEN) init_domheap_pages: 0xb87b1->0xb87bc
(XEN) init_heap_pages: 0xb87b1 -> 0xb87bc
(XEN) init_domheap_pages: 0xb88f1->0xb98ae
(XEN) init_heap_pages: 0xb88f1 -> 0xb98ae<- so the memory is from here

(XEN) Scrubbing Free RAM on 1 nodes using 8 CPUs
(XEN) Initial low memory virq threshold set at 0x4000 pages.
(XEN) Scrubbing Free RAM on 1 nodes using 8 CPUs


I expanded this a bit to include:

(XEN) Initial low memory virq threshold set at 0x4000 pages.
(XEN) NODE0 start=0x0 pages=579306, max_page=0xc
(XEN) NODE0:  #0  #1  #2  #3  #4  #5  #6  #7  (total=8)
(XEN) NODE0 start=0x0, per_cpu=72413, rem=2, end=0x8d6ea
   that is the end of 
memory, but
0xb98ae > 0x8d6ae.

end = min(node_start_pfn(i) + node_spanned_pages(i), max_page);
  0   0x8D6EA0xc


Oh:

/* XXX: implement NUMA support */
#define node_spanned_pages(nid) (total_pages)


If I understand correctly, this would be wrong here because the memory 
could be in multiple banks.


So, I think, what we would want to return here is bank[n]->end - 
bank[0]->start where n is the last bank.


Cheers,

--
Julien Grall

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


[Xen-devel] [qemu-mainline test] 113464: regressions - FAIL

2017-09-15 Thread osstest service owner
flight 113464 qemu-mainline real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113464/

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-amd64-xl-qemuu-win7-amd64 16 guest-localmigrate/x10 fail REGR. vs. 
113302
 test-amd64-i386-xl-qemuu-win7-amd64 16 guest-localmigrate/x10 fail REGR. vs. 
113302
 test-armhf-armhf-xl-credit2 16 guest-start/debian.repeat fail REGR. vs. 113302

Tests which did not succeed, but are not blocking:
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail  like 113302
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail  like 113302
 test-amd64-amd64-xl-rtds 10 debian-install   fail  like 113302
 test-armhf-armhf-libvirt-xsm 14 saverestore-support-checkfail  like 113302
 test-amd64-amd64-xl-qemuu-ws16-amd64 10 windows-installfail never pass
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qcow2 12 migrate-support-checkfail  never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-armhf-armhf-xl-multivcpu 13 migrate-support-checkfail  never pass
 test-armhf-armhf-xl-multivcpu 14 saverestore-support-checkfail  never pass
 test-armhf-armhf-xl-cubietruck 13 migrate-support-checkfail never pass
 test-armhf-armhf-xl-cubietruck 14 saverestore-support-checkfail never pass
 test-armhf-armhf-xl-credit2  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit2  14 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 13 guest-saverestore   fail never pass
 test-armhf-armhf-xl-rtds 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-libvirt-raw 12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  13 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-win10-i386 10 windows-install fail never pass
 test-amd64-amd64-xl-qemuu-win10-i386 10 windows-installfail never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-libvirt-xsm 13 migrate-support-checkfail   never pass

version targeted for testing:
 qemuu3dabde1128b671f36ac6cb36b97b273139964420
baseline version:
 qemuua6e8c1dacfd37d34542e33600dcc50b7683b735a

Last test of basis   113302  2017-09-11 10:18:16 Z4 days
Failing since113345  2017-09-12 00:21:07 Z3 days5 attempts
Testing same since   113464  2017-09-15 04:17:55 Z0 days1 attempts


People who touched revisions under test:
  Alexander Graf 
  Alexey Kardashevskiy 
  Cornelia Huck 
  David Gibson 
  Dr. David Alan Gilbert 
  Eduardo Otubo 
  Eric Auger 
  Gerd Hoffmann 
  Laurent Vivier 
  Mark Cave-Ayland 
  Mohammed Gamal 
  Peter Maydell 
  Philippe Mathieu-Daudé 
  Thomas Huth 
  Vadim Galitsyn 
  Vasilis Liaskovitis 

jobs:
 build-amd64-xsm  pass
 build-armhf-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-armhf  pass
 build-i386

Re: [Xen-devel] CONFIG_SCRUB_DEBUG=y + arm64 + livepatch = Xen BUG at page_alloc.c:738

2017-09-15 Thread Konrad Rzeszutek Wilk
.snip..
> (XEN) Loading dom0 DTB to 0x17e0-0x17e08265
> (XEN) init_domheap_pages: 0xb87b1->0xb87bc
> (XEN) init_heap_pages: 0xb87b1 -> 0xb87bc
> (XEN) init_domheap_pages: 0xb88f1->0xb98ae
> (XEN) init_heap_pages: 0xb88f1 -> 0xb98ae <- so the memory is from here
> 
> (XEN) Scrubbing Free RAM on 1 nodes using 8 CPUs
> (XEN) Initial low memory virq threshold set at 0x4000 pages.
> (XEN) Scrubbing Free RAM on 1 nodes using 8 CPUs

I expanded this a bit to include:

(XEN) Initial low memory virq threshold set at 0x4000 pages.
(XEN) NODE0 start=0x0 pages=579306, max_page=0xc
(XEN) NODE0:  #0  #1  #2  #3  #4  #5  #6  #7  (total=8) 
(XEN) NODE0 start=0x0, per_cpu=72413, rem=2, end=0x8d6ea
   that is the end of 
memory, but
0xb98ae > 0x8d6ae.

end = min(node_start_pfn(i) + node_spanned_pages(i), max_page); 
  0   0x8D6EA0xc


Oh:

/* XXX: implement NUMA support */
#define node_spanned_pages(nid) (total_pages)



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


[Xen-devel] [libvirt test] 113465: tolerable all pass - PUSHED

2017-09-15 Thread osstest service owner
flight 113465 libvirt real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113465/

Failures :-/ but no regressions.

Tests which did not succeed, but are not blocking:
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail  like 113434
 test-armhf-armhf-libvirt-xsm 14 saverestore-support-checkfail  like 113434
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail  like 113434
 test-amd64-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qcow2 12 migrate-support-checkfail  never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-armhf-armhf-libvirt-raw 12 migrate-support-checkfail   never pass

version targeted for testing:
 libvirt  a823d0a62e858a62a585a78599b6d859c5b4dcac
baseline version:
 libvirt  23706c1708458d13be594e0424f46cab4e2f8b17

Last test of basis   113434  2017-09-14 04:20:12 Z1 days
Testing same since   113465  2017-09-15 04:27:36 Z0 days1 attempts


People who touched revisions under test:
  Andrea Bolognani 
  Cole Robinson 
  John Ferlan 
  Peter Krempa 

jobs:
 build-amd64-xsm  pass
 build-armhf-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-armhf  pass
 build-i386   pass
 build-amd64-libvirt  pass
 build-armhf-libvirt  pass
 build-i386-libvirt   pass
 build-amd64-pvopspass
 build-armhf-pvopspass
 build-i386-pvops pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm   pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsmpass
 test-amd64-amd64-libvirt-xsm pass
 test-armhf-armhf-libvirt-xsm pass
 test-amd64-i386-libvirt-xsm  pass
 test-amd64-amd64-libvirt pass
 test-armhf-armhf-libvirt pass
 test-amd64-i386-libvirt  pass
 test-amd64-amd64-libvirt-pairpass
 test-amd64-i386-libvirt-pair pass
 test-amd64-i386-libvirt-qcow2pass
 test-armhf-armhf-libvirt-raw pass
 test-amd64-amd64-libvirt-vhd pass



sg-report-flight on osstest.test-lab.xenproject.org
logs: /home/logs/logs
images: /home/logs/images

Logs, config files, etc. are available at
http://logs.test-lab.xenproject.org/osstest/logs

Explanation of these reports, and of osstest in general, is at
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README.email;hb=master
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README;hb=master

Test harness code can be found at
http://xenbits.xen.org/gitweb?p=osstest.git;a=summary


Pushing revision :

+ branch=libvirt
+ revision=a823d0a62e858a62a585a78599b6d859c5b4dcac
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.
 PERLLIB=.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x '!=' x/home/osstest/repos/lock ']'
++ OSSTEST_REPOS_LOCK_LOCKED=/home/osstest/repos/lock
++ exec with-lock-ex -w /home/osstest/repos/lock ./ap-push libvirt 

[Xen-devel] [PATCH] xen: x86: mark xen_find_pt_base as __init

2017-09-15 Thread Arnd Bergmann
gcc-4.6 causes a harmless link-time warning:

WARNING: vmlinux.o(.text.unlikely+0x48e): Section mismatch in reference from 
the function xen_find_pt_base() to the function .init.text:m2p()
The function xen_find_pt_base() references
the function __init m2p().
This is often because xen_find_pt_base lacks a __init
annotation or the annotation of m2p is wrong.

Newer compilers inline this function, so it never shows up, but marking
it __init is the right way to avoid the warning.

Fixes: 70e61199559a ("xen: move p2m list if conflicting with e820 map")
Signed-off-by: Arnd Bergmann 
---
 arch/x86/xen/mmu_pv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 509f560bd0c6..7330cb3b2283 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -2220,7 +2220,7 @@ static void __init xen_write_cr3_init(unsigned long cr3)
  * not the first page table in the page table pool.
  * Iterate through the initial page tables to find the real page table base.
  */
-static phys_addr_t xen_find_pt_base(pmd_t *pmd)
+static phys_addr_t __init xen_find_pt_base(pmd_t *pmd)
 {
phys_addr_t pt_base, paddr;
unsigned pmdidx;
-- 
2.9.0


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


Re: [Xen-devel] CONFIG_SCRUB_DEBUG=y + arm64 + livepatch = Xen BUG at page_alloc.c:738

2017-09-15 Thread Boris Ostrovsky

> So in other words, it looks like scrub_heap_pages is somehow not
> including this MFN.

That would be a problem. How does NUMA info look like?

-boris

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


[Xen-devel] [PATCH 21/22] libxl: dm_restrict: Support uid range user

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 docs/man/xl.cfg.pod.5.in | 11 ++-
 tools/libxl/libxl_dm.c   | 32 
 tools/libxl/libxl_internal.h |  1 +
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
index 166ad4e..1c8d52d 100644
--- a/docs/man/xl.cfg.pod.5.in
+++ b/docs/man/xl.cfg.pod.5.in
@@ -2091,7 +2091,16 @@ For example, cdrom insert will fail.
 =item
 
 You must create user(s) for qemu to run as.
-Currently, you should either create
+
+Ideally, set aside a range of 32752 uids
+(from N to N+32751)
+and create a user
+whose name is B
+and whose uid is N
+and whose gid is a plain unprivileged gid.
+libxl will use one such user for each domid.
+
+Alternatively, either create
 B
 for every $domid from 1 to 32751 inclusive,
 or
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 10da40c..52feac0 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static const char *libxl_tapif_script(libxl__gc *gc)
 {
@@ -752,6 +753,9 @@ libxl__detect_gfx_passthru_kind(libxl__gc *gc,
  *  userlookup_helper_getpwnam(libxl__gc*, const char *user,
  * struct passwd **pwd_r);
  *
+ *  userlookup_helper_getpwuid(libxl__gc*, uid_t uid,
+ * struct passwd **pwd_r);
+ *
  *  returns 1 if the user was found, 0 if it was not, -1 on error
  */
 #define DEFINE_USERLOOKUP_HELPER(NAME,SPEC_TYPE,STRUCTNAME,SYSCONF)  \
@@ -790,6 +794,7 @@ libxl__detect_gfx_passthru_kind(libxl__gc *gc,
 }
 
 DEFINE_USERLOOKUP_HELPER(getpwnam, const char*, passwd, _SC_GETPW_R_SIZE_MAX);
+DEFINE_USERLOOKUP_HELPER(getpwuid, uid_t,   passwd, _SC_GETPW_R_SIZE_MAX);
 
 /* colo mode */
 enum {
@@ -950,6 +955,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
 uint64_t ram_size;
 const char *path, *chardev;
 char *user = NULL;
+struct passwd *user_base;
 
 dm_args = flexarray_make(gc, 16, 1);
 dm_envs = flexarray_make(gc, 16, 1);
@@ -1658,6 +1664,32 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
 if (ret > 0)
 goto end_search;
 
+ret = userlookup_helper_getpwnam(gc, LIBXL_QEMU_USER_RANGE_BASE,
+ _base);
+if (ret < 0)
+return ret;
+if (ret > 0) {
+struct passwd *user_clash;
+uid_t intended_uid = user_base->pw_uid + guest_domid;
+ret = userlookup_helper_getpwuid(gc, intended_uid, _clash);
+if (ret < 0)
+return ret;
+if (ret > 0) {
+LOGD(ERROR, guest_domid,
+ "wanted to use uid %ld (%s + %d) but that is user %s !",
+ (long)intended_uid, LIBXL_QEMU_USER_RANGE_BASE,
+ guest_domid, user_clash->pw_name);
+return ERROR_FAIL;
+}
+LOGD(DEBUG, guest_domid, "using uid %ld", (long)intended_uid);
+flexarray_append(dm_args, "-runasid");
+flexarray_append(dm_args,
+ GCSPRINTF("%ld.%ld", (long)intended_uid,
+   (long)user_base->pw_gid));
+user = NULL; /* we have taken care of it */
+goto end_search;
+}
+
 user = LIBXL_QEMU_USER_SHARED;
 ret = userlookup_helper_getpwnam(gc, user, 0);
 if (ret < 0)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 4f2f433..761501e 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -4316,6 +4316,7 @@ _hidden int libxl__read_sysfs_file_contents(libxl__gc *gc,
 #define LIBXL_QEMU_USER_PREFIX "xen-qemuuser"
 #define LIBXL_QEMU_USER_BASE   LIBXL_QEMU_USER_PREFIX"-domid"
 #define LIBXL_QEMU_USER_SHARED LIBXL_QEMU_USER_PREFIX"-shared"
+#define LIBXL_QEMU_USER_RANGE_BASE LIBXL_QEMU_USER_PREFIX"-range-base"
 
 static inline bool libxl__acpi_defbool_val(const libxl_domain_build_info 
*b_info)
 {
-- 
2.1.4


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


[Xen-devel] [PATCH 15/22] xentoolcore_restrict_all: "Implement" for xenstore

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/Rules.mk|  2 +-
 tools/xenstore/Makefile   |  7 ---
 tools/xenstore/xenstore.pc.in |  2 +-
 tools/xenstore/xs.c   | 14 ++
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 3239e76..be92f0a 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -146,7 +146,7 @@ LDLIBS_libxenguest = $(SHDEPS_libxenguest) 
$(XEN_LIBXC)/libxenguest$(libextensio
 SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC)
 
 CFLAGS_libxenstore = -I$(XEN_XENSTORE)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenstore =
+SHDEPS_libxenstore = $(SHLIB_libxentoolcore)
 LDLIBS_libxenstore = $(SHDEPS_libxenstore) 
$(XEN_XENSTORE)/libxenstore$(libextension)
 SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_XENSTORE)
 
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index ff428e2..2b99d2b 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -11,6 +11,7 @@ CFLAGS += -include $(XEN_ROOT)/tools/config.h
 CFLAGS += -I./include
 CFLAGS += $(CFLAGS_libxenevtchn)
 CFLAGS += $(CFLAGS_libxenctrl)
+CFLAGS += $(CFLAGS_libxentoolcore)
 CFLAGS += -DXEN_LIB_STORED="\"$(XEN_LIB_STORED)\""
 CFLAGS += -DXEN_RUN_STORED="\"$(XEN_RUN_STORED)\""
 
@@ -85,10 +86,10 @@ $(CLIENTS): xenstore
ln -f xenstore $@
 
 xenstore: xenstore_client.o $(LIBXENSTORE)
-   $(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(SOCKET_LIBS) -o $@ 
$(APPEND_LDFLAGS)
+   $(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) 
$(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
 
 xenstore-control: xenstore_control.o $(LIBXENSTORE)
-   $(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(SOCKET_LIBS) -o $@ 
$(APPEND_LDFLAGS)
+   $(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) 
$(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
 
 xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
$(CC) $^ $(LDFLAGS) -o $@ $(APPEND_LDFLAGS)
@@ -101,7 +102,7 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR)
 xs.opic: CFLAGS += -DUSE_PTHREAD
 
 libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
-   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(SOCKET_LIBS) 
$(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) 
$(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 libxenstore.a: xs.o xs_lib.o
$(AR) rcs $@ $^
diff --git a/tools/xenstore/xenstore.pc.in b/tools/xenstore/xenstore.pc.in
index 45dc6b0..6fd72a1 100644
--- a/tools/xenstore/xenstore.pc.in
+++ b/tools/xenstore/xenstore.pc.in
@@ -7,4 +7,4 @@ Description: The Xenstore library for Xen hypervisor
 Version: @@version@@
 Cflags: -I${includedir} @@cflagslocal@@
 Libs: @@libsflag@@${libdir} -lxenstore
-Requires.private: xenevtchn,xencontrol,xengnttab
+Requires.private: xenevtchn,xencontrol,xengnttab,xentoolcore
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 7f85bb2..ae4b878 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -35,6 +35,8 @@
 #include "list.h"
 #include "utils.h"
 
+#include 
+
 struct xs_stored_msg {
struct list_head list;
struct xsd_sockmsg hdr;
@@ -48,6 +50,7 @@ struct xs_stored_msg {
 struct xs_handle {
/* Communications channel to xenstore daemon. */
int fd;
+   Xentoolcore__Active_Handle tc_ah; /* for restrict */
 
/*
  * A read thread which pulls messages off the comms channel and
@@ -122,6 +125,7 @@ static void *read_thread(void *arg);
 
 struct xs_handle {
int fd;
+   Xentoolcore__Active_Handle tc_ah; /* for restrict */
struct list_head reply_list;
struct list_head watch_list;
/* Clients can select() on this pipe to wait for a watch to fire. */
@@ -219,6 +223,11 @@ static int get_dev(const char *connect_to)
return open(connect_to, O_RDWR);
 }
 
+static int all_restrict_cb(Xentoolcore__Active_Handle *ah, uint32_t domid) {
+struct xs_handle *h = CONTAINER_OF(ah, *h, tc_ah);
+return xentoolcore__restrict_by_dup2_null(h->fd);
+}
+
 static struct xs_handle *get_handle(const char *connect_to)
 {
struct stat buf;
@@ -232,6 +241,9 @@ static struct xs_handle *get_handle(const char *connect_to)
memset(h, 0, sizeof(*h));
h->fd = -1;
 
+   h->tc_ah.restrict_callback = all_restrict_cb;
+   xentoolcore__register_active_handle(>tc_ah);
+
if (stat(connect_to, ) != 0)
goto err;
 
@@ -269,6 +281,7 @@ err:
if (h) {
if (h->fd >= 0)
close(h->fd);
+   xentoolcore__deregister_active_handle(>tc_ah);
}
free(h);
 
@@ -330,6 +343,7 @@ static void close_fds_free(struct xs_handle *h) {
}
 
 close(h->fd);
+   

[Xen-devel] [PATCH 05/22] libxl: #include "xentoolcore_internal.h"

2017-09-15 Thread Ian Jackson
We are going to want to move something here.

Signed-off-by: Ian Jackson 
---
 tools/libxl/Makefile | 11 ++-
 tools/libxl/libxl_internal.h |  2 ++
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index aee0a4c..2c2b047 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -20,12 +20,13 @@ LIBUUID_LIBS += -luuid
 endif
 
 LIBXL_LIBS =
-LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) 
$(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) 
$(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
+LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) 
$(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) 
$(LDLIBS_libblktapctl) $(LDLIBS_libxentoolcore) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
 ifeq ($(CONFIG_LIBNL),y)
 LIBXL_LIBS += $(LIBNL3_LIBS)
 endif
 
 CFLAGS_LIBXL += $(CFLAGS_libxentoollog)
+CFLAGS_LIBXL += $(CFLAGS_libxentoolcore)
 CFLAGS_LIBXL += $(CFLAGS_libxenevtchn)
 CFLAGS_LIBXL += $(CFLAGS_libxenctrl)
 CFLAGS_LIBXL += $(CFLAGS_libxenguest)
@@ -178,7 +179,7 @@ LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \
libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o
 $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 
-$(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS += $(CFLAGS_libxentoollog)
+$(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS += $(CFLAGS_libxentoollog) 
$(CFLAGS_libxentoolcore)
 
 CLIENTS = testidl libxl-save-helper
 
@@ -301,13 +302,13 @@ libxlutil.a: $(LIBXLU_OBJS)
$(AR) rcs libxlutil.a $^
 
 test_%: test_%.o test_common.o libxlutil.so libxenlight_test.so
-   $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, 
$(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, 
$(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl 
$(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
-   $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) 
$(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) 
$(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) 
$(APPEND_LDFLAGS)
 
 testidl: testidl.o libxlutil.so libxenlight.so
-   $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) 
$(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) 
$(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 7247509..04be10a 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -19,6 +19,8 @@
 
 #include "libxl_osdeps.h" /* must come before any other headers */
 
+#include "xentoolcore_internal.h"
+
 #include "libxl_sr_stream_format.h"
 
 #include 
-- 
2.1.4


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


[Xen-devel] [PATCH 00/22] Provide some actual restriction of qemu

2017-09-15 Thread Ian Jackson
With this series, it is possible to run qemu in a way that I think
really does not have global privilege any more>

I have verified that it runs as a non-root user.  I have checked all
of its fds and they are either privcmd (which I have arranged to
neuter), or /dev/null, or harmless sockets and pipes, or evtchn.

Unfortunately this needs a new "xentoolcore" library, which all the
existing libraries register with so that the restrict call is
effective.

Also there are a number of lacunae.  In particular:

 - if we are not using a shared uid, we should kill all processes
   belonging to the chosen uid both at domain start time and at
   domain shutdown time

 - we should have qemu chroot

 - some audit and/or review of the resulting situation would be
   good before we offer security support for the new boundary

 - use of rlimits may be useful to mitigate the risk of DOS
   by a compromised qemu

 - cdrom insert would have to be done via fd passing and is not
   yet implemented

 - we need to think about what happens during migration (currently
   privileges are dropped very late, certainly after the receiving
   qemu has read the migration stream from its
   now-supposedly-untrusted peer)

The series depends for its functionality on a still-RFC qemu series I
have just posted, but should be harmless without the new qemu patches.

Thanks,
Ian.

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


[Xen-devel] [PATCH 19/22] libxl: libxl__dm_runas_helper: return pwd

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/libxl/libxl_dm.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 831c397..3c4ef2b 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -749,7 +749,8 @@ libxl__detect_gfx_passthru_kind(libxl__gc *gc,
 }
 
 /* return 1 if the user was found, 0 if it was not, -1 on error */
-static int libxl__dm_runas_helper(libxl__gc *gc, const char *username)
+static int libxl__dm_runas_helper(libxl__gc *gc, const char *username,
+   struct passwd **pwd_r)
 {
 struct passwd pwd, *user = NULL;
 char *buf = NULL;
@@ -773,8 +774,10 @@ static int libxl__dm_runas_helper(libxl__gc *gc, const 
char *username)
 }
 if (ret != 0)
 return ERROR_FAIL;
-if (user != NULL)
+if (user != NULL) {
+if (pwd_r) *pwd_r = pwd;
 return 1;
+}
 return 0;
 }
 }
@@ -1640,14 +1643,14 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
 }
 
 user = GCSPRINTF("%s%d", LIBXL_QEMU_USER_BASE, guest_domid);
-ret = libxl__dm_runas_helper(gc, user);
+ret = libxl__dm_runas_helper(gc, user, 0);
 if (ret < 0)
 return ret;
 if (ret > 0)
 goto end_search;
 
 user = LIBXL_QEMU_USER_SHARED;
-ret = libxl__dm_runas_helper(gc, user);
+ret = libxl__dm_runas_helper(gc, user, 0);
 if (ret < 0)
 return ret;
 if (ret > 0) {
-- 
2.1.4


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


[Xen-devel] [PATCH 18/22] libxl: Rationalise calculation of user to run qemu as

2017-09-15 Thread Ian Jackson
If the config specifies a user we use that.  Otherwise:

When we are not restricting qemu, there is very little point running
it as a different user than root.  Indeed, previously, creating the
"magic" users would cause qemu to become slightly dysfunctional (for
example, you can't insert a cd that the qemu user can't read).
So, in that case, default to running it as root.

Conversely, if restriction is requested, we must insist on running
qemu as a non-root user.

Sadly the admin is still required to create 2^16-epsilon users!

Signed-off-by: Ian Jackson 
---
 docs/man/xl.cfg.pod.5.in |  2 --
 tools/libxl/libxl_dm.c   | 13 ++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
index e3a73bc..166ad4e 100644
--- a/docs/man/xl.cfg.pod.5.in
+++ b/docs/man/xl.cfg.pod.5.in
@@ -2098,8 +2098,6 @@ or
 B
 (in which case different guests will not
 be protected against each other).
-And if you do not create the user,
-the restriction request will be silently ineffective!
 
 =item
 
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 472a42b..831c397 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1633,6 +1633,12 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
 goto end_search;
 }
 
+if (!libxl_defbool_val(b_info->u.hvm.dm_restrict)) {
+LOGD(DEBUG, guest_domid,
+ "dm_restrict disabled, starting QEMU as root");
+goto end_search;
+}
+
 user = GCSPRINTF("%s%d", LIBXL_QEMU_USER_BASE, guest_domid);
 ret = libxl__dm_runas_helper(gc, user);
 if (ret < 0)
@@ -1650,9 +1656,10 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
 goto end_search;
 }
 
-user = NULL;
-LOGD(DEBUG, guest_domid, "Could not find user %s, starting QEMU as 
root",
- LIBXL_QEMU_USER_SHARED);
+LOGD(ERROR, guest_domid,
+ "Could not find user %s%d or %s, cannot restrict",
+ LIBXL_QEMU_USER_BASE, guest_domid, LIBXL_QEMU_USER_SHARED);
+return ERROR_INVAL;
 
 end_search:
 if (user != NULL && strcmp(user, "root")) {
-- 
2.1.4


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


[Xen-devel] [PATCH 09/22] xentoolcore_restrict: Break out xentoolcore__restrict_by_dup2_null

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/libs/call/core.c | 30 +-
 tools/libs/toolcore/handlereg.c| 26 +++
 tools/libs/toolcore/include/xentoolcore_internal.h | 12 +
 tools/libs/toolcore/libxentoolcore.map |  1 +
 4 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c
index 11ecc87..d6ce73d 100644
--- a/tools/libs/call/core.c
+++ b/tools/libs/call/core.c
@@ -15,39 +15,11 @@
 
 #include 
 
-#include 
-#include 
-#include 
-#include 
-
 #include "private.h"
 
 static int all_restrict_cb(Xentoolcore__Active_Handle *ah, uint32_t domid) {
 xencall_handle *xcall = CONTAINER_OF(ah, *xcall, tc_ah);
-int nullfd = -1, r;
-
-if (xcall->fd < 0)
-/* just in case */
-return 0;
-
-/*
- * We don't implement a restrict function.  We neuter the fd by
- * dup'ing /dev/null onto it.  This is better than closing it,
- * because it does not involve locking against concurrent uses
- * of xencall in other threads.
- */
-nullfd = open("/dev/null",O_RDONLY);
-if (nullfd < 0) goto err;
-
-r = dup2(nullfd, xcall->fd);
-if (r < 0) goto err;
-
-close(nullfd);
-return 0;
-
-err:
-if (nullfd >= 0) close(nullfd);
-return -1;
+return xentoolcore__restrict_by_dup2_null(xcall->fd);
 }
 
 xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags)
diff --git a/tools/libs/toolcore/handlereg.c b/tools/libs/toolcore/handlereg.c
index cfd01a2..56d8b2d 100644
--- a/tools/libs/toolcore/handlereg.c
+++ b/tools/libs/toolcore/handlereg.c
@@ -22,6 +22,11 @@
 
 #include "xentoolcore_internal.h"
 
+#include 
+#include 
+#include 
+#include 
+
 #include 
 #include 
 
@@ -67,6 +72,27 @@ int xentoolcore_restrict_all(uint32_t domid) {
 return r;
 }
 
+int xentoolcore__restrict_by_dup2_null(int fd) {
+int nullfd = -1, r;
+
+if (fd < 0)
+/* just in case */
+return 0;
+
+nullfd = open("/dev/null",O_RDONLY);
+if (nullfd < 0) goto err;
+
+r = dup2(nullfd, fd);
+if (r < 0) goto err;
+
+close(nullfd);
+return 0;
+
+err:
+if (nullfd >= 0) close(nullfd);
+return -1;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libs/toolcore/include/xentoolcore_internal.h 
b/tools/libs/toolcore/include/xentoolcore_internal.h
index 27497d6..7e96a48 100644
--- a/tools/libs/toolcore/include/xentoolcore_internal.h
+++ b/tools/libs/toolcore/include/xentoolcore_internal.h
@@ -91,6 +91,18 @@ struct Xentoolcore__Active_Handle {
 void xentoolcore__register_active_handle(Xentoolcore__Active_Handle*);
 void xentoolcore__deregister_active_handle(Xentoolcore__Active_Handle*);
 
+/*
+ * Utility function for use in restrict_callback in libraries whose
+ * handles don't have a useful restrict function.  We neuter the fd by
+ * dup'ing /dev/null onto it.  This is better than closing it, because
+ * it does not involve locking against concurrent uses of in other
+ * threads.
+ *
+ * Returns the value that restrict_callback should return.
+ * fd may be < 0.
+ */
+int xentoolcore__restrict_by_dup2_null(int fd);
+
 /* -- convenient stuff -- */
 
 /*
diff --git a/tools/libs/toolcore/libxentoolcore.map 
b/tools/libs/toolcore/libxentoolcore.map
index eb5d251..0b7d925 100644
--- a/tools/libs/toolcore/libxentoolcore.map
+++ b/tools/libs/toolcore/libxentoolcore.map
@@ -3,5 +3,6 @@ VERS_1.0 {
xentoolcore_restrict_all;
xentoolcore__register_active_handle;
xentoolcore__deregister_active_handle;
+   xentoolcore__restrict_by_dup2_null;
local: *; /* Do not expose anything by default */
 };
-- 
2.1.4


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


[Xen-devel] [PATCH 17/22] xl, libxl: Provide dm_restrict

2017-09-15 Thread Ian Jackson
This functionality is still quite imperfect, but it will be useful in
certain restricted use cases.

Signed-off-by: Ian Jackson 
---
 docs/man/xl.cfg.pod.5.in| 86 +
 tools/libxl/libxl_create.c  |  1 +
 tools/libxl/libxl_dm.c  |  9 +
 tools/libxl/libxl_types.idl |  1 +
 tools/xl/xl_parse.c |  3 ++
 5 files changed, 100 insertions(+)

diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in
index 79cb2ea..e3a73bc 100644
--- a/docs/man/xl.cfg.pod.5.in
+++ b/docs/man/xl.cfg.pod.5.in
@@ -2045,6 +2045,92 @@ specified, enabling the use of XenServer PV drivers in 
the guest.
 This parameter only takes effect when device_model_version=qemu-xen.
 See B for more information.
 
+=item 

[Xen-devel] [PATCH 04/22] tools: qemu-xen build: prepare to link against xentoolcore

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/Makefile b/tools/Makefile
index 11ad42c..03d326a 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -244,6 +244,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
-DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \
-DXC_WANT_COMPAT_DEVICEMODEL_API=1 \
-I$(XEN_ROOT)/tools/include \
+   -I$(XEN_ROOT)/tools/libs/toolcore/include \
-I$(XEN_ROOT)/tools/libs/toollog/include \
-I$(XEN_ROOT)/tools/libs/evtchn/include \
-I$(XEN_ROOT)/tools/libs/gnttab/include \
@@ -255,10 +256,12 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
$(EXTRA_CFLAGS_QEMU_XEN)" \
--extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
-L$(XEN_ROOT)/tools/xenstore \
+   -L$(XEN_ROOT)/tools/libs/toolcore \
-L$(XEN_ROOT)/tools/libs/evtchn \
-L$(XEN_ROOT)/tools/libs/gnttab \
-L$(XEN_ROOT)/tools/libs/foreignmemory \
-L$(XEN_ROOT)/tools/libs/devicemodel \
+   -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toolcore \
-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
-- 
2.1.4


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


[Xen-devel] [PATCH 14/22] tools/xenstore: get_handle: Allocate struct before opening fd

2017-09-15 Thread Ian Jackson
Now we can also abolish the temporary local variable "fd" and simply
use h->fd.

This ordering is necessary to be able to call
xentoolcore__register_active_handle sensibly.

Signed-off-by: Ian Jackson 
---
 tools/xenstore/xs.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 65cba86..7f85bb2 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -223,27 +223,26 @@ static struct xs_handle *get_handle(const char 
*connect_to)
 {
struct stat buf;
struct xs_handle *h = NULL;
-   int fd = -1, saved_errno;
+   int saved_errno;
+
+   h = malloc(sizeof(*h));
+   if (h == NULL)
+   goto err;
+
+   memset(h, 0, sizeof(*h));
+   h->fd = -1;
 
if (stat(connect_to, ) != 0)
goto err;
 
if (S_ISSOCK(buf.st_mode))
-   fd = get_socket(connect_to);
+   h->fd = get_socket(connect_to);
else
-   fd = get_dev(connect_to);
+   h->fd = get_dev(connect_to);
 
-   if (fd == -1)
+   if (h->fd == -1)
goto err;
 
-   h = malloc(sizeof(*h));
-   if (h == NULL)
-   goto err;
-
-   memset(h, 0, sizeof(*h));
-
-   h->fd = fd;
-
INIT_LIST_HEAD(>reply_list);
INIT_LIST_HEAD(>watch_list);
 
@@ -267,7 +266,10 @@ static struct xs_handle *get_handle(const char *connect_to)
 err:
saved_errno = errno;
 
-   if (fd >= 0) close(fd);
+   if (h) {
+   if (h->fd >= 0)
+   close(h->fd);
+   }
free(h);
 
errno = saved_errno;
-- 
2.1.4


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


[Xen-devel] [PATCH 12/22] xentoolcore_restrict_all: "Implement" for xengnttab

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/Rules.mk|  2 +-
 tools/libs/gnttab/Makefile|  4 ++--
 tools/libs/gnttab/gnttab_core.c   | 10 ++
 tools/libs/gnttab/private.h   |  2 ++
 tools/libs/gnttab/xengnttab.pc.in |  2 +-
 5 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 7dd126a..3239e76 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -114,7 +114,7 @@ LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) 
$(XEN_LIBXENEVTCHN)/libxenevtchn$(l
 SHLIB_libxenevtchn  = $(SHDEPS_libxenevtchn) 
-Wl,-rpath-link=$(XEN_LIBXENEVTCHN)
 
 CFLAGS_libxengnttab = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude)
-SHDEPS_libxengnttab = $(SHLIB_libxentoollog)
+SHDEPS_libxengnttab = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore)
 LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) 
$(XEN_LIBXENGNTTAB)/libxengnttab$(libextension)
 SHLIB_libxengnttab  = $(SHDEPS_libxengnttab) 
-Wl,-rpath-link=$(XEN_LIBXENGNTTAB)
 
diff --git a/tools/libs/gnttab/Makefile b/tools/libs/gnttab/Makefile
index afb924f..dcfe686 100644
--- a/tools/libs/gnttab/Makefile
+++ b/tools/libs/gnttab/Makefile
@@ -7,7 +7,7 @@ SHLIB_LDFLAGS += -Wl,--version-script=libxengnttab.map
 
 CFLAGS   += -Werror -Wmissing-prototypes
 CFLAGS   += -I./include $(CFLAGS_xeninclude)
-CFLAGS   += $(CFLAGS_libxentoollog)
+CFLAGS   += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore)
 
 SRCS-GNTTAB+= gnttab_core.c
 SRCS-GNTSHR+= gntshr_core.c
@@ -64,7 +64,7 @@ libxengnttab.so.$(MAJOR): libxengnttab.so.$(MAJOR).$(MINOR)
$(SYMLINK_SHLIB) $< $@
 
 libxengnttab.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxengnttab.map
-   $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxengnttab.so.$(MAJOR) 
$(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxengnttab.so.$(MAJOR) 
$(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS_libxentoollog) 
$(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: build
diff --git a/tools/libs/gnttab/gnttab_core.c b/tools/libs/gnttab/gnttab_core.c
index 968c833..bc88110 100644
--- a/tools/libs/gnttab/gnttab_core.c
+++ b/tools/libs/gnttab/gnttab_core.c
@@ -22,6 +22,11 @@
 
 #include "private.h"
 
+static int all_restrict_cb(Xentoolcore__Active_Handle *ah, uint32_t domid) {
+xengnttab_handle *xgt = CONTAINER_OF(ah, *xgt, tc_ah);
+return xentoolcore__restrict_by_dup2_null(xgt->fd);
+}
+
 xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned 
open_flags)
 {
 xengnttab_handle *xgt = malloc(sizeof(*xgt));
@@ -33,6 +38,9 @@ xengnttab_handle *xengnttab_open(xentoollog_logger *logger, 
unsigned open_flags)
 xgt->logger = logger;
 xgt->logger_tofree  = NULL;
 
+xgt->tc_ah.restrict_callback = all_restrict_cb;
+xentoolcore__register_active_handle(>tc_ah);
+
 if (!xgt->logger) {
 xgt->logger = xgt->logger_tofree =
 (xentoollog_logger*)
@@ -47,6 +55,7 @@ xengnttab_handle *xengnttab_open(xentoollog_logger *logger, 
unsigned open_flags)
 
 err:
 osdep_gnttab_close(xgt);
+xentoolcore__deregister_active_handle(>tc_ah);
 xtl_logger_destroy(xgt->logger_tofree);
 free(xgt);
 return NULL;
@@ -60,6 +69,7 @@ int xengnttab_close(xengnttab_handle *xgt)
 return 0;
 
 rc = osdep_gnttab_close(xgt);
+xentoolcore__deregister_active_handle(>tc_ah);
 xtl_logger_destroy(xgt->logger_tofree);
 free(xgt);
 return rc;
diff --git a/tools/libs/gnttab/private.h b/tools/libs/gnttab/private.h
index 3ce4205..ed8df40 100644
--- a/tools/libs/gnttab/private.h
+++ b/tools/libs/gnttab/private.h
@@ -2,6 +2,7 @@
 #define XENGNTTAB_PRIVATE_H
 
 #include 
+#include 
 #include 
 
 /* Set of macros/defines used by both Linux and FreeBSD */
@@ -13,6 +14,7 @@
 struct xengntdev_handle {
 xentoollog_logger *logger, *logger_tofree;
 int fd;
+Xentoolcore__Active_Handle tc_ah;
 };
 
 int osdep_gnttab_open(xengnttab_handle *xgt);
diff --git a/tools/libs/gnttab/xengnttab.pc.in 
b/tools/libs/gnttab/xengnttab.pc.in
index 51aad22..4c3beed 100644
--- a/tools/libs/gnttab/xengnttab.pc.in
+++ b/tools/libs/gnttab/xengnttab.pc.in
@@ -7,4 +7,4 @@ Description: The Xengnttab library for Xen hypervisor
 Version: @@version@@
 Cflags: -I${includedir} @@cflagslocal@@
 Libs: @@libsflag@@${libdir} -lxengnttab
-Requires.private: xentoollog
+Requires.private: xentoollog,xentoolcore
-- 
2.1.4


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


[Xen-devel] [PATCH 22/22] RFC: tools: xentoolcore_restrict_all: use domid_t

2017-09-15 Thread Ian Jackson
This is an RFC because it does not currently compile, because not all
the places that use xentoolcore have a definition of domid in scope!

Signed-off-by: Ian Jackson 
---
 tools/libs/toolcore/handlereg.c| 2 +-
 tools/libs/toolcore/include/xentoolcore.h  | 4 ++--
 tools/libs/toolcore/include/xentoolcore_internal.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/libs/toolcore/handlereg.c b/tools/libs/toolcore/handlereg.c
index 56d8b2d..ca88c9e 100644
--- a/tools/libs/toolcore/handlereg.c
+++ b/tools/libs/toolcore/handlereg.c
@@ -55,7 +55,7 @@ void 
xentoolcore__deregister_active_handle(Xentoolcore__Active_Handle *ah) {
 unlock();
 }
 
-int xentoolcore_restrict_all(uint32_t domid) {
+int xentoolcore_restrict_all(domid_t domid) {
 /* xxx lock */
 int r;
 Xentoolcore__Active_Handle *ah;
diff --git a/tools/libs/toolcore/include/xentoolcore.h 
b/tools/libs/toolcore/include/xentoolcore.h
index 52f7aa3..6d9cada 100644
--- a/tools/libs/toolcore/include/xentoolcore.h
+++ b/tools/libs/toolcore/include/xentoolcore.h
@@ -25,7 +25,7 @@
 #include 
 
 /*
- * int xentoolcore_restrict_all(uint32_t domid);
+ * int xentoolcore_restrict_all(domid_t domid);
  *
  * Arranges that Xen library handles (fds etc.) which are currently held
  * by Xen libraries, can no longer be used other than to affect domid.
@@ -63,7 +63,7 @@
  * xen_some[other]library_open|close or xentoolcore_restrict_all
  *
  */
-int xentoolcore_restrict_all(uint32_t domid);
+int xentoolcore_restrict_all(domid_t domid);
 
 #endif /* XENTOOLCORE_H */
 
diff --git a/tools/libs/toolcore/include/xentoolcore_internal.h 
b/tools/libs/toolcore/include/xentoolcore_internal.h
index 7e96a48..dbdb1dd 100644
--- a/tools/libs/toolcore/include/xentoolcore_internal.h
+++ b/tools/libs/toolcore/include/xentoolcore_internal.h
@@ -81,7 +81,7 @@
 typedef struct Xentoolcore__Active_Handle Xentoolcore__Active_Handle;
 
 typedef int Xentoolcore__Restrict_Callback(Xentoolcore__Active_Handle*,
-   uint32_t domid);
+   domid_t domid);
 
 struct Xentoolcore__Active_Handle {
 Xentoolcore__Restrict_Callback *restrict_callback;
-- 
2.1.4


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


[Xen-devel] [PATCH 16/22] xentoolcore, _restrict_all: Document implementation "complete"

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/libs/toolcore/include/xentoolcore.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/libs/toolcore/include/xentoolcore.h 
b/tools/libs/toolcore/include/xentoolcore.h
index 1210d7d..52f7aa3 100644
--- a/tools/libs/toolcore/include/xentoolcore.h
+++ b/tools/libs/toolcore/include/xentoolcore.h
@@ -41,8 +41,10 @@
  *  
  *  IMPORTANT - IMPLEMENTATION STATUS
  *
- *  This function will be implemented insofar as it appears necessary
- *  for the purposes of running a deprivileged qemu.
+ *  This function has been implemented insofar as it appears necessary
+ *  for the purposes of running a deprivileged qemu, and is believed to
+ *  be sufficient (subject to the caveats discussed in the appropriate
+ *  libxl documatation for this feature).
  *
  *  However, this function is NOT implemented for all Xen libraries.
  *  For each use case of this function, the designer must evaluate and
-- 
2.1.4


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


[Xen-devel] [PATCH 20/22] libxl: userlookup_helper_getpwnam rename and turn into a macro

2017-09-15 Thread Ian Jackson
We are going to want versions of getpwuid, too.  And maybe in the
future getgr*.

This is most sanely achieved with a macro, as otherwise the types are
a mess.

Signed-off-by: Ian Jackson 
---
 tools/libxl/libxl_dm.c | 79 --
 1 file changed, 44 insertions(+), 35 deletions(-)

diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 3c4ef2b..10da40c 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -748,39 +748,48 @@ libxl__detect_gfx_passthru_kind(libxl__gc *gc,
 return LIBXL_GFX_PASSTHRU_KIND_DEFAULT;
 }
 
-/* return 1 if the user was found, 0 if it was not, -1 on error */
-static int libxl__dm_runas_helper(libxl__gc *gc, const char *username,
-   struct passwd **pwd_r)
-{
-struct passwd pwd, *user = NULL;
-char *buf = NULL;
-long buf_size;
-int ret;
-
-buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
-if (buf_size < 0) {
-buf_size = 2048;
-LOG(DEBUG,
-"sysconf(_SC_GETPW_R_SIZE_MAX) failed, setting the initial buffer size to %ld",
-buf_size);
-}
-
-while (1) {
-buf = libxl__realloc(gc, buf, buf_size);
-ret = getpwnam_r(username, , buf, buf_size, );
-if (ret == ERANGE) {
-buf_size += 128;
-continue;
-}
-if (ret != 0)
-return ERROR_FAIL;
-if (user != NULL) {
-if (pwd_r) *pwd_r = pwd;
-return 1;
-}
-return 0;
-}
-}
+/*
+ *  userlookup_helper_getpwnam(libxl__gc*, const char *user,
+ * struct passwd **pwd_r);
+ *
+ *  returns 1 if the user was found, 0 if it was not, -1 on error
+ */
+#define DEFINE_USERLOOKUP_HELPER(NAME,SPEC_TYPE,STRUCTNAME,SYSCONF)  \
+static int userlookup_helper_##NAME(libxl__gc *gc,  \
+SPEC_TYPE spec, \
+   struct STRUCTNAME **out)   \
+{   \
+struct STRUCTNAME resultbuf, *resultp = NULL;   \
+char *buf = NULL;   \
+long buf_size;  \
+int ret;\
+\
+buf_size = sysconf(SYSCONF);\
+if (buf_size < 0) { \
+buf_size = 2048;\
+LOG(DEBUG,  \
+"sysconf failed, setting the initial buffer size to %ld",   \
+buf_size);  \
+}   \
+\
+while (1) { \
+buf = libxl__realloc(gc, buf, buf_size);\
+ret = NAME##_r(spec, , buf, buf_size, ); \
+if (ret == ERANGE) {\
+buf_size += 128;\
+continue;   \
+}   \
+if (ret != 0)   \
+return ERROR_FAIL;  \
+if (resultp != NULL) {   \
+if (out) *out = resultp;\
+return 1;   \
+}   \
+return 0;   \
+}   \
+}
+
+DEFINE_USERLOOKUP_HELPER(getpwnam, const char*, passwd, _SC_GETPW_R_SIZE_MAX);
 
 /* colo mode */
 enum {
@@ -1643,14 +1652,14 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
 }
 
 user = GCSPRINTF("%s%d", LIBXL_QEMU_USER_BASE, guest_domid);
-ret = libxl__dm_runas_helper(gc, user, 0);
+ret = userlookup_helper_getpwnam(gc, user, 0);
 if (ret < 0)
 return ret;
 if (ret > 0)
 goto end_search;
 
 user = LIBXL_QEMU_USER_SHARED;
-ret = libxl__dm_runas_helper(gc, user, 0);
+ret = userlookup_helper_getpwnam(gc, user, 0);
 if (ret < 0)
 return ret;
 if (ret > 0) {
-- 
2.1.4


___
Xen-devel 

[Xen-devel] [PATCH 11/22] xentoolcore_restrict_all: Declare problems due to no evtchn support

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/libs/toolcore/include/xentoolcore.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/libs/toolcore/include/xentoolcore.h 
b/tools/libs/toolcore/include/xentoolcore.h
index 1ab646e..1210d7d 100644
--- a/tools/libs/toolcore/include/xentoolcore.h
+++ b/tools/libs/toolcore/include/xentoolcore.h
@@ -30,6 +30,11 @@
  * Arranges that Xen library handles (fds etc.) which are currently held
  * by Xen libraries, can no longer be used other than to affect domid.
  *
+ * Does not prevent effects that amount only to
+ *   - denial of service, possibly host-wide, by resource exhaustion etc.
+ *   - leak of not-very-interesting metainformation about other domains
+ * eg, specifically, event channel signals relating to other domains
+ *
  * If this cannot be achieved, returns -1 and sets errno.
  * Idempotent if domid is always the same.
  *
-- 
2.1.4


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


[Xen-devel] [PATCH 13/22] tools/xenstore: get_handle: use "goto err" error handling style

2017-09-15 Thread Ian Jackson
Replace the ad-hoc exit clauses with the error handling style where
  - local variables contain either things to be freed, or sentinels
  - all error exits go via an "err" label which frees everything

Signed-off-by: Ian Jackson 
---
 tools/xenstore/xs.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 56caac7..65cba86 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -226,7 +226,7 @@ static struct xs_handle *get_handle(const char *connect_to)
int fd = -1, saved_errno;
 
if (stat(connect_to, ) != 0)
-   return NULL;
+   goto err;
 
if (S_ISSOCK(buf.st_mode))
fd = get_socket(connect_to);
@@ -234,15 +234,11 @@ static struct xs_handle *get_handle(const char 
*connect_to)
fd = get_dev(connect_to);
 
if (fd == -1)
-   return NULL;
+   goto err;
 
h = malloc(sizeof(*h));
-   if (h == NULL) {
-   saved_errno = errno;
-   close(fd);
-   errno = saved_errno;
-   return NULL;
-   }
+   if (h == NULL)
+   goto err;
 
memset(h, 0, sizeof(*h));
 
@@ -267,6 +263,15 @@ static struct xs_handle *get_handle(const char *connect_to)
 #endif
 
return h;
+
+err:
+   saved_errno = errno;
+
+   if (fd >= 0) close(fd);
+   free(h);
+
+   errno = saved_errno;
+   return NULL;
 }
 
 struct xs_handle *xs_daemon_open(void)
-- 
2.1.4


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


[Xen-devel] [PATCH 08/22] xentoolcore_restrict_all: "Implement" for libxencall

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/Rules.mk|  2 +-
 tools/libs/call/Makefile  |  4 ++--
 tools/libs/call/core.c| 37 +
 tools/libs/call/linux.c   |  4 
 tools/libs/call/private.h |  2 ++
 tools/libs/call/xencall.pc.in |  2 +-
 6 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 9b2fe36..71037a1 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -119,7 +119,7 @@ LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) 
$(XEN_LIBXENGNTTAB)/libxengnttab$(l
 SHLIB_libxengnttab  = $(SHDEPS_libxengnttab) 
-Wl,-rpath-link=$(XEN_LIBXENGNTTAB)
 
 CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude)
-SHDEPS_libxencall =
+SHDEPS_libxencall = $(SHLIB_libxentoolcore)
 LDLIBS_libxencall = $(SHDEPS_libxencall) 
$(XEN_LIBXENCALL)/libxencall$(libextension)
 SHLIB_libxencall  = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_LIBXENCALL)
 
diff --git a/tools/libs/call/Makefile b/tools/libs/call/Makefile
index 1ccd5fd..39dd207 100644
--- a/tools/libs/call/Makefile
+++ b/tools/libs/call/Makefile
@@ -7,7 +7,7 @@ SHLIB_LDFLAGS += -Wl,--version-script=libxencall.map
 
 CFLAGS   += -Werror -Wmissing-prototypes
 CFLAGS   += -I./include $(CFLAGS_xeninclude)
-CFLAGS   += $(CFLAGS_libxentoollog)
+CFLAGS   += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore)
 
 SRCS-y += core.c buffer.c
 SRCS-$(CONFIG_Linux)   += linux.c
@@ -62,7 +62,7 @@ libxencall.so.$(MAJOR): libxencall.so.$(MAJOR).$(MINOR)
$(SYMLINK_SHLIB) $< $@
 
 libxencall.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxencall.map
-   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxencall.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) 
$(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxencall.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) 
$(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: build
diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c
index 5ca0372..11ecc87 100644
--- a/tools/libs/call/core.c
+++ b/tools/libs/call/core.c
@@ -15,8 +15,41 @@
 
 #include 
 
+#include 
+#include 
+#include 
+#include 
+
 #include "private.h"
 
+static int all_restrict_cb(Xentoolcore__Active_Handle *ah, uint32_t domid) {
+xencall_handle *xcall = CONTAINER_OF(ah, *xcall, tc_ah);
+int nullfd = -1, r;
+
+if (xcall->fd < 0)
+/* just in case */
+return 0;
+
+/*
+ * We don't implement a restrict function.  We neuter the fd by
+ * dup'ing /dev/null onto it.  This is better than closing it,
+ * because it does not involve locking against concurrent uses
+ * of xencall in other threads.
+ */
+nullfd = open("/dev/null",O_RDONLY);
+if (nullfd < 0) goto err;
+
+r = dup2(nullfd, xcall->fd);
+if (r < 0) goto err;
+
+close(nullfd);
+return 0;
+
+err:
+if (nullfd >= 0) close(nullfd);
+return -1;
+}
+
 xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags)
 {
 xencall_handle *xcall = malloc(sizeof(*xcall));
@@ -25,6 +58,8 @@ xencall_handle *xencall_open(xentoollog_logger *logger, 
unsigned open_flags)
 if (!xcall) return NULL;
 
 xcall->fd = -1;
+xcall->tc_ah.restrict_callback = all_restrict_cb;
+xentoolcore__register_active_handle(>tc_ah);
 
 xcall->flags = open_flags;
 xcall->buffer_cache_nr = 0;
@@ -53,6 +88,7 @@ xencall_handle *xencall_open(xentoollog_logger *logger, 
unsigned open_flags)
 
 err:
 osdep_xencall_close(xcall);
+xentoolcore__deregister_active_handle(>tc_ah);
 xtl_logger_destroy(xcall->logger_tofree);
 free(xcall);
 return NULL;
@@ -66,6 +102,7 @@ int xencall_close(xencall_handle *xcall)
 return 0;
 
 rc = osdep_xencall_close(xcall);
+xentoolcore__deregister_active_handle(>tc_ah);
 buffer_release_cache(xcall);
 xtl_logger_destroy(xcall->logger_tofree);
 free(xcall);
diff --git a/tools/libs/call/linux.c b/tools/libs/call/linux.c
index e8e0311..3f1b691 100644
--- a/tools/libs/call/linux.c
+++ b/tools/libs/call/linux.c
@@ -21,6 +21,10 @@
 #include 
 #include 
 
+#include 
+#include 
+#include 
+
 #include 
 #include 
 
diff --git a/tools/libs/call/private.h b/tools/libs/call/private.h
index 37dd15f..533f0c4 100644
--- a/tools/libs/call/private.h
+++ b/tools/libs/call/private.h
@@ -2,6 +2,7 @@
 #define XENCALL_PRIVATE_H
 
 #include 
+#include 
 
 #include 
 
@@ -20,6 +21,7 @@ struct xencall_handle {
 xentoollog_logger *logger, *logger_tofree;
 unsigned flags;
 int fd;
+Xentoolcore__Active_Handle tc_ah;
 
 /*
  * A simple cache of unused, single page, hypercall buffers
diff --git a/tools/libs/call/xencall.pc.in b/tools/libs/call/xencall.pc.in
index 475c133..409773e 100644
--- a/tools/libs/call/xencall.pc.in
+++ b/tools/libs/call/xencall.pc.in
@@ -7,4 +7,4 @@ Description: The Xencall 

[Xen-devel] [PATCH 03/22] xentoolcore, _restrict_all: Introduce new library and implementation

2017-09-15 Thread Ian Jackson
In practice, qemu opens a great many fds.  Tracking them all down and
playing whack-a-mole is unattractive.  It is also potentially fragile
in that future changes might accidentally undo our efforts.

Instead, we are going to teach all the Xen libraries how to register
their fds so that they can be neutered with one qemu call.

Signed-off-by: Ian Jackson 
---
 .gitignore |   4 +
 tools/Rules.mk |   6 ++
 tools/libs/Makefile|   1 +
 tools/libs/toolcore/Makefile   | 101 
 tools/libs/toolcore/handlereg.c|  78 
 tools/libs/toolcore/include/xentoolcore.h  |  71 ++
 tools/libs/toolcore/include/xentoolcore_internal.h | 102 +
 tools/libs/toolcore/libxentoolcore.map |   7 ++
 tools/libs/toolcore/xentoolcore.pc.in  |   9 ++
 9 files changed, 379 insertions(+)
 create mode 100644 tools/libs/toolcore/Makefile
 create mode 100644 tools/libs/toolcore/handlereg.c
 create mode 100644 tools/libs/toolcore/include/xentoolcore.h
 create mode 100644 tools/libs/toolcore/include/xentoolcore_internal.h
 create mode 100644 tools/libs/toolcore/libxentoolcore.map
 create mode 100644 tools/libs/toolcore/xentoolcore.pc.in

diff --git a/.gitignore b/.gitignore
index ecb198f..269ab0c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,6 +72,7 @@ stubdom/libxencall-*
 stubdom/libxenevtchn-*
 stubdom/libxenforeignmemory-*
 stubdom/libxengnttab-*
+stubdom/libxentoolcore-*
 stubdom/libxentoollog-*
 stubdom/lwip-*
 stubdom/lwip/
@@ -97,6 +98,8 @@ tools/config.cache
 config/Tools.mk
 config/Stubdom.mk
 config/Docs.mk
+tools/libs/toolcore/headers.chk
+tools/libs/toolcore/xentoolcore.pc
 tools/libs/toollog/headers.chk
 tools/libs/toollog/xentoollog.pc
 tools/libs/evtchn/headers.chk
@@ -351,6 +354,7 @@ tools/include/xen-foreign/arm64.h
 .git
 tools/misc/xen-hptool
 tools/misc/xen-mfndump
+tools/libs/toolcore/include/_*.h
 tools/libxc/_*.[ch]
 tools/libxl/_*.[ch]
 tools/libxl/testidl
diff --git a/tools/Rules.mk b/tools/Rules.mk
index dbc7635..5e1c7cb 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -10,6 +10,7 @@ export _INSTALL := $(INSTALL)
 INSTALL = $(XEN_ROOT)/tools/cross-install
 
 XEN_INCLUDE= $(XEN_ROOT)/tools/include
+XEN_LIBXENTOOLCORE  = $(XEN_ROOT)/tools/libs/toolcore
 XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
 XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libs/evtchn
 XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libs/gnttab
@@ -102,6 +103,11 @@ SHDEPS_libxentoollog =
 LDLIBS_libxentoollog = $(SHDEPS_libxentoollog) 
$(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension)
 SHLIB_libxentoollog  = $(SHDEPS_libxentoollog) 
-Wl,-rpath-link=$(XEN_LIBXENTOOLLOG)
 
+CFLAGS_libxentoolcore = -I$(XEN_LIBXENTOOLCORE)/include $(CFLAGS_xeninclude)
+SHDEPS_libxentoolcore =
+LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) 
$(XEN_LIBXENTOOLCORE)/libxentoolcore$(libextension)
+SHLIB_libxentoolcore  = $(SHDEPS_libxentoolcore) 
-Wl,-rpath-link=$(XEN_LIBXENTOOLCORE)
+
 CFLAGS_libxenevtchn = -I$(XEN_LIBXENEVTCHN)/include $(CFLAGS_xeninclude)
 SHDEPS_libxenevtchn =
 LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) 
$(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension)
diff --git a/tools/libs/Makefile b/tools/libs/Makefile
index 2035873..ea9a64d 100644
--- a/tools/libs/Makefile
+++ b/tools/libs/Makefile
@@ -2,6 +2,7 @@ XEN_ROOT = $(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
+SUBDIRS-y += toolcore
 SUBDIRS-y += toollog
 SUBDIRS-y += evtchn
 SUBDIRS-y += gnttab
diff --git a/tools/libs/toolcore/Makefile b/tools/libs/toolcore/Makefile
new file mode 100644
index 000..f86f839
--- /dev/null
+++ b/tools/libs/toolcore/Makefile
@@ -0,0 +1,101 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR  = 1
+MINOR  = 0
+SHLIB_LDFLAGS += -Wl,--version-script=libxentoolcore.map
+
+CFLAGS += -Werror -Wmissing-prototypes
+CFLAGS += -I./include
+
+SRCS-y += handlereg.c
+
+LIB_OBJS := $(patsubst %.c,%.o,$(SRCS-y))
+PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS-y))
+
+LIB := libxentoolcore.a
+ifneq ($(nosharedlibs),y)
+LIB += libxentoolcore.so
+endif
+
+PKG_CONFIG := xentoolcore.pc
+PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
+
+ifneq ($(CONFIG_LIBXC_MINIOS),y)
+PKG_CONFIG_INST := $(PKG_CONFIG)
+$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
+$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
+$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
+endif
+
+PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENTOOLCORE)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
+
+AUTOINCS=include/_xentoolcore_list.h
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build:
+   $(MAKE) libs
+
+.PHONY: libs
+libs: headers.chk $(LIB) $(PKG_CONFIG_INST) 

[Xen-devel] [PATCH 07/22] xentoolcore_restrict_all: Implement for libxendevicemodel

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/Rules.mk  |  2 +-
 tools/libs/devicemodel/Makefile |  3 ++-
 tools/libs/devicemodel/core.c   | 16 
 tools/libs/devicemodel/private.h|  3 +++
 tools/libs/devicemodel/xendevicemodel.pc.in |  2 +-
 5 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 5e1c7cb..9b2fe36 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -129,7 +129,7 @@ LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) 
$(XEN_LIBXENFOREIGNME
 SHLIB_libxenforeignmemory  = $(SHDEPS_libxenforeignmemory) 
-Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
 
 CFLAGS_libxendevicemodel = -I$(XEN_LIBXENDEVICEMODEL)/include 
$(CFLAGS_xeninclude)
-SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_xencall)
+SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) 
$(SHLIB_xencall)
 LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) 
$(XEN_LIBXENDEVICEMODEL)/libxendevicemodel$(libextension)
 SHLIB_libxendevicemodel  = $(SHDEPS_libxendevicemodel) 
-Wl,-rpath-link=$(XEN_LIBXENDEVICEMODEL)
 
diff --git a/tools/libs/devicemodel/Makefile b/tools/libs/devicemodel/Makefile
index f0e1e6c..3f7efd5 100644
--- a/tools/libs/devicemodel/Makefile
+++ b/tools/libs/devicemodel/Makefile
@@ -8,6 +8,7 @@ SHLIB_LDFLAGS += -Wl,--version-script=libxendevicemodel.map
 CFLAGS   += -Werror -Wmissing-prototypes
 CFLAGS   += -I./include $(CFLAGS_xeninclude)
 CFLAGS   += $(CFLAGS_libxentoollog)
+CFLAGS   += $(CFLAGS_libxentoolcore)
 CFLAGS   += $(CFLAGS_libxencall)
 
 SRCS-y += core.c
@@ -63,7 +64,7 @@ libxendevicemodel.so.$(MAJOR): 
libxendevicemodel.so.$(MAJOR).$(MINOR)
$(SYMLINK_SHLIB) $< $@
 
 libxendevicemodel.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxendevicemodel.map
-   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxendevicemodel.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) 
$(LDLIBS_libxentoollog) $(LDLIBS_libxencall) $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxendevicemodel.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) 
$(LDLIBS_libxentoollog) $(LDLIBS_libxencall) $(LDLIBS_libxentoolcore) 
$(APPEND_LDFLAGS)
 
 .PHONY: install
 install: build
diff --git a/tools/libs/devicemodel/core.c b/tools/libs/devicemodel/core.c
index 2093884..3292e53 100644
--- a/tools/libs/devicemodel/core.c
+++ b/tools/libs/devicemodel/core.c
@@ -21,6 +21,16 @@
 
 #include "private.h"
 
+static int all_restrict_cb(Xentoolcore__Active_Handle *ah, uint32_t domid) {
+xendevicemodel_handle *dmod = CONTAINER_OF(ah, *dmod, tc_ah);
+
+if (dmod->fd < 0)
+/* just in case */
+return 0;
+
+return xendevicemodel_restrict(dmod, domid);
+}
+
 xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger,
unsigned open_flags)
 {
@@ -30,6 +40,10 @@ xendevicemodel_handle *xendevicemodel_open(xentoollog_logger 
*logger,
 if (!dmod)
 return NULL;
 
+dmod->fd = -1;
+dmod->tc_ah.restrict_callback = all_restrict_cb;
+xentoolcore__register_active_handle(>tc_ah);
+
 dmod->flags = open_flags;
 dmod->logger = logger;
 dmod->logger_tofree = NULL;
@@ -55,6 +69,7 @@ xendevicemodel_handle *xendevicemodel_open(xentoollog_logger 
*logger,
 err:
 xtl_logger_destroy(dmod->logger_tofree);
 xencall_close(dmod->xcall);
+xentoolcore__deregister_active_handle(>tc_ah);
 free(dmod);
 return NULL;
 }
@@ -69,6 +84,7 @@ int xendevicemodel_close(xendevicemodel_handle *dmod)
 rc = osdep_xendevicemodel_close(dmod);
 
 xencall_close(dmod->xcall);
+xentoolcore__deregister_active_handle(>tc_ah);
 xtl_logger_destroy(dmod->logger_tofree);
 free(dmod);
 return rc;
diff --git a/tools/libs/devicemodel/private.h b/tools/libs/devicemodel/private.h
index 4ce5aac..c4a225f 100644
--- a/tools/libs/devicemodel/private.h
+++ b/tools/libs/devicemodel/private.h
@@ -7,11 +7,14 @@
 #include 
 #include 
 
+#include 
+
 struct xendevicemodel_handle {
 xentoollog_logger *logger, *logger_tofree;
 unsigned int flags;
 xencall_handle *xcall;
 int fd;
+Xentoolcore__Active_Handle tc_ah;
 };
 
 struct xendevicemodel_buf {
diff --git a/tools/libs/devicemodel/xendevicemodel.pc.in 
b/tools/libs/devicemodel/xendevicemodel.pc.in
index ed08f83..8bd04fa 100644
--- a/tools/libs/devicemodel/xendevicemodel.pc.in
+++ b/tools/libs/devicemodel/xendevicemodel.pc.in
@@ -7,4 +7,4 @@ Description: The Xendevicemodel library for Xen hypervisor
 Version: @@version@@
 Cflags: -I${includedir} @@cflagslocal@@
 Libs: @@libsflag@@${libdir} -lxendevicemodel
-Requires.private: xentoollog,xencall
+Requires.private: xentoolcore,xentoollog,xencall
-- 
2.1.4


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


[Xen-devel] [PATCH 06/22] tools: move CONTAINER_OF to xentoolcore_internal.h

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/libs/toolcore/include/xentoolcore_internal.h | 42 ++
 tools/libxl/libxl_internal.h   | 30 
 2 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/tools/libs/toolcore/include/xentoolcore_internal.h 
b/tools/libs/toolcore/include/xentoolcore_internal.h
index 670e29d..27497d6 100644
--- a/tools/libs/toolcore/include/xentoolcore_internal.h
+++ b/tools/libs/toolcore/include/xentoolcore_internal.h
@@ -24,6 +24,8 @@
 #ifndef XENTOOLCORE_INTERNAL_H
 #define XENTOOLCORE_INTERNAL_H
 
+#include 
+
 #include "xentoolcore.h"
 #include "_xentoolcore_list.h"
 
@@ -89,6 +91,46 @@ struct Xentoolcore__Active_Handle {
 void xentoolcore__register_active_handle(Xentoolcore__Active_Handle*);
 void xentoolcore__deregister_active_handle(Xentoolcore__Active_Handle*);
 
+/* -- convenient stuff -- */
+
+/*
+ * This does not appear in xentoolcore.h because it is a bit
+ * namespace-unclean.
+ */
+
+/*
+ * Convenience macros.
+ */
+
+/*
+ * CONTAINER_OF work like this.  Given:
+ *typedef struct {
+ *  ...
+ *  member_type member_name;
+ *  ...
+ *} outer_type;
+ *outer_type outer, *outer_var;
+ *member_type *inner_ptr = >member_name;
+ *
+ * Then, effectively:
+ *outer_type *CONTAINER_OF(member_type *inner_ptr,
+ * *outer_var, // or type name for outer_type
+ * member_name);
+ *
+ * So that:
+ *CONTAINER_OF(inner_ptr, *outer_var, member_name) == 
+ *CONTAINER_OF(inner_ptr, outer_type, member_name) == 
+ */
+#define CONTAINER_OF(inner_ptr, outer, member_name) \
+({  \
+typeof(outer) *container_of_;   \
+container_of_ = (void*)((char*)(inner_ptr) -\
+offsetof(typeof(outer), member_name));  \
+(void)(_of_->member_name ==   \
+   (typeof(inner_ptr))0) /* type check */;  \
+container_of_;  \
+})
+
 #endif /* XENTOOLCORE_INTERNAL_H */
 
 /*
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 04be10a..4f2f433 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3804,36 +3804,6 @@ _hidden void libxl__remus_restore_setup(libxl__egc *egc,
  * Convenience macros.
  */
 
-/*
- * CONTAINER_OF work like this.  Given:
- *typedef struct {
- *  ...
- *  member_type member_name;
- *  ...
- *} outer_type;
- *outer_type outer, *outer_var;
- *member_type *inner_ptr = >member_name;
- *
- * Then, effectively:
- *outer_type *CONTAINER_OF(member_type *inner_ptr,
- * *outer_var, // or type name for outer_type
- * member_name);
- *
- * So that:
- *CONTAINER_OF(inner_ptr, *outer_var, member_name) == 
- *CONTAINER_OF(inner_ptr, outer_type, member_name) == 
- */
-#define CONTAINER_OF(inner_ptr, outer, member_name) \
-({  \
-typeof(outer) *container_of_;   \
-container_of_ = (void*)((char*)(inner_ptr) -\
-offsetof(typeof(outer), member_name));  \
-(void)(_of_->member_name ==   \
-   (typeof(inner_ptr))0) /* type check */;  \
-container_of_;  \
-})
-
-
 #define FILLZERO LIBXL_FILLZERO
 
 
-- 
2.1.4


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


[Xen-devel] [PATCH 01/22] xen: Provide XEN_DMOP_remote_shutdown

2017-09-15 Thread Ian Jackson
SCHEDOP_remote_shutdown should be a DMOP so that a deprivileged qemu
can do the propery tidying up.

We should remove SCHEDOP_remote_shutdown at some point.

CC: Jan Beulich 
CC: Andrew Cooper 
CC: George Dunlap 
CC: Konrad Rzeszutek Wilk 
CC: Stefano Stabellini 
CC: Tim Deegan 
CC: Wei Liu 
Signed-off-by: Ian Jackson 
---
 xen/arch/x86/hvm/dm.c  |  9 +
 xen/include/public/hvm/dm_op.h | 12 
 xen/include/xlat.lst   |  1 +
 3 files changed, 22 insertions(+)

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index 4cf6dee..9eee9fb 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -630,6 +630,14 @@ static int dm_op(const struct dmop_args *op_args)
 rc = hvm_inject_msi(d, data->addr, data->data);
 break;
 }
+case XEN_DMOP_remote_shutdown:
+{
+const struct xen_dm_op_remote_shutdown *data =
+_shutdown;
+
+domain_shutdown(d, data->reason);
+break;
+}
 
 default:
 rc = -EOPNOTSUPP;
@@ -659,6 +667,7 @@ CHECK_dm_op_modified_memory;
 CHECK_dm_op_set_mem_type;
 CHECK_dm_op_inject_event;
 CHECK_dm_op_inject_msi;
+CHECK_dm_op_remote_shutdown;
 
 int compat_dm_op(domid_t domid,
  unsigned int nr_bufs,
diff --git a/xen/include/public/hvm/dm_op.h b/xen/include/public/hvm/dm_op.h
index 2a4c3d9..21552b7 100644
--- a/xen/include/public/hvm/dm_op.h
+++ b/xen/include/public/hvm/dm_op.h
@@ -357,6 +357,17 @@ struct xen_dm_op_map_mem_type_to_ioreq_server {
has to be set to zero by the caller */
 };
 
+/*
+ * XEN_DMOP_remote_shutdown : Declare a shutdown for another domain
+ *Identical to SCHEDOP_remote_shutdown
+ */
+#define XEN_DMOP_remote_shutdown 16
+
+struct xen_dm_op_remote_shutdown {
+uint32_t reason;   /* SHUTDOWN_* => enum sched_shutdown_reason */
+   /* (Other reason values are not blocked) */
+};
+
 struct xen_dm_op {
 uint32_t op;
 uint32_t pad;
@@ -377,6 +388,7 @@ struct xen_dm_op {
 struct xen_dm_op_inject_msi inject_msi;
 struct xen_dm_op_map_mem_type_to_ioreq_server
 map_mem_type_to_ioreq_server;
+struct xen_dm_op_remote_shutdown remote_shutdown;
 } u;
 };
 
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 0f17000..20055b4 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -70,6 +70,7 @@
 ?  dm_op_set_pci_intx_levelhvm/dm_op.h
 ?  dm_op_set_pci_link_routehvm/dm_op.h
 ?  dm_op_track_dirty_vram  hvm/dm_op.h
+?  dm_op_remote_shutdown   hvm/dm_op.h
 ?  vcpu_hvm_contexthvm/hvm_vcpu.h
 ?  vcpu_hvm_x86_32 hvm/hvm_vcpu.h
 ?  vcpu_hvm_x86_64 hvm/hvm_vcpu.h
-- 
2.1.4


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


[Xen-devel] [PATCH 02/22] tools: libxendevicemodel: Provide xendevicemodel_shutdown

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/libs/devicemodel/core.c   | 16 
 tools/libs/devicemodel/include/xendevicemodel.h |  9 +
 tools/libs/devicemodel/libxendevicemodel.map|  1 +
 3 files changed, 26 insertions(+)

diff --git a/tools/libs/devicemodel/core.c b/tools/libs/devicemodel/core.c
index d7c6476..2093884 100644
--- a/tools/libs/devicemodel/core.c
+++ b/tools/libs/devicemodel/core.c
@@ -532,6 +532,22 @@ int xendevicemodel_inject_event(
 return xendevicemodel_op(dmod, domid, 1, , sizeof(op));
 }
 
+int xendevicemodel_shutdown(
+xendevicemodel_handle *dmod, domid_t domid, unsigned int reason)
+{
+struct xen_dm_op op;
+struct xen_dm_op_remote_shutdown *data;
+
+memset(, 0, sizeof(op));
+
+op.op = XEN_DMOP_remote_shutdown;
+data = _shutdown;
+
+data->reason = reason;
+
+return xendevicemodel_op(dmod, domid, 1, , sizeof(op));
+}
+
 int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid)
 {
 return osdep_xendevicemodel_restrict(dmod, domid);
diff --git a/tools/libs/devicemodel/include/xendevicemodel.h 
b/tools/libs/devicemodel/include/xendevicemodel.h
index 580fad2..6ce39d1 100644
--- a/tools/libs/devicemodel/include/xendevicemodel.h
+++ b/tools/libs/devicemodel/include/xendevicemodel.h
@@ -317,6 +317,15 @@ int xendevicemodel_inject_event(
 uint8_t type, uint32_t error_code, uint8_t insn_len, uint64_t cr2);
 
 /**
+ * Shuts the domain down.
+ *
+ * @parm reason usually enum sched_shutdown_reason, see xen/sched.h
+ * @return 0 on success, -1 on failure.
+ */
+int xendevicemodel_shutdown(
+xendevicemodel_handle *dmod, domid_t domid, unsigned int reason);
+
+/**
  * This function restricts the use of this handle to the specified
  * domain.
  *
diff --git a/tools/libs/devicemodel/libxendevicemodel.map 
b/tools/libs/devicemodel/libxendevicemodel.map
index 130222c..fd57e79 100644
--- a/tools/libs/devicemodel/libxendevicemodel.map
+++ b/tools/libs/devicemodel/libxendevicemodel.map
@@ -18,6 +18,7 @@ VERS_1.0 {
xendevicemodel_modified_memory;
xendevicemodel_set_mem_type;
xendevicemodel_inject_event;
+   xendevicemodel_shutdown;
xendevicemodel_restrict;
xendevicemodel_close;
local: *; /* Do not expose anything by default */
-- 
2.1.4


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


[Xen-devel] [PATCH 10/22] xentoolcore_restrict_all: Implement for libxenforeignmemory

2017-09-15 Thread Ian Jackson
Signed-off-by: Ian Jackson 
---
 tools/Rules.mk  |  2 +-
 tools/libs/foreignmemory/Makefile   |  4 ++--
 tools/libs/foreignmemory/core.c | 15 +++
 tools/libs/foreignmemory/private.h  |  3 +++
 tools/libs/foreignmemory/xenforeignmemory.pc.in |  2 +-
 5 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/tools/Rules.mk b/tools/Rules.mk
index 71037a1..7dd126a 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -124,7 +124,7 @@ LDLIBS_libxencall = $(SHDEPS_libxencall) 
$(XEN_LIBXENCALL)/libxencall$(libextens
 SHLIB_libxencall  = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_LIBXENCALL)
 
 CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include 
$(CFLAGS_xeninclude)
-SHDEPS_libxenforeignmemory =
+SHDEPS_libxenforeignmemory = $(SHLIB_libxentoolcore)
 LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) 
$(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension)
 SHLIB_libxenforeignmemory  = $(SHDEPS_libxenforeignmemory) 
-Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
 
diff --git a/tools/libs/foreignmemory/Makefile 
b/tools/libs/foreignmemory/Makefile
index ab7f873..cbe815f 100644
--- a/tools/libs/foreignmemory/Makefile
+++ b/tools/libs/foreignmemory/Makefile
@@ -7,7 +7,7 @@ SHLIB_LDFLAGS += -Wl,--version-script=libxenforeignmemory.map
 
 CFLAGS   += -Werror -Wmissing-prototypes
 CFLAGS   += -I./include $(CFLAGS_xeninclude)
-CFLAGS   += $(CFLAGS_libxentoollog)
+CFLAGS   += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore)
 
 SRCS-y += core.c
 SRCS-$(CONFIG_Linux)   += linux.c
@@ -62,7 +62,7 @@ libxenforeignmemory.so.$(MAJOR): 
libxenforeignmemory.so.$(MAJOR).$(MINOR)
$(SYMLINK_SHLIB) $< $@
 
 libxenforeignmemory.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxenforeignmemory.map
-   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxenforeignmemory.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) 
$(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
+   $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) 
-Wl,libxenforeignmemory.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) 
$(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: build
diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/core.c
index a6897dc..b48ecba 100644
--- a/tools/libs/foreignmemory/core.c
+++ b/tools/libs/foreignmemory/core.c
@@ -19,6 +19,16 @@
 
 #include "private.h"
 
+static int all_restrict_cb(Xentoolcore__Active_Handle *ah, uint32_t domid) {
+xenforeignmemory_handle *fmem = CONTAINER_OF(ah, *fmem, tc_ah);
+
+if (fmem->fd < 0)
+/* just in case */
+return 0;
+
+return xenforeignmemory_restrict(fmem, domid);
+}
+
 xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
unsigned open_flags)
 {
@@ -31,6 +41,9 @@ xenforeignmemory_handle 
*xenforeignmemory_open(xentoollog_logger *logger,
 fmem->logger = logger;
 fmem->logger_tofree = NULL;
 
+fmem->tc_ah.restrict_callback = all_restrict_cb;
+xentoolcore__register_active_handle(>tc_ah);
+
 if (!fmem->logger) {
 fmem->logger = fmem->logger_tofree =
 (xentoollog_logger*)
@@ -45,6 +58,7 @@ xenforeignmemory_handle 
*xenforeignmemory_open(xentoollog_logger *logger,
 
 err:
 osdep_xenforeignmemory_close(fmem);
+xentoolcore__deregister_active_handle(>tc_ah);
 xtl_logger_destroy(fmem->logger_tofree);
 free(fmem);
 return NULL;
@@ -58,6 +72,7 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)
 return 0;
 
 rc = osdep_xenforeignmemory_close(fmem);
+xentoolcore__deregister_active_handle(>tc_ah);
 xtl_logger_destroy(fmem->logger_tofree);
 free(fmem);
 return rc;
diff --git a/tools/libs/foreignmemory/private.h 
b/tools/libs/foreignmemory/private.h
index c5c07cc..2470f3c 100644
--- a/tools/libs/foreignmemory/private.h
+++ b/tools/libs/foreignmemory/private.h
@@ -5,6 +5,8 @@
 
 #include 
 
+#include 
+
 #include 
 #include 
 
@@ -20,6 +22,7 @@ struct xenforeignmemory_handle {
 xentoollog_logger *logger, *logger_tofree;
 unsigned flags;
 int fd;
+Xentoolcore__Active_Handle tc_ah;
 };
 
 int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem);
diff --git a/tools/libs/foreignmemory/xenforeignmemory.pc.in 
b/tools/libs/foreignmemory/xenforeignmemory.pc.in
index 63432dc..61c9def 100644
--- a/tools/libs/foreignmemory/xenforeignmemory.pc.in
+++ b/tools/libs/foreignmemory/xenforeignmemory.pc.in
@@ -7,4 +7,4 @@ Description: The Xenforeignmemory library for Xen hypervisor
 Version: @@version@@
 Cflags: -I${includedir} @@cflagslocal@@
 Libs: @@libsflag@@${libdir} -lxenforeignmemory
-Requires.private: xentoollog
+Requires.private: xentoollog,xentoolcore
-- 
2.1.4


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


Re: [Xen-devel] CONFIG_SCRUB_DEBUG=y + arm64 + livepatch = Xen BUG at page_alloc.c:738

2017-09-15 Thread Konrad Rzeszutek Wilk
On Thu, Sep 14, 2017 at 05:39:23PM -0400, Boris Ostrovsky wrote:
> On 09/14/2017 05:26 PM, Konrad Rzeszutek Wilk wrote:
> > On Wed, Sep 13, 2017 at 02:49:41PM -0400, Boris Ostrovsky wrote:
> >> On 09/13/2017 02:25 PM, Julien Grall wrote:
> >>> Hi,
> >>>
> >>> On 09/13/2017 07:05 PM, Boris Ostrovsky wrote:
>  On 09/13/2017 11:32 AM, Konrad Rzeszutek Wilk wrote:
>  Well, that's not a fix. This eliminates the case that something in
>  ARM-specific code (which I haven't tested) accidentally clears
>  _PGC_need_scrub.
> 
>  OK, I think I know what the problem is. You are using
>  CONFIG_SEPARATE_XENHEAP, are you?
> >>> It seems the bug appear on Arm64, so CONFIG_SEPARATE_XENHEAP is not set.
> >>>
> >>> Note that Arm32 is using separate heap.
> >>
> >> For separate heap we will need
> >>
> >>
> >> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
> >> index b5243fc..9f62ea2 100644
> >> --- a/xen/common/page_alloc.c
> >> +++ b/xen/common/page_alloc.c
> >> @@ -2059,7 +2059,7 @@ void free_xenheap_pages(void *v, unsigned int order)
> >>
> >>  memguard_guard_range(v, 1 << (order + PAGE_SHIFT));
> >>
> >> -free_heap_pages(virt_to_page(v), order, false);
> >> +free_heap_pages(virt_to_page(v), order, scrub_debug);
> >>  }
> >>
> >>  #else
> >>
> >>
> >> If that doesn't help then there are two cases where free_heap_pages is
> >> called with 'false' --- one in alloc_domheap_pages() and the other in
> >> online_page().
> >>
> >> Setting one and then the other would further narrow it down.
> > It went further. See the serial log:
> 
> Hmm. As Julien said, this is ARM64 so this patch should not have any effect.
> 
> Have you tried flipping false to true in the two alloc_domheap_pages()
> invocations that I mentioned?

Yeah, it didn't help. But I decided during a certain call to debug this.


@@ -1705,6 +1711,7 @@ static void init_heap_pages(
 {
 unsigned long i;
 
+printk("%s: 0x%lx -> 0x%lx %s\n", __func__, page_to_mfn(pg), 
page_to_mfn(pg) + nr_pages, scrub_debug ? "scrub" : "");
 for ( i = 0; i < nr_pages; i++ )
 {
 unsigned int nid = phys_to_nid(page_to_maddr(pg+i));
@@ -1000,7 +1001,12 @@ if ( memflags & MEMF_debug ) {
 spin_unlock(_lock);
 }
 else if ( !(memflags & MEMF_no_scrub) )
+{
+
+   printk("%s:%d %d scrub mfn=0%lx\n", __func__, __LINE__, i, 
page_to_mfn([i]));
+
 check_one_page([i]);
+   }
 }
 
 if ( dirty_cnt )
@@ -1836,6 +1843,7 @@ static void __init smp_scrub_heap_pages(void *data)
 else
 end = start + chunk_size;
 
+printk("CPU%d: MFN=0x%lx -> 0x%lx\n", cpu, start, end);
 for ( mfn = start; mfn < end; mfn++ )
 {
 pg = mfn_to_page(mfn);

Shows:

(XEN) Loading dom0 DTB to 0x17e0-0x17e08265
(XEN) init_domheap_pages: 0xb87b1->0xb87bc
(XEN) init_heap_pages: 0xb87b1 -> 0xb87bc
(XEN) init_domheap_pages: 0xb88f1->0xb98ae
(XEN) init_heap_pages: 0xb88f1 -> 0xb98ae   <- so the memory is from here

(XEN) Scrubbing Free RAM on 1 nodes using 8 CPUs
(XEN) Initial low memory virq threshold set at 0x4000 pages.
(XEN) Scrubbing Free RAM on 1 nodes using 8 CPUs
(XEN) CPU0: MFN=0x0 -> 0x8000
(XEN) CPU6: MFN=0x6a12e -> 0x7212e
(XEN) CPU5: MFN=0x58651 -> 0x60651
(XEN) CPU2: MFN=0x235ba -> 0x2b5ba
(XEN) CPU1: MFN=0x11add -> 0x19add
(XEN) CPU3: MFN=0x35097 -> 0x3d097
(XEN) CPU4: MFN=0x46b74 -> 0x4eb74
(XEN) CPU7: MFN=0x7bc0b -> 0x83c0b
(XEN) .(XEN) CPU6: MFN=0x7212e -> 0x7a12e
(XEN) CPU5: MFN=0x60651 -> 0x68651
(XEN) CPU4: MFN=0x4eb74 -> 0x56b74
(XEN) CPU1: MFN=0x19add -> 0x21add
CPU0: MFN=0x8000 -> 0x1
(XEN) CPU7: MFN=0x83c0b -> 0x8bc0b
(XEN) CPU2: MFN=0x2b5ba -> 0x335ba
(XEN) CPU3: MFN=0x3d097 -> 0x45097
(XEN) .(XEN) CPU1: MFN=0x21add -> 0x235ba
(XEN) CPU2: MFN=0x335ba -> 0x35097
CPU0: MFN=0x1 -> 0x11add
(XEN) CPU3: MFN=0x45097 -> 0x46b74
(XEN) CPU6: MFN=0x7a12e -> 0x7bc0b
(XEN) CPU4: MFN=0x56b74 -> 0x58651
(XEN) CPU5: MFN=0x68651 -> 0x6a12e
(XEN) CPU7: MFN=0x8bc0b -> 0x8d6ea
(XEN) .done.
..snip..

(XEN) alloc_heap_pages:1006 0 scrub mfn=0b98ab
(XEN) Xen BUG at page_alloc.c:738

So in other words, it looks like scrub_heap_pages is somehow not
including this MFN.


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


[Xen-devel] [xen-unstable test] 113460: regressions - FAIL

2017-09-15 Thread osstest service owner
flight 113460 xen-unstable real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113460/

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-i386-xl-qemut-debianhvm-amd64-xsm 10 debian-hvm-install fail REGR. 
vs. 113387
 test-amd64-amd64-xl-credit2  15 guest-saverestorefail REGR. vs. 113387

Regressions which are regarded as allowable (not blocking):
 test-amd64-i386-xl-qemuu-win7-amd64 17 guest-stopfail REGR. vs. 113387
 test-amd64-i386-xl-qemut-win7-amd64 17 guest-stopfail REGR. vs. 113387

Tests which did not succeed, but are not blocking:
 test-armhf-armhf-xl-rtds   16 guest-start/debian.repeat fail blocked in 113387
 test-armhf-armhf-libvirt-xsm 14 saverestore-support-checkfail  like 113387
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail  like 113387
 test-amd64-amd64-xl-qemut-win7-amd64 16 guest-localmigrate/x10 fail like 113387
 test-amd64-amd64-xl-qemuu-win7-amd64 17 guest-stopfail like 113387
 test-amd64-amd64-xl-rtds 10 debian-install   fail  like 113387
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail  like 113387
 test-amd64-amd64-xl-qemut-ws16-amd64 10 windows-installfail never pass
 test-amd64-amd64-xl-qemuu-ws16-amd64 10 windows-installfail never pass
 test-amd64-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt  13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qcow2 12 migrate-support-checkfail  never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 13 guest-saverestore   fail never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-cubietruck 13 migrate-support-checkfail never pass
 test-armhf-armhf-xl-cubietruck 14 saverestore-support-checkfail never pass
 test-armhf-armhf-xl-multivcpu 13 migrate-support-checkfail  never pass
 test-armhf-armhf-xl-multivcpu 14 saverestore-support-checkfail  never pass
 test-amd64-i386-xl-qemut-ws16-amd64 13 guest-saverestore   fail never pass
 test-armhf-armhf-xl-credit2  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit2  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 14 saverestore-support-checkfail   never pass
 test-armhf-armhf-libvirt-raw 12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  13 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemut-win10-i386 10 windows-install fail never pass
 test-amd64-i386-xl-qemuu-win10-i386 10 windows-install fail never pass
 test-amd64-amd64-xl-qemut-win10-i386 10 windows-installfail never pass
 test-amd64-amd64-xl-qemuu-win10-i386 10 windows-installfail never pass

version targeted for testing:
 xen  fc3986d9632f24ad4d40cffd4cad25298e406122
baseline version:
 xen  16b1414de91b5a82a0996c67f6db3af7d7e32873

Last test of basis   113387  2017-09-12 23:20:09 Z2 days
Failing since113430  2017-09-14 01:24:48 Z1 days2 attempts
Testing same since   113460  2017-09-15 02:08:56 Z0 days1 attempts


People who touched revisions under test:
  Andrew Cooper 
  Bhupinder Thakur 
  Boris Ostrovsky 
  Dario Faggioli 
  Haozhong Zhang 
  Ian Jackson 
  Jan Beulich 
  Julien Grall 
  Oleksandr Grytsov 
  

[Xen-devel] [PATCH] qemu-xen-traditional: Link against xentoolcore

2017-09-15 Thread Ian Jackson
This should be inserted into the libxl xen.git series as a qemu tag
update, just after the library is introduced but before it is used.

Signed-off-by: Ian Jackson 
---
 xen-hooks.mak | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xen-hooks.mak b/xen-hooks.mak
index 0ca868f..a68eba3 100644
--- a/xen-hooks.mak
+++ b/xen-hooks.mak
@@ -27,6 +27,7 @@ LIBS += -L$(XEN_ROOT)/tools/libs/gnttab -lxengnttab
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog
+LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toolcore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/devicemodel
-- 
2.1.4


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


[Xen-devel] [ovmf baseline-only test] 72112: all pass

2017-09-15 Thread Platform Team regression test user
This run is configured for baseline tests only.

flight 72112 ovmf real [real]
http://osstest.xs.citrite.net/~osstest/testlogs/logs/72112/

Perfect :-)
All tests in this flight passed as required
version targeted for testing:
 ovmf 11b4463e096523fe03ac840472d483652ae93904
baseline version:
 ovmf b30abe7df464d91b84a42763e61bb3c85bfd80c9

Last test of basis72107  2017-09-15 03:50:43 Z0 days
Testing same since72112  2017-09-15 16:19:31 Z0 days1 attempts


People who touched revisions under test:
  Brijesh Singh 
  Laszlo Ersek 
  Paulo Alcantara 
  Star Zeng 

jobs:
 build-amd64-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-i386   pass
 build-amd64-libvirt  pass
 build-i386-libvirt   pass
 build-amd64-pvopspass
 build-i386-pvops pass
 test-amd64-amd64-xl-qemuu-ovmf-amd64 pass
 test-amd64-i386-xl-qemuu-ovmf-amd64  pass



sg-report-flight on osstest.xs.citrite.net
logs: /home/osstest/logs
images: /home/osstest/images

Logs, config files, etc. are available at
http://osstest.xs.citrite.net/~osstest/testlogs/logs

Test harness code can be found at
http://xenbits.xensource.com/gitweb?p=osstest.git;a=summary


Push not applicable.


commit 11b4463e096523fe03ac840472d483652ae93904
Author: Paulo Alcantara 
Date:   Tue Sep 12 09:30:23 2017 +0800

MdeModulePkg/UdfDxe: Fix NULL pointer dereference

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=704

For root directory, the FID (File Identifier Descriptor) pointer is
accessible through PRIVATE_UDF_FILE_DATA.Root, whereas non-root
directory and regular files, their FIDs are accessible through
PRIVATE_UDF_FILE_DATA.File.

In UdfSetPosition(), the FID was retrieved through
PRIVATE_UDF_FILE_DATA.File, hence when calling it with a root directory,
PRIVATE_UDF_FILE_DATA.File.FileIdentifierDescriptor would be NULL and
then dereferenced.

This patch fixes the NULL pointer dereference by calling _FILE() to
transparently return the correct UDF_FILE_INFO * which points to a valid
FID descriptor of a specific file.

Cc: Star Zeng 
Cc: Eric Dong 
Cc: Ruiyu Ni 
Cc: Laszlo Ersek 
Cc: Steven Shi 
Contributed-under: TianoCore Contribution Agreement 1.1
Reported-by: Steven Shi 
Signed-off-by: Paulo Alcantara 
Reviewed-by: Laszlo Ersek 
Reviewed-by: Star Zeng 

commit 54537008a2f7d4e8a35507af8b523e7b678abacd
Author: Star Zeng 
Date:   Thu Sep 14 18:52:22 2017 +0800

MdeModulePkg UdfDxe: Fix VS2010/VS2012 build failure

VS2010/VS2012 build failure with below info:
warning C4701:
  potentially uninitialized local variable 'DataOffset' used
  potentially uninitialized local variable 'FilePosition' used
  potentially uninitialized local variable 'FinishedSeeking' used
  potentially uninitialized local variable 'Data' used
warning C4703:
  potentially uninitialized local pointer variable 'Data' used

In fact, DataOffset, FilePosition and FinishedSeeking are initialized
and then used if (ReadFileInfo->Flags == READ_FILE_SEEK_AND_READ).
DoFreeAed will be set to TRUE when Data is allocated and returned from
GetAedAdsData(), and Data will be freed if (DoFreeAed) when exiting.

Use same method at 5afa5b815936e2b45a375b6521764195bed68680 to fix
the build failure.

There is related discussion at
https://lists.01.org/pipermail/edk2-devel/2017-September/014641.html

Cc: Laszlo Ersek 
Cc: Eric Dong 
Cc: Paulo Alcantara 
Cc: Ruiyu Ni 
Cc: Liming Gao 
Cc: Dandan Bi 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng 
Reviewed-by: Paulo Alcantara 

commit f60ed5ab7fb39f7327727facd56e58aedaebba31
Author: Brijesh Singh 
Date:   Thu Sep 14 16:22:47 2017 -0500

OvmfPkg/VirtioNetDxe: 

[Xen-devel] [xen-unstable-smoke test] 113480: tolerable all pass - PUSHED

2017-09-15 Thread osstest service owner
flight 113480 xen-unstable-smoke real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113480/

Failures :-/ but no regressions.

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass

version targeted for testing:
 xen  64a00683edcd2ad5b2abcd57783393836dda3110
baseline version:
 xen  fc3986d9632f24ad4d40cffd4cad25298e406122

Last test of basis   113456  2017-09-14 23:02:32 Z0 days
Testing same since   113480  2017-09-15 16:01:27 Z0 days1 attempts


People who touched revisions under test:
  Julien Grall 
  Wei Liu 

jobs:
 build-amd64  pass
 build-armhf  pass
 build-amd64-libvirt  pass
 test-armhf-armhf-xl  pass
 test-amd64-amd64-xl-qemuu-debianhvm-i386 pass
 test-amd64-amd64-libvirt pass



sg-report-flight on osstest.test-lab.xenproject.org
logs: /home/logs/logs
images: /home/logs/images

Logs, config files, etc. are available at
http://logs.test-lab.xenproject.org/osstest/logs

Explanation of these reports, and of osstest in general, is at
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README.email;hb=master
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README;hb=master

Test harness code can be found at
http://xenbits.xen.org/gitweb?p=osstest.git;a=summary


Pushing revision :

+ branch=xen-unstable-smoke
+ revision=64a00683edcd2ad5b2abcd57783393836dda3110
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.
 PERLLIB=.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x '!=' x/home/osstest/repos/lock ']'
++ OSSTEST_REPOS_LOCK_LOCKED=/home/osstest/repos/lock
++ exec with-lock-ex -w /home/osstest/repos/lock ./ap-push xen-unstable-smoke 
64a00683edcd2ad5b2abcd57783393836dda3110
+ branch=xen-unstable-smoke
+ revision=64a00683edcd2ad5b2abcd57783393836dda3110
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.:.
 PERLLIB=.:.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x/home/osstest/repos/lock '!=' x/home/osstest/repos/lock ']'
+ . ./cri-common
++ . ./cri-getconfig
+++ export PERLLIB=.:.:.:.
+++ PERLLIB=.:.:.:.
++ umask 002
+ select_xenbranch
+ case "$branch" in
+ tree=xen
+ xenbranch=xen-unstable-smoke
+ qemuubranch=qemu-upstream-unstable
+ '[' xxen = xlinux ']'
+ linuxbranch=
+ '[' xqemu-upstream-unstable = x ']'
+ select_prevxenbranch
++ ./cri-getprevxenbranch xen-unstable-smoke
+ prevxenbranch=xen-4.9-testing
+ '[' x64a00683edcd2ad5b2abcd57783393836dda3110 = x ']'
+ : tested/2.6.39.x
+ . ./ap-common
++ : osst...@xenbits.xen.org
+++ getconfig OsstestUpstream
+++ perl -e '
use Osstest;
readglobalconfig();
print $c{"OsstestUpstream"} or die $!;
'
++ :
++ : git://xenbits.xen.org/xen.git
++ : osst...@xenbits.xen.org:/home/xen/git/xen.git
++ : git://xenbits.xen.org/qemu-xen-traditional.git
++ : git://git.kernel.org
++ : git://git.kernel.org/pub/scm/linux/kernel/git
++ : git
++ : git://xenbits.xen.org/xtf.git
++ : osst...@xenbits.xen.org:/home/xen/git/xtf.git
++ : git://xenbits.xen.org/xtf.git
++ : git://xenbits.xen.org/libvirt.git
++ : osst...@xenbits.xen.org:/home/xen/git/libvirt.git
++ : git://xenbits.xen.org/libvirt.git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/rumprun.git
++ : git://git.seabios.org/seabios.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/seabios.git
++ : git://xenbits.xen.org/osstest/seabios.git
++ : https://github.com/tianocore/edk2.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/ovmf.git
++ : 

[Xen-devel] [PATCH 1/3] xen: timers: don't miss a timer event because of stop_timer()

2017-09-15 Thread Dario Faggioli
If stop_timer() is called between when a timer interrupt
arrives (and TIMER_SOFTIRQ is raised) and when softirqs are
checked and handled, the timer that has fire is (right in
stop_timer()) deactivated, and the handler for that
occurrence of the interrupt never executed.

This happens, e.g. to timers stopped during the wakeup
from idle (e.g., C-states, on x86) path.

To fix that, don't deactivate a timer, while stopping it,
if it has expired. On the contrary, when that happens,
(re-)raise the timer softirq, to make sure the handler is
invoked.

Signed-off-by: Dario Faggioli 
---
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Jan Beulich 
Cc: Stefano Stabellini 
Cc: Julien Grall 
Cc: Tim Deegan 
---
 xen/common/timer.c |   14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/xen/common/timer.c b/xen/common/timer.c
index d9ff669..b1d1511 100644
--- a/xen/common/timer.c
+++ b/xen/common/timer.c
@@ -217,7 +217,7 @@ static inline void activate_timer(struct timer *timer)
 timer->status = TIMER_STATUS_invalid;
 list_del(>inactive);
 
-if ( add_entry(timer) )
+if ( add_entry(timer) || timer->expires <= NOW() )
 cpu_raise_softirq(timer->cpu, TIMER_SOFTIRQ);
 }
 
@@ -326,7 +326,17 @@ void stop_timer(struct timer *timer)
 return;
 
 if ( active_timer(timer) )
-deactivate_timer(timer);
+{
+/*
+ * If the timer is expired already, 'call' the softirq handler to
+ * execute it (it will leave it inactive after that). If not, just
+ * deactivate it.
+ */
+if ( timer->expires <= NOW() )
+cpu_raise_softirq(timer->cpu, TIMER_SOFTIRQ);
+else
+deactivate_timer(timer);
+}
 
 timer_unlock_irqrestore(timer, flags);
 }


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


[Xen-devel] [PATCH 2/3] xen: RCU: make the period of the idle timer configurable.

2017-09-15 Thread Dario Faggioli
Make it possible for the user to specify, with the boot
time parameter rcu_idle_timer_period_ms, how frequently
a CPU that went idle with pending RCU callbacks should be
woken up to check if the grace period ended.

Typical values (i.e., some of the values used by Linux as
the tick frequency) are 10, 4 or 1 ms. Default valus (used
when this parameter is not specified) is 10ms. Maximum is
100ms.

Signed-off-by: Dario Faggioli 
---
Cc: Jan Beulich 
Cc: Julien Grall 
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Stefano Stabellini ,
Cc: Tim Deegan 
---
 docs/misc/xen-command-line.markdown |9 +
 xen/common/rcupdate.c   |   33 +
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/docs/misc/xen-command-line.markdown 
b/docs/misc/xen-command-line.markdown
index 9797c8d..acacc93 100644
--- a/docs/misc/xen-command-line.markdown
+++ b/docs/misc/xen-command-line.markdown
@@ -1422,6 +1422,15 @@ The following resources are available:
 sum of CBMs is fixed, that means actual `cos_max` in use will automatically
 reduce to half when CDP is enabled.
 
+### rcu\_idle\_timer\_period\_ms
+> `= `
+
+> Default: `10`
+
+How frequently a CPU which has gone idle, but with pending RCU callbacks,
+should be woken up to check if the grace period has completed, and the
+callbacks are safe to be executed. Expressed in milliseconds; maximum is 100ms.
+
 ### reboot
 > `= t[riple] | k[bd] | a[cpi] | p[ci] | P[ower] | e[fi] | n[o] [, [w]arm | 
 > [c]old]`
 
diff --git a/xen/common/rcupdate.c b/xen/common/rcupdate.c
index 871936f..dfd0daf 100644
--- a/xen/common/rcupdate.c
+++ b/xen/common/rcupdate.c
@@ -110,10 +110,35 @@ struct rcu_data {
  * About how far in the future the timer should be programmed each time,
  * it's hard to tell (guess!!). Since this mimics Linux's periodic timer
  * tick, take values used there as an indication. In Linux 2.6.21, tick
- * period can be 10ms, 4ms, 3.33ms or 1ms. Let's use 10ms, to enable
- * at least some power saving on the CPU that is going idle.
+ * period can be 10ms, 4ms, 3.33ms or 1ms.
+ *
+ * By default, we use 10ms, to enable at least some power saving on the
+ * CPU that is going idle. The user can change this, via a boot time
+ * parameter, but only up to 100ms.
  */
-#define RCU_IDLE_TIMER_PERIOD MILLISECS(10)
+#define IDLE_TIMER_PERIOD_MAX MILLISECS(100)
+#define IDLE_TIMER_PERIOD_DEFAULT MILLISECS(10)
+static s_time_t __read_mostly idle_timer_period = IDLE_TIMER_PERIOD_DEFAULT;
+
+static int parse_idle_timer_period(const char *s)
+{
+long unsigned int period = simple_strtoul(s, NULL, 10);
+int ret = 0;
+
+if ( MILLISECS(period) > IDLE_TIMER_PERIOD_MAX )
+{
+printk("WARNING: rcu_idle_timer_period_ms must be < %"PRI_stime"\n",
+   IDLE_TIMER_PERIOD_MAX / MILLISECS(1));
+ret = -EINVAL;
+}
+else
+idle_timer_period = MILLISECS(period);
+
+printk("RCU idle timer period: %lums\n", period);
+
+return ret;
+}
+custom_param("rcu_idle_timer_period_ms", parse_idle_timer_period);
 
 static DEFINE_PER_CPU(struct rcu_data, rcu_data);
 
@@ -453,7 +478,7 @@ void rcu_idle_timer_start()
 if (likely(!rdp->curlist))
 return;
 
-set_timer(>idle_timer, NOW() + RCU_IDLE_TIMER_PERIOD);
+set_timer(>idle_timer, NOW() + idle_timer_period);
 rdp->idle_timer_active = true;
 }
 


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


[Xen-devel] [PATCH 0/3] xen: RCU: Improve the idle timer handling

2017-09-15 Thread Dario Faggioli
Hello,

this series is the followup of my previous RCU series. It contains:
- the patch that makes the period of the RCU idle timer configurable, via a Xen
  boot time parameter, as suggested by Jan, during review of the original series
  (patch 2);
- the patch that makse the period of the RCU idle timer adaptive, but using the
  algorithm suggested by George, during review of the original series (patch 3).

Patch 1 is a fix for the fact that if we stop a timer that has already expired,
right now, we miss invoking the timer handler! This is a general bug, but is
particularly relevant for this series, as, without it, the RCU idle timer
handler is never run (and hence, George's algorithm can't work :-/).

Regards,
Dario
---
Dario Faggioli (3):
  xen: timers: don't miss a timer event because of stop_timer()
  xen: RCU: make the period of the idle timer configurable.
  xen: RCU: make the period of the idle timer adaptive.

 docs/misc/xen-command-line.markdown |9 ++
 xen/common/rcupdate.c   |   57 ---
 xen/common/timer.c  |   14 +++--
 3 files changed, 73 insertions(+), 7 deletions(-)
--
<> (Raistlin Majere)
-
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R Ltd., Cambridge (UK)

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


[Xen-devel] [PATCH 3/3] xen: RCU: make the period of the idle timer adaptive.

2017-09-15 Thread Dario Faggioli
Basically, if the RCU idle timer, when (if!) it fires,
finds that the grace period isn't over, we increase the
timer's period (i.e., it will fire later, next time).
If, OTOH, it finds the grace period is already finished,
we decrease the timer's period (i.e., it will fire a bit
earlier next time).

The goal is to let the period timer sefl-adjust to a
number of 'misses', of the order of 1%.

Signed-off-by: Dario Faggioli 
Suggested-by: George Dunlap 
---
Cc: Jan Beulich 
Cc: Julien Grall 
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Stefano Stabellini ,
Cc: Tim Deegan 
---
 xen/common/rcupdate.c |   24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/xen/common/rcupdate.c b/xen/common/rcupdate.c
index dfd0daf..9a708ef 100644
--- a/xen/common/rcupdate.c
+++ b/xen/common/rcupdate.c
@@ -118,6 +118,7 @@ struct rcu_data {
  */
 #define IDLE_TIMER_PERIOD_MAX MILLISECS(100)
 #define IDLE_TIMER_PERIOD_DEFAULT MILLISECS(10)
+#define IDLE_TIMER_PERIOD_MIN MICROSECS(100)
 static s_time_t __read_mostly idle_timer_period = IDLE_TIMER_PERIOD_DEFAULT;
 
 static int parse_idle_timer_period(const char *s)
@@ -140,6 +141,17 @@ static int parse_idle_timer_period(const char *s)
 }
 custom_param("rcu_idle_timer_period_ms", parse_idle_timer_period);
 
+/*
+ * Increment and decrement values for the idle timer handler. The algorithm
+ * works as follows:
+ * - if the timer actually fires, and it finds out that the grace period isn't
+ *   over yet, we add IDLE_TIMER_PERIOD_INCR to the timer's period;
+ * - if the timer actually fires and it finds the grace period over, we
+ *   subtract IDLE_TIMER_PERIOD_DECR from the timer's period.
+ */
+#define IDLE_TIMER_PERIOD_INCRMILLISECS(10)
+#define IDLE_TIMER_PERIOD_DECRMICROSECS(100)
+
 static DEFINE_PER_CPU(struct rcu_data, rcu_data);
 
 static int blimit = 10;
@@ -495,8 +507,18 @@ void rcu_idle_timer_stop()
 
 static void rcu_idle_timer_handler(void* data)
 {
-/* Nothing, really... Just count the number of times we fire */
 perfc_incr(rcu_idle_timer);
+
+if ( !cpumask_empty(_ctrlblk.cpumask) )
+{
+idle_timer_period = min_t(s_time_t, IDLE_TIMER_PERIOD_MAX,
+  idle_timer_period + IDLE_TIMER_PERIOD_INCR);
+}
+else
+{
+idle_timer_period = max_t(s_time_t, IDLE_TIMER_PERIOD_MIN,
+  idle_timer_period - IDLE_TIMER_PERIOD_DECR);
+}
 }
 
 void rcu_check_callbacks(int cpu)


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


[Xen-devel] [PATCH 4/4] xen: sched: simplify (and speedup) checking soft-affinity

2017-09-15 Thread Dario Faggioli
The fact of whether or not a vCPU has a soft-affinity
which is effective, i.e., with the power of actually
affecting the scheduling of the vCPU itself rarely
changes. Very, very rarely, as compared to how often
we need to check for the same thing (basically, at
every scheduling decision!).

That can be improved by storing in a (per-vCPU) flag
(it's actually a boolean field in struct vcpu) whether
or not, considering how hard-affinity and soft-affinity
look like, soft-affinity should or not be taken into
account during scheduling decisions.

This saves some cpumask manipulations, which is nice,
considering how frequently they were being done. Note
that we can't get rid of 100% of the cpumask operations
involved in the check, because soft-affinity being
effective or not, not only depends on the relationship
between the hard and soft-affinity masks of a vCPU, but
also of the online pCPUs and/or of what pCPUs are part
of the cpupool where the vCPU lives, and that's rather
impractical to store in a per-vCPU flag. Still the
overhead is reduced to "just" one cpumask_subset() (and
only if the newly introduced flag is 'true')!

Signed-off-by: Dario Faggioli 
---
Cc: George Dunlap 
Cc: Anshul Makkar 
---
 xen/common/schedule.c  |5 +
 xen/include/xen/sched-if.h |7 +++
 xen/include/xen/sched.h|2 ++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index a8b82fd..284df66 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -854,6 +854,11 @@ void sched_set_affinity(
 cpumask_copy(v->cpu_hard_affinity, hard);
 if ( soft )
 cpumask_copy(v->cpu_hard_affinity, soft);
+
+v->soft_aff_effective = !cpumask_subset(v->cpu_hard_affinity,
+v->cpu_soft_affinity) &&
+cpumask_intersects(v->cpu_soft_affinity,
+   v->cpu_hard_affinity);
 }
 
 static int vcpu_set_affinity(
diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h
index 417789a..1f4ff1b 100644
--- a/xen/include/xen/sched-if.h
+++ b/xen/include/xen/sched-if.h
@@ -247,10 +247,9 @@ static inline cpumask_t* cpupool_domain_cpumask(struct 
domain *d)
  */
 static inline int has_soft_affinity(const struct vcpu *v)
 {
-return !cpumask_subset(cpupool_domain_cpumask(v->domain),
-   v->cpu_soft_affinity) &&
-   !cpumask_subset(v->cpu_hard_affinity, v->cpu_soft_affinity) &&
-   cpumask_intersects(v->cpu_soft_affinity, v->cpu_hard_affinity);
+return v->soft_aff_effective &&
+   !cpumask_subset(cpupool_domain_cpumask(v->domain),
+   v->cpu_soft_affinity);
 }
 
 /*
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 4f386f1..68c66f3 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -210,6 +210,8 @@ struct vcpu
 bool hcall_compat;
 #endif
 
+/* Does soft affinity actually play a role (given hard affinity)? */
+bool soft_aff_effective;
 
 /*
  * > 0: a single port is being polled;


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


[Xen-devel] [PATCH 2/4] xen: sched: optimize exclusive pinning case (Credit1 & 2)

2017-09-15 Thread Dario Faggioli
Exclusive pinning of vCPUs is used, sometimes, for
achieving the highest level of determinism, and the
least possible overhead, for the vCPUs in question.

Although static 1:1 pinning is not recommended, for
general use cases, optimizing the tickling code (of
Credit1 and Credit2) is easy and cheap enough, so go
for it.

Signed-off-by: Dario Faggioli 
---
Cc: George Dunlap 
Cc: Anshul Makkar 
---
Changes from v1:
- use a flag during runtime, as suggested during review;
- make use of the affinity-change hook, introduced in pevious patch.
---
 xen/common/sched_credit.c|   35 +++
 xen/common/sched_credit2.c   |   40 
 xen/include/xen/perfc_defn.h |1 +
 3 files changed, 76 insertions(+)

diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c
index 4fdaa08..3efbfc8 100644
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -73,6 +73,7 @@
 #define CSCHED_FLAG_VCPU_PARKED0x0  /* VCPU over capped credits */
 #define CSCHED_FLAG_VCPU_YIELD 0x1  /* VCPU yielding */
 #define CSCHED_FLAG_VCPU_MIGRATING 0x2  /* VCPU may have moved to a new pcpu */
+#define CSCHED_FLAG_VCPU_PINNED0x4  /* VCPU can run only on 1 pcpu */
 
 
 /*
@@ -362,6 +363,25 @@ static inline void __runq_tickle(struct csched_vcpu *new)
 idlers_empty = cpumask_empty(_mask);
 
 /*
+ * Exclusive pinning is when a vcpu has hard-affinity with only one
+ * cpu, and there is no other vcpu that has hard-affinity with that
+ * same cpu. This is infrequent, but if it happens, is for achieving
+ * the most possible determinism, and least possible overhead for
+ * the vcpus in question.
+ *
+ * Try to identify the vast majority of these situations, and deal
+ * with them quickly.
+ */
+if ( unlikely(test_bit(CSCHED_FLAG_VCPU_PINNED, >flags) &&
+  cpumask_test_cpu(cpu, _mask)) )
+{
+ASSERT(cpumask_cycle(cpu, new->vcpu->cpu_hard_affinity) == cpu);
+SCHED_STAT_CRANK(tickled_idle_cpu_excl);
+__cpumask_set_cpu(cpu, );
+goto tickle;
+}
+
+/*
  * If the pcpu is idle, or there are no idlers and the new
  * vcpu is a higher priority than the old vcpu, run it here.
  *
@@ -457,6 +477,7 @@ static inline void __runq_tickle(struct csched_vcpu *new)
 }
 }
 
+ tickle:
 if ( !cpumask_empty() )
 {
 if ( unlikely(tb_init_done) )
@@ -1223,6 +1244,19 @@ csched_dom_cntl(
 return rc;
 }
 
+static void
+csched_aff_cntl(const struct scheduler *ops, struct vcpu *v,
+const cpumask_t *hard, const cpumask_t *soft)
+{
+struct csched_vcpu *svc = CSCHED_VCPU(v);
+
+/* Are we becoming exclusively pinned? */
+if ( cpumask_weight(hard) == 1 )
+set_bit(CSCHED_FLAG_VCPU_PINNED, >flags);
+else
+clear_bit(CSCHED_FLAG_VCPU_PINNED, >flags);
+}
+
 static inline void
 __csched_set_tslice(struct csched_private *prv, unsigned timeslice)
 {
@@ -2270,6 +2304,7 @@ static const struct scheduler sched_credit_def = {
 .yield  = csched_vcpu_yield,
 
 .adjust = csched_dom_cntl,
+.adjust_affinity= csched_aff_cntl,
 .adjust_global  = csched_sys_cntl,
 
 .pick_cpu   = csched_cpu_pick,
diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c
index 32234ac..e1985fb 100644
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -299,6 +299,12 @@
  */
 #define __CSFLAG_vcpu_yield 4
 #define CSFLAG_vcpu_yield (1U<<__CSFLAG_vcpu_yield)
+/*
+ * CSFLAGS_pinned: this vcpu is currently 'pinned', i.e., has its hard
+ * affinity set to one and only 1 cpu (and, hence, can only run there).
+ */
+#define __CSFLAG_pinned 5
+#define CSFLAG_pinned (1U<<__CSFLAG_pinned)
 
 static unsigned int __read_mostly opt_migrate_resist = 500;
 integer_param("sched_credit2_migrate_resist", opt_migrate_resist);
@@ -1453,6 +1459,26 @@ runq_tickle(const struct scheduler *ops, struct 
csched2_vcpu *new, s_time_t now)
 (unsigned char *));
 }
 
+/*
+ * Exclusive pinning is when a vcpu has hard-affinity with only one
+ * cpu, and there is no other vcpu that has hard-affinity with that
+ * same cpu. This is infrequent, but if it happens, is for achieving
+ * the most possible determinism, and least possible overhead for
+ * the vcpus in question.
+ *
+ * Try to identify the vast majority of these situations, and deal
+ * with them quickly.
+ */
+if ( unlikely((new->flags & CSFLAG_pinned) &&
+  cpumask_test_cpu(cpu, >idle) &&
+  !cpumask_test_cpu(cpu, >tickled)) )
+{
+ASSERT(cpumask_cycle(cpu, new->vcpu->cpu_hard_affinity) == cpu);
+SCHED_STAT_CRANK(tickled_idle_cpu_excl);
+ipid = cpu;
+goto tickle;
+}
+
 for_each_affinity_balance_step( bs )
 {
 /* 

[Xen-devel] [PATCH 1/4] xen: sched: introduce 'adjust_affinity' hook.

2017-09-15 Thread Dario Faggioli
For now, just as a way to give a scheduler an "heads up",
about the fact that the affinity changed.

This enables some optimizations, such as pre-computing
and storing (e.g., in flags) facts like a vcpu being
exclusively pinned to a pcpu, or having or not a
soft affinity. I.e., conditions that, despite the fact
that they rarely change, are right now checked very
frequently, even in hot paths.

Note also that this, in future, may turn out as a useful
mean for, e.g., having the schedulers vet, ack or nack
the changes themselves.

Signed-off-by: Dario Faggioli 
---
Cc: George Dunlap 
Cc: Anshul Makkar 
---
 xen/arch/x86/dom0_build.c  |4 +--
 xen/common/schedule.c  |   62 +---
 xen/include/xen/sched-if.h |3 ++
 xen/include/xen/sched.h|3 ++
 4 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c
index f616b99..94e4b7f 100644
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -125,8 +125,8 @@ struct vcpu *__init dom0_setup_vcpu(struct domain *d,
 if ( v )
 {
 if ( !d->is_pinned && !dom0_affinity_relaxed )
-cpumask_copy(v->cpu_hard_affinity, _cpus);
-cpumask_copy(v->cpu_soft_affinity, _cpus);
+sched_set_affinity(v, _cpus, NULL);
+sched_set_affinity(v, NULL, _cpus);
 }
 
 return v;
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index 8827921..a8b82fd 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -256,6 +256,9 @@ static void sched_spin_unlock_double(spinlock_t *lock1, 
spinlock_t *lock2,
 int sched_init_vcpu(struct vcpu *v, unsigned int processor) 
 {
 struct domain *d = v->domain;
+cpumask_t allcpus;
+
+cpumask_setall();
 
 /*
  * Initialize processor and affinity settings. The idler, and potentially
@@ -263,11 +266,9 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor)
  */
 v->processor = processor;
 if ( is_idle_domain(d) || d->is_pinned )
-cpumask_copy(v->cpu_hard_affinity, cpumask_of(processor));
+sched_set_affinity(v, cpumask_of(processor), );
 else
-cpumask_setall(v->cpu_hard_affinity);
-
-cpumask_setall(v->cpu_soft_affinity);
+sched_set_affinity(v, , );
 
 /* Initialise the per-vcpu timers. */
 init_timer(>periodic_timer, vcpu_periodic_timer_fn,
@@ -359,6 +360,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
 for_each_vcpu ( d, v )
 {
 spinlock_t *lock;
+cpumask_t allcpus;
 
 vcpudata = v->sched_priv;
 
@@ -366,10 +368,12 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
 migrate_timer(>singleshot_timer, new_p);
 migrate_timer(>poll_timer, new_p);
 
-cpumask_setall(v->cpu_hard_affinity);
-cpumask_setall(v->cpu_soft_affinity);
+cpumask_setall();
 
 lock = vcpu_schedule_lock_irq(v);
+
+sched_set_affinity(v, , );
+
 v->processor = new_p;
 /*
  * With v->processor modified we must not
@@ -680,7 +684,7 @@ void restore_vcpu_affinity(struct domain *d)
 
 if ( v->affinity_broken )
 {
-cpumask_copy(v->cpu_hard_affinity, v->cpu_hard_affinity_saved);
+sched_set_affinity(v, v->cpu_hard_affinity_saved, NULL);
 v->affinity_broken = 0;
 
 }
@@ -744,6 +748,8 @@ int cpu_disable_scheduler(unsigned int cpu)
 if ( cpumask_empty(_affinity) &&
  cpumask_test_cpu(cpu, v->cpu_hard_affinity) )
 {
+cpumask_t allcpus;
+
 if ( v->affinity_broken )
 {
 /* The vcpu is temporarily pinned, can't move it. */
@@ -761,7 +767,8 @@ int cpu_disable_scheduler(unsigned int cpu)
 else
 printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v);
 
-cpumask_setall(v->cpu_hard_affinity);
+cpumask_setall();
+sched_set_affinity(v, , NULL);
 }
 
 if ( v->processor != cpu )
@@ -831,8 +838,26 @@ int cpu_disable_scheduler(unsigned int cpu)
 return ret;
 }
 
+/*
+ * In general, this must be called with the scheduler lock held, because the
+ * adjust_affinity hook may want to modify the vCPU state. However, when the
+ * vCPU is being initialized (either for dom0 or domU) there is no risk of
+ * races, and it's fine to not take the look (we're talking about
+ * dom0_setup_vcpu() an sched_init_vcpu()).
+ */
+void sched_set_affinity(
+struct vcpu *v, const cpumask_t *hard, const cpumask_t *soft)
+{
+SCHED_OP(dom_scheduler(v->domain), adjust_affinity, v, hard, soft);
+
+if ( hard )
+cpumask_copy(v->cpu_hard_affinity, hard);
+if ( soft )
+cpumask_copy(v->cpu_hard_affinity, soft);
+}
+
 static int vcpu_set_affinity(
-struct 

[Xen-devel] [PATCH 0/4] xen: sched: optimize exclusive pinning and soft-affinity checking

2017-09-15 Thread Dario Faggioli
Hello,

This series is a rework of a patch that was, originally, sent as part of a
series (which went in already):

 https://lists.xen.org/archives/html/xen-devel/2017-07/msg02167.html

As it can be seen in the message above, George suggested doing things a little
bit differently, and I agreed. however, that:
- require a bit more of rework than expected, but here we are;
- opened the possibility for even more optimization. :-)

Basically, the effect of the series is that:
1) when a vCPU is exclusively pinned to a pCPU, a lot of checks, while making
   scheduling decisions in Credit1 and Credit2, are skipped (patch 2);
2) the check to see whether or not a vCPU has a soft-affinity that actually
   matters for the scheduling of the vCPU itself, and should be considered is
   optimized and made faster (patch 4).

So, the important bits are in patches 2 and 4, but both patches 1 and 3 are
necessary to make the other twos possible.

Regards,
Dario
---
Dario Faggioli (4):
  xen: sched: introduce 'adjust_affinity' hook.
  xen: sched: optimize exclusive pinning case (Credit1 & 2)
  xen: sched: improve checking soft-affinity
  xen: sched: simplify (and speedup) checking soft-affinity

 xen/arch/x86/dom0_build.c|4 +
 xen/common/sched_credit.c|  114 +++---
 xen/common/sched_credit2.c   |   50 --
 xen/common/sched_null.c  |8 +--
 xen/common/schedule.c|   67 +++--
 xen/include/xen/perfc_defn.h |1 
 xen/include/xen/sched-if.h   |   16 +++---
 xen/include/xen/sched.h  |5 ++
 8 files changed, 188 insertions(+), 77 deletions(-)
--
<> (Raistlin Majere)
-
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R Ltd., Cambridge (UK)

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


[Xen-devel] [PATCH 3/4] xen: sched: improve checking soft-affinity

2017-09-15 Thread Dario Faggioli
Whether or not a vCPU has a soft-affinity which is
effective, i.e., with the power of actually affecting
the scheduling of the vCPU itself, happens in an
helper function, called has_soft_affinity().

Such function takes a custom cpumask as its third
parameter, for better flexibility, but that mask is
different from the vCPU's hard-affinity only in one
case. Getting rid of that parameter, not only simplify
the function, but enables for optimizing the soft
affinity check (which will happen, in a subsequent
commit).

This commit, therefore, does that. It's mostly
mechanical, with the only exception _csched_cpu_pick()
(in Credit1 code).

Signed-off-by: Dario Faggioli 
---
Cc: George Dunlap 
Cc: Anshul Makkar 
---
 xen/common/sched_credit.c  |   79 +---
 xen/common/sched_credit2.c |   10 ++
 xen/common/sched_null.c|8 ++--
 xen/include/xen/sched-if.h |8 ++--
 4 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c
index 3efbfc8..35d0c98 100644
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -410,8 +410,7 @@ static inline void __runq_tickle(struct csched_vcpu *new)
 int new_idlers_empty;
 
 if ( balance_step == BALANCE_SOFT_AFFINITY
- && !has_soft_affinity(new->vcpu,
-   new->vcpu->cpu_hard_affinity) )
+ && !has_soft_affinity(new->vcpu) )
 continue;
 
 /* Are there idlers suitable for new (for this balance step)? */
@@ -743,50 +742,42 @@ __csched_vcpu_is_migrateable(struct vcpu *vc, int 
dest_cpu, cpumask_t *mask)
 static int
 _csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc, bool_t commit)
 {
-cpumask_t cpus;
 cpumask_t idlers;
-cpumask_t *online;
+cpumask_t *online = cpupool_domain_cpumask(vc->domain);
 struct csched_pcpu *spc = NULL;
 int cpu = vc->processor;
 int balance_step;
 
-/* Store in cpus the mask of online cpus on which the domain can run */
-online = cpupool_domain_cpumask(vc->domain);
-cpumask_and(, vc->cpu_hard_affinity, online);
-
 for_each_affinity_balance_step( balance_step )
 {
+affinity_balance_cpumask(vc, balance_step, cpumask_scratch_cpu(cpu));
+cpumask_and(cpumask_scratch_cpu(cpu), online, 
cpumask_scratch_cpu(cpu));
 /*
  * We want to pick up a pcpu among the ones that are online and
- * can accommodate vc, which is basically what we computed above
- * and stored in cpus. As far as hard affinity is concerned,
- * there always will be at least one of these pcpus, hence cpus
- * is never empty and the calls to cpumask_cycle() and
- * cpumask_test_cpu() below are ok.
+ * can accommodate vc. As far as hard affinity is concerned, there
+ * always will be at least one of these pcpus in the scratch cpumask,
+ * hence, the calls to cpumask_cycle() and cpumask_test_cpu() below
+ * are ok.
  *
- * On the other hand, when considering soft affinity too, it
- * is possible for the mask to become empty (for instance, if the
- * domain has been put in a cpupool that does not contain any of the
- * pcpus in its soft affinity), which would result in the ASSERT()-s
- * inside cpumask_*() operations triggering (in debug builds).
+ * On the other hand, when considering soft affinity, it is possible
+ * that the mask is empty (for instance, if the domain has been put
+ * in a cpupool that does not contain any of the pcpus in its soft
+ * affinity), which would result in the ASSERT()-s inside cpumask_*()
+ * operations triggering (in debug builds).
  *
- * Therefore, in this case, we filter the soft affinity mask against
- * cpus and, if the result is empty, we just skip the soft affinity
+ * Therefore, if that is the case, we just skip the soft affinity
  * balancing step all together.
  */
-if ( balance_step == BALANCE_SOFT_AFFINITY
- && !has_soft_affinity(vc, ) )
+if ( balance_step == BALANCE_SOFT_AFFINITY &&
+ (!has_soft_affinity(vc) ||
+  cpumask_empty(cpumask_scratch_cpu(cpu))) )
 continue;
 
-/* Pick an online CPU from the proper affinity mask */
-affinity_balance_cpumask(vc, balance_step, );
-cpumask_and(, , online);
-
 /* If present, prefer vc's current processor */
-cpu = cpumask_test_cpu(vc->processor, )
+cpu = cpumask_test_cpu(vc->processor, cpumask_scratch_cpu(cpu))
 ? vc->processor
-: cpumask_cycle(vc->processor, );
-ASSERT(cpumask_test_cpu(cpu, ));
+: cpumask_cycle(vc->processor, cpumask_scratch_cpu(cpu));

Re: [Xen-devel] [PATCH v2 13/17] x86emul: re-order checks in test harness

2017-09-15 Thread Andrew Cooper

On 14/09/17 16:19, Jan Beulich wrote:

On older systems printing the "n/a" messages (resulting from the
compiler not being new enough to deal with some of the test code) isn't
very useful: If both CPU and compiler are too old for a certain test,
we can as well omit those messages, as those tests wouldn't be run even
if the compiler did produce code. (This has become obvious with the
3DNow! tests, which I had to run on an older system still supporting
those insns, and that system naturally also had an older compiler.)

Signed-off-by: Jan Beulich 


Reviewed-by: Andrew Cooper 

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


Re: [Xen-devel] [PATCH v3] hvmloader: Use MB(x) and GB(x) macros

2017-09-15 Thread Konrad Rzeszutek Wilk
On Fri, Sep 15, 2017 at 05:57:50PM +0100, Wei Liu wrote:
> On Fri, Sep 15, 2017 at 12:55:51PM -0400, Konrad Rzeszutek Wilk wrote:
> > instead of hardcoding values. We also drop the uint64_t
> > cast as the macro uses ULL to produce the proper width
> > types.
> > 
> > Acked-by: Jan Beulich 
> > Signed-off-by: Konrad Rzeszutek Wilk 
> 
> You've got Jan's ack so you can commit it right away. :-)

True, but that was a year ago. It may have expired.

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


Re: [Xen-devel] [PATCH v2 02/17] x86emul: re-order cases of main switch statement

2017-09-15 Thread Andrew Cooper

On 14/09/17 16:12, Jan Beulich wrote:

Re-store intended numerical ordering, which has become "violated"
mostly by incremental additions where moving around bigger chunks did
not seem advisable. One exception though at the very top of the
switch(): Keeping the arithmetic ops together seems preferable over
entirely strict ordering.

Additionally move a few macro definitions before their first uses (the
placement is benign as long as those uses are themselves only macro
definitions, but that's going to change when those macros have helpers
broken out).

No (intended) functional change.

Signed-off-by: Jan Beulich 
Reviewed-by: George Dunlap 


Reviewed-by: Andrew Cooper 

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


Re: [Xen-devel] [PATCH v2 08/17] x86emul: fold/eliminate some local variables

2017-09-15 Thread Andrew Cooper

On 14/09/17 16:16, Jan Beulich wrote:

Make i switch-wide (at once making it unsigned, as it should have been)
and introduce n (for immediate use in enter and aam/aad handling).
Eliminate on-stack arrays in pusha/popa handling. Use ea.val instead of
a custom variable in bound handling.

No (intended) functional change.

Signed-off-by: Jan Beulich 


Reviewed-by: Andrew Cooper 

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


Re: [Xen-devel] [PATCH] mm: Scrub pages returned back to heap if MEMF_no_scrub is set

2017-09-15 Thread Konrad Rzeszutek Wilk
On Fri, Sep 15, 2017 at 12:47:29PM -0400, Boris Ostrovsky wrote:
> On 09/15/2017 12:05 PM, Jan Beulich wrote:
>  On 15.09.17 at 16:04,  wrote:
> >> Set free_heap_pages()'s need_scrub to true if alloc_domheap_pages()
> >> returns pages back to heap as result of assign_pages() error when those
> >> pages were requested with MEMF_no_scrub flag.
> >>
> >> We need to do this because there is a possibility that
> >> alloc_heap_pages() might clear buddy's PGC_need_scrubs flag without
> >> actually clearing the page.
> >>
> >> Signed-off-by: Boris Ostrovsky 
> >> ---
> >> We are declaring a likely clean (or almost clean) chunk to be dirty. Since
> >> this only happend on assign_pages() error I figured it would be acceptable.
> > I think that's fine, but let's wait a little to see whether others
> > have differing opinions.
> >
> >> --- a/xen/common/page_alloc.c
> >> +++ b/xen/common/page_alloc.c
> >> @@ -2227,7 +2227,7 @@ struct page_info *alloc_domheap_pages(
> >>  if ( d && !(memflags & MEMF_no_owner) &&
> >>   assign_pages(d, pg, order, memflags) )
> >>  {
> >> -free_heap_pages(pg, order, false);
> >> +free_heap_pages(pg, order, !!(memflags & MEMF_no_scrub));
> > No need for the !! (easily fixed while committing). 
> 
> Sure.
> 
> > With that
> > Reviewed-by: Jan Beulich 
> >
> > I take it this isn't related to the issue on ARM64 that Konrad has
> > found?
> 
> 
> It's related in the sense that I noticed this while looking at Konrad's
> problem. Whether or not it also fixes his issue --- I don't know. If it
> does then I think it will indicate that something else is going on there
> since this would mean he is hitting assign_pages() error.

Sadly no. Let me update the other email.
> 
> 
> -boris

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


Re: [Xen-devel] [PATCH 1/3] python: Add binding for xs_fileno()

2017-09-15 Thread Konrad Rzeszutek Wilk
On Fri, Sep 15, 2017 at 05:35:34PM +0100, Euan Harris wrote:
> xs_fileno() returns a file descriptor which receives events when Xenstore
> watches fire.   Exposing this in the Python bindings is a prerequisite
> for writing event-driven clients in Python.
> 
> Signed-off-by: Euan Harris 

Reviewed-by: Konrad Rzeszutek Wilk 

> ---
>  tools/python/xen/lowlevel/xs/xs.c | 20 
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/python/xen/lowlevel/xs/xs.c 
> b/tools/python/xen/lowlevel/xs/xs.c
> index aba5a20..9f1b916 100644
> --- a/tools/python/xen/lowlevel/xs/xs.c
> +++ b/tools/python/xen/lowlevel/xs/xs.c
> @@ -453,6 +453,25 @@ static PyObject *xspy_watch(XsHandle *self, PyObject 
> *args)
>  }
>  
>  
> +#define xspy_fileno_doc "\n"  \
> + "Return the FD to poll for notifications when watches fire.\n"   \
> + "Returns: [int] file descriptor.\n"\
> + "\n"
> +
> +static PyObject *xspy_fileno(XsHandle *self)
> +{
> +struct xs_handle *xh = xshandle(self);
> +int fd;
> +
> +if (!xh)
> +return NULL;
> +
> +fd = xs_fileno(xh);
> +
> +return PyInt_FromLong(fd);
> +}
> +
> +
>  #define xspy_read_watch_doc "\n" \
>   "Read a watch notification.\n"  \
>   "\n"\
> @@ -887,6 +906,7 @@ static PyMethodDef xshandle_methods[] = {
>  XSPY_METH(release_domain,METH_VARARGS),
>  XSPY_METH(close, METH_NOARGS),
>  XSPY_METH(get_domain_path,   METH_VARARGS),
> +XSPY_METH(fileno,METH_NOARGS),
>  { NULL /* Sentinel. */ },
>  };
>  
> -- 
> 1.8.3.1
> 
> 
> ___
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> https://lists.xen.org/xen-devel

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


Re: [Xen-devel] [PATCH v3] hvmloader: Use MB(x) and GB(x) macros

2017-09-15 Thread Wei Liu
On Fri, Sep 15, 2017 at 12:55:51PM -0400, Konrad Rzeszutek Wilk wrote:
> instead of hardcoding values. We also drop the uint64_t
> cast as the macro uses ULL to produce the proper width
> types.
> 
> Acked-by: Jan Beulich 
> Signed-off-by: Konrad Rzeszutek Wilk 

You've got Jan's ack so you can commit it right away. :-)

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


[Xen-devel] [PATCH v3] Left over patches from long-time ago.

2017-09-15 Thread Konrad Rzeszutek Wilk
Hey,

I was cleaning my mailbox and noticed that I still hadn't this done.
This one was from 2016 and it looks like I just never sent it out
(even thought I did the fix the next day). I never got to fix
the other patch:
https://lists.xen.org/archives/html/xen-devel/2016-09/msg03191.html

Anyhow, sending the first out and will commit it next week if nobody
complains.

The last reply was from Jan: 57ecd46b027800113...@prv-mh.provo.novell.com
https://lists.xen.org/archives/html/xen-devel/2016-09/msg03228.html

Thanks!

 tools/firmware/hvmloader/e820.c   | 6 +++---
 tools/firmware/hvmloader/pci.c| 8 
 tools/firmware/hvmloader/smbios.c | 5 ++---
 tools/firmware/hvmloader/util.h   | 3 +++
 4 files changed, 12 insertions(+), 10 deletions(-)


Konrad Rzeszutek Wilk (1):
  hvmloader: Use MB(x) and GB(x) macros


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


[Xen-devel] [PATCH v3] hvmloader: Use MB(x) and GB(x) macros

2017-09-15 Thread Konrad Rzeszutek Wilk
instead of hardcoding values. We also drop the uint64_t
cast as the macro uses ULL to produce the proper width
types.

Acked-by: Jan Beulich 
Signed-off-by: Konrad Rzeszutek Wilk 

---
Cc: Jan Beulich 
Cc: Andrew Cooper 
Cc: Ian Jackson 
Cc: Wei Liu 

v2: New submission
v3: Don't use leading underscores in macro.
  - Drop the uint64_t cast
  - Added Jan's Ack.
---
 tools/firmware/hvmloader/e820.c   | 6 +++---
 tools/firmware/hvmloader/pci.c| 8 
 tools/firmware/hvmloader/smbios.c | 5 ++---
 tools/firmware/hvmloader/util.h   | 3 +++
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
index 5541b18705..4d1c955a02 100644
--- a/tools/firmware/hvmloader/e820.c
+++ b/tools/firmware/hvmloader/e820.c
@@ -82,7 +82,7 @@ void adjust_memory_map(void)
 
 /* Modify the existing highmem region if it exists. */
 if ( memory_map.map[i].type == E820_RAM &&
- high_mem_end && map_start == ((uint64_t)1 << 32) )
+ high_mem_end && map_start == GB(4) )
 {
 if ( high_mem_end != map_end )
 memory_map.map[i].size = high_mem_end - map_start;
@@ -94,7 +94,7 @@ void adjust_memory_map(void)
 /* If there was no highmem region, just create one. */
 if ( high_mem_end )
 {
-memory_map.map[i].addr = ((uint64_t)1 << 32);
+memory_map.map[i].addr = GB(4);
 memory_map.map[i].size =
 ((uint64_t)hvm_info->high_mem_pgend << PAGE_SHIFT) -
 memory_map.map[i].addr;
@@ -234,7 +234,7 @@ int build_e820_table(struct e820entry *e820,
 }
 
 /* Low RAM goes here. Reserve space for special pages. */
-BUG_ON(low_mem_end < (2u << 20));
+BUG_ON(low_mem_end < MB(2));
 
 /*
  * Construct E820 table according to recorded memory map.
diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
index 9543e5aaf2..0b708bf578 100644
--- a/tools/firmware/hvmloader/pci.c
+++ b/tools/firmware/hvmloader/pci.c
@@ -59,7 +59,7 @@ static int find_next_rmrr(uint32_t base)
 {
 unsigned int i;
 int next_rmrr = -1;
-uint64_t end, min_end = 1ULL << 32;
+uint64_t end, min_end = GB(4);
 
 for ( i = 0; i < memory_map.nr_map ; i++ )
 {
@@ -297,7 +297,7 @@ void pci_setup(void)
 
 if ( mmio_hole_size )
 {
-uint64_t max_ram_below_4g = (1ULL << 32) - mmio_hole_size;
+uint64_t max_ram_below_4g = GB(4) - mmio_hole_size;
 
 if ( max_ram_below_4g > HVM_BELOW_4G_MMIO_START )
 {
@@ -385,13 +385,13 @@ void pci_setup(void)
 adjust_memory_map();
 
 high_mem_resource.base = ((uint64_t)hvm_info->high_mem_pgend) << 
PAGE_SHIFT;
-if ( high_mem_resource.base < 1ull << 32 )
+if ( high_mem_resource.base < GB(4) )
 {
 if ( hvm_info->high_mem_pgend != 0 )
 printf("WARNING: hvm_info->high_mem_pgend %x"
" does not point into high memory!",
hvm_info->high_mem_pgend);
-high_mem_resource.base = 1ull << 32;
+high_mem_resource.base = GB(4);
 }
 printf("%sRAM in high memory; setting high_mem resource base to 
"PRIllx"\n",
hvm_info->high_mem_pgend?"":"No ",
diff --git a/tools/firmware/hvmloader/smbios.c 
b/tools/firmware/hvmloader/smbios.c
index bdd96b2f7a..40d8399be1 100644
--- a/tools/firmware/hvmloader/smbios.c
+++ b/tools/firmware/hvmloader/smbios.c
@@ -239,15 +239,14 @@ get_memsize(void)
 
 sz = (uint64_t)hvm_info->low_mem_pgend << PAGE_SHIFT;
 if ( hvm_info->high_mem_pgend )
-sz += (((uint64_t)hvm_info->high_mem_pgend << PAGE_SHIFT)
-   - (1ull << 32));
+sz += (((uint64_t)hvm_info->high_mem_pgend << PAGE_SHIFT) - GB(4));
 
 /*
  * Round up to the nearest MB.  The user specifies domU pseudo-physical 
  * memory in megabytes, so not doing this could easily lead to reporting 
  * one less MB than the user specified.
  */
-return (sz + (1ul << 20) - 1) >> 20;
+return (sz + MB(1) - 1) >> 20;
 }
 
 void
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 2ef854eb8f..7bca6418d2 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -48,6 +48,9 @@ void __bug(char *file, int line) __attribute__((noreturn));
 #define max_t(type,x,y) \
 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
 
+#define MB(mb) (mb##ULL << 20)
+#define GB(gb) (gb##ULL << 30)
+
 static inline int test_bit(unsigned int b, const void *p)
 {
 return !!(((const uint8_t *)p)[b>>3] & (1u<<(b&7)));
-- 
2.13.0


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


Re: [Xen-devel] [PATCH] mm: Scrub pages returned back to heap if MEMF_no_scrub is set

2017-09-15 Thread Boris Ostrovsky
On 09/15/2017 12:05 PM, Jan Beulich wrote:
 On 15.09.17 at 16:04,  wrote:
>> Set free_heap_pages()'s need_scrub to true if alloc_domheap_pages()
>> returns pages back to heap as result of assign_pages() error when those
>> pages were requested with MEMF_no_scrub flag.
>>
>> We need to do this because there is a possibility that
>> alloc_heap_pages() might clear buddy's PGC_need_scrubs flag without
>> actually clearing the page.
>>
>> Signed-off-by: Boris Ostrovsky 
>> ---
>> We are declaring a likely clean (or almost clean) chunk to be dirty. Since
>> this only happend on assign_pages() error I figured it would be acceptable.
> I think that's fine, but let's wait a little to see whether others
> have differing opinions.
>
>> --- a/xen/common/page_alloc.c
>> +++ b/xen/common/page_alloc.c
>> @@ -2227,7 +2227,7 @@ struct page_info *alloc_domheap_pages(
>>  if ( d && !(memflags & MEMF_no_owner) &&
>>   assign_pages(d, pg, order, memflags) )
>>  {
>> -free_heap_pages(pg, order, false);
>> +free_heap_pages(pg, order, !!(memflags & MEMF_no_scrub));
> No need for the !! (easily fixed while committing). 

Sure.

> With that
> Reviewed-by: Jan Beulich 
>
> I take it this isn't related to the issue on ARM64 that Konrad has
> found?


It's related in the sense that I noticed this while looking at Konrad's
problem. Whether or not it also fixes his issue --- I don't know. If it
does then I think it will indicate that something else is going on there
since this would mean he is hitting assign_pages() error.


-boris

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


[Xen-devel] [PATCH 2/3] python: Extract registered watch search logic from xspy_read_watch()

2017-09-15 Thread Euan Harris
When a watch fires, xspy_read_watch() checks whether the client has
registered interest in the path which changed and, if so, returns the
path and a client-supplied token.   The binding for xs_check_watch()
needs to do the same, so this patch extracts the search code into a
separate function.

Signed-off-by: Euan Harris 
---
 tools/python/xen/lowlevel/xs/xs.c | 61 ---
 1 file changed, 38 insertions(+), 23 deletions(-)

diff --git a/tools/python/xen/lowlevel/xs/xs.c 
b/tools/python/xen/lowlevel/xs/xs.c
index 9f1b916..a4b50a0 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -77,6 +77,8 @@ static inline struct xs_handle *xshandle(XsHandle *self)
 
 static void remove_watch(XsHandle *xsh, PyObject *token);
 
+static PyObject *match_watch_by_token(XsHandle *self, char **xsval);
+
 static PyObject *none(bool result);
 
 static int parse_transaction_path(XsHandle *self, PyObject *args,
@@ -484,8 +486,6 @@ static PyObject *xspy_read_watch(XsHandle *self, PyObject 
*args)
 struct xs_handle *xh = xshandle(self);
 PyObject *val = NULL;
 char **xsval;
-PyObject *token;
-int i;
 unsigned int num;
 
 if (!xh)
@@ -497,32 +497,20 @@ again:
 Py_END_ALLOW_THREADS
 if (!xsval) {
 PyErr_SetFromErrno(xs_error);
-goto exit;
-}
-if (sscanf(xsval[XS_WATCH_TOKEN], "%li", (unsigned long *)) != 1) {
-   xs_set_error(EINVAL);
-goto exit;
-}
-for (i = 0; i < PyList_Size(self->watches); i++) {
-if (token == PyList_GetItem(self->watches, i))
-break;
-}
-if (i == PyList_Size(self->watches)) {
-  /* We do not have a registered watch for the one that has just fired.
- Ignore this -- a watch that has been recently deregistered can still
- have watches in transit.  This is a blocking method, so go back to
- read again.
-  */
-  free(xsval);
-  goto again;
+return val;
 }
-/* Create tuple (path, token). */
-val = Py_BuildValue("(sO)", xsval[XS_WATCH_PATH], token);
- exit:
+
+val = match_watch_by_token(self, xsval);
 free(xsval);
+
+if (!val && errno == EAGAIN) {
+goto again;
+}
+
 return val;
 }
 
+
 #define xspy_unwatch_doc "\n"  \
"Stop watching a path.\n"   \
" path  [string] : xenstore path.\n"\
@@ -868,6 +856,33 @@ static int parse_transaction_path(XsHandle *self, PyObject 
*args,
 }
 
 
+static PyObject *match_watch_by_token(XsHandle *self, char **xsval)
+{
+PyObject *token;
+int i;
+
+if (sscanf(xsval[XS_WATCH_TOKEN], "%li", (unsigned long *)) != 1) {
+   xs_set_error(EINVAL);
+return NULL;
+}
+for (i = 0; i < PyList_Size(self->watches); i++) {
+if (token == PyList_GetItem(self->watches, i))
+break;
+}
+if (i == PyList_Size(self->watches)) {
+/* We do not have a registered watch for the one that has just fired.
+   Ignore this -- a watch that has been recently deregistered can still
+   have watches in transit.
+*/
+xs_set_error(EAGAIN);
+return NULL;
+}
+
+/* Create tuple (path, token). */
+return Py_BuildValue("(sO)", xsval[XS_WATCH_PATH], token);
+}
+
+
 static PyObject *none(bool result)
 {
 if (result) {
-- 
1.8.3.1


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


[Xen-devel] [PATCH 0/3] python: Add non-blocking Xenstore watch bindings

2017-09-15 Thread Euan Harris
Expose xs_fileno() and xs_check_watch() to Python.   These functions
make it posible to write event-driven Xenstore clients in Python:

  #!/usr/bin/env python
  
  import xen.lowlevel.xs
  
  import sys
  import errno
  from select import select
  import time
  
  # Connect to XenStore and set watch
  xsh = xen.lowlevel.xs.xs()
  xsh.watch("/foo", "footoken")
  xsh.watch("/bar", "bartoken")
  
  # Start polling loop
  xsfd = xsh.fileno()
  while True:
 readable, writable, exceptional = select([xsfd], [], [xsfd], 1.0)
 print "%d tick" % time.time()
  
 if readable:
 while True:
 watch = xsh.check_watch()
 if not watch:
 break
 path, token = watch
 print "%d watch fired: path=%s, token=%s" % (time.time(), 
  path, token)
 value = xsh.read("", path)
 print "%d read %s = %s" % (time.time(), path, value)
  
 if exceptional:
 print "select error"
  
The polling loop can be simplified further by wrapping the call to
xsh.check_watch() in a generator, but this is easier to do in Python
than in the C bindings.


Euan Harris (3):
  python: Add wrapper for xs_fileno()
  python: Extract registered watch search logic from  xspy_read_watch()
  python: Add binding for non-blocking xs_check_watch()

 tools/python/xen/lowlevel/xs/xs.c | 109 ++
 1 file changed, 86 insertions(+), 23 deletions(-)

-- 
1.8.3.1


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


[Xen-devel] [PATCH 1/3] python: Add binding for xs_fileno()

2017-09-15 Thread Euan Harris
xs_fileno() returns a file descriptor which receives events when Xenstore
watches fire.   Exposing this in the Python bindings is a prerequisite
for writing event-driven clients in Python.

Signed-off-by: Euan Harris 
---
 tools/python/xen/lowlevel/xs/xs.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/tools/python/xen/lowlevel/xs/xs.c 
b/tools/python/xen/lowlevel/xs/xs.c
index aba5a20..9f1b916 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -453,6 +453,25 @@ static PyObject *xspy_watch(XsHandle *self, PyObject *args)
 }
 
 
+#define xspy_fileno_doc "\n"  \
+   "Return the FD to poll for notifications when watches fire.\n"   \
+   "Returns: [int] file descriptor.\n"\
+   "\n"
+
+static PyObject *xspy_fileno(XsHandle *self)
+{
+struct xs_handle *xh = xshandle(self);
+int fd;
+
+if (!xh)
+return NULL;
+
+fd = xs_fileno(xh);
+
+return PyInt_FromLong(fd);
+}
+
+
 #define xspy_read_watch_doc "\n"   \
"Read a watch notification.\n"  \
"\n"\
@@ -887,6 +906,7 @@ static PyMethodDef xshandle_methods[] = {
 XSPY_METH(release_domain,METH_VARARGS),
 XSPY_METH(close, METH_NOARGS),
 XSPY_METH(get_domain_path,   METH_VARARGS),
+XSPY_METH(fileno,METH_NOARGS),
 { NULL /* Sentinel. */ },
 };
 
-- 
1.8.3.1


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


[Xen-devel] [PATCH 3/3] python: Add binding for non-blocking xs_check_watch()

2017-09-15 Thread Euan Harris
xs_check_watch() checks for watch notifications without blocking.
Together with the binding for xs_fileno(), this makes it possible
to write event-driven clients in Python.

Signed-off-by: Euan Harris 
---
 tools/python/xen/lowlevel/xs/xs.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/tools/python/xen/lowlevel/xs/xs.c 
b/tools/python/xen/lowlevel/xs/xs.c
index a4b50a0..c9a9259 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -474,6 +474,33 @@ static PyObject *xspy_fileno(XsHandle *self)
 }
 
 
+#define xspy_check_watch_doc "\n"  \
+   "Check for watch notifications without blocking.\n" \
+   "\n"\
+   "Returns: [tuple] (path, token).\n" \
+   " None if no watches have fired.\n" \
+   "Raises xen.lowlevel.xs.Error on error.\n"  \
+   "\n"
+
+static PyObject *xspy_check_watch(XsHandle *self, PyObject *args)
+{
+struct xs_handle *xh = xshandle(self);
+PyObject *val = NULL;
+char **xsval;
+
+if (!xh)
+return NULL;
+
+xsval = xs_check_watch(xh);
+if (!xsval) {
+return none(errno == EAGAIN);
+}
+
+val = match_watch_by_token(self, xsval);
+free(xsval);
+return val;
+}
+
 #define xspy_read_watch_doc "\n"   \
"Read a watch notification.\n"  \
"\n"\
@@ -912,6 +939,7 @@ static PyMethodDef xshandle_methods[] = {
 XSPY_METH(set_permissions,   METH_VARARGS),
 XSPY_METH(watch, METH_VARARGS),
 XSPY_METH(read_watch,METH_NOARGS),
+XSPY_METH(check_watch,   METH_NOARGS),
 XSPY_METH(unwatch,   METH_VARARGS),
 XSPY_METH(transaction_start, METH_NOARGS),
 XSPY_METH(transaction_end,   METH_VARARGS | METH_KEYWORDS),
-- 
1.8.3.1


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


[Xen-devel] [seabios baseline-only test] 72110: regressions - FAIL

2017-09-15 Thread Platform Team regression test user
This run is configured for baseline tests only.

flight 72110 seabios real [real]
http://osstest.xs.citrite.net/~osstest/testlogs/logs/72110/

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-amd64-xl-qemuu-win10-i386 10 windows-install   fail REGR. vs. 72057

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-xl-qemuu-win7-amd64 18 guest-start/win.repeat fail blocked in 
72057
 test-amd64-amd64-qemuu-nested-intel 17 debian-hvm-install/l1/l2 fail like 72057
 test-amd64-i386-xl-qemuu-win7-amd64 17 guest-stop  fail like 72057
 test-amd64-i386-xl-qemuu-ws16-amd64 10 windows-install fail never pass
 test-amd64-amd64-xl-qemuu-ws16-amd64 10 windows-installfail never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-amd64-i386-xl-qemuu-win10-i386 17 guest-stop  fail never pass

version targeted for testing:
 seabios  1ef72ab2f89ae61dcdb3f01323bd0a7dc978c2b9
baseline version:
 seabios  828af21d3ec33a67251a4dd3aa5751dc6e8ccf16

Last test of basis72057  2017-09-03 16:20:31 Z   12 days
Testing same since72110  2017-09-15 07:19:03 Z0 days1 attempts


People who touched revisions under test:
  Kevin O'Connor 

jobs:
 build-amd64-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-i386   pass
 build-amd64-libvirt  pass
 build-i386-libvirt   pass
 build-amd64-pvopspass
 build-i386-pvops pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm   pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsmpass
 test-amd64-amd64-xl-qemuu-debianhvm-amd64-xsmpass
 test-amd64-i386-xl-qemuu-debianhvm-amd64-xsm pass
 test-amd64-amd64-qemuu-nested-amdfail
 test-amd64-i386-qemuu-rhel6hvm-amd   pass
 test-amd64-amd64-xl-qemuu-debianhvm-amd64pass
 test-amd64-i386-xl-qemuu-debianhvm-amd64 pass
 test-amd64-amd64-xl-qemuu-win7-amd64 fail
 test-amd64-i386-xl-qemuu-win7-amd64  fail
 test-amd64-amd64-xl-qemuu-ws16-amd64 fail
 test-amd64-i386-xl-qemuu-ws16-amd64  fail
 test-amd64-amd64-xl-qemuu-win10-i386 fail
 test-amd64-i386-xl-qemuu-win10-i386  fail
 test-amd64-amd64-qemuu-nested-intel  fail
 test-amd64-i386-qemuu-rhel6hvm-intel pass



sg-report-flight on osstest.xs.citrite.net
logs: /home/osstest/logs
images: /home/osstest/images

Logs, config files, etc. are available at
http://osstest.xs.citrite.net/~osstest/testlogs/logs

Test harness code can be found at
http://xenbits.xensource.com/gitweb?p=osstest.git;a=summary


Push not applicable.


commit 1ef72ab2f89ae61dcdb3f01323bd0a7dc978c2b9
Author: Kevin O'Connor 
Date:   Sat Sep 2 21:42:12 2017 -0400

tcgbios: Fix use of unitialized variable

Review-by: Stefan Berger 
Signed-off-by: Kevin O'Connor 

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


Re: [Xen-devel] [PATCH] mm: Scrub pages returned back to heap if MEMF_no_scrub is set

2017-09-15 Thread Jan Beulich
>>> On 15.09.17 at 16:04,  wrote:
> Set free_heap_pages()'s need_scrub to true if alloc_domheap_pages()
> returns pages back to heap as result of assign_pages() error when those
> pages were requested with MEMF_no_scrub flag.
> 
> We need to do this because there is a possibility that
> alloc_heap_pages() might clear buddy's PGC_need_scrubs flag without
> actually clearing the page.
> 
> Signed-off-by: Boris Ostrovsky 
> ---
> We are declaring a likely clean (or almost clean) chunk to be dirty. Since
> this only happend on assign_pages() error I figured it would be acceptable.

I think that's fine, but let's wait a little to see whether others
have differing opinions.

> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -2227,7 +2227,7 @@ struct page_info *alloc_domheap_pages(
>  if ( d && !(memflags & MEMF_no_owner) &&
>   assign_pages(d, pg, order, memflags) )
>  {
> -free_heap_pages(pg, order, false);
> +free_heap_pages(pg, order, !!(memflags & MEMF_no_scrub));

No need for the !! (easily fixed while committing). With that
Reviewed-by: Jan Beulich 

I take it this isn't related to the issue on ARM64 that Konrad has
found?

Jan


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


Re: [Xen-devel] [PATCH v2 2/5] libxl: enable per-VCPU extratime flag for RTDS

2017-09-15 Thread Meng Xu
On Wed, Sep 13, 2017 at 8:16 PM, Dario Faggioli
 wrote:
> On Fri, 2017-09-01 at 12:03 -0400, Meng Xu wrote:
>> On Fri, Sep 1, 2017 at 11:58 AM, Meng Xu 
>> wrote:
>> > @@ -705,6 +717,12 @@ static int sched_rtds_domain_set(libxl__gc
>> > *gc, uint32_t domid,
>> >  sdom.period = scinfo->period;
>> >  if (scinfo->budget != LIBXL_DOMAIN_SCHED_PARAM_BUDGET_DEFAULT)
>> >  sdom.budget = scinfo->budget;
>> > +if (scinfo->extratime !=
>> > LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT) {
>> > +if (scinfo->extratime)
>> > +sdom.flags |= XEN_DOMCTL_SCHEDRT_extra;
>> > +else
>> > +sdom.flags &= ~XEN_DOMCTL_SCHEDRT_extra;
>> > +}
>> >  if (sched_rtds_validate_params(gc, sdom.period, sdom.budget))
>> >  return ERROR_INVAL;
>>
>>
>> As you mentioned in the comment to the xl patch v1, I used
>> LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT for extratime flag as what
>> we did for period and budget. But the way we handle flags is exactly
>> the same with the way we handle period and budget.
>>
> Mmm... and (since you say 'But') is that a problem?

Sorry, the sentence should be "But the way we handle flags is *not* exactly
the same with the way we handle period and budget".
I missed "not" in the previous sentence.

>
>> I'm ok with what it is in this patch, although I feel that we can
>> kill the
>>  if (scinfo->extratime != LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT)
>> because LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT is -1.
>>
> No, sorry, I don't understand what you mean here...

I was thinking about the following code:

if (scinfo->extratime != LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT) {
if (scinfo->extratime)
sdom.flags |= XEN_DOMCTL_SCHEDRT_extra;
else
sdom.flags &= ~XEN_DOMCTL_SCHEDRT_extra;
}

This code can be changed to
if (scinfo->extratime)
sdom.flags |= XEN_DOMCTL_SCHEDRT_extra;
else
sdom.flags &= ~XEN_DOMCTL_SCHEDRT_extra;

If the extratime uses default value (-1), we still set the extratime flag.

That's why I feel we may kill the
 if (scinfo->extratime != LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT)

Please correct me if I'm wrong.

For the next version, I plan to keep what it is right now. That is:
if (scinfo->extratime != LIBXL_DOMAIN_SCHED_PARAM_EXTRATIME_DEFAULT) {
if (scinfo->extratime)
sdom.flags |= XEN_DOMCTL_SCHEDRT_extra;
else
sdom.flags &= ~XEN_DOMCTL_SCHEDRT_extra;
}


Best,

Meng

-- 
Meng Xu
Ph.D. Candidate in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/

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


[Xen-devel] [ovmf test] 113462: all pass - PUSHED

2017-09-15 Thread osstest service owner
flight 113462 ovmf real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113462/

Perfect :-)
All tests in this flight passed as required
version targeted for testing:
 ovmf 11b4463e096523fe03ac840472d483652ae93904
baseline version:
 ovmf b30abe7df464d91b84a42763e61bb3c85bfd80c9

Last test of basis   113443  2017-09-14 11:21:11 Z1 days
Testing same since   113462  2017-09-15 03:26:03 Z0 days1 attempts


People who touched revisions under test:
  Brijesh Singh 
  Laszlo Ersek 
  Paulo Alcantara 
  Star Zeng 

jobs:
 build-amd64-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-i386   pass
 build-amd64-libvirt  pass
 build-i386-libvirt   pass
 build-amd64-pvopspass
 build-i386-pvops pass
 test-amd64-amd64-xl-qemuu-ovmf-amd64 pass
 test-amd64-i386-xl-qemuu-ovmf-amd64  pass



sg-report-flight on osstest.test-lab.xenproject.org
logs: /home/logs/logs
images: /home/logs/images

Logs, config files, etc. are available at
http://logs.test-lab.xenproject.org/osstest/logs

Explanation of these reports, and of osstest in general, is at
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README.email;hb=master
http://xenbits.xen.org/gitweb/?p=osstest.git;a=blob;f=README;hb=master

Test harness code can be found at
http://xenbits.xen.org/gitweb?p=osstest.git;a=summary


Pushing revision :

+ branch=ovmf
+ revision=11b4463e096523fe03ac840472d483652ae93904
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.
 PERLLIB=.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x '!=' x/home/osstest/repos/lock ']'
++ OSSTEST_REPOS_LOCK_LOCKED=/home/osstest/repos/lock
++ exec with-lock-ex -w /home/osstest/repos/lock ./ap-push ovmf 
11b4463e096523fe03ac840472d483652ae93904
+ branch=ovmf
+ revision=11b4463e096523fe03ac840472d483652ae93904
+ . ./cri-lock-repos
++ . ./cri-common
+++ . ./cri-getconfig
 export PERLLIB=.:.:.
 PERLLIB=.:.:.
+++ umask 002
+++ getrepos
 getconfig Repos
 perl -e '
use Osstest;
readglobalconfig();
print $c{"Repos"} or die $!;
'
+++ local repos=/home/osstest/repos
+++ '[' -z /home/osstest/repos ']'
+++ '[' '!' -d /home/osstest/repos ']'
+++ echo /home/osstest/repos
++ repos=/home/osstest/repos
++ repos_lock=/home/osstest/repos/lock
++ '[' x/home/osstest/repos/lock '!=' x/home/osstest/repos/lock ']'
+ . ./cri-common
++ . ./cri-getconfig
+++ export PERLLIB=.:.:.:.
+++ PERLLIB=.:.:.:.
++ umask 002
+ select_xenbranch
+ case "$branch" in
+ tree=ovmf
+ xenbranch=xen-unstable
+ '[' xovmf = xlinux ']'
+ linuxbranch=
+ '[' x = x ']'
+ qemuubranch=qemu-upstream-unstable
+ select_prevxenbranch
++ ./cri-getprevxenbranch xen-unstable
+ prevxenbranch=xen-4.9-testing
+ '[' x11b4463e096523fe03ac840472d483652ae93904 = x ']'
+ : tested/2.6.39.x
+ . ./ap-common
++ : osst...@xenbits.xen.org
+++ getconfig OsstestUpstream
+++ perl -e '
use Osstest;
readglobalconfig();
print $c{"OsstestUpstream"} or die $!;
'
++ :
++ : git://xenbits.xen.org/xen.git
++ : osst...@xenbits.xen.org:/home/xen/git/xen.git
++ : git://xenbits.xen.org/qemu-xen-traditional.git
++ : git://git.kernel.org
++ : git://git.kernel.org/pub/scm/linux/kernel/git
++ : git
++ : git://xenbits.xen.org/xtf.git
++ : osst...@xenbits.xen.org:/home/xen/git/xtf.git
++ : git://xenbits.xen.org/xtf.git
++ : git://xenbits.xen.org/libvirt.git
++ : osst...@xenbits.xen.org:/home/xen/git/libvirt.git
++ : git://xenbits.xen.org/libvirt.git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : git
++ : git://xenbits.xen.org/osstest/rumprun.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/rumprun.git
++ : git://git.seabios.org/seabios.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/seabios.git
++ : git://xenbits.xen.org/osstest/seabios.git
++ : https://github.com/tianocore/edk2.git
++ : osst...@xenbits.xen.org:/home/xen/git/osstest/ovmf.git
++ : 

[Xen-devel] [linux-4.9 test] 113458: regressions - FAIL

2017-09-15 Thread osstest service owner
flight 113458 linux-4.9 real [real]
http://logs.test-lab.xenproject.org/osstest/logs/113458/

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-i386-xl-qemut-win7-amd64 16 guest-localmigrate/x10 fail REGR. vs. 
113202

Tests which are failing intermittently (not blocking):
 test-armhf-armhf-xl-rtds 12 guest-start  fail in 113425 pass in 113458
 test-armhf-armhf-xl-cubietruck 16 guest-start/debian.repeat fail in 113425 
pass in 113458
 test-armhf-armhf-xl-arndale   6 xen-install  fail in 113425 pass in 113458
 test-amd64-i386-rumprun-i386 17 rumprun-demo-xenstorels/xenstorels.repeat fail 
pass in 113425
 test-amd64-amd64-xl-qemut-win7-amd64 16 guest-localmigrate/x10 fail pass in 
113425
 test-amd64-i386-xl-qemuu-win7-amd64 16 guest-localmigrate/x10 fail pass in 
113425

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-xl-qemuu-win7-amd64 18 guest-start/win.repeat fail in 113425 
blocked in 113202
 test-amd64-amd64-xl-qemut-win7-amd64 18 guest-start/win.repeat fail in 113425 
like 113202
 test-amd64-i386-xl-qemuu-win7-amd64 17 guest-stop   fail in 113425 like 113202
 test-armhf-armhf-xl-rtds 16 guest-start/debian.repeatfail  like 113202
 test-amd64-amd64-xl-rtds 10 debian-install   fail  like 113202
 test-amd64-amd64-xl-qemuu-win7-amd64 16 guest-localmigrate/x10 fail like 113202
 test-amd64-amd64-xl-qemuu-ws16-amd64 10 windows-installfail never pass
 test-amd64-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-amd64-i386-libvirt  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-amd64-amd64-xl-qemut-ws16-amd64 10 windows-installfail never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-i386-libvirt-qcow2 12 migrate-support-checkfail  never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-multivcpu 13 migrate-support-checkfail  never pass
 test-armhf-armhf-xl-multivcpu 14 saverestore-support-checkfail  never pass
 test-armhf-armhf-xl-cubietruck 13 migrate-support-checkfail never pass
 test-armhf-armhf-xl-cubietruck 14 saverestore-support-checkfail never pass
 test-armhf-armhf-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt-xsm 14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 13 guest-saverestore   fail never pass
 test-amd64-i386-xl-qemut-ws16-amd64 13 guest-saverestore   fail never pass
 test-armhf-armhf-libvirt-raw 12 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail   never pass
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-armhf-armhf-xl-credit2  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit2  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-xsm  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  13 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemut-win10-i386 10 windows-install fail never pass
 test-amd64-amd64-xl-qemuu-win10-i386 10 windows-installfail never pass
 test-amd64-amd64-xl-qemut-win10-i386 10 windows-installfail never pass
 test-amd64-i386-xl-qemuu-win10-i386 10 windows-install fail never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail   never pass

version targeted for testing:
 linux4ad5dcaca7428dd2bc1a6a40c948e3799c1e27ae
baseline version:
 linuxf07cb3489cff38984a8df4d3a0fea5d0858c1eb0

Last test of basis   113202  2017-09-10 06:21:29 Z5 days
Testing same since   113425  2017-09-13 21:31:16 Z1 days2 attempts


People who touched revisions under test:
  Abhishek Sahu 

Re: [Xen-devel] [PATCH v2 1/5] xen:rtds: towards work conserving RTDS

2017-09-15 Thread Meng Xu
Hi Dario,

On Wed, Sep 13, 2017 at 9:06 PM, Dario Faggioli
 wrote:
>
> On Fri, 2017-09-01 at 11:58 -0400, Meng Xu wrote:
> > Make RTDS scheduler work conserving without breaking the real-time
> > guarantees.
> >
> > VCPU model:
> > Each real-time VCPU is extended to have an extratime flag
> > and a priority_level field.
> > When a VCPU's budget is depleted in the current period,
> > if it has extratime flag set,
> > its priority_level will increase by 1 and its budget will be
> > refilled;
> > othewrise, the VCPU will be moved to the depletedq.
> >
> > Scheduling policy is modified global EDF:
> > A VCPU v1 has higher priority than another VCPU v2 if
> > (i) v1 has smaller priority_leve; or
> > (ii) v1 has the same priority_level but has a smaller deadline
> >
> > Queue management:
> > Run queue holds VCPUs with extratime flag set and VCPUs with
> > remaining budget. Run queue is sorted in increasing order of VCPUs
> > priorities.
> > Depleted queue holds VCPUs which have extratime flag cleared and
> > depleted budget.
> > Replenished queue is not modified.
> >
> Mmm.. didn't we agree about putting a word of explanation of how the
> spare bandwidth ends up being distributed (i.e., in a way which is
> proportional to the utilization)?


I didn't recall that. I should have double checked that I have
resolved every comment in previous patch.
Anyway, I added the comment in the next version, which is comming soon.

>
> Or is it there and it's me that am
> not finding it?
>
> > --- a/xen/common/sched_rt.c
> > +++ b/xen/common/sched_rt.c
> > @@ -245,6 +258,11 @@ static inline struct list_head *rt_replq(const
> > struct scheduler *ops)
> >  return _priv(ops)->replq;
> >  }
> >
> > +static inline bool has_extratime(const struct rt_vcpu *svc)
> > +{
> > +return (svc->flags & RTDS_extratime) ? 1 : 0;
> > +}
> > +
> 'true' and 'false'. But I think
>
>  return svc->flags & RTDS_extratime
>
> is just fine already, without any need for the ?: operator.


OK. Either works for me. I will go with
return svc->flags & RTDS_extratime.
>
>
> The rest of the patch looks fine to me.


Thanks,

Meng

-- 
Meng Xu
Ph.D. Candidate in Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~mengxu/

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


Re: [Xen-devel] [PATCH RFC v2] Add SUPPORT.md

2017-09-15 Thread Konrad Rzeszutek Wilk
> +### Soft-reset for PV guests

s/PV/HVM/


> +
> +Status: Supported
> + 
> +Soft-reset allows a new kernel to start 'from scratch' with a fresh VM 
> state, 
> +but with all the memory from the previous state of the VM intact.
> +This is primarily designed to allow "crash kernels", 
> +which can do core dumps of memory to help with debugging in the event of a 
> crash.
> +
> +### xentrace
> +
> +Status, x86: Supported
> +
> +Tool to capture Xen trace buffer data
> +
> +### gcov
> +
> +Status: Supported, Not security supported
> +
> +Export hypervisor coverage data suitable for analysis by gcov or lcov.
> +
> +## Memory Management
> +
> +### Memory Ballooning
> +
> +Status: Supported
> +
> +### Memory Sharing
> +
> +Status, x86 HVM: Tech Preview
> +Status, ARM: Tech Preview
> +
> +Allow sharing of identical pages between guests
> +
> +### Memory Paging
> +
> +Status, x86 HVM: Experimenal
> +
> +Allow pages belonging to guests to be paged to disk
> +
> +### Transcendent Memory
> +
> +Status: Experimental
> +
> +[XXX Add description]

Guests with tmem drivers autoballoon memory out allowing a fluid
and dynamic memory allocation - in effect memory overcommit without
the need to swap. Only works with Linux guests (as it requires
OS drivers).

..snip..
> +### Live Patching
> +
> +Status, x86: Supported
> +Status, ARM: Experimental
> +
> +Compile time disabled

for ARM.

As the patch will do:

 config LIVEPATCH
-   bool "Live patching support (TECH PREVIEW)"
-   default n
+   bool "Live patching support"
+   default X86
depends on HAS_BUILD_ID = "y"
---help---
  Allows a running Xen hypervisor to be dynamically patched using

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


Re: [Xen-devel] [PATCH] xen: grant-table: Simplify get_page_frame

2017-09-15 Thread Julien Grall

Hi Jan,

On 09/15/2017 01:15 PM, Jan Beulich wrote:

On 14.09.17 at 18:49,  wrote:

get_page_from_gfn will be able to get reference on foreign page and as
per my understanding will allow to grant page on foreign memory.

This was not allowed with a simple get_page(...) on the ARM
implementation (no sharing nor paging supprot) but is allowed on the x86
implementation due to get_page_from_gfn.

On x86, foreign pages are currently only allowed for PVH dom0, so I
think it is not a big deal for now.

On Arm, foreign pages can be present on any domain. So this patch would
permit grant on foreing pages.

So I would like to check whether it would be valid to grant a mapping on
foreign pages?


No, I don't think grants should be permitted for other domains'
pages.


Which seems to match the PV behavior. I will update the patch to forbid 
foreign pages and use #ifdef.


Cheers,

--
Julien Grall

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


Re: [Xen-devel] [PATCH 09/12] arm/decode.c: switch to plain bool

2017-09-15 Thread Julien Grall



On 09/15/2017 03:39 PM, Wei Liu wrote:

On Fri, Sep 15, 2017 at 03:33:27PM +0100, Julien Grall wrote:

Hi Wei,

On 09/15/2017 10:42 AM, Wei Liu wrote:

Signed-off-by: Wei Liu 
---
   xen/arch/arm/decode.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c
index 514b7a21a5..795d126f02 100644
--- a/xen/arch/arm/decode.c
+++ b/xen/arch/arm/decode.c
@@ -26,7 +26,7 @@
   #include "decode.h"
   static void update_dabt(struct hsr_dabt *dabt, int reg,
-uint8_t size, bool_t sign)
+uint8_t size, bool sign)


You probably want to switch from 0 to false all the callers of update_dabt.



The following diff will be folded in.


Looks good to me.

Cheers,



diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c
index 795d126f02..8b1e15d118 100644
--- a/xen/arch/arm/decode.c
+++ b/xen/arch/arm/decode.c
@@ -101,16 +101,16 @@ static int decode_thumb(register_t pc, struct
hsr_dabt *dabt)
  switch ( opB & 0x3 )
  {
  case 0: /* Non-signed word */
-update_dabt(dabt, reg, 2, 0);
+update_dabt(dabt, reg, 2, false);
  break;
  case 1: /* Non-signed halfword */
-update_dabt(dabt, reg, 1, 0);
+update_dabt(dabt, reg, 1, false);
  break;
  case 2: /* Non-signed byte */
-update_dabt(dabt, reg, 0, 0);
+update_dabt(dabt, reg, 0, false);
  break;
  case 3: /* Signed byte */
-update_dabt(dabt, reg, 0, 1);
+update_dabt(dabt, reg, 0, true);
  break;
  }

@@ -118,19 +118,19 @@ static int decode_thumb(register_t pc, struct
hsr_dabt *dabt)
  }
  case 6:
  /* Load/Store word immediate offset */
-update_dabt(dabt, instr & 7, 2, 0);
+update_dabt(dabt, instr & 7, 2, false);
  break;
  case 7:
  /* Load/Store byte immediate offset */
-update_dabt(dabt, instr & 7, 0, 0);
+update_dabt(dabt, instr & 7, 0, false);
  break;
  case 8:
  /* Load/Store halfword immediate offset */
-update_dabt(dabt, instr & 7, 1, 0);
+update_dabt(dabt, instr & 7, 1, false);
  break;
  case 9:
  /* Load/Store word sp offset */
-update_dabt(dabt, (instr >> 8) & 7, 2, 0);
+update_dabt(dabt, (instr >> 8) & 7, 2, false);



--
Julien Grall

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


  1   2   >