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: 103296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2723503vqr; Mon, 5 Jun 2023 07:25:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZVD2oJSuQ6F5QbQjKY2caLSLLxVDopvSo58j1AWpC6Nem46AFycNhEW4Aenb3Tqx1UoBN X-Received: by 2002:a05:6a00:f96:b0:656:c971:951 with SMTP id ct22-20020a056a000f9600b00656c9710951mr5742961pfb.8.1685975124196; Mon, 05 Jun 2023 07:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685975124; cv=none; d=google.com; s=arc-20160816; b=s/jO6d9vfbDsu0Fdtjn7zcYjYLmIt08EqjQjUooJND1KChyIcdhL7rhlkWAftQIA7n HpHGaahP0+6jJsM5Irn0+z3c4C45SY1/c7HFlnGX3Yj0VwvIredoOcMpzJy13oBx7NNm K1+Go2lEKyXnvTBuP9bT2Wcxcm4jYyBHpEvdde4NTJrfr1qq1KGQ7Ek/3vOTdxQg12di as1awoXJADu3T54T6UwvbQfIywDXl4MT0n2qtytGzJxUlx154cmYQeQAa6gFSekPgC8y q2S8no8ycu9wGsm4eC9hknHoEM0tn/5q/vd7PdfYOW0IALTfC9aZfdtEgT+UzYuztFkS Jzaw== 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=2cC+ObGB+xSsfPslky5orlr06ncXedkCX7VtpUcsTbU=; b=eYnRwte/kao2hNN85SLIwjnOa16FrvZmksw9YBARJTugnfEYwTrkRBm1FKQRFtjmEK G0bxWYyvPaRAKtHEoIzN/JJwTdC9rvZh67XAcCcwrVzcfcYIV5mq5yZtCzfEn2b7hKZX C1nPfHUxrStZdMLu6kv35rdLnbFh9Md+Ws30Kgz19XUaagkVGfGnExwvD+zaq59uD5yW xVdyVRqqJ0Uggrig6t0BhsQvxkkaJs9UzSmWqsbrZpFVMEH/PFVfP5jCkyIsQb/d+MK3 lDZjA1r5Vx+9QESwndN9rD5DTGjOXoWml3OAXipIBiALi3wGgm9YWQwleAMwmWq+K+P+ fNVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="B2anWDs/"; 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 h184-20020a6383c1000000b00543b16f71c6si1725240pge.730.2023.06.05.07.25.09; Mon, 05 Jun 2023 07:25:24 -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="B2anWDs/"; 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 S234442AbjFEOJA (ORCPT + 99 others); Mon, 5 Jun 2023 10:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234320AbjFEOId (ORCPT ); Mon, 5 Jun 2023 10:08:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B28F810DD; 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=1685974094; 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=2cC+ObGB+xSsfPslky5orlr06ncXedkCX7VtpUcsTbU=; b=B2anWDs/k+wP7kZJEz1wf1t6dzh9lKq9C8ZsL3Df/ouPII7JuSDn+8Ws+EWHJoyKZMW3SD J5avIBtia+oRHWCvs4mtlIbMv5jMLEp3bJpNwGQ6MgluGWIDNxtHXxRz0tnV0ksdZ2ncxi NIPLhrNbSdDAXWOlKtcBGmFR3eir+0EDlrS2VcXwD6ybuXpTlM1HuyuPEN0LLN6CdZmmDZ xWaTYNHFYDY8Jm1g9U/YUgaRK0nQFUGvgnW1scfsJaF9TobW6ev8b01VCgBJBS5gQmiGIF IK3Fg+ZpHepGfvFwNDueIrbOAxtgJYrJqXsqedK3WX682c19dYgmEMAHpJl22Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685974094; 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=2cC+ObGB+xSsfPslky5orlr06ncXedkCX7VtpUcsTbU=; b=v+HwJhGtv0G1mnSJg6sGeHY2eEpDR9E7v6a7yo3AsuFTgKaU2Rq6fu786x0wrpgtGjZ2pN CKM4faTksxvQqRCw== 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/mtrr: Don't let mtrr_type_lookup() return MTRR_TYPE_INVALID Cc: Linus Torvalds , Juergen Gross , "Borislav Petkov (AMD)" , Michael Kelley , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230502120931.20719-15-jgross@suse.com> References: <20230502120931.20719-15-jgross@suse.com> MIME-Version: 1.0 Message-ID: <168597409373.404.18390017504973748078.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?1767873051794639025?= X-GMAIL-MSGID: =?utf-8?q?1767873051794639025?= The following commit has been merged into the x86/mtrr branch of tip: Commit-ID: 973df1942068c0cc72244ce7dce5e5aeca03ad5f Gitweb: https://git.kernel.org/tip/973df1942068c0cc72244ce7dce5e5aeca03ad5f Author: Juergen Gross AuthorDate: Tue, 02 May 2023 14:09:29 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 01 Jun 2023 15:04:33 +02:00 x86/mtrr: Don't let mtrr_type_lookup() return MTRR_TYPE_INVALID mtrr_type_lookup() should always return a valid memory type. In case there is no information available, it should return the default UC. This will remove the last case where mtrr_type_lookup() can return MTRR_TYPE_INVALID, so adjust the comment in include/uapi/asm/mtrr.h. Note that removing the MTRR_TYPE_INVALID #define from that header could break user code, so it has to stay. At the same time the mtrr_type_lookup() stub for the !CONFIG_MTRR case should set uniform to 1, as if the memory range would be covered by no MTRR at all. 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-15-jgross@suse.com Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/mtrr.h | 7 +++++-- arch/x86/include/uapi/asm/mtrr.h | 6 +++--- arch/x86/kernel/cpu/mtrr/generic.c | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h index 1bae790..5a758ee 100644 --- a/arch/x86/include/asm/mtrr.h +++ b/arch/x86/include/asm/mtrr.h @@ -86,9 +86,12 @@ static inline void mtrr_overwrite_state(struct mtrr_var_range *var, static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform) { /* - * Return no-MTRRs: + * Return the default MTRR type, without any known other types in + * that range. */ - return MTRR_TYPE_INVALID; + *uniform = 1; + + return MTRR_TYPE_UNCACHABLE; } #define mtrr_save_fixed_ranges(arg) do {} while (0) #define mtrr_save_state() do {} while (0) diff --git a/arch/x86/include/uapi/asm/mtrr.h b/arch/x86/include/uapi/asm/mtrr.h index ab194c8..3a8a8eb 100644 --- a/arch/x86/include/uapi/asm/mtrr.h +++ b/arch/x86/include/uapi/asm/mtrr.h @@ -107,9 +107,9 @@ typedef __u8 mtrr_type; #define MTRR_NUM_TYPES 7 /* - * Invalid MTRR memory type. mtrr_type_lookup() returns this value when - * MTRRs are disabled. Note, this value is allocated from the reserved - * values (0x7-0xff) of the MTRR memory types. + * Invalid MTRR memory type. No longer used outside of MTRR code. + * Note, this value is allocated from the reserved values (0x7-0xff) of + * the MTRR memory types. */ #define MTRR_TYPE_INVALID 0xff diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c index 4443e71..f6b426d 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -508,13 +508,13 @@ u8 mtrr_type_lookup(u64 start, u64 end, u8 *uniform) if (!mtrr_state_set) { /* Uniformity is unknown. */ *uniform = 0; - return MTRR_TYPE_INVALID; + return MTRR_TYPE_UNCACHABLE; } *uniform = 1; if (!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED)) - return MTRR_TYPE_INVALID; + return MTRR_TYPE_UNCACHABLE; for (i = 0; i < cache_map_n && start < end; i++) { /* Region after current map entry? -> continue with next one. */