From patchwork Wed Feb 15 22:00:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9575185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 94B3560493 for ; Wed, 15 Feb 2017 22:01:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 853EB28552 for ; Wed, 15 Feb 2017 22:01:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A3C328556; Wed, 15 Feb 2017 22:01:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15DF428555 for ; Wed, 15 Feb 2017 22:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752730AbdBOWBM (ORCPT ); Wed, 15 Feb 2017 17:01:12 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34712 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751702AbdBOWBK (ORCPT ); Wed, 15 Feb 2017 17:01:10 -0500 Received: by mail-wm0-f68.google.com with SMTP id c85so427803wmi.1; Wed, 15 Feb 2017 14:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=qXQ0WSGEifUeQiPU78M3J1HxV2j6gC2995disHayZV8=; b=S0JJEmJKcJgBzX3ryCxmEdeT4VDWlA/Yrt8j7F6/GVNLLOmJpnccBlORVMas/P+Q85 fnoW6gQ71z7/7iU1l2wfc58KgudT+/TMNugBWuSfwuP8OUqUtKVG5ti2rzTQFjgxz00I DMJ7LESz1uXXOVIR5cA3sIHVIMFVtD0iCbPTlfQQl6ZP13Q3XRLPoLUX5vC8GAyqizKb 17wgCWHvI8ibIb7ATu9nr/0RgFT0JWFfSEHKXbF2FSSNhddzu1HIYtIbhmOsIgrO90di yEQ/o5ZVic57TDFKuYgdIU5oC/jah1xuYGhdJ2/AiUdpmV6RIUY2UypPabLLHasaVm5N CBRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=qXQ0WSGEifUeQiPU78M3J1HxV2j6gC2995disHayZV8=; b=dlH5VLnrX1JkC2ertqPRVjuNS5Kdehvrkn599IQLIBP7gEeQ3FVOijW05wnAaapDoT Nuy3lmsLViUsRqCuUECfa/Gye5GO8bU7AMqaJkh/0IvtEr5fliXFFrK9p5l3bUHiDHPW wBCO9mt1IvukdJ7TV/cwxR5Cb0rgBGhQvYJcrSfbJSAF9tFoLY6HQrY4wugjLSwrU6VA j3UJnYrS05+qINFVoJ1jwPvdF47aFKh6w/S+zw26L6STdmnO+3pY99QvuW0gwJO40C6z 3zDml2R8BjWRPTbwYlcfdKss7h03ccbAOonzJXiOkdCPgq5W3EPqd4SEwWj9sWfWYBtq nxqg== X-Gm-Message-State: AMke39kX9aO2vrah+a5EqDxsH6rJYwT2/sSZPGi5x9rP9HmXPrqPB7/iAEifQOz1eQkUXA== X-Received: by 10.28.197.77 with SMTP id v74mr10411536wmf.30.1487196049184; Wed, 15 Feb 2017 14:00:49 -0800 (PST) Received: from donizetti.lan (94-39-187-56.adsl-ull.clienti.tiscali.it. [94.39.187.56]) by smtp.gmail.com with ESMTPSA id p49sm6462161wrb.10.2017.02.15.14.00.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Feb 2017 14:00:48 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 2/3] KVM: use separate generations for each address space Date: Wed, 15 Feb 2017 23:00:47 +0100 Message-Id: <20170215220048.3423-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170215220048.3423-1-pbonzini@redhat.com> References: <20170215220048.3423-1-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will make it easier to support multiple address spaces in kvm_gfn_to_hva_cache_init. Instead of having to check the address space id, we can keep on checking just the generation number. Signed-off-by: Paolo Bonzini Reviewed-by: Radim Krčmař --- virt/kvm/kvm_main.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e21bac7ed5d3..a83c186cefc1 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -506,11 +506,6 @@ static struct kvm_memslots *kvm_alloc_memslots(void) if (!slots) return NULL; - /* - * Init kvm generation close to the maximum to easily test the - * code of handling generation number wrap-around. - */ - slots->generation = -150; for (i = 0; i < KVM_MEM_SLOTS_NUM; i++) slots->id_to_index[i] = slots->memslots[i].id = i; @@ -641,9 +636,16 @@ static struct kvm *kvm_create_vm(unsigned long type) r = -ENOMEM; for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { - kvm->memslots[i] = kvm_alloc_memslots(); - if (!kvm->memslots[i]) + struct kvm_memslots *slots = kvm_alloc_memslots(); + if (!slots) goto out_err_no_srcu; + /* + * Generations must be different for each address space. + * Init kvm generation close to the maximum to easily test the + * code of handling generation number wrap-around. + */ + slots->generation = i * 2 - 150; + rcu_assign_pointer(kvm->memslots[i], slots); } if (init_srcu_struct(&kvm->srcu)) @@ -870,8 +872,14 @@ static struct kvm_memslots *install_new_memslots(struct kvm *kvm, * Increment the new memslot generation a second time. This prevents * vm exits that race with memslot updates from caching a memslot * generation that will (potentially) be valid forever. + * + * Generations must be unique even across address spaces. We do not need + * a global counter for that, instead the generation space is evenly split + * across address spaces. For example, with two address spaces, address + * space 0 will use generations 0, 4, 8, ... while * address space 1 will + * use generations 2, 6, 10, 14, ... */ - slots->generation++; + slots->generation += KVM_ADDRESS_SPACE_NUM * 2 - 1; kvm_arch_memslots_updated(kvm, slots);