From nobody Sun Feb 8 11:06:44 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011057.outbound.protection.outlook.com [52.101.62.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9F412DC792; Fri, 14 Nov 2025 18:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146019; cv=fail; b=u91VVidVStAhtOQVyWhUdRS/JHhQqwu8K6WqtYdWFQ8hOBSv4zUlVRGSDjVFgyW3CKfU+EnRaAyfAl7XvU4ikpNQ15zTJpgryUqHQ1n5fCL3uHAyLmO2l+OqMediX062ERqaC2a1o9eAcLNRRXfIxBNJujKRm5QV38HJl+MaJAE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146019; c=relaxed/simple; bh=P8eOpKjPN8VVAs7wU4wur9jUUBY+In4gy9jWEIHuuBg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e/a8d72n6R1Nj+3zu/+l/z/FQxkgtmtd7oVScE2bdLdp2xPJnRsSoVMWlYOKKnxwHGf2NsyhzcEwDNI9K8Y/N/KwLpl/pMznA77npfRYdsOgYewSnn9mkwap9fALA+T3+2HORbW1M5p3GmM7jII+DDVgKZFSl9Tkpa4VOCV+4dU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=A9Nc7aME; arc=fail smtp.client-ip=52.101.62.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="A9Nc7aME" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bwW5hNqihngJUvjx0rwmVhMDDhs1x4Hzrl2e6kl3pkBCX+Fp0Mx0QRwkr5/K81M0TG55oF6dVU0eBBT/aZRVJm1/ukKqbK4mVxRESxgcUp2CgEpznRJfCZIe5P/JyIZb9QmECzClmtmCrEKYGVt5uIKlZ00GCYLlR5TOqgKhHHXLqUEq0Re/GFuECp2u1OZC6PFP15R/HC85OGw1Ofraq00Gd2h0HZAZmYGfcZ8KsLZ7/vj3jqzrVT0vl88kPbWucXGRy7vidvgKlIvMgN6PG3d0cvn1uYXzv3yhearchC7LRYpvNtRXW2hjsS5RqoKtLw2KBIO+8ep+jDnu+L2y3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UW6HVILFRpTkwz+uNQDlHYb7DYqFMai3fdS4KNDdSvc=; b=R7xOX+Nzy3rJ9/QhN95VfZDfXNbAeE8KggdJhtMNX19FrYjGXg41rABcFshtVomGIpJ8D75x0pMngt9c+Cy7o4jUcqlQ/ZQbsAYnzda8qzFv+kZ/YOunUbrUDlwAGdOeRW7kAlWGt+vnNCOhhac+M6m28Tr7/M1G+SUkK7pgOfegFLB3CX4KP8XtAJywJnfTodh+q0uOzHWVf2PVXDOoiCMKdnS5DJfEPCEard/ZdqtATJxvy7GpqdncGRsVa2mM23IItM0k3ry2L1Lcbc6mItxUqWDH4CtSUkd59GBqLkpXfcdbRrjAdn9QdiVdHVfzapshDWNeq5sM2pHO4KPZFw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UW6HVILFRpTkwz+uNQDlHYb7DYqFMai3fdS4KNDdSvc=; b=A9Nc7aMEFl/8FP9+P5A4D/0Vu38UGycu0FrmIsiEHcmYZgtVGr21SjjZfoN8C+jz9LE4Hib032GJXh3UnzQP73RIOOIeu1O9/sFw9nC1nZ2MN6AnmSP5FeW4RSrypwPVlah1HoWjcnxK1YTIoiCdE5GzmWt+X7NQk2BEaO45Iog= Received: from BY5PR16CA0026.namprd16.prod.outlook.com (2603:10b6:a03:1a0::39) by DM4PR12MB6374.namprd12.prod.outlook.com (2603:10b6:8:a3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.18; Fri, 14 Nov 2025 18:46:50 +0000 Received: from SJ1PEPF00001CE2.namprd05.prod.outlook.com (2603:10b6:a03:1a0::4) by BY5PR16CA0026.outlook.office365.com (2603:10b6:a03:1a0::39) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9320.17 via Frontend Transport; Fri, 14 Nov 2025 18:46:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by SJ1PEPF00001CE2.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.13 via Frontend Transport; Fri, 14 Nov 2025 18:46:49 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.17; Fri, 14 Nov 2025 10:46:49 -0800 Received: from satlexmb07.amd.com (10.181.42.216) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 14 Nov 2025 12:46:49 -0600 Received: from xsjtanmays50.xilinx.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Fri, 14 Nov 2025 10:46:48 -0800 From: Tanmay Shah To: , , , , , CC: , , , , Xiang Xiao , Tanmay Shah Subject: [RFC PATCH 1/2] rpmsg: virtio_rpmsg_bus: allow the different vring size for send/recv Date: Fri, 14 Nov 2025 10:46:39 -0800 Message-ID: <20251114184640.3020427-2-tanmay.shah@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251114184640.3020427-1-tanmay.shah@amd.com> References: <20251114184640.3020427-1-tanmay.shah@amd.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 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE2:EE_|DM4PR12MB6374:EE_ X-MS-Office365-Filtering-Correlation-Id: db94d41b-df22-4c21-28a2-08de23ae2bd4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?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duzcwMjXWfH6ND2l3xkiV?= =?us-ascii?Q?aFuJBU0nBNKA8/qk76yxGNmvLmHXcYSAHPUfy5Tu+G2yHgGHRNjIShBskgej?= =?us-ascii?Q?6NLcjhypnv8N0Q/l2kh1bgbCBTNDcq7Zk17Hl/5OTFVtKn76YRSWJkK7/zQi?= =?us-ascii?Q?KtdqtQgrbPpcETo3UjLcmVkzsxt2UfOiwAPn8fp/CTIVGlKX3jT/A8HAPG/c?= =?us-ascii?Q?JX9/+WNL0R8sFFDvAgHVqCaeCmXpmgk8yGbAKkOLA+d9Mo8E2yWpYR8HAn/p?= =?us-ascii?Q?HAB+mi39vWfHAJkxzxKWBxlq9i5h8POLEe8IuybuJblsdGt9jPvbeXdKY3On?= =?us-ascii?Q?7igxkLD4op7ea89I7TebMlz8wkuJVocU3zGhRcBDWf10cO0UP+8Xpqskw8M6?= =?us-ascii?Q?7zal4QKB5/suqBuBeKv9OFUqPx11Xp3TYdDGsZ6nkK8CvIQc+qvtq3+rMg93?= =?us-ascii?Q?vQxKBlCjAqqdW36dGA56jXyLw759XCAkRRpzTvQZoJwtCHZh2D/GnrVLN0L0?= =?us-ascii?Q?lr4LrlIjkRTftBmJJMsAJzsxZlxwfgVxMo13F7C03cAOHzLc19CBItimOC6v?= =?us-ascii?Q?hbswSHj9r1UyVHvQ+hsq6R3hXffQ0Oj3JBMXogG76qjuSmRhrPyFUctZ7AHw?= =?us-ascii?Q?8Q1C6au/HG1j64D++35q6yX69vkqR9Y+JHQEBd7jbwuk2FG9Qv4SgHTMm/vY?= =?us-ascii?Q?XxPgW6qzY0Mq1a6boWY=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2025 18:46:49.8455 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db94d41b-df22-4c21-28a2-08de23ae2bd4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6374 Content-Type: text/plain; charset="utf-8" From: Xiang Xiao it's useful if the communication throughput is different from each side Signed-off-by: Xiang Xiao Signed-off-by: Tanmay Shah --- drivers/rpmsg/virtio_rpmsg_bus.c | 47 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_= bus.c index 484890b4a6a7..cc26dfcc3e29 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -37,8 +37,9 @@ * @svq: tx virtqueue * @rbufs: kernel address of rx buffers * @sbufs: kernel address of tx buffers - * @num_bufs: total number of buffers for rx and tx - * @buf_size: size of one rx or tx buffer + * @num_rbufs: total number of buffers for rx + * @num_sbufs: total number of buffers for tx + * @buf_size: size of one rx or tx buffer * @last_sbuf: index of last tx buffer used * @bufs_dma: dma base addr of the buffers * @tx_lock: protects svq, sbufs and sleepers, to allow concurrent senders. @@ -57,7 +58,8 @@ struct virtproc_info { struct virtio_device *vdev; struct virtqueue *rvq, *svq; void *rbufs, *sbufs; - unsigned int num_bufs; + unsigned int num_rbufs; + unsigned int num_sbufs; unsigned int buf_size; int last_sbuf; dma_addr_t bufs_dma; @@ -112,7 +114,7 @@ struct virtio_rpmsg_channel { /* * We're allocating buffers of 512 bytes each for communications. The * number of buffers will be computed from the number of buffers supported - * by the vring, upto a maximum of 512 buffers (256 in each direction). + * by the vring, up to a maximum of 256 in each direction. * * Each buffer will have 16 bytes for the msg header and 496 bytes for * the payload. @@ -127,7 +129,7 @@ struct virtio_rpmsg_channel { * can change this without changing anything in the firmware of the remote * processor. */ -#define MAX_RPMSG_NUM_BUFS (512) +#define MAX_RPMSG_NUM_BUFS (256) #define MAX_RPMSG_BUF_SIZE (512) =20 /* @@ -439,11 +441,8 @@ static void *get_a_tx_buf(struct virtproc_info *vrp) /* support multiple concurrent senders */ mutex_lock(&vrp->tx_lock); =20 - /* - * either pick the next unused tx buffer - * (half of our buffers are used for sending messages) - */ - if (vrp->last_sbuf < vrp->num_bufs / 2) + /* either pick the next unused tx buffer */ + if (vrp->last_sbuf < vrp->num_sbufs) ret =3D vrp->sbufs + vrp->buf_size * vrp->last_sbuf++; /* or recycle a used one */ else @@ -878,19 +877,20 @@ static int rpmsg_probe(struct virtio_device *vdev) vrp->rvq =3D vqs[0]; vrp->svq =3D vqs[1]; =20 - /* we expect symmetric tx/rx vrings */ - WARN_ON(virtqueue_get_vring_size(vrp->rvq) !=3D - virtqueue_get_vring_size(vrp->svq)); - /* we need less buffers if vrings are small */ - if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS / 2) - vrp->num_bufs =3D virtqueue_get_vring_size(vrp->rvq) * 2; + if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS) + vrp->num_rbufs =3D virtqueue_get_vring_size(vrp->rvq); + else + vrp->num_rbufs =3D MAX_RPMSG_NUM_BUFS; + + if (virtqueue_get_vring_size(vrp->svq) < MAX_RPMSG_NUM_BUFS) + vrp->num_sbufs =3D virtqueue_get_vring_size(vrp->svq); else - vrp->num_bufs =3D MAX_RPMSG_NUM_BUFS; + vrp->num_sbufs =3D MAX_RPMSG_NUM_BUFS; =20 vrp->buf_size =3D MAX_RPMSG_BUF_SIZE; =20 - total_buf_space =3D vrp->num_bufs * vrp->buf_size; + total_buf_space =3D (vrp->num_rbufs + vrp->num_sbufs) * vrp->buf_size; =20 /* allocate coherent memory for the buffers */ bufs_va =3D dma_alloc_coherent(vdev->dev.parent, @@ -904,14 +904,14 @@ static int rpmsg_probe(struct virtio_device *vdev) dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n", bufs_va, &vrp->bufs_dma); =20 - /* half of the buffers is dedicated for RX */ + /* first part of the buffers is dedicated for RX */ vrp->rbufs =3D bufs_va; =20 - /* and half is dedicated for TX */ - vrp->sbufs =3D bufs_va + total_buf_space / 2; + /* and second part is dedicated for TX */ + vrp->sbufs =3D bufs_va + vrp->num_rbufs * vrp->buf_size; =20 /* set up the receive buffers */ - for (i =3D 0; i < vrp->num_bufs / 2; i++) { + for (i =3D 0; i < vrp->num_rbufs; i++) { struct scatterlist sg; void *cpu_addr =3D vrp->rbufs + i * vrp->buf_size; =20 @@ -1001,7 +1001,8 @@ static int rpmsg_remove_device(struct device *dev, vo= id *data) static void rpmsg_remove(struct virtio_device *vdev) { struct virtproc_info *vrp =3D vdev->priv; - size_t total_buf_space =3D vrp->num_bufs * vrp->buf_size; + unsigned int num_bufs =3D vrp->num_rbufs + vrp->num_sbufs; + size_t total_buf_space =3D num_bufs * vrp->buf_size; int ret; =20 virtio_reset_device(vdev); --=20 2.34.1 From nobody Sun Feb 8 11:06:44 2026 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011064.outbound.protection.outlook.com [40.107.208.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A9F72DC34E; Fri, 14 Nov 2025 18:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146020; cv=fail; b=Lfs/b1GlJoCbw9yeX61JGrzjYnNN6rMSxhIGsGJXvj9MDvFZZs76vFehzbgP3/RFmhO3AiHd7+voDyh0RRzM+zrwgbjPC6Cx3i0E5OemqDtKmERiYk3LC5Nx5t1r8zpIlMwlm5vGl+S6VJkOsDmT/RPjYAS3pd5xPcLCdkOHZjU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146020; c=relaxed/simple; bh=Bu+N3ypH2MFZM+aBdZkPzE4HKuiKtz9JnUSGOu1WubM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=flzrWwCmb1wghqf3mhsfyesDbYKzn9owpTvi1PdOTkRYpUI1HOO3FLbAghKRxW///KEFVSTtk45gAkoPe3jTgkN0Eaa5o5O61tu/e0DJSOMZr9pZiNf4SaDZPq6ewFrLweawQIfzFamnQES6BOsdy8LLDxaoQnmFVTzABAYLGto= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=s8uVTad3; arc=fail smtp.client-ip=40.107.208.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="s8uVTad3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DFXDV3MwyT2F+EeoPd0GEcKv2ZH41uGXmTOgHXXYpDQz/Ib+c9DTZIBwJ5X4bnKHbuelhFL7Bxk/XrJbrjT6PvS10afdbdtppc1htB+N5N6eHvC8+a5tmMBBEm3uoSHzy3/tzOML3qQGK5iSVApcCqGe5ApHY5BWR+QB09mfPws7e3/Y9UGYw3RlhYk0OIL+bGpIOKrxhsmCwmKsEsW0iD6nUlT+zbF3FD726rVcuL1ZIe3byGqDWZqQAghKIediwdm7MMTBJ5vqy5mJkW9DpWxm1jHgakZf9oeh1JOhrJrnRStyatCUFTd9+1W12Debej8pj/EzbMou2+IvyezrWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I8rue0QF9O6k8/JwqWkDFpD7uAhuk3AbB3nthXrG0W8=; b=oUvtLHqo3zD8MeYAFaKuTVkWlSy4CLH8FZUCFLGFsaodHBREK1jLZJnfAA3R73VTU9I+12i4Xe1ogAGgeJ3f7QYFX7zMSmxYxWdDw03vn5e8Sm8uuhFcC+a4epCQG4UFrA1VeCC4dJT8lkqZaH2DN+usSQ1ktoqVVZDH2N7b65bjJ84jYaSPBUcWIjzjN/QloP6ZmMKG0i0IdUxIGVGCxBuGYpMEqhy2pyGDjEiMrSfqUAt2MLSYtbE1yw+I/KTKzjFVbEIO45fI73a2GMRk7dI6ZxF1Pb8wiMvAyMgQ1eAJ8+dXaLUWLm/jVt/WBZzmrfQVszxdrTFp2f6uMifuTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I8rue0QF9O6k8/JwqWkDFpD7uAhuk3AbB3nthXrG0W8=; b=s8uVTad3u9sfU+TWd3RDL2a6u6GzexhaLFgJQJ84w7FgqKRH7zR2+e13pg5i53CrRI6KPnzbo169EPYia3EcjL4MvZkhPb/FNmNcRxtbdE5Ci1XX8s/NZXHJbaKqksahh7r+UIVCr0ICtGTvrD0WArILeYlsoicm8vHtAjmm0pc= Received: from BY5PR16CA0032.namprd16.prod.outlook.com (2603:10b6:a03:1a0::45) by BN7PPF7F4CD71A4.namprd12.prod.outlook.com (2603:10b6:40f:fc02::6d6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.17; Fri, 14 Nov 2025 18:46:53 +0000 Received: from SJ1PEPF00001CE2.namprd05.prod.outlook.com (2603:10b6:a03:1a0:cafe::81) by BY5PR16CA0032.outlook.office365.com (2603:10b6:a03:1a0::45) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9320.18 via Frontend Transport; Fri, 14 Nov 2025 18:46:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by SJ1PEPF00001CE2.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.13 via Frontend Transport; Fri, 14 Nov 2025 18:46:50 +0000 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Fri, 14 Nov 2025 10:46:50 -0800 Received: from xsjtanmays50.xilinx.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Fri, 14 Nov 2025 10:46:49 -0800 From: Tanmay Shah To: , , , , , CC: , , , , Xiang Xiao , Tanmay Shah Subject: [RFC PATCH 2/2] rpmsg: virtio_rpmsg_bus: get buffer size from config space Date: Fri, 14 Nov 2025 10:46:40 -0800 Message-ID: <20251114184640.3020427-3-tanmay.shah@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251114184640.3020427-1-tanmay.shah@amd.com> References: <20251114184640.3020427-1-tanmay.shah@amd.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 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE2:EE_|BN7PPF7F4CD71A4:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e0caa43-305b-4e5e-a9cb-08de23ae2c59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?PHWnUTvW465Tkl++uI+/iaZBazFMAbpOGlC/apsd3wVGkBc/hJWH8m8KJ7Gp?= =?us-ascii?Q?KMypURLMNMhkuLExW66eQBs1XhxcFi8RK46DtyfCPcG+MN9DNdw81qHdH/oW?= =?us-ascii?Q?lgh6P/YEwrfDZrJKo4/DO4V+i8PiIoH2seYp42Od/N7PPJUESyX95ANkpsCt?= =?us-ascii?Q?i6iQptG+tQ3zxfJjwXlS+PHfxJxfIvLeXlsB8yBTyfVylqWOhnMkJyMXDnDf?= =?us-ascii?Q?2Hfqq6vprcuRr08nDIki8TRHCPlMmO2db7iluFr7u03y5tn4Fp0jQ97Kz6si?= =?us-ascii?Q?+AmYF9YS8wsAFK6XYOnO0on1nzhXjFX5agYhoB089+I+LN3L/IqhWnrkTN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cZvOq1NMVjbSflQ+YEY6v9GUiNxP94Su8qhSrF0xj?= =?us-ascii?Q?OBRCQJbMrVIO27a4YYaIPHpdm8GGBcONP9SyTsvXiui8G7kesUPkw5LkUbH6?= =?us-ascii?Q?8hmbA/W4MAhRWVm4O/pjlcoz5iESnJKwrZWxvOUBpWxigXi9ATv65Tptllif?= =?us-ascii?Q?rWGcXSSXYlWHF6fhn2pkLeBfxHC5xcfkg1hFLw2guw6KiAJOlZdBtxYFizPv?= =?us-ascii?Q?mgh6ZfO77ZHpTMrf6/m3F6QpDzuwMRxmfI7cLJF4FPbvtbi+VjFoSugNdUpZ?= =?us-ascii?Q?SMh3dkXFeTeXa79rUa3hCuHPvZ2IEo6wcz7SEDVXBRpoYhKQQ8ieJSkxhbU7?= =?us-ascii?Q?z+k/+U3NHAcezDKPV2k=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2025 18:46:50.7203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e0caa43-305b-4e5e-a9cb-08de23ae2c59 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PPF7F4CD71A4 Content-Type: text/plain; charset="utf-8" From: Xiang Xiao 512 bytes isn't always suitable for all case, let firmware maker decide the best value from resource table. enable by VIRTIO_RPMSG_F_BUFSZ feature bit. Signed-off-by: Xiang Xiao Signed-off-by: Tanmay Shah --- drivers/rpmsg/virtio_rpmsg_bus.c | 68 +++++++++++++++++++++++--------- include/linux/virtio_rpmsg.h | 24 +++++++++++ 2 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 include/linux/virtio_rpmsg.h diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_= bus.c index cc26dfcc3e29..03dd5535880a 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include =20 @@ -39,7 +40,8 @@ * @sbufs: kernel address of tx buffers * @num_rbufs: total number of buffers for rx * @num_sbufs: total number of buffers for tx - * @buf_size: size of one rx or tx buffer + * @rbuf_size: size of one rx buffer + * @sbuf_size: size of one tx buffer * @last_sbuf: index of last tx buffer used * @bufs_dma: dma base addr of the buffers * @tx_lock: protects svq, sbufs and sleepers, to allow concurrent senders. @@ -60,7 +62,8 @@ struct virtproc_info { void *rbufs, *sbufs; unsigned int num_rbufs; unsigned int num_sbufs; - unsigned int buf_size; + unsigned int rbuf_size; + unsigned int sbuf_size; int last_sbuf; dma_addr_t bufs_dma; struct mutex tx_lock; @@ -70,9 +73,6 @@ struct virtproc_info { atomic_t sleepers; }; =20 -/* The feature bitmap for virtio rpmsg */ -#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ - /** * struct rpmsg_hdr - common header for all rpmsg messages * @src: source address @@ -130,7 +130,7 @@ struct virtio_rpmsg_channel { * processor. */ #define MAX_RPMSG_NUM_BUFS (256) -#define MAX_RPMSG_BUF_SIZE (512) +#define DEFAULT_RPMSG_BUF_SIZE (512) =20 /* * Local addresses are dynamically allocated on-demand. @@ -443,7 +443,7 @@ static void *get_a_tx_buf(struct virtproc_info *vrp) =20 /* either pick the next unused tx buffer */ if (vrp->last_sbuf < vrp->num_sbufs) - ret =3D vrp->sbufs + vrp->buf_size * vrp->last_sbuf++; + ret =3D vrp->sbufs + vrp->sbuf_size * vrp->last_sbuf++; /* or recycle a used one */ else ret =3D virtqueue_get_buf(vrp->svq, &len); @@ -569,7 +569,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_devic= e *rpdev, * messaging), or to improve the buffer allocator, to support * variable-length buffer sizes. */ - if (len > vrp->buf_size - sizeof(struct rpmsg_hdr)) { + if (len > vrp->sbuf_size - sizeof(struct rpmsg_hdr)) { dev_err(dev, "message is too big (%d)\n", len); return -EMSGSIZE; } @@ -680,7 +680,7 @@ static ssize_t virtio_rpmsg_get_mtu(struct rpmsg_endpoi= nt *ept) struct rpmsg_device *rpdev =3D ept->rpdev; struct virtio_rpmsg_channel *vch =3D to_virtio_rpmsg_channel(rpdev); =20 - return vch->vrp->buf_size - sizeof(struct rpmsg_hdr); + return vch->vrp->sbuf_size - sizeof(struct rpmsg_hdr); } =20 static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, @@ -706,7 +706,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp,= struct device *dev, * We currently use fixed-sized buffers, so trivially sanitize * the reported payload length. */ - if (len > vrp->buf_size || + if (len > vrp->rbuf_size || msg_len > (len - sizeof(struct rpmsg_hdr))) { dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg_len); return -EINVAL; @@ -739,7 +739,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp,= struct device *dev, dev_warn_ratelimited(dev, "msg received with no recipient\n"); =20 /* publish the real size of the buffer */ - rpmsg_sg_init(&sg, msg, vrp->buf_size); + rpmsg_sg_init(&sg, msg, vrp->rbuf_size); =20 /* add the buffer back to the remote processor's virtqueue */ err =3D virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL); @@ -888,9 +888,39 @@ static int rpmsg_probe(struct virtio_device *vdev) else vrp->num_sbufs =3D MAX_RPMSG_NUM_BUFS; =20 - vrp->buf_size =3D MAX_RPMSG_BUF_SIZE; + /* + * If VIRTIO_RPMSG_F_BUFSZ feature is supported, then configure buf + * size from virtio device config space from the resource table. + * If the feature is not supported, then assign default buf size. + */ + if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_BUFSZ)) { + /* note: virtio_rpmsg_config is defined from remote view */ + virtio_cread(vdev, struct virtio_rpmsg_config, + txbuf_size, &vrp->rbuf_size); + virtio_cread(vdev, struct virtio_rpmsg_config, + rxbuf_size, &vrp->sbuf_size); + + /* The buffers must hold rpmsg header atleast */ + if (vrp->rbuf_size < sizeof(struct rpmsg_hdr) || + vrp->sbuf_size < sizeof(struct rpmsg_hdr)) { + dev_err(&vdev->dev, + "vdev config: rx buf sz =3D %d, tx buf sz =3D %d\n", + vrp->rbuf_size, vrp->sbuf_size); + err =3D -EINVAL; + goto vqs_del; + } + + dev_dbg(&vdev->dev, + "vdev config: rx buf sz =3D 0x%x, tx buf sz =3D 0x%x\n", + vrp->rbuf_size, vrp->sbuf_size); + } else { + vrp->rbuf_size =3D DEFAULT_RPMSG_BUF_SIZE; + vrp->sbuf_size =3D DEFAULT_RPMSG_BUF_SIZE; + } =20 - total_buf_space =3D (vrp->num_rbufs + vrp->num_sbufs) * vrp->buf_size; + total_buf_space =3D (vrp->num_rbufs * vrp->rbuf_size) + + (vrp->num_sbufs * vrp->sbuf_size); + total_buf_space =3D ALIGN(total_buf_space, PAGE_SIZE); =20 /* allocate coherent memory for the buffers */ bufs_va =3D dma_alloc_coherent(vdev->dev.parent, @@ -908,14 +938,14 @@ static int rpmsg_probe(struct virtio_device *vdev) vrp->rbufs =3D bufs_va; =20 /* and second part is dedicated for TX */ - vrp->sbufs =3D bufs_va + vrp->num_rbufs * vrp->buf_size; + vrp->sbufs =3D bufs_va + (vrp->num_rbufs * vrp->rbuf_size); =20 /* set up the receive buffers */ for (i =3D 0; i < vrp->num_rbufs; i++) { struct scatterlist sg; - void *cpu_addr =3D vrp->rbufs + i * vrp->buf_size; + void *cpu_addr =3D vrp->rbufs + i * vrp->rbuf_size; =20 - rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size); + rpmsg_sg_init(&sg, cpu_addr, vrp->rbuf_size); =20 err =3D virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr, GFP_KERNEL); @@ -1001,8 +1031,8 @@ static int rpmsg_remove_device(struct device *dev, vo= id *data) static void rpmsg_remove(struct virtio_device *vdev) { struct virtproc_info *vrp =3D vdev->priv; - unsigned int num_bufs =3D vrp->num_rbufs + vrp->num_sbufs; - size_t total_buf_space =3D num_bufs * vrp->buf_size; + size_t total_buf_space =3D (vrp->num_rbufs * vrp->rbuf_size) + + (vrp->num_sbufs * vrp->sbuf_size); int ret; =20 virtio_reset_device(vdev); @@ -1015,6 +1045,7 @@ static void rpmsg_remove(struct virtio_device *vdev) =20 vdev->config->del_vqs(vrp->vdev); =20 + total_buf_space =3D ALIGN(total_buf_space, PAGE_SIZE); dma_free_coherent(vdev->dev.parent, total_buf_space, vrp->rbufs, vrp->bufs_dma); =20 @@ -1028,6 +1059,7 @@ static struct virtio_device_id id_table[] =3D { =20 static unsigned int features[] =3D { VIRTIO_RPMSG_F_NS, + VIRTIO_RPMSG_F_BUFSZ, }; =20 static struct virtio_driver virtio_ipc_driver =3D { diff --git a/include/linux/virtio_rpmsg.h b/include/linux/virtio_rpmsg.h new file mode 100644 index 000000000000..6406bc505383 --- /dev/null +++ b/include/linux/virtio_rpmsg.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (C) Pinecone Inc. 2019 + * Copyright (C) Xiang Xiao + */ + +#ifndef _LINUX_VIRTIO_RPMSG_H +#define _LINUX_VIRTIO_RPMSG_H + +#include + +/* The feature bitmap for virtio rpmsg */ +#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP get buffer size from config space */ + +struct virtio_rpmsg_config { + /* The tx/rx individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */ + __u32 txbuf_size; + __u32 rxbuf_size; + __u32 reserved[14]; /* Reserve for the future use */ + /* Put the customize config here */ +} __attribute__((packed)); + +#endif /* _LINUX_VIRTIO_RPMSG_H */ --=20 2.34.1