Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9417353pxu; Mon, 28 Dec 2020 15:49:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+bXePqMPwXD31tmBgyMe0NGjxzz6WEBSPgahqUVE6MJ/fiMsbwEPEwMqHQCFKX3rCLMGk X-Received: by 2002:aa7:dd05:: with SMTP id i5mr44089151edv.223.1609199380953; Mon, 28 Dec 2020 15:49:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609199380; cv=none; d=google.com; s=arc-20160816; b=PV+WRzzDk7HTyYq0+VKzgi0zwrPoGlNy1mZy3N3igPw50mc3smxX6kMPXOFG6bCD21 zFh0FfELUTII8SAhmWTKJeOMj7FQR2YySUPw8EpDSeaeSWuJBmzCV37+Os0sbi9tPhNN iW8DXg893bRR+A5FMgwVnn85ueIhrfEbLaAf4WPCChxjlvImOs2Bisk5xCR9op/n6Od8 KY7pZIgJizDyAYOk/6tvT7vp6gUzo+MPb8oPB4Dus3DLMqpwPltzOqAiq90VH24lAoVt bHB7/ntpR+XrDZha6v/rnn5PoOJz1cmsmfGn71dcw186bbIn4J6PxwXHwT1LL0mwbwRL 5uaQ== 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=ievshYLV+R8msMBRokL57ZWfn2hvXw3yfCL+Dz6nPIo=; b=isYlOZpwMo9E0vyNnGBk63jXFJz/3WLCYue0BtBFSRggCYUdfH4iartE59qYc/maw7 ICgjtoFrGaIyjHD9hEeq2zUnCz9GJnl+y/LgV6NwLFh+8GWrh6mYbIKD/a9UxIfRR4Nv 0yaRLWKmg7bm8ode51ztvq4du2RQaL9MU8qVRTCL/VN02qW7IlMgKG4aIilAuKSGbsT3 vsszzTOGZ7H3Tqt4tq4jL4D3O8289IN+/7onvGUHYPAXSRPN5gP81T3fhAwaZrxlew8b +T2Znj8ttfoRKfTwQYQbMHCrU8v9vlwxfiz1hzRDwoKvQs29L/Zc0FzUMb+QbCDtK7dY cIjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PUFSepV9; 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 w1si21471008edl.297.2020.12.28.15.49.19; Mon, 28 Dec 2020 15:49:40 -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=PUFSepV9; 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 S2504620AbgL1OiL (ORCPT + 99 others); Mon, 28 Dec 2020 09:38:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:39864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504142AbgL1OcJ (ORCPT ); Mon, 28 Dec 2020 09:32:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 769CF2063A; Mon, 28 Dec 2020 14:31:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165914; bh=9ssjzMwYka8fIx+hvUzcJBCprK54wHmDvbZlEVUhIHk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PUFSepV9C0u0WxEpmIolWSDO4kFx37ZhgJERZpDBba7/79P6AYOemTI1LJ1D1GqEZ Yd9vzA8WkEjll5Qpi714ONLlYLQtWi4mVEPK9zIY7lT7GaOJeroDf+FrwDbT1HjLm0 gqVPklKAQvyj5RdW+N6oI/+4oKSsqyAZxlP/ORHw= 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 5.10 699/717] xen/xenbus: Count pending messages for each watch Date: Mon, 28 Dec 2020 13:51:37 +0100 Message-Id: <20201228125054.474872245@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 @@ -711,6 +711,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 @@ -768,6 +769,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); @@ -817,11 +820,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); @@ -868,7 +874,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; @@ -883,13 +888,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 @@ -61,6 +61,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.