Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754282AbdGJQV4 (ORCPT ); Mon, 10 Jul 2017 12:21:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52320 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753864AbdGJQVy (ORCPT ); Mon, 10 Jul 2017 12:21:54 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 47B7674863 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 47B7674863 Subject: Re: RFC: Task switch emulation fails for VM86 mode To: Nadav Amit , Wanpeng Li Cc: Radim Krcmar , kvm , "linux-kernel@vger.kernel.org" , Jan Kiszka References: From: Paolo Bonzini Message-ID: Date: Mon, 10 Jul 2017 18:21:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 10 Jul 2017 16:21:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1140 Lines: 24 On 10/07/2017 17:48, Nadav Amit wrote: >>> >>> Any proposal is a great appreciated. :) > I don’t see a (very) easy solution. The code was (apparently) never built to > deal with a task switch during an instruction emulation. > > AFAIU kvm_task_switch() expects information about the task-switch from the > CPU “task-switch assist” mechanisms, and this information (or even the fact > that a task-switch is needed due to an exception) are unavailable from the > instruction emulator. The instruction emulator itself does not know to > emulate task-switches, e.g., during far CALL and JMP. > > A complete solution is therefore complicated and requires some work. Your > specific problem may be addressed by detecting the injection of an exception > while having invalid guest state in vm86 in vmx_queue_exception() or in > handle_invalid_guest_state(), and emulating the “task-switch assist” > mechanism. I agree, the right solution would be to read the IDT in vmx_queue_exception if vmx->emulation_required, and inject the exception manually. It would be an extension of what kvm_inject_realmode_interrupt already does. Paolo