From patchwork Fri Oct 27 22:24:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 10030803 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 DCF926032C for ; Fri, 27 Oct 2017 22:43:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC49F28E92 for ; Fri, 27 Oct 2017 22:43:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF59728FF4; Fri, 27 Oct 2017 22:43:32 +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 3A1AA28E92 for ; Fri, 27 Oct 2017 22:43:32 +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=9VB005Q3Vv+sBjFsjYXikCr+rFLwIOPdBCUe4mNYxnI=; b=j4r T4UM29EhJTM6j9SGkezNwp7qtm/wXQgBMAkOFdMmR9ssJyc1AtvnH2/ECex2DrlFEQF0hQXERDfsk GRobnYCJlvbObf9PSjn6H1aaPoL4uhG8c+1TXpp3sazRMuN2ZuPaA2J26Hge9fb/Q8ysjsqt6ESFB PDwmnp50HewkqI3lp5+yzBgG0Dcv908y5i5dsQvObLgMtzz3aUKqjEXXk7F1uA9/v2Za/pi2ncSDt Ytaj9AdlYpHUtqufD0PGBrF+iZ1FF4TNn9/2kRkhU+C2/T2X2irLE/CZl4i0s/UT5Z4H0eb4tLoSD r8mJpQOf9vVEnjdNKXspXl25yL8pNGA==; 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 1e8DLX-0002pm-TE; Fri, 27 Oct 2017 22:43:23 +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 1e8DLE-0002Kr-8Y for linux-arm-kernel@bombadil.infradead.org; Fri, 27 Oct 2017 22:43:04 +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=oHHczvd6sG5XmxrvBzWHm93qmRxjLiazNh828ORt5Ug=; b=IEFNrXMML8SxBl4HL0yi6BpK3 uEEfnUCgc5ch87H0HKAzKPrvfti2WyVKtWb183ySVweHGQ5loK+Jj/1WclkxWB/FGOGFPYWCffwv3 B6X4jnqRqpihDPuptgWTAmRM9bUMxIIwMkVWSIUYhEMx2yqsBOnipXiTUUXpHpLSW12e9xFWQ3ago LLj8MDqt335KaygBBrhGOYskSC7bnRTm9XYBoEyf/sHrlwWIQfh5zDQpQ7JUC2KW3VNJBh7XkVBLU NgG57vpz+onDRwHnLfGK3+utp0rDTj1A5FDeRF0vgq3uCadVT9nnDBsi8/foWCjF8RCnsSnDFUJ7H cMAVzIHGQ==; Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e8D4B-0002vr-Vg for linux-arm-kernel@lists.infradead.org; Fri, 27 Oct 2017 22:25:31 +0000 Received: by mail-io0-x241.google.com with SMTP id j17so15724216iod.5 for ; Fri, 27 Oct 2017 15:25:06 -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=oHHczvd6sG5XmxrvBzWHm93qmRxjLiazNh828ORt5Ug=; b=GwnsRou/gIStPD3VN53Ui6XKsibEuaGiJFwAjUKald0hRVlJ9LR0S9HVS6fo/WkeHj Nduxl78V/L97BoV76CY+FkOq7b6IsS+lgpDYA9xxzeHSb9AerYvEd44EIGIDEQlb+nja dq2hHcGBcho3gma1JcPUspMhtGKxPw8zE4pOq4VXbhT5Qq81bHXPCbtgFzwO1+uD06IK gFEoyZH1/7Grm8flf2iaRF07ItkDJcAE7bx0Il1iLVuVNfSLckxqux9cPmpiiXB3VKHb AA6ISdDCtAAT7SGYWbDGqdbtmHe20gXJsr7MqxSX7HSvqHcjs0RlIhxslsGkw5YhaakX zI4w== 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=oHHczvd6sG5XmxrvBzWHm93qmRxjLiazNh828ORt5Ug=; b=nqiL5PTo9NM67MT/eXnAhWls/7GLwIDSVzpzq3JoLjd3wtPaugeUgiJCYoGCvbw4CX HuwfMK4APeAOO6mR40GrXYefmebQ39O4wb+S4rt2gQ5DkcIEBgxo7TjoJ6vUaEwwyKiP UvEyK1k3WO7w/wnMZzXdf3JtZW9s47I6omeDg37MRn2PjOi5qKljdoGw28A7iQi0XROB BlyOcKF4tUCChXafU7ryfOaX0Uuc9srwYnId/1elq8nHQic4htqtLKXrZK3CIHxAOEt0 3rQwJl25oxsEnEqSC1GAOm1oVL55BP/fpTcaL5YiW84oQTm9AEXbqiPCoIKDOK5kaNd9 fr3w== X-Gm-Message-State: AMCzsaWl6+8gqThq+LkMoSeq29Opt8sj3UrCtfMf7RADJOpSKCG1tc3N e16FeUiB3ibifyBLD6QPPkieOw== X-Google-Smtp-Source: ABhQp+RpwSsIGMY6lyZrFW1kEsq/aXvO9zFeKuFb+S2QEQ+CeckGwtfTwRfe+EdbUbgUm8mieHZu8g== X-Received: by 10.107.47.11 with SMTP id j11mr2317389ioo.225.1509143105493; Fri, 27 Oct 2017 15:25:05 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id q1sm1368447itc.9.2017.10.27.15.25.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Oct 2017 15:25:04 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH v3 02/12] arm: vdso: add include file defining __get_datapage() Date: Fri, 27 Oct 2017 15:24:50 -0700 Message-Id: <20171027222500.57068-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-20171027_232528_237112_E4657108 X-CRM114-Status: GOOD ( 25.14 ) 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 , Mark Salyzyn , James Morse , Andrew Pinski , Dmitry Safonov , Andy Gross , John Stultz , 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 Define the prototype for __get_datapage() in local datapage.h header. Rename all vdata variable that point to the datapage shortened to vd to relect a consistent and concise style. Make sure that all references to the datapage in vdso operations are readonly (const). Make sure datapage is first parameter to all subroutines to also be consistent. 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: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org v2: - split first CL into 2 of 7 pieces v3: - rebase (unchanged) --- arch/arm/vdso/datapage.h | 25 +++++++++++ arch/arm/vdso/vgettimeofday.c | 99 +++++++++++++++++++++---------------------- 2 files changed, 73 insertions(+), 51 deletions(-) create mode 100644 arch/arm/vdso/datapage.h diff --git a/arch/arm/vdso/datapage.h b/arch/arm/vdso/datapage.h new file mode 100644 index 000000000000..e3088bdfb946 --- /dev/null +++ b/arch/arm/vdso/datapage.h @@ -0,0 +1,25 @@ +/* + * Userspace implementations of __get_datapage + * + * 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 . + */ + +#ifndef __VDSO_DATAPAGE_H +#define __VDSO_DATAPAGE_H + +#include +#include + +extern const struct vdso_data *__get_datapage(void); + +#endif /* __VDSO_DATAPAGE_H */ diff --git a/arch/arm/vdso/vgettimeofday.c b/arch/arm/vdso/vgettimeofday.c index 8cf13af1323c..2474c17dc356 100644 --- a/arch/arm/vdso/vgettimeofday.c +++ b/arch/arm/vdso/vgettimeofday.c @@ -30,20 +30,19 @@ #include #include #include -#include #ifndef CONFIG_AEABI #error This code depends on AEABI system call conventions #endif -extern struct vdso_data *__get_datapage(void); +#include "datapage.h" -static notrace u32 vdso_read_begin(const struct vdso_data *vdata) +static notrace u32 vdso_read_begin(const struct vdso_data *vd) { u32 seq; do { - seq = READ_ONCE(vdata->tb_seq_count); + seq = READ_ONCE(vd->tb_seq_count); if ((seq & 1) == 0) break; @@ -55,12 +54,12 @@ static notrace u32 vdso_read_begin(const struct vdso_data *vdata) return seq; } -static notrace int vdso_read_retry(const struct vdso_data *vdata, u32 start) +static notrace int vdso_read_retry(const struct vdso_data *vd, u32 start) { u32 seq; smp_rmb(); /* Pairs with first smp_wmb in update_vsyscall */ - seq = READ_ONCE(vdata->tb_seq_count); + seq = READ_ONCE(vd->tb_seq_count); return seq != start; } @@ -81,38 +80,38 @@ static notrace long clock_gettime_fallback(clockid_t _clkid, return ret; } -static notrace int do_realtime_coarse(struct timespec *ts, - struct vdso_data *vdata) +static notrace int do_realtime_coarse(const struct vdso_data *vd, + struct timespec *ts) { u32 seq; do { - seq = vdso_read_begin(vdata); + seq = vdso_read_begin(vd); - ts->tv_sec = vdata->xtime_coarse_sec; - ts->tv_nsec = vdata->xtime_coarse_nsec; + ts->tv_sec = vd->xtime_coarse_sec; + ts->tv_nsec = vd->xtime_coarse_nsec; - } while (vdso_read_retry(vdata, seq)); + } while (vdso_read_retry(vd, seq)); return 0; } -static notrace int do_monotonic_coarse(struct timespec *ts, - struct vdso_data *vdata) +static notrace int do_monotonic_coarse(const struct vdso_data *vd, + struct timespec *ts) { struct timespec tomono; u32 seq; do { - seq = vdso_read_begin(vdata); + seq = vdso_read_begin(vd); - ts->tv_sec = vdata->xtime_coarse_sec; - ts->tv_nsec = vdata->xtime_coarse_nsec; + ts->tv_sec = vd->xtime_coarse_sec; + ts->tv_nsec = vd->xtime_coarse_nsec; - tomono.tv_sec = vdata->wtm_clock_sec; - tomono.tv_nsec = vdata->wtm_clock_nsec; + tomono.tv_sec = vd->wtm_clock_sec; + tomono.tv_nsec = vd->wtm_clock_nsec; - } while (vdso_read_retry(vdata, seq)); + } while (vdso_read_retry(vd, seq)); ts->tv_sec += tomono.tv_sec; timespec_add_ns(ts, tomono.tv_nsec); @@ -122,7 +121,7 @@ static notrace int do_monotonic_coarse(struct timespec *ts, #ifdef CONFIG_ARM_ARCH_TIMER -static notrace u64 get_ns(struct vdso_data *vdata) +static notrace u64 get_ns(const struct vdso_data *vd) { u64 cycle_delta; u64 cycle_now; @@ -130,29 +129,29 @@ static notrace u64 get_ns(struct vdso_data *vdata) cycle_now = arch_counter_get_cntvct(); - cycle_delta = (cycle_now - vdata->cs_cycle_last) & vdata->cs_mask; + cycle_delta = (cycle_now - vd->cs_cycle_last) & vd->cs_mask; - nsec = (cycle_delta * vdata->cs_mono_mult) + vdata->xtime_clock_snsec; - nsec >>= vdata->cs_shift; + nsec = (cycle_delta * vd->cs_mono_mult) + vd->xtime_clock_snsec; + nsec >>= vd->cs_shift; return nsec; } -static notrace int do_realtime(struct timespec *ts, struct vdso_data *vdata) +static notrace int do_realtime(const struct vdso_data *vd, struct timespec *ts) { u64 nsecs; u32 seq; do { - seq = vdso_read_begin(vdata); + seq = vdso_read_begin(vd); - if (vdata->use_syscall) + if (vd->use_syscall) return -1; - ts->tv_sec = vdata->xtime_clock_sec; - nsecs = get_ns(vdata); + ts->tv_sec = vd->xtime_clock_sec; + nsecs = get_ns(vd); - } while (vdso_read_retry(vdata, seq)); + } while (vdso_read_retry(vd, seq)); ts->tv_nsec = 0; timespec_add_ns(ts, nsecs); @@ -160,25 +159,25 @@ static notrace int do_realtime(struct timespec *ts, struct vdso_data *vdata) return 0; } -static notrace int do_monotonic(struct timespec *ts, struct vdso_data *vdata) +static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts) { struct timespec tomono; u64 nsecs; u32 seq; do { - seq = vdso_read_begin(vdata); + seq = vdso_read_begin(vd); - if (vdata->use_syscall) + if (vd->use_syscall) return -1; - ts->tv_sec = vdata->xtime_clock_sec; - nsecs = get_ns(vdata); + ts->tv_sec = vd->xtime_clock_sec; + nsecs = get_ns(vd); - tomono.tv_sec = vdata->wtm_clock_sec; - tomono.tv_nsec = vdata->wtm_clock_nsec; + tomono.tv_sec = vd->wtm_clock_sec; + tomono.tv_nsec = vd->wtm_clock_nsec; - } while (vdso_read_retry(vdata, seq)); + } while (vdso_read_retry(vd, seq)); ts->tv_sec += tomono.tv_sec; ts->tv_nsec = 0; @@ -189,12 +188,12 @@ static notrace int do_monotonic(struct timespec *ts, struct vdso_data *vdata) #else /* CONFIG_ARM_ARCH_TIMER */ -static notrace int do_realtime(struct timespec *ts, struct vdso_data *vdata) +static notrace int do_realtime(const struct vdso_data *vd, struct timespec *ts) { return -1; } -static notrace int do_monotonic(struct timespec *ts, struct vdso_data *vdata) +static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts) { return -1; } @@ -203,23 +202,22 @@ static notrace int do_monotonic(struct timespec *ts, struct vdso_data *vdata) notrace int __vdso_clock_gettime(clockid_t clkid, struct timespec *ts) { - struct vdso_data *vdata; int ret = -1; - vdata = __get_datapage(); + const struct vdso_data *vd = __get_datapage(); switch (clkid) { case CLOCK_REALTIME_COARSE: - ret = do_realtime_coarse(ts, vdata); + ret = do_realtime_coarse(vd, ts); break; case CLOCK_MONOTONIC_COARSE: - ret = do_monotonic_coarse(ts, vdata); + ret = do_monotonic_coarse(vd, ts); break; case CLOCK_REALTIME: - ret = do_realtime(ts, vdata); + ret = do_realtime(vd, ts); break; case CLOCK_MONOTONIC: - ret = do_monotonic(ts, vdata); + ret = do_monotonic(vd, ts); break; default: break; @@ -251,12 +249,11 @@ static notrace long gettimeofday_fallback(struct timeval *_tv, notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) { struct timespec ts; - struct vdso_data *vdata; int ret; - vdata = __get_datapage(); + const struct vdso_data *vd = __get_datapage(); - ret = do_realtime(&ts, vdata); + ret = do_realtime(vd, &ts); if (ret) return gettimeofday_fallback(tv, tz); @@ -265,8 +262,8 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) tv->tv_usec = ts.tv_nsec / 1000; } if (tz) { - tz->tz_minuteswest = vdata->tz_minuteswest; - tz->tz_dsttime = vdata->tz_dsttime; + tz->tz_minuteswest = vd->tz_minuteswest; + tz->tz_dsttime = vd->tz_dsttime; } return ret;