[PATCH v2 13/16] KVM: PPC: Book3S HV: XIVE: add a mapping for the source ESB pages

David Gibson david at gibson.dropbear.id.au
Mon Feb 25 14:47:26 AEDT 2019


On Fri, Feb 22, 2019 at 12:28:37PM +0100, Cédric Le Goater wrote:
> Each source is associated with an Event State Buffer (ESB) with a
> even/odd pair of pages which provides commands to manage the source:
> to trigger, to EOI, to turn off the source for instance.
> 
> The custom VM fault handler will deduce the guest IRQ number from the
> offset of the fault, and the ESB page of the associated XIVE interrupt
> will be inserted into the VMA using the internal structure caching
> information on the interrupts.
> 
> Signed-off-by: Cédric Le Goater <clg at kaod.org>

Reviewed-by: David Gibson <david at gibson.dropbear.id.au>

With the same caveat as the previous patch.

> ---
>  arch/powerpc/include/uapi/asm/kvm.h        |  1 +
>  arch/powerpc/kvm/book3s_xive_native.c      | 57 ++++++++++++++++++++++
>  Documentation/virtual/kvm/devices/xive.txt |  7 +++
>  3 files changed, 65 insertions(+)
> 
> diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uapi/asm/kvm.h
> index be9b255e061d..d8990e9044e3 100644
> --- a/arch/powerpc/include/uapi/asm/kvm.h
> +++ b/arch/powerpc/include/uapi/asm/kvm.h
> @@ -721,5 +721,6 @@ struct kvm_ppc_xive_eq {
>  #define KVM_XIVE_EQ_FLAG_ESCALATE	0x00000004
>  
>  #define KVM_XIVE_TIMA_PAGE_OFFSET	0
> +#define KVM_XIVE_ESB_PAGE_OFFSET	4
>  
>  #endif /* __LINUX_KVM_POWERPC_H */
> diff --git a/arch/powerpc/kvm/book3s_xive_native.c b/arch/powerpc/kvm/book3s_xive_native.c
> index c6ac818a13b2..92cab6409e8e 100644
> --- a/arch/powerpc/kvm/book3s_xive_native.c
> +++ b/arch/powerpc/kvm/book3s_xive_native.c
> @@ -176,6 +176,59 @@ int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
>  	return rc;
>  }
>  
> +static int xive_native_esb_fault(struct vm_fault *vmf)
> +{
> +	struct vm_area_struct *vma = vmf->vma;
> +	struct kvm_device *dev = vma->vm_file->private_data;
> +	struct kvmppc_xive *xive = dev->private;
> +	struct kvmppc_xive_src_block *sb;
> +	struct kvmppc_xive_irq_state *state;
> +	struct xive_irq_data *xd;
> +	u32 hw_num;
> +	u16 src;
> +	u64 page;
> +	unsigned long irq;
> +	u64 page_offset;
> +
> +	/*
> +	 * Linux/KVM uses a two pages ESB setting, one for trigger and
> +	 * one for EOI
> +	 */
> +	page_offset = vmf->pgoff - vma->vm_pgoff;
> +	irq = page_offset / 2;
> +
> +	sb = kvmppc_xive_find_source(xive, irq, &src);
> +	if (!sb) {
> +		pr_devel("%s: source %lx not found !\n", __func__, irq);
> +		return VM_FAULT_SIGBUS;
> +	}
> +
> +	state = &sb->irq_state[src];
> +	kvmppc_xive_select_irq(state, &hw_num, &xd);
> +
> +	arch_spin_lock(&sb->lock);
> +
> +	/*
> +	 * first/even page is for trigger
> +	 * second/odd page is for EOI and management.
> +	 */
> +	page = page_offset % 2 ? xd->eoi_page : xd->trig_page;
> +	arch_spin_unlock(&sb->lock);
> +
> +	if (WARN_ON(!page)) {
> +		pr_err("%s: acessing invalid ESB page for source %lx !\n",
> +		       __func__, irq);
> +		return VM_FAULT_SIGBUS;
> +	}
> +
> +	vmf_insert_pfn(vma, vmf->address, page >> PAGE_SHIFT);
> +	return VM_FAULT_NOPAGE;
> +}
> +
> +static const struct vm_operations_struct xive_native_esb_vmops = {
> +	.fault = xive_native_esb_fault,
> +};
> +
>  static int xive_native_tima_fault(struct vm_fault *vmf)
>  {
>  	struct vm_area_struct *vma = vmf->vma;
> @@ -205,6 +258,10 @@ static int kvmppc_xive_native_mmap(struct kvm_device *dev,
>  		if (vma_pages(vma) > 4)
>  			return -EINVAL;
>  		vma->vm_ops = &xive_native_tima_vmops;
> +	} else if (vma->vm_pgoff == KVM_XIVE_ESB_PAGE_OFFSET) {
> +		if (vma_pages(vma) > KVMPPC_XIVE_NR_IRQS * 2)
> +			return -EINVAL;
> +		vma->vm_ops = &xive_native_esb_vmops;
>  	} else {
>  		return -EINVAL;
>  	}
> diff --git a/Documentation/virtual/kvm/devices/xive.txt b/Documentation/virtual/kvm/devices/xive.txt
> index 4d6b41609fd9..be5000b2eb5a 100644
> --- a/Documentation/virtual/kvm/devices/xive.txt
> +++ b/Documentation/virtual/kvm/devices/xive.txt
> @@ -36,6 +36,13 @@ the legacy interrupt mode, referred as XICS (POWER7/8).
>    third (operating system) and the fourth (user level) are exposed the
>    guest.
>  
> +  2. Event State Buffer (ESB)
> +
> +  Each source is associated with an Event State Buffer (ESB) with
> +  either a pair of even/odd pair of pages which provides commands to
> +  manage the source: to trigger, to EOI, to turn off the source for
> +  instance.
> +
>  * Groups:
>  
>    1. KVM_DEV_XIVE_GRP_CTRL

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20190225/7c337e8a/attachment.sig>


More information about the Linuxppc-dev mailing list