public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH] x86/acrn: Improve ACRN hypercalls
Date: Thu,  4 Aug 2022 20:03:58 +0200	[thread overview]
Message-ID: <20220804180358.32944-1-ubizjak@gmail.com> (raw)

As explained in section 6.47.5.2, "Specifying Registers for Local Variables"
of the GCC info documentation, the correct way to specify register for
input operands when calling Extended 'asm' is to define a local register
variable and associate it with a specified register:

	register unsigned long r8 asm ("r8") = hcall_id;

Use the above approach instead of explicit MOV to R8 at the beginning
of the asm. The relaxed assignment allows compiler to optimize and
shrink drivers/virt/acrn.o for 181 bytes:

   text    data     bss     dec     hex filename
   4284     208       0    4492    118c hsm-new.o
   4465     208       0    4673    1241 hsm-old.o

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
 arch/x86/include/asm/acrn.h | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h
index e003a01b7c67..601867085b95 100644
--- a/arch/x86/include/asm/acrn.h
+++ b/arch/x86/include/asm/acrn.h
@@ -29,19 +29,16 @@ static inline u32 acrn_cpuid_base(void)
  *   - Hypercall number is passed in R8 register.
  *   - Up to 2 arguments are passed in RDI, RSI.
  *   - Return value will be placed in RAX.
- *
- * Because GCC doesn't support R8 register as direct register constraints, use
- * supported constraint as input with a explicit MOV to R8 in beginning of asm.
  */
 static inline long acrn_hypercall0(unsigned long hcall_id)
 {
 	long result;
 
-	asm volatile("movl %1, %%r8d\n\t"
-		     "vmcall\n\t"
+	register unsigned long r8 asm ("r8") = hcall_id;
+	asm volatile("vmcall"
 		     : "=a" (result)
-		     : "g" (hcall_id)
-		     : "r8", "memory");
+		     : "r" (r8)
+		     : "memory");
 
 	return result;
 }
@@ -51,11 +48,11 @@ static inline long acrn_hypercall1(unsigned long hcall_id,
 {
 	long result;
 
-	asm volatile("movl %1, %%r8d\n\t"
-		     "vmcall\n\t"
+	register unsigned long r8 asm ("r8") = hcall_id;
+	asm volatile("vmcall"
 		     : "=a" (result)
-		     : "g" (hcall_id), "D" (param1)
-		     : "r8", "memory");
+		     : "r" (r8), "D" (param1)
+		     : "memory");
 
 	return result;
 }
@@ -66,11 +63,11 @@ static inline long acrn_hypercall2(unsigned long hcall_id,
 {
 	long result;
 
-	asm volatile("movl %1, %%r8d\n\t"
-		     "vmcall\n\t"
+	register unsigned long r8 asm ("r8") = hcall_id;
+	asm volatile("vmcall"
 		     : "=a" (result)
-		     : "g" (hcall_id), "D" (param1), "S" (param2)
-		     : "r8", "memory");
+		     : "r" (r8), "D" (param1), "S" (param2)
+		     : "memory");
 
 	return result;
 }
-- 
2.37.1


             reply	other threads:[~2022-08-04 18:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 18:03 Uros Bizjak [this message]
2022-08-04 18:41 ` [PATCH] x86/acrn: Improve ACRN hypercalls Dave Hansen
2022-08-04 18:56   ` Uros Bizjak
2022-08-04 19:03     ` Dave Hansen
2022-08-08 18:59       ` H. Peter Anvin
2022-08-04 18:52 ` Sean Christopherson
2022-08-04 19:05   ` Uros Bizjak

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=20220804180358.32944-1-ubizjak@gmail.com \
    --to=ubizjak@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox