Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1110563lqd; Thu, 25 Apr 2024 06:26:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhK0P0zgzpvRVq0gmiigRBirpDsuTAbuLDeeS/Heo9YNO6OFaRZYTpLNlaAuWqC1bUPTMgJn1z5xN2CNrz65EtrGsPqePUrcPH6tcPqQ== X-Google-Smtp-Source: AGHT+IHqXeab1CGy79vx3XLbnNtJ+pe4HV+OH/ewyhLqSrpIFHuSONk3E/PmipoT/QairRTTC9Is X-Received: by 2002:a9d:6315:0:b0:6eb:c45c:a8a7 with SMTP id q21-20020a9d6315000000b006ebc45ca8a7mr6103683otk.28.1714051618562; Thu, 25 Apr 2024 06:26:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714051618; cv=pass; d=google.com; s=arc-20160816; b=XEzUx8yEVOeMkikonnJBOl+AHunhVOFfvS04mWtEzjg9pmvvznYatZFnVGtvIZKspm y5mBuGC8Ad7RV8pgy8yrm8Vusxcz3u0GbbMiK+hYnYFzJ2HjQMSLO4mgfT9b1e39Wfc+ ZzH86eXkeZ4VH8T0gXWdotTJCzD1eD1r4yneWvkYxfnZ1/x/IDx32R7TlC8fP7YgLIAY uBV+9UQ1DX5hrReNkGFg/KE7OBOQ3RrZVUKZJqLki/e8WpXUpvO8YdzPRInpYLzlNynA Qp9/lS27P54EA58DLa/IOPfjSR+vhO/19qYEAeDYnXQg4T6KCazRKXNMNZxos1xq8nlQ fIVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=f+80omviGrfI2IUYA99GEhyL3YmPqzK7HUQ87kE5ivQ=; fh=m9jxS9CENbjm0E4eaROFqE/Ho2xH7SzEr0uL2OnJ91Q=; b=H9k4FJ9NWSC5vLjCtLcqDpuM1GgPdbH+5Lgqm58cbytN65BzxC8f7IwtgFPgu77eox N+1qY8UNvma/aUOuvQOfkDBMj25pa4ogizV5f6wxljPoL9ldPR2O2158UepVYOyH1j6I Wc3ErlgiazJrgqb2Z6u88IqdaLjdr4tAX7EEXx0oi1F2A9AUQA2Us0mY+T1uJjpY5QI/ 8jOf+wZNZcYgdZ2I02JGacw3VynNEdhFXBWLvdoeLfbcSRP13n7iKHXJloXYrEIUz8h4 sDCZeBl/8riGsPgPFstbzC3DknWshIcNDKvNU/Xtm3SmPTLfXMiX8gOCRHZgsYo/LOkB NzSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a1h+dT50; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-158327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q2-20020a05620a0c8200b0078ed1542ae7si17080694qki.593.2024.04.25.06.26.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 06:26:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=a1h+dT50; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-158327-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D88D81C2417B for ; Thu, 25 Apr 2024 09:50:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B88268613E; Thu, 25 Apr 2024 09:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="a1h+dT50" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43C4384E06; Thu, 25 Apr 2024 09:49:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714038586; cv=none; b=LHS00i4qZ4XPyppRjYTI9/C6o9w3ANN5yU/wLzaiTtAG/YOVAyp8Q0uFYdnQ3ht7Zag079Su02MZWaP7iIHhlRh4WVA3XXH0R0dlh+e48V3Ixkb/ghdknORxgQ5N4lGpinXw3YyZTA93k525rBT6PSLbvDmR0O4FpkKnXI+W3bY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714038586; c=relaxed/simple; bh=QXFUf2dig+J5niW70mDgvb8l8rJWffgfwjHbPDKxhQc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OaBhurzt9qH4ZPDacP95preuQ1i34aM2KSApmOawx2hiKrta7A5XNCh5051C36/lUYpuRe4ZAxd3u6YSxjtovoXveE/8ksqVFta7RxxCj0xnV+MFQmzo5aaGi0YLy0g+ulTQdnkaAPftcdXioVWcleIYHNYhju7+bfSQ7X06fo0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=a1h+dT50; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714038585; x=1745574585; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=QXFUf2dig+J5niW70mDgvb8l8rJWffgfwjHbPDKxhQc=; b=a1h+dT50I1kHP5ZEK0Bjh4UNt1pJ6nzqYxq4FK5cd76gEVVrupCoIfix OmyVKOwVhDpnOxWCHO33p/U5yguyO5XucDgHE30C2gLdxsrvhy3ALbc9W KZRhfuDoHsJFDu33z8z6n6D9Mk5bUgZahrCm9KbD0rYNTCeAwBGq3F9I4 ZXp6XVoKdmB+qWpeX4MNaOGP/zuXNwtu3ELf6yi35KcaOQNWd0q7eCTg5 buVvAzEteIp6OIWh3xXrDCcHtRYI2FA3yQdd/X9dOhHLWUqwOKLTHh3uW hcgy9XiRFdkeashQvLbRrs15hLCvAZTucR3Bt7yUX458igPQl0TMAYUy7 w==; X-CSE-ConnectionGUID: dPDhQElGT8+zHT08G60n8w== X-CSE-MsgGUID: 3nWNCZe9Su+MuNOpv81OxA== X-IronPort-AV: E=McAfee;i="6600,9927,11054"; a="9582694" X-IronPort-AV: E=Sophos;i="6.07,229,1708416000"; d="scan'208";a="9582694" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2024 02:49:21 -0700 X-CSE-ConnectionGUID: OXFqQfJhS1OaxPgw+eHWxQ== X-CSE-MsgGUID: nbxUm9SeTkujsYTuA25Xvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,228,1708416000"; d="scan'208";a="25050465" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmviesa007.fm.intel.com with SMTP; 25 Apr 2024 02:49:18 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 25 Apr 2024 12:49:17 +0300 Date: Thu, 25 Apr 2024 12:49:17 +0300 From: Heikki Krogerus To: RD Babiera Cc: linux@roeck-us.net, gregkh@linuxfoundation.org, hdegoede@redhat.com, badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v1] usb: typec: tcpm: enforce ready state when queueing alt mode vdm Message-ID: References: <20240423202356.3372314-2-rdbabiera@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240423202356.3372314-2-rdbabiera@google.com> On Tue, Apr 23, 2024 at 08:23:57PM +0000, RD Babiera wrote: > Before sending Enter Mode for an Alt Mode, there is a gap between Discover > Modes and the Alt Mode driver queueing the Enter Mode VDM for the port > partner to send a message to the port. > > If this message results in unregistering Alt Modes such as in a DR_SWAP, > then the following deadlock can occur with respect to the DisplayPort Alt > Mode driver: > 1. The DR_SWAP state holds port->lock. Unregistering the Alt Mode driver > results in a cancel_work_sync() that waits for the current dp_altmode_work > to finish. > 2. dp_altmode_work makes a call to tcpm_altmode_enter. The deadlock occurs > because tcpm_queue_vdm_unlock attempts to hold port->lock. > > Before attempting to grab the lock, ensure that the port is in a state > vdm_run_state_machine can run in. Alt Mode unregistration will not occur > in these states. I'm probable missing something, but wouldn't it be safer to check port->state after grabbing the lock? > Fixes: 03eafcfb60c0 ("usb: typec: tcpm: Add tcpm_queue_vdm_unlocked() helper") > Cc: stable@vger.kernel.org > Signed-off-by: RD Babiera > --- > drivers/usb/typec/tcpm/tcpm.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index c26fb70c3ec6..6fa1601ac259 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -1564,6 +1564,10 @@ static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header, > static void tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header, > const u32 *data, int cnt, enum tcpm_transmit_type tx_sop_type) > { > + if (port->state != SRC_READY && port->state != SNK_READY && > + port->state != SRC_VDM_IDENTITY_REQUEST) > + return; > + > mutex_lock(&port->lock); > tcpm_queue_vdm(port, header, data, cnt, TCPC_TX_SOP); > mutex_unlock(&port->lock); > > base-commit: 684e9f5f97eb4b7831298ffad140d5c1d426ff27 > -- > 2.44.0.769.g3c40516874-goog -- heikki