From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3571C369B2 for ; Thu, 17 Apr 2025 12:05:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5A7B6B029F; Thu, 17 Apr 2025 08:05:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B08426B02A0; Thu, 17 Apr 2025 08:05:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AA886B02A1; Thu, 17 Apr 2025 08:05:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7BC096B029F for ; Thu, 17 Apr 2025 08:05:46 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F0AAEB37D2 for ; Thu, 17 Apr 2025 12:05:46 +0000 (UTC) X-FDA: 83343406692.16.0AE269D Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf02.hostedemail.com (Postfix) with ESMTP id 3354780012 for ; Thu, 17 Apr 2025 12:05:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=B4M5w1j+; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf02.hostedemail.com: domain of gavinguo@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=gavinguo@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744891545; a=rsa-sha256; cv=none; b=EIYy+UtCaUwK4u2j4tmNO6B2VUOoY0LjV9Wm+18DwLrz74201H/KPD2llYDomQ0O1mc+u1 aa1bg08GUMQwMzbga4RWqhZcpwY/dycW6H+q2S4e3bFC/UYyxScVyL9Z/wJzZ5xKi4F8OJ UpIEAtUh1x7gXoOo7dY+cfCwqV1lw6c= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=B4M5w1j+; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf02.hostedemail.com: domain of gavinguo@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=gavinguo@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744891545; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i5SGbSmQ/nSdHKVfpPRTT0tr56mPKmGz+8C1VufgiV8=; b=f4VivW4yQSOzZRxKfDABqFbJBb5WmKPoaHbVWesNUuPTuMVmMeK7U3JjgJp3/dN81YUQnW QET1mifJjB5+PnCSbZMMNXM/wD20yF4lM7JuFgqNNUMSZNUQWD1PygHzw/n9ejz1Jzbiai UMpsNvAe+jfX5IE4ULgdVtcNuYuAZVU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=i5SGbSmQ/nSdHKVfpPRTT0tr56mPKmGz+8C1VufgiV8=; b=B4M5w1j+mLC/XBlkLHgbz9Qtyd 1ZQJax4X/Yn9smfWBKDMnR/oqSbN+SLVMU+Vn4rpjQ27zHrwFdl0xn2IThfvtOPOiddgsw+V1+MQL /U7T9lQtCfBVQc+9qGMLmOmZMAZdVJTwTTvmS7L0gvDXoK6PlQgs1iN+1d+7re+w2RLy+46PBf0kc +OvNpvjgz9uNqYYwpNpmS+ihpZPsVWgrn+tAY6vdAZlk9VaBqndmLF3DGHBrNaPRAOqlq0KREE1nH EOPcTEuRaxdoEev6t50902ab3IznhUkGbPiKrFiut10AKNAG9Lpbf4akXuCGku0QjWHQF1N3s0R79 Cw/ngwgg==; Received: from 39-14-49-133.adsl.fetnet.net ([39.14.49.133] helo=[192.168.220.43]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim) id 1u5Nzx-000nJ1-BZ; Thu, 17 Apr 2025 14:05:41 +0200 Message-ID: <4f9a5c91-6410-456e-9a04-702f8a343a13@igalia.com> Date: Thu, 17 Apr 2025 20:05:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/huge_memory: fix dereferencing invalid pmd migration entry To: David Hildenbrand , Hugh Dickins Cc: linux-mm@kvack.org, akpm@linux-foundation.org, willy@infradead.org, ziy@nvidia.com, linmiaohe@huawei.com, revest@google.com, kernel-dev@igalia.com, linux-kernel@vger.kernel.org References: <20250414072737.1698513-1-gavinguo@igalia.com> <27d13454-280f-4966-b694-d7e58d991547@redhat.com> <6787d0ea-a1b9-08cf-1f48-e361058eec20@google.com> <83f17b85-c9fa-43a0-bec1-22c8565b67ad@redhat.com> <98d1d195-7821-4627-b518-83103ade56c0@redhat.com> <7d0ef7b5-043b-beca-72a9-6ae98b0d55fb@google.com> <05a7d51e-f065-445a-af0e-481f3461a76e@redhat.com> <4828e28d-eb56-449b-83c3-b5b2dc2ac6e2@redhat.com> Content-Language: en-US From: Gavin Guo In-Reply-To: <4828e28d-eb56-449b-83c3-b5b2dc2ac6e2@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam10 X-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N+0xt8y hnyHoBxBYG3TORWq1CPl+ZDqIyn48y1y/bdI7DfUMIQ2UufzBSvNyTOd3iVC8kmCukE/C3FNMwqVY4DMasZmDbCamSczk/NzJwalJmgJcMcLsoqbzb1qlGy56Clmg4WxvdEwSTDzy0r90cL45yVriNA8IQ53lDBGj2l29l7BYS+BnlcVqxFiv30IjSMGlPqANxsadIuQPixJoyF0sKsbMVf9Y7ClWXG8ngHu+qMFtciKONg+C6ndtzR9nBuoNH8d39puAOoQ4Dr2e60tXCP4bbPWLLHCisHocVVEtpfQK9JwtQCexqLJyDE4+4SCkcMpa7fW80Z+1HuyuAzhkwU+FYPTHWTr5REr5w57CYpuSTWCgeeg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 4/17/25 19:36, David Hildenbrand wrote: > On 17.04.25 13:21, Gavin Guo wrote: >> On 4/17/25 17:04, David Hildenbrand wrote: >>> On 17.04.25 10:55, Hugh Dickins wrote: >>>> On Thu, 17 Apr 2025, David Hildenbrand wrote: >>>>> On 17.04.25 09:18, David Hildenbrand wrote: >>>>>> On 17.04.25 07:36, Hugh Dickins wrote: >>>>>>> On Wed, 16 Apr 2025, David Hildenbrand wrote: >>>>>>>> >>>>>>>> Why not something like >>>>>>>> >>>>>>>> struct folio *entry_folio; >>>>>>>> >>>>>>>> if (folio) { >>>>>>>>    if (is_pmd_migration_entry(*pmd)) >>>>>>>>        entry_folio = pfn_swap_entry_folio(pmd_to_swp_entry(*pmd))); >>>>>>>>    else >>>>>>>>     entry_folio = pmd_folio(*pmd)); >>>>>>>> >>>>>>>>    if (folio != entry_folio) >>>>>>>>          return; >>>>>>>> } >>>>>>> >>>>>>> My own preference is to not add unnecessary code: >>>>>>> if folio and pmd_migration entry, we're not interested in >>>>>>> entry_folio. >>>>>>> But yes it could be written in lots of other ways. >>>>>> >>>>>> While I don't disagree about "not adding unnecessary code" in >>>>>> general, >>>>>> in this particular case just looking the folio up properly might >>>>>> be the >>>>>> better alternative to reasoning about locking rules with conditional >>>>>> input parameters :) >>>>>> >>>>> >>>>> FWIW, I was wondering if we can rework that code, letting the caller >>>>> to the >>>>> checking and getting rid of the folio parameter. Something like this >>>>> (incomplete, just to >>>>> discuss if we could move the TTU_SPLIT_HUGE_PMD handling). >>>> >>>> Yes, I too dislike the folio parameter used for a single case, and >>>> agree >>>> it's better for the caller who chose pmd to check that *pmd fits the >>>> folio. >>>> >>>> I haven't checked your code below, but it looks like a much better way >>>> to proceed, using the page_vma_mapped_walk() to get pmd lock and check; >>>> and cutting out two or more layers of split_huge_pmd obscurity. >>>> >>>> Way to go.  However... what we want right now is a fix that can easily >>>> go to stable: the rearrangements here in 6.15-rc mean, I think, that >>>> whatever goes into the current tree will have to be placed differently >>>> for stable, no seamless backports; but Gavin's patch (reworked if you >>>> insist) can be adapted to stable (differently for different releases) >>>> more more easily than the future direction you're proposing here. >>> >>> I'm fine with going with the current patch and looking into cleaning it >>> up properly (if possible). >>> >>> So for this patch >>> >>> Acked-by: David Hildenbrand >>> >>> @Gavin, can you look into cleaning that up? >> >> Thank you for your review. Before I begin the cleanup, could you please >> confirm the following action items: >> >> Zi Yan's suggestions for the patch are: >> 1. Replace the page fault with an invalid address access in the commit >>      description. > > Yes, that makes sense. > >> >> 2. Simplify the nested if-statements into a single if-statement to >>      reduce indentation. >> >> David, based on your comment, I understand that you are recommending the >> entry_folio implementation. Also, from your discussion with Hugh, it >> appears you agreed with my original approach of returning early when >> encountering a PMD migration entry, thereby avoiding unnecessary checks. >> Is that correct? If so, I will keep the current logic. Do you have any >> additional cleanup suggestions? > > Yes, the current patch is okay for upstream+stable, but we should look > into cleaning that up. Ah, I understand. I'll clean up the current one and propose another patch based on your RFC patch. Thanks for your review! > > See the cleanup RFC patch I posted where we remove the folio check > completely. Please let me know if you need more information. >