linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: gmbnomis@gmail.com (Simon Baatz)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 0/2] fix and improvement of flush(_kernel)_dcache_page()
Date: Wed, 26 Sep 2012 23:40:57 +0200	[thread overview]
Message-ID: <1348695659-27603-1-git-send-email-gmbnomis@gmail.com> (raw)

Hi,

another attempt to fix the regression caused by patch f8b63c1 "ARM:
6382/1" in 2.6.37 (see [2]).  The problem occurs on VIVT (and
probably VIPT aliasing) cache architectures for drivers that use
flush_kernel_dcache_page().  For example, 3.6-rc6 (as any kernel
beginning with 2.6.37) on kirkwood using mv_cesa produces data
corruption when using direct I/O:

~# cryptsetup luksOpen /dev/sda2 c_sda2
Enter passphrase for /dev/sda2: 
~# dd if=/dev/mapper/c_sda2 iflag=direct bs=4k count=16 2>/dev/null | sha1sum 
9ae4997ec85ad9b7ab4b10341e42ace80f0ea5d6  -
~# dd if=/dev/mapper/c_sda2 bs=4k count=16 2>/dev/null | sha1sum
ca39c5d4950b3704eff952c48e383bf1db20532e  -

(The mv_cesa driver uses the scatterlist memory iterator, which uses
flush_kernel_dcache_page() before kunmap()).

As described in [1], both flush_dcache_page() and
flush_kernel_dcache_page() need to handle the following cases:
- page cache pages with no user space mapping
- page cache pages with user space mapping(s)
- flush the kernel mapping of anonymous pages

The last one is contradictory to documentation for flush_dcache_page(),
but many uses in the kernel require it (drivers use it to flush
modifications via the kernel mapping).

In the proposed patch the implementation of flush_kernel_dcache_page()
follows the one of flush_dcache_page(), but only flushes the kernel
mapping, not the user mapping(s).

The second patch optimizes these two functions for non-aliasing VIPT
caches.  On these the flush of the kernel mapping for the anon case is
actually not needed.  It may be needed to ensure I/D coherency, but
this can be handled by __sync_icache_dcache() later and more
effectively (similar to arm64, see [3]).  Thus, we should be lazy as
well here and just clear the PG_dcache_clean bit.

I could only test this on kirkwood (ARMv5, VIVT) and raspberry pi
BCM2835 (ARMv6, PIPT / VIPT nonaliasing data cache).  More testing
would probably be a good thing...  Especially, I could not test the
non-aliasing cache case with a real driver using
flush_kernel_dcache_page() (mv_cesa on dove could be a test case for
this).

- Simon

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2012-August/113908.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2012-May/101795.html
[3] https://lkml.org/lkml/2012/9/12/121

Simon Baatz (2):
  ARM: Handle user space mapped pages in flush_kernel_dcache_page
  ARM: remove unnecessary flush of anon pages in
    flush(_kernel)_dcache_page()

 arch/arm/include/asm/cacheflush.h |    4 ++
 arch/arm/mm/flush.c               |   83 +++++++++++++++++++++++++++++--------
 2 files changed, 70 insertions(+), 17 deletions(-)

-- 
1.7.9.5

             reply	other threads:[~2012-09-26 21:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-26 21:40 Simon Baatz [this message]
2012-09-26 21:40 ` [PATCH V2 1/2] ARM: Handle user space mapped pages in flush_kernel_dcache_page Simon Baatz
2012-09-26 21:40 ` [PATCH 2/2] ARM: remove unnecessary flush of anon pages in flush(_kernel)_dcache_page() Simon Baatz
2012-09-27 12:23   ` Catalin Marinas
2012-09-27 17:35     ` Simon Baatz

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=1348695659-27603-1-git-send-email-gmbnomis@gmail.com \
    --to=gmbnomis@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.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).