Message ID | 1578415992-24054-1-git-send-email-krzk@kernel.org (mailing list archive) |
---|---|
Headers | show |
Series | iomap: Constify ioreadX() iomem argument | expand |
Le 08/01/2020 à 09:18, Krzysztof Kozlowski a écrit : > On Wed, 8 Jan 2020 at 09:13, Geert Uytterhoeven <geert@linux-m68k.org> wrote: >> >> Hi Krzysztof, >> >> On Wed, Jan 8, 2020 at 9:07 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote: >>> On Tue, Jan 7, 2020 at 5:53 PM Krzysztof Kozlowski <krzk@kernel.org> wrote: >>>> The ioread8/16/32() and others have inconsistent interface among the >>>> architectures: some taking address as const, some not. >>>> >>>> It seems there is nothing really stopping all of them to take >>>> pointer to const. >>> >>> Shouldn't all of them take const volatile __iomem pointers? >>> It seems the "volatile" is missing from all but the implementations in >>> include/asm-generic/io.h. >> >> As my "volatile" comment applies to iowrite*(), too, probably that should be >> done in a separate patch. >> >> Hence with patches 1-5 squashed, and for patches 11-13: >> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> > > I'll add to this one also changes to ioreadX_rep() and add another > patch for volatile for reads and writes. I guess your review will be > appreciated once more because of ioreadX_rep() > volatile should really only be used where deemed necessary: https://www.kernel.org/doc/html/latest/process/volatile-considered-harmful.html It is said: " ... accessor functions might use volatile on architectures where direct I/O memory access does work. Essentially, each accessor call becomes a little critical section on its own and ensures that the access happens as expected by the programmer." Christophe
Hi Christophe, On Wed, Jan 8, 2020 at 9:35 AM Christophe Leroy <christophe.leroy@c-s.fr> wrote: > Le 08/01/2020 à 09:18, Krzysztof Kozlowski a écrit : > > On Wed, 8 Jan 2020 at 09:13, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > >> On Wed, Jan 8, 2020 at 9:07 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote: > >>> On Tue, Jan 7, 2020 at 5:53 PM Krzysztof Kozlowski <krzk@kernel.org> wrote: > >>>> The ioread8/16/32() and others have inconsistent interface among the > >>>> architectures: some taking address as const, some not. > >>>> > >>>> It seems there is nothing really stopping all of them to take > >>>> pointer to const. > >>> > >>> Shouldn't all of them take const volatile __iomem pointers? > >>> It seems the "volatile" is missing from all but the implementations in > >>> include/asm-generic/io.h. > >> > >> As my "volatile" comment applies to iowrite*(), too, probably that should be > >> done in a separate patch. > >> > >> Hence with patches 1-5 squashed, and for patches 11-13: > >> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> > > > > I'll add to this one also changes to ioreadX_rep() and add another > > patch for volatile for reads and writes. I guess your review will be > > appreciated once more because of ioreadX_rep() > > volatile should really only be used where deemed necessary: > > https://www.kernel.org/doc/html/latest/process/volatile-considered-harmful.html > > It is said: " ... accessor functions might use volatile on > architectures where direct I/O memory access does work. Essentially, > each accessor call becomes a little critical section on its own and > ensures that the access happens as expected by the programmer." That is exactly the use case here: all above are accessor functions. Why would ioreadX() not need volatile, while readY() does? Gr{oetje,eeting}s, Geert
On Wed, Jan 8, 2020 at 9:36 AM Christophe Leroy <christophe.leroy@c-s.fr> wrote: > Le 08/01/2020 à 09:18, Krzysztof Kozlowski a écrit : > > On Wed, 8 Jan 2020 at 09:13, Geert Uytterhoeven <geert@linux-m68k.org> wrote: > > I'll add to this one also changes to ioreadX_rep() and add another > > patch for volatile for reads and writes. I guess your review will be > > appreciated once more because of ioreadX_rep() > > > > volatile should really only be used where deemed necessary: > > https://www.kernel.org/doc/html/latest/process/volatile-considered-harmful.html > > It is said: " ... accessor functions might use volatile on > architectures where direct I/O memory access does work. Essentially, > each accessor call becomes a little critical section on its own and > ensures that the access happens as expected by the programmer." The I/O accessors are one of the few places in which 'volatile' generally makes sense, at least for the implementations that do a plain pointer dereference (probably none of the ones in question here). In case of readl/writel, this is what we do in asm-generic: static inline u32 __raw_readl(const volatile void __iomem *addr) { return *(const volatile u32 __force *)addr; } The __force-cast that removes the __iomem here also means that the 'volatile' keyword could be dropped from the argument list, as it has no real effect any more, but then there are a few drivers that mark their iomem pointers as either 'volatile void __iomem*' or (worse) 'volatile void *', so we keep it in the argument list to not add warnings for those drivers. It may be time to change these drivers to not use volatile for __iomem pointers, but that seems out of scope for what Krzysztof is trying to do. Ideally we would be consistent here though, either using volatile all the time or never. Arnd
Hi Geert, Le 08/01/2020 à 09:43, Geert Uytterhoeven a écrit : > Hi Christophe, > > On Wed, Jan 8, 2020 at 9:35 AM Christophe Leroy <christophe.leroy@c-s.fr> wrote: >> Le 08/01/2020 à 09:18, Krzysztof Kozlowski a écrit : >>> On Wed, 8 Jan 2020 at 09:13, Geert Uytterhoeven <geert@linux-m68k.org> wrote: >>>> On Wed, Jan 8, 2020 at 9:07 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote: >>>>> On Tue, Jan 7, 2020 at 5:53 PM Krzysztof Kozlowski <krzk@kernel.org> wrote: >>>>>> The ioread8/16/32() and others have inconsistent interface among the >>>>>> architectures: some taking address as const, some not. >>>>>> >>>>>> It seems there is nothing really stopping all of them to take >>>>>> pointer to const. >>>>> >>>>> Shouldn't all of them take const volatile __iomem pointers? >>>>> It seems the "volatile" is missing from all but the implementations in >>>>> include/asm-generic/io.h. >>>> >>>> As my "volatile" comment applies to iowrite*(), too, probably that should be >>>> done in a separate patch. >>>> >>>> Hence with patches 1-5 squashed, and for patches 11-13: >>>> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> >>> >>> I'll add to this one also changes to ioreadX_rep() and add another >>> patch for volatile for reads and writes. I guess your review will be >>> appreciated once more because of ioreadX_rep() >> >> volatile should really only be used where deemed necessary: >> >> https://www.kernel.org/doc/html/latest/process/volatile-considered-harmful.html >> >> It is said: " ... accessor functions might use volatile on >> architectures where direct I/O memory access does work. Essentially, >> each accessor call becomes a little critical section on its own and >> ensures that the access happens as expected by the programmer." > > That is exactly the use case here: all above are accessor functions. > > Why would ioreadX() not need volatile, while readY() does? > My point was: it might be necessary for some arches and not for others. And as pointed by Arnd, the volatile is really only necessary for the dereference itself, should the arch use dereferencing. So I guess the best would be to go in the other direction: remove volatile keyword wherever possible instead of adding it where it is not needed. Christophe