Page MenuHomeFreeBSD

Intel IOMMU DMAR suspend/resume support (only without QI for now)
Needs ReviewPublic

Authored by val_packett.cool on Dec 3 2019, 2:23 PM.
Tags
Referenced Files
Unknown Object (File)
Wed, Nov 6, 5:30 PM
Unknown Object (File)
Oct 16 2024, 3:58 AM
Unknown Object (File)
Oct 13 2024, 10:06 AM
Unknown Object (File)
Oct 11 2024, 10:30 AM
Unknown Object (File)
Oct 9 2024, 1:01 AM
Unknown Object (File)
Oct 6 2024, 8:13 PM
Unknown Object (File)
Oct 4 2024, 9:26 AM
Unknown Object (File)
Oct 3 2024, 9:22 AM
Subscribers

Details

Reviewers
kib
Group Reviewers
Contributor Reviews (src)
Summary

Trying to sort of vaguely do what Linux does. With queued invalidation disabled (hw.dmar.enable=1 hw.dmar.qi=0) my laptop actually does resume :)

(debug prints are left over in the patch, I'll remove them in a later update)

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

DMARs must be suspended after, and resumed before any subordinate devices. Because DMARs do not participate in the newbus hierarchy, or rather, they are placed there in the arbitrary place determined by not relevant details of the driver implementation, newbus suspend/resume methods are really not appropriate to use. The methods should be nops, and actual suspend/resume done near nexus.

sys/x86/iommu/intel_dmar.h
247

The structure is not needed.

sys/x86/iommu/intel_drv.c
676

For this to have even a chance to work, you must reinitialize the queue before enabling qi. Also, I am surprised that it worked for you, since if queued invalidation was used, queue must be re-enabled for TLB flushes to work after resume, as well.

687

Command invalidation must not be used if queued invalidation is enabled.

690

This should only be done if translations were enabled before suspend.

693

You need to clear potentially unprocessed faults before enabling fault interrupt.

val_packett.cool added inline comments.
sys/x86/iommu/intel_dmar.h
247

of course, I just thought it was a nice thing to do :)

sys/x86/iommu/intel_drv.c
676

QI did not work for me, the DMAR-related calls from the IOAPIC driver locked the system up before getting to here.

Linux doesn't seem to be reinitializing the queue on resume, they just do the disable and the __enable which resets the head/tail but does not allocate memory, which is only done by the full enable at the original boot

687

Are dmar_qi_invalidate_ctx_glob_locked and dmar_qi_invalidate_iotlb_glob_locked the right functions for this when QI is enabled?

sys/x86/iommu/intel_drv.c
676

I mean that you need to re-initialize hardware state for queue, of course you do not need to reallocate queue. But for this to work, you need to ensure that the queue is drained.

I am not sure what you get with IOAPIC and why do you claim that it deadlock the system, but it is probably just a manifestation of the ordering issue I talked about in the general comment.

687

AFAIR yes, but they require working queue.

val_packett.cool edited the summary of this revision. (Show Details)

Now calling from IOAPIC suspend/resume functions (if there's any better place "close to the nexus" I haven't found it.)

Moved setting head/tail registers into dmar_enable_qi, so now that gets called on resume.

Added waiting for the queue to empty, it's actually already empty (tail == head) both before suspend and right after resume (in the latter case, it's just not initialized, head and tail are 0).

Now hangs in dmar_qi_invalidate_ctx_glob_locked