idxd_device_reset(idxd);
rc = idxd_device_config(idxd); if (rc < 0) goto out;
rc = idxd_device_enable(idxd); if (rc < 0) goto out;
for (i = 0; i < idxd->max_wqs; i++) { if (test_bit(i, idxd->wq_enable_map)) { struct idxd_wq *wq = idxd->wqs[i];
rc = idxd_wq_enable(wq); if (rc < 0) {
clear_bit(i, idxd->wq_enable_map);
dev_warn(dev, "Unable to re-enable wq %s\n",
dev_name(wq_confdev(wq)));
}
}
}
return;
out:
idxd_device_clear_state(idxd);
}
/* * The function sends a drain descriptor for the interrupt handle. The drain ensures * all descriptors with this interrupt handle is flushed and the interrupt * will allow the cleanup of the outstanding descriptors.
*/ staticvoid idxd_int_handle_revoke_drain(struct idxd_irq_entry *ie)
{ struct idxd_wq *wq = ie_to_wq(ie); struct idxd_device *idxd = wq->idxd; struct device *dev = &idxd->pdev->dev; struct dsa_hw_desc desc = {}; void __iomem *portal; int rc;
/* Issue a simple drain operation with interrupt but no completion record */
desc.flags = IDXD_OP_FLAG_RCI;
desc.opcode = DSA_OPCODE_DRAIN;
desc.priv = 1;
/* * The wmb() makes sure that the descriptor is all there before we * issue.
*/
wmb(); if (wq_dedicated(wq)) {
iosubmit_cmds512(portal, &desc, 1);
} else {
rc = idxd_enqcmds(wq, portal, &desc); /* This should not fail unless hardware failed. */ if (rc < 0)
dev_warn(dev, "Failed to submit drain desc on wq %d\n", wq->id);
}
}
if (!idxd->request_int_handles) {
kfree(revoke);
dev_warn(dev, "Unexpected int handle refresh interrupt.\n"); return;
}
/* * The loop attempts to acquire new interrupt handle for all interrupt * vectors that supports a handle. If a new interrupt handle is acquired and the * wq is kernel type, the driver will kill the percpu_ref to pause all * ongoing descriptor submissions. The interrupt handle is then changed. * After change, the percpu_ref is revived and all the pending submissions * are woken to try again. A drain is sent to for the interrupt handle * at the end to make sure all invalid int handle descriptors are processed.
*/ for (i = 1; i < idxd->irq_cnt; i++) { struct idxd_irq_entry *ie = idxd_get_ie(idxd, i); struct idxd_wq *wq = ie_to_wq(ie);
if (ie->int_handle == INVALID_INT_HANDLE) continue;
rc = idxd_device_request_int_handle(idxd, i, &new_handle, IDXD_IRQ_MSIX); if (rc < 0) {
dev_warn(dev, "get int handle %d failed: %d\n", i, rc); /* * Failed to acquire new interrupt handle. Kill the WQ * and release all the pending submitters. The submitters will * get error return code and handle appropriately.
*/
ie->int_handle = INVALID_INT_HANDLE;
idxd_wq_quiesce(wq);
idxd_abort_invalid_int_handle_descs(ie); continue;
}
/* No change in interrupt handle, nothing needs to be done */ if (ie->int_handle == new_handle) continue;
if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL) { /* * All the MSIX interrupts are allocated at once during probe. * Therefore we need to update all interrupts even if the WQ * isn't supporting interrupt operations.
*/
ie->int_handle = new_handle; continue;
}
/* Kill percpu_ref to pause additional descriptor submissions */
percpu_ref_kill(&wq->wq_active);
/* Wait for all submitters quiesce before we change interrupt handle */
wait_for_completion(&wq->wq_dead);
ie->int_handle = new_handle;
/* Revive percpu ref and wake up all the waiting submitters */
percpu_ref_reinit(&wq->wq_active);
complete_all(&wq->wq_resurrect);
mutex_unlock(&wq->wq_lock);
/* * The delay here is to wait for all possible MOVDIR64B that * are issued before percpu_ref_kill() has happened to have * reached the PCIe domain before the drain is issued. The driver * needs to ensure that the drain descriptor issued does not pass * all the other issued descriptors that contain the invalid * interrupt handle in order to ensure that the drain descriptor * interrupt will allow the cleanup of all the descriptors with * invalid interrupt handle.
*/ if (wq_dedicated(wq))
udelay(100);
idxd_int_handle_revoke_drain(ie);
}
kfree(revoke);
}
/* * Copy completion record to fault_addr in user address space * that is found by wq and PASID.
*/
copied = idxd_copy_cr(wq, entry_head->pasid, entry_head->fault_addr,
cr, copy_size); /* * The task that triggered the page fault is unknown currently * because multiple threads may share the user address * space or the task exits already before this fault. * So if the copy fails, SIGSEGV can not be sent to the task. * Just print an error for the failure. The user application * waiting for the completion record will time out on this * failure.
*/ switch (fault->status) { case DSA_COMP_CRA_XLAT: if (copied != copy_size) {
idxd_user_counter_increment(wq, entry_head->pasid, COUNTER_FAULT_FAILS);
dev_dbg_ratelimited(dev, "Failed to write to completion record: (%d:%d)\n",
copy_size, copied); if (entry_head->batch)
evl->batch_fail[entry_head->batch_id] = true;
} break; case DSA_COMP_BATCH_EVL_ERR: if (copied != copy_size) {
idxd_user_counter_increment(wq, entry_head->pasid, COUNTER_FAULT_FAILS);
dev_dbg_ratelimited(dev, "Failed to write to batch completion record: (%d:%d)\n",
copy_size, copied);
} break; case DSA_COMP_DRAIN_EVL: if (copied != copy_size)
dev_dbg_ratelimited(dev, "Failed to write to drain completion record: (%d:%d)\n",
copy_size, copied); break;
}
if (test_bit(index, evl->bmap)) {
clear_bit(index, evl->bmap);
} else {
status = DSA_COMP_STATUS(entry_head->error);
if (status == DSA_COMP_CRA_XLAT || status == DSA_COMP_DRAIN_EVL ||
status == DSA_COMP_BATCH_EVL_ERR) { struct idxd_evl_fault *fault; int ent_size = evl_ent_size(idxd);
if (entry_head->rci)
dev_dbg(dev, "Completion Int Req set, ignoring!\n");
if (!entry_head->rcr && status == DSA_COMP_DRAIN_EVL) return;
/* * IDXD device requires a Function Level Reset (FLR). * pci_reset_function() will reset the device with FLR.
*/
rc = pci_reset_function(idxd->pdev); if (rc)
dev_err(&idxd->pdev->dev, "FLR failed\n");
}
static irqreturn_t idxd_halt(struct idxd_device *idxd)
{ union gensts_reg gensts;
gensts.bits = ioread32(idxd->reg_base + IDXD_GENSTATS_OFFSET); if (gensts.state == IDXD_DEVICE_STATE_HALT) {
idxd->state = IDXD_DEV_HALTED; if (gensts.reset_type == IDXD_DEVICE_RESET_SOFTWARE) { /* * If we need a software reset, we will throw the work * on a system workqueue in order to allow interrupts * for the device command completions.
*/
INIT_WORK(&idxd->work, idxd_device_reinit);
queue_work(idxd->wq, &idxd->work);
} elseif (gensts.reset_type == IDXD_DEVICE_RESET_FLR) {
idxd->state = IDXD_DEV_HALTED;
idxd_mask_error_interrupts(idxd);
dev_dbg(&idxd->pdev->dev, "idxd halted, doing FLR. After FLR, configs are restored\n");
INIT_WORK(&idxd->work, idxd_device_flr);
queue_work(idxd->wq, &idxd->work);
} else {
idxd->state = IDXD_DEV_HALTED;
idxd_wqs_quiesce(idxd);
idxd_wqs_unmap_portal(idxd);
idxd_device_clear_state(idxd);
dev_err(&idxd->pdev->dev, "idxd halted, need system reset");
if (cause & IDXD_INTC_HALT_STATE) return idxd_halt(idxd);
if (cause & IDXD_INTC_ERR) {
spin_lock(&idxd->dev_lock); for (i = 0; i < 4; i++)
idxd->sw_err.bits[i] = ioread64(idxd->reg_base +
IDXD_SWERR_OFFSET + i * sizeof(u64));
desc->completion->status = 0;
rc = idxd_submit_desc(wq, desc); if (rc < 0) {
dev_dbg(&wq->idxd->pdev->dev, "Failed to resubmit desc %d to wq %d.\n",
desc->id, wq->id); /* * If the error is not -EAGAIN, it means the submission failed due to wq * has been killed instead of ENQCMDS failure. Here the driver needs to * notify the submitter of the failure by reporting abort status. * * -EAGAIN comes from ENQCMDS failure. idxd_submit_desc() will handle the * abort.
*/ if (rc != -EAGAIN) {
desc->completion->status = IDXD_COMP_DESC_ABORT;
idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, false);
}
idxd_free_desc(wq, desc);
}
kfree(irw);
}
if (status) { /* * Check against the original status as ABORT is software defined * and 0xff, which DSA_COMP_STATUS_MASK can mask out.
*/ if (unlikely(desc->completion->status == IDXD_COMP_DESC_ABORT)) {
idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true); continue;
}
/* * This lock protects list corruption from access of list outside of the irq handler * thread.
*/
spin_lock(&irq_entry->list_lock); if (list_empty(&irq_entry->work_list)) {
spin_unlock(&irq_entry->list_lock); return;
}
list_for_each_entry_safe(desc, n, &irq_entry->work_list, list) { if (desc->completion->status) {
list_move_tail(&desc->list, &flist);
}
}
spin_unlock(&irq_entry->list_lock);
list_for_each_entry_safe(desc, n, &flist, list) { /* * Check against the original status as ABORT is software defined * and 0xff, which DSA_COMP_STATUS_MASK can mask out.
*/
list_del(&desc->list);
if (unlikely(desc->completion->status == IDXD_COMP_DESC_ABORT)) {
idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true); continue;
}
/* * There are two lists we are processing. The pending_llist is where * submmiter adds all the submitted descriptor after sending it to * the workqueue. It's a lockless singly linked list. The work_list * is the common linux double linked list. We are in a scenario of * multiple producers and a single consumer. The producers are all * the kernel submitters of descriptors, and the consumer is the * kernel irq handler thread for the msix vector when using threaded * irq. To work with the restrictions of llist to remain lockless, * we are doing the following steps: * 1. Iterate through the work_list and process any completed * descriptor. Delete the completed entries during iteration. * 2. llist_del_all() from the pending list. * 3. Iterate through the llist that was deleted from the pending list * and process the completed entries. * 4. If the entry is still waiting on hardware, list_add_tail() to * the work_list.
*/
irq_process_work_list(irq_entry);
irq_process_pending_llist(irq_entry);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.