From patchwork Tue Apr 21 20:26:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Luis R. Rodriguez" X-Patchwork-Id: 6253591 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C6D589F1C4 for ; Tue, 21 Apr 2015 20:29:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 884E0202F2 for ; Tue, 21 Apr 2015 20:29:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDE6C201E4 for ; Tue, 21 Apr 2015 20:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932840AbbDUU2F (ORCPT ); Tue, 21 Apr 2015 16:28:05 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:36148 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932096AbbDUU2C (ORCPT ); Tue, 21 Apr 2015 16:28:02 -0400 Received: by pabsx10 with SMTP id sx10so251362101pab.3; Tue, 21 Apr 2015 13:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=Qc9lB+lGZl4EnG3/MF3p1Vi7Otj6nzTq5+okM1+nkyk=; b=cpUloKEOK3Qi+YICz2hOeG9PGHdEyTIfBVEIwcV/W1yVP6obYDCT7o7LyoJPst1Qqx fzALE6U9KPwevYQOxpmRbSUCPkIcxZzbnoMjCuHa2BjHZnzWH8IdLRyR0+CpHw7/241E wVv0eLQDGRBv7sDanDZ/DM5SCIy7UUjf/YdnJbMJwSOzM0GT/EhHoviR7s7VnYiTj4MM TyBmLP34He8KGKbyn3PRR8XO1duLEgVjLXrXkYlBFxaxzKuqDZKBsYGC4iH7hrWAxIN5 NYT63xZ1xzqirKPkz1Cp+UaeO4zNrBG1W4bs9wr6m+PLTo/gkNg/Ijp9ezxKF9XkNN3g W2EA== X-Received: by 10.68.240.40 with SMTP id vx8mr40346357pbc.27.1429648081550; Tue, 21 Apr 2015 13:28:01 -0700 (PDT) Received: from mcgrof@gmail.com (c-98-234-145-61.hsd1.ca.comcast.net. [98.234.145.61]) by mx.google.com with ESMTPSA id p1sm2884353pdl.60.2015.04.21.13.27.58 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 21 Apr 2015 13:28:00 -0700 (PDT) Received: by mcgrof@gmail.com (sSMTP sendmail emulation); Tue, 21 Apr 2015 13:27:58 -0700 From: "Luis R. Rodriguez" To: mingo@elte.hu, tglx@linutronix.de, hpa@zytor.com, syrjala@sci.fi, plagnioj@jcrosoft.com, tomi.valkeinen@ti.com Cc: linux-fbdev@vger.kernel.org, luto@amacapital.net, mst@redhat.com, cocci@systeme.lip6.fr, "Luis R. Rodriguez" , Toshi Kani , Jonathan Corbet , Dave Hansen , Suresh Siddha , Juergen Gross , Daniel Vetter , Dave Airlie , Antonino Daplas , Mel Gorman , Vlastimil Babka , Borislav Petkov , Davidlohr Bueso , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/6] x86: document WC MTRR effects on PAT / non-PAT pages Date: Tue, 21 Apr 2015 13:26:06 -0700 Message-Id: <1429647970-17479-3-git-send-email-mcgrof@do-not-panic.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1429647970-17479-1-git-send-email-mcgrof@do-not-panic.com> References: <1429647970-17479-1-git-send-email-mcgrof@do-not-panic.com> MIME-Version: 1.0 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Luis R. Rodriguez" As part of the effort to phase out MTRR use document write-combining MTRR effects on pages with different non-PAT page attributes flags and different PAT entry values. Extend arch_phys_wc_add() documentation to clarify power of two sizes / boundary requirements as we phase out mtrr_add() use. Lastly hint towards ioremap_uc() for corner cases on device drivers working with devices with mixed regions where MTRR size requirements would otherwise not enable write-combining effective memory types. Cc: Toshi Kani Cc: Jonathan Corbet Cc: Dave Hansen Cc: Andy Lutomirski Cc: Suresh Siddha Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Juergen Gross Cc: Daniel Vetter Cc: Dave Airlie Cc: Antonino Daplas Cc: Jean-Christophe Plagniol-Villard Cc: Tomi Valkeinen Cc: Ville Syrjälä Cc: Mel Gorman Cc: Vlastimil Babka Cc: Borislav Petkov Cc: Davidlohr Bueso Cc: linux-fbdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Luis R. Rodriguez --- Documentation/x86/mtrr.txt | 18 +++++++++++++++--- Documentation/x86/pat.txt | 40 +++++++++++++++++++++++++++++++++++++++- arch/x86/kernel/cpu/mtrr/main.c | 3 +++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/Documentation/x86/mtrr.txt b/Documentation/x86/mtrr.txt index cc071dc..a111a6c 100644 --- a/Documentation/x86/mtrr.txt +++ b/Documentation/x86/mtrr.txt @@ -1,7 +1,19 @@ MTRR (Memory Type Range Register) control -3 Jun 1999 -Richard Gooch - + +Richard Gooch - 3 Jun 1999 +Luis R. Rodriguez - April 9, 2015 + +=============================================================================== +Phasing MTRR use + +MTRR use is replaced on modern x86 hardware with PAT. Over time the only type +of effective MTRR that is expected to be supported will be for write-combining. +As MTRR use is phased out device drivers should use arch_phys_wc_add() to make +MTRR effective on non-PAT systems while a no-op on PAT enabled systems. + +For details refer to Documentation/x86/pat.txt. + +=============================================================================== On Intel P6 family processors (Pentium Pro, Pentium II and later) the Memory Type Range Registers (MTRRs) may be used to control diff --git a/Documentation/x86/pat.txt b/Documentation/x86/pat.txt index cf08c9f..2c27d20 100644 --- a/Documentation/x86/pat.txt +++ b/Documentation/x86/pat.txt @@ -34,6 +34,8 @@ ioremap | -- | UC- | UC- | | | | | ioremap_cache | -- | WB | WB | | | | | +ioremap_uc | -- | UC | UC | + | | | | ioremap_nocache | -- | UC- | UC- | | | | | ioremap_wc | -- | -- | WC | @@ -102,7 +104,43 @@ wants to export a RAM region, it has to do set_memory_uc() or set_memory_wc() as step 0 above and also track the usage of those pages and use set_memory_wb() before the page is freed to free pool. - +MTRR effects on PAT / non-PAT systems +------------------------------------- + +The following table provides the effects of using write-combining MTRRs when +using ioremap*() calls on x86 for both non-PAT and PAT systems. Ideally +mtrr_add() usage will be phased in favor of arch_phys_wc_add() which will +be a no-op on PAT enabled systems. The region over which a arch_phys_wc_add() +is made should already have be ioremap'd with write-combining page attributes +or PAT entries, this can be done by using ioremap_wc() / or respective helpers. +Devices which combine areas of IO memory desired to remain uncachable with +areas where write-combining is desirable and are restricted by the size +requirements of MTRRs should consider splitting up their IO memory space +cleanly with ioremap_uc() and ioremap_wc() followed by an arch_phys_wc_add() +encompassing both regions. Such use is nevertheless heavily discouraged as +the effective memory type is considered implementation defined. This strategy +should only be used as last resort on devices with size-contrained regions +where otherwise MTRR write-combining would not be effective. + +Note that you cannot use set_memory_wc() to override / whitelist IO remapped +memory space mapped with ioremap*() calls, set_memory_wc() can only be used +on RAM. + +---------------------------------------------------------------------- +MTRR Non-PAT PAT Linux ioremap value Effective memory type +---------------------------------------------------------------------- + Non-PAT | PAT + PAT + |PCD + ||PWT + ||| +WC 000 WB _PAGE_CACHE_MODE_WB WC | WC +WC 001 WC _PAGE_CACHE_MODE_WC WC* | WC +WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS WC* | UC +WC 011 UC _PAGE_CACHE_MODE_UC UC | UC +---------------------------------------------------------------------- + +(*) denotes implementation defined and is discouraged Notes: diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c index ea5f363..12abdbe 100644 --- a/arch/x86/kernel/cpu/mtrr/main.c +++ b/arch/x86/kernel/cpu/mtrr/main.c @@ -538,6 +538,9 @@ EXPORT_SYMBOL(mtrr_del); * attempts to add a WC MTRR covering size bytes starting at base and * logs an error if this fails. * + * The caller should expect to need to provide a power of two size on an + * equivalent power of two boundary. + * * Drivers must store the return value to pass to mtrr_del_wc_if_needed, * but drivers should not try to interpret that return value. */