Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp66408imm; Fri, 10 Aug 2018 07:43:21 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzDo+t2YO0uyIFGrQMsLtey6zEg7FeyFdj5cfJTBpuzyTSz9nLSWRUdq9oDqfWFVHkuWa1A X-Received: by 2002:a17:902:5a82:: with SMTP id r2-v6mr6354227pli.315.1533912201252; Fri, 10 Aug 2018 07:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533912201; cv=none; d=google.com; s=arc-20160816; b=UHF3iO4O+lzHztFdSAr8jvvVwDDCzcpyDPeuaijzzQSLt1Ua2aPCTJIs5oWrdcAOzA yBcaX9bDHgVR6NeZsscnTptU/aYtZ5juvzv+SRttK7lVQEc/ZQm9CmZuo9QpK1vDyqMy 3L/32MBBFlVogmt9FZLL/CHzhZPTHRWHDV8xMRkZyB3q0bDZ3sqW2iZ4oTfDNhF+85hS EnzqRYPWOqaWcaRdIUnS5dtIMRS/jVHo28tn+icee8bYy+Zr80XJ5H1O8AzfKHDdGMGZ EMSoHoRFql0OQSu1Sl8f9ugx2PHD4ASwd+Kjaq+Xf5h4Uy6ejU7zGCDyMETyTLGr1R2R OYPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:organization:user-agent :references:in-reply-to:subject:cc:to:from:message-id:date :arc-authentication-results; bh=oRxpjnK2ZkqePDlDiYwhlRG3z4kwkPUHOrJfPxAO3Wc=; b=ctThWk6BMAvMvn6ulLDPHRcH8E4SfKphVqwABi687VI+mfXVDsy/bZjUd50Vue3MqX lp/kdvcjrtby6ClJPUtqL7PN0G/5ku3Rj9BrbT1ZF7dtrQ5yuehWECEqydS01CkJYNpx zShvVJ9G6MsseWbCSTTtSyYwvVkb1Kon9YgkzbAvPiYnwVgMN0ekP7XDg0+lItCiheXN WNSQPU0AUfErDQj0x/Xew6CmlEUm/kCQn44IOSWogwxTgHCXPMoMKa6XmSysWrtEMkC9 6JnMjIzawOQQMJChMstTOA3gnKASHI/jhtBz1ggZHNmms8S1IXQkCpoEyngmgN+UbSAb B+zw== 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 n11-v6si7696971plg.344.2018.08.10.07.42.53; Fri, 10 Aug 2018 07:43:21 -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 S1728153AbeHJRLN (ORCPT + 99 others); Fri, 10 Aug 2018 13:11:13 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:38504 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727519AbeHJRLN (ORCPT ); Fri, 10 Aug 2018 13:11:13 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DA0967A9; Fri, 10 Aug 2018 07:41:01 -0700 (PDT) Received: from big-swifty.misterjones.org (unknown [10.37.8.123]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 313FF3F6C4; Fri, 10 Aug 2018 07:41:00 -0700 (PDT) Date: Fri, 10 Aug 2018 15:40:57 +0100 Message-ID: <86mutup9mu.wl-marc.zyngier@arm.com> From: Marc Zyngier To: Punit Agrawal Cc: , , , Christoffer Dall , Suzuki Poulose Subject: Re: [PATCH] KVM: arm/arm64: Skip updating page table entry if no change In-Reply-To: <20180810111300.17144-1-punit.agrawal@arm.com> References: <20180810111300.17144-1-punit.agrawal@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/25.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: ARM Ltd MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Punit, On Fri, 10 Aug 2018 12:13:00 +0100, Punit Agrawal wrote: > > Contention on updating a page table 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. > > Signed-off-by: Punit Agrawal > Cc: Marc Zyngier > Cc: Christoffer Dall > Cc: Suzuki Poulose This definitely deserves a Cc to stable, and a Fixes: tag. > -- > Hi, > > This problem was reported by a user when testing PUD hugepages. During > VM restore when all threads are running cpu intensive workload, the > refauting was causing the VM to not make any forward progress. > > This patch fixes the problem for PMD and PTE page fault handling. > > Thanks, > Punit > > Change-Id: I04c9aa8b9fbada47deb1a171c9959f400a0d2a21 > --- > virt/kvm/arm/mmu.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c > index 1d90d79706bd..a66a5441ca2f 100644 > --- a/virt/kvm/arm/mmu.c > +++ b/virt/kvm/arm/mmu.c > @@ -1027,6 +1027,18 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache > VM_BUG_ON(pmd_present(*pmd) && pmd_pfn(*pmd) != pmd_pfn(*new_pmd)); > > old_pmd = *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; Shouldn't you take this opportunity to also refactor it with the above VM_BUG_ON and the below pmd_present? At the moment, we end-up testing pmd_present twice, and your patch is awfully similar to the VM_BUG_ON one. > + > if (pmd_present(old_pmd)) { > pmd_clear(pmd); > kvm_tlb_flush_vmid_ipa(kvm, addr); > @@ -1101,6 +1113,10 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, > > /* Create 2nd stage page table mapping - Level 3 */ > old_pte = *pte; > + /* Skip page table update if there is no change */ > + if (pte_val(old_pte) == pte_val(*new_pte)) > + return 0; > + > if (pte_present(old_pte)) { > kvm_set_pte(pte, __pte(0)); > kvm_tlb_flush_vmid_ipa(kvm, addr); Thanks, M. -- Jazz is not dead, it just smell funny.