From patchwork Sat Jan 21 07:10:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13111013 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 98BB0C38141 for ; Sat, 21 Jan 2023 07:11:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35ADC6B007E; Sat, 21 Jan 2023 02:11:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2956D8E0001; Sat, 21 Jan 2023 02:11:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15C3D6B0081; Sat, 21 Jan 2023 02:11:19 -0500 (EST) 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 088016B007E for ; Sat, 21 Jan 2023 02:11:19 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C3C51160F84 for ; Sat, 21 Jan 2023 07:11:18 +0000 (UTC) X-FDA: 80377935036.25.1B2A7B5 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 2F538180012 for ; Sat, 21 Jan 2023 07:11:16 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XM+vtBXe; spf=none (imf24.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674285077; 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=/LORA17lyKlGYgS2Flqkv2l85bKFZsz0OAvq3/+VRvg=; b=PjRH+9Jxm3iQQVyIc89uKS8TrngdPF3myDFTCQYS5BgBujItmbgEZdVyHMjz/i8hEsv9uF MLIf7gk+geb5flrKJ1dbBXza9welBbthg1ZuhiVbNagTRKj92j8z4qGCSJOdMOXWUe1ZDA xttcudV0SfO7YDHQ//ulkC+Fxve+M5s= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XM+vtBXe; spf=none (imf24.hostedemail.com: domain of BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+1651c3ebed9361b307e7+7090+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674285077; a=rsa-sha256; cv=none; b=GhKrM5Cho/MSHqUU0QGam39IOoT191n6oGPVu8X7Cq1ydNAfBNq0Au3e7QjxXNk67xRpmE j5k1MzrUxdxWomuu6kAftF0ZFIjaxzY46cLBBBzUrqODd74axA2qjtdhP9En7mGlm8eafR rLryccJHeVyFpawupHeGNSMj5ypEn3k= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=/LORA17lyKlGYgS2Flqkv2l85bKFZsz0OAvq3/+VRvg=; b=XM+vtBXeQfHIdNOqhrRFIiQpVS as9nNsLzVhrL08NSOV1H9gmav0bvUe3POeb/f3XAmlet6O+Ix6L6o9MbYT+A0mDQFVc9CNw85j+mP NERzLlXmIFRpcIF6TyLrvj+CSmnsLkAMCCr9tZH85mXyIYuas+7dHo/5XtUDa01aAH3S9+j5JvbC1 kEmrBLUnVJkZl2i464hgzmRvAWEDjM/zFO+aJTEX1pSxpnrAPxtoV7C6pYzuMWsMZkF9uGZhEFupU JBOfMQNwevrkxKwrCCOX8UdmwyiezK2eYtxHpuW8dnEzOjlQUb2uR+3ZpkZOtuMtVNPNuO2RmEIrx wnRPmJLw==; Received: from [2001:4bb8:19a:2039:6754:cc81:9ace:36fc] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJ81v-00DTqj-OJ; Sat, 21 Jan 2023 07:11:12 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: [PATCH 07/10] mm: use remove_vm_area in __vunmap Date: Sat, 21 Jan 2023 08:10:48 +0100 Message-Id: <20230121071051.1143058-8-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121071051.1143058-1-hch@lst.de> References: <20230121071051.1143058-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2F538180012 X-Stat-Signature: ht4o6c54kfbw3xco1ox1r4oddsk8kqsg X-HE-Tag: 1674285076-134156 X-HE-Meta: U2FsdGVkX18NwP4dkbwW0KgVQ4dQqUAufK2MIttk2pFoMpRihUhLmHLPHWpG/+optZRQsynvrQmokPBsPyKz5tAlrC1IRS3QxI6ktnaoQmVhptxwORUi4L/5IQrb0OmhmYQgsUlERGb7HzRlARD4eNiXC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jXSiTDpGw0+MMUO1j7vyRh9Q2+PuX8hhskYzlc+95Sr7xvo0qaK5t7auYvrpq9N0yDmkAG3cjJ8R1MvgqKGUGdpLm1XVt+FkUmNeziRjvdrGLvbeTKc15+R3mA+jBS06fpMCzbwiTaiGWgHRgYoAi/ylJ5IVlRRD3ZMoePAjaURmV5Futqd9Vda+ABV+vjER6bRN5lWkewf2h9PKaef1/lbzpeXbUGSkhEOvMQtesW7tio1x5pYnK9m0RQdbU1CCkqxdqvtZSBcS8aIzQzHg4XmI8AvtBabtgM9Ayl0/KCD3zKX2UBLzZgbAFQlW5KDOlBv2IuC6ntyEZTQ/ 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: Use the common helper to find and remove a vmap_area instead of open coding it. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) Reviewed-by: David Hildenbrand --- mm/vmalloc.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ee0d641019c30b..97156eab6fe581 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2571,20 +2571,6 @@ 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 @@ -2597,10 +2583,18 @@ static struct vm_struct *__remove_vm_area(struct vmap_area *va) */ struct vm_struct *remove_vm_area(const void *addr) { + struct vmap_area *va; + struct vm_struct *vm; + might_sleep(); - return __remove_vm_area( - find_unlink_vmap_area((unsigned long) addr)); + va = find_unlink_vmap_area((unsigned long)addr); + if (!va || !va->vm) + return NULL; + vm = va->vm; + kasan_free_module_shadow(vm); + free_unmap_vmap_area(va); + return vm; } static inline void set_area_direct_map(const struct vm_struct *area, @@ -2666,7 +2660,6 @@ 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; @@ -2675,20 +2668,18 @@ static void __vunmap(const void *addr, int deallocate_pages) addr)) return; - va = find_unlink_vmap_area((unsigned long)addr); - if (unlikely(!va)) { + area = remove_vm_area(addr); + if (unlikely(!area)) { 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)); - __remove_vm_area(va); vm_remove_mappings(area, deallocate_pages); if (deallocate_pages) {