Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp661984ybh; Wed, 22 Jul 2020 09:58:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzN27iuBy5OaOYBBEUtgg8OpdcGP91UgPS5R1k1HnouIrUUhgbJpEJGKXLnY445mH0YAQhT X-Received: by 2002:aa7:dc46:: with SMTP id g6mr396362edu.194.1595437104213; Wed, 22 Jul 2020 09:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595437104; cv=none; d=google.com; s=arc-20160816; b=Lq2a5Lr52lJAjSMP4LvzkaX49QE5o/iS6IP0aeaPuZhxjzePQnM7fLa8GpXP/N0vAl 4FvqzeoLuj18GfJ2SoTV46lgo+lX0y7SsTuIvhxH8P5Dr/gAczRIMcJ6vaoBYU3DAzER 3C5INqZLth52JfhI/lzchtX+pGRBhOzJRAoWKwPCCWX207y2v+MJrfUGuiDqM7jw1XUJ WvMGXfVHPgXqctkjxTLNAtqZDCVbXs5duMFUFYWN20XjWPnn7onqQril3XtyeJzE5NOO xhM/XhBEfEkhppBOZjneNWLp+FLknN4k6IzvftHRRGeF7UsX2rxUQZkyLad8JBjwsj+h AfFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=W/L5P6Wi4l5w5E61NWRVDyen6nCeOgGhib6kkyx3xg4=; b=AWEQZmSRpJh3fcUQQokFzCwB8Vk/gjhxctEV6m/6sksEhLhtMvh1PnaHE9HAt+E9HX SGNad9HVUQNx3NxLioA0hnGt0mHyOS/geaJHnjHdJL0Mir4Cq6ucH7C4RNSwILZUWbk5 JgwUzGjO8ntgpenlUT0IZ2fovQv3+MmvbQBnQctG5rzoVvKK4Wl3x6Rx2Oc1bcJLTNYB Xdu6HdTL+JrgTvS1rl2OebHs7DJhTMatvQ4jS7hRqOpXd5KiCwIeahKLckThb7Wue9wm v0xZ3Rjhsz94zxuQYpFwgn0EZiIKYBzOK9qG+vcCHs5Aw1w0EKX9ai2nk80TmXa6Tvoy BfgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Gug+wemw; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si327692edq.372.2020.07.22.09.58.00; Wed, 22 Jul 2020 09:58:24 -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=@broadcom.com header.s=google header.b=Gug+wemw; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731117AbgGVQz0 (ORCPT + 99 others); Wed, 22 Jul 2020 12:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbgGVQzZ (ORCPT ); Wed, 22 Jul 2020 12:55:25 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20F3BC0619E0 for ; Wed, 22 Jul 2020 09:55:25 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id f7so2601458wrw.1 for ; Wed, 22 Jul 2020 09:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=W/L5P6Wi4l5w5E61NWRVDyen6nCeOgGhib6kkyx3xg4=; b=Gug+wemwkv5z2RLWjjalbOFEuEkFtC0ykSLnBs/RB/j5fl8oDtHwbf+UvDFuur5oO2 iOxEehek0b8oyIZ2hfEEuDtjBhX/77LZob3QNQQLJDNbWXwOq6ZB5E/tOFChQdPhYn/x md2N62uo++EmN2+MfnhZRE3dhfxo1FTGCuV6E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=W/L5P6Wi4l5w5E61NWRVDyen6nCeOgGhib6kkyx3xg4=; b=A0fxsiJ3RVj7XsjD+EB1loHOWJjRzjGnTJYsnRsPkuIqmoCII//G90v8zxT7NhrjwP uYow7LTzfbGjQG6dAtCBEGvWU/eLCocILuE6QrXzcQsSXobK5psI7VY2IPIfeJO9y05R K+SkLhCgXrOnfqls7214PQx6nstvCMkQCnWjzCzN/CNGUmTyRCt+aQFwqMcyCAWvUbdh QEGQv8VhvYQj9bEQUolQQjUxHIx0C7xVAUvs1HdoEpbXDY83DN6xNVSmr9U3hDNhaznt lJNNv1bXOdsM5LNPD1IQypZyyOXZrdW1ikjqWuNq/c2jgui5n2fjIIqfMMfLQ1nVrDYY DqZQ== X-Gm-Message-State: AOAM532bzwEmyKCOBl57LqI6LFa/ZpAsQlaC7m4yozmWnDRQ2r5tum7n Owixgrou98XXjeDrO1yCntJMig== X-Received: by 2002:adf:fd4e:: with SMTP id h14mr434451wrs.251.1595436923597; Wed, 22 Jul 2020 09:55:23 -0700 (PDT) Received: from [10.136.8.242] ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id j8sm565902wrd.85.2020.07.22.09.55.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jul 2020 09:55:22 -0700 (PDT) Subject: Re: [PATCH] i2c: iproc: fix race between client unreg and isr From: Ray Jui To: Wolfram Sang Cc: Dhananjay Phadke , Rayagonda Kokatanur , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Ray Jui , 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> Message-ID: <0995d57c-890c-cdd3-7ddf-ece6bc454528@broadcom.com> Date: Wed, 22 Jul 2020 09:55:17 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <5048cf44-e2c2-ee31-a9fb-b823f16c2c7d@broadcom.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/22/2020 8:51 AM, 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 Actually, thinking about it more, 1. and 2. here need to be an atomic operation so it needs to be wrapped by a spin lock/unlock (and it is safe to do so here before calling synchronize_irq below). Same applies to the two read-modify-write sequneces to enable some of the slave interrupts in the 'bcm_iproc_i2c_slave_isr' routine. > > 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); >>>>