From patchwork Mon Feb 5 17:26:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13545899 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 987B8C48292 for ; Mon, 5 Feb 2024 17:27:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 128E36B0088; Mon, 5 Feb 2024 12:27:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D7B86B0089; Mon, 5 Feb 2024 12:27:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE1706B008A; Mon, 5 Feb 2024 12:27:31 -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 D999D6B0088 for ; Mon, 5 Feb 2024 12:27:31 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9A2271A062A for ; Mon, 5 Feb 2024 17:27:31 +0000 (UTC) X-FDA: 81758431902.01.FB4AE6F Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf06.hostedemail.com (Postfix) with ESMTP id B7D22180012 for ; Mon, 5 Feb 2024 17:27:29 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ngQ0M3Oq; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf06.hostedemail.com: domain of dianders@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=dianders@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707154049; 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=4U+N71xHm4gg+B0aHt1NbcRFqwuGDCVmnH0NzcNhfq4=; b=CbjuuRPqFdNeEmY5yi37IDMoJ56lJFTHT1uK+TlWNXlt7oNEg9qiBKdrQUHcTKcoC/5Ard PA+dTV8vQ1FsVhaiEbrn9cO36Jb/g3c/ft1n3cIum1K2fHIFujrBsn/F3Kn6P5DrdREc3Q rzD0lXRZRA7Q6v0vVAuS/l0dHxL0K2E= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ngQ0M3Oq; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf06.hostedemail.com: domain of dianders@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=dianders@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707154049; a=rsa-sha256; cv=none; b=xj4v0NASe+4T/BU52zmxEt8nlphdubBPGPAhc5cS4ABParupBffvNLbLVxNGnUcgGguA5d gDdIPWFYJAB6xDcX8j4oyOEioisYWcZQneUKYDhr0l5BovAcnGtVmVPzs3J6lbAWeDE0xB HlFTvBuYaetHowdJpwg4r6kg/p1B3/Q= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d91397bd22so35670835ad.0 for ; Mon, 05 Feb 2024 09:27:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707154048; x=1707758848; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4U+N71xHm4gg+B0aHt1NbcRFqwuGDCVmnH0NzcNhfq4=; b=ngQ0M3OqqKzAJDP5zHdUZyutXU+g7eXedjHyGWszV3eyaTs8ELd2W0YPNpekjhLFfE 6bUfdg1n+CUR1yVt8Ru3EZa1GLFMJkkaplEqIhvIS7s33NKUZq0ht0V7k7XNG3lSuEb0 rLLmML2ZYUhLMAaDhJKphFk5aNAsxm+ZKzKA8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707154048; x=1707758848; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4U+N71xHm4gg+B0aHt1NbcRFqwuGDCVmnH0NzcNhfq4=; b=YnJJbFo0q3nLk399616XSH99IpPy8e1ZpfnHnDfI90YvH6oHiTPK0s/RpcvxUqhh2z 0N1Os8onxB4nq5R4gSEZJ7hum9JSMk59+6Eov74B5Zmo4kT6cukRHgQ2OBPT/iohycOJ vqndrrzz3X9N44CGQzWBTdjcDqAzcomQM+dPAkqqSwjBEJ1yFRAgc3AzyykudYxq9lq+ MUrz1tiVaRNAhVdLMidujSpnx1nruTg39fCqMfSmqOcMKfzkejmzRsCRrsizcrysDwq/ oXnMnGKBVR3J5X2ZItVRQodHfu/DG6d88jfkgVCxbvjaAR9OUPyLgFjGx4vpc94hjRyL X+UQ== X-Gm-Message-State: AOJu0YyvQkWkiubmpuq5hnToMV2/AahTOu6Tu5KYP59U0oRny9sUL+Cg ynhgpZpAC59+Ehfh2zAUALkJR3jeXAXWHLndbZfVGV4tZ7ah+e4uYoiRTNEa2g== X-Google-Smtp-Source: AGHT+IFUJYXHGIr2LCGI8FKWXE3xOLGI2mYhp7DYexE/TWjuF+OeqNnn4MkzN96+o/X73V7ZYaQWDA== X-Received: by 2002:a17:903:181:b0:1d9:3938:40bb with SMTP id z1-20020a170903018100b001d9393840bbmr164878plg.20.1707154048553; Mon, 05 Feb 2024 09:27:28 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVkRLaBMi1cNLgwcJ4gr0SdqkEdQyijwctiuf5LdVVfpVmK0cY3vbrQqxELm4VsUf5Iviie567CjnCp6QpZv2cJZ9qTb8bfFOzwsPSAlJh48jISJ5aEd1JYomsvY9PR9cZx2/SH/22aLo2LrtRfXvQSb2Bh1iuSAKT6xYetCUbxpQ4DFFVfEk7UJMJ1DqEHXhF2UQ+ReydK0bsF1WRihOmbhvch2i16kfzSuBnbaT8FTOs/yaujTj8mQ7QfpkBkp6Pbv7f/gEovrwRk1fsN+HmauyY2TRN4DA0XDpWrv23N7KxjeaOVBouvbOiux/BPvBL/ENUNLXoA3iqUrfDtfX7ZH924Fou+JlW18gHs1XX4HkDX8Bw5WvPK3NZTGnMWnpblMUi56HW33N7QE5JjPqf30PAXfjhzwnnGvCPTjkg0V7+BrDv9nwbIgg0TgeH2EJZ6lj47Nwmd/T1HsnXwnzPsUI46BtJckryogPjZAVY9WQM= Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:95f9:acd:a17b:b759]) by smtp.gmail.com with ESMTPSA id v11-20020a170902d08b00b001d942f744f6sm115259plv.157.2024.02.05.09.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 09:27:28 -0800 (PST) From: Douglas Anderson To: Alexander Viro , Christian Brauner Cc: Mark Brown , Catalin Marinas , Will Deacon , Dave Martin , Oleg Nesterov , linux-arm-kernel@lists.infradead.org, Matthew Wilcox , Douglas Anderson , Eric Biederman , Jan Kara , Kees Cook , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] regset: use kvzalloc() for regset_get_alloc() Date: Mon, 5 Feb 2024 09:26:30 -0800 Message-ID: <20240205092626.v2.1.Id9ad163b60d21c9e56c2d686b0cc9083a8ba7924@changeid> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B7D22180012 X-Stat-Signature: s874bt71xjzwk94f4uftaeoybfethatk X-HE-Tag: 1707154049-89170 X-HE-Meta: U2FsdGVkX1+syy/qPnOwu0e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xLCXYAJyZAJh06rVQazMlplbUBZ4k29jn3Zd4FchJD3WuhWMth8EQhRRdHitQY3aJcVrUH4CNXwngQS1MghVuRcY2fDIpj8LJiHqS0wBm3MeZ+lUgTtjKAj448NU8Z12R6dZEuaYIvKzyRfAhWMqP2KSk/tII6wMEH0W17j8W0G8ger3T4L19Qz/MhkePPud+dFLKIaSZ12CljddXhpl6xkAWnk0/3YZKlZUf0tda/4LN99lCOz+X0aKC/5OdM5RLrfgHVSJt1uWR6lvC9P4hnnhzoskilHdHOLs7V7mKmeQwdPuVktmMMOX7lzliEvy0CdJ9iQE98VEGtjPWVnYrTtxh3mt890YuyuH15Bw44hYd6PSV5FBuDuHEJqAk0SveWjdmK6SkZ1eDlfETkf65UQ4kHjjzBvDanUJ0= 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: While browsing through ChromeOS crash reports, I found one with an allocation failure that looked like this: chrome: page allocation failure: order:7, mode:0x40dc0(GFP_KERNEL|__GFP_COMP|__GFP_ZERO), nodemask=(null),cpuset=urgent,mems_allowed=0 CPU: 7 PID: 3295 Comm: chrome Not tainted 5.15.133-20574-g8044615ac35c #1 (HASH:1162 1) Hardware name: Google Lazor (rev3 - 8) with KB Backlight (DT) Call trace: ... warn_alloc+0x104/0x174 __alloc_pages+0x5f0/0x6e4 kmalloc_order+0x44/0x98 kmalloc_order_trace+0x34/0x124 __kmalloc+0x228/0x36c __regset_get+0x68/0xcc regset_get_alloc+0x1c/0x28 elf_core_dump+0x3d8/0xd8c do_coredump+0xeb8/0x1378 get_signal+0x14c/0x804 ... An order 7 allocation is (1 << 7) contiguous pages, or 512K. It's not a surprise that this allocation failed on a system that's been running for a while. More digging showed that it was fairly easy to see the order 7 allocation by just sending a SIGQUIT to chrome (or other processes) to generate a core dump. The actual amount being allocated was 279,584 bytes and it was for "core_note_type" NT_ARM_SVE. There was quite a bit of discussion [1] on the mailing lists in response to my v1 patch attempting to switch to vmalloc. The overall conclusion was that we could likely reduce the 279,584 byte allocation by quite a bit and Mark Brown has sent a patch to that effect [2]. However even with the 279,584 byte allocation gone there are still 65,552 byte allocations. These are just barely more than the 65,536 bytes and thus would require an order 5 allocation. An order 5 allocation is still something to avoid unless necessary and nothing needs the memory here to be contiguous. Change the allocation to kvzalloc() which should still be efficient for small allocations but doesn't force the memory subsystem to work hard (and maybe fail) at getting a large contiguous chunk. [1] https://lore.kernel.org/r/20240201171159.1.Id9ad163b60d21c9e56c2d686b0cc9083a8ba7924@changeid [2] https://lore.kernel.org/r/20240203-arm64-sve-ptrace-regset-size-v1-1-2c3ba1386b9e@kernel.org Signed-off-by: Douglas Anderson Reviewed-by: Catalin Marinas --- Changes in v2: - Use kvzalloc() instead of vmalloc(). - Update description based on v1 discussion. fs/binfmt_elf.c | 2 +- kernel/regset.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 5397b552fbeb..ac178ad38823 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1928,7 +1928,7 @@ static void free_note_info(struct elf_note_info *info) threads = t->next; WARN_ON(t->notes[0].data && t->notes[0].data != &t->prstatus); for (i = 1; i < info->thread_notes; ++i) - kfree(t->notes[i].data); + kvfree(t->notes[i].data); kfree(t); } kfree(info->psinfo.data); diff --git a/kernel/regset.c b/kernel/regset.c index 586823786f39..b2871fa68b2a 100644 --- a/kernel/regset.c +++ b/kernel/regset.c @@ -16,14 +16,14 @@ static int __regset_get(struct task_struct *target, if (size > regset->n * regset->size) size = regset->n * regset->size; if (!p) { - to_free = p = kzalloc(size, GFP_KERNEL); + to_free = p = kvzalloc(size, GFP_KERNEL); if (!p) return -ENOMEM; } res = regset->regset_get(target, regset, (struct membuf){.p = p, .left = size}); if (res < 0) { - kfree(to_free); + kvfree(to_free); return res; } *data = p; @@ -71,6 +71,6 @@ int copy_regset_to_user(struct task_struct *target, ret = regset_get_alloc(target, regset, size, &buf); if (ret > 0) ret = copy_to_user(data, buf, ret) ? -EFAULT : 0; - kfree(buf); + kvfree(buf); return ret; }