Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4530248imm; Mon, 20 Aug 2018 18:19:03 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyomSSWvPr/A12LENIhIJxEasb4aOd/TqVynBCxDi/1F+ijW50hb2Orw3YHwHMJd3gy16/N X-Received: by 2002:a63:4826:: with SMTP id v38-v6mr9900140pga.379.1534814343791; Mon, 20 Aug 2018 18:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534814343; cv=none; d=google.com; s=arc-20160816; b=CnfEmfrsLL7z7oPgyGZAoN6K2A2y9XBDkc0sEhdGuGuyDOrPBaEKg7j6eIKqTF5OOu Fj13KTsF600uHGJ0BoySFavqW4sNRlfh1kKDH6RtoRh1+8w59AVvvBNEIF36oHYGz4WT 7lWnzTjybPOy4QzGVQ1fp1Z1o+WWcHKNKH5mQJdOq/MjnXIp8upc9OoKvLdJkEsIxQBn BiFOxLRgWVz15k+65EL0yZTFMtOIKYKPlvwGEk1/MAoy3dbiX8NtfHvLVtIXUrqby6VK tRoG5M01Tq9P58Po9xuSlfxAyEL6vgkudNYZNyGNP1b766rpV2lhLsbBeox5GBfIbFJx me1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:arc-authentication-results; bh=kbn3w+/oAv+QK+zBDGZWoOHXbPNMIWJCblMN6Ihvws0=; b=IeDH7GEDTP7ehGK9kSlOV/sBJHg38ocFHscIuTjk37A7n0b2ou8/9EQP25+sVeDkOS uzmRZoT3e51ArgoJnanP5AD244bOZKw6CbsHwyk6s3TGaibXBD1BRSpP/bM32zNHDpd2 LJRSP5rnyB8flmsD9f235fT80yhKGVMjmTXOMx+vMp+CP7LvlpR6Iz8ms+v/rQDP8/H3 MNHl/3vFqaOxMOk7YQUbzOx2l69D84q2hhLK7p6Cu+Eu4U/vvSH+aIowdXAbtS6T9sHw JXK90O7PK3DWLek3MuIVfl/e2mdtDy0g3YUMQKiQRC9xcE5ypRk1B7QOr5+B0dF+LDe5 incg== 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 c16-v6si6464289pls.63.2018.08.20.18.18.34; Mon, 20 Aug 2018 18:19:03 -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 S1726797AbeHUEeg (ORCPT + 99 others); Tue, 21 Aug 2018 00:34:36 -0400 Received: from mga07.intel.com ([134.134.136.100]:17761 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725733AbeHUEeg (ORCPT ); Tue, 21 Aug 2018 00:34:36 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Aug 2018 18:16:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,267,1531810800"; d="scan'208";a="74359144" Received: from shbuild000.sh.intel.com (HELO byang_ol.sh.intel.com) ([10.239.144.215]) by FMSMGA003.fm.intel.com with ESMTP; 20 Aug 2018 18:16:39 -0700 From: Bin Yang To: tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, dave.hansen@intel.com, mark.gross@intel.com, bin.yang@intel.com Subject: [PATCH v3 3/5] x86/mm: add help function to check specific protection flags in range Date: Tue, 21 Aug 2018 01:16:24 +0000 Message-Id: <1534814186-37067-4-git-send-email-bin.yang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534814186-37067-1-git-send-email-bin.yang@intel.com> References: <1534814186-37067-1-git-send-email-bin.yang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce the needs_static_protections() helper to check specific protection flags in range. It calls static_protection() to check whether any part of the address/len range is forced to change from 'prot'. Suggested-by: Dave Hansen Signed-off-by: Bin Yang --- arch/x86/mm/pageattr.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 091f1d3..f630eb4 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -367,6 +367,30 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address, } /* + * static_protections() "forces" page protections for some address + * ranges. Return true if any part of the address/len range is forced + * to change from 'prot'. + */ +static inline bool +needs_static_protections(pgprot_t prot, unsigned long address, + unsigned long len, unsigned long pfn) +{ + int i; + + address &= PAGE_MASK; + len = PFN_ALIGN(len); + for (i = 0; i < (len >> PAGE_SHIFT); i++, address += PAGE_SIZE, pfn++) { + pgprot_t chk_prot = static_protections(prot, address, pfn); + + if (pgprot_val(chk_prot) != pgprot_val(prot)) + return true; + } + + /* Does static_protections() demand a change ? */ + return false; +} + +/* * Lookup the page table entry for a virtual address in a specific pgd. * Return a pointer to the entry and the level of the mapping. */ @@ -556,7 +580,7 @@ try_preserve_large_page(pte_t *kpte, unsigned long address, unsigned long nextpage_addr, numpages, pmask, psize, addr, pfn, old_pfn; pte_t new_pte, old_pte, *tmp; pgprot_t old_prot, new_prot, req_prot; - int i, do_split = 1; + int do_split = 1; enum pg_level level; if (cpa->force_split) @@ -660,14 +684,8 @@ try_preserve_large_page(pte_t *kpte, unsigned long address, * static_protection() requires a different pgprot for one of * the pages in the range we try to preserve: */ - pfn = old_pfn; - for (i = 0; i < (psize >> PAGE_SHIFT); i++, addr += PAGE_SIZE, pfn++) { - pgprot_t chk_prot = static_protections(req_prot, addr, pfn); - - if (pgprot_val(chk_prot) != pgprot_val(new_prot)) - goto out_unlock; - } - + if (needs_static_protections(new_prot, addr, psize, old_pfn)) + goto out_unlock; /* All checks passed. Just change the large mapping entry */ new_pte = pfn_pte(old_pfn, new_prot); -- 2.7.4