From patchwork Mon Nov 6 21:04:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 10044539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 996AC60247 for ; Mon, 6 Nov 2017 21:22:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88364256E6 for ; Mon, 6 Nov 2017 21:22:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AD2F2A019; Mon, 6 Nov 2017 21:22:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E5166256E6 for ; Mon, 6 Nov 2017 21:22:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=YHxryZuQyrh9eVJ0VEJ3EZE2+YxuylY02z1Sk+wrQJc=; b=J+A EhO52BKRVN8M30U9ZQ3YmU63jRjeTHuDUZpraQn3Je+NvSQ4dKPOrR6V404M/q9V8FMEXVZmYTVr5 ZFcpQm07p7GF1e5pf97CiMYdkLlSxEZ+sTQWk24G3DSfBZoOkTXdGDuxi0cZdjkqjUkeDVDbIH58a FDb5kDMNtaF6Rce0yhlcvrGdFzfYO+8T6cetPBg1MI2MMaSLswectQDlW0mbgi016aOilmNvNGe86 Kx1+mJun6AYVMeziaKz+1MlP70AofL23zM96RJQn7+PIo7K+NLL+Ed8Fwh6In1d7o4M2g+/YKX3jy oRPvZ5o3KaIs4AnRTIqCzSr7G5AoNyQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eBoqE-0006el-G3; Mon, 06 Nov 2017 21:21:58 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eBoqC-0006bk-Ip for linux-arm-kernel@bombadil.infradead.org; Mon, 06 Nov 2017 21:21:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=wdY6WRuT+0yApARy/24IWI1RYgpB8jOrDR8d/rKBRf4=; b=eNvWkw5U4LzIoSgaSKjzgLJBS OLhB3o4sAsZjmApQM+9+ZlRwvg/4HSVKUWLnNJVIMQ+/IRiwcyAgw+aAj9jOOjYGKeXeckrnhfxu5 3lcowz4d66dYtj1tPi/uokxn4kLO4WZ6DjpUgTOi87EbPHahHnxUrIDvj8stLmImsWz+t23F9n7c0 QHHRal3gcdIbZnnxt0mz23xxq7Kar1XmVMEtkZwtM/pR9ttlCKwC6KN+kkM7xtiG7f7F8NnPc7JW9 uxWSwZSUKwSwuskQp+gPKtPcyAi6LSLyY3F9V6+VH2MN4qoHZJu8YQ1h6fI43MiaMqy1XeGKYjcdp OLkpwDLtg==; Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eBoZW-0003pN-B1 for linux-arm-kernel@lists.infradead.org; Mon, 06 Nov 2017 21:04:44 +0000 Received: by mail-io0-x242.google.com with SMTP id 101so17201394ioj.3 for ; Mon, 06 Nov 2017 13:04:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wdY6WRuT+0yApARy/24IWI1RYgpB8jOrDR8d/rKBRf4=; b=RNT6hXdxK5+U6TfowqRhTRIu/srtqHSCTPYcyCLV1Q/ps4m+wr7Uj8C1fX0WRbmfwv E/C71SLij0517S34BEY7FQvtQeh8/j7QnXyuJRESkfPzlfEbVEseQ57Oh9Bo3NDvfHlt o+Ujk1CDuVGadbaX7ZUXWNntSdMMIF0w2zWW6eCGKStvBLNdw2BPOPpY7itcDJuq8teN VK4qc/B7Z0kySg0PgfpP0ThLkmIyDhxie/LbVdUw/Xg40KKQZAWqMVBjTpwHbSKsv4Lr nFM9u1cAgoEPnp/FZziZgH7vQwsbbgNO9HLlPlFLVHAJxNPLQTMjkoYq4cCp9BPzJTnc mXTQ== 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=wdY6WRuT+0yApARy/24IWI1RYgpB8jOrDR8d/rKBRf4=; b=DoywOy2GK6CqZqcCj58QJAT8oRzS8BPnS9SqfG+b5PKBdTWxebKNCpT2/NRk88Kihy GcGYVksD4rBV5sAN9HxVokk3FYoy3TVUiCi+4oFdwjIB1ZOt7Bmv3g9JiLC/phkhdoJu vr1nRtrsdvRhn6ev/H99Xn9ZzNPamdPnCvVCeVEeWcO9qRdHqQJAr7gE5gTZ6dumBhVW IlRyLDpum3cIcP1Wpq7/vEkNgGpkpP0PWh8wBX+82DXcqWu5q8noQPhO0OPbBJKVgkSJ tKcn+E4/Cpo6hKJKfhgNb3i/6ML+OT0JMsZmctxRS/3MI/3tu1f2y0BQ9CaBeU7ROalT fwuw== X-Gm-Message-State: AJaThX6yXg+EfB6rbx9c2F6Oo3D1hE+xuqOAPPmndXkK9v/mZD16y9pO dNQa3lr9TKpKu1C/BDA/2H2mAA== X-Google-Smtp-Source: ABhQp+RF1kNSVXjMuLluOsWMmU08IaYNEjZTYFXFfr1pNSw/X6ZOH6DKhNvU+V1AY6NAoDFpKq/n5A== X-Received: by 10.107.147.135 with SMTP id v129mr20864702iod.289.1510002258768; Mon, 06 Nov 2017 13:04:18 -0800 (PST) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id i63sm6104666ioi.68.2017.11.06.13.04.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Nov 2017 13:04:18 -0800 (PST) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH v5 12/12] lib: vdso: do not expose gettimeofday, if no arch supported timer Date: Mon, 6 Nov 2017 13:04:09 -0800 Message-Id: <20171106210413.95388-1-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.403.gc27cc4dac6-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171106_210442_490673_445B92C5 X-CRM114-Status: GOOD ( 18.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Laura Abbott , Kees Cook , Ard Biesheuvel , Catalin Marinas , Kevin Brodsky , Will Deacon , Russell King , Andy Lutomirski , James Morse , Andrew Pinski , Dmitry Safonov , Andy Gross , John Stultz , Thomas Gleixner , Mark Salyzyn , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. If ARCH_PROVIDES_TIMER is not defined, do not expose gettimeofday. libc will default directly to syscall. Also ifdef clock_gettime switch cases and stubs if not supported and other unused components. 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 v3: - do not expose gettimeofday if arch does not support user space timer. v4: - update commit message to reflect overall reasoning of patch series. v5: - rebase --- lib/vdso/vgettimeofday.c | 52 +++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/lib/vdso/vgettimeofday.c b/lib/vdso/vgettimeofday.c index d64f60010bb2..079955162be8 100644 --- a/lib/vdso/vgettimeofday.c +++ b/lib/vdso/vgettimeofday.c @@ -30,7 +30,9 @@ #include "compiler.h" #include "datapage.h" +#ifdef ARCH_PROVIDES_TIMER DEFINE_FALLBACK(gettimeofday, struct timeval *, tv, struct timezone *, tz) +#endif DEFINE_FALLBACK(clock_gettime, clockid_t, clock, struct timespec *, ts) DEFINE_FALLBACK(clock_getres, clockid_t, clock, struct timespec *, ts) @@ -291,30 +293,6 @@ static notrace int do_boottime(const struct vdso_data *vd, struct timespec *ts) return 0; } -#else /* ARCH_PROVIDES_TIMER */ - -static notrace int do_realtime(const struct vdso_data *vd, struct timespec *ts) -{ - return -1; -} - -static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts) -{ - return -1; -} - -static notrace int do_monotonic_raw(const struct vdso_data *vd, - struct timespec *ts) -{ - return -1; -} - -static notrace int do_boottime(const struct vdso_data *vd, - struct timespec *ts) -{ - return -1; -} - #endif /* ARCH_PROVIDES_TIMER */ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) @@ -328,6 +306,7 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) case CLOCK_MONOTONIC_COARSE: do_monotonic_coarse(vd, ts); break; +#ifdef ARCH_PROVIDES_TIMER case CLOCK_REALTIME: if (do_realtime(vd, ts)) goto fallback; @@ -344,6 +323,7 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) if (do_boottime(vd, ts)) goto fallback; break; +#endif default: goto fallback; } @@ -353,6 +333,7 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) return clock_gettime_fallback(clock, ts); } +#ifdef ARCH_PROVIDES_TIMER notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) { const struct vdso_data *vd = __get_datapage(); @@ -374,21 +355,28 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) return 0; } +#endif int __vdso_clock_getres(clockid_t clock, struct timespec *res) { long nsec; - if (clock == CLOCK_REALTIME || - clock == CLOCK_BOOTTIME || - clock == CLOCK_MONOTONIC || - clock == CLOCK_MONOTONIC_RAW) - nsec = MONOTONIC_RES_NSEC; - else if (clock == CLOCK_REALTIME_COARSE || - clock == CLOCK_MONOTONIC_COARSE) + switch (clock) { + case CLOCK_REALTIME_COARSE: + case CLOCK_MONOTONIC_COARSE: nsec = LOW_RES_NSEC; - else + break; +#ifdef ARCH_PROVIDES_TIMER + case CLOCK_REALTIME: + case CLOCK_MONOTONIC: + case CLOCK_MONOTONIC_RAW: + case CLOCK_BOOTTIME: + nsec = MONOTONIC_RES_NSEC; + break; +#endif + default: return clock_getres_fallback(clock, res); + } if (likely(res != NULL)) { res->tv_sec = 0;