public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Harald Freudenberger <freude@linux.ibm.com>
To: yskelg@gmail.com
Cc: Markus Elfring <Markus.Elfring@web.de>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	MichelleJin <shjy180909@gmail.com>,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	Holger Dengler <dengler@linux.ibm.com>
Subject: Re: [PATCH v2] s390/zcrypt: optimizes memory allocation in online_show()
Date: Tue, 25 Jun 2024 10:27:05 +0200	[thread overview]
Message-ID: <eefcf6fb6c66979c5b4c0a4572d64df6@linux.ibm.com> (raw)
In-Reply-To: <20240624222933.81363-2-yskelg@gmail.com>

On 2024-06-25 00:29, yskelg@gmail.com wrote:
> From: Yunseong Kim <yskelg@gmail.com>
> 
> Make memory allocation more precise (based on maxzqs) by allocating
> memory only for the queues that are truly affected by the online state
> changes.
> 
> Fixes: df6f508c68db ("s390/ap/zcrypt: notify userspace with online,
> config and mode info")
> Link:
> https://lore.kernel.org/linux-s390/your-ad-here.call-01625406648-ext-2488@work.hours/

What is this Link here? It is pointing to a PR for a 5.14 kernel and has 
no relation to this patch.

> Cc: linux-s390@vger.kernel.org
> Signed-off-by: Yunseong Kim <yskelg@gmail.com>
> ---
>  drivers/s390/crypto/zcrypt_card.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/s390/crypto/zcrypt_card.c
> b/drivers/s390/crypto/zcrypt_card.c
> index 050462d95222..2c80be3f2a00 100644
> --- a/drivers/s390/crypto/zcrypt_card.c
> +++ b/drivers/s390/crypto/zcrypt_card.c
> @@ -88,9 +88,10 @@ static ssize_t online_store(struct device *dev,
>  	 * the zqueue objects, we make sure they exist after lock release.
>  	 */
>  	list_for_each_entry(zq, &zc->zqueues, list)
> -		maxzqs++;
> +		if (!!zq->online != !!online)

I don't like this line. It is code duplication from the zcrypt_queue.c 
file
and uses knowledge about the internals of the zqueue which is not 
appropriate
here in zcrypt_card.c. Please note also that usually the total number of
queues attached to a card is in a one digit range. As kcalloc() anyway 
uses
the kmalloc pool which is ordered in powers of two it is unlikely to 
really
spare some memory by only allocating a pointer space for the online 
queues.

> +			maxzqs++;
>  	if (maxzqs > 0)
> -		zq_uelist = kcalloc(maxzqs + 1, sizeof(*zq_uelist), GFP_ATOMIC);
> +		zq_uelist = kcalloc(maxzqs, sizeof(*zq_uelist), GFP_ATOMIC);

Your improvement about removal of the +1 and use the i value later 
instead
of my implementation which uses a NULL as end of list is valid and makes 
sense
to me.

>  	list_for_each_entry(zq, &zc->zqueues, list)
>  		if (zcrypt_queue_force_online(zq, online))
>  			if (zq_uelist) {
> @@ -98,14 +99,11 @@ static ssize_t online_store(struct device *dev,
>  				zq_uelist[i++] = zq;
>  			}
>  	spin_unlock(&zcrypt_list_lock);
> -	if (zq_uelist) {
> -		for (i = 0; zq_uelist[i]; i++) {
> -			zq = zq_uelist[i];
> -			ap_send_online_uevent(&zq->queue->ap_dev, online);
> -			zcrypt_queue_put(zq);
> -		}
> -		kfree(zq_uelist);
> +	while (i--) {
> +		ap_send_online_uevent(&zq->queue->ap_dev, online);
> +		zcrypt_queue_put(zq_uelist[i]);

The content of this while loop is NOT covering the old code. zq is not
set any more and thus the ap_sen_online_uevent() uses a random zq which
is a left over from the list_for_each() loop.

>  	}
> +	kfree(zq_uelist);
> 
>  	return count;
>  }

You sent another patch for the online_store() function with exactly the
same code changes. I would see these changes as one patch and don't want
to have more or less equal changes spread over two patches.

I am sorry, I will not pick this and the online_store() patch.

regards Harald Freudenberger

  reply	other threads:[~2024-06-25  8:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 22:29 [PATCH v2] s390/zcrypt: optimizes memory allocation in online_show() yskelg
2024-06-25  8:27 ` Harald Freudenberger [this message]
2024-06-26  7:55   ` Yunseong Kim

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=eefcf6fb6c66979c5b4c0a4572d64df6@linux.ibm.com \
    --to=freude@linux.ibm.com \
    --cc=Markus.Elfring@web.de \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=dengler@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=shjy180909@gmail.com \
    --cc=svens@linux.ibm.com \
    --cc=yskelg@gmail.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