From patchwork Thu Sep 26 06:46:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812865 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 573E6CCF9E9 for ; Thu, 26 Sep 2024 06:48:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E00156B00AE; Thu, 26 Sep 2024 02:47:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DAEEB6B00B1; Thu, 26 Sep 2024 02:47:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C50206B00B3; Thu, 26 Sep 2024 02:47:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9FBB26B00AE for ; Thu, 26 Sep 2024 02:47:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 66AC4AADB6 for ; Thu, 26 Sep 2024 06:47:59 +0000 (UTC) X-FDA: 82605959478.19.CF8CB29 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by imf30.hostedemail.com (Postfix) with ESMTP id 97C9380012 for ; Thu, 26 Sep 2024 06:47:57 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=M5M1oAky; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.222.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727333156; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xHtLGGTaDvd+j7nlO+D4nlmKtDmH5wZnqdyAY1Z6B8s=; b=XYldgDQB4J26Gg05VbVPwS1/jasnpaZ5FUQeoMRVHm5r0ApIpWAh+1Glz0JxIhJ1bdJ1rq Zh/1iMKf7eEQXjgiSVZVJQQjhXjNTtX139b4i3Z94YlXNuZY1oiY1+Dh0ZC247RG5o+Ihi WD+N7IvuvmBpJK68AcRc7V5LbelF9vg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727333156; a=rsa-sha256; cv=none; b=NWWMiI9mTpeHuIjzjGFjlusA+QW0+VTT6VIc30Iab/q2ppzhO2aoE1XnJSgoKexNnnvHPz F7kPjycX6SoxRZYqbJS5Nz1fQyDTCPRwwxUXUdbuKK6FIoQ6fdrudwiGZpYOlz9aCMnM5/ 6MTmYf9FIlPwrSiYvXTTN0bqn2piCfs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=M5M1oAky; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.222.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7a9ad15d11bso57929885a.0 for ; Wed, 25 Sep 2024 23:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333277; x=1727938077; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xHtLGGTaDvd+j7nlO+D4nlmKtDmH5wZnqdyAY1Z6B8s=; b=M5M1oAkyela4Wd0MwTYtXzlmYv+diAv0zP46OcMVVOAOuD0DnSAJ5EXnqNTfVWR79q 7zfvOT+O4ysz0eN+zYPG1bslYuAQE6mK6uKNEP/771kHaf3WaRRFrJoLQbT09H6WvuKW +r/k09aMT4049po5MymgjCAyvyU3a+ezZn/i1xIXuC5F+andT3ptO7ZyQta8Qh9+66wS rg1vXtXhV0arKZSSaZ5jiikn9FoKkww5x8ABhBPGSOZa1+VpS8IfWt1FLxkQCY8o8EH4 xdHGcOGm8bskREM3WmHxVWrdDf8ygMNn+S2C306T5Uf63kMdu+eXFT87FMnnzSodkYGo suQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333277; x=1727938077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xHtLGGTaDvd+j7nlO+D4nlmKtDmH5wZnqdyAY1Z6B8s=; b=ddhUnde37vhwcr8woZn7MdFbqG4wzJOLtVFzR9cc5OJfyTfmU1TBhMkOMJ0Ruj9WXC ariEoOAts4hzLpVJEdYUpHOk3OSNzRC2InL3ItFJ+nBOpi9caepAJhKrmG7V6Gmx0laC iBzv6iVtyGJZaIKWgdkJ3tANWL5l3m0vMBjdBoCN5t08c7hD7kRe7Pwb9wk6Q3AD5H+u ZPPjjbSOeIkPBranDtVS3adPH3XwxdcUmiqCJMh+c3SJ/8EvPHoJ6G4FkVpfJ7pkV8mf COIFkjHjmk8FT7S6r0vDaZxVlHecv+f5V5blh3A8+bn1ki15FSfDRS7oOM7DfeRZYHAu eKaQ== X-Forwarded-Encrypted: i=1; AJvYcCU8mdYh9WRlsFxj/32oYQ/0XanrovHp0qYRt6FaaiutY9dapkGTENYYuJkroY6Lky/WAmktb20kNQ==@kvack.org X-Gm-Message-State: AOJu0YzZw1rvULIrm/+WZ/VT0SSuea0w0W3YXHmUSsTFMKWl/KTxrwEE x4CLjBH4WwvXvgp0Eyfba+8rIgCKoyjF6iu4JNENVN5svu1uDcOLvG7hGtQli3s= X-Google-Smtp-Source: AGHT+IGbo2MSjNAvLC3c2ApJAOpwKD09S+YUwBzMfKcY13i9YN/E+PXjNs0XRR1eOHqqnOUdrqUWyg== X-Received: by 2002:ac8:7d42:0:b0:458:2ce1:26f8 with SMTP id d75a77b69052e-45b5e045ea9mr77074431cf.60.1727333276776; Wed, 25 Sep 2024 23:47:56 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5257ff1esm23024611cf.38.2024.09.25.23.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:47:56 -0700 (PDT) From: Qi Zheng To: david@redhat.com, hughd@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, akpm@linux-foundation.org, rppt@kernel.org, vishal.moola@gmail.com, peterx@redhat.com, ryan.roberts@arm.com, christophe.leroy2@cs-soprasteria.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Qi Zheng Subject: [PATCH v5 09/13] mm: mremap: move_ptes() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:22 +0800 Message-Id: <9d582a09dbcf12e562ac5fe0ba05e9248a58f5e0.1727332572.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 97C9380012 X-Stat-Signature: dgejykeok56j6o8fneer34pp3sjjtcfa X-HE-Tag: 1727333277-41087 X-HE-Meta: U2FsdGVkX1/AVwuBsb/Ap2Y7e7GdrKYhYY8XjBSwlvfIlBPUWkGuNvsO9/06lTUKo9e7y3wGtZbifOp3ZVVG7i93qWCL+VCgPjAqlxftLVzajM64E7yIs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w2uGpXke0puMKmldVUK679imhT24onYBQfNYRvn/2SkULNE563ZbYlZVLROVifRk+E5QG2qgLostrOOEVWtfAblDvGqb2rbEwLey43bVwJPY9Uj2qQNXW+Zltjuv54O+2LfB4VXjI/a39ATL8m8i3Yv5TYyjHWUEdIADNe6mPs/5rTjnGpnstHg22Qh//6IzX1ewNHbniYghICb7Hj4vvfQ2AxGjPsoieCnEsTLHeJhSroc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In move_ptes(), we may modify the new_pte after acquiring the new_ptl, so convert it to using pte_offset_map_rw_nolock(). Now new_pte is none, so hpage_collapse_scan_file() path can not find this by traversing file->f_mapping, so there is no concurrency with retract_page_tables(). In addition, we already hold the exclusive mmap_lock, so this new_pte page is stable, so there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/mremap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 24712f8dbb6b5..9dffd4a5b4d18 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -143,6 +143,7 @@ static int move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, spinlock_t *old_ptl, *new_ptl; bool force_flush = false; unsigned long len = old_end - old_addr; + pmd_t dummy_pmdval; int err = 0; /* @@ -175,7 +176,15 @@ static int move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd, err = -EAGAIN; goto out; } - new_pte = pte_offset_map_nolock(mm, new_pmd, new_addr, &new_ptl); + /* + * Now new_pte is none, so hpage_collapse_scan_file() path can not find + * this by traversing file->f_mapping, so there is no concurrency with + * retract_page_tables(). In addition, we already hold the exclusive + * mmap_lock, so this new_pte page is stable, so there is no need to get + * pmdval and do pmd_same() check. + */ + new_pte = pte_offset_map_rw_nolock(mm, new_pmd, new_addr, &dummy_pmdval, + &new_ptl); if (!new_pte) { pte_unmap_unlock(old_pte, old_ptl); err = -EAGAIN;