Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp157409ybi; Wed, 29 May 2019 18:40:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0OADdRJSkelyJvHiTF+E+CQDV/i/7hqRDVK/Tevep6pNXgWK8aZz5kLJf6u/ByVWeH/C2 X-Received: by 2002:a17:90a:d14c:: with SMTP id t12mr1064736pjw.120.1559180443071; Wed, 29 May 2019 18:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559180443; cv=none; d=google.com; s=arc-20160816; b=K/C7kXyewppy/JadzREy+zpW0CbjnD8wNMHcxUDK6kPnIQ9oX3bAgZWm8lLV/Fj29P LUSUCNlvqYY3hykm+NtfvtVHA2EiRwwtFmn+Ut6Ebcf7WIkYDv+9cJa0dhUbgdLMmxBO azFi9ml0G9k13Ld5kYhOVDVuhV5egpNJeJGi6UwoROmb+5oFO6l/loWL3WAf7U6l9Cgn jSuCZfKh0m581kTKbb8RCnNtr9xrgFPdeBUly/fjPd1y9UoUknWoREGHyL4qRO4dcziH cuIRfiH3wrt68oHJApLfw9DYpSDcT1FqDyUhIL48Sp6aGelN6nBnBdbaawvuGAFL7ysK eWvg== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=b1Oz21y+/DtwNZeW5wTQFQqoFnacdpivbY1RSYxGSSk=; b=FVy0xcjsZyDkiEgiUto9dOUb4Cww5mTwzVRpxWwxwFrAZZwJO67avuWwyd2u3LwT0H j3HnRfqF2H5FiWuKGLhBVjkoR8fISzXv1x9trZu9AeVPWEvFFe2rs1EO990CDR63thSe 1tRCAq3U1uEqjjZ6jnlrlywp7az+/a6dZYiqV4sCOza8VnGUC06h33Us8s560LYcQjvB t5apcQFQzA8Qz4jeMwgrlNVKvotT5acYMmfKxLFssB8WeB8mrz8xV3tkX21ca1yA4GuL k2h77fT9u2KB/JC45bHbUnWn1PE2qIebCUr1doIsU7iO4DtihjOcWa8cGnQx1e4yCVEC J54g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si1417426pgv.390.2019.05.29.18.40.26; Wed, 29 May 2019 18:40:43 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbfE3BjI (ORCPT + 99 others); Wed, 29 May 2019 21:39:08 -0400 Received: from mga14.intel.com ([192.55.52.115]:7802 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbfE3BjI (ORCPT ); Wed, 29 May 2019 21:39:08 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 May 2019 18:39:07 -0700 X-ExtLoop1: 1 Received: from haiyuewa-mobl.ccr.corp.intel.com (HELO [10.67.64.79]) ([10.67.64.79]) by fmsmga008.fm.intel.com with ESMTP; 29 May 2019 18:39:05 -0700 Subject: Re: [PATCH i2c/slave-mqueue v5] i2c: slave-mqueue: add a slave backend to receive and queue messages To: Eduardo Valentin Cc: wsa@the-dreams.de, brendanhiggins@google.com, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, jarkko.nikula@linux.intel.com, andriy.shevchenko@intel.com, jae.hyun.yoo@linux.intel.com References: <1524503192-4176-1-git-send-email-haiyue.wang@linux.intel.com> <20190523220345.GA3417@u40b0340c692b58f6553c.ant.amazon.com> <35a9d066-c732-cb00-04a5-438c948915ae@linux.intel.com> <20190524173353.GA6428@u40b0340c692b58f6553c.ant.amazon.com> <20190529231100.GA18339@u40b0340c692b58f6553c.ant.amazon.com> From: "Wang, Haiyue" Message-ID: Date: Thu, 30 May 2019 09:39:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190529231100.GA18339@u40b0340c692b58f6553c.ant.amazon.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2019-05-30 07:11, Eduardo Valentin 写道: >>> this code goes access and modify data here, e.g. msg->len and msg->buf. >>> >>> On this case (I2C_SLAVE_WRITE_RECEIVED), this code wont protect access. >>> >>> This can cause concurrence issues if you receive an IRQ when the user >>> is on your bin_read(). >> User will not touch 'msg = mq->curr;', just touch 'msg = >> &mq->queue[mq->out];' > What happens if mq->curr == mq->queue[mq->out]? > 1. The Read will check. + spin_lock_irqsave(&mq->lock, flags); + if (mq->out != mq->in) { + msg = &mq->queue[mq->out]; 2. Flush the oldeast message. ^_^ + case I2C_SLAVE_STOP: + if (unlikely(mq->truncated || msg->len < 2)) + break; + + spin_lock(&mq->lock); + mq->in = MQ_QUEUE_NEXT(mq->in); + mq->curr = &mq->queue[mq->in]; + mq->curr->len = 0; + + /* Flush the oldest message */ + if (mq->out == mq->in) + mq->out = MQ_QUEUE_NEXT(mq->out); + spin_unlock(&mq->lock);