From patchwork Thu Jul 25 12:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13741898 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 3434AC3DA49 for ; Thu, 25 Jul 2024 12:55:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 686336B0093; Thu, 25 Jul 2024 08:55:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6358D6B0095; Thu, 25 Jul 2024 08:55:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 524716B0096; Thu, 25 Jul 2024 08:55:17 -0400 (EDT) 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 355C96B0093 for ; Thu, 25 Jul 2024 08:55:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C241B1210BA for ; Thu, 25 Jul 2024 12:55:16 +0000 (UTC) X-FDA: 82378270632.12.2FD318C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 3286D4000A for ; Thu, 25 Jul 2024 12:55:14 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YsTpK7T9; spf=pass (imf11.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721912066; 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:references:dkim-signature; bh=x/F5BHpep6qJ5VbKPG8N1K74yeQzBdMXuKRFeX9TShI=; b=S5NGYfSbSIClsQkKVbMC4fYQXZqc9XmjS647m3PbtZBFvuOa+H/4dX8vCNe17Qd1m9HSuo f3QLBjSc+B/mac0d7FnORAMnD1QxRrHKHIN62nIgQXLuuSJncd6mKaR2U7fV4iUW3HWe/V 8/WD1RwncacnJTe1U0tM2yQlca92EyQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721912066; a=rsa-sha256; cv=none; b=sEiDo522UxCn9Y6DShftToBDGT+RlAEQy9spcbRC5UIxeqWgYp3iPjmba0dxsZ5pcVMKlo 1ZSJIJR2lC1OhLW6+RSTgvmkI/k0f+UHsoiojuXS7srF6tQ+RK7Y/OPoGYoPqjcUBwYasW 3r8Ij1a5wJh4ULqWJ3RGuUaJpm/37EA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YsTpK7T9; spf=pass (imf11.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 44189612F4; Thu, 25 Jul 2024 12:55:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74C68C116B1; Thu, 25 Jul 2024 12:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721912113; bh=cICetE0oPku5oCZLNjMdluepkJysG2PwPkTft1lrcKc=; h=From:To:Cc:Subject:Date:From; b=YsTpK7T92PASjft75fgiCu9RC/lk0nEItX2TxjrgHlkHQJxVwWOxJmKPF9SAEI12k ydpkFs1QZpjqdah5kaDbSa7uZJEAPiHw0cTyFuyxqtVb+i0JdZzAf9QRYN2mG/1QGX vN7adkU4UWWiFkMc1lfyKCaDpVLC/Bbs8tY7xF1LsSW29OCLl9zHNAuMiw0kYiDbK0 asuxuatQ056gTMnvUcP3fwlgXsGyVSdXCROAYQC/5j9UZRPq9TMxriqlQKMfIyjXtK eNNEZyCOJ6ylrg04OXg4XsQ5THEt2S+brlZ544CaiJhvkJaPh8cmxhE5ik8Lcc0Uyp sY0bGgHttQqkw== From: Danilo Krummrich To: akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Danilo Krummrich Subject: [PATCH] mm: (k)vrealloc: document concurrency restrictions Date: Thu, 25 Jul 2024 14:54:37 +0200 Message-ID: <20240725125442.4957-1-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 3286D4000A X-Stat-Signature: 74xieokpbhy7sk5jqyf3rxsoon79pkha X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1721912114-693928 X-HE-Meta: U2FsdGVkX1/qYC9Sr+4AaiTqYKm0bB6SKWdBTuc7/jGbdhbYBgg2GroEFGNygdUOem5Pf+cWuXib1fP7Fym8VGevKabX4e1T8uOUn5UVCzgxpon3wsBKocrxmTi7vmeBWgcFb87pPOhlTTM4aWYb9Y7VkvRp6lu1oGoUY9fkwGQ2VnCb4POvg5LQTVWtyF0wqBMIPSMuPr6tUfAUBSmysHnI1i4hFympOZkQfRXaymuh0aNpgl/z+w3wZ3Q3qrUYwjWkGIJu0Mv5mi67n1LOjVTKv1EoNshv038UmlezI+eOF5jrp+bUkN4ewjj3OCJSCKAanMk/eXgPHHN1YuPmDNguRznwa/sj2Hj5M1gSg+S/cRuPZq5iCpI/3nTSghKpf5Oo5ZuRqWQGy4eRAAeMHXTm3g89p/P4mUVGA8gH7kURl/fXYYWW6OYTrYUN0kryAmVbYgpHLl82YmQEISiJUlLjO9/1DEb9Bj8i6K8CQZpiDRGpPb4soyIRz1zsKaqk/FpKDILHqnUz/BpwCnQlg6VnWfWD9tDp91Fs161j+y8sfRX7IbFjz6XWoGAD9N1JgDIwNRHWJXGgGhKEP5oQ8YGPb8RmDDqBVq/9uSr2MWIGRULXXc75lTKKYEHcib3VqzdGVup9v5YsuVRGWKXsRGlu7E6GrsJr3iLEl08Ctem2Jx8q7oLMz0qJafGOzD03P0COcmvUxBetjEk1aJ59+ojP2a1jnx/aG8HLaottZKn1SMRO65fQSbTqIb7crgNNFhWXGidA5fUpyfGu4OJGlOOcqObA+Jma13mEShwZp7DHfRMHiBWV22lYaDEy4cxWwyNqM4vob2fNpY5HJ6adPVw/xDvXb74vr5C074KV4esyzcXOBu7kIkkLo8EUvFGfm5B8qe0XCDC1yGA1/rvgLi8och4RjTJHDfqohbTcbzifduzt9dkCfgfffqDnZI6ZJFnqYFjcNL7j7sOvjV3 Y3J9sa3g JwHQSh4CYe40Oc5zx3W59lh6fOW6mHPRpwrbXz3qiVzx2v3RPTIEyoRlyDeXXoH32Igyv6UgoXr5Y4LdEJHZAu/3PLUnvS5sfvPbNCXnaRdMFU/V9m/UNbd+QZv/KhFHJuo5mH97JcIKzVaAaecWaoIYMbEaTL+M9QyhGGyjWejC7j7gjlkU1nLUU3s5+tcJBnlFTBiPOgMPhXer+ZhBZr8ex05TWrvxodonEkNJMY8bjsiTJvh+feaafxKMR79ZikZtjBHe++6LonJzSZYCh9oxHU+PELuVXE+OaFjJStnXkfrYT6haIGzfjR68f5+Dp5kLR 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: List-Subscribe: List-Unsubscribe: Document that concurrent calls to vrealloc() with itself or vfree() for the same memory allocation are not permitted, since it leads to undefined behavior. Consequently, the same applies for kvrealloc(), hence also document it for kvrealloc(). Suggested-by: Christoph Hellwig Suggested-by: Uladzislau Rezki Signed-off-by: Danilo Krummrich --- mm/util.c | 3 +++ mm/vmalloc.c | 3 +++ 2 files changed, 6 insertions(+) base-commit: d270beaca6818349b2aed7e6034b800a777087cc diff --git a/mm/util.c b/mm/util.c index 0ff5898cc6de..29ae93f6344f 100644 --- a/mm/util.c +++ b/mm/util.c @@ -732,6 +732,9 @@ EXPORT_SYMBOL(kvfree_sensitive); * If @p is %NULL, kvrealloc() behaves exactly like kvmalloc(). If @size is 0 * and @p is not a %NULL pointer, the object pointed to is freed. * + * This function must not be called concurrently with itself or kvfree() for the + * same memory allocation. + * * Return: pointer to the allocated memory or %NULL in case of error */ void *kvrealloc_noprof(const void *p, size_t size, gfp_t flags) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index caf032f0bd69..2a6d4ce57b73 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4049,6 +4049,9 @@ EXPORT_SYMBOL(vzalloc_node_noprof); * If @p is %NULL, vrealloc() behaves exactly like vmalloc(). If @size is 0 and * @p is not a %NULL pointer, the object pointed to is freed. * + * This function must not be called concurrently with itself or vfree() for the + * same memory allocation. + * * Return: pointer to the allocated memory; %NULL if @size is zero or in case of * failure */