Skip to content

Commit 6656920

Browse files
committed
[XTENSA] Add support for cache-aliasing
Add support for processors that have cache-aliasing issues, such as the Stretch S5000 processor. Cache-aliasing means that the size of the cache (for one way) is larger than the page size, thus, a page can end up in several places in cache depending on the virtual to physical translation. The method used here is to map a user page temporarily through the auto-refill way 0 and of of the DTLB. We probably will want to revisit this issue and use a better approach with kmap/kunmap. Signed-off-by: Chris Zankel <chris@zankel.net>
1 parent ff6fd46 commit 6656920

14 files changed

Lines changed: 816 additions & 414 deletions

File tree

‎arch/xtensa/kernel/asm-offsets.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#include <linux/stddef.h>
1919
#include <linux/thread_info.h>
2020
#include <linux/ptrace.h>
21+
#include <linux/mm.h>
22+
2123
#include <asm/ptrace.h>
2224
#include <asm/processor.h>
2325
#include <asm/uaccess.h>
2426

2527
#define DEFINE(sym, val) asm volatile("\n->" #sym " %0 " #val : : "i" (val))
26-
#define BLANK() asm volatile("\n->" : : )
2728

2829
int main(void)
2930
{
@@ -63,7 +64,6 @@ int main(void)
6364
DEFINE(PT_SIZE, sizeof(struct pt_regs));
6465
DEFINE(PT_AREG_END, offsetof (struct pt_regs, areg[XCHAL_NUM_AREGS]));
6566
DEFINE(PT_USER_SIZE, offsetof(struct pt_regs, areg[XCHAL_NUM_AREGS]));
66-
BLANK();
6767

6868
/* struct task_struct */
6969
DEFINE(TASK_PTRACE, offsetof (struct task_struct, ptrace));
@@ -73,27 +73,26 @@ int main(void)
7373
DEFINE(TASK_THREAD, offsetof (struct task_struct, thread));
7474
DEFINE(TASK_THREAD_INFO, offsetof (struct task_struct, stack));
7575
DEFINE(TASK_STRUCT_SIZE, sizeof (struct task_struct));
76-
BLANK();
7776

7877
/* struct thread_info (offset from start_struct) */
7978
DEFINE(THREAD_RA, offsetof (struct task_struct, thread.ra));
8079
DEFINE(THREAD_SP, offsetof (struct task_struct, thread.sp));
8180
DEFINE(THREAD_CP_SAVE, offsetof (struct task_struct, thread.cp_save));
8281
DEFINE(THREAD_CURRENT_DS, offsetof (struct task_struct, thread.current_ds));
83-
BLANK();
8482

8583
/* struct mm_struct */
8684
DEFINE(MM_USERS, offsetof(struct mm_struct, mm_users));
8785
DEFINE(MM_PGD, offsetof (struct mm_struct, pgd));
8886
DEFINE(MM_CONTEXT, offsetof (struct mm_struct, context));
89-
BLANK();
90-
DEFINE(PT_SINGLESTEP_BIT, PT_SINGLESTEP_BIT);
87+
88+
/* struct page */
89+
DEFINE(PAGE_FLAGS, offsetof(struct page, flags));
9190

9291
/* constants */
9392
DEFINE(_CLONE_VM, CLONE_VM);
9493
DEFINE(_CLONE_UNTRACED, CLONE_UNTRACED);
94+
DEFINE(PG_ARCH_1, PG_arch_1);
9595

9696
return 0;
9797
}
9898

99-

‎arch/xtensa/kernel/entry.S‎

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License. See the file "COPYING" in the main directory of this archive
88
* for more details.
99
*
10-
* Copyright (C) 2004-2005 by Tensilica Inc.
10+
* Copyright (C) 2004-2007 by Tensilica Inc.
1111
*
1212
* Chris Zankel <chris@zankel.net>
1313
*
@@ -169,7 +169,7 @@ _user_exception:
169169
* We have to save all registers up to the first '1' from
170170
* the right, except the current frame (bit 0).
171171
* Assume a2 is: 001001000110001
172-
* All regiser frames starting from the top fiel to the marked '1'
172+
* All register frames starting from the top field to the marked '1'
173173
* must be saved.
174174
*/
175175

@@ -1590,7 +1590,7 @@ ENTRY(fast_second_level_miss)
15901590
* The messy computation for 'pteval' above really simplifies
15911591
* into the following:
15921592
*
1593-
* pteval = ((pmdval - PAGE_OFFSET) & PAGE_MASK) | PAGE_KERNEL
1593+
* pteval = ((pmdval - PAGE_OFFSET) & PAGE_MASK) | PAGE_DIRECTORY
15941594
*/
15951595

15961596
movi a1, -PAGE_OFFSET
@@ -1602,7 +1602,7 @@ ENTRY(fast_second_level_miss)
16021602
or a0, a0, a1 # ... | PAGE_DIRECTORY
16031603

16041604
/*
1605-
* We utilize all three wired-ways (7-9( to hold pmd translations.
1605+
* We utilize all three wired-ways (7-9) to hold pmd translations.
16061606
* Memory regions are mapped to the DTLBs according to bits 28 and 29.
16071607
* This allows to map the three most common regions to three different
16081608
* DTLBs:
@@ -1652,6 +1652,73 @@ ENTRY(fast_second_level_miss)
16521652
9: l32i a0, a1, TASK_ACTIVE_MM # unlikely case mm == 0
16531653
j 8b
16541654

1655+
#if (DCACHE_WAY_SIZE > PAGE_SIZE)
1656+
1657+
2: /* Special case for cache aliasing.
1658+
* We (should) only get here if a clear_user_page, copy_user_page
1659+
* or the aliased cache flush functions got preemptively interrupted
1660+
* by another task. Re-establish temporary mapping to the
1661+
* TLBTEMP_BASE areas.
1662+
*/
1663+
1664+
/* We shouldn't be in a double exception */
1665+
1666+
l32i a0, a2, PT_DEPC
1667+
bgeui a0, VALID_DOUBLE_EXCEPTION_ADDRESS, 2f
1668+
1669+
/* Make sure the exception originated in the special functions */
1670+
1671+
movi a0, __tlbtemp_mapping_start
1672+
rsr a3, EPC_1
1673+
bltu a3, a0, 2f
1674+
movi a0, __tlbtemp_mapping_end
1675+
bgeu a3, a0, 2f
1676+
1677+
/* Check if excvaddr was in one of the TLBTEMP_BASE areas. */
1678+
1679+
movi a3, TLBTEMP_BASE_1
1680+
rsr a0, EXCVADDR
1681+
bltu a0, a3, 2f
1682+
1683+
addi a1, a0, -(2 << (DCACHE_ALIAS_ORDER + PAGE_SHIFT))
1684+
bgeu a1, a3, 2f
1685+
1686+
/* Check if we have to restore an ITLB mapping. */
1687+
1688+
movi a1, __tlbtemp_mapping_itlb
1689+
rsr a3, EPC_1
1690+
sub a3, a3, a1
1691+
1692+
/* Calculate VPN */
1693+
1694+
movi a1, PAGE_MASK
1695+
and a1, a1, a0
1696+
1697+
/* Jump for ITLB entry */
1698+
1699+
bgez a3, 1f
1700+
1701+
/* We can use up to two TLBTEMP areas, one for src and one for dst. */
1702+
1703+
extui a3, a0, PAGE_SHIFT + DCACHE_ALIAS_ORDER, 1
1704+
add a1, a3, a1
1705+
1706+
/* PPN is in a6 for the first TLBTEMP area and in a7 for the second. */
1707+
1708+
mov a0, a6
1709+
movnez a0, a7, a3
1710+
j 3b
1711+
1712+
/* ITLB entry. We only use dst in a6. */
1713+
1714+
1: witlb a6, a1
1715+
isync
1716+
j 4b
1717+
1718+
1719+
#endif // DCACHE_WAY_SIZE > PAGE_SIZE
1720+
1721+
16551722
2: /* Invalid PGD, default exception handling */
16561723

16571724
movi a3, exc_table

‎arch/xtensa/mm/Makefile‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,5 @@
55
# removes any old dependencies. DON'T put your own dependencies here
66
# unless it's something special (ie not a .c file).
77
#
8-
# Note 2! The CFLAGS definition is now in the main makefile...
98

10-
obj-y := init.o fault.o tlb.o misc.o
11-
obj-m :=
12-
obj-n :=
13-
obj- :=
9+
obj-y := init.o fault.o tlb.o misc.o cache.o

0 commit comments

Comments
 (0)