Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3206007rwb; Thu, 29 Sep 2022 23:30:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6xb0LJKgWiT/AwWLfN+6ZEoGYX5m6SVLJoRmpwjZROmWhipqU4kEz2Rtf0XWwWTvdPZJTX X-Received: by 2002:a63:fa4d:0:b0:43c:7fa:95f7 with SMTP id g13-20020a63fa4d000000b0043c07fa95f7mr6192158pgk.48.1664519455406; Thu, 29 Sep 2022 23:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664519455; cv=none; d=google.com; s=arc-20160816; b=pE5k4UfpxpG99S1Z/lmb7WvMS14dWyl12Er0CbVUfmIYGBt1f9WO9ugYuGP8j3EySu HjQiSMMhgEYxMVzT7NIBzGEiaZJ6/hu0oM0UshIFS21OzJld55T9Q85UMnU6Qoc4MX/o 35qivUtdVimeyhVJe3MKQPt4Hy/B2TwsprxLJb+gqciggGaGBvyEbL1N0UcFnOBGkeKW 4hUv8+V077Zu9gTHjCZ4Xc+NefIVoxRJ2gEfoxbmDlqgfIz/ktSTgxPZork4/lyfZq/P E52+xOxF3aR0In3dmRA9UDw/enEHZzfFbhrU5k4ELpEEFaPEqI+qw12XGeun/dLHafx3 BMqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=mWyDCK4sgwNQboz2oMaLFnl6zMEOPYFWjgXwMVYGH4A=; b=kT0HN4E0IX62CzOq+fr90bpQXSnYaphqQhEN4ZFkdHgqOgGb+vDiFoGkgZB8O13p0o PC5gHIBReVtlbkzlNYojBfsA85H4xOB4meO9GxPDzMrGO5ta0mxPv0nCpkmgHQYmZFEr D1/aQ1BTIQssspivyU9/x1eIvN0XcwGHf6OLViFBVW3s55b+MMJiQOEUfYm8NRut8LOR rZT5L6/pELPREHSsjvwo73CQKup/tVH/1klQK1yF88+oSqhsMUtitcLmPAqI0gGO+Vza 74Zl5iLU8A4Q8rIBsm3gzNuV+gCDRlof5TTP1KqTvGdCOk8w2lLHdYEbP3lJq0bDBIIs sKJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ryXghZb3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iy14-20020a170903130e00b0017890fb8ce6si1842036plb.53.2022.09.29.23.30.42; Thu, 29 Sep 2022 23:30:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ryXghZb3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbiI3GCE (ORCPT + 99 others); Fri, 30 Sep 2022 02:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230088AbiI3GCB (ORCPT ); Fri, 30 Sep 2022 02:02:01 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7A5391FD899; Thu, 29 Sep 2022 23:02:00 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1134) id 551B720E0A4E; Thu, 29 Sep 2022 23:02:00 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 551B720E0A4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1664517720; bh=mWyDCK4sgwNQboz2oMaLFnl6zMEOPYFWjgXwMVYGH4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ryXghZb3oeeWN0GT3g2MNq1x0AXB2gJ+2y70rfAV8NTeIIFiWpW4Muu6lKYiC/Mq+ tAxYeujr67OOQkWyWCKD8S4McdGmXYpQxugelV0r8jTwfTVllcfFcV2TkzZnLCUAvA D9X0DHgaSnRp0hpiTbKTxMK13DbHuC1Gou+i1oNM= From: Shradha Gupta To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: Shradha Gupta , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Michael Kelley Subject: [PATCH v2 1/2] mm/page_reporting: Add checks for page_reporting_order param Date: Thu, 29 Sep 2022 23:01:38 -0700 Message-Id: <1664517699-1085-2-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664517699-1085-1-git-send-email-shradhagupta@linux.microsoft.com> References: <1664447081-14744-1-git-send-email-shradhagupta@linux.microsoft.com> <1664517699-1085-1-git-send-email-shradhagupta@linux.microsoft.com> X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.37.2