Re: [PATCH v2 20/21] drm/xlnx: Initialize DRM driver instance with CMA helper macro

2020-09-15 Thread Hyun Kwon
Hi Tomas,

Thanks for the patch.

On Tue, Sep 15, 2020 at 08:53:46AM -0700, Laurent Pinchart wrote:
> Hi Thomas,
> 
> Thank you for the patch.
> 
> On Tue, Sep 15, 2020 at 04:59:57PM +0200, Thomas Zimmermann wrote:
> > The xlnx driver uses CMA helpers with default callback functions.
> > Initialize the driver structure with the rsp CMA helper macro. The
> > driver is being converted to use GEM object functions as part of
> > this change.
> > 
> > Two callbacks, .dumb_destroy and .gem_prime_import, were initialized
> > to their default implementations, so they are just kept empty now.
> > 
> > v2:
> > * initialize with DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE (Laurent)
> > 
> > Signed-off-by: Thomas Zimmermann 
> 
> Reviewed-by: Laurent Pinchart 
> 

Reviewed-by: Hyun Kwon 

Thanks,
-hyun

> > ---
> >  drivers/gpu/drm/xlnx/zynqmp_dpsub.c | 14 +-
> >  1 file changed, 1 insertion(+), 13 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c 
> > b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> > index 8e69303aad3f..f3ffc3703a0e 100644
> > --- a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> > +++ b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> > @@ -80,19 +80,7 @@ static struct drm_driver zynqmp_dpsub_drm_driver = {
> > .driver_features= DRIVER_MODESET | DRIVER_GEM |
> >   DRIVER_ATOMIC,
> >  
> > -   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
> > -   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
> > -   .gem_prime_export   = drm_gem_prime_export,
> > -   .gem_prime_import   = drm_gem_prime_import,
> > -   .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
> > -   .gem_prime_import_sg_table  = drm_gem_cma_prime_import_sg_table,
> > -   .gem_prime_vmap = drm_gem_cma_prime_vmap,
> > -   .gem_prime_vunmap   = drm_gem_cma_prime_vunmap,
> > -   .gem_prime_mmap = drm_gem_cma_prime_mmap,
> > -   .gem_free_object_unlocked   = drm_gem_cma_free_object,
> > -   .gem_vm_ops = _gem_cma_vm_ops,
> > -   .dumb_create= zynqmp_dpsub_dumb_create,
> > -   .dumb_destroy   = drm_gem_dumb_destroy,
> > +   DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE(zynqmp_dpsub_dumb_create),
> >  
> > .fops   = _dpsub_drm_fops,
> >  
> 
> -- 
> Regards,
> 
> Laurent Pinchart
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel



[ovmf test] 154370: all pass - PUSHED

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

Perfect :-)
All tests in this flight passed as required
version targeted for testing:
 ovmf a62fb4229d149560cac2bf56011fba49a281ed2b
baseline version:
 ovmf 1b461403ee723dab01d5828714cca0b9396a6b3c

Last test of basis   154333  2020-09-14 13:11:13 Z1 days
Testing same since   154370  2020-09-16 01:39:54 Z0 days1 attempts


People who touched revisions under test:
  Matthew Carlson 
  Matthew Carlson 

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 :

To xenbits.xen.org:/home/xen/git/osstest/ovmf.git
   1b461403ee..a62fb4229d  a62fb4229d149560cac2bf56011fba49a281ed2b -> 
xen-tested-master



[linux-linus test] 154364: regressions - FAIL

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

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-i386-qemut-rhel6hvm-intel  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-ws16-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-dmrestrict-amd64-dmrestrict 7 xen-boot fail REGR. vs. 
152332
 test-amd64-i386-xl-qemuu-debianhvm-amd64-shadow 7 xen-boot fail REGR. vs. 
152332
 test-amd64-i386-xl-xsm7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-qemuu-rhel6hvm-intel  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-debianhvm-amd64  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-examine   8 reboot   fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-debianhvm-i386-xsm  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-pair 10 xen-boot/src_hostfail REGR. vs. 152332
 test-amd64-i386-pair 11 xen-boot/dst_hostfail REGR. vs. 152332
 test-amd64-i386-libvirt   7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-ws16-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-debianhvm-amd64  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-libvirt-xsm   7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-qemut-rhel6hvm-amd  7 xen-boot   fail REGR. vs. 152332
 test-amd64-i386-qemuu-rhel6hvm-amd  7 xen-boot   fail REGR. vs. 152332
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 7 xen-boot fail REGR. vs. 
152332
 test-amd64-i386-xl7 xen-boot fail REGR. vs. 152332
 test-amd64-coresched-i386-xl  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-raw7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-freebsd10-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-pvshim 7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-debianhvm-i386-xsm  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-win7-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-shadow 7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-freebsd10-i386  7 xen-boot   fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-ovmf-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-win7-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-libvirt-pair 10 xen-boot/src_hostfail REGR. vs. 152332
 test-amd64-i386-libvirt-pair 11 xen-boot/dst_hostfail REGR. vs. 152332
 test-amd64-i386-xl-qemut-stubdom-debianhvm-amd64-xsm 7 xen-boot fail REGR. vs. 
152332

Tests which are failing intermittently (not blocking):
 test-amd64-amd64-xl-shadow   18 guest-localmigrate/x10 fail pass in 154356
 test-armhf-armhf-xl-credit1   7 xen-boot   fail pass in 154356
 test-amd64-amd64-libvirt-xsm 18 guest-start/debian.repeat  fail pass in 154356
 test-arm64-arm64-libvirt-xsm 16 guest-start/debian.repeat  fail pass in 154356

Tests which did not succeed, but are not blocking:
 test-armhf-armhf-xl-credit1 13 migrate-support-check fail in 154356 never pass
 test-armhf-armhf-xl-credit1 14 saverestore-support-check fail in 154356 never 
pass
 test-amd64-amd64-xl-qemut-win7-amd64 17 guest-stopfail like 152332
 test-amd64-amd64-xl-qemuu-win7-amd64 17 guest-stopfail like 152332
 test-amd64-amd64-xl-qemut-ws16-amd64 17 guest-stopfail like 152332
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail  like 152332
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail  like 152332
 test-amd64-amd64-xl-qemuu-ws16-amd64 17 guest-stopfail like 152332
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  14 saverestore-support-checkfail   never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 14 saverestore-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
 

Re: Compiling Xen from source

2020-09-15 Thread Andrew Cooper
On 15/09/2020 21:16, David I wrote:
> Hello,
>
> I am unable to mcompile xen-tools from source.
>
> here is the "stacktrace":
>
> ln -f xenstore xenstore-watch
> gcc xenstore_control.o    
>  -Wl,-rpath-link=/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore
> /home/david/xen/xen/tools/xenstore/../../tools/xenstore/libxenstore.so
> -ldl
>  
> /home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so
>  -o xenstore-control
> gcc  -m64 -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall
> -Wstrict-prototypes -Wdeclaration-after-statement
> -Wno-unused-but-set-variable -Wno-unused-local-typedefs   -O2
> -fomit-frame-pointer
> -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MF
> .xs_tdb_dump.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE   -Werror
> -I. -include /home/david/xen/xen/tools/xenstore/../../tools/config.h
> -I./include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/evtchn/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libxc/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toollog/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/foreignmemory/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/devicemodel/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -D__XEN_TOOLS__
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -DXEN_LIB_STORED="\"/var/lib/xenstored\""
> -DXEN_RUN_STORED="\"/var/run/xenstored\""   -c -o xs_tdb_dump.o
> xs_tdb_dump.c
> gcc  -m64 -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall
> -Wstrict-prototypes -Wdeclaration-after-statement
> -Wno-unused-but-set-variable -Wno-unused-local-typedefs   -O2
> -fomit-frame-pointer
> -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MF
> .utils.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE   -Werror -I.
> -include /home/david/xen/xen/tools/xenstore/../../tools/config.h
> -I./include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/evtchn/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libxc/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toollog/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/foreignmemory/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/devicemodel/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -D__XEN_TOOLS__
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include
> -DXEN_LIB_STORED="\"/var/lib/xenstored\""
> -DXEN_RUN_STORED="\"/var/run/xenstored\""  
> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/gnttab/include
> -I/home/david/xen/xen/tools/xenstore/../../tools/include  -c -o
> utils.o utils.c
> gcc xs_tdb_dump.o utils.o tdb.o talloc.o     -o xs_tdb_dump
> /usr/bin/ld : utils.o:(.data.rel.local+0x0) : définitions multiples de
> « xprintf »; xs_tdb_dump.o:(.bss+0x0) : défini pour la première fois ici
> collect2: error: ld returned 1 exit status
> make[4]: *** [Makefile:97 : xs_tdb_dump] Erreur 1
> make[4] : on quitte le répertoire « /home/david/xen/xen/tools/xenstore »
> make[3]: *** [/home/david/xen/xen/tools/../tools/Rules.mk:249 :
> subdir-install-xenstore] Erreur 2
> make[3] : on quitte le répertoire « /home/david/xen/xen/tools »
> make[2]: *** [/home/david/xen/xen/tools/../tools/Rules.mk:244 :
> subdirs-install] Erreur 2
> make[2] : on quitte le répertoire « /home/david/xen/xen/tools »
> make[1]: *** [Makefile:74 : install] Erreur 2
> make[1] : on quitte le répertoire « /home/david/xen/xen/tools »
> make: *** [Makefile:127 : install-tools] Erreur 2
> david@debian:~/xen/xen$ uname -a
> Linux debian 5.7.0-2-amd64 #1 SMP Debian 5.7.10-1 (2020-07-26) x86_64
> GNU/Linux
> david@debian:~/xen/xen$ gcc --version
> gcc (Debian 10.2.0-5) 10.2.0
> Copyright (C) 2020 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE.
>
> david@debian:~/xen/xen$ /usr/bin/ld --version
> GNU ld (GNU Binutils for Debian) 2.35
> Copyright (C) 2020 Free Software Foundation, Inc.
> Ce logiciel est libre; si vous le redistribuez, vous devez le faire
> selon les termes
> de la licence GNU General Public License version 3 ou postérieure
> selon votre besoin.
> Ce logiciel n'est couvert par aucune GARANTIE.
> david@debian:~/xen/xen$ git branch
>   master
> * 

Re: Compiling Xen from source

2020-09-15 Thread Hans van Kranenburg
Hi,

On 9/16/20 12:00 AM, Andrew Cooper wrote:
> On 15/09/2020 21:16, David I wrote:
>> Hello,
>>
>> I am unable to mcompile xen-tools from source.
>>
>> here is the "stacktrace":
>>
>> ln -f xenstore xenstore-watch
>> gcc xenstore_control.o    
>>  -Wl,-rpath-link=/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore
>> /home/david/xen/xen/tools/xenstore/../../tools/xenstore/libxenstore.so
>> -ldl
>>  
>> /home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so
>>  -o xenstore-control
>> gcc  -m64 -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall
>> -Wstrict-prototypes -Wdeclaration-after-statement
>> -Wno-unused-but-set-variable -Wno-unused-local-typedefs   -O2
>> -fomit-frame-pointer
>> -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MF
>> .xs_tdb_dump.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE   -Werror
>> -I. -include /home/david/xen/xen/tools/xenstore/../../tools/config.h
>> -I./include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/evtchn/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libxc/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toollog/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/foreignmemory/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/devicemodel/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -D__XEN_TOOLS__
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -DXEN_LIB_STORED="\"/var/lib/xenstored\""
>> -DXEN_RUN_STORED="\"/var/run/xenstored\""   -c -o xs_tdb_dump.o
>> xs_tdb_dump.c
>> gcc  -m64 -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall
>> -Wstrict-prototypes -Wdeclaration-after-statement
>> -Wno-unused-but-set-variable -Wno-unused-local-typedefs   -O2
>> -fomit-frame-pointer
>> -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MF
>> .utils.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE   -Werror -I.
>> -include /home/david/xen/xen/tools/xenstore/../../tools/config.h
>> -I./include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/evtchn/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libxc/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toollog/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/foreignmemory/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/devicemodel/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -D__XEN_TOOLS__
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include
>> -DXEN_LIB_STORED="\"/var/lib/xenstored\""
>> -DXEN_RUN_STORED="\"/var/run/xenstored\""  
>> -I/home/david/xen/xen/tools/xenstore/../../tools/libs/gnttab/include
>> -I/home/david/xen/xen/tools/xenstore/../../tools/include  -c -o
>> utils.o utils.c
>> gcc xs_tdb_dump.o utils.o tdb.o talloc.o     -o xs_tdb_dump
>> /usr/bin/ld : utils.o:(.data.rel.local+0x0) : définitions multiples de
>> « xprintf »; xs_tdb_dump.o:(.bss+0x0) : défini pour la première fois ici
>> collect2: error: ld returned 1 exit status
>> make[4]: *** [Makefile:97 : xs_tdb_dump] Erreur 1
>> make[4] : on quitte le répertoire « /home/david/xen/xen/tools/xenstore »
>> make[3]: *** [/home/david/xen/xen/tools/../tools/Rules.mk:249 :
>> subdir-install-xenstore] Erreur 2
>> make[3] : on quitte le répertoire « /home/david/xen/xen/tools »
>> make[2]: *** [/home/david/xen/xen/tools/../tools/Rules.mk:244 :
>> subdirs-install] Erreur 2
>> make[2] : on quitte le répertoire « /home/david/xen/xen/tools »
>> make[1]: *** [Makefile:74 : install] Erreur 2
>> make[1] : on quitte le répertoire « /home/david/xen/xen/tools »
>> make: *** [Makefile:127 : install-tools] Erreur 2
>> david@debian:~/xen/xen$ uname -a
>> Linux debian 5.7.0-2-amd64 #1 SMP Debian 5.7.10-1 (2020-07-26) x86_64
>> GNU/Linux
>> david@debian:~/xen/xen$ gcc --version
>> gcc (Debian 10.2.0-5) 10.2.0
>> Copyright (C) 2020 Free Software Foundation, Inc.
>> This is free software; see the source for copying conditions.  There is NO
>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
>> PURPOSE.
>>
>> david@debian:~/xen/xen$ /usr/bin/ld --version
>> GNU ld (GNU Binutils for Debian) 2.35
>> Copyright (C) 2020 Free Software Foundation, Inc.
>> Ce logiciel est libre; si vous le redistribuez, vous devez le faire
>> selon les termes
>> de la licence GNU General Public License version 3 ou 

[PATCH] x86/mm: Simplify expression in set_gpfn_from_mfn()

2020-09-15 Thread Andrew Cooper
Coverity points out that the "d &&" is redundant.

Fixes: c9476c4ad72 ("x86: don't override INVALID_M2P_ENTRY with 
SHARED_M2P_ENTRY")
Signed-off-by: Andrew Cooper 
---
CC: Jan Beulich 
CC: Roger Pau Monné 
CC: Wei Liu 
---
 xen/arch/x86/x86_64/mm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 0d1aadbfce..4c0a3a275c 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1336,7 +1336,7 @@ void set_gpfn_from_mfn(unsigned long mfn, unsigned long 
pfn)
 {
 const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
 
-if ( d && (d == dom_cow) )
+if ( d == dom_cow )
 entry = SHARED_M2P_ENTRY;
 }
 
-- 
2.11.0




[xen-4.13-testing test] 154358: tolerable FAIL - PUSHED

2020-09-15 Thread osstest service owner
flight 154358 xen-4.13-testing real [real]
http://logs.test-lab.xenproject.org/osstest/logs/154358/

Failures :-/ but no regressions.

Tests which did not succeed, but are not blocking:
 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-xl-pvshim12 guest-start  fail   never pass
 test-arm64-arm64-xl-credit2  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-credit1  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit1  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  14 saverestore-support-checkfail   never pass
 test-amd64-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-armhf-armhf-xl-credit2  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit2  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 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-multivcpu 13 migrate-support-checkfail  never pass
 test-armhf-armhf-xl-multivcpu 14 saverestore-support-checkfail  never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-credit1  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit1  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-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-amd64-amd64-xl-qemuu-win7-amd64 17 guest-stop fail never pass
 test-amd64-i386-xl-qemuu-win7-amd64 17 guest-stop  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-xl-qemut-win7-amd64 17 guest-stop  fail 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-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-amd64-i386-xl-qemut-ws16-amd64 17 guest-stop  fail never pass
 test-amd64-amd64-xl-qemut-win7-amd64 17 guest-stop fail 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-rtds 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 14 saverestore-support-checkfail   never pass
 test-amd64-amd64-xl-qemuu-ws16-amd64 17 guest-stop fail never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 17 guest-stop  fail never pass
 test-amd64-amd64-xl-qemut-ws16-amd64 17 guest-stop fail never pass

version targeted for testing:
 xen  c663fa577b42e7f4731bb33fc7f94f7ffb05a1ef
baseline version:
 xen  9b367b2b0b714f3ffb69ed6be0a118e8d3eac07f

Last test of basis   152528  2020-08-07 15:39:16 Z   39 days
Testing same since   154358  2020-09-15 09:40:09 Z0 days1 attempts


People who touched revisions under test:
  Andrew Cooper 
  Jan Beulich 
  Roger Pau Monné 

jobs:
 build-amd64-xsm  pass
 build-arm64-xsm  pass
 build-i386-xsm   pass
 build-amd64-xtf

Compiling Xen from source

2020-09-15 Thread David I
Hello,

I am unable to mcompile xen-tools from source.

here is the "stacktrace":

ln -f xenstore xenstore-watch
gcc xenstore_control.o
 -Wl,-rpath-link=/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore
/home/david/xen/xen/tools/xenstore/../../tools/xenstore/libxenstore.so -ldl
 /home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so
 -o xenstore-control
gcc  -m64 -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall
-Wstrict-prototypes -Wdeclaration-after-statement
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -O2
-fomit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MF
.xs_tdb_dump.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE   -Werror -I.
-include /home/david/xen/xen/tools/xenstore/../../tools/config.h
-I./include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/evtchn/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libxc/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/toollog/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/foreignmemory/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/devicemodel/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include -D__XEN_TOOLS__
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-DXEN_LIB_STORED="\"/var/lib/xenstored\""
-DXEN_RUN_STORED="\"/var/run/xenstored\""   -c -o xs_tdb_dump.o
xs_tdb_dump.c
gcc  -m64 -DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall
-Wstrict-prototypes -Wdeclaration-after-statement
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -O2
-fomit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MF
.utils.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE   -Werror -I. -include
/home/david/xen/xen/tools/xenstore/../../tools/config.h -I./include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/evtchn/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libxc/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/toollog/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/foreignmemory/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/devicemodel/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include -D__XEN_TOOLS__
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/toolcore/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include
-DXEN_LIB_STORED="\"/var/lib/xenstored\""
-DXEN_RUN_STORED="\"/var/run/xenstored\""
-I/home/david/xen/xen/tools/xenstore/../../tools/libs/gnttab/include
-I/home/david/xen/xen/tools/xenstore/../../tools/include  -c -o utils.o
utils.c
gcc xs_tdb_dump.o utils.o tdb.o talloc.o -o xs_tdb_dump
/usr/bin/ld : utils.o:(.data.rel.local+0x0) : définitions multiples de
« xprintf »; xs_tdb_dump.o:(.bss+0x0) : défini pour la première fois ici
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:97 : xs_tdb_dump] Erreur 1
make[4] : on quitte le répertoire « /home/david/xen/xen/tools/xenstore »
make[3]: *** [/home/david/xen/xen/tools/../tools/Rules.mk:249 :
subdir-install-xenstore] Erreur 2
make[3] : on quitte le répertoire « /home/david/xen/xen/tools »
make[2]: *** [/home/david/xen/xen/tools/../tools/Rules.mk:244 :
subdirs-install] Erreur 2
make[2] : on quitte le répertoire « /home/david/xen/xen/tools »
make[1]: *** [Makefile:74 : install] Erreur 2
make[1] : on quitte le répertoire « /home/david/xen/xen/tools »
make: *** [Makefile:127 : install-tools] Erreur 2
david@debian:~/xen/xen$ uname -a
Linux debian 5.7.0-2-amd64 #1 SMP Debian 5.7.10-1 (2020-07-26) x86_64
GNU/Linux
david@debian:~/xen/xen$ gcc --version
gcc (Debian 10.2.0-5) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

david@debian:~/xen/xen$ /usr/bin/ld --version
GNU ld (GNU Binutils for Debian) 2.35
Copyright (C) 2020 Free Software Foundation, Inc.
Ce logiciel est libre; si vous le redistribuez, vous devez le faire selon
les termes
de la licence GNU General Public License version 3 ou postérieure selon
votre besoin.
Ce logiciel n'est couvert par aucune GARANTIE.
david@debian:~/xen/xen$ git branch
  master
* stable-4.11
  staging
david@debian:~/xen/xen$

I was able to compile dist-xen correctly though. But dist-tools fails with
this error, I have seen a similar request here:

Re: [PATCH v3 02/11] xenbus: add freeze/thaw/restore callbacks support

2020-09-15 Thread Anchal Agarwal
On Sun, Sep 13, 2020 at 12:11:47PM -0400, boris.ostrov...@oracle.com wrote:
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On 8/21/20 6:26 PM, Anchal Agarwal wrote:
> > From: Munehisa Kamata 
> >
> > Since commit b3e96c0c7562 ("xen: use freeze/restore/thaw PM events for
> > suspend/resume/chkpt"), xenbus uses PMSG_FREEZE, PMSG_THAW and
> > PMSG_RESTORE events for Xen suspend. However, they're actually assigned
> > to xenbus_dev_suspend(), xenbus_dev_cancel() and xenbus_dev_resume()
> > respectively, and only suspend and resume callbacks are supported at
> > driver level. To support PM suspend and PM hibernation, modify the bus
> > level PM callbacks to invoke not only device driver's suspend/resume but
> > also freeze/thaw/restore.
> >
> > Note that we'll use freeze/restore callbacks even for PM suspend whereas
> > suspend/resume callbacks are normally used in the case, becausae the
> > existing xenbus device drivers already have suspend/resume callbacks
> > specifically designed for Xen suspend.
> 
> 
> Something is wrong with this sentence. Or with my brain --- I can't
> quite parse this.
> 
The message is trying to say that that freeze/thaw/restore callbacks will be
used for both PM SUSPEND and PM HIBERNATION. Since, we are only focussing on PM
hibernation, I will remove all wordings of PM suspend from this message to avoid
confusion. I left it there in case someone wants to pick it up in future knowing
framework is already present.
> 
> And please be consistent with "PM suspend" vs. "PM hibernation".
>
I should remove PM suspend from everywhere since the mode is not tested
for.
> 
> >  So we can allow the device
> > drivers to keep the existing callbacks wihtout modification.
> >
> 
> 
> > @@ -599,16 +600,33 @@ int xenbus_dev_suspend(struct device *dev)
> >   struct xenbus_driver *drv;
> >   struct xenbus_device *xdev
> >   = container_of(dev, struct xenbus_device, dev);
> > + bool xen_suspend = is_xen_suspend();
> >
> >   DPRINTK("%s", xdev->nodename);
> >
> >   if (dev->driver == NULL)
> >   return 0;
> >   drv = to_xenbus_driver(dev->driver);
> > - if (drv->suspend)
> > - err = drv->suspend(xdev);
> > - if (err)
> > - dev_warn(dev, "suspend failed: %i\n", err);
> > + if (xen_suspend) {
> > + if (drv->suspend)
> > + err = drv->suspend(xdev);
> > + } else {
> > + if (drv->freeze) {
> 
> 
> 'else if' (to avoid extra indent level).  In xenbus_dev_resume() too.
> 
> 
> > + err = drv->freeze(xdev);
> > + if (!err) {
> > + free_otherend_watch(xdev);
> > + free_otherend_details(xdev);
> > + return 0;
> > + }
> > + }
> > + }
> > +
> > + if (err) {
> > + dev_warn(>dev,
> 
> 
> Is there a reason why you replaced dev with xdev->dev (here and elsewhere)?
> 
> 
Nope, they should be same. We can use dev here too. I should probably just use
dev.
> >  "%s %s failed: %d\n", xen_suspend ?
> > + "suspend" : "freeze", xdev->nodename, err);
> > + return err;
> > + }
> > +
> >
> 
> > @@ -653,8 +683,44 @@ EXPORT_SYMBOL_GPL(xenbus_dev_resume);
> >
> >  int xenbus_dev_cancel(struct device *dev)
> >  {
> > - /* Do nothing */
> > - DPRINTK("cancel");
> > + int err;
> > + struct xenbus_driver *drv;
> > + struct xenbus_device *xendev = to_xenbus_device(dev);
> 
> 
> xdev for consistency please.
> 
Yes this I left unchanged, it should be consistent with xdev.
> 
> > + bool xen_suspend = is_xen_suspend();
> 
> 
> No need for this, you use it only once anyway.
> 
> 
> -boris
>
Thanks,
Anchal
> 



Re: [PATCH v3 01/11] xen/manage: keep track of the on-going suspend mode

2020-09-15 Thread boris . ostrovsky



>>
>>
> +
> +static int xen_setup_pm_notifier(void)
> +{
> + if (!xen_hvm_domain() || xen_initial_domain())
> + return -ENODEV;

 I don't think this works anymore.
>>> What do you mean?
>>> The first check is for xen domain types and other is for architecture 
>>> support.
>>> The reason I put this check here is because I wanted to segregate the two.
>>> I do not want to register this notifier at all for !hmv guest and also if 
>>> its
>>> an initial control domain.
>>> The arm check only lands in notifier because once hibernate() api is called 
>>> ->
>>> calls pm_notifier_call_chain for PM_HIBERNATION_PREPARE this will fail for
>>> aarch64.
>>> Once we have support for aarch64 this notifier can go away altogether.
>>>
>>> Is there any other reason I may be missing why we should move this check to
>>> notifier?
>>
>>
>> Not registering this notifier is equivalent to having it return NOTIFY_OK.
>>
> How is that different from current behavior?
>>
>> In your earlier versions just returning NOTIFY_OK was not sufficient for
>> hibernation to proceed since the notifier would also need to set
>> suspend_mode appropriately. But now your notifier essentially filters
>> out unsupported configurations. And so if it is not called your
>> configuration (e.g. PV domain) will be considered supported.
>>
> I am sorry if I am having a bit of hard time understanding this. 
> How will it be considered supported when its not even registered? My
> understanding is if its not registered, it will not land in notifier call 
> chain
> which is invoked in pm_notifier_call_chain().


Returning an error from xen_setup_pm_notifier() doesn't have any effect
on whether hibernation will start. It's the notifier that can stop it.

> 
> As Roger, mentioned in last series none of this should be a part of PVH dom0 
> hibernation as its not tested but this series should also not break anything.
> If I register this notifier for PVH dom0 and return error later that will 
> alter
> the current behavior right?
> 
> If a pm_notifier for pvh dom0 is not registered then it will not land in the
> notifier call chain and system will work as before this series.
> If I look for unsupported configurations, then !hvm domain is also one but we
> filter that out at the beginning and don't even bother about it.
> 
> Unless you mean guest running VMs itself? [Trying to read between the lines 
> may
> not be the case though]



In hibernate():

error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1,
_calls);
if (error) {
nr_calls--;
goto Exit;
}


Is you don't have notifier registered (as will be the case with PV
domains and dom0) you won't get an error and proceed with hibernation.
(And now I actually suspect it didn't work even with your previous patches)


But something like this I think will do what you want:


static int xen_pm_notifier(struct notifier_block *notifier,
unsigned long pm_event, void *unused)

{

   if (IS_ENABLED(CONFIG_ARM64) ||
   !xen_hvm_domain() || xen_initial_domain() ||
   (pm_event == PM_SUSPEND_PREPARE)) {
if ((pm_event == PM_SUSPEND_PREPARE) || (pm_event ==
PM_HIBERNATION_PREPARE))
pr_warn("%s is not supported for this guest",
(pm_event == PM_SUSPEND_PREPARE) ?
"Suspend" : "Hibernation");
return NOTIFY_BAD;

return NOTIFY_OK;

}

static int xen_setup_pm_notifier(void)
{
return register_pm_notifier(_pm_notifier_block);
}


I tried to see if there is a way to prevent hibernation without using
notifiers (like having a global flag or something) but didn't find
anything obvious. Perhaps others can point to a simpler way of doing this.


-boris




Re: [PATCH v2 1/2] libxl: provide a mechanism to define a device 'safe remove' function...

2020-09-15 Thread Roger Pau Monné
On Tue, Sep 15, 2020 at 02:40:09PM +, Durrant, Paul wrote:
> > -Original Message-
> > From: Roger Pau Monné 
> > Sent: 15 September 2020 15:32
> > To: Paul Durrant 
> > Cc: xen-devel@lists.xenproject.org; Durrant, Paul ; 
> > Ian Jackson
> > ; Wei Liu ; Anthony PERARD 
> > 
> > Subject: RE: [EXTERNAL] [PATCH v2 1/2] libxl: provide a mechanism to define 
> > a device 'safe remove'
> > function...
> > 
> > CAUTION: This email originated from outside of the organization. Do not 
> > click links or open
> > attachments unless you can confirm the sender and know the content is safe.
> > 
> > 
> > 
> > On Tue, Sep 15, 2020 at 03:10:06PM +0100, Paul Durrant wrote:
> > > From: Paul Durrant 
> > >
> > > ... and use it to define libxl_device_disk_safe_remove().
> > >
> > > This patch builds on the existent macro magic by using a new value of the
> > > 'force' field in in libxl__ao_device.
> > > It is currently defined as an int but is used in a boolean manner where
> > > 1 means the operation is forced and 0 means it is not (but is actually 
> > > forced
> > > after a 10s time-out). In adding a third value, this patch re-defines 
> > > 'force'
> > > as a struct type (libxl__force) with a single 'flag' field taking an
> > > enumerated value:
> > >
> > > LIBXL__FORCE_AUTO - corresponding to the old 0 value
> > > LIBXL__FORCE_ON   - corresponding to the old 1 value
> > > LIBXL__FORCE_OFF  - the new value
> > >
> > > The LIBXL_DEFINE_DEVICE_REMOVE() macro is then modified to define the
> > > libxl_device__remove() and libxl_device__destroy() functions,
> > > setting LIBXL__FORCE_AUTO and LIBXL__FORCE_ON (respectively) in the
> > > libxl__ao_device passed to libxl__initiate_device_generic_remove() and a
> > > new macro, LIBXL_DEFINE_DEVICE_SAFE_REMOVE(), is defined that sets
> > > LIBXL__FORCE_OFF instead. This macro is used to define the new
> > > libxl_device_disk_safe_remove() function.
> > >
> > > Signed-off-by: Paul Durrant 
> > 
> > Reviewed-by: Roger Pau Monné 
> > 
> 
> Thanks.
> 
> > Just one nit.
> > 
> > > diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> > > index e16ae9630b..1fcf85c3e2 100644
> > > --- a/tools/libxl/libxl_internal.h
> > > +++ b/tools/libxl/libxl_internal.h
> > > @@ -2730,12 +2730,20 @@ _hidden void libxl__prepare_ao_device(libxl__ao 
> > > *ao, libxl__ao_device
> > *aodev);
> > >  /* generic callback for devices that only need to set ao_complete */
> > >  _hidden void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device 
> > > *aodev);
> > >
> > > +typedef struct {
> > > +enum {
> > > +LIBXL__FORCE_AUTO, /* Re-execute with FORCE_ON if op times out */
> > > +LIBXL__FORCE_ON,
> > > +LIBXL__FORCE_OFF,
> > > +} flag;
> > > +} libxl__force;
> > 
> > Couldn't you just use the typedef against the union directly instead
> > of wrapping it around a struct?
> 
> You mean s/union/enum?

Yes :) sorry for that.

> I could have done that, but it helped find all the places where aodev->force 
> is used and I liked the abstraction. I don't mind changing if there are 
> strong opinions against it.

While it's indeed helpful to find the users to fixup, it just makes
the lines longer in the final patch IMO. Let's see what opinions
others have however.

Thanks, Roger.



Re: [PATCH v2 1/2] libxl: provide a mechanism to define a device 'safe remove' function...

2020-09-15 Thread Roger Pau Monné
On Tue, Sep 15, 2020 at 03:10:06PM +0100, Paul Durrant wrote:
> From: Paul Durrant 
> 
> ... and use it to define libxl_device_disk_safe_remove().
> 
> This patch builds on the existent macro magic by using a new value of the
> 'force' field in in libxl__ao_device.
> It is currently defined as an int but is used in a boolean manner where
> 1 means the operation is forced and 0 means it is not (but is actually forced
> after a 10s time-out). In adding a third value, this patch re-defines 'force'
> as a struct type (libxl__force) with a single 'flag' field taking an
> enumerated value:
> 
> LIBXL__FORCE_AUTO - corresponding to the old 0 value
> LIBXL__FORCE_ON   - corresponding to the old 1 value
> LIBXL__FORCE_OFF  - the new value
> 
> The LIBXL_DEFINE_DEVICE_REMOVE() macro is then modified to define the
> libxl_device__remove() and libxl_device__destroy() functions,
> setting LIBXL__FORCE_AUTO and LIBXL__FORCE_ON (respectively) in the
> libxl__ao_device passed to libxl__initiate_device_generic_remove() and a
> new macro, LIBXL_DEFINE_DEVICE_SAFE_REMOVE(), is defined that sets
> LIBXL__FORCE_OFF instead. This macro is used to define the new
> libxl_device_disk_safe_remove() function.
> 
> Signed-off-by: Paul Durrant 

Reviewed-by: Roger Pau Monné 

Just one nit.

> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> index e16ae9630b..1fcf85c3e2 100644
> --- a/tools/libxl/libxl_internal.h
> +++ b/tools/libxl/libxl_internal.h
> @@ -2730,12 +2730,20 @@ _hidden void libxl__prepare_ao_device(libxl__ao *ao, 
> libxl__ao_device *aodev);
>  /* generic callback for devices that only need to set ao_complete */
>  _hidden void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device 
> *aodev);
>  
> +typedef struct {
> +enum {
> +LIBXL__FORCE_AUTO, /* Re-execute with FORCE_ON if op times out */
> +LIBXL__FORCE_ON,
> +LIBXL__FORCE_OFF,
> +} flag;
> +} libxl__force;

Couldn't you just use the typedef against the union directly instead
of wrapping it around a struct?

Thanks, Roger.



[linux-linus test] 154356: regressions - FAIL

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

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-amd64-i386-qemut-rhel6hvm-intel  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-ws16-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-dmrestrict-amd64-dmrestrict 7 xen-boot fail REGR. vs. 
152332
 test-amd64-i386-xl-qemuu-debianhvm-amd64-shadow 7 xen-boot fail REGR. vs. 
152332
 test-amd64-i386-xl-xsm7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-qemuu-rhel6hvm-intel  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-debianhvm-amd64  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-examine   8 reboot   fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-debianhvm-i386-xsm  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-pair 10 xen-boot/src_hostfail REGR. vs. 152332
 test-amd64-i386-pair 11 xen-boot/dst_hostfail REGR. vs. 152332
 test-amd64-i386-libvirt   7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-ws16-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-debianhvm-amd64  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-libvirt-xsm   7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-qemut-rhel6hvm-amd  7 xen-boot   fail REGR. vs. 152332
 test-amd64-i386-qemuu-rhel6hvm-amd  7 xen-boot   fail REGR. vs. 152332
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 7 xen-boot fail REGR. vs. 
152332
 test-amd64-i386-xl7 xen-boot fail REGR. vs. 152332
 test-amd64-coresched-i386-xl  7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-raw7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-freebsd10-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-pvshim 7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-debianhvm-i386-xsm  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-win7-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-shadow 7 xen-boot fail REGR. vs. 152332
 test-amd64-i386-freebsd10-i386  7 xen-boot   fail REGR. vs. 152332
 test-amd64-i386-xl-qemuu-ovmf-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-xl-qemut-win7-amd64  7 xen-boot  fail REGR. vs. 152332
 test-amd64-i386-libvirt-pair 10 xen-boot/src_hostfail REGR. vs. 152332
 test-amd64-i386-libvirt-pair 11 xen-boot/dst_hostfail REGR. vs. 152332
 test-amd64-i386-xl-qemut-stubdom-debianhvm-amd64-xsm 7 xen-boot fail REGR. vs. 
152332

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-xl-qemut-win7-amd64 17 guest-stopfail like 152332
 test-amd64-amd64-xl-qemuu-win7-amd64 17 guest-stopfail like 152332
 test-amd64-amd64-xl-qemut-ws16-amd64 17 guest-stopfail like 152332
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail  like 152332
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail  like 152332
 test-amd64-amd64-xl-qemuu-ws16-amd64 17 guest-stopfail like 152332
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  14 saverestore-support-checkfail   never pass
 test-amd64-amd64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 14 saverestore-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 14 saverestore-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-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit1  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit1  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-credit1  13 migrate-support-checkfail   

Re: [PATCH 1/9] build: use if_changed more consistently (and correctly) for prelink*.o

2020-09-15 Thread Roger Pau Monné
On Tue, Sep 15, 2020 at 02:26:34PM +0200, Jan Beulich wrote:
> On 15.09.2020 13:56, Roger Pau Monné wrote:
> > On Mon, Sep 14, 2020 at 12:15:39PM +0200, Jan Beulich wrote:
> >> Switch to $(call if_changed,ld) where possible; presumably not doing so
> >> in e321576f4047 ("xen/build: start using if_changed") right away was an
> >> oversight, as it did for Arm in (just) one case. It failed to add
> >> prelink.o to $(targets), though, causing - judging from the observed
> >> behavior on x86 - undue rebuilds of the final binary (because of
> >> prelink.o getting rebuild for $(cmd_prelink.o) being empty, in turn
> >> because of .prelink.o.cmd not getting read) during "make install-xen".
> > 
> > I'm not sure I follow why prelink.o needs to be added to targets, does
> > this offer some kind of protection against rebuilds when doing make
> > install?
> 
> In a way, but (as I view it) not really. It is the use of ...
> 
> > The switch to if_changed LGTM.
> 
> ... if_changed which requires this. .*.cmd files will only be loaded
> for anything explicitly or implicitly listed as a target. While .o
> coming from $(obj-y) get added there automatically, prelink.o is not
> something that could be recognized as needing adding, hence the
> "manual" insertion.

This seems very prone to mistakes, as you have to remember that
whatever object that uses if_changed should also be part of the
targets set, or else it will get rebuild unconditionally.

I think adding some of the above reasoning to the commit message would
be helpful IMO.

> Without .prelink.o.cmd loaded, $(if_changed ) will always arrange
> for it to get re-built, because it then will consider the command
> used to build the file to have changed (as the stored one appears to
> be empty).

Acked-by: Roger Pau Monné 

Thanks, Roger.



Re: [PATCH v2 1/2] libxl: provide a mechanism to define a device 'safe remove' function...

2020-09-15 Thread Wei Liu
On Tue, Sep 15, 2020 at 03:10:06PM +0100, Paul Durrant wrote:
> From: Paul Durrant 
> 
> ... and use it to define libxl_device_disk_safe_remove().
> 
> This patch builds on the existent macro magic by using a new value of the
> 'force' field in in libxl__ao_device.
> It is currently defined as an int but is used in a boolean manner where
> 1 means the operation is forced and 0 means it is not (but is actually forced
> after a 10s time-out). In adding a third value, this patch re-defines 'force'
> as a struct type (libxl__force) with a single 'flag' field taking an
> enumerated value:
> 
> LIBXL__FORCE_AUTO - corresponding to the old 0 value
> LIBXL__FORCE_ON   - corresponding to the old 1 value
> LIBXL__FORCE_OFF  - the new value
> 
> The LIBXL_DEFINE_DEVICE_REMOVE() macro is then modified to define the
> libxl_device__remove() and libxl_device__destroy() functions,
> setting LIBXL__FORCE_AUTO and LIBXL__FORCE_ON (respectively) in the
> libxl__ao_device passed to libxl__initiate_device_generic_remove() and a
> new macro, LIBXL_DEFINE_DEVICE_SAFE_REMOVE(), is defined that sets
> LIBXL__FORCE_OFF instead. This macro is used to define the new
> libxl_device_disk_safe_remove() function.
> 
> Signed-off-by: Paul Durrant 

Reviewed-by: Wei Liu 



[PATCH v8 3/8] tools/misc: add xen-domctx to present domain context

2020-09-15 Thread Paul Durrant
This tool is analogous to 'xen-hvmctx' which presents HVM context.
Subsequent patches will add 'dump' functions when new records are
introduced.

Signed-off-by: Paul Durrant 
Acked-by: Ian Jackson 
---
Cc: Andrew Cooper 
Cc: Wei Liu 

NOTE: Ian requested ack from Andrew

v3:
 - Re-worked to avoid copying onto stack
 - Added optional typecode and instance arguments

v2:
 - Change name from 'xen-ctx' to 'xen-domctx'
---
 .gitignore  |   1 +
 tools/misc/Makefile |   4 +
 tools/misc/xen-domctx.c | 200 
 3 files changed, 205 insertions(+)
 create mode 100644 tools/misc/xen-domctx.c

diff --git a/.gitignore b/.gitignore
index 823f4743dc..cadb29ea23 100644
--- a/.gitignore
+++ b/.gitignore
@@ -212,6 +212,7 @@ tools/misc/xen_cpuperf
 tools/misc/xen-cpuid
 tools/misc/xen-detect
 tools/misc/xen-diag
+tools/misc/xen-domctx
 tools/misc/xen-tmem-list-parse
 tools/misc/xen-livepatch
 tools/misc/xenperf
diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 9fdb13597f..13e37402e2 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -31,6 +31,7 @@ INSTALL_SBIN   += xenpm
 INSTALL_SBIN   += xenwatchdogd
 INSTALL_SBIN   += xen-livepatch
 INSTALL_SBIN   += xen-diag
+INSTALL_SBIN   += xen-domctx
 INSTALL_SBIN += $(INSTALL_SBIN-y)
 
 # Everything to be installed in a private bin/
@@ -114,6 +115,9 @@ xen-livepatch: xen-livepatch.o
 xen-diag: xen-diag.o
$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
+xen-domctx: xen-domctx.o
+   $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+
 xen-lowmemd: xen-lowmemd.o
$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) 
$(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c
new file mode 100644
index 00..243325dfce
--- /dev/null
+++ b/tools/misc/xen-domctx.c
@@ -0,0 +1,200 @@
+/*
+ * xen-domctx.c
+ *
+ * Print out domain save records in a human-readable way.
+ *
+ * Copyright Amazon.com Inc. or its affiliates.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+static void *buf = NULL;
+static size_t len, off;
+
+#define GET_PTR(_x)\
+do {   \
+if ( len - off < sizeof(*(_x)) )   \
+{  \
+fprintf(stderr,\
+"error: need another %lu bytes, only %lu available\n", \
+sizeof(*(_x)), len - off); \
+exit(1);   \
+}  \
+(_x) = buf + off;  \
+} while (false);
+
+static void dump_header(void)
+{
+DOMAIN_SAVE_TYPE(HEADER) *h;
+
+GET_PTR(h);
+
+printf("HEADER: magic %#x, version %u\n",
+   h->magic, h->version);
+
+}
+
+static void dump_end(void)
+{
+DOMAIN_SAVE_TYPE(END) *e;
+
+GET_PTR(e);
+
+printf("END\n");
+}
+
+static void usage(const char *prog)
+{
+fprintf(stderr, "usage: %s  [  [  ]]\n",
+prog);
+exit(1);
+}
+
+int main(int argc, char **argv)
+{
+char *s, *e;
+long domid;
+long typecode = -1;
+long instance = -1;
+unsigned int entry;
+xc_interface *xch;
+int rc;
+
+if ( argc < 2 || argc > 4 )
+usage(argv[0]);
+
+s = e = argv[1];
+domid = strtol(s, , 0);
+
+if ( *s == '\0' || *e != '\0' ||
+ domid < 0 || domid >= 

[PATCH v8 2/8] xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontext

2020-09-15 Thread Paul Durrant
These domctls provide a mechanism to get and set domain context from
the toolstack.

Signed-off-by: Paul Durrant 
Reviewed-by: Julien Grall 
---
Cc: Daniel De Graaf 
Cc: Ian Jackson 
Cc: Wei Liu 
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Jan Beulich 
Cc: Stefano Stabellini 

v4:
 - Add missing zero pad checks

v3:
 - Addressed comments from Julien and Jan
 - Use vmalloc() rather than xmalloc_bytes()

v2:
 - drop mask parameter
 - const-ify some more buffers
---
 tools/flask/policy/modules/xen.if   |   4 +-
 tools/libxc/include/xenctrl.h   |   5 +
 tools/libxc/xc_domain.c |  56 +
 xen/common/domctl.c | 173 
 xen/include/public/domctl.h |  41 +++
 xen/xsm/flask/hooks.c   |   6 +
 xen/xsm/flask/policy/access_vectors |   4 +
 7 files changed, 287 insertions(+), 2 deletions(-)

diff --git a/tools/flask/policy/modules/xen.if 
b/tools/flask/policy/modules/xen.if
index 8eb2293a52..2bc9db4f64 100644
--- a/tools/flask/policy/modules/xen.if
+++ b/tools/flask/policy/modules/xen.if
@@ -53,7 +53,7 @@ define(`create_domain_common', `
allow $1 $2:domain2 { set_cpu_policy settsc setscheduler setclaim
set_vnumainfo get_vnumainfo cacheflush
psr_cmt_op psr_alloc soft_reset
-   resource_map get_cpu_policy };
+   resource_map get_cpu_policy setcontext };
allow $1 $2:security check_context;
allow $1 $2:shadow enable;
allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage 
mmuext_op updatemp };
@@ -97,7 +97,7 @@ define(`migrate_domain_out', `
allow $1 $2:hvm { gethvmc getparam };
allow $1 $2:mmu { stat pageinfo map_read };
allow $1 $2:domain { getaddrsize getvcpucontext pause destroy };
-   allow $1 $2:domain2 gettsc;
+   allow $1 $2:domain2 { gettsc getcontext };
allow $1 $2:shadow { enable disable logdirty };
 ')
 
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 4c89b7294c..5eb04dcb38 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -867,6 +867,11 @@ int xc_domain_hvm_setcontext(xc_interface *xch,
  uint8_t *hvm_ctxt,
  uint32_t size);
 
+int xc_domain_getcontext(xc_interface *xch, uint32_t domid,
+ void *ctxt_buf, size_t *size);
+int xc_domain_setcontext(xc_interface *xch, uint32_t domid,
+ const void *ctxt_buf, size_t size);
+
 /**
  * This function will return guest IO ABI protocol
  *
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 71829c2bce..e462a6f728 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -537,6 +537,62 @@ int xc_domain_hvm_setcontext(xc_interface *xch,
 return ret;
 }
 
+int xc_domain_getcontext(xc_interface *xch, uint32_t domid,
+ void *ctxt_buf, size_t *size)
+{
+int ret;
+DECLARE_DOMCTL = {
+.cmd = XEN_DOMCTL_getdomaincontext,
+.domain = domid,
+.u.getdomaincontext.size = *size,
+};
+DECLARE_HYPERCALL_BOUNCE(ctxt_buf, *size, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+
+if ( xc_hypercall_bounce_pre(xch, ctxt_buf) )
+return -1;
+
+set_xen_guest_handle(domctl.u.setdomaincontext.buffer, ctxt_buf);
+
+ret = do_domctl(xch, );
+
+xc_hypercall_bounce_post(xch, ctxt_buf);
+
+if ( ret )
+return ret;
+
+*size = domctl.u.getdomaincontext.size;
+if ( *size != domctl.u.getdomaincontext.size )
+{
+errno = EOVERFLOW;
+return -1;
+}
+
+return 0;
+}
+
+int xc_domain_setcontext(xc_interface *xch, uint32_t domid,
+ const void *ctxt_buf, size_t size)
+{
+int ret;
+DECLARE_DOMCTL = {
+.cmd = XEN_DOMCTL_setdomaincontext,
+.domain = domid,
+.u.setdomaincontext.size = size,
+};
+DECLARE_HYPERCALL_BOUNCE_IN(ctxt_buf, size);
+
+if ( xc_hypercall_bounce_pre(xch, ctxt_buf) )
+return -1;
+
+set_xen_guest_handle(domctl.u.setdomaincontext.buffer, ctxt_buf);
+
+ret = do_domctl(xch, );
+
+xc_hypercall_bounce_post(xch, ctxt_buf);
+
+return ret;
+}
+
 int xc_vcpu_getcontext(xc_interface *xch,
uint32_t domid,
uint32_t vcpu,
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 5ac6e9c5ca..8ce5e7a2fa 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -25,6 +25,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -273,6 +275,168 @@ static struct vnuma_info *vnuma_init(const struct 
xen_domctl_vnuma *uinfo,
 return ERR_PTR(ret);
 }
 
+struct domctl_context
+{
+void *buffer;
+struct domain_save_descriptor *desc;
+size_t len;
+size_t cur;
+};
+
+static int dry_run_append(void *priv, const void *data, size_t len)
+{
+struct 

[PATCH v8 1/8] xen/common: introduce a new framework for save/restore of 'domain' context

2020-09-15 Thread Paul Durrant
To allow enlightened HVM guests (i.e. those that have PV drivers) to be
migrated without their co-operation it will be necessary to transfer 'PV'
state such as event channel state, grant entry state, etc.

Currently there is a framework (entered via the hvm_save/load() functions)
that allows a domain's 'HVM' (architectural) state to be transferred but
'PV' state is also common with pure PV guests and so this framework is not
really suitable.

This patch adds the new public header and low level implementation of a new
common framework, entered via the domain_save/load() functions. Subsequent
patches will introduce other parts of the framework, and code that will
make use of it within the current version of the libxc migration stream.

This patch also marks the HVM-only framework as deprecated in favour of the
new framework.

Signed-off-by: Paul Durrant 
Acked-by: Julien Grall 
Reviewed-by: Jan Beulich 
---
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Stefano Stabellini 
Cc: Wei Liu 
Cc: Volodymyr Babchuk 
Cc: "Roger Pau Monné" 

v7:
 - Add an option to domain_load_end() to ignore unconsumed data, which will
   be needed by a subsequent patch
 - Kept acks since the modification is very small

v4:
 - Addressed further comments from Jan

v3:
 - Addressed comments from Julien and Jan
 - Save handlers no longer need to state entry length up-front
 - Save handlers expected to deal with multiple instances internally
 - Entries are now auto-padded to 8 byte boundary

v2:
 - Allow multi-stage save/load to avoid the need to double-buffer
 - Get rid of the masks and add an 'ignore' flag instead
 - Create copy function union to preserve const save buffer
 - Deprecate HVM-only framework
---
 xen/common/Makefile|   1 +
 xen/common/save.c  | 315 +
 xen/include/public/arch-arm/hvm/save.h |   5 +
 xen/include/public/arch-x86/hvm/save.h |   5 +
 xen/include/public/save.h  |  89 +++
 xen/include/xen/save.h | 170 +
 6 files changed, 585 insertions(+)
 create mode 100644 xen/common/save.c
 create mode 100644 xen/include/public/save.h
 create mode 100644 xen/include/xen/save.h

diff --git a/xen/common/Makefile b/xen/common/Makefile
index b3b60a1ba2..3e6f21714a 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -37,6 +37,7 @@ obj-y += radix-tree.o
 obj-y += rbtree.o
 obj-y += rcupdate.o
 obj-y += rwlock.o
+obj-y += save.o
 obj-y += shutdown.o
 obj-y += softirq.o
 obj-y += sort.o
diff --git a/xen/common/save.c b/xen/common/save.c
new file mode 100644
index 00..841c4d0e4e
--- /dev/null
+++ b/xen/common/save.c
@@ -0,0 +1,315 @@
+/*
+ * save.c: Save and restore PV guest state common to all domain types.
+ *
+ * Copyright Amazon.com Inc. or its affiliates.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see .
+ */
+
+#include 
+#include 
+
+struct domain_context {
+struct domain *domain;
+const char *name; /* for logging purposes */
+struct domain_save_descriptor desc;
+size_t len; /* for internal accounting */
+union {
+const struct domain_save_ops *save;
+const struct domain_load_ops *load;
+} ops;
+void *priv;
+};
+
+static struct {
+const char *name;
+domain_save_handler save;
+domain_load_handler load;
+} handlers[DOMAIN_SAVE_CODE_MAX + 1];
+
+void __init domain_register_save_type(unsigned int typecode,
+  const char *name,
+  domain_save_handler save,
+  domain_load_handler load)
+{
+BUG_ON(typecode >= ARRAY_SIZE(handlers));
+
+ASSERT(!handlers[typecode].save);
+ASSERT(!handlers[typecode].load);
+
+handlers[typecode].name = name;
+handlers[typecode].save = save;
+handlers[typecode].load = load;
+}
+
+int domain_save_begin(struct domain_context *c, unsigned int typecode,
+  unsigned int instance)
+{
+int rc;
+
+if ( typecode != c->desc.typecode )
+{
+ASSERT_UNREACHABLE();
+return -EINVAL;
+}
+ASSERT(!c->desc.length); /* Should always be zero during domain_save() */
+ASSERT(!c->len); /* Verify domain_save_end() was called */
+
+rc = c->ops.save->begin(c->priv, >desc);
+if ( rc )
+return rc;
+
+return 0;
+}
+
+int domain_save_data(struct domain_context *c, const void *src, size_t len)
+{

[PATCH v8 8/8] tools/libxc: add DOMAIN_CONTEXT records to the migration stream...

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

... and bump the version.

This patch implements version 4 of the migration stream by adding the code
necessary to save and restore DOMAIN_CONTEXT records, and removing the code
to save the SHARED_INFO and TSC_INFO records (as these are deprecated in
version 4).

Signed-off-by: Paul Durrant 
---
Cc: Ian Jackson 
Cc: Wei Liu 

v7:
 - New in v7
---
 tools/libxc/xc_sr_common.h   |  3 ++
 tools/libxc/xc_sr_common_x86.c   | 20 
 tools/libxc/xc_sr_common_x86.h   |  6 
 tools/libxc/xc_sr_restore.c  | 45 +--
 tools/libxc/xc_sr_save.c | 52 +++-
 tools/libxc/xc_sr_save_x86_hvm.c |  5 ---
 tools/libxc/xc_sr_save_x86_pv.c  | 22 --
 7 files changed, 97 insertions(+), 56 deletions(-)

diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
index f3bdea8006..91ba918b32 100644
--- a/tools/libxc/xc_sr_common.h
+++ b/tools/libxc/xc_sr_common.h
@@ -298,6 +298,9 @@ struct xc_sr_context
 
 /* Sender has invoked verify mode on the stream. */
 bool verify;
+
+/* Domain context blob. */
+struct xc_sr_blob context;
 } restore;
 };
 
diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c
index 77ea044a74..dda8e1053c 100644
--- a/tools/libxc/xc_sr_common_x86.c
+++ b/tools/libxc/xc_sr_common_x86.c
@@ -1,25 +1,5 @@
 #include "xc_sr_common_x86.h"
 
-int write_x86_tsc_info(struct xc_sr_context *ctx)
-{
-xc_interface *xch = ctx->xch;
-struct xc_sr_rec_x86_tsc_info tsc = {};
-struct xc_sr_record rec = {
-.type = REC_TYPE_X86_TSC_INFO,
-.length = sizeof(tsc),
-.data = ,
-};
-
-if ( xc_domain_get_tsc_info(xch, ctx->domid, ,
-, , ) < 0 )
-{
-PERROR("Unable to obtain TSC information");
-return -1;
-}
-
-return write_record(ctx, );
-}
-
 int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec)
 {
 xc_interface *xch = ctx->xch;
diff --git a/tools/libxc/xc_sr_common_x86.h b/tools/libxc/xc_sr_common_x86.h
index e08d81e0e7..39645d0196 100644
--- a/tools/libxc/xc_sr_common_x86.h
+++ b/tools/libxc/xc_sr_common_x86.h
@@ -3,12 +3,6 @@
 
 #include "xc_sr_common.h"
 
-/*
- * Obtains a domains TSC information from Xen and writes a X86_TSC_INFO record
- * into the stream.
- */
-int write_x86_tsc_info(struct xc_sr_context *ctx);
-
 /*
  * Parses a X86_TSC_INFO record and applies the result to the domain.
  */
diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c
index bc811e6e3a..858d0c184e 100644
--- a/tools/libxc/xc_sr_restore.c
+++ b/tools/libxc/xc_sr_restore.c
@@ -35,9 +35,9 @@ static int read_headers(struct xc_sr_context *ctx)
 return -1;
 }
 
-if ( ihdr.version < 2 || ihdr.version > 3 )
+if ( ihdr.version < 2 || ihdr.version > 4 )
 {
-ERROR("Invalid Version: Expected 2 <= ver <= 3, Got %d",
+ERROR("Invalid Version: Expected 2 <= ver <= 4, Got %d",
   ihdr.version);
 return -1;
 }
@@ -529,6 +529,20 @@ static int send_checkpoint_dirty_pfn_list(struct 
xc_sr_context *ctx)
 return rc;
 }
 
+static int stream_complete(struct xc_sr_context *ctx)
+{
+xc_interface *xch = ctx->xch;
+int rc;
+
+rc = xc_domain_setcontext(xch, ctx->domid,
+  ctx->restore.context.ptr,
+  ctx->restore.context.size);
+if ( rc < 0 )
+PERROR("Unable to restore domain context");
+
+return rc;
+}
+
 static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);
 static int handle_checkpoint(struct xc_sr_context *ctx)
 {
@@ -597,6 +611,10 @@ static int handle_checkpoint(struct xc_sr_context *ctx)
 /* COLO */
 
 /* We need to resume guest */
+rc = stream_complete(ctx);
+if ( rc )
+goto err;
+
 rc = ctx->restore.ops.stream_complete(ctx);
 if ( rc )
 goto err;
@@ -682,6 +700,21 @@ int handle_static_data_end(struct xc_sr_context *ctx)
 return rc;
 }
 
+/*
+ * Process a DOMAIN_CONTEXT record from the stream.
+ */
+static int handle_domain_context(struct xc_sr_context *ctx,
+ struct xc_sr_record *rec)
+{
+xc_interface *xch = ctx->xch;
+int rc = update_blob(>restore.context, rec->data, rec->length);
+
+if ( rc )
+ERROR("Unable to allocate %u bytes for domain context", rec->length);
+
+return rc;
+}
+
 static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
 {
 xc_interface *xch = ctx->xch;
@@ -709,6 +742,10 @@ static int process_record(struct xc_sr_context *ctx, 
struct xc_sr_record *rec)
 rc = handle_static_data_end(ctx);
 break;
 
+case REC_TYPE_DOMAIN_CONTEXT:
+rc = handle_domain_context(ctx, rec);
+break;
+
 default:
 rc = ctx->restore.ops.process_record(ctx, rec);
 

[PATCH v8 0/8] domain context infrastructure

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

Paul Durrant (8):
  xen/common: introduce a new framework for save/restore of 'domain'
context
  xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontext
  tools/misc: add xen-domctx to present domain context
  docs/specs: add missing definitions to libxc-migration-stream
  docs / tools: specific migration v4 to include DOMAIN_CONTEXT
  common/domain: add a domain context record for shared_info...
  x86/time: add a domain context record for tsc_info...
  tools/libxc: add DOMAIN_CONTEXT records to the migration stream...

 .gitignore   |   1 +
 docs/specs/libxc-migration-stream.pandoc |  69 -
 tools/flask/policy/modules/xen.if|   4 +-
 tools/libxc/include/xenctrl.h|   5 +
 tools/libxc/xc_domain.c  |  56 
 tools/libxc/xc_sr_common.c   |   1 +
 tools/libxc/xc_sr_common.h   |   3 +
 tools/libxc/xc_sr_common_x86.c   |  20 --
 tools/libxc/xc_sr_common_x86.h   |   6 -
 tools/libxc/xc_sr_restore.c  |  45 +++-
 tools/libxc/xc_sr_save.c |  52 +++-
 tools/libxc/xc_sr_save_x86_hvm.c |   5 -
 tools/libxc/xc_sr_save_x86_pv.c  |  22 --
 tools/libxc/xc_sr_stream_format.h|   1 +
 tools/misc/Makefile  |   4 +
 tools/misc/xen-domctx.c  | 289 +
 tools/python/xen/migration/libxc.py  |   2 +
 xen/arch/x86/time.c  |  34 ++-
 xen/common/Makefile  |   1 +
 xen/common/domain.c  | 144 +++
 xen/common/domctl.c  | 173 +
 xen/common/save.c| 315 +++
 xen/include/asm-x86/time.h   |   5 +-
 xen/include/public/arch-arm/hvm/save.h   |   5 +
 xen/include/public/arch-x86/hvm/save.h   |   5 +
 xen/include/public/domctl.h  |  41 +++
 xen/include/public/save.h| 111 
 xen/include/xen/save.h   | 170 
 xen/xsm/flask/hooks.c|   6 +
 xen/xsm/flask/policy/access_vectors  |   4 +
 30 files changed, 1524 insertions(+), 75 deletions(-)
 create mode 100644 tools/misc/xen-domctx.c
 create mode 100644 xen/common/save.c
 create mode 100644 xen/include/public/save.h
 create mode 100644 xen/include/xen/save.h
---
Cc: Andrew Cooper 
Cc: Daniel De Graaf 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Jan Beulich 
Cc: Julien Grall 
Cc: "Marek Marczykowski-Górecki" 
Cc: "Roger Pau Monné" 
Cc: Stefano Stabellini 
Cc: Volodymyr Babchuk 
Cc: Wei Liu 
-- 
2.20.1




[PATCH v8 4/8] docs/specs: add missing definitions to libxc-migration-stream

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

The STATIC_DATA_END, X86_CPUID_POLICY and X86_MSR_POLICY record types have
sections explaining what they are but their values are not defined. Indeed
their values are defined as "Reserved for future mandatory records."

Also, the spec revision is adjusted to match the migration stream version
and an END record is added to the description of a 'typical save record for
and x86 HVM guest.'

Signed-off-by: Paul Durrant 
Fixes: 6f71b5b1506 ("docs/migration Specify migration v3 and STATIC_DATA_END")
Fixes: ddd273d8863 ("docs/migration: Specify X86_{CPUID,MSR}_POLICY records")
---
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Jan Beulich 
Cc: Julien Grall 
Cc: Stefano Stabellini 
Cc: Wei Liu 

v7:
 - New in v7
---
 docs/specs/libxc-migration-stream.pandoc | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/docs/specs/libxc-migration-stream.pandoc 
b/docs/specs/libxc-migration-stream.pandoc
index 6b0c49e97a..8aeab3b11b 100644
--- a/docs/specs/libxc-migration-stream.pandoc
+++ b/docs/specs/libxc-migration-stream.pandoc
@@ -3,7 +3,7 @@
   Andrew Cooper <>
   Wen Congyang <>
   Yang Hongyang <>
-% Revision 2
+% Revision 3
 
 Introduction
 
@@ -227,7 +227,13 @@ type 0x: END
 
  0x000F: CHECKPOINT_DIRTY_PFN_LIST (Secondary -> Primary)
 
- 0x0010 - 0x7FFF: Reserved for future _mandatory_
+ 0x0010: STATIC_DATA_END
+
+ 0x0011: X86_CPUID_POLICY
+
+ 0x0012: X86_MSR_POLICY
+
+ 0x0013 - 0x7FFF: Reserved for future _mandatory_
  records.
 
  0x8000 - 0x: Reserved for future _optional_
@@ -732,6 +738,7 @@ A typical save record for an x86 HVM guest image would look 
like:
 * X86_TSC_INFO
 * HVM_PARAMS
 * HVM_CONTEXT
+* END record
 
 HVM_PARAMS must precede HVM_CONTEXT, as certain parameters can affect
 the validity of architectural state in the context.
-- 
2.20.1




[PATCH v8 6/8] common/domain: add a domain context record for shared_info...

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

... and update xen-domctx to dump some information describing the record.

NOTE: Processing of the content during restore is currently limited to
  PV domains, and matches processing of the PV-only SHARED_INFO record
  done by libxc. All content is, however, saved such that restore
  processing can be modified in future without requiring a new record
  format.

Signed-off-by: Paul Durrant 
---
Cc: Ian Jackson 
Cc: Wei Liu 
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Jan Beulich 
Cc: Julien Grall 
Cc: Stefano Stabellini 

v8:
 - Incorporate zero-ing out of shared info fields that would be done in
   processing of SHARED_INFO from older stream versions

v7:
 - Only restore vcpu_info and arch sub-structures for PV domains, to match
   processing of SHARED_INFO in xc_sr_restore_x86_pv.c
 - Use additional option to domain_load_end() to ignore the record for
   HVM domains

v6:
 - Only save compat_shared_info buffer if has_32bit_shinfo is set
 - Validate flags field in load handler

v5:
 - Addressed comments from Julien

v4:
 - Addressed comments from Jan

v3:
 - Actually dump some of the content of shared_info

v2:
 - Drop the header change to define a 'Xen' page size and instead use a
   variable length struct now that the framework makes this is feasible
 - Guard use of 'has_32bit_shinfo' in common code with CONFIG_COMPAT
---
 tools/misc/xen-domctx.c   |  78 +
 xen/common/domain.c   | 144 ++
 xen/include/public/save.h |  13 +++-
 3 files changed, 234 insertions(+), 1 deletion(-)

diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c
index 243325dfce..6ead7ea89d 100644
--- a/tools/misc/xen-domctx.c
+++ b/tools/misc/xen-domctx.c
@@ -31,6 +31,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -61,6 +62,82 @@ static void dump_header(void)
 
 }
 
+static void print_binary(const char *prefix, const void *val, size_t size,
+ const char *suffix)
+{
+printf("%s", prefix);
+
+while ( size-- )
+{
+uint8_t octet = *(const uint8_t *)val++;
+unsigned int i;
+
+for ( i = 0; i < 8; i++ )
+{
+printf("%u", octet & 1);
+octet >>= 1;
+}
+}
+
+printf("%s", suffix);
+}
+
+static void dump_shared_info(void)
+{
+DOMAIN_SAVE_TYPE(SHARED_INFO) *s;
+bool has_32bit_shinfo;
+shared_info_any_t *info;
+unsigned int i, n;
+
+GET_PTR(s);
+has_32bit_shinfo = s->flags & DOMAIN_SAVE_32BIT_SHINFO;
+
+printf("SHARED_INFO: has_32bit_shinfo: %s buffer_size: %u\n",
+   has_32bit_shinfo ? "true" : "false", s->buffer_size);
+
+info = (shared_info_any_t *)s->buffer;
+
+#define GET_FIELD_PTR(_f)\
+(has_32bit_shinfo ?  \
+ (const void *)&(info->x32._f) : \
+ (const void *)&(info->x64._f))
+#define GET_FIELD_SIZE(_f) \
+(has_32bit_shinfo ? sizeof(info->x32._f) : sizeof(info->x64._f))
+#define GET_FIELD(_f) \
+(has_32bit_shinfo ? info->x32._f : info->x64._f)
+
+n = has_32bit_shinfo ?
+ARRAY_SIZE(info->x32.evtchn_pending) :
+ARRAY_SIZE(info->x64.evtchn_pending);
+
+for ( i = 0; i < n; i++ )
+{
+const char *prefix = !i ?
+" evtchn_pending: " :
+" ";
+
+print_binary(prefix, GET_FIELD_PTR(evtchn_pending[0]),
+ GET_FIELD_SIZE(evtchn_pending[0]), "\n");
+}
+
+for ( i = 0; i < n; i++ )
+{
+const char *prefix = !i ?
+"evtchn_mask: " :
+" ";
+
+print_binary(prefix, GET_FIELD_PTR(evtchn_mask[0]),
+ GET_FIELD_SIZE(evtchn_mask[0]), "\n");
+}
+
+printf(" wc: version: %u sec: %u nsec: %u\n",
+   GET_FIELD(wc_version), GET_FIELD(wc_sec), GET_FIELD(wc_nsec));
+
+#undef GET_FIELD
+#undef GET_FIELD_SIZE
+#undef GET_FIELD_PTR
+}
+
 static void dump_end(void)
 {
 DOMAIN_SAVE_TYPE(END) *e;
@@ -173,6 +250,7 @@ int main(int argc, char **argv)
 switch (desc->typecode)
 {
 case DOMAIN_SAVE_CODE(HEADER): dump_header(); break;
+case DOMAIN_SAVE_CODE(SHARED_INFO): dump_shared_info(); break;
 case DOMAIN_SAVE_CODE(END): dump_end(); break;
 default:
 printf("Unknown type %u: skipping\n", desc->typecode);
diff --git a/xen/common/domain.c b/xen/common/domain.c
index f0f9c62feb..2375e250af 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1659,6 +1660,149 @@ int continue_hypercall_on_cpu(
 return 0;
 }
 
+static int save_shared_info(const struct domain *d, struct domain_context *c,
+bool dry_run)
+{
+struct domain_shared_info_context ctxt = {
+#ifdef 

[PATCH v8 7/8] x86/time: add a domain context record for tsc_info...

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

... and update xen-domctx to dump some information describing the record.

NOTE: Whilst the record definition is x86 specific, it is visible directly
  in the common header as context record numbers should be unique across
  all architectures.

Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
---
Cc: Ian Jackson 
Cc: Wei Liu 
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Julien Grall 
Cc: Stefano Stabellini 
Cc: "Roger Pau Monné" 

v8:
 - Removed stray blank line

v7:
 - New in v7
---
 tools/misc/xen-domctx.c| 11 +++
 xen/arch/x86/time.c| 34 +-
 xen/include/asm-x86/time.h |  5 +++--
 xen/include/public/save.h  | 13 -
 4 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/tools/misc/xen-domctx.c b/tools/misc/xen-domctx.c
index 6ead7ea89d..e582a79678 100644
--- a/tools/misc/xen-domctx.c
+++ b/tools/misc/xen-domctx.c
@@ -59,7 +59,17 @@ static void dump_header(void)
 
 printf("HEADER: magic %#x, version %u\n",
h->magic, h->version);
+}
+
+static void dump_tsc_info(void)
+{
+DOMAIN_SAVE_TYPE(TSC_INFO) *t;
+
+GET_PTR(t);
 
+printf("TSC_INFO: mode: %u incarnation: %u\n"
+   "  khz %u elapsed_nsec: %"PRIu64"\n",
+   t->mode, t->incarnation, t->khz, t->elapsed_nsec);
 }
 
 static void print_binary(const char *prefix, const void *val, size_t size,
@@ -251,6 +261,7 @@ int main(int argc, char **argv)
 {
 case DOMAIN_SAVE_CODE(HEADER): dump_header(); break;
 case DOMAIN_SAVE_CODE(SHARED_INFO): dump_shared_info(); break;
+case DOMAIN_SAVE_CODE(TSC_INFO): dump_tsc_info(); break;
 case DOMAIN_SAVE_CODE(END): dump_end(); break;
 default:
 printf("Unknown type %u: skipping\n", desc->typecode);
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 505e54ebd7..05f65fbf12 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2334,7 +2335,7 @@ int host_tsc_is_safe(void)
  * called to collect tsc-related data only for save file or live
  * migrate; called after last rdtsc is done on this incarnation
  */
-void tsc_get_info(struct domain *d, uint32_t *tsc_mode,
+void tsc_get_info(const struct domain *d, uint32_t *tsc_mode,
   uint64_t *elapsed_nsec, uint32_t *gtsc_khz,
   uint32_t *incarnation)
 {
@@ -2453,6 +2454,37 @@ int tsc_set_info(struct domain *d,
 return 0;
 }
 
+static int save_tsc_info(const struct domain *d, struct domain_context *c,
+ bool dry_run)
+{
+struct domain_tsc_info_context ctxt;
+
+if ( !dry_run )
+tsc_get_info(d, , _nsec, ,
+ );
+
+return DOMAIN_SAVE_ENTRY(TSC_INFO, c, 0, , sizeof(ctxt));
+}
+
+static int load_tsc_info(struct domain *d, struct domain_context *c)
+{
+struct domain_tsc_info_context ctxt;
+unsigned int i;
+int rc;
+
+rc = DOMAIN_LOAD_ENTRY(TSC_INFO, c, , , sizeof(ctxt));
+if ( rc )
+return rc;
+
+if ( i ) /* expect only a single instance */
+return -ENXIO;
+
+return tsc_set_info(d, ctxt.mode, ctxt.elapsed_nsec, ctxt.khz,
+ctxt.incarnation);
+}
+
+DOMAIN_REGISTER_SAVE_LOAD(TSC_INFO, save_tsc_info, load_tsc_info);
+
 /* vtsc may incur measurable performance degradation, diagnose with this */
 static void dump_softtsc(unsigned char key)
 {
diff --git a/xen/include/asm-x86/time.h b/xen/include/asm-x86/time.h
index f347311cc4..7f2ce6226a 100644
--- a/xen/include/asm-x86/time.h
+++ b/xen/include/asm-x86/time.h
@@ -59,8 +59,9 @@ u64 gtsc_to_gtime(struct domain *d, u64 tsc);
 int tsc_set_info(struct domain *d, uint32_t tsc_mode, uint64_t elapsed_nsec,
  uint32_t gtsc_khz, uint32_t incarnation);
 
-void tsc_get_info(struct domain *d, uint32_t *tsc_mode, uint64_t *elapsed_nsec,
-  uint32_t *gtsc_khz, uint32_t *incarnation);
+void tsc_get_info(const struct domain *d, uint32_t *tsc_mode,
+  uint64_t *elapsed_nsec, uint32_t *gtsc_khz,
+  uint32_t *incarnation);

 
 void force_update_vcpu_system_time(struct vcpu *v);
diff --git a/xen/include/public/save.h b/xen/include/public/save.h
index 0e855a4b97..aeb17298eb 100644
--- a/xen/include/public/save.h
+++ b/xen/include/public/save.h
@@ -93,7 +93,18 @@ struct domain_shared_info_context {
 
 DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context);
 
-#define DOMAIN_SAVE_CODE_MAX 2
+#if defined(__i386__) || defined(__x86_64__)
+struct domain_tsc_info_context {
+uint32_t mode;
+uint32_t incarnation;
+uint64_t elapsed_nsec;
+uint32_t khz;
+};
+
+DECLARE_DOMAIN_SAVE_TYPE(TSC_INFO, 3, struct domain_tsc_info_context);
+#endif
+
+#define DOMAIN_SAVE_CODE_MAX 3
 
 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
 
-- 
2.20.1




[PATCH v8 5/8] docs / tools: specific migration v4 to include DOMAIN_CONTEXT

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

A new 'domain context' framework was recently introduced to facilitate
transfer of state for both PV and HVM guests. Hence this patch mandates the
presence of a new DOMAIN_CONTEXT record in version 4 of the libxc migration
stream.
This record will incorprate the content of the domain's 'shared_info' page
and the TSC informaiton so the SHARED_INFO and TSC_INFO records are deprecated.
It is intended that, in future, this record will contain state currently
present in the HVM_CONTEXT record. However, for compatibility with earlier
migration streams, the version 4 stream format continues to specify an
HVM_CONTEXT record and XEN_DOMCTL_sethvmcontext will continue to accept all
content of that record that may be present in a version 3 stream.

Signed-off-by: Paul Durrant 
---
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Jan Beulich 
Cc: Julien Grall 
Cc: Stefano Stabellini 
Cc: Wei Liu 
Cc: "Marek Marczykowski-Górecki" 

v7:
 - New in v7
---
 docs/specs/libxc-migration-stream.pandoc | 62 ++--
 tools/libxc/xc_sr_common.c   |  1 +
 tools/libxc/xc_sr_stream_format.h|  1 +
 tools/python/xen/migration/libxc.py  |  2 +
 4 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/docs/specs/libxc-migration-stream.pandoc 
b/docs/specs/libxc-migration-stream.pandoc
index 8aeab3b11b..989f2a0cb6 100644
--- a/docs/specs/libxc-migration-stream.pandoc
+++ b/docs/specs/libxc-migration-stream.pandoc
@@ -3,7 +3,7 @@
   Andrew Cooper <>
   Wen Congyang <>
   Yang Hongyang <>
-% Revision 3
+% Revision 4
 
 Introduction
 
@@ -127,7 +127,7 @@ marker  0x.
 
 id  0x58454E46 ("XENF" in ASCII).
 
-version 0x0003.  The version of this specification.
+version 0x0004.  The version of this specification.
 
 options bit 0: Endianness.  0 = little-endian, 1 = big-endian.
 
@@ -209,9 +209,9 @@ type 0x: END
 
  0x0006: X86_PV_VCPU_XSAVE
 
- 0x0007: SHARED_INFO
+ 0x0007: SHARED_INFO (deprecated)
 
- 0x0008: X86_TSC_INFO
+ 0x0008: X86_TSC_INFO (deprecated)
 
  0x0009: HVM_CONTEXT
 
@@ -233,7 +233,9 @@ type 0x: END
 
  0x0012: X86_MSR_POLICY
 
- 0x0013 - 0x7FFF: Reserved for future _mandatory_
+ 0x0013: DOMAIN_CONTEXT
+
+ 0x0014 - 0x7FFF: Reserved for future _mandatory_
  records.
 
  0x8000 - 0x: Reserved for future _optional_
@@ -442,10 +444,11 @@ X86_PV_VCPU_MSRS 
XEN_DOMCTL_{get,set}\_vcpu_msrs
 
 \clearpage
 
-SHARED_INFO

+SHARED_INFO (deprecated)
+
 
-The content of the Shared Info page.
+The content of the Shared Info page. This is incorporated into the
+DOMAIN_CONTEXT record as of specification version 4.
 
  0 1 2 3 4 5 6 7 octet
 +-+
@@ -462,11 +465,12 @@ shared_info  Contents of the shared info page.  This 
record
 
 \clearpage
 
-X86_TSC_INFO
-
+X86_TSC_INFO (deprecated)
+-
 
 Domain TSC information, as accessed by the
-XEN_DOMCTL_{get,set}tscinfo hypercall sub-ops.
+XEN_DOMCTL_{get,set}tscinfo hypercall sub-ops. This is incorporated into the
+DOMAIN_CONTEXT record as of specification version 4.
 
  0 1 2 3 4 5 6 7 octet
 +++
@@ -680,6 +684,25 @@ MSR_policy   Array of xen_msr_entry_t[]'s
 
 \clearpage
 
+DOMAIN_CONTEXT
+--
+
+Domain context, as accessed by the
+XEN_DOMCTL_{get,set}domaincontext hypercall sub-ops.
+
+ 0 1 2 3 4 5 6 7 octet
++-+
+| dom_ctx |
+...
++-+
+
+
+FieldDescription
+---  ---
+dom_ctx  The Domain Context blob from Xen.
+
+
+\clearpage
 
 Layout
 ==
@@ -706,8 +729,7 @@ A typical save record for an x86 PV guest image would look 
like:
 * STATIC_DATA_END
 * X86_PV_P2M_FRAMES record
 * Many PAGE_DATA records
-* X86_TSC_INFO
-* SHARED_INFO record
+* DOMAIN_CONTEXT
 * VCPU context records for each online VCPU
 * X86_PV_VCPU_BASIC record
 * X86_PV_VCPU_EXTENDED record
@@ -735,7 +757,7 @@ A typical save record for an x86 HVM guest image would look 
like:
 * X86_{CPUID,MSR}_POLICY
 * STATIC_DATA_END
 * Many PAGE_DATA records
-* X86_TSC_INFO
+* DOMAIN_CONTEXT
 * HVM_PARAMS
 * HVM_CONTEXT
 * END record
@@ -746,6 +768,18 @@ the validity of architectural state in the 

Re: [PATCH v2 06/21] drm/i915: Introduce GEM object functions

2020-09-15 Thread Tvrtko Ursulin



On 15/09/2020 15:59, Thomas Zimmermann wrote:

GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in i915.

v2:
* move object-function instance to i915_gem_object.c (Jani)

Signed-off-by: Thomas Zimmermann 
---
  drivers/gpu/drm/i915/gem/i915_gem_object.c| 21 ---
  drivers/gpu/drm/i915/gem/i915_gem_object.h|  3 ---
  drivers/gpu/drm/i915/i915_drv.c   |  4 
  .../gpu/drm/i915/selftests/mock_gem_device.c  |  3 ---
  4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c 
b/drivers/gpu/drm/i915/gem/i915_gem_object.c
index c8421fd9d2dc..3389ac972d16 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
@@ -39,9 +39,18 @@ static struct i915_global_object {
struct kmem_cache *slab_objects;
  } global;
  
+static const struct drm_gem_object_funcs i915_gem_object_funcs;

+
  struct drm_i915_gem_object *i915_gem_object_alloc(void)
  {
-   return kmem_cache_zalloc(global.slab_objects, GFP_KERNEL);
+   struct drm_i915_gem_object *obj;
+
+   obj = kmem_cache_zalloc(global.slab_objects, GFP_KERNEL);
+   if (!obj)
+   return NULL;
+   obj->base.funcs = _gem_object_funcs;
+
+   return obj;
  }
  
  void i915_gem_object_free(struct drm_i915_gem_object *obj)

@@ -101,7 +110,7 @@ void i915_gem_object_set_cache_coherency(struct 
drm_i915_gem_object *obj,
!(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE);
  }
  
-void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file)

+static void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file 
*file)
  {
struct drm_i915_gem_object *obj = to_intel_bo(gem);
struct drm_i915_file_private *fpriv = file->driver_priv;
@@ -264,7 +273,7 @@ static void __i915_gem_free_work(struct work_struct *work)
i915_gem_flush_free_objects(i915);
  }
  
-void i915_gem_free_object(struct drm_gem_object *gem_obj)

+static void i915_gem_free_object(struct drm_gem_object *gem_obj)
  {
struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
struct drm_i915_private *i915 = to_i915(obj->base.dev);
@@ -403,6 +412,12 @@ int __init i915_global_objects_init(void)
return 0;
  }
  
+static const struct drm_gem_object_funcs i915_gem_object_funcs = {

+   .free = i915_gem_free_object,
+   .close = i915_gem_close_object,
+   .export = i915_gem_prime_export,
+};
+
  #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  #include "selftests/huge_gem_object.c"
  #include "selftests/huge_pages.c"
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h 
b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index d46db8d8f38e..eaf3d4147be0 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -38,9 +38,6 @@ void __i915_gem_object_release_shmem(struct 
drm_i915_gem_object *obj,
  
  int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align);
  
-void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file);

-void i915_gem_free_object(struct drm_gem_object *obj);
-
  void i915_gem_flush_free_objects(struct drm_i915_private *i915);
  
  struct sg_table *

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 94e00e450683..011a3fb41ece 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1750,12 +1750,8 @@ static struct drm_driver driver = {
.lastclose = i915_driver_lastclose,
.postclose = i915_driver_postclose,
  
-	.gem_close_object = i915_gem_close_object,

-   .gem_free_object_unlocked = i915_gem_free_object,
-
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = i915_gem_prime_export,
.gem_prime_import = i915_gem_prime_import,
  
  	.dumb_create = i915_gem_dumb_create,

diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c 
b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
index f127e633f7ca..9244b5d6fb01 100644
--- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
+++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
@@ -87,9 +87,6 @@ static struct drm_driver mock_driver = {
.name = "mock",
.driver_features = DRIVER_GEM,
.release = mock_device_release,
-
-   .gem_close_object = i915_gem_close_object,
-   .gem_free_object_unlocked = i915_gem_free_object,
  };
  
  static void release_dev(struct device *dev)




Looks obviously fine.

Reviewed-by: Tvrtko Ursulin 

Regards,

Tvrtko



Re: [PATCH 1/9] build: use if_changed more consistently (and correctly) for prelink*.o

2020-09-15 Thread Roger Pau Monné
On Mon, Sep 14, 2020 at 12:15:39PM +0200, Jan Beulich wrote:
> Switch to $(call if_changed,ld) where possible; presumably not doing so
> in e321576f4047 ("xen/build: start using if_changed") right away was an
> oversight, as it did for Arm in (just) one case. It failed to add
> prelink.o to $(targets), though, causing - judging from the observed
> behavior on x86 - undue rebuilds of the final binary (because of
> prelink.o getting rebuild for $(cmd_prelink.o) being empty, in turn
> because of .prelink.o.cmd not getting read) during "make install-xen".

I'm not sure I follow why prelink.o needs to be added to targets, does
this offer some kind of protection against rebuilds when doing make
install?

The switch to if_changed LGTM.

Thanks, Roger.



Re: [PATCH v2 20/21] drm/xlnx: Initialize DRM driver instance with CMA helper macro

2020-09-15 Thread Laurent Pinchart
Hi Thomas,

Thank you for the patch.

On Tue, Sep 15, 2020 at 04:59:57PM +0200, Thomas Zimmermann wrote:
> The xlnx driver uses CMA helpers with default callback functions.
> Initialize the driver structure with the rsp CMA helper macro. The
> driver is being converted to use GEM object functions as part of
> this change.
> 
> Two callbacks, .dumb_destroy and .gem_prime_import, were initialized
> to their default implementations, so they are just kept empty now.
> 
> v2:
>   * initialize with DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE (Laurent)
> 
> Signed-off-by: Thomas Zimmermann 

Reviewed-by: Laurent Pinchart 

> ---
>  drivers/gpu/drm/xlnx/zynqmp_dpsub.c | 14 +-
>  1 file changed, 1 insertion(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c 
> b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> index 8e69303aad3f..f3ffc3703a0e 100644
> --- a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> +++ b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> @@ -80,19 +80,7 @@ static struct drm_driver zynqmp_dpsub_drm_driver = {
>   .driver_features= DRIVER_MODESET | DRIVER_GEM |
> DRIVER_ATOMIC,
>  
> - .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
> - .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
> - .gem_prime_export   = drm_gem_prime_export,
> - .gem_prime_import   = drm_gem_prime_import,
> - .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
> - .gem_prime_import_sg_table  = drm_gem_cma_prime_import_sg_table,
> - .gem_prime_vmap = drm_gem_cma_prime_vmap,
> - .gem_prime_vunmap   = drm_gem_cma_prime_vunmap,
> - .gem_prime_mmap = drm_gem_cma_prime_mmap,
> - .gem_free_object_unlocked   = drm_gem_cma_free_object,
> - .gem_vm_ops = _gem_cma_vm_ops,
> - .dumb_create= zynqmp_dpsub_dumb_create,
> - .dumb_destroy   = drm_gem_dumb_destroy,
> + DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE(zynqmp_dpsub_dumb_create),
>  
>   .fops   = _dpsub_drm_fops,
>  

-- 
Regards,

Laurent Pinchart



[xen-unstable-smoke test] 154361: tolerable all pass - PUSHED

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

Failures :-/ but no regressions.

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-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

version targeted for testing:
 xen  51526576219f122ec7ccfd55dea95afbca70d330
baseline version:
 xen  39ab598c50a2b539f376adc363d684c2df6c8dd7

Last test of basis   154357  2020-09-15 09:01:19 Z0 days
Testing same since   154361  2020-09-15 13:01:26 Z0 days1 attempts


People who touched revisions under test:
  Andrew Cooper 
  Roger Pau Monné 

jobs:
 build-arm64-xsm  pass
 build-amd64  pass
 build-armhf  pass
 build-amd64-libvirt  pass
 test-armhf-armhf-xl  pass
 test-arm64-arm64-xl-xsm  pass
 test-amd64-amd64-xl-qemuu-debianhvm-amd64pass
 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 :

To xenbits.xen.org:/home/xen/git/xen.git
   39ab598c50..5152657621  51526576219f122ec7ccfd55dea95afbca70d330 -> smoke



Re: [PATCH v2 00/21] Convert all remaining drivers to GEM object functions

2020-09-15 Thread Christian König

Added my rb to the amdgpu and radeon patches.

Should we pick those up through the amd branches or do you want to push 
everything to drm-misc-next?


I think the later since this should result in much merge clash.

Christian.

Am 15.09.20 um 16:59 schrieb Thomas Zimmermann:

The GEM and PRIME related callbacks in struct drm_driver are deprecated in
favor of GEM object functions in struct drm_gem_object_funcs. This patchset
converts the remaining drivers to object functions and removes most of the
obsolete interfaces.

Patches #1 to #16 and #18 to #19 convert DRM drivers to GEM object functions,
one by one. Each patch moves existing callbacks from struct drm_driver to an
instance of struct drm_gem_object_funcs, and sets these funcs when the GEM
object is initialized. The expection is .gem_prime_mmap. There are different
ways of how drivers implement the callback, and moving it to GEM object
functions requires a closer review for each.

Patch #17 fixes virtgpu to use GEM object functions where possible. The
driver recently introduced a function for one of the deprecated callbacks.

Patch #20 converts xlnx to CMA helper macros. There's no apparent reason
why the driver does the GEM setup on it's own. Using CMA helper macros
adds GEM object functions implicitly.

With most of the GEM and PRIME moved to GEM object functions, related code
in struct drm_driver and in the DRM core/helpers is being removed by patch
#21.

Further testing is welcome. I tested the drivers for which I have HW
available. These are gma500, i915, nouveau, radeon and vc4. The console,
Weston and Xorg apparently work with the patches applied.

v2:
* moved code in amdgpu and radeon
* made several functions static in various drivers
* updated TODO-list item
* fix virtgpu

Thomas Zimmermann (21):
   drm/amdgpu: Introduce GEM object functions
   drm/armada: Introduce GEM object functions
   drm/etnaviv: Introduce GEM object functions
   drm/exynos: Introduce GEM object functions
   drm/gma500: Introduce GEM object functions
   drm/i915: Introduce GEM object functions
   drm/mediatek: Introduce GEM object functions
   drm/msm: Introduce GEM object funcs
   drm/nouveau: Introduce GEM object functions
   drm/omapdrm: Introduce GEM object functions
   drm/pl111: Introduce GEM object functions
   drm/radeon: Introduce GEM object functions
   drm/rockchip: Convert to drm_gem_object_funcs
   drm/tegra: Introduce GEM object functions
   drm/vc4: Introduce GEM object functions
   drm/vgem: Introduce GEM object functions
   drm/virtgpu: Set PRIME export function in struct drm_gem_object_funcs
   drm/vkms: Introduce GEM object functions
   drm/xen: Introduce GEM object functions
   drm/xlnx: Initialize DRM driver instance with CMA helper macro
   drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver

  Documentation/gpu/todo.rst|  7 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   |  6 --
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   | 23 +++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h   |  5 --
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c|  1 +
  drivers/gpu/drm/armada/armada_drv.c   |  3 -
  drivers/gpu/drm/armada/armada_gem.c   | 12 ++-
  drivers/gpu/drm/armada/armada_gem.h   |  2 -
  drivers/gpu/drm/drm_gem.c | 35 ++--
  drivers/gpu/drm/drm_gem_cma_helper.c  |  6 +-
  drivers/gpu/drm/drm_prime.c   | 17 ++--
  drivers/gpu/drm/etnaviv/etnaviv_drv.c | 13 ---
  drivers/gpu/drm/etnaviv/etnaviv_drv.h |  1 -
  drivers/gpu/drm/etnaviv/etnaviv_gem.c | 19 -
  drivers/gpu/drm/exynos/exynos_drm_drv.c   | 10 ---
  drivers/gpu/drm/exynos/exynos_drm_gem.c   | 15 
  drivers/gpu/drm/gma500/framebuffer.c  |  2 +
  drivers/gpu/drm/gma500/gem.c  | 18 +++-
  drivers/gpu/drm/gma500/gem.h  |  3 +
  drivers/gpu/drm/gma500/psb_drv.c  |  9 --
  drivers/gpu/drm/gma500/psb_drv.h  |  2 -
  drivers/gpu/drm/i915/gem/i915_gem_object.c| 21 -
  drivers/gpu/drm/i915/gem/i915_gem_object.h|  3 -
  drivers/gpu/drm/i915/i915_drv.c   |  4 -
  .../gpu/drm/i915/selftests/mock_gem_device.c  |  3 -
  drivers/gpu/drm/mediatek/mtk_drm_drv.c|  5 --
  drivers/gpu/drm/mediatek/mtk_drm_gem.c| 11 +++
  drivers/gpu/drm/msm/msm_drv.c | 13 ---
  drivers/gpu/drm/msm/msm_drv.h |  1 -
  drivers/gpu/drm/msm/msm_gem.c | 19 -
  drivers/gpu/drm/nouveau/nouveau_drm.c |  9 --
  drivers/gpu/drm/nouveau/nouveau_gem.c | 13 +++
  drivers/gpu/drm/nouveau/nouveau_gem.h |  2 +
  drivers/gpu/drm/nouveau/nouveau_prime.c   |  2 +
  drivers/gpu/drm/omapdrm/omap_drv.c|  9 --
  drivers/gpu/drm/omapdrm/omap_gem.c| 18 +++-
  drivers/gpu/drm/omapdrm/omap_gem.h|  2 -
  drivers/gpu/drm/pl111/pl111_drv.c |  5 +-
  

Re: [PATCH 1/9] build: use if_changed more consistently (and correctly) for prelink*.o

2020-09-15 Thread Jan Beulich
On 15.09.2020 15:46, Roger Pau Monné wrote:
> On Tue, Sep 15, 2020 at 02:26:34PM +0200, Jan Beulich wrote:
>> On 15.09.2020 13:56, Roger Pau Monné wrote:
>>> On Mon, Sep 14, 2020 at 12:15:39PM +0200, Jan Beulich wrote:
 Switch to $(call if_changed,ld) where possible; presumably not doing so
 in e321576f4047 ("xen/build: start using if_changed") right away was an
 oversight, as it did for Arm in (just) one case. It failed to add
 prelink.o to $(targets), though, causing - judging from the observed
 behavior on x86 - undue rebuilds of the final binary (because of
 prelink.o getting rebuild for $(cmd_prelink.o) being empty, in turn
 because of .prelink.o.cmd not getting read) during "make install-xen".
>>>
>>> I'm not sure I follow why prelink.o needs to be added to targets, does
>>> this offer some kind of protection against rebuilds when doing make
>>> install?
>>
>> In a way, but (as I view it) not really. It is the use of ...
>>
>>> The switch to if_changed LGTM.
>>
>> ... if_changed which requires this. .*.cmd files will only be loaded
>> for anything explicitly or implicitly listed as a target. While .o
>> coming from $(obj-y) get added there automatically, prelink.o is not
>> something that could be recognized as needing adding, hence the
>> "manual" insertion.
> 
> This seems very prone to mistakes, as you have to remember that
> whatever object that uses if_changed should also be part of the
> targets set, or else it will get rebuild unconditionally.

The use of $(if_changed ...) has further similar pitfalls: One may
not forget to add FORCE to the dependencies, and there may not be
blanks after the comma (where one would usually put one). But I think
the benefits of this construct are so significant that this extra
care that's needed is well justified. Plus this is actually mentioned
(at least in passing) in docs/misc/xen-makefiles/makefile.rst.

> I think adding some of the above reasoning to the commit message would
> be helpful IMO.

Well, I've merely re-explained what I think the commit message
already says.

>> Without .prelink.o.cmd loaded, $(if_changed ) will always arrange
>> for it to get re-built, because it then will consider the command
>> used to build the file to have changed (as the stored one appears to
>> be empty).
> 
> Acked-by: Roger Pau Monné 

Thanks.

Jan



Re: [PATCH v2 1/2] libxl: provide a mechanism to define a device 'safe remove' function...

2020-09-15 Thread Wei Liu
On Tue, Sep 15, 2020 at 04:48:14PM +0200, Roger Pau Monné wrote:
> On Tue, Sep 15, 2020 at 02:40:09PM +, Durrant, Paul wrote:
> > > -Original Message-
> > > From: Roger Pau Monné 
> > > Sent: 15 September 2020 15:32
> > > To: Paul Durrant 
> > > Cc: xen-devel@lists.xenproject.org; Durrant, Paul 
> > > ; Ian Jackson
> > > ; Wei Liu ; Anthony PERARD 
> > > 
> > > Subject: RE: [EXTERNAL] [PATCH v2 1/2] libxl: provide a mechanism to 
> > > define a device 'safe remove'
> > > function...
> > > 
> > > CAUTION: This email originated from outside of the organization. Do not 
> > > click links or open
> > > attachments unless you can confirm the sender and know the content is 
> > > safe.
> > > 
> > > 
> > > 
> > > On Tue, Sep 15, 2020 at 03:10:06PM +0100, Paul Durrant wrote:
> > > > From: Paul Durrant 
> > > >
> > > > ... and use it to define libxl_device_disk_safe_remove().
> > > >
> > > > This patch builds on the existent macro magic by using a new value of 
> > > > the
> > > > 'force' field in in libxl__ao_device.
> > > > It is currently defined as an int but is used in a boolean manner where
> > > > 1 means the operation is forced and 0 means it is not (but is actually 
> > > > forced
> > > > after a 10s time-out). In adding a third value, this patch re-defines 
> > > > 'force'
> > > > as a struct type (libxl__force) with a single 'flag' field taking an
> > > > enumerated value:
> > > >
> > > > LIBXL__FORCE_AUTO - corresponding to the old 0 value
> > > > LIBXL__FORCE_ON   - corresponding to the old 1 value
> > > > LIBXL__FORCE_OFF  - the new value
> > > >
> > > > The LIBXL_DEFINE_DEVICE_REMOVE() macro is then modified to define the
> > > > libxl_device__remove() and libxl_device__destroy() 
> > > > functions,
> > > > setting LIBXL__FORCE_AUTO and LIBXL__FORCE_ON (respectively) in the
> > > > libxl__ao_device passed to libxl__initiate_device_generic_remove() and a
> > > > new macro, LIBXL_DEFINE_DEVICE_SAFE_REMOVE(), is defined that sets
> > > > LIBXL__FORCE_OFF instead. This macro is used to define the new
> > > > libxl_device_disk_safe_remove() function.
> > > >
> > > > Signed-off-by: Paul Durrant 
> > > 
> > > Reviewed-by: Roger Pau Monné 
> > > 
> > 
> > Thanks.
> > 
> > > Just one nit.
> > > 
> > > > diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> > > > index e16ae9630b..1fcf85c3e2 100644
> > > > --- a/tools/libxl/libxl_internal.h
> > > > +++ b/tools/libxl/libxl_internal.h
> > > > @@ -2730,12 +2730,20 @@ _hidden void libxl__prepare_ao_device(libxl__ao 
> > > > *ao, libxl__ao_device
> > > *aodev);
> > > >  /* generic callback for devices that only need to set ao_complete */
> > > >  _hidden void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device 
> > > > *aodev);
> > > >
> > > > +typedef struct {
> > > > +enum {
> > > > +LIBXL__FORCE_AUTO, /* Re-execute with FORCE_ON if op times out 
> > > > */
> > > > +LIBXL__FORCE_ON,
> > > > +LIBXL__FORCE_OFF,
> > > > +} flag;
> > > > +} libxl__force;
> > > 
> > > Couldn't you just use the typedef against the union directly instead
> > > of wrapping it around a struct?
> > 
> > You mean s/union/enum?
> 
> Yes :) sorry for that.
> 
> > I could have done that, but it helped find all the places where 
> > aodev->force is used and I liked the abstraction. I don't mind changing if 
> > there are strong opinions against it.
> 
> While it's indeed helpful to find the users to fixup, it just makes
> the lines longer in the final patch IMO. Let's see what opinions
> others have however.

I don't feel strongly about this either way.

Wei.

> 
> Thanks, Roger.



Re: [PATCH v2 12/21] drm/radeon: Introduce GEM object functions

2020-09-15 Thread Christian König

Am 15.09.20 um 16:59 schrieb Thomas Zimmermann:

GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in radeon.

v2:
* move object-function instance to radeon_gem.c (Christian)
* set callbacks in radeon_gem_object_create() (Christian)

Signed-off-by: Thomas Zimmermann 


Reviewed-by: Christian König 


---
  drivers/gpu/drm/radeon/radeon_drv.c | 23 +
  drivers/gpu/drm/radeon/radeon_gem.c | 31 +
  2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_drv.c 
b/drivers/gpu/drm/radeon/radeon_drv.c
index 4cd30613fa1d..65061c949aee 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -124,13 +124,6 @@ void radeon_driver_irq_preinstall_kms(struct drm_device 
*dev);
  int radeon_driver_irq_postinstall_kms(struct drm_device *dev);
  void radeon_driver_irq_uninstall_kms(struct drm_device *dev);
  irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg);
-void radeon_gem_object_free(struct drm_gem_object *obj);
-int radeon_gem_object_open(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
-void radeon_gem_object_close(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
-struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
-   int flags);
  extern int radeon_get_crtc_scanoutpos(struct drm_device *dev, unsigned int 
crtc,
  unsigned int flags, int *vpos, int *hpos,
  ktime_t *stime, ktime_t *etime,
@@ -145,14 +138,9 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
  int radeon_mode_dumb_create(struct drm_file *file_priv,
struct drm_device *dev,
struct drm_mode_create_dumb *args);
-struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
  struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device 
*dev,
struct 
dma_buf_attachment *,
struct sg_table *sg);
-int radeon_gem_prime_pin(struct drm_gem_object *obj);
-void radeon_gem_prime_unpin(struct drm_gem_object *obj);
-void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
-void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  
  /* atpx handler */

  #if defined(CONFIG_VGA_SWITCHEROO)
@@ -550,7 +538,7 @@ long radeon_drm_ioctl(struct file *filp,
}
  
  	ret = drm_ioctl(filp, cmd, arg);

-   
+
pm_runtime_mark_last_busy(dev->dev);
pm_runtime_put_autosuspend(dev->dev);
return ret;
@@ -609,22 +597,13 @@ static struct drm_driver kms_driver = {
.irq_uninstall = radeon_driver_irq_uninstall_kms,
.irq_handler = radeon_driver_irq_handler_kms,
.ioctls = radeon_ioctls_kms,
-   .gem_free_object_unlocked = radeon_gem_object_free,
-   .gem_open_object = radeon_gem_object_open,
-   .gem_close_object = radeon_gem_object_close,
.dumb_create = radeon_mode_dumb_create,
.dumb_map_offset = radeon_mode_dumb_mmap,
.fops = _driver_kms_fops,
  
  	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,

.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = radeon_gem_prime_export,
-   .gem_prime_pin = radeon_gem_prime_pin,
-   .gem_prime_unpin = radeon_gem_prime_unpin,
-   .gem_prime_get_sg_table = radeon_gem_prime_get_sg_table,
.gem_prime_import_sg_table = radeon_gem_prime_import_sg_table,
-   .gem_prime_vmap = radeon_gem_prime_vmap,
-   .gem_prime_vunmap = radeon_gem_prime_vunmap,
  
  	.name = DRIVER_NAME,

.desc = DRIVER_DESC,
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c 
b/drivers/gpu/drm/radeon/radeon_gem.c
index e5c4271e64ed..0ccd7213e41f 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -35,7 +35,17 @@
  
  #include "radeon.h"
  
-void radeon_gem_object_free(struct drm_gem_object *gobj)

+struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
+   int flags);
+struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
+int radeon_gem_prime_pin(struct drm_gem_object *obj);
+void radeon_gem_prime_unpin(struct drm_gem_object *obj);
+void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
+void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
+
+static const struct drm_gem_object_funcs radeon_gem_object_funcs;
+
+static void radeon_gem_object_free(struct drm_gem_object *gobj)
  {
struct radeon_bo *robj = gem_to_radeon_bo(gobj);
  
@@ -85,6 +95,7 @@ int radeon_gem_object_create(struct radeon_device *rdev, unsigned long size,

 

Re: [PATCH v2 02/21] drm/armada: Introduce GEM object functions

2020-09-15 Thread Russell King - ARM Linux admin
On Tue, Sep 15, 2020 at 04:59:39PM +0200, Thomas Zimmermann wrote:
> GEM object functions deprecate several similar callback interfaces in
> struct drm_driver. This patch replaces the per-driver callbacks with
> per-instance callbacks in armada.
> 
> Signed-off-by: Thomas Zimmermann 

Acked-by: Russell King 

Thanks.

> ---
>  drivers/gpu/drm/armada/armada_drv.c |  3 ---
>  drivers/gpu/drm/armada/armada_gem.c | 12 +++-
>  drivers/gpu/drm/armada/armada_gem.h |  2 --
>  3 files changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/armada/armada_drv.c 
> b/drivers/gpu/drm/armada/armada_drv.c
> index 980d3f1f8f16..22247cfce80b 100644
> --- a/drivers/gpu/drm/armada/armada_drv.c
> +++ b/drivers/gpu/drm/armada/armada_drv.c
> @@ -37,13 +37,10 @@ DEFINE_DRM_GEM_FOPS(armada_drm_fops);
>  
>  static struct drm_driver armada_drm_driver = {
>   .lastclose  = drm_fb_helper_lastclose,
> - .gem_free_object_unlocked = armada_gem_free_object,
>   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
>   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
> - .gem_prime_export   = armada_gem_prime_export,
>   .gem_prime_import   = armada_gem_prime_import,
>   .dumb_create= armada_gem_dumb_create,
> - .gem_vm_ops = _gem_vm_ops,
>   .major  = 1,
>   .minor  = 0,
>   .name   = "armada-drm",
> diff --git a/drivers/gpu/drm/armada/armada_gem.c 
> b/drivers/gpu/drm/armada/armada_gem.c
> index ecf8a55e93d9..c343fbefe47c 100644
> --- a/drivers/gpu/drm/armada/armada_gem.c
> +++ b/drivers/gpu/drm/armada/armada_gem.c
> @@ -25,7 +25,7 @@ static vm_fault_t armada_gem_vm_fault(struct vm_fault *vmf)
>   return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
>  }
>  
> -const struct vm_operations_struct armada_gem_vm_ops = {
> +static const struct vm_operations_struct armada_gem_vm_ops = {
>   .fault  = armada_gem_vm_fault,
>   .open   = drm_gem_vm_open,
>   .close  = drm_gem_vm_close,
> @@ -184,6 +184,12 @@ armada_gem_map_object(struct drm_device *dev, struct 
> armada_gem_object *dobj)
>   return dobj->addr;
>  }
>  
> +static const struct drm_gem_object_funcs armada_gem_object_funcs = {
> + .free = armada_gem_free_object,
> + .export = armada_gem_prime_export,
> + .vm_ops = _gem_vm_ops,
> +};
> +
>  struct armada_gem_object *
>  armada_gem_alloc_private_object(struct drm_device *dev, size_t size)
>  {
> @@ -195,6 +201,8 @@ armada_gem_alloc_private_object(struct drm_device *dev, 
> size_t size)
>   if (!obj)
>   return NULL;
>  
> + obj->obj.funcs = _gem_object_funcs;
> +
>   drm_gem_private_object_init(dev, >obj, size);
>  
>   DRM_DEBUG_DRIVER("alloc private obj %p size %zu\n", obj, size);
> @@ -214,6 +222,8 @@ static struct armada_gem_object 
> *armada_gem_alloc_object(struct drm_device *dev,
>   if (!obj)
>   return NULL;
>  
> + obj->obj.funcs = _gem_object_funcs;
> +
>   if (drm_gem_object_init(dev, >obj, size)) {
>   kfree(obj);
>   return NULL;
> diff --git a/drivers/gpu/drm/armada/armada_gem.h 
> b/drivers/gpu/drm/armada/armada_gem.h
> index de04cc2c8f0e..ffcc7e8dd351 100644
> --- a/drivers/gpu/drm/armada/armada_gem.h
> +++ b/drivers/gpu/drm/armada/armada_gem.h
> @@ -21,8 +21,6 @@ struct armada_gem_object {
>   void*update_data;
>  };
>  
> -extern const struct vm_operations_struct armada_gem_vm_ops;
> -
>  #define drm_to_armada_gem(o) container_of(o, struct armada_gem_object, obj)
>  
>  void armada_gem_free_object(struct drm_gem_object *);
> -- 
> 2.28.0
> 
> 

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!



Re: [PATCH v2 01/21] drm/amdgpu: Introduce GEM object functions

2020-09-15 Thread Christian König

Am 15.09.20 um 16:59 schrieb Thomas Zimmermann:

GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in amdgpu. The only exception is gem_prime_mmap,
which is non-trivial to convert.

v2:
* move object-function instance to amdgpu_gem.c (Christian)
* set callbacks in amdgpu_gem_object_create() (Christian)

Signed-off-by: Thomas Zimmermann 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|  6 --
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 23 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h|  5 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  1 +
  4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 6edde2b9e402..840ca8f9c1e1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1505,19 +1505,13 @@ static struct drm_driver kms_driver = {
.lastclose = amdgpu_driver_lastclose_kms,
.irq_handler = amdgpu_irq_handler,
.ioctls = amdgpu_ioctls_kms,
-   .gem_free_object_unlocked = amdgpu_gem_object_free,
-   .gem_open_object = amdgpu_gem_object_open,
-   .gem_close_object = amdgpu_gem_object_close,
.dumb_create = amdgpu_mode_dumb_create,
.dumb_map_offset = amdgpu_mode_dumb_mmap,
.fops = _driver_kms_fops,
  
  	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,

.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = amdgpu_gem_prime_export,
.gem_prime_import = amdgpu_gem_prime_import,
-   .gem_prime_vmap = amdgpu_gem_prime_vmap,
-   .gem_prime_vunmap = amdgpu_gem_prime_vunmap,
.gem_prime_mmap = amdgpu_gem_prime_mmap,
  
  	.name = DRIVER_NAME,

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index aa7f230c71bf..aeecd5dc3ce4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -36,9 +36,12 @@
  
  #include "amdgpu.h"

  #include "amdgpu_display.h"
+#include "amdgpu_dma_buf.h"
  #include "amdgpu_xgmi.h"
  
-void amdgpu_gem_object_free(struct drm_gem_object *gobj)

+static const struct drm_gem_object_funcs amdgpu_gem_object_funcs;
+
+static void amdgpu_gem_object_free(struct drm_gem_object *gobj)
  {
struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj);
  
@@ -87,6 +90,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,

return r;
}
*obj = >tbo.base;
+   (*obj)->funcs = _gem_object_funcs;
  
  	return 0;

  }
@@ -119,8 +123,8 @@ void amdgpu_gem_force_release(struct amdgpu_device *adev)
   * Call from drm_gem_handle_create which appear in both new and open ioctl
   * case.
   */
-int amdgpu_gem_object_open(struct drm_gem_object *obj,
-  struct drm_file *file_priv)
+static int amdgpu_gem_object_open(struct drm_gem_object *obj,
+ struct drm_file *file_priv)
  {
struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj);
struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
@@ -152,8 +156,8 @@ int amdgpu_gem_object_open(struct drm_gem_object *obj,
return 0;
  }
  
-void amdgpu_gem_object_close(struct drm_gem_object *obj,

-struct drm_file *file_priv)
+static void amdgpu_gem_object_close(struct drm_gem_object *obj,
+   struct drm_file *file_priv)
  {
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
@@ -211,6 +215,15 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,
ttm_eu_backoff_reservation(, );
  }
  
+static const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {

+   .free = amdgpu_gem_object_free,
+   .open = amdgpu_gem_object_open,
+   .close = amdgpu_gem_object_close,
+   .export = amdgpu_gem_prime_export,
+   .vmap = amdgpu_gem_prime_vmap,
+   .vunmap = amdgpu_gem_prime_vunmap,
+};
+
  /*
   * GEM ioctls.
   */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
index e0f025dd1b14..637bf51dbf06 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
@@ -33,11 +33,6 @@
  #define AMDGPU_GEM_DOMAIN_MAX 0x3
  #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, 
tbo.base)
  
-void amdgpu_gem_object_free(struct drm_gem_object *obj);

-int amdgpu_gem_object_open(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
-void amdgpu_gem_object_close(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
  unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
  
  /*

diff --git 

Re: [PATCH 3/3] x86/shim: don't permit HVM and PV_SHIM_EXCLUSIVE at the same time

2020-09-15 Thread Roger Pau Monné
On Mon, Sep 14, 2020 at 02:39:33PM +0200, Jan Beulich wrote:
> This combination doesn't really make sense (and there likely are more).
> The alternative here would be some presumably intrusive #ifdef-ary to
> get this combination to actually build again.
> 
> Signed-off-by: Jan Beulich 

I'm not sure I see a way to cater for Andrew requests while allowing
PV_SHIM_EXCLUSIVE to gate options in order to be able to remove
code.

Maybe PV_SHIM_EXCLUSIVE should be moved to the top level Kconfig
screen on x86 and behave like a list, so that you select a 'Normal'
hypervisor build or a 'PV shim exclusive' build, and that could
completely change the contents of the menus?

If that doesn't seem suitable I think the proposed patch is a good
option unless someone has a better approach.

Thanks, Roger.



[PATCH v2 20/21] drm/xlnx: Initialize DRM driver instance with CMA helper macro

2020-09-15 Thread Thomas Zimmermann
The xlnx driver uses CMA helpers with default callback functions.
Initialize the driver structure with the rsp CMA helper macro. The
driver is being converted to use GEM object functions as part of
this change.

Two callbacks, .dumb_destroy and .gem_prime_import, were initialized
to their default implementations, so they are just kept empty now.

v2:
* initialize with DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE (Laurent)

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/xlnx/zynqmp_dpsub.c | 14 +-
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c 
b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
index 8e69303aad3f..f3ffc3703a0e 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
@@ -80,19 +80,7 @@ static struct drm_driver zynqmp_dpsub_drm_driver = {
.driver_features= DRIVER_MODESET | DRIVER_GEM |
  DRIVER_ATOMIC,
 
-   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
-   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export   = drm_gem_prime_export,
-   .gem_prime_import   = drm_gem_prime_import,
-   .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
-   .gem_prime_import_sg_table  = drm_gem_cma_prime_import_sg_table,
-   .gem_prime_vmap = drm_gem_cma_prime_vmap,
-   .gem_prime_vunmap   = drm_gem_cma_prime_vunmap,
-   .gem_prime_mmap = drm_gem_cma_prime_mmap,
-   .gem_free_object_unlocked   = drm_gem_cma_free_object,
-   .gem_vm_ops = _gem_cma_vm_ops,
-   .dumb_create= zynqmp_dpsub_dumb_create,
-   .dumb_destroy   = drm_gem_dumb_destroy,
+   DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE(zynqmp_dpsub_dumb_create),
 
.fops   = _dpsub_drm_fops,
 
-- 
2.28.0




[PATCH v2 10/21] drm/omapdrm: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in omapdrm.

v2:
* make omap_gem_free_object() static (Tomi)

Signed-off-by: Thomas Zimmermann 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Tomi Valkeinen 
---
 drivers/gpu/drm/omapdrm/omap_drv.c |  9 -
 drivers/gpu/drm/omapdrm/omap_gem.c | 18 --
 drivers/gpu/drm/omapdrm/omap_gem.h |  2 --
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c 
b/drivers/gpu/drm/omapdrm/omap_drv.c
index 53d5e184ee77..2e598b8b72af 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.c
+++ b/drivers/gpu/drm/omapdrm/omap_drv.c
@@ -521,12 +521,6 @@ static int dev_open(struct drm_device *dev, struct 
drm_file *file)
return 0;
 }
 
-static const struct vm_operations_struct omap_gem_vm_ops = {
-   .fault = omap_gem_fault,
-   .open = drm_gem_vm_open,
-   .close = drm_gem_vm_close,
-};
-
 static const struct file_operations omapdriver_fops = {
.owner = THIS_MODULE,
.open = drm_open,
@@ -549,10 +543,7 @@ static struct drm_driver omap_drm_driver = {
 #endif
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = omap_gem_prime_export,
.gem_prime_import = omap_gem_prime_import,
-   .gem_free_object_unlocked = omap_gem_free_object,
-   .gem_vm_ops = _gem_vm_ops,
.dumb_create = omap_gem_dumb_create,
.dumb_map_offset = omap_gem_dumb_map_offset,
.ioctls = ioctls,
diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c 
b/drivers/gpu/drm/omapdrm/omap_gem.c
index d0d12d5dd76c..979d53a93c2b 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem.c
+++ b/drivers/gpu/drm/omapdrm/omap_gem.c
@@ -487,7 +487,7 @@ static vm_fault_t omap_gem_fault_2d(struct drm_gem_object 
*obj,
  * vma->vm_private_data points to the GEM object that is backing this
  * mapping.
  */
-vm_fault_t omap_gem_fault(struct vm_fault *vmf)
+static vm_fault_t omap_gem_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct drm_gem_object *obj = vma->vm_private_data;
@@ -1089,7 +1089,7 @@ void omap_gem_describe_objects(struct list_head *list, 
struct seq_file *m)
  * Constructor & Destructor
  */
 
-void omap_gem_free_object(struct drm_gem_object *obj)
+static void omap_gem_free_object(struct drm_gem_object *obj)
 {
struct drm_device *dev = obj->dev;
struct omap_drm_private *priv = dev->dev_private;
@@ -1169,6 +1169,18 @@ static bool omap_gem_validate_flags(struct drm_device 
*dev, u32 flags)
return true;
 }
 
+static const struct vm_operations_struct omap_gem_vm_ops = {
+   .fault = omap_gem_fault,
+   .open = drm_gem_vm_open,
+   .close = drm_gem_vm_close,
+};
+
+static const struct drm_gem_object_funcs omap_gem_object_funcs = {
+   .free = omap_gem_free_object,
+   .export = omap_gem_prime_export,
+   .vm_ops = _gem_vm_ops,
+};
+
 /* GEM buffer object constructor */
 struct drm_gem_object *omap_gem_new(struct drm_device *dev,
union omap_gem_size gsize, u32 flags)
@@ -1236,6 +1248,8 @@ struct drm_gem_object *omap_gem_new(struct drm_device 
*dev,
size = PAGE_ALIGN(gsize.bytes);
}
 
+   obj->funcs = _gem_object_funcs;
+
/* Initialize the GEM object. */
if (!(flags & OMAP_BO_MEM_SHMEM)) {
drm_gem_private_object_init(dev, obj, size);
diff --git a/drivers/gpu/drm/omapdrm/omap_gem.h 
b/drivers/gpu/drm/omapdrm/omap_gem.h
index 729b7812a815..eda9b4839c30 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem.h
+++ b/drivers/gpu/drm/omapdrm/omap_gem.h
@@ -48,7 +48,6 @@ struct drm_gem_object *omap_gem_new_dmabuf(struct drm_device 
*dev, size_t size,
struct sg_table *sgt);
 int omap_gem_new_handle(struct drm_device *dev, struct drm_file *file,
union omap_gem_size gsize, u32 flags, u32 *handle);
-void omap_gem_free_object(struct drm_gem_object *obj);
 void *omap_gem_vaddr(struct drm_gem_object *obj);
 
 /* Dumb Buffers Interface */
@@ -69,7 +68,6 @@ struct dma_buf *omap_gem_prime_export(struct drm_gem_object 
*obj, int flags);
 struct drm_gem_object *omap_gem_prime_import(struct drm_device *dev,
struct dma_buf *buffer);
 
-vm_fault_t omap_gem_fault(struct vm_fault *vmf);
 int omap_gem_roll(struct drm_gem_object *obj, u32 roll);
 void omap_gem_cpu_sync_page(struct drm_gem_object *obj, int pgoff);
 void omap_gem_dma_sync_buffer(struct drm_gem_object *obj,
-- 
2.28.0




[PATCH v2 19/21] drm/xen: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in xen. The only exception is gem_prime_mmap,
which is non-trivial to convert.

v2:
* convert xen_drm_drv_free_object_unlocked() to static
  callback (Oleksandr)

Signed-off-by: Thomas Zimmermann 
Acked-by: Oleksandr Andrushchenko 
---
 drivers/gpu/drm/xen/xen_drm_front.c | 44 ++---
 drivers/gpu/drm/xen/xen_drm_front.h |  2 ++
 drivers/gpu/drm/xen/xen_drm_front_gem.c | 15 +
 3 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/xen/xen_drm_front.c 
b/drivers/gpu/drm/xen/xen_drm_front.c
index cc93a8c9547b..98b6d2ba088a 100644
--- a/drivers/gpu/drm/xen/xen_drm_front.c
+++ b/drivers/gpu/drm/xen/xen_drm_front.c
@@ -381,6 +381,23 @@ void xen_drm_front_on_frame_done(struct xen_drm_front_info 
*front_info,
fb_cookie);
 }
 
+void xen_drm_front_gem_object_free(struct drm_gem_object *obj)
+{
+   struct xen_drm_front_drm_info *drm_info = obj->dev->dev_private;
+   int idx;
+
+   if (drm_dev_enter(obj->dev, )) {
+   xen_drm_front_dbuf_destroy(drm_info->front_info,
+  xen_drm_front_dbuf_to_cookie(obj));
+   drm_dev_exit(idx);
+   } else {
+   dbuf_free(_info->front_info->dbuf_list,
+ xen_drm_front_dbuf_to_cookie(obj));
+   }
+
+   xen_drm_front_gem_free_object_unlocked(obj);
+}
+
 static int xen_drm_drv_dumb_create(struct drm_file *filp,
   struct drm_device *dev,
   struct drm_mode_create_dumb *args)
@@ -435,23 +452,6 @@ static int xen_drm_drv_dumb_create(struct drm_file *filp,
return ret;
 }
 
-static void xen_drm_drv_free_object_unlocked(struct drm_gem_object *obj)
-{
-   struct xen_drm_front_drm_info *drm_info = obj->dev->dev_private;
-   int idx;
-
-   if (drm_dev_enter(obj->dev, )) {
-   xen_drm_front_dbuf_destroy(drm_info->front_info,
-  xen_drm_front_dbuf_to_cookie(obj));
-   drm_dev_exit(idx);
-   } else {
-   dbuf_free(_info->front_info->dbuf_list,
- xen_drm_front_dbuf_to_cookie(obj));
-   }
-
-   xen_drm_front_gem_free_object_unlocked(obj);
-}
-
 static void xen_drm_drv_release(struct drm_device *dev)
 {
struct xen_drm_front_drm_info *drm_info = dev->dev_private;
@@ -483,22 +483,12 @@ static const struct file_operations xen_drm_dev_fops = {
.mmap   = xen_drm_front_gem_mmap,
 };
 
-static const struct vm_operations_struct xen_drm_drv_vm_ops = {
-   .open   = drm_gem_vm_open,
-   .close  = drm_gem_vm_close,
-};
-
 static struct drm_driver xen_drm_driver = {
.driver_features   = DRIVER_GEM | DRIVER_MODESET | 
DRIVER_ATOMIC,
.release   = xen_drm_drv_release,
-   .gem_vm_ops= _drm_drv_vm_ops,
-   .gem_free_object_unlocked  = xen_drm_drv_free_object_unlocked,
.prime_handle_to_fd= drm_gem_prime_handle_to_fd,
.prime_fd_to_handle= drm_gem_prime_fd_to_handle,
.gem_prime_import_sg_table = xen_drm_front_gem_import_sg_table,
-   .gem_prime_get_sg_table= xen_drm_front_gem_get_sg_table,
-   .gem_prime_vmap= xen_drm_front_gem_prime_vmap,
-   .gem_prime_vunmap  = xen_drm_front_gem_prime_vunmap,
.gem_prime_mmap= xen_drm_front_gem_prime_mmap,
.dumb_create   = xen_drm_drv_dumb_create,
.fops  = _drm_dev_fops,
diff --git a/drivers/gpu/drm/xen/xen_drm_front.h 
b/drivers/gpu/drm/xen/xen_drm_front.h
index 54486d89650e..cefafe859aba 100644
--- a/drivers/gpu/drm/xen/xen_drm_front.h
+++ b/drivers/gpu/drm/xen/xen_drm_front.h
@@ -160,4 +160,6 @@ int xen_drm_front_page_flip(struct xen_drm_front_info 
*front_info,
 void xen_drm_front_on_frame_done(struct xen_drm_front_info *front_info,
 int conn_idx, u64 fb_cookie);
 
+void xen_drm_front_gem_object_free(struct drm_gem_object *obj);
+
 #endif /* __XEN_DRM_FRONT_H_ */
diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c 
b/drivers/gpu/drm/xen/xen_drm_front_gem.c
index a8aefaa38bd3..f3830a0d1808 100644
--- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
+++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
@@ -57,6 +57,19 @@ static void gem_free_pages_array(struct xen_gem_object 
*xen_obj)
xen_obj->pages = NULL;
 }
 
+static const struct vm_operations_struct xen_drm_drv_vm_ops = {
+   .open   = drm_gem_vm_open,
+   .close  = drm_gem_vm_close,
+};
+
+static const struct drm_gem_object_funcs xen_drm_front_gem_object_funcs = {
+   .free = xen_drm_front_gem_object_free,
+   .get_sg_table = 

[PATCH v2 21/21] drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver

2020-09-15 Thread Thomas Zimmermann
Several GEM and PRIME callbacks have been deprecated in favor of
per-instance GEM object functions. Remove the callbacks as they are
now unused. The only exception is .gem_prime_mmap, which is still
in use by several drivers.

What is also gone is gem_vm_ops in struct drm_driver. All drivers now
use struct drm_gem_object_funcs.vm_ops instead.

While at it, the patch also improves error handling around calls
to .free and .get_sg_table callbacks.

v2:
* update related TODO item (Sam)

Signed-off-by: Thomas Zimmermann 
---
 Documentation/gpu/todo.rst   |  7 +--
 drivers/gpu/drm/drm_gem.c| 35 +++-
 drivers/gpu/drm/drm_gem_cma_helper.c |  6 +-
 drivers/gpu/drm/drm_prime.c  | 17 +++---
 include/drm/drm_drv.h| 85 ++--
 5 files changed, 25 insertions(+), 125 deletions(-)

diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index b0ea17da8ff6..0fc6bc222392 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -289,11 +289,8 @@ struct drm_gem_object_funcs
 ---
 
 GEM objects can now have a function table instead of having the callbacks on 
the
-DRM driver struct. This is now the preferred way and drivers can be moved over.
-
-We also need a 2nd version of the CMA define that doesn't require the
-vmapping to be present (different hook for prime importing). Plus this needs to
-be rolled out to all drivers using their own implementations, too.
+DRM driver struct. This is now the preferred way. Callbacks in drivers have 
been
+converted, except for struct drm_driver.gem_prime_mmap.
 
 Level: Intermediate
 
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 19d73868490e..96945bed8291 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -247,12 +247,9 @@ drm_gem_object_release_handle(int id, void *ptr, void 
*data)
 {
struct drm_file *file_priv = data;
struct drm_gem_object *obj = ptr;
-   struct drm_device *dev = obj->dev;
 
if (obj->funcs && obj->funcs->close)
obj->funcs->close(obj, file_priv);
-   else if (dev->driver->gem_close_object)
-   dev->driver->gem_close_object(obj, file_priv);
 
drm_gem_remove_prime_handles(obj, file_priv);
drm_vma_node_revoke(>vma_node, file_priv);
@@ -407,10 +404,6 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
ret = obj->funcs->open(obj, file_priv);
if (ret)
goto err_revoke;
-   } else if (dev->driver->gem_open_object) {
-   ret = dev->driver->gem_open_object(obj, file_priv);
-   if (ret)
-   goto err_revoke;
}
 
*handlep = handle;
@@ -982,12 +975,11 @@ drm_gem_object_free(struct kref *kref)
 {
struct drm_gem_object *obj =
container_of(kref, struct drm_gem_object, refcount);
-   struct drm_device *dev = obj->dev;
 
-   if (obj->funcs)
-   obj->funcs->free(obj);
-   else if (dev->driver->gem_free_object_unlocked)
-   dev->driver->gem_free_object_unlocked(obj);
+   if (drm_WARN_ON_ONCE(obj->dev, !obj->funcs || !obj->funcs->free))
+   return;
+
+   obj->funcs->free(obj);
 }
 EXPORT_SYMBOL(drm_gem_object_free);
 
@@ -1049,9 +1041,9 @@ EXPORT_SYMBOL(drm_gem_vm_close);
  * @obj_size: the object size to be mapped, in bytes
  * @vma: VMA for the area to be mapped
  *
- * Set up the VMA to prepare mapping of the GEM object using the gem_vm_ops
- * provided by the driver. Depending on their requirements, drivers can either
- * provide a fault handler in their gem_vm_ops (in which case any accesses to
+ * Set up the VMA to prepare mapping of the GEM object using the GEM object's
+ * vm_ops. Depending on their requirements, GEM objects can either
+ * provide a fault handler in their vm_ops (in which case any accesses to
  * the object will be trapped, to perform migration, GTT binding, surface
  * register allocation, or performance monitoring), or mmap the buffer memory
  * synchronously after calling drm_gem_mmap_obj.
@@ -1065,12 +1057,11 @@ EXPORT_SYMBOL(drm_gem_vm_close);
  * callers must verify access restrictions before calling this helper.
  *
  * Return 0 or success or -EINVAL if the object size is smaller than the VMA
- * size, or if no gem_vm_ops are provided.
+ * size, or if no vm_ops are provided.
  */
 int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
 struct vm_area_struct *vma)
 {
-   struct drm_device *dev = obj->dev;
int ret;
 
/* Check for valid size. */
@@ -1095,8 +1086,6 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned 
long obj_size,
} else {
if (obj->funcs && obj->funcs->vm_ops)
vma->vm_ops = obj->funcs->vm_ops;
-   else if (dev->driver->gem_vm_ops)
-   

[PATCH v2 12/21] drm/radeon: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in radeon.

v2:
* move object-function instance to radeon_gem.c (Christian)
* set callbacks in radeon_gem_object_create() (Christian)

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/radeon/radeon_drv.c | 23 +
 drivers/gpu/drm/radeon/radeon_gem.c | 31 +
 2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_drv.c 
b/drivers/gpu/drm/radeon/radeon_drv.c
index 4cd30613fa1d..65061c949aee 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -124,13 +124,6 @@ void radeon_driver_irq_preinstall_kms(struct drm_device 
*dev);
 int radeon_driver_irq_postinstall_kms(struct drm_device *dev);
 void radeon_driver_irq_uninstall_kms(struct drm_device *dev);
 irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg);
-void radeon_gem_object_free(struct drm_gem_object *obj);
-int radeon_gem_object_open(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
-void radeon_gem_object_close(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
-struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
-   int flags);
 extern int radeon_get_crtc_scanoutpos(struct drm_device *dev, unsigned int 
crtc,
  unsigned int flags, int *vpos, int *hpos,
  ktime_t *stime, ktime_t *etime,
@@ -145,14 +138,9 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
 int radeon_mode_dumb_create(struct drm_file *file_priv,
struct drm_device *dev,
struct drm_mode_create_dumb *args);
-struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
 struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
struct 
dma_buf_attachment *,
struct sg_table *sg);
-int radeon_gem_prime_pin(struct drm_gem_object *obj);
-void radeon_gem_prime_unpin(struct drm_gem_object *obj);
-void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
-void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
 
 /* atpx handler */
 #if defined(CONFIG_VGA_SWITCHEROO)
@@ -550,7 +538,7 @@ long radeon_drm_ioctl(struct file *filp,
}
 
ret = drm_ioctl(filp, cmd, arg);
-   
+
pm_runtime_mark_last_busy(dev->dev);
pm_runtime_put_autosuspend(dev->dev);
return ret;
@@ -609,22 +597,13 @@ static struct drm_driver kms_driver = {
.irq_uninstall = radeon_driver_irq_uninstall_kms,
.irq_handler = radeon_driver_irq_handler_kms,
.ioctls = radeon_ioctls_kms,
-   .gem_free_object_unlocked = radeon_gem_object_free,
-   .gem_open_object = radeon_gem_object_open,
-   .gem_close_object = radeon_gem_object_close,
.dumb_create = radeon_mode_dumb_create,
.dumb_map_offset = radeon_mode_dumb_mmap,
.fops = _driver_kms_fops,
 
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = radeon_gem_prime_export,
-   .gem_prime_pin = radeon_gem_prime_pin,
-   .gem_prime_unpin = radeon_gem_prime_unpin,
-   .gem_prime_get_sg_table = radeon_gem_prime_get_sg_table,
.gem_prime_import_sg_table = radeon_gem_prime_import_sg_table,
-   .gem_prime_vmap = radeon_gem_prime_vmap,
-   .gem_prime_vunmap = radeon_gem_prime_vunmap,
 
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c 
b/drivers/gpu/drm/radeon/radeon_gem.c
index e5c4271e64ed..0ccd7213e41f 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -35,7 +35,17 @@
 
 #include "radeon.h"
 
-void radeon_gem_object_free(struct drm_gem_object *gobj)
+struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
+   int flags);
+struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
+int radeon_gem_prime_pin(struct drm_gem_object *obj);
+void radeon_gem_prime_unpin(struct drm_gem_object *obj);
+void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
+void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
+
+static const struct drm_gem_object_funcs radeon_gem_object_funcs;
+
+static void radeon_gem_object_free(struct drm_gem_object *gobj)
 {
struct radeon_bo *robj = gem_to_radeon_bo(gobj);
 
@@ -85,6 +95,7 @@ int radeon_gem_object_create(struct radeon_device *rdev, 
unsigned long size,
return r;
}
*obj = >tbo.base;
+   (*obj)->funcs = 

[PATCH v2 07/21] drm/mediatek: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in mediatek. The only exception is gem_prime_mmap,
which is non-trivial to convert.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/mediatek/mtk_drm_drv.c |  5 -
 drivers/gpu/drm/mediatek/mtk_drm_gem.c | 11 +++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c 
b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 040a8f393fe2..2f8d0043fca7 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -301,18 +301,13 @@ struct drm_gem_object *mtk_drm_gem_prime_import(struct 
drm_device *dev,
 static struct drm_driver mtk_drm_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
 
-   .gem_free_object_unlocked = mtk_drm_gem_free_object,
-   .gem_vm_ops = _gem_cma_vm_ops,
.dumb_create = mtk_drm_gem_dumb_create,
 
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import = mtk_drm_gem_prime_import,
-   .gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
.gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
.gem_prime_mmap = mtk_drm_gem_mmap_buf,
-   .gem_prime_vmap = mtk_drm_gem_prime_vmap,
-   .gem_prime_vunmap = mtk_drm_gem_prime_vunmap,
.fops = _drm_fops,
 
.name = DRIVER_NAME,
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c 
b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
index 6190cc3b7b0d..591b90410e4a 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
@@ -8,11 +8,20 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "mtk_drm_drv.h"
 #include "mtk_drm_gem.h"
 
+static const struct drm_gem_object_funcs mtk_drm_gem_object_funcs = {
+   .free = mtk_drm_gem_free_object,
+   .get_sg_table = mtk_gem_prime_get_sg_table,
+   .vmap = mtk_drm_gem_prime_vmap,
+   .vunmap = mtk_drm_gem_prime_vunmap,
+   .vm_ops = _gem_cma_vm_ops,
+};
+
 static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct drm_device *dev,
unsigned long size)
 {
@@ -25,6 +34,8 @@ static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct 
drm_device *dev,
if (!mtk_gem_obj)
return ERR_PTR(-ENOMEM);
 
+   mtk_gem_obj->base.funcs = _drm_gem_object_funcs;
+
ret = drm_gem_object_init(dev, _gem_obj->base, size);
if (ret < 0) {
DRM_ERROR("failed to initialize gem object\n");
-- 
2.28.0




[PATCH v2 14/21] drm/tegra: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in tegra.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/tegra/drm.c | 4 
 drivers/gpu/drm/tegra/gem.c | 8 
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index ba9d1c3e7cac..f0f581cd345e 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -858,12 +858,8 @@ static struct drm_driver tegra_drm_driver = {
.debugfs_init = tegra_debugfs_init,
 #endif
 
-   .gem_free_object_unlocked = tegra_bo_free_object,
-   .gem_vm_ops = _bo_vm_ops,
-
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = tegra_gem_prime_export,
.gem_prime_import = tegra_gem_prime_import,
 
.dumb_create = tegra_bo_dumb_create,
diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c
index 47e2935b8c68..d481dea4738d 100644
--- a/drivers/gpu/drm/tegra/gem.c
+++ b/drivers/gpu/drm/tegra/gem.c
@@ -231,6 +231,12 @@ static int tegra_bo_iommu_unmap(struct tegra_drm *tegra, 
struct tegra_bo *bo)
return 0;
 }
 
+static const struct drm_gem_object_funcs tegra_gem_object_funcs = {
+   .free = tegra_bo_free_object,
+   .export = tegra_gem_prime_export,
+   .vm_ops = _bo_vm_ops,
+};
+
 static struct tegra_bo *tegra_bo_alloc_object(struct drm_device *drm,
  size_t size)
 {
@@ -241,6 +247,8 @@ static struct tegra_bo *tegra_bo_alloc_object(struct 
drm_device *drm,
if (!bo)
return ERR_PTR(-ENOMEM);
 
+   bo->gem.funcs = _gem_object_funcs;
+
host1x_bo_init(>base, _bo_ops);
size = round_up(size, PAGE_SIZE);
 
-- 
2.28.0




[PATCH v2 15/21] drm/vc4: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in vc4. The only exception is gem_prime_mmap,
which is non-trivial to convert.

Signed-off-by: Thomas Zimmermann 
Reviewed-by: Eric Anholt 
---
 drivers/gpu/drm/vc4/vc4_bo.c  | 21 -
 drivers/gpu/drm/vc4/vc4_drv.c | 12 
 drivers/gpu/drm/vc4/vc4_drv.h |  1 -
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
index 74ceebd62fbc..f432278173cd 100644
--- a/drivers/gpu/drm/vc4/vc4_bo.c
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
@@ -21,6 +21,8 @@
 #include "vc4_drv.h"
 #include "uapi/drm/vc4_drm.h"
 
+static vm_fault_t vc4_fault(struct vm_fault *vmf);
+
 static const char * const bo_type_names[] = {
"kernel",
"V3D",
@@ -374,6 +376,21 @@ static struct vc4_bo *vc4_bo_get_from_cache(struct 
drm_device *dev,
return bo;
 }
 
+static const struct vm_operations_struct vc4_vm_ops = {
+   .fault = vc4_fault,
+   .open = drm_gem_vm_open,
+   .close = drm_gem_vm_close,
+};
+
+static const struct drm_gem_object_funcs vc4_gem_object_funcs = {
+   .free = vc4_free_object,
+   .export = vc4_prime_export,
+   .get_sg_table = drm_gem_cma_prime_get_sg_table,
+   .vmap = vc4_prime_vmap,
+   .vunmap = drm_gem_cma_prime_vunmap,
+   .vm_ops = _vm_ops,
+};
+
 /**
  * vc4_gem_create_object - Implementation of driver->gem_create_object.
  * @dev: DRM device
@@ -400,6 +417,8 @@ struct drm_gem_object *vc4_create_object(struct drm_device 
*dev, size_t size)
vc4->bo_labels[VC4_BO_TYPE_KERNEL].size_allocated += size;
mutex_unlock(>bo_lock);
 
+   bo->base.base.funcs = _gem_object_funcs;
+
return >base.base;
 }
 
@@ -684,7 +703,7 @@ struct dma_buf * vc4_prime_export(struct drm_gem_object 
*obj, int flags)
return dmabuf;
 }
 
-vm_fault_t vc4_fault(struct vm_fault *vmf)
+static vm_fault_t vc4_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct drm_gem_object *obj = vma->vm_private_data;
diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index f1a5fd5dab6f..d27eaa2d0cfe 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -140,12 +140,6 @@ static void vc4_close(struct drm_device *dev, struct 
drm_file *file)
kfree(vc4file);
 }
 
-static const struct vm_operations_struct vc4_vm_ops = {
-   .fault = vc4_fault,
-   .open = drm_gem_vm_open,
-   .close = drm_gem_vm_close,
-};
-
 static const struct file_operations vc4_drm_fops = {
.owner = THIS_MODULE,
.open = drm_open,
@@ -195,16 +189,10 @@ static struct drm_driver vc4_drm_driver = {
 #endif
 
.gem_create_object = vc4_create_object,
-   .gem_free_object_unlocked = vc4_free_object,
-   .gem_vm_ops = _vm_ops,
 
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = vc4_prime_export,
-   .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
.gem_prime_import_sg_table = vc4_prime_import_sg_table,
-   .gem_prime_vmap = vc4_prime_vmap,
-   .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
.gem_prime_mmap = vc4_prime_mmap,
 
.dumb_create = vc4_dumb_create,
diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index 8c8d96b6289f..a22478a35199 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -799,7 +799,6 @@ int vc4_get_hang_state_ioctl(struct drm_device *dev, void 
*data,
 struct drm_file *file_priv);
 int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
   struct drm_file *file_priv);
-vm_fault_t vc4_fault(struct vm_fault *vmf);
 int vc4_mmap(struct file *filp, struct vm_area_struct *vma);
 int vc4_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
 struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,
-- 
2.28.0




[PATCH v2 16/21] drm/vgem: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in vgem. The only exception is gem_prime_mmap,
which is non-trivial to convert.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/vgem/vgem_drv.c | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
index cb884c890065..fa54a6d1403d 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.c
+++ b/drivers/gpu/drm/vgem/vgem_drv.c
@@ -50,6 +50,8 @@
 #define DRIVER_MAJOR   1
 #define DRIVER_MINOR   0
 
+static const struct drm_gem_object_funcs vgem_gem_object_funcs;
+
 static struct vgem_device {
struct drm_device drm;
struct platform_device *platform;
@@ -167,6 +169,8 @@ static struct drm_vgem_gem_object *__vgem_gem_create(struct 
drm_device *dev,
if (!obj)
return ERR_PTR(-ENOMEM);
 
+   obj->base.funcs = _gem_object_funcs;
+
ret = drm_gem_object_init(dev, >base, roundup(size, PAGE_SIZE));
if (ret) {
kfree(obj);
@@ -401,12 +405,20 @@ static int vgem_prime_mmap(struct drm_gem_object *obj,
return 0;
 }
 
+static const struct drm_gem_object_funcs vgem_gem_object_funcs = {
+   .free = vgem_gem_free_object,
+   .pin = vgem_prime_pin,
+   .unpin = vgem_prime_unpin,
+   .get_sg_table = vgem_prime_get_sg_table,
+   .vmap = vgem_prime_vmap,
+   .vunmap = vgem_prime_vunmap,
+   .vm_ops = _gem_vm_ops,
+};
+
 static struct drm_driver vgem_driver = {
.driver_features= DRIVER_GEM | DRIVER_RENDER,
.open   = vgem_open,
.postclose  = vgem_postclose,
-   .gem_free_object_unlocked   = vgem_gem_free_object,
-   .gem_vm_ops = _gem_vm_ops,
.ioctls = vgem_ioctls,
.num_ioctls = ARRAY_SIZE(vgem_ioctls),
.fops   = _driver_fops,
@@ -415,13 +427,8 @@ static struct drm_driver vgem_driver = {
 
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_pin = vgem_prime_pin,
-   .gem_prime_unpin = vgem_prime_unpin,
.gem_prime_import = vgem_prime_import,
.gem_prime_import_sg_table = vgem_prime_import_sg_table,
-   .gem_prime_get_sg_table = vgem_prime_get_sg_table,
-   .gem_prime_vmap = vgem_prime_vmap,
-   .gem_prime_vunmap = vgem_prime_vunmap,
.gem_prime_mmap = vgem_prime_mmap,
 
.name   = DRIVER_NAME,
-- 
2.28.0




[PATCH v2 06/21] drm/i915: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in i915.

v2:
* move object-function instance to i915_gem_object.c (Jani)

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/i915/gem/i915_gem_object.c| 21 ---
 drivers/gpu/drm/i915/gem/i915_gem_object.h|  3 ---
 drivers/gpu/drm/i915/i915_drv.c   |  4 
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  3 ---
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c 
b/drivers/gpu/drm/i915/gem/i915_gem_object.c
index c8421fd9d2dc..3389ac972d16 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
@@ -39,9 +39,18 @@ static struct i915_global_object {
struct kmem_cache *slab_objects;
 } global;
 
+static const struct drm_gem_object_funcs i915_gem_object_funcs;
+
 struct drm_i915_gem_object *i915_gem_object_alloc(void)
 {
-   return kmem_cache_zalloc(global.slab_objects, GFP_KERNEL);
+   struct drm_i915_gem_object *obj;
+
+   obj = kmem_cache_zalloc(global.slab_objects, GFP_KERNEL);
+   if (!obj)
+   return NULL;
+   obj->base.funcs = _gem_object_funcs;
+
+   return obj;
 }
 
 void i915_gem_object_free(struct drm_i915_gem_object *obj)
@@ -101,7 +110,7 @@ void i915_gem_object_set_cache_coherency(struct 
drm_i915_gem_object *obj,
!(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE);
 }
 
-void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file)
+static void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file 
*file)
 {
struct drm_i915_gem_object *obj = to_intel_bo(gem);
struct drm_i915_file_private *fpriv = file->driver_priv;
@@ -264,7 +273,7 @@ static void __i915_gem_free_work(struct work_struct *work)
i915_gem_flush_free_objects(i915);
 }
 
-void i915_gem_free_object(struct drm_gem_object *gem_obj)
+static void i915_gem_free_object(struct drm_gem_object *gem_obj)
 {
struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
struct drm_i915_private *i915 = to_i915(obj->base.dev);
@@ -403,6 +412,12 @@ int __init i915_global_objects_init(void)
return 0;
 }
 
+static const struct drm_gem_object_funcs i915_gem_object_funcs = {
+   .free = i915_gem_free_object,
+   .close = i915_gem_close_object,
+   .export = i915_gem_prime_export,
+};
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftests/huge_gem_object.c"
 #include "selftests/huge_pages.c"
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h 
b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index d46db8d8f38e..eaf3d4147be0 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -38,9 +38,6 @@ void __i915_gem_object_release_shmem(struct 
drm_i915_gem_object *obj,
 
 int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align);
 
-void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file);
-void i915_gem_free_object(struct drm_gem_object *obj);
-
 void i915_gem_flush_free_objects(struct drm_i915_private *i915);
 
 struct sg_table *
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 94e00e450683..011a3fb41ece 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1750,12 +1750,8 @@ static struct drm_driver driver = {
.lastclose = i915_driver_lastclose,
.postclose = i915_driver_postclose,
 
-   .gem_close_object = i915_gem_close_object,
-   .gem_free_object_unlocked = i915_gem_free_object,
-
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = i915_gem_prime_export,
.gem_prime_import = i915_gem_prime_import,
 
.dumb_create = i915_gem_dumb_create,
diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c 
b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
index f127e633f7ca..9244b5d6fb01 100644
--- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
+++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
@@ -87,9 +87,6 @@ static struct drm_driver mock_driver = {
.name = "mock",
.driver_features = DRIVER_GEM,
.release = mock_device_release,
-
-   .gem_close_object = i915_gem_close_object,
-   .gem_free_object_unlocked = i915_gem_free_object,
 };
 
 static void release_dev(struct device *dev)
-- 
2.28.0




[PATCH v2 11/21] drm/pl111: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in pl111. The only exception is gem_prime_mmap,
which is non-trivial to convert.

v2:
* use drm_gem_cma_create_object_default_funcs() (Eric)

Signed-off-by: Thomas Zimmermann 
Reviewed-by: Eric Anholt 
---
 drivers/gpu/drm/pl111/pl111_drv.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/pl111/pl111_drv.c 
b/drivers/gpu/drm/pl111/pl111_drv.c
index 46b0d1c4a16c..ecef8a2383d2 100644
--- a/drivers/gpu/drm/pl111/pl111_drv.c
+++ b/drivers/gpu/drm/pl111/pl111_drv.c
@@ -224,15 +224,12 @@ static struct drm_driver pl111_drm_driver = {
.major = 1,
.minor = 0,
.patchlevel = 0,
+   .gem_create_object = drm_gem_cma_create_object_default_funcs,
.dumb_create = drm_gem_cma_dumb_create,
-   .gem_free_object_unlocked = drm_gem_cma_free_object,
-   .gem_vm_ops = _gem_cma_vm_ops,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import_sg_table = pl111_gem_import_sg_table,
-   .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
.gem_prime_mmap = drm_gem_cma_prime_mmap,
-   .gem_prime_vmap = drm_gem_cma_prime_vmap,
 
 #if defined(CONFIG_DEBUG_FS)
.debugfs_init = pl111_debugfs_init,
-- 
2.28.0




[PATCH v2 02/21] drm/armada: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in armada.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/armada/armada_drv.c |  3 ---
 drivers/gpu/drm/armada/armada_gem.c | 12 +++-
 drivers/gpu/drm/armada/armada_gem.h |  2 --
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/armada/armada_drv.c 
b/drivers/gpu/drm/armada/armada_drv.c
index 980d3f1f8f16..22247cfce80b 100644
--- a/drivers/gpu/drm/armada/armada_drv.c
+++ b/drivers/gpu/drm/armada/armada_drv.c
@@ -37,13 +37,10 @@ DEFINE_DRM_GEM_FOPS(armada_drm_fops);
 
 static struct drm_driver armada_drm_driver = {
.lastclose  = drm_fb_helper_lastclose,
-   .gem_free_object_unlocked = armada_gem_free_object,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export   = armada_gem_prime_export,
.gem_prime_import   = armada_gem_prime_import,
.dumb_create= armada_gem_dumb_create,
-   .gem_vm_ops = _gem_vm_ops,
.major  = 1,
.minor  = 0,
.name   = "armada-drm",
diff --git a/drivers/gpu/drm/armada/armada_gem.c 
b/drivers/gpu/drm/armada/armada_gem.c
index ecf8a55e93d9..c343fbefe47c 100644
--- a/drivers/gpu/drm/armada/armada_gem.c
+++ b/drivers/gpu/drm/armada/armada_gem.c
@@ -25,7 +25,7 @@ static vm_fault_t armada_gem_vm_fault(struct vm_fault *vmf)
return vmf_insert_pfn(vmf->vma, vmf->address, pfn);
 }
 
-const struct vm_operations_struct armada_gem_vm_ops = {
+static const struct vm_operations_struct armada_gem_vm_ops = {
.fault  = armada_gem_vm_fault,
.open   = drm_gem_vm_open,
.close  = drm_gem_vm_close,
@@ -184,6 +184,12 @@ armada_gem_map_object(struct drm_device *dev, struct 
armada_gem_object *dobj)
return dobj->addr;
 }
 
+static const struct drm_gem_object_funcs armada_gem_object_funcs = {
+   .free = armada_gem_free_object,
+   .export = armada_gem_prime_export,
+   .vm_ops = _gem_vm_ops,
+};
+
 struct armada_gem_object *
 armada_gem_alloc_private_object(struct drm_device *dev, size_t size)
 {
@@ -195,6 +201,8 @@ armada_gem_alloc_private_object(struct drm_device *dev, 
size_t size)
if (!obj)
return NULL;
 
+   obj->obj.funcs = _gem_object_funcs;
+
drm_gem_private_object_init(dev, >obj, size);
 
DRM_DEBUG_DRIVER("alloc private obj %p size %zu\n", obj, size);
@@ -214,6 +222,8 @@ static struct armada_gem_object 
*armada_gem_alloc_object(struct drm_device *dev,
if (!obj)
return NULL;
 
+   obj->obj.funcs = _gem_object_funcs;
+
if (drm_gem_object_init(dev, >obj, size)) {
kfree(obj);
return NULL;
diff --git a/drivers/gpu/drm/armada/armada_gem.h 
b/drivers/gpu/drm/armada/armada_gem.h
index de04cc2c8f0e..ffcc7e8dd351 100644
--- a/drivers/gpu/drm/armada/armada_gem.h
+++ b/drivers/gpu/drm/armada/armada_gem.h
@@ -21,8 +21,6 @@ struct armada_gem_object {
void*update_data;
 };
 
-extern const struct vm_operations_struct armada_gem_vm_ops;
-
 #define drm_to_armada_gem(o) container_of(o, struct armada_gem_object, obj)
 
 void armada_gem_free_object(struct drm_gem_object *);
-- 
2.28.0




[PATCH v2 13/21] drm/rockchip: Convert to drm_gem_object_funcs

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in rockchip. The only exception is gem_prime_mmap,
which is non-trivial to convert.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c |  5 -
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 10 ++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index 0f3eb392fe39..b7654f5e4225 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -212,15 +212,10 @@ static const struct file_operations 
rockchip_drm_driver_fops = {
 static struct drm_driver rockchip_drm_driver = {
.driver_features= DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
.lastclose  = drm_fb_helper_lastclose,
-   .gem_vm_ops = _gem_cma_vm_ops,
-   .gem_free_object_unlocked = rockchip_gem_free_object,
.dumb_create= rockchip_gem_dumb_create,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table,
.gem_prime_import_sg_table  = rockchip_gem_prime_import_sg_table,
-   .gem_prime_vmap = rockchip_gem_prime_vmap,
-   .gem_prime_vunmap   = rockchip_gem_prime_vunmap,
.gem_prime_mmap = rockchip_gem_mmap_buf,
.fops   = _drm_driver_fops,
.name   = DRIVER_NAME,
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
index 0055d86576f7..bddc7d99efe3 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
@@ -296,6 +296,14 @@ static void rockchip_gem_release_object(struct 
rockchip_gem_object *rk_obj)
kfree(rk_obj);
 }
 
+static const struct drm_gem_object_funcs rockchip_gem_object_funcs = {
+   .free = rockchip_gem_free_object,
+   .get_sg_table = rockchip_gem_prime_get_sg_table,
+   .vmap = rockchip_gem_prime_vmap,
+   .vunmap = rockchip_gem_prime_vunmap,
+   .vm_ops = _gem_cma_vm_ops,
+};
+
 static struct rockchip_gem_object *
rockchip_gem_alloc_object(struct drm_device *drm, unsigned int size)
 {
@@ -310,6 +318,8 @@ static struct rockchip_gem_object *
 
obj = _obj->base;
 
+   obj->funcs = _gem_object_funcs;
+
drm_gem_object_init(drm, obj, size);
 
return rk_obj;
-- 
2.28.0




[PATCH v2 17/21] drm/virtgpu: Set PRIME export function in struct drm_gem_object_funcs

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces virtgpu's per-driver PRIME export
function with a per-object function.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/virtio/virtgpu_drv.c| 1 -
 drivers/gpu/drm/virtio/virtgpu_object.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c 
b/drivers/gpu/drm/virtio/virtgpu_drv.c
index b039f493bda9..1f8d6ed11d21 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -203,7 +203,6 @@ static struct drm_driver driver = {
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_mmap = drm_gem_prime_mmap,
-   .gem_prime_export = virtgpu_gem_prime_export,
.gem_prime_import = virtgpu_gem_prime_import,
.gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table,
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c 
b/drivers/gpu/drm/virtio/virtgpu_object.c
index 842f8b61aa89..4f7d7ea8194c 100644
--- a/drivers/gpu/drm/virtio/virtgpu_object.c
+++ b/drivers/gpu/drm/virtio/virtgpu_object.c
@@ -108,6 +108,7 @@ static const struct drm_gem_object_funcs 
virtio_gpu_shmem_funcs = {
.close = virtio_gpu_gem_object_close,
 
.print_info = drm_gem_shmem_print_info,
+   .export = virtgpu_gem_prime_export,
.pin = drm_gem_shmem_pin,
.unpin = drm_gem_shmem_unpin,
.get_sg_table = drm_gem_shmem_get_sg_table,
-- 
2.28.0




[PATCH v2 01/21] drm/amdgpu: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in amdgpu. The only exception is gem_prime_mmap,
which is non-trivial to convert.

v2:
* move object-function instance to amdgpu_gem.c (Christian)
* set callbacks in amdgpu_gem_object_create() (Christian)

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c|  6 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 23 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h|  5 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c |  1 +
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 6edde2b9e402..840ca8f9c1e1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1505,19 +1505,13 @@ static struct drm_driver kms_driver = {
.lastclose = amdgpu_driver_lastclose_kms,
.irq_handler = amdgpu_irq_handler,
.ioctls = amdgpu_ioctls_kms,
-   .gem_free_object_unlocked = amdgpu_gem_object_free,
-   .gem_open_object = amdgpu_gem_object_open,
-   .gem_close_object = amdgpu_gem_object_close,
.dumb_create = amdgpu_mode_dumb_create,
.dumb_map_offset = amdgpu_mode_dumb_mmap,
.fops = _driver_kms_fops,
 
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_export = amdgpu_gem_prime_export,
.gem_prime_import = amdgpu_gem_prime_import,
-   .gem_prime_vmap = amdgpu_gem_prime_vmap,
-   .gem_prime_vunmap = amdgpu_gem_prime_vunmap,
.gem_prime_mmap = amdgpu_gem_prime_mmap,
 
.name = DRIVER_NAME,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index aa7f230c71bf..aeecd5dc3ce4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -36,9 +36,12 @@
 
 #include "amdgpu.h"
 #include "amdgpu_display.h"
+#include "amdgpu_dma_buf.h"
 #include "amdgpu_xgmi.h"
 
-void amdgpu_gem_object_free(struct drm_gem_object *gobj)
+static const struct drm_gem_object_funcs amdgpu_gem_object_funcs;
+
+static void amdgpu_gem_object_free(struct drm_gem_object *gobj)
 {
struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj);
 
@@ -87,6 +90,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, 
unsigned long size,
return r;
}
*obj = >tbo.base;
+   (*obj)->funcs = _gem_object_funcs;
 
return 0;
 }
@@ -119,8 +123,8 @@ void amdgpu_gem_force_release(struct amdgpu_device *adev)
  * Call from drm_gem_handle_create which appear in both new and open ioctl
  * case.
  */
-int amdgpu_gem_object_open(struct drm_gem_object *obj,
-  struct drm_file *file_priv)
+static int amdgpu_gem_object_open(struct drm_gem_object *obj,
+ struct drm_file *file_priv)
 {
struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj);
struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
@@ -152,8 +156,8 @@ int amdgpu_gem_object_open(struct drm_gem_object *obj,
return 0;
 }
 
-void amdgpu_gem_object_close(struct drm_gem_object *obj,
-struct drm_file *file_priv)
+static void amdgpu_gem_object_close(struct drm_gem_object *obj,
+   struct drm_file *file_priv)
 {
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
@@ -211,6 +215,15 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,
ttm_eu_backoff_reservation(, );
 }
 
+static const struct drm_gem_object_funcs amdgpu_gem_object_funcs = {
+   .free = amdgpu_gem_object_free,
+   .open = amdgpu_gem_object_open,
+   .close = amdgpu_gem_object_close,
+   .export = amdgpu_gem_prime_export,
+   .vmap = amdgpu_gem_prime_vmap,
+   .vunmap = amdgpu_gem_prime_vunmap,
+};
+
 /*
  * GEM ioctls.
  */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
index e0f025dd1b14..637bf51dbf06 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h
@@ -33,11 +33,6 @@
 #define AMDGPU_GEM_DOMAIN_MAX  0x3
 #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, tbo.base)
 
-void amdgpu_gem_object_free(struct drm_gem_object *obj);
-int amdgpu_gem_object_open(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
-void amdgpu_gem_object_close(struct drm_gem_object *obj,
-   struct drm_file *file_priv);
 unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
 
 /*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 

[PATCH v2 18/21] drm/vkms: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in vkms.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/vkms/vkms_drv.c |  8 
 drivers/gpu/drm/vkms/vkms_gem.c | 13 +
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index cb0b6230c22c..726801ab44d4 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -51,12 +51,6 @@ static const struct file_operations vkms_driver_fops = {
.release= drm_release,
 };
 
-static const struct vm_operations_struct vkms_gem_vm_ops = {
-   .fault = vkms_gem_fault,
-   .open = drm_gem_vm_open,
-   .close = drm_gem_vm_close,
-};
-
 static void vkms_release(struct drm_device *dev)
 {
struct vkms_device *vkms = container_of(dev, struct vkms_device, drm);
@@ -98,8 +92,6 @@ static struct drm_driver vkms_driver = {
.release= vkms_release,
.fops   = _driver_fops,
.dumb_create= vkms_dumb_create,
-   .gem_vm_ops = _gem_vm_ops,
-   .gem_free_object_unlocked = vkms_gem_free_object,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import_sg_table = vkms_prime_import_sg_table,
 
diff --git a/drivers/gpu/drm/vkms/vkms_gem.c b/drivers/gpu/drm/vkms/vkms_gem.c
index a017fc59905e..19a0e260a4df 100644
--- a/drivers/gpu/drm/vkms/vkms_gem.c
+++ b/drivers/gpu/drm/vkms/vkms_gem.c
@@ -7,6 +7,17 @@
 
 #include "vkms_drv.h"
 
+static const struct vm_operations_struct vkms_gem_vm_ops = {
+   .fault = vkms_gem_fault,
+   .open = drm_gem_vm_open,
+   .close = drm_gem_vm_close,
+};
+
+static const struct drm_gem_object_funcs vkms_gem_object_funcs = {
+   .free = vkms_gem_free_object,
+   .vm_ops = _gem_vm_ops,
+};
+
 static struct vkms_gem_object *__vkms_gem_create(struct drm_device *dev,
 u64 size)
 {
@@ -17,6 +28,8 @@ static struct vkms_gem_object *__vkms_gem_create(struct 
drm_device *dev,
if (!obj)
return ERR_PTR(-ENOMEM);
 
+   obj->gem.funcs = _gem_object_funcs;
+
size = roundup(size, PAGE_SIZE);
ret = drm_gem_object_init(dev, >gem, size);
if (ret) {
-- 
2.28.0




[PATCH v2 00/21] Convert all remaining drivers to GEM object functions

2020-09-15 Thread Thomas Zimmermann
The GEM and PRIME related callbacks in struct drm_driver are deprecated in
favor of GEM object functions in struct drm_gem_object_funcs. This patchset
converts the remaining drivers to object functions and removes most of the
obsolete interfaces.

Patches #1 to #16 and #18 to #19 convert DRM drivers to GEM object functions,
one by one. Each patch moves existing callbacks from struct drm_driver to an
instance of struct drm_gem_object_funcs, and sets these funcs when the GEM
object is initialized. The expection is .gem_prime_mmap. There are different
ways of how drivers implement the callback, and moving it to GEM object
functions requires a closer review for each.

Patch #17 fixes virtgpu to use GEM object functions where possible. The
driver recently introduced a function for one of the deprecated callbacks.

Patch #20 converts xlnx to CMA helper macros. There's no apparent reason
why the driver does the GEM setup on it's own. Using CMA helper macros
adds GEM object functions implicitly.

With most of the GEM and PRIME moved to GEM object functions, related code
in struct drm_driver and in the DRM core/helpers is being removed by patch
#21.

Further testing is welcome. I tested the drivers for which I have HW
available. These are gma500, i915, nouveau, radeon and vc4. The console,
Weston and Xorg apparently work with the patches applied.

v2:
* moved code in amdgpu and radeon
* made several functions static in various drivers
* updated TODO-list item
* fix virtgpu

Thomas Zimmermann (21):
  drm/amdgpu: Introduce GEM object functions
  drm/armada: Introduce GEM object functions
  drm/etnaviv: Introduce GEM object functions
  drm/exynos: Introduce GEM object functions
  drm/gma500: Introduce GEM object functions
  drm/i915: Introduce GEM object functions
  drm/mediatek: Introduce GEM object functions
  drm/msm: Introduce GEM object funcs
  drm/nouveau: Introduce GEM object functions
  drm/omapdrm: Introduce GEM object functions
  drm/pl111: Introduce GEM object functions
  drm/radeon: Introduce GEM object functions
  drm/rockchip: Convert to drm_gem_object_funcs
  drm/tegra: Introduce GEM object functions
  drm/vc4: Introduce GEM object functions
  drm/vgem: Introduce GEM object functions
  drm/virtgpu: Set PRIME export function in struct drm_gem_object_funcs
  drm/vkms: Introduce GEM object functions
  drm/xen: Introduce GEM object functions
  drm/xlnx: Initialize DRM driver instance with CMA helper macro
  drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver

 Documentation/gpu/todo.rst|  7 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   |  6 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c   | 23 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h   |  5 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c|  1 +
 drivers/gpu/drm/armada/armada_drv.c   |  3 -
 drivers/gpu/drm/armada/armada_gem.c   | 12 ++-
 drivers/gpu/drm/armada/armada_gem.h   |  2 -
 drivers/gpu/drm/drm_gem.c | 35 ++--
 drivers/gpu/drm/drm_gem_cma_helper.c  |  6 +-
 drivers/gpu/drm/drm_prime.c   | 17 ++--
 drivers/gpu/drm/etnaviv/etnaviv_drv.c | 13 ---
 drivers/gpu/drm/etnaviv/etnaviv_drv.h |  1 -
 drivers/gpu/drm/etnaviv/etnaviv_gem.c | 19 -
 drivers/gpu/drm/exynos/exynos_drm_drv.c   | 10 ---
 drivers/gpu/drm/exynos/exynos_drm_gem.c   | 15 
 drivers/gpu/drm/gma500/framebuffer.c  |  2 +
 drivers/gpu/drm/gma500/gem.c  | 18 +++-
 drivers/gpu/drm/gma500/gem.h  |  3 +
 drivers/gpu/drm/gma500/psb_drv.c  |  9 --
 drivers/gpu/drm/gma500/psb_drv.h  |  2 -
 drivers/gpu/drm/i915/gem/i915_gem_object.c| 21 -
 drivers/gpu/drm/i915/gem/i915_gem_object.h|  3 -
 drivers/gpu/drm/i915/i915_drv.c   |  4 -
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  3 -
 drivers/gpu/drm/mediatek/mtk_drm_drv.c|  5 --
 drivers/gpu/drm/mediatek/mtk_drm_gem.c| 11 +++
 drivers/gpu/drm/msm/msm_drv.c | 13 ---
 drivers/gpu/drm/msm/msm_drv.h |  1 -
 drivers/gpu/drm/msm/msm_gem.c | 19 -
 drivers/gpu/drm/nouveau/nouveau_drm.c |  9 --
 drivers/gpu/drm/nouveau/nouveau_gem.c | 13 +++
 drivers/gpu/drm/nouveau/nouveau_gem.h |  2 +
 drivers/gpu/drm/nouveau/nouveau_prime.c   |  2 +
 drivers/gpu/drm/omapdrm/omap_drv.c|  9 --
 drivers/gpu/drm/omapdrm/omap_gem.c| 18 +++-
 drivers/gpu/drm/omapdrm/omap_gem.h|  2 -
 drivers/gpu/drm/pl111/pl111_drv.c |  5 +-
 drivers/gpu/drm/radeon/radeon_drv.c   | 23 +
 drivers/gpu/drm/radeon/radeon_gem.c   | 31 ++-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c   |  5 --
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c   | 10 +++
 drivers/gpu/drm/tegra/drm.c   |  4 -
 drivers/gpu/drm/tegra/gem.c   |  8 ++
 

[PATCH v2 08/21] drm/msm: Introduce GEM object funcs

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in msm. The only exception is gem_prime_mmap,
which is non-trivial to convert.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/msm/msm_drv.c | 13 -
 drivers/gpu/drm/msm/msm_drv.h |  1 -
 drivers/gpu/drm/msm/msm_gem.c | 19 ++-
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 79333842f70a..5952767ea478 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -978,12 +978,6 @@ static const struct drm_ioctl_desc msm_ioctls[] = {
DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, 
DRM_RENDER_ALLOW),
 };
 
-static const struct vm_operations_struct vm_ops = {
-   .fault = msm_gem_fault,
-   .open = drm_gem_vm_open,
-   .close = drm_gem_vm_close,
-};
-
 static const struct file_operations fops = {
.owner  = THIS_MODULE,
.open   = drm_open,
@@ -1009,18 +1003,11 @@ static struct drm_driver msm_driver = {
.irq_preinstall = msm_irq_preinstall,
.irq_postinstall= msm_irq_postinstall,
.irq_uninstall  = msm_irq_uninstall,
-   .gem_free_object_unlocked = msm_gem_free_object,
-   .gem_vm_ops = _ops,
.dumb_create= msm_gem_dumb_create,
.dumb_map_offset= msm_gem_dumb_map_offset,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_pin  = msm_gem_prime_pin,
-   .gem_prime_unpin= msm_gem_prime_unpin,
-   .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
.gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
-   .gem_prime_vmap = msm_gem_prime_vmap,
-   .gem_prime_vunmap   = msm_gem_prime_vunmap,
.gem_prime_mmap = msm_gem_prime_mmap,
 #ifdef CONFIG_DEBUG_FS
.debugfs_init   = msm_debugfs_init,
diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
index af259b0573ea..7bcea10be81f 100644
--- a/drivers/gpu/drm/msm/msm_drv.h
+++ b/drivers/gpu/drm/msm/msm_drv.h
@@ -269,7 +269,6 @@ void msm_gem_shrinker_cleanup(struct drm_device *dev);
 int msm_gem_mmap_obj(struct drm_gem_object *obj,
struct vm_area_struct *vma);
 int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
-vm_fault_t msm_gem_fault(struct vm_fault *vmf);
 uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
 int msm_gem_get_iova(struct drm_gem_object *obj,
struct msm_gem_address_space *aspace, uint64_t *iova);
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index b4553caaa196..de915ff6f4b4 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -247,7 +247,7 @@ int msm_gem_mmap(struct file *filp, struct vm_area_struct 
*vma)
return msm_gem_mmap_obj(vma->vm_private_data, vma);
 }
 
-vm_fault_t msm_gem_fault(struct vm_fault *vmf)
+static vm_fault_t msm_gem_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct drm_gem_object *obj = vma->vm_private_data;
@@ -994,6 +994,22 @@ int msm_gem_new_handle(struct drm_device *dev, struct 
drm_file *file,
return ret;
 }
 
+static const struct vm_operations_struct vm_ops = {
+   .fault = msm_gem_fault,
+   .open = drm_gem_vm_open,
+   .close = drm_gem_vm_close,
+};
+
+static const struct drm_gem_object_funcs msm_gem_object_funcs = {
+   .free = msm_gem_free_object,
+   .pin = msm_gem_prime_pin,
+   .unpin = msm_gem_prime_unpin,
+   .get_sg_table = msm_gem_prime_get_sg_table,
+   .vmap = msm_gem_prime_vmap,
+   .vunmap = msm_gem_prime_vunmap,
+   .vm_ops = _ops,
+};
+
 static int msm_gem_new_impl(struct drm_device *dev,
uint32_t size, uint32_t flags,
struct drm_gem_object **obj)
@@ -1024,6 +1040,7 @@ static int msm_gem_new_impl(struct drm_device *dev,
INIT_LIST_HEAD(_obj->vmas);
 
*obj = _obj->base;
+   (*obj)->funcs = _gem_object_funcs;
 
return 0;
 }
-- 
2.28.0




[PATCH v2 04/21] drm/exynos: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in exynos. The only exception is gem_prime_mmap,
which is non-trivial to convert.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/exynos/exynos_drm_drv.c | 10 --
 drivers/gpu/drm/exynos/exynos_drm_gem.c | 15 +++
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c 
b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index dbd80f1e4c78..fe46680ca208 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -75,11 +75,6 @@ static void exynos_drm_postclose(struct drm_device *dev, 
struct drm_file *file)
file->driver_priv = NULL;
 }
 
-static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
-   .open = drm_gem_vm_open,
-   .close = drm_gem_vm_close,
-};
-
 static const struct drm_ioctl_desc exynos_ioctls[] = {
DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
DRM_RENDER_ALLOW),
@@ -124,16 +119,11 @@ static struct drm_driver exynos_drm_driver = {
.open   = exynos_drm_open,
.lastclose  = drm_fb_helper_lastclose,
.postclose  = exynos_drm_postclose,
-   .gem_free_object_unlocked = exynos_drm_gem_free_object,
-   .gem_vm_ops = _drm_gem_vm_ops,
.dumb_create= exynos_drm_gem_dumb_create,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import   = exynos_drm_gem_prime_import,
-   .gem_prime_get_sg_table = exynos_drm_gem_prime_get_sg_table,
.gem_prime_import_sg_table  = exynos_drm_gem_prime_import_sg_table,
-   .gem_prime_vmap = exynos_drm_gem_prime_vmap,
-   .gem_prime_vunmap   = exynos_drm_gem_prime_vunmap,
.gem_prime_mmap = exynos_drm_gem_prime_mmap,
.ioctls = exynos_ioctls,
.num_ioctls = ARRAY_SIZE(exynos_ioctls),
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c 
b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index efa476858db5..69a5cf28b4ae 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -129,6 +129,19 @@ void exynos_drm_gem_destroy(struct exynos_drm_gem 
*exynos_gem)
kfree(exynos_gem);
 }
 
+static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
+   .open = drm_gem_vm_open,
+   .close = drm_gem_vm_close,
+};
+
+static const struct drm_gem_object_funcs exynos_drm_gem_object_funcs = {
+   .free = exynos_drm_gem_free_object,
+   .get_sg_table = exynos_drm_gem_prime_get_sg_table,
+   .vmap = exynos_drm_gem_prime_vmap,
+   .vunmap = exynos_drm_gem_prime_vunmap,
+   .vm_ops = _drm_gem_vm_ops,
+};
+
 static struct exynos_drm_gem *exynos_drm_gem_init(struct drm_device *dev,
  unsigned long size)
 {
@@ -143,6 +156,8 @@ static struct exynos_drm_gem *exynos_drm_gem_init(struct 
drm_device *dev,
exynos_gem->size = size;
obj = _gem->base;
 
+   obj->funcs = _drm_gem_object_funcs;
+
ret = drm_gem_object_init(dev, obj, size);
if (ret < 0) {
DRM_DEV_ERROR(dev->dev, "failed to initialize gem object\n");
-- 
2.28.0




[PATCH v2 03/21] drm/etnaviv: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in etnaviv. The only exception is gem_prime_mmap,
which is non-trivial to convert.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/etnaviv/etnaviv_drv.c | 13 -
 drivers/gpu/drm/etnaviv/etnaviv_drv.h |  1 -
 drivers/gpu/drm/etnaviv/etnaviv_gem.c | 19 ++-
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c 
b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
index a9a3afaef9a1..aa270b79e585 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
@@ -468,12 +468,6 @@ static const struct drm_ioctl_desc etnaviv_ioctls[] = {
ETNA_IOCTL(PM_QUERY_SIG, pm_query_sig, DRM_RENDER_ALLOW),
 };
 
-static const struct vm_operations_struct vm_ops = {
-   .fault = etnaviv_gem_fault,
-   .open = drm_gem_vm_open,
-   .close = drm_gem_vm_close,
-};
-
 static const struct file_operations fops = {
.owner  = THIS_MODULE,
.open   = drm_open,
@@ -490,16 +484,9 @@ static struct drm_driver etnaviv_drm_driver = {
.driver_features= DRIVER_GEM | DRIVER_RENDER,
.open   = etnaviv_open,
.postclose   = etnaviv_postclose,
-   .gem_free_object_unlocked = etnaviv_gem_free_object,
-   .gem_vm_ops = _ops,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_pin  = etnaviv_gem_prime_pin,
-   .gem_prime_unpin= etnaviv_gem_prime_unpin,
-   .gem_prime_get_sg_table = etnaviv_gem_prime_get_sg_table,
.gem_prime_import_sg_table = etnaviv_gem_prime_import_sg_table,
-   .gem_prime_vmap = etnaviv_gem_prime_vmap,
-   .gem_prime_vunmap   = etnaviv_gem_prime_vunmap,
.gem_prime_mmap = etnaviv_gem_prime_mmap,
 #ifdef CONFIG_DEBUG_FS
.debugfs_init   = etnaviv_debugfs_init,
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h 
b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
index 4d8dc9236e5f..914f0867ff71 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h
+++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
@@ -49,7 +49,6 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void 
*data,
struct drm_file *file);
 
 int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
-vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf);
 int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
 struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
 void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c 
b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
index ea19f1d27275..312e9d58d5a7 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
@@ -171,7 +171,7 @@ int etnaviv_gem_mmap(struct file *filp, struct 
vm_area_struct *vma)
return obj->ops->mmap(obj, vma);
 }
 
-vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf)
+static vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct drm_gem_object *obj = vma->vm_private_data;
@@ -561,6 +561,22 @@ void etnaviv_gem_obj_add(struct drm_device *dev, struct 
drm_gem_object *obj)
mutex_unlock(>gem_lock);
 }
 
+static const struct vm_operations_struct vm_ops = {
+   .fault = etnaviv_gem_fault,
+   .open = drm_gem_vm_open,
+   .close = drm_gem_vm_close,
+};
+
+static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = {
+   .free = etnaviv_gem_free_object,
+   .pin = etnaviv_gem_prime_pin,
+   .unpin = etnaviv_gem_prime_unpin,
+   .get_sg_table = etnaviv_gem_prime_get_sg_table,
+   .vmap = etnaviv_gem_prime_vmap,
+   .vunmap = etnaviv_gem_prime_vunmap,
+   .vm_ops = _ops,
+};
+
 static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags,
const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj)
 {
@@ -595,6 +611,7 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 
size, u32 flags,
INIT_LIST_HEAD(_obj->vram_list);
 
*obj = _obj->base;
+   (*obj)->funcs = _gem_object_funcs;
 
return 0;
 }
-- 
2.28.0




[PATCH v2 09/21] drm/nouveau: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in nouveau.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/nouveau/nouveau_drm.c   |  9 -
 drivers/gpu/drm/nouveau/nouveau_gem.c   | 13 +
 drivers/gpu/drm/nouveau/nouveau_gem.h   |  2 ++
 drivers/gpu/drm/nouveau/nouveau_prime.c |  2 ++
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c 
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 42fc5c813a9b..72640bca1617 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -1207,16 +1207,7 @@ driver_stub = {
 
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
-   .gem_prime_pin = nouveau_gem_prime_pin,
-   .gem_prime_unpin = nouveau_gem_prime_unpin,
-   .gem_prime_get_sg_table = nouveau_gem_prime_get_sg_table,
.gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table,
-   .gem_prime_vmap = nouveau_gem_prime_vmap,
-   .gem_prime_vunmap = nouveau_gem_prime_vunmap,
-
-   .gem_free_object_unlocked = nouveau_gem_object_del,
-   .gem_open_object = nouveau_gem_object_open,
-   .gem_close_object = nouveau_gem_object_close,
 
.dumb_create = nouveau_display_dumb_create,
.dumb_map_offset = nouveau_display_dumb_map_offset,
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c 
b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 89adadf4706b..28e0cbb00876 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -169,6 +169,17 @@ nouveau_gem_object_close(struct drm_gem_object *gem, 
struct drm_file *file_priv)
ttm_bo_unreserve(>bo);
 }
 
+const struct drm_gem_object_funcs nouveau_gem_object_funcs = {
+   .free = nouveau_gem_object_del,
+   .open = nouveau_gem_object_open,
+   .close = nouveau_gem_object_close,
+   .pin = nouveau_gem_prime_pin,
+   .unpin = nouveau_gem_prime_unpin,
+   .get_sg_table = nouveau_gem_prime_get_sg_table,
+   .vmap = nouveau_gem_prime_vmap,
+   .vunmap = nouveau_gem_prime_vunmap,
+};
+
 int
 nouveau_gem_new(struct nouveau_cli *cli, u64 size, int align, uint32_t domain,
uint32_t tile_mode, uint32_t tile_flags,
@@ -186,6 +197,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int 
align, uint32_t domain,
if (IS_ERR(nvbo))
return PTR_ERR(nvbo);
 
+   nvbo->bo.base.funcs = _gem_object_funcs;
+
/* Initialize the embedded gem-object. We return a single gem-reference
 * to the caller, instead of a normal nouveau_bo ttm reference. */
ret = drm_gem_object_init(drm->dev, >bo.base, size);
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.h 
b/drivers/gpu/drm/nouveau/nouveau_gem.h
index 978e07591990..b35c180322e2 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.h
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.h
@@ -5,6 +5,8 @@
 #include "nouveau_drv.h"
 #include "nouveau_bo.h"
 
+extern const struct drm_gem_object_funcs nouveau_gem_object_funcs;
+
 static inline struct nouveau_bo *
 nouveau_gem_object(struct drm_gem_object *gem)
 {
diff --git a/drivers/gpu/drm/nouveau/nouveau_prime.c 
b/drivers/gpu/drm/nouveau/nouveau_prime.c
index b2ecb91f8ddc..a8264aebf3d4 100644
--- a/drivers/gpu/drm/nouveau/nouveau_prime.c
+++ b/drivers/gpu/drm/nouveau/nouveau_prime.c
@@ -77,6 +77,8 @@ struct drm_gem_object 
*nouveau_gem_prime_import_sg_table(struct drm_device *dev,
 
nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_GART;
 
+   nvbo->bo.base.funcs = _gem_object_funcs;
+
/* Initialize the embedded gem-object. We return a single gem-reference
 * to the caller, instead of a normal nouveau_bo ttm reference. */
ret = drm_gem_object_init(dev, >bo.base, size);
-- 
2.28.0




[PATCH v2 05/21] drm/gma500: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
GEM object functions deprecate several similar callback interfaces in
struct drm_driver. This patch replaces the per-driver callbacks with
per-instance callbacks in gma500.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/gma500/framebuffer.c |  2 ++
 drivers/gpu/drm/gma500/gem.c | 18 --
 drivers/gpu/drm/gma500/gem.h |  3 +++
 drivers/gpu/drm/gma500/psb_drv.c |  9 -
 drivers/gpu/drm/gma500/psb_drv.h |  2 --
 5 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/gma500/framebuffer.c 
b/drivers/gpu/drm/gma500/framebuffer.c
index 54d9876b5305..5ede24fb44ae 100644
--- a/drivers/gpu/drm/gma500/framebuffer.c
+++ b/drivers/gpu/drm/gma500/framebuffer.c
@@ -24,6 +24,7 @@
 #include 
 
 #include "framebuffer.h"
+#include "gem.h"
 #include "gtt.h"
 #include "psb_drv.h"
 #include "psb_intel_drv.h"
@@ -285,6 +286,7 @@ static struct gtt_range *psbfb_alloc(struct drm_device 
*dev, int aligned_size)
/* Begin by trying to use stolen memory backing */
backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1, PAGE_SIZE);
if (backing) {
+   backing->gem.funcs = _gem_object_funcs;
drm_gem_private_object_init(dev, >gem, aligned_size);
return backing;
}
diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
index f9c4b1d76f56..8f07de83b6fb 100644
--- a/drivers/gpu/drm/gma500/gem.c
+++ b/drivers/gpu/drm/gma500/gem.c
@@ -18,7 +18,9 @@
 
 #include "psb_drv.h"
 
-void psb_gem_free_object(struct drm_gem_object *obj)
+static vm_fault_t psb_gem_fault(struct vm_fault *vmf);
+
+static void psb_gem_free_object(struct drm_gem_object *obj)
 {
struct gtt_range *gtt = container_of(obj, struct gtt_range, gem);
 
@@ -36,6 +38,17 @@ int psb_gem_get_aperture(struct drm_device *dev, void *data,
return -EINVAL;
 }
 
+static const struct vm_operations_struct psb_gem_vm_ops = {
+   .fault = psb_gem_fault,
+   .open = drm_gem_vm_open,
+   .close = drm_gem_vm_close,
+};
+
+const struct drm_gem_object_funcs psb_gem_object_funcs = {
+   .free = psb_gem_free_object,
+   .vm_ops = _gem_vm_ops,
+};
+
 /**
  * psb_gem_create  -   create a mappable object
  * @file: the DRM file of the client
@@ -63,6 +76,7 @@ int psb_gem_create(struct drm_file *file, struct drm_device 
*dev, u64 size,
dev_err(dev->dev, "no memory for %lld byte GEM object\n", size);
return -ENOSPC;
}
+   r->gem.funcs = _gem_object_funcs;
/* Initialize the extra goodies GEM needs to do all the hard work */
if (drm_gem_object_init(dev, >gem, size) != 0) {
psb_gtt_free_range(dev, r);
@@ -123,7 +137,7 @@ int psb_gem_dumb_create(struct drm_file *file, struct 
drm_device *dev,
  * vma->vm_private_data points to the GEM object that is backing this
  * mapping.
  */
-vm_fault_t psb_gem_fault(struct vm_fault *vmf)
+static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
 {
struct vm_area_struct *vma = vmf->vma;
struct drm_gem_object *obj;
diff --git a/drivers/gpu/drm/gma500/gem.h b/drivers/gpu/drm/gma500/gem.h
index 4a74dc623b6b..3741a711b9fd 100644
--- a/drivers/gpu/drm/gma500/gem.h
+++ b/drivers/gpu/drm/gma500/gem.h
@@ -8,6 +8,9 @@
 #ifndef _GEM_H
 #define _GEM_H
 
+extern const struct drm_gem_object_funcs psb_gem_object_funcs;
+
 extern int psb_gem_create(struct drm_file *file, struct drm_device *dev,
  u64 size, u32 *handlep, int stolen, u32 align);
+
 #endif
diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
index 34b4aae9a15e..b13376a6fb91 100644
--- a/drivers/gpu/drm/gma500/psb_drv.c
+++ b/drivers/gpu/drm/gma500/psb_drv.c
@@ -480,12 +480,6 @@ static const struct dev_pm_ops psb_pm_ops = {
.runtime_idle = psb_runtime_idle,
 };
 
-static const struct vm_operations_struct psb_gem_vm_ops = {
-   .fault = psb_gem_fault,
-   .open = drm_gem_vm_open,
-   .close = drm_gem_vm_close,
-};
-
 static const struct file_operations psb_gem_fops = {
.owner = THIS_MODULE,
.open = drm_open,
@@ -507,9 +501,6 @@ static struct drm_driver driver = {
.irq_uninstall = psb_irq_uninstall,
.irq_handler = psb_irq_handler,
 
-   .gem_free_object_unlocked = psb_gem_free_object,
-   .gem_vm_ops = _gem_vm_ops,
-
.dumb_create = psb_gem_dumb_create,
.ioctls = psb_ioctls,
.fops = _gem_fops,
diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
index 956926341316..c71a5a4e912c 100644
--- a/drivers/gpu/drm/gma500/psb_drv.h
+++ b/drivers/gpu/drm/gma500/psb_drv.h
@@ -735,12 +735,10 @@ extern const struct drm_connector_helper_funcs
 extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs;
 
 /* gem.c */
-extern void psb_gem_free_object(struct drm_gem_object *obj);
 extern int psb_gem_get_aperture(struct drm_device *dev, void *data,

Re: [PATCH 2/3] x86/shim: adjust Kconfig defaults

2020-09-15 Thread Roger Pau Monné
On Mon, Sep 14, 2020 at 02:39:08PM +0200, Jan Beulich wrote:
> Just like HVM, defaulting SHADOW_PAGING and TBOOT to Yes in shim-
> exclusive mode makes no sense, as the respective code is dead there.
> 
> Also adjust the shim default config file: It needs to specifiy values
> only for settings where a non-default value is wanted.
> 
> Signed-off-by: Jan Beulich 

Reviewed-by: Roger Pau Monné 

> 
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -116,9 +116,9 @@ config XEN_SHSTK
> compatiblity can be provided via the PV Shim mechanism.
>  
>  config SHADOW_PAGING
> -bool "Shadow Paging"
> -default y
> ----help---
> + bool "Shadow Paging"
> + default y if !PV_SHIM_EXCLUSIVE

I think you could also do: default !PV_SHIM_EXCLUSIVE?

I'm fine with using the current form.

Thanks, Roger.



RE: [PATCH v2 1/2] libxl: provide a mechanism to define a device 'safe remove' function...

2020-09-15 Thread Durrant, Paul
> -Original Message-
> From: Roger Pau Monné 
> Sent: 15 September 2020 15:32
> To: Paul Durrant 
> Cc: xen-devel@lists.xenproject.org; Durrant, Paul ; 
> Ian Jackson
> ; Wei Liu ; Anthony PERARD 
> 
> Subject: RE: [EXTERNAL] [PATCH v2 1/2] libxl: provide a mechanism to define a 
> device 'safe remove'
> function...
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open
> attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> On Tue, Sep 15, 2020 at 03:10:06PM +0100, Paul Durrant wrote:
> > From: Paul Durrant 
> >
> > ... and use it to define libxl_device_disk_safe_remove().
> >
> > This patch builds on the existent macro magic by using a new value of the
> > 'force' field in in libxl__ao_device.
> > It is currently defined as an int but is used in a boolean manner where
> > 1 means the operation is forced and 0 means it is not (but is actually 
> > forced
> > after a 10s time-out). In adding a third value, this patch re-defines 
> > 'force'
> > as a struct type (libxl__force) with a single 'flag' field taking an
> > enumerated value:
> >
> > LIBXL__FORCE_AUTO - corresponding to the old 0 value
> > LIBXL__FORCE_ON   - corresponding to the old 1 value
> > LIBXL__FORCE_OFF  - the new value
> >
> > The LIBXL_DEFINE_DEVICE_REMOVE() macro is then modified to define the
> > libxl_device__remove() and libxl_device__destroy() functions,
> > setting LIBXL__FORCE_AUTO and LIBXL__FORCE_ON (respectively) in the
> > libxl__ao_device passed to libxl__initiate_device_generic_remove() and a
> > new macro, LIBXL_DEFINE_DEVICE_SAFE_REMOVE(), is defined that sets
> > LIBXL__FORCE_OFF instead. This macro is used to define the new
> > libxl_device_disk_safe_remove() function.
> >
> > Signed-off-by: Paul Durrant 
> 
> Reviewed-by: Roger Pau Monné 
> 

Thanks.

> Just one nit.
> 
> > diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> > index e16ae9630b..1fcf85c3e2 100644
> > --- a/tools/libxl/libxl_internal.h
> > +++ b/tools/libxl/libxl_internal.h
> > @@ -2730,12 +2730,20 @@ _hidden void libxl__prepare_ao_device(libxl__ao 
> > *ao, libxl__ao_device
> *aodev);
> >  /* generic callback for devices that only need to set ao_complete */
> >  _hidden void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device 
> > *aodev);
> >
> > +typedef struct {
> > +enum {
> > +LIBXL__FORCE_AUTO, /* Re-execute with FORCE_ON if op times out */
> > +LIBXL__FORCE_ON,
> > +LIBXL__FORCE_OFF,
> > +} flag;
> > +} libxl__force;
> 
> Couldn't you just use the typedef against the union directly instead
> of wrapping it around a struct?

You mean s/union/enum?

I could have done that, but it helped find all the places where aodev->force is 
used and I liked the abstraction. I don't mind changing if there are strong 
opinions against it.

  Paul

> 
> Thanks, Roger.


RE: [PATCH v7 7/9] common/domain: add a domain context record for shared_info...

2020-09-15 Thread Durrant, Paul
> -Original Message-
> From: Paul Durrant 
> Sent: 04 September 2020 18:30
> To: 'Jan Beulich' 
> Cc: xen-devel@lists.xenproject.org; Durrant, Paul ; 
> 'Ian Jackson'
> ; 'Wei Liu' ; 'Andrew Cooper' 
> ;
> 'George Dunlap' ; 'Julien Grall' ; 
> 'Stefano Stabellini'
> 
> Subject: RE: [EXTERNAL] [PATCH v7 7/9] common/domain: add a domain context 
> record for shared_info...
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open
> attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> > -Original Message-
> > From: Jan Beulich 
> > Sent: 26 August 2020 14:58
> > To: Paul Durrant 
> > Cc: xen-devel@lists.xenproject.org; Paul Durrant ; Ian 
> > Jackson
> > ; Wei Liu ; Andrew Cooper 
> > ; George
> > Dunlap ; Julien Grall ; Stefano 
> > Stabellini
> > 
> > Subject: Re: [PATCH v7 7/9] common/domain: add a domain context record for 
> > shared_info...
> >
> > On 18.08.2020 12:30, Paul Durrant wrote:
> > > v7:
> > >  - Only restore vcpu_info and arch sub-structures for PV domains, to match
> > >processing of SHARED_INFO in xc_sr_restore_x86_pv.c
> >
> > Since you point out this original logic, ...
> >
> > > +static int load_shared_info(struct domain *d, struct domain_context *c)
> > > +{
> > > +struct domain_shared_info_context ctxt;
> > > +size_t hdr_size = offsetof(typeof(ctxt), buffer);
> > > +unsigned int i;
> > > +int rc;
> > > +
> > > +rc = DOMAIN_LOAD_BEGIN(SHARED_INFO, c, );
> > > +if ( rc )
> > > +return rc;
> > > +
> > > +if ( i ) /* expect only a single instance */
> > > +return -ENXIO;
> > > +
> > > +rc = domain_load_data(c, , hdr_size);
> > > +if ( rc )
> > > +return rc;
> > > +
> > > +if ( ctxt.buffer_size > sizeof(shared_info_t) ||
> > > + (ctxt.flags & ~DOMAIN_SAVE_32BIT_SHINFO) )
> > > +return -EINVAL;
> > > +
> > > +if ( ctxt.flags & DOMAIN_SAVE_32BIT_SHINFO )
> > > +{
> > > +#ifdef CONFIG_COMPAT
> > > +has_32bit_shinfo(d) = true;
> > > +#else
> > > +return -EINVAL;
> > > +#endif
> > > +}
> > > +
> > > +if ( is_pv_domain(d) )
> > > +{
> > > +shared_info_t *shinfo = xmalloc(shared_info_t);
> > > +
> > > +rc = domain_load_data(c, shinfo, sizeof(*shinfo));
> > > +if ( rc )
> > > +{
> > > +xfree(shinfo);
> > > +return rc;
> > > +}
> > > +
> > > +#ifdef CONFIG_COMPAT
> > > +if ( has_32bit_shinfo(d) )
> > > +{
> > > +memcpy(>shared_info->compat.vcpu_info,
> > > +   >compat.vcpu_info,
> > > +   sizeof(d->shared_info->compat.vcpu_info));
> > > +memcpy(>shared_info->compat.arch,
> > > +   >compat.arch,
> > > +   sizeof(d->shared_info->compat.vcpu_info));
> > > +}
> > > +else
> > > +{
> > > +memcpy(>shared_info->native.vcpu_info,
> > > +   >native.vcpu_info,
> > > +   sizeof(d->shared_info->native.vcpu_info));
> > > +memcpy(>shared_info->native.arch,
> > > +   >native.arch,
> > > +   sizeof(d->shared_info->native.arch));
> > > +}
> > > +#else
> > > +memcpy(>shared_info->vcpu_info,
> > > +   >vcpu_info,
> > > +   sizeof(d->shared_info->vcpu_info));
> > > +memcpy(>shared_info->arch,
> > > +   >arch,
> > > +   sizeof(d->shared_info->shared));
> > > +#endif
> >
> > ... where does the rest of that logic (resetting of
> > arch.pfn_to_mfn_frame_list_list, evtchn_pending, evtchn_mask, and
> > evtchn_pending_sel) get done? Or why is it not needed anymore?
> 
> The resetting logic is still in xc_sr_restore_x86_pv.c (see patch #6). It's 
> going to need to stay
> there anyway to deal with older streams so I made it common to both cases; it 
> seems slightly separate
> from restoring the shared info.
> 

Actually I've changed my mind on this one; I'll do the zeroing here and leave 
the old SHARED_INFO record restore code alone.

  Paul

>   Paul
> 
> >
> > Jan



[PATCH v2 1/2] libxl: provide a mechanism to define a device 'safe remove' function...

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

... and use it to define libxl_device_disk_safe_remove().

This patch builds on the existent macro magic by using a new value of the
'force' field in in libxl__ao_device.
It is currently defined as an int but is used in a boolean manner where
1 means the operation is forced and 0 means it is not (but is actually forced
after a 10s time-out). In adding a third value, this patch re-defines 'force'
as a struct type (libxl__force) with a single 'flag' field taking an
enumerated value:

LIBXL__FORCE_AUTO - corresponding to the old 0 value
LIBXL__FORCE_ON   - corresponding to the old 1 value
LIBXL__FORCE_OFF  - the new value

The LIBXL_DEFINE_DEVICE_REMOVE() macro is then modified to define the
libxl_device__remove() and libxl_device__destroy() functions,
setting LIBXL__FORCE_AUTO and LIBXL__FORCE_ON (respectively) in the
libxl__ao_device passed to libxl__initiate_device_generic_remove() and a
new macro, LIBXL_DEFINE_DEVICE_SAFE_REMOVE(), is defined that sets
LIBXL__FORCE_OFF instead. This macro is used to define the new
libxl_device_disk_safe_remove() function.

Signed-off-by: Paul Durrant 
---
Cc: Ian Jackson 
Cc: Wei Liu 
Cc: Anthony PERARD 

v2:
 - New in v2
---
 tools/libxl/libxl.h  | 33 +
 tools/libxl/libxl_device.c   |  9 +
 tools/libxl/libxl_disk.c |  4 +++-
 tools/libxl/libxl_domain.c   |  2 +-
 tools/libxl/libxl_internal.h | 30 +++---
 5 files changed, 57 insertions(+), 21 deletions(-)

diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 1cd6c38e83..1ea5b4f446 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -438,6 +438,12 @@
  */
 #define LIBXL_HAVE_CREATEINFO_PASSTHROUGH 1
 
+/*
+ * LIBXL_HAVE_DISK_SAFE_REMOVE indicates that the
+ * libxl_device_disk_safe_remove() function is defined.
+ */
+#define LIBXL_HAVE_DISK_SAFE_REMOVE 1
+
 /*
  * libxl ABI compatibility
  *
@@ -1936,6 +1942,15 @@ void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int 
nr_vcpus);
  *   structure is passed in are filled in with appropriate values for
  *   the device created.
  *
+ * libxl_device__destroy(ctx, domid, device):
+ *
+ *   Removes the given device from the specified domain without guest
+ *   co-operation. It is guest specific what affect this will have on
+ *   a running guest.
+ *
+ *   This function does not interact with the guest and therefore
+ *   cannot block on the guest.
+ *
  * libxl_device__remove(ctx, domid, device):
  *
  *   Removes the given device from the specified domain by performing
@@ -1943,16 +1958,14 @@ void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int 
nr_vcpus);
  *   guest is running.
  *
  *   This method is currently synchronous and therefore can block
- *   while interacting with the guest.
- *
- * libxl_device__destroy(ctx, domid, device):
+ *   while interacting with the guest. There is a time-out of 10s on
+ *   this interaction after which libxl_device__destroy()
+ *   semantics apply.
  *
- *   Removes the given device from the specified domain without guest
- *   co-operation. It is guest specific what affect this will have on
- *   a running guest.
+ * libxl_device__safe_remove(ctx, domid, device):
  *
- *   This function does not interact with the guest and therefore
- *   cannot block on the guest.
+ *   This has the same semantics as libxl_device__remove() but,
+ *   in the event of hitting the 10s time-out, this function will fail.
  *
  * Controllers
  * ---
@@ -2033,6 +2046,10 @@ int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t 
domid,
   libxl_device_disk *disk,
   const libxl_asyncop_how *ao_how)
   LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_disk_safe_remove(libxl_ctx *ctx, uint32_t domid,
+  libxl_device_disk *disk,
+  const libxl_asyncop_how *ao_how)
+  LIBXL_EXTERNAL_CALLERS_ONLY;
 
 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx,
   uint32_t domid, int *num)
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 0381c5d509..e081faf9a9 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -973,7 +973,7 @@ void libxl__initiate_device_generic_remove(libxl__egc *egc,
 goto out;
 }
 
-if (aodev->force)
+if (aodev->force.flag == LIBXL__FORCE_ON)
 libxl__xs_path_cleanup(gc, t,
libxl__device_frontend_path(gc, 
aodev->dev));
 
@@ -1092,9 +1092,9 @@ static void device_backend_callback(libxl__egc *egc, 
libxl__ev_devstate *ds,
 
 if (rc == ERROR_TIMEDOUT &&
 aodev->action == LIBXL__DEVICE_ACTION_REMOVE &&
-!aodev->force) {
+aodev->force.flag == LIBXL__FORCE_AUTO) {
 LOGD(DEBUG, aodev->dev->domid, "Timeout reached, initiating forced 
remove");
-

[PATCH v2 0/2] fix 'xl block-detach'

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

This series makes it behave as the documentation states it should

Paul Durrant (2):
  libxl: provide a mechanism to define a device 'safe remove'
function...
  xl: implement documented '--force' option for block-detach

 docs/man/xl.1.pod.in |  4 ++--
 tools/libxl/libxl.h  | 33 +
 tools/libxl/libxl_device.c   |  9 +
 tools/libxl/libxl_disk.c |  4 +++-
 tools/libxl/libxl_domain.c   |  2 +-
 tools/libxl/libxl_internal.h | 30 +++---
 tools/xl/xl_block.c  | 21 -
 tools/xl/xl_cmdtable.c   |  3 ++-
 8 files changed, 77 insertions(+), 29 deletions(-)

-- 
2.20.1




[PATCH v2 2/2] xl: implement documented '--force' option for block-detach

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

The manpage for 'xl' documents an option to force a block device to be
released even if the domain to which it is attached does not co-operate.
The documentation also states that, if the force flag is not specified, the
block-detach operation should fail.

Currently the force option is not implemented and a non-forced block-detach
will auto-force after a time-out of 10s. This patch implements the force
option and also stops auto-forcing a non-forced block-detach by calling
libxl_device_disk_safe_remove() rather than libxl_device_disk_remove(),
allowing the operation to fail cleanly as per the documented behaviour.

NOTE: The documentation is also adjusted since the normal positioning of
  options is before compulsory parameters. It is also noted that use of
  the --force option may lead to a guest crash.

Signed-off-by: Paul Durrant 
Acked-by: Wei Liu 
---
Cc: Ian Jackson 
Cc: Anthony PERARD 

v2:
 - Add missing '.'
 - Use the new libxl_device_disk_safe_remove() function
 - Keep Wei's A-b as the modifications are trivial
---
 docs/man/xl.1.pod.in   |  4 ++--
 tools/xl/xl_block.c| 21 -
 tools/xl/xl_cmdtable.c |  3 ++-
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in
index 52a47a6fbd..5f7d3a7134 100644
--- a/docs/man/xl.1.pod.in
+++ b/docs/man/xl.1.pod.in
@@ -1389,7 +1389,7 @@ Note that only PV block devices are supported by 
block-attach.
 Requests to attach emulated devices (eg, vdev=hdc) will result in only
 the PV view being available to the guest.
 
-=item B I I [I]
+=item B [I] I I
 
 Detach a domain's virtual block device. I may be the symbolic
 name or the numeric device id given to the device by domain 0.  You
@@ -1406,7 +1406,7 @@ B
 =item B<--force>
 
 If this parameter is specified the device will be forcefully detached, which
-may cause IO errors in the domain.
+may cause IO errors in the domain and possibly a guest crash
 
 =back
 
diff --git a/tools/xl/xl_block.c b/tools/xl/xl_block.c
index acaf9b96b8..70eed431e4 100644
--- a/tools/xl/xl_block.c
+++ b/tools/xl/xl_block.c
@@ -96,12 +96,21 @@ int main_blocklist(int argc, char **argv)
 
 int main_blockdetach(int argc, char **argv)
 {
+static struct option opts[] = {
+{"force", 0, 0, 'f'},
+COMMON_LONG_OPTS
+};
 uint32_t domid;
 int opt, rc = 0;
 libxl_device_disk disk;
-
-SWITCH_FOREACH_OPT(opt, "", NULL, "block-detach", 2) {
-/* No options */
+bool force = false;
+
+SWITCH_FOREACH_OPT(opt, "f", opts, "block-detach", 2) {
+case 'f':
+force = true;
+break;
+default:
+break;
 }
 
 domid = find_domain(argv[optind]);
@@ -110,9 +119,11 @@ int main_blockdetach(int argc, char **argv)
 fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]);
 return 1;
 }
-rc = libxl_device_disk_remove(ctx, domid, , 0);
+rc = !force ? libxl_device_disk_safe_remove(ctx, domid, , 0) :
+libxl_device_disk_destroy(ctx, domid, , 0);
 if (rc) {
-fprintf(stderr, "libxl_device_disk_remove failed.\n");
+fprintf(stderr, "libxl_device_disk_%s failed.\n",
+!force ? "safe_remove" : "destroy");
 return 1;
 }
 libxl_device_disk_dispose();
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 2b8e1b321a..7da6c1b927 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -368,7 +368,8 @@ struct cmd_spec cmd_table[] = {
 { "block-detach",
   _blockdetach, 0, 1,
   "Destroy a domain's virtual block device",
-  " ",
+  "[option]  ",
+  "-f, --forcedo not wait for the domain to release the device"
 },
 { "vtpm-attach",
   _vtpmattach, 1, 1,
-- 
2.20.1




[xen-unstable-smoke test] 154357: tolerable all pass - PUSHED

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

Failures :-/ but no regressions.

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-libvirt 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-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

version targeted for testing:
 xen  39ab598c50a2b539f376adc363d684c2df6c8dd7
baseline version:
 xen  fc4e79c3f77f4360064f3614e32557a105458bae

Last test of basis   154341  2020-09-14 16:00:26 Z0 days
Testing same since   154357  2020-09-15 09:01:19 Z0 days1 attempts


People who touched revisions under test:
  Don Slutz 
  Jan Beulich 
  Roger Pau Monné 

jobs:
 build-arm64-xsm  pass
 build-amd64  pass
 build-armhf  pass
 build-amd64-libvirt  pass
 test-armhf-armhf-xl  pass
 test-arm64-arm64-xl-xsm  pass
 test-amd64-amd64-xl-qemuu-debianhvm-amd64pass
 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 :

To xenbits.xen.org:/home/xen/git/xen.git
   fc4e79c3f7..39ab598c50  39ab598c50a2b539f376adc363d684c2df6c8dd7 -> smoke



Re: [PATCH 1/9] build: use if_changed more consistently (and correctly) for prelink*.o

2020-09-15 Thread Jan Beulich
On 15.09.2020 13:56, Roger Pau Monné wrote:
> On Mon, Sep 14, 2020 at 12:15:39PM +0200, Jan Beulich wrote:
>> Switch to $(call if_changed,ld) where possible; presumably not doing so
>> in e321576f4047 ("xen/build: start using if_changed") right away was an
>> oversight, as it did for Arm in (just) one case. It failed to add
>> prelink.o to $(targets), though, causing - judging from the observed
>> behavior on x86 - undue rebuilds of the final binary (because of
>> prelink.o getting rebuild for $(cmd_prelink.o) being empty, in turn
>> because of .prelink.o.cmd not getting read) during "make install-xen".
> 
> I'm not sure I follow why prelink.o needs to be added to targets, does
> this offer some kind of protection against rebuilds when doing make
> install?

In a way, but (as I view it) not really. It is the use of ...

> The switch to if_changed LGTM.

... if_changed which requires this. .*.cmd files will only be loaded
for anything explicitly or implicitly listed as a target. While .o
coming from $(obj-y) get added there automatically, prelink.o is not
something that could be recognized as needing adding, hence the
"manual" insertion.

Without .prelink.o.cmd loaded, $(if_changed ) will always arrange
for it to get re-built, because it then will consider the command
used to build the file to have changed (as the stored one appears to
be empty).

Jan



Re: [PATCH 3/3] x86/shim: don't permit HVM and PV_SHIM_EXCLUSIVE at the same time

2020-09-15 Thread Jan Beulich
On 15.09.2020 13:02, Roger Pau Monné wrote:
> On Mon, Sep 14, 2020 at 02:39:33PM +0200, Jan Beulich wrote:
>> This combination doesn't really make sense (and there likely are more).
>> The alternative here would be some presumably intrusive #ifdef-ary to
>> get this combination to actually build again.
>>
>> Signed-off-by: Jan Beulich 
> 
> I'm not sure I see a way to cater for Andrew requests while allowing
> PV_SHIM_EXCLUSIVE to gate options in order to be able to remove
> code.

Yes, I'm specifically hoping for his input, in particular in light
of the additional argument given in the cover letter (HVM not
actually usable in this mode).

> Maybe PV_SHIM_EXCLUSIVE should be moved to the top level Kconfig
> screen on x86 and behave like a list, so that you select a 'Normal'
> hypervisor build or a 'PV shim exclusive' build, and that could
> completely change the contents of the menus?

This might be another option, yes. Let's see what Andrew thinks.

And btw - the patch needs an update anyway, as I've lost the
defaulting to Y of this option.

Jan



Re: [PATCH 2/3] x86/shim: adjust Kconfig defaults

2020-09-15 Thread Jan Beulich
On 15.09.2020 12:49, Roger Pau Monné wrote:
> On Mon, Sep 14, 2020 at 02:39:08PM +0200, Jan Beulich wrote:
>> Just like HVM, defaulting SHADOW_PAGING and TBOOT to Yes in shim-
>> exclusive mode makes no sense, as the respective code is dead there.
>>
>> Also adjust the shim default config file: It needs to specifiy values
>> only for settings where a non-default value is wanted.
>>
>> Signed-off-by: Jan Beulich 
> 
> Reviewed-by: Roger Pau Monné 

Thanks.

>> --- a/xen/arch/x86/Kconfig
>> +++ b/xen/arch/x86/Kconfig
>> @@ -116,9 +116,9 @@ config XEN_SHSTK
>>compatiblity can be provided via the PV Shim mechanism.
>>  
>>  config SHADOW_PAGING
>> -bool "Shadow Paging"
>> -default y
>> ----help---
>> +bool "Shadow Paging"
>> +default y if !PV_SHIM_EXCLUSIVE
> 
> I think you could also do: default !PV_SHIM_EXCLUSIVE?

Oh, yes, in this case I can indeed. I've mechanically used the form
wanted when the prompt isn't unconditionally visible. Will switch.

Jan



Re: [RFC PATCH v2] efi: const correct EFI functions

2020-09-15 Thread Trammell Hudson
On Tuesday, September 15, 2020 12:36 PM, Jan Beulich  wrote:
> In order for these casts to be halfway safe, they need to happen in
> inline functions, not macros. That way it'll be sufficiently clear
> and certain that it's really only the const which gets changed,
> but not e.g. also the pointed-to type.

At some point it really looks easier to just add const to
the efi headers rather than having to recreate all of their
verbose APIs.  The efiapi.h header was added nine years ago
and has been edited once, seven years ago, so it isn't a source
of significant churn.

Meanwhile, if someone wants to delve into the cursed mines
of sourceforge, perhaps the gnuefi devs can be convinced to
update their sources.

> Apart from this I think the whole change wants splitting up, to
> (about) one basic change at a time.

Yeah, the string and file const changes ended up mixed in the
change set.  They are sort of related, but it would be easiest
if the EFI constness was fixed first so that the printed strings
don't need additional casts.

--
Trammell



Re: [RFC PATCH v2] efi: const correct EFI functions

2020-09-15 Thread Jan Beulich
On 15.09.2020 12:02, Trammell Hudson wrote:
> @@ -149,10 +150,23 @@ static struct file __initdata cfg;
>  static struct file __initdata kernel;
>  static struct file __initdata ramdisk;
>  static struct file __initdata xsm;
> -static CHAR16 __initdata newline[] = L"\r\n";
> -
> -#define PrintStr(s) StdOut->OutputString(StdOut, s)
> -#define PrintErr(s) StdErr->OutputString(StdErr, s)
> +static const CHAR16 __initconst newline[] = L"\r\n";
> +
> +/* Cast away const-ness on EFI entry points */
> +#define PrintStr(s) StdOut->OutputString(StdOut, (CHAR16 *)(s))
> +#define PrintErr(s) StdErr->OutputString(StdErr, (CHAR16 *)(s))
> +#define efi_file_open(file,handle,name,mode,attr) \
> +(file)->Open(file, handle, (CHAR16 *)(name), mode, attr)
> +#define efi_handle_protocol(handle, protocol, interface) \
> +efi_bs->HandleProtocol(handle, (EFI_GUID *)(protocol), interface)
> +#define efi_locate_protocol(protocol, registration, interface) \
> +efi_bs->LocateProtocol((EFI_GUID *)(protocol), (void *)(registration), \
> +   interface)
> +#define efi_locate_handle(type, protocol, key, size, buffer) \
> +efi_bs->LocateHandle(type, (EFI_GUID *)(protocol), (void *)(key), \
> + size, buffer)
> +#define shim_verify(shim, ptr, len) \
> +(shim)->Verify((void *)(ptr), len)

In order for these casts to be halfway safe, they need to happen in
inline functions, not macros. That way it'll be sufficiently clear
and certain that it's really _only_ the const which gets changed,
but not e.g. also the pointed-to type.

Apart from this I think the whole change wants splitting up, to
(about) one basic change at a time.

Jan



[RFC PATCH v2] efi: const correct EFI functions

2020-09-15 Thread Trammell Hudson
By wrapping the few EFI handler functions used by the Xen boot process
and casting away constness where safe, it is possible to allow most of
the rest of the EFI boot code to use constant strings and GUIDs.

There are a few places in the code that casts away the const that should
be reconsidered. For instance, the config parser code modifies the config
file in place, which would not work if it were in a read-only segment.

Signed-off-by: Trammell Hudson 
---
 xen/arch/arm/efi/efi-boot.h |   8 +-
 xen/arch/x86/efi/efi-boot.h |  40 -
 xen/common/efi/boot.c   | 157 
 3 files changed, 111 insertions(+), 94 deletions(-)

diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h
index 6527cb0bdf..13666bc065 100644
--- a/xen/arch/arm/efi/efi-boot.h
+++ b/xen/arch/arm/efi/efi-boot.h
@@ -418,9 +418,9 @@ static void __init efi_arch_memory_setup(void)
 {
 }

-static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
-   CHAR16 *cmdline_options,
-   char *cfgfile_options)
+static void __init efi_arch_handle_cmdline(const CHAR16 *image_name,
+   const CHAR16 *cmdline_options,
+   const char *cfgfile_options)
 {
 union string name;
 char *buf;
@@ -482,7 +482,7 @@ static void __init efi_arch_handle_cmdline(CHAR16 
*image_name,
 }

 static void __init efi_arch_handle_module(struct file *file, const CHAR16 
*name,
-  char *options)
+  const char *options)
 {
 int node;
 int chosen;
diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 7188c9a551..8e9811f3e0 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -280,10 +280,10 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE 
dir_handle, char *sect
 {
 union string name;

-name.s = get_value(, section, "ucode");
-if ( !name.s )
-name.s = get_value(, "global", "ucode");
-if ( name.s )
+name.cs = get_value(, section, "ucode");
+if ( !name.cs )
+name.cs = get_value(, "global", "ucode");
+if ( name.cs )
 {
 microcode_set_module(mbi.mods_count);
 split_string(name.s);
@@ -292,29 +292,29 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE 
dir_handle, char *sect
 }
 }

-static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
-   CHAR16 *cmdline_options,
-   char *cfgfile_options)
+static void __init efi_arch_handle_cmdline(const CHAR16 *image_name,
+   const CHAR16 *cmdline_options,
+   const char *cfgfile_options)
 {
 union string name;

 if ( cmdline_options )
 {
-name.w = cmdline_options;
+name.cw = cmdline_options;
 w2s();
-place_string(, name.s);
+place_string(, name.cs);
 }
 if ( cfgfile_options )
 place_string(, cfgfile_options);
 /* Insert image name last, as it gets prefixed to the other options. */
 if ( image_name )
 {
-name.w = image_name;
+name.cw = image_name;
 w2s();
 }
 else
-name.s = "xen";
-place_string(, name.s);
+name.cs = "xen";
+place_string(, name.cs);

 if ( mbi.cmdline )
 mbi.flags |= MBI_CMDLINE;
@@ -328,8 +328,8 @@ static void __init efi_arch_handle_cmdline(CHAR16 
*image_name,

 static void __init efi_arch_edd(void)
 {
-static EFI_GUID __initdata bio_guid = BLOCK_IO_PROTOCOL;
-static EFI_GUID __initdata devp_guid = DEVICE_PATH_PROTOCOL;
+static const EFI_GUID __initconst bio_guid = BLOCK_IO_PROTOCOL;
+static const EFI_GUID __initconst devp_guid = DEVICE_PATH_PROTOCOL;
 EFI_HANDLE *handles = NULL;
 unsigned int i;
 UINTN size;
@@ -339,12 +339,12 @@ static void __init efi_arch_edd(void)
 BUILD_BUG_ON(offsetof(struct edd_info, edd_device_params) != EDDEXTSIZE);
 BUILD_BUG_ON(sizeof(struct edd_device_params) != EDDPARMSIZE);
 size = 0;
-status = efi_bs->LocateHandle(ByProtocol, _guid, NULL, , NULL);
+status = efi_locate_handle(ByProtocol, _guid, NULL, , NULL);
 if ( status == EFI_BUFFER_TOO_SMALL )
 status = efi_bs->AllocatePool(EfiLoaderData, size, (void **));
 if ( !EFI_ERROR(status) )
-status = efi_bs->LocateHandle(ByProtocol, _guid, NULL, ,
-  handles);
+status = efi_locate_handle(ByProtocol, _guid, NULL, ,
+   handles);
 if ( EFI_ERROR(status) )
 size = 0;
 for ( i = 0; i < size / sizeof(*handles); ++i )
@@ -355,7 +355,7 @@ static void __init efi_arch_edd(void)
 struct edd_device_params *params = >edd_device_params;

Re: [RFC PATCH] efi: const correct EFI functions

2020-09-15 Thread Trammell Hudson
On Tuesday, September 15, 2020 9:41 AM, Jan Beulich  wrote:
> On 14.09.2020 17:05, Trammell Hudson wrote:
> > [...] I checked to see
> > which functions would need to be wrapped. It is a surprisingly
> > small number:
> > #define PrintStr(s) StdOut->OutputString(StdOut, (CHAR16 *)(s))
> > #define PrintErr(s) StdErr->OutputString(StdErr, (CHAR16 *)(s))
> > #define efi_file_open(file,handle,name,mode,attr) \
> > (file)->Open(file, handle, (CHAR16 *)(name), mode, attr)
> > #define shim_verify(shim, ptr, len) \
> > (shim)->Verify((void *)(ptr), len)
>
> That's surprisingly few. What about e.g. HandleProtocol() and
> LocateHandle()? GUIDs shouldn't really be non-const either.

Good point -- I did not track down all uses of efi_bs and every GUID.  I'll 
send a RFC patch v2 in a minute with all of the GUIDs converted to __initconst.

--
Trammell




[xen-4.13-testing test] 154122: trouble: fail/pass/preparing

2020-09-15 Thread osstest service owner
flight 154122 xen-4.13-testing running [real]
http://logs.test-lab.xenproject.org/osstest/logs/154122/

Failures and problems with tests :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 test-armhf-armhf-xl-credit2   2 hosts-allocate   running
 test-amd64-amd64-dom0pvh-xl-amd  2 hosts-allocate   running
 test-amd64-coresched-amd64-xl  2 hosts-allocate   running

Tests which did not succeed, but are not blocking:
 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-libvirt-raw 12 migrate-support-checkfail   never pass
 test-amd64-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-amd64-i386-xl-pvshim12 guest-start  fail   never pass
 test-armhf-armhf-xl-vhd  12 migrate-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit1  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt 13 migrate-support-checkfail   never pass
 test-armhf-armhf-libvirt-raw 13 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit1  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-cubietruck 13 migrate-support-checkfail never pass
 test-armhf-armhf-xl-multivcpu 13 migrate-support-checkfail  never pass
 test-amd64-amd64-libvirt 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-i386-libvirt-xsm  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-rtds 13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  13 saverestore-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-credit1  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-libvirt 14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-arndale  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-credit1  14 saverestore-support-checkfail   never pass
 test-armhf-armhf-xl-cubietruck 14 saverestore-support-checkfail never pass
 test-armhf-armhf-xl-multivcpu 14 saverestore-support-checkfail  never pass
 test-armhf-armhf-xl-rtds 14 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-win7-amd64 17 guest-stop  fail never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 17 guest-stop  fail never pass
 test-amd64-amd64-xl-qemuu-ws16-amd64 17 guest-stop fail never pass
 test-amd64-amd64-xl-qemuu-win7-amd64 17 guest-stop fail never pass
 test-amd64-amd64-xl-qemut-ws16-amd64 17 guest-stop fail never pass
 test-amd64-amd64-xl-qemut-win7-amd64 17 guest-stop fail never pass
 test-amd64-amd64-qemuu-nested-amd 17 debian-hvm-install/l1/l2  fail never pass
 test-amd64-i386-xl-qemut-win7-amd64 17 guest-stop  fail never pass
 test-amd64-i386-xl-qemut-ws16-amd64 17 guest-stop  fail never pass

version targeted for testing:
 xen  c663fa577b42e7f4731bb33fc7f94f7ffb05a1ef
baseline version:
 xen  9b367b2b0b714f3ffb69ed6be0a118e8d3eac07f

Last test of basis   152528  2020-08-07 15:39:16 Z   38 days
Testing same since  (not found) 0 attempts


People who touched revisions under test:
  Andrew Cooper 
  Jan Beulich 
  Roger Pau Monné 

jobs:
 build-amd64-xsm  pass
 

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

2020-09-15 Thread Wei Yang
On Tue, Sep 15, 2020 at 11:15:53AM +0200, David Hildenbrand wrote:
>On 15.09.20 11:06, Wei Yang wrote:
>> On Tue, Sep 15, 2020 at 09:35:30AM +0200, David Hildenbrand wrote:
>>>
> static int __ref try_remove_memory(int nid, u64 start, u64 size)
> {
>   int rc = 0;
> @@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 
> start, u64 size)
>   memblock_remove(start, size);
>   }
>
> - __release_memory_resource(start, size);
> + release_mem_region_adjustable(_resource, start, size);
>

 Seems the only user of release_mem_region_adjustable() is here, can we move
 iomem_resource into the function body? Actually, we don't iterate the 
 resource
 tree from any level. We always start from the root.
>>>
>>> You mean, making iomem_resource implicit? I can spot that something
>>> similar was done for
>>>
>>> #define devm_release_mem_region(dev, start, n) \
>>> __devm_release_region(dev, _resource, (start), (n))
>>>
>> 
>> What I prefer is remove iomem_resource from the parameter list. Just use is 
>> in
>> the function body.
>> 
>> For the example you listed, __release_region() would have varies of *parent*,
>> which looks reasonable to keep it here.
>
>Yeah I got that ("making iomem_resource implicit"), as I said:
>

Thanks

>>> I'll send an addon patch for that, ok? - thanks.
>
>-- 
>Thanks,
>
>David / dhildenb

-- 
Wei Yang
Help you, Help me



[xen-4.14-testing test] 154350: tolerable FAIL - PUSHED

2020-09-15 Thread osstest service owner
flight 154350 xen-4.14-testing real [real]
http://logs.test-lab.xenproject.org/osstest/logs/154350/

Failures :-/ but no regressions.

Tests which did not succeed, but are not blocking:
 test-amd64-i386-xl-pvshim12 guest-start  fail   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-arm64-arm64-xl-seattle  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-seattle  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-xsm  14 saverestore-support-checkfail   never pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 11 migrate-support-check 
fail never pass
 test-arm64-arm64-xl  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-credit1  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit1  14 saverestore-support-checkfail   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-arm64-arm64-xl-credit2  13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-credit2  14 saverestore-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 13 migrate-support-checkfail   never pass
 test-arm64-arm64-xl-thunderx 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-arm64-arm64-libvirt-xsm 13 migrate-support-checkfail   never pass
 test-arm64-arm64-libvirt-xsm 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-amd64-libvirt-vhd 12 migrate-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-win7-amd64 17 guest-stop  fail never pass
 test-amd64-amd64-xl-qemut-win7-amd64 17 guest-stop 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-credit1  13 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-credit1  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-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-libvirt 14 saverestore-support-checkfail   never pass
 test-amd64-amd64-xl-qemuu-win7-amd64 17 guest-stop fail never pass
 test-amd64-amd64-xl-qemut-ws16-amd64 17 guest-stop fail never pass
 test-amd64-i386-xl-qemut-ws16-amd64 17 guest-stop  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-xl-qemut-win7-amd64 17 guest-stop  fail 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-vhd  12 migrate-support-checkfail   never pass
 test-armhf-armhf-xl-vhd  13 saverestore-support-checkfail   never pass
 test-amd64-i386-xl-qemuu-ws16-amd64 17 guest-stop  fail never pass
 test-amd64-amd64-xl-qemuu-ws16-amd64 17 guest-stop fail never pass

version targeted for testing:
 xen  28855ebcdbfa437e60bc16c761405476fe16bc39
baseline version:
 xen  483b43c4573329a28f1c9e18f90694e5be35ddb9

Last test of basis   154148  2020-09-12 01:43:23 Z3 days
Testing same since   154350  2020-09-15 00:36:14 Z0 days1 attempts


People who touched revisions under test:
  Bertrand Marquis 
  Julien Grall 
  Stefano Stabellini 
  Wei Chen 

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

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

2020-09-15 Thread David Hildenbrand
On 15.09.20 11:06, Wei Yang wrote:
> On Tue, Sep 15, 2020 at 09:35:30AM +0200, David Hildenbrand wrote:
>>
 static int __ref try_remove_memory(int nid, u64 start, u64 size)
 {
int rc = 0;
 @@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 
 start, u64 size)
memblock_remove(start, size);
}

 -  __release_memory_resource(start, size);
 +  release_mem_region_adjustable(_resource, start, size);

>>>
>>> Seems the only user of release_mem_region_adjustable() is here, can we move
>>> iomem_resource into the function body? Actually, we don't iterate the 
>>> resource
>>> tree from any level. We always start from the root.
>>
>> You mean, making iomem_resource implicit? I can spot that something
>> similar was done for
>>
>> #define devm_release_mem_region(dev, start, n) \
>>  __devm_release_region(dev, _resource, (start), (n))
>>
> 
> What I prefer is remove iomem_resource from the parameter list. Just use is in
> the function body.
> 
> For the example you listed, __release_region() would have varies of *parent*,
> which looks reasonable to keep it here.

Yeah I got that ("making iomem_resource implicit"), as I said:

>> I'll send an addon patch for that, ok? - thanks.

-- 
Thanks,

David / dhildenb




RE: [PATCH v3] x86/HVM: more consistently set I/O completion

2020-09-15 Thread Paul Durrant
> -Original Message-
> From: Jan Beulich 
> Sent: 15 September 2020 09:26
> To: Andrew Cooper ; Paul Durrant 
> Cc: xen-devel@lists.xenproject.org; Wei Liu ; Roger Pau Monné 
> ; Jun
> Nakajima ; Kevin Tian ; George 
> Dunlap
> 
> Subject: Re: [PATCH v3] x86/HVM: more consistently set I/O completion
> 
> On 27.08.2020 09:09, Jan Beulich wrote:
> > Doing this just in hvm_emulate_one_insn() is not enough.
> > hvm_ud_intercept() and hvm_emulate_one_vm_event() can get invoked for
> > insns requiring one or more continuations, and at least in principle
> > hvm_emulate_one_mmio() could, too. Without proper setting of the field,
> > handle_hvm_io_completion() will do nothing completion-wise, and in
> > particular the missing re-invocation of the insn emulation paths will
> > lead to emulation caching not getting disabled in due course, causing
> > the ASSERT() in {svm,vmx}_vmenter_helper() to trigger.
> >
> > Reported-by: Don Slutz 
> >
> > Similar considerations go for the clearing of vio->mmio_access, which
> > gets moved as well.
> >
> > Additionally all updating of vio->mmio_* now gets done dependent upon
> > the new completion value, rather than hvm_ioreq_needs_completion()'s
> > return value. This is because it is the completion chosen which controls
> > what path will be taken when handling the completion, not the simple
> > boolean return value. In particular, PIO completion doesn't involve
> > going through the insn emulator, and hence emulator state ought to get
> > cleared early (or it won't get cleared at all).
> >
> > The new logic, besides allowing for a caller override for the
> > continuation type to be set (for VMX real mode emulation), will also
> > avoid setting an MMIO completion when a simpler PIO one will do. This
> > is a minor optimization only as a side effect - the behavior is strictly
> > needed at least for hvm_ud_intercept(), as only memory accesses can
> > successfully complete through handle_mmio(). Care of course needs to be
> > taken to correctly deal with "mixed" insns (doing both MMIO and PIO at
> > the same time, i.e. INS/OUTS). For this, hvmemul_validate() now latches
> > whether the insn being emulated is a memory access, as this information
> > is no longer easily available at the point where we want to consume it.
> >
> > Note that the presence of non-NULL .validate fields in the two ops
> > structures in hvm_emulate_one_mmio() was really necessary even before
> > the changes here: Without this, passing non-NULL as middle argument to
> > hvm_emulate_init_once() is meaningless.
> >
> > The restrictions on when the #UD intercept gets actually enabled are why
> > it was decided that this is not a security issue:
> > - the "hvm_fep" option to enable its use is a debugging option only,
> > - for the cross-vendor case is considered experimental, even if
> >   unfortunately SUPPORT.md doesn't have an explicit statement about
> >   this.
> > The other two affected functions are
> > - hvm_emulate_one_vm_event(), used for introspection,
> > - hvm_emulate_one_mmio(), used for Dom0 only,
> > which aren't qualifying this as needing an XSA either.
> >
> > Signed-off-by: Jan Beulich 
> > Tested-by: Don Slutz 
> > ---
> > v3: Add comment ahead of _hvm_emulate_one(). Add parentheses in a
> > conditional expr. Justify why this does not need an XSA.
> > v2: Make updating of vio->mmio_* fields fully driven by the new
> > completion value.
> > ---
> > I further think that the entire tail of _hvm_emulate_one() (everything
> > past the code changed/added there by this patch) wants skipping in case
> > a completion is needed, at the very least for the mmio and realmode
> > cases, where we know we'll come back here.
> 
> Does one of the two of you have an opinion on this aspect?
> 

It seems reasonable that we only want to execute the tail once but I'm unsure 
of the consequences of deferring it until I/O emulation is complete.

  Paul

> Jan




[libvirt test] 154353: regressions - FAIL

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

Regressions :-(

Tests which did not succeed and are blocking,
including tests which could not be run:
 build-i386-libvirt6 libvirt-buildfail REGR. vs. 151777
 build-amd64-libvirt   6 libvirt-buildfail REGR. vs. 151777
 build-arm64-libvirt   6 libvirt-buildfail REGR. vs. 151777
 build-armhf-libvirt   6 libvirt-buildfail REGR. vs. 151777

Tests which did not succeed, but are not blocking:
 test-amd64-amd64-libvirt  1 build-check(1)   blocked  n/a
 test-amd64-amd64-libvirt-pair  1 build-check(1)   blocked  n/a
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm 1 build-check(1) blocked n/a
 test-amd64-amd64-libvirt-vhd  1 build-check(1)   blocked  n/a
 test-amd64-amd64-libvirt-xsm  1 build-check(1)   blocked  n/a
 test-amd64-i386-libvirt   1 build-check(1)   blocked  n/a
 test-amd64-i386-libvirt-pair  1 build-check(1)   blocked  n/a
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsm 1 build-check(1) blocked n/a
 test-amd64-i386-libvirt-xsm   1 build-check(1)   blocked  n/a
 test-arm64-arm64-libvirt  1 build-check(1)   blocked  n/a
 test-arm64-arm64-libvirt-qcow2  1 build-check(1)   blocked  n/a
 test-arm64-arm64-libvirt-xsm  1 build-check(1)   blocked  n/a
 test-armhf-armhf-libvirt  1 build-check(1)   blocked  n/a
 test-armhf-armhf-libvirt-raw  1 build-check(1)   blocked  n/a

version targeted for testing:
 libvirt  af16e754cd4efc3ca1df2b2e725945be743e87f9
baseline version:
 libvirt  2c846fa6bcc11929c9fb857a22430fb9945654ad

Last test of basis   151777  2020-07-10 04:19:19 Z   67 days
Failing since151818  2020-07-11 04:18:52 Z   66 days   62 attempts
Testing same since   154353  2020-09-15 04:20:01 Z0 days1 attempts


People who touched revisions under test:
  Andika Triwidada 
  Andrea Bolognani 
  Balázs Meskó 
  Bastien Orivel 
  Bihong Yu 
  Binfeng Wu 
  Boris Fiuczynski 
  Christian Ehrhardt 
  Côme Borsoi 
  Daniel Henrique Barboza 
  Daniel P. Berrange 
  Daniel P. Berrangé 
  Erik Skultety 
  Fangge Jin 
  Fedora Weblate Translation 
  Han Han 
  Hao Wang 
  Ian Wienand 
  Jamie Strandboge 
  Jamie Strandboge 
  Jean-Baptiste Holcroft 
  Jianan Gao 
  Jim Fehlig 
  Jin Yan 
  Jiri Denemark 
  Jonathon Jongsma 
  Ján Tomko 
  Kashyap Chamarthy 
  Kevin Locke 
  Laine Stump 
  Liao Pingfang 
  Lin Ma 
  Lin Ma 
  Marek Marczykowski-Górecki 
  Martin Kletzander 
  Matt Coleman 
  Matt Coleman 
  Michal Privoznik 
  Neal Gompa 
  Nikolay Shirokovskiy 
  Patrick Magauran 
  Paulo de Rezende Pinatti 
  Pavel Hrdina 
  Peter Krempa 
  Pino Toscano 
  Pino Toscano 
  Piotr Drąg 
  Prathamesh Chavan 
  Roman Bogorodskiy 
  Ryan Schmidt 
  Sam Hartman 
  Scott Shambarger 
  Sebastian Mitterle 
  Simon Gaiser 
  Stefan Bader 
  Stefan Berger 
  Szymon Scholz 
  Thomas Huth 
  Tim Wiederhake 
  Tomáš Golembiovský 
  Wang Xin 
  Weblate 
  Yang Hang 
  Yanqiu Zhang 
  Yi Li 
  Yi Wang 
  Yuri Chornoivan 
  Zheng Chuan 

jobs:
 build-amd64-xsm  pass
 build-arm64-xsm  pass
 build-i386-xsm   pass
 build-amd64  pass
 build-arm64  pass
 build-armhf  pass
 build-i386   pass
 build-amd64-libvirt  fail
 build-arm64-libvirt  fail
 build-armhf-libvirt  fail
 build-i386-libvirt   fail
 build-amd64-pvopspass
 build-arm64-pvopspass
 build-armhf-pvopspass
 build-i386-pvops pass
 test-amd64-amd64-libvirt-qemuu-debianhvm-amd64-xsm   blocked 
 test-amd64-i386-libvirt-qemuu-debianhvm-amd64-xsmblocked 
 test-amd64-amd64-libvirt-xsm blocked 
 test-arm64-arm64-libvirt-xsm blocked 
 test-amd64-i386-libvirt-xsm  blocked 
 test-amd64-amd64-libvirt blocked 
 test-arm64-arm64-libvirt blocked 
 test-armhf-armhf-libvirt blocked 
 test-amd64-i386-libvirt  

Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

2020-09-15 Thread Wei Yang
On Tue, Sep 15, 2020 at 09:35:30AM +0200, David Hildenbrand wrote:
>
>>> static int __ref try_remove_memory(int nid, u64 start, u64 size)
>>> {
>>> int rc = 0;
>>> @@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 
>>> start, u64 size)
>>> memblock_remove(start, size);
>>> }
>>>
>>> -   __release_memory_resource(start, size);
>>> +   release_mem_region_adjustable(_resource, start, size);
>>>
>> 
>> Seems the only user of release_mem_region_adjustable() is here, can we move
>> iomem_resource into the function body? Actually, we don't iterate the 
>> resource
>> tree from any level. We always start from the root.
>
>You mean, making iomem_resource implicit? I can spot that something
>similar was done for
>
>#define devm_release_mem_region(dev, start, n) \
>   __devm_release_region(dev, _resource, (start), (n))
>

What I prefer is remove iomem_resource from the parameter list. Just use is in
the function body.

For the example you listed, __release_region() would have varies of *parent*,
which looks reasonable to keep it here.

>I'll send an addon patch for that, ok? - thanks.
>
>-- 
>Thanks,
>
>David / dhildenb

-- 
Wei Yang
Help you, Help me



Re: [PATCH 18/20] drm/xen: Introduce GEM object functions

2020-09-15 Thread Thomas Zimmermann
Hi

Am 13.08.20 um 13:19 schrieb Oleksandr Andrushchenko:
> Hi,
> 
> On 8/13/20 11:36 AM, Thomas Zimmermann wrote:
>> GEM object functions deprecate several similar callback interfaces in
>> struct drm_driver. This patch replaces the per-driver callbacks with
>> per-instance callbacks in xen. The only exception is gem_prime_mmap,
>> which is non-trivial to convert.
>>
>> Signed-off-by: Thomas Zimmermann 
>> ---
>>   drivers/gpu/drm/xen/xen_drm_front.c | 12 +---
>>   drivers/gpu/drm/xen/xen_drm_front.h |  2 ++
>>   drivers/gpu/drm/xen/xen_drm_front_gem.c | 15 +++
>>   3 files changed, 18 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xen/xen_drm_front.c 
>> b/drivers/gpu/drm/xen/xen_drm_front.c
>> index 3e660fb111b3..bd9af1875af1 100644
>> --- a/drivers/gpu/drm/xen/xen_drm_front.c
>> +++ b/drivers/gpu/drm/xen/xen_drm_front.c
>> @@ -433,7 +433,7 @@ static int xen_drm_drv_dumb_create(struct drm_file *filp,
>>  return ret;
>>   }
>>   
>> -static void xen_drm_drv_free_object_unlocked(struct drm_gem_object *obj)
>> +void xen_drm_drv_free_object_unlocked(struct drm_gem_object *obj)
> 
> Can we please have naming consistent and name it as
> 
> xen_drm_front_drv_free_object_unlocked or any other name if this seems to be 
> too long,
> 
> but starting with xen_drm_front_ as the rest of exported functions?

There already is a function with that name in drm_xen_front_gem.c. I'll
move the callback function next to the object-function structure and
rename it slightly.

Best regards
Thomas

> 
> With this,
> 
> Acked-by: Oleksandr Andrushchenko 
> 
> Thank you,
> 
> Oleksandr
> 
>>   {
>>  struct xen_drm_front_drm_info *drm_info = obj->dev->dev_private;
>>  int idx;
>> @@ -481,22 +481,12 @@ static const struct file_operations xen_drm_dev_fops = 
>> {
>>  .mmap   = xen_drm_front_gem_mmap,
>>   };
>>   
>> -static const struct vm_operations_struct xen_drm_drv_vm_ops = {
>> -.open   = drm_gem_vm_open,
>> -.close  = drm_gem_vm_close,
>> -};
>> -
>>   static struct drm_driver xen_drm_driver = {
>>  .driver_features   = DRIVER_GEM | DRIVER_MODESET | 
>> DRIVER_ATOMIC,
>>  .release   = xen_drm_drv_release,
>> -.gem_vm_ops= _drm_drv_vm_ops,
>> -.gem_free_object_unlocked  = xen_drm_drv_free_object_unlocked,
>>  .prime_handle_to_fd= drm_gem_prime_handle_to_fd,
>>  .prime_fd_to_handle= drm_gem_prime_fd_to_handle,
>>  .gem_prime_import_sg_table = xen_drm_front_gem_import_sg_table,
>> -.gem_prime_get_sg_table= xen_drm_front_gem_get_sg_table,
>> -.gem_prime_vmap= xen_drm_front_gem_prime_vmap,
>> -.gem_prime_vunmap  = xen_drm_front_gem_prime_vunmap,
>>  .gem_prime_mmap= xen_drm_front_gem_prime_mmap,
>>  .dumb_create   = xen_drm_drv_dumb_create,
>>  .fops  = _drm_dev_fops,
>> diff --git a/drivers/gpu/drm/xen/xen_drm_front.h 
>> b/drivers/gpu/drm/xen/xen_drm_front.h
>> index f92c258350ca..93e60c1db550 100644
>> --- a/drivers/gpu/drm/xen/xen_drm_front.h
>> +++ b/drivers/gpu/drm/xen/xen_drm_front.h
>> @@ -160,4 +160,6 @@ int xen_drm_front_page_flip(struct xen_drm_front_info 
>> *front_info,
>>   void xen_drm_front_on_frame_done(struct xen_drm_front_info *front_info,
>>   int conn_idx, u64 fb_cookie);
>>   
>> +void xen_drm_drv_free_object_unlocked(struct drm_gem_object *obj);
>> +
>>   #endif /* __XEN_DRM_FRONT_H_ */
>> diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c 
>> b/drivers/gpu/drm/xen/xen_drm_front_gem.c
>> index f0b85e094111..7b315c08bcfc 100644
>> --- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
>> +++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
>> @@ -56,6 +56,19 @@ static void gem_free_pages_array(struct xen_gem_object 
>> *xen_obj)
>>  xen_obj->pages = NULL;
>>   }
>>   
>> +static const struct vm_operations_struct xen_drm_drv_vm_ops = {
>> +.open   = drm_gem_vm_open,
>> +.close  = drm_gem_vm_close,
>> +};
>> +
>> +static const struct drm_gem_object_funcs xen_drm_front_gem_object_funcs = {
>> +.free = xen_drm_drv_free_object_unlocked,
>> +.get_sg_table = xen_drm_front_gem_get_sg_table,
>> +.vmap = xen_drm_front_gem_prime_vmap,
>> +.vunmap = xen_drm_front_gem_prime_vunmap,
>> +.vm_ops = _drm_drv_vm_ops,
>> +};
>> +
>>   static struct xen_gem_object *gem_create_obj(struct drm_device *dev,
>>   size_t size)
>>   {
>> @@ -66,6 +79,8 @@ static struct xen_gem_object *gem_create_obj(struct 
>> drm_device *dev,
>>  if (!xen_obj)
>>  return ERR_PTR(-ENOMEM);
>>   
>> +xen_obj->base.funcs = _drm_front_gem_object_funcs;
>> +
>>  ret = drm_gem_object_init(dev, _obj->base, size);
>>  if (ret < 0) {
>>  kfree(xen_obj);

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 

Re: [PATCH v3 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends

2020-09-15 Thread kernel test robot
Hi David,

I love your patch! Perhaps something to improve:

[auto build test WARNING on next-20200909]
[cannot apply to mmotm/master hnaz-linux-mm/master xen-tip/linux-next 
powerpc/next linus/master v5.9-rc4 v5.9-rc3 v5.9-rc2 v5.9-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/David-Hildenbrand/mm-memory_hotplug-selective-merging-of-system-ram-resources/20200910-171630
base:7204eaa2c1f509066486f488c9dcb065d7484494
:: branch date: 9 hours ago
:: commit date: 9 hours ago
config: powerpc-randconfig-r011-20200909 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 
0a5dc7effb191eff740e0e7ae7bd8e1f6bdb3ad9)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:15:
   In file included from include/linux/radix-tree.h:18:
   In file included from include/linux/xarray.h:14:
   In file included from include/linux/gfp.h:6:
   In file included from include/linux/mmzone.h:853:
   include/linux/memory_hotplug.h:354:55: error: unknown type name 'mhp_t'
   extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
 ^
   include/linux/memory_hotplug.h:355:53: error: unknown type name 'mhp_t'
   extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
   ^
   include/linux/memory_hotplug.h:357:11: error: unknown type name 'mhp_t'
  mhp_t mhp_flags);
  ^
   include/linux/memory_hotplug.h:360:10: error: unknown type name 'mhp_t'
mhp_t mhp_flags);
^
   In file included from arch/powerpc/kernel/asm-offsets.c:21:
>> include/linux/mman.h:137:9: warning: division by zero is undefined 
>> [-Wdivision-by-zero]
  _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED) |
  ^~~~
   include/linux/mman.h:115:21: note: expanded from macro '_calc_vm_trans'
  : ((x) & (bit1)) / ((bit1) / (bit2
   ^ ~
   include/linux/mman.h:138:9: warning: division by zero is undefined 
[-Wdivision-by-zero]
  _calc_vm_trans(flags, MAP_SYNC,   VM_SYNC  );
  ^~~~
   include/linux/mman.h:115:21: note: expanded from macro '_calc_vm_trans'
  : ((x) & (bit1)) / ((bit1) / (bit2
   ^ ~
   2 warnings and 4 errors generated.
   make[2]: *** [scripts/Makefile.build:117: arch/powerpc/kernel/asm-offsets.s] 
Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1196: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:185: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

# 
https://github.com/0day-ci/linux/commit/d88270d1c0783a7f99f24a85692be90fd2ae0d7d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
David-Hildenbrand/mm-memory_hotplug-selective-merging-of-system-ram-resources/20200910-171630
git checkout d88270d1c0783a7f99f24a85692be90fd2ae0d7d
vim +137 include/linux/mman.h

^1da177e4c3f41 Linus Torvalds  2005-04-16  128  
^1da177e4c3f41 Linus Torvalds  2005-04-16  129  /*
^1da177e4c3f41 Linus Torvalds  2005-04-16  130   * Combine the mmap "flags" 
argument into "vm_flags" used internally.
^1da177e4c3f41 Linus Torvalds  2005-04-16  131   */
^1da177e4c3f41 Linus Torvalds  2005-04-16  132  static inline unsigned long
^1da177e4c3f41 Linus Torvalds  2005-04-16  133  calc_vm_flag_bits(unsigned long 
flags)
^1da177e4c3f41 Linus Torvalds  2005-04-16  134  {
^1da177e4c3f41 Linus Torvalds  2005-04-16  135  return 
_calc_vm_trans(flags, MAP_GROWSDOWN,  VM_GROWSDOWN ) |
^1da177e4c3f41 Linus Torvalds  2005-04-16  136 
_calc_vm_trans(flags, MAP_DENYWRITE,  VM_DENYWRITE ) |
b6fb293f2497a9 Jan Kara2017-11-01 @137 
_calc_vm_trans(flags, MAP_LOCKED, 

[PATCH v9 7/8] iommu: remove the share_p2m operation

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

Sharing of HAP tables is now VT-d specific so the operation is never defined
for AMD IOMMU any more. There's also no need to pro-actively set vtd.pgd_maddr
when using shared EPT as it is straightforward to simply define a helper
function to return the appropriate value in the shared and non-shared cases.

NOTE: This patch also modifies unmap_vtd_domain_page() to take a const
  pointer since the only thing it calls, unmap_domain_page(), also takes
  a const pointer.

Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
---
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Wei Liu 
Cc: "Roger Pau Monné" 
Cc: Kevin Tian 

v6:
 - Adjust code to return P2M paddr
 - Add removed comment back in

v5:
 - Pass 'nr_pt_levels' into domain_pgd_maddr() directly

v2:
 - Put the PGD level adjust into the helper function too, since it is
   irrelevant in the shared EPT case
---
 xen/arch/x86/mm/p2m.c |  3 -
 xen/drivers/passthrough/iommu.c   |  8 ---
 xen/drivers/passthrough/vtd/extern.h  |  2 +-
 xen/drivers/passthrough/vtd/iommu.c   | 90 +++
 xen/drivers/passthrough/vtd/x86/vtd.c |  2 +-
 xen/include/xen/iommu.h   |  3 -
 6 files changed, 52 insertions(+), 56 deletions(-)

diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index 01ff92862d..d382199c88 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -726,9 +726,6 @@ int p2m_alloc_table(struct p2m_domain *p2m)
 
 p2m->phys_table = pagetable_from_mfn(top_mfn);
 
-if ( hap_enabled(d) )
-iommu_share_p2m_table(d);
-
 p2m_unlock(p2m);
 return 0;
 }
diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index a9da4d2b06..90748062e5 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -500,14 +500,6 @@ int iommu_do_domctl(
 return ret;
 }
 
-void iommu_share_p2m_table(struct domain* d)
-{
-ASSERT(hap_enabled(d));
-
-if ( iommu_use_hap_pt(d) )
-iommu_get_ops()->share_p2m(d);
-}
-
 void iommu_crash_shutdown(void)
 {
 if ( !iommu_crash_disable )
diff --git a/xen/drivers/passthrough/vtd/extern.h 
b/xen/drivers/passthrough/vtd/extern.h
index ada3c3098c..9cf5b578c9 100644
--- a/xen/drivers/passthrough/vtd/extern.h
+++ b/xen/drivers/passthrough/vtd/extern.h
@@ -72,7 +72,7 @@ void flush_all_cache(void);
 uint64_t alloc_pgtable_maddr(unsigned long npages, nodeid_t node);
 void free_pgtable_maddr(u64 maddr);
 void *map_vtd_domain_page(u64 maddr);
-void unmap_vtd_domain_page(void *va);
+void unmap_vtd_domain_page(const void *va);
 int domain_context_mapping_one(struct domain *domain, struct vtd_iommu *iommu,
u8 bus, u8 devfn, const struct pci_dev *);
 int domain_context_unmap_one(struct domain *domain, struct vtd_iommu *iommu,
diff --git a/xen/drivers/passthrough/vtd/iommu.c 
b/xen/drivers/passthrough/vtd/iommu.c
index 68cf0e535a..58d4550a4c 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -318,6 +318,48 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, 
u64 addr, int alloc)
 return pte_maddr;
 }
 
+static uint64_t domain_pgd_maddr(struct domain *d, unsigned int nr_pt_levels)
+{
+struct domain_iommu *hd = dom_iommu(d);
+uint64_t pgd_maddr;
+unsigned int agaw;
+
+ASSERT(spin_is_locked(>arch.mapping_lock));
+
+if ( iommu_use_hap_pt(d) )
+{
+pagetable_t pgt = p2m_get_pagetable(p2m_get_hostp2m(d));
+
+return pagetable_get_paddr(pgt);
+}
+
+if ( !hd->arch.vtd.pgd_maddr )
+{
+/* Ensure we have pagetables allocated down to leaf PTE. */
+addr_to_dma_page_maddr(d, 0, 1);
+
+if ( !hd->arch.vtd.pgd_maddr )
+return 0;
+}
+
+pgd_maddr = hd->arch.vtd.pgd_maddr;
+
+/* Skip top levels of page tables for 2- and 3-level DRHDs. */
+for ( agaw = level_to_agaw(4);
+  agaw != level_to_agaw(nr_pt_levels);
+  agaw-- )
+{
+const struct dma_pte *p = map_vtd_domain_page(pgd_maddr);
+
+pgd_maddr = dma_pte_addr(*p);
+unmap_vtd_domain_page(p);
+if ( !pgd_maddr )
+return 0;
+}
+
+return pgd_maddr;
+}
+
 static void iommu_flush_write_buffer(struct vtd_iommu *iommu)
 {
 u32 val;
@@ -1286,7 +1328,7 @@ int domain_context_mapping_one(
 struct context_entry *context, *context_entries;
 u64 maddr, pgd_maddr;
 u16 seg = iommu->drhd->segment;
-int agaw, rc, ret;
+int rc, ret;
 bool_t flush_dev_iotlb;
 
 ASSERT(pcidevs_locked());
@@ -1340,37 +1382,18 @@ int domain_context_mapping_one(
 if ( iommu_hwdom_passthrough && is_hardware_domain(domain) )
 {
 context_set_translation_type(*context, CONTEXT_TT_PASS_THRU);
-agaw = level_to_agaw(iommu->nr_pt_levels);
 }
 else
 {
 spin_lock(>arch.mapping_lock);
 
-/* Ensure we have pagetables allocated down to leaf PTE. */
-if ( 

[PATCH v9 6/8] common/grant_table: batch flush I/O TLB

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

This patch avoids calling iommu_iotlb_flush() for each individual GNTTABOP and
instead calls iommu_iotlb_flush_all() at the end of a batch. This should mean
non-singleton map/unmap operations perform better.

NOTE: A batch is the number of operations done before a pre-emption check and,
  in the case of unmap, a TLB flush.

Suggested-by: Jan Beulich 
Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
---
Cc: Andrew Cooper 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Julien Grall 
Cc: Stefano Stabellini 
Cc: Wei Liu 

v6:
 - Fix spelling of 'preemption'
 - Drop unneeded 'currd' stack variable

v5:
 - Add batching to gnttab_map_grant_ref() to handle flushing before pre-
   emption check
 - Maintain per-op flushing in the case of singletons

v3:
 - New in v3
---
 xen/common/grant_table.c | 199 ++-
 1 file changed, 133 insertions(+), 66 deletions(-)

diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index beb6b2d40d..1e3d7a2d33 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -241,7 +241,13 @@ struct gnttab_unmap_common {
 grant_ref_t ref;
 };
 
-/* Number of unmap operations that are done between each tlb flush */
+/* Number of map operations that are done between each preemption check */
+#define GNTTAB_MAP_BATCH_SIZE 32
+
+/*
+ * Number of unmap operations that are done between each tlb flush and
+ * preemption check.
+ */
 #define GNTTAB_UNMAP_BATCH_SIZE 32
 
 
@@ -979,7 +985,7 @@ static unsigned int mapkind(
 
 static void
 map_grant_ref(
-struct gnttab_map_grant_ref *op)
+struct gnttab_map_grant_ref *op, bool do_flush, unsigned int *flush_flags)
 {
 struct domain *ld, *rd, *owner = NULL;
 struct grant_table *lgt, *rgt;
@@ -1229,12 +1235,11 @@ map_grant_ref(
 if ( kind )
 {
 dfn_t dfn = _dfn(mfn_x(mfn));
-unsigned int flush_flags = 0;
 int err;
 
-err = iommu_map(ld, dfn, mfn, 1, kind, _flags);
-if ( !err )
-err = iommu_iotlb_flush(ld, dfn, 1, flush_flags);
+err = iommu_map(ld, dfn, mfn, 1, kind, flush_flags);
+if ( do_flush && !err )
+err = iommu_iotlb_flush(ld, dfn, 1, *flush_flags);
 if ( err )
 {
 double_gt_unlock(lgt, rgt);
@@ -1319,29 +1324,59 @@ static long
 gnttab_map_grant_ref(
 XEN_GUEST_HANDLE_PARAM(gnttab_map_grant_ref_t) uop, unsigned int count)
 {
-int i;
-struct gnttab_map_grant_ref op;
+unsigned int done = 0;
+int rc = 0;
 
-for ( i = 0; i < count; i++ )
+while ( count )
 {
-if ( i && hypercall_preempt_check() )
-return i;
+unsigned int i, c = min_t(unsigned int, count, GNTTAB_MAP_BATCH_SIZE);
+unsigned int flush_flags = 0;
 
-if ( unlikely(__copy_from_guest_offset(, uop, i, 1)) )
-return -EFAULT;
+for ( i = 0; i < c; i++ )
+{
+struct gnttab_map_grant_ref op;
 
-map_grant_ref();
+if ( unlikely(__copy_from_guest(, uop, 1)) )
+{
+rc = -EFAULT;
+break;
+}
 
-if ( unlikely(__copy_to_guest_offset(uop, i, , 1)) )
-return -EFAULT;
+map_grant_ref(, c == 1, _flags);
+
+if ( unlikely(__copy_to_guest(uop, , 1)) )
+{
+rc = -EFAULT;
+break;
+}
+
+guest_handle_add_offset(uop, 1);
+}
+
+if ( c > 1 )
+{
+int err = iommu_iotlb_flush_all(current->domain, flush_flags);
+
+if ( !rc )
+rc = err;
+}
+
+if ( rc )
+break;
+
+count -= c;
+done += c;
+
+if ( count && hypercall_preempt_check() )
+return done;
 }
 
-return 0;
+return rc;
 }
 
 static void
 unmap_common(
-struct gnttab_unmap_common *op)
+struct gnttab_unmap_common *op, bool do_flush, unsigned int *flush_flags)
 {
 domid_t  dom;
 struct domain   *ld, *rd;
@@ -1485,22 +1520,20 @@ unmap_common(
 {
 unsigned int kind;
 dfn_t dfn = _dfn(mfn_x(op->mfn));
-unsigned int flush_flags = 0;
 int err = 0;
 
 double_gt_lock(lgt, rgt);
 
 kind = mapkind(lgt, rd, op->mfn);
 if ( !kind )
-err = iommu_unmap(ld, dfn, 1, _flags);
+err = iommu_unmap(ld, dfn, 1, flush_flags);
 else if ( !(kind & MAPKIND_WRITE) )
-err = iommu_map(ld, dfn, op->mfn, 1, IOMMUF_readable,
-_flags);
+err = iommu_map(ld, dfn, op->mfn, 1, IOMMUF_readable, flush_flags);
 
 double_gt_unlock(lgt, rgt);
 
-if ( !err )
-err = iommu_iotlb_flush(ld, dfn, 1, flush_flags);
+if ( do_flush && !err )
+err = iommu_iotlb_flush(ld, dfn, 1, *flush_flags);
 if ( err )
  

[PATCH v9 8/8] iommu: stop calling IOMMU page tables 'p2m tables'

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

It's confusing and not consistent with the terminology introduced with 'dfn_t'.
Just call them IOMMU page tables.

Also remove a pointless check of the 'acpi_drhd_units' list in
vtd_dump_page_table_level(). If the list is empty then IOMMU mappings would
not have been enabled for the domain in the first place.

NOTE: All calls to printk() have also been removed from
  iommu_dump_page_tables(); the implementation specific code is now
  responsible for all output.
  The check for the global 'iommu_enabled' has also been replaced by an
  ASSERT since iommu_dump_page_tables() is not registered as a key handler
  unless IOMMU mappings are enabled.
  Error messages are now prefixed with the name of the function.

Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
---
Cc: Andrew Cooper 
Cc: Kevin Tian 

v6:
 - Cosmetic adjustment
 - Drop use of __func__

v5:
 - Make sure domain id is in the output
 - Use VTDPREFIX in output for consistency

v2:
 - Moved all output into implementation specific code
---
 xen/drivers/passthrough/amd/pci_amd_iommu.c | 20 +++---
 xen/drivers/passthrough/iommu.c | 21 ---
 xen/drivers/passthrough/vtd/iommu.c | 30 -
 xen/include/xen/iommu.h |  2 +-
 4 files changed, 33 insertions(+), 40 deletions(-)

diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c 
b/xen/drivers/passthrough/amd/pci_amd_iommu.c
index 3390c22cf3..5fe9dc849d 100644
--- a/xen/drivers/passthrough/amd/pci_amd_iommu.c
+++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c
@@ -491,8 +491,8 @@ static int amd_iommu_group_id(u16 seg, u8 bus, u8 devfn)
 
 #include 
 
-static void amd_dump_p2m_table_level(struct page_info* pg, int level, 
- paddr_t gpa, int indent)
+static void amd_dump_page_table_level(struct page_info *pg, int level,
+  paddr_t gpa, int indent)
 {
 paddr_t address;
 struct amd_iommu_pte *table_vaddr;
@@ -504,7 +504,7 @@ static void amd_dump_p2m_table_level(struct page_info* pg, 
int level,
 table_vaddr = __map_domain_page(pg);
 if ( table_vaddr == NULL )
 {
-printk("Failed to map IOMMU domain page %"PRIpaddr"\n", 
+printk("AMD IOMMU failed to map domain page %"PRIpaddr"\n",
 page_to_maddr(pg));
 return;
 }
@@ -521,7 +521,7 @@ static void amd_dump_p2m_table_level(struct page_info* pg, 
int level,
 
 if ( pde->next_level && (pde->next_level != (level - 1)) )
 {
-printk("IOMMU p2m table error. next_level = %d, expected %d\n",
+printk("AMD IOMMU table error. next_level = %d, expected %d\n",
pde->next_level, level - 1);
 
 continue;
@@ -529,7 +529,7 @@ static void amd_dump_p2m_table_level(struct page_info* pg, 
int level,
 
 address = gpa + amd_offset_level_address(index, level);
 if ( pde->next_level >= 1 )
-amd_dump_p2m_table_level(
+amd_dump_page_table_level(
 mfn_to_page(_mfn(pde->mfn)), pde->next_level,
 address, indent + 1);
 else
@@ -542,16 +542,16 @@ static void amd_dump_p2m_table_level(struct page_info* 
pg, int level,
 unmap_domain_page(table_vaddr);
 }
 
-static void amd_dump_p2m_table(struct domain *d)
+static void amd_dump_page_tables(struct domain *d)
 {
 const struct domain_iommu *hd = dom_iommu(d);
 
 if ( !hd->arch.amd.root_table )
 return;
 
-printk("p2m table has %u levels\n", hd->arch.amd.paging_mode);
-amd_dump_p2m_table_level(hd->arch.amd.root_table,
- hd->arch.amd.paging_mode, 0, 0);
+printk("AMD IOMMU %pd table has %u levels\n", d, hd->arch.amd.paging_mode);
+amd_dump_page_table_level(hd->arch.amd.root_table,
+  hd->arch.amd.paging_mode, 0, 0);
 }
 
 static const struct iommu_ops __initconstrel _iommu_ops = {
@@ -578,7 +578,7 @@ static const struct iommu_ops __initconstrel _iommu_ops = {
 .suspend = amd_iommu_suspend,
 .resume = amd_iommu_resume,
 .crash_shutdown = amd_iommu_crash_shutdown,
-.dump_p2m_table = amd_dump_p2m_table,
+.dump_page_tables = amd_dump_page_tables,
 };
 
 static const struct iommu_init_ops __initconstrel _iommu_init_ops = {
diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 90748062e5..8fae77b593 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 
-static void iommu_dump_p2m_table(unsigned char key);
+static void iommu_dump_page_tables(unsigned char key);
 
 unsigned int __read_mostly iommu_dev_iotlb_timeout = 1000;
 integer_param("iommu_dev_iotlb_timeout", iommu_dev_iotlb_timeout);
@@ -212,7 +212,7 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
 if ( !is_iommu_enabled(d) )
 return;
 
-register_keyhandler('o', 

[PATCH v9 0/8] IOMMU cleanup

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

Paul Durrant (8):
  x86/iommu: convert VT-d code to use new page table allocator
  iommu: remove unused iommu_ops method and tasklet
  iommu: flush I/O TLB if iommu_map() or iommu_unmap() fail
  iommu: make map and unmap take a page count, similar to flush
  remove remaining uses of iommu_legacy_map/unmap
  common/grant_table: batch flush I/O TLB
  iommu: remove the share_p2m operation
  iommu: stop calling IOMMU page tables 'p2m tables'

 xen/arch/x86/mm.c   |  22 +-
 xen/arch/x86/mm/p2m-ept.c   |  21 +-
 xen/arch/x86/mm/p2m-pt.c|  16 +-
 xen/arch/x86/mm/p2m.c   |  27 ++-
 xen/arch/x86/x86_64/mm.c|  20 +-
 xen/common/grant_table.c| 208 --
 xen/common/memory.c |   7 +-
 xen/drivers/passthrough/amd/iommu.h |   2 +-
 xen/drivers/passthrough/amd/iommu_map.c |   4 +-
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  20 +-
 xen/drivers/passthrough/arm/ipmmu-vmsa.c|   2 +-
 xen/drivers/passthrough/arm/smmu.c  |   2 +-
 xen/drivers/passthrough/iommu.c | 118 +++---
 xen/drivers/passthrough/vtd/extern.h|   2 +-
 xen/drivers/passthrough/vtd/iommu.c | 225 +---
 xen/drivers/passthrough/vtd/x86/vtd.c   |   2 +-
 xen/drivers/passthrough/x86/iommu.c |   2 +-
 xen/include/xen/iommu.h |  36 +---
 18 files changed, 372 insertions(+), 364 deletions(-)
---
Cc: Andrew Cooper 
Cc: Bertrand Marquis 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Jan Beulich 
Cc: Julien Grall 
Cc: Jun Nakajima 
Cc: Kevin Tian 
Cc: Oleksandr Tyshchenko 
Cc: "Roger Pau Monné" 
Cc: Stefano Stabellini 
Cc: Wei Liu 
-- 
2.20.1




[PATCH v9 3/8] iommu: flush I/O TLB if iommu_map() or iommu_unmap() fail

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

This patch adds a full I/O TLB flush to the error paths of iommu_map() and
iommu_unmap().

Without this change callers need constructs such as:

rc = iommu_map/unmap(...)
err = iommu_flush(...)
if ( !rc )
  rc = err;

With this change, it can be simplified to:

rc = iommu_map/unmap(...)
if ( !rc )
  rc = iommu_flush(...)

because, if the map or unmap fails the flush will be unnecessary. This saves
a stack variable and generally makes the call sites tidier.

Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
---

v6:
 - Remove stray blank

v5:
 - Avoid unnecessary flushing if 'page_order' is 0
 - Add missing indirection on 'flush_flags'

v2:
 - New in v2
---
 xen/drivers/passthrough/iommu.c | 34 +
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 660dc5deb2..eb65631d59 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -274,6 +274,13 @@ int iommu_map(struct domain *d, dfn_t dfn, mfn_t mfn,
 break;
 }
 
+/*
+ * Something went wrong so, if we were dealing with more than a single
+ * page, flush everything and clear flush flags.
+ */
+if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_flags) 
)
+*flush_flags = 0;
+
 return rc;
 }
 
@@ -283,14 +290,8 @@ int iommu_legacy_map(struct domain *d, dfn_t dfn, mfn_t 
mfn,
 unsigned int flush_flags = 0;
 int rc = iommu_map(d, dfn, mfn, page_order, flags, _flags);
 
-if ( !this_cpu(iommu_dont_flush_iotlb) )
-{
-int err = iommu_iotlb_flush(d, dfn, (1u << page_order),
-flush_flags);
-
-if ( !rc )
-rc = err;
-}
+if ( !this_cpu(iommu_dont_flush_iotlb) && !rc )
+rc = iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags);
 
 return rc;
 }
@@ -330,6 +331,13 @@ int iommu_unmap(struct domain *d, dfn_t dfn, unsigned int 
page_order,
 }
 }
 
+/*
+ * Something went wrong so, if we were dealing with more than a single
+ * page, flush everything and clear flush flags.
+ */
+if ( page_order && unlikely(rc) && !iommu_iotlb_flush_all(d, *flush_flags) 
)
+*flush_flags = 0;
+
 return rc;
 }
 
@@ -338,14 +346,8 @@ int iommu_legacy_unmap(struct domain *d, dfn_t dfn, 
unsigned int page_order)
 unsigned int flush_flags = 0;
 int rc = iommu_unmap(d, dfn, page_order, _flags);
 
-if ( !this_cpu(iommu_dont_flush_iotlb) )
-{
-int err = iommu_iotlb_flush(d, dfn, (1u << page_order),
-flush_flags);
-
-if ( !rc )
-rc = err;
-}
+if ( !this_cpu(iommu_dont_flush_iotlb) && !rc )
+rc = iommu_iotlb_flush(d, dfn, (1u << page_order), flush_flags);
 
 return rc;
 }
-- 
2.20.1




[PATCH v9 4/8] iommu: make map and unmap take a page count, similar to flush

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

At the moment iommu_map() and iommu_unmap() take a page order rather than a
count, whereas iommu_iotlb_flush() takes a page count rather than an order.
This patch makes them consistent with each other, opting for a page count since
CPU page orders are not necessarily the same as those of an IOMMU.

NOTE: The 'page_count' parameter is also made an unsigned long in all the
  aforementioned functions.

Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
Reviewed-by: Julien Grall 
---
Cc: Andrew Cooper 
Cc: Wei Liu 
Cc: "Roger Pau Monné" 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Stefano Stabellini 
Cc: Jun Nakajima 
Cc: Kevin Tian 
Cc: Bertrand Marquis 
Cc: Oleksandr Tyshchenko 

v8:
 - Fix IPMMU-VMSA code too

v7:
 - Fix ARM build

v6:
 - Fix missing conversion to unsigned long in AMD code
 - Fixed unconverted call to iommu_legacy_unmap() in x86/mm.c
 - s/1ul/1 in the grant table code

v5:
 - Re-worked to just use a page count, rather than both a count and an order

v2:
 - New in v2
---
 xen/arch/x86/mm.c|  8 --
 xen/arch/x86/mm/p2m-ept.c|  6 ++--
 xen/arch/x86/mm/p2m-pt.c |  4 +--
 xen/arch/x86/mm/p2m.c|  5 ++--
 xen/arch/x86/x86_64/mm.c |  4 +--
 xen/common/grant_table.c |  6 ++--
 xen/drivers/passthrough/amd/iommu.h  |  2 +-
 xen/drivers/passthrough/amd/iommu_map.c  |  4 +--
 xen/drivers/passthrough/arm/ipmmu-vmsa.c |  2 +-
 xen/drivers/passthrough/arm/smmu.c   |  2 +-
 xen/drivers/passthrough/iommu.c  | 35 +++-
 xen/drivers/passthrough/vtd/iommu.c  |  4 +--
 xen/drivers/passthrough/x86/iommu.c  |  2 +-
 xen/include/xen/iommu.h  | 12 
 14 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 42a6dc9ba4..9447dabc50 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2441,7 +2441,7 @@ static int cleanup_page_mappings(struct page_info *page)
 
 if ( d && unlikely(need_iommu_pt_sync(d)) && is_pv_domain(d) )
 {
-int rc2 = iommu_legacy_unmap(d, _dfn(mfn), PAGE_ORDER_4K);
+int rc2 = iommu_legacy_unmap(d, _dfn(mfn), 1u << PAGE_ORDER_4K);
 
 if ( !rc )
 rc = rc2;
@@ -2968,9 +2968,11 @@ static int _get_page_type(struct page_info *page, 
unsigned long type,
 mfn_t mfn = page_to_mfn(page);
 
 if ( (x & PGT_type_mask) == PGT_writable_page )
-rc = iommu_legacy_unmap(d, _dfn(mfn_x(mfn)), PAGE_ORDER_4K);
+rc = iommu_legacy_unmap(d, _dfn(mfn_x(mfn)),
+1ul << PAGE_ORDER_4K);
 else
-rc = iommu_legacy_map(d, _dfn(mfn_x(mfn)), mfn, PAGE_ORDER_4K,
+rc = iommu_legacy_map(d, _dfn(mfn_x(mfn)), mfn,
+  1ul << PAGE_ORDER_4K,
   IOMMUF_readable | IOMMUF_writable);
 
 if ( unlikely(rc) )
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index b8154a7ecc..12cf38f6eb 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -843,14 +843,14 @@ out:
  need_modify_vtd_table )
 {
 if ( iommu_use_hap_pt(d) )
-rc = iommu_iotlb_flush(d, _dfn(gfn), (1u << order),
+rc = iommu_iotlb_flush(d, _dfn(gfn), 1ul << order,
(iommu_flags ? IOMMU_FLUSHF_added : 0) |
(vtd_pte_present ? IOMMU_FLUSHF_modified
 : 0));
 else if ( need_iommu_pt_sync(d) )
 rc = iommu_flags ?
-iommu_legacy_map(d, _dfn(gfn), mfn, order, iommu_flags) :
-iommu_legacy_unmap(d, _dfn(gfn), order);
+iommu_legacy_map(d, _dfn(gfn), mfn, 1ul << order, iommu_flags) 
:
+iommu_legacy_unmap(d, _dfn(gfn), 1ul << order);
 }
 
 unmap_domain_page(table);
diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c
index badb26bc34..3af51be78e 100644
--- a/xen/arch/x86/mm/p2m-pt.c
+++ b/xen/arch/x86/mm/p2m-pt.c
@@ -679,9 +679,9 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t 
mfn,
 if ( need_iommu_pt_sync(p2m->domain) &&
  (iommu_old_flags != iommu_pte_flags || old_mfn != mfn_x(mfn)) )
 rc = iommu_pte_flags
- ? iommu_legacy_map(d, _dfn(gfn), mfn, page_order,
+ ? iommu_legacy_map(d, _dfn(gfn), mfn, 1ul << page_order,
 iommu_pte_flags)
- : iommu_legacy_unmap(d, _dfn(gfn), page_order);
+ : iommu_legacy_unmap(d, _dfn(gfn), 1ul << page_order);
 
 /*
  * Free old intermediate tables if necessary.  This has to be the
diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index db7bde0230..928344be30 100644
--- a/xen/arch/x86/mm/p2m.c
+++ 

[PATCH v9 5/8] remove remaining uses of iommu_legacy_map/unmap

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

The 'legacy' functions do implicit flushing so amend the callers to do the
appropriate flushing.

Unfortunately, because of the structure of the P2M code, we cannot remove
the per-CPU 'iommu_dont_flush_iotlb' global and the optimization it
facilitates. Checking of this flag is now done only in relevant callers of
iommu_iotlb_flush(). Also, 'iommu_dont_flush_iotlb' is now declared
as bool (rather than bool_t) and setting/clearing it are no longer pointlessly
gated on is_iommu_enabled() returning true. (Arguably it is also pointless to
gate the call to iommu_iotlb_flush() on that condition - since it is a no-op
in that case - but the if clause allows the scope of a stack variable to be
restricted).

NOTE: The code in memory_add() now sets 'ret' if iommu_map() or
  iommu_iotlb_flush() fails.

Signed-off-by: Paul Durrant 
---
Cc: Jan Beulich 
Cc: Andrew Cooper 
Cc: Wei Liu 
Cc: "Roger Pau Monné" 
Cc: George Dunlap 
Cc: Ian Jackson 
Cc: Julien Grall 
Cc: Stefano Stabellini 
Cc: Jun Nakajima 
Cc: Kevin Tian 

v9:
 - Moved check of 'iommu_dont_flush_iotlb' out of iommu_iotlb_flush() and
   into callers to avoid re-introducing a problem on Arm
 - Dropped Jan's R-b due to change

v6:
 - Fix formatting problem in memory_add()

v5:
 - Re-base
 - Removed failure case on overflow of unsigned int as it is no longer
   necessary

v3:
 - Same as v2; elected to implement batch flushing in the grant table code as
   a subsequent patch

v2:
 - Shorten the diff (mainly because of a prior patch introducing automatic
   flush-on-fail into iommu_map() and iommu_unmap())
---
 xen/arch/x86/mm.c   | 24 +---
 xen/arch/x86/mm/p2m-ept.c   | 21 +
 xen/arch/x86/mm/p2m-pt.c| 16 
 xen/arch/x86/mm/p2m.c   | 25 +
 xen/arch/x86/x86_64/mm.c| 20 +++-
 xen/common/grant_table.c| 29 ++---
 xen/common/memory.c |  7 +++
 xen/drivers/passthrough/iommu.c | 23 ---
 xen/include/xen/iommu.h | 21 +
 9 files changed, 96 insertions(+), 90 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 9447dabc50..fec8a19920 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -2441,10 +2441,16 @@ static int cleanup_page_mappings(struct page_info *page)
 
 if ( d && unlikely(need_iommu_pt_sync(d)) && is_pv_domain(d) )
 {
-int rc2 = iommu_legacy_unmap(d, _dfn(mfn), 1u << PAGE_ORDER_4K);
+unsigned int flush_flags = 0;
+int err;
+
+err = iommu_unmap(d, _dfn(mfn), 1ul << PAGE_ORDER_4K, 
_flags);
+if ( !err && !this_cpu(iommu_dont_flush_iotlb) )
+err = iommu_iotlb_flush(d, _dfn(mfn), 1ul << PAGE_ORDER_4K,
+flush_flags);
 
 if ( !rc )
-rc = rc2;
+rc = err;
 }
 
 if ( likely(!is_special_page(page)) )
@@ -2966,14 +2972,18 @@ static int _get_page_type(struct page_info *page, 
unsigned long type,
 if ( d && unlikely(need_iommu_pt_sync(d)) && is_pv_domain(d) )
 {
 mfn_t mfn = page_to_mfn(page);
+dfn_t dfn = _dfn(mfn_x(mfn));
+unsigned int flush_flags = 0;
 
 if ( (x & PGT_type_mask) == PGT_writable_page )
-rc = iommu_legacy_unmap(d, _dfn(mfn_x(mfn)),
-1ul << PAGE_ORDER_4K);
+rc = iommu_unmap(d, dfn, 1ul << PAGE_ORDER_4K, _flags);
 else
-rc = iommu_legacy_map(d, _dfn(mfn_x(mfn)), mfn,
-  1ul << PAGE_ORDER_4K,
-  IOMMUF_readable | IOMMUF_writable);
+rc = iommu_map(d, dfn, mfn, 1ul << PAGE_ORDER_4K,
+   IOMMUF_readable | IOMMUF_writable, 
_flags);
+
+if ( !rc && !this_cpu(iommu_dont_flush_iotlb) )
+rc = iommu_iotlb_flush(d, dfn, 1ul << PAGE_ORDER_4K,
+   flush_flags);
 
 if ( unlikely(rc) )
 {
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index 12cf38f6eb..71473fd31d 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -842,15 +842,20 @@ out:
 if ( rc == 0 && p2m_is_hostp2m(p2m) &&
  need_modify_vtd_table )
 {
-if ( iommu_use_hap_pt(d) )
-rc = iommu_iotlb_flush(d, _dfn(gfn), 1ul << order,
-   (iommu_flags ? IOMMU_FLUSHF_added : 0) |
-   (vtd_pte_present ? IOMMU_FLUSHF_modified
-: 0));
-else if ( need_iommu_pt_sync(d) )
+unsigned int flush_flags = 0;
+
+if ( need_iommu_pt_sync(d) )
 rc = iommu_flags ?
-

[PATCH v9 1/8] x86/iommu: convert VT-d code to use new page table allocator

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

This patch converts the VT-d code to use the new IOMMU page table allocator
function. This allows all the free-ing code to be removed (since it is now
handled by the general x86 code) which reduces TLB and cache thrashing as well
as shortening the code.

The scope of the mapping_lock in intel_iommu_quarantine_init() has also been
increased slightly; it should have always covered accesses to
'arch.vtd.pgd_maddr'.

NOTE: The common IOMMU needs a slight modification to avoid scheduling the
  cleanup tasklet if the free_page_table() method is not present (since
  the tasklet will unconditionally call it).

Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
---
Cc: Kevin Tian 

v2:
 - New in v2 (split from "add common page-table allocator")
---
 xen/drivers/passthrough/iommu.c |   6 +-
 xen/drivers/passthrough/vtd/iommu.c | 101 ++--
 2 files changed, 39 insertions(+), 68 deletions(-)

diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 1d644844ab..2b1db8022c 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -225,8 +225,10 @@ static void iommu_teardown(struct domain *d)
 {
 struct domain_iommu *hd = dom_iommu(d);
 
-hd->platform_ops->teardown(d);
-tasklet_schedule(_pt_cleanup_tasklet);
+iommu_vcall(hd->platform_ops, teardown, d);
+
+if ( hd->platform_ops->free_page_table )
+tasklet_schedule(_pt_cleanup_tasklet);
 }
 
 void iommu_domain_destroy(struct domain *d)
diff --git a/xen/drivers/passthrough/vtd/iommu.c 
b/xen/drivers/passthrough/vtd/iommu.c
index 94e0455a4d..607e8b5e65 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -265,10 +265,15 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, 
u64 addr, int alloc)
 
 addr &= (((u64)1) << addr_width) - 1;
 ASSERT(spin_is_locked(>arch.mapping_lock));
-if ( !hd->arch.vtd.pgd_maddr &&
- (!alloc ||
-  ((hd->arch.vtd.pgd_maddr = alloc_pgtable_maddr(1, hd->node)) == 0)) )
-goto out;
+if ( !hd->arch.vtd.pgd_maddr )
+{
+struct page_info *pg;
+
+if ( !alloc || !(pg = iommu_alloc_pgtable(domain)) )
+goto out;
+
+hd->arch.vtd.pgd_maddr = page_to_maddr(pg);
+}
 
 parent = (struct dma_pte *)map_vtd_domain_page(hd->arch.vtd.pgd_maddr);
 while ( level > 1 )
@@ -279,13 +284,16 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, 
u64 addr, int alloc)
 pte_maddr = dma_pte_addr(*pte);
 if ( !pte_maddr )
 {
+struct page_info *pg;
+
 if ( !alloc )
 break;
 
-pte_maddr = alloc_pgtable_maddr(1, hd->node);
-if ( !pte_maddr )
+pg = iommu_alloc_pgtable(domain);
+if ( !pg )
 break;
 
+pte_maddr = page_to_maddr(pg);
 dma_set_pte_addr(*pte, pte_maddr);
 
 /*
@@ -675,45 +683,6 @@ static void dma_pte_clear_one(struct domain *domain, 
uint64_t addr,
 unmap_vtd_domain_page(page);
 }
 
-static void iommu_free_pagetable(u64 pt_maddr, int level)
-{
-struct page_info *pg = maddr_to_page(pt_maddr);
-
-if ( pt_maddr == 0 )
-return;
-
-PFN_ORDER(pg) = level;
-spin_lock(_pt_cleanup_lock);
-page_list_add_tail(pg, _pt_cleanup_list);
-spin_unlock(_pt_cleanup_lock);
-}
-
-static void iommu_free_page_table(struct page_info *pg)
-{
-unsigned int i, next_level = PFN_ORDER(pg) - 1;
-u64 pt_maddr = page_to_maddr(pg);
-struct dma_pte *pt_vaddr, *pte;
-
-PFN_ORDER(pg) = 0;
-pt_vaddr = (struct dma_pte *)map_vtd_domain_page(pt_maddr);
-
-for ( i = 0; i < PTE_NUM; i++ )
-{
-pte = _vaddr[i];
-if ( !dma_pte_present(*pte) )
-continue;
-
-if ( next_level >= 1 )
-iommu_free_pagetable(dma_pte_addr(*pte), next_level);
-
-dma_clear_pte(*pte);
-iommu_sync_cache(pte, sizeof(struct dma_pte));
-}
-
-unmap_vtd_domain_page(pt_vaddr);
-free_pgtable_maddr(pt_maddr);
-}
-
 static int iommu_set_root_entry(struct vtd_iommu *iommu)
 {
 u32 sts;
@@ -1748,16 +1717,7 @@ static void iommu_domain_teardown(struct domain *d)
 xfree(mrmrr);
 }
 
-ASSERT(is_iommu_enabled(d));
-
-if ( iommu_use_hap_pt(d) )
-return;
-
-spin_lock(>arch.mapping_lock);
-iommu_free_pagetable(hd->arch.vtd.pgd_maddr,
- agaw_to_level(hd->arch.vtd.agaw));
 hd->arch.vtd.pgd_maddr = 0;
-spin_unlock(>arch.mapping_lock);
 }
 
 static int __must_check intel_iommu_map_page(struct domain *d, dfn_t dfn,
@@ -2669,23 +2629,28 @@ static void vtd_dump_p2m_table(struct domain *d)
 static int __init intel_iommu_quarantine_init(struct domain *d)
 {
 struct domain_iommu *hd = dom_iommu(d);
+struct page_info *pg;
 struct dma_pte *parent;
 unsigned int agaw = 

[PATCH v9 2/8] iommu: remove unused iommu_ops method and tasklet

2020-09-15 Thread Paul Durrant
From: Paul Durrant 

The VT-d and AMD IOMMU implementations both use the general x86 IOMMU page
table allocator and ARM always shares page tables with CPU. Hence there is no
need to retain the free_page_table() method or the tasklet which invokes it.

Signed-off-by: Paul Durrant 
Reviewed-by: Jan Beulich 
---

v2:
  - New in v2 (split from "add common page-table allocator")
---
 xen/drivers/passthrough/iommu.c | 25 -
 xen/include/xen/iommu.h |  2 --
 2 files changed, 27 deletions(-)

diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c
index 2b1db8022c..660dc5deb2 100644
--- a/xen/drivers/passthrough/iommu.c
+++ b/xen/drivers/passthrough/iommu.c
@@ -49,10 +49,6 @@ bool_t __read_mostly amd_iommu_perdev_intremap = 1;
 
 DEFINE_PER_CPU(bool_t, iommu_dont_flush_iotlb);
 
-DEFINE_SPINLOCK(iommu_pt_cleanup_lock);
-PAGE_LIST_HEAD(iommu_pt_cleanup_list);
-static struct tasklet iommu_pt_cleanup_tasklet;
-
 static int __init parse_iommu_param(const char *s)
 {
 const char *ss;
@@ -226,9 +222,6 @@ static void iommu_teardown(struct domain *d)
 struct domain_iommu *hd = dom_iommu(d);
 
 iommu_vcall(hd->platform_ops, teardown, d);
-
-if ( hd->platform_ops->free_page_table )
-tasklet_schedule(_pt_cleanup_tasklet);
 }
 
 void iommu_domain_destroy(struct domain *d)
@@ -368,23 +361,6 @@ int iommu_lookup_page(struct domain *d, dfn_t dfn, mfn_t 
*mfn,
 return iommu_call(hd->platform_ops, lookup_page, d, dfn, mfn, flags);
 }
 
-static void iommu_free_pagetables(void *unused)
-{
-do {
-struct page_info *pg;
-
-spin_lock(_pt_cleanup_lock);
-pg = page_list_remove_head(_pt_cleanup_list);
-spin_unlock(_pt_cleanup_lock);
-if ( !pg )
-return;
-iommu_vcall(iommu_get_ops(), free_page_table, pg);
-} while ( !softirq_pending(smp_processor_id()) );
-
-tasklet_schedule_on_cpu(_pt_cleanup_tasklet,
-cpumask_cycle(smp_processor_id(), 
_online_map));
-}
-
 int iommu_iotlb_flush(struct domain *d, dfn_t dfn, unsigned int page_count,
   unsigned int flush_flags)
 {
@@ -508,7 +484,6 @@ int __init iommu_setup(void)
 #ifndef iommu_intremap
 printk("Interrupt remapping %sabled\n", iommu_intremap ? "en" : "dis");
 #endif
-tasklet_init(_pt_cleanup_tasklet, iommu_free_pagetables, NULL);
 }
 
 return rc;
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 3272874958..1831dc66b0 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -263,8 +263,6 @@ struct iommu_ops {
 int __must_check (*lookup_page)(struct domain *d, dfn_t dfn, mfn_t *mfn,
 unsigned int *flags);
 
-void (*free_page_table)(struct page_info *);
-
 #ifdef CONFIG_X86
 int (*enable_x2apic)(void);
 void (*disable_x2apic)(void);
-- 
2.20.1




Re: [PATCH v3] x86/HVM: more consistently set I/O completion

2020-09-15 Thread Jan Beulich
On 27.08.2020 09:09, Jan Beulich wrote:
> Doing this just in hvm_emulate_one_insn() is not enough.
> hvm_ud_intercept() and hvm_emulate_one_vm_event() can get invoked for
> insns requiring one or more continuations, and at least in principle
> hvm_emulate_one_mmio() could, too. Without proper setting of the field,
> handle_hvm_io_completion() will do nothing completion-wise, and in
> particular the missing re-invocation of the insn emulation paths will
> lead to emulation caching not getting disabled in due course, causing
> the ASSERT() in {svm,vmx}_vmenter_helper() to trigger.
> 
> Reported-by: Don Slutz 
> 
> Similar considerations go for the clearing of vio->mmio_access, which
> gets moved as well.
> 
> Additionally all updating of vio->mmio_* now gets done dependent upon
> the new completion value, rather than hvm_ioreq_needs_completion()'s
> return value. This is because it is the completion chosen which controls
> what path will be taken when handling the completion, not the simple
> boolean return value. In particular, PIO completion doesn't involve
> going through the insn emulator, and hence emulator state ought to get
> cleared early (or it won't get cleared at all).
> 
> The new logic, besides allowing for a caller override for the
> continuation type to be set (for VMX real mode emulation), will also
> avoid setting an MMIO completion when a simpler PIO one will do. This
> is a minor optimization only as a side effect - the behavior is strictly
> needed at least for hvm_ud_intercept(), as only memory accesses can
> successfully complete through handle_mmio(). Care of course needs to be
> taken to correctly deal with "mixed" insns (doing both MMIO and PIO at
> the same time, i.e. INS/OUTS). For this, hvmemul_validate() now latches
> whether the insn being emulated is a memory access, as this information
> is no longer easily available at the point where we want to consume it.
> 
> Note that the presence of non-NULL .validate fields in the two ops
> structures in hvm_emulate_one_mmio() was really necessary even before
> the changes here: Without this, passing non-NULL as middle argument to
> hvm_emulate_init_once() is meaningless.
> 
> The restrictions on when the #UD intercept gets actually enabled are why
> it was decided that this is not a security issue:
> - the "hvm_fep" option to enable its use is a debugging option only,
> - for the cross-vendor case is considered experimental, even if
>   unfortunately SUPPORT.md doesn't have an explicit statement about
>   this.
> The other two affected functions are
> - hvm_emulate_one_vm_event(), used for introspection,
> - hvm_emulate_one_mmio(), used for Dom0 only,
> which aren't qualifying this as needing an XSA either.
> 
> Signed-off-by: Jan Beulich 
> Tested-by: Don Slutz 
> ---
> v3: Add comment ahead of _hvm_emulate_one(). Add parentheses in a
> conditional expr. Justify why this does not need an XSA.
> v2: Make updating of vio->mmio_* fields fully driven by the new
> completion value.
> ---
> I further think that the entire tail of _hvm_emulate_one() (everything
> past the code changed/added there by this patch) wants skipping in case
> a completion is needed, at the very least for the mmio and realmode
> cases, where we know we'll come back here.

Does one of the two of you have an opinion on this aspect?

Jan



Re: libxenguest and xenguest.h

2020-09-15 Thread Jürgen Groß

On 15.09.20 10:11, Jan Beulich wrote:

On 15.09.2020 10:06, Jürgen Groß wrote:

On 15.09.20 09:55, Jan Beulich wrote:

On 15.09.2020 07:18, Jürgen Groß wrote:

Andy has reported a libxenguest related build failure of qemu when
building qemu outside the Xen build environment. Problem is xenguest.h
now including xenctrl_dom.h, which is including xen/libelf/libelf.h.

The underlying problem is that libxenguest is basically offering some
"official" functions via xenguest.h, while some other functions are
only Xen internally usable and are defined in xenctrl_dom.h.

This is a rather weird construction and I'm seeing the following
solutions:

1. Make xen/include/xen/libelf.h a public header (or split the parts
  needed by xenguest.h into a public header)


Besides being conceptually wrong imo, this could (afaict) cause name
space issues to consumers. This definitely gets a -1 from me, if not
a -2.


2. Reflect the two parts of libxenguest by carving out the xenctrl_dom.h
  defined parts into a new library not made public

3. Make the xenctrl_dom.h interfaces internal again by not adding it to
  the installed headers


This option would seem to imply that qemu has no real need to include
this header, as otherwise how would this address the build issue?


In fact qemu doesn't need to include xenguest.h at all, but this was
just how the problem was discovered.

So before my patches xenctrl_dom.h (or xc_dom.h as it was named at that
time) was included only from Xen sources (libxenguest, libxl, pvgrub).
Basically there was a rather large part of libxenguest ot really usable
by anyone outside the Xen build system. External users could use only
the interfaces which are declared in xenguest.h.


But then - what did change?


I included xenctrl_dom.h from xenguest.h as it contains interfaces of
libxenguest.


In any event, to me it looks like headers shouldn't have mixed purpose.
Either they're internal (and don't get installed), or they're meant for
public consumption (and then everything that's in there).


Right.

And my thinking for libxenguest was that all interfaces it offers should
be in a public header.


Juergen



Re: [PATCH v3] EFI: free unused boot mem in at least some cases

2020-09-15 Thread Jan Beulich
On 15.09.2020 10:08, Jan Beulich wrote:
> Address at least the primary reason why 52bba67f8b87 ("efi/boot: Don't
> free ebmalloc area at all") was put in place: Make xen_in_range() aware
> of the freed range. This is in particular relevant for EFI-enabled
> builds not actually running on EFI, as the entire range will be unused
> in this case.
> 
> Signed-off-by: Jan Beulich 
> Acked-by: Roger Pau Monné 
> ---
> v3: Don't free the memory twice.
> v2: Also adjust the two places where comments point out that they need
> to remain in sync with xen_in_range(). Add assertions to
> xen_in_range().

I've sent this just for the sake of having it on the list; I'm about
to commit it with Roger's ack.

Jan



Re: libxenguest and xenguest.h

2020-09-15 Thread Jan Beulich
On 15.09.2020 10:06, Jürgen Groß wrote:
> On 15.09.20 09:55, Jan Beulich wrote:
>> On 15.09.2020 07:18, Jürgen Groß wrote:
>>> Andy has reported a libxenguest related build failure of qemu when
>>> building qemu outside the Xen build environment. Problem is xenguest.h
>>> now including xenctrl_dom.h, which is including xen/libelf/libelf.h.
>>>
>>> The underlying problem is that libxenguest is basically offering some
>>> "official" functions via xenguest.h, while some other functions are
>>> only Xen internally usable and are defined in xenctrl_dom.h.
>>>
>>> This is a rather weird construction and I'm seeing the following
>>> solutions:
>>>
>>> 1. Make xen/include/xen/libelf.h a public header (or split the parts
>>>  needed by xenguest.h into a public header)
>>
>> Besides being conceptually wrong imo, this could (afaict) cause name
>> space issues to consumers. This definitely gets a -1 from me, if not
>> a -2.
>>
>>> 2. Reflect the two parts of libxenguest by carving out the xenctrl_dom.h
>>>  defined parts into a new library not made public
>>>
>>> 3. Make the xenctrl_dom.h interfaces internal again by not adding it to
>>>  the installed headers
>>
>> This option would seem to imply that qemu has no real need to include
>> this header, as otherwise how would this address the build issue?
> 
> In fact qemu doesn't need to include xenguest.h at all, but this was
> just how the problem was discovered.
> 
> So before my patches xenctrl_dom.h (or xc_dom.h as it was named at that
> time) was included only from Xen sources (libxenguest, libxl, pvgrub).
> Basically there was a rather large part of libxenguest ot really usable
> by anyone outside the Xen build system. External users could use only
> the interfaces which are declared in xenguest.h.

But then - what did change?

In any event, to me it looks like headers shouldn't have mixed purpose.
Either they're internal (and don't get installed), or they're meant for
public consumption (and then everything that's in there).

Jan



[PATCH v3] EFI: free unused boot mem in at least some cases

2020-09-15 Thread Jan Beulich
Address at least the primary reason why 52bba67f8b87 ("efi/boot: Don't
free ebmalloc area at all") was put in place: Make xen_in_range() aware
of the freed range. This is in particular relevant for EFI-enabled
builds not actually running on EFI, as the entire range will be unused
in this case.

Signed-off-by: Jan Beulich 
Acked-by: Roger Pau Monné 
---
v3: Don't free the memory twice.
v2: Also adjust the two places where comments point out that they need
to remain in sync with xen_in_range(). Add assertions to
xen_in_range().
---
The remaining issue could be addressed too, by making the area 2M in
size and 2M-aligned.

--- a/xen/arch/x86/efi/stub.c
+++ b/xen/arch/x86/efi/stub.c
@@ -52,6 +52,12 @@ bool efi_enabled(unsigned int feature)
 
 void __init efi_init_memory(void) { }
 
+bool efi_boot_mem_unused(unsigned long *start, unsigned long *end)
+{
+*start = *end = (unsigned long)_end;
+return false;
+}
+
 void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { }
 
 bool efi_rs_using_pgtables(void)
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -830,6 +830,7 @@ void __init noreturn __start_xen(unsigne
 module_t *mod;
 unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1];
 int i, j, e820_warn = 0, bytes = 0;
+unsigned long eb_start, eb_end;
 bool acpi_boot_table_init_done = false, relocated = false;
 int ret;
 struct ns16550_defaults ns16550 = {
@@ -1145,7 +1146,8 @@ void __init noreturn __start_xen(unsigne
 
 /*
  * This needs to remain in sync with xen_in_range() and the
- * respective reserve_e820_ram() invocation below.
+ * respective reserve_e820_ram() invocation below. No need to
+ * query efi_boot_mem_unused() here, though.
  */
 mod[mbi->mods_count].mod_start = virt_to_mfn(_stext);
 mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
@@ -1417,8 +1419,18 @@ void __init noreturn __start_xen(unsigne
 if ( !xen_phys_start )
 panic("Not enough memory to relocate Xen\n");
 
+/* FIXME: Putting a hole in .bss would shatter the large page mapping. */
+if ( using_2M_mapping() )
+efi_boot_mem_unused(NULL, NULL);
+
 /* This needs to remain in sync with xen_in_range(). */
-reserve_e820_ram(_e820, __pa(_stext), __pa(__2M_rwdata_end));
+if ( efi_boot_mem_unused(_start, _end) )
+{
+reserve_e820_ram(_e820, __pa(_stext), __pa(eb_start));
+reserve_e820_ram(_e820, __pa(eb_end), __pa(__2M_rwdata_end));
+}
+else
+reserve_e820_ram(_e820, __pa(_stext), __pa(__2M_rwdata_end));
 
 /* Late kexec reservation (dynamic start address). */
 kexec_reserve_area(_e820);
@@ -1979,7 +1991,7 @@ int __hwdom_init xen_in_range(unsigned l
 paddr_t start, end;
 int i;
 
-enum { region_s3, region_ro, region_rw, nr_regions };
+enum { region_s3, region_ro, region_rw, region_bss, nr_regions };
 static struct {
 paddr_t s, e;
 } xen_regions[nr_regions] __hwdom_initdata;
@@ -2004,6 +2016,14 @@ int __hwdom_init xen_in_range(unsigned l
 /* hypervisor .data + .bss */
 xen_regions[region_rw].s = __pa(&__2M_rwdata_start);
 xen_regions[region_rw].e = __pa(&__2M_rwdata_end);
+if ( efi_boot_mem_unused(, ) )
+{
+ASSERT(__pa(start) >= xen_regions[region_rw].s);
+ASSERT(__pa(end) <= xen_regions[region_rw].e);
+xen_regions[region_rw].e = __pa(start);
+xen_regions[region_bss].s = __pa(end);
+xen_regions[region_bss].e = __pa(&__2M_rwdata_end);
+}
 }
 
 start = (paddr_t)mfn << PAGE_SHIFT;
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -1,3 +1,4 @@
+#include 
 #include 
 #include 
 #include 
@@ -364,6 +365,8 @@ void tboot_shutdown(uint32_t shutdown_ty
 /* if this is S3 then set regions to MAC */
 if ( shutdown_type == TB_SHUTDOWN_S3 )
 {
+unsigned long s, e;
+
 /*
  * Xen regions for tboot to MAC. This needs to remain in sync with
  * xen_in_range().
@@ -378,6 +381,15 @@ void tboot_shutdown(uint32_t shutdown_ty
 /* hypervisor .data + .bss */
 g_tboot_shared->mac_regions[2].start = 
(uint64_t)__pa(&__2M_rwdata_start);
 g_tboot_shared->mac_regions[2].size = __2M_rwdata_end - 
__2M_rwdata_start;
+if ( efi_boot_mem_unused(, ) )
+{
+g_tboot_shared->mac_regions[2].size =
+s - (unsigned long)__2M_rwdata_start;
+g_tboot_shared->mac_regions[3].start = __pa(e);
+g_tboot_shared->mac_regions[3].size =
+(unsigned long)__2M_rwdata_end - e;
+g_tboot_shared->num_mac_regions = 4;
+}
 
 /*
  * MAC domains and other Xen memory
--- a/xen/common/efi/ebmalloc.c
+++ b/xen/common/efi/ebmalloc.c
@@ -1,5 +1,6 @@
 #include "efi.h"
 #include 
+#include 
 
 #ifdef CONFIG_ARM
 /*
@@ -21,7 +22,7 @@
 
 static char 

Re: libxenguest and xenguest.h

2020-09-15 Thread Jürgen Groß

On 15.09.20 09:55, Jan Beulich wrote:

On 15.09.2020 07:18, Jürgen Groß wrote:

Andy has reported a libxenguest related build failure of qemu when
building qemu outside the Xen build environment. Problem is xenguest.h
now including xenctrl_dom.h, which is including xen/libelf/libelf.h.

The underlying problem is that libxenguest is basically offering some
"official" functions via xenguest.h, while some other functions are
only Xen internally usable and are defined in xenctrl_dom.h.

This is a rather weird construction and I'm seeing the following
solutions:

1. Make xen/include/xen/libelf.h a public header (or split the parts
 needed by xenguest.h into a public header)


Besides being conceptually wrong imo, this could (afaict) cause name
space issues to consumers. This definitely gets a -1 from me, if not
a -2.


2. Reflect the two parts of libxenguest by carving out the xenctrl_dom.h
 defined parts into a new library not made public

3. Make the xenctrl_dom.h interfaces internal again by not adding it to
 the installed headers


This option would seem to imply that qemu has no real need to include
this header, as otherwise how would this address the build issue?


In fact qemu doesn't need to include xenguest.h at all, but this was
just how the problem was discovered.

So before my patches xenctrl_dom.h (or xc_dom.h as it was named at that
time) was included only from Xen sources (libxenguest, libxl, pvgrub).
Basically there was a rather large part of libxenguest ot really usable
by anyone outside the Xen build system. External users could use only
the interfaces which are declared in xenguest.h.


Juergen



Re: [PATCH 1/3] x86/shim: fix build with PV_SHIM_EXCLUSIVE and SHADOW_PAGING

2020-09-15 Thread Jan Beulich
On 14.09.2020 18:44, Roger Pau Monné wrote:
> On Mon, Sep 14, 2020 at 02:38:49PM +0200, Jan Beulich wrote:
>> While there's little point in enabling both, the combination ought to at
>> least build correctly. Drop the direct PV_SHIM_EXCLUSIVE conditionals
>> and instead zap PG_log_dirty to zero under the right conditions, and key
>> other #ifdef-s off of that.
>>
>> While there also expand on ded576ce07e9 ("x86/shadow: dirty VRAM
>> tracking is needed for HVM only"): There was yet another is_hvm_domain()
>> missing, and code touching the struct fields needs to be guarded by
>> suitable #ifdef-s as well. While there also guard shadow-mode-only
>> fields accordingly.
>>
>> Fixes: 8b5b49ceb3d9 ("x86: don't include domctl and alike in shim-exclusive 
>> builds")
>> Reported-by: Andrew Cooper 
>> Signed-off-by: Jan Beulich 
> 
> Reviewed-by: Roger Pau Monné 

Thanks.

> We seem to be growing more and more ifdefs which is not ideal IMO, we
> should rather aim to remove them by splitting code into separate
> compilation units. There doesn't seem to be much option to split
> stuff in this case, so be it.

Right - I was indeed wondering whether maybe shadow_vram_{get,put}_l1e()
could be moved into hvm.c, but I didn't want to right away take the time
to check, as it seemed more important to get the build issue addressed.

Beyond the #ifdef-s added there the majority of the changes here are
merely adjustments to existing ones. (I'd except the new PG_log_dirty
conditional #define-s from the ones wanting better alternatives, as we
have been doing the same already for other PG_* constants.)

Jan



Re: libxenguest and xenguest.h

2020-09-15 Thread Jan Beulich
On 15.09.2020 07:18, Jürgen Groß wrote:
> Andy has reported a libxenguest related build failure of qemu when
> building qemu outside the Xen build environment. Problem is xenguest.h
> now including xenctrl_dom.h, which is including xen/libelf/libelf.h.
> 
> The underlying problem is that libxenguest is basically offering some
> "official" functions via xenguest.h, while some other functions are
> only Xen internally usable and are defined in xenctrl_dom.h.
> 
> This is a rather weird construction and I'm seeing the following
> solutions:
> 
> 1. Make xen/include/xen/libelf.h a public header (or split the parts
> needed by xenguest.h into a public header)

Besides being conceptually wrong imo, this could (afaict) cause name
space issues to consumers. This definitely gets a -1 from me, if not
a -2.

> 2. Reflect the two parts of libxenguest by carving out the xenctrl_dom.h
> defined parts into a new library not made public
> 
> 3. Make the xenctrl_dom.h interfaces internal again by not adding it to
> the installed headers

This option would seem to imply that qemu has no real need to include
this header, as otherwise how would this address the build issue?

Jan



Re: [RFC PATCH] efi: const correct EFI functions

2020-09-15 Thread Jan Beulich
On 14.09.2020 17:05, Trammell Hudson wrote:
> On Monday, September 14, 2020 10:55 AM, Jan Beulich  wrote:
>> On 14.09.2020 16:46, Trammell Hudson wrote:
>>> Option 3 would be to write wrappers for the few functions that are
>>> used in the EFI boot path that cast-away the constness of their
>>> arguments (while also silently cursing the UEFI forum for not
>>> writing const-correct code).
>>
>> This would be kind of a last resort fallback (except for the
>> cursing, which of course we can do at any time).
> 
> Since you didn't like the time travel option, I checked to see
> which functions would need to be wrapped.  It is a surprisingly
> small number:
> 
> #define PrintStr(s) StdOut->OutputString(StdOut, (CHAR16 *)(s))
> #define PrintErr(s) StdErr->OutputString(StdErr, (CHAR16 *)(s))
> #define efi_file_open(file,handle,name,mode,attr) \
>   (file)->Open(file, handle, (CHAR16 *)(name), mode, attr)
> #define shim_verify(shim, ptr, len) \
>   (shim)->Verify((void *)(ptr), len)

That's surprisingly few. What about e.g. HandleProtocol() and
LocateHandle()? GUIDs shouldn't really be non-const either.

Jan



Re: [PATCH v2 2/7] kernel/resource: move and rename IORESOURCE_MEM_DRIVER_MANAGED

2020-09-15 Thread David Hildenbrand
On 15.09.20 04:20, Wei Yang wrote:
> On Tue, Sep 08, 2020 at 10:10:07PM +0200, David Hildenbrand wrote:
>> IORESOURCE_MEM_DRIVER_MANAGED currently uses an unused PnP bit, which is
>> always set to 0 by hardware. This is far from beautiful (and confusing),
>> and the bit only applies to SYSRAM. So let's move it out of the
>> bus-specific (PnP) defined bits.
>>
>> We'll add another SYSRAM specific bit soon. If we ever need more bits for
>> other purposes, we can steal some from "desc", or reshuffle/regroup what we
>> have.
> 
> I think you make this definition because we use IORESOURCE_SYSRAM_RAM for
> hotpluged memory? So we make them all in IORESOURCE_SYSRAM_XXX family?

Yeah, to specify based on the extended MEM type SYSRAM. Because it
really only applies to that.

-- 
Thanks,

David / dhildenb




Re: [PATCH v2 1/7] kernel/resource: make release_mem_region_adjustable() never fail

2020-09-15 Thread David Hildenbrand


>> static int __ref try_remove_memory(int nid, u64 start, u64 size)
>> {
>>  int rc = 0;
>> @@ -1777,7 +1757,7 @@ static int __ref try_remove_memory(int nid, u64 start, 
>> u64 size)
>>  memblock_remove(start, size);
>>  }
>>
>> -__release_memory_resource(start, size);
>> +release_mem_region_adjustable(_resource, start, size);
>>
> 
> Seems the only user of release_mem_region_adjustable() is here, can we move
> iomem_resource into the function body? Actually, we don't iterate the resource
> tree from any level. We always start from the root.

You mean, making iomem_resource implicit? I can spot that something
similar was done for

#define devm_release_mem_region(dev, start, n) \
__devm_release_region(dev, _resource, (start), (n))

I'll send an addon patch for that, ok? - thanks.

-- 
Thanks,

David / dhildenb




  1   2   >