Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp752216rdg; Wed, 11 Oct 2023 04:47:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKpjjrTF1po3n73AYoyyzJtz2C3QafKygMnSmDGJ38Ch16fwWX8G3NGc6QX90jSLlAv9Rx X-Received: by 2002:a05:6a20:258e:b0:159:c24f:5fa4 with SMTP id k14-20020a056a20258e00b00159c24f5fa4mr21227324pzd.1.1697024841377; Wed, 11 Oct 2023 04:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697024841; cv=none; d=google.com; s=arc-20160816; b=FJqbovDe0idGgsGYmii++kic6yRaXAJ/USeMfQzMjtQxeIcd+KHO4WGE4TChz3++UI gLc02Q+BZ7d+E12W4h+ZU5YobJut8UNJRzDUWeZWdaJ192jOASMU52RItmLj1G4SiHHJ C3vNSwUjZpI2LrzgeFCLQ50d95niG3z829+Krhc63bMrQ0HbLnbKmmPUB/rOfw1cTOPA bNFcYlsofj+NyNEswG//JBWu1fXVLxnxH/S/eeUmhKPaUPbDclXsDgbUKMirZcg6pX37 tralLmgVnoxjnnLj1+o8+k2Ulle1BkseqUgsy1V2fduuFK6nL4Z9O8SicMDClDav39kf 97rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :in-reply-to:from:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature:dkim-filter; bh=XGuOkaqyAecoK0JJacf8f1olgpmSUik25eSknsMpW+I=; fh=Q4R+VJu3QVIOZQ8uKnvQiSoeuOU5c+BgO651hJr3zgw=; b=ez+4dB0KyEp3YttsUL1oloCzq+txI7K3WksDrPjvSg9vnlVWrAbaQp8t84EEt9BF4G vFoy8NGiM74i0GIT0kh3kRuLAofXKvYeN96MXSB5uIamlC98GSFcF67T3oyV7WmM3t/n t8ym0G6wCZxZ+7T6yvCud1d8mntTxYar5pl4SsiMZnI/ShyFCPqI5bFKbwGFInCkI6Z6 1ZEwHGtM4v/5DbaDWkXu290kF/gn0yBq7sO8zUxBEaIcpiJbUJefPwgRtIFc/Pj3rKgJ oiKLzv8dsovQqjlydZOv/Bi1MrYDlXqx/c6UKEOP1atu0WVUH6ela2KOcWCvVKjtc5on DonA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TQdKa5NA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k26-20020a6568da000000b00578b9064636si13808221pgt.242.2023.10.11.04.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 04:47:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TQdKa5NA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4E35A81BDF1B; Wed, 11 Oct 2023 04:47:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346062AbjJKLrQ (ORCPT + 99 others); Wed, 11 Oct 2023 07:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234723AbjJKLrO (ORCPT ); Wed, 11 Oct 2023 07:47:14 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7D4A94 for ; Wed, 11 Oct 2023 04:47:11 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231011114707euoutp02cf41786e543c08b39a90d6aef9f10c41~NCxb-fv9X2233722337euoutp028 for ; Wed, 11 Oct 2023 11:47:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231011114707euoutp02cf41786e543c08b39a90d6aef9f10c41~NCxb-fv9X2233722337euoutp028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1697024828; bh=XGuOkaqyAecoK0JJacf8f1olgpmSUik25eSknsMpW+I=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=TQdKa5NAgRFeVOEj/prepUazxBY7i95K1WujW7gJl0T+777ZEMfnpUMMAYMxy1exj PXQlt3lT3q8bvqk3qx+tSMyb9yOIFJRaVOF+8T1DeEtYvimY+fYp/rtXp392sOCBUm jZXGKMBB1m8ibwf++gamwdRXmcVB6uyPO9cyxlVg= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231011114707eucas1p28ac4c13408ce7d01727b2d2c3b48817b~NCxbrv-JR0503505035eucas1p2C; Wed, 11 Oct 2023 11:47:07 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 2F.FB.37758.B3B86256; Wed, 11 Oct 2023 12:47:07 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231011114706eucas1p256d0ce177e0c1f73ab3a052294518341~NCxbB1HbP3267632676eucas1p2W; Wed, 11 Oct 2023 11:47:06 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231011114706eusmtrp1f68c013e058293ea46288de941dd8338~NCxbBSXpC0630706307eusmtrp1X; Wed, 11 Oct 2023 11:47:06 +0000 (GMT) X-AuditID: cbfec7f5-815ff7000002937e-4c-65268b3b9e8b Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 98.5A.10549.A3B86256; Wed, 11 Oct 2023 12:47:06 +0100 (BST) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231011114705eusmtip26e62b69454e4db95963929ad7466f8df~NCxZxqzN71468314683eusmtip2T; Wed, 11 Oct 2023 11:47:05 +0000 (GMT) Message-ID: Date: Wed, 11 Oct 2023 13:47:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] i2c: brcmstb: Add support for atomic transfers Content-Language: en-US To: Gregor Riepl , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Kamal Dasu , Broadcom internal kernel review list , Andi Shyti , Florian Fainelli , Wolfram Sang From: Marek Szyprowski In-Reply-To: Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGKsWRmVeSWpSXmKPExsWy7djP87rW3WqpBkumqlrc/9rBaLG29yiL xbpt95gtdm84zGSx6fE1VouOv18YLS7vmsNm0du9n83i7v65jA6cHrPun2Xz2DnrLrvHplWd bB6bl9R7fN4kF8AaxWWTkpqTWZZapG+XwJVx520bc0GfQMXv2edYGxhbeLsYOTkkBEwkVv+6 wtTFyMUhJLCCUWLCwW9sIAkhgS+MEhcWqUEkPjNKtN5fzNrFyAHWMXV9FER8OaPE1APXG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mtlZKqkb2eTkpqT WZZapG+XoJdx520bc0GfQMXv2edYGxhbeLsYOTgkBEwkpq6P6mLk4hASWMooMf3VTeYuRk6g uIzEyWkNrBC2sMSfa11sEEXvGSX+be4BS/AK2EnM/ruBDWQQi4CqxKTFRhBhQYmTM5+wgNii AvIS92/NYAexhQWcJT43X2AEsZkFxCVuPZnPBDJTRKCVUeJIy2ywBcwCnxklHvacZ4TYdoxR 4v3Hu2Cj2AQMJbregpzBycEpYCtx63Q7K8QoM4murV1QY+UlmrfOZp7AKDQLySWzkGychaRl FpKWBYwsqxhFUkuLc9Nziw31ihNzi0vz0vWS83M3MQIjcduxn5t3MM579VHvECMTB+MhRgkO ZiUR3keZKqlCvCmJlVWpRfnxRaU5qcWHGE2BoTGRWUo0OR+YCvJK4g3NDEwNTcwsDUwtzYyV xHk9CzoShQTSE0tSs1NTC1KLYPqYODilGpgEP902MqudGFPL+6xieusMubV78/eG3NlUvOOT S/1ytWv+n7p5qg39HNIrru0V3u38NTiIXYdx/crnJ8vkZ56K8J3AscE6ecXEeWXzqtNyOIUT 2Gof8f4v7uB28EveZl98YvubhLz8tFtsdZnXXzYwlpQ0iD1sKt+QlvB5+uMElijOZsmCJcfn N998waX/Nn+T+c9uTu1jzX2P9XldxCrmZEq4pP1InL7hstZWD8/giXenLb6y4lcKRwl3I0OK yNvby+evK5WQ2XmpRlR16v6QOQFvW2t0jqXEp/9fYBh6ZWbhi81xay3seVJmq4Ts0e6ZPVmt qXZ3m8qMixMnvsz8GGegKmll9vfVpWNnDyixFGckGmoxFxUnAgAes9omTQMAAA== X-CMS-MailID: 20231011114706eucas1p256d0ce177e0c1f73ab3a052294518341 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20231006144123eucas1p111cbbdbd70927ffbd697f7edf6b7ae1c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231006144123eucas1p111cbbdbd70927ffbd697f7edf6b7ae1c References: <20231006144117.4079796-1-m.szyprowski@samsung.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 04:47:20 -0700 (PDT) On 11.10.2023 12:23, Gregor Riepl wrote: > I admit that I don't understand the I²C subsystem very well, but > doesn't this introduce a potential race condition? > > > ... > > @@ -240,7 +241,7 @@ static int > brcmstb_i2c_wait_for_completion(struct brcmstb_i2c_dev *dev) > > ... >> -    if (dev->irq >= 0) { >> +    if (dev->irq >= 0 && !dev->atomic) { > > ... > > @@ -287,7 +288,7 @@ static int brcmstb_send_i2c_cmd(struct > brcmstb_i2c_dev *dev, > > ... >> -    if (dev->irq >= 0) >> +    if (dev->irq >= 0 && !dev->atomic) > > ... > > +static int brcmstb_i2c_xfer_atomic(struct i2c_adapter *adapter, > > +                   struct i2c_msg msgs[], int num) > > ... >> +    dev->atomic = true; >> +    ret = brcmstb_i2c_xfer(adapter, msgs, num); >> +    dev->atomic = false; >> ... > > What happens when one of the if() branches is taken in one thread > while another thread is just executing the assignment of the atomic > flag? My expectation would be that the first tread still sees the old > flag value and happily executes the branch, while > brcmstb_i2c_xfer_atomic() sets the flag just after and initiates a > transfer. > > I'd expect that access to the flag must be atomic as well, so maybe > something like > https://www.kernel.org/doc/html/latest/core-api/wrappers/atomic_t.html > is needed, or some other synchronization mechanism. > > Or is it guaranteed that brcmstb_i2c_wait_for_completion() and > brcmstb_send_i2c_cmd() can only be called from the same thread as > brcmstb_i2c_xfer_atomic() ? Atomic i2c transfers are some kind of a special case. I guess that i2c core takes care of NOT multiplexing atomic and standard i2c transfers. No special locking/protection is needed in the bus drivers. This is at least what I see from commits like 08960b022fb6 ("i2c: tegra-bpmp: convert to use new atomic callbacks") or 3d11a12ece85 ("i2c: ocores: enable atomic xfers"). Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland