From patchwork Tue Sep 24 06:10:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13810172 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81675CF9C6B for ; Tue, 24 Sep 2024 06:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=a5exoCzehntR4bd+ahks+h4WFwEAjFaMLu5nKDHss+4=; b=O7DW/jfkYiQkrY5rmwwlOjRoqg oDEk/yU/IZbq1vE2Qja1KX2fbOCEqu1HJxcfJuTBqxTMFiaTGpHk0CA5LXdJK4KJdLPEzW2n18ma1 nwaOl8ZfT760hdQy63kkndj9SwINbgq+DB/ANWRtKufYk1xA4SYnAlIlxNgnkdmO/8b08mhR6nTLz jCPW68waM8DM9NRROeRnThKoH86lquuFGvHePZNbuujFvYJOTwDmIeRQ7FOM61xkPHZ9hOI8dyRZr F4PGZN/pZVeJQ+Wk1II7FNzbvxStAYiVviB2om5WGEgKKBBrtYORJYp/pDklapqxl1WsC6lgJ/icn OEF1OVEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssyv2-00000001EUQ-3ZGA; Tue, 24 Sep 2024 06:21:04 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssylb-00000001C0b-2EdU for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 06:11:20 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20570b42f24so56153075ad.1 for ; Mon, 23 Sep 2024 23:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158278; x=1727763078; darn=lists.infradead.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=a5exoCzehntR4bd+ahks+h4WFwEAjFaMLu5nKDHss+4=; b=SUglfZbY3mlGfOrHA5Wk6EEiP/TzVtpnX7iEPkBy5nr/5/mPD4N0Cw+yK23nPSY+A8 rixI1KZ3/0Lzbi0LR8ALnng1ooU3GnGavFNOazJlhy00PlRB9QIn6RPFEX+jUzHz3f0g HYCWP6qyVhfldl9kxkyI3cg/DIz06j/4lOuOSB6pE0KeUGUeIye9pZiozbtP12AWz6Zv E5Fs8jZ4uHJqbYjXN5sxhFVzJ9BMDdWvZfzXy/AwTYIO7ymiGGEaD22SRiD3Ir+rCaEY x8dBWUBaZP5kfWwn+cY0A9298u7yAacViwnoDoCI6X8ym+tIxYPCn+M5idx+nog3I65j q/ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727158278; x=1727763078; 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=a5exoCzehntR4bd+ahks+h4WFwEAjFaMLu5nKDHss+4=; b=TnpgwNbsuEqAezQR9ezh0A2aFnKGKHPQC4joBezTY4gYWuRXeztLGB60cZZge3w9un rTyYeCzuOntRw6GiIMEv54KVg02t5wKQ2XeAoUQqYmqy8lZyVuPVGqJ2CF5rZxjz8pFk 3tfE0euW31w7a141qQEXtrAnZsiiwnbFhm/xSGw8QlLApCWd7PjgLMqGVNT8vVOUZ5LQ Qgkw09isbw24F+nfqSqGELFahMQ0uYhe/0/Gc9+ODtIULqRmtOwNraHitfxg2TnV/8VH NhqSrj5ZYI9FgTEGwrxSTf+pE02w9GvNsof4uB5LpITeAdRjQcOPevHImf/SlQuN3dVq kEKw== X-Forwarded-Encrypted: i=1; AJvYcCX78lGZ+kErjGl1BVPU2Thr+EZh2DfwGi/b8EO8OuqRtZh/mmRT/6JHeC1ziYor9wsyN/m3zwjTlza7HYMgmMOg@lists.infradead.org X-Gm-Message-State: AOJu0Ywzx/ieV+qYD+VXErbFXFKAa2y88GZyZZIgXJKonT32zETycdFR p1pRxKsVIy/RlRoM4LKXVpfyol/CtrqgvJJajarkzB/juiWJGjVd6ueZn7VDUCDpxh0LVoH5Q0t xdVQ= X-Google-Smtp-Source: AGHT+IHw+OqtuQ5LCBY4YmqC9EJn7stUTlaTSc5oItaKMOqNO6mqJktvnwlzFLYt5xYGl9LymCl5gw== X-Received: by 2002:a17:902:d50f:b0:207:1709:380 with SMTP id d9443c01a7336-208d838ede3mr189786005ad.27.1727158278506; Mon, 23 Sep 2024 23:11:18 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20af17229c9sm4344885ad.85.2024.09.23.23.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 23:11:17 -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 v4 08/13] mm: copy_pte_range() use pte_offset_map_rw_nolock() Date: Tue, 24 Sep 2024 14:10:00 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240923_231119_589746_2CFAB349 X-CRM114-Status: GOOD ( 12.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In copy_pte_range(), we may modify the src_pte entry after holding the src_ptl, so convert it to using pte_offset_map_rw_nolock(). Since we already hold the exclusive mmap_lock, and the copy_pte_range() and retract_page_tables() are using vma->anon_vma to be exclusive, so the PTE page is stable, there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/memory.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 6432b636d1ba7..c19cf14e1c565 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1086,6 +1086,7 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, struct mm_struct *src_mm = src_vma->vm_mm; pte_t *orig_src_pte, *orig_dst_pte; pte_t *src_pte, *dst_pte; + pmd_t dummy_pmdval; pte_t ptent; spinlock_t *src_ptl, *dst_ptl; int progress, max_nr, ret = 0; @@ -1111,7 +1112,15 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, ret = -ENOMEM; goto out; } - src_pte = pte_offset_map_nolock(src_mm, src_pmd, addr, &src_ptl); + + /* + * We already hold the exclusive mmap_lock, the copy_pte_range() and + * retract_page_tables() are using vma->anon_vma to be exclusive, so + * the PTE page is stable, and there is no need to get pmdval and do + * pmd_same() check. + */ + src_pte = pte_offset_map_rw_nolock(src_mm, src_pmd, addr, &dummy_pmdval, + &src_ptl); if (!src_pte) { pte_unmap_unlock(dst_pte, dst_ptl); /* ret == 0 */