Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4117179pxa; Mon, 10 Aug 2020 00:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwO6QlhFa/7WfpNiOtlpctquUys8S7PGIw3hBUeHs6prbm3RyBQVExkiGePaAPMXV9E1UG4 X-Received: by 2002:a50:c449:: with SMTP id w9mr20573090edf.65.1597045408960; Mon, 10 Aug 2020 00:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597045408; cv=none; d=google.com; s=arc-20160816; b=uslYyceyvgCd63VjayLR2EZ+VvNjMCH9dn5Bm/gwYXgwkOiVq0Mtfn3fVAk7ppqoEh FfTGGa0ejJ7MLicFAVV8rejeZVADbbfZlicnPEla2KQBG/Az2n0H9rn2SfMQPr7dtUkp z9x12mSA4zViTdaB9JakUMzTc9l+Th5ngOzKq0414Zu+ZOBbSepmPxUbc2qhfccFisHN LnNuCURYHLiUSoQLCrjNPU2RuaHcSk/42GJ17VQDrrGKdI98o5wf0aTz2DrwH0qDn8Fj TwxjEbq8tf3qOcH4eV2fliAG5XiaIqxZBodnpX1lGIWe7Hw4Fw6Xzd9wupJOzkW50t4R o8hA== 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=q/p0Bl4Vk/aMQV5R0RuRd9iNljPfuhyjU+deoaPgFus=; b=gqplFpljF6l17eNudz58px9cB6n9Ay9/h4K9PXgQHRfVfXdLfYwPjWkzQ6FHgyy+HK 9XvdG3htTpM5VpwqsWDmZCsGgDdDKTA2PIuByoPi/grjSTdQN7pFdYM55fi4vS4Zz94t ANh2mbHIjUCdj62BABnRoNf7POaQ3y0rEhd8oAa66JT1bTz7g4U0xPKvfA0X4RbzSz7j mbSpUHPXbhU+dtMLVF4Bz2kynkY9ik5fe3gwsonUTfhdQ7LU1Zh3XuepgdvKE+uKluTv QTSp6yKTmDaL4GShB3hc+B13X6EjJB2rAPRZHgyEIbhGUClbLBuZS08ljgZuQdKakqGB C0pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=gKB1xCO0; 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 yj16si11317615ejb.59.2020.08.10.00.43.05; Mon, 10 Aug 2020 00:43:28 -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=gKB1xCO0; 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 S1726501AbgHJHmd (ORCPT + 99 others); Mon, 10 Aug 2020 03:42:33 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:59683 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbgHJHmc (ORCPT ); Mon, 10 Aug 2020 03:42:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1597045352; x=1628581352; h=from:to:cc:subject:date:message-id:in-reply-to: mime-version; bh=q/p0Bl4Vk/aMQV5R0RuRd9iNljPfuhyjU+deoaPgFus=; b=gKB1xCO0uTgxFaHqRZfk0e76ef72kHjA/tsgAwhrRbRwrfPxLe5y2yvP IUgLXKABJF2WYtfd9Ep2wbjzKwTMi1/jYYU0LDmZdlFf0lZF1DSltTX1j j0yGVEPlfcu8fLi25qRO81nUDNBbxwUCAoJXecn9UPKP8N4qH29mR7hCu w=; 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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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