linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Leonardo Brás" <leobras@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/1] crypto/pcrypt: Do not use isolated CPUs for callback
Date: Tue, 11 Oct 2022 15:20:39 -0300	[thread overview]
Message-ID: <3d6d47035f8897542a4786eef5a6b8885f4caaf0.camel@redhat.com> (raw)
In-Reply-To: <b23b08274ccff99fb341ea272e968f72c2e289ce.camel@redhat.com>

On Fri, 2022-10-07 at 18:42 -0300, Leonardo Brás wrote:
> On Wed, 2022-10-05 at 09:57 -0300, Marcelo Tosatti wrote:
> > On Tue, Oct 04, 2022 at 03:25:37AM -0300, Leonardo Bras wrote:
> > > Currently pcrypt_aead_init_tfm() will pick callback cpus (ctx->cb_cpu)
> > > from any online cpus. Later padata_reorder() will queue_work_on() the
> > > chosen cb_cpu.
> > > 
> > > This is undesired if the chosen cb_cpu is listed as isolated (i.e. using
> > > isolcpus=... kernel parameter), since the work queued will interfere with
> > > the workload on the isolated cpu.
> > > 
> > > Make sure isolated cpus are not used for pcrypt.
> > > 
> > > Signed-off-by: Leonardo Bras <leobras@redhat.com>
> > > ---
> > >  crypto/pcrypt.c | 10 +++++++---
> > >  1 file changed, 7 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
> > > index 9d10b846ccf73..9017d08c91a8d 100644
> > > --- a/crypto/pcrypt.c
> > > +++ b/crypto/pcrypt.c
> > > @@ -16,6 +16,7 @@
> > >  #include <linux/kobject.h>
> > >  #include <linux/cpu.h>
> > >  #include <crypto/pcrypt.h>
> > > +#include <linux/sched/isolation.h>
> > >  
> > >  static struct padata_instance *pencrypt;
> > >  static struct padata_instance *pdecrypt;
> > > @@ -175,13 +176,16 @@ static int pcrypt_aead_init_tfm(struct crypto_aead *tfm)
> > >  	struct pcrypt_instance_ctx *ictx = aead_instance_ctx(inst);
> > >  	struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(tfm);
> > >  	struct crypto_aead *cipher;
> > > +	struct cpumask non_isolated;
> > > +
> > > +	cpumask_and(&non_isolated, cpu_online_mask, housekeeping_cpumask(HK_TYPE_DOMAIN));
> > 
> > Since certain systems do not use isolcpus=domain, so please use a flag
> > that is setup by nohz_full=, for example HK_FLAG_MISC:
> > 
> > static int __init housekeeping_nohz_full_setup(char *str)
> > {
> >         unsigned long flags;
> > 
> >         flags = HK_FLAG_TICK | HK_FLAG_WQ | HK_FLAG_TIMER | HK_FLAG_RCU |
> >                 HK_FLAG_MISC | HK_FLAG_KTHREAD;
> > 
> >         return housekeeping_setup(str, flags);
> > }
> > __setup("nohz_full=", housekeeping_nohz_full_setup);
> 
> Oh, sure. 
> Since we are talking about WorkQueues, I think it makes sense to pick
> HK_FLAG_WQ. 
> 
> > 
> > Also, shouldnt you use cpumask_t ?/
> 
> Yeah, I think so. 
> I was quick to choose the 'struct cpumask' because all functions would operate
> in this variable type, but yeah, I think it makes sense to have this variable
> being opaque here.

In fact, it seems neither 'struct cpumask' nor 'cpumask_t' are recommended to be
used allocated in the stack, due to the large size it can get (up to 1kB). 

At include/linux/cpumask.h we have:
'cpumask_var_t: struct cpumask for stack usage'
which should work better at least for init functions like this.

In other cases, I see 'static cpumask_t' being used to avoid the allocation
overhead, but it's probably due to the functions being called in very specific
scenarios. It could mean trouble if multiple cpus try to use it at once.

What do you recommend on it?

Best regards,
Leo

> 
> > 
> > Looks good otherwise.
> > 
> > Thanks!
> 
> Thank you for reviewing! 
> 
> Leo
> 
> > 
> > 
> > >  
> > >  	cpu_index = (unsigned int)atomic_inc_return(&ictx->tfm_count) %
> > > -		    cpumask_weight(cpu_online_mask);
> > > +		    cpumask_weight(&non_isolated);
> > >  
> > > -	ctx->cb_cpu = cpumask_first(cpu_online_mask);
> > > +	ctx->cb_cpu = cpumask_first(&non_isolated);
> > >  	for (cpu = 0; cpu < cpu_index; cpu++)
> > > -		ctx->cb_cpu = cpumask_next(ctx->cb_cpu, cpu_online_mask);
> > > +		ctx->cb_cpu = cpumask_next(ctx->cb_cpu, &non_isolated);
> > >  
> > >  	cipher = crypto_spawn_aead(&ictx->spawn);
> > >  
> > > -- 
> > > 2.37.3
> > > 
> > > 
> > 
> 


  reply	other threads:[~2022-10-11 18:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04  6:25 [PATCH v1 1/1] crypto/pcrypt: Do not use isolated CPUs for callback Leonardo Bras
2022-10-05 12:57 ` Marcelo Tosatti
2022-10-07 21:42   ` Leonardo Brás
2022-10-11 18:20     ` Leonardo Brás [this message]
2022-11-01 17:35       ` Marcelo Tosatti
2022-11-02  2:09         ` Leonardo Bras Soares Passos

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=3d6d47035f8897542a4786eef5a6b8885f4caaf0.camel@redhat.com \
    --to=leobras@redhat.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=steffen.klassert@secunet.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).