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: 13080236 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 C7DF4C4332F for ; Thu, 22 Dec 2022 19:00:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3EA7900002; Thu, 22 Dec 2022 14:00:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBE21900004; Thu, 22 Dec 2022 14:00:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D37EE900003; Thu, 22 Dec 2022 14:00:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BD5AF900002 for ; Thu, 22 Dec 2022 14:00:38 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7D5A1AB4CE for ; Thu, 22 Dec 2022 19:00:38 +0000 (UTC) X-FDA: 80270858556.17.98D718B Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 63F9140002 for ; Thu, 22 Dec 2022 19:00:35 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PjEfHeIv; spf=pass (imf11.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671735635; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=xFGD4VIGKFF/VgK3W8l6J2/VT0xeVWmVNx8bDUgm6n8=; b=eCYm+qj2Dv/MSPiEo9XBfIve2+d2fMXUx9i9de9u/qdKVt6ibyLCXbjQGEg44SS/MMSlpn y++o8jMNsF5mrdbYE9d8wEjp9bJENqPIOBn3KBi63NjYHk2k+sUziOmWW3eP8sQxsSeNiG ldycbwhQuA55aB9O92t/cGR1YmWf4Js= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PjEfHeIv; spf=pass (imf11.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671735635; a=rsa-sha256; cv=none; b=UBFa6p8NOfguvnO5fd0MdhdTRjflokrZYq833Ys+HBA6jmKqH3CU+YJSh6PFDHhuNKsNR3 OjlCzGgbXvCTqbNLoT30MqaAveBQXiv06QMF0gdji0P4k3bWd7k0JZJYbCvKuLm5PvupRN 4gl04NJuO/AXKI4rpqWEDf5ZmSwcntY= Received: by mail-lf1-f51.google.com with SMTP id b3so4093014lfv.2 for ; Thu, 22 Dec 2022 11:00:34 -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=ye+OyVoEDTAhwDPqP0knCD0zx6kuWW/13T8+e2czekIj03BuuSFuqAUiu97kzUwd/N QGB4hNGrnSw6dhhQtc03F4niLFDQh6tn5fy/LVZIWfA0rzJueQECQfG70s+MnRynnoZf sCHqX01Eq6V2i9nlBKs/KtXWvbJyM5pdhKq/52trYhy4tlLjkFQ0kTI8uRgk38HENiGN 2FkiVMdegpRohGg2nyxW7+a+XZydobM+CMo86q3EOgc1FYlxdIXnF40jTi9Yq6OZ7Jud ktM2jOY5rl9w6zy4YSQtBjEeLkYzSg0e48y2zRSIT/oLGS/4hWT/qNPOF+el+Jdj4+0T Juqg== X-Gm-Message-State: AFqh2kpAhULVInxyB02JnvNqVg7KrpnOPN8xVNhnVt2gq2K47PKeofeK Ujv1K08yPpv7TK4BZFlEpZc= X-Google-Smtp-Source: AMrXdXtwRLeGl6roX1wbkOoZ3GXJm4X3LNeUwUJivdXD+/FVCK7yPlPjMZWjL7DFMTWhKsmS7oQpGg== 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 63F9140002 X-Rspam-User: X-Stat-Signature: dr5ict8zkk3kopzg5e8wwq16xpbn5zqi X-HE-Tag: 1671735635-40655 X-HE-Meta: U2FsdGVkX1+ZS/H/mkiANiqNWvOR+8QrxaO11rcnqJMcRqaA46igoXO9l3NCg9OeOCbOb1LSO3klrpBxx/0HhImoYOxLebUFZLjDAEJ/PrD/PO0hAgbmdg0R0+/1z69VJvrVpjB7ixLbK8yzzazrny0cbcvwpsUoUAM73+cGO034mU07xlJfjJh/QjyXw1WHq/FutSPll6ZlrYQGSMS2Eo+uhr/BWRprciB6cEtwwlOw6GN9SaoMVMmEC5dp/dQHLafu5BmPEDZyMCPFHJkbb/OlJIKuSeHKHrz5v98F1uRfDuI2xkl/HQLASBrgkuBhBF/i94vXR5dM5zeXJI/H82KoilJ5UikwmUGBgNiQGjBiq6e9HQgIpLb37caIFGUx5srXkVJeypzBK6oWsI3gDNGyAmS3nWGMypEcS1XLjnDTUUDIkgfSpslnFgpDHw8BB91h9sDaVnJ3+7mAqt5nTAO2JFBrNXNgHg7YtG5OG3u84A6VIU/4A9bfOGqrpSLYA1zbD8adPmWPScn3+EG4aWeMnrds6Nvm+ERJpg3t7wQBNAD2sfYMo5Th2WjtWcdmbTi9qILiJzRHHhNk78FZZvaHcAx5yq0akMU3ELweFJIYkCKNBNulzjW5e5np4nb+lRDRRLt66UOMC13BZauxlyEFKs6BVWM1U/JgA1BdK4eZfhprROBFIsK/Lmo7RYrkMbaFZhTGzqa1LzPLxDvT4VE1bd4jfpxdcwMa48cZB5TgyOT8YVc4HDZCt+I6UldLBh7g0qSzkRWIUIDa46xvsI3wEClsxIvudx6c0+xH5+rAMYYB9CeC1SBINB4oRpmBB4mSR00uIERl+fz7xicmwFoFEw5OvtjLdr83/4FHtIF2Zngg6o1TbTJhWLvNdQFw8Z0IBTc6s62FH6Z55fYfBAmpOEa41ZSN3JQKA41XDHWgxSIk2jGdU0TbShRGWYS+2b/XiYnk+NluAUIbKlr A/6fZk8j Ol2EjtoiCme8a/G4xnUlVQ3E+UnO1P34G/qbLhMDjF5dFK2UTj2Mak9vUc1L0/ItfTDQDZzA7TbOmLBSdsB+gRK/4l1aaueBfGbm3iAaoASvTe/3WpGmfWj8b2HRQ44jtfKas1hdjqdiuahfaj43RP5mQz5DZPIV7OpwI7GfWERBrmSM= 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: 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: 13080238 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 473E5C4167B for ; Thu, 22 Dec 2022 19:00:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CF94900005; Thu, 22 Dec 2022 14:00:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 65802900004; Thu, 22 Dec 2022 14:00:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D3B7940007; Thu, 22 Dec 2022 14:00:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 30A13900004 for ; Thu, 22 Dec 2022 14:00:39 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E733C1C6727 for ; Thu, 22 Dec 2022 19:00:38 +0000 (UTC) X-FDA: 80270858556.14.6D5574F Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by imf18.hostedemail.com (Postfix) with ESMTP id D93D11C001D for ; Thu, 22 Dec 2022 19:00:35 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="bcrd/4/x"; spf=pass (imf18.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671735636; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i+DOrKc/WLcF8tZORAcZxALx+GbVZfz9pT9WtlPUuC4=; b=O75LikEXijioAGXmDm2WEQ43/hp3yRU4f2DcgBTZxjUZln3w020btGYd7zzKJVFeh3/OEr FfE1ntzP4tIojwQo5pI7ybfveKbshNQthv9DSnuOwFu9JyCj5WMsFXwgxNJDfetubeMXJu kJJ4wUKBPDHGeLPyLAj+EdnnQ6frTWU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="bcrd/4/x"; spf=pass (imf18.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671735636; a=rsa-sha256; cv=none; b=EA8SUkK9qWqKXl9Z0YsZj6GB2wHCz8Z07X4WCeoIirwdjOnBu9VPoj/Y0EpNBsWfpbj5Ka EkZHlGpRH22RHhgINO9Y5RHx8ln6uUKI7IUelQaybszAhkvRxcuc9lhU69iRTuO3n1T8EY 0V/0zlp1qyuOQlTjvBx/PEm1/ckj0xg= Received: by mail-lf1-f49.google.com with SMTP id cf42so4101212lfb.1 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=R+wcues/eVAAo6keT3Ktw4TWKhMa4Fhjwq/Oj79Egpqnp18LXQyH0PTiLB9cpEr4Q9 nJ9Fa6tz3x30IYgnim2HUxAY5gn09eWQ4nI6f4bmwcJphKt1BxI1Q6b+TL6R/2juI6CR VuyGd1R9XbyUd+kdPcJYtOYgtxMmaviiRrsjlxYbDKOEJiF797xvCGq6Y51xGDExyhnS U3oh4TiEuPpmHemOLiO9b2M3ixDpht3bpM4tINcNMz2hcjkkgY3lih2hSot6P5DyxPzj xI3BbStPx0LCK9S3uNhvamvGHylE0Z09hRaFbJRVKMNI+5mMC9qVX7JgB5SY15TQYown Tq3Q== X-Gm-Message-State: AFqh2koyThCN+239AvOkYC6vQhfb+x8eJkxgVuSM1j2jHGXH0xj/ZV5E jDItpFZj/4YbSXyPFhcawVA= X-Google-Smtp-Source: AMrXdXul5bZK1z5ZO6+wV5M1B4ckWgEp7djYnY12RmpTYVoVITC2Do/+E8FCHd6bs5YsCMrtD5VgnQ== 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D93D11C001D X-Rspam-User: X-Stat-Signature: 478tdeeuahbrfuw8uf6tsfrmpjwminka X-HE-Tag: 1671735635-535244 X-HE-Meta: U2FsdGVkX1/rvpDQUd1+u0cNpdEfdVPaDpvzq7Rf5usqTs6bcbosL0lTdCIeK0YorUBKMzxdCIu4/H5NE7pgzBmda41cpvuoLWINE/HUrFW9lQqb4VsxpVsIF1XsYEh5iyhxYcG9GFX79lXHXVAvVd4mw5kNRGeqH/eNt76eGY9fegEL+Xg6gxH9JnI9HaPWwRLByibljfxthZnn2otGGQHxaGPSskne0Oe2b6jQdhoJs/EeNEqkk3ZZbbLfJbl2qJE/l4SMwVBo5ZcrAkCV7/wvMM+y9FsWTrNqp6QChniuDh9rvf8xHbdozZ+a7CgJ/BdZvG3pNJDu9VQFIumYI0XA+JWncPds+3wGPzX45omVX7biPSrYwH+m5ZuVh7xjcgvQnhuKQk7KayYIBB5okLwqZ5SXuttnl3cpfNh2Cn3fbV2DWs5Pmj0JzvtPzner1mF5Wdq2yJPfVgAeOeuYddjfC2D7GUUluB/nEKlH3TqDNCnYUXsVC3mzAqQbQZtdbqk7LZ2Wxf3pV43mKsLKpUrLHHLdeLVWpIjfDL4mZUMXVKdDfIeGVXUXT/mKBEsZ1m9NDCeyNllwLaEqzTXiSO2dNzj63ru69ntsRMnA2SwEHP59hyIvAyi7q/rP56AxDIC5svK4lgXQ8cI/6QAfRX4R6pzL5IcAn49nXdGWHGGgeOz9e/UjsaSwA+ZVFntRYwAdxxhK4TD5Bo8JqvnBJnIoWtIw4qhfwaUGOBr9n9Hyjz3uUn84R8C+S3k7pcmnhVhQA68yO2+QTRDhdUYbId6XkY+B2SJU5QEAxrdk4n0ZES8N8DYLrd4wSluO2sxiUN+t8pQn6Jvt3RV3U2Cvgtar8keZ91IG0d19F7lSofZcRCjsO+MLCtnghWqKVmX3RdPIYFkP6TYldIzdkyBXsQiN9+8H+EKaP7qj2jjMb6DDrLTK3+CDQ/BJBbK7abUG6w/AoFG9/MnAvXja/Lm a6xe8klp mTyI8zf9UiBnkIlh5BJsIuK2EQGiDr1RnA11yy7YKheUSBuBRS5SrBpaWLVrwPSY6jsG83PK0rG4/YZ+Hezmtu6DDA5BW9kWHC1Ww8Cx9PLUVkeE1wFLnmAVrXo6Z3semgppxQdekhsn3kmelBS+7H5LXFMLRf9UmS8YdEvRIdGTa/mQ= 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: 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: 13080237 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 7DB00C001B2 for ; Thu, 22 Dec 2022 19:00:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C4A0900003; Thu, 22 Dec 2022 14:00:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34B72900005; Thu, 22 Dec 2022 14:00:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F33EE900003; Thu, 22 Dec 2022 14:00:38 -0500 (EST) 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 DCB87900002 for ; Thu, 22 Dec 2022 14:00:38 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9B2A41A0949 for ; Thu, 22 Dec 2022 19:00:38 +0000 (UTC) X-FDA: 80270858556.19.E97A999 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by imf18.hostedemail.com (Postfix) with ESMTP id A40151C0013 for ; Thu, 22 Dec 2022 19:00:36 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Dqr3iTZ0; spf=pass (imf18.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.41 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671735636; a=rsa-sha256; cv=none; b=qu3ZeOxBcJAD+qnsOm7r6hun4lV4U0/DN6tLoTxHEjz3BqcfWKhR2UbhJgcAN65jX/IC6s eIDrXnHvdX2FQkYtfD4n1LUZbtuX3i+PBuq/RCvjuVov4cf7wXM2K15mfFlkKxaDLmdvjC 76X/+c3PZD1EDaO0gnrXVTWvjW3HLNA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Dqr3iTZ0; spf=pass (imf18.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.41 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671735636; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=At43IBCLPeuA3Qoij5h6NdcJqc+/xwkW1Zl5H96ba4o=; b=mjp0EZoPVUbUoEELuAqVrHY3d/yvcgsv2nLGBwdDp+EXPiw2JzalypRzJAsddrrPf06BcJ 6nu5aKKecFnKZkh1E1nigVbPcYYwrz2Z5fWfQ7XLQWX+4Mua5IftES7m6pEr23O9DGFVAS VNKoshKWBoPuwhU1uRkKU/8m0x3sQYA= Received: by mail-lf1-f41.google.com with SMTP id b13so4094767lfo.3 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=uZYOp4C6A8HOS6lXTGTHxDVe472X2iOOysFqoa/vgCbaHmAbS+Ix4PmpPEOuRNcM13 ahG1OBIaNhi1c7s5FYr9pV12p6u+xOY1qzAHd7Byfl/h8X38b87C6COBEBZV9X34omFL 0DlFLnCwYofw9Ax8WghtOU+xrRTKeYwm+/PqRbV1QaaK/n0zkNCOeKP4f/kAgnJqWa10 oiJFx24X5XzDpZKLsIFlh4e6XwXygaR6eutB7FVmkaNchxozucB/Kv4HDx9ZptXdr2R8 WDg5eP6UcoPlWX32dz4ku3bA14XjJL6l9suLeSej/hxxTyvn24agjGjMUvjanv+kcvr6 KVUw== X-Gm-Message-State: AFqh2krv5NBGrCqB87CmbqDBqpP/+/kIGfLmJtmzGe3QFNSthJKQQlMx 7lVVf7GJSCPiXuDN7Qw7sL8= X-Google-Smtp-Source: AMrXdXvv/k1GbWC8VD6nUe01H19g0QQ6rT7WPMAhGe/HhukHF3+U6/vdOWzIkaKy+1YR/bzzerRjTA== 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A40151C0013 X-Stat-Signature: pmtgmqibxuykbst17hgfbti9arecad5k X-HE-Tag: 1671735636-84309 X-HE-Meta: U2FsdGVkX18iVgE2qR2qkiCbBnfZx3rHg87Z3LeOO8afZKPRL0KR3wi4gOU/gE5Z8gImZaBad+wTsNNnBmsmWkrhdcVtzZ2OS7ZJ96vAA9NmDHLEMwmAFVudMg6HX5Won4oU1XBLWesmKsSuLpodM8S2so8w2II1yq9qPDC9pjaFC6t0rwBjqH1wpvsMVV7HRM9u5K5VPO6deJRBNTrBty4UK9yEw6Ip9FjZMRjve7AubxIEL/1r/LVGB7JBDsMTmPJjR+jQBKQfEWgsHcJBirugaGo9vDQHeAbTJO7LGkY3145VT+6D56yzrXA0wOQGQkx3W+D4sbgg04K5DpXjR5cvaehl4aT/5PpwhgVcZR1YBqTX5VBdoY3L2j///BAqJha5vkq7jvV6fOC6JUQ4npkYcWyberbF/3vxBR/ifrme4zKCj3PXqsVJpaF3ZpQqk9r8WD0ZppSYu9E3hoDzBEvtyJo0o1fkxn9ghUy7irwn5dw2hZJoaVMz9bHcgn8PcUzVQgnctT4KecWCDtXlORKQhmN0UYYF8Cj9pDkBCqdLCWBgrRnqbXsMjYPPMHZPNmhIvyqhIGJGLXQ2UJZT38iL6W1J5Ykth4AyhA8Hz/0U+imyIDoXRBvfII/7fRQSBrCbsOWhXv85+vnwpfKVP2gvE1dPBK71ECHVHWTIY2HIkfVcprA9lJkcCg3mFD9iwWVDuUBfDI1xcXYIhtqi0A6Eu0v/d2JCrLtBdWE1biUcr91y46OgoivdJ96s+/SfOjkGKYYUHl2RDofKxwvVBNIu6vAy7MKtV1BjktXCHu9wZ/iq+WMAiqHHRbnhhWSh4ImPq6kIvn7bwM8+vdNdEgpKxh1WBpjprlUTSyzgbnprQYNfzXbHX4ETzyWRYMQzVzZhRME34oj/sgfema7ICi8AuuOBBdIL3zSLKA3tX1YI0LMpXjUShdup8WvXPD/Z7FiZTklJkItCGO8w8zb YpBFI1Th lhcbqGBkRF/oRkIYJ90k8OqGUVOKdFwq1oWgwuhucQHz2bM5rjzyPZ9fbhvelt58jD1KLdL193UwQ2GgPiKbejHGCzODnE9RCErYrK/IRf0ypEDKDZiN9aO/8EmmHh3tMBhrbcceTd50FC8ohUoo9/uBHpMYysA5EnFtdbvtnWAHmK6I= 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: 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);