Skip to contentSkip to conversation

tests: fix tpm-crb tpm-tis tests race

PATCH In review Marc-André Lureau 5 participants 6 messages Mar 16, 2018 – May 18, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: fix tpm-crb tpm-tis tests race

No need to close the TPM data socket on the emulator end, qemu will close it after a SHUTDOWN. This avoids a race between close() and read() in the TPM data thread.

---
 tests/tpm-emu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/tpm-emu.c +1 -1
index 4dada76834..8c2bd53cad 100644
@@ -125,7 +125,7 @@ void *tpm_emu_ctrl_thread(void *data)
         case CMD_SHUTDOWN: {
             ptm_res res = 0;
             qio_channel_write(ioc, (char *)&res, sizeof(res), &error_abort);
-            qio_channel_close(s->tpm_ioc, &error_abort);
+            /* the tpm data thread is expected to finish now */
             g_thread_join(s->emu_tpm_thread);
             break;
         }
Signature · 1 line
2.16.2.521.g9aa15f885a
#1 lore raw
Quoted 15 lines · Marc-André Lureau

No need to close the TPM data socket on the emulator end, qemu will close it after a SHUTDOWN. This avoids a race between close() and read() in the TPM data thread.

---
 tests/tpm-emu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/tpm-emu.c +0 -0
index 4dada76834..8c2bd53cad 100644

tests/tpm-emu.c void *tpm_emu_ctrl_thread(void *data) · line 129

Quoted 6 lines
tests/tpm-emu.c +1 -1
@@ -125,7 +125,7 @@ void *tpm_emu_ctrl_thread(void *data)
         case CMD_SHUTDOWN: {
             ptm_res res = 0;
             qio_channel_write(ioc, (char *)&res, sizeof(res), &error_abort);
-            qio_channel_close(s->tpm_ioc, &error_abort);
+            /* the tpm data thread is expected to finish now */
             g_thread_join(s->emu_tpm_thread);

Won't this leave an orphaed FD open in the test suite ? Is it perhaps sufficient to just swap the order of the g_thread_join and qio_channel_close calls, so that we join the thread before we close the channel that the thread is using ?

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw

Hi

Quoted 11 lines · Daniel P. Berrangé
Quoted 10 lines · Marc-André Lureau

No need to close the TPM data socket on the emulator end, qemu will close it after a SHUTDOWN. This avoids a race between close() and read() in the TPM data thread.

---
 tests/tpm-emu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

tests/tpm-emu.c void *tpm_emu_ctrl_thread(void *data) · line 129

Quoted 11 lines
tests/tpm-emu.c +1 -1
index 4dada76834..8c2bd53cad 100644
@@ -125,7 +125,7 @@ void *tpm_emu_ctrl_thread(void *data)
         case CMD_SHUTDOWN: {
             ptm_res res = 0;
             qio_channel_write(ioc, (char *)&res, sizeof(res), &error_abort);
-            qio_channel_close(s->tpm_ioc, &error_abort);
+            /* the tpm data thread is expected to finish now */
             g_thread_join(s->emu_tpm_thread);

Won't this leave an orphaed FD open in the test suite ? Is it perhaps sufficient to just swap the order of the g_thread_join and qio_channel_close calls, so that we join the thread before we close the channel that the thread is using ?

Isn't the socket close on the last unref? (at end of tpm_emu_tpm_thread())

Quoted 8 lines

Regards,
Daniel
--

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Signature · 1 line
Marc-André Lureau
#3 lore raw
Quoted 31 lines · Marc-André Lureau

Hi

Quoted 11 lines · Daniel P. Berrangé
Quoted 10 lines · Marc-André Lureau

No need to close the TPM data socket on the emulator end, qemu will close it after a SHUTDOWN. This avoids a race between close() and read() in the TPM data thread.

---
 tests/tpm-emu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

tests/tpm-emu.c void *tpm_emu_ctrl_thread(void *data) · line 129

Quoted 11 lines
tests/tpm-emu.c +1 -1
index 4dada76834..8c2bd53cad 100644
@@ -125,7 +125,7 @@ void *tpm_emu_ctrl_thread(void *data)
         case CMD_SHUTDOWN: {
             ptm_res res = 0;
             qio_channel_write(ioc, (char *)&res, sizeof(res), &error_abort);
-            qio_channel_close(s->tpm_ioc, &error_abort);
+            /* the tpm data thread is expected to finish now */
             g_thread_join(s->emu_tpm_thread);

Won't this leave an orphaed FD open in the test suite ? Is it perhaps sufficient to just swap the order of the g_thread_join and qio_channel_close calls, so that we join the thread before we close the channel that the thread is using ?

Quoted 1 line

Isn't the socket close on the last unref? (at end of tpm_emu_tpm_thread())

Oh yes, that is true. I should have looked at more than just diff context. In that case

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by
#4 lore raw
Quoted 30 lines · Daniel P. Berrangé
Quoted 29 lines · Marc-André Lureau

Hi

Quoted 26 lines · Daniel P. Berrangé
Quoted 15 lines · Marc-André Lureau

No need to close the TPM data socket on the emulator end, qemu will close it after a SHUTDOWN. This avoids a race between close() and read() in the TPM data thread.

---
  tests/tpm-emu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/tpm-emu.c +0 -0
index 4dada76834..8c2bd53cad 100644

tests/tpm-emu.c void *tpm_emu_ctrl_thread(void *data) · line 129

Quoted 6 lines
tests/tpm-emu.c +1 -1
@@ -125,7 +125,7 @@ void *tpm_emu_ctrl_thread(void *data)
          case CMD_SHUTDOWN: {
              ptm_res res = 0;
              qio_channel_write(ioc, (char *)&res, sizeof(res), &error_abort);
-            qio_channel_close(s->tpm_ioc, &error_abort);
+            /* the tpm data thread is expected to finish now */
              g_thread_join(s->emu_tpm_thread);

Won't this leave an orphaed FD open in the test suite ? Is it perhaps sufficient to just swap the order of the g_thread_join and qio_channel_close calls, so that we join the thread before we close the channel that the thread is using ?

Quoted 5 lines
Quoted 1 line

Isn't the socket close on the last unref? (at end of tpm_emu_tpm_thread())

Oh yes, that is true. I should have looked at more than just diff context. In that case

Ha. It's already done :-)

Quoted 3 lines

Regards,
Daniel

Reviewed-by Tested-by on v1 1/1
#5 lore raw
In reply to Marc-André Lureau
Quoted 6 lines · Marc-André Lureau

No need to close the TPM data socket on the emulator end, qemu will close it after a SHUTDOWN. This avoids a race between close() and read() in the TPM data thread.

Quoted 9 lines
---
 tests/tpm-emu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/tpm-emu.c +0 -0
index 4dada76834..8c2bd53cad 100644

tests/tpm-emu.c void *tpm_emu_ctrl_thread(void *data) · line 131

Quoted 8 lines
tests/tpm-emu.c +1 -1
@@ -125,7 +125,7 @@ void *tpm_emu_ctrl_thread(void *data)
         case CMD_SHUTDOWN: {
             ptm_res res = 0;
             qio_channel_write(ioc, (char *)&res, sizeof(res), &error_abort);
-            qio_channel_close(s->tpm_ioc, &error_abort);
+            /* the tpm data thread is expected to finish now */
             g_thread_join(s->emu_tpm_thread);
             break;
         }

--
Alex Bennée