Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp784034ybd; Sat, 22 Jun 2019 15:10:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSic7BBPyipzoUc9gTden/i/qKmIuItGCgWv9FSx9D33XndyE+PrjQaWCBIHiWi0RAjUvm X-Received: by 2002:a17:902:28c9:: with SMTP id f67mr140602715plb.19.1561241438206; Sat, 22 Jun 2019 15:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561241438; cv=none; d=google.com; s=arc-20160816; b=MKKvtLVWQ9orOlxuWt2La6dpC7eBtjvXklCvPZOs0tKGhzN12IMvYQhXSd/tngGEFI OsJJujZQUkaGaHorc0PDvUMIipePBWPQx82884PYUOJOxB/LV9A+yWqzll1RHIQCX3WH EZhGUD8uzLtPA8u+LoOTMv7KOgf2VAwqpUlXruo4vOLkOK7PnRyHL5R6Pj0Jp/Wi5pM1 eZd1HZhkDtLLFbz79UCOf0KfX1CLJiiOWNLSgxLkZ/MzWCEb6xFYP1EIkoyd8ot3tpko 9T0VL9cYE3hnfrLw9y7kgW4Ykqa+nXY5hfq3aFMDqpll4j1kTroZCDfMg+31mRG+x7jw WoJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9Plls7yoArd9C47FZhASUQBvV/imJO9giIvI6NCI2wk=; b=am8iMhLXZg3K9B+2rsm0IbgjjNnNmkErCWaDqtWrPGF81bXj8sJGJgkvpc1pCUyAEm 30Za0ebC7mon/HAIeOEjytnnfHE0J0W67BcpVKPuR7cKMxaoRTn4xoFEn3cQLM4Z+HSN 4mQnD1oxOrM8qfg1xu/6kNHNz3hislw6CQ4pdk2t94cuMXNEMWsnRALWSOOxPOXOn83T fRoylt7Sl3+4MPZa9rT41uf0oVG+X8LRodu3HQCKxIgjUEc8NgI6rnbvCcmtGggSDiw2 GWQAvCJftLzhtqMSx9cW9trPEjDJi7eisWLkrsyq38YQ2o6tMroLu15FyndaxGeM95Zq GYbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AW2o0cx5; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g9si5760440pgq.563.2019.06.22.15.10.04; Sat, 22 Jun 2019 15:10:38 -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=@kernel.org header.s=default header.b=AW2o0cx5; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726343AbfFVWIY (ORCPT + 99 others); Sat, 22 Jun 2019 18:08:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:47074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725844AbfFVWIX (ORCPT ); Sat, 22 Jun 2019 18:08:23 -0400 Received: from localhost (c-67-180-165-146.hsd1.ca.comcast.net [67.180.165.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 45FCA206B7; Sat, 22 Jun 2019 22:08:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561241302; bh=BvSt+fMYJewY1L3HbKjDF1ilwCwa+LuIeaLapVC1Lgc=; h=From:To:Cc:Subject:Date:From; b=AW2o0cx5rRzHPlM3kEFWc4wjywu9160FB9Kw2twAkwA7z2afodlI8HqBVFl8LnUVo 7GBtbN5ptaatKQayxBsSyyNgBr35HLaj08U0ZHlqLJJB1qMN4foQo2oHQQ7U/by0d2 56k0JUnYWOQVl7+tX+cblbb7zL1V2BtKNnCK0IkA= From: Andy Lutomirski To: x86@kernel.org Cc: LKML , Borislav Petkov , Andy Lutomirski , Peter Zijlstra , Linus Torvalds Subject: [PATCH] x86/vdso: Give the [ph]vclock_page declarations real types Date: Sat, 22 Jun 2019 15:08:18 -0700 Message-Id: <6920c5188f8658001af1fc56fd35b815706d300c.1561241273.git.luto@kernel.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clean up the vDSO code a bit by giving pvclock_page and hvclock_page their actual types instead of u8[PAGE_SIZE]. This shouldn't materially affect the generated code. Heavily based on a patch from Linus. Cc: Borislav Petkov Cc: Peter Zijlstra Signed-off-by: Linus Torvalds Signed-off-by: Andy Lutomirski --- arch/x86/entry/vdso/vclock_gettime.c | 36 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c index 4aed41f638bb..907efc5015ec 100644 --- a/arch/x86/entry/vdso/vclock_gettime.c +++ b/arch/x86/entry/vdso/vclock_gettime.c @@ -28,13 +28,33 @@ extern int __vdso_clock_gettime(clockid_t clock, struct timespec *ts); extern int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); extern time_t __vdso_time(time_t *t); +/* + * Declare the memory-mapped vclock data pages. These come from hypervisors. + * If we ever reintroduce something like direct access to an MMIO clock like + * the HPET again, it will go here as well. + * + * A load from any of these pages will segfault if the clock in question is + * disabled, so appropriate compiler barriers and checks need to be used + * to prevent stray loads. + * + * These declarations MUST NOT be const. The compiler will assume that + * an extern const variable has genuinely constant contents, and the + * resulting code won't work, since the whole point is that these pages + * change over time, possibly while we're accessing them. + */ + #ifdef CONFIG_PARAVIRT_CLOCK -extern u8 pvclock_page[PAGE_SIZE] +/* + * This is the vCPU 0 pvclock page. We only use pvclock from the vDSO + * if the hypervisor tells us that all vCPUs can get valid data from the + * vCPU 0 page. + */ +extern struct pvclock_vsyscall_time_info pvclock_page __attribute__((visibility("hidden"))); #endif #ifdef CONFIG_HYPERV_TSCPAGE -extern u8 hvclock_page[PAGE_SIZE] +extern struct ms_hyperv_tsc_page hvclock_page __attribute__((visibility("hidden"))); #endif @@ -69,14 +89,9 @@ notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) #endif #ifdef CONFIG_PARAVIRT_CLOCK -static notrace const struct pvclock_vsyscall_time_info *get_pvti0(void) -{ - return (const struct pvclock_vsyscall_time_info *)&pvclock_page; -} - static notrace u64 vread_pvclock(void) { - const struct pvclock_vcpu_time_info *pvti = &get_pvti0()->pvti; + const struct pvclock_vcpu_time_info *pvti = &pvclock_page.pvti; u32 version; u64 ret; @@ -117,10 +132,7 @@ static notrace u64 vread_pvclock(void) #ifdef CONFIG_HYPERV_TSCPAGE static notrace u64 vread_hvclock(void) { - const struct ms_hyperv_tsc_page *tsc_pg = - (const struct ms_hyperv_tsc_page *)&hvclock_page; - - return hv_read_tsc_page(tsc_pg); + return hv_read_tsc_page(&hvclock_page); } #endif -- 2.21.0