lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri,  7 May 2021 16:57:52 +0800
From:   Yangbo Lu <yangbo.lu@....com>
To:     netdev@...r.kernel.org
Cc:     Yangbo Lu <yangbo.lu@....com>,
        "David S . Miller" <davem@...emloft.net>,
        Richard Cochran <richardcochran@...il.com>,
        Claudiu Manoil <claudiu.manoil@....com>,
        Jakub Kicinski <kuba@...nel.org>
Subject: [net-next 2/6] ptp: support virtual clock and domain via sysfs

Add support for virtual clock and domain via sysfs. Attributes
new_vclock_domain/delete_vclock_domain are to create/remove ptp
virtual clock. Attribute domain is to change domain value of the
ptp clock.

Signed-off-by: Yangbo Lu <yangbo.lu@....com>
---
 Documentation/ABI/testing/sysfs-ptp |  25 ++++++
 drivers/ptp/ptp_sysfs.c             | 122 ++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-ptp b/Documentation/ABI/testing/sysfs-ptp
index 2363ad810ddb..9c419c5554b5 100644
--- a/Documentation/ABI/testing/sysfs-ptp
+++ b/Documentation/ABI/testing/sysfs-ptp
@@ -25,6 +25,23 @@ Description:
 		MAC based ones. The string does not necessarily have
 		to be any kind of unique id.
 
+What:		/sys/class/ptp/ptpN/delete_vclock_domain
+Date:		May 2021
+Contact:	Yangbo Lu <yangbo.lu@....com>
+Description:
+		This write-only file removes PTP virtual clock for the
+		specified domain. Write the u8 domain value into this
+		file to remove the PTP virtual clock.
+
+What:		/sys/class/ptp/ptpN/domain
+Date:		May 2021
+Contact:	Yangbo Lu <yangbo.lu@....com>
+Description:
+		This file contains the domain value that the PTP clock
+		serves. Time stamps of PTP messages of this domain are
+		provided by this PTP clock. Write a new u8 value into
+		this file to change the domain.
+
 What:		/sys/class/ptp/ptpN/max_adjustment
 Date:		September 2010
 Contact:	Richard Cochran <richardcochran@...il.com>
@@ -101,6 +118,14 @@ Description:
 		the form of three integers: channel index, seconds,
 		and nanoseconds.
 
+What:		/sys/class/ptp/ptpN/new_vclock_domain
+Date:		May 2021
+Contact:	Yangbo Lu <yangbo.lu@....com>
+Description:
+		This write-only file creates PTP virtual clock for a
+		specified domain. Write the u8 domain value into this
+		file to create the PTP virtual clock.
+
 What:		/sys/class/ptp/ptpN/period
 Date:		September 2010
 Contact:	Richard Cochran <richardcochran@...il.com>
diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
index be076a91e20e..d8e7e05bd52d 100644
--- a/drivers/ptp/ptp_sysfs.c
+++ b/drivers/ptp/ptp_sysfs.c
@@ -121,6 +121,119 @@ static ssize_t period_store(struct device *dev,
 }
 static DEVICE_ATTR(period, 0220, NULL, period_store);
 
+static int check_domain_avail(struct device *dev, void *data)
+{
+	struct ptp_clock *ptp = dev_get_drvdata(dev);
+	struct ptp_clock_info *info = ptp->info;
+	u8 *domain = data;
+
+	if (info->domain == *domain)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int delete_vclock_domain(struct device *dev, void *data)
+{
+	struct ptp_clock *ptp = dev_get_drvdata(dev);
+	struct ptp_clock_info *info = ptp->info;
+	struct ptp_vclock *vclock = info_to_vclock(info);
+	u8 *domain = data;
+
+	if (!info->is_vclock)
+		return 0;
+
+	if (info->domain == *domain) {
+		ptp_vclock_unregister(vclock);
+		/* For break. Not error. */
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static ssize_t domain_show(struct device *dev,
+			   struct device_attribute *attr, char *page)
+{
+	struct ptp_clock *ptp = dev_get_drvdata(dev);
+
+	return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->domain);
+}
+
+static ssize_t domain_store(struct device *dev,
+			    struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	struct ptp_clock *ptp = dev_get_drvdata(dev);
+	struct ptp_clock_info *info = ptp->info;
+	int err = -EINVAL;
+	u8 domain;
+
+	if (kstrtou8(buf, 0, &domain))
+		goto out;
+
+	if (device_for_each_child(dev->parent, &domain, check_domain_avail)) {
+		dev_err(dev, "the domain value already in used\n");
+		goto out;
+	}
+
+	info->domain = domain;
+
+	return count;
+out:
+	return err;
+}
+static DEVICE_ATTR_RW(domain);
+
+static ssize_t new_vclock_domain_store(struct device *dev,
+				       struct device_attribute *attr,
+				       const char *buf, size_t count)
+{
+	struct ptp_clock *ptp = dev_get_drvdata(dev);
+	struct ptp_vclock *vclock;
+	int err = -EINVAL;
+	u8 domain;
+
+	if (kstrtou8(buf, 0, &domain))
+		goto out;
+
+	if (device_for_each_child(dev->parent, &domain, check_domain_avail)) {
+		dev_err(dev, "the domain value already in used\n");
+		goto out;
+	}
+
+	vclock = ptp_vclock_register(ptp, domain);
+	if (!vclock)
+		goto out;
+
+	return count;
+out:
+	return err;
+}
+static DEVICE_ATTR_WO(new_vclock_domain);
+
+static ssize_t delete_vclock_domain_store(struct device *dev,
+					  struct device_attribute *attr,
+					  const char *buf, size_t count)
+{
+	int err = -EINVAL;
+	u8 domain;
+
+	if (kstrtou8(buf, 0, &domain))
+		goto out;
+
+	if (!device_for_each_child(dev->parent, &domain,
+				   delete_vclock_domain)) {
+		dev_err(dev, "no such vclock domain in used\n");
+		goto out;
+	}
+
+	return count;
+out:
+	return err;
+}
+static DEVICE_ATTR_WO(delete_vclock_domain);
+
 static ssize_t pps_enable_store(struct device *dev,
 				struct device_attribute *attr,
 				const char *buf, size_t count)
@@ -161,6 +274,9 @@ static struct attribute *ptp_attrs[] = {
 	&dev_attr_extts_enable.attr,
 	&dev_attr_fifo.attr,
 	&dev_attr_period.attr,
+	&dev_attr_domain.attr,
+	&dev_attr_new_vclock_domain.attr,
+	&dev_attr_delete_vclock_domain.attr,
 	&dev_attr_pps_enable.attr,
 	NULL
 };
@@ -183,6 +299,12 @@ static umode_t ptp_is_attribute_visible(struct kobject *kobj,
 	} else if (attr == &dev_attr_pps_enable.attr) {
 		if (!info->pps)
 			mode = 0;
+	} else if (attr == &dev_attr_new_vclock_domain.attr) {
+		if (info->is_vclock || !info->vclock_cc)
+			mode = 0;
+	} else if (attr == &dev_attr_delete_vclock_domain.attr) {
+		if (info->is_vclock || !info->vclock_cc)
+			mode = 0;
 	}
 
 	return mode;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ