Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp707990rdg; Wed, 11 Oct 2023 03:24:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHj1V57LnT/h5CxerfyxOcDQ4LXfaEJ/isEPnStaxmb5DyeSzNv142MeC/815CYX2t9P87D X-Received: by 2002:a05:6a21:628:b0:171:6b28:75c5 with SMTP id ll40-20020a056a21062800b001716b2875c5mr5202019pzb.56.1697019850392; Wed, 11 Oct 2023 03:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697019850; cv=none; d=google.com; s=arc-20160816; b=rArZzANFmBo2N/osvLGLFG3JRBIJwfxCOHfm8QyzY0DhuyP7wosgYmgse0oTQBltfc TdWM+Sf6ARXK5L681A9aC8Z7oYX2NFRHlIAJZ7rqE8L12lj1ZKZs7YLVf2IWoECpeD/X QhSC00OEheRRBF+o76wft5q8TUY+eVuRj+36kcLEzo1YNJKdNRVpMZPfwB4IuLE3YZj+ 53dVGPaB0gUkxP4nfd80DmQryFVLfPGY3sy9XvWjL7gHqPouX22WhtUcRoXTVNhJNhIe U1UXISeSKbrWfm3OJNNpUDcmPGQwQcWebYlsK55UZk4kpnupvO6RyOr5ZjvwXlq55f/M XIUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:content-language:references:cc:to:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=bX+yrAuVDTEDKkc7P0hOKfzpwI5t1BU6OZLf3VDs9ao=; fh=CYwrodkZyOnLzw3K/6c2/c0HGft8W3KA7RhrZqeOx5s=; b=i6ALpcmQ8sWK4kI/rcVMVbr6rVAEx9sy+nIhts4N81wqPfLEIwjux4UHHZHxxjGPxl zFY1lRp9E4+Yct9IQ4q6gp2+6o41B5BDlwr5q2yFCLTf/BdkirkqH4lxs/ePLJoNQjSY J/MaDunMdai/x+0Oqz16sVA7GqXmHJcjZyCWGPcko94l80eninoQXavL7pFHJUMrFipk 5y3tRDXzl+DE9rRhDOdcCcIX0W0jr3U9dirXSG+Okwp6DWSzIHosIcjQUjcV2wEp48E/ VCGVRIVAcZM7gU0jvKB/QhnVdPSdjxFaa9/gGhwVK0Es9b0SMvxjzLrfLfyUt5b/g5yw lfAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FS2cGOrK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id kw14-20020a170902f90e00b001c72c893ad0si13349628plb.48.2023.10.11.03.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 03:24:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FS2cGOrK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 438698020939; Wed, 11 Oct 2023 03:24:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234686AbjJKKXk (ORCPT + 99 others); Wed, 11 Oct 2023 06:23:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231628AbjJKKXh (ORCPT ); Wed, 11 Oct 2023 06:23:37 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4AFB0; Wed, 11 Oct 2023 03:23:35 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-405497850dbso61556505e9.0; Wed, 11 Oct 2023 03:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697019814; x=1697624614; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=bX+yrAuVDTEDKkc7P0hOKfzpwI5t1BU6OZLf3VDs9ao=; b=FS2cGOrKfi8VkcP2/nRVGaQ18DieQWSXkyQ2aZ/47vav+7df78GY53/I+3f8dqhG8Y 3AgTHHSGC1S45LrtXgl7yskO9OaL8er8vmbZ9llGCnlsjSWILQxHZ4T7NTMNwzMMmsV3 Du60voNV5eFQljR4+aNzLfLcWjx4/b30m0Yr4uwN2OSreRsdaNl0jnfns4VTEd4pvEDx 9D9HJSrRs52fM8XQU2bCgpWdOLGXxY4HJqJow4GOtREGKSBON/44M9ASH3qL2Kn/oGrU N3+QZJYwmzoMhnToTOVYDYpFKYmix9mu3ZJs1SNKLA/Ib3n20IZ0V9Ou4HYr2/CwJ6sK RW4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697019814; x=1697624614; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bX+yrAuVDTEDKkc7P0hOKfzpwI5t1BU6OZLf3VDs9ao=; b=U3WkmYw8Mog7/FpXYu6c/L0BsFg2D04NBM+E+k6K/TO7Z1ssyfQsNQJxmXcyZME/67 mmeSkN8ecNwxxmye/t/J6uYgftEssyGHdDOTtCr7XO13VZOx55A3SA2+2F77rdoY6vOA ZGLVO0QEB3cwcPscUS2id04wdISBatpcrSLiZrVVJYbu3PBPwfeMqi7SUoGPuhgnXlNc c2Voc/Ny398VUUDB1trVMJk7uwfktJDRfXko2jXkfnrPDdS/aKgXFZastKXSS/xGi8eL C42Dho7BJiMxATT8qKl/2HTz2XxxHpLYEDGJnXIrJy3/zhftto5DzFt33VHnX4LeNem5 +RiA== X-Gm-Message-State: AOJu0YxPsI3+eJsbugwuv4uAQD9kO7X804JeIXm1AmBVDxzlwZ8edhdS VIGR+PaGf0WrtoxaKgzlSv7w1TQkiScZR3jr X-Received: by 2002:a05:600c:1e28:b0:407:5b7c:2f6a with SMTP id ay40-20020a05600c1e2800b004075b7c2f6amr2510587wmb.0.1697019813855; Wed, 11 Oct 2023 03:23:33 -0700 (PDT) Received: from ?IPV6:2a02:168:575a:b00b:10e9:ac6e:518d:a489? ([2a02:168:575a:b00b:10e9:ac6e:518d:a489]) by smtp.googlemail.com with ESMTPSA id v10-20020a05600c470a00b00407460234f9sm11116659wmo.21.2023.10.11.03.23.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 03:23:33 -0700 (PDT) Message-ID: Date: Wed, 11 Oct 2023 12:23:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] i2c: brcmstb: Add support for atomic transfers To: Marek Szyprowski , 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 References: <20231006144117.4079796-1-m.szyprowski@samsung.com> Content-Language: en-US, de-CH, fr-CH From: Gregor Riepl Autocrypt: addr=onitake@gmail.com; keydata= xsFNBFRqKQQBEACvTLgUh15kgWID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hr7jqlkEl6MVhOeLYvtHtT6bjtXcLcmH7lkjqEouEteRTVLjTBA3N7zYN+eg5 QY76YGH6vDJIzau2noYxByYLABEBAAHCwXwEGAEKACYCGwwWIQQ+Q4V0cRHn5D8UutyyNQ/5 1RtZpwUCY4/ROQUJEugPNQAKCRCyNQ/51RtZp6i6D/9XbncsEOnaWQNC3ukmy19Ho+Em23uh TwchU0FGGYL5APRsUFzeS5g2f/gza3oBcW2JmcLETWkae7QnXj46ujCxePij3CTO01ZUjdVR P4hmPsIUVZEgQlw1ueM1QCpXjOc2abC31C1LKd/I2sIAETuu3pMvOpACXtyspBEiVvNoK5Wu gjQLktZwdjEbadSa6VUaHxsmn6tjqYq7T3CLlTXtMGpaj1/kY1QF/jpB0l+ZY7d1R+2mfylm SLhifR31zJjj/FqISDUf253MftZGvMEDMzyxX08oFRq3EM/B3MZLIKyk+IJDw3gH9jsRB3Z/ iTsQSvOwYYFFyIm6w0yyuPhk4HKjzC0HKqLLwq8GiFNpIMkYLfQWfdRLO3TASqWPPdySP4NO gJK6XYeRDF39qo493q4Klgym5HUDibpJ1heNLGQhojNoAV7YX5Pc/Rnoi7qxO/Wdb4vdG8BW e4t3UaDs0pRVghO+VnP7lxyYsnPgeHDKhUBDNM97bWVkfHZDgeD50wpynCWrl0IFveZAZaJG a0cmtan5CnxHkscTFmQN3xr+y2/GaQm37qc/Xdeynknu2idbWlV5wc/9cKuIKxPbyQ7tCSVw OJnKk5hmCyPRlBg4QACPP62jE7o1s05l7aPeMhYJOhJYKprkIBqPheyloQD0qYssenz3XZHE DMcsQA== In-Reply-To: <20231006144117.4079796-1-m.szyprowski@samsung.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Wed, 11 Oct 2023 03:24:07 -0700 (PDT) X-Spam-Level: ** Hi, 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() ? Regards, Gregor