xen.git
8 years agoxen/arm: vpl011: Add support for vuart console in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:31 +0000 (11:43 +0530)]
xen/arm: vpl011: Add support for vuart console in xenconsole

This patch finally adds the support for vuart console. It adds
two new fields in the console initialization:

- optional
- use_gnttab

optional flag tells whether the console is optional.

use_gnttab tells whether the ring buffer should be allocated using
grant table.

The VUART console is enabled ony for ARM.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add support for multiple consoles in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:30 +0000 (11:43 +0530)]
xen/arm: vpl011: Add support for multiple consoles in xenconsole

This patch adds the support for multiple consoles and introduces the
iterator functions to operate on multiple consoles.

The functions called by the iterators check that they are operating
on valid I/O parameters. This ensures that if a particular console is
not initialized then the functions will not do anything for that
console type.

This patch is in preparation to support a new vuart console.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new console_close_evtchn function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:29 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new console_close_evtchn function in xenconsole

This patch introduces a console_close_evtchn function. This function closes
the console event channel.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new console_open_log function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:28 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new console_open_log function in xenconsole

This patch introduces a console_open_log console_cleanup function. This function
opens the console log file.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new console_cleanup function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:27 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new console_cleanup function in xenconsole

This patch introduces a new console_cleanup function. This function
frees up the console resources.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new handle_console_tty function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:26 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new handle_console_tty function in xenconsole

This patch introduces a new handle_console_tty function. This function
performs read/write from/to console tty.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new handle_console_ring function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:25 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new handle_console_ring function in xenconsole

This patch introduces a new handle_console_ring function. This function
reads the data from the ring buffer on receiving an event.

The initialization of event channel poll fd to -1 is moved inside the
handle_console_ring function as they are related. There should be no
change in the behavior as there is no functional change.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new console_evtchn_unmask function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:24 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new console_evtchn_unmask function in xenconsole

This patch introduces a new console_evtchn_unmask function. This function
unmasks the console event channel if it is masked for some timeout
period.

One optimization that has been done is to merge the two for loops.

One for loop was used to iterate through all domains and
unmask the domain event channels which had been rate limited for a
specified duration.

The other for loop was run to add the event channel fd and the tty fd to
the poll list.

These two for loops were merged so that the these operations can be done
in one iteration instead of two iterations.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new maybe_add_console_tty_fd function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:23 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new maybe_add_console_tty_fd function in xenconsole

This patch introduces a new maybe_add_console_tty_fd function. This function
adds the tty fd to the list of polled fds.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new maybe_add_console_evtchn_fd function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:22 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new maybe_add_console_evtchn_fd function in xenconsole

This patch introduces a new maybe_add_console_evtchn_fd function. This
function adds the console event channel FD to list of polled FDs.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new buffer_available function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:21 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new buffer_available function in xenconsole

This patch introduces a new buffer_available function to check if
more data is allowed to be buffered.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new console_init function in xenconsole
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:20 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new console_init function in xenconsole

This patch introduces a new console_init function. This function
initializes the console structure.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Modify xenconsole functions to take console structure as input
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:19 +0000 (11:43 +0530)]
xen/arm: vpl011: Modify xenconsole functions to take console structure as input

Xenconsole functions take domain structure as input. These functions shall be
modified to take console structure as input since these functions typically perform
console specific operations.

Also the console specific functions starting with prefix "domain_" shall be modified
to "console_" to indicate that these are console specific functions.

This patch is in preparation to support multiple consoles to support vuart console.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Rename the console structure field conspath to xspath
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:18 +0000 (11:43 +0530)]
xen/arm: vpl011: Rename the console structure field conspath to xspath

The console->conspath name is changed to console->xspath as it is
clear from the name that it is referring to xenstore path.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Modify xenconsole to define and use a new console structure
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:17 +0000 (11:43 +0530)]
xen/arm: vpl011: Modify xenconsole to define and use a new console structure

Xenconsole uses a domain structure which contains console specific fields. This
patch defines a new console structure, which would be used by the xenconsole
functions to perform console specific operations like reading/writing data from/to
the console ring buffer or reading/writing data from/to console tty.

This patch is in preparation to support multiple consoles to support vuart console.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add a new vuart node in the xenstore
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:16 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new vuart node in the xenstore

Add a new vuart console node to xenstore. This node is added at

/local/domain/$DOMID/vuart/0.

The node contains information such as the ring-ref, event channel,
buffer limit and type of console.

Xenconsole reads the node information to setup the ring buffer and
event channel for sending/receiving vuart data.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: vpl011: Add a new domctl API to initialize vpl011
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:15 +0000 (11:43 +0530)]
xen/arm: vpl011: Add a new domctl API to initialize vpl011

Add a new domctl API to initialize vpl011. It takes the GFN and console
backend domid as input and returns an event channel to be used for
sending and receiving events from Xen.

Xen will communicate with xenconsole using GFN as the ring buffer and
the event channel to transmit and receive pl011 data on the guest domain's
behalf.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Rearrange xen header includes in alphabetical order in domctl.c
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:14 +0000 (11:43 +0530)]
xen/arm: vpl011: Rearrange xen header includes in alphabetical order in domctl.c

Rearrange xen header includes in alphabetical order in domctl.c.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Julien Grall <julien.grall@arm.com>
8 years agoxen/arm: vpl011: Add support for vuart in libxl
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:13 +0000 (11:43 +0530)]
xen/arm: vpl011: Add support for vuart in libxl

An option is provided in libxl to enable/disable SBSA vuart while
creating a guest domain.

Libxl now supports a generic vuart console and SBSA uart is a specific type.
In future support can be added for multiple vuart of different types.

User can enable SBSA vuart by adding the following line in the guest
configuration file:

vuart = "sbsa_uart"

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: vpl011: Allocate a new GFN in the toolstack for vuart
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:12 +0000 (11:43 +0530)]
xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart

Allocate a new gfn to be used as a ring buffer between xenconsole
and Xen for sending/receiving pl011 console data.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: vpl011: Add SBSA UART emulation in Xen
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:11 +0000 (11:43 +0530)]
xen/arm: vpl011: Add SBSA UART emulation in Xen

Add emulation code to emulate read/write access to pl011 registers
and pl011 interrupts:

    - Emulate DR read/write by reading and writing from/to the IN
      and OUT ring buffers and raising an event to the backend when
      there is data in the OUT ring buffer and injecting an interrupt
      to the guest when there is data in the IN ring buffer

    - Other registers are related to interrupt management and
      essentially control when interrupts are delivered to the guest

This patch implements the SBSA Generic UART which is a subset of ARM
PL011 UART.

The SBSA Generic UART is covered in Appendix B of
https://static.docs.arm.com/den0029/a/Server_Base_System_Architecture_v3_1_ARM_DEN_0029A.pdf

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Acked-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen/arm: vpl011: Define common ring buffer helper functions in console.h
Bhupinder Thakur [Wed, 27 Sep 2017 06:13:10 +0000 (11:43 +0530)]
xen/arm: vpl011: Define common ring buffer helper functions in console.h

DEFINE_XEN_FLEX_RING(xencons) defines common helper functions such as
xencons_queued() to tell the current size of the ring buffer,
xencons_mask() to mask off the index, which are useful helper functions.
pl011 emulation code will use these helper functions.

io/console.h includes io/ring.h which defines DEFINE_XEN_FLEX_RING.

In console/daemon/io.c, string.h had to be included before io/console.h
because ring.h uses string functions.

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
8 years agox86/msr: Correct the definition of MSR_IA32_APICBASE_BASE
Andrew Cooper [Fri, 5 Aug 2016 13:51:13 +0000 (14:51 +0100)]
x86/msr: Correct the definition of MSR_IA32_APICBASE_BASE

0xfffff << 12 is undefined behaviour, due to shifting into the sign bit of an
integer.

Spotted by the Undefined Behaviour Sanitiser

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/x86: p2m-pod: Rework prototype of p2m_pod_demand_populate
Julien Grall [Mon, 2 Oct 2017 12:59:41 +0000 (13:59 +0100)]
xen/x86: p2m-pod: Rework prototype of p2m_pod_demand_populate

    - Switch the return type to bool
    - Remove the parameter p2m_query_t q as it is not used

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m-pod: Use typesafe gfn for the fields reclaim_single and max_guest
Julien Grall [Mon, 2 Oct 2017 12:59:40 +0000 (13:59 +0100)]
xen/x86: p2m-pod: Use typesafe gfn for the fields reclaim_single and max_guest

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m-pod: Use typesafe gfn in p2m_pod_demand_populate
Julien Grall [Mon, 2 Oct 2017 12:59:39 +0000 (13:59 +0100)]
xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_demand_populate

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m-pod: Use typesafe gfn in p2m_pod_zero_check
Julien Grall [Mon, 2 Oct 2017 12:59:38 +0000 (13:59 +0100)]
xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_zero_check

At the same time make the array gfns const has it is not modified within
the function.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m-pod: Clean-up p2m_pod_zero_check
Julien Grall [Mon, 2 Oct 2017 12:59:37 +0000 (13:59 +0100)]
xen/x86: p2m-pod: Clean-up p2m_pod_zero_check

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m-pod: Use typesafe GFN in pod_eager_record
Julien Grall [Mon, 2 Oct 2017 12:59:36 +0000 (13:59 +0100)]
xen/x86: p2m-pod: Use typesafe GFN in pod_eager_record

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m: Use typesafe GFN in p2m_set_entry
Julien Grall [Mon, 2 Oct 2017 12:59:35 +0000 (13:59 +0100)]
xen/x86: p2m: Use typesafe GFN in p2m_set_entry

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m: Use typesafe gfn for the P2M callbacks get_entry and set_entry
Julien Grall [Mon, 2 Oct 2017 12:59:34 +0000 (13:59 +0100)]
xen/x86: p2m: Use typesafe gfn for the P2M callbacks get_entry and set_entry

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
8 years agoxen/x86: p2m-pod: Use typesafe gfn in p2m_pod_decrease_reservation
Julien Grall [Mon, 2 Oct 2017 15:40:04 +0000 (16:40 +0100)]
xen/x86: p2m-pod: Use typesafe gfn in p2m_pod_decrease_reservation

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
8 years agoxen/x86: p2m-pod: Clean-up use of typesafe MFN
Julien Grall [Mon, 2 Oct 2017 15:40:03 +0000 (16:40 +0100)]
xen/x86: p2m-pod: Clean-up use of typesafe MFN

Some unboxing/boxing can be avoided by using mfn_add(...) instead.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/x86: p2m-pod: Avoid redundant assignments in p2m_pod_demand_populate
Julien Grall [Mon, 2 Oct 2017 15:40:02 +0000 (16:40 +0100)]
xen/x86: p2m-pod: Avoid redundant assignments in p2m_pod_demand_populate

gfn_aligned is assigned 3 times with the exact same formula. All the
variables used are not modified, so consolidate in a single assignment
at the beginning of the function.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/x86: p2m-pod: Fix coding style
Julien Grall [Mon, 2 Oct 2017 15:40:01 +0000 (16:40 +0100)]
xen/x86: p2m-pod: Fix coding style

Also take the opportunity to:
    - move from 1 << * to 1UL << *.
    - use unsigned when possible
    - move from unsigned int -> unsigned long for some induction
    variables

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/x86: p2m-pod: Fix coding style for comments
Julien Grall [Mon, 2 Oct 2017 15:40:01 +0000 (16:40 +0100)]
xen/x86: p2m-pod: Fix coding style for comments

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/x86: p2m-pod: Remove trailing whitespaces
Julien Grall [Mon, 2 Oct 2017 15:40:00 +0000 (16:40 +0100)]
xen/x86: p2m-pod: Remove trailing whitespaces

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/x86: p2m-pod: Clean-up includes
Julien Grall [Mon, 2 Oct 2017 15:39:59 +0000 (16:39 +0100)]
xen/x86: p2m-pod: Clean-up includes

A lot of the headers are not necessary. At the same time, order them in the
alphabetical order.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
8 years agox86/monitor: Notify monitor if an emulation fails.
Petre Pircalabu [Mon, 2 Oct 2017 15:04:56 +0000 (16:04 +0100)]
x86/monitor: Notify monitor if an emulation fails.

If case of a vm_event with the emulate_flags set, if the instruction
is not implemented by the emulator, the monitor should be notified instead
of directly injecting a hw exception.
This behavior can be used to re-execute an instruction not supported by
the emulator using the real processor (e.g. altp2m) instead of just
crashing.

Signed-off-by: Petre Pircalabu <ppircalabu@bitdefender.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
8 years agox86emul: Add return code information to error messages
Petre Pircalabu [Mon, 2 Oct 2017 15:04:55 +0000 (16:04 +0100)]
x86emul: Add return code information to error messages

- print the return code of the last failed emulator operation
in hvm_dump_emulation_state.
- print the return code in sh_page_fault (SHADOW_PRINTK) to make the
distiction between X86EMUL_UNHANDLEABLE and X86EMUL_UNIMPLEMENTED.

Signed-off-by: Petre Pircalabu <ppircalabu@bitdefender.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agox86emul: New return code for unimplemented instruction
Petre Pircalabu [Mon, 2 Oct 2017 15:04:54 +0000 (16:04 +0100)]
x86emul: New return code for unimplemented instruction

Enforce the distinction between an instruction not implemented by the
emulator and the failure to emulate that instruction by defining a new
return code, X86EMUL_UNIMPLEMENTED.

This value should only be returned by the core emulator when a valid
opcode is found but the execution logic for that instruction is missing.
It should NOT be returned by any of the x86_emulate_ops callbacks.

e.g. hvm_process_io_intercept should not return X86EMUL_UNIMPLEMENTED.
The return value of this function depends on either the return code of
one of the hvm_io_ops handlers (read/write) or the value returned by
hvm_copy_guest_from_phys / hvm_copy_to_guest_phys.

Similary, none of this functions should return X86EMUL_UNIMPLEMENTED.
 - hvm_io_intercept
 - hvmemul_do_io
 - hvm_send_buffered_ioreq
 - hvm_send_ioreq
 - hvm_broadcast_ioreq
 - hvmemul_do_io_buffer
 - hvmemul_validate

Also the behavior of hvm_emulate_one_insn and vmx_realmode_emulate_one
was modified to generate an Invalid Opcode trap when X86EMUL_UNRECOGNIZED
is returned by the emulator instead of just crash the domain.

Signed-off-by: Petre Pircalabu <ppircalabu@bitdefender.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agox86/svm: Fix a livelock when trying to run shadowed unpaged guests
Andrew Cooper [Tue, 26 Sep 2017 16:08:33 +0000 (17:08 +0100)]
x86/svm: Fix a livelock when trying to run shadowed unpaged guests

On AMD processors which support SMEP (Some Fam16h processors) and SMAP (Zen,
Fam17h), a guest which is running with shadow paging and clears CR0.PG while
keeping CR4.{SMEP,SMAP} set will livelock, as hardware raises #PF which the
shadow pagetable concludes shouldn't happen.

This occurs because hardware is running with host paging settings, which
causes the guests choice of SMEP/SMAP to actually take effect, even though
they shouldn't from the guests point of view.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
8 years agolibxl: remove dead code in libxl__domain_build_info_setdefault
Roger Pau Monne [Fri, 29 Sep 2017 09:53:07 +0000 (10:53 +0100)]
libxl: remove dead code in libxl__domain_build_info_setdefault

Coverity-ID: 1418831

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen/arm: Correctly report the memory region in the dummy NUMA helpers
Julien Grall [Fri, 29 Sep 2017 20:16:47 +0000 (13:16 -0700)]
xen/arm: Correctly report the memory region in the dummy NUMA helpers

NUMA is currently not supported on Arm. Because common code is
NUMA-aware, dummy helpers are instead provided to expose a single node.

Those helpers are for instance used to know the region to scrub.

However the memory region is not reported correctly. Indeed, the
frametable may not be at the beginning of the memory and there might be
multiple memory banks. This will lead to not scrub some part of the
memory.

The memory information can be found using:
    * first_valid_mfn as the start of the memory
    * max_page - first_valid_mfn as the spanned pages

Note that first_valid_mfn is now been exported. The prototype has been
added in asm-arm/numa.h and not in a common header because I would
expect the variable to become static once NUMA is fully supported on
Arm.

This is XSA-245.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reported-and-Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
8 years agoxen/page_alloc: Cover memory unreserved after boot in first_valid_mfn
Julien Grall [Fri, 29 Sep 2017 20:16:21 +0000 (13:16 -0700)]
xen/page_alloc: Cover memory unreserved after boot in first_valid_mfn

On Arm, some regions (e.g Initramfs, Dom0 Kernel...) are marked as
reserved until the hardware domain is built and they are copied into its
memory. Therefore, they will not be added in the boot allocator via
init_boot_pages.

Instead, init_xenheap_pages will be called once the region are not used
anymore.

Update first_valid_mfn in both init_heap_pages and init_boot_pages
(already exist) to cover all the cases.

This is XSA-245.

Signed-off-by: Julien Grall <julien.grall@arm.com>
[Adjust comment, added locking around first_valid_mfn update]
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Reported-and-Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
8 years agoxen/arm: Fix the issue in cmp_mmio_handler used in find_mmio_handler
Bhupinder Thakur [Fri, 29 Sep 2017 05:59:46 +0000 (11:29 +0530)]
xen/arm: Fix the issue in cmp_mmio_handler used in find_mmio_handler

This patch fixes the wrong range check done in cmp_mmio_handler().

This function returns -1 , 0 or 1  based on whether the key value
is below the range, in the range or above the range where the range is
(start, start+size). However, it should check against (start, start+size-1)
because start+size falls outside the range.

This resulted in returning a wrong mmio_handler for a given mmio address which
happened to be start+size.

This bug was introduced when the mmio region search switched from
linear search to binary search in the following commit:

8047e09 "xen/arm: io: Use binary search for mmio handler lookup".

Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
8 years agoxen: fail gnttab_grow_table() in case of missing allocations
Juergen Gross [Fri, 29 Sep 2017 10:51:40 +0000 (12:51 +0200)]
xen: fail gnttab_grow_table() in case of missing allocations

In case gnttab_grow_table() is being called without
grant_table_set_limits() having been called for the domain, e.g. in
case of a toolstack error, fail the function instead of crashing the
system.

While at it let gnttab_grow_table() return a proper error code instead
of 1 for success.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
8 years agoxen/gnttab: Clean up goto tangle in grant_table_init()
Andrew Cooper [Fri, 29 Sep 2017 12:29:21 +0000 (13:29 +0100)]
xen/gnttab: Clean up goto tangle in grant_table_init()

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
8 years agolibxl: remove device model "none" from IDL
Roger Pau Monne [Fri, 22 Sep 2017 15:25:12 +0000 (16:25 +0100)]
libxl: remove device model "none" from IDL

And the xl.cfg man page documentation.

It should be possible to re-introduce it in the future with a proper
implementation, in order to create a HVM guest without a device model,
which is slightly different from a PVHv2 guest.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoxl: add PVH as a guest type
Roger Pau Monne [Fri, 22 Sep 2017 15:25:11 +0000 (16:25 +0100)]
xl: add PVH as a guest type

And remove device model "none".

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add PVH support to x86 functions
Roger Pau Monne [Fri, 22 Sep 2017 15:25:11 +0000 (16:25 +0100)]
libxl: add PVH support to x86 functions

This also includes the x86 ACPI related functions. Remove support for
device model "none"

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add PVH support to USB
Roger Pau Monne [Fri, 22 Sep 2017 15:25:11 +0000 (16:25 +0100)]
libxl: add PVH support to USB

Add PVH support to usb related functions.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: remove device model "none" support from stream functions
Roger Pau Monne [Fri, 22 Sep 2017 15:25:10 +0000 (16:25 +0100)]
libxl: remove device model "none" support from stream functions

Remove the usage of device model "none" in the migration stream
related functions.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: PVH guests use PV nics
Roger Pau Monne [Fri, 22 Sep 2017 15:25:10 +0000 (16:25 +0100)]
libxl: PVH guests use PV nics

Remove device model "none" support from the nic functions.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add PVH support to memory functions
Roger Pau Monne [Fri, 22 Sep 2017 15:25:10 +0000 (16:25 +0100)]
libxl: add PVH support to memory functions

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add PVH support to vpcu hotplug, domain destruction/pause and domain configuration
Roger Pau Monne [Fri, 22 Sep 2017 15:25:10 +0000 (16:25 +0100)]
libxl: add PVH support to vpcu hotplug, domain destruction/pause and domain configuration

And remove support for device model "none".

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add PVH support to domain save/suspend
Roger Pau Monne [Fri, 22 Sep 2017 15:25:09 +0000 (16:25 +0100)]
libxl: add PVH support to domain save/suspend

And remove the device model "none" support.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add PVH support to domain building
Roger Pau Monne [Fri, 22 Sep 2017 15:25:09 +0000 (16:25 +0100)]
libxl: add PVH support to domain building

And remove device model "none" support.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: set device model for PVH guests
Roger Pau Monne [Fri, 22 Sep 2017 15:25:09 +0000 (16:25 +0100)]
libxl: set device model for PVH guests

PVH guests use the same device model selection as PV guests, because
PVH guests only use the device model for the PV backends.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: remove device model "none" support from disk related functions
Roger Pau Monne [Fri, 22 Sep 2017 15:25:08 +0000 (16:25 +0100)]
libxl: remove device model "none" support from disk related functions

CD-ROM backend selection was partially based on the device model, this
is no longer needed since the device model "none" is now removed, so
HVM guests always have a device model.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add PVH support to domain creation
Roger Pau Monne [Fri, 22 Sep 2017 15:25:08 +0000 (16:25 +0100)]
libxl: add PVH support to domain creation

Remove the device model "none" support from domain creation and
introduce support for PVH.

This requires changing some of the HVM checks to be applied for both
HVM and PVH.

Setting device model to none was never supported since it was an
unstable interface used while transitioning from PVHv1 to PVHv2.

Now that PVHv1 has been finally removed and that a supported
interface for PVHv2 is being added this option is no longer necessary,
hence it's removed.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: set PVH guests to use the PV console
Roger Pau Monne [Fri, 22 Sep 2017 15:25:08 +0000 (16:25 +0100)]
libxl: set PVH guests to use the PV console

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: allow PVH guests to use a bootloader
Roger Pau Monne [Fri, 22 Sep 2017 15:25:07 +0000 (16:25 +0100)]
libxl: allow PVH guests to use a bootloader

Allow PVH guests to boot using a bootloader.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: introduce a PVH guest type
Roger Pau Monne [Fri, 22 Sep 2017 15:25:07 +0000 (16:25 +0100)]
libxl: introduce a PVH guest type

The new guest type is introduced to the libxl IDL. libxl__domain_make
is also modified to save the guest type, and libxl__domain_type is
expanded to fetch that information when detecting guest type.

This is required because the hypervisor only differentiates between PV
and HVM guests, so libxl needs some extra information in order to
differentiate between a HVM and a PVH guest.

The new PVH guest type and its options are documented on the xl.cfg
man page.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoxl: introduce a firmware option
Roger Pau Monne [Fri, 22 Sep 2017 15:25:07 +0000 (16:25 +0100)]
xl: introduce a firmware option

The new firmware option aims to provide a coherent way to set the
firmware for the different kind of guests Xen supports.

For PV guests the available firmwares are pvgrub{32|64}, and for HVM
the following are supported: bios, uefi, seabios, rombios and ovmf.
Note that uefi maps to ovmf, and bios maps to the default firmware for
each device model.

The xl.cfg man page is updated to document the new feature.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoxl: introduce a domain type option
Roger Pau Monne [Fri, 22 Sep 2017 15:25:06 +0000 (16:25 +0100)]
xl: introduce a domain type option

Introduce a new type option to xl configuration files in order to
specify the domain type. This supersedes the current builder option.

The new option is documented in the xl.cfg man page, and the previous
builder option is marked as deprecated.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl/xl: use the new location of domain_build_info fields
Roger Pau Monne [Thu, 28 Sep 2017 11:04:07 +0000 (12:04 +0100)]
libxl/xl: use the new location of domain_build_info fields

This is required because those options will be used by the new PVH
guest type, and thus need to be shared between PV and HVM.

Defines are added in order to signal consumers that the fields are
available.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoxl: parsing code movement
Roger Pau Monne [Thu, 28 Sep 2017 11:04:07 +0000 (12:04 +0100)]
xl: parsing code movement

Code movement in preparation for making the bootloader,
bootloader_args, nested_hvm and timer_mode fields shared between all
guests types. While moving the code, limit the line-length to 80
columns.

No functional change.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: introduce a way to mark fields as deprecated in the idl
Roger Pau Monne [Thu, 28 Sep 2017 11:04:06 +0000 (12:04 +0100)]
libxl: introduce a way to mark fields as deprecated in the idl

The deprecation involves generating a function that copies the
deprecated fields into it's new location if the new location has not
been set.

The fields that are going to be shared between PVH and HVM or between
PVH and PV are moved to the top level of libxl_domain_build_info, and
the old locations are marked as deprecated.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add is_default checkers for string and timer_mode types
Roger Pau Monne [Thu, 28 Sep 2017 11:04:06 +0000 (12:04 +0100)]
libxl: add is_default checkers for string and timer_mode types

Those types are missing a helper to check whether a definition of the
type holds the default value. This will be required by a later patch
that will implement deprecation of fields inside of a libxl type.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agolibxendevicemodel: initialise extent.pad to zero
Wei Liu [Thu, 28 Sep 2017 10:00:00 +0000 (11:00 +0100)]
libxendevicemodel: initialise extent.pad to zero

The pad field needs to be zero as required by the hypervisor.

Instead of setting the pad separately, use C99 initialiser.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
8 years agox86/hvm/dmop: fix EFAULT condition
Wei Liu [Thu, 28 Sep 2017 09:34:55 +0000 (10:34 +0100)]
x86/hvm/dmop: fix EFAULT condition

The copy macro returns false when the copy fails.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agopublic: add some comments to arch-x86/cpuid.h
Juergen Gross [Thu, 28 Sep 2017 10:06:21 +0000 (12:06 +0200)]
public: add some comments to arch-x86/cpuid.h

Leaf 4 of the Xen-specific CPUID leaves isn't mentioned at all in
include/public/arch-x86/cpuid.h, the comments for leaf 5 don't tell
anything about the sub-leaf semantics.

Add comments to clarify the interface.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
8 years agox86: add new Xen cpuid node for max address width info
Juergen Gross [Thu, 28 Sep 2017 10:05:53 +0000 (12:05 +0200)]
x86: add new Xen cpuid node for max address width info

On very large hosts a pv-guest needs to know whether it will have to
handle frame numbers larger than 32 bits in order to select the
appropriate grant interface version.

Add a new Xen specific CPUID node to contain the maximum machine address
width similar to the x86 CPUID node 0x80000008 containing the maximum
physical address width. The maximum frame width needs to take memory
hotplug into account.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
8 years agoarm: move arch specific grant table bits into grant_table.c
Juergen Gross [Thu, 28 Sep 2017 09:09:35 +0000 (11:09 +0200)]
arm: move arch specific grant table bits into grant_table.c

Instead of attaching the ARM specific grant table data to the domain
structure add it to struct grant_table. Add the needed arch functions
to the asm-*/grant_table.h includes.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien.grall@arm.com>
8 years agognttab: delay allocation of sub structures
Juergen Gross [Thu, 28 Sep 2017 09:09:03 +0000 (11:09 +0200)]
gnttab: delay allocation of sub structures

Delay the allocation of the grant table sub structures in order to
allow modifying parameters needed for sizing of these structures at a
per domain basis. Allocate the structures and the table frames only
from grant_table_init().

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
8 years agolibxl: add libxl support for setting grant table resource limits
Juergen Gross [Thu, 28 Sep 2017 09:08:40 +0000 (11:08 +0200)]
libxl: add libxl support for setting grant table resource limits

Add new domain config items for setting the limits for the maximum
numbers of grant table frames and maptrack frames of a domain.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoxl: add global grant limit config items
Juergen Gross [Thu, 28 Sep 2017 09:08:22 +0000 (11:08 +0200)]
xl: add global grant limit config items

Add xl.conf config items for default values of grant limits:

max_grant_frames will set the default for the maximum number of grant
frames for a domain which will take effect if the domain's config file
doesn't specify a value. If max_grant_frames isn't set in xl.conf it
will default to 32 for hosts with all memory below 16TB and to 64 for
hosts with memory above 16TB.

max_maptrack_frames will set the default for the maximum number of
maptrack frames for a domain. If max_maptrack_frames isn't set in
xl.conf it will default to 0, as normally only backend domains need
maptrack frames.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agolibxl: add max possible mfn to libxl_physinfo
Juergen Gross [Thu, 28 Sep 2017 09:07:24 +0000 (11:07 +0200)]
libxl: add max possible mfn to libxl_physinfo

Add the maximum possible mfn of the host to the libxl_physinfo
data structure.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agotools: set grant limits for xenstore stubdom
Juergen Gross [Thu, 28 Sep 2017 09:06:57 +0000 (11:06 +0200)]
tools: set grant limits for xenstore stubdom

When creating a Xenstore stubdom set the grant limits: the stubdom
will need to setup a very limited amount of grants only, so 4 grant
frames are enough. For being able to support up to 32768 domains it
will need 128 maptrack frames (1 mapping per domain, 256 maptrack
entries per maptrack frame).

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agolibxc: add libxc support for setting grant table resource limits
Juergen Gross [Thu, 28 Sep 2017 09:06:43 +0000 (11:06 +0200)]
libxc: add libxc support for setting grant table resource limits

Add a new libxc function xc_domain_set_gnttbl_limits() setting the
limits for the maximum numbers of grant table frames and maptrack
frames of a domain.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agoadd function for obtaining highest possible memory address
Juergen Gross [Thu, 28 Sep 2017 09:05:37 +0000 (11:05 +0200)]
add function for obtaining highest possible memory address

Add a function for obtaining the highest possible physical memory
address of the system. This value is influenced by:

- hypervisor configuration (CONFIG_BIGMEM)
- processor capability (max. addressable physical memory)
- memory map at boot time
- memory hotplug capability

Add this value to xen_sysctl_physinfo in order to enable dom0 to do a
proper sizing of grant frame limits of guests.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien.grall@arm.com>
8 years agox86emul: properly refuse LOCK on most 0FC7 insns
Jan Beulich [Thu, 28 Sep 2017 09:04:20 +0000 (11:04 +0200)]
x86emul: properly refuse LOCK on most 0FC7 insns

When adding support for RDRAND/RDSEED/RDPID I didn't remember to also
update this special early check. Make it (hopefully) future-proof by
also refusing VEX-encodings.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agopython/libxc: extend the call to get/set cap for credit2
Wei Liu [Wed, 27 Sep 2017 11:46:22 +0000 (12:46 +0100)]
python/libxc: extend the call to get/set cap for credit2

Commit 68817024 ("xen: credit2: allow to set and get utilization cap")
added a new parameter. Implement it for the python binding as well.

Coverity-ID: 1418532

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
8 years agoxen/credit2: add missing unlock
Wei Liu [Wed, 27 Sep 2017 11:46:21 +0000 (12:46 +0100)]
xen/credit2: add missing unlock

Coverity-ID: 1418531

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
8 years agoMerge remote-tracking branch 'origin/staging' into staging
Wei Liu [Tue, 26 Sep 2017 10:26:07 +0000 (11:26 +0100)]
Merge remote-tracking branch 'origin/staging' into staging

8 years agoIntroduce migration precopy policy
Jennifer Herbert [Mon, 25 Sep 2017 18:55:34 +0000 (19:55 +0100)]
Introduce migration precopy policy

This Patch allows a migration precopy policy to be specified.

The precopy phase of the xc_domain_save() live migration algorithm has
historically been implemented to run until either a) (almost) no pages
are dirty or b) some fixed, hard-coded maximum number of precopy
iterations has been exceeded.  This policy and its implementation are
less than ideal for a few reasons:
- the logic of the policy is intertwined with the control flow of the
  mechanism of the precopy stage
- it can't take into account facts external to the immediate
  migration context, such external state transfer state, interactive
  user input, or the passage of wall-clock time.
- it does not permit the user to change their mind, over time, about
  what to do at the end of the precopy (they get an unconditional
  transition into the stop-and-copy phase of the migration)

To permit callers to implement arbitrary higher-level policies governing
when the live migration precopy phase should end, and what should be
done next:
- add a precopy_policy() callback to the xc_domain_save() user-supplied
  callbacks
- during the precopy phase of live migrations, consult this policy after
  each batch of pages transmitted and take the dictated action, which
  may be to a) abort the migration entirely, b) continue with the
  precopy, or c) proceed to the stop-and-copy phase.
- provide an implementation of the old policy, used when
  precopy_policy callback  is not provided.

Signed-off-by: Jennifer Herbert <Jennifer.Herbert@citrix.com>
Signed-off-by: Joshua Otto <jtotto@uwaterloo.ca>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoTidy libxc xc_domain_save
Jennifer Herbert [Mon, 25 Sep 2017 18:55:33 +0000 (19:55 +0100)]
Tidy libxc xc_domain_save

Tidy up libxc's xc_domain_save, removing unused paramaters
max_iters and max_factor, making matching changes to libxl.

Signed-off-by: Joshua Otto <jtotto@uwaterloo.ca>
Signed-off-by: Jennifer Herbert <Jennifer.Herbert@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoConfig.mk: update OVMF changeset
Anthony PERARD [Tue, 26 Sep 2017 09:52:10 +0000 (10:52 +0100)]
Config.mk: update OVMF changeset

Update to allow to build OVMF with GCC 7.2.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agolibxl/xl: allow to get and set cap on Credit2.
Dario Faggioli [Tue, 26 Sep 2017 09:48:47 +0000 (10:48 +0100)]
libxl/xl: allow to get and set cap on Credit2.

Note that a cap is considered valid only if
it is within the [1, nr_vcpus]% interval.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
8 years agoxen: credit2: improve distribution of budget (for domains with caps)
Dario Faggioli [Tue, 26 Sep 2017 09:48:47 +0000 (10:48 +0100)]
xen: credit2: improve distribution of budget (for domains with caps)

Instead of letting the vCPU that for first tries to get
some budget take it all (although temporarily), allow each
vCPU to only get a specific quota of the total budget.

This improves fairness, allows for more parallelism, and
prevents vCPUs from not being able to get any budget (e.g.,
because some other vCPU always comes before and gets it all)
for one or more period, and hence starve (and cause troubles
in guest kernels, such as livelocks, triggering of whatchdogs,
etc.).

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@eu.citrix.com>
8 years agoxen: credit2: allow to set and get utilization cap
Dario Faggioli [Tue, 26 Sep 2017 09:48:46 +0000 (10:48 +0100)]
xen: credit2: allow to set and get utilization cap

As cap is already present in Credit1, as a parameter, all
the wiring is there already for it to be percolate down
to csched2_dom_cntl() too.

In this commit, we actually deal with it, and implement
setting, changing or disabling the cap of a domain.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
8 years agox86/pv: Fix assertion failure in pv_emulate_privileged_op()
Andrew Cooper [Mon, 25 Sep 2017 17:19:01 +0000 (18:19 +0100)]
x86/pv: Fix assertion failure in pv_emulate_privileged_op()

The ABI of {read,write}_msr() requires them to use x86_emul_hw_exception() if
they report an exception with the emulator core.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
8 years agox86/levelling: Avoid NULL pointer dereference
Andrew Cooper [Mon, 25 Sep 2017 16:24:46 +0000 (17:24 +0100)]
x86/levelling: Avoid NULL pointer dereference

Coverity points out that next is indeed NULL at times.  Only try to read the
.cpuid_faulting field when we sure that next isn't NULL.

Fixes e7a370733bd "x86: replace arch_vcpu::cpuid_faulting with msr_vcpu_policy"

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
8 years agox86/hvm/ioreq: use bool rather than bool_t
Paul Durrant [Mon, 25 Sep 2017 14:40:39 +0000 (16:40 +0200)]
x86/hvm/ioreq: use bool rather than bool_t

This patch changes use of bool_t to bool in the ioreq server code. It also
fixes an incorrect indentation in a continuation line.

This patch is purely cosmetic. No semantic or functional change.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
8 years agox86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfn
Paul Durrant [Mon, 25 Sep 2017 14:40:03 +0000 (16:40 +0200)]
x86/hvm/ioreq: rename .*pfn and .*gmfn to .*gfn

Since ioreq servers are only relevant to HVM guests and all the names in
question unequivocally refer to guest frame numbers, name them all .*gfn
to avoid any confusion.

This patch is purely cosmetic. No semantic or functional change.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
8 years agox86emul/test: generate non-pie executable for 64bit builds
Wei Liu [Mon, 25 Sep 2017 10:46:36 +0000 (11:46 +0100)]
x86emul/test: generate non-pie executable for 64bit builds

PIE may (and commonly will) result in the binary being loaded above
the 4Gb boundary, which can't work with at least the VZEROUPPER compat
mode test.

Add -fno-PIE and -no-pie when appropriate so that gcc won't generate a
PIE executable.

Reported-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
8 years agopython: Add binding for non-blocking xs_check_watch()
Euan Harris [Fri, 22 Sep 2017 16:21:14 +0000 (17:21 +0100)]
python: Add binding for non-blocking xs_check_watch()

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

Signed-off-by: Euan Harris <euan.harris@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
8 years agopython: Extract registered watch search logic from xspy_read_watch()
Euan Harris [Fri, 22 Sep 2017 16:21:13 +0000 (17:21 +0100)]
python: Extract registered watch search logic from xspy_read_watch()

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

Signed-off-by: Euan Harris <euan.harris@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
8 years agopython: Add binding for xs_fileno()
Euan Harris [Fri, 22 Sep 2017 16:21:12 +0000 (17:21 +0100)]
python: Add binding for xs_fileno()

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

Signed-off-by: Euan Harris <euan.harris@citrix.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>