Andrew Cooper [Wed, 23 Sep 2020 13:09:03 +0000 (14:09 +0100)]
Adjust XSA-221 PoC based on XSA-343 behaviour change
XSA-343 has made SCHEDOP_poll fail for un-established event channels, which is
reasonable behaviour. Don't bother trying to audit the error codes, and
always run to the end of the loop.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Fri, 5 Jun 2020 19:20:50 +0000 (20:20 +0100)]
Remove ambiguous uses of iret/lret
GAS of at least version 2.34 complains:
Warning: no instruction mnemonic suffix given and no register operands; using default for `lret'
This is legitimate, as without a suffix, there are up to 3 possible encodings
actually meant.
Use l/q suffixes as appropriate, using __ASM_SEL() in cases where we need to
conditionally select between the suffixes. Use the same trick to clean up
some code32/64 statements.
Sadly, this cannot be done for the single ambiguous use of lcall, because
lcallq isn't accepted as a valid mnemonic. Leave the XSA-298 PoC as it is.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
There are a number of ways to do this, but by far the most efficient way is to
have vsnprintf() expand \n's in the output buffer.
This however is non-standard behaviour for vsnprintf(). Rename it to
vsnprintf_internal() and take extra flags, and have vprintk() use the new
LF_TO_CRLF control flag.
Inside vsnprintf_internal(), rearrange the non-format and %c logic to share
the expansion logic, as well as extending the logic to fmt_string().
Extend the selftests to confirm correct behaviour in both modes, for all ways
of being able to pass newline characters into a format operation.
Reported-by: Pawel Wieczorkiewicz <wipawel@amazon.de> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Thu, 4 Jun 2020 17:36:57 +0000 (18:36 +0100)]
Fix assembler type warnings with newer binutils
GAS of at least version 2.34 complains:
hypercall_page.S: Assembler messages:
hypercall_page.S:24: Warning: symbol 'HYPERCALL_set_trap_table' already has its type set
...
hypercall_page.S:71: Warning: symbol 'HYPERCALL_arch_7' already has its type set
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Mon, 27 Apr 2020 13:57:35 +0000 (14:57 +0100)]
xtf-runner: Python3 fix when not specifying --quiet
Andy reports:
Combined test results:
Traceback (most recent call last):
File "./xtf-runner", line 716, in <module>
sys.exit(main())
File "./xtf-runner", line 711, in main
return run_tests(opts)
File "./xtf-runner", line 559, in run_tests
if res == "SUCCESS" and opts.quiet >= 2:
TypeError: '>=' not supported between instances of 'NoneType' and 'int'
Reported-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Currently the xenbus_write() does not handle ring wrapping around
correctly. When ring buffer is almost full and there is not enough
space for next packet (e.g. there is 12 bytes of space left, but the
packet header needs to transmit 16 bytes) the memcpy() goes out of the
ring buffer boundry.
Instead, the part variable should be limited to the space available in
the ring buffer, so the memcpy() can fill up the buffer, update len
variable (to indicate that there is still some data to be copied) and
thereby the xenbus_write() loop can iterate again to finish copying
the remainder of data to the beginning of the ring buffer.
Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Mon, 17 Feb 2020 09:48:26 +0000 (09:48 +0000)]
Fix asm constraints for push/pop instructions
There are several issues with 64bit builds. Correct the types/constraints to
prohibit encoding 32bit registers, and immediates which can't be represented
as a 32bit signed extended number.
Introduce asm_checks() in selftest as a build-time check for constraint corner
cases, to be extended as needed.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Tue, 7 May 2019 10:19:58 +0000 (11:19 +0100)]
Use named asm parameters for _ASM_EXTABLE_HANDLER()
LTO builds need to know that ex_record_fault_{eax,edi} are referenced from
within asm, to avoid the functions being discarded.
Previously, this was done with an "X" parameter listing the function twice,
but this can lead to copy/paste mistakes. Instead, use a named parameter and
the "p" type and "P" modifier, which works compatibly between GCC and Clang.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Thu, 16 May 2019 18:12:33 +0000 (18:12 +0000)]
Simplify the unhandled_exception handling for tests
Tests, being single-purpose by their very nature, don't in practice use the
flexibility to change the unhandled exception hook. Furthermore, updating the
pointer has to be done carefully (i.e. with compiler barriers) because the
compiler doesn't see any connection between the hook and surrounding code
which may fault.
Switch to the using method already used by the syscall infrastructure and use
a single weak do_unhandled_exception() function which may be overridden by
guests wanting to implement their own custom behaviour.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Fri, 10 May 2019 16:22:15 +0000 (16:22 +0000)]
Misc trivial code cleanup
* Use named asm parameters for non-trivial blocks
* "=r" (x) : "r" (x) is more commonly "+r" (x)
* Correct the header guard in x86-gate.h
* Remove brackets from absolute memory addresss
* Use unsigned int rather than unsigned long and forcing back to int with %k
* Drop unused ex_record_fault_eax reference
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Sat, 11 May 2019 18:20:34 +0000 (19:20 +0100)]
libc: Fix strcmp() ABI violations
The C standard specifies that strcmp() interprets the provided strings as
unsigned char, rather than signed. This affects the result when used on
strings with the high bit set.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Jan Beulich [Fri, 11 Jan 2019 09:50:20 +0000 (02:50 -0700)]
nested-vmx: exceptions take priority over VMFail*
The way the instruction invocations are coded, it is compiler version
dependent whether things work: With old gcc, fail_{,in}valid will not
get touched and hence remain at their initial values, while with newer
gcc evaluation of the status flags occurs outside of the asm(), i.e.
also when an exception was received (in which case EFLAGS didn't change
from its value before the faulting instruction).
Since it is more logical anyway to check for a possible exception first,
do so uniformly instead of trying to fiddle with the asm() in some way.
Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Roger Pau Monne [Wed, 2 May 2018 14:22:35 +0000 (15:22 +0100)]
XSA-261 PoC
This requires adding some basic IO APIC and HPET functionality.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Compile fixes, misc cleanup and consistency improvements, and written
documentation.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
These are intended to facilitate 64bit compatiblity mode segments, but are
exposed in 32bit builds as straight aliases of __{KERN,USER}_{CS,DS} for the
benefit of common code.
Fix up one opencoded use in the XSA-196 PoC.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Thu, 22 Mar 2018 11:50:50 +0000 (11:50 +0000)]
Introduce and use __maybe_unused
This allows for the 32bit ifdefary of ex_pf_user to be dropped without
suffering a warning in the 64bit build, while still allowing LTO to drop the
function.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Fri, 2 Mar 2018 14:02:35 +0000 (14:02 +0000)]
Add more helpful GDTE() helpers
All tests and some setup infrastructure need explicitly typed versions of
INIT_GDTE() and INIT_GDTE_SYM(). Introduce GDTE() and GDTE_SYM() to do just
this, and update the impacted users.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Wed, 14 Feb 2018 17:37:09 +0000 (17:37 +0000)]
Support the use of GDTs in PV guests
GDT frames in PV guests need to be page aligned, and like pagetables, mapped
read-only. Move gdt[] into __page_aligned_{data,bss} and leave it empty for
PV guests to begin with.
The PV arch_init_traps() code registers the frame with Xen, and tests wanting
to make use of it need to use hypercall_update_descriptor().
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Wed, 14 Feb 2018 18:24:46 +0000 (18:24 +0000)]
Move more includes into arch/xtf.h to ease writing tests
It is currently very hit and miss whether functionality is included, and some
current inclusions are already unnecessary. Make it easier for tests by
putting all common includes in arch/xtf.h, so tests only have to include xtf.h
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Wed, 14 Feb 2018 15:42:25 +0000 (15:42 +0000)]
32bit: Save and restore %ds and %es when handling exceptions
For tests which play with segments (especially those which reduce %ds.limit),
failing to restore usable segments can result in cascade failures (most
obviously when trying to poke characters into the console ring).
Remove the vm86 special case in handle_exception() and load __KERN_DS into %ds
and %es unconditionally. Forgo the unconditional loading of %fs and %gs as
they are unreferenced in exception context.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Mon, 12 Feb 2018 11:33:42 +0000 (11:33 +0000)]
Introduce and use xenstore_init()
This really should have been introduced along with xenstore_read(), but the
problem only becomes apparent when booting an XTF test as the initial domain.
The presence of xenstore must not be assumed.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Sun, 28 Jan 2018 18:23:27 +0000 (18:23 +0000)]
Cope being booting as the initial domain
When booted as the initial domain (most commonly in PV-shim mode), the console
and xenbus rings aren't configured, as it is the responsibility of the initial
domain to provide xenconsole/xenstored services for other domains.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Fri, 26 Jan 2018 16:39:15 +0000 (16:39 +0000)]
Introduce support for booting with the PVH ABI
All XTF HVM guests are compatible with the PVH ABI. Populate the PHYS32_ENTRY
elfnote and stash the pvh_start_info pointer provided by the domain builder.
Skip the Qemu console setup when booting PVH.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Andrew Cooper [Wed, 31 Jan 2018 10:57:58 +0000 (10:57 +0000)]
Rename start_info to pv_start_info
In preparation to introduce pvh_start_info. Rename the type to match, fix up
the accidental double extern, and move the variable into pv/traps.c to match
with its declaration in traps.h.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>