All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Pitre <nicolas.pitre@linaro.org>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Russell King <linux@armlinux.org.uk>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>, Arnd Bergmann <arnd@arndb.de>,
	Chris Brandt <chris.brandt@renesas.com>,
	Pratyush Anand <panand@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>,
	Neeraj Upadhyay <neeraju@codeaurora.org>,
	Laura Abbott <labbott@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Jerome Marchand <jmarchan@redhat.com>,
	Konstantin Khlebnikov <koct9i@gmail.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	"moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>,
	"open list:GENERIC INCLUDE/ASM HEADER FILES" 
	<linux-arch@vger.kernel.org>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>
Subject: Re: [PATCH RFC] mm: Add debug_virt_to_phys()
Date: Sat, 12 Nov 2016 11:32:15 -0500 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.20.1611121129420.1618@knanqh.ubzr> (raw)
In-Reply-To: <55bd0bb5-c11c-12bc-7d73-520ae3901f03@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3008 bytes --]

On Fri, 11 Nov 2016, Florian Fainelli wrote:

> Le 11/11/2016 à 17:49, Nicolas Pitre a écrit :
> > On Fri, 11 Nov 2016, Florian Fainelli wrote:
> > 
> >> When CONFIG_DEBUG_VM is turned on, virt_to_phys() maps to
> >> debug_virt_to_phys() which helps catch vmalloc space addresses being
> >> passed. This is helpful in debugging bogus drivers that just assume
> >> linear mappings all over the place.
> >>
> >> For ARM, ARM64, Unicore32 and Microblaze, the architectures define
> >> __virt_to_phys() as being the functional implementation of the address
> >> translation, so we special case the debug stub to call into
> >> __virt_to_phys directly.
> >>
> >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> >> ---
> >>  arch/arm/include/asm/memory.h      |  4 ++++
> >>  arch/arm64/include/asm/memory.h    |  4 ++++
> >>  include/asm-generic/memory_model.h |  4 ++++
> >>  mm/debug.c                         | 15 +++++++++++++++
> >>  4 files changed, 27 insertions(+)
> >>
> >> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> >> index 76cbd9c674df..448dec9b8b00 100644
> >> --- a/arch/arm/include/asm/memory.h
> >> +++ b/arch/arm/include/asm/memory.h
> >> @@ -260,11 +260,15 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
> >>   * translation for translating DMA addresses.  Use the driver
> >>   * DMA support - see dma-mapping.h.
> >>   */
> >> +#ifndef CONFIG_DEBUG_VM
> >>  #define virt_to_phys virt_to_phys
> >>  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >>  {
> >>  	return __virt_to_phys((unsigned long)(x));
> >>  }
> >> +#else
> >> +#define virt_to_phys debug_virt_to_phys
> >> +#endif
> > [...]
> > 
> > Why don't you do something more like:
> > 
> >  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >  {
> > +        debug_virt_to_phys(x);
> >          return __virt_to_phys((unsigned long)(x));
> >  }
> > 
> > [...]
> > 
> > static inline void debug_virt_to_phys(const void *address)
> > {
> > #ifdef CONFIG_DEBUG_VM
> >         BUG_ON(is_vmalloc_addr(address));
> > #endif
> > }
> > 
> > ?
> 
> This is how I started doing it initially, but to get the
> is_vmalloc_addr() definition, we need to include linux/mm.h and then
> everything falls apart because of the include and dependencies chain. We
> could open code the is_vmalloc_addr() check because that's simple
> enough, but we still need VMALLOC_START and VMALLOC_END and to get there
> we need to include pgtable.h, and there are still some inclusion
> problems in doing so.
> 
> The other reason was to avoid putting the same checks in architecture
> specific code, except for those like ARM/ARM64/Unicore32/Microblaze
> where I could not find a simple way to undefined virt_to_phys and
> redefine it to debug_virt_to_phys.

You could still move the check out of line like in your patch. But the 
debug function doesn't have to be the one returning the translated 
address. This has the advantage of cutting on the amount of ifdefery.


Nicolas

WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Pitre <nicolas.pitre@linaro.org>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Russell King <linux@armlinux.org.uk>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>, Arnd Bergmann <arnd@arndb.de>,
	Chris Brandt <chris.brandt@renesas.com>,
	Pratyush Anand <panand@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>,
	Neeraj Upadhyay <neeraju@codeaurora.org>,
	Laura Abbott <labbott@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Jerome Marchand <jmarchan@redhat.com>,
	Konstantin Khlebnikov <koct9i@gmail.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	"moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>,
	open list:GENERIC
Subject: Re: [PATCH RFC] mm: Add debug_virt_to_phys()
Date: Sat, 12 Nov 2016 11:32:15 -0500 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.20.1611121129420.1618@knanqh.ubzr> (raw)
In-Reply-To: <55bd0bb5-c11c-12bc-7d73-520ae3901f03@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3008 bytes --]

On Fri, 11 Nov 2016, Florian Fainelli wrote:

> Le 11/11/2016 à 17:49, Nicolas Pitre a écrit :
> > On Fri, 11 Nov 2016, Florian Fainelli wrote:
> > 
> >> When CONFIG_DEBUG_VM is turned on, virt_to_phys() maps to
> >> debug_virt_to_phys() which helps catch vmalloc space addresses being
> >> passed. This is helpful in debugging bogus drivers that just assume
> >> linear mappings all over the place.
> >>
> >> For ARM, ARM64, Unicore32 and Microblaze, the architectures define
> >> __virt_to_phys() as being the functional implementation of the address
> >> translation, so we special case the debug stub to call into
> >> __virt_to_phys directly.
> >>
> >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> >> ---
> >>  arch/arm/include/asm/memory.h      |  4 ++++
> >>  arch/arm64/include/asm/memory.h    |  4 ++++
> >>  include/asm-generic/memory_model.h |  4 ++++
> >>  mm/debug.c                         | 15 +++++++++++++++
> >>  4 files changed, 27 insertions(+)
> >>
> >> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> >> index 76cbd9c674df..448dec9b8b00 100644
> >> --- a/arch/arm/include/asm/memory.h
> >> +++ b/arch/arm/include/asm/memory.h
> >> @@ -260,11 +260,15 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
> >>   * translation for translating DMA addresses.  Use the driver
> >>   * DMA support - see dma-mapping.h.
> >>   */
> >> +#ifndef CONFIG_DEBUG_VM
> >>  #define virt_to_phys virt_to_phys
> >>  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >>  {
> >>  	return __virt_to_phys((unsigned long)(x));
> >>  }
> >> +#else
> >> +#define virt_to_phys debug_virt_to_phys
> >> +#endif
> > [...]
> > 
> > Why don't you do something more like:
> > 
> >  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >  {
> > +        debug_virt_to_phys(x);
> >          return __virt_to_phys((unsigned long)(x));
> >  }
> > 
> > [...]
> > 
> > static inline void debug_virt_to_phys(const void *address)
> > {
> > #ifdef CONFIG_DEBUG_VM
> >         BUG_ON(is_vmalloc_addr(address));
> > #endif
> > }
> > 
> > ?
> 
> This is how I started doing it initially, but to get the
> is_vmalloc_addr() definition, we need to include linux/mm.h and then
> everything falls apart because of the include and dependencies chain. We
> could open code the is_vmalloc_addr() check because that's simple
> enough, but we still need VMALLOC_START and VMALLOC_END and to get there
> we need to include pgtable.h, and there are still some inclusion
> problems in doing so.
> 
> The other reason was to avoid putting the same checks in architecture
> specific code, except for those like ARM/ARM64/Unicore32/Microblaze
> where I could not find a simple way to undefined virt_to_phys and
> redefine it to debug_virt_to_phys.

You could still move the check out of line like in your patch. But the 
debug function doesn't have to be the one returning the translated 
address. This has the advantage of cutting on the amount of ifdefery.


Nicolas

WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Pitre <nicolas.pitre@linaro.org>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Russell King <linux@armlinux.org.uk>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>, Arnd Bergmann <arnd@arndb.de>,
	Chris Brandt <chris.brandt@renesas.com>,
	Pratyush Anand <panand@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Mark Rutland <mark.rutland@arm.com>,
	James Morse <james.morse@arm.com>,
	Neeraj Upadhyay <neeraju@codeaurora.org>,
	Laura Abbott <labbott@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Jerome Marchand <jmarchan@redhat.com>,
	Konstantin Khlebnikov <koct9i@gmail.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	"moderated list:ARM PORT" <linux-arm-kernel@lists.infradead.org>,
	"open list:GENERIC INCLUDE/ASM HEADER FILES"
	<linux-arch@vger.kernel.org>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>
Subject: Re: [PATCH RFC] mm: Add debug_virt_to_phys()
Date: Sat, 12 Nov 2016 11:32:15 -0500 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.20.1611121129420.1618@knanqh.ubzr> (raw)
In-Reply-To: <55bd0bb5-c11c-12bc-7d73-520ae3901f03@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3008 bytes --]

On Fri, 11 Nov 2016, Florian Fainelli wrote:

> Le 11/11/2016 a 17:49, Nicolas Pitre a ecrit :
> > On Fri, 11 Nov 2016, Florian Fainelli wrote:
> > 
> >> When CONFIG_DEBUG_VM is turned on, virt_to_phys() maps to
> >> debug_virt_to_phys() which helps catch vmalloc space addresses being
> >> passed. This is helpful in debugging bogus drivers that just assume
> >> linear mappings all over the place.
> >>
> >> For ARM, ARM64, Unicore32 and Microblaze, the architectures define
> >> __virt_to_phys() as being the functional implementation of the address
> >> translation, so we special case the debug stub to call into
> >> __virt_to_phys directly.
> >>
> >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> >> ---
> >>  arch/arm/include/asm/memory.h      |  4 ++++
> >>  arch/arm64/include/asm/memory.h    |  4 ++++
> >>  include/asm-generic/memory_model.h |  4 ++++
> >>  mm/debug.c                         | 15 +++++++++++++++
> >>  4 files changed, 27 insertions(+)
> >>
> >> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> >> index 76cbd9c674df..448dec9b8b00 100644
> >> --- a/arch/arm/include/asm/memory.h
> >> +++ b/arch/arm/include/asm/memory.h
> >> @@ -260,11 +260,15 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
> >>   * translation for translating DMA addresses.  Use the driver
> >>   * DMA support - see dma-mapping.h.
> >>   */
> >> +#ifndef CONFIG_DEBUG_VM
> >>  #define virt_to_phys virt_to_phys
> >>  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >>  {
> >>  	return __virt_to_phys((unsigned long)(x));
> >>  }
> >> +#else
> >> +#define virt_to_phys debug_virt_to_phys
> >> +#endif
> > [...]
> > 
> > Why don't you do something more like:
> > 
> >  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >  {
> > +        debug_virt_to_phys(x);
> >          return __virt_to_phys((unsigned long)(x));
> >  }
> > 
> > [...]
> > 
> > static inline void debug_virt_to_phys(const void *address)
> > {
> > #ifdef CONFIG_DEBUG_VM
> >         BUG_ON(is_vmalloc_addr(address));
> > #endif
> > }
> > 
> > ?
> 
> This is how I started doing it initially, but to get the
> is_vmalloc_addr() definition, we need to include linux/mm.h and then
> everything falls apart because of the include and dependencies chain. We
> could open code the is_vmalloc_addr() check because that's simple
> enough, but we still need VMALLOC_START and VMALLOC_END and to get there
> we need to include pgtable.h, and there are still some inclusion
> problems in doing so.
> 
> The other reason was to avoid putting the same checks in architecture
> specific code, except for those like ARM/ARM64/Unicore32/Microblaze
> where I could not find a simple way to undefined virt_to_phys and
> redefine it to debug_virt_to_phys.

You could still move the check out of line like in your patch. But the 
debug function doesn't have to be the one returning the translated 
address. This has the advantage of cutting on the amount of ifdefery.


Nicolas

WARNING: multiple messages have this Message-ID (diff)
From: nicolas.pitre@linaro.org (Nicolas Pitre)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH RFC] mm: Add debug_virt_to_phys()
Date: Sat, 12 Nov 2016 11:32:15 -0500 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.20.1611121129420.1618@knanqh.ubzr> (raw)
In-Reply-To: <55bd0bb5-c11c-12bc-7d73-520ae3901f03@gmail.com>

On Fri, 11 Nov 2016, Florian Fainelli wrote:

> Le 11/11/2016 ? 17:49, Nicolas Pitre a ?crit :
> > On Fri, 11 Nov 2016, Florian Fainelli wrote:
> > 
> >> When CONFIG_DEBUG_VM is turned on, virt_to_phys() maps to
> >> debug_virt_to_phys() which helps catch vmalloc space addresses being
> >> passed. This is helpful in debugging bogus drivers that just assume
> >> linear mappings all over the place.
> >>
> >> For ARM, ARM64, Unicore32 and Microblaze, the architectures define
> >> __virt_to_phys() as being the functional implementation of the address
> >> translation, so we special case the debug stub to call into
> >> __virt_to_phys directly.
> >>
> >> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> >> ---
> >>  arch/arm/include/asm/memory.h      |  4 ++++
> >>  arch/arm64/include/asm/memory.h    |  4 ++++
> >>  include/asm-generic/memory_model.h |  4 ++++
> >>  mm/debug.c                         | 15 +++++++++++++++
> >>  4 files changed, 27 insertions(+)
> >>
> >> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
> >> index 76cbd9c674df..448dec9b8b00 100644
> >> --- a/arch/arm/include/asm/memory.h
> >> +++ b/arch/arm/include/asm/memory.h
> >> @@ -260,11 +260,15 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
> >>   * translation for translating DMA addresses.  Use the driver
> >>   * DMA support - see dma-mapping.h.
> >>   */
> >> +#ifndef CONFIG_DEBUG_VM
> >>  #define virt_to_phys virt_to_phys
> >>  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >>  {
> >>  	return __virt_to_phys((unsigned long)(x));
> >>  }
> >> +#else
> >> +#define virt_to_phys debug_virt_to_phys
> >> +#endif
> > [...]
> > 
> > Why don't you do something more like:
> > 
> >  static inline phys_addr_t virt_to_phys(const volatile void *x)
> >  {
> > +        debug_virt_to_phys(x);
> >          return __virt_to_phys((unsigned long)(x));
> >  }
> > 
> > [...]
> > 
> > static inline void debug_virt_to_phys(const void *address)
> > {
> > #ifdef CONFIG_DEBUG_VM
> >         BUG_ON(is_vmalloc_addr(address));
> > #endif
> > }
> > 
> > ?
> 
> This is how I started doing it initially, but to get the
> is_vmalloc_addr() definition, we need to include linux/mm.h and then
> everything falls apart because of the include and dependencies chain. We
> could open code the is_vmalloc_addr() check because that's simple
> enough, but we still need VMALLOC_START and VMALLOC_END and to get there
> we need to include pgtable.h, and there are still some inclusion
> problems in doing so.
> 
> The other reason was to avoid putting the same checks in architecture
> specific code, except for those like ARM/ARM64/Unicore32/Microblaze
> where I could not find a simple way to undefined virt_to_phys and
> redefine it to debug_virt_to_phys.

You could still move the check out of line like in your patch. But the 
debug function doesn't have to be the one returning the translated 
address. This has the advantage of cutting on the amount of ifdefery.


Nicolas

  reply	other threads:[~2016-11-12 16:32 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-12  0:44 [PATCH RFC] mm: Add debug_virt_to_phys() Florian Fainelli
2016-11-12  0:44 ` Florian Fainelli
2016-11-12  0:44 ` Florian Fainelli
2016-11-12  0:44 ` Florian Fainelli
2016-11-12  0:44 ` Florian Fainelli
2016-11-12  1:49 ` Nicolas Pitre
2016-11-12  1:49   ` Nicolas Pitre
2016-11-12  1:49   ` Nicolas Pitre
2016-11-12  1:49   ` Nicolas Pitre
2016-11-12  1:49   ` Nicolas Pitre
2016-11-12  3:39   ` Florian Fainelli
2016-11-12  3:39     ` Florian Fainelli
2016-11-12  3:39     ` Florian Fainelli
2016-11-12  3:39     ` Florian Fainelli
2016-11-12  3:39     ` Florian Fainelli
2016-11-12 16:32     ` Nicolas Pitre [this message]
2016-11-12 16:32       ` Nicolas Pitre
2016-11-12 16:32       ` Nicolas Pitre
2016-11-12 16:32       ` Nicolas Pitre
2016-11-12 16:32       ` Nicolas Pitre
2016-11-12  5:43 ` Will Deacon
2016-11-12  5:43   ` Will Deacon
2016-11-12  5:43   ` Will Deacon
2016-11-12  5:43   ` Will Deacon
2016-11-12  5:43   ` Will Deacon
2016-11-12 19:29   ` Florian Fainelli
2016-11-12 19:29     ` Florian Fainelli
2016-11-12 19:29     ` Florian Fainelli
2016-11-12 19:29     ` Florian Fainelli
2016-11-12 19:29     ` Florian Fainelli
2016-11-14 18:45 ` Laura Abbott
2016-11-14 18:45   ` Laura Abbott
2016-11-14 18:45   ` Laura Abbott
2016-11-14 18:45   ` Laura Abbott
2016-11-14 18:45   ` Laura Abbott
2016-11-14 19:23   ` Florian Fainelli
2016-11-14 19:23     ` Florian Fainelli
2016-11-14 19:23     ` Florian Fainelli
2016-11-14 19:23     ` Florian Fainelli
2016-11-14 19:23     ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.20.1611121129420.1618@knanqh.ubzr \
    --to=nicolas.pitre@linaro.org \
    --cc=akpm@linux-foundation.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=chris.brandt@renesas.com \
    --cc=f.fainelli@gmail.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=james.morse@arm.com \
    --cc=jmarchan@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=koct9i@gmail.com \
    --cc=labbott@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@armlinux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=mhocko@suse.com \
    --cc=neeraju@codeaurora.org \
    --cc=panand@redhat.com \
    --cc=vbabka@suse.cz \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.