Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1290625rdb; Wed, 24 Jan 2024 10:18:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRwMD8w81MhBHwUE2ftDXNwuiHQTzvlRJDp77Df+ovDtYRWgoPkwiVjI7vkLdxQR1Cf0qd X-Received: by 2002:a17:90b:1244:b0:28c:93f:974d with SMTP id gx4-20020a17090b124400b0028c093f974dmr4311263pjb.70.1706120313078; Wed, 24 Jan 2024 10:18:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706120313; cv=pass; d=google.com; s=arc-20160816; b=c21uRmajvN6Uo/7iVbTykQfHLU7IyQ/NNXZLY2oVfpi0DxlU1in/S2Cn6rOrTiStib Le0C73HwEVi71znlEX5+1anfgiFnz44fX4FuqdKPG0n2ncs/TPblIUVYbD0BZGhMWdDr WONKYAiIb4Bat2snO/8taiY4NYxOXUFK5WBF0RID7AwdbEbcmh6xN7rJs7TF/sSRG3Nx tIqa1v7RaO+GrBGlzK5GOHDBesecGI+61KtNXECk1SD5XCNJOARoWkjqPsEpH+Q0bUKP I9rD3/FEWB0FKXHkUvxOLPCz1CYm4cXx7iMILPavLj687w/RLRl430COqDM81e5VACo0 3Jiw== 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=JnWW0YGIRHhj9FPB5uwq6ip9sjkkaSOo+b0b10q2ru4=; fh=/HiAJTt/CIa+hjPfMobP5rj6c+JZjqo1vaC2HndtZxs=; b=Bl113Hr3hKu2VQct86GovWrtNXBraUJqu6/su+DDCwZGiv4cgMy40OHSHTvrUJqxrm AXZEYFlhBsFa8vE4jfzbZ//qtlxUWo1fRPgNF+uLEw/SE99HUBObxJpM3GbRTsJncOeD OgEuTAL/4LOTq9msG6RXot+9j4Ze1JzFgntfgC204y7Js1LJO7zqj6aFRah1CWy7hjdZ UaaEmFtOiuybmgJ4FK9eNKWCWlx0jlv8XTQ7tu5LGtufvAFVRkL/sdseb9VdPUFTwI8P G02cR0R7DW9X64A/jux/g2ua9TL7q72N3PXJRvpG6ybruX5E6MFKogErH+c5stKAjYzb Se7w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RN2ZUfo7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37050-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37050-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h21-20020a17090aa89500b002903bdecbeasi10448579pjq.104.2024.01.24.10.18.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 10:18:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37050-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RN2ZUfo7; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37050-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37050-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 411972870FC for ; Wed, 24 Jan 2024 13:08:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D70277F0B; Wed, 24 Jan 2024 13:08:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RN2ZUfo7" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 9167977640; Wed, 24 Jan 2024 13:08:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101717; cv=none; b=ijxhzKGtlm9GgY76aw5QQJ2nCZr/+3WWol4CpZxcTrEVaeeub8meABzxNkmveo8ykID+1BNiQdgGGbw1Xtp0xGuocpAeGPGbLVxCPfOcei67Z9RLpipPQ1ohxO3GU8irzWF5EDRjFdXVw4eThbK9KsVMK3mpMU1wToIO9mNLhIU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101717; c=relaxed/simple; bh=LRKdvEQWoCEx4ySV7N81w6fG9TXYEayrBjmBpv5mIUM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M/pFWPKkgr7kTq1wkEexq1d6jkj8BpLgqd1ytYXUZclYyUaHxQdBesqe1HBKT9KY0iWGv32kUvz9zClTPWAFGFiMsyih/RvqtfilEwWTFZB2sNnlwC98QQGB4h95uFNmffKftLGCaUciIuW6nBA3x2hRIWkHrMslicYxSEbjp5Q= 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=RN2ZUfo7; arc=none smtp.client-ip=192.198.163.8 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=1706101715; x=1737637715; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=LRKdvEQWoCEx4ySV7N81w6fG9TXYEayrBjmBpv5mIUM=; b=RN2ZUfo7PHjrnmDobH2GtdPWshoIE815A9QbeAygdNbFFifOur2Z6xs9 rAo8Nj/3ES4xnHDrst+hU5acZv/D29zLyH8H8yjzoaPs+Qs9992uZMg4f qABxPxN+pL5SvJ39pxygq3o9+Xm+drTPL+Tcv78H0f746u9xpsXkZIXo/ BqpzCYlvyrsMMt1/PnMLOZl7ED5/N7Ic7SjLeer++zTpbHj0BJITOvpf7 IBfq5iWanP8EmyA1s4qcyjGEzMks79+REgeBWrzLNGxWfwetadyIeU8gR JKjrTX89DX3Fe06n4fPyoaFgK0X6zWIdOykU73iyrL+ov9HQ8ri6nIQwv g==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="15361425" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="15361425" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 05:08:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="929680051" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="929680051" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmsmga001.fm.intel.com with SMTP; 24 Jan 2024 05:08:30 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Wed, 24 Jan 2024 15:08:30 +0200 Date: Wed, 24 Jan 2024 15:08:30 +0200 From: Heikki Krogerus To: "Christian A. Ehrhardt" Cc: linux-usb@vger.kernel.org, Dell.Client.Kernel@dell.com, Greg Kroah-Hartman , Neil Armstrong , Hans de Goede , Jack Pham , Fabrice Gasnier , Samuel =?utf-8?B?xIxhdm9q?= , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/3] usb: ucsi: Add missing ppm_lock Message-ID: References: <20240121204123.275441-1-lk@c--e.de> <20240121204123.275441-2-lk@c--e.de> 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: On Wed, Jan 24, 2024 at 01:04:06PM +0100, Christian A. Ehrhardt wrote: > > Hi Heikki, > > Thanks for looking into this. > > On Wed, Jan 24, 2024 at 10:09:04AM +0200, Heikki Krogerus wrote: > > On Sun, Jan 21, 2024 at 09:41:21PM +0100, Christian A. Ehrhardt wrote: > > > Calling ->sync_write must be done while holding the PPM lock as > > > the mailbox logic does not support concurrent commands. > > > > > > At least since the addition of partner task this means that > > > ucsi_acknowledge_connector_change should be called with the > > > PPM lock held as it calls ->sync_write. > > > > > > Thus protect the only call to ucsi_acknowledge_connector_change > > > with the PPM. All other calls to ->sync_write already happen > > > under the PPM lock. > > > > > > Fixes: b9aa02ca39a4 ("usb: typec: ucsi: Add polling mechanism for partner tasks like alt mode checking") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Christian A. Ehrhardt > > > --- > > > drivers/usb/typec/ucsi/ucsi.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c > > > index 61b64558f96c..8f9dff993b3d 100644 > > > --- a/drivers/usb/typec/ucsi/ucsi.c > > > +++ b/drivers/usb/typec/ucsi/ucsi.c > > > @@ -935,7 +935,9 @@ static void ucsi_handle_connector_change(struct work_struct *work) > > > > > > clear_bit(EVENT_PENDING, &con->ucsi->flags); > > > > > > + mutex_lock(&ucsi->ppm_lock); > > > ret = ucsi_acknowledge_connector_change(ucsi); > > > + mutex_unlock(&ucsi->ppm_lock); > > > if (ret) > > > dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret); > > > > Is this really actually fixing some issue? The function has already > > taken the connector lock, so what exactly could happen without this? > > I've definitely _seen_ issues with the quirk from PATCH 3/3 if the > lock is missing. I'm pretty sure from looking at the code that races > with other connectors can happen without the quirk, too. > > The PPM lock protects the Mailbox and the ACK_PENDING/COMMAND_PENDING > bits and I could observe cases where ucsi_acpi_sync_write() was entered > with the COMMAND_PENDING bit already set. One possible sequence is this: > > ucsi_connector_change() for connector #1 > => schedules partner tasks > => Acks the connector change > => Releases locks > ucsi_connecotr_change() for connector #2 > => acquire con lock for #2 > => Start to process connector state change > => Processing reaches the point right before > ucsi_acknowledge_connector_change() > Connector #1 workqueue starts to process one of the partner tasks > => Acquire con lock for connector #1 > => Acquire ppm lock > => Enter ucsi_exec_command() > => ->sync_write() starts to use the mailbox and sets > COMMAND_PENDING > => ->sync_write blocks waiting for the command completion > with wait_for_completion_timeout(). > ucsi_connector_change() for connector #2 continues > => execute ucsi_acknowledge_connector_change() and start using > the mailbox that is still in use. > => BOOM > > There is a simpler an much more likely sequence with the dell quirk active. Okay. Reviewed-by: Heikki Krogerus -- heikki