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 6BBF9C433EF for ; Wed, 20 Jul 2022 15:09:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C41E56B0071; Wed, 20 Jul 2022 11:09:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF3396B0073; Wed, 20 Jul 2022 11:09:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABA366B0074; Wed, 20 Jul 2022 11:09:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9D30D6B0071 for ; Wed, 20 Jul 2022 11:09:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6F097140584 for ; Wed, 20 Jul 2022 15:09:09 +0000 (UTC) X-FDA: 79707811218.08.6B7C6BA Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by imf18.hostedemail.com (Postfix) with ESMTP id B9DC41C0098 for ; Wed, 20 Jul 2022 15:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1658329748; x=1689865748; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=XQEIPKoK4Ose4pVN5SW4281GICAnAiZSwLOy+QWsPEU=; b=l8VMMgP+DFukIHRU93zXnSxLv7PwASTnfktMpJNGwJSht8djpKr/IeB8 c+aP6S/B1x8X09pCNCOyGEeSPlRRrzfbiAkahhbCkOSE32N9NJFW+3qPV i397cd9bRNY3LQABeT7x2rLZuf7+Y1TbJr76ik1zyfA94mSXoPHLfz5oW Q=; Received: from unknown (HELO ironmsg05-sd.qualcomm.com) ([10.53.140.145]) by alexa-out-sd-01.qualcomm.com with ESMTP; 20 Jul 2022 08:09:07 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg05-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2022 08:09:07 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 20 Jul 2022 08:09:06 -0700 Received: from [10.216.34.46] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 20 Jul 2022 08:09:01 -0700 Message-ID: Date: Wed, 20 Jul 2022 20:38:58 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] mm: fix use-after free of page_ext after race with memory-offline Content-Language: en-US To: Michal Hocko CC: , , , , , , , , , , , , "iamjoonsoo.kim@lge.com" , Pavan Kondeti References: <1657810063-28938-1-git-send-email-quic_charante@quicinc.com> From: Charan Teja Kalla In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658329749; a=rsa-sha256; cv=none; b=grREl72UTOfOK6RLtmUx1DWYon5bgDdj0Xxi3Cjr87LqrXnaIhccqIZRfTGC5xQd+5rgaU XQAQVKSKzlQJkbU5sr/XrIq7O/bgiVa10VKjqqamegK+c/17ypDx0ukn93KJvLgIfKytrw b2dvuxKdF0ldQ3uVHH+nPjmsqozK8w0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=l8VMMgP+; spf=pass (imf18.hostedemail.com: domain of quic_charante@quicinc.com designates 199.106.114.38 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658329749; 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=XQEIPKoK4Ose4pVN5SW4281GICAnAiZSwLOy+QWsPEU=; b=4f+8Rgf2wQ5a39WETnzliKYJr7YZB0cszsjNF/X1C8AquoEvcMlR509s1jZpMp9g9Mcq1m a14fRzlIF7BK0uVd1EQtNvXB65wHSLrgAdfGUu4/xDd4o4DrPTN5NmYi53GTWDWlQwv5ZV plsdpGQkcXcUeMhp6++QrhpwUbf/Kx0= X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B9DC41C0098 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=l8VMMgP+; spf=pass (imf18.hostedemail.com: domain of quic_charante@quicinc.com designates 199.106.114.38 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com X-Stat-Signature: y8mghmoynt973a91wange6zzcmxy6dbx X-HE-Tag: 1658329748-190767 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: Thanks Michal here!! On 7/19/2022 9:13 PM, Michal Hocko wrote: >>>>>> diff --git a/mm/page_ext.c b/mm/page_ext.c >>>>>> index 3dc715d..5ccd3ee 100644 >>>>>> --- a/mm/page_ext.c >>>>>> +++ b/mm/page_ext.c >>>>>> @@ -299,8 +299,9 @@ static void __free_page_ext(unsigned long pfn) >>>>>> if (!ms || !ms->page_ext) >>>>>> return; >>>>>> base = get_entry(ms->page_ext, pfn); >>>>>> - free_page_ext(base); >>>>>> ms->page_ext = NULL; >>>>>> + synchronize_rcu(); >>>>>> + free_page_ext(base); >>>>>> } >>>>> So you are imposing the RCU grace period for each page_ext! This can get >>>>> really expensive. Have you tried to measure the effect? >>> I was wrong here! This is for each memory section which is not as >>> terrible as every single page_ext. This can be still quite a lot memory >>> sections in a single memory block (e.g. on ppc memory sections are >>> ridiculously small). >>> >> On the ARM64, I see that the minimum a section size will go is 128MB. I >> think 16MB is the section size on ppc. Any inputs on how frequently >> offline/online operation is being done on this ppc arch? > I have seen several reports where 16MB sections were used on PPC LPARs > with a non trivial size. My usual answer to that is tha this is mostly a > self inflicted injury but I am told that for some reasons I cannot > udnerstand this is not easy to change. So reasonable or not this is not > all that uncommon in PPC land. > > We definitely shouldn't optimize for those setups but we shouldn't make > them suffer even more as well. Besides that it seems that a single > rcu_synchronize per offline operation should be doable. I too feel it is doable but the code might look to need to traverse the sections of a memory block twice. 1) with synchronize_rcu() calling for each memory section of a memblock: --------------------------------------------------------------------- for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION) __free_page_ext(pfn): ms->page_ext = NULL synchronize_rcu();// Called on every section. free_page_ext();//free the page_ext. 2) With a single synchronize_rcu() for each offlined block: ------------------------------------------------------- for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION) { __free_page_ext(pfn): ms->page_ext = NULL; } synchronize_rcu(); // call synchronize_rcu for just once for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION) free_page_ext(); // Free the page_ext. Any better code you have in mind here please? But since there are few sections the overhead of traversing them will be definitely less compared to synchronize_rcu() per memsection. But I really doubt if there will be a real impact making sync_rcu per section because,(as david also mentioned and you also corrected it I think), the concern here is for ppc where the min memblock size is 256M with section size of 16M and there is a single offline operation on that block but can end up in calling 16 sync_rcu() calls. Should we really optimize this case here? If yes, I can go with the approach 2) mentioned above. Sorry if I am really undermining the problem here. Thanks, Charan