Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1172553pxb; Wed, 6 Apr 2022 10:25:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOdSxFpMJnO3NagdE8YAVCHKAM7uRMaAPD3YSXks0avngHjxZaKh1gQbTTUEqcD+AbbFuI X-Received: by 2002:a17:90b:3ec9:b0:1c7:74f6:ae6e with SMTP id rm9-20020a17090b3ec900b001c774f6ae6emr11087828pjb.212.1649265943775; Wed, 06 Apr 2022 10:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649265943; cv=none; d=google.com; s=arc-20160816; b=GaubrpKVst1FfaZSnlV1Rl3Rnd+lxWNKUEoow32DAAocoKeN1IXF5i2SdBmvM1FFSs kqb+0ZQoQ1r8wxdVHzL6/ZDD257K+fUVDF8pUiOTOxTxLDClaCq2d5skZz7fEUyVqyYc mP0GAi1VGJo1CojNNwPVrOOnIcnlXJfbl6hTDSzwBM9IW0RFUdqhZ7jy7cBlgQ4F1G6C nH/rQ5E3DyiSxDsgPjlZNw8VFUgmkLlsESxQ5Wg3tvgH801l+I13eOrwsprHjjBX6qUY 41CjA5M+7zGZQsfiJhW7BibiZMzA3W5m8omcLdmbrwcin+wJRTLXdwSZ7rokjEV8A2OM 1f3Q== 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=gvvHNK31xfpOwtxJewygKdztvYJJAU335smWzM+MkoY=; b=Gk6H3c509yvNLQ7F8zrZEXof9tn1J8BtIhq/sVPmxzJNM91UCbJsLkDzyLprdGiBrk sO4aQAwGfqiacTvaHdHnmWmcRs5yWdyQVz5TpImsca+uBRyGc4CbfhWWRdGjbwo0j5VQ kB1Skgy360yw7BblGtkWj/iRkeF/1CpHNo0ST871ya3GWJ9txyOXsp/XoyL7u2LPeQBf kuUJ5bCkhNWyXiy9WaLm6MSTg/JHlvjnSKc3/ehOy2RN6Y+H3mulFCmYpAkz6E/mR8Qz JVnigFLHqG8Kpep/w7mJTpIYT5TbW6qayoMuuGc0EmvrHRZtl4vk9HIcOf3DQLGoLmFz iPjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id lp3-20020a17090b4a8300b001c69ee187d0si5810722pjb.171.2022.04.06.10.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 10:25:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 392582852AA; Wed, 6 Apr 2022 10:24:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239033AbiDFR0O (ORCPT + 99 others); Wed, 6 Apr 2022 13:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238714AbiDFRZx (ORCPT ); Wed, 6 Apr 2022 13:25:53 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 22B8F3BF8BA for ; Wed, 6 Apr 2022 08:24:46 -0700 (PDT) Received: (qmail 190547 invoked by uid 1000); 6 Apr 2022 11:24:46 -0400 Date: Wed, 6 Apr 2022 11:24:46 -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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220406092445.215288-1-mdevaev@gmail.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 12:24:45PM +0300, Maxim Devaev wrote: > Using the SIGUSR1 signal sent to the "file-storage" thread > from the userspace, it is possible to break IO operations > that block the gadget. Thus, it is possible to implement > "force eject" without stopping the gadget and umounting > it from the host side. 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. > There are two problems here: > > - In order to send a signal, we need to find the thread > in procfs, but if several mass storage gadgets are created > in the system, each process has the same name and it is > impossible to distinguish one gadget from another. > > - Root privileges are required to send the signal. > > The proposed "break_io" interface solves both problems. > It allows us to get rid of the procfs search and delegate > sending the signal to a regular user. Or to keep this ability restricted to the superuser, if that is desired. > Signed-off-by: Maxim Devaev > --- > drivers/usb/gadget/function/f_mass_storage.c | 22 ++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c > index 6ad669dde41c..e9b7c59e1dc4 100644 > --- a/drivers/usb/gadget/function/f_mass_storage.c > +++ b/drivers/usb/gadget/function/f_mass_storage.c > @@ -3239,6 +3239,27 @@ static ssize_t fsg_opts_stall_store(struct config_item *item, const char *page, > > CONFIGFS_ATTR(fsg_opts_, stall); > > +static ssize_t fsg_opts_break_io_store(struct config_item *item, > + const char *page, size_t len) > +{ > + struct fsg_opts *opts = to_fsg_opts(item); > + unsigned long flags; > + > + mutex_lock(&opts->lock); > + spin_lock_irqsave(&opts->common->lock, flags); > + > + if (opts->common->thread_task) > + send_sig_info(SIGUSR1, SEND_SIG_PRIV, > + opts->common->thread_task); 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). Alan Stern > + > + spin_unlock_irqrestore(&opts->common->lock, flags); > + mutex_unlock(&opts->lock); > + > + return len; > +} > + > +CONFIGFS_ATTR_WO(fsg_opts_, break_io); > + > #ifdef CONFIG_USB_GADGET_DEBUG_FILES > static ssize_t fsg_opts_num_buffers_show(struct config_item *item, char *page) > { > @@ -3283,6 +3304,7 @@ CONFIGFS_ATTR(fsg_opts_, num_buffers); > > static struct configfs_attribute *fsg_attrs[] = { > &fsg_opts_attr_stall, > + &fsg_opts_attr_break_io, > #ifdef CONFIG_USB_GADGET_DEBUG_FILES > &fsg_opts_attr_num_buffers, > #endif > -- > 2.35.1 >