Received: by 10.192.165.148 with SMTP id m20csp5143307imm; Tue, 1 May 2018 09:46:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrEklNFtxL0psZh4o+qWE0AZLn+67/l/dohn2m1TbyfrXKPYG4cxBozeg9hukpz7dTCskV8 X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr6735201plt.378.1525193175976; Tue, 01 May 2018 09:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525193175; cv=none; d=google.com; s=arc-20160816; b=uknj8AKwv6YK5lGnUzVhnLpKsVBGOVyTwSa4L4JLeXHerXlMoLiNEBtLh3buazANSc JLcA8Vm3cMP66NTT9W/PQYpO1TeYKWvYU1fUVqfR/EDYPEwsddKmQFloijUr+vzbKq6K o3rMSqZusQ+45gQng9oXnPLxCYTYnYoJF+V/47wKrm2WNOynpfRq24eJTdjBKKTX9nGy 0QuzpjgCOFgHSlMbgO/42TFz7Wys6+OEqHdrF6iTEY9mDmupGqNHWHXfc8dIPkZjceA6 7/hWTu2uJPp00GxpD82lJoYbh8bidSHUYzrwm5LEj6AlSGi849iwhmLvdvctXYAzwT0l Hf8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=fLDWotd+HjLOkcaivceD3JN+d74vJu2VbqBS5gTQN+E=; b=l6l7tL/uOXRLQtbs2ci6vK0y2wl1RcRnuM+Jg8g8417CUpaZWolEwYiBHM8xz3mHhD T0vTqwmQyaS1XW+fVlM33KTGKg9cOibpdSF7X1s7vnClVhkX5oqpIA6fW3edRD3KoSSr QGiYBxoV9jv0ysg0e4M4xvLmLXD5Mi+418WlPrgt+nImpGVNNad5skuQFEHtpGrZkYHf y+UlyivijIfsTnwgn/fRC6oyCApsMjpz8UcoJxgHKB4uGwGKmxGSLkIEO6I58fB2CipX 96uf8ewT4/dO0stZsGlV+/togsWKgY/p/zlTe5KDfXcVue19d513iSbijx3JO+P4KRy/ 7Euw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Z1odwAaq; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e125si9726885pfg.112.2018.05.01.09.46.01; Tue, 01 May 2018 09:46:15 -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=@chromium.org header.s=google header.b=Z1odwAaq; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756125AbeEAQpi (ORCPT + 99 others); Tue, 1 May 2018 12:45:38 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:45541 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753878AbeEAQpg (ORCPT ); Tue, 1 May 2018 12:45:36 -0400 Received: by mail-pf0-f172.google.com with SMTP id c10so9471429pfi.12 for ; Tue, 01 May 2018 09:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fLDWotd+HjLOkcaivceD3JN+d74vJu2VbqBS5gTQN+E=; b=Z1odwAaqLw9mTUl5X9FHXFCQMOxkMUXc2oQ8KDRqi5s4vjiup2CKr24QHRbUwPB+YQ +AnZ3hOKWd3YkkNcjBdyPcrnW2akPSeE1SKFwYos1NjpjaOP8jdFuxTxDmRAjCx3kWEz diGlaDs3mPFim8Nfa08JJQjYFppc8k0WfohXw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fLDWotd+HjLOkcaivceD3JN+d74vJu2VbqBS5gTQN+E=; b=pqhPBhnIlHBso336dfbL7THOiK+DHO/yF+7mo/KWuYyT1KlL6i3vLU8Rt6FzH5xnQe pEqSeDRIjEy22li8q3dIDVYseWXo+MeT8RjOrBrKh8VPRMvz46Lq1e83ukaTa2MM3qoJ ZKBZl69Swxrk7811lJLtWNukYsFsI9u/BuvdNcqCPaLK2eysGHnJFc+xPplBMAEz5FEU 18pxgCWMS67fWR/z+j1uPtZhEDVQ8nwi+bSgTupqsB9AWxHgRhM1PLQKme9aFLwysHSJ Srub6YtFhipSM6kbBWT9r+gmSjh2lwnRinp5o1TTsZXwuGGpjOA/E6ux4rPlB0EBX9t6 o1dA== X-Gm-Message-State: ALQs6tDP/9kq8tZXvWt+XmRCBuoYH5x5Ebq4YcR/mv/SD10x4rH9vSpM eSdpVAXzf2xn1rmwHVGEpErySw== X-Received: by 2002:a63:69c3:: with SMTP id e186-v6mr13511486pgc.353.1525193135887; Tue, 01 May 2018 09:45:35 -0700 (PDT) Received: from localhost ([2620:0:1000:1501:8e2d:4727:1211:622]) by smtp.gmail.com with ESMTPSA id g72sm28488777pfg.60.2018.05.01.09.45.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 May 2018 09:45:35 -0700 (PDT) Date: Tue, 1 May 2018 09:45:34 -0700 From: Matthias Kaehlcke To: Lina Iyer Cc: Doug Anderson , Andy Gross , David Brown , linux-arm-msm@vger.kernel.org, "open list:ARM/QUALCOMM SUPPORT" , Rajendra Nayak , Bjorn Andersson , LKML , Stephen Boyd , Evan Green Subject: Re: [PATCH v6 05/10] drivers: qcom: rpmh-rsc: write sleep/wake requests to TCS Message-ID: <20180501164534.GE133494@google.com> References: <20180419221635.17849-6-ilina@codeaurora.org> <20180425214111.GC243180@google.com> <20180427173943.GD6380@codeaurora.org> <20180427184017.GI243180@google.com> <20180427194559.GE6380@codeaurora.org> <20180427200605.GJ243180@google.com> <20180427213201.GA23157@codeaurora.org> <20180427215449.GA133494@google.com> <20180501161010.GB23157@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180501161010.GB23157@codeaurora.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lina, On Tue, May 01, 2018 at 10:10:10AM -0600, Lina Iyer wrote: > On Fri, Apr 27 2018 at 17:24 -0600, Doug Anderson wrote: > > Hi, > > > > On Fri, Apr 27, 2018 at 2:54 PM, Matthias Kaehlcke wrote: > > > > > Am I getting something wrong here? > > > > > > > > The for_each_set_bit() should increment the 'i' and we would attempt to > > > > compare the first address in the request with the next command in the > > > > TCS cache. If they don't match we repeat the process again. If it does, > > > > then we loop through 'j' to find if the sequence matches. > > > > > > > > Did I miss something? > > > > > > One of us is clearly in need of more caffeine or ready for the > > > weekend, it might be me :) Maybe another pair of eyeballs could help > I need them both. Sorry about the back and forth. I understand what the > problem is. The code doesnt look right. I seem to have messed it up. > Thanks Matthias for being patient and going through this. > > > > to resolve this deadlock ... > > > > > > My single stepping above assumes that tcs->cmd_cache[i] matches > > > cmd[0].addr, i.e. we either found the start of the sequence we are > > > looking for or another sequence that starts with the same address. My > > > claim is that the code returns i in either case, whether the > > > subsequent addresses match or not. > > > > I haven't reviewed this patch in detail, but I attempted to be another > > pair of eyes here. Something is definitely wrong with the "for (j = > > 0; j < len; j++)" loop. I believe the code that's written right now > > is equivalent to this much shorter function: > > > > +static int find_match(const struct tcs_group *tcs, const struct tcs_cmd *cmd, > > + int len) > > +{ > > + int i, j; > > + > > + /* Check for already cached commands */ > > + for_each_set_bit(i, tcs->slots, MAX_TCS_SLOTS) { > > + if (tcs->cmd_cache[i] == cmd[0].addr) > > + return i; > > + } > > + > > + return -ENODATA; > > +} > > > > Specifically the test "if (tcs->cmd_cache[i] != cmd[0].addr)" does not > > take "j" into account. Thus if it was false when "j == 0" it will > > continue to be false for "j == 1", "j == 2", etc. Eventually you'll > > hit the "else if (j == len - 1)" and return. > > > > I believe that's what Matthias has been saying. I personally haven't > > looked at the rest of the patch to see how things out to be fixed, but > > I'm quite convinced that the function either has a bug or should be > > written as the shorter version I've written above. > > > Yes, this is incorrect in its current form. This is what it should be - > > static int find_match(const struct tcs_group *tcs, const struct tcs_cmd *cmd, > int len) > { > int i, j; > > /* Check for already cached commands */ > for_each_set_bit(i, tcs->slots, MAX_TCS_SLOTS) { > if (tcs->cmd_cache[i] != cmd[0].addr) > continue; This looks better. > for (j = 0; j < len; j++) { > WARN(tcs->cmd_cache[i + j] != cmd[j].addr, > "Message does not match previous sequence.\n"); > return -EINVAL; > } However this will return -EINVAL for any message in the first iteration. > if (j == len - 1) > return i; > } You can just return 'i' here, 'j' will always be equals to 'len' (not 'len - 1') when this point is reached. I think you want something like this: for (j = 0; j < len; j++) { if (tcs->cmd_cache[i + j] != cmd[j].addr) { pr_warn("Message does not match previous sequence.\n"); return -EINVAL; } } return i; Before entering the loop you also have to verify that 'i + (len - 1)' doesn't exceed 'tcs->cmd_cache'.