From patchwork Wed Oct 11 06:45:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115511 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp410171qgn; Tue, 10 Oct 2017 23:47:39 -0700 (PDT) X-Received: by 10.98.103.93 with SMTP id b90mr15719687pfc.2.1507704459304; Tue, 10 Oct 2017 23:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507704459; cv=none; d=google.com; s=arc-20160816; b=PI8aOJAWSKO6Bem8+iUwiD7hocUuw/VlI0QX0x0PaJFV0bkxUt2ol06KlmRNftRmJe 9zndYcRScUbsbXEQZDIfEQyEWKdqNJmI3a/ZlwPbopSbObf4SLoPiIHpgTq9jBCj87PB /uW2GCMtiD/QHKjxeyzgQBLZg4ueBEuiDQwz8RkZKWCQQGuc8m0RKXrwHBWwSRSnJT2D QztGCGQ6bA8vW95FUOS/BpvRze6cbLSWPqH4c8tLHkd0Jdf59Ac9nvCp0uqoQZpmfQGm 01IyEO6dg73EmbXJjIahUOLGTxbEsoK3mAL1ITcl3GDpplbWsKrcYEf1r5su6gZPraiP JcYw== 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=tom3zK/GFw6uChMa7PbJyymdKgx1ATdTjjhFDCuYEuU=; b=AJlIb9VAvJesy9+uq64H8DmW9uAi/iVtgDsuTRyt39HiJj/nzjQ4muid43DJF5+jH1 YwKgQhdl3afCaSleSpz4R7tvR+zKq9xSNRyduX5mX3TaS/w7Ha8DnEcSS3uRywZSWSOv BgLad5c6BLAGeeJY0V2hz6+/LkTAHV3XsRxuQFIzy/WMnWCppsjSmXfpaLNJDQ6LZr8E fwxliHJsK2r3zeKPtivajBk8JI4QhhwAMAz53jU0TpEosm/7hztqShBqkzOV8pHD38c+ Lhf8f4gm4MfLBri4SoI/5LtUdVjpjKC5BFRRKMBdXXkGcZEGipRzM2drtkyr0UssgIlk Cypw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JksIELn6; 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 k190si10496067pfc.298.2017.10.10.23.47.39; Tue, 10 Oct 2017 23:47:39 -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=JksIELn6; 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 S1757199AbdJKGri (ORCPT + 26 others); Wed, 11 Oct 2017 02:47:38 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:43297 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754255AbdJKGp2 (ORCPT ); Wed, 11 Oct 2017 02:45:28 -0400 Received: by mail-pf0-f182.google.com with SMTP id a8so198363pfc.0 for ; Tue, 10 Oct 2017 23:45:28 -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=tom3zK/GFw6uChMa7PbJyymdKgx1ATdTjjhFDCuYEuU=; b=JksIELn6lNP5XLtRV+AYHsEtkzK5RQmLdzp1B6bZuv6mydUd9hsM6Ix4j9Txi6uZsu e6rDvjoFmqumc8Y9tkS2YQQr5UjB9Z+OQGoW2ggSPiKFioJ1RWA3Tquf+2VmFDhqCTw2 /78ymiYCHqci7Ae/bXVrQEi6TNtnt7TnZtJiI= 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=tom3zK/GFw6uChMa7PbJyymdKgx1ATdTjjhFDCuYEuU=; b=RKI1EZT/EEQkIsozKKs5KP5sNlIr/Bg6f6P8IBXqZB9sjQgdIrqO7RyTHsol5bVbcl 68F4a0ILjCasFogd4b+tADqVKT8/DbYR2/4X4kra8vZ4v+GOhpsemy6nLvZJ1a/bkkVQ KKeF/UA/M+TuENDAMptHRBgWJIEE3g97g8AL2wlgATNUw4iLpeyY5rX3XpXOnwl6duCi 6Jz4X+aGXE40NprRnimx/wEglP8YWOGtQew5lZejFnW+og2GqUdLuACoMP+9Zrg8wSCk nl8cat90yu/f94f4evBQyd4w5T9KltxFTaVk9rRCR8VrKMUTiqK7Ol9qCjAK/oCY/pk+ 4M8w== X-Gm-Message-State: AMCzsaX6WFwgfFzGJpun0J4wBbLLkiIcN+3D1qB0cw7iBG/XPNfX7nop DEOpSPMsYeJqwBKlVEyhk9edSw== X-Google-Smtp-Source: AOwi7QDL6mk4t0dsTf5de1FDG2B+OE+27V0xVxoGzltoW509FqK61RpBaZH4Zk+pP9eF1QwiDR50Zg== X-Received: by 10.84.192.3 with SMTP id b3mr14664066pld.118.1507704328263; Tue, 10 Oct 2017 23:45:28 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 23:45:27 -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 1/7] net: qrtr: Invoke sk_error_report() after setting sk_err Date: Tue, 10 Oct 2017 23:45:17 -0700 Message-Id: <20171011064523.7902-2-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 manually waking up any context sleeping on the sock to signal an error we should call sk_error_report(). This has the added benefit that in-kernel consumers can override this notification with its own callback. Signed-off-by: Bjorn Andersson --- Changes since v1: - None net/qrtr/qrtr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.12.0 diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index c2f5c13550c0..7e4b49a8349e 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -541,7 +541,7 @@ static void qrtr_reset_ports(void) sock_hold(&ipc->sk); ipc->sk.sk_err = ENETRESET; - wake_up_interruptible(sk_sleep(&ipc->sk)); + ipc->sk.sk_error_report(&ipc->sk); sock_put(&ipc->sk); } mutex_unlock(&qrtr_port_lock); From patchwork Wed Oct 11 06:45:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115510 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp409873qgn; Tue, 10 Oct 2017 23:47:14 -0700 (PDT) X-Received: by 10.98.33.80 with SMTP id h77mr16021144pfh.18.1507704434056; Tue, 10 Oct 2017 23:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507704434; cv=none; d=google.com; s=arc-20160816; b=ZxwFhBRhVhEQ2+gNqZhsLFRk9J2NoAJB+5rvVaTuui9+Dv7e78ueC+MQ7YL+CO/y+e 8hq8UAFb//CXL5+6Mzf5ok6mx6aDZVZmeG7aDO4aW8fTByMBNjmbc7ULgzVzWs3uH2F6 OgcUuA/lEZPzXUa2xHfg+itiB+fGa+TlEDY7a8+leJ/PHzrWGdSVsCeFE3quq4GklTcp M2P/T4QTplTo5vRiZB43YoMi3nD0mh06usSI/yFlcPZ3w5UNcipbX4z98FQ/FIMu98FV VKgloPISCc6tklkGXHp5EG0GQyFLBLH1AoUGX57E5na4uSy/75XvrSc7+QtQ1AjNYk6H oLkg== 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=h/npvkaeX43uDoR5BegIAix9tb04HzMt3KAuok3Tw4Q=; b=NyjI8reXfNzwbcOu+XV07QwXbv2zdJwpRWYe0kgEYyI9x8ogr6q9oDtCNHiyKy+0x1 h0ivMdjXlDucSnINAdrmfNtciH3s+Db2JMGgwg5WCgXyBbVj8qHU1N7hWhwNuu3rFucq QXLpphEnVSCySNJHrjKnvCqPJHY1A5XO9h3bU1N9rGxEiyHuOZ6hvOdscJuh0Bb6m11u d89xAq97zkVv8f4NP0+Ak6M/kwjoFl8Vin9y+3DG+J0fbM+DwSAuDaaTUtB3sVNXtVxs hAcO3w/g783sIcHAyLmzK6GMRgqxlR4SaaRnBmtuEPilQJ8bvyE3L98QvV/MzQ2+CwT9 DJuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nyt0BZ9y; 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 k190si10496067pfc.298.2017.10.10.23.47.13; Tue, 10 Oct 2017 23:47:14 -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=Nyt0BZ9y; 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 S1757283AbdJKGrL (ORCPT + 26 others); Wed, 11 Oct 2017 02:47:11 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:56459 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756094AbdJKGp3 (ORCPT ); Wed, 11 Oct 2017 02:45:29 -0400 Received: by mail-pf0-f175.google.com with SMTP id b85so631842pfj.13 for ; Tue, 10 Oct 2017 23:45:29 -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=h/npvkaeX43uDoR5BegIAix9tb04HzMt3KAuok3Tw4Q=; b=Nyt0BZ9yuGBSGyhpl2oPBlk8s9nHdHYRMa1qV3FYKxe46NoXcA6DA0Q83z94U5wF0K WLLarVq8TVtD/FcV0w7bFi+k3UoNjxZaflPxnlz/LovIdepSMrUfZ18w2Z8UF2Yeyz87 rxue6S0ndTO7QLHt4PNB+Bzfz43qQzVLXIx1I= 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=h/npvkaeX43uDoR5BegIAix9tb04HzMt3KAuok3Tw4Q=; b=O05JAzXKUViYPpU6/hdRw2CITUihjr8Dr/Qojg2O9SgpQuxKMPDeE1Q3MM5R6JU/QI 0PMsQDQCXOF+1FLrewH5qnEIW0jWLP8HpimOvmdN4ifvLnWfuwhHb+901609eJFEQAXL ruZNKa5BPmxAZii43NmE0lMP9obHHjLZm3LTFRUQIwhNqkWrlZuKyXdmYdyk5GY3DR5S rQinle4rlqNsaltbQ63FRtmJdjOSNsNXDOawBCBZpiZylhx2lc56fOHtKEvBl9hYZGcT uAWeHbT4MImezhPriGNxJ1+NVwB3AMzmUDtzzPPkzIGztFa0g2mgsfNMepX6DceI24Q6 cKiA== X-Gm-Message-State: AMCzsaW3c2NeP4203KVL2lNspmxccfuiteVn3moyDV44dDFo+UaYj6QF 8BJwjhGsxn2ZvLz2JOaZ0mLhmQ== X-Google-Smtp-Source: AOwi7QCsWDpHBPPlS2B/ThD1tSvLTyH0M+EKRu3OJvVadAlZOHt26TUra6247x43HdGyE9jvzPD8HA== X-Received: by 10.84.235.3 with SMTP id o3mr8888620plk.30.1507704329396; Tue, 10 Oct 2017 23:45:29 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 23:45:28 -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 2/7] net: qrtr: Move constants to header file Date: Tue, 10 Oct 2017 23:45:18 -0700 Message-Id: <20171011064523.7902-3-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 The constants are used by both the name server and clients, so clarify their value and move them to the uapi header. Signed-off-by: Bjorn Andersson --- Changes since v1: - None include/uapi/linux/qrtr.h | 3 +++ net/qrtr/qrtr.c | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) -- 2.12.0 diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h index 9d76c566f66e..63e8803e4d90 100644 --- a/include/uapi/linux/qrtr.h +++ b/include/uapi/linux/qrtr.h @@ -4,6 +4,9 @@ #include #include +#define QRTR_NODE_BCAST 0xffffffffu +#define QRTR_PORT_CTRL 0xfffffffeu + struct sockaddr_qrtr { __kernel_sa_family_t sq_family; __u32 sq_node; diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 7e4b49a8349e..15981abc042c 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -61,8 +61,6 @@ struct qrtr_hdr { } __packed; #define QRTR_HDR_SIZE sizeof(struct qrtr_hdr) -#define QRTR_NODE_BCAST ((unsigned int)-1) -#define QRTR_PORT_CTRL ((unsigned int)-2) struct qrtr_sock { /* WARNING: sk must be the first member */ From patchwork Wed Oct 11 06:45:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115505 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp408787qgn; Tue, 10 Oct 2017 23:45:41 -0700 (PDT) X-Received: by 10.84.177.195 with SMTP id x61mr14158233plb.286.1507704341253; Tue, 10 Oct 2017 23:45:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507704341; cv=none; d=google.com; s=arc-20160816; b=nhlHjGkm0xU1oT2c+wQJIK8GsyYn24E6GWz74AE8rejHuCmTxb35GDhhmjNbtU1jwB gZMQPGdnsG+4OpGfBFaP/d57dyuK+OZeB7az85Af7DxEWNK5ImqPRo1fF/Vahfre+K9d LYvItlKsvdYd9aGKTEafTfPSy5PQ0Y7xYqdyJg+UC9xvpTEH4dBcbod0EIjseYBBWMMj IJrOvcmulhGltpclkZ66Zj/phkk5ud12O/r677jl5emTgFCEIVspBbgzbIPLSNd7NpQF 6ZLzLu3xULps9N7UfdinVGq+yxz05kdQ0OoXISUqWzMnh9J/aBscVQYHzp2HO4khf/TJ n6JA== 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=RijD6igbTEBvJnMMJXStHeiIgf820aIMkYoEuuRjLdE=; b=EOJdVcCyGVB5eL+JgnjP2YugtX4l+AUqhUS+CCteDreENj345aw6L15upzxxfNv7hz sTuSxsxrWgPeaWdF9s6zkl1sodnsrefo59Ufq9ZF6LxmIdpucoT3Iegv46yrgnlkHId8 WMmPeElyYzjUQyE7qwrGidLbAoWs6cda1g36mmMIDzc05Rh8uG9TN7aCM+4IJ2yuFpG4 wuG5VzaBnf9Afbazdgq7TgvG6nKSd3QZ3Rga9IMD7t4UnIZ2gENpnZGsGDyldKRKkhM+ hTWbaICuVpJif71iT4BE0fkg9TZGvVPOjh9NGxIT0Icdo442n2yltGhyUBXVE6MeHQ+O RZeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gS6Sd2mU; 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 l61si10227402plb.490.2017.10.10.23.45.40; Tue, 10 Oct 2017 23:45:41 -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=gS6Sd2mU; 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 S1756971AbdJKGpf (ORCPT + 26 others); Wed, 11 Oct 2017 02:45:35 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:55385 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756584AbdJKGpb (ORCPT ); Wed, 11 Oct 2017 02:45:31 -0400 Received: by mail-pf0-f179.google.com with SMTP id 17so634544pfn.12 for ; Tue, 10 Oct 2017 23:45:31 -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=RijD6igbTEBvJnMMJXStHeiIgf820aIMkYoEuuRjLdE=; b=gS6Sd2mUwDCvit9wrcGdHkxDSuugTybW1msmXmNI4yja3+or0w14jJhPQimTnaMeNJ U2TRDRTrkD9lD7fUy8LnmN6GsyzhUVjOBS/bBCuJwolVnRds4ySiDEpC3C1U+ziWw8So 38zCPWKwe9z7CIS2xux+F1tZqvTvrvOfsfmV0= 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=RijD6igbTEBvJnMMJXStHeiIgf820aIMkYoEuuRjLdE=; b=uW2Sym8ze/ecW36xPzOLitBlS+5g9Fw6okEHW1TuU03dFwdTrKljYPtAjlaqryu6cc BF6e38ZSeYtQaq0l+kud2RO1ZzQB4SjQWqXVs+jqlaQX10Y/zXBCyfNd2a4GCHL8Pl2p FINNLnOe30ki1QfM4JtUJfawyqjlhXijeh2lYGj4z8WaxzGVk1aTMmhxVzT72t5hbSqY Xq3dGlHcNdvZLluv//ZwTfqSCI+kv8AAcj5gITHUvYYTD5O8F/cAyq2KWfd9eS8F2xzs LKXpHBP6gKWn/NG0xYkn00LIlnadXozK7fxJWIYnw2yAOh+pbfxAAt3h4W9HlQlFSHHk /mSw== X-Gm-Message-State: AMCzsaW53jXnvELbme5F3+nT4JPd7eQx62dTlzZ5cZd3OsXIdBlYQqMA 2gb96Wx4tkqJ0nZ15Ep5S+2MnQ== X-Google-Smtp-Source: AOwi7QDqfHWBnVRUUYVOj6/H7/JTxtnAg15Sx4aaOTquolPgAgdMRY3i1ssRgO4XSfbAfrMYvQeRlQ== X-Received: by 10.99.99.65 with SMTP id x62mr14627376pgb.221.1507704330544; Tue, 10 Oct 2017 23:45:30 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 23:45:29 -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 3/7] net: qrtr: Add control packet definition to uapi Date: Tue, 10 Oct 2017 23:45:19 -0700 Message-Id: <20171011064523.7902-4-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 The QMUX protocol specification defines structure of the special control packet messages being sent between handlers of the control port. Add these to the uapi header, as this structure and the associated types are shared between the kernel and all userspace handlers of control messages. Signed-off-by: Bjorn Andersson --- Changes since v1: - None include/uapi/linux/qrtr.h | 32 ++++++++++++++++++++++++++++++++ net/qrtr/qrtr.c | 12 ------------ 2 files changed, 32 insertions(+), 12 deletions(-) -- 2.12.0 diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h index 63e8803e4d90..179af64846e0 100644 --- a/include/uapi/linux/qrtr.h +++ b/include/uapi/linux/qrtr.h @@ -13,4 +13,36 @@ struct sockaddr_qrtr { __u32 sq_port; }; +enum qrtr_pkt_type { + QRTR_TYPE_DATA = 1, + QRTR_TYPE_HELLO = 2, + QRTR_TYPE_BYE = 3, + QRTR_TYPE_NEW_SERVER = 4, + QRTR_TYPE_DEL_SERVER = 5, + QRTR_TYPE_DEL_CLIENT = 6, + QRTR_TYPE_RESUME_TX = 7, + QRTR_TYPE_EXIT = 8, + QRTR_TYPE_PING = 9, + QRTR_TYPE_NEW_LOOKUP = 10, + QRTR_TYPE_DEL_LOOKUP = 11, +}; + +struct qrtr_ctrl_pkt { + __le32 cmd; + + union { + struct { + __le32 service; + __le32 instance; + __le32 node; + __le32 port; + } server; + + struct { + __le32 node; + __le32 port; + } client; + }; +} __packed; + #endif /* _LINUX_QRTR_H */ diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 15981abc042c..d85ca7170b8f 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -26,18 +26,6 @@ #define QRTR_MIN_EPH_SOCKET 0x4000 #define QRTR_MAX_EPH_SOCKET 0x7fff -enum qrtr_pkt_type { - QRTR_TYPE_DATA = 1, - QRTR_TYPE_HELLO = 2, - QRTR_TYPE_BYE = 3, - QRTR_TYPE_NEW_SERVER = 4, - QRTR_TYPE_DEL_SERVER = 5, - QRTR_TYPE_DEL_CLIENT = 6, - QRTR_TYPE_RESUME_TX = 7, - QRTR_TYPE_EXIT = 8, - QRTR_TYPE_PING = 9, -}; - /** * struct qrtr_hdr - (I|R)PCrouter packet header * @version: protocol version From patchwork Wed Oct 11 06:45:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115509 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp409646qgn; Tue, 10 Oct 2017 23:46:52 -0700 (PDT) X-Received: by 10.84.213.16 with SMTP id f16mr14405828pli.262.1507704412280; Tue, 10 Oct 2017 23:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507704412; cv=none; d=google.com; s=arc-20160816; b=gHf84c1cnSVggrcJOUTvhlE8Yc+KYZ3UfjBBQbr0Gh81G05nOf84XU6QAsuU8JCg+a z3Jm4ktOj0SyCjsoLZEDz7Y3Lqxj/Dzoiqxka6keoWilqLierXMSJB3/PZpJBXwS2M+E lKTQZvBgaib3lYvctNPCF/A4V1PgZGjLpLbK7wmWvnhi1ONXfHhKSlLZzsEXPIHY6Iol oZt5pnWi6VkoKD3/dy6vXev7YE0Mki0hUszxjmVr5wi+j4uikamldvqIpn2YCDINTuya X2qTaHkuICLRerC7+eRU29yuXaigBQmuu3s8MOULFi/xEdzHUcXaSjILu1+3m/AcjceP kHhA== 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=rQkfhZgzX0jibOzSh4gukfTfoazegg4qhPASiFfai+E=; b=g8BSmiOlwrdkszwf2MwY5vaHJZL78LpOerVSVoQFbpH0Gwez4gfzEb2G+l1j0D3Q5+ EzkWJ8k88x1KvTRR/sstcWzVuYCqrC5I6TnvUJm5VKaMYTnJ9rpT9HCZVkZfju7ybeBv q+e8oAWVtKG44vInmTrCYGqVwYE3dJnjYuctVNoQm6cXlgWWdOnckgQNeroH6GqH+lh1 zuT/mBkTPsBgerYDTdQfN8agFhh+FzizGAATr89HsE/yL3RRq7LBJPAAHoDzIWZMqpvr tyvVtJhkPtA5wu/xVM8XHoPCAyQm8+5yqaPVCVM9NHZOqSkQhJVbWEuPsVV+XlaQA/v0 jb5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YXNv5UbG; 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 33si10444535plq.357.2017.10.10.23.46.52; Tue, 10 Oct 2017 23:46:52 -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=YXNv5UbG; 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 S1757274AbdJKGqu (ORCPT + 26 others); Wed, 11 Oct 2017 02:46:50 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:43370 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756606AbdJKGpc (ORCPT ); Wed, 11 Oct 2017 02:45:32 -0400 Received: by mail-pg0-f53.google.com with SMTP id n4so512359pgn.0 for ; Tue, 10 Oct 2017 23:45:32 -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=rQkfhZgzX0jibOzSh4gukfTfoazegg4qhPASiFfai+E=; b=YXNv5UbG5jq2bo/y4ZY8tyadFO708UmSB9mNw6YWqB1nayh8hzZ9u+IUQcWC85K6Wl MDfpWOQXKUKUKb0jFxdjyNaRpxTyqCKvST4lPWQBQzvhSPF7EYYmgLv1YoJwptW9CZGX GzPS1zLkp94+R1WgzzbqXk5dKcbeK6zDBmNFc= 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=rQkfhZgzX0jibOzSh4gukfTfoazegg4qhPASiFfai+E=; b=RAuAKct/etjT+G17QARUwXcWRJIK576PHDIbkxKVNSIvejjgkic9Ax00KiSJ/zvMUX G7jGzQtrgzTT80EL9WiRr8KBim8GutMxrbTq1YfMhVVFiPzty1QDux6Sgz1x2HOmNNbo ijtWZB5RTFfZDGRcGcfaxUt6ZoqBpZfk4Ai1s6D3uCg95JuhSA5qRyehvm19CHLqGe1U BQcIu+LDNLnUaQm/m5noDwTLZeSbbakgZ693vxYoTslVcSO0DeFXWSCGbvSyx0N6H497 T+1oDvwwW9FTmto26odF8fyTZDmhyFzMA6zOeVjeCURx+9vgVVPvhtDIz4n41iccMAnq NCQA== X-Gm-Message-State: AMCzsaXA25eaVlXAV8ELqe4z50MMve366SP7EEpBa+c3l620TmQhzuXx SnKZ8cnT3oHsqVDNXkGD16rx69wErv8= X-Google-Smtp-Source: AOwi7QDPpQu3uctUf/Cm0Q8zSW/msSuIq1E0M83tRv69QKu9UQvjn4kjaaFBeYPPFjfzd/mtdJAh5w== X-Received: by 10.101.82.8 with SMTP id o8mr14605073pgp.404.1507704331867; Tue, 10 Oct 2017 23:45:31 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 23:45:31 -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 4/7] net: qrtr: Pass source and destination to enqueue functions Date: Tue, 10 Oct 2017 23:45:20 -0700 Message-Id: <20171011064523.7902-5-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 Defer writing the message header to the skb until its time to enqueue the packet. As the receive path is reworked to decode the message header as it's received from the transport and only pass around the payload in the skb this change means that we do not have to fill out the full message header just to decode it immediately in qrtr_local_enqueue(). In the future this change also makes it possible to prepend message headers based on the version of each link. Signed-off-by: Bjorn Andersson --- Changes since v1: - None net/qrtr/qrtr.c | 120 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 51 deletions(-) -- 2.12.0 diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index d85ca7170b8f..82dc83789310 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -97,8 +97,12 @@ struct qrtr_node { struct list_head item; }; -static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb); -static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb); +static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to); +static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to); /* Release node resources and free the node. * @@ -136,10 +140,27 @@ static void qrtr_node_release(struct qrtr_node *node) } /* Pass an outgoing packet socket buffer to the endpoint driver. */ -static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb) +static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to) { + struct qrtr_hdr *hdr; + size_t len = skb->len; int rc = -ENODEV; + hdr = skb_push(skb, QRTR_HDR_SIZE); + hdr->version = cpu_to_le32(QRTR_PROTO_VER); + hdr->type = cpu_to_le32(type); + hdr->src_node_id = cpu_to_le32(from->sq_node); + hdr->src_port_id = cpu_to_le32(from->sq_port); + hdr->dst_node_id = cpu_to_le32(to->sq_node); + hdr->dst_port_id = cpu_to_le32(to->sq_port); + + hdr->size = cpu_to_le32(len); + hdr->confirm_rx = 0; + + skb_put_padto(skb, ALIGN(len, 4)); + mutex_lock(&node->ep_lock); if (node->ep) rc = node->ep->xmit(node->ep, skb); @@ -237,23 +258,13 @@ EXPORT_SYMBOL_GPL(qrtr_endpoint_post); static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, u32 src_node, u32 dst_node) { - struct qrtr_hdr *hdr; struct sk_buff *skb; skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL); if (!skb) return NULL; - skb_reset_transport_header(skb); - hdr = skb_put(skb, QRTR_HDR_SIZE); - hdr->version = cpu_to_le32(QRTR_PROTO_VER); - hdr->type = cpu_to_le32(type); - hdr->src_node_id = cpu_to_le32(src_node); - hdr->src_port_id = cpu_to_le32(QRTR_PORT_CTRL); - hdr->confirm_rx = cpu_to_le32(0); - hdr->size = cpu_to_le32(pkt_len); - hdr->dst_node_id = cpu_to_le32(dst_node); - hdr->dst_port_id = cpu_to_le32(QRTR_PORT_CTRL); + skb_reserve(skb, QRTR_HDR_SIZE); return skb; } @@ -326,6 +337,8 @@ static void qrtr_port_put(struct qrtr_sock *ipc); static void qrtr_node_rx_work(struct work_struct *work) { struct qrtr_node *node = container_of(work, struct qrtr_node, work); + struct sockaddr_qrtr dst; + struct sockaddr_qrtr src; struct sk_buff *skb; while ((skb = skb_dequeue(&node->rx_queue)) != NULL) { @@ -341,6 +354,11 @@ static void qrtr_node_rx_work(struct work_struct *work) dst_port = le32_to_cpu(phdr->dst_port_id); confirm = !!phdr->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, src_node); ipc = qrtr_port_lookup(dst_port); @@ -357,7 +375,9 @@ static void qrtr_node_rx_work(struct work_struct *work) skb = qrtr_alloc_resume_tx(dst_node, node->nid, dst_port); if (!skb) break; - if (qrtr_node_enqueue(node, skb)) + + if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, + &dst, &src)) break; } } @@ -407,6 +427,8 @@ EXPORT_SYMBOL_GPL(qrtr_endpoint_register); void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) { struct qrtr_node *node = ep->node; + struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL}; + struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL}; struct sk_buff *skb; mutex_lock(&node->ep_lock); @@ -416,7 +438,7 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) /* Notify the local controller about the event */ skb = qrtr_alloc_local_bye(node->nid); if (skb) - qrtr_local_enqueue(NULL, skb); + qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst); qrtr_node_release(node); ep->node = NULL; @@ -454,11 +476,17 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) { struct sk_buff *skb; int port = ipc->us.sq_port; + struct sockaddr_qrtr to; + + to.sq_family = AF_QIPCRTR; + to.sq_node = QRTR_NODE_BCAST; + to.sq_port = QRTR_PORT_CTRL; skb = qrtr_alloc_del_client(&ipc->us); if (skb) { skb_set_owner_w(skb, &ipc->sk); - qrtr_bcast_enqueue(NULL, skb); + qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us, + &to); } if (port == QRTR_PORT_CTRL) @@ -606,19 +634,25 @@ static int qrtr_bind(struct socket *sock, struct sockaddr *saddr, int len) } /* Queue packet to local peer socket. */ -static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb) +static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to) { - const struct qrtr_hdr *phdr; struct qrtr_sock *ipc; + struct qrtr_hdr *phdr; - phdr = (const struct qrtr_hdr *)skb_transport_header(skb); - - ipc = qrtr_port_lookup(le32_to_cpu(phdr->dst_port_id)); + ipc = qrtr_port_lookup(to->sq_port); if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */ kfree_skb(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); + if (sock_queue_rcv_skb(&ipc->sk, skb)) { qrtr_port_put(ipc); kfree_skb(skb); @@ -631,7 +665,9 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb) } /* Queue packet for broadcast. */ -static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb) +static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to) { struct sk_buff *skbn; @@ -641,11 +677,11 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb) if (!skbn) break; skb_set_owner_w(skbn, skb->sk); - qrtr_node_enqueue(node, skbn); + qrtr_node_enqueue(node, skbn, type, from, to); } mutex_unlock(&qrtr_node_lock); - qrtr_local_enqueue(node, skb); + qrtr_local_enqueue(node, skb, type, from, to); return 0; } @@ -653,13 +689,14 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb) static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) { DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name); - int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *); + int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int, + struct sockaddr_qrtr *, struct sockaddr_qrtr *); struct qrtr_sock *ipc = qrtr_sk(sock->sk); struct sock *sk = sock->sk; struct qrtr_node *node; - struct qrtr_hdr *hdr; struct sk_buff *skb; size_t plen; + u32 type = QRTR_TYPE_DATA; int rc; if (msg->msg_flags & ~(MSG_DONTWAIT)) @@ -713,32 +750,14 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) if (!skb) goto out_node; - skb_reset_transport_header(skb); - skb_put(skb, len + QRTR_HDR_SIZE); - - hdr = (struct qrtr_hdr *)skb_transport_header(skb); - hdr->version = cpu_to_le32(QRTR_PROTO_VER); - hdr->src_node_id = cpu_to_le32(ipc->us.sq_node); - hdr->src_port_id = cpu_to_le32(ipc->us.sq_port); - hdr->confirm_rx = cpu_to_le32(0); - hdr->size = cpu_to_le32(len); - hdr->dst_node_id = cpu_to_le32(addr->sq_node); - hdr->dst_port_id = cpu_to_le32(addr->sq_port); + skb_reserve(skb, QRTR_HDR_SIZE); - rc = skb_copy_datagram_from_iter(skb, QRTR_HDR_SIZE, - &msg->msg_iter, len); + rc = memcpy_from_msg(skb_put(skb, len), msg, len); if (rc) { kfree_skb(skb); goto out_node; } - if (plen != len) { - rc = skb_pad(skb, plen - len); - if (rc) - goto out_node; - skb_put(skb, plen - len); - } - if (ipc->us.sq_port == QRTR_PORT_CTRL) { if (len < 4) { rc = -EINVAL; @@ -747,12 +766,11 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) } /* control messages already require the type as 'command' */ - skb_copy_bits(skb, QRTR_HDR_SIZE, &hdr->type, 4); - } else { - hdr->type = cpu_to_le32(QRTR_TYPE_DATA); + skb_copy_bits(skb, 0, &type, 4); + type = le32_to_cpu(type); } - rc = enqueue_fn(node, skb); + rc = enqueue_fn(node, skb, type, &ipc->us, addr); if (rc >= 0) rc = len; From patchwork Wed Oct 11 06:45:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115508 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp409380qgn; Tue, 10 Oct 2017 23:46:31 -0700 (PDT) X-Received: by 10.98.155.219 with SMTP id e88mr1794653pfk.218.1507704391623; Tue, 10 Oct 2017 23:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507704391; cv=none; d=google.com; s=arc-20160816; b=xU2245Gr3/As49O9kPIrroxq6IZ/67IO3yLRa1pkIaRMxDKVacHfuTHDNdmzj4a0Rl 7PfrbEutECQ31iXzEjeofOq/8TD4haQhB4x11HX166ijeWpRHxvAxSczVaPI0iDZSmGD Rg+fsrNopXxNIpeNr0OcT1cJFJ57WYVzaKcCP90LQIuDw1JvJGe1tnM4INzgDybcFVO4 cZtN7iBgVxlXjcP8TDoInJuMbGi6PbyC5mXenLEMRl0c2dZYCldkKtfG9yoKC1dqDAct DqVbqB4oLZEOp15pbk6W6cKaIDrWtt4C1CjnnMO5QZ+WzytAc0vfczN8F09r2Kag3/R5 75eg== 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=QfLJ1GQt2kUmZJ19r3Ql2dtpKB6jNX2WGkqpLg1nQ0E=; b=Zpq+6VnpgJc4AalQznTF/uULmBMB0fB5Z1jwPAsuQpPMYtFxb1cSzvTJ1Y50LyjMDJ IQXXMSUh9Y/uNrzAvoPzC6knCw5Rw56NAehHjzMmq5Te3mzSCk1vN/8nlMxtcSoaBDbT R9dvzjh7tQHXpxijCWgiWZe0ac41zUhS8xGWSJP4icyH+8HWXLa+9CtjeyjC4+XyS6+N aMlzhyPMK1GBsngnbmt3zKl5I5NaddVNtlUcHYioJKzQJJp72fDNU+GrPqnITwBv+HTP tCd3vwGR9w2qVtmHOmDVIj+/r+ruV4UAmnJZcxTF5HuHY6r5IKExXEKiPpZk/IFAofU0 ++LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i4O/WzpS; 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 v41si10795599plg.597.2017.10.10.23.46.31; Tue, 10 Oct 2017 23:46:31 -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=i4O/WzpS; 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 S1757258AbdJKGq3 (ORCPT + 26 others); Wed, 11 Oct 2017 02:46:29 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:55571 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756642AbdJKGpd (ORCPT ); Wed, 11 Oct 2017 02:45:33 -0400 Received: by mail-pg0-f42.google.com with SMTP id b11so512753pgn.12 for ; Tue, 10 Oct 2017 23:45:33 -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=QfLJ1GQt2kUmZJ19r3Ql2dtpKB6jNX2WGkqpLg1nQ0E=; b=i4O/WzpSxGXY6knByDRsQ0l54XrH/76TCDWBHaF5bnYgxEJ0O1IuRtET2yJ+Xsd5ey AQYbfgbVnoX/QuHCg9x6xIGQAhuTDXyOEspx8/U/OuGoGAi5MYM3Cn4Ak8z+VcQbH7H6 WnJGHXlUuqIhT1pME5hNTasor5mjb4ZmdXebY= 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=QfLJ1GQt2kUmZJ19r3Ql2dtpKB6jNX2WGkqpLg1nQ0E=; b=RVu3YhVL/BOIhbShg6n4l+AUT7zx7EPevtP/6zotgyfEJvLyb6HfQEKlx1pptlzux6 GOhJH79PXeu5nXst7lJUCM6qzRvs0mb5xFRFp2tiNkMnMJ4g9uK0trwoiiHLMrGjW260 T+SZKfRr1V4hP9yMJKsvY9o/oR/LTE16KVq8TEhAkZYvn+f9B7qWybc9Cu3o3NyOuDqn CbvY4Xema9FsUw2ACpSzTT+wzjGje36iwYE0ZE4vPek2VEujOdRz+OVbV39/lNReguvh EKor3aInLHSsefnECMSxZLs3F3puCx1HThYzKv+yfyao5xSq7gPjZJf4bCBkqGhDEIdm k+Vg== X-Gm-Message-State: AMCzsaWbFcwXVtQocMG5Cuhy+yvuX13kdpcpTsDDWebN9B/3GZCacXA1 9y5ok4edX37i6EYd8iBHpOO7pA== X-Google-Smtp-Source: AOwi7QBXWVtJKdx+FB5efZq0uLMJ8j2MAX7FXT+L0DXIJV5uMbse+aIRdssj84SZnZa0NuGWNmMYKg== X-Received: by 10.99.149.66 with SMTP id t2mr9226999pgn.105.1507704333044; Tue, 10 Oct 2017 23:45:33 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 23:45:32 -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 5/7] net: qrtr: Clean up control packet handling Date: Tue, 10 Oct 2017 23:45:21 -0700 Message-Id: <20171011064523.7902-6-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 As the message header generation is deferred the internal functions for generating control packets can be simplified. This patch modifies qrtr_alloc_ctrl_packet() to, in addition to the sk_buff, return a reference to a struct qrtr_ctrl_pkt, which clarifies and simplifies the helpers to the point that these functions can be folded back into the callers. Signed-off-by: Bjorn Andersson --- Changes since v1: - None net/qrtr/qrtr.c | 93 ++++++++++++++++++--------------------------------------- 1 file changed, 29 insertions(+), 64 deletions(-) -- 2.12.0 diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 82dc83789310..a84edba7b1ef 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -255,9 +255,18 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) } EXPORT_SYMBOL_GPL(qrtr_endpoint_post); -static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, - u32 src_node, u32 dst_node) +/** + * qrtr_alloc_ctrl_packet() - allocate control packet skb + * @pkt: reference to qrtr_ctrl_pkt pointer + * + * Returns newly allocated sk_buff, or NULL on failure + * + * This function allocates a sk_buff large enough to carry a qrtr_ctrl_pkt and + * on success returns a reference to the control packet in @pkt. + */ +static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt) { + const int pkt_len = sizeof(struct qrtr_ctrl_pkt); struct sk_buff *skb; skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL); @@ -265,64 +274,7 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, return NULL; skb_reserve(skb, QRTR_HDR_SIZE); - - return skb; -} - -/* Allocate and construct a resume-tx packet. */ -static struct sk_buff *qrtr_alloc_resume_tx(u32 src_node, - u32 dst_node, u32 port) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_RESUME_TX, pkt_len, - src_node, dst_node); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_RESUME_TX); - buf[1] = cpu_to_le32(src_node); - buf[2] = cpu_to_le32(port); - - return skb; -} - -/* Allocate and construct a BYE message to signal remote termination */ -static struct sk_buff *qrtr_alloc_local_bye(u32 src_node) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_BYE, pkt_len, - src_node, qrtr_local_nid); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_BYE); - - return skb; -} - -static struct sk_buff *qrtr_alloc_del_client(struct sockaddr_qrtr *sq) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_DEL_CLIENT, pkt_len, - sq->sq_node, QRTR_NODE_BCAST); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_DEL_CLIENT); - buf[1] = cpu_to_le32(sq->sq_node); - buf[2] = cpu_to_le32(sq->sq_port); + *pkt = skb_put_zero(skb, pkt_len); return skb; } @@ -337,6 +289,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc); static void qrtr_node_rx_work(struct work_struct *work) { struct qrtr_node *node = container_of(work, struct qrtr_node, work); + struct qrtr_ctrl_pkt *pkt; struct sockaddr_qrtr dst; struct sockaddr_qrtr src; struct sk_buff *skb; @@ -372,10 +325,14 @@ static void qrtr_node_rx_work(struct work_struct *work) } if (confirm) { - skb = qrtr_alloc_resume_tx(dst_node, node->nid, dst_port); + skb = qrtr_alloc_ctrl_packet(&pkt); if (!skb) break; + pkt->cmd = cpu_to_le32(QRTR_TYPE_RESUME_TX); + pkt->client.node = cpu_to_le32(dst.sq_node); + pkt->client.port = cpu_to_le32(dst.sq_port); + if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &dst, &src)) break; @@ -429,6 +386,7 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) struct qrtr_node *node = ep->node; struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL}; struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL}; + struct qrtr_ctrl_pkt *pkt; struct sk_buff *skb; mutex_lock(&node->ep_lock); @@ -436,9 +394,11 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) mutex_unlock(&node->ep_lock); /* Notify the local controller about the event */ - skb = qrtr_alloc_local_bye(node->nid); - if (skb) + skb = qrtr_alloc_ctrl_packet(&pkt); + if (skb) { + pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE); qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst); + } qrtr_node_release(node); ep->node = NULL; @@ -474,6 +434,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc) /* Remove port assignment. */ static void qrtr_port_remove(struct qrtr_sock *ipc) { + struct qrtr_ctrl_pkt *pkt; struct sk_buff *skb; int port = ipc->us.sq_port; struct sockaddr_qrtr to; @@ -482,8 +443,12 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) to.sq_node = QRTR_NODE_BCAST; to.sq_port = QRTR_PORT_CTRL; - skb = qrtr_alloc_del_client(&ipc->us); + skb = qrtr_alloc_ctrl_packet(&pkt); if (skb) { + pkt->cmd = cpu_to_le32(QRTR_TYPE_DEL_CLIENT); + pkt->client.node = cpu_to_le32(ipc->us.sq_node); + pkt->client.port = cpu_to_le32(ipc->us.sq_port); + skb_set_owner_w(skb, &ipc->sk); qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us, &to); 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: From patchwork Wed Oct 11 06:45:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115507 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp408984qgn; Tue, 10 Oct 2017 23:45:59 -0700 (PDT) X-Received: by 10.98.50.66 with SMTP id y63mr15919365pfy.155.1507704359882; Tue, 10 Oct 2017 23:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507704359; cv=none; d=google.com; s=arc-20160816; b=TwFh8nrVty87RbrNkC/L6IP+zGeJCOHl2MWpU4SidyyciSyc8BwYDbynPimwsg9joB cMLVhsDq/7ECCF0LY/HBDnkzPIxuSaAa7wU9J3v2iOyIcFhnxB5iH7giAaSU2BKHzzO3 Cwadyljw1gruhBIkKGKZbzJQ/R0GjrlXCYAipu8kIoJNS0wb/oYyOygrv4CYL/e7v0bd Zd595eFA9vRGssmv0cIU0m14o2DK1ODDj/9ZW8J8Ek6Y2JguyKrYpuwiIW3CTFoSEsTQ EYvysIszYuLUAfsk7K4HmtV6bVkI7YIAFgCK+ksTdXfQ7IEWd5zvfXTS0jAbph6iYc4k 9eMg== 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=uI30fVoZYQc4HVDfnlhM+XiZkFYD0NAdoBJXGsFHK6E=; b=VMjPqUPmslcmkGUzfDvYpVu/aEztZNYpLaMLs/nSdWVsQomOmq0w2w0jgeT9FA6GcI BdWRVH8t7s300+VV7eAADVVSSKXfX2FRMk3HMRvKNY42zuEWLUt+LR4i3aZUWr/n7Vb3 CmF5mBk50HC0pdB2Lj7McsPfGg52KrdcBVSh43TwI1e1aqfH/z3e1vyTUQCYTTNxlrdG 2A37qUfzvDVLIBOzY8If9gaUYMcbbx9yIVQH4AIQN2wGYgFXK+DQ8aPsetlp0P/bt7Rv hodfBKBOdcIXWNQgg8mash6M41UhmR7eAJRdmJg5lnd/no12sUMzoZKt2wGuOUdbf32O nkDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eTIgJ7vb; 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 b68si7217001pfg.366.2017.10.10.23.45.59; Tue, 10 Oct 2017 23:45:59 -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=eTIgJ7vb; 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 S1757109AbdJKGpj (ORCPT + 26 others); Wed, 11 Oct 2017 02:45:39 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:50592 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756998AbdJKGpg (ORCPT ); Wed, 11 Oct 2017 02:45:36 -0400 Received: by mail-pf0-f181.google.com with SMTP id m63so648370pfk.7 for ; Tue, 10 Oct 2017 23:45:36 -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=uI30fVoZYQc4HVDfnlhM+XiZkFYD0NAdoBJXGsFHK6E=; b=eTIgJ7vbDUOpQYK6ud3AveUdkMOmlHLuES+S+Qq8jzoL6G6hD8GcoggkEVQQ8ttc2k tbNiqSOPoD443uJY4t0j1HblQXShOy+kpTzF6uzg8YJ1b68CXCqzljl5DfGZrd9J8gRS WUFrh2zwTKIz/Jo1KcmtDyCmQsxpxYQ6YItPw= 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=uI30fVoZYQc4HVDfnlhM+XiZkFYD0NAdoBJXGsFHK6E=; b=FnpQj8/byFAisRMvfqi6Kx8Afn0JrGIcRBEr5WgZ8cDGhjsJVljs6tZ3GjMl8QZNac FD/B6EBIAYhEIeD3E7kyUreebPb2tALkESkEc71GoQ5J8d8X/w9N2sIHICRdO/OqPNxA F4lMkbPpJZVKsazk8Cpu5seP5BndfNJyRA84+JAoD1D2yNFHm7bFpCAk1E5vTso29TDG vxflsptc8Ng9jMJyAY5IvSF1TK5LBA+bfAUPqcGi4Swu+KCk+C7W3sxbQz8iRU979BMl 78t3o3aYIfTN1YGVUqP2pVJoC45f80/PjcAprIjmeMV8XhIMM/vgaz8VIikYDX+mOLAo 7dxg== X-Gm-Message-State: AMCzsaUl5a7z34BsUZoVCzVPrZdAxaqfYiFq05uilbH2eUpd4twbLZ/V TRGl1jP+cx594+db1llXYBhXfR75NpU= X-Google-Smtp-Source: AOwi7QC626oh/5hWBmRZAAUL2WUtLYqu0BAlAemAkYeVFb5o/GApR1gFDjehmntLwspONt74pOn9bA== X-Received: by 10.84.131.36 with SMTP id 33mr14675611pld.100.1507704335868; Tue, 10 Oct 2017 23:45:35 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 23:45:35 -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 7/7] net: qrtr: Support decoding incoming v2 packets Date: Tue, 10 Oct 2017 23:45:23 -0700 Message-Id: <20171011064523.7902-8-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 Add the necessary logic for decoding incoming messages of version 2 as well. Also make sure there's room for the bigger of version 1 and 2 headers in the code allocating skbs for outgoing messages. Signed-off-by: Bjorn Andersson --- Changes since v1: - Dropped __packed from struct qrtr_hdr_v2 net/qrtr/qrtr.c | 132 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 38 deletions(-) -- 2.12.0 diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 7bca6ec892a5..e458ece96d3d 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -20,14 +20,15 @@ #include "qrtr.h" -#define QRTR_PROTO_VER 1 +#define QRTR_PROTO_VER_1 1 +#define QRTR_PROTO_VER_2 3 /* auto-bind range */ #define QRTR_MIN_EPH_SOCKET 0x4000 #define QRTR_MAX_EPH_SOCKET 0x7fff /** - * struct qrtr_hdr - (I|R)PCrouter packet header + * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1 * @version: protocol version * @type: packet type; one of QRTR_TYPE_* * @src_node_id: source node @@ -37,7 +38,7 @@ * @dst_node_id: destination node * @dst_port_id: destination port */ -struct qrtr_hdr { +struct qrtr_hdr_v1 { __le32 version; __le32 type; __le32 src_node_id; @@ -48,6 +49,32 @@ struct qrtr_hdr { __le32 dst_port_id; } __packed; +/** + * struct qrtr_hdr_v2 - (I|R)PCrouter packet header later versions + * @version: protocol version + * @type: packet type; one of QRTR_TYPE_* + * @flags: bitmask of QRTR_FLAGS_* + * @optlen: length of optional header data + * @size: length of packet, excluding this header and optlen + * @src_node_id: source node + * @src_port_id: source port + * @dst_node_id: destination node + * @dst_port_id: destination port + */ +struct qrtr_hdr_v2 { + u8 version; + u8 type; + u8 flags; + u8 optlen; + __le32 size; + __le16 src_node_id; + __le16 src_port_id; + __le16 dst_node_id; + __le16 dst_port_id; +}; + +#define QRTR_FLAGS_CONFIRM_RX BIT(0) + struct qrtr_cb { u32 src_node; u32 src_port; @@ -58,7 +85,8 @@ struct qrtr_cb { u8 confirm_rx; }; -#define QRTR_HDR_SIZE sizeof(struct qrtr_hdr) +#define QRTR_HDR_MAX_SIZE max_t(size_t, sizeof(struct qrtr_hdr_v1), \ + sizeof(struct qrtr_hdr_v2)) struct qrtr_sock { /* WARNING: sk must be the first member */ @@ -154,12 +182,12 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to) { - struct qrtr_hdr *hdr; + struct qrtr_hdr_v1 *hdr; size_t len = skb->len; int rc = -ENODEV; - hdr = skb_push(skb, QRTR_HDR_SIZE); - hdr->version = cpu_to_le32(QRTR_PROTO_VER); + hdr = skb_push(skb, sizeof(*hdr)); + hdr->version = cpu_to_le32(QRTR_PROTO_VER_1); hdr->type = cpu_to_le32(type); hdr->src_node_id = cpu_to_le32(from->sq_node); hdr->src_port_id = cpu_to_le32(from->sq_port); @@ -224,52 +252,80 @@ static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid) 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; + const struct qrtr_hdr_v1 *v1; + const struct qrtr_hdr_v2 *v2; struct sk_buff *skb; struct qrtr_cb *cb; - unsigned int psize; unsigned int size; - unsigned int type; unsigned int ver; - unsigned int dst; + size_t hdrlen; - if (len < QRTR_HDR_SIZE || len & 3) + if (len & 3) return -EINVAL; - ver = le32_to_cpu(phdr->version); - size = le32_to_cpu(phdr->size); - type = le32_to_cpu(phdr->type); - dst = le32_to_cpu(phdr->dst_port_id); + skb = netdev_alloc_skb(NULL, len); + if (!skb) + return -ENOMEM; - psize = (size + 3) & ~3; + cb = (struct qrtr_cb *)skb->cb; - if (ver != QRTR_PROTO_VER) - return -EINVAL; + /* Version field in v1 is little endian, so this works for both cases */ + ver = *(u8*)data; - if (len != psize + QRTR_HDR_SIZE) - return -EINVAL; + switch (ver) { + case QRTR_PROTO_VER_1: + v1 = data; + hdrlen = sizeof(*v1); - if (dst != QRTR_PORT_CTRL && type != QRTR_TYPE_DATA) - return -EINVAL; + cb->type = le32_to_cpu(v1->type); + cb->src_node = le32_to_cpu(v1->src_node_id); + cb->src_port = le32_to_cpu(v1->src_port_id); + cb->confirm_rx = !!v1->confirm_rx; + cb->dst_node = le32_to_cpu(v1->dst_node_id); + cb->dst_port = le32_to_cpu(v1->dst_port_id); - skb = netdev_alloc_skb(NULL, len); - if (!skb) - return -ENOMEM; + size = le32_to_cpu(v1->size); + break; + case QRTR_PROTO_VER_2: + v2 = data; + hdrlen = sizeof(*v2) + v2->optlen; + + cb->type = v2->type; + cb->confirm_rx = !!(v2->flags & QRTR_FLAGS_CONFIRM_RX); + cb->src_node = le16_to_cpu(v2->src_node_id); + cb->src_port = le16_to_cpu(v2->src_port_id); + cb->dst_node = le16_to_cpu(v2->dst_node_id); + cb->dst_port = le16_to_cpu(v2->dst_port_id); + + if (cb->src_port == (u16)QRTR_PORT_CTRL) + cb->src_port = QRTR_PORT_CTRL; + if (cb->dst_port == (u16)QRTR_PORT_CTRL) + cb->dst_port = QRTR_PORT_CTRL; + + size = le32_to_cpu(v2->size); + break; + default: + pr_err("qrtr: Invalid version %d\n", ver); + goto err; + } - 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; + if (len != ALIGN(size, 4) + hdrlen) + goto err; - skb_put_data(skb, data + QRTR_HDR_SIZE, size); + if (cb->dst_port != QRTR_PORT_CTRL && cb->type != QRTR_TYPE_DATA) + goto err; + + skb_put_data(skb, data + hdrlen, size); skb_queue_tail(&node->rx_queue, skb); schedule_work(&node->work); return 0; + +err: + kfree_skb(skb); + return -EINVAL; + } EXPORT_SYMBOL_GPL(qrtr_endpoint_post); @@ -287,11 +343,11 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt) const int pkt_len = sizeof(struct qrtr_ctrl_pkt); struct sk_buff *skb; - skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL); + skb = alloc_skb(QRTR_HDR_MAX_SIZE + pkt_len, GFP_KERNEL); if (!skb) return NULL; - skb_reserve(skb, QRTR_HDR_SIZE); + skb_reserve(skb, QRTR_HDR_MAX_SIZE); *pkt = skb_put_zero(skb, pkt_len); return skb; @@ -720,12 +776,12 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) } plen = (len + 3) & ~3; - skb = sock_alloc_send_skb(sk, plen + QRTR_HDR_SIZE, + skb = sock_alloc_send_skb(sk, plen + QRTR_HDR_MAX_SIZE, msg->msg_flags & MSG_DONTWAIT, &rc); if (!skb) goto out_node; - skb_reserve(skb, QRTR_HDR_SIZE); + skb_reserve(skb, QRTR_HDR_MAX_SIZE); rc = memcpy_from_msg(skb_put(skb, len), msg, len); if (rc) {