Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1354346pxu; Thu, 17 Dec 2020 08:07:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb68au2rQWACGNEnisVblPEtYkkAP0gmi7UtWm9C457RnwCC0ZYCb2hmh1ArPkwvtgsxND X-Received: by 2002:a50:e80c:: with SMTP id e12mr38761edn.288.1608221242352; Thu, 17 Dec 2020 08:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608221242; cv=none; d=google.com; s=arc-20160816; b=r/EPlmoXGallPWI8UO4yg0qR0SRQAs/i0yaGkzWEoVLL5AC3fubarc2tJ71M0FAzVl G/ysfgoZURLFu2iXYnAabsoDgkL4pQaWClRrwsSHWkGXlD7qH41JwdE35/ijOvQNJwlh g27RRAO30KDKth66cdNb2cxhPbidP5oE36p9WBuWQBKLEG+BMPo4fV/TcJ7cx7+eM2Al AqFTIQUwT7iVECxEIm5GvnhoD2hoXSGNRNn7ZCq6wRfe8rZ1erpx3RRb8i7q79lqifoQ Ye05Lmdq9LXV0ItqndX2HCxXHcw2x++CDhO+iaF8CTzqDbFkCvbQZ/REgz0N+gLHfv/P yM5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2YmxoZfq/FJgaUjFNGuK4Ht5NlZny6+5b/Pu3VGDsno=; b=bNPEJ3ATxZdsii1dTnBOcJYLm7euwMoA4gF+Le68JYBd4xRquJBn5i1n4gUWp84eOa Dzn+aU5eTCDd67jDMEo3N6acf3HrhHTZhR7jg2hNi7bsxzO0r0ZQzr40fU7btMlk6/JC ZRPbkD+mIVHELpzcMqxb/jFC+S3ymEmgW1Bn6DnRzt3+POW4TflA29s1jMRuj1eKuDYc PvSx5EYHTyn2XpGSKdjpClacW0+7vRpS/e/xYhi6/TCNpTUUd/YDz/vLjTmk8XuiM4Wd JAh6Yf2ukmHIu+EJMmql1qUOzTIpvyegRXDmxGuydbcYcqF5rtOzOBe1so5Sgubi6iiw AUyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=XGko+xkH; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h26si2856151ejq.399.2020.12.17.08.06.59; Thu, 17 Dec 2020 08:07:22 -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=@amazon.com header.s=amazon201209 header.b=XGko+xkH; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729418AbgLQQFX (ORCPT + 99 others); Thu, 17 Dec 2020 11:05:23 -0500 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:11995 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729150AbgLQQFW (ORCPT ); Thu, 17 Dec 2020 11:05:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608221122; x=1639757122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=2YmxoZfq/FJgaUjFNGuK4Ht5NlZny6+5b/Pu3VGDsno=; b=XGko+xkHekPLMbD+4HzFQgYbPt6LfGy5zeC2PcuUECaaqeOCkgI5w43w I2kgH7B5CqXa5KtB7ZWZ7Yt9voU3Xax1oKcFoOBkTr4ESLmwy9kgXLRtA hqgFeO5Jmr3mrlxhYoVCx07C6Ov+GmZq0MWc+a191WPjXGdCC2aFwBMy2 4=; X-IronPort-AV: E=Sophos;i="5.78,428,1599523200"; d="scan'208";a="69745804" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-22cc717f.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 17 Dec 2020 16:04:34 +0000 Received: from EX13D31EUA004.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2a-22cc717f.us-west-2.amazon.com (Postfix) with ESMTPS id 478F5A1CC0; Thu, 17 Dec 2020 16:04:33 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.162.146) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 17 Dec 2020 16:04:27 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , Subject: [PATCH v3 1/5] xen/xenbus: Allow watches discard events before queueing Date: Thu, 17 Dec 2020 17:03:58 +0100 Message-ID: <20201217160402.26303-2-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201217160402.26303-1-sjpark@amazon.com> References: <20201217160402.26303-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.146] X-ClientProxiedBy: EX13D14UWC001.ant.amazon.com (10.43.162.5) To EX13D31EUA004.ant.amazon.com (10.43.165.161) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park If handling logics of watch events are slower than the events enqueue logic and the events can be created from the guests, the guests could trigger memory pressure by intensively inducing the events, because it will create a huge number of pending events that exhausting the memory. This is known as XSA-349. Fortunately, some watch events could be ignored, depending on its handler callback. For example, if the callback has interest in only one single path, the watch wouldn't want multiple pending events. Or, some watches could ignore events to same path. To let such watches to volutarily help avoiding the memory pressure situation, this commit introduces new watch callback, 'will_handle'. If it is not NULL, it will be called for each new event just before enqueuing it. Then, if the callback returns false, the event will be discarded. No watch is using the callback for now, though. This is part of XSA-349 This is upstream commit fed1755b118147721f2c87b37b9d66e62c39b668 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 --- drivers/net/xen-netback/xenbus.c | 2 ++ drivers/xen/xenbus/xenbus_client.c | 1 + drivers/xen/xenbus/xenbus_xs.c | 7 ++++++- include/xen/xenbus.h | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c index 56ebd8267386..23f03af0a2d4 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c @@ -697,12 +697,14 @@ static int xen_register_watchers(struct xenbus_device *dev, struct xenvif *vif) return -ENOMEM; snprintf(node, maxlen, "%s/rate", dev->nodename); vif->credit_watch.node = node; + vif->credit_watch.will_handle = NULL; vif->credit_watch.callback = xen_net_rate_changed; err = register_xenbus_watch(&vif->credit_watch); if (err) { pr_err("Failed to set watcher %s\n", vif->credit_watch.node); kfree(node); vif->credit_watch.node = NULL; + vif->credit_watch.will_handle = NULL; vif->credit_watch.callback = NULL; } return err; diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 266f446ba331..d02d25f784c9 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -120,6 +120,7 @@ int xenbus_watch_path(struct xenbus_device *dev, const char *path, int err; watch->node = path; + watch->will_handle = NULL; watch->callback = callback; err = register_xenbus_watch(watch); diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index ce65591b4168..0ea1c259f2f1 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -903,7 +903,12 @@ static int process_msg(void) spin_lock(&watches_lock); msg->u.watch.handle = find_watch( msg->u.watch.vec[XS_WATCH_TOKEN]); - if (msg->u.watch.handle != NULL) { + if (msg->u.watch.handle != NULL && + (!msg->u.watch.handle->will_handle || + msg->u.watch.handle->will_handle( + msg->u.watch.handle, + (const char **)msg->u.watch.vec, + msg->u.watch.vec_size))) { spin_lock(&watch_events_lock); list_add_tail(&msg->list, &watch_events); wake_up(&watch_events_waitq); diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index 32b944b7cebd..11697aa023b5 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -58,6 +58,13 @@ struct xenbus_watch /* Path being watched. */ const char *node; + /* + * Called just before enqueing new event while a spinlock is held. + * The event will be discarded if this callback returns false. + */ + bool (*will_handle)(struct xenbus_watch *, + const char **vec, unsigned int len); + /* Callback (executed in a process context with no locks held). */ void (*callback)(struct xenbus_watch *, const char **vec, unsigned int len); -- 2.17.1