summaryrefslogtreecommitdiff
path: root/drivers/s390/crypto/ap_queue.c
diff options
context:
space:
mode:
authorHarald Freudenberger <freude@linux.ibm.com>2023-09-12 10:08:51 +0200
committerVasily Gorbik <gor@linux.ibm.com>2023-10-16 13:04:09 +0200
commita19a161482b1739c2207861d086403389dc1bd47 (patch)
tree6b83d98ddc5dae57d7f67939a2d4c400e5cd71b1 /drivers/s390/crypto/ap_queue.c
parent32d1d9204f8db3360be55e65bd182a1a68f93308 (diff)
s390/zcrypt: introduce new internal AP queue se_bound attribute
This patch introduces a new AP queue internal attribute se_bound which reflects the bound state of an APQN within a Secure Execution environment. With introduction of Secure Execution guests now an AP firmware queue needs to be bound to the guest before usage. This patch introduces a new internal attribute reflecting this bound state and some glue code to handle this new field during lifetime of an AP queue device. Together with that now the zcrypt scheduler considers the state of the AP queues when a message is about to be distributed among the existing queues. There is a new function ap_queue_usable() which returns true only when all conditions for using this AP queue device are fulfilled. In details this means: the AP queue needs to be configured, not checkstopped and within an SE environment it needs to be bound. So the new function gives and indication if the AP queue device is ready to serve requests or not. Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Reviewed-by: Holger Dengler <dengler@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Diffstat (limited to 'drivers/s390/crypto/ap_queue.c')
-rw-r--r--drivers/s390/crypto/ap_queue.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/drivers/s390/crypto/ap_queue.c b/drivers/s390/crypto/ap_queue.c
index 2943b2529d3a..993240370ecf 100644
--- a/drivers/s390/crypto/ap_queue.c
+++ b/drivers/s390/crypto/ap_queue.c
@@ -33,6 +33,11 @@ static inline bool ap_q_supports_assoc(struct ap_queue *aq)
return ap_test_bit(&aq->card->functions, AP_FUNC_EP11);
}
+static inline bool ap_q_needs_bind(struct ap_queue *aq)
+{
+ return ap_q_supports_bind(aq) && ap_sb_available();
+}
+
/**
* ap_queue_enable_irq(): Enable interrupt support on this AP queue.
* @aq: The AP queue
@@ -304,6 +309,7 @@ static enum ap_sm_wait ap_sm_reset(struct ap_queue *aq)
aq->sm_state = AP_SM_STATE_RESET_WAIT;
aq->interrupt = false;
aq->rapq_fbit = 0;
+ aq->se_bound = false;
return AP_SM_WAIT_LOW_TIMEOUT;
default:
aq->dev_state = AP_DEV_STATE_ERROR;
@@ -868,7 +874,12 @@ static ssize_t se_bind_store(struct device *dev,
}
status = ap_bapq(aq->qid);
spin_unlock_bh(&aq->lock);
- if (status.response_code) {
+ if (!status.response_code) {
+ aq->se_bound = true;
+ AP_DBF_INFO("%s bapq(0x%02x.%04x) success\n", __func__,
+ AP_QID_CARD(aq->qid),
+ AP_QID_QUEUE(aq->qid));
+ } else {
AP_DBF_WARN("%s RC 0x%02x on bapq(0x%02x.%04x)\n",
__func__, status.response_code,
AP_QID_CARD(aq->qid),
@@ -1074,6 +1085,42 @@ int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg)
EXPORT_SYMBOL(ap_queue_message);
/**
+ * ap_queue_usable(): Check if queue is usable just now.
+ * @aq: The AP queue device to test for usability.
+ * This function is intended for the scheduler to query if it makes
+ * sense to enqueue a message into this AP queue device by calling
+ * ap_queue_message(). The perspective is very short-term as the
+ * state machine and device state(s) may change at any time.
+ */
+bool ap_queue_usable(struct ap_queue *aq)
+{
+ bool rc = true;
+
+ spin_lock_bh(&aq->lock);
+
+ /* check for not configured or checkstopped */
+ if (!aq->config || aq->chkstop) {
+ rc = false;
+ goto unlock_and_out;
+ }
+
+ /* device state needs to be ok */
+ if (aq->dev_state != AP_DEV_STATE_OPERATING) {
+ rc = false;
+ goto unlock_and_out;
+ }
+
+ /* SE guest's queues additionally need to be bound */
+ if (ap_q_needs_bind(aq) && !aq->se_bound)
+ rc = false;
+
+unlock_and_out:
+ spin_unlock_bh(&aq->lock);
+ return rc;
+}
+EXPORT_SYMBOL(ap_queue_usable);
+
+/**
* ap_cancel_message(): Cancel a crypto request.
* @aq: The AP device that has the message queued
* @ap_msg: The message that is to be removed