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: 13772870 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 505B8C531DF for ; Thu, 22 Aug 2024 07:19:39 +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=YTJMrM+GLhYLeZwUuiK6dImcBAbTGjqYt196yQPATUA=; b=lnfcOodVVAADL1fIDr6J7rZUKD yINvwnfCYtVKWzfx94Y/u8OJ9FnjC9dXOtOjh2XXXKvptqIlbqmzgfimuwG5iAJB4YW6MUihR8AA4 BPXwajcNVceIo5hUGptPg4yAgoNmMzGlnZ3bUZh8G9edU1NXU80pTsg+CkdrBXvgGIa151zYkDr6v fLx98yTTGd9oJF0gMlwItP5nD6CM313iKK4OUx256cuUTM8SwUHZ/wH4bTCd7cw26pdcFvGTiIeDj BdrRNJoWR0RF9U5rV/tyGEn0scoE6AUqdPEr0hOT0TwAvneRjsVJA5ijOLdBgBDucn3XzdfJ27Qnf /GpL7ujA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh26R-0000000BpM7-1pqq; Thu, 22 Aug 2024 07:19:27 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh21Y-0000000Bn3k-0KcK for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 07:14:25 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7142a93ea9cso394348b3a.3 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=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=YTJMrM+GLhYLeZwUuiK6dImcBAbTGjqYt196yQPATUA=; b=KV5a4q0pSLPYlBSNjm+kGIpEDvZ3pmtNnHufz/3cqo4kmnPsV2zo0BHycWwXqe+RIg zn7CllPEn6tRBkM2YUEXSI8KuutXUavI5Ykt7ya6MCIfTuEK+pv480bN9gyq6hucBb9m jkOvStK/sLEw6H3NuQ9g7yMIURrFSd+bQ9bHpm7lLOdvPeuDhSilpq7dd8nnoYhk+8Qs Hh/b6PTYSbVmT3wLZXmmILJ2xzP/JDRQvmQjr+BBbFPVcYYCeQOCEWu0iH18C3HUqdeF n35WmQkHVDK17Y4rLEzts4hLcMDDURDpXR0UYJp7t+h6pW7WADargQvTSjzq6BV5bQbD loRg== 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=u3vCsTu+8U0o6NvecXzy1gIq6b0weizqde539NUt+a9HJaPoSCFmmfSCaXZXtIWk8z zCkRy5E3DjkpMOimHR+cE4Ncr30uCldvwTKzyKDmOLXg8CBlgfaN0YTTzysMSU4lIe5M yoP+I2fi9GERvXKBBIRF3FWRxAWLWmggqjOpACQmqGBN5XOPnOCw1j1j9O35Kk82agMm bWwdoXi8se3McSKnRjOo5TlwL3BAyVA4wPu9sCjhy7tGtMc60DaVxJoF20hLcctS4jSF KtpzHG9+ZpfXPfPdDxbqoQziw7b6gRRx/j8lbEN6nPj7oVkEPJC8eGs9MDZcrLpQi8+l oRsg== X-Forwarded-Encrypted: i=1; AJvYcCUvXXqx/nghuYdX387qadUilGv3h2Llph8N7bfxLhYm9wABWVY+ELLGSOPATahPAHp7BCqb87n+zWhuTAmxm1gq@lists.infradead.org X-Gm-Message-State: AOJu0Yx9lTVF/dbOq/DhAYVb7huA6gerYKKVa66bFBEjll8MMrR0QVMb dKN4jCrXLVf9tD9A+0L6nqKVzfisGbh+vt4dFoilfkRrQqIkZgVYIfv+jHaF4uk= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_001424_166307_857A307A X-CRM114-Status: GOOD ( 14.01 ) 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 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);