Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5130867iog; Wed, 22 Jun 2022 12:39:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sY/tIqGGPY/n2GqTt5eJNwPo/BVphg7h6NymHqud6OUlsEO+vx0QOQWVECt7ztTIN1bXzL X-Received: by 2002:a17:902:ebd1:b0:162:224f:abbb with SMTP id p17-20020a170902ebd100b00162224fabbbmr35220101plg.160.1655926792228; Wed, 22 Jun 2022 12:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655926792; cv=none; d=google.com; s=arc-20160816; b=ZkSzhV6HGlG/Sp7O2ZvTCoTbWizapIxAMoNTxKlwQg0qtfB4VSbQ2r7hO4gf04REMw dcPFZu+Tn1YAp7nnfP4BdAQXwdsINMkK95zwWavI1diTN1H3O2SHHzpVOl9RUHgiXLtM 9CaaENcs0xbQRpJlPEK8Cyt8uGeHTZhjgotQufpdrc29At0ccGI3lKSDEhMUT1RuxuKe H8nuxmfX3r9bVzQ20u8O7abPpXYxD+jfIkTts0+UXfyN3l3GcFwuZ8tzfEGux7nK8v4n 0dMxytYYWYBpZ2kQyhlHZkgt3pm2fGEVsIFnkspiCYqjVIvENdAT8dvAbTNHPY00FK0x 6zHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CLXhh2jHdU4NArrkTkPf5gXuXh+EDE9oNWeupQnPsQk=; b=qBltCYwjBScpIm5FK9sOtPT05jkknpWEf9Uu2QSqWKAR6ST/UrN4CY62qBDNLgD6k8 CtyltzDx8zdT1r+wm1Swwfg8UZjIC9tQUSuTPoK2CtOCwTVx2lZXJgHTlutNqgv81V/x razMojQTdy3gtLp24csjsv+K4cZe3BNo9zA3FYRAqmR2u45pOJVqq4+/BYtQUf9Gf+YM jtokW5ClAbU88YV6alZWi0VMEHr8iSloIkW9kpny7w1R0AShtP/4MKnyK5LpyCBNy5Qs 9gEw5mVR9fl1I0MN9CaDRq85o9JrFwl2+MpUwHaURr1wKLs8d9mVoasW8dP1zwHypXpa oiXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dVl/dbLV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a17090aa88a00b001e858850fbcsi444930pjq.50.2022.06.22.12.39.39; Wed, 22 Jun 2022 12:39:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dVl/dbLV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1356078AbiFVT3I (ORCPT + 99 others); Wed, 22 Jun 2022 15:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236619AbiFVT10 (ORCPT ); Wed, 22 Jun 2022 15:27:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EC9B23DA48 for ; Wed, 22 Jun 2022 12:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655926040; 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=CLXhh2jHdU4NArrkTkPf5gXuXh+EDE9oNWeupQnPsQk=; b=dVl/dbLVy0TEXut7U082Y0LRqU0D8R5bjU84YsP9ykCyAYQeAkQiwblzAp54h4KJ3jTMpo /KHH7dGEnVbuWR41VBeUCbhk2LjsY3k7BXl/PXXK6Y4t4D6YGpFSehLT5qvfZ3v5INrN4j WtlaEbO28wHBjdGJFSm7cdTCB80cQ+Y= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-4uDFGgT2PiWTMXu_E4ZL6Q-1; Wed, 22 Jun 2022 15:27:14 -0400 X-MC-Unique: 4uDFGgT2PiWTMXu_E4ZL6Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2430294EDC6; Wed, 22 Jun 2022 19:27:13 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B3AE1121314; Wed, 22 Jun 2022 19:27:13 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: maz@kernel.org, anup@brainfault.org, seanjc@google.com, bgardon@google.com, peterx@redhat.com, maciej.szmigiero@oracle.com, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, pfeiner@google.com, jiangshanlai@gmail.com, dmatlack@google.com Subject: [PATCH v7 07/23] KVM: x86/mmu: Consolidate shadow page allocation and initialization Date: Wed, 22 Jun 2022 15:26:54 -0400 Message-Id: <20220622192710.2547152-8-pbonzini@redhat.com> In-Reply-To: <20220622192710.2547152-1-pbonzini@redhat.com> References: <20220622192710.2547152-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Matlack Consolidate kvm_mmu_alloc_page() and kvm_mmu_alloc_shadow_page() under the latter so that all shadow page allocation and initialization happens in one place. No functional change intended. Signed-off-by: David Matlack Message-Id: <20220516232138.1783324-8-dmatlack@google.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/mmu.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index a59fe860da29..8b84cdd8c6cd 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1664,27 +1664,6 @@ static void drop_parent_pte(struct kvm_mmu_page *sp, mmu_spte_clear_no_track(parent_pte); } -static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, bool direct) -{ - struct kvm_mmu_page *sp; - - sp = kvm_mmu_memory_cache_alloc(&vcpu->arch.mmu_page_header_cache); - sp->spt = kvm_mmu_memory_cache_alloc(&vcpu->arch.mmu_shadow_page_cache); - if (!direct) - sp->gfns = kvm_mmu_memory_cache_alloc(&vcpu->arch.mmu_gfn_array_cache); - set_page_private(virt_to_page(sp->spt), (unsigned long)sp); - - /* - * active_mmu_pages must be a FIFO list, as kvm_zap_obsolete_pages() - * depends on valid pages being added to the head of the list. See - * comments in kvm_zap_obsolete_pages(). - */ - sp->mmu_valid_gen = vcpu->kvm->arch.mmu_valid_gen; - list_add(&sp->link, &vcpu->kvm->arch.active_mmu_pages); - kvm_mod_used_mmu_pages(vcpu->kvm, +1); - return sp; -} - static void mark_unsync(u64 *spte); static void kvm_mmu_mark_parents_unsync(struct kvm_mmu_page *sp) { @@ -2072,7 +2051,23 @@ static struct kvm_mmu_page *kvm_mmu_alloc_shadow_page(struct kvm_vcpu *vcpu, struct hlist_head *sp_list, union kvm_mmu_page_role role) { - struct kvm_mmu_page *sp = kvm_mmu_alloc_page(vcpu, role.direct); + struct kvm_mmu_page *sp; + + sp = kvm_mmu_memory_cache_alloc(&vcpu->arch.mmu_page_header_cache); + sp->spt = kvm_mmu_memory_cache_alloc(&vcpu->arch.mmu_shadow_page_cache); + if (!role.direct) + sp->gfns = kvm_mmu_memory_cache_alloc(&vcpu->arch.mmu_gfn_array_cache); + + set_page_private(virt_to_page(sp->spt), (unsigned long)sp); + + /* + * active_mmu_pages must be a FIFO list, as kvm_zap_obsolete_pages() + * depends on valid pages being added to the head of the list. See + * comments in kvm_zap_obsolete_pages(). + */ + sp->mmu_valid_gen = vcpu->kvm->arch.mmu_valid_gen; + list_add(&sp->link, &vcpu->kvm->arch.active_mmu_pages); + kvm_mod_used_mmu_pages(vcpu->kvm, +1); sp->gfn = gfn; sp->role = role; -- 2.31.1