Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support

2013-02-01 Thread Alexander Graf

On 01.02.2013, at 04:49, Bhushan Bharat-R65777 wrote:

 
 
 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org [mailto:kvm-ppc-ow...@vger.kernel.org] On
 Behalf Of Alexander Graf
 Sent: Friday, January 25, 2013 6:08 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support
 
 
 On 16.01.2013, at 09:20, Bharat Bhushan wrote:
 
 This patchset adds the QEMU debug stub support for powerpc (booke/bookehv).
 [1/8] KVM: PPC: booke: use vcpu reference from thread_struct
 - This is a cleanup patch to use vcpu reference from thread struct
 [2/8] KVM: PPC: booke: Allow multiple exception types [3/8] KVM: PPC:
 booke: Added debug handler
 - These two patches install the KVM debug handler.
 [4/8] Added ONE_REG interface for debug instruction
 - Add the ioctl interface to get the debug instruction for
   setting software breakpoint from QEMU debug stub.
 [5/8] KVM: PPC: debug stub interface parameter defined [6/8] booke:
 Added DBCR4 SPR number [7/8] KVM: booke/bookehv: Add debug stub
 support
 - Add the debug stub interface on booke/bookehv [8/8] KVM:PPC:booke:
 Allow debug interrupt injection to guest
 -- with this qemu can inject debug interrupt to guest
 
 Thanks, applied 1/8, 2/8, 6/8.
 
 
 Alex I cannot see these 3 patches on kvm-ppc-next branch. Are those applied 
 on some other branch ?

Yes, my staging tree is now kvm-ppc-queue, as I'm not allowed to rebase 
kvm-ppc-next...


Alex

--
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 3/8] KVM: PPC: booke: Added debug handler

2013-02-01 Thread Alexander Graf

On 01.02.2013, at 06:04, Bhushan Bharat-R65777 wrote:

 
 
 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org [mailto:kvm-ppc-ow...@vger.kernel.org] On
 Behalf Of Alexander Graf
 Sent: Thursday, January 31, 2013 10:38 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 31.01.2013, at 17:58, Bhushan Bharat-R65777 wrote:
 
 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Thursday, January 31, 2013 5:47 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 30.01.2013, at 12:30, Bhushan Bharat-R65777 wrote:
 
 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, January 25, 2013 5:13 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Bhushan
 Bharat-R65777
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 16.01.2013, at 09:24, Bharat Bhushan wrote:
 
 From: Bharat Bhushan bharat.bhus...@freescale.com
 
 Installed debug handler will be used for guest debug support and
 debug facility emulation features (patches for these features will
 follow this patch).
 
 Signed-off-by: Liu Yu yu@freescale.com
 [bharat.bhus...@freescale.com: Substantial changes]
 Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
 ---
 arch/powerpc/include/asm/kvm_host.h |1 +
 arch/powerpc/kernel/asm-offsets.c   |1 +
 arch/powerpc/kvm/booke_interrupts.S |   49 
 ++-
 --
 --
 3 files changed, 44 insertions(+), 7 deletions(-)
 
 diff --git a/arch/powerpc/include/asm/kvm_host.h
 b/arch/powerpc/include/asm/kvm_host.h
 index 8a72d59..f4ba881 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -503,6 +503,7 @@ struct kvm_vcpu_arch {
 u32 tlbcfg[4];
 u32 mmucfg;
 u32 epr;
 +   u32 crit_save;
 struct kvmppc_booke_debug_reg dbg_reg; #endif
 gpa_t paddr_accessed;
 diff --git a/arch/powerpc/kernel/asm-offsets.c
 b/arch/powerpc/kernel/asm-offsets.c
 index 46f6afd..02048f3 100644
 --- a/arch/powerpc/kernel/asm-offsets.c
 +++ b/arch/powerpc/kernel/asm-offsets.c
 @@ -562,6 +562,7 @@ int main(void)
 DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, 
 arch.last_inst));
 DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, 
 arch.fault_dear));
 DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu,
 arch.fault_esr));
 +   DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu,
 +arch.crit_save));
 #endif /* CONFIG_PPC_BOOK3S */
 #endif /* CONFIG_KVM */
 
 diff --git a/arch/powerpc/kvm/booke_interrupts.S
 b/arch/powerpc/kvm/booke_interrupts.S
 index eae8483..dd9c5d4 100644
 --- a/arch/powerpc/kvm/booke_interrupts.S
 +++ b/arch/powerpc/kvm/booke_interrupts.S
 @@ -52,12 +52,7 @@
 (1BOOKE_INTERRUPT_PROGRAM) | \
 (1BOOKE_INTERRUPT_DTLB_MISS))
 
 -.macro KVM_HANDLER ivor_nr scratch srr0
 -_GLOBAL(kvmppc_handler_\ivor_nr)
 -   /* Get pointer to vcpu and record exit number. */
 -   mtspr   \scratch , r4
 -   mfspr   r4, SPRN_SPRG_THREAD
 -   lwz r4, THREAD_KVM_VCPU(r4)
 +.macro __KVM_HANDLER ivor_nr scratch srr0
 stw r3, VCPU_GPR(R3)(r4)
 stw r5, VCPU_GPR(R5)(r4)
 stw r6, VCPU_GPR(R6)(r4)
 @@ -74,6 +69,46 @@ _GLOBAL(kvmppc_handler_\ivor_nr)
 bctr
 .endm
 
 +.macro KVM_HANDLER ivor_nr scratch srr0
 +_GLOBAL(kvmppc_handler_\ivor_nr)
 +   /* Get pointer to vcpu and record exit number. */
 +   mtspr   \scratch , r4
 +   mfspr   r4, SPRN_SPRG_THREAD
 +   lwz r4, THREAD_KVM_VCPU(r4)
 +   __KVM_HANDLER \ivor_nr \scratch \srr0 .endm
 +
 +.macro KVM_DBG_HANDLER ivor_nr scratch srr0
 +_GLOBAL(kvmppc_handler_\ivor_nr)
 +   mtspr   \scratch, r4
 +   mfspr   r4, SPRN_SPRG_THREAD
 +   lwz r4, THREAD_KVM_VCPU(r4)
 +   stw r3, VCPU_CRIT_SAVE(r4)
 +   mfcrr3
 +   mfspr   r4, SPRN_CSRR1
 +   andi.   r4, r4, MSR_PR
 +   bne 1f
 
 
 +   /* debug interrupt happened in enter/exit path */
 +   mfspr   r4, SPRN_CSRR1
 +   rlwinm  r4, r4, 0, ~MSR_DE
 +   mtspr   SPRN_CSRR1, r4
 +   lis r4, 0x
 +   ori r4, r4, 0x
 +   mtspr   SPRN_DBSR, r4
 +   mfspr   r4, SPRN_SPRG_THREAD
 +   lwz r4, THREAD_KVM_VCPU(r4)
 +   mtcrr3
 +   lwz r3, VCPU_CRIT_SAVE(r4)
 +   mfspr   r4, \scratch
 +   rfci
 
 What is this part doing? Try to ignore the debug exit?
 
 As BOOKE doesn't have hardware support for virtualization, hardware
 never know
 current pc is in guest or in host.
 So when enable hardware single step for guest, it cannot be disabled
 at the
 time guest exit. Thus, we'll see that an single step interrupt
 happens at the beginning of guest exit path.
 
 With the above code we 

[PATCH v2] tcm_vhost: Multi-target support

2013-02-01 Thread Asias He
In order to take advantages of Paolo's multi-queue virito-scsi, we need
multi-target support in tcm_vhost first. Otherwise all the requests go
to one queue and other queues are idle.

This patch makes:

1. All the targets under the wwpn is seen and can be used by guest.
2. No need to pass the tpgt number in struct vhost_scsi_target to
   tcm_vhost.ko. Only wwpn is needed.
3. We can always pass max_target = 255 to guest now, since we abort the
   request who's target id does not exist.

Changes in v2:
- Handle non-contiguous tpgt

Signed-off-by: Asias He as...@redhat.com
---
 drivers/vhost/tcm_vhost.c | 117 ++
 drivers/vhost/tcm_vhost.h |   4 +-
 2 files changed, 79 insertions(+), 42 deletions(-)

diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
index 218deb6..f1481f0 100644
--- a/drivers/vhost/tcm_vhost.c
+++ b/drivers/vhost/tcm_vhost.c
@@ -59,8 +59,14 @@ enum {
VHOST_SCSI_VQ_IO = 2,
 };
 
+#define VHOST_SCSI_MAX_TARGET 256
+
 struct vhost_scsi {
-   struct tcm_vhost_tpg *vs_tpg;   /* Protected by vhost_scsi-dev.mutex */
+   /* Protected by vhost_scsi-dev.mutex */
+   struct tcm_vhost_tpg *vs_tpg[VHOST_SCSI_MAX_TARGET];
+   char vs_vhost_wwpn[TRANSPORT_IQN_LEN];
+   bool vs_endpoint;
+
struct vhost_dev dev;
struct vhost_virtqueue vqs[3];
 
@@ -564,13 +570,11 @@ static void vhost_scsi_handle_vq(struct vhost_scsi *vs)
u32 exp_data_len, data_first, data_num, data_direction;
unsigned out, in, i;
int head, ret;
+   u8 target;
 
/* Must use ioctl VHOST_SCSI_SET_ENDPOINT */
-   tv_tpg = vs-vs_tpg;
-   if (unlikely(!tv_tpg)) {
-   pr_err(%s endpoint not set\n, __func__);
+   if (unlikely(!vs-vs_endpoint))
return;
-   }
 
mutex_lock(vq-mutex);
vhost_disable_notify(vs-dev, vq);
@@ -637,6 +641,28 @@ static void vhost_scsi_handle_vq(struct vhost_scsi *vs)
break;
}
 
+   /* Extract the tpgt */
+   target = v_req.lun[1];
+   tv_tpg = vs-vs_tpg[target];
+
+   /* Target does not exist, fail the request */
+   if (unlikely(!tv_tpg)) {
+   struct virtio_scsi_cmd_resp __user *resp;
+   struct virtio_scsi_cmd_resp rsp;
+
+   memset(rsp, 0, sizeof(rsp));
+   rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
+   resp = vq-iov[out].iov_base;
+   ret = __copy_to_user(resp, rsp, sizeof(rsp));
+   if (!ret)
+   vhost_add_used_and_signal(vs-dev,
+   vs-vqs[2], head, 0);
+   else
+   pr_err(Faulted on virtio_scsi_cmd_resp\n);
+
+   continue;
+   }
+
exp_data_len = 0;
for (i = 0; i  data_num; i++)
exp_data_len += vq-iov[data_first + i].iov_len;
@@ -745,6 +771,7 @@ static int vhost_scsi_set_endpoint(
 {
struct tcm_vhost_tport *tv_tport;
struct tcm_vhost_tpg *tv_tpg;
+   bool match = false;
int index;
 
mutex_lock(vs-dev.mutex);
@@ -771,14 +798,11 @@ static int vhost_scsi_set_endpoint(
}
tv_tport = tv_tpg-tport;
 
-   if (!strcmp(tv_tport-tport_name, t-vhost_wwpn) 
-   (tv_tpg-tport_tpgt == t-vhost_tpgt)) {
+   if (!strcmp(tv_tport-tport_name, t-vhost_wwpn)) {
tv_tpg-tv_tpg_vhost_count++;
-   mutex_unlock(tv_tpg-tv_tpg_mutex);
-   mutex_unlock(tcm_vhost_mutex);
 
mutex_lock(vs-dev.mutex);
-   if (vs-vs_tpg) {
+   if (vs-vs_tpg[tv_tpg-tport_tpgt]) {
mutex_unlock(vs-dev.mutex);
mutex_lock(tv_tpg-tv_tpg_mutex);
tv_tpg-tv_tpg_vhost_count--;
@@ -786,15 +810,24 @@ static int vhost_scsi_set_endpoint(
return -EEXIST;
}
 
-   vs-vs_tpg = tv_tpg;
+   vs-vs_tpg[tv_tpg-tport_tpgt] = tv_tpg;
smp_mb__after_atomic_inc();
+   match = true;
mutex_unlock(vs-dev.mutex);
-   return 0;
}
mutex_unlock(tv_tpg-tv_tpg_mutex);
}
mutex_unlock(tcm_vhost_mutex);
-   return -EINVAL;
+
+   mutex_lock(vs-dev.mutex);
+   if (match) {
+   memcpy(vs-vs_vhost_wwpn, t-vhost_wwpn,
+  sizeof(vs-vs_vhost_wwpn));
+   vs-vs_endpoint = true;
+   }
+   mutex_unlock(vs-dev.mutex);
+
+   return 0;
 }
 
 static int 

[PATCH] KVM: PPC: BookE: Handle alignment interrupts

2013-02-01 Thread Alexander Graf
When the guest triggers an alignment interrupt, we don't handle it properly
today and instead BUG_ON(). This really shouldn't happen.

Instead, we should just pass the interrupt back into the guest so it can deal
with it.

Reported-by: Gao Guanhua-B22826 b22...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c|   16 +++-
 arch/powerpc/kvm/booke_interrupts.S |6 --
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index d2f502d..020923e 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -182,6 +182,14 @@ static void kvmppc_core_queue_inst_storage(struct kvm_vcpu 
*vcpu,
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
 }
 
+static void kvmppc_core_queue_alignment(struct kvm_vcpu *vcpu, ulong 
dear_flags,
+   ulong esr_flags)
+{
+   vcpu-arch.queued_dear = dear_flags;
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ALIGNMENT);
+}
+
 void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags)
 {
vcpu-arch.queued_esr = esr_flags;
@@ -345,6 +353,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
switch (priority) {
case BOOKE_IRQPRIO_DTLB_MISS:
case BOOKE_IRQPRIO_DATA_STORAGE:
+   case BOOKE_IRQPRIO_ALIGNMENT:
update_dear = true;
/* fall through */
case BOOKE_IRQPRIO_INST_STORAGE:
@@ -358,7 +367,6 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_SPE_FP_DATA:
case BOOKE_IRQPRIO_SPE_FP_ROUND:
case BOOKE_IRQPRIO_AP_UNAVAIL:
-   case BOOKE_IRQPRIO_ALIGNMENT:
allowed = 1;
msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
@@ -971,6 +979,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
r = RESUME_GUEST;
break;
 
+   case BOOKE_INTERRUPT_ALIGNMENT:
+   kvmppc_core_queue_alignment(vcpu, vcpu-arch.fault_dear,
+   vcpu-arch.fault_esr);
+   r = RESUME_GUEST;
+   break;
+
 #ifdef CONFIG_KVM_BOOKE_HV
case BOOKE_INTERRUPT_HV_SYSCALL:
if (!(vcpu-arch.shared-msr  MSR_PR)) {
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index eae8483..7fa4167 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -45,12 +45,14 @@
 (1BOOKE_INTERRUPT_DEBUG))
 
 #define NEED_DEAR_MASK ((1BOOKE_INTERRUPT_DATA_STORAGE) | \
-(1BOOKE_INTERRUPT_DTLB_MISS))
+(1BOOKE_INTERRUPT_DTLB_MISS)) | \
+(1BOOKE_INTERRUPT_ALIGNMENT))
 
 #define NEED_ESR_MASK ((1BOOKE_INTERRUPT_DATA_STORAGE) | \
(1BOOKE_INTERRUPT_INST_STORAGE) | \
(1BOOKE_INTERRUPT_PROGRAM) | \
-   (1BOOKE_INTERRUPT_DTLB_MISS))
+   (1BOOKE_INTERRUPT_DTLB_MISS)) | \
+   (1BOOKE_INTERRUPT_ALIGNMENT))
 
 .macro KVM_HANDLER ivor_nr scratch srr0
 _GLOBAL(kvmppc_handler_\ivor_nr)
-- 
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


Re: [PATCH 7/8] KVM: PPC: booke/bookehv: Add debug stub support

2013-02-01 Thread Alexander Graf

On 01.02.2013, at 07:31, Bhushan Bharat-R65777 wrote:

 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, January 25, 2013 5:37 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 7/8] KVM: PPC: booke/bookehv: Add debug stub support
 
 
 On 16.01.2013, at 09:24, Bharat Bhushan wrote:
 
 This patch adds the debug stub support on booke/bookehv.
 Now QEMU debug stub can use hw breakpoint, watchpoint and software
 breakpoint to debug guest.
 
 Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
 ---
 arch/powerpc/include/asm/kvm_host.h   |5 +
 arch/powerpc/include/asm/kvm_ppc.h|2 +
 arch/powerpc/include/uapi/asm/kvm.h   |   22 -
 arch/powerpc/kernel/asm-offsets.c |   26 ++
 arch/powerpc/kvm/booke.c  |  124 +
 arch/powerpc/kvm/booke_interrupts.S   |  114 ++
 arch/powerpc/kvm/bookehv_interrupts.S |  145 
 -
 arch/powerpc/kvm/e500_emulate.c   |6 ++
 arch/powerpc/kvm/e500mc.c |3 +-
 9 files changed, 422 insertions(+), 25 deletions(-)
 
 diff --git a/arch/powerpc/include/asm/kvm_host.h
 b/arch/powerpc/include/asm/kvm_host.h
 index f4ba881..a9feeb0 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -504,7 +504,12 @@ struct kvm_vcpu_arch {
 u32 mmucfg;
 u32 epr;
 u32 crit_save;
 +   /* guest debug registers*/
 struct kvmppc_booke_debug_reg dbg_reg;
 +   /* shadow debug registers */
 +   struct kvmppc_booke_debug_reg shadow_dbg_reg;
 +   /* host debug registers*/
 +   struct kvmppc_booke_debug_reg host_dbg_reg;
 #endif
 gpa_t paddr_accessed;
 gva_t vaddr_accessed;
 diff --git a/arch/powerpc/include/asm/kvm_ppc.h
 b/arch/powerpc/include/asm/kvm_ppc.h
 index b3c481e..e4b3398 100644
 --- a/arch/powerpc/include/asm/kvm_ppc.h
 +++ b/arch/powerpc/include/asm/kvm_ppc.h
 @@ -45,6 +45,8 @@ enum emulation_result {
 EMULATE_FAIL, /* can't emulate this instruction */
 EMULATE_AGAIN,/* something went wrong. go again */
 EMULATE_DO_PAPR,  /* kvm_run filled with PAPR request */
 +   EMULATE_DEBUG_INST,   /* debug instruction for software
 +breakpoint, exit to userspace */
 
 Does this do something different from DO_PAPR? Maybe it makes sense to have 
 an
 exit code EMULATE_EXIT_USER?
 
 I think EMULATE_DO_PAPR does something similar but the name is confusing. May 
 be we can rename EMULATE_DO_PAPR to 
 EMULATE_EXIT_USER.

Yeah, please check that it actually does the right thing still for PAPR exits 
then :).


Alex

--
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 V4 RESEND 00/22] Multiqueue virtio-net

2013-02-01 Thread Jason Wang
On 02/01/2013 03:39 PM, Jason Wang wrote:
 Hello all:

 This seires is an update of last version of multiqueue virtio-net support.

Hi Anthony:

This series is not applied cleanly on master, could you please pick
those for 1.4?

Thanks
--
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] tcm_vhost: Multi-target support

2013-02-01 Thread Asias He
On 02/01/2013 03:38 PM, Nicholas A. Bellinger wrote:
 On Fri, 2013-02-01 at 12:03 +0800, Asias He wrote:
 On 02/01/2013 04:59 AM, Nicholas A. Bellinger wrote:
 On Thu, 2013-01-31 at 17:28 +0800, Asias He wrote:
 Hello Nicholas,

 On 01/31/2013 03:33 PM, Asias He wrote:
 In order to take advantages of Paolo's multi-queue virito-scsi, we need
 multi-target support in tcm_vhost first. Otherwise all the requests go
 to one queue and other queues are idle.

 
 SNIP
 
 @@ -771,14 +799,11 @@ static int vhost_scsi_set_endpoint(
   }
   tv_tport = tv_tpg-tport;
  
 - if (!strcmp(tv_tport-tport_name, t-vhost_wwpn) 
 - (tv_tpg-tport_tpgt == t-vhost_tpgt)) {
 + if (!strcmp(tv_tport-tport_name, t-vhost_wwpn)) {
   tv_tpg-tv_tpg_vhost_count++;
 - mutex_unlock(tv_tpg-tv_tpg_mutex);
 - mutex_unlock(tcm_vhost_mutex);
  
   mutex_lock(vs-dev.mutex);
 - if (vs-vs_tpg) {
 + if (vs-vs_tpg[tv_tpg-tport_tpgt - 1]) {
   mutex_unlock(vs-dev.mutex);
   mutex_lock(tv_tpg-tv_tpg_mutex);
   tv_tpg-tv_tpg_vhost_count--;
 @@ -786,15 +811,17 @@ static int vhost_scsi_set_endpoint(
   return -EEXIST;
   }
  
 - vs-vs_tpg = tv_tpg;
 + vs-vs_tpg[tv_tpg-tport_tpgt - 1] = tv_tpg;


 tv_tpg-tport_tpgt starts from 0, right? I thought it starts from 1,
 because I always got it starts from 1 in targetcli.

 o- vhost
o- naa.6001405bd4e8476d
   o- tpg1
  o- luns
 o- lun0
   o- tpg2
  o- luns
 o- lun0
   o- tpg3
  o- luns
 o- lun0
   o- tpg4
  o- luns
 o- lun0


 So at least with iscsi-target, we start from tpgt=1 to avoid some legacy
 initiators that have issues handling tgpt=0.

 Given that rtslib/targetcli currently expect this with the tpgs
 feature is enabled, starting from tpgt=1 with tcm_vhost probably makes
 the most sense.

 Okay. But tgpt can be 0, right?

 
 Most certainly, in the end it's totally up to the fabric.  ;)

okay.

  
 I saw this setup:

   cd /sys/kernel/config/target
   mkdir -p core/fileio_0/fileio
   echo 'fd_dev_name=/home/pbonzini/test.img,fd_dev_size=5905580032' 
 core/fileio_0/fileio/control
   echo 1  core/fileio_0/fileio/enable
   mkdir -p vhost/naa.600140554cf3a18e/tpgt_0/lun/lun_0
   cd vhost/naa.600140554cf3a18e/tpgt_0
   ln -sf ../../../../../core/fileio_0/fileio/ lun/lun_0/virtual_scsi_port
   echo naa.60014053226f0388  nexus

 And this:

** Setup wwpn and tpgt
$ wwpn=naa.0
$ tpgt=/sys/kernel/config/target/vhost/$wwpn/tpgt_0
$ nexus=$tpgt/nexus
$ mkdir -p $tpgt
$ echo -n $wwpn  $nexus


 
 OK, I think you'll want to avoid the extra vs-vs_tpg[tpgt - 1] offset
 above to properly support this.

Yes. Already did that.

 --nab
 

 If it is true. I will cook v2 of this patch.

 Also, the tv_tpg-tport_tpgt can be none-continuous. e.g.

 o- vhost
o- naa.6001405bd4e8476d
   o- tpg1
  o- luns
 o- lun0
   o- tpg2
  o- luns
 o- lun0
   o- tpg4
  o- luns
 o- lun0

 I will handle this in v2.


 Correct, tpgt values may be optionally non-contiguous up to unsigned
 short.

 ok.

 --nab




 
 


-- 
Asias
--
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] KVM: VMX: disable SMEP feature when guest is in non-paging mode

2013-02-01 Thread Dongxiao Xu
SMEP is disabled if CPU is in non-paging mode in hardware.
However KVM always uses paging mode to emulate guest non-paging
mode with HAP. To emulate this behavior, SMEP needs to be manually
disabled when guest switches to non-paging mode.

We met an issue that, SMP Linux guest with recent kernel (enable
SMEP support, for example, 3.5.3) would crash with triple fault if
setting unrestricted_guest=0. This is because KVM uses an identity
mapping page table to emulate the non-paging mode, where the page
table is set with USER flag. If SMEP is still enabled in this case,
guest will meet unhandlable page fault and then crash.

Signed-off-by: Dongxiao Xu dongxiao...@intel.com
Signed-off-by: Xiantao Zhang xiantao.zh...@intel.com
---
 arch/x86/kvm/vmx.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 9120ae1..e82f20d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3155,6 +3155,14 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned 
long cr4)
if (!is_paging(vcpu)) {
hw_cr4 = ~X86_CR4_PAE;
hw_cr4 |= X86_CR4_PSE;
+   /*
+* SMEP is disabled if CPU is in non-paging mode in
+* hardware. However KVM always uses paging mode to
+* emulate guest non-paging mode with HAP.
+* To emulate this behavior, SMEP needs to be manually
+* disabled when guest switches to non-paging mode.
+*/
+   hw_cr4 = ~X86_CR4_SMEP;
} else if (!(cr4  X86_CR4_PAE)) {
hw_cr4 = ~X86_CR4_PAE;
}
-- 
1.7.1

--
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 3/8] KVM: PPC: booke: Added debug handler

2013-02-01 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, February 01, 2013 1:36 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 01.02.2013, at 06:04, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
  Sent: Thursday, January 31, 2013 10:38 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org
  Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
  On 31.01.2013, at 17:58, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: Alexander Graf [mailto:ag...@suse.de]
  Sent: Thursday, January 31, 2013 5:47 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org
  Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
  On 30.01.2013, at 12:30, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: Alexander Graf [mailto:ag...@suse.de]
  Sent: Friday, January 25, 2013 5:13 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Bhushan
  Bharat-R65777
  Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
  On 16.01.2013, at 09:24, Bharat Bhushan wrote:
 
  From: Bharat Bhushan bharat.bhus...@freescale.com
 
  Installed debug handler will be used for guest debug support and
  debug facility emulation features (patches for these features
  will follow this patch).
 
  Signed-off-by: Liu Yu yu@freescale.com
  [bharat.bhus...@freescale.com: Substantial changes]
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  ---
  arch/powerpc/include/asm/kvm_host.h |1 +
  arch/powerpc/kernel/asm-offsets.c   |1 +
  arch/powerpc/kvm/booke_interrupts.S |   49
 ++-
  --
  --
  3 files changed, 44 insertions(+), 7 deletions(-)
 
  diff --git a/arch/powerpc/include/asm/kvm_host.h
  b/arch/powerpc/include/asm/kvm_host.h
  index 8a72d59..f4ba881 100644
  --- a/arch/powerpc/include/asm/kvm_host.h
  +++ b/arch/powerpc/include/asm/kvm_host.h
  @@ -503,6 +503,7 @@ struct kvm_vcpu_arch {
u32 tlbcfg[4];
u32 mmucfg;
u32 epr;
  + u32 crit_save;
struct kvmppc_booke_debug_reg dbg_reg; #endif
gpa_t paddr_accessed;
  diff --git a/arch/powerpc/kernel/asm-offsets.c
  b/arch/powerpc/kernel/asm-offsets.c
  index 46f6afd..02048f3 100644
  --- a/arch/powerpc/kernel/asm-offsets.c
  +++ b/arch/powerpc/kernel/asm-offsets.c
  @@ -562,6 +562,7 @@ int main(void)
DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, 
  arch.last_inst));
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu,
 arch.fault_dear));
DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu,
  arch.fault_esr));
  + DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu,
  +arch.crit_save));
  #endif /* CONFIG_PPC_BOOK3S */
  #endif /* CONFIG_KVM */
 
  diff --git a/arch/powerpc/kvm/booke_interrupts.S
  b/arch/powerpc/kvm/booke_interrupts.S
  index eae8483..dd9c5d4 100644
  --- a/arch/powerpc/kvm/booke_interrupts.S
  +++ b/arch/powerpc/kvm/booke_interrupts.S
  @@ -52,12 +52,7 @@
  (1BOOKE_INTERRUPT_PROGRAM) | \
  (1BOOKE_INTERRUPT_DTLB_MISS))
 
  -.macro KVM_HANDLER ivor_nr scratch srr0
  -_GLOBAL(kvmppc_handler_\ivor_nr)
  - /* Get pointer to vcpu and record exit number. */
  - mtspr   \scratch , r4
  - mfspr   r4, SPRN_SPRG_THREAD
  - lwz r4, THREAD_KVM_VCPU(r4)
  +.macro __KVM_HANDLER ivor_nr scratch srr0
stw r3, VCPU_GPR(R3)(r4)
stw r5, VCPU_GPR(R5)(r4)
stw r6, VCPU_GPR(R6)(r4)
  @@ -74,6 +69,46 @@ _GLOBAL(kvmppc_handler_\ivor_nr)
bctr
  .endm
 
  +.macro KVM_HANDLER ivor_nr scratch srr0
  +_GLOBAL(kvmppc_handler_\ivor_nr)
  + /* Get pointer to vcpu and record exit number. */
  + mtspr   \scratch , r4
  + mfspr   r4, SPRN_SPRG_THREAD
  + lwz r4, THREAD_KVM_VCPU(r4)
  + __KVM_HANDLER \ivor_nr \scratch \srr0 .endm
  +
  +.macro KVM_DBG_HANDLER ivor_nr scratch srr0
  +_GLOBAL(kvmppc_handler_\ivor_nr)
  + mtspr   \scratch, r4
  + mfspr   r4, SPRN_SPRG_THREAD
  + lwz r4, THREAD_KVM_VCPU(r4)
  + stw r3, VCPU_CRIT_SAVE(r4)
  + mfcrr3
  + mfspr   r4, SPRN_CSRR1
  + andi.   r4, r4, MSR_PR
  + bne 1f
 
 
  + /* debug interrupt happened in enter/exit path */
  + mfspr   r4, SPRN_CSRR1
  + rlwinm  r4, r4, 0, ~MSR_DE
  + mtspr   SPRN_CSRR1, r4
  + lis r4, 0x
  + ori r4, r4, 0x
  + mtspr   SPRN_DBSR, r4
  + mfspr   r4, SPRN_SPRG_THREAD
  + lwz r4, THREAD_KVM_VCPU(r4)
  + mtcrr3
  + lwz r3, VCPU_CRIT_SAVE(r4)
  + mfspr   r4, \scratch
  + rfci
 
  What is this part doing? Try to ignore the debug exit?
 
  As BOOKE doesn't have hardware support 

RE: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support

2013-02-01 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, February 01, 2013 1:34 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org
 Subject: Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support
 
 
 On 01.02.2013, at 04:49, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
  Sent: Friday, January 25, 2013 6:08 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Bhushan
  Bharat-R65777
  Subject: Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub
  support
 
 
  On 16.01.2013, at 09:20, Bharat Bhushan wrote:
 
  This patchset adds the QEMU debug stub support for powerpc 
  (booke/bookehv).
  [1/8] KVM: PPC: booke: use vcpu reference from thread_struct
- This is a cleanup patch to use vcpu reference from thread struct
  [2/8] KVM: PPC: booke: Allow multiple exception types [3/8] KVM: PPC:
  booke: Added debug handler
- These two patches install the KVM debug handler.
  [4/8] Added ONE_REG interface for debug instruction
- Add the ioctl interface to get the debug instruction for
  setting software breakpoint from QEMU debug stub.
  [5/8] KVM: PPC: debug stub interface parameter defined [6/8] booke:
  Added DBCR4 SPR number [7/8] KVM: booke/bookehv: Add debug stub
  support
- Add the debug stub interface on booke/bookehv [8/8] KVM:PPC:booke:
  Allow debug interrupt injection to guest
-- with this qemu can inject debug interrupt to guest
 
  Thanks, applied 1/8, 2/8, 6/8.
 
 
  Alex I cannot see these 3 patches on kvm-ppc-next branch. Are those applied 
  on
 some other branch ?
 
 Yes, my staging tree is now kvm-ppc-queue, as I'm not allowed to rebase 
 kvm-ppc-
 next...

On which branch we should send our patches on kvm-ppc-queue or kmv-ppc-next?

Thanks
-Bharat

--
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 v2 2/3] VFIO-AER: Vfio-pci driver changes for supporting AER

2013-02-01 Thread Pandarathil, Vijaymohan R


 -Original Message-
 From: Alex Williamson [mailto:alex.william...@redhat.com]
 Sent: Tuesday, January 29, 2013 5:25 AM
 To: Pandarathil, Vijaymohan R
 Cc: Gleb Natapov; Bjorn Helgaas; Blue Swirl; Ortiz, Lance E;
 kvm@vger.kernel.org; qemu-de...@nongnu.org; linux-...@vger.kernel.org;
 linux-ker...@vger.kernel.org
 Subject: Re: [PATCH v2 2/3] VFIO-AER: Vfio-pci driver changes for
 supporting AER
 
 On Mon, 2013-01-28 at 12:31 -0700, Alex Williamson wrote:
  On Mon, 2013-01-28 at 09:54 +, Pandarathil, Vijaymohan R wrote:
 - New VFIO_SET_IRQ ioctl option to pass the eventfd that is signalled
 when
 an error occurs in the vfio_pci_device
  
 - Register pci_error_handler for the vfio_pci driver
  
 - When the device encounters an error, the error handler registered
 by
 the vfio_pci driver gets invoked by the AER infrastructure
  
 - In the error handler, signal the eventfd registered for the device.
  
 - This results in the qemu eventfd handler getting invoked and
 appropriate action taken for the guest.
  
   Signed-off-by: Vijay Mohan Pandarathil vijaymohan.pandarat...@hp.com
   ---
drivers/vfio/pci/vfio_pci.c | 44
 -
drivers/vfio/pci/vfio_pci_intrs.c   | 32 +++
drivers/vfio/pci/vfio_pci_private.h |  1 +
include/uapi/linux/vfio.h   |  3 +++
4 files changed, 79 insertions(+), 1 deletion(-)
  
   diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
   index b28e66c..ff2a078 100644
   --- a/drivers/vfio/pci/vfio_pci.c
   +++ b/drivers/vfio/pci/vfio_pci.c
   @@ -196,7 +196,9 @@ static int vfio_pci_get_irq_count(struct
 vfio_pci_device *vdev, int irq_type)
  
 return (flags  PCI_MSIX_FLAGS_QSIZE) + 1;
 }
   - }
   + } else if (irq_type == VFIO_PCI_ERR_IRQ_INDEX)
   + if (pci_is_pcie(vdev-pdev))
   + return 1;
  
 return 0;
}
   @@ -223,9 +225,18 @@ static long vfio_pci_ioctl(void *device_data,
 if (vdev-reset_works)
 info.flags |= VFIO_DEVICE_FLAGS_RESET;
  
   + if (pci_is_pcie(vdev-pdev)) {
   + info.flags |= VFIO_DEVICE_FLAGS_PCI_AER;
   + info.flags |= VFIO_DEVICE_FLAGS_PCI_AER_NOTIFY;
 
  Not sure this second flag should be AER specific or if it's even needed,
  see below for more comments on this.
 
   + }
   +
 info.num_regions = VFIO_PCI_NUM_REGIONS;
 info.num_irqs = VFIO_PCI_NUM_IRQS;
  
   + /* Expose only implemented IRQs */
   + if (!(info.flags  VFIO_DEVICE_FLAGS_PCI_AER_NOTIFY))
   + info.num_irqs--;
 
  I'm having second thoughts on this, see further below.
 
   +
 return copy_to_user((void __user *)arg, info, minsz);
  
 } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
   @@ -302,6 +313,10 @@ static long vfio_pci_ioctl(void *device_data,
 if (info.argsz  minsz || info.index = VFIO_PCI_NUM_IRQS)
 return -EINVAL;
  
   + if ((info.index == VFIO_PCI_ERR_IRQ_INDEX) 
   +  !pci_is_pcie(vdev-pdev))
   + return -EINVAL;
   +
 
  Perhaps we could incorporate the index test above this too?
 
  switch (info.index) {
  case VFIO_PCI_INTX_IRQ_INDEX: ... VFIO_PCI_MSIX_IRQ_INDEX:
  break;
  case VFIO_PCI_ERR_IRQ_INDEX:
  if (pci_is_pcie(vdev-pdev))
  break;
  default:
  return -EINVAL;
  }
 
  This is more similar to how I've re-written the same for the proposed
  VGA/legacy I/O support.
 
 info.flags = VFIO_IRQ_INFO_EVENTFD;
  
 info.count = vfio_pci_get_irq_count(vdev, info.index);
   @@ -538,11 +553,38 @@ static void vfio_pci_remove(struct pci_dev *pdev)
 kfree(vdev);
}
  
   +static pci_ers_result_t vfio_err_detected(struct pci_dev *pdev,
   + pci_channel_state_t state)
 
  This is actually AER specific, right?  So perhaps it should be
  vfio_pci_aer_err_detected?
 
  Also, please follow existing whitespace usage throughout, tabs followed
  by spaces to align function parameter wrap.
 
   +{
   + struct vfio_pci_device *vpdev;
   + void *vdev;
 
  struct vfio_device *vdev;
 
   +
   + vdev = vfio_device_get_from_dev(pdev-dev);
   + if (vdev == NULL)
   + return PCI_ERS_RESULT_DISCONNECT;
   +
   + vpdev = vfio_device_data(vdev);
   + if (vpdev == NULL)
   + return PCI_ERS_RESULT_DISCONNECT;
   +
   + if (vpdev-err_trigger)
   + eventfd_signal(vpdev-err_trigger, 1);
   +
   + vfio_device_put_vdev(vdev);
   +
   + return PCI_ERS_RESULT_CAN_RECOVER;
   +}
   +
   +static const struct pci_error_handlers vfio_err_handlers = {
   + .error_detected = vfio_err_detected,
   +};
   +
static struct pci_driver vfio_pci_driver = {
 .name   = vfio-pci,
 .id_table   = NULL, /* only dynamic ids */
 .probe  = vfio_pci_probe,
 

[PATCH qom-cpu-next 3/6] cpu: Move exit_request field to CPUState

2013-02-01 Thread Andreas Färber
Since it was located before breakpoints field, it needs to be reset.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c  |8 
 exec.c  |4 +++-
 hw/spapr_hcall.c|5 +++--
 include/exec/cpu-defs.h |2 --
 include/qom/cpu.h   |2 ++
 kvm-all.c   |6 +++---
 qom/cpu.c   |1 +
 target-i386/kvm.c   |4 ++--
 8 Dateien geändert, 18 Zeilen hinzugefügt(+), 14 Zeilen entfernt(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 19ebb4a..32f3559 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -198,7 +198,7 @@ int cpu_exec(CPUArchState *env)
 cpu_single_env = env;
 
 if (unlikely(exit_request)) {
-env-exit_request = 1;
+cpu-exit_request = 1;
 }
 
 #if defined(TARGET_I386)
@@ -539,8 +539,8 @@ int cpu_exec(CPUArchState *env)
 next_tb = 0;
 }
 }
-if (unlikely(env-exit_request)) {
-env-exit_request = 0;
+if (unlikely(cpu-exit_request)) {
+cpu-exit_request = 0;
 env-exception_index = EXCP_INTERRUPT;
 cpu_loop_exit(env);
 }
@@ -593,7 +593,7 @@ int cpu_exec(CPUArchState *env)
starting execution if there is a pending interrupt. */
 env-current_tb = tb;
 barrier();
-if (likely(!env-exit_request)) {
+if (likely(!cpu-exit_request)) {
 tc_ptr = tb-tc_ptr;
 /* execute the generated code */
 next_tb = tcg_qemu_tb_exec(env, tc_ptr);
diff --git a/exec.c b/exec.c
index b85508b..dbb893a 100644
--- a/exec.c
+++ b/exec.c
@@ -492,7 +492,9 @@ void cpu_reset_interrupt(CPUArchState *env, int mask)
 
 void cpu_exit(CPUArchState *env)
 {
-env-exit_request = 1;
+CPUState *cpu = ENV_GET_CPU(env);
+
+cpu-exit_request = 1;
 cpu_unlink_tb(env);
 }
 
diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c
index 2889742..af1db6e 100644
--- a/hw/spapr_hcall.c
+++ b/hw/spapr_hcall.c
@@ -513,13 +513,14 @@ static target_ulong h_cede(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
target_ulong opcode, target_ulong *args)
 {
 CPUPPCState *env = cpu-env;
+CPUState *cs = CPU(cpu);
 
 env-msr |= (1ULL  MSR_EE);
 hreg_compute_hflags(env);
-if (!cpu_has_work(CPU(cpu))) {
+if (!cpu_has_work(cs)) {
 env-halted = 1;
 env-exception_index = EXCP_HLT;
-env-exit_request = 1;
+cs-exit_request = 1;
 }
 return H_SUCCESS;
 }
diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index ba814ff..ca39f05 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -26,7 +26,6 @@
 #include config.h
 #include setjmp.h
 #include inttypes.h
-#include signal.h
 #include qemu/osdep.h
 #include qemu/queue.h
 #include exec/hwaddr.h
@@ -160,7 +159,6 @@ typedef struct CPUWatchpoint {
  memory was accessed */ \
 uint32_t halted; /* Nonzero if the CPU is in suspend state */   \
 uint32_t interrupt_request; \
-volatile sig_atomic_t exit_request; \
 CPU_COMMON_TLB  \
 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];   \
 /* buffer for temporaries in the code generator */  \
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index c465d88..42f3f34 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -20,6 +20,7 @@
 #ifndef QEMU_CPU_H
 #define QEMU_CPU_H
 
+#include signal.h
 #include hw/qdev-core.h
 #include qemu/thread.h
 
@@ -96,6 +97,7 @@ struct CPUState {
 bool created;
 bool stop;
 bool stopped;
+volatile sig_atomic_t exit_request;
 
 int kvm_fd;
 bool kvm_vcpu_dirty;
diff --git a/kvm-all.c b/kvm-all.c
index 04ec2d5..4decfdc 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1537,7 +1537,7 @@ int kvm_cpu_exec(CPUArchState *env)
 DPRINTF(kvm_cpu_exec()\n);
 
 if (kvm_arch_process_async_events(cpu)) {
-env-exit_request = 0;
+cpu-exit_request = 0;
 return EXCP_HLT;
 }
 
@@ -1548,7 +1548,7 @@ int kvm_cpu_exec(CPUArchState *env)
 }
 
 kvm_arch_pre_run(cpu, run);
-if (env-exit_request) {
+if (cpu-exit_request) {
 DPRINTF(interrupt exit requested\n);
 /*
  * KVM requires us to reenter the kernel after IO exits to complete
@@ -1622,7 +1622,7 @@ int kvm_cpu_exec(CPUArchState *env)
 vm_stop(RUN_STATE_INTERNAL_ERROR);
 }
 
-env-exit_request = 0;
+cpu-exit_request = 0;
 return ret;
 }
 
diff --git a/qom/cpu.c b/qom/cpu.c
index 870e9ba..7d8c675 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -32,6 +32,7 @@ void cpu_reset(CPUState *cpu)
 
 static void 

Re: [Qemu-devel] QEMU buildbot maintenance state

2013-02-01 Thread Christian Berendt
I merged the two pending pull requests and added the configurations of 
the qemu-kvm and kvm buildbots to the GitHub repository.


The daily cronjob on the buildbot system is now active and the 
configuration provided on GitHub will now be used.


The open change requests will be processed tomorrow.

Hope everything is still working, if not drop me a line.

Christian.

--
Christian Berendt
Solution Architect
Mail: bere...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
--
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 V4 RESEND 05/22] net: intorduce qemu_del_nic()

2013-02-01 Thread Eric Blake
On 02/01/2013 12:39 AM, Jason Wang wrote:

s/intorduce/introduce/ in the subject

 To support multiqueue nic, this patch separate the nic destructor from

s/separate/separates/

 qemu_del_net_client() to a new helper qemu_del_nic() since the mapping 
 bettween

s/bettween/between/

 NiCState and NetClientState were not 1:1 in multiqueue. The following patches
 would refactor this function to support multiqueue nic.
 
 Signed-off-by: Jason Wang jasow...@redhat.com
 Signed-off-by: Michael S. Tsirkin m...@redhat.com
 ---

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 8/8] KVM:PPC:booke: Allow debug interrupt injection to guest

2013-02-01 Thread Scott Wood

On 01/31/2013 06:11:32 PM, Alexander Graf wrote:


On 31.01.2013, at 23:40, Scott Wood wrote:

 On 01/31/2013 01:20:39 PM, Alexander Graf wrote:
 On 31.01.2013, at 20:05, Alexander Graf wrote:
 
  On 31.01.2013, at 19:54, Scott Wood wrote:
 
  On 01/31/2013 12:52:41 PM, Alexander Graf wrote:
  On 31.01.2013, at 19:43, Scott Wood wrote:
  On 01/31/2013 12:21:07 PM, Alexander Graf wrote:
  How about something like this? Then both targets at least  
suck as much :).

 
  I'm not sure that should be the goal...
 
  Thanks to e500mc's awful hardware design, we don't know who  
sets the MSR_DE bit. Once we forced it onto the guest, we have no  
change to know whether the guest also set it or not. We could only  
guess.

 
  MSRP[DEP] can prevent the guest from modifying MSR[DE] -- but  
we still need to set it in the first place.

 
  According to ISA V2.06B, the hypervisor should set DBCR0[EDM]  
to let the guest know that the debug resources are not available, and  
that the value of MSR[DE] is not specified and not modifiable.
  So what would the guest do then to tell the hypervisor that it  
actually wants to know about debug events?

 
  The guest is out of luck, just as if a JTAG were in use.
 
  Hrm.
 
  Can we somehow generalize this out of luck behavior?
 
  Every time we would set or clear an MSR bit in shadow_msr on  
e500v2, we would instead set or clear it in the real MSR. That way  
only e500mc is out of luck, but the code would still be shared.


 I don't follow.  e500v2 is just as out-of-luck.  The mechanism  
simply does not support sharing debug resources.


For e500v2 we have 2 fields

  * MSR as the guest sees it
  * MSR as we execute when the guest runs

Since we know the MSR when the guest sees it, we can decide what to  
do when we get an unhandled debug interrupt.


That's not the same thing as making the real MSR[DE] show up in the  
guest MSR[DE].


There are other problems with sharing -- what happens when both host  
and guest try to write to a particular IAC or DAC?


Also, performance would be pretty awful if the guest has e.g. single  
stepping in DBCR0 enabled but MSR[DE]=0, and the host doesn't care  
about single stepping (but does want debugging enabled in general).


 What do you mean by the real MSR?  The real MSR is shadow_msr,  
and MSR_DE must always be set there if the host is debugging the  
guest.  As for reflecting it into the guest MSR, we could, but I  
don't really see the point.  We're never going to actually send a  
debug exception to the guest when the host owns the debug resources.


Why not? That's the whole point of jumping through user space.


That's still needed for software breakpoints, which don't rely on the  
debug resources.



  1) guest exits with debug interrupt
  2) QEMU gets a debug exit
  3) QEMU checks in its list whether it belongs to its own debug  
points

  4) if not, it reinjects the interrupt into the guest

Step 4 is pretty difficult to do when we don't know whether the guest  
is actually capable of handling debug interrupts at that moment.


Software breakpoints take a Program interrupt rather than a Debug  
interrupt, unless MSR[DE]=1 and DBCR0[TRAP]=1.  If the guest does not  
own debug resources we should always send it to the Program interrupt,  
so MSR[DE] doesn't matter.


 The = ~MSR_DE line is pointless on bookehv, and makes it harder  
to read.  I had to stare at it a while before noticing that you  
initially set is_debug from the guest MSR and that you'd never really  
clear MSR_DE here on bookehv.


Well, I'm mostly bouncing ideas here to find a way to express what  
we're trying to say in a way that someone who hasn't read this email  
thread would still understand what's going on :).


I think it's already straightforward enough if you accept that shared  
debug resources aren't supported, and that we are either in a mode  
where the real MSR[DE] reflects the guest MSR[DE], or a mode where the  
real MSR[DE] is always on in guest mode and the guest MSR[DE] is  
irrelevant.



How about this version?


diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 38a62ef..9929c41 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -133,6 +133,28 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu  
*vcpu)

 #endif
 }

+static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
+{
+#ifndef CONFIG_KVM_BOOKE_HV
+	/* Synchronize guest's desire to get debug interrupts into  
shadow MSR */

+   vcpu-arch.shadow_msr = ~MSR_DE;
+   vcpu-arch.shadow_msr |= vcpu-arch.shared-msr  MSR_DE;
+#endif
+
+	/* Force enable debug interrupts when user space wants to debug  
*/

+   if (vcpu-guest_debug) {
+#ifdef CONFIG_KVM_BOOKE_HV
+   /*
+		 * Since there is no shadow MSR, sync MSR_DE into the  
guest

+* visible MSR.
+*/
+   vcpu-arch.shared-msr |= MSR_DE;
+#else
+   vcpu-arch.shadow_msr |= MSR_DE;
+#endif
+   }
+}


This shows 

Re: [Qemu-devel] [PATCH V4 RESEND 15/22] tap: multiqueue support

2013-02-01 Thread Eric Blake
On 02/01/2013 12:39 AM, Jason Wang wrote:
 Recently, linux support multiqueue tap which could let userspace call 
 TUNSETIFF
 for a signle device many times to create multiple file descriptors as

s/signle/single/

 independent queues. User could also enable/disabe a specific queue through

s/disabe/disable/

 TUNSETQUEUE.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: KVM: x86: use dynamic percpu allocations for shared msrs area

2013-02-01 Thread Andy Lutomirski
On Thu, Jan 3, 2013 at 5:41 AM, Marcelo Tosatti mtosa...@redhat.com wrote:

 Andy, Mike, can you confirm whether this fixes the percpu allocation
 failures when loading kvm.ko? TIA

 

 Use dynamic percpu allocations for the shared msrs structure,
 to avoid using the limited reserved percpu space.

 Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

Sorry for the amazingly long delay.  What kernel does this apply to?

--Andy
--
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] KVM: VMX: disable SMEP feature when guest is in non-paging mode

2013-02-01 Thread Paolo Bonzini
Il 01/02/2013 09:30, Dongxiao Xu ha scritto:
 SMEP is disabled if CPU is in non-paging mode in hardware.
 However KVM always uses paging mode to emulate guest non-paging
 mode with HAP. To emulate this behavior, SMEP needs to be manually
 disabled when guest switches to non-paging mode.
 
 We met an issue that, SMP Linux guest with recent kernel (enable
 SMEP support, for example, 3.5.3) would crash with triple fault if
 setting unrestricted_guest=0. This is because KVM uses an identity
 mapping page table to emulate the non-paging mode, where the page
 table is set with USER flag. If SMEP is still enabled in this case,
 guest will meet unhandlable page fault and then crash.
 
 Signed-off-by: Dongxiao Xu dongxiao...@intel.com
 Signed-off-by: Xiantao Zhang xiantao.zh...@intel.com
 ---
  arch/x86/kvm/vmx.c |8 
  1 files changed, 8 insertions(+), 0 deletions(-)
 
 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
 index 9120ae1..e82f20d 100644
 --- a/arch/x86/kvm/vmx.c
 +++ b/arch/x86/kvm/vmx.c
 @@ -3155,6 +3155,14 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned 
 long cr4)
   if (!is_paging(vcpu)) {
   hw_cr4 = ~X86_CR4_PAE;
   hw_cr4 |= X86_CR4_PSE;
 + /*
 +  * SMEP is disabled if CPU is in non-paging mode in
 +  * hardware. However KVM always uses paging mode to
 +  * emulate guest non-paging mode with HAP.
 +  * To emulate this behavior, SMEP needs to be manually
 +  * disabled when guest switches to non-paging mode.
 +  */
 + hw_cr4 = ~X86_CR4_SMEP;
   } else if (!(cr4  X86_CR4_PAE)) {
   hw_cr4 = ~X86_CR4_PAE;
   }
 

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
--
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 qom-cpu-next v3 3/4] target-i386: Slim conversion to X86CPU subclasses

2013-02-01 Thread Andreas Färber
Move x86_def_t definition to header and embed into X86CPUClass.
Register types per built-in model definition.

Move version initialization from x86_cpudef_setup() to class_init.

Inline cpu_x86_register() into the X86CPU initfn.
Since instance_init cannot reports errors, drop error handling.

Replace cpu_x86_find_by_name() with x86_cpu_class_by_name().
Move KVM host vendor override from cpu_x86_find_by_name() to the initfn.

Register host-{i386,x86_64}-cpu type from KVM code to avoid #ifdefs.
Make kvm_cpu_fill_host() a class_init and inline cpu_x86_fill_model_id().

Let kvm_check_features_against_host() obtain host-{i386,86_64}-cpu for
comparison.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-i386/cpu-qom.h |   24 
 target-i386/cpu.c |  324 +
 target-i386/cpu.h |2 -
 target-i386/kvm.c |   93 ++
 4 Dateien geändert, 228 Zeilen hinzugefügt(+), 215 Zeilen entfernt(-)

diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 48e6b54..80bf72d 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -30,6 +30,27 @@
 #define TYPE_X86_CPU i386-cpu
 #endif
 
+#define TYPE_HOST_X86_CPU host- TYPE_X86_CPU
+
+typedef struct x86_def_t {
+const char *name;
+uint32_t level;
+/* vendor is zero-terminated, 12 character ASCII string */
+char vendor[CPUID_VENDOR_SZ + 1];
+int family;
+int model;
+int stepping;
+uint32_t features, ext_features, ext2_features, ext3_features;
+uint32_t kvm_features, svm_features;
+uint32_t xlevel;
+char model_id[48];
+/* Store the results of Centaur's CPUID instructions */
+uint32_t ext4_features;
+uint32_t xlevel2;
+/* The feature bits on CPUID[EAX=7,ECX=0].EBX */
+uint32_t cpuid_7_0_ebx_features;
+} x86_def_t;
+
 #define X86_CPU_CLASS(klass) \
 OBJECT_CLASS_CHECK(X86CPUClass, (klass), TYPE_X86_CPU)
 #define X86_CPU(obj) \
@@ -41,6 +62,7 @@
  * X86CPUClass:
  * @parent_realize: The parent class' realize handler.
  * @parent_reset: The parent class' reset handler.
+ * @info: Model-specific data.
  *
  * An x86 CPU model or family.
  */
@@ -51,6 +73,8 @@ typedef struct X86CPUClass {
 
 DeviceRealize parent_realize;
 void (*parent_reset)(CPUState *cpu);
+
+x86_def_t info;
 } X86CPUClass;
 
 /**
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index ee2fd6b..6c95740 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -346,25 +346,6 @@ static void add_flagname_to_bitmaps(const char *flagname,
 }
 }
 
-typedef struct x86_def_t {
-const char *name;
-uint32_t level;
-/* vendor is zero-terminated, 12 character ASCII string */
-char vendor[CPUID_VENDOR_SZ + 1];
-int family;
-int model;
-int stepping;
-uint32_t features, ext_features, ext2_features, ext3_features;
-uint32_t kvm_features, svm_features;
-uint32_t xlevel;
-char model_id[48];
-/* Store the results of Centaur's CPUID instructions */
-uint32_t ext4_features;
-uint32_t xlevel2;
-/* The feature bits on CPUID[EAX=7,ECX=0].EBX */
-uint32_t cpuid_7_0_ebx_features;
-} x86_def_t;
-
 #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
 #define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \
   CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC)
@@ -868,86 +849,6 @@ static x86_def_t builtin_x86_defs[] = {
 },
 };
 
-#ifdef CONFIG_KVM
-static int cpu_x86_fill_model_id(char *str)
-{
-uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
-int i;
-
-for (i = 0; i  3; i++) {
-host_cpuid(0x8002 + i, 0, eax, ebx, ecx, edx);
-memcpy(str + i * 16 +  0, eax, 4);
-memcpy(str + i * 16 +  4, ebx, 4);
-memcpy(str + i * 16 +  8, ecx, 4);
-memcpy(str + i * 16 + 12, edx, 4);
-}
-return 0;
-}
-#endif
-
-/* Fill a x86_def_t struct with information about the host CPU, and
- * the CPU features supported by the host hardware + host kernel
- *
- * This function may be called only if KVM is enabled.
- */
-static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
-{
-#ifdef CONFIG_KVM
-KVMState *s = kvm_state;
-uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
-
-assert(kvm_enabled());
-
-x86_cpu_def-name = host;
-host_cpuid(0x0, 0, eax, ebx, ecx, edx);
-x86_cpu_vendor_words2str(x86_cpu_def-vendor, ebx, edx, ecx);
-
-host_cpuid(0x1, 0, eax, ebx, ecx, edx);
-x86_cpu_def-family = ((eax  8)  0x0F) + ((eax  20)  0xFF);
-x86_cpu_def-model = ((eax  4)  0x0F) | ((eax  0xF)  12);
-x86_cpu_def-stepping = eax  0x0F;
-
-x86_cpu_def-level = kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX);
-x86_cpu_def-features = kvm_arch_get_supported_cpuid(s, 0x1, 0, R_EDX);
-x86_cpu_def-ext_features = kvm_arch_get_supported_cpuid(s, 0x1, 0, R_ECX);
-
-if (x86_cpu_def-level = 7) {
-x86_cpu_def-cpuid_7_0_ebx_features =
-kvm_arch_get_supported_cpuid(s, 0x7, 0, R_EBX);
-} 

Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support

2013-02-01 Thread Alexander Graf

On 01.02.2013, at 04:49, Bhushan Bharat-R65777 wrote:

 
 
 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org [mailto:kvm-ppc-ow...@vger.kernel.org] On
 Behalf Of Alexander Graf
 Sent: Friday, January 25, 2013 6:08 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support
 
 
 On 16.01.2013, at 09:20, Bharat Bhushan wrote:
 
 This patchset adds the QEMU debug stub support for powerpc (booke/bookehv).
 [1/8] KVM: PPC: booke: use vcpu reference from thread_struct
 - This is a cleanup patch to use vcpu reference from thread struct
 [2/8] KVM: PPC: booke: Allow multiple exception types [3/8] KVM: PPC:
 booke: Added debug handler
 - These two patches install the KVM debug handler.
 [4/8] Added ONE_REG interface for debug instruction
 - Add the ioctl interface to get the debug instruction for
   setting software breakpoint from QEMU debug stub.
 [5/8] KVM: PPC: debug stub interface parameter defined [6/8] booke:
 Added DBCR4 SPR number [7/8] KVM: booke/bookehv: Add debug stub
 support
 - Add the debug stub interface on booke/bookehv [8/8] KVM:PPC:booke:
 Allow debug interrupt injection to guest
 -- with this qemu can inject debug interrupt to guest
 
 Thanks, applied 1/8, 2/8, 6/8.
 
 
 Alex I cannot see these 3 patches on kvm-ppc-next branch. Are those applied 
 on some other branch ?

Yes, my staging tree is now kvm-ppc-queue, as I'm not allowed to rebase 
kvm-ppc-next...


Alex

--
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 3/8] KVM: PPC: booke: Added debug handler

2013-02-01 Thread Alexander Graf

On 01.02.2013, at 06:04, Bhushan Bharat-R65777 wrote:

 
 
 -Original Message-
 From: kvm-ppc-ow...@vger.kernel.org [mailto:kvm-ppc-ow...@vger.kernel.org] On
 Behalf Of Alexander Graf
 Sent: Thursday, January 31, 2013 10:38 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 31.01.2013, at 17:58, Bhushan Bharat-R65777 wrote:
 
 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Thursday, January 31, 2013 5:47 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 30.01.2013, at 12:30, Bhushan Bharat-R65777 wrote:
 
 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, January 25, 2013 5:13 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan
 Bharat-R65777
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 16.01.2013, at 09:24, Bharat Bhushan wrote:
 
 From: Bharat Bhushan bharat.bhus...@freescale.com
 
 Installed debug handler will be used for guest debug support and
 debug facility emulation features (patches for these features will
 follow this patch).
 
 Signed-off-by: Liu Yu yu@freescale.com
 [bharat.bhus...@freescale.com: Substantial changes]
 Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
 ---
 arch/powerpc/include/asm/kvm_host.h |1 +
 arch/powerpc/kernel/asm-offsets.c   |1 +
 arch/powerpc/kvm/booke_interrupts.S |   49 
 ++-
 --
 --
 3 files changed, 44 insertions(+), 7 deletions(-)
 
 diff --git a/arch/powerpc/include/asm/kvm_host.h
 b/arch/powerpc/include/asm/kvm_host.h
 index 8a72d59..f4ba881 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -503,6 +503,7 @@ struct kvm_vcpu_arch {
 u32 tlbcfg[4];
 u32 mmucfg;
 u32 epr;
 +   u32 crit_save;
 struct kvmppc_booke_debug_reg dbg_reg; #endif
 gpa_t paddr_accessed;
 diff --git a/arch/powerpc/kernel/asm-offsets.c
 b/arch/powerpc/kernel/asm-offsets.c
 index 46f6afd..02048f3 100644
 --- a/arch/powerpc/kernel/asm-offsets.c
 +++ b/arch/powerpc/kernel/asm-offsets.c
 @@ -562,6 +562,7 @@ int main(void)
 DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, 
 arch.last_inst));
 DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, 
 arch.fault_dear));
 DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu,
 arch.fault_esr));
 +   DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu,
 +arch.crit_save));
 #endif /* CONFIG_PPC_BOOK3S */
 #endif /* CONFIG_KVM */
 
 diff --git a/arch/powerpc/kvm/booke_interrupts.S
 b/arch/powerpc/kvm/booke_interrupts.S
 index eae8483..dd9c5d4 100644
 --- a/arch/powerpc/kvm/booke_interrupts.S
 +++ b/arch/powerpc/kvm/booke_interrupts.S
 @@ -52,12 +52,7 @@
 (1BOOKE_INTERRUPT_PROGRAM) | \
 (1BOOKE_INTERRUPT_DTLB_MISS))
 
 -.macro KVM_HANDLER ivor_nr scratch srr0
 -_GLOBAL(kvmppc_handler_\ivor_nr)
 -   /* Get pointer to vcpu and record exit number. */
 -   mtspr   \scratch , r4
 -   mfspr   r4, SPRN_SPRG_THREAD
 -   lwz r4, THREAD_KVM_VCPU(r4)
 +.macro __KVM_HANDLER ivor_nr scratch srr0
 stw r3, VCPU_GPR(R3)(r4)
 stw r5, VCPU_GPR(R5)(r4)
 stw r6, VCPU_GPR(R6)(r4)
 @@ -74,6 +69,46 @@ _GLOBAL(kvmppc_handler_\ivor_nr)
 bctr
 .endm
 
 +.macro KVM_HANDLER ivor_nr scratch srr0
 +_GLOBAL(kvmppc_handler_\ivor_nr)
 +   /* Get pointer to vcpu and record exit number. */
 +   mtspr   \scratch , r4
 +   mfspr   r4, SPRN_SPRG_THREAD
 +   lwz r4, THREAD_KVM_VCPU(r4)
 +   __KVM_HANDLER \ivor_nr \scratch \srr0 .endm
 +
 +.macro KVM_DBG_HANDLER ivor_nr scratch srr0
 +_GLOBAL(kvmppc_handler_\ivor_nr)
 +   mtspr   \scratch, r4
 +   mfspr   r4, SPRN_SPRG_THREAD
 +   lwz r4, THREAD_KVM_VCPU(r4)
 +   stw r3, VCPU_CRIT_SAVE(r4)
 +   mfcrr3
 +   mfspr   r4, SPRN_CSRR1
 +   andi.   r4, r4, MSR_PR
 +   bne 1f
 
 
 +   /* debug interrupt happened in enter/exit path */
 +   mfspr   r4, SPRN_CSRR1
 +   rlwinm  r4, r4, 0, ~MSR_DE
 +   mtspr   SPRN_CSRR1, r4
 +   lis r4, 0x
 +   ori r4, r4, 0x
 +   mtspr   SPRN_DBSR, r4
 +   mfspr   r4, SPRN_SPRG_THREAD
 +   lwz r4, THREAD_KVM_VCPU(r4)
 +   mtcrr3
 +   lwz r3, VCPU_CRIT_SAVE(r4)
 +   mfspr   r4, \scratch
 +   rfci
 
 What is this part doing? Try to ignore the debug exit?
 
 As BOOKE doesn't have hardware support for virtualization, hardware
 never know
 current pc is in guest or in host.
 So when enable hardware single step for guest, it cannot be disabled
 at the
 time guest exit. Thus, we'll see that an single step interrupt
 happens at the beginning of guest exit path.
 
 With the above code 

Re: Query about SPE operation fault in e500v2 KVM. thanks.

2013-02-01 Thread Alexander Graf
On 01.02.2013, at 07:09, Gao Guanhua-B22826 wrote:

 Hi Alex,
 
 The guest will not be hung after applying the patch, but the test result is 
 still wrong.
 
 root@model:/media/ram# ./spe_align_e500v2
 high in 0x1 out 0x
 low in 0x1 out 0x
 spe test failed!
 Segmentation fault
 
 Then we made some more modifications, the test result is right finally.
 
 In arch/powerpc/kvm/booke.c  kvmppc_booke_irqprio_deliver:
case BOOKE_IRQPRIO_ALIGNMENT:
update_dear = true;
allowed = 1;
msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
break;
 In arch/powerpc/kvm/booke_interrupts.S
 #define NEED_DEAR_MASK ((1BOOKE_INTERRUPT_DATA_STORAGE) | \
(1BOOKE_INTERRUPT_DTLB_MISS) | \
(1BOOKE_INTERRUPT_ALIGNMENT))
 
 Test result:
 root@model:/media/ram# ./spe_align_e500v2
 high in 0x64 out 0x64
 low in 0x64 out 0x64

Thanks a lot for testing and fixing this one :). I'm glad it works for you. 
I've written up a patch that does this slightly differently and also takes EPR 
into account. Could you please check whether that one works as well?


Thanks,

Alex

--
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] KVM: PPC: BookE: Handle alignment interrupts

2013-02-01 Thread Alexander Graf
When the guest triggers an alignment interrupt, we don't handle it properly
today and instead BUG_ON(). This really shouldn't happen.

Instead, we should just pass the interrupt back into the guest so it can deal
with it.

Reported-by: Gao Guanhua-B22826 b22...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c|   16 +++-
 arch/powerpc/kvm/booke_interrupts.S |6 --
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index d2f502d..020923e 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -182,6 +182,14 @@ static void kvmppc_core_queue_inst_storage(struct kvm_vcpu 
*vcpu,
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
 }
 
+static void kvmppc_core_queue_alignment(struct kvm_vcpu *vcpu, ulong 
dear_flags,
+   ulong esr_flags)
+{
+   vcpu-arch.queued_dear = dear_flags;
+   vcpu-arch.queued_esr = esr_flags;
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ALIGNMENT);
+}
+
 void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags)
 {
vcpu-arch.queued_esr = esr_flags;
@@ -345,6 +353,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
switch (priority) {
case BOOKE_IRQPRIO_DTLB_MISS:
case BOOKE_IRQPRIO_DATA_STORAGE:
+   case BOOKE_IRQPRIO_ALIGNMENT:
update_dear = true;
/* fall through */
case BOOKE_IRQPRIO_INST_STORAGE:
@@ -358,7 +367,6 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_SPE_FP_DATA:
case BOOKE_IRQPRIO_SPE_FP_ROUND:
case BOOKE_IRQPRIO_AP_UNAVAIL:
-   case BOOKE_IRQPRIO_ALIGNMENT:
allowed = 1;
msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
@@ -971,6 +979,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
r = RESUME_GUEST;
break;
 
+   case BOOKE_INTERRUPT_ALIGNMENT:
+   kvmppc_core_queue_alignment(vcpu, vcpu-arch.fault_dear,
+   vcpu-arch.fault_esr);
+   r = RESUME_GUEST;
+   break;
+
 #ifdef CONFIG_KVM_BOOKE_HV
case BOOKE_INTERRUPT_HV_SYSCALL:
if (!(vcpu-arch.shared-msr  MSR_PR)) {
diff --git a/arch/powerpc/kvm/booke_interrupts.S 
b/arch/powerpc/kvm/booke_interrupts.S
index eae8483..7fa4167 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -45,12 +45,14 @@
 (1BOOKE_INTERRUPT_DEBUG))
 
 #define NEED_DEAR_MASK ((1BOOKE_INTERRUPT_DATA_STORAGE) | \
-(1BOOKE_INTERRUPT_DTLB_MISS))
+(1BOOKE_INTERRUPT_DTLB_MISS)) | \
+(1BOOKE_INTERRUPT_ALIGNMENT))
 
 #define NEED_ESR_MASK ((1BOOKE_INTERRUPT_DATA_STORAGE) | \
(1BOOKE_INTERRUPT_INST_STORAGE) | \
(1BOOKE_INTERRUPT_PROGRAM) | \
-   (1BOOKE_INTERRUPT_DTLB_MISS))
+   (1BOOKE_INTERRUPT_DTLB_MISS)) | \
+   (1BOOKE_INTERRUPT_ALIGNMENT))
 
 .macro KVM_HANDLER ivor_nr scratch srr0
 _GLOBAL(kvmppc_handler_\ivor_nr)
-- 
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


RE: Query about SPE operation fault in e500v2 KVM. thanks.

2013-02-01 Thread Gao Guanhua-B22826
Hi Alex,

The new patch works well.


Regards,
Guanhua

 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, February 01, 2013 4:15 PM
 To: Gao Guanhua-B22826
 Cc: kvm-ppc@vger.kernel.org
 Subject: Re: Query about SPE operation fault in e500v2 KVM. thanks.
 
 On 01.02.2013, at 07:09, Gao Guanhua-B22826 wrote:
 
  Hi Alex,
 
  The guest will not be hung after applying the patch, but the test
 result is still wrong.
 
  root@model:/media/ram# ./spe_align_e500v2 high in 0x1 out 0x
  low in 0x1 out 0x spe test failed!
  Segmentation fault
 
  Then we made some more modifications, the test result is right finally.
 
  In arch/powerpc/kvm/booke.c  kvmppc_booke_irqprio_deliver:
 case BOOKE_IRQPRIO_ALIGNMENT:
 update_dear = true;
 allowed = 1;
 msr_mask = MSR_CE | MSR_ME | MSR_DE;
 int_class = INT_CLASS_NONCRIT;
 break;
  In arch/powerpc/kvm/booke_interrupts.S
  #define NEED_DEAR_MASK ((1BOOKE_INTERRUPT_DATA_STORAGE) | \
 (1BOOKE_INTERRUPT_DTLB_MISS) | \
 (1BOOKE_INTERRUPT_ALIGNMENT))
 
  Test result:
  root@model:/media/ram# ./spe_align_e500v2 high in 0x64 out 0x64 low in
  0x64 out 0x64
 
 Thanks a lot for testing and fixing this one :). I'm glad it works for
 you. I've written up a patch that does this slightly differently and also
 takes EPR into account. Could you please check whether that one works as
 well?
 
 
 Thanks,
 
 Alex
 


--
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 3/8] KVM: PPC: booke: Added debug handler

2013-02-01 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, February 01, 2013 1:36 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
 Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
 On 01.02.2013, at 06:04, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
  Sent: Thursday, January 31, 2013 10:38 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
  Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
  On 31.01.2013, at 17:58, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: Alexander Graf [mailto:ag...@suse.de]
  Sent: Thursday, January 31, 2013 5:47 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
  Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
  On 30.01.2013, at 12:30, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: Alexander Graf [mailto:ag...@suse.de]
  Sent: Friday, January 25, 2013 5:13 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan
  Bharat-R65777
  Subject: Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler
 
 
  On 16.01.2013, at 09:24, Bharat Bhushan wrote:
 
  From: Bharat Bhushan bharat.bhus...@freescale.com
 
  Installed debug handler will be used for guest debug support and
  debug facility emulation features (patches for these features
  will follow this patch).
 
  Signed-off-by: Liu Yu yu@freescale.com
  [bharat.bhus...@freescale.com: Substantial changes]
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  ---
  arch/powerpc/include/asm/kvm_host.h |1 +
  arch/powerpc/kernel/asm-offsets.c   |1 +
  arch/powerpc/kvm/booke_interrupts.S |   49
 ++-
  --
  --
  3 files changed, 44 insertions(+), 7 deletions(-)
 
  diff --git a/arch/powerpc/include/asm/kvm_host.h
  b/arch/powerpc/include/asm/kvm_host.h
  index 8a72d59..f4ba881 100644
  --- a/arch/powerpc/include/asm/kvm_host.h
  +++ b/arch/powerpc/include/asm/kvm_host.h
  @@ -503,6 +503,7 @@ struct kvm_vcpu_arch {
u32 tlbcfg[4];
u32 mmucfg;
u32 epr;
  + u32 crit_save;
struct kvmppc_booke_debug_reg dbg_reg; #endif
gpa_t paddr_accessed;
  diff --git a/arch/powerpc/kernel/asm-offsets.c
  b/arch/powerpc/kernel/asm-offsets.c
  index 46f6afd..02048f3 100644
  --- a/arch/powerpc/kernel/asm-offsets.c
  +++ b/arch/powerpc/kernel/asm-offsets.c
  @@ -562,6 +562,7 @@ int main(void)
DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, 
  arch.last_inst));
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu,
 arch.fault_dear));
DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu,
  arch.fault_esr));
  + DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu,
  +arch.crit_save));
  #endif /* CONFIG_PPC_BOOK3S */
  #endif /* CONFIG_KVM */
 
  diff --git a/arch/powerpc/kvm/booke_interrupts.S
  b/arch/powerpc/kvm/booke_interrupts.S
  index eae8483..dd9c5d4 100644
  --- a/arch/powerpc/kvm/booke_interrupts.S
  +++ b/arch/powerpc/kvm/booke_interrupts.S
  @@ -52,12 +52,7 @@
  (1BOOKE_INTERRUPT_PROGRAM) | \
  (1BOOKE_INTERRUPT_DTLB_MISS))
 
  -.macro KVM_HANDLER ivor_nr scratch srr0
  -_GLOBAL(kvmppc_handler_\ivor_nr)
  - /* Get pointer to vcpu and record exit number. */
  - mtspr   \scratch , r4
  - mfspr   r4, SPRN_SPRG_THREAD
  - lwz r4, THREAD_KVM_VCPU(r4)
  +.macro __KVM_HANDLER ivor_nr scratch srr0
stw r3, VCPU_GPR(R3)(r4)
stw r5, VCPU_GPR(R5)(r4)
stw r6, VCPU_GPR(R6)(r4)
  @@ -74,6 +69,46 @@ _GLOBAL(kvmppc_handler_\ivor_nr)
bctr
  .endm
 
  +.macro KVM_HANDLER ivor_nr scratch srr0
  +_GLOBAL(kvmppc_handler_\ivor_nr)
  + /* Get pointer to vcpu and record exit number. */
  + mtspr   \scratch , r4
  + mfspr   r4, SPRN_SPRG_THREAD
  + lwz r4, THREAD_KVM_VCPU(r4)
  + __KVM_HANDLER \ivor_nr \scratch \srr0 .endm
  +
  +.macro KVM_DBG_HANDLER ivor_nr scratch srr0
  +_GLOBAL(kvmppc_handler_\ivor_nr)
  + mtspr   \scratch, r4
  + mfspr   r4, SPRN_SPRG_THREAD
  + lwz r4, THREAD_KVM_VCPU(r4)
  + stw r3, VCPU_CRIT_SAVE(r4)
  + mfcrr3
  + mfspr   r4, SPRN_CSRR1
  + andi.   r4, r4, MSR_PR
  + bne 1f
 
 
  + /* debug interrupt happened in enter/exit path */
  + mfspr   r4, SPRN_CSRR1
  + rlwinm  r4, r4, 0, ~MSR_DE
  + mtspr   SPRN_CSRR1, r4
  + lis r4, 0x
  + ori r4, r4, 0x
  + mtspr   SPRN_DBSR, r4
  + mfspr   r4, SPRN_SPRG_THREAD
  + lwz r4, THREAD_KVM_VCPU(r4)
  + mtcrr3
  + lwz r3, VCPU_CRIT_SAVE(r4)
  + mfspr   r4, \scratch
  + rfci
 
  What is this part doing? Try to ignore the debug exit?
 
  As BOOKE doesn't have hardware 

RE: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support

2013-02-01 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, February 01, 2013 1:34 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
 Subject: Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support
 
 
 On 01.02.2013, at 04:49, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: kvm-ppc-ow...@vger.kernel.org
  [mailto:kvm-ppc-ow...@vger.kernel.org] On Behalf Of Alexander Graf
  Sent: Friday, January 25, 2013 6:08 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan
  Bharat-R65777
  Subject: Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub
  support
 
 
  On 16.01.2013, at 09:20, Bharat Bhushan wrote:
 
  This patchset adds the QEMU debug stub support for powerpc 
  (booke/bookehv).
  [1/8] KVM: PPC: booke: use vcpu reference from thread_struct
- This is a cleanup patch to use vcpu reference from thread struct
  [2/8] KVM: PPC: booke: Allow multiple exception types [3/8] KVM: PPC:
  booke: Added debug handler
- These two patches install the KVM debug handler.
  [4/8] Added ONE_REG interface for debug instruction
- Add the ioctl interface to get the debug instruction for
  setting software breakpoint from QEMU debug stub.
  [5/8] KVM: PPC: debug stub interface parameter defined [6/8] booke:
  Added DBCR4 SPR number [7/8] KVM: booke/bookehv: Add debug stub
  support
- Add the debug stub interface on booke/bookehv [8/8] KVM:PPC:booke:
  Allow debug interrupt injection to guest
-- with this qemu can inject debug interrupt to guest
 
  Thanks, applied 1/8, 2/8, 6/8.
 
 
  Alex I cannot see these 3 patches on kvm-ppc-next branch. Are those applied 
  on
 some other branch ?
 
 Yes, my staging tree is now kvm-ppc-queue, as I'm not allowed to rebase 
 kvm-ppc-
 next...

On which branch we should send our patches on kvm-ppc-queue or kmv-ppc-next?

Thanks
-Bharat

--
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 8/8] KVM:PPC:booke: Allow debug interrupt injection to guest

2013-02-01 Thread Scott Wood

On 01/31/2013 06:11:32 PM, Alexander Graf wrote:


On 31.01.2013, at 23:40, Scott Wood wrote:

 On 01/31/2013 01:20:39 PM, Alexander Graf wrote:
 On 31.01.2013, at 20:05, Alexander Graf wrote:
 
  On 31.01.2013, at 19:54, Scott Wood wrote:
 
  On 01/31/2013 12:52:41 PM, Alexander Graf wrote:
  On 31.01.2013, at 19:43, Scott Wood wrote:
  On 01/31/2013 12:21:07 PM, Alexander Graf wrote:
  How about something like this? Then both targets at least  
suck as much :).

 
  I'm not sure that should be the goal...
 
  Thanks to e500mc's awful hardware design, we don't know who  
sets the MSR_DE bit. Once we forced it onto the guest, we have no  
change to know whether the guest also set it or not. We could only  
guess.

 
  MSRP[DEP] can prevent the guest from modifying MSR[DE] -- but  
we still need to set it in the first place.

 
  According to ISA V2.06B, the hypervisor should set DBCR0[EDM]  
to let the guest know that the debug resources are not available, and  
that the value of MSR[DE] is not specified and not modifiable.
  So what would the guest do then to tell the hypervisor that it  
actually wants to know about debug events?

 
  The guest is out of luck, just as if a JTAG were in use.
 
  Hrm.
 
  Can we somehow generalize this out of luck behavior?
 
  Every time we would set or clear an MSR bit in shadow_msr on  
e500v2, we would instead set or clear it in the real MSR. That way  
only e500mc is out of luck, but the code would still be shared.


 I don't follow.  e500v2 is just as out-of-luck.  The mechanism  
simply does not support sharing debug resources.


For e500v2 we have 2 fields

  * MSR as the guest sees it
  * MSR as we execute when the guest runs

Since we know the MSR when the guest sees it, we can decide what to  
do when we get an unhandled debug interrupt.


That's not the same thing as making the real MSR[DE] show up in the  
guest MSR[DE].


There are other problems with sharing -- what happens when both host  
and guest try to write to a particular IAC or DAC?


Also, performance would be pretty awful if the guest has e.g. single  
stepping in DBCR0 enabled but MSR[DE]=0, and the host doesn't care  
about single stepping (but does want debugging enabled in general).


 What do you mean by the real MSR?  The real MSR is shadow_msr,  
and MSR_DE must always be set there if the host is debugging the  
guest.  As for reflecting it into the guest MSR, we could, but I  
don't really see the point.  We're never going to actually send a  
debug exception to the guest when the host owns the debug resources.


Why not? That's the whole point of jumping through user space.


That's still needed for software breakpoints, which don't rely on the  
debug resources.



  1) guest exits with debug interrupt
  2) QEMU gets a debug exit
  3) QEMU checks in its list whether it belongs to its own debug  
points

  4) if not, it reinjects the interrupt into the guest

Step 4 is pretty difficult to do when we don't know whether the guest  
is actually capable of handling debug interrupts at that moment.


Software breakpoints take a Program interrupt rather than a Debug  
interrupt, unless MSR[DE]=1 and DBCR0[TRAP]=1.  If the guest does not  
own debug resources we should always send it to the Program interrupt,  
so MSR[DE] doesn't matter.


 The = ~MSR_DE line is pointless on bookehv, and makes it harder  
to read.  I had to stare at it a while before noticing that you  
initially set is_debug from the guest MSR and that you'd never really  
clear MSR_DE here on bookehv.


Well, I'm mostly bouncing ideas here to find a way to express what  
we're trying to say in a way that someone who hasn't read this email  
thread would still understand what's going on :).


I think it's already straightforward enough if you accept that shared  
debug resources aren't supported, and that we are either in a mode  
where the real MSR[DE] reflects the guest MSR[DE], or a mode where the  
real MSR[DE] is always on in guest mode and the guest MSR[DE] is  
irrelevant.



How about this version?


diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 38a62ef..9929c41 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -133,6 +133,28 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu  
*vcpu)

 #endif
 }

+static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
+{
+#ifndef CONFIG_KVM_BOOKE_HV
+	/* Synchronize guest's desire to get debug interrupts into  
shadow MSR */

+   vcpu-arch.shadow_msr = ~MSR_DE;
+   vcpu-arch.shadow_msr |= vcpu-arch.shared-msr  MSR_DE;
+#endif
+
+	/* Force enable debug interrupts when user space wants to debug  
*/

+   if (vcpu-guest_debug) {
+#ifdef CONFIG_KVM_BOOKE_HV
+   /*
+		 * Since there is no shadow MSR, sync MSR_DE into the  
guest

+* visible MSR.
+*/
+   vcpu-arch.shared-msr |= MSR_DE;
+#else
+   vcpu-arch.shadow_msr |= MSR_DE;
+#endif
+   }
+}


This shows