From patchwork Mon Jan 30 20:49:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13121812 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 60BA1C636CD for ; Mon, 30 Jan 2023 20:49:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE8B46B0071; Mon, 30 Jan 2023 15:49:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D00A96B0073; Mon, 30 Jan 2023 15:49:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B77896B0072; Mon, 30 Jan 2023 15:49:50 -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 9EC156B0071 for ; Mon, 30 Jan 2023 15:49:50 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7639A1A04F3 for ; Mon, 30 Jan 2023 20:49:50 +0000 (UTC) X-FDA: 80412656940.27.0A1B711 Received: from out-35.mta1.migadu.com (out-35.mta1.migadu.com [95.215.58.35]) by imf22.hostedemail.com (Postfix) with ESMTP id 84F3CC0020 for ; Mon, 30 Jan 2023 20:49:48 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.35 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111788; 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=vpL8/NdYX1/weZXFrNrkU0jpgSm404fZwOGAfIO2ueo=; b=SRVPrC2w9/rH60s3z2cVaxiwOwaWkRxxvi7MWr+Yanq6X8EmYkN+ghrxZ0JOPcuKu/p4Vv R+emEXqZlJGdjPv/nhzmQHLdJpON8ylDXC3BK9xKyj8g4BiVQCBz8mqaKd2EtP0Tri/WWI 5kNc7CBNSyVBu1+bsYB+2/QWqVZcJZA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.35 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111788; a=rsa-sha256; cv=none; b=WQL2aJyYKwogBGdb1qHueKCWJIdZnPglKB9WWvcEhsSdeyqKWV+UyjTzAGXTQdbOrgn37b KALxdNKgViQl37ng77FZFKqQzuFF4HgOOi/5aYYFuWgSrFCKpESzNWl+BUoZEtchhdTZL0 XjYvJjicbNlRMz5C8MCsnJqvpx2toYE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1675111786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vpL8/NdYX1/weZXFrNrkU0jpgSm404fZwOGAfIO2ueo=; b=l/E56Ec3WqQvEhqdZjl8IUp453ZZ1+XVexohawe9WXRwZLVX9lAj0fJNkLKpd1L0XbJ/cZ r7uaM/Wl4isiyHyMF6tbOKjX8DK6rY8u5FVwTS72y6me8Wdk0ledgHuQWb2LrJtfpWi2lC Ire9k++4IxKra40cnB4YNO9o09pIkPQ= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 01/18] lib/stackdepot: fix setting next_slab_inited in init_stack_slab Date: Mon, 30 Jan 2023 21:49:25 +0100 Message-Id: <9fbb4d2bf9b2676a29b120980b5ffbda8e2304ee.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: z97a9cz3zsgkh7nruiirbuo9isbbiayy X-Rspam-User: X-Rspamd-Queue-Id: 84F3CC0020 X-Rspamd-Server: rspam06 X-HE-Tag: 1675111788-375484 X-HE-Meta: U2FsdGVkX19qb5pqjyGUySpGxrH34HhETyVupLn4gl65F/nLv3rE70uFMietY5XQFOuk48kBLTaEYz+dURhy0ODxj6KQmkyxjwZd2JoCmvqOPbIcz/TJ4wxCt59CHeTEl3gczn/bOEuewlWipK7C1VgrRJmsybjNao9eteN1YEFy8XBDOoIgwceHdm8n4g9zavAQ3rut+GPf89qJKkukp8HpIdhQ1EwFYaXVPXQt8//41Jr+G25xaYL6wUiCnBsI8EWw5iYVJotXu1j4WZZ8JeKT6pYYIZ5kG2W5cw9tnNXO/ARveR5wOM2VY7fDoaf4bFJGn2yppW59mYU0DwU5rArakNeUGaLlxx0ulyKdjbwZ0NJriksv19ZyIdTfl653tq8lbFMbnrouxSLXedxq19YuYlLP+ZDW2pTnqJJmz1nshl/7L7IgQIsCHbLxTHrf3ag5tBSgr12BcSNNtZ0hT99o0oZeTeHfbq0+/9LNqgEV4Izfexw84hdoUQz+Rzeuh+X9UHxcNRoTv4K+roV3tnfvk3qtiYb47OKw28Zncznx5wrP/UQM59StqttlE2CXTh1LEwyhStMIUwopc2f01ZGcYkU1GBM9xZq8r1MUOfHPG5WOwo0crXzqfLhtpz0azgDXgYwfpvZeG4g+4QczcuZX6tFazyjf2657C+BDuhYgTq0EpoydEyCVBDivLT60s8euHhkqZ22eXOiRI3WunAmoGyoyhHxEpblNizEJln11MaKPNfMDmLwmIMh6fpNIjJa+vxzfkIh76NpJDoOn11JwK254tr9+JY2yMCaHErtaUVnbdSViWhdQsyc2kivYmmILEvdZT5Icq33VwlxQrqsT/KFqMiCNbwmQYbypzPba6KxUhiSDhL3O7ZZh806SrxYEgPb+o9xGvz49tI3OTTLfqFUjtYqANj7KvnDZRW0fF7sXl9DOHGofZiujJZVuN8zAHxL1kDw2gcbXdHb o9qjNq26 cOXua+VGZuJ/GNEAQ7XCf7bxekzin/U6fWbzKyV0v6XRk3iJJdh87Q5tX1ujkOzkF2pecHxBrjplwnpTqZO9gDQR2pbhTSycsBGdibR3Nohe4izEkHnD5W+aGGk5eqWtmaTeq1MDebN50e9Cc61KSYc0poQ== 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: From: Andrey Konovalov In commit 305e519ce48e ("lib/stackdepot.c: fix global out-of-bounds in stack_slabs"), init_stack_slab was changed to only use preallocated memory for the next slab if the slab number limit is not reached. However, setting next_slab_inited was not moved together with updating stack_slabs. Set next_slab_inited only if the preallocated memory was used for the next slab. Fixes: 305e519ce48e ("lib/stackdepot.c: fix global out-of-bounds in stack_slabs") Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 79e894cf8406..0eed9bbcf23e 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -105,12 +105,13 @@ static bool init_stack_slab(void **prealloc) if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) { stack_slabs[depot_index + 1] = *prealloc; *prealloc = NULL; + /* + * This smp_store_release pairs with smp_load_acquire() + * from |next_slab_inited| above and in + * stack_depot_save(). + */ + smp_store_release(&next_slab_inited, 1); } - /* - * This smp_store_release pairs with smp_load_acquire() from - * |next_slab_inited| above and in stack_depot_save(). - */ - smp_store_release(&next_slab_inited, 1); } return true; }