All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel List <xen-devel@lists.xen.org>,
	David Vrabel <david.vrabel@citrix.com>,
	Konrad Wilk <konrad.wilk@oracle.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>
Subject: [RFC] Linux save_fl PVOP for Xen
Date: Thu, 16 Apr 2015 19:40:28 +0100	[thread overview]
Message-ID: <5530021C.4070905@citrix.com> (raw)

Having recently got some Broadwell hardware, our automatic test system
discovered that 32bit PV guests would reliably blow up while attempting
to boot.

It turns out that the save_fl PVOP is at fault.  The comment is false,
as setup_smap() uses it to check that the Alignment Check flag is clear.

As the Xen PVOP leaves everything other than %ah worth of eflags
uninitialised, the BUG_ON(eflags & X86_EFLAGS_AC) in setup_smap() is
unconditional undefined behaviour on all versions of Linux since SMAP
support was introduced.

I had developed a patch (see below) and was writing up the commit
message, but it would appear that this PVOP is also used by PVHVM
domains, which invalidates an assumption underlying the fix (insofar
that 'pushf' would unconditionally have IF set).

There are a few options available, but I would like to gather opinions,
as none of them are fantastic.

1) Extend the patch to work for PVHVM as well.  This is problem as it
will make a long hotpath even longer.

2) Change setup_smap() to use something like native_safe_fl().  Unlikely
to get traction upstream, and fragile to similar changes in the future.

3) Change PVHVM to use the native save_fl().  (I don't see why it
doesn't now), but this is a much more invasive change.

Suggestions/alternatives welcome.

~Andrew

diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
index a1207cb..fd4de44 100644
--- a/arch/x86/xen/irq.c
+++ b/arch/x86/xen/irq.c
@@ -26,18 +26,14 @@ void xen_force_evtchn_callback(void)
 asmlinkage __visible unsigned long xen_save_fl(void)
 {
        struct vcpu_info *vcpu;
-       unsigned long flags;
+       unsigned long flags = native_save_fl();
 
        vcpu = this_cpu_read(xen_vcpu);
 
-       /* flag has opposite sense of mask */
-       flags = !vcpu->evtchn_upcall_mask;
+       if (vcpu->evtchn_upcall_mask)
+               flags &= ~X86_EFLAGS_IF;
 
-       /* convert to IF type flag
-          -0 -> 0x00000000
-          -1 -> 0xffffffff
-       */
-       return (-flags) & X86_EFLAGS_IF;
+       return flags;
 }
 PV_CALLEE_SAVE_REGS_THUNK(xen_save_fl);
 
diff --git a/arch/x86/xen/xen-asm.S b/arch/x86/xen/xen-asm.S
index 3e45aa0..ba435ff 100644
--- a/arch/x86/xen/xen-asm.S
+++ b/arch/x86/xen/xen-asm.S
@@ -65,9 +65,18 @@ ENDPATCH(xen_irq_disable_direct)
  * x86 use opposite senses (mask vs enable).
  */
 ENTRY(xen_save_fl_direct)
-       testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
-       setz %ah
-       addb %ah, %ah
+       pushf
+       testb   $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
+       setnz   %al
+       shl     $1, %al
+       not     %al
+#ifdef CONFIG_X86_64
+       andb    %al, 1(%rsp)
+       pop     %rax
+#else
+       andb    %al, 1(%esp)
+       pop     %eax
+#endif
 ENDPATCH(xen_save_fl_direct)
        ret
        ENDPROC(xen_save_fl_direct)

             reply	other threads:[~2015-04-16 18:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-16 18:40 Andrew Cooper [this message]
2015-04-17 10:26 ` [RFC] Linux save_fl PVOP for Xen David Vrabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5530021C.4070905@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.