From: Arnd Bergmann <arnd@arndb.de>
To: Carsten Otte <cotte@de.ibm.com>
Cc: EHRHARDT@de.ibm.com, hollisb@us.ibm.com,
kvm-devel@lists.sourceforge.net, heiko.carstens@de.ibm.com,
jeroney@us.ibm.com, Avi Kivity <avi@qumranet.com>,
virtualization@lists.linux-foundation.org,
borntraeger@de.ibm.com, oliver.paukstadt@millenux.com,
schwidefsky@de.ibm.com, rvdheij@gmail.com, os@de.ibm.com,
jblunck@suse.de, "Zhang, Xiantao" <xiantao.zhang@intel.com>
Subject: Re: [RFC/PATCH 05/15 v3] kvm-s390: s390 arch backend for the kvm kernel module
Date: Mon, 31 Mar 2008 07:36:56 +0200 [thread overview]
Message-ID: <200803310736.58001.arnd@arndb.de> (raw)
In-Reply-To: <1206467240.6507.41.camel@cotte.boeblingen.de.ibm.com>
On Tuesday 25 March 2008, Carsten Otte wrote:
> +
> +static inline void __user *__guestaddr_to_user(struct kvm_vcpu *vcpu,
> + u64 guestaddr)
> +{
> + u64 prefix = vcpu->arch.sie_block->prefix;
> + u64 origin = vcpu->kvm->arch.guest_origin;
> + u64 memsize = vcpu->kvm->arch.guest_memsize;
> +
> + if (guestaddr < 2 * PAGE_SIZE)
> + guestaddr += prefix;
> + else if ((guestaddr >= prefix) && (guestaddr < prefix + 2 * PAGE_SIZE))
> + guestaddr -= prefix;
What happens if prefix is set to 4096? Does this do the right thing
according to the architecture definition?
> + if (guestaddr & 7)
> + BUG();
BUG_ON(guestaddr & 7);
same for the others.
> +static inline int copy_to_guest(struct kvm_vcpu *vcpu, u64 guestdest,
> + const void *from, unsigned long n)
> +{
> + u64 prefix = vcpu->arch.sie_block->prefix;
> + u64 origin = vcpu->kvm->arch.guest_origin;
> + u64 memsize = vcpu->kvm->arch.guest_memsize;
> +
> + if ((guestdest < 2 * PAGE_SIZE) && (guestdest + n > 2 * PAGE_SIZE))
> + goto slowpath;
> +
> + if ((guestdest < prefix) && (guestdest + n > prefix))
> + goto slowpath;
> +
> + if ((guestdest < prefix + 2 * PAGE_SIZE)
> + && (guestdest + n > prefix + 2 * PAGE_SIZE))
> + goto slowpath;
> +
> + if (guestdest < 2 * PAGE_SIZE)
> + guestdest += prefix;
> + else if ((guestdest >= prefix) && (guestdest < prefix + 2 * PAGE_SIZE))
> + guestdest -= prefix;
> +
> + if (guestdest + n > memsize)
> + return -EFAULT;
> +
> + if (guestdest + n < guestdest)
> + return -EFAULT;
> +
> + guestdest += origin;
> +
> + return copy_to_user((void __user *) guestdest, from, n);
> +slowpath:
> + return __copy_to_guest_slow(vcpu, guestdest, from, n);
> +}
I assume that the call to copy_to_user is performance critical. Therefore, I'd
reorder the code to handle the common case inline:
extern inline int __copy_to_guest(u64 guestdest, const void *from, unsigned long n,
unsigned long origin, unsigned long prefix);
static inline int copy_to_guest(struct kvm_vcpu *vcpu, u64 guestdest,
const void *from, unsigned long n)
{
u64 prefix = vcpu->arch.sie_block->prefix;
u64 origin = vcpu->kvm->arch.guest_origin;
u64 memsize = vcpu->kvm->arch.guest_memsize;
if (n <= 0 || (guestdest + n > memsize))
return -EFAULT;
if (guestdest >= prefix + 2 * PAGE_SIZE) ||
((guestdest >= 2 * PAGE_SIZE) && (guestdest + n < prefix)))
/* no translation needed */
return copy_to_user((void __user *) guestdest + origin, from, n);
else
/* target needs to be translated */
return __copy_to_guest(guestdest, from, n, origin, prefix);
This should make the inline version shorter and faster and keep most
of the interesting bits out-of-line.
> + try_module_get(THIS_MODULE);
Shouldn't you check the return value of this?
> +static int __guestcopy(struct kvm_vcpu *vcpu, u64 guestdest, const void *from,
> + unsigned long n, int prefix)
> +{
> + if (prefix)
> + return copy_to_guest(vcpu, guestdest, from, n);
> + else
> + return copy_to_guest_absolute(vcpu, guestdest, from, n);
> +}
If you pass the vcpu->prefix or 0 in the prefix argument, you can always
call __copy_to_guest() directly.
> Index: linux-host/arch/s390/kvm/sie64a.S
> ===================================================================
> --- /dev/null
> +++ linux-host/arch/s390/kvm/sie64a.S
> @@ -0,0 +1,47 @@
> +/*
> + * sie64a.S - low level sie call
> + *
> + * Copyright IBM Corp. 2008
I would guess that this file has some bits in it that are older than
2008. How about
Copyright IBM Corp. 2004-2008
> +
> +SP_R5 = 5 * 8 # offset into stackframe
> +SP_R6 = 6 * 8
> +
> +/*
> + * sie64a calling convention:
> + * %r2 pointer to sie control block
> + * %r3 guest register save area
> + */
> + .globl sie64a
> +sie64a:
> + lgr %r5,%r3
> + stmg %r5,%r14,SP_R5(%r15) # save register on entry
> + lgr %r14,%r2 # pointer to sie control block
> + lmg %r0,%r13,0(%r3) # load guest gprs 0-13
> +sie_inst:
> + sie 0(%r14)
> + lg %r14,SP_R5(%r15)
> + stmg %r0,%r13,0(%r14) # save guest gprs 0-13
> + lghi %r2,0
> + lmg %r6,%r14,SP_R6(%r15)
> + br %r14
> +
> +sie_err:
> + lg %r14,SP_R5(%r15)
> + stmg %r0,%r13,0(%r14) # save guest gprs 0-13
> + lghi %r2,-EFAULT
> + lmg %r6,%r14,SP_R6(%r15)
> + br %r14
> +
> + .section __ex_table,"a"
> + .quad sie_inst,sie_err
> + .previous
EFAULT looks a bit too specific here, maybe EINVAL would be better?
> +/* for KVM_GET_REGS and KVM_SET_REGS */
> +struct kvm_regs {
> + /* general purpose regs for s390 */
> + __u64 gprs[16];
> +};
> +
> +/* for KVM_GET_SREGS and KVM_SET_SREGS */
> +struct kvm_sregs {
> + __u32 acrs[16];
> + __u64 crs[16];
> +};
Shouldn't that contain the PSW as well? Or is the PSW part of the
16 CRS?
> +/* for KVM_GET_FPU and KVM_SET_FPU */
> +struct kvm_fpu {
> + __u32 fpc;
> + __u64 fprs[16];
> +};
What about decimal floating point, does that use the same registers?
Arnd <><
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
next prev parent reply other threads:[~2008-03-31 5:36 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-20 16:24 [RFC/PATCH 00/15] kvm on big iron Carsten Otte
2008-03-21 11:02 ` Avi Kivity
2008-03-21 11:22 ` [kvm-devel] " Carsten Otte
2008-03-21 19:44 ` buliding and testing PowerPC KVM Hollis Blanchard
2008-03-25 16:56 ` Avi Kivity
2008-03-25 18:18 ` Hollis Blanchard
2008-03-25 18:21 ` Jerone Young
2008-03-25 18:23 ` Jerone Young
2008-03-26 16:40 ` Avi Kivity
2008-03-22 17:02 ` [RFC/PATCH 00/15 v2] kvm on big iron Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 00/15 v3] " Carsten Otte
2008-03-27 12:02 ` Avi Kivity
[not found] ` <1206458154.6217.12.camel@cotte.boeblingen.de.ibm.com>
2008-03-25 17:47 ` [RFC/PATCH 01/15 v3] preparation: provide hook to enable pgstes in user pagetable Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 02/15 v3] preparation: host memory management changes for s390 kvm Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 03/15 v3] preparation: address of the 64bit extint parm in lowcore Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 04/15 v3] preparation: split sysinfo defintions for kvm use Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 05/15 v3] kvm-s390: s390 arch backend for the kvm kernel module Carsten Otte
2008-03-31 5:36 ` Arnd Bergmann [this message]
2008-04-02 10:20 ` Christian Borntraeger
2008-03-25 17:47 ` [RFC/PATCH 06/15 v3] kvm-s390: sie intercept handling Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 07/15 v3] kvm-s390: interrupt subsystem, cpu timer, waitpsw Carsten Otte
2008-03-31 5:43 ` Arnd Bergmann
2008-03-25 17:47 ` [RFC/PATCH 08/15 v3] kvm-s390: intercepts for privileged instructions Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 09/15 v3] kvm-s390: interprocessor communication via sigp Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 10/15 v3] kvm-s390: intercepts for diagnose instructions Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 11/15 v3] kvm-s390: add kvm to kconfig on s390 Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 12/15 v3] kvm-s390: API documentation Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 13/15 v3] kvm-s390: update maintainers Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 14/15 v3] guest: detect when running on kvm Carsten Otte
2008-03-25 17:47 ` [RFC/PATCH 15/15 v3] guest: virtio device support, and kvm hypercalls Carsten Otte
[not found] ` <1206203560.7177.45.camel@cotte.boeblingen.de.ibm.com>
2008-03-22 17:02 ` [RFC/PATCH 01/15 v2] preparation: provide hook to enable pgstes in user pagetable Carsten Otte
2008-03-24 21:50 ` Andrew Morton
2008-03-22 17:02 ` [RFC/PATCH 02/15 v2] preparation: host memory management changes for s390 kvm Carsten Otte
2008-03-24 21:52 ` Andrew Morton
2008-03-22 17:02 ` [RFC/PATCH 03/15 v2] preparation: address of the 64bit extint parm in lowcore Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 04/15 v2] preparation: split sysinfo defintions for kvm use Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 05/15 v2] kvm-s390: s390 arch backend for the kvm kernel module Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 06/15 v2] kvm-s390: sie intercept handling Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 07/15 v2] kvm-s390: interrupt subsystem, cpu timer, waitpsw Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 08/15 v2] kvm-s390: intercepts for privileged instructions Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 09/15 v2] kvm-s390: interprocessor communication via sigp Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 10/15 v2] kvm-s390: intercepts for diagnose instructions Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 11/15 v2] kvm-s390: add kvm to kconfig on s390 Carsten Otte
2008-03-22 17:02 ` [RFC/PATCH 12/15 v2] kvm-s390: API documentation Carsten Otte
2008-03-22 17:03 ` [RFC/PATCH 13/15 v2] kvm-s390: update maintainers Carsten Otte
2008-03-22 17:03 ` [RFC/PATCH 14/15 v2] guest: detect when running on kvm Carsten Otte
2008-03-22 17:03 ` [RFC/PATCH 15/15 v2] guest: virtio device support, and kvm hypercalls Carsten Otte
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=200803310736.58001.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=EHRHARDT@de.ibm.com \
--cc=avi@qumranet.com \
--cc=borntraeger@de.ibm.com \
--cc=cotte@de.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=hollisb@us.ibm.com \
--cc=jblunck@suse.de \
--cc=jeroney@us.ibm.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=oliver.paukstadt@millenux.com \
--cc=os@de.ibm.com \
--cc=rvdheij@gmail.com \
--cc=schwidefsky@de.ibm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xiantao.zhang@intel.com \
/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