From patchwork Thu Oct 10 18:24:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13831070 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 034F9D2444D for ; Thu, 10 Oct 2024 20:26:42 +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=Sag0fj8OwucY2qRogRu5ELvjWktNcy71jZ/+qgEdHaE=; b=pFRGpIzA+G4CNK/sxEZSHOXDzR +foAdENe2slcy1+iR+3j1EEiViZ4VmZUo/fiqOZD9iGnSa1NKpSzG6QtOrosTVJOx7mbxSlzZeeiW Ro3cXzNransgMZnATknP9eaSacJYRBTLEaq1YqUih/hLTUp4rprJRP37CzoZKw8iyLUv39W5bsNg8 HXNy/IEck6NM/3OWnGmvXF2YQxj3eYNzhlXRMKlHHYegzIhTIaB+JKJnBht1ykSNSLeR3PWMsPcaf nvSw7T3pudKrfSRHN7xBmnOUAkSD9tG2uS5KvVUJudZoy/mEMmaTrXvHqddFoY/RJVBw5wGQstJqN 8Hq3XzGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syzjx-0000000EGGN-3eEs; Thu, 10 Oct 2024 20:26:29 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syxsc-0000000DrWB-3n4M for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 18:27:21 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e284982a31so22465637b3.3 for ; Thu, 10 Oct 2024 11:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728584837; x=1729189637; 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=Sag0fj8OwucY2qRogRu5ELvjWktNcy71jZ/+qgEdHaE=; b=E2zHzaRZqpx7PmmOp3LUhoHU9Dr1MkBl5G0WTprILSNA1mq0tHxEkTsU10v77+QvpN 0zFwtgeL7W3gLusd7cDl6EFytNV+h4xDtKwQ84UL7e0cR2cdNgj3Dnms8wEJu/GQeCw2 rt7R7dMOceITVKPIgq5JWL/qwK3SfMqFQ2pgXkciOlQiuO16Q7TJPnLvr3j8HJGzk/g/ PNbNvTkYqJyNtEyeLClT7pwiry+CiUZP34/omc1IrYUyQZyp2bxaEbPY4j91F8t3KOyK XOI9XrCQ/PvTIRVwt9Rf9AqfV0T7By8bPGHJYXiy5nTIL84TTZYDMKUFvEYpQPHXGEzJ 9snQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584837; x=1729189637; 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=Sag0fj8OwucY2qRogRu5ELvjWktNcy71jZ/+qgEdHaE=; b=qhCqtIQW2JNGLQq7o2IsaPsEc5n7XSIMMBGw7pY0Oz3reuv4bxD3OULbXYnJBVbtlk vQiQyCdMPmvHLrUXv7M/CmPsCq6m2Ha2LZ3E8L9IM+13Juq+noLdfjlhTJr2MQMXFbzT ou3+5RwkA36/BEnxSdqusRW9p1zIDFQ7lcSpl4FPEjARtoB3NsMsPNnnAsEl8iQfoGyn SnPQ/ChNbqz762FE5I16SZoW0GihDma6dpdMpmFVwUSbu5gQTSDoFPnZGjxwxRqqWCtL my/Qw4lZ/3wiC2ggAL7yyo1+orPkrDsM+JckJKjDA0D4PGeMDUQRZMEwT/t5w8UepO3p QJBg== X-Forwarded-Encrypted: i=1; AJvYcCVX0HaFWC/hGYM7zmfE51z5e5OsXr2i5+XuL2RKDPAow8TaM1y6lMfmRigFQhs2ku90rkd6LeDtMi9HiNWR+PMO@lists.infradead.org X-Gm-Message-State: AOJu0Yyc1TorAv2qQOkfTA0OWj3iGo+FJNkG3vXQ05/sYCR7uY4FRZm9 8VJP59bdtsTEPQ2QkqgSbeWDqCag2Z3gBL0eXffP3DvnGKfiIZuiQgQkUuk7MswbpPl8U05p7MI nsA== X-Google-Smtp-Source: AGHT+IEjJriLMGICq9yty21Fx3Z3FQyTG0XCg9lS5qhc+MvTVoRASG8drmw0OxSoWZyAtrQmM3pJDo8jQYk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a5b:a4c:0:b0:e28:f454:7de5 with SMTP id 3f1490d57ef6-e28fe52740fmr75826276.6.1728584837458; Thu, 10 Oct 2024 11:27:17 -0700 (PDT) Date: Thu, 10 Oct 2024 11:24:11 -0700 In-Reply-To: <20241010182427.1434605-1-seanjc@google.com> Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241010182427.1434605-70-seanjc@google.com> Subject: [PATCH v13 69/85] KVM: MIPS: 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, " =?utf-8?q?Alex_Benn=C3=A9e?= " , Yan Zhao , David Matlack , David Stevens , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_112719_142882_3A9A7A43 X-CRM114-Status: GOOD ( 11.15 ) 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 --- arch/mips/kvm/mmu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index c17157e700c0..4da9ce4eb54d 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c @@ -514,7 +514,6 @@ static int _kvm_mips_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, set_pte(ptep, pte_mkdirty(*ptep)); pfn = pte_pfn(*ptep); mark_page_dirty(kvm, gfn); - kvm_set_pfn_dirty(pfn); } if (out_entry) @@ -628,7 +627,6 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, if (write_fault) { prot_bits |= __WRITEABLE; mark_page_dirty(kvm, gfn); - kvm_set_pfn_dirty(pfn); } } entry = pfn_pte(pfn, __pgprot(prot_bits)); @@ -642,6 +640,9 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, if (out_buddy) *out_buddy = *ptep_buddy(ptep); + if (writeable) + kvm_set_pfn_dirty(pfn); + spin_unlock(&kvm->mmu_lock); kvm_release_pfn_clean(pfn); kvm_set_pfn_accessed(pfn);