Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp941896ybh; Wed, 22 Jul 2020 18:01:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgPCM9kanZUts2XAeH8U+8WFc6OH+ZJrV0IXPU1GbmYgd/Ess+3uDgB6G4ExEnyA9UjAV3 X-Received: by 2002:a05:6402:1494:: with SMTP id e20mr1960224edv.2.1595466077562; Wed, 22 Jul 2020 18:01:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595466077; cv=none; d=google.com; s=arc-20160816; b=RmFACnt1XBGbJPNymjdy8RJe+eCspR8LGtLATPyV9ts9gcSnyr1hxey0J6WdKqFC0/ 22+6VKRYcgFCXHQ0YWitTb9VGbtMprQ19xDJC4fia/k8rKD226EKL+A8lAj1+FdoF4l2 nbw/oq6JBu3KlyccPJclggjoXYJQGJaQqEPhYAx4y6TJEUzHvP8w/hYGv4JI6ie77Unf P4Q3/6BBPpqKeCpJ3QoDyyzET4jP7Y56lkU0Z6eJdoWt8Snw5tuLAzXenqAInTUk6gyV bhp+/e4z7m0B1PhuAaYFYbRclbNz2ZJeyLEvgAnACeLIoZm7KUP5hOAOiJVLz2PrMJNc o1wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:from:message-id:content-transfer-encoding :mime-version:user-agent:in-reply-to:references:cc:subject:to:date :dkim-signature:dkim-filter; bh=COad48i7F7Ppim6j74aTQgCPv4ntgv9CarhdXkZqMSI=; b=k9e+EImC41Nn6ohKIxSgnqEYlF1KI5SMgqCADipo3lagD1N5BA9zrtyzGeJFMIfWT5 jCV2UT35Y6qaWolomY/zlCThxGWxETJdr7riRnC8F+vznvVUrt4sAs/1ArYHkBpLgEmR Zm5DxHo2EcXoNglxdNHp6OfJLu/72shQV0ju3Y0i4mN1PUTzKnNO5TnZMgc2C++lDLUU M/o3qR1EAEHnit2eHrqS0QpS9Vdavwv2n5mx8dSFUvjcWO2uC/CiGM7/RgFGC50a6l/Y EZqAIJN555BMZaemyiUyIc22zReKa0D9f4sLKSqPzaEi3BqRrB1Fi8O/nWDsHSoziRHR M6UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=niMgtu2U; 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 s5si1012419ejx.28.2020.07.22.18.00.55; Wed, 22 Jul 2020 18:01:17 -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=niMgtu2U; 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 S2387451AbgGWA6p (ORCPT + 99 others); Wed, 22 Jul 2020 20:58:45 -0400 Received: from linux.microsoft.com ([13.77.154.182]:58652 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbgGWA6p (ORCPT ); Wed, 22 Jul 2020 20:58:45 -0400 Received: by linux.microsoft.com (Postfix, from userid 1046) id D288C20B4908; Wed, 22 Jul 2020 17:58:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D288C20B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1595465924; bh=COad48i7F7Ppim6j74aTQgCPv4ntgv9CarhdXkZqMSI=; h=Date:To:Subject:Cc:References:In-Reply-To:From:From; b=niMgtu2U1MhpmWIEO3cGbPKV10cWPPsqIFr07inBG1vKDl0zmHzqzlc8qrAmggp2N 5mGg9NdqEaGD+eIpTEWZ0ouRM1eH5z9gQbJNjRSwV9FBMxtwI2d29qezbxuw6rvMwg +KIyK7esmDdlGvp/2oHrdVwlXhUvjNel8nOaNzEg= Date: Wed, 22 Jul 2020 17:58:43 -0700 To: wsa@kernel.org, ray.jui@broadcom.com Subject: Re: [PATCH] i2c: iproc: fix race between client unreg and isr Cc: rjui@broadcom.com, rayagonda.kokatanur@broadcom.com, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, dphadke@linux.microsoft.com, bcm-kernel-feedback-list@broadcom.com References: <1595115599-100054-1-git-send-email-dphadke@linux.microsoft.com> <116ac90c-8b49-ca89-90a4-9a28f43a7c50@broadcom.com> <20200722104128.GK1030@ninjato> <5048cf44-e2c2-ee31-a9fb-b823f16c2c7d@broadcom.com> In-Reply-To: <5048cf44-e2c2-ee31-a9fb-b823f16c2c7d@broadcom.com> User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20200723005844.D288C20B4908@linux.microsoft.com> From: dphadke@linux.microsoft.com (Dhananjay Phadke) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ray Jui wrote: > > On 7/22/2020 3:41 AM, Wolfram Sang wrote: > > > >>> + synchronize_irq(iproc_i2c->irq); > >> > >> If one takes a look at the I2C slave ISR routine, there are places where > >> IRQ can be re-enabled in the ISR itself. What happens after we mask all > >> slave interrupt and when 'synchronize_irq' is called, which I suppose is > >> meant to wait for inflight interrupt to finish where there's a chance > >> the interrupt can be re-enable again? How is one supposed to deal with that? > > > > I encountered the same problem with the i2c-rcar driver before I left > > for my holidays. > > > > I think the following sequence needs to be implemented to make this > safe, i.e., after 'synchronize_irq', no further slave interrupt will be > fired. > > In 'bcm_iproc_i2c_unreg_slave': > > 1. Set an atomic variable 'unreg_slave' (I'm bad in names so please come > up with a better name than this) > > 2. Disable all slave interrupts > > 3. synchronize_irq > > 4. Set slave to NULL > > 5. Erase slave addresses > > In the ISR routine, it should always check against 'unreg_slave' before > enabling any slave interrupt. If 'unreg_slave' is set, no slave > interrupt should be re-enabled from within the ISR. > > I think the above sequence can ensure no further slave interrupt after > 'synchronize_irq'. I suggested using an atomic variable instead of > variable + spinlock due to the way how sync irq works, i.e., "If you use > this function while holding a resource the IRQ handler may need you will > deadlock.". > > Thanks, > > Ray > > >>> + iproc_i2c->slave = NULL; > >>> + > >>> /* Erase the slave address programmed */ > >>> tmp = iproc_i2c_rd_reg(iproc_i2c, S_CFG_SMBUS_ADDR_OFFSET); > >>> tmp &= ~BIT(S_CFG_EN_NIC_SMB_ADDR3_SHIFT); > >>>