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 X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D1C6C433E0 for ; Mon, 10 Aug 2020 07:42:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E53E920678 for ; Mon, 10 Aug 2020 07:42:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="ecEsqmRi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E53E920678 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 417976B0006; Mon, 10 Aug 2020 03:42:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C72D6B0007; Mon, 10 Aug 2020 03:42:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B6176B0008; Mon, 10 Aug 2020 03:42:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 163BE6B0006 for ; Mon, 10 Aug 2020 03:42:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CCBA48248047 for ; Mon, 10 Aug 2020 07:42:33 +0000 (UTC) X-FDA: 77133866586.26.boys70_090422e26fd8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 7D4561804B66A for ; Mon, 10 Aug 2020 07:42:33 +0000 (UTC) X-HE-Tag: boys70_090422e26fd8 X-Filterd-Recvd-Size: 5546 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Mon, 10 Aug 2020 07:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597045353; x=1628581353; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=q/p0Bl4Vk/aMQV5R0RuRd9iNljPfuhyjU+deoaPgFus=; b=ecEsqmRinmik/jC7lpFYT2a+pGStJ1SUpnbU1gYGaIwb/yqrEgnjwrKd dnt7GPkqr9RDMj/BbKfHo65sFUJTMzk4gsKUoGCM804ujyuG0J4zj56Mp Q4dQoL1xv9pjg6CfHRh7LehuHw21mHQf66GGl7282Q+b3bAMjXx72bd+U U=; IronPort-SDR: Isl8z6UY0KpLTxS6jF5n1NSDuiRTpqJiDuBKR7FLfaxRKrl5b2afXK6vOVniDTuhyKJ6ahvX9v y24PXynPyJGA== X-IronPort-AV: E=Sophos;i="5.75,456,1589241600"; d="scan'208";a="66744338" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1a-821c648d.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 10 Aug 2020 07:42:26 +0000 Received: from EX13MTAUEB002.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-821c648d.us-east-1.amazon.com (Postfix) with ESMTPS id B4329A1D54; Mon, 10 Aug 2020 07:42:14 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEB002.ant.amazon.com (10.43.60.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 10 Aug 2020 07:42:13 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.160.192) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 10 Aug 2020 07:41:57 +0000 From: SeongJae Park To: SeongJae Park CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v19 09/15] mm/damon: Implement a debugfs interface Date: Mon, 10 Aug 2020 09:41:43 +0200 Message-ID: <20200810074143.26863-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200804091416.31039-10-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.160.192] X-ClientProxiedBy: EX13D46UWB002.ant.amazon.com (10.43.161.70) To EX13D31EUA001.ant.amazon.com (10.43.165.15) X-Rspamd-Queue-Id: 7D4561804B66A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 Tue, 4 Aug 2020 11:14:10 +0200 SeongJae Park wrote: > From: SeongJae Park > > This commit implements a debugfs interface for DAMON. It works for the > virtual address spaces monitoring. [...] > + > +#define targetid_is_pid(ctx) \ > + (ctx->target_valid == kdamond_vm_target_valid) > + [...] > + > +static ssize_t debugfs_target_ids_write(struct file *file, > + const char __user *buf, size_t count, loff_t *ppos) > +{ > + struct damon_ctx *ctx = &damon_user_ctx; > + char *kbuf; > + unsigned long *targets; > + ssize_t nr_targets; > + ssize_t ret = count; > + struct damon_target *target; > + int i; > + int err; > + > + kbuf = user_input_str(buf, count, ppos); > + if (IS_ERR(kbuf)) > + return PTR_ERR(kbuf); > + > + targets = str_to_target_ids(kbuf, ret, &nr_targets); > + if (!targets) { > + ret = -ENOMEM; > + goto out; > + } > + > + if (targetid_is_pid(ctx)) { > + for (i = 0; i < nr_targets; i++) > + targets[i] = (unsigned long)find_get_pid( > + (int)targets[i]); > + } > + > + mutex_lock(&ctx->kdamond_lock); > + if (ctx->kdamond) { > + ret = -EINVAL; > + goto unlock_out; > + } > + > + if (targetid_is_pid(ctx)) { > + damon_for_each_target(target, ctx) > + put_pid((struct pid *)target->id); If non-pid target ids were set before by the kernel API, this will cause a problem. Therefore, the DAMON users should cleanup there target ids properly. However, I found that this could be easily missed. Indeed, my new test code missed the cleanup. Moreover, it would be hard to do that when concurrent DAMON users exist. One straightforward fix would be making 'damon_set_targets()' to remember last target id type and do 'put_pid()' if the last target id type was pid, instead of here. This will work, but make the address space independent part to be coupled with the dependent part. Or, we could add another callback for cleanup and let debugfs code to register a function doing 'put_pid()' and remove of the targets as the callback. This approach will allow the address space independent part to be remain independent. I will fix this problem with the second approach in the next spin. Thanks, SeongJae Park