From patchwork Thu Dec 22 19:00:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 35913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp116257wrn; Thu, 22 Dec 2022 11:04:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXunLulCdLbuhJMSTfb1eeruCKovSYedELzrmpt3RnBavaoAXWdlAQl+HjBDfteB5KlyL+QN X-Received: by 2002:a17:903:228a:b0:191:217f:b2ea with SMTP id b10-20020a170903228a00b00191217fb2eamr10285731plh.40.1671735857401; Thu, 22 Dec 2022 11:04:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671735857; cv=none; d=google.com; s=arc-20160816; b=z1JW7pZ/E+z3EyGlBc+eG2UYwoBrKcfMj06ITqHRxP8IDcxKTOwGI8c9bl77EvaiT1 S3G8Nt5gFNz5uq8cVMqDvCRXe8foTuD12HgPfDTisw6stP9Z38/4HSJhmxNr5O4TzRZ7 gDO8ADgnj63FcdxDBWtJaPG9Tt/Y8g0YUTUEWeLmNxkD+pj6ZG03LalSP+lIVEnPYHBo VOpmYlBnPXHLd+Ouzoo1YgOcP8uJjxqUfrTZWfla3yOCqWcNIlYJSyRDRpWV6E8bTQP0 aonxGBmBphavU4YQhFYwuE68nc5ACErKpLRwZlfIs2Wolc+iaBomWEHprS1WgWXAAo6s Uhfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xFGD4VIGKFF/VgK3W8l6J2/VT0xeVWmVNx8bDUgm6n8=; b=LxDz2aKjumGdokabj90tmwYN7ZGqLYX7sGhzYoHqyekN8SPRUD8feMii0Dw4xBKoRS wdST8bg5ziXluwaggWIcRvuQTLd485e8oYPVfyn6q4nUgG8IDls82EtA9Quet1cpkZjk VBJ7HfAEDmYXTxeMmAXgroVmHTxZJ3zPeyaH6ekvXV81cxX+LX7DxKM+bCk+Nz3Ov3bt Jpg29DGqYcXeXtJzVxNFWUee/EpPlAK0tu7a310ZG8dhNFYbuthbOktB6yTWxP8prkgy PVXF6pxSIl7ODQmF1iF8lTnPBa2bHgxTef8nQGMrEgik2VLr+q3Co1/sTiu74F0G3Z8U DmYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PjEfHeIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a170902c1c500b0018537cc29f9si1210252plc.15.2022.12.22.11.04.02; Thu, 22 Dec 2022 11:04:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PjEfHeIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235408AbiLVTAm (ORCPT + 99 others); Thu, 22 Dec 2022 14:00:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbiLVTAh (ORCPT ); Thu, 22 Dec 2022 14:00:37 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C7D4233AB for ; Thu, 22 Dec 2022 11:00:35 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id f34so4050135lfv.10 for ; Thu, 22 Dec 2022 11:00:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xFGD4VIGKFF/VgK3W8l6J2/VT0xeVWmVNx8bDUgm6n8=; b=PjEfHeIvZJi/4S12sn9JGXZNOZM2wzHObFOhOl9XJx0YgNJvbJRTcTu5+qyQ0wKPYU PBhUKu4FcEJyPvnsxq3X5tofzpUREJxpyb0pKYrwk3FLWIWghNUvhAILYvekBCp3o5sc C52ub7lXZ9HtC+lvZqE+wQTUrCCVgFsEtOMEQpgDif60a4yPSjpF1/YlgyPK6RLbPWbs 43WCM75n2T4FUVL2H0eXfPFQffnCLflKwiE88owiUiN5Fw1ckhaqjpn2JfHARVjcDozT 5082axGIHk5OOLCfkB1lIzKpbmRUgXIGxFjIaKb6HqxFpQRtJozeS9GYTrRx8e1RUP4/ JK5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xFGD4VIGKFF/VgK3W8l6J2/VT0xeVWmVNx8bDUgm6n8=; b=2Unn0mAlYufwJWRivQQx7DTtK0K2SkrdkWE7xn5mvXWhPTTmhTIT/3ivUn4BPmdpLL Tbo1p/+qNxq/H3UeUSqIcV+oERHjk54AP5pZheVTdW5oiKkrNH0aFWwHyzU1rAFTRTQy xyCS1RWdFXqbOxlhNI0nC+0AkNNeBx0ok3SOlX+U1+oP06kQnUGYYe4L4xsVd6YgpKTR m5QLeci/qC8TD9meTZYWI7h44ybScI0lYGirPr5IEOH5TIXitqyy1bVM9psGgNVJVzIn 8Hzx6CiTZK1AxVmH8P1L9TzatpOU/UovRQLpBUll/2q9qzttSyml3eHF85mT7a7mUWNs sV1w== X-Gm-Message-State: AFqh2kpxMP2Jib3/yZPtZtzOzMRQ/lp/xrrJCJyt4VTmgebL/zsAiAki 0FJ5CXDC5c3BSXuBC2YUqq8= X-Received: by 2002:ac2:47f6:0:b0:4af:f5c1:b1c7 with SMTP id b22-20020ac247f6000000b004aff5c1b1c7mr1729091lfp.20.1671735633323; Thu, 22 Dec 2022 11:00:33 -0800 (PST) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id c20-20020ac24154000000b0048a8c907fe9sm164209lfi.167.2022.12.22.11.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 11:00:32 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: Andrew Morton Cc: linux-mm@kvack.org, LKML , Baoquan He , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , Nicholas Piggin , Uladzislau Rezki , Oleksiy Avramchenko , Roman Gushchin Subject: [PATCH v3 1/3] mm: vmalloc: Avoid calling __find_vmap_area() twice in __vunmap() Date: Thu, 22 Dec 2022 20:00:20 +0100 Message-Id: <20221222190022.134380-1-urezki@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752942098442616707?= X-GMAIL-MSGID: =?utf-8?q?1752942098442616707?= Currently the __vunmap() path calls __find_vmap_area() twice. Once on entry to check that the area exists, then inside the remove_vm_area() function which also performs a new search for the VA. In order to improvie it from a performance point of view we split remove_vm_area() into two new parts: - find_unlink_vmap_area() that does a search and unlink from tree; - __remove_vm_area() that removes without searching. In this case there is no any functional change for remove_vm_area() whereas vm_remove_mappings(), where a second search happens, switches to the __remove_vm_area() variant where the already detached VA is passed as a parameter, so there is no need to find it again. Performance wise, i use test_vmalloc.sh with 32 threads doing alloc free on a 64-CPUs-x86_64-box: perf without this patch: - 31.41% 0.50% vmalloc_test/10 [kernel.vmlinux] [k] __vunmap - 30.92% __vunmap - 17.67% _raw_spin_lock native_queued_spin_lock_slowpath - 12.33% remove_vm_area - 11.79% free_vmap_area_noflush - 11.18% _raw_spin_lock native_queued_spin_lock_slowpath 0.76% free_unref_page perf with this patch: - 11.35% 0.13% vmalloc_test/14 [kernel.vmlinux] [k] __vunmap - 11.23% __vunmap - 8.28% find_unlink_vmap_area - 7.95% _raw_spin_lock 7.44% native_queued_spin_lock_slowpath - 1.93% free_vmap_area_noflush - 0.56% _raw_spin_lock 0.53% native_queued_spin_lock_slowpath 0.60% __vunmap_range_noflush __vunmap() consumes around ~20% less CPU cycles on this test. v2 -> v3: - update commit message; - rename the vm_remove_mappings() to the va_remove_mappings(); - move va-unlinking to the callers so the free_vmap_area_noflush() now expects a VA that has been disconnected; - eliminate a local variable in the remove_vm_area(). Reported-by: Roman Gushchin Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Lorenzo Stoakes Reviewed-by: Christoph Hellwig --- mm/vmalloc.c | 77 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 9e30f0b39203..eb91ecaa7277 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1815,9 +1815,9 @@ static void drain_vmap_area_work(struct work_struct *work) } /* - * Free a vmap area, caller ensuring that the area has been unmapped - * and flush_cache_vunmap had been called for the correct range - * previously. + * Free a vmap area, caller ensuring that the area has been unmapped, + * unlinked and flush_cache_vunmap had been called for the correct + * range previously. */ static void free_vmap_area_noflush(struct vmap_area *va) { @@ -1825,9 +1825,8 @@ static void free_vmap_area_noflush(struct vmap_area *va) unsigned long va_start = va->va_start; unsigned long nr_lazy; - spin_lock(&vmap_area_lock); - unlink_va(va, &vmap_area_root); - spin_unlock(&vmap_area_lock); + if (WARN_ON_ONCE(!list_empty(&va->list))) + return; nr_lazy = atomic_long_add_return((va->va_end - va->va_start) >> PAGE_SHIFT, &vmap_lazy_nr); @@ -1871,6 +1870,19 @@ struct vmap_area *find_vmap_area(unsigned long addr) return va; } +static struct vmap_area *find_unlink_vmap_area(unsigned long addr) +{ + struct vmap_area *va; + + spin_lock(&vmap_area_lock); + va = __find_vmap_area(addr, &vmap_area_root); + if (va) + unlink_va(va, &vmap_area_root); + spin_unlock(&vmap_area_lock); + + return va; +} + /*** Per cpu kva allocator ***/ /* @@ -2015,6 +2027,10 @@ static void free_vmap_block(struct vmap_block *vb) tmp = xa_erase(&vmap_blocks, addr_to_vb_idx(vb->va->va_start)); BUG_ON(tmp != vb); + spin_lock(&vmap_area_lock); + unlink_va(vb->va, &vmap_area_root); + spin_unlock(&vmap_area_lock); + free_vmap_area_noflush(vb->va); kfree_rcu(vb, rcu_head); } @@ -2591,6 +2607,20 @@ struct vm_struct *find_vm_area(const void *addr) return va->vm; } +static struct vm_struct *__remove_vm_area(struct vmap_area *va) +{ + struct vm_struct *vm; + + if (!va || !va->vm) + return NULL; + + vm = va->vm; + kasan_free_module_shadow(vm); + free_unmap_vmap_area(va); + + return vm; +} + /** * remove_vm_area - find and remove a continuous kernel virtual area * @addr: base address @@ -2603,26 +2633,10 @@ struct vm_struct *find_vm_area(const void *addr) */ struct vm_struct *remove_vm_area(const void *addr) { - struct vmap_area *va; - might_sleep(); - spin_lock(&vmap_area_lock); - va = __find_vmap_area((unsigned long)addr, &vmap_area_root); - if (va && va->vm) { - struct vm_struct *vm = va->vm; - - va->vm = NULL; - spin_unlock(&vmap_area_lock); - - kasan_free_module_shadow(vm); - free_unmap_vmap_area(va); - - return vm; - } - - spin_unlock(&vmap_area_lock); - return NULL; + return __remove_vm_area( + find_unlink_vmap_area((unsigned long) addr)); } static inline void set_area_direct_map(const struct vm_struct *area, @@ -2636,16 +2650,17 @@ static inline void set_area_direct_map(const struct vm_struct *area, set_direct_map(area->pages[i]); } -/* Handle removing and resetting vm mappings related to the vm_struct. */ -static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages) +/* Handle removing and resetting vm mappings related to the VA's vm_struct. */ +static void va_remove_mappings(struct vmap_area *va, int deallocate_pages) { + struct vm_struct *area = va->vm; unsigned long start = ULONG_MAX, end = 0; unsigned int page_order = vm_area_page_order(area); int flush_reset = area->flags & VM_FLUSH_RESET_PERMS; int flush_dmap = 0; int i; - remove_vm_area(area->addr); + __remove_vm_area(va); /* If this is not VM_FLUSH_RESET_PERMS memory, no need for the below. */ if (!flush_reset) @@ -2690,6 +2705,7 @@ static void vm_remove_mappings(struct vm_struct *area, int deallocate_pages) static void __vunmap(const void *addr, int deallocate_pages) { struct vm_struct *area; + struct vmap_area *va; if (!addr) return; @@ -2698,19 +2714,20 @@ static void __vunmap(const void *addr, int deallocate_pages) addr)) return; - area = find_vm_area(addr); - if (unlikely(!area)) { + va = find_unlink_vmap_area((unsigned long)addr); + if (unlikely(!va)) { WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n", addr); return; } + area = va->vm; debug_check_no_locks_freed(area->addr, get_vm_area_size(area)); debug_check_no_obj_freed(area->addr, get_vm_area_size(area)); kasan_poison_vmalloc(area->addr, get_vm_area_size(area)); - vm_remove_mappings(area, deallocate_pages); + va_remove_mappings(va, deallocate_pages); if (deallocate_pages) { int i; From patchwork Thu Dec 22 19:00:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 35915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp116364wrn; Thu, 22 Dec 2022 11:04:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXu8T2zIzriAAhgm1FCV0gA2e232ep78xaCZCIPzsxqsOJ0t7+pGKLI9N4w2Sk3SpEKFYwIH X-Received: by 2002:a17:907:9c08:b0:78d:f454:ba4a with SMTP id ld8-20020a1709079c0800b0078df454ba4amr5189219ejc.73.1671735867513; Thu, 22 Dec 2022 11:04:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671735867; cv=none; d=google.com; s=arc-20160816; b=c3y8vqtszVSUf901gLagxC7Zp8lkEr7nb7H0ATi6YjHnaQL/wzRZ8/s9jG/pTcoxYF z4XDSD5BS2BhH6WIg4CjzFPCBvUtE/J47hHkMC5Kl8Yf+G0lZUQfwMejHbBG6iUML4Mv a2zCEpjQ86mPNdsy/pLcdlihvOKFW9jsbXbEI+v7AUkJCI1wfee0aEJC0DAJeVFAkY/w S2vG7XbagjJsYLoOeD1cBvTaykEb0pwYzD0FMYD/IVaJfzpS+GXj0ESns4FlvISLeK+L Dad9XN2k49yruBSwoR2B1dAmNBp0vUpne4sr21sO+kKh3tLeRBZaiRQR6awsIqomsFDm zebQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i+DOrKc/WLcF8tZORAcZxALx+GbVZfz9pT9WtlPUuC4=; b=oyKQcTv4wnmIbyTn64IX2jY3GCQdqOD82/g7FWCybUa05odgI+sCuAnMfPvOgqhEtn dhUzk2lk6nAwZzAGyPhYzuqrBlw3ty0VLJHsZ2JPl9s3vXp9JCaT8fZDAEyZ2Q+AeOl1 z40eYybtUGK2Waah4Z6fF3pSCKK/m31tIaqGub6U5vCK64+6RtapjS98p0EpIn7OuFOz L9OVOYaMbWzfC0QWAyjgZYSyxzpZ9MfqRH2ei7KvRQh/JU6Z0fBc/DBTAZlgJyEpJjuo x/9cvbuh1r9W0mPi1fOdfKB/Ji9WQiJeOqubYD6E8wf/GQw73M/MQPHVc7lHUN5aqdp2 6jiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="bcrd/4/x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs35-20020a1709072d2300b007819684b56fsi1059200ejc.225.2022.12.22.11.04.04; Thu, 22 Dec 2022 11:04:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="bcrd/4/x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235460AbiLVTAq (ORCPT + 99 others); Thu, 22 Dec 2022 14:00:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229674AbiLVTAi (ORCPT ); Thu, 22 Dec 2022 14:00:38 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEED4248EE for ; Thu, 22 Dec 2022 11:00:35 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id bp15so4028822lfb.13 for ; Thu, 22 Dec 2022 11:00:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i+DOrKc/WLcF8tZORAcZxALx+GbVZfz9pT9WtlPUuC4=; b=bcrd/4/xejvVpq2+B3spoa/sbs9+HPre0M1zqgfRI4dfY5E5LLvs2Qh8ug58GxtUlS maVwcN/m+756UH2rwsGldqcaBBY4cgnAT1gpT5r67UCTO8byxZzI1h7F/Z4hd4dD3OMI pwjn8QOFoRBrS4dZPFZk1GAW7LFmW+QMvJqP19G0NtyH5b6iXpL67h0+kV8VaNk2h9DJ cmBkv3h+DmAARSsdpskD45XXO1BfEN/S2Pc4Ypcd8ACZ7ZgK+xOC8vgd2bX7/NUMoEH7 eL3xq2h11ZhNpZ2t1u/eQch2Q5E6nCkWHMmqAyYutaSnLMFckQpTER9Z80Z3zQ5VEVF1 ky/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i+DOrKc/WLcF8tZORAcZxALx+GbVZfz9pT9WtlPUuC4=; b=bGvukt+0yfOe1WOfMlMbdR6T3+c8t6GercNHKgz2bcjadgoWgvt12nfp23EzdLahWV RPgp6p7j1U8RQ9Dse+jVv+9aEAVykVUIOkTN1eLRHAnCLOciyYHbyrezFGvkfk2b/Ir0 SpiOy+HBnBRUfuxVViS+/9GAhQnwNuVA+e2hqulF8ZyAobzeknrsZlxksccO5zbt4Zei 5s2Hd1ZUje2vZ4Exp89c0kInVCcL0p8rsOyo9d3/xrYkdvL+3SRDgxZGilx16oFQd79H +NczrIdljVRCI3GbHa7S+Vbb2mWMVlYyFWpNGfABIL1F/ke4W2ljvsMemHSJ/pmCgodj E2Zg== X-Gm-Message-State: AFqh2koP/8kGwbpkZtTVGL0CcNCsZ93het2Ro6ZCqS3YtuamtyaIVNIt jFBmrxgTWGuKJogkp+Zo2tI= X-Received: by 2002:a05:6512:b9f:b0:4b5:9914:87f6 with SMTP id b31-20020a0565120b9f00b004b5991487f6mr2162013lfv.66.1671735634218; Thu, 22 Dec 2022 11:00:34 -0800 (PST) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id c20-20020ac24154000000b0048a8c907fe9sm164209lfi.167.2022.12.22.11.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 11:00:33 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: Andrew Morton Cc: linux-mm@kvack.org, LKML , Baoquan He , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , Nicholas Piggin , Uladzislau Rezki , Oleksiy Avramchenko , Christoph Hellwig Subject: [PATCH v3 2/3] mm: vmalloc: Switch to find_unlink_vmap_area() in vm_unmap_ram() Date: Thu, 22 Dec 2022 20:00:21 +0100 Message-Id: <20221222190022.134380-2-urezki@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221222190022.134380-1-urezki@gmail.com> References: <20221222190022.134380-1-urezki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752942109285366743?= X-GMAIL-MSGID: =?utf-8?q?1752942109285366743?= Switch from find_vmap_area() to find_unlink_vmap_area() to prevent a double access to the vmap_area_lock: one for finding area, second time is for unlinking from a tree. Reviewed-by: Christoph Hellwig Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index eb91ecaa7277..70e5000b9d68 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2252,7 +2252,7 @@ void vm_unmap_ram(const void *mem, unsigned int count) return; } - va = find_vmap_area(addr); + va = find_unlink_vmap_area(addr); BUG_ON(!va); debug_check_no_locks_freed((void *)va->va_start, (va->va_end - va->va_start)); From patchwork Thu Dec 22 19:00:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 35914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp116325wrn; Thu, 22 Dec 2022 11:04:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXsPY4rYgMLM/RfEqzQZYkOYMOVDPZobPldnE4iHqz5Ybx4e+Nxkuz21R/2j5oI4sZ0/7E5E X-Received: by 2002:a17:907:9a98:b0:7c1:d4c:f08c with SMTP id km24-20020a1709079a9800b007c10d4cf08cmr5218163ejc.4.1671735863936; Thu, 22 Dec 2022 11:04:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671735863; cv=none; d=google.com; s=arc-20160816; b=CUHYn95o6/8cmHnVT73FM2QRZ7WavtkklLuczBompd2LRzKOW+moaO52bfE+NDm3gw JADYagiB32/iDvpWlSN4bX4q4nYeuEUvGwQUTzfQnQhE1MLDoKr9NoWG7oup1w9dDApT EFAlAPmdKhZ2ICrJ92Jhiv8dwAbxoxL6lNRpWpOR4uOiqwDu+suuNLKqm6yucK4pqk5l 9T8lADsx+kGYznrOidvv5arK2RlxNuhBLnaggaQKnjbXreiMZzWol9tfj0ExycQ73mx+ lUXXhP5hpv8PRfO7mzFnINFsooN6uzRtopS2FD2s8V7JD4dZt++b7mmeBDSwW7lRK/a6 BKlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=At43IBCLPeuA3Qoij5h6NdcJqc+/xwkW1Zl5H96ba4o=; b=jRIG0pzZiyFJFNpN852Gu6qXL6VQhXXeNpEzUego8H0L8B3+y3buO9Af4kURr2x2lF dLyvWcD1Mzm6n7MoWRjm8DSAGVVxK2mao260MKgDidJ9CkUM814q2Ym7G5JqXtqTFloA JPX2j34TvG47K8mJ4o33bcGyXsySiMQj9djNwkTuEVho7REtM0pxSCOrjecZ8hnCOLDl HETJLS5REd3LR+XIumw1F44xeCsY8xy1ub5uwI6QjKISyOWeWnDHKeiranYrJGmIUGyS lr2ybwTyJiplMYnsSp00M4HuxBaNBq5v7ShBnqThXtFgGcav6RDPmmxe3p0s+uWGJELo ZBiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Dqr3iTZ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he17-20020a1709073d9100b0078c3197bf86si1146503ejc.533.2022.12.22.11.04.00; Thu, 22 Dec 2022 11:04:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Dqr3iTZ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230298AbiLVTAk (ORCPT + 99 others); Thu, 22 Dec 2022 14:00:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiLVTAi (ORCPT ); Thu, 22 Dec 2022 14:00:38 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA5A723304 for ; Thu, 22 Dec 2022 11:00:36 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id o6so4072968lfi.5 for ; Thu, 22 Dec 2022 11:00:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=At43IBCLPeuA3Qoij5h6NdcJqc+/xwkW1Zl5H96ba4o=; b=Dqr3iTZ0vzi70FOzZCaSh8aJhEc4QWrvczhL1whAhjZsrmsmNR9XDbERrQ+QdsxnCz NXXUnCyPLEKwSNi/nPioasZlPFKne+ljvHsef3XRmYULCgnlhYHXSTzOnqEza/jON6FP 7YvavRGlP0sUCaScGkAG+SDHAJl2mS++2Oq/qQ+zgVykelUeL9x0ATuMuSddjx4f8G2/ 2TSyGTB4r1kPJ8qSevDi1E2qgvQxatN/QWx+q+rgxp/fnX62hrfw1bM7cWq2YWpQ7eOM BkRzAmRfSliOkhUzDNtFK7zemygu+nen07SRpSIEQ7x+T+AcJu3df9Fr/pqwlU4DxnPf zH7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=At43IBCLPeuA3Qoij5h6NdcJqc+/xwkW1Zl5H96ba4o=; b=E8uyLYiMY20S7ctSvjWBe4dLt1ZOdu/EnWBrkkI9sBEIJvb+i8O9PJc2xcfAMQTsqz U/CKiVf3Ylf8rv6Za9r9aF9oEwnDxVBNQceqaUqFQxPmdhx7LIYgwBoTXE48Kyjk9RY8 FcDiPjxFPqLcieBILNChHvvJdwoOlFnZDImBDetxzBZJVmcFLuxmKl9AibXe7Oz1d/7y aQpHmKyCVQmj63IfZ8zVFKyK+Q0bS99g50PDTUn4hLcSyzSqrNF8LkL8MvkTvx/XP/C0 R0+S5KLAroF3afaavjYlDvDe9YCApihANC5FA9uApcF194wiyrRGodZuTtDEJNl7qvQQ Nngw== X-Gm-Message-State: AFqh2krgzRWNrY0hlS/IZ3h3Kw4BeHXTIGV8QyvR8fJvWWDK9Lc7fcFX R0zQQqktZv3tLA8eabVWdnY= X-Received: by 2002:a05:6512:3683:b0:4b5:b46d:e52 with SMTP id d3-20020a056512368300b004b5b46d0e52mr1603684lfs.50.1671735634989; Thu, 22 Dec 2022 11:00:34 -0800 (PST) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id c20-20020ac24154000000b0048a8c907fe9sm164209lfi.167.2022.12.22.11.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 11:00:34 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: Andrew Morton Cc: linux-mm@kvack.org, LKML , Baoquan He , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , Nicholas Piggin , Uladzislau Rezki , Oleksiy Avramchenko Subject: [PATCH v3 3/3] mm: vmalloc: Replace BUG_ON() by WARN_ON_ONCE() Date: Thu, 22 Dec 2022 20:00:22 +0100 Message-Id: <20221222190022.134380-3-urezki@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221222190022.134380-1-urezki@gmail.com> References: <20221222190022.134380-1-urezki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752942105382135524?= X-GMAIL-MSGID: =?utf-8?q?1752942105382135524?= Currently a vm_unmap_ram() functions triggers a BUG() if an area is not found. Replace it by the WARN_ON_ONCE() error message and keep machine alive instead of stopping it. The worst case is a memory leaking. Reviewed-by: Lorenzo Stoakes Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Christoph Hellwig --- mm/vmalloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 70e5000b9d68..09a9b93b32ca 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2253,7 +2253,9 @@ void vm_unmap_ram(const void *mem, unsigned int count) } va = find_unlink_vmap_area(addr); - BUG_ON(!va); + if (WARN_ON_ONCE(!va)) + return; + debug_check_no_locks_freed((void *)va->va_start, (va->va_end - va->va_start)); free_unmap_vmap_area(va);