Fix for the SLS mitigation, which makes a "SETcc/RET" pair grow to

"SETcc/RET/INT3".  This doesn't fit anymore in 4 bytes, so the
 alignment has to change to 8.
 -----BEGIN PGP SIGNATURE-----
 
 iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmI3MxgUHHBib256aW5p
 QHJlZGhhdC5jb20ACgkQv/vSX3jHroN4Nwf/YEibPDhjE0gL8TBu4QC0c8zvDbP4
 yHRkN69NUWdS9VA9RXHysJ57tzBnCKUto1jFOxp/7OeLDLpegj29KkPUynQ5AdIN
 ts4MarjQalKkr7XpGFoTKv/3CK2xdvcEfO32b/u634jUTaQR26b90rRIKrpxCzns
 GNz+IpCNLLggNJSJD5k6JENjipPQj4Il3+AfSh++Df/3TNRJNQxWhus8a0cYgxwt
 pQpoAwBv5omE6sBFsLy3ksGsAAEz5w8cXvxEp8C5xEU6Rbd45xsiQiJfy59EwvEC
 FqxVQseULv0wTSpNyhnCptEoRxP6gdj+NWBnilqa4BIC/iePoPmdM1XYUQ==
 =XG/D
 -----END PGP SIGNATURE-----

Merge tag 'for-linus-5.17' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull kvm fix from Paolo Bonzini:
 "Fix for the SLS mitigation, which makes a 'SETcc/RET' pair grow
  to 'SETcc/RET/INT3'.

  This doesn't fit in 4 bytes any more, so the alignment has to
  change to 8 for this case"

* tag 'for-linus-5.17' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
  kvm/emulate: Fix SETcc emulation function offsets with SLS
This commit is contained in:
Linus Torvalds 2022-03-20 09:46:52 -07:00
commit 7445b2dcd7

View File

@ -429,8 +429,23 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
FOP_END
/* Special case for SETcc - 1 instruction per cc */
/*
* Depending on .config the SETcc functions look like:
*
* SETcc %al [3 bytes]
* RET [1 byte]
* INT3 [1 byte; CONFIG_SLS]
*
* Which gives possible sizes 4 or 5. When rounded up to the
* next power-of-two alignment they become 4 or 8.
*/
#define SETCC_LENGTH (4 + IS_ENABLED(CONFIG_SLS))
#define SETCC_ALIGN (4 << IS_ENABLED(CONFIG_SLS))
static_assert(SETCC_LENGTH <= SETCC_ALIGN);
#define FOP_SETCC(op) \
".align 4 \n\t" \
".align " __stringify(SETCC_ALIGN) " \n\t" \
".type " #op ", @function \n\t" \
#op ": \n\t" \
#op " %al \n\t" \
@ -1047,7 +1062,7 @@ static int em_bsr_c(struct x86_emulate_ctxt *ctxt)
static __always_inline u8 test_cc(unsigned int condition, unsigned long flags)
{
u8 rc;
void (*fop)(void) = (void *)em_setcc + 4 * (condition & 0xf);
void (*fop)(void) = (void *)em_setcc + SETCC_ALIGN * (condition & 0xf);
flags = (flags & EFLAGS_MASK) | X86_EFLAGS_IF;
asm("push %[flags]; popf; " CALL_NOSPEC