* [PATCH v3 1/2] s390/ap: Support new APMLM field with PQAP/TAPQ instruction
2026-10-13 13:44 [PATCH v3 0/2] Support APMLM field with PQAP/TAPQ instruction Harald Freudenberger
@ 2026-10-13 13:44 ` Harald Freudenberger
2026-10-13 13:52 ` sashiko-bot
2026-10-13 13:44 ` [PATCH v3 2/2] s390/ap: Cap AP maximum message size adjustable via module parameter Harald Freudenberger
1 sibling, 1 reply; 5+ messages in thread
From: Harald Freudenberger @ 2026-10-13 13:44 UTC (permalink / raw)
To: dengler, fcallies
Cc: freude, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev
There is a new field APMLM (AP message limit multiplier) defined
within the GR2 register on successful invocation of the TAPQ
subfunction for the PQAP instruction.
So the new formula to calculate the AP max message limit is now:
if ml field <= 3
AP max message limit is 12KB
else
AP max message limit = apml * (apmlm + 1) * 4KB
Also adapt the HWINFO mask to have this new apmlm field shine
through this bit filter mask.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
---
arch/s390/include/asm/ap.h | 4 ++--
drivers/s390/crypto/ap_bus.h | 2 +-
drivers/s390/crypto/ap_card.c | 3 ++-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/s390/include/asm/ap.h b/arch/s390/include/asm/ap.h
index c91b6ace199d..01d575c35887 100644
--- a/arch/s390/include/asm/ap.h
+++ b/arch/s390/include/asm/ap.h
@@ -123,8 +123,8 @@ struct ap_tapq_hwinfo {
unsigned int : 14;
unsigned int at : 8; /* ap type */
unsigned int nd : 8; /* nr of domains */
- unsigned int : 4;
- unsigned int ml : 4; /* apxl ml */
+ unsigned int mlm : 4; /* AP msg limit multiplier */
+ unsigned int ml : 4; /* AP msg limit */
unsigned int : 3;
unsigned int qd : 5; /* queue depth */
};
diff --git a/drivers/s390/crypto/ap_bus.h b/drivers/s390/crypto/ap_bus.h
index fb4d678336e4..34f9dcd96bc7 100644
--- a/drivers/s390/crypto/ap_bus.h
+++ b/drivers/s390/crypto/ap_bus.h
@@ -181,7 +181,7 @@ struct ap_card {
bool chkstop; /* checkstop state */
};
-#define TAPQ_CARD_HWINFO_MASK 0xFFFF0000FFFF0F1FUL
+#define TAPQ_CARD_HWINFO_MASK 0xFFFF0000FFFFFF1FUL
#define ASSOC_IDX_INVALID 0x10000
#define to_ap_card(x) container_of((x), struct ap_card, ap_dev.device)
diff --git a/drivers/s390/crypto/ap_card.c b/drivers/s390/crypto/ap_card.c
index c86397f4ddcd..e9a8180f08c2 100644
--- a/drivers/s390/crypto/ap_card.c
+++ b/drivers/s390/crypto/ap_card.c
@@ -242,7 +242,8 @@ struct ap_card *ap_card_create(int id, struct ap_tapq_hwinfo hwinfo,
ac->hwinfo = hwinfo;
ac->id = id;
ac->maxmsgsize = hwinfo.ml > 3 ?
- hwinfo.ml * AP_TAPQ_ML_FIELD_CHUNK_SIZE : AP_DEFAULT_MAX_MSG_SIZE;
+ hwinfo.ml * (hwinfo.mlm + 1) * AP_TAPQ_ML_FIELD_CHUNK_SIZE :
+ AP_DEFAULT_MAX_MSG_SIZE;
return ac;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 2/2] s390/ap: Cap AP maximum message size adjustable via module parameter
2026-10-13 13:44 [PATCH v3 0/2] Support APMLM field with PQAP/TAPQ instruction Harald Freudenberger
2026-10-13 13:44 ` [PATCH v3 1/2] s390/ap: Support new " Harald Freudenberger
@ 2026-10-13 13:44 ` Harald Freudenberger
2026-10-13 13:52 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: Harald Freudenberger @ 2026-10-13 13:44 UTC (permalink / raw)
To: dengler, fcallies
Cc: freude, linux-s390, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev
With AP bus now supporting the new APMLM field with PQAP/TAPQ the AP
max message size could be raised up to 960KB. As this amount of memory
is tried to get allocated on each AP request/reply it would quickly
cause some memory problems.
Introduce a reasonable default upper limit
AP_DEFAULT_MAX_MSG_SIZE_LIMIT (72KB) and expose it via a read-only
module parameter 'max_msg_size_limit'. When creating an AP card, clip
the calculated AP max message size from the hardware info fetched via
PQAP/TAPQ to this upper limit and log a debug feature warning
(AP_DBF_WARN) if the card's reported limit exceeds it.
Also define some lower limit AP_MIN_MSG_SIZE (12KB) and ensure during
module init that a user-supplied max_msg_size_limit parameter is not
lower than this minimum, adjusting it with a warning if necessary.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
---
drivers/s390/crypto/ap_bus.c | 11 +++++++++++
drivers/s390/crypto/ap_bus.h | 5 ++++-
drivers/s390/crypto/ap_card.c | 6 ++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index d82df5b4e2db..639a02f41cea 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -76,6 +76,10 @@ MODULE_PARM_DESC(useirq, "Use interrupt if available, default is 1 (on).");
atomic_t ap_max_msg_size = ATOMIC_INIT(AP_DEFAULT_MAX_MSG_SIZE);
EXPORT_SYMBOL(ap_max_msg_size);
+unsigned int ap_max_msg_size_limit = AP_DEFAULT_MAX_MSG_SIZE_LIMIT;
+module_param_named(max_msg_size_limit, ap_max_msg_size_limit, uint, 0444);
+MODULE_PARM_DESC(max_msg_size_limit, "Upper limit for AP max message size.");
+
static struct device *ap_root_device;
/* Hashtable of all queue devices on the AP bus */
@@ -2631,6 +2635,13 @@ static int __init ap_module_init(void)
ap_domain_index = -1;
}
+ /* verify AP max msg size limit module parameter */
+ if (ap_max_msg_size_limit < AP_MIN_MSG_SIZE) {
+ pr_warn("max_msg_size_limit (%u) below minimum %u, adjusting\n",
+ ap_max_msg_size_limit, AP_MIN_MSG_SIZE);
+ ap_max_msg_size_limit = AP_MIN_MSG_SIZE;
+ }
+
/* Create /sys/bus/ap. */
rc = bus_register(&ap_bus_type);
if (rc)
diff --git a/drivers/s390/crypto/ap_bus.h b/drivers/s390/crypto/ap_bus.h
index 34f9dcd96bc7..5dcc9c54e32e 100644
--- a/drivers/s390/crypto/ap_bus.h
+++ b/drivers/s390/crypto/ap_bus.h
@@ -25,11 +25,14 @@
#define AP_RESET_TIMEOUT (HZ*0.7) /* Time in ticks for reset timeouts. */
#define AP_CONFIG_TIME 30 /* Time in seconds between AP bus rescans. */
#define AP_POLL_TIME 1 /* Time in ticks between receive polls. */
-#define AP_DEFAULT_MAX_MSG_SIZE (12 * 1024)
+#define AP_MIN_MSG_SIZE (12 * 1024)
+#define AP_DEFAULT_MAX_MSG_SIZE AP_MIN_MSG_SIZE
+#define AP_DEFAULT_MAX_MSG_SIZE_LIMIT (72 * 1024)
#define AP_TAPQ_ML_FIELD_CHUNK_SIZE (4096)
extern int ap_domain_index;
extern atomic_t ap_max_msg_size;
+extern unsigned int ap_max_msg_size_limit;
extern DECLARE_HASHTABLE(ap_queues, 8);
extern spinlock_t ap_queues_lock;
diff --git a/drivers/s390/crypto/ap_card.c b/drivers/s390/crypto/ap_card.c
index e9a8180f08c2..134c14fb2e03 100644
--- a/drivers/s390/crypto/ap_card.c
+++ b/drivers/s390/crypto/ap_card.c
@@ -14,6 +14,7 @@
#include <asm/sclp.h>
#include "ap_bus.h"
+#include "ap_debug.h"
/*
* AP card related attributes.
@@ -244,6 +245,11 @@ struct ap_card *ap_card_create(int id, struct ap_tapq_hwinfo hwinfo,
ac->maxmsgsize = hwinfo.ml > 3 ?
hwinfo.ml * (hwinfo.mlm + 1) * AP_TAPQ_ML_FIELD_CHUNK_SIZE :
AP_DEFAULT_MAX_MSG_SIZE;
+ if (ac->maxmsgsize > ap_max_msg_size_limit) {
+ AP_DBF_WARN("card 0x%02x: ml=%d mlm=%d exceeds max_msg_size_limit %u, clipping\n",
+ id, hwinfo.ml, hwinfo.mlm, ap_max_msg_size_limit);
+ ac->maxmsgsize = ap_max_msg_size_limit;
+ }
return ac;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread