Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2464274imm; Mon, 24 Sep 2018 04:59:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV620YYEYZGypnORw+zrsHrwNYzpAxd5iRiJRwJeZKYrRwJNmQnpFqtZBPL6i6wg0vRAyrXd6 X-Received: by 2002:a63:1b0b:: with SMTP id b11-v6mr9209603pgb.66.1537790351154; Mon, 24 Sep 2018 04:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537790351; cv=none; d=google.com; s=arc-20160816; b=ZRv8z2Mcm3yc46vpTI6wRI15pw25iQo9I5/b7Cb/4xkOYJY7ROMZ4yOUeBtWDnVQHH fMLOUQ+H15tQdRMfCDGGkd/zCSTG9LGQ/mWi53fkovNY4XRa8eT6/d5dULnDi/It6Sgu 183BPsfv84djoYetuPntObO2kt/NLl9AHs8gLMfTUWrHhQYVxdZVdXHl8BSfyF9HPahN F2MmI5V+wamoJaD7hA79FHKufc4ByqdWvdIOBsZ8PHWFj3bFJzn9FAx1sA0fLKC9yuhd PoMOmFU6MhfDhu7aFZOHzoqrfvl0SBan6Rgku9EXIoqRTzhm/y+sQVdgpEsmfkh9MNAd uu+w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=AQaN/2c+xr1s9VsCuW6zOajqoEsbM3BWdukBop7bgFw=; b=o+Ga9TwRPRG0AdNZyYUGHrKdryqEsFjRwzQKK+dcrxhkktimEn1qQzJj55xyqTE8hg DvU1Rh7bLiOnQ93O/hNRuRDxjTnlVx9mhnMR0CfyLA3pTYLz6dvVyYO4CUKMmP4gMtwX d0B7T/eAO69U5A1nZqX+dV43pMlBz/YybK/ruaUWlUCf/flGE8KxF8ytsKuL49P6BZ8s kAZsbL1nG3jnL9bGPCAKaL70TZbbjA6UKl/Ek0LqIfA4/KaibGHCCo25ouQIRwPvBpem ggqodeHtwjRGOl9VpXa7Avbq40gwF1BtGq3U5oJl+c1YHG6KPMeDuyDWgARvK+I4GPY2 l/dA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21-v6si7881789pgn.56.2018.09.24.04.58.55; Mon, 24 Sep 2018 04:59:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730341AbeIXR7t (ORCPT + 99 others); Mon, 24 Sep 2018 13:59:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52324 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729194AbeIXR7s (ORCPT ); Mon, 24 Sep 2018 13:59:48 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 21B3DD64; Mon, 24 Sep 2018 11:58:02 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Burton , Hauke Mehrtens , Rene Nielsen , Alexandre Belloni , James Hogan , linux-mips@linux-mips.org Subject: [PATCH 4.4 69/70] MIPS: VDSO: Match data page cache colouring when D$ aliases Date: Mon, 24 Sep 2018 13:53:08 +0200 Message-Id: <20180924113107.984774618@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113058.420454070@linuxfoundation.org> References: <20180924113058.420454070@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paul Burton commit 0f02cfbc3d9e413d450d8d0fd660077c23f67eff upstream. When a system suffers from dcache aliasing a user program may observe stale VDSO data from an aliased cache line. Notably this can break the expectation that clock_gettime(CLOCK_MONOTONIC, ...) is, as its name suggests, monotonic. In order to ensure that users observe updates to the VDSO data page as intended, align the user mappings of the VDSO data page such that their cache colouring matches that of the virtual address range which the kernel will use to update the data page - typically its unmapped address within kseg0. This ensures that we don't introduce aliasing cache lines for the VDSO data page, and therefore that userland will observe updates without requiring cache invalidation. Signed-off-by: Paul Burton Reported-by: Hauke Mehrtens Reported-by: Rene Nielsen Reported-by: Alexandre Belloni Fixes: ebb5e78cc634 ("MIPS: Initial implementation of a VDSO") Patchwork: https://patchwork.linux-mips.org/patch/20344/ Tested-by: Alexandre Belloni Tested-by: Hauke Mehrtens Cc: James Hogan Cc: linux-mips@linux-mips.org Cc: stable@vger.kernel.org # v4.4+ Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/vdso.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/arch/mips/kernel/vdso.c +++ b/arch/mips/kernel/vdso.c @@ -14,12 +14,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include /* Kernel-provided data used by the VDSO. */ @@ -118,12 +120,30 @@ int arch_setup_additional_pages(struct l vvar_size = gic_size + PAGE_SIZE; size = vvar_size + image->size; + /* + * Find a region that's large enough for us to perform the + * colour-matching alignment below. + */ + if (cpu_has_dc_aliases) + size += shm_align_mask + 1; + base = get_unmapped_area(NULL, 0, size, 0, 0); if (IS_ERR_VALUE(base)) { ret = base; goto out; } + /* + * If we suffer from dcache aliasing, ensure that the VDSO data page + * mapping is coloured the same as the kernel's mapping of that memory. + * This ensures that when the kernel updates the VDSO data userland + * will observe it without requiring cache invalidations. + */ + if (cpu_has_dc_aliases) { + base = __ALIGN_MASK(base, shm_align_mask); + base += ((unsigned long)&vdso_data - gic_size) & shm_align_mask; + } + data_addr = base + gic_size; vdso_addr = data_addr + PAGE_SIZE;