Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp608672rdb; Thu, 22 Feb 2024 13:40:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV6aR92UqqLhwWJR6yfTzhYUw8gZLVc0NqOtaR2PqcImnszBLR9wCSCY7GHFnkx/qJ4KmvnPYNoKDpVF7UhtmWVh11KZCL0/iOcapQKbA== X-Google-Smtp-Source: AGHT+IH0i5y1CMGv2euISmkQWW0IUBnrNlg3bzCQMvcQQcuyJ8C1EU2tjoAitQ+9GD1oKcfc4R0K X-Received: by 2002:a05:6a20:8603:b0:1a0:a098:5855 with SMTP id l3-20020a056a20860300b001a0a0985855mr104610pze.17.1708638034283; Thu, 22 Feb 2024 13:40:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708638034; cv=pass; d=google.com; s=arc-20160816; b=A9PvqRjIfbVy2d/hNab6zFnb87Ws/M1XS3ET7y42c38hnG6g/hYMDy8xyRqo5HQBJf 7yBRZt8EbPpyT++U7MXwPGTUySPgHZOLFloodhhT4ERVZ5o5oNCzmySL3z10C95SKCg4 gGmWiWca82rxmdWTjuJAWv+aIcLm/yjH1W2MZqyhN9RFfU0NT7HpUnlZWzzxm0QrtChr ZHtzHbwM/gQ4V003V1bEhsENyjVSF+FYMFkDTvT/Jn//OmHO711XYwwAoItIdauupDAD XQvQQPSoRxoe9eHgEw9qvBUzt6W+VXjBU97LEZwi0/cTC0nMg4JJHTyoOBXFJTj+BipB YoSg== 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=O8T88KUTsat+v60SwCJm+u5qeBncKT1mRDiD1St2Ld0=; fh=HUgOPOMLUPcroonsK10/uEWpbBCP57e0QFUoVmMwghQ=; b=OPd8dx1eG+fq2p8+GszaOanwVmrXD79mdVLNUPmBTfyE0+d32h36Oh2xj8wIDBb+mE 9rcfwNNIWyFGEv95ksHSOHOs1UOJmIti3b3dHQd5XaDkG/d2cs/0tbg9lzQmHPiTBPV5 eyL17mHU/njGVj2j6k9J0K0lGe7SHI3BZEv/0KR0mBJ8gfg+ZMc/LqhICO8ATDdB+ylf DxMPVeHMEfEJq0Xsg1OSKxz+eJTTAwGWLhYQ+uSJcBk2djZpkYlShmsOg0cHxUNxgdPO 77BlpBBCenwQ8V2sZqZ+97o+HQIfF6FHntXczsmWkg70Y3zyBWDMXX2tJvtgYililf6D uzlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IVvH0HT5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s14-20020a056a0008ce00b006e130b90d4csi11212254pfu.254.2024.02.22.13.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:40:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IVvH0HT5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-77173-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77173-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E9C8528B5F7 for ; Thu, 22 Feb 2024 18:47:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A84D149399; Thu, 22 Feb 2024 18:39:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IVvH0HT5" 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 A7360140372 for ; Thu, 22 Feb 2024 18:39:52 +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=1708627194; cv=none; b=JahPKSN0VZq3GpZCzOQODPzEt9ThSsKq7srtCh4mKh454t+Gi0UNxtT+GLJLHgSRMah2Bw8TABxoHM+Spga33KvCFtOoldDsv4N5xeXUpGwRXLwfuFITdsv+nejvo3/yVLihxw74LWMtRZspzal7qk+dBgy5Vv0udLln3tnsIk0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708627194; c=relaxed/simple; bh=lVSBkQ+5G44BZu5dX85c0yqtBnGNPsKMRwhEBPumIA8=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=cp4P7gzJj52hFDGOCF854WZcyxPfGmR0bxpWHi6kzQFKiFOiCBHACIMd5hwdUilJC6HoXowXuI36Pz1JhxvxbYq8Squ01OcZyM486rF6Lif4Z6eOzRFs48fWrk+c7lircczl6qaG3bUTmlHJz2n0omP1SiXbpPa+RWIGB5XxsYc= 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=IVvH0HT5; 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=1708627193; x=1740163193; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=lVSBkQ+5G44BZu5dX85c0yqtBnGNPsKMRwhEBPumIA8=; b=IVvH0HT5ijKUg7MA6/qPZlzP9TCpjvpT6AH0x7VLswbz9gGtWB8qbPrw JKjx9UYHoCPf0wc6UkSS/jiVnya/MQHw0Poyvr4HbNBzLrHoqgzM7eCDj AmyixkCd8Ye29FzblJ+v8VRAS8gSgOWcnuxo1VMQMriWYTRVvYOYxCmhh +2PmfwZtWfPg2fKU1SHDTHXJTZxWiWt+h6pz2u7crDOihVKc3JhpGh+La eq3kb9LBch2w1nBxHnaqzFAcEmPcQ2adoN3usJnzOdwtQUXxtEcTQ5Buz jkoNvtBGe0SBruu9JAsdy5j5/jJ2Z9c5MJ7b5UeJIdeHySNnYKCfVMqsE A==; X-IronPort-AV: E=McAfee;i="6600,9927,10992"; a="3031831" X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="3031831" 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:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="5975561" 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:52 -0800 Subject: [RFC][PATCH 19/34] x86/cpu: Introduce cache alignment multiplier 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:51 -0800 References: <20240222183926.517AFCD2@davehans-spike.ostc.intel.com> In-Reply-To: <20240222183926.517AFCD2@davehans-spike.ostc.intel.com> Message-Id: <20240222183951.6BCC4D89@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen The kernel currently tracks two different but similar-sounding values: x86_clflush_size and x86_cache_alignment x86_clflush_size is literally the size of the cacheline which is also the architectural granularity at which CLFLUSH operates. But some weirdo CPUs like the Pentium 4 do some operations across two cachelines. Their CLFLUSH still works at 'x86_clflush_size' but they need some operations aligned to that double cacheline to work well, thus 'x86_cache_alignment'. Introduce and use a 'bsp_addr_config' field for these systems. Note that the Intel Family 15 code actually did this in two different sites, one for 32-bit and one for 64-bit. Unify them. Signed-off-by: Dave Hansen --- b/arch/x86/include/asm/processor.h | 7 +++++++ b/arch/x86/kernel/cpu/centaur.c | 2 +- b/arch/x86/kernel/cpu/common.c | 3 +++ b/arch/x86/kernel/cpu/intel.c | 10 ++++------ 4 files changed, 15 insertions(+), 7 deletions(-) diff -puN arch/x86/include/asm/processor.h~x86_cache_alignment_mult arch/x86/include/asm/processor.h --- a/arch/x86/include/asm/processor.h~x86_cache_alignment_mult 2024-02-22 10:08:57.732817356 -0800 +++ b/arch/x86/include/asm/processor.h 2024-02-22 10:08:57.740817669 -0800 @@ -172,6 +172,13 @@ struct x86_addr_config { * platforms that use memory encryption. */ u8 phys_addr_reduction_bits; + + /* + * "x86_clflush_size" is the size of an actual cacheline. + * Allow systems to specify a multiplier where alignment + * will take place at a more coarse granularity. + */ + u8 cache_align_mult; }; /* diff -puN arch/x86/kernel/cpu/centaur.c~x86_cache_alignment_mult arch/x86/kernel/cpu/centaur.c --- a/arch/x86/kernel/cpu/centaur.c~x86_cache_alignment_mult 2024-02-22 10:08:57.732817356 -0800 +++ b/arch/x86/kernel/cpu/centaur.c 2024-02-22 10:08:57.740817669 -0800 @@ -216,7 +216,7 @@ static void init_centaur(struct cpuinfo_ static void bsp_init_centaur(struct cpuinfo_x86 *c) { if (c->x86 == 0x6 && c->x86_model >= 0xf) - c->x86_cache_alignment = x86_clflush_size() * 2; + bsp_addr_config.cache_align_mult = 2; } #ifdef CONFIG_X86_32 diff -puN arch/x86/kernel/cpu/common.c~x86_cache_alignment_mult arch/x86/kernel/cpu/common.c --- a/arch/x86/kernel/cpu/common.c~x86_cache_alignment_mult 2024-02-22 10:08:57.736817513 -0800 +++ b/arch/x86/kernel/cpu/common.c 2024-02-22 10:08:57.740817669 -0800 @@ -1124,7 +1124,10 @@ void get_cpu_address_sizes(struct cpuinf } } c->x86_cache_bits = x86_config.phys_bits; + c->x86_cache_alignment = x86_clflush_size(); + if (bsp_addr_config.cache_align_mult) + c->x86_cache_alignment *= bsp_addr_config.cache_align_mult; /* Do this last to avoid affecting ->x86_cache_bits. */ x86_config.phys_bits -= bsp_addr_config.phys_addr_reduction_bits; diff -puN arch/x86/kernel/cpu/intel.c~x86_cache_alignment_mult arch/x86/kernel/cpu/intel.c --- a/arch/x86/kernel/cpu/intel.c~x86_cache_alignment_mult 2024-02-22 10:08:57.736817513 -0800 +++ b/arch/x86/kernel/cpu/intel.c 2024-02-22 10:08:57.740817669 -0800 @@ -236,10 +236,6 @@ static void early_init_intel(struct cpui #ifdef CONFIG_X86_64 set_cpu_cap(c, X86_FEATURE_SYSENTER32); -#else - /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */ - if (c->x86 == 15 && c->x86_cache_alignment == 64) - c->x86_cache_alignment = 128; #endif /* @@ -418,6 +414,10 @@ static void bsp_init_intel(struct cpuinf WARN_ON_ONCE(keyid_bits); bsp_addr_config.phys_addr_reduction_bits = 4; } + + /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */ + if (c->x86 == 15) + bsp_addr_config.cache_align_mult = 2; } #ifdef CONFIG_X86_32 @@ -659,8 +659,6 @@ static void init_intel(struct cpuinfo_x8 set_cpu_bug(c, X86_BUG_MONITOR); #ifdef CONFIG_X86_64 - if (c->x86 == 15) - c->x86_cache_alignment = x86_clflush_size() * 2; if (c->x86 == 6) set_cpu_cap(c, X86_FEATURE_REP_GOOD); #else _