Hi, On 4/4/22 21:56, Sathyanarayanan Kuppuswamy wrote: > Hi Hans, > > On 4/4/22 3:07 AM, Hans de Goede wrote: >>> +static int __init tdx_attest_init(void) >>> +{ >>> + dma_addr_t handle; >>> + long ret = 0; >>> + >>> + mutex_lock(&attestation_lock); >>> + >>> + ret = misc_register(&tdx_attest_device); >>> + if (ret) { >>> + pr_err("misc device registration failed\n"); >>> + mutex_unlock(&attestation_lock); >>> + return ret; >>> + } >> Why not do this as the last thing of the probe? > > We need misc device reference in dma_alloc_coherent() and > dma_set_coherent_mask() calls. This is the reason for keeping > misc_register() at the beginining of the init function. Erm, you are supposed to pass an actual device-device as parameter to dma_alloc_coherent(), so that it can see what bus/dma-domain the device is connected to and if an ioMMU might be involved... >> That will avoid the need to unregister this again in all >> the error-exit paths and also fixes a possible deadlock. >> > > Agree. But, unless we create another device locally, I don't > think we can avoid this. Do you prefer this approach? Yes, passing the "struct device" which is embedded inside a miscdevice as device to dma_alloc_coherent() is just wrong. Please make your module_init function register a platform_device using platform_device_register_simple() (on systems with TDX support) and then turn your code/driver into a standard platform_driver using the platform_device which the driver binds to as parameter to dma_alloc_coherent(). See: https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/commit/?id=c4d2ff35d350428eca2ae1a1e2119e4c6297811d for a simple (completely unrelated) driver which uses this method to have a device to bind to for talking to a secondary function of the embedded-controller on some platforms. Regards, Hans