Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp152173pxb; Tue, 10 Nov 2020 23:27:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzR8NkSTMLciLWbU/qCk6wE3ZlUJVNpd4kFNpqGDUxV3uypxnoH0aeBZR1peTb/7AW+SviX X-Received: by 2002:a50:cd09:: with SMTP id z9mr3598097edi.152.1605079649513; Tue, 10 Nov 2020 23:27:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605079649; cv=none; d=google.com; s=arc-20160816; b=xcCBnyc38uwEaDVxVG5YmH5MNxV8x7uiM0q9eyG1R7AJ6lvwRvwhUTp1fcQUqqKXjB +xdV3wUZ+8NgsLnf431ec0nFlGwtSTiIu//4AVP03nKm690jA5fwe7vIgjSJow0BSyll pBELlzgfzIH2J6UrZEa129Kg39MjNuBbBYOaBqlMbgrB/q7xApwaePMxTrmENSqvb2D4 qma+WWKvE6y6ZQ1uOF2ZVMOi4mmW4ksbmdvZJbA9aQEkIOdaCb4fBKB3nnmArYA20/Ym snFx7X2JmjrIVAXWzw85kbBS4o1i4KACtIP9LduJ6IyzHi/QQ271VJrq3w4v+Ytl2MOg UiLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=naJx7L5dVhnIJUTXsH59C3jAeMHe1RfwjImfd5ZlDuE=; b=D8+rJsYPKJgY6lu7CMFmCJdmaZ0XaaSQMJzeieEZCObFDPYcOkjKTLPW9qM0fNxTof ool1R4UTuJepbNXRafqYFLrnY9OM2y5HfbpnytSCEThnoUkb2xnRM1UjoU51fCdHfdP8 1+ePezNs9h8c5uykfQbsSx4I+oq9ThsBE8ylnl744pG6NpBjaZfjAcZkRgL2ii7Ajza3 NaMELsHab+jw28NNF0OROcxVIqdqSY5raxoerasuTApUKN5lrGOUhltLOY4EsbWWAi14 GS67NDN4j4V0eWyuBb9kft2ABD8O8JzH5rmFY63oaZpOZ7s6YmxjgciGGqQFEoT+Ww4I 6jxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e3eZMUsv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si793348edy.201.2020.11.10.23.27.06; Tue, 10 Nov 2020 23:27:29 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=e3eZMUsv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726229AbgKKHMs (ORCPT + 99 others); Wed, 11 Nov 2020 02:12:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726172AbgKKHMj (ORCPT ); Wed, 11 Nov 2020 02:12:39 -0500 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49496C0613D4 for ; Tue, 10 Nov 2020 23:12:39 -0800 (PST) Received: by mail-pj1-x1044.google.com with SMTP id s35so224748pjd.1 for ; Tue, 10 Nov 2020 23:12:39 -0800 (PST) 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=naJx7L5dVhnIJUTXsH59C3jAeMHe1RfwjImfd5ZlDuE=; b=e3eZMUsvleUyeAIyjLNcLJrmaIyRBthaonYzr6MKkhx5DdCk4JdcyHDhct8yvhKnOj 11Yi56zdVnRXk0zuYFv+MBPq1NF8oWPxsHsns/OWWKJO8nGIaemofz0LJSgcK3neO8tI eYBwDFhjKPFJIgmfR70Gb6GSWovbW8y6ftiVeN9keXUnSE2hEkdfUPULWvkiYVgkp4hT XPt1QyxdvnI89QGrXf7oxm2qM/Gm3TAYtrmZSQ8Ca71zWGF3xG+pIjcoXoxg8nym8+0o /fcbXNbTGLIW/ZwCXKfoFwn2kvM1qQ/y8PmylYHH0yhRY4xQ1jHHJRcwq5mFoilS28QG 6xFg== 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=naJx7L5dVhnIJUTXsH59C3jAeMHe1RfwjImfd5ZlDuE=; b=gCCNng1On7L73+p1INWobaWzQUnigyLg7c+Qv/pakBqZ44jmOS+cqiVYRqMn3OZ8eO 2GGO0snUf8MkSy704DaHyMbWY4Wv1U7RcKC0dW07CoB1Znc9NHtN0qzRmx1JhVVzGNgz S7/T4RlLwmxbohkEAFrnFuURtoCuSF+Z8T5xHuuC+wQm0JCcX/G6zZ0WO5RxAv3Zi13x y/oi0wPCuX+jyPiTEwpQ+FDOeTb50C7TCe6CoIwGpIswZWRl5DGHBsNIJZ7cPmMAboZg qWr+uXmOnasVS61goclLp7k7QXJT7bNOcwzCyIl8fuqHvODKh0atUQgOQqvq9etdu3dL eW0A== X-Gm-Message-State: AOAM532mA+sDw4QPiROzsW2XHznBIsmNgA5488FptlA32+p3BBbj9VBl giwr3xpfoMqU5C9KFbsNIhLTDA== X-Received: by 2002:a17:902:7606:b029:d3:d2dd:2b3b with SMTP id k6-20020a1709027606b02900d3d2dd2b3bmr20400514pll.67.1605078758833; Tue, 10 Nov 2020 23:12:38 -0800 (PST) Received: from localhost ([45.137.216.7]) by smtp.gmail.com with ESMTPSA id ce19sm1413829pjb.53.2020.11.10.23.12.37 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Nov 2020 23:12:38 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Andre Przywara , Dave Martin , James Clark , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Al Grant , Wei Li , John Garry , Will Deacon , Mathieu Poirier , linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v8 05/22] perf arm-spe: Fix packet length handling Date: Wed, 11 Nov 2020 15:11:32 +0800 Message-Id: <20201111071149.815-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111071149.815-1-leo.yan@linaro.org> References: <20201111071149.815-1-leo.yan@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When processing address packet and counter packet, if the packet contains extended header, it misses to account the extra one byte for header length calculation, thus returns the wrong packet length. To correct the packet length calculation, one possible fixing is simply to plus extra 1 for extended header, but will spread some duplicate code in the flows for processing address packet and counter packet. Alternatively, we can refine the function arm_spe_get_payload() to not only support short header and allow it to support extended header, and rely on it for the packet length calculation. So this patch refactors function arm_spe_get_payload() with a new argument 'ext_hdr' for support extended header; the packet processing flows can invoke this function to unify the packet length calculation. Signed-off-by: Leo Yan Reviewed-by: Andre Przywara --- .../arm-spe-decoder/arm-spe-pkt-decoder.c | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c index f1b4cb008837..04fd7fd7c15f 100644 --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c @@ -82,14 +82,15 @@ static unsigned int arm_spe_payload_len(unsigned char hdr) } static int arm_spe_get_payload(const unsigned char *buf, size_t len, + unsigned char ext_hdr, struct arm_spe_pkt *packet) { - size_t payload_len = arm_spe_payload_len(buf[0]); + size_t payload_len = arm_spe_payload_len(buf[ext_hdr]); - if (len < 1 + payload_len) + if (len < 1 + ext_hdr + payload_len) return ARM_SPE_NEED_MORE_BYTES; - buf++; + buf += 1 + ext_hdr; switch (payload_len) { case 1: packet->payload = *(uint8_t *)buf; break; @@ -99,7 +100,7 @@ static int arm_spe_get_payload(const unsigned char *buf, size_t len, default: return ARM_SPE_BAD_PACKET; } - return 1 + payload_len; + return 1 + ext_hdr + payload_len; } static int arm_spe_get_pad(struct arm_spe_pkt *packet) @@ -130,7 +131,7 @@ static int arm_spe_get_timestamp(const unsigned char *buf, size_t len, struct arm_spe_pkt *packet) { packet->type = ARM_SPE_TIMESTAMP; - return arm_spe_get_payload(buf, len, packet); + return arm_spe_get_payload(buf, len, 0, packet); } static int arm_spe_get_events(const unsigned char *buf, size_t len, @@ -145,14 +146,14 @@ static int arm_spe_get_events(const unsigned char *buf, size_t len, */ packet->index = arm_spe_payload_len(buf[0]); - return arm_spe_get_payload(buf, len, packet); + return arm_spe_get_payload(buf, len, 0, packet); } static int arm_spe_get_data_source(const unsigned char *buf, size_t len, struct arm_spe_pkt *packet) { packet->type = ARM_SPE_DATA_SOURCE; - return arm_spe_get_payload(buf, len, packet); + return arm_spe_get_payload(buf, len, 0, packet); } static int arm_spe_get_context(const unsigned char *buf, size_t len, @@ -160,8 +161,7 @@ static int arm_spe_get_context(const unsigned char *buf, size_t len, { packet->type = ARM_SPE_CONTEXT; packet->index = buf[0] & 0x3; - - return arm_spe_get_payload(buf, len, packet); + return arm_spe_get_payload(buf, len, 0, packet); } static int arm_spe_get_op_type(const unsigned char *buf, size_t len, @@ -169,41 +169,31 @@ static int arm_spe_get_op_type(const unsigned char *buf, size_t len, { packet->type = ARM_SPE_OP_TYPE; packet->index = buf[0] & 0x3; - return arm_spe_get_payload(buf, len, packet); + return arm_spe_get_payload(buf, len, 0, packet); } static int arm_spe_get_counter(const unsigned char *buf, size_t len, const unsigned char ext_hdr, struct arm_spe_pkt *packet) { - if (len < 2) - return ARM_SPE_NEED_MORE_BYTES; - packet->type = ARM_SPE_COUNTER; if (ext_hdr) packet->index = ((buf[0] & 0x3) << 3) | (buf[1] & 0x7); else packet->index = buf[0] & 0x7; - packet->payload = le16_to_cpu(*(uint16_t *)(buf + 1)); - - return 1 + ext_hdr + 2; + return arm_spe_get_payload(buf, len, ext_hdr, packet); } static int arm_spe_get_addr(const unsigned char *buf, size_t len, const unsigned char ext_hdr, struct arm_spe_pkt *packet) { - if (len < 8) - return ARM_SPE_NEED_MORE_BYTES; - packet->type = ARM_SPE_ADDRESS; if (ext_hdr) packet->index = ((buf[0] & 0x3) << 3) | (buf[1] & 0x7); else packet->index = buf[0] & 0x7; - memcpy_le64(&packet->payload, buf + 1, 8); - - return 1 + ext_hdr + 8; + return arm_spe_get_payload(buf, len, ext_hdr, packet); } static int arm_spe_do_get_packet(const unsigned char *buf, size_t len, -- 2.17.1