Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753089AbdHBLWo (ORCPT ); Wed, 2 Aug 2017 07:22:44 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36025 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751753AbdHBLWm (ORCPT ); Wed, 2 Aug 2017 07:22:42 -0400 Subject: struct pt_regs missing in /usr/include/ tree for eBPF program compile References: To: ast@kernel.org, Hendrik Brueckner , Linux Kernel Mailing List Cc: Martin Schwidefsky , Heiko Carstens From: Thomas-Mich Richter Organization: IBM LTC X-Forwarded-Message-Id: Date: Wed, 2 Aug 2017 13:22:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-IE Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 17080211-0016-0000-0000-000004DE2148 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17080211-0017-0000-0000-000028152C5D Message-Id: <49c5e39b-a7d9-1e2d-24ec-57852f7d1e51@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-02_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1708020185 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2740 Lines: 65 I work on the perf tool and its bpf support for IBM s390 and came across a strange issue compiling tools/testing/selftests/bpf/test_verifier.c on s390x. This is the compile error: gcc -Wall -O2 -I../../../include/uapi -I../../../lib -I../../../../include/generated -DHAVE_GENHDR -I../../../include test_verifier.c /root/linux-devel/tools/testing/selftests/bpf/libbpf.a -lcap -lelf -o /root/linux-devel/tools/testing/selftests/bpf/test_verifier In file included from test_verifier.c:63:0: ../../../include/uapi/linux/bpf_perf_event.h:14:17: error: field ‘regs’ has incomplete type struct pt_regs regs; This shows up in test case "unpriv: spill/fill of different pointers ldx" at line 1811. This issue is located in file /usr/include/linux/bpf_perf_event.h which is a copy of the linux kernels include/uapi/linux/bpf_perf_event.h. It contains: struct bpf_perf_event_data { struct pt_regs regs; __u64 sample_period; }; On s390 struct pt_regs is not exported to user space and does not appear anywhere in /usr/include. How about other architectures beside Intel? As far as I know 1. the struct pt_regs contains only kernel registers, no user space registers? 2. Is part of the kernel API and should not be exported at all? When I investigated the kernel side of the bpf() system call, the test case ends up in functions pe_prog_is_valid_access() and pe_prog_convert_ctx_access() via syscall(bpf) +--> bpf_prog_load() +--> find_prog_type() to load eBPF type specific verifiers | pe_prog_is_valid_access() and pe_prog_convert_ctx_access() +--> bpf_check() to verify (and modify) the eBPF +--> check_vfg() +--> do_check() +--> check_xadd() +--> check_mem_access() +--> check_ctx_access() +--> env->prog->aux->ops->is_valid_access which is set to pe_prog_is_valid_access() Now this last function expects and verifies struct pt_regs via struct member offsets which needs a correct struct pt_regs previously setup by user space eBPF program. This also requires a correct struct pt_regs in /usr/include/linux/bpf_perf_event.h (which includes /usr/include/{linux,asm,sym}/ptrace.h How to achieve this on a platform which does not export struct pt_regs to the user? Thanks a lot for your help. -- Thomas Richter, Dept 3303, IBM LTC Boeblingen Germany -- Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294