Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp434820rwe; Thu, 1 Sep 2022 01:54:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR6dFhgeiAyzQlkmGz6Eu4KUV1pgC+9tioYIFKgHLw8D+A/DAlsVnBd13MckhkaFFZ9MVkDH X-Received: by 2002:a05:6402:379:b0:448:de41:2c0c with SMTP id s25-20020a056402037900b00448de412c0cmr8899240edw.290.1662022499006; Thu, 01 Sep 2022 01:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662022498; cv=none; d=google.com; s=arc-20160816; b=JuaTA8GSTvwpCX3YG1fJ3tStHbZ7G7OLp9LMlivHz8vCVlSiSdSBV6sBrzCZl5OVYX ZOgtk0Zl+6/Kj3dLKuukTpr2rnyCHjiAq+J8hesggsvQ+44wuKjs71ypGGbAMmCcBmAd EhjEoG2rECvF/S8ECPp+yIX4FRJkj4Uzs4OWPXKU2ELwQBm4CDOVrl8sCc90IAFUqQGr 5Ty7bjW64qcoT4hQYTsesX+AnBqdcGG7NSkZn8vbRGNZSS2npCnN4nn9d25p4x0OUkuG 5Wpyqz6gtsP8/VRHuPL9OZ9aKuk31iG3TMRTsbdXVAFWQMRy2HNmcngTPrBMKM7UMjVO kZaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=B52ZBonsYfDis+ILqz2UQ6k9hoQNSr2kjmalO9O9fQs=; b=zrAXzhdeQIbycAjQKVjbMF+KLQs+3qa9VfzV4HT4QmK+2ERjYMeaS5x9NR8Eg97IIY QBm6iX6+iGHiMs1vshn+EH37OLvbJaKkdSFjQVktiWB9bnXFXErVQm5HOc8plrHjQu4F nkdECdtTWTOUZ76b7TF18vavVE9XxDV9OZKe1EaQcyyT7744/pbaneWsMgKnzBquiMOg 5csoGXjbzrt+JV1YEhcJ6Ou6U7aAO/05cfxaTYN/b9q/GM4y75VKM2sUxzh2o0RKrVOB WTV/eWUJI4azKKDaF+RI5rDQHwmK8FrjO8EWvRtQ4JWbkn4bRxMNAUgMuB7oWpf3V9TV 2PTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=ew1QCZi4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k4-20020a1709067ac400b0073d6277ca42si10908936ejo.201.2022.09.01.01.54.32; Thu, 01 Sep 2022 01:54:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=ew1QCZi4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234110AbiIAIcH (ORCPT + 99 others); Thu, 1 Sep 2022 04:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229798AbiIAIcD (ORCPT ); Thu, 1 Sep 2022 04:32:03 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 844B612AE1D for ; Thu, 1 Sep 2022 01:32:01 -0700 (PDT) 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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