Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4534818imm; Mon, 17 Sep 2018 16:02:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYvgDLZ00ICmOfmfFU1W/1zEV5Iod4PW0xSN+1ENqCHxy6G4wklzV3sGkAULE3HMNCeRD7Z X-Received: by 2002:a63:f344:: with SMTP id t4-v6mr25525890pgj.428.1537225366566; Mon, 17 Sep 2018 16:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537225366; cv=none; d=google.com; s=arc-20160816; b=QcZIPHxgzOxnlcC+mUASW/AJA9ndBUtEgo18bzU+QHiQpGJSNWOLaJO+HMdx+sDewi F3JNZb2vpYNM4tjNgvogIBuapMq0VPv8xmc++Cilsam5B4mQg+GhQEsbHYLM+WQOCA6C YzzQ7p0TaCJZbK/sJTl/mymyKbZqArrqP5m9yBpXv7yT/xrctQ1325TkoM90DhFVrBkR J6kmMlo/2PC7sk9j6bgGueh52P5BID2z2zx8MLQOiWpkrLt58AXHBQQK4ppUSWhQQWez rY1MPzED9/gB4/Jo0sMXRfhybGnToGg0Txk9JoEnpTuftByQVvmzRgJOAP1WEN31VhnY etfg== 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=CtPHjY2WLlNutc+HAbK+K+kZGwK1YNmb4jDOlzLbmhU=; b=aGzG/Bvk26MF91bbmX21A8P8cx//swIrQjThBPWH2kuwYShngaCWs9nniUYC1t75Yi pY1jIRypysZnQTBOEG6saRZrUp7lQ1kQzJRwR31b4wRm8KoZ25DZ8GBKxVjYPmMhksfv mP2nsBGyoQz3hFppQRQIzvzdvG/zABvoA5dy6tXHFNVY1vbb2uuaiC9b36YPA3At7jNE ZOG2xBymgpxBxiFPtMGjC540vhncgAxOXgePm4Spl2/DnkdSwW38XGhcp6r4Z/LVs0uc mQDmp5/mQWDP6GwKgrrgV+oEqRex5f09jg1+82tmY0g36+YBYn4KckpiiEAVkgD4A+++ aMtg== 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 o20-v6si16348806pgk.120.2018.09.17.16.02.31; Mon, 17 Sep 2018 16:02:46 -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 S1730385AbeIREbp (ORCPT + 99 others); Tue, 18 Sep 2018 00:31:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48442 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbeIREbp (ORCPT ); Tue, 18 Sep 2018 00:31:45 -0400 Received: from localhost (li1825-44.members.linode.com [172.104.248.44]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7A561C49; Mon, 17 Sep 2018 23:02:16 +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.14 007/126] MIPS: VDSO: Match data page cache colouring when D$ aliases Date: Tue, 18 Sep 2018 00:40:55 +0200 Message-Id: <20180917211704.293713196@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180917211703.481236999@linuxfoundation.org> References: <20180917211703.481236999@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.14-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 @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include +#include #include /* Kernel-provided data used by the VDSO. */ @@ -128,12 +130,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;