From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Graf Subject: Re: [PATCH v2] kvm/book3s: Make kernel emulated H_PUT_TCE available for "PR" KVM Date: Wed, 02 May 2012 15:32:30 +0200 Message-ID: <4FA1376E.2030606@suse.de> References: <1331884714.3105.166.camel@pasglop> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org To: Benjamin Herrenschmidt Return-path: In-Reply-To: <1331884714.3105.166.camel@pasglop> Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 03/16/2012 08:58 AM, Benjamin Herrenschmidt wrote: > There is nothing in the code for emulating TCE tables in the kernel > that prevents it from working on "PR" KVM... other than ifdef's and > location of the code. > > This renames book3s_64_vio_hv.c to book3s_64_vio.c and moves the > bulk of the code there. > > This speeds things up a bit on my G5. > --- > > v2. Changed the ifdef as per discussion with Alex. I still didn't > manage to get git to figure out the rename but that's no big deal, > the old file had only one small function in it. There's no code > change, you can trust me on that one, It's really just moving > things around :-) > > arch/powerpc/include/asm/kvm_host.h | 4 +- > arch/powerpc/include/asm/kvm_ppc.h | 2 + > arch/powerpc/kvm/Makefile | 3 +- > arch/powerpc/kvm/book3s_64_vio.c | 187 +++++++++++++++++++++++++++++++++++ > arch/powerpc/kvm/book3s_64_vio_hv.c | 73 -------------- > arch/powerpc/kvm/book3s_hv.c | 109 -------------------- > arch/powerpc/kvm/book3s_pr.c | 3 + > arch/powerpc/kvm/book3s_pr_papr.c | 18 ++++ > arch/powerpc/kvm/powerpc.c | 8 +- > 9 files changed, 221 insertions(+), 186 deletions(-) > create mode 100644 arch/powerpc/kvm/book3s_64_vio.c > delete mode 100644 arch/powerpc/kvm/book3s_64_vio_hv.c > > diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h > index 42a527e..d848cdc 100644 > --- a/arch/powerpc/include/asm/kvm_host.h > +++ b/arch/powerpc/include/asm/kvm_host.h > @@ -237,7 +237,6 @@ struct kvm_arch { > unsigned long vrma_slb_v; > int rma_setup_done; > int using_mmu_notifiers; > - struct list_head spapr_tce_tables; > spinlock_t slot_phys_lock; > unsigned long *slot_phys[KVM_MEM_SLOTS_NUM]; > int slot_npages[KVM_MEM_SLOTS_NUM]; > @@ -245,6 +244,9 @@ struct kvm_arch { > struct kvmppc_vcore *vcores[KVM_MAX_VCORES]; > struct kvmppc_linear_info *hpt_li; > #endif /* CONFIG_KVM_BOOK3S_64_HV */ > +#ifdef CONFIG_PPC_BOOK3S_64 > + struct list_head spapr_tce_tables; > +#endif > }; > > /* > diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h > index 7f0a3da..c1069f6 100644 > --- a/arch/powerpc/include/asm/kvm_ppc.h > +++ b/arch/powerpc/include/asm/kvm_ppc.h > @@ -126,6 +126,8 @@ extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu, > extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu); > extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, > struct kvm_create_spapr_tce *args); > +extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, > + unsigned long ioba, unsigned long tce); > extern long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, > struct kvm_allocate_rma *rma); > extern struct kvmppc_linear_info *kvm_alloc_rma(void); > diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile > index 25225ae..8c95def 100644 > --- a/arch/powerpc/kvm/Makefile > +++ b/arch/powerpc/kvm/Makefile > @@ -54,6 +54,7 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ > book3s_paired_singles.o \ > book3s_pr.o \ > book3s_pr_papr.o \ > + book3s_64_vio.o \ > book3s_emulate.o \ > book3s_interrupts.o \ > book3s_mmu_hpte.o \ > @@ -70,7 +71,7 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ > kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ > book3s_hv_rmhandlers.o \ > book3s_hv_rm_mmu.o \ > - book3s_64_vio_hv.o \ > + book3s_64_vio.o \ > book3s_hv_builtin.o > > kvm-book3s_64-module-objs := \ > diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c > new file mode 100644 > index 0000000..193ba68 > --- /dev/null > +++ b/arch/powerpc/kvm/book3s_64_vio.c > @@ -0,0 +1,187 @@ > +/* > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License, version 2, as > + * published by the Free Software Foundation. > + * > + * 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. > + * > + * Copyright 2010 Paul Mackerras, IBM Corp. > + * Copyright 2011 David Gibson, IBM Corporation > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64)) > + > +/* WARNING: This will be called in real-mode on HV KVM and virtual > + * mode on PR KVM > + */ > +long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, > + unsigned long ioba, unsigned long tce) > +{ > + struct kvm *kvm = vcpu->kvm; > + struct kvmppc_spapr_tce_table *stt; > + > + /* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx\n", */ > + /* liobn, ioba, tce); */ > + > + list_for_each_entry(stt,&kvm->arch.spapr_tce_tables, list) { > + if (stt->liobn == liobn) { > + unsigned long idx = ioba>> SPAPR_TCE_SHIFT; > + struct page *page; > + u64 *tbl; > + > + /* udbg_printf("H_PUT_TCE: liobn 0x%lx => stt=%p window_size=0x%x\n", */ > + /* liobn, stt, stt->window_size); */ > + if (ioba>= stt->window_size) > + return H_PARAMETER; > + > + page = stt->pages[idx / TCES_PER_PAGE]; > + tbl = (u64 *)page_address(page); > + > + /* FIXME: Need to validate the TCE itself */ > + /* udbg_printf("tce @ %p\n",&tbl[idx % TCES_PER_PAGE]); */ > + tbl[idx % TCES_PER_PAGE] = tce; > + return H_SUCCESS; > + } > + } > + > + /* Didn't find the liobn, punt it to userspace */ > + return H_TOO_HARD; > +} This function needs to be available in real mode on HV, but the ones below must be on module code when kvm is compiled as a module, because they call kvm infrastructure which lives in module code. Alex