Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2930781pxy; Mon, 3 May 2021 11:08:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwutfAZ6ojAmfNLfqoyYfQdkCoISlqo55zRmx0eIJaBxvrd7IExXFlwciW5K19ooTP4sQsa X-Received: by 2002:a17:902:7b92:b029:eb:6fc0:39e6 with SMTP id w18-20020a1709027b92b02900eb6fc039e6mr21473655pll.83.1620065300247; Mon, 03 May 2021 11:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620065300; cv=none; d=google.com; s=arc-20160816; b=C57aDOzscCVWL/0DimCsgTc657nRpP/Sp2Ezanpi0HME8wpu/ATrWDnpjDMgquPmLH f4GtJX/fczGYTj54fJM2VcX6zjxXgM1DkOB5YnFPYkB/t7dUMR5pudoXXA3tX9LPO1yG Awz+oRILDtp+EOA439k5ubr6/OhyHWGgbgATxgnHl72dKzmAXg1rQDZxLbgKI1r7tqT1 rlWXxMUHu9UnJmKeIgS2l3vI1co6d2R9HVftRYiEAVy47WWW/bLYsWFGh/pgSBImCexi bj4EIqyJHP0AQcOrkrGLasl30ZmdnfCBWmcTBE4bK8vpyzL0bl86Swfja5U6Z10xmWFj f54A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=VzRlOpLcca7V9AiLT0iCFq770kJqp+Mv325CWJzR+JQ=; b=iuy18myN1dbGOA2Qjqh42twCo7xKdTvWqlfthoHJZWVCBUv6qqCISITAoQw396Z/Q4 lUrcUVIoKu417XOZXznGlfUpvowSkuNJIV4SfcMKVx34RUUQichJfWqkapoQ87mrhHi6 oz/W7vAjgBplX+/qWQUzyd+CC1qopcjILVZk9Txn9HvgH5zTvdPiU/1YnhCFTyZ2rpmy oIRBlGMOYkmHzxNZCJGawus3iKEGDBvpUQZjzeh31bUOlwhcIsUryBUTTIdtELfuKC58 S4ZT1O6UklRWvxfK8Dsmkotc3O61kPuSRfbYnK6Fi2NpaIGaL/RUTRyxmLPvYeGUnkKi T+Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T2AEhpHb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si392489pgs.448.2021.05.03.11.07.58; Mon, 03 May 2021 11:08:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T2AEhpHb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234404AbhECNpz (ORCPT + 99 others); Mon, 3 May 2021 09:45:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42322 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233159AbhECNpy (ORCPT ); Mon, 3 May 2021 09:45:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620049500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VzRlOpLcca7V9AiLT0iCFq770kJqp+Mv325CWJzR+JQ=; b=T2AEhpHbwZR0lnuAcmmCdY0Dxjy1eMoD8b4vxo4HyyAYJAAiBBNqNgod3oWaR8vYDFLr6b kHKiw6YIcCFapWCNz1Uzz8QJrEqTHI5z6P7fAM/5AOS8AflRIKPXHw/cimmgVuLU+kTNlK bcSd2wGyyvrrp88o9Ti4tWDLV9I8FNs= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-499-PVZXzPlnMNmhH2B5I5jZjA-1; Mon, 03 May 2021 09:44:59 -0400 X-MC-Unique: PVZXzPlnMNmhH2B5I5jZjA-1 Received: by mail-ej1-f69.google.com with SMTP id h9-20020a1709063c09b0290393e97fec0fso2042494ejg.13 for ; Mon, 03 May 2021 06:44:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=VzRlOpLcca7V9AiLT0iCFq770kJqp+Mv325CWJzR+JQ=; b=QqUmCDYR0EAq6QcDbkumrknUE5J8eAuhEcCLNH315ud48J4ZmeTganJecFSQP5RYCb RaXUj7yMSmVRI7yARwsYi59CrT7GCFueQLjWJWa65exE+u6qUpbpfC7VwawKv9Gj1GUz 65XK02lrPrgJWD8VRMAJLGEtB+iUyb8CTYu/r81ILHjC+SjsXr9eSlSn2FAOujFpt7dL OHnDVg1i47XB2+WZCONYRP5pKalXwBgsyeGmmQ/qjq9CCalbFqp0L3aoevtoK//SyVX2 NhtwVf+xfn0y3XgYyElC6ykwIXhxKNu/DEBOyUPatyQN/ALZ6VjT4kccLh7Lhl5mg3yz KRHA== X-Gm-Message-State: AOAM532AeefAOu3lp+wiUCse8hdUmjkbtd5fmcAnGL2gJdvB7zABCN8/ 86TjThosTmvACVoEIMnXq2jgt1EYcKFbECsHt9fhHnsvW5I+wi5FuQ4yCSn5xbeMN3SS3FDENtu 7Mn+lGYd+xfnCGswugiZIKpX/ X-Received: by 2002:a17:906:6717:: with SMTP id a23mr2384450ejp.502.1620049498224; Mon, 03 May 2021 06:44:58 -0700 (PDT) X-Received: by 2002:a17:906:6717:: with SMTP id a23mr2384423ejp.502.1620049497997; Mon, 03 May 2021 06:44:57 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id e4sm11027186ejh.98.2021.05.03.06.44.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 May 2021 06:44:57 -0700 (PDT) Subject: Re: [PATCH v2 0/7] Lazily allocate memslot rmaps To: Ben Gardon , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Peter Xu , Sean Christopherson , Peter Shier , Junaid Shahid , Jim Mattson , Yulei Zhang , Wanpeng Li , Vitaly Kuznetsov , Xiao Guangrong References: <20210429211833.3361994-1-bgardon@google.com> From: Paolo Bonzini Message-ID: Date: Mon, 3 May 2021 15:44:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210429211833.3361994-1-bgardon@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/04/21 23:18, Ben Gardon wrote: > This series enables KVM to save memory when using the TDP MMU by waiting > to allocate memslot rmaps until they are needed. To do this, KVM tracks > whether or not a shadow root has been allocated. In order to get away > with not allocating the rmaps, KVM must also be sure to skip operations > which iterate over the rmaps. If the TDP MMU is in use and we have not > allocated a shadow root, these operations would essentially be op-ops > anyway. Skipping the rmap operations has a secondary benefit of avoiding > acquiring the MMU lock in write mode in many cases, substantially > reducing MMU lock contention. > > This series was tested on an Intel Skylake machine. With the TDP MMU off > and on, this introduced no new failures on kvm-unit-tests or KVM selftests. Thanks, I only reported some technicalities in the ordering of loads (which matter since the loads happen with SRCU protection only). Apart from this, this looks fine! Paolo > Changelog: > v2: > Incorporated feedback from Paolo and Sean > Replaced the memslot_assignment_lock with slots_arch_lock, which > has a larger critical section. > > Ben Gardon (7): > KVM: x86/mmu: Track if shadow MMU active > KVM: x86/mmu: Skip rmap operations if shadow MMU inactive > KVM: x86/mmu: Deduplicate rmap freeing > KVM: x86/mmu: Factor out allocating memslot rmap > KVM: mmu: Refactor memslot copy > KVM: mmu: Add slots_arch_lock for memslot arch fields > KVM: x86/mmu: Lazily allocate memslot rmaps > > arch/x86/include/asm/kvm_host.h | 13 +++ > arch/x86/kvm/mmu/mmu.c | 153 +++++++++++++++++++++----------- > arch/x86/kvm/mmu/mmu_internal.h | 2 + > arch/x86/kvm/mmu/tdp_mmu.c | 6 +- > arch/x86/kvm/mmu/tdp_mmu.h | 4 +- > arch/x86/kvm/x86.c | 110 +++++++++++++++++++---- > include/linux/kvm_host.h | 9 ++ > virt/kvm/kvm_main.c | 54 ++++++++--- > 8 files changed, 264 insertions(+), 87 deletions(-) >