From patchwork Fri Jun 8 23:50:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10455365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 14A1660234 for ; Sat, 9 Jun 2018 00:01:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAF08294F7 for ; Sat, 9 Jun 2018 00:01:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E955D29545; Sat, 9 Jun 2018 00:01:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C55262956D for ; Sat, 9 Jun 2018 00:01:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C6596B026D; Fri, 8 Jun 2018 20:00:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6250B6B026E; Fri, 8 Jun 2018 20:00:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 452FB6B026F; Fri, 8 Jun 2018 20:00:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id ED2326B026D for ; Fri, 8 Jun 2018 20:00:56 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id g6-v6so8189374plq.9 for ; Fri, 08 Jun 2018 17:00:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=xUZgIa01soZI+mflDEELoN6k8at8cOVNORNaKGLS5Q4=; b=iLhs2jrxe7ub8xsSBCWW6XUtgCawT/6guuUrDFvGl3zRlLOm8AnkL6eT139sgxnQJE 4BTLZ2X3p2DWASiGKyW3RlQ+V5uR16wgJxrdDcTL2DPdPy/0waUl3ZHog2u0+NidAge5 vslphWxxJqAIaZ3ecglaSxKQPfzOOXihkWdAHZUNF7iYzfcPFouwLHgTECVH6BmQtfr2 RN+aBKiIHiEnEUd4JuoB36cmSn/JxlKTl9XR4pE6zO4kXKxnOXtwNlVQAGqcPHf5Ny3B aljHRlhjl5YS5p/YD6aIxAR/Uq1VCbHEXMnyvHEsg6X885jQW/K1SzLd/P3WmcBT0o8M mzzA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E1gKcmSV98Lk4ch7f2Zs+WMEyBh5Ptv9FGe8WqR4H5dyo7Hl0v+ fsvJesPi4q81T/kJqfXzxG5vj1BTaK8gCyCIdQi2iTjel7RT8op3Z/fkm6jxpkzhxRZYKnUWbuh Zv8g09csi6Cqq4qysZYGyyxTnt7aGseF1Er2to2Xc0Hwh50mIaY1K8vTE0nvzb3UbDA== X-Received: by 2002:a63:7356:: with SMTP id d22-v6mr7012912pgn.156.1528502456635; Fri, 08 Jun 2018 17:00:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ4v3OOWUFexOyhQJEGpfXyV6sXfNagP58XNm1praZ/+uakj4WWLcvxHTwAVu2tVywmVhkY X-Received: by 2002:a63:7356:: with SMTP id d22-v6mr7012877pgn.156.1528502455906; Fri, 08 Jun 2018 17:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528502455; cv=none; d=google.com; s=arc-20160816; b=WKfOMDr71pYjQNJp9RM2DoHxCinMbqSm9Bd5bkjjjJ8QlKBHiXf2upipQHs8D41pl/ GEt1xWRqW0s+3l4iO+wFW7xd8RHVRZ8BkTwdYlMmDuy0OUx3NdFQDl6l1lsOToN8bpAG bA5bzIR3aG5dVYRLiLlQwq72L4rJU0XYylLg5C5aiLtlbMCu1FkQYOFHRkt06jQ6I96j bLWbrg9VriwODWg/2Kzb8jleHtpx/pafh7qzB5cRR+kJuXtI0nfJF+TFrYirFWAis/3t WLJ+xGW8zjjEWqiKqRZo45Hb6rWDbesH8Ljd7SBXBkkqqTkfbLTJm+0xLTPz8QpBlm8n 9ozA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=lFJXk6NB0coVRniColYHfAcr+bte8l6SfnS0XpzNBMH6hujAd99ZbcxFGp6keWOelL sNUmrU7zRClRM//+droGvZhV7QtW98tZFsW4gVniBMIvVJxwv7KzQSZIHSbUZQ50KKhk r9Np3DoMs6sxktAHoWO5r+EZ0oWj8YojpEiQ0HI55RNrvqHbgADRKhrnBfrQ8iVCj79/ AzX/bPCFBTlq5CNjVDN1wcGujOStarsjSJX5y+oeqrNoNa71zuI7K/1u72+Arg+nN6fq jpkmRiEGhpG44tI4IaRF4SiN409IqoVRmsQDh7qlOmfC4vhDLifpyPFgplyi2u8Fgq5u Jh6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga04.intel.com (mga04.intel.com. [192.55.52.120]) by mx.google.com with ESMTPS id t127-v6si8472290pfc.174.2018.06.08.17.00.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Jun 2018 17:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) client-ip=192.55.52.120; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jun 2018 17:00:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,492,1520924400"; d="scan'208";a="62555440" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga001.fm.intel.com with ESMTP; 08 Jun 2018 17:00:55 -0700 Subject: [PATCH v4 07/12] 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-mm@kvack.org, linux-fsdevel@vger.kernel.org, jack@suse.cz Date: Fri, 08 Jun 2018 16:50:58 -0700 Message-ID: <152850185800.38390.16809919962943041626.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152850182079.38390.8280340535691965744.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152850182079.38390.8280340535691965744.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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;