From patchwork Mon Oct 2 22:00:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 147505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1715870vqb; Mon, 2 Oct 2023 15:04:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxhAVcTguu5m6LhpRPOsQ12H7iO/mDJEAxzIfnEhZjg/JoFoEKN4Acvdda9BUHNJotxkMD X-Received: by 2002:a05:6e02:f91:b0:348:e9e4:4902 with SMTP id v17-20020a056e020f9100b00348e9e44902mr12129260ilo.0.1696284257715; Mon, 02 Oct 2023 15:04:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696284257; cv=none; d=google.com; s=arc-20160816; b=QA8g35MiPVvzZKtxhBhz5HVFkya330nKJnuXjoatridjNQik0neYkVGzLQoS2eVH1K bFo35poyErAZ39KVCjCJmaB7hVz9BFSh57+X0CbYO9Ax8OE5sV1q0hy1Qe4NCaCiw3Jx 4HCnsUZphrTaD2Dod+NUeXcehJD/31U+qx+XmU9LWkQ7QG0s9Ojh2D+ONkkY+nBpZG0G GLXvXzVtb6O/VuSNSpGuACV6rqcqqK+O4TFMGvfbjrMnpGwC0E8goHegL68CFzpvnu4s LkCRdefclIBEH04CyuouhxjdzyFxs8kpLm6ATZ4LakDTzT1wsoTcBPEhGMW04uXCyTDb vSHw== 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=16PrGyn3bbq+ogiQMF15Q3zKbw65miM+aKyPGWpkTNc=; fh=xyrST9uoOGIH6DfjtPSZrQG9CjuT/MH54F5sxjohGTg=; b=t2HYuAb/eT7Wk5mUYO/mSAe2aAD+ttghWR5KdQl1KqDKv520bSuNkD8mEQcpUtEP5m akz1HIc76NiJ/XyC1jz2g7WmL9wwJhFHeGLc0c5kM1LJUYoHGXih7YC5eCcTMt17iE+h b+9sJHR5FRayxz1drUz8MjCYRvz1UUKMF7AylQ+K6JVxpgRolvD8VWP4oy1qhPuq3Txg HnwjKg6whAulnZNrpkzN1LqvClYlYtEJzWgIRamN0nEja4ylqGzX2sdJr1hGGCWPiRXU rGQBR43S0YbpiFjDtffd090Dbpj+LqmT8/oDy6DVTncZpU74lA0tgCGDvJtdw2agbIAk UvEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VSTu3bFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l12-20020a63da4c000000b00565f0e91894si27482162pgj.394.2023.10.02.15.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:04:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VSTu3bFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id AFDB18033346; Mon, 2 Oct 2023 15:04:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbjJBWA6 (ORCPT + 18 others); Mon, 2 Oct 2023 18:00:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjJBWA5 (ORCPT ); Mon, 2 Oct 2023 18:00:57 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0865CB0 for ; Mon, 2 Oct 2023 15:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696284053; x=1727820053; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H2+S0sBELZz8cu4/nPPlTew2jxCEXoyQGzddLHftHbA=; b=VSTu3bFtvThwQEMEZbdEcepUrsKt41Yi91nQxrXKQ7Hwns5aVUBk+yam lQdEGMf5vmoZ/AQ3ySviPlKLVHyYWF0WcaIBEsDIImyliUrDwMvzvSBjj tzau6g/jGdovQFAwCWfDMQYRA8GtvkGFpMLmdxrOGHycW+AuCjTK2wNmH NHHmyMsy2SxpRbhrqHC32Sqa64KuhdjTmIqkOa697o1AEVzZElsFgP+xU 6B54zgtoRm2PVLYWEyi150vnOdefkQUxgh/mMfiWlZ0BDF/93U1XnOkfG Gh3A1amFmfOIbEYqpT8ri6jn66X9P6v9flHmefiVo5+nQP94ks9aGR1KM g==; X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="4312859" X-IronPort-AV: E=Sophos;i="6.03,194,1694761200"; d="scan'208";a="4312859" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 15:00:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="821011423" X-IronPort-AV: E=Sophos;i="6.03,194,1694761200"; d="scan'208";a="821011423" Received: from viggo.jf.intel.com (HELO ray2.intel.com) ([10.54.77.144]) by fmsmga004.fm.intel.com with ESMTP; 02 Oct 2023 15:00:50 -0700 From: Dave Hansen To: linux-kernel@vger.kernel.org, nathan@kernel.org Cc: x86@kernel.org, acdunlap@google.com, ashok.raj@intel.com, bp@alien8.de, dave.hansen@linux.intel.com, david@redhat.com, dionnaglaze@google.com, hpa@zytor.com, jacobhxu@google.com, jgross@suse.com, jroedel@suse.de, khalid.elmously@canonical.com, kim.phillips@amd.com, kirill.shutemov@linux.intel.com, llvm@lists.linux.dev, luto@kernel.org, mingo@redhat.com, nikunj@amd.com, peterz@infradead.org, pgonda@google.com, rientjes@google.com, rppt@kernel.org, seanjc@google.com, tglx@linutronix.de, thomas.lendacky@amd.com, Ingo Molnar Subject: [PATCH] x86/boot: Move x86_cache_alignment initialization to correct spot Date: Mon, 2 Oct 2023 15:00:45 -0700 Message-Id: <20231002220045.1014760-1-dave.hansen@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231002200426.GA4127272@dev-arch.thelio-3990X> References: <20231002200426.GA4127272@dev-arch.thelio-3990X> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 15:04:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778682961505061849 X-GMAIL-MSGID: 1778682961505061849 c->x86_cache_alignment is initialized from c->x86_clflush_size. However, commit fbf6449f84bf moved c->x86_clflush_size initialization to later in boot without moving the c->x86_cache_alignment assignment. This presumably left c->x86_cache_alignment set to zero for longer than it should be. The result was an oops on 32-bit kernels while accessing a pointer at 0x20. The 0x20 came from accessing a structure member at offset 0x10 (buffer->cpumask) from a ZERO_SIZE_PTR=0x10. kmalloc() can evidently return ZERO_SIZE_PTR when it's given 0 as its alignment requirement. Move the c->x86_cache_alignment initialization to be after c->x86_clflush_size has an actual value. Fixes: fbf6449f84bf ("x86/sev-es: Set x86_virt_bits to the correct value straight away, instead of a two-phase approach") Cc: Adam Dunlap Cc: Ingo Molnar Cc: Jacob Xu Link: https://lore.kernel.org/all/20231002200426.GA4127272@dev-arch.thelio-3990X/ Tested-by: Nathan Chancellor --- arch/x86/kernel/cpu/common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8d7063e4f63c9..9c51ad5bbf319 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1141,6 +1141,7 @@ void get_cpu_address_sizes(struct cpuinfo_x86 *c) } } c->x86_cache_bits = c->x86_phys_bits; + c->x86_cache_alignment = c->x86_clflush_size; } static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c) @@ -1594,8 +1595,6 @@ static void __init cpu_parse_early_param(void) */ static void __init early_identify_cpu(struct cpuinfo_x86 *c) { - c->x86_cache_alignment = c->x86_clflush_size; - memset(&c->x86_capability, 0, sizeof(c->x86_capability)); c->extended_cpuid_level = 0;