Received: by 10.192.165.148 with SMTP id m20csp1104375imm; Fri, 27 Apr 2018 12:47:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpqwjd2MEWQgKKjNEUOWWWzdR+MVlaGHrffrJBM0qgBHy7F0eZIPBBtnB7CzwNcZ+uMwKs9 X-Received: by 2002:a17:902:566:: with SMTP id 93-v6mr3462719plf.327.1524858451450; Fri, 27 Apr 2018 12:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524858451; cv=none; d=google.com; s=arc-20160816; b=JJapqtF2bxzUU/uo7ZXQcUuqF6iCEZVh9vIunkG5H8NU1H9+lptqj+jl1jrmTi6Sjr sdtoEGk2bn2fzHQFqoU+vH1KBAOjlF3JDJY7KtUFS4/ctMyvFR4IM5H9/Y8ZvG9maJKo D2Kcd5mC/RpDwheoVNMnHeXX/8Jpq0wn7TnGeT565bYa6OZqBQrKl3sq/U9AJ0C7aZMY yHJ7zYbqljhCxqJmut6kn3FhFrgxtA+HtguH44yaizeMly6Xp23DDHkK5u7c0Lbk3259 rSvVI/ON+S+rFrPmh5/IfxgpMZZ5reqWL4X4hfzm8UReL3oe3WyLRYDV8Px+sv9vAIQB j6OA== 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:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=iB2ksWj9la6NOcnQc5GDRgXpdz3ZI6bLvdwAEZ9rgcs=; b=GFsqKYAO8DtLE1Ydm4KM0XYAu/IdO6qRV9KChh2L1dF5t2qTJhPk+YvRYwD/JK5d4T J+yluWeG+ANU6UWe8sJ/lI3qP6Fj7lBN4fnj5XX5WkU/otwZarMWVjUXA1vZ/MWIZlKg lqvEVWvysAyDiPtPZS8OZOJZ2NOmMvgjjSWoXh/NiQtNtMdfIC52yYVBc5rHwRJsf2EM BOpPw7R+dfA2V086jhx6n4669MVsz8xY+JTYgzv8TAurOVbBy47tBghJ1dICT+tA3i6I EV0r77MWdy8ZGlX7PmzOSs3uJD+rbzA8AQkd/+9SeZoBMIDQIXWEybVR26bZhPBRLOSA bC3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Q0wKiqnr; dkim=pass header.i=@codeaurora.org header.s=default header.b=bDHdOCho; 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 g3-v6si1768753plb.536.2018.04.27.12.47.16; Fri, 27 Apr 2018 12:47:31 -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=@codeaurora.org header.s=default header.b=Q0wKiqnr; dkim=pass header.i=@codeaurora.org header.s=default header.b=bDHdOCho; 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 S1759088AbeD0TqG (ORCPT + 99 others); Fri, 27 Apr 2018 15:46:06 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:33798 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758703AbeD0TqB (ORCPT ); Fri, 27 Apr 2018 15:46:01 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3F090607C6; Fri, 27 Apr 2018 19:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524858361; bh=TVQbSk++F8R7Ox3GX4dT26KJO4lAJKC8Xl6Q/x6Oc8Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q0wKiqnrlEPG+HmxgbCaa/H+o5rB8IOonmKPq9Hs13qMhoB+Zpv0eO9EEMcmXqQqg tGCAMKpKbCGLXgXYU3tiGs7rJmMIU/VzFGX/tPyV3wLPWhUAqi6/y5SH1g/MOOGA08 hLxa0ePaAx4yX59AUO7tR1GB1FvFqZPVnfocukeQ= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C7F466034E; Fri, 27 Apr 2018 19:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524858360; bh=TVQbSk++F8R7Ox3GX4dT26KJO4lAJKC8Xl6Q/x6Oc8Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bDHdOChoZDVfrDFQ5OA+YQIUuWzL/DKyO4uF7WLk3uH5r83lvlSmeO+Cofwz2wpV3 YJ2cOKsEzCzs9z4CqVL/M1t53RecuqFM1fkr7pXJi+3u91vnmjwjBYwKZCPpb3JEIx mhD/NymhJkNNzU/9Fi87GBHkFCbTZ9actTDvJfXw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C7F466034E Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org Date: Fri, 27 Apr 2018 13:45:59 -0600 From: Lina Iyer To: Matthias Kaehlcke Cc: andy.gross@linaro.org, david.brown@linaro.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, rnayak@codeaurora.org, bjorn.andersson@linaro.org, linux-kernel@vger.kernel.org, sboyd@kernel.org, evgreen@chromium.org, dianders@chromium.org Subject: Re: [PATCH v6 05/10] drivers: qcom: rpmh-rsc: write sleep/wake requests to TCS Message-ID: <20180427194559.GE6380@codeaurora.org> References: <20180419221635.17849-1-ilina@codeaurora.org> <20180419221635.17849-6-ilina@codeaurora.org> <20180425214111.GC243180@google.com> <20180427173943.GD6380@codeaurora.org> <20180427184017.GI243180@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180427184017.GI243180@google.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 27 2018 at 12:40 -0600, Matthias Kaehlcke wrote: >On Fri, Apr 27, 2018 at 11:39:43AM -0600, Lina Iyer wrote: >> On Wed, Apr 25 2018 at 15:41 -0600, Matthias Kaehlcke wrote: >> > On Thu, Apr 19, 2018 at 04:16:30PM -0600, Lina Iyer wrote: >> > > Sleep and wake requests are sent when the application processor >> > > subsystem of the SoC is entering deep sleep states like in suspend. >> > > These requests help lower the system power requirements when the >> > > resources are not in use. >> > > >> > > Sleep and wake requests are written to the TCS slots but are not >> > > triggered at the time of writing. The TCS are triggered by the firmware >> > > after the last of the CPUs has executed its WFI. Since these requests >> > > may come in different batches of requests, it is the job of this >> > > controller driver to find and arrange the requests into the available >> > > TCSes. >> > > >> > > Signed-off-by: Lina Iyer >> > > Reviewed-by: Evan Green >> > > --- >> > > drivers/soc/qcom/rpmh-internal.h | 8 +++ >> > > drivers/soc/qcom/rpmh-rsc.c | 120 +++++++++++++++++++++++++++++++ >> > > 2 files changed, 128 insertions(+) >> > > >> > > diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h >> > > index d9a21726e568..6e19fe458c31 100644 >> > > --- a/drivers/soc/qcom/rpmh-internal.h >> > > +++ b/drivers/soc/qcom/rpmh-internal.h >> > >> > >> > >> > > +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) { >> > > + for (j = 0; j < len; j++) { >> > > + if (tcs->cmd_cache[i] != cmd[0].addr) { >> > >> > Shouldn't the condition be 'tcs->cmd_cache[i + j] != cmd[j].addr'? >> > >> Here, we are trying to find the first address from the request and its >> position 'i' in the cmd_cache. >> >> > Otherwise the code below the following if branch will never be >> > executed. Either the 'tcs->cmd_cache[i] != cmd[0].addr' branch isn't >> > entered because the addresses match, or the addresses don't match >> > and the inner loop is aborted after the first iteration. >> > >> > > + if (j == 0) >> > > + break; >> > > + WARN(tcs->cmd_cache[i + j] != cmd[j].addr, >> > > + "Message does not match previous sequence.\n"); >> We now check for the sequence using the iterator 'j' only after we have >> found 'i' (the beginning of our request). >> >> I hope that helps clear the concern. > >It doesn't, maybe I'm just confused, the driver has a certain >complexity and I don't claim to have a comprehensive understanding :) > >If I understand correctly find_match() is used to find a sequence of >commands of length 'len' in the command cache. If that is correct I >would expect it to do the following: > >1. iterate through the commands in the command cache and find a >command that matches the first command in the sequence > >2. verify that the (len - 1) subsequent commands match those in the >sequence, otherwise bail out > >If I'm not mistaken the current version of find_match() only checks >that the first command exists. After that it happily increases the >command index, but doesn't perform any checks (after finding the first >command 'tcs->cmd_cache[i] != cmd[0].addr' remains false for the >subsequent values of j). When j reaches (len - 1) the function >returns the index of the first command in the cache, regardless of >whether the other commands match or not. > Did you miss the check inside the WARN? WARN(tcs->cmd_cache[i + j] != cmd[j].addr, --Lina