From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Sheng Yang <sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH] KVM: VMX: Fix repeatly calling alloc_apic_access_page()
Date: Mon, 05 Nov 2007 15:55:24 +0200 [thread overview]
Message-ID: <472F20CC.5060501@qumranet.com> (raw)
In-Reply-To: <200711051352.15366.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Sheng Yang wrote:
>
>>> return kvm;
>>> }
>>>
>>> diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
>>> index 42e7fad..89007b2 100644
>>> --- a/drivers/kvm/vmx.c
>>> +++ b/drivers/kvm/vmx.c
>>> @@ -1466,6 +1466,8 @@ static int alloc_apic_access_page(struct kvm *kvm)
>>> int r;
>>>
>>> r = -EFAULT;
>>> + if (kvm->apic_access_page)
>>> + return 0;
>>>
>> Racy, what if two vcpus are created simultaneously?
>>
>
> I think it is not racy, for BSP have been created before APs in sequence, and
> I am ensure only BSP(vcpu id=0) would call this.
>
>
That's true for qemu. But we have to be use malicious userspace can't
crash the kernel or leak memory using the kvm APIs.
>>> kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
>>> kvm_userspace_mem.flags = 0;
>>> kvm_userspace_mem.guest_phys_addr = 0xfee00000ULL;
>>> @@ -1584,7 +1586,8 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
>>> vmcs_writel(CR0_GUEST_HOST_MASK, ~0UL);
>>> vmcs_writel(CR4_GUEST_HOST_MASK, KVM_GUEST_CR4_MASK);
>>>
>>> - if (vm_need_virtualize_apic_accesses(vmx->vcpu.kvm))
>>> + if ((vmx->vcpu.vcpu_id == 0) &&
>>> + (vm_need_virtualize_apic_accesses(vmx->vcpu.kvm)))
>>> if (alloc_apic_access_page(vmx->vcpu.kvm) != 0)
>>> return -ENOMEM;
>>>
>> We may not have vcpu id 0 (though it's very unlikely).
>>
>
> Um... I am not quite understand when we will miss vcpu id 0. I think vcpu id 0
> is used to indicate BSP.
>
That's what qemu does. But another userspace perhaps will do this
differently.
This is a minor problem compared to the one above.
>
>> I think the problems arise because we are doing a VM-wide operation
>> (memory slot) from a vcpu context. I think adding a ->vm_create() arch
>> op and allocating the memory there will be better (under kvm->lock).
>>
>
> Agree, but a little problem remains.
>
> I have to do feature detection before call allocate function, but
> kvm_create_vm() is called before kvm_create_irqchip(). So I can't find a
> proper position for create_vm(). Any suggestion?
>
You're right, during vm creation we have no idea if we want the
FlexPriority page.
So you can do this in the same place, just take kvm->mutex and check if
it exists first (you need to do that anyway), no dependency on vcpu 0.
--
Any sufficiently difficult bug is indistinguishable from a feature.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
next prev parent reply other threads:[~2007-11-05 13:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-02 5:13 [PATCH] KVM: VMX: Fix repeatly calling alloc_apic_access_page() Sheng Yang
[not found] ` <200711021313.43013.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2007-11-04 7:46 ` Avi Kivity
[not found] ` <472D78CA.6080508-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-05 5:52 ` [PATCH] KVM: VMX: Fix repeatly calling alloc_apic_access_page () Sheng Yang
[not found] ` <200711051352.15366.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2007-11-05 13:55 ` Avi Kivity [this message]
2007-11-05 8:52 ` [PATCH] KVM: VMX: Fix repeatlycalling alloc_apic_access_page() Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A02557D41-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-11-05 13:58 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=472F20CC.5060501@qumranet.com \
--to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.