From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C53116CD0E for ; Mon, 5 Aug 2024 23:26:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722900370; cv=none; b=IkqtVLhl0Aqvzgnh03EiLGUCjiz+OFZ/e3iXXis0M8TXpzp2yRs3cUnFn7BD8T8tRzMIGvdBJsWc3HZAFDgCDcfPDb4kbeSniwJM445hAXM/v7eXatNSTMm4iXaO3JCmU5oaGOHbTggilbDBvWzHs2+2krQ0E1E6aEa+vrXKjqE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722900370; c=relaxed/simple; bh=NZCRFKbIN8PF8TtGzo0TuabedSFqMXcg0tKfwiHnKPs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J4iM6GmWurcOkJVNV3mtPMTkHUl7A9uthab4Hu/OJWed7bPO2VyLuAkPPpI9WoQ/WBiWgsC5JNRtAkJxypoDFfo/51CK7Axp5Ay0tspKvbrN0UofOwdBw8wafdL/WxwdsQkxHJpCiMxTEo1O8RgTQYeBIoz3+rQlNPJqy52EBDQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=nsqM4WvI; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nsqM4WvI" Date: Mon, 5 Aug 2024 23:25:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1722900362; 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=+mfeo2RqmDWupNPy1ZQ9DQzaW41XBFzcKm+dZAjG39w=; b=nsqM4WvIeqvYHal0R7bad4sl2RiCqdaEThtnF1PVGpbpIk6TP7/CSQ1lcdBlex5IzcKPCb 7g4CjFX6c6eUuhlGombjt0+/nOmNqPRG0qjhofrleHk8DYNXPAn7Q/OhxjYef93ialM8P+ YvQTTQKWBorXAs+vuLMxHvrpEon2vKo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sean Christopherson Cc: Paolo Bonzini , Marc Zyngier , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , David Stevens Subject: Re: [PATCH v12 54/84] KVM: arm64: Mark "struct page" pfns accessed/dirty before dropping mmu_lock Message-ID: References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-55-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240726235234.228822-55-seanjc@google.com> X-Migadu-Flow: FLOW_OUT [+cc Fuad] Fuad, you mentioned in commit 9c30fc615daa ("KVM: arm64: Move setting the page as dirty out of the critical section") that restructuring around the MMU lock was helpful for reuse (presumably for pKVM), but I lack the context there. On Fri, Jul 26, 2024 at 04:52:03PM -0700, Sean Christopherson wrote: > Mark pages/folios accessed+dirty prior to dropping mmu_lock, as marking a > page/folio dirty after it has been written back can make some filesystems > unhappy (backing KVM guests will such filesystem files is uncommon, and typo: s/will/with/ > the race is minuscule, hence the lack of complaints). See the link below > for details. > > This will also allow converting arm64 to kvm_release_faultin_page(), which > requires that mmu_lock be held (for the aforementioned reason). > > Link: https://lore.kernel.org/all/cover.1683044162.git.lstoakes@gmail.com > Signed-off-by: Sean Christopherson > --- > arch/arm64/kvm/mmu.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 22ee37360c4e..ce13c3d884d5 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1685,15 +1685,17 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > } > > out_unlock: > + if (writable && !ret) > + kvm_set_pfn_dirty(pfn); I'm guessing you meant kvm_release_pfn_dirty() here, because this leaks a reference. > + else > + kvm_release_pfn_clean(pfn); > + > read_unlock(&kvm->mmu_lock); > > /* Mark the page dirty only if the fault is handled successfully */ > - if (writable && !ret) { > - kvm_set_pfn_dirty(pfn); > + if (writable && !ret) > mark_page_dirty_in_slot(kvm, memslot, gfn); > - } > > - kvm_release_pfn_clean(pfn); > return ret != -EAGAIN ? ret : 0; > } > > -- > 2.46.0.rc1.232.g9752f9e123-goog > -- Thanks, Oliver