From patchwork Thu Feb 9 07:22:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 54779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp188019wrn; Wed, 8 Feb 2023 23:28:34 -0800 (PST) X-Google-Smtp-Source: AK7set/NBgzcObozcmjTYdzOwKcu3LeudGwUd907yO0SLLdEGsx7duYDCal9yvjopHFxgry8fxD2 X-Received: by 2002:a05:6a20:3c8c:b0:bc:63d0:d9d9 with SMTP id b12-20020a056a203c8c00b000bc63d0d9d9mr12529596pzj.47.1675927713854; Wed, 08 Feb 2023 23:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675927713; cv=none; d=google.com; s=arc-20160816; b=n5wVtgihvtAvuLSQ0YvKowRtq/QbN0IZSKMxdjwllECXL4IB+VxOyFZOQomlleFmlD mRna8T0QH3+Aj3689U9GFJNUNSpn3TYzf1UYKuMWrc4h6LlSNoNcfrca89mK3o4IMGzW AeZ4Ncjp85gvy5vxEzhj2ZwNCH2XRi7PFXTDbpfQqSM4iJdp5AexmsT8GULTAg63UY68 pQ49TFdw28Q7NvAvdmtF+i7oaQvbrtDRxPVLcLMrCQERtZVT/0H4pLO/CBmkyCf0H8ft 15aFb1xaUkSH2Cx4RVw/75/lEYfLqB33nmv6UYI0C5+WpQqVzsr4BwW9XLw2CLrDhFNL jCIQ== 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=9mEOMWv35R/f7zhiS0ZyJfuk4uTp5/VuATvRXuKHpDE=; b=0TX8pQ9cMEr9sbJ5/6FfqpRaHL7i4GMmrh0HDh2GsEMfF3CgMujX3KaAZcPxt/nwwB MPo6p8TuB9p/sk9/+Ymc33McQd7FGSghAFfYN3LYLIoerieR/t3izz7aNugLAARraDh4 An6RFfbL5UHR8IK2GdhjvVhdhnaEZ26oWH1Q4Ka/F91IJIrz3NNjeb44LAARTfQGRxDf ghuWzM3s66U1p4mk87zc+x63Py4+F/RVs+bS2PmkQZo829tZeCS0s/o2FBjy9dfUY5EV 7aUmuugzuCNnR5La5IOlovswtjEyNHuVcxvdZ4HEy58lY2xavkyvqfOOVL1tbmVp4jn/ TG3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=YFgxsrgr; 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 19-20020a621813000000b005991e382017si1094560pfy.131.2023.02.08.23.28.21; Wed, 08 Feb 2023 23:28:33 -0800 (PST) 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=YFgxsrgr; 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 S230023AbjBIHXt (ORCPT + 99 others); Thu, 9 Feb 2023 02:23:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbjBIHXe (ORCPT ); Thu, 9 Feb 2023 02:23:34 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AB3049010 for ; Wed, 8 Feb 2023 23:23:13 -0800 (PST) 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 49A965C21F; Thu, 9 Feb 2023 07:23:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1675927389; 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=9mEOMWv35R/f7zhiS0ZyJfuk4uTp5/VuATvRXuKHpDE=; b=YFgxsrgrMz4OTZGEV5t5OQQp2iOYlVpEFNMiezmnGgZnwDiDSDSyf8RHaZOMax41g5Zcok yBS7FM0NkUE0dp0cGPu6gi3UCIZXgvJ5pzmt69/xbPQrdyb+ojPlogLUzXuxJ7Sxdb81tQ 92eLAn/u4svn9et+ALd6eMI3ZUo2Zbc= 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 F20C91339E; Thu, 9 Feb 2023 07:23:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sGnGOVyf5GMjeQAAMHmgww (envelope-from ); Thu, 09 Feb 2023 07:23:08 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: lists@nerdbynature.de, mikelley@microsoft.com, torvalds@linux-foundation.org, Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 8/8] x86/mtrr: drop sanity check in mtrr_type_lookup_fixed() Date: Thu, 9 Feb 2023 08:22:20 +0100 Message-Id: <20230209072220.6836-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230209072220.6836-1-jgross@suse.com> References: <20230209072220.6836-1-jgross@suse.com> MIME-Version: 1.0 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 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?1757337578764568728?= X-GMAIL-MSGID: =?utf-8?q?1757337578764568728?= mtrr_type_lookup_fixed() contains a sanity check for the case it is being called with a start address above 1 MB. As it is static and it is called only iff the start address is below 1MB, this sanity check can be dropped. 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. Signed-off-by: Juergen Gross --- arch/x86/include/uapi/asm/mtrr.h | 6 +++--- arch/x86/kernel/cpu/mtrr/generic.c | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/uapi/asm/mtrr.h b/arch/x86/include/uapi/asm/mtrr.h index 376563f2bac1..4aa05c2ffa78 100644 --- a/arch/x86/include/uapi/asm/mtrr.h +++ b/arch/x86/include/uapi/asm/mtrr.h @@ -115,9 +115,9 @@ struct mtrr_state_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 afb59ff2cc00..575b050a55bf 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -114,16 +114,12 @@ static int check_type_overlap(u8 *prev, u8 *curr) * 0xC0000 - 0xFFFFF : This range is divided into sixty-four 4KB sub-ranges * * Return Values: - * MTRR_TYPE_(type) - Matched memory type - * MTRR_TYPE_INVALID - Unmatched + * MTRR_TYPE_(type) - Memory type */ static u8 mtrr_type_lookup_fixed(u64 start, u64 end) { int idx; - if (start >= 0x100000) - return MTRR_TYPE_INVALID; - /* 0x0 - 0x7FFFF */ if (start < 0x80000) { idx = 0;