From patchwork Thu Sep 7 06:03:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 111858 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp357013qge; Wed, 6 Sep 2017 23:04:02 -0700 (PDT) X-Received: by 10.84.132.1 with SMTP id 1mr1734005ple.253.1504764242289; Wed, 06 Sep 2017 23:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504764242; cv=none; d=google.com; s=arc-20160816; b=sbQ4W6/2s416KtjRvkzepqhFImBKN9YmeN5TLSkbc7uImskQsSU1qYS147CQ62Bvaj jdj6jXxaSfc+RneE1u7wuDHKDE8pI06EPaVrsTX8Na4iT/OXngpWeKvIoWrCohKe23Vw n1Jeka3uKPgt0drEnPFxR0S8+jTPMYeKSM66y+bijr3kB+WXiYPqVVLgkWiCXFMVQjgk RZYWlaML0/ffiJS2o9W7pZJjdqEW9je2vqU3Ma6Q62puesGzdFCSYWLmHdMDusnPLIRJ Wl8MbU67VgKKFZEyXY6h2Gblbtq5OSfzsN94FL+KsuAgETmdSq5mcQrWGml01P6+bkYg cySQ== 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=/thH9etSK4B+8rLqtVVQ/Jd8bt8cVU+Vh5nH0wQcye8=; b=M6LkYPe7YHbZai9usBv+OvVe58Vs5uldIKfqrdfleTqUTW1Bg6aipjD8JTl+OHQ6Tp ozEAzFNLAjG6slcdbRYFD/IFe6p7IgvFc5cz2SI7YluUKI6GJxm3iGM4sjuLNLDCwVR5 xyD1QnttjSauUvdOIq2Yd6Gv72WKR2w09RKPvfynIR04rlHW4hoaA9D6Sa4tBqNGhpXg eQF837mUyY41bkQSH2H9ra0L1PaPb+pIH08vfYRsgIp8UFf2OFQVQQCMvGdD+F+NELng QNqsyoDMc6w/Zf8mLAPmeRAQj/+C6mhz6h3JqtjV6zcMQCjG097RYHqdyUqHFzEX/z63 ao6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j1vbo/tK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 u123si1355978pgc.27.2017.09.06.23.04.02; Wed, 06 Sep 2017 23:04:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=j1vbo/tK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1754177AbdIGGDs (ORCPT + 26 others); Thu, 7 Sep 2017 02:03:48 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:38662 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754023AbdIGGDl (ORCPT ); Thu, 7 Sep 2017 02:03:41 -0400 Received: by mail-pg0-f51.google.com with SMTP id v66so19132277pgb.5 for ; Wed, 06 Sep 2017 23:03:41 -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=/thH9etSK4B+8rLqtVVQ/Jd8bt8cVU+Vh5nH0wQcye8=; b=j1vbo/tKXHVzgG39CyBcP99h5BToxM24LgHviGFnwSvyDWD98Y+hkt3dQ+lStcdKP+ IW230IbPVtQobF3oYSmZ0GNJ3fmmCXVeaqd7WISalBTkAOS1MxY8ASHDSFF+ZRYv9A8o 2M8chteYIRKEezdehvw6MA2tfZf/hfhyTJI8Q= 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=/thH9etSK4B+8rLqtVVQ/Jd8bt8cVU+Vh5nH0wQcye8=; b=NpyyMbn99MbJZ+CFAZ2mBut+mAWbi5vwItm8t680KFiz9tj+ItxQ2XOVpwk9/cjKOv 3J1nqCbIxWEbX2tCQzIGRbXognj/WqvTyrplyfstPQgTTX6hvIz+Bmx1pgk9IuBbeQ+4 PXtAeCPrrGva3I/T/fJmnUFyERvu0Rp5lm15aVkxti4WehrzJSw9PztS+zgj2rQwItjM UVopDQ93BfoImMdvFHpvusi0Cctl5qDqdWbsQI3jg1oUx2Dd20db2dnU3q5qE38NeSwj 1vgdsoaqMuDkZ5DNN+5IzDX3HwqHOZBCaC2KXxAszW/gRRHQVfHqNjGM5F5a0MzzNNmW /nqA== X-Gm-Message-State: AHPjjUgdPx1e03XVdo8lID4OUsY1YbB9aMIsjkeJW3BbyLutA5ANpfyi Ajp3prEmTjT5AamS X-Google-Smtp-Source: ADKCNb5Q0irZ/BkvhnKP51naXW2sY0DgY/9ferenaL4cTujpB9eo9+a/Uux48ELdyqPcCCFnvq6kqw== X-Received: by 10.98.73.144 with SMTP id r16mr1598862pfi.314.1504764220515; Wed, 06 Sep 2017 23:03:40 -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 s1sm2186650pfk.27.2017.09.06.23.03.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 23:03:40 -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: [PATCH 6/7] net: qrtr: Use sk_buff->cb in receive path Date: Wed, 6 Sep 2017 23:03:28 -0700 Message-Id: <20170907060329.32402-7-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170907060329.32402-1-bjorn.andersson@linaro.org> References: <20170907060329.32402-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 f28ecd7d735b..5042999756ce 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: