Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp913955imm; Fri, 11 May 2018 08:15:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZovKAlgzUGuqB+FQ3M+rW68dV9WfhSwc7Vm8Q2M72SkTI5grYq1UHYV428+MQs49e8cJMvA X-Received: by 2002:a17:902:6b0c:: with SMTP id o12-v6mr5812756plk.159.1526051702331; Fri, 11 May 2018 08:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526051702; cv=none; d=google.com; s=arc-20160816; b=MagLxZTVfGEsLquAdyOB85056nvP7jOZA2VCitYSWRxa0r8mcbODNfEb+RIeTCTWN9 O9TQ5JzXuik4UpijNkKFlEUOqbXm+Vn2gYVP5a6T+Va4LmScnicsyEpgqINZw8whNGXf KQSeHnKeSV0AVEL4kpUg6izJRvUWzxqbwANUR27sQ0ebzJORuBwwQo6kFGn/vWMu2qXs D3S+BANk/u2920E+Ih7ErFvUjMj8j8bfBy5vNTTMoU76rsiTQADUHSF5vHTw/7+KMHYd QiPiceBCZINiD3R43VgWs0+ZiWwqzE9wLj/xzSEUEeabLTxwjWOGkqyNeI0V+C4kN4E7 hMBg== 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:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=L9+idRl0WU8oKcx1dpsmDCHynGGI+3djC92iRaSVZbE=; b=t1E1ULSKpAoX2QXxUC7PJMpEjL4Z+r0W4kogjgRh7pKHNLrHHUtyLYU7b9nj1MfvFA M6ye/JJi9diXa7wKvzG+g0zsLJtJsIN3Ut0vOzYHHQIXuxLUfGxN8SkafaF7/upiDFWn udp5ARdzmNp+4XF/tWa035H5sYqcCPHUjGCeDacYK64TRC2WbUYQlri3H515yXKXsmaa y3FHRKeTWYDBILVK3mVW7YB6gl6Ejx2Bu2fh1M6iHtjvcHCJjNMM47Co11MQac3viCKC tI+XCFGYxZ2yT8n1KZwfYW7w71vABI5HK2UcZ3kK4IS8FNf1d4N5iRfwzANcb6z+bA5l pniw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=T83TdvGS; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14-v6si3448637plr.131.2018.05.11.08.14.47; Fri, 11 May 2018 08:15:02 -0700 (PDT) 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=@ti.com header.s=ti-com-17Q1 header.b=T83TdvGS; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751333AbeEKPOa (ORCPT + 99 others); Fri, 11 May 2018 11:14:30 -0400 Received: from lelnx193.ext.ti.com ([198.47.27.77]:40263 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750722AbeEKPO2 (ORCPT ); Fri, 11 May 2018 11:14:28 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id w4BFENd6016068; Fri, 11 May 2018 10:14:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1526051663; bh=L9+idRl0WU8oKcx1dpsmDCHynGGI+3djC92iRaSVZbE=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=T83TdvGSVm+rt9p9CU0nwMfic1HSeuT5ueQ6/19Y/oJ32HGarE9kmA7Oq6WH716Mi lk7a7XXzf8h+6h6k1zoziRKkN8LI+cWjKY1goRmIfiTlBphlCBGHVRoUw5Rh6kNrJl FN+ImSGTukjcXg3wozcCCgTY1OAKUXpdt+oZ0mh0= Received: from DLEE110.ent.ti.com (dlee110.ent.ti.com [157.170.170.21]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4BFENca023155; Fri, 11 May 2018 10:14:23 -0500 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 11 May 2018 10:14:23 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 11 May 2018 10:14:23 -0500 Received: from [128.247.59.147] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w4BFENFX019322; Fri, 11 May 2018 10:14:23 -0500 Subject: Re: I2C PM overhaul needed? (Re: [PATCH 1/2] i2c: sprd: Prevent i2c accesses after suspend is called) To: Wolfram Sang CC: Baolin Wang , Mark Brown , , LKML References: <99031524fa147e72451d26f54b24f36093c0d3fa.1523255712.git.baolin.wang@linaro.org> <20180427121417.auv4ppryegkprv32@ninjato> <20180502052336.i5f4yv2ho3za7qa7@tetsubishi> <3485f73f-e356-6db0-89fc-d51bf8bdab71@ti.com> <20180504122447.u3xgrkperxz5dpcz@ninjato> <20180508163221.2slrtg3cidvpj7g2@ninjato> From: Grygorii Strashko Message-ID: Date: Fri, 11 May 2018 10:14:23 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180508163221.2slrtg3cidvpj7g2@ninjato> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/08/2018 11:32 AM, Wolfram Sang wrote: > Grygorii, > > thanks a lot for your input. Much appreciated! > >> That would be great, but note: >> 1) only i2c_transfer() operations are locked, so if driver is doing >> i2c_transfer(1) >> i2c_transfer(2) <- suspend in the middle >> <- suspend in between >> i2c_transfer(3) >> It will not help. > > Will it not improve the situation by ensuring that at least the transfer > with its (potenitally) multiple messages got completed? That we are at > least in a bus-free state (assuming single-master here) before > suspending? > >> Everything depends on timings :( - in my practice 10000 suspend iteration tests >> where required to run many times to catch 3 buggy I2C client drivers. > > Matches my experiences that creating a reliable test case for that is > not that easy as I thought. Or I am missing something obvious. > >> 2) It's normal to abort suspend if system is busy, so if I2C core will be able >> to catch active I2C operation - it should abort, but again I do not see how it >> can be detected 100% with current I2C core design or without reworking huge number of drivers. > > I agree. After second thought, waiting for i2c_transfer to finish maybe > won't be enough, I am afraid. We don't know if STOP has been put on the > wires yet. My best bet now is that we implement such a > 'is-transfer-ongoing'-check in the suspend function of the master > driver? That check should be optional, but recommended. > >> 3) So, only one thing I2C core potentially can do - catch invalid access and >> report it. "wait for transfer to finish" wouldn't work as for me. > > And we do this in suspend_noirq function of the i2c core. > >>> I at least know of some Renesas boards which needed the I2C connected >>> PMIC to do a system reset (not sure about suspend, need to recheck >>> that). That still today causes problems because interrupts are disabled >>> then. >> >> this was triggered few times already (sry, don't have links), as of now, >> and as I know, the only ways to W/A this is: >> - to create barametal platform driver (some time in ASM) >> - or delegate final suspend operation to another system controller (co-processor), >> as example TI am335x SoCs, >> - or implement I2C driver in hw - TI AVS/SmartReflex. > > Yes. Please note that this is only needed for reset, not suspend. So, it > is a bit easier. Still, it might make more sense to use a platform based > solution. I'll think about that. > >> Sry, but 99% percent of I2C client drivers *should not* access I2C bus after >> .suspend_noirq() stage it's BUG-BUG!! Any W/A will just hide real problems. > > I do believe you, still is there documentation about such things? I like > to understand more but didn't dig up something up to now. E.g. I grepped > for "noirq" in Documentation/power. > >> "master_xfer_irqless" might be a not bad idea, but, in my opinion, it >> should be used explicitly by platform code only, and each usage should >> be proved to exist. > > Yes, we can think about it once it is really needed. > >> Some additional info: > > Thanks a lot for that! > >> I'm attaching some very old patch (don't ask me why it was not sent :() >> I did for Android system - which likes suspend very much. Some >> part of below diff are obsolete now (like omap_i2c_suspend()), >> but .noirq() callback are still valid and can show over all idea. >> Really helped to catch min 3 buggy client drivers with timers, delayed >> or periodic works. > > Ok, so what do you think about my plan to: > > 1) encourage drivers to check if there is still an ongoing transfer in > their .suspend function (or the core can do that, too, if we agree that > checking for a taken adapter lock is sufficient) > > -> to ensure transfers don't get interrupted in the middle It probably should be part of .suspend_noirq() also. > > 2) use a .suspend_noirq callback in i2c_bus_type.pm to reject and WARN > about transfers still going on in that phase > > -> this ensures that buggy drivers are caught > > 3) write some documentation about our findings / assumptions / > recommendations to a file in Documentation/i2c/ > > -> this ensures we won't forget why we did things like they are ;) > > ? Sry, for delayed reply. It sounds good. -- regards, -grygorii