Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp226261imw; Mon, 4 Jul 2022 08:08:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s5WsHY31Xswqno8LApkIVGCA3cunx7eC9kWZ3Gd0rU0hjDpeSmgQfcPHCv4eGBFI97hp42 X-Received: by 2002:a05:6402:452:b0:434:a373:f9f8 with SMTP id p18-20020a056402045200b00434a373f9f8mr39792935edw.290.1656947327389; Mon, 04 Jul 2022 08:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656947327; cv=none; d=google.com; s=arc-20160816; b=KIKDgg8gqITePIfH/iW3eGzUaRDUJ93CLIAHJYwkDR5T2R1/es4ouRTm00p7z6HrJs BGMPSvkYzGemO3mulDVyGNWPXC9FhhH9cS3/ifZ/mRsUi5uIgAm216UAoDI14y8Hofpq Ux9HcfEnPhbMa3lN8KNWykcPbT86ZV3X1SksjsP2uTiPMNjHA05p0Lkr14QNmgYOsc5f mXx5McszPmdTv3P5R/npojNFdJ4/gpsfyAlbKvbc0/QIyJ4Z7rD/vhe3CXsXemlLp/W8 c3Ae/a/y4SDxJ/+qX2j/SA/BZX5lCYJFkBDM5wajFkLkQfLpHl6AOH9a5GRiOoOrLrJy kcAQ== 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:dkim-signature; bh=tcCu7JlOflaUOhftN8zn6NBCcrJEEUzGyosivbilm9Y=; b=lKU3FlGLhw5kcf0ca9uhddsrC2hQaChz42aAroRZ6bIhXqRoonKvb/M7kAlVOd9aXq M+XG4cZ3WZAe9RDtQuBbD13lw4YAezvTs171d9GCuNHqu9J1lC/lesJlm8IuKad6f2N4 OgwcaYw0DkhE6E63FujGYeqFg/TyZ5mxgnKt/2Zo5aM/PFu9jSXSm9dmo3SgvHXvDDPs gZjbQq2MDI+h34m3YROEd2w55L4FARSR96E0/fznJf4MtX9Y2h7sMt6pkNk8pgKDJprn TmhfboDOkGMrouK/C+o236qAxzHqhWof2ZMwLyxEJY45FXGE1qmmre6xSjLKXliiHIBZ Ts/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=haqBElDu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw23-20020a1709066a1700b00726ab6cedddsi7785827ejc.220.2022.07.04.08.08.20; Mon, 04 Jul 2022 08:08:47 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=haqBElDu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233357AbiGDObJ (ORCPT + 99 others); Mon, 4 Jul 2022 10:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiGDObI (ORCPT ); Mon, 4 Jul 2022 10:31:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2212C38A4; Mon, 4 Jul 2022 07:31:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B249B61667; Mon, 4 Jul 2022 14:31:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96D15C3411E; Mon, 4 Jul 2022 14:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656945064; bh=abX2vFyPPxtUJL8wR+WOgxjRHK6sRVK3yADC3+pFltw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=haqBElDu9pTENB2dVUV2nrZD5Uk0XFiKbqJc2LFiDC8sy+CbpiUEMZ43KKyPpqV1x wDKhunuPle1p/Hsmj8Zbs1/T1Pr9JwbUFBtP4g9uE3vIjIg2iH4FfgWs918wPTj54n AL0mouy/oyRePOLwILDmV2KyPST9gEVWWUnaPpuc= Date: Mon, 4 Jul 2022 16:31:01 +0200 From: Greg KH To: Tetsuo Handa Cc: "Rafael J. Wysocki" , Len Brown , Pavel Machek , arnd@arndb.de, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH] char: misc: make misc_open() and misc_register() killable Message-ID: References: <000000000000d9ff3a05bb37069e@google.com> <72e74af9-f1b6-e383-a2c3-6ee8a0aea5e0@I-love.SAKURA.ne.jp> <100f445e-9fa8-4f37-76aa-8359f0008c59@I-love.SAKURA.ne.jp> <01a93294-e323-b9ca-7e95-a33d4b89dc47@I-love.SAKURA.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <01a93294-e323-b9ca-7e95-a33d4b89dc47@I-love.SAKURA.ne.jp> X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mon, Jul 04, 2022 at 09:34:04PM +0900, Tetsuo Handa wrote: > On 2022/07/04 20:01, Greg KH wrote: > > On Mon, Jul 04, 2022 at 07:25:44PM +0900, Tetsuo Handa wrote: > >> On 2022/07/04 16:29, Greg KH wrote: > >>> On Mon, Jul 04, 2022 at 03:44:07PM +0900, Tetsuo Handa wrote: > >>>> syzbot is reporting hung task at misc_open() [1], for snapshot_open() from > >>>> misc_open() might sleep for long with misc_mtx held whereas userspace can > >>>> flood with concurrent misc_open() requests. Mitigate this problem by making > >>>> misc_open() and misc_register() killable. > >>> > >>> I do not understand, why not just fix snapshot_open()? Why add this > >>> complexity to the misc core for a foolish individual misc device? Why > >>> not add the fix there where it is spinning instead? > >> > >> Quoting an example from [1]. Multiple processes are calling misc_open() and > >> all but one processes are blocked at mutex_lock(&misc_mtx). The one which is > >> not blocked at mutex_lock(&misc_mtx) is also holding system_transition_mutex. > > > > And that is because of that one misc device, right? Why not fix that > > instead of papering over the issue in the misc core? > > Since "struct file_operations"->open() is allowed to sleep, calling > "struct file_operations"->open() via reassignment by "struct miscdevice"->fops > with locks held can cause problems. > > Assuming that this is not a deadlock hidden by device_initialize(), current > mutex_lock(&misc_mtx) is as problematic as major_names_lock mentioned at > https://lkml.kernel.org/r/b2af8a5b-3c1b-204e-7f56-bea0b15848d6@i-love.sakura.ne.jp . > > >> If you don't like mutex_lock_killable(&misc_mtx), we will need to consider moving > >> file->f_op->open() from misc_open() to after mutex_unlock(&misc_mtx). > > Below is minimal changes for avoid calling "struct file_operations"->open() with > misc_mtx held. This would be nothing but moving hung task warning from misc_open() > to snapshot_open() (and therefore we would need to introduce killable version of > lock_system_sleep()), but we can avoid making misc_mtx like major_names_lock above. > > Greg, can you accept this minimal change? > > drivers/char/misc.c | 4 ++++ > include/linux/miscdevice.h | 1 + > kernel/power/user.c | 1 + > 3 files changed, 6 insertions(+) I don't understand what you are trying to "fix" here. What is userspace doing (as a normal user) that is causing a problem, and what problem is it causing and for what device/hardware/driver is this a problem? Yes, you can sleep in open(), but you shouldn't sleep long, if at all possible as it can be annoying. So why not fix up the offending driver not to sleep to long? thanks, greg k-h