mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Burton <paul.burton@imgtec.com>
To: <linux-mips@linux-mips.org>, Ralf Baechle <ralf@linux-mips.org>
Cc: James Hogan <james.hogan@imgtec.com>,
	Paul Burton <paul.burton@imgtec.com>,
	Adam Buchbinder <adam.buchbinder@gmail.com>,
	"Huacai Chen" <chenhc@lemote.com>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	<linux-kernel@vger.kernel.org>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH 08/12] MIPS: mm: Don't clobber $1 on XPA TLB refill
Date: Fri, 15 Apr 2016 11:36:56 +0100	[thread overview]
Message-ID: <1460716620-13382-9-git-send-email-paul.burton@imgtec.com> (raw)
In-Reply-To: <1460716620-13382-1-git-send-email-paul.burton@imgtec.com>

From: James Hogan <james.hogan@imgtec.com>

For XPA kernels build_update_entries() uses $1 (at) as a scratch
register, but doesn't arrange for it to be preserved, so it will always
be clobbered by the TLB refill exception. Although this register
normally has a very short lifetime that doesn't cross memory accesses,
TLB refills due to instruction fetches (either on a page boundary or
after preemption) could clobber live data, and its easy to reproduce
the clobber with a little bit of assembler code.

Note that the use of a hardware page table walker will partly mask the
problem, as the TLB refill handler will not always be invoked.

This is fixed by avoiding the use of the extra scratch register. The
pte_high parts (going into the lower half of the EntryLo registers) are
loaded and manipulated separately so as to keep the PTE pointer around
for the other halves (instead of storing in the scratch register), and
the pte_low parts (going into the high half of the EntryLo registers)
are masked with 0x00ffffff using an ext instruction (instead of loading
0x00ffffff into the scratch register and AND'ing).

[paul.burton@imgtec.com:
  - Rebase atop other TLB work.
  - Use ext instead of an sll, srl sequence.
  - Use cpu_has_xpa instead of #ifdefs.
  - Modify commit subject to include "mm".]

Fixes: c5b367835cfc ("MIPS: Add support for XPA.")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
---

 arch/mips/mm/tlbex.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index ceaee32..004cd9f 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -1006,26 +1006,22 @@ static void build_update_entries(u32 **p, unsigned int tmp, unsigned int ptep)
 	if (config_enabled(CONFIG_XPA)) {
 		int pte_off_even = sizeof(pte_t) / 2;
 		int pte_off_odd = pte_off_even + sizeof(pte_t);
-		const int scratch = 1; /* Our extra working register */
-
-		uasm_i_addu(p, scratch, 0, ptep);
 
 		uasm_i_lw(p, tmp, pte_off_even, ptep); /* even pte */
 		UASM_i_ROTR(p, tmp, tmp, ilog2(_PAGE_GLOBAL));
 		UASM_i_MTC0(p, tmp, C0_ENTRYLO0);
 
-		uasm_i_lw(p, ptep, pte_off_odd, ptep); /* odd pte */
-		UASM_i_ROTR(p, ptep, ptep, ilog2(_PAGE_GLOBAL));
-		UASM_i_MTC0(p, ptep, C0_ENTRYLO1);
-
-		uasm_i_lw(p, tmp, 0, scratch);
-		uasm_i_lw(p, ptep, sizeof(pte_t), scratch);
-		uasm_i_lui(p, scratch, 0xff);
-		uasm_i_ori(p, scratch, scratch, 0xffff);
-		uasm_i_and(p, tmp, scratch, tmp);
-		uasm_i_and(p, ptep, scratch, ptep);
+		uasm_i_lw(p, tmp, 0, ptep);
+		uasm_i_ext(p, tmp, tmp, 0, 24);
 		uasm_i_mthc0(p, tmp, C0_ENTRYLO0);
-		uasm_i_mthc0(p, ptep, C0_ENTRYLO1);
+
+		uasm_i_lw(p, tmp, pte_off_odd, ptep); /* odd pte */
+		UASM_i_ROTR(p, tmp, tmp, ilog2(_PAGE_GLOBAL));
+		UASM_i_MTC0(p, tmp, C0_ENTRYLO1);
+
+		uasm_i_lw(p, tmp, sizeof(pte_t), ptep);
+		uasm_i_ext(p, tmp, tmp, 0, 24);
+		uasm_i_mthc0(p, tmp, C0_ENTRYLO1);
 		return;
 	}
 
-- 
2.8.0

  parent reply	other threads:[~2016-04-15 10:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1460716620-13382-1-git-send-email-paul.burton@imgtec.com>
2016-04-15 10:36 ` [PATCH 01/12] MIPS: Separate XPA CPU feature into LPA and MVH Paul Burton
2016-04-15 10:36 ` [PATCH 02/12] MIPS: Fix HTW config on XPA kernel without LPA enabled Paul Burton
2016-04-15 10:36 ` [PATCH 03/12] MIPS: Remove redundant asm/pgtable-bits.h inclusions Paul Burton
2016-04-15 19:16   ` James Hogan
2016-04-15 21:19     ` Paul Burton
2016-04-15 10:36 ` [PATCH 04/12] MIPS: Use enums to make asm/pgtable-bits.h readable Paul Burton
2016-04-15 20:29   ` James Hogan
2016-05-11  9:38     ` Ralf Baechle
2016-04-15 10:36 ` [PATCH 06/12] MIPS: mm: Unify pte_page definition Paul Burton
2016-04-15 23:16   ` James Hogan
2016-04-15 10:36 ` Paul Burton [this message]
2016-04-15 10:36 ` [PATCH 09/12] MIPS: mm: Pass scratch register through to iPTE_SW Paul Burton
2016-04-15 22:28   ` James Hogan
2016-04-15 10:36 ` [PATCH 10/12] MIPS: mm: Be more explicit about PTE mode bit handling Paul Burton
2016-04-15 10:36 ` [PATCH 11/12] MIPS: mm: Simplify build_update_entries Paul Burton
2016-04-15 23:09   ` James Hogan
2016-04-15 10:37 ` [PATCH 12/12] MIPS: mm: Don't do MTHC0 if XPA not present Paul Burton
2016-05-10 12:44 ` [PATCH 00/12] TLB/XPA fixes & cleanups Ralf Baechle
2016-05-10 17:47   ` Florian Fainelli
2016-05-11 10:03     ` Ralf Baechle
2016-05-11 19:17       ` 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=1460716620-13382-9-git-send-email-paul.burton@imgtec.com \
    --to=paul.burton@imgtec.com \
    --cc=adam.buchbinder@gmail.com \
    --cc=chenhc@lemote.com \
    --cc=james.hogan@imgtec.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=ralf@linux-mips.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

all inboxes | Powered by JetHome®