Received: by 10.223.148.5 with SMTP id 5csp6655664wrq; Wed, 17 Jan 2018 16:58:42 -0800 (PST) X-Google-Smtp-Source: ACJfBoueK6t1wCQoX2KC0W29KoGcUQCR3vdktgBecCfoSUb2qBxHdTl/DUyy7nbUH5saCLxLIp7i X-Received: by 10.84.235.131 with SMTP id p3mr20167346plk.18.1516237122124; Wed, 17 Jan 2018 16:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516237122; cv=none; d=google.com; s=arc-20160816; b=RK9MKPZdDATaIRG23tNx3JGudW82QTG+pA6ptkoN2FSse3A5s1FjlYjUd3m0eTxZ7/ MrN3K5y5EP463y2S1yzXgGa1DF9iQxUc3lkpcU/5WSkUPCqvywDFetqSmTPOKew5FkAj VEARntQ5vNIFwjHjH5Kipurz9MbldNizOx2bQJzAxbgy6UzUC6HZ8ATka4uSBZK+1nSl oNHcSpF+CjiQ5qu4Mgit+GTWKEdY3TonecZt7kBg8FiuX+Vo2aoNmnfmd1xYgonX7nPe Ej+dQeFGiBEYA5tGdg0yaEaiXOOUOnp+63/+pF6qYyQwzNsiCfzhRK+ogbzBIaqB8PFQ l5sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=nGC7VS8Rn+O0GOtbgvhoaWH87SbrgPB2/QrjOpTcMeo=; b=FQfbN5GkA0lQHzqWJVVmvtQ+Ixt+GcHag3a9DIC3yhWdU/4L0wvCAuZ36yhhrUDZpE EPkxI6Uqo7tlRtiY+zFAuN7nSysZmOhANjhSN590xsOk9SmMEOplkKLSRe1l3zDYUg9d wN9UYYBUu2gbjSALJeai0DZAaAhIw7BWJ3VndbRbrbg3XRRdwVKHhyuMkpN1EQsUkiez fEIhSEMfoLzn9ROmrDLn+geRVfb4h+k7AuVg/11nZME+sgcQETiwRvYW9Qt4n/FM4fTa ildt6rjHEWAGUw20+Q/Tuklh497YBlkzp6HRNupi8Haq0pup5ctjrwcWZjuOj1q21Icj qZ6w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10si5454647pff.290.2018.01.17.16.58.19; Wed, 17 Jan 2018 16:58:42 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753908AbeARA5q (ORCPT + 99 others); Wed, 17 Jan 2018 19:57:46 -0500 Received: from mga01.intel.com ([192.55.52.88]:17341 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753054AbeARA5p (ORCPT ); Wed, 17 Jan 2018 19:57:45 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jan 2018 16:57:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,374,1511856000"; d="scan'208";a="22570824" Received: from haiyuewa-mobl1.ccr.corp.intel.com (HELO [10.239.196.40]) ([10.239.196.40]) by fmsmga004.fm.intel.com with ESMTP; 17 Jan 2018 16:57:43 -0800 Subject: Re: [PATCH arm/aspeed/ast2500 v1] ipmi: add an Aspeed KCS IPMI BMC driver To: minyard@acm.org, joel@jms.id.au, openbmc@lists.ozlabs.org, openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: andriy.shevchenko@intel.com References: <1516103023-19244-1-git-send-email-haiyue.wang@linux.intel.com> <54c6562b-f35a-c616-b6c2-a2eadf6937da@acm.org> From: "Wang, Haiyue" Message-ID: <39da73d5-23da-c2b3-7fd2-b9c6c7e293ac@linux.intel.com> Date: Thu, 18 Jan 2018 08:57:43 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-01-18 00:31, Corey Minyard wrote: > On 01/17/2018 08:31 AM, Wang, Haiyue wrote: >> >> > > Snip... > >>>>> >>>>> + >>>>> +struct kcs_bmc { >>>>> +    struct regmap *map; >>>>> +    spinlock_t     lock; >>>> >>>> This lock is only used in threads, as far as I can tell. Couldn't >>>> it just be a normal mutex? >>>> But more on this later. >>>> >> I missed this lock using in KCS ISR function, for AST2500 is single >> core CPU. The critical data such as >> data_in_avail is shared between ISR and user thread, spinlock_t >> related API should be the right one ? >> especially for SMP ? >> > > Sort of.  In the case below, you need to use spin_lock_irqsave(), you > don't necessarily get > here with interrupts disabled. > > In the ones called from user context, you should really use > spin_lock_irq().  Interrupts > should always be on at that point, so it's better. > Understood, will change it with the right API call. >> static irqreturn_t kcs_bmc_irq(int irq, void *arg) >> { >>     .... >>     spin_lock(&kcs_bmc->lock);  // <-- MISSED >> >>     switch (sts) { >>     case KCS_STR_IBF | KCS_STR_CMD_DAT: >>         kcs_rx_cmd(kcs_bmc); >>         break; >> >>     case KCS_STR_IBF: >>         kcs_rx_data(kcs_bmc); >>         break; >> >>     default: >>         ret = IRQ_NONE; >>         break; >>     } >> >>     spin_unlock(&kcs_bmc->lock); // <-- MISSED >> >>     return ret; >> } >> >> > >>>>> + spin_lock_irqsave(&kcs_bmc->lock, flags); >>>>> +    if (kcs_bmc->kcs_phase == KCS_PHASE_READ) { >>>> >>>> If you don't modify kcs_phase here, you have a race condition. You >>>> probably >>>> need a KCS_WAIT_READ condition.  Also, the nomenclature of "read" >>>> and "write" >>>> here is a little confusing, since your phases are from the host's >>>> point of view, >>>> not this driver's point of view.  You might want to document that >>>> explicitly. >>>> >> The race condition means that the user MAY write the duplicated >> response ? > > Not exactly.  Two threads can call this, and if it hasn't transitions > from the read phase, > the data out will be overwritten. > OK, will add new state KCS_WAIT_READ handling.