Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4530243imm; Mon, 20 Aug 2018 18:19:03 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw1vhXrHc2ZTxl79HM2l/ZvrGAn8xOHnws6JXdDoYb/lUBVgWvdNyvmFOtmFs2MvFDdqEP3 X-Received: by 2002:a65:5144:: with SMTP id g4-v6mr44767506pgq.21.1534814343774; 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=njcGYBJcSd7T2/UvXUgZFBdaWL3/XvNRTBWLRZ/3oEU7MWejFEhQuNAmzhQVWWxJai hr8LzdhZJ0kVQMzeGonNabuXfU4hpmxKxtkeAVzBlijoU5SBMVk4/sViUj6XNPPSM/LR ibxCkgurVIHRFnHkV5ezdV3I7iRHGzYD5+PoTE/jTsMiygZKCO94wOvA5J0JXJrd001w YHKKj+LEpJbBIaH+oq1NklsDYbUkxe4nz9QpyqF99oz/8Zt/dJI/mu0Udtm9GVOkAa/Q DU0efkZ8sDJd3iAUuvfq5VgXixtBo8sXVKerS490umR9Z6MDFRN1nAh1Ybd2tR83AK6S d+VQ== 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=pod1ik9dDOZRo7pne689HUQ+47S1+Xa2ogstoYpxTfo=; b=cKmgkR2jz1HG0+jKzN5dLDMym6NysufP6gXIvpZV2Om0UuCb3hgKK02tI8rtNJhdch Vg36ug7bV2pyeIDLbN+hjkmprI1tdYf/QO8VLq1DdqchQ3TIV6mkHfRAuflsNdKu8Qhw gzK5yEWSRhR2avMt2DTrzOVzDCBUeKy9/xVuOPe9uQnOrRKiQaRDyePGwYlPw4R670LD slROSiWXWEliuhuEm9Hnplfz12hhNCRxKfEP1isfZL+x4bzuJJKsq/BU3rsQDAYAQZJL zN20KeZkltZRgElt+JkUqLB8mfB+Nzkhr8PfogHfdcSzTkuSzW1YdW+q8ZwJDVWswl7E rj8g== 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 m188-v6si10956559pgm.355.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 S1726760AbeHUEef (ORCPT + 99 others); Tue, 21 Aug 2018 00:34:35 -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 S1725733AbeHUEee (ORCPT ); Tue, 21 Aug 2018 00:34:34 -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:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,267,1531810800"; d="scan'208";a="74359141" 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:37 -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 2/5] x86/mm: avoid static_protection() checking if not whole large page attr change Date: Tue, 21 Aug 2018 01:16:23 +0000 Message-Id: <1534814186-37067-3-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 The range check whether the address is aligned to the large page and covers the full large page (1G or 2M) is obvious to do _before_ static_protection() check, because if the requested range does not fit and has a different pgprot_val() then it will decide to split after the check anyway. The approach and some of the comments came from Thomas Gleixner's email example for how to do this Suggested-by: Thomas Gleixner Signed-off-by: Bin Yang --- arch/x86/mm/pageattr.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 68613fd..091f1d3 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -645,11 +645,21 @@ try_preserve_large_page(pte_t *kpte, unsigned long address, } /* + * If the requested address range is not aligned to the start of + * the large page or does not cover the full range, split it up. + * No matter what the static_protections() check below does, it + * would anyway result in a split after doing all the check work + * for nothing. + */ + addr = address & pmask; + if (address != addr || cpa->numpages != numpages) + goto out_unlock; + + /* * We need to check the full range, whether * static_protection() requires a different pgprot for one of * the pages in the range we try to preserve: */ - addr = address & pmask; 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); @@ -659,24 +669,11 @@ try_preserve_large_page(pte_t *kpte, unsigned long address, } - /* - * We need to change the attributes. Check, whether we can - * change the large page in one go. We request a split, when - * the address is not aligned and the number of pages is - * smaller than the number of pages in the large page. Note - * that we limited the number of possible pages already to - * the number of pages in the large page. - */ - if (address == (address & pmask) && cpa->numpages == (psize >> PAGE_SHIFT)) { - /* - * The address is aligned and the number of pages - * covers the full page. - */ - new_pte = pfn_pte(old_pfn, new_prot); - __set_pmd_pte(kpte, address, new_pte); - cpa->flags |= CPA_FLUSHTLB; - do_split = 0; - } + /* All checks passed. Just change the large mapping entry */ + new_pte = pfn_pte(old_pfn, new_prot); + __set_pmd_pte(kpte, address, new_pte); + cpa->flags |= CPA_FLUSHTLB; + do_split = 0; out_unlock: spin_unlock(&pgd_lock); -- 2.7.4