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: 50481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2395188wrn; Mon, 30 Jan 2023 13:03:19 -0800 (PST) X-Google-Smtp-Source: AK7set/CgzCjDA5nOlf1tnVp0F+KuzwegQ1rt7R099hvNrSX7ZuAj/Fxj8h70k77JZZPYVLWsiTM X-Received: by 2002:a17:906:44d:b0:878:816f:8691 with SMTP id e13-20020a170906044d00b00878816f8691mr14929067eja.71.1675112598923; Mon, 30 Jan 2023 13:03:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112598; cv=none; d=google.com; s=arc-20160816; b=cJ1aG2/7BbsopprEobNwT4EoIeK2H/s2Vyx61OwaZZBt6gUK24zYMbLRRH2XXRHOzY gQRMu7T+q91odaV8sVeuBDFe4VtwPJIZCRs39c2XMMFsRuJo19OTaESsSVZAUIpXMdgt RGos0B3YOVt6NB+QfqQwCjob48o6qV89ziLG2sxBm/LsW3N6BBrK5NqTNmp0krEN8sUh 8hC3JwLiOP1phHcf6RRKnaM0sokH8zBBr4j0SpvDLyLBBSprEORYJFydIGjfGtsmbJSu 6h/5N+jWk5CnjnZFeT88v5UVId7vd2DngiXP4NZHgjqq4WpaKEgCnT28D1lRqh7KQGLn lYVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vpL8/NdYX1/weZXFrNrkU0jpgSm404fZwOGAfIO2ueo=; b=aL/SU+DFR/GGN2TFi+Jf2P00xbD1ewdpdWAhQhg2ouHdriH0Y6/LYJMKjMxSOTSKj/ TUpb6vm+DjAbLJwCxEKhxJ5Q73pad237fQgKrfxnGleM2k8PX3qcge3n6GO3wZMIBNES nFRGqVEJMF8odhFhloRJqYDxR/DWxdEel3gKOUP6ZAMYEltSCoL7+DjpKC13NBu7PSok 8puY1303eNmF8l3LrQW9HDFfmCwpHKiwRHih3DHh0MSam78ztahrQ/hiOVcO6M7KQudy Rye/LGITHRDGBy8x9yUwPwGVg6VQvDmDh7c1v8gruxgzYarMHM50+xa14QD551m1V3VY ZcCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gk4-20020a17090790c400b00886971a7fc7si6384927ejb.732.2023.01.30.13.02.54; Mon, 30 Jan 2023 13:03:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbjA3U4M (ORCPT + 99 others); Mon, 30 Jan 2023 15:56:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbjA3U4L (ORCPT ); Mon, 30 Jan 2023 15:56:11 -0500 X-Greylist: delayed 382 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 30 Jan 2023 12:56:10 PST Received: from out-195.mta1.migadu.com (out-195.mta1.migadu.com [95.215.58.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3182A15A for ; Mon, 30 Jan 2023 12:56:10 -0800 (PST) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482868511311815?= X-GMAIL-MSGID: =?utf-8?q?1756482868511311815?= 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; }