From patchwork Thu Oct 5 03:51:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 114835 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp143429qgn; Wed, 4 Oct 2017 20:51:50 -0700 (PDT) X-Received: by 10.99.36.66 with SMTP id k63mr20788849pgk.223.1507175510698; Wed, 04 Oct 2017 20:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507175510; cv=none; d=google.com; s=arc-20160816; b=C4uhn9ktDJa7ezvRjQm7tq4uIcNm0pjibO8fDB+pDE8KztfpdqA1yy4EGYzFA0dsD0 GjvfyNJ6kjbljRDLhUnuWBSc6VmK4ZbADQQg7hhrkk4P9zqOY1yxvwLpxNBHvsFuv4hO 9/T3+IUVGExSm1pTE4yAOFnuVMhc+O4ab6HSKwaEEOEkIWjesz269nRsegpXusgW92wR qeJGxR4riK4NsoDmwYKb5USrvjWXmWaoMrIIYRLvAto86PWCWC1ilMCNrQbEvg4xgURY g+khoJn90jzxkPUxAThWYWtTjqygQEujH8mQp9dLMaZhVYoc3na1TKVjOtra9oaDyMpU LFmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=y3SJcYvMCM/BIhZ+s6QSqv1On31hKOUUvCqzFGzMcLI=; b=KW4O6zxEJ5HLccX7UaVlLpgnmyj24gps6nUIFZRBoJFrFbNeysdK8EEtTQf92CNuya mscq5QnbyWmfGL21RXO4bFoHMpyQjAow1YGPbRyr9T9+lqT+fdR3dUgQ/zGVNOCLyfPU EP7fR1QN64sTEHPnVTl2KmIwh+O8yyBjrGsktjx7JB8s+BR2icNVTmgXut2uLiILWjQ/ SlWg9PyRURyL+minQadA+u0Go+zuL5jp5GgZrGgGgUo6EK3vReR3ba94r8hXWrgfEJvL P7jzvu3eV/4R+quRwrXYQq4csyrwQVoL/RSgCh/OTYKnBl0J5MgBAaTilhZa8qDLDzkP 3U2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=belRAyid; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92si13267618pli.660.2017.10.04.20.51.50; Wed, 04 Oct 2017 20:51:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=belRAyid; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751477AbdJEDvs (ORCPT + 8 others); Wed, 4 Oct 2017 23:51:48 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:51932 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751774AbdJEDvR (ORCPT ); Wed, 4 Oct 2017 23:51:17 -0400 Received: by mail-pf0-f169.google.com with SMTP id n14so5426522pfh.8 for ; Wed, 04 Oct 2017 20:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y3SJcYvMCM/BIhZ+s6QSqv1On31hKOUUvCqzFGzMcLI=; b=belRAyidTIBD0d3kIPYUnuXD3TxPgRsovD6ZLcK84CvjHaBQY6rEOlXn1+3jsKCLHU l13pLbgCIMjIWAr1zzRFc5Q1P8keQhqOGY4U8PzZTy1OlT4EQjct0lUJfKpEajRi5QMR pXI0pA3y4Caemz086OEMqkAW1Bv1mPeI9iIyg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y3SJcYvMCM/BIhZ+s6QSqv1On31hKOUUvCqzFGzMcLI=; b=E/xC6kUzWHxNdeRQVbAaMIrfVSxBRwBESqBzPwd5Whpy2VwiJM2t7QLlIb/AfFFI3A K5spyxuizQjheM/BwbvvWzh+BiDo8fEqMQZDVjL+46Wub6rzDFv5LNUV0/ODr0ZtmEnq MZv2fWavSPqhbZg3SsfJnIHRLvKyEnFlFvxL+MuliSlb/8GBs+KuWdBVPckKJ/zCnA1c hScsMlVlWR8sUAtPwudPVt8bhx4daf3mKxpmIWpn6e+fjCnMZtmUcdugBEeVxtKFqmVH 9/Qp7vRDOr1g0ORYX4BSBBXLqTl4b/hi1RP2K8RHP4p8Rb8ix3Pkcr4/I47RpqtaNEiD aukQ== X-Gm-Message-State: AMCzsaXciOW05ZVqgD7jFQu1k4MJC9KRsiKaQhZY9mMF/EbXkKys72Sa StBnMRHzK4+t/k7Z/J7TqulUyw== X-Google-Smtp-Source: AOwi7QDk5oVw6IkBS/5m1kZ5ytd3JC+vGws11FOrOcAubyaagWUSvEc9YZ6jipVP6g2ifnddYywamA== X-Received: by 10.159.249.67 with SMTP id h3mr12114051pls.236.1507175476644; Wed, 04 Oct 2017 20:51:16 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id f131sm13067035pfc.27.2017.10.04.20.51.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 20:51:15 -0700 (PDT) From: Bjorn Andersson To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Chris Lew Subject: [RESEND PATCH 6/7] net: qrtr: Use sk_buff->cb in receive path Date: Wed, 4 Oct 2017 20:51:04 -0700 Message-Id: <20171005035105.14677-7-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20171005035105.14677-1-bjorn.andersson@linaro.org> References: <20171005035105.14677-1-bjorn.andersson@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Rather than parsing the header of incoming messages throughout the implementation do it once when we retrieve the message and store the relevant information in the "cb" member of the sk_buff. This allows us to, in a later commit, decode version 2 messages into this same structure. Signed-off-by: Bjorn Andersson --- net/qrtr/qrtr.c | 70 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 30 deletions(-) -- 2.12.0 diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index a84edba7b1ef..7bca6ec892a5 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -48,6 +48,16 @@ struct qrtr_hdr { __le32 dst_port_id; } __packed; +struct qrtr_cb { + u32 src_node; + u32 src_port; + u32 dst_node; + u32 dst_port; + + u8 type; + u8 confirm_rx; +}; + #define QRTR_HDR_SIZE sizeof(struct qrtr_hdr) struct qrtr_sock { @@ -216,6 +226,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) struct qrtr_node *node = ep->node; const struct qrtr_hdr *phdr = data; struct sk_buff *skb; + struct qrtr_cb *cb; unsigned int psize; unsigned int size; unsigned int type; @@ -245,8 +256,15 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) if (!skb) return -ENOMEM; - skb_reset_transport_header(skb); - skb_put_data(skb, data, len); + cb = (struct qrtr_cb *)skb->cb; + cb->src_node = le32_to_cpu(phdr->src_node_id); + cb->src_port = le32_to_cpu(phdr->src_port_id); + cb->dst_node = le32_to_cpu(phdr->dst_node_id); + cb->dst_port = le32_to_cpu(phdr->dst_port_id); + cb->type = type; + cb->confirm_rx = !!phdr->confirm_rx; + + skb_put_data(skb, data + QRTR_HDR_SIZE, size); skb_queue_tail(&node->rx_queue, skb); schedule_work(&node->work); @@ -295,26 +313,20 @@ static void qrtr_node_rx_work(struct work_struct *work) struct sk_buff *skb; while ((skb = skb_dequeue(&node->rx_queue)) != NULL) { - const struct qrtr_hdr *phdr; - u32 dst_node, dst_port; struct qrtr_sock *ipc; - u32 src_node; + struct qrtr_cb *cb; int confirm; - phdr = (const struct qrtr_hdr *)skb_transport_header(skb); - src_node = le32_to_cpu(phdr->src_node_id); - dst_node = le32_to_cpu(phdr->dst_node_id); - dst_port = le32_to_cpu(phdr->dst_port_id); - confirm = !!phdr->confirm_rx; + cb = (struct qrtr_cb *)skb->cb; + src.sq_node = cb->src_node; + src.sq_port = cb->src_port; + dst.sq_node = cb->dst_node; + dst.sq_port = cb->dst_port; + confirm = !!cb->confirm_rx; - src.sq_node = src_node; - src.sq_port = le32_to_cpu(phdr->src_port_id); - dst.sq_node = dst_node; - dst.sq_port = dst_port; + qrtr_node_assign(node, cb->src_node); - qrtr_node_assign(node, src_node); - - ipc = qrtr_port_lookup(dst_port); + ipc = qrtr_port_lookup(cb->dst_port); if (!ipc) { kfree_skb(skb); } else { @@ -604,7 +616,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, struct sockaddr_qrtr *to) { struct qrtr_sock *ipc; - struct qrtr_hdr *phdr; + struct qrtr_cb *cb; ipc = qrtr_port_lookup(to->sq_port); if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */ @@ -612,11 +624,9 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, return -ENODEV; } - phdr = skb_push(skb, QRTR_HDR_SIZE); - skb_reset_transport_header(skb); - - phdr->src_node_id = cpu_to_le32(from->sq_node); - phdr->src_port_id = cpu_to_le32(from->sq_port); + cb = (struct qrtr_cb *)skb->cb; + cb->src_node = from->sq_node; + cb->src_port = from->sq_port; if (sock_queue_rcv_skb(&ipc->sk, skb)) { qrtr_port_put(ipc); @@ -750,9 +760,9 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, int flags) { DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name); - const struct qrtr_hdr *phdr; struct sock *sk = sock->sk; struct sk_buff *skb; + struct qrtr_cb *cb; int copied, rc; lock_sock(sk); @@ -769,22 +779,22 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg, return rc; } - phdr = (const struct qrtr_hdr *)skb_transport_header(skb); - copied = le32_to_cpu(phdr->size); + copied = skb->len; if (copied > size) { copied = size; msg->msg_flags |= MSG_TRUNC; } - rc = skb_copy_datagram_msg(skb, QRTR_HDR_SIZE, msg, copied); + rc = skb_copy_datagram_msg(skb, 0, msg, copied); if (rc < 0) goto out; rc = copied; if (addr) { + cb = (struct qrtr_cb *)skb->cb; addr->sq_family = AF_QIPCRTR; - addr->sq_node = le32_to_cpu(phdr->src_node_id); - addr->sq_port = le32_to_cpu(phdr->src_port_id); + addr->sq_node = cb->src_node; + addr->sq_port = cb->src_port; msg->msg_namelen = sizeof(*addr); } @@ -877,7 +887,7 @@ static int qrtr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) case TIOCINQ: skb = skb_peek(&sk->sk_receive_queue); if (skb) - len = skb->len - QRTR_HDR_SIZE; + len = skb->len; rc = put_user(len, (int __user *)argp); break; case SIOCGIFADDR: