Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp642856rwi; Wed, 26 Oct 2022 05:36:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6zFf4WfwEd32/jqVT/NyXUiPteI9yAGoK5OenZxQM+qgbnKEWo4hGAXTXvbNBlk6yqzEmF X-Received: by 2002:a17:902:968f:b0:180:a7ff:78ba with SMTP id n15-20020a170902968f00b00180a7ff78bamr3309483plp.87.1666787799891; Wed, 26 Oct 2022 05:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666787799; cv=none; d=google.com; s=arc-20160816; b=SgJag5IaLhsZ2v+L3eR68KWGXHZf/TMLQ1nfnaSY22r/mwqgNZZmBUQtVLTjHNMymD +QzIjYW2VxtI517K8hNkQzyjSA2f7nGWBQn+ttgY9BMSufEkTSuCjpVdtRqC3DodwPD1 GjShbXu304NZH8Ouyl7EC+lWZvCiqD1IIoW8ibHk3s7/X1C3Y/xyr3ZTdBSlAzS4SIG6 fFgqP5TN4aFRBhXto13bBesA6cbGLLMhebkYd4zjD4UrZll/dQMyV6quPxZvD+txTkun QCQWkjvxZHJ1I2YXYHqzB3VVlxxAUOTMQR+6zCcuK+6eHHjARXa0hAdMa3xFyEuZTP2D fWfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YpAx1fAxb98uuZeWq7KRaROK0Dpa8l/uXpA25r47Z6Q=; b=wk/5GPpNaT4KPqm+ekccOmIfQA8mAqKJp6BXY/vdRODZUsbAQLDPtYXIDdPh9R/x7J LU9pEluHvY9LYqpjUfhcwdhTOK+RGe1v6uPbqSs9DsivmLw1EdTD+vejVKKnuSF2fUDY qPDgIRUctxLWXVBREukIiuAemX0o5D2mdhoDmZr6uazgZZZmhpY11PqssGMmATNaTn9Y gf3gHCwvrNNi58kpYBoVNqxYCy4+nyxvZ42fJAVdqVXSUik1gWltISs6lTrAiCQKhyEc RhwhlZFNCd8hYCirwSU3bNB8EqJK4iuRkZN6ki+eN+J6Ysa8NncNU8/taBc6SaxRawNp GrpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GLVvkhyQ; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a654685000000b004355fc90c39si6713366pgr.261.2022.10.26.05.36.24; Wed, 26 Oct 2022 05:36:39 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=GLVvkhyQ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233533AbiJZMDQ (ORCPT + 99 others); Wed, 26 Oct 2022 08:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233485AbiJZMDN (ORCPT ); Wed, 26 Oct 2022 08:03:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 331AE1EAC7; Wed, 26 Oct 2022 05:03:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B672D61E66; Wed, 26 Oct 2022 12:03:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA89BC433D6; Wed, 26 Oct 2022 12:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666785791; bh=6nSdeLY7Vee3zTn134Svm4OVr3YBNP5jgNn+QKXMSVc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GLVvkhyQ2pa5HCN+eKkJGW96HlNJqNbUAlfedOV5KjSFWq2yjrck4LiZm4ksRKplm T/+mBH4se+pxATjhaKPnXelfg8u51eSSjkoVgxqiPuxOu11SZDfKjDoqzAO/b2OSKL 5bvI+TLWzFu+ssFg99xbvpxYOpp2LUM/gkI4WLhY= Date: Wed, 26 Oct 2022 14:04:04 +0200 From: Greg KH To: Borislav Petkov Cc: Yazen Ghannam , linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, tony.luck@intel.com, x86@kernel.org, Smita.KoralahalliChannabasappa@amd.com, mpatocka@redhat.com Subject: Re: [PATCH] x86/MCE/AMD: Decrement threshold_bank refcount when removing threshold blocks Message-ID: References: <20220614174346.3648305-1-yazen.ghannam@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 On Wed, Oct 26, 2022 at 12:16:40PM +0200, Borislav Petkov wrote: > On Wed, Jun 15, 2022 at 01:51:47PM +0000, Yazen Ghannam wrote: > > Yes, I believe that's true based on code inspection. But I'm not aware of any > > reported issues in this area before the commit listed above. So I decided to > > switch the Fixes tag from what I had before (shown below). I can switch it > > back if you think that's best. > > > > Fixes: 019f34fccfd5 ("x86, MCE, AMD: Move shared bank to node descriptor") > > Yeah, that is probably the culprit. I finally got to this and am able to > repro on my F10h box. > > Here's what I think the fix should be, Greg, please check this > for no-nos, especially for doing a kobject_put() on the parent in > remove_shared_bank_kobjects(). But that is basically the reverse > operation of the kobject_add() I'm doing when sharing the bank, more to > that below. > > I wonder why we see this now - maybe the kobject reference counting got > changed since then... > > Anyway, thoughts? > > --- > From: Borislav Petkov > > x86/MCE/AMD: Correctly drop shared bank references > > Old AMD machines have a shared MCA bank 4 which reports northbridge > error types. That bank has a bunch of controls which are exposed this > way in sysfs on CPU0: > > /sys/devices/system/machinecheck/machinecheck0/northbridge/ > ├── dram > │   ├── error_count > │   ├── interrupt_enable > │   └── threshold_limit > ├── ht_links > │   ├── error_count > │   ├── interrupt_enable > │   └── threshold_limit > └── l3_cache > ├── error_count > ├── interrupt_enable > └── threshold_limit > > In order to expose the exact same controls - the bank is shared > between all CPUs - threshold_create_bank() reuses the bank pointer and > kobject_add()s it to the parent of the other CPUs: > > mce: threshold_create_bank: CPU1, yes, use it, kref: 4, parent_kref: 3, name: northbridge > mce: threshold_create_bank: CPU1, inc cpus: 2, bank ref: 4 > mce: __threshold_add_blocks: entry, kobj: 0xffff888100adb218, parent: 0xffff888100c10c00 ref: 1, parent_kref: 4, name: dram > mce: __threshold_add_blocks: misc, kobj: 0xffff888100adb418, parent: 0xffff888100c10c00, kref: 1, parent_kref: 6, name: l3_cache > mce: __threshold_add_blocks: misc, kobj: 0xffff888100adb318, parent: 0xffff888100c10c00, kref: 1, parent_kref: 7, name: ht_links > ... > > kobject_add() does a kobject_get() on the parent for each sysfs file it > adds. > > Therefore, in order to unwind the same setup work when the CPU goes > offline and the bank *references* only are being removed - the other > CPUs still share it - do a kobject_put() on the parent. Eeek, no! You can't decrement the reference on the parent, that could cause you to get dropped. And you can not reuse kobjects, is that the issue here? When you are done with one, you have to delete it. Then create a new one. No need to move anything around, just destory it all and then add new ones. > Rename things more properly while at it and add comments. > > Signed-off-by: Borislav Petkov > > --- > > diff --git a/arch/x86/kernel/cpu/mce/amd.c b/arch/x86/kernel/cpu/mce/amd.c > index 1c87501e0fa3..b2bdee9e0bae 100644 > --- a/arch/x86/kernel/cpu/mce/amd.c > +++ b/arch/x86/kernel/cpu/mce/amd.c > @@ -1241,31 +1241,40 @@ static void threshold_block_release(struct kobject *kobj) > kfree(to_block(kobj)); > } > > +/* > + * Drop refcounts and delete list heads in order to free the memory. > + */ > static void deallocate_threshold_blocks(struct threshold_bank *bank) > { > + struct list_head *head = &bank->blocks->miscj; > struct threshold_block *pos, *tmp; > > - list_for_each_entry_safe(pos, tmp, &bank->blocks->miscj, miscj) { > - list_del(&pos->miscj); > + list_for_each_entry_safe(pos, tmp, head, miscj) { > kobject_put(&pos->kobj); > + list_del(&pos->miscj); > } > > kobject_put(&bank->blocks->kobj); > } > > -static void __threshold_remove_blocks(struct threshold_bank *b) > +/* > + * Only put the parent kobject of each block. The inverse of kobject_add() > + * above in threshold_create_bank(). > + */ > +static void remove_shared_bank_kobjects(struct threshold_bank *bank) > { > - struct threshold_block *pos = NULL; > - struct threshold_block *tmp = NULL; > + struct list_head *head = &bank->blocks->miscj; > + struct threshold_block *pos, *tmp; > > - kobject_del(b->kobj); > + list_for_each_entry_safe(pos, tmp, head, miscj) > + kobject_put(pos->kobj.parent); No, please don't do that. > > - list_for_each_entry_safe(pos, tmp, &b->blocks->miscj, miscj) > - kobject_del(&pos->kobj); > + kobject_put(bank->kobj); What changed to cause problems? the kobject reference logic hasn't changed, was it some topology stuff? thanks, greg k-h