Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6702305imm; Tue, 24 Jul 2018 01:18:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfLaAVYKZS80UDU4mvmstvd7zfnQpjOVkemGF2OSklZJzGfMWNyjxC3oSYBwhau39we7vDr X-Received: by 2002:a63:291:: with SMTP id 139-v6mr15455904pgc.365.1532420304652; Tue, 24 Jul 2018 01:18:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532420304; cv=none; d=google.com; s=arc-20160816; b=bKwZJDuPUBDX0QzdOo1DTKibMfnyib4a4VgPTPDakSy6UpqSvxLkVz66bA2GJzGZN3 JEUwCgqp26xu3hmufe9fD0lWiOh3TDotHKB0IbwGXrjUhxNDPbqFlFBKdRANsJMDXd+c ko6w+kZh6YTPBvUewc6J1gadi/6p9HuswJ15f5NcROnWVlplTnqhvKEjS/kflcef6Y0s AhxFARwuQ0IEujmUxkD/Hgj1EBzrveCJxLOgPLbuTIljMP62LRWTLSbgkmqKijVwFKRW fsG22wZ8YXwZD0KsWUNHFrScgz4X4NVWUPY5ck+wJUd5N3G8gS3nK1sEY3HyoPpXG4di 7IIA== 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:message-id:date:thread-index:thread-topic:subject :cc:from:dkim-signature:arc-authentication-results; bh=S0jF1Axhq1uEgqsixELHtMmqB8hu0Lw/BN1/lx2rV7k=; b=dUbz/A27W+KO7jm5H6gP1gNJaeKRaHg7gplUa9Egibz60ayCVcGjSbDXrE8Lukgw/P lBjZSfKdhC4gx2SS/AckOj7SWTtJYcoFcGu3ogFTD/LmeIkgB+obhW3vKCnWx+QI55aH Zz2qlL0wY3373qZfilI+JpZiPp3H6FKxUtRRWgFpcrkqpD8Velcxrqxn/JN3pgAqN2ov 09RYRXK960IZY6BadNn/LOTIvo7sZAOz4VggIvx5/t3l736Zq6In2FONff5XAsz8jQ0M 4PLIOsllglJT0KdwU3IG496x7fmxf7t2vXjOJUS5z+v6bE7vO+s/lVxmB9f9AeM4ZBcC /8yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b="a9XE5xp/"; 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 i4-v6si10979093pgd.657.2018.07.24.01.18.08; Tue, 24 Jul 2018 01:18:24 -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="a9XE5xp/"; 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 S2388584AbeGXJWd (ORCPT + 99 others); Tue, 24 Jul 2018 05:22:33 -0400 Received: from mail-hk2apc01on0124.outbound.protection.outlook.com ([104.47.124.124]:26912 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388383AbeGXJWd (ORCPT ); Tue, 24 Jul 2018 05:22:33 -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=S0jF1Axhq1uEgqsixELHtMmqB8hu0Lw/BN1/lx2rV7k=; b=a9XE5xp/JFm7UULFw9PERtxpNfkBnRaYwax9idhi1aZqY2oGp8VpHfr++lDQ1z+C4Qd7RSExb29CwOySJgILc9OS88uf46sPkSezxXDFLtGSDVEp1VB8fjNKN0bhOf5GW1JVZlRXQvCD1MHL8LGbPQQCe2ReU6vy+cyPd+gzGps= Received: from SG2P15301MB0093.APCP153.PROD.OUTLOOK.COM (10.170.136.145) by SG2P15301MB0015.APCP153.PROD.OUTLOOK.COM (10.170.135.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.1; Tue, 24 Jul 2018 08:17:08 +0000 Received: from SG2P15301MB0093.APCP153.PROD.OUTLOOK.COM ([fe80::f916:a637:8730:be25]) by SG2P15301MB0093.APCP153.PROD.OUTLOOK.COM ([fe80::f916:a637:8730:be25%4]) with mapi id 15.20.1017.000; Tue, 24 Jul 2018 08:17:08 +0000 From: Tianyu Lan CC: Tianyu Lan , "pbonzini@redhat.com" , "rkrcmar@redhat.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte() Thread-Topic: [PATCH] KVM/MMU: Combine flushing remote tlb in mmu_set_spte() Thread-Index: AQHUIya2sfSO0xmUGUuqak4mr618Fw== Date: Tue, 24 Jul 2018 08:17:07 +0000 Message-ID: <1532420205-29930-1-git-send-email-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;SG2P15301MB0015;6:fS0jsWcoNrUUam17rNqT2DB8OGT/RN40FSNqdaMeExxbT8uI/09DgrKbAEK+mJWTFd6ZJkWS+p7O3/xgCUXU6hHN70EXvJ8SA3GQZ71ykpv7RDIkOeR4kXKtzknEd91Flo+VmjozMrwDJjiJV85hDit5gjDHKl6EFQ3XFOr/r6H7XxIIcobB3AvzdLmTyKZzUw9cS/1Few9GpdCSFZdpJ10xQuBT5AAsmqPs4NCAAnWADs5UhmuFtOGMlmHDTjWJiQK//0NXHrMMU0CkGTGguFOIgDx5aHJ41euCY7ss2Njy7hK9a6mCUi+PT+FLyNO7TsNaUma1OI3QtPl+X7soHTRZ9MPxCk2lTDj/sqRakHiAdHJdr0O84erAKepRhUAcBK4k5ncgU0ntuDcxTXEXMJtx1FHc4pZTbP2fxb2SRwPfEg6Ikpg0g6xqU6phmB6n9IjrSdIGxRdJjKRGWeDzgQ==;5:sjfvf8AvudryW6ILKRf+pP+nJJSt/MccF9XnhiMJNTwKCU2fLojmLkxNy2DOaLaoUaXFJqSLt5tjIyM9Iudi5hhmhOfzk5jH8rxDm0FLcCUPfwe67WYz4UCATzkLpll4vzWbYqbiWdZWKkSpBjOmh8kktWF2ga5MF9Oo4MTxLzo=;7:DsExfmdGHrP5tegYpxfWP6RnPnwgaSc6kVjOJnFb4UI2WQRx4xSD8e6qaDgTToppR/F+o9QaGJx8vOuJizNF6zmcHvFPvDiXW6mlGzDXH3LTg8rIXDWF/h1MQtEIa1G0HUuIj4ey4g7gq7J91A4xQyBZVgwRNB8xGzCb9iqfNwnAeI277os8JW0aTsEelkJusHB7+FmGkcRQMYJL2o/qStRfliHZlaHecc5dIF65zqA1V1CMsLYd3lZ7HYJxn0em x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 31684082-bfe5-4075-6f3e-08d5f13dd932 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600073)(711020)(4618075)(2017052603328)(7193020);SRVR:SG2P15301MB0015; x-ms-traffictypediagnostic: SG2P15301MB0015: 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)(3231311)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011)(7699016);SRVR:SG2P15301MB0015;BCL:0;PCL:0;RULEID:;SRVR:SG2P15301MB0015; x-forefront-prvs: 0743E8D0A6 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(136003)(39860400002)(396003)(376002)(346002)(199004)(189003)(8936002)(10290500003)(5660300001)(102836004)(2906002)(1857600001)(14454004)(26005)(478600001)(25786009)(99286004)(256004)(1671002)(8676002)(72206003)(53936002)(6116002)(105586002)(6486002)(68736007)(6506007)(81156014)(97736004)(54906003)(22452003)(316002)(3846002)(59246006)(36756003)(4326008)(2616005)(486006)(6512007)(476003)(10090500001)(5250100002)(106356001)(109986005)(81166006)(7736002)(66066001)(2900100001)(86612001)(14444005)(305945005)(6436002)(86362001);DIR:OUT;SFP:1102;SCL:1;SRVR:SG2P15301MB0015;H:SG2P15301MB0093.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: weBWPTcNc8LnMFvVlLiO5kMJQqB+9LpjqwKoIhH7pEGkuj+cqStv5R2fvMf5LGOpUflnii5KgYkWwqVXsV9U7dhoZknYkiwwm3VRXtntWEK0k18WLbyqQcUMZXa9eqyf2qDRqRUwcS5bbcNAoY+g8Nr1hBo0o9RcMPLRAg9G0cwupKQPMkeiot2w37IaFTJXtLctBgnA8Ge+7DlfD1gW0LMQGuFDHSWDrNEkkV7Jl0cu2x98yjuehGd5xj9kiFmNabXVM+ARk3fjoW2Tmt/kWv9cL/MhsYiCvvtsTnKTXDYK5r6ZVNIZcF/u4eCjo9d1QJ2ZMjCcvN5czJIX+IAgQAuHG8UvAwA9ceqlyXQpu7g= 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: 31684082-bfe5-4075-6f3e-08d5f13dd932 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jul 2018 08:17:07.7549 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2P15301MB0015 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 mmu_set_spte() flushes remote tlbs for drop_parent_pte/drop_spte() and set_spte() separately. This may introduce redundant flush. This patch is to combine these flushes and check flush request after calling set_spte(). Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 22a7984..8f21632 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *s= ptep, unsigned pte_access, int rmap_count; int set_spte_ret; int ret =3D RET_PF_RETRY; + bool flush =3D false; =20 pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__, *sptep, write_fault, gfn); @@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 = *sptep, unsigned pte_access, =20 child =3D page_header(pte & PT64_BASE_ADDR_MASK); drop_parent_pte(child, sptep); - kvm_flush_remote_tlbs(vcpu->kvm); + flush =3D true; } else if (pfn !=3D spte_to_pfn(*sptep)) { pgprintk("hfn old %llx new %llx\n", spte_to_pfn(*sptep), pfn); drop_spte(vcpu->kvm, sptep); - kvm_flush_remote_tlbs(vcpu->kvm); + flush =3D true; } else was_rmapped =3D 1; } @@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *s= ptep, unsigned pte_access, ret =3D RET_PF_EMULATE; kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); } - if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH) + if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH || flush) kvm_flush_remote_tlbs(vcpu->kvm); =20 if (unlikely(is_mmio_spte(*sptep))) --=20 2.7.4