Message ID | 20210716082755.428187-9-leobras.c@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | DDW + Indirect Mapping | expand |
Related | show |
On 16/07/2021 10:27, Leonardo Bras wrote: > Update remove_dma_window() so it can be used to remove DDW with a given > property name. > > This enables the creation of new property names for DDW, so we can > have different usage for it, like indirect mapping. > > Signed-off-by: Leonardo Bras <leobras.c@gmail.com> > Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> > --- > arch/powerpc/platforms/pseries/iommu.c | 21 +++++++++++---------- > 1 file changed, 11 insertions(+), 10 deletions(-) > > diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c > index 108c3dcca686..17c6f4706e76 100644 > --- a/arch/powerpc/platforms/pseries/iommu.c > +++ b/arch/powerpc/platforms/pseries/iommu.c > @@ -830,31 +830,32 @@ static void remove_dma_window(struct device_node *np, u32 *ddw_avail, > np, ret, ddw_avail[DDW_REMOVE_PE_DMA_WIN], liobn); > } > > -static void remove_ddw(struct device_node *np, bool remove_prop) > +static int remove_ddw(struct device_node *np, bool remove_prop, const char *win_name) > { Why switch to returning an int? None of the callers check it. Fred > struct property *win; > u32 ddw_avail[DDW_APPLICABLE_SIZE]; > int ret = 0; > > + win = of_find_property(np, win_name, NULL); > + if (!win) > + return -EINVAL; > + > ret = of_property_read_u32_array(np, "ibm,ddw-applicable", > &ddw_avail[0], DDW_APPLICABLE_SIZE); > if (ret) > - return; > - > - win = of_find_property(np, DIRECT64_PROPNAME, NULL); > - if (!win) > - return; > + return 0; > > if (win->length >= sizeof(struct dynamic_dma_window_prop)) > remove_dma_window(np, ddw_avail, win); > > if (!remove_prop) > - return; > + return 0; > > ret = of_remove_property(np, win); > if (ret) > pr_warn("%pOF: failed to remove direct window property: %d\n", > np, ret); > + return 0; > } > > static bool find_existing_ddw(struct device_node *pdn, u64 *dma_addr, int *window_shift) > @@ -907,7 +908,7 @@ static int find_existing_ddw_windows(void) > for_each_node_with_property(pdn, DIRECT64_PROPNAME) { > direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len); > if (!direct64 || len < sizeof(*direct64)) { > - remove_ddw(pdn, true); > + remove_ddw(pdn, true, DIRECT64_PROPNAME); > continue; > } > > @@ -1382,7 +1383,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) > kfree(win64); > > out_remove_win: > - remove_ddw(pdn, true); > + remove_ddw(pdn, true, DIRECT64_PROPNAME); > > out_failed: > if (default_win_removed) > @@ -1547,7 +1548,7 @@ static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long acti > * we have to remove the property when releasing > * the device node. > */ > - remove_ddw(np, false); > + remove_ddw(np, false, DIRECT64_PROPNAME); > if (pci && pci->table_group) > iommu_pseries_free_group(pci->table_group, > np->full_name); >
Hello Fred, thanks for the feedback! On Tue, 2021-07-20 at 19:51 +0200, Frederic Barrat wrote: > > > On 16/07/2021 10:27, Leonardo Bras wrote: > > Update remove_dma_window() so it can be used to remove DDW with a > > given > > property name. > > > > This enables the creation of new property names for DDW, so we can > > have different usage for it, like indirect mapping. > > > > Signed-off-by: Leonardo Bras <leobras.c@gmail.com> > > Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> > > --- > > arch/powerpc/platforms/pseries/iommu.c | 21 +++++++++++---------- > > 1 file changed, 11 insertions(+), 10 deletions(-) > > > > diff --git a/arch/powerpc/platforms/pseries/iommu.c > > b/arch/powerpc/platforms/pseries/iommu.c > > index 108c3dcca686..17c6f4706e76 100644 > > --- a/arch/powerpc/platforms/pseries/iommu.c > > +++ b/arch/powerpc/platforms/pseries/iommu.c > > @@ -830,31 +830,32 @@ static void remove_dma_window(struct > > device_node *np, u32 *ddw_avail, > > np, ret, ddw_avail[DDW_REMOVE_PE_DMA_WIN], > > liobn); > > } > > > > -static void remove_ddw(struct device_node *np, bool remove_prop) > > +static int remove_ddw(struct device_node *np, bool remove_prop, > > const char *win_name) > > { > > > Why switch to returning an int? None of the callers check it. IIRC, in a previous version it did make sense, which is not the case anymore. I will revert this. Thanks! > > Fred
On Tue, 2021-08-17 at 02:59 -0300, Leonardo Brás wrote: > Hello Fred, thanks for the feedback! > > On Tue, 2021-07-20 at 19:51 +0200, Frederic Barrat wrote: > > > > > > On 16/07/2021 10:27, Leonardo Bras wrote: > > > Update remove_dma_window() so it can be used to remove DDW with a > > > given > > > property name. > > > > > > This enables the creation of new property names for DDW, so we > > > can > > > have different usage for it, like indirect mapping. > > > > > > Signed-off-by: Leonardo Bras <leobras.c@gmail.com> > > > Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> > > > --- > > > arch/powerpc/platforms/pseries/iommu.c | 21 +++++++++++-------- > > > -- > > > 1 file changed, 11 insertions(+), 10 deletions(-) > > > > > > diff --git a/arch/powerpc/platforms/pseries/iommu.c > > > b/arch/powerpc/platforms/pseries/iommu.c > > > index 108c3dcca686..17c6f4706e76 100644 > > > --- a/arch/powerpc/platforms/pseries/iommu.c > > > +++ b/arch/powerpc/platforms/pseries/iommu.c > > > @@ -830,31 +830,32 @@ static void remove_dma_window(struct > > > device_node *np, u32 *ddw_avail, > > > np, ret, > > > ddw_avail[DDW_REMOVE_PE_DMA_WIN], > > > liobn); > > > } > > > > > > -static void remove_ddw(struct device_node *np, bool remove_prop) > > > +static int remove_ddw(struct device_node *np, bool remove_prop, > > > const char *win_name) > > > { > > > > > > Why switch to returning an int? None of the callers check it. > > IIRC, in a previous version it did make sense, which is not the case > anymore. I will revert this. > > Thanks! Oh, sorry about that, it is in fact still needed: It will make sense in patch v5 10/11: On iommu_reconfig_notifier(), if (action == OF_RECONFIG_DETACH_NODE), we need to remove a DDW if it exists. As there may be different window names, it tests for DIRECT64_PROPNAME, and if it's not found, it tests for DMA64_PROPNAME. This approach will skip scanning for DMA64_PROPNAME if DIRECT64_PROPNAME was found, as both may not exist in the same node. But for this approach to work we need remove_ddw() to return error if the property is not found. Does it make sense? or should I just test for both? Best regards, Leonardo Bras
On 17/08/2021 16:12, Leonardo Brás wrote: > On Tue, 2021-08-17 at 02:59 -0300, Leonardo Brás wrote: >> Hello Fred, thanks for the feedback! >> >> On Tue, 2021-07-20 at 19:51 +0200, Frederic Barrat wrote: >>> >>> >>> On 16/07/2021 10:27, Leonardo Bras wrote: >>>> Update remove_dma_window() so it can be used to remove DDW with a >>>> given >>>> property name. >>>> >>>> This enables the creation of new property names for DDW, so we >>>> can >>>> have different usage for it, like indirect mapping. >>>> >>>> Signed-off-by: Leonardo Bras <leobras.c@gmail.com> >>>> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> >>>> --- >>>> arch/powerpc/platforms/pseries/iommu.c | 21 +++++++++++-------- >>>> -- >>>> 1 file changed, 11 insertions(+), 10 deletions(-) >>>> >>>> diff --git a/arch/powerpc/platforms/pseries/iommu.c >>>> b/arch/powerpc/platforms/pseries/iommu.c >>>> index 108c3dcca686..17c6f4706e76 100644 >>>> --- a/arch/powerpc/platforms/pseries/iommu.c >>>> +++ b/arch/powerpc/platforms/pseries/iommu.c >>>> @@ -830,31 +830,32 @@ static void remove_dma_window(struct >>>> device_node *np, u32 *ddw_avail, >>>> np, ret, >>>> ddw_avail[DDW_REMOVE_PE_DMA_WIN], >>>> liobn); >>>> } >>>> >>>> -static void remove_ddw(struct device_node *np, bool remove_prop) >>>> +static int remove_ddw(struct device_node *np, bool remove_prop, >>>> const char *win_name) >>>> { >>> >>> >>> Why switch to returning an int? None of the callers check it. >> >> IIRC, in a previous version it did make sense, which is not the case >> anymore. I will revert this. >> >> Thanks! > > Oh, sorry about that, it is in fact still needed: Then you should have added it in 10/11. > > It will make sense in patch v5 10/11: > On iommu_reconfig_notifier(), if (action == OF_RECONFIG_DETACH_NODE), > we need to remove a DDW if it exists. > > As there may be different window names, it tests for DIRECT64_PROPNAME, > and if it's not found, it tests for DMA64_PROPNAME. > > This approach will skip scanning for DMA64_PROPNAME if > DIRECT64_PROPNAME was found, as both may not exist in the same node. > But for this approach to work we need remove_ddw() to return error if > the property is not found. > > Does it make sense? or should I just test for both? Or you could just try removing both without checking the return code, it is one extra of_find_property in very rare code path. Not worth reposting though imho. (sorry I was off last week, catching up). Thanks,
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c index 108c3dcca686..17c6f4706e76 100644 --- a/arch/powerpc/platforms/pseries/iommu.c +++ b/arch/powerpc/platforms/pseries/iommu.c @@ -830,31 +830,32 @@ static void remove_dma_window(struct device_node *np, u32 *ddw_avail, np, ret, ddw_avail[DDW_REMOVE_PE_DMA_WIN], liobn); } -static void remove_ddw(struct device_node *np, bool remove_prop) +static int remove_ddw(struct device_node *np, bool remove_prop, const char *win_name) { struct property *win; u32 ddw_avail[DDW_APPLICABLE_SIZE]; int ret = 0; + win = of_find_property(np, win_name, NULL); + if (!win) + return -EINVAL; + ret = of_property_read_u32_array(np, "ibm,ddw-applicable", &ddw_avail[0], DDW_APPLICABLE_SIZE); if (ret) - return; - - win = of_find_property(np, DIRECT64_PROPNAME, NULL); - if (!win) - return; + return 0; if (win->length >= sizeof(struct dynamic_dma_window_prop)) remove_dma_window(np, ddw_avail, win); if (!remove_prop) - return; + return 0; ret = of_remove_property(np, win); if (ret) pr_warn("%pOF: failed to remove direct window property: %d\n", np, ret); + return 0; } static bool find_existing_ddw(struct device_node *pdn, u64 *dma_addr, int *window_shift) @@ -907,7 +908,7 @@ static int find_existing_ddw_windows(void) for_each_node_with_property(pdn, DIRECT64_PROPNAME) { direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len); if (!direct64 || len < sizeof(*direct64)) { - remove_ddw(pdn, true); + remove_ddw(pdn, true, DIRECT64_PROPNAME); continue; } @@ -1382,7 +1383,7 @@ static bool enable_ddw(struct pci_dev *dev, struct device_node *pdn) kfree(win64); out_remove_win: - remove_ddw(pdn, true); + remove_ddw(pdn, true, DIRECT64_PROPNAME); out_failed: if (default_win_removed) @@ -1547,7 +1548,7 @@ static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long acti * we have to remove the property when releasing * the device node. */ - remove_ddw(np, false); + remove_ddw(np, false, DIRECT64_PROPNAME); if (pci && pci->table_group) iommu_pseries_free_group(pci->table_group, np->full_name);