[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] x86: correct asm() constraints when dealing with immediate selector values


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 13 Sep 2021 08:26:21 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=b56+p+h/+f3Lf2jWmYx6VT7RCUyvcBike6T9rfJgClA=; b=gV7ZxZx2OX3WkiLVjZdN/jgueFx5CwYny/V2HcXIkoWwq0+P9ev/JpZqz2mDRh/PTfTvW+02Fb12cQ0LGxJhLPysus44O8emyK8kZiYvAIPfxaTMw0LD6zfA5oYMX3kF/mjl/twUjw7njcCnxOZVFpIU/93Dd+uRdHKAiEpLyV1yGkr1c+BxDKXxDlaWcwvdLlPdBplEpvGGkW5W+eB2djS4yb5MP6DmQPBJGo3GiA9M5mfoFu6D6BYrPEfjZBCAE/fyiOOvnK4r25KRgkreZyY+4JaJ/37ITs6kyn4gTYxXBCN98LzfnqlfoT47ZnBk4VZtYSIoBOtUeDhzdK5c+A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UEYCO+yD7YhSXLCJ/zNBkiNfk7VflGHeAUIp3/20d50loDckfHm57V6xmeEfK+UvltIwE9tsQaZb1dALdJf1PkiB+2YeIdk3RrwnbbSbmjXO2YQmA3CAKQTopog4JHEcIehLJPYdgqGWBIAOlZaefInRRXJArVQXLkeREQgxnV4Q5wE7CIwYVmFzPNSERsnm2waY8i1+y8mqU/zskO+cW4OZJwWoT42KtmSV9awK/ikAmla5xLFwysGiGeqfy6m/lMlGaIdmw+2yaOS0W/lbHTU8qKEh/YiXxzTPtJbxN/ivsIUIJCS4nHfrTKduf7KybkEf1Bq9UzYn2tX7rvssGQ==
  • Authentication-results: citrix.com; dkim=none (message not signed) header.d=none;citrix.com; dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 13 Sep 2021 06:26:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

asm() constraints need to fit both the intended insn(s) which the
respective operands are going to be used with as well as the actual kind
of value specified. "m" (alone) together with a constant, however, leads
to gcc saying

error: memory input <N> is not directly addressable

while clang complains

error: invalid lvalue in asm input for constraint 'm'

And rightly so - in order to access a memory operand, an address needs
to be specified to the insn. In some cases it might be possible for a
compiler to synthesize a memory operand holding the requested constant,
but I think any solution there would have sharp edges.

If "m" alone doesn't work with constants, it is at best pointless (and
perhaps misleading or even risky - the compiler might decide to actually
pick "m" and not try very hard to find a suitable register) to specify
it alongside "r". And indeed clang does, oddly enough despite its
objection to "m" alone. Which means there the change also improves the
generated code.

While there also switch the two operand case to using named operands.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2: Use named operands in do_double_fault().

--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -736,7 +736,7 @@ void __init detect_zen2_null_seg_behavio
        uint64_t base;
 
        wrmsrl(MSR_FS_BASE, 1);
-       asm volatile ( "mov %0, %%fs" :: "rm" (0) );
+       asm volatile ( "mov %0, %%fs" :: "r" (0) );
        rdmsrl(MSR_FS_BASE, base);
 
        if (base == 0)
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -248,7 +248,8 @@ void do_double_fault(struct cpu_user_reg
 
     console_force_unlock();
 
-    asm ( "lsll %1, %0" : "=r" (cpu) : "rm" (PER_CPU_SELECTOR) );
+    asm ( "lsll %[sel], %[limit]" : [limit] "=r" (cpu)
+                                  : [sel] "r" (PER_CPU_SELECTOR) );
 
     /* Find information saved during fault and dump it to the console. */
     printk("*** DOUBLE FAULT ***\n");




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.