]> xenbits.xensource.com Git - xen.git/log
xen.git
8 years agoIOMMU: add domain crash logic
Quan Xu [Fri, 8 Jul 2016 06:45:13 +0000 (00:45 -0600)]
IOMMU: add domain crash logic

Add domain crash logic to the generic IOMMU layer to benefit
all platforms.

No spamming of the log can occur. For DomU, we avoid logging any
message for already dying domains. For Dom0, that'll still be more
verbose than we'd really like, but it at least wouldn't outright
flood the console.

Signed-off-by: Quan Xu <quan.xu@intel.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Quan Xu <quan.xu@intel.com>
8 years agoIOMMU/ATS: use a struct pci_dev * instead of SBDF
Quan Xu [Fri, 8 Jul 2016 06:44:23 +0000 (00:44 -0600)]
IOMMU/ATS: use a struct pci_dev * instead of SBDF

Do away with struct pci_ats_dev; integrate the few bits of information
in struct pci_dev (and as a result drop get_ats_device() altogether).
Hook ATS devices onto a linked list off of each IOMMU instead of on a
global one.

Signed-off-by: Quan Xu <quan.xu@intel.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
Tested-by: Quan Xu <quan.xu@intel.com>
8 years agoXSM-Policy: allow source domain access to setpodtarget and getpodtarget for ballooning.
Anshul Makkar [Thu, 14 Jul 2016 14:46:12 +0000 (15:46 +0100)]
XSM-Policy: allow source domain access to setpodtarget and getpodtarget for ballooning.

Access to setpodtarget and getpodtarget is required by dom0 to set the balloon
targets for domU. The patch gives source domain (dom0) access to set
this target for domU and resolve the following permission denied erro
message during ballooning :
avc:  denied  { setpodtarget } for domid=0 target=9
scontext=system_u:system_r:dom0_t
tcontext=system_u:system_r:domU_t tclass=domain

Signed-off-by: Anshul Makkar <anshul.makkar@citrix.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
8 years agoxsm: add a default policy to .init.data
Daniel De Graaf [Thu, 14 Jul 2016 14:18:47 +0000 (10:18 -0400)]
xsm: add a default policy to .init.data

This adds a Kconfig option and support for including the XSM policy from
tools/flask/policy in the hypervisor so that the bootloader does not
need to provide a policy to get sane behavior from an XSM-enabled
hypervisor.  The policy provided by the bootloader, if present, will
override the built-in policy.

The XSM policy is not moved out of tools because that remains the
primary location for installing and configuring the policy.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agoxsm: rework policy_buffer globals
Daniel De Graaf [Thu, 14 Jul 2016 14:18:46 +0000 (10:18 -0400)]
xsm: rework policy_buffer globals

This makes the buffers function parameters instead of globals, in
preparation for adding alternate locations for the policy.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agoarm: vgic: Split vgic_domain_init() functionality into two functions
Shanker Donthineni [Mon, 27 Jun 2016 20:33:39 +0000 (15:33 -0500)]
arm: vgic: Split vgic_domain_init() functionality into two functions

Separate the code logic that does the registration of vgic_v3/v2 ops
to a new function domain_vgic_register(). The intention of this
separation is to record the required mmio count in vgic_v3/v2_init()
and pass it to function domain_io_init() in a follow-up patch patch.

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Reviewed-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoarm/gic-v3: Remove an unused macro MAX_RDIST_COUNT
Shanker Donthineni [Mon, 27 Jun 2016 20:33:38 +0000 (15:33 -0500)]
arm/gic-v3: Remove an unused macro MAX_RDIST_COUNT

The macro MAX_RDIST_COUNT is not being used after converting code
to handle number of redistributor dynamically. So remove it from
header file and the two other panic() messages that are not valid
anymore.

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: vgic: Use dynamic memory allocation for vgic_rdist_region
Shanker Donthineni [Mon, 27 Jun 2016 20:33:37 +0000 (15:33 -0500)]
xen/arm: vgic: Use dynamic memory allocation for vgic_rdist_region

The number of Redistributor regions allowed for dom0 is hardcoded
to a define MAX_RDIST_COUNT which is 4. Some systems, especially
latest server chips, may have more than 4 redistributors. Either we
have to increase MAX_RDIST_COUNT to a bigger number or allocate
memory based on the number of redistributors that are found in MADT
table. In the worst case scenario, the macro MAX_RDIST_COUNT should
be equal to CONFIG_NR_CPUS in order to support per CPU Redistributors.

Increasing MAX_RDIST_COUNT has a effect, it blows 'struct domain'
size and hits BUILD_BUG_ON() in domain build code path.

struct domain *alloc_domain_struct(void)
{
    struct domain *d;
    BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
    d = alloc_xenheap_pages(0, 0);
    if ( d == NULL )
        return NULL;
...

This patch uses the second approach to fix the BUILD_BUG().

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Reviewed-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoarm/gic-v3: Parse per-cpu redistributor entry in GICC subtable
Shanker Donthineni [Mon, 27 Jun 2016 20:33:36 +0000 (15:33 -0500)]
arm/gic-v3: Parse per-cpu redistributor entry in GICC subtable

The redistributor address can be specified either as part of GICC or
GICR subtable depending on the power domain. The current driver
doesn't support parsing redistributor entry that is defined in GICC
subtable. The GIC CPU subtable entry holds the associated Redistributor
base address if it is not on always-on power domain.

The per CPU Redistributor size is not defined in ACPI specification.
Set the GICR region size to SZ_256K if the GIC hardware is capable of
Direct Virtual LPI Injection feature, SZ_128K otherwise.

This patch adds necessary code to handle both types of Redistributors
base addresses.

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoarm/gic-v3: Move GICR subtable parsing into a new function
Shanker Donthineni [Thu, 14 Jul 2016 14:13:13 +0000 (15:13 +0100)]
arm/gic-v3: Move GICR subtable parsing into a new function

Add a new function to parse GICR subtable and move the code that
is specific to GICR table to a new function without changing the
function gicv3_acpi_init() behavior.

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoarm/gic-v3: Do early GICD ioremap and clean up
Shanker Donthineni [Mon, 27 Jun 2016 20:33:34 +0000 (15:33 -0500)]
arm/gic-v3: Do early GICD ioremap and clean up

For ACPI based XEN boot, the GICD region needs to be accessed inside
the function gicv3_acpi_init() in later patch. There is a duplicate
panic() message, one in the DTS probe and second one in the ACPI probe
path. For these two reasons, move the code that validates the GICD base
address and does the region ioremap to a separate function. The
following patch accesses the GICD region inside gicv3_acpi_init() for
finding per CPU Redistributor size.

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoarm/gic-v3: Use acpi_table_parse_madt() to parse MADT subtables
Shanker Donthineni [Mon, 27 Jun 2016 20:33:33 +0000 (15:33 -0500)]
arm/gic-v3: Use acpi_table_parse_madt() to parse MADT subtables

The function acpi_table_parse_madt() does the same functionality as
function acpi_parse_entries() expect it takes a few arguments.

Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org>
Reviewed-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: traps: Data Abort are always unconditional
Julien Grall [Wed, 22 Jun 2016 13:21:03 +0000 (14:21 +0100)]
xen/arm: traps: Data Abort are always unconditional

The HSR encoding for an exception from a data abort does not contain a
conditional code (see G6-4264 in ARM DDI 0487A.i) because they are
always conditional.

So drop the pointless condition check.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: traps: Second attempt to correctly use the content of HPFAR_EL2
Julien Grall [Wed, 22 Jun 2016 13:21:02 +0000 (14:21 +0100)]
xen/arm: traps: Second attempt to correctly use the content of HPFAR_EL2

Commit c051618 "xen/arm: traps: Correctly interpret the content of the
register HPFAR_EL2" attempted to fix the interpretation of HPFAR_EL2.

However, the register contains a 4KB-aligned address. This means that
the reported address is not directly usable to know the faulting IPA.
The offset in the 4KB page can be found by looking at the associated virtual
address (FAR_EL2/HDFAR).

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Simply the definition of PAGE_SIZE by using the macro _AC
Julien Grall [Wed, 22 Jun 2016 13:21:01 +0000 (14:21 +0100)]
xen/arm: Simply the definition of PAGE_SIZE by using the macro _AC

The macro _AC is used to define constant for both assembly and C.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: p2m: Rework the interface of apply_p2m_changes and use typesafe
Julien Grall [Tue, 12 Jul 2016 13:59:35 +0000 (14:59 +0100)]
xen/arm: p2m: Rework the interface of apply_p2m_changes and use typesafe

Most of the callers of apply_p2m_changes have a GFN, a MFN and the
number of frame to change in hand.

Rather than asking each caller to convert the frame to an address,
rework the interfaces to pass the GFN, MFN and the number of frame.

Note that it would be possible to do more clean-up in apply_p2m_changes,
but this will be done in a follow-up series.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: p2m: Use typesafe gfn for {max,lowest}_mapped_gfn
Julien Grall [Tue, 12 Jul 2016 13:59:34 +0000 (14:59 +0100)]
xen/arm: p2m: Use typesafe gfn for {max,lowest}_mapped_gfn

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: p2m: Introduce helpers to insert and remove mapping
Julien Grall [Tue, 12 Jul 2016 13:59:33 +0000 (14:59 +0100)]
xen/arm: p2m: Introduce helpers to insert and remove mapping

More the half of the arguments of INSERT and REMOVE are the same for
each callers. Simplify the callers of apply_p2m_changes by adding new
helpers which will fill common arguments with default values.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Use the typesafes mfn and gfn in map_regions_rw_cache ...
Julien Grall [Tue, 12 Jul 2016 13:59:32 +0000 (14:59 +0100)]
xen/arm: Use the typesafes mfn and gfn in map_regions_rw_cache ...

to avoid mixing machine frame with guest frame. Also rename the
parameters of the function and drop pointless PAGE_MASK in the caller.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Use the typesafes mfn and gfn in map_dev_mmio_region...
Julien Grall [Tue, 12 Jul 2016 13:59:31 +0000 (14:59 +0100)]
xen/arm: Use the typesafes mfn and gfn in map_dev_mmio_region...

to avoid mixing machine frame with guest frame. Also drop the prefix start_.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: p2m: Remove unused operation ALLOCATE
Julien Grall [Tue, 12 Jul 2016 13:59:30 +0000 (14:59 +0100)]
xen/arm: p2m: Remove unused operation ALLOCATE

The operation ALLOCATE is unused. If we ever need it, it could be
reimplemented with INSERT.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: dom0_build: Remove dead code in allocate_memory
Julien Grall [Tue, 12 Jul 2016 13:59:29 +0000 (14:59 +0100)]
xen/arm: dom0_build: Remove dead code in allocate_memory

The code to allocate memory when dom0 does not use direct mapping is
relying on the presence of memory node in the DT.

However, they are not present when booting using UEFI or when using
ACPI.

Rather than fixing the code, remove it because dom0 is always direct
memory mapped and therefore the code is never tested. Also add a
check to avoid disabling direct memory mapped and not implementing
the associated RAM bank allocation.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: map_regions_rw_cache: Map the region with p2m->default_access
Julien Grall [Tue, 12 Jul 2016 13:59:28 +0000 (14:59 +0100)]
xen/arm: map_regions_rw_cache: Map the region with p2m->default_access

The parameter 'access' is used by memaccess to restrict temporarily the
permission. This parameter should not be used for other purpose (such
as restricting permanently the permission).

Instead, we should use the default access requested by memacess. When it
is not enabled, the access will be p2m_access_rwx (i.e no restriction
applied).

The type p2m_mmio_direct will map the region read-write and
non-executable before any further restriction by memaccess. Note that
this is already the resulting permission with the curreent combination
of the type and the access. So there is no functional change.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: arm64: Add helpers to decode and encode branch instructions
Julien Grall [Wed, 22 Jun 2016 11:15:23 +0000 (12:15 +0100)]
xen/arm: arm64: Add helpers to decode and encode branch instructions

We may need to update branch instruction when patching Xen.

The code has been imported from the files arch/arm64/kernel/insn.c
and arch/arm64/include/asm/insn.h in Linux v4.6.

Note that only the necessary helpers have been imported.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: arm64: Reserve a brk immediate to fault on purpose
Julien Grall [Wed, 22 Jun 2016 11:15:22 +0000 (12:15 +0100)]
xen/arm: arm64: Reserve a brk immediate to fault on purpose

It may not possible to return a proper error when encoding an
instruction. Instead, a handcrafted instruction will be returned.

Also, provide the encoding for the faulting instruction.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: arm64: Move the define BRK_BUG_FRAME into a separate header
Julien Grall [Wed, 22 Jun 2016 11:15:21 +0000 (12:15 +0100)]
xen/arm: arm64: Move the define BRK_BUG_FRAME into a separate header

New immediates will be defined in the future. To keep track of the
immediates allocated, gather all of them in a separate header.

Also rename BRK_BUG_FRAME to BKR_BUG_FRAME_IMM.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm64: Add an helper to invalidate all instruction caches
Julien Grall [Wed, 22 Jun 2016 11:15:20 +0000 (12:15 +0100)]
xen/arm64: Add an helper to invalidate all instruction caches

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Add cpu_hwcap bitmap
Julien Grall [Wed, 22 Jun 2016 11:15:19 +0000 (12:15 +0100)]
xen/arm: Add cpu_hwcap bitmap

This will be used to know if a feature, which Xen cares, is available accross
all the CPUs.

This code is a light version of arch/arm64/kernel/cpufeature.c from
Linux v4.6-rc3.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Add macros to handle the MIDR
Julien Grall [Wed, 22 Jun 2016 11:15:18 +0000 (12:15 +0100)]
xen/arm: Add macros to handle the MIDR

Add new macros to easily get different parts of the register and to
check if a given MIDR match a CPU model range. The latter will be really
useful to handle errata later.

The macros have been imported from the header
arch/arm64/include/asm/cputype.h in Linux v4.6-rc3.

Also remove MIDR_MASK which is unused.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Include the header asm-arm/system.h in asm-arm/page.h
Julien Grall [Wed, 22 Jun 2016 11:15:17 +0000 (12:15 +0100)]
xen/arm: Include the header asm-arm/system.h in asm-arm/page.h

The header asm-arm/page.h makes use of the macro dsb defined in the header
asm-arm/system.h. Currently, the includer has to specify both of them.

This can be avoided by including asm-arm/system.h in asm-arm/page.h.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Makefile: Sort the entries alphabetically
Julien Grall [Wed, 22 Jun 2016 11:15:16 +0000 (12:15 +0100)]
xen/arm: Makefile: Sort the entries alphabetically

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agox86, hvm: document the de facto policy for vCPU ids
Vitaly Kuznetsov [Tue, 12 Jul 2016 11:44:42 +0000 (13:44 +0200)]
x86, hvm: document the de facto policy for vCPU ids

PVHVM guests may need to know Xen's idea of vCPU ids they have and the
only way they can figure them out is to use ACPI ids from MADT table.
Document the de facto policy.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agovmx/monitor: CPUID events
Tamas K Lengyel [Tue, 12 Jul 2016 18:13:18 +0000 (12:13 -0600)]
vmx/monitor: CPUID events

This patch implements sending notification to a monitor subscriber when an
x86/vmx guest executes the CPUID instruction.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@zentific.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agolibxl: constify src parameter of libxl_nocpuid.c:libxl_cpuid_policy_list_copy
Wei Liu [Wed, 13 Jul 2016 13:13:44 +0000 (14:13 +0100)]
libxl: constify src parameter of libxl_nocpuid.c:libxl_cpuid_policy_list_copy

In 11316d31 ("libxl: constify copy and length calculation functions") I
forgot to take care of libxl_nocpuid.c which also contains an
implementation of libxl_cpuid_policy_list_copy. That broke ARM build.

Fix it by constifying the src parameter.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoxen/arm: Rework the interface of p2m_cache_flush and use typesafe gfn
Julien Grall [Fri, 10 Jun 2016 17:48:02 +0000 (18:48 +0100)]
xen/arm: Rework the interface of p2m_cache_flush and use typesafe gfn

p2m_cache_flush is expecting GFNs in parameter and not MFNs. Rename
the variable to *gfn* and use typesafe to avoid possible misusage.

Also, modify the prototype of the function to describe the range
using the start and the number of GFNs. This will avoid to wonder
whether the end if inclusive or exclusive.

Note that the type of the parameters 'start' is changed from xen_pfn_t
(aka uint64_t) to gfn_t (aka unsigned long). This means that a truncation
will occur for ARM32. It is fine because it will always be encoded on 28
bits maximum (40 bits address).

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: Rework the interface of p2m_lookup and use typesafe gfn and mfn
Julien Grall [Tue, 14 Jun 2016 08:31:00 +0000 (09:31 +0100)]
xen/arm: Rework the interface of p2m_lookup and use typesafe gfn and mfn

The prototype and the declaration of p2m_lookup disagree on how the
function should be used. One expect a frame number whilst the other
an address.

Thankfully, everyone is using with an address today. However, most of
the callers have to convert a guest frame to an address. Modify
the interface to take a guest physical frame in parameter and return
a machine frame.

Whilst modifying the interface, use typesafe gfn and mfn for clarity
and catching possible misusage.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen: Use a typesafe to define INVALID_GFN
Julien Grall [Tue, 28 Jun 2016 13:37:57 +0000 (14:37 +0100)]
xen: Use a typesafe to define INVALID_GFN

Also take the opportunity to convert arch/x86/debug.c to the typesafe gfn.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Acked-by: Tim Deegan <tim@xen.org>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agoxen: Use a typesafe to define INVALID_MFN
Julien Grall [Fri, 24 Jun 2016 14:38:54 +0000 (15:38 +0100)]
xen: Use a typesafe to define INVALID_MFN

Also take the opportunity to convert arch/x86/debug.c to the typesafe
mfn and use proper printf format for MFN/GFN when the code around is
modified.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Tim Deegan <tim@xen.org>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agoxen/passthrough: x86: Use INVALID_GFN rather than INVALID_MFN
Julien Grall [Tue, 28 Jun 2016 12:31:32 +0000 (13:31 +0100)]
xen/passthrough: x86: Use INVALID_GFN rather than INVALID_MFN

A variable containing a guest frame should be compared to INVALID_GFN
and not INVALID_MFN.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Tim Deegan <tim@xen.org>
8 years agoxen: Use the typesafe mfn and gfn in map_mmio_regions...
Julien Grall [Fri, 10 Jun 2016 16:11:03 +0000 (17:11 +0100)]
xen: Use the typesafe mfn and gfn in map_mmio_regions...

to avoid mixing machine frame with guest frame.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Tim Deegan <tim@xen.org>
8 years agox86/vmx_update_guest_cr: minor optimization
Corneliu ZUZU [Sat, 9 Jul 2016 04:12:07 +0000 (07:12 +0300)]
x86/vmx_update_guest_cr: minor optimization

Minor optimization @ vmx_update_guest_cr: checks if v->arch.hvm_vmx.exec_control
was modified before actually calling vmx_update_cpu_exec_control(v).

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agolibxl: move DEFINE_DEVICE* macros to libxl_internal.h
Juergen Gross [Wed, 6 Jul 2016 14:55:34 +0000 (16:55 +0200)]
libxl: move DEFINE_DEVICE* macros to libxl_internal.h

In order to be able to have all functions related to a device type in
a single source file move the macros used to generate device type
specific functions to libxl_internal.h. Rename the macros as they are
no longer local to a source file. While at it hide device remove and
device destroy in one macro as those are always used in pairs. Move
usage of the macros to the appropriate source files.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: refactor domcreate_attach_dtdev() to use device type framework
Juergen Gross [Wed, 6 Jul 2016 14:55:33 +0000 (16:55 +0200)]
libxl: refactor domcreate_attach_dtdev() to use device type framework

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: refactor domcreate_attach_pci() to use device type framework
Juergen Gross [Wed, 6 Jul 2016 14:55:32 +0000 (16:55 +0200)]
libxl: refactor domcreate_attach_pci() to use device type framework

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add framework for device types
Juergen Gross [Wed, 6 Jul 2016 14:55:31 +0000 (16:55 +0200)]
libxl: add framework for device types

Instead of duplicate coding for each device type (vtpms, usbctrls, ...)
especially on domain creation introduce a framework for that purpose.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: only issue cpu-add call to QEMU for not present CPU
Wei Liu [Wed, 8 Jun 2016 14:01:02 +0000 (15:01 +0100)]
libxl: only issue cpu-add call to QEMU for not present CPU

Calculate the final bitmap for CPUs to add to avoid having annoying
error messages complaining those CPUs are already present. Example
message is like (wrapped):

libxl: error: libxl_qmp.c:287:qmp_handle_error_response: received an
error message from QMP server: Unable to add CPU: 0, it already exists

We can also properly handle error from QMP now.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: update vcpus bitmap in retrieved guest config
Wei Liu [Fri, 3 Jun 2016 15:38:32 +0000 (16:38 +0100)]
libxl: update vcpus bitmap in retrieved guest config

... because the available vcpu bitmap can change during domain life time
due to cpu hotplug and unplug.

For QEMU upstream, we interrogate QEMU for the number of vcpus. For
others, we look directly into xenstore for information.

Reported-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: introduce libxl__qmp_query_cpus
Wei Liu [Tue, 7 Jun 2016 09:03:39 +0000 (10:03 +0100)]
libxl: introduce libxl__qmp_query_cpus

It interrogates QEMU for CPUs and update the bitmap accordingly.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: libxl_domain_need_memory shouldn't modify b_info
Wei Liu [Mon, 11 Jul 2016 11:03:51 +0000 (12:03 +0100)]
libxl: libxl_domain_need_memory shouldn't modify b_info

This function is used to return the memory needed for a guest. It's not
in a position to modify the b_info passed in (note the _setdefault
function).

Constify the passed in b_info, use a copy to do the calculation. Mark
the change in API in libxl.h.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: constify copy and length calculation functions
Wei Liu [Mon, 11 Jul 2016 14:12:57 +0000 (15:12 +0100)]
libxl: constify copy and length calculation functions

These functions are not supposed to modify the passed in parameters.
Reflect that in function declarations.

Mark the change in APIs in libxl.h

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoxen/arm: io: Protect the handlers with a read-write lock
Julien Grall [Tue, 28 Jun 2016 16:34:31 +0000 (17:34 +0100)]
xen/arm: io: Protect the handlers with a read-write lock

Currently, accessing the I/O handlers does not require to take a lock
because new handlers are always added at the end of the array. In a
follow-up patch, this array will be sort to optimize the look up.

Given that most of the time the I/O handlers will not be modify,
using a spinlock will add contention when multiple vCPU are accessing
the emulated MMIOs. So use a read-write lock to protected the handlers.

Finally, take the opportunity to re-indent correctly domain_io_init.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: gic-v3: No need to sort the Redistributor regions
Julien Grall [Tue, 28 Jun 2016 15:51:54 +0000 (16:51 +0100)]
xen/arm: gic-v3: No need to sort the Redistributor regions

The sorting was required by the vGIC emulation until commit
9b9d51e98edb8c5c731e2d06dfad3633053d88a4 "xen/arm: vgic-v3:
Correctly retrieve the vCPU associated to a re-distributor".

Furthermore, the code is buggy because both local variables 'l' and 'r'
point to the same region.

So drop the code which sort the Redistributors array.

Reported-by: Shanker Donthineni <shankerd@codeaurora.org>
Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: map_dev_mmio_region: The iomem permission check should be done on MFN
Julien Grall [Tue, 14 Jun 2016 11:50:26 +0000 (12:50 +0100)]
xen/arm: map_dev_mmio_region: The iomem permission check should be done on MFN

The helper iomem_access_permitted expects MFNs in parameters and not
GNFs. Thankfully only the hardware domain can call this function and
it will always be with GFNS == MFNs for now.

Also, fix the printf to use the MFN range and not the GFN one.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Shannon Zhao <shannon.zhao@linaro.org>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agolibxl/arm: Factor out codes for generating DTB
Shannon Zhao [Tue, 5 Jul 2016 03:12:31 +0000 (11:12 +0800)]
libxl/arm: Factor out codes for generating DTB

Factor out codes for generating DTB to prepare for adding ACPI tables
generation codes.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
[ wei: fix indentation while committing ]

8 years agoXSM/policy: Allow the source domain access to settime and setdomainhandle domctls...
Anshul Makkar [Thu, 7 Jul 2016 13:45:47 +0000 (14:45 +0100)]
XSM/policy: Allow the source domain access to settime and setdomainhandle domctls while creating domain.

This patch resolves the following permission denied scenarios while creating
new domU :
avc:  denied  { setdomainhandle } for domid=0 target=1
scontext=system_u:system_r:dom0_t tcontext=system_u:system_r:domU_t tclass=domain

avc:  denied  { settime } for domid=0 target=1 scontext=system_u:system_r:dom0_t
tcontext=system_u:system_r:domU_t tclass=domain

Signed-off-by: Anshul Makkar <anshul.makkar@citrix.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
8 years agotools/hotplug: Add native systemd xendriverdomain.service
Rusty Bird [Thu, 7 Jul 2016 14:09:32 +0000 (14:09 +0000)]
tools/hotplug: Add native systemd xendriverdomain.service

A dedicated Xen driver domain init service starts "xl devd" in domU. But
currently, it is only supplied in the form of a SysV init script, which
systemd users run through a backward compatiblity wrapper automatically
generated by systemd-sysv-generator. This patch adds a (naturally more
lightweight) native systemd unit to be used instead.

The xendriverdomain service is only relevant to domU, but should not run
in dom0. Therefore, the systemd unit uses "ConditionVirtualization=xen",
which evaluates to true in domU and (since systemd version 214, released
on 2014-06-11) to false in dom0. Users or distributors who need to be
compatible with even older systemd versions, but still want to prevent
"xl devd" startup in dom0, could add the following line in [Service]:
ExecStartPre=/bin/sh -c "! grep -q control_d /proc/xen/capabilities"

(Please rerun autogen.sh after applying this patch)

Signed-off-by: Rusty Bird <rustybird@openmailbox.org>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
[ wei: rerun autogen.sh ]

8 years agotools/xl: Allow callers of `xl info` to select specific information
Andrew Cooper [Thu, 30 Jun 2016 16:40:23 +0000 (17:40 +0100)]
tools/xl: Allow callers of `xl info` to select specific information

When scripting, it is much more convenient to use:

    [root@fusebot ~]# xl info xen_version
    4.8-unstable

than to construct some sed/awk/other to parse:

    [root@fusebot ~]# xl info
    ...
    xen_version            : 4.8-unstable
    ...

This works by wrapping all printf() calls in main_info() with maybe_printf(),
which formats its arguments, compares the resulting string to the provided
restriction, and discards it if no match is found.

A restriction like this doesn't make sense in combination with --numa, so is
excluded in that case.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen: credit2: avoid calling __update_svc_load() multiple times on the same vcpu
Dario Faggioli [Wed, 6 Jul 2016 16:37:37 +0000 (17:37 +0100)]
xen: credit2: avoid calling __update_svc_load() multiple times on the same vcpu

by not resetting the variable that should guard against
that at the beginning of each step of the outer loop.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen: credit2: when tickling, check idle cpus first
Dario Faggioli [Wed, 6 Jul 2016 16:34:14 +0000 (17:34 +0100)]
xen: credit2: when tickling, check idle cpus first

If there are idle pCPUs, it's always better to try to
"ship" the new vCPU there, instead than letting it
preempting on a currently busy one.

This commit also adds a cpumask_test_or_cycle() helper
function, to make it easier to code the preference for
the pCPU where the vCPU was running before.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen: credit2: do not warn if calling burn_credits more than once
Dario Faggioli [Wed, 6 Jul 2016 16:02:58 +0000 (17:02 +0100)]
xen: credit2: do not warn if calling burn_credits more than once

on the same vcpu, without NOW() having changed.

This is, in fact, a legitimate use case. If it happens,
we should just do nothing, without producing any warning
or debug message.

While there, fix style and add a couple of branching
hints.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen: credit2: kill useless helper function choose_cpu
Dario Faggioli [Wed, 6 Jul 2016 15:59:41 +0000 (16:59 +0100)]
xen: credit2: kill useless helper function choose_cpu

In fact, it has the same signature of csched2_cpu_pick,
which also is its unique caller.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen: credit2: insert and tickle don't need a cpu parameter
Dario Faggioli [Wed, 6 Jul 2016 15:56:28 +0000 (16:56 +0100)]
xen: credit2: insert and tickle don't need a cpu parameter

In fact, they always operate on the svc->processor of
the csched2_vcpu passed to them.

No functional change intended.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: Anshul Makkar <anshul.makkar@citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen: sched: make the 'tickled' perf counter clearer
Dario Faggioli [Wed, 6 Jul 2016 15:54:02 +0000 (16:54 +0100)]
xen: sched: make the 'tickled' perf counter clearer

In fact, what we have right now, i.e., tickle_idlers_none
and tickle_idlers_some, is not good enough for describing
what really happens in the various tickling functions of
the various scheduler.

Switch to a more descriptive set of counters, such as:
 - tickled_no_cpu: for when we don't tickle anyone
 - tickled_idle_cpu: for when we tickle one or more
                     idler
 - tickled_busy_cpu: for when we tickle one or more
                     non-idler

While there, fix style of an "out:" label in sched_rt.c.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: Meng Xu <mengxu@cis.upenn.edu>
Acked-by: George Dunlap <george.dunlap@citrix.com>
8 years agominor fixes (formatting, comments, unused includes etc.)
Corneliu ZUZU [Fri, 8 Jul 2016 07:49:23 +0000 (09:49 +0200)]
minor fixes (formatting, comments, unused includes etc.)

Minor fixes:
 - remove some empty lines
 - remove some unused includes
 - multi-line comment fixes
 - 80-columns formatting fixes

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
8 years agox86/vm-event: minor ASSERT fix, add 'unlikely'
Corneliu ZUZU [Fri, 8 Jul 2016 07:48:52 +0000 (09:48 +0200)]
x86/vm-event: minor ASSERT fix, add 'unlikely'

Minor fixes:

* vm_event_register_write_resume: ASSERT on non-NULL v->arch.vm_event instead of
  &v->arch.vm_event->write_data.
* add 'unlikely' in if

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
8 years agoxen/arm64: Use the correct TLBs flush instruction to nuke stage-2 TLBs
Julien Grall [Thu, 7 Jul 2016 18:49:08 +0000 (19:49 +0100)]
xen/arm64: Use the correct TLBs flush instruction to nuke stage-2 TLBs

The function flush_tlb is called to invalidate the TLBs for the current
domain when the stage-2 page tables are modified.

On ARMv8, the instruction "tlbi vmalle1is" (resp. "tlbi vmalle1") will
invalidate stage 1 entries associated to the current VMID (see D4-1811 in
ARM DDI 0487A.j).

Given that an implementation is allowed to cache separately stage 1 and
stage 2 translation (see D4.7.1), the instructions will not remove stage
2 entries when the translation is not combined in a single entry.
This will result the TLBs to hold invalid entries and possibly multiple
entries using the same VA.

Use "tlbi vmalls12e1is" (resp. "tlbi vmalls12e1"), to flush both stage
1 and 2 entries when the domain p2m is changed.

Also modify flush_tlb_local to invalidate stage 1 and 2 for the local
TLBs. Note that this function is used in the instruction abort path
before translating a GVA to a IPA. As far as I understand is to avoid a
guest poisoning the DTLB when memacces is in use. We might be able to
only invalidate stage 1 entries. However, I choose the safest way for now
(i.e invalidating stage 1 and 2 entries). We would need to introduce a
new set of helpers when we will want to restrict it.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agomonitor: minor #include change
Corneliu ZUZU [Thu, 7 Jul 2016 12:29:50 +0000 (14:29 +0200)]
monitor: minor #include change

Move xen/paging.h #include from hvm/monitor.h to hvm/monitor.c (include strictly
where needed) and also change to asm/paging.h (include strictly what's needed).

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
8 years agox86/vm_event_resume: surround VM_EVENT_REASON_MOV_TO_MSR w/ CONFIG_X86
Corneliu ZUZU [Thu, 7 Jul 2016 12:27:32 +0000 (14:27 +0200)]
x86/vm_event_resume: surround VM_EVENT_REASON_MOV_TO_MSR w/ CONFIG_X86

VM_EVENT_REASON_MOV_TO_MSR is X86-specific, surround w/ #ifdef accordingly.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
8 years agomonitor: rename and relocate vm_event_monitor_traps
Tamas K Lengyel [Thu, 7 Jul 2016 12:25:50 +0000 (14:25 +0200)]
monitor: rename and relocate vm_event_monitor_traps

The function vm_event_monitor_traps actually belongs in the monitor subsystem.
As part of this patch we fix the sync input's type to bool_t to match how
the callers use it.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@zentific.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
8 years agolibxl/netbsd: check num_exec in hotplug function
Wei Liu [Sat, 2 Jul 2016 11:35:30 +0000 (12:35 +0100)]
libxl/netbsd: check num_exec in hotplug function

This basically replicates the same logic in libxl_linux.c but with one
change -- only test num_exec == 0 in nic hotplug case because NetBSD let
QEMU call a script itself. Without this patch libxl will loop
indefinitely trying to execute hotplug script.

Reported-by: John Nemeth <jnemeth@cue.bc.ca>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
8 years agolibxl: debug output for args and env when invoking hotplug script
Wei Liu [Fri, 15 Apr 2016 11:56:03 +0000 (12:56 +0100)]
libxl: debug output for args and env when invoking hotplug script

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agox86emul: fold local variables
Jan Beulich [Tue, 5 Jul 2016 09:17:53 +0000 (11:17 +0200)]
x86emul: fold local variables

Declare some variables to they can be used by multiple pieces of code,
allowing some figure braces to be dropped (which don't align nicely
when used inside of case labeled statements).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agox86emul: drop pointless and add useful default cases
Jan Beulich [Tue, 5 Jul 2016 09:17:25 +0000 (11:17 +0200)]
x86emul: drop pointless and add useful default cases

There's no point in having default cases when all possible values have
respective case statements, or when there's just a "break" statement.

Otoh the two main switch() statements better get default cases added,
just to cover the case of someone altering one of the two lookup arrays
without suitably changing these switch statements.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agox86emul: use consistent exit mechanism
Jan Beulich [Tue, 5 Jul 2016 09:16:55 +0000 (11:16 +0200)]
x86emul: use consistent exit mechanism

Similar code should use similar exit mechanisms (return vs goto).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agovm-event: proper vCPU-paused checks at resume
Corneliu ZUZU [Mon, 4 Jul 2016 10:11:44 +0000 (12:11 +0200)]
vm-event: proper vCPU-paused checks at resume

A VM_EVENT_FLAG_VCPU_PAUSED flag in a vm-event response should only be treated
as informative that the toolstack user wants the vm-event subsystem to unpause
the target vCPU, but not be relied upon to decide if the target vCPU is actually
paused.

That being said, this patch does the following:

* Fixes (replaces) the old behavior in vm_event_resume, which relied on
  VM_EVENT_FLAG_VCPU_PAUSED to determine if the target vCPU is paused, by
  actually checking the vCPU vm-event pause-count.

* ASSERTs that the vCPU is paused in vm_event_set_registers and
  vm_event_toggle_singlestep.

* Ignores VM_EVENT_FLAG_DENY @ vm_event_register_write_resume if the target vCPU
  is not paused. Also adjusts comment in public/vm_event.h to reflect that.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
8 years agovm-event: MAINTAINERS fix
Corneliu ZUZU [Mon, 4 Jul 2016 10:11:30 +0000 (12:11 +0200)]
vm-event: MAINTAINERS fix

Fix vm-event section of MAINTAINERS file: add back files x86/hvm/monitor.c,
asm-x86/hvm/monitor.h, x86/monitor.c, x86/vm_event.c and sort entries
alphabetically.

Culprits which got MAINTAINERS out-of-sync:
c/s ca63cee: "monitor: Rename hvm/event to hvm/monitor":
    - added x86/hvm/monitor.c & asm-x86/hvm/monitor.h w/o MAINTAINERS update
c/s ec89da2: "MAINTAINERS: update monitor/vm_event covered code":
    - (mistakenly?) removed both x86/monitor.c & x86/vm_event.c

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
8 years agox86/vmx: clean up TRAP_int3 handling
Tamas K Lengyel [Mon, 4 Jul 2016 10:11:03 +0000 (12:11 +0200)]
x86/vmx: clean up TRAP_int3 handling

Clean up the handling of TRAP_int3 VMEXITs to conform to the handling
of TRAP_debug.

Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agox86/vm_event: add HVM debug exception vm_events
Tamas K Lengyel [Mon, 4 Jul 2016 10:10:00 +0000 (12:10 +0200)]
x86/vm_event: add HVM debug exception vm_events

Since in-guest debug exceptions are now unconditionally trapped to Xen, adding
a hook for vm_event subscribers to tap into this new always-on guest event. We
rename along the way hvm_event_breakpoint_type to hvm_event_type to better
match the various events that can be passed with it. We also introduce the
necessary monitor_op domctl's to enable subscribing to the events.

This patch also provides monitor subscribers to int3 events proper access
to the instruction length necessary for accurate event-reinjection. Without
this subscribers manually have to evaluate if the int3 instruction has any
prefix attached which would change the instruction length.

Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agox86/VT-x: Dump VMCS on VMLAUNCH/VMRESUME failure
Andrew Cooper [Thu, 30 Jun 2016 20:00:01 +0000 (21:00 +0100)]
x86/VT-x: Dump VMCS on VMLAUNCH/VMRESUME failure

If a VMLAUNCH/VMRESUME fails due to invalid control or host state, dump the
VMCS before crashing the domain.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
8 years agosched: rtds: use non-atomic bit-ops
Tianyang Chen [Thu, 30 Jun 2016 12:01:02 +0000 (14:01 +0200)]
sched: rtds: use non-atomic bit-ops

Vcpu flags are checked and cleared atomically. Performance can be
improved with corresponding non-atomic versions since schedule.c
already has spin_locks in place.

Signed-off-by: Tianyang Chen <tiche@cis.upenn.edu>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
8 years agosched: rtds code clean-up
Tianyang Chen [Thu, 30 Jun 2016 12:00:34 +0000 (14:00 +0200)]
sched: rtds code clean-up

No functional change:
 -aligned comments in rt_vcpu struct
 -removed double underscores from the names of some functions
 -fixed coding sytle for control structures involving lists
 -fixed typos in the comments
 -added comments for UPDATE_LIMIT_SHIFT

Signed-off-by: Tianyang Chen <tiche@cis.upenn.edu>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
8 years agox86: remove duplicated IA32_FEATURE_CONTROL MSR macro
Kai Huang [Thu, 30 Jun 2016 11:59:20 +0000 (13:59 +0200)]
x86: remove duplicated IA32_FEATURE_CONTROL MSR macro

Below commit introduced a new macro MSR_IA32_FEATURE_CONTROL for
IA32_FEATURE_CONTROL MSR but it didn't remove old IA32_FEATURE_CONTROL_MSR
macro. The new one has better naming convention, so remove the old as a
duplication. Also move the macros of bit definition of IA32_FEATURE_CONTROL MSR
down to make them together with the new one. The *_MSR* infix is also removed as
it is pointless.

commit 5a211704e8813c4890c8ce8dc4189d1dfb35ecd0
Author: Len Brown <len.brown@intel.com>
Date:   Fri Apr 8 22:31:47 2016 +0200

    mwait-idle: prevent SKL-H boot failure when C8+C9+C10 enabled

    Some SKL-H configurations require "max_cstate=7" to boot.
    While that is an effective workaround, it disables C10.

    ......

Above commit also used SGX_ENABLE (bit 18) in IA32_FEATURE_CONTROL MSR without a
macro for it. A new macro IA32_FEATURE_CONTROL_SGX_ENABLE is also added for
better code and future use.

Relevant code that uses those macros are changed accordingly.

Signed-off-by: Kai Huang <kai.huang@linux.intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agoxen/page_alloc: Distinguish different errors from assign_pages()
Andrew Cooper [Tue, 28 Jun 2016 17:42:15 +0000 (18:42 +0100)]
xen/page_alloc: Distinguish different errors from assign_pages()

assign_pages() has a return type of int, but only returns 0 or -1.  As there
are two distinct failure cases, return a more meaningful error.

All caller currently use its boolean nature, so there is no resulting
change (yet).

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
8 years agoRevert "xen: arm: Update arm64 image header"
Andrew Cooper [Wed, 29 Jun 2016 18:13:20 +0000 (19:13 +0100)]
Revert "xen: arm: Update arm64 image header"

This reverts commit 14eedf8e7169b05e383220b682656a449e5f1c08.

This patch is breaking boot on any ARM64 platform (UEFI and bootwrapper).

Requested-by: Julien Grall <julien.grall@arm.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agoMAINTAINERS: change gdbsx maintainer
Elena Ufimtseva [Wed, 29 Jun 2016 14:39:46 +0000 (16:39 +0200)]
MAINTAINERS: change gdbsx maintainer

Change gdbsx maintainer to myself.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
8 years agox86/EFI + Live Patch: avoid symbol address truncation
Jan Beulich [Wed, 29 Jun 2016 14:38:50 +0000 (16:38 +0200)]
x86/EFI + Live Patch: avoid symbol address truncation

ld associates __init_end, placed outside of any section by the linker
script, with the following section, resulting in a huge (wrapped, as it
would be negative) section relative offset. COFF symbol tables store
section relative addresses, and hence the above leads to assembler
truncation warnings when all symbols get included in the symbol table
(for Live Patching code). To overcome this, move __init_end past both
ALIGN() directives. The consuming code (init_done()) is fine with such
an adjustment (the distinction really would only be relevant for the
loop claring the pages, and I think it's acceptable to clear a few
more on - for now - EFI). This effectively results in the
(__init_begin,__init_end) and (__2M_init_start,__2M_init_end) pairs to
become identical, with their different names only serving documentation
purposes now.

Note that moving __init_end and __2M_init_end into .init is not a good
idea, as that would significantly grow xen.efi binary size.

While inspecting symbol table and ld behavior I also noticed that
__2M_text_start gets put at address zero in the EFI case, which hasn't
caused problems solely because we don't actually reference that symbol.
Correct the setting of the initial address, and comment out said symbol
for the time being, as with the initial address correction it would in
turn cause an assembler truncation warning similar to the one mentioned
above.

While checking init_done() for correctness with the above changes I
noticed that code can easily be folded there, at once correcting the
logged amount of memory which has got freed for the 2M-alignment case
(i.e. EFI right now).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agoRevert "xsm: add a default policy to .init.data"
Jan Beulich [Wed, 29 Jun 2016 14:37:07 +0000 (16:37 +0200)]
Revert "xsm: add a default policy to .init.data"

This reverts commit 08cffe6696c047123bd552e095163924c8ef4353,
which broke the ARM (32-bit) build.

8 years agoxen/arm: Rename grant_table_gfpn into grant_table_gfn and use the typesafe gfn
Julien Grall [Tue, 28 Jun 2016 16:17:09 +0000 (17:17 +0100)]
xen/arm: Rename grant_table_gfpn into grant_table_gfn and use the typesafe gfn

The correct acronym for a guest physical frame is gfn. Also use
the typesafe gfn to ensure that a guest frame is effectively used.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen: Use typesafe gfn in xenmem_add_to_physmap_one
Julien Grall [Tue, 28 Jun 2016 16:17:08 +0000 (17:17 +0100)]
xen: Use typesafe gfn in xenmem_add_to_physmap_one

The x86 version of the function xenmem_add_to_physmap_one contains
variable name gpfn and gfn which make the code very confusing.
I have left unchanged for now.

Also, rename gpfn to gfn in the ARM version as the latter is the correct
acronym for a guest physical frame.

Finally, remove the trailing whitespace around the changes.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen: Use typesafe gfn/mfn in guest_physmap_* helpers
Julien Grall [Tue, 28 Jun 2016 16:17:07 +0000 (17:17 +0100)]
xen: Use typesafe gfn/mfn in guest_physmap_* helpers

Also rename some variables to gfn or mfn when it does not require much
rework.

Finally replace %hu with %d when printing the domain id in
guest_physmap_add_entry (arch/x86/mm/p2m.c).

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen: arm: Update arm64 image header
Dirk Behme [Mon, 27 Jun 2016 07:53:10 +0000 (09:53 +0200)]
xen: arm: Update arm64 image header

With the Linux kernel commits

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/Documentation/arm64/booting.txt?id=4370eec05a887b0cd4392cd5dc5b2713174745c0

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/Documentation/arm64/booting.txt?id=a2c1d73b94ed49f5fac12e95052d7b140783f800

the arm64 image header changed. While the size of the header isn't changed,
some members have changed their usage.

Update Xen to this updated image header.

The main changes are that the first magic is gone and that there is an
image size, now.

In case we read a size != 0, let's use this image size, now. This does
allow us to check if the kernel Image is larger than the size given in
the device tree, too.

Additionally, add an error message if the magic is not found. This might
be the case with kernel's < 3.12 prior to

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4370eec05a887b0cd4392cd5dc5b2713174745c0

which introduced the second magic.

This is acceptable as the support of Xen for ARM64 in Linux has been added
in Linux 3.11 and the number of boards supported by Linux 3.11 on ARM64 is
very limited: ARM models and X-gene. And for the latter it was an early
support with only the serial and timer upstreamed.

Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Julien Grall <julien.grall@arm.com>
8 years agovm_event: clear up return value of vm_event_monitor_traps
Tamas K Lengyel [Tue, 28 Jun 2016 09:36:03 +0000 (11:36 +0200)]
vm_event: clear up return value of vm_event_monitor_traps

The return value has not been clearly defined, with the function
never returning 0 which seemingly indicated a condition where the
guest should crash.

In this patch we define -rc as error condition where a subscriber is
present but an error prevented the notification from being sent;
0 where there is no subscriber or the notification was sent and the vCPU
is not paused (i.e. safe to continue execution as normal); and 1 where the
notification was sent with the vCPU paused and we are waiting for a
response.

Signed-off-by: Tamas K Lengyel <tamas@tklengyel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agovt-d: convert conditionals of qi_ctrl->qinval_maddr into ASSERT()s
Quan Xu [Tue, 28 Jun 2016 09:35:40 +0000 (11:35 +0200)]
vt-d: convert conditionals of qi_ctrl->qinval_maddr into ASSERT()s

QI ought to have got disabled if any of the IOMMU table setup
failed. A QI function (other than enable_qinval) is unreachable
when qi_ctrl->qinval_maddr is zero.

Signed-off-by: Quan Xu <quan.xu@intel.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agovt-d: synchronize for Device-TLB flush one by one
Quan Xu [Tue, 28 Jun 2016 09:35:19 +0000 (11:35 +0200)]
vt-d: synchronize for Device-TLB flush one by one

Today we do Device-TLB flush synchronization after issuing flush
requests for all ATS devices belonging to a VM. Doing so however
imposes a limitation, i.e. that we can not figure out which flush
request is blocked in the flush queue list, based on VT-d spec.

To prepare correct Device-TLB flush timeout handling in next patch,
we change the behavior to synchronize for every Device-TLB flush
request. So the Device-TLB flush interface is changed a little bit,
by checking timeout within the function instead of outside of function.

Accordingly we also do a similar change for flush interfaces of
IOTLB/IEC/Context, i.e. moving synchronization into the function.
Since there is no user of a non-synced interface, we just rename
existing ones with _sync suffix.

Signed-off-by: Quan Xu <quan.xu@intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
8 years agoIOMMU: add a timeout parameter for device IOTLB invalidation
Quan Xu [Tue, 28 Jun 2016 09:33:39 +0000 (11:33 +0200)]
IOMMU: add a timeout parameter for device IOTLB invalidation

The parameter 'iommu_dev_iotlb_timeout' specifies the timeout
of device IOTLB invalidation in milliseconds. By default, the
timeout is 1000 milliseconds, which can be boot-time changed.

We also confirmed with VT-d hardware team that 1 milliseconds
is large enough for VT-d IOMMU internal invalidation.

the existing panic() is eliminated and we bubble up the timeout
of device IOTLB invalidation for further processing, as the
PCI-e Address Translation Services (ATS) mandates a timeout of
60 seconds for device IOTLB invalidation. Obviously we can't
spin for 60 seconds or otherwise Xen hypervisor hangs.

Signed-off-by: Quan Xu <quan.xu@intel.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
8 years agoxsm: add a default policy to .init.data
Daniel De Graaf [Mon, 20 Jun 2016 14:04:26 +0000 (10:04 -0400)]
xsm: add a default policy to .init.data

This adds a Kconfig option and support for including the XSM policy from
tools/flask/policy in the hypervisor so that the bootloader does not
need to provide a policy to get sane behavior from an XSM-enabled
hypervisor.  The policy provided by the bootloader, if present, will
override the built-in policy.

Enabling this option only builds the policy if checkpolicy is available
during compilation of the hypervisor; otherwise, it does nothing.  The
XSM policy is not moved out of tools because that remains the primary
location for installing and configuring the policy.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Doug Goldstein <cardoe@cardoe.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>
8 years agoxen: Make FLASK_AVC_STATS kconfig option visible
Daniel De Graaf [Mon, 20 Jun 2016 14:04:25 +0000 (10:04 -0400)]
xen: Make FLASK_AVC_STATS kconfig option visible

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Doug Goldstein <cardoe@cardoe.com>
8 years agoxsm: clean up unregistration
Daniel De Graaf [Mon, 20 Jun 2016 14:04:24 +0000 (10:04 -0400)]
xsm: clean up unregistration

The only possible value of original_ops was &dummy_xsm_ops, and
unregister_xsm was never used.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Doug Goldstein <cardoe@cardoe.com>
8 years agoxsm: annotate setup functions with __init
Daniel De Graaf [Mon, 20 Jun 2016 14:04:23 +0000 (10:04 -0400)]
xsm: annotate setup functions with __init

These functions were only called from __init functions.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Doug Goldstein <cardoe@cardoe.com>
8 years agoxen: move FLASK entry under XSM in Kconfig
Daniel De Graaf [Tue, 21 Jun 2016 17:09:23 +0000 (13:09 -0400)]
xen: move FLASK entry under XSM in Kconfig

Since enabling XSM is required to enable FLASK, place the option for
FLASK below the one for XSM.  In addition, since it does not make sense
to enable XSM without any XSM providers, and FLASK is the only XSM
provider, hide the option to disable FLASK under EXPERT.

Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Doug Goldstein <cardoe@cardoe.com>