From patchwork Tue Jan 11 13:30:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 471731 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0BDUJIj017559 for ; Tue, 11 Jan 2011 13:30:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754009Ab1AKNaO (ORCPT ); Tue, 11 Jan 2011 08:30:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57906 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755618Ab1AKNaJ (ORCPT ); Tue, 11 Jan 2011 08:30:09 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0BDU8EO011846 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Jan 2011 08:30:09 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0BDU8I7005692; Tue, 11 Jan 2011 08:30:08 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 84BFA133F77; Tue, 11 Jan 2011 15:30:07 +0200 (IST) From: Gleb Natapov To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH unit-tests 2/3] Test that error code is pushed on exception's task stack. Date: Tue, 11 Jan 2011 15:30:06 +0200 Message-Id: <1294752607-7920-2-git-send-email-gleb@redhat.com> In-Reply-To: <1294752607-7920-1-git-send-email-gleb@redhat.com> References: <1294752607-7920-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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.6 (demeter1.kernel.org [140.211.167.41]); Tue, 11 Jan 2011 13:30:19 +0000 (UTC) diff --git a/x86/taskswitch2.c b/x86/taskswitch2.c index f51cb91..683834e 100644 --- a/x86/taskswitch2.c +++ b/x86/taskswitch2.c @@ -3,6 +3,7 @@ #include "apic-defs.h" #include "apic.h" #include "processor.h" +#include "vm.h" #define xstr(s) str(s) #define str(s) #s @@ -10,6 +11,9 @@ static volatile int test_count; static volatile unsigned int test_divider; +static char *fault_addr; +static ulong fault_phys; + static int g_fail; static int g_tests; @@ -66,6 +70,27 @@ start: goto start; } +void do_pf_tss(ulong *error_code) +{ + printf("PF task is running %x %x\n", error_code, *(ulong*)error_code); + print_current_tss_info(); + if (*(ulong*)error_code == 0x2) /* write access, not present */ + test_count++; + install_pte(phys_to_virt(read_cr3()), 1, fault_addr, + fault_phys | PTE_PRESENT | PTE_WRITE, 0); +} + +extern void pf_tss(void); + +asm ( + "pf_tss: \n\t" + "push %esp \n\t" + "call do_pf_tss \n\t" + "add $4, %esp \n\t" + "iret\n\t" + "jmp pf_tss\n\t" + ); + static void jmp_tss(void) { start: @@ -92,6 +117,7 @@ int main() { unsigned int res; + setup_vm(); setup_idt(); setup_gdt(); setup_tss32(); @@ -156,6 +182,19 @@ int main() printf("Return from int 3\n"); report("BP exeption", test_count == 1); + /* + * test that PF triggers task gate and error code is placed on + * exception task's stack + */ + fault_addr = alloc_vpage(); + fault_phys = (ulong)virt_to_phys(alloc_page()); + test_count = 0; + set_intr_task_gate(14, pf_tss); + printf("Access unmapped page\n"); + *fault_addr = 0; + printf("Return from pf tss\n"); + report("PF exeption", test_count == 1); + /* test that calling a task by lcall works */ test_count = 0; set_intr_task_gate(0, irq_tss);