From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Gabriel L. Somlo" Subject: Re: [PATCH v2] kvm: x86: emulate monitor and mwait instructions as nop Date: Wed, 4 Jun 2014 16:11:15 -0400 Message-ID: <20140604201114.GM1653@ERROL.INI.CMU.EDU> References: <46EF8587-E226-44C5-930A-49E4F7FBBC82@gmail.com> <4D29A9ED-3A3D-43D6-A47F-98184BFFA0A3@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Paolo Bonzini , Alexander Graf , kvm@vger.kernel.org, mst@redhat.com, Borislav Petkov To: Nadav Amit Return-path: Received: from mail-qa0-f41.google.com ([209.85.216.41]:56438 "EHLO mail-qa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751346AbaFDULS (ORCPT ); Wed, 4 Jun 2014 16:11:18 -0400 Received: by mail-qa0-f41.google.com with SMTP id dc16so21895qab.0 for ; Wed, 04 Jun 2014 13:11:18 -0700 (PDT) Content-Disposition: inline In-Reply-To: <4D29A9ED-3A3D-43D6-A47F-98184BFFA0A3@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Jun 04, 2014 at 11:01:50PM +0300, Nadav Amit wrote: > On Jun 4, 2014, at 10:43 PM, Gabriel L. Somlo wrote: > > My implementation still emulates the instruction as a NOP, but first checks for an exception. [...] > Anyhow, if you want a real mwait emulation, you can write-protect the page of the monitored memory area in the EPT of the other VCPUs and set a callback once a write to the area takes place. You may want the host to cause a spurious wakeup after you do the write-protection, so you will not miss a write of another VCPU to the monitored area. After the spurious wake-up, the VM is likely to issue an additional mwait, using the same monitored cache-line. > > Additional care for DMAs (emulated and paravirtual) might be needed with the assistance of QEMU. The complicated case is dealing with the DMAs of assigned devices due to the lack of support for I/O page-faules. I took a stab at something like that a while ago: http://www.contrib.andrew.cmu.edu/~somlo/OSXKVM/kvm-mwait-emu-20140205.patch with limited success, probably due to my lack of familiarity with the fine details of the KVM code base... :) My main interest was to get it working well enough to be useful for idle loops (which is the only thing I know of that either Linux or OS X use monitor and mwait for, currently -- so DMA wasn't a huge priority). Even if we got it working well enough in the general case (any number of vcpus, etc) I think it would still suck for idle loops when compared to simply falling back to HLT (mainly due to all the TLB shootdowns required to make it work) :) Thanks, --Gabriel