From patchwork Mon Jun 4 23:12:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10447467 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 83B4E6054D for ; Mon, 4 Jun 2018 23:22:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7604E29222 for ; Mon, 4 Jun 2018 23:22:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ACCF29227; Mon, 4 Jun 2018 23:22:17 +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 0C01129226 for ; Mon, 4 Jun 2018 23:22:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5B666B026A; Mon, 4 Jun 2018 19:22:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D30A76B026C; Mon, 4 Jun 2018 19:22:15 -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 C47FB6B026D; Mon, 4 Jun 2018 19:22:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 82DDB6B026A for ; Mon, 4 Jun 2018 19:22:15 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id r4-v6so103367pgq.2 for ; Mon, 04 Jun 2018 16:22:15 -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=Rix3a4y3T+21hASfPLsDx9gS7ozwTqL10sUlfggnIRvp07R0iKRbrJUQJovuAe9EHa REMadVW+YtcAXm52p2lA003r/WpaszDtqtbljprcoMpeKihWOQ0ydy1PLJxBax6AJwhG poh9pBnT08zwajB32rKkbZwdlGv03hmJyMgP3bpIoSBjwQL7XpSkz0ugpbfzbkBMZp3o L/PyMSGwraTNXhVtj3srHX3Y3ZluiUo1chTpHgod/hKn9Im2vi1hC5Yqk+wJByJ0B1oR dJ03Fw/+AGSyX3btrlIXwkTbR9pRMka/3xzVdPTS2fKDbhfWcBz1olfkHBRauol7AhFx zwlw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 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: ALKqPwck8PrbOojcgYMm8m8H9xZGuzQ5zO7t+Ra4+rMN+2nYoVdPt5kU tYcpHJDMPqhNF9l+EIDXzw9OCVABw5SGoUMPqItpy0ePg9j1A31CXbjxWY8PvfQiMutJQrDQ1UU GwsG0muCtNc568lHu5wCsrI2GGSXCb09qqG4iRhnuvlZS/TtWJFX00yxs06XvKf8BMQ== X-Received: by 2002:a65:608d:: with SMTP id t13-v6mr18515548pgu.266.1528154535205; Mon, 04 Jun 2018 16:22:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIZyNxb++ah94OmPjhJOqk1RPLzQqhGAZDPw0H+/1zL6KiXd5v+3y8fDcjAh4tHLm7MrWit X-Received: by 2002:a65:608d:: with SMTP id t13-v6mr18515520pgu.266.1528154534478; Mon, 04 Jun 2018 16:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528154534; cv=none; d=google.com; s=arc-20160816; b=zNfVuh460/7xopSx95VJZFIkhyMuQX3VLlSM46xPZRagD8CHCudPUel8elTwwYOROh XLV9gGzpxwH6jCwpalOsdH1+W2TFfPGS4OAfgwvaim5zIhuudo6Hfp+ZU3UU/QQJnokn OYf9usFe3Cl9vSTUfb9OtOue1Vycp3cENlBmkkQZnjYD4KRhlSlC4+h+uNSRMPtevWl5 Ncx3j5exogMcTR4Y1aWJXU/ZcIXW9ZwCVvsYyPu3JmBVqDu2FYTaoUuJ0r397XaTyXrR bUKRpklbp8gxyk63swsewXujA47RqOvUHmMLD1KFfINzhWe/n06W9GKITTFi6H/kGBOv Ra+Q== 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=Pr9oSe/xHG/zejFMZhXNBUJa+AbPwrLpa5Rr26ox9WlHckIu+4w2JRLRf7v9KC7RMa xolV//TvYiondDsBCzeBvTZ1k9ZXIH4rU9Sd8YdO2ppdBkW+O39yOZ3Hhjbc0Is1wqGB QhrNIZqSJhwb0Yks0YQCQRj5XQ/62bF5XkJdS/zNmzV8JGVJjiqPW1DbeusDcjIPNPtK h+cqyd+XL4eyI11OgXN8jfeLrLGCQV0z2o+aFcJzx9GEfh9Cf5/YuP8RNhUN+60h7rFj QeLxiReh31tY+RKUsaYz0KbnS7D+cQ0r3XAJrOrOWNLM0/3hhkXhMw/Bp8m3wcmT+NnO k54w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id a143-v6si7072314pfd.258.2018.06.04.16.22.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 16:22:14 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 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 orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2018 16:22:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,477,1520924400"; d="scan'208";a="64291821" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga002.jf.intel.com with ESMTP; 04 Jun 2018 16:22:14 -0700 Subject: [PATCH v3 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: Mon, 04 Jun 2018 16:12:17 -0700 Message-ID: <152815393710.39010.782984743904638793.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152815389835.39010.13253559944508110923.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152815389835.39010.13253559944508110923.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;