From nobody Tue Nov 26 08:43:52 2024 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C7E9204937; Fri, 18 Oct 2024 18:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275616; cv=none; b=nP51eHc34Edl1lpIBAE5H39B7xGvtr9iZJqouU8PFXH1JNrNgM3EO0Hx8kjohyKSsdc9+K7UjlhaodYfHoWjDocoGILLjHaGfHVChytc+PSLUAcvFEQzrjfLH8hwidM9miFozBoEdAXK/zOvBM/nASn9Y7S6LJMYM0O1vowi36g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275616; c=relaxed/simple; bh=4CxVELtCiC1PGqAMrMDaZY++hvnaH/4mDabb37qz28Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gq82gvo/pLYCc1OCx9D/9nPUSeeVjBVDy1YMJWzHoOu7/f4Uefb7Ma5uiAmssqXLViCn8kPTqd+eJckgTc/mW3El1+CSU53Hfw39Fy9rGetuSgYWvuasG/fuNy7zrDS08oFy+j3ZYfg139LTvpsD3dz1nydJPTlZV9OBwDGqiJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kvFHcF1X; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kvFHcF1X" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7180bd5b79dso826380a34.2; Fri, 18 Oct 2024 11:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275613; x=1729880413; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bEtsWUfg8YbHWegd1g+Jr8qqOJM5RSkKK7SlSHJ9GsA=; b=kvFHcF1XIFh1bqhCiT7nsTvEq6SDeRjBIVGxi9vmR7wv6ttSqDsVn5URFjIgmEBPWd jb6ECOFCDFZcDp5/GNrlJepIclSqMqg24K0BEWdxQlTSwo6WLuP3ToRxSlJS07bL8HbC j+/waD+qRw8BY18AYtIugbcP5k0Vm1OGo2rH6qszjQGCDSsRmwXDiVdw2c16o4Alod4d KXNODQz90VAlmyQD8ZA1yrhzzBVCk99jQhC8/yrhykJ/M0AuIdGvdHLSC4758y5NAbuA b1K8t/Jt23wxqg26Yd9DaZV89MQMkgPHqTh7yxB0NohNYcbmwX/CiN0gn+d6M04RFEKn eAtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275613; x=1729880413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bEtsWUfg8YbHWegd1g+Jr8qqOJM5RSkKK7SlSHJ9GsA=; b=KyaTdjCJyRHrdqYdPbm78BO6MnJ5xy+d8qRUOxoZzj4GXqcLvtezwk6PsvRw7imyVC jnbbXL4gpzYT71X0P1ZEZSDbZV9Y5BzYgoMVarx+yO/qw4Dpy6YYes+QVeXpar1Zbban ZRXgU7zEHz4h3OOswxjrKnUino+CyKFXylvHFzQbQ/Oq4skwz/F1ZttsJOIte0VQUeDV wP60Y2j6a5dGu8tap9x9bX+a4JbCY8Oyh2gLL0tIn1edBWTx3Wj4VKdBb3hMBeqMHFuU KYpOQIyo+Wyz34/5HFta45Iq3x10ES6axOXkiNK64CR6x/xwUO9/sl80fqYKcvl4ctSl 5Y6w== X-Forwarded-Encrypted: i=1; AJvYcCVWNmL6jet60QGmORUFRYXBCz1geEETsvxFCkZDOVTv99QW1psj+BZpxS4vmdX0U23iREupZz2yeUcSyvj4@vger.kernel.org, AJvYcCXOjSVIFBAgYgJIMsWdNQaXFXy1rrQHS6v4bG4SOx71Kg3gO/LX+0ksFVlgiMd0dtrI/S31Auk1sG+1aDdu@vger.kernel.org X-Gm-Message-State: AOJu0YxahSm5c9aTP1x8nSmAX1X9T4yuRJ384rYQQSIMeE1O+zVwN8M+ DpsZui7DisklwwOz71Jo5VX+YvNbmRYi+8ZqqCFYjGMPXI1fxH8fnLM2gw== X-Google-Smtp-Source: AGHT+IH/ZwPbMR+tkggdmm11Pqicm2tPVZQJBJrQzdCvwhafo8if+1UoU0Ata2i19T16kZzjOo3q/A== X-Received: by 2002:a05:6830:91b:b0:718:15a9:505a with SMTP id 46e09a7af769-7181a89f0e0mr2549619a34.23.1729275611695; Fri, 18 Oct 2024 11:20:11 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:11 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 01/10] net: qrtr: ns: validate msglen before ctrl_pkt use Date: Fri, 18 Oct 2024 13:18:19 -0500 Message-ID: <20241018181842.1368394-2-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The qrtr_ctrl_pkt structure is currently accessed without checking if the received payload is large enough to hold the structure's fields. Add a check to ensure the payload length is sufficient. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/ns.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 3de9350cbf30..6158e08c0252 100644 --- a/net/qrtr/ns.c +++ b/net/qrtr/ns.c @@ -619,6 +619,9 @@ static void qrtr_ns_worker(struct work_struct *work) break; } =20 + if ((size_t)msglen < sizeof(pkt)) + break; + pkt =3D recv_buf; cmd =3D le32_to_cpu(pkt->cmd); if (cmd < ARRAY_SIZE(qrtr_ctrl_pkt_strings) && --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 096E5204943; Fri, 18 Oct 2024 18:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275616; cv=none; b=hjHewqzl1wAVye7UXI4b/B+Solhc8A0qp+pXnCDUpLQwYseLh2y90b75Gu9zUGmJeDN80L/Ui/WaxYti/ZVwA6QXUTTC1Dan1JwE7S5w9GvULjIlRVwfgV8SbBx9RPxyUWCa3Gz47gMYDCzXts2u5bfBrw77+CSJUBstt9aN1a8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275616; c=relaxed/simple; bh=L23+6sq3kg2caMXWM/34FecMsesnc8/juvs69qPX+Wc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pr5QH3H7AaYplwWedEGek11h/rw7WajNlk5DOK8gzAoJmUzIawejyqaAROb8hil7HkiXOlTEsf21yGJ7Sz9A+WHQ8LtJOqN47AfgjLmJo0/t9BQuLTxPiTqGySrD8b7AlT9fu0/kgB7n0/dwQs4wTRSHqvuh7rWTPY6kGx7h9No= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C0YBLrsg; arc=none smtp.client-ip=209.85.161.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C0YBLrsg" Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5e98bfea0ceso1184067eaf.0; Fri, 18 Oct 2024 11:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275614; x=1729880414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ciGorupT18JNvO1t/IWulr06C4PqVaO5+ZCUGfEvvMY=; b=C0YBLrsgjRHAzSNX7BNuuLPcCQgxC7D2qKvR//STtIqvUFiFFT1qu7enHrZB4GN9HH 8WKuNnJlBN0jmqRPK07BoQQ+Rpn8AluLl3xmgJh6dz8jyiZIc5P3bCgj/VTy6TdIkHRZ reObXfldalm7NQsryyaUOKUcf+3H5bhGQ9c91DyxUdpM5Pg1xDw2Qc+/kIZvzC8Uo2oa a+mh/CH7nOEztN0tN2X0NsPz3/sQPR1czYg2FpKssdMvs2BhAtut4XFRGj1g3gUM7Mf+ s07ZlwwpuxiLds8l20II4mH4WZwHHJoFChvp4mQxP5JNnKm3J/H+LUYZ5viNL/5tQU/t HdEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275614; x=1729880414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ciGorupT18JNvO1t/IWulr06C4PqVaO5+ZCUGfEvvMY=; b=oKMQZSvcE7ATCW7Ub4G8q+jfDNBnDiDHhsFMauAfTfVIAuCi06o7YPbkLGBD8Ou7sx BdwrRQrjLZQ/irf2HtC02MumbUbzuIXWCtY41zmY5+RztLFtC0HwhSz1ADgSVZWshxR/ hHIKycO/yEmvNUbKA1SP4i16fix7tCs7lZSDzkURciuLPMP+K04LlmOp9+5WAJwDwd66 kDsSfV4YVyL3kR/Jkue2z/BC6FwQxP5uKwe8PJKz2R+C/ZEBl7/b5yzofKyK/Awj61S2 sBBPlz6BgABQLYOHLv2KW8DYkhTfDVyrp/OX9QpNHuQZpP5TJ531VuFf5yIW3NQJfEc7 AL9g== X-Forwarded-Encrypted: i=1; AJvYcCUlBD6ATS+Q/O2Cs1DdF+yJXfakDNTHQANS6ycrsx/IMPpEZYhJIsqoalbrNJ/IJqqjfH3Mf+ylMsD4YLDU@vger.kernel.org, AJvYcCV55SimWijPjGEXuPQ6llaon265nq/4T3zGIsZIGsyZV1vsTehon/kiWSJMZyE3FTXvzo/vLbPO8LUygnd8@vger.kernel.org X-Gm-Message-State: AOJu0Yx3viNCVFEV65l7vrI0iknk0LeHpt0BYOIbxQxgS17b10VBuA5C VGE4vQSW/mBdVy/PXyuu3LFUFKbEaRfaHuYQMGfzbNnFHFrNqszghditTQ== X-Google-Smtp-Source: AGHT+IFxbvRld1RRNMrjrSm2ZDFOtSkV02aoSNPU9/ci9YDUhC+qPIG7yGGbRPaWILoI0c4aqrYX/g== X-Received: by 2002:a05:6820:160d:b0:5e1:e87d:9e75 with SMTP id 006d021491bc7-5eb8b7970b8mr2674476eaf.5.1729275613871; Fri, 18 Oct 2024 11:20:13 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:13 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 02/10] net: qrtr: allocate and track endpoint ids Date: Fri, 18 Oct 2024 13:18:20 -0500 Message-ID: <20241018181842.1368394-3-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, QRTR endpoints are tracked solely by their pointer value, which is sufficient as they are not exposed to user space and it is assumed that each endpoint has a unique set of node identifiers associated with it. However, this assumption does not hold when multiple devices of the same type are connected to the system. For example, multiple PCIe based 5G modems. Such a setup results in multiple endpoints with confliciting node identifiers. To enable support for such scenarios, introduce the ability to track and assign unique identifiers to QRTR endpoints. These identifiers can then be exposed to user space, allowing for userspace clients to identify which endpoint sent a given message, or to direct a message to a specific endpoint. A simple allocation strategy is used based on xa_alloc_cyclic. Remote endpoint ids start at 'qrtr_local_nid' + 1. Since qrtr_local_nid is currently always set to 1 and never changed, node identifiers start at '1' for the local endpoint and 2..INT_MAX for remote endpoints. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 24 ++++++++++++++++++++++++ net/qrtr/qrtr.h | 1 + 2 files changed, 25 insertions(+) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index 00c51cf693f3..be275871fb2a 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -22,6 +22,7 @@ #define QRTR_MAX_EPH_SOCKET 0x7fff #define QRTR_EPH_PORT_RANGE \ XA_LIMIT(QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET) +#define QRTR_ENDPOINT_RANGE XA_LIMIT(qrtr_local_nid + 1, INT_MAX) =20 #define QRTR_PORT_CTRL_LEGACY 0xffff =20 @@ -109,6 +110,10 @@ static LIST_HEAD(qrtr_all_nodes); /* lock for qrtr_all_nodes and node reference */ static DEFINE_MUTEX(qrtr_node_lock); =20 +/* endpoint id allocation management */ +static DEFINE_XARRAY_ALLOC(qrtr_endpoints); +static u32 next_endpoint_id; + /* local port allocation management */ static DEFINE_XARRAY_ALLOC(qrtr_ports); =20 @@ -585,6 +590,8 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qr= tr_ctrl_pkt **pkt, int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid) { struct qrtr_node *node; + u32 endpoint_id; + int rc; =20 if (!ep || !ep->xmit) return -EINVAL; @@ -593,6 +600,13 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, u= nsigned int nid) if (!node) return -ENOMEM; =20 + rc =3D xa_alloc_cyclic(&qrtr_endpoints, &endpoint_id, NULL, + QRTR_ENDPOINT_RANGE, &next_endpoint_id, + GFP_KERNEL); + + if (rc < 0) + goto free_node; + kref_init(&node->ref); mutex_init(&node->ep_lock); skb_queue_head_init(&node->rx_queue); @@ -608,8 +622,12 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, u= nsigned int nid) list_add(&node->item, &qrtr_all_nodes); mutex_unlock(&qrtr_node_lock); ep->node =3D node; + ep->id =3D endpoint_id; =20 return 0; +free_node: + kfree(node); + return rc; } EXPORT_SYMBOL_GPL(qrtr_endpoint_register); =20 @@ -628,8 +646,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) struct sk_buff *skb; unsigned long flags; void __rcu **slot; + u32 endpoint_id; =20 mutex_lock(&node->ep_lock); + endpoint_id =3D node->ep->id; node->ep =3D NULL; mutex_unlock(&node->ep_lock); =20 @@ -656,6 +676,10 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) mutex_unlock(&node->qrtr_tx_lock); =20 qrtr_node_release(node); + + xa_erase(&qrtr_endpoints, endpoint_id); + + ep->id =3D 0; ep->node =3D NULL; } EXPORT_SYMBOL_GPL(qrtr_endpoint_unregister); diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h index 3f2d28696062..11b897af05e6 100644 --- a/net/qrtr/qrtr.h +++ b/net/qrtr/qrtr.h @@ -21,6 +21,7 @@ struct qrtr_endpoint { int (*xmit)(struct qrtr_endpoint *ep, struct sk_buff *skb); /* private: not for endpoint use */ struct qrtr_node *node; + u32 id; }; =20 int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid); --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2D89204F7E; Fri, 18 Oct 2024 18:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275618; cv=none; b=mR2nUj/FYecPe8+LgbSjN/ninHHNdnIr/aXodyufxR4kLabdBhXyyfwde0/rSvlISf01DWVGumMxfOhodtAd/pIYRWGV96DLZthHU0BB4fuzn9RwmwVTlK8mUSwKXA2UsAl1cG8KMP0hkZtY+cjDVcJ4MqLy7UNGPkomQRMX804= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275618; c=relaxed/simple; bh=WudN9ftC6DeqlaCrwSUWzPCAN0Q9s+iy462O/XnUrdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AyDTT6g4LjBnJXoobjgnU09LTnZxW4xKXbfHV5XuQYRe9m8q+7GSWpNrOzp7ucFeWCzzWpeAcjNX7tZG+VPqWNrtvQ8eDgzK+VAr50pEjVWFY1lI1R4mdlzzKfTeK3fuG4iQ4u1Xy/x+HEmwfzMM5JfsumfrmECLS7hGzpQl5ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NtyTox00; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NtyTox00" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5eb8099f2e2so815337eaf.3; Fri, 18 Oct 2024 11:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275615; x=1729880415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=33FckhCRiLLoBZH7c4mWURCUmvTf+hn2g56oXXwJibo=; b=NtyTox0042+vaO6foqBp/QM+OSiO7FwrUklF6o94otzoW5QHML9Uw9ZXjbouSc4lQG xjgM5ECty2Tz6XR88gdNrBtZoDeAqqgDQ9/D/o7Oc/rfhZH6bo4ViED3eSuPTkYD2SQz ybWshcL2Y+l2zfgQKDxVcr9Kk49uqp91uZdCqJnuffq1zsbv/47y7ewcZRtZrZ6337Ix H0SpntncP5zcKyuAs10Kp/h9Cs4XtOnfRMv3KuiOjYy27hAIv0weBXbdK3J2nwD5CMoG ijDLDZiPOvAH1/e82AE39F/ZGEPtgntR4B0jFpR5QabqCW101Szp+houkt7j/tmJ3/MO 1gzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275615; x=1729880415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=33FckhCRiLLoBZH7c4mWURCUmvTf+hn2g56oXXwJibo=; b=oA67Kfwjaf9vlVwNcjgBCgvrAq60tD2muiSHnu4CXkjXvz+ymxFdF0kwYueDbsi41o DmpVJ7raaJm4VWGPIO2t4EOsC92pprYSf8ep3jBLzVNjZkdh7WUOJfybovSXPNBoukd4 Ax88krXtWE5xgj3jWMobu6wEzxjXRVxNVLePDRFa7mldohOcLhGncTBnre6o5HjnPCel UqRTdZeBaadXfkeGPSwRhqHX2PgTGEpuvviMmNa5eR4u66KoTt7bvyqUmgzpBiY32ACN g4uaKYgeB91gWBMwfPbdqi/d19lCoxQBFJUoOsOKloSOqGIiDIyaIImFkI+3Kl2Ec/9/ 5txg== X-Forwarded-Encrypted: i=1; AJvYcCW619WKqyrkUfAulmOtECJZI+dkeQN7bf+/HIA5HUOvsd8OdS0+6EESxhR37qkdoIEy6csSdUNERbvjFsgf@vger.kernel.org, AJvYcCX67aESW8B8QD5Qr1x8wmZ75gJpnJojJE5lxj0HGqrhNq3a8JL0U5zrauvmeqEGmuZLIzO5V8JBqqZSGzhc@vger.kernel.org X-Gm-Message-State: AOJu0YwsEwRsDHLl4FD2HGs2JRcuS6R3aZ24QjjOaa0WlITe+ukYJL9Z tO/VlrzNdIoNgZY3jAEO3mxgO9VZGvsW54z1uS/tMldVe76na4JsESNhYg== X-Google-Smtp-Source: AGHT+IHyWOcgr4FWztL1ijnQ1zPOX+9VjBTxIsRdSUtYUaREeHMbbj4CLzZSuGU1zUiyi3qwWZiqZQ== X-Received: by 2002:a05:6820:610:b0:5e7:caf5:ae1f with SMTP id 006d021491bc7-5eb8b36af65mr3052839eaf.2.1729275615643; Fri, 18 Oct 2024 11:20:15 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:15 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 03/10] net: qrtr: support identical node ids Date: Fri, 18 Oct 2024 13:18:21 -0500 Message-ID: <20241018181842.1368394-4-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for tracking multiple endpoints that may have conflicting node identifiers. This is achieved by using both the node and endpoint identifiers as the key inside the radix_tree data structure. For backward compatibility with existing clients, the previous key schema (node identifier only) is preserved. However, this schema will only support the first endpoint/node combination. This is acceptable for legacy clients as support for multiple endpoints with conflicting node identifiers was not previously possible. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index be275871fb2a..e83d491a8da9 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -418,12 +418,20 @@ static struct qrtr_node *qrtr_node_lookup(unsigned in= t nid) static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid) { unsigned long flags; + unsigned long key; =20 if (nid =3D=3D QRTR_EP_NID_AUTO) return; =20 spin_lock_irqsave(&qrtr_nodes_lock, flags); - radix_tree_insert(&qrtr_nodes, nid, node); + + /* Always insert with the endpoint_id + node_id */ + key =3D (unsigned long)node->ep->id << 32 | nid; + radix_tree_insert(&qrtr_nodes, key, node); + + if (!radix_tree_lookup(&qrtr_nodes, nid)) + radix_tree_insert(&qrtr_nodes, nid, node); + if (node->nid =3D=3D QRTR_EP_NID_AUTO) node->nid =3D nid; spin_unlock_irqrestore(&qrtr_nodes_lock, flags); --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B23E204943; Fri, 18 Oct 2024 18:20:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275623; cv=none; b=Modh/xsDkuBVP/Q1B51nza+6xJ6Z+769t8IBKMYQ42P8u/M+LnafWGQ/JjazXtBWdWaIqdiTEPB1gLNp5BUpXxV2oH2IQaYe8NMFoxkDs8Oh/HNQZw6XDce0rBrRHi/d1wKt/ev0UfzgNVl5RTr7IB/4kbjoJQyYFbCmYXBX6HE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275623; c=relaxed/simple; bh=42N8FciEStj25u9SRmfxdwezJlhIErqX4t77tU6oh/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HmwLid2HB9p5ufhhQUCmvXYseK6QQ2fuULJph3BnCXz6ghsyDVxXkBOfmCmLgMqY86LxUGJb8pusgVMXRHitbb3TY5TODmlVlzAzNG8eJ70osWvthaS53DnEmbeXcsoQRgNUZjjKw52IO0s8Ru8dC9usMAZvBflzSmtIA8fQISI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mtdn81k8; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mtdn81k8" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5eb5be68c7dso1290680eaf.0; Fri, 18 Oct 2024 11:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275620; x=1729880420; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZczAMi2hDqPWVMrpvbf8BFefPSLZzPya8/DNabzq6mw=; b=mtdn81k82N53/fDnGZrJGi95VvRNwqXNNznQNiBgB1HBBxgtARUzIWPbgoWwhpSjPk Y7ouaopXunrDacwdelRFmlcVmIOBNC7yDyfBp6FjzufoNGBMflCDUsfBMViP7r3Ifs/F H00QVnzbaTR4YhsdEg8qxPaACz0ssQsymOmDKMmlQ8J2KdjD1oLsuoJ6z7QebmRnRrVC 3kr3yEaQQlpftoWgdTuuwjKWLLs5vRA8yglo6bvtoUyaI5AoG6aawiJHkhdvBt9+H/aw cP/0/zpUSWJ8/yL0a1B4TTr6GVmIMwqRrCEs0q3iI4Y26VCcOwo9itOUudOAXmT2Ec4/ Tgpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275620; x=1729880420; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZczAMi2hDqPWVMrpvbf8BFefPSLZzPya8/DNabzq6mw=; b=Nn8b29u0Ie32XAh7W6EBtS1fSrigTi3MAxXwawDXyF/2vHCJj9SNZlzJ6sII3TkkTd AGC1PD4YKIa7wSj3M9I41AmOSzducBGsXibD0VH/OkvtdEs3skr03sxhLyiOIsceXfTi 9objk3bxauafYN8uWXB8srQ+iM+SOxugb9vW8ZzznkMfD9WNjj1+XPaZBys8Nb6SRGSn nKhoE1cosbtYIBM1wP65KGhBFk9/sfLfXDiZO6qHU8n+ed1RFQFKJN9JxexaDwP3ZGSr 01IQ+nKjcIOKZ9p2TeFZU2VSd2N+VG/I/MvcbS49d/L94EmV+apJLgzk9M8P6GPPtaTw k3qQ== X-Forwarded-Encrypted: i=1; AJvYcCUqWDPMC/RMmfVYldxZwfZQO0FyE8sMpMmo8yCeqpqViqMA4iIi4NsN9FNY//j34rFHLMZpnfGAGJtYapau@vger.kernel.org, AJvYcCXA726n6+Ou8Or18cO7I/Gmk/vmBV3D7190LRkAMYgTR1AkP9fA0os0Ggux1BAFR1t2JIwkAY9etiXfiDpr@vger.kernel.org X-Gm-Message-State: AOJu0YyWnzzVGtAt55xBCgqiNswt2A9ojHuwBImgnPnz+Z6NLSujh2qi jpU6i19nLUdzHFUl0M8IsCJyr0PH5/W/3sexdYJpYW8EGWwuVadEUGRexA== X-Google-Smtp-Source: AGHT+IECMyRQDXwQa1ChpcsRURplDsYElR0Gfmuwtu0DhTGmjYpZKuJZIRc6M7V2ub+V0BTGdcM9XA== X-Received: by 2002:a05:6820:151a:b0:5e5:d0c8:8030 with SMTP id 006d021491bc7-5eb8b551749mr3017383eaf.3.1729275620066; Fri, 18 Oct 2024 11:20:20 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:19 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jens Axboe , Pavel Begunkov , Kuniyuki Iwashima , Gabriel Krisman Bertazi , Mina Almasry , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [RFC PATCH v1 04/10] net: qrtr: Report sender endpoint in aux data Date: Fri, 18 Oct 2024 13:18:22 -0500 Message-ID: <20241018181842.1368394-5-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce support for reporting the remote endpoint that generated a given QRTR message to clients using AF_QIPCRTR family sockets. This is achieved by including QRTR_ENDPOINT auxiliary data, which carries the endpoint identifier of the message sender. To receive this auxiliary data, clients must explicitly opt-in by using setsockopt with the QRTR_REPORT_ENDPOINT option enabled. Implementation of getsockopt and setsockopt is provided. An additional level 'SOL_QRTR' is added to socket.h for use by AF_QIPCRTR family sockets. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- include/linux/socket.h | 1 + include/uapi/linux/qrtr.h | 6 +++ net/qrtr/af_qrtr.c | 87 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/include/linux/socket.h b/include/linux/socket.h index d18cc47e89bd..7491884340cf 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -386,6 +386,7 @@ struct ucred { #define SOL_MCTP 285 #define SOL_SMC 286 #define SOL_VSOCK 287 +#define SOL_QRTR 288 =20 /* IPX options */ #define IPX_TYPE 1 diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h index f7e2fb3d752b..6d0911984a05 100644 --- a/include/uapi/linux/qrtr.h +++ b/include/uapi/linux/qrtr.h @@ -46,4 +46,10 @@ struct qrtr_ctrl_pkt { }; } __packed; =20 +/* setsockopt / getsockopt */ +#define QRTR_REPORT_ENDPOINT 1 + +/* CMSG */ +#define QRTR_ENDPOINT 1 + #endif /* _LINUX_QRTR_H */ diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index e83d491a8da9..cb7bd1c71e6d 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -26,6 +26,10 @@ =20 #define QRTR_PORT_CTRL_LEGACY 0xffff =20 +enum { + QRTR_F_REPORT_ENDPOINT, +}; + /** * struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1 * @version: protocol version @@ -79,6 +83,7 @@ struct qrtr_cb { u32 src_port; u32 dst_node; u32 dst_port; + u32 endpoint_id; =20 u8 type; u8 confirm_rx; @@ -92,6 +97,7 @@ struct qrtr_sock { struct sock sk; struct sockaddr_qrtr us; struct sockaddr_qrtr peer; + unsigned long flags; }; =20 static inline struct qrtr_sock *qrtr_sk(struct sock *sk) @@ -513,6 +519,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const = void *data, size_t len) if (cb->dst_port =3D=3D QRTR_PORT_CTRL_LEGACY) cb->dst_port =3D QRTR_PORT_CTRL; =20 + cb->endpoint_id =3D ep->id; + if (!size || len !=3D ALIGN(size, 4) + hdrlen) goto err; =20 @@ -1064,6 +1072,7 @@ static int qrtr_recvmsg(struct socket *sock, struct m= sghdr *msg, size_t size, int flags) { DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name); + struct qrtr_sock *ipc =3D qrtr_sk(sock->sk); struct sock *sk =3D sock->sk; struct sk_buff *skb; struct qrtr_cb *cb; @@ -1089,6 +1098,10 @@ static int qrtr_recvmsg(struct socket *sock, struct = msghdr *msg, msg->msg_flags |=3D MSG_TRUNC; } =20 + if (cb->endpoint_id && test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags)) + put_cmsg(msg, SOL_QRTR, QRTR_ENDPOINT, + sizeof(cb->endpoint_id), &cb->endpoint_id); + rc =3D skb_copy_datagram_msg(skb, 0, msg, copied); if (rc < 0) goto out; @@ -1234,6 +1247,78 @@ static int qrtr_ioctl(struct socket *sock, unsigned = int cmd, unsigned long arg) return rc; } =20 +static int qrtr_setsockopt(struct socket *sock, int level, int optname, + sockptr_t optval, unsigned int optlen) +{ + struct qrtr_sock *ipc =3D qrtr_sk(sock->sk); + struct sock *sk =3D sock->sk; + unsigned int val =3D 0; + int rc =3D 0; + + if (level !=3D SOL_QRTR) + return -ENOPROTOOPT; + + if (optlen >=3D sizeof(val) && + copy_from_sockptr(&val, optval, sizeof(val))) + return -EFAULT; + + lock_sock(sk); + + switch (optname) { + case QRTR_REPORT_ENDPOINT: + assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val); + break; + default: + rc =3D -ENOPROTOOPT; + } + + release_sock(sk); + + return rc; +} + +static int qrtr_getsockopt(struct socket *sock, int level, int optname, + char __user *optval, int __user *optlen) +{ + struct qrtr_sock *ipc =3D qrtr_sk(sock->sk); + struct sock *sk =3D sock->sk; + unsigned int val; + int len; + int rc =3D 0; + + if (level !=3D SOL_QRTR) + return -ENOPROTOOPT; + + if (get_user(len, optlen)) + return -EFAULT; + + if (len < sizeof(val)) + return -EINVAL; + + lock_sock(sk); + + switch (optname) { + case QRTR_REPORT_ENDPOINT: + val =3D test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags); + break; + default: + rc =3D -ENOPROTOOPT; + } + + release_sock(sk); + + if (rc) + return rc; + + len =3D sizeof(int); + + if (put_user(len, optlen) || + copy_to_user(optval, &val, len)) + rc =3D -EFAULT; + + return rc; +} + static int qrtr_release(struct socket *sock) { struct sock *sk =3D sock->sk; @@ -1281,6 +1366,8 @@ static const struct proto_ops qrtr_proto_ops =3D { .shutdown =3D sock_no_shutdown, .release =3D qrtr_release, .mmap =3D sock_no_mmap, + .setsockopt =3D qrtr_setsockopt, + .getsockopt =3D qrtr_getsockopt, }; =20 static struct proto qrtr_proto =3D { --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FE0020697D; Fri, 18 Oct 2024 18:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275625; cv=none; b=qFZ7+07uapnEx8pEzQbngKwZSps1NQgdIGlTYWNARkvcRZquIMCIsL2/hkNt7VsoZnNHCbrBTVfV9KRsrheaBlY/hBdCHlT40hsNYu5JOSDfEATKpR92A5vP6nmTu7kRfNPBO7GcghrjdVpYXrme7LSQw3Ml1n5YHBgVQGfzavU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275625; c=relaxed/simple; bh=Jqk9t6WqUxgOSLlvZ3OiYUOtfU662Z01mQkIZRFbT5U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TBCuRthCuKH1rQ5lXLOBUNeZ1i6WV0OSvWLGLMKd4KSGHAbN9LB6X4yCRGz2lJIZEVVS6kY/Oh9T0Up+hbGYlxXTjNUA4fRNRcwmYANwgoMgZ2yzeQYwBQ6QwGB/I54l17gxhMEfZcW3IcSt9aQrtdBHY5MmtlSIhKcOvF8c5z8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XS22+Iaq; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XS22+Iaq" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5eb6abc6342so1478258eaf.0; Fri, 18 Oct 2024 11:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275622; x=1729880422; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wTMpYIXHYNCs7bSRCpbxFRGF6reME+eyLPM7z+f7+Fc=; b=XS22+IaqqXUujk3Gitl8xsdZ67QD4MDiUcNzDDHvOzNGCPcnbX+0AY5xLKjMK+0+8s wljLMblcQoUmiDeZwoqb13GgQmsqyw2rOlCKamwdfFMCl0pvA2ExgbgIThnFQvnOIXy2 xDui7pNzJi774cID7xctFUt5LnScCb/TYSpyh1hWp7qdOg3W8AuQLvQ6OGvDZ2ooUMCm 3H8IWV/4cdi4E7q3CD3ZGk817lcKRZf0ttnht81MFwomUnlSEZcjgtVu4rVWl0CyqBwF JMzLySzHSr+WEX59qKCL1iACJzsijguUpQS+m4b8Emzp4eSigiGDGw0NFbYjLDNkb4nR PkGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275622; x=1729880422; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wTMpYIXHYNCs7bSRCpbxFRGF6reME+eyLPM7z+f7+Fc=; b=hmvZ7QTQ2FBNR2Nl5ztico4SCLk3YxQG8S+qUJvoGE5UK7+DoR1sBsJBIV/0xfJsbZ DPC6IlDB6P1ataGX3HOGn9gClPEUoQlnfnSzGg4SvQhQvUbLI1Ud3OGDwhmCyRb/OSrM KFRZTfvuy+UhDkyI31WTOEfnClQfz/o3qR8/+lCsfToWfOJGgEjAV0zDllSpG/ZBhc9t 5VC1hbY3er5dmfJ2UQ3LAcpwyJb3P3w5Ox4wDIc3KGy6dP90VeZE2vaElzv1y/z8B9Dd UH0oD37jBtVjQ9suYDn+QdMuGfI61yhsK3UvhxFOuWNFBtpt/NEpN/a0bjSoZUPUTSc7 h6kA== X-Forwarded-Encrypted: i=1; AJvYcCVDmqriWoef0YpXoyq0Bqa7DtZE+JeqQib/6doVyYmotVDTeMHExL8Me2GrbTDAO9TXifmS/mi4ccVeU2UO@vger.kernel.org, AJvYcCVTCfaoWWe2iVSUdUoo2FKy0VnAEM+L5dRJwamMBIPiUEYBowfDy811mieOQ6a6rS25bIqjgELcefzV8KRZ@vger.kernel.org X-Gm-Message-State: AOJu0Yz5vo/S+hnmjkPZWPQFkC2G/m2PelcUlJ3oOrWnv4UOsXp0hRIH RVGH2XChZYFKk8Q5WHaVwe5eRXR3lsfNxujNvzCOlFWdYS6CflNZImEgRw== X-Google-Smtp-Source: AGHT+IHrr5ctvzud0yteza2a9cQOrgEySRGHiYN8KdAn2gGnVum2L6yeh0XMgP24bYfrrwCWYJSZMw== X-Received: by 2002:a05:6820:1ac5:b0:5e3:b361:e457 with SMTP id 006d021491bc7-5eb8b378a7fmr2949706eaf.1.1729275622139; Fri, 18 Oct 2024 11:20:22 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:21 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 05/10] net: qrtr: Report endpoint for locally generated messages Date: Fri, 18 Oct 2024 13:18:23 -0500 Message-ID: <20241018181842.1368394-6-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For messages generated by the local endpoint destined to the local endpoint, report the local endpoint identifier. Same QRTR_ENDPOINT auxiliary data and QRTR_REPORT_ENDPOINT socket option semantics apply as for messages generated by remote endpoints. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index cb7bd1c71e6d..568ccb1d8574 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -163,9 +163,11 @@ struct qrtr_tx_flow { #define QRTR_TX_FLOW_LOW 5 =20 static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to); static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to); static struct qrtr_sock *qrtr_port_lookup(int port); @@ -349,6 +351,7 @@ static void qrtr_tx_flow_failed(struct qrtr_node *node,= int dest_node, =20 /* Pass an outgoing packet socket buffer to the endpoint driver. */ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to) { @@ -678,7 +681,8 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) skb =3D qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC); if (skb) { pkt->cmd =3D cpu_to_le32(QRTR_TYPE_BYE); - qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst); + qrtr_local_enqueue(NULL, skb, endpoint_id, + QRTR_TYPE_BYE, &src, &dst); } } spin_unlock_irqrestore(&qrtr_nodes_lock, flags); @@ -745,8 +749,8 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) pkt->client.port =3D cpu_to_le32(ipc->us.sq_port); =20 skb_set_owner_w(skb, &ipc->sk); - qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us, - &to); + qrtr_bcast_enqueue(NULL, skb, qrtr_local_nid, + QRTR_TYPE_DEL_CLIENT, &ipc->us, &to); } =20 if (port =3D=3D QRTR_PORT_CTRL) @@ -886,6 +890,7 @@ static int qrtr_bind(struct socket *sock, struct sockad= dr *saddr, int len) =20 /* Queue packet to local peer socket. */ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to) { @@ -903,6 +908,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, s= truct sk_buff *skb, cb =3D (struct qrtr_cb *)skb->cb; cb->src_node =3D from->sq_node; cb->src_port =3D from->sq_port; + cb->endpoint_id =3D endpoint_id; =20 if (sock_queue_rcv_skb(&ipc->sk, skb)) { qrtr_port_put(ipc); @@ -917,6 +923,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, s= truct sk_buff *skb, =20 /* Queue packet for broadcast. */ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to) { @@ -928,11 +935,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, type, from, to); + qrtr_node_enqueue(node, skbn, endpoint_id, type, from, to); } mutex_unlock(&qrtr_node_lock); =20 - qrtr_local_enqueue(NULL, skb, type, from, to); + qrtr_local_enqueue(NULL, skb, endpoint_id, type, from, to); =20 return 0; } @@ -940,12 +947,13 @@ 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 le= n) { DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name); - int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int, + int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, u32, int, struct sockaddr_qrtr *, struct sockaddr_qrtr *); __le32 qrtr_type =3D cpu_to_le32(QRTR_TYPE_DATA); struct qrtr_sock *ipc =3D qrtr_sk(sock->sk); struct sock *sk =3D sock->sk; struct qrtr_node *node; + u32 endpoint_id =3D qrtr_local_nid; struct sk_buff *skb; size_t plen; u32 type; @@ -1029,7 +1037,7 @@ static int qrtr_sendmsg(struct socket *sock, struct m= sghdr *msg, size_t len) } =20 type =3D le32_to_cpu(qrtr_type); - rc =3D enqueue_fn(node, skb, type, &ipc->us, addr); + rc =3D enqueue_fn(node, skb, endpoint_id, type, &ipc->us, addr); if (rc >=3D 0) rc =3D len; =20 @@ -1061,7 +1069,8 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb) pkt->client.node =3D cpu_to_le32(cb->dst_node); pkt->client.port =3D cpu_to_le32(cb->dst_port); =20 - ret =3D qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &local, &remote= ); + ret =3D qrtr_node_enqueue(node, skb, cb->endpoint_id, + QRTR_TYPE_RESUME_TX, &local, &remote); =20 qrtr_node_release(node); =20 --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2942D2076CF; Fri, 18 Oct 2024 18:20:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275627; cv=none; b=MWJbA5VQurhohevaos/So+9ydKAane8r/JSSmWlR8Zmb6Bhhb47Bcd9P286y1uri1pNEPI4+66cmqP093/ux/A0Q68Pe08KS1B2EoP2LpLJX104eB6vUyeDU8Ot4+XxW2i8lOEpC6C5pbd5MCJeFK7txGslKTa0iFvgd7L14nTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275627; c=relaxed/simple; bh=l4xxKg5YrJjM3W6imiFvX7Q+9nShLoDvCIMCu1xX1Fk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oqo/O1o7ioRVTphu1jKpDZwuMS7U+e7n+2dhKQqA/8TXXK+rFJabAW/ew4zaub4bBClYhWtjibbcFzGKvo0moad041Ea9vbQqn/jm/mJLkuLoDwb06AEZpCjUHSo8yrdz20mTQS5rBt9x4wfDGfJ5AaNcine63ZakdwWd63N+ys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k/93fNoT; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k/93fNoT" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5e7ff0f41caso1506359eaf.1; Fri, 18 Oct 2024 11:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275624; x=1729880424; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QStOGvOLdX3PrWtPehm1QP6E2mFCaI3TK2ezOt9+AZc=; b=k/93fNoTBmYeTlXDN9LN/bI+dcdtO9jjKSmtBCYqoOfDj15mFV/nfgN2pv1kFXawuh j/lFQiRuKK9EnyfQu2+B3rdbNN3egPAvD99TNZfdR4Cm+hKwSUZjw0Mir6YZGWPSfevx spLNzqRnB+J+niafAhKpg0qs6EdeEkixILiR3r/T/9Pj8XFI5RKmWXgu+b0LzN01r8XS zT+4Wv77kPXfrxnBn8bb1OHxPzrqUWlGJSM2TEvKraHvhnO7OGoEj3kPU/HMew1BG1dN E0vpK8fDpwsHxLqYDKGvHjlVsegV3NXskRyUs9CrQycuicyYeIgNZfXfouflUyAd1ffR cndg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275624; x=1729880424; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QStOGvOLdX3PrWtPehm1QP6E2mFCaI3TK2ezOt9+AZc=; b=xAvsl7Cz8818f3Og0IeJPxAfCO042GxvBmkwNofXjS046BKmSfiOSem9TK2ajUAjXg +2vt6B9sZj7BJcErODf1z9z+Zm+VBGeC1YzWQyGn/HP7TVGVkUHBh6OqyBOquv+OdBGV fLt5Fqdus91Pt2+ah9x9Mg3SPMzrTxRQEAFSLCQCcjhAbVrdKyBorJFG8c5QqFy+ksvS Q0/UfLo7m+R9TFq3e/H3C+U2mGfWwyU7fVx25XiIFcRfk9q5UmsVi8ehb1cO/5w5/oyo NZoO531M2OTVqRhHWVoBcKbjXOtOyFj6fJvezKNeJvOY7UAWPMwJgsmMrXU9CDhpCfXM jsGQ== X-Forwarded-Encrypted: i=1; AJvYcCVRUnXPkQ47uHl7UFtapbv2qep+pogs6NnC53N3HO0iTBfKXnIRVRKOkFuuWV0AdlGJAL2iFwd1ywAQ7wjJ@vger.kernel.org, AJvYcCXqC9Kh++zIvJISfxd1xhY2CANivRe+HZOb6vAxLKi2oogKIAH7RjdsaoEX480GkMhJ839cHykMRFTKp9z7@vger.kernel.org X-Gm-Message-State: AOJu0Ywka7SrV6J+8pDjhAamgCCQikWvDkHusBCcfX/r+Q7b84jIUvLh U00tVUpHBbeSltrsrFnuHYqAU/Rvobdn0sbato/pu5hEo9CpVo5mivJ3sQ== X-Google-Smtp-Source: AGHT+IFAk9Gg0hEqUNkR1emXEUhU6U7WuiIXXdl5U5vD2KGKOyVTjw/EU2bJN3n6U3M7C7WvcK7+gA== X-Received: by 2002:a05:6820:820:b0:5d6:ab0:b9a6 with SMTP id 006d021491bc7-5eb8c95ce67mr2181096eaf.4.1729275624105; Fri, 18 Oct 2024 11:20:24 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:23 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 06/10] net: qrtr: Allow sendmsg to target an endpoint Date: Fri, 18 Oct 2024 13:18:24 -0500 Message-ID: <20241018181842.1368394-7-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow QIPCRTR family sockets to include QRTR_ENDPOINT auxiliary data as part of the sendmsg system call. By including this parameter, the client can ask the kernel to route the message to a given endpoint, in situations where multiple endpoints with conflicting node identifier sets exist in the system. For legacy clients, or clients that do not include QRTR_ENDPOINT data, the endpoint is looked up, as before, by only using the node identifier of the destination qrtr socket address. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 80 +++++++++++++++++++++++++++++++++------------- net/qrtr/qrtr.h | 2 ++ 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index 568ccb1d8574..23749a0b0c15 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -106,6 +106,36 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *s= k) return container_of(sk, struct qrtr_sock, sk); } =20 +int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id) +{ + struct cmsghdr *cmsg; + u32 endpoint_id =3D 0; + + for_each_cmsghdr(cmsg, msg) { + if (!CMSG_OK(msg, cmsg)) + return -EINVAL; + + if (cmsg->cmsg_level !=3D SOL_QRTR) + continue; + + if (cmsg->cmsg_type !=3D QRTR_ENDPOINT) + return -EINVAL; + + if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32))) + return -EINVAL; + + /* Endpoint ids start at 1 */ + endpoint_id =3D *(u32 *)CMSG_DATA(cmsg); + if (!endpoint_id) + return -EINVAL; + } + + if (out_endpoint_id) + *out_endpoint_id =3D endpoint_id; + + return 0; +} + static unsigned int qrtr_local_nid =3D 1; =20 /* for node ids */ @@ -404,14 +434,16 @@ static int qrtr_node_enqueue(struct qrtr_node *node, = struct sk_buff *skb, * * callers must release with qrtr_node_release() */ -static struct qrtr_node *qrtr_node_lookup(unsigned int nid) +static struct qrtr_node *qrtr_node_lookup(unsigned int endpoint_id, + unsigned int nid) { struct qrtr_node *node; unsigned long flags; + unsigned long key =3D (unsigned long)endpoint_id << 32 | nid; =20 mutex_lock(&qrtr_node_lock); spin_lock_irqsave(&qrtr_nodes_lock, flags); - node =3D radix_tree_lookup(&qrtr_nodes, nid); + node =3D radix_tree_lookup(&qrtr_nodes, key); node =3D qrtr_node_acquire(node); spin_unlock_irqrestore(&qrtr_nodes_lock, flags); mutex_unlock(&qrtr_node_lock); @@ -953,6 +985,7 @@ static int qrtr_sendmsg(struct socket *sock, struct msg= hdr *msg, size_t len) struct qrtr_sock *ipc =3D qrtr_sk(sock->sk); struct sock *sk =3D sock->sk; struct qrtr_node *node; + u32 msg_endpoint_id; u32 endpoint_id =3D qrtr_local_nid; struct sk_buff *skb; size_t plen; @@ -965,46 +998,48 @@ static int qrtr_sendmsg(struct socket *sock, struct m= sghdr *msg, size_t len) if (len > 65535) return -EMSGSIZE; =20 + rc =3D qrtr_msg_get_endpoint(msg, &msg_endpoint_id); + if (rc < 0) + return rc; + lock_sock(sk); =20 if (addr) { - if (msg->msg_namelen < sizeof(*addr)) { - release_sock(sk); - return -EINVAL; - } + rc =3D -EINVAL; =20 - if (addr->sq_family !=3D AF_QIPCRTR) { - release_sock(sk); - return -EINVAL; - } + if (msg->msg_namelen < sizeof(*addr)) + goto release_sock; + + if (addr->sq_family !=3D AF_QIPCRTR) + goto release_sock; =20 rc =3D qrtr_autobind(sock); - if (rc) { - release_sock(sk); - return rc; - } + if (rc) + goto release_sock; } else if (sk->sk_state =3D=3D TCP_ESTABLISHED) { addr =3D &ipc->peer; } else { - release_sock(sk); - return -ENOTCONN; + rc =3D -ENOTCONN; + goto release_sock; } =20 node =3D NULL; if (addr->sq_node =3D=3D QRTR_NODE_BCAST) { if (addr->sq_port !=3D QRTR_PORT_CTRL && qrtr_local_nid !=3D QRTR_NODE_BCAST) { - release_sock(sk); - return -ENOTCONN; + rc =3D -ENOTCONN; + goto release_sock; } enqueue_fn =3D qrtr_bcast_enqueue; } else if (addr->sq_node =3D=3D ipc->us.sq_node) { enqueue_fn =3D qrtr_local_enqueue; } else { - node =3D qrtr_node_lookup(addr->sq_node); + endpoint_id =3D msg_endpoint_id; + + node =3D qrtr_node_lookup(endpoint_id, addr->sq_node); if (!node) { - release_sock(sk); - return -ECONNRESET; + rc =3D endpoint_id ? -ENXIO : -ECONNRESET; + goto release_sock; } enqueue_fn =3D qrtr_node_enqueue; } @@ -1043,6 +1078,7 @@ static int qrtr_sendmsg(struct socket *sock, struct m= sghdr *msg, size_t len) =20 out_node: qrtr_node_release(node); +release_sock: release_sock(sk); =20 return rc; @@ -1057,7 +1093,7 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb) struct sk_buff *skb; int ret; =20 - node =3D qrtr_node_lookup(remote.sq_node); + node =3D qrtr_node_lookup(cb->endpoint_id, remote.sq_node); if (!node) return -EINVAL; =20 diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h index 11b897af05e6..22fcecbf8de2 100644 --- a/net/qrtr/qrtr.h +++ b/net/qrtr/qrtr.h @@ -34,4 +34,6 @@ int qrtr_ns_init(void); =20 void qrtr_ns_remove(void); =20 +int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id); + #endif --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6593A20969D; Fri, 18 Oct 2024 18:20:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275629; cv=none; b=KlMm75/82e85FzwMJaIMpH/Z7kdGKWg4s9O0mOqPkA8M5+lMTIyJJTZn6Ogts70lj46BJh3CMtJAWgN0jY7lJKAxx7NQZz/dUaxnyS5kG3LwglaxkQ5ogfWjwZLsBKk1ySkL5Xh1B795LTAMWukaNqMdCQ86uKTfPStnN/UB8Bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275629; c=relaxed/simple; bh=3XACKo/pFuD+zNXmFPGHbf4kk7ld46ZIOgUe2iuHHBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SzvgrTTUJxP1sAwgRe0VNtQpgkKF/d6tEqPhvY2gbr9GNzdc1YqtKVjRp66R1mTT27j1Evw0EPs4dubE+c0ZACBeItI8kfXf+Qlyd18IqazEYyTJ/owGf+8Wbc6zjRaO7i+wPYrlKUL+Zmu4td6pmwLBoMdqxCfeVL+k5sw2K6s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aW+h6HfU; arc=none smtp.client-ip=209.85.161.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aW+h6HfU" Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5eb70a772ccso1195294eaf.0; Fri, 18 Oct 2024 11:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275626; x=1729880426; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ndKcW9vvldcHXXks3zBgM3lQGpSUMPL+gKrZxYgEdL4=; b=aW+h6HfUukK+MwsF2Rkbua3GUm6VAEZKyty2jst41Jjj9mzTV/oyPi1/Bm1FULzWRv zYh8RRmWU52m4q3/TqjqbpGni0DY1V8kQmc5xLAMAXWQLt7V00BcD9d3U1aaHhIsoKaw ZX3SI0OoL9VpHOnAjCWGm4LedRCQjNto6HPhYZx3bcg6GT3Kj9ny9mQZbP1Tb6F5Bnaj C0HOLZ4I/SZ9MBc6L2QIY0jP/dkE5SMFH6rFfAL15hkuO8le3sKG/gZ9n26MBF9f3rla pfxbsQWdMugOQYKU77+GJq5UZBp7tBI4tLvEDvFcnlN1QBybLm50Mta+1Sf4dqJ6ol6p In+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275626; x=1729880426; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ndKcW9vvldcHXXks3zBgM3lQGpSUMPL+gKrZxYgEdL4=; b=gchnV7IGvPfHNbsDkmgaDQFDVNo43ZvGD0ifGNtG9l71230Y/4/afXvPeMyRJtmTky PrACX8ueXLbpG/jtgLbQ2H8ZKD+QXhKorWA2NJBAPR0gPiM88WSt5viF4rK+/H3pHntJ 0Jp98W02jRnVPUySYagv+fV6UxviofV1mgx+q7j9fNRPPeCYmC7wagqmmhDyn72vFjkX EAn++5Y0cocpPaLbTXi9yGTRLCM7uqrgNC7HTVvSuCk1P0Toa45xNf6aaV2ALcPiqkwR XqCGuINN8bPAy1M5Rr4S3MG5na3gEJSfCV5nVOGH+8uOOCiQoDXRCg1pDR2Rs2IHGSzB RjmQ== X-Forwarded-Encrypted: i=1; AJvYcCUoXqBk9xhycRehwqR07++fAxkN5o+RfaGSDVaB3g4e+i5KCOtRAeFJNJDOo6MxaBESg908KgluburXYkBq@vger.kernel.org, AJvYcCVfqYKA6GVeJp4cRC7fbl/zEBcui+/MxAtombYBwJitAXtvDx/VjOclRuBifhM0ctRQf3CrI+djs8igoNpF@vger.kernel.org X-Gm-Message-State: AOJu0YxhdnFdpKGl/eL2MrNfOyD8CNQwhpKTr8amiwEfjVwf1PYzUD4J edvnZ97jUWOb+t5+c3b2/LOv3lDkEt0mLBZ4PqbSsGIJ8/Nwzcw4TAKXrg== X-Google-Smtp-Source: AGHT+IHOOMjMq52wLrdAP+g4LwRWu1SqN7ru4viQIFijEXQNfxYMvFv0Wz4XN7fg+mnLor72B1cwQQ== X-Received: by 2002:a05:6820:610:b0:5eb:7e7c:5303 with SMTP id 006d021491bc7-5eb8b3a7aa3mr2374335eaf.2.1729275626329; Fri, 18 Oct 2024 11:20:26 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:25 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 07/10] net: qrtr: allow socket endpoint binding Date: Fri, 18 Oct 2024 13:18:25 -0500 Message-ID: <20241018181842.1368394-8-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the ability to bind a QIPCRTR family socket to a specific endpoint. When a socket is bound, only messages from the bound endpoint can be received, and any messages sent from the socket are by default directed to the bound endpoint. Clients can bind a socket by using the setsockopt system call with the QRTR_BIND_ENDPOINT option set to the desired endpoint binding. A previously set binding can be reset by setting QRTR_BIND_ENDPOINT option to zero. This behavior matches that of SO_BINDTOIFINDEX. This functionality is useful for clients that need to communicate with a specific device (i.e. endpoint), such as a PCIe-based 5G modem, and are not interested in messages from other endpoints / nodes. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- include/uapi/linux/qrtr.h | 1 + net/qrtr/af_qrtr.c | 54 ++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h index 6d0911984a05..0a8667b049c3 100644 --- a/include/uapi/linux/qrtr.h +++ b/include/uapi/linux/qrtr.h @@ -48,6 +48,7 @@ struct qrtr_ctrl_pkt { =20 /* setsockopt / getsockopt */ #define QRTR_REPORT_ENDPOINT 1 +#define QRTR_BIND_ENDPOINT 2 =20 /* CMSG */ #define QRTR_ENDPOINT 1 diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index 23749a0b0c15..b2f9c25ba8f8 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -98,6 +98,7 @@ struct qrtr_sock { struct sockaddr_qrtr us; struct sockaddr_qrtr peer; unsigned long flags; + u32 bound_endpoint; }; =20 static inline struct qrtr_sock *qrtr_sk(struct sock *sk) @@ -587,9 +588,13 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const= void *data, size_t len) if (!ipc) goto err; =20 - if (sock_queue_rcv_skb(&ipc->sk, skb)) { - qrtr_port_put(ipc); - goto err; + /* Sockets bound to an endpoint only rx from that endpoint */ + if (!ipc->bound_endpoint || + ipc->bound_endpoint =3D=3D cb->endpoint_id) { + if (sock_queue_rcv_skb(&ipc->sk, skb)) { + qrtr_port_put(ipc); + goto err; + } } =20 qrtr_port_put(ipc); @@ -928,29 +933,41 @@ static int qrtr_local_enqueue(struct qrtr_node *node,= struct sk_buff *skb, { struct qrtr_sock *ipc; struct qrtr_cb *cb; + int ret =3D -ENODEV; =20 ipc =3D qrtr_port_lookup(to->sq_port); - if (!ipc || &ipc->sk =3D=3D skb->sk) { /* do not send to self */ - if (ipc) - qrtr_port_put(ipc); - kfree_skb(skb); - return -ENODEV; - } + if (!ipc) + goto done; + + if (&ipc->sk =3D=3D skb->sk) /* do not send to self */ + goto done; + + /* + * Filter out unwanted packets that are not on behalf of the bound + * endpoint. Certain special packets (such as an empty NEW_SERVER + * packet that serves as a sentinel value) always go through. + */ + if (endpoint_id && ipc->bound_endpoint && + ipc->bound_endpoint !=3D endpoint_id) + goto done; =20 cb =3D (struct qrtr_cb *)skb->cb; cb->src_node =3D from->sq_node; cb->src_port =3D from->sq_port; cb->endpoint_id =3D endpoint_id; =20 - if (sock_queue_rcv_skb(&ipc->sk, skb)) { - qrtr_port_put(ipc); - kfree_skb(skb); - return -ENOSPC; - } + ret =3D -ENOSPC; + if (sock_queue_rcv_skb(&ipc->sk, skb)) + goto done; =20 qrtr_port_put(ipc); =20 return 0; +done: + if (ipc) + qrtr_port_put(ipc); + kfree_skb(skb); + return ret; } =20 /* Queue packet for broadcast. */ @@ -1034,7 +1051,8 @@ static int qrtr_sendmsg(struct socket *sock, struct m= sghdr *msg, size_t len) } else if (addr->sq_node =3D=3D ipc->us.sq_node) { enqueue_fn =3D qrtr_local_enqueue; } else { - endpoint_id =3D msg_endpoint_id; + endpoint_id =3D msg_endpoint_id ? + msg_endpoint_id : ipc->bound_endpoint; =20 node =3D qrtr_node_lookup(endpoint_id, addr->sq_node); if (!node) { @@ -1313,6 +1331,9 @@ static int qrtr_setsockopt(struct socket *sock, int l= evel, int optname, case QRTR_REPORT_ENDPOINT: assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val); break; + case QRTR_BIND_ENDPOINT: + ipc->bound_endpoint =3D val; + break; default: rc =3D -ENOPROTOOPT; } @@ -1346,6 +1367,9 @@ static int qrtr_getsockopt(struct socket *sock, int l= evel, int optname, case QRTR_REPORT_ENDPOINT: val =3D test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags); break; + case QRTR_BIND_ENDPOINT: + val =3D ipc->bound_endpoint; + break; default: rc =3D -ENOPROTOOPT; } --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CB3120B209; Fri, 18 Oct 2024 18:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275631; cv=none; b=U9Au5mB2FQofNBoA5A5hO4joGu9Ul8MBklJWZYWc2E9sjWJ6Pg0Cy+Ny5o/Pffm5N5G8vAdpI0uomqlvO1wZgYWHEjegxVMZW4Mrga72X5ICGVpYI/uY/yTbxkXcx1B6bV8riHSC9PgmDo0chkM514tApf3muz+si5Z3Rzl5s+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275631; c=relaxed/simple; bh=K6TGwjaC6x34laNvtnUI/gfDwGY3CtnGj3CGQQdvOAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gdlg2Lpqq/hLsnk2/3fRGX1UBFiuxdsv3F9rPHtvpdddm8Bv9f+/9ag8ZKukLHf2jWpxeVc1UswoBQxInhAlTMcIpgfCz2Cuvh/mL/cAoDbEN7PDTeUluPIAGAJgYcx5EXHGaXQRGlg6uAaim4EKbvgkBS3jUEUns0JYT54MbJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zl+jLCLs; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zl+jLCLs" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-7180e07185bso1061155a34.3; Fri, 18 Oct 2024 11:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275628; x=1729880428; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ovKNqE6RDKN0Hrsi58QwvncI+Go0wvmwlY1ykYujsaE=; b=Zl+jLCLspriE8pwuBSJ4Axz5oHzQx473gGOl2zNU5bm/ULACz6oSXe4sVU8Rp5lneO dWttd2Nqp4L+AfKt/b7TyRiL/QqAZE0dgZJBc7iAmUo/aENRZ/xG2gnH6hTc2zkdspC8 vWmRYlx/+rQNJ+ZeBKXgrIt+kldNEEEAJdwWIM9UQCfqTb7oIhxiY9w9meiS5IFb+k6m QK6mPNOvVu4hy/yN+7On0z2DuOIEnu8LLkVtQT0xsi50ffXODnrzXNzagJ8UcZ9w3bCp VK/aAYSF3VMOkgPnJEZbmOjq0x/YHNjMaHuqZk20gTQB7u/a2GD+p8lx4/Ff0UNGYLab IsnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275628; x=1729880428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ovKNqE6RDKN0Hrsi58QwvncI+Go0wvmwlY1ykYujsaE=; b=TTgCb892nqw3dOqRVDSPa8WJsAOmJIMcNdBr3iuoEe5MbAiEKlxSY0TCLgvXNszE+x ua2L7d913Myk4bjiJRLgdQu9VT3GVvb4CXUOlZ7i/Uo0H+zJ5K/YqX8Czh/1iM6rVvBk 3mBiw9lGuxcpiK+qtnUX+SzgLio4LQKsm4Q4lfAQ+N0nRsrij5K+c+FraAnNoG647djO l/S0TpEjGYVZ6CtanGulwKf0z8nEF5ScM/AGXdlKlHK81idjRaI/R1ry6blEvBDbJlMt qqnZMFG24vmXw3shtPBlGfaukTM3stDdPaNRjKr3PjZzorFzPzdnwPhGitd8WrQ2sKhT +kBA== X-Forwarded-Encrypted: i=1; AJvYcCWYl57JyAp2TkxnuUWYxre7bLLeG/urykjk+gLWTqzevGtkcstlZBZYQ/3gv0H/5HTEGkVzR1vHODQkaklY@vger.kernel.org, AJvYcCWmtMlv8X6q2sQ35/PoI0xdNzK0mJhpBa/uj7LkDJwECp+Cdf4SDhsVil8DRHTUGE8CXMGjKHRyzYz6GsX2@vger.kernel.org X-Gm-Message-State: AOJu0YxmS/O6JWyfwkEvNeH1T5hfW6a066eg6g7MjglX47aofIVEbYd5 r3HfmP8UqjbWphY2wSZck0lWzO1i6CEHO3fNMt9Qg4hnHIaq3jO9tG2gEQ== X-Google-Smtp-Source: AGHT+IFCxyJSxPQP6RAex7Yy8ews7j05lGPKGou37IK8oImGmwL/23ibsKuS7C/gej0nrLDrDXLDyQ== X-Received: by 2002:a05:6830:4997:b0:718:c0d:6c02 with SMTP id 46e09a7af769-7181a5c4e70mr4266746a34.2.1729275628108; Fri, 18 Oct 2024 11:20:28 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:27 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 08/10] net: qrtr: Drop remote {NEW|DEL}_LOOKUP messages Date: Fri, 18 Oct 2024 13:18:26 -0500 Message-ID: <20241018181842.1368394-9-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These messages are explicitly filtered out by the in-kernel name service (ns.c). Filter them out even earlier to save some CPU cycles. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index b2f9c25ba8f8..95c9679725ee 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -560,6 +560,11 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const= void *data, size_t len) if (!size || len !=3D ALIGN(size, 4) + hdrlen) goto err; =20 + /* Don't allow remote lookups */ + if (cb->type =3D=3D QRTR_TYPE_NEW_LOOKUP || + cb->type =3D=3D QRTR_TYPE_DEL_LOOKUP) + goto err; + if ((cb->type =3D=3D QRTR_TYPE_NEW_SERVER || cb->type =3D=3D QRTR_TYPE_RESUME_TX) && size < sizeof(struct qrtr_ctrl_pkt)) --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EE2F20E034; Fri, 18 Oct 2024 18:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275634; cv=none; b=CT5z0RjB/ruyhi4QySgHnNHvqByj8Wr+P8EGgQ8uNQKkpE7waJSUS4xkYp68xEePv8uFZpkc4so007qWEZO9041XZW6pfXglaSnMyEd3FCaq9sPq4SLATPvIqHMqaQQ+YcRKne/met6m8Gd0b3/nZvUXb4ursBdgzdUVPRnKHn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275634; c=relaxed/simple; bh=aA2jSJoNyalqp8WXqjcCcmVDza8tosKbDMDvAIGniio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SEVhsIbj3bzScwR7mbaPkAs9/jCFatFlSFV07JY3XTfWl2D7I8x3YM3eO9YX7+unWXgEu1jN3I+BlifjhIiCrSxC9yUdFkgwsqP4hW8zfOwwlaHXULrwCq4EgCrhhHpN48OVcGWn4t/bfGYKWYzU3zQsSU790MVGmrjsds8Boto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eAYGNToP; arc=none smtp.client-ip=209.85.210.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eAYGNToP" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7181b86a749so475005a34.3; Fri, 18 Oct 2024 11:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275630; x=1729880430; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tPt7HWg9o/t9Kiabv7bBS/POb/GbeQprp+oLjeSGecY=; b=eAYGNToPLAjEPukGK+pjA2OkSroXQ3RktIdg+kEu6h5I/0ysuOqBe+ZGseyqBGlXB3 is6gvUQj9Zq3RINA52eilSyfn9PfUBwbe9r9uIyt4Lqe2ujCyje3dAR7mZ2fW70GqKV4 iKPOHp2FfTLxQHaWZm/3TtoPx8CkNwIvZFB0sp83/96z7oFbrCazy1dj5iOEzlneGKA/ RMgnNR0Fs2kfYsbm2PZodlpkHqxtUzPFbtjdXkEsScKpQRfY3Kb6+JDw7LWVvLN0DSuf 40sE7BWgGW6yTeSpgtAS1YIS4e1z2GH+1GrAlAGJC5QrRuapEG2oR1fG5kkVZ/wiGM67 vgBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275630; x=1729880430; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tPt7HWg9o/t9Kiabv7bBS/POb/GbeQprp+oLjeSGecY=; b=OFZK4GTe6HDNBIC1sjQCUcg3/oGchKqpyQZQtE0qLUNIK59RVjrStYZtZnmD5VUbii tM3NhZsj5g3Hy/9+clFnPcWGEHBCEfALr8DlPfaD6/O5qh1EC68umo2xIk9xIkLB+HNP sVBwHhijRPk6oUphjmzwcRIDjWXDlD1cfrzaRvCCEJVUX+sBKjo3RTAj//ANSRiDOlHg vfsWwfj24KN9ORk13UJUdTDrKGHx2HuMgv9IwWnoB7YiHKsYAWv4bWaQeNezQgChILvO x3bJD0bBiqhowN+SZg8G0JwaS/cI9+dCz9gtj0x77Bm1M0bh6rZM0R82+PZmSYdf3TiF HHgA== X-Forwarded-Encrypted: i=1; AJvYcCX9xvLbr9b+nzh0n5hgJxMq0CauoeeOlSdnT5YwsngHD4I+iiA58mJFSbCXooY2zak5qr1yWDqoFO53fACN@vger.kernel.org, AJvYcCXBbG4/2xaQkzyzsVPRHnnvokWMmaEu0343I8TuhlP7B/W0vmg0clptri4ULzf9OeyKk9P8ZBvXZmEcv6Ky@vger.kernel.org X-Gm-Message-State: AOJu0YzrLaVUy5pKgsrMhwNCAH2KKZ1gfEpX/Pabf9sq0BV07gOttO0+ /EIFJ0nqBItJrLrl4hPLTDwOhdMmGwwK0UlSk0+ftAV6OcIB47rc+O+qiA== X-Google-Smtp-Source: AGHT+IELXxVKa8uSNHsrmFkWlSULMmo+HrSU9FKGLh9XpdiQDGAyW7oTf42WeF24URvVoJpzBZQzIQ== X-Received: by 2002:a05:6830:3989:b0:717:f707:cb92 with SMTP id 46e09a7af769-7181a8c20d7mr2879917a34.28.1729275630276; Fri, 18 Oct 2024 11:20:30 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:29 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 09/10] net: qrtr: ns: support multiple endpoints Date: Fri, 18 Oct 2024 13:18:27 -0500 Message-ID: <20241018181842.1368394-10-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend the qrtr name service with the concept of an endpoint. Endpoints can be remote or local, and are represented by a unique endpoint id. This allows the qrtr name service to support multiple devices (endpoints) that might have overlapping node / port combinations. The socket used by the name service is subscribed to receive endpoint information via a mechanism similar to the SOL_QRTR QRTR_REPORT_ENDPOINT socket option. Internal data structures are then extended to track endpoint information in addition to nodes and ports. The name service directs packets to the endpoint originating the request. For NEW_SERVER and DEL_SERVER messages triggered using lookups or due to remote endpoints sending the corresponding message, qrtr name service generates a NEW_SERVER and DEL_SERVER messages to all local sockets registered to receive such notifications. The messages are made to look as if they're coming from the remote endpoint using a special extension to AF_QRTR sendmsg operation. This extension only works for the local socket that owns the QRTR_PORT_CTRL port (name service). Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 14 +++ net/qrtr/ns.c | 296 +++++++++++++++++++++++++++------------------ net/qrtr/qrtr.h | 1 + 3 files changed, 193 insertions(+), 118 deletions(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index 95c9679725ee..ea678c3c5752 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -107,6 +107,15 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *s= k) return container_of(sk, struct qrtr_sock, sk); } =20 +void qrtr_sock_set_report_endpoint(struct sock *sk) +{ + struct qrtr_sock *ipc =3D qrtr_sk(sk); + + lock_sock(sk); + assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, 1); + release_sock(sk); +} + int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id) { struct cmsghdr *cmsg; @@ -1092,6 +1101,11 @@ static int qrtr_sendmsg(struct socket *sock, struct = msghdr *msg, size_t len) =20 /* control messages already require the type as 'command' */ skb_copy_bits(skb, 0, &qrtr_type, 4); + /* + * Allow local name service to make packets appear as if + * they originated remotely + */ + endpoint_id =3D msg_endpoint_id; } =20 type =3D le32_to_cpu(qrtr_type); diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 6158e08c0252..a3118a05dcb8 100644 --- a/net/qrtr/ns.c +++ b/net/qrtr/ns.c @@ -5,6 +5,7 @@ * Copyright (c) 2020, Linaro Ltd. */ =20 +#define pr_fmt(fmt) "QRTR NS: "fmt #include #include #include @@ -16,7 +17,7 @@ #define CREATE_TRACE_POINTS #include =20 -static DEFINE_XARRAY(nodes); +static DEFINE_XARRAY(endpoints); =20 static struct { struct socket *sock; @@ -60,6 +61,7 @@ struct qrtr_server { =20 unsigned int node; unsigned int port; + u32 endpoint_id; =20 struct list_head qli; }; @@ -69,28 +71,70 @@ struct qrtr_node { struct xarray servers; }; =20 -static struct qrtr_node *node_get(unsigned int node_id) +struct qrtr_ns_endpoint { + unsigned int id; + struct xarray nodes; +}; + +static struct qrtr_node *node_lookup(u32 endpoint_id, unsigned int node_id) +{ + struct qrtr_ns_endpoint *endpoint; + + endpoint =3D xa_load(&endpoints, endpoint_id); + if (!endpoint) + return NULL; + + return xa_load(&endpoint->nodes, node_id); +} + +static struct qrtr_node *node_new(u32 endpoint_id, unsigned int node_id) { + struct qrtr_ns_endpoint *endpoint; struct qrtr_node *node; + bool new_endpoint =3D false; =20 - node =3D xa_load(&nodes, node_id); - if (node) - return node; + endpoint =3D xa_load(&endpoints, endpoint_id); + if (!endpoint) { + endpoint =3D kzalloc(sizeof(*endpoint), GFP_KERNEL); + if (!endpoint) + return NULL; + + endpoint->id =3D endpoint_id; + xa_init(&endpoint->nodes); + + if (xa_store(&endpoints, endpoint_id, endpoint, GFP_KERNEL)) { + kfree(endpoint); + return NULL; + } + + new_endpoint =3D true; + } else { + node =3D xa_load(&endpoint->nodes, node_id); + if (node) + return node; + } =20 /* If node didn't exist, allocate and insert it to the tree */ node =3D kzalloc(sizeof(*node), GFP_KERNEL); if (!node) - return NULL; + goto error; =20 node->id =3D node_id; xa_init(&node->servers); =20 - if (xa_store(&nodes, node_id, node, GFP_KERNEL)) { + if (xa_store(&endpoint->nodes, node_id, node, GFP_KERNEL)) { kfree(node); - return NULL; + goto error; } =20 return node; +error: + if (new_endpoint) { + xa_erase(&endpoints, endpoint_id); + kfree(endpoint); + } + + return NULL; } =20 static int server_match(const struct qrtr_server *srv, @@ -106,19 +150,42 @@ static int server_match(const struct qrtr_server *srv, return (srv->instance & ifilter) =3D=3D f->instance; } =20 -static int service_announce_new(struct sockaddr_qrtr *dest, - struct qrtr_server *srv) +static int qrtr_ns_sendmsg(u32 endpoint_id, struct sockaddr_qrtr *dest, + struct qrtr_ctrl_pkt *pkt) { - struct qrtr_ctrl_pkt pkt; struct msghdr msg =3D { }; struct kvec iv; + u8 control[CMSG_SPACE(sizeof(endpoint_id))]; + struct cmsghdr *cmsg; + + iv.iov_base =3D pkt; + iv.iov_len =3D sizeof(*pkt); + + msg.msg_name =3D (struct sockaddr *)dest; + msg.msg_namelen =3D sizeof(*dest); + + if (endpoint_id) { + msg.msg_control =3D control; + msg.msg_controllen =3D sizeof(control); + + cmsg =3D CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level =3D SOL_QRTR; + cmsg->cmsg_type =3D QRTR_ENDPOINT; + cmsg->cmsg_len =3D CMSG_LEN(sizeof(endpoint_id)); + memcpy(CMSG_DATA(cmsg), &endpoint_id, sizeof(endpoint_id)); + } + + return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(*pkt)); +} + +static int service_announce_new(u32 endpoint_id, struct sockaddr_qrtr *des= t, + struct qrtr_server *srv) +{ + struct qrtr_ctrl_pkt pkt; =20 trace_qrtr_ns_service_announce_new(srv->service, srv->instance, srv->node, srv->port); =20 - iv.iov_base =3D &pkt; - iv.iov_len =3D sizeof(pkt); - memset(&pkt, 0, sizeof(pkt)); pkt.cmd =3D cpu_to_le32(QRTR_TYPE_NEW_SERVER); pkt.server.service =3D cpu_to_le32(srv->service); @@ -126,26 +193,18 @@ static int service_announce_new(struct sockaddr_qrtr = *dest, pkt.server.node =3D cpu_to_le32(srv->node); pkt.server.port =3D cpu_to_le32(srv->port); =20 - msg.msg_name =3D (struct sockaddr *)dest; - msg.msg_namelen =3D sizeof(*dest); - - return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + return qrtr_ns_sendmsg(endpoint_id, dest, &pkt); } =20 -static void service_announce_del(struct sockaddr_qrtr *dest, +static void service_announce_del(u32 endpoint_id, struct sockaddr_qrtr *de= st, struct qrtr_server *srv) { struct qrtr_ctrl_pkt pkt; - struct msghdr msg =3D { }; - struct kvec iv; int ret; =20 trace_qrtr_ns_service_announce_del(srv->service, srv->instance, srv->node, srv->port); =20 - iv.iov_base =3D &pkt; - iv.iov_len =3D sizeof(pkt); - memset(&pkt, 0, sizeof(pkt)); pkt.cmd =3D cpu_to_le32(QRTR_TYPE_DEL_SERVER); pkt.server.service =3D cpu_to_le32(srv->service); @@ -153,27 +212,22 @@ static void service_announce_del(struct sockaddr_qrtr= *dest, pkt.server.node =3D cpu_to_le32(srv->node); pkt.server.port =3D cpu_to_le32(srv->port); =20 - msg.msg_name =3D (struct sockaddr *)dest; - msg.msg_namelen =3D sizeof(*dest); - - ret =3D kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + ret =3D qrtr_ns_sendmsg(endpoint_id, dest, &pkt); if (ret < 0 && ret !=3D -ENODEV) pr_err("failed to announce del service\n"); - - return; } =20 -static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *sr= v, - bool new) +static void lookup_notify(u32 endpoint_id, struct sockaddr_qrtr *to, + struct qrtr_server *srv, bool new) { struct qrtr_ctrl_pkt pkt; - struct msghdr msg =3D { }; - struct kvec iv; int ret; =20 - iv.iov_base =3D &pkt; - iv.iov_len =3D sizeof(pkt); - + /* + * Notify a local client at @to about a server change. The aux data + * will look as if it came from the endpoint that reported the event + * (remote or local) + */ memset(&pkt, 0, sizeof(pkt)); pkt.cmd =3D new ? cpu_to_le32(QRTR_TYPE_NEW_SERVER) : cpu_to_le32(QRTR_TYPE_DEL_SERVER); @@ -184,28 +238,25 @@ static void lookup_notify(struct sockaddr_qrtr *to, s= truct qrtr_server *srv, pkt.server.port =3D cpu_to_le32(srv->port); } =20 - msg.msg_name =3D (struct sockaddr *)to; - msg.msg_namelen =3D sizeof(*to); - - ret =3D kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + ret =3D qrtr_ns_sendmsg(endpoint_id, to, &pkt); if (ret < 0 && ret !=3D -ENODEV) pr_err("failed to send lookup notification\n"); } =20 -static int announce_servers(struct sockaddr_qrtr *sq) +static int announce_servers(u32 endpoint_id, struct sockaddr_qrtr *sq) { struct qrtr_server *srv; struct qrtr_node *node; unsigned long index; int ret; =20 - node =3D node_get(qrtr_ns.local_node); + node =3D node_lookup(qrtr_ns.local_node, qrtr_ns.local_node); if (!node) return 0; =20 - /* Announce the list of servers registered in this node */ + /* Announce servers registered on local endpoint to remote endpoint */ xa_for_each(&node->servers, index, srv) { - ret =3D service_announce_new(sq, srv); + ret =3D service_announce_new(endpoint_id, sq, srv); if (ret < 0) { if (ret =3D=3D -ENODEV) continue; @@ -217,7 +268,8 @@ static int announce_servers(struct sockaddr_qrtr *sq) return 0; } =20 -static struct qrtr_server *server_add(unsigned int service, +static struct qrtr_server *server_add(u32 endpoint_id, + unsigned int service, unsigned int instance, unsigned int node_id, unsigned int port) @@ -238,7 +290,7 @@ static struct qrtr_server *server_add(unsigned int serv= ice, srv->node =3D node_id; srv->port =3D port; =20 - node =3D node_get(node_id); + node =3D node_new(endpoint_id, node_id); if (!node) goto err; =20 @@ -264,7 +316,8 @@ static struct qrtr_server *server_add(unsigned int serv= ice, return NULL; } =20 -static int server_del(struct qrtr_node *node, unsigned int port, bool bcas= t) +static int server_del(u32 endpoint_id, struct qrtr_node *node, + unsigned int port, bool bcast) { struct qrtr_lookup *lookup; struct qrtr_server *srv; @@ -276,9 +329,10 @@ static int server_del(struct qrtr_node *node, unsigned= int port, bool bcast) =20 xa_erase(&node->servers, port); =20 - /* Broadcast the removal of local servers */ + /* Broadcast the removal of local servers to remote endpoints */ if (srv->node =3D=3D qrtr_ns.local_node && bcast) - service_announce_del(&qrtr_ns.bcast_sq, srv); + service_announce_del(qrtr_ns.local_node, + &qrtr_ns.bcast_sq, srv); =20 /* Announce the service's disappearance to observers */ list_for_each(li, &qrtr_ns.lookups) { @@ -288,7 +342,7 @@ static int server_del(struct qrtr_node *node, unsigned = int port, bool bcast) if (lookup->instance && lookup->instance !=3D srv->instance) continue; =20 - lookup_notify(&lookup->sq, srv, false); + lookup_notify(endpoint_id, &lookup->sq, srv, false); } =20 kfree(srv); @@ -296,23 +350,15 @@ static int server_del(struct qrtr_node *node, unsigne= d int port, bool bcast) return 0; } =20 -static int say_hello(struct sockaddr_qrtr *dest) +static int say_hello(u32 endpoint_id, struct sockaddr_qrtr *dest) { struct qrtr_ctrl_pkt pkt; - struct msghdr msg =3D { }; - struct kvec iv; int ret; =20 - iv.iov_base =3D &pkt; - iv.iov_len =3D sizeof(pkt); - memset(&pkt, 0, sizeof(pkt)); pkt.cmd =3D cpu_to_le32(QRTR_TYPE_HELLO); =20 - msg.msg_name =3D (struct sockaddr *)dest; - msg.msg_namelen =3D sizeof(*dest); - - ret =3D kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + ret =3D qrtr_ns_sendmsg(endpoint_id, dest, &pkt); if (ret < 0) pr_err("failed to send hello msg\n"); =20 @@ -320,42 +366,38 @@ static int say_hello(struct sockaddr_qrtr *dest) } =20 /* Announce the list of servers registered on the local node */ -static int ctrl_cmd_hello(struct sockaddr_qrtr *sq) +static int ctrl_cmd_hello(u32 endpoint_id, struct sockaddr_qrtr *sq) { int ret; =20 - ret =3D say_hello(sq); + /* Send Hello and New Server messages to remote endpoint */ + ret =3D say_hello(endpoint_id, sq); if (ret < 0) return ret; =20 - return announce_servers(sq); + return announce_servers(endpoint_id, sq); } =20 -static int ctrl_cmd_bye(struct sockaddr_qrtr *from) +static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from) { struct qrtr_node *local_node; struct qrtr_ctrl_pkt pkt; struct qrtr_server *srv; struct sockaddr_qrtr sq; - struct msghdr msg =3D { }; struct qrtr_node *node; unsigned long index; - struct kvec iv; int ret; =20 - iv.iov_base =3D &pkt; - iv.iov_len =3D sizeof(pkt); - - node =3D node_get(from->sq_node); + node =3D node_lookup(endpoint_id, from->sq_node); if (!node) return 0; =20 /* Advertise removal of this client to all servers of remote node */ xa_for_each(&node->servers, index, srv) - server_del(node, srv->port, true); + server_del(endpoint_id, node, srv->port, true); =20 /* Advertise the removal of this client to all local servers */ - local_node =3D node_get(qrtr_ns.local_node); + local_node =3D node_lookup(qrtr_ns.local_node, qrtr_ns.local_node); if (!local_node) return 0; =20 @@ -368,10 +410,8 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from) sq.sq_node =3D srv->node; sq.sq_port =3D srv->port; =20 - msg.msg_name =3D (struct sockaddr *)&sq; - msg.msg_namelen =3D sizeof(sq); - - ret =3D kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + /* Bye will look as if it came from endpoint_id */ + ret =3D qrtr_ns_sendmsg(endpoint_id, &sq, &pkt); if (ret < 0 && ret !=3D -ENODEV) { pr_err("failed to send bye cmd\n"); return ret; @@ -380,25 +420,20 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from) return 0; } =20 -static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, +static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int node_id, unsigned int port) { struct qrtr_node *local_node; struct qrtr_lookup *lookup; struct qrtr_ctrl_pkt pkt; - struct msghdr msg =3D { }; struct qrtr_server *srv; struct sockaddr_qrtr sq; struct qrtr_node *node; struct list_head *tmp; struct list_head *li; unsigned long index; - struct kvec iv; int ret; =20 - iv.iov_base =3D &pkt; - iv.iov_len =3D sizeof(pkt); - /* Don't accept spoofed messages */ if (from->sq_node !=3D node_id) return -EINVAL; @@ -423,12 +458,12 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *= from, * DEL_SERVER. Neighbours would've already removed the server belonging * to this port due to the DEL_CLIENT broadcast from qrtr_port_remove(). */ - node =3D node_get(node_id); + node =3D node_lookup(endpoint_id, node_id); if (node) - server_del(node, port, false); + server_del(endpoint_id, node, port, false); =20 /* Advertise the removal of this client to all local servers */ - local_node =3D node_get(qrtr_ns.local_node); + local_node =3D node_lookup(qrtr_ns.local_node, qrtr_ns.local_node); if (!local_node) return 0; =20 @@ -442,10 +477,8 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *f= rom, sq.sq_node =3D srv->node; sq.sq_port =3D srv->port; =20 - msg.msg_name =3D (struct sockaddr *)&sq; - msg.msg_namelen =3D sizeof(sq); - - ret =3D kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + /* Del Client will look as if it came from endpoint_id */ + ret =3D qrtr_ns_sendmsg(endpoint_id, &sq, &pkt); if (ret < 0 && ret !=3D -ENODEV) { pr_err("failed to send del client cmd\n"); return ret; @@ -454,7 +487,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *fr= om, return 0; } =20 -static int ctrl_cmd_new_server(struct sockaddr_qrtr *from, +static int ctrl_cmd_new_server(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int service, unsigned int instance, unsigned int node_id, unsigned int port) { @@ -469,12 +502,16 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *= from, port =3D from->sq_port; } =20 - srv =3D server_add(service, instance, node_id, port); - if (!srv) + srv =3D server_add(endpoint_id, service, instance, node_id, port); + if (!srv) { + pr_err("Failed to add server\n"); return -EINVAL; + } =20 if (srv->node =3D=3D qrtr_ns.local_node) { - ret =3D service_announce_new(&qrtr_ns.bcast_sq, srv); + /* Broadcast local server info to all peer endpoints */ + ret =3D service_announce_new(qrtr_ns.local_node, + &qrtr_ns.bcast_sq, srv); if (ret < 0) { pr_err("failed to announce new service\n"); return ret; @@ -489,13 +526,13 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *= from, if (lookup->instance && lookup->instance !=3D instance) continue; =20 - lookup_notify(&lookup->sq, srv, true); + lookup_notify(endpoint_id, &lookup->sq, srv, true); } =20 return ret; } =20 -static int ctrl_cmd_del_server(struct sockaddr_qrtr *from, +static int ctrl_cmd_del_server(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int service, unsigned int instance, unsigned int node_id, unsigned int port) { @@ -511,24 +548,22 @@ static int ctrl_cmd_del_server(struct sockaddr_qrtr *= from, if (from->sq_node =3D=3D qrtr_ns.local_node && from->sq_port !=3D port) return -EINVAL; =20 - node =3D node_get(node_id); + node =3D node_lookup(endpoint_id, node_id); if (!node) return -ENOENT; =20 - server_del(node, port, true); + server_del(endpoint_id, node, port, true); =20 return 0; } =20 -static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from, +static int ctrl_cmd_new_lookup(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int service, unsigned int instance) { struct qrtr_server_filter filter; struct qrtr_lookup *lookup; - struct qrtr_server *srv; - struct qrtr_node *node; - unsigned long node_idx; - unsigned long srv_idx; + unsigned long id; + struct qrtr_ns_endpoint *endpoint; =20 /* Accept only local observers */ if (from->sq_node !=3D qrtr_ns.local_node) @@ -547,22 +582,30 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *= from, filter.service =3D service; filter.instance =3D instance; =20 - xa_for_each(&nodes, node_idx, node) { - xa_for_each(&node->servers, srv_idx, srv) { - if (!server_match(srv, &filter)) - continue; + xa_for_each(&endpoints, id, endpoint) { + struct qrtr_node *node; + unsigned long node_idx; =20 - lookup_notify(from, srv, true); + xa_for_each(&endpoint->nodes, node_idx, node) { + unsigned long srv_idx; + struct qrtr_server *srv; + + xa_for_each(&node->servers, srv_idx, srv) { + if (!server_match(srv, &filter)) + continue; + + lookup_notify(id, from, srv, true); + } } } =20 /* Empty notification, to indicate end of listing */ - lookup_notify(from, NULL, true); + lookup_notify(0, from, NULL, true); =20 return 0; } =20 -static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from, +static void ctrl_cmd_del_lookup(u32 endpoint_id, struct sockaddr_qrtr *fro= m, unsigned int service, unsigned int instance) { struct qrtr_lookup *lookup; @@ -595,6 +638,7 @@ static void qrtr_ns_worker(struct work_struct *work) ssize_t msglen; void *recv_buf; struct kvec iv; + u8 control[32]; int ret; =20 msg.msg_name =3D (struct sockaddr *)&sq; @@ -605,8 +649,12 @@ static void qrtr_ns_worker(struct work_struct *work) return; =20 for (;;) { + u32 endpoint_id; + iv.iov_base =3D recv_buf; iv.iov_len =3D recv_buf_size; + msg.msg_control =3D control; + msg.msg_controllen =3D sizeof(control); =20 msglen =3D kernel_recvmsg(qrtr_ns.sock, &msg, &iv, 1, iv.iov_len, MSG_DONTWAIT); @@ -619,6 +667,16 @@ static void qrtr_ns_worker(struct work_struct *work) break; } =20 + /* AUX data is written direct into the control buffer */ + msg.msg_control =3D control; + msg.msg_controllen =3D sizeof(control) - msg.msg_controllen; + + ret =3D qrtr_msg_get_endpoint(&msg, &endpoint_id); + if (ret < 0) { + pr_err("error receiving endpoint id: %d\n", ret); + break; + } + if ((size_t)msglen < sizeof(pkt)) break; =20 @@ -632,25 +690,25 @@ static void qrtr_ns_worker(struct work_struct *work) ret =3D 0; switch (cmd) { case QRTR_TYPE_HELLO: - ret =3D ctrl_cmd_hello(&sq); + ret =3D ctrl_cmd_hello(endpoint_id, &sq); break; case QRTR_TYPE_BYE: - ret =3D ctrl_cmd_bye(&sq); + ret =3D ctrl_cmd_bye(endpoint_id, &sq); break; case QRTR_TYPE_DEL_CLIENT: - ret =3D ctrl_cmd_del_client(&sq, + ret =3D ctrl_cmd_del_client(endpoint_id, &sq, le32_to_cpu(pkt->client.node), le32_to_cpu(pkt->client.port)); break; case QRTR_TYPE_NEW_SERVER: - ret =3D ctrl_cmd_new_server(&sq, + ret =3D ctrl_cmd_new_server(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance), le32_to_cpu(pkt->server.node), le32_to_cpu(pkt->server.port)); break; case QRTR_TYPE_DEL_SERVER: - ret =3D ctrl_cmd_del_server(&sq, + ret =3D ctrl_cmd_del_server(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance), le32_to_cpu(pkt->server.node), @@ -661,12 +719,12 @@ static void qrtr_ns_worker(struct work_struct *work) case QRTR_TYPE_RESUME_TX: break; case QRTR_TYPE_NEW_LOOKUP: - ret =3D ctrl_cmd_new_lookup(&sq, + ret =3D ctrl_cmd_new_lookup(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance)); break; case QRTR_TYPE_DEL_LOOKUP: - ctrl_cmd_del_lookup(&sq, + ctrl_cmd_del_lookup(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance)); break; @@ -700,6 +758,8 @@ int qrtr_ns_init(void) if (ret < 0) return ret; =20 + qrtr_sock_set_report_endpoint(qrtr_ns.sock->sk); + ret =3D kernel_getsockname(qrtr_ns.sock, (struct sockaddr *)&sq); if (ret < 0) { pr_err("failed to get socket name\n"); @@ -727,7 +787,7 @@ int qrtr_ns_init(void) qrtr_ns.bcast_sq.sq_node =3D QRTR_NODE_BCAST; qrtr_ns.bcast_sq.sq_port =3D QRTR_PORT_CTRL; =20 - ret =3D say_hello(&qrtr_ns.bcast_sq); + ret =3D say_hello(qrtr_ns.local_node, &qrtr_ns.bcast_sq); if (ret < 0) goto err_wq; =20 diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h index 22fcecbf8de2..b4f50336ae75 100644 --- a/net/qrtr/qrtr.h +++ b/net/qrtr/qrtr.h @@ -35,5 +35,6 @@ int qrtr_ns_init(void); void qrtr_ns_remove(void); =20 int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id); +void qrtr_sock_set_report_endpoint(struct sock *sk); =20 #endif --=20 2.45.2 From nobody Tue Nov 26 08:43:52 2024 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5524A210180; Fri, 18 Oct 2024 18:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275635; cv=none; b=rv307dCgHpdWDm/HpL4OUJAmU7NkHTzV/6FKaVSMGtdN/5b+RPQbzlhBNoR/U7BFqOTOV015i+Vz7XWznLZ7rGC73nxrlM4EzmbgG+4s0XRThgyHaUOSl1t4bwobm/Shsp4ayD3TKN0839wMcbL6E4M9wZtWhfWqo04grbhsNHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275635; c=relaxed/simple; bh=gpysWTwbaT7QYLy965q+HAh2HOEdzqhi1zgnC19uOuE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pg9+OKi6Wij7yUdi9yFznzKTxWyunxVctuHjfzi72AbvwCqQ1/0gh/Yzah+APCoccJs/vl0IxdICHlpcNIHrzzGLfi5UPxmqIq64tnfZqJaF/HXiGArgsJqhVjvJvBDTs9IJUfNJsw269oR5RgTYlIfzK5/VOH0SOputV2JcvXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=STNi5ZJu; arc=none smtp.client-ip=209.85.161.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="STNi5ZJu" Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5eb858c4d20so1046772eaf.1; Fri, 18 Oct 2024 11:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275632; x=1729880432; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DBGm+6GLpMz9H37HwD/cw/vMAFvsf+gx6krj/k7dSxY=; b=STNi5ZJu/IeZezukLhs7WJUyjcq7ZrSMqfjJU1P91gSiiUEM4UE1PmzAPiJDWXAuRF DNwdOg9dKX6CfCJ6iBUUVWylRPrvbjkJx1V51XIWEy3B2ZMXp1krFZeCSoPlt8zeUshL NhNK2v9t9F41RnuGagz0jxC1so8ony0d8HDkjQn7BOfSBkwWC8P5fPta1D3d435hj7oQ 9ZZU7QlePYyQsg0nh6u9EB1ksE+gzSK8SAq0FacyQQg0IlCvouecsBxLFMZPEQD8UuaM r6V1xMbQfVGye2rGHU27rgN+WqkI2iPCIva+O46fzz+LjMTpzT7S/tZIRLrBYy2n/29D LY1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275632; x=1729880432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DBGm+6GLpMz9H37HwD/cw/vMAFvsf+gx6krj/k7dSxY=; b=DTGfQoEyCElJkmCACmCpvpp1cn/1wSkMd572CrM5xDX3fEKCr3VlT+56w2187Xkl2p LNLxgvHp9ie/3W2rzDeOwR+Bmx20P7NouPu3GtT5XxhOBO35f8xk0SBLaIxsdfgHAv0e pQribLo3z2Izd+upUzfNQd+DT2Ovc3JwjQ+fDNFgH5seG/g86BdcarIVp4BSq8VjZS5z AQtwDs2GDVnq17CQ/U2z3bweXKOrP6DsRHzdQ/CqBjVu4Du/wfv2j5iSLt7nPqewvdIa 4UuZmHYQt5JIlFtxgLM/5WknXmKDTbgeraGT0QLsKneoNn4RnMSf49ExKyPqY7oojggx /5Cw== X-Forwarded-Encrypted: i=1; AJvYcCVgEV5cMF4MomBBoIHKFa2muuEfOs4TQbgtGtWP+Gmv0HilhixsQVSpbGhFdddJDDVK+ObAaGW5H26ik/Iq@vger.kernel.org, AJvYcCXirWQ2yZzxjrdiGt9men50XmP7nL1eD3qHLS9miFadWG21IbEnJrsLhIBtob/ZUsC/wkfIAK1VhCaPWGNu@vger.kernel.org X-Gm-Message-State: AOJu0Yz6Ppy6k3YbMkeOmCeD4myTv25LxolrMerLk5G3MT9ZPnBzFuIk bCrHKIWQDM/FZ6JZAfHLaksqLr89ACUu1GEND5fx5srXsMCsxOC5/mDYhA== X-Google-Smtp-Source: AGHT+IEigEsZoghbHPEIF1WQgJCl7+bgGhW7Sej1ZWgUeYTU8nx+mZ9xNyziTVCDCTe4s4Kbp4Qs/Q== X-Received: by 2002:a05:6820:1846:b0:5e1:ea03:928f with SMTP id 006d021491bc7-5eb8b7b39e6mr2960787eaf.7.1729275632172; Fri, 18 Oct 2024 11:20:32 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:31 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 10/10] net: qrtr: mhi: Report endpoint id in sysfs Date: Fri, 18 Oct 2024 13:18:28 -0500 Message-ID: <20241018181842.1368394-11-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a read-only 'endpoint' sysfs entry that contains the qrtr endpoint identifier assigned to this mhi device. Can be used to direct / receive qrtr traffic only from a particular MHI device. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/mhi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c index 69f53625a049..a4696ed31fb1 100644 --- a/net/qrtr/mhi.c +++ b/net/qrtr/mhi.c @@ -72,6 +72,16 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, = struct sk_buff *skb) return rc; } =20 +static ssize_t endpoint_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct qrtr_mhi_dev *qdev =3D dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", qdev->ep.id); +} + +static DEVICE_ATTR_RO(endpoint); + static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev, const struct mhi_device_id *id) { @@ -91,6 +101,9 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_de= v, if (rc) return rc; =20 + if (device_create_file(&mhi_dev->dev, &dev_attr_endpoint) < 0) + dev_err(qdev->dev, "Failed to create endpoint attribute\n"); + /* start channels */ rc =3D mhi_prepare_for_transfer_autoqueue(mhi_dev); if (rc) { @@ -107,6 +120,7 @@ static void qcom_mhi_qrtr_remove(struct mhi_device *mhi= _dev) { struct qrtr_mhi_dev *qdev =3D dev_get_drvdata(&mhi_dev->dev); =20 + device_remove_file(&mhi_dev->dev, &dev_attr_endpoint); qrtr_endpoint_unregister(&qdev->ep); mhi_unprepare_from_transfer(mhi_dev); dev_set_drvdata(&mhi_dev->dev, NULL); --=20 2.45.2