Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1526950imm; Wed, 26 Sep 2018 20:51:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV62hoDf4mEnX3V3laPyoms2OsRmZCrcT6HCopwR1NFiHMGJGk20FOWFaymaMYgu0dPVDv+Os X-Received: by 2002:a62:565c:: with SMTP id k89-v6mr9098863pfb.212.1538020305778; Wed, 26 Sep 2018 20:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538020305; cv=none; d=google.com; s=arc-20160816; b=mfzYD+pcs6rG7sKwinY1vzIrLiS3omhWAWNmoivCWlDB/Km51IX1hmQ4nTPZqA8dVN O22s6IUt2XBiNxQStbvvfjXQ8i6qnp2pQEIejEd6tHzATYkyJK89z2RqgR1Tc78ghpuk NOnVU+h+YiY/2bADxZ6KqS+93fRr/LchpUHLbRuECMcR5tTooMbJnAPFArJc6aAtePqU tKQUdtX8cXTkey2wzM571Dmbx3OJSLauSzJn6uqAskdi1Oz0G1fs2upQTuEZ9PIhWQPS GOvcoyuvPcWJT2A7tgDa8SDMlGYALByzrN5eqGsjSaQoPdrmG41c4VJyA4io7sT81wnY HbCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:from:dkim-signature; bh=AlIm/wQ/SZgqpyNhzLcWF/CMv40EdanX/aX8d6oGa0o=; b=BPbgp9M9f5aVbMaLt//dU3SkQpr8YcAwqIpDPZ8s4fYESBMgtKQWM4zptPCaqzgSWv 9INH2SJpkzP+dyYPfXkUrRb+es34+q478w1ael5I1dyFUjYjGXKdq9d8/o/QXdm6EiaL 56iqgxVe3CK9Lpuf26Ok5wAsyMpVXOUs64wBA9AfzcMivvsR2aF55QqrDzkW4b8lMKgW Hm3ml2P0t1Y17H03fAE92gjn0qTc6CpVVXfYdJPwPqf2I/cGSeHsyknZOYafsJbXfRID oFpx/bB63Vpm3Z8MfwqBKa26I/97Ea9FMtmfMKf9XN/O7Q11vIQ99kMsBwqtmpCsuUiK V/hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=bDQkhJsT; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id az4-v6si760151plb.513.2018.09.26.20.51.31; Wed, 26 Sep 2018 20:51:45 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=bDQkhJsT; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727223AbeI0KFp (ORCPT + 99 others); Thu, 27 Sep 2018 06:05:45 -0400 Received: from mail-pu1apc01on0133.outbound.protection.outlook.com ([104.47.126.133]:32445 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726659AbeI0KFo (ORCPT ); Thu, 27 Sep 2018 06:05:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AlIm/wQ/SZgqpyNhzLcWF/CMv40EdanX/aX8d6oGa0o=; b=bDQkhJsTzoFuzlicChmgYbpdkapKnp0LKemI5sw4gUtUlXBKg3NtE77sfX4zBPYVltbDIspLIS66+iK1iuBGrvMduzohXRHtkjHOTorQcmrqgItDac33Qqne4almGqyHqqWBjthpNmfY7JX9dD2Q7Fe3b66T0ycTBS99UwaGdwg= Received: from HK0P153MB0129.APCP153.PROD.OUTLOOK.COM (52.133.156.18) by HK0P153MB0177.APCP153.PROD.OUTLOOK.COM (52.133.210.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.3; Thu, 27 Sep 2018 03:49:17 +0000 Received: from HK0P153MB0129.APCP153.PROD.OUTLOOK.COM ([fe80::8584:ad93:130a:6267]) by HK0P153MB0129.APCP153.PROD.OUTLOOK.COM ([fe80::8584:ad93:130a:6267%3]) with mapi id 15.20.1207.011; Thu, 27 Sep 2018 03:49:17 +0000 From: Tianyu Lan CC: Tianyu Lan , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "pbonzini@redhat.com" , "rkrcmar@redhat.com" , "devel@linuxdriverproject.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "Michael Kelley (EOSG)" , vkuznets , Jork Loeser Subject: [PATCH V3 5/13] KVM/MMU: Flush tlb directly in the kvm_zap_gfn_range() Thread-Topic: [PATCH V3 5/13] KVM/MMU: Flush tlb directly in the kvm_zap_gfn_range() Thread-Index: AQHUVhUQ4M/Jq/VbY0i+60xtcKOfTg== Date: Thu, 27 Sep 2018 03:49:17 +0000 Message-ID: <20180927034829.2230-6-Tianyu.Lan@microsoft.com> References: <20180927034829.2230-1-Tianyu.Lan@microsoft.com> In-Reply-To: <20180927034829.2230-1-Tianyu.Lan@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Tianyu.Lan@microsoft.com; x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;HK0P153MB0177;6:rWbq5efMtsiRlaaGjYV+IWq5JEcU2r5TDD+CC9qGtGTicHN0ujPVn7pyB2zNlIkWPGkAs5sQ6Fdv2yCFnF1HsS4T4g3bhB7pb2waeqJ3KPlvH9kIbDDIyK3oyhPcFDgscA2MhBS7+ztVaka+RVrWWmbznw60CXb6S0ZBhxq6CiWLN/TUXxu2JY9rm/JCfccDOKKNF0mI6zL7hcLN/f+8E52Y17CNiiXoznJ3DcKAOujI1FyDViuBS3ZPg95RuY9EKKKp0GlJmZtr2fbkstvDz+UII/9zjrF4OAGWpq/0YMNwF80+d7b8d2jXCUqK6KsKW4qtbODSD9WMn9L6hkcNit32RKs+fFTxtbAyElciHaejquINWIITms+0KRpuqUByw+O0XGjE+W2bX+NBHLa5xVpr7On5pzqZARBB7/2qz8/Ry470fBc/LQH7PQjNPnt8szbUe5UPAZtdtdfY0YSWcg==;5:6XeysVQgstTUFukl8vVtYxIr4GVtNzkbop3r933SWwWb7VkYM9GxDseqE9C0oYrxcRvQmtPE50KapNZYYzRueAbtFLdbDPgeb2D2tEIHy68xP/p1NTe7jM4J5fqefJP5L8rhQT/J+N2s+4jqk7TZ/LcWQKht9z7okUxuZYdYG6A=;7:nClr6GexManXUbzaXPl0fDW6KnrHsdRs5FvXSrQIVmToQ1NTeu7lY45nY2Q9UQN/IDvjJ6Z1EendETYRQlu1LM1hTA7b8BxSOwSyHNEMpd5dDoscN5SjknTF6+8+K9RX8dbwUF2+TVrHUkxgfaN3jt9NnkaSga1iQ63g4GmkFv8IdqXYZTrS0BfkfzdLYYfup7590tacg6dMutldTUk3LshEOE1QSOMqgFDuysQsSSLP+R/fj8jnfNCgwmrJ4rPN x-ms-office365-filtering-correlation-id: 411a4aa2-e235-439b-eb1a-08d6242c3328 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(2017052603328)(7193020);SRVR:HK0P153MB0177; x-ms-traffictypediagnostic: HK0P153MB0177: x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231355)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(6055026)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699051);SRVR:HK0P153MB0177;BCL:0;PCL:0;RULEID:;SRVR:HK0P153MB0177; x-forefront-prvs: 0808323E97 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(136003)(396003)(346002)(39860400002)(366004)(199004)(189003)(105586002)(99286004)(10290500003)(486006)(478600001)(68736007)(106356001)(14454004)(72206003)(81156014)(6486002)(8676002)(6506007)(1671002)(81166006)(6512007)(2900100001)(2906002)(6436002)(76176011)(8936002)(10090500001)(3846002)(6116002)(54906003)(36756003)(316002)(59246006)(102836004)(26005)(1076002)(5660300001)(5250100002)(109986005)(107886003)(11346002)(446003)(2616005)(4326008)(25786009)(476003)(22452003)(7416002)(53936002)(86612001)(86362001)(71190400001)(71200400001)(14444005)(66066001)(7736002)(256004)(305945005)(34290500001)(97736004);DIR:OUT;SFP:1102;SCL:1;SRVR:HK0P153MB0177;H:HK0P153MB0129.APCP153.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: NdD8alzHxOwrXplu1B31Oetso6lISqac5Q5FRxthh2eRoIvcaHqcU6rjexWG+PqCO0wPI8kD9iLxSlYwsuoq/imPrHkXudGXa14Lf0WltqHS6U13GyswDH/uBg9K3WMSxnE879yg2LWQg1PN2m1DGPZdCfAiUUG25/eVWOcIo8Xe3UHvJqCtY8R1vvvZTeqBEGWt9kq/e3f+sUTp98uzQ7VOKxJJU03nUrKoPVIADX8SM0YMSwIj7D+8sGbNF88gYyGquL4f67AfsvjjwmdVxPomauITvskb4D2+aBXJoeOeztBsPzWfKqLjWWj7Kj4p3aSTDWYZfqlnXghKUuxFxJNisvdFafF1Bp1wpLAymSg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 411a4aa2-e235-439b-eb1a-08d6242c3328 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Sep 2018 03:49:17.1311 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK0P153MB0177 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Originally, flush tlb is done by slot_handle_level_range(). This patch is to flush tlb directly in the kvm_zap_gfn_range() when range flush is available. Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 877edae0401f..f24101ef763e 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -5578,6 +5578,7 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_sta= rt, gfn_t gfn_end) { struct kvm_memslots *slots; struct kvm_memory_slot *memslot; + bool flush =3D false; int i; =20 spin_lock(&kvm->mmu_lock); @@ -5585,18 +5586,27 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_s= tart, gfn_t gfn_end) slots =3D __kvm_memslots(kvm, i); kvm_for_each_memslot(memslot, slots) { gfn_t start, end; + bool flush_tlb =3D true; =20 start =3D max(gfn_start, memslot->base_gfn); end =3D min(gfn_end, memslot->base_gfn + memslot->npages); if (start >=3D end) continue; =20 - slot_handle_level_range(kvm, memslot, kvm_zap_rmapp, - PT_PAGE_TABLE_LEVEL, PT_MAX_HUGEPAGE_LEVEL, - start, end - 1, true); + if (kvm_available_flush_tlb_with_range()) + flush_tlb =3D false; + + flush =3D slot_handle_level_range(kvm, memslot, + kvm_zap_rmapp, PT_PAGE_TABLE_LEVEL, + PT_MAX_HUGEPAGE_LEVEL, start, + end - 1, flush_tlb); } } =20 + if (flush && kvm_available_flush_tlb_with_range()) + kvm_flush_remote_tlbs_with_address(kvm, gfn_start, + gfn_end - gfn_start + 1); + spin_unlock(&kvm->mmu_lock); } =20 --=20 2.14.4