From patchwork Thu Feb 22 18:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 205031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp176893dyb; Thu, 22 Feb 2024 12:00:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVLtn2Wj+M+MmWTUixxP4SpbICzOCpOQbjyrK3x+3mgvRg098VfIUQeeu4Ejoh47eav6fme980ullZtlJrFBIlh70hTHA== X-Google-Smtp-Source: AGHT+IF7XK++ilqCbbnD7GO5aTXMOitDE/bsWc6nOFvApDpQii5uMwdxZ89wMhKMZUc8B0/02OjY X-Received: by 2002:a05:6902:510:b0:dc6:4b5a:410a with SMTP id x16-20020a056902051000b00dc64b5a410amr183679ybs.12.1708632033830; Thu, 22 Feb 2024 12:00:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708632033; cv=pass; d=google.com; s=arc-20160816; b=LlLV0SdMwRnh9XuHxM28/X/Ezs5pNNmd5e/SMjQCLwEZKO97pyeLr263JAWbWeVOMn mAHEnEcJNOKwJPWcZbB1mdHbBfhlnpBpshxTKjbm0/c0nI1KeaJM0P1fDokGuP9vsonB i4l2ibwGNGHcja0NNlURusxc3id2qsKktE61n0GgincI2D7O4AXbJqgAd3jgSO7eI1al h0flAhYPiVs/49eMM4A6ensH/jIFiT7bprIrGamqp6Tr/J9B6KjJBnNGxl7PK/hW9X76 JkkGQA+4dSb1LzkKnbQdOLFbk4cwFL+7tD/4eKLvf2ehn5LDi+YqBSsY1171BgmD/9c+ orNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id :in-reply-to:references:date:from:cc:to:subject:dkim-signature; bh=foGMvudsd7WfiIpJQAJrh6w+6rc64QUxHF01rh6aHec=; fh=HUgOPOMLUPcroonsK10/uEWpbBCP57e0QFUoVmMwghQ=; b=eSMVNHAeXzN15qkFIn/FFV4QYGdnqjxmnUtDlfy1P4cU6FinuNqXMBlMRwtjzpDou/ GM8H2zw29JxF1rY2FuZon60y2kvsE6lsqdFhWElmLW6JJvDW8Uzsyvnmxir5A7+/PALC 7KRyhDh9HOes6tvCkkmedUp7SHE60W7ZlUHY97cnMh5k+QOgdR1hbBUkl6pBHZMqbfZt UmPLkHOSgAmy95vCf5uYtUZUQWKhoyD3ipjlmkbMys7klVnAuAZpUFlmcp0vwLMorSka cfAAF2FJQEk+yvY/tXtHK4YVHfOHJYPpO6oa9hK9jO0unPpkRknfv+K+UNVYH23hdb5I A67Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ke59vf46; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77161-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77161-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j9-20020a05620a410900b0078794823c3fsi2930009qko.239.2024.02.22.12.00.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 12:00:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77161-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ke59vf46; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77161-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77161-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 32F031C254F9 for ; Thu, 22 Feb 2024 18:44:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E12BB73F07; Thu, 22 Feb 2024 18:39:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ke59vf46" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60E606E602 for ; Thu, 22 Feb 2024 18:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708627177; cv=none; b=ASX0WDKAg7yNFTAknFuPZKoIRCPUWLU5fBqOqwQZksOaUMpxMnZBfLTnJ4rPjNAusZeUoasFMOmQqTkuRztMabXHo54mP9lA+kQONXLMV4WF/jPorsshArlTsW8qcgqiYfBhFRtWlWd3kq+VInPwuGcebH+ajCQFMhKoXmOD1zA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708627177; c=relaxed/simple; bh=rsFsu/cEO8uggTXoV412vUNfouqZDj34S3bAyQtscUc=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=jTY/9Or5H0HIYybA9OVQz6cdlvq0x0pZESwjEln83xSNwc3Pa1drn7PAyKMdfgd9KKfgj2qUP7Fef03RsooZUjqd/bBi2z/GXaBhd/MdvVYlJC2E67OidUsj1EaENaGmXhLvFOpvRizKXkkyFMhgXGZwvG4ZbJzpDZIAJ9DQQlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ke59vf46; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708627177; x=1740163177; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=rsFsu/cEO8uggTXoV412vUNfouqZDj34S3bAyQtscUc=; b=Ke59vf46hCB8/Y38lI5g097MW0ExmetfvzN+yayXeJDw+ExuaFCmtA+a 2CVic5l2rgqi1jjqEpQ/UXsJ1/QjDs9zMmpmLugFbPBoGLm6iMOoCUuGx QNIdhD40uLuHiNutswp4JRz4xdxYDn8I2vEnEteiAMao1Z3cMx+dS+myA qLzter1YHNvOMtPNNTPEKZgDedbv5rU1G1FMAiLXGA8VBI0Xoq0pMMw+F cEbdByQdPgzNC2242FqU6lDPG9LxGWiDnoN0h1VoT3C5n5EltrjfufeeZ lmEquCaAQQq63ar959dzgeu2dwr/H1HePyFWhv9QdQgJ91GK2Va93KqHr A==; X-IronPort-AV: E=McAfee;i="6600,9927,10992"; a="3031733" X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="3031733" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 10:39:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="5975440" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by orviesa008.jf.intel.com with ESMTP; 22 Feb 2024 10:39:36 -0800 Subject: [RFC][PATCH 07/34] x86/mm: Introduce virtual address space limit helper To: linux-kernel@vger.kernel.org Cc: kirill.shutemov@linux.intel.com,pbonzini@redhat.com,tglx@linutronix.de,x86@kernel.org,bp@alien8.de,Dave Hansen From: Dave Hansen Date: Thu, 22 Feb 2024 10:39:35 -0800 References: <20240222183926.517AFCD2@davehans-spike.ostc.intel.com> In-Reply-To: <20240222183926.517AFCD2@davehans-spike.ostc.intel.com> Message-Id: <20240222183935.286751FF@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791630543920368119 X-GMAIL-MSGID: 1791630543920368119 From: Dave Hansen This uses the same logic and approach which were used for the physical address limits with x86_phys_bits() and extends them to the virtual address space. Introduce a system-wide helper for users to query the size of the virtual address space: x86_virt_bits() Signed-off-by: Dave Hansen Reviewed-by: Kai Huang --- b/arch/x86/events/amd/brs.c | 2 +- b/arch/x86/events/amd/lbr.c | 2 +- b/arch/x86/events/intel/pt.c | 4 ++-- b/arch/x86/include/asm/processor.h | 5 +++++ b/arch/x86/kernel/cpu/proc.c | 2 +- b/arch/x86/mm/maccess.c | 4 ++-- 6 files changed, 12 insertions(+), 7 deletions(-) diff -puN arch/x86/events/amd/brs.c~x86_virt_bits-func arch/x86/events/amd/brs.c --- a/arch/x86/events/amd/brs.c~x86_virt_bits-func 2024-02-22 10:08:51.528573793 -0800 +++ b/arch/x86/events/amd/brs.c 2024-02-22 10:08:51.536574107 -0800 @@ -285,7 +285,7 @@ void amd_brs_drain(void) struct perf_branch_entry *br = cpuc->lbr_entries; union amd_debug_extn_cfg cfg; u32 i, nr = 0, num, tos, start; - u32 shift = 64 - boot_cpu_data.x86_virt_bits; + u32 shift = 64 - x86_virt_bits(); /* * BRS event forced on PMC0, diff -puN arch/x86/events/amd/lbr.c~x86_virt_bits-func arch/x86/events/amd/lbr.c --- a/arch/x86/events/amd/lbr.c~x86_virt_bits-func 2024-02-22 10:08:51.528573793 -0800 +++ b/arch/x86/events/amd/lbr.c 2024-02-22 10:08:51.536574107 -0800 @@ -89,7 +89,7 @@ static __always_inline u64 amd_pmu_lbr_g static __always_inline u64 sign_ext_branch_ip(u64 ip) { - u32 shift = 64 - boot_cpu_data.x86_virt_bits; + u32 shift = 64 - x86_virt_bits(); return (u64)(((s64)ip << shift) >> shift); } diff -puN arch/x86/events/intel/pt.c~x86_virt_bits-func arch/x86/events/intel/pt.c --- a/arch/x86/events/intel/pt.c~x86_virt_bits-func 2024-02-22 10:08:51.528573793 -0800 +++ b/arch/x86/events/intel/pt.c 2024-02-22 10:08:51.536574107 -0800 @@ -1453,8 +1453,8 @@ static void pt_event_addr_filters_sync(s * canonical addresses does not affect the result of the * address filter. */ - msr_a = clamp_to_ge_canonical_addr(a, boot_cpu_data.x86_virt_bits); - msr_b = clamp_to_le_canonical_addr(b, boot_cpu_data.x86_virt_bits); + msr_a = clamp_to_ge_canonical_addr(a, x86_virt_bits()); + msr_b = clamp_to_le_canonical_addr(b, x86_virt_bits()); if (msr_b < msr_a) msr_a = msr_b = 0; } diff -puN arch/x86/include/asm/processor.h~x86_virt_bits-func arch/x86/include/asm/processor.h --- a/arch/x86/include/asm/processor.h~x86_virt_bits-func 2024-02-22 10:08:51.532573950 -0800 +++ b/arch/x86/include/asm/processor.h 2024-02-22 10:08:51.536574107 -0800 @@ -772,4 +772,9 @@ static inline u8 x86_phys_bits(void) return boot_cpu_data.x86_phys_bits; } +static inline u8 x86_virt_bits(void) +{ + return boot_cpu_data.x86_virt_bits; +} + #endif /* _ASM_X86_PROCESSOR_H */ diff -puN arch/x86/kernel/cpu/proc.c~x86_virt_bits-func arch/x86/kernel/cpu/proc.c --- a/arch/x86/kernel/cpu/proc.c~x86_virt_bits-func 2024-02-22 10:08:51.532573950 -0800 +++ b/arch/x86/kernel/cpu/proc.c 2024-02-22 10:08:51.536574107 -0800 @@ -133,7 +133,7 @@ static int show_cpuinfo(struct seq_file seq_printf(m, "clflush size\t: %u\n", c->x86_clflush_size); seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment); seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n", - x86_phys_bits(), c->x86_virt_bits); + x86_phys_bits(), x86_virt_bits()); seq_puts(m, "power management:"); for (i = 0; i < 32; i++) { diff -puN arch/x86/mm/maccess.c~x86_virt_bits-func arch/x86/mm/maccess.c --- a/arch/x86/mm/maccess.c~x86_virt_bits-func 2024-02-22 10:08:51.536574107 -0800 +++ b/arch/x86/mm/maccess.c 2024-02-22 10:08:51.536574107 -0800 @@ -20,10 +20,10 @@ bool copy_from_kernel_nofault_allowed(co * is initialized. Needed for instruction decoding in early * exception handlers. */ - if (!boot_cpu_data.x86_virt_bits) + if (!x86_virt_bits()) return true; - return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits); + return __is_canonical_address(vaddr, x86_virt_bits()); } #else bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)