Re: [PATCH] SVM: forbid guest to execute monitor/mwait

Joerg Roedel
2007-03-22T10:17:29Z

On Thu, Mar 22, 2007 at 12:06:32PM +0200, Avi Kivity wrote:
> Joerg Roedel wrote:
> >On Thu, Mar 22, 2007 at 09:38:12AM +0200, Avi Kivity wrote:
> >
> >>Joerg Roedel wrote:
> >>
> >>>From: Joerg Roedel <joerg.roedel-5C7GfCeVMHo@public.gmane.org>
> >>>
> >>>This patch forbids the guest to execute monitor/mwait instructions on
> >>>SVM. This is necessary because the guest can execute these instructions
> >>>if they are available even if the kvm cpuid doesn't report its
> >>>existence.
> >>>
> >>>
> >>You're intercepting the instructions unconditionally. What about the case where cpuid does
> >>report monitor/mwait support? The guest can legitimately use them then.
> >>
> >
> >I prepared a patch for QEmu to handle this but finally not
> >submitted it because QEmu does not set the Monitor bit anyway. But you
> >are right. It is possible for userspace to set the Montior bit and the
> >guest won't be able to use it.
> >I think an architecture dependent cpuid mask feature in the kernel would
> >solve this problem. I'll prepare a patch for that.
> >
> >
>
> I think I'm misunderstanding something.
>
> Is there actually an AMD cpu that supports monitor/mwait? If not (understandably, having no

Yes, the family 10h processors have support for that.

> hyperthreading), then wouldn't executing monitor or mwait generate #UD anyway? I don't think
> there's need for the cpuid mask as long as setting the monitor bit cannot endanger the
> kernel.

There is no danger for the host kernel but for the guest. If the
userspace sets the monitor bit the guest will receive an #UD when trying
to use it. And we don't want the guest to use it because it is not
virtualized yet.

Joerg