[RESEND PATCH 0/2] crypto: sunxi-ss: fix 64-bit compilation

STALE3923d

Revision resend of 2 in this series.

6 messages, 3 authors, 2016-01-18 · open the first message on its own page

[RESEND PATCH 0/2] crypto: sunxi-ss: fix 64-bit compilation

From: Andre Przywara <andre.przywara@arm.com>
Date: 2016-01-08 11:24:33

(resending to add linux-crypto, patches unchanged)

Hi,

these two patches provide a different approach to an issue I tried
to fix lately [1].
Instead of casting everything I now promote local types to size_t, so
that the min3() arguments naturally match in type.
As size_t is defined as "unsigned int" on 32-bit architectures
anyway, that actually does not change anything there, but instead
provides a clean approach to get it compiled for arm64.

I split this up because 1/2 seems much cleaner to me than 2/2, so we
can have a separate discussion/merge process on this.

Cheers,
Andre.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/395689.html

Andre Przywara (2):
  crypto: sunxi-ss-cipher: promote variables to match types in min3()
    calls
  crypto: sunxi-ss-hash: promote variables to match types in min3()
    calls

 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 20 ++++++++++----------
 drivers/crypto/sunxi-ss/sun4i-ss-hash.c   | 12 ++++++------
 drivers/crypto/sunxi-ss/sun4i-ss.h        |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)

-- 
2.6.4

[RESEND PATCH 1/2] crypto: sunxi-ss-cipher: promote variables to match types in min3() calls

From: Andre Przywara <andre.przywara@arm.com>
Date: 2016-01-08 11:24:36

(resending to add linux-crypto, patch unchanged)

The min3() macro expects all arguments to be of the same type (or
size at least).
Change the type of some local variables in sun4i-ss-cipher.c to
size_t to match the type used in some generic structures we
compare against.
That shouldn't change anything for 32-bit (as size_t is unsigned int
there anyway), but allows compilation for 64-bit architectures.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
index a19ee12..707f30f 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
@@ -25,13 +25,13 @@ static int sun4i_ss_opti_poll(struct ablkcipher_request *areq)
 	struct sun4i_cipher_req_ctx *ctx = ablkcipher_request_ctx(areq);
 	u32 mode = ctx->mode;
 	/* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */
-	u32 rx_cnt = SS_RX_DEFAULT;
-	u32 tx_cnt = 0;
+	size_t rx_cnt = SS_RX_DEFAULT;
+	size_t tx_cnt = 0;
 	u32 spaces;
 	u32 v;
 	int i, err = 0;
-	unsigned int ileft = areq->nbytes;
-	unsigned int oleft = areq->nbytes;
+	size_t ileft = areq->nbytes;
+	size_t oleft = areq->nbytes;
 	unsigned int todo;
 	struct sg_mapping_iter mi, mo;
 	unsigned int oi, oo; /* offset for in and out */
@@ -134,13 +134,13 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq)
 	struct sun4i_cipher_req_ctx *ctx = ablkcipher_request_ctx(areq);
 	u32 mode = ctx->mode;
 	/* when activating SS, the default FIFO space is SS_RX_DEFAULT(32) */
-	u32 rx_cnt = SS_RX_DEFAULT;
-	u32 tx_cnt = 0;
+	size_t rx_cnt = SS_RX_DEFAULT;
+	size_t tx_cnt = 0;
 	u32 v;
 	u32 spaces;
 	int i, err = 0;
-	unsigned int ileft = areq->nbytes;
-	unsigned int oleft = areq->nbytes;
+	size_t ileft = areq->nbytes;
+	size_t oleft = areq->nbytes;
 	unsigned int todo;
 	struct sg_mapping_iter mi, mo;
 	unsigned int oi, oo;	/* offset for in and out */
@@ -148,7 +148,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq)
 	char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
 	unsigned int ob = 0;	/* offset in buf */
 	unsigned int obo = 0;	/* offset in bufo*/
-	unsigned int obl = 0;	/* length of data in bufo */
+	size_t obl = 0;	/* length of data in bufo */
 
 	if (areq->nbytes == 0)
 		return 0;
@@ -251,7 +251,7 @@ static int sun4i_ss_cipher_poll(struct ablkcipher_request *areq)
 		spaces = readl(ss->base + SS_FCSR);
 		rx_cnt = SS_RXFIFO_SPACES(spaces);
 		tx_cnt = SS_TXFIFO_SPACES(spaces);
-		dev_dbg(ss->dev, "%x %u/%u %u/%u cnt=%u %u/%u %u/%u cnt=%u %u %u\n",
+		dev_dbg(ss->dev, "%x %u/%zu %zu/%u cnt=%zu %u/%zu %zu/%u cnt=%zu %u %u\n",
 			mode,
 			oi, mi.length, ileft, areq->nbytes, rx_cnt,
 			oo, mo.length, oleft, areq->nbytes, tx_cnt,
-- 
2.6.4

[RESEND PATCH 2/2] crypto: sunxi-ss-hash: promote variables to match types in min3() calls

From: Andre Przywara <andre.przywara@arm.com>
Date: 2016-01-08 11:24:39

(resending to add linux-crypto, patch unchanged)

The min3() macro expects all arguments to be of the same type (or
size at least).
Change the type of some local variables in sun4i-ss-hash.c to
size_t to match the type used in some generic structures we
compare against.
That shouldn't change anything for 32-bit (as size_t is unsigned int
there anyway), but allows compilation for 64-bit architectures.
There are two casts still necessary, because we can't change the type
in a generic structure.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/crypto/sunxi-ss/sun4i-ss-hash.c | 12 ++++++------
 drivers/crypto/sunxi-ss/sun4i-ss.h      |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
index ff80314..c0384f1 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
@@ -170,7 +170,7 @@ int sun4i_hash_update(struct ahash_request *areq)
 	struct sun4i_ss_ctx *ss = op->ss;
 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
 	unsigned int in_i = 0; /* advancement in the current SG */
-	unsigned int end;
+	size_t end;
 	/*
 	 * end is the position when we need to stop writing to the device,
 	 * to be compared to i
@@ -181,7 +181,7 @@ int sun4i_hash_update(struct ahash_request *areq)
 	size_t copied = 0;
 	struct sg_mapping_iter mi;
 
-	dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x wl=%u h0=%0x",
+	dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x wl=%zu h0=%0x",
 		__func__, crypto_tfm_alg_name(areq->base.tfm),
 		op->byte_count, areq->nbytes, op->mode,
 		op->len, op->hash[0]);
@@ -206,7 +206,7 @@ int sun4i_hash_update(struct ahash_request *areq)
 	end = ((areq->nbytes + op->len) / 64) * 64 - op->len;
 
 	if (end > areq->nbytes || areq->nbytes - end > 63) {
-		dev_err(ss->dev, "ERROR: Bound error %u %u\n",
+		dev_err(ss->dev, "ERROR: Bound error %zu %u\n",
 			end, areq->nbytes);
 		return -EINVAL;
 	}
@@ -266,7 +266,7 @@ int sun4i_hash_update(struct ahash_request *areq)
 		}
 		if (mi.length - in_i > 3 && i < end) {
 			/* how many bytes we can read from current SG */
-			in_r = min3(mi.length - in_i, areq->nbytes - i,
+			in_r = min3(mi.length - in_i, (size_t)areq->nbytes - i,
 				    ((mi.length - in_i) / 4) * 4);
 			/* how many bytes we can write in the device*/
 			todo = min3((u32)(end - i) / 4, rx_cnt, (u32)in_r / 4);
@@ -289,7 +289,7 @@ int sun4i_hash_update(struct ahash_request *areq)
 	if ((areq->nbytes - i) < 64) {
 		while (i < areq->nbytes && in_i < mi.length && op->len < 64) {
 			/* how many bytes we can read from current SG */
-			in_r = min3(mi.length - in_i, areq->nbytes - i,
+			in_r = min3(mi.length - in_i, (size_t)areq->nbytes - i,
 				    64 - op->len);
 			memcpy(op->buf + op->len, mi.addr + in_i, in_r);
 			op->len += in_r;
@@ -352,7 +352,7 @@ int sun4i_hash_final(struct ahash_request *areq)
 	u32 wb = 0;
 	unsigned int nwait, nbw = 0;
 
-	dev_dbg(ss->dev, "%s: byte=%llu len=%u mode=%x wl=%u h=%x",
+	dev_dbg(ss->dev, "%s: byte=%llu len=%u mode=%x wl=%zu h=%x",
 		__func__, op->byte_count, areq->nbytes, op->mode,
 		op->len, op->hash[0]);
 
diff --git a/drivers/crypto/sunxi-ss/sun4i-ss.h b/drivers/crypto/sunxi-ss/sun4i-ss.h
index 8e9c05f..c15fa21 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss.h
+++ b/drivers/crypto/sunxi-ss/sun4i-ss.h
@@ -162,7 +162,7 @@ struct sun4i_req_ctx {
 	u64 byte_count; /* number of bytes "uploaded" to the device */
 	u32 hash[5]; /* for storing SS_IVx register */
 	char buf[64];
-	unsigned int len;
+	size_t len;
 	struct sun4i_ss_ctx *ss;
 };
 
-- 
2.6.4

Re: [RESEND PATCH 0/2] crypto: sunxi-ss: fix 64-bit compilation

From: Corentin LABBE <clabbe.montjoie@gmail.com>
Date: 2016-01-16 20:32:52

Le 08/01/2016 12:24, Andre Przywara a ?crit :
(resending to add linux-crypto, patches unchanged)

Hi,

these two patches provide a different approach to an issue I tried
to fix lately [1].
Instead of casting everything I now promote local types to size_t, so
that the min3() arguments naturally match in type.
As size_t is defined as "unsigned int" on 32-bit architectures
anyway, that actually does not change anything there, but instead
provides a clean approach to get it compiled for arm64.

I split this up because 1/2 seems much cleaner to me than 2/2, so we
can have a separate discussion/merge process on this.

Cheers,
Andre.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/395689.html

Andre Przywara (2):
  crypto: sunxi-ss-cipher: promote variables to match types in min3()
    calls
  crypto: sunxi-ss-hash: promote variables to match types in min3()
    calls

 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 20 ++++++++++----------
 drivers/crypto/sunxi-ss/sun4i-ss-hash.c   | 12 ++++++------
 drivers/crypto/sunxi-ss/sun4i-ss.h        |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)
Hello

Sorry for this late answer.

I am in trouble with those patch, so we have with Andre a long conversation about it.
Basically, sun4i-ss will never be available on 64bits platform. (A64 will have a totally new crypto engine).
So letting it to compile under 64bit arch is only useful when goal is to add COMPILE_TEST for it.
But COMPILE_TEST cannot simply be added with those patch since some arches (x86/x86_64 at least) does not have writesl/readsl available.
The conclusion is that it is simpler to block 64bit build for sun4i-ss.

Regards

LABBE Corentin

Re: [RESEND PATCH 0/2] crypto: sunxi-ss: fix 64-bit compilation

From: Andre Przywara <andre.przywara@arm.com>
Date: 2016-01-18 10:03:38

Hi Corentin,

(CC:ing Boris for the x86 parts)

thanks for looking at this and your answer.

On 16/01/16 20:32, Corentin LABBE wrote:
Le 08/01/2016 12:24, Andre Przywara a ?crit :
quoted
(resending to add linux-crypto, patches unchanged)

Hi,

these two patches provide a different approach to an issue I tried
to fix lately [1].
Instead of casting everything I now promote local types to size_t, so
that the min3() arguments naturally match in type.
As size_t is defined as "unsigned int" on 32-bit architectures
anyway, that actually does not change anything there, but instead
provides a clean approach to get it compiled for arm64.

I split this up because 1/2 seems much cleaner to me than 2/2, so we
can have a separate discussion/merge process on this.

Cheers,
Andre.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/395689.html

Andre Przywara (2):
  crypto: sunxi-ss-cipher: promote variables to match types in min3()
    calls
  crypto: sunxi-ss-hash: promote variables to match types in min3()
    calls

 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 20 ++++++++++----------
 drivers/crypto/sunxi-ss/sun4i-ss-hash.c   | 12 ++++++------
 drivers/crypto/sunxi-ss/sun4i-ss.h        |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)
Hello

Sorry for this late answer.

I am in trouble with those patch, so we have with Andre a long conversation about it.
Basically, sun4i-ss will never be available on 64bits platform. (A64 will have a totally new crypto engine).
So letting it to compile under 64bit arch is only useful when goal is to add COMPILE_TEST for it.
OK, but actually I don't see the strict requirement for having
COMPILE_TEST here. Usually those warnings point to portability issues in
the code and should be fixed, regardless of it being usable for a
particular architecture or not. Since it got enabled with ARCH_SUNXI on
arm64 without further ado, I took this as a sufficient reason to fix
those issues.

But I see your point in it being useless outside of arm(32) (unless
Allwinner comes up with a ARMv8 SoC using the "old" crypto engine ;-)
But COMPILE_TEST cannot simply be added with those patch since some arches (x86/x86_64 at least) does not have writesl/readsl available.
So for the records (and interested x86 readers):
The sunxi-ss driver uses writesl/readsl, which _are_ defined in
include/asm-generic/io.h. But x86 does not include this header (probably
for historic reasons). So I added the #include in
arch/x86/include/asm/io.h, this required to dummy define a lot of
implemented functions, like:
#define readb readb
basically for all MMIO and IO port accessors. After that it worked, I
could use COMPILE_TEST on the driver and found the same issues as with
arm64 (which were fixed by my patch).

Now adding a number of hideous #defines to a core header in an unrelated
architecture to enable COMPILE_TEST for a single driver seems a bit of a
stretch to me, so I refrain from sending this out - unless people ask
for it.

Boris, do you recall any discussions about asm-generic/io.h on x86 in
the past?
The conclusion is that it is simpler to block 64bit build for sun4i-ss.
OK, I am fine with just adding "&& !64BIT" to the Kconfig entry.
Actually that was my first impulse on finding this issue, but then I
felt it a bit cowardly to paper over the problem instead of fixing it.

So if no-one disagrees, I will include the !64bit dependency in the A64
enablement series I plan to send out later this week.

Cheers,
Andre.

Re: [RESEND PATCH 0/2] crypto: sunxi-ss: fix 64-bit compilation

From: Borislav Petkov <bp@alien8.de>
Date: 2016-01-18 10:15:38

On Mon, Jan 18, 2016 at 10:01:55AM +0000, Andre Przywara wrote:
Hi Corentin,

(CC:ing Boris for the x86 parts)

thanks for looking at this and your answer.

On 16/01/16 20:32, Corentin LABBE wrote:
quoted
Le 08/01/2016 12:24, Andre Przywara a ?crit :
quoted
(resending to add linux-crypto, patches unchanged)

Hi,

these two patches provide a different approach to an issue I tried
to fix lately [1].
Instead of casting everything I now promote local types to size_t, so
that the min3() arguments naturally match in type.
As size_t is defined as "unsigned int" on 32-bit architectures
anyway, that actually does not change anything there, but instead
provides a clean approach to get it compiled for arm64.

I split this up because 1/2 seems much cleaner to me than 2/2, so we
can have a separate discussion/merge process on this.

Cheers,
Andre.

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/395689.html

Andre Przywara (2):
  crypto: sunxi-ss-cipher: promote variables to match types in min3()
    calls
  crypto: sunxi-ss-hash: promote variables to match types in min3()
    calls

 drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 20 ++++++++++----------
 drivers/crypto/sunxi-ss/sun4i-ss-hash.c   | 12 ++++++------
 drivers/crypto/sunxi-ss/sun4i-ss.h        |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)
Hello

Sorry for this late answer.

I am in trouble with those patch, so we have with Andre a long conversation about it.
Basically, sun4i-ss will never be available on 64bits platform. (A64 will have a totally new crypto engine).
So letting it to compile under 64bit arch is only useful when goal is to add COMPILE_TEST for it.
OK, but actually I don't see the strict requirement for having
COMPILE_TEST here. Usually those warnings point to portability issues in
the code and should be fixed, regardless of it being usable for a
particular architecture or not. Since it got enabled with ARCH_SUNXI on
arm64 without further ado, I took this as a sufficient reason to fix
those issues.

But I see your point in it being useless outside of arm(32) (unless
Allwinner comes up with a ARMv8 SoC using the "old" crypto engine ;-)
quoted
But COMPILE_TEST cannot simply be added with those patch since some arches (x86/x86_64 at least) does not have writesl/readsl available.
So for the records (and interested x86 readers):
The sunxi-ss driver uses writesl/readsl, which _are_ defined in
include/asm-generic/io.h. But x86 does not include this header (probably
for historic reasons). So I added the #include in
arch/x86/include/asm/io.h, this required to dummy define a lot of
implemented functions, like:
#define readb readb
basically for all MMIO and IO port accessors. After that it worked, I
could use COMPILE_TEST on the driver and found the same issues as with
arm64 (which were fixed by my patch).

Now adding a number of hideous #defines to a core header in an unrelated
architecture to enable COMPILE_TEST for a single driver seems a bit of a
stretch to me, so I refrain from sending this out - unless people ask
for it.

Boris, do you recall any discussions about asm-generic/io.h on x86 in
the past?
Bah, I don't remember what I did last week. :-)

Let's CC tip people. I'm leaving in the rest of the mail for reference.
quoted
The conclusion is that it is simpler to block 64bit build for sun4i-ss.
OK, I am fine with just adding "&& !64BIT" to the Kconfig entry.
Actually that was my first impulse on finding this issue, but then I
felt it a bit cowardly to paper over the problem instead of fixing it.

So if no-one disagrees, I will include the !64bit dependency in the A64
enablement series I plan to send out later this week.

Cheers,
Andre.
-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help