Re: [PATCH 7/9] s390: Convert from tasklet to BH workqueue

2024-04-08 Thread Harald Freudenberger

On 2024-03-27 17:03, Allen Pais wrote:
The only generic interface to execute asynchronously in the BH context 
is

tasklet; however, it's marked deprecated and has some design flaws. To
replace tasklets, BH workqueue support was recently added. A BH 
workqueue
behaves similarly to regular workqueues except that the queued work 
items

are executed in the BH context.

This patch converts drivers/infiniband/* from tasklet to BH workqueue.

Based on the work done by Tejun Heo 
Branch: https://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git 
for-6.10


Note: Not tested. Please test/review.

Signed-off-by: Allen Pais 
---
...
 drivers/s390/crypto/ap_bus.c   | 24 +++---
 drivers/s390/crypto/ap_bus.h   |  2 +-
 drivers/s390/crypto/zcrypt_msgtype50.c |  2 +-
 drivers/s390/crypto/zcrypt_msgtype6.c  |  4 +--
...


Applied and tested the s390 AP bus and zcrypt part of the patch.
Works fine, a sniff test did not show any problems.
Thanks for your work.

Reviewed-by: Harald Freudenberger 


Re: [PATCH v3] random: handle archrandom with multiple longs

2022-08-01 Thread Harald Freudenberger

On 2022-07-19 15:02, Jason A. Donenfeld wrote:
The archrandom interface was originally designed for x86, which 
supplies

RDRAND/RDSEED for receiving random words into registers, resulting in
one function to generate an int and another to generate a long. 
However,

other architectures don't follow this.

On arm64, the SMCCC TRNG interface can return between 1 and 3 longs. On
s390, the CPACF TRNG interface can return arbitrary amounts, with 32
longs having the same cost as one. On UML, the os_getrandom() interface
can return arbitrary amounts.

So change the api signature to take a "max_longs" parameter designating
the maximum number of longs requested, and then return the number of
longs generated.

Since callers need to check this return value and loop anyway, each 
arch
implementation does not bother implementing its own loop to try again 
to

fill the maximum number of longs. Additionally, all existing callers
pass in a constant max_longs parameter. Taken together, these two 
things

mean that the codegen doesn't really change much for one-word-at-a-time
platforms, while performance is greatly improved on platforms such as
s390.

Cc: Will Deacon 
Cc: Alexander Gordeev 
Cc: Thomas Gleixner 
Cc: H. Peter Anvin 
Cc: Catalin Marinas 
Cc: Borislav Petkov 
Cc: Heiko Carstens 
Cc: Johannes Berg 
Cc: Mark Rutland 
Cc: Harald Freudenberger 
Acked-by: Michael Ellerman 
Signed-off-by: Jason A. Donenfeld 
---
 arch/arm64/include/asm/archrandom.h   | 102 --
 arch/arm64/kernel/kaslr.c |   2 +-
 arch/powerpc/include/asm/archrandom.h |  30 ++--
 arch/powerpc/kvm/book3s_hv.c  |   2 +-
 arch/s390/include/asm/archrandom.h|  29 ++--
 arch/um/include/asm/archrandom.h  |  21 ++
 arch/x86/include/asm/archrandom.h |  41 +--
 arch/x86/kernel/espfix_64.c   |   2 +-
 drivers/char/random.c |  45 
 include/asm-generic/archrandom.h  |  18 +
 include/linux/random.h|  12 +--
 11 files changed, 116 insertions(+), 188 deletions(-)

diff --git a/arch/arm64/include/asm/archrandom.h
b/arch/arm64/include/asm/archrandom.h
index c3b9fa56af67..109e2a4454be 100644
--- a/arch/arm64/include/asm/archrandom.h
+++ b/arch/arm64/include/asm/archrandom.h
@@ -58,7 +58,7 @@ static inline bool __arm64_rndrrs(unsigned long *v)
return ok;
 }

-static inline bool __must_check arch_get_random_long(unsigned long *v)
+static inline size_t __must_check arch_get_random_longs(unsigned long
*v, size_t max_longs)
 {
/*
 * Only support the generic interface after we have detected
@@ -66,27 +66,15 @@ static inline bool __must_check
arch_get_random_long(unsigned long *v)
 * cpufeature code and with potential scheduling between CPUs
 * with and without the feature.
 */
-   if (cpus_have_const_cap(ARM64_HAS_RNG) && __arm64_rndr(v))
-   return true;
-   return false;
+	if (max_longs && cpus_have_const_cap(ARM64_HAS_RNG) && 
__arm64_rndr(v))

+   return 1;
+   return 0;
 }

-static inline bool __must_check arch_get_random_int(unsigned int *v)
+static inline size_t __must_check arch_get_random_seed_longs(unsigned
long *v, size_t max_longs)
 {
-   if (cpus_have_const_cap(ARM64_HAS_RNG)) {
-   unsigned long val;
-
-   if (__arm64_rndr(&val)) {
-   *v = val;
-   return true;
-   }
-   }
-   return false;
-}
-
-static inline bool __must_check arch_get_random_seed_long(unsigned 
long *v)

-{
-   struct arm_smccc_res res;
+   if (!max_longs)
+   return 0;

/*
 * We prefer the SMCCC call, since its semantics (return actual
@@ -95,10 +83,23 @@ static inline bool __must_check
arch_get_random_seed_long(unsigned long *v)
 * (the output of a pseudo RNG freshly seeded by a TRNG).
 */
if (smccc_trng_available) {
-   arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_RND64, 64, &res);
+   struct arm_smccc_res res;
+
+   max_longs = min_t(size_t, 3, max_longs);
+   arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_RND64, max_longs * 64, 
&res);
if ((int)res.a0 >= 0) {
-   *v = res.a3;
-   return true;
+   switch (max_longs) {
+   case 3:
+   *v++ = res.a1;
+   fallthrough;
+   case 2:
+   *v++ = res.a2;
+   fallthrough;
+   case 1:
+   *v++ = res.a3;
+   break;
+   }
+   return max_longs;
}
}

@@ -108,32 +109,9 @@ static inline bool __must_check
arch_get_random_seed_long(unsigned l

Re: [PATCH 6/6] s390x: Mark archrandom.h functions __must_check

2019-10-30 Thread Harald Freudenberger
On 29.10.19 14:18, Richard Henderson wrote:
> On 10/29/19 8:26 AM, Harald Freudenberger wrote:
>> Fine with me, Thanks, reviewed, build and tested.
>> You may add my reviewed-by: Harald Freudenberger 
>> However, will this go into the kernel tree via crypto or s390 subsystem ?
> That's an excellent question.
>
> As an API decision, perhaps going via crypto makes more sense,
> but none of the patches are dependent on one another, so they
> could go through separate architecture trees.
>
> It has been a long time since I have done much kernel work;
> I'm open to suggestions on the subject.
>
>
> r~
Since the change needs to be done in include/linux/random.h
and in parallel with all the arch files in arch/xxx/include/asm/archrandom.h
it should go in one shot. I'd suggest to post the patch series to linux-crypto
and let Herbert Xu handle this.



Re: [PATCH 6/6] s390x: Mark archrandom.h functions __must_check

2019-10-29 Thread Harald Freudenberger
On 28.10.19 22:05, Richard Henderson wrote:
> We cannot use the pointer output without validating the
> success of the random read.
>
> Signed-off-by: Richard Henderson 
> ---
> Cc: Heiko Carstens 
> Cc: Vasily Gorbik 
> Cc: Christian Borntraeger 
> ---
>  arch/s390/include/asm/archrandom.h | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/s390/include/asm/archrandom.h 
> b/arch/s390/include/asm/archrandom.h
> index c67b82dfa558..f3f1ee0a8c38 100644
> --- a/arch/s390/include/asm/archrandom.h
> +++ b/arch/s390/include/asm/archrandom.h
> @@ -33,17 +33,17 @@ static inline bool arch_has_random_seed(void)
>   return false;
>  }
>
> -static inline bool arch_get_random_long(unsigned long *v)
> +static inline bool __must_check arch_get_random_long(unsigned long *v)
>  {
>   return false;
>  }
>
> -static inline bool arch_get_random_int(unsigned int *v)
> +static inline bool __must_check arch_get_random_int(unsigned int *v)
>  {
>   return false;
>  }
>
> -static inline bool arch_get_random_seed_long(unsigned long *v)
> +static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
>  {
>   if (static_branch_likely(&s390_arch_random_available)) {
>   return s390_arch_random_generate((u8 *)v, sizeof(*v));
> @@ -51,7 +51,7 @@ static inline bool arch_get_random_seed_long(unsigned long 
> *v)
>   return false;
>  }
>
> -static inline bool arch_get_random_seed_int(unsigned int *v)
> +static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
>  {
>   if (static_branch_likely(&s390_arch_random_available)) {
>   return s390_arch_random_generate((u8 *)v, sizeof(*v));
Fine with me, Thanks, reviewed, build and tested.
You may add my reviewed-by: Harald Freudenberger 
However, will this go into the kernel tree via crypto or s390 subsystem ?