From patchwork Tue Sep 24 06:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13810168 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 BE389CF9C71 for ; Tue, 24 Sep 2024 06:18:54 +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=88oX8R3xcxvOkzUvzbp2hva7xyyimZKCI3msRz7gwSQ=; b=mY+j5WaRObmxeTc6QNxImUCg4+ y6SqOPZVKUUptI7DRcwYNDEdSmzK1rjk9iYv1cIAWBQpjwUfLVpsgmfs+dM1hKzzEh43TlyuB7FHb Hx2cOR0hSHlRwoYmKNwR5jzdXcVTw6hkNEHzVnwzI/1GrtsNp0/oCQ8aY2McfQi3r37rFfJFvBd1W WVnVcWGAm5j/qSkdX8h6XbpWR7rCw3RqqwfZ/GAJwHmlOts52JmjBBdIkoSpqsTSiX2orbY5fshfS LUDSqSbcCFgy8GNUHQX59f4xW0/YobxdniWT3NyFudfzu4RMWUb4tWYMFo0NDHSQqbiLMLwQ7KNaJ +abeBXLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssysn-00000001Dro-3NBk; Tue, 24 Sep 2024 06:18:45 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssylO-00000001Btn-3pBx for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 06:11:08 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2055a3f80a4so32066595ad.2 for ; Mon, 23 Sep 2024 23:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158266; x=1727763066; 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=88oX8R3xcxvOkzUvzbp2hva7xyyimZKCI3msRz7gwSQ=; b=fcuG6MXcbXlKzUCF1Fn1/3zWDsry0M6wkznXq5/mwudxtIM7vsn6WdTMUH7+B3dfDe SWtxFMcpU23c/BQyeGYRN6xgJhFUggR+9XbEkelYGkkB8DkZSgRv0V+YZ/fxH+fFyKiH F+R/VSqkbAxxueUrCJ8oKSivEmxUo6qCKslhUwwYUM108HGFLWOMChTBQc7urG6Ej7w3 WfQClRGWhRX9zTEepBxFdftDgEEOBTvSMjdHu/l4Yre7Yky1X4x7QD/pVozWJiPdwlic XGe3v2fmVGMdogxadLiX5qb5WYCdwomRvqAdCIWUWm4nxE9IUA4PE68magUxQDpu1exL X/JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727158266; x=1727763066; 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=88oX8R3xcxvOkzUvzbp2hva7xyyimZKCI3msRz7gwSQ=; b=T+Pl9ex9GjNfhde9Ndoc3h8g0abzJ7b6i4WIkXaYsDCvf3zhSOUKBBrHISn2y68PWi Nqt4RXevZCyK8RLtLpSBplttX/dFCXRWvXwX+OD5ol5pbLCYSuIaYC0Chf7rD6kBKpns y6/k6HyrYDRHroQEgEb0wNQBXX2gqnfokgjx9iG9Vjs5DasmZXSsXptD+0rSIgjWFCDK e588EDPKJTMp1nBd3fHEkcQGlOxR5T36SlLeU4DymunAjG8nv31a7X2sQx+NiKZky9Rc C/+HGwywaVojJlBnpKHC6t4h7fD9P+zUAirKh40BdSTaWpF7tdppswTCIByw17xPhatb Wd9A== X-Forwarded-Encrypted: i=1; AJvYcCW98IKAtCNWbopXARv9Rnj6wZRy5Sqo1sZ4o3E26K7VeDk9+01NR532GjzHhZ9VtPnOOTGtNfWDaEd4byslgBMY@lists.infradead.org X-Gm-Message-State: AOJu0Yym2vtvxC1kKg/8j9sFS57UNKeHbGb6A+OfWB4UKL1PrIYaiykP xGl1PaLShZPq4SP8yFR6jtLQf+uVATgltJmKBJ/VUjfNS841Eztq4jJ7oFUP7sk= X-Google-Smtp-Source: AGHT+IE0gKFIx3/KW4QPIJwQt51ZMLGla2X2YU2KRRy7vcX0w9t/15+gAAip1FE70+J7SP+04M4CVg== X-Received: by 2002:a17:902:d511:b0:205:7574:3b87 with SMTP id d9443c01a7336-208d980bb34mr182109485ad.15.1727158265764; Mon, 23 Sep 2024 23:11:05 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20af17229c9sm4344885ad.85.2024.09.23.23.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 23:11:05 -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 v4 06/13] mm: handle_pte_fault() use pte_offset_map_rw_nolock() Date: Tue, 24 Sep 2024 14:09:58 +0800 Message-Id: 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-20240923_231107_004535_AF2330CA X-CRM114-Status: GOOD ( 14.27 ) 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index a245d28787034..6432b636d1ba7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5750,14 +5750,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);