Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1871555pxb; Mon, 23 Aug 2021 06:41:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZmE51Z1nIrHBfzQBJeh8JEAWOw7ySy+hb3OWTBosH4OHFV6yIWSeyUIDCgWv3mwUKSx55 X-Received: by 2002:a05:6e02:e51:: with SMTP id l17mr23347935ilk.73.1629726093588; Mon, 23 Aug 2021 06:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629726093; cv=none; d=google.com; s=arc-20160816; b=Kb3Dp/b/nq3jg60WqV6KVwXuYNEkMY6/LiLyzW9VyQfzi/s6hRrppLkPaxClnyGUlQ xXzqkJEe8d068rrkTOBxiISDmMWwchMw4kPeJqKf3uPF/7U+GKMAbnhtQbEbSibqKgi3 OoZunaODx94jNOGtcGLpRQtnNJZ0tHfbXEj8dR4T4K3RChocTUzfza07wAfaDlWzUA/L QNHEEQoTZ82sQvuKiUYUqt3p2X3K1gVEyrxBiyf8OzArkA7YF7zsLKpmVWBWujX6tn7b kyt6GA3/vqqqFScR0yjLJvOFdD64yRGauBG3SJ5V8so6/k3rer1CCZUssZdxT1gZxK1Q QS8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vDAwDNrs70PDBIgh6tM7DTK9SFNnj5FHLm+1BK/qmTA=; b=DKrQIqVAzkREldA5fd14sAWDmCVmO+gErxnchrvjwm6ITBmLS8nTHuWVCXcVEhqGyU ePiTWcTMGQQL9GC6+AugvtEFIzxWjflJivedCjSsY+u/3AWten9j1aAqQ1wsOvnXpfy+ OodrYt+UZ87b+XnD7oHZ/hLG8ebzuPZ5rLEk6XOELR6SQcHSDINw51r+QrTQ4270RQqG KxzIg608jUNCSLAppxhhpWFVlh2PoPsky/QY30LnH/Yg6TLq+D3Yw1nNHMrAamqbeAM3 SHbCLmslYiC9pTJak/08VZCcUmJ7peZtwY+TbBfwUndzYuTxHmcMe75ofM1ygaoFnzDW s1Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=j3PPjl5x; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si17401986jat.94.2021.08.23.06.41.20; Mon, 23 Aug 2021 06:41:33 -0700 (PDT) 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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=j3PPjl5x; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbhHWNkX (ORCPT + 99 others); Mon, 23 Aug 2021 09:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbhHWNkW (ORCPT ); Mon, 23 Aug 2021 09:40:22 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD0E9C061575; Mon, 23 Aug 2021 06:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vDAwDNrs70PDBIgh6tM7DTK9SFNnj5FHLm+1BK/qmTA=; b=j3PPjl5xKUWP3vBHITYYskIxm 9iGIA8RlWfQV0i5U4EVe61Cd68byE2j/Te/ishZPvEBDwM9iKqXwhC7ZqGdXhxeUz+vP5X8kOJu55 fe6k/1ZBBysMwya/j49spaXzoniVoLgDdNPqxtpBydMrAFmP9H3vfLVIj6cLiG+NymWlJb8vot5cJ GFrmGwSJE5weKoRTeBO9KhvH8OncxES6OEd3oMKUKD5EL8kHMrnNP8O/t5PAiP/sWrNCCvwBIyLpw VgxvPcalVUgyPr1oaJR1LtObLCPOEar1FXKUrMbkRpGgIPW8nEcoeTvn7ug4KkYgJMswdJDK05lta KD+Ls+yEA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:47582) by pandora.armlinux.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mIAAc-00033W-FT; Mon, 23 Aug 2021 14:39:22 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1mIAAY-0006Dc-ER; Mon, 23 Aug 2021 14:39:18 +0100 Date: Mon, 23 Aug 2021 14:39:18 +0100 From: "Russell King (Oracle)" To: Leo Yan Cc: James Clark , Arnaldo Carvalho de Melo , Mike Leach , Will Deacon , Peter Zijlstra , Adrian Hunter , Andi Kleen , Mark Rutland , Catalin Marinas , linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Li Huafei , Jin Yao , Riccardo Mancini , Ingo Molnar , Namhyung Kim , Suzuki K Poulose , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , John Garry , coresight@lists.linaro.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 3/3] perf auxtrace arm: Support compat_auxtrace_mmap__{read_head|write_tail} Message-ID: <20210823133918.GP22278@shell.armlinux.org.uk> References: <20210809112727.596876-1-leo.yan@linaro.org> <20210809112727.596876-4-leo.yan@linaro.org> <6ce4057a-57cf-501d-6449-2069cd00ba57@arm.com> <20210823133043.GF100516@leoy-ThinkPad-X240s> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210823133043.GF100516@leoy-ThinkPad-X240s> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 23, 2021 at 09:30:43PM +0800, Leo Yan wrote: > Hi James, > > On Mon, Aug 23, 2021 at 01:23:42PM +0100, James Clark wrote: > > > > > > On 09/08/2021 12:27, Leo Yan wrote: > > > When the tool runs with compat mode on Arm platform, the kernel is in > > > 64-bit mode and user space is in 32-bit mode; the user space can use > > > instructions "ldrd" and "strd" for 64-bit value atomicity. > > > > > > This patch adds compat_auxtrace_mmap__{read_head|write_tail} for arm > > > building, it uses "ldrd" and "strd" instructions to ensure accessing > > > atomicity for aux head and tail. The file arch/arm/util/auxtrace.c is > > > built for arm and arm64 building, these two functions are not needed for > > > arm64, so check the compiler macro "__arm__" to only include them for > > > arm building. > > > > > > Signed-off-by: Leo Yan > > > --- > > > tools/perf/arch/arm/util/auxtrace.c | 32 +++++++++++++++++++++++++++++ > > > 1 file changed, 32 insertions(+) > > > > > > diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util/auxtrace.c > > > index b187bddbd01a..c7c7ec0812d5 100644 > > > --- a/tools/perf/arch/arm/util/auxtrace.c > > > +++ b/tools/perf/arch/arm/util/auxtrace.c > > > @@ -107,3 +107,35 @@ struct auxtrace_record > > > *err = 0; > > > return NULL; > > > } > > > + > > > +#if defined(__arm__) > > > +u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm) > > > +{ > > > + struct perf_event_mmap_page *pc = mm->userpg; > > > + u64 result; > > > + > > > + __asm__ __volatile__( > > > +" ldrd %0, %H0, [%1]" > > > + : "=&r" (result) > > > + : "r" (&pc->aux_head), "Qo" (pc->aux_head) > > > + ); > > > + > > > + return result; > > > +} > > > > Hi Leo, > > > > I see that this is a duplicate of the atomic read in arch/arm/include/asm/atomic.h > > Exactly. > > > For x86, it's possible to include tools/include/asm/atomic.h, but that doesn't > > include arch/arm/include/asm/atomic.h and there are some other #ifdefs that might > > make it not so easy for Arm. Just wondering if you considered trying to include the > > existing one? Or decided that it was easier to duplicate it? > > Good finding! > > With you reminding, I recognized that the atomic operations for > arm/arm64 should be improved for user space program. So far, perf tool > simply uses the compiler's atomic implementations (from > asm-generic/atomic-gcc.h) for arm/arm64; but for a more reliable > implementation, I think we should improve the user space program with > architecture's atomic instructions. No we should not. Sometimes, what's in the kernel is for the kernel's use only, and not for userspace's use. That may be because what works in kernel space does not work in userspace. For example, the ARMv6+ atomic operations can be executed in userspace _provided_ they are only used on memory which has an exclusive monitor. They can't be used on anything that is not "normal memory". Prior to ARMv6, the atomic operations rely on disabling interrupts. That facility is simply not available to userspace, so these must not be made available to userspace. The same applies to bitops. We've been here before in the past, when the kernel headers were not separated from the user ABI headers, and people would write programs that included e.g. bitops.h on x86 because they had optimised bitops code. This made the userspace programs very non-portable - without re-implementing userspace versions of this stuff in every userspace program that did this stuff. So no, having experienced the effects of this kind of thing in the past, the kernel should _not_ export architecture specific code in header files to userspace. Also, it should be pointed out that by doing so, you create a licensing issue. If the code is GPLv2, and you build your program such that it incorporates GPLv2 code, then if the userspace program is not GPLv2 compliant, you have a licensing problem, and in effect the program can be distributed. Please do not go down this route. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!