From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9A6FC169C4 for ; Fri, 8 Feb 2019 17:51:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B34C20863 for ; Fri, 8 Feb 2019 17:51:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NlB/HFNd"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BI1SV2XT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B34C20863 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xvCskUs+yz9toGcKToSJU1h9LLrWlQVKjTzGEwnqx6w=; b=NlB/HFNdklxS2d LO/10PzF99OnH9lSBviVwtjOlgkid2vdwiTFaLaKOhKy99qeRE7bLYW+KOwgKeWQJekgcvZgt/KPv OTdle9YQd+8GUbc4cAq3wDo6sjXtlTfAd8A6l4zsDgczX9mvj9T0bk9vWSXiTsKCZPnVi5ToI8exp 9Y2h137Y2D181qununJNKjHpZrR9rSDHH3K+WeiUGRp/v5/gsEGXfHTYp/EUXgpJJlUvc5ZOrb3zi abI7t8OpE6oQvyfQxxI6U/olfmpWgagmLogjS/tWVFHpC3fHbgIZbKPgbPl3e6uSuhy5MAA4u30xX MPItnsdBTPUuu/7nzzEw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gsAJE-0004Tv-Jc; Fri, 08 Feb 2019 17:51:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gsAJA-0003oI-3g for linux-arm-kernel@bombadil.infradead.org; Fri, 08 Feb 2019 17:51:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=l91mJS3jGbF9gq6jv1RIvNd6hpeL7oMfGoeS3HqJt+4=; b=BI1SV2XTux5f9PCEN1UXgGeGn WxkDhVaPhdaWyTHzFgw8oeBtt9ePJXdsLAyj54d/B0xfVODmMw+ZcnhMnCBxg93bSWZWc9S56tVm9 XEGNP9JfV7CizAE8NorFLJxaDaWKZnCDDfoKKJQeKqq2A8yOFbWuPr77TJXUMCNpTJSpV67/bpCHN ieQbOHxH/5rwekUE4P/dLX96zxcKjrye7bneCmy6DUU5ydXuDnWNN/I4FyhcwgkEP12JK5ZlVjsvi zPLV+Tz+m5BcOawh+Eiv/iJGnrh1tkYPfN7oe0eK/B7GYopmkAvZoDqEnXHtfflsXBwjB3XnDGE26 UAWCXx9tg==; Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gsA41-0006dt-No for linux-arm-kernel@lists.infradead.org; Fri, 08 Feb 2019 17:35:49 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3FA781596; Fri, 8 Feb 2019 09:35:44 -0800 (PST) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2C80E3F719; Fri, 8 Feb 2019 09:35:42 -0800 (PST) Date: Fri, 8 Feb 2019 17:35:39 +0000 From: Will Deacon To: Thomas Gleixner Subject: Re: [PATCH v2 06/28] kernel: Define gettimeofday vdso common code Message-ID: <20190208173539.GD24375@fuggles.cambridge.arm.com> References: <20181129170530.37789-1-vincenzo.frascino@arm.com> <20181129170530.37789-7-vincenzo.frascino@arm.com> <20181207175321.GA11430@edgewater-inn.cambridge.arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181207175321.GA11430@edgewater-inn.cambridge.arm.com> User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190208_173546_101417_4E49ECE3 X-CRM114-Status: GOOD ( 30.27 ) 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: linux-arch@vger.kernel.org, Arnd Bergmann , Catalin Marinas , Daniel Lezcano , Russell King , Ralf Baechle , Mark Salyzyn , Paul Burton , Vincenzo Frascino , Peter Collingbourne , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Thomas, On Fri, Dec 07, 2018 at 05:53:21PM +0000, Will Deacon wrote: > On Thu, Nov 29, 2018 at 11:11:52PM +0100, Thomas Gleixner wrote: > > On Thu, 29 Nov 2018, Vincenzo Frascino wrote: > > > +static __always_inline notrace int __do_realtime_or_tai( > > > + const struct vdso_data *vd, > > > + struct __vdso_timespec *ts, > > > + bool is_tai) > > > +{ > > > + u32 seq, cs_mono_mult, cs_shift; > > > + u64 ns, sec; > > > + u64 cycle_last, cs_mono_mask; > > > + > > > + if (vd->use_syscall) > > > + return -1; > > > +repeat: > > > + seq = vdso_read_begin(vd); > > > + cycle_last = vd->cs_cycle_last; > > > + cs_mono_mult = vd->cs_mono_mult; > > > + cs_shift = vd->cs_shift; > > > + cs_mono_mask = vd->cs_mono_mask; > > > + > > > + if (is_tai) > > > + sec = vd->tai_sec; > > > + else > > > + sec = vd->xtime_clock_sec; > > > + ns = vd->xtime_clock_nsec; > > > + > > > + if (unlikely(vdso_read_retry(vd, seq))) > > > + goto repeat; > > > + > > > + ns += get_clock_shifted_nsec(cycle_last, cs_mono_mult, cs_mono_mask); > > > > This is broken. You cannot read the counter outside the seq count protected > > region. Please tell the ARM64 folks that their VDSO asm maze is broken. > > We'll fix the maze, but could you explain a bit about the brokenness, > please? The write side in update_vsyscall() is only touching the data page, > so I think we've got those fields covered correctly with the seqlock. We'd > only have to worry about protecting the counter if it could be written > somehow. > > Is your concern to do with migrating between systems, where the new system > has a counter with a different offset? If so, what does the program flow > look like when migrating in? I guess somehow we ensure that update_vsyscall() > is invoked before userspace can resume. > > Anyway, moving the counter read into the protected region is a little fiddly > because the memory barriers we have in there won't give us the ordering we > need. We'll instead need to do something nasty, like create a dependency > from the counter read to the read of the seqlock: > > Maybe the untested crufty hack below, although this will be a nightmare to > implement in C. We discussed this in person this week, but you couldn't recall the details off the top of your head so I'm replying here. Please could you clarify what your concern was with the existing code, and whether or not I've got the wrong end of the stick? Cheers, Will > --->8 > > diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S > index c39872a7b03c..2d1dfecae76b 100644 > --- a/arch/arm64/kernel/vdso/gettimeofday.S > +++ b/arch/arm64/kernel/vdso/gettimeofday.S > @@ -73,6 +73,8 @@ x_tmp .req x8 > movn x_tmp, #0xff00, lsl #48 > and \res, x_tmp, \res > mul \res, \res, \mult > + and x_tmp, x_tmp, xzr > + add vdso_data, vdso_data, x_tmp > .endm > > /* > @@ -147,12 +149,12 @@ ENTRY(__kernel_gettimeofday) > /* w11 = cs_mono_mult, w12 = cs_shift */ > ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] > ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] > - seqcnt_check fail=1b > > get_nsec_per_sec res=x9 > lsl x9, x9, x12 > > get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 > + seqcnt_check fail=1b > get_ts_realtime res_sec=x10, res_nsec=x11, \ > clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 > > @@ -211,13 +213,13 @@ realtime: > /* w11 = cs_mono_mult, w12 = cs_shift */ > ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] > ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] > - seqcnt_check fail=realtime > > /* All computations are done with left-shifted nsecs. */ > get_nsec_per_sec res=x9 > lsl x9, x9, x12 > > get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 > + seqcnt_check fail=realtime > get_ts_realtime res_sec=x10, res_nsec=x11, \ > clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 > clock_gettime_return, shift=1 > @@ -231,7 +233,6 @@ monotonic: > ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] > ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] > ldp x3, x4, [vdso_data, #VDSO_WTM_CLK_SEC] > - seqcnt_check fail=monotonic > > /* All computations are done with left-shifted nsecs. */ > lsl x4, x4, x12 > @@ -239,6 +240,7 @@ monotonic: > lsl x9, x9, x12 > > get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 > + seqcnt_check fail=monotonic > get_ts_realtime res_sec=x10, res_nsec=x11, \ > clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 > > @@ -253,13 +255,13 @@ monotonic_raw: > /* w11 = cs_raw_mult, w12 = cs_shift */ > ldp w12, w11, [vdso_data, #VDSO_CS_SHIFT] > ldp x13, x14, [vdso_data, #VDSO_RAW_TIME_SEC] > - seqcnt_check fail=monotonic_raw > > /* All computations are done with left-shifted nsecs. */ > get_nsec_per_sec res=x9 > lsl x9, x9, x12 > > get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 > + seqcnt_check fail=monotonic_raw > get_ts_clock_raw res_sec=x10, res_nsec=x11, \ > clock_nsec=x15, nsec_to_sec=x9 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel