From patchwork Thu Jan 19 10:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107648 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 85F5DC004D4 for ; Thu, 19 Jan 2023 10:02:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17EFC6B0074; Thu, 19 Jan 2023 05:02:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 130836B0078; Thu, 19 Jan 2023 05:02:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01DAA6B007B; Thu, 19 Jan 2023 05:02:41 -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 E96566B0074 for ; Thu, 19 Jan 2023 05:02:41 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B323F140CCD for ; Thu, 19 Jan 2023 10:02:41 +0000 (UTC) X-FDA: 80371109322.06.DB9EC0C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id 2444140016 for ; Thu, 19 Jan 2023 10:02:39 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=cHu2DsLK; dmarc=none; spf=none (imf04.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674122560; 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=QK+F13Jz0ZfHS1BGxHd277aqAwbql//Xt13P525IYcU=; b=0RS08BYcMHoVqbSwaWkKnNTtAUDbYGfPxeNu+y0zRuX937V7SiTj49UjjO1YFVgGZmGPfj JbA+vsYkD+SIvaOS5gZfsVbiPyL2SBOX0HGm7bTHB8X+MutqS4s6l+6IAONvAespoImW87 Q5GgONzolsXEBsEvWcJNBsnoe0DFUOg= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=cHu2DsLK; dmarc=none; spf=none (imf04.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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674122560; a=rsa-sha256; cv=none; b=A369wvBqPE3/xre3uCF76x5fXI5OT/Tlh1Ehu+prnJNAzKkcnEhxlglOrYAxcL3QgiQqtg gLOdI1g0mTKiZUk+01IkP8NvCl/3g09WLwJboVcGQcz+Bo4IPxbVUhQvOpId1yck87zqzJ Ysj3wVLYLGwfQz9NYd7vMF7jexE7WJ4= 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=QK+F13Jz0ZfHS1BGxHd277aqAwbql//Xt13P525IYcU=; b=cHu2DsLK5r+czKvoPPihZH+pwk ycSoqlnJlzu1B8RFcXOYfnq7ieAxyQU2ExI58cv4GhBFSpiJHJEdWZsqxxQ/f+z53/+18TGsierra 1aH5jZCvXfXECBs5sN8MImor2InNV1ljGLhfmSQVG1lmjHbfcHfRIRCHMcBkbQEyuMnM4J5AVssoJ WG8D/7Dl4He8nyFzMglwcEPKjSSLpvC+CrrlKlwqz2NaIvdwPDAyyE2GeMnsMkd10nw6vF8kFuzHO y1vhX3eS+2A088niNo1hgb/Cp6wgKes3zH5MdKr7SQlLKOrjI2lWxqz5sBPpkWcU1EZXt+d/ZCWc1 5iWGSljw==; 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 1pIRkj-004LWG-6v; Thu, 19 Jan 2023 10:02:38 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 01/10] vmalloc: reject vmap with VM_FLUSH_RESET_PERMS Date: Thu, 19 Jan 2023 11:02:17 +0100 Message-Id: <20230119100226.789506-2-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-Queue-Id: 2444140016 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 3maakfnthzsfu45hjetrrw94ih9q5eo5 X-HE-Tag: 1674122559-791992 X-HE-Meta: U2FsdGVkX19pnyMqCu09AKX4YPCCg9VHM4pHKRdLQZ6TRyenbv5QjPHVow3fC14N0kwtumgZOoHTCpmA/kYUbP5Zbd0uWpv7Gn94wgRBmOzK9SkzxHm2x6I0tyvkyUEFHcfg/cFXU7FGxVJHfg5zeLQ69RqRZ6dMegxqTSeAS33Wi7PDjYX4lxVAW5eijw5T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 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: VM_FLUSH_RESET_PERMS is just for use with vmalloc as it is tied to freeing the underlying pages. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 0781c5a8e0e73d..6957d15d526e46 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2883,6 +2883,9 @@ void *vmap(struct page **pages, unsigned int count, might_sleep(); + if (WARN_ON_ONCE(flags & VM_FLUSH_RESET_PERMS)) + return NULL; + /* * Your top guard is someone else's bottom guard. Not having a top * guard compromises someone else's mappings too. From patchwork Thu Jan 19 10:02:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107649 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 4AABEC004D4 for ; Thu, 19 Jan 2023 10:02:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB5146B0078; Thu, 19 Jan 2023 05:02:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3D676B007B; Thu, 19 Jan 2023 05:02:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2BF76B007D; Thu, 19 Jan 2023 05:02:47 -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 B7D146B0078 for ; Thu, 19 Jan 2023 05:02:47 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8C432140CAB for ; Thu, 19 Jan 2023 10:02:47 +0000 (UTC) X-FDA: 80371109574.29.C3F5E6F Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id 24669100013 for ; Thu, 19 Jan 2023 10:02:45 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="mLU4/4FN"; 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=1674122566; 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=/gC0OwkR0jaMw4/imRoa+Guq6kwX6Vfz518yrgqHDK8=; b=V1hBHpAE9j28W2el4+9tZbVpjY4w2yyrzfJ4EeF6o83mjFTPTG2XdXmwPCGyiFE3awwVYR nczJQPpaHYNmNuREr6Qe8icGPxTLQGW4wxQfglanRzOWH3xhtjPhXD9E2RusYt2dGTTHMU IdhQziISrJJ3uBiXQwOtitcxshcjyJ0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="mLU4/4FN"; 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=1674122566; a=rsa-sha256; cv=none; b=p4Zc9TfPtFjFbIZAFXZBR235CSVubfzX4Fz+m1h4R0ET1gGlgBNADUyZjLoRvr4F5RhvYU 3UJ/npRjoQkBYVeDbqhrqdSiY9P8DUPPt1U6JLkNX286e6LpyNmHZwCE5tWFW2HfNHhkyk Rr8cWIi8w4inzOPjnbvVxSemkraRF8A= 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=/gC0OwkR0jaMw4/imRoa+Guq6kwX6Vfz518yrgqHDK8=; b=mLU4/4FNnOluiMgeY94YjOwYrK DvgjdklKB/A8LjJvxw4R6pFxmcemZ2m8k+hNL+5hC0KYtTuwWoyQzqddyZD2Mz6xiw6ruejjwe1uQ M9BWERVlumI1SmBUBDwQ7YeYbPk3BZhfwV1yNdrTuC7opwDyLnUuhts9RNsjmUrnj9fVXiLn0QeEv dtjJbY83CxRfPwD+hYrcWwQa4ucc/U1gyba6TGLK8EnxqICNEbyf4DQqqL3JWej0vqE99tASyhJuF Ijo4TImzkQMbJQVC67LWj5fn1+ECTaLwa7jz6becjqCGcz04Ex+cD80+VUcJwF50Io1CEpCiutNkX kN9JXmKw==; 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 1pIRkn-004LXA-6G; Thu, 19 Jan 2023 10:02:41 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 02/10] mm: remove __vfree Date: Thu, 19 Jan 2023 11:02:18 +0100 Message-Id: <20230119100226.789506-3-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 24669100013 X-Stat-Signature: xq6ngzygnmj3wyihcdiq1zqjjcdejua6 X-HE-Tag: 1674122565-519959 X-HE-Meta: U2FsdGVkX1+8PIvE1VQQZoycrAd5hu1qKoI9YoKc3WDRfk/cpyp6yZ1YRY/meKQghojY5CeQy7aZMR7oCDZde2rADKCwthWnBW+ct2SVVKTOHlLUhoSr60rJC75MM8VJiG4SPyYuE2c61U7rJyR7weLm1CULm6CWBZphvqISyLHzBtgQSGobFHquC9X967TJ56Zf8q9NIjz2+/ROBIi/LGDu3yEXYzPdBM1qXTZ1QgkO35Vmc2CKpuZFVf3dIQr8lOUKhfp7GPmusQ9Nbg+Xzsf7NnF+vF7fi3e4A681uNv+MVp7vNjBa20khcBaJsHmnq2Uy3LoTY6WxtbpAnaf0rlBDXc2+ESUBBGJXSaVMeMtevl/6ODhVoSMYqPpDWj3X+GvLRqnoRaLwRnnF5g5LMnRDIrLhdEiE+sPt6QqUlvHjP00xSiI/c5NBfpqfJIYsJRPMHFnu2I92J+5AaqESkqs47NITquHt8oySwRF/ZjdPxLi95lZXuRJkKHbtrvAb9sKEhX5alhpCZx1g5t8ie32J5B6xjU2IMKmyUL+FfEZUmybhqwFCD3X2wCp+cOD+86uYiCxffUJLVbrzZYcpaga9peJ6yEO8xUf/mtEak6sRwHOWEGivP2CLTczdRk8WyhX4ce7sihkh/xTx8WgCT64CYMPoGX9OaHgq6IUnh3DK/rflY9b95iI8oo8mGshsjhPnSBpYKJ4yD+CbDYUMi51Jxyi4jIGNOmn4jc8MbQQrq7LXurwMbQzS7GTWNpum6X0v7Nn9LAktAwE0HOfExcCnsdSx4zf5YKf0x57QY/p1uGEcxfX7nL2c9zIyS7221Bw+0PINEJhXQqvGGFv2enSAWkLL+4z81QymCLlBXJlAKhYjCi/BjJaxjTL83fAXvTezYEeaAnaCgK1x39t8ODwZXSV9Kh7FONEaNL+qvW7Zgwil2zWn3utNad8Wk5j34cxMKMK1y+wMhPYqm8 BOiUkiNF QOsy6SwjaCQho6yvdSpkWepCqN/pX2hJYRrebxSwsrOfe1pMts7xO1nvZNri/guD/MwOgh90ado9E12xrHZgtffpeQcYgwB29hd6vMFvzSS5BvSRxeoOrLVtAGfKedHzDdDF9/jUKnHsKMUwDhHsFfRAIheY/9TimAc+KNToKDQUSN7nu+fJX0+wpDpclCzp9zypoB4jc6BhOfYzF5ApAcfQfA46tlEbDgAEzSAKFXGp5a3w= 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: __vfree is a subset of vfree that just skips a few checks, and which is only used by vfree and an error cleanup path. Fold __vfree into vfree and switch the only other caller to call vfree() instead. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 6957d15d526e46..b989828b45109a 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2801,14 +2801,6 @@ void vfree_atomic(const void *addr) __vfree_deferred(addr); } -static void __vfree(const void *addr) -{ - if (unlikely(in_interrupt())) - __vfree_deferred(addr); - else - __vunmap(addr, 1); -} - /** * vfree - Release memory allocated by vmalloc() * @addr: Memory base address @@ -2836,8 +2828,10 @@ void vfree(const void *addr) if (!addr) return; - - __vfree(addr); + if (unlikely(in_interrupt())) + __vfree_deferred(addr); + else + __vunmap(addr, 1); } EXPORT_SYMBOL(vfree); @@ -3104,7 +3098,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, /* * If not enough pages were obtained to accomplish an - * allocation request, free them via __vfree() if any. + * allocation request, free them via vfree() if any. */ if (area->nr_pages != nr_small_pages) { warn_alloc(gfp_mask, NULL, @@ -3144,7 +3138,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, return area->addr; fail: - __vfree(area->addr); + vfree(area->addr); return NULL; } From patchwork Thu Jan 19 10:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107650 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 D147AC00A5A for ; Thu, 19 Jan 2023 10:02:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AF386B007B; Thu, 19 Jan 2023 05:02:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 638326B007D; Thu, 19 Jan 2023 05:02:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B2516B007E; Thu, 19 Jan 2023 05:02:52 -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 38FCD6B007B for ; Thu, 19 Jan 2023 05:02:52 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0ED16A0D73 for ; Thu, 19 Jan 2023 10:02:52 +0000 (UTC) X-FDA: 80371109784.09.6DEFF1C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 926E51C0009 for ; Thu, 19 Jan 2023 10:02:50 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qrRTjUaY; spf=none (imf20.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=1674122570; 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=+SWYz7hAitAY6tJURkuPWfGlLqC5qa9HeAAlAfkW1oo=; b=lT2m81tTFHSbBO7xggZu5zmOPat7wqiuaaPkh1aPx1EvFkfeJ2gP03OHXVdf9Dnljrv83f Fo0ykkYbgp2HVsdnK1scERRiu9n0GCdkXsCGrAgGIhRopLGyLuDdtXCjR/caYR7OzgJEJG 105S50tEIWpdl8kDp5u+4O2UkHKfnsE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qrRTjUaY; spf=none (imf20.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=1674122570; a=rsa-sha256; cv=none; b=tmivWtb5f1mYE7Yc5l8HxvWJYxwAcBOGsGlNoCxCcAtcqSlUVefrGqUoZ7UIzMvd/x94Z4 O4j3gnxJ/aow90uXompJ8jZ/c+pYzglPEVHpzpw1CMlOMSWbAAt0GG6TI5xsJGqbeB1q3k NUghJB5PH90NdPl1U7eu6InpKgb2+dQ= 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=+SWYz7hAitAY6tJURkuPWfGlLqC5qa9HeAAlAfkW1oo=; b=qrRTjUaYDJOmCjxy17FgDxWEgP 51+uM6Mfsapjtd/4ihiC3ANS3F7VKD9IWwZD6YcZVSjtxyiJI1j6utKXNPwtOG8PBim/BgmnfH90c oF7qPE/82eVpRek2eqn465b1yHMKUyCNvRFw+g1qFNmp6rrOh7MFHXomaUGrtIZCRSGgus1iLoQ+2 DyLp5CR10NKDD9p5TgM9fxwF2DMQBqFpWrtijghD0zLSKBXqaTzYouGA+SxOe/BZ9g2GSQImNnM1H LbWLum71fNWkQFfGV/9NGNjtFN2N7/vhW8Go0d8wo//8KS8w0kLwdD/ufq8XP5uP82xbG4N1NhKVe PcN8FAeA==; 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 1pIRkr-004LY0-Um; Thu, 19 Jan 2023 10:02:48 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 03/10] mm: remove __vfree_deferred Date: Thu, 19 Jan 2023 11:02:19 +0100 Message-Id: <20230119100226.789506-4-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 926E51C0009 X-Stat-Signature: b5hqmtwhs4739pkf7d8y7y5xejm5zf1g X-HE-Tag: 1674122570-671675 X-HE-Meta: U2FsdGVkX18Ne5uCUfzy5mkDZ171JjsJTb/S/wJZ0XQQ9DLy5IYi1s0U4ZpOmVpDLPyUT0zwQsEy2c7/X2xI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UiYDaAdoSGhDeQTAULqcfF2bK2MMOiPka13QIaUH9DQ6K3pBltYDqC3l8UfD3cBF0Mqn8HYqO8D9W5P29XHc= 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: Fold __vfree_deferred into vfree_atomic, and call vfree_atomic early on from vfree if called from interrupt context so that the extra low-level helper can be avoided. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index b989828b45109a..fafb6227f4428f 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2769,20 +2769,6 @@ static void __vunmap(const void *addr, int deallocate_pages) kfree(area); } -static inline void __vfree_deferred(const void *addr) -{ - /* - * Use raw_cpu_ptr() because this can be called from preemptible - * context. Preemption is absolutely fine here, because the llist_add() - * implementation is lockless, so it works even if we are adding to - * another cpu's list. schedule_work() should be fine with this too. - */ - struct vfree_deferred *p = raw_cpu_ptr(&vfree_deferred); - - if (llist_add((struct llist_node *)addr, &p->list)) - schedule_work(&p->wq); -} - /** * vfree_atomic - release memory allocated by vmalloc() * @addr: memory base address @@ -2792,13 +2778,19 @@ static inline void __vfree_deferred(const void *addr) */ void vfree_atomic(const void *addr) { - BUG_ON(in_nmi()); + struct vfree_deferred *p = raw_cpu_ptr(&vfree_deferred); + BUG_ON(in_nmi()); kmemleak_free(addr); - if (!addr) - return; - __vfree_deferred(addr); + /* + * Use raw_cpu_ptr() because this can be called from preemptible + * context. Preemption is absolutely fine here, because the llist_add() + * implementation is lockless, so it works even if we are adding to + * another cpu's list. schedule_work() should be fine with this too. + */ + if (addr && llist_add((struct llist_node *)addr, &p->list)) + schedule_work(&p->wq); } /** @@ -2820,17 +2812,16 @@ void vfree_atomic(const void *addr) */ void vfree(const void *addr) { - BUG_ON(in_nmi()); + if (unlikely(in_interrupt())) { + vfree_atomic(addr); + return; + } + BUG_ON(in_nmi()); kmemleak_free(addr); + might_sleep(); - might_sleep_if(!in_interrupt()); - - if (!addr) - return; - if (unlikely(in_interrupt())) - __vfree_deferred(addr); - else + if (addr) __vunmap(addr, 1); } EXPORT_SYMBOL(vfree); From patchwork Thu Jan 19 10:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107651 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 C8F4EC38142 for ; Thu, 19 Jan 2023 10:02:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63A4B6B007D; Thu, 19 Jan 2023 05:02:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59C136B007E; Thu, 19 Jan 2023 05:02:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43CCD6B0080; Thu, 19 Jan 2023 05:02:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2C9126B007D for ; Thu, 19 Jan 2023 05:02:59 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EF95D80948 for ; Thu, 19 Jan 2023 10:02:58 +0000 (UTC) X-FDA: 80371110036.01.CBB7A8B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id E3681180018 for ; Thu, 19 Jan 2023 10:02:56 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Q3Mzg9Ex; spf=none (imf24.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=1674122577; 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=FD2JG+d6yA1abtYvFdChjy0cPOnrDbMf2ONV7gibGRw=; b=hTDU5vz/t+ltWZeWgz+Seoy0j1dm8TLDEe4+veMBhvG16CpkUom7vIF79lwXr68XQ1lJ2A WFxndijBN+1L2qJcP7SAip2FxdBHmXuHSQfEta1HPnIfbyLTzgs5vxSJvCDCHscIko3WzI Xq9nSCVr/k52A7X1krLTZUbMAiCqoO0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Q3Mzg9Ex; spf=none (imf24.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=1674122577; a=rsa-sha256; cv=none; b=F1B42rMkwoyh0qdQ0p3ua6RiLsbwwJx2IXqsgNTHqHbHu+IaBCFhAG56ziRKvvk2HgvTSE n0ykt+sNdHma+0C+izirlUhCQ9ms7FFb5EETfYtnNz1u0/ab1fWz4N7k+8IgseM/Sv7rTg crrjVQf9ocCrpk6ZcbpsmKIkPysPHP0= 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=FD2JG+d6yA1abtYvFdChjy0cPOnrDbMf2ONV7gibGRw=; b=Q3Mzg9ExOfQ9QIFTYVyn+Td4Mx b9PuPdiTdsjSkZt2rCoUKE2lEOxr1sf23v+d984Fpyeg62PW18/wLtwZ4bBsRvz2kxlOFkZXOvBlQ CDwRrLk2w1Dla3vHsHPWYwBsBkVmbozdHf7Ae+qbGq1tfXzySCrmr2TAKhw6YHkmfxDGrsKZrREKM ZfXlaGUW849DpkLqY1d850ORmqx3fzMya4S5nHSyy1g6mriRi40whoGbKmEVhLTCnegA6kT8UobKQ t9QQ2ZHvpyKKNoEXqOhw18/h4nKpho8m9GVKdcwOabodZeZ33HuAjjIE4kS/VjSaPdeWkssUAe8tq JpUK0TSw==; 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 1pIRl0-004Lc0-6v; Thu, 19 Jan 2023 10:02:54 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 04/10] mm: move vmalloc_init and free_work down in vmalloc.c Date: Thu, 19 Jan 2023 11:02:20 +0100 Message-Id: <20230119100226.789506-5-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: E3681180018 X-Rspam-User: X-Stat-Signature: cnx6ysgrfm5qob9rgby4mdmd76tat9hu X-HE-Tag: 1674122576-468820 X-HE-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fvbBMz5zAzxxtv7I9cuCHek2XMnmOis6mMB0DvFszQrFTr3Iqth+H5K/24GAqYoTwjWapHOnFtELr1cQxZwk0iw0jloYMdfYJwZJDGgHqQC7uIgWKPbCWH76GwX+KQ/xaOhYXOdYE6yLhXuh7brdh4d63ASFK8= 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: Move these two functions around a bit to avoid forward declarations. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 105 +++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index fafb6227f4428f..daeb28b54663d5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -89,17 +89,6 @@ struct vfree_deferred { }; static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred); -static void __vunmap(const void *, int); - -static void free_work(struct work_struct *w) -{ - struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq); - struct llist_node *t, *llnode; - - llist_for_each_safe(llnode, t, llist_del_all(&p->list)) - __vunmap((void *)llnode, 1); -} - /*** Page table manipulation functions ***/ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot, @@ -2449,48 +2438,6 @@ static void vmap_init_free_space(void) } } -void __init vmalloc_init(void) -{ - struct vmap_area *va; - struct vm_struct *tmp; - int i; - - /* - * Create the cache for vmap_area objects. - */ - vmap_area_cachep = KMEM_CACHE(vmap_area, SLAB_PANIC); - - for_each_possible_cpu(i) { - struct vmap_block_queue *vbq; - struct vfree_deferred *p; - - vbq = &per_cpu(vmap_block_queue, i); - spin_lock_init(&vbq->lock); - INIT_LIST_HEAD(&vbq->free); - p = &per_cpu(vfree_deferred, i); - init_llist_head(&p->list); - INIT_WORK(&p->wq, free_work); - } - - /* Import existing vmlist entries. */ - for (tmp = vmlist; tmp; tmp = tmp->next) { - va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT); - if (WARN_ON_ONCE(!va)) - continue; - - va->va_start = (unsigned long)tmp->addr; - va->va_end = va->va_start + tmp->size; - va->vm = tmp; - insert_vmap_area(va, &vmap_area_root, &vmap_area_list); - } - - /* - * Now we can initialize a free vmap space. - */ - vmap_init_free_space(); - vmap_initialized = true; -} - static inline void setup_vmalloc_vm_locked(struct vm_struct *vm, struct vmap_area *va, unsigned long flags, const void *caller) { @@ -2769,6 +2716,15 @@ static void __vunmap(const void *addr, int deallocate_pages) kfree(area); } +static void delayed_vfree_work(struct work_struct *w) +{ + struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq); + struct llist_node *t, *llnode; + + llist_for_each_safe(llnode, t, llist_del_all(&p->list)) + __vunmap((void *)llnode, 1); +} + /** * vfree_atomic - release memory allocated by vmalloc() * @addr: memory base address @@ -4315,3 +4271,46 @@ static int __init proc_vmalloc_init(void) module_init(proc_vmalloc_init); #endif + +void __init vmalloc_init(void) +{ + struct vmap_area *va; + struct vm_struct *tmp; + int i; + + /* + * Create the cache for vmap_area objects. + */ + vmap_area_cachep = KMEM_CACHE(vmap_area, SLAB_PANIC); + + for_each_possible_cpu(i) { + struct vmap_block_queue *vbq; + struct vfree_deferred *p; + + vbq = &per_cpu(vmap_block_queue, i); + spin_lock_init(&vbq->lock); + INIT_LIST_HEAD(&vbq->free); + p = &per_cpu(vfree_deferred, i); + init_llist_head(&p->list); + INIT_WORK(&p->wq, delayed_vfree_work); + } + + /* Import existing vmlist entries. */ + for (tmp = vmlist; tmp; tmp = tmp->next) { + va = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT); + if (WARN_ON_ONCE(!va)) + continue; + + va->va_start = (unsigned long)tmp->addr; + va->va_end = va->va_start + tmp->size; + va->vm = tmp; + insert_vmap_area(va, &vmap_area_root, &vmap_area_list); + } + + /* + * Now we can initialize a free vmap space. + */ + vmap_init_free_space(); + vmap_initialized = true; +} + From patchwork Thu Jan 19 10:02:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107653 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 635A1C004D4 for ; Thu, 19 Jan 2023 10:06:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E01856B0081; Thu, 19 Jan 2023 05:06:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB0626B0082; Thu, 19 Jan 2023 05:06:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C788D6B0083; Thu, 19 Jan 2023 05:06:27 -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 B6D706B0081 for ; Thu, 19 Jan 2023 05:06:27 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9A2E9C0CFE for ; Thu, 19 Jan 2023 10:06:27 +0000 (UTC) X-FDA: 80371118814.23.1B9D4DF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 166E5180010 for ; Thu, 19 Jan 2023 10:06:25 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=rEgNupxq; spf=none (imf24.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=1674122786; a=rsa-sha256; cv=none; b=CiCLnpRgHLwYv4Vv5NT+GtckAFTlwlIvGz7be8JxmxTYvOkZ7SS5X5AaZYPQ3yYB1Pa4aL XZl5wZJJxQnw2ezhfnzGgJhktpjV1sxO8VMmJK6HRNWCUiWNRNPbdb8I6/TFqFmnruXrKJ rN0BlpJ/iLwTIPQZOVOBR8Jgrw65Bk8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=rEgNupxq; spf=none (imf24.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=1674122786; 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=4RmV19EAM+B2CDmR2ihG/lcFPqU+d4bBFKrZ9jZTpyo=; b=vruvhTVJzljOSzrqOaDLJFNmADxThIQdToII5XPl4UEmzWWRNx3JSmCIYVC53MyRKVhn9M qkxwe2xSR5/swHLsdaPXKezVW+OichJfsTMXNMosZlnomLi/IciPfC7Gp/szWQzBIXL0dQ w5XtXXqDXqzVdBCeRDcfLRdwJ0RIMu4= 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=4RmV19EAM+B2CDmR2ihG/lcFPqU+d4bBFKrZ9jZTpyo=; b=rEgNupxqCYWtsaiPmzcb93PGgc UVBG7t5c6mOcpdxHMVJB30NDMCarj6Frwf2vCCex2m0H/z6EU2SiyL4dI3EvnXsLQapNPYKVND5UI DS6rHirbyD5irWqapPkFUN90mq/wbAl1B7ZxLZb01XsyAL5t9l575G5J3wzrQ/53fUDvCD5Fho1cp NLvKcnegXZOmybSwa2c3FSdzyytKFfcGF9fcXCwCSXKVKPFP85CPF/FuhIM2E00erhg90KEX3fMFs dKllPZM4OgMxZPqRYcNrT53JSib/qAi/rLvLY2uS0xd8A0/a2rTZ5+U4NaGm1YS+Du6cHrd9WWZUs zhQN0YAQ==; 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 1pIRoN-004Lco-Hl; Thu, 19 Jan 2023 10:06:24 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 05/10] mm: call vfree instead of __vunmap from delayed_vfree_work Date: Thu, 19 Jan 2023 11:02:21 +0100 Message-Id: <20230119100226.789506-6-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-Rspam-User: X-Rspamd-Queue-Id: 166E5180010 X-Rspamd-Server: rspam01 X-Stat-Signature: m6c8ycsep1iy3fyd5q8kni6jtzp1867y X-HE-Tag: 1674122785-348144 X-HE-Meta: U2FsdGVkX1+Q05Fch4U2ktSvJa/nbcMvf2KsvAIDcmZJWHtqxPoRt957OMSfU6PD6Y92yMAZSnJAoqmjVguE1jKbawII/PHPPiWOLGe/qKOSwuglmO6NswCe1CoYVYPxorPZ4zoKkK1+WVYgmXOHWuVpU0hamuj7SVX3R8VvvE9H0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=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This adds an extra, never taken, in_interrupt() branch, but will allow to cut down the maze of vfree helpers. Reviewed-by: Christoph Hellwig Reviewed-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 daeb28b54663d5..3c07520b8b821b 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2722,7 +2722,7 @@ static void delayed_vfree_work(struct work_struct *w) struct llist_node *t, *llnode; llist_for_each_safe(llnode, t, llist_del_all(&p->list)) - __vunmap((void *)llnode, 1); + vfree(llnode); } /** From patchwork Thu Jan 19 10:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107654 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 755CEC00A5A for ; Thu, 19 Jan 2023 10:06:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12F876B0082; Thu, 19 Jan 2023 05:06:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E0098E0001; Thu, 19 Jan 2023 05:06:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE9D06B0085; Thu, 19 Jan 2023 05:06:30 -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 E12396B0082 for ; Thu, 19 Jan 2023 05:06:30 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C25FAC0CFE for ; Thu, 19 Jan 2023 10:06:30 +0000 (UTC) X-FDA: 80371118940.01.45A36ED Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP id 5266D1C000B for ; Thu, 19 Jan 2023 10:06:29 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=kV37HWuz; spf=none (imf21.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=1674122789; 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=j7jaCYzdOgDTuecb3mgn/VwQXE5kJbITGLcmpq6VV5U=; b=dL71aAOG9wpZnA4cBHSnbOJHOREfapIdUMMgdJqWjHGf0QWZSKkmtC7xb2GWyZELDHbBFE OYQS3+fCZ2a2Wux9B5OmJTjFu5qiYTo8Y3DwFwl+rUL5e6v+bOeDhjMJfAQ7n0Np2JdhiO OwRt6GvpSt82cuXW4rDS0IHGngYeW20= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=kV37HWuz; spf=none (imf21.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=1674122789; a=rsa-sha256; cv=none; b=e6cZXOVYVTVNFJboDGLDYa2iyW681RGCqEFQ6hfb18XNa8hUKWdM26x6F+Nn+GqDh2rtZI Ynkw3GhkN3d0I0QQxSokmuD5s2NOzP5c9Ai0VocY3qK+xw//C9K0LF0qtLB8AxGIYiJfnh G9gNypVer5IKkDYb0dX6BWqrYhS4e5w= 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=j7jaCYzdOgDTuecb3mgn/VwQXE5kJbITGLcmpq6VV5U=; b=kV37HWuz8zMbPV1zmRBCT+qf6i VB0BjClP5+YX6nJoqfQXvZqjh9yOsqum+Yp/xFaZ21QTRiTMEsixAkdqwvThvFCWds3ndXXCZOJfC Xn9Wn87TKyusqTphHw8K60tqN0P/SCfl8PWrkMc7HF5zB2HwvqJU8WRXamMz233DBXGMrFAuYDWe1 fWnNtBRl0CxLWTi18sqEvwUsQd5UjR5B9Kgk6SM2DwHDhlDPh3e1LL6dhoYnhMiXpd+wZ7JNGJISN BGOEQNuq/51hqjUP2B7V1NPcqCaMqllR7ryrW0JWugUQxYZyHKd4tG/qcAhXqLHm/3DqALkWy3C2+ dBbUwtSQ==; 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 1pIRoQ-004N5c-VA; Thu, 19 Jan 2023 10:06:27 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 06/10] mm: move __remove_vm_area out of va_remove_mappings Date: Thu, 19 Jan 2023 11:02:22 +0100 Message-Id: <20230119100226.789506-7-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5266D1C000B X-Stat-Signature: j933ru7edycgy5hmi16w53yfhwky1s9y X-HE-Tag: 1674122789-868585 X-HE-Meta: U2FsdGVkX1+6cgOxXyxEZefPtNuAKNeznQKAv6CLeOM3NZv1SDdKmhKMweJw0cosIwZ84Diaa4kQuvZFY6+hON+80r0ER4yY6U1Bt3c1SPAq1JNAkz66h41sKd8a3Gc9PwfY91+jL6oSZ7JCFEyo7WI6LIgr4e7uWl2bD7pGkD5x+DUp95ccDM1HsauFtbq/FqQxq3FSVtTIud2Zs3CkOR7iX67DqaRHJmj0d3RW3O0EhPPumW26t1IRGZw7a2HMj+G8BiMRH3AA1e+zIY4GLX92soUARv8DAqIn/lvrfV1vPSwYSauaxQItUNMWixQ4FYdNUjisEdMCemL+53wSg3WE391mg7ZRBpOTXIG2CkLXFFBmizc5IzHh7lC3jV6wXMUg3dJHyTk0tw4R5DEV4yPgZtMNw7e0teXt8DdYMsYB1WD8Rtt0mFYd1620TLTZuWfzdwg6pmkA4KSjtajE12b2oI2eaXkOIukpdRz3nkDlCNCToMHPpS6pSyiNtWjwUVcrCPc3SH0+KoTJWw9hqQHwcUuE5MkKyt2u5x9SUNY6UcjbqdEIhTLeUJ73e7LoBCt1J9lLTNJPR0pP4+/1C8Nj5nBI9RtoXp82e3i7da4OfnSHRpbH+0DKGDfLAGaddgAJ9hWZ9N0BUQGuH2gkPfJ0oRYKzxd4gYp1gZ611InfpgiLdLiAj1ic8B9tqj6SAAsHcv2K9oSZJp8Tn73AuCpDkvONQZv37UEhubHB9vrBbB0g2Lx8ErCss4UHn2NisJfO1MOqMfLJl6HxyFVazz0K7R79cObVjs4LeJm7d2qL/DI39SC8q20KgA9AZ6uREkUkwwcUB7XijSS8tgZ6E97CAaYaDwL5XZ/8KjfihlIhI1Yt+ejqwUx8b5/8CHwLRge4k36CXz6xnYIPQMBh4neZOKzmS/Vp7I7bEAhcnri9i1rchpQQLc4XKYmOSGSKmTzqR+s6Q/dE0kydiKW hsqiI7X7 jXGGm3yb6JZbEFRLAnFdne0AWJO2zYvomSfZUi8DwaZngW0/5mVs5arLA0cbPzLapk6jdeN91J4BEG4lehwd6Or83ucZB0a9Rjfei+sqaOqA/8q5sS/3zgjvbXMIbSOA3Vawjb8JluRTt1AqykXpydmNZgD+WWW8Ib/PXuotlZLb1fC/AJQTFGyqPa/8FssjypNqTBppslU2OxrBNV9jyK9LRSayFmfCAxVWQvHRmjRd7vOE= 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: __remove_vm_area is the only part of va_remove_mappings that requires a vmap_area. Move the call out to the caller and only pass the vm_struct to va_remove_mappings. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 3c07520b8b821b..09c6fcfdaeb7c9 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2614,18 +2614,15 @@ 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 VA's vm_struct. */ -static void va_remove_mappings(struct vmap_area *va, int deallocate_pages) +/* Handle removing and resetting vm mappings related to the vm_struct. */ +static void va_remove_mappings(struct vm_struct *area, 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(va); - /* If this is not VM_FLUSH_RESET_PERMS memory, no need for the below. */ if (!flush_reset) return; @@ -2691,7 +2688,8 @@ static void __vunmap(const void *addr, int deallocate_pages) kasan_poison_vmalloc(area->addr, get_vm_area_size(area)); - va_remove_mappings(va, deallocate_pages); + __remove_vm_area(va); + va_remove_mappings(area, deallocate_pages); if (deallocate_pages) { int i; 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+k9O3VIjxtD9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UV3OKIboJXr1HRf4XQGPoDfvhVRXBiNsjIwErtQ9SS8wHOSJKp954xhaE9dPwEqGiVvx53oPbsi6aKRdZzU= 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) --- 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) { 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/6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OifyRcsBDgLohNoPJBBgF7+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) { From patchwork Thu Jan 19 10:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107657 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 1BA70C004D4 for ; Thu, 19 Jan 2023 10:06:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA4828E0003; Thu, 19 Jan 2023 05:06:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A551C8E0002; Thu, 19 Jan 2023 05:06:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91CF58E0003; Thu, 19 Jan 2023 05:06:44 -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 849388E0002 for ; Thu, 19 Jan 2023 05:06:44 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 57DAE160D1A for ; Thu, 19 Jan 2023 10:06:44 +0000 (UTC) X-FDA: 80371119528.04.881A679 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id E2375C0012 for ; Thu, 19 Jan 2023 10:06:42 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Dbnq8ckF; spf=none (imf10.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=1674122802; 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=iyd8tqGiY9j8oDNLq7gNrgqmUQgcTuGZnKBX+j0mJu4=; b=4bOblmdcY04g1ScCb4BoWAGbvuOZPVDTuEuYZiyQ3zQYT4e16vXmbClF0THcQ8ZtkO0qCb 0uCdW9RTJhRd6rMmKzavPh3ZRpJg8iB4vNqSFXj1ZBa3CmG33aLNm4IbvGBvRouofplqz8 AHIH75/s+N7S5EB73xeVvQ1ty/j148M= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Dbnq8ckF; spf=none (imf10.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=1674122803; a=rsa-sha256; cv=none; b=0PLsM+aDcUoR4L3mFWNzIGoMlj+859t8tsTdqUwf0LA27XgZ7ozaRFkTACLFlVk82unI8Q RixJVK185f0yr+iLaFket53tTCHvIcTtDrTRwEHZE0QvXBzGl08vfSHCIXf9Ixofae7IRv 2Cwh0pUERth/+23YU7pU7BeXx471fUY= 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=iyd8tqGiY9j8oDNLq7gNrgqmUQgcTuGZnKBX+j0mJu4=; b=Dbnq8ckFqYSFSkdw/O55JZYdU+ u+dJyDawMnfEO+4NsxlWT7hRoFL8OMJYd6SmxDFF/TukEDZ8sHRtuMPS8BC3tGpesWKEss9honOEv AzfpUcfkZuKlMIX0rTducW5OFmR1ynNht/U2gRNRHclYc1s5eW3y6toEXvpuPuhUnLl+iOizKKOb+ Ep+EbN1ZePYQKAcbbD5dJpfZOfi6YKuqmsCaSxrIQyUXEM0Lk1uMGJWRbofXG5pNlCnSJ1q1Hkply RyRqZmY22UA7KjaJLW5lSagZAKOAlUwt3u0NnjXoXW5YE3J1DkOAIVWmAHo3mpyhC2Q3YnblQF3+t 83Z//cAA==; 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 1pIRoe-004NB5-9M; Thu, 19 Jan 2023 10:06:41 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 09/10] mm: split __vunmap Date: Thu, 19 Jan 2023 11:02:25 +0100 Message-Id: <20230119100226.789506-10-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-Queue-Id: E2375C0012 X-Stat-Signature: rgj69wx4kocmoniwu9g4runstp395kx3 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674122802-972736 X-HE-Meta: U2FsdGVkX19IoJOYt8PwrLK9SbVn4bG2iNTKqNb2hZ5DwW4XqwbkLH4Tl6OfxdCapUxReudwEyatmYnGkF18OpGlNktnGT3WWbl2rLpb5K2+R1qyjxKDwAjS2bMnE3t+TWU4VrwAbFWJ3FEEuzxW1CesCqwx6/TlZ7wv6LBNgm9y9zX+oDO7Upwwx5UqbQj6aXjvNSdpSSOLuUUpBxjO/rJV8iHK+FggTlT05rjF35zCn6L7iER/r7xlrqdiN9XDD9ctXpsjb7a/gBG4/lawfXV0maKbJx2vjOfh9tmqkrnCYs1uPTGkYffyFFdyQka2cwu181RQL2ZcS1WcwsIMpg/fcPSKcPhwDl+lqWFP4yrZQN/V9nkGyqtlMLQ6S4AX6QxsNMvRZTFSuqBlyYZke/bPbacOH6k5KsH+IWwPlNDe2L1XNQL8A1e2wT1fyrOCmOMGJs/6TNPcE7aoCvvhVMNhmXjHbh+2Q9dc17xE8eYfCnM1Wt3n80sl/LmNmKwr5Opmu6+k8n0z+cx3EcJTyh5E+xRd7peIGirizFeDk60MCmUmzkjouXBA7A7PGN83SftOEiXNgG9TduSrYahSBidZYJjkr2VsJlX58vq+EFIlZcsaWmrMYWlkukOUrZZyhg6v9vWOxacBO3F7xZC93iyjw4JbeQ7XJzAl3MNs8Iy7i8v0RNdwmqTOmuSH/vexQXP+n8uR0/w101Ncz7PhW8PPAa8gCee7qEuWP3oBjxuPZiTuSWwtg93a4nqPZNzCg4lSMQLNExkQ8X3C9fMV9xQsdMd69bpJlyloL2iNUfSIdVePlcbe1OOelQpMe4D2dR/Lo+yXLcZbxfThUccdaVORXe//dGctcTUYOrATQ9+LRDvv3HhBqUDiSACgfpB0VAnNgQKu73Mm4XzlqXZIM3vRnQCjuj3EKARstYdp2OAz1erBfibEMVuCPU5oxRDlACSvjjtMQYg3MZpE5lc gvHxHhNs bVCQLPk69Xm3pMBZBcSEaBXl9NegMCdH9EZbwbRdaGYH+vZ4jpRyiT1T8vFUp5oOY1X6KPxpUEZ0MDV31UhehjfoqpuZrueFboMehhK17iAqSE3jkl6gVSmFuFNmNljpUEBqLRj3QNDFXqgjSZWfO2EZCz8gcJXrsnzscXIDsFnIKMS5/7E5vExx3KzgWq6g1uwMZBsl20ZtH3Z0PQywNTs4tCp8BHm4Zc7YE 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: vunmap only needs to find and free the vmap_area and vm_strut, so open code that there and merge the rest of the code into vfree. Signed-off-by: Christoph Hellwig --- mm/vmalloc.c | 85 ++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 4cb189bdd51499..791d906d7e407c 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2666,45 +2666,6 @@ static void va_remove_mappings(struct vm_struct *area, int deallocate_pages) set_area_direct_map(area, set_direct_map_default_noflush); } -static void __vunmap(const void *addr, int deallocate_pages) -{ - struct vm_struct *area; - - if (!addr) - return; - - area = remove_vm_area(addr); - if (unlikely(!area)) { - WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n", - addr); - return; - } - - va_remove_mappings(area, deallocate_pages); - - if (deallocate_pages) { - int i; - - for (i = 0; i < area->nr_pages; i++) { - struct page *page = area->pages[i]; - - BUG_ON(!page); - mod_memcg_page_state(page, MEMCG_VMALLOC, -1); - /* - * High-order allocs for huge vmallocs are split, so - * can be freed as an array of order-0 allocations - */ - __free_pages(page, 0); - cond_resched(); - } - atomic_long_sub(area->nr_pages, &nr_vmalloc_pages); - - kvfree(area->pages); - } - - kfree(area); -} - static void delayed_vfree_work(struct work_struct *w) { struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq); @@ -2757,6 +2718,9 @@ void vfree_atomic(const void *addr) */ void vfree(const void *addr) { + struct vm_struct *vm; + int i; + if (unlikely(in_interrupt())) { vfree_atomic(addr); return; @@ -2766,8 +2730,32 @@ void vfree(const void *addr) kmemleak_free(addr); might_sleep(); - if (addr) - __vunmap(addr, 1); + if (!addr) + return; + + vm = remove_vm_area(addr); + if (unlikely(!vm)) { + WARN(1, KERN_ERR "Trying to vfree() nonexistent vm area (%p)\n", + addr); + return; + } + + va_remove_mappings(vm, true); + for (i = 0; i < vm->nr_pages; i++) { + struct page *page = vm->pages[i]; + + BUG_ON(!page); + mod_memcg_page_state(page, MEMCG_VMALLOC, -1); + /* + * High-order allocs for huge vmallocs are split, so + * can be freed as an array of order-0 allocations + */ + __free_pages(page, 0); + cond_resched(); + } + atomic_long_sub(vm->nr_pages, &nr_vmalloc_pages); + kvfree(vm->pages); + kfree(vm); } EXPORT_SYMBOL(vfree); @@ -2782,10 +2770,21 @@ EXPORT_SYMBOL(vfree); */ void vunmap(const void *addr) { + struct vm_struct *vm; + BUG_ON(in_interrupt()); might_sleep(); - if (addr) - __vunmap(addr, 0); + + if (!addr) + return; + vm = remove_vm_area(addr); + if (unlikely(!vm)) { + WARN(1, KERN_ERR "Trying to vunmap() nonexistent vm area (%p)\n", + addr); + return; + } + WARN_ON_ONCE(vm->flags & VM_FLUSH_RESET_PERMS); + kfree(vm); } EXPORT_SYMBOL(vunmap); From patchwork Thu Jan 19 10:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107658 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 BE00AC00A5A for ; Thu, 19 Jan 2023 10:07:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 525CD6B0082; Thu, 19 Jan 2023 05:07:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D6528E0002; Thu, 19 Jan 2023 05:07:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39E7D6B0085; Thu, 19 Jan 2023 05:07:14 -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 273326B0082 for ; Thu, 19 Jan 2023 05:07:14 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 06E35140CBE for ; Thu, 19 Jan 2023 10:07:14 +0000 (UTC) X-FDA: 80371120788.11.A373031 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf25.hostedemail.com (Postfix) with ESMTP id 840FEA0012 for ; Thu, 19 Jan 2023 10:07:12 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fxi+I+rj; spf=none (imf25.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=1674122832; 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=N6RK7sD1bhTlPOZWkzdYEDixwksJjCe7JpWeHG+wfsg=; b=iQCi0jPAf8e1bXF0tsCDeecgrzV6mtlmDWsIgdD1xnRmh1G0G5oGDcZH9SR+XNEiY4MXrK AikLVjD6R1+koIiozKhQy7CvGQCzIGKl0kEW80/uxlEp8aYkgrUKwGS6A9qa0iY4hRCbFO kH/RuAwbkQnNl34jreaFgWSH1GozS08= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fxi+I+rj; spf=none (imf25.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=1674122832; a=rsa-sha256; cv=none; b=d/59aCzw3eKjOnQOPVVbPYKDqj4f9bnd26K7JjEPxd+BEBmrOvJSQ0CfGL8VzhwpHNAdLJ UDCWjHdULg9rP0SK70rK/FKHimwweq55MKxqAqY0OlNeV+BbqEQraMgRZgArYtA0TP4E9s 4OUual4VNyU9ue8hhs9J3FusfOigtPw= 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=N6RK7sD1bhTlPOZWkzdYEDixwksJjCe7JpWeHG+wfsg=; b=fxi+I+rjMIPm9aq1Lf4AGHLq0t zcf0gfRREWv1msyE/Kw3jABqEm7S00/+4aO+QkP0aRRPcMXXJ6ej4FzlPTPGxp+0U32pn/wuuQfBA wLErfPOzU7w4Q1qRMu8K8sROZBxPkUxUi3UGIzFiZCJZCRY3ebIUAbcnSqFsr0DvTp9rJg9Fd4Imb T/6UXMEr70/mFXGG8QoLZKubBvkuoX/z0GdyjvJnyyadQqNFpRrV/N3sZS6U/UId3dhK+NTbES7Xn 2ZzmZ0OpRZl/VSM3Lj18r5aeuaxtpRkzGO8grTBNdPyzv94+FkQO4E8pWG3UYvCRar3LTjKcCIkgQ XJgzOylA==; 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 1pIRp6-004NMP-OP; Thu, 19 Jan 2023 10:07:09 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 10/10] mm: refactor va_remove_mappings Date: Thu, 19 Jan 2023 11:02:26 +0100 Message-Id: <20230119100226.789506-11-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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 5wdztnan7j6a61r6thnzr7s49qp78r1q X-Rspamd-Queue-Id: 840FEA0012 X-HE-Tag: 1674122832-907066 X-HE-Meta: U2FsdGVkX18qcm1ou3V5PKHqMv3iThx1KMlECPKhh0mNts7yqDkabnu7vgrE1u7Ojj0Nr8D/K4KxR0gJP1AbHmBKQISFcUEOEQBBqmse9xvnmyuTgBqkF0F58GfMEaGgG4WpW/Sd8DmwmY0DVtsl0kJgczVy08IIUUdauCVYeoM6LrVBDSngJXCqzt4R/MQaAIGV+G7ekhEY65KhJGWWiidYmafJS1L7+xXEZAju+NtwbojkYG9GAGNF17WArzIyGL1FR074MAAK76dvT01FI0MH357sFYeoAEgtYXv99hpo3FCssafGgs1mufV5jk1Cm11rcchkRcKGeve7nG4GBS6oJxY0205W3cT5ldUSSKkVEbvXGbS7xFyc/Ap3McYjXoRPMdUUv9vmC90PMeDSAqaM0Agg9E7qy2fLiSNr8X3lXCCaBv+1/olONo/TIHo6UHxXtiZTXndI863mqRZbW9n/68AxMlNzcpe6dsaKLqfXJXTK4YLsnR8AIenlJBesQqB6DL4E03qEshv8puiOPr82aGjVMzrsGhPON3CvT5/7cjdHNxLw9Dt0KkJUc1/QvEw0jXKOXj5KFVutfReRLDbUiRjRMv5ONPQQ6TVrItPS6Xhma8V9LYMlXYeJDKvwhgBp6T4yj5YXXuN2vq/3OgIG5WH7NWyOwxqnFX3SzRd5IrNVE2Wa5jR3GBI4QXY7S6ONg3pHlvErdiXi8qdTWA8+5tPVj0eNYWkjRNEEc9l7VUHZLV1RBciYhkbtMMfS/dBtodTEvL7+DeTjZ6qd0QdumPDcspnA8dZqFZwuOHQAjl1K2ekGLQ+Ed6dl4UOjo6yyfSvUVdszomUHPFzpRgmkwx4O3Y6QyPm+bEqjK8PH8Xi2UvPDDmGOZDMgt14cxXeYUBUa9UeR8lIvZMo/1y4Y8a3oSsleiH0qh8ZpB73uguOKNdvLFNwTzflCWAdhLm8/Oah8OmCz9YAEibk 6x1gPRsO GV/kJfq2iMJX4TRt7GmJI4wnB2EnCU0mQwEAVMw92bwY18glPhv7BYGdWEcZRpvemqulNXDicNpy3nRu54MOEo4+N5KP7HGHtlvr6k8X24cOqjOxkFPhT5qeznEDpVvobNUvCwovQsv8CMj4I9yPG47A9o6wjubbIMK6iL0zMHP2q1dkLtTPhC4mus+Qfj1tw0NzutyYd7uYfOWyLIkX5zTlC5jTN+2Abqdl1AAyne/fRDpg= 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: Move the VM_FLUSH_RESET_PERMS to the caller and rename the function to better describe what it is doing. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 791d906d7e407c..f41be986b01e4e 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2617,35 +2617,23 @@ 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 va_remove_mappings(struct vm_struct *area, int deallocate_pages) +/* + * Flush the vm mapping and reset the direct map. + */ +static void vm_reset_perms(struct vm_struct *area) { 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; - /* If this is not VM_FLUSH_RESET_PERMS memory, no need for the below. */ - if (!flush_reset) - return; - - /* - * If not deallocating pages, just do the flush of the VM area and - * return. - */ - if (!deallocate_pages) { - vm_unmap_aliases(); - return; - } - /* - * If execution gets here, flush the vm mapping and reset the direct - * map. Find the start and end range of the direct mappings to make sure + * Find the start and end range of the direct mappings to make sure that * the vm_unmap_aliases() flush includes the direct map. */ for (i = 0; i < area->nr_pages; i += 1U << page_order) { unsigned long addr = (unsigned long)page_address(area->pages[i]); + if (addr) { unsigned long page_size; @@ -2740,7 +2728,8 @@ void vfree(const void *addr) return; } - va_remove_mappings(vm, true); + if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS)) + vm_reset_perms(vm); for (i = 0; i < vm->nr_pages; i++) { struct page *page = vm->pages[i];