From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,NO_DNS_FOR_FROM, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 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) 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 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