From patchwork Wed Mar 24 21:24:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 88067 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2OLTekL014216 for ; Wed, 24 Mar 2010 21:29:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753465Ab0CXV3g (ORCPT ); Wed, 24 Mar 2010 17:29:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5635 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753334Ab0CXV3W (ORCPT ); Wed, 24 Mar 2010 17:29:22 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTLgU013563 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 24 Mar 2010 17:29:22 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTLUY022847; Wed, 24 Mar 2010 17:29:21 -0400 Received: from amt.cnet (vpn-10-46.rdu.redhat.com [10.11.10.46]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o2OLTKAL008896; Wed, 24 Mar 2010 17:29:20 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id D0CCC68AC66; Wed, 24 Mar 2010 18:28:11 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o2OLSAmX022375; Wed, 24 Mar 2010 18:28:10 -0300 Message-Id: <20100324212725.719993098@amt.cnet> User-Agent: quilt/0.47-1 Date: Wed, 24 Mar 2010 18:24:10 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [patch 2/8] test: add pagefault exception handler References: <20100324212408.790319364@amt.cnet> Content-Disposition: inline; filename=pf-vector X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 24 Mar 2010 21:29:43 +0000 (UTC) Index: qemu-kvm/kvm/user/test/lib/x86/smp.c =================================================================== --- qemu-kvm.orig/kvm/user/test/lib/x86/smp.c +++ qemu-kvm/kvm/user/test/lib/x86/smp.c @@ -5,6 +5,7 @@ #include "fwcfg.h" #define IPI_VECTOR 0x20 +#define PF_VECTOR 0xe static struct spinlock ipi_lock; static void (*ipi_function)(void *data); @@ -18,6 +19,20 @@ static __attribute__((used)) void ipi() ipi_done = 1; } +unsigned long read_cr2() +{ + unsigned long cr2; + + asm volatile ("mov %%cr2, %0" : "=r"(cr2)); + return cr2; +} + +static __attribute__((used)) void pf() +{ + printf("PF: %lx\n", read_cr2()); + asm ("call exit"); +} + asm ( "ipi_entry: \n" " call ipi \n" @@ -28,21 +43,31 @@ asm ( #endif ); +asm ( + "pf_entry: \n" + " call pf \n" +#ifndef __x86_64__ + " iret" +#else + " iretq" +#endif + ); + -static void set_ipi_descriptor(void (*ipi_entry)(void)) +static void set_exp_descriptor(void (*entry)(void), unsigned vec) { - unsigned short *desc = (void *)(IPI_VECTOR * sizeof(long) * 2); + unsigned short *desc = (void *)(vec * sizeof(long) * 2); unsigned short cs; - unsigned long ipi = (unsigned long)ipi_entry; + unsigned long fn = (unsigned long)entry; asm ("mov %%cs, %0" : "=r"(cs)); - desc[0] = ipi; + desc[0] = fn; desc[1] = cs; desc[2] = 0x8e00; - desc[3] = ipi >> 16; + desc[3] = fn >> 16; #ifdef __x86_64__ - desc[4] = ipi >> 32; - desc[5] = ipi >> 48; + desc[4] = fn >> 32; + desc[5] = fn >> 48; desc[6] = 0; desc[7] = 0; #endif @@ -118,8 +143,10 @@ void smp_init_ids(void) { int i; void ipi_entry(void); + void pf_entry(void); - set_ipi_descriptor(ipi_entry); + set_exp_descriptor(ipi_entry, IPI_VECTOR); + set_exp_descriptor(pf_entry, PF_VECTOR); setup_smp_id(0); for (i = 1; i < cpu_count(); ++i)