Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp173318pxa; Tue, 4 Aug 2020 02:37:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiNEboIpS42UC3lq7T6vNfZeRw+/ch0W+1jUo6IMF9GsYKkLxHzBsMP6ln9PWOm47PZTHh X-Received: by 2002:a17:907:42a0:: with SMTP id ny24mr21015557ejb.328.1596533864293; Tue, 04 Aug 2020 02:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596533864; cv=none; d=google.com; s=arc-20160816; b=JYKIgb+xxdfrSq4gwJa1DN5qcfCQ35pPcPpxluAwVTOXr9MchWZGFhzIfsaf1H3ol1 Fu/l+5mzFAGgfueUMuwiVvO4Fgx6+ovlWAQ3bR78glvwIVM5SpkhmAjK4COKXPHQT7VA Hm4zLLiDYvvKGhOjU2lTtR7kHrhCDFoxDA3WpInW9SWVelGqmfyEhu7Rgh0GUWceFCGv +wCW8BuLnAXJid2Cagk+PjH/vq9ludI3YMBZYHgqpeIrVzbnEI7lowcE1NAFZ3KmYI/y 6ABXFrOZaEVGNAFnKDEa66bB9WwPjrSpq/wniVo4OSTSOk7WarImd794yRUT6sD15BwD ioOw== 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; bh=SShYs16CVuBwNl5SDy+itT8Ms2P1YROFUyuiNgxXVCo=; b=ithnFAB+8SZEQZDIFHyRVYJ5k3xOwGNqKwOicWnaU+EhbvBgsH2EjAynaVnp+bbNLh 7yk3bg15pg6L5KH36VfQySbLSXIccmKyrUfNrQrIleQc5yH054gDIzkH3wHP4mBwTvKa bavatk9AViPhlIH9CD4uEWUN/TKgBCPQPTNQ30dEMrSudS2RRJwE69bFu0brFuUK3LnK AlnbKtfPi3z5HPwLc404uC7bw9jTkvfpKwfYzSbs6LGaEv0cxTyRh+/AkXHishFFhbzv f6bdiT2tihPB5Ivn4PUc1H7KZ7vwMFUCwalEx0q2jhGgXU61odTLhrCGuHdQImqfw0e7 zsUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si3741490ejm.274.2020.08.04.02.37.22; Tue, 04 Aug 2020 02:37:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728330AbgHDJgk (ORCPT + 99 others); Tue, 4 Aug 2020 05:36:40 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:10008 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727997AbgHDJgg (ORCPT ); Tue, 4 Aug 2020 05:36:36 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0749L9gL104465; Tue, 4 Aug 2020 05:36:32 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 32q4yf8brf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 04 Aug 2020 05:36:32 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0749ZpU2016724; Tue, 4 Aug 2020 09:36:30 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 32n01835kd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 04 Aug 2020 09:36:30 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0749aRSJ26149246 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Aug 2020 09:36:27 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8CC16A4054; Tue, 4 Aug 2020 09:36:27 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 724DDA4065; Tue, 4 Aug 2020 09:36:27 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 4 Aug 2020 09:36:27 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 55390) id 29A69E1347; Tue, 4 Aug 2020 11:36:27 +0200 (CEST) From: Sven Schnelle To: Thomas Gleixner , Vincenzo Frascino Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, hca@linux.ibm.com, Sven Schnelle Subject: [PATCH 2/3] timekeeping/vsyscall: Provide vdso_update_begin/end() Date: Tue, 4 Aug 2020 11:36:06 +0200 Message-Id: <20200804093607.69841-3-svens@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200804093607.69841-1-svens@linux.ibm.com> References: <20200804093607.69841-1-svens@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-04_03:2020-08-03,2020-08-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=703 mlxscore=0 adultscore=0 clxscore=1015 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008040068 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner Architectures can have the requirement to add additional architecture specific data to the VDSO data page which needs to be updated independent of the timekeeper updates. To protect these updates vs. concurrent readers and a conflicting update through timekeeping, provide helper functions to make such updates safe. vdso_update_begin() takes the timekeeper_lock to protect against a potential update from timekeeper code and increments the VDSO sequence count to signal data inconsistency to concurrent readers. vdso_update_end() makes the sequence count even again to signal data consistency and drops the timekeeper lock. Signed-off-by: Thomas Gleixner Signed-off-by: Sven Schnelle --- include/vdso/vsyscall.h | 3 +++ kernel/time/timekeeping.c | 2 +- kernel/time/timekeeping_internal.h | 11 +++++++--- kernel/time/vsyscall.c | 32 ++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/include/vdso/vsyscall.h b/include/vdso/vsyscall.h index 2c6134e0c23d..b0fdc9c6bf43 100644 --- a/include/vdso/vsyscall.h +++ b/include/vdso/vsyscall.h @@ -6,6 +6,9 @@ #include +unsigned long vdso_update_begin(void); +void vdso_update_end(unsigned long flags); + #endif /* !__ASSEMBLY__ */ #endif /* __VDSO_VSYSCALL_H */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index d20d489841c8..8459aa87986f 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -50,7 +50,7 @@ static struct { .seq = SEQCNT_ZERO(tk_core.seq), }; -static DEFINE_RAW_SPINLOCK(timekeeper_lock); +DEFINE_RAW_SPINLOCK(timekeeper_lock); static struct timekeeper shadow_timekeeper; /** diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h index bcbb52db2256..4ca2787d1642 100644 --- a/kernel/time/timekeeping_internal.h +++ b/kernel/time/timekeeping_internal.h @@ -1,12 +1,14 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef _TIMEKEEPING_INTERNAL_H #define _TIMEKEEPING_INTERNAL_H -/* - * timekeeping debug functions - */ + #include +#include #include +/* + * timekeeping debug functions + */ #ifdef CONFIG_DEBUG_FS extern void tk_debug_account_sleep_time(const struct timespec64 *t); #else @@ -31,4 +33,7 @@ static inline u64 clocksource_delta(u64 now, u64 last, u64 mask) } #endif +/* Semi public for serialization of non timekeeper VDSO updates. */ +extern raw_spinlock_t timekeeper_lock; + #endif /* _TIMEKEEPING_INTERNAL_H */ diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c index 54ce6eb2ca36..e8806eda6874 100644 --- a/kernel/time/vsyscall.c +++ b/kernel/time/vsyscall.c @@ -13,6 +13,8 @@ #include #include +#include "timekeeping_internal.h" + static inline void update_vdso_data(struct vdso_data *vdata, struct timekeeper *tk) { @@ -127,3 +129,33 @@ void update_vsyscall_tz(void) __arch_sync_vdso_data(vdata); } + +/** + * vdso_update_begin - Start of a VDSO update section + * + * Allows architecture code to safely update the architecture specific VDSO + * data. + */ +unsigned long vdso_update_begin(void) +{ + struct vdso_data *vdata = __arch_get_k_vdso_data(); + unsigned long flags; + + raw_spin_lock_irqsave(&timekeeper_lock, flags); + vdso_write_begin(vdata); + return flags; +} + +/** + * vdso_update_end - End of a VDSO update section + * + * Pairs with vdso_update_begin(). + */ +void vdso_update_end(unsigned long flags) +{ + struct vdso_data *vdata = __arch_get_k_vdso_data(); + + vdso_write_end(vdata); + __arch_sync_vdso_data(vdata); + raw_spin_unlock_irqrestore(&timekeeper_lock, flags); +} -- 2.17.1