Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4035742imm; Mon, 18 Jun 2018 08:08:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLA+9NhCYDHj68MqsP2OXCVCU6gVrgTBsZuLLJcOqQscxz2Ae50wDetpyRiVzszumqZcqIJ X-Received: by 2002:a62:d9c5:: with SMTP id b66-v6mr13923541pfl.41.1529334512319; Mon, 18 Jun 2018 08:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529334512; cv=none; d=google.com; s=arc-20160816; b=rgEMAaSnU3e44Ald307I9C7xXA3gdGmqoZcYX1B3U8x/znLFlqcOddd3MjAKXbvdoB 7UevB/tVeUzjCuJ6EgA7NO1SiMxzlHkTmumWrUWvUI1e1kBEVPoNckcj20KG2kYlniqL +/hYMa1aVaLWV9yMlT8VDaoHKZWxJxncp3Mcs5yB2peQ4VDlvxB5lgORdu+/ELd7oI5c 9tjKaYHU1Ns0xpVs43wTx8MB7BdJCQsmmnp2OcWoDMV9qhK8C5szgC9RicaktvCxyTLP uHMK9zX3eoXsqu2Y6QcvzVt+bXAGBuFflUajZ95EJGgqoQ2VWCwvhw2z4pcIAFp1vCvn QLsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=44dzkhIiEMIXdRAgb830BZbSIT2hzQQz0nLkhj4biIo=; b=WI40/WMxriFwS2+BfGa2nr1awjwdrYgPZ0sCmZOij88aqwLHPSF/pQ1MipEYKHBzjZ Nei9NfH/JXyo2is7zwpKHQDhvRlquboUY0DJeX/js/tEKHWt6L0jcJYQ5CQ6sFN9XoR5 2vWvkwSYOJzZzPc7dEF7SBweoZg4gur/g/rWah9wVWbx+StTzU/Z+i+N/RNTXQLAvwkf +nJ+mIwhw0ciNkZRAWSsOJt0Sn4ti95G+r00KVreWkHHntmywELV5rozgSixEFIGnqx2 0iZdxaHvxNT+JM76YZ16aB1YVlStmFraC/ugvYb7nXjBC70NyZuokTga1kclVryUUav/ 0kZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=u3mu1vaZ; 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=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4-v6si11951476pgs.244.2018.06.18.08.08.18; Mon, 18 Jun 2018 08:08:32 -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=@android.com header.s=20161025 header.b=u3mu1vaZ; 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=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965004AbeFRPHC (ORCPT + 99 others); Mon, 18 Jun 2018 11:07:02 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:37793 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935259AbeFRPG7 (ORCPT ); Mon, 18 Jun 2018 11:06:59 -0400 Received: by mail-pl0-f65.google.com with SMTP id 31-v6so9195938plc.4 for ; Mon, 18 Jun 2018 08:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=44dzkhIiEMIXdRAgb830BZbSIT2hzQQz0nLkhj4biIo=; b=u3mu1vaZwr1En0851lSuTKKwnl8MlK7E2cmvnm+KcI8TeTsDRVsXH+Mb6tGrPMzFiw 3+o3lvGHImj+aicqeeMdIaDbpMahSjiV9XHYQ3SbngJHgsR/PjQybIbjTYVh4CLoqbuP QoeP2SoAC9+LGBQCijjfF6QH1gYerte8wDHS8kHCRH3n5wRfygV61bBaH56csQwUbrnG d5rKPSwN0DfacumJSQAwa2GqhOp1h58yuY9NXxAdluMpPcPG4pRlQJz9XtJp2RZ3/Rbl cDueMzFTvo28y0ZTe1ARVO9NIvU1E5wS1RCWP6aXiuwFuPW7vT6VqBwo4z1jICYNOBFm tCmQ== 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=44dzkhIiEMIXdRAgb830BZbSIT2hzQQz0nLkhj4biIo=; b=d9xL6I7OtYVHlayzMsUvWvdSXO4sLw5Lt6BHJrtIC1ps16JDC0WXaOPb17Xqum8Zei zm4CDCb+q49TEaVKVJisxgoeb/RSDxITSJwrXfVm0nV+LhyRg6ePu0AVYCkcHNtwdwgu tvGaDLyHQ+TD5hek+HUQqQeW7GZf0i+LS2Lim4bzdnanSeg94xwK+lpfByspx9kJ7Ozg /ZyVu9d2JmwODs931ti4Rzd9p8a4/01Y43SvSr8BNzC0F8ls+XK2zfCVtrh9XxIx4xod ahl9HmwBUCkiFEJh5XK4/9t4o9OljNUbNJCizPZ34uzoA5fwCJ4FlXaux56HAKmzvgWN +0ew== X-Gm-Message-State: APt69E1m7cOYMbvTF3ENQkNvk+MWF9xZQUjT6MuxP9143eFT2jiPqIEN iajhKl2kh9N1pRam/xaolOQMmWYaCLM= X-Received: by 2002:a17:902:7484:: with SMTP id h4-v6mr14324821pll.154.1529334418004; Mon, 18 Jun 2018 08:06:58 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([2620:0:1000:1611:6077:8eec:bc7e:d0f4]) by smtp.gmail.com with ESMTPSA id i7-v6sm54830660pfa.34.2018.06.18.08.06.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 08:06:57 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Cc: Mark Salyzyn , James Morse , Russell King , Catalin Marinas , Will Deacon , Andy Lutomirski , Dmitry Safonov , John Stultz , Mark Rutland , Laura Abbott , Kees Cook , Ard Biesheuvel , Andy Gross , Kevin Brodsky , Andrew Pinski , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Jeremy Linton , Ingo Molnar , "Paul E. McKenney" Subject: RESEND [PATCH v5 03/12] arm: vdso: inline assembler operations to compiler.h Date: Mon, 18 Jun 2018 08:05:49 -0700 Message-Id: <20180618150613.10322-4-salyzyn@android.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180618150613.10322-1-salyzyn@android.com> References: <20180618150613.10322-1-salyzyn@android.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Take an effort to recode the arm64 vdso code from assembler to C previously submitted by Andrew Pinski , rework it for use in both arm and arm64, overlapping any optimizations for each architecture. But instead of landing it in arm64, land the result into lib/vdso and unify both implementations to simplify future maintenance. Move compiler-specific code to a local compiler.h file: - CONFIG_AEABI dependency check. - System call fallback functions standardized into a DEFINE_FALLBACK macro. - Replace arch_counter_get_cntvct() with arch_vdso_read_counter. - Deal with architecture specific unresolved references emitted by GCC. - Optimize handling of fallback calls in callers. - For time functions that always return success, do not waste time checking return value for switch to fallback. - Optimize unlikely nullptr checking in __vdso_gettimeofday, if tv null no need to proceed to fallback, as vdso is still capable of filling in the tv values. Signed-off-by: Mark Salyzyn Cc: James Morse Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Andy Lutomirski Cc: Dmitry Safonov Cc: John Stultz Cc: Mark Rutland Cc: Laura Abbott Cc: Kees Cook Cc: Ard Biesheuvel Cc: Andy Gross Cc: Kevin Brodsky Cc: Andrew Pinski Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: Jeremy Linton v2: - split first CL into 3 of 7 pieces v4: - switch to arch_vdso_read_counter as common API - update commit message to reflect overall reasoning v5: - comment about asm/arch_timer.h and asm/processor.h regarding why they have been added in compiler.h for porting clarity. - add linux/compiler.h in vgettimeofday.c because of notrace. - remove unnecessary dependency on linux/hrtimer.h --- arch/arm/vdso/compiler.h | 69 +++++++++++++++++++++ arch/arm/vdso/vgettimeofday.c | 109 +++++++++------------------------- 2 files changed, 96 insertions(+), 82 deletions(-) create mode 100644 arch/arm/vdso/compiler.h diff --git a/arch/arm/vdso/compiler.h b/arch/arm/vdso/compiler.h new file mode 100644 index 000000000000..af24502797e8 --- /dev/null +++ b/arch/arm/vdso/compiler.h @@ -0,0 +1,69 @@ +/* + * Userspace implementations of fallback calls + * + * Copyright (C) 2017 Cavium, Inc. + * Copyright (C) 2012 ARM Limited + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Author: Will Deacon + * Rewriten into C by: Andrew Pinski + */ + +#ifndef __VDSO_COMPILER_H +#define __VDSO_COMPILER_H + +#include /* for arch_counter_get_cntvct() */ +#include /* for cpu_relax() */ +#include +#include + +#ifndef CONFIG_AEABI +#error This code depends on AEABI system call conventions +#endif + +#define DEFINE_FALLBACK(name, type_arg1, name_arg1, type_arg2, name_arg2) \ +static notrace long name##_fallback(type_arg1 _##name_arg1, \ + type_arg2 _##name_arg2) \ +{ \ + register type_arg1 name_arg1 asm("r0") = _##name_arg1; \ + register type_arg2 name_arg2 asm("r1") = _##name_arg2; \ + register long ret asm ("r0"); \ + register long nr asm("r7") = __NR_##name; \ + \ + asm volatile( \ + " swi #0\n" \ + : "=r" (ret) \ + : "r" (name_arg1), "r" (name_arg2), "r" (nr) \ + : "memory"); \ + \ + return ret; \ +} + +#define arch_vdso_read_counter() arch_counter_get_cntvct() + +/* Avoid unresolved references emitted by GCC */ + +void __aeabi_unwind_cpp_pr0(void) +{ +} + +void __aeabi_unwind_cpp_pr1(void) +{ +} + +void __aeabi_unwind_cpp_pr2(void) +{ +} + +#endif /* __VDSO_COMPILER_H */ diff --git a/arch/arm/vdso/vgettimeofday.c b/arch/arm/vdso/vgettimeofday.c index 2474c17dc356..522094b147a2 100644 --- a/arch/arm/vdso/vgettimeofday.c +++ b/arch/arm/vdso/vgettimeofday.c @@ -22,21 +22,16 @@ * Reworked and rebased over arm version by: Mark Salyzyn */ -#include -#include -#include -#include #include -#include -#include -#include - -#ifndef CONFIG_AEABI -#error This code depends on AEABI system call conventions -#endif +#include /* for notrace */ +#include +#include "compiler.h" #include "datapage.h" +DEFINE_FALLBACK(gettimeofday, struct timeval *, tv, struct timezone *, tz) +DEFINE_FALLBACK(clock_gettime, clockid_t, clock, struct timespec *, ts) + static notrace u32 vdso_read_begin(const struct vdso_data *vd) { u32 seq; @@ -63,23 +58,6 @@ static notrace int vdso_read_retry(const struct vdso_data *vd, u32 start) return seq != start; } -static notrace long clock_gettime_fallback(clockid_t _clkid, - struct timespec *_ts) -{ - register struct timespec *ts asm("r1") = _ts; - register clockid_t clkid asm("r0") = _clkid; - register long ret asm ("r0"); - register long nr asm("r7") = __NR_clock_gettime; - - asm volatile( - " swi #0\n" - : "=r" (ret) - : "r" (clkid), "r" (ts), "r" (nr) - : "memory"); - - return ret; -} - static notrace int do_realtime_coarse(const struct vdso_data *vd, struct timespec *ts) { @@ -127,7 +105,7 @@ static notrace u64 get_ns(const struct vdso_data *vd) u64 cycle_now; u64 nsec; - cycle_now = arch_counter_get_cntvct(); + cycle_now = arch_vdso_read_counter(); cycle_delta = (cycle_now - vd->cs_cycle_last) & vd->cs_mask; @@ -200,85 +178,52 @@ static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts) #endif /* CONFIG_ARM_ARCH_TIMER */ -notrace int __vdso_clock_gettime(clockid_t clkid, struct timespec *ts) +notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) { - int ret = -1; - const struct vdso_data *vd = __get_datapage(); - switch (clkid) { + switch (clock) { case CLOCK_REALTIME_COARSE: - ret = do_realtime_coarse(vd, ts); + do_realtime_coarse(vd, ts); break; case CLOCK_MONOTONIC_COARSE: - ret = do_monotonic_coarse(vd, ts); + do_monotonic_coarse(vd, ts); break; case CLOCK_REALTIME: - ret = do_realtime(vd, ts); + if (do_realtime(vd, ts)) + goto fallback; break; case CLOCK_MONOTONIC: - ret = do_monotonic(vd, ts); + if (do_monotonic(vd, ts)) + goto fallback; break; default: - break; + goto fallback; } - if (ret) - ret = clock_gettime_fallback(clkid, ts); - - return ret; -} - -static notrace long gettimeofday_fallback(struct timeval *_tv, - struct timezone *_tz) -{ - register struct timezone *tz asm("r1") = _tz; - register struct timeval *tv asm("r0") = _tv; - register long ret asm ("r0"); - register long nr asm("r7") = __NR_gettimeofday; - - asm volatile( - " swi #0\n" - : "=r" (ret) - : "r" (tv), "r" (tz), "r" (nr) - : "memory"); - - return ret; + return 0; +fallback: + return clock_gettime_fallback(clock, ts); } notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) { - struct timespec ts; - int ret; - const struct vdso_data *vd = __get_datapage(); - ret = do_realtime(vd, &ts); - if (ret) - return gettimeofday_fallback(tv, tz); + if (likely(tv != NULL)) { + struct timespec ts; + + if (do_realtime(vd, &ts)) + return gettimeofday_fallback(tv, tz); - if (tv) { tv->tv_sec = ts.tv_sec; tv->tv_usec = ts.tv_nsec / 1000; } - if (tz) { + + if (unlikely(tz != NULL)) { tz->tz_minuteswest = vd->tz_minuteswest; tz->tz_dsttime = vd->tz_dsttime; } - return ret; -} - -/* Avoid unresolved references emitted by GCC */ - -void __aeabi_unwind_cpp_pr0(void) -{ -} - -void __aeabi_unwind_cpp_pr1(void) -{ -} - -void __aeabi_unwind_cpp_pr2(void) -{ + return 0; } -- 2.18.0.rc1.244.gcf134e6275-goog