From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E64ADC55178 for ; Sun, 25 Oct 2020 16:58:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9CCD0208E4 for ; Sun, 25 Oct 2020 16:58:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="s19AaSFB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CCD0208E4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ybU31tMHTpfu382TMzqhTdvSodcQcgYxOt2EuXfPNZw=; b=s19AaSFBCtrkv5dFO+0W0Tchp FHPm1mNGyqIfqQ8DtQRw6hvPH38mya4+riDsE3CYWuwrbiStV2qJpVjEm+eotnxMfkQ9eRujvq4cL JUcrNShfwcZyECyK3scyKZ2pR03nNlBl0puBHDGdwpZYgC6txuHDK8iG6lf53msKc+SnVJID5n9is aRirHCk2mOcS43elRBfsRw/8R770O+rP7eTdFGd0CywthqGED2ZlIGQwg16Qn6iOmTHdLTsMnbS2q A3Q0kXi6MHAgdXxWeJ10R1ijLmOnSXADrUVb0nT/lkCPG81DehklkIDZHzjcRYL9MeGaSSL8GN9WW jGIkgO8RA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kWjKD-0007Et-Ly; Sun, 25 Oct 2020 16:56:57 +0000 Received: from mail-lf1-f66.google.com ([209.85.167.66]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kWjK8-0007Dy-3w for linux-arm-kernel@lists.infradead.org; Sun, 25 Oct 2020 16:56:53 +0000 Received: by mail-lf1-f66.google.com with SMTP id j30so8814199lfp.4 for ; Sun, 25 Oct 2020 09:56:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ePQFbJ/3Ad8/iX5Bs449C4InLn8t8GvqBrcAtxnaBrw=; b=lnyCxJrmJ/szjOCo2sN7YGuTJzYs4gA5k/JEX8ajEFuADw0NwQok1vUdtBOy+1llXC h61ctdmLGx8/0YQRgI385f3mkkWJ7AkAG4BatZpXvJtRcWSnECAJTmQ4GpaQSnqDyNCm +6nIwNdjV0o14xUevGb+OzpzqmnhwR22FlJQVb2Tv3719Ebm/gUOonEkViIcWrrwSRhV kvP2BvLMw7yK9ctD6XtJe3+PMfi4YB5niXH4HPGxpZL/z12J3HTyXX8lkPBumIT0BTcF j9VNfu7BvpXiJi6EUtVCSr53zBRqgVdEpi9WbG5fyxX66xZGz3zaRVzBQibA+veNW8jP ZGmw== X-Gm-Message-State: AOAM531FmhCI2QELpxDCn6oj1pK0qsa9lPiPcrTyJlM2DTrv74HSfRsK ze8QuuKqvPX7hRJOPiBabX8= X-Google-Smtp-Source: ABdhPJw0J0QYFNhrbQ5xJk2wEIsCh8he6dIVwqhUM/8GfMALjY8iyY5XhCPb37I1yXtuPPPcMA5RlQ== X-Received: by 2002:a05:6512:331a:: with SMTP id k26mr3457916lfe.349.1603645006196; Sun, 25 Oct 2020 09:56:46 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id c202sm778432lfg.133.2020.10.25.09.56.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 09:56:44 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWjK3-0004fv-U4; Sun, 25 Oct 2020 17:56:48 +0100 Date: Sun, 25 Oct 2020 17:56:47 +0100 From: Johan Hovold To: Thomas Gleixner Subject: Re: [patch V2 02/13] USB: serial: keyspan_pda: Replace in_interrupt() usage Message-ID: <20201025165647.GR26280@localhost> References: <20201019100629.419020859@linutronix.de> <20201019101109.753597069@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201019101109.753597069@linutronix.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201025_125652_213588_732A6B59 X-CRM114-Status: GOOD ( 32.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Felipe Balbi , Thomas Winischhofer , Mathias Nyman , Peter Zijlstra , Greg Kroah-Hartman , Sebastian Andrzej Siewior , linux-usb@vger.kernel.org, Johan Hovold , Krzysztof Kozlowski , LKML , linux-samsung-soc@vger.kernel.org, Kukjin Kim , Valentina Manea , Duncan Sands , "Ahmed S. Darwish" , Alan Stern , linux-omap@vger.kernel.org, Shuah Khan , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Oct 19, 2020 at 12:06:31PM +0200, Thomas Gleixner wrote: > keyspan_pda_write() uses in_interrupt() to check whether it is safe to > invoke functions which might sleep. > > The usage of in_interrupt() in drivers is phased out and Linus clearly > requested that code which changes behaviour depending on context should > either be seperated or the context be conveyed in an argument passed by the > caller, which usually knows the context. > > Aside of that it does not cover all contexts which cannot sleep, > e.g. preempt disabled regions which cannot be reliably detected on all > kernel configurations. > > With the current printk() implementation console->write() can be invoked > from almost any context. The upcoming rework of the console core will > provide thread context for console drivers which require to sleep. > > For now, restrict the room query which can sleep to tty writes which happen > from preemptible task context. > > The usability for dmesg output is limited anyway because it's almost > guaranteed to drop the 'LF' which is submitted after the dmesg line because > the device supports only one transfer on flight. Same for any printk() > which is coming in before the previous transfer has been done. > > This new restriction does not make it worse than before, but it makes the > condition correct under all circumstances. > > Signed-off-by: Ahmed S. Darwish > Signed-off-by: Sebastian Andrzej Siewior > Signed-off-by: Thomas Gleixner > Cc: Johan Hovold > Cc: Greg Kroah-Hartman > Cc: linux-usb@vger.kernel.org > > --- > drivers/usb/serial/keyspan_pda.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > --- a/drivers/usb/serial/keyspan_pda.c > +++ b/drivers/usb/serial/keyspan_pda.c > @@ -477,10 +477,12 @@ static int keyspan_pda_write(struct tty_ > > count = (count > port->bulk_out_size) ? port->bulk_out_size : count; > > - /* Check if we might overrun the Tx buffer. If so, ask the > - device how much room it really has. This is done only on > - scheduler time, since usb_control_msg() sleeps. */ > - if (count > priv->tx_room && !in_interrupt()) { > + /* > + * Check if we might overrun the Tx buffer. If so, ask the device > + * how much room it really has. This can only be invoked for tty > + * usage because the console write can't sleep. > + */ > + if (count > priv->tx_room && tty) { > u8 *room; > > room = kmalloc(1, GFP_KERNEL); There's a ton of issues with this driver, but this is arguably making things worse. A line discipline may call write() from just about any context so we cannot rely on tty being non-NULL here (e.g. PPP). I've prepared a series fixing up the driver's write implementation that does away with this room check in the write path instead. Johan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel