From: Harald Freudenberger <freude@linux.ibm.com>
To: dengler@linux.ibm.com, fcallies@linux.ibm.com
Cc: freude@linux.ibm.com, linux-s390@vger.kernel.org,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>
Subject: [PATCH v3 2/2] s390/ap: Cap AP maximum message size adjustable via module parameter
Date: Tue, 13 Oct 2026 15:44:22 +0200 [thread overview]
Message-ID: <20261013134422.64155-3-freude@linux.ibm.com> (raw)
In-Reply-To: <20261013134422.64155-1-freude@linux.ibm.com>
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
next prev parent reply other threads:[~2026-10-13 13:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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:52 ` sashiko-bot
2026-10-13 13:44 ` Harald Freudenberger [this message]
2026-10-13 13:52 ` [PATCH v3 2/2] s390/ap: Cap AP maximum message size adjustable via module parameter sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261013134422.64155-3-freude@linux.ibm.com \
--to=freude@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=dengler@linux.ibm.com \
--cc=fcallies@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox