Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp805874ybh; Mon, 13 Jul 2020 01:25:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybxWXVLtwyo80D5X8ZzM8/qDvi65mSWWm+/pr7wD0AmI1icOAk8ZpgMwmLJFiaOc4FDbwO X-Received: by 2002:a17:907:20c4:: with SMTP id qq4mr70803468ejb.85.1594628729647; Mon, 13 Jul 2020 01:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594628729; cv=none; d=google.com; s=arc-20160816; b=TAScAZAbSOf7afE2tJOl6HSsO+9RWWXOJyxcT7+vS2tKyz5vH5HhUHagVXdu2lK0Kn OOMyZAqKviCgBpgTR96b3gqfo/jjUhKq+IkLYSxffltCHBrYKwlcQExexCyTTPqFrb1F 1zXda7yFRaoTsZ7FTCOBOKa1yyOUSgUeC6t+MrcXDa769GUyEXVZRWAu0/5bshAHtMjn 9uMmHpMRetYEusLcyfv71XhrgCUZ6QsZEaU35H0BRqEn91YlH5YEpYuCjUAGDo3Hv7/B 2tcaZlrLi0sA96sXQ7QOTueNfMvvypB0UVJ2vFbBZT+qBxfDaHYgOVQUA5D4MTAQl4jW yw3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject:ironport-sdr :ironport-sdr; bh=XLCGZFoPO60gbcUyT00pJMQCRuvqyKV4czHxsgEBE8Q=; b=Jum0S60UKz5WtzpP5FQ9eIVta9pUD/uGGeddvuso6xo4zPGmGpZq4/oDCuU4bg711n fULidJFxyGBKGtJIlJaBEhCFME/snDvCUv2PfessJGZExWqKDhkFRI188fjO1KhNx/I2 ID2A8Be+5VmKorO4ae6vZiyevMo14ssNHqxCeS9wxpswJz6W2SzpDDC/k/C7kpOubRWp /OLxPzk0OcPw4AiIXcrf68ausl6E2T5Wm+j09+i6m07CkW59FQS/CL8gFgyYlwS3eNs1 hk3smVfXvWAVR4faXAEc2Wu06SgO+yZFVIBZGopnxNEt7G9ZnGnKdyyoZ38hckrqBdwl JhmQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b30si9189628edj.204.2020.07.13.01.25.06; Mon, 13 Jul 2020 01:25:29 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726360AbgGMIY6 (ORCPT + 99 others); Mon, 13 Jul 2020 04:24:58 -0400 Received: from mga04.intel.com ([192.55.52.120]:49516 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbgGMIY5 (ORCPT ); Mon, 13 Jul 2020 04:24:57 -0400 IronPort-SDR: yiOlnoNwbvbLeFPt9Z6AKLRL+63r7ZWSM5F8uIwQZqgSs3Ts5dtuopuuW4xIZDtvTEDNnFuYnw y8PduKqy1rUg== X-IronPort-AV: E=McAfee;i="6000,8403,9680"; a="146057365" X-IronPort-AV: E=Sophos;i="5.75,346,1589266800"; d="scan'208";a="146057365" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2020 01:24:57 -0700 IronPort-SDR: ivpD031Syyq6sRNRFaDb99m6vvcZZ25rrVtrbeH2JPwBnwok9C3l+mwbkn6Ix6wCpUfxOLZV9B US7A02fhl3Mg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,346,1589266800"; d="scan'208";a="269656686" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP; 13 Jul 2020 01:24:57 -0700 Received: from [10.249.229.49] (abudanko-mobl.ccr.corp.intel.com [10.249.229.49]) by linux.intel.com (Postfix) with ESMTP id 4245758080E; Mon, 13 Jul 2020 01:24:55 -0700 (PDT) Subject: Re: [PATCH v10 05/15] perf evlist: implement control command handling functions To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: <4af50c95-36f6-7a61-5a22-2949970fe7a5@linux.intel.com> <93e1c3b1-ee77-a94d-8806-049e0245fab7@linux.intel.com> From: Alexey Budankov Organization: Intel Corp. Message-ID: <218d3cf9-86fc-44ac-89eb-4b7ad422deb8@linux.intel.com> Date: Mon, 13 Jul 2020 11:24:54 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13.07.2020 6:20, Namhyung Kim wrote: > On Wed, Jul 8, 2020 at 4:50 PM Alexey Budankov > wrote: >> >> >> Implement functions of initialization, finalization and processing >> of control command messages coming from control file descriptors. >> Allocate control file descriptor as descriptor at struct pollfd >> object of evsel_list for atomic poll() operation. >> >> Signed-off-by: Alexey Budankov >> --- > [SNIP] >> +static int evlist__ctlfd_recv(struct evlist *evlist, enum evlist_ctl_cmd *cmd, >> + char *cmd_data, size_t data_size) >> +{ >> + int err; >> + char c; >> + size_t bytes_read = 0; >> + >> + memset(cmd_data, 0, data_size--); > > I overlooked the '--' at the end and thought there might be > buffer overflow.. Care to add a comment? If it wants to be more explicit then it could possibly be implemented like this: memset(cmd_data, 0, data_size); data_size--; > >> + >> + do { >> + err = read(evlist->ctl_fd.fd, &c, 1); > > Maybe I missed earlier discussion, but do we really want > this 1 byte read in a loop? That was the explicit request to support commands of variable length so it implements it like that. Alexei > > Thanks > Namhyung > > >> + if (err > 0) { >> + if (c == '\n' || c == '\0') >> + break; >> + cmd_data[bytes_read++] = c; >> + if (bytes_read == data_size) >> + break; >> + } else { >> + if (err == -1) >> + pr_err("Failed to read from ctlfd %d: %m\n", evlist->ctl_fd.fd); >> + break; >> + } >> + } while (1); >> + >> + pr_debug("Message from ctl_fd: \"%s%s\"\n", cmd_data, >> + bytes_read == data_size ? "" : c == '\n' ? "\\n" : "\\0"); >> + >> + if (err > 0) { >> + if (!strncmp(cmd_data, EVLIST_CTL_CMD_ENABLE_TAG, >> + (sizeof(EVLIST_CTL_CMD_ENABLE_TAG)-1))) { >> + *cmd = EVLIST_CTL_CMD_ENABLE; >> + } else if (!strncmp(cmd_data, EVLIST_CTL_CMD_DISABLE_TAG, >> + (sizeof(EVLIST_CTL_CMD_DISABLE_TAG)-1))) { >> + *cmd = EVLIST_CTL_CMD_DISABLE; >> + } >> + } >> + >> + return err; >> +}