Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3483077pxb; Mon, 4 Apr 2022 18:24:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUDaeEJrWDrJCAhSZjycEmuuomQRg+/7+J9GBMohFCbAA546+IZ61G2BjukFwWE4I6jw0R X-Received: by 2002:a17:902:e949:b0:14b:1f32:e926 with SMTP id b9-20020a170902e94900b0014b1f32e926mr923679pll.170.1649121877701; Mon, 04 Apr 2022 18:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649121877; cv=none; d=google.com; s=arc-20160816; b=UPiKRlqoXUEdvU6rH9HPs8iQy395BKIsbIi2so8VwFBFxw7je33oitmW6bt6/3+DJb h6phnW/GoaNYR6iVa08NrVnVRk9cLJGbg/+IN9gHI1P1KLCJ4wyLmrXOwC54wk2QlajF B20IhsXMKVCQLRyqXF4G9NASzty8LjPRSVc+RWHsKFhEHgwNzRHbof8m73JKkzyXiEUw +wg/rM1BNnRenLZbd43HQ4gFw5uP5mQJb00ttlhzONG6YDU6FMRJjBfUBn8mpoXG1/nD cobDGDjYLRtG6R9DStpXMconYPadZSdS2IO7TwCrgLR9FmyLY9Oh9iR1VovIoQJUDrOH A0AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=3L7eFZJMeJwnV9w8LfFb8yVtnAkHUxkpK6RM13PqQG4=; b=Xs3kRwBvbcYdou/8ljMD4JIUr8PllMb8a1GwKnEn190xzi6gVY4Bodvb/kRISzbbQo K5eekTut6r1WaZx8qCWWy6yA9B8gCNo392vF7gmlY1LRYQWrBcISML9iiUvmQTjWupYv sIetUB48VgoB76jH2mwXRszJtQQ3pQe3xM9GYOKvyH/pEm8Vdiw07pzFU9PYHfPIzI8i +lP46I7cEvS3joTdyCGPXwnbNT2r670WY+jXLqV6cvPT2TeE6gRt7MmOXG3rRb80vIAb jt77iYAut5Mf831LkseLEIpYC0R3wekgYObkUf68UD1HCZ+T1bD29xftiUM1zB3H95zw 8+Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=VJS8BKQy; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x37-20020a634a25000000b003828dd9d0fdsi11557291pga.843.2022.04.04.18.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 18:24:37 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=VJS8BKQy; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 017161965EA; Mon, 4 Apr 2022 17:15:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359691AbiDCRp6 (ORCPT + 99 others); Sun, 3 Apr 2022 13:45:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237064AbiDCRpt (ORCPT ); Sun, 3 Apr 2022 13:45:49 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C8D3245A1; Sun, 3 Apr 2022 10:43:55 -0700 (PDT) Received: from [192.168.148.80] (unknown [182.2.43.220]) by gnuweeb.org (Postfix) with ESMTPSA id 79C217E30F; Sun, 3 Apr 2022 17:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1649007834; bh=g+Aaz5gOVqg1UqHTFl/e0lztT7SCfdRxe0LTCYfvGZk=; h=Date:To:Cc:References:From:Subject:In-Reply-To:From; b=VJS8BKQytvGXeh/iknV1WP23B+3ujmMNZgtGO9lX+V8isx+SiPX63/uQIvw7djKPZ CU0wNWiAVl2IfY9pUXH7fpTNsNktrVJhyYTjQqInaJ0h3ecRsC2KEVxU/O82YOXBD7 985rLFWu6H9CgPv+h64O15W8gBBR7lRIxyjg0uFoJSuxlSTlSaz4xPa+TyOw8yqLj0 Q83Jgzaysft60cZpOJV9vqrx925iPNI1k5NXaSIcM6uX9QseSYFRvTNiCVP99sdiIx CR3JRFUTeyA8sBCtYrq329cm9QAM7PSGxLzBLU/948GQikbxcyyJXt1QSH+0BbLgrN xgbfU7M3Fi7lQ== Message-ID: <215ca9e7-b719-d5b8-c6db-1d71544d47be@gnuweeb.org> Date: Mon, 4 Apr 2022 00:43:47 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: Thomas Gleixner , Borislav Petkov Cc: Alviro Iskandar Setiawan , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Tony Luck , Yazen Ghannam , Linux Edac Mailing List , Linux Kernel Mailing List , Stable Kernel , GNU/Weeb Mailing List , x86 Mailing List References: <20220329104705.65256-1-ammarfaizi2@gnuweeb.org> <20220329104705.65256-3-ammarfaizi2@gnuweeb.org> <87wng6ksjl.ffs@tglx> From: Ammar Faizi Subject: Re: [PATCH v6 2/2] x86/MCE/AMD: Fix memory leak when `threshold_create_bank()` fails In-Reply-To: <87wng6ksjl.ffs@tglx> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 4/4/22 12:03 AM, Thomas Gleixner wrote: > On Tue, Mar 29 2022 at 17:47, Ammar Faizi wrote: > >> In mce_threshold_create_device(), if threshold_create_bank() fails, the >> @bp will be leaked, because the call to mce_threshold_remove_device() >> will not free the @bp. mce_threshold_remove_device() frees >> @threshold_banks. At that point, the @bp has not been written to >> @threshold_banks, @threshold_banks is NULL, so the call is just a nop. >> >> Fix this by extracting the cleanup part into a new static function >> __threshold_remove_device(), then call it from create/remove device >> functions. > > The way simpler fix is to move > >> } >> this_cpu_write(threshold_banks, bp); > > before the loop. That's safe because the banks cannot yet be reached via > an MCE as the vector is not yet enabled: > >> if (thresholding_irq_en) >> mce_threshold_vector = amd_threshold_interrupt; Thomas, I did like what you said (in the patch v4), but after Yazen and Borislav reviewed it, we got a conclusion that it's not safe. See [1] and [2] for the full message. [1]: https://lore.kernel.org/lkml/YkFsQhpGGXIFTMyp@zn.tnic/ [2]: https://lore.kernel.org/lkml/Yh+oyD%2F5M3TW5ZMM@yaz-ubuntu/ Yazen, Borislav, please take a deeper look on this again. I will send a v7 revision to really make it simpler by moving that "per-CPU var write" before the loop. Thanks! -- Ammar Faizi