Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4950115ybg; Mon, 21 Oct 2019 17:40:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHPfxZzqmFcvCpw0yRyLchgzHIFdE/JowFInCthpPdblxotf0H5ZudVvePPrkDGOrmPMF4 X-Received: by 2002:aa7:d5d3:: with SMTP id d19mr27606692eds.213.1571704817607; Mon, 21 Oct 2019 17:40:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571704817; cv=none; d=google.com; s=arc-20160816; b=ighq9UoRO2WTD5wkz5lx2umDXRxJGORCCpbQrZhmmXiKvLzxTVjC7N8pSSsm15V2Mh JdbLEL4THNeTKU6vHpg9IDs4XbAL5YkhdxLvcm6Ew/mB2AeGeVhbaQbFw1mIcp//lqhj WfICwfR4hRGVEv+xdXC+fJKBG1n1RGfu21HGOSzhER3FCH/ZWl+DnxDgVdk5mpayKy9g dpzgmrLtnKGxgTi2wOzwRkTxV0OVJYITeVqarxRge7fj1bbWQgqdwKHLyaQn1A+O+NyA feMBQ7/QhCgpaA18HhZIAdgmPZ5WKlVB/8pk58rK5ww2aBT0D2oiUTUwR/9g8FYJaTXU kQjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=kAV9mZk31//PQSbhUzVS8GD/tO5sHc2vU0fyunyjyu4=; b=Lj9QcqfmYXUuLfNmVsAWoTIfUDaf5R2F62MuNmkm2mZ5MWV8TNhwiXDLoB2K20wPQw 7U+djEE+YAWGDhu6jJRXgwWiafJs5abnpW3sioD2xmjx+0hqjSyvtqtTTEX049GOUOqJ aNvKY3n6HIbY5wx/n/CKtjCvhta4ND1DWmtVg92UtEWgGvH6Um/+1fk+hwjtPQgah8Wr YK9Zf+pIPyFHRnQKMGMTFgAgu9jEvIJTIprF+xwS0vIOuy5nyxUCnxttLj6uBl0HfaXf AeSbgLj96GGCRTku6CYx25mKpGyOYw4VBo7f7j/Gqe59nXvu4I3cq54ocVcG+wVfOmHR Ag5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si10842926eda.129.2019.10.21.17.39.54; Mon, 21 Oct 2019 17:40:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730541AbfJVAfk (ORCPT + 99 others); Mon, 21 Oct 2019 20:35:40 -0400 Received: from mga07.intel.com ([134.134.136.100]:35281 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727953AbfJVAfk (ORCPT ); Mon, 21 Oct 2019 20:35:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Oct 2019 17:35:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,325,1566889200"; d="scan'208";a="348897196" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.41]) by orsmga004.jf.intel.com with ESMTP; 21 Oct 2019 17:35:38 -0700 From: Sean Christopherson To: James Hogan , Paul Mackerras , Christian Borntraeger , Janosch Frank , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Marc Zyngier Cc: David Hildenbrand , Cornelia Huck , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , James Morse , Julien Thierry , Suzuki K Poulose , linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: [PATCH v2 00/15] KVM: Dynamically size memslot arrays Date: Mon, 21 Oct 2019 17:35:22 -0700 Message-Id: <20191022003537.13013-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The end goal of this series is to dynamically size the memslot array so that KVM allocates memory based on the number of memslots in use, as opposed to unconditionally allocating memory for the maximum number of memslots. On x86, each memslot consumes 88 bytes, and so with 2 address spaces of 512 memslots, each VM consumes ~90k bytes for the memslots. E.g. given a VM that uses a total of 30 memslots, dynamic sizing reduces the memory footprint from 90k to ~2.6k bytes. The changes required to support dynamic sizing are relatively small, e.g. are essentially contained in patches 12/13 and 13/13. Patches 1-11 clean up the memslot code, which has gotten quite crusy, especially __kvm_set_memory_region(). The clean up is likely not strictly necessary to switch to dynamic sizing, but I didn't have a remotely reasonable level of confidence in the correctness of the dynamic sizing without first doing the clean up. Testing, especially non-x86 platforms, would be greatly appreciated. The non-x86 changes are for all intents and purposes untested, e.g. I compile tested pieces of the code by copying them into x86, but that's it. In theory, the vast majority of the functional changes are arch agnostic, in theory... v2: - Split "Drop kvm_arch_create_memslot()" into three patches to move minor functional changes to standalone patches [Janosch]. - Rebase to latest kvm/queue (f0574a1cea5b, "KVM: x86: fix ...") - Collect an Acked-by and a Reviewed-by Sean Christopherson (15): KVM: Reinstall old memslots if arch preparation fails KVM: Don't free new memslot if allocation of said memslot fails KVM: PPC: Move memslot memory allocation into prepare_memory_region() KVM: x86: Allocate memslot resources during prepare_memory_region() KVM: Drop kvm_arch_create_memslot() KVM: Explicitly free allocated-but-unused dirty bitmap KVM: Refactor error handling for setting memory region KVM: Move setting of memslot into helper routine KVM: Move memslot deletion to helper function KVM: Simplify kvm_free_memslot() and all its descendents KVM: Clean up local variable usage in __kvm_set_memory_region() KVM: Provide common implementation for generic dirty log functions KVM: Ensure validity of memslot with respect to kvm_get_dirty_log() KVM: Terminate memslot walks via used_slots KVM: Dynamically size memslot array based on number of used slots arch/mips/include/asm/kvm_host.h | 2 +- arch/mips/kvm/mips.c | 68 +--- arch/powerpc/include/asm/kvm_ppc.h | 14 +- arch/powerpc/kvm/book3s.c | 22 +- arch/powerpc/kvm/book3s_hv.c | 36 +- arch/powerpc/kvm/book3s_pr.c | 20 +- arch/powerpc/kvm/booke.c | 17 +- arch/powerpc/kvm/powerpc.c | 13 +- arch/s390/include/asm/kvm_host.h | 2 +- arch/s390/kvm/kvm-s390.c | 21 +- arch/x86/include/asm/kvm_page_track.h | 3 +- arch/x86/kvm/page_track.c | 15 +- arch/x86/kvm/x86.c | 100 ++--- include/linux/kvm_host.h | 48 +-- virt/kvm/arm/arm.c | 47 +-- virt/kvm/arm/mmu.c | 18 +- virt/kvm/kvm_main.c | 546 ++++++++++++++++---------- 17 files changed, 467 insertions(+), 525 deletions(-) -- 2.22.0