x86/mem_sharing: cleanup code and comments in various locations

No functional changes.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@intel.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
[Further cleanup]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
Tamas K Lengyel authored and Andrew Cooper committed 2019-12-19 18:05:11 +00:00
1 parent e09aa1dbf3
commit ca14eba3cc
4 files changed
+538 -482

No files matched your search

+7 -6
View File
@@ -1884,7 +1884,7 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,
* If this GFN is emulated MMIO or marked as read-only, pass the fault
* to the mmio handler.
*/
if ( (p2mt == p2m_mmio_dm) ||
if ( (p2mt == p2m_mmio_dm) ||
(npfec.write_access &&
(p2m_is_discard_write(p2mt) || (p2mt == p2m_ioreq_server))) )
{
@@ -1902,12 +1902,11 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,
if ( npfec.write_access && (p2mt == p2m_ram_shared) )
{
ASSERT(p2m_is_hostp2m(p2m));
sharing_enomem =
(mem_sharing_unshare_page(currd, gfn, 0) < 0);
sharing_enomem = mem_sharing_unshare_page(currd, gfn, 0);
rc = 1;
goto out_put_gfn;
}
/* Spurious fault? PoD and log-dirty also take this path. */
if ( p2m_is_ram(p2mt) )
{
@@ -1953,9 +1952,11 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,
__put_gfn(p2m, gfn);
__put_gfn(hostp2m, gfn);
out:
/* All of these are delayed until we exit, since we might
/*
* All of these are delayed until we exit, since we might
* sleep on event ring wait queues, and we must not hold
* locks in such circumstance */
* locks in such circumstance.
*/
if ( paged )
p2m_mem_paging_populate(currd, gfn);
if ( sharing_enomem )
File diff suppressed because it is too large. Load diff
+10 -7
View File
@@ -511,8 +511,10 @@ mfn_t __get_gfn_type_access(struct p2m_domain *p2m, unsigned long gfn_l,
if ( (q & P2M_UNSHARE) && p2m_is_shared(*t) )
{
ASSERT(p2m_is_hostp2m(p2m));
/* Try to unshare. If we fail, communicate ENOMEM without
* sleeping. */
/*
* Try to unshare. If we fail, communicate ENOMEM without
* sleeping.
*/
if ( mem_sharing_unshare_page(p2m->domain, gfn_l, 0) < 0 )
mem_sharing_notify_enomem(p2m->domain, gfn_l, false);
mfn = p2m->get_entry(p2m, gfn, t, a, q, page_order, NULL);
@@ -892,15 +894,15 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
&a, 0, NULL, NULL);
if ( p2m_is_shared(ot) )
{
/* Do an unshare to cleanly take care of all corner
* cases. */
/* Do an unshare to cleanly take care of all corner cases. */
int rc;
rc = mem_sharing_unshare_page(p2m->domain,
gfn_x(gfn_add(gfn, i)), 0);
if ( rc )
{
p2m_unlock(p2m);
/* NOTE: Should a guest domain bring this upon itself,
/*
* NOTE: Should a guest domain bring this upon itself,
* there is not a whole lot we can do. We are buried
* deep in locks from most code paths by now. So, fail
* the call and don't try to sleep on a wait queue
@@ -909,8 +911,9 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
* However, all current (changeset 3432abcf9380) code
* paths avoid this unsavoury situation. For now.
*
* Foreign domains are okay to place an event as they
* won't go to sleep. */
* Foreign domains are okay to place an event as they
* won't go to sleep.
*/
(void)mem_sharing_notify_enomem(p2m->domain,
gfn_x(gfn_add(gfn, i)), false);
return rc;
+22 -18
View File
@@ -33,12 +33,14 @@
#define MEM_SHARING_AUDIT 0
#endif
typedef uint64_t shr_handle_t;
typedef uint64_t shr_handle_t;
typedef struct rmap_hashtab {
struct list_head *bucket;
/* Overlaps with prev pointer of list_head in union below.
* Unlike the prev pointer, this can be NULL. */
/*
* Overlaps with prev pointer of list_head in union below.
* Unlike the prev pointer, this can be NULL.
*/
void *flag;
} rmap_hashtab_t;
@@ -57,34 +59,33 @@ struct page_sharing_info
};
};
#define sharing_supported(_d) \
(is_hvm_domain(_d) && paging_mode_hap(_d))
unsigned int mem_sharing_get_nr_saved_mfns(void);
unsigned int mem_sharing_get_nr_shared_mfns(void);
#define MEM_SHARING_DESTROY_GFN (1<<1)
/* Only fails with -ENOMEM. Enforce it with a BUG_ON wrapper. */
int __mem_sharing_unshare_page(struct domain *d,
unsigned long gfn,
uint16_t flags);
unsigned long gfn,
uint16_t flags);
static inline int mem_sharing_unshare_page(struct domain *d,
unsigned long gfn,
uint16_t flags)
{
int rc = __mem_sharing_unshare_page(d, gfn, flags);
BUG_ON( rc && (rc != -ENOMEM) );
BUG_ON(rc && (rc != -ENOMEM));
return rc;
}
/* If called by a foreign domain, possible errors are
/*
* If called by a foreign domain, possible errors are
* -EBUSY -> ring full
* -ENOSYS -> no ring to begin with
* and the foreign mapper is responsible for retrying.
*
* If called by the guest vcpu itself and allow_sleep is set, may
* sleep on a wait queue, so the caller is responsible for not
* holding locks on entry. It may only fail with ENOSYS
* If called by the guest vcpu itself and allow_sleep is set, may
* sleep on a wait queue, so the caller is responsible for not
* holding locks on entry. It may only fail with ENOSYS
*
* If called by the guest vcpu itself and allow_sleep is not set,
* then it's the same as a foreign domain.
@@ -92,10 +93,11 @@ static inline int mem_sharing_unshare_page(struct domain *d,
int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn,
bool allow_sleep);
int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg);
int mem_sharing_domctl(struct domain *d,
int mem_sharing_domctl(struct domain *d,
struct xen_domctl_mem_sharing_op *mec);
/* Scans the p2m and relinquishes any shared pages, destroying
/*
* Scans the p2m and relinquishes any shared pages, destroying
* those for which this domain holds the final reference.
* Preemptible.
*/
@@ -107,19 +109,21 @@ static inline unsigned int mem_sharing_get_nr_saved_mfns(void)
{
return 0;
}
static inline unsigned int mem_sharing_get_nr_shared_mfns(void)
{
return 0;
}
static inline int mem_sharing_unshare_page(struct domain *d,
unsigned long gfn,
static inline int mem_sharing_unshare_page(struct domain *d, unsigned long gfn,
uint16_t flags)
{
ASSERT_UNREACHABLE();
return -EOPNOTSUPP;
}
static inline int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn,
bool allow_sleep)
bool allow_sleep)
{
ASSERT_UNREACHABLE();
return -EOPNOTSUPP;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.