Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1282913lqd; Thu, 25 Apr 2024 10:37:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsouK78d1dOOur0ayqYw8jkT20wh3JMxzKzZli40cCzVln1aFo3EPpBd9yIULaScRxlxvexE8swK/oeYrk0UApECzUINKAPrk09fawdA== X-Google-Smtp-Source: AGHT+IGgO8hUV38dg2q0VB5rcyo5R7xEQ0tc7rkmilYEVCYNwLTayij9SanQgdCCfWYFnWNXhTBR X-Received: by 2002:ac2:4e93:0:b0:515:d1a6:1b07 with SMTP id o19-20020ac24e93000000b00515d1a61b07mr42092lfr.15.1714066666758; Thu, 25 Apr 2024 10:37:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714066666; cv=pass; d=google.com; s=arc-20160816; b=wfY5sr19/BK4hyEE8kEbfqNaNZXvpNTL5idFQKXEMd91y0gKGuK+ZLxiUNwFx0W2bg NcwFABhxQfaTWBuz60cebJMHy6hPz1B/OwkJAwR9RbzkNUBMZMcUUqtUBGzGj6S+44B8 3Ix56jdzBaKlS5Tp7+peHSxzp1TJryC8lzuASJK4wnJfu2B/syIlWAe5UpYU1AT1J2A4 lO6ZoQTgAowTmiuX/UtxoKPEmSNhyCgVnkRkdaMN6TqqtF0Sw1wZ1vGDG4MADqLErQhE TNxrqG6EOH68FOgM/IYASCF75E/27PDfFokETTz6zXC+slRx4rdr1BKaHFj7C0o+07xw QNww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=B3VQQbOwXZfXUmtHrc/wDZo3lxxcsHSUDqcA5obudZE=; fh=cbv9tAiRiqXcpHlU4zSqWTXq/8jmqroCUQTS0JrCXVU=; b=sURQwmZwihfH9jpRUNHRztBqOUruJZeYH4TEuqk5xeEnyk+CKOhTLmq9UEGuwjajhU sSZ5aeYclXLENUcxHbKLYvSJFlOiz8n6KF08QmEKOfKBNCYriEas9adp7OIqdeIKjWSv 4EgAqBjQgCfuKof6FtJ+UQ6r5ipNiGajVXWv+G+Q+X5+g5HwpVbG+m0shi69dftpjmCx Zpce41gmNiBmjhOUHZABkID82DjvTQAstsulhHdUdFJDxX0/Fvh2KGUQyxHOgZXfJDPY MHprlA0jvWw/NjkGY7kTaUSFV4Bolp9K8JggKPufUO0XJm162NQ2lUOzZYEbWn8Mfqtb 7ung==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XJ9PStDT; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-158977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h25-20020a1709062dd900b00a5873061113si4244389eji.508.2024.04.25.10.37.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 10:37:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XJ9PStDT; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-158977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4E6611F248D9 for ; Thu, 25 Apr 2024 17:37:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38AC814EC52; Thu, 25 Apr 2024 17:37:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XJ9PStDT" Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E90F914EC43 for ; Thu, 25 Apr 2024 17:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714066656; cv=none; b=R4v+mrYMcUKpVxM2wTfAqHFxiBxKbUduu5TSVqxaTakdBeOcRP52yf35hXzGFcHIGdeOeSzur4/jtryuBvZUwp4Y37t8rIBykH83Bp0l+0pFd7BgwpdkEnrnPyFZ81e1W8OwThSDRTixY53gYb+wEAJrF3U8ccbSGT5s46X4k+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714066656; c=relaxed/simple; bh=B3VQQbOwXZfXUmtHrc/wDZo3lxxcsHSUDqcA5obudZE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=LE5MGVWGqGStRm4bK4zhqQzCuKhwJ4o2boyC+85gclpvJnCETemF9u25Hn5ZLJVe4NAG1Kbp+ULjcxXZuri6HPq0c7u20ckJk3p0T6uT/WjNd2flYqhUYer9045HZ3aFgAV+IwdwYpTZlw+UYkoVURBSYz6mPct4mv9Q1i+EA68= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XJ9PStDT; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5722eb4f852so1057a12.0 for ; Thu, 25 Apr 2024 10:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714066653; x=1714671453; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=B3VQQbOwXZfXUmtHrc/wDZo3lxxcsHSUDqcA5obudZE=; b=XJ9PStDT7Y8jirOyfZyIFA//mDF01QzJ/i1+l2MS4UIu7EfvC/h/s0R5QWRDrzx6LX aKKNDx4WYv+O8Lo+AZYp9CNX6ZL3gxV3Css62Sp8S7+8S5IDLODsuWPTgChhHmNE2ViT Ca48NN1SbWyc7WEPMrn8WHgnklcjeGi3NIMTesqDGcTp6rjvvKdcNb+9A8hSJYm+CPoV HTgnZvJlXSv6bTCSXTIXKqecDgOsmf/eZFeE5ZtYO5ZILA5LlO4rCjejf3lkueObwC6g Qi8c87B8DLqXcvmRyf+mENC7jGA2OK9LFd+u0N1DNCIKmj5Sk8hk+507CDaHkuRwv2zE Cf6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714066653; x=1714671453; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B3VQQbOwXZfXUmtHrc/wDZo3lxxcsHSUDqcA5obudZE=; b=l9NML13BCPXfMRF3SWS1utKkKinhPBMb36Hl3GlY2LdACZ/Pq96RUbzqzIIH5sS1ze V3Cqra+rdGj3ixnVl9afHWfwQEroq8ePwenQLLBGISrC9lYIuqZ5k8EnpjFl/Te2S8fN u+8dMAjDWa6SFU2HsjcYFeSwqZCBxW7fnlHiPxA3Tsf2QJESxkIdbvbaZdCV7d6X6LK1 rPrsdQ9Vx4pXFlOXgHqIT06QyIRfCQMdJUbAWffrjiAxx26BKTBir21fTlPf2AeAW0Zy CKA8i9hBMomsR+dI2i/NlVjfo9pYupS6hxNX3HiDnOAb/JgFW/FWsZf+Y/bN2Pdi6nG+ Quxg== X-Forwarded-Encrypted: i=1; AJvYcCVbzkRXXE7PdttFKGVZ9/qXJVKDVJKnscUJRIuTaIMvS5n8RcuEBuOY+o1jzgt3GL7t0X764z++aR2l6ZyOahoQe0g4HogJoRuwtPgv X-Gm-Message-State: AOJu0YyY0Tooi896S/sJbaTdL+afWvFvqBNdQ19N8tAMI2GYObBC66Vd SIOvwZ+oRf2rfJjdxFG27cbsda9bZ8EdPB4NU/vRGE9N5KisNlDm5bbS69C1NEjgPTec4aXWiTP DXwu66anSFyZPdhLlepe82R/6fLS9t6Kjjzh6 X-Received: by 2002:a05:6402:30a1:b0:572:3fb6:3d0c with SMTP id df1-20020a05640230a100b005723fb63d0cmr2428edb.4.1714066653043; Thu, 25 Apr 2024 10:37:33 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240423202356.3372314-2-rdbabiera@google.com> In-Reply-To: From: RD Babiera Date: Thu, 25 Apr 2024 10:37:21 -0700 Message-ID: Subject: Re: [PATCH v1] usb: typec: tcpm: enforce ready state when queueing alt mode vdm To: Heikki Krogerus 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 25, 2024 at 2:49=E2=80=AFAM Heikki Krogerus wrote: > I'm probable missing something, but wouldn't it be safer to check > port->state after grabbing the lock? I could have been more explicit in describing the deadlock, my bad. But there are two threads here: Thread A starts in the TCPM. It is the port state machine that transitions to DR_SWAP and holds port->lock. When it unregisters DisplayPort Alt Mode, it goes int= o the DP Alt Mode driver and hangs until any DP Alt Mode work is finished. Thread B starts in the DP Alt Mode driver. It attempts to call tcpm_enter_m= ode and the call to mutex_lock in tcpm_queue_vdm_unlock hangs because Thread A holds the lock. Thread A will never drop the lock because it waits for Thre= ad B to finish. So, the check is done before grabbing the lock because the thread needs to = avoid grabbing the lock in the first place. If port->state changes between queueing and sending the message, the VDM state machine will drop the message anyways because port->state isn't in the ready state as well. best, rd