From patchwork Thu Aug 22 07:13:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13772874 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 CD4FEC3DA4A for ; Thu, 22 Aug 2024 07:21:57 +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=kCwbwV/YmKb9rcRCZPyi2vEyGZwxl6QKnoBllHH347k=; b=Ra70lZP5eENWTmEg8eTmVEnyYQ ei1wr5EXZW/yAf6B0qX41Wp5p3HKMav/y3mNO94K0J4bPXOFk3TgTLQAMoBQCZ5afOCsd3NPNhkl+ bzMr3p7hpRdJm4zditAoXbvBPRc8w7Wlv2QPtYuXegnVePWQZpfbJ3MRiqMzJeIwa926GERGN8Lnn o96qIipeJ9bB04pg/9gaonpIl7O6oiTlv+9Jag3b/GT5W0279Q9v/h4R9oJtnWxCyB/lcDF/CF5J5 T4NM8PN4DPSENEjB19dYVzh9uH64Lr64h5SpUAqKeZL+yfqHsoTjMQ7t7qMF8euPnp2VFEqIJF+tt GFpUPhVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh28g-0000000BqEi-2SsN; Thu, 22 Aug 2024 07:21:46 +0000 Received: from mail-oa1-x32.google.com ([2001:4860:4864:20::32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh21p-0000000BnFW-1Fls for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 07:14:42 +0000 Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-27012aa4a74so250300fac.0 for ; Thu, 22 Aug 2024 00:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724310879; x=1724915679; 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=kCwbwV/YmKb9rcRCZPyi2vEyGZwxl6QKnoBllHH347k=; b=Z+zWqv1fJfCR0Y6It0hmpE70eNYz/31M1EPLn+GJi5v3bS8LRZy5Ypkdi+1ot684Mo OcQl3DT0jZCMYq1PBw1lTdbAfTLwh3ZjFlX1gz2/seb75IyiTAt/PnHIX+YO9uWEkV91 1DOg+BLUMrJCTKKKP5pkrNrS+F2Rt4QBTLb/qPzkQgxRlNFw82GtYrHPneMNPgSMePih KflTH/GZax7wlUvGzR8kHTJgN9H1iuiMhToejdx8NMkMglhLoz8cG8owYZIDi618fFjW qQohzPG4cdt515cJQx7qAQFfcKAmW15ZFqW90PVvO5iZvG3UYRrUNkK4Dz6pzbmkJj4s xm7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724310879; x=1724915679; 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=kCwbwV/YmKb9rcRCZPyi2vEyGZwxl6QKnoBllHH347k=; b=pf5CBqWcemS4BXPMgyYN33Gk4tqO86gVR7wcpA7H1i09VFHG4Cvn4GZbz4TPlx+UJz mwncKJihwDPlKp5jYBC6cVC7/v9FJYjjr59KjncMoUbj3L92jGWjz+2R/rXem7tnnJjC ShOXhq+F9io9/s5E3/CWLQW7KJA2Xwxa9FrQ01yv7yIp8cAq7hp8y5pZoxOQdfWPSM4h nmldftJmlu7iSqaiH5dyVIWkEUbjotdE0xWIyccoQChOWb75+yEzIVBYH++Yka5G1+tI AxN55wSnTknY1AEp4VekHa//G3bkYqqcX4IDnhjcFxJVpXamtstvlaCm8vG4EOce1S/S m7WQ== X-Forwarded-Encrypted: i=1; AJvYcCUBtkmwODnRfE/HsJOyi54/0QSwNwABOrPmvfOjngXIzb/xfEt8nLYIJXGWBYfUXCONOdEUY21y8ZVpZ6pS+aLu@lists.infradead.org X-Gm-Message-State: AOJu0Yw+Gyhpnk/w7fA+QTaZ21jp7FzJjD1eW6J49EL/ZGsUYi2al3cA Q0EABB1HFPhoFI368d2EZOOUXN1eEXG3aHXCwWAJiEAGaS/Uey7hgqetnLYWvYM= X-Google-Smtp-Source: AGHT+IFsTn+Q5A1WOhbyPTAjHclYiOvt3nhLZV/Hi5KOu9NOtbxQa/3JykhMvHE3PrFxCVBhO2k7lw== X-Received: by 2002:a05:6871:149:b0:268:afc3:648e with SMTP id 586e51a60fabf-273cffcb557mr1073020fac.42.1724310879532; Thu, 22 Aug 2024 00:14:39 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([240e:473:c90:f96:d029:ea8a:4e6d:d272]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ac994a3sm695095a12.16.2024.08.22.00.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:14:39 -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 v2 09/14] mm: mremap: move_ptes() use pte_offset_map_rw_nolock() Date: Thu, 22 Aug 2024 15:13:24 +0800 Message-Id: <12097a187fee5f21860d4f87e7aa103f822e298e.1724310149.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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_001441_360310_6ADAFF86 X-CRM114-Status: GOOD ( 11.90 ) 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 move_ptes(), we may modify the new_pte after acquiring the new_ptl, so convert it to using pte_offset_map_rw_nolock(). But since we already hold the exclusive mmap_lock, there is no need to get pmdval to do pmd_same() check, just pass a dummy variable to it. Signed-off-by: Qi Zheng --- mm/mremap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 24712f8dbb6b5..f96b025c09079 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,13 @@ 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); + /* + * Use the maywrite version to indicate that new_pte will be modified, + * but since we hold the exclusive mmap_lock, there is no need to + * recheck pmd_same() after acquiring the new_ptl. + */ + 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;