Re: [RFC PATCH] pps: Increase PPS_MAX_SOURCES value.

From: Rodolfo Giometti
Date: Wed Jun 21 2023 - 11:32:28 EST


On 20/06/23 22:42, Charlie Johnston wrote:
I've resubmitted the patch with just PPS_MAX_SOURCES = MINORMASK. The system which hits the limit and causes the problem is currently available for testing.

Is there anything you'd like me to try running? Or just confirm the limit change works?

Sorry for the delay (i was very busy in these days)! Please, test the attached two patches.

Ciao,

Rodolfo

--
GNU/Linux Solutions e-mail: giometti@xxxxxxxxxxxx
Linux Device Driver giometti@xxxxxxxx
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
From 029bb28772b4751cd07beb5f366066e9333ea502 Mon Sep 17 00:00:00 2001
From: Charlie Johnston <charlie.johnston@xxxxxx>
Date: Mon, 12 Jun 2023 14:08:28 -0500
Subject: [PATCH 1/2] include/uapi pps.h: increase PPS_MAX_SOURCES value

For consistency with what others use for minors, this change sets
PPS_MAX_SOURCES to MINORMASK.

The PPS_MAX_SOURCES value is currently set to 16. In some cases this
was not sufficient for a system. For example, a system with multiple
(4+) PCIe cards each with 4 PTP-capable ethernet interfaces could run
out of the available PPS major:minors if each interface registers a
PPS source.

Signed-off-by: Charlie Johnston <charlie.johnston@xxxxxx>
Acked-by: Rodolfo Giometti <giometti@xxxxxxxxxxxx>
---
include/uapi/linux/pps.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
index 009ebcd8ced5..90f2e86020ba 100644
--- a/include/uapi/linux/pps.h
+++ b/include/uapi/linux/pps.h
@@ -26,7 +26,7 @@
#include <linux/types.h>

#define PPS_VERSION "5.3.6"
-#define PPS_MAX_SOURCES 16 /* should be enough... */
+#define PPS_MAX_SOURCES MINORMASK

/* Implementation note: the logical states ``assert'' and ``clear''
* are implemented in terms of the chip register, i.e. ``assert''
--
2.34.1

From 347f4b3bcfcf95039b53ca0f66586f547e9a9229 Mon Sep 17 00:00:00 2001
From: Rodolfo Giometti <giometti@xxxxxxxxxxxx>
Date: Wed, 21 Jun 2023 16:42:38 +0200
Subject: [PATCH 2/2] include/uapi pps.h: drop not needed PPS_MAX_SOURCES
define

Userspace PPS clients should not known about how many PPS sources can
be defined within the system (nor the rfc2783 say so), so we can
safely drop this define since is not used anymore in the kernel too.

Signed-off-by: Rodolfo Giometti <giometti@xxxxxxxxxxxx>
---
drivers/pps/pps.c | 6 +++---
include/uapi/linux/pps.h | 1 -
2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 5d19baae6a38..1a6131608036 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -354,7 +354,7 @@ int pps_register_cdev(struct pps_device *pps)
* Get new ID for the new PPS source. After idr_alloc() calling
* the new source will be freely available into the kernel.
*/
- err = idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL);
+ err = idr_alloc(&pps_idr, pps, 0, MINORMASK, GFP_KERNEL);
if (err < 0) {
if (err == -ENOSPC) {
pr_err("%s: too many PPS sources in the system\n",
@@ -449,7 +449,7 @@ EXPORT_SYMBOL(pps_lookup_dev);
static void __exit pps_exit(void)
{
class_destroy(pps_class);
- unregister_chrdev_region(pps_devt, PPS_MAX_SOURCES);
+ unregister_chrdev_region(pps_devt, MINORMASK);
}

static int __init pps_init(void)
@@ -463,7 +463,7 @@ static int __init pps_init(void)
}
pps_class->dev_groups = pps_groups;

- err = alloc_chrdev_region(&pps_devt, 0, PPS_MAX_SOURCES, "pps");
+ err = alloc_chrdev_region(&pps_devt, 0, MINORMASK, "pps");
if (err < 0) {
pr_err("failed to allocate char device region\n");
goto remove_class;
diff --git a/include/uapi/linux/pps.h b/include/uapi/linux/pps.h
index 90f2e86020ba..8a4096f18af1 100644
--- a/include/uapi/linux/pps.h
+++ b/include/uapi/linux/pps.h
@@ -26,7 +26,6 @@
#include <linux/types.h>

#define PPS_VERSION "5.3.6"
-#define PPS_MAX_SOURCES MINORMASK

/* Implementation note: the logical states ``assert'' and ``clear''
* are implemented in terms of the chip register, i.e. ``assert''
--
2.34.1