Support APMLM field with PQAP/TAPQ instruction
Subsystems (2)
Harald Freudenberger
maintainerv3 cover Support APMLM field with PQAP/TAPQ instruction
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. This patch (series) covers all what's needed to support this new field within the AP bus code.
Changelog:
v1: initial version
v2: The update of the bit mask TAPQ_CARD_HWINFO_MASK was missing. So
the new field apmlm could not shine through.
v3: Shashiko complained about that there is no upper limit but the
combination of apml and apmlm could lead to memory allocations of 960KB per AP request/reply. So introduce an upper and lower limit to crop this firmware given AP message size limit into reasonable range. By default 12KB...72KB but the upper limit can be adjusted via module parameter.
Harald Freudenberger (2):
s390/ap: Support new APMLM field with PQAP/TAPQ instruction s390/ap: Cap AP maximum message size adjustable via module parameter
arch/s390/include/asm/ap.h | 4 ++-- drivers/s390/crypto/ap_bus.c | 11 +++++++++++ drivers/s390/crypto/ap_bus.h | 7 +++++-- drivers/s390/crypto/ap_card.c | 9 ++++++++- 4 files changed, 26 insertions(+), 5 deletions(-)
--
2.43.0
Harald Freudenberger
maintainerPATCH v3 1/2 s390/ap: Support new APMLM field with PQAP/TAPQ instruction
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.
--- 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(-)
arch/s390/include/asm/ap.h +2 -2
@@ -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 */ };
drivers/s390/crypto/ap_bus.h +1 -1
@@ -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)
drivers/s390/crypto/ap_card.c +2 -1
@@ -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; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 1/2] s390/ap: Support new APMLM field with PQAP/TAPQ instruction
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
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
Quoted 4 lines
Also adapt the HWINFO mask to have this new apmlm field shine through this bit filter mask.
Signed-off-by Harald Freudenberger <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Harald Freudenberger
maintainerPATCH v3 2/2 s390/ap: Cap AP maximum message size adjustable via module parameter
In reply to Harald FreudenbergerWith 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.
--- 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(-)
drivers/s390/crypto/ap_bus.c +11 -0
@@ -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)
drivers/s390/crypto/ap_bus.h +4 -1
@@ -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;
drivers/s390/crypto/ap_card.c +6 -0
@@ -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; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v3 2/2] s390/ap: Cap AP maximum message size adjustable via module parameter
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines
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.
Quoted 5 lines
Also define some lower limit
AP_MIN_MSG_SIZE(12KB) and ensure during module init that a user-suppliedmax_msg_size_limitparameter is not lower than this minimum, adjusting it with a warning if necessary.Signed-off-by Harald Freudenberger <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2