From patchwork Thu Sep 29 10:24:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shradha Gupta X-Patchwork-Id: 12993899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 664A5C4332F for ; Thu, 29 Sep 2022 10:24:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E06A8D0003; Thu, 29 Sep 2022 06:24:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88E848D0001; Thu, 29 Sep 2022 06:24:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72ECD8D0003; Thu, 29 Sep 2022 06:24:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 643818D0001 for ; Thu, 29 Sep 2022 06:24:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C28D3AB9F4 for ; Thu, 29 Sep 2022 10:24:51 +0000 (UTC) X-FDA: 79964739582.15.5E6537E Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf16.hostedemail.com (Postfix) with ESMTP id 3FA07180011 for ; Thu, 29 Sep 2022 10:24:51 +0000 (UTC) Received: by linux.microsoft.com (Postfix, from userid 1134) id 2FB1520DEE80; Thu, 29 Sep 2022 03:24:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2FB1520DEE80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1664447090; bh=mWyDCK4sgwNQboz2oMaLFnl6zMEOPYFWjgXwMVYGH4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SQq1j/TGTKNgftQPa/1lLz0CNf/6/sX0IV2JrXrkdUMoWX606HHPBjS81p0mfbKep upjEu4ANjuEYEUCBjwzHlL+jOkTnOSMWKPAvyvayrJi7zqDg18lEDsjUMzmcUXbNhQ w6DEZD2Z7EVjcKAlrXhoL1fcp+uo7bR2HGogVATw= From: Shradha Gupta To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Shradha Gupta , Michael Kelley Subject: [PATCH 1/2] mm/page_reporting: Add checks for page_reporting_order param value Date: Thu, 29 Sep 2022 03:24:40 -0700 Message-Id: <1664447081-14744-2-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664447081-14744-1-git-send-email-shradhagupta@linux.microsoft.com> References: <1664447081-14744-1-git-send-email-shradhagupta@linux.microsoft.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664447091; a=rsa-sha256; cv=none; b=tXFiFROd21nHsv57zRYm1wF6XILRwq+S3PJHtMHsb+padYwRXvWVnQp5l0sXpUtMtKqitI HNPEBeJeCtwjjZWaEK2/vrSStK4UGu4p4xI4Zxmqhx8VDiXub/JZW/9m6ojjMXpnOsl8s+ 8c7TNzuICfzjrT6oUgXU0Ehn1AY8Pbk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b="SQq1j/TG"; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf16.hostedemail.com: domain of shradhagupta@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=shradhagupta@linux.microsoft.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664447091; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=mWyDCK4sgwNQboz2oMaLFnl6zMEOPYFWjgXwMVYGH4A=; b=Zfq0wXvS94G2vQG+CkPtvLgunfnZ8GHhROzs5aOq0OqIZ2fgHqRpxinKzgFt+WvZkJTeZ4 HzwEEBk5LZFNoiEclzG35xycTiLW5TuS5ZDE8SuyvKE4k6j0qL20/oWjPtQt8fIKMZ9uIW m+E+TLDdk9ITDeSMmlsvM4Bg6/UQi5Y= X-Stat-Signature: mn944zcw77ccctf1t334gtkdszdrpdgd X-Rspamd-Queue-Id: 3FA07180011 X-Rspamd-Server: rspam04 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b="SQq1j/TG"; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf16.hostedemail.com: domain of shradhagupta@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=shradhagupta@linux.microsoft.com X-Rspam-User: X-HE-Tag: 1664447091-615366 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Current code allows the page_reporting_order parameter to be changed via sysfs to any integer value. The new value is used immediately in page reporting code with no validation, which could cause incorrect behavior. Fix this by adding validation of the new value. Export this parameter for use in the driver that is calling the page_reporting_register(). This is needed by drivers like hv_balloon to know the order of the pages reported. Traditionally the values provided in the kernel boot line or subsequently changed via sysfs take priority therefore, if page_reporting_order parameter's value is set, it takes precedence over the value passed while registering with the driver. Signed-off-by: Shradha Gupta --- mm/page_reporting.c | 50 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/mm/page_reporting.c b/mm/page_reporting.c index 382958eef8a9..29d67c824fd2 100644 --- a/mm/page_reporting.c +++ b/mm/page_reporting.c @@ -11,10 +11,42 @@ #include "page_reporting.h" #include "internal.h" -unsigned int page_reporting_order = MAX_ORDER; -module_param(page_reporting_order, uint, 0644); +/* Initialize to an unsupported value */ +unsigned int page_reporting_order = -1; + +int page_order_update_notify(const char *val, const struct kernel_param *kp) +{ + /* + * If param is set beyond this limit, order is set to default + * pageblock_order value + */ + return param_set_uint_minmax(val, kp, 0, MAX_ORDER-1); +} + +const struct kernel_param_ops page_reporting_param_ops = { + .set = &page_order_update_notify, + /* + * For the get op, use param_get_int instead of param_get_uint. + * This is to make sure that when unset the initialized value of + * -1 is shown correctly + */ + .get = ¶m_get_int, +}; + +module_param_cb(page_reporting_order, &page_reporting_param_ops, + &page_reporting_order, 0644); MODULE_PARM_DESC(page_reporting_order, "Set page reporting order"); +/* + * This symbol is also a kernel parameter. Export the page_reporting_order + * symbol so that other drivers can access it to control order values without + * having to introduce another configurable parameter. Only one driver can + * register with the page_reporting driver for the service, so we have just + * one control parameter for the use case(which can be accessed in both + * drivers) + */ +EXPORT_SYMBOL_GPL(page_reporting_order); + #define PAGE_REPORTING_DELAY (2 * HZ) static struct page_reporting_dev_info __rcu *pr_dev_info __read_mostly; @@ -330,10 +362,18 @@ int page_reporting_register(struct page_reporting_dev_info *prdev) } /* - * Update the page reporting order if it's specified by driver. - * Otherwise, it falls back to @pageblock_order. + * If the page_reporting_order value is not set, we check if + * an order is provided from the driver that is performing the + * registration. If that is not provided either, we default to + * pageblock_order. */ - page_reporting_order = prdev->order ? : pageblock_order; + + if (page_reporting_order == -1) { + if (prdev->order > 0 && prdev->order <= MAX_ORDER) + page_reporting_order = prdev->order; + else + page_reporting_order = pageblock_order; + } /* initialize state and work structures */ atomic_set(&prdev->state, PAGE_REPORTING_IDLE);