Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1827669imm; Mon, 3 Sep 2018 10:28:03 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY4+rDlt32K2n2Yyo9zKoDCcTa25hVcZ8H+E7htoJC9IY24As2227rfU//C4hdqRJc23o0S X-Received: by 2002:a17:902:7b83:: with SMTP id w3-v6mr29684591pll.192.1535995683424; Mon, 03 Sep 2018 10:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995683; cv=none; d=google.com; s=arc-20160816; b=RuT59oVnEEbfozZzm9h28Drulq+c5jy3oEV9pZ9RUU9Ke3W1PAjFuzLs0X1KWqK/Fm hJ25LMAf4Ze38AFjQjjmJJpFezr2fTV83ozIskiIGIog1J2yfFKX9wiMMHLpRasXSHTV xgcoXbCkqUOGfsOqK/OR2b5s582UCYEh6WUDB/GqPCUcGp3uwZK4oJIwMfbyEhxYAAAU LdK5HcExvL8X7sVcf2/62udl8rHmzLZO99If7hh1bheTpFBcTD7NWwUqflr9NGaPFUAu 5TYxyu2ScYRLGkoJPffDQWXKtx/rCF6Yj7DXZvtoOy3YfCRGLwdhE9eK9ah0+uX4ru9S V33A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=WhZnNQJp7uN6AXZwJdE2dih00CGT42V5eHQYZMzph7o=; b=dxzbLx33Ypd6egSmMbYwLYNrTQT3UDOY0GRrzaIOIWkR7Ghvo0y/oUEoKnvHNSlofN plOwolV3mOv10AB+2RBuJD7vRZ5Ok5iIjttTxijmdVeuoYjVoYPlFtC+6gISxxkHt+BC gLM+lpqOcLnPBdNO4J9x1a5uNGcEyD7mUP93Ll2OCULTNN2cXS5JPng+j8RexmsFrZc5 4IL0StbKjoBVj+dLoY+916QvCk4yHZyQbQsvdeD+SlmCud7YTPGGXH2thdwoUeJ4EDsm I9BZItA+E8IHib2BN7mrx1cBeMu1yHTtn6tl6uy38GpHcdqD2DTVFe030xv5sZUFqOXg CjYQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y27-v6si18823658pgc.152.2018.09.03.10.27.48; Mon, 03 Sep 2018 10:28:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730821AbeICVr3 (ORCPT + 99 others); Mon, 3 Sep 2018 17:47:29 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45888 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728541AbeICVr3 (ORCPT ); Mon, 3 Sep 2018 17:47:29 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 65CDFD24; Mon, 3 Sep 2018 17:26:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suzuki Poulose , Christoffer Dall , Punit Agrawal , Marc Zyngier Subject: [PATCH 4.14 100/165] KVM: arm/arm64: Skip updating PMD entry if no change Date: Mon, 3 Sep 2018 18:56:26 +0200 Message-Id: <20180903165700.534235079@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Punit Agrawal commit 86658b819cd0a9aa584cd84453ed268a6f013770 upstream. Contention on updating a PMD entry by a large number of vcpus can lead to duplicate work when handling stage 2 page faults. As the page table update follows the break-before-make requirement of the architecture, it can lead to repeated refaults due to clearing the entry and flushing the tlbs. This problem is more likely when - * there are large number of vcpus * the mapping is large block mapping such as when using PMD hugepages (512MB) with 64k pages. Fix this by skipping the page table update if there is no change in the entry being updated. Cc: stable@vger.kernel.org Fixes: ad361f093c1e ("KVM: ARM: Support hugetlbfs backed huge pages") Reviewed-by: Suzuki Poulose Acked-by: Christoffer Dall Signed-off-by: Punit Agrawal Signed-off-by: Marc Zyngier Signed-off-by: Greg Kroah-Hartman --- virt/kvm/arm/mmu.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -901,19 +901,35 @@ static int stage2_set_pmd_huge(struct kv pmd = stage2_get_pmd(kvm, cache, addr); VM_BUG_ON(!pmd); - /* - * Mapping in huge pages should only happen through a fault. If a - * page is merged into a transparent huge page, the individual - * subpages of that huge page should be unmapped through MMU - * notifiers before we get here. - * - * Merging of CompoundPages is not supported; they should become - * splitting first, unmapped, merged, and mapped back in on-demand. - */ - VM_BUG_ON(pmd_present(*pmd) && pmd_pfn(*pmd) != pmd_pfn(*new_pmd)); - old_pmd = *pmd; if (pmd_present(old_pmd)) { + /* + * Multiple vcpus faulting on the same PMD entry, can + * lead to them sequentially updating the PMD with the + * same value. Following the break-before-make + * (pmd_clear() followed by tlb_flush()) process can + * hinder forward progress due to refaults generated + * on missing translations. + * + * Skip updating the page table if the entry is + * unchanged. + */ + if (pmd_val(old_pmd) == pmd_val(*new_pmd)) + return 0; + + /* + * Mapping in huge pages should only happen through a + * fault. If a page is merged into a transparent huge + * page, the individual subpages of that huge page + * should be unmapped through MMU notifiers before we + * get here. + * + * Merging of CompoundPages is not supported; they + * should become splitting first, unmapped, merged, + * and mapped back in on-demand. + */ + VM_BUG_ON(pmd_pfn(old_pmd) != pmd_pfn(*new_pmd)); + pmd_clear(pmd); kvm_tlb_flush_vmid_ipa(kvm, addr); } else {