Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4382074pxu; Wed, 9 Dec 2020 16:04:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvWI4xBezvWhgb9zD+OxbpYkIShM4T+wLhSZMLKkmsGrc201NxmeK86s01EL5LttwGtf1/ X-Received: by 2002:a50:f307:: with SMTP id p7mr4300625edm.368.1607558673766; Wed, 09 Dec 2020 16:04:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607558673; cv=none; d=google.com; s=arc-20160816; b=cufG0BHrKY6Xi8TpPrgFvqSto3Doro9ERahBfxkHX0+dHwNx8rHgZGMirjPaYi3SUh GKalBd+dYy4fV50jOogQvq4cUygMwUMOVXIW2K53LoPVniEjwYLgV0qBhQG9hbAdkSXw dDWo8AMkN2uwbTsVVFt6he0b9eMBLAwScem3GAEsVJ5FR8Oh2nPAtZFpvOK31JLgopFA KRXXb9m/SVb74Lho12WlB17ZtRpG6zlsRs8Gvc4PqfD5wpl6UgZ0WAM+3NW1Dt8K5dzS 3/4Rhw7jxHjFWkjMzAeiu8tGEFSgYyjV8CjkzcX8oj9RDPqBo1Rqq+8psY2f8UGZnfEB szlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fEDy9e6MULAxxvc3gfaoOMf7yXixV4MmveX5QoBc0M0=; b=gJWCbwtZHYZYD81jsMKkVLc040EBsbjvNDh6iS+XGEUhmS13IXOvHOrv2o+zX/ck9O TSsFoGxiNTmTcgowj6TPNCnQOV1zyPQVg0TGIkJmHRpajH+zERjGAw4qncQXUrHA5gEO j35A6bkNFTUNWduO0ipvc18YVHxn3FBhqO4gRVRPes+4HVHowyRYBt5RnV5CMtGoiL9k A9d/x5WQC0noqlIj7tCoyoAbFz2e8IidNzZD3iLunUzhxf24z/4FANEkhA3hDR7XXnAM uwjQIGWkQU0B6Sh47LtvK0O8rcEvk5JCu8PIl2wjn1f017rP+InxakN2TWU4B0Rs0sa7 oVww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TFpdJEn8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si1546993ejg.677.2020.12.09.16.04.11; Wed, 09 Dec 2020 16:04:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TFpdJEn8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729882AbgLIXsK (ORCPT + 99 others); Wed, 9 Dec 2020 18:48:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgLIXsK (ORCPT ); Wed, 9 Dec 2020 18:48:10 -0500 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C746BC0613CF for ; Wed, 9 Dec 2020 15:47:29 -0800 (PST) Received: by mail-qt1-x841.google.com with SMTP id b9so2412877qtr.2 for ; Wed, 09 Dec 2020 15:47:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fEDy9e6MULAxxvc3gfaoOMf7yXixV4MmveX5QoBc0M0=; b=TFpdJEn84BFYinB2Dg6QobxTWrhtFD+bYMceAur0R4opoz8o8WgG73WauK9wx1G+6a 35hVLIt17CA2FOx3rKigWTYiGtllriycdvLS1XDI/dsYNZiKT6tW1pIJEPGZnUcWdJOC gIBodtPVt2Ih/WvntEzQ/EwHLlJ0s36catgNg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fEDy9e6MULAxxvc3gfaoOMf7yXixV4MmveX5QoBc0M0=; b=GuqOhFyKBn6C4z6+JkuPXG7ameXbZA6AyZGoWhhJoqQv4XivE05fx0dCm0RmcKWkFW TpaW1tD0VKSuCLf10WjCRKuUeMPFv7N/+kr+RMYil/3p9SPmiHPnMDukkApXGnLF6CT8 RgJRy4YnKwix113xgjpQ6oK8wtmN5NqiTUCFJqRKBWkLW5QbbCTTsus4wwoN9E2d/PtE TdhQeqwlZpPTo+c4/6rWqNUEhHwru3t3g59uW9OaOyZ6V1FY2coAuyg0/Nv1M/5bxlL5 ttJvN4ra8+lemRV3gcjv2RWq9Ea2fyjJpwi9RsROwb8UmpfniEna3aFsQuQqDyQqmi4c tjLg== X-Gm-Message-State: AOAM530Vo3L5DKgBqVlVcqhnNQMxOxT5aiLQkOZse3CEGWcxVudsck99 4PNnEfH5dn52mxFGUxwJWpDJ/bK1C8jQK/ccA8sdVW5wMF4= X-Received: by 2002:ac8:594c:: with SMTP id 12mr6032953qtz.224.1607557648904; Wed, 09 Dec 2020 15:47:28 -0800 (PST) MIME-Version: 1.0 References: <20201203030846.51669-1-pmalani@chromium.org> <20201208093734.GD680328@kuha.fi.intel.com> <20201209161356.GI680328@kuha.fi.intel.com> <20201209171524.GK680328@kuha.fi.intel.com> In-Reply-To: From: Prashant Malani Date: Wed, 9 Dec 2020 15:47:17 -0800 Message-ID: Subject: Re: [PATCH] usb: typec: Add bus type for plug alt modes To: Heikki Krogerus Cc: "open list:USB NETWORKING DRIVERS" , Greg Kroah-Hartman , Benson Leung , Jonathan Corbet , "open list:DOCUMENTATION" , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 9, 2020 at 2:59 PM Prashant Malani wrote: > > Hi Heikki, > > On Wed, Dec 9, 2020 at 9:15 AM Heikki Krogerus > wrote: > > > > Hi Prashant, > > > > On Wed, Dec 09, 2020 at 08:22:52AM -0800, Prashant Malani wrote: > > > Hi Heikki, > > > > > > On Wed, Dec 9, 2020 at 8:14 AM Heikki Krogerus > > > wrote: > > > > > > > > On Tue, Dec 08, 2020 at 03:45:19PM -0800, Prashant Malani wrote: > > > > > Hi Heikki, > > > > > > > > > > Thanks a lot for looking at the patch. > > > > > > > > > > On Tue, Dec 8, 2020 at 1:37 AM Heikki Krogerus wrote: > > > > > > > > > > > > On Wed, Dec 02, 2020 at 07:08:47PM -0800, Prashant Malani wrote: > > > > > > > Add the Type C bus for plug alternate modes which are being > > > > > > > registered via the Type C connector class. This ensures that udev events > > > > > > > get generated when plug alternate modes are registered (and not just for > > > > > > > partner/port alternate modes), even though the Type C bus doesn't link > > > > > > > plug alternate mode devices to alternate mode drivers. > > > > > > > > > > > > I still don't understand how is the uevent related to the bus? If you > > > > > > check the device_add() function, on line 2917, kobject_uevent() is > > > > > > called unconditionally. The device does not need a bus for that event > > > > > > to be generated. > > > > > > > > > > My initial thought process was to see what is the difference in the adev device > > > > > initialization between partner altmode and plug altmode (the only difference I saw in > > > > > typec_register_altmode() was regarding the bus field). > > > > > > > > > > Yes, kobject_uevent() is called unconditionally, but it's return value isn't checked, > > > > > so we don't know if it succeeded or not. > > > > > > > > > > In the case of cable plug altmode, I see it fail with the following error[1]: > > > > > > > > > > [ 114.431409] kobject: 'port1-plug0.0' (000000004ad42956): kobject_uevent_env: filter function caused the event to drop! > > > > > > > > > > I think the filter function which is called is this one: drivers/base/core.c: dev_uevent_filter() [2] > > > > > > > > > > static int dev_uevent_filter(struct kset *kset, struct kobject *kobj) > > > > > { > > > > > struct kobj_type *ktype = get_ktype(kobj); > > > > > > > > > > if (ktype == &device_ktype) { > > > > > struct device *dev = kobj_to_dev(kobj); > > > > > if (dev->bus) > > > > > return 1; > > > > > if (dev->class) > > > > > return 1; > > > > > } > > > > > return 0; > > > > > } > > > > > > > > > > So, both the "if (dev->bus)" and "if (dev->class)" checks are failing here. In the case of partner alt modes, bus is set by the class.c code > > > > > so this check likely returns 1 in that case. > > > > > > > > OK. I understand the issue now. So I would say that the proper > > > > solution to this problem is to link the alt modes with the class > > > > instead of the bus. That is much smaller change IMO. > > > > > > Got it. Just to confirm that I understand correctly, do you mean: > > > 1. Only cable plug alt modes should be linked with the class instead of the bus. > > > > > > > > > > > > 2. All alt modes (cable plug, partner, port) should be linked with the > > > class instead of the bus > > > > > > My initial interpretation is 1.) since the bus linkage would be > > > necessary to match alt mode drivers to partner alt mode devices. > > > But, my understanding of the bus code is limited so I could be wrong; > > > could you kindly clarify? > > > > We don't need to care about the bus here. A device can be part of a > > bus and a class at the same time. I don't think there is any reason to > > limit the class to only plug alt modes, so let's just assign it to all > > of them. > > I had actually tried this earlier, but here we run into errors. > If we always set the class, then "partner" altmode device creation > fails ("port" altmode creation will likely also fail, but I haven't > verified that) > > The issue is that if we set both "class" and "bus", the device_add() > [1] code tries to create the "subsystem" symlink in the altmode > device's sysfs entry twice. > > The first creation is in the call to device_add_class_symlinks()[2] > which creates a "subsystem" file [3]. Note that if "class" is not set, > this code doesn't execute. > Next is the call to bus_add_device() [4] which again tries to create > the "subsystem" symlink [5] and fails since it already exists; this > leads to failure. > > There are 2 solutions I can see: > 1. Only set class for cable plug alt modes (which won't have a bus > set). This will avoid the double "subsystem" sysfs file creation. > 2. Change the bus_add_device() code to: > a. use the _nowarn() option of the symlink create function which > prevents the warn stack traces on -EEXIST error, and > b. check for -EEXIST return value and don't fail if so. > > 2.) Sounds good to me, but I'm not sure if it's alright to continue if > a "subsystem" symlink already exists. It looks like the "subsystem" name depends on the bus_type.name and class.name (for bus and class respectively). So it is possible the two symlinks will not point to the same location (For example, the class for typec is "typec_mux" but the bus is simply "typec"). Given this, it sounds like option 1.) might be better, but I'll defer to your suggestions. Best regards, -Prashant