Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4174464ybi; Mon, 15 Jul 2019 05:05:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTEsfDDXwaqW3F1x4XZP+6S0CWUyqTZEVv+InvMi3ZedcuwHc+gkRnJt2om2eV1LN0uLLK X-Received: by 2002:a65:52ca:: with SMTP id z10mr27255560pgp.424.1563192304679; Mon, 15 Jul 2019 05:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563192304; cv=none; d=google.com; s=arc-20160816; b=ogeOdS9AL9GyAGbDvX/5Y80GXsu8mQHiCAHYYMjOehUWoA3X4dUmHa3uZRW0ntxwj9 E7a6WOyNIENaMIyBHO/Jm4euQfNmAfiyaqDPDtDkteuHZc7n/PJcPN8UPInE8mimgcPx OHAN4FuUkJy+Lm62CvgvHTwrwHGtaiUvowx3LKzPzkzaT8oM1ZJtMN+ZFRQlrnF/JPFt g5XOQdUKZ9QWZjE2rz6HkxtWwBJ/pUX7yMSNJX7NlHCcgEQxigT5C2NjfG/bDr457V+7 wywzVSM9HzvSJlog6CiLAZaV4TpegYwVKn6rktGdiQZrk8BOmldQu/34SCsK0aDdTToi 2osg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=siKrRVKRpx7RpKSTXYP2AWsLiceVEcAiCzz2p78ubgQ=; b=zmS8FNJ+fTnKoA2dpok4XVMPD4c9ioh3R9LcRbs7Si/75+kWEKwhoO6DAMU3aE7LdN verXfblpYsvC1NfvPFCMg+GnDCSAuzHb9fqP2tauxjdSQEXq8RBqXGZypvAJR38vS8VE NOcaOZ1h/mCtn1BBDgM/Bm+Hz15/aNkBj2hd5XvlicPJVi8zkxDIczd4Qsk7k5aUzV6R /DP0LgQ7wWBxZ3XKYuAXAAEFwdUB7wxpYe+P53sk5q4pHUji/WF/Z7nsJ+mCVZdq6UWG fnr2kslo/LC2KmFJxnkoFTcNaG72UKb3xH4Nf7cIbOlviQfr3Fbhhth7+kfigPC2VoM7 nB7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=a1N4c1Nt; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si16238585pfp.65.2019.07.15.05.04.47; Mon, 15 Jul 2019 05:05:04 -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=@gmail.com header.s=20161025 header.b=a1N4c1Nt; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729910AbfGOME3 (ORCPT + 99 others); Mon, 15 Jul 2019 08:04:29 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:41763 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729827AbfGOME2 (ORCPT ); Mon, 15 Jul 2019 08:04:28 -0400 Received: by mail-ed1-f66.google.com with SMTP id p15so15198398eds.8 for ; Mon, 15 Jul 2019 05:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=siKrRVKRpx7RpKSTXYP2AWsLiceVEcAiCzz2p78ubgQ=; b=a1N4c1NtrSMBmRxyDN1bt+aTDEXwAEcei9NMSHaK04P0PCKhOuIH5Rpew/9/xRWm23 Js79ou5nQuSpYL2Uv1qlCrixRaHPYiWh9me97FNMBPo44li0Mw8G508ONYsF6C1rcpiq KAgn0CbtK+Q+ZetNMzH5J2QSfmcp2viSOMtgFq8zHeD04TiIQFVJJT7Z6rykkYLxLsi/ nStP3afTeB3MmiAnfjsqtd4CzuiawatGLjQxhloRHnsklUW5PyPaU9+F3dOrYJiHbjWK iUN59zVgLNhIQK/7QMVFl5C8PWNoGqp72CB0gHxiVb7ax2bqGx6LLj79R3ENL18ksSbp y4CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=siKrRVKRpx7RpKSTXYP2AWsLiceVEcAiCzz2p78ubgQ=; b=XROjsRiLjfGNY3XCTKUPbZqgpMrvDNtbB7ciQsuHd6JMZj89HEYetyQp8BwQp17ajt THGQXPkKp+31Y/YSVEh3tpet3gBCKVTB6wm84TBb/kMzijPkaN9jyD1lem99G0DYM2Q7 zBNQtlb8ZzQpzOapie4yX7mZFvwL+f29TDNgdvP+k3tmVhPNNkv6saQxDmQnjDDWAcyp 7FAeIdvsZdIomDBLHBW2l6IwuUD+JpvYQAljLclAoxyXGEdPKiONqN4tL0hDo83H4fLD pKlxEmyGYxu+7V/gEP+T2yTruqbeT5hZO4msWDPeHDV61yMLCT6o+oIhPIboWfmz1SJy idkQ== X-Gm-Message-State: APjAAAX3Saz7tckn5z4NWg50S3SsnU14v2pb/fT3OPYNxfWfRPaeZ1LZ eV7fP82TDf6ajSGevWHVwzMBS5Xucc1V/vf8ScynnuHd7xM= X-Received: by 2002:a17:906:fac7:: with SMTP id lu7mr19649721ejb.109.1563192266966; Mon, 15 Jul 2019 05:04:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Uros Bizjak Date: Mon, 15 Jul 2019 14:04:15 +0200 Message-ID: Subject: Re: [RFC PATCH, x86]: Disable CPA cache flush for selfsnoop targets To: Thomas Gleixner Cc: LKML , X86 ML , Andrew Lutomirski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 15, 2019 at 10:24 AM Thomas Gleixner wrote: > > Uros, > > On Thu, 11 Jul 2019, Uros Bizjak wrote: > > Recent patch [1] disabled a self-snoop feature on a list of processor > > models with a known errata, so we are confident that the feature > > should work on remaining models also for other purposes than to speed > > up MTRR programming. > > > > I would like to resurrect an old patch [2] that avoids calling clflush > > and wbinvd > > to invalidate caches when CPU supports selfsnoop. > > Please do not attach patches, send them inline and please add a proper > changelog. Just saying 'Disable CPA cache flush for selfsnoop targets' in > the subject line then nada gives absolutely zero information. Thanks for your remarks and instructions! I'll send a new revision of the patch with expanded ChangeLog later today, saying something along the lines of: "CPUs which have self-snooping capability can handle conflicting memory type across CPUs by snooping its own cache. Commit #fd329f276ecaa ("x86/mtrr: Skip cache flushes on CPUs with cache self-snooping") avoids cache flushes when MTRR registers are programmed. The Page Attribute Table (PAT) is a companion feature to the MTRRs, and according to section 11.12.4 of the Intel 64 and IA 32 Architectures Software Developer's Manual, if the CPU supports cache self-snooping, it is not necessary to flush caches when remapping a page that was previously mapped as a different memory type. Note that commit #1e03bff360010 ("x86/cpu/intel: Clear cache self-snoop capability in CPUs with known errata") cleared cache self-snoop capability for CPUs where conflicting memory types lead to unpredictable behavior, machine check errors, or hangs." > > The patch was ported to latest Fedora kernel (5.1.16) and tested with > > CONFIG_CPA_DEBUG on INTEL_FAM6_IVYBRIDGE_X. The relevant ports of > > dmesg show: > > > > ... > > < hundreds of CPA protect messages, resulting from set_memory_rw CPA > > undo test in mm/init_64.c > > > CPA protect Rodata RO: 0xffffffffbd1fe000 - 0xffffffffbd1fefff PFN > > 1461fe req 8000000000000063 prevent 0000000000000002 > > CPA protect Rodata RO: 0xffff889c461fe000 - 0xffff889c461fefff PFN > > 1461fe req 8000000000000063 prevent 0000000000000002 > > Testing CPA: again > > Freeing unused kernel image memory: 2016K > > Freeing unused kernel image memory: 4K > > x86/mm: Checked W+X mappings: passed, no W+X pages found. > > rodata_test: all tests were successful > > x86/mm: Checking user space page tables > > x86/mm: Checked W+X mappings: passed, no W+X pages found. > > > > and from CPA selftest: > > > > CPA self-test: > > 4k 36352 large 4021 gb 0 x 81[ffff889b00098000-ffff889bdf7ff000] miss 133120 > > 4k 180224 large 3740 gb 0 x 81[ffff889b00098000-ffff889bdf7ff000] miss 133120 > > 4k 180224 large 3740 gb 0 x 81[ffff889b00098000-ffff889bdf7ff000] miss 133120 > > ok. > > These outputs are pretty useless simply because the selftest only verifies > the inner workings of CPA itself, but has nothing to do with the > correctness vs. cache flushing. Please note that CONFIG_CPA_DEBUG also spawns a pageattr-test kthread which remaps a memory page every 30 seconds. I was confident enough to run the patched kernel (with CONFIG_CPA_DEBUG) on my main workstation (Ivybridge-X, Fedora 30), already for a week without a single problem. Uros.