From patchwork Wed Oct 11 06:45:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115506 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp408802qgn; Tue, 10 Oct 2017 23:45:43 -0700 (PDT) X-Received: by 10.98.31.14 with SMTP id f14mr15868405pff.235.1507704343332; Tue, 10 Oct 2017 23:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507704343; cv=none; d=google.com; s=arc-20160816; b=lki6krJyxlT3abYeb/GmjrWldCD7H7BqSMMCR61QGphdM9G1A4WZu0/GKL4cAcvHDU 86ftduGFAYo5Rq9/1F18l1PT79j6uT52wSpARxNT+MjMalwVgHa8EOd76pCkpAdlMhJF 0AjP6c+aD+YCYhyigrJ7my3MxDrBjBa1KABzt95IkHG0nBBw0J7wvUU9fD2CnyCbjuGQ XrUpF/xwAoJzmSOkHU5SC+aTJmvc9sBOzs384tsChzg9ZkZgO+A9CMk+MYXpRUTPJoCw VvcaPN16lPpJvKVzcIayfMdcB4UDKqR8GzwECGW7EHm0vVUEHPtvoSCSJMpMuntBFhQx pMxw== 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=FCsK9I95JYz1hSXlgU8275vF1VbqNqAID6oexLjVgsg=; b=mphlOQ90ypBNPOObH1crQ/N/URES2/EqDkCxeufCNgiI0jo3gkT5aDaFwXv/42j+8M 2LAVtq+H6Tisc/Y4kSRuH2icjqrxMqjBwwvpyjycbpM5/cKftInjvPMU7ZlogFIJ8vwd tbFc9eEfArz0d1EbHFPxHOkbp5kBDk8Q0nW2xRIZKDIP/gTrnUwI0x7vTCMXyF7wD0t/ Pr+ZuN58yhibIo1AHi6Hi6BAijFCfywZs4OaGXRmDXGam3eJnkVQviChdSf2bhU39E+Y VAVCTXkI2UPKNgBGySlPk1cGpYsklkCSmuwldfurJTpIzJVbcg1Zw++JYgcsTtpCmS9Q H7lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LRFAjnfU; 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 c11si9814015pga.244.2017.10.10.23.45.43; Tue, 10 Oct 2017 23:45:43 -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=LRFAjnfU; 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 S1757159AbdJKGpl (ORCPT + 26 others); Wed, 11 Oct 2017 02:45:41 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:44821 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756910AbdJKGpf (ORCPT ); Wed, 11 Oct 2017 02:45:35 -0400 Received: by mail-pg0-f43.google.com with SMTP id j3so511697pga.1 for ; Tue, 10 Oct 2017 23:45:35 -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=FCsK9I95JYz1hSXlgU8275vF1VbqNqAID6oexLjVgsg=; b=LRFAjnfUg2TsuwQqktMyeULYtEY8j7B2yVhm/jYdBb1q9LWK2Oyd3AxHihOBgE35X1 4uxdtBzK4Am/mPjfH4WUQyqHPgIjzA3dT1g2KGhi48xc2STsLdaMaO9lWHI+lwpSnglX oX9Hmt/QJ9ru9sxc1F/O/MZ9Y+dQdxHFy3FFg= 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=FCsK9I95JYz1hSXlgU8275vF1VbqNqAID6oexLjVgsg=; b=ckn83NMEpVvPWYJwxm/vpOyUqmdk6Qu+wQ6OHfhdvBJcBmLLqE+OqIO7UjCE0tJhVa Scue4x7Rfb7Dt5rLOBkUqkcdONb1x6UMX7/6PlR4gJtb6mNRGe5ye+rd0i1B0GRDsDR1 PvQEo/VdnIiXAxTv8JHGyfRaqbK90dG4XQO63aUVJLuwGvxz4Sy0L4lV8mqZU+DWOUIN 2bO3EMPtftGQdLIenYS4jzUL70KN88h0BfdUDRSlDIZQ7389EUSVqyJl9A+vLoQafp9z K58/p6qzhmnvaMWJdyMdNad9C/+sRuPsaHd4E2yjSU2giIAwjbr45WDZWNPrcQqWbHSU hjbA== X-Gm-Message-State: AMCzsaU2kBis5HAB8KjTYgX3BffQCIiASVnyIdPaUEIPVjkjpqL9EN9x pLf4Du53K4vZkQbawAUoNTP+pw== X-Google-Smtp-Source: AOwi7QCCaYWTk7Ogu1+qHnLYAkE+4JPtSpUgYbdHfdShWHasHM46n33jOV2M1luZlmVHaCpepWy+EQ== X-Received: by 10.99.63.199 with SMTP id m190mr14600354pga.201.1507704334543; Tue, 10 Oct 2017 23:45:34 -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 l79sm411779pfb.33.2017.10.10.23.45.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 23:45:33 -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 v2 6/7] net: qrtr: Use sk_buff->cb in receive path Date: Tue, 10 Oct 2017 23:45:22 -0700 Message-Id: <20171011064523.7902-7-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20171011064523.7902-1-bjorn.andersson@linaro.org> References: <20171011064523.7902-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 --- Changes since v1: - None 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: