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;