@@ -23,6 +23,7 @@ static unsigned int mktme_available_keyids; /* Free Hardware KeyIDs */
static struct kmem_cache *mktme_prog_cache; /* Hardware programming cache */
static unsigned long *mktme_target_map; /* PCONFIG programming target */
static cpumask_var_t mktme_leadcpus; /* One CPU per PCONFIG target */
+static bool mktme_allow_keys; /* HW topology supports keys */
enum mktme_keyid_state {
KEYID_AVAILABLE, /* Available to be assigned */
@@ -253,32 +254,55 @@ static void mktme_destroy_key(struct key *key)
percpu_ref_kill(&encrypt_count[keyid]);
}
+static void mktme_update_pconfig_targets(void);
/* Key Service Method to create a new key. Payload is preparsed. */
int mktme_instantiate_key(struct key *key, struct key_preparsed_payload *prep)
{
u32 *payload = prep->payload.data[0];
unsigned long flags;
+ int ret = -ENOKEY;
int keyid;
spin_lock_irqsave(&mktme_lock, flags);
+
+ /* Topology supports key creation */
+ if (mktme_allow_keys)
+ goto get_key;
+
+ /* Topology unknown, check it. */
+ if (!mktme_hmat_evaluate()) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
+ /* Keys are now allowed. Update the programming targets. */
+ mktme_update_pconfig_targets();
+ mktme_allow_keys = true;
+
+get_key:
keyid = mktme_reserve_keyid(key);
spin_unlock_irqrestore(&mktme_lock, flags);
if (!keyid)
- return -ENOKEY;
+ goto out;
if (percpu_ref_init(&encrypt_count[keyid], mktme_percpu_ref_release,
0, GFP_KERNEL))
- goto err_out;
+ goto out_free_key;
- if (!mktme_program_keyid(keyid, *payload))
- return MKTME_PROG_SUCCESS;
+ ret = mktme_program_keyid(keyid, *payload);
+ if (ret == MKTME_PROG_SUCCESS)
+ goto out;
+ /* Key programming failed */
percpu_ref_exit(&encrypt_count[keyid]);
-err_out:
+
+out_free_key:
spin_lock_irqsave(&mktme_lock, flags);
mktme_release_keyid(keyid);
+out_unlock:
spin_unlock_irqrestore(&mktme_lock, flags);
- return -ENOKEY;
+out:
+ return ret;
}
/* Make sure arguments are correct for the TYPE of key requested */