Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3839681pxv; Mon, 19 Jul 2021 09:59:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytCfTEsCp4UskTl6B9sI70CvmXfouIicmr705fqOPXP7ya/wTHZB7vcO51GG3evbAxOl67 X-Received: by 2002:a5d:928f:: with SMTP id s15mr19285306iom.142.1626713993674; Mon, 19 Jul 2021 09:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626713993; cv=none; d=google.com; s=arc-20160816; b=ZjGmy0cMYJ99c8vQ/jbIjN7bxjrx9TuvvWIkf3KcGzrTChKpKbPe6KHzQlALs87bK8 I3/ReCbM+PpvJ84BM7VSViAORylAA7iiSqa7SdlM8EteKh58i+T7DvXVwNGL9BUu3RkL uLoGW9NknvooCU43TcCA1tpFe32IN9WMcu9XI3hMBfnYzgbY3aUUPBaRLNOTkqvIOAyS /G7xt3QsTaVsFg7s/pE1r5y0/i20LKCkWDcm0HO7ffgXiRUhGMVzglt1xbEslstccfdQ IRaMJYgXrZoUrOBM++Wbww2ACRHJ0JBlraOn/0M/OgO62d6Ib1p22u0+k8vOyBfddeZ9 R4Zw== 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=K87LKbXNtY//OwDXppbbobycULv6IxGa/MEGLtStpMU=; b=0aADb4LrTMGVN23P2pIBZL7WOC+Y8q6xyH5AyWOH6JWBYXl9LyvUuaLACFgSOnylwh kCihrBAFkWHSrJv1hGpSR1wWDFCJt5ADEfETu51fJoXRsKWotF/OHvq956vHMP72Si23 gULQgVv6GrkbNs+Lo/2ubmCJoNtlmbm7Ff4N88CqermDv0aRusGemZOLi6G+CvhlgpSp GcUSbub1CW1Pntxb28wRQ8Pztq74DhlwPfOKJlZN2wxxohy4xxHNefg5cc2RJNwxKDg0 uU06FZbKBruG0QRCXMysUQkRIETrIn7+4zQegR5WiwqtBd1A8o2Ba6e65G7ry0MLxGvD YrFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="GXo/N09o"; 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 d17si2030960ilf.150.2021.07.19.09.59.41; Mon, 19 Jul 2021 09:59:53 -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="GXo/N09o"; 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 S1344221AbhGSQRq (ORCPT + 99 others); Mon, 19 Jul 2021 12:17:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:47400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343848AbhGSPLK (ORCPT ); Mon, 19 Jul 2021 11:11:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B52C4610D2; Mon, 19 Jul 2021 15:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626709909; bh=wrAXyTUu8iaEYGFgf4AL1J9lnFaFjPOR7mr8+BQtH7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GXo/N09o0p1349yylNvHMiKwCP58dxZTr23pVqXrOwZ25dQyioZM2kgjVRvWA9X5U hIZ+Z9P0YjMnZwMaKhia1GmTZf37j0+zOAerGJxuNgVK/Xl1+gAxjug++Qd4AtXtpP tVBZjYTbyFb206+TebbWj4I7FKf1pQfyEZu5h/b8= 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 5.4 147/149] MIPS: vdso: Invalid GIC access through VDSO Date: Mon, 19 Jul 2021 16:54:15 +0200 Message-Id: <20210719144936.079981460@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144901.370365147@linuxfoundation.org> References: <20210719144901.370365147@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/include/asm/vdso/vdso.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/include/asm/vdso/vdso.h b/arch/mips/include/asm/vdso/vdso.h index 737ddfc3411c..a327ca21270e 100644 --- a/arch/mips/include/asm/vdso/vdso.h +++ b/arch/mips/include/asm/vdso/vdso.h @@ -67,7 +67,7 @@ static inline const struct vdso_data *get_vdso_data(void) static inline void __iomem *get_gic(const struct 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