haven: irq_lend: Defer vm_name to vmid translation

Presently, hh_irq_wait_for_lend translates supplied vm_name to vmid.
However, if this function is called prior to RM populating this table,
then wait_for_lend call fails with -EINVAL. Translating vm_name to vmid
in wait_for_lend is unnecessary, and only done because it was convenient
in private data structure. Thus, add vm_name to the private data
structure and translate vm_names upon receiving a lend notification.

Change-Id: Iaa51aaab42508ffa121a550afa0568a048327dca
Signed-off-by: Elliot Berman <eberman@codeaurora.org>
This commit is contained in:
Elliot Berman 2020-05-01 14:56:01 -07:00
commit 4510fcd855
2 changed files with 19 additions and 11 deletions

View file

@ -16,6 +16,7 @@
struct hh_irq_entry {
hh_vmid_t vmid;
enum hh_vm_names vm_name;
hh_irq_handle_fn handle;
void *data;
@ -80,12 +81,21 @@ static int hh_irq_lent_nb_handler(struct notifier_block *this,
{
unsigned long flags;
enum hh_irq_label label;
enum hh_vm_names owner_name;
struct hh_irq_entry *entry;
struct hh_rm_notif_vm_irq_lent_payload *lent = data;
int ret;
if (cmd != HH_RM_NOTIF_VM_IRQ_LENT)
return NOTIFY_DONE;
ret = hh_rm_get_vm_name(lent->owner_vmid, &owner_name);
if (ret) {
pr_warn_ratelimited("%s: unknown name for vmid: %d\n", __func__,
lent->owner_vmid);
return ret;
}
spin_lock_irqsave(&hh_irq_lend_lock, flags);
for (label = 0; label < HH_IRQ_LABEL_MAX; label++) {
entry = &hh_irq_entries[label];
@ -93,8 +103,8 @@ static int hh_irq_lent_nb_handler(struct notifier_block *this,
continue;
if (label == lent->virq_label &&
(entry->vmid == HH_VM_MAX ||
entry->vmid == lent->owner_vmid)) {
(entry->vm_name == HH_VM_MAX ||
entry->vm_name == owner_name)) {
entry->vmid = lent->owner_vmid;
entry->virq_handle = lent->virq_handle;
@ -207,7 +217,6 @@ EXPORT_SYMBOL(hh_irq_reclaim);
int hh_irq_wait_for_lend(enum hh_irq_label label, enum hh_vm_names name,
hh_irq_handle_fn on_lend, void *data)
{
int ret;
unsigned long flags;
struct hh_irq_entry *entry;
@ -222,19 +231,13 @@ int hh_irq_wait_for_lend(enum hh_irq_label label, enum hh_vm_names name,
return -EINVAL;
}
ret = hh_rm_get_vmid(name, &entry->vmid);
if (ret) {
entry->state = HH_IRQ_STATE_NONE;
spin_unlock_irqrestore(&hh_irq_lend_lock, flags);
return ret;
}
entry->vm_name = name;
entry->handle = on_lend;
entry->data = data;
entry->state = HH_IRQ_STATE_WAIT_LEND;
spin_unlock_irqrestore(&hh_irq_lend_lock, flags);
return ret;
return 0;
}
EXPORT_SYMBOL(hh_irq_wait_for_lend);

View file

@ -194,6 +194,7 @@ out:
kfree(resp_payload);
return ret;
}
EXPORT_SYMBOL(hh_rm_vm_irq_accept);
/**
* hh_rm_vm_irq_lend: Lend an IRQ to another VM
@ -333,6 +334,7 @@ int hh_rm_vm_irq_lend_notify(hh_vmid_t vmid, int virq, int label,
return hh_rm_vm_irq_notify(&vmid, 1, HH_VM_IRQ_NOTIFY_FLAGS_LENT,
*virq_handle);
}
EXPORT_SYMBOL(hh_rm_vm_irq_lend_notify);
/**
* hh_rm_vm_irq_release: Return a lent IRQ
@ -371,6 +373,7 @@ static int hh_rm_vm_irq_release(hh_virq_handle_t virq_handle)
return ret;
}
EXPORT_SYMBOL(hh_rm_vm_irq_release);
/**
* hh_rm_vm_irq_release_notify: Release IRQ back to a VM and notify that it has
@ -389,6 +392,7 @@ int hh_rm_vm_irq_release_notify(hh_vmid_t vmid, hh_virq_handle_t virq_handle)
return hh_rm_vm_irq_notify(NULL, 0, HH_VM_IRQ_NOTIFY_FLAGS_RELEASED,
virq_handle);
}
EXPORT_SYMBOL(hh_rm_vm_irq_release_notify);
/**
* hh_rm_vm_irq_reclaim: Return a lent IRQ
@ -427,6 +431,7 @@ int hh_rm_vm_irq_reclaim(hh_virq_handle_t virq_handle)
return ret;
}
EXPORT_SYMBOL(hh_rm_vm_irq_reclaim);
/**
* hh_rm_vm_alloc_vmid: Return a vmid associated with the vm loaded into