From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: "Luis R. Rodriguez" <mcgrof@suse.com>
Cc: Christoph Hellwig <hch@lst.de>,
	Andy Lutomirski <luto@amacapital.net>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Julia Lawall <julia.lawall@lip6.fr>,
	Dan Williams <dan.j.williams@intel.com>,
	Arnd Bergmann <arnd@arndb.de>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ross Zwisler <ross.zwisler@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Juergen Gross <jgross@suse.com>, X86 ML <x86@kernel.org>,
	"Kani, Toshimitsu" <toshi.kani@hp.com>,
	"linux-nvdimm@lists.01.org" <linux-nvdimm@ml01.01.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Stefan Bader <stefan.bader@canonical.com>,
	Linux MM <linux-mm@kvack.org>, Ralf Baechle <ralf@linux-mips.org>,
	Henrique de Moraes Holschuh <hmh@hmh.eng.br>,
	Michael Ellerman <mpe@ellerman.id.au>, Tejun Heo <tj@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	mcgrof@do-not-panic.com,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v5 2/6] arch: unify ioremap prototypes and macro aliases
Date: Tue, 7 Jul 2015 11:13:30 +0100	[thread overview]
Message-ID: <20150707101330.GJ7557@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20150707095012.GQ7021@wotan.suse.de>
On Tue, Jul 07, 2015 at 11:50:12AM +0200, Luis R. Rodriguez wrote:
> mcgrof@ergon ~/linux-next (git::kill-mtrr)$ git grep ioremap_nocache drivers/| wc -l
> 359
Yes, it's because we have:
(a) LDD telling people they should be using ioremap_nocache() for mapping
    devices.
(b) We have documentation in the Documentation/ subdirectory telling people
    to use ioremap_nocache() for the same.
> This is part of the work I've been doing lately. The
> eventual goal once we have the write-combing areas properly split with
> ioremap_wc() and using the new proper preferred architecture agnostic modifier
> (arch_phys_wc_add()) is to change the default ioremap behaviour on x86 to use
> strong UC for PAT enabled systems for *both* ioremap() and ioremap_nocache().
Please note that on ARM, ioremap_wc() gives what's termed in ARM ARM
speak "normal memory, non-cacheable" - which can be subject to speculation,
write combining, multiple accesses, etc.  The important point is that
such mapping is not suitable for device registers, but is suitable for
device regions that have "memory like" properties (iow, a chunk of RAM,
like video drivers.)  It does support unaligned accesses.
> Because of these grammatical issues and the issues with
> unaligned access with ARM I think its important we put some effort
> to care a bit more about defining clear semantics through grammar
> for new APIs or as we rewrite APIs. We have tools to do this these
> days, best make use of them.
I'm in support of anything which more clearly specifies the requirements
for these APIs.
> While we're at it and reconsidering all this, a few items I wish for
> us to address as well then, most of them related to grammar, some
> procedural clarification:
> 
>   * Document it as not supported to have overlapping ioremap() calls.
>     No one seems to have a clue if this should work, but clearly this
>     is just a bad idea. I don't see why we should support the complexity
>     of having this. It seems we can write grammar rules to prevent this.
On ARM, we (probably) have a lot of cases where ioremap() is used multiple
times for the same physical address space, so we shouldn't rule out having
multiple mappings of the same type.  However, differing types would be a
problem on ARM.
>   * We seem to care about device drivers / kernel code doing unaligned
>     accesses with certain ioremap() variants. At least for ARM you should
>     not do unaligned accesses on ioremap_nocache() areas.
... and ioremap() areas.
If we can stop the "abuse" of ioremap_nocache() to map device registers,
then we could potentially switch ioremap_nocache() to be a normal-memory
like mapping, which would allow it to support unaligned accesses.
>     I am not sure
>     if we can come up with grammar to vet for / warn for unaligned access
>     type of code in driver code on some memory area when some ioremap()
>     variant is used, but this could be looked into. I believe we may
>     want rules for unaligned access maybe in general, and not attached
>     to certain calls due to performance considerations, so this work
>     may be welcomed regardless (refer to
>     Documentation/unaligned-memory-access.txt)
>     
>   * We seem to want to be pedantic about adding new ioremap() variants, the
>     unaligned issue on ARM is one reason, do we ideally then want *all*
>     architecture maintainers to provide an Acked-by for any new ioremap
>     variants ?
/If/ we get the current mess sorted out so that we have a safe fallback,
and we have understanding of the different architecture variants (iow,
documented what the safe fallback is) I don't see any reason why we'd
need acks from arch maintainers.  Unfortunately, we're not in that
situation today, because of the poorly documented mess that ioremap*()
currently is (and yes, I'm partly to blame for that too by not documenting
ARMs behaviour here.)
I have some patches (prepared last week, I was going to push them out
towards the end of the merge window) which address that, but unfortunately
the ARM autobuilders have been giving a number of seemingly random boot
failures, and I'm not yet sure what's going on... so I'm holding that
back until stuff has settled down.
Another issue is... the use of memcpy()/memset() directly on memory
returned from ioremap*().  The pmem driver does this.  This fails sparse
checks.  However, years ago, x86 invented the memcpy_fromio()/memcpy_toio()
memset_io() functions, which took a __iomem pointer (which /presumably/
means they're supposed to operate on the memory associated with an
ioremap'd region.)
Should these functions always be used for mappings via ioremap*(), and
the standard memcpy()/memset() be avoided?  To me, that sounds like a
very good thing, because that gives us more control over the
implementation of the functions used to access ioremap'd regions,
and the arch can decide to prevent GCC inlining its own memset() or
memcpy() code if desired.
Note that on x86, these three functions are merely wrappers around
standard memcpy()/memset(), so there should be no reason why pmem.c
couldn't be updated to use these accessors instead.
-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply	other threads:[~2015-07-07 10:14 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-22  8:24 [PATCH v5 0/6] pmem api, generic ioremap_cache, and memremap Dan Williams
2015-06-22  8:24 ` [PATCH v5 1/6] arch, drivers: don't include <asm/io.h> directly, use <linux/io.h> instead Dan Williams
2015-06-22 16:01   ` Christoph Hellwig
2015-06-22  8:24 ` [PATCH v5 2/6] arch: unify ioremap prototypes and macro aliases Dan Williams
2015-06-22 16:10   ` Christoph Hellwig
2015-06-22 17:12     ` Dan Williams
2015-06-23 10:07       ` Christoph Hellwig
2015-06-23 15:04         ` Dan Williams
2015-06-24 12:24           ` Christoph Hellwig
2015-06-30 22:57     ` Dan Williams
2015-07-01  6:23       ` Christoph Hellwig
2015-07-01  6:55         ` Geert Uytterhoeven
2015-07-01  6:59           ` Christoph Hellwig
2015-07-01  7:19             ` Geert Uytterhoeven
2015-07-01  7:28               ` Christoph Hellwig
2015-07-07  9:50                 ` Luis R. Rodriguez
2015-07-07 10:13                   ` Russell King - ARM Linux [this message]
2015-07-07 10:27                     ` Geert Uytterhoeven
2015-07-07 16:07                     ` Luis R. Rodriguez
2015-07-07 23:10                       ` Toshi Kani
2015-07-09  1:40                         ` Luis R. Rodriguez
2015-07-09 23:43                           ` Toshi Kani
2015-07-01  8:09           ` Russell King - ARM Linux
2015-07-01 16:47             ` Dan Williams
2015-07-09 18:54   ` Luis R. Rodriguez
2015-06-22  8:24 ` [PATCH v5 3/6] cleanup IORESOURCE_CACHEABLE vs ioremap() Dan Williams
2015-06-22  8:24 ` [PATCH v5 4/6] devm: fix ioremap_cache() usage Dan Williams
2015-06-22  8:24 ` [PATCH v5 5/6] arch: introduce memremap_cache() and memremap_wt() Dan Williams
2015-06-22  8:24 ` [PATCH v5 6/6] arch, x86: pmem api for ensuring durability of persistent memory updates Dan Williams
2015-06-22 16:17   ` Christoph Hellwig
2015-06-22 17:51     ` Dan Williams
2015-06-23 10:09       ` Christoph Hellwig
2015-06-23 10:39     ` Richard Weinberger
2015-06-24 12:08       ` Christoph Hellwig
2015-06-24 12:35         ` Richard Weinberger
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=20150707101330.GJ7557@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=bp@alien8.de \
    --cc=dan.j.williams@intel.com \
    --cc=geert@linux-m68k.org \
    --cc=hch@lst.de \
    --cc=hmh@hmh.eng.br \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=julia.lawall@lip6.fr \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nvdimm@ml01.01.org \
    --cc=luto@amacapital.net \
    --cc=mcgrof@do-not-panic.com \
    --cc=mcgrof@suse.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=ralf@linux-mips.org \
    --cc=ross.zwisler@linux.intel.com \
    --cc=stefan.bader@canonical.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=toshi.kani@hp.com \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).