Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1507039ybk; Thu, 21 May 2020 08:28:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYtSyjmlnToRxH7FsUqtSIWqru5B/bHRdJF5sgEqK+F0lTHNJxzMvl+KI7LnxSLzuFQHwy X-Received: by 2002:a17:906:c838:: with SMTP id dd24mr4007022ejb.28.1590074938631; Thu, 21 May 2020 08:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590074938; cv=none; d=google.com; s=arc-20160816; b=sP9w6rHKdh5dFDHx8G/ozP6MdupDKKPWdjIo5wkmvT6tENBA4i/Jndb9ANjqHr79bz IMtvS4/p3Z0JkcB4WUVNuOju1hnwBYULUwwANuxT1Le+tgr0xOva8KqTHXuoygGkUbz8 vpyjuHlNyvPGsLTE8d89uJZZKQpxHPVa4LOwkjjdzUmpYcYYjAu8KwgNwJ/aD+4P59pn NLd66VyOLJLwCtBl7nWa8nzseI1UZIXratIfufLl1Wjk8mCRAwqyAXAV/4KE3JiGAeWh Vv3s9/lIMKWZCjh+6gbGOG2iLBsLRQ3d4XdcFmT03f7VHCybiXdMU3DRuDx9hCqQLfXw cAYA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JbuVES4sGeXmBWCIUtKRaw/rHIoTZMMW5qXIKBqBv/E=; b=Btdo0df5kJCVAHBkaoGt5UU/faMikYXyl7x10Johxko8/0/E2hh/du3d8mIulgE6GE kU0F7Qs2tmI+7l93H7NzsB7FpKkre2lXRCm17VdlzCvMtUQIIqWIPkJzDljS8SMqDwtn CLy2gJgWVujK3ITc3tXN/pv0hVep5B7/+NgOl1qcvzH7IOITTMHpOd+OoT4t2pbypREK aqeYf9IP2xoieCp2cUKe5GsCcGLuZSlN2tq6bS17UImSUab+59IJfkuZF8E00jEYpKAy bLZh7vVLaT+u1JfO3s9VjU3hG3qrziMo9Gx2KbC5IbXKfy3lzdEPlEHjwivQPQRdhQaz 3G/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lRjXmaOk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i9si3311068edb.594.2020.05.21.08.28.35; Thu, 21 May 2020 08:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lRjXmaOk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730501AbgEUP0a (ORCPT + 99 others); Thu, 21 May 2020 11:26:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:34462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730179AbgEUP03 (ORCPT ); Thu, 21 May 2020 11:26:29 -0400 Received: from localhost.localdomain (unknown [157.51.235.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9B62E207D8; Thu, 21 May 2020 15:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590074788; bh=R+8fnNnzhTdOZ/Cs65zOwAB+wU+cKSE32QyrSBLOcBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lRjXmaOkTZYI685XFHc8GYW370pxeBy3VvY9kCCqtuLAZbBb2Pv3rro9szFDs0V5z VS++bEP5Pfr+LUEYAJvCzzTDFgxlDf+zdvQWVymwteHPclpwrbgHhrJdUnV38TTxfO LoGmOG/LHp95augCIbOg4w0YXAW+AWdY6xyz4A0U= From: mani@kernel.org To: gregkh@linuxfoundation.org Cc: hemantk@codeaurora.org, jhugo@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bhaumik Bhatt , Manivannan Sadhasivam Subject: [PATCH 08/14] bus: mhi: core: Ensure non-zero session or sequence ID values are used Date: Thu, 21 May 2020 20:55:34 +0530 Message-Id: <20200521152540.17335-9-mani@kernel.org> X-Mailer: git-send-email 2.26.GIT In-Reply-To: <20200521152540.17335-1-mani@kernel.org> References: <20200521152540.17335-1-mani@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bhaumik Bhatt While writing any sequence or session identifiers, it is possible that the host could write a zero value, whereas only non-zero values should be supported writes to those registers. Ensure that the host does not write a non-zero value for them and also log them in debug messages. A macro is introduced to simplify this check and the existing checks are also converted to use this macro. Signed-off-by: Bhaumik Bhatt Reviewed-by: Jeffrey Hugo Reviewed-by: Manivannan Sadhasivam Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/core/boot.c | 15 +++++++-------- drivers/bus/mhi/core/internal.h | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/bus/mhi/core/boot.c b/drivers/bus/mhi/core/boot.c index 80e4d7609aaa..0b38014d040e 100644 --- a/drivers/bus/mhi/core/boot.c +++ b/drivers/bus/mhi/core/boot.c @@ -43,10 +43,7 @@ void mhi_rddm_prepare(struct mhi_controller *mhi_cntrl, lower_32_bits(mhi_buf->dma_addr)); mhi_write_reg(mhi_cntrl, base, BHIE_RXVECSIZE_OFFS, mhi_buf->len); - sequence_id = prandom_u32() & BHIE_RXVECSTATUS_SEQNUM_BMSK; - - if (unlikely(!sequence_id)) - sequence_id = 1; + sequence_id = MHI_RANDOM_U32_NONZERO(BHIE_RXVECSTATUS_SEQNUM_BMSK); mhi_write_reg_field(mhi_cntrl, base, BHIE_RXVECDB_OFFS, BHIE_RXVECDB_SEQNUM_BMSK, BHIE_RXVECDB_SEQNUM_SHFT, @@ -189,7 +186,9 @@ static int mhi_fw_load_amss(struct mhi_controller *mhi_cntrl, return -EIO; } - dev_dbg(dev, "Starting AMSS download via BHIe\n"); + sequence_id = MHI_RANDOM_U32_NONZERO(BHIE_TXVECSTATUS_SEQNUM_BMSK); + dev_dbg(dev, "Starting AMSS download via BHIe. Sequence ID:%u\n", + sequence_id); mhi_write_reg(mhi_cntrl, base, BHIE_TXVECADDR_HIGH_OFFS, upper_32_bits(mhi_buf->dma_addr)); @@ -198,7 +197,6 @@ static int mhi_fw_load_amss(struct mhi_controller *mhi_cntrl, mhi_write_reg(mhi_cntrl, base, BHIE_TXVECSIZE_OFFS, mhi_buf->len); - sequence_id = prandom_u32() & BHIE_TXVECSTATUS_SEQNUM_BMSK; mhi_write_reg_field(mhi_cntrl, base, BHIE_TXVECDB_OFFS, BHIE_TXVECDB_SEQNUM_BMSK, BHIE_TXVECDB_SEQNUM_SHFT, sequence_id); @@ -246,14 +244,15 @@ static int mhi_fw_load_sbl(struct mhi_controller *mhi_cntrl, goto invalid_pm_state; } - dev_dbg(dev, "Starting SBL download via BHI\n"); + session_id = MHI_RANDOM_U32_NONZERO(BHI_TXDB_SEQNUM_BMSK); + dev_dbg(dev, "Starting SBL download via BHI. Session ID:%u\n", + session_id); mhi_write_reg(mhi_cntrl, base, BHI_STATUS, 0); mhi_write_reg(mhi_cntrl, base, BHI_IMGADDR_HIGH, upper_32_bits(dma_addr)); mhi_write_reg(mhi_cntrl, base, BHI_IMGADDR_LOW, lower_32_bits(dma_addr)); mhi_write_reg(mhi_cntrl, base, BHI_IMGSIZE, size); - session_id = prandom_u32() & BHI_TXDB_SEQNUM_BMSK; mhi_write_reg(mhi_cntrl, base, BHI_IMGTXDB, session_id); read_unlock_bh(pm_lock); diff --git a/drivers/bus/mhi/core/internal.h b/drivers/bus/mhi/core/internal.h index 0965ca3c9632..80b32c20149c 100644 --- a/drivers/bus/mhi/core/internal.h +++ b/drivers/bus/mhi/core/internal.h @@ -452,6 +452,7 @@ enum mhi_pm_state { #define PRIMARY_CMD_RING 0 #define MHI_DEV_WAKE_DB 127 #define MHI_MAX_MTU 0xffff +#define MHI_RANDOM_U32_NONZERO(bmsk) (prandom_u32_max(bmsk) + 1) enum mhi_er_type { MHI_ER_TYPE_INVALID = 0x0, -- 2.26.GIT