From mboxrd@z Thu Jan 1 00:00:00 1970 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 81CF3FA373E for ; Wed, 26 Oct 2022 15:33:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 091318E0002; Wed, 26 Oct 2022 11:33:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 019C08E0001; Wed, 26 Oct 2022 11:33:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFCA88E0002; Wed, 26 Oct 2022 11:33:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CA5428E0001 for ; Wed, 26 Oct 2022 11:33:52 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7B912120577 for ; Wed, 26 Oct 2022 15:33:52 +0000 (UTC) X-FDA: 80063495904.06.20A5768 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf22.hostedemail.com (Postfix) with ESMTP id 03AC3C0018 for ; Wed, 26 Oct 2022 15:33:50 +0000 (UTC) Received: by mail-wm1-f42.google.com with SMTP id l32so10482545wms.2 for ; Wed, 26 Oct 2022 08:33:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Rpy3zNSL/y/tD/d9yfVMzCJsLEWWsJUHpcwvg6PJ/JA=; b=E94zEJ/KQKzwMdDiqxUcNvMT4fGV5tX5S6T6ZKPPlNHwhalA+16GArqrrHIA0PjgnS 9y5CqqJJiGBIXjOruKyYPH8Qjx9W6xlMjsUV2QdeSP/1HbqYRCaIBx6TAyKu7OOUezsD 0iWLLfslvTqJ823CfXOyemluiJXTkUvx7c8AmxQYG4GJ6O9F6CuBVT6xzyJtZU9tB6xO wzHbXy/opkm97yGBSKa6B+O54+rbCF5jzTpnqH/zEXTLtDGkML+H8qI1p16fU9zDAPDX kEjOQiC7ck8uHpogthHsB6OxjgXST/OZ4UtqFJIYbc2e1rPqGJnVVEztg22zNI9YkcT1 Ohkw== X-Gm-Message-State: ACrzQf2zN7OaiL4GrBL4SllId08j+PVydJCGZOdKqC/8uNv0qtpWhAkX sxvyqHWp5y08lk/m+BSBAxg= X-Google-Smtp-Source: AMsMyM4Axp+Fa7CgEJvzWt4sr8Nyu2jUTvpMABm/oeliK2HiYmE8ODrqHBmjg8gr00pbnp2x8ceRlg== X-Received: by 2002:a05:600c:310a:b0:3c6:f9a6:5a7d with SMTP id g10-20020a05600c310a00b003c6f9a65a7dmr2924497wmo.29.1666798429687; Wed, 26 Oct 2022 08:33:49 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id f18-20020a5d58f2000000b0022b315b4649sm5736607wrd.26.2022.10.26.08.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 08:33:48 -0700 (PDT) Date: Wed, 26 Oct 2022 15:33:47 +0000 From: Wei Liu To: Shradha Gupta Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Michael Kelley Subject: Re: [PATCH v2 1/2] mm/page_reporting: Add checks for page_reporting_order param Message-ID: References: <1664447081-14744-1-git-send-email-shradhagupta@linux.microsoft.com> <1664517699-1085-1-git-send-email-shradhagupta@linux.microsoft.com> <1664517699-1085-2-git-send-email-shradhagupta@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1664517699-1085-2-git-send-email-shradhagupta@linux.microsoft.com> ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wei.liu.linux@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=wei.liu.linux@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666798431; a=rsa-sha256; cv=none; b=wx7TaUf+6q1WDkHy0/WmutCvlpXZaXIR4FEtNnZFChyrjP0MkvdemhqizroHwq1135dJEx A1UgULwVGLfMrpRPjN1galOmTAGEWkMrysLnl6phlv2zY+U5fz2TWZIVojeyNUaquaCsBm 9pDtjSqFW/6t8mS3IX6Kgn5QjG/nVSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666798431; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rpy3zNSL/y/tD/d9yfVMzCJsLEWWsJUHpcwvg6PJ/JA=; b=vNwv6E5yBOT5pWhp9k5wAEvj08j0DtLqEXd7QmDDcqCjomcCmdn8E9UnmY0Jb71p4B0zI5 zwFJz72JIuYpv6v5Vjq6Yk9Vs1li2gtTGZ5tYA7bKwQzF//pqJv2wpgDV/OdgqAIBiU2F3 dINW3EpV7HQvYkKUdbnq4Tbyw9VhnXM= X-Rspamd-Queue-Id: 03AC3C0018 Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wei.liu.linux@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=wei.liu.linux@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) X-Rspamd-Server: rspam02 X-Rspam-User: X-Stat-Signature: 9nzjbx7kgo94kqy3hph3jpxmyoaji3o8 X-HE-Tag: 1666798430-820094 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: On Thu, Sep 29, 2022 at 11:01:38PM -0700, Shradha Gupta wrote: > 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 Andrew and other MM reviewers, can I get an ack / nack for this patch? > --- > 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 >