From patchwork Thu Sep 26 06:46:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812888 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 3CDABCCF9E9 for ; Thu, 26 Sep 2024 06:56:40 +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=nb9n7E67s2XhOAzaJJIvK6ZLpZ mcx9W9U359Zo9IbE+svY5l9rEL8Tc37G7ixA6IVDT2qa2gkmmB3mdJE0d7kOcCMzVBUH6cbb8JV4Y C2KNMLNTJFU3l0tEvQWNmJHfV4HjqKdue+ItN9qHYETqQdGMav4FLrauZhM03E8Pof11HL6S1MJKr kbefHJ9QWgZ6y5l9R4Dp3xV0SQgBbBgf+oZrgcGhCnIT4uS2BPxKQZ1Acr4Hzf+7Nf66uy3VHlE6+ cuO3gb05SRdz8JbMlladKfW1Eax0HIfqJg+Z65MN7MUTCgTNHlP5GHbbOpbmJL7qhZqBaKYmMwVqS VtPaS6BQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stiQP-00000007Pfm-42xr; Thu, 26 Sep 2024 06:56:29 +0000 Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stiHn-00000007NS7-2PgX for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 06:47:36 +0000 Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-4585e250f9dso3064871cf.1 for ; Wed, 25 Sep 2024 23:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333254; x=1727938054; 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=gseWG6ZFpn/oU53572WELno7DYvQ/nYjpuC3dMPwVnkzd9hXXBwUQggSNS4kgpxVQo yeSzui97RdGo5FtLxFQE/ediKpQVzu9i7NCbsARpgDk7nijZoDamHE8v+niJ7RJxFEpb pCjQzWd8rYxX2BLGiRkYUDMkXkWdfLyN3FPS24LkXVv5RRmI2A/K+kcNAm1EMkBkI0xv THYVgsjC9iEt1rj7lupHAgB5CyXTXEo4IUQyHU0hkyx9GGNOlmefn9cspI6hxOzjWxwS WPRDEwb0kFQdMl35d+2116XGhWKA8+BAH+u+3sLumLTjgR5BbuM2ulneRyG7wgLDGgHj AZ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333254; x=1727938054; 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=GageM00VItgBgVa8VEvGDck8HbxLbfyYaS3YjmIRtEG5Qzh0LnSQbdXr8XyJlF9OpQ RBoQ/AjGjT3KbtugCgInEwVM5vW2HrXXkbNU9JAUTeK1G3Yaa1GAwu6LaRtXkvGIxBnv vlZQjbyEdpwtPYJRUyJfYw+rZAQgNBxfIB4fAQOfRCIhihVfXwluW7tVzzDhwlVvVfeO JisT9xRu74OX7OB6nFN4m4qd8l1Ai7sk59PI957kJ0Q7Z2085RSzZQUJaa/xn552MUNG wS1j2ha5BItWz8ERus5/7UnAQWihd/pw04eLQBu90lzVnCi7/fC0QK9io3SU+oQRssvH 3bUw== X-Forwarded-Encrypted: i=1; AJvYcCXQ1TDhKPm0hHJCyWkXUFq6C49WRpbounJ3+mhWvMWA5DwRZr7tUXE0dxVmpbD4Kw/mRK2DqeaspW1sJJBrVQSU@lists.infradead.org X-Gm-Message-State: AOJu0YxmEYQZPwmpJYJ5aWpFL/0YMIPTpDr6v0PqCMvm6u4JD/p5qM8N nhOMQxI8TO7LQL/fqokssTl6hCM8l6XlnuOaVFxdM5GJX42JwJwyKVirg9iGYAY= X-Google-Smtp-Source: AGHT+IEkNfjkqcOSOf8WFqyh7ycpXwLGwDHOuzbRwWfPgE4JYY85w8LbZC4JktZjOBGqNKfXWcA2mg== X-Received: by 2002:ac8:5a43:0:b0:458:3824:a083 with SMTP id d75a77b69052e-45b5def43dcmr69885101cf.32.1727333254117; Wed, 25 Sep 2024 23:47:34 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5257ff1esm23024611cf.38.2024.09.25.23.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:47:33 -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 v5 06/13] mm: handle_pte_fault() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:19 +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-20240925_234735_659889_76C6B2AE X-CRM114-Status: GOOD ( 13.78 ) 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);