From patchwork Thu Jan 19 10:02:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107656 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 581D0C38142 for ; Thu, 19 Jan 2023 10:06:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E76B56B0083; Thu, 19 Jan 2023 05:06:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E25F68E0002; Thu, 19 Jan 2023 05:06:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CED636B0087; Thu, 19 Jan 2023 05:06:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BE4CD6B0083 for ; Thu, 19 Jan 2023 05:06:37 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9AB8C1C1F8D for ; Thu, 19 Jan 2023 10:06:37 +0000 (UTC) X-FDA: 80371119234.06.B105B71 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf27.hostedemail.com (Postfix) with ESMTP id 25D924000F for ; Thu, 19 Jan 2023 10:06:35 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=5GivvQIF; spf=none (imf27.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=1674122796; 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=AElLtgOVMNP1XmOOqZ2Yx/1rqE5S/2CvgM9Mbc1XABY=; b=1luGZtWlwKijqWrL5Ib5QqULQ9oN78MTKqsE/LhTB/AsGpYUblMlG0FfCliXb1NBFHuG1q 8UK3xlUaupCK+5eYscoB+CudqSUXDgy7u0fGSEE8BeWSHLu7pIoUgynzDdDaKyLtFnceU6 MZAgGMKuxV5gjrmavhFZo1flwhbMptE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=5GivvQIF; spf=none (imf27.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=1674122796; a=rsa-sha256; cv=none; b=cbFHsXixxLZH9m07CF5CzxhHEuVxewtlC8L/lKtEqgSX6xqDDJ5CcE7puAhIyy3kKLVLoF L59qZe5OI3CcK9DHggpCOfwyq0vw2lhfi05g0ZbnZGoGwSAA+eKK1Q1XMgtzKnFoz0gmht Y66mEWR+oVXelrHiyhUWvkTgojp7NWs= 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=AElLtgOVMNP1XmOOqZ2Yx/1rqE5S/2CvgM9Mbc1XABY=; b=5GivvQIFGsM1iR51lSwNcPFX6q 1WGKhbxoHwKwoXkg5aE70892tU/CjTm246FHtNqfU2WYoNiTph9pCCWjazJHo8gRucCXT8Q46g8vf Enx4ymi7a0TaVkuYeTcdqdDy4KT4xHsb/6ao+7k4vrnuc4OOPqcfb70k6qx78GaHxV1eLY/4FPNCC EvLkqSS+o8Jl5mOu8nrbuBjOeNdMBRJUhR5lHHbegr+G51ECfzxgspNEaaAJ+h7Lce6LC0yU349qM 7M0lXeiPIpJHyN2163WtvE1BV6a+6VKGulT+65Umu6o5xNTLi3YQy76GK4imXV9AElLfQtRD4sx+G E/fyNGxA==; 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 1pIRoX-004N8u-IA; Thu, 19 Jan 2023 10:06:34 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 08/10] mm: move debug checks from __vunmap to remove_vm_area Date: Thu, 19 Jan 2023 11:02:24 +0100 Message-Id: <20230119100226.789506-9-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: rspam07 X-Rspamd-Queue-Id: 25D924000F X-Rspam-User: X-Stat-Signature: rdobowfck7cbr5hixbx8sck8da86cgni X-HE-Tag: 1674122795-751382 X-HE-Meta: U2FsdGVkX1/6GVwjITi+v7m7rCW+ISyCegzOiNCgsak3NaOQ48G3An5/VZzzmtM8mkOMseeS2d02DIZbUvjE5K7yO92db/mhPRS8cEw/AAte8PAlg1v2krf78PgF+OKOFiP8DkwyBiNYC/Xy5C4bCCuGfmG+Kg3gematWGX1Ot7ElCR8N49ae2eh6+dM7/Vh0la5hOq21THcqOci1LYKqKmV8+RbBALZJwNVYkIJ7TONEODrBLMGPUAHLX5PXFyug3C7PX31ZgXeO6CHw0kmI3A3yA19aepTidyL2dBj7XZNdvBJbcMFIZlf0TLoY5A7/kEIo6iL8f4KDBI/9TcfCVIsVeoMHb6FPn3Ap4puoWjslnE/pzSP5M7UBkbQYnqnr241rbTBjLAWW7h+lsqISDdjn1n0ARNlz+ziB5hYJfFoUon8W22HQVBNFB78MbPiHxWzvgSmrttrLCWYzhZzj2lS1Gt1wlnqHkyPPbhniw76aiXodvcS0w+oskwx4suEuy4xyzn+O2pYKxLv+vla7sLTH7hRvWwohzii636zNgMVisXCLheJcDtasrxwno8EN3eUW20vheeM2Ei1Nw13VGWnNuxO3WQ6t51KG0gELFaBymgxoGwegpHk1uMFBynDz8Hisdoni6+EgxaWf6c3GTXEpNIhEDNjiIGt2zTlFuIcytJMGrWE376rKvscrlkDwuV9Xpphj3c+d2mXRYUXXIngNA/5tsS30eQLh4Il4iOPuSsADlfcqBlYMF3t0OffYAPrRrWnBzZmv/ANmmHuaeEba4CALlQeNTZKBeeRBfLNKEt+6TW10TlKAbLLD1U4AZ5H/bnHtfGZe0bIBgU27zs5NB9NOmxqxHbgGC5sNbhALNn9axYVwLhC0AvtdPjzvfERv6Kabj5RyoLlwXDr0OSzR62ns/3v+NZz1b8Em63usN2kRJmQSUJgmkbpbcu9mrzg2Ghy4Xp+hcPOjvL QBbC6alx MOH2y0ef2QdcWIzXIJKj09DFSzOxz1jWK8qiv//TMlJ42sxfzfB/Z6yFFa6D330iI3Ro93AcQFsUorIehRmBObCGAaWHAOzLOboqJPBQSFlEP6Zp6qqkND/HOifyRcsBDgLohNoPJBBgF7+KGvVZ4hfKj6t7Tom+e48Hlp8YnBhgpSczaOc5CbyiHJRmETG931KDTbr/uB/esBLN4L/ztjsBLinwRzpBgM7NH 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: All these checks apply to the free_vm_area interface as well, so move them to the common routine. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 096633ba89965a..4cb189bdd51499 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2588,11 +2588,20 @@ struct vm_struct *remove_vm_area(const void *addr) might_sleep(); + if (WARN(!PAGE_ALIGNED(addr), "Trying to vfree() bad address (%p)\n", + addr)) + return NULL; + va = find_unlink_vmap_area((unsigned long)addr); if (!va || !va->vm) return NULL; vm = va->vm; + + debug_check_no_locks_freed(vm->addr, get_vm_area_size(vm)); + debug_check_no_obj_freed(vm->addr, get_vm_area_size(vm)); kasan_free_module_shadow(vm); + kasan_poison_vmalloc(vm->addr, get_vm_area_size(vm)); + free_unmap_vmap_area(va); return vm; } @@ -2664,10 +2673,6 @@ static void __vunmap(const void *addr, int deallocate_pages) if (!addr) return; - if (WARN(!PAGE_ALIGNED(addr), "Trying to vfree() bad address (%p)\n", - addr)) - return; - area = remove_vm_area(addr); if (unlikely(!area)) { WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n", @@ -2675,11 +2680,6 @@ static void __vunmap(const void *addr, int deallocate_pages) return; } - 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)); - va_remove_mappings(area, deallocate_pages); if (deallocate_pages) {