2007-07-18 01:37:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* grant_table.h
|
|
|
|
*
|
|
|
|
* Two sets of functionality:
|
|
|
|
* 1. Granting foreign access to our memory reservation.
|
|
|
|
* 2. Accessing others' memory reservations via grant references.
|
|
|
|
* (i.e., mechanisms for both sender and recipient of grant references)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004-2005, K A Fraser
|
|
|
|
* Copyright (c) 2005, Christopher Clark
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation; or, when distributed
|
|
|
|
* separately from the Linux kernel or incorporated into other
|
|
|
|
* software packages, subject to the following license:
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this source file (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy, modify,
|
|
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ASM_GNTTAB_H__
|
|
|
|
#define __ASM_GNTTAB_H__
|
|
|
|
|
2009-02-09 20:05:49 +00:00
|
|
|
#include <asm/page.h>
|
|
|
|
|
|
|
|
#include <xen/interface/xen.h>
|
2007-07-18 01:37:06 +00:00
|
|
|
#include <xen/interface/grant_table.h>
|
2009-02-09 20:05:49 +00:00
|
|
|
|
|
|
|
#include <asm/xen/hypervisor.h>
|
2007-07-18 01:37:06 +00:00
|
|
|
|
2009-02-09 20:05:49 +00:00
|
|
|
#include <xen/features.h>
|
2015-06-19 16:49:03 +00:00
|
|
|
#include <xen/page.h>
|
2014-12-24 14:17:06 +00:00
|
|
|
#include <linux/mm_types.h>
|
|
|
|
#include <linux/page-flags.h>
|
2015-06-19 16:49:03 +00:00
|
|
|
#include <linux/kernel.h>
|
2009-02-09 20:05:49 +00:00
|
|
|
|
2012-05-08 13:46:57 +00:00
|
|
|
#define GNTTAB_RESERVED_XENSTORE 1
|
|
|
|
|
2007-07-18 01:37:06 +00:00
|
|
|
/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
|
|
|
|
#define NR_GRANT_FRAMES 4
|
|
|
|
|
|
|
|
struct gnttab_free_callback {
|
|
|
|
struct gnttab_free_callback *next;
|
|
|
|
void (*fn)(void *);
|
|
|
|
void *arg;
|
|
|
|
u16 count;
|
|
|
|
};
|
|
|
|
|
2014-12-09 18:28:37 +00:00
|
|
|
struct gntab_unmap_queue_data;
|
|
|
|
|
|
|
|
typedef void (*gnttab_unmap_refs_done)(int result, struct gntab_unmap_queue_data *data);
|
|
|
|
|
|
|
|
struct gntab_unmap_queue_data
|
|
|
|
{
|
|
|
|
struct delayed_work gnttab_work;
|
|
|
|
void *data;
|
|
|
|
gnttab_unmap_refs_done done;
|
|
|
|
struct gnttab_unmap_grant_ref *unmap_ops;
|
|
|
|
struct gnttab_unmap_grant_ref *kunmap_ops;
|
|
|
|
struct page **pages;
|
|
|
|
unsigned int count;
|
|
|
|
unsigned int age;
|
|
|
|
};
|
|
|
|
|
2010-05-17 16:08:21 +00:00
|
|
|
int gnttab_init(void);
|
2008-05-26 22:31:27 +00:00
|
|
|
int gnttab_suspend(void);
|
|
|
|
int gnttab_resume(void);
|
|
|
|
|
2007-07-18 01:37:06 +00:00
|
|
|
int gnttab_grant_foreign_access(domid_t domid, unsigned long frame,
|
|
|
|
int readonly);
|
2011-12-12 10:15:07 +00:00
|
|
|
|
2007-07-18 01:37:06 +00:00
|
|
|
/*
|
|
|
|
* End access through the given grant reference, iff the grant entry is no
|
|
|
|
* longer in use. Return 1 if the grant entry was freed, 0 if it is still in
|
|
|
|
* use.
|
|
|
|
*/
|
|
|
|
int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Eventually end access through the given grant reference, and once that
|
|
|
|
* access has been ended, free the given page too. Access will be ended
|
|
|
|
* immediately iff the grant entry is not in use, otherwise it will happen
|
|
|
|
* some time later. page may be 0, in which case no freeing will occur.
|
|
|
|
*/
|
|
|
|
void gnttab_end_foreign_access(grant_ref_t ref, int readonly,
|
|
|
|
unsigned long page);
|
|
|
|
|
|
|
|
int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn);
|
|
|
|
|
|
|
|
unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref);
|
|
|
|
unsigned long gnttab_end_foreign_transfer(grant_ref_t ref);
|
|
|
|
|
|
|
|
int gnttab_query_foreign_access(grant_ref_t ref);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* operations on reserved batches of grant references
|
|
|
|
*/
|
|
|
|
int gnttab_alloc_grant_references(u16 count, grant_ref_t *pprivate_head);
|
|
|
|
|
|
|
|
void gnttab_free_grant_reference(grant_ref_t ref);
|
|
|
|
|
|
|
|
void gnttab_free_grant_references(grant_ref_t head);
|
|
|
|
|
|
|
|
int gnttab_empty_grant_references(const grant_ref_t *pprivate_head);
|
|
|
|
|
|
|
|
int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
|
|
|
|
|
|
|
|
void gnttab_release_grant_reference(grant_ref_t *private_head,
|
|
|
|
grant_ref_t release);
|
|
|
|
|
|
|
|
void gnttab_request_free_callback(struct gnttab_free_callback *callback,
|
|
|
|
void (*fn)(void *), void *arg, u16 count);
|
|
|
|
void gnttab_cancel_free_callback(struct gnttab_free_callback *callback);
|
|
|
|
|
|
|
|
void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
|
|
|
|
unsigned long frame, int readonly);
|
|
|
|
|
2015-06-19 17:05:06 +00:00
|
|
|
/* Give access to the first 4K of the page */
|
|
|
|
static inline void gnttab_page_grant_foreign_access_ref_one(
|
|
|
|
grant_ref_t ref, domid_t domid,
|
|
|
|
struct page *page, int readonly)
|
|
|
|
{
|
|
|
|
gnttab_grant_foreign_access_ref(ref, domid, xen_page_to_gfn(page),
|
|
|
|
readonly);
|
|
|
|
}
|
|
|
|
|
2007-07-18 01:37:06 +00:00
|
|
|
void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid,
|
|
|
|
unsigned long pfn);
|
|
|
|
|
2009-02-09 20:05:49 +00:00
|
|
|
static inline void
|
|
|
|
gnttab_set_map_op(struct gnttab_map_grant_ref *map, phys_addr_t addr,
|
|
|
|
uint32_t flags, grant_ref_t ref, domid_t domid)
|
|
|
|
{
|
|
|
|
if (flags & GNTMAP_contains_pte)
|
|
|
|
map->host_addr = addr;
|
|
|
|
else if (xen_feature(XENFEAT_auto_translated_physmap))
|
|
|
|
map->host_addr = __pa(addr);
|
|
|
|
else
|
|
|
|
map->host_addr = addr;
|
|
|
|
|
|
|
|
map->flags = flags;
|
|
|
|
map->ref = ref;
|
|
|
|
map->dom = domid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, phys_addr_t addr,
|
|
|
|
uint32_t flags, grant_handle_t handle)
|
|
|
|
{
|
|
|
|
if (flags & GNTMAP_contains_pte)
|
|
|
|
unmap->host_addr = addr;
|
|
|
|
else if (xen_feature(XENFEAT_auto_translated_physmap))
|
|
|
|
unmap->host_addr = __pa(addr);
|
|
|
|
else
|
|
|
|
unmap->host_addr = addr;
|
|
|
|
|
|
|
|
unmap->handle = handle;
|
|
|
|
unmap->dev_bus_addr = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-02 09:19:17 +00:00
|
|
|
int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status);
|
2012-10-17 08:39:14 +00:00
|
|
|
int arch_gnttab_map_shared(xen_pfn_t *frames, unsigned long nr_gframes,
|
2008-04-02 17:54:00 +00:00
|
|
|
unsigned long max_nr_gframes,
|
2011-11-22 01:58:06 +00:00
|
|
|
void **__shared);
|
2017-11-02 09:19:17 +00:00
|
|
|
int arch_gnttab_map_status(uint64_t *frames, unsigned long nr_gframes,
|
|
|
|
unsigned long max_nr_gframes,
|
|
|
|
grant_status_t **__shared);
|
xen/granttable: Grant tables V2 implementation
Receiver-side copying of packets is based on this implementation, it gives
better performance and better CPU accounting. It totally supports three types:
full-page, sub-page and transitive grants.
However this patch does not cover sub-page and transitive grants, it mainly
focus on Full-page part and implements grant table V2 interfaces corresponding
to what already exists in grant table V1, such as: grant table V2
initialization, mapping, releasing and exported interfaces.
Each guest can only supports one type of grant table type, every entry in grant
table should be the same version. It is necessary to set V1 or V2 version before
initializing the grant table.
Grant table exported interfaces of V2 are same with those of V1, Xen is
responsible to judge what grant table version guests are using in every grant
operation.
V2 fulfills the same role of V1, and it is totally backwards compitable with V1.
If dom0 support grant table V2, the guests runing on it can run with either V1
or V2.
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Annie Li <annie.li@oracle.com>
[v1: Modified alloc_vm_area call (new parameters), indentation, and cleanpatch
warnings]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
2011-11-22 01:59:21 +00:00
|
|
|
void arch_gnttab_unmap(void *shared, unsigned long nr_gframes);
|
2008-04-02 17:54:00 +00:00
|
|
|
|
2014-01-06 15:40:36 +00:00
|
|
|
struct grant_frames {
|
|
|
|
xen_pfn_t *pfn;
|
|
|
|
unsigned int count;
|
|
|
|
void *vaddr;
|
|
|
|
};
|
|
|
|
extern struct grant_frames xen_auto_xlat_grant_frames;
|
2010-05-17 16:08:21 +00:00
|
|
|
unsigned int gnttab_max_grant_frames(void);
|
2014-01-30 12:56:34 +00:00
|
|
|
int gnttab_setup_auto_xlat_frames(phys_addr_t addr);
|
2014-01-06 15:40:36 +00:00
|
|
|
void gnttab_free_auto_xlat_frames(void);
|
2010-05-17 16:08:21 +00:00
|
|
|
|
2007-07-18 01:37:06 +00:00
|
|
|
#define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
|
|
|
|
|
2015-01-08 18:06:01 +00:00
|
|
|
int gnttab_alloc_pages(int nr_pages, struct page **pages);
|
|
|
|
void gnttab_free_pages(int nr_pages, struct page **pages);
|
|
|
|
|
2010-12-10 14:54:44 +00:00
|
|
|
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
|
2014-02-03 11:43:59 +00:00
|
|
|
struct gnttab_map_grant_ref *kmap_ops,
|
2010-12-10 14:54:44 +00:00
|
|
|
struct page **pages, unsigned int count);
|
|
|
|
int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
|
2015-01-05 14:13:41 +00:00
|
|
|
struct gnttab_unmap_grant_ref *kunmap_ops,
|
2012-09-12 11:44:30 +00:00
|
|
|
struct page **pages, unsigned int count);
|
2014-12-09 18:28:37 +00:00
|
|
|
void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item);
|
2015-04-03 06:42:59 +00:00
|
|
|
int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item);
|
2014-12-09 18:28:37 +00:00
|
|
|
|
2010-12-10 14:54:44 +00:00
|
|
|
|
2012-09-14 14:26:59 +00:00
|
|
|
/* Perform a batch of grant map/copy operations. Retry every batch slot
|
|
|
|
* for which the hypervisor returns GNTST_eagain. This is typically due
|
|
|
|
* to paged out target frames.
|
|
|
|
*
|
|
|
|
* Will retry for 1, 2, ... 255 ms, i.e. 256 times during 32 seconds.
|
|
|
|
*
|
|
|
|
* Return value in each iand every status field of the batch guaranteed
|
|
|
|
* to not be GNTST_eagain.
|
|
|
|
*/
|
|
|
|
void gnttab_batch_map(struct gnttab_map_grant_ref *batch, unsigned count);
|
|
|
|
void gnttab_batch_copy(struct gnttab_copy *batch, unsigned count);
|
|
|
|
|
2014-12-24 14:17:06 +00:00
|
|
|
|
|
|
|
struct xen_page_foreign {
|
|
|
|
domid_t domid;
|
|
|
|
grant_ref_t gref;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct xen_page_foreign *xen_page_foreign(struct page *page)
|
|
|
|
{
|
|
|
|
if (!PageForeign(page))
|
|
|
|
return NULL;
|
|
|
|
#if BITS_PER_LONG < 64
|
|
|
|
return (struct xen_page_foreign *)page->private;
|
|
|
|
#else
|
|
|
|
BUILD_BUG_ON(sizeof(struct xen_page_foreign) > BITS_PER_LONG);
|
|
|
|
return (struct xen_page_foreign *)&page->private;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-06-19 16:49:03 +00:00
|
|
|
/* Split Linux page in chunk of the size of the grant and call fn
|
|
|
|
*
|
|
|
|
* Parameters of fn:
|
|
|
|
* gfn: guest frame number
|
|
|
|
* offset: offset in the grant
|
|
|
|
* len: length of the data in the grant.
|
|
|
|
* data: internal information
|
|
|
|
*/
|
|
|
|
typedef void (*xen_grant_fn_t)(unsigned long gfn, unsigned int offset,
|
|
|
|
unsigned int len, void *data);
|
|
|
|
|
|
|
|
void gnttab_foreach_grant_in_range(struct page *page,
|
|
|
|
unsigned int offset,
|
|
|
|
unsigned int len,
|
|
|
|
xen_grant_fn_t fn,
|
|
|
|
void *data);
|
|
|
|
|
|
|
|
/* Helper to get to call fn only on the first "grant chunk" */
|
|
|
|
static inline void gnttab_for_one_grant(struct page *page, unsigned int offset,
|
|
|
|
unsigned len, xen_grant_fn_t fn,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
/* The first request is limited to the size of one grant */
|
|
|
|
len = min_t(unsigned int, XEN_PAGE_SIZE - (offset & ~XEN_PAGE_MASK),
|
|
|
|
len);
|
|
|
|
|
|
|
|
gnttab_foreach_grant_in_range(page, offset, len, fn, data);
|
|
|
|
}
|
|
|
|
|
2015-10-13 16:50:12 +00:00
|
|
|
/* Get @nr_grefs grants from an array of page and call fn for each grant */
|
|
|
|
void gnttab_foreach_grant(struct page **pages,
|
|
|
|
unsigned int nr_grefs,
|
|
|
|
xen_grant_fn_t fn,
|
|
|
|
void *data);
|
|
|
|
|
2015-06-19 16:49:03 +00:00
|
|
|
/* Get the number of grant in a specified region
|
|
|
|
*
|
|
|
|
* start: Offset from the beginning of the first page
|
|
|
|
* len: total length of data (can cross multiple page)
|
|
|
|
*/
|
|
|
|
static inline unsigned int gnttab_count_grant(unsigned int start,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
return XEN_PFN_UP(xen_offset_in_page(start) + len);
|
|
|
|
}
|
|
|
|
|
2007-07-18 01:37:06 +00:00
|
|
|
#endif /* __ASM_GNTTAB_H__ */
|