Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp210478imm; Fri, 13 Jul 2018 22:01:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpchrJw2koi8wOJR8mQNQJtgSI8a71a5cMfSZ5hpbeVMbgc37Ll9miGMn2R6XxNI1kJuKpuz X-Received: by 2002:a17:902:ab95:: with SMTP id f21-v6mr8719278plr.264.1531544500608; Fri, 13 Jul 2018 22:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531544500; cv=none; d=google.com; s=arc-20160816; b=iBKaEppA87MwFIUmyCZfdZZrBwNrgL/X67FWpTczQxLPxCVGRJx63O4OC+HnJzipCQ +UpESa5vbYHYTcD/pOTTcYpaOBCAay+PZy1+R268zXamjzRDyShHrC0cuq4Jlo3JAM4W PdAY5sy1pSJFRGlpDVKoODqWRBmq+zO5H6EUhvN+vzzxYxIrKP53DUW8dLgENbuyNF99 uSk2Z0U06lzuF8EHgEgTJ3Sypw886++r2i69hav0I43wV80b3QUCIevMrik2pH9np9pJ y/82y5Zvlxttw4r1BB4y14QoomvfVQskYIfF/k/N9Ii/zswF0SxXvdOmvpM+XsOdacNH 0D5w== 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:cc:to:from :subject:arc-authentication-results; bh=xUZgIa01soZI+mflDEELoN6k8at8cOVNORNaKGLS5Q4=; b=NpIuJBAEUJcG/uDm8jE5OH7zwLQdQAXzj1PLkLg2RtUU6ozh/liECO0lnoFrIIYC/f bDsl8cxlsK4E21pA/XwqplzvJehrMtYDOeaxeNA1um+BRvkQnmkcETBsP1/QZ5wjl6Qk W0tfWGDi09gasxg6+EmJsSv7DPUCHaNV0fzjSBce5Yp/Q69PNscv+mpdypdyOH+hoB3O BQrOYBz2jWaBy9thcGCn0Ar5X93Ys5O1Wl05guUMHNSPywpovP0L/Qv2BIFiUwxk54ty 4vnnhIZbs8/Rff0sQztlz+d1mxgg7L6W4kIEj1DEze9Q44X24juyFex4KlVAFJdj3S0X +XZw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10-v6si23093220pgf.470.2018.07.13.22.01.25; Fri, 13 Jul 2018 22:01:40 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727349AbeGNFSF (ORCPT + 99 others); Sat, 14 Jul 2018 01:18:05 -0400 Received: from mga06.intel.com ([134.134.136.31]:28125 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727199AbeGNFSE (ORCPT ); Sat, 14 Jul 2018 01:18:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jul 2018 22:00:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,350,1526367600"; d="scan'208";a="245634850" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga006.fm.intel.com with ESMTP; 13 Jul 2018 22:00:24 -0700 Subject: [PATCH v6 11/13] x86/mm/pat: Prepare {reserve, free}_memtype() for "decoy" addresses From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Tony Luck , Borislav Petkov , linux-edac@vger.kernel.org, x86@kernel.org, hch@lst.de, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Fri, 13 Jul 2018 21:50:27 -0700 Message-ID: <153154382700.34503.10197588570935341739.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153154376846.34503.15480221419473501643.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153154376846.34503.15480221419473501643.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for using set_memory_uc() instead set_memory_np() for isolating poison from speculation, teach the memtype code to sanitize physical addresses vs __PHYSICAL_MASK. The motivation for using set_memory_uc() for this case is to allow ongoing access to persistent memory pages via the pmem-driver + memcpy_mcsafe() until the poison is repaired. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Borislav Petkov Cc: Cc: Signed-off-by: Dan Williams --- arch/x86/mm/pat.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index 1555bd7d3449..6788ffa990f8 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c @@ -512,6 +512,17 @@ static int free_ram_pages_type(u64 start, u64 end) return 0; } +static u64 sanitize_phys(u64 address) +{ + /* + * When changing the memtype for pages containing poison allow + * for a "decoy" virtual address (bit 63 clear) passed to + * set_memory_X(). __pa() on a "decoy" address results in a + * physical address with it 63 set. + */ + return address & __PHYSICAL_MASK; +} + /* * req_type typically has one of the: * - _PAGE_CACHE_MODE_WB @@ -533,6 +544,8 @@ int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type, int is_range_ram; int err = 0; + start = sanitize_phys(start); + end = sanitize_phys(end); BUG_ON(start >= end); /* end is exclusive */ if (!pat_enabled()) { @@ -609,6 +622,9 @@ int free_memtype(u64 start, u64 end) if (!pat_enabled()) return 0; + start = sanitize_phys(start); + end = sanitize_phys(end); + /* Low ISA region is always mapped WB. No need to track */ if (x86_platform.is_untracked_pat_range(start, end)) return 0;