Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3120584imu; Mon, 17 Dec 2018 13:45:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/VbwXz3dtL1iBbxvUEeHPP62ArslXxqoSIRcLAp9HNf7j363ywEjN3lFHxD5j0Smk1CJbx7 X-Received: by 2002:a17:902:8d8e:: with SMTP id v14mr14013242plo.133.1545083115760; Mon, 17 Dec 2018 13:45:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545083115; cv=none; d=google.com; s=arc-20160816; b=ZoZU9dmdKGu3VfJJrCq4FxtBBx/N6733V5nJJLoUKqOEcnuplCXp8oRHIhdicZUAZY 4JoQWjcgkGA+So4vnon51nQCVPqAEdRm5WKCU+t8eL3qS0ZLWlMYMoxh4Cm+3sTSlFel kH3PVEF84Z1fBiiS9Xmd/aaE7STtoWvYwi6cja5Jzu6JbbCqFHsTt5ET/UxrSc4V7jnb /ZfyeOql3PCwI7i4HSA7WejCRfbIyGItCOLjwrTsET/NYMutUF9uyslxTGvunOJ63ECI vBWFJlcGaur/el0jxpeEb1hQ6q+HJuDLhuJXv9fc+rKOFHRn2jWL+E85Nzxpgp9e1sEm Xb1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GzJw5OfqZmFeF3p28QfnsLekp01V+WlkztoA/o5MB54=; b=kk3l4LkvvBHMWDEUwkggcEiMm5YKu4C24KNsfme6p0YQ95HPYgfJlqRyjmxnZ0imjf gblUicIv7JgXOJCnEPDPBWv1D+6dNpmtIdt14kcmizeTZzXCre9OAwrUre8M2+oA2+IO mecs7ke3oYmT2eF/Yo3swGNB3KXbBaUON276OZQMW7eR28LapKXSUFhYLaXz3A3FM1Yv 5WKJLApzdRiRkleKWmz4s8NUV8n5YL8CzWmlWY/LkUXOfv5lOwMMle5UnSbCKhTMHjQL D5p41Cv9JcniXdHyJJ6O6lQkNB0lqxqW9MwiCKX4d5512uL8t3/uoLR2aN/Qz00bw2Tw nHMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WYxsJrP4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si12225757pfb.188.2018.12.17.13.45.00; Mon, 17 Dec 2018 13:45:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=WYxsJrP4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388198AbeLQQWh (ORCPT + 99 others); Mon, 17 Dec 2018 11:22:37 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:50524 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbeLQQWh (ORCPT ); Mon, 17 Dec 2018 11:22:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GzJw5OfqZmFeF3p28QfnsLekp01V+WlkztoA/o5MB54=; b=WYxsJrP404KuAZ2ACEgEdDK7l nkBSRImFxKA13t+MK5lTOYQiicpZuZKazn7bmwDj+2IlsDtct6CC1Uw6WDTGajnKe5y94U5mlc5op JB5tGoD4ja81ENX8kijklOQiBBew9EGn9tWwQH4/eh4vrLwfKl7UQX2NM92rUYee5AtGc7+UQbwfL 2ViuXTBIbTq2flLaf1pz23VW7S8tAqbSk2oQIVIiaADY1FRuVqUPMslUQo7uYouhCVkKPxIWKf3QZ DOMqiWnScFsyY5gLOn1x4AtB1AMkSGsHZkPzq9fn/ETXvXZ5v/0mkje5LQSEN6aA7Qc4adrteE2di lnJN8TOyQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gYvez-0002p8-7C; Mon, 17 Dec 2018 16:22:26 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9126B20276ABC; Mon, 17 Dec 2018 17:22:23 +0100 (CET) Date: Mon, 17 Dec 2018 17:22:23 +0100 From: Peter Zijlstra To: Suren Baghdasaryan Cc: gregkh@linuxfoundation.org, tj@kernel.org, lizefan@huawei.com, hannes@cmpxchg.org, axboe@kernel.dk, dennis@kernel.org, dennisszhou@gmail.com, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 6/6] psi: introduce psi monitor Message-ID: <20181217162223.GD2218@hirez.programming.kicks-ass.net> References: <20181214171508.7791-1-surenb@google.com> <20181214171508.7791-7-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181214171508.7791-7-surenb@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 14, 2018 at 09:15:08AM -0800, Suren Baghdasaryan wrote: > +ssize_t psi_trigger_parse(char *buf, size_t nbytes, enum psi_res res, > + enum psi_states *state, u32 *threshold_us, u32 *win_sz_us) > +{ > + bool some; > + bool threshold_pct; > + u32 threshold; > + u32 win_sz; > + char *p; > + > + p = strsep(&buf, " "); > + if (p == NULL) > + return -EINVAL; > + > + /* parse type */ > + if (!strcmp(p, "some")) > + some = true; > + else if (!strcmp(p, "full")) > + some = false; > + else > + return -EINVAL; > + > + switch (res) { > + case (PSI_IO): > + *state = some ? PSI_IO_SOME : PSI_IO_FULL; > + break; > + case (PSI_MEM): > + *state = some ? PSI_MEM_SOME : PSI_MEM_FULL; > + break; > + case (PSI_CPU): > + if (!some) > + return -EINVAL; > + *state = PSI_CPU_SOME; > + break; > + default: > + return -EINVAL; > + } > + > + while (isspace(*buf)) > + buf++; > + > + p = strsep(&buf, "%"); > + if (p == NULL) > + return -EINVAL; > + > + if (buf == NULL) { > + /* % sign was not found, threshold is specified in us */ > + buf = p; > + p = strsep(&buf, " "); > + if (p == NULL) > + return -EINVAL; > + > + threshold_pct = false; > + } else > + threshold_pct = true; > + > + /* parse threshold */ > + if (kstrtouint(p, 0, &threshold)) > + return -EINVAL; > + > + while (isspace(*buf)) > + buf++; > + > + p = strsep(&buf, " "); > + if (p == NULL) > + return -EINVAL; > + > + /* Parse window size */ > + if (kstrtouint(p, 0, &win_sz)) > + return -EINVAL; > + > + /* Check window size */ > + if (win_sz < PSI_TRIG_MIN_WIN_US || win_sz > PSI_TRIG_MAX_WIN_US) > + return -EINVAL; > + > + if (threshold_pct) > + threshold = (threshold * win_sz) / 100; > + > + /* Check threshold */ > + if (threshold == 0 || threshold > win_sz) > + return -EINVAL; > + > + *threshold_us = threshold; > + *win_sz_us = win_sz; > + > + return 0; > +} How well has this thing been fuzzed? Custom string parser, yay!