Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9231465pxu; Mon, 28 Dec 2020 09:58:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwu/0m0Xx3UcX2QAtGaaKEB3/qVoE5fTFoTcpsDQtkXtmRlhy1fZh10o4jlDql4ZTMTLzN2 X-Received: by 2002:a17:907:444f:: with SMTP id on23mr43803599ejb.300.1609178294447; Mon, 28 Dec 2020 09:58:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609178294; cv=none; d=google.com; s=arc-20160816; b=noixXnr9o3IoX7kQyRSA4Ebk8yLPEqWcKV/MIUnv/O6Iv00UMBeBDXmj/xp1YBwVjk 2fyYdSDapNwP8tWSoBFwhBc06wsCLcuCBaQjVgmxwhOmQqGhwLBJphqCHaBjjJF7v/uz h+PDYf57CdxOK0bzYIco1kuyENjEdMR5dsVWG39U8eubfzA5gd7+WXRVUnoslvMMP8aM FOWY3j++gCbkDbUMjlSvy/7MX/U2UFyEX7+8/hfEsY1MUBCwNo8VZNcdKMAH6jtb+Ty4 dzjkWPIzFRwdosRZOfVXW4AaGNWm3NJK04Ur8KZJeiu95qM5TlVB25KHtY10EXnN40Z0 yu0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZtFp5pPM2geM9AuigXnJxLKmorkm91RQc2M73xl8rPE=; b=vuI6fEaaj6Z3e/IxBa/LAM1uieUHZyK73OMq5JK91CSzO0JepKlcsdW+2K5BEv2f+J LfQeisMNL6FnNJtxqZXwdaCSQ+qUusc5TkeGqllaA4e56lW2XiLkbLncITqnrBzgbC13 NxNRPaNTbM4QNtZFDMpQ/TAgK3PqoSRJyjZaKQs1qGOVS6+6G+tx6R/C+pqi1Bw5LuN4 kBmFN65y/ktHRrPzyGjZmQ4MQ00w0nbRXehEnMD4abiEOPGwwAXd1EV2zY6eUKA2FRYF Yf9HgfULSRuXpLoBPvWOWT3zfu/MXc4li86N/XgL5GcbL6QUjy4wNSWU8qUeIvtg/dpn cH3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cXNeh5E5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hd41si20494680ejc.168.2020.12.28.09.57.52; Mon, 28 Dec 2020 09:58:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cXNeh5E5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732715AbgL1NTR (ORCPT + 99 others); Mon, 28 Dec 2020 08:19:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:47540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732454AbgL1NTO (ORCPT ); Mon, 28 Dec 2020 08:19:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD32C206ED; Mon, 28 Dec 2020 13:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161538; bh=fxEV+T+67ehhJY5BiibI8qpWzIOYTjkTKEPR5YQIsx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cXNeh5E5WBqesT2Q7mWrYD5g+XOgZD6gS29eiujox16CyHBSpGRSTN1QI6VK96zQm 1A9DSPzrSD2x5JVlJMdYwr0Ia8L8GaZcYTS+Kf3xME5C4wjiIHPsJB4UebOHLSkxiK IA/s9ga4FkZII5bL+Av2Sj2z2nfB6KtQoDLLv/5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, SeongJae Park , Michael Kurth , Pawel Wieczorkiewicz , Juergen Gross Subject: [PATCH 4.14 239/242] xen/xenbus: Count pending messages for each watch Date: Mon, 28 Dec 2020 13:50:44 +0100 Message-Id: <20201228124916.450261118@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park commit 3dc86ca6b4c8cfcba9da7996189d1b5a358a94fc upstream. 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 Cc: stable@vger.kernel.org Signed-off-by: SeongJae Park Reported-by: Michael Kurth Reported-by: Pawel Wieczorkiewicz Reviewed-by: Juergen Gross Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- drivers/xen/xenbus/xenbus_xs.c | 29 ++++++++++++++++++----------- include/xen/xenbus.h | 2 ++ 2 files changed, 20 insertions(+), 11 deletions(-) --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -706,6 +706,7 @@ int xs_watch_msg(struct xs_watch_event * event->path, event->token))) { spin_lock(&watch_events_lock); list_add_tail(&event->list, &watch_events); + event->handle->nr_pending++; wake_up(&watch_events_waitq); spin_unlock(&watch_events_lock); } else @@ -763,6 +764,8 @@ int register_xenbus_watch(struct xenbus_ sprintf(token, "%lX", (long)watch); + watch->nr_pending = 0; + down_read(&xs_watch_rwsem); spin_lock(&watches_lock); @@ -812,11 +815,14 @@ void unregister_xenbus_watch(struct xenb /* Cancel pending watch events. */ spin_lock(&watch_events_lock); - list_for_each_entry_safe(event, tmp, &watch_events, list) { - if (event->handle != watch) - continue; - list_del(&event->list); - kfree(event); + if (watch->nr_pending) { + list_for_each_entry_safe(event, tmp, &watch_events, list) { + if (event->handle != watch) + continue; + list_del(&event->list); + kfree(event); + } + watch->nr_pending = 0; } spin_unlock(&watch_events_lock); @@ -863,7 +869,6 @@ void xs_suspend_cancel(void) static int xenwatch_thread(void *unused) { - struct list_head *ent; struct xs_watch_event *event; xenwatch_pid = current->pid; @@ -878,13 +883,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); + event = list_first_entry_or_null(&watch_events, + struct xs_watch_event, list); + if (event) { + list_del(&event->list); + event->handle->nr_pending--; + } spin_unlock(&watch_events_lock); - if (ent != &watch_events) { - event = list_entry(ent, struct xs_watch_event, list); + if (event) { event->handle->callback(event->handle, event->path, event->token); kfree(event); --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -59,6 +59,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.