From patchwork Fri Dec 16 11:59:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1716487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Xau4JfzO; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYSNg21jbz23ym for ; Fri, 16 Dec 2022 23:00:51 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NYSNg0qGPz3bh2 for ; Fri, 16 Dec 2022 23:00:51 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Xau4JfzO; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::429; helo=mail-pf1-x429.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Xau4JfzO; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NYSMM6gCcz3bV1 for ; Fri, 16 Dec 2022 22:59:43 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id c13so1625624pfp.5 for ; Fri, 16 Dec 2022 03:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RkK8Pzds8OKBNuAjNuAFouO9VU2uQ92WQMSt5dA+bX8=; b=Xau4JfzOXLH/qpYXd83cOlucScIkfAGiAsElBDfFWtUK1hdDF5ENOBF7FyvzgIsHxV 3B5zyqi30S23R+t9AmX5ZHXFPTNiIA649b7zs31WuPe66XuiZg5WY10bgH4cvIxNnTCe 8t9jGmf/eKWIRBtQU35we8r4GpoLL9ZypxJqPStw4SmbQArh/mRe+/CxXR9q36chgiGY 3FhbxoOwbxTQa4GtSoPk2dj2i11oMD8qkeQdRldRWTwOhaWLSVQKOl4ZpZKNvQfO1V9F DjoilcHP1UMBwqn2xy4ItQ7IA2DoUe5sjyf5BT4xi82uqK2LvcMBA3ZJibmZ01B6UkjZ 1VcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RkK8Pzds8OKBNuAjNuAFouO9VU2uQ92WQMSt5dA+bX8=; b=afiOpdoOdMHucACDmYJSnPmw6ZrnT3MAG9/ossfW5cHRi15OCTWuNQ9SIWdoLaThTI eYlTMSJNSjf3ak1MdIv/bGVoC3pA87HEZazgZIZeFOFasz0UTZuypPWHOm9GOyG5xEPj 5S4ada+59jxt9oQ/CvjOqMVOMaSgbpo++89jnR8XE6xpmc9M5DRJtw98Wfddyvn6RTz/ SokTmGDMYMBgr20yerCER3U0aFXkQ90exrsyVcHKsD3M+059C4R+xYeo9gkU0EfCPOSd TgkHQ/vSvYslDHmqUClMLxzCiTuHZxdWcjaFL3Ne6jtQRxY7cAJHqu4adXW/gsgitRo/ wCFw== X-Gm-Message-State: ANoB5pnduuwfUZ5zRNIJZUovtRiNmW8tzPL/FFHuyP592z1uEzfjT7UM ttuLgymSU8up1yAQa4fGNSZmjA6nxB/71Q== X-Google-Smtp-Source: AA0mqf5VTPwRwijvxJ6ngo6MZWHmC/Z6CjFq6zKO69fkstHUS/HZKnRBWJXYUECXiKL7bw6khOw39A== X-Received: by 2002:a05:6a00:795:b0:576:cc71:b8ed with SMTP id g21-20020a056a00079500b00576cc71b8edmr27886965pfu.34.1671191979361; Fri, 16 Dec 2022 03:59:39 -0800 (PST) Received: from bobo.ozlabs.ibm.com (115-64-236-36.tpgi.com.au. [115.64.236.36]) by smtp.gmail.com with ESMTPSA id g22-20020a625216000000b0057ef155103asm1289438pfb.155.2022.12.16.03.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 03:59:38 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/4] powerpc/64s: Fix stress_hpt memblock alloc alignment Date: Fri, 16 Dec 2022 21:59:27 +1000 Message-Id: <20221216115930.2667772-2-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221216115930.2667772-1-npiggin@gmail.com> References: <20221216115930.2667772-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The stress_hpt memblock allocation did not pass in an alignment, which causes a stack dump in early boot (that I missed, oops). Fixes: 6b34a099faa1 ("powerpc/64s/hash: add stress_hpt kernel boot option to increase hash faults") Signed-off-by: Nicholas Piggin --- arch/powerpc/mm/book3s64/hash_utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 80a148c57de8..fa1c148e1f50 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -1051,7 +1051,8 @@ static void __init htab_initialize(void) static_branch_enable(&stress_hpt_key); // Too early to use nr_cpu_ids, so use NR_CPUS tmp = memblock_phys_alloc_range(sizeof(struct stress_hpt_struct) * NR_CPUS, - 0, 0, MEMBLOCK_ALLOC_ANYWHERE); + __alignof__(struct stress_hpt_struct), + 0, MEMBLOCK_ALLOC_ANYWHERE); memset((void *)tmp, 0xff, sizeof(struct stress_hpt_struct) * NR_CPUS); stress_hpt_struct = __va(tmp); From patchwork Fri Dec 16 11:59:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1716488 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=n7vu6EOm; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYSPm1LKCz23ym for ; Fri, 16 Dec 2022 23:01:47 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NYSPg2cMqz3bfk for ; Fri, 16 Dec 2022 23:01:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=n7vu6EOm; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::529; helo=mail-pg1-x529.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=n7vu6EOm; dkim-atps=neutral Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NYSMN0qsRz3bVy for ; Fri, 16 Dec 2022 22:59:43 +1100 (AEDT) Received: by mail-pg1-x529.google.com with SMTP id 62so1577900pgb.13 for ; Fri, 16 Dec 2022 03:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P6GZ5wjoHKgPVnn522+72lxNpKkugmzeDUcZHpY4Rm0=; b=n7vu6EOmesgwTC6sebdlEqOPCAq3KNmT5ZQvvtUlFDy0hu6J3HNunwD+4KpGgsDsUI bH+LOQqxGVvqBMRcbRzh6B6QUvD3fhLFb2Eu8P1MUdSE1Z5FOFxLaDIwsRfu3MGjzK4E aOiVpiPKIPtoIvf3bYtpgsF9dn8MNFu1m5+bnsjVUjphph1qTIIz+jN5NrnxmVK+kHec CHMsBlxQyfKp7Ziq33Zno+r/Fa14cHD7V3Pech9/Mbsfmrllz1CQjFWKrDsesdwZOSVq aZ2IDG++0zoSCGPAnypXa6wWWs2dVoLPkP2cN5wZ6y7ixJY8aL1NMj3vvkcT1+9C7asb uxaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P6GZ5wjoHKgPVnn522+72lxNpKkugmzeDUcZHpY4Rm0=; b=UPfN6llc9YsNs2tqsnXV5N4gjCftJegUjcdGpjQ/M27TcuJl83DDimKJpWvhBHNyCn /cpUFyeSQIrpIm0Bv5/Khg1LCzb9Sx5+rorf1w+k8q92t2+5dbBan6E6woaFNmQDtXDe /I+xHDTYc/7cn8uFranmg+fNLFs4RuG89JDRMXSPZD4va8P+m9dwYKrELt9qFZFwzzjr gHwAf8HPelGnGBckiHB4l5p4Jz0zyrGBEzy/+2WsX6GRBNawrPUrwD3lv89CUnpv0OUN AuYcAaUQJyhIWkh/9LxAJnyxR4qSWALx1keCJxHWmikKfewJ2hWwh+dfg2hAXJRw38H5 AbWw== X-Gm-Message-State: ANoB5pmRhC5WlMkum0YPCdB1XR2EaG0XKtzqnuj9IhABxhs4eONYndxE +uSQ3tJYFEzdpZ3A9PKFM678x0Ktc5En5g== X-Google-Smtp-Source: AA0mqf7FDQs4+6IXDzjCM0GA26kjXImC7VjYHa5i6f0ybBoi6AIaRzgO0D+3nfimDFpGcY9VxthHuQ== X-Received: by 2002:aa7:8b4d:0:b0:56c:962:fe7e with SMTP id i13-20020aa78b4d000000b0056c0962fe7emr31265822pfd.32.1671191981717; Fri, 16 Dec 2022 03:59:41 -0800 (PST) Received: from bobo.ozlabs.ibm.com (115-64-236-36.tpgi.com.au. [115.64.236.36]) by smtp.gmail.com with ESMTPSA id g22-20020a625216000000b0057ef155103asm1289438pfb.155.2022.12.16.03.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 03:59:41 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/4] powerpc/64: Fix task_cpu in early boot when booting non-zero cpuid Date: Fri, 16 Dec 2022 21:59:28 +1000 Message-Id: <20221216115930.2667772-3-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221216115930.2667772-1-npiggin@gmail.com> References: <20221216115930.2667772-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" powerpc/64 can boot on a non-zero SMP processor id. Initially, the boot CPU is said to be "assumed to be 0" until early_init_devtree() discovers the id from the device tree. That is not a good description because the assumption can be wrong and that has to be handled, the better description is that 0 is used as a placeholder, and things are fixed after the real id is discovered. smp_processor_id() is set to the boot cpuid, but task_cpu(current) is not, which causes the smp_processor_id() == task_cpu(current) invariant to be broken until init_idle() in sched_init(). This is quite fragile and could lead to subtle bugs in future. One bug is that validate_sp_size uses task_cpu() to get the process stack, so any stack trace from the the booting CPU between early_init_devtree() and sched_init() will have problems. Early on paca_ptrs[0] will be poisoned, so that can cause machine checks dereferencing that memory in real mode. Later, validating the current stack pointer against the idle task of a different secondary will probably cause no stack trace to be printed. Fix this by setting thread_info->cpu right after smp_processor_id() is set to the boot cpuid. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/setup_64.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index a0dee7354fe6..e6c8d1e326f7 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -396,6 +396,9 @@ void __init early_setup(unsigned long dt_ptr) } fixup_boot_paca(paca_ptrs[boot_cpuid]); setup_paca(paca_ptrs[boot_cpuid]); /* install the paca into registers */ + // smp_processor_id() now reports boot_cpuid + + task_thread_info(current)->cpu = boot_cpuid; // fix task_cpu(current) /* * Configure exception handlers. This include setting up trampolines From patchwork Fri Dec 16 11:59:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1716489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=aZE0/7go; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYSQh0chhz23ym for ; Fri, 16 Dec 2022 23:02:36 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NYSQg6lTRz3cKW for ; Fri, 16 Dec 2022 23:02:35 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=aZE0/7go; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1034; helo=mail-pj1-x1034.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=aZE0/7go; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NYSMR2Z24z3bct for ; Fri, 16 Dec 2022 22:59:47 +1100 (AEDT) Received: by mail-pj1-x1034.google.com with SMTP id hd14-20020a17090b458e00b0021909875bccso8302228pjb.1 for ; Fri, 16 Dec 2022 03:59:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7B1I8l1tea8GLuvshZ0T9XI8KL6wiYwGl97FyXz35Gw=; b=aZE0/7goOYTyGcNSsBWvu4mtlU4+e4LMeD9TzrwEd92AuOpj/GUMdh14DmDGipxHdH vPN+BYRgSvH/1wNi9Ni8VMyigALcyzAxZCBOQgyVTwK1uAM+yZ/mxvFDxskIz7HbpW3U OQPLC/4wGOlfzrAliUct4FuCEiOMLbYpbrTcwWgzTibTWdVCXNYMyg6AsC1k/zduLVSW glyIapzBqsHyqiZYW4bk2ZokvkJu2/6cyYK9HlOp2Dt1OyoI9OKSpoBcQuUg5EIsl3CP OGXWQ7RZ1vXQP+W3FSCtvQoTRDl8NqUd7FS8OTQO0bdZ6D1RdHfjT9O3WtKTtILajeNo 071Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7B1I8l1tea8GLuvshZ0T9XI8KL6wiYwGl97FyXz35Gw=; b=TocBC7w1MlkjBltEIGH5SBg0Uo5jU7jXgBoM9dY+qwu1RB1pz7/rmH8Tbx54SqBMvZ dAG937f82kgDzhXRkOd/2+1mBT8HdBw2lwl3mtmTbIv7lLm8xA43R9wHIt8b/62sbhyS S3hSrV9GR75SzokSQC7VNTgMhrVlQDrfHaQcYoc3Y/mKL9teFVldADSRn3FbCDref1KN 7lP5KCNhRgQkx7FiuMo8TzyJZ1AB5wscPUJmxK4reogaVrRF7iPObOgQVIZugFpptd4y aThz1j08HKFVrDqiXnBdSfRwnFyW1f0M8IBx3a3uz+PJOZF/spDDz8K87+f1ZaVfyj1z x05g== X-Gm-Message-State: ANoB5plBPJqm9ZfrqlaFORxgFDWgQ+emhBZtixGX4W/aRHALCkUs55sY XhVZPVouWYLv8q5HNE8tAM48umLXHia68w== X-Google-Smtp-Source: AA0mqf6zko5zeLqGOMxIiT+6qXjM+RzLRTsM2TarxUvb90SSMpYfOrOeo78ruuDw4ZFWeDuRd7Pu6Q== X-Received: by 2002:a05:6a21:9103:b0:a5:35f1:95d1 with SMTP id tn3-20020a056a21910300b000a535f195d1mr36691354pzb.35.1671191984008; Fri, 16 Dec 2022 03:59:44 -0800 (PST) Received: from bobo.ozlabs.ibm.com (115-64-236-36.tpgi.com.au. [115.64.236.36]) by smtp.gmail.com with ESMTPSA id g22-20020a625216000000b0057ef155103asm1289438pfb.155.2022.12.16.03.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 03:59:43 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 3/4] powerpc/64: Move paca allocation to early_setup() Date: Fri, 16 Dec 2022 21:59:29 +1000 Message-Id: <20221216115930.2667772-4-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221216115930.2667772-1-npiggin@gmail.com> References: <20221216115930.2667772-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The early paca and boot cpuid dance is complicated and currently does not quite work as expected for boot cpuid != 0 cases. early_init_devtree() currently allocates the paca_ptrs and boot cpuid paca, but until that returns and early_setup() calls setup_paca(), this thread is currently still executing with smp_processor_id() == 0. One problem this causes is the paca_ptrs[smp_processor_id()] pointer is poisoned, so valid_emergency_stack() (any backtrace) and any similar users will crash. Another is that the hardware id which is set here will not be returned by get_hard_smp_processor_id(smp_processor_id()), but it would work correctly for boot_cpuid == 0, which could lead to difficult to reproduce or find bugs. The hard id does not seem to be used by the rest of early_init_devtree(), it just looks like all this code might have been put here to allocate somewhere to store boot CPU hardware id while scanning the devtree. Rearrange things so the hwid is put in a global variable like boot_cpuid, and do all the paca allocation and boot paca setup in the 64-bit early_setup() after we have everything ready to go. The paca_ptrs[0] re-poisoning code in early_setup does not seem to have ever worked, because paca_ptrs[0] was never not-poisoned when boot_cpuid is not 0. Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/paca.h | 1 - arch/powerpc/include/asm/smp.h | 1 + arch/powerpc/kernel/prom.c | 12 ++---------- arch/powerpc/kernel/setup-common.c | 4 ++++ arch/powerpc/kernel/setup_64.c | 11 +++++------ 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h index 09f1790d0ae1..0ab3511a47d7 100644 --- a/arch/powerpc/include/asm/paca.h +++ b/arch/powerpc/include/asm/paca.h @@ -295,7 +295,6 @@ extern void free_unused_pacas(void); #else /* CONFIG_PPC64 */ -static inline void allocate_paca_ptrs(void) { } static inline void allocate_paca(int cpu) { } static inline void free_unused_pacas(void) { } diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h index f63505d74932..6c6cb53d7045 100644 --- a/arch/powerpc/include/asm/smp.h +++ b/arch/powerpc/include/asm/smp.h @@ -26,6 +26,7 @@ #include extern int boot_cpuid; +extern int boot_cpu_hwid; /* PPC64 only */ extern int spinning_secondaries; extern u32 *cpu_to_phys_id; extern bool coregroup_enabled; diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 4f1c920aa13e..b3aa6df872a5 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -369,9 +369,7 @@ static int __init early_init_dt_scan_cpus(unsigned long node, DBG("boot cpu: logical %d physical %d\n", found, be32_to_cpu(intserv[found_thread])); boot_cpuid = found; - - // Pass the boot CPU's hard CPU id back to our caller - *((u32 *)data) = be32_to_cpu(intserv[found_thread]); + boot_cpu_hwid = be32_to_cpu(intserv[found_thread]); /* * PAPR defines "logical" PVR values for cpus that @@ -755,7 +753,6 @@ static inline void save_fscr_to_task(void) {} void __init early_init_devtree(void *params) { - u32 boot_cpu_hwid; phys_addr_t limit; DBG(" -> early_init_devtree(%px)\n", params); @@ -851,7 +848,7 @@ void __init early_init_devtree(void *params) /* Retrieve CPU related informations from the flat tree * (altivec support, boot CPU ID, ...) */ - of_scan_flat_dt(early_init_dt_scan_cpus, &boot_cpu_hwid); + of_scan_flat_dt(early_init_dt_scan_cpus, NULL); if (boot_cpuid < 0) { printk("Failed to identify boot CPU !\n"); BUG(); @@ -868,11 +865,6 @@ void __init early_init_devtree(void *params) mmu_early_init_devtree(); - // NB. paca is not installed until later in early_setup() - allocate_paca_ptrs(); - allocate_paca(boot_cpuid); - set_hard_smp_processor_id(boot_cpuid, boot_cpu_hwid); - #ifdef CONFIG_PPC_POWERNV /* Scan and build the list of machine check recoverable ranges */ of_scan_flat_dt(early_init_dt_scan_recoverable_ranges, NULL); diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index 6d041993a45d..efb301a4987c 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -86,6 +86,10 @@ EXPORT_SYMBOL(machine_id); int boot_cpuid = -1; EXPORT_SYMBOL_GPL(boot_cpuid); +#ifdef CONFIG_PPC64 +int boot_cpu_hwid = -1; +#endif + /* * These are used in binfmt_elf.c to put aux entries on the stack * for each elf executable being started. diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index e6c8d1e326f7..78d8a105764b 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -385,15 +385,14 @@ void __init early_setup(unsigned long dt_ptr) /* * Do early initialization using the flattened device * tree, such as retrieving the physical memory map or - * calculating/retrieving the hash table size. + * calculating/retrieving the hash table size, discover + * boot_cpuid and boot_cpu_hwid. */ early_init_devtree(__va(dt_ptr)); - /* Now we know the logical id of our boot cpu, setup the paca. */ - if (boot_cpuid != 0) { - /* Poison paca_ptrs[0] again if it's not the boot cpu */ - memset(&paca_ptrs[0], 0x88, sizeof(paca_ptrs[0])); - } + allocate_paca_ptrs(); + allocate_paca(boot_cpuid); + set_hard_smp_processor_id(boot_cpuid, boot_cpu_hwid); fixup_boot_paca(paca_ptrs[boot_cpuid]); setup_paca(paca_ptrs[boot_cpuid]); /* install the paca into registers */ // smp_processor_id() now reports boot_cpuid From patchwork Fri Dec 16 11:59:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1716490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kzPbNopU; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYSRj0ntlz23ym for ; Fri, 16 Dec 2022 23:03:28 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NYSRh3c1vz3fD9 for ; Fri, 16 Dec 2022 23:03:28 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kzPbNopU; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::635; helo=mail-pl1-x635.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kzPbNopU; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NYSMT1WZTz3bXL for ; Fri, 16 Dec 2022 22:59:48 +1100 (AEDT) Received: by mail-pl1-x635.google.com with SMTP id d7so2065034pll.9 for ; Fri, 16 Dec 2022 03:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jFdtN6Twm/Q4+OPS0op+uuJ+Ke3EoqZ59eFa8lp8vg8=; b=kzPbNopUo66h5349XieMml0MHtHLSr2gUNysz4KZzRCVuqVFDewHZeLyGG35w6r5Ba lRXg0SzBOtimlbNMc2lscMmDfhrwheCZ5AVK1JnTN/6NMLh0RGSiNFRxeOD11EmLiocH hPB1TJHVIEm5y6GzQ4+Vjpfw1ujv4N8A3XOTEmjs/JRIWZt7+MJVRquoD7pqjUTYNaMb xlGHSQQDUlW8kXNFu/gVCZeHGYwrYRerA/VtLOR5q0U5d7Z82JNl5+sUH8pXdVKCv48h t4LleNsLt1rwPyJlJlnRA4d32NMHKHMdynujCPW0mm7wxxltFm+U10FhGolWgecqY7Ki pFRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jFdtN6Twm/Q4+OPS0op+uuJ+Ke3EoqZ59eFa8lp8vg8=; b=VUJ6g8zH8Yhteyr86lqRVQOfxSLyZfHA0Kx/O5D5qbo7eIiuzSZ7YZ6Xuwz3nciyCY bFUPBNEJP4C8FVBrN9wZNQzHUZl3LIJzvfTvxlxTvbPwWQQREGU++FPJLwPYrcRkxybi Lh7U/sq019Ute1NJStNbJupwxo7fC/n+YnZ4O+QQshZmO5LkM7Upo+FkcYUcxScQOEaq 35au/jrpNQB/jcClql+YcpucLawXTUFjE/bs9hGuLkJY1M3s0zwanjeaUdSM/+ukpW6n GPreTTyeymfaMwZeLPIC9Ht7f1nx9Kfop5qz0aSOyjsPZ+mvFqWR0pCScHcAM4KxTbFa CWPQ== X-Gm-Message-State: ANoB5pms3OsFrRTj6uyeg1PFxmaQRLkhyVZdDpkXrVoosdEL/ESwLlOW 5IXtrL9Qrt2CQ098MSA6BDEbuN74bHUKfQ== X-Google-Smtp-Source: AA0mqf5BKYE9FM+XiurZWsY8i49rG4DwhuZdJYP8GMKlLdDijFkR3vQGY9O/CEUPOTfgOMeN/q2kcw== X-Received: by 2002:a05:6a20:441e:b0:ac:16ae:1082 with SMTP id ce30-20020a056a20441e00b000ac16ae1082mr56647442pzb.32.1671191986408; Fri, 16 Dec 2022 03:59:46 -0800 (PST) Received: from bobo.ozlabs.ibm.com (115-64-236-36.tpgi.com.au. [115.64.236.36]) by smtp.gmail.com with ESMTPSA id g22-20020a625216000000b0057ef155103asm1289438pfb.155.2022.12.16.03.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 03:59:45 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 4/4] powerpc: Skip stack validation checking alternate stacks if they are not allocated Date: Fri, 16 Dec 2022 21:59:30 +1000 Message-Id: <20221216115930.2667772-5-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221216115930.2667772-1-npiggin@gmail.com> References: <20221216115930.2667772-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Stack validation in early boot can just bail out of checking alternate stacks if they are not validated yet. Checking against a NULL stack could cause NULLish pointer values to be considered valid. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/process.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index edb46d0806ef..95d605bdff85 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -2118,6 +2118,9 @@ static inline int valid_irq_stack(unsigned long sp, struct task_struct *p, unsigned long stack_page; unsigned long cpu = task_cpu(p); + if (!hardirq_ctx[cpu] || !softirq_ctx[cpu]) + return 0; + stack_page = (unsigned long)hardirq_ctx[cpu]; if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes) return 1; @@ -2139,6 +2142,14 @@ static inline int valid_emergency_stack(unsigned long sp, struct task_struct *p, if (!paca_ptrs) return 0; + if (!paca_ptrs[cpu]->emergency_sp) + return 0; + +# ifdef CONFIG_PPC_BOOK3S_64 + if (!paca_ptrs[cpu]->nmi_emergency_sp || !paca_ptrs[cpu]->mc_emergency_sp) + return 0; +#endif + stack_page = (unsigned long)paca_ptrs[cpu]->emergency_sp - THREAD_SIZE; if (sp >= stack_page && sp <= stack_page + THREAD_SIZE - nbytes) return 1;