From patchwork Wed Sep 6 12:42:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13375633 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 17F34EB8FB7 for ; Wed, 6 Sep 2023 12:32:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E6EF440165; Wed, 6 Sep 2023 08:32:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66F76440151; Wed, 6 Sep 2023 08:32:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E94E440165; Wed, 6 Sep 2023 08:32:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3D9AE440151 for ; Wed, 6 Sep 2023 08:32:19 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E4A941A09C3 for ; Wed, 6 Sep 2023 12:32:18 +0000 (UTC) X-FDA: 81206110356.18.576CFCA Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf27.hostedemail.com (Postfix) with ESMTP id 8607740027 for ; Wed, 6 Sep 2023 12:32:13 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694003534; a=rsa-sha256; cv=none; b=BTX/BCpxPf2ALmFWZLgiFfdTs7iTMzXwUNcNFrifG4v6wQe0mfQ9AK+iU/vELYBTw+V3hR M8BcNpUBvqjcuEF8vf33kx8vKWU7JlvAvTdM1K1qH5bzenSQNG4d6FxOCuS5+/Fi+fYXGA uRmhpuK4ShUzW76720Vd1HGIXb5hOoc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694003534; 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; bh=JToBRFxNl66zYWnBducdJrCDg3ZqDJA6CVg9yHTw5eA=; b=7qb9S+oYW+oCLhSBw4qNXXlfcu5vFitKPALGOYgWktuh/3NFeSvcxeL7yQh4jo5IFk9FZT bo+6qp5qGK/cem7jKe+0CoPU83sAnTybsoKV/wlIsv/CWbTHkGuVrq46FnKTpol5g8fQh8 6U3OktVR/BuAWkuChtDuF9yolvxeGvA= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RghWt4tLNzTlps; Wed, 6 Sep 2023 20:29:30 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 6 Sep 2023 20:32:07 +0800 From: Kefeng Wang To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , , CC: Kefeng Wang Subject: [PATCH -rfc 1/3] mm: kasan: shadow: add cond_resched() in kasan_populate_vmalloc_pte() Date: Wed, 6 Sep 2023 20:42:32 +0800 Message-ID: <20230906124234.134200-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230906124234.134200-1-wangkefeng.wang@huawei.com> References: <20230906124234.134200-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8607740027 X-Stat-Signature: cfiyhwwfqwfigygnkgsftfwjime3ijxi X-HE-Tag: 1694003533-502741 X-HE-Meta: U2FsdGVkX18Z3mRGGYPGP/KqBvLkObTqGkM89Vds+ldlQtIrdcDWBDrbvpUnETER24t0tETERpY8CTbbAWNgLvGy6Ytsrm7N9EWOQVVjfD2V3jQ40bk6YXG65nznwWF2vfkyS7p5UTMMf59V4LtsNj6/ahwJNOP+rSPYyVL5wcyEZzR0NhdgXFuXpOgBpqCS9UZaqhx74ntH/Zi9wFhoxrqMMrb7d9J17YLIrGFGv7n1HnQcHLo17XQhWzkj+FYvaLBlgNWP1Jf9/UASISHJOsMjH4I3Sy+hbpaZ9eg0kb71bm1NqDr51efCEbUJQoFk2TfItDr9weQB0XqY7atYelniOYNwE/RI0F1ZzJEICTwRck3SqSkcN5uynflshQaMCgnPMqE6/Ug6pmQN8sgwkJ5hYIsXPeZM0CktFaxMgvTfuUOYOpxzD3ggUyPunlUjrBvAv0Huu8UyIF0MN6gCZiC1X2jC+HPgOB9Bl2SDwb/5qZwVKTwXa9/H8ruFtdmlc+sD4SA4LFWCoV5BymcEtQTzzpcd3bacO79WjB6qSw3pmi3n2wq7yLxpanntxfbof8kEHZmPVs9ye4+wRiNEbRDJYG91MeaDtQBf1DVllYjETKtb8mCm4psqbjEAHD6kxvYBQXJckfbYv1Ka4pKLHP8Wnux9Hz9HnQM3Jio/6jtSbEGW6VQGulrsLC1vmbJD0hHiv8EQXha3CSb2dgYpmNVgaVCx1Ga6It/ZqyrZtt2AUjr9WTdyE0cnM3PYDtcDRhsXSlbDQiK0FRPId7a1vBNP5fNQwIZQq+aSJnXA8OsTCiuyGIxeuvLoBYplq+jBIBfHkAnQu7z4M+VZeFOqrHlSqW2Opv1ZNHLX51RjtUCsK5qop/x3vb6TMbuFiDOcVVk7eS7R9YPNRsNtPaCHhx7bgxtVzZIasS7bn//xiklfhvH/rPUAyuowBqQx23vVbU4nL/t3dJN7Nm3jaUx 9QwARKnr Ze3GgK2e6x/uCmVSB6w4TbFDJDrFymmeU9dZQDABp4Zd1uAVsqDv/l0pEpKxA2Z0ZTAIiM6cJyf/3Yfx1CBzAZlz68Ly8UC+vV1ZILdpF57O4VC2+g4UQ9QqpWh7n8sLrolEGXgeFhvhdwezl6oRuCj2sI4r5lSJ5T/VME53iXjmTJ6si9ZatvsniNyexgbJgP+biAJaH4t08iW/mzZw6KBNTHm8JDIq5Cwa1gJjoAP1AkkW3xV8ljchZ5CcOfGDKE5S48HAdxi1PPaE= 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 kasan_populate_vmalloc() will cost a lot of time when populate large size, it will cause soft lockup, watchdog: BUG: soft lockup - CPU#3 stuck for 26s! [insmod:458] _raw_spin_unlock_irqrestore+0x50/0xb8 rmqueue_bulk+0x434/0x6b8 get_page_from_freelist+0xdd4/0x1680 __alloc_pages+0x244/0x508 alloc_pages+0xf0/0x218 __get_free_pages+0x1c/0x50 kasan_populate_vmalloc_pte+0x30/0x188 __apply_to_page_range+0x3ec/0x650 apply_to_page_range+0x1c/0x30 kasan_populate_vmalloc+0x60/0x70 alloc_vmap_area.part.67+0x328/0xe50 alloc_vmap_area+0x4c/0x78 __get_vm_area_node.constprop.76+0x130/0x240 __vmalloc_node_range+0x12c/0x340 __vmalloc_node+0x8c/0xb0 vmalloc+0x2c/0x40 Fix it by adding a cond_resched(). Signed-off-by: Kefeng Wang --- mm/kasan/shadow.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index dd772f9d0f08..fd15e38ff80e 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -317,6 +317,8 @@ static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, unsigned long page; pte_t pte; + cond_resched(); + if (likely(!pte_none(ptep_get(ptep)))) return 0; From patchwork Wed Sep 6 12:42:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13375634 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 B6794EB8FB8 for ; Wed, 6 Sep 2023 12:32:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58867440167; Wed, 6 Sep 2023 08:32:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53781440151; Wed, 6 Sep 2023 08:32:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 426B8440167; Wed, 6 Sep 2023 08:32:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 33BB9440151 for ; Wed, 6 Sep 2023 08:32:33 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 06A9840B03 for ; Wed, 6 Sep 2023 12:32:33 +0000 (UTC) X-FDA: 81206110986.16.8C1B5E4 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf07.hostedemail.com (Postfix) with ESMTP id 93E5040028 for ; Wed, 6 Sep 2023 12:32:29 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694003551; 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; bh=AX+U74nr5Le0KVgJkSOr8aMz7KHIoSPWgWf306Yi4XU=; b=wSI+sUPpVbpKlQdOMcXQNryhQIVLJz84QwAtbZ0UVVl3fzntzrmi/ruP72Xct3YxJPbRuc hnJt1ebOffQdG+wdFhqQEZmTfz5pLURCZmWR1Gw4tz5Mrq2ZJ7yOgZ3xSxJQUisyHcYpZA ImTbHZKR+LXMbzIyQjWzwqOVsRyxVi0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694003551; a=rsa-sha256; cv=none; b=3j6ats1tRDEjdBnx+icd6hrICK4YRZPQAp66kMh14VfbRzZvaPi4Pa7KC6bN6ZDD93tMXU hBEOQQV9VelK6UlHv9YV+hf50/fAJbUkG4CCkR+azHLmrXAERAMsFsQbwMfQPldEfWbZnu 7pA4L1hxp6Vzvx7jgccdNHP1lumkLFY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RghXr5F7rz1M96W; Wed, 6 Sep 2023 20:30:20 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 6 Sep 2023 20:32:07 +0800 From: Kefeng Wang To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , , CC: Kefeng Wang Subject: [PATCH -rfc 2/3] mm: kasan: shadow: move free_page() out of page table lock Date: Wed, 6 Sep 2023 20:42:33 +0800 Message-ID: <20230906124234.134200-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230906124234.134200-1-wangkefeng.wang@huawei.com> References: <20230906124234.134200-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 93E5040028 X-Rspam-User: X-Stat-Signature: zp88yo64f7giktract7sj59mtosu3c8c X-Rspamd-Server: rspam03 X-HE-Tag: 1694003549-629120 X-HE-Meta: U2FsdGVkX1/6XNWNTjHsdwjDKcED4B3L5pi6kiJoIanguYRaDUdNYRWCu8D2jp95UHn7Z4TDws3TCpBS5zF4mVS4aOf00xrLcVEfI1tGWvCi/cTyyObmW0Xb1wKOOuwzsuLA2M2MQrZ8FlYPRafhQV9QjmsZpImjuyJgkcx67dLNTFkmmK9IWUp+4O4lNmAXUsOMdSez9E+6leXYOOmWSgFxzo2Fmet4qQbI41oWinD/rTwYVK1B0th+KisRjR+Y29J2PsXog28Gvs7jugGEUfBpp6nKpYW7rVXgJ65t3FUs2mZL1YD9SPivmBv4UPg/pZ09KHRwn7tv+aNUGubbqpizserCWb3xqHmvd0oyIvtnHkMqUengAlnyGIRTV9hzWwYdxSz64miSVAS/UGFa2VYObBVHZDlbnsJP0mYIQJJJk1zgo83oggFMonx5sELPe/ZvoS+arj8IK1xoHdn97m3CKBtn44qQeOF/CgWWNT+qBGskoRElcq+Q3J6eJKAZKltChSA9KaHrXCX/pnXI7GhOiciVUD2fvSjkDYMobpDDwffK5iZvXrlR/iyVEaStZLJ2g/rQLRaDPpiBMMFvUVT6Hg8CAGOxTe4UMp+lBtozNBX5V/uJVT3YDIcB/dPSxDzeD95x5YfXtMAxl2jluDH060d9KUD6dz2RrJFwLUdICOsZFwAvkeyqniVOlydstD3Z1eyqIpi0/gGPgm6c/O9i+S7n+5kMkavihqSq1tUvpMSkvAN1Zm789S+TauDz3pAT3qF3EwxwRWj5IcIuTH60nTu66ptZrQtarxdJtkjirZrGk/kNwj2UfN+TyYL9s1L0Cb6vqSnlphnn+lPG+H4oQLEBEbJHmtj/sFURjPOxmNxrDVdgInVvRf+FBZb2CRPJPGjRUhi9joGCR5VlsvC1ouIcvcGMvtf9PZShxV5Bn0cBdBG31hR6QYDlPxZwqi7HrcEA4DXtrNZc6nK 1UA3r/w1 W6VZskkXnTENyuoHQBDga9nftptYXVGgZcatS0Proi5rY7QY8JuzOK815b1C+sPndg7RImtOLZlKj8F3q1spLW0+T0TPt1G466u2geONkaU57BSWLApKkDBwsxAnpqPhJuSDPjNE6nZf8Mdb9sXuccvZyiplctViVcOD/bBqFuuvQXiXTGgYBBndYHTQjGHHRsf43E9liY2LOHwTTxv3V33kd7AHF6MUrgb/JUIU0hhwzmeNi93iSvfRyejPdFNY2TQCTP6O4wAtqGRQ= 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: free_page() is not needed to be protected by page table lock, and it will take a little longer, so move it out of the spinlock. Signed-off-by: Kefeng Wang --- mm/kasan/shadow.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index fd15e38ff80e..d7d6724da2e0 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -423,12 +423,13 @@ static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, page = (unsigned long)__va(pte_pfn(ptep_get(ptep)) << PAGE_SHIFT); spin_lock(&init_mm.page_table_lock); - - if (likely(!pte_none(ptep_get(ptep)))) { + if (likely(!pte_none(ptep_get(ptep)))) pte_clear(&init_mm, addr, ptep); - free_page(page); - } + else + page = 0; spin_unlock(&init_mm.page_table_lock); + if (page) + free_page(page); return 0; } From patchwork Wed Sep 6 12:42:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13375653 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 6BD8CEB8FC0 for ; Wed, 6 Sep 2023 12:51:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9768440167; Wed, 6 Sep 2023 08:51:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4767440151; Wed, 6 Sep 2023 08:51:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B36B0440167; Wed, 6 Sep 2023 08:51:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A5E8E440151 for ; Wed, 6 Sep 2023 08:51:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 72F2F409FA for ; Wed, 6 Sep 2023 12:51:52 +0000 (UTC) X-FDA: 81206159664.01.092114B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf11.hostedemail.com (Postfix) with ESMTP id 3D8B440016 for ; Wed, 6 Sep 2023 12:51:48 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694004710; 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; bh=YsHmY5hkpTTrJQqvQfSH4rSGK0inQUOy9GMYacmc4e0=; b=LPSohORvGVqGNr6XqG3XSRZj5QNzx6pcIP8sb/NpWrmiSSpmRXoM2EKPyAhSPZqy0GdO5T JaouBQVCKmlggrrlc78fw6jdx+11hVFCvhdyi2e7HK71tpH/uOUgkdMy+hYb7DXLmWCz7F srw1GGcWN5Qh2ELRXmjQBqevrXXQHLg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694004710; a=rsa-sha256; cv=none; b=kCuazNvRDf9zZ6021a+uWfwrBDyVUov5u/NTX2HkAKHJHaiB+LCUEN2FKPtmLhWvfoV2Ye Tz8LjWScV9AOxdG+8RSLK9Whm34kdSvnjtod0RL9cX9afswpBTb1tmaj74woQ13dC/963P Dqw5e0al2QALx65plJXlSWRkIbLwWVA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RghXr4FGFzrSb1; Wed, 6 Sep 2023 20:30:20 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 6 Sep 2023 20:32:08 +0800 From: Kefeng Wang To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , , CC: Kefeng Wang Subject: [PATCH -rfc 3/3] mm: kasan: shadow: HACK: add cond_resched_lock() in kasan_depopulate_vmalloc_pte() Date: Wed, 6 Sep 2023 20:42:34 +0800 Message-ID: <20230906124234.134200-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230906124234.134200-1-wangkefeng.wang@huawei.com> References: <20230906124234.134200-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 3D8B440016 X-Rspam-User: X-Stat-Signature: c8ecpa9c3pie7ghpa7x184i1qy7fkng5 X-Rspamd-Server: rspam03 X-HE-Tag: 1694004708-79558 X-HE-Meta: U2FsdGVkX191bF+I45d0uhOFQey4oSUkZPdWJqd5mDek8slquaDuGIt8vpc1s/Mzh6YNM9GeB3agFF88RjW/1Dwlyc8E+AGEU0E8H54nkRnkXpZuWU8sD+NcdeCPtla7um3igiVHvn0zYsVzG9RT9VLMst+uDn8IP7szMPFyjg6RJyj3m8XHgHFC92F8ejhjSVhpCgI4yRG+CoYsJ65WHdumdB4aJFZFYY17Z3I2wpFkGng6+tOqx8AOTgM0xK24SiVxBldG9zoYRQb8K/GPYyQx2Gh1evXu0ekVrYGEkprFuxx/2GQUQhgyg9OklRdoO0EsLyoA8v3Pz0j2fXtQFBE9mluT9nljVdhcAVnLRBIXwb7lG7uUoDPHLtZL3bSn8MPaUqvolROo6XuXYGixAuOkKE+WZXet+lZnOv7SVORYaG9UioNOuAYiMXrAP7UgBbAi78rjv53Z8InRLOSUB+QOhF2ph+t98IyFtfsJdAF5TH67vMxK/RaHNgliNaG8mtyLE87U9uBx2ajH8DoGeixLoCb/PF2EhRpf8KsF3PfAca+Ka/ZeFEKi2ZSb5sqMCBWPvZNVKKmTVwIIrAFxwCalkbt6cwGBWj8/DRyHGtgUW8rVh8SWjSv3NbzQweSp190/+V8fG605tjGsl5UoMPPuMlw2l+fPi2ia3az2HrO6l5qM57qX1rl0qe0p7jarQMNTAmYSxW9LBjNf27rw6EjbN+XtZZKs/FlCqYTCHck7FdQ3DW+URzCAcy4gUtm/q5Uw+urC7kyxA3rhA9xmpsZKya4YRjZC3zheaOKe3PSPu04Ma6g2lgk+ENkiQ441s/i0erC/NWy33LLGRkHODszOgkcSgqgSLPUajk+Iv1WJ/B7NtFv5IEMytSi6Dg3NV6yNbQZgZyrEt5VXhQdP6wWULXKI/F9Znr0yNpw7a50bmhfc+iU/CEaYDDwROIKKyI6jPekpZQsAfXz3g/X nPTQIfNN LOssXV5rceLKdewhx6kxN38OtEIKOLSyhjeopp5CCp2Z09Rtp+pxA7QQT+rC7Hrj0B0rb84Cme6HEey2XmUCpPw3hOLtrJEu/wNHiHkWRPNxc4xbFSRfBOa0P46X0DMCSJYGHat+5Aa801qtIGOmjS/e/5JF9+8+8XywwElmfJ+APsfAo+UQhEk38ItmFj0+MrEh5zvue0u4M9KJWRN7e+bV/yE8pKHOiFfJqfH2vvWYRK+kIY8msbD+uUDRNxYTxJj/60Q/6NL2T4EY= 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: There is a similar softlockup issue with large size in kasan_release_vmalloc(), watchdog: BUG: soft lockup - CPU#6 stuck for 48s! [kworker/6:1:59] _raw_spin_unlock_irqrestore+0x50/0xb8 free_pcppages_bulk+0x2bc/0x3e0 free_unref_page_commit+0x1fc/0x290 free_unref_page+0x184/0x250 __free_pages+0x154/0x1a0 free_pages+0x88/0xb0 kasan_depopulate_vmalloc_pte+0x58/0x80 __apply_to_page_range+0x3ec/0x650 apply_to_existing_page_range+0x1c/0x30 kasan_release_vmalloc+0xa4/0x118 __purge_vmap_area_lazy+0x4f4/0xe30 drain_vmap_area_work+0x60/0xc0 process_one_work+0x4cc/0xa38 worker_thread+0x240/0x638 kthread+0x1c8/0x1e0 ret_from_fork+0x10/0x20 But it is could be fixed by adding a cond_resched_lock(), but see comment about kasan_release_vmalloc(), free_vmap_area_lock is to protect the concurrency, so it looks risky, any advise to fix this issue? Signed-off-by: Kefeng Wang --- include/linux/kasan.h | 9 ++++++--- mm/kasan/shadow.c | 9 ++++++--- mm/vmalloc.c | 7 ++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 3df5499f7936..6d85715c47ad 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -385,7 +385,8 @@ void kasan_populate_early_vm_area_shadow(void *start, unsigned long size); int kasan_populate_vmalloc(unsigned long addr, unsigned long size); void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, - unsigned long free_region_end); + unsigned long free_region_end, + void *lock); #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ @@ -400,7 +401,8 @@ static inline int kasan_populate_vmalloc(unsigned long start, static inline void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, - unsigned long free_region_end) { } + unsigned long free_region_end, + void *lock) { } #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ @@ -435,7 +437,8 @@ static inline int kasan_populate_vmalloc(unsigned long start, static inline void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, - unsigned long free_region_end) { } + unsigned long free_region_end, + void *lock) { } static inline void *kasan_unpoison_vmalloc(const void *start, unsigned long size, diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index d7d6724da2e0..4bce98e2b30d 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -416,12 +416,14 @@ int kasan_populate_vmalloc(unsigned long addr, unsigned long size) } static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, - void *unused) + void *lock) { unsigned long page; page = (unsigned long)__va(pte_pfn(ptep_get(ptep)) << PAGE_SHIFT); + cond_resched_lock(lock); + spin_lock(&init_mm.page_table_lock); if (likely(!pte_none(ptep_get(ptep)))) pte_clear(&init_mm, addr, ptep); @@ -511,7 +513,8 @@ static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, */ void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, - unsigned long free_region_end) + unsigned long free_region_end, + void *lock) { void *shadow_start, *shadow_end; unsigned long region_start, region_end; @@ -547,7 +550,7 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, apply_to_existing_page_range(&init_mm, (unsigned long)shadow_start, size, kasan_depopulate_vmalloc_pte, - NULL); + lock); flush_tlb_kernel_range((unsigned long)shadow_start, (unsigned long)shadow_end); } diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 228a4a5312f2..c40ea7d1b65e 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1768,7 +1768,8 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end) if (is_vmalloc_or_module_addr((void *)orig_start)) kasan_release_vmalloc(orig_start, orig_end, - va->va_start, va->va_end); + va->va_start, va->va_end, + &free_vmap_area_lock); atomic_long_sub(nr, &vmap_lazy_nr); num_purged_areas++; @@ -4198,7 +4199,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, &free_vmap_area_list); if (va) kasan_release_vmalloc(orig_start, orig_end, - va->va_start, va->va_end); + va->va_start, va->va_end, NULL); vas[area] = NULL; } @@ -4248,7 +4249,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, &free_vmap_area_list); if (va) kasan_release_vmalloc(orig_start, orig_end, - va->va_start, va->va_end); + va->va_start, va->va_end, &free_vmap_area_lock); vas[area] = NULL; kfree(vms[area]); }