Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4145149ioa; Tue, 26 Apr 2022 18:41:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDXkMrhuomE6IRHgOFBjLZVrEjCnXUg92qCchOhosTreSZqyiW4g/PDq1j2XernfQZCpEq X-Received: by 2002:a17:907:3f91:b0:6d7:16c0:ae1b with SMTP id hr17-20020a1709073f9100b006d716c0ae1bmr23895066ejc.74.1651023676528; Tue, 26 Apr 2022 18:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651023676; cv=none; d=google.com; s=arc-20160816; b=J2ZYUzXqk1q++fFZ5aDGuFRLtpRIx96nY65crwKZVrJwVtQMS6iZHvMlGqbxaF/NP3 lclWfr77A1V4JtnFsXRxhfdlsxZRkuawCHnj9baR73qzdAANTDkZJc6KH3z1xeBr+fVa x5J0iNLJQ/kd48PVlX9TXd/mR2y/53YED+w5yyzhOym+wWTKXHwAzGKC/TNiaMWbc2fj VUY0mD9kOBV9IedDTPczRRGLK4Ky6fyvng0Pvf6aV8XKBL1899w0yMTfdj8rK/Pyc4HB 02DjGkhoUKNGh3KehbtaMJer8/e/VsJI0vakSWdN8TeNqagPxuqABy4r0f5Cs3Ezp18x 5Gyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=M+2LynW425H8sZZr+Nji7eLzhzllLwXclikvPApWbbs=; b=X4s9rtHBrUQOFWxKqkUmcb1M19gSBtx4QyxYH4UvC/XEpWscYYAGYPHlNpaOg43xZ2 1Y3KNcCe0II/EtOa8WiCG7pZ8Pqp7fWfUJR6zB1aEJxY4WisxjVIl8me51fFzqx4OAGH K+7Sjp4ISxKnLua6pZbhzLAnJ0zYE+DhbkOkzWecix1H/s0rtcNlbTfP4MKo9ppxA6Um hlVHtC0Ms8GqFi/cVcIf4nXD6CoUiA7jgFRszrj5Ymrh9gMqexqzeYbuV4jtpeVpXlis lGhusOG/eAiMrG1AOsTSyvjEAnBcy0dcf1s6OuVDe/jkiuPNHxwh/T9I1bnSLDuKo72K CL1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hENXxB7Y; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f6-20020a170906c08600b006f3a8137351si4172731ejz.181.2022.04.26.18.40.59; Tue, 26 Apr 2022 18:41:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=@gmail.com header.s=20210112 header.b=hENXxB7Y; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356000AbiDZXJ1 (ORCPT + 67 others); Tue, 26 Apr 2022 19:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355994AbiDZXJ0 (ORCPT ); Tue, 26 Apr 2022 19:09:26 -0400 Received: from mail-ua1-x932.google.com (mail-ua1-x932.google.com [IPv6:2607:f8b0:4864:20::932]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50E903586B; Tue, 26 Apr 2022 16:06:17 -0700 (PDT) Received: by mail-ua1-x932.google.com with SMTP id w21so8214uan.3; Tue, 26 Apr 2022 16:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=M+2LynW425H8sZZr+Nji7eLzhzllLwXclikvPApWbbs=; b=hENXxB7YcCHl3W+jQLxJvM/1B0lvDLpy/9lpzXAG5zv3zv+lgsoUZKgNeaHV3if2Ho kUWpyc20TwNlxCh7nsHd/3y338ZpkcTl39og6bBcHs2jLT0Wx0oxgEZjdNQ4SyaBp+7z Yz1eos3lYvJXaTmLNDLUdvf8Ve2Fd2NSKBNamRYQnK+HnwHDcU2+s1wa9NbnHsVMTA88 VuFkRX9ovVV2Kx1/i1KFp6V9kUGHUKrCixf1csBmjN7+JBJqbRdSgTt+1UYE76UGD4k0 IH1F/WyMMsHdnq1ewV/SL/ia31b0Kyljvp0LWfYcxFBJjldwn4DffyLOxBNn4GbkUgqV fb+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=M+2LynW425H8sZZr+Nji7eLzhzllLwXclikvPApWbbs=; b=qGFmZo72zppV7p+BHG8h8x24Bc0apJVYXEKsRZAmWfIB1aqpRDYAD+MI6pZdxURAOM D6Ryo11xMF7RWe2ASK4rjE51dvFwVhJ9bnmRcxAQgu8dzm5j4lHVFQ3m5UFi/0yfIAtM daAwQG3WXommWGo7nYA8DYfUAGmhofjQ3bDJ2gk/sB2LhuGllyZi09lzGUgZirD635t4 CfM/nspgUc6B0/cdtvbML1ychQd9/uLESqYICYTDcPbpIlXXCieZUm/f2Qw8wBY0URF5 4wD2ex6vpm2Kx8dGiysF6toEck0KI/Ajsym2pVAvmmtB+R5Xt1rd9IEF92pQzr7vQ1zL tLhg== X-Gm-Message-State: AOAM531KMhCkGJjTO0cULH3R0Kjur2TlqSIB0CNcliIxY/BHGjUA0WJa DUyibqaVRPEHW0vfgKPv/2mUT2K0KqIKDYb2PpY= X-Received: by 2002:ab0:284c:0:b0:362:88a1:979e with SMTP id c12-20020ab0284c000000b0036288a1979emr4158007uaq.74.1651014376415; Tue, 26 Apr 2022 16:06:16 -0700 (PDT) MIME-Version: 1.0 References: <20220407223629.21487-1-ricardo.martinez@linux.intel.com> <20220407223629.21487-5-ricardo.martinez@linux.intel.com> In-Reply-To: From: Sergey Ryazanov Date: Wed, 27 Apr 2022 02:06:16 +0300 Message-ID: Subject: Re: [PATCH net-next v6 04/13] net: wwan: t7xx: Add port proxy infrastructure To: "Veleta, Moises" Cc: Ricardo Martinez , "netdev@vger.kernel.org" , "linux-wireless@vger.kernel.org" , Jakub Kicinski , David Miller , Johannes Berg , Loic Poulain , "Kumar, M Chetan" , "Devegowda, Chandrashekar" , linuxwwan , "chiranjeevi.rapolu@linux.intel.com" , "Liu, Haijun" , "Hanania, Amir" , Andy Shevchenko , "Sharma, Dinesh" , "Lee, Eliot" , "Jarvinen, Ilpo Johannes" , "Bossart, Pierre-louis" , "Sethuraman, Muralidharan" , "Mishra, Soumya Prakash" , "Kancharla, Sreehari" , "Sahu, Madhusmita" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-wireless@vger.kernel.org Hello Moises, On Tue, Apr 26, 2022 at 10:46 PM Veleta, Moises w= rote: > From: Sergey Ryazanov > Sent: Monday, April 25, 2022 4:53 PM > To: Ricardo Martinez > Cc: netdev@vger.kernel.org ; linux-wireless@vger.= kernel.org ; Jakub Kicinski ; David Miller ; Johannes Berg ; Loic Poulain ; Kumar, M Chetan ; Devegowda, Chandrashekar ; linuxwwan ; chiranjeevi.rapolu@linux.intel.com ; Liu, Haijun ; H= anania, Amir ; Andy Shevchenko ; Sharma, Dinesh ; Lee, Eliot ; Jarvinen, Ilpo Johannes ; Veleta, Moises ; Bossart, Pierre-louis ; Sethuraman, Muralidharan ; Mishra, Soumya Prakash ; Kanc= harla, Sreehari ; Sahu, Madhusmita > Subject: Re: [PATCH net-next v6 04/13] net: wwan: t7xx: Add port proxy in= frastructure > > On Fri, Apr 8, 2022 at 1:37 AM Ricardo Martinez > wrote: >> Port-proxy provides a common interface to interact with different types >> of ports. Ports export their configuration via `struct t7xx_port` and >> operate as defined by `struct port_ops`. >> >> Signed-off-by: Haijun Liu >> Co-developed-by: Chandrashekar Devegowda >> Signed-off-by: Chandrashekar Devegowda >> Co-developed-by: Ricardo Martinez >> Signed-off-by: Ricardo Martinez >> >> From a WWAN framework perspective: >> Reviewed-by: Loic Poulain > > [skipped] > >> +int t7xx_port_enqueue_skb(struct t7xx_port *port, struct sk_buff *skb) >> +{ >> + unsigned long flags; >> + >> + spin_lock_irqsave(&port->rx_wq.lock, flags); >> + if (port->rx_skb_list.qlen >=3D port->rx_length_th) { >> + spin_unlock_irqrestore(&port->rx_wq.lock, flags); > > Probably skb should be freed here before returning. The caller assumes > that skb will be consumed even in case of error. > > [MV] We do not drop port ctrl messages. We keep them and try again later. > Whereas WWAN skbs are dropped if conditions are met. I missed that the WWAN port returns no error when it drops the skb. And then I concluded that any failure to process the CCCI message should be accomplished with the skb freeing. Now the handling of CCCI messages is more clear to me. Thank you for the clarifications! To avoid similar misinterpretation in the future, I thought that the skb freeing in the WWAN port worth a comment. Something to describe that despite dropping the message, the return code is zero, indicating skb consumption. Similarly in this (t7xx_port_enqueue_skb) function. Something like: "return an error here, the caller will try again later". And maybe in t7xx_cldma_gpd_rx_from_q() near the loop break after the .skb_recv() failure test. Something like: "break message processing for now will try this message later". What do you think? >> + return -ENOBUFS; >> + } >> + __skb_queue_tail(&port->rx_skb_list, skb); >> + spin_unlock_irqrestore(&port->rx_wq.lock, flags); >> + >> + wake_up_all(&port->rx_wq); >> + return 0; >> +} > > [skipped] > >> +static int t7xx_port_proxy_recv_skb(struct cldma_queue *queue, struct s= k_buff *skb) >> +{ >> + struct ccci_header *ccci_h =3D (struct ccci_header *)skb->data; >> + struct t7xx_pci_dev *t7xx_dev =3D queue->md_ctrl->t7xx_dev; >> + struct t7xx_fsm_ctl *ctl =3D t7xx_dev->md->fsm_ctl; >> + struct device *dev =3D queue->md_ctrl->dev; >> + struct t7xx_port_conf *port_conf; >> + struct t7xx_port *port; >> + u16 seq_num, channel; >> + int ret; >> + >> + if (!skb) >> + return -EINVAL; >> + >> + channel =3D FIELD_GET(CCCI_H_CHN_FLD, le32_to_cpu(ccci_h->status= )); >> + if (t7xx_fsm_get_md_state(ctl) =3D=3D MD_STATE_INVALID) { >> + dev_err_ratelimited(dev, "Packet drop on channel 0x%x, m= odem not ready\n", channel); >> + goto drop_skb; >> + } >> + >> + port =3D t7xx_port_proxy_find_port(t7xx_dev, queue, channel); >> + if (!port) { >> + dev_err_ratelimited(dev, "Packet drop on channel 0x%x, p= ort not found\n", channel); >> + goto drop_skb; >> + } >> + >> + seq_num =3D t7xx_port_next_rx_seq_num(port, ccci_h); >> + port_conf =3D port->port_conf; >> + skb_pull(skb, sizeof(*ccci_h)); >> + >> + ret =3D port_conf->ops->recv_skb(port, skb); >> + if (ret) { >> + skb_push(skb, sizeof(*ccci_h)); > > Header can not be pushed back here, since the .recv_skb() callback > consumes (frees) skb even in case of error. See > t7xx_port_wwan_recv_skb() and my comment in t7xx_port_enqueue_skb(). > Pushing the header back after failure will trigger the use-after-free > error. > > [MV] Since t7xx_port_wwan_recv_skb returns 0 when dropping a skb, it skip= s this push operation and > will not trigger the error stated. Inside of that function an error is pr= inted. > >> + return ret; >> + } >> + >> + port->seq_nums[MTK_RX] =3D seq_num; > > The expected sequence number updated only on successful .recv_skb() > exit. This will trigger the out-of-order seqno warning on a next > message after a .recv_skb() failure. Is this intentional behaviour? > > Maybe the expected sequence number should be updated before the > .recv_skb() call? Or even the sequence number update should be moved > to t7xx_port_next_rx_seq_num()? > > [MV] For t7xx_port_wwan_recv_skb, it drops skb and seq_nums is updated. > for t7xx_port_enqueue_skb, it retains skb and can be processed again late= r, skipping this update upon error. Now this is clear to me. Thanks. >> + return 0; >> + >> +drop_skb: >> + dev_kfree_skb_any(skb); >> + return 0; >> +} --=20 Sergey