From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4748FECAAD5 for ; Mon, 12 Sep 2022 12:02:03 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 6AE5A15F9; Mon, 12 Sep 2022 14:01:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6AE5A15F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662984121; bh=RPWT9rKsWP9FM2ux9RvEk+SvbNcKtBbwIAIZlTXQpKE=; h=Date:Subject:To:References:From:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=X2u0ykGdSYGDsXQVsN9hNjFpjs72jT5PHp/Ahd3Z6ufoZBisi8XrWHXght++KgiRP MM8wGJlndbCkJAHKbQKFZW521G/c07zxMFCIsOeZH+mqIemYiue9pOitzwKpr7WusJ eNobxpCODzqTVxHj6Wj0qayJgH6e72vxHVvr5gXM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D81A1F80558; Mon, 12 Sep 2022 14:00:18 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D329DF8053C; Mon, 12 Sep 2022 14:00:17 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3EB22F8053C for ; Mon, 12 Sep 2022 14:00:10 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3EB22F8053C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ELR4svMe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662984012; x=1694520012; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=RPWT9rKsWP9FM2ux9RvEk+SvbNcKtBbwIAIZlTXQpKE=; b=ELR4svMe5o/VtpOm7LPbmZ0p1nkICOgwYhZBS8d503CuL/LyfMkt7f9E WkuNN8aWaCVxI0zyZjXaXgvQXiKLT19lhq+tkZuIg9LHgkCCmERH26py4 a0fpNj+VFeBQArUI9x+IyOZ39sY6NqwccLjh0pG0k+vTDm1TyxztMWXOU /cUGMA9U2fZ/E49tUDBRH+H+D4vsdzfk0ikOHPvueza92KGy7NOsBeVe8 +hCEXi/ouQdk3u+fXHQ8PsS/6pIZeyh3r1UFoC2oykUZ1IRpdvJUzYS5o Nn+IdAywbHnb7pOsmxgsHX1vVf4+H4wL5hwDopwjV42cUabNtzYXowpCv w==; X-IronPort-AV: E=McAfee;i="6500,9779,10467"; a="280864762" X-IronPort-AV: E=Sophos;i="5.93,310,1654585200"; d="scan'208";a="280864762" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2022 05:00:08 -0700 X-IronPort-AV: E=Sophos;i="5.93,310,1654585200"; d="scan'208";a="705126482" Received: from vtsymbal-mobl.ger.corp.intel.com (HELO [10.252.32.67]) ([10.252.32.67]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2022 05:00:05 -0700 Message-ID: <72cd1004-e952-b167-e08d-2b5623b638fd@linux.intel.com> Date: Mon, 12 Sep 2022 13:00:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.11.0 Subject: Re: [PATCH v2 3/5] soundwire: bus: Don't re-enumerate before status is UNATTACHED Content-Language: en-US To: Richard Fitzgerald , vkoul@kernel.org, yung-chuan.liao@linux.intel.com, sanyog.r.kale@intel.com References: <20220907085259.3602-1-rf@opensource.cirrus.com> <20220907085259.3602-4-rf@opensource.cirrus.com> From: Pierre-Louis Bossart In-Reply-To: <20220907085259.3602-4-rf@opensource.cirrus.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On 9/7/22 10:52, Richard Fitzgerald wrote: > Don't re-enumerate a peripheral on #0 until we have seen and > handled an UNATTACHED notification for that peripheral. > > Without this, it is possible for the UNATTACHED status to be missed > and so the slave->status remains at ATTACHED. If slave->status never > changes to UNATTACHED the child driver will never be notified of the > UNATTACH, and the code in sdw_handle_slave_status() will skip the > second part of enumeration because the slave->status has not changed. > > This scenario can happen because PINGs are handled in a workqueue > function which is working from a snapshot of an old PING, and there > is no guarantee when this function will run. > > A peripheral could report attached in the PING being handled by > sdw_handle_slave_status(), but has since reverted to device #0 and is > then found in the loop in sdw_program_device_num(). Previously the > code would not have updated slave->status to UNATTACHED because it had > not yet handled a PING where that peripheral had UNATTACHED. > > This situation happens fairly frequently with multiple peripherals on > a bus that are intentionally reset (for example after downloading > firmware). > > Signed-off-by: Richard Fitzgerald Reviewed-by: Pierre-Louis Bossart > --- > drivers/soundwire/bus.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c > index 1cc858b4107d..6e569a875a9b 100644 > --- a/drivers/soundwire/bus.c > +++ b/drivers/soundwire/bus.c > @@ -773,6 +773,16 @@ static int sdw_program_device_num(struct sdw_bus *bus) > if (sdw_compare_devid(slave, id) == 0) { > found = true; > > + /* > + * To prevent skipping state-machine stages don't > + * program a device until we've seen it UNATTACH. > + * Must return here because no other device on #0 > + * can be detected until this one has been > + * assigned a device ID. > + */ > + if (slave->status != SDW_SLAVE_UNATTACHED) > + return 0; > + > /* > * Assign a new dev_num to this Slave and > * not mark it present. It will be marked From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96C19ECAAD5 for ; Mon, 12 Sep 2022 12:00:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbiILMAU (ORCPT ); Mon, 12 Sep 2022 08:00:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbiILMAM (ORCPT ); Mon, 12 Sep 2022 08:00:12 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E828E2A966 for ; Mon, 12 Sep 2022 05:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662984008; x=1694520008; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=RPWT9rKsWP9FM2ux9RvEk+SvbNcKtBbwIAIZlTXQpKE=; b=G6wmZWmChlM7wRXeJFBKgGU4Kr0U+R9ecrrQAztg8+9VR2ZMtSzGpIfu oyFjQNaZyIgMWzB7FUzXVB8B6gueCNwRq7EiGm+08xb5YZvIf0odaZNxi WIE7u2OORLccCBe3TXb7oKis54L7+J+6J1h5OEK/6lfL3FIHVlsZeTlNx xM8PH2QYwi1dt/TZLZ9bWXcMXA4pnh5gls/zBYjZXQdEdK3USrX1InbrT OrioUVYLG8QtAqnhk0utYX7bbydmcPL2r0YYadlZkWt2eOrtoNv22Df21 wssX8PqnRj1u1SJILWhnPLwRsyenI7K+zJR9I6U1sWOzo26+s5YPBk3d4 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10467"; a="297847496" X-IronPort-AV: E=Sophos;i="5.93,310,1654585200"; d="scan'208";a="297847496" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2022 05:00:08 -0700 X-IronPort-AV: E=Sophos;i="5.93,310,1654585200"; d="scan'208";a="705126482" Received: from vtsymbal-mobl.ger.corp.intel.com (HELO [10.252.32.67]) ([10.252.32.67]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2022 05:00:05 -0700 Message-ID: <72cd1004-e952-b167-e08d-2b5623b638fd@linux.intel.com> Date: Mon, 12 Sep 2022 13:00:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.11.0 Subject: Re: [PATCH v2 3/5] soundwire: bus: Don't re-enumerate before status is UNATTACHED Content-Language: en-US To: Richard Fitzgerald , vkoul@kernel.org, yung-chuan.liao@linux.intel.com, sanyog.r.kale@intel.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com References: <20220907085259.3602-1-rf@opensource.cirrus.com> <20220907085259.3602-4-rf@opensource.cirrus.com> From: Pierre-Louis Bossart In-Reply-To: <20220907085259.3602-4-rf@opensource.cirrus.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/7/22 10:52, Richard Fitzgerald wrote: > Don't re-enumerate a peripheral on #0 until we have seen and > handled an UNATTACHED notification for that peripheral. > > Without this, it is possible for the UNATTACHED status to be missed > and so the slave->status remains at ATTACHED. If slave->status never > changes to UNATTACHED the child driver will never be notified of the > UNATTACH, and the code in sdw_handle_slave_status() will skip the > second part of enumeration because the slave->status has not changed. > > This scenario can happen because PINGs are handled in a workqueue > function which is working from a snapshot of an old PING, and there > is no guarantee when this function will run. > > A peripheral could report attached in the PING being handled by > sdw_handle_slave_status(), but has since reverted to device #0 and is > then found in the loop in sdw_program_device_num(). Previously the > code would not have updated slave->status to UNATTACHED because it had > not yet handled a PING where that peripheral had UNATTACHED. > > This situation happens fairly frequently with multiple peripherals on > a bus that are intentionally reset (for example after downloading > firmware). > > Signed-off-by: Richard Fitzgerald Reviewed-by: Pierre-Louis Bossart > --- > drivers/soundwire/bus.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c > index 1cc858b4107d..6e569a875a9b 100644 > --- a/drivers/soundwire/bus.c > +++ b/drivers/soundwire/bus.c > @@ -773,6 +773,16 @@ static int sdw_program_device_num(struct sdw_bus *bus) > if (sdw_compare_devid(slave, id) == 0) { > found = true; > > + /* > + * To prevent skipping state-machine stages don't > + * program a device until we've seen it UNATTACH. > + * Must return here because no other device on #0 > + * can be detected until this one has been > + * assigned a device ID. > + */ > + if (slave->status != SDW_SLAVE_UNATTACHED) > + return 0; > + > /* > * Assign a new dev_num to this Slave and > * not mark it present. It will be marked