From patchwork Fri Jul 26 23:52:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743552 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 EB865C3DA4A for ; Sat, 27 Jul 2024 00:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XEv6FisOGr6vpV2eziQMsIEoEavMf3RHPa1v90mbDdU=; b=ITmlg6PYC5QSm4sCAiamrDTrjU QvHwnhC2zIdyyCnAVOwQTApKMCMt0LYvX8K0KSHAN9DcHqYXVB6aSUxQz5cwe3WDn6P/AXYSRN0HX 9vyZ+QtQyWSepKqDPQcV4H0SEC6R5AKGAX+fIzaKRwDkC3quum6FqaplWssTmXQQFZkvwNg6OFtTE iSFBSOLDhM/NNZilJk6wFzoh4fmkzQe4Qvh26Og7c5tsFwVzq/y76qMNcW5Grp69R5ryc71wTya8v tM7ZnO42MLPr0MjYMQihrw1wjDnpKmd374b3UDs5enxrBEICJxwnAQjJePmspMdk+df1JbCL0RYfS cX7bu7Yg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVGr-00000005h6H-21Vo; Sat, 27 Jul 2024 00:26:49 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUlv-00000005QvF-3Xg3 for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:53 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dfa73db88dcso444062276.0 for ; Fri, 26 Jul 2024 16:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038090; x=1722642890; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=XEv6FisOGr6vpV2eziQMsIEoEavMf3RHPa1v90mbDdU=; b=EeCsWPS9kIjQeoy2YhVAeX8xthgjWzE22IQrjisj/hzoLhWw/cZNvxdgXKZd+ivJ5B dXklDq9YktuJK2q/IsJ231CG8P8ZBxPVuhoS1eaK+6KlYLxfWVAGEkmxL/akQFweDMvX CtagECM/ocgqShIgyoYH8oIEC1YyRUQZj2EI93Uot2LFbK3q0r8/mrr3IpuXro0JYRLc z4G7HavOIyyHLQt2fAaN0KbNm2VcHX1vpvP5D9/LRgSa7FYyrRYGEsBJgsHZUuQSYmOO L8ZTvt0xGAcJjM7n2ZX+hm5vY9MtMwG6e2IMwg/sDbtg7N0TaCZGdYImjosRDo18eZ+i mMRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038090; x=1722642890; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XEv6FisOGr6vpV2eziQMsIEoEavMf3RHPa1v90mbDdU=; b=UiT4w7WgNDmP9Nz7XVHsn5Jk+nQF95BV8LdD3nIMqsIzSq1vNUKPTguEJ11b/Nbj4X 7k72k3RHSbK38d5xj7LHYLcgpURco0BqLIP5HsYkOh2tKgPma1O624kunNImfiZ85ne4 dcTRQS8J61j7yqRDjwS8lBMnTh4+nTckjM1PE3qHA56KUTEMzB7Vs2WmtKr7EF7DAib0 86/KdxHAl9Wx08AMkpUuVMDBue8S68cIUA4SO3nUVEO7m/JSy7tXS+vNbEmGteEnkKcV jOP+hARQurJ1eNXZ/m2G23MYI7fQw+cc7rCTIMAg14OusfyHAPmh1Tfz6faaL8yK5mk2 o5MQ== X-Forwarded-Encrypted: i=1; AJvYcCVMkVtn6J4TtIt9vm1rTYlopia5QCgdODDa1CuNfg/SIWgJGEIMOiJiRVr98YwypnGpU3WwUEhPU18Oj/9ssIYma3tpFanjRPCZckaqVhMKFNkbdCI= X-Gm-Message-State: AOJu0YyTum4vf5DMlA2k3as9HnhYZWANXZGtffaZSQweT67nYRvwQtXK +YtdT15DcBafEb8njRUfyrQUfG1raeZK1EkhWAcWd65B0fOUQK3bpxCI0R+PdWn9Ar/UEzQLOsM fLA== X-Google-Smtp-Source: AGHT+IEFsToK4Mtfkt/isyLtzSbxuiJaEYiedQjj5sFCo8o3/vbFtfyZ9L8therJfArRWUvkwGk/K/B8SPA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1002:b0:e05:6961:6db3 with SMTP id 3f1490d57ef6-e0b54503b59mr2236276.9.1722038090539; Fri, 26 Jul 2024 16:54:50 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:13 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-65-seanjc@google.com> Subject: [PATCH v12 64/84] KVM: LoongArch: Mark "struct page" pfns dirty only in "slow" page fault path From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165452_056331_F0F792B7 X-CRM114-Status: GOOD ( 11.19 ) 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: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 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 the race is minuscule, hence the lack of complaints). See the link below for details. Link: https://lore.kernel.org/all/cover.1683044162.git.lstoakes@gmail.com Signed-off-by: Sean Christopherson Reviewed-by: Bibo Mao --- arch/loongarch/kvm/mmu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 *vcpu, 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, unsigned 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) kvm_set_pfn_dirty(pfn); - } + + spin_unlock(&kvm->mmu_lock); + + if (prot_bits & _PAGE_DIRTY) + mark_page_dirty_in_slot(kvm, memslot, gfn); kvm_release_pfn_clean(pfn); out: