From patchwork Fri Jul 26 23:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743532 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 7D663C3DA49 for ; Sat, 27 Jul 2024 00:22:30 +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=Tp8vWxWuEfoTun4nd23rTIy8nVqGGlQS/g8lo8vNdQg=; b=AEP5VXb5wrWvMemoUujgQjqxFj zDmFQmDZrQJBlnvNcs6ws9VXr4nrEeT3fG/0I47bxhCe5WvA+i5A4j/o6zX6PvpsN/RS/PmjhvWAK SCZzTmjLxZ6gVbT0mRYKLu/ZTdaJhemYis5tePTj9TwGbWNe6Fj7Y2I2/OQVUby+X7J51xGrTX+ua 6MQMAy4mBgmb5w+KLAuufDi1aiVmiMTAKqF5mQ1anR0S/0mCQWnfJShy/tK8MvNceq0rDW02udNG9 eN5QuLVZTxZizienoQgobItlZxgXPaudzJjFA9YcPap+71yn08KLJ5joaiJz+JdmmDGOiusQoGdap ItIL2w2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVCT-00000005f34-3y7j; Sat, 27 Jul 2024 00:22:17 +0000 Received: from mail-pf1-f201.google.com ([209.85.210.201]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUla-00000005QeK-2KuH for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:33 +0000 Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-70d23f0a3d7so1451317b3a.1 for ; Fri, 26 Jul 2024 16:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038069; x=1722642869; 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=Tp8vWxWuEfoTun4nd23rTIy8nVqGGlQS/g8lo8vNdQg=; b=a1Lhshv8scCGz4BW/AhCsEkLRsaRE03TXxu79ACYfTgekGUogBCvMSdGmgyhHZOtFV M5/Y3F0oraYdEq2hipg7fJb6pX222KltgONMQcluQxaskkHxMb+TwImU+Z6cgCzipXUS 97v+5JEJlIEUh9/pPVsIw3GeKmbtcPutToCS4lgJVAzaPwm3JEArcedc4zy9dP7h1bDH /hky0GMwSrc5viTH5liLZAWG7T+SY3RdN2B9mjqtDfIIrESwzQws6ZGsekrs2pT4cFmn n2uZXIGgMJ2lcjAEfipWXqTDWdkYlaA+3KveekqQb7ZRlc+/knjrPxRFLKThdYPKjxny wi2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038069; x=1722642869; 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=Tp8vWxWuEfoTun4nd23rTIy8nVqGGlQS/g8lo8vNdQg=; b=G3kLGkT8/M1r1TqX+4n0nQtoUPNnWhhzBwkZQXpr3PU4ZpwWnWZktPgdeXa8GWoPZM NirnxbnqDMV+YmfvochClhF79To2o7YScGmv8ye832YmDsfBWhT6i+efGWI5ssaAOZgK lRP3cXyEDO2DRsSnZ+qADzB0pU/E6J4eAbhs9EoO/rcyTLyC5s6gld28/MayEv5h8Fmn +6H/B/rQruZMDSrtO3NOFHEea9FB7TdyPi5ACPYsWIOZxnWLeK2r7qhFrJlAw9b/z41s qFjFcdZJ+fuxuFFLQ2NEDC1ZbIUvi3YmkfWrb54cW28aIf8d82Gh29SwI1gbJasJva65 7cLg== X-Forwarded-Encrypted: i=1; AJvYcCUXHI6SRU6GFbzpdJ7B2mDWRN8ZglgicwI/GiC1sST9IIynbvuTDofZMPBpDIPp0KZQu/AS+71tkntvznS4JOTA3aGJ3G4BTNrAt2C4CSEtzEQvWpg= X-Gm-Message-State: AOJu0YzjjhEpUm9sNIm7LE38M1gTgGqMmuLhhXMm9pdY7qwbCftUgUK0 66A0LN7mPoOVv4wK5crZ5EQT2zx6JxlyetkXLhcWpCzt813iMhHEFwHMCyL6dRzEtwOsIKZoSxr rFg== X-Google-Smtp-Source: AGHT+IGdEcu09Hin88e0jkC1IJzP1gp2m8bzTdpaUdhQIiML2lxsNf415Y84GaeMaBcBrlwhHWl3MjBIRUQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:6f1c:b0:706:71b3:d7cf with SMTP id d2e1a72fcca58-70ece926b55mr9310b3a.0.1722038068878; Fri, 26 Jul 2024 16:54:28 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:03 -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-55-seanjc@google.com> Subject: [PATCH v12 54/84] KVM: arm64: Mark "struct page" pfns accessed/dirty before dropping mmu_lock 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_165430_787653_A3130E9C X-CRM114-Status: GOOD ( 12.40 ) 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 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 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); + 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; }