Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1221752ybg; Thu, 4 Jun 2020 04:22:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2jmh0do6e2eai6B0woIrufDjluDygCywsfYmHDwKPG6ysFP2macrWl9NXbpJXU5oEJTVB X-Received: by 2002:a50:d556:: with SMTP id f22mr3936455edj.307.1591269724120; Thu, 04 Jun 2020 04:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591269724; cv=none; d=google.com; s=arc-20160816; b=ymc7obfJyMBwcSTHgtUoDvQ42kWxfRQaFFImsFfCHAQ5nx9MXSsskDoJKJTR7WUSCo ZFsttw9yFnLFzi5lCsj9PIrRKRT8Uno6Vkbmr0oSVHDNBzTBfPItCNKo+OBtbe2YFk/V gGjmc1DLy6PxNVn/707efvZjtUMzDMdDcPiXAd9yPwSpqqzUynIqvwFEtY/AJ3payxqg OU9opYnzGhvNzi1A+YJYQMjwsQ3Dv8/atNvOJUUu6lRRXr8hsbauVdmy0jDAUSxW4Gvg GeW/I2Gis8LcxOxf1ujK9+Uwu9ciyS3i6wQiIvrAtOGrS2rdb9iygZFG/uuyHL0RLBPt LRuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:dkim-signature; bh=Qil4CHTe9zc+4qSWiwfHINBzR6yECNz+NaYOle+YSdE=; b=OT9bNB92Q1uZ/DVaZDihdW0ZHobIBj48RK3YL7K4CLeExCV3czSYDY+draSepxaExB DDW4UBPhrEVRzP26mdjsRTvCy8Y2ogaAP8dFSw3A5euP+ec67OtMjlgJsqXPPulMWdaQ hzYHmzfShjGtVzFvLXbeHcuT397QRvPqLYJPnN1piuOdNQ+WeH++WKM2e20uJ6c+rzlq DymcZGzGMmvsn+KIXeC2G8KcRQZIN2ox8pHrIF1qRDszxilWBQRdtdkNBuegmctNRM33 8WxG5R5Wuu6WydmRBM5OwWzSIKKUhkYTt6kEtrPmWoWHIP+d51VKVBTnGq3ZpJXomX2d fbTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=t3AEgxuD; 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 s16si1501105edu.512.2020.06.04.04.21.40; Thu, 04 Jun 2020 04:22:04 -0700 (PDT) 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=t3AEgxuD; 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 S1727051AbgFDLSu (ORCPT + 99 others); Thu, 4 Jun 2020 07:18:50 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:42537 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgFDLSt (ORCPT ); Thu, 4 Jun 2020 07:18:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591269529; x=1622805529; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=Qil4CHTe9zc+4qSWiwfHINBzR6yECNz+NaYOle+YSdE=; b=t3AEgxuDms8WwFRf4q+9WMN6S+xA0vXQJrBV3CJajjFpICkRdClqIQCU WcCjNWfpucWBhghoigUSpM3azQETuvDA2eExadOdyIsglCx8ZaLJtoKcD /p5gtrsdNf9A1QoEA0aLw6+EKlHj6fpaIvq7BjWJMROLIyFl/aKE9NYJf s=; IronPort-SDR: 1V684L6BWiC3yvDiZT0UEWaWau9eDZ9TCdD43ZQNpdVhQb/dZZ31ltqHFAwFDK3kTgp7NAAy+l IXlqRIBf2HVw== X-IronPort-AV: E=Sophos;i="5.73,472,1583193600"; d="scan'208";a="49788679" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-9ec21598.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 04 Jun 2020 11:18:44 +0000 Received: from EX13MTAUEA002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-9ec21598.us-east-1.amazon.com (Postfix) with ESMTPS id 622C2A3941; Thu, 4 Jun 2020 11:18:33 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Jun 2020 11:18:32 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.161.34) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Jun 2020 11:18:16 +0000 From: SeongJae Park To: SeongJae Park CC: , SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [RFC v9 4/8] mm/damon/schemes: Implement a debugfs interface Date: Thu, 4 Jun 2020 13:17:57 +0200 Message-ID: <20200604111757.7659-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200526075702.27339-5-sjpark@amazon.com> (raw) MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.34] X-ClientProxiedBy: EX13D19UWC001.ant.amazon.com (10.43.162.64) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 May 2020 09:56:58 +0200 SeongJae Park wrote: > From: SeongJae Park > > This commit implements a debugfs interface for the data access > monitoring oriented memory management schemes. It is supposed to be > used by administrators and/or privileged user space programs. Users can > read and update the rules using ``/damon/schemes`` file. The > format is:: > > > > Signed-off-by: SeongJae Park > --- > mm/damon.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 174 insertions(+), 2 deletions(-) > > diff --git a/mm/damon.c b/mm/damon.c > index 6a07649d1f5d..bcc732e8735c 100644 > --- a/mm/damon.c > +++ b/mm/damon.c > @@ -173,6 +173,29 @@ static void damon_destroy_task(struct damon_task *t) > damon_free_task(t); > } > + > +/* > + * Converts a string into an array of struct damos pointers > + * > + * Returns an array of struct damos pointers that converted if the conversion > + * success, or NULL otherwise. > + */ > +static struct damos **str_to_schemes(const char *str, ssize_t len, > + ssize_t *nr_schemes) > +{ > + struct damos *scheme, **schemes; > + const int max_nr_schemes = 256; > + int pos = 0, parsed, ret; > + unsigned int min_sz, max_sz, min_nr_a, max_nr_a, min_age, max_age; > + unsigned int action; > + > + schemes = kmalloc_array(max_nr_schemes, sizeof(scheme), > + GFP_KERNEL); > + if (!schemes) > + return NULL; > + > + *nr_schemes = 0; > + while (pos < len && *nr_schemes < max_nr_schemes) { > + ret = sscanf(&str[pos], "%u %u %u %u %u %u %u%n", > + &min_sz, &max_sz, &min_nr_a, &max_nr_a, > + &min_age, &max_age, &action, &parsed); > + if (ret != 7) > + break; > + if (action >= DAMOS_ACTION_LEN) { > + pr_err("wrong action %d\n", action); > + goto fail; > + } > + > + pos += parsed; > + scheme = damon_new_scheme(min_sz, max_sz, min_nr_a, max_nr_a, > + min_age, max_age, action); > + if (!scheme) > + goto fail; > + > + schemes[*nr_schemes] = scheme; > + *nr_schemes += 1; > + } > + if (!*nr_schemes) > + goto fail; > + return schemes; > +fail: > + free_schemes_arr(schemes, *nr_schemes); > + return NULL; > +} > + > +static ssize_t debugfs_schemes_write(struct file *file, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + struct damon_ctx *ctx = &damon_user_ctx; > + char *kbuf; > + struct damos **schemes; > + ssize_t nr_schemes = 0, ret; > + int err; > + > + if (*ppos) > + return -EINVAL; > + > + kbuf = kmalloc(count, GFP_KERNEL); > + if (!kbuf) > + return -ENOMEM; > + > + ret = simple_write_to_buffer(kbuf, count, ppos, buf, count); > + if (ret < 0) > + goto out; > + > + schemes = str_to_schemes(kbuf, ret, &nr_schemes); In case of wrong input, 'str_to_schemes()' could return NULL with non-zero nr_schemes, but the case is not handled here. I will properly handle the case in the next spin. Thanks, SeongJae Park > + > + mutex_lock(&ctx->kdamond_lock); > + if (ctx->kdamond) { > + ret = -EBUSY; > + goto unlock_out; > + } > + > + err = damon_set_schemes(ctx, schemes, nr_schemes); > + if (err) > + ret = err; > + else > + nr_schemes = 0; > +unlock_out: > + mutex_unlock(&ctx->kdamond_lock); > + free_schemes_arr(schemes, nr_schemes); > +out: > + kfree(kbuf); > + return ret; > +} > +