From: "Jürgen Groß" <jgross@suse.com>
To: SeongJae Park <sjpark@amazon.com>, stable@vger.kernel.org
Cc: SeongJae Park <sjpark@amazon.de>,
doebel@amazon.de, aams@amazon.de, mku@amazon.de, julien@xen.org,
wipawel@amazon.de, linux-kernel@vger.kernel.org,
Author Redacted <security@xen.org>
Subject: Re: [PATCH 4/5] xen/xenbus: Count pending messages for each watch
Date: Thu, 17 Dec 2020 15:50:34 +0100 [thread overview]
Message-ID: <76711b5d-4166-19ff-e817-694675051f90@suse.com> (raw)
In-Reply-To: <20201217081727.8253-5-sjpark@amazon.com>
[-- Attachment #1.1.1: Type: text/plain, Size: 3509 bytes --]
On 17.12.20 09:17, SeongJae Park wrote:
> From: SeongJae Park <sjpark@amazon.de>
>
> This commit adds a counter of pending messages for each watch in the
> struct. It is used to skip unnecessary pending messages lookup in
> 'unregister_xenbus_watch()'. It could also be used in 'will_handle'
> callback.
>
> This is part of XSA-349
>
> This is upstream commit 3dc86ca6b4c8cfcba9da7996189d1b5a358a94fc
>
> Cc: stable@vger.kernel.org
> Signed-off-by: SeongJae Park <sjpark@amazon.de>
> Reported-by: Michael Kurth <mku@amazon.de>
> Reported-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
> Signed-off-by: Author Redacted <security@xen.org>
> Reviewed-by: Juergen Gross <jgross@suse.com>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> drivers/xen/xenbus/xenbus_xs.c | 30 ++++++++++++++++++------------
> include/xen/xenbus.h | 2 ++
> 2 files changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c
> index 0ea1c259f2f1..420d478e1708 100644
> --- a/drivers/xen/xenbus/xenbus_xs.c
> +++ b/drivers/xen/xenbus/xenbus_xs.c
> @@ -701,6 +701,8 @@ int register_xenbus_watch(struct xenbus_watch *watch)
>
> sprintf(token, "%lX", (long)watch);
>
> + watch->nr_pending = 0;
> +
I'm missing the incrementing of nr_pending, which was present in the
upstream patch.
Juergen
> down_read(&xs_state.watch_mutex);
>
> spin_lock(&watches_lock);
> @@ -750,12 +752,15 @@ void unregister_xenbus_watch(struct xenbus_watch *watch)
>
> /* Cancel pending watch events. */
> spin_lock(&watch_events_lock);
> - list_for_each_entry_safe(msg, tmp, &watch_events, list) {
> - if (msg->u.watch.handle != watch)
> - continue;
> - list_del(&msg->list);
> - kfree(msg->u.watch.vec);
> - kfree(msg);
> + if (watch->nr_pending) {
> + list_for_each_entry_safe(msg, tmp, &watch_events, list) {
> + if (msg->u.watch.handle != watch)
> + continue;
> + list_del(&msg->list);
> + kfree(msg->u.watch.vec);
> + kfree(msg);
> + }
> + watch->nr_pending = 0;
> }
> spin_unlock(&watch_events_lock);
>
> @@ -802,7 +807,6 @@ void xs_suspend_cancel(void)
>
> static int xenwatch_thread(void *unused)
> {
> - struct list_head *ent;
> struct xs_stored_msg *msg;
>
> for (;;) {
> @@ -815,13 +819,15 @@ static int xenwatch_thread(void *unused)
> mutex_lock(&xenwatch_mutex);
>
> spin_lock(&watch_events_lock);
> - ent = watch_events.next;
> - if (ent != &watch_events)
> - list_del(ent);
> + msg = list_first_entry_or_null(&watch_events,
> + struct xs_stored_msg, list);
> + if (msg) {
> + list_del(&msg->list);
> + msg->u.watch.handle->nr_pending--;
> + }
> spin_unlock(&watch_events_lock);
>
> - if (ent != &watch_events) {
> - msg = list_entry(ent, struct xs_stored_msg, list);
> + if (msg) {
> msg->u.watch.handle->callback(
> msg->u.watch.handle,
> (const char **)msg->u.watch.vec,
> diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
> index 1772507dc2c9..ed9e7e3307b7 100644
> --- a/include/xen/xenbus.h
> +++ b/include/xen/xenbus.h
> @@ -58,6 +58,8 @@ struct xenbus_watch
> /* Path being watched. */
> const char *node;
>
> + unsigned int nr_pending;
> +
> /*
> * Called just before enqueing new event while a spinlock is held.
> * The event will be discarded if this callback returns false.
>
[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
next prev parent reply other threads:[~2020-12-17 14:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-17 8:17 [PATCH 0/5] Backport of patch series for stable 4.4 branch SeongJae Park
2020-12-17 8:17 ` [PATCH 1/5] xen/xenbus: Allow watches discard events before queueing SeongJae Park
2020-12-17 8:17 ` [PATCH 2/5] xen/xenbus: Add 'will_handle' callback support in xenbus_watch_path() SeongJae Park
2020-12-17 13:04 ` SeongJae Park
2020-12-17 8:17 ` [PATCH 3/5] xen/xenbus/xen_bus_type: Support will_handle watch callback SeongJae Park
2020-12-17 8:17 ` [PATCH 4/5] xen/xenbus: Count pending messages for each watch SeongJae Park
2020-12-17 14:50 ` Jürgen Groß [this message]
2020-12-17 15:19 ` SeongJae Park
2021-01-05 11:01 [PATCH 0/5] Backport of patch series for stable 4.9 branch SeongJae Park
2021-01-05 11:01 ` [PATCH 4/5] xen/xenbus: Count pending messages for each watch SeongJae Park
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=76711b5d-4166-19ff-e817-694675051f90@suse.com \
--to=jgross@suse.com \
--cc=aams@amazon.de \
--cc=doebel@amazon.de \
--cc=julien@xen.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mku@amazon.de \
--cc=security@xen.org \
--cc=sjpark@amazon.com \
--cc=sjpark@amazon.de \
--cc=stable@vger.kernel.org \
--cc=wipawel@amazon.de \
/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
Powered by JetHome