]> xenbits.xensource.com Git - people/hx242/xen.git/log
people/hx242/xen.git
5 years agox86/setup: do not map memory when passing to allocators directnonmap-v2.3
Hongyan Xia [Wed, 9 Oct 2019 13:54:23 +0000 (14:54 +0100)]
x86/setup: do not map memory when passing to allocators

Also destroy the existing mappings to the direct map region when passing
to allocators.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86: properly (un)map pages in restore_all_guests.
Hongyan Xia [Fri, 13 Sep 2019 16:59:30 +0000 (17:59 +0100)]
x86: properly (un)map pages in restore_all_guests.

Before, it assumed both cr3 could be accessed via a direct map. This is
no longer true.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/mm: don't call unmap on a xenheap allocation
Hongyan Xia [Mon, 30 Sep 2019 18:23:25 +0000 (19:23 +0100)]
x86/mm: don't call unmap on a xenheap allocation

This used to work when unmap on the direct map was just a no-op, which
is no longer true.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/domain_page: only enable the fast paths when there is direct map
Hongyan Xia [Tue, 1 Oct 2019 09:50:24 +0000 (10:50 +0100)]
x86/domain_page: only enable the fast paths when there is direct map

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agoxen/page_alloc: add a path for xenheap when there is no direct map
Hongyan Xia [Tue, 1 Oct 2019 09:30:45 +0000 (10:30 +0100)]
xen/page_alloc: add a path for xenheap when there is no direct map

When there is not an always-mapped direct map, xenheap allocations need
to be mapped and unmapped on-demand.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agoacpi: add a path to work with no direct map
Hongyan Xia [Fri, 13 Sep 2019 08:21:11 +0000 (09:21 +0100)]
acpi: add a path to work with no direct map

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agoxen/page_alloc: statically allocate bootmem_region_list
Hongyan Xia [Tue, 1 Oct 2019 09:13:20 +0000 (10:13 +0100)]
xen/page_alloc: statically allocate bootmem_region_list

This is to avoid all sorts of bootstrapping problems, especially when
we do not have a direct map.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/pv: refactor how building dom0 in PV handles domheap mappings
Hongyan Xia [Fri, 13 Sep 2019 14:23:52 +0000 (15:23 +0100)]
x86/pv: refactor how building dom0 in PV handles domheap mappings

Building a PV dom0 is allocating from the domheap but uses it like the
xenheap. This is clearly wrong. Fix.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/pv: domheap pages should be mapped while relocating initrd
Wei Liu [Tue, 19 Feb 2019 15:45:12 +0000 (15:45 +0000)]
x86/pv: domheap pages should be mapped while relocating initrd

Xen shouldn't use domheap page as if they were xenheap pages. Map and
unmap pages accordingly.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/domain_page: use PMAP when d/vcache is not ready
Hongyan Xia [Mon, 30 Sep 2019 17:06:51 +0000 (18:06 +0100)]
x86/domain_page: use PMAP when d/vcache is not ready

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/mapcache: initialise the mapcache even for the idle domain
Hongyan Xia [Wed, 11 Sep 2019 09:37:14 +0000 (10:37 +0100)]
x86/mapcache: initialise the mapcache even for the idle domain

In situations where PMAP cannot be used or the mapcache of a domain is
simply not ready, we need to have a mapcache in the idle domain to map
pages when there is no direct map.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agoKconfig: add an option to enable and disable the direct map
Hongyan Xia [Wed, 9 Oct 2019 13:41:40 +0000 (14:41 +0100)]
Kconfig: add an option to enable and disable the direct map

This only works for x86 for now but can include Arm at some point.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86: lift vcpu mapcache to arch_vcpu
Wei Liu [Mon, 17 Dec 2018 15:58:13 +0000 (15:58 +0000)]
x86: lift vcpu mapcache to arch_vcpu

It is going to be needed by HVM as well, because we want even HVM vcpu
to have a per-vcpu mapcache.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86: lift domain mapcache to arch_domain
Wei Liu [Mon, 17 Dec 2018 15:50:49 +0000 (15:50 +0000)]
x86: lift domain mapcache to arch_domain

It is going to be needed by HVM as well, because we want even HVM
domain to have a per-domain mapcache.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86: add Persistent Map (PMAP) infrastructure
Wei Liu [Fri, 11 Jan 2019 17:20:21 +0000 (17:20 +0000)]
x86: add Persistent Map (PMAP) infrastructure

The basic idea is like Persistent Kernel Map (PKMAP) in linux. We
pre-populate all the relevant page tables before system is fully set
up.

It is needed to bootstrap map domain page infrastructure -- we need
some way to map pages to set up the mapcache without a direct map.

In order to keep the number of entries minimal, this infrastructure
can only be used by one CPU at a time.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/mm: drop _new suffix for page table APIs
Wei Liu [Fri, 8 Feb 2019 17:19:26 +0000 (17:19 +0000)]
x86/mm: drop _new suffix for page table APIs

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
Changed since v1:
- Fix rebase conflicts against new master and other changes since v1.

Changed since v2:
- Also drop _new for the fix of l2t leak.

5 years agox86: switch to use domheap page for page tables
Wei Liu [Tue, 5 Feb 2019 17:20:11 +0000 (17:20 +0000)]
x86: switch to use domheap page for page tables

Modify all the _new APIs to handle domheap pages.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: drop old page table APIs
Wei Liu [Tue, 5 Feb 2019 17:06:43 +0000 (17:06 +0000)]
x86/mm: drop old page table APIs

Now that we've switched all users to the new APIs, the old ones aren't
needed anymore.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86: remove lXe_to_lYe in __start_xen
Wei Liu [Tue, 5 Feb 2019 17:04:56 +0000 (17:04 +0000)]
x86: remove lXe_to_lYe in __start_xen

Properly map and unmap page tables where necessary.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/pv: properly map and unmap page table in dom0_construct_pv
Wei Liu [Tue, 5 Feb 2019 16:35:28 +0000 (16:35 +0000)]
x86/pv: properly map and unmap page table in dom0_construct_pv

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/pv: properly map and unmap page tables in mark_pv_pt_pages_rdonly
Wei Liu [Tue, 5 Feb 2019 16:32:54 +0000 (16:32 +0000)]
x86/pv: properly map and unmap page tables in mark_pv_pt_pages_rdonly

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/smpboot: remove lXe_to_lYe in cleanup_cpu_root_pgt
Wei Liu [Tue, 5 Feb 2019 13:51:12 +0000 (13:51 +0000)]
x86/smpboot: remove lXe_to_lYe in cleanup_cpu_root_pgt

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in subarch_memory_op
Wei Liu [Tue, 5 Feb 2019 13:47:07 +0000 (13:47 +0000)]
x86_64/mm: map and unmap page tables in subarch_memory_op

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in subarch_init_memory
Wei Liu [Tue, 5 Feb 2019 13:44:22 +0000 (13:44 +0000)]
x86_64/mm: map and unmap page tables in subarch_init_memory

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in cleanup_frame_table
Wei Liu [Tue, 5 Feb 2019 13:35:19 +0000 (13:35 +0000)]
x86_64/mm: map and unmap page tables in cleanup_frame_table

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in setup_compat_m2p_table
Wei Liu [Tue, 5 Feb 2019 13:25:05 +0000 (13:25 +0000)]
x86_64/mm: map and unmap page tables in setup_compat_m2p_table

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in destroy_m2p_mapping
Wei Liu [Tue, 5 Feb 2019 13:19:43 +0000 (13:19 +0000)]
x86_64/mm: map and unmap page tables in destroy_m2p_mapping

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping
Wei Liu [Tue, 5 Feb 2019 13:09:18 +0000 (13:09 +0000)]
x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in share_hotadd_m2p_table
Wei Liu [Tue, 5 Feb 2019 13:06:08 +0000 (13:06 +0000)]
x86_64/mm: map and unmap page tables in share_hotadd_m2p_table

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: map and unmap page tables in m2p_mapped
Wei Liu [Tue, 5 Feb 2019 12:56:41 +0000 (12:56 +0000)]
x86_64/mm: map and unmap page tables in m2p_mapped

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/shim: map and unmap page tables in replace_va_mapping
Wei Liu [Tue, 5 Feb 2019 12:48:03 +0000 (12:48 +0000)]
x86/shim: map and unmap page tables in replace_va_mapping

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/smpboot: drop lXe_to_lYe invocations from cleanup_cpu_root_pgt
Wei Liu [Mon, 4 Feb 2019 18:16:30 +0000 (18:16 +0000)]
x86/smpboot: drop lXe_to_lYe invocations from cleanup_cpu_root_pgt

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/smpboot: switch pl*e to use new APIs in clone_mapping
Wei Liu [Mon, 4 Feb 2019 17:57:33 +0000 (17:57 +0000)]
x86/smpboot: switch pl*e to use new APIs in clone_mapping

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/smpboot: clone_mapping should have one exit path
Wei Liu [Mon, 4 Feb 2019 17:48:45 +0000 (17:48 +0000)]
x86/smpboot: clone_mapping should have one exit path

We will soon need to clean up page table mappings in the exit path.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/smpboot: add emacs block
Wei Liu [Mon, 4 Feb 2019 17:45:50 +0000 (17:45 +0000)]
x86/smpboot: add emacs block

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agoefi: switch EFI L4 table to use new APIs
Wei Liu [Mon, 4 Feb 2019 17:19:27 +0000 (17:19 +0000)]
efi: switch EFI L4 table to use new APIs

This requires storing the MFN instead of linear address of the L4
table. Adjust code accordingly.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agoefi: add emacs block to boot.c
Wei Liu [Mon, 4 Feb 2019 17:01:10 +0000 (17:01 +0000)]
efi: add emacs block to boot.c

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agoefi: use new page table APIs in efi_init_memory
Wei Liu [Mon, 4 Feb 2019 17:00:59 +0000 (17:00 +0000)]
efi: use new page table APIs in efi_init_memory

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agoefi: avoid using global variable in copy_mapping
Wei Liu [Mon, 4 Feb 2019 16:40:34 +0000 (16:40 +0000)]
efi: avoid using global variable in copy_mapping

We will soon switch efi_l4_table to use ephemeral mapping. Make
copy_mapping take a pointer to the mapping instead of using the global
variable.

No functional change intended.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agoefi: use new page table APIs in copy_mapping
Wei Liu [Mon, 4 Feb 2019 16:01:03 +0000 (16:01 +0000)]
efi: use new page table APIs in copy_mapping

After inspection ARM doesn't have alloc_xen_pagetable so this function
is x86 only, which means it is safe for us to change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
XXX test this in gitlab ci to be sure.

5 years agox86_64/mm: drop lXe_to_lYe invocations from setup_m2p_table
Wei Liu [Thu, 31 Jan 2019 19:04:23 +0000 (19:04 +0000)]
x86_64/mm: drop lXe_to_lYe invocations from setup_m2p_table

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: switch to new APIs in setup_m2p_table
Wei Liu [Thu, 31 Jan 2019 19:01:11 +0000 (19:01 +0000)]
x86_64/mm: switch to new APIs in setup_m2p_table

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: introduce pl2e in setup_m2p_table
Wei Liu [Thu, 31 Jan 2019 18:52:48 +0000 (18:52 +0000)]
x86_64/mm: introduce pl2e in setup_m2p_table

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm.c: remove code that serves no purpose in setup_m2p_table
Wei Liu [Thu, 31 Jan 2019 18:49:36 +0000 (18:49 +0000)]
x86_64/mm.c: remove code that serves no purpose in setup_m2p_table

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: drop l4e_to_l3e invocation from paging_init
Wei Liu [Thu, 31 Jan 2019 18:31:04 +0000 (18:31 +0000)]
x86_64/mm: drop l4e_to_l3e invocation from paging_init

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86_64/mm: switch to new APIs in paging_init
Wei Liu [Tue, 29 Jan 2019 14:40:26 +0000 (14:40 +0000)]
x86_64/mm: switch to new APIs in paging_init

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
Changed since v1:
- Use a global mapping for compat_idle_pg_table_l2, otherwise
  l2_ro_mpt will unmap it.

5 years agox86_64/mm: introduce pl2e in paging_init
Wei Liu [Thu, 31 Jan 2019 18:06:53 +0000 (18:06 +0000)]
x86_64/mm: introduce pl2e in paging_init

Introduce pl2e so that we can use l2_ro_mpt to point to the page table
itself.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: switch to new APIs in arch_init_memory
Wei Liu [Tue, 29 Jan 2019 14:15:47 +0000 (14:15 +0000)]
x86/mm: switch to new APIs in arch_init_memory

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: drop lXe_to_lYe invocations from modify_xen_mappings
Wei Liu [Fri, 1 Feb 2019 13:15:59 +0000 (13:15 +0000)]
x86/mm: drop lXe_to_lYe invocations from modify_xen_mappings

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: switch to new APIs in modify_xen_mappings
Wei Liu [Tue, 29 Jan 2019 14:03:48 +0000 (14:03 +0000)]
x86/mm: switch to new APIs in modify_xen_mappings

Page tables allocated in that function should be mapped and unmapped
now.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
Changed since v1:
- Remove redundant lines.

5 years agox86/mm: drop lXe_to_lYe invocations in map_pages_to_xen
Wei Liu [Fri, 1 Feb 2019 12:39:26 +0000 (12:39 +0000)]
x86/mm: drop lXe_to_lYe invocations in map_pages_to_xen

Map and unmap page tables where necessary.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
Changed since v2:
- Fix a leak in mapping l2t.

5 years agox86/mm: switch to new APIs in map_pages_to_xen
Wei Liu [Tue, 29 Jan 2019 13:56:43 +0000 (13:56 +0000)]
x86/mm: switch to new APIs in map_pages_to_xen

Page tables allocated in that function should be mapped and unmapped
now.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
---
Changed since v1:
- Remove redundant lines.

5 years agox86/mm: rewrite virt_to_xen_l*e
Wei Liu [Tue, 29 Jan 2019 12:42:23 +0000 (12:42 +0000)]
x86/mm: rewrite virt_to_xen_l*e

Rewrite that function to use the new APIs. Modify its callers to unmap
the pointer returned.

Note that the change of virt_to_xen_l1e also requires vmap_to_mfn to
unmap the page.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/mm: change pl*e to l*t in virt_to_xen_l*e
Wei Liu [Tue, 29 Jan 2019 12:54:48 +0000 (12:54 +0000)]
x86/mm: change pl*e to l*t in virt_to_xen_l*e

We will need to have a variable named pl*e when we rewrite
virt_to_xen_l*e. Change pl*e to l*t to reflect better its purpose.
This will make reviewing later patch easier.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Hongyan Xia <hongyax@amazon.com>
5 years agox86/mm: add an end_of_loop label in modify_xen_mappings
Wei Liu [Mon, 28 Jan 2019 18:45:06 +0000 (18:45 +0000)]
x86/mm: add an end_of_loop label in modify_xen_mappings

We will soon need to clean up mappings whenever the out most loop
is ended. Add a new label and turn relevant continue's into goto's.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: make sure there is one exit path for modify_xen_mappings
Wei Liu [Mon, 28 Jan 2019 18:41:26 +0000 (18:41 +0000)]
x86/mm: make sure there is one exit path for modify_xen_mappings

We will soon need to handle dynamically mapping / unmapping page
tables in the said function.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: add an end_of_loop label in map_pages_to_xen
Wei Liu [Mon, 28 Jan 2019 18:35:52 +0000 (18:35 +0000)]
x86/mm: add an end_of_loop label in map_pages_to_xen

We will soon need to clean up mappings whenever the out most loop is
ended. Add a new label and turn relevant continue's into goto's.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: map_pages_to_xen should have one exit path
Wei Liu [Mon, 28 Jan 2019 18:30:47 +0000 (18:30 +0000)]
x86/mm: map_pages_to_xen should have one exit path

We will soon rewrite the function to handle dynamically mapping and
unmapping of page tables.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: introduce l{1,2}t local variables to modify_xen_mappings
Wei Liu [Mon, 28 Jan 2019 18:10:10 +0000 (18:10 +0000)]
x86/mm: introduce l{1,2}t local variables to modify_xen_mappings

The pl2e and pl1e variables are heavily (ab)used in that function.  It
is fine at the moment because all page tables are always mapped so
there is no need to track the life time of each variable.

We will soon have the requirement to map and unmap page tables. We
need to track the life time of each variable to avoid leakage.

Introduce some l{1,2}t variables with limited scope so that we can
track life time of pointers to xen page tables more easily.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86/mm: introduce l{1,2}t local variables to map_pages_to_xen
Wei Liu [Mon, 28 Jan 2019 17:54:24 +0000 (17:54 +0000)]
x86/mm: introduce l{1,2}t local variables to map_pages_to_xen

The pl2e and pl1e variables are heavily (ab)used in that function. It
is fine at the moment because all page tables are always mapped so
there is no need to track the life time of each variable.

We will soon have the requirement to map and unmap page tables. We
need to track the life time of each variable to avoid leakage.

Introduce some l{1,2}t variables with limited scope so that we can
track life time of pointers to xen page tables more easily.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86: introduce a new set of APIs to manage Xen page tables
Wei Liu [Wed, 23 Jan 2019 15:33:07 +0000 (15:33 +0000)]
x86: introduce a new set of APIs to manage Xen page tables

We are going to switch to using domheap page for page tables.
A new set of APIs is introduced to allocate, map, unmap and free pages
for page tables.

The allocation and deallocation work on mfn_t but not page_info,
because they are required to work even before frame table is set up.

Implement the old functions with the new ones. We will rewrite, site
by site, other mm functions that manipulate page tables to use the new
APIs.

Note these new APIs still use xenheap page underneath and no actual
map and unmap is done so that we don't break xen half way. They will
be switched to use domheap and dynamic mappings when usage of old APIs
is eliminated.

No functional change intended in this patch.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agox86: move some xen mm function declarations
Wei Liu [Wed, 23 Jan 2019 15:17:41 +0000 (15:17 +0000)]
x86: move some xen mm function declarations

They were put into page.h but mm.h is more appropriate.

The real reason is that I will be adding some new functions which
takes mfn_t. It turns out it is a bit difficult to do in page.h.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
5 years agostubdom/vtpm: include stdio.h for declaration of printf
Olaf Hering [Wed, 2 Oct 2019 17:05:36 +0000 (19:05 +0200)]
stubdom/vtpm: include stdio.h for declaration of printf

The function read_vtpmblk uses printf(3), but stdio.h is not included
in this file. This results in a warning from gcc-7:

vtpmblk.c: In function 'read_vtpmblk':
vtpmblk.c:322:7: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
       printf("Expected: ");
vtpmblk.c:322:7: warning: incompatible implicit declaration of built-in function 'printf'
vtpmblk.c:322:7: note: include '<stdio.h>' or provide a declaration of 'printf'

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agodocs/sphinx: Indent cleanup
Andrew Cooper [Fri, 19 Jul 2019 07:57:50 +0000 (08:57 +0100)]
docs/sphinx: Indent cleanup

Sphinx, its linters, and RST modes in common editors, expect 3 spaces of
indentation.  Some bits already conform to this expectation.  Update the
rest to match.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Lars Kurth <lars.kurth@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agox86/microcode: Drop trailing whitespace in printk()
Andrew Cooper [Tue, 8 Oct 2019 19:23:26 +0000 (20:23 +0100)]
x86/microcode: Drop trailing whitespace in printk()

This has actually been present since c/s bd7c09c0 in 2008, and survived
through all of the recent microcode refactoring.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoPrep for 4.13.0-rc1: Set version to -rc
Ian Jackson [Mon, 14 Oct 2019 10:31:31 +0000 (11:31 +0100)]
Prep for 4.13.0-rc1: Set version to -rc

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
5 years agoPrep for 4.13.0-rc1: Pin QEMU_* and MINIOS to tags
Ian Jackson [Mon, 14 Oct 2019 10:30:52 +0000 (11:30 +0100)]
Prep for 4.13.0-rc1: Pin QEMU_* and MINIOS to tags

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
5 years agoxen/arm: domain_build: harden make_cpus_node()
Stefano Stabellini [Thu, 10 Oct 2019 00:42:11 +0000 (17:42 -0700)]
xen/arm: domain_build: harden make_cpus_node()

make_cpus_node() is using a static buffer to generate the FDT node name.
While mpdir_aff is a 64-bit integer, we only ever use the bits [23:0] as
only AFF{0, 1, 2} are supported for now.

To avoid any potential issues in the future, check that mpdir_aff has
only bits [23:0] set.

Take the opportunity to reduce the size of the buffer. Indeed, only 8
characters are needed to print a 32-bit hexadecimal number. So
sizeof("cpu@") + 8 + 1 (for '\0') = 13 characters is sufficient.

Fixes: c81a791d34 (xen/arm: Set 'reg' of cpu node for dom0 to match MPIDR's affinity)
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Julien Grall <julien.grall@arm.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agox86/mm: don't needlessly veto migration
Paul Durrant [Thu, 10 Oct 2019 15:45:15 +0000 (17:45 +0200)]
x86/mm: don't needlessly veto migration

Now that xl.cfg has an option to explicitly enable IOMMU mappings for a
domain, migration may be needlessly vetoed due to the check of
is_iommu_enabled() in paging_log_dirty_enable().
There is actually no need to prevent logdirty from being enabled unless
devices are assigned to a domain.

NOTE: While in the neighbourhood, the bool_t parameter type in
      paging_log_dirty_enable() is replaced with a bool and the format
      of the comment in assign_device() is fixed.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agox86/efi: properly handle 0 in pixel reserved bitmask
Igor Druzhinin [Thu, 10 Oct 2019 14:50:50 +0000 (16:50 +0200)]
x86/efi: properly handle 0 in pixel reserved bitmask

In some graphics modes firmware is allowed to return 0 in pixel reserved
bitmask which doesn't go against UEFI Spec 2.8 (12.9 Graphics Output Protocol).

Without this change non-TrueColor modes won't work which will cause
GOP init to fail - observed while trying to boot EFI Xen with Cirrus VGA.

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoxen/docs: arm: Update dom0less binding and example
Julien Grall [Tue, 13 Aug 2019 21:11:15 +0000 (22:11 +0100)]
xen/docs: arm: Update dom0less binding and example

The binding for the dom0less module does not match Xen implementation.
Any module should contain the compatible "multiboot,module" to be
recognized.

This was clearly an oversight as other examples with Xen code base
provide the compatible "multiboot,module".

So fix the binding and the example associated to it.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agox86/hvm: Fix the use of "hap=0" following c/s c0902a9a143a
Andrew Cooper [Wed, 9 Oct 2019 18:21:14 +0000 (19:21 +0100)]
x86/hvm: Fix the use of "hap=0" following c/s c0902a9a143a

c/s c0902a9a143a refactored hvm_enable() a little, but dropped the logic which
cleared hap_supported in the case that the user had asked for it off.

This results in Xen booting up, claiming:

  (XEN) HVM: Hardware Assisted Paging (HAP) detected but disabled

but with HAP advertised via sysctl, and XEN_DOMCTL_CDF_hap being accepted in
domain_create().

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Wei Liu <wl@xen.org>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agopci: clear {host/guest}_maskall field on assign
Roger Pau Monné [Thu, 10 Oct 2019 08:59:27 +0000 (10:59 +0200)]
pci: clear {host/guest}_maskall field on assign

The current implementation of host_maskall makes it sticky across
assign and deassign calls, which means that once a guest forces Xen to
set host_maskall the maskall bit is not going to be cleared until a
call to PHYSDEVOP_prepare_msix is performed. Such call however
shouldn't be part of the normal flow when doing PCI passthrough, and
hence the flag needs to be cleared when assigning in order to prevent
host_maskall being carried over from previous assignations.

Note that the entry maskbit is reset when the msix capability is
initialized, and the guest_maskall field is also cleared so that the
hardware value matches Xen's internal state (hardware maskall =
host_maskall | guest_maskall).

Also note that doing the reset of host_maskall there would allow the
guest to reset such field by enabling and disabling MSIX, which is not
intended.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Chao Gao <chao.gao@intel.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoefi/boot: make sure graphics mode is set while booting through MB2
Igor Druzhinin [Thu, 10 Oct 2019 08:58:45 +0000 (10:58 +0200)]
efi/boot: make sure graphics mode is set while booting through MB2

If a bootloader is using native driver instead of EFI GOP it might
reset graphics mode to be different from what has been originally set
by firmware. While booting through MB2 Xen either need to parse video
setting passed by MB2 and use them instead of what GOP reports or
reset the mode to synchronise it with firmware - prefer the latter.

Observed while booting Xen using MB2 with EFI GRUB2 compiled with
all possible video drivers where native drivers take priority over firmware.

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoefi/boot: add missing pointer dereference in set_color
Igor Druzhinin [Thu, 10 Oct 2019 08:58:09 +0000 (10:58 +0200)]
efi/boot: add missing pointer dereference in set_color

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoAMD/IOMMU: pre-fill all DTEs right after table allocation
Jan Beulich [Thu, 10 Oct 2019 07:51:46 +0000 (09:51 +0200)]
AMD/IOMMU: pre-fill all DTEs right after table allocation

Make sure we don't leave any DTEs unexpected requests through which
would be passed through untranslated. Set V and IV right away (with
all other fields left as zero), relying on the V and/or IV bits
getting cleared only by amd_iommu_set_root_page_table() and
amd_iommu_set_intremap_table() under special pass-through circumstances.
Switch back to initial settings in amd_iommu_disable_domain_device().

Take the liberty and also make the latter function static, constifying
its first parameter at the same time, at this occasion.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoAMD/IOMMU: allow callers to request allocate_buffer() to skip its memset()
Jan Beulich [Thu, 10 Oct 2019 07:51:12 +0000 (09:51 +0200)]
AMD/IOMMU: allow callers to request allocate_buffer() to skip its memset()

The command ring buffer doesn't need clearing up front in any event.
Subsequently we'll also want to avoid clearing the device tables.

While playing with functions signatures replace undue use of fixed width
types at the same time, and extend this to deallocate_buffer() as well.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoAMD/IOMMU: allocate one device table per PCI segment
Jan Beulich [Thu, 10 Oct 2019 07:50:00 +0000 (09:50 +0200)]
AMD/IOMMU: allocate one device table per PCI segment

Having a single device table for all segments can't possibly be right.
(Even worse, the symbol wasn't static despite being used in just one
source file.) Attach the device tables to their respective IVRS mapping
ones.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoiommu/arm: Remove arch_iommu_populate_page_table() completely
Oleksandr Tyshchenko [Mon, 30 Sep 2019 10:34:31 +0000 (13:34 +0300)]
iommu/arm: Remove arch_iommu_populate_page_table() completely

The Arm realization should have been removed in the following commit
as redundant:
f89f555 remove late (on-demand) construction of IOMMU page tables

So, remove unused function completely.

Fixes: f89f555 ('remove late (on-demand) construction of IOMMU page tables')
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoxen/arm: fix duplicate memory node in DT
Stefano Stabellini [Tue, 8 Oct 2019 01:15:01 +0000 (18:15 -0700)]
xen/arm: fix duplicate memory node in DT

When reserved-memory regions are present in the host device tree, dom0
is started with multiple memory nodes. Each memory node should have a
unique name, but today they are all called "memory" leading to Linux
printing the following warning at boot:

  OF: Duplicate name in base, renamed to "memory#1"

This patch fixes the problem by appending a "@<unit-address>" to the
name, as per the Device Tree specification, where <unit-address> matches
the base of address of the first region.

Fixes: 248faa637d2 (xen/arm: add reserved-memory regions to the dom0 memory node)
Reported-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoxen/arm: make_memory_node return error on nr_banks == 0
Stefano Stabellini [Tue, 8 Oct 2019 01:15:00 +0000 (18:15 -0700)]
xen/arm: make_memory_node return error on nr_banks == 0

Call make_memory_node for reserved_memory only if we actually have any
reserved_memory regions to handle.

Add a check in make_memory_node to return an error if it has been called
with no memory banks as argument.

Fixes: 248faa637d2 (xen/arm: add reserved-memory regions to the dom0 memory node)
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agodocs: update all URLs in man pages
Lars Kurth [Thu, 3 Oct 2019 15:47:05 +0000 (08:47 -0700)]
docs: update all URLs in man pages

Specifically
* xen.org to xenproject.org
* http to https
* Replaced pages where page has moved
  (including on xen pages as well as external pages)
* Removed some URLs (e.g. downloads for Linux PV drivers)

Tested-by: Lars Kurth <lars.kurth@citrix.com>
Signed-off-by: Lars Kurth <lars.kurth@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Wei Liu <wl@xen.org>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoxen/sched: let credit scheduler control its timer all alone
Juergen Gross [Mon, 7 Oct 2019 06:35:19 +0000 (08:35 +0200)]
xen/sched: let credit scheduler control its timer all alone

The credit scheduler is the only scheduler with tick_suspend and
tick_resume callbacks. Today those callbacks are invoked without being
guarded by the scheduler lock which is critical when at the same the
cpu those callbacks are active is being moved to or from a cpupool.

Crashes like the following are possible due to that race:

(XEN) ----[ Xen-4.13.0-8.0.12-d  x86_64  debug=y   Not tainted ]----
(XEN) CPU:    79
(XEN) RIP:    e008:[<ffff82d0802467dc>] set_timer+0x39/0x1f7
(XEN) RFLAGS: 0000000000010002   CONTEXT: hypervisor
<snip>
(XEN) Xen call trace:
(XEN)    [<ffff82d0802467dc>] set_timer+0x39/0x1f7
(XEN)    [<ffff82d08022c1f4>]
sched_credit.c#csched_tick_resume+0x54/0x59
(XEN)    [<ffff82d080241dfe>] sched_tick_resume+0x67/0x86
(XEN)    [<ffff82d0802eda52>] mwait-idle.c#mwait_idle+0x32b/0x357
(XEN)    [<ffff82d08027939e>] domain.c#idle_loop+0xa6/0xc2
(XEN)
(XEN) Pagetable walk from 0000000000000048:
(XEN)  L4[0x000] = 00000082cfb9c063 ffffffffffffffff
(XEN)  L3[0x000] = 00000082cfb9b063 ffffffffffffffff
(XEN)  L2[0x000] = 00000082cfb9a063 ffffffffffffffff
(XEN)  L1[0x000] = 0000000000000000 ffffffffffffffff
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 79:
(XEN) FATAL PAGE FAULT
(XEN) [error_code=0000]
(XEN) Faulting linear address: 0000000000000048
(XEN) ****************************************

The callbacks are used when the cpu is going to or coming from idle in
order to allow higher C-states.

The credit scheduler knows when it is going to schedule an idle
scheduling unit or another one after idle, so it can easily stop or
resume the timer itself removing the need to do so via the callback.
As this timer handling is done in the main scheduling function the
scheduler lock is still held, so the race with cpupool operations can
no longer occur. Note that calling the callbacks from schedule_cpu_rm()
and schedule_cpu_add() is no longer needed, as the transitions to and
from idle in the cpupool with credit active will automatically occur
and do the right thing.

With the last user of the callbacks gone those can be removed.

Suggested-by: George Dunlap <george.dunlap@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Dario Faggioli <dfaggioli@suse.com>
5 years agoxen/xsm: flask: Check xmalloc_array() return in security_sid_to_context()
Julien Grall [Fri, 4 Oct 2019 16:53:26 +0000 (17:53 +0100)]
xen/xsm: flask: Check xmalloc_array() return in security_sid_to_context()

xmalloc_array() may return NULL if there are memory. Rather than trying
to deference it directly, we should check the return value first.

Coverity-ID: 1381852
Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoxen/xsm: flask: Prevent NULL deference in flask_assign_{, dt}device()
Julien Grall [Fri, 4 Oct 2019 16:32:49 +0000 (17:32 +0100)]
xen/xsm: flask: Prevent NULL deference in flask_assign_{, dt}device()

flask_assign_{, dt}device() may be used to check whether you can test if
a device is assigned. In this case, the domain will be NULL.

However, flask_iommu_resource_use_perm() will be called and may end up
to deference a NULL pointer. This can be prevented by moving the call
after we check the validity for the domain pointer.

Coverity-ID: 1486741
Fixes: 71e617a6b8 ('use is_iommu_enabled() where appropriate...')
Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Paul Durrant <paul@xen.org>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agox86/Kconfig: Invert the defaults for CONFIG_{PVH_GUEST,PV_SHIM}
Andrew Cooper [Tue, 1 Oct 2019 16:27:49 +0000 (17:27 +0100)]
x86/Kconfig: Invert the defaults for CONFIG_{PVH_GUEST,PV_SHIM}

This is a minor UI change, but users which have elected to enable
XEN_GUEST (which still defaults to no) will definitely need one of these
options, and will typically want both.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Wei Liu <wl@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoxen/nospec: Introduce CONFIG_SPECULATIVE_HARDEN_ARRAY
Andrew Cooper [Thu, 31 Jan 2019 18:01:16 +0000 (18:01 +0000)]
xen/nospec: Introduce CONFIG_SPECULATIVE_HARDEN_ARRAY

There are legitimate circumstance where array hardening is not wanted or
needed.  Allow it to be turned off.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agox86/spec-ctrl: Annotate remaining model names
Andrew Cooper [Thu, 3 Oct 2019 14:04:03 +0000 (15:04 +0100)]
x86/spec-ctrl: Annotate remaining model names

The names in retpoline_safe() are copied from should_use_eager_fpu().  The
names in mds_calculations() come partly from Linux's intel-family.h, and
partly from conversations with Intel.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agoxen/arm: add dom0-less device assignment info to docs
Stefano Stabellini [Thu, 3 Oct 2019 17:35:41 +0000 (10:35 -0700)]
xen/arm: add dom0-less device assignment info to docs

Add info about the SPI used for the virtual pl011.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
5 years agoxen/arm: introduce nr_spis
Stefano Stabellini [Thu, 3 Oct 2019 17:34:15 +0000 (10:34 -0700)]
xen/arm: introduce nr_spis

We don't have a clear way to know how many virtual SPIs we need for the
dom0-less domains. Introduce a new option under xen,domain to specify
the number of SPIs to allocate for a domain.

The property is optional. When absent, we'll use the physical number of
GIC lines for dom0-less domains, or GUEST_VPL011_SPI+1 if vpl011 is
requested, whichever is greater.

Remove the old setting of nr_spis based on the presence of the vpl011.

The implication of this change is that without nr_spis dom0less domains
get the same amount of SPI allocated as dom0, regardless of how many
physical devices they have assigned, and regardless of whether they have
a virtual pl011 (which also needs an emulated SPI). This is done because
the SPIs allocation needs to be done before parsing any passthrough
information, so we have to account for any potential physical SPI
assigned to the domain.

When nr_spis is present, the domain gets exactly nr_spis allocated SPIs.
If the number is too low, it might not be enough for the devices
assigned it to it. If the number is less than GUEST_VPL011_SPI, the
virtual pl011 won't work.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Acked-by: Julien Grall <julien.grall@arm.com>
5 years agoxen/arm: handle "multiboot,device-tree" compatible nodes
Stefano Stabellini [Thu, 3 Oct 2019 17:34:15 +0000 (10:34 -0700)]
xen/arm: handle "multiboot,device-tree" compatible nodes

Detect "multiboot,device-tree" compatible nodes. Add them to the bootmod
array as BOOTMOD_GUEST_DTB.  In kernel_probe, find the right
BOOTMOD_GUEST_DTB and store a pointer to it in dtb_bootmodule.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
5 years agoxen/arm: assign devices to boot domains
Stefano Stabellini [Thu, 3 Oct 2019 17:34:05 +0000 (10:34 -0700)]
xen/arm: assign devices to boot domains

Scan the user provided dtb fragment at boot. For each device node, map
memory to guests, and route interrupts and setup the iommu.

The memory region to remap is specified by the "xen,reg" property.

The iommu is setup by passing the node of the device to assign on the
host device tree. The path is specified in the device tree fragment as
the "xen,path" string property.

The interrupts are remapped based on the information from the
corresponding node on the host device tree. Call
handle_device_interrupts to remap interrupts. Interrupts related device
tree properties are copied from the device tree fragment, same as all
the other properties.

Require both xen,reg and xen,path to be present, unless
xen,force-assign-without-iommu is also set. In that case, tolerate a
missing xen,path, also tolerate iommu setup failure for the passthrough
device.

Also set add the new flag XEN_DOMCTL_CDF_iommu so that dom0less domU
can use the IOMMU if a partial dtb is specified.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Reviewed-by: Julien Grall <julien.grall@arm.com>
5 years agoxen/arm: copy dtb fragment to guest dtb
Stefano Stabellini [Mon, 30 Sep 2019 23:13:37 +0000 (16:13 -0700)]
xen/arm: copy dtb fragment to guest dtb

Read the dtb fragment corresponding to a passthrough device from memory
at the location referred to by the "multiboot,device-tree" compatible
node.

Add a new field named dtb_bootmodule to struct kernel_info to keep track
of the dtb fragment location.

Copy the fragment to the guest dtb (only /aliases and /passthrough).

Set kinfo->phandle_gic based on the phandle of the special "/gic"
node in the device tree fragment. "/gic" is a dummy node in the dtb
fragment that represents the gic interrupt controller. Other properties
in the dtb fragment might refer to it (for instance interrupt-parent of
a device node). We reuse the phandle of "/gic" from the dtb fragment as
the phandle of the full GIC node that will be created for the guest
device tree. That way, when we copy properties from the device tree
fragment to the domU device tree the links remain unbroken.

scan_passthrough_prop is introduced here and not used in this patch but
it will be used by later patches.

Some of the code below is taken from tools/libxl/libxl_arm.c. Note that
it is OK to take LGPL 2.1 code and including it into a GPLv2 code base.
The result is GPLv2 code.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
----
Changes in v6:
- code style
- in-code comment
- commit message improvements

Changes in v5:
- code style
- in-code comment
- remove depth parameter from scan_pfdt_node
- for instead of loop in domain_handle_dtb_bootmodule
- move "gic" check to domain_handle_dtb_bootmodule
- add check_partial_fdt
- use DT_ROOT_NODE_ADDR/SIZE_CELLS_DEFAULT
- add scan_passthrough_prop parameter, set it to false for "/aliases"

Changes in v4:
- use recursion in the implementation
- rename handle_properties to handle_prop_pfdt
- rename scan_pt_node to scan_pfdt_node
- pass kinfo to handle_properties
- use uint32_t instead of u32
- rename r to res
- add "passthrough" and "aliases" check
- add a name == NULL check
- code style
- move DTB fragment scanning earlier, before DomU GIC node creation
- set guest_phandle_gic based on "/gic"
- in-code comment

Changes in v3:
- switch to using device_tree_for_each_node for the copy

Changes in v2:
- add a note about the code coming from libxl in the commit message
- copy /aliases
- code style

5 years agoxen/arm: introduce kinfo->phandle_gic
Stefano Stabellini [Mon, 30 Sep 2019 23:13:37 +0000 (16:13 -0700)]
xen/arm: introduce kinfo->phandle_gic

Instead of always hard-coding the GIC phandle (GUEST_PHANDLE_GIC), store
it in a variable under kinfo. This way it can be dynamically chosen per
domain. Remove the fdt pointer argument to the make_*_domU_node
functions and oass a struct kernel_info * instead. The fdt pointer can
be accessed from kinfo->fdt. Remove the struct domain *d parameter to
the make_*_domU_node functions because it becomes unused.

Initialize phandle_gic to GUEST_PHANDLE_GIC at the beginning of
prepare_dtb_domU for DomUs. Later patches will change the value of
phandle_gic depending on user provided information.

For Dom0, initialize phandle_gic to dt_interrupt_controller->phandle
(current value) at the beginning of prepare_dtb.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
5 years agoxen/arm: export device_tree_get_reg and device_tree_get_u32
Stefano Stabellini [Mon, 30 Sep 2019 23:13:37 +0000 (16:13 -0700)]
xen/arm: export device_tree_get_reg and device_tree_get_u32

They'll be used in later patches.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
5 years agoxen/arm: introduce handle_device_interrupts
Stefano Stabellini [Mon, 30 Sep 2019 23:13:37 +0000 (16:13 -0700)]
xen/arm: introduce handle_device_interrupts

Move the interrupt handling code out of handle_device to a new function
so that it can be reused for dom0less VMs (it will be used in later
patches).

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
Acked-by: Julien Grall <julien.grall@arm.com>
5 years agoxen/arm: boot with device trees with "mmu-masters" and "iommus"
Stefano Stabellini [Mon, 30 Sep 2019 20:56:18 +0000 (13:56 -0700)]
xen/arm: boot with device trees with "mmu-masters" and "iommus"

Some Device Trees may expose both legacy SMMU and generic IOMMU bindings
together. However, the SMMU driver in Xen is only supporting the legacy
SMMU bindings, leading to fatal initialization errors at boot time.

This patch fixes the booting problem by adding a check to
iommu_add_dt_device: if the Xen driver doesn't support the new generic
bindings, and the device is behind an IOMMU, do not return error. The
following iommu_assign_dt_device should succeed.

This check will become superfluous, hence removable, once the Xen SMMU
driver gets support for the generic IOMMU bindings.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agolibxl: don't try to manipulate json config for stubdomain
Marek Marczykowski-Górecki [Sat, 28 Sep 2019 14:20:37 +0000 (15:20 +0100)]
libxl: don't try to manipulate json config for stubdomain

Stubdomain do not have it's own config file - its configuration is
derived from target domains. Do not try to manipulate it when attaching
PCI device.

This bug prevented starting HVM with stubdomain and PCI passthrough
device attached.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agolibxl: attach PCI device to qemu only after setting pciback/pcifront
Marek Marczykowski-Górecki [Tue, 1 Oct 2019 04:24:19 +0000 (05:24 +0100)]
libxl: attach PCI device to qemu only after setting pciback/pcifront

When qemu is running in stubdomain, handling "pci-ins" command will fail
if pcifront is not initialized already. Fix this by sending such command
only after confirming that pciback/front is running.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
5 years agolibxl: do not attach xen-pciback to HVM domain, if stubdomain is in use
Marek Marczykowski-Górecki [Sat, 28 Sep 2019 14:20:35 +0000 (15:20 +0100)]
libxl: do not attach xen-pciback to HVM domain, if stubdomain is in use

HVM domains use IOMMU and device model assistance for communicating with
PCI devices, xen-pcifront/pciback isn't directly needed by HVM domain.
But pciback serve also second function - it reset the device when it is
deassigned from the guest and for this reason pciback needs to be used
with HVM domain too.
When HVM domain has device model in stubdomain, attaching xen-pciback to
the target domain itself may prevent attaching xen-pciback to the
(PV) stubdomain, effectively breaking PCI passthrough.

Fix this by attaching pciback only to one domain: if PV stubdomain is in
use, let it be stubdomain (the commit prevents attaching device to target
HVM in this case); otherwise, attach it to the target domain.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>