From patchwork Wed Sep 4 08:40:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13790094 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 863F2CD3431 for ; Wed, 4 Sep 2024 08:41:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20A7B6B00D4; Wed, 4 Sep 2024 04:41:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 194226B010D; Wed, 4 Sep 2024 04:41:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED9A88D023A; Wed, 4 Sep 2024 04:41:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CA1DA8D0239 for ; Wed, 4 Sep 2024 04:41:25 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 940D6A0D99 for ; Wed, 4 Sep 2024 08:41:25 +0000 (UTC) X-FDA: 82526411730.28.807F05B Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf09.hostedemail.com (Postfix) with ESMTP id B35A9140007 for ; Wed, 4 Sep 2024 08:41:23 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IRn1vXPd; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725439259; a=rsa-sha256; cv=none; b=MssZxNvCSqpGW/+0Zl7Ie5HjxVQQJzjfJFbSdpAXAD37lnLMWlVyvBsm4Y5krnMzmIY0r4 b7Y8niryC9Q2tklyBW09Af87aAqBMlh7ft8c0GkVm30dTVwTS3l77B3YKQjt6+4CA4u6sh jKjtwxwBMLUo5y5KoyC5qieycji9QQk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IRn1vXPd; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.181 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=1725439259; 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=pGIEfQHzsThgJvUA20OC+gjd0SFgF9+h9gc5ip8dlng=; b=CTeZ0lEmScXl8BHQXH3U/XodnKr+RuF/PvFFuXSqXVfm2KLTQWa69BsKxdVMvOvd02SBYr t7EEqb6tJ0QBh9vUvpWv50YkfpszoKAcast+KBuADtT1ODA5BUmZfmDOtZ7048SW7bBuyD dMiToVMruvLG0V0SQRKOeUzFLQlqQ7s= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7cd9cfe4748so4059127a12.2 for ; Wed, 04 Sep 2024 01:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439282; x=1726044082; 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=pGIEfQHzsThgJvUA20OC+gjd0SFgF9+h9gc5ip8dlng=; b=IRn1vXPde4dKciOvXjUjpRHyNbvoGRqb4a8HghL5hxv9JMvydDfKS78AYsMtnoLZhn xMvONTEPQMzGdLU+Twcw9UxJC1zxrz+az31NmFllgigXEoazNhC4u3PWlQPSzd1P6a2v gN9/lFUK8pIW5vDw6JD0ehaA4Tgs7DHrwvTBoBXBKCskWs/BoGhvLmO+oXnVzzGzj6Cr FyoQ4P2QXMC1vqbcNHUGIyG5XpZm2uNmVATA+QrLMRGUdUftK5d1qP9YyX+XOtB4SBC8 T3edEPuQtibg34Xj7CdDg/PL+C8xuozkrXOW5h4TPiAfZJ7ry9OTYMinVvjpqQYUGJrN xP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725439282; x=1726044082; 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=pGIEfQHzsThgJvUA20OC+gjd0SFgF9+h9gc5ip8dlng=; b=ZDxafyE2BF7jA2Gw1YOBkt5FCsmOC2SFjiztHEcdBPpiReDGDoxAOktS+iFzRxyYd3 pVMLLZwrUENfzTLc7Qc9686pjYThpmFzxBQ78XgcbIfaSQCzrvuCfEzeteJfvoEUW9rY 402mgL0hFNhTX79qtf7W8yzywkq+brdx+L4kA69plUfatGBR8gd9xuYdGtIuqbQ6HY1e tieWvNog4AH7GApiR+8qQvEHxeVQudf3ztFXy/8Hd33u1p6Qn+1mqgonzaJnoHMU2BZu xemU3JYDqRB2S5vwEBhnz9m0RWoSG0l4jhA7HezolXUTkfPpBYbUT8KJzLqeHN4AtYwa SR6A== X-Forwarded-Encrypted: i=1; AJvYcCXAwLSai28p+ROJIGM0BgAks+r+lEiS9QOJKCq4F93UeKdN6xmAf1sPJ+D6t66bDTluJBqOVBpHNQ==@kvack.org X-Gm-Message-State: AOJu0YyiGUXhUKqlziMMrozHnxZ55RIlQfOK7fl59hzf+2UsQ350XXiY 79iCZhw97gDFaaKbE93QV7Kng+kiqithsLSOePf7FUFgSzn39nat7R7L54Ol6xM= X-Google-Smtp-Source: AGHT+IGQLG6wPNgDOgfzFUGIly89eF+GLm9izjxQGbRYP1g8ZSKlFJK5pYdbKQOnPMpn9+eqCP/7EQ== X-Received: by 2002:a05:6a21:2d86:b0:1c8:b65b:3db8 with SMTP id adf61e73a8af0-1ced607378emr11775108637.9.1725439282360; Wed, 04 Sep 2024 01:41:22 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.242]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae95a51csm9414045ad.117.2024.09.04.01.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 01:41: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 v3 06/14] mm: handle_pte_fault() use pte_offset_map_rw_nolock() Date: Wed, 4 Sep 2024 16:40:14 +0800 Message-Id: <20240904084022.32728-7-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20240904084022.32728-1-zhengqi.arch@bytedance.com> References: <20240904084022.32728-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: B35A9140007 X-Rspamd-Server: rspam01 X-Stat-Signature: we19dw8gg5au91yp1qmhi61axemb6mb3 X-HE-Tag: 1725439283-613729 X-HE-Meta: U2FsdGVkX1+6x+cXC+WcXa7qyuqWnpirs2cZu8zmTafyXfLPeKChU7xjBBpQNg4kIXIIUZDFRYo0L11n7o+8xw0GUlWjhZ0L6qXQWJCK4RJcWQ2dtyTQMMSm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I4Sy1feMSuzDhd7h14+Lc9Wv8eh/UEBZecaBCjRmWQeQ4GjPKjMtp1vgpgSozznc4aesHmMkeIJoIpYcxb0YaKTTcX9jHPugW0zrSw0SDUU6E1nEAMHo8x6sBusFa3oIOVjXDPV0v3Eaj2TUehly/ierFfcde3Wo/626WhMw1sL1RFTd/7RMASNKdqlr7sgeoFIIl+5hSr9QuLcaBAT/7bi2FdQCel5/A0O1yKIzmWRS3xIyvLItg1kRIuUY= 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 42674c0748cba..06674f94b7a4e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5498,14 +5498,24 @@ 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 may be + * modified, but since we will use pte_same() to detect the + * change of the !pte_none() entry, there is no need to recheck + * the pmdval. Here we chooes to pass a dummy variable instead + * of NULL, which helps new user think about why this place is + * special. */ - 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);