Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp765895imm; Wed, 23 May 2018 05:20:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoQlrSFwK2GYflTdBsPvVdLjARK9HlMleaetAdt9yBpfv4h6kdhcJAOwl3SHcaxZ+3wi8s8 X-Received: by 2002:a63:2a89:: with SMTP id q131-v6mr2129481pgq.379.1527078036259; Wed, 23 May 2018 05:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527078036; cv=none; d=google.com; s=arc-20160816; b=a1ob5bOQ2pKp2pR55u3/mqar3wCpDiF2Dc3bOoS4HP8k4TMQhlblTelzTueMxiaOit DcrcqCHJ4buwPCuAFd4+4dCJjocfQ9CMJ29iVBcWlsLz9uxeCMEg4yL2nqDyfmHVuloi 1CmIm/F6UrZiWgLFDtB1GGbM6wzSCn9ABF/IMQTHT7ipY+fTw/UCUKahFfHNlGmsksAk DU1QtvcopsgC9RDdG7hLPc4JSa11Qf6l9Q4QnU2mC6A2bMf8+G75iFpSjILut09sNIRW SHN30xcKOJ9qCPNqTM7XatdgfrYfFGk6s8GXYiMn8wXmXJEaHgCZdAbIJD88ak/xj0E3 Vtlg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=gQK0UaNnnII5oL3w1T9TORjEBhGH1E7+aQOk5TIYTdI=; b=JM+pt7FeiRIfW1w3Tv+qhjCH+8r+59qyXoOAVyr5GuHwCSfHUhAcDDgiPR794a+H+F mSnbzpxIpKm8aOEf3pt9q9+Kb1x45iY2VTDBaHkcAiMvo0gGBVDUuI6pA45i8YUzCsFL gtXU/tn9wZx8AdNVrJer8AGs85GMhOaB/P/Ws+CjytG3hpWQD6psxNAGB5EEa6xrcFpJ bzh3MH4YKn0cBFYlK+MYCRo8Mn5PE0QeSrq6E7fg+1wtZ42E6zcsCkN9vhj32xZP9AsZ Md86wfJ9Vx/OspxQhbZMWaLMjaCfHG2dHkZODe+7Ng/funny5dj3mOOW+r9o3pgtRQoZ HxTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=IS/FOsBs; dkim=pass header.i=@codeaurora.org header.s=default header.b=IS/FOsBs; 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 n3-v6si1351084pgr.106.2018.05.23.05.20.21; Wed, 23 May 2018 05:20:36 -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=IS/FOsBs; dkim=pass header.i=@codeaurora.org header.s=default header.b=IS/FOsBs; 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 S932759AbeEWMTc (ORCPT + 99 others); Wed, 23 May 2018 08:19:32 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:38666 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932080AbeEWMT2 (ORCPT ); Wed, 23 May 2018 08:19:28 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id AFDB160314; Wed, 23 May 2018 12:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527077967; bh=/de1MspYBmuJo9oZchajKLnMbGMojcUUrc50PpWmBKM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=IS/FOsBs+B3YQc1CDJtumsgEJ8LF8EeIJ9RsXpR9du6A97O+xeJsCtBr7z2Z07oyK A5c7xJoX1MSYaH/Vl3pwbM1hZhp/93kCvXo1Z+38Cct9hFGm/bkeZU0YFo4Algx6SA g+V9MQj7d4rSPse6T167QNXVH1Lc/N3WphpQD6vY= 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.3 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,FROM_LOCAL_NOVOWEL,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.206.16.80] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rplsssn@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 6A6EA60314; Wed, 23 May 2018 12:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527077967; bh=/de1MspYBmuJo9oZchajKLnMbGMojcUUrc50PpWmBKM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=IS/FOsBs+B3YQc1CDJtumsgEJ8LF8EeIJ9RsXpR9du6A97O+xeJsCtBr7z2Z07oyK A5c7xJoX1MSYaH/Vl3pwbM1hZhp/93kCvXo1Z+38Cct9hFGm/bkeZU0YFo4Algx6SA g+V9MQj7d4rSPse6T167QNXVH1Lc/N3WphpQD6vY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 6A6EA60314 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=rplsssn@codeaurora.org Subject: Re: [PATCH v8 04/10] drivers: qcom: rpmh: add RPMH helper functions To: Doug Anderson , Lina Iyer Cc: Andy Gross , David Brown , linux-arm-msm@vger.kernel.org, "open list:ARM/QUALCOMM SUPPORT" , Rajendra Nayak , msivasub@codeaurora.org, mkshah@codeaurora.org, Bjorn Andersson , LKML , Stephen Boyd , Evan Green , Matthias Kaehlcke References: <20180509170159.29682-1-ilina@codeaurora.org> <20180509170159.29682-5-ilina@codeaurora.org> <20180515174736.GB28489@codeaurora.org> From: Raju P L S S S N Message-ID: Date: Wed, 23 May 2018 17:49:17 +0530 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 5/15/2018 11:52 PM, Doug Anderson wrote: > Hi, > > On Tue, May 15, 2018 at 10:47 AM, Lina Iyer wrote: >> On Fri, May 11 2018 at 14:17 -0600, Doug Anderson wrote: >>> >>> Hi, >>> >>> On Wed, May 9, 2018 at 10:01 AM, Lina Iyer wrote: >>>> >>>> +int rpmh_write(const struct device *dev, enum rpmh_state state, >>>> + const struct tcs_cmd *cmd, u32 n) >>>> +{ >>>> + DECLARE_COMPLETION_ONSTACK(compl); >>>> + DEFINE_RPMH_MSG_ONSTACK(dev, state, &compl, rpm_msg); >>>> + int ret; >>>> + >>>> + if (!cmd || !n || n > MAX_RPMH_PAYLOAD) >>>> + return -EINVAL; >>>> + >>>> + memcpy(rpm_msg.cmd, cmd, n * sizeof(*cmd)); >>>> + rpm_msg.msg.num_cmds = n; >>>> + >>>> + ret = __rpmh_write(dev, state, &rpm_msg); >>>> + if (ret) >>>> + return ret; >>>> + >>>> + ret = wait_for_completion_timeout(&compl, RPMH_TIMEOUT_MS); >>> >>> >>> IMO it's almost never a good idea to use wait_for_completion_timeout() >>> together with a completion that's declared on the stack. If you >>> somehow insist that this is a good idea then I need to see incredibly >>> clear and obvious code/comments that say why it's impossible that the >>> process might somehow try to signal the completion _after_ >>> RPMH_TIMEOUT_MS has expired. >>> >>> Specifically if the timeout happens but the process could still signal >>> a completion later then they will access random data on the stack of a >>> function that has already returned. This causes ridiculously >>> difficult-to-debug crashes. >>> >>> >>> NOTE: You've got timeout set to 10 seconds here. Is that really even >>> useful? IMO just call wait_for_completion() without a timeout. It's >>> much better to have a nice clean hang than a random stack corruption. >>> >>> >> The 10 sec timeout will guarantee that we will not get a response at all >> anymore for the request. Usually requests can be considered failed if >> there is no response in a few tens of microseconds. 10 sec is just an >> arbitarily large number. >> >> The reason we use timeout is that once the timeout happens, we know we >> have failed, we could trigger a watchdog or crash the system. This is >> very important for our productization in debugging RPMH failures. A >> hang would not always trigger a watchdog and the failure would be silent >> and possibly fatal but hard to debug. > > If you intend the system to crash when this timeout happens then IMHO > add a BUG_ON. Then I won't worry about something coming around later > and clobbering the stack. > > -Doug > Sure. Will add BUG_ON in next patch. Thanks, Raju.