From patchwork Tue Oct 31 18:33:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 10035161 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 88683602B9 for ; Tue, 31 Oct 2017 18:36:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E4B228A8A for ; Tue, 31 Oct 2017 18:36:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 730F428A9A; Tue, 31 Oct 2017 18:36:11 +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 CF91C28A8A for ; Tue, 31 Oct 2017 18:36:10 +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=0aCFmeDBKoHkL6G+HvEtbii9LXBVPiGUFIwzXYVybis=; b=lzi gKTgRZykB+gCp9CRVTAfU0EF59FyJzH8pgL3QdVKKCnbQZp3siryheoHyUjov9swZlVHQkqvPwtkE 7fcyyUcKVCVZZa19I31bPSn4K53+j/aeKhEJv+YoXxNq6uHRNju6e2j3Wob5qUnuyOjVfKetg6qoF OyxICRzDUjMNwPQRrA6S5RbLtp/theTjWv/l/nhNySeiAxkYsgD5gza7sEn/5IDAEWMDpqQrzGJCN 3xfjLySsMc5vEIQfah/+GDJC0ZiHjaUFwOUrgqwN6/W8iDWxcVbd0rsNDfaVDWPncZt4M2uBqgUAu dxGF1Fn7CwbaHr48vx7mfjUBQl7L3kQ==; 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 1e9bON-0002KS-23; Tue, 31 Oct 2017 18:36:03 +0000 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e9bMX-0007Yo-Im for linux-arm-kernel@lists.infradead.org; Tue, 31 Oct 2017 18:34:21 +0000 Received: by mail-pf0-x244.google.com with SMTP id b85so14397784pfj.13 for ; Tue, 31 Oct 2017 11:33:49 -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; bh=JeWCtkdMsd3Oj7LKHB5+vBcKVphT1AGp5P1adgd3zoc=; b=KKnAhazBJxobMVOmMkU6sjDLTt2Hb8nOEev+gyVqq6lGwpj00V8s8J+EPCB4pygC6q /NAg8R5IGc8pCrHRd3bCLzbivbGYkpbaGw3F3z8igUEgmMhcj5fo12s39RzGD67/DGM1 UZPyZApYGrSd1Hz2ZxBZlepzpoMuj0+lVMbmbN+M8OAeibix+V+cwaa62QXy/QB+eG/Z 6x9wVHswqI9DULAlIe65KQcQX6HKG4fh2JY13Q8XP3Q7mNbnL+hT+73xlsujPJ6hELDp XP0pdcEqBC3OdvQ3ODt9ym2TT0IjkAllPqLND3qsZgHN3zopYRXUpH8LyvDQ3LY/PcMK f6DA== 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=JeWCtkdMsd3Oj7LKHB5+vBcKVphT1AGp5P1adgd3zoc=; b=CtwdTdLeUbAuRCZy2n0ieXbd5warolQfCvWMlJ/lSycFi4BobW1xzpY/HOatpDI6+t N//P6C6FvqTqX0cQsGX72/FtlBKNRanCWJ5ecuAX7ITtZyyQAELZVLLfGuFMFBo3hhXv RNHSbQUoebVkFkJHT/1EOVKuDNzLLWoXo+EwvkemxJQHNjOkDRXgmVOgCBnIGYFN7yE1 HqcmGIrOQF3vFbYuQJdM3IHxWfkqsGvTqpYmAh7GNOPQjbvlQ/OngOz7l1kHh71U2btc IMAK5/IFOwD6UK7///uj6lmEuYv8IsdwBrqV33ZZTKMIXBDq7YIo4GvfEiodoo/8I7W1 YMpw== X-Gm-Message-State: AMCzsaWAFHYf6oCfUDcbjbazQ4YOxPyrimO9kwZZWs72UmbMbFEZk9mT u3wFTcQLAI9ZBKxybfUFU3Swxw== X-Google-Smtp-Source: ABhQp+T5cudonyqcT2SEUxrl7VnCr7cYSSGPf5RLsl+/m7nvnhrx4JI2Nn2u8Zwyhr0mHgvPNSS2ig== X-Received: by 10.99.100.67 with SMTP id y64mr2714126pgb.349.1509474828667; Tue, 31 Oct 2017 11:33:48 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id m74sm5100080pfi.2.2017.10.31.11.33.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Oct 2017 11:33:48 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH v4 12/12] lib: vdso: do not expose gettimeofday, if no arch supported timer Date: Tue, 31 Oct 2017 11:33:40 -0700 Message-Id: <20171031183345.81499-1-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.rc2.357.g7e34df9404-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171031_113410_257566_289A7480 X-CRM114-Status: GOOD ( 16.46 ) 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. --- 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 4f500aba7e60..896e20e34a23 100644 --- a/lib/vdso/vgettimeofday.c +++ b/lib/vdso/vgettimeofday.c @@ -29,7 +29,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) @@ -285,30 +287,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) @@ -322,6 +300,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; @@ -338,6 +317,7 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) if (do_boottime(vd, ts)) goto fallback; break; +#endif default: goto fallback; } @@ -347,6 +327,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(); @@ -368,21 +349,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;