Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17729751ybl; Thu, 2 Jan 2020 10:56:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxtJ3/jf1LvrCu5MMQkbPqZfan5b1k4inxHxPjXt3WPr+7ORwWrMSawGuRxnoTqQmDY5rcL X-Received: by 2002:a05:6830:2057:: with SMTP id f23mr92936149otp.110.1577991411571; Thu, 02 Jan 2020 10:56:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577991411; cv=none; d=google.com; s=arc-20160816; b=ii1yEV8kazN2BIIxSwPPBUT5Ah4+Rl1cB3wrjipSi1s5fl1LdChhMFELqPjxkzs4PN hz2wWv3GS+xf0QyGAeP3qGwXXvndvoaX1FPTFDx9fvMw9ICvLVXSmUy5U08b8XAhx/y5 FUW0G8yaNmaFQtdR8RGMJHGiV03shg7u0h3tM41C6wYQDJ16qKpsq93M6w0OqVz61kIy Zbfpt1if13HLu8e5j2vhbM++F3Ffo2b3ddz9dksQkFikL6iElunVzGfIZb5hP7cBvfR0 WqaRhlpNjJe+aYeODfMbs1GKwaMrHwGE0J+muBJP3RpTSUeC+Vgv5QNjrEoIJ1Jk4xId Iqqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:date:from:dkim-signature; bh=SVhqJNc9KZvv3EKUfF1sirEUq6RG4WOzhSxBPIcUwS8=; b=EE4Tn0pNSJgO87WP/fzoi7LpbLYGvqWLa5YkUAur5NiqOBWsb68Ztl1pApApRFVovw /5//G83g00MS+2RBYMXfM8tZFMs717DMBfcPWkQilCdvLTK6xqWaRWRBUahiSDS9Lb+t YENgp49bIJxQP/zjp4H6uQ7Ms+bLwv4ARYijJh46ZhwqBTKJOmi0qgy37GqTsbwI0+k0 MU3Csp5O69yVr046m6J2pj2Ez2eMYuH3ktUkfjgoxj9SzeAWUZ4rwzIETLvRYs5uyPMw 6ooreiqZwgaIZx1UJNgKXJ/ViUtKsyKnYEe9yXAwtEKxOUH9zBXoJwARhn6kKngo2lvc XRWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@maine.edu header.s=google header.b=fGyQZIUO; 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 z65si17960554oia.33.2020.01.02.10.56.38; Thu, 02 Jan 2020 10:56:51 -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=pass header.i=@maine.edu header.s=google header.b=fGyQZIUO; 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 S1728129AbgABSz6 (ORCPT + 99 others); Thu, 2 Jan 2020 13:55:58 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:40192 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727951AbgABSz6 (ORCPT ); Thu, 2 Jan 2020 13:55:58 -0500 Received: by mail-qk1-f196.google.com with SMTP id c17so32072369qkg.7 for ; Thu, 02 Jan 2020 10:55:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maine.edu; s=google; h=from:date:to:cc:subject:message-id:user-agent:mime-version; bh=SVhqJNc9KZvv3EKUfF1sirEUq6RG4WOzhSxBPIcUwS8=; b=fGyQZIUOE1EwKvzSQHfBo9D3ndHkj15jXCmb5aymGBAJQfOtBwHVCRboNJoRoIcuGy KneQgA1RZQFkATPeiB9vPaiszLvna07HrPQkzMpne4sSlSGbKu0kc8WBF6XnL8ZvaQOi G7rByV+7OuPjDQmfQHsZwZTOGeYvxOViiRS58= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:user-agent :mime-version; bh=SVhqJNc9KZvv3EKUfF1sirEUq6RG4WOzhSxBPIcUwS8=; b=pHlyfeiCAWEM0ZrOt9UhrFzdC5DUC5VrFhrbdP6W7scuLeNhepOKr8xbu8VQ66WLy+ /y6vH3rBCeiyDECnqd0oQRZje9yQYXTGOgk2IS72R6Py3P0rY0LFiQmc5kQEmd7nn+Zs q0UDJ+D/WWxuq44zCNB6srkSfo2APJmeGOIgXwugI2eEl2yDaMCbEoBam5RJafVvPJQ9 egDU63wJYX+3pPpcmr2xp+1ew5RLd+huGxlRHxDFIqLzcdnxPINtSminpPUhqsC6EyRY taM3zq2kJuZCxv1HvbxzWn0GiNu9Df5keSpxA/1kOcoSz9hmmqTiJbHO6bVdNLAro9N0 VA3A== X-Gm-Message-State: APjAAAU/I3Hw+2KC1/iPY98aLU/kEGP4+Iy5QSPAk+jNMhvf1O9gixkh rlHFLu0smnthOZ5RN53/3zykPH0Kix8= X-Received: by 2002:a05:620a:16c6:: with SMTP id a6mr69034478qkn.140.1577991356527; Thu, 02 Jan 2020 10:55:56 -0800 (PST) Received: from macbook-air (weaver.eece.maine.edu. [130.111.218.23]) by smtp.gmail.com with ESMTPSA id v5sm17210024qth.70.2020.01.02.10.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2020 10:55:55 -0800 (PST) From: Vince Weaver X-Google-Original-From: Vince Weaver Date: Thu, 2 Jan 2020 13:55:47 -0500 (EST) X-X-Sender: vince@macbook-air To: linux-kernel@vger.kernel.org cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim Subject: [perf] perf_event_open() sometimes returning 0 Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello so I was tracking down some odd behavior in the perf_fuzzer which turns out to be because perf_even_open() sometimes returns 0 (indicating a file descriptor of 0) even though as far as I can tell stdin is still open. Before I waste too much time trying to track this down, is this a known issue? Some sample strace output: perf_event_open({type=PERF_TYPE_RAW, size=0x78 /* PERF_ATTR_SIZE_??? */, config=0x1313, ...}, 0, 3, -1, PERF_FLAG_FD_NO_GROUP) = 0 perf_event_open({type=PERF_TYPE_SOFTWARE, size=0x78 /* PERF_ATTR_SIZE_??? */, config=PERF_COUNT_SW_DUMMY, ...}, -1, 3, -1, PERF_FLAG_FD_NO_GROUP|PERF_FLAG_FD_OUTPUT) = 0 perf_event_open({type=PERF_TYPE_SOFTWARE, size=0x78 /* PERF_ATTR_SIZE_??? */, config=PERF_COUNT_SW_PAGE_FAULTS_MIN, ...}, 158266, 2, -1, PERF_FLAG_FD_CLOEXEC) = 0 perf_event_open({type=PERF_TYPE_HW_CACHE, size=0x78 /* PERF_ATTR_SIZE_??? */, config=PERF_COUNT_HW_CACHE_DTLB|PERF_COUNT_HW_CACHE_OP_READ<<8|PERF_COUNT_HW_CACHE_RESULT_MISS<<16, ...}, 0, 4, -1, PERF_FLAG_FD_NO_GROUP|PERF_FLAG_FD_CLOEXEC) = 0 perf_event_open({type=PERF_TYPE_RAW, size=0x78 /* PERF_ATTR_SIZE_??? */, config=0, ...}, -1, 0, -1, PERF_FLAG_FD_OUTPUT|PERF_FLAG_FD_CLOEXEC) = 0 On my Haswell system (running current git) I can reproduce things with a single call: memset(&pe[0],0,sizeof(struct perf_event_attr)); pe[0].type=PERF_TYPE_RAW; pe[0].size=120; pe[0].config=0x0ULL; pe[0].sample_period=0x4777c3ULL; pe[0].sample_type=PERF_SAMPLE_STREAM_ID; /* 200 */ pe[0].read_format=PERF_FORMAT_TOTAL_TIME_RUNNING|PERF_FORMAT_ID|PERF_FORMAT_GROUP; /* e */ pe[0].inherit=1; pe[0].exclude_hv=1; pe[0].exclude_idle=1; pe[0].enable_on_exec=1; pe[0].watermark=1; pe[0].precise_ip=0; /* arbitrary skid */ pe[0].mmap_data=1; pe[0].exclude_guest=1; pe[0].exclude_callchain_kernel=1; pe[0].mmap2=1; pe[0].comm_exec=1; pe[0].context_switch=1; pe[0].bpf_event=1; pe[0].wakeup_watermark=47545; pe[0].bp_type=HW_BREAKPOINT_EMPTY; pe[0].branch_sample_type=PERF_SAMPLE_BRANCH_KERNEL|PERF_SAMPLE_BRANCH_ANY_RETURN|PERF_SAMPLE_BRANCH_COND|0x800ULL; pe[0].sample_regs_user=42ULL; pe[0].sample_stack_user=0xfffffffd; pe[0].aux_watermark=25443; pe[0].aux_sample_size=8192; fd[0]=perf_event_open(&pe[0], -1, /* current thread */ 0, /* Only cpu 0 */ -1, /* New Group Leader */ PERF_FLAG_FD_OUTPUT|PERF_FLAG_FD_CLOEXEC /*a*/ );