From patchwork Fri Jul 26 23:52:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743566 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 B11E5C3DA4A for ; Sat, 27 Jul 2024 00:28:47 +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=EmsAuvL8HQXwYqsGGesvXxhYre2Gu8OeDMQE+hBNppI=; b=EmLOdjhDS0YQ3GhfMHJRVaIIOQ 6NkkD6OB7vjZeaMYCss/LxsGljXfRwj0AUVo/zRPW6EFMFBmTEYYm6d/ZlV/DjUUTtfL3KabERY65 fpyIRiD0J3eZDfr3EJpRf4zeXZL2uFPUOJJBWGGuxdrJaHOw62VG4XBlJYZIRww6QXWGu7F80JGsz zARsF3FIQkk67vasanFSAh35GqPjNrmxuC6oxgz03POjls+diJyEm3vIOt4zN1ieu6aR+r31pEWT8 nTZLUx5UWEct5QUQ9OMItmrk7NQ4sI/AlVM5uEhC/1K7iytEAbPdrJEjgAxyZG9jJpOraXiuBsk+U gXuxq6bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVIc-00000005i0O-2Rqo; Sat, 27 Jul 2024 00:28:38 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUm5-00000005R3f-0AiT for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:55:03 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-649731dd35bso1375103a12.0 for ; Fri, 26 Jul 2024 16:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038100; x=1722642900; 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=EmsAuvL8HQXwYqsGGesvXxhYre2Gu8OeDMQE+hBNppI=; b=UfGQyyD3vq6j6kdku9TuM0lVETgP2Gx9PLJcBddmimczlR/92NTCV8JBanvDkn0VyW tkUpNxwhs2rqDe9AeYtCkFi0c9BL6/wQs41+x5hTOCgr0KWgTgIKdyQThTDilvWtt66o 7Q+HXsjzpMWObpUqE5lZe6fsL9CNIBcWF1GhSVq1nLvIwQccrvx97vl4bK5xV3/66k8Y +OiHB/tIDt+vyeCWcRMXAr2U4uf5k0adbru5mqt94PmgJknDkxDDt3V+SNO39kgJngOM 0UyNKEEgZsJ7Zxzqlj2pZpmoRWn/+OjCncoW/6LbaovHQaxSec0ANSLpI39TZLIlzv9R NquA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038100; x=1722642900; 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=EmsAuvL8HQXwYqsGGesvXxhYre2Gu8OeDMQE+hBNppI=; b=N0lQZTDHc4y1+JIPEUfbbr8u7uvKz8ZP2VbBIErhcyxVSJwDqlkBuoYIXcSbttwm4q U020nnYt9wn2NVuaVDApKJk5nrNYVv0PgEV/F47oH9kHPSGD7YDt3yL3EdkVU6ph6avR uxx2axHEAfK44rb1UO4FqEgum2uz07er7lWkdP6WF5k0cjiJSvs4eC/qMgImPlV/9gnq RruRQKAntKXunXkMHXrgYRwqBa55SsiSQr9H8AGh7Rg7eLSwjC5bC6AxSAWws2Xq/Hpr OCV+GliHJs+se8RihSlongq7rlPgOJP+vwI2gdGTO0kSMHOT32jjN/pqvK2TjmA8yNSO MwQA== X-Forwarded-Encrypted: i=1; AJvYcCXkQNviHiLmbgT6hknIxTKpwyMF27zMKZ8+HOnYCni0RVpbUFfeduF+7qP8XYExpdq1J3+Dxgwt/Wqu3pHm0K/ELu9oliinQookbQVcok/D8Z4gM6k= X-Gm-Message-State: AOJu0Yxgw3qlEEhqWWnBpUSkuK92OgaoHrRg2LRHbWnaNtj6Wt7YHzfT njJNE1shyc1XuQBTqYjZEcPspEHzquNT4mQgCWaIB4798akkFF8kZ4pc+aSUyZTmh0scn4atArf SNg== X-Google-Smtp-Source: AGHT+IFixvL6M1c2YXLcj1uim9WdRxJ+9f/3q289x5sMH5Ueo8TBf7rPuOmHjx69h4l0El/Ee2ditwF800M= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a02:fca:b0:72b:5113:ec05 with SMTP id 41be03b00d2f7-7ac8e39fc8dmr2096a12.5.1722038098497; Fri, 26 Jul 2024 16:54:58 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:17 -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-69-seanjc@google.com> Subject: [PATCH v12 68/84] 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, David Matlack , David Stevens X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165501_277452_DE000CC3 X-CRM114-Status: GOOD ( 11.17 ) 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);