From patchwork Mon Aug 26 12:18:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 269874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B26562C00C4 for ; Mon, 26 Aug 2013 22:19:31 +1000 (EST) Received: from localhost ([::1]:51133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDvlZ-0002xw-Kb for incoming@patchwork.ozlabs.org; Mon, 26 Aug 2013 08:19:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDvlA-0002xO-6r for qemu-devel@nongnu.org; Mon, 26 Aug 2013 08:19:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VDvl1-0002sJ-Cd for qemu-devel@nongnu.org; Mon, 26 Aug 2013 08:19:04 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:46606) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VDvl0-0002rm-FO for qemu-devel@nongnu.org; Mon, 26 Aug 2013 08:18:55 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 26 Aug 2013 17:39:46 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 26 Aug 2013 17:39:44 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 74DCDE0054; Mon, 26 Aug 2013 17:49:21 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r7QCIhCt38731792; Mon, 26 Aug 2013 17:48:43 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r7QCIkhs021882; Mon, 26 Aug 2013 17:48:46 +0530 Received: from skywalker.linux.vnet.ibm.com ([9.124.219.48]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r7QCIjrZ021857; Mon, 26 Aug 2013 17:48:45 +0530 From: "Aneesh Kumar K.V" To: Alexander Graf In-Reply-To: <489F72F5-1040-4D17-968E-5BB42043E51D@suse.de> References: <1377235210-27093-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> <1377235210-27093-3-git-send-email-aneesh.kumar@linux.vnet.ibm.com> <31707B5A-C56F-4343-8851-1DD516A099AD@suse.de> <87r4dhdmwc.fsf@linux.vnet.ibm.com> <489F72F5-1040-4D17-968E-5BB42043E51D@suse.de> User-Agent: Notmuch/0.15.2+167~g5306b2b (http://notmuchmail.org) Emacs/24.3.50.1 (x86_64-unknown-linux-gnu) Date: Mon, 26 Aug 2013 17:48:44 +0530 Message-ID: <87eh9gejbv.fsf@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13082612-4790-0000-0000-000009FA6C13 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.1 Cc: Paul Mackerras , "qemu-ppc@nongnu.org list:PowerPC" , "qemu-devel@nongnu.org qemu-devel" Subject: Re: [Qemu-devel] [PATCH -V3 2/4] target-ppc: Fix page table lookup with kvm enabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Alexander Graf writes: > On 26.08.2013, at 07:46, Aneesh Kumar K.V wrote: > >> Alexander Graf writes: ... >>> >>> This breaks PR KVM which doesn't have an HTAB fd. >>> >>> I think what you want is code in kvmppc_set_papr() that tries to fetch >>> an HTAB fd. You can then modify the check to if (kvm_enabled() && >>> kvmppc_has_htab_fd()), as the below case should work just fine on PR >>> KVM. >> >> As explained before caching htab fd may not really work. How about >> >> diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c >> index fce8835..cf6aca4 100644 >> --- a/target-ppc/kvm.c >> +++ b/target-ppc/kvm.c >> @@ -1892,19 +1892,24 @@ void kvm_arch_init_irq_routing(KVMState *s) >> { >> } >> >> -int kvmppc_hash64_load_hpte(PowerPCCPU *cpu, uint64_t index, >> - target_ulong *hpte0, target_ulong *hpte1) > > Against which tree is this? I don't even have this function in mine. Sorry for the confusion, i wanted to show how it changed from the current function. So it was done as a patch against this series. > >> +hwaddr kvmppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash, >> + bool secondary, target_ulong ptem, > > I'm having a hard time following this code. How do you tell the kernel which PTE group you're interested in? > >> + target_ulong *hpte0, target_ulong *hpte1) >> { >> int htab_fd; >> + uint64_t index; >> + hwaddr pte_offset; >> + target_ulong pte0, pte1; >> struct kvm_get_htab_fd ghf; >> struct kvm_get_htab_buf { >> struct kvm_get_htab_header header; >> /* >> * Older kernel required one extra byte. >> */ >> - unsigned long hpte[3]; >> + unsigned long hpte[(HPTES_PER_GROUP * 2) + 1]; > > Does this need your kernel patch to work? This is the updated patch. commit f38b39855c383c55e4ad5d0a4ab617a99de134d8 Author: Aneesh Kumar K.V Date: Wed Aug 7 11:34:02 2013 +0530 target-ppc: Fix page table lookup with kvm enabled With kvm enabled, we store the hash page table information in the hypervisor. Use ioctl to read the htab contents. Without this we get the below error when trying to read the guest address (gdb) x/10 do_fork 0xc000000000098660 : Cannot access memory at address 0xc000000000098660 (gdb) Signed-off-by: Aneesh Kumar K.V diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 1838465..05b066c 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -1888,3 +1888,62 @@ int kvm_arch_on_sigbus(int code, void *addr) void kvm_arch_init_irq_routing(KVMState *s) { } + +hwaddr kvmppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash, + bool secondary, target_ulong ptem, + target_ulong *hpte0, target_ulong *hpte1) +{ + int htab_fd; + uint64_t index; + hwaddr pte_offset; + target_ulong pte0, pte1; + struct kvm_get_htab_fd ghf; + struct kvm_get_htab_buf { + struct kvm_get_htab_header header; + /* + * Older kernel required one extra byte. + */ + unsigned long hpte[(HPTES_PER_GROUP * 2) + 1]; + } hpte_buf; + + index = (hash * HPTES_PER_GROUP) & cpu->env.htab_mask; + *hpte0 = 0; + *hpte1 = 0; + if (!cap_htab_fd) { + return 0; + } + + ghf.flags = 0; + ghf.start_index = index; + htab_fd = kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &ghf); + if (htab_fd < 0) { + goto error_out; + } + /* + * Read the hpte group + */ + if (read(htab_fd, &hpte_buf, sizeof(hpte_buf)) < 0) { + goto out; + } + + index = 0; + pte_offset = (hash * HASH_PTEG_SIZE_64) & cpu->env.htab_mask;; + while (index < hpte_buf.header.n_valid) { + pte0 = hpte_buf.hpte[(index * 2)]; + pte1 = hpte_buf.hpte[(index * 2) + 1]; + if ((pte0 & HPTE64_V_VALID) + && (secondary == !!(pte0 & HPTE64_V_SECONDARY)) + && HPTE64_V_COMPARE(pte0, ptem)) { + *hpte0 = pte0; + *hpte1 = pte1; + close(htab_fd); + return pte_offset; + } + index++; + pte_offset += HASH_PTE_SIZE_64; + } +out: + close(htab_fd); +error_out: + return -1; +} diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h index 4ae7bf2..dad0e57 100644 --- a/target-ppc/kvm_ppc.h +++ b/target-ppc/kvm_ppc.h @@ -42,7 +42,9 @@ int kvmppc_get_htab_fd(bool write); int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns); int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, uint16_t n_valid, uint16_t n_invalid); - +hwaddr kvmppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash, + bool secondary, target_ulong ptem, + target_ulong *hpte0, target_ulong *hpte1); #else static inline uint32_t kvmppc_get_tbfreq(void) @@ -181,6 +183,14 @@ static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, abort(); } +static inline hwaddr kvmppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash, + bool secondary, + target_ulong ptem, + target_ulong *hpte0, + target_ulong *hpte1) +{ + abort(); +} #endif #ifndef CONFIG_KVM diff --git a/target-ppc/mmu-hash64.c b/target-ppc/mmu-hash64.c index 67fc1b5..2288fe8 100644 --- a/target-ppc/mmu-hash64.c +++ b/target-ppc/mmu-hash64.c @@ -302,37 +302,50 @@ static int ppc_hash64_amr_prot(CPUPPCState *env, ppc_hash_pte64_t pte) return prot; } -static hwaddr ppc_hash64_pteg_search(CPUPPCState *env, hwaddr pteg_off, +static hwaddr ppc_hash64_pteg_search(CPUPPCState *env, hwaddr hash, bool secondary, target_ulong ptem, ppc_hash_pte64_t *pte) { - hwaddr pte_offset = pteg_off; + hwaddr pte_offset; target_ulong pte0, pte1; - int i; - - for (i = 0; i < HPTES_PER_GROUP; i++) { - pte0 = ppc_hash64_load_hpte0(env, pte_offset); - pte1 = ppc_hash64_load_hpte1(env, pte_offset); - - if ((pte0 & HPTE64_V_VALID) - && (secondary == !!(pte0 & HPTE64_V_SECONDARY)) - && HPTE64_V_COMPARE(pte0, ptem)) { - pte->pte0 = pte0; - pte->pte1 = pte1; - return pte_offset; + int i, ret = 0; + + if (kvm_enabled()) { + ret = kvmppc_hash64_pteg_search(ppc_env_get_cpu(env), hash, + secondary, ptem, + &pte->pte0, &pte->pte1); + } + /* + * We don't support htab fd, check whether we have a copy of htab + */ + if (!ret) { + pte_offset = (hash * HASH_PTEG_SIZE_64) & env->htab_mask;; + for (i = 0; i < HPTES_PER_GROUP; i++) { + pte0 = ppc_hash64_load_hpte0(env, pte_offset); + pte1 = ppc_hash64_load_hpte1(env, pte_offset); + + if ((pte0 & HPTE64_V_VALID) + && (secondary == !!(pte0 & HPTE64_V_SECONDARY)) + && HPTE64_V_COMPARE(pte0, ptem)) { + pte->pte0 = pte0; + pte->pte1 = pte1; + return pte_offset; + } + pte_offset += HASH_PTE_SIZE_64; } - - pte_offset += HASH_PTE_SIZE_64; + /* + * We didn't find a valid entry. + */ + ret = -1; } - - return -1; + return ret; } static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env, ppc_slb_t *slb, target_ulong eaddr, ppc_hash_pte64_t *pte) { - hwaddr pteg_off, pte_offset; + hwaddr pte_offset; hwaddr hash; uint64_t vsid, epnshift, epnmask, epn, ptem; @@ -367,8 +380,7 @@ static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env, " vsid=" TARGET_FMT_lx " ptem=" TARGET_FMT_lx " hash=" TARGET_FMT_plx "\n", env->htab_base, env->htab_mask, vsid, ptem, hash); - pteg_off = (hash * HASH_PTEG_SIZE_64) & env->htab_mask; - pte_offset = ppc_hash64_pteg_search(env, pteg_off, 0, ptem, pte); + pte_offset = ppc_hash64_pteg_search(env, hash, 0, ptem, pte); if (pte_offset == -1) { /* Secondary PTEG lookup */ @@ -377,8 +389,7 @@ static hwaddr ppc_hash64_htab_lookup(CPUPPCState *env, " hash=" TARGET_FMT_plx "\n", env->htab_base, env->htab_mask, vsid, ptem, ~hash); - pteg_off = (~hash * HASH_PTEG_SIZE_64) & env->htab_mask; - pte_offset = ppc_hash64_pteg_search(env, pteg_off, 1, ptem, pte); + pte_offset = ppc_hash64_pteg_search(env, ~hash, 1, ptem, pte); } return pte_offset;