Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3863396ybt; Tue, 23 Jun 2020 12:41:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeb+Yfn5jgM2I1mSGycwKoIu23wgyKlsOuJHneCfQFLLts6SbO3bNcd8VoIZAJqctVLnGM X-Received: by 2002:a17:906:6d4b:: with SMTP id a11mr22665983ejt.108.1592941317294; Tue, 23 Jun 2020 12:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592941317; cv=none; d=google.com; s=arc-20160816; b=T75fNzSAnuZ6epr3rO9dbmBtSCPyNTRvFdAfkzpIRMdF/TbjjKSoRgSn4ZrHbg1lL6 cRH+m5tkkhFSc5NHJphII7XjwVLTAVkDD3y5pRNSmpvfLpoXWdVcH/0v9jT3XhoHLJ0W 3uKPx3XMvP30MVIHU50FkGMhbXQQ+XM//btyud3zuUABLCvvNuvxjEye43JFa1R3184/ DjByr6+twpkWVHblhaDDs+nNWTQndAxiWWYBzzKf50XaDfixXz3rFPMk0BNjyRi06fYC r271N+v1+AD7yB5b+lESwzhmpaq2t2T05G8+ayJ4hDFrEpf7tjrHc/HjqGiBJK+ZXaWn P9sA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=h7IahZYHoPwH41IkthoOryT85qPUiDOOGeK83dUiQQc=; b=FrfdYdCCieo5OSBXRiVoAGcjWxsRlxWx+CVRqeS0VM9Ax2UBu4yVKwYI018PNV2Iaj GwlpF/Ea0GipDi/SJ8nixwVV82B4//YAJMvS2tcXw6y3l8jbD49+T1KjDMR/Z3ZsiG+7 xaKM91PaGNjvYyyvxQToHXtDbDYLqiJB4kSXJ0njqQeol+/nQqVp9cKYn/SQ11nq4veR geUprBD6U7fTALkmsgMO2cdtBwyHHWkdKT9rSUONublA6h0dD8vKn6J9vVJcrdkdDNlL UuLMk67sfEI1rmFNdl3v/xQcH406vbmpBvUXqh9ybfdnZcRg9kPJT0k4t2IeV8/EhjLZ byjQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si7281519edq.110.2020.06.23.12.41.33; Tue, 23 Jun 2020 12:41:57 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387584AbgFWTke (ORCPT + 99 others); Tue, 23 Jun 2020 15:40:34 -0400 Received: from mga06.intel.com ([134.134.136.31]:64955 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387552AbgFWTkd (ORCPT ); Tue, 23 Jun 2020 15:40:33 -0400 IronPort-SDR: 27dcbfEWvyUzYxD4UFoVGk5IKvgbvh7wqDC35wVAumvwtn18OxQZ+4ltKrgFfaSA8Uf/UPxGve MduHO7sn2CFA== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="205705218" X-IronPort-AV: E=Sophos;i="5.75,272,1589266800"; d="scan'208";a="205705218" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 12:40:29 -0700 IronPort-SDR: OxkCl1QTw9cXQdRJkueRV54wYK/yDLffHc0VHjfGjWwC06tlKrUIWsWCVA3h4m+jYwlKg79+T0 /92R18hTihhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,272,1589266800"; d="scan'208";a="319249372" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by FMSMGA003.fm.intel.com with ESMTP; 23 Jun 2020 12:40:29 -0700 From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Feiner , Jon Cargille Subject: [PATCH 2/2] KVM: x86/mmu: Optimize MMU page cache lookup for fully direct MMUs Date: Tue, 23 Jun 2020 12:40:27 -0700 Message-Id: <20200623194027.23135-3-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200623194027.23135-1-sean.j.christopherson@intel.com> References: <20200623194027.23135-1-sean.j.christopherson@intel.com> 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 Skip the unsync checks and the write flooding clearing for fully direct MMUs, which are guaranteed to not have unsync'd or indirect pages (write flooding detection only applies to indirect pages). For TDP, this avoids unnecessary memory reads and writes, and for the write flooding count will also avoid dirtying a cache line (unsync_child_bitmap itself consumes a cache line, i.e. write_flooding_count is guaranteed to be in a different cache line than parent_ptes). Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 67f8f82e9783..c568a5c55276 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2475,6 +2475,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, int direct, unsigned int access) { + bool direct_mmu = vcpu->arch.mmu->direct_map; union kvm_mmu_page_role role; struct hlist_head *sp_list; unsigned quadrant; @@ -2490,8 +2491,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, if (role.direct) role.gpte_is_8_bytes = true; role.access = access; - if (!vcpu->arch.mmu->direct_map - && vcpu->arch.mmu->root_level <= PT32_ROOT_LEVEL) { + if (!direct_mmu && vcpu->arch.mmu->root_level <= PT32_ROOT_LEVEL) { quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1; role.quadrant = quadrant; @@ -2510,6 +2510,9 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, if (sp->role.word != role.word) continue; + if (direct_mmu) + goto trace_get_page; + if (sp->unsync) { /* The page is good, but __kvm_sync_page might still end * up zapping it. If so, break in order to rebuild it. @@ -2525,6 +2528,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); __clear_sp_write_flooding_count(sp); + +trace_get_page: trace_kvm_mmu_get_page(sp, false); goto out; } -- 2.26.0