From patchwork Sat Jan 21 07:10:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13111014 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 0AA3BC25B50 for ; Sat, 21 Jan 2023 07:11:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C18A8E0002; Sat, 21 Jan 2023 02:11:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 971D98E0001; Sat, 21 Jan 2023 02:11:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 812D08E0002; Sat, 21 Jan 2023 02:11:22 -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 722F78E0001 for ; Sat, 21 Jan 2023 02:11:22 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4DABF1C418F for ; Sat, 21 Jan 2023 07:11:22 +0000 (UTC) X-FDA: 80377935204.02.44E5735 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id A6BF1A000B for ; Sat, 21 Jan 2023 07:11:20 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=1nYfA6Iq; spf=none (imf15.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=1674285080; 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=2AhZtCg8WcctCTduxx8cDUSUIZL38/xwLWyYwxGa4ko=; b=pYd2Jy8QC426WtRJ589KboRY9gejTIkfg24tOKRJn1SgIBlH3vFVh8LZ0Kqfce21FnTmPy iMdD7hdp9rBeiufztrHSdh+YsLWM8Ks+by4TEuqWAsQ000AqfRqz9Tck2jsV20mOLYUxQT OHqXn8PCm3OoMIMmkuamXmpIFXx4L4Q= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=1nYfA6Iq; spf=none (imf15.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=1674285080; a=rsa-sha256; cv=none; b=Mkq/Z6RPrHbJ9LKgnzY1udQTjjfMv04b6zVkVn4/JUNS4Hk3tdmJa6dO63RpoCiKCaHxdu 55eAJgDzPq9Ggm8utakBTdq/dktWvm/AJCtHRGfGl4vwEDlmxZvkQMl7wULsmsmuEt1Bfa geSArKnp900wdgXuLSTqKP2EAfcl2FQ= 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=2AhZtCg8WcctCTduxx8cDUSUIZL38/xwLWyYwxGa4ko=; b=1nYfA6IqZ22RIVP4VNjWYursgd Wzd52qurYBoiY5lhthB1Ey9UZpv4RdZ84MHk0oqSJLDXtuod+IJpqxtmg7d6E445XUHVK9DVJlQa8 wW5Pnl4Dvc27/w7DWkm2DV5OtHrWUvqjSB1FfMIXuxdMaEQ3uaTQTgztjizbgxOMf/tLq1nMFCsOn lE6ZJgsTna49sB9nbnKnkuCTjkifirZSs12RAmr+eKkITv/HI7JOWUPaSChQY0ibJ4N9BkHkeKL+Z Jpx8qbvE2Ft05cIOPi440FOdkone7RPDFJh+Qu/2mNbwQmzQXvQ5fPsyXEaOulfSOHONCIeSwseUI /fpcQgAA==; 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 1pJ81y-00DTre-Kp; Sat, 21 Jan 2023 07:11:15 +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 08/10] mm: move debug checks from __vunmap to remove_vm_area Date: Sat, 21 Jan 2023 08:10:49 +0100 Message-Id: <20230121071051.1143058-9-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: A6BF1A000B X-Stat-Signature: 18ecn8otit9gcdemzopruz9q1gi1pctq X-HE-Tag: 1674285080-704307 X-HE-Meta: U2FsdGVkX18X/YwKOj+35+fRHG8lYpOcJQerAIrak6RPlVnVb1TPAYXoA2T2GiLRwKA7f+praO+VX3XollBv/zuxImFU7i4PejCARfVLS/GSrDFezW9JG9oY6U89mKUVwDp1Yr3WUe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+TSjHQDEmMMOvpX2DVhtN/6LOJu9JXJEsckY4fNg6YDtlhuI6h356fgnN0nVJvB16lSR5C+ERWog8sqEFWkUKVjoR3cvENMn/c4a3Lx3QEIqlKlW4OPRGyQClvyMBup3w5aFX5EOBKhFpxrLqLoZC5FkQkKEANNB6A2suyYFGvJt5hkKU/I5tUN+YOIs6rzrwl0m1O3h9jovI0KlsEM9QerHr5YoLNo1fjP9mPX+xgcZ2Dt9JX4SIXlAFP3V18MIMPEtl/f6L9geMzQUZKIQYANn+owdBhIkgmSpNQZnfbwQmEtCG7R2dFPjLUpuIMspQEM0Gp2Wsx1QxkWwWyxzcbaIq6EPraf4V 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) Reviewed-by: David Hildenbrand --- mm/vmalloc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 97156eab6fe581..5b432508319a4f 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)); - vm_remove_mappings(area, deallocate_pages); if (deallocate_pages) {