From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: <xen-devel@lists.xenproject.org>, <linux-kernel@vger.kernel.org>,
<boris.ostrovsky@oracle.com>, <stefano.stabellini@eu.citrix.com>,
<david.vrabel@citrix.com>, <hpa@zytor.com>
Subject: Re: [PATCH v13 16/19] xen/grant: Implement an grant frame array struct (v2).
Date: Sun, 5 Jan 2014 18:38:13 +0000 [thread overview]
Message-ID: <alpine.DEB.2.02.1401051838010.8667@kaball.uk.xensource.com> (raw)
In-Reply-To: <1388777916-1328-17-git-send-email-konrad.wilk@oracle.com>
On Fri, 3 Jan 2014, Konrad Rzeszutek Wilk wrote:
> The 'xen_hvm_resume_frames' used to be an 'unsigned long'
> and contain the virtual address of the grants. That was OK
> for most architectures (PVHVM, ARM) were the grants are contiguous
> in memory. That however is not the case for PVH - in which case
> we will have to do a lookup for each virtual address for the PFN.
>
> Instead of doing that, lets make it a structure which will contain
> the array of PFNs, the virtual address and the count of said PFNs.
>
> Also provide a generic functions: gnttab_setup_auto_xlat_frames and
> gnttab_free_auto_xlat_frames to populate said structure with
> appropriate values for PVHVM and ARM.
>
> To round it off, change the name from 'xen_hvm_resume_frames' to
> a more descriptive one - 'xen_auto_xlat_grant_frames'.
>
> For PVH, in patch "xen/pvh: Piggyback on PVHVM for grant driver"
> we will populate the 'xen_auto_xlat_grant_frames' by ourselves.
>
> v2 moves the xen_remap in the gnttab_setup_auto_xlat_frames
> and also introduces xen_unmap for gnttab_free_auto_xlat_frames.
>
> Suggested-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> arch/arm/include/asm/xen/page.h | 1 +
> arch/arm/xen/enlighten.c | 9 +++++--
> arch/x86/include/asm/xen/page.h | 1 +
> drivers/xen/grant-table.c | 58 ++++++++++++++++++++++++++++++++++++-----
> drivers/xen/platform-pci.c | 10 ++++---
> include/xen/grant_table.h | 9 ++++++-
> 6 files changed, 75 insertions(+), 13 deletions(-)
>
> diff --git a/arch/arm/include/asm/xen/page.h b/arch/arm/include/asm/xen/page.h
> index 75579a9d..5af8fb3 100644
> --- a/arch/arm/include/asm/xen/page.h
> +++ b/arch/arm/include/asm/xen/page.h
> @@ -118,5 +118,6 @@ static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
> }
>
> #define xen_remap(cookie, size) ioremap_cached((cookie), (size));
> +#define xen_unmap(cookie) iounmap((cookie))
>
> #endif /* _ASM_ARM_XEN_PAGE_H */
> diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
> index 8550123..2162172 100644
> --- a/arch/arm/xen/enlighten.c
> +++ b/arch/arm/xen/enlighten.c
> @@ -208,6 +208,7 @@ static int __init xen_guest_init(void)
> const char *version = NULL;
> const char *xen_prefix = "xen,xen-";
> struct resource res;
> + unsigned long grant_frames;
>
> node = of_find_compatible_node(NULL, NULL, "xen,xen");
> if (!node) {
> @@ -224,10 +225,10 @@ static int __init xen_guest_init(void)
> }
> if (of_address_to_resource(node, GRANT_TABLE_PHYSADDR, &res))
> return 0;
> - xen_hvm_resume_frames = res.start;
> + grant_frames = res.start;
> xen_events_irq = irq_of_parse_and_map(node, 0);
> pr_info("Xen %s support found, events_irq=%d gnttab_frame_pfn=%lx\n",
> - version, xen_events_irq, (xen_hvm_resume_frames >> PAGE_SHIFT));
> + version, xen_events_irq, (grant_frames >> PAGE_SHIFT));
> xen_domain_type = XEN_HVM_DOMAIN;
>
> xen_setup_features();
> @@ -265,6 +266,10 @@ static int __init xen_guest_init(void)
> if (xen_vcpu_info == NULL)
> return -ENOMEM;
>
> + if (gnttab_setup_auto_xlat_frames(grant_frames)) {
> + free_percpu(xen_vcpu_info);
> + return -ENOMEM;
> + }
> gnttab_init();
> if (!xen_initial_domain())
> xenbus_probe(NULL);
> diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
> index 4a092cc..3e276eb 100644
> --- a/arch/x86/include/asm/xen/page.h
> +++ b/arch/x86/include/asm/xen/page.h
> @@ -227,5 +227,6 @@ void make_lowmem_page_readonly(void *vaddr);
> void make_lowmem_page_readwrite(void *vaddr);
>
> #define xen_remap(cookie, size) ioremap((cookie), (size));
> +#define xen_unmap(cookie) iounmap((cookie))
>
> #endif /* _ASM_X86_XEN_PAGE_H */
> diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
> index cc1b4fa..6c78fd21 100644
> --- a/drivers/xen/grant-table.c
> +++ b/drivers/xen/grant-table.c
> @@ -65,8 +65,7 @@ static unsigned int nr_grant_frames;
> static int gnttab_free_count;
> static grant_ref_t gnttab_free_head;
> static DEFINE_SPINLOCK(gnttab_list_lock);
> -unsigned long xen_hvm_resume_frames;
> -EXPORT_SYMBOL_GPL(xen_hvm_resume_frames);
> +struct grant_frames xen_auto_xlat_grant_frames;
>
> static union {
> struct grant_entry_v1 *v1;
> @@ -838,6 +837,51 @@ unsigned int gnttab_max_grant_frames(void)
> }
> EXPORT_SYMBOL_GPL(gnttab_max_grant_frames);
>
> +int gnttab_setup_auto_xlat_frames(unsigned long addr)
> +{
> + xen_pfn_t *pfn;
> + unsigned int max_nr_gframes = __max_nr_grant_frames();
> + unsigned int i;
> + void *vaddr;
> +
> + if (xen_auto_xlat_grant_frames.count)
> + return -EINVAL;
> +
> + vaddr = xen_remap(addr, PAGE_SIZE * max_nr_gframes);
> + if (vaddr == NULL) {
> + pr_warn("Failed to ioremap gnttab share frames (addr=0x%08lx)!\n",
> + addr);
> + return -ENOMEM;
> + }
> + pfn = kcalloc(max_nr_gframes, sizeof(pfn[0]), GFP_KERNEL);
> + if (!pfn) {
> + xen_unmap(vaddr);
> + return -ENOMEM;
> + }
> + for (i = 0; i < max_nr_gframes; i++)
> + pfn[i] = PFN_DOWN(addr) + i;
> +
> + xen_auto_xlat_grant_frames.vaddr = vaddr;
> + xen_auto_xlat_grant_frames.pfn = pfn;
> + xen_auto_xlat_grant_frames.count = max_nr_gframes;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(gnttab_setup_auto_xlat_frames);
> +
> +void gnttab_free_auto_xlat_frames(void)
> +{
> + if (!xen_auto_xlat_grant_frames.count)
> + return;
> + kfree(xen_auto_xlat_grant_frames.pfn);
> + xen_unmap(xen_auto_xlat_grant_frames.vaddr);
> +
> + xen_auto_xlat_grant_frames.pfn = NULL;
> + xen_auto_xlat_grant_frames.count = 0;
> + xen_auto_xlat_grant_frames.vaddr = NULL;
> +}
> +EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames);
> +
> /* Handling of paged out grant targets (GNTST_eagain) */
> #define MAX_DELAY 256
> static inline void
> @@ -1068,6 +1112,7 @@ static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
> struct xen_add_to_physmap xatp;
> unsigned int i = end_idx;
> rc = 0;
> + BUG_ON(xen_auto_xlat_grant_frames.count < nr_gframes);
> /*
> * Loop backwards, so that the first hypercall has the largest
> * index, ensuring that the table will grow only once.
> @@ -1076,7 +1121,7 @@ static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
> xatp.domid = DOMID_SELF;
> xatp.idx = i;
> xatp.space = XENMAPSPACE_grant_table;
> - xatp.gpfn = (xen_hvm_resume_frames >> PAGE_SHIFT) + i;
> + xatp.gpfn = xen_auto_xlat_grant_frames.pfn[i];
> rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
> if (rc != 0) {
> pr_warn("grant table add_to_physmap failed, err=%d\n",
> @@ -1175,11 +1220,10 @@ static int gnttab_setup(void)
>
> if (xen_feature(XENFEAT_auto_translated_physmap) && gnttab_shared.addr == NULL)
> {
> - gnttab_shared.addr = xen_remap(xen_hvm_resume_frames,
> - PAGE_SIZE * max_nr_gframes);
> + gnttab_shared.addr = xen_auto_xlat_grant_frames.vaddr;
> if (gnttab_shared.addr == NULL) {
> - pr_warn("Failed to ioremap gnttab share frames (addr=0x%08lx)!\n",
> - xen_hvm_resume_frames);
> + pr_warn("gnttab share frames (addr=0x%08lx) is not mapped!\n",
> + (unsigned long)xen_auto_xlat_grant_frames.vaddr);
> return -ENOMEM;
> }
> }
> diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c
> index 2f3528e..f1947ac 100644
> --- a/drivers/xen/platform-pci.c
> +++ b/drivers/xen/platform-pci.c
> @@ -108,6 +108,7 @@ static int platform_pci_init(struct pci_dev *pdev,
> long ioaddr;
> long mmio_addr, mmio_len;
> unsigned int max_nr_gframes;
> + unsigned long grant_frames;
>
> if (!xen_domain())
> return -ENODEV;
> @@ -154,13 +155,16 @@ static int platform_pci_init(struct pci_dev *pdev,
> }
>
> max_nr_gframes = gnttab_max_grant_frames();
> - xen_hvm_resume_frames = alloc_xen_mmio(PAGE_SIZE * max_nr_gframes);
> + grant_frames = alloc_xen_mmio(PAGE_SIZE * max_nr_gframes);
> + if (gnttab_setup_auto_xlat_frames(grant_frames))
> + goto out;
> ret = gnttab_init();
> if (ret)
> - goto out;
> + goto grant_out;
> xenbus_probe(NULL);
> return 0;
> -
> +grant_out:
> + gnttab_free_auto_xlat_frames();
> out:
> pci_release_region(pdev, 0);
> mem_out:
> diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
> index 694dcaf..5acb1e4 100644
> --- a/include/xen/grant_table.h
> +++ b/include/xen/grant_table.h
> @@ -178,8 +178,15 @@ int arch_gnttab_map_status(uint64_t *frames, unsigned long nr_gframes,
> grant_status_t **__shared);
> void arch_gnttab_unmap(void *shared, unsigned long nr_gframes);
>
> -extern unsigned long xen_hvm_resume_frames;
> +struct grant_frames {
> + xen_pfn_t *pfn;
> + unsigned int count;
> + void *vaddr;
> +};
> +extern struct grant_frames xen_auto_xlat_grant_frames;
> unsigned int gnttab_max_grant_frames(void);
> +int gnttab_setup_auto_xlat_frames(unsigned long addr);
> +void gnttab_free_auto_xlat_frames(void);
>
> #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
>
> --
> 1.8.3.1
>
next prev parent reply other threads:[~2014-01-05 18:39 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-03 19:38 [PATCH v13] Linux Xen PVH support (v13) Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 01/19] xen/p2m: Check for auto-xlat when doing mfn_to_local_pfn Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 02/19] xen/pvh/x86: Define what an PVH guest is (v3) Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 03/19] xen/pvh: Early bootup changes in PV code (v4) Konrad Rzeszutek Wilk
2014-01-05 17:49 ` Stefano Stabellini
2014-01-03 19:38 ` [PATCH v13 04/19] xen/pvh: Don't setup P2M tree Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 05/19] xen/mmu/p2m: Refactor the xen_pagetable_init code (v2) Konrad Rzeszutek Wilk
2014-01-05 17:51 ` Stefano Stabellini
2014-01-03 19:38 ` [PATCH v13 06/19] xen/mmu: Cleanup xen_pagetable_p2m_copy a bit Konrad Rzeszutek Wilk
2014-01-05 17:56 ` Stefano Stabellini
2014-01-03 19:38 ` [PATCH v13 07/19] xen/pvh: MMU changes for PVH (v2) Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 08/19] xen/pvh/mmu: Use PV TLB instead of native Konrad Rzeszutek Wilk
2014-01-05 18:11 ` Stefano Stabellini
2014-01-05 19:41 ` Konrad Rzeszutek Wilk
2014-01-06 11:33 ` Stefano Stabellini
2014-01-06 14:59 ` Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 09/19] xen/pvh: Setup up shared_info Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 10/19] xen/pvh: Load GDT/GS in early PV bootup code for BSP Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 11/19] xen/pvh: Secondary VCPU bringup (non-bootup CPUs) Konrad Rzeszutek Wilk
2014-01-06 10:52 ` David Vrabel
2014-01-06 15:03 ` Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 12/19] xen/pvh: Update E820 to work with PVH (v2) Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 13/19] xen/pvh: Piggyback on PVHVM for event channels (v2) Konrad Rzeszutek Wilk
2014-01-05 18:15 ` Stefano Stabellini
2014-01-03 19:38 ` [PATCH v13 14/19] xen/grants: Remove gnttab_max_grant_frames dependency on gnttab_init Konrad Rzeszutek Wilk
2014-01-05 18:16 ` Stefano Stabellini
2014-01-03 19:38 ` [PATCH v13 15/19] xen/grant-table: Refactor gnttab_init Konrad Rzeszutek Wilk
2014-01-05 18:18 ` Stefano Stabellini
2014-01-05 19:33 ` Konrad Rzeszutek Wilk
2014-01-03 19:38 ` [PATCH v13 16/19] xen/grant: Implement an grant frame array struct (v2) Konrad Rzeszutek Wilk
2014-01-05 18:38 ` Stefano Stabellini [this message]
2014-01-03 19:38 ` [PATCH v13 17/19] xen/pvh: Piggyback on PVHVM for grant driver (v4) Konrad Rzeszutek Wilk
2014-01-05 18:20 ` Stefano Stabellini
2014-01-03 19:38 ` [PATCH v13 18/19] xen/pvh: Piggyback on PVHVM XenBus Konrad Rzeszutek Wilk
2014-01-05 17:54 ` Stefano Stabellini
2014-01-03 19:38 ` [PATCH v13 19/19] xen/pvh: Support ParaVirtualized Hardware extensions (v3) Konrad Rzeszutek Wilk
2014-01-06 10:55 ` [PATCH v13] Linux Xen PVH support (v13) David Vrabel
2014-01-06 14:53 ` Konrad Rzeszutek Wilk
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=alpine.DEB.2.02.1401051838010.8667@kaball.uk.xensource.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=hpa@zytor.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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
all inboxes | Powered by JetHome®