Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d094a84e authored by Kees Cook's avatar Kees Cook Committed by Shiraz Hashim
Browse files

arm: fixmap: implement __set_fixmap()



This is used from set_fixmap() and clear_fixmap() via asm-generic/fixmap.h.
Also makes sure that the fixmap allocation fits into the expected range.

Based on patch by Rabin Vincent.

Change-Id: I8b62edc032cb8a6a7be67fa57e84a55805dae743
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Cc: Rabin Vincent <rabin@rab.in>
Acked-by: default avatarNicolas Pitre <nico@linaro.org>
Git-commit: 99b4ac9afce4129323b5b4c7002a942a9489914c
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git


[shashim@codeaurora.org: resolve trivial merge conflicts]
Signed-off-by: default avatarShiraz Hashim <shashim@codeaurora.org>
parent 220f229a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ enum fixed_addresses {
extern void __early_set_fixmap(enum fixed_addresses idx,
					phys_addr_t phys, pgprot_t flags);

#define __set_fixmap __early_set_fixmap
void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot);

#include <asm-generic/fixmap.h>

+24 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <asm/cputype.h>
#include <asm/sections.h>
#include <asm/cachetype.h>
#include <asm/fixmap.h>
#include <asm/sections.h>
#include <asm/setup.h>
#include <asm/smp_plat.h>
@@ -393,6 +394,29 @@ SET_MEMORY_FN(rw, pte_set_rw)
SET_MEMORY_FN(x, pte_set_x)
SET_MEMORY_FN(nx, pte_set_nx)

/*
 * To avoid TLB flush broadcasts, this uses local_flush_tlb_kernel_range().
 * As a result, this can only be called with preemption disabled, as under
 * stop_machine().
 */
void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
{
	unsigned long vaddr = __fix_to_virt(idx);
	pte_t *pte = pte_offset_kernel(pmd_off_k(vaddr), vaddr);

	/* Make sure fixmap region does not exceed available allocation. */
	BUILD_BUG_ON(FIXADDR_START + (__end_of_fixed_addresses * PAGE_SIZE) >
		     FIXADDR_END);
	BUG_ON(idx >= __end_of_fixed_addresses);

	if (pgprot_val(prot))
		set_pte_at(NULL, vaddr, pte,
			pfn_pte(phys >> PAGE_SHIFT, prot));
	else
		pte_clear(NULL, vaddr, pte);
	local_flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
}

/*
 * Adjust the PMD section entries according to the CPU in use.
 */