On Mon, Jan 04, 2021 at 11:38:38AM -0500, Andrey Grodzovsky wrote: > Hello, I am AMD developer and I am trying to implement support for on the > fly graceful graphic card extraction. Are you talking about surprise removal (eg card on the other end of a Thunderbolt connector where there is no possibility for software locking), or are you talking about an orderly removal (where the user requests removal and there is time to tear everything down gracefully)? > One issue I am facing is how to avoid > accesses to physical addresses both in RAM and MMIO from user mode and > kernel after device is gone. For user accesses (mmap) I use the page fault > handler to route all RW accesses to dummy zero page. I would like to do the > same for kernel side mappings both form RAM (kmap) and device IO > (ioremap) but it looks like there is no same mechanism of page fault > handlers for kernel side mappings. ioremap() is done through the vmalloc space. It would, in theory, be possible to reprogram the page tables used for vmalloc to point to your magic page. I don't think we have such a mechanism today, and there are lots of problems with things like TLB flushes. It's probably going to be harder than you think. I'm adding the linux-pci mailing list so you can be helped with the logistics of device hot-remove.