Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3704021ybb; Mon, 6 Apr 2020 14:01:29 -0700 (PDT) X-Google-Smtp-Source: APiQypKpF8ou0O+6dIplPmNFD2pFJfxwcqxXma/OGgCHRyFH0VdLC3SWyQtcnW/czCyNpP2z6MWh X-Received: by 2002:aca:61d4:: with SMTP id v203mr1127871oib.72.1586206889417; Mon, 06 Apr 2020 14:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586206889; cv=none; d=google.com; s=arc-20160816; b=TM/upuQcOdcwg4yypyF6x+AOxdWu4pDPtOm16aVkmK3TmLDe1FRA+b8kI2gE53v3TZ 1NAh2h7HqTn4od21phRqn4ZM0/Wy++VnFmMH867ZHJocDWLU9S5SlGFQI8iYsh+6TsiU ZNoM/gsk/gPI915fVCysLoy+UiFvki40hu9B632Toz0QV0FH4DgtLoAVGFXblmd5BnKQ ScbLhs3crC8W8NDdiGDDQdWoC0eOVoafbCSvzSKOGn4ztnKScIFvXD9NE2Loeh6GgrEl MQCGZKYteQhbR0BV9pOfEH0bYw/LDfRcdAUxtqjDYq9yIQbPUNBqZrGSk+X1HbqF6rRs ollg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xDcQX17HFUPfQcKCEWaZBkiGfQ7BVBDiiBRiD7w6IoI=; b=G1ZdUvrLmHaCLNdjnPlJz0gxfZccg5SHwQen/oB5lm1MYD8lM3YbxkZjLxDTMDYHVe 89jknyjQnG7q2nUJvLaozCzcEHA2Toa4y3F1WxKv1nhVGejqeeneTyDmkCWFsIC0K6rz 71IIUDbeDMndImUsU66Uq39ao7xG8n5vTxMH43RTI1k/cNmTk0pfgPjruAuSgGd6s+vr Lnmw2nQfmtfByGx9GwI0o2qz9h97+BGp/qauNHLHt9vpiRsBNA5BlALvHtT3JEFYgWND RQMCZ/1GWgu3aKlD0++ip6TEqU1Qdn5ffEMQsmAucjM2hVnLPYiw+9CXR8w8qrAvUnBJ KJkw== ARC-Authentication-Results: i=1; mx.google.com; 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 a17si265439oie.2.2020.04.06.14.01.16; Mon, 06 Apr 2020 14:01:29 -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; 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 S1726197AbgDFVAk (ORCPT + 99 others); Mon, 6 Apr 2020 17:00:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:40724 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgDFVAk (ORCPT ); Mon, 6 Apr 2020 17:00:40 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 08B77AA55; Mon, 6 Apr 2020 21:00:37 +0000 (UTC) From: Michal Suchanek To: linuxppc-dev@lists.ozlabs.org, Nicholas Piggin Cc: Michal Suchanek , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , linux-kernel@vger.kernel.org, Christophe Leroy Subject: [PATCH] powerpcs: perf: consolidate perf_callchain_user_64 and perf_callchain_user_32 Date: Mon, 6 Apr 2020 23:00:22 +0200 Message-Id: <20200406210022.32265-1-msuchanek@suse.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <1585896170.ohti800w9v.astroid@bobo.none> References: <1585896170.ohti800w9v.astroid@bobo.none> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org perf_callchain_user_64 and perf_callchain_user_32 are nearly identical. Consolidate into one function with thin wrappers. Suggested-by: Nicholas Piggin Signed-off-by: Michal Suchanek --- arch/powerpc/perf/callchain.h | 24 +++++++++++++++++++++++- arch/powerpc/perf/callchain_32.c | 21 ++------------------- arch/powerpc/perf/callchain_64.c | 14 ++++---------- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/arch/powerpc/perf/callchain.h b/arch/powerpc/perf/callchain.h index 7a2cb9e1181a..7540bb71cb60 100644 --- a/arch/powerpc/perf/callchain.h +++ b/arch/powerpc/perf/callchain.h @@ -2,7 +2,7 @@ #ifndef _POWERPC_PERF_CALLCHAIN_H #define _POWERPC_PERF_CALLCHAIN_H -int read_user_stack_slow(void __user *ptr, void *buf, int nb); +int read_user_stack_slow(const void __user *ptr, void *buf, int nb); void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs); void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry, @@ -16,4 +16,26 @@ static inline bool invalid_user_sp(unsigned long sp) return (!sp || (sp & mask) || (sp > top)); } +/* + * On 32-bit we just access the address and let hash_page create a + * HPTE if necessary, so there is no need to fall back to reading + * the page tables. Since this is called at interrupt level, + * do_page_fault() won't treat a DSI as a page fault. + */ +static inline int __read_user_stack(const void __user *ptr, void *ret, + size_t size) +{ + int rc; + + if ((unsigned long)ptr > TASK_SIZE - size || + ((unsigned long)ptr & (size - 1))) + return -EFAULT; + rc = probe_user_read(ret, ptr, size); + + if (rc && IS_ENABLED(CONFIG_PPC64)) + return read_user_stack_slow(ptr, ret, size); + + return rc; +} + #endif /* _POWERPC_PERF_CALLCHAIN_H */ diff --git a/arch/powerpc/perf/callchain_32.c b/arch/powerpc/perf/callchain_32.c index 8aa951003141..1b4621f177e8 100644 --- a/arch/powerpc/perf/callchain_32.c +++ b/arch/powerpc/perf/callchain_32.c @@ -31,26 +31,9 @@ #endif /* CONFIG_PPC64 */ -/* - * On 32-bit we just access the address and let hash_page create a - * HPTE if necessary, so there is no need to fall back to reading - * the page tables. Since this is called at interrupt level, - * do_page_fault() won't treat a DSI as a page fault. - */ -static int read_user_stack_32(unsigned int __user *ptr, unsigned int *ret) +static int read_user_stack_32(const unsigned int __user *ptr, unsigned int *ret) { - int rc; - - if ((unsigned long)ptr > TASK_SIZE - sizeof(unsigned int) || - ((unsigned long)ptr & 3)) - return -EFAULT; - - rc = probe_user_read(ret, ptr, sizeof(*ret)); - - if (IS_ENABLED(CONFIG_PPC64) && rc) - return read_user_stack_slow(ptr, ret, 4); - - return rc; + return __read_user_stack(ptr, ret, sizeof(*ret); } /* diff --git a/arch/powerpc/perf/callchain_64.c b/arch/powerpc/perf/callchain_64.c index df1ffd8b20f2..55bbc25a54ed 100644 --- a/arch/powerpc/perf/callchain_64.c +++ b/arch/powerpc/perf/callchain_64.c @@ -24,7 +24,7 @@ * interrupt context, so if the access faults, we read the page tables * to find which page (if any) is mapped and access it directly. */ -int read_user_stack_slow(void __user *ptr, void *buf, int nb) +int read_user_stack_slow(const void __user *ptr, void *buf, int nb) { int ret = -EFAULT; pgd_t *pgdir; @@ -65,16 +65,10 @@ int read_user_stack_slow(void __user *ptr, void *buf, int nb) return ret; } -static int read_user_stack_64(unsigned long __user *ptr, unsigned long *ret) +static int read_user_stack_64(const unsigned long __user *ptr, + unsigned long *ret) { - if ((unsigned long)ptr > TASK_SIZE - sizeof(unsigned long) || - ((unsigned long)ptr & 7)) - return -EFAULT; - - if (!probe_user_read(ret, ptr, sizeof(*ret))) - return 0; - - return read_user_stack_slow(ptr, ret, 8); + return __read_user_stack(ptr, ret, sizeof(*ret)); } /* -- 2.23.0