Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4161559pxv; Mon, 19 Jul 2021 18:54:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO/NUqymnzVrxelruI/iQk09Qa3R8Y6sF2ZteReqPaVm3ppQc3JCgyfLY42O9DTt4lkaTQ X-Received: by 2002:a6b:d108:: with SMTP id l8mr20704043iob.65.1626746068801; Mon, 19 Jul 2021 18:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626746068; cv=none; d=google.com; s=arc-20160816; b=w6tj/izcxqEs69rIl3zlTRjQLQVozC8B+V/lnUlXEmv2YyyFHzzwRgT+KlAGik7n5L vJ75XkCpsPYKAXAW4uKX6NZzRMUZ4yZM6CqprtTv25pqvSXaZiFIHgZk7WlV8vE9pd0j HigISFft2Vh/FOCMl3R5VzlsCsbJBzl5ggNTrphVLKRCxv+DoldFqR40mYYXyiOvDPDQ CehrU9LQ7gMllAA6cr73Uq/wA8pKS5ExxrOMYj2yrBrxlhMi3dJrDMRIA3LKFzyBFisb Mx7ngTEefV9wsMNgmB+RUzeXaGd8tCn6sZakRD8JvHW954mn7lc3BCOF4CGncijKbRGS KQRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nyGFqfHVghDFzx44utEleMa81VUWIHZ9hd/ngSylhBU=; b=jID3j1EmTISO9HV0aiy9LmrESISmnQFtCREE5Pm1zUBsGXwRHD9MvcQrZa8/iqf8VS Z2K4Hh2U1k3TNMYxC2ByMiiPutWJ+7LHFZnKSFMxofHbHvMx84RUtPwsLHTQU6DcArRN CNN0mlya4jEsIclehlF9gP08dsCbXfZyf9lqzYc7mW3FPZY81dlCtnc2W0HZjXEuSY/S LlQ5ma0bkp61CtYjWltJ+UOOlnTb0m/EzVuUtm66Mcu/D0nGN2SmHYZPaYyIkwrsO9qw VUuWACU6l/uPWMQR82wlsChf6PWATJRsuq14ne8t5QD9ESf8NKZg+mYHcWFUDlIlabb8 TtoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jnXFLnv3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p13si21399823jak.113.2021.07.19.18.54.17; Mon, 19 Jul 2021 18:54:28 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jnXFLnv3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345449AbhGSPLi (ORCPT + 99 others); Mon, 19 Jul 2021 11:11:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:40436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344280AbhGSOso (ORCPT ); Mon, 19 Jul 2021 10:48:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C100A61003; Mon, 19 Jul 2021 15:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626708448; bh=TNFVtHoJc3PqwJwXyaoHT9IFm9G1RO35rNOmgMwLZag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jnXFLnv3tsyNGA5bS9hRhI3wMfCJhebgoMt4CSbuOme0ctoLSB0T5jT5wrJCfPl/m hoD0BnSma/g11j/UYTpG2KogtpRXgih7rcUMP3Vr5CqMChHtGgrt24nsX6HLqziEDg M6MlhQv0JM86LlwU4F2FgzOr3PoOnzaI/cqoAZqM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Martin=20F=C3=A4cknitz?= , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 4.14 314/315] MIPS: vdso: Invalid GIC access through VDSO Date: Mon, 19 Jul 2021 16:53:23 +0200 Message-Id: <20210719144953.805394783@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.861561397@linuxfoundation.org> References: <20210719144942.861561397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Fäcknitz [ Upstream commit 47ce8527fbba145a7723685bc9a27d9855e06491 ] Accessing raw timers (currently only CLOCK_MONOTONIC_RAW) through VDSO doesn't return the correct time when using the GIC as clock source. The address of the GIC mapped page is in this case not calculated correctly. The GIC mapped page is calculated from the VDSO data by subtracting PAGE_SIZE: void *get_gic(const struct vdso_data *data) { return (void __iomem *)data - PAGE_SIZE; } However, the data pointer is not page aligned for raw clock sources. This is because the VDSO data for raw clock sources (CS_RAW = 1) is stored after the VDSO data for coarse clock sources (CS_HRES_COARSE = 0). Therefore, only the VDSO data for CS_HRES_COARSE is page aligned: +--------------------+ | | | vd[CS_RAW] | ---+ | vd[CS_HRES_COARSE] | | +--------------------+ | -PAGE_SIZE | | | | GIC mapped page | <--+ | | +--------------------+ When __arch_get_hw_counter() is called with &vd[CS_RAW], get_gic returns the wrong address (somewhere inside the GIC mapped page). The GIC counter values are not returned which results in an invalid time. Fixes: a7f4df4e21dd ("MIPS: VDSO: Add implementations of gettimeofday() and clock_gettime()") Signed-off-by: Martin Fäcknitz Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/vdso/vdso.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/vdso/vdso.h b/arch/mips/vdso/vdso.h index cfb1be441dec..921589b45bc2 100644 --- a/arch/mips/vdso/vdso.h +++ b/arch/mips/vdso/vdso.h @@ -81,7 +81,7 @@ static inline const union mips_vdso_data *get_vdso_data(void) static inline void __iomem *get_gic(const union mips_vdso_data *data) { - return (void __iomem *)data - PAGE_SIZE; + return (void __iomem *)((unsigned long)data & PAGE_MASK) - PAGE_SIZE; } #endif /* CONFIG_CLKSRC_MIPS_GIC */ -- 2.30.2