Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2659957ybx; Fri, 8 Nov 2019 07:33:17 -0800 (PST) X-Google-Smtp-Source: APXvYqz6hWp+6bfB9ZArvfD0vErEYR2wq8iyQj0GeHFVI42cEiWILP/ZUNgIj0P02og7JjgSdSnk X-Received: by 2002:a05:6402:1049:: with SMTP id e9mr10810741edu.91.1573227197890; Fri, 08 Nov 2019 07:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573227197; cv=none; d=google.com; s=arc-20160816; b=W+oAAv+qXg9DT1rNNAy9P6xsnI4zjPuV2YbwvzIBPimgiM1Djfa5SB2xQ6BMLIFHJT ghqLD5ZK9/wxeVMejt8WSKamzYo21qH5TFLuGRueTwA68/sKvqRUs4YAl0Jz/2lS+Hb2 vs5UzLoV5LhPfhqgiE/z9HmZWgzMaUH+G7SWdTEDDjbaxHxJ8LDGScUVmec351UPH2as Ceq2Jd1+s/X4X93tsyMFeoKd0v6F5emUv3M22NCLXst822zzC6TMYQSO6AwUWATWurQE FMGd0uXxr+r0TUGLIscqoZcoaE2inLE6Pe3LngK9paOcysMF42onmDpMVn07WPAmbRQr XDeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Wy2nApVSv0Jbeun95X8bJdRkeSPWfkwqp16W5VjvXSQ=; b=Ere2Xh8s5n1nQqEU9F4mZagRk5FRLydLe10gTrTOXsfsxSD3a16jN3+Jn/E6B2HZVq TfK8BzmZWqljuZJ2w9EpE8JTejXjF1PY/YXturrbdpskpsM2jAePxsC/eB3p0iGcoIT5 wfKkcQpa28Ts43o6W+7VRrnrSKV7IwYv+UlkLyUCwQBMzvr8MN2hTQYYJD02Add9W7SC Ic4DoAvCUf815gxdyTxwcis7iyZomuK8FUuzCyiKQtCEOZVn9by3DgoBVn+if3PgQtxh RsE7l8LqMLL9HF5u8CTeAJeixewCW7Noi6n11JXFm+NsYxZu5cy9z7lNpVqrLnDjMgtW SwEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="oXvp/OSE"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f26si3992459ejr.92.2019.11.08.07.32.51; Fri, 08 Nov 2019 07:33:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="oXvp/OSE"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726670AbfKHPcO (ORCPT + 99 others); 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