From patchwork Wed Aug 21 08:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13771005 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 A48A2C52D6F for ; Wed, 21 Aug 2024 08:25:32 +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=xk5nZGQoU/UHicxrt5T+UXYIL6+4L5PcGNmpQKRqaJs=; b=IZz5WLov9aExuyDgjyTqQRy8dY frdrkNA0Sq1fmSAjrlGdL1JJMwfb0wPGShlgf+cnwyEzlZTxLUgVDZhqvU2R2nAhbdCnJlHok+1qV Fm0Ma8MZlDCHM44jY9Wzxdx3YolqAUi+nMmsAT4ValnX1Dv2frwYoYdsMy9asuxrK1xdAnWmR4zMX fyjL8TAPIhPZeoaNBZLOeKXfHZkpHfEHDyEkhnyTe8NDmG5/WDtIh2FFHp4wNL4+vu9Uy557XGkco FIXxn84q3ML6CSLDmlyOb6T52JdP9U7OXzF8dXb2zmHhsmV31bI+emuvGYaL6SBEY/fVG0/z1OFFt gnFCtgFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sggeb-000000083Bj-2Zm3; Wed, 21 Aug 2024 08:25:17 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sggZe-000000081y7-058E for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 08:20:11 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2d439572aeaso379667a91.1 for ; Wed, 21 Aug 2024 01:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724228409; x=1724833209; 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=xk5nZGQoU/UHicxrt5T+UXYIL6+4L5PcGNmpQKRqaJs=; b=Hmu1wH35xIwxGHHxlejwQyvZCJllXS1fJtJRnAzPxJjMhkQrUh3AP6LDGXFyFD6Z9m Ioy6miHFW+ej6W+s6HmqsecW7TK+VP6fg28Mzpo++yhLy/7ixKoYTMvd8W3KJly2p5cT KhqQoB8tJVQ6AmlBFjoSQUwB+L/wVMvoB4otGZh7yhEKOxIqgO6q/THKjJcFiFdyEogA wTCf0Rvx+TRlu1VyQnW8QlIDw44bc3O3lq/fwIEEeRJ38xHHssjdi/tTE/OuZNKefAgx mHKIWM6zlzXUBgmmc08VNbI2s6+5bo3mm88qPHXafpQBm8vOjKTp4u7K2HU7+hVEWL8Y jQMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724228409; x=1724833209; 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=xk5nZGQoU/UHicxrt5T+UXYIL6+4L5PcGNmpQKRqaJs=; b=a3I2ZUlzROlxtcOJDDVP0pGR5KS6RVOUDNJ490Hj6DwotQsTELjFB2HR8GRXyJlIGP jVKbKplw8YmqXjNyQ/oW/RslqpuC90wAlxohZp30fbCjhUbFGJQo6Rp8zQBIS2QUZpjV 9FEtRDcXyspyE0YM6zZ65dkaP0ex0JNnBW3tSrt9m1IeOLiTjAwcFgi1ZIbfKAN7kfF7 nDqWrB1HdRZ3+CIvDTVLrE1zuEwRynpfJsi2EKldCjEJ0YJV8UzPWsqn+t3ukyWhMGMF 1HddowfzrRKKv5YjZf21nyrQ5WVsQUYZUISKB9Jjcy8z1zwbKb9QNWk10R5MoA8J32pw 5i6Q== X-Forwarded-Encrypted: i=1; AJvYcCVrzpZh5w2RHRTjG6WHJ6ModYBy7geMiYDH4pzawVeRsMl5sE/11Kr8rvCRGZ52Ek7Hbt5GrrNiDjono3g91R/c@lists.infradead.org X-Gm-Message-State: AOJu0YzrLWDVha9+c5Sk0snlyDEBP88ZRBJx4GE1M7JIkJG+h4XFHhv9 Mf19zoXcXAn5+7gUbt+tcCc5l74JapTBZW0QF52wjvsOmJ3RpDTqkuteA1ZcBoA= X-Google-Smtp-Source: AGHT+IEz6hEUMU7QDWWn6q3mNXap3/YJ5XtpoR3UgLNTk8qimJ6ZhRH05YhkApxF5Pk84JIDmuV6pg== X-Received: by 2002:a17:90b:4a10:b0:2cb:5dbb:d394 with SMTP id 98e67ed59e1d1-2d5e995c932mr2717849a91.4.1724228407428; Wed, 21 Aug 2024 01:20:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d5eb9049b0sm1091453a91.17.2024.08.21.01.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 01:20:07 -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 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 06/14] mm: handle_pte_fault() use pte_offset_map_maywrite_nolock() Date: Wed, 21 Aug 2024 16:18:49 +0800 Message-Id: <239432a0bc56464e58a6baf3622fdc72526c8d57.1724226076.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-20240821_012010_083613_731DD709 X-CRM114-Status: GOOD ( 12.60 ) 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_maywrite_nolock(). But since we already do the pte_same() check, so there is no need to get pmdval to do pmd_same() check, just pass NULL to pmdvalp parameter. Signed-off-by: Qi Zheng --- mm/memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 93c0c25433d02..d3378e98faf13 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5504,9 +5504,14 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) * 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. */ - vmf->pte = pte_offset_map_nolock(vmf->vma->vm_mm, vmf->pmd, - vmf->address, &vmf->ptl); + vmf->pte = pte_offset_map_maywrite_nolock(vmf->vma->vm_mm, + vmf->pmd, vmf->address, + NULL, &vmf->ptl); if (unlikely(!vmf->pte)) return 0; vmf->orig_pte = ptep_get_lockless(vmf->pte);