From patchwork Thu Jan 19 10:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107655 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 7A07AC38142 for ; Thu, 19 Jan 2023 10:06:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 180078E0001; Thu, 19 Jan 2023 05:06:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12F026B0085; Thu, 19 Jan 2023 05:06:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F39548E0001; Thu, 19 Jan 2023 05:06:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E4C426B0083 for ; Thu, 19 Jan 2023 05:06:34 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BFBE31C4F1F for ; Thu, 19 Jan 2023 10:06:34 +0000 (UTC) X-FDA: 80371119108.07.6099E6B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id 46CF7100007 for ; Thu, 19 Jan 2023 10:06:32 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=bS1CoJN8; spf=none (imf05.hostedemail.com: domain of BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+d6c99cb0ec1a2cfa7d20+7088+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=1674122792; 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=WZU8nCOq2sige+3G4gVQDMyQgBDgha7FhSR8F36iY04=; b=1lq67jRQRsK/Jq+NVd48sUqg9w3z+zuS1LTPBGL6Zs5FAdnCtTtVqLxAOQrb5rR8xdTcYS 3kiGX1by74feaNPDPJ5ss97Wh5ieyUC+NJ/PO8AT5OvBygVw6jP/yOBsdb6AgXdo5nN5VR G7zKqheyVlw6NEDF7xINUKKLNRAPjR4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=bS1CoJN8; spf=none (imf05.hostedemail.com: domain of BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674122792; a=rsa-sha256; cv=none; b=WO83e1TuWCUDXVlLrcgYASM/PFzczIuXPLXvcmR2/iE6B2IIkYDTvFEoNtXMxd5AU3TgWn E33EPrGQcMTOOnkBmPzkZUa/K3CEwH41ptqF9VWMUm+Y3HHVPo73zMJmnfTsmrKo2l3nyb IYYHOTRjJ2gWktCR51XeD4KIp6P5s3Q= 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=WZU8nCOq2sige+3G4gVQDMyQgBDgha7FhSR8F36iY04=; b=bS1CoJN8gSNzbQgw3PvmP7USXM NBtQLU3o1THa1r5hRSfVNett827HtWs2N7oOtJ4IE/9y9hRDjD0Z50gsgBIsZzrRCKc2TyAyko7rr D0Ey968id21p7dfhnTdYzWvht5kfC5cMp/POygyt8rPzMkjUmUel2KVNXoAw9BS+nVpIDoLEOhf6R mnZctfObDdI+OzhPQXMVZ5OsoJMAqLXbrr77exAS8gzfyJ1X1IdFpHq3OdnwyUG/CYd2YQ4CE2nEZ 9tMWOpiZhJEAxtCg8QOvovUfbN4EOpFrrg461MZvN9LJg7m+aFmGkc4rk7JwjtHirUNBEL+BEIdEx oobpm9HQ==; Received: from 089144197172.atnat0006.highway.a1.net ([89.144.197.172] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIRoU-004N7A-0p; Thu, 19 Jan 2023 10:06:30 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 07/10] mm: use remove_vm_area in __vunmap Date: Thu, 19 Jan 2023 11:02:23 +0100 Message-Id: <20230119100226.789506-8-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119100226.789506-1-hch@lst.de> References: <20230119100226.789506-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 46CF7100007 X-Stat-Signature: 1m8xymhjjjetfpwdab1co678iwef511q X-Rspam-User: X-HE-Tag: 1674122792-859348 X-HE-Meta: U2FsdGVkX1/J8C6hXnpCgcd1JaKr0tfE0Y301KaujZebqtIWkP/CBIt/JloL3xs4a1Y+k9O3VIjxtD9Qnsafa7MbL0vttZewE6+JABIkWcUFnxjGPVft94ikkMwZt/8SGRhXNgiItxX+M04/2SyOcguyV6lKmX9MNqeOs4+3VAq1Y+o2H+7NXoE/drftbW4NU+vMVCnqPbLehx2bK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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) --- mm/vmalloc.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 09c6fcfdaeb7c9..096633ba89965a 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 va_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); va_remove_mappings(area, deallocate_pages); if (deallocate_pages) {