Received: by 2002:a05:7412:85a1:b0:e2:908c:2ebd with SMTP id n33csp45219rdh; Mon, 30 Oct 2023 13:16:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEI2EXEvf5TsUVzXgccY2fLpzlJ6WzEgsds2spJuds4MaV4V9d7EHImzXA30nEORzsMjDJG X-Received: by 2002:a05:6a21:398f:b0:17a:ee7d:c035 with SMTP id ad15-20020a056a21398f00b0017aee7dc035mr9066730pzc.38.1698697010320; Mon, 30 Oct 2023 13:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698697010; cv=none; d=google.com; s=arc-20160816; b=D2gtCa0OYunZoNOObg30jTnZABLzXbfPTMOJmTbpjm5DoiD6E/gxnxYaqDHaETtaNE 1Ls0qdxfhlPU4zCgHxpxBPC0Y4Kec3yOy/r/gWxvoKxGt1Hi6n+dimHVXejLMwK3Umrv RT8cDMOaYX4Mjj/0Np6bLhvTVhEBFd+Nm9b5IehMq8ZhAD06REXAhQQWy87eYJMpaQzs uWtrj2Qh80SH2wl4wB8MMU0eWAJGTYX7xgpDvLmbAq3QVKVid0DoUGGBiZpRW7GVsNv/ 3qW8KBLMMKtFbh2iNYpWoYi2S349dAwPTfsE/F6SVkPxT35ggya3qyFT8GZUNQ942OeB kqIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+jRgWu4wq7HEdb6M9xaqIwEKJPe6YuGuA0xc3W8gBcA=; fh=kG662odMJ0WGm3Ewws3x+ZkLxJAE5EntYad9jgGZYfA=; b=d54AsNDfBfbXJQNdPjdl8wnPS2CdWUwMe/6Z/jJ/cTJDVQnQKSkVI3Hen+oDKfx5ND IQ/1vcF1WoNtkIkEdRGS+08GnzCNf1GVvxqi2rBrEId8gpJlVRHB9cQIySNN/3xT88/l T5LgZPtMdz6eOyKBkvR2bDnCJTxYnAEDomZItnd2fSt2OxjDuWJuH21Rih17Bz69+56W 5rvTGFS/6Nx6wszu5qhYlFSYAJDU2JfQuE+0rBg+dSYrj2vCtXQaNMR0AZ/hCkY/0uNC dszez4zvr1uS17xynTMl4/nhOP28OoGZ2IGJgB1qU5aMX7oQKJivQhwl/yH/1y4Ic0Ev cYqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y9JAKpoZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id w67-20020a636246000000b005775e2a7951si3622690pgb.345.2023.10.30.13.16.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 13:16:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Y9JAKpoZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C8B3F8084941; Mon, 30 Oct 2023 13:16:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229456AbjJ3UQj (ORCPT + 99 others); Mon, 30 Oct 2023 16:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjJ3UQi (ORCPT ); Mon, 30 Oct 2023 16:16:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E53EF9 for ; Mon, 30 Oct 2023 13:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698696945; 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: in-reply-to:in-reply-to:references:references; bh=+jRgWu4wq7HEdb6M9xaqIwEKJPe6YuGuA0xc3W8gBcA=; b=Y9JAKpoZpGkrSwuboDes7yeVI1Hbl7RJFCbASaukmMFTCkGiagIJMgWH8RmwVd6DohyUz8 YoqVocRS87v9jId4/khwbi4L0zoYfaXntglJ0YmGz3hJX1M3AqXgk4Ua3a0lw5Yy9uEl0c j5lSzyzdWe9U17HwVLfjeOcIaXu6O2g= 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-326-lvevkqKVNxOHfkWGx-LmZw-1; Mon, 30 Oct 2023 16:15:38 -0400 X-MC-Unique: lvevkqKVNxOHfkWGx-LmZw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-41cd9e05c8bso6073361cf.1 for ; Mon, 30 Oct 2023 13:15:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698696936; x=1699301736; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+jRgWu4wq7HEdb6M9xaqIwEKJPe6YuGuA0xc3W8gBcA=; b=uJtC6HpwIKuKcHC21NsrGDkthzGWVvdWdkrSG2AFK7hkIpLpjN3aKrq9MTISVBI/yO awz21bAnLzX2zsCiZWFATRj4dkk4DLq/RJYKjoeRIJ40lFpS181ZOgAUNeYYlqj55TCS tNCsdpglqzN7o9CLk6UxrY2Rabz1oFGoQJ8qH+fIYlSartFpB1Zi+vewtpN8+wU6Do6K AHpL111ki/k3EKoJRgnJQAIFsEcUMfAdYFh8gKE7aKQUfVb4vhIrABLTxOa11ySd/5xK zFmI4wUAe/reA0731oQwj/6fhkEe3TiHfoCq7mbCxXFmEDoZ9IEz0DnzxaBi4XoFhIkq /WtA== X-Gm-Message-State: AOJu0YzUuRlZGxVMGIF1lUN5R4ajiCFDkDIpvQLD838QIWSSlmZgaSXQ jkFKQEO9vMT72F1O9YEvobVuYE+FX8IAm+PLFJZWWLnrrdBCS28Bd80c8yM4P4TX/vUs0iU90NL JapOHkierpybIqtyBhNuE64HY X-Received: by 2002:ac8:7741:0:b0:41e:49e9:fb18 with SMTP id g1-20020ac87741000000b0041e49e9fb18mr9885708qtu.0.1698696936579; Mon, 30 Oct 2023 13:15:36 -0700 (PDT) X-Received: by 2002:ac8:7741:0:b0:41e:49e9:fb18 with SMTP id g1-20020ac87741000000b0041e49e9fb18mr9885676qtu.0.1698696936116; Mon, 30 Oct 2023 13:15:36 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id j15-20020a05622a038f00b00410a9dd3d88sm3671836qtx.68.2023.10.30.13.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 13:15:35 -0700 (PDT) Date: Mon, 30 Oct 2023 16:15:13 -0400 From: Peter Xu To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, david@redhat.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com, jannh@google.com, zhangpeng362@huawei.com, bgeffon@google.com, kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v4 1/5] mm/rmap: support move to different root anon_vma in folio_move_anon_rmap() Message-ID: References: <20231028003819.652322-1-surenb@google.com> <20231028003819.652322-2-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231028003819.652322-2-surenb@google.com> X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 30 Oct 2023 13:16:47 -0700 (PDT) On Fri, Oct 27, 2023 at 05:38:11PM -0700, Suren Baghdasaryan wrote: > From: Andrea Arcangeli > > For now, folio_move_anon_rmap() was only used to move a folio to a > different anon_vma after fork(), whereby the root anon_vma stayed > unchanged. For that, it was sufficient to hold the folio lock when > calling folio_move_anon_rmap(). > > However, we want to make use of folio_move_anon_rmap() to move folios > between VMAs that have a different root anon_vma. As folio_referenced() > performs an RMAP walk without holding the folio lock but only holding the > anon_vma in read mode, holding the folio lock is insufficient. > > When moving to an anon_vma with a different root anon_vma, we'll have to > hold both, the folio lock and the anon_vma lock in write mode. > Consequently, whenever we succeeded in folio_lock_anon_vma_read() to > read-lock the anon_vma, we have to re-check if the mapping was changed > in the meantime. If that was the case, we have to retry. > > Note that folio_move_anon_rmap() must only be called if the anon page is > exclusive to a process, and must not be called on KSM folios. > > This is a preparation for UFFDIO_MOVE, which will hold the folio lock, > the anon_vma lock in write mode, and the mmap_lock in read mode. > > Signed-off-by: Andrea Arcangeli > Signed-off-by: Suren Baghdasaryan Acked-by: Peter Xu -- Peter Xu