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 546B1ECAAD3 for ; Thu, 1 Sep 2022 08:32:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA5456B0073; Thu, 1 Sep 2022 04:32:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E54FE6B0074; Thu, 1 Sep 2022 04:32:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D44E48D0001; Thu, 1 Sep 2022 04:32:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C21706B0073 for ; Thu, 1 Sep 2022 04:32:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 97A20AB243 for ; Thu, 1 Sep 2022 08:32:01 +0000 (UTC) X-FDA: 79862848842.14.95C00EB Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by imf06.hostedemail.com (Postfix) with ESMTP id 26860180044 for ; Thu, 1 Sep 2022 08:32:00 +0000 (UTC) Received: from [192.168.210.80] (unknown [182.2.39.249]) by gnuweeb.org (Postfix) with ESMTPSA id 961C180866; Thu, 1 Sep 2022 08:31:55 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662021120; bh=LXF7eI1yQrVMaWbZtpBHxTo7k3XXXY6ySsuxRufruxM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ew1QCZi4NfHMRE9AnbMQwpAvstecLGWlhjLF1hrJSpUchJiYL8rzkOaW8smMlbTzG JRTBh9QsO1i0RmCJfpF/dvTm0EFohIDngpNRRISHO+0+cezcpMsHoaSOaItBX3EM38 vT8juBXaJcsX10uN+vISwVCMnUpYNBcC/o3XoyD1pTZQym2P+Zft1FvxKFvcAGO//4 EKgYgOXz42liZ34IIMOeI+hg3WrqU1wX5WSP+ziP8JAt+lE234SM5SE1B9E8taYmQv BUZytEOuH/EDPdoVZ/pqI3h1XcUDI+q8iGJZzeXMXNrzz6sO+KhClCdMlFmtt3HVWy DSyT/lCnI9FWA== Message-ID: <3c69f09e-1e34-73f9-b38b-733971ef38cb@gnuweeb.org> Date: Thu, 1 Sep 2022 15:31:51 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 3/3] mm,page_owner: Filter out stacks by a threshold counter Content-Language: en-US To: Oscar Salvador , Andrew Morton Cc: Linux Kernel Mailing List , Linux MM Mailing List , Michal Hocko , Vlastimil Babka , Eric Dumazet , Waiman Long , Suren Baghdasaryan References: <20220901044249.4624-1-osalvador@suse.de> <20220901044249.4624-4-osalvador@suse.de> From: Ammar Faizi In-Reply-To: <20220901044249.4624-4-osalvador@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gnuweeb.org header.s=default header.b=ew1QCZi4; spf=pass (imf06.hostedemail.com: domain of ammarfaizi2@gnuweeb.org designates 51.81.211.47 as permitted sender) smtp.mailfrom=ammarfaizi2@gnuweeb.org; dmarc=pass (policy=none) header.from=gnuweeb.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662021121; a=rsa-sha256; cv=none; b=4m8FMfs2i1kFWw5rHDfvEM1OnkPLC3q0I2ukirrwMdEgPEJjp2GQjH9PbLhNgwwtJ2vI+2 5jlKsFmgHDYMBMIuJDwNsZkuA8lM4C0jEYlSHGL5dWSNyPdtzzqut74H2bTBcbv5yWpOfE 2JANJTRmUdwZqLC6uzkbAqmBAfgcNYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662021121; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=B52ZBonsYfDis+ILqz2UQ6k9hoQNSr2kjmalO9O9fQs=; b=TpTVpHQ3iEZv2ZmTwgXqBf3hio+9TRMXXMle/6Na34XWcWWCNXHtXeKTCMfav2XCWsMpMq xB3qh3w467uoGsBwo4zZfP2HZSn491M+bHxzNL/6kKPCfWZAT8jFDALg9l2PW80vM2ZiQX 6sde9url3KveM960ZRKURCOVMSfzWFk= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 26860180044 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gnuweeb.org header.s=default header.b=ew1QCZi4; spf=pass (imf06.hostedemail.com: domain of ammarfaizi2@gnuweeb.org designates 51.81.211.47 as permitted sender) smtp.mailfrom=ammarfaizi2@gnuweeb.org; dmarc=pass (policy=none) header.from=gnuweeb.org X-Stat-Signature: 74muqdpsa7r5iofr76jjy9cnfew5brz5 X-HE-Tag: 1662021120-564363 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 9/1/22 11:42 AM, Oscar Salvador wrote:> +static ssize_t read_page_owner_threshold(struct file *file, char __user *buf, > + size_t count, loff_t *pos) > +{ > + char *kbuf; > + int ret = 0; > + > + count = min_t(size_t, count, PAGE_SIZE); > + > + if (*pos >= count) > + return 0; > + > + kbuf = kmalloc(count, GFP_KERNEL); > + if (!kbuf) > + return ENOMEM; Missing a negative sign, return -ENOMEM. > + ret = scnprintf(kbuf, count, "%lu\n", threshold_count); > + if (copy_to_user(buf, kbuf, ret)) > + ret = -EFAULT; > + > + *pos += count; > + kfree(kbuf); > + > + return ret; > +} > + > +static ssize_t write_page_owner_threshold(struct file *file, const char __user *buf, > + size_t count, loff_t *pos) > +{ > + char *kbuf; > + int ret = 0; > + > + count = min_t(size_t, count, PAGE_SIZE); > + kbuf = kmalloc(count, GFP_KERNEL); This looks overestimating to me. For unsigned long, on a 64-bit system has max val 18446744073709551615 (20 chars). You can use stack a allocated local variable with length 21. No need to use kmalloc(). The same way with the read() op. > + if (!kbuf) > + return -ENOMEM; > + > + if (copy_from_user(kbuf, buf, count)) { > + ret = -EFAULT; > + goto out; > + } > + > + kbuf[count - 1] = '\0'; > + > + ret = kstrtoul(kbuf, 10, &threshold_count); > + > +out: > + kfree(kbuf); > + return ret ? ret : count; > +} > + > +static const struct file_operations proc_page_owner_threshold = { > + .read = read_page_owner_threshold, > + .write = write_page_owner_threshold, > +}; -- Ammar Faizi