From patchwork Sat Jul 14 04:50:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10524529 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 2E29F602B3 for ; Sat, 14 Jul 2018 05:00:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EB64294E8 for ; Sat, 14 Jul 2018 05:00:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 130EB2959F; Sat, 14 Jul 2018 05:00:31 +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 093EC294E8 for ; Sat, 14 Jul 2018 05:00:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E542C6B0270; Sat, 14 Jul 2018 01:00:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DD9EE6B0271; Sat, 14 Jul 2018 01:00:26 -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 C55CC6B0272; Sat, 14 Jul 2018 01:00:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id 7F9436B0271 for ; Sat, 14 Jul 2018 01:00:26 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id y7-v6so20823083plt.17 for ; Fri, 13 Jul 2018 22:00:26 -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=DPTl2aglZ2jM35TM76VdjJP6VSpL5SAkRZQURm4AHd3krlnCu87DwfFcjaRwvZYsPC CYmE7yTNpzgPZBV8MJa2PuskKy0k+xkw4aANWv9fMpU9aovYLyHZL4J7iwVtRYZhu9OY 7xK1NmZvaGZQP8a3v8+mO5qSz/WVVHm20VcLiO/AC8o5/dysB8cyqmO0JN/BZD7KZgDB 9LyNaNf9c7vboUZk210C8rGaXignlMMl0jivY4o9Yb9tKUBx3RA01yVhOLmWTClsSCZn KzMyUs4Xw5yjA+Mq1I8OXgDza0aMSWPLBtgty0w8RM8ctTibdERWv/z8Mdm1lSieQGQI OqLw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 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: AOUpUlExJHAnyshf+XDUnvxMF40jbeZdpSQLoenLtdsma32pkq2iu6Sp SSbbOa7u2gwQ1bP7b40Jd6YTGvT0fp4MtOg9wH/W4sJzrpqQr3wCV8HI1I+jm68JiNk8r07AsNm cCT2GcldhIvOQF45yZHQK0ws97MhH7d2+mtYp+PxZxK0cZR/oFrbTxiQKOy40HVlYOA== X-Received: by 2002:a17:902:8e87:: with SMTP id bg7-v6mr8877826plb.129.1531544426196; Fri, 13 Jul 2018 22:00:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeP5D7cYxb8yK9DgS5YCOmlG2SIFNNfL9w6iU4zd1zDSE2hbXBZeEMoxkEBl2f22EEuG8Z1 X-Received: by 2002:a17:902:8e87:: with SMTP id bg7-v6mr8877795plb.129.1531544425553; Fri, 13 Jul 2018 22:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531544425; cv=none; d=google.com; s=arc-20160816; b=KygHm8fHWEWpSwabfSqLIIS5BlWyi6GtctLo7CIF+aSM52pHaWiRM60rG99caWULl4 cu/Vy3LMV4FAXIQjd9ptgX/UtVvuL5TtjGFfkEwhQSZjHfO8+iOOk3N4N3m1OEZfSKPO eJJj1c5ybAWHCHRkFvuOUF9V/BL9YtE1muoqmoF7XzO1TqqBNwoAOffy2JA/bfYah4Wg SDPfNz1Kat2NpXMngRMTTwxqIm8JobzNmpsEJaYxJviAuPEVwu9y2MdHkK/FGlEFvGZn T9QFf1BGfQb4bTJbmAQ13xjuiGPskdGysyc3dOs6VQVrBlLC+HgLuwDKJhPMhvQC/+zT at4g== 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=mf2GtaKMKSBdBBxEsgGWAr74jnRx3Fo8mpwaQu/a/MrF2kaZOFD3MYwkYVM8+JUGqk LbeTNdnwCww/0Nwr8PFiysiO0HJt4Ohb5wMWwig0xSbYarIYpniZ7XFJFTIv62FvoR0G oC+CYQwUaoRmh8UUitYntEi/9pIjQHjRoBseGSLXuFuKeSTCiCX0wqCVCK/4LlwIQh14 w2XxGY3Says187ZN4wTNzN1sDDFMoOFOBWRYkPNviGirfl583z0KRfgNGMwhSyceiJmv 4YRtvbOycEffF5ovVX6MkMPbyBnPAVLBGKG+LcrnjJ15Q3J27XSs7F5vqIUF/zkO9K3s Kbhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id r7-v6si25486631ple.435.2018.07.13.22.00.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 22:00:25 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 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 fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.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 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;