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-next>] [day] [month] [year] [list]
Message-Id: <20190325170250.2547-1-twawrzynczak@chromium.org>
Date:   Mon, 25 Mar 2019 11:02:50 -0600
From:   twawrzynczak@...omium.org
To:     unlisted-recipients:; (no To-header on input)
Cc:     Benson Leung <bleung@...omium.org>,
        Enric Balletbo i Serra <enric.balletbo@...labora.com>,
        Guenter Roeck <groeck@...omium.org>,
        linux-kernel@...r.kernel.org,
        Tim Wawrzynczak <twawrzynczak@...omium.org>
Subject: [PATCH v2] platform/chrome: mfd/cros_ec_sysfs: Add sysfs entry to retrieve EC uptime.

From: Tim Wawrzynczak <twawrzynczak@...omium.org>

The new sysfs entry 'uptime' is being made available to userspace so that
a userspace daemon can synchronize EC logs with host time.

Signed-off-by: Tim Wawrzynczak <twawrzynczak@...omium.org>
---
Enric, the use case for this is ChromeOS's userspace daemon, timberslide,
which collects the EC logs for sending bug reports, etc.  This is part of
a series of patches which is prefixing host timestamps before each EC
log line.  The daemon matches up the EC log lines' seconds-since-boot
with the time gotten from the new 'uptime' node and calculates the
host time that the log line was printed at.
---
 drivers/platform/chrome/cros_ec_sysfs.c | 34 +++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index fe0b7614ae1b..b3915d3287c5 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -107,6 +107,38 @@ static ssize_t reboot_store(struct device *dev,
 	return count;
 }
 
+static ssize_t uptime_show(struct device *dev,
+			   struct device_attribute *attr, char *buf)
+{
+	struct ec_response_uptime_info *resp;
+	struct cros_ec_command *msg;
+	int ret;
+	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
+	u32 time_since_ec_boot_ms;
+
+	msg = kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	/* Get EC uptime information */
+	msg->version = 0;
+	msg->command = EC_CMD_GET_UPTIME_INFO + ec->cmd_offset;
+	msg->insize = sizeof(*resp);
+	msg->outsize = 0;
+	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+	if (ret < 0) {
+		time_since_ec_boot_ms = 0;
+	} else {
+		resp = (struct ec_response_uptime_info *)msg->data;
+		time_since_ec_boot_ms = resp->time_since_ec_boot_ms;
+	}
+
+	ret = scnprintf(buf, PAGE_SIZE, "%u\n", time_since_ec_boot_ms);
+
+	kfree(msg);
+	return ret;
+}
+
 static ssize_t version_show(struct device *dev,
 			    struct device_attribute *attr, char *buf)
 {
@@ -314,12 +346,14 @@ static DEVICE_ATTR_RW(reboot);
 static DEVICE_ATTR_RO(version);
 static DEVICE_ATTR_RO(flashinfo);
 static DEVICE_ATTR_RW(kb_wake_angle);
+static DEVICE_ATTR_RO(uptime);
 
 static struct attribute *__ec_attrs[] = {
 	&dev_attr_kb_wake_angle.attr,
 	&dev_attr_reboot.attr,
 	&dev_attr_version.attr,
 	&dev_attr_flashinfo.attr,
+	&dev_attr_uptime.attr,
 	NULL,
 };
 
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ