Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1829857ioo; Fri, 27 May 2022 19:24:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjnuHt/vZ2zY4c1M3WhYVNZ+q5tTndxsut0C5L0iYwoXRfYJwGdlWK7zVZbs41tFsIHP8E X-Received: by 2002:a65:63d9:0:b0:374:6b38:c6b3 with SMTP id n25-20020a6563d9000000b003746b38c6b3mr39985550pgv.195.1653704671186; Fri, 27 May 2022 19:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653704671; cv=none; d=google.com; s=arc-20160816; b=z8noX1sMeETvQ4Jf+vKoilFx715Vw5SBV5DTvFw7kKWfZgPR8AHyZqZg3smE9a7jo8 hH1UugExgSXW7bC1sSi22LSIodF0lyfQYN6zrgkhvB3nTE1OFev5t1lA1xOZOQAtdOMz aaV9bemHsmpcgZK9ByLhaqRrcoeaU29T9GXBiKgPhAOdCAYFLLOp1hkjffONG0Fx3STw /lD4jhrz6D8Z00Ql8ow+2HCvWWAVAAUBX9LhhI3W96pqlChKWXx6iWGpfwITvbTozIax Erl9hpwrrgD3WWzrCwCHa+Pz7IVAXoZ/Fy8YYY5cR/O/x/+u6LfWvK4OZEzkAPKo0/7P DDdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=32tHU9oFrbasp6sYkRxjcfqhJzKVUPxs4GEFSaVxhJY=; b=aqv9PfZmeQxTiwCjQaIZ13h+HxEbkGC5bZY4+kODM2cLAFvx2cydDfdNRzd4dqvp8c aHGvAek/h7DUWhiBvmJ90c/2npStNa+6CktUJysAVlpXeNCmh2kAF9hySb63hhn3OH5R IDfSLV8/AWNPuCZlAQYiz0ccYz+xiF9BIBCIZsTzO5AFrblLiVyA52/a+Qyyh7VGmasX 2PhE3Mqh+snALPp8zdDoLBXoMPhmvX7hpURYqZM0kgeOFQTcm9IezWI0FWKUF7IwUhhY t2CdTqtKJLALcfkzuTJyPcMQhmrv03NFJjae0AEKEVrVMdxlS/8EB+V2Bbyf2T+3gE1B zoug== 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 i18-20020a17090acf9200b001c73b8066e0si4089005pju.74.2022.05.27.19.24.18; Fri, 27 May 2022 19:24:30 -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 S1346728AbiE0K7i (ORCPT + 99 others); Fri, 27 May 2022 06:59:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350414AbiE0K7g (ORCPT ); Fri, 27 May 2022 06:59:36 -0400 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94ADB12E30F; Fri, 27 May 2022 03:59:34 -0700 (PDT) Received: from mail-yb1-f170.google.com ([209.85.219.170]) by mrelayeu.kundenserver.de (mreue108 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MxDck-1nagUG2Bui-00xdsr; Fri, 27 May 2022 12:59:32 +0200 Received: by mail-yb1-f170.google.com with SMTP id h75so1298847ybg.4; Fri, 27 May 2022 03:59:32 -0700 (PDT) X-Gm-Message-State: AOAM530ThosBoAXjZMTkPJhZKMvYR+9cTw+Q2VrK51YA9X7ew3QblMrP 79m/8lRD2Rhu1ujASVk3pKJFm9mDDp/A0cOTRTI= X-Received: by 2002:a25:31c2:0:b0:641:660f:230f with SMTP id x185-20020a2531c2000000b00641660f230fmr39185871ybx.472.1653649171073; Fri, 27 May 2022 03:59:31 -0700 (PDT) MIME-Version: 1.0 References: <20220419211658.11403-1-apais@linux.microsoft.com> <20220419211658.11403-2-apais@linux.microsoft.com> In-Reply-To: From: Arnd Bergmann Date: Fri, 27 May 2022 12:59:14 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC 1/1] drivers/dma/*: replace tasklets with workqueue To: Vinod Koul Cc: Arnd Bergmann , Linus Walleij , Allen Pais , Vincent Guittot , olivier.dautricourt@orolia.com, Stefan Roese , Kees Cook , linux-hardening@vger.kernel.org, Ludovic Desroches , Tudor Ambarus , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list , Nicolas Saenz Julienne , Paul Cercueil , Eugeniy.Paltsev@synopsys.com, Gustavo Pimentel , Viresh Kumar , Andy Shevchenko , Leo Li , zw@zh-kernel.org, Zhou Wang , Shawn Guo , Sascha Hauer , Sean Wang , Matthias Brugger , =?UTF-8?Q?Andreas_F=C3=A4rber?= , Manivannan Sadhasivam , Logan Gunthorpe , Sanjay R Mehta , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Andy Gross , Bjorn Andersson , Krzysztof Kozlowski , green.wan@sifive.com, Orson Zhai , Baolin Wang , Lyra Zhang , Patrice CHOTARD , Chen-Yu Tsai , =?UTF-8?Q?Jernej_=C5=A0krabec?= , Samuel Holland , dmaengine@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:IrdVXaCr/iQtw8Mck98AsO+WGMa/ZodKqN96B4Fe1uabK65AnL7 qYJYWPEtVpl71RH8M1VJTEepWOeuHOdLQTEccRWOScPR0b/K6grHXTstGWc0MJdhPmm5/iD RLmb2aBLaf6qFyAt/sFBLJUDTI0X7Ax3fY8B7emLb+jIZatyVJIDkSK9bLQeP+aTME7fVix 8Q/2xDAhL8s26m5R1nxJQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:vfPV2nj/JfM=:fUkfskn5IOihfv8fgcki9k SOkN6pDqUGp5rpc6YmE1oMxJgrXlQB9h6YumlrlW2EF5PCcNkxPICw+FF1q58cURiaPdB+gko XBtzda1lOqZ5bgo5IwI7/0iCsDtsoWaoGDtiFsJGq3Kisyc12QzOwfLZhfpHkVebAGkO4iXzy mFWJ6VW7gaVK8AoDkpd+nf0dwM8t3N8qW2qriHxZI2qNkC5zyXQtN9nNRIrz6FcWxcB9r/8F9 JKv5Kz3JkP/ly+nYznDw6RubyVfa7NRIYqVG/uZbvinKyLkSpq6gXJv5O0yc5oxrqWhmlvwGf dGhoTKaztcDUuvJH+141XAdZAJXYFdhp+TDmn+KzDwbpNRaF0hFmtbT8VRcYOEP1LbulIw4nW yOSBXLjj5dVAWuUqX3WfX7DUZvpK4pESfNTRkyKVLkGTiDnDX0zpkATX9x/shAOYDJ5Z6kIFp 2kmuOR7yr3Zp+sGb0JK+lqmHkJ4rqOySQ7zOBsQz8tTo6Gjj1F2LA+4mz+YUTPP0MaKbGN84x 0sbqszOiJqN8bj0ybzud225hlABU+aKnR6tuSYNoRt2YtaBe6aPou8rcA2dHcU/N/m7xnzGra VvlZqbXNGY4zKm6UtVprVGmnZFQCti/0EBbqxulQhzeHrZahDUqjnzHam2ZkO2pNUJvR0r3RX 2yhd4hVQCgg2Hhdjzr0oHUQONwqdGifWTZuDvtjt6ZoaQdnxT6QgBOJLR7nbaZZnIbuLhGSGr 4f8s+hd3ZhlZSkhJzHbbySABs5775zvSHG2oXA== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 Fri, May 27, 2022 at 10:06 AM Vinod Koul wrote: > On 25-05-22, 13:03, Arnd Bergmann wrote: > > What might work better in the case of the dmaengine API would > > be an approach like: > > > > 1. add helper functions to call the callback functions from a > > tasklet locally defined in drivers/dma/dmaengine.c to allow > > deferring it from hardirq context > > > > 2. Change all tasklets that are not part of the callback > > mechanism to work queue functions, I only see > > xilinx_dpdma_chan_err_task in the patch, but there > > may be more > > > > 3. change all drivers to move their custom tasklets back into > > hardirq context and instead call the new helper for deferring > > the callback. > > > > 4. Extend the dmaengine callback API to let slave drivers > > pick hardirq, tasklet or task context for the callback. > > task context can mean either a workqueue, or a threaded > > IRQ here, with the default remaining the tasklet version. > > That does sound a good idea, but I dont know who will use the workqueue > or a threaded context here, it might be that most would default to > hardirq or tasklet context for obvious reasons... If the idea is to remove tasklets from the kernel for good, then the choice is only between workqueue and hardirq at this point. The workqueue version is the one that would make sense for any driver that just defers execution from the callback down into task context. If that gets called in task context already, the driver can be simpler. I took a brief look at the roughly 150 slave drivers, and it does seem like very few of them actually want task context: * Over Half the drivers just do a complete(), which could probably be pulled into the dmaengine layer and done from hardirq, avoiding the callback entirely * A lot of the remaining drivers have interrupts disabled for the entire callback, which means they might as well use hardirqs, regardless of what they want * drivers/crypto/* and drivers/mmc/* tend to call another tasklet to do the real work. * drivers/ata/sata_dwc_460ex.c and drivers/ntb/ntb_transport.c probably want task context * Some drivers like sound/soc/sh/siu_pcm.c start a new DMA from the callback. Is that allowed from hardirq? If we do the first three steps above, and then add a 'struct completion' pointer to dma_async_tx_descriptor as an alternative to the callback, that would already reduce the number of drivers that end up in a tasklet significantly and should be completely safe. Unfortunately we can't just move the rest into hardirq context because that breaks anything using spin_lock_bh to protect against concurrent execution of the tasklet. A possible alternative might be to then replace the global dmaengine tasklet with a custom softirq. Obviously those are not so hot either, but dmaengine could be considered special enough to fit in the same category as net_rx/tx and block with their global softirqs. Arnd