Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3382571imw; Mon, 18 Jul 2022 07:10:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sWEYXO2aUMd5GkfOqw/x6YAOji1L7G61tDdMQQzxVwktSNGOA7Z7kZdVw7eUo2Fak4tmRE X-Received: by 2002:a1f:4882:0:b0:375:24c4:5484 with SMTP id v124-20020a1f4882000000b0037524c45484mr7756363vka.23.1658153442531; Mon, 18 Jul 2022 07:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658153442; cv=none; d=google.com; s=arc-20160816; b=ppi06BzwAoizPdaMtCNRS0fUgZayFg+Ut9F0+8ay47W2/tqMD88azmALh+68ppJPxc FLp0HvjAOp0qqT4hrj81/PrUJhws+JsFA3chI2nVFTywXEdU1tg+L1DzbysbVaFHqrIy cu/G+VEZgKi9YSwpekpuRPlSf3wtwdXCedvNW2kAWc20PcrPi3vp4mnW6nRS3caVjyQR poZUyH0P1YKRnDsgucP6Y/AHF/OrmsdzTU6qwwqrrQXq0SsoFC9ekLdKF4ugsdTtlnjK fReaw0fzeZqkrg6L30sXV6DlYi/3nXm/HSCvuohbG9RPBuJzJ52lJTvz6WCE0kYo1Q5q y+5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=vf4REEPL4Gjd3BgNJelj9yn/G1FQopQlzM8XP/ubJLU=; b=F3nLrRhUaiLuFYeszzuVf2hqSUcKOlsk984ZvjGitbL8u1147LV9LtvtYkzStOVgfI SA9iUH6yAGad11sNvio0KJMtVjIN5wd8+T6wZTGPbevngyAVaqkT8VQyHe9cT3GdI7Ta kgmca1c4RqLDsTRO74VSBrWnPv8y0R4cKZbiggbsk0rQoyfBmF0LTuc6B+8483sCgLNK Kz338bLSR6R4s0Bl/nNLIMyiszdm2Iztd+dj9VJp8My32JaJaZ9Slh4xEHx595kAgeak l+uWb3YrHr2oUflp6TYcqxVpy65jlInqGndUl0obfqcxbAz5CaXKuNvEHiUbqrXPaVWh EpzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b="gkXlx/JO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a65-20020a676644000000b0035731069651si1892491vsc.660.2022.07.18.07.10.26; Mon, 18 Jul 2022 07:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b="gkXlx/JO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233453AbiGRN61 (ORCPT + 99 others); Mon, 18 Jul 2022 09:58:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbiGRN6X (ORCPT ); Mon, 18 Jul 2022 09:58:23 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63AC327FC8 for ; Mon, 18 Jul 2022 06:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1658152702; x=1689688702; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=vf4REEPL4Gjd3BgNJelj9yn/G1FQopQlzM8XP/ubJLU=; b=gkXlx/JOdgSw1tJyBHzecLKQmSzw6uFbe/yGOjMRTQW5F8RM9QlNU9Fh EUYUbwX1WvUiXHoW/nJZyyOMMhplFwv0GOJlwtfVjlUTLvQCIlNHVneXY vOzwiwm6KtZB4F/iRo7XdIGGNm+ECgu1ZPgissEx8G/DXhHu4ddfQgb8Z g=; Received: from unknown (HELO ironmsg02-sd.qualcomm.com) ([10.53.140.142]) by alexa-out-sd-02.qualcomm.com with ESMTP; 18 Jul 2022 06:58:22 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg02-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2022 06:58:21 -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; Mon, 18 Jul 2022 06:58:21 -0700 Received: from [10.216.50.214] (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; Mon, 18 Jul 2022 06:58:16 -0700 Message-ID: Date: Mon, 18 Jul 2022 19:28:13 +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" 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) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks Michal for the comments!! On 7/18/2022 5:20 PM, Michal Hocko wrote: >> The above mentioned race is just one example __but the problem persists >> in the other paths too involving page_ext->flags access(eg: >> page_is_idle())__. Since offline waits till the last reference on the >> page goes down i.e. any path that took the refcount on the page can make >> the memory offline operation to wait. Eg: In the migrate_pages() >> operation, we do take the extra refcount on the pages that are under >> migration and then we do copy page_owner by accessing page_ext. For >> >> Fix those paths where offline races with page_ext access by maintaining >> synchronization with rcu lock. > Please be much more specific about the synchronization. How does RCU > actually synchronize the offlining and access? Higher level description > of all the actors would be very helpful not only for the review but also > for future readers. I will improve the commit message about this synchronization change using RCU's. > > Also, more specifically > [...] >> 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 didn't really measure the effect. Let me measure it and post these in V2. > Is there any reason why page_ext is freed during offlining rather when > it is hotremoved? This is something I am struggling to get the answer. IMO, this is even wrong design where I don't have page_ext but page. Moving the freeing of page_ext to hotremove path actually solves the problem but somehow this idea didn't liked[1]. copying the excerpt here: "> > 3) Change the design where the page_ext is valid as long as the struct > page is alive. :/ Doesn't spark joy." @Joonsoo : We see that you did commit eefa864b701d ("mm/page_ext: resurrect struct page extending code for debugging"). Any reason why the page_ext is chosen to free at offline operation rather than the remove operation of a memory block? [1] https://lore.kernel.org/linux-mm/8fefe59d-c893-39f4-3225-65343086c867@redhat.com/ > > Thanks!