From patchwork Mon Nov 16 16:21:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11909739 X-Patchwork-Delegate: kuba@kernel.org 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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 D3291C4742C for ; Mon, 16 Nov 2020 16:21:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EE5F217A0 for ; Mon, 16 Nov 2020 16:21:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="B4moO4Yl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vz7XVscu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731937AbgKPQVY (ORCPT ); Mon, 16 Nov 2020 11:21:24 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:42138 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731791AbgKPQVX (ORCPT ); Mon, 16 Nov 2020 11:21:23 -0500 From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1605543681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PruUOlPfnj8E5tSIjr63DwXZAV48I0qrDxF2pgYMOa0=; b=B4moO4YlQKYcBzNpk6q6UVV7iTPyKXK3a7tnD9SIXTbYZXVwu8y3yGOY2523TkYhCOdUIt dIg0Eym0aX6E41ia9oSwH+dVZ3Pg//jg53+faq9Dyc6F4r7huVfSYu83W5JwRVFNVAl40U O/cm8u8yoxyHhXKl4+QNI5+L4LrBA3wbl7NsseVNCc5MMaCp1/b04skKdB1zNvAtPBEGKi 6VAIFtjkzUy7g/xi9IrR0b20cXxxgNHMPTOL5azx3kUdiqtPMxgRdqe5bs5W5NxkCdUcyI 4h7wlaBxR8Pblx0Su4CjvVHmPJY18GxHNhK650dL0hG/A+XdA538omx0gDnwLQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1605543681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PruUOlPfnj8E5tSIjr63DwXZAV48I0qrDxF2pgYMOa0=; b=vz7XVscu4zH+dtG9j33pYZcQoH8zQmM1y0ftdMKp87elrLcoD9Mp2G6XT0rPoLQtgBZY1T /5rjpEiFwWybZ8Aw== To: linux-atm-general@lists.sourceforge.net Cc: Chas Williams <3chas3@gmail.com>, netdev@vger.kernel.org, Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 1/3] atm: nicstar: Unmap DMA on send error Date: Mon, 16 Nov 2020 17:21:14 +0100 Message-Id: <20201116162117.387191-2-bigeasy@linutronix.de> In-Reply-To: <20201116162117.387191-1-bigeasy@linutronix.de> References: <20201116162117.387191-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The `skb' is mapped for DMA in ns_send() but does not unmap DMA in case push_scqe() fails to submit the `skb'. The memory of the `skb' is released so only the DMA mapping is leaking. Unmap the DMA mapping in case push_scqe() failed. Fixes: 864a3ff635fa7 ("atm: [nicstar] remove virt_to_bus() and support 64-bit platforms") Cc: Chas Williams <3chas3@gmail.com> Signed-off-by: Sebastian Andrzej Siewior --- drivers/atm/nicstar.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c index 7af74fb450a0d..09ad73361879e 100644 --- a/drivers/atm/nicstar.c +++ b/drivers/atm/nicstar.c @@ -1706,6 +1706,8 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb) if (push_scqe(card, vc, scq, &scqe, skb) != 0) { atomic_inc(&vcc->stats->tx_err); + dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), skb->len, + DMA_TO_DEVICE); dev_kfree_skb_any(skb); return -EIO; } From patchwork Mon Nov 16 16:21:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11909737 X-Patchwork-Delegate: kuba@kernel.org 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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 B8787C4742C for ; Mon, 16 Nov 2020 16:21:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C55921D7E for ; Mon, 16 Nov 2020 16:21:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bZxr/3gF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0wC5Vcsw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731945AbgKPQV2 (ORCPT ); Mon, 16 Nov 2020 11:21:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731782AbgKPQVX (ORCPT ); Mon, 16 Nov 2020 11:21:23 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3D5C0613CF for ; Mon, 16 Nov 2020 08:21:23 -0800 (PST) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1605543681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4XdsPHV3mCyVzy7ZIKI8ieqE/6aF9GvT/f/X/zzyrUU=; b=bZxr/3gF/xqklWUwfR6uEB4uwDT4PzLnfLKKEk9/471wifaW7IQdUBQ5bUk6GaTQ1q+9zm 3jypxJFMAXM2n9jQnfft2OiqeN71/+kykx4rltW2g9HJL6u506z6KuP7YKgMyTGRzynnr0 CIn0zYZKy8dr0Ivy1CSCCoyj4NCgDRd4ZEQpXNgEzqAny8er0HIJwrPgE7zCk+i3VIft58 puOSw7SZzW8cguQobBg2+KHcLg3sA7O3aG5GtF0wK49dGCRTwLHwYSgHJmZkEGTEvxowtr EY1G91yQvHH0Jm2+FUijtkrIiLZBVp10RZMuILQGvfW7YFFQW1L5h0/MnF4pvw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1605543681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4XdsPHV3mCyVzy7ZIKI8ieqE/6aF9GvT/f/X/zzyrUU=; b=0wC5VcswbHD8fF7TvOAyrQu/xz8cNKBsoWBs7tSwpaocz4jwRu7XKyvVtj7EmjJbp6zGRn pzgM70Gb95ZtrnDA== To: linux-atm-general@lists.sourceforge.net Cc: Chas Williams <3chas3@gmail.com>, netdev@vger.kernel.org, Thomas Gleixner , Sebastian Andrzej Siewior , Jakub Kicinski Subject: [PATCH 2/3] atm: nicstar: Replace in_interrupt() usage Date: Mon, 16 Nov 2020 17:21:15 +0100 Message-Id: <20201116162117.387191-3-bigeasy@linutronix.de> In-Reply-To: <20201116162117.387191-1-bigeasy@linutronix.de> References: <20201116162117.387191-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org push_scqe() uses in_interrupt() to figure out if it is allowed to 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 separated or the context be conveyed in an argument passed by the caller, which usually knows the context. Aside of that in_interrupt() is not correct as it does not catch preempt disabled regions which neither can sleep. ns_send() (the only caller of push_scqe()) has the following callers: - vcc_sendmsg() used as proto_ops::sendmsg is expected to be invoked in preemtible context. -> vcc->dev->ops->send() (ns_send()) - atm_vcc::send via atmdev_ops::send either directly (pointer copied by atm_init_aal34() or atm_init_aal5()) or via atm_send_aal0(). This is invoked by drivers (like br2684, clip, pppoatm, ...) which are called from net_device_ops::ndo_start_xmit with BH disabled. Add atmdev_ops::send_bh which is used by callers from BH context (atm_send_aal*()) and if this callback missing then ::send is used instead. Implement this callback in nicstar and use it to replace in_interrupt(). Cc: netdev@vger.kernel.org Cc: Chas Williams <3chas3@gmail.com> CC: Jakub Kicinski Signed-off-by: Sebastian Andrzej Siewior --- drivers/atm/nicstar.c | 24 ++++++++++++++++++------ include/linux/atmdev.h | 1 + net/atm/raw.c | 12 ++++++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c index 09ad73361879e..5c7e4df159b91 100644 --- a/drivers/atm/nicstar.c +++ b/drivers/atm/nicstar.c @@ -130,8 +130,9 @@ static int ns_open(struct atm_vcc *vcc); static void ns_close(struct atm_vcc *vcc); static void fill_tst(ns_dev * card, int n, vc_map * vc); static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb); +static int ns_send_bh(struct atm_vcc *vcc, struct sk_buff *skb); static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd, - struct sk_buff *skb); + struct sk_buff *skb, bool may_sleep); static void process_tsq(ns_dev * card); static void drain_scq(ns_dev * card, scq_info * scq, int pos); static void process_rsq(ns_dev * card); @@ -160,6 +161,7 @@ static const struct atmdev_ops atm_ops = { .close = ns_close, .ioctl = ns_ioctl, .send = ns_send, + .send_bh = ns_send_bh, .phy_put = ns_phy_put, .phy_get = ns_phy_get, .proc_read = ns_proc_read, @@ -1620,7 +1622,7 @@ static void fill_tst(ns_dev * card, int n, vc_map * vc) card->tst_addr = new_tst; } -static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb) +static int _ns_send(struct atm_vcc *vcc, struct sk_buff *skb, bool may_sleep) { ns_dev *card; vc_map *vc; @@ -1704,7 +1706,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb) scq = card->scq0; } - if (push_scqe(card, vc, scq, &scqe, skb) != 0) { + if (push_scqe(card, vc, scq, &scqe, skb, may_sleep) != 0) { atomic_inc(&vcc->stats->tx_err); dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), skb->len, DMA_TO_DEVICE); @@ -1716,8 +1718,18 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb) return 0; } +static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb) +{ + return _ns_send(vcc, skb, true); +} + +static int ns_send_bh(struct atm_vcc *vcc, struct sk_buff *skb) +{ + return _ns_send(vcc, skb, false); +} + static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd, - struct sk_buff *skb) + struct sk_buff *skb, bool may_sleep) { unsigned long flags; ns_scqe tsr; @@ -1728,7 +1740,7 @@ static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd, spin_lock_irqsave(&scq->lock, flags); while (scq->tail == scq->next) { - if (in_interrupt()) { + if (!may_sleep) { spin_unlock_irqrestore(&scq->lock, flags); printk("nicstar%d: Error pushing TBD.\n", card->index); return 1; @@ -1773,7 +1785,7 @@ static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd, int has_run = 0; while (scq->tail == scq->next) { - if (in_interrupt()) { + if (!may_sleep) { data = scq_virt_to_bus(scq, scq->next); ns_write_sram(card, scq->scd, &data, 1); spin_unlock_irqrestore(&scq->lock, flags); diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h index 5d5ff2203fa22..d7493016cd466 100644 --- a/include/linux/atmdev.h +++ b/include/linux/atmdev.h @@ -186,6 +186,7 @@ struct atmdev_ops { /* only send is required */ void __user *arg); #endif int (*send)(struct atm_vcc *vcc,struct sk_buff *skb); + int (*send_bh)(struct atm_vcc *vcc, struct sk_buff *skb); int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags); void (*phy_put)(struct atm_dev *dev,unsigned char value, unsigned long addr); diff --git a/net/atm/raw.c b/net/atm/raw.c index b3ba44aab0ee6..2b5f78a7ec3e4 100644 --- a/net/atm/raw.c +++ b/net/atm/raw.c @@ -54,6 +54,8 @@ static int atm_send_aal0(struct atm_vcc *vcc, struct sk_buff *skb) kfree_skb(skb); return -EADDRNOTAVAIL; } + if (vcc->dev->ops->send_bh) + return vcc->dev->ops->send_bh(vcc, skb); return vcc->dev->ops->send(vcc, skb); } @@ -71,7 +73,10 @@ int atm_init_aal34(struct atm_vcc *vcc) vcc->push = atm_push_raw; vcc->pop = atm_pop_raw; vcc->push_oam = NULL; - vcc->send = vcc->dev->ops->send; + if (vcc->dev->ops->send_bh) + vcc->send = vcc->dev->ops->send_bh; + else + vcc->send = vcc->dev->ops->send; return 0; } @@ -80,7 +85,10 @@ int atm_init_aal5(struct atm_vcc *vcc) vcc->push = atm_push_raw; vcc->pop = atm_pop_raw; vcc->push_oam = NULL; - vcc->send = vcc->dev->ops->send; + if (vcc->dev->ops->send_bh) + vcc->send = vcc->dev->ops->send_bh; + else + vcc->send = vcc->dev->ops->send; return 0; } EXPORT_SYMBOL(atm_init_aal5); From patchwork Mon Nov 16 16:21:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11909733 X-Patchwork-Delegate: kuba@kernel.org 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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 BBB8AC5519F for ; Mon, 16 Nov 2020 16:21:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6259B221F8 for ; Mon, 16 Nov 2020 16:21:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yMsU7Mtj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mIao/k0l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731943AbgKPQVY (ORCPT ); Mon, 16 Nov 2020 11:21:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731938AbgKPQVY (ORCPT ); Mon, 16 Nov 2020 11:21:24 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13740C0613CF for ; Mon, 16 Nov 2020 08:21:24 -0800 (PST) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1605543682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jtvi8V/LQ5Rz6+0ztSY/Wqp0Vo+6J9KTqf1s3xDgcTo=; b=yMsU7MtjRiWYE/hV3aSXuElkOrLBBaBHa6p6FnbBdqqeeeEQWQw39NYOVGk9Ufvdl6YLJ1 bsIGLHFo5EQ9JCHslkNw83dLATvFZM6nr7F7pPrjkKZrQG3WIhpqTQssaVH5KAXC9OHrIR 0Thvt4teukV2zWRZAOEkG8bptsH5G+y7gTh54FUZbmxl53zaIH9IoWRkHpBk99+3mf89vn r7U8SHcOFXn0wAehQCG8I/za6Br7t98DOBsk7C2NITGTpAjhKZkfsYNZG/aGbDHYYubyvs IcLKWF+Iq3QuTthm6xct584zQwsP+iH1gu0tRtiIih26SYt2MgnnQ53fv/WMJw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1605543682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jtvi8V/LQ5Rz6+0ztSY/Wqp0Vo+6J9KTqf1s3xDgcTo=; b=mIao/k0l+YKGI6MGB/D+EmLXVbSEol2bfW+xcs228wXAp5uCbpWzBuT/oNMm2AJnVR5oAZ cXusfG4J4XMKG6Cw== To: linux-atm-general@lists.sourceforge.net Cc: Chas Williams <3chas3@gmail.com>, netdev@vger.kernel.org, Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 3/3] atm: lanai: Remove in_interrupt() usage Date: Mon, 16 Nov 2020 17:21:16 +0100 Message-Id: <20201116162117.387191-4-bigeasy@linutronix.de> In-Reply-To: <20201116162117.387191-1-bigeasy@linutronix.de> References: <20201116162117.387191-1-bigeasy@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org lanai_shutdown_tx_vci() uses in_interrupt() to issue a warning message if the function was used in context in which it is not safe to sleep. The usage of in_interrupt() in driver code is deprecated as it can not always detect all states where it is not allowed to sleep. msleep() has debug code which will trigger a warning if used in bad context. Remove in_interrupt(). Cc: Chas Williams <3chas3@gmail.com> Cc: netdev@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- drivers/atm/lanai.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c index ac811cfa68431..d7277c26e4232 100644 --- a/drivers/atm/lanai.c +++ b/drivers/atm/lanai.c @@ -765,8 +765,7 @@ static void lanai_shutdown_tx_vci(struct lanai_dev *lanai, struct sk_buff *skb; unsigned long flags, timeout; int read, write, lastread = -1; - APRINTK(!in_interrupt(), - "lanai_shutdown_tx_vci called w/o process context!\n"); + if (lvcc->vbase == NULL) /* We were never bound to a VCI */ return; /* 15.2.1 - wait for queue to drain */