From: Mete Durlu <meted@linux.ibm.com>
To: Ilya Leoshkevich <iii@linux.ibm.com>,
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>,
Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: linux-s390@vger.kernel.org
Subject: Re: [PATCH v5] s390/diag204: Add common diag204 interface with caching
Date: Fri, 6 Nov 2026 12:12:54 +0100 [thread overview]
Message-ID: <6345f71e-8532-4a58-b991-8f2a0efe1fea@linux.ibm.com> (raw)
In-Reply-To: <97ebb3cb-ce2f-4695-b4bd-8da2dcecf873@linux.ibm.com>
On 06/11/2026 00:06, Ilya Leoshkevich wrote:
Hi Ilya,
>
> [...]
>
>> +static void diag204_work_fn(struct work_struct *work)
>> +{
>> + mutex_lock(&diag204_mutex);
>
> Consider using guard(mutex)(&diag204_mutex).
Right, that would make the work_fn much simpler;
{
guard(mutex)(&diag204_mutex);
if (diag204_is_cache_valid()) {
mod_delayed_work(system_dfl_wq, &diag204_work,
DIAG204_WORK_DELAY);
return;
}
diag204_free_buffer(diag204_cache_info.buf);
diag204_cache_info.expires = 0;
diag204_cache_info.buf = NULL;
}
I'll incorporate that!
> [...]
>
>> +/**
>> + * diag204_store() - Store diag204 data
>> + * @buf: Diag204 data buffer allocated using
>> + * diag204_allocate_buffer() or a page aligned,
>> zeroed buffer
>> + * with a size acquired from diag204_get_buf_size().
>> + * @allow_busy: Allow diag204 to return -EBUSY instead of
>> blocking and
>> + * return early when there is a concurrent updater.
>> + *
>> + * Diag204 queries CPU utilization data from the hypervisor. Per CPU
>> + * utilization information is returned either only for the current guest
>> + * or, with authorization for all guests configured.
>> + *
>> + * Context: diag204_store() can sleep and holds diag204_mutex to
>> serialize
>> + * diag204 cache access.
>> + *
>> + * Return:
>> + * * 0 on success
>> + * * -EOPNOTSUPP diag204 is not supported
>> + * * -EINVAL if @buf is NULL
>> + * * -ENOMEM if the temporary buffer could not be allocated
>> + * * -EBUSY if @allow_busy is set and diag204 or a concurrent cache
>> update
>> + * is busy
>> + * * -EINTR if interrupted by a signal
>> + */
>> +int diag204_store(void *buf, bool allow_busy)
>> +{
>> + int rc;
>> +
>> + if (!diag204_is_available())
>> + return -EOPNOTSUPP;
>> + if (!buf)
>> + return -EINVAL;
>> + rc = 0;
>> + if (allow_busy) {
>> + if (!mutex_trylock(&diag204_mutex))
>> + return -EBUSY;
>> + } else {
>> + if (mutex_lock_killable(&diag204_mutex))
>> + return -EINTR;
>> + }
>> + if (diag204_is_cache_valid())
>> + goto copy;
>> + rc = diag204_update_cache(allow_busy);
>> + if (rc)
>> + goto out;
>> +copy:
>> + memcpy(buf, diag204_cache_info.buf, diag204_get_buf_size());
>
> I wonder if it would make sense to return the buffer address and keep
> the lock. Most callers should not take more time than memcpy() and would
> benefit from simplified buffer management. Others can do memcpy()
> themselves. __acquires() and __releases() annotations should help with
> keeping such solution maintainable.
IMO keeping this self contained would keep the lock management
burden away from the callers while also preventing duplicate
lock release chunks and logic.
__acquires() and __releases() should help indicate any misuse
but I am not sure if it's worth it.
One objective of this patch series is to simplify the diag204
interface, so I would like to keep moving forward with the current
approach if there is no big reason against it.
Thanks!
next prev parent reply other threads:[~2026-11-06 11:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 9:24 [PATCH v5] s390/diag204: Add common diag204 interface with caching Mete Durlu
2026-11-05 16:04 ` sashiko-bot
2026-11-05 23:06 ` Ilya Leoshkevich
2026-11-06 11:12 ` Mete Durlu [this message]
2026-11-06 15:38 ` Heiko Carstens
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=6345f71e-8532-4a58-b991-8f2a0efe1fea@linux.ibm.com \
--to=meted@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=sumanthk@linux.ibm.com \
--cc=svens@linux.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.