Re: [Qemu-devel] [PATCH 1/4] Use getaddrinfo for migration

2012-02-24 Thread Kevin Wolf
Am 10.02.2012 07:27, schrieb Amos Kong:
 This allows us to use ipv4/ipv6 for migration addresses.
 Once there, it also uses /etc/services names (it came free).
 
 Signed-off-by: Juan Quintela quint...@redhat.com
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  migration-tcp.c |   60 ---
  net.c   |  108 
 +++
  qemu_socket.h   |3 ++
  3 files changed, 127 insertions(+), 44 deletions(-)

This patch is making too many changes at once:

1. Move code around
2. Remove duplicated code between client and server
3. Replace parse_host_port() with an open-coded version
4. Modify the open-coded parse_host_port() to use getaddrinfo instead of
inet_aton/gethostbyname (Why can't we just change parse_host_port? Are
there valid reasons to use the old implementation? Which?)

This makes it rather hard to review.

 diff --git a/migration-tcp.c b/migration-tcp.c
 index 35a5781..644bb8f 100644
 --- a/migration-tcp.c
 +++ b/migration-tcp.c
 @@ -81,43 +81,27 @@ static void tcp_wait_for_connect(void *opaque)
  
  int tcp_start_outgoing_migration(MigrationState *s, const char *host_port)
  {
 -struct sockaddr_in addr;
  int ret;
 -
 -ret = parse_host_port(addr, host_port);
 -if (ret  0) {
 -return ret;
 -}
 +int fd;
  
  s-get_error = socket_errno;
  s-write = socket_write;
  s-close = tcp_close;
  
 -s-fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
 -if (s-fd == -1) {
 -DPRINTF(Unable to open socket);
 -return -socket_error();
 -}
 -
 -socket_set_nonblock(s-fd);
 -
 -do {
 -ret = connect(s-fd, (struct sockaddr *)addr, sizeof(addr));
 -if (ret == -1) {
 -ret = -socket_error();
 -}
 -if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) {
 -qemu_set_fd_handler2(s-fd, NULL, NULL, tcp_wait_for_connect, s);
 -return 0;
 -}
 -} while (ret == -EINTR);
 -
 -if (ret  0) {
 +ret = tcp_client_start(host_port, fd);
 +s-fd = fd;
 +if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) {
 +DPRINTF(connect in progress);
 +qemu_set_fd_handler2(s-fd, NULL, NULL, tcp_wait_for_connect, s);
 +} else if (ret  0) {
  DPRINTF(connect failed\n);
 -migrate_fd_error(s);
 +if (ret != -EINVAL) {
 +migrate_fd_error(s);
 +}

This looks odd. It is probably needed to keep the old behaviour where a
failed parse_host_port() wouldn't call migrate_fd_error(). Is this
really required? Maybe I'm missing something, but the caller can't know
which failure case we had and if migrate_fd_error() has been called.

  return ret;
 +} else {
 +migrate_fd_connect(s);
  }
 -migrate_fd_connect(s);
  return 0;
  }
  
 @@ -157,28 +141,16 @@ out2:
  
  int tcp_start_incoming_migration(const char *host_port)
  {
 -struct sockaddr_in addr;
 -int val;
 +int ret;
  int s;
  
  DPRINTF(Attempting to start an incoming migration\n);
  
 -if (parse_host_port(addr, host_port)  0) {
 -fprintf(stderr, invalid host/port combination: %s\n, host_port);
 -return -EINVAL;
 -}
 -
 -s = qemu_socket(PF_INET, SOCK_STREAM, 0);
 -if (s == -1) {
 -return -socket_error();
 +ret = tcp_server_start(host_port, s);
 +if (ret  0) {
 +return ret;
  }
  
 -val = 1;
 -setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)val, sizeof(val));
 -
 -if (bind(s, (struct sockaddr *)addr, sizeof(addr)) == -1) {
 -goto err;
 -}
  if (listen(s, 1) == -1) {
  goto err;
  }
 diff --git a/net.c b/net.c
 index c34474f..f63014c 100644
 --- a/net.c
 +++ b/net.c
 @@ -99,6 +99,114 @@ static int get_str_sep(char *buf, int buf_size, const 
 char **pp, int sep)
  return 0;
  }
  
 +static int tcp_server_bind(int fd, struct addrinfo *rp)
 +{
 +int ret;
 +int val = 1;
 +
 +/* allow fast reuse */
 +setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)val, 
 sizeof(val));
 +
 +ret = bind(fd, rp-ai_addr, rp-ai_addrlen);
 +
 +if (ret == -1) {
 +ret = -socket_error();
 +}
 +return ret;
 +
 +}
 +
 +static int tcp_client_connect(int fd, struct addrinfo *rp)
 +{
 +int ret;
 +
 +do {
 +ret = connect(fd, rp-ai_addr, rp-ai_addrlen);
 +if (ret == -1) {
 +ret = -socket_error();
 +}
 +} while (ret == -EINTR);
 +
 +return ret;
 +}
 +
 +
 +static int tcp_start_common(const char *str, int *fd, bool server)
 +{
 +char hostname[512];
 +const char *service;
 +const char *name;
 +struct addrinfo hints;
 +struct addrinfo *result, *rp;
 +int s;
 +int sfd;
 +int ret = -EINVAL;
 +
 +*fd = -1;
 +service = str;
 +if (get_str_sep(hostname, sizeof(hostname), service, ':')  0) {
 +return -EINVAL;
 +}

Separating host name and port at the first colon 

Add GSoC project ideas to the wiki!

2012-02-24 Thread Stefan Hajnoczi
This is a reminder that QEMU will apply for Google Summer of Code 2012 and we
need project ideas and mentors.  Libvirt and kvm.ko projects are also welcome!

http://wiki.qemu.org/Google_Summer_of_Code_2012

Please add yourself to the wiki now if you want to mentor a project
this summer.  I will file our application next week.

Thanks,
Stefan
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 2/4] net/socket: allow ipv6 for net_socket_listen_init and socket_connect_init

2012-02-24 Thread Kevin Wolf
Am 10.02.2012 07:27, schrieb Amos Kong:
 Remove use of parse_host_port.
 More SO_SOCKADDR changes.
 
 Signed-off-by: Juan Quintela quint...@redhat.com
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  net/socket.c |   60 
 +++---
  1 files changed, 11 insertions(+), 49 deletions(-)
 
 diff --git a/net/socket.c b/net/socket.c
 index d4c2002..439a69c 100644
 --- a/net/socket.c
 +++ b/net/socket.c
 @@ -403,29 +403,13 @@ static int net_socket_listen_init(VLANState *vlan,
const char *host_str)
  {
  NetSocketListenState *s;
 -int fd, val, ret;
 -struct sockaddr_in saddr;
 -
 -if (parse_host_port(saddr, host_str)  0)
 -return -1;
 +int fd, ret;
  
  s = g_malloc0(sizeof(NetSocketListenState));
  
 -fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
 -if (fd  0) {
 -perror(socket);
 -g_free(s);
 -return -1;
 -}
 -socket_set_nonblock(fd);
 -
 -/* allow fast reuse */
 -val = 1;
 -setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)val, 
 sizeof(val));
 -
 -ret = bind(fd, (struct sockaddr *)saddr, sizeof(saddr));
 +ret = tcp_server_start(host_str, fd);
  if (ret  0) {
 -perror(bind);
 +fprintf(stderr, tcp_server_start: %s\n, strerror(ret));

error_report, and it should be strerror(-ret).

  g_free(s);
  closesocket(fd);
  return -1;
 @@ -451,41 +435,19 @@ static int net_socket_connect_init(VLANState *vlan,
 const char *host_str)
  {
  NetSocketState *s;
 -int fd, connected, ret, err;
 +int fd, connected, ret;
  struct sockaddr_in saddr;
  
 -if (parse_host_port(saddr, host_str)  0)
 -return -1;
 -
 -fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
 -if (fd  0) {
 -perror(socket);
 +ret = tcp_client_start(host_str, fd);
 +if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) {
 +connected = 0;
 +} else if (ret  0) {
 +closesocket(fd);

There is no open fd in this case. The only time that fd != -1 and ret 
0 is for -EINPROGRESS and -EWOULDBLOCK.

  return -1;
 +} else {
 +connected = 1;
  }
 -socket_set_nonblock(fd);
  
 -connected = 0;
 -for(;;) {
 -ret = connect(fd, (struct sockaddr *)saddr, sizeof(saddr));
 -if (ret  0) {
 -err = socket_error();
 -if (err == EINTR || err == EWOULDBLOCK) {
 -} else if (err == EINPROGRESS) {
 -break;
 -#ifdef _WIN32
 -} else if (err == WSAEALREADY || err == WSAEINVAL) {
 -break;
 -#endif

This part is lost without replacement?

 -} else {
 -perror(connect);
 -closesocket(fd);

tcp_client_start uses close() instead of closesocket() in error case,
should probably be changed.

Kevin
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 3/4] net: split hostname and service by last colon

2012-02-24 Thread Kevin Wolf
Am 10.02.2012 07:27, schrieb Amos Kong:
 IPv6 address contains colons, parse will be wrong.
 
 [2312::8274]:5200
 
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  net.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/net.c b/net.c
 index f63014c..9e1ef9e 100644
 --- a/net.c
 +++ b/net.c
 @@ -84,7 +84,7 @@ static int get_str_sep(char *buf, int buf_size, const char 
 **pp, int sep)
  const char *p, *p1;
  int len;
  p = *pp;
 -p1 = strchr(p, sep);
 +p1 = strrchr(p, sep);
  if (!p1)
  return -1;
  len = p1 - p;

And what if the port isn't specified? I think you would erroneously
interpret the last part of the IP address as port.

Kevin
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 1/4] Use getaddrinfo for migration

2012-02-24 Thread Kevin Wolf
Am 10.02.2012 07:27, schrieb Amos Kong:
 This allows us to use ipv4/ipv6 for migration addresses.
 Once there, it also uses /etc/services names (it came free).
 
 Signed-off-by: Juan Quintela quint...@redhat.com
 Signed-off-by: Amos Kong ak...@redhat.com
 ---
  migration-tcp.c |   60 ---
  net.c   |  108 
 +++
  qemu_socket.h   |3 ++
  3 files changed, 127 insertions(+), 44 deletions(-)

 @@ -157,28 +141,16 @@ out2:
  
  int tcp_start_incoming_migration(const char *host_port)
  {
 -struct sockaddr_in addr;
 -int val;
 +int ret;
  int s;
  
  DPRINTF(Attempting to start an incoming migration\n);
  
 -if (parse_host_port(addr, host_port)  0) {
 -fprintf(stderr, invalid host/port combination: %s\n, host_port);
 -return -EINVAL;
 -}

Oh, and this case doesn't print an error message any more now.

Kevin
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 0/4] support to migrate with IPv6 address

2012-02-24 Thread Kevin Wolf
Am 10.02.2012 07:26, schrieb Amos Kong:
 Those four patches make migration of IPv6 address work.
 Use getaddrinfo() to socket addresses infomation.
 
 ---
 
 Amos Kong (4):
   Use getaddrinfo for migration
   net/socket: allow ipv6 for net_socket_listen_init and 
 socket_connect_init
   net: split hostname and service by last colon
   net: support to include ipv6 address by brackets

I think it would be better to split the patches differently:

1. Create tcp_server_start by moving code. Keep using parse_host_port
and the old loop around connect.
2. Unify all TCP servers to use this code
3. Introduce the client code and the convert all clients. Up to here,
this should be pure refactoring work.
4. Only now start changing the logic. First thing is getaddrinfo. Don't
change from IPv4 to IPv6 yet.
5. Make all changes required for IPv6 (getaddrinfo arguments, address
parsing, etc.)

Having step-by-step conversions with an explanation of each step in the
commit message makes it so much easier to understand the commits.

For the comments on details see the replies to the individual patches.

Kevin
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [libvirt] Add GSoC project ideas to the wiki!

2012-02-24 Thread Michal Privoznik
On 24.02.2012 10:19, Stefan Hajnoczi wrote:
 This is a reminder that QEMU will apply for Google Summer of Code 2012 and we
 need project ideas and mentors.  Libvirt and kvm.ko projects are also welcome!
 
 http://wiki.qemu.org/Google_Summer_of_Code_2012
 
 Please add yourself to the wiki now if you want to mentor a project
 this summer.  I will file our application next week.
 
 Thanks,
 Stefan

Hi Stefan,

Thank you for the opportunity. I was personally thinking about something
libvirt-snmp related. Nowdays, it is difficult to add new elements to
MIB, as some parts of code were generated by mib2c. Any change to MIB
requires regeneration of such source files and thus leads to loss of all
previous changes. So one thing that is coming to my mind is drop this
dependency and use libsnmp directly. But I am not sure it is worth of GSoC.

Michal
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [libvirt] Add GSoC project ideas to the wiki!

2012-02-24 Thread Stefan Hajnoczi
On Fri, Feb 24, 2012 at 10:38 AM, Michal Privoznik mpriv...@redhat.com wrote:
 On 24.02.2012 10:19, Stefan Hajnoczi wrote:
 Thank you for the opportunity. I was personally thinking about something
 libvirt-snmp related. Nowdays, it is difficult to add new elements to
 MIB, as some parts of code were generated by mib2c. Any change to MIB
 requires regeneration of such source files and thus leads to loss of all
 previous changes. So one thing that is coming to my mind is drop this
 dependency and use libsnmp directly. But I am not sure it is worth of GSoC.

If this project is self-contained and can be completed in 12 weeks by
a person without prior libvirt and SNMP experience, but fluent C
programming skills, then it sounds suitable.

Is there any creativity required or problems to solve that aren't
grunt work?  For example, if you just need to run mib2c and then
manually diff to produce the final C version, then this sounds like a
lot of manual work but little gain for the student.

Stefan
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/37] KVM: PPC: booke: add booke-level vcpu load/put

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

This gives us a place to put load/put actions that correspond to
code that is booke-specific but not specific to a particular core.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/44x.c   |3 +++
 arch/powerpc/kvm/booke.c |8 
 arch/powerpc/kvm/booke.h |3 +++
 arch/powerpc/kvm/e500.c  |3 +++
 4 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
index 7b612a7..879a1a7 100644
--- a/arch/powerpc/kvm/44x.c
+++ b/arch/powerpc/kvm/44x.c
@@ -29,15 +29,18 @@
 #include asm/kvm_ppc.h
 
 #include 44x_tlb.h
+#include booke.h
 
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
+   kvmppc_booke_vcpu_load(vcpu, cpu);
kvmppc_44x_tlb_load(vcpu);
 }
 
 void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
 {
kvmppc_44x_tlb_put(vcpu);
+   kvmppc_booke_vcpu_put(vcpu);
 }
 
 int kvmppc_core_check_processor_compat(void)
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index ee9e1ee..a2456c7 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -968,6 +968,14 @@ void kvmppc_decrementer_func(unsigned long data)
kvmppc_set_tsr_bits(vcpu, TSR_DIS);
 }
 
+void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
+{
+}
+
+void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)
+{
+}
+
 int __init kvmppc_booke_init(void)
 {
unsigned long ivor[16];
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index 2fe2027..05d1d99 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -71,4 +71,7 @@ void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu);
 /* high-level function, manages flags, host state */
 void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu);
 
+void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
+void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu);
+
 #endif /* __KVM_BOOKE_H__ */
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index ddcd896..2d5fe04 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -36,6 +36,7 @@ void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
 
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
+   kvmppc_booke_vcpu_load(vcpu, cpu);
kvmppc_e500_tlb_load(vcpu, cpu);
 }
 
@@ -47,6 +48,8 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
if (vcpu-arch.shadow_msr  MSR_SPE)
kvmppc_vcpu_disable_spe(vcpu);
 #endif
+
+   kvmppc_booke_vcpu_put(vcpu);
 }
 
 int kvmppc_core_check_processor_compat(void)
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 19/37] KVM: PPC: e500mc: add load inst fixup

2012-02-24 Thread Alexander Graf
There's always a chance we're unable to read a guest instruction. The guest
could have its TLB mapped execute-, but not readable, something odd happens
and our TLB gets flushed. So it's a good idea to be prepared for that case
and have a fallback that allows us to fix things up in that case.

Add fixup code that keeps guest code from potentially crashing our host kernel.

Signed-off-by: Alexander Graf ag...@suse.de

---

v1 - v2:

  - fix whitespace
  - use explicit preempt counts
---
 arch/powerpc/kvm/bookehv_interrupts.S |   30 +-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 63023ae..f7dc3f6 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -28,6 +28,7 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 #include asm/bitsperlong.h
+#include asm/thread_info.h
 
 #include ../kernel/head_booke.h /* for THREAD_NORMSAVE() */
 
@@ -171,9 +172,36 @@
PPC_STL r30, VCPU_GPR(r30)(r4)
PPC_STL r31, VCPU_GPR(r31)(r4)
mtspr   SPRN_EPLC, r8
+
+   /* disable preemption, so we are sure we hit the fixup handler */
+#ifdef CONFIG_PPC64
+   clrrdi  r8,r1,THREAD_SHIFT
+#else
+   rlwinm  r8,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+#endif
+   li  r7, 1
+stwr7, TI_PREEMPT(r8)
+
isync
-   lwepx   r9, 0, r5
+
+   /*
+* In case the read goes wrong, we catch it and write an invalid value
+* in LAST_INST instead.
+*/
+1: lwepx   r9, 0, r5
+2:
+.section .fixup, ax
+3: li  r9, KVM_INST_FETCH_FAILED
+   b   2b
+.previous
+.section __ex_table,a
+   PPC_LONG_ALIGN
+   PPC_LONG 1b,3b
+.previous
+
mtspr   SPRN_EPLC, r3
+   li  r7, 0
+stwr7, TI_PREEMPT(r8)
stw r9, VCPU_LAST_INST(r4)
.endif
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/37] KVM: PPC: e500mc: Move r1/r2 restoration very early

2012-02-24 Thread Alexander Graf
If we hit any exception whatsoever in the restore path and r1/r2 aren't the
host registers, we don't get a working oops. So it's always a good idea to
restore them as early as possible.

This time, it actually has practical reasons to do so too, since we need to
have the host page fault handler fix up our guest instruction read code. And
for that to work we need r1/r2 restored.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 9eaeebd..63023ae 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -67,6 +67,12 @@
  * saved in vcpu: cr, ctr, r3-r13
  */
 .macro kvm_handler_common intno, srr0, flags
+   /* Restore host stack pointer */
+   PPC_STL r1, VCPU_GPR(r1)(r4)
+   PPC_STL r2, VCPU_GPR(r2)(r4)
+   PPC_LL  r1, VCPU_HOST_STACK(r4)
+   PPC_LL  r2, HOST_R2(r1)
+
mfspr   r10, SPRN_PID
lwz r8, VCPU_HOST_PID(r4)
PPC_LL  r11, VCPU_SHARED(r4)
@@ -290,10 +296,8 @@ _GLOBAL(kvmppc_resume_host)
/* Save remaining volatile guest register state to vcpu. */
mfspr   r3, SPRN_VRSAVE
PPC_STL r0, VCPU_GPR(r0)(r4)
-   PPC_STL r1, VCPU_GPR(r1)(r4)
mflrr5
mfspr   r6, SPRN_SPRG4
-   PPC_STL r2, VCPU_GPR(r2)(r4)
PPC_STL r5, VCPU_LR(r4)
mfspr   r7, SPRN_SPRG5
PPC_STL r3, VCPU_VRSAVE(r4)
@@ -334,10 +338,6 @@ _GLOBAL(kvmppc_resume_host)
mtspr   SPRN_EPCR, r3
isync
 
-   /* Restore host stack pointer */
-   PPC_LL  r1, VCPU_HOST_STACK(r4)
-   PPC_LL  r2, HOST_R2(r1)
-
/* Switch to kernel stack and jump to handler. */
PPC_LL  r3, HOST_RUN(r1)
mr  r5, r14 /* intno */
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 14/37] KVM: PPC: booke: standard PPC floating point support

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

e500mc has a normal PPC FPU, rather than SPE which is found
on e500v1/v2.

Based on code from Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/system.h |1 +
 arch/powerpc/kvm/booke.c  |   44 +
 arch/powerpc/kvm/booke.h  |   30 +
 3 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/system.h 
b/arch/powerpc/include/asm/system.h
index c377457..73eee86 100644
--- a/arch/powerpc/include/asm/system.h
+++ b/arch/powerpc/include/asm/system.h
@@ -140,6 +140,7 @@ extern void via_cuda_init(void);
 extern void read_rtc_time(void);
 extern void pmac_find_display(void);
 extern void giveup_fpu(struct task_struct *);
+extern void load_up_fpu(void);
 extern void disable_kernel_fp(void);
 extern void enable_kernel_fp(void);
 extern void flush_fp_to_thread(struct task_struct *);
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 75dbaeb..0b77be1 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -457,6 +457,11 @@ void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
int ret;
+#ifdef CONFIG_PPC_FPU
+   unsigned int fpscr;
+   int fpexc_mode;
+   u64 fpr[32];
+#endif
 
if (!vcpu-arch.sane) {
kvm_run-exit_reason = KVM_EXIT_INTERNAL_ERROR;
@@ -479,7 +484,46 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
}
 
kvm_guest_enter();
+
+#ifdef CONFIG_PPC_FPU
+   /* Save userspace FPU state in stack */
+   enable_kernel_fp();
+   memcpy(fpr, current-thread.fpr, sizeof(current-thread.fpr));
+   fpscr = current-thread.fpscr.val;
+   fpexc_mode = current-thread.fpexc_mode;
+
+   /* Restore guest FPU state to thread */
+   memcpy(current-thread.fpr, vcpu-arch.fpr, sizeof(vcpu-arch.fpr));
+   current-thread.fpscr.val = vcpu-arch.fpscr;
+
+   /*
+* Since we can't trap on MSR_FP in GS-mode, we consider the guest
+* as always using the FPU.  Kernel usage of FP (via
+* enable_kernel_fp()) in this thread must not occur while
+* vcpu-fpu_active is set.
+*/
+   vcpu-fpu_active = 1;
+
+   kvmppc_load_guest_fp(vcpu);
+#endif
+
ret = __kvmppc_vcpu_run(kvm_run, vcpu);
+
+#ifdef CONFIG_PPC_FPU
+   kvmppc_save_guest_fp(vcpu);
+
+   vcpu-fpu_active = 0;
+
+   /* Save guest FPU state from thread */
+   memcpy(vcpu-arch.fpr, current-thread.fpr, sizeof(vcpu-arch.fpr));
+   vcpu-arch.fpscr = current-thread.fpscr.val;
+
+   /* Restore userspace FPU state from stack */
+   memcpy(current-thread.fpr, fpr, sizeof(current-thread.fpr));
+   current-thread.fpscr.val = fpscr;
+   current-thread.fpexc_mode = fpexc_mode;
+#endif
+
kvm_guest_exit();
 
 out:
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index d53bcf2..3bf5eda 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -96,4 +96,34 @@ enum int_class {
 
 void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type);
 
+/*
+ * Load up guest vcpu FP state if it's needed.
+ * It also set the MSR_FP in thread so that host know
+ * we're holding FPU, and then host can help to save
+ * guest vcpu FP state if other threads require to use FPU.
+ * This simulates an FP unavailable fault.
+ *
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (vcpu-fpu_active  !(current-thread.regs-msr  MSR_FP)) {
+   load_up_fpu();
+   current-thread.regs-msr |= MSR_FP;
+   }
+#endif
+}
+
+/*
+ * Save guest vcpu FP state into thread.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (vcpu-fpu_active  (current-thread.regs-msr  MSR_FP))
+   giveup_fpu(current);
+#endif
+}
 #endif /* __KVM_BOOKE_H__ */
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 37/37] KVM: PPC: booke: Reinject performance monitor interrupts

2012-02-24 Thread Alexander Graf
When we get a performance monitor interrupt, we need to make sure that
the host receives it. So reinject it like we reinject the other host
destined interrupts.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/hw_irq.h |1 +
 arch/powerpc/kvm/booke.c  |3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/hw_irq.h 
b/arch/powerpc/include/asm/hw_irq.h
index bb712c9..904e66c 100644
--- a/arch/powerpc/include/asm/hw_irq.h
+++ b/arch/powerpc/include/asm/hw_irq.h
@@ -12,6 +12,7 @@
 #include asm/processor.h
 
 extern void timer_interrupt(struct pt_regs *);
+extern void performance_monitor_exception(struct pt_regs *regs);
 
 #ifdef CONFIG_PPC64
 #include asm/paca.h
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 709fd45..c391357 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -630,6 +630,9 @@ static void kvmppc_restart_interrupt(struct kvm_vcpu *vcpu,
case BOOKE_INTERRUPT_MACHINE_CHECK:
/* FIXME */
break;
+   case BOOKE_INTERRUPT_PERFORMANCE_MONITOR:
+   performance_monitor_exception(regs);
+   break;
}
 }
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 36/37] KVM: PPC: booke: expose guest registers on irq reinject

2012-02-24 Thread Alexander Graf
When reinjecting an interrupt into the host interrupt handler after we're
back in host kernel land, let's tell the kernel about all the guest state
that the interrupt happened at.

This helps getting reasonable numbers out of perf.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   54 +
 1 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 423701b..709fd45 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -593,37 +593,61 @@ static int emulation_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
}
 }
 
-/**
- * kvmppc_handle_exit
- *
- * Return value is in the form (errcode2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
- */
-int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
-   unsigned int exit_nr)
+static void kvmppc_fill_pt_regs(struct kvm_vcpu *vcpu, struct pt_regs *regs)
 {
-   int r = RESUME_HOST;
+   int i;
 
-   /* update before a new last_exit_type is rewritten */
-   kvmppc_update_timing_stats(vcpu);
+   for (i = 0; i  32; i++)
+   regs-gpr[i] = kvmppc_get_gpr(vcpu, i);
+   regs-nip = vcpu-arch.pc;
+   regs-msr = vcpu-arch.shared-msr;
+   regs-ctr = vcpu-arch.ctr;
+   regs-link = vcpu-arch.lr;
+   regs-xer = kvmppc_get_xer(vcpu);
+   regs-ccr = kvmppc_get_cr(vcpu);
+   regs-dar = get_guest_dear(vcpu);
+   regs-dsisr = get_guest_esr(vcpu);
+}
+
+static void kvmppc_restart_interrupt(struct kvm_vcpu *vcpu,
+unsigned int exit_nr)
+{
+   struct pt_regs regs = *current-thread.regs;
 
+   kvmppc_fill_pt_regs(vcpu, regs);
switch (exit_nr) {
case BOOKE_INTERRUPT_EXTERNAL:
-   do_IRQ(current-thread.regs);
+   do_IRQ(regs);
break;
-
case BOOKE_INTERRUPT_DECREMENTER:
-   timer_interrupt(current-thread.regs);
+   timer_interrupt(regs);
break;
-
 #if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3E_64)
case BOOKE_INTERRUPT_DOORBELL:
-   doorbell_exception(current-thread.regs);
+   doorbell_exception(regs);
break;
 #endif
case BOOKE_INTERRUPT_MACHINE_CHECK:
/* FIXME */
break;
}
+}
+
+/**
+ * kvmppc_handle_exit
+ *
+ * Return value is in the form (errcode2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
+ */
+int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
+   unsigned int exit_nr)
+{
+   int r = RESUME_HOST;
+
+   /* update before a new last_exit_type is rewritten */
+   kvmppc_update_timing_stats(vcpu);
+
+   /* restart interrupts if they were meant for the host */
+   kvmppc_restart_interrupt(vcpu, exit_nr);
 
local_irq_enable();
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 34/37] KVM: PPC: e500: fix typo in tlb code

2012-02-24 Thread Alexander Graf
The tlbncfg registers should be populated with their respective TLB's
values. Fix the obvious typo.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500_tlb.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 279e10a..e05232b 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -1268,8 +1268,8 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 
*vcpu_e500)
 
vcpu-arch.tlbcfg[1] = mfspr(SPRN_TLB1CFG) 
 ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
-   vcpu-arch.tlbcfg[0] |= vcpu_e500-gtlb_params[1].entries;
-   vcpu-arch.tlbcfg[0] |=
+   vcpu-arch.tlbcfg[1] |= vcpu_e500-gtlb_params[1].entries;
+   vcpu-arch.tlbcfg[1] |=
vcpu_e500-gtlb_params[1].ways  TLBnCFG_ASSOC_SHIFT;
 
return 0;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 35/37] KVM: PPC: booke: Support perfmon interrupts

2012-02-24 Thread Alexander Graf
When during guest context we get a performance monitor interrupt, we
currently bail out and oops. Let's route it to its correct handler
instead.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 7adef28..423701b 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -677,6 +677,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
r = RESUME_GUEST;
break;
 
+   case BOOKE_INTERRUPT_PERFORMANCE_MONITOR:
+   r = RESUME_GUEST;
+   break;
+
case BOOKE_INTERRUPT_HV_PRIV:
r = emulation_exit(run, vcpu);
break;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 32/37] KVM: PPC: booke: add GS documentation for program interrupt

2012-02-24 Thread Alexander Graf
The comment for program interrupts triggered when using bookehv was
misleading. Update it to mention why MSR_GS indicates that we have
to inject an interrupt into the guest again, not emulate it.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   10 --
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 451ba16..7adef28 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -683,8 +683,14 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 
case BOOKE_INTERRUPT_PROGRAM:
if (vcpu-arch.shared-msr  (MSR_PR | MSR_GS)) {
-   /* Program traps generated by user-level software must 
be handled
-* by the guest kernel. */
+   /*
+* Program traps generated by user-level software must
+* be handled by the guest kernel.
+*
+* In GS mode, hypervisor privileged instructions trap
+* on BOOKE_INTERRUPT_HV_PRIV, not here, so these are
+* actual program interrupts, handled by the guest.
+*/
kvmppc_core_queue_program(vcpu, vcpu-arch.fault_esr);
r = RESUME_GUEST;
kvmppc_account_exit(vcpu, USR_PR_INST);
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 33/37] KVM: PPC: bookehv: remove unused code

2012-02-24 Thread Alexander Graf
There was some unused code in the exit code path that must have been
a leftover from earlier iterations. While it did no hard, it's superfluous
and thus should be removed.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 021d087..b1c099b 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -112,9 +112,6 @@
 * appropriate for the exception type).
 */
cmpwr6, r8
-   .if \flags  NEED_EMU
-   lwz r9, KVM_LPID(r9)
-   .endif
beq 1f
mfmsr   r7
.if \srr0 != SPRN_MCSRR0  \srr0 != SPRN_CSRR0
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 31/37] KVM: PPC: booke: Readd debug abort code for machine check

2012-02-24 Thread Alexander Graf
When during guest execution we get a machine check interrupt, we don't
know how to handle it yet. So let's add the error printing code back
again that we dropped accidently earlier and tell user space that something
went really wrong.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |7 ++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 288bc05..451ba16 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -632,7 +632,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 
switch (exit_nr) {
case BOOKE_INTERRUPT_MACHINE_CHECK:
-   r = RESUME_GUEST;
+   printk(MACHINE CHECK: %lx\n, mfspr(SPRN_MCSR));
+   kvmppc_dump_vcpu(vcpu);
+   /* For debugging, send invalid exit reason to user space */
+   run-hw.hardware_exit_reason = ~1ULL  32;
+   run-hw.hardware_exit_reason |= mfspr(SPRN_MCSR);
+   r = RESUME_HOST;
break;
 
case BOOKE_INTERRUPT_EXTERNAL:
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 29/37] KVM: PPC: bookehv: disable MAS register updates early

2012-02-24 Thread Alexander Graf
We need to make sure that no MAS updates happen automatically while we
have the guest MAS registers loaded. So move the disabling code a bit
higher up so that it covers the full time we have guest values in MAS
registers.

The race this patch fixes should never occur, but it makes the code a
bit more logical to do it this way around.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |   10 ++
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 469bd3f..021d087 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -358,6 +358,7 @@ _GLOBAL(kvmppc_resume_host)
mtspr   SPRN_MAS4, r6
stw r5, VCPU_SHARED_MAS7_3+0(r11)
mtspr   SPRN_MAS6, r8
+   /* Enable MAS register updates via exception */
mfspr   r3, SPRN_EPCR
rlwinm  r3, r3, 0, ~SPRN_EPCR_DMIUH
mtspr   SPRN_EPCR, r3
@@ -515,6 +516,11 @@ lightweight_exit:
mtspr   SPRN_PID, r3
 
PPC_LL  r11, VCPU_SHARED(r4)
+   /* Disable MAS register updates via exception */
+   mfspr   r3, SPRN_EPCR
+   orisr3, r3, SPRN_EPCR_DMIUH@h
+   mtspr   SPRN_EPCR, r3
+   isync
/* Save host mas4 and mas6 and load guest MAS registers */
mfspr   r3, SPRN_MAS4
stw r3, VCPU_HOST_MAS4(r4)
@@ -538,10 +544,6 @@ lightweight_exit:
lwz r5, VCPU_SHARED_MAS7_3+0(r11)
mtspr   SPRN_MAS6, r3
mtspr   SPRN_MAS7, r5
-   /* Disable MAS register updates via exception */
-   mfspr   r3, SPRN_EPCR
-   orisr3, r3, SPRN_EPCR_DMIUH@h
-   mtspr   SPRN_EPCR, r3
 
/*
 * Host interrupt handlers may have clobbered these guest-readable
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 30/37] KVM: PPC: bookehv: add comment about shadow_msr

2012-02-24 Thread Alexander Graf
For BookE HV the guest visible MSR is shared-msr and is identical to
the MSR that is in use while the guest is running, because we can't trap
reads from/to MSR.

So shadow_msr is unused there. Indicate that with a comment.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index ed95f53..633d68f 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -386,6 +386,7 @@ struct kvm_vcpu_arch {
 #endif
u32 vrsave; /* also USPRG0 */
u32 mmucr;
+   /* shadow_msr is unused for BookE HV */
ulong shadow_msr;
ulong csrr0;
ulong csrr1;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 27/37] KVM: PPC: bookehv: remove negation for CONFIG_64BIT

2012-02-24 Thread Alexander Graf
Instead if doing

  #ifndef CONFIG_64BIT
  ...
  #else
  ...
  #endif

we should rather do

  #ifdef CONFIG_64BIT
  ...
  #else
  ...
  #endif

which is a lot easier to read. Change the bookehv implementation to
stick with this rule.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |   24 
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 215381e..c5a0796 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -99,10 +99,10 @@
.endif
 
orisr8, r6, MSR_CE@h
-#ifndef CONFIG_64BIT
-   stw r6, (VCPU_SHARED_MSR + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
std r6, (VCPU_SHARED_MSR)(r11)
+#else
+   stw r6, (VCPU_SHARED_MSR + 4)(r11)
 #endif
ori r8, r8, MSR_ME | MSR_RI
PPC_STL r5, VCPU_PC(r4)
@@ -344,10 +344,10 @@ _GLOBAL(kvmppc_resume_host)
stw r5, VCPU_SHARED_MAS0(r11)
mfspr   r7, SPRN_MAS2
stw r6, VCPU_SHARED_MAS1(r11)
-#ifndef CONFIG_64BIT
-   stw r7, (VCPU_SHARED_MAS2 + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
std r7, (VCPU_SHARED_MAS2)(r11)
+#else
+   stw r7, (VCPU_SHARED_MAS2 + 4)(r11)
 #endif
mfspr   r5, SPRN_MAS3
mfspr   r6, SPRN_MAS4
@@ -530,10 +530,10 @@ lightweight_exit:
stw r3, VCPU_HOST_MAS6(r4)
lwz r3, VCPU_SHARED_MAS0(r11)
lwz r5, VCPU_SHARED_MAS1(r11)
-#ifndef CONFIG_64BIT
-   lwz r6, (VCPU_SHARED_MAS2 + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
ld  r6, (VCPU_SHARED_MAS2)(r11)
+#else
+   lwz r6, (VCPU_SHARED_MAS2 + 4)(r11)
 #endif
lwz r7, VCPU_SHARED_MAS7_3+4(r11)
lwz r8, VCPU_SHARED_MAS4(r11)
@@ -572,10 +572,10 @@ lightweight_exit:
PPC_LL  r6, VCPU_CTR(r4)
PPC_LL  r7, VCPU_CR(r4)
PPC_LL  r8, VCPU_PC(r4)
-#ifndef CONFIG_64BIT
-   lwz r9, (VCPU_SHARED_MSR + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
ld  r9, (VCPU_SHARED_MSR)(r11)
+#else
+   lwz r9, (VCPU_SHARED_MSR + 4)(r11)
 #endif
PPC_LL  r0, VCPU_GPR(r0)(r4)
PPC_LL  r1, VCPU_GPR(r1)(r4)
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 23/37] KVM: PPC: booke: deliver program int on emulation failure

2012-02-24 Thread Alexander Graf
When we fail to emulate an instruction for the guest, we better go in and
tell it that we failed to emulate it, by throwing an illegal instruction
exception.

Please beware that we basically never get around to telling the guest that
we failed thanks to the debugging code right above it. If user space however
decides that it wants to ignore the debug, we would at least do the right
thing afterwards.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 17d5318..9979be1 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -545,13 +545,13 @@ static int emulation_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
return RESUME_HOST;
 
case EMULATE_FAIL:
-   /* XXX Deliver Program interrupt to guest. */
printk(KERN_CRIT %s: emulation at %lx failed (%08x)\n,
   __func__, vcpu-arch.pc, vcpu-arch.last_inst);
/* For debugging, encode the failing instruction and
 * report it to userspace. */
run-hw.hardware_exit_reason = ~0ULL  32;
run-hw.hardware_exit_reason |= vcpu-arch.last_inst;
+   kvmppc_core_queue_program(vcpu, ESR_PIL);
return RESUME_HOST;
 
default:
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 24/37] KVM: PPC: booke: rework rescheduling checks

2012-02-24 Thread Alexander Graf
Instead of checking whether we should reschedule only when we exited
due to an interrupt, let's always check before entering the guest back
again. This gets the target more in line with the other archs.

Also while at it, generalize the whole thing so that eventually we could
have a single kvmppc_prepare_to_enter function for all ppc targets that
does signal and reschedule checking for us.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_ppc.h |2 +-
 arch/powerpc/kvm/book3s.c  |4 ++-
 arch/powerpc/kvm/booke.c   |   70 ---
 3 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index e709975..7f0a3da 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -95,7 +95,7 @@ extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
 extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
 extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);
 
-extern void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
+extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
 extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags);
 extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 7d54f4e..c8ead7b 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -258,7 +258,7 @@ static bool clear_irqprio(struct kvm_vcpu *vcpu, unsigned 
int priority)
return true;
 }
 
-void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
+int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 {
unsigned long *pending = vcpu-arch.pending_exceptions;
unsigned long old_pending = vcpu-arch.pending_exceptions;
@@ -283,6 +283,8 @@ void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 
/* Tell the guest about our interrupt status */
kvmppc_update_int_pending(vcpu, *pending, old_pending);
+
+   return 0;
 }
 
 pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn)
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 9979be1..3fcec2c 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -439,8 +439,9 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
 }
 
 /* Check pending exceptions and deliver one, if possible. */
-void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
+int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 {
+   int r = 0;
WARN_ON_ONCE(!irqs_disabled());
 
kvmppc_core_check_exceptions(vcpu);
@@ -451,8 +452,44 @@ void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
local_irq_disable();
 
kvmppc_set_exit_type(vcpu, EMULATED_MTMSRWE_EXITS);
-   kvmppc_core_check_exceptions(vcpu);
+   r = 1;
};
+
+   return r;
+}
+
+/*
+ * Common checks before entering the guest world.  Call with interrupts
+ * disabled.
+ *
+ * returns !0 if a signal is pending and check_signal is true
+ */
+static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu, bool check_signal)
+{
+   int r = 0;
+
+   WARN_ON_ONCE(!irqs_disabled());
+   while (true) {
+   if (need_resched()) {
+   local_irq_enable();
+   cond_resched();
+   local_irq_disable();
+   continue;
+   }
+
+   if (kvmppc_core_prepare_to_enter(vcpu)) {
+   /* interrupts got enabled in between, so we
+  are back at square 1 */
+   continue;
+   }
+
+   if (check_signal  signal_pending(current))
+   r = 1;
+
+   break;
+   }
+
+   return r;
 }
 
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
@@ -470,10 +507,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
}
 
local_irq_disable();
-
-   kvmppc_core_prepare_to_enter(vcpu);
-
-   if (signal_pending(current)) {
+   if (kvmppc_prepare_to_enter(vcpu, true)) {
kvm_run-exit_reason = KVM_EXIT_INTR;
ret = -EINTR;
goto out;
@@ -598,25 +632,21 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 
switch (exit_nr) {
case BOOKE_INTERRUPT_MACHINE_CHECK:
-   kvm_resched(vcpu);
r = RESUME_GUEST;
break;
 
case BOOKE_INTERRUPT_EXTERNAL:
kvmppc_account_exit(vcpu, EXT_INTR_EXITS);
-   kvm_resched(vcpu);
r = RESUME_GUEST;
break;
 
case BOOKE_INTERRUPT_DECREMENTER:
kvmppc_account_exit(vcpu, DEC_EXITS);
-   kvm_resched(vcpu);
  

[PATCH 26/37] KVM: PPC: bookehv: fix exit timing

2012-02-24 Thread Alexander Graf
When using exit timing stats, we clobber r9 in the NEED_EMU case,
so better move that part down a few lines and fix it that way.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index f7dc3f6..215381e 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -83,10 +83,6 @@
stw r10, VCPU_GUEST_PID(r4)
mtspr   SPRN_PID, r8
 
-   .if \flags  NEED_EMU
-   lwz r9, VCPU_KVM(r4)
-   .endif
-
 #ifdef CONFIG_KVM_EXIT_TIMING
/* save exit time */
 1: mfspr   r7, SPRN_TBRU
@@ -98,6 +94,10 @@
PPC_STL r9, VCPU_TIMING_EXIT_TBU(r4)
 #endif
 
+   .if \flags  NEED_EMU
+   lwz r9, VCPU_KVM(r4)
+   .endif
+
orisr8, r6, MSR_CE@h
 #ifndef CONFIG_64BIT
stw r6, (VCPU_SHARED_MSR + 4)(r11)
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 25/37] KVM: PPC: booke: BOOKE_IRQPRIO_MAX is n+1

2012-02-24 Thread Alexander Graf
The semantics of BOOKE_IRQPRIO_MAX changed to denote the highest available
irqprio + 1, so let's reflect that in the code too.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 3fcec2c..288bc05 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -425,7 +425,7 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
}
 
priority = __ffs(*pending);
-   while (priority = BOOKE_IRQPRIO_MAX) {
+   while (priority  BOOKE_IRQPRIO_MAX) {
if (kvmppc_booke_irqprio_deliver(vcpu, priority))
break;
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 28/37] KVM: PPC: bookehv: remove SET_VCPU

2012-02-24 Thread Alexander Graf
The SET_VCPU macro is a leftover from times when the vcpu struct wasn't
stored in the thread on vcpu_load/put. It's not needed anymore. Remove it.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |8 
 1 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index c5a0796..469bd3f 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -35,9 +35,6 @@
 #define GET_VCPU(vcpu, thread) \
PPC_LL  vcpu, THREAD_KVM_VCPU(thread)
 
-#define SET_VCPU(vcpu) \
-PPC_STLvcpu, (THREAD + THREAD_KVM_VCPU)(r2)
-
 #define LONGBYTES  (BITS_PER_LONG / 8)
 
 #define VCPU_GPR(n)(VCPU_GPRS + (n * LONGBYTES))
@@ -517,11 +514,6 @@ lightweight_exit:
lwz r3, VCPU_GUEST_PID(r4)
mtspr   SPRN_PID, r3
 
-   /* Save vcpu pointer for the exception handlers
-* must be done before loading guest r2.
-*/
-// SET_VCPU(r4)
-
PPC_LL  r11, VCPU_SHARED(r4)
/* Save host mas4 and mas6 and load guest MAS registers */
mfspr   r3, SPRN_MAS4
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 22/37] KVM: PPC: booke: remove leftover debugging

2012-02-24 Thread Alexander Graf
The e500mc patches left some debug code in that we don't need. Remove it.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |5 -
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 9fcc760..17d5318 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -469,11 +469,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
return -EINVAL;
}
 
-   if (!current-thread.kvm_vcpu) {
-   WARN(1, no vcpu\n);
-   return -EPERM;
-   }
-
local_irq_disable();
 
kvmppc_core_prepare_to_enter(vcpu);
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 21/37] KVM: PPC: make e500v2 kvm and e500mc cpu mutually exclusive

2012-02-24 Thread Alexander Graf
We can't run e500v2 kvm on e500mc kernels, so indicate that by
making the 2 options mutually exclusive in kconfig.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/Kconfig |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 44a998d..f4dacb9 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -120,7 +120,7 @@ config KVM_EXIT_TIMING
 
 config KVM_E500V2
bool KVM support for PowerPC E500v2 processors
-   depends on EXPERIMENTAL  E500
+   depends on EXPERIMENTAL  E500  !PPC_E500MC
select KVM
select KVM_MMIO
---help---
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 20/37] KVM: PPC: rename CONFIG_KVM_E500 - CONFIG_KVM_E500V2

2012-02-24 Thread Alexander Graf
The CONFIG_KVM_E500 option really indicates that we're running on a V2 machine,
not on a machine of the generic E500 class. So indicate that properly and
change the config name accordingly.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/Kconfig|8 
 arch/powerpc/kvm/Makefile   |4 ++--
 arch/powerpc/kvm/booke.c|2 +-
 arch/powerpc/kvm/e500.h |6 +++---
 arch/powerpc/kvm/e500_tlb.c |2 +-
 arch/powerpc/kvm/powerpc.c  |8 
 6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 58f6e68..44a998d 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -109,7 +109,7 @@ config KVM_440
 
 config KVM_EXIT_TIMING
bool Detailed exit timing
-   depends on KVM_440 || KVM_E500 || KVM_E500MC
+   depends on KVM_440 || KVM_E500V2 || KVM_E500MC
---help---
  Calculate elapsed time for every exit/enter cycle. A per-vcpu
  report is available in debugfs kvm/vm#_vcpu#_timing.
@@ -118,14 +118,14 @@ config KVM_EXIT_TIMING
 
  If unsure, say N.
 
-config KVM_E500
-   bool KVM support for PowerPC E500 processors
+config KVM_E500V2
+   bool KVM support for PowerPC E500v2 processors
depends on EXPERIMENTAL  E500
select KVM
select KVM_MMIO
---help---
  Support running unmodified E500 guest kernels in virtual machines on
- E500 host processors.
+ E500v2 host processors.
 
  This module provides access to the hardware capabilities through
  a character device node named /dev/kvm.
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index 62febd7..25225ae 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -36,7 +36,7 @@ kvm-e500-objs := \
e500.o \
e500_tlb.o \
e500_emulate.o
-kvm-objs-$(CONFIG_KVM_E500) := $(kvm-e500-objs)
+kvm-objs-$(CONFIG_KVM_E500V2) := $(kvm-e500-objs)
 
 kvm-e500mc-objs := \
$(common-objs-y) \
@@ -98,7 +98,7 @@ kvm-objs-$(CONFIG_KVM_BOOK3S_32) := $(kvm-book3s_32-objs)
 kvm-objs := $(kvm-objs-m) $(kvm-objs-y)
 
 obj-$(CONFIG_KVM_440) += kvm.o
-obj-$(CONFIG_KVM_E500) += kvm.o
+obj-$(CONFIG_KVM_E500V2) += kvm.o
 obj-$(CONFIG_KVM_E500MC) += kvm.o
 obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o
 obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index fcbe928..9fcc760 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -762,7 +762,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
gpa_t gpaddr;
gfn_t gfn;
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
if (!(vcpu-arch.shared-msr  MSR_PR) 
(eaddr  PAGE_MASK) == vcpu-arch.magic_page_ea) {
kvmppc_map_magic(vcpu);
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 3143085..7967f3f 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -39,7 +39,7 @@ struct tlbe_priv {
struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
 };
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
 struct vcpu_id_table;
 #endif
 
@@ -89,7 +89,7 @@ struct kvmppc_vcpu_e500 {
u64 *g2h_tlb1_map;
unsigned int *h2g_tlb1_rmap;
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
u32 pid[E500_PID_NUM];
 
/* vcpu id table */
@@ -136,7 +136,7 @@ void kvmppc_get_sregs_e500_tlb(struct kvm_vcpu *vcpu, 
struct kvm_sregs *sregs);
 int kvmppc_set_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
 
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
 unsigned int kvmppc_e500_get_sid(struct kvmppc_vcpu_e500 *vcpu_e500,
 unsigned int as, unsigned int gid,
 unsigned int pr, int avoid_recursion);
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index e232bb4..279e10a 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -156,7 +156,7 @@ static inline void write_host_tlbe(struct kvmppc_vcpu_e500 
*vcpu_e500,
}
 }
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
 void kvmppc_map_magic(struct kvm_vcpu *vcpu)
 {
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 58a084f..26c6a8d 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -74,7 +74,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
case HC_VENDOR_KVM | KVM_HC_FEATURES:
r = HC_EV_SUCCESS;
-#if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500)
+#if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
 #endif
@@ -230,7 +230,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case 

[PATCH 17/37] KVM: PPC: e500mc: implicitly set MSR_GS

2012-02-24 Thread Alexander Graf
When setting MSR for an e500mc guest, we implicitly always set MSR_GS
to make sure the guest is in guest state. Since we have this implicit
rule there, we don't need to explicitly pass MSR_GS to set_msr().

Remove all explicit setters of MSR_GS.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   11 +--
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 85bd5b8..fcbe928 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -280,7 +280,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
 unsigned int priority)
 {
int allowed = 0;
-   ulong uninitialized_var(msr_mask);
+   ulong msr_mask = 0;
bool update_esr = false, update_dear = false;
ulong crit_raw = vcpu-arch.shared-critical;
ulong crit_r1 = kvmppc_get_gpr(vcpu, 1);
@@ -322,20 +322,19 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_AP_UNAVAIL:
case BOOKE_IRQPRIO_ALIGNMENT:
allowed = 1;
-   msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
+   msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
break;
case BOOKE_IRQPRIO_CRITICAL:
case BOOKE_IRQPRIO_DBELL_CRIT:
allowed = vcpu-arch.shared-msr  MSR_CE;
allowed = allowed  !crit;
-   msr_mask = MSR_GS | MSR_ME;
+   msr_mask = MSR_ME;
int_class = INT_CLASS_CRIT;
break;
case BOOKE_IRQPRIO_MACHINE_CHECK:
allowed = vcpu-arch.shared-msr  MSR_ME;
allowed = allowed  !crit;
-   msr_mask = MSR_GS;
int_class = INT_CLASS_MC;
break;
case BOOKE_IRQPRIO_DECREMENTER:
@@ -346,13 +345,13 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_DBELL:
allowed = vcpu-arch.shared-msr  MSR_EE;
allowed = allowed  !crit;
-   msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
+   msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
break;
case BOOKE_IRQPRIO_DEBUG:
allowed = vcpu-arch.shared-msr  MSR_DE;
allowed = allowed  !crit;
-   msr_mask = MSR_GS | MSR_ME;
+   msr_mask = MSR_ME;
int_class = INT_CLASS_CRIT;
break;
}
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/37] KVM: PPC: e500mc support

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Add processor support for e500mc, using hardware virtualization support
(GS-mode).

Current issues include:
 - No support for external proxy (coreint) interrupt mode in the guest.

Includes work by Ashish Kalra ashish.ka...@freescale.com,
Varun Sethi varun.se...@freescale.com, and
Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/cputable.h   |6 +-
 arch/powerpc/include/asm/kvm.h|1 +
 arch/powerpc/kernel/cpu_setup_fsl_booke.S |1 +
 arch/powerpc/kernel/head_fsl_booke.S  |   46 
 arch/powerpc/kvm/Kconfig  |   17 ++-
 arch/powerpc/kvm/Makefile |   11 +
 arch/powerpc/kvm/e500.h   |   13 +-
 arch/powerpc/kvm/e500_emulate.c   |   24 ++-
 arch/powerpc/kvm/e500_tlb.c   |   21 ++-
 arch/powerpc/kvm/e500mc.c |  342 +
 arch/powerpc/kvm/powerpc.c|6 +-
 11 files changed, 476 insertions(+), 12 deletions(-)
 create mode 100644 arch/powerpc/kvm/e500mc.c

diff --git a/arch/powerpc/include/asm/cputable.h 
b/arch/powerpc/include/asm/cputable.h
index 2022f2d..598cd24 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -168,6 +168,7 @@ extern const char *powerpc_base_platform;
 #define CPU_FTR_LWSYNC ASM_CONST(0x0800)
 #define CPU_FTR_NOEXECUTE  ASM_CONST(0x1000)
 #define CPU_FTR_INDEXED_DCRASM_CONST(0x2000)
+#define CPU_FTR_EMB_HV ASM_CONST(0x4000)
 
 /*
  * Add the 64-bit processor unique features in the top half of the word;
@@ -386,11 +387,11 @@ extern const char *powerpc_base_platform;
CPU_FTR_NODSISRALIGN | CPU_FTR_NOEXECUTE)
 #define CPU_FTRS_E500MC(CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
-   CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC)
+   CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC | CPU_FTR_EMB_HV)
 #define CPU_FTRS_E5500 (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
CPU_FTR_DBELL | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
-   CPU_FTR_DEBUG_LVL_EXC)
+   CPU_FTR_DEBUG_LVL_EXC | CPU_FTR_EMB_HV)
 #define CPU_FTRS_GENERIC_32(CPU_FTR_COMMON | CPU_FTR_NODSISRALIGN)
 
 /* 64-bit CPUs */
@@ -535,6 +536,7 @@ enum {
 #ifdef CONFIG_PPC_E500MC
CPU_FTRS_E500MC  CPU_FTRS_E5500 
 #endif
+   ~CPU_FTR_EMB_HV/* can be removed at runtime */
CPU_FTRS_POSSIBLE,
 };
 #endif /* __powerpc64__ */
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index b921c3f..1bea4d8 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -277,6 +277,7 @@ struct kvm_sync_regs {
 #define KVM_CPU_E500V2 2
 #define KVM_CPU_3S_32  3
 #define KVM_CPU_3S_64  4
+#define KVM_CPU_E500MC 5
 
 /* for KVM_CAP_SPAPR_TCE */
 struct kvm_create_spapr_tce {
diff --git a/arch/powerpc/kernel/cpu_setup_fsl_booke.S 
b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
index 8053db0..69fdd23 100644
--- a/arch/powerpc/kernel/cpu_setup_fsl_booke.S
+++ b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
@@ -73,6 +73,7 @@ _GLOBAL(__setup_cpu_e500v2)
mtlrr4
blr
 _GLOBAL(__setup_cpu_e500mc)
+   mr  r5, r4
mflrr4
bl  __e500_icache_setup
bl  __e500_dcache_setup
diff --git a/arch/powerpc/kernel/head_fsl_booke.S 
b/arch/powerpc/kernel/head_fsl_booke.S
index 418931f..88c0a35 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -380,10 +380,16 @@ interrupt_base:
mtspr   SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
mfspr   r10, SPRN_SPRG_THREAD
stw r11, THREAD_NORMSAVE(0)(r10)
+#ifdef CONFIG_KVM_BOOKE_HV
+BEGIN_FTR_SECTION
+   mfspr   r11, SPRN_SRR1
+END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
+#endif
stw r12, THREAD_NORMSAVE(1)(r10)
stw r13, THREAD_NORMSAVE(2)(r10)
mfcrr13
stw r13, THREAD_NORMSAVE(3)(r10)
+   DO_KVM  BOOKE_INTERRUPT_DTLB_MISS SPRN_SRR1
mfspr   r10, SPRN_DEAR  /* Get faulting address */
 
/* If we are faulting a kernel address, we have to use the
@@ -468,10 +474,16 @@ interrupt_base:
mtspr   SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
mfspr   r10, SPRN_SPRG_THREAD
stw r11, THREAD_NORMSAVE(0)(r10)
+#ifdef CONFIG_KVM_BOOKE_HV
+BEGIN_FTR_SECTION
+   mfspr   r11, SPRN_SRR1
+END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
+#endif
stw r12, THREAD_NORMSAVE(1)(r10)
stw r13, THREAD_NORMSAVE(2)(r10)
mfcrr13
stw r13, THREAD_NORMSAVE(3)(r10)
+

[PATCH 13/37] KVM: PPC: booke: category E.HV (GS-mode) support

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Chips such as e500mc that implement category E.HV in Power ISA 2.06
provide hardware virtualization features, including a new MSR mode for
guest state.  The guest OS can perform many operations without trapping
into the hypervisor, including transitions to and from guest userspace.

Since we can use SRR1[GS] to reliably tell whether an exception came from
guest state, instead of messing around with IVPR, we use DO_KVM similarly
to book3s.

Current issues include:
 - Machine checks from guest state are not routed to the host handler.
 - The guest can cause a host oops by executing an emulated instruction
   in a page that lacks read permission.  Existing e500/4xx support has
   the same problem.

Includes work by Ashish Kalra ashish.ka...@freescale.com,
Varun Sethi varun.se...@freescale.com, and
Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
[agraf: remove pt_regs usage]
Signed-off-by: Alexander Graf ag...@suse.de

---

v1 - v2:

  - ESR - GESR
---
 arch/powerpc/include/asm/dbell.h|1 +
 arch/powerpc/include/asm/kvm_asm.h  |8 +
 arch/powerpc/include/asm/kvm_booke_hv_asm.h |   49 +++
 arch/powerpc/include/asm/kvm_host.h |   19 +-
 arch/powerpc/include/asm/kvm_ppc.h  |3 +
 arch/powerpc/include/asm/mmu-book3e.h   |6 +
 arch/powerpc/include/asm/processor.h|3 +
 arch/powerpc/include/asm/reg.h  |2 +
 arch/powerpc/include/asm/reg_booke.h|   34 ++
 arch/powerpc/kernel/asm-offsets.c   |   15 +-
 arch/powerpc/kernel/head_booke.h|   28 ++-
 arch/powerpc/kvm/Kconfig|3 +
 arch/powerpc/kvm/booke.c|  309 ---
 arch/powerpc/kvm/booke.h|   24 +-
 arch/powerpc/kvm/booke_emulate.c|   23 +-
 arch/powerpc/kvm/bookehv_interrupts.S   |  587 +++
 arch/powerpc/kvm/powerpc.c  |5 +
 arch/powerpc/kvm/timing.h   |6 +
 18 files changed, 1058 insertions(+), 67 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_booke_hv_asm.h
 create mode 100644 arch/powerpc/kvm/bookehv_interrupts.S

diff --git a/arch/powerpc/include/asm/dbell.h b/arch/powerpc/include/asm/dbell.h
index efa74ac..d7365b0 100644
--- a/arch/powerpc/include/asm/dbell.h
+++ b/arch/powerpc/include/asm/dbell.h
@@ -19,6 +19,7 @@
 
 #define PPC_DBELL_MSG_BRDCAST  (0x0400)
 #define PPC_DBELL_TYPE(x)  (((x)  0xf)  (63-36))
+#define PPC_DBELL_LPID(x)  ((x)  (63 - 49))
 enum ppc_dbell {
PPC_DBELL = 0,  /* doorbell */
PPC_DBELL_CRIT = 1, /* critical doorbell */
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 7b1f0e0..0978152 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -48,6 +48,14 @@
 #define BOOKE_INTERRUPT_SPE_FP_DATA 33
 #define BOOKE_INTERRUPT_SPE_FP_ROUND 34
 #define BOOKE_INTERRUPT_PERFORMANCE_MONITOR 35
+#define BOOKE_INTERRUPT_DOORBELL 36
+#define BOOKE_INTERRUPT_DOORBELL_CRITICAL 37
+
+/* booke_hv */
+#define BOOKE_INTERRUPT_GUEST_DBELL 38
+#define BOOKE_INTERRUPT_GUEST_DBELL_CRIT 39
+#define BOOKE_INTERRUPT_HV_SYSCALL 40
+#define BOOKE_INTERRUPT_HV_PRIV 41
 
 /* book3s */
 
diff --git a/arch/powerpc/include/asm/kvm_booke_hv_asm.h 
b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
new file mode 100644
index 000..30a600f
--- /dev/null
+++ b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010-2011 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef ASM_KVM_BOOKE_HV_ASM_H
+#define ASM_KVM_BOOKE_HV_ASM_H
+
+#ifdef __ASSEMBLY__
+
+/*
+ * All exceptions from guest state must go through KVM
+ * (except for those which are delivered directly to the guest) --
+ * there are no exceptions for which we fall through directly to
+ * the normal host handler.
+ *
+ * Expected inputs (normal exceptions):
+ *   SCRATCH0 = saved r10
+ *   r10 = thread struct
+ *   r11 = appropriate SRR1 variant (currently used as scratch)
+ *   r13 = saved CR
+ *   *(r10 + THREAD_NORMSAVE(0)) = saved r11
+ *   *(r10 + THREAD_NORMSAVE(2)) = saved r13
+ *
+ * Expected inputs (crit/mcheck/debug exceptions):
+ *   appropriate SCRATCH = saved r8
+ *   r8 = exception level stack frame
+ *   r9 = *(r8 + _CCR) = saved CR
+ *   r11 = appropriate SRR1 variant (currently used as scratch)
+ *   *(r8 + GPR9) = saved r9
+ *   *(r8 + GPR10) = saved r10 (r10 not yet clobbered)
+ *   *(r8 + GPR11) = saved r11
+ */
+.macro DO_KVM intno srr1
+#ifdef CONFIG_KVM_BOOKE_HV
+BEGIN_FTR_SECTION
+   mtocrf  0x80, r11   /* check MSR[GS] without clobbering reg */
+   bf  3, kvmppc_resume_\intno\()_\srr1
+   b   

[PATCH 12/37] powerpc/booke: Provide exception macros with interrupt name

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

DO_KVM will need to identify the particular exception type.

There is an existing set of arbitrary numbers that Linux passes,
but it's an undocumented mess that sort of corresponds to server/classic
exception vectors but not really.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kernel/head_44x.S   |   23 +--
 arch/powerpc/kernel/head_booke.h |   41 ++
 arch/powerpc/kernel/head_fsl_booke.S |   52 +-
 3 files changed, 68 insertions(+), 48 deletions(-)

diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
index 7dd2981..d1192c5 100644
--- a/arch/powerpc/kernel/head_44x.S
+++ b/arch/powerpc/kernel/head_44x.S
@@ -248,10 +248,11 @@ _ENTRY(_start);
 
 interrupt_base:
/* Critical Input Interrupt */
-   CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception)
+   CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)
 
/* Machine Check Interrupt */
-   CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
+   CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \
+  machine_check_exception)
MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception)
 
/* Data Storage Interrupt */
@@ -261,7 +262,8 @@ interrupt_base:
INSTRUCTION_STORAGE_EXCEPTION
 
/* External Input Interrupt */
-   EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
+   EXCEPTION(0x0500, BOOKE_INTERRUPT_EXTERNAL, ExternalInput, \
+ do_IRQ, EXC_XFER_LITE)
 
/* Alignment Interrupt */
ALIGNMENT_EXCEPTION
@@ -273,29 +275,32 @@ interrupt_base:
 #ifdef CONFIG_PPC_FPU
FP_UNAVAILABLE_EXCEPTION
 #else
-   EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, 
EXC_XFER_EE)
+   EXCEPTION(0x2010, BOOKE_INTERRUPT_FP_UNAVAIL, \
+ FloatingPointUnavailable, unknown_exception, EXC_XFER_EE)
 #endif
/* System Call Interrupt */
START_EXCEPTION(SystemCall)
-   NORMAL_EXCEPTION_PROLOG
+   NORMAL_EXCEPTION_PROLOG(BOOKE_INTERRUPT_SYSCALL)
EXC_XFER_EE_LITE(0x0c00, DoSyscall)
 
/* Auxiliary Processor Unavailable Interrupt */
-   EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, 
EXC_XFER_EE)
+   EXCEPTION(0x2020, BOOKE_INTERRUPT_AP_UNAVAIL, \
+ AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE)
 
/* Decrementer Interrupt */
DECREMENTER_EXCEPTION
 
/* Fixed Internal Timer Interrupt */
/* TODO: Add FIT support */
-   EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE)
+   EXCEPTION(0x1010, BOOKE_INTERRUPT_FIT, FixedIntervalTimer, \
+ unknown_exception, EXC_XFER_EE)
 
/* Watchdog Timer Interrupt */
/* TODO: Add watchdog support */
 #ifdef CONFIG_BOOKE_WDT
-   CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException)
+   CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, WatchdogException)
 #else
-   CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception)
+   CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, unknown_exception)
 #endif
 
/* Data TLB Error Interrupt */
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index fc921bf..06ab353 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -2,6 +2,8 @@
 #define __HEAD_BOOKE_H__
 
 #include asm/ptrace.h/* for STACK_FRAME_REGS_MARKER */
+#include asm/kvm_asm.h
+
 /*
  * Macros used for common Book-e exception handling
  */
@@ -28,7 +30,7 @@
  */
 #define THREAD_NORMSAVE(offset)(THREAD_NORMSAVES + (offset * 4))
 
-#define NORMAL_EXCEPTION_PROLOG
 \
+#define NORMAL_EXCEPTION_PROLOG(intno) 
 \
mtspr   SPRN_SPRG_WSCRATCH0, r10;   /* save one register */  \
mfspr   r10, SPRN_SPRG_THREAD;   \
stw r11, THREAD_NORMSAVE(0)(r10);\
@@ -113,7 +115,7 @@
  * registers as the normal prolog above. Instead we use a portion of the
  * critical/machine check exception stack at low physical addresses.
  */
-#define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, exc_level_srr0, exc_level_srr1) \
+#define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, intno, exc_level_srr0, 
exc_level_srr1) \
mtspr   SPRN_SPRG_WSCRATCH_##exc_level,r8;   \
BOOKE_LOAD_EXC_LEVEL_STACK(exc_level);/* r8 points to the exc_level 
stack*/ \
stw r9,GPR9(r8);/* save various registers  */\
@@ -162,12 +164,13 @@
SAVE_4GPRS(3, r11);  \
SAVE_2GPRS(7, r11)
 

[PATCH 16/37] KVM: PPC: e500mc: Add doorbell emulation support

2012-02-24 Thread Alexander Graf
When one vcpu wants to kick another, it can issue a special IPI instruction
called msgsnd. This patch emulates this instruction, its clearing counterpart
and the infrastructure required to actually trigger that interrupt inside
a guest vcpu.

With this patch, SMP guests on e500mc work.

Signed-off-by: Alexander Graf ag...@suse.de

---

v1 - v2:

  - introduce and use constants
  - drop e500mc ifdefs
---
 arch/powerpc/include/asm/dbell.h |2 +
 arch/powerpc/kvm/booke.c |2 +
 arch/powerpc/kvm/e500_emulate.c  |   68 ++
 3 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/dbell.h b/arch/powerpc/include/asm/dbell.h
index d7365b0..154c067 100644
--- a/arch/powerpc/include/asm/dbell.h
+++ b/arch/powerpc/include/asm/dbell.h
@@ -19,7 +19,9 @@
 
 #define PPC_DBELL_MSG_BRDCAST  (0x0400)
 #define PPC_DBELL_TYPE(x)  (((x)  0xf)  (63-36))
+#define PPC_DBELL_TYPE_MASKPPC_DBELL_TYPE(0xf)
 #define PPC_DBELL_LPID(x)  ((x)  (63 - 49))
+#define PPC_DBELL_PIR_MASK 0x3fff
 enum ppc_dbell {
PPC_DBELL = 0,  /* doorbell */
PPC_DBELL_CRIT = 1, /* critical doorbell */
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 0b77be1..85bd5b8 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -326,6 +326,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
int_class = INT_CLASS_NONCRIT;
break;
case BOOKE_IRQPRIO_CRITICAL:
+   case BOOKE_IRQPRIO_DBELL_CRIT:
allowed = vcpu-arch.shared-msr  MSR_CE;
allowed = allowed  !crit;
msr_mask = MSR_GS | MSR_ME;
@@ -342,6 +343,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
keep_irq = true;
/* fall through */
case BOOKE_IRQPRIO_EXTERNAL:
+   case BOOKE_IRQPRIO_DBELL:
allowed = vcpu-arch.shared-msr  MSR_EE;
allowed = allowed  !crit;
msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 98b6c1c..99155f8 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -14,16 +14,74 @@
 
 #include asm/kvm_ppc.h
 #include asm/disassemble.h
+#include asm/dbell.h
 
 #include booke.h
 #include e500.h
 
+#define XOP_MSGSND  206
+#define XOP_MSGCLR  238
 #define XOP_TLBIVAX 786
 #define XOP_TLBSX   914
 #define XOP_TLBRE   946
 #define XOP_TLBWE   978
 #define XOP_TLBILX  18
 
+#ifdef CONFIG_KVM_E500MC
+static int dbell2prio(ulong param)
+{
+   int msg = param  PPC_DBELL_TYPE_MASK;
+   int prio = -1;
+
+   switch (msg) {
+   case PPC_DBELL_TYPE(PPC_DBELL):
+   prio = BOOKE_IRQPRIO_DBELL;
+   break;
+   case PPC_DBELL_TYPE(PPC_DBELL_CRIT):
+   prio = BOOKE_IRQPRIO_DBELL_CRIT;
+   break;
+   default:
+   break;
+   }
+
+   return prio;
+}
+
+static int kvmppc_e500_emul_msgclr(struct kvm_vcpu *vcpu, int rb)
+{
+   ulong param = vcpu-arch.gpr[rb];
+   int prio = dbell2prio(param);
+
+   if (prio  0)
+   return EMULATE_FAIL;
+
+   clear_bit(prio, vcpu-arch.pending_exceptions);
+   return EMULATE_DONE;
+}
+
+static int kvmppc_e500_emul_msgsnd(struct kvm_vcpu *vcpu, int rb)
+{
+   ulong param = vcpu-arch.gpr[rb];
+   int prio = dbell2prio(rb);
+   int pir = param  PPC_DBELL_PIR_MASK;
+   int i;
+   struct kvm_vcpu *cvcpu;
+
+   if (prio  0)
+   return EMULATE_FAIL;
+
+   kvm_for_each_vcpu(i, cvcpu, vcpu-kvm) {
+   int cpir = cvcpu-arch.shared-pir;
+   if ((param  PPC_DBELL_MSG_BRDCAST) || (cpir == pir)) {
+   set_bit(prio, cvcpu-arch.pending_exceptions);
+   kvm_vcpu_kick(cvcpu);
+   }
+   }
+
+   return EMULATE_DONE;
+}
+#endif
+
 int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int inst, int *advance)
 {
@@ -36,6 +94,16 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
case 31:
switch (get_xop(inst)) {
 
+#ifdef CONFIG_KVM_E500MC
+   case XOP_MSGSND:
+   emulated = kvmppc_e500_emul_msgsnd(vcpu, get_rb(inst));
+   break;
+
+   case XOP_MSGCLR:
+   emulated = kvmppc_e500_emul_msgclr(vcpu, get_rb(inst));
+   break;
+#endif
+
case XOP_TLBRE:
emulated = kvmppc_e500_emul_tlbre(vcpu);
break;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/37] KVM: PPC: e500: refactor core-specific TLB code

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

The PID handling is e500v1/v2-specific, and is moved to e500.c.

The MMU sregs code and kvmppc_core_vcpu_translate will be shared with
e500mc, and is moved from e500.c to e500_tlb.c.

Partially based on patches from Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
[agraf: fix bisectability]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/kvm/e500.c |  357 +++
 arch/powerpc/kvm/e500.h |   62 -
 arch/powerpc/kvm/e500_emulate.c |6 +-
 arch/powerpc/kvm/e500_tlb.c |  460 +--
 5 files changed, 473 insertions(+), 414 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 52eb9c1..47612cc 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -426,6 +426,8 @@ struct kvm_vcpu_arch {
ulong fault_esr;
ulong queued_dear;
ulong queued_esr;
+   u32 tlbcfg[4];
+   u32 mmucfg;
 #endif
gpa_t paddr_accessed;
 
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index 76b35d8..b479ed7 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -22,9 +22,281 @@
 #include asm/tlbflush.h
 #include asm/kvm_ppc.h
 
+#include ../mm/mmu_decl.h
 #include booke.h
 #include e500.h
 
+struct id {
+   unsigned long val;
+   struct id **pentry;
+};
+
+#define NUM_TIDS 256
+
+/*
+ * This table provide mappings from:
+ * (guestAS,guestTID,guestPR) -- ID of physical cpu
+ * guestAS [0..1]
+ * guestTID[0..255]
+ * guestPR [0..1]
+ * ID  [1..255]
+ * Each vcpu keeps one vcpu_id_table.
+ */
+struct vcpu_id_table {
+   struct id id[2][NUM_TIDS][2];
+};
+
+/*
+ * This table provide reversed mappings of vcpu_id_table:
+ * ID -- address of vcpu_id_table item.
+ * Each physical core has one pcpu_id_table.
+ */
+struct pcpu_id_table {
+   struct id *entry[NUM_TIDS];
+};
+
+static DEFINE_PER_CPU(struct pcpu_id_table, pcpu_sids);
+
+/* This variable keeps last used shadow ID on local core.
+ * The valid range of shadow ID is [1..255] */
+static DEFINE_PER_CPU(unsigned long, pcpu_last_used_sid);
+
+/*
+ * Allocate a free shadow id and setup a valid sid mapping in given entry.
+ * A mapping is only valid when vcpu_id_table and pcpu_id_table are match.
+ *
+ * The caller must have preemption disabled, and keep it that way until
+ * it has finished with the returned shadow id (either written into the
+ * TLB or arch.shadow_pid, or discarded).
+ */
+static inline int local_sid_setup_one(struct id *entry)
+{
+   unsigned long sid;
+   int ret = -1;
+
+   sid = ++(__get_cpu_var(pcpu_last_used_sid));
+   if (sid  NUM_TIDS) {
+   __get_cpu_var(pcpu_sids).entry[sid] = entry;
+   entry-val = sid;
+   entry-pentry = __get_cpu_var(pcpu_sids).entry[sid];
+   ret = sid;
+   }
+
+   /*
+* If sid == NUM_TIDS, we've run out of sids.  We return -1, and
+* the caller will invalidate everything and start over.
+*
+* sid  NUM_TIDS indicates a race, which we disable preemption to
+* avoid.
+*/
+   WARN_ON(sid  NUM_TIDS);
+
+   return ret;
+}
+
+/*
+ * Check if given entry contain a valid shadow id mapping.
+ * An ID mapping is considered valid only if
+ * both vcpu and pcpu know this mapping.
+ *
+ * The caller must have preemption disabled, and keep it that way until
+ * it has finished with the returned shadow id (either written into the
+ * TLB or arch.shadow_pid, or discarded).
+ */
+static inline int local_sid_lookup(struct id *entry)
+{
+   if (entry  entry-val != 0 
+   __get_cpu_var(pcpu_sids).entry[entry-val] == entry 
+   entry-pentry == __get_cpu_var(pcpu_sids).entry[entry-val])
+   return entry-val;
+   return -1;
+}
+
+/* Invalidate all id mappings on local core -- call with preempt disabled */
+static inline void local_sid_destroy_all(void)
+{
+   __get_cpu_var(pcpu_last_used_sid) = 0;
+   memset(__get_cpu_var(pcpu_sids), 0, sizeof(__get_cpu_var(pcpu_sids)));
+}
+
+static void *kvmppc_e500_id_table_alloc(struct kvmppc_vcpu_e500 *vcpu_e500)
+{
+   vcpu_e500-idt = kzalloc(sizeof(struct vcpu_id_table), GFP_KERNEL);
+   return vcpu_e500-idt;
+}
+
+static void kvmppc_e500_id_table_free(struct kvmppc_vcpu_e500 *vcpu_e500)
+{
+   kfree(vcpu_e500-idt);
+   vcpu_e500-idt = NULL;
+}
+
+/* Map guest pid to shadow.
+ * We use PID to keep shadow of current guest non-zero PID,
+ * and use PID1 to keep shadow of guest zero PID.
+ * So that guest tlbe with TID=0 can be accessed at any time */
+static void kvmppc_e500_recalc_shadow_pid(struct kvmppc_vcpu_e500 *vcpu_e500)
+{
+   preempt_disable();
+   vcpu_e500-vcpu.arch.shadow_pid = kvmppc_e500_get_sid(vcpu_e500,
+  

[PATCH 11/37] KVM: PPC: e500: emulate tlbilx

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

tlbilx is the new, preferred invalidation instruction.  It is not
found on e500 prior to e500mc, but there should be no harm in
supporting it on all e500.

Based on code from Ashish Kalra ashish.ka...@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.h |1 +
 arch/powerpc/kvm/e500_emulate.c |9 ++
 arch/powerpc/kvm/e500_tlb.c |   52 +++
 3 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index f4dee55..ce3f163 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -124,6 +124,7 @@ int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 
*vcpu_e500,
 int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu);
 int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu);
 int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb);
+int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int rt, int ra, int rb);
 int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb);
 int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500);
 void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500);
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index c80794d..af02c18 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -22,6 +22,7 @@
 #define XOP_TLBSX   914
 #define XOP_TLBRE   946
 #define XOP_TLBWE   978
+#define XOP_TLBILX  18
 
 int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int inst, int *advance)
@@ -29,6 +30,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
int emulated = EMULATE_DONE;
int ra;
int rb;
+   int rt;
 
switch (get_op(inst)) {
case 31:
@@ -47,6 +49,13 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
emulated = kvmppc_e500_emul_tlbsx(vcpu,rb);
break;
 
+   case XOP_TLBILX:
+   ra = get_ra(inst);
+   rb = get_rb(inst);
+   rt = get_rt(inst);
+   emulated = kvmppc_e500_emul_tlbilx(vcpu, rt, ra, rb);
+   break;
+
case XOP_TLBIVAX:
ra = get_ra(inst);
rb = get_rb(inst);
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index c8ce51d..6eb5d65 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -631,6 +631,58 @@ int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int 
ra, int rb)
return EMULATE_DONE;
 }
 
+static void tlbilx_all(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel,
+  int pid, int rt)
+{
+   struct kvm_book3e_206_tlb_entry *tlbe;
+   int tid, esel;
+
+   /* invalidate all entries */
+   for (esel = 0; esel  vcpu_e500-gtlb_params[tlbsel].entries; esel++) {
+   tlbe = get_entry(vcpu_e500, tlbsel, esel);
+   tid = get_tlb_tid(tlbe);
+   if (rt == 0 || tid == pid) {
+   inval_gtlbe_on_host(vcpu_e500, tlbsel, esel);
+   kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
+   }
+   }
+}
+
+static void tlbilx_one(struct kvmppc_vcpu_e500 *vcpu_e500, int pid,
+  int ra, int rb)
+{
+   int tlbsel, esel;
+   gva_t ea;
+
+   ea = kvmppc_get_gpr(vcpu_e500-vcpu, rb);
+   if (ra)
+   ea += kvmppc_get_gpr(vcpu_e500-vcpu, ra);
+
+   for (tlbsel = 0; tlbsel  2; tlbsel++) {
+   esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, -1);
+   if (esel = 0) {
+   inval_gtlbe_on_host(vcpu_e500, tlbsel, esel);
+   kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
+   break;
+   }
+   }
+}
+
+int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int rt, int ra, int rb)
+{
+   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+   int pid = get_cur_spid(vcpu);
+
+   if (rt == 0 || rt == 1) {
+   tlbilx_all(vcpu_e500, 0, pid, rt);
+   tlbilx_all(vcpu_e500, 1, pid, rt);
+   } else if (rt == 3) {
+   tlbilx_one(vcpu_e500, pid, ra, rb);
+   }
+
+   return EMULATE_DONE;
+}
+
 int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu)
 {
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/37] KVM: PPC: booke: Move vm core init/destroy out of booke.c

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

e500mc will want to do lpid allocation/deallocation here.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/44x.c   |9 +
 arch/powerpc/kvm/booke.c |9 -
 arch/powerpc/kvm/e500.c  |9 +
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
index 879a1a7..50e7dbc 100644
--- a/arch/powerpc/kvm/44x.c
+++ b/arch/powerpc/kvm/44x.c
@@ -163,6 +163,15 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
kmem_cache_free(kvm_vcpu_cache, vcpu_44x);
 }
 
+int kvmppc_core_init_vm(struct kvm *kvm)
+{
+   return 0;
+}
+
+void kvmppc_core_destroy_vm(struct kvm *kvm)
+{
+}
+
 static int __init kvmppc_44x_init(void)
 {
int r;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index a2456c7..2ee9bae 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -932,15 +932,6 @@ void kvmppc_core_commit_memory_region(struct kvm *kvm,
 {
 }
 
-int kvmppc_core_init_vm(struct kvm *kvm)
-{
-   return 0;
-}
-
-void kvmppc_core_destroy_vm(struct kvm *kvm)
-{
-}
-
 void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr)
 {
vcpu-arch.tcr = new_tcr;
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index 2d5fe04..ac6c9ae 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -226,6 +226,15 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
 }
 
+int kvmppc_core_init_vm(struct kvm *kvm)
+{
+   return 0;
+}
+
+void kvmppc_core_destroy_vm(struct kvm *kvm)
+{
+}
+
 static int __init kvmppc_e500_init(void)
 {
int r, i;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/37] KVM: PPC: e500: Track TLB1 entries with a bitmap

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Rather than invalidate everything when a TLB1 entry needs to be
taken down, keep track of which host TLB1 entries are used for
a given guest TLB1 entry, and invalidate just those entries.

Based on code from Ashish Kalra ashish.ka...@freescale.com
and Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.h |5 +++
 arch/powerpc/kvm/e500_tlb.c |   72 ---
 2 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 34cef08..f4dee55 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -2,6 +2,7 @@
  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu yu@freescale.com
+ * Ashish Kalra ashish.ka...@freescale.com
  *
  * Description:
  * This file is based on arch/powerpc/kvm/44x_tlb.h and
@@ -25,6 +26,7 @@
 
 #define E500_TLB_VALID 1
 #define E500_TLB_DIRTY 2
+#define E500_TLB_BITMAP 4
 
 struct tlbe_ref {
pfn_t pfn;
@@ -82,6 +84,9 @@ struct kvmppc_vcpu_e500 {
struct page **shared_tlb_pages;
int num_shared_tlb_pages;
 
+   u64 *g2h_tlb1_map;
+   unsigned int *h2g_tlb1_rmap;
+
 #ifdef CONFIG_KVM_E500
u32 pid[E500_PID_NUM];
 
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 9925fc6..c8ce51d 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu, yu@freescale.com
+ * Ashish Kalra, ashish.ka...@freescale.com
  *
  * Description:
  * This file is based on arch/powerpc/kvm/44x_tlb.c,
@@ -175,8 +176,28 @@ static void inval_gtlbe_on_host(struct kvmppc_vcpu_e500 
*vcpu_e500,
struct kvm_book3e_206_tlb_entry *gtlbe =
get_entry(vcpu_e500, tlbsel, esel);
 
-   if (tlbsel == 1) {
-   kvmppc_e500_tlbil_all(vcpu_e500);
+   if (tlbsel == 1 
+   vcpu_e500-gtlb_priv[1][esel].ref.flags  E500_TLB_BITMAP) {
+   u64 tmp = vcpu_e500-g2h_tlb1_map[esel];
+   int hw_tlb_indx;
+   unsigned long flags;
+
+   local_irq_save(flags);
+   while (tmp) {
+   hw_tlb_indx = __ilog2_u64(tmp  -tmp);
+   mtspr(SPRN_MAS0,
+ MAS0_TLBSEL(1) |
+ MAS0_ESEL(to_htlb1_esel(hw_tlb_indx)));
+   mtspr(SPRN_MAS1, 0);
+   asm volatile(tlbwe);
+   vcpu_e500-h2g_tlb1_rmap[hw_tlb_indx] = 0;
+   tmp = tmp - 1;
+   }
+   mb();
+   vcpu_e500-g2h_tlb1_map[esel] = 0;
+   vcpu_e500-gtlb_priv[1][esel].ref.flags = ~E500_TLB_BITMAP;
+   local_irq_restore(flags);
+
return;
}
 
@@ -282,6 +303,16 @@ static inline void kvmppc_e500_ref_release(struct tlbe_ref 
*ref)
}
 }
 
+static void clear_tlb1_bitmap(struct kvmppc_vcpu_e500 *vcpu_e500)
+{
+   if (vcpu_e500-g2h_tlb1_map)
+   memset(vcpu_e500-g2h_tlb1_map,
+  sizeof(u64) * vcpu_e500-gtlb_params[1].entries, 0);
+   if (vcpu_e500-h2g_tlb1_rmap)
+   memset(vcpu_e500-h2g_tlb1_rmap,
+  sizeof(unsigned int) * host_tlb_params[1].entries, 0);
+}
+
 static void clear_tlb_privs(struct kvmppc_vcpu_e500 *vcpu_e500)
 {
int tlbsel = 0;
@@ -511,7 +542,7 @@ static void kvmppc_e500_tlb0_map(struct kvmppc_vcpu_e500 
*vcpu_e500,
 /* XXX for both one-one and one-to-many , for now use TLB1 */
 static int kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 *vcpu_e500,
u64 gvaddr, gfn_t gfn, struct kvm_book3e_206_tlb_entry *gtlbe,
-   struct kvm_book3e_206_tlb_entry *stlbe)
+   struct kvm_book3e_206_tlb_entry *stlbe, int esel)
 {
struct tlbe_ref *ref;
unsigned int victim;
@@ -524,6 +555,14 @@ static int kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 
*vcpu_e500,
ref = vcpu_e500-tlb_refs[1][victim];
kvmppc_e500_shadow_map(vcpu_e500, gvaddr, gfn, gtlbe, 1, stlbe, ref);
 
+   vcpu_e500-g2h_tlb1_map[esel] |= (u64)1  victim;
+   vcpu_e500-gtlb_priv[1][esel].ref.flags |= E500_TLB_BITMAP;
+   if (vcpu_e500-h2g_tlb1_rmap[victim]) {
+   unsigned int idx = vcpu_e500-h2g_tlb1_rmap[victim];
+   vcpu_e500-g2h_tlb1_map[idx] = ~(1ULL  victim);
+   }
+   vcpu_e500-h2g_tlb1_rmap[victim] = esel;
+
return victim;
 }
 
@@ -728,7 +767,7 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
 * are mapped on the fly. */
stlbsel = 1;
sesel = kvmppc_e500_tlb1_map(vcpu_e500, eaddr,
-  

[PATCH 07/37] KVM: PPC: e500: merge asm/kvm_e500.h into arch/powerpc/kvm/e500.h

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Keeping two separate headers for e500-specific things was a
pain, and wasn't even organized along any logical boundary.

There was TLB stuff in asm/kvm_e500.h despite the existence of
arch/powerpc/kvm/e500_tlb.h, and nothing in asm/kvm_e500.h needed
to be referenced from outside arch/powerpc/kvm.

Signed-off-by: Scott Wood scottw...@freescale.com
[agraf: fix bisectability]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_e500.h |   96 ---
 arch/powerpc/kvm/e500.c |1 -
 arch/powerpc/kvm/e500.h |   82 --
 arch/powerpc/kvm/e500_emulate.c |1 -
 arch/powerpc/kvm/e500_tlb.c |1 -
 5 files changed, 78 insertions(+), 103 deletions(-)
 delete mode 100644 arch/powerpc/include/asm/kvm_e500.h

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
deleted file mode 100644
index 8cd50a5..000
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
- *
- * Author: Yu Liu, yu@freescale.com
- *
- * Description:
- * This file is derived from arch/powerpc/include/asm/kvm_44x.h,
- * by Hollis Blanchard holl...@us.ibm.com.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_KVM_E500_H__
-#define __ASM_KVM_E500_H__
-
-#include linux/kvm_host.h
-
-#define BOOKE_INTERRUPT_SIZE 36
-
-#define E500_PID_NUM   3
-#define E500_TLB_NUM   2
-
-#define E500_TLB_VALID 1
-#define E500_TLB_DIRTY 2
-
-struct tlbe_ref {
-   pfn_t pfn;
-   unsigned int flags; /* E500_TLB_* */
-};
-
-struct tlbe_priv {
-   struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
-};
-
-struct vcpu_id_table;
-
-struct kvmppc_e500_tlb_params {
-   int entries, ways, sets;
-};
-
-struct kvmppc_vcpu_e500 {
-   /* Unmodified copy of the guest's TLB -- shared with host userspace. */
-   struct kvm_book3e_206_tlb_entry *gtlb_arch;
-
-   /* Starting entry number in gtlb_arch[] */
-   int gtlb_offset[E500_TLB_NUM];
-
-   /* KVM internal information associated with each guest TLB entry */
-   struct tlbe_priv *gtlb_priv[E500_TLB_NUM];
-
-   struct kvmppc_e500_tlb_params gtlb_params[E500_TLB_NUM];
-
-   unsigned int gtlb_nv[E500_TLB_NUM];
-
-   /*
-* information associated with each host TLB entry --
-* TLB1 only for now.  If/when guest TLB1 entries can be
-* mapped with host TLB0, this will be used for that too.
-*
-* We don't want to use this for guest TLB0 because then we'd
-* have the overhead of doing the translation again even if
-* the entry is still in the guest TLB (e.g. we swapped out
-* and back, and our host TLB entries got evicted).
-*/
-   struct tlbe_ref *tlb_refs[E500_TLB_NUM];
-   unsigned int host_tlb1_nv;
-
-   u32 host_pid[E500_PID_NUM];
-   u32 pid[E500_PID_NUM];
-   u32 svr;
-
-   /* vcpu id table */
-   struct vcpu_id_table *idt;
-
-   u32 l1csr0;
-   u32 l1csr1;
-   u32 hid0;
-   u32 hid1;
-   u32 tlb0cfg;
-   u32 tlb1cfg;
-   u64 mcar;
-
-   struct page **shared_tlb_pages;
-   int num_shared_tlb_pages;
-
-   struct kvm_vcpu vcpu;
-};
-
-static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
-{
-   return container_of(vcpu, struct kvmppc_vcpu_e500, vcpu);
-}
-
-#endif /* __ASM_KVM_E500_H__ */
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index 5c450ba..76b35d8 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -20,7 +20,6 @@
 #include asm/reg.h
 #include asm/cputable.h
 #include asm/tlbflush.h
-#include asm/kvm_e500.h
 #include asm/kvm_ppc.h
 
 #include booke.h
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 02ecde2..51d13bd 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -1,11 +1,12 @@
 /*
  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
- * Author: Yu Liu, yu@freescale.com
+ * Author: Yu Liu yu@freescale.com
  *
  * Description:
- * This file is based on arch/powerpc/kvm/44x_tlb.h,
- * by Hollis Blanchard holl...@us.ibm.com.
+ * This file is based on arch/powerpc/kvm/44x_tlb.h and
+ * arch/powerpc/include/asm/kvm_44x.h by Hollis Blanchard holl...@us.ibm.com,
+ * Copyright IBM Corp. 2007-2008
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2, as
@@ -18,7 +19,80 @@
 #include linux/kvm_host.h
 #include asm/mmu-book3e.h
 #include asm/tlb.h
-#include asm/kvm_e500.h
+
+#define E500_PID_NUM   3
+#define E500_TLB_NUM   2
+
+#define E500_TLB_VALID 1
+#define 

[PATCH 06/37] KVM: PPC: e500: rename e500_tlb.h to e500.h

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

This is in preparation for merging in the contents of
arch/powerpc/include/asm/kvm_e500.h.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.c |2 +-
 arch/powerpc/kvm/{e500_tlb.h = e500.h} |6 +++---
 arch/powerpc/kvm/e500_emulate.c |2 +-
 arch/powerpc/kvm/e500_tlb.c |2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
 rename arch/powerpc/kvm/{e500_tlb.h = e500.h} (98%)

diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index ac6c9ae..5c450ba 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -24,7 +24,7 @@
 #include asm/kvm_ppc.h
 
 #include booke.h
-#include e500_tlb.h
+#include e500.h
 
 void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
 {
diff --git a/arch/powerpc/kvm/e500_tlb.h b/arch/powerpc/kvm/e500.h
similarity index 98%
rename from arch/powerpc/kvm/e500_tlb.h
rename to arch/powerpc/kvm/e500.h
index 5c6d2d7..02ecde2 100644
--- a/arch/powerpc/kvm/e500_tlb.h
+++ b/arch/powerpc/kvm/e500.h
@@ -12,8 +12,8 @@
  * published by the Free Software Foundation.
  */
 
-#ifndef __KVM_E500_TLB_H__
-#define __KVM_E500_TLB_H__
+#ifndef KVM_E500_H
+#define KVM_E500_H
 
 #include linux/kvm_host.h
 #include asm/mmu-book3e.h
@@ -171,4 +171,4 @@ static inline int tlbe_is_host_safe(const struct kvm_vcpu 
*vcpu,
return 1;
 }
 
-#endif /* __KVM_E500_TLB_H__ */
+#endif /* KVM_E500_H */
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 6d0b2bd..2a1a228 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -17,7 +17,7 @@
 #include asm/kvm_e500.h
 
 #include booke.h
-#include e500_tlb.h
+#include e500.h
 
 #define XOP_TLBIVAX 786
 #define XOP_TLBSX   914
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 6e53e41..1d623a0 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -29,7 +29,7 @@
 #include asm/kvm_e500.h
 
 #include ../mm/mmu_decl.h
-#include e500_tlb.h
+#include e500.h
 #include trace.h
 #include timing.h
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/37] powerpc/e500: split CPU_FTRS_ALWAYS/CPU_FTRS_POSSIBLE

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Split e500 (v1/v2) and e500mc/e5500 to allow optimization of feature
checks that differ between the two.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/cputable.h |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/cputable.h 
b/arch/powerpc/include/asm/cputable.h
index 6a034a2..2022f2d 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -483,8 +483,10 @@ enum {
CPU_FTRS_E200 |
 #endif
 #ifdef CONFIG_E500
-   CPU_FTRS_E500 | CPU_FTRS_E500_2 | CPU_FTRS_E500MC |
-   CPU_FTRS_E5500 |
+   CPU_FTRS_E500 | CPU_FTRS_E500_2 |
+#endif
+#ifdef CONFIG_PPC_E500MC
+   CPU_FTRS_E500MC | CPU_FTRS_E5500 |
 #endif
0,
 };
@@ -528,8 +530,10 @@ enum {
CPU_FTRS_E200 
 #endif
 #ifdef CONFIG_E500
-   CPU_FTRS_E500  CPU_FTRS_E500_2  CPU_FTRS_E500MC 
-   CPU_FTRS_E5500 
+   CPU_FTRS_E500  CPU_FTRS_E500_2 
+#endif
+#ifdef CONFIG_PPC_E500MC
+   CPU_FTRS_E500MC  CPU_FTRS_E5500 
 #endif
CPU_FTRS_POSSIBLE,
 };
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/37] powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Currently 32-bit only cares about this for choice of exception
vector, which is done in core-specific code.  However, KVM will
want to distinguish as well.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/cputable.h |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/cputable.h 
b/arch/powerpc/include/asm/cputable.h
index ad55a1c..6a034a2 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -376,7 +376,8 @@ extern const char *powerpc_base_platform;
 #define CPU_FTRS_47X   (CPU_FTRS_440x6)
 #define CPU_FTRS_E200  (CPU_FTR_USE_TB | CPU_FTR_SPE_COMP | \
CPU_FTR_NODSISRALIGN | CPU_FTR_COHERENT_ICACHE | \
-   CPU_FTR_UNIFIED_ID_CACHE | CPU_FTR_NOEXECUTE)
+   CPU_FTR_UNIFIED_ID_CACHE | CPU_FTR_NOEXECUTE | \
+   CPU_FTR_DEBUG_LVL_EXC)
 #define CPU_FTRS_E500  (CPU_FTR_MAYBE_CAN_DOZE | CPU_FTR_USE_TB | \
CPU_FTR_SPE_COMP | CPU_FTR_MAYBE_CAN_NAP | CPU_FTR_NODSISRALIGN | \
CPU_FTR_NOEXECUTE)
@@ -385,7 +386,7 @@ extern const char *powerpc_base_platform;
CPU_FTR_NODSISRALIGN | CPU_FTR_NOEXECUTE)
 #define CPU_FTRS_E500MC(CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
-   CPU_FTR_DBELL)
+   CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC)
 #define CPU_FTRS_E5500 (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
CPU_FTR_DBELL | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/37] KVM: PPC: e500: clean up arch/powerpc/kvm/e500.h

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Move vcpu to the beginning of vcpu_e500 to give it appropriate
prominence, especially if more fields end up getting added to the
end of vcpu_e500 (and vcpu ends up in the middle).

Remove gratuitous extern and add parameter names to prototypes.

Signed-off-by: Scott Wood scottw...@freescale.com
[agraf: fix bisectability]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.h |   25 ++---
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 51d13bd..a48af00 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -42,6 +42,8 @@ struct kvmppc_e500_tlb_params {
 };
 
 struct kvmppc_vcpu_e500 {
+   struct kvm_vcpu vcpu;
+
/* Unmodified copy of the guest's TLB -- shared with host userspace. */
struct kvm_book3e_206_tlb_entry *gtlb_arch;
 
@@ -85,8 +87,6 @@ struct kvmppc_vcpu_e500 {
 
struct page **shared_tlb_pages;
int num_shared_tlb_pages;
-
-   struct kvm_vcpu vcpu;
 };
 
 static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
@@ -113,19 +113,22 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct 
kvm_vcpu *vcpu)
  (MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3 \
   | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)
 
-extern void kvmppc_dump_tlbs(struct kvm_vcpu *);
-extern int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *, ulong);
-extern int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *);
-extern int kvmppc_e500_emul_tlbre(struct kvm_vcpu *);
-extern int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *, int, int);
-extern int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *, int);
-extern int kvmppc_e500_tlb_search(struct kvm_vcpu *, gva_t, unsigned int, int);
 extern void kvmppc_e500_tlb_put(struct kvm_vcpu *);
 extern void kvmppc_e500_tlb_load(struct kvm_vcpu *, int);
-extern int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *);
-extern void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *);
 extern void kvmppc_e500_tlb_setup(struct kvmppc_vcpu_e500 *);
 extern void kvmppc_e500_recalc_shadow_pid(struct kvmppc_vcpu_e500 *);
+int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *vcpu_e500,
+   ulong value);
+int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu);
+int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu);
+int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb);
+int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb);
+int kvmppc_e500_tlb_search(struct kvm_vcpu *, gva_t, unsigned int, int);
+int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500);
+void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500);
+
+void kvmppc_get_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
+int kvmppc_set_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
 
 /* TLB helper functions */
 static inline unsigned int
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/37] KVM: PPC: e500mc support v2

2012-02-24 Thread Alexander Graf
This is Scott's e500mc RFC patch set rebased, berobbed of its pt_regs
parts and fixed for bisectability. On top of them, I addressed all the
comments that I had on the code and that came up in his code as FIXMEs.

I verified that this patch set works just fine on e500mc and doesn't
break e500v2, so I would say it's good to go as it is, unless someone
has strong objections to how things are done. Everything hereafter
I would prefer to do based on a working upstream version rather than
a downstream fork, as that way exposure is a lot higher.

v1 - v2:

  - ESR - GESR
  - introduce and use constants for doorbell
  - drop e500mc ifdefs for doorbell
  - fix whitespace
  - use explicit preempt counts in inst fixup
  - rework e500v2 kconfig patch
  - add patches 31-37

Alexander Graf (22):
  KVM: PPC: e500mc: Add doorbell emulation support
  KVM: PPC: e500mc: implicitly set MSR_GS
  KVM: PPC: e500mc: Move r1/r2 restoration very early
  KVM: PPC: e500mc: add load inst fixup
  KVM: PPC: rename CONFIG_KVM_E500 - CONFIG_KVM_E500V2
  KVM: PPC: make e500v2 kvm and e500mc cpu mutually exclusive
  KVM: PPC: booke: remove leftover debugging
  KVM: PPC: booke: deliver program int on emulation failure
  KVM: PPC: booke: rework rescheduling checks
  KVM: PPC: booke: BOOKE_IRQPRIO_MAX is n+1
  KVM: PPC: bookehv: fix exit timing
  KVM: PPC: bookehv: remove negation for CONFIG_64BIT
  KVM: PPC: bookehv: remove SET_VCPU
  KVM: PPC: bookehv: disable MAS register updates early
  KVM: PPC: bookehv: add comment about shadow_msr
  KVM: PPC: booke: Readd debug abort code for machine check
  KVM: PPC: booke: add GS documentation for program interrupt
  KVM: PPC: bookehv: remove unused code
  KVM: PPC: e500: fix typo in tlb code
  KVM: PPC: booke: Support perfmon interrupts
  KVM: PPC: booke: expose guest registers on irq reinject
  KVM: PPC: booke: Reinject performance monitor interrupts

Scott Wood (15):
  powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit
  powerpc/e500: split CPU_FTRS_ALWAYS/CPU_FTRS_POSSIBLE
  KVM: PPC: factor out lpid allocator from book3s_64_mmu_hv
  KVM: PPC: booke: add booke-level vcpu load/put
  KVM: PPC: booke: Move vm core init/destroy out of booke.c
  KVM: PPC: e500: rename e500_tlb.h to e500.h
  KVM: PPC: e500: merge asm/kvm_e500.h into arch/powerpc/kvm/e500.h
  KVM: PPC: e500: clean up arch/powerpc/kvm/e500.h
  KVM: PPC: e500: refactor core-specific TLB code
  KVM: PPC: e500: Track TLB1 entries with a bitmap
  KVM: PPC: e500: emulate tlbilx
  powerpc/booke: Provide exception macros with interrupt name
  KVM: PPC: booke: category E.HV (GS-mode) support
  KVM: PPC: booke: standard PPC floating point support
  KVM: PPC: e500mc support

 arch/powerpc/include/asm/cputable.h |   21 +-
 arch/powerpc/include/asm/dbell.h|3 +
 arch/powerpc/include/asm/hw_irq.h   |1 +
 arch/powerpc/include/asm/kvm.h  |1 +
 arch/powerpc/include/asm/kvm_asm.h  |8 +
 arch/powerpc/include/asm/kvm_book3s.h   |3 +
 arch/powerpc/include/asm/kvm_booke.h|3 +
 arch/powerpc/include/asm/kvm_booke_hv_asm.h |   49 +++
 arch/powerpc/include/asm/kvm_e500.h |   96 -
 arch/powerpc/include/asm/kvm_host.h |   22 +-
 arch/powerpc/include/asm/kvm_ppc.h  |   10 +-
 arch/powerpc/include/asm/mmu-book3e.h   |6 +
 arch/powerpc/include/asm/processor.h|3 +
 arch/powerpc/include/asm/reg.h  |2 +
 arch/powerpc/include/asm/reg_booke.h|   34 ++
 arch/powerpc/include/asm/system.h   |1 +
 arch/powerpc/kernel/asm-offsets.c   |   15 +-
 arch/powerpc/kernel/cpu_setup_fsl_booke.S   |1 +
 arch/powerpc/kernel/head_44x.S  |   23 +-
 arch/powerpc/kernel/head_booke.h|   69 ++-
 arch/powerpc/kernel/head_fsl_booke.S|   98 -
 arch/powerpc/kvm/44x.c  |   12 +
 arch/powerpc/kvm/Kconfig|   28 +-
 arch/powerpc/kvm/Makefile   |   15 +-
 arch/powerpc/kvm/book3s.c   |4 +-
 arch/powerpc/kvm/book3s_64_mmu_hv.c |   26 +-
 arch/powerpc/kvm/booke.c|  470 +
 arch/powerpc/kvm/booke.h|   57 +++-
 arch/powerpc/kvm/booke_emulate.c|   23 +-
 arch/powerpc/kvm/bookehv_interrupts.S   |  606 +++
 arch/powerpc/kvm/e500.c |  372 ++---
 arch/powerpc/kvm/e500.h |  302 +
 arch/powerpc/kvm/e500_emulate.c |  110 +-
 arch/powerpc/kvm/e500_tlb.c |  588 +++---
 arch/powerpc/kvm/e500_tlb.h |  174 
 arch/powerpc/kvm/e500mc.c   |  342 +++
 arch/powerpc/kvm/powerpc.c  |   47 ++-
 arch/powerpc/kvm/timing.h   |6 +
 38 files changed, 2797 insertions(+), 854 deletions(-)
 create mode 100644 

[PATCH 03/37] KVM: PPC: factor out lpid allocator from book3s_64_mmu_hv

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

We'll use it on e500mc as well.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_book3s.h |3 ++
 arch/powerpc/include/asm/kvm_booke.h  |3 ++
 arch/powerpc/include/asm/kvm_ppc.h|5 
 arch/powerpc/kvm/book3s_64_mmu_hv.c   |   26 +---
 arch/powerpc/kvm/powerpc.c|   34 +
 5 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index aa795cc..046041f 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -452,4 +452,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu 
*vcpu)
 
 #define INS_DCBZ   0x7c0007ec
 
+/* LPIDs we support with this build -- runtime limit may be lower */
+#define KVMPPC_NR_LPIDS(LPID_RSVD + 1)
+
 #endif /* __ASM_KVM_BOOK3S_H__ */
diff --git a/arch/powerpc/include/asm/kvm_booke.h 
b/arch/powerpc/include/asm/kvm_booke.h
index a90e091..b7cd335 100644
--- a/arch/powerpc/include/asm/kvm_booke.h
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -23,6 +23,9 @@
 #include linux/types.h
 #include linux/kvm_host.h
 
+/* LPIDs we support with this build -- runtime limit may be lower */
+#define KVMPPC_NR_LPIDS64
+
 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
 {
vcpu-arch.gpr[num] = val;
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 9d6dee0..731e920 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -204,4 +204,9 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
 struct kvm_dirty_tlb *cfg);
 
+long kvmppc_alloc_lpid(void);
+void kvmppc_claim_lpid(long lpid);
+void kvmppc_free_lpid(long lpid);
+void kvmppc_init_lpid(unsigned long nr_lpids);
+
 #endif /* __POWERPC_KVM_PPC_H__ */
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index ddc485a..d031ce1 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -36,13 +36,11 @@
 
 /* POWER7 has 10-bit LPIDs, PPC970 has 6-bit LPIDs */
 #define MAX_LPID_970   63
-#define NR_LPIDS   (LPID_RSVD + 1)
-unsigned long lpid_inuse[BITS_TO_LONGS(NR_LPIDS)];
 
 long kvmppc_alloc_hpt(struct kvm *kvm)
 {
unsigned long hpt;
-   unsigned long lpid;
+   long lpid;
struct revmap_entry *rev;
struct kvmppc_linear_info *li;
 
@@ -72,14 +70,9 @@ long kvmppc_alloc_hpt(struct kvm *kvm)
}
kvm-arch.revmap = rev;
 
-   /* Allocate the guest's logical partition ID */
-   do {
-   lpid = find_first_zero_bit(lpid_inuse, NR_LPIDS);
-   if (lpid = NR_LPIDS) {
-   pr_err(kvm_alloc_hpt: No LPIDs free\n);
-   goto out_freeboth;
-   }
-   } while (test_and_set_bit(lpid, lpid_inuse));
+   lpid = kvmppc_alloc_lpid();
+   if (lpid  0)
+   goto out_freeboth;
 
kvm-arch.sdr1 = __pa(hpt) | (HPT_ORDER - 18);
kvm-arch.lpid = lpid;
@@ -96,7 +89,7 @@ long kvmppc_alloc_hpt(struct kvm *kvm)
 
 void kvmppc_free_hpt(struct kvm *kvm)
 {
-   clear_bit(kvm-arch.lpid, lpid_inuse);
+   kvmppc_free_lpid(kvm-arch.lpid);
vfree(kvm-arch.revmap);
if (kvm-arch.hpt_li)
kvm_release_hpt(kvm-arch.hpt_li);
@@ -171,8 +164,7 @@ int kvmppc_mmu_hv_init(void)
if (!cpu_has_feature(CPU_FTR_HVMODE))
return -EINVAL;
 
-   memset(lpid_inuse, 0, sizeof(lpid_inuse));
-
+   /* POWER7 has 10-bit LPIDs, PPC970 and e500mc have 6-bit LPIDs */
if (cpu_has_feature(CPU_FTR_ARCH_206)) {
host_lpid = mfspr(SPRN_LPID);   /* POWER7 */
rsvd_lpid = LPID_RSVD;
@@ -181,9 +173,11 @@ int kvmppc_mmu_hv_init(void)
rsvd_lpid = MAX_LPID_970;
}
 
-   set_bit(host_lpid, lpid_inuse);
+   kvmppc_init_lpid(rsvd_lpid + 1);
+
+   kvmppc_claim_lpid(host_lpid);
/* rsvd_lpid is reserved for use in partition switching */
-   set_bit(rsvd_lpid, lpid_inuse);
+   kvmppc_claim_lpid(rsvd_lpid);
 
return 0;
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 00d7e34..9806ea5 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -808,6 +808,40 @@ out:
return r;
 }
 
+static unsigned long lpid_inuse[BITS_TO_LONGS(KVMPPC_NR_LPIDS)];
+static unsigned long nr_lpids;
+
+long kvmppc_alloc_lpid(void)
+{
+   long lpid;
+
+   do {
+   lpid = find_first_zero_bit(lpid_inuse, KVMPPC_NR_LPIDS);
+   if (lpid = nr_lpids) {
+   pr_err(%s: No LPIDs 

[RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Pekka Enberg
This patch adds a --bios command line option to vm run. You can use this to
try to boot with SeaBIOS, for example:

  ./vm run --bios=/usr/share/seabios/bios.bin \
 --disk $HOME/images/debian_lenny_amd64_standard.qcow2

This doesn't boot yet for obvious reasons but at least people can now start to
play with external BIOS images easily.

Cc: Yang Bai hamo...@gmail.com
Cc: Matt Evans m...@ozlabs.org
Cc: Ron Minnich rminn...@gmail.com
Cc: Anthony Liguori aligu...@us.ibm.com
Cc: John Floren j...@jfloren.net
Cc: Sasha Levin levinsasha...@gmail.com
Cc: Cyrill Gorcunov gorcu...@openvz.org
Cc: Asias He asias.he...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Signed-off-by: Pekka Enberg penb...@kernel.org
---
 tools/kvm/Makefile   |2 +
 tools/kvm/builtin-run.c  |   32 +++--
 tools/kvm/include/kvm/kvm.h  |1 +
 tools/kvm/powerpc/boot.c |8 +++
 tools/kvm/x86/boot.c |   41 ++
 tools/kvm/x86/include/kvm/bios.h |3 +-
 6 files changed, 75 insertions(+), 12 deletions(-)
 create mode 100644 tools/kvm/powerpc/boot.c
 create mode 100644 tools/kvm/x86/boot.c

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index cfa5547..0a9c2cc 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -113,6 +113,7 @@ LIBFDT_OBJS = $(patsubst 
%,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC))
 #x86
 ifeq ($(ARCH),x86)
DEFINES += -DCONFIG_X86
+   OBJS+= x86/boot.o
OBJS+= x86/cpuid.o
OBJS+= x86/interrupt.o
OBJS+= x86/ioport.o
@@ -129,6 +130,7 @@ endif
 # POWER/ppc:  Actually only support ppc64 currently.
 ifeq ($(uname_M), ppc64)
DEFINES += -DCONFIG_PPC
+   OBJS+= powerpc/boot.o
OBJS+= powerpc/ioport.o
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 466169e..f96c581 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -76,6 +76,7 @@ static const char *kernel_cmdline;
 static const char *kernel_filename;
 static const char *vmlinux_filename;
 static const char *initrd_filename;
+static const char *bios_filename;
 static const char *image_filename[MAX_DISK_IMAGES];
 static const char *console;
 static const char *dev;
@@ -458,6 +459,8 @@ static const struct option options[] = {
Initial RAM disk image),
OPT_STRING('p', params, kernel_cmdline, params,
Kernel command line arguments),
+   OPT_STRING('b', bios, bios_filename, bios,
+   BIOS to boot in virtual machine),
 
OPT_GROUP(Networking options:),
OPT_CALLBACK_DEFAULT('n', network, NULL, network params,
@@ -1110,14 +1113,16 @@ static int kvm_cmd_run_init(int argc, const char **argv)
printf(  # %s run -k %s -m %Lu -c %d --name %s\n, KVM_BINARY_NAME,
kernel_filename, ram_size / 1024 / 1024, nrcpus, guest_name);
 
-   if (!kvm__load_kernel(kvm, kernel_filename, initrd_filename,
-   real_cmdline, vidmode))
-   die(unable to load kernel %s, kernel_filename);
+   if (!bios_filename) {
+   if (!kvm__load_kernel(kvm, kernel_filename,
+   initrd_filename, real_cmdline, vidmode))
+   die(unable to load kernel %s, kernel_filename);
 
-   kvm-vmlinux = vmlinux_filename;
-   r = symbol_init(kvm);
-   if (r  0)
-   pr_debug(symbol_init() failed with error %d\n, r);
+   kvm-vmlinux = vmlinux_filename;
+   r = symbol_init(kvm);
+   if (r  0)
+   pr_debug(symbol_init() failed with error %d\n, r);
+   }
 
ioport__setup_arch();
 
@@ -1218,10 +1223,15 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 
kvm__start_timer(kvm);
 
-   kvm__arch_setup_firmware(kvm);
-   if (r  0) {
-   pr_err(kvm__arch_setup_firmware() failed with error %d\n, r);
-   goto fail;
+   if (bios_filename) {
+   if (!kvm__load_bios(kvm, bios_filename))
+   die(unable to load bios %s: %s, bios_filename, 
strerror(errno));
+   } else {
+   kvm__arch_setup_firmware(kvm);
+   if (r  0) {
+   pr_err(kvm__arch_setup_firmware() failed with error 
%d\n, r);
+   goto fail;
+   }
}
 
for (i = 0; i  nrcpus; i++) {
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 7870118..258d11a 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -39,6 +39,7 @@ int kvm__recommended_cpus(struct kvm *kvm);
 int kvm__max_cpus(struct kvm *kvm);
 void kvm__init_ram(struct kvm *kvm);
 int kvm__exit(struct kvm *kvm);
+bool kvm__load_bios(struct kvm *kvm, const char *bios_filename);
 bool kvm__load_kernel(struct kvm *kvm, 

[RFC/PATCH 2/2] kvm tools, seabios: Add support for SeaBIOS debugging output

2012-02-24 Thread Pekka Enberg
SeaBIOS outputs debugging messages to special debug port (0x0402). This patch
unconditionally hooks the PIO port to LKVM so that when user specifies a
SeaBIOS image, you'll see this for vm run:

  [penberg@tux kvm]$ ./vm run --bios /usr/share/seabios/bios.bin
# lkvm run -k ../../arch/x86/boot/bzImage -m 448 -c 4 --name guest-25983
  Start bios (version 0.6.0)
  Unable to unlock ram - bridge not found
  Ram Size=0x0010 (0x high)

  hangs here

Once we have SeaBIOS fully operational, we probably should hide the feature
under --debug-seabios command line option.

Cc: Yang Bai hamo...@gmail.com
Cc: Matt Evans m...@ozlabs.org
Cc: Ron Minnich rminn...@gmail.com
Cc: Anthony Liguori aligu...@us.ibm.com
Cc: John Floren j...@jfloren.net
Cc: Sasha Levin levinsasha...@gmail.com
Cc: Cyrill Gorcunov gorcu...@openvz.org
Cc: Asias He asias.he...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Signed-off-by: Pekka Enberg penb...@kernel.org
---
 tools/kvm/x86/ioport.c |   18 ++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/x86/ioport.c b/tools/kvm/x86/ioport.c
index 8a91bf2..86302e6 100644
--- a/tools/kvm/x86/ioport.c
+++ b/tools/kvm/x86/ioport.c
@@ -1,6 +1,7 @@
 #include kvm/ioport.h
 
 #include stdlib.h
+#include stdio.h
 
 static bool debug_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, 
void *data, int size)
 {
@@ -11,6 +12,21 @@ static struct ioport_operations debug_ops = {
.io_out = debug_io_out,
 };
 
+static bool seabios_debug_io_out(struct ioport *ioport, struct kvm *kvm, u16 
port, void *data, int size)
+{
+   char ch;
+
+   ch = ioport__read8(data);
+
+   putchar(ch);
+
+   return true;
+}
+
+static struct ioport_operations seabios_debug_ops = {
+   .io_out = seabios_debug_io_out,
+};
+
 static bool dummy_io_in(struct ioport *ioport, struct kvm *kvm, u16 port, void 
*data, int size)
 {
return true;
@@ -56,4 +72,6 @@ void ioport__setup_arch(void)
/* PORT 03D4-03D5 - COLOR VIDEO - CRT CONTROL REGISTERS */
ioport__register(0x03D4, dummy_read_write_ioport_ops, 1, NULL);
ioport__register(0x03D5, dummy_write_only_ioport_ops, 1, NULL);
+
+   ioport__register(0x402, seabios_debug_ops, 1, NULL);
 }
-- 
1.7.6.5

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Cyrill Gorcunov
On Fri, Feb 24, 2012 at 05:05:29PM +0200, Pekka Enberg wrote:
 This patch adds a --bios command line option to vm run. You can use this 
 to
 try to boot with SeaBIOS, for example:
 
   ./vm run --bios=/usr/share/seabios/bios.bin \
--disk $HOME/images/debian_lenny_amd64_standard.qcow2
 
 This doesn't boot yet for obvious reasons but at least people can now start to
 play with external BIOS images easily.

Hi Pekka, I believe it worth merging to start
working on this feature.

Cyrill
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Anthony Liguori

On 02/24/2012 09:05 AM, Pekka Enberg wrote:

This patch adds a --bios command line option to vm run. You can use this to
try to boot with SeaBIOS, for example:

   ./vm run --bios=/usr/share/seabios/bios.bin \
 --disk $HOME/images/debian_lenny_amd64_standard.qcow2

This doesn't boot yet for obvious reasons but at least people can now start to
play with external BIOS images easily.


You may want to call it firmware as other platforms also have firmware.  For 
instance, it may be desirable to use the same interface to load SLOF with spapr.




Cc: Yang Baihamo...@gmail.com
Cc: Matt Evansm...@ozlabs.org
Cc: Ron Minnichrminn...@gmail.com
Cc: Anthony Liguorialigu...@us.ibm.com
Cc: John Florenj...@jfloren.net
Cc: Sasha Levinlevinsasha...@gmail.com
Cc: Cyrill Gorcunovgorcu...@openvz.org
Cc: Asias Heasias.he...@gmail.com
Cc: Ingo Molnarmi...@elte.hu
Signed-off-by: Pekka Enbergpenb...@kernel.org
---
  tools/kvm/Makefile   |2 +
  tools/kvm/builtin-run.c  |   32 +++--
  tools/kvm/include/kvm/kvm.h  |1 +
  tools/kvm/powerpc/boot.c |8 +++
  tools/kvm/x86/boot.c |   41 ++
  tools/kvm/x86/include/kvm/bios.h |3 +-
  6 files changed, 75 insertions(+), 12 deletions(-)
  create mode 100644 tools/kvm/powerpc/boot.c
  create mode 100644 tools/kvm/x86/boot.c

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index cfa5547..0a9c2cc 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -113,6 +113,7 @@ LIBFDT_OBJS = $(patsubst 
%,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC))
  #x86
  ifeq ($(ARCH),x86)
DEFINES += -DCONFIG_X86
+   OBJS+= x86/boot.o
OBJS+= x86/cpuid.o
OBJS+= x86/interrupt.o
OBJS+= x86/ioport.o
@@ -129,6 +130,7 @@ endif
  # POWER/ppc:  Actually only support ppc64 currently.
  ifeq ($(uname_M), ppc64)
DEFINES += -DCONFIG_PPC
+   OBJS+= powerpc/boot.o
OBJS+= powerpc/ioport.o
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 466169e..f96c581 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -76,6 +76,7 @@ static const char *kernel_cmdline;
  static const char *kernel_filename;
  static const char *vmlinux_filename;
  static const char *initrd_filename;
+static const char *bios_filename;
  static const char *image_filename[MAX_DISK_IMAGES];
  static const char *console;
  static const char *dev;
@@ -458,6 +459,8 @@ static const struct option options[] = {
Initial RAM disk image),
OPT_STRING('p', params,kernel_cmdline, params,
Kernel command line arguments),
+   OPT_STRING('b', bios,bios_filename, bios,
+   BIOS to boot in virtual machine),

OPT_GROUP(Networking options:),
OPT_CALLBACK_DEFAULT('n', network, NULL, network params,
@@ -1110,14 +1113,16 @@ static int kvm_cmd_run_init(int argc, const char **argv)
printf(  # %s run -k %s -m %Lu -c %d --name %s\n, KVM_BINARY_NAME,
kernel_filename, ram_size / 1024 / 1024, nrcpus, guest_name);

-   if (!kvm__load_kernel(kvm, kernel_filename, initrd_filename,
-   real_cmdline, vidmode))
-   die(unable to load kernel %s, kernel_filename);
+   if (!bios_filename) {
+   if (!kvm__load_kernel(kvm, kernel_filename,
+   initrd_filename, real_cmdline, vidmode))
+   die(unable to load kernel %s, kernel_filename);

-   kvm-vmlinux = vmlinux_filename;
-   r = symbol_init(kvm);
-   if (r  0)
-   pr_debug(symbol_init() failed with error %d\n, r);
+   kvm-vmlinux = vmlinux_filename;
+   r = symbol_init(kvm);
+   if (r  0)
+   pr_debug(symbol_init() failed with error %d\n, r);
+   }

ioport__setup_arch();

@@ -1218,10 +1223,15 @@ static int kvm_cmd_run_init(int argc, const char **argv)

kvm__start_timer(kvm);

-   kvm__arch_setup_firmware(kvm);
-   if (r  0) {
-   pr_err(kvm__arch_setup_firmware() failed with error %d\n, r);
-   goto fail;
+   if (bios_filename) {
+   if (!kvm__load_bios(kvm, bios_filename))
+   die(unable to load bios %s: %s, bios_filename, 
strerror(errno));
+   } else {
+   kvm__arch_setup_firmware(kvm);
+   if (r  0) {
+   pr_err(kvm__arch_setup_firmware() failed with error 
%d\n, r);
+   goto fail;
+   }
}

for (i = 0; i  nrcpus; i++) {
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 7870118..258d11a 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -39,6 +39,7 @@ int kvm__recommended_cpus(struct kvm *kvm);
  int 

Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread ron minnich
I think you need to look at the change floren and I worked up,
assuming I can get him to release it to you.

Our change is a bit less complex and adds fewer lines of code. You've
added an extra option to load a bios, and it will be somewhat limited
as those ever-demanding users continue to demand more and more :-)

What we did instead is let users specify the load address of the
kernel, and the IP from which to start. So our command line ends up
with --kernel being a seabios image, and using switches to set the
load address at e and the initial IP at 0. Of course, now that
I know the memory is reflected to high memory too, the initial IP
could just as easily be fff0.

Anyway, John, can you give us a look at a patch please?

ron
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread John Floren
Yeah, I'll try to work something up... got approval from Keith.

On Fri, Feb 24, 2012 at 8:27 AM, ron minnich rminn...@gmail.com wrote:
 I think you need to look at the change floren and I worked up,
 assuming I can get him to release it to you.

 Our change is a bit less complex and adds fewer lines of code. You've
 added an extra option to load a bios, and it will be somewhat limited
 as those ever-demanding users continue to demand more and more :-)

 What we did instead is let users specify the load address of the
 kernel, and the IP from which to start. So our command line ends up
 with --kernel being a seabios image, and using switches to set the
 load address at e and the initial IP at 0. Of course, now that
 I know the memory is reflected to high memory too, the initial IP
 could just as easily be fff0.

 Anyway, John, can you give us a look at a patch please?

 ron
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Pekka Enberg
On Fri, 2012-02-24 at 09:23 -0600, Anthony Liguori wrote:
 On 02/24/2012 09:05 AM, Pekka Enberg wrote:
  This patch adds a --bios command line option to vm run. You can use 
  this to
  try to boot with SeaBIOS, for example:
 
 ./vm run --bios=/usr/share/seabios/bios.bin \
   --disk $HOME/images/debian_lenny_amd64_standard.qcow2
 
  This doesn't boot yet for obvious reasons but at least people can now start 
  to
  play with external BIOS images easily.
 
 You may want to call it firmware as other platforms also have firmware.  For 
 instance, it may be desirable to use the same interface to load SLOF with 
 spapr.

I renamed the command line option to --firmware.

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Pekka Enberg
On Fri, 2012-02-24 at 08:27 -0800, ron minnich wrote:
 I think you need to look at the change floren and I worked up,
 assuming I can get him to release it to you.
 
 Our change is a bit less complex and adds fewer lines of code. You've
 added an extra option to load a bios, and it will be somewhat limited
 as those ever-demanding users continue to demand more and more :-)
 
 What we did instead is let users specify the load address of the
 kernel, and the IP from which to start. So our command line ends up
 with --kernel being a seabios image, and using switches to set the
 load address at e and the initial IP at 0. Of course, now that
 I know the memory is reflected to high memory too, the initial IP
 could just as easily be fff0.

I went ahead and applied my patches. Feel free to extend it to support
the kind of configuration options you need.

I personally want a simple command line option that does everything for
me automatically.

Pekka

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Pekka Enberg
Hi,

I played around with the --debug-ioport command line option and was able 
to cheat my way past SeaBIOS POST phase. Should SeaBIOS automatically pick 
up virtio devices and attempt to boot them?

And no, I'm not going to commit this, at least not for now.

Pekka

From 8070dd3cfd3a371f4d968fd2446514f03df1f149 Mon Sep 17 00:00:00 2001
From: Pekka Enberg penb...@kernel.org
Date: Fri, 24 Feb 2012 20:20:16 +0200
Subject: [PATCH] kvmtool, seabios: Ignore BIOS POST legacy registers

This makes SeaBIOS limp along all the way to boot menu:

  [penberg@tux kvm]$ ./vm run --firmware /usr/share/seabios/bios.bin
# lkvm run -k ../../arch/x86/boot/bzImage -m 448 -c 4 --name guest-11658
  Start bios (version 0.6.0)
  Unable to unlock ram - bridge not found
  Ram Size=0x0010 (0x high)
  CPU Mhz=13
  Found 1 cpu(s) max supported 1 cpu(s)
  PCI: bus=0 devfn=0x08: vendor_id=0x1af4 device_id=0x1009
  PCI: bus=0 devfn=0x10: vendor_id=0x1af4 device_id=0x1009
  PCI: bus=0 devfn=0x18: vendor_id=0x1af4 device_id=0x1000
  region 0: 0x
  region 1: 0x
  WARNING - Unable to allocate resource at mptable_init:26!
  WARNING - Unable to allocate resource at smbios_init:381!
  Scan for VGA option rom
  WARNING - Timeout at i8042_wait_read:35!
  Found 2 lpt ports
  Found 4 serial ports
  Scan for option roms
  Press F12 for boot menu.

Signed-off-by: Pekka Enberg penb...@kernel.org
---
 tools/kvm/hw/i8042.c   |8 
 tools/kvm/x86/ioport.c |   18 ++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/hw/i8042.c b/tools/kvm/hw/i8042.c
index 3a36425..542fffd 100644
--- a/tools/kvm/hw/i8042.c
+++ b/tools/kvm/hw/i8042.c
@@ -19,6 +19,7 @@
  * Registers
  */
 #define I8042_DATA_REG 0x60
+#define I8042_PORT_B_REG   0x61
 #define I8042_COMMAND_REG  0x64
 
 /*
@@ -307,6 +308,10 @@ static bool kbd_in(struct ioport *ioport, struct kvm *kvm, 
u16 port, void *data,
ioport__write32(data, value);
break;
}
+   case I8042_PORT_B_REG: {
+   ioport__write8(data, 0x20);
+   break;
+   }
default:
return false;
}
@@ -327,6 +332,9 @@ static bool kbd_out(struct ioport *ioport, struct kvm *kvm, 
u16 port, void *data
kbd_write_data(value);
break;
}
+   case I8042_PORT_B_REG: {
+   break;
+   }
default:
return false;
}
diff --git a/tools/kvm/x86/ioport.c b/tools/kvm/x86/ioport.c
index 86302e6..7b3f4e3 100644
--- a/tools/kvm/x86/ioport.c
+++ b/tools/kvm/x86/ioport.c
@@ -50,15 +50,24 @@ void ioport__setup_arch(void)
 {
/* Legacy ioport setup */
 
+   /*  - 001F - DMA1 controller */
+   ioport__register(0x, dummy_read_write_ioport_ops, 32, NULL);
+
/* 0x0020 - 0x003F - 8259A PIC 1 */
ioport__register(0x0020, dummy_read_write_ioport_ops, 2, NULL);
 
/* PORT 0040-005F - PIT - PROGRAMMABLE INTERVAL TIMER (8253, 8254) */
ioport__register(0x0040, dummy_read_write_ioport_ops, 4, NULL);
 
+   /* 0092 - PS/2 system control port A */
+   ioport__register(0x0092, dummy_read_write_ioport_ops, 1, NULL);
+
/* 0x00A0 - 0x00AF - 8259A PIC 2 */
ioport__register(0x00A0, dummy_read_write_ioport_ops, 2, NULL);
 
+   /* 00C0 - 001F - DMA2 controller */
+   ioport__register(0x00C0, dummy_read_write_ioport_ops, 32, NULL);
+
/* PORT 00E0-00EF are 'motherboard specific' so we use them for our
   internal debugging purposes.  */
ioport__register(IOPORT_DBG, debug_ops, 1, NULL);
@@ -69,9 +78,18 @@ void ioport__setup_arch(void)
/* 0x00F0 - 0x00FF - Math co-processor */
ioport__register(0x00F0, dummy_write_only_ioport_ops, 2, NULL);
 
+   /* PORT 0278-027A - PARALLEL PRINTER PORT (usually LPT1, sometimes 
LPT2) */
+   ioport__register(0x0278, dummy_read_write_ioport_ops, 3, NULL);
+
+   /* PORT 0378-037A - PARALLEL PRINTER PORT (usually LPT2, sometimes 
LPT3) */
+   ioport__register(0x0378, dummy_read_write_ioport_ops, 3, NULL);
+
/* PORT 03D4-03D5 - COLOR VIDEO - CRT CONTROL REGISTERS */
ioport__register(0x03D4, dummy_read_write_ioport_ops, 1, NULL);
ioport__register(0x03D5, dummy_write_only_ioport_ops, 1, NULL);
 
ioport__register(0x402, seabios_debug_ops, 1, NULL);
+
+   /* 0510 - QEMU BIOS configuration register */
+   ioport__register(0x510, dummy_read_write_ioport_ops, 2, NULL);
 }
-- 
1.7.6.5

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Pekka Enberg
On Fri, Feb 24, 2012 at 8:54 PM, Pekka Enberg penb...@kernel.org wrote:
 I played around with the --debug-ioport command line option and was able
 to cheat my way past SeaBIOS POST phase. Should SeaBIOS automatically pick
 up virtio devices and attempt to boot them?

Aah, I guess we need to implement proper support for QEMU BIOS config
port (0x510) because the dummy port is accidentally asking for a
boot menu.

If I disable boot menu support from SeaBIOS, I'm now seeing this PCI
out of address space error which I suppose is what Ron and John were
talking about earlier:

[penberg@tux kvm]$ ./vm run --firmware
/home/penberg/seabios/out/bios.bin -d
~/images/debian_lenny_amd64_standard.qcow2 --debug-ioport
  Warning: Forcing read-only support for QCOW
  # lkvm run -k ../../arch/x86/boot/bzImage -m 448 -c 4 --name guest-12176
Start bios (version pre-1.6.4-20120224_205725-tux)
enabling shadow ram
Unable to unlock ram - bridge not found
qemu_cfg_present=0
Find memory size
Add to e820 map:  0010 1
Add to e820 map:   1
Add to e820 map: fffc 0004 2
Add to e820 map: 000a 0005 -1
Add to e820 map: 000f 0001 2
Add to e820 map: fffbc000 4000 2
Ram Size=0x0010 (0x high)
malloc setup
pmm_malloc zone=0x000f0060 handle= size=51132 align=10
ret=0x00083780 (detail=0x0008ff40)
Relocating init from 0x000e3950 to 0x00083780 (size 51132)
malloc fixup reloc
init ivt
init bda
Add to e820 map: 0009fc00 0400 2
init pic
init timer
tsc calibrate start=25589844 end=25596132 diff=6288
CPU Mhz=3
math cp init
init mtrr
pci setup
=== PCI bus  bridge init ===
PCI: pci_bios_init_bus_rec bus = 0x0
=== PCI device probing ===
PCI probe
pmm_malloc zone=0x0008fe90 handle= size=112 align=10
ret=0x000836b0 (detail=0x00083720)
PCI device 00:01.0 (vd=1af4:1001 c=0180)
pmm_malloc zone=0x0008fe90 handle= size=112 align=10
ret=0x00083610 (detail=0x00083680)
PCI device 00:02.0 (vd=1af4:1000 c=0200)
Found 2 PCI devices (max PCI bus is 00)
=== PCI new allocation pass #1 ===
pmm_malloc zone=0x0008fe90 handle= size=532 align=10
ret=0x000833c0 (detail=0x000835e0)
PCI: check devices
PCI: out of address space

Pekka
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [KVM paravirt issue?] Re: vsyscall=emulate regression

2012-02-24 Thread Andy Lutomirski
On Thu, Feb 23, 2012 at 8:34 PM, H. Peter Anvin h...@zytor.com wrote:
 On 02/16/2012 09:39 AM, Avi Kivity wrote:

 Yes, this is on purpose

 Why?

I think the this refers to the PF_INSTR fault when executing at
0xff600xxx.  That's definitely intentional -- it's how
vsyscall emulation works.

I think it's unintentional that some kvm versions apparently forget to
set the PF_INSTR bit.

--Andy


        -hpa


 --
 H. Peter Anvin, Intel Open Source Technology Center
 I work for Intel.  I don't speak on their behalf.




-- 
Andy Lutomirski
AMA Capital Management, LLC
Office: (310) 553-5322
Mobile: (650) 906-0647
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread ron minnich
On Fri, Feb 24, 2012 at 10:00 AM, Pekka Enberg penb...@kernel.org wrote:

 I personally want a simple command line option that does everything for
 me automatically.

it's a great goal, and I like the swtich a lot. But if you want that
-firmware option why not have it turn into an automated setting of the
options that John's got in his patch? It really is less code overall
and I love the fact that kvm tool is so tiny, I'm anxious to keep it
that way :-)

ron
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Pekka Enberg
On Fri, Feb 24, 2012 at 10:00 AM, Pekka Enberg penb...@kernel.org wrote:
 I personally want a simple command line option that does everything for
 me automatically.

On Fri, Feb 24, 2012 at 9:07 PM, ron minnich rminn...@gmail.com wrote:
 it's a great goal, and I like the swtich a lot. But if you want that
 -firmware option why not have it turn into an automated setting of the
 options that John's got in his patch? It really is less code overall
 and I love the fact that kvm tool is so tiny, I'm anxious to keep it
 that way :-)

Hey, feel free to change it that way. I wanted to be able to play with
seabios too and simply got bored while waiting for someone to send a
patch to allow that.

Pekka
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread Pekka Enberg
On Fri, Feb 24, 2012 at 9:01 PM, Pekka Enberg penb...@kernel.org wrote:
 Aah, I guess we need to implement proper support for QEMU BIOS config
 port (0x510) because the dummy port is accidentally asking for a
 boot menu.

 If I disable boot menu support from SeaBIOS, I'm now seeing this PCI
 out of address space error which I suppose is what Ron and John were
 talking about earlier:

[snip, snip]

So looking at SeaBIOS code, it seems to me we could simply make LKVM
lie to it by claiming to be coreboot and get away with it, no? We'd
basically avoid all the PCI allocation passes and such.

How difficult is it to initialize a struct cb_header data structure?
src/coreboot.c::find_cb_header() seems to be rather strict but
certainly nothing that we fundamentally can't do.

Another option is to extend the Xen codepaths to support LKVM too.

Pekka
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread John Floren
On Fri, Feb 24, 2012 at 11:18 AM, Pekka Enberg penb...@kernel.org wrote:
 On Fri, Feb 24, 2012 at 9:01 PM, Pekka Enberg penb...@kernel.org wrote:
 Aah, I guess we need to implement proper support for QEMU BIOS config
 port (0x510) because the dummy port is accidentally asking for a
 boot menu.

 If I disable boot menu support from SeaBIOS, I'm now seeing this PCI
 out of address space error which I suppose is what Ron and John were
 talking about earlier:

 [snip, snip]

 So looking at SeaBIOS code, it seems to me we could simply make LKVM
 lie to it by claiming to be coreboot and get away with it, no? We'd
 basically avoid all the PCI allocation passes and such.

 How difficult is it to initialize a struct cb_header data structure?
 src/coreboot.c::find_cb_header() seems to be rather strict but
 certainly nothing that we fundamentally can't do.

 Another option is to extend the Xen codepaths to support LKVM too.

                                Pekka

Just tell SeaBIOS to compile for Coreboot. That seemed to get me going.

John
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 33/37] KVM: PPC: bookehv: remove unused code

2012-02-24 Thread Scott Wood
On 02/24/2012 08:26 AM, Alexander Graf wrote:
 There was some unused code in the exit code path that must have been
 a leftover from earlier iterations. While it did no hard, it's superfluous
 and thus should be removed.

s/hard/harm/ -- at that assumes exit timing wasn't enabled. :-)

 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  arch/powerpc/kvm/bookehv_interrupts.S |3 ---
  1 files changed, 0 insertions(+), 3 deletions(-)
 
 diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
 b/arch/powerpc/kvm/bookehv_interrupts.S
 index 021d087..b1c099b 100644
 --- a/arch/powerpc/kvm/bookehv_interrupts.S
 +++ b/arch/powerpc/kvm/bookehv_interrupts.S
 @@ -112,9 +112,6 @@
* appropriate for the exception type).
*/
   cmpwr6, r8
 - .if \flags  NEED_EMU
 - lwz r9, KVM_LPID(r9)
 - .endif
   beq 1f
   mfmsr   r7
   .if \srr0 != SPRN_MCSRR0  \srr0 != SPRN_CSRR0

Can also remove lwzr9, VCPU_KVM(r4).

-Scott

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 35/37] KVM: PPC: booke: Support perfmon interrupts

2012-02-24 Thread Scott Wood
On 02/24/2012 08:26 AM, Alexander Graf wrote:
 When during guest context we get a performance monitor interrupt, we
 currently bail out and oops. Let's route it to its correct handler
 instead.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  arch/powerpc/kvm/booke.c |4 
  1 files changed, 4 insertions(+), 0 deletions(-)
 
 diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
 index 7adef28..423701b 100644
 --- a/arch/powerpc/kvm/booke.c
 +++ b/arch/powerpc/kvm/booke.c
 @@ -677,6 +677,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
 kvm_vcpu *vcpu,
   r = RESUME_GUEST;
   break;
  
 + case BOOKE_INTERRUPT_PERFORMANCE_MONITOR:
 + r = RESUME_GUEST;
 + break;
 +
   case BOOKE_INTERRUPT_HV_PRIV:
   r = emulation_exit(run, vcpu);
   break;

Why do we need to call timer_interrupt() explicitly, but can rely on
automatic retriggering for perfmon?

-Scott

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 36/37] KVM: PPC: booke: expose guest registers on irq reinject

2012-02-24 Thread Scott Wood
On 02/24/2012 08:26 AM, Alexander Graf wrote:
 +static void kvmppc_fill_pt_regs(struct kvm_vcpu *vcpu, struct pt_regs *regs)
  {
 - int r = RESUME_HOST;
 + int i;
  
 - /* update before a new last_exit_type is rewritten */
 - kvmppc_update_timing_stats(vcpu);
 + for (i = 0; i  32; i++)
 + regs-gpr[i] = kvmppc_get_gpr(vcpu, i);
 + regs-nip = vcpu-arch.pc;
 + regs-msr = vcpu-arch.shared-msr;
 + regs-ctr = vcpu-arch.ctr;
 + regs-link = vcpu-arch.lr;
 + regs-xer = kvmppc_get_xer(vcpu);
 + regs-ccr = kvmppc_get_cr(vcpu);
 + regs-dar = get_guest_dear(vcpu);
 + regs-dsisr = get_guest_esr(vcpu);
 +}

How much overhead does this add to every interrupt?  Can't we keep this
to the minimum that perf cares about?

 +
 +static void kvmppc_restart_interrupt(struct kvm_vcpu *vcpu,
 +  unsigned int exit_nr)
 +{
 + struct pt_regs regs = *current-thread.regs;
  
 + kvmppc_fill_pt_regs(vcpu, regs);

Why are you copying out of current-thread.regs?  That's old junk data,
set by some previous exception and possibly overwritten since.

-Scott

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-24 Thread John Floren
Here are some small changes I made to get SeaBIOS to work on lkvm.
Some may not be entirely needed.

Oh, and I've also attached the .config I used.

John

On Fri, Feb 24, 2012 at 11:29 AM, John Floren j...@jfloren.net wrote:
 On Fri, Feb 24, 2012 at 11:18 AM, Pekka Enberg penb...@kernel.org wrote:
 On Fri, Feb 24, 2012 at 9:01 PM, Pekka Enberg penb...@kernel.org wrote:
 Aah, I guess we need to implement proper support for QEMU BIOS config
 port (0x510) because the dummy port is accidentally asking for a
 boot menu.

 If I disable boot menu support from SeaBIOS, I'm now seeing this PCI
 out of address space error which I suppose is what Ron and John were
 talking about earlier:

 [snip, snip]

 So looking at SeaBIOS code, it seems to me we could simply make LKVM
 lie to it by claiming to be coreboot and get away with it, no? We'd
 basically avoid all the PCI allocation passes and such.

 How difficult is it to initialize a struct cb_header data structure?
 src/coreboot.c::find_cb_header() seems to be rather strict but
 certainly nothing that we fundamentally can't do.

 Another option is to extend the Xen codepaths to support LKVM too.

                                Pekka

 Just tell SeaBIOS to compile for Coreboot. That seemed to get me going.

 John
From 3f304bb583627d000be0c8ea8039c0c7c8a4c781 Mon Sep 17 00:00:00 2001
From: John Floren j...@jfloren.net
Date: Fri, 24 Feb 2012 17:11:44 -0800
Subject: [PATCH] Tweaks to allow SeaBIOS to boot on lkvm. Remember to build
 for Coreboot when you do make menuconfig.

---
 src/Kconfig  |8 
 src/clock.c  |3 +++
 src/coreboot.c   |4 ++--
 src/paravirt.c   |4 ++--
 src/pirtable.c   |2 +-
 src/post.c   |8 
 src/virtio-blk.c |   25 +++--
 7 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/Kconfig b/src/Kconfig
index 250663a..21e13aa 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -108,7 +108,7 @@ menu Hardware support
 help
 Support for AHCI disk code.
 config VIRTIO_BLK
-depends on DRIVES  !COREBOOT
+depends on DRIVES
 bool virtio-blk controllers
 default y
 help
@@ -298,13 +298,13 @@ endmenu
 
 menu BIOS Tables
 config PIRTABLE
-depends on !COREBOOT
+#depends on !COREBOOT
 bool PIR table
 default y
 help
 Support generation of a PIR table in 0xf000 segment.
 config MPTABLE
-depends on !COREBOOT
+#depends on !COREBOOT
 bool MPTable
 default y
 help
@@ -316,7 +316,7 @@ menu BIOS Tables
 Support generation of SM BIOS tables.  This is also
 sometimes called DMI.
 config ACPI
-depends on !COREBOOT
+#depends on !COREBOOT
 bool ACPI
 default y
 help
diff --git a/src/clock.c b/src/clock.c
index e8a48a1..ee6c15b 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -68,6 +68,7 @@ u8 no_tsc VAR16VISIBLE;
 static void
 calibrate_tsc(void)
 {
+if (0) {
 u32 eax, ebx, ecx, edx, cpuid_features = 0;
 cpuid(0, eax, ebx, ecx, edx);
 if (eax  0)
@@ -107,6 +108,8 @@ calibrate_tsc(void)
 
 dprintf(1, CPU Mhz=%u\n, hz / 100);
 }
+SET_GLOBAL(cpu_khz, 2128000);
+}
 
 static u64
 emulate_tsc(void)
diff --git a/src/coreboot.c b/src/coreboot.c
index e328c15..976f20d 100644
--- a/src/coreboot.c
+++ b/src/coreboot.c
@@ -179,9 +179,9 @@ coreboot_fill_map(void)
 fail:
 // No table found..  Use 16Megs as a dummy value.
 dprintf(1, Unable to find coreboot table!\n);
-RamSize = 16*1024*1024;
+RamSize = 512*1024*1024;
 RamSizeOver4G = 0;
-add_e820(0, 16*1024*1024, E820_RAM);
+add_e820(0, RamSize, E820_RAM);
 return;
 }
 
diff --git a/src/paravirt.c b/src/paravirt.c
index 9cf77de..c38a84d 100644
--- a/src/paravirt.c
+++ b/src/paravirt.c
@@ -46,8 +46,8 @@ void qemu_cfg_port_probe(void)
 char *sig = QEMU;
 int i;
 
-if (CONFIG_COREBOOT)
-return;
+//if (CONFIG_COREBOOT)
+//return;
 
 qemu_cfg_present = 1;
 
diff --git a/src/pirtable.c b/src/pirtable.c
index 4c3f1ff..7cb358e 100644
--- a/src/pirtable.c
+++ b/src/pirtable.c
@@ -17,7 +17,7 @@ struct pir_table {
 } PACKED;
 
 extern struct pir_table PIR_TABLE;
-#if CONFIG_PIRTABLE  !CONFIG_COREBOOT
+#if CONFIG_PIRTABLE // !CONFIG_COREBOOT
 struct pir_table PIR_TABLE __aligned(16) VAR16EXPORT = {
 .pir = {
 .version = 0x0100,
diff --git a/src/post.c b/src/post.c
index b4ad1fa..880a238 100644
--- a/src/post.c
+++ b/src/post.c
@@ -157,10 +157,10 @@ ram_probe(void)
 static void
 init_bios_tables(void)
 {
-if (CONFIG_COREBOOT) {
-coreboot_copy_biostable();
-return;
-}
+//if (CONFIG_COREBOOT) {
+//coreboot_copy_biostable();
+//return;
+//}
 if (usingXen()) {
 	xen_copy_biostables();
 	return;
diff --git a/src/virtio-blk.c b/src/virtio-blk.c
index b869189..9022601 100644
--- a/src/virtio-blk.c
+++ 

Re: [PATCH v6 02/12] ARM: KVM: Initial skeleton to compile KVM support

2012-02-24 Thread Rusty Russell
On Thu, 23 Feb 2012 23:43:14 -0500, Christoffer Dall 
c.d...@virtualopensystems.com wrote:
  Like much of your code, I find this far too readable.  How about:
 
 far too readable - what does this mean?

It means I was joking with my suggestion.

I do this so often as I review patches just to keep my mind engaged.

Clearly, my humor failed here.
Rusty.
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/37] powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Currently 32-bit only cares about this for choice of exception
vector, which is done in core-specific code.  However, KVM will
want to distinguish as well.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/cputable.h |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/cputable.h 
b/arch/powerpc/include/asm/cputable.h
index ad55a1c..6a034a2 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -376,7 +376,8 @@ extern const char *powerpc_base_platform;
 #define CPU_FTRS_47X   (CPU_FTRS_440x6)
 #define CPU_FTRS_E200  (CPU_FTR_USE_TB | CPU_FTR_SPE_COMP | \
CPU_FTR_NODSISRALIGN | CPU_FTR_COHERENT_ICACHE | \
-   CPU_FTR_UNIFIED_ID_CACHE | CPU_FTR_NOEXECUTE)
+   CPU_FTR_UNIFIED_ID_CACHE | CPU_FTR_NOEXECUTE | \
+   CPU_FTR_DEBUG_LVL_EXC)
 #define CPU_FTRS_E500  (CPU_FTR_MAYBE_CAN_DOZE | CPU_FTR_USE_TB | \
CPU_FTR_SPE_COMP | CPU_FTR_MAYBE_CAN_NAP | CPU_FTR_NODSISRALIGN | \
CPU_FTR_NOEXECUTE)
@@ -385,7 +386,7 @@ extern const char *powerpc_base_platform;
CPU_FTR_NODSISRALIGN | CPU_FTR_NOEXECUTE)
 #define CPU_FTRS_E500MC(CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
-   CPU_FTR_DBELL)
+   CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC)
 #define CPU_FTRS_E5500 (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
CPU_FTR_DBELL | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/37] KVM: PPC: booke: add booke-level vcpu load/put

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

This gives us a place to put load/put actions that correspond to
code that is booke-specific but not specific to a particular core.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/44x.c   |3 +++
 arch/powerpc/kvm/booke.c |8 
 arch/powerpc/kvm/booke.h |3 +++
 arch/powerpc/kvm/e500.c  |3 +++
 4 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
index 7b612a7..879a1a7 100644
--- a/arch/powerpc/kvm/44x.c
+++ b/arch/powerpc/kvm/44x.c
@@ -29,15 +29,18 @@
 #include asm/kvm_ppc.h
 
 #include 44x_tlb.h
+#include booke.h
 
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
+   kvmppc_booke_vcpu_load(vcpu, cpu);
kvmppc_44x_tlb_load(vcpu);
 }
 
 void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
 {
kvmppc_44x_tlb_put(vcpu);
+   kvmppc_booke_vcpu_put(vcpu);
 }
 
 int kvmppc_core_check_processor_compat(void)
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index ee9e1ee..a2456c7 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -968,6 +968,14 @@ void kvmppc_decrementer_func(unsigned long data)
kvmppc_set_tsr_bits(vcpu, TSR_DIS);
 }
 
+void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
+{
+}
+
+void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)
+{
+}
+
 int __init kvmppc_booke_init(void)
 {
unsigned long ivor[16];
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index 2fe2027..05d1d99 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -71,4 +71,7 @@ void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu);
 /* high-level function, manages flags, host state */
 void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu);
 
+void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
+void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu);
+
 #endif /* __KVM_BOOKE_H__ */
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index ddcd896..2d5fe04 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -36,6 +36,7 @@ void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
 
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
+   kvmppc_booke_vcpu_load(vcpu, cpu);
kvmppc_e500_tlb_load(vcpu, cpu);
 }
 
@@ -47,6 +48,8 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
if (vcpu-arch.shadow_msr  MSR_SPE)
kvmppc_vcpu_disable_spe(vcpu);
 #endif
+
+   kvmppc_booke_vcpu_put(vcpu);
 }
 
 int kvmppc_core_check_processor_compat(void)
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 19/37] KVM: PPC: e500mc: add load inst fixup

2012-02-24 Thread Alexander Graf
There's always a chance we're unable to read a guest instruction. The guest
could have its TLB mapped execute-, but not readable, something odd happens
and our TLB gets flushed. So it's a good idea to be prepared for that case
and have a fallback that allows us to fix things up in that case.

Add fixup code that keeps guest code from potentially crashing our host kernel.

Signed-off-by: Alexander Graf ag...@suse.de

---

v1 - v2:

  - fix whitespace
  - use explicit preempt counts
---
 arch/powerpc/kvm/bookehv_interrupts.S |   30 +-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 63023ae..f7dc3f6 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -28,6 +28,7 @@
 #include asm/asm-compat.h
 #include asm/asm-offsets.h
 #include asm/bitsperlong.h
+#include asm/thread_info.h
 
 #include ../kernel/head_booke.h /* for THREAD_NORMSAVE() */
 
@@ -171,9 +172,36 @@
PPC_STL r30, VCPU_GPR(r30)(r4)
PPC_STL r31, VCPU_GPR(r31)(r4)
mtspr   SPRN_EPLC, r8
+
+   /* disable preemption, so we are sure we hit the fixup handler */
+#ifdef CONFIG_PPC64
+   clrrdi  r8,r1,THREAD_SHIFT
+#else
+   rlwinm  r8,r1,0,0,31-THREAD_SHIFT   /* current thread_info */
+#endif
+   li  r7, 1
+stwr7, TI_PREEMPT(r8)
+
isync
-   lwepx   r9, 0, r5
+
+   /*
+* In case the read goes wrong, we catch it and write an invalid value
+* in LAST_INST instead.
+*/
+1: lwepx   r9, 0, r5
+2:
+.section .fixup, ax
+3: li  r9, KVM_INST_FETCH_FAILED
+   b   2b
+.previous
+.section __ex_table,a
+   PPC_LONG_ALIGN
+   PPC_LONG 1b,3b
+.previous
+
mtspr   SPRN_EPLC, r3
+   li  r7, 0
+stwr7, TI_PREEMPT(r8)
stw r9, VCPU_LAST_INST(r4)
.endif
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 37/37] KVM: PPC: booke: Reinject performance monitor interrupts

2012-02-24 Thread Alexander Graf
When we get a performance monitor interrupt, we need to make sure that
the host receives it. So reinject it like we reinject the other host
destined interrupts.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/hw_irq.h |1 +
 arch/powerpc/kvm/booke.c  |3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/hw_irq.h 
b/arch/powerpc/include/asm/hw_irq.h
index bb712c9..904e66c 100644
--- a/arch/powerpc/include/asm/hw_irq.h
+++ b/arch/powerpc/include/asm/hw_irq.h
@@ -12,6 +12,7 @@
 #include asm/processor.h
 
 extern void timer_interrupt(struct pt_regs *);
+extern void performance_monitor_exception(struct pt_regs *regs);
 
 #ifdef CONFIG_PPC64
 #include asm/paca.h
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 709fd45..c391357 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -630,6 +630,9 @@ static void kvmppc_restart_interrupt(struct kvm_vcpu *vcpu,
case BOOKE_INTERRUPT_MACHINE_CHECK:
/* FIXME */
break;
+   case BOOKE_INTERRUPT_PERFORMANCE_MONITOR:
+   performance_monitor_exception(regs);
+   break;
}
 }
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 14/37] KVM: PPC: booke: standard PPC floating point support

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

e500mc has a normal PPC FPU, rather than SPE which is found
on e500v1/v2.

Based on code from Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/system.h |1 +
 arch/powerpc/kvm/booke.c  |   44 +
 arch/powerpc/kvm/booke.h  |   30 +
 3 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/system.h 
b/arch/powerpc/include/asm/system.h
index c377457..73eee86 100644
--- a/arch/powerpc/include/asm/system.h
+++ b/arch/powerpc/include/asm/system.h
@@ -140,6 +140,7 @@ extern void via_cuda_init(void);
 extern void read_rtc_time(void);
 extern void pmac_find_display(void);
 extern void giveup_fpu(struct task_struct *);
+extern void load_up_fpu(void);
 extern void disable_kernel_fp(void);
 extern void enable_kernel_fp(void);
 extern void flush_fp_to_thread(struct task_struct *);
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 75dbaeb..0b77be1 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -457,6 +457,11 @@ void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
int ret;
+#ifdef CONFIG_PPC_FPU
+   unsigned int fpscr;
+   int fpexc_mode;
+   u64 fpr[32];
+#endif
 
if (!vcpu-arch.sane) {
kvm_run-exit_reason = KVM_EXIT_INTERNAL_ERROR;
@@ -479,7 +484,46 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
}
 
kvm_guest_enter();
+
+#ifdef CONFIG_PPC_FPU
+   /* Save userspace FPU state in stack */
+   enable_kernel_fp();
+   memcpy(fpr, current-thread.fpr, sizeof(current-thread.fpr));
+   fpscr = current-thread.fpscr.val;
+   fpexc_mode = current-thread.fpexc_mode;
+
+   /* Restore guest FPU state to thread */
+   memcpy(current-thread.fpr, vcpu-arch.fpr, sizeof(vcpu-arch.fpr));
+   current-thread.fpscr.val = vcpu-arch.fpscr;
+
+   /*
+* Since we can't trap on MSR_FP in GS-mode, we consider the guest
+* as always using the FPU.  Kernel usage of FP (via
+* enable_kernel_fp()) in this thread must not occur while
+* vcpu-fpu_active is set.
+*/
+   vcpu-fpu_active = 1;
+
+   kvmppc_load_guest_fp(vcpu);
+#endif
+
ret = __kvmppc_vcpu_run(kvm_run, vcpu);
+
+#ifdef CONFIG_PPC_FPU
+   kvmppc_save_guest_fp(vcpu);
+
+   vcpu-fpu_active = 0;
+
+   /* Save guest FPU state from thread */
+   memcpy(vcpu-arch.fpr, current-thread.fpr, sizeof(vcpu-arch.fpr));
+   vcpu-arch.fpscr = current-thread.fpscr.val;
+
+   /* Restore userspace FPU state from stack */
+   memcpy(current-thread.fpr, fpr, sizeof(current-thread.fpr));
+   current-thread.fpscr.val = fpscr;
+   current-thread.fpexc_mode = fpexc_mode;
+#endif
+
kvm_guest_exit();
 
 out:
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index d53bcf2..3bf5eda 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -96,4 +96,34 @@ enum int_class {
 
 void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type);
 
+/*
+ * Load up guest vcpu FP state if it's needed.
+ * It also set the MSR_FP in thread so that host know
+ * we're holding FPU, and then host can help to save
+ * guest vcpu FP state if other threads require to use FPU.
+ * This simulates an FP unavailable fault.
+ *
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (vcpu-fpu_active  !(current-thread.regs-msr  MSR_FP)) {
+   load_up_fpu();
+   current-thread.regs-msr |= MSR_FP;
+   }
+#endif
+}
+
+/*
+ * Save guest vcpu FP state into thread.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (vcpu-fpu_active  (current-thread.regs-msr  MSR_FP))
+   giveup_fpu(current);
+#endif
+}
 #endif /* __KVM_BOOKE_H__ */
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 34/37] KVM: PPC: e500: fix typo in tlb code

2012-02-24 Thread Alexander Graf
The tlbncfg registers should be populated with their respective TLB's
values. Fix the obvious typo.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500_tlb.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 279e10a..e05232b 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -1268,8 +1268,8 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 
*vcpu_e500)
 
vcpu-arch.tlbcfg[1] = mfspr(SPRN_TLB1CFG) 
 ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
-   vcpu-arch.tlbcfg[0] |= vcpu_e500-gtlb_params[1].entries;
-   vcpu-arch.tlbcfg[0] |=
+   vcpu-arch.tlbcfg[1] |= vcpu_e500-gtlb_params[1].entries;
+   vcpu-arch.tlbcfg[1] |=
vcpu_e500-gtlb_params[1].ways  TLBnCFG_ASSOC_SHIFT;
 
return 0;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 35/37] KVM: PPC: booke: Support perfmon interrupts

2012-02-24 Thread Alexander Graf
When during guest context we get a performance monitor interrupt, we
currently bail out and oops. Let's route it to its correct handler
instead.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 7adef28..423701b 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -677,6 +677,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
r = RESUME_GUEST;
break;
 
+   case BOOKE_INTERRUPT_PERFORMANCE_MONITOR:
+   r = RESUME_GUEST;
+   break;
+
case BOOKE_INTERRUPT_HV_PRIV:
r = emulation_exit(run, vcpu);
break;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 33/37] KVM: PPC: bookehv: remove unused code

2012-02-24 Thread Alexander Graf
There was some unused code in the exit code path that must have been
a leftover from earlier iterations. While it did no hard, it's superfluous
and thus should be removed.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 021d087..b1c099b 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -112,9 +112,6 @@
 * appropriate for the exception type).
 */
cmpwr6, r8
-   .if \flags  NEED_EMU
-   lwz r9, KVM_LPID(r9)
-   .endif
beq 1f
mfmsr   r7
.if \srr0 != SPRN_MCSRR0  \srr0 != SPRN_CSRR0
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 32/37] KVM: PPC: booke: add GS documentation for program interrupt

2012-02-24 Thread Alexander Graf
The comment for program interrupts triggered when using bookehv was
misleading. Update it to mention why MSR_GS indicates that we have
to inject an interrupt into the guest again, not emulate it.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   10 --
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 451ba16..7adef28 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -683,8 +683,14 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 
case BOOKE_INTERRUPT_PROGRAM:
if (vcpu-arch.shared-msr  (MSR_PR | MSR_GS)) {
-   /* Program traps generated by user-level software must 
be handled
-* by the guest kernel. */
+   /*
+* Program traps generated by user-level software must
+* be handled by the guest kernel.
+*
+* In GS mode, hypervisor privileged instructions trap
+* on BOOKE_INTERRUPT_HV_PRIV, not here, so these are
+* actual program interrupts, handled by the guest.
+*/
kvmppc_core_queue_program(vcpu, vcpu-arch.fault_esr);
r = RESUME_GUEST;
kvmppc_account_exit(vcpu, USR_PR_INST);
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 31/37] KVM: PPC: booke: Readd debug abort code for machine check

2012-02-24 Thread Alexander Graf
When during guest execution we get a machine check interrupt, we don't
know how to handle it yet. So let's add the error printing code back
again that we dropped accidently earlier and tell user space that something
went really wrong.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |7 ++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 288bc05..451ba16 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -632,7 +632,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 
switch (exit_nr) {
case BOOKE_INTERRUPT_MACHINE_CHECK:
-   r = RESUME_GUEST;
+   printk(MACHINE CHECK: %lx\n, mfspr(SPRN_MCSR));
+   kvmppc_dump_vcpu(vcpu);
+   /* For debugging, send invalid exit reason to user space */
+   run-hw.hardware_exit_reason = ~1ULL  32;
+   run-hw.hardware_exit_reason |= mfspr(SPRN_MCSR);
+   r = RESUME_HOST;
break;
 
case BOOKE_INTERRUPT_EXTERNAL:
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 29/37] KVM: PPC: bookehv: disable MAS register updates early

2012-02-24 Thread Alexander Graf
We need to make sure that no MAS updates happen automatically while we
have the guest MAS registers loaded. So move the disabling code a bit
higher up so that it covers the full time we have guest values in MAS
registers.

The race this patch fixes should never occur, but it makes the code a
bit more logical to do it this way around.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |   10 ++
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 469bd3f..021d087 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -358,6 +358,7 @@ _GLOBAL(kvmppc_resume_host)
mtspr   SPRN_MAS4, r6
stw r5, VCPU_SHARED_MAS7_3+0(r11)
mtspr   SPRN_MAS6, r8
+   /* Enable MAS register updates via exception */
mfspr   r3, SPRN_EPCR
rlwinm  r3, r3, 0, ~SPRN_EPCR_DMIUH
mtspr   SPRN_EPCR, r3
@@ -515,6 +516,11 @@ lightweight_exit:
mtspr   SPRN_PID, r3
 
PPC_LL  r11, VCPU_SHARED(r4)
+   /* Disable MAS register updates via exception */
+   mfspr   r3, SPRN_EPCR
+   orisr3, r3, SPRN_EPCR_DMIUH@h
+   mtspr   SPRN_EPCR, r3
+   isync
/* Save host mas4 and mas6 and load guest MAS registers */
mfspr   r3, SPRN_MAS4
stw r3, VCPU_HOST_MAS4(r4)
@@ -538,10 +544,6 @@ lightweight_exit:
lwz r5, VCPU_SHARED_MAS7_3+0(r11)
mtspr   SPRN_MAS6, r3
mtspr   SPRN_MAS7, r5
-   /* Disable MAS register updates via exception */
-   mfspr   r3, SPRN_EPCR
-   orisr3, r3, SPRN_EPCR_DMIUH@h
-   mtspr   SPRN_EPCR, r3
 
/*
 * Host interrupt handlers may have clobbered these guest-readable
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 30/37] KVM: PPC: bookehv: add comment about shadow_msr

2012-02-24 Thread Alexander Graf
For BookE HV the guest visible MSR is shared-msr and is identical to
the MSR that is in use while the guest is running, because we can't trap
reads from/to MSR.

So shadow_msr is unused there. Indicate that with a comment.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index ed95f53..633d68f 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -386,6 +386,7 @@ struct kvm_vcpu_arch {
 #endif
u32 vrsave; /* also USPRG0 */
u32 mmucr;
+   /* shadow_msr is unused for BookE HV */
ulong shadow_msr;
ulong csrr0;
ulong csrr1;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 27/37] KVM: PPC: bookehv: remove negation for CONFIG_64BIT

2012-02-24 Thread Alexander Graf
Instead if doing

  #ifndef CONFIG_64BIT
  ...
  #else
  ...
  #endif

we should rather do

  #ifdef CONFIG_64BIT
  ...
  #else
  ...
  #endif

which is a lot easier to read. Change the bookehv implementation to
stick with this rule.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |   24 
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index 215381e..c5a0796 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -99,10 +99,10 @@
.endif
 
orisr8, r6, MSR_CE@h
-#ifndef CONFIG_64BIT
-   stw r6, (VCPU_SHARED_MSR + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
std r6, (VCPU_SHARED_MSR)(r11)
+#else
+   stw r6, (VCPU_SHARED_MSR + 4)(r11)
 #endif
ori r8, r8, MSR_ME | MSR_RI
PPC_STL r5, VCPU_PC(r4)
@@ -344,10 +344,10 @@ _GLOBAL(kvmppc_resume_host)
stw r5, VCPU_SHARED_MAS0(r11)
mfspr   r7, SPRN_MAS2
stw r6, VCPU_SHARED_MAS1(r11)
-#ifndef CONFIG_64BIT
-   stw r7, (VCPU_SHARED_MAS2 + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
std r7, (VCPU_SHARED_MAS2)(r11)
+#else
+   stw r7, (VCPU_SHARED_MAS2 + 4)(r11)
 #endif
mfspr   r5, SPRN_MAS3
mfspr   r6, SPRN_MAS4
@@ -530,10 +530,10 @@ lightweight_exit:
stw r3, VCPU_HOST_MAS6(r4)
lwz r3, VCPU_SHARED_MAS0(r11)
lwz r5, VCPU_SHARED_MAS1(r11)
-#ifndef CONFIG_64BIT
-   lwz r6, (VCPU_SHARED_MAS2 + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
ld  r6, (VCPU_SHARED_MAS2)(r11)
+#else
+   lwz r6, (VCPU_SHARED_MAS2 + 4)(r11)
 #endif
lwz r7, VCPU_SHARED_MAS7_3+4(r11)
lwz r8, VCPU_SHARED_MAS4(r11)
@@ -572,10 +572,10 @@ lightweight_exit:
PPC_LL  r6, VCPU_CTR(r4)
PPC_LL  r7, VCPU_CR(r4)
PPC_LL  r8, VCPU_PC(r4)
-#ifndef CONFIG_64BIT
-   lwz r9, (VCPU_SHARED_MSR + 4)(r11)
-#else
+#ifdef CONFIG_64BIT
ld  r9, (VCPU_SHARED_MSR)(r11)
+#else
+   lwz r9, (VCPU_SHARED_MSR + 4)(r11)
 #endif
PPC_LL  r0, VCPU_GPR(r0)(r4)
PPC_LL  r1, VCPU_GPR(r1)(r4)
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 28/37] KVM: PPC: bookehv: remove SET_VCPU

2012-02-24 Thread Alexander Graf
The SET_VCPU macro is a leftover from times when the vcpu struct wasn't
stored in the thread on vcpu_load/put. It's not needed anymore. Remove it.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |8 
 1 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index c5a0796..469bd3f 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -35,9 +35,6 @@
 #define GET_VCPU(vcpu, thread) \
PPC_LL  vcpu, THREAD_KVM_VCPU(thread)
 
-#define SET_VCPU(vcpu) \
-PPC_STLvcpu, (THREAD + THREAD_KVM_VCPU)(r2)
-
 #define LONGBYTES  (BITS_PER_LONG / 8)
 
 #define VCPU_GPR(n)(VCPU_GPRS + (n * LONGBYTES))
@@ -517,11 +514,6 @@ lightweight_exit:
lwz r3, VCPU_GUEST_PID(r4)
mtspr   SPRN_PID, r3
 
-   /* Save vcpu pointer for the exception handlers
-* must be done before loading guest r2.
-*/
-// SET_VCPU(r4)
-
PPC_LL  r11, VCPU_SHARED(r4)
/* Save host mas4 and mas6 and load guest MAS registers */
mfspr   r3, SPRN_MAS4
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 26/37] KVM: PPC: bookehv: fix exit timing

2012-02-24 Thread Alexander Graf
When using exit timing stats, we clobber r9 in the NEED_EMU case,
so better move that part down a few lines and fix it that way.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/bookehv_interrupts.S |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index f7dc3f6..215381e 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -83,10 +83,6 @@
stw r10, VCPU_GUEST_PID(r4)
mtspr   SPRN_PID, r8
 
-   .if \flags  NEED_EMU
-   lwz r9, VCPU_KVM(r4)
-   .endif
-
 #ifdef CONFIG_KVM_EXIT_TIMING
/* save exit time */
 1: mfspr   r7, SPRN_TBRU
@@ -98,6 +94,10 @@
PPC_STL r9, VCPU_TIMING_EXIT_TBU(r4)
 #endif
 
+   .if \flags  NEED_EMU
+   lwz r9, VCPU_KVM(r4)
+   .endif
+
orisr8, r6, MSR_CE@h
 #ifndef CONFIG_64BIT
stw r6, (VCPU_SHARED_MSR + 4)(r11)
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 25/37] KVM: PPC: booke: BOOKE_IRQPRIO_MAX is n+1

2012-02-24 Thread Alexander Graf
The semantics of BOOKE_IRQPRIO_MAX changed to denote the highest available
irqprio + 1, so let's reflect that in the code too.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 3fcec2c..288bc05 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -425,7 +425,7 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
}
 
priority = __ffs(*pending);
-   while (priority = BOOKE_IRQPRIO_MAX) {
+   while (priority  BOOKE_IRQPRIO_MAX) {
if (kvmppc_booke_irqprio_deliver(vcpu, priority))
break;
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 22/37] KVM: PPC: booke: remove leftover debugging

2012-02-24 Thread Alexander Graf
The e500mc patches left some debug code in that we don't need. Remove it.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |5 -
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 9fcc760..17d5318 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -469,11 +469,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
return -EINVAL;
}
 
-   if (!current-thread.kvm_vcpu) {
-   WARN(1, no vcpu\n);
-   return -EPERM;
-   }
-
local_irq_disable();
 
kvmppc_core_prepare_to_enter(vcpu);
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 20/37] KVM: PPC: rename CONFIG_KVM_E500 - CONFIG_KVM_E500V2

2012-02-24 Thread Alexander Graf
The CONFIG_KVM_E500 option really indicates that we're running on a V2 machine,
not on a machine of the generic E500 class. So indicate that properly and
change the config name accordingly.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/Kconfig|8 
 arch/powerpc/kvm/Makefile   |4 ++--
 arch/powerpc/kvm/booke.c|2 +-
 arch/powerpc/kvm/e500.h |6 +++---
 arch/powerpc/kvm/e500_tlb.c |2 +-
 arch/powerpc/kvm/powerpc.c  |8 
 6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 58f6e68..44a998d 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -109,7 +109,7 @@ config KVM_440
 
 config KVM_EXIT_TIMING
bool Detailed exit timing
-   depends on KVM_440 || KVM_E500 || KVM_E500MC
+   depends on KVM_440 || KVM_E500V2 || KVM_E500MC
---help---
  Calculate elapsed time for every exit/enter cycle. A per-vcpu
  report is available in debugfs kvm/vm#_vcpu#_timing.
@@ -118,14 +118,14 @@ config KVM_EXIT_TIMING
 
  If unsure, say N.
 
-config KVM_E500
-   bool KVM support for PowerPC E500 processors
+config KVM_E500V2
+   bool KVM support for PowerPC E500v2 processors
depends on EXPERIMENTAL  E500
select KVM
select KVM_MMIO
---help---
  Support running unmodified E500 guest kernels in virtual machines on
- E500 host processors.
+ E500v2 host processors.
 
  This module provides access to the hardware capabilities through
  a character device node named /dev/kvm.
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index 62febd7..25225ae 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -36,7 +36,7 @@ kvm-e500-objs := \
e500.o \
e500_tlb.o \
e500_emulate.o
-kvm-objs-$(CONFIG_KVM_E500) := $(kvm-e500-objs)
+kvm-objs-$(CONFIG_KVM_E500V2) := $(kvm-e500-objs)
 
 kvm-e500mc-objs := \
$(common-objs-y) \
@@ -98,7 +98,7 @@ kvm-objs-$(CONFIG_KVM_BOOK3S_32) := $(kvm-book3s_32-objs)
 kvm-objs := $(kvm-objs-m) $(kvm-objs-y)
 
 obj-$(CONFIG_KVM_440) += kvm.o
-obj-$(CONFIG_KVM_E500) += kvm.o
+obj-$(CONFIG_KVM_E500V2) += kvm.o
 obj-$(CONFIG_KVM_E500MC) += kvm.o
 obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o
 obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index fcbe928..9fcc760 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -762,7 +762,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
gpa_t gpaddr;
gfn_t gfn;
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
if (!(vcpu-arch.shared-msr  MSR_PR) 
(eaddr  PAGE_MASK) == vcpu-arch.magic_page_ea) {
kvmppc_map_magic(vcpu);
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 3143085..7967f3f 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -39,7 +39,7 @@ struct tlbe_priv {
struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
 };
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
 struct vcpu_id_table;
 #endif
 
@@ -89,7 +89,7 @@ struct kvmppc_vcpu_e500 {
u64 *g2h_tlb1_map;
unsigned int *h2g_tlb1_rmap;
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
u32 pid[E500_PID_NUM];
 
/* vcpu id table */
@@ -136,7 +136,7 @@ void kvmppc_get_sregs_e500_tlb(struct kvm_vcpu *vcpu, 
struct kvm_sregs *sregs);
 int kvmppc_set_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
 
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
 unsigned int kvmppc_e500_get_sid(struct kvmppc_vcpu_e500 *vcpu_e500,
 unsigned int as, unsigned int gid,
 unsigned int pr, int avoid_recursion);
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index e232bb4..279e10a 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -156,7 +156,7 @@ static inline void write_host_tlbe(struct kvmppc_vcpu_e500 
*vcpu_e500,
}
 }
 
-#ifdef CONFIG_KVM_E500
+#ifdef CONFIG_KVM_E500V2
 void kvmppc_map_magic(struct kvm_vcpu *vcpu)
 {
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 58a084f..26c6a8d 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -74,7 +74,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
case HC_VENDOR_KVM | KVM_HC_FEATURES:
r = HC_EV_SUCCESS;
-#if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500)
+#if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
 #endif
@@ -230,7 +230,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case 

[PATCH 21/37] KVM: PPC: make e500v2 kvm and e500mc cpu mutually exclusive

2012-02-24 Thread Alexander Graf
We can't run e500v2 kvm on e500mc kernels, so indicate that by
making the 2 options mutually exclusive in kconfig.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/Kconfig |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 44a998d..f4dacb9 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -120,7 +120,7 @@ config KVM_EXIT_TIMING
 
 config KVM_E500V2
bool KVM support for PowerPC E500v2 processors
-   depends on EXPERIMENTAL  E500
+   depends on EXPERIMENTAL  E500  !PPC_E500MC
select KVM
select KVM_MMIO
---help---
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/37] KVM: PPC: booke: category E.HV (GS-mode) support

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Chips such as e500mc that implement category E.HV in Power ISA 2.06
provide hardware virtualization features, including a new MSR mode for
guest state.  The guest OS can perform many operations without trapping
into the hypervisor, including transitions to and from guest userspace.

Since we can use SRR1[GS] to reliably tell whether an exception came from
guest state, instead of messing around with IVPR, we use DO_KVM similarly
to book3s.

Current issues include:
 - Machine checks from guest state are not routed to the host handler.
 - The guest can cause a host oops by executing an emulated instruction
   in a page that lacks read permission.  Existing e500/4xx support has
   the same problem.

Includes work by Ashish Kalra ashish.ka...@freescale.com,
Varun Sethi varun.se...@freescale.com, and
Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
[agraf: remove pt_regs usage]
Signed-off-by: Alexander Graf ag...@suse.de

---

v1 - v2:

  - ESR - GESR
---
 arch/powerpc/include/asm/dbell.h|1 +
 arch/powerpc/include/asm/kvm_asm.h  |8 +
 arch/powerpc/include/asm/kvm_booke_hv_asm.h |   49 +++
 arch/powerpc/include/asm/kvm_host.h |   19 +-
 arch/powerpc/include/asm/kvm_ppc.h  |3 +
 arch/powerpc/include/asm/mmu-book3e.h   |6 +
 arch/powerpc/include/asm/processor.h|3 +
 arch/powerpc/include/asm/reg.h  |2 +
 arch/powerpc/include/asm/reg_booke.h|   34 ++
 arch/powerpc/kernel/asm-offsets.c   |   15 +-
 arch/powerpc/kernel/head_booke.h|   28 ++-
 arch/powerpc/kvm/Kconfig|3 +
 arch/powerpc/kvm/booke.c|  309 ---
 arch/powerpc/kvm/booke.h|   24 +-
 arch/powerpc/kvm/booke_emulate.c|   23 +-
 arch/powerpc/kvm/bookehv_interrupts.S   |  587 +++
 arch/powerpc/kvm/powerpc.c  |5 +
 arch/powerpc/kvm/timing.h   |6 +
 18 files changed, 1058 insertions(+), 67 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_booke_hv_asm.h
 create mode 100644 arch/powerpc/kvm/bookehv_interrupts.S

diff --git a/arch/powerpc/include/asm/dbell.h b/arch/powerpc/include/asm/dbell.h
index efa74ac..d7365b0 100644
--- a/arch/powerpc/include/asm/dbell.h
+++ b/arch/powerpc/include/asm/dbell.h
@@ -19,6 +19,7 @@
 
 #define PPC_DBELL_MSG_BRDCAST  (0x0400)
 #define PPC_DBELL_TYPE(x)  (((x)  0xf)  (63-36))
+#define PPC_DBELL_LPID(x)  ((x)  (63 - 49))
 enum ppc_dbell {
PPC_DBELL = 0,  /* doorbell */
PPC_DBELL_CRIT = 1, /* critical doorbell */
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 7b1f0e0..0978152 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -48,6 +48,14 @@
 #define BOOKE_INTERRUPT_SPE_FP_DATA 33
 #define BOOKE_INTERRUPT_SPE_FP_ROUND 34
 #define BOOKE_INTERRUPT_PERFORMANCE_MONITOR 35
+#define BOOKE_INTERRUPT_DOORBELL 36
+#define BOOKE_INTERRUPT_DOORBELL_CRITICAL 37
+
+/* booke_hv */
+#define BOOKE_INTERRUPT_GUEST_DBELL 38
+#define BOOKE_INTERRUPT_GUEST_DBELL_CRIT 39
+#define BOOKE_INTERRUPT_HV_SYSCALL 40
+#define BOOKE_INTERRUPT_HV_PRIV 41
 
 /* book3s */
 
diff --git a/arch/powerpc/include/asm/kvm_booke_hv_asm.h 
b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
new file mode 100644
index 000..30a600f
--- /dev/null
+++ b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010-2011 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef ASM_KVM_BOOKE_HV_ASM_H
+#define ASM_KVM_BOOKE_HV_ASM_H
+
+#ifdef __ASSEMBLY__
+
+/*
+ * All exceptions from guest state must go through KVM
+ * (except for those which are delivered directly to the guest) --
+ * there are no exceptions for which we fall through directly to
+ * the normal host handler.
+ *
+ * Expected inputs (normal exceptions):
+ *   SCRATCH0 = saved r10
+ *   r10 = thread struct
+ *   r11 = appropriate SRR1 variant (currently used as scratch)
+ *   r13 = saved CR
+ *   *(r10 + THREAD_NORMSAVE(0)) = saved r11
+ *   *(r10 + THREAD_NORMSAVE(2)) = saved r13
+ *
+ * Expected inputs (crit/mcheck/debug exceptions):
+ *   appropriate SCRATCH = saved r8
+ *   r8 = exception level stack frame
+ *   r9 = *(r8 + _CCR) = saved CR
+ *   r11 = appropriate SRR1 variant (currently used as scratch)
+ *   *(r8 + GPR9) = saved r9
+ *   *(r8 + GPR10) = saved r10 (r10 not yet clobbered)
+ *   *(r8 + GPR11) = saved r11
+ */
+.macro DO_KVM intno srr1
+#ifdef CONFIG_KVM_BOOKE_HV
+BEGIN_FTR_SECTION
+   mtocrf  0x80, r11   /* check MSR[GS] without clobbering reg */
+   bf  3, kvmppc_resume_\intno\()_\srr1
+   b   

[PATCH 17/37] KVM: PPC: e500mc: implicitly set MSR_GS

2012-02-24 Thread Alexander Graf
When setting MSR for an e500mc guest, we implicitly always set MSR_GS
to make sure the guest is in guest state. Since we have this implicit
rule there, we don't need to explicitly pass MSR_GS to set_msr().

Remove all explicit setters of MSR_GS.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   11 +--
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 85bd5b8..fcbe928 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -280,7 +280,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
 unsigned int priority)
 {
int allowed = 0;
-   ulong uninitialized_var(msr_mask);
+   ulong msr_mask = 0;
bool update_esr = false, update_dear = false;
ulong crit_raw = vcpu-arch.shared-critical;
ulong crit_r1 = kvmppc_get_gpr(vcpu, 1);
@@ -322,20 +322,19 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_AP_UNAVAIL:
case BOOKE_IRQPRIO_ALIGNMENT:
allowed = 1;
-   msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
+   msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
break;
case BOOKE_IRQPRIO_CRITICAL:
case BOOKE_IRQPRIO_DBELL_CRIT:
allowed = vcpu-arch.shared-msr  MSR_CE;
allowed = allowed  !crit;
-   msr_mask = MSR_GS | MSR_ME;
+   msr_mask = MSR_ME;
int_class = INT_CLASS_CRIT;
break;
case BOOKE_IRQPRIO_MACHINE_CHECK:
allowed = vcpu-arch.shared-msr  MSR_ME;
allowed = allowed  !crit;
-   msr_mask = MSR_GS;
int_class = INT_CLASS_MC;
break;
case BOOKE_IRQPRIO_DECREMENTER:
@@ -346,13 +345,13 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_DBELL:
allowed = vcpu-arch.shared-msr  MSR_EE;
allowed = allowed  !crit;
-   msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
+   msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
break;
case BOOKE_IRQPRIO_DEBUG:
allowed = vcpu-arch.shared-msr  MSR_DE;
allowed = allowed  !crit;
-   msr_mask = MSR_GS | MSR_ME;
+   msr_mask = MSR_ME;
int_class = INT_CLASS_CRIT;
break;
}
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/37] KVM: PPC: e500mc support

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Add processor support for e500mc, using hardware virtualization support
(GS-mode).

Current issues include:
 - No support for external proxy (coreint) interrupt mode in the guest.

Includes work by Ashish Kalra ashish.ka...@freescale.com,
Varun Sethi varun.se...@freescale.com, and
Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/cputable.h   |6 +-
 arch/powerpc/include/asm/kvm.h|1 +
 arch/powerpc/kernel/cpu_setup_fsl_booke.S |1 +
 arch/powerpc/kernel/head_fsl_booke.S  |   46 
 arch/powerpc/kvm/Kconfig  |   17 ++-
 arch/powerpc/kvm/Makefile |   11 +
 arch/powerpc/kvm/e500.h   |   13 +-
 arch/powerpc/kvm/e500_emulate.c   |   24 ++-
 arch/powerpc/kvm/e500_tlb.c   |   21 ++-
 arch/powerpc/kvm/e500mc.c |  342 +
 arch/powerpc/kvm/powerpc.c|6 +-
 11 files changed, 476 insertions(+), 12 deletions(-)
 create mode 100644 arch/powerpc/kvm/e500mc.c

diff --git a/arch/powerpc/include/asm/cputable.h 
b/arch/powerpc/include/asm/cputable.h
index 2022f2d..598cd24 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -168,6 +168,7 @@ extern const char *powerpc_base_platform;
 #define CPU_FTR_LWSYNC ASM_CONST(0x0800)
 #define CPU_FTR_NOEXECUTE  ASM_CONST(0x1000)
 #define CPU_FTR_INDEXED_DCRASM_CONST(0x2000)
+#define CPU_FTR_EMB_HV ASM_CONST(0x4000)
 
 /*
  * Add the 64-bit processor unique features in the top half of the word;
@@ -386,11 +387,11 @@ extern const char *powerpc_base_platform;
CPU_FTR_NODSISRALIGN | CPU_FTR_NOEXECUTE)
 #define CPU_FTRS_E500MC(CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
-   CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC)
+   CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC | CPU_FTR_EMB_HV)
 #define CPU_FTRS_E5500 (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \
CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \
CPU_FTR_DBELL | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
-   CPU_FTR_DEBUG_LVL_EXC)
+   CPU_FTR_DEBUG_LVL_EXC | CPU_FTR_EMB_HV)
 #define CPU_FTRS_GENERIC_32(CPU_FTR_COMMON | CPU_FTR_NODSISRALIGN)
 
 /* 64-bit CPUs */
@@ -535,6 +536,7 @@ enum {
 #ifdef CONFIG_PPC_E500MC
CPU_FTRS_E500MC  CPU_FTRS_E5500 
 #endif
+   ~CPU_FTR_EMB_HV/* can be removed at runtime */
CPU_FTRS_POSSIBLE,
 };
 #endif /* __powerpc64__ */
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index b921c3f..1bea4d8 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -277,6 +277,7 @@ struct kvm_sync_regs {
 #define KVM_CPU_E500V2 2
 #define KVM_CPU_3S_32  3
 #define KVM_CPU_3S_64  4
+#define KVM_CPU_E500MC 5
 
 /* for KVM_CAP_SPAPR_TCE */
 struct kvm_create_spapr_tce {
diff --git a/arch/powerpc/kernel/cpu_setup_fsl_booke.S 
b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
index 8053db0..69fdd23 100644
--- a/arch/powerpc/kernel/cpu_setup_fsl_booke.S
+++ b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
@@ -73,6 +73,7 @@ _GLOBAL(__setup_cpu_e500v2)
mtlrr4
blr
 _GLOBAL(__setup_cpu_e500mc)
+   mr  r5, r4
mflrr4
bl  __e500_icache_setup
bl  __e500_dcache_setup
diff --git a/arch/powerpc/kernel/head_fsl_booke.S 
b/arch/powerpc/kernel/head_fsl_booke.S
index 418931f..88c0a35 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -380,10 +380,16 @@ interrupt_base:
mtspr   SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
mfspr   r10, SPRN_SPRG_THREAD
stw r11, THREAD_NORMSAVE(0)(r10)
+#ifdef CONFIG_KVM_BOOKE_HV
+BEGIN_FTR_SECTION
+   mfspr   r11, SPRN_SRR1
+END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
+#endif
stw r12, THREAD_NORMSAVE(1)(r10)
stw r13, THREAD_NORMSAVE(2)(r10)
mfcrr13
stw r13, THREAD_NORMSAVE(3)(r10)
+   DO_KVM  BOOKE_INTERRUPT_DTLB_MISS SPRN_SRR1
mfspr   r10, SPRN_DEAR  /* Get faulting address */
 
/* If we are faulting a kernel address, we have to use the
@@ -468,10 +474,16 @@ interrupt_base:
mtspr   SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
mfspr   r10, SPRN_SPRG_THREAD
stw r11, THREAD_NORMSAVE(0)(r10)
+#ifdef CONFIG_KVM_BOOKE_HV
+BEGIN_FTR_SECTION
+   mfspr   r11, SPRN_SRR1
+END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
+#endif
stw r12, THREAD_NORMSAVE(1)(r10)
stw r13, THREAD_NORMSAVE(2)(r10)
mfcrr13
stw r13, THREAD_NORMSAVE(3)(r10)
+

[PATCH 12/37] powerpc/booke: Provide exception macros with interrupt name

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

DO_KVM will need to identify the particular exception type.

There is an existing set of arbitrary numbers that Linux passes,
but it's an undocumented mess that sort of corresponds to server/classic
exception vectors but not really.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kernel/head_44x.S   |   23 +--
 arch/powerpc/kernel/head_booke.h |   41 ++
 arch/powerpc/kernel/head_fsl_booke.S |   52 +-
 3 files changed, 68 insertions(+), 48 deletions(-)

diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
index 7dd2981..d1192c5 100644
--- a/arch/powerpc/kernel/head_44x.S
+++ b/arch/powerpc/kernel/head_44x.S
@@ -248,10 +248,11 @@ _ENTRY(_start);
 
 interrupt_base:
/* Critical Input Interrupt */
-   CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception)
+   CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)
 
/* Machine Check Interrupt */
-   CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
+   CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \
+  machine_check_exception)
MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception)
 
/* Data Storage Interrupt */
@@ -261,7 +262,8 @@ interrupt_base:
INSTRUCTION_STORAGE_EXCEPTION
 
/* External Input Interrupt */
-   EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
+   EXCEPTION(0x0500, BOOKE_INTERRUPT_EXTERNAL, ExternalInput, \
+ do_IRQ, EXC_XFER_LITE)
 
/* Alignment Interrupt */
ALIGNMENT_EXCEPTION
@@ -273,29 +275,32 @@ interrupt_base:
 #ifdef CONFIG_PPC_FPU
FP_UNAVAILABLE_EXCEPTION
 #else
-   EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, 
EXC_XFER_EE)
+   EXCEPTION(0x2010, BOOKE_INTERRUPT_FP_UNAVAIL, \
+ FloatingPointUnavailable, unknown_exception, EXC_XFER_EE)
 #endif
/* System Call Interrupt */
START_EXCEPTION(SystemCall)
-   NORMAL_EXCEPTION_PROLOG
+   NORMAL_EXCEPTION_PROLOG(BOOKE_INTERRUPT_SYSCALL)
EXC_XFER_EE_LITE(0x0c00, DoSyscall)
 
/* Auxiliary Processor Unavailable Interrupt */
-   EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, 
EXC_XFER_EE)
+   EXCEPTION(0x2020, BOOKE_INTERRUPT_AP_UNAVAIL, \
+ AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE)
 
/* Decrementer Interrupt */
DECREMENTER_EXCEPTION
 
/* Fixed Internal Timer Interrupt */
/* TODO: Add FIT support */
-   EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE)
+   EXCEPTION(0x1010, BOOKE_INTERRUPT_FIT, FixedIntervalTimer, \
+ unknown_exception, EXC_XFER_EE)
 
/* Watchdog Timer Interrupt */
/* TODO: Add watchdog support */
 #ifdef CONFIG_BOOKE_WDT
-   CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException)
+   CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, WatchdogException)
 #else
-   CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception)
+   CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, unknown_exception)
 #endif
 
/* Data TLB Error Interrupt */
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index fc921bf..06ab353 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -2,6 +2,8 @@
 #define __HEAD_BOOKE_H__
 
 #include asm/ptrace.h/* for STACK_FRAME_REGS_MARKER */
+#include asm/kvm_asm.h
+
 /*
  * Macros used for common Book-e exception handling
  */
@@ -28,7 +30,7 @@
  */
 #define THREAD_NORMSAVE(offset)(THREAD_NORMSAVES + (offset * 4))
 
-#define NORMAL_EXCEPTION_PROLOG
 \
+#define NORMAL_EXCEPTION_PROLOG(intno) 
 \
mtspr   SPRN_SPRG_WSCRATCH0, r10;   /* save one register */  \
mfspr   r10, SPRN_SPRG_THREAD;   \
stw r11, THREAD_NORMSAVE(0)(r10);\
@@ -113,7 +115,7 @@
  * registers as the normal prolog above. Instead we use a portion of the
  * critical/machine check exception stack at low physical addresses.
  */
-#define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, exc_level_srr0, exc_level_srr1) \
+#define EXC_LEVEL_EXCEPTION_PROLOG(exc_level, intno, exc_level_srr0, 
exc_level_srr1) \
mtspr   SPRN_SPRG_WSCRATCH_##exc_level,r8;   \
BOOKE_LOAD_EXC_LEVEL_STACK(exc_level);/* r8 points to the exc_level 
stack*/ \
stw r9,GPR9(r8);/* save various registers  */\
@@ -162,12 +164,13 @@
SAVE_4GPRS(3, r11);  \
SAVE_2GPRS(7, r11)
 

[PATCH 16/37] KVM: PPC: e500mc: Add doorbell emulation support

2012-02-24 Thread Alexander Graf
When one vcpu wants to kick another, it can issue a special IPI instruction
called msgsnd. This patch emulates this instruction, its clearing counterpart
and the infrastructure required to actually trigger that interrupt inside
a guest vcpu.

With this patch, SMP guests on e500mc work.

Signed-off-by: Alexander Graf ag...@suse.de

---

v1 - v2:

  - introduce and use constants
  - drop e500mc ifdefs
---
 arch/powerpc/include/asm/dbell.h |2 +
 arch/powerpc/kvm/booke.c |2 +
 arch/powerpc/kvm/e500_emulate.c  |   68 ++
 3 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/dbell.h b/arch/powerpc/include/asm/dbell.h
index d7365b0..154c067 100644
--- a/arch/powerpc/include/asm/dbell.h
+++ b/arch/powerpc/include/asm/dbell.h
@@ -19,7 +19,9 @@
 
 #define PPC_DBELL_MSG_BRDCAST  (0x0400)
 #define PPC_DBELL_TYPE(x)  (((x)  0xf)  (63-36))
+#define PPC_DBELL_TYPE_MASKPPC_DBELL_TYPE(0xf)
 #define PPC_DBELL_LPID(x)  ((x)  (63 - 49))
+#define PPC_DBELL_PIR_MASK 0x3fff
 enum ppc_dbell {
PPC_DBELL = 0,  /* doorbell */
PPC_DBELL_CRIT = 1, /* critical doorbell */
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 0b77be1..85bd5b8 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -326,6 +326,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
int_class = INT_CLASS_NONCRIT;
break;
case BOOKE_IRQPRIO_CRITICAL:
+   case BOOKE_IRQPRIO_DBELL_CRIT:
allowed = vcpu-arch.shared-msr  MSR_CE;
allowed = allowed  !crit;
msr_mask = MSR_GS | MSR_ME;
@@ -342,6 +343,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
keep_irq = true;
/* fall through */
case BOOKE_IRQPRIO_EXTERNAL:
+   case BOOKE_IRQPRIO_DBELL:
allowed = vcpu-arch.shared-msr  MSR_EE;
allowed = allowed  !crit;
msr_mask = MSR_GS | MSR_CE | MSR_ME | MSR_DE;
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 98b6c1c..99155f8 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -14,16 +14,74 @@
 
 #include asm/kvm_ppc.h
 #include asm/disassemble.h
+#include asm/dbell.h
 
 #include booke.h
 #include e500.h
 
+#define XOP_MSGSND  206
+#define XOP_MSGCLR  238
 #define XOP_TLBIVAX 786
 #define XOP_TLBSX   914
 #define XOP_TLBRE   946
 #define XOP_TLBWE   978
 #define XOP_TLBILX  18
 
+#ifdef CONFIG_KVM_E500MC
+static int dbell2prio(ulong param)
+{
+   int msg = param  PPC_DBELL_TYPE_MASK;
+   int prio = -1;
+
+   switch (msg) {
+   case PPC_DBELL_TYPE(PPC_DBELL):
+   prio = BOOKE_IRQPRIO_DBELL;
+   break;
+   case PPC_DBELL_TYPE(PPC_DBELL_CRIT):
+   prio = BOOKE_IRQPRIO_DBELL_CRIT;
+   break;
+   default:
+   break;
+   }
+
+   return prio;
+}
+
+static int kvmppc_e500_emul_msgclr(struct kvm_vcpu *vcpu, int rb)
+{
+   ulong param = vcpu-arch.gpr[rb];
+   int prio = dbell2prio(param);
+
+   if (prio  0)
+   return EMULATE_FAIL;
+
+   clear_bit(prio, vcpu-arch.pending_exceptions);
+   return EMULATE_DONE;
+}
+
+static int kvmppc_e500_emul_msgsnd(struct kvm_vcpu *vcpu, int rb)
+{
+   ulong param = vcpu-arch.gpr[rb];
+   int prio = dbell2prio(rb);
+   int pir = param  PPC_DBELL_PIR_MASK;
+   int i;
+   struct kvm_vcpu *cvcpu;
+
+   if (prio  0)
+   return EMULATE_FAIL;
+
+   kvm_for_each_vcpu(i, cvcpu, vcpu-kvm) {
+   int cpir = cvcpu-arch.shared-pir;
+   if ((param  PPC_DBELL_MSG_BRDCAST) || (cpir == pir)) {
+   set_bit(prio, cvcpu-arch.pending_exceptions);
+   kvm_vcpu_kick(cvcpu);
+   }
+   }
+
+   return EMULATE_DONE;
+}
+#endif
+
 int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int inst, int *advance)
 {
@@ -36,6 +94,16 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
case 31:
switch (get_xop(inst)) {
 
+#ifdef CONFIG_KVM_E500MC
+   case XOP_MSGSND:
+   emulated = kvmppc_e500_emul_msgsnd(vcpu, get_rb(inst));
+   break;
+
+   case XOP_MSGCLR:
+   emulated = kvmppc_e500_emul_msgclr(vcpu, get_rb(inst));
+   break;
+#endif
+
case XOP_TLBRE:
emulated = kvmppc_e500_emul_tlbre(vcpu);
break;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/37] KVM: PPC: e500: emulate tlbilx

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

tlbilx is the new, preferred invalidation instruction.  It is not
found on e500 prior to e500mc, but there should be no harm in
supporting it on all e500.

Based on code from Ashish Kalra ashish.ka...@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.h |1 +
 arch/powerpc/kvm/e500_emulate.c |9 ++
 arch/powerpc/kvm/e500_tlb.c |   52 +++
 3 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index f4dee55..ce3f163 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -124,6 +124,7 @@ int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 
*vcpu_e500,
 int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu);
 int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu);
 int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb);
+int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int rt, int ra, int rb);
 int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb);
 int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500);
 void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500);
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index c80794d..af02c18 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -22,6 +22,7 @@
 #define XOP_TLBSX   914
 #define XOP_TLBRE   946
 #define XOP_TLBWE   978
+#define XOP_TLBILX  18
 
 int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int inst, int *advance)
@@ -29,6 +30,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
int emulated = EMULATE_DONE;
int ra;
int rb;
+   int rt;
 
switch (get_op(inst)) {
case 31:
@@ -47,6 +49,13 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
emulated = kvmppc_e500_emul_tlbsx(vcpu,rb);
break;
 
+   case XOP_TLBILX:
+   ra = get_ra(inst);
+   rb = get_rb(inst);
+   rt = get_rt(inst);
+   emulated = kvmppc_e500_emul_tlbilx(vcpu, rt, ra, rb);
+   break;
+
case XOP_TLBIVAX:
ra = get_ra(inst);
rb = get_rb(inst);
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index c8ce51d..6eb5d65 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -631,6 +631,58 @@ int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int 
ra, int rb)
return EMULATE_DONE;
 }
 
+static void tlbilx_all(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel,
+  int pid, int rt)
+{
+   struct kvm_book3e_206_tlb_entry *tlbe;
+   int tid, esel;
+
+   /* invalidate all entries */
+   for (esel = 0; esel  vcpu_e500-gtlb_params[tlbsel].entries; esel++) {
+   tlbe = get_entry(vcpu_e500, tlbsel, esel);
+   tid = get_tlb_tid(tlbe);
+   if (rt == 0 || tid == pid) {
+   inval_gtlbe_on_host(vcpu_e500, tlbsel, esel);
+   kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
+   }
+   }
+}
+
+static void tlbilx_one(struct kvmppc_vcpu_e500 *vcpu_e500, int pid,
+  int ra, int rb)
+{
+   int tlbsel, esel;
+   gva_t ea;
+
+   ea = kvmppc_get_gpr(vcpu_e500-vcpu, rb);
+   if (ra)
+   ea += kvmppc_get_gpr(vcpu_e500-vcpu, ra);
+
+   for (tlbsel = 0; tlbsel  2; tlbsel++) {
+   esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, -1);
+   if (esel = 0) {
+   inval_gtlbe_on_host(vcpu_e500, tlbsel, esel);
+   kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
+   break;
+   }
+   }
+}
+
+int kvmppc_e500_emul_tlbilx(struct kvm_vcpu *vcpu, int rt, int ra, int rb)
+{
+   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+   int pid = get_cur_spid(vcpu);
+
+   if (rt == 0 || rt == 1) {
+   tlbilx_all(vcpu_e500, 0, pid, rt);
+   tlbilx_all(vcpu_e500, 1, pid, rt);
+   } else if (rt == 3) {
+   tlbilx_one(vcpu_e500, pid, ra, rb);
+   }
+
+   return EMULATE_DONE;
+}
+
 int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu)
 {
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/37] KVM: PPC: booke: Move vm core init/destroy out of booke.c

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

e500mc will want to do lpid allocation/deallocation here.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/44x.c   |9 +
 arch/powerpc/kvm/booke.c |9 -
 arch/powerpc/kvm/e500.c  |9 +
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
index 879a1a7..50e7dbc 100644
--- a/arch/powerpc/kvm/44x.c
+++ b/arch/powerpc/kvm/44x.c
@@ -163,6 +163,15 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
kmem_cache_free(kvm_vcpu_cache, vcpu_44x);
 }
 
+int kvmppc_core_init_vm(struct kvm *kvm)
+{
+   return 0;
+}
+
+void kvmppc_core_destroy_vm(struct kvm *kvm)
+{
+}
+
 static int __init kvmppc_44x_init(void)
 {
int r;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index a2456c7..2ee9bae 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -932,15 +932,6 @@ void kvmppc_core_commit_memory_region(struct kvm *kvm,
 {
 }
 
-int kvmppc_core_init_vm(struct kvm *kvm)
-{
-   return 0;
-}
-
-void kvmppc_core_destroy_vm(struct kvm *kvm)
-{
-}
-
 void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr)
 {
vcpu-arch.tcr = new_tcr;
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index 2d5fe04..ac6c9ae 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -226,6 +226,15 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
 }
 
+int kvmppc_core_init_vm(struct kvm *kvm)
+{
+   return 0;
+}
+
+void kvmppc_core_destroy_vm(struct kvm *kvm)
+{
+}
+
 static int __init kvmppc_e500_init(void)
 {
int r, i;
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/37] KVM: PPC: e500: Track TLB1 entries with a bitmap

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Rather than invalidate everything when a TLB1 entry needs to be
taken down, keep track of which host TLB1 entries are used for
a given guest TLB1 entry, and invalidate just those entries.

Based on code from Ashish Kalra ashish.ka...@freescale.com
and Liu Yu yu@freescale.com.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.h |5 +++
 arch/powerpc/kvm/e500_tlb.c |   72 ---
 2 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 34cef08..f4dee55 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -2,6 +2,7 @@
  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu yu@freescale.com
+ * Ashish Kalra ashish.ka...@freescale.com
  *
  * Description:
  * This file is based on arch/powerpc/kvm/44x_tlb.h and
@@ -25,6 +26,7 @@
 
 #define E500_TLB_VALID 1
 #define E500_TLB_DIRTY 2
+#define E500_TLB_BITMAP 4
 
 struct tlbe_ref {
pfn_t pfn;
@@ -82,6 +84,9 @@ struct kvmppc_vcpu_e500 {
struct page **shared_tlb_pages;
int num_shared_tlb_pages;
 
+   u64 *g2h_tlb1_map;
+   unsigned int *h2g_tlb1_rmap;
+
 #ifdef CONFIG_KVM_E500
u32 pid[E500_PID_NUM];
 
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 9925fc6..c8ce51d 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu, yu@freescale.com
+ * Ashish Kalra, ashish.ka...@freescale.com
  *
  * Description:
  * This file is based on arch/powerpc/kvm/44x_tlb.c,
@@ -175,8 +176,28 @@ static void inval_gtlbe_on_host(struct kvmppc_vcpu_e500 
*vcpu_e500,
struct kvm_book3e_206_tlb_entry *gtlbe =
get_entry(vcpu_e500, tlbsel, esel);
 
-   if (tlbsel == 1) {
-   kvmppc_e500_tlbil_all(vcpu_e500);
+   if (tlbsel == 1 
+   vcpu_e500-gtlb_priv[1][esel].ref.flags  E500_TLB_BITMAP) {
+   u64 tmp = vcpu_e500-g2h_tlb1_map[esel];
+   int hw_tlb_indx;
+   unsigned long flags;
+
+   local_irq_save(flags);
+   while (tmp) {
+   hw_tlb_indx = __ilog2_u64(tmp  -tmp);
+   mtspr(SPRN_MAS0,
+ MAS0_TLBSEL(1) |
+ MAS0_ESEL(to_htlb1_esel(hw_tlb_indx)));
+   mtspr(SPRN_MAS1, 0);
+   asm volatile(tlbwe);
+   vcpu_e500-h2g_tlb1_rmap[hw_tlb_indx] = 0;
+   tmp = tmp - 1;
+   }
+   mb();
+   vcpu_e500-g2h_tlb1_map[esel] = 0;
+   vcpu_e500-gtlb_priv[1][esel].ref.flags = ~E500_TLB_BITMAP;
+   local_irq_restore(flags);
+
return;
}
 
@@ -282,6 +303,16 @@ static inline void kvmppc_e500_ref_release(struct tlbe_ref 
*ref)
}
 }
 
+static void clear_tlb1_bitmap(struct kvmppc_vcpu_e500 *vcpu_e500)
+{
+   if (vcpu_e500-g2h_tlb1_map)
+   memset(vcpu_e500-g2h_tlb1_map,
+  sizeof(u64) * vcpu_e500-gtlb_params[1].entries, 0);
+   if (vcpu_e500-h2g_tlb1_rmap)
+   memset(vcpu_e500-h2g_tlb1_rmap,
+  sizeof(unsigned int) * host_tlb_params[1].entries, 0);
+}
+
 static void clear_tlb_privs(struct kvmppc_vcpu_e500 *vcpu_e500)
 {
int tlbsel = 0;
@@ -511,7 +542,7 @@ static void kvmppc_e500_tlb0_map(struct kvmppc_vcpu_e500 
*vcpu_e500,
 /* XXX for both one-one and one-to-many , for now use TLB1 */
 static int kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 *vcpu_e500,
u64 gvaddr, gfn_t gfn, struct kvm_book3e_206_tlb_entry *gtlbe,
-   struct kvm_book3e_206_tlb_entry *stlbe)
+   struct kvm_book3e_206_tlb_entry *stlbe, int esel)
 {
struct tlbe_ref *ref;
unsigned int victim;
@@ -524,6 +555,14 @@ static int kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 
*vcpu_e500,
ref = vcpu_e500-tlb_refs[1][victim];
kvmppc_e500_shadow_map(vcpu_e500, gvaddr, gfn, gtlbe, 1, stlbe, ref);
 
+   vcpu_e500-g2h_tlb1_map[esel] |= (u64)1  victim;
+   vcpu_e500-gtlb_priv[1][esel].ref.flags |= E500_TLB_BITMAP;
+   if (vcpu_e500-h2g_tlb1_rmap[victim]) {
+   unsigned int idx = vcpu_e500-h2g_tlb1_rmap[victim];
+   vcpu_e500-g2h_tlb1_map[idx] = ~(1ULL  victim);
+   }
+   vcpu_e500-h2g_tlb1_rmap[victim] = esel;
+
return victim;
 }
 
@@ -728,7 +767,7 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
 * are mapped on the fly. */
stlbsel = 1;
sesel = kvmppc_e500_tlb1_map(vcpu_e500, eaddr,
-  

[PATCH 07/37] KVM: PPC: e500: merge asm/kvm_e500.h into arch/powerpc/kvm/e500.h

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Keeping two separate headers for e500-specific things was a
pain, and wasn't even organized along any logical boundary.

There was TLB stuff in asm/kvm_e500.h despite the existence of
arch/powerpc/kvm/e500_tlb.h, and nothing in asm/kvm_e500.h needed
to be referenced from outside arch/powerpc/kvm.

Signed-off-by: Scott Wood scottw...@freescale.com
[agraf: fix bisectability]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_e500.h |   96 ---
 arch/powerpc/kvm/e500.c |1 -
 arch/powerpc/kvm/e500.h |   82 --
 arch/powerpc/kvm/e500_emulate.c |1 -
 arch/powerpc/kvm/e500_tlb.c |1 -
 5 files changed, 78 insertions(+), 103 deletions(-)
 delete mode 100644 arch/powerpc/include/asm/kvm_e500.h

diff --git a/arch/powerpc/include/asm/kvm_e500.h 
b/arch/powerpc/include/asm/kvm_e500.h
deleted file mode 100644
index 8cd50a5..000
--- a/arch/powerpc/include/asm/kvm_e500.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
- *
- * Author: Yu Liu, yu@freescale.com
- *
- * Description:
- * This file is derived from arch/powerpc/include/asm/kvm_44x.h,
- * by Hollis Blanchard holl...@us.ibm.com.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_KVM_E500_H__
-#define __ASM_KVM_E500_H__
-
-#include linux/kvm_host.h
-
-#define BOOKE_INTERRUPT_SIZE 36
-
-#define E500_PID_NUM   3
-#define E500_TLB_NUM   2
-
-#define E500_TLB_VALID 1
-#define E500_TLB_DIRTY 2
-
-struct tlbe_ref {
-   pfn_t pfn;
-   unsigned int flags; /* E500_TLB_* */
-};
-
-struct tlbe_priv {
-   struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
-};
-
-struct vcpu_id_table;
-
-struct kvmppc_e500_tlb_params {
-   int entries, ways, sets;
-};
-
-struct kvmppc_vcpu_e500 {
-   /* Unmodified copy of the guest's TLB -- shared with host userspace. */
-   struct kvm_book3e_206_tlb_entry *gtlb_arch;
-
-   /* Starting entry number in gtlb_arch[] */
-   int gtlb_offset[E500_TLB_NUM];
-
-   /* KVM internal information associated with each guest TLB entry */
-   struct tlbe_priv *gtlb_priv[E500_TLB_NUM];
-
-   struct kvmppc_e500_tlb_params gtlb_params[E500_TLB_NUM];
-
-   unsigned int gtlb_nv[E500_TLB_NUM];
-
-   /*
-* information associated with each host TLB entry --
-* TLB1 only for now.  If/when guest TLB1 entries can be
-* mapped with host TLB0, this will be used for that too.
-*
-* We don't want to use this for guest TLB0 because then we'd
-* have the overhead of doing the translation again even if
-* the entry is still in the guest TLB (e.g. we swapped out
-* and back, and our host TLB entries got evicted).
-*/
-   struct tlbe_ref *tlb_refs[E500_TLB_NUM];
-   unsigned int host_tlb1_nv;
-
-   u32 host_pid[E500_PID_NUM];
-   u32 pid[E500_PID_NUM];
-   u32 svr;
-
-   /* vcpu id table */
-   struct vcpu_id_table *idt;
-
-   u32 l1csr0;
-   u32 l1csr1;
-   u32 hid0;
-   u32 hid1;
-   u32 tlb0cfg;
-   u32 tlb1cfg;
-   u64 mcar;
-
-   struct page **shared_tlb_pages;
-   int num_shared_tlb_pages;
-
-   struct kvm_vcpu vcpu;
-};
-
-static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
-{
-   return container_of(vcpu, struct kvmppc_vcpu_e500, vcpu);
-}
-
-#endif /* __ASM_KVM_E500_H__ */
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index 5c450ba..76b35d8 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -20,7 +20,6 @@
 #include asm/reg.h
 #include asm/cputable.h
 #include asm/tlbflush.h
-#include asm/kvm_e500.h
 #include asm/kvm_ppc.h
 
 #include booke.h
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 02ecde2..51d13bd 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -1,11 +1,12 @@
 /*
  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
- * Author: Yu Liu, yu@freescale.com
+ * Author: Yu Liu yu@freescale.com
  *
  * Description:
- * This file is based on arch/powerpc/kvm/44x_tlb.h,
- * by Hollis Blanchard holl...@us.ibm.com.
+ * This file is based on arch/powerpc/kvm/44x_tlb.h and
+ * arch/powerpc/include/asm/kvm_44x.h by Hollis Blanchard holl...@us.ibm.com,
+ * Copyright IBM Corp. 2007-2008
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2, as
@@ -18,7 +19,80 @@
 #include linux/kvm_host.h
 #include asm/mmu-book3e.h
 #include asm/tlb.h
-#include asm/kvm_e500.h
+
+#define E500_PID_NUM   3
+#define E500_TLB_NUM   2
+
+#define E500_TLB_VALID 1
+#define 

[PATCH 06/37] KVM: PPC: e500: rename e500_tlb.h to e500.h

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

This is in preparation for merging in the contents of
arch/powerpc/include/asm/kvm_e500.h.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.c |2 +-
 arch/powerpc/kvm/{e500_tlb.h = e500.h} |6 +++---
 arch/powerpc/kvm/e500_emulate.c |2 +-
 arch/powerpc/kvm/e500_tlb.c |2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
 rename arch/powerpc/kvm/{e500_tlb.h = e500.h} (98%)

diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
index ac6c9ae..5c450ba 100644
--- a/arch/powerpc/kvm/e500.c
+++ b/arch/powerpc/kvm/e500.c
@@ -24,7 +24,7 @@
 #include asm/kvm_ppc.h
 
 #include booke.h
-#include e500_tlb.h
+#include e500.h
 
 void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
 {
diff --git a/arch/powerpc/kvm/e500_tlb.h b/arch/powerpc/kvm/e500.h
similarity index 98%
rename from arch/powerpc/kvm/e500_tlb.h
rename to arch/powerpc/kvm/e500.h
index 5c6d2d7..02ecde2 100644
--- a/arch/powerpc/kvm/e500_tlb.h
+++ b/arch/powerpc/kvm/e500.h
@@ -12,8 +12,8 @@
  * published by the Free Software Foundation.
  */
 
-#ifndef __KVM_E500_TLB_H__
-#define __KVM_E500_TLB_H__
+#ifndef KVM_E500_H
+#define KVM_E500_H
 
 #include linux/kvm_host.h
 #include asm/mmu-book3e.h
@@ -171,4 +171,4 @@ static inline int tlbe_is_host_safe(const struct kvm_vcpu 
*vcpu,
return 1;
 }
 
-#endif /* __KVM_E500_TLB_H__ */
+#endif /* KVM_E500_H */
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index 6d0b2bd..2a1a228 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -17,7 +17,7 @@
 #include asm/kvm_e500.h
 
 #include booke.h
-#include e500_tlb.h
+#include e500.h
 
 #define XOP_TLBIVAX 786
 #define XOP_TLBSX   914
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 6e53e41..1d623a0 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -29,7 +29,7 @@
 #include asm/kvm_e500.h
 
 #include ../mm/mmu_decl.h
-#include e500_tlb.h
+#include e500.h
 #include trace.h
 #include timing.h
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/37] powerpc/e500: split CPU_FTRS_ALWAYS/CPU_FTRS_POSSIBLE

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Split e500 (v1/v2) and e500mc/e5500 to allow optimization of feature
checks that differ between the two.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/cputable.h |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/cputable.h 
b/arch/powerpc/include/asm/cputable.h
index 6a034a2..2022f2d 100644
--- a/arch/powerpc/include/asm/cputable.h
+++ b/arch/powerpc/include/asm/cputable.h
@@ -483,8 +483,10 @@ enum {
CPU_FTRS_E200 |
 #endif
 #ifdef CONFIG_E500
-   CPU_FTRS_E500 | CPU_FTRS_E500_2 | CPU_FTRS_E500MC |
-   CPU_FTRS_E5500 |
+   CPU_FTRS_E500 | CPU_FTRS_E500_2 |
+#endif
+#ifdef CONFIG_PPC_E500MC
+   CPU_FTRS_E500MC | CPU_FTRS_E5500 |
 #endif
0,
 };
@@ -528,8 +530,10 @@ enum {
CPU_FTRS_E200 
 #endif
 #ifdef CONFIG_E500
-   CPU_FTRS_E500  CPU_FTRS_E500_2  CPU_FTRS_E500MC 
-   CPU_FTRS_E5500 
+   CPU_FTRS_E500  CPU_FTRS_E500_2 
+#endif
+#ifdef CONFIG_PPC_E500MC
+   CPU_FTRS_E500MC  CPU_FTRS_E5500 
 #endif
CPU_FTRS_POSSIBLE,
 };
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/37] KVM: PPC: e500: clean up arch/powerpc/kvm/e500.h

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Move vcpu to the beginning of vcpu_e500 to give it appropriate
prominence, especially if more fields end up getting added to the
end of vcpu_e500 (and vcpu ends up in the middle).

Remove gratuitous extern and add parameter names to prototypes.

Signed-off-by: Scott Wood scottw...@freescale.com
[agraf: fix bisectability]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500.h |   25 ++---
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index 51d13bd..a48af00 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -42,6 +42,8 @@ struct kvmppc_e500_tlb_params {
 };
 
 struct kvmppc_vcpu_e500 {
+   struct kvm_vcpu vcpu;
+
/* Unmodified copy of the guest's TLB -- shared with host userspace. */
struct kvm_book3e_206_tlb_entry *gtlb_arch;
 
@@ -85,8 +87,6 @@ struct kvmppc_vcpu_e500 {
 
struct page **shared_tlb_pages;
int num_shared_tlb_pages;
-
-   struct kvm_vcpu vcpu;
 };
 
 static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
@@ -113,19 +113,22 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct 
kvm_vcpu *vcpu)
  (MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3 \
   | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)
 
-extern void kvmppc_dump_tlbs(struct kvm_vcpu *);
-extern int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *, ulong);
-extern int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *);
-extern int kvmppc_e500_emul_tlbre(struct kvm_vcpu *);
-extern int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *, int, int);
-extern int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *, int);
-extern int kvmppc_e500_tlb_search(struct kvm_vcpu *, gva_t, unsigned int, int);
 extern void kvmppc_e500_tlb_put(struct kvm_vcpu *);
 extern void kvmppc_e500_tlb_load(struct kvm_vcpu *, int);
-extern int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *);
-extern void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *);
 extern void kvmppc_e500_tlb_setup(struct kvmppc_vcpu_e500 *);
 extern void kvmppc_e500_recalc_shadow_pid(struct kvmppc_vcpu_e500 *);
+int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *vcpu_e500,
+   ulong value);
+int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu);
+int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu);
+int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb);
+int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb);
+int kvmppc_e500_tlb_search(struct kvm_vcpu *, gva_t, unsigned int, int);
+int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500);
+void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500);
+
+void kvmppc_get_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
+int kvmppc_set_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
 
 /* TLB helper functions */
 static inline unsigned int
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/37] KVM: PPC: factor out lpid allocator from book3s_64_mmu_hv

2012-02-24 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

We'll use it on e500mc as well.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_book3s.h |3 ++
 arch/powerpc/include/asm/kvm_booke.h  |3 ++
 arch/powerpc/include/asm/kvm_ppc.h|5 
 arch/powerpc/kvm/book3s_64_mmu_hv.c   |   26 +---
 arch/powerpc/kvm/powerpc.c|   34 +
 5 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index aa795cc..046041f 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -452,4 +452,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu 
*vcpu)
 
 #define INS_DCBZ   0x7c0007ec
 
+/* LPIDs we support with this build -- runtime limit may be lower */
+#define KVMPPC_NR_LPIDS(LPID_RSVD + 1)
+
 #endif /* __ASM_KVM_BOOK3S_H__ */
diff --git a/arch/powerpc/include/asm/kvm_booke.h 
b/arch/powerpc/include/asm/kvm_booke.h
index a90e091..b7cd335 100644
--- a/arch/powerpc/include/asm/kvm_booke.h
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -23,6 +23,9 @@
 #include linux/types.h
 #include linux/kvm_host.h
 
+/* LPIDs we support with this build -- runtime limit may be lower */
+#define KVMPPC_NR_LPIDS64
+
 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
 {
vcpu-arch.gpr[num] = val;
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 9d6dee0..731e920 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -204,4 +204,9 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
 struct kvm_dirty_tlb *cfg);
 
+long kvmppc_alloc_lpid(void);
+void kvmppc_claim_lpid(long lpid);
+void kvmppc_free_lpid(long lpid);
+void kvmppc_init_lpid(unsigned long nr_lpids);
+
 #endif /* __POWERPC_KVM_PPC_H__ */
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index ddc485a..d031ce1 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -36,13 +36,11 @@
 
 /* POWER7 has 10-bit LPIDs, PPC970 has 6-bit LPIDs */
 #define MAX_LPID_970   63
-#define NR_LPIDS   (LPID_RSVD + 1)
-unsigned long lpid_inuse[BITS_TO_LONGS(NR_LPIDS)];
 
 long kvmppc_alloc_hpt(struct kvm *kvm)
 {
unsigned long hpt;
-   unsigned long lpid;
+   long lpid;
struct revmap_entry *rev;
struct kvmppc_linear_info *li;
 
@@ -72,14 +70,9 @@ long kvmppc_alloc_hpt(struct kvm *kvm)
}
kvm-arch.revmap = rev;
 
-   /* Allocate the guest's logical partition ID */
-   do {
-   lpid = find_first_zero_bit(lpid_inuse, NR_LPIDS);
-   if (lpid = NR_LPIDS) {
-   pr_err(kvm_alloc_hpt: No LPIDs free\n);
-   goto out_freeboth;
-   }
-   } while (test_and_set_bit(lpid, lpid_inuse));
+   lpid = kvmppc_alloc_lpid();
+   if (lpid  0)
+   goto out_freeboth;
 
kvm-arch.sdr1 = __pa(hpt) | (HPT_ORDER - 18);
kvm-arch.lpid = lpid;
@@ -96,7 +89,7 @@ long kvmppc_alloc_hpt(struct kvm *kvm)
 
 void kvmppc_free_hpt(struct kvm *kvm)
 {
-   clear_bit(kvm-arch.lpid, lpid_inuse);
+   kvmppc_free_lpid(kvm-arch.lpid);
vfree(kvm-arch.revmap);
if (kvm-arch.hpt_li)
kvm_release_hpt(kvm-arch.hpt_li);
@@ -171,8 +164,7 @@ int kvmppc_mmu_hv_init(void)
if (!cpu_has_feature(CPU_FTR_HVMODE))
return -EINVAL;
 
-   memset(lpid_inuse, 0, sizeof(lpid_inuse));
-
+   /* POWER7 has 10-bit LPIDs, PPC970 and e500mc have 6-bit LPIDs */
if (cpu_has_feature(CPU_FTR_ARCH_206)) {
host_lpid = mfspr(SPRN_LPID);   /* POWER7 */
rsvd_lpid = LPID_RSVD;
@@ -181,9 +173,11 @@ int kvmppc_mmu_hv_init(void)
rsvd_lpid = MAX_LPID_970;
}
 
-   set_bit(host_lpid, lpid_inuse);
+   kvmppc_init_lpid(rsvd_lpid + 1);
+
+   kvmppc_claim_lpid(host_lpid);
/* rsvd_lpid is reserved for use in partition switching */
-   set_bit(rsvd_lpid, lpid_inuse);
+   kvmppc_claim_lpid(rsvd_lpid);
 
return 0;
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 00d7e34..9806ea5 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -808,6 +808,40 @@ out:
return r;
 }
 
+static unsigned long lpid_inuse[BITS_TO_LONGS(KVMPPC_NR_LPIDS)];
+static unsigned long nr_lpids;
+
+long kvmppc_alloc_lpid(void)
+{
+   long lpid;
+
+   do {
+   lpid = find_first_zero_bit(lpid_inuse, KVMPPC_NR_LPIDS);
+   if (lpid = nr_lpids) {
+   pr_err(%s: No LPIDs 

Re: [PATCH 33/37] KVM: PPC: bookehv: remove unused code

2012-02-24 Thread Scott Wood
On 02/24/2012 08:26 AM, Alexander Graf wrote:
 There was some unused code in the exit code path that must have been
 a leftover from earlier iterations. While it did no hard, it's superfluous
 and thus should be removed.

s/hard/harm/ -- at that assumes exit timing wasn't enabled. :-)

 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  arch/powerpc/kvm/bookehv_interrupts.S |3 ---
  1 files changed, 0 insertions(+), 3 deletions(-)
 
 diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
 b/arch/powerpc/kvm/bookehv_interrupts.S
 index 021d087..b1c099b 100644
 --- a/arch/powerpc/kvm/bookehv_interrupts.S
 +++ b/arch/powerpc/kvm/bookehv_interrupts.S
 @@ -112,9 +112,6 @@
* appropriate for the exception type).
*/
   cmpwr6, r8
 - .if \flags  NEED_EMU
 - lwz r9, KVM_LPID(r9)
 - .endif
   beq 1f
   mfmsr   r7
   .if \srr0 != SPRN_MCSRR0  \srr0 != SPRN_CSRR0

Can also remove lwzr9, VCPU_KVM(r4).

-Scott

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 35/37] KVM: PPC: booke: Support perfmon interrupts

2012-02-24 Thread Scott Wood
On 02/24/2012 08:26 AM, Alexander Graf wrote:
 When during guest context we get a performance monitor interrupt, we
 currently bail out and oops. Let's route it to its correct handler
 instead.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  arch/powerpc/kvm/booke.c |4 
  1 files changed, 4 insertions(+), 0 deletions(-)
 
 diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
 index 7adef28..423701b 100644
 --- a/arch/powerpc/kvm/booke.c
 +++ b/arch/powerpc/kvm/booke.c
 @@ -677,6 +677,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
 kvm_vcpu *vcpu,
   r = RESUME_GUEST;
   break;
  
 + case BOOKE_INTERRUPT_PERFORMANCE_MONITOR:
 + r = RESUME_GUEST;
 + break;
 +
   case BOOKE_INTERRUPT_HV_PRIV:
   r = emulation_exit(run, vcpu);
   break;

Why do we need to call timer_interrupt() explicitly, but can rely on
automatic retriggering for perfmon?

-Scott

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   >