From patchwork Thu Apr 19 01:34:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 133676 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp88060ljf; Wed, 18 Apr 2018 18:34:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx49gAN2IYIfgbULzHiJcX9WG9zyT1QnL2qQT1FcZBdT2v6rIyrKfqRakHldtGzsXI5cSjQno X-Received: by 2002:a17:902:7d85:: with SMTP id a5-v6mr4161598plm.102.1524101672881; Wed, 18 Apr 2018 18:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524101672; cv=none; d=google.com; s=arc-20160816; b=sZxnxzzRIuaqH9LoWcSZULUNTiYXaMojfQnNG8O0umM+uNtiZtEmAnORlqKf25tg26 m3xfjVwJoair4D3OKV/YFmaXB47lAiZJqi1Cq2xIQZSmdRIOmwYXV0gDK1aAYVXQBY0f mS3n4XLl2aI3q9Nc9OyiaAgQChGGNOVecFwEc3tiaittCdWVuC3UFu3sTduDS0TNYY9b TcSlkzzrbl9eYS/AAKlOFmgT6XkyR5GC2Iin0afW7pZ9AZH4RuNxX8jFXlJCMSgGoflP JrCi1ioZzkipqIF9An6YroezTsombYWP/UtO1cEmEkNkDvqocSPQpogEAd1XIE6XmIFd 0EsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Mo4KoBOnfav7uXjL6PFcsm72z+Fjm4rDnqqAiuV+NDg=; b=QyQHb1nRubnpud3TaV4Iav2Dt6QPgqOFjoDGGsj8Q/+xo1eq4Y83SLJn2us7TGx8IA 5j2G4eaSicAZ1/K8j2eIbviDLClXdZ2xs0fWzg7YEIMDnEGWTntDrpd5whkJeiZR57lY ALbNnRl1n0OmLUdndzLnI+P7qWp7IP+KmJYofc/EhwONfcsECI6Qg5AUH6cUWplW8RCZ Qki9S0yZAzumMDKRhThb91Pg7HwMUJyey1g75ITo0IlECpdVJeFWMhnVbnkx/Ao8zIub NXFawTjNaY9zMF7gRw6mQghC8oUla3Xk56NCA3YOBSnFJwnVpba7SPrP8C9EoSfICUYQ gvDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f89+vUkI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4-v6si2470457plo.190.2018.04.18.18.34.32; Wed, 18 Apr 2018 18:34:32 -0700 (PDT) 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=@linaro.org header.s=google header.b=f89+vUkI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753097AbeDSBe3 (ORCPT + 29 others); Wed, 18 Apr 2018 21:34:29 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:33482 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752255AbeDSBeZ (ORCPT ); Wed, 18 Apr 2018 21:34:25 -0400 Received: by mail-oi0-f66.google.com with SMTP id 126-v6so3405438oig.0 for ; Wed, 18 Apr 2018 18:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Mo4KoBOnfav7uXjL6PFcsm72z+Fjm4rDnqqAiuV+NDg=; b=f89+vUkIxXMdIV6UqdIsiuECs4UV9nCyfMsAbOIoJnJGlQKsvsdZ5Kw+U/i+zz2c4S Ef4eCbtHdVmPIADNsAFPVeH5zxdKLF+x1IFdXtnO/9eEkYy5gbIxnE1R4zC6jiE1Bn+B cVFFLhrXZesTcPLrtTrX+ZAPR3t0ZPer///AA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Mo4KoBOnfav7uXjL6PFcsm72z+Fjm4rDnqqAiuV+NDg=; b=HmmuJ5nolrsNZH7YQFlRqAzS9/T0BlIJlQg64L8/TbJqfHU54+WFFP8Ixebv/OMgi+ jYVr3aGkOizBEoFJ5JT6DUVE2AZZVzkmQOtULz0Y5BxNbzp/+pOXVxkhgng/wTRsQJE2 Qx/F9S7WNeVsP6fWh+s02qXFxacNojOfti5PyWLYZ+NdT5SPMOJCboBKpKVjUOMFbS5A mDZbNpDWdeDnkZ1qmRkHdF+HlrAvW1UFa5DYRBykbHAMetVqFp82Xgt1uZld4WBfLRjy p6ZyCnW6RGExdCVlkmWSe1M/saQkozEnqtyUHZJLxzsgMogNqgcu+1vBPgGLUPF30BQp Qv6w== X-Gm-Message-State: ALQs6tBIyCw9ySF22sIdDM9iWLBEVWPwBXsvCbO1uy9TmiNaFUQOF6Oi J1QPaLh8B5AVCFIPpSdDvuiWsg== X-Received: by 2002:aca:4441:: with SMTP id r62-v6mr2681144oia.227.1524101665340; Wed, 18 Apr 2018 18:34:25 -0700 (PDT) Received: from localhost.localdomain (li973-238.members.linode.com. [45.33.19.238]) by smtp.gmail.com with ESMTPSA id m84-v6sm1389662oia.1.2018.04.18.18.34.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 18:34:24 -0700 (PDT) From: Leo Yan To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH bpf-next 1/5] samples/bpf: Fix typo in comment Date: Thu, 19 Apr 2018 09:34:02 +0800 Message-Id: <1524101646-6544-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> References: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix typo by replacing 'iif' with 'if'. Signed-off-by: Leo Yan --- samples/bpf/bpf_load.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 1.9.1 diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c index bebe418..28e4678 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c @@ -393,7 +393,7 @@ static int load_elf_maps_section(struct bpf_map_data *maps, int maps_shndx, continue; if (sym[nr_maps].st_shndx != maps_shndx) continue; - /* Only increment iif maps section */ + /* Only increment if maps section */ nr_maps++; } From patchwork Thu Apr 19 01:34:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 133677 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp88109ljf; Wed, 18 Apr 2018 18:34:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx482D8H9H8jnXa8Hhmy2qqi5LhP547sDzqxMwcJgPJwqDiaCMw4YjpIeLmdg/QMxPHgxXYoo X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr4182613pla.345.1524101678414; Wed, 18 Apr 2018 18:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524101678; cv=none; d=google.com; s=arc-20160816; b=ZvBS1dtEb1OLXwWCpnQDhUVLnzpTNLep0DtwuOQHfLjrm+EMsrX4N7kJh0yAcDyLJk VciZjZIy4w4ZFUeCRN7ExnCT7JYHyRCV6mqIQMINuziPObCjU8i8RoUSH93QS+3qttY0 ocbLU8zzsdopz2um+CxtEieX//c9nF09jPCd9o/8s79ZW9I4czet71WXwexOD0Wx9wUF AVjPt1JDKf5RG+Sl06XnjnajCWH+xHp8geOF2uuAJi1uTBXM+F3W8vbMPvAjRi7QIdX1 wuZLykwd2ON2faVYlfkdp9T2ilNkFnEduz9zUYIVq72eWn9utA/olVy4uyODDKhNsphy 8cNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=xyuB+Mlp2g4Wi5znxx8xbYXUTHS8ghxQ1WZMqEfS+AA=; b=T4EcqSV0fArQqdm7XjhgqiRbrxIsUn0i8uw5oGg3qyW71C3SCk/7Yas25xMMEUFeJp pkJBJkdjRtFYICz2Z5aXjBaTwwVyvojdFsHbXczBZlvxq9EgRNzekuJmQSrScDbh4HFf /SLiR9pEnn4MJOszMGpJNeEF194/rKg9eG6NkNhCnXyD0/irlPeKQzDKiix5Pfrulj4v hM2lKjxgDDr8RldIGK6e2foTAB13NFK+gYBczSghu/YBB3OAtDi4U7HCnSSAS24sqSq6 dkJhCzT+RyDSyXMZUtv2e2nOF6LzHzMqcvZzIGrTf8zXYTat+4ix8KaI0e8+WlhTdwhA k8bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RDMOJXPf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4-v6si2401335pln.468.2018.04.18.18.34.38; Wed, 18 Apr 2018 18:34:38 -0700 (PDT) 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=@linaro.org header.s=google header.b=RDMOJXPf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753206AbeDSBef (ORCPT + 29 others); Wed, 18 Apr 2018 21:34:35 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:47020 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752899AbeDSBe3 (ORCPT ); Wed, 18 Apr 2018 21:34:29 -0400 Received: by mail-ot0-f195.google.com with SMTP id v64-v6so4098626otb.13 for ; Wed, 18 Apr 2018 18:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xyuB+Mlp2g4Wi5znxx8xbYXUTHS8ghxQ1WZMqEfS+AA=; b=RDMOJXPfOAdQUsMRhxI3Wnkg/86FFeuKOFD5f/+o1zko9jD74iiDUyaLqubiEjU1vO DIzhqrNMgmcwUknAsvRvWKCjk6JiTa/Ok4+rxI7zLJdp+wclHm6M34meBHn9mX9LRkgU tQSZ7gVjZJkln0bnVmc2T9xppPM+NfiuuMVgQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xyuB+Mlp2g4Wi5znxx8xbYXUTHS8ghxQ1WZMqEfS+AA=; b=Vqp7MYIV716BtSpqpZUqKdoPXnzfoGEAEZwZOaykGVbjEzZqEZvIP4TqhnsTemfqxm msjhUD5pEXTPOB4wX8ZV/YkEKdROT5iLZnXMsNXShGd3ahdak8FTvFHGU9v4wjyuhjq5 lxLKNU7x3CiQkqiMA7keXFa8vTfcAxTt9nWsfnW2YnpSplFKAjopjMcMgCxuNBPNsVLu r87BnmLnb36S+qLjZy7POY4X4FJTVWBweDDa7DAv/2MhFca1Q3kwhBzaYsq8+67LcoST CA5XXcMn6QQvjMl+yGcjeqmWc7Uv4OHR9y6xTM2oYRGG4vOANlPCA0wQcnhL6Q9ju4pH Mlpw== X-Gm-Message-State: ALQs6tBh7wP3sIE5Tgr2OyR7WtCVmMp2209oXmeITB7AOgNyI9PSIqLH E+nVvYVV90Om/NvpdxDOvGyiuw== X-Received: by 2002:a9d:1920:: with SMTP id j32-v6mr2897841ota.383.1524101669169; Wed, 18 Apr 2018 18:34:29 -0700 (PDT) Received: from localhost.localdomain (li973-238.members.linode.com. [45.33.19.238]) by smtp.gmail.com with ESMTPSA id m84-v6sm1389662oia.1.2018.04.18.18.34.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 18:34:28 -0700 (PDT) From: Leo Yan To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH bpf-next 2/5] samples/bpf: Dynamically allocate structure 'syms' Date: Thu, 19 Apr 2018 09:34:03 +0800 Message-Id: <1524101646-6544-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> References: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Structure 'syms' is used to store kernel symbol info by reading proc fs node '/proc/kallsyms', this structure is declared with 300000 entries and static linked into bss section. For most case the kernel symbols has less than 300000 entries, so it's safe to define so large array, but the side effect is bss section is big introduced by this structure and it isn't flexible. To fix this, this patch dynamically allocates memory for structure 'syms' based on parsing '/proc/kallsyms' line number at the runtime, which can save elf file required memory significantly. Before: text data bss dec hex filename 18841 1172 5199776 5219789 4fa5cd samples/bpf/sampleip After: text data bss dec hex filename 19101 1188 399792 420081 668f1 samples/bpf/sampleip Signed-off-by: Leo Yan --- samples/bpf/bpf_load.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c index 28e4678..c2bf7ca 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c @@ -651,8 +651,7 @@ void read_trace_pipe(void) } } -#define MAX_SYMS 300000 -static struct ksym syms[MAX_SYMS]; +static struct ksym *syms; static int sym_cnt; static int ksym_cmp(const void *p1, const void *p2) @@ -678,12 +677,30 @@ int load_kallsyms(void) break; if (!addr) continue; + sym_cnt++; + } + + syms = calloc(sym_cnt, sizeof(*syms)); + if (!syms) { + fclose(f); + return -ENOMEM; + } + + rewind(f); + while (!feof(f)) { + if (!fgets(buf, sizeof(buf), f)) + break; + if (sscanf(buf, "%p %c %s", &addr, &symbol, func) != 3) + break; + if (!addr) + continue; syms[i].addr = (long) addr; syms[i].name = strdup(func); i++; } - sym_cnt = i; qsort(syms, sym_cnt, sizeof(struct ksym), ksym_cmp); + + fclose(f); return 0; } From patchwork Thu Apr 19 01:34:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 133680 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp88579ljf; Wed, 18 Apr 2018 18:35:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/71xGgsUYAON4o9VUERXRSPFpm8Uq/Gylbybxc+nXW2WIBpzAIWqSm/nTwR8S4Hsy0d6u+ X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr4035005plo.220.1524101725284; Wed, 18 Apr 2018 18:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524101725; cv=none; d=google.com; s=arc-20160816; b=RcpxPt9/KlD23i3xv9mhwZ2zZhdowtEmhC8Oi6q8t7R7xYSTmO+uCqRHZUULbooGTy +S2Z4xIXSSozBZfp1mbjCb6wXltYMmCLW0VjyLSPimbVU472/obVZXE6+nefkAP6lvWZ 41Gke/atGgvY2WVe9pPNDRD4/jeycOG7YCrQkjaVtchUlWgdYC2bOGe8fiRpQAprOfYv PwU2qrq4ZYIleDg8CeBFpA7wrjMbC5sGAurotzdUcH3Thz8j2XlBcsirXO7sdGAlcrwz B6tpKtPuqB/fdWEjyCa7+F9BnPENtLHD4b2pPWhaCfJU1+E/1J/x7p7x/q1wYw1qct4f dAJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=bTeOv4ZbemmKNwy5sel+mHx//WZci0eMoeuPCgl8/r4=; b=qG2+R9g1n1ahuwV1UHbkQAtng4Cm8OPJ1/M6uTgIpdxIlBJTjnOEshbucYwtM/YdsU DJcc9x6tiLLGVSQxBRmO1zMatOrJJF36gUOf7g5oDiqZlEo52IML7AbxgvNWB/uMDsIF MvJdXhenoap4NSMetFZQZyMjaDzfkTogZbxhmaR00OiY8TL1JI9LT01q7a+Sd81LE0RK phAXNGES+YE+aPh2Plmr03Okhiq2rKdzRi71q9xvZaUCQQTM3Ff0PohIbCPI8JQYqept iK+eZ1JcEU+T8N6gFEwLoFgdpfd4f4hcypTWrpogOjWU5G/HwjnOZgOeJmiWieE/lQ9Z AreA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PaWzhRWB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si2088674pgt.575.2018.04.18.18.35.25; Wed, 18 Apr 2018 18:35:25 -0700 (PDT) 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=@linaro.org header.s=google header.b=PaWzhRWB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753420AbeDSBfW (ORCPT + 29 others); Wed, 18 Apr 2018 21:35:22 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:43204 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753131AbeDSBed (ORCPT ); Wed, 18 Apr 2018 21:34:33 -0400 Received: by mail-ot0-f195.google.com with SMTP id d9-v6so4106197oth.10 for ; Wed, 18 Apr 2018 18:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bTeOv4ZbemmKNwy5sel+mHx//WZci0eMoeuPCgl8/r4=; b=PaWzhRWByuSB7Dg8cFgLt2fgfktHbSr/64MustDqkIIJChQhfJ+4Jn6tW2+M2qEGx+ NYwTnxtSdMu80cxgyoQHTBvj2krXy8ymf5smIx+e2VhINEpqz+3stVunQApXotCKEMHK s0ZumkMdLUkELa1i61+PHkF8lF4lzOQbEnnGY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bTeOv4ZbemmKNwy5sel+mHx//WZci0eMoeuPCgl8/r4=; b=hCebnJz/VqjAJgLWWGAswOmYSLbVRE1uPiWX26xpzpbOi88tCabEIE8tUDEfjb81VH f34fS2i22U3dRhNdx1Oh4eMoZhjtG7FPIFfFo2h5poRKyGo7PkDiy42TIttZCrQCVGv/ Ec8BFh8Ju5nvrIR7azk/ROLbzwwrLOZ0zxvk02f3ROvrRyVxHNW8UkpJ6BOWdAKhyQV1 0SgM3NBYEAa/j/hLsFIdEa8uAIxl4Z8rHhqdzsSsd52be8JzIlI5cUcN7iwN1Ffx91xP WPJVWbThW6VPftuPJ2GvFZ1FuF4VzqUa3BLBHh8wpg51uuFNaomArvjpUdouXEdy2roU DufA== X-Gm-Message-State: ALQs6tCWM1SK1dRawcOfnsn4qWz5QfN8/Fd39LKz0eQAHhpty+qImW6S c4pmlmjqS2EQmYK5Cex3LP5GjA== X-Received: by 2002:a9d:4442:: with SMTP id f2-v6mr2884237otj.319.1524101673003; Wed, 18 Apr 2018 18:34:33 -0700 (PDT) Received: from localhost.localdomain (li973-238.members.linode.com. [45.33.19.238]) by smtp.gmail.com with ESMTPSA id m84-v6sm1389662oia.1.2018.04.18.18.34.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 18:34:32 -0700 (PDT) From: Leo Yan To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH bpf-next 3/5] samples/bpf: Use NULL for failed to find symbol Date: Thu, 19 Apr 2018 09:34:04 +0800 Message-Id: <1524101646-6544-4-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> References: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function ksym_search() is used to parse address and return the symbol structure, when the address is out of range for kernel symbols it returns the symbol structure of kernel '_stext' entry; this introduces confusion and it misses the chance to intuitively tell the address is out of range. This commit changes to use NULL pointer for failed to find symbol, user functions need to check the pointer is NULL and get to know the address has no corresponding kernel symbol for it. Signed-off-by: Leo Yan --- samples/bpf/bpf_load.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c index c2bf7ca..0c0584f 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c @@ -726,7 +726,7 @@ struct ksym *ksym_search(long key) /* valid ksym */ return &syms[start - 1]; - /* out of range. return _stext */ - return &syms[0]; + /* out of range. return NULL */ + return NULL; } From patchwork Thu Apr 19 01:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 133678 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp88153ljf; Wed, 18 Apr 2018 18:34:44 -0700 (PDT) X-Google-Smtp-Source: AIpwx48h5ccg7jcugbnNCYUtNCeWdi1b4/wlp4H9xzVwC0131+ETUQcXiCnEUW9A6ynRoSmA7DCe X-Received: by 2002:a17:902:7004:: with SMTP id y4-v6mr4278382plk.3.1524101684401; Wed, 18 Apr 2018 18:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524101684; cv=none; d=google.com; s=arc-20160816; b=P/v7EgaNzjjmkf/kl9MYK2V615vmI1jmUhDGynX4exwnpJj/UTryAxthBi2Svco0dL N1shvbV2vOAqUh/gLwN3OHSwY56RvTNk7pS4O3K2Q0yfBNaWnzkDfFNH7ewggJ5M0yjS /mKObK7MxACgucyjfRuHvG1MOgvbPB0lIFMp+kdwnDeBR8AwRsz/lNTCQyHxNcmx9Tm0 IvmLW9t8Xtz9DYBP3v04WmW1IXbFvK3/SCtfRSLbo0rzisecwZQw9psOSkXPGbMmrx6j j+Hgesma9ENXRLmyAunvfm//zQEeb2yMH7rN30bwLXi4RoYHCT79lN8XWzR6G/q0dNei jVVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Q9j3hjp6C3hGgRQ1gOH+nbpkRqMgT/dlUC6fOr13IQA=; b=DGoEwGdXRY1Lgo7OFqju5mldooY7K4SnMMdZasu+11lUVSIVskrJWdaNTh+dFUOy8v zI4UH6KTG3X0WI9aapvJkq8weAn8ar3+PSDnc6Z2L/sZV3aQRaNGCDGhr2Gqv2784q9c 9ZMCdtE66nrGL74P0l9rM7M2BrckThkIzPdI0Wkfly3wgWzPdsdUT5R0fA7csNaaeY6p yy6aMZNGmRLM0TlHC71z8Tu2v2egYe7TmDJuVD+r4a0L9KZoFmWJbvB97YrodrX/e8MD cVsUthvXiAfRlclOeysNecuSgmrJZtQKifAaUgMD72Yz31QjPcBBx9zGHrSHpPPuuQwf pjHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AXd1J2hI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4-v6si2401335pln.468.2018.04.18.18.34.44; Wed, 18 Apr 2018 18:34:44 -0700 (PDT) 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=@linaro.org header.s=google header.b=AXd1J2hI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753303AbeDSBek (ORCPT + 29 others); Wed, 18 Apr 2018 21:34:40 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:40496 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752899AbeDSBeh (ORCPT ); Wed, 18 Apr 2018 21:34:37 -0400 Received: by mail-ot0-f193.google.com with SMTP id h8-v6so4113337otj.7 for ; Wed, 18 Apr 2018 18:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q9j3hjp6C3hGgRQ1gOH+nbpkRqMgT/dlUC6fOr13IQA=; b=AXd1J2hIbd9dufSqCb5RReQEY8KXYcIev6xjCda8rkHKoqqV16bIhCg/H5MHe5LoP1 2/Xi3ShG93O2R598Ib2kt9kjmo0kGj45pj6Hb9DfCx9gjWmmS98gE6R09WdzoE5R2V2a hNLAwEOGngSEs1Z2IlXMsAoCpod4dTGoIx/pU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q9j3hjp6C3hGgRQ1gOH+nbpkRqMgT/dlUC6fOr13IQA=; b=DW0ks7Fs0BGgGJ7oK9A+DN55IKcOdaDil/1fXJjFsE0/AfMb5AeAmEivPiHrqMo3cu qQWOy2qzfYZMeUFUNJe+nUr2m0HZLQJeoUI7xSKAcgRXA9dPAZyvhomk3ixSsmELBpNf 0U6QM/Vbz+irNoO6dWyIZmVGZlOLbF+clYtH5Wc1p5rzyIThz/a3Msg1ylDkFMLhfW4O TCTz36fIlRolDelOogwbjby8BSalGYyC2PIdeHJc33BxlIAPt3ooHt4EwgbLzB2E8BAc JXXmozvKNQUqRMxBsCetLrjEVpJzqD3yZNKnXfcvLy3EeHBk0w6uL/S4pL8rj4uszTkS Dcrg== X-Gm-Message-State: ALQs6tDAxUqiKtSIO4YO69wqoL9RCUCh9dT6ObeMw/LLQuKdY+WbNJSl m9C+KPHvQc+2E5J0QHUxpMYAuA== X-Received: by 2002:a9d:2222:: with SMTP id o31-v6mr2992588ota.340.1524101676677; Wed, 18 Apr 2018 18:34:36 -0700 (PDT) Received: from localhost.localdomain (li973-238.members.linode.com. [45.33.19.238]) by smtp.gmail.com with ESMTPSA id m84-v6sm1389662oia.1.2018.04.18.18.34.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 18:34:35 -0700 (PDT) From: Leo Yan To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH bpf-next 4/5] samples/bpf: Refine printing symbol for sampleip Date: Thu, 19 Apr 2018 09:34:05 +0800 Message-Id: <1524101646-6544-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> References: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code defines macro 'PAGE_OFFSET' and uses it to decide if the address is in kernel space or not. But different architecture has different 'PAGE_OFFSET' so this program cannot be used for all platforms. This commit changes to check returned pointer from ksym_search() to judge if the address falls into kernel space or not, and removes macro 'PAGE_OFFSET' as it isn't used anymore. As result, this program has no architecture dependency. Signed-off-by: Leo Yan --- samples/bpf/sampleip_user.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 1.9.1 diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c index 4ed690b..0eea1b3 100644 --- a/samples/bpf/sampleip_user.c +++ b/samples/bpf/sampleip_user.c @@ -26,7 +26,6 @@ #define DEFAULT_FREQ 99 #define DEFAULT_SECS 5 #define MAX_IPS 8192 -#define PAGE_OFFSET 0xffff880000000000 static int nr_cpus; @@ -107,14 +106,13 @@ static void print_ip_map(int fd) /* sort and print */ qsort(counts, max, sizeof(struct ipcount), count_cmp); for (i = 0; i < max; i++) { - if (counts[i].ip > PAGE_OFFSET) { - sym = ksym_search(counts[i].ip); + sym = ksym_search(counts[i].ip); + if (sym) printf("0x%-17llx %-32s %u\n", counts[i].ip, sym->name, counts[i].count); - } else { + else printf("0x%-17llx %-32s %u\n", counts[i].ip, "(user)", counts[i].count); - } } if (max == MAX_IPS) { From patchwork Thu Apr 19 01:34:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 133679 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp88164ljf; Wed, 18 Apr 2018 18:34:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx48/iToJbkHJWNjmjwLByzvxhH/Q+QM9YwxKnTaHKEXeWQCeplbIXVi97U/DED5NXNEIKy7t X-Received: by 10.101.91.73 with SMTP id y9mr3426636pgr.93.1524101686546; Wed, 18 Apr 2018 18:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524101686; cv=none; d=google.com; s=arc-20160816; b=piNIT+XfpRorFkWX8IIyjUPnK5O7/7VYVdEZ0oIjrB2kT6+ubj8SZoe6ctFr5IyxNH xkiQvTeDD3XDpnSX5fHq5ot7Vl8CQBhTSyQUTJtOwpEKt9Nn1VbCCYsB6buz7elX0kac WwcZImA5zY83aKZyHnSi6vslQ/udA9raMCT3zPcjX5KlKmTgk9QCVNuWE+t7DfvNVU7B Exxquq5QXFWX/kRWec6MZo/Cn0W7mtdNUzfurV32vg4Rk3bK64ucL3szL8X3BqsSAI3a gdziXOTqrikGv0YRT5V9JajAhG18qsLt7f5Qt10gAPudoNUUkC8NsOh8MvT/bgiijzxY NBxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=afsRL9gkwOKNylX66mBBa9diOhkIPMbJz9/FrnqwgzU=; b=kPFYpjpU0MV3Ye8SB4hhuru17sKn88sTyA4kT7S6Txzz8buBAcUu8cmevmicF/1rBz LNElE6gyzb1pFI5GBRxLz+vl3VASNwfI2jLc6hNFG6ebBlI0Pb5u28YmtIxkqptw4pB1 /xwUl3DODbB+h29a3htwRZQkK9dcyt6xdD3h47NQ5zxSZ+3LT4X4UpziAe7/R+/B6E53 CZxuohAo5mdYjwBM8w9EESMC3NPYo59Jx9A+eoQrVoaDLSWxjDikP8iOwWVBh7FcrSAi HKV8HiJ6Jy42XjP2ucqVcLriyjDvFo+HHAVBoyW+QssHSk99aFidAHRMpQ/cswY8rYOi vwRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fgTjjZGr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12-v6si2399718pls.578.2018.04.18.18.34.46; Wed, 18 Apr 2018 18:34:46 -0700 (PDT) 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=@linaro.org header.s=google header.b=fgTjjZGr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753352AbeDSBen (ORCPT + 29 others); Wed, 18 Apr 2018 21:34:43 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:34813 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbeDSBel (ORCPT ); Wed, 18 Apr 2018 21:34:41 -0400 Received: by mail-oi0-f66.google.com with SMTP id e23-v6so3406481oiy.1 for ; Wed, 18 Apr 2018 18:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=afsRL9gkwOKNylX66mBBa9diOhkIPMbJz9/FrnqwgzU=; b=fgTjjZGrBZ6SQq/TevzkY9op6GlPvF6rasEkuoRs0B7Y3sh7A3TRgh654F1n4nmQeo gLUvLiUrX9ZKGk2hTARmXbDhSL7OoTcPR7JIiniss7kC6dCY8p1+PRihRB/RHbAN1XWN ADrSzCPMQMTCR+0+rIN6fD7/9qMoFJYQ/itfw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=afsRL9gkwOKNylX66mBBa9diOhkIPMbJz9/FrnqwgzU=; b=pTcbak6u7WTWgjyKjseNSS57rpztYM65fiygGvc3vuW9H3y4miAb6qfk0Ks1VNlCf7 0LUoCK6Oy+UdqnzVkj5M1OMA6AM3MykHbb0MFm1sapMXqsBi7toaVgnKUcISX6O7tH4l lnu9VtiNAxhR9uBp4lb3C7qtt+s9Kc7MOED8L+JKCzusVkWk/3uPH6jAWIr9HVzc0rVI JZO8vF7CnIDrW0l8WkU36w6QR7urRLR002/mGocS1ppeGHz92NflFyTgFTrYD+Rl81yl nDotRkDAGx6teT/jrToIQUvvmdgD2hMHrAaxBJRCwaA49D6Q0PTFgNP6Epjb+47Mu/Vz FPYw== X-Gm-Message-State: ALQs6tCjFYSExxfeSiVDHHUYoN8zmme9433Xgc34NsCrK9rG1nqZNHiN 6OMda0oX9bwWzaukLROsUXBNQCCuGb8= X-Received: by 2002:aca:42d5:: with SMTP id p204-v6mr2593201oia.264.1524101680460; Wed, 18 Apr 2018 18:34:40 -0700 (PDT) Received: from localhost.localdomain (li973-238.members.linode.com. [45.33.19.238]) by smtp.gmail.com with ESMTPSA id m84-v6sm1389662oia.1.2018.04.18.18.34.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 18:34:39 -0700 (PDT) From: Leo Yan To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH bpf-next 5/5] samples/bpf: Handle NULL pointer returned by ksym_search() Date: Thu, 19 Apr 2018 09:34:06 +0800 Message-Id: <1524101646-6544-6-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> References: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit handles NULL pointer returned by ksym_search() to directly print address hexadecimal value, the change is applied in 'trace_event', 'spintest' and 'offwaketime' programs. Signed-off-by: Leo Yan --- samples/bpf/offwaketime_user.c | 5 +++++ samples/bpf/spintest_user.c | 5 ++++- samples/bpf/trace_event_user.c | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c index 512f87a..fce2113 100644 --- a/samples/bpf/offwaketime_user.c +++ b/samples/bpf/offwaketime_user.c @@ -27,6 +27,11 @@ static void print_ksym(__u64 addr) if (!addr) return; sym = ksym_search(addr); + if (!sym) { + printf("%llx;", addr); + return; + } + if (PRINT_RAW_ADDR) printf("%s/%llx;", sym->name, addr); else diff --git a/samples/bpf/spintest_user.c b/samples/bpf/spintest_user.c index 3d73621..3140803 100644 --- a/samples/bpf/spintest_user.c +++ b/samples/bpf/spintest_user.c @@ -36,7 +36,10 @@ int main(int ac, char **argv) bpf_map_lookup_elem(map_fd[0], &next_key, &value); assert(next_key == value); sym = ksym_search(value); - printf(" %s", sym->name); + if (!sym) + printf(" %lx", value); + else + printf(" %s", sym->name); key = next_key; } if (key) diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c index 56f7a25..d2ab33e 100644 --- a/samples/bpf/trace_event_user.c +++ b/samples/bpf/trace_event_user.c @@ -33,6 +33,11 @@ static void print_ksym(__u64 addr) if (!addr) return; sym = ksym_search(addr); + if (!sym) { + printf("%llx;", addr); + return; + } + printf("%s;", sym->name); if (!strcmp(sym->name, "sys_read")) sys_read_seen = true;