Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4607776ybb; Tue, 24 Mar 2020 01:49:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtHYzFnOyLJSy4XpXI81FUAczMIAn6CtMROg8Zeo7bRkQ2aUlh+E8N2VVjp6990ftUBmUPK X-Received: by 2002:aca:474e:: with SMTP id u75mr2522030oia.52.1585039740239; Tue, 24 Mar 2020 01:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585039740; cv=none; d=google.com; s=arc-20160816; b=NwiRlp7s6DlP/SOFqb9LlHPh9XtM+hN++vahLT8OyUYfmTpYHre0r9xmm+SR4znnAG Tj9bRgCK0p5xC3rlsxrJb07Rr9AnVWvzqgUiTneRPZ9YA146b+mQRjVGNeiZWEzXw3dN qK6VjO3fe84okKK5lU2Xc5s3ooAwLgvqIKCTLoLhgONlvcjRpGgUSOvuDtDPyjGT6tDr 8I1C5RMmkOh4dVyVRkLFvwIKGKaTLm+dunEpu9D7SfRfRz3DhIaigr4UOeuJD+ZoEI40 2uIoavAkqe1UqAhWRudl1j37mZ/5kxJqM0PNqKf3ODvxgvpF3y0KMSGmEI5sYOvqUu8M KpFQ== 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:message-id :user-agent:mime-version:in-reply-to:references:cc:to:subject:from :date:dkim-signature; bh=bt3cOsdr0C8cVmPItgi4WdtrPk2V3/FsORYh/CBY/lI=; b=aQTubpSTdhEVhWZlWXqeqAKXa6fAuinEz5IsU5FO2HYarMbQGCxATLezetR77SGai6 pJCquEdHjzSHJ8VwmAQV21xdQanv3ZB8bR89sunbiDmlFZ/AWdD8Nf4tVfg/eYIQp7qV GBnPd/KRm8CqDfQMpILyBCyGgt7g7/XUsijbJ6QYGcdUUsKtr6MAHe6bGUYg1qmv452E TdPqs+Mx8Zlf3wFr7BTQfX/xyx1lTSCcpPa58h0TAbpiAnP6k70HMoxaAjGrL9tM9K/o leKAtcifcy4RhKp7Ibvni4BE8Euqbldp0meqIcyeUL+Iebs6GMf031tgKoi+NX1Mh8w4 fFFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vA3p3t11; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w31si8366446otb.59.2020.03.24.01.48.46; Tue, 24 Mar 2020 01:49:00 -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=@gmail.com header.s=20161025 header.b=vA3p3t11; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbgCXIs2 (ORCPT + 99 others); Tue, 24 Mar 2020 04:48:28 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:38762 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726462AbgCXIs2 (ORCPT ); Tue, 24 Mar 2020 04:48:28 -0400 Received: by mail-pj1-f67.google.com with SMTP id m15so1136077pje.3; Tue, 24 Mar 2020 01:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :user-agent:message-id:content-transfer-encoding; bh=bt3cOsdr0C8cVmPItgi4WdtrPk2V3/FsORYh/CBY/lI=; b=vA3p3t11FbBNkJKydmTaNNK3N5QW4gtpYzmlrgSF1JIT3wXicBoyZQ6X2qPv4Qvl27 atW1VCrGbGDlTg1jxwlWdC53pfi5pO12GqKqWwzjPJCi8yZkG6OkVtvJw1OLGhqdMKWJ YVITCgHIF79H5pfiZs2gYUgZSyX4kEOcNHQAOMwGVYaxcpUJsAqTXPerqQZwYHyBEzGP +AvKs5zDXWGhMNjVuH2KjgkSnFMBn/CbVRXP9QCpCiofOD2/GVjOn735K6I/pb/gBuj3 IWQbe9lei2ON6VbPeMLYajngQQ1HgV/7UZkMxmMQH9Ng01J1kjTH9anTeMvW0mB2L1lX KhRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:user-agent:message-id:content-transfer-encoding; bh=bt3cOsdr0C8cVmPItgi4WdtrPk2V3/FsORYh/CBY/lI=; b=BuT+swMKDciqMfV1Rt6b9L2ej13W46AaJH+nVcnlpLSEvMRgWhqVvEMlbPx0O1YQC9 Yts21G3x83lNM0WDFqrTtd6Vvoeh8v7hRSlzqdiaNgp+P+Yk1S0Scm9C2QYzvAQBni35 j1OjkBuMgmaMQ5IMAXvZp5p3rykDi7l3j92hy8ogMbDhRkHUodak1UmkyyaRL9Dz5Zjo pwKyyaqClj4WRk7Or93WOs0ytCCwzD8r2QlTmeoKtPnAOvxYiH54ZySEDgCM2R1yt0Ql b/aovxDs72u2Cpv+rwsja1I9yHm2IndN+msDJSle5b7pGg/ST/jVuMZsHl5FtOBgfmwY 0P5w== X-Gm-Message-State: ANhLgQ1kIirLbHksAVKFZvd36dbcWNzsFfXdJKR2uY1WiK//NFUwKKs4 DmmHF9mz15q0B5qvRnc6q5w= X-Received: by 2002:a17:90a:37c4:: with SMTP id v62mr4006668pjb.151.1585039706935; Tue, 24 Mar 2020 01:48:26 -0700 (PDT) Received: from localhost (14-202-190-183.tpgi.com.au. [14.202.190.183]) by smtp.gmail.com with ESMTPSA id f22sm10687021pgl.20.2020.03.24.01.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 01:48:26 -0700 (PDT) Date: Tue, 24 Mar 2020 18:48:20 +1000 From: Nicholas Piggin Subject: Re: [PATCH v11 3/8] powerpc/perf: consolidate read_user_stack_32 To: linuxppc-dev@lists.ozlabs.org, Michal Suchanek Cc: Arnaldo Carvalho de Melo , Alexander Shishkin , Allison Randal , Andy Shevchenko , Arnd Bergmann , Thiago Jung Bauermann , Benjamin Herrenschmidt , Sebastian Andrzej Siewior , Claudio Carvalho , Christophe Leroy , "David S. Miller" , "Eric W. Biederman" , Eric Richter , Greg Kroah-Hartman , Gustavo Luiz Duarte , Hari Bathini , Jordan Niethe , Jiri Olsa , Jonathan Cameron , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Rutland , Masahiro Yamada , Mauro Carvalho Chehab , Michael Neuling , Ingo Molnar , Michael Ellerman , Namhyung Kim , Nayna Jain , Paul Mackerras , Peter Zijlstra , Rob Herring , Thomas Gleixner , Valentin Schneider , Alexander Viro References: <20200225173541.1549955-1-npiggin@gmail.com> <184347595442b4ca664613008a09e8cea7188c36.1584620202.git.msuchanek@suse.de> In-Reply-To: <184347595442b4ca664613008a09e8cea7188c36.1584620202.git.msuchanek@suse.de> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1585039473.da4762n2s0.astroid@bobo.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Michal Suchanek's on March 19, 2020 10:19 pm: > There are two almost identical copies for 32bit and 64bit. >=20 > The function is used only in 32bit code which will be split out in next > patch so consolidate to one function. >=20 > Signed-off-by: Michal Suchanek > Reviewed-by: Christophe Leroy > --- > v6: new patch > v8: move the consolidated function out of the ifdef block. > v11: rebase on top of def0bfdbd603 > --- > arch/powerpc/perf/callchain.c | 48 +++++++++++++++++------------------ > 1 file changed, 24 insertions(+), 24 deletions(-) >=20 > diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.= c > index cbc251981209..c9a78c6e4361 100644 > --- a/arch/powerpc/perf/callchain.c > +++ b/arch/powerpc/perf/callchain.c > @@ -161,18 +161,6 @@ static int read_user_stack_64(unsigned long __user *= ptr, unsigned long *ret) > return read_user_stack_slow(ptr, ret, 8); > } > =20 > -static int read_user_stack_32(unsigned int __user *ptr, unsigned int *re= t) > -{ > - if ((unsigned long)ptr > TASK_SIZE - sizeof(unsigned int) || > - ((unsigned long)ptr & 3)) > - return -EFAULT; > - > - if (!probe_user_read(ret, ptr, sizeof(*ret))) > - return 0; > - > - return read_user_stack_slow(ptr, ret, 4); > -} > - > static inline int valid_user_sp(unsigned long sp, int is_64) > { > if (!sp || (sp & 7) || sp > (is_64 ? TASK_SIZE : 0x100000000UL) - 32) > @@ -277,19 +265,9 @@ static void perf_callchain_user_64(struct perf_callc= hain_entry_ctx *entry, > } > =20 > #else /* 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 *re= t) > +static int read_user_stack_slow(void __user *ptr, void *buf, int nb) > { > - if ((unsigned long)ptr > TASK_SIZE - sizeof(unsigned int) || > - ((unsigned long)ptr & 3)) > - return -EFAULT; > - > - return probe_user_read(ret, ptr, sizeof(*ret)); > + return 0; > } > =20 > static inline void perf_callchain_user_64(struct perf_callchain_entry_ct= x *entry, > @@ -312,6 +290,28 @@ static inline int valid_user_sp(unsigned long sp, in= t is_64) > =20 > #endif /* CONFIG_PPC64 */ > =20 > +/* > + * 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. > + */ The comment is actually probably better to stay in the 32-bit read_user_stack_slow implementation. Is that function defined on 32-bit purely so that you can use IS_ENABLED()? In that case I would prefer to put a BUG() there which makes it self documenting. Thanks, Nick > +static int read_user_stack_32(unsigned int __user *ptr, unsigned int *re= t) > +{ > + int rc; > + > + if ((unsigned long)ptr > TASK_SIZE - sizeof(unsigned int) || > + ((unsigned long)ptr & 3)) > + return -EFAULT; > + > + rc =3D probe_user_read(ret, ptr, sizeof(*ret)); > + > + if (IS_ENABLED(CONFIG_PPC64) && rc) > + return read_user_stack_slow(ptr, ret, 4); > + > + return rc; > +} > + > /* > * Layout for non-RT signal frames > */ > --=20 > 2.23.0 >=20 >=20 =