Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4035636imm; Mon, 18 Jun 2018 08:08:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKyIMJOv/tQx5/VV+JsuPvBhZwhK49bY24tow70A7Uxc6giPlmCWKkPrzDgs4jt6IjWHFfE X-Received: by 2002:a63:3c4c:: with SMTP id i12-v6mr11446949pgn.309.1529334507240; Mon, 18 Jun 2018 08:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529334507; cv=none; d=google.com; s=arc-20160816; b=jvvs/HQtPZN6B+hnwN7GPQsk4kkwHPQJsgfVoDdGJ7rhpJjbn1amFcy60S/rA/X3Wf F3NnNCEG65ECb0MiCU6s+LDOvIc4jAmIZxZyJu0mSEWjLjFiC16knRGSUFXvF1EuId/4 3wTp2yemqtgfVVYUxQ+QtCUw0fVNMqjNxL+oNLuRGmlXKhBNZCyRXD83FIAtmR8L7nKA 393tgZITfhv0Bx3nNh3LG+KnW4oa8vdx9EqmBi76OODnwfvWDwvz4oPxI1lGjW3uv0NM svQ8YAd0+A29y6VNNw7LyDiTdzfVk2kbSWwnDsP4UF3tgqaVzEDkoL+a+MbF/mXqRtCA nQtA== 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=PWSA8YbjNb3oiv9hZyIcAulkGwZy2kUuKoc3BzHF5n8=; b=pkUSS2GPzeEInDhUZDAi2UD4l++QgWRi1D+7BER7CgKaXVYyYeaOEDmVl7qpWu1m8R NHoCBZ+i5TcX+Wc217olBqNEgoKTFnniEEwRjDVsOzLU1q+URjQDJqZomIDY3oOM9GM3 Yo1/5s5RMwTZYrBEzBSv5mBTF2Gury9ydDM5J39T6nM07NPMmIZ6yIRGR/m8LlHalGKu rUyPEW0XowM7sRkacMSziDZJ3xJ5w8liHLHoHWl4z3LBOmyritKP9NwkGQ7KUKrDWtSd dPo3wVzQDHgtfNNIKA5C7djnro1nXChDQopLqfiwQ2Wq+GUcOzwnIf4XI+8/Y3A74fFP q25g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b="P8xUq/Ik"; 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 1-v6si15002804plo.20.2018.06.18.08.08.12; Mon, 18 Jun 2018 08:08:27 -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="P8xUq/Ik"; 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 S965187AbeFRPGi (ORCPT + 99 others); Mon, 18 Jun 2018 11:06:38 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:42185 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935427AbeFRPGf (ORCPT ); Mon, 18 Jun 2018 11:06:35 -0400 Received: by mail-pg0-f65.google.com with SMTP id c10-v6so7662265pgu.9 for ; Mon, 18 Jun 2018 08:06:35 -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=PWSA8YbjNb3oiv9hZyIcAulkGwZy2kUuKoc3BzHF5n8=; b=P8xUq/IkVNw1G/exqDtSmVyyXoaDmVtgN/5X8zD4hntfJbkgH/dOLwiIBe0z5/j7VX 9E+Wps5DcPv7S0o6gLiLlSs8my9cXdSYwAGujhJSq1+Jx7q147mwcBMmGwotioO77ehM 5L2r1loKdJvy3g7PJsKUCNurc0IDsEBZhIaOneNSGx2TiGkp6/uVGjMksG0vWPbvx8Ch 5L4I1SXpXFqFZi6GNPp7B8GNYLiVBr6dQLq15ZL+iCKEDPG5RHr9fEV/qqoE+3LyQv7d iY4FxBWjJLJvlD6/QJF68ce8Lajag03go31aex291StbVzhmdc5CK7wL0RJCe4JoFxHP Z0ZQ== 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=PWSA8YbjNb3oiv9hZyIcAulkGwZy2kUuKoc3BzHF5n8=; b=mmc1Y2QSRW4sbgGy0R1dXTJjZuu0nC1RceBJMW9Zb1pkxRD7bHBAWx4ij8cvAIbgvd koBLkBKd8x/rj2Rr25cue4v7MQSwsdtwqI5Ad/7fxxx78ZSKawCPx+JBu/xT+B0RKvg7 pY95gobMGgZxUO87/t/IO4B+4q3miWrJoOyWuHGTFTcZlVCZIUvDUhmhoqcMvrfqD55S 2wIWGvNMIIqLy8C4zyhO1Db51RiyWTC8cBEVxbQVcq1eoj7yxusDgOpfaIZUSjHeBmsu 0x/MOAQnLqZ+GIxb8pgCiTRUJnaBJ0cYfsQ9UWctdHdiOMwLjECcRo59MVgq7CTmNFKB op8Q== X-Gm-Message-State: APt69E2LrAywLVgvalN6ZvPqfCLCbjAWwwQsNOSKzQ+TT2TEB6tdjVjl iohsGsppEpob0fvlUOarTIjnjomaTlg= X-Received: by 2002:a63:3759:: with SMTP id g25-v6mr11545510pgn.59.1529334394984; Mon, 18 Jun 2018 08:06:34 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 08:06:34 -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 , Jinbum Park , Ingo Molnar , "Paul E. McKenney" Subject: RESEND [PATCH v5 01/12] arm: vdso: rename vdso_datapage variables Date: Mon, 18 Jun 2018 08:05:47 -0700 Message-Id: <20180618150613.10322-2-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. Rename seq_count to tb_seq_count. Rename tk_is_cntvct to use_syscall. Rename cs_mult to cs_mono_mult. All to align with the variables in the arm64 vdso datapage. Rework vdso_read_begin() and vdso_read_retry() functions to reflect modern access patterns for tb_seq_count field. Update copyright message to reflect the start of the contributions in this series. 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 1 of 7 pieces v4: - update commit message to reflect reasoning v5: - rebase --- arch/arm/include/asm/vdso_datapage.h | 6 +-- arch/arm/kernel/vdso.c | 17 ++++---- arch/arm/vdso/vgettimeofday.c | 61 +++++++++++++++------------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/arch/arm/include/asm/vdso_datapage.h b/arch/arm/include/asm/vdso_datapage.h index 9be259442fca..fa3e1856244d 100644 --- a/arch/arm/include/asm/vdso_datapage.h +++ b/arch/arm/include/asm/vdso_datapage.h @@ -29,8 +29,8 @@ * 32 bytes. */ struct vdso_data { - u32 seq_count; /* sequence count - odd during updates */ - u16 tk_is_cntvct; /* fall back to syscall if false */ + u32 tb_seq_count; /* sequence count - odd during updates */ + u16 use_syscall; /* fall back to syscall if true */ u16 cs_shift; /* clocksource shift */ u32 xtime_coarse_sec; /* coarse time */ u32 xtime_coarse_nsec; @@ -38,7 +38,7 @@ struct vdso_data { u32 wtm_clock_sec; /* wall to monotonic offset */ u32 wtm_clock_nsec; u32 xtime_clock_sec; /* CLOCK_REALTIME - seconds */ - u32 cs_mult; /* clocksource multiplier */ + u32 cs_mono_mult; /* clocksource multiplier */ u64 cs_cycle_last; /* last cycle value */ u64 cs_mask; /* clocksource mask */ diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index f4dd7f9663c1..c2c57f6b8c60 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -276,14 +276,14 @@ void arm_install_vdso(struct mm_struct *mm, unsigned long addr) static void vdso_write_begin(struct vdso_data *vdata) { - ++vdso_data->seq_count; + ++vdso_data->tb_seq_count; smp_wmb(); /* Pairs with smp_rmb in vdso_read_retry */ } static void vdso_write_end(struct vdso_data *vdata) { smp_wmb(); /* Pairs with smp_rmb in vdso_read_begin */ - ++vdso_data->seq_count; + ++vdso_data->tb_seq_count; } static bool tk_is_cntvct(const struct timekeeper *tk) @@ -307,10 +307,10 @@ static bool tk_is_cntvct(const struct timekeeper *tk) * counter again, making it even, indicating to userspace that the * update is finished. * - * Userspace is expected to sample seq_count before reading any other - * fields from the data page. If seq_count is odd, userspace is + * Userspace is expected to sample tb_seq_count before reading any other + * fields from the data page. If tb_seq_count is odd, userspace is * expected to wait until it becomes even. After copying data from - * the page, userspace must sample seq_count again; if it has changed + * the page, userspace must sample tb_seq_count again; if it has changed * from its previous value, userspace must retry the whole sequence. * * Calls to update_vsyscall are serialized by the timekeeping core. @@ -328,18 +328,19 @@ void update_vsyscall(struct timekeeper *tk) vdso_write_begin(vdso_data); - vdso_data->tk_is_cntvct = tk_is_cntvct(tk); + vdso_data->use_syscall = !tk_is_cntvct(tk); vdso_data->xtime_coarse_sec = tk->xtime_sec; vdso_data->xtime_coarse_nsec = (u32)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift); vdso_data->wtm_clock_sec = wtm->tv_sec; vdso_data->wtm_clock_nsec = wtm->tv_nsec; - if (vdso_data->tk_is_cntvct) { + if (!vdso_data->use_syscall) { vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; vdso_data->xtime_clock_sec = tk->xtime_sec; vdso_data->xtime_clock_snsec = tk->tkr_mono.xtime_nsec; - vdso_data->cs_mult = tk->tkr_mono.mult; + vdso_data->cs_mono_mult = tk->tkr_mono.mult; + /* tkr_mono.shift == tkr_raw.shift */ vdso_data->cs_shift = tk->tkr_mono.shift; vdso_data->cs_mask = tk->tkr_mono.mask; } diff --git a/arch/arm/vdso/vgettimeofday.c b/arch/arm/vdso/vgettimeofday.c index a9dd619c6c29..8cf13af1323c 100644 --- a/arch/arm/vdso/vgettimeofday.c +++ b/arch/arm/vdso/vgettimeofday.c @@ -1,18 +1,25 @@ /* - * Copyright 2015 Mentor Graphics Corporation. + * Userspace implementations of gettimeofday() and friends. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; version 2 of the - * License. + * Copyright (C) 2017 Cavium, Inc. + * Copyright (C) 2015 Mentor Graphics Corporation + * Copyright (C) 2012 ARM Limited * - * 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. + * 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 from arch64 version into C by: Andrew Pinski + * Reworked and rebased over arm version by: Mark Salyzyn */ #include @@ -31,32 +38,30 @@ extern struct vdso_data *__get_datapage(void); -static notrace u32 __vdso_read_begin(const struct vdso_data *vdata) -{ - u32 seq; -repeat: - seq = READ_ONCE(vdata->seq_count); - if (seq & 1) { - cpu_relax(); - goto repeat; - } - return seq; -} - static notrace u32 vdso_read_begin(const struct vdso_data *vdata) { u32 seq; - seq = __vdso_read_begin(vdata); + do { + seq = READ_ONCE(vdata->tb_seq_count); + + if ((seq & 1) == 0) + break; - smp_rmb(); /* Pairs with smp_wmb in vdso_write_end */ + cpu_relax(); + } while (true); + + smp_rmb(); /* Pairs with second smp_wmb in update_vsyscall */ return seq; } static notrace int vdso_read_retry(const struct vdso_data *vdata, u32 start) { - smp_rmb(); /* Pairs with smp_wmb in vdso_write_begin */ - return vdata->seq_count != start; + u32 seq; + + smp_rmb(); /* Pairs with first smp_wmb in update_vsyscall */ + seq = READ_ONCE(vdata->tb_seq_count); + return seq != start; } static notrace long clock_gettime_fallback(clockid_t _clkid, @@ -127,7 +132,7 @@ static notrace u64 get_ns(struct vdso_data *vdata) cycle_delta = (cycle_now - vdata->cs_cycle_last) & vdata->cs_mask; - nsec = (cycle_delta * vdata->cs_mult) + vdata->xtime_clock_snsec; + nsec = (cycle_delta * vdata->cs_mono_mult) + vdata->xtime_clock_snsec; nsec >>= vdata->cs_shift; return nsec; @@ -141,7 +146,7 @@ static notrace int do_realtime(struct timespec *ts, struct vdso_data *vdata) do { seq = vdso_read_begin(vdata); - if (!vdata->tk_is_cntvct) + if (vdata->use_syscall) return -1; ts->tv_sec = vdata->xtime_clock_sec; @@ -164,7 +169,7 @@ static notrace int do_monotonic(struct timespec *ts, struct vdso_data *vdata) do { seq = vdso_read_begin(vdata); - if (!vdata->tk_is_cntvct) + if (vdata->use_syscall) return -1; ts->tv_sec = vdata->xtime_clock_sec; -- 2.18.0.rc1.244.gcf134e6275-goog