From: Paolo Bonzini <pbonzini@redhat.com>
To: "Chen, Tiejun" <tiejun.chen@intel.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Cc: KVM list <kvm@vger.kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
jamie@audible.transient.net, Igor Mammedov <imammedo@redhat.com>
Subject: Re: [PATCH] kvm: fix to update memslots properly
Date: Tue, 10 Mar 2015 12:59:01 +0100 [thread overview]
Message-ID: <54FEDC85.8060002@redhat.com> (raw)
In-Reply-To: <54FE8C66.8020001@intel.com>
>>> This suggests another fix. We can change the insertion to use a ">="
>>> comparison, as in your first patch. Alone it is not correct, but we
>>> only need to take some care and avoid breaking the case of deleting a
>>> memslot.
>>>
>>> It's enough to wrap the second loop (that you patched) with
>>> "if (new->npages)". In the new->npages == 0 case the first loop has
>>> already set i to the right value, and moving i back would be wrong:
>>>
>>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>>> index f5283438ee05..050974c051b5 100644
>>> --- a/virt/kvm/kvm_main.c
>>> +++ b/virt/kvm/kvm_main.c
>>> @@ -687,11 +687,23 @@ static void update_memslots(struct kvm_memslots
>>> *slots,
>>> slots->id_to_index[mslots[i].id] = i;
>>> i++;
>>> }
>>> - while (i > 0 &&
>>> - new->base_gfn > mslots[i - 1].base_gfn) {
>>> - mslots[i] = mslots[i - 1];
>>> - slots->id_to_index[mslots[i].id] = i;
>>> - i--;
>>> +
>>> + /*
>>> + * The ">=" is needed when creating a slot with base_gfn == 0,
>>> + * so that it moves before all those with base_gfn == npages == 0.
>>> + *
>>> + * On the other hand, if new->npages is zero, the above loop has
>>> + * already left i pointing to the beginning of the empty part of
>>> + * mslots, and the ">=" would move the hole backwards in this
>>> + * case---which is wrong. So skip the loop when deleting a slot.
>>> + */
>>> + if (new->npages) {
>>> + while (i > 0 &&
>>> + new->base_gfn >= mslots[i - 1].base_gfn) {
>>> + mslots[i] = mslots[i - 1];
>>> + slots->id_to_index[mslots[i].id] = i;
>>> + i--;
>>> + }
>>> }
>>>
>>> mslots[i] = *new;
>>>
>>> Paolo
>>
>> Paolo,
>>
>> Can you include a proper changelog for this patch?
>>
>
> But this is already applied long time ago...
Yes, this is commit efbeec7098eee2b3d2359d0cc24bbba0436e7f21.
Paolo
prev parent reply other threads:[~2015-03-10 11:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-26 4:55 [PATCH] kvm: fix to update memslots properly Tiejun Chen
2014-12-27 20:41 ` Paolo Bonzini
2014-12-27 22:52 ` Jamie Heilman
2014-12-29 1:06 ` Chen, Tiejun
2015-03-09 20:54 ` Marcelo Tosatti
2015-03-10 6:17 ` Chen, Tiejun
2015-03-10 11:59 ` Paolo Bonzini [this message]
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=54FEDC85.8060002@redhat.com \
--to=pbonzini@redhat.com \
--cc=imammedo@redhat.com \
--cc=jamie@audible.transient.net \
--cc=kvm@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mtosatti@redhat.com \
--cc=tiejun.chen@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox