Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1833712imm; Mon, 3 Sep 2018 10:37:05 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb8XSjTn9rew9ajmyc+D+nt4gX9RQ+n+pbESdWgHwkzH2ebQLGApJwzvCHaF6BGQaKKmePB X-Received: by 2002:a62:47d1:: with SMTP id p78-v6mr30709703pfi.197.1535996225031; Mon, 03 Sep 2018 10:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996225; cv=none; d=google.com; s=arc-20160816; b=Ya/IPw2mpiEHTPRqFVpbfBhr4wQ419H5Ryn0YLSVpprUQwcQJ4Se5AyjRAooSeSpC3 S/io6SJCOIqiyDMosdrmLv6ApdfZ1pVfnUz9uucHoIpzjptrX9eBbd+7dYbYrL7PnuB9 BgKcbX/I2weY0gPb5AF47sVu4fvPnXPPlWx8fsxKNv8UrXZc4uUPHLAQPHfrb+qTqzI1 6+sL1SqhXdDMYlWyMGiJMMkszN10Qn0gagz3o8S5gxfdrOtrqAmyaaVwK03mU6BAPF3Z Gu2HK0ax6grD1zP/xx4SKSNYa1+SILLtlzxOQ9Aroztrq8lsDxaPfTBEB8ajcGV7TzKm 1XIA== 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=cdc69/95C6NHfwn3Z0MHPfScqGVUtpG7t1dzYpLET6c=; b=elh7+2rCxWMz7VBP1FRy2+qvGtI9VvO8i2kIN+izlQd6AMps/mkxen9XVZiN0Dao8k G01jVZ25sbfbMuh/SUm0acALWtKyLrIVRgQKRLgIbF6vmNEgsPYbhoxC6o82lTstxNEk pa7GWE7xG1WDE/vEHUHFwaP7KtY3l5/FrqS016mpDoFSQUYFeZsYhnryFNnRz6OFtorm HSKRCDbs3iLUl7xnJxFLKKEuDBDtlZYZzcO8CmgzeStq0ZnVM12bsz8JOFU/+ChaB7+d cZRkdWz64EcmqxRNS8/TwhcYfPMVsi+lKZL5Uo5wIQNLmXFgh1K54PCNXykCPMtNqXKE wxdw== 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 w10-v6si15804996pgh.342.2018.09.03.10.36.50; Mon, 03 Sep 2018 10:37:05 -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 S1731504AbeICV4f (ORCPT + 99 others); Mon, 3 Sep 2018 17:56:35 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47998 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727972AbeICV4e (ORCPT ); Mon, 3 Sep 2018 17:56:34 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 93717D1B; Mon, 3 Sep 2018 17:35:24 +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.18 035/123] KVM: arm/arm64: Skip updating PMD entry if no change Date: Mon, 3 Sep 2018 18:56:19 +0200 Message-Id: <20180903165720.971781432@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@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.18-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 @@ -1015,19 +1015,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 {