From patchwork Thu Dec 5 22:38:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 3291411 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9925E9F373 for ; Thu, 5 Dec 2013 22:38:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A657E204DF for ; Thu, 5 Dec 2013 22:38:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C32D6202EC for ; Thu, 5 Dec 2013 22:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753257Ab3LEWis (ORCPT ); Thu, 5 Dec 2013 17:38:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:27236 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753047Ab3LEWir (ORCPT ); Thu, 5 Dec 2013 17:38:47 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rB5MceOQ015308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 5 Dec 2013 17:38:40 -0500 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rB5MccJv017664; Thu, 5 Dec 2013 17:38:38 -0500 Message-ID: <52A1006D.2070304@redhat.com> Date: Thu, 05 Dec 2013 23:38:37 +0100 From: Laszlo Ersek User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 MIME-Version: 1.0 To: Paolo Bonzini CC: edk2-devel@lists.sourceforge.net, KVM devel mailing list Subject: Re: [edk2] apparent KVM problem with LRET in TianoCore S3 resume trampoline References: <52A0A5E0.3090802@redhat.com> <52A0BB05.8010703@redhat.com> In-Reply-To: <52A0BB05.8010703@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 12/05/13 18:42, Paolo Bonzini wrote: > diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S > index e59fd04..d1cac9d 100644 > --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S > +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S > @@ -19,7 +19,7 @@ ASM_PFX(AsmTransferControl): > # rcx S3WakingVector :DWORD > # rdx AcpiLowMemoryBase :DWORD > lea _AsmTransferControl_al_0000(%rip), %eax > - movq $0x2800000000, %r8 > + movq $0x1000000000, %r8 > orq %r8, %rax > pushq %rax > shrd $20, %ecx, %ebx > @@ -28,24 +28,32 @@ ASM_PFX(AsmTransferControl): > movl %ebx, jmp_addr(%rip) > lret > _AsmTransferControl_al_0000: > + # Old SS should still be okay? > + addl _AsmTransferControl_al_0001-_AsmTransferControl_al_0000, %eax > + pushl $0x28 > + pushl %eax > + movq %cr0, %rax > + movq %cr4, %rbx > + andl $0x7fffffff, %eax > + andb $0xdf, %bl > + movq %rax, %cr0 # sets EFER.LMA=0 too, so says Intel > + movl $0x0c0000080, %ecx > + rdmsr > + andb $0xfe, %ah # set EFER.LME=0 > + wrmsr > + movq %rbx, %cr4 # only now set CR4.PAE=0 > + lret > +_AsmTransferControl_al_0001: > .byte 0x0b8, 0x30, 0 # mov ax, 30h as selector > movl %eax, %ds > movl %eax, %es > movl %eax, %fs > movl %eax, %gs > movl %eax, %ss > - movq %cr0, %rax > - movq %cr4, %rbx > - .byte 0x66 > - andl $0x7ffffffe, %eax > - andb $0xdf, %bl > - movq %rax, %cr0 > - .byte 0x66 > - movl $0x0c0000080, %ecx > - rdmsr > - andb $0xfe, %ah > - wrmsr > - movq %rbx, %cr4 > + movl %cr0, %rax # Get control register 0 > + .byte 0x66 > + .byte 0x83,0xe0,0xfe # and eax, 0fffffffeh ; Clear PE bit (bit #0) > + .byte 0xf,0x22,0xc0 # mov cr0, eax ; Activate real mode I had to add this incremental patch to get it to compile: The 2nd lret is reached (just before _AsmTransferControl_al_0001), but then the CPU goes off in the woods. For a while it seems to be spinning who knows where, and in 15-20 seconds or so the guest reboots. Does gas support mode switches in one file? I found examples on the net (for nasm I think) where people were thunking to real mode and back to protected mode in a single assembly file, and they could use native mnemonics for each part. (They just switched the assembler's mode in sync with execution modes.) Thanks Laszlo Thanks, Laszlo --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S index c28df3f..85d2a36 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/S3Asm.S @@ -30,8 +30,8 @@ ASM_PFX(AsmTransferControl): _AsmTransferControl_al_0000: # Old SS should still be okay? addl _AsmTransferControl_al_0001-_AsmTransferControl_al_0000, %eax - pushl $0x28 - pushl %eax + .byte 0x6a,0x28 # pushl $0x28 ; opnd sz = 32bits in seg 0x10 + .byte 0x50 # pushl %eax movq %cr0, %rax movq %cr4, %rbx andl $0x7fffffff, %eax @@ -50,7 +50,7 @@ _AsmTransferControl_al_0001: movl %eax, %fs movl %eax, %gs movl %eax, %ss - movl %cr0, %rax # Get control register 0 + .byte 0x0f,0x20,0xc0 # movl %cr0, %eax ; Get control register 0 .byte 0x66 .byte 0x83,0xe0,0xfe # and eax, 0fffffffeh ; Clear PE bit (bit #0) .byte 0xf,0x22,0xc0 # mov cr0, eax ; Activate real mode