netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Seth Jennings <sjenning@linux.vnet.ibm.com>
To: "David S . Miller" <davem@davemloft.net>
Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, Eric Dumazet <eric.dumazet@gmail.com>,
	Brian King <brking@linux.vnet.ibm.com>,
	Robert Jennings <rcj@linux.vnet.ibm.com>
Subject: [PATCH 1/3] crypto: Add per-cpu transform alloc() and free()
Date: Wed,  7 Dec 2011 12:59:08 -0600	[thread overview]
Message-ID: <1323284350-13784-2-git-send-email-sjenning@linux.vnet.ibm.com> (raw)
In-Reply-To: <1323284350-13784-1-git-send-email-sjenning@linux.vnet.ibm.com>

This patch add two functions for allocating a freeing
dynamically allocated per-cpu transform structures.

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
---
 crypto/api.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/crypto/api.c b/crypto/api.c
index 033a714..f95b3f9 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -602,5 +602,67 @@ int crypto_has_alg(const char *name, u32 type, u32 mask)
 }
 EXPORT_SYMBOL_GPL(crypto_has_alg);
 
+/*
+ * Per-cpu crypto helpers
+ *
+ * crypto_alloc_percpu_tfms() and crypto_free_percpu_tfms() are used for
+ * allocating tfms on a per-cpu basis. The set of cpus the tfms are
+ * allocated/freed on is determined by the cpumask (see linux/cpumask.h).
+ * If the cpu_possible_mask is used, then the user has a tfm for every cpu
+ * that could ever possibly enabled. However, if the user calls with cpumask
+ * cpu_online_mask or cpu_present_mask with HOTPLUG enabled, the user
+ * must register a cpu notifier to allocate/free the tfm for dynamically
+ * added/removed cpus.
+*/
+void crypto_free_percpu_tfms(struct crypto_tfm * __percpu *tfms,
+				const struct cpumask *cpumask)
+{
+	int cpu;
+	struct crypto_tfm *tfm;
+
+	if (!tfms)
+		return;
+
+	for_each_cpu(cpu, cpumask) {
+		tfm = *per_cpu_ptr(tfms, cpu);
+		if (!tfm)
+			continue;
+		crypto_free_tfm(tfm);
+		*per_cpu_ptr(tfms, cpu) = NULL;
+	}
+
+	free_percpu(tfms);
+}
+EXPORT_SYMBOL_GPL(crypto_free_percpu_tfms);
+
+struct crypto_tfm * __percpu *crypto_alloc_percpu_tfms(const char *alg_name,
+			u32 type, u32 mask, const struct cpumask *cpumask)
+{
+	int cpu, err;
+	struct crypto_tfm * __percpu *tfms, *tfm;
+
+	tfms = alloc_percpu(struct crypto_tfm *);
+	if (!tfms) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	for_each_cpu(cpu, cpumask) {
+		tfm = crypto_alloc_base(alg_name, type, mask);
+		if (IS_ERR(tfm)) {
+			err = PTR_ERR(tfm);
+			goto error;
+		}
+		*per_cpu_ptr(tfms, cpu) = tfm;
+	}
+	return tfms;
+
+error:
+	if (tfms)
+		crypto_free_percpu_tfms(tfms, cpumask);
+	return (struct crypto_tfm * __percpu *)(ERR_PTR(err));
+}
+EXPORT_SYMBOL_GPL(crypto_alloc_percpu_tfms);
+
 MODULE_DESCRIPTION("Cryptographic core API");
 MODULE_LICENSE("GPL");
-- 
1.7.5.4

  reply	other threads:[~2011-12-07 18:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-07 18:59 [PATCH 0/3] crypto: Add per-cpu transform helpers Seth Jennings
2011-12-07 18:59 ` Seth Jennings [this message]
2011-12-07 18:59 ` [PATCH 2/3] crypto: Add inline per-cpu wrappers for compression Seth Jennings
2011-12-07 18:59 ` [PATCH 3/3] xfrm: Modify xfrm_ipcomp code to use new per-cpu helpers Seth Jennings

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=1323284350-13784-2-git-send-email-sjenning@linux.vnet.ibm.com \
    --to=sjenning@linux.vnet.ibm.com \
    --cc=brking@linux.vnet.ibm.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rcj@linux.vnet.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).