__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
 *
 * vineetg: May 2011
 *  -Refactored get_new_mmu_context( ) to only handle live-mm.
 *   retiring-mm handled in other hooks
 *
 * Vineetg: March 25th, 2008: Bug #92690
 *  -Major rewrite of Core ASID allocation routine get_new_mmu_context
 *
 * Amit Bhor, Sameer Dhavale: Codito Technologies 2004
 */

#ifndef _ASM_ARC_MMU_CONTEXT_H
#define _ASM_ARC_MMU_CONTEXT_H

#include <linux/sched/mm.h>

#include <asm/tlb.h>
#include <asm-generic/mm_hooks.h>

/*		ARC ASID Management
 *
 * MMU tags TLBs with an 8-bit ASID, avoiding need to flush the TLB on
 * context-switch.
 *
 * ASID is managed per cpu, so task threads across CPUs can have different
 * ASID. Global ASID management is needed if hardware supports TLB shootdown
 * and/or shared TLB across cores, which ARC doesn't.
 *
 * Each task is assigned unique ASID, with a simple round-robin allocator
 * tracked in @asid_cpu. When 8-bit value rolls over,a new cycle is started
 * over from 0, and TLB is flushed
 *
 * A new allocation cycle, post rollover, could potentially reassign an ASID
 * to a different task. Thus the rule is to refresh the ASID in a new cycle.
 * The 32 bit @asid_cpu (and mm->asid) have 8 bits MMU PID and rest 24 bits
 * serve as cycle/generation indicator and natural 32 bit unsigned math
 * automagically increments the generation when lower 8 bits rollover.
 */

#define MM_CTXT_ASID_MASK	0x000000ff /* MMU PID reg :8 bit PID */
#define MM_CTXT_CYCLE_MASK	(~MM_CTXT_ASID_MASK)

#define MM_CTXT_FIRST_CYCLE	(MM_CTXT_ASID_MASK + 1)
#define MM_CTXT_NO_ASID		0UL

#define asid_mm(mm, cpu)	mm->context.asid[cpu]
#define hw_pid(mm, cpu)		(asid_mm(mm, cpu) & MM_CTXT_ASID_MASK)

DECLARE_PER_CPU(unsigned int, asid_cache);
#define asid_cpu(cpu)		per_cpu(asid_cache, cpu)

/*
 * Get a new ASID if task doesn't have a valid one (unalloc or from prev cycle)
 * Also set the MMU PID register to existing/updated ASID
 */
static inline void get_new_mmu_context(struct mm_struct *mm)
{
	const unsigned int cpu = smp_processor_id();
	unsigned long flags;

	local_irq_save(flags);

	/*
	 * Move to new ASID if it was not from current alloc-cycle/generation.
	 * This is done by ensuring that the generation bits in both mm->ASID
	 * and cpu's ASID counter are exactly same.
	 *
	 * Note: Callers needing new ASID unconditionally, independent of
	 * 	 generation, e.g. local_flush_tlb_mm() for forking  parent,
	 * 	 first need to destroy the context, setting it to invalid
	 * 	 value.
	 */
	if (!((asid_mm(mm, cpu) ^ asid_cpu(cpu)) & MM_CTXT_CYCLE_MASK))
		goto set_hw;

	/* move to new ASID and handle rollover */
	if (unlikely(!(++asid_cpu(cpu) & MM_CTXT_ASID_MASK))) {

		local_flush_tlb_all();

		/*
		 * Above check for rollover of 8 bit ASID in 32 bit container.
		 * If the container itself wrapped around, set it to a non zero
		 * "generation" to distinguish from no context
		 */
		if (!asid_cpu(cpu))
			asid_cpu(cpu) = MM_CTXT_FIRST_CYCLE;
	}

	/* Assign new ASID to tsk */
	asid_mm(mm, cpu) = asid_cpu(cpu);

set_hw:
	mmu_setup_asid(mm, hw_pid(mm, cpu));

	local_irq_restore(flags);
}

/*
 * Initialize the context related info for a new mm_struct
 * instance.
 */
#define init_new_context init_new_context
static inline int
init_new_context(struct task_struct *tsk, struct mm_struct *mm)
{
	int i;

	for_each_possible_cpu(i)
		asid_mm(mm, i) = MM_CTXT_NO_ASID;

	return 0;
}

#define destroy_context destroy_context
static inline void destroy_context(struct mm_struct *mm)
{
	unsigned long flags;

	/* Needed to elide CONFIG_DEBUG_PREEMPT warning */
	local_irq_save(flags);
	asid_mm(mm, smp_processor_id()) = MM_CTXT_NO_ASID;
	local_irq_restore(flags);
}

/* Prepare the MMU for task: setup PID reg with allocated ASID
    If task doesn't have an ASID (never alloc or stolen, get a new ASID)
*/
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
			     struct task_struct *tsk)
{
	const int cpu = smp_processor_id();

	/*
	 * Note that the mm_cpumask is "aggregating" only, we don't clear it
	 * for the switched-out task, unlike some other arches.
	 * It is used to enlist cpus for sending TLB flush IPIs and not sending
	 * it to CPUs where a task once ran-on, could cause stale TLB entry
	 * re-use, specially for a multi-threaded task.
	 * e.g. T1 runs on C1, migrates to C3. T2 running on C2 munmaps.
	 *      For a non-aggregating mm_cpumask, IPI not sent C1, and if T1
	 *      were to re-migrate to C1, it could access the unmapped region
	 *      via any existing stale TLB entries.
	 */
	cpumask_set_cpu(cpu, mm_cpumask(next));

	mmu_setup_pgd(next, next->pgd);

	get_new_mmu_context(next);
}

/*
 * activate_mm defaults (in asm-generic) to switch_mm and is called at the
 * time of execve() to get a new ASID Note the subtlety here:
 * get_new_mmu_context() behaves differently here vs. in switch_mm(). Here
 * it always returns a new ASID, because mm has an unallocated "initial"
 * value, while in latter, it moves to a new ASID, only if it was
 * unallocated
 */

/* it seemed that deactivate_mm( ) is a reasonable place to do book-keeping
 * for retiring-mm. However destroy_context( ) still needs to do that because
 * between mm_release( ) = >deactive_mm( ) and
 * mmput => .. => __mmdrop( ) => destroy_context( )
 * there is a good chance that task gets sched-out/in, making its ASID valid
 * again (this teased me for a whole day).
 */

#include <asm-generic/mmu_context.h>

#endif /* __ASM_ARC_MMU_CONTEXT_H */

Filemanager

Name Type Size Permission Actions
Kbuild File 215 B 0644
arcregs.h File 9.44 KB 0644
asm-offsets.h File 165 B 0644
asserts.h File 958 B 0644
atomic-llsc.h File 2.71 KB 0644
atomic-spinlock.h File 2.88 KB 0644
atomic.h File 658 B 0644
atomic64-arcv2.h File 5.57 KB 0644
barrier.h File 1.34 KB 0644
bitops.h File 3.69 KB 0644
bug.h File 819 B 0644
cache.h File 3.52 KB 0644
cacheflush.h File 2.38 KB 0644
cachetype.h File 185 B 0644
checksum.h File 2.32 KB 0644
cmpxchg.h File 3.24 KB 0644
current.h File 548 B 0644
delay.h File 1.85 KB 0644
disasm.h File 3.72 KB 0644
dma.h File 218 B 0644
dsp-impl.h File 3.77 KB 0644
dsp.h File 796 B 0644
dwarf.h File 1.04 KB 0644
elf.h File 1.89 KB 0644
entry-arcv2.h File 7.71 KB 0644
entry-compact.h File 9.45 KB 0644
entry.h File 4.42 KB 0644
exec.h File 264 B 0644
fpu.h File 1.1 KB 0644
futex.h File 3.53 KB 0644
highmem.h File 1.39 KB 0644
hugepage.h File 2.14 KB 0644
io.h File 5.97 KB 0644
irq.h File 737 B 0644
irqflags-arcv2.h File 3.41 KB 0644
irqflags-compact.h File 4.31 KB 0644
irqflags.h File 363 B 0644
jump_label.h File 1.91 KB 0644
kdebug.h File 254 B 0644
kgdb.h File 1.21 KB 0644
kprobes.h File 1.06 KB 0644
linkage.h File 1.45 KB 0644
mach_desc.h File 1.9 KB 0644
mmu-arcv2.h File 2.46 KB 0644
mmu.h File 486 B 0644
mmu_context.h File 5.44 KB 0644
module.h File 428 B 0644
page.h File 3.22 KB 0644
pci.h File 360 B 0644
perf_event.h File 2 KB 0644
pgalloc.h File 2.68 KB 0644
pgtable-bits-arcv2.h File 4.79 KB 0644
pgtable-levels.h File 5.44 KB 0644
pgtable.h File 780 B 0644
processor.h File 2.96 KB 0644
ptrace.h File 4.39 KB 0644
sections.h File 261 B 0644
serial.h File 498 B 0644
setup.h File 1.21 KB 0644
shmparam.h File 297 B 0644
smp.h File 3.82 KB 0644
spinlock.h File 8.38 KB 0644
spinlock_types.h File 905 B 0644
stacktrace.h File 1.15 KB 0644
string.h File 1.01 KB 0644
switch_to.h File 553 B 0644
syscall.h File 1.73 KB 0644
syscalls.h File 547 B 0644
thread_info.h File 3.35 KB 0644
timex.h File 362 B 0644
tlb.h File 262 B 0644
tlbflush.h File 1.62 KB 0644
uaccess.h File 15.54 KB 0644
unistd.h File 305 B 0644
unwind.h File 3.37 KB 0644
vermagic.h File 157 B 0644
vmalloc.h File 87 B 0644
Filemanager