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 89CB6C3DA7F for ; Fri, 2 Aug 2024 19:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:Cc:To:From:Subject:Message-ID:References:Mime-Version: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TTqa7oavJrWkxSTFWtVmMnGsBDrmN4Dgl5PSeoZtRS0=; b=qtGGbYl/GoiObsaCKx4vYVpMXP 7lTdwHKmpqkd17sROrACoRdZcfFa2p3EaABr1iEGfIVQG7kjUAHzTpg2rWVOI96U0CtGccxvbqEDN UhWiLMTcjgg4p+PURHhLdMg79hDMwYm/28nfz/olkNvpQNa/Z6eDGnwimN5KSJ7dI/pvPmkB77ldc MWNcszABDxILk+Kvx7TiQdTEsk5YIk7ZUHQuoi/nDU01EuOK7tJw3KTutoVN/1N8MYWCBEksUQwy7 8ekgYTS0BdZvoYT989S+8QCgRh143r8kelFC7UAgWGsvMk8j2WjFXWb5Gw8E7BDNkfKHL3GpCQybJ KbDILXVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZy1D-00000009stb-1pYn; Fri, 02 Aug 2024 19:32:51 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZy0a-00000009sds-1mBX for linux-arm-kernel@lists.infradead.org; Fri, 02 Aug 2024 19:32:14 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2cf13d7f5b9so10540698a91.0 for ; Fri, 02 Aug 2024 12:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722627130; x=1723231930; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=TTqa7oavJrWkxSTFWtVmMnGsBDrmN4Dgl5PSeoZtRS0=; b=qK+csV+A+AF7bZWtakH9Rfx/kKgYZ19CMbJ/tjFre18EtPOdbGmpitpI5NMc4gbEJt BFJLIMOZ30WxLjLEvGqTWN5mV3VuWFX/uGPVjbHaHKtefyqi5+Tk83wgkbHG2Dw+PfXP +8huhYOayWEZeiS7qN8CxtGtFFNEEqvNpUJ+G+U+rKplS+8TB2MQho2PQFO5SH+q0uIH kEBQV+FXhnjT/CcIzKipojL/gbuGlnQLPZ98mW4s59kQgRfty12UGbRvSc+qL3tAdm1J iW4O1GcSCtgEA7GX7facql0n5xodq8ikMIz8tbuEn/tD6nug2Y6VS7Q5I0Ft0cq8oxLV 6y+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722627130; x=1723231930; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=TTqa7oavJrWkxSTFWtVmMnGsBDrmN4Dgl5PSeoZtRS0=; b=oeX/laByRRrEr/94XLEOTgxJmS2ciY8mrn/RTIbTvIeGY9z6Kw0A/LTEmInhNBTxUf OteyJ1tXoGs6e7+DFjx6egzN9LmLHu7xv95fRqdv78VQTuTSHUBEHWkbZF4GbxX6efBN qqj8yDd5RV1ugwu81UYCDBS+klFQdDvnwYdjuS30bLvB393d00u8SZN3wSVzNzV2DPod P/+dakc3Ae/07gBu0tbHOcSUMkZ64DypuWox5xkMHiqMlpSzkqmY5vX8WkMlAWY54Pzk +/1FaMux8maCzuI71WoPEIAyPQdmMD90YnYN09MuLFttU+FMAj7C+c/qph39rUG1EOTb RDJw== X-Forwarded-Encrypted: i=1; AJvYcCVq1O7hgK56S5nAfLfXsp8bRX0C3uJLfJf6jOYBhEAFey0wfBbyCY8As577KDc+4uerq7JtgfM3gAiiboDB2bQCuc+rhn3TvNJcKkPYJRIoilokX7M= X-Gm-Message-State: AOJu0YzcWID0KoCDTBCa8L/frk2DlGzoG6eHRpxtk4s9hURytxteZ8vM RKplPwkcahn6yL6CdltGLCuFcl0N0pLzV5MS8Y+VDRQlvu8AJpWt+TojVonveCQTGs7bz1Yp3aE aHA== X-Google-Smtp-Source: AGHT+IHxpD4UvI3cH5YcMAfSn5X/q5FbzhvcZwiTnoiXfWEKupcq/mKgFqqrl+E4nqq+ftOi/sOAAYuzYXs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:50cf:b0:2c9:61f9:9b27 with SMTP id 98e67ed59e1d1-2cff9526286mr68117a91.5.1722627130434; Fri, 02 Aug 2024 12:32:10 -0700 (PDT) Date: Fri, 2 Aug 2024 12:32:09 -0700 In-Reply-To: Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-65-seanjc@google.com> Message-ID: Subject: Re: [PATCH v12 64/84] KVM: LoongArch: Mark "struct page" pfns dirty only in "slow" page fault path From: Sean Christopherson To: maobibo Cc: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240802_123212_480117_FDC46BA8 X-CRM114-Status: GOOD ( 20.87 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Aug 02, 2024, maobibo wrote: > On 2024/7/27 =E4=B8=8A=E5=8D=887:52, Sean Christopherson wrote: > > Mark pages/folios dirty only the slow page fault path, i.e. only when > > mmu_lock is held and the operation is mmu_notifier-protected, as markin= g a > > page/folio dirty after it has been written back can make some filesyste= ms > > unhappy (backing KVM guests will such filesystem files is uncommon, and > > the race is minuscule, hence the lack of complaints). > >=20 > > See the link below for details. > >=20 > > Link: https://lore.kernel.org/all/cover.1683044162.git.lstoakes@gmail.c= om > > Signed-off-by: Sean Christopherson > > --- > > arch/loongarch/kvm/mmu.c | 18 ++++++++++-------- > > 1 file changed, 10 insertions(+), 8 deletions(-) > >=20 > > diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c > > index 2634a9e8d82c..364dd35e0557 100644 > > --- a/arch/loongarch/kvm/mmu.c > > +++ b/arch/loongarch/kvm/mmu.c > > @@ -608,13 +608,13 @@ static int kvm_map_page_fast(struct kvm_vcpu *vcp= u, unsigned long gpa, bool writ > > if (kvm_pte_young(changed)) > > kvm_set_pfn_accessed(pfn); > > - if (kvm_pte_dirty(changed)) { > > - mark_page_dirty(kvm, gfn); > > - kvm_set_pfn_dirty(pfn); > > - } > > if (page) > > put_page(page); > > } > > + > > + if (kvm_pte_dirty(changed)) > > + mark_page_dirty(kvm, gfn); > > + > > return ret; > > out: > > spin_unlock(&kvm->mmu_lock); > > @@ -915,12 +915,14 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, un= signed long gpa, bool write) > > else > > ++kvm->stat.pages; > > kvm_set_pte(ptep, new_pte); > > - spin_unlock(&kvm->mmu_lock); > > - if (prot_bits & _PAGE_DIRTY) { > > - mark_page_dirty_in_slot(kvm, memslot, gfn); > > + if (writeable) > Is it better to use write or (prot_bits & _PAGE_DIRTY) here? writable is > pte permission from function hva_to_pfn_slow(), write is fault action. Marking folios dirty in the slow/full path basically necessitates marking t= he folio dirty if KVM creates a writable SPTE, as KVM won't mark the folio dir= ty if/when _PAGE_DIRTY is set. Practically speaking, I'm 99.9% certain it doesn't matter. The folio is ma= rked dirty by core MM when the folio is made writable, and cleaning the folio tr= iggers an mmu_notifier invalidation. I.e. if the page is mapped writable in KVM's stage-2 PTEs, then its folio has already been marked dirty.