Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2894778pxb; Thu, 10 Feb 2022 07:51:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLI8LGer/z4/qYMyLityzM/m8mzCl9BmFr9U56BD1ZRJg8nBogVPrWK0BSxf/lbyVda95b X-Received: by 2002:a63:6c87:: with SMTP id h129mr6858529pgc.530.1644508313575; Thu, 10 Feb 2022 07:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644508313; cv=none; d=google.com; s=arc-20160816; b=BMBK+VKKKdi6QwyYUiGiBTXbn5ClI7AJ1xzgd2c+ODh74TaBn8iJGGVtrq9hcfVk4m 4N9rX6uQQ8WH8YXvp9ozT6FtwIfMxeY6ay8v35RC5iZ5X3juu2Rvpz1tTqOwEqNyQFcV +2Hvn/PW2X61GXQSx5Ti1btgvgDIb8AvDQ0JdD8wsiF9LKGXuABl7TPt+ZTfydySOPwp TF/XElOczv/kr/aT3NPnJy0CVoNKkusp5PDoy87RNsTJjgDUFVpFyTZqXiXKUntEadiL Oucg1QW7ypuF73HiXNk7r3WRwR/jJhJAtbas7c99qYTGZET8dUHqzdlP5/5xQtyXPRGC J9IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3peSMU7U9JPK5bOMlTrHE2/UGwjXVVkFyIoSi7Sg6/U=; b=cuVY12T+LuuBMK9sxjbvfAwN2gtVw8JbtyRpGhWEDE3XHV5UmfS6e9aUl4sTUdGE4p TsEp53WmcEIknAcQSUbqz65kJ9u7iq8zQk8SY02cOqEohPiCP9r8/+2ST0EpBtboyG2U kztm5XrQ3GFnXtBmbx9pVER6jGXsFpq4oOuBbL5BQCo+qU3WwLOZhg8TAf/+OPm8uqnj MEoxVL2/GGtZwz/LDIb1gKPRuDkihVuiuyIizUSF11a3SpLSLs/A0WMEaXG4bXSroRb9 ZXj6yNOheMePztYKcLYodl02Nfax/ntSkHUudhmFWk1WYSukbHKpQ1wrXQZ6hW8p9Sxz AG8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PUlXK2cM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f23si18400387pfn.377.2022.02.10.07.51.40; Thu, 10 Feb 2022 07:51:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PUlXK2cM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242949AbiBJOa2 (ORCPT + 99 others); Thu, 10 Feb 2022 09:30:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:45360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242945AbiBJOa1 (ORCPT ); Thu, 10 Feb 2022 09:30:27 -0500 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01109B92; Thu, 10 Feb 2022 06:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644503428; x=1676039428; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=raoLlF1RJ+lMrQ5oJTeQR9ZgMBhNkETVNbVQPX0SD0k=; b=PUlXK2cM5gIB6Ghiexz2EZ+hKJ8FdBzXpVfkwM90FNJJ/z3ZwOqdsngm P1zd23rZmW/Fl2P/FCveIowBjXDm4qqBrXv7pxBG9mma1p4Vu7Y5Amp+P eV+FrdW2LkjoduwckzWMTEoWUq0Q3TKbEcfJjcT+HXcpmmN39emYduW09 qBnGP5Fg4+Vv3xc6EaRGJOSmsZZgi8L1KJN8NaU5wZIJN+KbZisS84T4N Sw/n8s1IYklkcBjBsWY0oH+nSxdJyexgiKj8dSzrfdjw/ZYoG4trxP6Pa TPlmuB2sRcYwTrUiB2eXRFk+LbtHjJALW9yI18ox6b+YIKFHIdoLrlEYD w==; X-IronPort-AV: E=McAfee;i="6200,9189,10253"; a="310238769" X-IronPort-AV: E=Sophos;i="5.88,359,1635231600"; d="scan'208";a="310238769" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2022 06:30:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,358,1635231600"; d="scan'208";a="679163361" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmsmga001.fm.intel.com with SMTP; 10 Feb 2022 06:30:23 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 10 Feb 2022 16:30:23 +0200 Date: Thu, 10 Feb 2022 16:30:23 +0200 From: Heikki Krogerus To: Jia-Ju Bai Cc: Greg KH , kyletso@google.com, jackp@codeaurora.org, andy.shevchenko@gmail.com, unixbhaskar@gmail.com, subbaram@codeaurora.org, mrana@codeaurora.org, "linux-usb@vger.kernel.org" , linux-kernel Subject: Re: [BUG] usb: typec: ucsi: possible deadlock in ucsi_pr_swap() and ucsi_handle_connector_change() Message-ID: References: <037de7ac-e210-bdf5-ec7a-8c0c88a0be20@gmail.com> <43d6c3b5-17e6-63a8-21fa-3ff9f478ada7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <43d6c3b5-17e6-63a8-21fa-3ff9f478ada7@gmail.com> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 10, 2022 at 10:24:42AM +0800, Jia-Ju Bai wrote: > > > On 2022/2/9 22:30, Heikki Krogerus wrote: > > On Wed, Feb 09, 2022 at 11:50:57AM +0800, Jia-Ju Bai wrote: > > > Hello, > > > > > > My static analysis tool reports a possible deadlock in the ucsi driver in > > > Linux 5.16: > > > > > > ucsi_pr_swap() > > > ? mutex_lock(&con->lock); --> Line 962 (Lock A) > > > ? wait_for_completion_timeout(&con->complete, ...) --> Line 981 (Wait X) > > > > > > ucsi_handle_connector_change() > > > ? mutex_lock(&con->lock); --> Line 763 (Lock A) > > > ? complete(&con->complete); --> Line 782 (Wake X) > > > ? complete(&con->complete); --> Line 807 (Wake X) > > > > > > When ucsi_pr_swap() is executed, "Wait X" is performed by holding "Lock A". > > > If ucsi_handle_connector_change() is executed at this time, "Wake X" cannot > > > be performed to wake up "Wait X" in ucsi_handle_connector_change(), because > > > "Lock A" has been already held by ucsi_handle_connector_change(), causing a > > > possible deadlock. > > > I find that "Wait X" is performed with a timeout, to relieve the possible > > > deadlock; but I think this timeout can cause inefficient execution. > > > > > > I am not quite sure whether this possible problem is real. > > > Any feedback would be appreciated, thanks :) > > This is probable a regression from commit ad74b8649bea ("usb: typec: > > ucsi: Preliminary support for alternate modes"). Can you test does > > this patch fix the issue (attached)? > > Hi Heikki, > > Thanks for the reply and patch. > After the patch is used, my tool does not report this deadlock in the ucsi > driver. > Thus, I think this patch should be okay to fix the deadlock :) Thanks for testing it. I'll tag you as the reporter and tester in the patch. Br, -- heikki