Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1013822pxb; Thu, 9 Sep 2021 18:01:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3PBidXjs1ZKcwdwXtnSPb9G6NSiGRNh4nucG5RzyeGwNy+liAAxgYFq1m62xfEcHz8hNR X-Received: by 2002:a5e:db06:: with SMTP id q6mr5042979iop.129.1631235688957; Thu, 09 Sep 2021 18:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631235688; cv=none; d=google.com; s=arc-20160816; b=P3qT2OBoWW9UpRsHSfCFmk4zL4wP6jKoKxNPUNjRsTDYcG6UmTuaNUdUDrAWABxlTq e/9G0xKUYgKbKVhyJIxOUgbcpFFDs38ej9GIF7dj2Oj37AUf2/dcSx/7/hhUab7EXxg3 bDkPjvTF97qYkOg3p/xmX6aaUn8fi0xnbA/VkVLndXihSpNaGjTLTXMH6FP40p80nlyX xw5M0ZLnlT0iAu+8rQrIMATNg54EZA7g2zLOdf3E59qM3ZAF+n+Mw8cArSQaNANJUSMU OCxRvkCQwNo1qXUTmETNXa5lqmRh0rvwIkHoUmg7bmfUfCZhZ/eTvMMdihcbTL+4g0Yz g69A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VuVOKXgn2rHOkWL+5u8OV559JLRa615N1WqcD9ZZCd0=; b=pGk2iNhBjJ982lY/9JKuKMd6yIcGf3zqvzu2bOBci0MgBx/emV9pcq49BY6gRGuVBk su2Q0P8lzm3LYmEIOpTP++5GrTCGfixuVbc1u3gPJJ+oxia4E3HNEXgw02qTaE0Ky0oI s9shAQCnt4YANtCKXAJyp86rkiZRJp/cbOUE2YqXmV5JjEh+HeUgzbZh5J8TNEfohnaQ l8pUbVPbdff7/k23ULtptIuZ/J1D+ImcX6lU2JQR95QAsqAbtvQbz15Z+Oz2xlS41E6e 5ed8lStTQ5KHgAcEGz3sYFVYcupVxTsE56Auv2XLtjfcV6xm4Yurn+fu/mZDAKhvUX6m g9Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ALbpLLYU; 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 b135si3473092iof.27.2021.09.09.18.01.17; Thu, 09 Sep 2021 18:01:28 -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=k20201202 header.b=ALbpLLYU; 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 S244527AbhIJA7o (ORCPT + 99 others); Thu, 9 Sep 2021 20:59:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:48678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234299AbhIJAXJ (ORCPT ); Thu, 9 Sep 2021 20:23:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9DFE360F6C; Fri, 10 Sep 2021 00:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631233319; bh=dtQE6qpxahyt6p2yznUbHA//kAq5UXiIVqJAS7BSAmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ALbpLLYUtg/dbyv+PxAgDercLO6B2xRSKQSqOHxQMuT44ij09ejHWZfNUHb3n+UEb hckfJd840rwD0gVY6la0c/7NwEcGZju/VFyr+sXL6p8MexbZevPMZwA5WjHH8ULOK6 AgmYAgZYQPjad1uG15srlcji5uXtOXJ4Qbtql7UljTkPTdpvdaBJVstUOIVJX8+m9S uGi1UCMbfs1k/W5OdYQCoFMsFugsTgOXalYTSXnCzrKTpaNQe74P1ZfMgO6lAK52+5 uRlM9ce/3vNkKYw2luyJhKancSId1RTJpi4voA0fAGARoEMurvIgYw0JR0K23EoBtQ E966SSXTcCPUA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bart Van Assche , Adrian Hunter , Stanley Chu , Can Guo , Asutosh Das , Avri Altman , Bean Huo , Daejun Park , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 11/37] scsi: ufs: Verify UIC locking requirements at runtime Date: Thu, 9 Sep 2021 20:21:16 -0400 Message-Id: <20210910002143.175731-11-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910002143.175731-1-sashal@kernel.org> References: <20210910002143.175731-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche [ Upstream commit 35c7d874f5993db04ce3aa310ae088f14b801eda ] Instead of documenting the locking requirements of the UIC code as comments, use lockdep_assert_held() such that lockdep verifies the lockdep requirements at runtime if lockdep is enabled. Link: https://lore.kernel.org/r/20210722033439.26550-8-bvanassche@acm.org Cc: Adrian Hunter Cc: Stanley Chu Cc: Can Guo Cc: Asutosh Das Reviewed-by: Avri Altman Reviewed-by: Bean Huo Reviewed-by: Daejun Park Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 16 +++++++++------- drivers/scsi/ufs/ufshcd.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 0429ba5d7d23..f8d0fe6cb09d 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1986,15 +1986,15 @@ static inline u8 ufshcd_get_upmcrs(struct ufs_hba *hba) } /** - * ufshcd_dispatch_uic_cmd - Dispatch UIC commands to unipro layers + * ufshcd_dispatch_uic_cmd - Dispatch an UIC command to the Unipro layer * @hba: per adapter instance * @uic_cmd: UIC command - * - * Mutex must be held. */ static inline void ufshcd_dispatch_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) { + lockdep_assert_held(&hba->uic_cmd_mutex); + WARN_ON(hba->active_uic_cmd); hba->active_uic_cmd = uic_cmd; @@ -2010,11 +2010,10 @@ ufshcd_dispatch_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) } /** - * ufshcd_wait_for_uic_cmd - Wait complectioin of UIC command + * ufshcd_wait_for_uic_cmd - Wait for completion of an UIC command * @hba: per adapter instance * @uic_cmd: UIC command * - * Must be called with mutex held. * Returns 0 only if success. */ static int @@ -2023,6 +2022,8 @@ ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) int ret; unsigned long flags; + lockdep_assert_held(&hba->uic_cmd_mutex); + if (wait_for_completion_timeout(&uic_cmd->done, msecs_to_jiffies(UIC_CMD_TIMEOUT))) ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT; @@ -2042,14 +2043,15 @@ ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) * @uic_cmd: UIC command * @completion: initialize the completion only if this is set to true * - * Identical to ufshcd_send_uic_cmd() expect mutex. Must be called - * with mutex held and host_lock locked. * Returns 0 only if success. */ static int __ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd, bool completion) { + lockdep_assert_held(&hba->uic_cmd_mutex); + lockdep_assert_held(hba->host->host_lock); + if (!ufshcd_ready_for_uic_cmd(hba)) { dev_err(hba->dev, "Controller not ready to accept UIC commands\n"); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 92ef6e6a3e51..803a2a37875b 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -493,7 +493,7 @@ struct ufs_stats { * @priv: pointer to variant specific private data * @irq: Irq number of the controller * @active_uic_cmd: handle of active UIC command - * @uic_cmd_mutex: mutex for uic command + * @uic_cmd_mutex: mutex for UIC command * @tmf_tag_set: TMF tag set. * @tmf_queue: Used to allocate TMF tags. * @pwr_done: completion for power mode change -- 2.30.2