Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1405739pxb; Wed, 6 Apr 2022 17:58:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySCrtIk8Ln4hvuo9BQ5v24cdfwcC+HO1bBQyfkDEMacvpAzRhnfrrHHKiyaPUEjQAUUqVy X-Received: by 2002:a05:6402:4414:b0:408:4dc0:3ee9 with SMTP id y20-20020a056402441400b004084dc03ee9mr11782449eda.203.1649293109439; Wed, 06 Apr 2022 17:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649293109; cv=none; d=google.com; s=arc-20160816; b=hHlZZQ8hO0EhY8cW6y236APepWES8pv0Ldq+J5ru71WK9MjVHDTlKpEPlCZnqQluk6 tvl8S90v4g4gBlbDgg2A9dswaI8VQB+XJiyxwHwhuQB/2oDLECyQeSpzzZxriD/pLjjO TmgBTXFki2EaTrRZUh4qQ5iUtD0yw0dfkYDeHIMk9v/9df7A5aPNLLOUzMVI6Hep/v9l CVd2v8J8+DrP1NSeBL+YJwv2HOrKo9BwRq9LMZrY91zQAAblmd/NnVpOF2qibgAsJ/jl 0DYWllLfIA3i+BKPduXBmyRq7NV3LvNjuY2o8D+SMH8jfcph3Wz99Y7PJJZ2wa4dNk7T bX5w== 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=pnmAbRszvBN9WxlPlTTzuFKVYYc2qCAgsdKr50beG6U=; b=p/hm7inazxLQgYafoPhVNio2G4sIw/WtE6LDs7MgWCLBHgGvX1sIbNgNCdESV3QjXy 51MhI7zzhyJhnBlxvno/bTSPRBATYXQ+lfDHDahTwJm+XsccDh4Vez057HewK4CwGsjq 25gLBup1R5LU8BoQTu99xO9178E2h0oLjF6nHo8d/mYsA+6XYbQJuScNcv4Ubr80ziLr /v2aZxifDUztH+L59XMQxz19by0BaQ/cdvLpC3x/QA3uqU4Zu22dExgWleke2PWFG31f J86ltFbJ4iKjkr2rHiq8y93bIIJ9QMx6ssjyEDBbVSykKgmIXbqnGEcvriYokn2fBlR1 U1fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y19-20020a056402441300b00419dbec993fsi18241557eda.374.2022.04.06.17.57.35; Wed, 06 Apr 2022 17:58:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233839AbiDFUL3 (ORCPT + 99 others); Wed, 6 Apr 2022 16:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233906AbiDFUK5 (ORCPT ); Wed, 6 Apr 2022 16:10:57 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 821741B60E2 for ; Wed, 6 Apr 2022 10:51:41 -0700 (PDT) Received: (qmail 195999 invoked by uid 1000); 6 Apr 2022 13:51:40 -0400 Date: Wed, 6 Apr 2022 13:51:40 -0400 From: Alan Stern To: Maxim Devaev Cc: linux-usb@vger.kernel.org, Felipe Balbi , Greg Kroah-Hartman , Cai Huoqing , linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: gadget: f_mass_storage: break IO operations via configfs Message-ID: References: <20220406092445.215288-1-mdevaev@gmail.com> <20220406195234.4f63cb4a@reki> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220406195234.4f63cb4a@reki> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 06, 2022 at 07:52:34PM +0300, Maxim Devaev wrote: > > It's not clear to me how breaking I/O operations allows you to do a > > "force eject". It seems that what you would need is something like > > fsg_store_file() that omits the curlun->prevent_medium_removal check. > > Interrupting a lengthy I/O operation doesn't really have anything to do > > with this. > > Perhaps I chose the wrong path, it's just how my userspace code works now. > If the drive is connected to a Linux host, then in order to clear > the "file" and extract the image, I sent a SIGUSR1 signal to the "file-storage" > thread. This interrupted long IO operations, reset curlun->prevent_medium_removal > and I got the ability to extract. Oh, I see. That's kind of an unintended side effect of not calling raise_exception(). And while it does interrupt long I/O operations, it does so in non-sanctioned way. To the host it will appear as though the gadget's firmware has crashed, since the gadget will stop sending or receiving data. Eventually the host will time out and reset the gadget. Maybe that's the sort of thing you want, but I rather doubt it. > It was done in our KVM-over-IP project and worked for several years, > just now I want to do it without searching for procfs and the need > to use sudo helpers like this: > https://github.com/pikvm/kvmd/blob/1b3a2cc/kvmd/helpers/otgmsd/unlock/__init__.py > > Maybe it's worth introducing some option that will allow us to ignore > curlun->prevent_medium_removal and perform a forced extraction? > Something like "allow_force_eject" on the same lavel with "stall". Or have a separate sysfs file where any write at all will be interpreted as a forced eject. Either way would work. > Will masking the curlun->prevent_medium_removal flag be enough? I think so. But it will be blocked to some extent by long-running I/O operations, because those operations acquire the filesem rw-semaphore for reading. More precisely, each individual command holds the rw-semaphore. But the semaphore is dropped between commands, and a long-running I/O operation typically consists of many separate commands. So the blocking may be acceptable. > > Or to keep this ability restricted to the superuser, if that is desired. > > Indeed. > > > You should not call send_sig_info() directly; instead call > > raise_exception(). It already does the work you need (including some > > things you left out). > > raise_exception() assumes the setting of a new state, and I did not want to do this, > since the same does not happen when throwing a signal from userspace. Userspace isn't supposed to send the USR1 signal, only the INT, TERM, or KILL signals. USR1 is supposed to be reserved for the driver's internal use. Unfortunately, AFAIK there's no way to allow the driver to send a signal to itself without also allowing the signal to be sent by userspace. :-( And sending the signal _does_ set a new state, whether you intended to or not. Although in this case, the new state is always the same as the old state, i.e., FSG_STATE_NORMAL. Alan Stern