From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46676C2E9 for ; Tue, 6 Aug 2024 15:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722957573; cv=none; b=DNpkkYyXn7yI3LrIk2XqfGoUIU5luQO0ZPJGkIIm47n6PMj4Sb2yY4k39TNkg0rO01L35zYjGLlS/aJhjeN6BiLubWqNxwxCF0CVShEKpdrtKc42LNzNgOgO0uS9BN3FZdZEFmr5l2L7Ni24KJMcZK76YpC/t6KSJuX5w6ppF74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722957573; c=relaxed/simple; bh=507JunshFPL0z45Z3MTpxjvv85WUDf3XTVoh4ip9AK8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U32WoAMWCv54ICzIvpjLq+NnSZY6A5zs63efJifh3D7q89MuitDEfBlLUgvFbtAXVvuo4R5i/uT2/hTDiKXZWMzcSBS+FeDXeI+R+W6LfG9mG43i+lNTPkb6h+iJsAWl7B48wbpllexqErtXwcCFPZxi0HuVrpMFn97cWLBKdPU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iVLpNt8H; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iVLpNt8H" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1fc51ea72abso7299605ad.1 for ; Tue, 06 Aug 2024 08:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722957572; x=1723562372; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zfDlFqosrXLKfrNosA2JBe6CUch6c/VqYqOk4CYX594=; b=iVLpNt8HQO4wYEdnnjSjRlbnbQxOTNZtYKDfnPpHaseFWo5rNXVL7mNe3b+OX9K7K+ OZrxO3xGpQBXYUrO5ezrBM6ZiXunCT02FXUR1pUX0lx9IBPNnImShdseHlqu+23sVOal WQVzrE9Ssov9R+YUO+yvBoSYMEMkPSPGSOR14G7/RkownBYnEXb5OeFHnY6pvVNeRINt r2j45hCeywjBtyhiFn5dueFKYEWBGf/QN23tE+1h6SCGO/ulegqulTRwyONiwQEqtikz Fh2uQRATQF287ICDw3kvbYE/qCJTCdTPn5BKHHPkjUV7Srq6ZNE/sEYVtLcvKKQZDtNa wqFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722957572; x=1723562372; h=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=zfDlFqosrXLKfrNosA2JBe6CUch6c/VqYqOk4CYX594=; b=wZcMz5kdhC/51+/omlcoTMloKpa5UCn3AIZRgHBvBTFBDlAeDC3W0zBeq1x9iWC+rP mhNcVDG/7yUwzQ6OCmJR09P3czdENMohvnWdyO7l2P/87kRUDpzR3VBoYWMI/WS7uQbJ xUAKKeR3og69/kdofHM8KRKvK92N7az6CO5NUD9LbwI0nWpoCh4+UDeBbHGeF94mGC2o s6V8gTDbt6VqowkvgIlB+tg50TAYzYGXFROEEvGUq64qYNaI8+vVk8BLswm9ldvY45QJ NJnTUOVNl5EPVeKAoRFFxbYPhsjU2zi2ZphsyzflnvYsQNVu7iSP2rxxzUGpmjO5Xliz ULLQ== X-Forwarded-Encrypted: i=1; AJvYcCVG7ATBhur6DIbPRNvmK8jm0q1bB/0dH6PpkT49pQxpsXlUivpIorRZR6ENGGry8vjZAGGZmOlheY1DajQwlYokJtfCK04F X-Gm-Message-State: AOJu0Yzdzyh3HMOolaNAajlL89U8T0pw7mpdKIFhrQWRNXiLxz2Z8adz PsJ41nL1iioqGC7J4eYSyW6ecObPSqZwiUGomVcNDohxnyr0aEj9n3a7CmV4WZbXJg0gU7HooLG gPw== X-Google-Smtp-Source: AGHT+IG+kq4xSCmsszhC87T6ezpGfclhL8SLo9v6dzemvAwTfI9EBqVt37Vs+G2GK8dBxj5hzSimY+F6XI8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:e743:b0:1fb:54d9:ebb3 with SMTP id d9443c01a7336-1ff57309939mr9499665ad.6.1722957571476; Tue, 06 Aug 2024 08:19:31 -0700 (PDT) Date: Tue, 6 Aug 2024 08:19:29 -0700 In-Reply-To: <86ikwe2fph.wl-maz@kernel.org> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-55-seanjc@google.com> <86ikwe2fph.wl-maz@kernel.org> Message-ID: Subject: Re: [PATCH v12 54/84] KVM: arm64: Mark "struct page" pfns accessed/dirty before dropping mmu_lock From: Sean Christopherson To: Marc Zyngier Cc: Oliver Upton , Paolo Bonzini , Tianrui Zhao , Bibo Mao , 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 , Fuad Tabba Content-Type: text/plain; charset="us-ascii" On Tue, Aug 06, 2024, Marc Zyngier wrote: > On Tue, 06 Aug 2024 00:26:54 +0100, > Oliver Upton wrote: > > > > On Mon, Aug 05, 2024 at 11:26:03PM +0000, Oliver Upton wrote: > > > [+cc Fuad] > > > > Take 2! > > > > > Fuad, you mentioned in commit 9c30fc615daa ("KVM: arm64: Move setting > > > the page as dirty out of the critical section") that restructuring > > > around the MMU lock was helpful for reuse (presumably for pKVM), but I > > > lack the context there. > > > > > > On Fri, Jul 26, 2024 at 04:52:03PM -0700, Sean Christopherson wrote: > > > > 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 > > > > > > typo: s/will/with/ > > > > > > > the race is minuscule, hence the lack of complaints). See the link below > > > > for details. > > Should we consider reverting 9c30fc615daa then? Aha! After thinking through things more, I don't think a revert is necessary. I _think_ the worst case scenario is that KVM would trigger this WARN in filemap_unaccount_folio(): /* * At this point folio must be either written or cleaned by * truncate. Dirty folio here signals a bug and loss of * unwritten data - on ordinary filesystems. * * But it's harmless on in-memory filesystems like tmpfs; and can * occur when a driver which did get_user_pages() sets page dirty * before putting it, while the inode is being finally evicted. * * Below fixes dirty accounting after removing the folio entirely * but leaves the dirty flag set: it has no effect for truncated * folio and anyway will be cleared before returning folio to * buddy allocator. */ if (WARN_ON_ONCE(folio_test_dirty(folio) && mapping_can_writeback(mapping))) folio_account_cleaned(folio, inode_to_wb(mapping->host)); KVM won't actually write memory because the stage-2 mappings are protected by the mmu_notifier, i.e. there is no risk of loss of data, even if the VM were backed by memory that needs writeback. And FWIW, given that multiple other KVM architectures mark folios dirty outside of mmu_notifier protection and have never tripped over this, I think it's highly unlikely the WARN will ever be triggered by a sane virtualization setup. I can add something to that effect to the changelog, e.g. to document that this isn't super urgent.