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]); }