Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp195406lqp; Thu, 4 Apr 2024 10:22:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUN3H/W7H8qKJbR2PPVu8IwfvPUB/8dnxRWB8+X8vNbqjzHlO1FOLSfrZ4xSj3ZHYZAdGrU20xcg66q99Z2jM5JFlyqOW/ppG3fc1M9Bg== X-Google-Smtp-Source: AGHT+IHnwHViwMlpZs5Ul8Joc4a5t/I/6deYW8Go3iz0UfVU3WLPf+4QmIeL3uMY8BWKqusAHDMY X-Received: by 2002:a17:907:e9e:b0:a51:8fdd:6161 with SMTP id ho30-20020a1709070e9e00b00a518fdd6161mr319755ejc.47.1712251322992; Thu, 04 Apr 2024 10:22:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712251322; cv=pass; d=google.com; s=arc-20160816; b=XBKwYsDiKHR/GyO2RC2bvNGqCL2bhQV6Oy2/KQ/ltJLp3bRo7hdjDwbx3TZD7sLb5a vxua8q8SZS05UNTHSBuM5tYC6Iyk3OQ6ArcbhAIzUEbpbJbK2S6/ug2Ctd6eGihzBMkW yZe1oHv/MR/1NP+px1T/NQKItcp7LN10Ludodxy+J3rqAoFq4oDB/2yN6xRKAxzw7TlP qAmpgOVAPUxnlRpKQRwQ6dE5LflCGhbQNmOVvtjKlxX8UsQmftgws32Kg3mWfFv2hc9s yYu4pGOmNrSmneO5VP62TBHFaJYrbuBEo2i9PPsMJZEOGb1nYxNv1Q4QGG2ZSZHbQ+l4 r1Iw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2AAEG8ys83OU4EuRCbJQyodfMWerUNVMHCfTJ2nvxPU=; fh=9IDYpBw7A16QOl1r08/6GFgzyf9Jwo7M6nucQi2kY9c=; b=BANCjhhQTljk7tELVkaDr8wGLoSWZ2GMW+FtxZBG01UgAKS+IY/uXLo/6wS+72Vsz5 jH4wuYMOQU0j8Oi9wJ+ljgNq6k10giQf4B67zQb3ABq0kS98Z5VUoe4nniQ2tQfj4/gI B1PGKdEMZFstLOidCdPw9fVtRkuaL9ezaWUBkBDOJZ2zqH2g8uUyY1XPPvdHmt3qBZ2o OyoJRyRJu9yo0WBhNBtDEvc6HWmmM/wFLkyBeIGshlaBRnF2oCAAdrfSrtNhyHLxxEJ/ NHijVxvJAW5dt2DLI612jUu8+biV06kS75cy4wjopu0mEiZ6VeIR7JT+CvbI3DCcxYXF K+5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HAhC2m7Z; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-131884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131884-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cs12-20020a170906dc8c00b00a4e595d5cc8si5494502ejc.791.2024.04.04.10.22.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 10:22:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HAhC2m7Z; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-131884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131884-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AE4BD1F29958 for ; Thu, 4 Apr 2024 17:22:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D52212D75C; Thu, 4 Apr 2024 17:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="HAhC2m7Z" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 31B9D14A8B for ; Thu, 4 Apr 2024 17:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712251315; cv=none; b=nyPdSwJTXYuLN2oUrnqKzsa9kjbURyAxRKcI9dzEYBTBbVtf7ucXSoY3VRwmisWo5lvkcfCXHCLC0TdJ022i1b1EOq0RoWpbcq5nghE5tivL2SULLjTML6WGjNhP98iMnH+YsIdnbBMzAKmBKGovAIQnBp0AV0fxy3Pylpzb1do= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712251315; c=relaxed/simple; bh=I/Y7BkE/ovvkHXAQwnA3lR9TA6Ahb13PwB8H9hTUXKY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jPnHwZFnLDotz3UsdcK33M8oMzhtZwnqGtQGNB8cmk5Q8ylpODIDtB0QvUiii1tImjGu9JujGtsKWGfwYGTWXlDN9Nviwq7VVPAIJJ0/9YY6LZQLE429XXYL2oq+lwZbhpu1DPPzFAzVUsmwndFQO38B56hcr2BmD/QWKlTzkwI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=HAhC2m7Z; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2AAEG8ys83OU4EuRCbJQyodfMWerUNVMHCfTJ2nvxPU=; b=HAhC2m7ZVzD6zPrXiQJLgjLHaW AO3AVTmlWvFBXCD1yKqq7bWONdClkxDKKJ3ou7VzLfGQ/SMxwkrdwQqdaZQAlCW1NbH0geh5Jid2q 9AAaaRG/qZaJvCcgYoNWMcAgIXza61/yE3cZ/QBg0Wxsvzg5hrrq9waG574EojwJgRNGAp6yrHLrA xwXaqqkcWFNBIABKNY7wzOXtPho8VvFFLo+wkpM8JbBkVGaPIbBs298IlNWBXmC5qoNiLkBaeE8c7 +1o3MRkpK6xiKTBkPvFLTjVOE9SGQhc2JGcEPImDkJFyBRKoLIgobIMBAGJ4QbwPF321JJtG1x7/J HhzVRtHQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsQmc-00000008WpL-1PQc; Thu, 04 Apr 2024 17:21:50 +0000 Date: Thu, 4 Apr 2024 18:21:50 +0100 From: Matthew Wilcox To: Lokesh Gidra Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com, kernel-team@android.com, aarcange@redhat.com, peterx@redhat.com, david@redhat.com, zhengqi.arch@bytedance.com, kaleshsingh@google.com, ngeoffray@google.com Subject: Re: [PATCH] userfaultfd: change src_folio after ensuring it's unpinned in UFFDIO_MOVE Message-ID: References: <20240404171726.2302435-1-lokeshgidra@google.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240404171726.2302435-1-lokeshgidra@google.com> On Thu, Apr 04, 2024 at 10:17:26AM -0700, Lokesh Gidra wrote: > - folio_move_anon_rmap(src_folio, dst_vma); > - WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr)); > - > src_pmdval = pmdp_huge_clear_flush(src_vma, src_addr, src_pmd); > /* Folio got pinned from under us. Put it back and fail the move. */ > if (folio_maybe_dma_pinned(src_folio)) { > @@ -2270,6 +2267,9 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm > goto unlock_ptls; > } > > + folio_move_anon_rmap(src_folio, dst_vma); > + WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr)); > + This use of WRITE_ONCE scares me. We hold the folio locked. Why do we need to use WRITE_ONCE? Who's looking at folio->index without holding the folio lock?