From patchwork Tue Aug 11 12:58:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charan Teja Kalla X-Patchwork-Id: 11709225 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFC35739 for ; Tue, 11 Aug 2020 12:58:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 718BF206C3 for ; Tue, 11 Aug 2020 12:58:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="BEtGbDWO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 718BF206C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 727BB8D0001; Tue, 11 Aug 2020 08:58:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6B1336B0007; Tue, 11 Aug 2020 08:58:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57A3D8D0001; Tue, 11 Aug 2020 08:58:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 3E8636B0005 for ; Tue, 11 Aug 2020 08:58:53 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BAC238248047 for ; Tue, 11 Aug 2020 12:58:52 +0000 (UTC) X-FDA: 77138292504.05.foot81_3902e3126fe3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 8C7A21801C180 for ; Tue, 11 Aug 2020 12:58:52 +0000 (UTC) X-Spam-Summary: 1,0,0,bb0bf903e489d2f3,d41d8cd98f00b204,bounce+d06763.be9e4a-linux-mm=kvack.org@mg.codeaurora.org,,RULES_HIT:41:355:379:541:800:960:965:966:967:973:988:989:1260:1345:1437:1535:1542:1711:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2525:2540:2559:2564:2682:2685:2693:2731:2741:2859:2895:2903:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4390:4395:5007:6119:6261:6653:7903:8660:9010:9025:10004:11026:11218:11232:11658:11914:12043:12048:12114:12295:12296:12297:12438:12517:12519:12555:12986:13148:13161:13229:13230:14096:14181:14394:14721:21080:21451:21627:21740:21796:21939:21966:21972:21987:21990:22119:30012:30036:30054:30070,0,RBL:69.72.43.7:@mg.codeaurora.org:.lbl8.mailshell.net-62.14.0.100 66.201.201.201;04yrzoe1kiy9dxh5a1n49ad1z64nnockk4uuf4r3c6j7tk5ufgyifr1ajnui93r.e4su9j53rfph43cuttk97fxccpg7brrnrckwtpf3jpqztuksnp6s8dd8stjjna8.6- lbl8.mai X-HE-Tag: foot81_3902e3126fe3 X-Filterd-Recvd-Size: 5112 Received: from m43-7.mailgun.net (m43-7.mailgun.net [69.72.43.7]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 11 Aug 2020 12:58:49 +0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1597150732; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=Sx3ep+KIHVu/tITGzEEH1tzVULyGxJl+pKTXi6iVWK8=; b=BEtGbDWOJNSvIKMePc191uvxXiImJv59XgIq9qzjizbAVJLkAhzclGV5Tq6fIYtGN8cyxGj6 aGkdjM/m+AqXqnCup6xZw2TdnWPlyxGp+oweFDOt9TafSeR3Kulk1K2mMz3DsqDZ1+cmg7XB loo9e3DdEyjTsmAihibKI/OH1kQ= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyIwY2Q3OCIsICJsaW51eC1tbUBrdmFjay5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n12.prod.us-west-2.postgun.com with SMTP id 5f3296002889723bf8146727 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 11 Aug 2020 12:58:40 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 1534BC433C6; Tue, 11 Aug 2020 12:58:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from charante-linux.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: charante) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4F332C433C9; Tue, 11 Aug 2020 12:58:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4F332C433C9 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=charante@codeaurora.org From: Charan Teja Reddy To: akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, david@redhat.com, rientjes@google.com, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, vinmenon@codeaurora.org, Charan Teja Reddy Subject: [PATCH V2] mm, page_alloc: fix core hung in free_pcppages_bulk() Date: Tue, 11 Aug 2020 18:28:23 +0530 Message-Id: <1597150703-19003-1-git-send-email-charante@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-Rspamd-Queue-Id: 8C7A21801C180 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: The following race is observed with the repeated online, offline and a delay between two successive online of memory blocks of movable zone. P1 P2 Online the first memory block in the movable zone. The pcp struct values are initialized to default values,i.e., pcp->high = 0 & pcp->batch = 1. Allocate the pages from the movable zone. Try to Online the second memory block in the movable zone thus it entered the online_pages() but yet to call zone_pcp_update(). This process is entered into the exit path thus it tries to release the order-0 pages to pcp lists through free_unref_page_commit(). As pcp->high = 0, pcp->count = 1 proceed to call the function free_pcppages_bulk(). Update the pcp values thus the new pcp values are like, say, pcp->high = 378, pcp->batch = 63. Read the pcp's batch value using READ_ONCE() and pass the same to free_pcppages_bulk(), pcp values passed here are, batch = 63, count = 1. Since num of pages in the pcp lists are less than ->batch, then it will stuck in while(list_empty(list)) loop with interrupts disabled thus a core hung. Avoid this by ensuring free_pcppages_bulk() is called with proper count of pcp list pages. The mentioned race is some what easily reproducible without [1] because pcp's are not updated for the first memory block online and thus there is a enough race window for P2 between alloc+free and pcp struct values update through onlining of second memory block. With [1], the race is still exists but it is very much narrow as we update the pcp struct values for the first memory block online itself. [1]: https://patchwork.kernel.org/patch/11696389/ Signed-off-by: Charan Teja Reddy Acked-by: David Rientjes Acked-by: David Hildenbrand Acked-by: Michal Hocko --- v1: https://patchwork.kernel.org/patch/11707637/ mm/page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e4896e6..839039f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1304,6 +1304,11 @@ static void free_pcppages_bulk(struct zone *zone, int count, struct page *page, *tmp; LIST_HEAD(head); + /* + * Ensure proper count is passed which otherwise would stuck in the + * below while (list_empty(list)) loop. + */ + count = min(pcp->count, count); while (count) { struct list_head *list;