mirror of
https://github.com/torvalds/linux.git
synced 2024-12-29 22:31:32 +00:00
aefa5688c0
upatepp can get called for a nohpte fault when we find from the linux page table that the translation was hashed before. In that case we are sure that there is no existing translation, hence we could avoid doing tlbie. We could possibly race with a parallel fault filling the TLB. But that should be ok because updatepp is only ever relaxing permissions. We also look at linux pte permission bits when filling hash pte permission bits. We also hold the linux pte busy bits while inserting/updating a hashpte entry, hence a paralle update of linux pte is not possible. On the other hand mprotect involves ptep_modify_prot_start which cause a hpte invalidate and not updatepp. Performance number: We use randbox_access_bench written by Anton. Kernel with THP disabled and smaller hash page table size. 86.60% random_access_b [kernel.kallsyms] [k] .native_hpte_updatepp 2.10% random_access_b random_access_bench [.] doit 1.99% random_access_b [kernel.kallsyms] [k] .do_raw_spin_lock 1.85% random_access_b [kernel.kallsyms] [k] .native_hpte_insert 1.26% random_access_b [kernel.kallsyms] [k] .native_flush_hash_range 1.18% random_access_b [kernel.kallsyms] [k] .__delay 0.69% random_access_b [kernel.kallsyms] [k] .native_hpte_remove 0.37% random_access_b [kernel.kallsyms] [k] .clear_user_page 0.34% random_access_b [kernel.kallsyms] [k] .__hash_page_64K 0.32% random_access_b [kernel.kallsyms] [k] fast_exception_return 0.30% random_access_b [kernel.kallsyms] [k] .hash_page_mm With Fix: 27.54% random_access_b random_access_bench [.] doit 22.90% random_access_b [kernel.kallsyms] [k] .native_hpte_insert 5.76% random_access_b [kernel.kallsyms] [k] .native_hpte_remove 5.20% random_access_b [kernel.kallsyms] [k] fast_exception_return 5.12% random_access_b [kernel.kallsyms] [k] .__hash_page_64K 4.80% random_access_b [kernel.kallsyms] [k] .hash_page_mm 3.31% random_access_b [kernel.kallsyms] [k] data_access_common 1.84% random_access_b [kernel.kallsyms] [k] .trace_hardirqs_on_caller Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
208 lines
5.4 KiB
C
208 lines
5.4 KiB
C
/*
|
|
* PS3 pagetable management routines.
|
|
*
|
|
* Copyright (C) 2006 Sony Computer Entertainment Inc.
|
|
* Copyright 2006, 2007 Sony Corporation
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; version 2 of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/memblock.h>
|
|
|
|
#include <asm/machdep.h>
|
|
#include <asm/prom.h>
|
|
#include <asm/udbg.h>
|
|
#include <asm/lv1call.h>
|
|
#include <asm/ps3fb.h>
|
|
|
|
#define PS3_VERBOSE_RESULT
|
|
#include "platform.h"
|
|
|
|
/**
|
|
* enum lpar_vas_id - id of LPAR virtual address space.
|
|
* @lpar_vas_id_current: Current selected virtual address space
|
|
*
|
|
* Identify the target LPAR address space.
|
|
*/
|
|
|
|
enum ps3_lpar_vas_id {
|
|
PS3_LPAR_VAS_ID_CURRENT = 0,
|
|
};
|
|
|
|
|
|
static DEFINE_SPINLOCK(ps3_htab_lock);
|
|
|
|
static long ps3_hpte_insert(unsigned long hpte_group, unsigned long vpn,
|
|
unsigned long pa, unsigned long rflags, unsigned long vflags,
|
|
int psize, int apsize, int ssize)
|
|
{
|
|
int result;
|
|
u64 hpte_v, hpte_r;
|
|
u64 inserted_index;
|
|
u64 evicted_v, evicted_r;
|
|
u64 hpte_v_array[4], hpte_rs;
|
|
unsigned long flags;
|
|
long ret = -1;
|
|
|
|
/*
|
|
* lv1_insert_htab_entry() will search for victim
|
|
* entry in both primary and secondary pte group
|
|
*/
|
|
vflags &= ~HPTE_V_SECONDARY;
|
|
|
|
hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID;
|
|
hpte_r = hpte_encode_r(ps3_mm_phys_to_lpar(pa), psize, apsize) | rflags;
|
|
|
|
spin_lock_irqsave(&ps3_htab_lock, flags);
|
|
|
|
/* talk hvc to replace entries BOLTED == 0 */
|
|
result = lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, hpte_group,
|
|
hpte_v, hpte_r,
|
|
HPTE_V_BOLTED, 0,
|
|
&inserted_index,
|
|
&evicted_v, &evicted_r);
|
|
|
|
if (result) {
|
|
/* all entries bolted !*/
|
|
pr_info("%s:result=%s vpn=%lx pa=%lx ix=%lx v=%llx r=%llx\n",
|
|
__func__, ps3_result(result), vpn, pa, hpte_group,
|
|
hpte_v, hpte_r);
|
|
BUG();
|
|
}
|
|
|
|
/*
|
|
* see if the entry is inserted into secondary pteg
|
|
*/
|
|
result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT,
|
|
inserted_index & ~0x3UL,
|
|
&hpte_v_array[0], &hpte_v_array[1],
|
|
&hpte_v_array[2], &hpte_v_array[3],
|
|
&hpte_rs);
|
|
BUG_ON(result);
|
|
|
|
if (hpte_v_array[inserted_index % 4] & HPTE_V_SECONDARY)
|
|
ret = (inserted_index & 7) | (1 << 3);
|
|
else
|
|
ret = inserted_index & 7;
|
|
|
|
spin_unlock_irqrestore(&ps3_htab_lock, flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static long ps3_hpte_remove(unsigned long hpte_group)
|
|
{
|
|
panic("ps3_hpte_remove() not implemented");
|
|
return 0;
|
|
}
|
|
|
|
static long ps3_hpte_updatepp(unsigned long slot, unsigned long newpp,
|
|
unsigned long vpn, int psize, int apsize,
|
|
int ssize, unsigned long inv_flags)
|
|
{
|
|
int result;
|
|
u64 hpte_v, want_v, hpte_rs;
|
|
u64 hpte_v_array[4];
|
|
unsigned long flags;
|
|
long ret;
|
|
|
|
want_v = hpte_encode_avpn(vpn, psize, ssize);
|
|
|
|
spin_lock_irqsave(&ps3_htab_lock, flags);
|
|
|
|
result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT, slot & ~0x3UL,
|
|
&hpte_v_array[0], &hpte_v_array[1],
|
|
&hpte_v_array[2], &hpte_v_array[3],
|
|
&hpte_rs);
|
|
|
|
if (result) {
|
|
pr_info("%s: result=%s read vpn=%lx slot=%lx psize=%d\n",
|
|
__func__, ps3_result(result), vpn, slot, psize);
|
|
BUG();
|
|
}
|
|
|
|
hpte_v = hpte_v_array[slot % 4];
|
|
|
|
/*
|
|
* As lv1_read_htab_entries() does not give us the RPN, we can
|
|
* not synthesize the new hpte_r value here, and therefore can
|
|
* not update the hpte with lv1_insert_htab_entry(), so we
|
|
* instead invalidate it and ask the caller to update it via
|
|
* ps3_hpte_insert() by returning a -1 value.
|
|
*/
|
|
if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) {
|
|
/* not found */
|
|
ret = -1;
|
|
} else {
|
|
/* entry found, just invalidate it */
|
|
result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT,
|
|
slot, 0, 0);
|
|
ret = -1;
|
|
}
|
|
|
|
spin_unlock_irqrestore(&ps3_htab_lock, flags);
|
|
return ret;
|
|
}
|
|
|
|
static void ps3_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
|
|
int psize, int ssize)
|
|
{
|
|
panic("ps3_hpte_updateboltedpp() not implemented");
|
|
}
|
|
|
|
static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn,
|
|
int psize, int apsize, int ssize, int local)
|
|
{
|
|
unsigned long flags;
|
|
int result;
|
|
|
|
spin_lock_irqsave(&ps3_htab_lock, flags);
|
|
|
|
result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, slot, 0, 0);
|
|
|
|
if (result) {
|
|
pr_info("%s: result=%s vpn=%lx slot=%lx psize=%d\n",
|
|
__func__, ps3_result(result), vpn, slot, psize);
|
|
BUG();
|
|
}
|
|
|
|
spin_unlock_irqrestore(&ps3_htab_lock, flags);
|
|
}
|
|
|
|
static void ps3_hpte_clear(void)
|
|
{
|
|
unsigned long hpte_count = (1UL << ppc64_pft_size) >> 4;
|
|
u64 i;
|
|
|
|
for (i = 0; i < hpte_count; i++)
|
|
lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, i, 0, 0);
|
|
|
|
ps3_mm_shutdown();
|
|
ps3_mm_vas_destroy();
|
|
}
|
|
|
|
void __init ps3_hpte_init(unsigned long htab_size)
|
|
{
|
|
ppc_md.hpte_invalidate = ps3_hpte_invalidate;
|
|
ppc_md.hpte_updatepp = ps3_hpte_updatepp;
|
|
ppc_md.hpte_updateboltedpp = ps3_hpte_updateboltedpp;
|
|
ppc_md.hpte_insert = ps3_hpte_insert;
|
|
ppc_md.hpte_remove = ps3_hpte_remove;
|
|
ppc_md.hpte_clear_all = ps3_hpte_clear;
|
|
|
|
ppc64_pft_size = __ilog2(htab_size);
|
|
}
|
|
|