Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1810470imm; Mon, 3 Sep 2018 10:02:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbN/2PsH1xOpJll4kq/eVYiKSqtpmzEuR4eEsCZUpHi4NlNdESVYe7Xy6t4Yhacoc3BioE4 X-Received: by 2002:a63:ef4f:: with SMTP id c15-v6mr26789216pgk.368.1535994133539; Mon, 03 Sep 2018 10:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535994133; cv=none; d=google.com; s=arc-20160816; b=S+uqs/ULpUj3jOfsHpStqGUg031ydQJZZZ1QKSnMVYyCnLjWrrGQ/wD9VIhnBug9L4 Iyxq7KTg0x05FMJ08toZDYhyIV5q8gWsGP/3RCQb3+XuaPGn5NhZYaw03YnAdyYl43f6 DsBjLmIUYn8jEvz27u5vf4vd48MQia4BBxg0z1iv++/erlREy4xdFR4Jc0k4KUOV+9wK 13oTHzvhbUeTcMsU8uUXgv3DcOAZMWbPdukQAIhKQKtRE9KXn291VaqhMEFVYcXCBJrY xJolleXUqLiSnQKu/sJ2hu+E6zJa7igk1CviLLsYa0tuvNxSAwNPy/gMHhIAA6Gt8Z3i woTA== 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=eh/PHCQLFzuAjrgaONeFLrMliKNUb9z9MQIkpvw6W3Q=; b=JWuSfLon4cU8fvklWxtEgEtUl2wBzU/UhU+naM//ISXdyImJvOKF7KZ99XosvtoHmM XU9x4VW6O/fUtjUSiEAeR5SxrBUPKRaZ4ieszp5nnakHRKVcEmQZbTxDXsv17uXAOsap 7ZP7BDnAENJefMD4RNTcYELQaaF/U6joCxT08jzV4RuVIYx3MtSB5y6UYq4XhLTtIemG zXLifgh+QyvAvmk48QW244Fo0i0KlXYGvIdRR8GqUlp/pd6jF+/MdB7yG8tOhhlCig+J vawyX0lxePjUAew2T1cNxBFkVmKBQwz3pICZcgzuuCGnvmp437V+ATtX9UpCGQWlmwZq Wy8A== 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 l5-v6si18314506pff.304.2018.09.03.10.01.58; Mon, 03 Sep 2018 10:02:13 -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 S1728489AbeICVVx (ORCPT + 99 others); Mon, 3 Sep 2018 17:21:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38592 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbeICVVw (ORCPT ); Mon, 3 Sep 2018 17:21:52 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7D537CFB; Mon, 3 Sep 2018 17:00:52 +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.4 52/80] KVM: arm/arm64: Skip updating PMD entry if no change Date: Mon, 3 Sep 2018 18:49:30 +0200 Message-Id: <20180903164936.226916392@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903164934.171677301@linuxfoundation.org> References: <20180903164934.171677301@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.4-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 --- arch/arm/kvm/mmu.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -892,19 +892,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 {