Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2739915pxa; Fri, 7 Aug 2020 20:56:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuPxHA9QZOA6chroqAW/qvPJQcbiMGfFVdl1dMVAiFxs2wrGR3qG40kSHekpTpoAIJgCs1 X-Received: by 2002:a17:906:89a:: with SMTP id n26mr4990446eje.363.1596858981310; Fri, 07 Aug 2020 20:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596858981; cv=none; d=google.com; s=arc-20160816; b=QyFOJZWrHOF4dfXmGPuqQGAJy2QHeItqqKnLf+boexJZogRtzH/d0ZXJdJsj++7Xps zHqWNv+3Ebtj/S/d79MS/baTusl0rgJLlSonf0jbZQL9BMhW89wOQgxJwZt60QBBa7nv cFGXESZE8EnmyPrPdU93HRZNfvLrHeNjj0UUt4E1FG0EQB+qL8GB1MfdIhpdMUgPt8yx T8ceir2L12n7ruKg0w6TlXjsJQGTO2e7ztbGEqWVTusq4EWtbgEU4yPSNoZTVWFdCunJ asqb2pmYU8EG+kF8JKeiJ+6YSPw8CDbvYrSLctiNr9SNMMiiBjT07xJfkKzqPtym3eSp eXsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=yv1HNv+auWWTtGIHj8cYxCKVDXHJnHrx+GEc0N8XXUI=; b=oJl0kYRqeSI9mTyNjx15e8hV1ZZC/4gg3bmwRNle+ozFqGGmV0r6szbCG61Or6kjkt BQ8QyOKW314vgK1syFfEdDHQWHh5xJ/bctqrsEPduja81TFDRd93i3Rl+EuIS4EoQppf uO1DDl+imCCXEL4NQ7dZym57Vmt+GieyjpKREdjOPyPbAsm+R2YJ8Pao1WswalRYFIUt bPGRKAbWXiSewcnSUhW0GxML5WYqGCI1S9EP8X2ZEgUotZL1uIW/MUwL8CFLu7Maxvzt 3MkkPQ3xzZz+dmJv28jaLlJNa0RmuZGt6lnbuneuSrXQ3BMo5cT+e3ioh9ihH1u5OTKO AgbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=PpdjXDy1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me17si6686945ejb.258.2020.08.07.20.55.57; Fri, 07 Aug 2020 20:56:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=PpdjXDy1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbgHHDzZ (ORCPT + 99 others); Fri, 7 Aug 2020 23:55:25 -0400 Received: from linux.microsoft.com ([13.77.154.182]:49470 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbgHHDzZ (ORCPT ); Fri, 7 Aug 2020 23:55:25 -0400 Received: by linux.microsoft.com (Postfix, from userid 1046) id 49EBD20B4908; Fri, 7 Aug 2020 20:55:25 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 49EBD20B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1596858925; bh=yv1HNv+auWWTtGIHj8cYxCKVDXHJnHrx+GEc0N8XXUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PpdjXDy1StNRCYJdscNOuDJasjAuyBvq1a5LrNWdEAHy9ao+IphTIEzYm4L/MgoRq Q1bZVnQu3P5khUwSJ2ttjPCrocuczYjLvZVxWPusO2jWo0SybO5Dtf7PUsAlMjSySP Hchpqoukeqyp3mgOPNMBZ41eNGEjtVIcMVFbOoU8= From: Dhananjay Phadke To: f.fainelli@gmail.com Cc: bcm-kernel-feedback-list@broadcom.com, dphadke@linux.microsoft.com, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, rayagonda.kokatanur@broadcom.com, rjui@broadcom.com, wsa@kernel.org Subject: Re: [PATCH v2] i2c: iproc: fix race between client unreg and isr Date: Fri, 7 Aug 2020 20:55:25 -0700 Message-Id: <1596858925-45763-1-git-send-email-dphadke@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <00a30ca7-d533-94ba-994a-9a133fadb045@gmail.com> References: <00a30ca7-d533-94ba-994a-9a133fadb045@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/7/2020, Florian Fainelli wrote: > > When i2c client unregisters, synchronize irq before setting > > iproc_i2c->slave to NULL. > > > > (1) disable_irq() > > (2) Mask event enable bits in control reg > > (3) Erase slave address (avoid further writes to rx fifo) > > (4) Flush tx and rx FIFOs > > (5) Clear pending event (interrupt) bits in status reg > > (6) enable_irq() > > (7) Set client pointer to NULL > > > > > @@ -1091,6 +1091,17 @@ static int bcm_iproc_i2c_unreg_slave(struct i2c_client *slave) > > tmp &= ~BIT(S_CFG_EN_NIC_SMB_ADDR3_SHIFT); > > iproc_i2c_wr_reg(iproc_i2c, S_CFG_SMBUS_ADDR_OFFSET, tmp); > > > > + /* flush TX/RX FIFOs */ > > + tmp = (BIT(S_FIFO_RX_FLUSH_SHIFT) | BIT(S_FIFO_TX_FLUSH_SHIFT)); > > + iproc_i2c_wr_reg(iproc_i2c, S_FIFO_CTRL_OFFSET, tmp); > > + > > + /* clear all pending slave interrupts */ > > + iproc_i2c_wr_reg(iproc_i2c, IS_OFFSET, ISR_MASK_SLAVE); > > + > > + enable_irq(iproc_i2c->irq); > > + > > + iproc_i2c->slave = NULL; > > There is nothing that checks on iproc_i2c->slave being valid within the > interrupt handler, we assume that the pointer is valid which is fin, > however non functional it may be, it may feel more natural to move the > assignment before the enable_irq()? As far as the teardown sequence ensures no more interrupts arrive after enable_irq() and they are enabled only after setting pointer during client register(); checking for NULL in ISR isn't necessary. If The teardown sequence doesn't guarantee quiescing of interrupts, setting NULL before or after enable_irq() is equally vulnerable. Dhananjay