From patchwork Sat Apr 1 06:36:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 78064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1064776vqo; Sat, 1 Apr 2023 00:10:55 -0700 (PDT) X-Google-Smtp-Source: AKy350ZqkTAYO1MNGRyXL73RoMZfFAGUNVDjejE+WT/m61uyA1gEh80R/tlq9wNnUf3OvJ78TEBb X-Received: by 2002:a17:903:2448:b0:1a0:5349:6606 with SMTP id l8-20020a170903244800b001a053496606mr35153694pls.56.1680333055740; Sat, 01 Apr 2023 00:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680333055; cv=none; d=google.com; s=arc-20160816; b=tS+FKFE7uxHRKUcCvB/A9rtH5cQG1u09o2CdvlzQA/gn7kwLahKoo8+QW1f5KWu0UY dDQ3jqPYQXr2X/2eHRC41rCafI7RX8P63Ov6hsloJh2tLXLQ6cs4cmzEJWJp1M+TwNFN brzyf/U+FEf6M8ZCcP7nzOPHmDBSD7D7cewt/xLzn5HSQzzi+WP4PD16JCNy121E0W4C v7pUxoW+ZqBSXd3AguJdKoccaGXVmvFvjjPWHlWSHET/1cPDT9O7gJYt9mVzQbfbRHjU SFvH94WNkRP2xwbVh7iUosKgbhpgBrKGuYhNcni9/xtEsfYu6yo4LntSefkTnIx2+4MI X7pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PLhZnRzaTF/w19VvaTwREzeMUwLtgou6VVO1Iy9aXOI=; b=VwF4N4RRZ+UOVtCEZbQau6R0SoCNcP5VoBo0/9SuhHE83jl6TmMKb/ygE3SS6BLHlS kYP+MD+GuKXmGI5JGn8GQSqXaReAIc/QExaPlH5jhnYZqyml32DAZI68l0dYbSLbshYi m67wFd7S/u1boz1le/rHJtQSbonb5lL4kjEHsq2YLatn+XYKsM/ccFYG/ZSWtXgce0tZ rj77moX4xYYB63dDDa70DOJmZeWSl4n3jmynzdW6Smwv9fsFScAPenJIcrwURTDiZVKb 7aDmzWXxoasR21yiBdhEsAQE2PIlKmLLjHKEkw3XJ9hUZab+DqyswgCyh3M5swFqkqyS XgLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=hlJX4+mn; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a17090301c900b0019abec982c2si4296637plh.77.2023.04.01.00.10.43; Sat, 01 Apr 2023 00:10:55 -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=@suse.com header.s=susede1 header.b=hlJX4+mn; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233527AbjDAGjH (ORCPT + 99 others); Sat, 1 Apr 2023 02:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbjDAGip (ORCPT ); Sat, 1 Apr 2023 02:38:45 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A468B20DB7 for ; Fri, 31 Mar 2023 23:38:23 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6510F1FD6D; Sat, 1 Apr 2023 06:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1680331095; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PLhZnRzaTF/w19VvaTwREzeMUwLtgou6VVO1Iy9aXOI=; b=hlJX4+mn92AjAhl6PYx0T3gUWvKaL2etfSkUjXhW4rfmimMPLmlIg0hjuaB7X7gZP/vVQ+ 0wYDXpajnNGpXf6sBmava6k/WHQ2InPTViQQljFPd1R7lLImrKDpprLUmY4nHw4wKvj18x Gi+mz7kqtLf55Tk2X+Cq4e90o84NV7U= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 10565134FB; Sat, 1 Apr 2023 06:38:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2ZmXAlfRJ2SQdwAAMHmgww (envelope-from ); Sat, 01 Apr 2023 06:38:15 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Linus Torvalds , Michael Kelley Subject: [PATCH v5 14/15] x86/mm: only check uniform after calling mtrr_type_lookup() Date: Sat, 1 Apr 2023 08:36:51 +0200 Message-Id: <20230401063652.23522-15-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230401063652.23522-1-jgross@suse.com> References: <20230401063652.23522-1-jgross@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761956914353488829?= X-GMAIL-MSGID: =?utf-8?q?1761956914353488829?= 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 to not 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. Suggested-by: Linus Torvalds Signed-off-by: Juergen Gross Tested-by: Michael Kelley --- V3: - adapt comment for pud_set_huge() --- 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 e4f499eb0f29..15a8009a4480 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;