From patchwork Wed Aug 21 08:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13770989 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 1FABBC52D7C for ; Wed, 21 Aug 2024 08:20:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8C176B00C9; Wed, 21 Aug 2024 04:20:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3B9B6B00CA; Wed, 21 Aug 2024 04:20:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B6836B00CB; Wed, 21 Aug 2024 04:20:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 69B4C6B00C9 for ; Wed, 21 Aug 2024 04:20:12 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1FBBBA09FD for ; Wed, 21 Aug 2024 08:20:12 +0000 (UTC) X-FDA: 82475555064.17.C0B5D89 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf18.hostedemail.com (Postfix) with ESMTP id 42D6A1C000F for ; Wed, 21 Aug 2024 08:20:10 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GdfPQOzZ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf18.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724228345; a=rsa-sha256; cv=none; b=4K/YdQYL0mnRDy6uDg8/L+vMY1uQeC1P/zSgAHpmbg+F26Wu0JRfnmaP734UrkEVwI/ADr iqKzlBwoXGNscVBOpMv+G2Credd/KnVTt/Xx6YF//aVw8fkuAU0z7FH39SFYby5crEfH27 pF/8jXfZAJCDx1mQEvSDDTT1YIqhg9k= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GdfPQOzZ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf18.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724228345; 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=xk5nZGQoU/UHicxrt5T+UXYIL6+4L5PcGNmpQKRqaJs=; b=YdCcCkk6zSbwmbSlY1+JvLK03OLkG8GF6ixb/M3UkNLsmQ9VJNxd7s4xJytEvZ1syhtyCq GLx+8bwXeWNb8E0SF/2LH+L+Nn9saYxh4qVVe+lU9UiCp6woneU0hOHc/t0yFsTIZq3bv1 wmJupctaFiiF/RHF2wV0juQnYB2SBgI= Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2d5f5d8cc01so117895a91.0 for ; Wed, 21 Aug 2024 01:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724228409; x=1724833209; 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=xk5nZGQoU/UHicxrt5T+UXYIL6+4L5PcGNmpQKRqaJs=; b=GdfPQOzZSkCDg8196kkByoENjCFu6aQ7l3aY3UPHnV2qbvpCSe4BSQ+GpjIgfX8EUe y/8T7AzfrNlbr1Hy1N9U5DtwoIQAckrcStaeNVROY1J+8N/3OoxUAXAQzej2eRzdKQKY 18NV+a7PkZbqkSq/anfqbcrkntZLXX+ibQ2FFRUvOeZh8U3LBXy0AdQNYwemmsrU5jjS mqZfuiWDlOlUhDM32d+vgel10qxE/AJREf8K8mEFO8ctPJL0LQGQowqjBW4/P6jFkRvn AWShaNU6oy7Ns0t7W4gzOVtB6Y4R1OABDTmbnGoib4iAYcQmPYGeGWekY+hDweLdx6ZB FA7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724228409; x=1724833209; 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=xk5nZGQoU/UHicxrt5T+UXYIL6+4L5PcGNmpQKRqaJs=; b=sqIEHU4HEp8sfM2dR3KsYz0rnbMROidEhK4H+suzZXe+AwuwxtiQC44lswcgomS6jv X3sQIMGcermi1sE7Atkhz+yoUXJH5gN60dRJU6Bcenu9z37F+K5OkjHoSchbOZveu34C CEoyt/34fpWUQx7xEqtLPO/exTmLxCxS+l5wIXC/GodYBnNyLLe4lfO5I3eJO7wJ2akJ yOnrquO0CxtlCtqjFdNAvQaHqXXripGqdO/gH6zo/CrWNIvsmLl5fK2o8+hdIxBal/QP UvByUGNHlpjpl/Lsw40R+KIWZUSBCDaR14C2krRjwuRlm3jnaqIKfvGhgmajTU/fCVCU Lzjw== X-Forwarded-Encrypted: i=1; AJvYcCXOZh7pNKqnNxfTCMunO5UGO94CTNvd4lE3ITEegUeM9ZWohLe8BPs7FhOA6sgA2kkDx99QxjZICA==@kvack.org X-Gm-Message-State: AOJu0YyLLjr9vDYR80nR1YGVGBTnWne9SQRGZ13AR1CxFT0F1jEIgaBy 14JkSx7k11lAD/PAQELArALezacXYODOdtHQGrt3tWGV8ysWE2hFbpUZRfs97Ao= X-Google-Smtp-Source: AGHT+IEz6hEUMU7QDWWn6q3mNXap3/YJ5XtpoR3UgLNTk8qimJ6ZhRH05YhkApxF5Pk84JIDmuV6pg== X-Received: by 2002:a17:90b:4a10:b0:2cb:5dbb:d394 with SMTP id 98e67ed59e1d1-2d5e995c932mr2717849a91.4.1724228407428; Wed, 21 Aug 2024 01:20:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d5eb9049b0sm1091453a91.17.2024.08.21.01.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 01:20:07 -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 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 06/14] mm: handle_pte_fault() use pte_offset_map_maywrite_nolock() Date: Wed, 21 Aug 2024 16:18:49 +0800 Message-Id: <239432a0bc56464e58a6baf3622fdc72526c8d57.1724226076.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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 42D6A1C000F X-Stat-Signature: po7cjwrskxf4yytojusxmrbb11nrkpsw X-Rspam-User: X-HE-Tag: 1724228410-819239 X-HE-Meta: U2FsdGVkX19ziTKsT7BeZvATQSAGfGk3mNUpc9sjQqmYpg3A7vJDkktwYN14Lajhn1+Jnzh1uT7YsO1Ykv2O3TZOssMqM36KLs3Xtd0VgEyUhqutLzKIVxKIWTdQrlPRonqXJGI9t+0sD+WUFz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yDyEsr0wG2DtVQlZc5W/Yh2cc5B92DlbIPDu3XQUuLAZkPbGnvm2lBv6pS1fiCxgoSrPj8Pp8KIfNPha7HRI5MupifABJjIV9EBxkO6/342PS1uG9JlpKeE52ULscvUNG7W0Cb0BSlSdAPpI2eJk6U+vNt341uXNzNEkteNmoQeOFz2wPB1zEzsytArooY6zG5vKQBvfmlw== 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 handle_pte_fault(), we may modify the vmf->pte after acquiring the vmf->ptl, so convert it to using pte_offset_map_maywrite_nolock(). But since we already do the pte_same() check, so there is no need to get pmdval to do pmd_same() check, just pass NULL to pmdvalp parameter. Signed-off-by: Qi Zheng --- mm/memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 93c0c25433d02..d3378e98faf13 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5504,9 +5504,14 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) * pmd by anon khugepaged, since that takes mmap_lock in write * mode; but shmem or file collapse to THP could still morph * it into a huge pmd: just retry later if so. + * + * Use the maywrite version to indicate that vmf->pte will be + * modified, but since we will use pte_same() to detect the + * change of the pte entry, there is no need to get pmdval. */ - vmf->pte = pte_offset_map_nolock(vmf->vma->vm_mm, vmf->pmd, - vmf->address, &vmf->ptl); + vmf->pte = pte_offset_map_maywrite_nolock(vmf->vma->vm_mm, + vmf->pmd, vmf->address, + NULL, &vmf->ptl); if (unlikely(!vmf->pte)) return 0; vmf->orig_pte = ptep_get_lockless(vmf->pte);