]> xenbits.xensource.com Git - xtf.git/log
xtf.git
4 years agobuild: Use LD
Andrew Cooper [Mon, 19 Apr 2021 15:06:38 +0000 (16:06 +0100)]
build: Use LD

This is going to matter for proper LLVM support, where we want to default to
ld.lld

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agobuild: Drop lto
Andrew Cooper [Mon, 19 Apr 2021 15:05:12 +0000 (16:05 +0100)]
build: Drop lto

It's experimental, fairly broken, and getting in the way of the build system
overhaul to support non-x86 architectures.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoCodeQL: Two trivial fixes
Andrew Cooper [Mon, 19 Apr 2021 14:16:07 +0000 (15:16 +0100)]
CodeQL: Two trivial fixes

 * xsa-173: Short global name
 * vsnprintf.c: Suspicious 'sizeof' use

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoCI: Add Github Action for CodeQL analysis
Andrew Cooper [Fri, 16 Apr 2021 23:43:16 +0000 (00:43 +0100)]
CI: Add Github Action for CodeQL analysis

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoCI: Add Github Actions for running scan-build
Andrew Cooper [Thu, 15 Apr 2021 01:23:08 +0000 (02:23 +0100)]
CI: Add Github Actions for running scan-build

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agovarious: Fix scan-build deadcode.DeadStores issues
Andrew Cooper [Thu, 15 Apr 2021 01:03:00 +0000 (02:03 +0100)]
various: Fix scan-build deadcode.DeadStores issues

Scan-build complains:

  main.c:164:15: warning: Although the value stored to 'cr4' is used in the enclosing expression, the value is never actually read from 'cr4' [deadcode.DeadStores]
      write_cr4(cr4 &= ~X86_CR4_DE);
                ^      ~~~~~~~~~~~

Rework all impacted logic avoid dead stores of this form.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agognttab: Fix scan-build core.CallAndMessage issues
Andrew Cooper [Thu, 15 Apr 2021 00:36:20 +0000 (01:36 +0100)]
gnttab: Fix scan-build core.CallAndMessage issues

scan-build complains:

  arch/x86/grant_table.c:41:17: warning: 1st function call argument is an uninitialized value [core.CallAndMessage]
                  pte_from_gfn(gnttab_gfns[i], PF_SYM(AD, RW, P)), UVMF_INVLPG);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

because it can't observe that GNTTABOP_setup_table fills the variable on its
success path.

Initialising the array (which is currently one entry) isn't trivial because
the array is variadic.  Drop the nr_frames variable and use the sizeof()
expression directly, to create compile-time constant size.

A similar issue is reported against xsa-255, but this is trivial to resolve.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoCI: Add Github Actions for building
Andrew Cooper [Wed, 7 Apr 2021 22:56:04 +0000 (23:56 +0100)]
CI: Add Github Actions for building

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoDrop dependency on gcc-multilib
Andrew Cooper [Thu, 15 Apr 2021 15:55:09 +0000 (16:55 +0100)]
Drop dependency on gcc-multilib

inttypes.h in particular isn't a freestanding header, and certain distros have
problems providing suitable freestanding headers anyway.  This also gets more
complicated as we start supporting other architectures.

Take the plunge and switch to entirely local headers only.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoFix LGTM static analysis issues
Andrew Cooper [Thu, 15 Apr 2021 17:05:05 +0000 (18:05 +0100)]
Fix LGTM static analysis issues

 * xtf-runner: Class TestInstance implements __hash__ but does not define __eq__.
 * mkinfo.py: Import of 'os' is not used.

LGTM also complains about gdt/idt/tss being global symbols with too-short
names.  As they're the most appropriate architectural names, insert
suppression comments.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoxtf: Perform misc code cleanup
Michal Orzel [Wed, 10 Mar 2021 10:43:32 +0000 (11:43 +0100)]
xtf: Perform misc code cleanup

 * Define macro ALIGN to set alignment.  Header file asm_macros.h should not
   contain architecture specific code.  Replace hardcoded alignment value with
   a call to macro ALIGN.

 * Move declaration of shared_info into xtf/traps.h.  Declaration of
   shared_info structure should be placed in xtf/traps.h as it is a common
   declaration for all the possible architectures.

 * Do not protect including <arch/barrier.h>.  We should always include
   <arch/barrier.h> and rely on the compiler to throw an error. This would
   avoid increasing #if protection each time we would add a new architecture.

Signed-off-by: Michal Orzel <michal.orzel@arm.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoAdd HYPERCALL5 and hypercall_argo_op()
Christopher Clark [Thu, 28 Jan 2021 06:26:35 +0000 (22:26 -0800)]
Add HYPERCALL5 and hypercall_argo_op()

[Split out from argo patch]

Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
[Also implement HYPERCALL0 as it is frequently opencoded]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agohypercall: Refine fix for Clang code generation bug
Andrew Cooper [Wed, 11 Nov 2020 12:57:45 +0000 (12:57 +0000)]
hypercall: Refine fix for Clang code generation bug

It was incorrect to switch "=a" to "+a" and set up hcall, as the hypercall
number is encoded in the offset within hypercall_page.  Switch res back to
just an output.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agohypercall: Work around Clang code generation bug
Andrew Cooper [Fri, 6 Nov 2020 18:53:39 +0000 (18:53 +0000)]
hypercall: Work around Clang code generation bug

_hypercall64_4() is mis-compiled by some versions of Clang (5 is ok, 9 and
later not), in a way which breaks the XSA-286 PoC.

Clang loses the association between argument 4 being in %r10 between the input
"a" (_a4) and the output "=&r" (__ign4), so while the input is handled
correctly, the clobber on the output is missed.

In the XSA-286, PoC, this causes clang to hoist the setting of DOMID_SELF out
of the loop, and the test subsequently to malfunction on debug versions of Xen
which intentionally clobber the hypercall parameters.

Rewrite the hypercall macros to a single "+r" parameter form, rather than dual
input/output form, which causes all tested versions of Clang to set up %r10 on
each loop iteration.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoXSA-286 PoC
Andrew Cooper [Mon, 19 Oct 2020 13:02:59 +0000 (14:02 +0100)]
XSA-286 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agohypercall: Reposition hypercall_xen_version()
Andrew Cooper [Mon, 19 Oct 2020 17:34:44 +0000 (18:34 +0100)]
hypercall: Reposition hypercall_xen_version()

It has gotten out of order.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoXSA-333 PoC
Andrew Cooper [Wed, 9 Sep 2020 14:11:17 +0000 (15:11 +0100)]
XSA-333 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agobuild: Allow tests to specify the number of vcpus required
Andrew Cooper [Thu, 1 Oct 2020 09:42:31 +0000 (10:42 +0100)]
build: Allow tests to specify the number of vcpus required

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agobarrier: Use LOCK ADD rather than MFENCE
Andrew Cooper [Mon, 5 Oct 2020 17:47:09 +0000 (18:47 +0100)]
barrier: Use LOCK ADD rather than MFENCE

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoXSA-339 PoC
Andrew Cooper [Mon, 14 Sep 2020 15:02:58 +0000 (16:02 +0100)]
XSA-339 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoAdjust XSA-221 PoC based on XSA-343 behaviour change
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>
4 years agoUpdate copyright years
Andrew Cooper [Tue, 11 Aug 2020 19:36:30 +0000 (20:36 +0100)]
Update copyright years

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoXSA-317 PoC
Julien Grall [Tue, 7 Jul 2020 10:54:49 +0000 (11:54 +0100)]
XSA-317 PoC

Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoxenbus: Don't wait if the response ring is full
Julien Grall [Thu, 9 Jul 2020 18:46:47 +0000 (19:46 +0100)]
xenbus: Don't wait if the response ring is full

XenStore response can be bigger than the response ring. In this case,
it is possible to have the ring full (e.g cons = 19 and prod = 1043).

However, XTF will consider that there is no data and therefore wait for
more input. This will result to block indefinitely as the ring is full.

This can be solved by avoiding to mask the difference between prod and
cons.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
4 years agopv: Add sysenter handling for guests
Andrew Cooper [Mon, 29 Jun 2020 13:17:46 +0000 (14:17 +0100)]
pv: Add sysenter handling for guests

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agopv: Register callbacks in a loop
Andrew Cooper [Mon, 29 Jun 2020 13:15:22 +0000 (14:15 +0100)]
pv: Register callbacks in a loop

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agolibc: add strncmp() function
Pawel Wieczorkiewicz [Thu, 23 Apr 2020 10:19:18 +0000 (10:19 +0000)]
libc: add strncmp() function

Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
[Fix style]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoRemove ambiguous uses of iret/lret
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>
4 years agovsnprintf: Expand \n to \r\n for console output
Andrew Cooper [Thu, 4 Jun 2020 12:54:54 +0000 (13:54 +0100)]
vsnprintf: Expand \n to \r\n for console output

xenconsoled doesn't automatically convert \n into \r\n, which causes test
output to appear like this in some terminals:

  [root@host ~]# xl create -c tests/selftest/test-pv64-selftest.cfg
  Parsing config from tests/selftest/test-pv64-selftest.cfg
  --- Xen Test Framework ---
                            Environment: PV 64bit (Long mode 4 levels)
                                                                      XTF Selftests

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>
4 years agoFix assembler type warnings with newer binutils
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>
4 years agoxtf-runner: Python3 fix when not specifying --quiet
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>
4 years agoXSA-316 PoC
Igor Druzhinin [Tue, 7 Apr 2020 20:18:56 +0000 (21:18 +0100)]
XSA-316 PoC

Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
4 years agoxenbus: fix xenbus_write() ring overflow
Pawel Wieczorkiewicz [Wed, 3 Jun 2020 08:21:41 +0000 (08:21 +0000)]
xenbus: fix xenbus_write() ring overflow

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>
5 years agodocs: Fix formatting in the all-docs index
Andrew Cooper [Mon, 17 Feb 2020 18:29:36 +0000 (18:29 +0000)]
docs: Fix formatting in the all-docs index

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoFix asm constraints for push/pop instructions
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>
5 years agoAvoid "q" constraint unless necessary
Andrew Cooper [Sun, 16 Feb 2020 23:23:56 +0000 (23:23 +0000)]
Avoid "q" constraint unless necessary

Several tests are better off using "r", which permits the use of
%esi/%edi/%ebp/%esp in 32bit builds.

For the XSA-170 test, jmp indirect doesn't have an immediate encoding, but
will happily accept a memory encoding.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoSimplify setting the overflow flag
Andrew Cooper [Mon, 17 Feb 2020 13:43:59 +0000 (13:43 +0000)]
Simplify setting the overflow flag

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoDoxygen: Fix ref linkage for xsa-consoleio-write
Andrew Cooper [Mon, 16 Dec 2019 15:20:38 +0000 (15:20 +0000)]
Doxygen: Fix ref linkage for xsa-consoleio-write

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoXSA-308 PoC
Andrew Cooper [Mon, 4 Nov 2019 18:18:14 +0000 (18:18 +0000)]
XSA-308 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoxtf-runner: More Python 2.6 compatibility fixes
Andrew Cooper [Thu, 5 Dec 2019 00:01:11 +0000 (00:01 +0000)]
xtf-runner: More Python 2.6 compatibility fixes

The {} shorthand for .format() is only valid in Python 2.7

Reported-by: Glenn Enright <glenn@rimuhosting.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoMisc extra instruction wrappers
Andrew Cooper [Wed, 4 Dec 2019 18:19:25 +0000 (18:19 +0000)]
Misc extra instruction wrappers

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoFix LTO build in xsa-consoleio-write
Andrew Cooper [Wed, 4 Dec 2019 13:02:01 +0000 (13:02 +0000)]
Fix LTO build in xsa-consoleio-write

The compiler can't spot the assembly reference to zero_page[]

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoRevert another part of ""Revert "Fix the use of ./xtf-runner on Python 2.4""
Andrew Cooper [Wed, 4 Dec 2019 12:17:59 +0000 (12:17 +0000)]
Revert another part of ""Revert "Fix the use of ./xtf-runner on Python 2.4""

subprocess.check_output() is Python 2.7 only.

Reported-by: Glenn Enright <glenn@rimuhosting.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoxtf-runner: Support multiple quiet settings
Andrew Cooper [Fri, 29 Nov 2019 15:29:45 +0000 (15:29 +0000)]
xtf-runner: Support multiple quiet settings

Particularly useful for './xtf-runner -aqq' for "run all tests" and trying to
spot problems amongst the output.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoCONSOLEIO_write stack overflow PoC
Andrew Cooper [Fri, 29 Nov 2019 13:37:56 +0000 (13:37 +0000)]
CONSOLEIO_write stack overflow PoC

Classify it as an XSA test (which arguably ought to be named 'security'),
despite no XSA being issued.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
5 years agoXSA-298 PoC
Andrew Cooper [Tue, 7 May 2019 10:19:58 +0000 (11:19 +0100)]
XSA-298 PoC

5 years agoXSA-296 PoC
Andrew Cooper [Thu, 11 Apr 2019 15:50:23 +0000 (16:50 +0100)]
XSA-296 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoidt: Constify the xtf_idte parameter to xtf_set_idte()
Andrew Cooper [Fri, 15 Nov 2019 13:23:03 +0000 (13:23 +0000)]
idt: Constify the xtf_idte parameter to xtf_set_idte()

It is only ever read.  Take the opportunity to adjust all callers to construct
their struct xtf_idte in .rodata.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agodocs: Use https:// links in preference to http://
Andrew Cooper [Thu, 28 Nov 2019 20:52:36 +0000 (20:52 +0000)]
docs: Use https:// links in preference to http://

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoDrop custom stack handling for nested tasks
Andrew Cooper [Mon, 25 Nov 2019 13:31:54 +0000 (13:31 +0000)]
Drop custom stack handling for nested tasks

I don't recall how I came to this conclusion, but its not correct.  IRET with
NT set doesn't inspect the stack at all.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agolink: Introduce _start[] to match _end[]
Andrew Cooper [Mon, 4 Nov 2019 13:03:39 +0000 (13:03 +0000)]
link: Introduce _start[] to match _end[]

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoRevert part of "Revert "Fix the use of ./xtf-runner on Python 2.4""
Andrew Cooper [Fri, 1 Nov 2019 16:42:38 +0000 (16:42 +0000)]
Revert part of "Revert "Fix the use of ./xtf-runner on Python 2.4""

{} for set notation isn't Py 2.6 compatible.

Reported-by: Glenn Enright <glenn@rimuhosting.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoxtf-runner: Python 3 compatibility
Andrew Cooper [Fri, 25 Oct 2019 15:11:06 +0000 (16:11 +0100)]
xtf-runner: Python 3 compatibility

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoRevert "Fix the use of ./xtf-runner on Python 2.4"
Andrew Cooper [Fri, 25 Oct 2019 18:00:22 +0000 (19:00 +0100)]
Revert "Fix the use of ./xtf-runner on Python 2.4"

In order to add Python 3 compatibility, we must set a baseline of Python 2.6.
Drop the 2.4 compatibility hacks.

This logically reverts 1313f37eef92d427bbd77838c3e1b95be323e607

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoUse named asm parameters for _ASM_EXTABLE_HANDLER()
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>
5 years agoXSA-173: Update test to newer idioms
Andrew Cooper [Fri, 10 May 2019 22:26:06 +0000 (23:26 +0100)]
XSA-173: Update test to newer idioms

 * Use TEST-EXTRA-CFG to request shadow by default
 * Use exinfo_t to avoid opencoding the check for Rsvd

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoTSX: Fix the encoding of XEND
Andrew Cooper [Fri, 9 Aug 2019 17:46:02 +0000 (18:46 +0100)]
TSX: Fix the encoding of XEND

0xd6 is XTEST, not XEND.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoIntroduce evntchn handling support for PV guests
Andrew Cooper [Wed, 12 Jun 2019 09:59:48 +0000 (10:59 +0100)]
Introduce evntchn handling support for PV guests

Fill in the event callback, and use a weak do_evtchn() hook which can be
implemented by guests.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoSimplify the unhandled_exception handling for tests
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>
5 years agoMisc trivial code cleanup
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>
5 years agoIntroduce pack_{tss,ldt}_desc() to work around latent 64bit issues
Andrew Cooper [Mon, 13 May 2019 10:26:25 +0000 (10:26 +0000)]
Introduce pack_{tss,ldt}_desc() to work around latent 64bit issues

LDT and TSS descriptors use two slots in 64bit.  While no published tests are
affected, some in-development ones are.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoIntroduce pack_intr_gate() to mirror pack_task_gate()
Andrew Cooper [Mon, 13 May 2019 10:26:24 +0000 (10:26 +0000)]
Introduce pack_intr_gate() to mirror pack_task_gate()

In HVM's arch_init_traps(), fold setup_gate() and setup_doublefault(), as they
are only token wrappers at this point.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agoLTO: Specify the use of gold with a compiler option rather than an explicit path
Andrew Cooper [Sat, 11 May 2019 18:21:02 +0000 (19:21 +0100)]
LTO: Specify the use of gold with a compiler option rather than an explicit path

This allows the compiler to pick up gold from the path, rather than forcing
the use of the system gold all the time.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
5 years agolibc: Fix strcmp() ABI violations
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>
6 years agoPV FSGSBASE behaviour
Andrew Cooper [Tue, 30 Apr 2019 13:29:24 +0000 (14:29 +0100)]
PV FSGSBASE behaviour

Functional test, which also doubles for XSA-293

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agoXSA-279 PoC
Andrew Cooper [Wed, 10 Oct 2018 10:42:00 +0000 (10:42 +0000)]
XSA-279 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agoXSA-277 PoC
Andrew Cooper [Tue, 9 Oct 2018 17:59:29 +0000 (18:59 +0100)]
XSA-277 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agonested-vmx: exceptions take priority over VMFail*
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>
6 years agoXSA-278 PoC
Andrew Cooper [Wed, 10 Oct 2018 10:09:12 +0000 (10:09 +0000)]
XSA-278 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agodebug-regs: Check the vcpu's initial register state
Andrew Cooper [Fri, 25 May 2018 10:04:32 +0000 (11:04 +0100)]
debug-regs: Check the vcpu's initial register state

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agodebug-regs: Detect the PV IO shadow handling bugs
Andrew Cooper [Fri, 1 Jun 2018 13:11:35 +0000 (14:11 +0100)]
debug-regs: Detect the PV IO shadow handling bugs

Also fix up some poor choice of constant names.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agoXSA-269 PoC
Andrew Cooper [Mon, 30 Jul 2018 17:32:06 +0000 (18:32 +0100)]
XSA-269 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agoXSA-265 PoC
Andrew Cooper [Mon, 25 Jun 2018 15:53:10 +0000 (16:53 +0100)]
XSA-265 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agoTSX intrinsics
Andrew Cooper [Sun, 29 Apr 2018 14:55:31 +0000 (15:55 +0100)]
TSX intrinsics

These are implemented to the GCC API, but are compatible with older
toolchains.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agoXSA-260: Work around toolchain problems with older GCC
Andrew Cooper [Tue, 5 Jun 2018 11:13:24 +0000 (12:13 +0100)]
XSA-260: Work around toolchain problems with older GCC

GCC 4.4.7 of RHEL/CentOS 6 vintage can't cope with an ebp/rbp register clobber
when compiling with frame pointers enabled.  Switch to ebx/rbx instead.

Reported-by: Glenn Enright <glenn@rimuhosting.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Tested-by: Glenn Enright <glenn@rimuhosting.com>
6 years agoXSA-261 PoC
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>
6 years agoXSA-260 PoC
Andrew Cooper [Thu, 22 Mar 2018 11:50:50 +0000 (11:50 +0000)]
XSA-260 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agox86/msr: Clean up MSR field declarations
Andrew Cooper [Thu, 24 May 2018 13:36:22 +0000 (14:36 +0100)]
x86/msr: Clean up MSR field declarations

 * Consistently use ULL for the benefit of 32bit builds
 * Drop leading MSR_ prefixes from bit names
 * Drop unnecessary bit-position defines

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
6 years agox86: mov to/from sreg can be encoded with a memory operand
Andrew Cooper [Thu, 10 May 2018 13:18:22 +0000 (14:18 +0100)]
x86: mov to/from sreg can be encoded with a memory operand

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoXSA-259 PoC
Andrew Cooper [Mon, 12 Mar 2018 13:35:23 +0000 (13:35 +0000)]
XSA-259 PoC

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoProperly bracket EXINFO()'s parameters before operating on them
Andrew Cooper [Wed, 2 May 2018 13:33:45 +0000 (14:33 +0100)]
Properly bracket EXINFO()'s parameters before operating on them

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoRudimentary syscall handling for PV guests
Andrew Cooper [Thu, 22 Mar 2018 11:50:50 +0000 (11:50 +0000)]
Rudimentary syscall handling for PV guests

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce __user_data
Andrew Cooper [Thu, 22 Mar 2018 11:50:50 +0000 (11:50 +0000)]
Introduce __user_data

Fix up the missing __user_text in Doxyfile, and the missing linker assertions
that the user bss boundaries are page aligned.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agox86/io-apic: Fix 64bit MMIO accesses
Andrew Cooper [Fri, 13 Apr 2018 18:37:21 +0000 (19:37 +0100)]
x86/io-apic: Fix 64bit MMIO accesses

While most of the IO-APIC registers are 64 bits wide, the spec states that
they must be accessed with 32bit accesses.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce some basic IO-APIC infrastructure
Andrew Cooper [Fri, 13 Apr 2018 13:41:21 +0000 (13:41 +0000)]
Introduce some basic IO-APIC infrastructure

Replace some opencoded IOAPIC_DEFAULT_BASE constants.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce some basic HPET infrastructure
Roger Pau Monne [Fri, 30 Mar 2018 12:39:42 +0000 (13:39 +0100)]
Introduce some basic HPET infrastructure

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce __{KERN,USER}_{CS,DS}32 selector constants
Andrew Cooper [Mon, 9 Apr 2018 13:06:20 +0000 (14:06 +0100)]
Introduce __{KERN,USER}_{CS,DS}32 selector constants

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>
7 years agoIntroduce and use __user_page_aligned_bss
Andrew Cooper [Thu, 22 Mar 2018 11:50:50 +0000 (11:50 +0000)]
Introduce and use __user_page_aligned_bss

This avoids special casing user_stack[] as data, and allows the
!test_wants_user_mappings remapping logic to become entirely generic.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoUse a linker ASSERT() to check that the mappings are within l1_identmap[]
Andrew Cooper [Thu, 22 Mar 2018 11:50:50 +0000 (11:50 +0000)]
Use a linker ASSERT() to check that the mappings are within l1_identmap[]

This avoids needing the runtime checks in hvm's arch_init_traps()

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce and use __maybe_unused
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>
7 years agoXSA-255 PoC
Jan Beulich [Thu, 15 Feb 2018 17:28:09 +0000 (17:28 +0000)]
XSA-255 PoC

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoFix latent bug in 64bit exec_user_param()
Andrew Cooper [Wed, 4 Apr 2018 20:18:34 +0000 (21:18 +0100)]
Fix latent bug in 64bit exec_user_param()

Use a full %rsp reference rather than %esp.  Only a latent bug as the upper
bits will be clear.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce a basic test for debugging infrastructure
Andrew Cooper [Fri, 23 Mar 2018 15:38:05 +0000 (15:38 +0000)]
Introduce a basic test for debugging infrastructure

To begin with, this just checks that the PV %dr7 latch issue is resolved.
There are many more bugs to fix.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce new debug register definitions and helpers
Andrew Cooper [Fri, 23 Mar 2018 13:38:35 +0000 (13:38 +0000)]
Introduce new debug register definitions and helpers

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoFactor out debug register infrastructure into a new header
Andrew Cooper [Fri, 23 Mar 2018 13:17:05 +0000 (13:17 +0000)]
Factor out debug register infrastructure into a new header

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoIntroduce update_desc() for updates to live descriptor entries
Andrew Cooper [Fri, 2 Mar 2018 14:19:56 +0000 (14:19 +0000)]
Introduce update_desc() for updates to live descriptor entries

GCC 4.4 from CentOS 6 is clever enough to turn the invlpg test's

  gdt[GDTE_AVAIL0] = GDTE_SYM(0, 1, COMMON, DATA, DPL0, B, W);
  write_fs(GDTE_AVAIL0 << 3);

into

  103927:       b8 48 00 00 00                  mov    $0x48,%eax
  10392c:       c7 05 48 f0 10 00 01 00 00 00   movl   $0x1,0x10f048
  103936:       8e e0                           mov    %eax,%fs
  103938:       c7 05 4c f0 10 00 00 93 c0 00   movl   $0xc09300,0x10f04c

which hardware rightfully complains about, as the descriptor isn't valid at
the point that %fs is loaded.

Introduce update_desc() which copes with PV and HVM differences, and enforces
a compiler barrier to prevent reordering of later operations.

Reported-by: Glenn Enright <glenn@rimuhosting.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoAdd more helpful GDTE() helpers
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>
7 years agovmx: Don't create strings[] on the stack of every vmx_insn_err_strerror() call
Andrew Cooper [Fri, 2 Mar 2018 13:19:53 +0000 (13:19 +0000)]
vmx: Don't create strings[] on the stack of every vmx_insn_err_strerror() call

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agox86/apic: Set SPIV.EN in apic_init() so the device is ready for use
Andrew Cooper [Thu, 22 Feb 2018 17:21:34 +0000 (17:21 +0000)]
x86/apic: Set SPIV.EN in apic_init() so the device is ready for use

This is more useful behaviour than forcing all tests which call apic_init() to
set up SPIV themselves to actually receive interrupts.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
7 years agoselftest: test x2apic basic initialisation as well if possible
Andrew Cooper [Thu, 22 Feb 2018 17:21:34 +0000 (17:21 +0000)]
selftest: test x2apic basic initialisation as well if possible

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>