RE: [PATCH v2 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group
> From: Nicolin Chen > Sent: Thursday, June 16, 2022 8:03 AM > > Cases like VFIO wish to attach a device to an existing domain that was > not allocated specifically from the device. This raises a condition > where the IOMMU driver can fail the domain attach because the domain and > device are incompatible with each other. > > This is a soft failure that can be resolved by using a different domain. > > Provide a dedicated errno from the IOMMU driver during attach that the > reason attached failed is because of domain incompatability. EMEDIUMTYPE > is chosen because it is never used within the iommu subsystem today and > evokes a sense that the 'medium' aka the domain is incompatible. > > VFIO can use this to know attach is a soft failure and it should continue > searching. Otherwise the attach will be a hard failure and VFIO will > return the code to userspace. > > Update all drivers to return EMEDIUMTYPE in their failure paths that are > related to domain incompatability. Also turn adjacent error prints into > debug prints, for these soft failures, to prevent a kernel log spam. > > Add kdocs describing this behavior. > > Suggested-by: Jason Gunthorpe > Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group
On Thu, Jun 16, 2022 at 10:09:49AM +0800, Baolu Lu wrote: > External email: Use caution opening links or attachments > > > On 2022/6/16 08:03, Nicolin Chen wrote: > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > > index 44016594831d..0dd13330fe12 100644 > > --- a/drivers/iommu/intel/iommu.c > > +++ b/drivers/iommu/intel/iommu.c > > @@ -4323,7 +4323,7 @@ static int prepare_domain_attach_device(struct > > iommu_domain *domain, > > return -ENODEV; > > > > if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) > > - return -EOPNOTSUPP; > > + return -EMEDIUMTYPE; > > > > /* check if this iommu agaw is sufficient for max mapped address */ > > addr_width = agaw_to_width(iommu->agaw); > > @@ -4331,10 +4331,10 @@ static int prepare_domain_attach_device(struct > > iommu_domain *domain, > > addr_width = cap_mgaw(iommu->cap); > > > > if (dmar_domain->max_addr > (1LL << addr_width)) { > > - dev_err(dev, "%s: iommu width (%d) is not " > > + dev_dbg(dev, "%s: iommu width (%d) is not " > > "sufficient for the mapped address (%llx)\n", > > __func__, addr_width, dmar_domain->max_addr); > > - return -EFAULT; > > + return -EMEDIUMTYPE; > > } > > dmar_domain->gaw = addr_width; > > Can we simply remove the dev_err()? As the return value has explicitly > explained the failure reason, putting a print statement won't help much. Yes. As long as no one has objection, I can remove that in the next version. ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group
On 2022/6/16 08:03, Nicolin Chen wrote: diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 44016594831d..0dd13330fe12 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4323,7 +4323,7 @@ static int prepare_domain_attach_device(struct iommu_domain *domain, return -ENODEV; if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) - return -EOPNOTSUPP; + return -EMEDIUMTYPE; /* check if this iommu agaw is sufficient for max mapped address */ addr_width = agaw_to_width(iommu->agaw); @@ -4331,10 +4331,10 @@ static int prepare_domain_attach_device(struct iommu_domain *domain, addr_width = cap_mgaw(iommu->cap); if (dmar_domain->max_addr > (1LL << addr_width)) { - dev_err(dev, "%s: iommu width (%d) is not " + dev_dbg(dev, "%s: iommu width (%d) is not " "sufficient for the mapped address (%llx)\n", __func__, addr_width, dmar_domain->max_addr); - return -EFAULT; + return -EMEDIUMTYPE; } dmar_domain->gaw = addr_width; Can we simply remove the dev_err()? As the return value has explicitly explained the failure reason, putting a print statement won't help much. Best regards, baolu ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu