From 300f8d23b5ee2a4254d10dd09590a426446e3feb Mon Sep 17 00:00:00 2001 From: Harald Freudenberger Date: Fri, 11 Oct 2024 14:28:50 +0200 Subject: [PATCH] lszcrypt: Fix wrong state showing up for removed AP queue within SE guest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a queue is removed from a SE guest which was in a state other than "usable" (for example "unbound") the state displayed by lszcrypt switches to "usable" until the queue device is finally removed by the AP bus scan running every 30s. This intermediate state is caused by reading 0x00000000 on the underlying /sys/devices/cardxx/xx.yyyy/ap_functions. lszcrypt only extracts the BS bits from this value and maps these both bits to string output 0: "usable" 1: "bound" 2: "unbound" 3: "illicit" totally ignoring the fact that there is no AP function at all. Now the code checks for a valid ap_functions value first, before actually extracting and displaying the SE state. In case the ap_functions reads as 0x00000000 lszcrypt now displays the string "invalid". Signed-off-by: Harald Freudenberger Reviewed-by: Holger Dengler Signed-off-by: Jan Höppner --- zconf/zcrypt/lszcrypt.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/zconf/zcrypt/lszcrypt.c b/zconf/zcrypt/lszcrypt.c index 8d523c67..604387ad 100644 --- a/zconf/zcrypt/lszcrypt.c +++ b/zconf/zcrypt/lszcrypt.c @@ -693,21 +693,25 @@ static void read_subdev_rec_verbose(struct util_rec *rec, const char *grp_dev, util_rec_set(rec, "sestat", "error"); return; } - switch (EXTRACT_BS_BITS(facility)) { - case 0: - util_rec_set(rec, "sestat", "usable"); - break; - case 1: - util_rec_set(rec, "sestat", "bound"); - break; - case 2: - util_rec_set(rec, "sestat", "unbound"); - break; - case 3: - util_rec_set(rec, "sestat", "illicit"); - break; - default: - util_rec_set(rec, "sestat", "-"); + if (facility) { + switch (EXTRACT_BS_BITS(facility)) { + case 0: + util_rec_set(rec, "sestat", "usable"); + break; + case 1: + util_rec_set(rec, "sestat", "bound"); + break; + case 2: + util_rec_set(rec, "sestat", "unbound"); + break; + case 3: + util_rec_set(rec, "sestat", "illicit"); + break; + default: + util_rec_set(rec, "sestat", "-"); + } + } else { + util_rec_set(rec, "sestat", "invalid"); } } }