On Wed, Apr 24, 2024 at 04:01:04PM -0700, Tomasz Jeznach wrote: > > > + /* Update existing or allocate new entries in device directory */ > > > + for (i = 0; i < fwspec->num_ids; i++) { > > > + dc = riscv_iommu_get_dc(iommu, fwspec->ids[i], !iommu_domain); > > > + if (!dc && !iommu_domain) > > > + continue; > > > + if (!dc) > > > + return -ENODEV; > > > > But if this fails some of the fwspecs were left in a weird state ? > > > > Drivers should try hard to have attach functions that fail and make no > > change at all or fully succeed. > > > > Meaning ideally preallocate any required memory before doing any > > change to the HW visable structures. > > Good point. Done. > Looking at the fwspec->ids[] I'm assuming nobody will add/modify the > IDs after iommu_probe_device() completes. Yes > > > + /* Swap device context, update TC valid bit as the last operation */ > > > + xchg64(&dc->fsc, fsc); > > > + xchg64(&dc->ta, ta); > > > + xchg64(&dc->tc, tc); > > > > This doesn't loook right? When you get to adding PAGING suport fsc has > > the page table pfn and ta has the cache tag, so this will end up > > tearing the data for sure, eg when asked to replace a PAGING domain > > with another PAGING domain? That will create a functional/security > > problem, right? > > > > I would encourage you to re-use the ARM sequencing code, ideally moved > > to some generic helper library. Every iommu driver dealing with > > multi-quanta descriptors seems to have this same fundamental > > sequencing problem. > > > > Good point. Reworked. I suppose by force clearing the v bit before starting the sequence? That is OK but won't support some non-embedded focused features in the long run. It is a good approach to get the driver landed though. > > The release_domain has landed too now. Please don't invent weird NULL > > domain types that have special meaning. I assume clearing the V bit is > > a blocking behavior? So please implement a proper blocking domain and > > set release_domain = &riscv_iommu_blocking and just omit this release > > function. > > > > Updated to use release_domain, should be cleaner now. > Clearing TC.V is a blocking (but noisy) behavior, should be fine for > release domain where devices should be quiesced already. blocking is fine to be noisy. Jason