From patchwork Thu Aug 22 07:13:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13772829 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 120BCC3DA4A for ; Thu, 22 Aug 2024 07:14:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA4128000D; Thu, 22 Aug 2024 03:14:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A074980009; Thu, 22 Aug 2024 03:14:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E3628000D; Thu, 22 Aug 2024 03:14:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5312880009 for ; Thu, 22 Aug 2024 03:14:26 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 14C951A0FDD for ; Thu, 22 Aug 2024 07:14:26 +0000 (UTC) X-FDA: 82479018132.15.7EC5273 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf20.hostedemail.com (Postfix) with ESMTP id 3D7321C001B for ; Thu, 22 Aug 2024 07:14:24 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="FT/YbMZC"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 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=1724310774; 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=YTJMrM+GLhYLeZwUuiK6dImcBAbTGjqYt196yQPATUA=; b=2ZSe1v9Daq3dSdEBawOkERjAEfBJuHfwnNp3ww2wHnE9xdImVWY8MT7juFwmNM6Ur0dRby xFmsMiAKLlAKSUgTXLFX1f9t86vxIteLBou8mriws3mWOw1HZnn31TSxJeLys1grWlNUOd /CUGp1FP/QCdYp8y0XsP588SHRmiado= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724310774; a=rsa-sha256; cv=none; b=g9GxJFz6DJ+nws8fP1910N75rzQ/MaqIV9gR42Vrv3K/y2srv6GmyMV/a4GyDe7Rv6KGBH FhVgSGJcLR/qQiOkS48evIXY8jqUwJty4M3TdDR/wfhHrnbR+DDKjSqCEm9bEW09HlMhrT jMnpxcf8kOdAvff3EeZQTs5zyr7J2qo= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="FT/YbMZC"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-714186ce2f2so440769b3a.0 for ; Thu, 22 Aug 2024 00:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724310863; x=1724915663; 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=YTJMrM+GLhYLeZwUuiK6dImcBAbTGjqYt196yQPATUA=; b=FT/YbMZCmX8vy1afyzGZ8OIkqB7ejguMMWhX2gOTEtbh1lqP9nzP9SKB+g1eI/BLQb g2F6Bw02ejDLVWcUucz0MfDibovB5TgWCtHibjGno66MVnBUlXdEA6BsmhK9AWJKcL5j oLq/PNKF7X9SUntvvAagD/Vd1afVaJ4Rwo0g4IMbOY80AP4EZsk0/HQWrvvqe8KGUR7M M6k3ANcuveopFVRxsA2W+ve/pifmXZalQpWIYvBCuaCiAQvWLHXNaa7uWuVM4J//jDZd X5sApl0EVQc4l4qcql6kfF6NIDVZ2qWjgZxN/KhSbDVLm/Tlmw7Y/nblzdLtYBOhlLlf pOIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724310863; x=1724915663; 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=YTJMrM+GLhYLeZwUuiK6dImcBAbTGjqYt196yQPATUA=; b=KXXGMcDbvL09adYvWPekeAqnnhxN4f4Npl/XyrnmtI6z9WGZ67aJqh4VsmqbKiTpJC JAB+ExmbwVLLmtVVDs1iJbpzPHWPxEdcVBkmsBhs6XNy/YgmMQwuWiA4PG2jF0hfFZik iKGAr6rSvIoxh1I9FOmCFHzKsKtdK36a6YldmBI02gKfX6tVtorYdBiLHNsMEnlyQp5N 21kqDBIhFtBi7PKbTrQioGZByw4xCFsGThF0vMM6T4rZ6ywtTCvGJcQsJ5MwqHbTqqOK WXkjdNU4rrwP2FQ+5EPHsZMBqx2Ew7FBmLf/4P78LZUHvGybfnwY8GUwxRxzFwasTsZE 3ONQ== X-Forwarded-Encrypted: i=1; AJvYcCVkHPV3MzZUl6BQk8JcM4pKx6LA8dhV8NHuIrFD56b2+yXw830wtw92oOxq5MnAcQo8vwGt5SM0Jg==@kvack.org X-Gm-Message-State: AOJu0YzGeYZlmPe7nJBKeXipleQh7Fiviawv2kQF7NIr4bV+xf/Z2Icb 6zo2/cCqJGZOQpUEjwTJGSIdZCUtie3OewnyFDRkQqzZPT7BIoGaNG/2j35+YUY= X-Google-Smtp-Source: AGHT+IEJaUpX6CQIEutPHebqIOZXfyMaKxdLW1UElMR3gb10gY3PgzFG7UEaK+UwdtskMN8KUpfIGw== X-Received: by 2002:a05:6a00:cd4:b0:714:1bce:913a with SMTP id d2e1a72fcca58-7142356e960mr5852557b3a.21.1724310862916; Thu, 22 Aug 2024 00:14:22 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:14:22 -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 06/14] mm: handle_pte_fault() use pte_offset_map_rw_nolock() Date: Thu, 22 Aug 2024 15:13:21 +0800 Message-Id: <5acabedfae7ded01b075960b4a91f2e15b4d76b5.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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3D7321C001B X-Stat-Signature: asxgnsa8uzeb9cu4hedy86bsdr8b3x6b X-Rspam-User: X-HE-Tag: 1724310863-585179 X-HE-Meta: U2FsdGVkX1+qBedf54p6VMR6/Dgl49AtwCtNQgwkx8pW19uZxvcLryFlYqGn8HtIkEx7vQogCrOQELOJ8c8E9PU2L9cvrzUZ3TTk2zSJBBP6brTrb3AsEcJOiYXYdKsh5j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c9FIIWlVxN9LGxUKmveWCcFtStjeSDnVGI52xfr9W2y4SG86KD45LpTPLKIpSSUd4RIOPhTCdN2hLXbE92Jh7jbdIzyru1HY+2tbd13OuxwyKdkZGVbjrGTvYxZyEMv0p06sD920HLmRnfkoxL28mA8JHUMPkZGdr+xKrD05mIHAY6b9DEzc5Oe9Sulp1clzKFeyFon/ktUUnR1Wa8072Fx5Q5VxYZzazjCjSOkP1+D 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_rw_nolock(). But since we will do the pte_same() check, so there is no need to get pmdval to do pmd_same() check, just pass a dummy variable to it. Signed-off-by: Qi Zheng Acked-by: David Hildenbrand Reviewed-by: Muchun Song --- mm/memory.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 93c0c25433d02..7b6071a0e21e2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5499,14 +5499,22 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) vmf->pte = NULL; vmf->flags &= ~FAULT_FLAG_ORIG_PTE_VALID; } else { + pmd_t dummy_pmdval; + /* * A regular pmd is established and it can't morph into a huge * 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, so + * just pass a dummy variable to it. */ - vmf->pte = pte_offset_map_nolock(vmf->vma->vm_mm, vmf->pmd, - vmf->address, &vmf->ptl); + vmf->pte = pte_offset_map_rw_nolock(vmf->vma->vm_mm, vmf->pmd, + vmf->address, &dummy_pmdval, + &vmf->ptl); if (unlikely(!vmf->pte)) return 0; vmf->orig_pte = ptep_get_lockless(vmf->pte);