Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1138045rdb; Fri, 1 Dec 2023 08:00:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFznURqnGG3Z1mVzLNrhAMVXJmk4DcTujl7zDQ9YpTrfz2HC0UAnVna2P6l4YfAM2yn1S59 X-Received: by 2002:a17:902:f689:b0:1cf:d620:c641 with SMTP id l9-20020a170902f68900b001cfd620c641mr19555070plg.22.1701446411336; Fri, 01 Dec 2023 08:00:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701446411; cv=none; d=google.com; s=arc-20160816; b=dqC4PjMF5ZKL5I8IxBE1BaMGfJKLvWX/O/qHK0WhwcUX0dOFw0YPxdR381lyVvIHge N45Wiwn2ZhDik1+ZcmjG4yXbPmNzwk8EfHYfNAsCV7ZG37NUhz1sGi/BOH8pcJKAJrcB eYP18ikAT25OhC2Gqo8rg17gTrYOXVy2PRpTnz9Fyj1inVt9d+cjfpVjFEI2+oJcZKgb 1yhrGj7KtH9nDLTgFXD+PXac/7xmk1yKNcRETMxf3Vzm8uYXPEXcGe+TXPXXHf140K3F ZAKE8/fwk3t9t/Roc3wgJF6SMdGHiPAeLNYF3p6x9MMYQYhMkVylznOfu5UXvDxH3zIQ dURQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=cSMpOldTs2rHCFKmPzzVk+HJ1ifOrVk3O/ClGiWoBRU=; fh=mXrHwKK2M4IpPqCT3KxbG8s7EedmOWGPU8PKYGJihhc=; b=X1urZa6gs1vcpbkeJt6iINaLlsfbH9ZG8PvVrcJ15Z9iKPK3PfPP7SGRdlhMa488kU r3f84XCZngyQtG6b9IZxqcsMEY0ggQgX+n0al69NQeTcJyEouY2kdFaBHGJgF8EAPKYy ANxFK/zsurHxDTIlB4OWU6euXZt/em6AWSkPnj3Vxyh6ckbxOQnwSLsTB+V+IaPRMv6v 23EunqPzq3aCCQILn9HJ53qFLh2nvCifSF4qfz7OWcJ0YQ2Ie5lw9Vbi2JlXxcldbjIK /tfyneJaPBfoEZ8QGKuYfE8hyEh60Ykf5dHX4ZGGxNvbLaWezSiGDT43xY+irP/tl+SA M3pQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id v11-20020a1709028d8b00b001d00ed1185bsi3324331plo.506.2023.12.01.08.00.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 08:00:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 616288184A86; Fri, 1 Dec 2023 08:00:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjLAP7u (ORCPT + 99 others); Fri, 1 Dec 2023 10:59:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbjLAP7t (ORCPT ); Fri, 1 Dec 2023 10:59:49 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id F11AA10D0 for ; Fri, 1 Dec 2023 07:59:54 -0800 (PST) Received: (qmail 290509 invoked by uid 1000); 1 Dec 2023 10:59:53 -0500 Date: Fri, 1 Dec 2023 10:59:53 -0500 From: Alan Stern To: Douglas Anderson Cc: linux-usb@vger.kernel.org, Greg Kroah-Hartman , Simon Horman , Grant Grundler , Hayes Wang , =?iso-8859-1?Q?Bj=F8rn?= Mork , Paolo Abeni , netdev@vger.kernel.org, "David S . Miller" , Brian Geffon , Bastien Nocera , Benjamin Tissoires , Flavio Suligoi , Heikki Krogerus , Ricardo =?iso-8859-1?Q?Ca=F1uelo?= , Rob Herring , Roy Luo , Stanley Chang , Vincent Mailhol , linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: core: Save the config when a device is deauthorized+authorized Message-ID: <62b7467f-f142-459d-aa23-8bfd70bbe733@rowland.harvard.edu> References: <20231130154337.1.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231130154337.1.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 01 Dec 2023 08:00:05 -0800 (PST) On Thu, Nov 30, 2023 at 03:43:47PM -0800, Douglas Anderson wrote: > Right now, when a USB device is deauthorized (by writing 0 to the > "authorized" field in sysfs) and then reauthorized (by writing a 1) it > loses any configuration it might have had. This is because > usb_deauthorize_device() calls: > usb_set_configuration(usb_dev, -1); > ...and then usb_authorize_device() calls: > usb_choose_configuration(udev); > ...to choose the "best" configuration. > > This generally works OK and it looks like the above design was chosen > on purpose. In commit 93993a0a3e52 ("usb: introduce > usb_authorize/deauthorize()") we can see some discussion about keeping > the old config but it was decided not to bother since we can't save it > for wireless USB anyway. It can be noted that as of commit > 1e4c574225cc ("USB: Remove remnants of Wireless USB and UWB") wireless > USB is removed anyway, so there's really not a good reason not to keep > the old config. > > Unfortunately, throwing away the old config breaks when something has > decided to choose a config other than the normal "best" config. > Specifically, it can be noted that as of commit ec51fbd1b8a2 ("r8152: > add USB device driver for config selection") that the r8152 driver > subclasses the generic USB driver and selects a config other than the > one that would have been selected by usb_choose_configuration(). This > logic isn't re-run after a deauthorize + authorize and results in the > r8152 driver not being re-bound. > > Let's change things to save the old config when we deauthorize and > then restore it when we re-authorize. We'll disable this logic for > wireless USB where we re-fetch the descriptor after authorization. Would it be better to make the r8152 driver override usb_choose_configuration()? This is the sort of thing that subclassing is intended for. Alan Stern