Skip to contentSkip to conversation

tpm: adapt sysfs cancel path for new TPM driver

PATCH In review Stefan Berger 2 participants 2 messages Mar 21, 2016 – Mar 28, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tpm: adapt sysfs cancel path for new TPM driver

This patch addresses BZ 1281413.

Adapt the sysfs TPM command cancel path for the TPM driver that does not use a miscdevice anymore since Linux 4.0. Support old and new paths.

---
 hw/tpm/tpm_passthrough.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
hw/tpm/tpm_passthrough.c +15 -8
index e98efb7..e1edb38 100644
@@ -377,6 +377,8 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb)
     int fd = -1;
     char *dev;
     char path[PATH_MAX];
+    const char *prefix[] = {"misc/", "tpm/"};
+    int i;
 
     if (tb->cancel_path) {
         fd = qemu_open(tb->cancel_path, O_WRONLY);
@@ -390,16 +392,21 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb)
     dev = strrchr(tpm_pt->tpm_dev, '/');
     if (dev) {
         dev++;
-        if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel",
-                     dev) < sizeof(path)) {
-            fd = qemu_open(path, O_WRONLY);
-            if (fd >= 0) {
-                tb->cancel_path = g_strdup(path);
-            } else {
-                error_report("tpm_passthrough: Could not open TPM cancel "
-                             "path %s : %s", path, strerror(errno));
+        for (i = 0; i < ARRAY_SIZE(prefix); i++) {
+            if (snprintf(path, sizeof(path),
+                         "/sys/class/%s%s/device/cancel",
+                         prefix[i], dev) < sizeof(path)) {
+                fd = qemu_open(path, O_WRONLY);
+                if (fd >= 0) {
+                    tb->cancel_path = g_strdup(path);
+                    break;
+                }
             }
         }
+        if (fd < 0) {
+            error_report("tpm_passthrough: Could not open TPM cancel "
+                         "path %s : %s", path, strerror(errno));
+        }
     } else {
        error_report("tpm_passthrough: Bad TPM device path %s",
                     tpm_pt->tpm_dev);
Signature · 1 line
2.4.3
#1 lore raw

Peter, Michael,

I have 3 TPM related patches on the mailing list that are fixing
buges. They are either being overlooked or ignored. How can we make progress with them?

Regards,
Stefan

Quoted 54 lines · Stefan Berger

This patch addresses BZ 1281413.

Adapt the sysfs TPM command cancel path for the TPM driver that does not use a miscdevice anymore since Linux 4.0. Support old and new paths.

---
  hw/tpm/tpm_passthrough.c | 23 +++++++++++++++--------
  1 file changed, 15 insertions(+), 8 deletions(-)
hw/tpm/tpm_passthrough.c +15 -8
index e98efb7..e1edb38 100644
@@ -377,6 +377,8 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb)
      int fd = -1;
      char *dev;
      char path[PATH_MAX];
+    const char *prefix[] = {"misc/", "tpm/"};
+    int i;
 
      if (tb->cancel_path) {
          fd = qemu_open(tb->cancel_path, O_WRONLY);
@@ -390,16 +392,21 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb)
      dev = strrchr(tpm_pt->tpm_dev, '/');
      if (dev) {
          dev++;
-        if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel",
-                     dev) < sizeof(path)) {
-            fd = qemu_open(path, O_WRONLY);
-            if (fd >= 0) {
-                tb->cancel_path = g_strdup(path);
-            } else {
-                error_report("tpm_passthrough: Could not open TPM cancel "
-                             "path %s : %s", path, strerror(errno));
+        for (i = 0; i < ARRAY_SIZE(prefix); i++) {
+            if (snprintf(path, sizeof(path),
+                         "/sys/class/%s%s/device/cancel",
+                         prefix[i], dev) < sizeof(path)) {
+                fd = qemu_open(path, O_WRONLY);
+                if (fd >= 0) {
+                    tb->cancel_path = g_strdup(path);
+                    break;
+                }
              }
          }
+        if (fd < 0) {
+            error_report("tpm_passthrough: Could not open TPM cancel "
+                         "path %s : %s", path, strerror(errno));
+        }
      } else {
         error_report("tpm_passthrough: Bad TPM device path %s",
                      tpm_pt->tpm_dev);