[PATCH] util: fix cache invalidation of swtpm capabilities

The check for whether the swtpm binary was modified is checking pointers to the mtime field in two distinct structs, so will always compare different. This resulted in re-probing swtpm capabilities every time, as many as 20 times for a single VM launch. Fixes: commit 01cf7a1bb9f1da27ad8bcbaa82c4f7a948c6a793 Author: Stefan Berger <stefanb@us.ibm.com> Date: Thu Jul 25 14:22:04 2019 -0400 tpm: Check whether previously found executables were updated Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virtpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 8a77ba98ff..ffec23a535 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -301,7 +301,7 @@ virTPMEmulatorInit(void) findit = true; if (!findit && - &statbuf.st_mtime != &prgs[i].stat->st_mtime) + statbuf.st_mtime != prgs[i].stat->st_mtime) findit = true; } -- 2.33.1

On 11/24/21 11:58, Daniel P. Berrangé wrote:
The check for whether the swtpm binary was modified is checking pointers to the mtime field in two distinct structs, so will always compare different. This resulted in re-probing swtpm capabilities every time, as many as 20 times for a single VM launch.
Fixes:
commit 01cf7a1bb9f1da27ad8bcbaa82c4f7a948c6a793 Author: Stefan Berger <stefanb@us.ibm.com> Date: Thu Jul 25 14:22:04 2019 -0400
tpm: Check whether previously found executables were updated
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virtpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 8a77ba98ff..ffec23a535 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -301,7 +301,7 @@ virTPMEmulatorInit(void) findit = true;
if (!findit && - &statbuf.st_mtime != &prgs[i].stat->st_mtime) + statbuf.st_mtime != prgs[i].stat->st_mtime) findit = true; }
Well, if the function ends up on the same position in stack every time it's called then this works :-) Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal

On Wed, Nov 24, 2021 at 10:58:38AM +0000, Daniel P. Berrangé wrote:
The check for whether the swtpm binary was modified is checking pointers to the mtime field in two distinct structs, so will always compare different. This resulted in re-probing swtpm capabilities every time, as many as 20 times for a single VM launch.
Fixes:
commit 01cf7a1bb9f1da27ad8bcbaa82c4f7a948c6a793 Author: Stefan Berger <stefanb@us.ibm.com> Date: Thu Jul 25 14:22:04 2019 -0400
tpm: Check whether previously found executables were updated
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
--- src/util/virtpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 8a77ba98ff..ffec23a535 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -301,7 +301,7 @@ virTPMEmulatorInit(void) findit = true;
if (!findit && - &statbuf.st_mtime != &prgs[i].stat->st_mtime) + statbuf.st_mtime != prgs[i].stat->st_mtime) findit = true; }
-- 2.33.1

On a Wednesday in 2021, Daniel P. Berrangé wrote:
The check for whether the swtpm binary was modified is checking pointers to the mtime field in two distinct structs, so will always compare different. This resulted in re-probing swtpm capabilities every time, as many as 20 times for a single VM launch.
Fixes:
commit 01cf7a1bb9f1da27ad8bcbaa82c4f7a948c6a793 Author: Stefan Berger <stefanb@us.ibm.com> Date: Thu Jul 25 14:22:04 2019 -0400
tpm: Check whether previously found executables were updated
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virtpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (4)
-
Daniel P. Berrangé
-
Ján Tomko
-
Martin Kletzander
-
Michal Prívozník