Received: by 10.192.165.148 with SMTP id m20csp5117692imm; Tue, 1 May 2018 09:19:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpFmlmujVTNISUxOvj9ODUr5Qkbklv3GU5CbbMvy1csH9j3XQw4pWaFslwNLzMfXXSwb9XT X-Received: by 2002:a63:6dc8:: with SMTP id i191-v6mr13148735pgc.291.1525191590577; Tue, 01 May 2018 09:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525191590; cv=none; d=google.com; s=arc-20160816; b=H8fBg4S/rUge4ZQ2S+QTjReKXBvGoX4szL4K/lYfQnEhhttQfvN9Lwsy8Lyn9YcmpH cHCoQ5WLLethoU3Dyc/9IqqsIz0y1BkSeXEjzRlqFI2gP5SWwpFGoskxoL6DtrdU1/tP 2uthLDKXIJ2JCvqJB6Cwep59yfhMc1iMFsX7YF/cXpsjo8LeyPD1qkp7wnczloq61iu9 b4/wl5zMWtOlYCZfWoTBJzCHe927ePLHWPczZY+F8CAzTEN94a8F8SIuGnlFaGFLa/I/ 54619joRh+0prJrQKz7tF95Dr2Txv7wT/um6vwJYO2FI1WZB87BAK88e+rHu0Wvqj2dw hR7A== 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=Palmq9Trz1YaGG5uwfXJds8NRHY/N0VJuhaqZ6Em3mM=; b=SHsEDjgTszwBr8R49RBx8S/rrJYOwSowjkph42orQ9c5scYa4jlo8AHvuxQ/HKl1QX mYAzXl5JGHqES8+HVenyqRkc1+oVvsN4MGQ4CxB4vIctJ+7ykTsgYE/vgg+rC2DYTP9b FDThStyFXDhp7lqX2DgBqdF7DPCOgTO4QQREhdCc4+IHRgUIns+F2RXLtZOSUcK63vgK BDbs0a2GRr09IpAj8gztKQduIWyuP8mzO5zMe/V3fNe3hi48cP929/6uhYB0253g8PJf rkuP6zYomS0Nnyp64qzDw4T8RmVry17sbpiwoF63VjbEqKPyaRJlEL0als/0jFVTkMZL QboA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=hpZ5HawV; dkim=pass header.i=@codeaurora.org header.s=default header.b=T6pCwp37; 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 z19-v6si7968077plo.174.2018.05.01.09.19.36; Tue, 01 May 2018 09:19:50 -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=hpZ5HawV; dkim=pass header.i=@codeaurora.org header.s=default header.b=T6pCwp37; 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 S1756114AbeEAQSW (ORCPT + 99 others); Tue, 1 May 2018 12:18:22 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:43714 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756053AbeEAQSU (ORCPT ); Tue, 1 May 2018 12:18:20 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 80C0C607CF; Tue, 1 May 2018 16:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525191012; bh=zRu6SMnqEQHtp/MOWy5qS7kb1753/UzGHYQwH/056OU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hpZ5HawVzSpkzLWuGdlPXNbfpx2vaxjJKSjGGKiFG66dkVtxzNTtkkbcH+rkBwzr7 ryVjXyqxRFXeZHvJdL8Uv5oOhFeOVIEoCRPv6WHmsb0ZolojHcAvMYo01JSWL5ooiw UM8Y7LOoFTyev8ehwzWtkf8y4JaNt3xB62G4k6eM= 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 9A98960710; Tue, 1 May 2018 16:10:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525191011; bh=zRu6SMnqEQHtp/MOWy5qS7kb1753/UzGHYQwH/056OU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T6pCwp3795d5XLX3uFQ1rIikDxQkKejqVZa3Aq6/V4LFX6Vg2EidBiWscLe7K5JG4 tyxpAGmedBjbArpNQMApjwwEUfLl6WEHW4j/XH/UNo1Mv/L9UrqUYYb/2A92fN2jnp zewKXO4pAFh1bLkEjfLi+z08SHu0oceSweG9CsqQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9A98960710 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: Tue, 1 May 2018 10:10:10 -0600 From: Lina Iyer To: Doug Anderson Cc: Matthias Kaehlcke , 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: <20180501161010.GB23157@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> <20180427194559.GE6380@codeaurora.org> <20180427200605.GJ243180@google.com> <20180427213201.GA23157@codeaurora.org> <20180427215449.GA133494@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: 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 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; for (j = 0; j < len; j++) { WARN(tcs->cmd_cache[i + j] != cmd[j].addr, "Message does not match previous sequence.\n"); return -EINVAL; } if (j == len - 1) return i; } return -ENODATA; } Thanks, Lina