Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2938607imm; Mon, 13 Aug 2018 03:13:32 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxdqvUB6wvNeEbcV0AetYmbZAIMZvM/GKTPq2FSxpqNUf1bpus4SKqIswbDXjV1JaSpDU7m X-Received: by 2002:a63:3f05:: with SMTP id m5-v6mr16159557pga.51.1534155212040; Mon, 13 Aug 2018 03:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534155212; cv=none; d=google.com; s=arc-20160816; b=NuX4APGSz9eOWo+Yo6FANA9Ybv7m6bAK4ejtkLHCvLU0kpDpZm2P9C70we+3b3ZzHB tkHwKV0xXqXwOUe1z/RAp+iizbFjJAdhJxkfGdq5pCD25DJ1/eR2eA+orP9qdl4o5C1m crOie0MZqHJ0fl6SkXzDrn7lKbSqrh4X0pouK61HLVqDUexxdjwVx/BerrGdl+iNPMOc b2DoXc2PJdqLEiE4CsNUp2CVIO14Hch1BLokE43cqqH5stZr9BsECvpdUA9MqxSSDD4W NOcnln0AHBbTkl7d4IExUi9Sc2cEJTnU93wwz6dnYRccALrK61NzWqJGJdzdve3rGnxB 9VKg== 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:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=LJQPUogKV14MiWQae1anrpx0Sz6cERPLeMzxc7r211U=; b=yKa16rt2sRwKZ0ubjWmx5JSWM9ue0t0jYezCumdzNajvNwbVIQ/l5Bt8YfMLisNxo3 BSliFkLbQMJzaTvQkj9bq5lPOToispo60CPN5/0Hu3y9YnlHbrgTJb2PbFLlBEnhpAsF dfgWdqt2GCmuhBAi1H8YM9MkjgDhv1Xmdo+mSI81RAIMKqAMY6Nqsa0+0vQmz4N3hsBw BsDEAp5+cXG24iZVSxmwi9abznBCobEnJ24fxoB6qJtvwShpBzYQzOnftr4p/P2qcuw7 PMzTR5gnjAel0Nr7lGNrUqxpsZ2rqor82LcuURoIMUnv7pZX4uOgj9FglR5RguQGyeSu urcg== 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 v11-v6si13392204plp.33.2018.08.13.03.13.17; Mon, 13 Aug 2018 03:13:32 -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 S1728733AbeHMMnC (ORCPT + 99 others); Mon, 13 Aug 2018 08:43:02 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:56302 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728310AbeHMMnC (ORCPT ); Mon, 13 Aug 2018 08:43:02 -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 1DC3F15A2; Mon, 13 Aug 2018 03:01:29 -0700 (PDT) Received: from localhost (e105922-lin.emea.arm.com [10.4.13.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 927523F73C; Mon, 13 Aug 2018 03:01:28 -0700 (PDT) From: Punit Agrawal To: Suzuki K Poulose Cc: kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 1/2] KVM: arm/arm64: Skip updating PMD entry if no change References: <20180813094049.3726-1-punit.agrawal@arm.com> <20180813094049.3726-2-punit.agrawal@arm.com> Date: Mon, 13 Aug 2018 11:01:27 +0100 In-Reply-To: (Suzuki K. Poulose's message of "Mon, 13 Aug 2018 10:46:04 +0100") Message-ID: <87wosu1t6w.fsf@e105922-lin.cambridge.arm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Suzuki K Poulose writes: > On 08/13/2018 10:40 AM, Punit Agrawal wrote: >> 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. >> >> Fixes: ad361f093c1e ("KVM: ARM: Support hugetlbfs backed huge pages") >> Change-Id: Ib417957c842ef67a6f4b786f68df62048d202c24 >> Signed-off-by: Punit Agrawal >> Cc: Marc Zyngier >> Cc: Christoffer Dall >> Cc: Suzuki Poulose >> Cc: stable@vger.kernel.org >> --- >> virt/kvm/arm/mmu.c | 40 +++++++++++++++++++++++++++++----------- >> 1 file changed, 29 insertions(+), 11 deletions(-) >> >> diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c >> index 1d90d79706bd..2ab977edc63c 100644 >> --- a/virt/kvm/arm/mmu.c >> +++ b/virt/kvm/arm/mmu.c >> @@ -1015,19 +1015,36 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache >> 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)) { >> + /* >> + * 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)); >> + >> + /* >> + * 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)) >> + goto out; > > minor nit: You could as well return here, as there are no other users > for the label and there are no clean up actions. Ok - I'll do a quick respin for the maintainers to pick up if they are happy with the other aspects of the patch. > > Either way, > > Reviewed-by: Suzuki K Poulose Thanks Suzuki. > > >> + >> pmd_clear(pmd); >> kvm_tlb_flush_vmid_ipa(kvm, addr); >> } else { >> @@ -1035,6 +1052,7 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache >> } >> kvm_set_pmd(pmd, *new_pmd); >> +out: >> return 0; >> } >> >> > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm