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: 13790196 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 7FA98CA0ED3 for ; Wed, 4 Sep 2024 09:12:00 +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=pGIEfQHzsThgJvUA20OC+gjd0SFgF9+h9gc5ip8dlng=; b=UtISB/zQOwPZrSOpdEVX5ukThZ 2zGamhQUyEmWdE6Pjcg7MtOSrkLJz2G24ZJO2siXPktZ3o6+bMGNStkEnx2BbDCTdGZCh0qRytFCL SrxE2o7gDqD9yxDHyU+SolR6CQxOUSaxrXvl9mlhHDrGy+nuI9Oon+P55vqHO0PJHkujTZEAYlS8m p0L+QCD64kuc42P5vWWA7VRHCkTnHG1sIZOJyWA7oPINEw5g59Pv8fpl/xi7nesyV74HP25/DNtAW eUnNjszotVkYskwiDe7PXIZuuK176WacCGgKGtcR4szDBLk0mpujxWKdjHseEKQ9+NhjyMWkWMkll fSU3wgKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slm3K-00000003cCP-2rAN; Wed, 04 Sep 2024 09:11:50 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllZr-00000003TFO-1Ccd for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 08:41:25 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-7d4c923a3d7so1410727a12.3 for ; Wed, 04 Sep 2024 01:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439282; x=1726044082; 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=pGIEfQHzsThgJvUA20OC+gjd0SFgF9+h9gc5ip8dlng=; b=GDOjZ8XQ24safzyCsCDbpJEM6N6MtSg/m/8iM8f1KWf+ScV4Y28hbdVP68OdxsSAtq 4uSuTEVzrOECAXp/DxTkUwiL32CgLcEv2NpBvA7UpqPAUyKUhcWYx39Soc1CLy0+nn4u uEP6lRK/t9cyvKs0W5fnRrTS/atAqnlRbpRplBZ9us6JAj9+ExsxgZh59Cy9N+f1sfLz r2jCy6KoGIe1Dnw9jVKtZq7F7htcFgWVDqaNWx1aui/QSqnR+xaHXvq69hinR9xSZWox qEmmmOpgRDAA+jIpzZPw0jnsc+saJ2VyMDqBIGw7a6P3Ql5hW2WBGDkClKJH7BQZJUko whBQ== 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=itTFVm19o1bLLIayziXZSLhRDTu/Mr1rkP3se8CNFAQoBHfok/+TeUYUkZ/NkjFVTD udygtA5yku+hJpxiBO3mbtb+OC3GbkFAUzCcb9FE2mgrovP0SxucEdkOQ+0sc1r8hitm vAAVUJQrNAkpathsJGS8X6cQDmoePcss21aF65plMEsIKLV2ZQSx2Vqel7fYYzYWDf+W fdLVoYjgYiAaRRSEoDN3VKrPuKdho80+14PV4kx7qSp/9OlcozNr0TCRaI6oCTn6ppMe aiW/ZAvIFVvYbQ3HngOCS19cdDCSxGIvN7dhZc6BmqkTYlYUUgAIl14QSLD0bGLjfPNO NbsA== X-Forwarded-Encrypted: i=1; AJvYcCWwx/ZiqliWsUZWJxBqXj5X3ABIhhS2TOnwTU+eOtO30Y9awAdAl+qxXLKoexq7vhMPDq7pEDEj5Z4OOLC8Prpe@lists.infradead.org X-Gm-Message-State: AOJu0YwQKjLVVS5DiwC7ZL8vRivOMpGKtpCNqVq4R7/xdTqAHYp3bpRS rEsgVrzTgww4XE3qss+JrD9qWXkiUI7ZQBFQlvckA8PmGb/XHFXruyritVtiing= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_014123_364293_1FCA6145 X-CRM114-Status: GOOD ( 14.40 ) 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 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);