From patchwork Wed Sep 26 07:58:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 10615385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CD0315E8 for ; Wed, 26 Sep 2018 07:59:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 442082A45D for ; Wed, 26 Sep 2018 07:59:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 373A32A468; Wed, 26 Sep 2018 07:59:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACA7D2A463 for ; Wed, 26 Sep 2018 07:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727015AbeIZOLC (ORCPT ); Wed, 26 Sep 2018 10:11:02 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45191 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeIZOLC (ORCPT ); Wed, 26 Sep 2018 10:11:02 -0400 Received: by mail-pg1-f196.google.com with SMTP id t70-v6so8705621pgd.12 for ; Wed, 26 Sep 2018 00:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=b1MLhdCJ1we2s6/YWLYta+CYJ2hZ26fVDD4M7VaBh70=; b=RYZOdN3XzU19YXrH7/nn5Unuc4m3X04Yn0wRhCOUGc0SPzYcB5jX0nBtP0yYAjtqPm ghBdvHtH0dmSNrttLSjg/VZUUWAZLKI/ZZU35kAYNH12TqvOslrRuRJ/u7YF44K4+zKE Dbn7BweFH3JtfddzsvA3FQHmVwi0+fbo90ayhm5gF5wQeOEy1aqBeG+CqExCY/HER8Hm f9p0DRbM8RXHhpDaj1a6RBerQdzexLge2JUAMZ2svNPdvx5noBsyFHUGfnVYZ9H/IfBx t/JcAU6jeUU4h5cUVUK6mEVb+3cjblEOInGkbNFolaTCgR/I0PAMloxVk9iEekiN22tx G9dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=b1MLhdCJ1we2s6/YWLYta+CYJ2hZ26fVDD4M7VaBh70=; b=DQmrpiVicIuC962uCnujM0p+xgl0F/4eyEhevY0o+1tC14z5KUGuGv0ONK911osYYv EjLphPbs+iSFAzg9y3UM769WnTPah7V+aHg61+LPqfplT/NvBUmmEK4RQy4D9ZXEbywx Rmietlpu3OJnDTatUTKu1Gw4jakuIsll9PSN0AoVzb22wOuqzBJMcXL68gpC9x135CXU 4vnu3nv1P6JvVm+Lvu7Je1xWLVY7Sm52ICa5dB0gHl6QlukD/+QE4hDISB3jMjWiID/2 Fs8qlyNEI3zfXZkJZO7j56g+xw8IxvZqlAutG2m2pH/UzKTYBITL3OZiboalzVELeL+9 WSTw== X-Gm-Message-State: ABuFfojUx4rE28WrPWMyh34zpBXM0NrnaPyi5R2l24VrSnWvmGVTSjHh xLVXaJ+jkOPRNwh30Tu5sQc= X-Google-Smtp-Source: ACcGV61dQ5+dZFsoYlN+a7AZz+84gqocqSUX6k1/B82HjYmwlBYlOKTetgYbaxIF8ANKsxPtvDiDmg== X-Received: by 2002:a62:174a:: with SMTP id 71-v6mr4978609pfx.217.1537948762009; Wed, 26 Sep 2018 00:59:22 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id k23-v6sm5416382pgl.42.2018.09.26.00.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Sep 2018 00:59:21 -0700 (PDT) From: Wei Yang To: pbonzini@redhat.com, rkrcmar@redhat.com Cc: x86@kernel.org, kvm@vger.kernel.org, Wei Yang Subject: [PATCH] KVM: x86: introduce drop_spte_fast() when caller knows rmap_head Date: Wed, 26 Sep 2018 15:58:53 +0800 Message-Id: <20180926075853.28715-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP rmap_remove() would remove the sptep after locating the correct rmap_head. While in several cases, the caller has already known the correct rmap_head. This patch introduce drop_spte_fast() which remove sptep directly from rmap_head by pte_list_remove(). Signed-off-by: Wei Yang --- arch/x86/kvm/mmu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 371d200ffd4a..9fa77aa24fc7 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1412,6 +1412,13 @@ static u64 *rmap_get_next(struct rmap_iterator *iter) for (_spte_ = rmap_get_first(_rmap_head_, _iter_); \ _spte_; _spte_ = rmap_get_next(_iter_)) +/* In case caller knows the rmap_head, just remove it by pte_list_remove() */ +static void drop_spte_fast(struct kvm_rmap_head *rmap_head, u64 *sptep) +{ + if (mmu_spte_clear_track_bits(sptep)) + pte_list_remove(sptep, rmap_head); +} + static void drop_spte(struct kvm *kvm, u64 *sptep) { if (mmu_spte_clear_track_bits(sptep)) @@ -1669,7 +1676,7 @@ static bool kvm_zap_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head) while ((sptep = rmap_get_first(rmap_head, &iter))) { rmap_printk("%s: spte %p %llx.\n", __func__, sptep, *sptep); - drop_spte(kvm, sptep); + drop_spte_fast(rmap_head, sptep); flush = true; } @@ -1705,7 +1712,7 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head, need_flush = 1; if (pte_write(*ptep)) { - drop_spte(kvm, sptep); + drop_spte_fast(rmap_head, sptep); goto restart; } else { new_spte = *sptep & ~PT64_BASE_ADDR_MASK; @@ -5598,7 +5605,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm, if (sp->role.direct && !kvm_is_reserved_pfn(pfn) && PageTransCompoundMap(pfn_to_page(pfn))) { - drop_spte(kvm, sptep); + drop_spte_fast(rmap_head, sptep); need_tlb_flush = 1; goto restart; }