From patchwork Mon Jun 5 14:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 103282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2716962vqr; Mon, 5 Jun 2023 07:15:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Cg8T8yjAp1AW807l2Zju9kdcH3oNNz7ZHgTaLxQfgGcA9dLKjgT/dgYbyBX3zhTWOdKEU X-Received: by 2002:a05:6a20:42a3:b0:114:6669:21f8 with SMTP id o35-20020a056a2042a300b00114666921f8mr2889241pzj.35.1685974547957; Mon, 05 Jun 2023 07:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685974547; cv=none; d=google.com; s=arc-20160816; b=pw5ZAY8cep9PghH4483PgBuxUYzg2Vkd1F87YApNrSy0G/rrnA7O4licHHlpZB2qbF vQQemt41SmComOypn4tSDOV+HY2gphJKraNhXKBrVV+5XDuQEyA7tPboZDq7k09cKD5W kaTZn/i/asa00hNNfBAl11LqM/qT08U+ycpmAak3bVm1raokUZmwi3vW9zZtwBIeeOpc m/iUZD7JC5OiXdCPnaoWGgmXl+YCR5/JII5ZH0UHtNoglUtsWwmdSJ3rnZo0Gh5CDKNN gqkPU+Jgrn56gREDURzf+TR6W/m3vVcqNPelBWg3C+Qa7HBIwrb4OEfBLfhEgRL8E7Yf cmQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=9Kb8ggiqGNt/KIP6O4DQ2argUL9ZpkFBooFelw+TaMk=; b=rE+Ah+GaKyRw1OJkhK8ryjOrnFV8+fcOweT5/KnAC91A1mOw8ICqMUyFA47d3IziFE a+UrBwcAbQdrhCuiLH6nHnTuKO+cbCgcg+ZT19Vurc6O79dSoejlbk/hkgnw7tSggW/+ 3+L+GD2RJF8eC8V8l6uLFjpFXErXMzqGASi1JTOSg2wAs4SidXPplQa8yK3V+MpVHaGc OqyzsL/Xfi6Paj34ReLwq4sjvzXp3j+l5rKeWJt9jJPJVM8ZS3uH1PCmwv7uWdewYNJH mx1xaAerylGhVJqeHBHsvio2Jq571VzOybUJkWmbTZzwQuQFtW+Jnb0pxSNaCOtneuNU 7SfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="E/uU3kRO"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q21-20020a63d615000000b0053ef31be221si5534513pgg.841.2023.06.05.07.15.34; Mon, 05 Jun 2023 07:15:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="E/uU3kRO"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234427AbjFEOI5 (ORCPT + 99 others); Mon, 5 Jun 2023 10:08:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234106AbjFEOIb (ORCPT ); Mon, 5 Jun 2023 10:08:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A5F5E49; Mon, 5 Jun 2023 07:08:15 -0700 (PDT) Date: Mon, 05 Jun 2023 14:08:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685974093; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Kb8ggiqGNt/KIP6O4DQ2argUL9ZpkFBooFelw+TaMk=; b=E/uU3kROn8LS1g8ciw72wiWWc4vmZldzurMoSACt58YdKcIyFobI8z+H2MEV5N6rOf4J+6 0/7FdRHA6nEkpdVX7ohajJX/xIMmcGgnYt7gVP+r4qdrK2S+13OY6/tlxOsUx0CgJlW7bt PuPv0qjpKVxt0Qujgbk76g7TrKZga31NZf+UWnlrXmwYuxLNMf1tTLUzuSKIe2NJFWDkPO XvYzD7VzjQObns+LdLr6WITzxAcofkijHvyKmFgPyLSUwNLqpfEg0aVeC44/KdwJ/05Jk2 xFLvrwKVhJ4xvtignObn/v4WId16Zd9WlWZZxAHf3+sJ8cq7SV1/yDOy58QJyw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685974093; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Kb8ggiqGNt/KIP6O4DQ2argUL9ZpkFBooFelw+TaMk=; b=bqA5xzVuTLXTTSHYpPGD+go31gLU1KuFqgL2F+2Td7qT8ub2qUmg4g/d/mDOnthNpyaUep V3jU6vFuzA93A4DQ== From: "tip-bot2 for Juergen Gross" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mtrr] x86/mm: Only check uniform after calling mtrr_type_lookup() Cc: Linus Torvalds , Juergen Gross , "Borislav Petkov (AMD)" , Michael Kelley , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230502120931.20719-16-jgross@suse.com> References: <20230502120931.20719-16-jgross@suse.com> MIME-Version: 1.0 Message-ID: <168597409343.404.684368670702488833.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767872447261196300?= X-GMAIL-MSGID: =?utf-8?q?1767872447261196300?= The following commit has been merged into the x86/mtrr branch of tip: Commit-ID: 12f0dd8df14285a5604f35ed3af8b8c33e8fd97f Gitweb: https://git.kernel.org/tip/12f0dd8df14285a5604f35ed3af8b8c33e8fd97f Author: Juergen Gross AuthorDate: Tue, 02 May 2023 14:09:30 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 01 Jun 2023 15:04:33 +02:00 x86/mm: Only check uniform after calling mtrr_type_lookup() Today pud_set_huge() and pmd_set_huge() test for the MTRR type to be WB or INVALID after calling mtrr_type_lookup(). Those tests can be dropped as the only reason not to use a large mapping would be uniform being 0. Any MTRR type can be accepted as long as it applies to the whole memory range covered by the mapping, as the alternative would only be to map the same region with smaller pages instead, using the same PAT type as for the large mapping. [ bp: Massage commit message. ] Suggested-by: Linus Torvalds Signed-off-by: Juergen Gross Signed-off-by: Borislav Petkov (AMD) Tested-by: Michael Kelley Link: https://lore.kernel.org/r/20230502120931.20719-16-jgross@suse.com Signed-off-by: Borislav Petkov (AMD) --- arch/x86/mm/pgtable.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index e4f499e..15a8009 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -702,14 +702,8 @@ void p4d_clear_huge(p4d_t *p4d) * pud_set_huge - setup kernel PUD mapping * * MTRRs can override PAT memory types with 4KiB granularity. Therefore, this - * function sets up a huge page only if any of the following conditions are met: - * - * - MTRRs are disabled, or - * - * - MTRRs are enabled and the range is completely covered by a single MTRR, or - * - * - MTRRs are enabled and the corresponding MTRR memory type is WB, which - * has no effect on the requested PAT memory type. + * function sets up a huge page only if the complete range has the same MTRR + * caching mode. * * Callers should try to decrease page size (1GB -> 2MB -> 4K) if the bigger * page mapping attempt fails. @@ -718,11 +712,10 @@ void p4d_clear_huge(p4d_t *p4d) */ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) { - u8 mtrr, uniform; + u8 uniform; - mtrr = mtrr_type_lookup(addr, addr + PUD_SIZE, &uniform); - if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) && - (mtrr != MTRR_TYPE_WRBACK)) + mtrr_type_lookup(addr, addr + PUD_SIZE, &uniform); + if (!uniform) return 0; /* Bail out if we are we on a populated non-leaf entry: */ @@ -745,11 +738,10 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) */ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot) { - u8 mtrr, uniform; + u8 uniform; - mtrr = mtrr_type_lookup(addr, addr + PMD_SIZE, &uniform); - if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) && - (mtrr != MTRR_TYPE_WRBACK)) { + mtrr_type_lookup(addr, addr + PMD_SIZE, &uniform); + if (!uniform) { pr_warn_once("%s: Cannot satisfy [mem %#010llx-%#010llx] with a huge-page mapping due to MTRR override.\n", __func__, addr, addr + PMD_SIZE); return 0;