From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C437FA372C for ; Fri, 8 Nov 2019 15:32:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D783221882 for ; Fri, 8 Nov 2019 15:32:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alien8.de header.i=@alien8.de header.b="oXvp/OSE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726887AbfKHPcO (ORCPT ); Fri, 8 Nov 2019 10:32:14 -0500 Received: from mail.skyhub.de ([5.9.137.197]:59148 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726152AbfKHPcO (ORCPT ); Fri, 8 Nov 2019 10:32:14 -0500 Received: from zn.tnic (p200300EC2F0D3700C146D27A9F02E8E8.dip0.t-ipconnect.de [IPv6:2003:ec:2f0d:3700:c146:d27a:9f02:e8e8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id BEC711EC0D03; Fri, 8 Nov 2019 16:32:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1573227128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=Wy2nApVSv0Jbeun95X8bJdRkeSPWfkwqp16W5VjvXSQ=; b=oXvp/OSEVBnqkFXh3X/bJm8gHHcJmwurn9LAgHETk+DvQI2DU/yKp04mOAoXwTlZLhXml3 xZL3iV6jYVCunLJB4cfTXT5MrVlGTADTagu7TIPIZyJwsIokQHoP7NMt4aQg0JYXNNMMNW jZbHiNve4Z2jYsOE/PLgU63y6pX6tio= Date: Fri, 8 Nov 2019 16:32:03 +0100 From: Borislav Petkov To: Robert Richter Cc: James Morse , Mauro Carvalho Chehab , Tony Luck , Borislav Petkov , "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v3] EDAC, ghes: Fix locking and memory barrier issues Message-ID: <20191108153203.GE4503@zn.tnic> References: <20191105200732.3053-1-rrichter@marvell.com> <20191105201115.v2pe6k6g2brx5itv@rric.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191105201115.v2pe6k6g2brx5itv@rric.localdomain> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 05, 2019 at 08:11:22PM +0000, Robert Richter wrote: > On 05.11.19 20:07:51, Robert Richter wrote: > > The ghes registration and refcount is broken in several ways: > > > > * ghes_edac_register() returns with success for a 2nd instance even > > if a first instance is still running. This is not correct as the > > first instance may fail later. A subsequent registration may not > > finish before the first. Parallel registrations must be avoided. > > > > * The refcount was increased even if a registration failed. This > > leads to stale counters preventing the device from being released. > > > > * The ghes refcount may not be decremented properly on > > unregistration. Always decrement the refcount once > > ghes_edac_unregister() is called to keep the refcount sane. > > > > * The ghes_pvt pointer is handed to the irq handler before > > registration finished. > > > > * The mci structure could be freed while the irq handler is running. > > > > Fix this by adding a mutex to ghes_edac_register(). This mutex > > serializes instances to register and unregister. The refcount is only > > increased if the registration succeeded. This makes sure the refcount > > is in a consistent state after registering or unregistering a device. > > Note: A spinlock cannot be used here as the code section may sleep. > > > > The ghes_pvt is protected by ghes_lock now. This ensures the pointer > > is not updated before registration was finished or while the irq > > handler is running. It is unset before unregistering the device > > including necessary (implicit) memory barriers making the changes > > visible to other cpus. Thus, the device can not be used anymore by an > > interrupt. > > > > Also, rename ghes_init to ghes_refcount for better readability and > > switch to refcount API. > > > > A refcount is needed. There can be multiple GHES structures being > > defined (see ACPI 6.3 specification, 18.3.2.7 Generic Hardware Error > > Source, "Some platforms may describe multiple Generic Hardware Error > > Source structures with different notification types, ..."). > > > > Another approach to use the mci's device refcount (get_device()) and > > have a release function does not work here. A release function will be > > called only for device_release() with the last put_device() call. The > > device must be deleted *before* that with device_del(). This is only > > possible by maintaining an own refcount. > > > > Fixes: 0fe5f281f749 ("EDAC, ghes: Model a single, logical memory controller") > > Fixes: 1e72e673b9d1 ("EDAC/ghes: Fix Use after free in ghes_edac remove path") > > Co-developed-by: James Morse > > Signed-off-by: James Morse > > Co-developed-by: Borislav Petkov > > Signed-off-by: Borislav Petkov > > Signed-off-by: Robert Richter > > I hope this SOB chain is correct now. Yeah. Applied, thanks. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette