From patchwork Tue Jul 6 07:57:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Qiang" X-Patchwork-Id: 12360015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA039C07E96 for ; Tue, 6 Jul 2021 07:58:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B73B61992 for ; Tue, 6 Jul 2021 07:58:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B73B61992 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=windriver.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0389A6B0011; Tue, 6 Jul 2021 03:58:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F03616B0036; Tue, 6 Jul 2021 03:58:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D07846B005D; Tue, 6 Jul 2021 03:58:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id A03396B0011 for ; Tue, 6 Jul 2021 03:58:06 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 088DA181FC55A for ; Tue, 6 Jul 2021 07:58:06 +0000 (UTC) X-FDA: 78331409772.32.241DC7E Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by imf16.hostedemail.com (Postfix) with ESMTP id 15B67F000091 for ; Tue, 6 Jul 2021 07:58:04 +0000 (UTC) Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1667w3bD004229; Tue, 6 Jul 2021 07:58:03 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by mx0a-0064b401.pphosted.com with ESMTP id 39mjcfr0xc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Jul 2021 07:58:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SN6JGzo6SHJayd15j9UN40YkBwKH70QELJDX3tKTdkjgVEyWC2I1m2jE/yn0WxXdAaScBjJ0kOjhQ7qVqyLthyocUUjRxlUmORdZij7ZpqJnIAOd+BccK0xEUnDYbWK1igm5VLVmMHUGJS/OTtAncrbhDyq13UmJ8K5CvR2wO9sPZEgN8fSDnGlkVKBUITqwsX1vJBGN7J5wA0Q/JpkMRsdMQEFbVHL5NSHMmUae7Om2EY+FXZTx1QZXGbeAwEvdvniWIUhslZ5DPkqdOIY5sDXXka52x7Hf7QKvl8pZ4x2wVPoht1uhjRAulSAWaNu2DHGx/BaCYbcW1H1ZWghEiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SArZnNb8qzGQgy4oSrJU+vLnxL0ElFHPEkTiUhvGRvE=; b=XnvMACsTTYeyV/UHXCc6066dOq3fkBRmvZcJ+t8fdWNN9KmVJDieVpWQT2V0bRkvqLUtfNY4PMAyzoSsGCT8xISlfLQpw0bQvJi2b2PYHJuKIe4avHHUoksMKe77GqXMYIdBtaNF8a+EaUnSh30gcnIv58uFIBDU9YIb+tvMS9qe4IY6/QksRbDwsHqVGpJGP1a4tKxvn9O/3PPgFFYrbInxHAu+ar4Kjmht1/Y867GwyxXS+oXfM1zeTr10Ckb65X4zx3M3ZA/nDBFmkoe28xAC/+m9R+EoxibG7GeBu38CG+ZITEOvUkIKKODh1NtVP2OinFnb0lXHJCsmBAH7KA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SArZnNb8qzGQgy4oSrJU+vLnxL0ElFHPEkTiUhvGRvE=; b=b6Ya6IAtnQQ0ToTCs1oxywtwLcEmeA/CDzT5aSth6WSRWhAZc1ptX+meoGJCX6s7cRCwmuFOIu1LD10bJDG0+nFT8sQtXhOXfgIgtG8s6gmRrJBBM8HvhtzN+DofVaLzCVOmMB8aegyvN9yJ4v1/OpR28ym+Ih0dOcsv34nrL2c= Received: from BL1PR11MB5478.namprd11.prod.outlook.com (2603:10b6:208:31d::12) by BL0PR11MB3138.namprd11.prod.outlook.com (2603:10b6:208:7b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.31; Tue, 6 Jul 2021 07:57:59 +0000 Received: from BL1PR11MB5478.namprd11.prod.outlook.com ([fe80::a140:b563:8725:5c2b]) by BL1PR11MB5478.namprd11.prod.outlook.com ([fe80::a140:b563:8725:5c2b%8]) with mapi id 15.20.4287.033; Tue, 6 Jul 2021 07:57:59 +0000 From: qiang.zhang@windriver.com To: syzbot+0123a2b8f9e623d5b443@syzkaller.appspotmail.com, mgorman@techsingularity.net, akpm@linux-foundation.org, alobakin@pm.me, songmuchun@bytedance.com, wangqing@vivo.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm/page_alloc: Fix sleeping function called in case of irqsdisable Date: Tue, 6 Jul 2021 15:57:54 +0800 Message-Id: <20210706075754.10726-1-qiang.zhang@windriver.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR0302CA0013.apcprd03.prod.outlook.com (2603:1096:202::23) To BL1PR11MB5478.namprd11.prod.outlook.com (2603:10b6:208:31d::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-qzhang2-d1.wrs.com (60.247.85.82) by HK2PR0302CA0013.apcprd03.prod.outlook.com (2603:1096:202::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.8 via Frontend Transport; Tue, 6 Jul 2021 07:57:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1df76666-e0ce-41d0-7b93-08d94053c5c5 X-MS-TrafficTypeDiagnostic: BL0PR11MB3138: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PtkC//5Tk0ynh9mAPsor6dlEar21OlNn39sRgK5j8Rikmjc0HYPmgWUVvpG93W0Ni0EP+vEmr6PjrjDOIYRCQW5pEDF69KcG8oePt8B3AN2b3BLoctbtK6GhQvI985UsOqrZj29+JfEIZa1/eKQ1CxmWT3K/cIlt8enR7p+gPZI0qXOFDzx5xM6nCQpgoDgOflbjeGjczBB7Sem6Lo0biZvQzDaut/oPdccD3wjfCV25wxEcKRyr4awlNZOPCZLC0N0Eev3UJJjCo2Mgyv4V0jlbFwi/JpDyzyJfCJPGJL/wCF5ecsVxowY+trNY1BYpmXIOmNPimbPhy+AX7y7nVQxMFZCnzwRRQLqVgiZLmS6i5g9aT21orVtIs433hI3bucZ1xZK4vthqFn2XJZs+EgCOjt1ariHmqDDuCE42JNwceLwjKvbqzoTl+H6wRUX3+YTKoCl2YPiN0Abn6imTIebzyKkxj2uTWXmEJ360bj0YLgw2BYakqvzct7iosyj/O7osLBdxHR9oEqvjUs5EwfmJk3Snd1m8Q2YkTeqRq+VaGyPx3LwCk5x0uugsmv7Jtoi0kJVAGubp/xnomtxSD9NLXmiD2/cXn9YisS6fcEoU84j4R6AV/4JJyXeTLHyXTxRTybS5fbstsU0gkf3o8Kbb/OX3cULneCLvh6MROeEAksUyYb55JZoFTD7Zvw41JxErDzz2sBiPBHGVm7di4Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL1PR11MB5478.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(346002)(396003)(136003)(366004)(39850400004)(2906002)(8936002)(316002)(52116002)(66556008)(66946007)(1076003)(6512007)(9686003)(66476007)(6486002)(956004)(6506007)(186003)(478600001)(5660300002)(26005)(16526019)(4326008)(38100700002)(8676002)(36756003)(83380400001)(38350700002)(86362001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YRXaRy4r2CGFef56P3jgnZlxqzJMg2XAt3mrqTAGyClZAsPM6hrH7QOcHXMdqC2lZHi6thRW0r9leBamBmk4uAqkTZSKEzvnJNB71sddVckpjibJXEwvWnGOs6+niV47AfwcsPfYIRBHZTDTzJ1vs6JHLBuRceAx1h+VhYAPzr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d4sLABeZTfXgOSb3q5QnlbnfPWmNcKTjWcwKx4T+5hl23dP1J3s2OhwFS0AFeplHolm/qXFseRnUvMY9q8demaxLJ/8Z2+IExq8Hm+uxoWkh X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1df76666-e0ce-41d0-7b93-08d94053c5c5 X-MS-Exchange-CrossTenant-AuthSource: BL1PR11MB5478.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2021 07:57:59.6124 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rsX+LjpMmLWArcXR7T3VuY8wH5M4NIi6pIDvamytKxfWJQ5IZ2pvgnW4HFPbV+HW7KV3cW8CKcp6kLvf7AoJHV0AxnLr6dhmj8H4wbbSAuU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR11MB3138 X-Proofpoint-GUID: ngRkXjjWGAHHN5lwSEdyCmKKzXmCdFP9 X-Proofpoint-ORIG-GUID: ngRkXjjWGAHHN5lwSEdyCmKKzXmCdFP9 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-06_02:2021-07-02,2021-07-06 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 clxscore=1011 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107060040 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 15B67F000091 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=b6Ya6IAt; spf=pass (imf16.hostedemail.com: domain of "prvs=28210c7fa5=qiang.zhang@windriver.com" designates 205.220.178.238 as permitted sender) smtp.mailfrom="prvs=28210c7fa5=qiang.zhang@windriver.com"; dmarc=pass (policy=none) header.from=windriver.com X-Stat-Signature: 9658mbg4wqptnf9wmo6x6z1ybndpq6dw X-HE-Tag: 1625558284-591510 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: From: Zqiang BUG: sleeping function called from invalid context at mm/page_alloc.c:5179 in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 1, name: swapper/0 ..... __dump_stack lib/dump_stack.c:79 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:96 ___might_sleep.cold+0x1f1/0x237 kernel/sched/core.c:9153 prepare_alloc_pages+0x3da/0x580 mm/page_alloc.c:5179 __alloc_pages+0x12f/0x500 mm/page_alloc.c:5375 alloc_page_interleave+0x1e/0x200 mm/mempolicy.c:2147 alloc_pages+0x238/0x2a0 mm/mempolicy.c:2270 stack_depot_save+0x39d/0x4e0 lib/stackdepot.c:303 save_stack+0x15e/0x1e0 mm/page_owner.c:120 __set_page_owner+0x50/0x290 mm/page_owner.c:181 prep_new_page mm/page_alloc.c:2445 [inline] __alloc_pages_bulk+0x8b9/0x1870 mm/page_alloc.c:5313 alloc_pages_bulk_array_node include/linux/gfp.h:557 [inline] vm_area_alloc_pages mm/vmalloc.c:2775 [inline] __vmalloc_area_node mm/vmalloc.c:2845 [inline] __vmalloc_node_range+0x39d/0x960 mm/vmalloc.c:2947 __vmalloc_node mm/vmalloc.c:2996 [inline] vzalloc+0x67/0x80 mm/vmalloc.c:3066 If the PAGE_OWNER is enabled, in __set_page_owner(), the pages will be allocated to save calltrace info, due to the allocated action is executed under irq disable(pagesets.lock be held), if the gfp variable contains the flag that causes sleep, will trigger above information. the prep_new_page() is not need to disable irq for protection, fix it through enable irq before call prep_new_page(). Fixes: 0f87d9d30f21 ("mm/page_alloc: add an array-based interface to the bulk page allocator") Reported-by: syzbot+0123a2b8f9e623d5b443@syzkaller.appspotmail.com Suggested-by: Muchun Song Signed-off-by: Zqiang --- v1->v2: beacuse when acquire local_lock again, the current task may be run on another CPU, The @pcp and @pcp_list need to be reloaded. mm/page_alloc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d6e94cc8066c..9adbc0a20938 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5286,11 +5286,6 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, if (unlikely(!zone)) goto failed; - /* Attempt the batch allocation */ - local_lock_irqsave(&pagesets.lock, flags); - pcp = this_cpu_ptr(zone->per_cpu_pageset); - pcp_list = &pcp->lists[order_to_pindex(ac.migratetype, 0)]; - while (nr_populated < nr_pages) { /* Skip existing pages */ @@ -5299,14 +5294,23 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, continue; } + /* Attempt the batch allocation */ + local_lock_irqsave(&pagesets.lock, flags); + pcp = this_cpu_ptr(zone->per_cpu_pageset); + pcp_list = &pcp->lists[order_to_pindex(ac.migratetype, 0)]; + page = __rmqueue_pcplist(zone, 0, ac.migratetype, alloc_flags, pcp, pcp_list); if (unlikely(!page)) { /* Try and get at least one page */ if (!nr_populated) goto failed_irq; + + local_unlock_irqrestore(&pagesets.lock, flags); break; } + + local_unlock_irqrestore(&pagesets.lock, flags); nr_account++; prep_new_page(page, 0, gfp, 0); @@ -5317,8 +5321,6 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, nr_populated++; } - local_unlock_irqrestore(&pagesets.lock, flags); - __count_zid_vm_events(PGALLOC, zone_idx(zone), nr_account); zone_statistics(ac.preferred_zoneref->zone, zone, nr_account);