memobj: transform memobj lock to refcounting

We had a deadlock between:
 - free_process_memory_range (take lock) -> ihk_mc_pt_free_range ->
... -> remote_flush_tlb_array_cpumask -> "/* Wait for all cores */"
and
 - obj_list_lookup() under fileobj_list_lock that disabled irqs
and thus never ack'd the remote flush

The rework is quite big but removes the need for the big lock,
although devobj and shmobj needed a new smaller lock to be
introduced - the new locks are used much more locally and
should not cause problems.

On the bright side, refcounting being moved to memobj level means
we could remove refcounting implemented separately in all object
types and simplifies code a bit.

Change-Id: I6bc8438a98b1d8edddc91c4ac33c11b88e097ebb
This commit is contained in:
Dominique Martinet
2018-08-07 15:40:25 +09:00
parent b51886421e
commit c25fb2aa39
10 changed files with 307 additions and 403 deletions

View File

@@ -32,9 +32,11 @@ static ihk_spinlock_t the_zeroobj_lock = SPIN_LOCK_UNLOCKED;
static struct zeroobj *the_zeroobj = NULL; /* singleton */
static memobj_get_page_func_t zeroobj_get_page;
static memobj_free_func_t zeroobj_free;
static struct memobj_ops zeroobj_ops = {
.get_page = &zeroobj_get_page,
.free = &zeroobj_free,
};
static struct zeroobj *to_zeroobj(struct memobj *memobj)
@@ -74,6 +76,12 @@ static struct page *page_list_first(struct zeroobj *obj)
/***********************************************************************
* zeroobj
*/
static void zeroobj_free(struct memobj *obj)
{
kprintf("trying to free zeroobj, this should never happen\n");
}
static int alloc_zeroobj(void)
{
int error;
@@ -101,8 +109,8 @@ static int alloc_zeroobj(void)
obj->memobj.ops = &zeroobj_ops;
obj->memobj.flags = MF_ZEROOBJ;
obj->memobj.size = 0;
ihk_atomic_set(&obj->memobj.refcnt, 2); // never reaches 0
page_list_init(obj);
ihk_mc_spinlock_init(&obj->memobj.lock);
virt = ihk_mc_alloc_pages(1, IHK_MC_AP_NOWAIT); /* XXX:NYI:large page */
if (!virt) {
@@ -159,6 +167,7 @@ int zeroobj_create(struct memobj **objp)
error = 0;
*objp = to_memobj(the_zeroobj);
memobj_ref(*objp);
out:
dkprintf("zeroobj_create(%p):%d %p\n", objp, error, *objp);