public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Avi Kivity <avi@qumranet.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 8/13] KVM: vcpu execution loop
Date: Tue, 24 Oct 2006 00:18:54 +0200	[thread overview]
Message-ID: <200610240018.55100.arnd@arndb.de> (raw)
In-Reply-To: <453D27F8.8020509@qumranet.com>

On Monday 23 October 2006 22:37, Avi Kivity wrote:
> Arnd Bergmann wrote:
> > On Monday 23 October 2006 22:16, Avi Kivity wrote:
> >>> This looks like you should simply put it into a .S file.
> >>
> >> Then I lose all the offsetof constants down the line.  Sure, I could do
> >> the asm-offsets dance but it seems to me like needless obfuscation.
> >
> > Ok, I see.
> >
> > How if you pass &vcpu->regs and &vcpu->cr2 to the functions instead of
> > kvm_vcpu?
>
> I could do that, but I feel that's more brittle.  I might need more (or
> other) fields later on.  It will also cost me more  pushes on the stack
> (no real performance or space impact, just C64-era frugality).

Maybe you could save some more stack usage by doing something like this:

static inline void vmlaunch(struct kvm_vcpu *vcpu)
{
	register unsigned long rax asm("rax");
	register unsigned long rbx asm("rbx");
	register unsigned long rcx asm("rcx");
	register unsigned long rdx asm("rdx");
	register unsigned long rsi asm("rsi");
	register unsigned long rdi asm("rdi");
	register unsigned long rbp asm("rbp");
	register unsigned long r8  asm("r8");
	register unsigned long r9  asm("r9");
	register unsigned long r10 asm("r10");
	register unsigned long r11 asm("r11");
	register unsigned long r12 asm("r12");
	register unsigned long r13 asm("r13");
	register unsigned long r14 asm("r14");
	register unsigned long r15 asm("r15");

	asm ("mov %%cr2, %0" : : "r" (vcpu->cr2));

	rax = vcpu->regs[VCPU_REGS_RAX];
	rbx = vcpu->regs[VCPU_REGS_RBX];
	rcx = vcpu->regs[VCPU_REGS_RCX];
	rdx = vcpu->regs[VCPU_REGS_RDX];
	rsi = vcpu->regs[VCPU_REGS_RSI];
	rdi = vcpu->regs[VCPU_REGS_RDI];
	rbp = vcpu->regs[VCPU_REGS_RBP];
	r8  = vcpu->regs[VCPU_REGS_R8 ];
	r9  = vcpu->regs[VCPU_REGS_R9 ];
	r10 = vcpu->regs[VCPU_REGS_R10];
	r11 = vcpu->regs[VCPU_REGS_R11];
	r12 = vcpu->regs[VCPU_REGS_R12];
	r13 = vcpu->regs[VCPU_REGS_R13];
	r14 = vcpu->regs[VCPU_REGS_R14];
	r15 = vcpu->regs[VCPU_REGS_R15];

	asm ("vmlaunch\n\t" :
		"+r" (rax),
		"+r" (rbx),
		"+r" (rcx),
		"+r" (rdx),
		"+r" (rsi),
		"+r" (rdi),
		"+r" (rbp),
		"+r" (r8),
		"+r" (r9),
		"+r" (r10),
		"+r" (r11),
		"+r" (r12),
		"+r" (r13),
		"+r" (r14),
		"+r" (r15)
	);

	vcpu->regs[VCPU_REGS_RAX] = rax;
	vcpu->regs[VCPU_REGS_RBX] = rbx;
	vcpu->regs[VCPU_REGS_RCX] = rcx;
	vcpu->regs[VCPU_REGS_RDX] = rdx;
	vcpu->regs[VCPU_REGS_RSI] = rsi;
	vcpu->regs[VCPU_REGS_RDI] = rdi;
	vcpu->regs[VCPU_REGS_RBP] = rbp;
	vcpu->regs[VCPU_REGS_R8 ] = r8 ;
	vcpu->regs[VCPU_REGS_R9 ] = r9 ;
	vcpu->regs[VCPU_REGS_R10] = r10;
	vcpu->regs[VCPU_REGS_R11] = r11;
	vcpu->regs[VCPU_REGS_R12] = r12;
	vcpu->regs[VCPU_REGS_R13] = r13;
	vcpu->regs[VCPU_REGS_R14] = r14;
	vcpu->regs[VCPU_REGS_R15] = r15;

	asm ("mov %0, %%cr2" : "=r" (vcpu->cr2));
}

Unfortunately, I couldn't get this to do the right thing with the output
flags. Unless I missed something, your solution is really the best one you
can express in gcc.

	Arnd <><

  parent reply	other threads:[~2006-10-23 22:18 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-23 13:28 [PATCH 0/7] KVM: Kernel-based Virtual Machine (v2) Avi Kivity
2006-10-23 13:29 ` [PATCH 1/13] KVM: userspace interface Avi Kivity
2006-10-24 12:51   ` Muli Ben-Yehuda
2006-10-24 12:56     ` Avi Kivity
2006-10-24 12:59       ` Muli Ben-Yehuda
2006-10-23 13:29 ` [PATCH 2/13] KVM: Intel virtual mode extensions definitions Avi Kivity
2006-10-23 13:30 ` [PATCH 3/13] KVM: kvm data structures Avi Kivity
2006-10-23 13:30 ` [PATCH 4/13] KVM: random accessors and constants Avi Kivity
2006-10-23 13:30 ` [PATCH 5/13] KVM: virtualization infrastructure Avi Kivity
2006-10-23 19:35   ` Arnd Bergmann
2006-10-23 20:28     ` Avi Kivity
2006-10-23 20:35       ` Arnd Bergmann
2006-10-23 20:39         ` Avi Kivity
2006-10-24 12:03         ` Avi Kivity
2006-10-24  5:19           ` Andi Kleen
2006-10-24 13:43             ` [PATCH] x86: Extract segment descriptor definitions for use outside of x86_64 Avi Kivity
2006-10-24 14:10               ` Andi Kleen
2006-10-23 13:30 ` [PATCH 6/13] KVM: memory slot management Avi Kivity
2006-10-23 13:30 ` [PATCH 7/13] KVM: vcpu creation and maintenance Avi Kivity
2006-10-23 13:30 ` [PATCH 8/13] KVM: vcpu execution loop Avi Kivity
     [not found]   ` <200610232141.45802.arnd@arndb.de>
2006-10-23 20:16     ` Avi Kivity
2006-10-23 20:29       ` Arnd Bergmann
2006-10-23 20:37         ` Avi Kivity
2006-10-23 21:02           ` Antonio Vargas
2006-10-23 21:11             ` Avi Kivity
2006-10-23 22:08               ` Antonio Vargas
2006-10-23 22:18           ` Arnd Bergmann [this message]
2006-10-23 13:31 ` [PATCH 9/13] KVM: define exit handlers Avi Kivity
2006-10-24  1:05   ` Anthony Liguori
2006-10-24  7:23     ` Avi Kivity
2006-10-23 13:31 ` [PATCH 10/13] KVM: less common " Avi Kivity
2006-10-23 13:31 ` [PATCH 11/13] KVM: mmu Avi Kivity
2006-10-23 13:31 ` [PATCH 12/13] KVM: x86 emulator Avi Kivity
2006-10-23 13:31 ` [PATCH 13/13] KVM: plumbing Avi Kivity
2006-10-23 13:44 ` [PATCH 0/7] KVM: Kernel-based Virtual Machine (v2) Avi Kivity
2006-10-23 15:38 ` [PATCH 0/13] KVM: qemu patch Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2006-10-26 17:19 [PATCH 0/13] KVM: Kernel-based Virtual Machine (v3) Avi Kivity
2006-10-26 17:29 ` [PATCH 8/13] KVM: vcpu execution loop Avi Kivity

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=200610240018.55100.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=avi@qumranet.com \
    --cc=linux-kernel@vger.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