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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A503C433FE for ; Wed, 22 Dec 2021 19:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345315AbhLVTsm (ORCPT ); Wed, 22 Dec 2021 14:48:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345307AbhLVTsk (ORCPT ); Wed, 22 Dec 2021 14:48:40 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4280C06173F for ; Wed, 22 Dec 2021 11:48:39 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id v7so6937936wrv.12 for ; Wed, 22 Dec 2021 11:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colorfullife-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=s0Np47Sa5pl9gnz8YRlCOL68fxuhegQ0UELp+V7hih0=; b=ShpxXURYszaRMGGR7Amw9aByeA2z9pmwguw8vJMrwma0p7JrEpZAR//BeulUjTnj4B D3Gv45fD6hNXeM3/mRdYiiBubdKW7j+wgRlIWLPf8R7hqqaUhWdTgxePlh4HoTJ32G2V ezxsX+SpUXz95b65NKPd3pqEt2CuZ2oBGk30meGymGMRMGxngkY7I9E/uvR+1jMxQtkD u+OS/gIG7X3qxv9zdGVx/hOSUR+/EB8nN01ntjA3CDwTZI/SQ0MgKd6zXX7XQ9MFzNGr G2U6eUr1iavHJofLSRrJ5ZmkNCcggBSQCKFQDZUhdNgQraXr0UtZ/TvbyTkEROBnYCYp ncmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=s0Np47Sa5pl9gnz8YRlCOL68fxuhegQ0UELp+V7hih0=; b=KAJjvL90/4m3JJNjmJb9zYKjOEAfgTEQeiG/IdEZ/Sx8aeqawyr8B6tW0chdFcbiQn n6OraKFwI45DUvNc0MNUJ5MUHJtmxE9YzENE6A0C07CuXk6H/FbSLRxdL64iUCdf7IpC sENuPuz/MA8tg7OEJ3dAnmER3JIi1hbQ8AWQJ6IP3RYBpa8Q6//fdzeGtj3zHqhaMXqQ FER7hSiDg/YQftG+2l0TpUT+vpF8FYz5gzP3hXV+gkZrE79UGmUPNht8Qx5BfRpiH0hY pbM6Nzbe2RsHdBpR9p2rGXfDnlp5GI4wFqQC5H24JDL1AqoASbObLfyiL7L/LM85jQaI oJrA== X-Gm-Message-State: AOAM530iQI6tLJfKN2U6iw5LxuN/MsvqC6eMuPap4S2v6mo0MKbHHcfS NMz61gAeOs217SnAdstWyTv0dDbQKneVevsF X-Google-Smtp-Source: ABdhPJwrNjuRSRbCuEDIvyvjT5LMfUxmfDcjFXxqtdFWy3mco/AY4P0vZNGjc6maPs4bae7pSiZfeg== X-Received: by 2002:a5d:4dca:: with SMTP id f10mr3113197wru.595.1640202518184; Wed, 22 Dec 2021 11:48:38 -0800 (PST) Received: from localhost.localdomain (p200300d9970878003dae64a47964a371.dip0.t-ipconnect.de. [2003:d9:9708:7800:3dae:64a4:7964:a371]) by smtp.googlemail.com with ESMTPSA id c7sm3273596wri.21.2021.12.22.11.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 11:48:37 -0800 (PST) From: Manfred Spraul To: LKML , Andrew Morton Cc: Vasily Averin , cgel.zte@gmail.com, shakeelb@google.com, rdunlap@infradead.org, dbueso@suse.de, unixbhaskar@gmail.com, chi.minghao@zte.com.cn, arnd@arndb.de, Zeal Robot , linux-mm@kvack.org, 1vier1@web.de, Manfred Spraul , stable@vger.kernel.org Subject: [PATCH] mm/util.c: Make kvfree() safe for calling while holding spinlocks Date: Wed, 22 Dec 2021 20:48:28 +0100 Message-Id: <20211222194828.15320-1-manfred@colorfullife.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One codepath in find_alloc_undo() calls kvfree() while holding a spinlock. Since vfree() can sleep this is a bug. Previously, the code path used kfree(), and kfree() is safe to be called while holding a spinlock. Minghao proposed to fix this by updating find_alloc_undo(). Alternate proposal to fix this: Instead of changing find_alloc_undo(), change kvfree() so that the same rules as for kfree() apply: Having different rules for kfree() and kvfree() just asks for bugs. Disadvantage: Releasing vmalloc'ed memory will be delayed a bit. Reported-by: Zeal Robot Reported-by: Minghao Chi Link: https://lore.kernel.org/all/20211222081026.484058-1-chi.minghao@zte.com.cn/ Fixes: fc37a3b8b438 ("[PATCH] ipc sem: use kvmalloc for sem_undo allocation") Cc: stable@vger.kernel.org Signed-off-by: Manfred Spraul --- mm/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/util.c b/mm/util.c index 741ba32a43ac..7f9181998835 100644 --- a/mm/util.c +++ b/mm/util.c @@ -610,12 +610,12 @@ EXPORT_SYMBOL(kvmalloc_node); * It is slightly more efficient to use kfree() or vfree() if you are certain * that you know which one to use. * - * Context: Either preemptible task context or not-NMI interrupt. + * Context: Any context except NMI interrupt. */ void kvfree(const void *addr) { if (is_vmalloc_addr(addr)) - vfree(addr); + vfree_atomic(addr); else kfree(addr); } -- 2.33.1