From patchwork Wed Jul 4 21:41:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10507663 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 A2096603D7 for ; Wed, 4 Jul 2018 21:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9893828CD3 for ; Wed, 4 Jul 2018 21:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D00828DAA; Wed, 4 Jul 2018 21:51:12 +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=ham 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 21C9928CD3 for ; Wed, 4 Jul 2018 21:51:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5E226B0271; Wed, 4 Jul 2018 17:51:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A34416B0272; Wed, 4 Jul 2018 17:51:10 -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 94A1C6B0273; Wed, 4 Jul 2018 17:51:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 56D696B0271 for ; Wed, 4 Jul 2018 17:51:10 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id f66-v6so460647plb.10 for ; Wed, 04 Jul 2018 14:51:10 -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=YPzzrmAzZitjBBlI2kBCwpERsJnlHaqIvV+SX3ToXJ3E7KvLBgHUZJJvUaROwhYbaD KV5BvCE6IzZJAUnAy2h19CS0wnTaaK0XsQDcYvc/bhK16Fn9dHizy8KIIySWQFWL9mwB /z3FLA/CU+fW1bFmzaOL3/XaTqfCykR+E5bN7+6R5h7o/pkOvEFDaQPDAYeoyRzbLUBd bVQnrQPEMzudxhI1vqSGjGOY5Wc3eUdH1TtE9Jc8rtlIBtxpF53Of3zNSshvLgRddW9a wQ0qE286v3XkhTR26SkDoiuTKWgF0g6xVQUkQG5QXq6sS+IrUzIxN6TTwKPicUFCjtOB D2Dg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 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: APt69E3o3onKnZKebJboJ6eqGuzY3XAJyEO+fHJJuJ6hXbx22PoAeWD+ BAE8YqQKU3UDRBS74IRr5+nzhLQrh3/wTcZA59fyM29pVz35NbHFJKbaGQPN9XIfaYFgJTW5++h bF2nCTTZoAMr13rHNUeDn+iu/HTxP9utM7gxbDnjBvx+Scy9c+rlsWwMUd8nZPv15Sw== X-Received: by 2002:a63:3190:: with SMTP id x138-v6mr3241337pgx.60.1530741070036; Wed, 04 Jul 2018 14:51:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcJBMyR5Aj2TUxL8Ins0XmSEv6zoG8Sueo5+RHAdn79IPIa+jM5G5XNfPzM1H3d/dwbSQ0b X-Received: by 2002:a63:3190:: with SMTP id x138-v6mr3241314pgx.60.1530741069377; Wed, 04 Jul 2018 14:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530741069; cv=none; d=google.com; s=arc-20160816; b=yDHUIM+JOzFdqfRuQ/BpPPrLccq6o5yfe08eK3ZywXivVycCmMQuRwVsmiEeu1lp0C ZlTUFMCLHr7WNZHoG5cQnK35j+UnLamKq8Dr987PQ2YMbcGTlVevn8Ub4WcYZOMJNUwg aile4tLkKgCFm/N3h6w3f2B4lQWu42KKNUxm1O+E2BZapZVH3CPMqeOrXLVZYytrFRa4 +I0rQN5McAu3ODorkMdLTfWRkNGj7KXV1+LmICM+43BxmcGxjSGXS+iAUl9UgET2BY1Z jY9ENgGoue1KUal2uQwFb8ddRvRoUnpYjVrepqUipYdBxHKNVqc0P/UBm0NpErFPPX4Q ODjg== 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=qDwkdphWoq2VACxRC1QufzEM0dKJvccKx+E+Kv7e5VUlfhbk7MxsvhCAGSfrwK673l RwhKAwfeL311nm03yr3syylt5r5Namn9UdxLqcORbA1tGgT1iYzhRcBNTyzUPv7/Zcgs Q0ZoW8Rv8JcM4f3ltqDV5Rx/Kc75K1nhpRT9kERcwtr9/MKlRM7a/TFww/oReof73Poh K/z9pZIS3hCXnbLE4Jk0HlmLe9XNKFSU6x3EpLoVfvvWmpS9mqja3iwuC8rEW2JmY4n0 yvLUVWnWK6zDkqsdjRZAt2vlZ1IUBZo2ddfpe2dmTeBUkI/DDQ4pAalzRTFWaR+cBqa6 MHgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTPS id n9-v6si3974594pgp.558.2018.07.04.14.51.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 14:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 as permitted sender) client-ip=192.55.52.88; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 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 orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2018 14:51:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,309,1526367600"; d="scan'208";a="64478224" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003.jf.intel.com with ESMTP; 04 Jul 2018 14:51:08 -0700 Subject: [PATCH v5 09/11] 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, hch@lst.de, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jack@suse.cz, ross.zwisler@linux.intel.com Date: Wed, 04 Jul 2018 14:41:11 -0700 Message-ID: <153074047123.27838.4050356397245428561.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153074042316.27838.17319837331947007626.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153074042316.27838.17319837331947007626.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;