Skip to content

Commit 0f02cfb

Browse files
committed
MIPS: VDSO: Match data page cache colouring when D$ aliases
When a system suffers from dcache aliasing a user program may observe stale VDSO data from an aliased cache line. Notably this can break the expectation that clock_gettime(CLOCK_MONOTONIC, ...) is, as its name suggests, monotonic. In order to ensure that users observe updates to the VDSO data page as intended, align the user mappings of the VDSO data page such that their cache colouring matches that of the virtual address range which the kernel will use to update the data page - typically its unmapped address within kseg0. This ensures that we don't introduce aliasing cache lines for the VDSO data page, and therefore that userland will observe updates without requiring cache invalidation. Signed-off-by: Paul Burton <paul.burton@mips.com> Reported-by: Hauke Mehrtens <hauke@hauke-m.de> Reported-by: Rene Nielsen <rene.nielsen@microsemi.com> Reported-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Fixes: ebb5e78 ("MIPS: Initial implementation of a VDSO") Patchwork: https://patchwork.linux-mips.org/patch/20344/ Tested-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Tested-by: Hauke Mehrtens <hauke@hauke-m.de> Cc: James Hogan <jhogan@kernel.org> Cc: linux-mips@linux-mips.org Cc: stable@vger.kernel.org # v4.4+
1 parent 5b394b2 commit 0f02cfb

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎arch/mips/kernel/vdso.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
#include <linux/err.h>
1414
#include <linux/init.h>
1515
#include <linux/ioport.h>
16+
#include <linux/kernel.h>
1617
#include <linux/mm.h>
1718
#include <linux/sched.h>
1819
#include <linux/slab.h>
1920
#include <linux/timekeeper_internal.h>
2021

2122
#include <asm/abi.h>
2223
#include <asm/mips-cps.h>
24+
#include <asm/page.h>
2325
#include <asm/vdso.h>
2426

2527
/* Kernel-provided data used by the VDSO. */
@@ -128,12 +130,30 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
128130
vvar_size = gic_size + PAGE_SIZE;
129131
size = vvar_size + image->size;
130132

133+
/*
134+
* Find a region that's large enough for us to perform the
135+
* colour-matching alignment below.
136+
*/
137+
if (cpu_has_dc_aliases)
138+
size += shm_align_mask + 1;
139+
131140
base = get_unmapped_area(NULL, 0, size, 0, 0);
132141
if (IS_ERR_VALUE(base)) {
133142
ret = base;
134143
goto out;
135144
}
136145

146+
/*
147+
* If we suffer from dcache aliasing, ensure that the VDSO data page
148+
* mapping is coloured the same as the kernel's mapping of that memory.
149+
* This ensures that when the kernel updates the VDSO data userland
150+
* will observe it without requiring cache invalidations.
151+
*/
152+
if (cpu_has_dc_aliases) {
153+
base = __ALIGN_MASK(base, shm_align_mask);
154+
base += ((unsigned long)&vdso_data - gic_size) & shm_align_mask;
155+
}
156+
137157
data_addr = base + gic_size;
138158
vdso_addr = data_addr + PAGE_SIZE;
139159

0 commit comments

Comments
 (0)