From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B92A337688 for ; Wed, 1 Apr 2026 15:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775057004; cv=none; b=didS08l1+4IqoPG51albplvy0skK2LNV85YjdpvdzwJapOrE/nILE1Vo/5WtBhE7joPkiSGap4NqMVgKCco0RfOWE6TiqcxDYAt0Ysp7x7U+O8PKWYFu0ScDc4vuNITM00+F7TRUXKWpC/xTCadvrU8qcp5+n4iv10nag7jK6JU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775057004; c=relaxed/simple; bh=FK4FRk1Y65CYn8uGR2QCCam08ZS9JbZQAzIx2Tu7zhw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pnkMuj8wNEO50aF7zrlsTW7+l6pcmRTulPTqaVQtDueGfoshJB0LabxgLHjcr5mgrhIeDtsuvUESX5PIq9L/VCQ7s+7yfGjjksBd+dKI1+GIAGwKhP+2RhIBB6kKQL3nuV2XCNB1DtR4WdtWNt7kp4NCl8/z0iBi64wequQQ4MI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Xy+ggk8X; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q+5+V3Z1; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xy+ggk8X"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q+5+V3Z1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775057002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AS9sBE8MNzlgdJ7Owvs0YGGHjd+pXwcJRuuv+ZiN8LE=; b=Xy+ggk8XalA8GicI6SyjtfbSnafV03ZJopH1gzkjMudGfVM6oqtpFJou9wiNQGNfztjWwe V4Npvo3FB0CHtrNXwehpfy15592QR5Vo/i3EATEfE8nh6mWCtQBme+P0C3CRljWc5s30ij H0YEZlzn06DcfRKilGgc+rcZZEnfN7k= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-ocdal_cXO3epfflDxq_Vvg-1; Wed, 01 Apr 2026 11:23:21 -0400 X-MC-Unique: ocdal_cXO3epfflDxq_Vvg-1 X-Mimecast-MFC-AGG-ID: ocdal_cXO3epfflDxq_Vvg_1775057001 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-50b4fe4ff7bso33020381cf.0 for ; Wed, 01 Apr 2026 08:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775057001; x=1775661801; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=AS9sBE8MNzlgdJ7Owvs0YGGHjd+pXwcJRuuv+ZiN8LE=; b=Q+5+V3Z1wJdXh6SJJQa+4OogSnZ411gXG2GhVOT0gVXrwZBeZ5sk+/cKFNuOOhxRHx e6JN9hmRdYbI80nBvQXy+gKiNiy81sNTHc6QLo5kmwjAPDAERDoGGtlvffusY55DAPeu Yaa3j7IK0o4w+HHHvBEWRCIV7dUWSmKtAAZRVX02xg6UlVa9inaQ2EYGgZ/Lutfm+/1R 14HA3tVl3tRccLvmHJHuTIhTMVL3LDRIHKjkwHUBZWNOckF5VYiRd6QEoYyQxu8K0WL6 ZLlqN1p2owFSK7dMTctxuZdoWau5rU7sVJ+1huf1ovKPtnSre2VIpz9Fa1+FNR4ndJ27 ECIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775057001; x=1775661801; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AS9sBE8MNzlgdJ7Owvs0YGGHjd+pXwcJRuuv+ZiN8LE=; b=nPM+s1X0fXwgaS9AQy7NENdOB3YSd+6bR4tgwjc09eLo1qDJrSwAUygPnrmF58u8IR sIpcfibHUyoI3tWTpuW0sD1YFDKksCodG89t+vEDuAH37mMXNHAXZ1eABS4bsqeNHkL1 3I9Z5Xc3S9sM0VMWf6YWh7iIcm9o8pojJws85mbxcjb9RCgKfZGoYDpQMY/SO7jGA5W4 W80GK0LRunTaUtQEbDgHl0PyMGSgrEFh6N39VIx55gfb1toljnVuYAoBon0k3YOjNiMG 7q1lXhFA2FMg7STcyZHmB3OD29ifO2IFPMVSLtmhKMwreqaeFSimSsOkhZIBCIe6cD6o lYNQ== X-Forwarded-Encrypted: i=1; AJvYcCUFjPbNMU8Dmqc95RWIxH5TDS/m8UC0PCURIV/Ynm2haRdxFbQvDtuCbUbb5KPFvyUkArDmZWUqCjZeJE0=@vger.kernel.org X-Gm-Message-State: AOJu0YwunRgjY0ibuj1LHF7a5CeT8sHx+QBlJsYpTaXGX3i3yDQvb/Lb MFGUguS3yaf8NpOvRm8ONPNt7GeZU3KcKAs0r72xfF2oatOKe7KVgFYQcZWxiSzMlpn8Uo2Mv69 uCub7fsN99p9nnA2nB4FQIFjHR1V3XH4Z6ySs4Vbrt6JAfYPdJFwk9U79Y7dVMzlZzg== X-Gm-Gg: ATEYQzyw541EyXQiYApLgG+PdqluRlS0O2+UsvWo8eZ90OKdfwKu3k9DQzo6busTpwF DErWZxB2LUKwWM2euv91WQt1oF/UB1j3FtC4pXgd0NYSbPodgD30PlNMJfoEWBcAmi+Imhh4Ozw /LYZ1ZGJpM+wOOZReIeO/KkPZD5pZ4lMfsXPLUU2JA+Y/17DH+7X9oUyhG+OIjqec0AvBtY6FFK B6X+/zqifujDs5Xm4hasXjWgLXar4zgXJE3eAygA4a1iMsXALAHYchvXege0Ainuke+D4e0S4lm qf34rjd9bVgJHFVgekv2BHvfpemiIPWjlabY5ji69+38KvbuLH2Wm1TiTJQnQcFImJPV3NC9qoP OEGKaU03h0K97YwcqaR8DKZLNd7DqbzV4wkEN7IOnNuzfrA== X-Received: by 2002:ac8:5dcb:0:b0:509:5116:b433 with SMTP id d75a77b69052e-50d3c146b2fmr49400921cf.11.1775057000867; Wed, 01 Apr 2026 08:23:20 -0700 (PDT) X-Received: by 2002:ac8:5dcb:0:b0:509:5116:b433 with SMTP id d75a77b69052e-50d3c146b2fmr49400251cf.11.1775057000209; Wed, 01 Apr 2026 08:23:20 -0700 (PDT) Received: from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50d4b1dcdaasm345181cf.9.2026.04.01.08.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 08:23:18 -0700 (PDT) Date: Wed, 1 Apr 2026 11:23:17 -0400 From: Peter Xu To: David CARLIER Cc: Mike Rapoport , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka Subject: Re: [PATCH v4] mm/userfaultfd: detect VMA replacement after copy retry in mfill_copy_folio_retry() Message-ID: References: <20260331134158.622084-1-devnexen@gmail.com> <20260331200148.cc0c95deaf070579a68af041@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Apr 01, 2026 at 09:06:36AM +0100, David CARLIER wrote: > The invariant I was going for: "the folio we allocated is still > compatible with the VMA we're about to install it into." Since > alloc_folio() allocates from the VMA's backing file (inode), checking > that vm_file is still the same after re-acquiring locks ensures the > folio matches the inode. The vm_flags comparison was a secondary guard > against permission/type changes during the window. > > That said, I can see the vma_snapshot abstraction is doing too much for > what's really needed. Would a simpler approach work better — just > saving vm_file (with get_file/fput) before the drop and comparing it > directly after re-acquiring? That makes the invariant explicit: "same > backing file means the folio is valid for this VMA." IMHO the flags is needed, consider a shared shmem vma remapped to a private shmem vma. That needs to be covered in the fix. Actually instead of reducing checks, maybe we also need to check the offset of the mapping too, that is: vma->vm_pgoff can't change otherwise it may also affect how the back store would behave on this UFFDIO_COPY request. For that, see the example of shmem_get_pgoff_policy() where it seems we can apply different policies to different ranges of the back store. Thanks, -- Peter Xu