From patchwork Tue May 7 10:43:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 163482 Delivered-To: patches@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp1175404ilm; Tue, 7 May 2019 03:43:39 -0700 (PDT) X-Received: by 2002:a17:902:854a:: with SMTP id d10mr39698471plo.8.1557225819411; Tue, 07 May 2019 03:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557225819; cv=none; d=google.com; s=arc-20160816; b=GH2KB28kZ20/RKIlwLVMf6Rn56u+nDniQWpEOKrRMGHKTWh+tIUZGK0TtO3HQ9iGty qpoHJLyrT2q5wwzhrXqR8zxJxDyB8tv9cY945mYgHUwB6Pj4BkpHJ5MWneM8BtivJGbN xl999LhMWwb2+XIeqYz8CYDyjZpj+sHNz8crMAYjhxMntfokNu69YB46MYTaMseGToUy /Yvb6XXQlg+v8ArfRuvVUhmhG17GP/Tg0frK2molfu/+YFDqVe2ZFQLyv9iRfdB3X/AY 6rgE3cc9+4ibUriDGv2x3Eakcaq+ytiBJWo1PA6tikGoUHxb83dMpbPJ/sxz8D/W32xl 4VXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=7T/D1qg92Tnyc14faM+3S0JIoYMsReYT92zo9Cu0CII=; b=s+8nKHpzSrTzN+W6Z1QByHsPOb3IWKudRxLv+qNKbXKrmSzuRsyopZzHca98smu092 L7/8ckYa+HNKnG/Ckyv97bpqCXX8tx848zEc+gNilbfTMjET3atML/1Wo58H2k1T8g6Z ngDlZjgUtnecrxnh7fIC+i7Sgq8YOMUBs4sk4ovS/irvweaBTx0SekPMpZIoqIiH9eIg E3a8Vj5JgD+6I23nnoP93U3kK98nxTXYe4ekI2zwJr7V3RMXBCFZ6N+TQxVWFuI5KuAI zIxUBNY85FlpcdGgkVMI9zYZCuF0ZvkDAgqSJ7rYlWeqpJWtAfVB/v6TPSIZoN8OSCXk MAWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tTFCtmFn; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a69sor15352356pla.0.2019.05.07.03.43.39 for (Google Transport Security); Tue, 07 May 2019 03:43:39 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tTFCtmFn; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=7T/D1qg92Tnyc14faM+3S0JIoYMsReYT92zo9Cu0CII=; b=tTFCtmFnZNdn5p4drns18uhidO6+qiNWwjOKhjgitrUj7ggTkNJifUf8mX33JMvwHw tTajtMjYA/7O2uCCfhXGs66WqAfje8pFwShVglm+R4I46vkCeUglzA7QrCFl3bP1q0tg IA5Ak1R98ODCTASqUmFv+wmfmAMdb9y3NwlZxWUtbTne6CeFqcEldb+Ov4xE3V8lNC11 EdnfWGvjd5HTk8zgzUvU6qx99C3Qo0ySUNAjxALOQdKpqDrCeqC+uAqNnBrkldIFNY3g xzJd4/6TKzYunVWgNhyTv5hgYXp/b8lbyLM57IR9A23mD1NWKExS7ZxzV69I8Uy26Clj B5Ng== 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; bh=7T/D1qg92Tnyc14faM+3S0JIoYMsReYT92zo9Cu0CII=; b=nsSEcxkbwM7CU5Vucn8aRfIVmStGYCyBRf1hEXBZb8T0MeA7lszS5tky5y2COJoOvg VtEFCvIwkWqwEmAEV2sxcT36MEyBK/QvEv3fHjxRvTiAKwhUjzTrunwgcaGSqK1ulbwX 9RnC/yFToV2nI+/U5uD5ZYmFbLBVYOeSOzjQYdYQpE+soN16i44rbESGCYJC4DlcjGjk ymOmsNGFZXdXFslQCE1fgCP5go4K2KXm1MMzKn6iaBmW9LJIeelqm9j8oTe5q9la7rpM 6BDyR610wEpjzibWXHk9PAXjU/ReBA9J6wOphoXVb2Z9o14HEjv8ReuAFa5u6oz0jb+5 pBBA== X-Gm-Message-State: APjAAAVqaZecYwNgK04G4Fni32DgRaDVeDm4viI5YpS1//1ewfWThQmH 7mU2F75xsUuWP19cpTPCLKlPOtwW19jADg== X-Google-Smtp-Source: APXvYqweczXoqlP3gq6tHP9mQXqhc6LjcFygdKsz8i85GpuP/Rd7D5BJ+8HVBAY3B44hQ6uyrCKDkA== X-Received: by 2002:a17:902:6946:: with SMTP id k6mr39688859plt.81.1557225819041; Tue, 07 May 2019 03:43:39 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.252.67.140]) by smtp.gmail.com with ESMTPSA id m21sm39392056pff.146.2019.05.07.03.43.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 May 2019 03:43:38 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 1/3] ftrace: initial support for 32 bit apps Date: Tue, 7 May 2019 16:13:17 +0530 Message-Id: <1557225797-32604-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 Signed-off-by: Sumit Garg --- core/arch/arm/arm.mk | 18 +++++++++++++++--- core/arch/arm/kernel/ftrace.c | 7 ++++--- lib/libutee/arch/arm/utee_mcount_a32.S | 27 +++++++++++++++++++-------- lib/libutee/include/user_ta_header.h | 10 +++++----- ta/arch/arm/user_ta_header.c | 9 +++++++-- 5 files changed, 50 insertions(+), 21 deletions(-) -- 2.7.4 diff --git a/core/arch/arm/arm.mk b/core/arch/arm/arm.mk index be53df2..f03bf6c 100644 --- a/core/arch/arm/arm.mk +++ b/core/arch/arm/arm.mk @@ -89,7 +89,9 @@ platform-aflags-generic ?= -pipe arm32-platform-cflags-no-hard-float ?= -mfloat-abi=soft arm32-platform-cflags-hard-float ?= -mfloat-abi=hard -funsafe-math-optimizations -arm32-platform-cflags-generic ?= -mthumb -mthumb-interwork \ +arm32-platform-cflags-generic-thumb ?= -mthumb -mthumb-interwork \ + -fno-short-enums -fno-common -mno-unaligned-access +arm32-platform-cflags-generic-arm ?= -marm \ -fno-short-enums -fno-common -mno-unaligned-access arm32-platform-aflags-no-hard-float ?= @@ -138,7 +140,7 @@ core-platform-cflags += $(arm32-platform-cflags-no-hard-float) ifeq ($(CFG_UNWIND),y) core-platform-cflags += -funwind-tables endif -core-platform-cflags += $(arm32-platform-cflags-generic) +core-platform-cflags += $(arm32-platform-cflags-generic-thumb) core-platform-aflags += $(core_arm32-platform-aflags) core-platform-aflags += $(arm32-platform-aflags) endif @@ -166,7 +168,17 @@ ta_arm32-platform-cflags += $(arm32-platform-cflags) ta_arm32-platform-cflags += $(platform-cflags-optimization) ta_arm32-platform-cflags += $(platform-cflags-debug-info) ta_arm32-platform-cflags += -fpic -ta_arm32-platform-cflags += $(arm32-platform-cflags-generic) + +# Thumb mode doesn't support function graph tracing due to missing +# frame pointer support required to trace function call chain. So +# rather compile in ARM mode if function tracing is enabled. +ifeq ($(CFG_TA_FTRACE_SUPPORT),y) +ta_arm32-platform-cflags += $(arm32-platform-cflags-generic-arm) \ + -fno-omit-frame-pointer -mapcs +else +ta_arm32-platform-cflags += $(arm32-platform-cflags-generic-thumb) +endif + ifeq ($(arm32-platform-hard-float-enabled),y) ta_arm32-platform-cflags += $(arm32-platform-cflags-hard-float) else diff --git a/core/arch/arm/kernel/ftrace.c b/core/arch/arm/kernel/ftrace.c index 4b4a49b..8f34c6a 100644 --- a/core/arch/arm/kernel/ftrace.c +++ b/core/arch/arm/kernel/ftrace.c @@ -23,11 +23,12 @@ void ta_fbuf_init(struct ta_head *ta_head, struct tee_ta_session *s) size_t fbuf_size = 0; int count = 0; - if (ta_head->ftrace_buf_end > ta_head->ftrace_buf_start) - fbuf_size = ta_head->ftrace_buf_end - ta_head->ftrace_buf_start; + if (ta_head->ftrace_buf_end.ptr64 > ta_head->ftrace_buf_start.ptr64) + fbuf_size = ta_head->ftrace_buf_end.ptr64 - + ta_head->ftrace_buf_start.ptr64; if (fbuf_size >= MIN_FTRACE_BUF_SIZE) { - fbuf = (struct ftrace_buf *)ta_head->ftrace_buf_start; + fbuf = (struct ftrace_buf *)ta_head->ftrace_buf_start.ptr64; fbuf->head_off = sizeof(struct ftrace_buf); count = snprintk((char *)fbuf + fbuf->head_off, MAX_HEADER_STRLEN, diff --git a/lib/libutee/arch/arm/utee_mcount_a32.S b/lib/libutee/arch/arm/utee_mcount_a32.S index 0626baa..8923b8a 100644 --- a/lib/libutee/arch/arm/utee_mcount_a32.S +++ b/lib/libutee/arch/arm/utee_mcount_a32.S @@ -26,25 +26,36 @@ */ FUNC __gnu_mcount_nc, : stmdb sp!, {r0-r3, lr} - ldr r0, [sp, #20] /* lr of instrumented func */ #ifdef CFG_TA_GPROF_SUPPORT + ldr r0, [sp, #20] /* lr of instrumented func */ mcount_adj_pc r0, r0 mcount_adj_pc r1, lr /* instrumented func */ bl __mcount_internal #endif +#ifdef CFG_TA_FTRACE_SUPPORT + /* Get instrumented function's pc value */ + ldr r0, [sp, #16] + mcount_adj_pc r0, r0 + /* Get instrumented function's lr address pointer */ + sub r1, fp, #4 + bl ftrace_enter +#endif ldmia sp!, {r0-r3, ip, lr} bx ip END_FUNC __gnu_mcount_nc #ifdef CFG_TA_FTRACE_SUPPORT -/* - * ftrace is not yet supported in 32bit mode. Currently this is just a - * placeholder to avoid linking error. - */ FUNC __ftrace_return, : - push {lr} - pop {ip, lr} - bx ip + /* save return value regs */ + stmdb sp!, {r0-r3} + + /* get return address of parent func */ + bl ftrace_return + mov lr, r0 + + /* restore return value regs */ + ldmia sp!, {r0-r3} + bx lr END_FUNC __ftrace_return #endif diff --git a/lib/libutee/include/user_ta_header.h b/lib/libutee/include/user_ta_header.h index e2445b2..63e5d82 100644 --- a/lib/libutee/include/user_ta_header.h +++ b/lib/libutee/include/user_ta_header.h @@ -27,9 +27,9 @@ #define TA_FLAGS_MASK GENMASK_32(9, 0) -union ta_head_func_ptr { +union compat_ptr { uint64_t ptr64; - struct ta_head_func_ptr32 { + struct compat_ptr32 { uint32_t lo; uint32_t hi; } ptr32; @@ -39,10 +39,10 @@ struct ta_head { TEE_UUID uuid; uint32_t stack_size; uint32_t flags; - union ta_head_func_ptr entry; + union compat_ptr entry; #ifdef CFG_TA_FTRACE_SUPPORT - uintptr_t ftrace_buf_start; - uintptr_t ftrace_buf_end; + union compat_ptr ftrace_buf_start; + union compat_ptr ftrace_buf_end; #endif }; diff --git a/ta/arch/arm/user_ta_header.c b/ta/arch/arm/user_ta_header.c index 5496294..d294f1f 100644 --- a/ta/arch/arm/user_ta_header.c +++ b/ta/arch/arm/user_ta_header.c @@ -60,8 +60,13 @@ const struct ta_head ta_head __section(".ta_head") = { .entry.ptr64 = (uint64_t)__utee_entry, #endif #ifdef CFG_TA_FTRACE_SUPPORT - .ftrace_buf_start = (uintptr_t)&__ftrace_buf_start, - .ftrace_buf_end = (uintptr_t)__ftrace_buf_end, +#ifdef __ILP32__ + .ftrace_buf_start.ptr32 = { .lo = (uint32_t)&__ftrace_buf_start }, + .ftrace_buf_end.ptr32 = { .lo = (uint32_t)__ftrace_buf_end }, +#else + .ftrace_buf_start.ptr64 = (uint64_t)&__ftrace_buf_start, + .ftrace_buf_end.ptr64 = (uint64_t)__ftrace_buf_end, +#endif #endif };