public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Yang Zhang <yang.z.zhang@intel.com>
Cc: kvm@vger.kernel.org, gleb@redhat.com, haitao.shan@intel.com,
	xiantao.zhang@intel.com, Kevin Tian <kevin.tian@intel.com>
Subject: Re: [PATCH v11 3/3] x86, apicv: add virtual interrupt delivery support
Date: Mon, 21 Jan 2013 19:05:43 -0200	[thread overview]
Message-ID: <20130121210543.GA7110@amt.cnet> (raw)
In-Reply-To: <1358331672-32384-4-git-send-email-yang.z.zhang@intel.com>

On Wed, Jan 16, 2013 at 06:21:12PM +0800, Yang Zhang wrote:
> From: Yang Zhang <yang.z.zhang@Intel.com>
> 
> Virtual interrupt delivery avoids KVM to inject vAPIC interrupts
> manually, which is fully taken care of by the hardware. This needs
> some special awareness into existing interrupr injection path:
> 
> - for pending interrupt, instead of direct injection, we may need
>   update architecture specific indicators before resuming to guest.
> 
> - A pending interrupt, which is masked by ISR, should be also
>   considered in above update action, since hardware will decide
>   when to inject it at right time. Current has_interrupt and
>   get_interrupt only returns a valid vector from injection p.o.v.
> 
> Signed-off-by: Kevin Tian <kevin.tian@intel.com>
> Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
> ---
>  arch/ia64/kvm/lapic.h           |    6 ++
>  arch/x86/include/asm/kvm_host.h |    7 ++
>  arch/x86/include/asm/vmx.h      |   11 +++
>  arch/x86/kvm/irq.c              |   56 +++++++++++-
>  arch/x86/kvm/lapic.c            |   69 +++++++++------
>  arch/x86/kvm/lapic.h            |   23 +++++
>  arch/x86/kvm/svm.c              |   25 +++++
>  arch/x86/kvm/vmx.c              |  184 +++++++++++++++++++++++++++++++++++++--
>  arch/x86/kvm/x86.c              |   11 ++-
>  arch/x86/kvm/x86.h              |    2 +
>  include/linux/kvm_host.h        |    3 +
>  virt/kvm/ioapic.c               |   38 ++++++++
>  virt/kvm/ioapic.h               |    1 +
>  virt/kvm/irq_comm.c             |   25 +++++
>  virt/kvm/kvm_main.c             |    5 +
>  15 files changed, 421 insertions(+), 45 deletions(-)
> 

> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 35aa8e6..d90bfa8 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -697,6 +697,12 @@ struct kvm_x86_ops {
>  	void (*enable_nmi_window)(struct kvm_vcpu *vcpu);
>  	void (*enable_irq_window)(struct kvm_vcpu *vcpu);
>  	void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr);
> +	int (*has_virtual_interrupt_delivery)(void);
> +	void (*update_apic_irq)(struct kvm_vcpu *vcpu, int max_irr);

Call it hwapic_irr_update().

> +	void (*update_eoi_exitmap)(struct kvm_vcpu *vcpu);
> +	void (*set_svi)(int isr);

SVI is VMX-specific. Call it hwapic_isr_update().

> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 526955d..8b9752a 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -84,8 +84,8 @@ module_param(vmm_exclusive, bool, S_IRUGO);
>  static bool __read_mostly fasteoi = 1;
>  module_param(fasteoi, bool, S_IRUGO);
>  
> -static bool __read_mostly enable_apicv_reg = 1;
> -module_param(enable_apicv_reg, bool, S_IRUGO);
> +static bool __read_mostly enable_apicv_reg_vid = 1;
> +module_param(enable_apicv_reg_vid, bool, S_IRUGO);
>  
>  /*
>   * If nested=1, nested virtualization is supported, i.e., guests may use

> @@ -2783,8 +2793,14 @@ static __init int hardware_setup(void)
>  	if (!cpu_has_vmx_ple())
>  		ple_gap = 0;
>  
> -	if (!cpu_has_vmx_apic_register_virt())
> -		enable_apicv_reg = 0;
> +	if (!cpu_has_vmx_apic_register_virt() ||
> +				!cpu_has_vmx_virtual_intr_delivery())
> +		enable_apicv_reg_vid = 0;
> +
> +	if (enable_apicv_reg_vid)
> +		kvm_x86_ops->update_cr8_intercept = NULL;
> +	else
> +		kvm_x86_ops->update_apic_irq = NULL;

Please be consistent regarding ->update_apic_irq: if HW does not support 
acceleration, or HW acceleration has been disabled, it is NULL (SVM
should be NULL, then).

If so, then please delete enable_apic_reg_vid check in vmx_set_svi.

> +static void vmx_set_svi(int isr)
> +{
> +	u16 status;
> +	u8 old;
> +
> +	if (!enable_apicv_reg_vid)
> +		return;

See above.

> +static void set_eoi_exitmap_one(struct kvm_vcpu *vcpu,
> +				u32 vector)
> +{
> +	struct vcpu_vmx *vmx = to_vmx(vcpu);
> +
> +	if (WARN_ONCE((vector > 255),
> +		"KVM VMX: vector (%d) out of range\n", vector))
> +		return;

Please remove the WARN_ON, inject triple fault if this happens
(and add a tracepoint).

> +
> +	__set_bit(vector, (unsigned long *)vmx->eoi_exit_bitmap);
> +}
> +
> +static void vmx_check_ioapic_entry(struct kvm_vcpu *vcpu,
> +				   struct kvm_lapic_irq *irq)
> +{
> +	struct kvm_lapic **dst;
> +	struct kvm_apic_map *map;
> +	unsigned long bitmap = 1;
> +	int i;
> +
> +	rcu_read_lock();
> +	map = rcu_dereference(vcpu->kvm->arch.apic_map);
> +
> +	if (unlikely(!map)) {
> +		set_eoi_exitmap_one(vcpu, irq->vector);
> +		goto out;
> +	}
> +
> +	if (irq->dest_mode == 0) { /* physical mode */
> +		if (irq->delivery_mode == APIC_DM_LOWEST ||
> +				irq->dest_id == 0xff) {
> +			set_eoi_exitmap_one(vcpu, irq->vector);
> +			goto out;
> +		}
> +		dst = &map->phys_map[irq->dest_id & 0xff];
> +	} else {
> +		u32 mda = irq->dest_id << (32 - map->ldr_bits);
> +
> +		dst = map->logical_map[apic_cluster_id(map, mda)];
> +
> +		bitmap = apic_logical_id(map, mda);
> +	}
> +
> +	for_each_set_bit(i, &bitmap, 16) {
> +		if (!dst[i])
> +			continue;
> +		if (dst[i]->vcpu == vcpu) {
> +			set_eoi_exitmap_one(vcpu, irq->vector);
> +			break;
> +		}
> +	}
> +
> +out:
> +	rcu_read_unlock();
> +}

All this can be moved to generic code, then

hwapic_vector_intercept_on_eoi() becomes a callback to kvm_x86_ops.

> index e224f7a..e8e7b6a 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -122,6 +122,8 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
>  	gva_t addr, void *val, unsigned int bytes,
>  	struct x86_exception *exception);
>  
> +void set_eoi_exitmap(struct kvm_vcpu *vcpu);
> +

This should be in virt/kvm/ioapic.h.

> @@ -82,5 +82,6 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
>  		struct kvm_lapic_irq *irq);
>  int kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
>  int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
> +void ioapic_update_eoi_exitmap(struct kvm *kvm);

prefix with kvm_


  parent reply	other threads:[~2013-01-21 21:09 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-16 10:21 [PATCH v11 0/3] x86, apicv: Add APIC virtualization support Yang Zhang
2013-01-16 10:21 ` [PATCH v11 1/3] x86, apicv: add APICv register " Yang Zhang
2013-01-16 10:21 ` [PATCH v11 2/3] x86, apicv: add virtual x2apic support Yang Zhang
2013-01-17 13:22   ` Gleb Natapov
2013-01-18  1:49     ` Zhang, Yang Z
2013-01-21 19:59   ` Marcelo Tosatti
2013-01-21 20:21     ` Gleb Natapov
2013-01-21 21:21       ` Marcelo Tosatti
2013-01-21 21:34         ` Gleb Natapov
2013-01-21 22:16           ` Marcelo Tosatti
2013-01-22  0:33             ` Marcelo Tosatti
2013-01-22  3:37               ` Zhang, Yang Z
2013-01-22  9:45               ` Gleb Natapov
2013-01-22  9:42             ` Gleb Natapov
2013-01-22 12:21     ` Zhang, Yang Z
2013-01-22 15:55       ` Gleb Natapov
2013-01-22 23:13         ` Marcelo Tosatti
2013-01-23  0:35           ` Zhang, Yang Z
2013-01-23 10:29           ` Gleb Natapov
2013-01-16 10:21 ` [PATCH v11 3/3] x86, apicv: add virtual interrupt delivery support Yang Zhang
2013-01-17  1:26   ` Zhang, Yang Z
2013-01-20 12:51     ` Gleb Natapov
2013-01-21  0:49       ` Zhang, Yang Z
2013-01-21  5:03         ` Gleb Natapov
2013-01-21  7:18           ` Zhang, Yang Z
2013-01-21 21:08           ` Marcelo Tosatti
2013-01-23  0:45           ` Zhang, Yang Z
2013-01-23 10:33             ` Gleb Natapov
2013-01-23 10:52               ` Zhang, Yang Z
2013-01-21 21:05   ` Marcelo Tosatti [this message]
2013-01-21 21:18     ` Gleb Natapov
2013-01-21 21:54       ` Marcelo Tosatti
2013-01-22  3:38         ` Zhang, Yang Z
2013-01-16 10:27 ` [PATCH v11 0/3] x86, apicv: Add APIC virtualization support Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130121210543.GA7110@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=gleb@redhat.com \
    --cc=haitao.shan@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=xiantao.zhang@intel.com \
    --cc=yang.z.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox