From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68E33C25B76 for ; Tue, 11 Jun 2024 05:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CicNpgZoqhpMOMzfeFdSX1WUoemPxKPIii6dvTbBhgY=; b=qWt0TDDz9DX1m7 0hBilUczpWjNE2L6Cc1Uu0ht/eLSnnv9hWk5UMEdXIuG0+hr4NVoiextEL6tLPA7hLvGL+fBK92Mi CpykleylBEtZCqtohV7Baw0ZxMux3R9YGuls/bj4ScniiyeQ2Hf/ybdE7gGgQjQl+5ibARPPWPcqC Pj0tmPq7iGTTWjLZksHccwMyHEng59PigkZ3bNohKMdHf2mFFBm4QotN0f3voqamgN5bEKdXjhIrP Nm9k7bikZPjXqEkcJUPvQo/oPKynt1b0nv07MjhzAFO83FxE7CCbaCkKPRK+lW4d+IwPTPaIyIhfT 3npMsL5M4eLYbFK5QnMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGuWQ-00000007bUS-24U0; Tue, 11 Jun 2024 05:58:18 +0000 Received: from out-176.mta0.migadu.com ([91.218.175.176]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGuWM-00000007bSN-2rDW for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 05:58:17 +0000 X-Envelope-To: jthoughton@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1718085486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aqiWe39MZdeODszfKFW0wTFxaRO6NFFUSNnRgYQUTLg=; b=cyEhHRmuHeeS06ZjBXNkPufgh3B8leCOaQ+2mkGJsxw/fHVbVvUbyAUlYdvNZ9xfM9HCHm m4wplQ7pMuC8Dp8TGrb57W3hgjukde4F/i3k4080Q2Pj9PRiHNda6b2hjDUS8A2WB9ueZh mwDKUBEjSMLvLDQO1P+3kvVaJ2uaU30= X-Envelope-To: akpm@linux-foundation.org X-Envelope-To: pbonzini@redhat.com X-Envelope-To: ankita@nvidia.com X-Envelope-To: axelrasmussen@google.com X-Envelope-To: catalin.marinas@arm.com X-Envelope-To: dmatlack@google.com X-Envelope-To: rientjes@google.com X-Envelope-To: james.morse@arm.com X-Envelope-To: corbet@lwn.net X-Envelope-To: maz@kernel.org X-Envelope-To: rananta@google.com X-Envelope-To: ryan.roberts@arm.com X-Envelope-To: seanjc@google.com X-Envelope-To: shahuang@redhat.com X-Envelope-To: suzuki.poulose@arm.com X-Envelope-To: weixugc@google.com X-Envelope-To: will@kernel.org X-Envelope-To: yuzhao@google.com X-Envelope-To: yuzenghui@huawei.com X-Envelope-To: kvmarm@lists.linux.dev X-Envelope-To: kvm@vger.kernel.org X-Envelope-To: linux-arm-kernel@lists.infradead.org X-Envelope-To: linux-doc@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-mm@kvack.org Date: Mon, 10 Jun 2024 22:57:54 -0700 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: James Houghton Cc: Andrew Morton , Paolo Bonzini , Ankit Agrawal , Axel Rasmussen , Catalin Marinas , David Matlack , David Rientjes , James Morse , Jonathan Corbet , Marc Zyngier , Raghavendra Rao Ananta , Ryan Roberts , Sean Christopherson , Shaoqin Huang , Suzuki K Poulose , Wei Xu , Will Deacon , Yu Zhao , Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v5 3/9] KVM: arm64: Relax locking for kvm_test_age_gfn and kvm_age_gfn Message-ID: References: <20240611002145.2078921-1-jthoughton@google.com> <20240611002145.2078921-4-jthoughton@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240611002145.2078921-4-jthoughton@google.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_225815_365990_D6F94872 X-CRM114-Status: GOOD ( 26.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jun 11, 2024 at 12:21:39AM +0000, James Houghton wrote: > Replace the MMU write locks (taken in the memslot iteration loop) for > read locks. > > Grabbing the read lock instead of the write lock is safe because the > only requirement we have is that the stage-2 page tables do not get > deallocated while we are walking them. The stage2_age_walker() callback > is safe to race with itself; update the comment to reflect the > synchronization change. > > Signed-off-by: James Houghton > --- > arch/arm64/kvm/Kconfig | 1 + > arch/arm64/kvm/hyp/pgtable.c | 15 +++++++++------ > arch/arm64/kvm/mmu.c | 26 ++++++++++++++++++++------ > 3 files changed, 30 insertions(+), 12 deletions(-) > > diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig > index 58f09370d17e..7a1af8141c0e 100644 > --- a/arch/arm64/kvm/Kconfig > +++ b/arch/arm64/kvm/Kconfig > @@ -22,6 +22,7 @@ menuconfig KVM > select KVM_COMMON > select KVM_GENERIC_HARDWARE_ENABLING > select KVM_GENERIC_MMU_NOTIFIER > + select KVM_MMU_NOTIFIER_YOUNG_LOCKLESS > select HAVE_KVM_CPU_RELAX_INTERCEPT > select KVM_MMIO > select KVM_GENERIC_DIRTYLOG_READ_PROTECT > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 9e2bbee77491..b1b0f7148cff 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -1319,10 +1319,10 @@ static int stage2_age_walker(const struct kvm_pgtable_visit_ctx *ctx, > data->young = true; > > /* > - * stage2_age_walker() is always called while holding the MMU lock for > - * write, so this will always succeed. Nonetheless, this deliberately > - * follows the race detection pattern of the other stage-2 walkers in > - * case the locking mechanics of the MMU notifiers is ever changed. > + * This walk may not be exclusive; the PTE is permitted to change s/may not/is not/ > + * from under us. If there is a race to update this PTE, then the > + * GFN is most likely young, so failing to clear the AF is likely > + * to be inconsequential. > */ > if (data->mkold && !stage2_try_set_pte(ctx, new)) > return -EAGAIN; > @@ -1345,10 +1345,13 @@ bool kvm_pgtable_stage2_test_clear_young(struct kvm_pgtable *pgt, u64 addr, > struct kvm_pgtable_walker walker = { > .cb = stage2_age_walker, > .arg = &data, > - .flags = KVM_PGTABLE_WALK_LEAF, > + .flags = KVM_PGTABLE_WALK_LEAF | > + KVM_PGTABLE_WALK_SHARED, > }; > + int r; > > - WARN_ON(kvm_pgtable_walk(pgt, addr, size, &walker)); > + r = kvm_pgtable_walk(pgt, addr, size, &walker); > + WARN_ON(r && r != -EAGAIN); I could've been more explicit last time around, could you please tone this down to WARN_ON_ONCE() as well? > return data.young; > } > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 8bcab0cc3fe9..a62c27a347ed 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1773,25 +1773,39 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) > bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) > { > u64 size = (range->end - range->start) << PAGE_SHIFT; > + bool young = false; > + > + read_lock(&kvm->mmu_lock); > > if (!kvm->arch.mmu.pgt) > return false; I'm guessing you meant to have 'goto out' here, since this early return fails to drop the mmu_lock. -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel