From patchwork Tue Mar 19 07:58:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WJxXTgbO; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPKg3tzKz1yWn for ; Tue, 19 Mar 2024 19:00:39 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WJxXTgbO; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPKg2ryTz3vYw for ; Tue, 19 Mar 2024 19:00:39 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=WJxXTgbO; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42a; helo=mail-pf1-x42a.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (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 4TzPJZ0wSgz3cDk for ; Tue, 19 Mar 2024 18:59:41 +1100 (AEDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6e6c8823519so5020571b3a.0 for ; Tue, 19 Mar 2024 00:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835179; x=1711439979; darn=lists.ozlabs.org; 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=MV1GkDUYdGk6FpqIRujPCzrSPB/odnEVLVEaqpwb+zI=; b=WJxXTgbOlEfzbYJ602Mly9ljVa5MtGxRjAfMKSRa2LsYp5B+h9G17WTrEqu5blO0WX irdAKnQrNymzS77yjuqcPgzUR3w7qOckau7nTcMsuRYU4McOqf5mwGEaZmhzRv3me2NR l32cDnsnxgvf0Qxbj6AGxVYFxlaMLIm6x52CfHfIrVC1009nwE1cFOTIJQ1VVFsQmhjo ut8boUW/BQo3DJPenoCS+CUvFgg4BfFJilBMJYW1dVmyG8KTMNtcQePhjAQTc5pBLjyu W8QzzJcEwg5hH67Ss68kfDYXL5lwq/OR2ndozfyiVXrRhhNdw5qtoMkIZWWqXCC0Iz0q 9MqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835179; x=1711439979; 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=MV1GkDUYdGk6FpqIRujPCzrSPB/odnEVLVEaqpwb+zI=; b=A5/5xcb3OrluBBtRwDnciCB3JiE9T1lvf71YDBgPy1NiMTpj2GXi/rUSzUQ8+lC6xc 8J79UO+7vhacw7vGnho4C6JI1yuAJkhHvwtwq57qPfnwO0aqLYsjT2KRFBeh+rXDod1T eC1PrLWQKmeufcu64Of6h9CskgEsABlip0EQDFSH/7Q55+7H2v8Hq6kmzKlsw4URujLH H+4W/CBhuDsJwYZQjez6T92K0BDSOg03kRMx3VprVxKPfkDEeVlXbHAEApCkTeJiY2ub 1DFLEAl29eSjJpRIcqmOMvL60P9bf5TEeF0dYOMLE1uthv5id+GdEJeSD2sL+fq1vzMC eCiw== X-Forwarded-Encrypted: i=1; AJvYcCXfFZHlL+9lUIlK1kz3xh5aGeRiST60ZIolLWqZ/8ZRwN73bNMdt0abxsptTYkW5jLUU0taGUYEUef20umpB1RYy4OcFr2t/ahszV3QiA== X-Gm-Message-State: AOJu0YxbG8C9p36ioP3/JWsbrCiQXffi1GBR+9H6Vc+oCmTa6p7LNcnZ z7JW2cgOCWLNyxOPBI2k5GFA0/9BIwi1+eTLrK+dss8UDwTYbUb4 X-Google-Smtp-Source: AGHT+IHeL4fHra/9GDTXS1doTdE3e+vFe2XbaH0TFQXn1QEOJgVJ8PGJhTMXeVyepFJKOTtmHxwhkg== X-Received: by 2002:a05:6a00:3d10:b0:6e7:2dd1:6e7d with SMTP id lo16-20020a056a003d1000b006e72dd16e7dmr2352807pfb.18.1710835179082; Tue, 19 Mar 2024 00:59:39 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.00.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 00:59:38 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 01/35] arch-run: Add functions to help handle migration directives from test Date: Tue, 19 Mar 2024 17:58:52 +1000 Message-ID: <20240319075926.2422707-2-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The migration harness will be expanded to deal with more commands from the test, moving these checks into functions helps keep things managable. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- scripts/arch-run.bash | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 413f3eda8..e34d784c0 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -122,6 +122,16 @@ qmp_events () jq -c 'select(has("event"))' } +filter_quiet_msgs () +{ + grep -v "Now migrate the VM (quiet)" +} + +seen_migrate_msg () +{ + grep -q -e "Now migrate the VM" < $1 +} + run_migration () { if ! command -v ncat >/dev/null 2>&1; then @@ -152,7 +162,7 @@ run_migration () -chardev socket,id=mon,path=${src_qmp},server=on,wait=off \ -mon chardev=mon,mode=control > ${src_outfifo} & live_pid=$! - cat ${src_outfifo} | tee ${src_out} | grep -v "Now migrate the VM (quiet)" & + cat ${src_outfifo} | tee ${src_out} | filter_quiet_msgs & # Start the first destination QEMU machine in advance of the test # reaching the migration point, since we expect at least one migration. @@ -162,7 +172,7 @@ run_migration () while ps -p ${live_pid} > /dev/null ; do # Wait for test exit or further migration messages. - if ! grep -q -i "Now migrate the VM" < ${src_out} ; then + if ! seen_migrate_msg ${src_out} ; then sleep 0.1 else do_migration || return $? @@ -190,11 +200,11 @@ do_migration () -mon chardev=mon,mode=control -incoming unix:${dst_incoming} \ < <(cat ${dst_infifo}) > ${dst_outfifo} & incoming_pid=$! - cat ${dst_outfifo} | tee ${dst_out} | grep -v "Now migrate the VM (quiet)" & + cat ${dst_outfifo} | tee ${dst_out} | filter_quiet_msgs & # The test must prompt the user to migrate, so wait for the - # "Now migrate VM" console message. - while ! grep -q -i "Now migrate the VM" < ${src_out} ; do + # "Now migrate VM" or similar console message. + while ! seen_migrate_msg ${src_out} ; do if ! ps -p ${live_pid} > /dev/null ; then echo "ERROR: Test exit before migration point." >&2 echo > ${dst_infifo} From patchwork Tue Mar 19 07:58:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Wsa9pfye; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPLd0Jgvz1yWn for ; Tue, 19 Mar 2024 19:01:29 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Wsa9pfye; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPLc0LBYz3vYq for ; Tue, 19 Mar 2024 19:01:28 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=Wsa9pfye; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::435; helo=mail-pf1-x435.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (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 4TzPJd3kngz3cy8 for ; Tue, 19 Mar 2024 18:59:45 +1100 (AEDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso3170160b3a.1 for ; Tue, 19 Mar 2024 00:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835182; x=1711439982; darn=lists.ozlabs.org; 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=7znwqTVB8+8L1jJIfaQ7a8vMZg63pFuyoiAqB5ObgC4=; b=Wsa9pfyeKyZIhmusnxfOlH+IM3BejNvufPXsjjhn20jq6tQzoadKsJZgevUvBUf8BS vRvAFawNETnPIvEvVHGopnkm9rQr64b5ktXVkOp8do4QfbAZqgqqKkIjtQxvxNHwlp0d uqhIeG0itI+paetTjWj42OWCE+7V3H+nVsURXnCE/tw3JJ1g/VhUpBZOpHz9QlCrY3e/ AJJ0SbljhilgCzHmsJTcvKhDf1zS8dTvWKk7Kaj4GcJHDCr55YLaITzQqQ3rnZdE7XRg 55MnU9IbzLrEFqeZyxLfDGo3R5IW4VgJpIdaDc1FJAK23TiYs/kGOjFfg//AqtgUmAJV dFoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835182; x=1711439982; 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=7znwqTVB8+8L1jJIfaQ7a8vMZg63pFuyoiAqB5ObgC4=; b=hzyZWiFcQO7dToIPNRwEaPW7UmTF9wIkyS0d0/bUESz9SB7zFAZTC7s+Jwe/uV/IAm WE97oB/2u2ybnocRdg6Lqz+/XHVxmfEuRnWTDFifWyqEcMJ5nHDAaq1V0H20oNk4QOQ9 1kolUGDAb1yNnqdhhLc3FxMMTCZmQa+EOgn/gL21Fsu5LSpjPa7myyBByL08vq5a8kiI VhZKA3fL7nZoRK47sQiOlmwoI/fQu5Ge8gKoXOkMr4zWRn52tM5KxpuhpxMMI00qu0us +ZaVOVEpv9QuW8ANvRI79mfFVPFJYknnt4was+SBL/9i2+pK9XJQxfJsPKWx4GbokvnV bJaw== X-Forwarded-Encrypted: i=1; AJvYcCXTZMWbMVdQKA0lrz+v9o0Dc5+6bPyoMmax+CB7y7GBlDLLo/TreOzjaExDKrwwJDH5mOI6fs+RZ1WPGIPSsH4nRAUcMw0OnomWS7E1UQ== X-Gm-Message-State: AOJu0Yx3Klq9pbz5lOiLKwYTwaVqtDG7KyPbWMkhQPYd+UO5ugCdZUKP HJJD11x4jD2hw3DVdvPqCnw1qQyzA5eV+vqeGj+nTn9lgP0mpEOh X-Google-Smtp-Source: AGHT+IE4j+Tvbeu58NluMV0rzs1CQ2K9gXa/2zH3LKie41jBP9/lGyR0R3vWNoE8F5Vdq7v8pF2U6Q== X-Received: by 2002:a05:6a21:3115:b0:1a3:647b:b892 with SMTP id yz21-20020a056a21311500b001a3647bb892mr2682650pzb.15.1710835182535; Tue, 19 Mar 2024 00:59:42 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.00.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 00:59:42 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 02/35] arch-run: Keep infifo open Date: Tue, 19 Mar 2024 17:58:53 +1000 Message-ID: <20240319075926.2422707-3-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The infifo fifo that is used to send characters to QEMU console is only able to receive one character before the cat process exits. Supporting interactions between test and harness involving multiple characters requires the fifo to remain open. The infifo is removed by the exit handler like other files and fifos so it does not have to be removed explicitly. With this we can let the cat out of the subshell, simplifying the input pipeline. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- scripts/arch-run.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index e34d784c0..39419d4e2 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -158,6 +158,11 @@ run_migration () mkfifo ${src_outfifo} mkfifo ${dst_outfifo} + # Holding both ends of the input fifo open prevents opens from + # blocking and readers getting EOF when a writer closes it. + mkfifo ${dst_infifo} + exec {dst_infifo_fd}<>${dst_infifo} + eval "$migcmdline" \ -chardev socket,id=mon,path=${src_qmp},server=on,wait=off \ -mon chardev=mon,mode=control > ${src_outfifo} & @@ -191,14 +196,10 @@ run_migration () do_migration () { - # We have to use cat to open the named FIFO, because named FIFO's, - # unlike pipes, will block on open() until the other end is also - # opened, and that totally breaks QEMU... - mkfifo ${dst_infifo} eval "$migcmdline" \ -chardev socket,id=mon,path=${dst_qmp},server=on,wait=off \ -mon chardev=mon,mode=control -incoming unix:${dst_incoming} \ - < <(cat ${dst_infifo}) > ${dst_outfifo} & + < ${dst_infifo} > ${dst_outfifo} & incoming_pid=$! cat ${dst_outfifo} | tee ${dst_out} | filter_quiet_msgs & @@ -245,7 +246,6 @@ do_migration () # keypress to dst so getchar completes and test continues echo > ${dst_infifo} - rm ${dst_infifo} # Wait for the incoming socket being removed, ready for next destination while [ -S ${dst_incoming} ] ; do sleep 0.1 ; done From patchwork Tue Mar 19 07:58:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913399 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GqIprZER; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPMP3zznz1yWn for ; Tue, 19 Mar 2024 19:02:09 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GqIprZER; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPMP3F4mz3vfL for ; Tue, 19 Mar 2024 19:02:09 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=GqIprZER; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::234; helo=mail-oi1-x234.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) (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 4TzPJj5r2Qz3d2S for ; Tue, 19 Mar 2024 18:59:49 +1100 (AEDT) Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3c36ecdb8cdso2392601b6e.1 for ; Tue, 19 Mar 2024 00:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835186; x=1711439986; darn=lists.ozlabs.org; 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=WJXIfkCsibp4Aw45b+vw1E9RlbSLpSfwY3Yn03ICrgs=; b=GqIprZERb4HjRJ7vYnw7brFgG7hA0JsQDARvkKCLKjiaXykVNaQf/ucyUJ1AbA5odx 2QApH+0aD0ZTLNFy2dQaX5SKzPzvgFQY+QpSGpe83zgJESLNfYha/I40UWYimayuiNI7 UYm0LGdvDfkfs0m4eUVUz0bnKxhXGwkI8GjxzW12ntzjCL11Pwv3jodtDtOoQPupUlO2 3ac0aoFBdHLYlBzBL7E5WW9Z6HZ2sFOKb0UUTUjh01E1mvV3Vvdq41qCf78rsmLXQwYY F8kvivsHqqFpIqIHsnNSocCPJLmSmskwAmuPElXcixMWXwdBTu10NpVojhoDDbJQIlbK MgNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835186; x=1711439986; 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=WJXIfkCsibp4Aw45b+vw1E9RlbSLpSfwY3Yn03ICrgs=; b=iMOB1x1S4cleC1b4DXI6hGU6+1K4aLMMJ82HnjZsNkkssvdpCb1lakFW4yqzZJZAZJ mKKy9AgwL54LRGQpQ0HfNphioW3fsgoSJ/f5JBWmR+vu1VQ6TsYHA+Vc97iLmrVcpzGV 5eRyvVMkni295PnZq00hz0bu3bbUFSeHnliDFXk4FbK1mVX0XZAHVeMO50OACS6Zc/Cq z+wLCRym4W1mF1Tu6wwbnyxsVfbOIXzhYxxgB3n539gDTRLGZeIkchiQdJkyrXVvW7h6 bcl5V6cmmSQJP1WGhO/TpqhP/+E67vq7+a00yPeA90GS2BuLsrVJREOa4hg5xaxY5fKX bHuQ== X-Forwarded-Encrypted: i=1; AJvYcCWblIIcb6eYRfk6+e0L/wEbXe1bWBBjWroDHNPjmhXY4iBHNBZbW0gaBDsFXzHskbgJAQghAqaGOHvyccz2Be16UE0tNUcaNso7vMBvig== X-Gm-Message-State: AOJu0YyiLFWFv0ymCEZrJDtpGAXnobUt0k0Pr0Dq2IdCAic+zcwIJTSQ tiBnHFb4XJN2qzXsgOdicT0DvnpSdW+GejpD6PfgWMgqynFOcjjR X-Google-Smtp-Source: AGHT+IHpvTT6B8OY18z+7YTBKY9h7TRV22MDyvqJw1A8sJ4u8JA9bEthO8U5aiKvrS2sDYbpR8Qc9g== X-Received: by 2002:a05:6808:2121:b0:3c2:4e50:426e with SMTP id r33-20020a056808212100b003c24e50426emr2264794oiw.27.1710835186240; Tue, 19 Mar 2024 00:59:46 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.00.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 00:59:46 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 03/35] migration: Add a migrate_skip command Date: Tue, 19 Mar 2024 17:58:54 +1000 Message-ID: <20240319075926.2422707-4-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Tests that are run with MIGRATION=yes but skip due to some requirement not being met will show as a failure due to the harness requirement to see one successful migration. The workaround for this is to migrate in test's skip path. Add a new command that just tells the harness to not expect a migration. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- common/selftest-migration.c | 14 ++++++++----- lib/migrate.c | 19 ++++++++++++++++- lib/migrate.h | 2 ++ powerpc/unittests.cfg | 6 ++++++ s390x/unittests.cfg | 5 +++++ scripts/arch-run.bash | 41 +++++++++++++++++++++++++++++-------- 6 files changed, 73 insertions(+), 14 deletions(-) diff --git a/common/selftest-migration.c b/common/selftest-migration.c index 54b5d6b2d..0afd8581c 100644 --- a/common/selftest-migration.c +++ b/common/selftest-migration.c @@ -14,14 +14,18 @@ int main(int argc, char **argv) { - int i = 0; - report_prefix_push("migration"); - for (i = 0; i < NR_MIGRATIONS; i++) - migrate_quiet(); + if (argc > 1 && !strcmp(argv[1], "skip")) { + migrate_skip(); + report(true, "migration skipping"); + } else { + int i; - report(true, "simple harness stress test"); + for (i = 0; i < NR_MIGRATIONS; i++) + migrate_quiet(); + report(true, "simple harness stress"); + } report_prefix_pop(); diff --git a/lib/migrate.c b/lib/migrate.c index 92d1d957d..1d22196b7 100644 --- a/lib/migrate.c +++ b/lib/migrate.c @@ -39,7 +39,24 @@ void migrate_once(void) if (migrated) return; - migrated = true; + migrate(); } + +/* + * When the test has been started in migration mode, but the test case is + * skipped and no migration point is reached, this can be used to tell the + * harness not to mark it as a failure to migrate. + */ +void migrate_skip(void) +{ + static bool did_migrate_skip; + + if (did_migrate_skip) + return; + did_migrate_skip = true; + + puts("Skipped VM migration (quiet)\n"); + (void)getchar(); +} diff --git a/lib/migrate.h b/lib/migrate.h index 95b9102b0..db6e0c501 100644 --- a/lib/migrate.h +++ b/lib/migrate.h @@ -9,3 +9,5 @@ void migrate(void); void migrate_quiet(void); void migrate_once(void); + +void migrate_skip(void); diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 1559bee98..cae4949e8 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -43,6 +43,12 @@ groups = selftest migration # https://lore.kernel.org/qemu-devel/20240219061731.232570-1-npiggin@gmail.com/ accel = kvm +[selftest-migration-skip] +file = selftest-migration.elf +machine = pseries +groups = selftest migration +extra_params = -append "skip" + [spapr_hcall] file = spapr_hcall.elf diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index dac9e4db1..49e3e4608 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -31,6 +31,11 @@ groups = selftest migration # https://lore.kernel.org/qemu-devel/20240219061731.232570-1-npiggin@gmail.com/ accel = kvm +[selftest-migration-skip] +file = selftest-migration.elf +groups = selftest migration +extra_params = -append "skip" + [intercept] file = intercept.elf diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 39419d4e2..4a1aab48d 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -124,12 +124,17 @@ qmp_events () filter_quiet_msgs () { - grep -v "Now migrate the VM (quiet)" + grep -v "Now migrate the VM (quiet)" | + grep -v "Skipped VM migration (quiet)" } seen_migrate_msg () { - grep -q -e "Now migrate the VM" < $1 + if [ $skip_migration -eq 1 ]; then + grep -q -e "Now migrate the VM" < $1 + else + grep -q -e "Now migrate the VM" -e "Skipped VM migration" < $1 + fi } run_migration () @@ -142,7 +147,7 @@ run_migration () migcmdline=$@ trap 'trap - TERM ; kill 0 ; exit 2' INT TERM - trap 'rm -f ${src_out} ${dst_out} ${src_outfifo} ${dst_outfifo} ${dst_incoming} ${src_qmp} ${dst_qmp} ${dst_infifo}' RETURN EXIT + trap 'rm -f ${src_out} ${dst_out} ${src_outfifo} ${dst_outfifo} ${dst_incoming} ${src_qmp} ${dst_qmp} ${src_infifo} ${dst_infifo}' RETURN EXIT dst_incoming=$(mktemp -u -t mig-helper-socket-incoming.XXXXXXXXXX) src_out=$(mktemp -t mig-helper-stdout1.XXXXXXXXXX) @@ -151,21 +156,26 @@ run_migration () dst_outfifo=$(mktemp -u -t mig-helper-fifo-stdout2.XXXXXXXXXX) src_qmp=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX) dst_qmp=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX) - dst_infifo=$(mktemp -u -t mig-helper-fifo-stdin.XXXXXXXXXX) + src_infifo=$(mktemp -u -t mig-helper-fifo-stdin1.XXXXXXXXXX) + dst_infifo=$(mktemp -u -t mig-helper-fifo-stdin2.XXXXXXXXXX) src_qmpout=/dev/null dst_qmpout=/dev/null + skip_migration=0 mkfifo ${src_outfifo} mkfifo ${dst_outfifo} # Holding both ends of the input fifo open prevents opens from # blocking and readers getting EOF when a writer closes it. + mkfifo ${src_infifo} mkfifo ${dst_infifo} + exec {src_infifo_fd}<>${src_infifo} exec {dst_infifo_fd}<>${dst_infifo} eval "$migcmdline" \ -chardev socket,id=mon,path=${src_qmp},server=on,wait=off \ - -mon chardev=mon,mode=control > ${src_outfifo} & + -mon chardev=mon,mode=control \ + < ${src_infifo} > ${src_outfifo} & live_pid=$! cat ${src_outfifo} | tee ${src_out} | filter_quiet_msgs & @@ -179,8 +189,11 @@ run_migration () # Wait for test exit or further migration messages. if ! seen_migrate_msg ${src_out} ; then sleep 0.1 - else + elif grep -q "Now migrate the VM" < ${src_out} ; then do_migration || return $? + elif [ $skip_migration -eq 0 ] && grep -q "Skipped VM migration" < ${src_out} ; then + echo > ${src_infifo} # Resume src and carry on. + break; fi done @@ -207,10 +220,10 @@ do_migration () # "Now migrate VM" or similar console message. while ! seen_migrate_msg ${src_out} ; do if ! ps -p ${live_pid} > /dev/null ; then - echo "ERROR: Test exit before migration point." >&2 echo > ${dst_infifo} - qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null + echo "ERROR: Test exit before migration point." >&2 + qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null return 3 fi sleep 0.1 @@ -220,6 +233,15 @@ do_migration () while ! [ -S ${dst_incoming} ] ; do sleep 0.1 ; done while ! [ -S ${dst_qmp} ] ; do sleep 0.1 ; done + if [ $skip_migration -eq 0 ] && grep -q "Skipped VM migration" < ${src_out} ; then + # May not get any migrations, exit to main loop for now... + echo > ${dst_infifo} + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null + echo > ${src_infifo} # Resume src and carry on. + skip_migration=1 + return 0 + fi + qmp ${src_qmp} '"migrate", "arguments": { "uri": "unix:'${dst_incoming}'" }' > ${src_qmpout} # Wait for the migration to complete @@ -259,6 +281,9 @@ do_migration () tmp=${src_out} src_out=${dst_out} dst_out=${tmp} + tmp=${src_infifo} + src_infifo=${dst_infifo} + dst_infifo=${tmp} tmp=${src_outfifo} src_outfifo=${dst_outfifo} dst_outfifo=${tmp} From patchwork Tue Mar 19 07:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913401 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=fllXKGbQ; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPP6578bz1yWn for ; Tue, 19 Mar 2024 19:03:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=fllXKGbQ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPP6443jz3vbD for ; Tue, 19 Mar 2024 19:03:38 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=fllXKGbQ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2001:4860:4864:20::35; helo=mail-oa1-x35.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) (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 4TzPJv0Yx7z3dVf for ; Tue, 19 Mar 2024 18:59:58 +1100 (AEDT) Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-221ffba5c8bso3924942fac.1 for ; Tue, 19 Mar 2024 00:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835190; x=1711439990; darn=lists.ozlabs.org; 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=10lGgDqnsMt0XwfaOryIvipVXVv9JLsYtLmwhCPRr0M=; b=fllXKGbQ594R0HxuJWQyEYdprVLtEwBu/mnlnmuyFW8fGVatxkH/Zy4Q3C7bKbs1lQ xN2nMzHrJU12efyxEIObYFa4Qhy+AyAdwG8QEdUUoU0Ro8hkse6sA1ZB7S/HHKWFoKIW U+tGNOXtZlwjOEm73KsvhtVdFajSAuYZV9hOPnT+xg4RMzsWoZsmmL1Id0DfVrUQJ1/B Fjcrbfl3xSWJ8YEwR2Jycz7h8B8KrNID6ba4tsah+V8/3j/G+48LVguE8M0KciXYweCx 0sdVNGU3mH9hY1JLzX9aT3rOQqIPRTT5NnKNhXajIftqwC38avGvva24/t2eO/lS7UOt JbaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835190; x=1711439990; 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=10lGgDqnsMt0XwfaOryIvipVXVv9JLsYtLmwhCPRr0M=; b=SQDPMaJM65M32RegudE24r5mz273GpqK5RlrUAqrYl6P2LbzwtAL/zptgwRsKt5OGm 0S6OqHWudi4W5cvZ7ttV1kVb637rzIkhUmX1DVDY1r6XOvzoyNZIW9nnvoB0Pe8U6NSw DAHiQeNx+X/tROOyhLNX+VroU84GbZ+O9F6hNdEQDU/bUJouds0JInoF7FqyEC1ezWcC hIq+j1KPqspTiZyW3gOrYIANgN6UD/N5cGu5x8+P7V+3FifrjK+u3oYDwR8T4Q7JtmBE HWgVEJEUMRNhoGaTjxjRW4dHRvO7/Uzaw3LH69MZBzeDPowb8Xiz8HGCfegZcFiAh8nL URkA== X-Forwarded-Encrypted: i=1; AJvYcCXy82EZY+LtNLkiRiZ7czn9eHgux+X0klalqklKviWBMsHaEtjSNv/zCW7UoLRnvK528pDKfnoK98xlkUwSqhcquc2qNQwOK6jK+VN7lQ== X-Gm-Message-State: AOJu0Yzz8uM5Q3YrluZRy5KY29iBWq+GxB9pIW6VSUNco7VoQLHk8++w gYT1nsThm1PFEyI7+2qFKwEWM6UIK8AGna4r/IrlkQC9FYjOJQ7E X-Google-Smtp-Source: AGHT+IEHA5cS3U9V0i0I4RyX7h8FZvucKUvdH1mBrotXbjx1EaX70J8HT3P3/TbrepxQrYOrIZQcZg== X-Received: by 2002:a05:6871:7411:b0:21f:d4ee:ae01 with SMTP id nw17-20020a056871741100b0021fd4eeae01mr15154634oac.18.1710835190083; Tue, 19 Mar 2024 00:59:50 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.00.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 00:59:49 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 04/35] (arm|s390): Use migrate_skip in test cases Date: Tue, 19 Mar 2024 17:58:55 +1000 Message-ID: <20240319075926.2422707-5-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Have tests use the new migrate_skip command in skip paths, rather than calling migrate_once to prevent harness reporting an error. s390x/migration.c adds a new command that looks like it was missing previously. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- arm/gic.c | 21 ++++++++++++--------- s390x/migration-cmm.c | 8 ++++---- s390x/migration-skey.c | 4 +++- s390x/migration.c | 1 + 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/arm/gic.c b/arm/gic.c index c950b0d15..bbf828f17 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -782,13 +782,15 @@ static void test_its_migration(void) struct its_device *dev2, *dev7; cpumask_t mask; - if (its_setup1()) + if (its_setup1()) { + migrate_skip(); return; + } dev2 = its_get_device(2); dev7 = its_get_device(7); - migrate_once(); + migrate(); stats_reset(); cpumask_clear(&mask); @@ -819,8 +821,10 @@ static void test_migrate_unmapped_collection(void) int pe0 = 0; u8 config; - if (its_setup1()) + if (its_setup1()) { + migrate_skip(); return; + } if (!errata(ERRATA_UNMAPPED_COLLECTIONS)) { report_skip("Skipping test, as this test hangs without the fix. " @@ -836,7 +840,7 @@ static void test_migrate_unmapped_collection(void) its_send_mapti(dev2, 8192, 0, col); gicv3_lpi_set_config(8192, LPI_PROP_DEFAULT); - migrate_once(); + migrate(); /* on the destination, map the collection */ its_send_mapc(col, true); @@ -875,8 +879,10 @@ static void test_its_pending_migration(void) void *ptr; int i; - if (its_prerequisites(4)) + if (its_prerequisites(4)) { + migrate_skip(); return; + } dev = its_create_device(2 /* dev id */, 8 /* nb_ites */); its_send_mapd(dev, true); @@ -923,7 +929,7 @@ static void test_its_pending_migration(void) gicv3_lpi_rdist_enable(pe0); gicv3_lpi_rdist_enable(pe1); - migrate_once(); + migrate(); /* let's wait for the 256 LPIs to be handled */ mdelay(1000); @@ -970,17 +976,14 @@ int main(int argc, char **argv) } else if (!strcmp(argv[1], "its-migration")) { report_prefix_push(argv[1]); test_its_migration(); - migrate_once(); report_prefix_pop(); } else if (!strcmp(argv[1], "its-pending-migration")) { report_prefix_push(argv[1]); test_its_pending_migration(); - migrate_once(); report_prefix_pop(); } else if (!strcmp(argv[1], "its-migrate-unmapped-collection")) { report_prefix_push(argv[1]); test_migrate_unmapped_collection(); - migrate_once(); report_prefix_pop(); } else if (strcmp(argv[1], "its-introspection") == 0) { report_prefix_push(argv[1]); diff --git a/s390x/migration-cmm.c b/s390x/migration-cmm.c index 43673f18e..b4043a80e 100644 --- a/s390x/migration-cmm.c +++ b/s390x/migration-cmm.c @@ -55,12 +55,12 @@ int main(void) { report_prefix_push("migration-cmm"); - if (!check_essa_available()) + if (!check_essa_available()) { report_skip("ESSA is not available"); - else + migrate_skip(); + } else { test_migration(); - - migrate_once(); + } report_prefix_pop(); return report_summary(); diff --git a/s390x/migration-skey.c b/s390x/migration-skey.c index 8d6d8ecfe..1a196ae1e 100644 --- a/s390x/migration-skey.c +++ b/s390x/migration-skey.c @@ -169,6 +169,7 @@ static void test_skey_migration_parallel(void) if (smp_query_num_cpus() == 1) { report_skip("need at least 2 cpus for this test"); + migrate_skip(); goto error; } @@ -233,6 +234,7 @@ int main(int argc, char **argv) if (test_facility(169)) { report_skip("storage key removal facility is active"); + migrate_skip(); goto error; } @@ -247,11 +249,11 @@ int main(int argc, char **argv) break; default: print_usage(); + migrate_skip(); break; } error: - migrate_once(); report_prefix_pop(); return report_summary(); } diff --git a/s390x/migration.c b/s390x/migration.c index 269e272de..115afb731 100644 --- a/s390x/migration.c +++ b/s390x/migration.c @@ -164,6 +164,7 @@ int main(void) if (smp_query_num_cpus() == 1) { report_skip("need at least 2 cpus for this test"); + migrate_skip(); goto done; } From patchwork Tue Mar 19 07:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=URplWMMK; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPNB3Hvdz1yWn for ; Tue, 19 Mar 2024 19:02:50 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=URplWMMK; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPNB28zjz3vhr for ; Tue, 19 Mar 2024 19:02:50 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=URplWMMK; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::430; helo=mail-pf1-x430.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 4TzPJr2BRFz3dVK for ; Tue, 19 Mar 2024 18:59:56 +1100 (AEDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6e6c0098328so4280999b3a.3 for ; Tue, 19 Mar 2024 00:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835194; x=1711439994; darn=lists.ozlabs.org; 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=iwiLL+39rNvTnl3S/NlQsxl8YV1cuqwJpTXMZpjU20o=; b=URplWMMKDG1IRgyBLBfBrifcl+5+AbiZ10io0SWTlATwf+bEi21wThzcv+NWXs2Em8 UoQTO+xZNINEWnuRXsZMrQUGpoA2y7Yo6EUvnIXik7Mb4T0I/wv9CjoP/HJpmXI4ZtXt wyhj2c3lcGWaQ80hvObRrG/1AvHKYYlbfUFaSXzo4yPoynbedxUdLZ5ciaOAhPj6RS0/ SZayo5WyPhHjm5JvFLYU2jdxDNZuo/IjIvUP1bbHEP6d749cfJO/MKjFMaP8nzYr1u0t SS6ZcM+XiGao0PGpu/FnaOzUkhJCZcy9sETpsXfj5mkkBdPNwfJ/FHvnSgOkRRQk7xVF pgrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835194; x=1711439994; 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=iwiLL+39rNvTnl3S/NlQsxl8YV1cuqwJpTXMZpjU20o=; b=jbMS5wQ71E9XSamKfk7h8vtruKgoq4OS8uDQrKFXgepUZveYxq0n7LsD875fNKSM15 wVeFb2CH8qRjfutwHjZHzBd67/FwYe2+FQtF3e4BGBFWCLbeRu9DQFEStDc27PzoWtj1 X5ZKyACkUoXwm38gp+mV0pfQ3aOhnZEozwrq/Bfrx54eNTFyGOFrgoFsLgaKOhWGtQ+l kBGlFjVQxFmhBBeHUqXytBCSY91giG3bs5Gb/0OFieT6o2isu+XyviDHt/E2dobE/F3x JKHArGu3h6Sc9sqHhWrAmc0EZFjdpZqqTEs9MpHd0Uc9LokOSfi+GQXB51y5TxAeYo78 Ix3Q== X-Forwarded-Encrypted: i=1; AJvYcCVyRbM30FzBCfhb8uAPv/+Bbp6LpihVysoIJ/inGZwvdwpjO1Rv7zekFUBBDAWeheKlqlWGeysLC0ZkXOd6TtGXliRCcLPTMT6N2jaZ1A== X-Gm-Message-State: AOJu0YzHJfmbPLgdswy7GN4etb2P+AR4Gu8VJRB7ZHPSM80ZG/sIyB0F wYpOs5N8dv5/e1TgdiyLK0sDTweEQ5VYtUg7bpn2leFIj0UAcOp1xriApVx5t4A= X-Google-Smtp-Source: AGHT+IF9J5BfMuicYhHFmGj3QmDkgtilbahQgsH/XQQp9Mr0YY71rN0t/oPLgM3FmJxBPiyt5H8umA== X-Received: by 2002:a05:6a00:844:b0:6e6:fb34:2568 with SMTP id q4-20020a056a00084400b006e6fb342568mr2080064pfk.0.1710835193686; Tue, 19 Mar 2024 00:59:53 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.00.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 00:59:53 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 05/35] arch-run: Add a "continuous" migration option for tests Date: Tue, 19 Mar 2024 17:58:56 +1000 Message-ID: <20240319075926.2422707-6-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The cooperative migration protocol is very good to control precise pre and post conditions for a migration event. However in some cases its intrusiveness to the test program, can mask problems and make analysis more difficult. For example to stress test migration vs concurrent complicated memory access, including TLB refill, ram dirtying, etc., then the tight spin at getchar() and resumption of the workload after migration is unhelpful. This adds a continuous migration mode that directs the harness to perform migrations continually. This is added to the migration selftests, which also sees cooperative migration iterations reduced to avoid increasing test time too much. Signed-off-by: Nicholas Piggin --- common/selftest-migration.c | 16 +++++++++-- lib/migrate.c | 18 ++++++++++++ lib/migrate.h | 3 ++ scripts/arch-run.bash | 55 ++++++++++++++++++++++++++++++++----- 4 files changed, 82 insertions(+), 10 deletions(-) diff --git a/common/selftest-migration.c b/common/selftest-migration.c index 0afd8581c..9a9b61835 100644 --- a/common/selftest-migration.c +++ b/common/selftest-migration.c @@ -9,12 +9,13 @@ */ #include #include +#include -#define NR_MIGRATIONS 30 +#define NR_MIGRATIONS 15 int main(int argc, char **argv) { - report_prefix_push("migration"); + report_prefix_push("migration harness"); if (argc > 1 && !strcmp(argv[1], "skip")) { migrate_skip(); @@ -24,7 +25,16 @@ int main(int argc, char **argv) for (i = 0; i < NR_MIGRATIONS; i++) migrate_quiet(); - report(true, "simple harness stress"); + report(true, "cooperative migration"); + + migrate_begin_continuous(); + mdelay(2000); + migrate_end_continuous(); + mdelay(1000); + migrate_begin_continuous(); + mdelay(2000); + migrate_end_continuous(); + report(true, "continuous migration"); } report_prefix_pop(); diff --git a/lib/migrate.c b/lib/migrate.c index 1d22196b7..770f76d5c 100644 --- a/lib/migrate.c +++ b/lib/migrate.c @@ -60,3 +60,21 @@ void migrate_skip(void) puts("Skipped VM migration (quiet)\n"); (void)getchar(); } + +void migrate_begin_continuous(void) +{ + puts("Begin continuous migration\n"); + (void)getchar(); +} + +void migrate_end_continuous(void) +{ + /* + * Migration can split this output between source and dest QEMU + * output files, print twice and match once to always cope with + * a split. + */ + puts("End continuous migration\n"); + puts("End continuous migration (quiet)\n"); + (void)getchar(); +} diff --git a/lib/migrate.h b/lib/migrate.h index db6e0c501..35b6703a2 100644 --- a/lib/migrate.h +++ b/lib/migrate.h @@ -11,3 +11,6 @@ void migrate_quiet(void); void migrate_once(void); void migrate_skip(void); + +void migrate_begin_continuous(void); +void migrate_end_continuous(void); diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 4a1aab48d..1901a929f 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -125,15 +125,17 @@ qmp_events () filter_quiet_msgs () { grep -v "Now migrate the VM (quiet)" | + grep -v "Begin continuous migration (quiet)" | + grep -v "End continuous migration (quiet)" | grep -v "Skipped VM migration (quiet)" } seen_migrate_msg () { if [ $skip_migration -eq 1 ]; then - grep -q -e "Now migrate the VM" < $1 + grep -q -e "Now migrate the VM" -e "Begin continuous migration" < $1 else - grep -q -e "Now migrate the VM" -e "Skipped VM migration" < $1 + grep -q -e "Now migrate the VM" -e "Begin continuous migration" -e "Skipped VM migration" < $1 fi } @@ -161,6 +163,7 @@ run_migration () src_qmpout=/dev/null dst_qmpout=/dev/null skip_migration=0 + continuous_migration=0 mkfifo ${src_outfifo} mkfifo ${dst_outfifo} @@ -186,9 +189,12 @@ run_migration () do_migration || return $? while ps -p ${live_pid} > /dev/null ; do - # Wait for test exit or further migration messages. - if ! seen_migrate_msg ${src_out} ; then + if [ ${continuous_migration} -eq 1 ] ; then + do_migration || return $? + elif ! seen_migrate_msg ${src_out} ; then sleep 0.1 + elif grep -q "Begin continuous migration" < ${src_out} ; then + do_migration || return $? elif grep -q "Now migrate the VM" < ${src_out} ; then do_migration || return $? elif [ $skip_migration -eq 0 ] && grep -q "Skipped VM migration" < ${src_out} ; then @@ -218,7 +224,7 @@ do_migration () # The test must prompt the user to migrate, so wait for the # "Now migrate VM" or similar console message. - while ! seen_migrate_msg ${src_out} ; do + while [ ${continuous_migration} -eq 0 ] && ! seen_migrate_msg ${src_out} ; do if ! ps -p ${live_pid} > /dev/null ; then echo > ${dst_infifo} qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null @@ -229,12 +235,32 @@ do_migration () sleep 0.1 done + if grep -q "Begin continuous migration" < ${src_out} ; then + if [ ${continuous_migration} -eq 1 ] ; then + echo > ${dst_infifo} + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null + echo "ERROR: Continuous migration already begun." >&2 + qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null + return 3 + fi + continuous_migration=1 + echo > ${src_infifo} + fi + # Wait until the destination has created the incoming and qmp sockets while ! [ -S ${dst_incoming} ] ; do sleep 0.1 ; done while ! [ -S ${dst_qmp} ] ; do sleep 0.1 ; done if [ $skip_migration -eq 0 ] && grep -q "Skipped VM migration" < ${src_out} ; then # May not get any migrations, exit to main loop for now... + # No migrations today, shut down dst in an orderly manner... + if [ ${continuous_migration} -eq 1 ] ; then + echo > ${dst_infifo} + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null + echo "ERROR: Can't skip in continuous migration." >&2 + qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null + return 3 + fi echo > ${dst_infifo} qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null echo > ${src_infifo} # Resume src and carry on. @@ -266,8 +292,23 @@ do_migration () qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null - # keypress to dst so getchar completes and test continues - echo > ${dst_infifo} + # Should we end continuous migration? + if grep -q "End continuous migration" < ${src_out} ; then + if [ ${continuous_migration} -eq 0 ] ; then + echo "ERROR: Can't end continuous migration when not started." >&2 + echo > ${dst_infifo} + qmp ${dst_qmp} '"quit"'> ${dst_qmpout} 2>/dev/null + qmp ${src_qmp} '"quit"'> ${src_qmpout} 2>/dev/null + return 3 + fi + continuous_migration=0 + echo > ${src_infifo} + fi + + if [ ${continuous_migration} -eq 0 ]; then + # keypress to dst so getchar completes and test continues + echo > ${dst_infifo} + fi # Wait for the incoming socket being removed, ready for next destination while [ -S ${dst_incoming} ] ; do sleep 0.1 ; done From patchwork Tue Mar 19 07:58:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JttvvOL+; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPPv6DY4z1yWn for ; Tue, 19 Mar 2024 19:04:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JttvvOL+; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPPv3lrNz3vYh for ; Tue, 19 Mar 2024 19:04:19 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=JttvvOL+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42c; helo=mail-pf1-x42c.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 4TzPJw08qQz3dVf for ; Tue, 19 Mar 2024 18:59:59 +1100 (AEDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e6b5432439so5041061b3a.1 for ; Tue, 19 Mar 2024 00:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835197; x=1711439997; darn=lists.ozlabs.org; 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=cYcSW/ibSMj6iVuV1sk8Zdj3J66OqbMWoQwMjKPP3FU=; b=JttvvOL+eZ3qV0KeCDKs9PbUIDHAN/6np/7xupwGnfqmAs6SaQigA26aMlrXZJN67x bOrCHXGoWh+tMACfOINNl6C8dmG9E1QST8h8FDcnEZRtEiFgCK+UkLhHYMVUsqpSTi1/ v4dqupVbbckcMvTGmRhhYRBXPEnCPl3H0+H/1Y9JKC9LAz4i7U/Q1HTnYEGRC43UCgGX EtidFC2vKAE5SLEusc1jgJmTX6Wvb7iJgZ+O4yrhxUU/Y8i5GfHN+K2Hs7S8XtxgvMdE Y3r8EsZ4s5LErO37CdFdjYLNgz/U7Dlqe8j6iIcUmdEB/wMDM8mVkVeAg8ppVRIGU2cr C8KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835197; x=1711439997; 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=cYcSW/ibSMj6iVuV1sk8Zdj3J66OqbMWoQwMjKPP3FU=; b=uqbvLeCZww1IFk199OkzcRO80V7flWzJFz25lx7SuoSgay+Kv2XXmVd6jYHvgrsl7+ +TcClhS6VGQohYCbXUw4K8vLUnF39TeXyeYY0Nr+P4UvGp6Ckzai08yzixwPUPbg/i92 ByNAALqzFp9hzxJTfpul0XPsF/bFJOyA7A8p1OeVailM5jiygEdYwabQNnzG6UAnYBI/ rOwWCXoQT2ZeKSFayECuAD3oUpg29Fw1AxMRMebPUnn93WWwok7BFAHF5HL/3O7CxqJc lSsKEgmgv/gFgFRlc4TlBN8+JCvt5TwWkbJKH9UjyQjkXyIngSmRjEbfQorEk6rTHu5d d7RA== X-Forwarded-Encrypted: i=1; AJvYcCVQPl48BiyVXoS/W6bKhZ67dcEJ07YVzQ+SIMRVeUUx4S+NE0ruiRbBgiK8n/zHV3/5Bci5ExSKJ4xpCMU5o1Vd53oc1VfOxFN2PHZOYA== X-Gm-Message-State: AOJu0YxuZ7LdnLOE2vZSrO4iswwF1Ixo9nFl6XkL+DlsTZUmYpsvk6Gs 3hceMzw4o6wETQ98H+6fuf7i5nYQI8ikD1K/10w50deK3XZlAWOy X-Google-Smtp-Source: AGHT+IFMGBRGfTdm1Xi8PAhIoZeRYeQWIYa6zNRyD2io/DMVYPLb1oYyq/AdJHPXtgA/PjJTjuJEng== X-Received: by 2002:a05:6a00:2309:b0:6e6:bb2b:882c with SMTP id h9-20020a056a00230900b006e6bb2b882cmr16430185pfh.13.1710835197183; Tue, 19 Mar 2024 00:59:57 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.00.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 00:59:57 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 06/35] gitlab-ci: Run migration selftest on s390x and powerpc Date: Tue, 19 Mar 2024 17:58:57 +1000 Message-ID: <20240319075926.2422707-7-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The migration harness is complicated and easy to break so CI will be helpful. Signed-off-by: Nicholas Piggin --- .gitlab-ci.yml | 18 +++++++++++------- s390x/unittests.cfg | 8 ++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ff34b1f50..bd34da04f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -92,26 +92,28 @@ build-arm: build-ppc64be: extends: .outoftree_template script: - - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu + - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat - mkdir build - cd build - ../configure --arch=ppc64 --endian=big --cross-prefix=powerpc64-linux-gnu- - make -j2 - ACCEL=tcg ./run_tests.sh - selftest-setup spapr_hcall rtas-get-time-of-day rtas-get-time-of-day-base - rtas-set-time-of-day emulator + selftest-setup selftest-migration selftest-migration-skip spapr_hcall + rtas-get-time-of-day rtas-get-time-of-day-base rtas-set-time-of-day + emulator | tee results.txt - if grep -q FAIL results.txt ; then exit 1 ; fi build-ppc64le: extends: .intree_template script: - - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu + - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat - ./configure --arch=ppc64 --endian=little --cross-prefix=powerpc64-linux-gnu- - make -j2 - ACCEL=tcg ./run_tests.sh - selftest-setup spapr_hcall rtas-get-time-of-day rtas-get-time-of-day-base - rtas-set-time-of-day emulator + selftest-setup selftest-migration selftest-migration-skip spapr_hcall + rtas-get-time-of-day rtas-get-time-of-day-base rtas-set-time-of-day + emulator | tee results.txt - if grep -q FAIL results.txt ; then exit 1 ; fi @@ -135,7 +137,7 @@ build-riscv64: build-s390x: extends: .outoftree_template script: - - dnf install -y qemu-system-s390x gcc-s390x-linux-gnu + - dnf install -y qemu-system-s390x gcc-s390x-linux-gnu nmap-ncat - mkdir build - cd build - ../configure --arch=s390x --cross-prefix=s390x-linux-gnu- @@ -161,6 +163,8 @@ build-s390x: sclp-1g sclp-3g selftest-setup + selftest-migration-kvm + selftest-migration-skip sieve smp stsi diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 49e3e4608..b79b99416 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -31,6 +31,14 @@ groups = selftest migration # https://lore.kernel.org/qemu-devel/20240219061731.232570-1-npiggin@gmail.com/ accel = kvm +[selftest-migration-kvm] +file = selftest-migration.elf +groups = nodefault +accel = kvm +# This is a special test for gitlab-ci that can must not use TCG until the +# TCG migration fix has made its way into CI environment's QEMU. +# https://lore.kernel.org/qemu-devel/20240219061731.232570-1-npiggin@gmail.com/ + [selftest-migration-skip] file = selftest-migration.elf groups = selftest migration From patchwork Tue Mar 19 07:58:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=eN3PLoiT; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPQh6ZQLz1yWn for ; Tue, 19 Mar 2024 19:05:00 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=eN3PLoiT; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPQh5Xntz3vk5 for ; Tue, 19 Mar 2024 19:05:00 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=eN3PLoiT; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::229; helo=mail-oi1-x229.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (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 4TzPK020Y3z3dWS for ; Tue, 19 Mar 2024 19:00:04 +1100 (AEDT) Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3c3775ce48fso2702789b6e.2 for ; Tue, 19 Mar 2024 01:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835201; x=1711440001; darn=lists.ozlabs.org; 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=yeFiA3EfY+1JD1RuYQnw5HbvsQt45vIrT0LQVWviu8g=; b=eN3PLoiTJRgrnlVUf+zLxRdgpQRleqwnQx1O35lgZ+uIGeUm3ZnCyOE65ce2DyPts6 lW9mTQ3FlEcGgVpA6Go/Q0Wr3dPc1GTMmJ1wEQgOQqMs19stkWmivHrFlinhEVuu+OGy u35M5v7HpCRrlxOs2RBcXWb9M6Ms9PYZSGx8o2AFPGy1cDRzYg4s+Su0qrS0w0G8wJ53 XAHS/l/1KG+zPZQ5T7Z+KKuHUpeTpiCIJLMmHSDP55Ki/jD9Hoh2trloGHI4UM60zKxI E9DzG0WsfqALB27KklvcPU24g5snnaIhLz8huB0xGSsXV1awV265N+LTwyr/18S2I3Im pThw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835201; x=1711440001; 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=yeFiA3EfY+1JD1RuYQnw5HbvsQt45vIrT0LQVWviu8g=; b=VKP0MyGtTIsEGb4lukMhAqaBtpa8D1Jdv4MHxh8OOqaDNqmq3SdKT1EdLY0VtL29Qr cl/t4cNbc4qEuuHHEwQlS5Eun6rBsZxmhbvQECNEi46JytLGoL5h/vO5CYvJ+4X5Ca6P Y4NfRw2aKL6fYz6H1PN2pAtOVM+FwoP7/g4HdEwfAn008x7708Q1c6endWAHBO7m5bT9 YemYbM5gJSIp9Dr27uUkE+VrTQ/Use5vk7xuEWX1uO6PmFamIXzpZteL7FzyOnfkVYhb kSzN+GfZ2I3DSqvn3SuKE+Tp71pcpFPR/DWGsF+K347IHUYdkjQA3KY8j4/xqtKgh9i8 iQ+g== X-Forwarded-Encrypted: i=1; AJvYcCVi0xaXGAu2Qqr8QlG0YZrgdPJuYdOeZmKju7rVU2jQyNQrjkUisS22QaZ/9PBXrm0in6AwA5AkCeCVgoKQhQJ3CrJH/GRwJqhLenVG1w== X-Gm-Message-State: AOJu0YxSl+LhQnz207fmdwxJgKESgFhVzVGo5zw+zVhOO0EK60Y94X16 dDouCZY0Ykg/FaVuE3BciRWjCdX/SsJ2naUdEiCo9JRYmq80ge52 X-Google-Smtp-Source: AGHT+IEKjVgOynnGlounTLvOmvJWwFgatUFePuOrHk3/ueXtGI7nUei9T7Qa+BG/xrhoE5qSdYaWUg== X-Received: by 2002:a05:6808:1b24:b0:3c3:8540:8641 with SMTP id bx36-20020a0568081b2400b003c385408641mr6963268oib.9.1710835200772; Tue, 19 Mar 2024 01:00:00 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.00.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:00 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 07/35] common: add memory dirtying vs migration test Date: Tue, 19 Mar 2024 17:58:58 +1000 Message-ID: <20240319075926.2422707-8-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This test stores to a bunch of pages and verifies previous stores, while being continually migrated. Default runtime is 5 seconds. Add this test to ppc64 and s390x builds. This can fail due to a QEMU TCG physical memory dirty bitmap bug, so it is not enabled in unittests for TCG yet. The selftest-migration test time is reduced significantly because this test Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- common/memory-verify.c | 67 +++++++++++++++++++++++++++++++++++++ common/selftest-migration.c | 8 ++--- powerpc/Makefile.common | 1 + powerpc/memory-verify.c | 1 + powerpc/unittests.cfg | 7 ++++ s390x/Makefile | 1 + s390x/memory-verify.c | 1 + s390x/unittests.cfg | 6 ++++ 8 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 common/memory-verify.c create mode 120000 powerpc/memory-verify.c create mode 120000 s390x/memory-verify.c diff --git a/common/memory-verify.c b/common/memory-verify.c new file mode 100644 index 000000000..e78fb4338 --- /dev/null +++ b/common/memory-verify.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Simple memory verification test, used to exercise dirty memory migration. + */ +#include +#include +#include +#include +#include + +#define NR_PAGES 32 + +static unsigned time_sec = 5; + +static void do_getopts(int argc, char **argv) +{ + int i; + + for (i = 0; i < argc; ++i) { + if (strcmp(argv[i], "-t") == 0) { + i++; + if (i == argc) + break; + time_sec = atol(argv[i]); + } + } + + printf("running for %d secs\n", time_sec); +} + +int main(int argc, char **argv) +{ + void *mem = malloc(NR_PAGES*PAGE_SIZE); + bool success = true; + uint64_t ms; + long i; + + do_getopts(argc, argv); + + report_prefix_push("memory"); + + memset(mem, 0, NR_PAGES*PAGE_SIZE); + + migrate_begin_continuous(); + ms = get_clock_ms(); + i = 0; + do { + int j; + + for (j = 0; j < NR_PAGES*PAGE_SIZE; j += PAGE_SIZE) { + if (*(volatile long *)(mem + j) != i) { + success = false; + goto out; + } + *(volatile long *)(mem + j) = i + 1; + } + i++; + } while (get_clock_ms() - ms < time_sec * 1000); +out: + migrate_end_continuous(); + + report(success, "memory verification stress test"); + + report_prefix_pop(); + + return report_summary(); +} diff --git a/common/selftest-migration.c b/common/selftest-migration.c index 9a9b61835..3693148aa 100644 --- a/common/selftest-migration.c +++ b/common/selftest-migration.c @@ -11,7 +11,7 @@ #include #include -#define NR_MIGRATIONS 15 +#define NR_MIGRATIONS 5 int main(int argc, char **argv) { @@ -28,11 +28,11 @@ int main(int argc, char **argv) report(true, "cooperative migration"); migrate_begin_continuous(); - mdelay(2000); - migrate_end_continuous(); mdelay(1000); + migrate_end_continuous(); + mdelay(500); migrate_begin_continuous(); - mdelay(2000); + mdelay(1000); migrate_end_continuous(); report(true, "continuous migration"); } diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index da4a7bbb8..1e181da69 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -7,6 +7,7 @@ tests-common = \ $(TEST_DIR)/selftest.elf \ $(TEST_DIR)/selftest-migration.elf \ + $(TEST_DIR)/memory-verify.elf \ $(TEST_DIR)/spapr_hcall.elf \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ diff --git a/powerpc/memory-verify.c b/powerpc/memory-verify.c new file mode 120000 index 000000000..5985c730f --- /dev/null +++ b/powerpc/memory-verify.c @@ -0,0 +1 @@ +../common/memory-verify.c \ No newline at end of file diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index cae4949e8..e65217c18 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -49,6 +49,13 @@ machine = pseries groups = selftest migration extra_params = -append "skip" +# This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream +[migration-memory] +file = memory-verify.elf +accel = kvm +machine = pseries +groups = migration + [spapr_hcall] file = spapr_hcall.elf diff --git a/s390x/Makefile b/s390x/Makefile index 344d46d68..ddc0969f3 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -1,5 +1,6 @@ tests = $(TEST_DIR)/selftest.elf tests += $(TEST_DIR)/selftest-migration.elf +tests += $(TEST_DIR)/memory-verify.elf tests += $(TEST_DIR)/intercept.elf tests += $(TEST_DIR)/emulator.elf tests += $(TEST_DIR)/sieve.elf diff --git a/s390x/memory-verify.c b/s390x/memory-verify.c new file mode 120000 index 000000000..5985c730f --- /dev/null +++ b/s390x/memory-verify.c @@ -0,0 +1 @@ +../common/memory-verify.c \ No newline at end of file diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index b79b99416..550eff787 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -44,6 +44,12 @@ file = selftest-migration.elf groups = selftest migration extra_params = -append "skip" +# This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream +[migration-memory] +file = memory-verify.elf +accel = kvm +groups = migration + [intercept] file = intercept.elf From patchwork Tue Mar 19 07:58:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jvXzeiFt; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPRV2Zpyz1yWs for ; Tue, 19 Mar 2024 19:05:42 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jvXzeiFt; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPRV1NLnz3vlP for ; Tue, 19 Mar 2024 19:05:42 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=jvXzeiFt; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::336; helo=mail-ot1-x336.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) (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 4TzPK373kLz3dRp for ; Tue, 19 Mar 2024 19:00:07 +1100 (AEDT) Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6e67451b084so2921172a34.2 for ; Tue, 19 Mar 2024 01:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835204; x=1711440004; darn=lists.ozlabs.org; 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=Een3HCEHuSXtESOmVVoN9fReFwtOgW3Iul9yQ4dmcnU=; b=jvXzeiFtgOfTiATeMoxythPpUWmaF/AyhOb+NJSRne4t/vDT4rFtVt/Ny8kAKndj8x bI/w3AbvLsNyWWyWnSlMy6749nlU1zZECpsSLNzrns2x5hj4KNXiGiGXwmvDpCkl+1EU GsbPGrib4OPhjOspLH9cs6cNz+NTIZmE+AK/cGhHpRR09miPzfuogn9d/eVdFNVZHO/Y tHLePtGbxMplz4JeKxWS1+gTFdN9AnpbXv3iF31sBfGs+okBlP8TgmUGtpN7hhxF6SHe +AVLKkajGHNrWcSb4mDpuRpMAN5q2EIC+eX9aDfywZgskN63Kd/tAJAH7MC3VcbVKrF1 X8Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835204; x=1711440004; 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=Een3HCEHuSXtESOmVVoN9fReFwtOgW3Iul9yQ4dmcnU=; b=aQPFwIEkXB9fTIM9GHszaOjKXLBy2+m5sDRyscVvH2b8VdHLFt8M5afwi1yitZgROx xLa226+vKpx4RM4qB67SHJWkHdRkdpvWeSKGb1QHCu2tnUN6DzbT7o54OrMyNJCExtZL YPa17Vn2CK3sB7EZv0PnT+JEka4RnbeVbCRaReZGe3MsTW6eBrpYm9eZHWJBvVpnTvlu NkCMFbf8aPX/x+6BIHqVzzLN3Wjg+gZo7oV/95uvmm7axqgjTxNDQ+WHZUPEQZ3kSWoz RjglUDLqYsnDpUiBjAs4XujO9mbz86I09RU/nbQrV9Wel5JfLjx7HW/QG+6ByqtbTHqZ 0TYg== X-Forwarded-Encrypted: i=1; AJvYcCVgi3L42OT8cVAWBlpECmIWExc3Zwtoyt3aw+FxspQApIu2jhE9Cu/Ggt6JLLzhYppNxD9bZOCac2IpICAWkoqK3lklGczyITkaLxidqQ== X-Gm-Message-State: AOJu0YzL7vpQhMtOKcCjDAzZs8lPWCXsuVORNMnRnDt38Y9QEv/Ykeuv /4FGq64R+gnQimAuadUmZh0KhdTtcyf3me8guQ3xP6naWid67cpu4Wl+g19+CYU= X-Google-Smtp-Source: AGHT+IE6pXL3TbQuF53EpPTbvzqyaweI3wiT6cAyH+5pKuELD5LZX4DmnMUsiZUZa3mX+J/Y3Z8pRQ== X-Received: by 2002:a05:6870:b6a6:b0:222:342a:10fd with SMTP id cy38-20020a056870b6a600b00222342a10fdmr17760520oab.5.1710835204416; Tue, 19 Mar 2024 01:00:04 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:04 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 08/35] powerpc: Fix KVM caps on POWER9 hosts Date: Tue, 19 Mar 2024 17:58:59 +1000 Message-ID: <20240319075926.2422707-9-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" KVM does not like to run on POWER9 hosts without cap-ccf-assist=off. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- powerpc/run | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powerpc/run b/powerpc/run index e469f1eb3..5cdb94194 100755 --- a/powerpc/run +++ b/powerpc/run @@ -24,6 +24,8 @@ M+=",accel=$ACCEL$ACCEL_PROPS" if [[ "$ACCEL" == "tcg" ]] ; then M+=",cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off" +elif [[ "$ACCEL" == "kvm" ]] ; then + M+=",cap-ccf-assist=off" fi command="$qemu -nodefaults $M -bios $FIRMWARE" From patchwork Tue Mar 19 07:59:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FwsNVywA; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPSH2Dfvz1yWs for ; Tue, 19 Mar 2024 19:06:23 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FwsNVywA; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPSH196Hz3vbV for ; Tue, 19 Mar 2024 19:06:23 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=FwsNVywA; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 4TzPK73Vb5z3d36 for ; Tue, 19 Mar 2024 19:00:11 +1100 (AEDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso3170352b3a.1 for ; Tue, 19 Mar 2024 01:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835209; x=1711440009; darn=lists.ozlabs.org; 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=Fndo0MEe/uD2EZQF5VsTSnetuecWQ7lAuCXwwSf7lcs=; b=FwsNVywA8ps095+gXo6CC4Fto/STxbGIeCPekJTaAv0HYcXwd5E/aVp+Tf+r+FbjhL JD8Di5ljrizCpPZJsFWtl9nnh1h0hoYqLx3CxPFmaycZaoNcwdwgmJtvhdUSFKGpWUg8 RMu4g3ATMlnL42HV4kIUne/PULUCo+NSpjJ/7+5biokKLs/kjLXlS9b8CFSk2jK3UTqd Y7754eFiZ11COjIgGWiYZ6iVPELOaTlX5OmnCxdfEgfioZMnAMqNuVckaHb6VVN1567w /LPtOK7P3s3iMk5OV/OljCTEnpnxbe1ud3iamgyWcUY4DBtxFrn0/80mEU7Dd37yzwGE 4JRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835209; x=1711440009; 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=Fndo0MEe/uD2EZQF5VsTSnetuecWQ7lAuCXwwSf7lcs=; b=g+wZobNjPGQY1dUCLJbYepw7Znd31EVu1pi8Xa6ybyVge7Hri/C9DHD1NuweUEHQYk HIb8Lnsp6DvX/RV3a/96EnJjN26JYDGKtNjPeMOWkmislG9hQ1963BVEpea09QGzpT1u u9kYrLEEzTNX08KeKrhdlhIvES8kC4iWZxrDrUIdAkSebrsZBWQfgNmSUhz1SYYUBnc1 zplZYAGPH8AbUTQy6ruV8mJt7ranT2kczwmZOxeMhUoFanioX1rAMUY/BK3VAavu0CwW K/2ZuG6DdQUTMUroFeHPUQMG8IccGn/Oo/iJWNABRsnsJbGXm4WMUvZggj5JCvv93vAm U3Cw== X-Forwarded-Encrypted: i=1; AJvYcCWfMooIVqxTRYpByDfiZrvBG7Xg39R3ldGUa8vuED7n4Iau67obD2snhFbWn51UKpesNM8Q4y+WsmrsDAZcR63iQ3Kre1t36SPWMldPlQ== X-Gm-Message-State: AOJu0YydzAG6yMiIo6IhdV1u2ZMi19lTCWl4vF3HY2tfcDQhm9RYhq6x 08JK3UMyrtmEbgh2ZxD6JB96ukgKn5Zgh0ro9Wn9QqfEpXPCtckN X-Google-Smtp-Source: AGHT+IFZbtU7rOQxkkj6cesJgK7vAzyFAtMiMK+nZ/sLlmWkv8FYDQnCfG7JqFhH5FkYWgLdW+bq5A== X-Received: by 2002:a05:6a00:cd2:b0:6e7:1cd9:c032 with SMTP id b18-20020a056a000cd200b006e71cd9c032mr2488662pfv.6.1710835208039; Tue, 19 Mar 2024 01:00:08 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:07 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 09/35] powerpc: Fix stack backtrace termination Date: Tue, 19 Mar 2024 17:59:00 +1000 Message-ID: <20240319075926.2422707-10-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The backtrace handler terminates when it sees a NULL caller address, but the powerpc stack setup does not keep such a NULL caller frame at the start of the stack. This happens to work on pseries because the memory at 0 is mapped and it contains 0 at the location of the return address pointer if it were a stack frame. But this is fragile, and does not work with powernv where address 0 contains firmware instructions. Use the existing dummy frame on stack as the NULL caller, and create a new frame on stack for the entry code. Signed-off-by: Nicholas Piggin --- powerpc/cstart64.S | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index e18ae9a22..80baabe8f 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -46,6 +46,21 @@ start: add r1, r1, r31 add r2, r2, r31 + /* Zero backpointers in initial stack frame so backtrace() stops */ + li r0,0 + std r0,0(r1) + std r0,16(r1) + + /* + * Create entry frame of 64-bytes, same as the initial frame. A callee + * may use the caller frame to store LR, and backtrace() termination + * looks for return address == NULL, so the initial stack frame can't + * be used to call C or else it could overwrite the zeroed LR save slot + * and break backtrace termination. This frame would be unnecessary if + * backtrace looked for a zeroed frame address. + */ + stdu r1,-64(r1) + /* save DTB pointer */ std r3, 56(r1) From patchwork Tue Mar 19 07:59:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XbxhVJhC; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPTC66XXz1yWs for ; Tue, 19 Mar 2024 19:07:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XbxhVJhC; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPTC52vbz3vp9 for ; Tue, 19 Mar 2024 19:07:11 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=XbxhVJhC; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::432; helo=mail-pf1-x432.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (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 4TzPKB5FTdz3dVp for ; Tue, 19 Mar 2024 19:00:14 +1100 (AEDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6e6b54a28d0so3968032b3a.2 for ; Tue, 19 Mar 2024 01:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835212; x=1711440012; darn=lists.ozlabs.org; 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=Id22OkJ20G4vUjLZJ8P1mh+xH6ux/SpttyO50Hmp/l8=; b=XbxhVJhCuU4SUFTgxxhkFeZ4hQWYpqp0KX897Kxlbo7RL67KkvaRQZh3iOgU5i0v09 bqsHNdYzBV8R/6tWqVNW7y8zJqyqwneifEBJxYkLP1NuYxqv7VZafIoB2BdHkiC4n8wP DA8csM97xtiYTIGfijul7tUJuiC95/RfMyiI8IWO8/a7h7hUdw2tFn8+CRqYAykMNwy5 TvTkGaN0o5+xWVVp5q0yXHDM22B2UisAP773Q2fR+7DAT5KXl7Ta3n5aI1upkKTUuoQG 9X19ttNiDbpw3gzP2k415gebnzYkO3AYlV96LKaghNq646RHhKggcs3CENTbyZDOU6QA G8rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835212; x=1711440012; 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=Id22OkJ20G4vUjLZJ8P1mh+xH6ux/SpttyO50Hmp/l8=; b=PJMyFZv+9cn2fqMD6+md6S5qj3O45emqbaBU0oIW0+AcF3P80WvvvfqC8sOff2+Egi lb4aOQpKVkQR2RaObWaeO1kwAQQEH/bFMBPJqSZ3SmHZKCrcb01FLXfVrtoV1CX3d9bm EUGUHVOggZxMP+dCPFwkObzGdWkacaoKOTpyrX4iprMtetr+K6ub+zkZAimtjnGC7XEX gnK3EaZHx+5w8K4tbKRyEH0tFG9rY0ZBy+IoFlFssflLkUrVafp58taYl86AE1gf2p/I 4ec30zvky5XTZOqrpu4m5jDdz0h9tiQQdBzXhm6zugpetRQP7IKXj1OF1aL5bm+a8DjP 8aWg== X-Forwarded-Encrypted: i=1; AJvYcCXzkZsrP4SDj5dPl/Lu0KBzIF/dcsca66XONQ1MHffLI3rhcX4wOVeN+L3PFO4PNKu6E6kQ4Ls7Yj+OD6JjPrk/kkWXfgaM6C7wUU5Fxg== X-Gm-Message-State: AOJu0YxtD76AHfR2JOgCv9pgvidSWtQoeEDXoUOjDnPyOmFpeqKqmRnm z0QeqxzvvYS8xOFx1EY2AW4E2DyxXAEPST+zSa3tiuFzz5YZFrrZ X-Google-Smtp-Source: AGHT+IGSKzI6HlMM56ySu6oApKoM2roAqmMSDxssn9agceD2FwP7QjLSmoGGDgkqwBmJ7cIf+3cy2A== X-Received: by 2002:aa7:8883:0:b0:6e6:b32c:501d with SMTP id z3-20020aa78883000000b006e6b32c501dmr15756831pfe.19.1710835211651; Tue, 19 Mar 2024 01:00:11 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:11 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 10/35] powerpc: interrupt stack backtracing Date: Tue, 19 Mar 2024 17:59:01 +1000 Message-ID: <20240319075926.2422707-11-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add support for backtracing across interrupt stacks, and add interrupt frame backtrace for unhandled interrupts. This requires a back-chain created from initial interrupt stack frame to the r1 value of the interrupted context. A label is added at the return location of the exception handler call, so the unwinder can recognize the initial interrupt frame. The additional cstart entry-frame is no longer required because the unwinder now looks for frame == 0 as well as address == 0. Signed-off-by: Nicholas Piggin --- lib/powerpc/processor.c | 4 +++- lib/ppc64/asm/stack.h | 3 +++ lib/ppc64/stack.c | 53 +++++++++++++++++++++++++++++++++++++++++ powerpc/Makefile.ppc64 | 1 + powerpc/cstart64.S | 15 +++--------- 5 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 lib/ppc64/stack.c diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index ad0d95666..114584024 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -51,7 +51,9 @@ void do_handle_exception(struct pt_regs *regs) return; } - printf("unhandled cpu exception %#lx at NIA:0x%016lx MSR:0x%016lx\n", regs->trap, regs->nip, regs->msr); + printf("Unhandled cpu exception %#lx at NIA:0x%016lx MSR:0x%016lx\n", + regs->trap, regs->nip, regs->msr); + dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]); abort(); } diff --git a/lib/ppc64/asm/stack.h b/lib/ppc64/asm/stack.h index 9734bbb8f..94fd1021c 100644 --- a/lib/ppc64/asm/stack.h +++ b/lib/ppc64/asm/stack.h @@ -5,4 +5,7 @@ #error Do not directly include . Just use . #endif +#define HAVE_ARCH_BACKTRACE +#define HAVE_ARCH_BACKTRACE_FRAME + #endif diff --git a/lib/ppc64/stack.c b/lib/ppc64/stack.c new file mode 100644 index 000000000..e6f259de7 --- /dev/null +++ b/lib/ppc64/stack.c @@ -0,0 +1,53 @@ +#include +#include +#include + +extern char do_handle_exception_return[]; + +int arch_backtrace_frame(const void *frame, const void **return_addrs, + int max_depth, bool current_frame) +{ + static int walking; + int depth = 0; + const unsigned long *bp = (unsigned long *)frame; + void *return_addr; + + asm volatile("" ::: "lr"); /* Force it to save LR */ + + if (walking) { + printf("RECURSIVE STACK WALK!!!\n"); + return 0; + } + walking = 1; + + if (current_frame) + bp = __builtin_frame_address(0); + + bp = (unsigned long *)bp[0]; + return_addr = (void *)bp[2]; + + for (depth = 0; bp && depth < max_depth; depth++) { + return_addrs[depth] = return_addr; + if (return_addrs[depth] == 0) + break; + if (return_addrs[depth] == do_handle_exception_return) { + struct pt_regs *regs; + + regs = (void *)bp + STACK_FRAME_OVERHEAD; + bp = (unsigned long *)bp[0]; + /* Represent interrupt frame with vector number */ + return_addr = (void *)regs->trap; + if (depth + 1 < max_depth) { + depth++; + return_addrs[depth] = return_addr; + return_addr = (void *)regs->nip; + } + } else { + bp = (unsigned long *)bp[0]; + return_addr = (void *)bp[2]; + } + } + + walking = 0; + return depth; +} diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 index b0ed2b104..eb682c226 100644 --- a/powerpc/Makefile.ppc64 +++ b/powerpc/Makefile.ppc64 @@ -17,6 +17,7 @@ cstart.o = $(TEST_DIR)/cstart64.o reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 +cflatobjs += lib/ppc64/stack.o # ppc64 specific tests tests = $(TEST_DIR)/spapr_vpa.elf diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index 80baabe8f..07d297f61 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -51,16 +51,6 @@ start: std r0,0(r1) std r0,16(r1) - /* - * Create entry frame of 64-bytes, same as the initial frame. A callee - * may use the caller frame to store LR, and backtrace() termination - * looks for return address == NULL, so the initial stack frame can't - * be used to call C or else it could overwrite the zeroed LR save slot - * and break backtrace termination. This frame would be unnecessary if - * backtrace looked for a zeroed frame address. - */ - stdu r1,-64(r1) - /* save DTB pointer */ std r3, 56(r1) @@ -195,6 +185,7 @@ call_handler: .endr mfsprg1 r0 std r0,GPR1(r1) + std r0,0(r1) /* Backchain from interrupt stack to regular stack */ /* lr, xer, ccr */ @@ -213,12 +204,12 @@ call_handler: subi r31, r31, 0b - start_text ld r2, (p_toc_text - start_text)(r31) - /* FIXME: build stack frame */ - /* call generic handler */ addi r3,r1,STACK_FRAME_OVERHEAD bl do_handle_exception + .global do_handle_exception_return +do_handle_exception_return: /* restore context */ From patchwork Tue Mar 19 07:59:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hcgvwsPn; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPV06Slcz1yWs for ; Tue, 19 Mar 2024 19:07:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hcgvwsPn; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPV05R26z3dVX for ; Tue, 19 Mar 2024 19:07:52 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=hcgvwsPn; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42c; helo=mail-pf1-x42c.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 4TzPKF2NzGz3vX6 for ; Tue, 19 Mar 2024 19:00:17 +1100 (AEDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e6cadfffdbso4748140b3a.3 for ; Tue, 19 Mar 2024 01:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835215; x=1711440015; darn=lists.ozlabs.org; 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=YFuBo08DUaAz6ZvDhAEJB3wUvgXlATo9fgYTN1VzCLs=; b=hcgvwsPnhM/khmK5wJT5UCSxQwTBmZlxzudDYF1PkaV84jwFjxGcac9riO/u1bRvL8 uDKbU5zGJPz8F/eTjsshPVdqXyyGN3zPa0/IYFXN5CKaDQ7NmBUluOCXBK2WDmp3w7E/ umH0wbDRgFVbtHBK+EpY0x+nIHmczrYZAjU4eWbE3waV2WdxfDez6YxnO2nH01WwhGN5 OI0cHT2Y+hTDTQF2UsxHp1WDr40Ch7kdcrgNT35x+JpU8H4yeDCW4mRg+R2si5t2cCD4 bd5Guf3HAn0ZTNXu06pi1rqY2B0ehlNrlTJFGqafzkCoIyG9/MGhxyC+YiOqRmC/y25r ESgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835216; x=1711440016; 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=YFuBo08DUaAz6ZvDhAEJB3wUvgXlATo9fgYTN1VzCLs=; b=kkOn8oL4Be7AFPoW/MITT1CtE647ymo2hHGOpdtS5djwrlLAKHwGYVzbVwiTCxo+TR ebLYa86Cut9/pO2MRMH17WwCPSzK/V6AwhVKQITmMkBcsP4hqmsNT45ATFa710i8aSZX SKFZw6Md8OWoEAdo+gO6VMgsS0BNwGwIlcKb3z8Kpf00PFYnyCvZ0550bsRHsy92A5vs RSISC3I9KlBcQkDnEHNYj1SGVEuvEca41MuG6GOzm53R0daFiRdbmkp9yw7+PHKYSZ5f RldYP1ZMb0A7NtSK14MYtLtOONSTxXM4oZDaRCUBePEHicQWk5wxe1lYEtAv+M5ADysa jNfw== X-Forwarded-Encrypted: i=1; AJvYcCW0h/VaEPss4ro75oc8sHY8Nmh6b0OteA83cfep0oMUGZZDJa6txeaoNjHbpAL0CunDKDBynrSzbTnOntznt8ST07SDnhsKSIhs7YBqRQ== X-Gm-Message-State: AOJu0YzvWkFVkG9DfUWjutYfT7L091vpKuZI4lUeIPUGeZaqetnydkSr C81vhimmfq0c/QlchRVp1Ee/ES9989Wp8otzLxJ8scDtb1nqE081Xv6LFtsHu/w= X-Google-Smtp-Source: AGHT+IENpa8i7Hd5Xdb5+UPe9MXLCmjIg2awXprwcY21VxhPQIbh5LLo+PflfXT1t3rdgHjD8KzLqQ== X-Received: by 2002:a05:6a00:2f17:b0:6e6:f9b8:38eb with SMTP id fe23-20020a056a002f1700b006e6f9b838ebmr10416494pfb.21.1710835215502; Tue, 19 Mar 2024 01:00:15 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:15 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 11/35] powerpc/sprs: Specify SPRs with data rather than code Date: Tue, 19 Mar 2024 17:59:02 +1000 Message-ID: <20240319075926.2422707-12-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" A significant rework that builds an array of 'struct spr', where each element describes an SPR. This makes various metadata about the SPR like name and access type easier to carry and use. Hypervisor privileged registers are described despite not being used at the moment for completeness, but also the code might one day be reused for a hypervisor-privileged test. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/reg.h | 2 + powerpc/sprs.c | 647 +++++++++++++++++++++++++++++------------- 2 files changed, 457 insertions(+), 192 deletions(-) diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 6810c1d82..1f991288e 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -5,6 +5,8 @@ #define UL(x) _AC(x, UL) +#define SPR_SRR0 0x01a +#define SPR_SRR1 0x01b #define SPR_TB 0x10c #define SPR_SPRG0 0x110 #define SPR_SPRG1 0x111 diff --git a/powerpc/sprs.c b/powerpc/sprs.c index a19d80a1a..44edd0d7b 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -30,229 +30,458 @@ #include #include -uint64_t before[1024], after[1024]; - -/* Common SPRs for all PowerPC CPUs */ -static void set_sprs_common(uint64_t val) +/* "Indirect" mfspr/mtspr which accept a non-constant spr number */ +static uint64_t __mfspr(unsigned spr) { - mtspr(9, val); /* CTR */ - // mtspr(273, val); /* SPRG1 */ /* Used by our exception handler */ - mtspr(274, val); /* SPRG2 */ - mtspr(275, val); /* SPRG3 */ + uint64_t tmp; + uint64_t ret; + + asm volatile( +" bcl 20, 31, 1f \n" +"1: mflr %0 \n" +" addi %0, %0, (2f-1b) \n" +" add %0, %0, %2 \n" +" mtctr %0 \n" +" bctr \n" +"2: \n" +".LSPR=0 \n" +".rept 1024 \n" +" mfspr %1, .LSPR \n" +" b 3f \n" +" .LSPR=.LSPR+1 \n" +".endr \n" +"3: \n" + : "=&r"(tmp), + "=r"(ret) + : "r"(spr*8) /* 8 bytes per 'mfspr ; b' block */ + : "lr", "ctr"); + + return ret; } -/* SPRs from PowerPC Operating Environment Architecture, Book III, Vers. 2.01 */ -static void set_sprs_book3s_201(uint64_t val) +static void __mtspr(unsigned spr, uint64_t val) { - mtspr(18, val); /* DSISR */ - mtspr(19, val); /* DAR */ - mtspr(152, val); /* CTRL */ - mtspr(256, val); /* VRSAVE */ - mtspr(786, val); /* MMCRA */ - mtspr(795, val); /* MMCR0 */ - mtspr(798, val); /* MMCR1 */ + uint64_t tmp; + + asm volatile( +" bcl 20, 31, 1f \n" +"1: mflr %0 \n" +" addi %0, %0, (2f-1b) \n" +" add %0, %0, %2 \n" +" mtctr %0 \n" +" bctr \n" +"2: \n" +".LSPR=0 \n" +".rept 1024 \n" +" mtspr .LSPR, %1 \n" +" b 3f \n" +" .LSPR=.LSPR+1 \n" +".endr \n" +"3: \n" + : "=&r"(tmp) + : "r"(val), + "r"(spr*8) /* 8 bytes per 'mfspr ; b' block */ + : "lr", "ctr", "xer"); } +static uint64_t before[1024], after[1024]; + +#define SPR_PR_READ 0x0001 +#define SPR_PR_WRITE 0x0002 +#define SPR_OS_READ 0x0010 +#define SPR_OS_WRITE 0x0020 +#define SPR_HV_READ 0x0100 +#define SPR_HV_WRITE 0x0200 + +#define RW 0x333 +#define RO 0x111 +#define WO 0x222 +#define OS_RW 0x330 +#define OS_RO 0x110 +#define OS_WO 0x220 +#define HV_RW 0x300 +#define HV_RO 0x100 +#define HV_WO 0x200 + +#define SPR_ASYNC 0x1000 /* May be updated asynchronously */ +#define SPR_INT 0x2000 /* May be updated by synchronous interrupt */ +#define SPR_HARNESS 0x4000 /* Test harness uses the register */ + +struct spr { + const char *name; + uint8_t width; + uint16_t access; + uint16_t type; +}; + +/* SPRs common denominator back to PowerPC Operating Environment Architecture */ +static const struct spr sprs_common[1024] = { + [1] = { "XER", 64, RW, SPR_HARNESS, }, /* Used by compiler */ + [8] = { "LR", 64, RW, SPR_HARNESS, }, /* Compiler, mfspr/mtspr */ + [9] = { "CTR", 64, RW, SPR_HARNESS, }, /* Compiler, mfspr/mtspr */ + [18] = { "DSISR", 32, OS_RW, SPR_INT, }, + [19] = { "DAR", 64, OS_RW, SPR_INT, }, + [26] = { "SRR0", 64, OS_RW, SPR_INT, }, + [27] = { "SRR1", 64, OS_RW, SPR_INT, }, +[268] = { "TB", 64, RO , SPR_ASYNC, }, +[269] = { "TBU", 32, RO, SPR_ASYNC, }, +[272] = { "SPRG0", 64, OS_RW, SPR_HARNESS, }, /* Interrupt stacr */ +[273] = { "SPRG1", 64, OS_RW, SPR_HARNESS, }, /* Interrupt Scratch */ +[274] = { "SPRG2", 64, OS_RW, }, +[275] = { "SPRG3", 64, OS_RW, }, +[287] = { "PVR", 32, OS_RO, }, +}; + +/* SPRs from PowerPC Operating Environment Architecture, Book III, Vers. 2.01 */ +static const struct spr sprs_201[1024] = { + [22] = { "DEC", 32, OS_RW, SPR_ASYNC, }, + [25] = { "SDR1", 64, HV_RW | OS_RO, }, + [29] = { "ACCR", 64, OS_RW, }, +[136] = { "CTRL", 32, RO, }, +[152] = { "CTRL", 32, OS_WO, }, +[259] = { "SPRG3", 64, RO, }, +/* ASR, EAR omitted */ +[284] = { "TBL", 32, HV_WO, }, +[285] = { "TBU", 32, HV_WO, }, +[310] = { "HDEC", 32, HV_RW, SPR_ASYNC, }, +[1013]= { "DABR", 64, HV_RW | OS_RO, }, +[1023]= { "PIR", 32, OS_RO, SPR_ASYNC, }, /* Can't be virtualised, appears to be async */ +}; + +static const struct spr sprs_970_pmu[1024] = { +/* POWER4+ PMU, should confirm with PPC970 */ +[770] = { "MMCRA", 64, RO, }, +[771] = { "PMC1", 32, RO, }, +[772] = { "PMC2", 32, RO, }, +[773] = { "PMC3", 32, RO, }, +[774] = { "PMC4", 32, RO, }, +[775] = { "PMC5", 32, RO, }, +[776] = { "PMC6", 32, RO, }, +[777] = { "PMC7", 32, RO, }, +[778] = { "PMC8", 32, RO, }, +[779] = { "MMCR0", 64, RO, }, +[780] = { "SIAR", 64, RO, }, +[781] = { "SDAR", 64, RO, }, +[782] = { "MMCR1", 64, RO, }, +[786] = { "MMCRA", 64, OS_RW, }, +[787] = { "PMC1", 32, OS_RW, }, +[788] = { "PMC2", 32, OS_RW, }, +[789] = { "PMC3", 32, OS_RW, }, +[790] = { "PMC4", 32, OS_RW, }, +[791] = { "PMC5", 32, OS_RW, }, +[792] = { "PMC6", 32, OS_RW, }, +[793] = { "PMC7", 32, OS_RW, }, +[794] = { "PMC8", 32, OS_RW, }, +[795] = { "MMCR0", 64, OS_RW, }, +[796] = { "SIAR", 64, OS_RW, }, +[797] = { "SDAR", 64, OS_RW, }, +[798] = { "MMCR1", 64, OS_RW, }, +}; + +/* These are common SPRs from 2.07S onward (POWER CPUs that support KVM HV) */ +static const struct spr sprs_power_common[1024] = { + [3] = { "DSCR", 64, RW, }, + [13] = { "AMR", 64, RW, }, + [17] = { "DSCR", 64, OS_RW, }, + [28] = { "CFAR", 64, OS_RW, SPR_ASYNC, }, /* Effectively async */ + [29] = { "AMR", 64, OS_RW, }, + [61] = { "IAMR", 64, OS_RW, }, +[136] = { "CTRL", 32, RO, }, +[152] = { "CTRL", 32, OS_WO, }, +[153] = { "FSCR", 64, OS_RW, }, +[157] = { "UAMOR", 64, OS_RW, }, +[159] = { "PSPB", 32, OS_RW, }, +[176] = { "DPDES", 64, HV_RW | OS_RO, }, +[180] = { "DAWR0", 64, HV_RW, }, +[186] = { "RPR", 64, HV_RW, }, +[187] = { "CIABR", 64, HV_RW, }, +[188] = { "DAWRX0", 32, HV_RW, }, +[190] = { "HFSCR", 64, HV_RW, }, +[256] = { "VRSAVE", 32, RW, }, +[259] = { "SPRG3", 64, RO, }, +[284] = { "TBL", 32, HV_WO, }, +[285] = { "TBU", 32, HV_WO, }, +[286] = { "TBU40", 64, HV_WO, }, +[304] = { "HSPRG0", 64, HV_RW, }, +[305] = { "HSPRG1", 64, HV_RW, }, +[306] = { "HDSISR", 32, HV_RW, SPR_INT, }, +[307] = { "HDAR", 64, HV_RW, SPR_INT, }, +[308] = { "SPURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[309] = { "PURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[313] = { "HRMOR", 64, HV_RW, }, +[314] = { "HSRR0", 64, HV_RW, SPR_INT, }, +[315] = { "HSRR1", 64, HV_RW, SPR_INT, }, +[318] = { "LPCR", 64, HV_RW, }, +[319] = { "LPIDR", 32, HV_RW, }, +[336] = { "HMER", 64, HV_RW, }, +[337] = { "HMEER", 64, HV_RW, }, +[338] = { "PCR", 64, HV_RW, }, +[349] = { "AMOR", 64, HV_RW, }, +[446] = { "TIR", 64, OS_RO, }, +[800] = { "BESCRS", 64, RW, }, +[801] = { "BESCRSU", 32, RW, }, +[802] = { "BESCRR", 64, RW, }, +[803] = { "BESCRRU", 32, RW, }, +[804] = { "EBBHR", 64, RW, }, +[805] = { "EBBRR", 64, RW, }, +[806] = { "BESCR", 64, RW, }, +[815] = { "TAR", 64, RW, }, +[848] = { "IC", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[849] = { "VTB", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[896] = { "PPR", 64, RW, }, +[898] = { "PPR32", 32, RW, }, +[1023]= { "PIR", 32, OS_RO, SPR_ASYNC, }, /* Can't be virtualised, appears to be async */ +}; + +static const struct spr sprs_tm[1024] = { +#if 0 + /* XXX: leave these out until enabling TM facility (and more testing) */ +[128] = { "TFHAR", 64, RW, }, +[129] = { "TFIAR", 64, RW, }, +[130] = { "TEXASR", 64, RW, }, +[131] = { "TEXASRU", 32, RW, }, +#endif +}; + /* SPRs from PowerISA 2.07 Book III-S */ -static void set_sprs_book3s_207(uint64_t val) -{ - mtspr(3, val); /* DSCR */ - mtspr(13, val); /* AMR */ - mtspr(17, val); /* DSCR */ - mtspr(18, val); /* DSISR */ - mtspr(19, val); /* DAR */ - mtspr(29, val); /* AMR */ - mtspr(61, val); /* IAMR */ - // mtspr(152, val); /* CTRL */ /* TODO: Needs a fix in KVM */ - mtspr(153, val); /* FSCR */ - mtspr(157, val); /* UAMOR */ - mtspr(159, val); /* PSPB */ - mtspr(256, val); /* VRSAVE */ - // mtspr(272, val); /* SPRG0 */ /* Used by our exception handler */ - mtspr(769, val); /* MMCR2 */ - mtspr(770, val); /* MMCRA */ - mtspr(771, val); /* PMC1 */ - mtspr(772, val); /* PMC2 */ - mtspr(773, val); /* PMC3 */ - mtspr(774, val); /* PMC4 */ - mtspr(775, val); /* PMC5 */ - mtspr(776, val); /* PMC6 */ - mtspr(779, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); /* MMCR0 */ - mtspr(784, val); /* SIER */ - mtspr(785, val); /* MMCR2 */ - mtspr(786, val); /* MMCRA */ - mtspr(787, val); /* PMC1 */ - mtspr(788, val); /* PMC2 */ - mtspr(789, val); /* PMC3 */ - mtspr(790, val); /* PMC4 */ - mtspr(791, val); /* PMC5 */ - mtspr(792, val); /* PMC6 */ - mtspr(795, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); /* MMCR0 */ - mtspr(796, val); /* SIAR */ - mtspr(797, val); /* SDAR */ - mtspr(798, val); /* MMCR1 */ - mtspr(800, val); /* BESCRS */ - mtspr(801, val); /* BESCCRSU */ - mtspr(802, val); /* BESCRR */ - mtspr(803, val); /* BESCRRU */ - mtspr(804, val); /* EBBHR */ - mtspr(805, val); /* EBBRR */ - mtspr(806, val); /* BESCR */ - mtspr(815, val); /* TAR */ -} +static const struct spr sprs_207[1024] = { + [22] = { "DEC", 32, OS_RW, SPR_ASYNC, }, + [25] = { "SDR1", 64, HV_RW, }, +[177] = { "DHDES", 64, HV_RW, }, +[283] = { "CIR", 32, OS_RO, }, +[310] = { "HDEC", 32, HV_RW, SPR_ASYNC, }, +[312] = { "RMOR", 64, HV_RW, }, +[339] = { "HEIR", 32, HV_RW, SPR_INT, }, +}; /* SPRs from PowerISA 3.00 Book III */ -static void set_sprs_book3s_300(uint64_t val) -{ - set_sprs_book3s_207(val); - mtspr(48, val); /* PIDR */ - mtspr(144, val); /* TIDR */ - mtspr(823, val); /* PSSCR */ -} +static const struct spr sprs_300[1024] = { + [22] = { "DEC", 64, OS_RW, SPR_ASYNC, }, + [48] = { "PIDR", 32, OS_RW, }, +[144] = { "TIDR", 64, OS_RW, }, +[283] = { "CIR", 32, OS_RO, }, +[310] = { "HDEC", 64, HV_RW, SPR_ASYNC, }, +[339] = { "HEIR", 32, HV_RW, SPR_INT, }, +[464] = { "PTCR", 64, HV_RW, }, +[816] = { "ASDR", 64, HV_RW, SPR_INT, }, +[823] = { "PSSCR", 64, OS_RW, }, +[855] = { "PSSCR", 64, HV_RW, }, +}; -/* SPRs from Power ISA Version 3.1B */ -static void set_sprs_book3s_31(uint64_t val) -{ - set_sprs_book3s_207(val); - mtspr(48, val); /* PIDR */ - /* 3.1 removes TIDR */ - mtspr(823, val); /* PSSCR */ -} +/* SPRs from PowerISA 3.1B Book III */ +static const struct spr sprs_31[1024] = { + [22] = { "DEC", 64, OS_RW, SPR_ASYNC, }, + [48] = { "PIDR", 32, OS_RW, }, +[181] = { "DAWR1", 64, HV_RW, }, +[189] = { "DAWRX1", 32, HV_RW, }, +[310] = { "HDEC", 64, HV_RW, SPR_ASYNC, }, +[339] = { "HEIR", 64, HV_RW, SPR_INT, }, +[455] = { "HDEXCR", 32, RO, }, +[464] = { "PTCR", 64, HV_RW, }, +[468] = { "HASHKEYR", 64, OS_RW, }, +[469] = { "HASHPKEYR", 64, HV_RW, }, +[471] = { "HDEXCR", 64, HV_RW, }, +[812] = { "DEXCR", 32, RO, }, +[816] = { "ASDR", 64, HV_RW, SPR_INT, }, +[823] = { "PSSCR", 64, OS_RW, }, +[828] = { "DEXCR", 64, OS_RW, }, +[855] = { "PSSCR", 64, HV_RW, }, +}; -static void set_sprs(uint64_t val) +/* SPRs POWER9, POWER10 User Manual */ +static const struct spr sprs_power9_10[1024] = { +[276] = { "SPRC", 64, HV_RW, }, +[277] = { "SPRD", 64, HV_RW, }, +[317] = { "TFMR", 64, HV_RW, }, +[799] = { "IMC", 64, HV_RW, }, +[850] = { "LDBAR", 64, HV_RO, }, +[851] = { "MMCRC", 32, HV_RW, }, +[853] = { "PMSR", 32, HV_RO, }, +[861] = { "L2QOSR", 64, HV_WO, }, +[881] = { "TRIG1", 64, OS_WO, }, +[882] = { "TRIG2", 64, OS_WO, }, +[884] = { "PMCR", 64, HV_RW, }, +[885] = { "RWMR", 64, HV_RW, }, +[895] = { "WORT", 64, OS_RW, }, /* UM says 18-bits! */ +[921] = { "TSCR", 32, HV_RW, }, +[922] = { "TTR", 64, HV_RW, }, +[1006]= { "TRACE", 64, WO, }, +[1008]= { "HID", 64, HV_RW, }, +}; + +/* This covers POWER8 and POWER9 PMUs */ +static const struct spr sprs_power_common_pmu[1024] = { +[768] = { "SIER", 64, RO, }, +[769] = { "MMCR2", 64, RW, }, +[770] = { "MMCRA", 64, RW, }, +[771] = { "PMC1", 32, RW, }, +[772] = { "PMC2", 32, RW, }, +[773] = { "PMC3", 32, RW, }, +[774] = { "PMC4", 32, RW, }, +[775] = { "PMC5", 32, RW, }, +[776] = { "PMC6", 32, RW, }, +[779] = { "MMCR0", 64, RW, }, +[780] = { "SIAR", 64, RO, }, +[781] = { "SDAR", 64, RO, }, +[782] = { "MMCR1", 64, RO, }, +[784] = { "SIER", 64, OS_RW, }, +[785] = { "MMCR2", 64, OS_RW, }, +[786] = { "MMCRA", 64, OS_RW, }, +[787] = { "PMC1", 32, OS_RW, }, +[788] = { "PMC2", 32, OS_RW, }, +[789] = { "PMC3", 32, OS_RW, }, +[790] = { "PMC4", 32, OS_RW, }, +[791] = { "PMC5", 32, OS_RW, }, +[792] = { "PMC6", 32, OS_RW, }, +[795] = { "MMCR0", 64, OS_RW, }, +[796] = { "SIAR", 64, OS_RW, }, +[797] = { "SDAR", 64, OS_RW, }, +[798] = { "MMCR1", 64, OS_RW, }, +}; + +static const struct spr sprs_power10_pmu[1024] = { +[736] = { "SIER2", 64, RO, }, +[737] = { "SIER3", 64, RO, }, +[738] = { "MMCR3", 64, RO, }, +[752] = { "SIER2", 64, OS_RW, }, +[753] = { "SIER3", 64, OS_RW, }, +[754] = { "MMCR3", 64, OS_RW, }, +}; + +static struct spr sprs[1024]; + +static void setup_sprs(void) { - set_sprs_common(val); + int i; + + for (i = 0; i < 1024; i++) { + if (sprs_common[i].name) { + memcpy(&sprs[i], &sprs_common[i], sizeof(struct spr)); + } + } switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_970: case PVR_VER_970FX: case PVR_VER_970MP: - set_sprs_book3s_201(val); + for (i = 0; i < 1024; i++) { + if (sprs_201[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_201[i], sizeof(struct spr)); + } + if (sprs_970_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + } break; + case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: case PVR_VER_POWER8: - set_sprs_book3s_207(val); + for (i = 0; i < 1024; i++) { + if (sprs_power_common[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common[i], sizeof(struct spr)); + } + if (sprs_207[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_207[i], sizeof(struct spr)); + } + if (sprs_tm[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_tm[i], sizeof(struct spr)); + } + if (sprs_power_common_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + } break; + case PVR_VER_POWER9: - set_sprs_book3s_300(val); + for (i = 0; i < 1024; i++) { + if (sprs_power_common[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common[i], sizeof(struct spr)); + } + if (sprs_300[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_300[i], sizeof(struct spr)); + } + if (sprs_tm[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_tm[i], sizeof(struct spr)); + } + if (sprs_power9_10[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power9_10[i], sizeof(struct spr)); + } + if (sprs_power_common_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + } break; + case PVR_VER_POWER10: - set_sprs_book3s_31(val); + for (i = 0; i < 1024; i++) { + if (sprs_power_common[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common[i], sizeof(struct spr)); + } + if (sprs_31[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_31[i], sizeof(struct spr)); + } + if (sprs_power9_10[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power9_10[i], sizeof(struct spr)); + } + if (sprs_power_common_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + if (sprs_power10_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power10_pmu[i], sizeof(struct spr)); + } + } break; + default: - puts("Warning: Unknown processor version!\n"); + memcpy(sprs, sprs_common, sizeof(sprs)); + puts("Warning: Unknown processor version, falling back to common SPRs!\n"); + break; } } -static void get_sprs_common(uint64_t *v) -{ - v[9] = mfspr(9); /* CTR */ - // v[273] = mfspr(273); /* SPRG1 */ /* Used by our exception handler */ - v[274] = mfspr(274); /* SPRG2 */ - v[275] = mfspr(275); /* SPRG3 */ -} - -static void get_sprs_book3s_201(uint64_t *v) -{ - v[18] = mfspr(18); /* DSISR */ - v[19] = mfspr(19); /* DAR */ - v[136] = mfspr(136); /* CTRL */ - v[256] = mfspr(256); /* VRSAVE */ - v[786] = mfspr(786); /* MMCRA */ - v[795] = mfspr(795); /* MMCR0 */ - v[798] = mfspr(798); /* MMCR1 */ -} - -static void get_sprs_book3s_207(uint64_t *v) -{ - v[3] = mfspr(3); /* DSCR */ - v[13] = mfspr(13); /* AMR */ - v[17] = mfspr(17); /* DSCR */ - v[18] = mfspr(18); /* DSISR */ - v[19] = mfspr(19); /* DAR */ - v[29] = mfspr(29); /* AMR */ - v[61] = mfspr(61); /* IAMR */ - // v[136] = mfspr(136); /* CTRL */ /* TODO: Needs a fix in KVM */ - v[153] = mfspr(153); /* FSCR */ - v[157] = mfspr(157); /* UAMOR */ - v[159] = mfspr(159); /* PSPB */ - v[256] = mfspr(256); /* VRSAVE */ - v[259] = mfspr(259); /* SPRG3 (read only) */ - // v[272] = mfspr(272); /* SPRG0 */ /* Used by our exception handler */ - v[769] = mfspr(769); /* MMCR2 */ - v[770] = mfspr(770); /* MMCRA */ - v[771] = mfspr(771); /* PMC1 */ - v[772] = mfspr(772); /* PMC2 */ - v[773] = mfspr(773); /* PMC3 */ - v[774] = mfspr(774); /* PMC4 */ - v[775] = mfspr(775); /* PMC5 */ - v[776] = mfspr(776); /* PMC6 */ - v[779] = mfspr(779); /* MMCR0 */ - v[780] = mfspr(780); /* SIAR (read only) */ - v[781] = mfspr(781); /* SDAR (read only) */ - v[782] = mfspr(782); /* MMCR1 (read only) */ - v[784] = mfspr(784); /* SIER */ - v[785] = mfspr(785); /* MMCR2 */ - v[786] = mfspr(786); /* MMCRA */ - v[787] = mfspr(787); /* PMC1 */ - v[788] = mfspr(788); /* PMC2 */ - v[789] = mfspr(789); /* PMC3 */ - v[790] = mfspr(790); /* PMC4 */ - v[791] = mfspr(791); /* PMC5 */ - v[792] = mfspr(792); /* PMC6 */ - v[795] = mfspr(795); /* MMCR0 */ - v[796] = mfspr(796); /* SIAR */ - v[797] = mfspr(797); /* SDAR */ - v[798] = mfspr(798); /* MMCR1 */ - v[800] = mfspr(800); /* BESCRS */ - v[801] = mfspr(801); /* BESCCRSU */ - v[802] = mfspr(802); /* BESCRR */ - v[803] = mfspr(803); /* BESCRRU */ - v[804] = mfspr(804); /* EBBHR */ - v[805] = mfspr(805); /* EBBRR */ - v[806] = mfspr(806); /* BESCR */ - v[815] = mfspr(815); /* TAR */ -} - -static void get_sprs_book3s_300(uint64_t *v) +static void get_sprs(uint64_t *v) { - get_sprs_book3s_207(v); - v[48] = mfspr(48); /* PIDR */ - v[144] = mfspr(144); /* TIDR */ - v[823] = mfspr(823); /* PSSCR */ -} + int i; -static void get_sprs_book3s_31(uint64_t *v) -{ - get_sprs_book3s_207(v); - v[48] = mfspr(48); /* PIDR */ - v[823] = mfspr(823); /* PSSCR */ + for (i = 0; i < 1024; i++) { + if (!(sprs[i].access & SPR_OS_READ)) + continue; + v[i] = __mfspr(i); + } } -static void get_sprs(uint64_t *v) +static void set_sprs(uint64_t val) { - uint32_t pvr = mfspr(287); /* Processor Version Register */ - - get_sprs_common(v); + int i; - switch (pvr >> 16) { - case 0x39: /* PPC970 */ - case 0x3C: /* PPC970FX */ - case 0x44: /* PPC970MP */ - get_sprs_book3s_201(v); - break; - case 0x4b: /* POWER8E */ - case 0x4c: /* POWER8NVL */ - case 0x4d: /* POWER8 */ - get_sprs_book3s_207(v); - break; - case 0x4e: /* POWER9 */ - get_sprs_book3s_300(v); - break; - case 0x80: /* POWER10 */ - get_sprs_book3s_31(v); - break; + for (i = 0; i < 1024; i++) { + if (!(sprs[i].access & SPR_OS_WRITE)) + continue; + if (sprs[i].type & SPR_HARNESS) + continue; + if (!strcmp(sprs[i].name, "MMCR0")) { + /* XXX: could use a comment or better abstraction! */ + __mtspr(i, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); + } else { + __mtspr(i, val); + } } } @@ -289,7 +518,9 @@ int main(int argc, char **argv) } } - printf("Settings SPRs to %#lx...\n", pat); + setup_sprs(); + + printf("Setting SPRs to 0x%lx...\n", pat); set_sprs(pat); memset(before, 0, sizeof(before)); @@ -299,18 +530,50 @@ int main(int argc, char **argv) if (pause) { migrate_once(); + /* Reload regs changed by getchar/putchar hcalls */ + before[SPR_SRR0] = mfspr(SPR_SRR0); + before[SPR_SRR1] = mfspr(SPR_SRR1); + + /* WORT seems to go to 0 after KVM switch, perhaps CPU idle */ + if (sprs[895].name) + before[895] = mfspr(895); } else { msleep(2000); + + /* Reload regs changed by dec interrupt */ + before[SPR_SRR0] = mfspr(SPR_SRR0); + before[SPR_SRR1] = mfspr(SPR_SRR1); + before[SPR_SPRG1] = mfspr(SPR_SPRG1); + + /* WORT seems to go to 0 after KVM switch, perhaps CPU idle */ + if (sprs[895].name) + before[895] = mfspr(895); } get_sprs(after); puts("Checking SPRs...\n"); for (i = 0; i < 1024; i++) { - if (before[i] != 0 || after[i] != 0) - report(before[i] == after[i], - "SPR %d:\t%#018lx <==> %#018lx", i, before[i], - after[i]); + bool pass = true; + + if (!(sprs[i].access & SPR_OS_READ)) + continue; + + if (sprs[i].width == 32) { + if (before[i] >> 32) + pass = false; + } + if (!(sprs[i].type & (SPR_HARNESS|SPR_ASYNC)) && (before[i] != after[i])) + pass = false; + + if (sprs[i].width == 32 && !(before[i] >> 32) && !(after[i] >> 32)) + report(pass, "%-10s(%4d):\t 0x%08lx <==> 0x%08lx", + sprs[i].name, i, + before[i], after[i]); + else + report(pass, "%-10s(%4d):\t0x%016lx <==> 0x%016lx", + sprs[i].name, i, + before[i], after[i]); } return report_summary(); From patchwork Tue Mar 19 07:59:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Yf3B0+J/; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPVx3vRxz1yWs for ; Tue, 19 Mar 2024 19:08:41 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Yf3B0+J/; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPVx2nq8z3vkC for ; Tue, 19 Mar 2024 19:08:41 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=Yf3B0+J/; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2001:4860:4864:20::36; helo=mail-oa1-x36.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) (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 4TzPKL1W5gz3vXr for ; Tue, 19 Mar 2024 19:00:21 +1100 (AEDT) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-2226572ccf8so3179434fac.2 for ; Tue, 19 Mar 2024 01:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835219; x=1711440019; darn=lists.ozlabs.org; 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=izEPUDLrTWux3hhd+DYadQTbCcRPUPa7uPofKkjLRfw=; b=Yf3B0+J/LQzxv6Y28mJBn9z1jF5BYznLXolmDq2IqGiUsz07x1KRL/ACnvjT0hb6P2 6hyZWJ/MVeOA35PME2260LMnKOITrhoY5WRtCd/AKkqRPJtlmEDwzJ0fJs/uRYAwaMc1 p3hzp9P+02zXdDMNQQe8mZwgcQRaYSHPhA/wcpVlKy5GnmEj+A7zq62Qg3S9pJSC2Lw1 IWoLoPqY5RaZE9+nWbS4HHpar7EO4qE4RFw4Q54EifdB9Cz6oSof3Dygne1axx6viBCb fSYU045+CWrKQE4Wm7yTsqqP9fvvHLdYMEon9ysuNbhspDlPkatt453EtO5tfPEwvTpx NGqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835219; x=1711440019; 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=izEPUDLrTWux3hhd+DYadQTbCcRPUPa7uPofKkjLRfw=; b=GnKmFFp6YM24Yb1+VEttqZACqlFcZDBztPONVE9vfyJqD+jUWzPOjc8iTkXDj6s+pk 6lLPeIA4VShN3qwn0otSVSEldzhhdrWQ++7OoAjUZuImFnat++7vfg9+u8NosmU426G9 12UQt18URNZMwL2W6eved2C1Lg+eLknJ37XsYO56cD7uTaH8ugZMMkjsnGiJDGaQB4xC fMXhsguieftXFKUoV/63iEsJW4BwGDzfCi3IS+0N0U09UA5pFIx2gkXFtJdJHUnEwx/D ZY4yMxF7QKMsCjvK3yOLA9aLBfsS70QgyzySfXw1BjwsasLjAVZgfbaLS80P0KFopwEC 9bhQ== X-Forwarded-Encrypted: i=1; AJvYcCV7Tfa2CwZM65mxzAUjz8i+ypTMpHTlneWJovPicN8NbJEDmjQdmDttUr5SrW3Hfygo3ntzoFY4RbsqJYpEr+98no+YUaxvm1YoDTKDHg== X-Gm-Message-State: AOJu0Yy0V5WRDLB1RaYtdNEzkQkdVWPlW19OxIbplTqfLI2hI8iKTD2e WdoGMzy+jlq1mdrf0EYm7cL4eKzFwZBWjRHDyxF7fLwR3N5hqt9S X-Google-Smtp-Source: AGHT+IG6AoUV4kxb29g3tkOeDbXZj/QPCcaJ2eebh/M0r60HpuDQrZKe9HHIFG91jyt9Gi9dH8DNRQ== X-Received: by 2002:a05:6871:554:b0:221:14d4:6ab9 with SMTP id t20-20020a056871055400b0022114d46ab9mr16702195oal.2.1710835219241; Tue, 19 Mar 2024 01:00:19 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:19 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 12/35] powerpc/sprs: Avoid taking PMU interrupts caused by register fuzzing Date: Tue, 19 Mar 2024 17:59:03 +1000 Message-ID: <20240319075926.2422707-13-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Storing certain values in MMCR0 can cause PMU interrupts when msleep enables MSR[EE], and this crashes the test. Freeze the PMU counters and clear any PMU exception before calling msleep. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/reg.h | 4 ++++ powerpc/sprs.c | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 1f991288e..c80b32059 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -24,6 +24,10 @@ #define PVR_VER_POWER10 UL(0x00800000) #define SPR_HSRR0 0x13a #define SPR_HSRR1 0x13b +#define SPR_MMCR0 0x31b +#define MMCR0_FC UL(0x80000000) +#define MMCR0_PMAE UL(0x04000000) +#define MMCR0_PMAO UL(0x00000080) /* Machine State Register definitions: */ #define MSR_EE_BIT 15 /* External Interrupts Enable */ diff --git a/powerpc/sprs.c b/powerpc/sprs.c index 44edd0d7b..cb1d6c980 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -476,12 +476,7 @@ static void set_sprs(uint64_t val) continue; if (sprs[i].type & SPR_HARNESS) continue; - if (!strcmp(sprs[i].name, "MMCR0")) { - /* XXX: could use a comment or better abstraction! */ - __mtspr(i, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); - } else { - __mtspr(i, val); - } + __mtspr(i, val); } } @@ -538,6 +533,16 @@ int main(int argc, char **argv) if (sprs[895].name) before[895] = mfspr(895); } else { + /* + * msleep will enable MSR[EE] and take a decrementer + * interrupt. Must account for changed registers and + * prevent taking unhandled interrupts. + */ + /* Prevent PMU interrupt */ + mtspr(SPR_MMCR0, (mfspr(SPR_MMCR0) | MMCR0_FC) & + ~(MMCR0_PMAO | MMCR0_PMAE)); + before[SPR_MMCR0] = mfspr(SPR_MMCR0); + before[779] = mfspr(SPR_MMCR0); msleep(2000); /* Reload regs changed by dec interrupt */ From patchwork Tue Mar 19 07:59:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cAJLoN50; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPWk4dyxz1yWs for ; Tue, 19 Mar 2024 19:09:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cAJLoN50; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPWk3Zf4z3vsp for ; Tue, 19 Mar 2024 19:09:22 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=cAJLoN50; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2001:4860:4864:20::32; helo=mail-oa1-x32.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) (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 4TzPKP6p2wz3vYN for ; Tue, 19 Mar 2024 19:00:25 +1100 (AEDT) Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-2228c3ffcbdso1445595fac.2 for ; Tue, 19 Mar 2024 01:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835223; x=1711440023; darn=lists.ozlabs.org; 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=0dYKloMaVNRA1K0WdUqfNiU807y8A/fMNA27ThMkpH8=; b=cAJLoN50CtqtGiX4Loh7rO+0ECMPO9z3FxGq/xBniTma4K4QHm1r+ujr2rI9ubOnsd YIqVAB2gTZ9O99L4yRqG2UrMxKcUq/hRuNujAvloG5ELPaqigSiocOJDLK22WzHN4Lvp 6Lub0z9bf3VBx1+JaXPXhorNeIhdV8j9I+eAk4V2Kjgx6yqvN0CllB84gon5xuPIS2Zs fLc7IPgy/Nzsj/XaM77wlkl94fNcJ+PWp5ImL/8VHtXQjbWTfA5QET+88YjfcltzSkKN BRwFuP5ynbj0D0rjYJvJebzpJ+c7cyhtzGH9QVr0Jy0X4ILUYUcr56iZ0YaL/Z8IvG3A xErA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835223; x=1711440023; 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=0dYKloMaVNRA1K0WdUqfNiU807y8A/fMNA27ThMkpH8=; b=Imcc9xS0UeF7GMgm5fRRJluuiHWuO7tBjXdwY9082ge7EhzPBx/X2BJoVygMt0PY6E VudRrP3KXTRJ9xOZwd/NGbFQLNDkPnKliScd771RvkHVlXUO7bV3d5CMOTm69MyslYF/ 2Izo+h3fKXr5zCjl9MQLAcsjxFekkwApaykAK0hLNqP11L0zNaRSPA5Z/Zakc/0/KxDE DWwpgRzUXuEPiUW2P+qnEyw+0nhyI/F+72p73m62RqyIwxQYeTHNnQ5f0B+Dm/7rvdk/ 8aDLtJIkWfela5AaGOmzfafpWdGQ6kqGWJDkMVlC3xeZWov3xXOa/KlFLzMepBEsbApS L+Tg== X-Forwarded-Encrypted: i=1; AJvYcCXDJY2sH0Yam7JliPH2kvmrGIL/RsOTNMskv90XvriPFEYcMrYlltITOmWSd2J7HKezHd+mF45qqYNmUCkxz4RAuOIHndYn5dLGrdMs6g== X-Gm-Message-State: AOJu0Yxxd5YPX3x7YyVMYBbqB2fbKlEj89p8j+JJS3rn1ukjvHWM46S5 0wzzWaBfiObtQP6Z2IcohU4qmkr5P39YmxUiEwbDkHg1RxaLvslX X-Google-Smtp-Source: AGHT+IEUonzbDLFfzykkcQwpnCF2OnRoX6IIO7f1kwVSXYK0lVTHuWmBwNyL1fdxb0nxoRNutxc8cA== X-Received: by 2002:a05:6870:84cb:b0:21e:b8f7:9a1b with SMTP id l11-20020a05687084cb00b0021eb8f79a1bmr13865746oak.25.1710835223042; Tue, 19 Mar 2024 01:00:23 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:22 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 13/35] doc: start documentation directory with unittests.cfg doc Date: Tue, 19 Mar 2024 17:59:04 +1000 Message-ID: <20240319075926.2422707-14-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Consolidate unittests.cfg documentation in one place. Suggested-by: Andrew Jones Signed-off-by: Nicholas Piggin --- arm/unittests.cfg | 26 ++----------- docs/unittests.txt | 89 +++++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 25 ++---------- riscv/unittests.cfg | 26 ++----------- s390x/unittests.cfg | 18 ++------- x86/unittests.cfg | 26 ++----------- 6 files changed, 107 insertions(+), 103 deletions(-) create mode 100644 docs/unittests.txt diff --git a/arm/unittests.cfg b/arm/unittests.cfg index fe601cbb1..54cedea28 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -1,28 +1,10 @@ ############################################################################## # unittest configuration # -# [unittest_name] -# file = .flat # Name of the flat file to be used. -# smp = # Number of processors the VM will use -# # during this test. Use $MAX_SMP to use -# # the maximum the host supports. Defaults -# # to one. -# extra_params = -append # Additional parameters used. -# arch = arm|arm64 # Select one if the test case is -# # specific to only one. -# groups = ... # Used to identify test cases -# # with run_tests -g ... -# # Specify group_name=nodefault -# # to have test not run by -# # default -# accel = kvm|tcg # Optionally specify if test must run with -# # kvm or tcg. If not specified, then kvm will -# # be used when available. -# timeout = # Optionally specify a timeout. -# check = = # check a file for a particular value before running -# # a test. The check line can contain multiple files -# # to check separated by a space but each check -# # parameter needs to be of the form = +# arm specifics: +# +# file = .flat # arm uses .flat files +# arch = arm|arm64 ############################################################################## # diff --git a/docs/unittests.txt b/docs/unittests.txt new file mode 100644 index 000000000..53e02077c --- /dev/null +++ b/docs/unittests.txt @@ -0,0 +1,89 @@ +unittests +********* + +run_tests.sh is driven by the /unittests.cfg file. That file defines +test cases by specifying an executable (target image) under the / +directory, and how to run it. This way, for example, a single file can +provide multiple test cases by being run with different host configurations +and/or different parameters passed to it. + +Detailed output from run_tests.sh unit tests are stored in files under +the logs/ directory. + +unittests.cfg format +==================== + +# is the comment symbol, all following contents of the line is ignored. + +Each unit test is defined as with a [unit-test-name] line, followed by +a set of parameters that control how the test case is run. The name is +arbitrary and appears in the status reporting output. + +Parameters appear on their own lines under the test name, and have a +param = value format. + +Available parameters +==================== +Note! Some parameters like smp and extra_params modify how a test is run, +while others like arch and accel restrict the configurations in which the +test is run. + +file +---- +file = + +This parameter is mandatory and specifies which binary under the / +directory to run. Typically this is .flat or .elf, depending +on the arch. The directory name is not included, only the file name. + +arch +---- +For / directories that support multiple architectures, this restricts +the test to the specified arch. By default, the test will run on any +architecture. + +smp +--- +smp = + +Optional, the number of processors created in the machine to run the test. +Defaults to 1. $MAX_SMP can be used to specify the maximum supported. + +extra_params +------------ +These are extra parameters supplied to the QEMU process. -append '...' can +be used to pass arguments into the test case argv. Multiple parameters can +be added, for example: + +extra_params = -m 256 -append 'smp=2' + +groups +------ +groups = ... + +Used to group the test cases for the `run_tests.sh -g ...` run group +option. Adding a test to the nodefault group will cause it to not be +run by default. + +accel +----- +accel = kvm|tcg + +This restricts the test to the specified accelerator. By default, the +test will run on either accelerator. (Note, the accelerator can be +specified with ACCEL= environment variable, and defaults to KVM if +available). + +timeout +------- +timeout = + +Optional timeout in seconds, after which the test will be killed and fail. + +check +----- +check = =< + +Check a file for a particular value before running a test. The check line +can contain multiple files to check separated by a space, but each check +parameter needs to be of the form = diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index e65217c18..432c81d58 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -1,28 +1,9 @@ ############################################################################## # unittest configuration # -# [unittest_name] -# file = .flat # Name of the flat file to be used. -# smp = # Number of processors the VM will use -# # during this test. Use $MAX_SMP to use -# # the maximum the host supports. Defaults -# # to one. -# extra_params = -append # Additional parameters used. -# arch = ppc64 # Select one if the test case is -# # specific to only one. -# groups = ... # Used to identify test cases -# # with run_tests -g ... -# # Specify group_name=nodefault -# # to have test not run by -# # default -# accel = kvm|tcg # Optionally specify if test must run with -# # kvm or tcg. If not specified, then kvm will -# # be used when available. -# timeout = # Optionally specify a timeout. -# check = = # check a file for a particular value before running -# # a test. The check line can contain multiple files -# # to check separated by a space but each check -# # parameter needs to be of the form = +# powerpc specifics: +# +# file = .elf # powerpc uses .elf files ############################################################################## # diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg index 5a23bed9c..50c67e37f 100644 --- a/riscv/unittests.cfg +++ b/riscv/unittests.cfg @@ -1,28 +1,10 @@ ############################################################################## # unittest configuration # -# [unittest_name] -# file = .flat # Name of the flat file to be used. -# smp = # Number of processors the VM will use -# # during this test. Use $MAX_SMP to use -# # the maximum the host supports. Defaults -# # to one. -# extra_params = -append # Additional parameters used. -# arch = riscv32|riscv64 # Select one if the test case is -# # specific to only one. -# groups = ... # Used to identify test cases -# # with run_tests -g ... -# # Specify group_name=nodefault -# # to have test not run by -# # default -# accel = kvm|tcg # Optionally specify if test must run with -# # kvm or tcg. If not specified, then kvm will -# # be used when available. -# timeout = # Optionally specify a timeout. -# check = = # check a file for a particular value before running -# # a test. The check line can contain multiple files -# # to check separated by a space but each check -# # parameter needs to be of the form = +# riscv specifics: +# +# file = .flat # riscv uses .flat files +# arch = riscv32|risc64 ############################################################################## [selftest] diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 550eff787..d6abf72f3 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -1,21 +1,9 @@ ############################################################################## # unittest configuration # -# [unittest_name] -# file = .elf # Name of the elf file to be used. -# extra_params = -append # Additional parameters used. -# groups = ... # Used to identify test cases -# # with run_tests -g ... -# # Specify group_name=nodefault -# # to have test not run by default -# accel = kvm|tcg # Optionally specify if test must run with -# # kvm or tcg. If not specified, then kvm will -# # be used when available. -# timeout = # Optionally specify a timeout. -# check = = # check a file for a particular value before running -# # a test. The check line can contain multiple files -# # to check separated by a space but each check -# # parameter needs to be of the form = +# s390x specifics: +# +# file = .elf # s390x uses .elf files ############################################################################## [selftest-setup] diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 124be7a1f..867a8ea2f 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -1,28 +1,10 @@ ############################################################################## # unittest configuration # -# [unittest_name] -# file = .flat # Name of the flat file to be used. -# smp = # Number of processors the VM will use -# # during this test. Use $MAX_SMP to use -# # the maximum the host supports. Defaults -# # to one. -# extra_params = -append # Additional parameters used. -# arch = i386|x86_64 # Select one if the test case is -# # specific to only one. -# groups = ... # Used to identify test cases -# # with run_tests -g ... -# # Specify group_name=nodefault -# # to have test not run by -# # default -# accel = kvm|tcg # Optionally specify if test must run with -# # kvm or tcg. If not specified, then kvm will -# # be used when available. -# timeout = # Optionally specify a timeout. -# check = = # check a file for a particular value before running -# # a test. The check line can contain multiple files -# # to check separated by a space but each check -# # parameter needs to be of the form = +# x86 specifics: +# +# file = .flat # x86 uses .flat files +# arch = i386|x86_64 ############################################################################## [apic-split] From patchwork Tue Mar 19 07:59:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LKQvCwiJ; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPXX166gz1yWn for ; Tue, 19 Mar 2024 19:10:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LKQvCwiJ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPXW4NCnz3vtq for ; Tue, 19 Mar 2024 19:10:03 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=LKQvCwiJ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::235; helo=mail-oi1-x235.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (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 4TzPKT4w66z3vYT for ; Tue, 19 Mar 2024 19:00:29 +1100 (AEDT) Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3c38d4b670bso826664b6e.2 for ; Tue, 19 Mar 2024 01:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835227; x=1711440027; darn=lists.ozlabs.org; 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=0y0odnkHg56MP9cN9AQCJ0tr4xMulM+8pNx+P8ve/gI=; b=LKQvCwiJWHKA02GMEDD89YgU+W/MCUecYdj8DygVYNRzGtc+OdESpDvAm3S1MBZmkR E+/uKSnzhzpIni6R0hcD9SPTi3UQbE8SVmxuDfquON6hj3MbRUsDqbepGbYkXePC5C2i Dt6dKlCWGNCthlYWWAiJV0kkMuZJhdCq8IwEPdwmu3eg1haTh7HY3YIZHpW3RzaCG266 Ar6gbegqNTNwtvZoBvF+pLRFIMJDgouqvhO+TcpniW8PM0JtrttfzchItTPO3d7Ci6ng 9YQAdAPYeiJGP5DWzWW+jM/CvNjqMg+JUWYHu7RNZWqAEnjAvyHP06x1tFrwcdTA1p9H AI9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835227; x=1711440027; 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=0y0odnkHg56MP9cN9AQCJ0tr4xMulM+8pNx+P8ve/gI=; b=Jtw4a5f+ZNFnlHmJDhNG7WlUv4lWQSgCK97WngwmM7Y5Dy6xchSeN3wgA2/yEJBfLd x2diYZPWt3dbRc+MqRrn+yRZKGbAQzrxL/Ly2tsHru5J//mOmLNjmozv9BZZ3Wtvz7ft PcD62rOOp6tw4EDJAkjEuoh1QllNCmYrld83cJu3sLXgGkeZ94B4fI9M+xV9aMvOLYIC Wss9qTx+1P48B0C4nL45AdlKKDM1qiCkZL9coACjzYnb9wu04H/h27O5oXShqssmEwAx 5N+brcStjuURVSvOnigptDgpYzKUV9u3r1dqu25StKedLmgyLpMQQXWBj6vhtPT4gdlo MtRw== X-Forwarded-Encrypted: i=1; AJvYcCV3rT7ps3kZsCHRtLw24M7xjtxvKyC3272N6LJz17zU8JBuKI51rqXd2jY7ac2e1o6OecGJkmnf823h74wSqQ5tTphKNF4/lK34hNgmag== X-Gm-Message-State: AOJu0YyOczs1JWPNvZOmJ0F5u51bqee+TRthvnNtqaaKq+e0bFRygs8k PU3E4IsOYv3SV7dPu3QEVslm2czF+r8uwu5uN0NpWK217HAulqww X-Google-Smtp-Source: AGHT+IF9aDLZUPosgy6rpk16ZaqRepm+7B0h+dF+YDWbgQFj5DBzE5ABhTXmbPl0bJZP9AS+TMu9Gg== X-Received: by 2002:a05:6808:f0a:b0:3c3:69a2:4248 with SMTP id m10-20020a0568080f0a00b003c369a24248mr16079802oiw.28.1710835226966; Tue, 19 Mar 2024 01:00:26 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:26 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 14/35] scripts: allow machine option to be specified in unittests.cfg Date: Tue, 19 Mar 2024 17:59:05 +1000 Message-ID: <20240319075926.2422707-15-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled. Acked-by: Thomas Huth Acked-by: Andrew Jones Signed-off-by: Nicholas Piggin --- docs/unittests.txt | 6 ++++++ scripts/common.bash | 8 ++++++-- scripts/runtime.bash | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/unittests.txt b/docs/unittests.txt index 53e02077c..5b184723c 100644 --- a/docs/unittests.txt +++ b/docs/unittests.txt @@ -42,6 +42,12 @@ For / directories that support multiple architectures, this restricts the test to the specified arch. By default, the test will run on any architecture. +machine +------- +For those architectures that support multiple machine types, this allows +machine-specific tests to be created. By default, the test will run on +any machine type. + smp --- smp = diff --git a/scripts/common.bash b/scripts/common.bash index b9413d683..ee1dd8659 100644 --- a/scripts/common.bash +++ b/scripts/common.bash @@ -10,6 +10,7 @@ function for_each_unittest() local opts local groups local arch + local machine local check local accel local timeout @@ -21,7 +22,7 @@ function for_each_unittest() if [[ "$line" =~ ^\[(.*)\]$ ]]; then rematch=${BASH_REMATCH[1]} if [ -n "${testname}" ]; then - $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout" fi testname=$rematch smp=1 @@ -29,6 +30,7 @@ function for_each_unittest() opts="" groups="" arch="" + machine="" check="" accel="" timeout="" @@ -58,6 +60,8 @@ function for_each_unittest() groups=${BASH_REMATCH[1]} elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then arch=${BASH_REMATCH[1]} + elif [[ $line =~ ^machine\ *=\ *(.*)$ ]]; then + machine=${BASH_REMATCH[1]} elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then check=${BASH_REMATCH[1]} elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then @@ -67,7 +71,7 @@ function for_each_unittest() fi done if [ -n "${testname}" ]; then - $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout" fi exec {fd}<&- } diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 255e756f2..a66940ead 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -30,7 +30,7 @@ premature_failure() get_cmdline() { local kernel=$1 - echo "TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts" + echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts" } skip_nodefault() @@ -78,9 +78,10 @@ function run() local kernel="$4" local opts="$5" local arch="$6" - local check="${CHECK:-$7}" - local accel="$8" - local timeout="${9:-$TIMEOUT}" # unittests.cfg overrides the default + local machine="$7" + local check="${CHECK:-$8}" + local accel="$9" + local timeout="${10:-$TIMEOUT}" # unittests.cfg overrides the default if [ "${CONFIG_EFI}" == "y" ]; then kernel=${kernel/%.flat/.efi} @@ -114,6 +115,13 @@ function run() return 2 fi + if [ -n "$machine" ] && [ -n "$MACHINE" ] && [ "$machine" != "$MACHINE" ]; then + print_result "SKIP" $testname "" "$machine only" + return 2 + elif [ -n "$MACHINE" ]; then + machine="$MACHINE" + fi + if [ -n "$accel" ] && [ -n "$ACCEL" ] && [ "$accel" != "$ACCEL" ]; then print_result "SKIP" $testname "" "$accel only, but ACCEL=$ACCEL" return 2 From patchwork Tue Mar 19 07:59:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ZaN31w7s; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPYS34w3z1yWn for ; Tue, 19 Mar 2024 19:10:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ZaN31w7s; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPYS1zqZz3dWZ for ; Tue, 19 Mar 2024 19:10:52 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=ZaN31w7s; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 4TzPKY22v7z3vXP for ; Tue, 19 Mar 2024 19:00:33 +1100 (AEDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6e6b54a28ebso5147187b3a.2 for ; Tue, 19 Mar 2024 01:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835231; x=1711440031; darn=lists.ozlabs.org; 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=iE7qlIRnEcs8kYKgLfZ1UH5UWYqf3U0H7OylMM9X6hk=; b=ZaN31w7sbPKUi29j+MWoSnPBaeXCWaDyVCl1bYGWhuB6sgcK3r5yHkEtZ8+B29bCcO kE1Cmh3yGZth/HNYWXyImc5bNuDHaAqxf5FbhL7SqyGiw3AHd4/cLDATLr+Rw2I+Q+xZ +IMANblB009i9p6IzbvNeICBK1sQaUwNBCpCxHTw4Zrihc6ur3yyJ2Ght6Y3js38rq7t nUDOl87GYWwz5Uc1Yw8r+wnJcEWpYVM5gN02CPdgP9e7rw/zhZyQBGw8mxqdgXo/VMm/ HgE7oWUuQTd2Cdf+3YbnY2vTdDeF3v016rEo1D6Ug6bVlWPDdsWAynY2U8FHgnFXItoL jRQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835231; x=1711440031; 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=iE7qlIRnEcs8kYKgLfZ1UH5UWYqf3U0H7OylMM9X6hk=; b=mnx1GaUiP91MY92uePBIPl/yvmnOBGaCwex7RcUE/g5CMv/UVvq/ggUXOIDFRwi1P2 c5+/oMlpyETkkaN0tfk1dUtPk3+Y105VBUQ5f1AthGvNZyPpfOvCAsEadGUoVMgllivW kFnwL8M8VVtSYrwPV6/DvoFohHkwpF/6jsUSamJPBmRubWuVm+c44VwI6RtroIuVO4tv dt00dwBkaPupDAO5c77KF3Jk6BsVnDaNnr4MSCfcqtFvnBK+pwXruGEY3Mu0f2EJhmaZ W5P+AXgZd2GHqvR8tnaW4spEDwMX2rh98EAenHJBHHFEeCjXzAAzIo6mNQhQe3m4okPV KGgw== X-Forwarded-Encrypted: i=1; AJvYcCVr+6zn9JtvX69uIJnLVgzjSWvbsF3TmRnzJs5ExI14If8xQgsuV1qj4xk4p4FoNRFY5aOGf6j9Zrf/O7vuqvhSHIAUi0TPr9hItuaJig== X-Gm-Message-State: AOJu0Yx806rGfwdMS7MA9MRz9aMRU9BdmVo4fkWBGaj4wOyHq+DrfQvF olqEHH1pXpmRRRjWbp0ZyWhv+SIV7VuJhsdMh9mkfzt7wqbp1LTu X-Google-Smtp-Source: AGHT+IE3j83vagr9YQNSHx4O3hggYW3w01Qxw3BclgKX6y9IBAmrQryPE+Xgc1ShN/cEbvm0lP5Q4g== X-Received: by 2002:a05:6a00:b4c:b0:6e6:f799:5480 with SMTP id p12-20020a056a000b4c00b006e6f7995480mr12594586pfo.4.1710835230661; Tue, 19 Mar 2024 01:00:30 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:30 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 15/35] scripts: Accommodate powerpc powernv machine differences Date: Tue, 19 Mar 2024 17:59:06 +1000 Message-ID: <20240319075926.2422707-16-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The QEMU powerpc powernv machine has minor differences that must be accommodated for in output parsing: - Summary parsing must search more lines of output for the summary line, to accommodate OPAL message on shutdown. - Premature failure testing must tolerate case differences in kernel load error message. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- powerpc/unittests.cfg | 1 + scripts/runtime.bash | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 432c81d58..4929e71a1 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -4,6 +4,7 @@ # powerpc specifics: # # file = .elf # powerpc uses .elf files +# machine = pseries|powernv ############################################################################## # diff --git a/scripts/runtime.bash b/scripts/runtime.bash index a66940ead..e4ad1962f 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -9,7 +9,7 @@ FAIL() { echo -ne "\e[31mFAIL\e[0m"; } extract_summary() { local cr=$'\r' - tail -3 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/'"$cr"'\{0,1\}$/)/' + tail -5 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/'"$cr"'\{0,1\}$/)/' } # We assume that QEMU is going to work if it tried to load the kernel @@ -18,7 +18,9 @@ premature_failure() local log="$(eval "$(get_cmdline _NO_FILE_4Uhere_)" 2>&1)" echo "$log" | grep "_NO_FILE_4Uhere_" | - grep -q -e "could not \(load\|open\) kernel" -e "error loading" -e "failed to load" && + grep -q -e "[Cc]ould not \(load\|open\) kernel" \ + -e "error loading" \ + -e "failed to load" && return 1 RUNTIME_log_stderr <<< "$log" From patchwork Tue Mar 19 07:59:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FXmW4C/W; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPZF5ZpWz1yWn for ; Tue, 19 Mar 2024 19:11:33 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FXmW4C/W; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPZF3B6jz3vxB for ; Tue, 19 Mar 2024 19:11:33 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=FXmW4C/W; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::235; helo=mail-oi1-x235.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (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 4TzPKc5rs8z3vZ3 for ; Tue, 19 Mar 2024 19:00:36 +1100 (AEDT) Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3bbbc6e51d0so3513211b6e.3 for ; Tue, 19 Mar 2024 01:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835235; x=1711440035; darn=lists.ozlabs.org; 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=A/6DqvhkTh1Tmy+OsiBBzZYDchefCUva9404sTCS9R4=; b=FXmW4C/Wti30K4b0HWmv80Orcn0M10VTA8dWIOeFLt4v9Je4m3UMBVvUAnwSaqbO2s ueQ7JBV1LccRsyTfHDC3VSBugAI+Ov3zQrXZj5ofe71G+r4vbE3EMMdA+pwNGkXFMh4P CDSimwdsCNYlOwBmYr4ePvCKOHVTWy53qM6q0E23MuGjhuWpvyArqMf6EHBl0z7QzCGg aYJU1VG35cG2iTwDLDKwsgoK9N8P3CCvQCwxe7aX1xPpK0J0xmS8cQSYUIwHW7gTKf7u NYNLfHN2thiMUBNBr+5CSXz+ogyuF40VeBn64m3Cl+fGGINEa77MQ4TabvKaoq/4PR/E 0iBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835235; x=1711440035; 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=A/6DqvhkTh1Tmy+OsiBBzZYDchefCUva9404sTCS9R4=; b=TEUNRW/WcLlejC4pKhqoSmHXKCr/E+EiQr4xLIlObn+fEbB9hOkyJEiNRxXVNq1bVw AOrQ3EhDQToDbvtHmGY4viEL+DJcPiA/ajQQeVzjXNaV8jPCTU3P26zvvcD+5UDkiLsU xtRGsnRky8qNOSUmBO2555TstzkEhSPR9YQY2tpqInyVhDcxgblAVYB2+27mmfHwCDF3 Xl0Tant6a0+7MCeJeK5XWIiR7448hDUu6QVl1eIs2vUUPlZdhSkV3zKLYwwSZ3Y0Yz/8 QRyDFBMuD07Mw+T73qvXiVa77Tb0jTPsRjAyaUoa4MEJybc7pjJYvEzhnBNhtxJ5GpyZ 12eQ== X-Forwarded-Encrypted: i=1; AJvYcCXLVj+nmiwKweDsawvUVbrIwmK210HfQfiYyoldvSJmE+XdHjctpF8DuJF9YJdOnA8EXbgf36w87OO2r55o/YZV472H+CktLIMJu4fuMQ== X-Gm-Message-State: AOJu0Yyt7SSa5+gUQumqxdxwiDlNhey5INOjB4WDVsKH0JFZT35Cwtfe WsENIXNbedg6XVn73rmhZToPLROXXMWIDXljkkBYqTDzZs1AuOx8 X-Google-Smtp-Source: AGHT+IEinN0aP5a5VnLQgVv6iEJ8+FJR6SajiFvZvNkRXcLWGAgjAVTzopkl20NxqrXZljs9vhutyQ== X-Received: by 2002:a05:6808:318c:b0:3c2:3f90:1aa0 with SMTP id cd12-20020a056808318c00b003c23f901aa0mr19090650oib.39.1710835234702; Tue, 19 Mar 2024 01:00:34 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:34 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 16/35] powerpc: Support powernv machine with QEMU TCG Date: Tue, 19 Mar 2024 17:59:07 +1000 Message-ID: <20240319075926.2422707-17-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add support for QEMU's powernv machine. This uses standard firmware (skiboot) rather than a minimal firmware shim. Reviewed-by: Cédric Le Goater Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 23 +++++++++++ lib/powerpc/asm/reg.h | 4 ++ lib/powerpc/hcall.c | 4 +- lib/powerpc/io.c | 27 ++++++++++++- lib/powerpc/io.h | 6 +++ lib/powerpc/processor.c | 37 ++++++++++++++++++ lib/powerpc/setup.c | 14 +++++-- lib/ppc64/asm/opal.h | 15 ++++++++ lib/ppc64/opal-calls.S | 50 ++++++++++++++++++++++++ lib/ppc64/opal.c | 76 +++++++++++++++++++++++++++++++++++++ powerpc/Makefile.ppc64 | 2 + powerpc/cstart64.S | 7 ++++ powerpc/run | 42 ++++++++++++++++---- powerpc/unittests.cfg | 10 ++++- 14 files changed, 301 insertions(+), 16 deletions(-) create mode 100644 lib/ppc64/asm/opal.h create mode 100644 lib/ppc64/opal-calls.S create mode 100644 lib/ppc64/opal.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index e415f9235..9d8061962 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -10,6 +10,8 @@ void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *); void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ +extern bool cpu_has_hv; + static inline uint64_t mfspr(int nr) { uint64_t ret; @@ -38,4 +40,25 @@ static inline void mtmsr(uint64_t msr) asm volatile ("mtmsrd %[msr]" :: [msr] "r" (msr) : "memory"); } +/* + * This returns true on PowerNV / OPAL machines which run in hypervisor + * mode. False on pseries / PAPR machines that run in guest mode. + */ +static inline bool machine_is_powernv(void) +{ + return cpu_has_hv; +} + +/* + * This returns true on pseries / PAPR / KVM machines which run under a + * hypervisor or QEMU pseries machine. False for PowerNV / OPAL. + */ +static inline bool machine_is_pseries(void) +{ + return !machine_is_powernv(); +} + +void enable_mcheck(void); +void disable_mcheck(void); + #endif /* _ASMPOWERPC_PROCESSOR_H_ */ diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index c80b32059..782e75527 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -30,7 +30,11 @@ #define MMCR0_PMAO UL(0x00000080) /* Machine State Register definitions: */ +#define MSR_LE_BIT 0 #define MSR_EE_BIT 15 /* External Interrupts Enable */ +#define MSR_HV_BIT 60 /* Hypervisor mode */ #define MSR_SF_BIT 63 /* 64-bit mode */ +#define MSR_ME UL(0x1000) + #endif diff --git a/lib/powerpc/hcall.c b/lib/powerpc/hcall.c index b4d39ac65..45f201315 100644 --- a/lib/powerpc/hcall.c +++ b/lib/powerpc/hcall.c @@ -25,7 +25,7 @@ int hcall_have_broken_sc1(void) return r3 == (unsigned long)H_PRIVILEGE; } -void putchar(int c) +void papr_putchar(int c) { unsigned long vty = 0; /* 0 == default */ unsigned long nr_chars = 1; @@ -34,7 +34,7 @@ void putchar(int c) hcall(H_PUT_TERM_CHAR, vty, nr_chars, chars); } -int __getchar(void) +int __papr_getchar(void) { register unsigned long r3 asm("r3") = H_GET_TERM_CHAR; register unsigned long r4 asm("r4") = 0; /* 0 == default vty */ diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c index a381688bc..ab7bb843c 100644 --- a/lib/powerpc/io.c +++ b/lib/powerpc/io.c @@ -9,13 +9,33 @@ #include #include #include +#include #include "io.h" static struct spinlock print_lock; +void putchar(int c) +{ + if (machine_is_powernv()) + opal_putchar(c); + else + papr_putchar(c); +} + +int __getchar(void) +{ + if (machine_is_powernv()) + return __opal_getchar(); + else + return __papr_getchar(); +} + void io_init(void) { - rtas_init(); + if (machine_is_powernv()) + assert(!opal_init()); + else + rtas_init(); } void puts(const char *s) @@ -38,7 +58,10 @@ void exit(int code) // FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(), // maybe by plugging chr-testdev into a spapr-vty. printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1); - rtas_power_off(); + if (machine_is_powernv()) + opal_power_off(); + else + rtas_power_off(); halt(code); __builtin_unreachable(); } diff --git a/lib/powerpc/io.h b/lib/powerpc/io.h index d4f21ba15..943bf142b 100644 --- a/lib/powerpc/io.h +++ b/lib/powerpc/io.h @@ -8,6 +8,12 @@ #define _POWERPC_IO_H_ extern void io_init(void); +extern int opal_init(void); +extern void opal_power_off(void); extern void putchar(int c); +extern void opal_putchar(int c); +extern void papr_putchar(int c); +extern int __opal_getchar(void); +extern int __papr_getchar(void); #endif diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index 114584024..1b4bb0d61 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -84,6 +84,16 @@ void sleep_tb(uint64_t cycles) { uint64_t start, end, now; + if (!machine_is_pseries()) { + /* + * P9/10 Could use 'stop' to sleep here which would be + * interesting. stop with ESL=0 should be simple enough, ESL=1 + * would require SRESET based wakeup which is more involved. + */ + delay(cycles); + return; + } + start = now = get_tb(); end = start + cycles; @@ -120,3 +130,30 @@ void usleep(uint64_t us) { sleep_tb((us * tb_hz) / 1000000); } + +static void rfid_msr(uint64_t msr) +{ + uint64_t tmp; + + asm volatile( + "mtsrr1 %1 \n\ + bl 0f \n\ + 0: \n\ + mflr %0 \n\ + addi %0,%0,1f-0b \n\ + mtsrr0 %0 \n\ + rfid \n\ + 1: \n" + : "=r"(tmp) : "r"(msr) : "lr"); +} + +void enable_mcheck(void) +{ + /* This is a no-op on pseries */ + rfid_msr(mfmsr() | MSR_ME); +} + +void disable_mcheck(void) +{ + rfid_msr(mfmsr() & ~MSR_ME); +} diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index d98f66fae..89e5157f2 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "io.h" @@ -85,6 +86,8 @@ static void cpu_set(int fdtnode, u64 regval, void *info) } } +bool cpu_has_hv; + static void cpu_init(void) { struct cpu_set_params params; @@ -98,12 +101,13 @@ static void cpu_init(void) tb_hz = params.tb_hz; /* Interrupt Endianness */ - + if (machine_is_pseries()) { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - hcall(H_SET_MODE, 1, 4, 0, 0); + hcall(H_SET_MODE, 1, 4, 0, 0); #else - hcall(H_SET_MODE, 0, 4, 0, 0); + hcall(H_SET_MODE, 0, 4, 0, 0); #endif + } } static void mem_init(phys_addr_t freemem_start) @@ -159,6 +163,10 @@ void setup(const void *fdt) u32 fdt_size; int ret; + cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); + + enable_mcheck(); + /* * Before calling mem_init we need to move the fdt and initrd * to safe locations. We move them to construct the memory diff --git a/lib/ppc64/asm/opal.h b/lib/ppc64/asm/opal.h new file mode 100644 index 000000000..de64e2c8d --- /dev/null +++ b/lib/ppc64/asm/opal.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASMPPC64_OPAL_H_ +#define _ASMPPC64_OPAL_H_ + +#define OPAL_SUCCESS 0 + +#define OPAL_CONSOLE_WRITE 1 +#define OPAL_CONSOLE_READ 2 +#define OPAL_CEC_POWER_DOWN 5 +#define OPAL_POLL_EVENTS 10 +#define OPAL_REINIT_CPUS 70 +# define OPAL_REINIT_CPUS_HILE_BE (1 << 0) +# define OPAL_REINIT_CPUS_HILE_LE (1 << 1) + +#endif diff --git a/lib/ppc64/opal-calls.S b/lib/ppc64/opal-calls.S new file mode 100644 index 000000000..8cb4c3e91 --- /dev/null +++ b/lib/ppc64/opal-calls.S @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2016 IBM Corporation. + */ + +#include + + .text + .globl opal_call +opal_call: + mr r0,r3 + mr r3,r4 + mr r4,r5 + mr r5,r6 + mr r6,r7 + mflr r11 + std r11,16(r1) + mfcr r12 + stw r12,8(r1) + std r2,-8(r1) /* use redzone */ + + /* Set opal return address */ + LOAD_REG_ADDR(r11, opal_return) + mtlr r11 + mfmsr r12 + std r12,-16(r1) /* use redzone */ + + /* switch to BE when we enter OPAL */ + li r11,(1 << MSR_LE_BIT) + ori r11,r11,(1 << MSR_EE_BIT) + andc r12,r12,r11 + mtspr SPR_HSRR1,r12 + + /* load the opal call entry point and base */ + LOAD_REG_ADDR(r11, opal) + ld r12,8(r11) + ld r2,0(r11) + mtspr SPR_HSRR0,r12 + hrfid + +opal_return: + FIXUP_ENDIAN + ld r12,-16(r1) /* use redzone */ + mtmsrd r12 + ld r2,-8(r1) /* use redzone */ + lwz r11,8(r1); + ld r12,16(r1) + mtcr r11; + mtlr r12 + blr diff --git a/lib/ppc64/opal.c b/lib/ppc64/opal.c new file mode 100644 index 000000000..63fe42ae6 --- /dev/null +++ b/lib/ppc64/opal.c @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * OPAL call helpers + */ +#include +#include +#include +#include +#include +#include "../powerpc/io.h" + +struct opal { + uint64_t base; + uint64_t entry; +} opal; + +extern int64_t opal_call(int64_t token, int64_t arg1, int64_t arg2, int64_t arg3); + +int opal_init(void) +{ + const struct fdt_property *prop; + int node, len; + + node = fdt_path_offset(dt_fdt(), "/ibm,opal"); + if (node < 0) + return -1; + + prop = fdt_get_property(dt_fdt(), node, "opal-base-address", &len); + if (!prop) + return -1; + opal.base = fdt64_to_cpu(*(uint64_t *)prop->data); + + prop = fdt_get_property(dt_fdt(), node, "opal-entry-address", &len); + if (!prop) + return -1; + opal.entry = fdt64_to_cpu(*(uint64_t *)prop->data); + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + if (opal_call(OPAL_REINIT_CPUS, OPAL_REINIT_CPUS_HILE_LE, 0, 0) != OPAL_SUCCESS) + return -1; +#endif + + return 0; +} + +extern void opal_power_off(void) +{ + opal_call(OPAL_CEC_POWER_DOWN, 0, 0, 0); + while (true) + opal_call(OPAL_POLL_EVENTS, 0, 0, 0); +} + +void opal_putchar(int c) +{ + unsigned long vty = 0; /* 0 == default */ + unsigned long nr_chars = cpu_to_be64(1); + char ch = c; + + opal_call(OPAL_CONSOLE_WRITE, (int64_t)vty, (int64_t)&nr_chars, (int64_t)&ch); +} + +int __opal_getchar(void) +{ + unsigned long vty = 0; /* 0 == default */ + unsigned long nr_chars = cpu_to_be64(1); + char ch; + int rc; + + rc = opal_call(OPAL_CONSOLE_READ, (int64_t)vty, (int64_t)&nr_chars, (int64_t)&ch); + if (rc != OPAL_SUCCESS) + return -1; + if (nr_chars == 0) + return -1; + + return ch; +} diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 index eb682c226..a18a9628f 100644 --- a/powerpc/Makefile.ppc64 +++ b/powerpc/Makefile.ppc64 @@ -18,6 +18,8 @@ reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 cflatobjs += lib/ppc64/stack.o +cflatobjs += lib/ppc64/opal.o +cflatobjs += lib/ppc64/opal-calls.o # ppc64 specific tests tests = $(TEST_DIR)/spapr_vpa.elf diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index 07d297f61..405cb0561 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -97,6 +97,13 @@ start: sync isync + /* powernv machine does not check broken_sc1 */ + mfmsr r3 + li r4,1 + sldi r4,r4,MSR_HV_BIT + and. r3,r3,r4 + bne 1f + /* patch sc1 if needed */ bl hcall_have_broken_sc1 cmpwi r3, 0 diff --git a/powerpc/run b/powerpc/run index 5cdb94194..172f32a46 100755 --- a/powerpc/run +++ b/powerpc/run @@ -1,5 +1,14 @@ #!/usr/bin/env bash +get_qemu_machine () +{ + if [ "$MACHINE" ]; then + echo $MACHINE + else + echo pseries + fi +} + if [ -z "$KUT_STANDALONE" ]; then if [ ! -f config.mak ]; then echo "run ./configure && make first. See ./configure -h" @@ -11,24 +20,41 @@ fi set_qemu_accelerator || exit $? +MACHINE=$(get_qemu_machine) || + exit $? + +if [[ "$MACHINE" == "powernv"* ]] && [ "$ACCEL" = "kvm" ]; then + echo "PowerNV machine does not support KVM. ACCEL=tcg must be specified." + exit 2 +fi + qemu=$(search_qemu_binary) || exit $? -if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then - echo "$qemu doesn't support pSeries ('-machine pseries'). Exiting." +if ! $qemu -machine '?' 2>&1 | grep $MACHINE > /dev/null; then + echo "$qemu doesn't support '-machine $MACHINE'. Exiting." exit 2 fi -M='-machine pseries' +M="-machine $MACHINE" M+=",accel=$ACCEL$ACCEL_PROPS" +B="" +D="" + +if [[ "$MACHINE" == "pseries"* ]] ; then + if [[ "$ACCEL" == "tcg" ]] ; then + M+=",cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off" + elif [[ "$ACCEL" == "kvm" ]] ; then + M+=",cap-ccf-assist=off" + fi + B+="-bios $FIRMWARE" +fi -if [[ "$ACCEL" == "tcg" ]] ; then - M+=",cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off" -elif [[ "$ACCEL" == "kvm" ]] ; then - M+=",cap-ccf-assist=off" +if [[ "$MACHINE" == "powernv"* ]] ; then + D+="-device ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10" fi -command="$qemu -nodefaults $M -bios $FIRMWARE" +command="$qemu -nodefaults $M $B $D" command+=" -display none -serial stdio -kernel" command="$(migration_cmd) $(timeout_cmd) $command" diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 4929e71a1..3c3783ba6 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -15,11 +15,12 @@ [selftest-setup] file = selftest.elf smp = 2 -extra_params = -m 256 -append 'setup smp=2 mem=256' +extra_params = -m 1g -append 'setup smp=2 mem=1024' groups = selftest [selftest-migration] file = selftest-migration.elf +machine = pseries groups = selftest migration # TODO: Remove accel=kvm once the following TCG migration fix has been merged: # https://lore.kernel.org/qemu-devel/20240219061731.232570-1-npiggin@gmail.com/ @@ -40,24 +41,29 @@ groups = migration [spapr_hcall] file = spapr_hcall.elf +machine = pseries [spapr_vpa] file = spapr_vpa.elf +machine = pseries [rtas-get-time-of-day] file = rtas.elf +machine = pseries timeout = 5 extra_params = -append "get-time-of-day date=$(date +%s)" groups = rtas [rtas-get-time-of-day-base] file = rtas.elf +machine = pseries timeout = 5 extra_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)" groups = rtas [rtas-set-time-of-day] file = rtas.elf +machine = pseries extra_params = -append "set-time-of-day" timeout = 5 groups = rtas @@ -67,6 +73,7 @@ file = emulator.elf [h_cede_tm] file = tm.elf +machine = pseries accel = kvm smp = 2,threads=2 extra_params = -machine cap-htm=on -append "h_cede_tm" @@ -77,5 +84,6 @@ file = sprs.elf [sprs-migration] file = sprs.elf +machine = pseries extra_params = -append '-w' groups = migration From patchwork Tue Mar 19 07:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FNWLF8QV; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPb32T7Dz1yWn for ; Tue, 19 Mar 2024 19:12:15 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FNWLF8QV; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPb31jBZz3vy5 for ; Tue, 19 Mar 2024 19:12:15 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=FNWLF8QV; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2001:4860:4864:20::30; helo=mail-oa1-x30.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) (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 4TzPKk5jzRz3vZ7 for ; Tue, 19 Mar 2024 19:00:42 +1100 (AEDT) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-2297d0d6013so307220fac.0 for ; Tue, 19 Mar 2024 01:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835240; x=1711440040; darn=lists.ozlabs.org; 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=VtLN1scLK9iq8iGSlvZdRb8xYUKfqrTfHAWG3UXIB58=; b=FNWLF8QVkaMRIZrTSQK9PuYvEBk2msk9lqwKYnOYLHN3iBLM9YSPcuGNJ8F9jcyzeX rjmCmIkApV7bbRQazV3rDo2QlFE/eVJ5cqVgPt1/RJ3mh2rCWIQzSVDVLCqwEkoGMR1h HhPkmg8b/fsJSkmAQt5OmzWz2W0vCRGZ5BYSzrKPy0llL0MZg7cuQElfdE2mBbHmDrap q9G7G3u+SjlznxGZ5HFpV5OxVzV/0dicvRIYgeQP7Dn217diIgnxTrCkeXnn42a6XQsk uA0IC91YAdhJksbURWJNXwrI56Gdf54LiAOommaIMiYYl+kR2roh9HXc+gvsLSoliSqP j48Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835240; x=1711440040; 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=VtLN1scLK9iq8iGSlvZdRb8xYUKfqrTfHAWG3UXIB58=; b=Y1sToqtzjALHskqKsvDTWKwtOZ6CY3v5WcMmulhaANqgukFRNaTqs8IqOf0ShZq93v D855nnrgr7+pFPpvSWp9qfJ24bIfCDMS3oWrR8B63TqjtRY8zS3zFaChdzKIivP0Zzqc RwDVgiZVRYohISkUuXbB/OjGSnGD6vV7lmE36PuxOpHfz+APoQdF6pqsgvoK4ClqK4pS eCDOjsZvhjQkUhyGobeHJMech9eiMYoHdmTz6HfiTtFrc3YrIkxq8PEtuhlkw3RsYKOz Fk4N9Khyi+RL64qnSPPJwCtfcA3H3FewbyRbPr4I0bIlVo9VkNRyLfXc1i6Hvm+pdftF nZKg== X-Forwarded-Encrypted: i=1; AJvYcCVWz4qTzOda/8bjhO3NtKCF0lqD7hpQheWnspjB1TVu0PUNAlzL3LLZ6qeILVZjl/TjxzmVgNwknH3S6u4jpT2ZmgzDpVY9KvyJYXzurg== X-Gm-Message-State: AOJu0YxZWK5pkospcvsBjgM7Oca/IjHpAGC2tVswpXa4bUmqFf3ccHw7 HeIOXyN/sWp/lO7cffHAAPk1XR66uliuhB9GjeU7lzyRKJXJ8CCJ8aSUx8iAG6M= X-Google-Smtp-Source: AGHT+IGlWKOKRt3F1gQ7vnh1VTi5A2f1z4cQOP1avw4yFBk9YAoWjGjQRXOfv6o6wGXqph9/37jrtA== X-Received: by 2002:a05:6870:13c9:b0:220:d5cb:1450 with SMTP id 9-20020a05687013c900b00220d5cb1450mr10380882oat.10.1710835238705; Tue, 19 Mar 2024 01:00:38 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:38 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 17/35] powerpc: Fix emulator illegal instruction test for powernv Date: Tue, 19 Mar 2024 17:59:08 +1000 Message-ID: <20240319075926.2422707-18-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Illegal instructions cause 0xe40 (HEAI) interrupts rather than program interrupts. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 1 + lib/powerpc/setup.c | 13 +++++++++++++ powerpc/emulator.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index 9d8061962..cf1b9d8ff 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -11,6 +11,7 @@ void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ extern bool cpu_has_hv; +extern bool cpu_has_heai; static inline uint64_t mfspr(int nr) { diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 89e5157f2..3c81aee9e 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -87,6 +87,7 @@ static void cpu_set(int fdtnode, u64 regval, void *info) } bool cpu_has_hv; +bool cpu_has_heai; static void cpu_init(void) { @@ -108,6 +109,18 @@ static void cpu_init(void) hcall(H_SET_MODE, 0, 4, 0, 0); #endif } + + switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { + case PVR_VER_POWER10: + case PVR_VER_POWER9: + case PVR_VER_POWER8E: + case PVR_VER_POWER8NVL: + case PVR_VER_POWER8: + cpu_has_heai = true; + break; + default: + break; + } } static void mem_init(phys_addr_t freemem_start) diff --git a/powerpc/emulator.c b/powerpc/emulator.c index 39dd59645..af5174944 100644 --- a/powerpc/emulator.c +++ b/powerpc/emulator.c @@ -31,6 +31,20 @@ static void program_check_handler(struct pt_regs *regs, void *opaque) regs->nip += 4; } +static void heai_handler(struct pt_regs *regs, void *opaque) +{ + int *data = opaque; + + if (verbose) { + printf("Detected invalid instruction %#018lx: %08x\n", + regs->nip, *(uint32_t*)regs->nip); + } + + *data = 8; /* Illegal instruction */ + + regs->nip += 4; +} + static void alignment_handler(struct pt_regs *regs, void *opaque) { int *data = opaque; @@ -363,6 +377,8 @@ int main(int argc, char **argv) int i; handle_exception(0x700, program_check_handler, (void *)&is_invalid); + if (cpu_has_heai) + handle_exception(0xe40, heai_handler, (void *)&is_invalid); handle_exception(0x600, alignment_handler, (void *)&alignment); for (i = 1; i < argc; i++) { From patchwork Tue Mar 19 07:59:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gTW132GW; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPbz4Vwlz1yWn for ; Tue, 19 Mar 2024 19:13:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gTW132GW; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPbz21Pwz3vqR for ; Tue, 19 Mar 2024 19:13:03 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=gTW132GW; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c33; helo=mail-oo1-xc33.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) (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 4TzPKn58rVz3vZK for ; Tue, 19 Mar 2024 19:00:45 +1100 (AEDT) Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5a46b28a77dso3015228eaf.1 for ; Tue, 19 Mar 2024 01:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835242; x=1711440042; darn=lists.ozlabs.org; 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=56iBudlm9U8d1gus42bi1dKHG12FVRnvk/I1w3JRqyc=; b=gTW132GWCPpwozDNi9hB6+1wtGLj7QATdz/yqSJ6rXXOvq6nSZOedT2QKfYACHFDzY WSJGOR6Grr+0yiq4XV2kWFAwpfgZk5KRP/uoe8UlRA/H78vBSaHuAGmmdeEXzsruAKmH dqAkTfE919aX0ZFKPMTREnTXzy1PVH7cplNUW42aEFNkkcuGYU+qS16eG5Z9+C2dc+OM oNGtXVajCLQwOrJGvEt/PjJiTekNw8siONmR2NA3vCBYpDUv8N9E2nSk5L5VKy5loeJE 7vZYOyQ7SUNrEonWEQT/UR/AnutsCIgpAjy3Wjo5ytvuZMszFkDQiUMEsn/efRuAnVZB yAkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835242; x=1711440042; 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=56iBudlm9U8d1gus42bi1dKHG12FVRnvk/I1w3JRqyc=; b=KiG4D6e5yg/G9JaJqgzRma0YAsSxMa0kEGWf79C86QVsQrioYXALWJPduEjOUe0NpO b5WzWyTmPOfu8mfeyuYnYue8zNmw4A1jnjUah5JyGER72TS3BCgjvuX3HUVbchjOVk/M /3gK0DmaiouR0bUaPbxva1rUfkDtH4OpwWCawFZ5v+vSKldG0sbcQhJ7VMUvViS6w0nb SgTxg7yUdpxuE6YBkJIV1cDUTO/bohm6GO0FkWjP1IswXKpy96OmbK1Bnc1OGeIBYG+N ALAzflKYUAIGd/jzHQXH57KM2E7FS7oXMmUXlJLwynAuZPNt1/pPLaUdcNdrX7GMugfc jFJg== X-Forwarded-Encrypted: i=1; AJvYcCU47WIDVwxTW6ETvshfHCz+sd8u0oeNK+jZwJ47t1eaK3XuuG7yOsyKfLon91CWlkeuPTAus3aiO95EMgPw2Jl4c9mMLHeJ7XDKwcuiOw== X-Gm-Message-State: AOJu0YznneTW9KqwJ4/J9qhpV++cmIYN/AObozTDJxcex7h/UT+uRAp8 uTUVycpVOZ66fS9yc7kUAZc0CXf/IBar3XfTRVG3ER2P3+LdwQAc X-Google-Smtp-Source: AGHT+IENcluRYOn764yX9kdrqhDitabVcoLdDZNFBA6m80FQCe8kH+MHmByOwdqnFMJLcUcM2UVYxw== X-Received: by 2002:a05:6870:40c7:b0:21e:b2ee:75a4 with SMTP id l7-20020a05687040c700b0021eb2ee75a4mr1948697oal.15.1710835242665; Tue, 19 Mar 2024 01:00:42 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:42 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 18/35] powerpc/sprs: Test hypervisor registers on powernv machine Date: Tue, 19 Mar 2024 17:59:09 +1000 Message-ID: <20240319075926.2422707-19-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This enables HV privilege registers to be tested with the powernv machine. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- powerpc/sprs.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/powerpc/sprs.c b/powerpc/sprs.c index cb1d6c980..0a82418d6 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -199,16 +199,16 @@ static const struct spr sprs_power_common[1024] = { [190] = { "HFSCR", 64, HV_RW, }, [256] = { "VRSAVE", 32, RW, }, [259] = { "SPRG3", 64, RO, }, -[284] = { "TBL", 32, HV_WO, }, -[285] = { "TBU", 32, HV_WO, }, -[286] = { "TBU40", 64, HV_WO, }, +[284] = { "TBL", 32, HV_WO, }, /* Things can go a bit wonky with */ +[285] = { "TBU", 32, HV_WO, }, /* Timebase changing. Should save */ +[286] = { "TBU40", 64, HV_WO, }, /* and restore it. */ [304] = { "HSPRG0", 64, HV_RW, }, [305] = { "HSPRG1", 64, HV_RW, }, [306] = { "HDSISR", 32, HV_RW, SPR_INT, }, [307] = { "HDAR", 64, HV_RW, SPR_INT, }, [308] = { "SPURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, [309] = { "PURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, -[313] = { "HRMOR", 64, HV_RW, }, +[313] = { "HRMOR", 64, HV_RW, SPR_HARNESS, }, /* Harness can't cope with HRMOR changing */ [314] = { "HSRR0", 64, HV_RW, SPR_INT, }, [315] = { "HSRR1", 64, HV_RW, SPR_INT, }, [318] = { "LPCR", 64, HV_RW, }, @@ -306,7 +306,7 @@ static const struct spr sprs_power9_10[1024] = { [921] = { "TSCR", 32, HV_RW, }, [922] = { "TTR", 64, HV_RW, }, [1006]= { "TRACE", 64, WO, }, -[1008]= { "HID", 64, HV_RW, }, +[1008]= { "HID", 64, HV_RW, SPR_HARNESS, }, /* HILE would be unhelpful to change */ }; /* This covers POWER8 and POWER9 PMUs */ @@ -350,6 +350,22 @@ static const struct spr sprs_power10_pmu[1024] = { static struct spr sprs[1024]; +static bool spr_read_perms(int spr) +{ + if (cpu_has_hv) + return !!(sprs[spr].access & SPR_HV_READ); + else + return !!(sprs[spr].access & SPR_OS_READ); +} + +static bool spr_write_perms(int spr) +{ + if (cpu_has_hv) + return !!(sprs[spr].access & SPR_HV_WRITE); + else + return !!(sprs[spr].access & SPR_OS_WRITE); +} + static void setup_sprs(void) { int i; @@ -461,7 +477,7 @@ static void get_sprs(uint64_t *v) int i; for (i = 0; i < 1024; i++) { - if (!(sprs[i].access & SPR_OS_READ)) + if (!spr_read_perms(i)) continue; v[i] = __mfspr(i); } @@ -472,8 +488,9 @@ static void set_sprs(uint64_t val) int i; for (i = 0; i < 1024; i++) { - if (!(sprs[i].access & SPR_OS_WRITE)) + if (!spr_write_perms(i)) continue; + if (sprs[i].type & SPR_HARNESS) continue; __mtspr(i, val); @@ -561,7 +578,7 @@ int main(int argc, char **argv) for (i = 0; i < 1024; i++) { bool pass = true; - if (!(sprs[i].access & SPR_OS_READ)) + if (!spr_read_perms(i)) continue; if (sprs[i].width == 32) { From patchwork Tue Mar 19 07:59:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hMmHiBaF; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPcm1rXsz1yWn for ; Tue, 19 Mar 2024 19:13:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hMmHiBaF; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPcm13WCz3w25 for ; Tue, 19 Mar 2024 19:13:44 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=hMmHiBaF; dkim-atps=neutral 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=lists.ozlabs.org) 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 4TzPKs1L9Qz3vZh for ; Tue, 19 Mar 2024 19:00:48 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso3170760b3a.1 for ; Tue, 19 Mar 2024 01:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835247; x=1711440047; darn=lists.ozlabs.org; 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=s+3RoOfc/EiUQ/8sMOu4GgA6whcTEdJrTaOoRFd5C9o=; b=hMmHiBaFOqcfbO1Jc2hTtTDGkeVwswP/tsxsMZkaPCnC2DrbtP5KEyy+lznk8MuWfv w3YT1zqwf4tIYhbboeFE+f52SKc0v0MTjI+mhAI27iZ/ZqO7H67pfm9iTcMxqkQrGWDB +aX4ObizIqLCEjIJtWO2mY9bDYXf6ZQwpy0wV+iIPcmvKkX/iPIrbD/Opf7PB215LJy8 G0aBiHNymaZ5ogb40ONfifGAl8IzPaqwdAoRTNRIGuBkAoYrFB873syGe3C9+N+G+DST dfHy+VI0UGxD8hauH6ODyjwy+WrA0PQsvDpmLIPzoQt9jKLQpF6gntdtr9Mc5e1vxPOx 1rQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835247; x=1711440047; 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=s+3RoOfc/EiUQ/8sMOu4GgA6whcTEdJrTaOoRFd5C9o=; b=AM18fzGzS2SvecKMwRRiXW1JgY/qMv3rQLmWNfVFjegrAF3JhrIBgDDwbfTMZ9wgcx n5KvUb+UGx1ytfaFncjsQOlYR4mSqGyP0Qv/TSSQajEmpl2lil7JpgjqM2o0Rs6cwBln unyWC9s8g4069mofRZP70EPmbCL9GuqkddW3SLUrSwk3YkbugDC8kds/pIVtWRqrZtED 390qSc8ng+iWjnVjPHTLl3IgD29O1oXMi+agih7MX9kZxI7rZQBNorXtIb2i66RXyYtU qTc4YbDpvZpet6Y1LL0eJV0cpnOawOVmA9EwCQ2OD6o8cHh+hP1alFg0brrteQkC8m9+ q9uQ== X-Forwarded-Encrypted: i=1; AJvYcCWGBP0J4lw1u+gbtyFIyZhgDm9HGT092CXy7wTy9tvp9plJN/bUoX8vkVWJ3HwRtGNcMtnwgZw+Vbd3qLgJCiMOSyVTJCul5hD6WzeDIw== X-Gm-Message-State: AOJu0YwwCfL300/0kVRLn3IGFH8/rRND4Nok+R9Wv4+OPHZXKUv0jzSp GlsiS3jfRxYgCE4YOskeDRRbGcEPIfYbI2TNO2vvyDLGfN1J9Yx9 X-Google-Smtp-Source: AGHT+IEoJ2QYv4qOrrK/lVq7fq9Cz61EqlqwkAbdQgEs9ItG8puo2idHO4Sk7HaN3YX9Wpqm2/OsXQ== X-Received: by 2002:a05:6a21:1508:b0:1a3:54aa:b5dd with SMTP id nq8-20020a056a21150800b001a354aab5ddmr2650151pzb.3.1710835246432; Tue, 19 Mar 2024 01:00:46 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:46 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 19/35] powerpc: general interrupt tests Date: Tue, 19 Mar 2024 17:59:10 +1000 Message-ID: <20240319075926.2422707-20-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add basic testing of various kinds of interrupts, machine check, page fault, illegal, decrementer, trace, syscall, etc. This has a known failure on QEMU TCG pseries machines where MSR[ME] can be incorrectly set to 0. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 4 + lib/powerpc/asm/reg.h | 17 ++ lib/powerpc/setup.c | 11 + lib/ppc64/asm/ptrace.h | 16 ++ powerpc/Makefile.common | 3 +- powerpc/interrupts.c | 414 ++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 3 + 7 files changed, 467 insertions(+), 1 deletion(-) create mode 100644 powerpc/interrupts.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index cf1b9d8ff..eed37d1f4 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -11,7 +11,11 @@ void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ extern bool cpu_has_hv; +extern bool cpu_has_power_mce; +extern bool cpu_has_siar; extern bool cpu_has_heai; +extern bool cpu_has_prefix; +extern bool cpu_has_sc_lev; static inline uint64_t mfspr(int nr) { diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 782e75527..d6097f48f 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -5,8 +5,15 @@ #define UL(x) _AC(x, UL) +#define SPR_DSISR 0x012 +#define SPR_DAR 0x013 +#define SPR_DEC 0x016 #define SPR_SRR0 0x01a #define SPR_SRR1 0x01b +#define SRR1_PREFIX UL(0x20000000) +#define SPR_FSCR 0x099 +#define FSCR_PREFIX UL(0x2000) +#define SPR_HFSCR 0x0be #define SPR_TB 0x10c #define SPR_SPRG0 0x110 #define SPR_SPRG1 0x111 @@ -22,12 +29,17 @@ #define PVR_VER_POWER8 UL(0x004d0000) #define PVR_VER_POWER9 UL(0x004e0000) #define PVR_VER_POWER10 UL(0x00800000) +#define SPR_HDEC 0x136 #define SPR_HSRR0 0x13a #define SPR_HSRR1 0x13b +#define SPR_LPCR 0x13e +#define LPCR_HDICE UL(0x1) +#define SPR_HEIR 0x153 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) #define MMCR0_PMAE UL(0x04000000) #define MMCR0_PMAO UL(0x00000080) +#define SPR_SIAR 0x31c /* Machine State Register definitions: */ #define MSR_LE_BIT 0 @@ -35,6 +47,11 @@ #define MSR_HV_BIT 60 /* Hypervisor mode */ #define MSR_SF_BIT 63 /* 64-bit mode */ +#define MSR_DR UL(0x0010) +#define MSR_IR UL(0x0020) +#define MSR_BE UL(0x0200) /* Branch Trace Enable */ +#define MSR_SE UL(0x0400) /* Single Step Enable */ +#define MSR_EE UL(0x8000) #define MSR_ME UL(0x1000) #endif diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 3c81aee9e..9b665f59c 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -87,7 +87,11 @@ static void cpu_set(int fdtnode, u64 regval, void *info) } bool cpu_has_hv; +bool cpu_has_power_mce; /* POWER CPU machine checks */ +bool cpu_has_siar; bool cpu_has_heai; +bool cpu_has_prefix; +bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ static void cpu_init(void) { @@ -112,15 +116,22 @@ static void cpu_init(void) switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_POWER10: + cpu_has_prefix = true; + cpu_has_sc_lev = true; case PVR_VER_POWER9: case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: case PVR_VER_POWER8: + cpu_has_power_mce = true; cpu_has_heai = true; + cpu_has_siar = true; break; default: break; } + + if (!cpu_has_hv) /* HEIR is HV register */ + cpu_has_heai = false; } static void mem_init(phys_addr_t freemem_start) diff --git a/lib/ppc64/asm/ptrace.h b/lib/ppc64/asm/ptrace.h index 12de7499b..db263a59e 100644 --- a/lib/ppc64/asm/ptrace.h +++ b/lib/ppc64/asm/ptrace.h @@ -5,6 +5,9 @@ #define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */ #ifndef __ASSEMBLY__ + +#include + struct pt_regs { unsigned long gpr[32]; unsigned long nip; @@ -17,6 +20,19 @@ struct pt_regs { unsigned long _pad; /* stack must be 16-byte aligned */ }; +static inline bool regs_is_prefix(volatile struct pt_regs *regs) +{ + return regs->msr & SRR1_PREFIX; +} + +static inline void regs_advance_insn(struct pt_regs *regs) +{ + if (regs_is_prefix(regs)) + regs->nip += 8; + else + regs->nip += 4; +} + #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \ STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE) diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 1e181da69..68165fc25 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -12,7 +12,8 @@ tests-common = \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ $(TEST_DIR)/tm.elf \ - $(TEST_DIR)/sprs.elf + $(TEST_DIR)/sprs.elf \ + $(TEST_DIR)/interrupts.elf tests-all = $(tests-common) $(tests) all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c new file mode 100644 index 000000000..552c48ef2 --- /dev/null +++ b/powerpc/interrupts.c @@ -0,0 +1,414 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test interrupts + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; + +static void mce_handler(struct pt_regs *regs, void *opaque) +{ + bool *is_fetch = opaque; + + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + if (*is_fetch) + regs->nip = regs->link; + else + regs_advance_insn(regs); +} + +static void fault_handler(struct pt_regs *regs, void *opaque) +{ + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + if (regs->trap == 0x400 || regs->trap == 0x480) + regs->nip = regs->link; + else + regs_advance_insn(regs); +} + +static void test_mce(void) +{ + unsigned long addr = -4ULL; + uint8_t tmp; + bool is_fetch; + + report_prefix_push("mce"); + + handle_exception(0x200, mce_handler, &is_fetch); + handle_exception(0x300, fault_handler, NULL); + handle_exception(0x380, fault_handler, NULL); + handle_exception(0x400, fault_handler, NULL); + handle_exception(0x480, fault_handler, NULL); + + if (machine_is_powernv()) { + enable_mcheck(); + } else { + report(mfmsr() & MSR_ME, "pseries machine has MSR[ME]=1"); + if (!(mfmsr() & MSR_ME)) { /* try to fix it */ + enable_mcheck(); + } + if (mfmsr() & MSR_ME) { + disable_mcheck(); + report(mfmsr() & MSR_ME, "pseries is unable to change MSR[ME]"); + if (!(mfmsr() & MSR_ME)) { /* try to fix it */ + enable_mcheck(); + } + } + } + + is_fetch = false; + asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); + + report(got_interrupt, "MCE on access to invalid real address"); + if (got_interrupt) { + report(mfspr(SPR_DAR) == addr, "MCE sets DAR correctly"); + if (cpu_has_power_mce) + report(recorded_regs.msr & (1ULL << 21), "d-side MCE sets SRR1[42]"); + got_interrupt = false; + } + + is_fetch = true; + asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); + report(got_interrupt, "MCE on fetch from invalid real address"); + if (got_interrupt) { + report(recorded_regs.nip == addr, "MCE sets SRR0 correctly"); + if (cpu_has_power_mce) + report(!(recorded_regs.msr & (1ULL << 21)), "i-side MCE clears SRR1[42]"); + got_interrupt = false; + } + + handle_exception(0x200, NULL, NULL); + handle_exception(0x300, NULL, NULL); + handle_exception(0x380, NULL, NULL); + handle_exception(0x400, NULL, NULL); + handle_exception(0x480, NULL, NULL); + + report_prefix_pop(); +} + +static void dseg_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); + regs->msr &= ~MSR_DR; +} + +static void test_dseg(void) +{ + uint64_t msr, tmp; + + report_prefix_push("data segment"); + + /* Some HV start in radix mode and need 0x300 */ + handle_exception(0x300, &dseg_handler, NULL); + handle_exception(0x380, &dseg_handler, NULL); + + asm volatile( +" mfmsr %0 \n \ + ori %0,%0,%2 \n \ + mtmsrd %0 \n \ + lbz %1,0(0) " + : "=r"(msr), "=r"(tmp) : "i"(MSR_DR): "memory"); + + report(got_interrupt, "interrupt on NULL dereference"); + got_interrupt = false; + + handle_exception(0x300, NULL, NULL); + handle_exception(0x380, NULL, NULL); + + report_prefix_pop(); +} + +static void dec_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->msr &= ~MSR_EE; +} + +static void test_dec(void) +{ + uint64_t msr; + uint64_t tb; + + report_prefix_push("decrementer"); + + handle_exception(0x900, &dec_handler, NULL); + + asm volatile( +" mtdec %1 \n \ + mfmsr %0 \n \ + ori %0,%0,%2 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "r"(10000), "i"(MSR_EE): "memory"); + + tb = get_tb(); + while (!got_interrupt) { + if (get_tb() - tb > tb_hz * 5) + break; /* timeout 5s */ + } + + report(got_interrupt, "interrupt on decrementer underflow"); + got_interrupt = false; + + handle_exception(0x900, NULL, NULL); + + if (!machine_is_powernv()) + goto done; /* Skip HV tests */ + + handle_exception(0x980, &dec_handler, NULL); + + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_HDICE); + asm volatile( +" mtspr 0x136,%1 \n \ + mtdec %3 \n \ + mfmsr %0 \n \ + ori %0,%0,%2 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "r"(10000), "i"(MSR_EE), "r"(0x7fffffff): "memory"); + + tb = get_tb(); + while (!got_interrupt) { + if (get_tb() - tb > tb_hz * 5) + break; /* timeout 5s */ + } + + mtspr(SPR_LPCR, mfspr(SPR_LPCR) & ~LPCR_HDICE); + + report(got_interrupt, "interrupt on hdecrementer underflow"); + got_interrupt = false; + + handle_exception(0x980, NULL, NULL); + +done: + report_prefix_pop(); +} + + +static volatile uint64_t recorded_heir; + +static void heai_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); + if (cpu_has_heai) + recorded_heir = mfspr(SPR_HEIR); +} + +static void program_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); +} + +/* + * This tests invalid instruction handling. powernv (HV) should take an + * HEAI interrupt with the HEIR SPR set to the instruction image. pseries + * (guest) should take a program interrupt. CPUs which support prefix + * should report prefix instruction in (H)SRR1[34]. + */ +static void test_illegal(void) +{ + report_prefix_push("illegal instruction"); + + if (machine_is_powernv()) { + handle_exception(0xe40, &heai_handler, NULL); + } else { + handle_exception(0x700, &program_handler, NULL); + } + + asm volatile(".long 0x12345678" ::: "memory"); + report(got_interrupt, "interrupt on invalid instruction"); + got_interrupt = false; + if (cpu_has_heai) + report(recorded_heir == 0x12345678, "HEIR: 0x%08lx", recorded_heir); + report(!regs_is_prefix(&recorded_regs), "(H)SRR1 prefix bit clear"); + + if (cpu_has_prefix) { + asm volatile(".balign 8 ; .long 0x04000123; .long 0x00badc0d"); + report(got_interrupt, "interrupt on invalid prefix instruction"); + got_interrupt = false; + if (cpu_has_heai) + report(recorded_heir == 0x0400012300badc0d, "HEIR: 0x%08lx", recorded_heir); + report(regs_is_prefix(&recorded_regs), "(H)SRR1 prefix bit set"); + } + + handle_exception(0xe40, NULL, NULL); + handle_exception(0x700, NULL, NULL); + + report_prefix_pop(); +} + +static void sc_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); +} + +static void test_sc(void) +{ + report_prefix_push("syscall"); + + handle_exception(0xc00, &sc_handler, NULL); + + asm volatile("sc 0" ::: "memory"); + + report(got_interrupt, "interrupt on sc 0 instruction"); + got_interrupt = false; + if (cpu_has_sc_lev) + report(((recorded_regs.msr >> 20) & 0x3) == 0, "SRR1 set LEV=0"); + if (machine_is_powernv()) { + asm volatile("sc 1" ::: "memory"); + + report(got_interrupt, "interrupt on sc 1 instruction"); + got_interrupt = false; + if (cpu_has_sc_lev) + report(((recorded_regs.msr >> 20) & 0x3) == 1, "SRR1 set LEV=1"); + } + + handle_exception(0xc00, NULL, NULL); + + report_prefix_pop(); +} + + +static void trace_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->msr &= ~(MSR_SE | MSR_BE); +} + +static void program_trace_handler(struct pt_regs *regs, void *data) +{ + regs->msr &= ~(MSR_SE | MSR_BE); + regs->nip += 4; +} + +extern char trace_insn[]; +extern char trace_insn2[]; +extern char trace_insn3[]; +extern char trace_rfid[]; + +static void test_trace(void) +{ + unsigned long msr; + + report_prefix_push("trace"); + + handle_exception(0xd00, &trace_handler, NULL); + + msr = mfmsr() | MSR_SE; + asm volatile( + " mtmsr %0 \n" + ".global trace_insn \n" + "trace_insn: \n" + " nop \n" + : : "r"(msr) : "memory"); + + report(got_interrupt, "interrupt on single step"); + got_interrupt = false; + report(recorded_regs.nip == (unsigned long)trace_insn + 4, + "single step interrupt at the correct address"); + if (cpu_has_siar) + report(mfspr(SPR_SIAR) == (unsigned long)trace_insn, + "single step recorded SIAR at the correct address"); + + msr = mfmsr() | MSR_SE; + asm volatile( + " mtmsr %0 \n" + ".global trace_insn2 \n" + "trace_insn2: \n" + " b 1f \n" + " nop \n" + "1: \n" + : : "r"(msr) : "memory"); + + report(got_interrupt, "interrupt on single step branch"); + got_interrupt = false; + report(recorded_regs.nip == (unsigned long)trace_insn2 + 8, + "single step interrupt at the correct address"); + if (cpu_has_siar) + report(mfspr(SPR_SIAR) == (unsigned long)trace_insn2, + "single step recorded SIAR at the correct address"); + + msr = mfmsr() | MSR_BE; + asm volatile( + " mtmsr %0 \n" + ".global trace_insn3 \n" + "trace_insn3: \n" + " nop \n" + " b 1f \n" + " nop \n" + "1: \n" + : : "r"(msr) : "memory"); + + report(got_interrupt, "interrupt on branch trace"); + got_interrupt = false; + report(recorded_regs.nip == (unsigned long)trace_insn3 + 12, + "branch trace interrupt at the correct address"); + if (cpu_has_siar) + report(mfspr(SPR_SIAR) == (unsigned long)trace_insn3 + 4, + "branch trace recorded SIAR at the correct address"); + + handle_exception(0x700, &program_trace_handler, NULL); + msr = mfmsr() | MSR_SE; + asm volatile( + " mtmsr %0 \n" + " trap \n" + : : "r"(msr) : "memory"); + + report(!got_interrupt, "no interrupt on single step trap"); + got_interrupt = false; + handle_exception(0x700, NULL, NULL); + + msr = mfmsr() | MSR_SE; + mtspr(SPR_SRR0, (unsigned long)trace_rfid); + mtspr(SPR_SRR1, mfmsr()); + asm volatile( + " mtmsr %0 \n" + " rfid \n" + ".global trace_rfid \n" + "trace_rfid: \n" + : : "r"(msr) : "memory"); + + report(!got_interrupt, "no interrupt on single step rfid"); + got_interrupt = false; + handle_exception(0xd00, NULL, NULL); + + report_prefix_pop(); +} + + +int main(int argc, char **argv) +{ + report_prefix_push("interrupts"); + + if (cpu_has_power_mce) + test_mce(); + test_dseg(); + test_illegal(); + test_dec(); + test_sc(); + test_trace(); + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 3c3783ba6..9fdc86b66 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -71,6 +71,9 @@ groups = rtas [emulator] file = emulator.elf +[interrupts] +file = interrupts.elf + [h_cede_tm] file = tm.elf machine = pseries From patchwork Tue Mar 19 07:59:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IAVE/U+v; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPdY5fHcz1yWn for ; Tue, 19 Mar 2024 19:14:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IAVE/U+v; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPdY2b0Qz3w3K for ; Tue, 19 Mar 2024 19:14:25 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=IAVE/U+v; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2001:4860:4864:20::2f; helo=mail-oa1-x2f.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) (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 4TzPKx3qNMz3vb4 for ; Tue, 19 Mar 2024 19:00:53 +1100 (AEDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-222ba2a19bdso1542325fac.1 for ; Tue, 19 Mar 2024 01:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835251; x=1711440051; darn=lists.ozlabs.org; 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=fmYXUw1NFQqCkvaC1UircBJTaa68tPuVL3/2t/uANro=; b=IAVE/U+v8ngULWGfdqMnwQ695q2mSAWTm3azovnG0MVy/ssGbOIu8uiv/HTQWooMhA lODUSqWbEiI4M9ec443+jUdSOII9k8CDhohQ/wjzcqx/y88ZEbycLeAfekkF3Ehw+8H9 Vx+MLEkTggytpf8yvWMDNigX2zr2+ZSpmlYeWeT6ahdfk8h8gwwYnFwpS4SVcvN96gG/ Q11953hZlyPCet/mSStSZF19j0JohseQgAvc3K8LSwR8Ht1zJ1ImQxsI73Cr+hj+uAz7 fCabBqSBB/7yMu7e7De5mJOKZrFD6WSbnUpADZCCQKZsurFycEG6zKtPNG1vdV76IaR6 dGUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835251; x=1711440051; 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=fmYXUw1NFQqCkvaC1UircBJTaa68tPuVL3/2t/uANro=; b=VAd61XQGSiOztr8e9a0ezWKPFuIy7MZnbQZgoMUj7rr9VVLj09b8Ju/25VxB0gkTjv pzjk1DfbyrEkV+zy2uYLRxH5KV8zZUzWLNfs6mIllmkaf/Rv5osW+A43wRSQZm8esVh9 QANDZzMko4p6ri7SppUtqlyAUGSHPz+rIcqhsu0nmQod/FHaKFc8FNh+F7Rfy9PmrUrl LUGTFVnfObmKIP6bKvE0KAdumIciHmzPqI+caM/3vYV9r7U2lJbe8/zBkcGkUebzZ34o Sy4lBTpjl9Mz+AkkHnzZshsNl/0OC+7yy3T316orhGUEwQm9QxgPeiEmoZdPEuXuOoJx p3bg== X-Forwarded-Encrypted: i=1; AJvYcCXw7BDs1701Q3rHoznBfkj0cui5PCFsrlDC1YOhj3ZA8wM5a0UqHrpj89rsq4DsgMTVwnzoq/5FJyFuB/90RovHZoOIiWoIoABCQRHlUQ== X-Gm-Message-State: AOJu0YxpUp8c+0AhHtv7qAnXuZQyaOG8MYTQ16/iJ0CWXctK/nFm6wAk LbB/PSqMTGGns0F0L8CKSXi7nmtNzxoSmjQG31YpiINVCjKYv1Yxn4vAwc1Nti8= X-Google-Smtp-Source: AGHT+IFfHuNzVGIE29NF+n08DtvfpVDdYpSp3yZpBjdFnpuN+dbSWe0Rtn2wUlx4d+yiEmJX+pa07w== X-Received: by 2002:a05:6870:e9a9:b0:21e:8590:6a5 with SMTP id r41-20020a056870e9a900b0021e859006a5mr15351073oao.2.1710835250874; Tue, 19 Mar 2024 01:00:50 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:50 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 20/35] powerpc: Add rtas stop-self support Date: Tue, 19 Mar 2024 17:59:11 +1000 Message-ID: <20240319075926.2422707-21-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In preparation for improved SMP support, add stop-self support to the harness. This is non-trivial because it requires an unlocked rtas call: a CPU can't be holding a spin lock when it goes offline or it will deadlock other CPUs. rtas permits stop-self to be called without serialising all other rtas operations. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/rtas.h | 2 ++ lib/powerpc/rtas.c | 78 +++++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/lib/powerpc/asm/rtas.h b/lib/powerpc/asm/rtas.h index 6fb407a18..364bf9355 100644 --- a/lib/powerpc/asm/rtas.h +++ b/lib/powerpc/asm/rtas.h @@ -23,8 +23,10 @@ struct rtas_args { extern void rtas_init(void); extern int rtas_token(const char *service, uint32_t *token); extern int rtas_call(int token, int nargs, int nret, int *outputs, ...); +extern int rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, int *outputs, ...); extern void rtas_power_off(void); +extern void rtas_stop_self(void); #endif /* __ASSEMBLY__ */ #define RTAS_MSR_MASK 0xfffffffffffffffe diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c index 41c0a243e..b477a38e0 100644 --- a/lib/powerpc/rtas.c +++ b/lib/powerpc/rtas.c @@ -87,40 +87,86 @@ int rtas_token(const char *service, uint32_t *token) return 0; } -int rtas_call(int token, int nargs, int nret, int *outputs, ...) +static void __rtas_call(struct rtas_args *args) { - va_list list; - int ret, i; + enter_rtas(__pa(args)); +} - spin_lock(&rtas_lock); +static int rtas_call_unlocked_va(struct rtas_args *args, + int token, int nargs, int nret, int *outputs, + va_list list) +{ + int ret, i; - rtas_args.token = cpu_to_be32(token); - rtas_args.nargs = cpu_to_be32(nargs); - rtas_args.nret = cpu_to_be32(nret); - rtas_args.rets = &rtas_args.args[nargs]; + args->token = cpu_to_be32(token); + args->nargs = cpu_to_be32(nargs); + args->nret = cpu_to_be32(nret); + args->rets = &args->args[nargs]; - va_start(list, outputs); for (i = 0; i < nargs; ++i) - rtas_args.args[i] = cpu_to_be32(va_arg(list, u32)); - va_end(list); + args->args[i] = cpu_to_be32(va_arg(list, u32)); for (i = 0; i < nret; ++i) - rtas_args.rets[i] = 0; + args->rets[i] = 0; - enter_rtas(__pa(&rtas_args)); + __rtas_call(args); if (nret > 1 && outputs != NULL) for (i = 0; i < nret - 1; ++i) - outputs[i] = be32_to_cpu(rtas_args.rets[i + 1]); + outputs[i] = be32_to_cpu(args->rets[i + 1]); + + ret = nret > 0 ? be32_to_cpu(args->rets[0]) : 0; + + return ret; +} + +int rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, int *outputs, ...) +{ + va_list list; + int ret; - ret = nret > 0 ? be32_to_cpu(rtas_args.rets[0]) : 0; + va_start(list, outputs); + ret = rtas_call_unlocked_va(args, token, nargs, nret, outputs, list); + va_end(list); + + return ret; +} + +int rtas_call(int token, int nargs, int nret, int *outputs, ...) +{ + va_list list; + int ret; + + spin_lock(&rtas_lock); + + va_start(list, outputs); + ret = rtas_call_unlocked_va(&rtas_args, token, nargs, nret, outputs, list); + va_end(list); spin_unlock(&rtas_lock); + return ret; } +void rtas_stop_self(void) +{ + struct rtas_args args; + uint32_t token; + int ret; + + ret = rtas_token("stop-self", &token); + if (ret) { + puts("RTAS stop-self not available\n"); + return; + } + + ret = rtas_call_unlocked(&args, token, 0, 1, NULL); + printf("RTAS stop-self returned %d\n", ret); +} + void rtas_power_off(void) { + struct rtas_args args; uint32_t token; int ret; @@ -130,6 +176,6 @@ void rtas_power_off(void) return; } - ret = rtas_call(token, 2, 1, NULL, -1, -1); + ret = rtas_call_unlocked(&args, token, 2, 1, NULL, -1, -1); printf("RTAS power-off returned %d\n", ret); } From patchwork Tue Mar 19 07:59:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Jmq+2X6F; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPfV2hVLz1yWv for ; Tue, 19 Mar 2024 19:15:14 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Jmq+2X6F; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPfT629dz3w4l for ; Tue, 19 Mar 2024 19:15:13 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=Jmq+2X6F; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c31; helo=mail-oo1-xc31.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) (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 4TzPL1704Sz3vY9 for ; Tue, 19 Mar 2024 19:00:57 +1100 (AEDT) Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5a21859a4b8so2348798eaf.0 for ; Tue, 19 Mar 2024 01:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835255; x=1711440055; darn=lists.ozlabs.org; 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=GGo+1arrsYAVXsfTP4gQ2EL+vABqvISnH52kVRdFyBU=; b=Jmq+2X6F4BpTTB26NgCj43lV69M3F/HgBEU0SAJq4+i81V+IM2awSyinsvE5CAUXzZ hi0pvRXmVdQWCtcW4QQOJ22G2zw2b8MT1XCOlvHTkjD9ZHPn1SF2C3Jpfp7yAol3DhMO HjC8Xme52WN/ZuBPsRRDv71SHOI2VFfjWIkDMbY1i04L5sqvt6Oxb6xMJ2NtrP4BViBL oZSZufX5z6zzRmUXdUVxGjy2kQVQT/TTd5cdypqTZLydw2vKAZPKtbqc0K0llYq/fS8/ n6n+eCEcd/MtwyNBNsVBfygx1gE7Fnq7b9DMdmjL9U5gvLy0W6S0IvLWcbWBu+6eun0U 2O5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835255; x=1711440055; 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=GGo+1arrsYAVXsfTP4gQ2EL+vABqvISnH52kVRdFyBU=; b=QdvPvx403vALAQmyfP6Y24X2AXjV3Jq+wn4Qwrasagh5crPNm5G4de7tcaYsI/5Svl /q1LbA0VifUnArLxNyHJohJv6BefX0gS60/Na+KjLBSe/A+xSpzLyLIVwGZx0vUaUbz5 IeUa16YjCIrRo5bA9tLiJxLVf3/XLMA0hpjrjT8oD96+paO8DSxZURjAwmo0fQWAGUI6 c9p2JtIP4ArGIiT7bY+R99k4CssxeDxwfweCGOV8t8VkidC2IUwknmtCQkhqHNPLTKYU 8a+HNgQaWH8TjHBfYpy9Cp6x4vt5ls1GzYTHutLGfA5vuykmjdnK96/A1giJJfxtOYmW Xyjw== X-Forwarded-Encrypted: i=1; AJvYcCWU9FJA+6L2u+vwqNMjfNIhPtjJ64DQ4/WfdoU0oXN/FNz2VVzX1QuMNvnWbA7HWZJuOjvjvSGUhgylLeLMfPs4afDJzgw7QqF4o1F9Zg== X-Gm-Message-State: AOJu0YyJU/b+IFsqPz9bySrlmwYHLhvcKTbxw0I16Wa4Dz2EsIbGmEsf HYmqQrN9tfMz7UKr9wA+zsVQAaWID2VnvwnTg0JjI+1lOfWB2vyfk5MtGvTCL1I= X-Google-Smtp-Source: AGHT+IFs4elYHLqSQaWxfOpvn0n1iBEA3/4l52mkNvpdgddck5fItF7mXhG/KqTc01Uq87acxqM7Qg== X-Received: by 2002:a05:6820:1629:b0:5a1:78c0:4327 with SMTP id bb41-20020a056820162900b005a178c04327mr13805982oob.4.1710835254929; Tue, 19 Mar 2024 01:00:54 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:54 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 21/35] powerpc: Remove broken SMP exception stack setup Date: Tue, 19 Mar 2024 17:59:12 +1000 Message-ID: <20240319075926.2422707-22-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The exception stack setup does not work correctly for SMP, because it is the boot processor that calls cpu_set() which sets SPRG2 to the exception stack, not the target CPU itself. So secondaries never got their SPRG2 set to a valid exception stack. Remove the SMP code and just set an exception stack for the boot processor. Make the stack 64kB while we're here, to match the size of the regular stack. Signed-off-by: Nicholas Piggin --- lib/powerpc/setup.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 9b665f59c..496af40f8 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -42,10 +42,6 @@ struct cpu_set_params { uint64_t tb_hz; }; -#define EXCEPTION_STACK_SIZE (32*1024) /* 32kB */ - -static char exception_stack[NR_CPUS][EXCEPTION_STACK_SIZE]; - static void cpu_set(int fdtnode, u64 regval, void *info) { static bool read_common_info = false; @@ -56,10 +52,6 @@ static void cpu_set(int fdtnode, u64 regval, void *info) cpus[cpu] = regval; - /* set exception stack address for this CPU (in SPGR0) */ - asm volatile ("mtsprg0 %[addr]" :: - [addr] "r" (exception_stack[cpu + 1])); - if (!read_common_info) { const struct fdt_property *prop; u32 *data; @@ -180,6 +172,10 @@ static void mem_init(phys_addr_t freemem_start) ? __icache_bytes : __dcache_bytes); } +#define EXCEPTION_STACK_SIZE SZ_64K + +static char boot_exception_stack[EXCEPTION_STACK_SIZE]; + void setup(const void *fdt) { void *freemem = &stacktop; @@ -189,6 +185,10 @@ void setup(const void *fdt) cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); + /* set exception stack address for this CPU (in SPGR0) */ + asm volatile ("mtsprg0 %[addr]" :: + [addr] "r" (boot_exception_stack)); + enable_mcheck(); /* From patchwork Tue Mar 19 07:59:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=k7LxATRn; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPgH5PJLz1yWv for ; Tue, 19 Mar 2024 19:15:55 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=k7LxATRn; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPgH1bJTz3vt2 for ; Tue, 19 Mar 2024 19:15:55 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=k7LxATRn; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c29; helo=mail-oo1-xc29.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) (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 4TzPL82KHKz3vby for ; Tue, 19 Mar 2024 19:01:04 +1100 (AEDT) Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5a470320194so2466375eaf.3 for ; Tue, 19 Mar 2024 01:01:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835261; x=1711440061; darn=lists.ozlabs.org; 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=0VAyLVBNs98eyzAZ6tU9po3MJ8lcsuAPyekaTSdXNeg=; b=k7LxATRn97JYhLea1Z2oGADll4I8GIWs1DVuogDbxD+YqLZFH0h5PTVGaJ6BHdynIk ub9Rm8I3Vnp6gBt8LmEgp3IvrfOQ6uoC3OM/UciT27Bo7b+9CEhYdYipvx/4o+m4L9No E43vxEwspBJnHaNZiKui1bjFq+8VQj6LDOOGDNsHyBI00mAMq3qFdUwQDmH/vPM1ORKQ FxM4bCSCf+XtjVvuIFV38aJiYzUN51+mWaa+4hPS/bzMtTdNVQqGoOj1UVo1T0+zWkUz zXarv6+XKefuiCvAw64IFLeNkMnvlcF4Ovoeavp/MdByxEXw8gQ5zkhliRvlY1prT4Lx 0M9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835261; x=1711440061; 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=0VAyLVBNs98eyzAZ6tU9po3MJ8lcsuAPyekaTSdXNeg=; b=rAGI27A3lAI8bS7gcWcQXov7knzwva6Nrhy9mX1QTlPXDR5aVI/aH4pj7edyH12+PN HNdjTGuOmoEa0mNxhymaRb7bDBGr93qFIeFVdWCKCB9LGYgNjhDI/bSZiUVVly7EQ6TI UKPy20YoBSZAsy/sCUlJhqktHu+W7+iJ9nAGrwooSNuAoxSwdkIK933z42eNQ2LP/X5b fxaZlV/52EFsgJ8qU3n+q4JWSRd/IZL4AEnON7tFUiK19tpeFZo4meNQ0sp1VBzxfuWP zsdJw6nYI2g4k4xpwlqM9uS8FB4YzRMjWoI+kBJy3sv00BU3nDDwtYXA1hTxLzMG8a+T qUlg== X-Forwarded-Encrypted: i=1; AJvYcCUPoh3dbJqOmKXfkxmSw6fEEFONOEzYSUM0SPePxWrZQI/ibPJcMvBh6SzjiPjDH2GRqM9ARModYZZBKQlJrFyY50yz0bIXugR1coWYJA== X-Gm-Message-State: AOJu0YzzuLE/VPQnhVXT21MPVhz5LP3w/Tyb9JWV+BaK39byibVwMfD7 rtWlpYRIv2uX0p+5I5kA4+Fjpv896dUHv0x34Hu3adQ6ggXo6Z9p X-Google-Smtp-Source: AGHT+IER5OJcj3/5Kz8fO1aD101lLMaRMXWcnt/KQnM6vB7JwjBpRiMlzvINL7Sym91NrUe84MOEYQ== X-Received: by 2002:a05:6359:4ca6:b0:17e:4b00:843a with SMTP id kk38-20020a0563594ca600b0017e4b00843amr2533435rwc.5.1710835260911; Tue, 19 Mar 2024 01:01:00 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:00:58 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 22/35] powerpc: add SMP and IPI support Date: Tue, 19 Mar 2024 17:59:13 +1000 Message-ID: <20240319075926.2422707-23-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" powerpc SMP support is very primitive and does not set up a first-class runtime environment for secondary CPUs. This reworks SMP support, and provides a complete C and harness environment for the secondaries, including interrupt handling, as well as IPI support. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 23 +++ lib/powerpc/asm/reg.h | 1 + lib/powerpc/asm/setup.h | 2 - lib/powerpc/asm/smp.h | 46 +++-- lib/powerpc/io.c | 15 +- lib/powerpc/processor.c | 7 +- lib/powerpc/setup.c | 90 +++++++--- lib/powerpc/smp.c | 282 +++++++++++++++++++++++++---- lib/ppc64/asm-offsets.c | 7 + lib/ppc64/asm/atomic.h | 6 + lib/ppc64/asm/barrier.h | 3 + lib/ppc64/asm/opal.h | 7 + powerpc/Makefile.common | 1 + powerpc/cstart64.S | 49 ++++- powerpc/selftest.c | 4 +- powerpc/smp.c | 348 ++++++++++++++++++++++++++++++++++++ powerpc/tm.c | 4 +- powerpc/unittests.cfg | 8 + 18 files changed, 818 insertions(+), 85 deletions(-) create mode 100644 lib/ppc64/asm/atomic.h create mode 100644 powerpc/smp.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index eed37d1f4..a3859b5d4 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -16,6 +16,7 @@ extern bool cpu_has_siar; extern bool cpu_has_heai; extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; +extern bool cpu_has_pause_short; static inline uint64_t mfspr(int nr) { @@ -45,6 +46,28 @@ static inline void mtmsr(uint64_t msr) asm volatile ("mtmsrd %[msr]" :: [msr] "r" (msr) : "memory"); } +static inline void local_irq_enable(void) +{ + unsigned long msr; + + asm volatile( +" mfmsr %0 \n \ + ori %0,%0,%1 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "i"(MSR_EE): "memory"); +} + +static inline void local_irq_disable(void) +{ + unsigned long msr; + + asm volatile( +" mfmsr %0 \n \ + andc %0,%0,%1 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "r"(MSR_EE): "memory"); +} + /* * This returns true on PowerNV / OPAL machines which run in hypervisor * mode. False on pseries / PAPR machines that run in guest mode. diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index d6097f48f..d2ca964c4 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -19,6 +19,7 @@ #define SPR_SPRG1 0x111 #define SPR_SPRG2 0x112 #define SPR_SPRG3 0x113 +#define SPR_TBU40 0x11e #define SPR_PVR 0x11f #define PVR_VERSION_MASK UL(0xffff0000) #define PVR_VER_970 UL(0x00390000) diff --git a/lib/powerpc/asm/setup.h b/lib/powerpc/asm/setup.h index cc7cf5e25..9ca318ce6 100644 --- a/lib/powerpc/asm/setup.h +++ b/lib/powerpc/asm/setup.h @@ -8,8 +8,6 @@ #include #define NR_CPUS 8 /* arbitrarily set for now */ -extern u32 cpus[NR_CPUS]; -extern int nr_cpus; extern uint64_t tb_hz; diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index 21940b4bc..4519e5436 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -2,21 +2,45 @@ #define _ASMPOWERPC_SMP_H_ #include +#include -extern int nr_threads; +typedef void (*secondary_entry_fn)(int cpu_id); -struct start_threads { - int nr_threads; - int nr_started; -}; +struct cpu { + unsigned long server_no; + unsigned long stack; + unsigned long exception_stack; + secondary_entry_fn entry; +} __attribute__((packed)); /* used by asm */ -typedef void (*secondary_entry_fn)(void); +extern int nr_cpus_present; +extern int nr_cpus_online; +extern struct cpu cpus[]; -extern void halt(void); +register struct cpu *__current_cpu asm("r13"); +static inline struct cpu *current_cpu(void) +{ + return __current_cpu; +} -extern int start_thread(int cpu_id, secondary_entry_fn entry, uint32_t r3); -extern struct start_threads start_cpu(int cpu_node, secondary_entry_fn entry, - uint32_t r3); -extern bool start_all_cpus(secondary_entry_fn entry, uint32_t r3); +static inline int smp_processor_id(void) +{ + return current_cpu()->server_no; +} + +void cpu_init(struct cpu *cpu, int cpu_id); + +extern void halt(int cpu_id); + +extern bool start_all_cpus(secondary_entry_fn entry); +extern void stop_all_cpus(void); + +struct pt_regs; +void register_ipi(void (*fn)(struct pt_regs *, void *), void *data); +void unregister_ipi(void); +void cpu_init_ipis(void); +void local_ipi_enable(void); +void local_ipi_disable(void); +void send_ipi(int cpu_id); #endif /* _ASMPOWERPC_SMP_H_ */ diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c index ab7bb843c..cb7f2f050 100644 --- a/lib/powerpc/io.c +++ b/lib/powerpc/io.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "io.h" static struct spinlock print_lock; @@ -55,13 +56,17 @@ extern void halt(int code); void exit(int code) { + static int exited = 0; + // FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(), // maybe by plugging chr-testdev into a spapr-vty. - printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1); - if (machine_is_powernv()) - opal_power_off(); - else - rtas_power_off(); + if (atomic_fetch_inc(&exited) == 0) { + printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1); + if (machine_is_powernv()) + opal_power_off(); + else + rtas_power_off(); + } halt(code); __builtin_unreachable(); } diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index 1b4bb0d61..a6ce3c905 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -13,6 +13,7 @@ #include #include #include +#include static struct { void (*func)(struct pt_regs *, void *data); @@ -44,6 +45,8 @@ void do_handle_exception(struct pt_regs *regs) { unsigned char v; + __current_cpu = (struct cpu *)mfspr(SPR_SPRG0); + v = regs->trap >> 5; if (v < 128 && handlers[v].func) { @@ -51,8 +54,8 @@ void do_handle_exception(struct pt_regs *regs) return; } - printf("Unhandled cpu exception %#lx at NIA:0x%016lx MSR:0x%016lx\n", - regs->trap, regs->nip, regs->msr); + printf("Unhandled CPU%d exception %#lx at NIA:0x%016lx MSR:0x%016lx\n", + smp_processor_id(), regs->trap, regs->nip, regs->msr); dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]); abort(); } diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 496af40f8..16f009152 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -2,7 +2,7 @@ * Initialize machine setup information and I/O. * * After running setup() unit tests may query how many cpus they have - * (nr_cpus), how much memory they have (PHYSICAL_END - PHYSICAL_START), + * (nr_cpus_present), how much memory they have (PHYSICAL_END - PHYSICAL_START), * may use dynamic memory allocation (malloc, etc.), printf, and exit. * Finally, argc and argv are also ready to be passed to main(). * @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -28,8 +29,8 @@ extern unsigned long stacktop; char *initrd; u32 initrd_size; -u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) }; -int nr_cpus; +u32 cpu_to_hwid[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) }; +int nr_cpus_present; uint64_t tb_hz; struct mem_region mem_regions[NR_MEM_REGIONS]; @@ -44,13 +45,32 @@ struct cpu_set_params { static void cpu_set(int fdtnode, u64 regval, void *info) { + const struct fdt_property *prop; + u32 *threads; static bool read_common_info = false; struct cpu_set_params *params = info; - int cpu = nr_cpus++; - - assert_msg(cpu < NR_CPUS, "Number cpus exceeds maximum supported (%d).", NR_CPUS); - - cpus[cpu] = regval; + int nr_threads; + int len, i; + + /* Get the id array of threads on this node */ + prop = fdt_get_property(dt_fdt(), fdtnode, + "ibm,ppc-interrupt-server#s", &len); + assert(prop); + + nr_threads = len >> 2; /* Divide by 4 since 4 bytes per thread */ + threads = (u32 *)prop->data; /* Array of valid ids */ + + for (i = 0; i < nr_threads; i++) { + if (nr_cpus_present >= NR_CPUS) { + static bool warned = false; + if (!warned) { + printf("Warning: Number of present CPUs exceeds maximum supported (%d).\n", NR_CPUS); + warned = true; + } + break; + } + cpu_to_hwid[nr_cpus_present++] = fdt32_to_cpu(threads[i]); + } if (!read_common_info) { const struct fdt_property *prop; @@ -84,32 +104,25 @@ bool cpu_has_siar; bool cpu_has_heai; bool cpu_has_prefix; bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ +bool cpu_has_pause_short; -static void cpu_init(void) +static void cpu_init_params(void) { struct cpu_set_params params; int ret; - nr_cpus = 0; + nr_cpus_present = 0; ret = dt_for_each_cpu_node(cpu_set, ¶ms); assert(ret == 0); __icache_bytes = params.icache_bytes; __dcache_bytes = params.dcache_bytes; tb_hz = params.tb_hz; - /* Interrupt Endianness */ - if (machine_is_pseries()) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - hcall(H_SET_MODE, 1, 4, 0, 0); -#else - hcall(H_SET_MODE, 0, 4, 0, 0); -#endif - } - switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_POWER10: cpu_has_prefix = true; cpu_has_sc_lev = true; + cpu_has_pause_short = true; case PVR_VER_POWER9: case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: @@ -175,19 +188,37 @@ static void mem_init(phys_addr_t freemem_start) #define EXCEPTION_STACK_SIZE SZ_64K static char boot_exception_stack[EXCEPTION_STACK_SIZE]; +struct cpu cpus[NR_CPUS]; + +void cpu_init(struct cpu *cpu, int cpu_id) +{ + cpu->server_no = cpu_id; + + cpu->stack = (unsigned long)memalign(SZ_4K, SZ_64K); + cpu->stack += SZ_64K - 64; + cpu->exception_stack = (unsigned long)memalign(SZ_4K, SZ_64K); + cpu->exception_stack += SZ_64K - 64; +} void setup(const void *fdt) { void *freemem = &stacktop; const char *bootargs, *tmp; + struct cpu *cpu; u32 fdt_size; int ret; cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); - /* set exception stack address for this CPU (in SPGR0) */ - asm volatile ("mtsprg0 %[addr]" :: - [addr] "r" (boot_exception_stack)); + memset(cpus, 0xff, sizeof(cpus)); + + cpu = &cpus[0]; + cpu->server_no = fdt_boot_cpuid_phys(fdt); + cpu->exception_stack = (unsigned long)boot_exception_stack; + cpu->exception_stack += SZ_64K - 64; + + mtspr(SPR_SPRG0, (unsigned long)cpu); + __current_cpu = cpu; enable_mcheck(); @@ -230,8 +261,19 @@ void setup(const void *fdt) assert(STACK_INT_FRAME_SIZE % 16 == 0); - /* call init functions */ - cpu_init(); + /* set parameters from dt */ + cpu_init_params(); + + /* Interrupt Endianness */ + if (machine_is_pseries()) { +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + hcall(H_SET_MODE, 1, 4, 0, 0); +#else + hcall(H_SET_MODE, 0, 4, 0, 0); +#endif + } + + cpu_init_ipis(); /* cpu_init must be called before mem_init */ mem_init(PAGE_ALIGN((unsigned long)freemem)); diff --git a/lib/powerpc/smp.c b/lib/powerpc/smp.c index 3e211eba8..a3bf85d44 100644 --- a/lib/powerpc/smp.c +++ b/lib/powerpc/smp.c @@ -6,58 +6,253 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#include #include +#include +#include +#include #include #include +#include +#include #include #include -int nr_threads; - struct secondary_entry_data { secondary_entry_fn entry; - uint64_t r3; - int nr_started; }; +int nr_cpus_online = 1; + +static void stop_self(int cpu_id) +{ + if (machine_is_powernv()) { + if (opal_call(OPAL_RETURN_CPU, 0, 0, 0) != OPAL_SUCCESS) { + printf("OPAL_RETURN_CPU failed\n"); + } + } else { + rtas_stop_self(); + } + + printf("failed to stop cpu %d\n", cpu_id); + assert(0); +} + +void main_secondary(struct cpu *cpu); +void main_secondary(struct cpu *cpu) +{ + mtspr(SPR_SPRG0, (unsigned long)cpu); + __current_cpu = cpu; + + enable_mcheck(); + + cpu_init_ipis(); + + atomic_fetch_inc(&nr_cpus_online); + + cpu->entry(cpu->server_no); + + mb(); + atomic_fetch_dec(&nr_cpus_online); + + stop_self(cpu->server_no); +} + +enum OpalThreadStatus { + OPAL_THREAD_INACTIVE = 0x0, + OPAL_THREAD_STARTED = 0x1, + OPAL_THREAD_UNAVAILABLE = 0x2 /* opal-v3 */ +}; + +#define H_EOI 0x64 +#define H_CPPR 0x68 +#define H_IPI 0x6c +#define H_XIRR 0x74 + +static void (*ipi_fn)(struct pt_regs *regs, void *data); + +static void dbell_handler(struct pt_regs *regs, void *data) +{ + /* sync */ + ipi_fn(regs, data); +} + +static void extint_handler(struct pt_regs *regs, void *data) +{ + int32_t xirr; + int32_t xisr; + int64_t rc; + + asm volatile("mr r3,%1 ; sc 1 ; mr %0,r4" : "=r"(xirr) : "r"(H_XIRR)); + xisr = xirr & 0xffffff; + + if (xisr == 2) { /* IPI */ + rc = hcall(H_IPI, smp_processor_id(), 0xff); + assert(rc == H_SUCCESS); + } + + xirr |= (5 << 24); + rc = hcall(H_EOI, xirr); + assert(rc == H_SUCCESS); + + /* lower IPI */ + ipi_fn(regs, data); +} + +void cpu_init_ipis(void) +{ + if (machine_is_powernv()) { + /* skiboot can leave some messages set */ + unsigned long rb = (5 << (63-36)); + asm volatile("msgclr %0" :: "r"(rb) : "memory"); + } +} + +void local_ipi_enable(void) +{ + if (machine_is_pseries()) { + hcall(H_CPPR, 5); + } +} + +void local_ipi_disable(void) +{ + if (machine_is_pseries()) { + hcall(H_CPPR, 0); + } +} + +void register_ipi(void (*fn)(struct pt_regs *, void *), void *data) +{ + ipi_fn = fn; + if (machine_is_powernv()) { + handle_exception(0xe80, &dbell_handler, data); + } else { + handle_exception(0x500, &extint_handler, data); + } +} + +void unregister_ipi(void) +{ + if (machine_is_powernv()) { + handle_exception(0xe80, NULL, NULL); + } else { + handle_exception(0x500, NULL, NULL); + } +} + +void send_ipi(int cpu_id) +{ + if (machine_is_powernv()) { + unsigned long rb = (5 << (63-36)) | cpu_id; + asm volatile("lwsync" ::: "memory"); + asm volatile("msgsnd %0" :: "r"(rb) : "memory"); + } else { + hcall(H_IPI, cpu_id, 4); + } +} + +static int nr_started = 1; + +extern void start_secondary(uint64_t server_no); /* asm entry point */ + +static bool cpu_is_running(int cpu_id) +{ + if (machine_is_powernv()) { + int64_t ret; + uint8_t status; + + ret = opal_call(OPAL_QUERY_CPU_STATUS, cpu_id, (unsigned long)&status, 0); + if (ret != OPAL_SUCCESS) { + printf("OPAL_QUERY_CPU_STATUS failed for cpu %d\n", cpu_id); + return false; + } + return (status != OPAL_THREAD_INACTIVE); + } else { + uint32_t query_token; + int outputs[1], ret; + + ret = rtas_token("query-cpu-stopped-state", &query_token); + if (ret != 0) { + printf("rtas token query-cpu-stopped-state failed\n"); + return false; + } + + ret = rtas_call(query_token, 1, 2, outputs, cpu_id); + if (ret) { + printf("query-cpu-stopped-state failed for cpu %d\n", cpu_id); + return ret; + } + if (outputs[0]) /* cpu not in stopped state */ + return true; + return false; + } +} + /* * Start stopped thread cpu_id at entry * Returns: <0 on failure to start stopped cpu * 0 on success * >0 on cpu not in stopped state */ -int start_thread(int cpu_id, secondary_entry_fn entry, uint32_t r3) +static int start_thread(int cpu_id, secondary_entry_fn entry) { - uint32_t query_token, start_token; - int outputs[1], ret; + struct cpu *cpu; + uint64_t tb; - ret = rtas_token("query-cpu-stopped-state", &query_token); - assert(ret == 0); - ret = rtas_token("start-cpu", &start_token); - assert(ret == 0); + if (nr_started >= NR_CPUS) { + /* Reached limit */ + return -1; + } + + if (cpu_id == smp_processor_id()) { + /* Boot CPU already started */ + return -1; + } - ret = rtas_call(query_token, 1, 2, outputs, cpu_id); - if (ret) { - printf("query-cpu-stopped-state failed for cpu %d\n", cpu_id); - } else if (!outputs[0]) { /* cpu in stopped state */ - ret = rtas_call(start_token, 3, 1, NULL, cpu_id, entry, r3); - if (ret) + tb = get_tb(); + while (cpu_is_running(cpu_id)) { + if (get_tb() - tb > 3*tb_hz) { + printf("Unable to start running CPU:%d\n", cpu_id); + return 1; + } + } + + cpu = &cpus[nr_started]; + nr_started++; + + cpu_init(cpu, cpu_id); + cpu->entry = entry; + + if (machine_is_powernv()) { + if (opal_call(OPAL_START_CPU, cpu_id, (unsigned long)start_secondary, 0) != OPAL_SUCCESS) { printf("failed to start cpu %d\n", cpu_id); - } else { /* cpu not in stopped state */ - ret = outputs[0]; + return -1; + } + } else { + uint32_t start_token; + int ret; + + ret = rtas_token("start-cpu", &start_token); + assert(ret == 0); + + ret = rtas_call(start_token, 3, 1, NULL, cpu_id, start_secondary, cpu_id); + if (ret) { + printf("failed to start cpu %d\n", cpu_id); + return ret; + } } - return ret; + return 0; } /* * Start all stopped threads (vcpus) on cpu_node * Returns: Number of stopped cpus which were successfully started */ -struct start_threads start_cpu(int cpu_node, secondary_entry_fn entry, - uint32_t r3) +static void start_core(int cpu_node, secondary_entry_fn entry) { - int len, i, nr_threads, nr_started = 0; + int len, i, nr_threads; const struct fdt_property *prop; u32 *threads; @@ -67,23 +262,18 @@ struct start_threads start_cpu(int cpu_node, secondary_entry_fn entry, assert(prop); nr_threads = len >> 2; /* Divide by 4 since 4 bytes per thread */ - threads = (u32 *)prop->data; /* Array of valid ids */ - for (i = 0; i < nr_threads; i++) { - if (!start_thread(fdt32_to_cpu(threads[i]), entry, r3)) - nr_started++; - } + threads = (u32 *)prop->data; /* Array of valid ids */ - return (struct start_threads) { nr_threads, nr_started }; + for (i = 0; i < nr_threads; i++) + start_thread(fdt32_to_cpu(threads[i]), entry); } static void start_each_secondary(int fdtnode, u64 regval __unused, void *info) { struct secondary_entry_data *datap = info; - struct start_threads ret = start_cpu(fdtnode, datap->entry, datap->r3); - nr_threads += ret.nr_threads; - datap->nr_started += ret.nr_started; + start_core(fdtnode, datap->entry); } /* @@ -92,14 +282,34 @@ static void start_each_secondary(int fdtnode, u64 regval __unused, void *info) * Returns: TRUE on success * FALSE on failure */ -bool start_all_cpus(secondary_entry_fn entry, uint32_t r3) +bool start_all_cpus(secondary_entry_fn entry) { - struct secondary_entry_data data = { entry, r3, 0 }; + struct secondary_entry_data data = { entry }; + uint64_t tb; int ret; + assert(nr_cpus_online == 1); + assert(nr_started == 1); ret = dt_for_each_cpu_node(start_each_secondary, &data); assert(ret == 0); + assert(nr_started == nr_cpus_present); - /* We expect that we come in with one thread already started */ - return data.nr_started == nr_threads - 1; + tb = get_tb(); + while (nr_cpus_online < nr_cpus_present) { + if (get_tb() - tb > 3*tb_hz) { + printf("failed to start all secondaries\n"); + assert(0); + } + cpu_relax(); + } + + return 1; +} + +void stop_all_cpus(void) +{ + while (nr_cpus_online > 1) + cpu_relax(); + mb(); + nr_started = 1; } diff --git a/lib/ppc64/asm-offsets.c b/lib/ppc64/asm-offsets.c index 7843a20b4..0ac2c9a75 100644 --- a/lib/ppc64/asm-offsets.c +++ b/lib/ppc64/asm-offsets.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include int main(void) { @@ -50,5 +52,10 @@ int main(void) DEFINE(_XER, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, xer)); DEFINE(_CCR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, ccr)); DEFINE(_TRAP, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, trap)); + + DEFINE(SIZEOF_STRUCT_CPU, sizeof(struct cpu)); + DEFINE(EXCEPTION_STACK, offsetof(struct cpu, exception_stack)); + DEFINE(MAX_CPUS, NR_CPUS); + return 0; } diff --git a/lib/ppc64/asm/atomic.h b/lib/ppc64/asm/atomic.h new file mode 100644 index 000000000..0f461b9ce --- /dev/null +++ b/lib/ppc64/asm/atomic.h @@ -0,0 +1,6 @@ +#ifndef _POWERPC_ATOMIC_H_ +#define _POWERPC_ATOMIC_H_ + +#include "asm-generic/atomic.h" + +#endif /* _POWERPC_ATOMIC_H_ */ diff --git a/lib/ppc64/asm/barrier.h b/lib/ppc64/asm/barrier.h index 76f6efa78..475434b6a 100644 --- a/lib/ppc64/asm/barrier.h +++ b/lib/ppc64/asm/barrier.h @@ -1,6 +1,9 @@ #ifndef _ASMPPC64_BARRIER_H_ #define _ASMPPC64_BARRIER_H_ +#define cpu_relax() asm volatile("or 1,1,1 ; or 2,2,2" ::: "memory") +#define pause_short() asm volatile(".long 0x7c40003c" ::: "memory") + #define mb() asm volatile("sync":::"memory") #define rmb() asm volatile("sync":::"memory") #define wmb() asm volatile("sync":::"memory") diff --git a/lib/ppc64/asm/opal.h b/lib/ppc64/asm/opal.h index de64e2c8d..6c3e9ffe2 100644 --- a/lib/ppc64/asm/opal.h +++ b/lib/ppc64/asm/opal.h @@ -2,14 +2,21 @@ #ifndef _ASMPPC64_OPAL_H_ #define _ASMPPC64_OPAL_H_ +#include + #define OPAL_SUCCESS 0 #define OPAL_CONSOLE_WRITE 1 #define OPAL_CONSOLE_READ 2 #define OPAL_CEC_POWER_DOWN 5 #define OPAL_POLL_EVENTS 10 +#define OPAL_START_CPU 41 +#define OPAL_QUERY_CPU_STATUS 42 +#define OPAL_RETURN_CPU 69 #define OPAL_REINIT_CPUS 70 # define OPAL_REINIT_CPUS_HILE_BE (1 << 0) # define OPAL_REINIT_CPUS_HILE_LE (1 << 1) +int64_t opal_call(int64_t token, int64_t arg1, int64_t arg2, int64_t arg3); + #endif diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 68165fc25..744dfc1f7 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -12,6 +12,7 @@ tests-common = \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ $(TEST_DIR)/tm.elf \ + $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ $(TEST_DIR)/interrupts.elf diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index 405cb0561..8c4da65bc 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -125,6 +125,49 @@ start: bl exit b halt +/* + * start_secondary is the secondary entry point. r3 contains the cpu id + */ +.globl start_secondary +start_secondary: + FIXUP_ENDIAN + /* Switch to 64-bit mode */ + mfmsr r1 + li r2,1 + sldi r2,r2,MSR_SF_BIT + or r1,r1,r2 + mtmsrd r1 + + bl 0f +0: mflr r31 + subi r31, r31, 0b - start /* QEMU's kernel load address */ + + ld r2, (p_toc - start)(r31) + + LOAD_REG_ADDR(r9, cpus) + li r8,0 + li r7,0 +1: ldx r6,r9,r7 + cmpd r6,r3 + beq 2f + addi r7,r7,SIZEOF_STRUCT_CPU + addi r8,r8,1 + cmpdi r8,MAX_CPUS + bne 1b + b . + +2: add r3,r9,r7 + ld r1,8(r3) + + /* Zero backpointers in initial stack frame so backtrace() stops */ + li r0,0 + std r0,0(r1) + std r0,16(r1) + + bl main_secondary + bl exit + b halt + .align 3 p_stack: .llong stackptr p_toc: .llong tocptr @@ -257,7 +300,8 @@ do_handle_exception_return: . = \vec mtsprg1 r1 /* save r1 */ - mfsprg0 r1 /* get exception stack address */ + mfsprg0 r1 /* get struct cpu address */ + ld r1,EXCEPTION_STACK(r1) /* get exception stack address */ subi r1,r1, INT_FRAME_SIZE /* save r0 and ctr to call generic handler */ @@ -273,7 +317,8 @@ do_handle_exception_return: . = \vec mtsprg1 r1 /* save r1 */ - mfsprg0 r1 /* get exception stack address */ + mfsprg0 r1 /* get struct cpu address */ + ld r1,EXCEPTION_STACK(r1) /* get exception stack address */ subi r1,r1, INT_FRAME_SIZE /* save r0 and ctr to call generic handler */ diff --git a/powerpc/selftest.c b/powerpc/selftest.c index 7acff7104..8d1a2c767 100644 --- a/powerpc/selftest.c +++ b/powerpc/selftest.c @@ -8,6 +8,7 @@ #include #include #include +#include static void check_setup(int argc, char **argv) { @@ -34,7 +35,8 @@ static void check_setup(int argc, char **argv) } else if (strcmp(argv[i], "smp") == 0) { - report(nr_cpus == (int)val, "nr_cpus = %d", nr_cpus); + report(nr_cpus_present == (int)val, + "nr_cpus_present = %d", nr_cpus_present); ++nr_tests; } diff --git a/powerpc/smp.c b/powerpc/smp.c new file mode 100644 index 000000000..644cf1c75 --- /dev/null +++ b/powerpc/smp.c @@ -0,0 +1,348 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * SMP and IPI Tests + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile bool start_test_running = true; +static volatile int nr_cpus_started; + +static void start_fn(int cpu_id) +{ + atomic_fetch_inc(&nr_cpus_started); + while (start_test_running) + cpu_relax(); + atomic_fetch_dec(&nr_cpus_started); +} + +static void test_start_cpus(int argc, char **argv) +{ + uint64_t tb; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + nr_cpus_started = 1; + if (!start_all_cpus(start_fn)) + report_abort("Failed to start secondary cpus"); + + tb = get_tb(); + while (nr_cpus_started < nr_cpus_present) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Failed to start all secondaries"); + } + + if (nr_cpus_started != nr_cpus_online) + report_abort("Started CPUs does not match online"); + + barrier(); + start_test_running = false; + barrier(); + + tb = get_tb(); + while (nr_cpus_started > 1) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Failed to stop all secondaries"); + } + + stop_all_cpus(); + + report(true, "start cpus"); +} + +static volatile int nr_cpus_ipi = 0; + +static void ipi_handler(struct pt_regs *regs, void *data) +{ + atomic_fetch_inc(&nr_cpus_ipi); +} + +static volatile bool ipi_test_running = true; + +static void ipi_fn(int cpu_id) +{ + local_ipi_enable(); + + mtspr(SPR_DEC, 0x7fffffff); + local_irq_enable(); + while (ipi_test_running) + cpu_relax(); + local_irq_disable(); + + local_ipi_disable(); +} + +static void test_ipi_cpus(int argc, char **argv) +{ + uint64_t tb; + int i; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + register_ipi(ipi_handler, NULL); + + if (!start_all_cpus(ipi_fn)) + report_abort("Failed to start secondary cpus"); + + for (i = 1; i < nr_cpus_online; i++) + send_ipi(cpus[i].server_no); + + tb = get_tb(); + while (nr_cpus_ipi < nr_cpus_online - 1) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Secondaries failed to respond to IPIs"); + } + + send_ipi(cpus[1].server_no); + + tb = get_tb(); + while (nr_cpus_ipi < nr_cpus_online) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Secondaries failed to respond to IPIs"); + } + + ipi_test_running = false; + + stop_all_cpus(); + + assert(nr_cpus_ipi == nr_cpus_present); + + unregister_ipi(); + + report(true, "IPI cpus"); +} + +static uint64_t time; +static bool time_went_backward; + +static void check_and_record_time(void) +{ + uint64_t tb; + uint64_t t; + uint64_t old; + + t = time; +again: + barrier(); + tb = get_tb(); + asm volatile("1: ldarx %0,0,%1 ; cmpd %0,%2 ; bne 2f ; stdcx. %3,0,%1 ; bne- 1b; 2:" : "=&r"(old) : "r"(&time), "r"(t), "r"(tb) : "memory", "cr0"); + assert(tb >= t); + if (old != t) { + t = old; + goto again; + } + if (old > tb) + time_went_backward = true; +} + +static void update_time(int64_t tb_offset) +{ + uint64_t new_tb; + + new_tb = get_tb() + tb_offset; + mtspr(SPR_TBU40, new_tb); + if ((get_tb() & 0xFFFFFF) < (new_tb & 0xFFFFFF)) { + new_tb += 0x1000000; + mtspr(SPR_TBU40, new_tb); + } +} + +static void time_sync_fn(int cpu_id) +{ + uint64_t start = get_tb(); + + while (!time_went_backward && get_tb() - start < tb_hz*2) { + check_and_record_time(); + cpu_relax(); + } + + while (!time_went_backward && get_tb() - start < tb_hz*2) { + check_and_record_time(); + udelay(1); + } + + if (machine_is_powernv()) { + while (!time_went_backward && get_tb() - start < tb_hz*2) { + check_and_record_time(); + update_time(0x1234000000); + cpu_relax(); + update_time(-0x1234000000); + } + } +} + +static void test_time_sync(int argc, char **argv) +{ + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + time_went_backward = false; + + if (!start_all_cpus(time_sync_fn)) + report_abort("Failed to start secondary cpus"); + + time_sync_fn(-1); + + stop_all_cpus(); + + report(!time_went_backward, "time sync"); +} + +static volatile bool relax_test_running = true; + +static int relax_loop_count[NR_CPUS]; + +static void relax_fn(int cpu_id) +{ + volatile int i = 0; + + while (relax_test_running) { + cpu_relax(); + i++; + } + + relax_loop_count[cpu_id] = i; +} + +#define ITERS 1000000 + +static void test_relax(int argc, char **argv) +{ + volatile int i; + int count; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + if (!start_all_cpus(relax_fn)) + report_abort("Failed to start secondary cpus"); + + for (i = 0; i < ITERS; i++) + ; + + relax_test_running = false; + + stop_all_cpus(); + + count = 0; + for (i = 0; i < NR_CPUS; i++) + count += relax_loop_count[i]; + if (count == 0) + count = 1; + + report(true, "busy-loops on CPU:%d vs cpu_relax-loops on others %ld%%", smp_processor_id(), (long)ITERS * 100 / count); +} + +static volatile bool pause_test_running = true; + +static int pause_loop_count[NR_CPUS]; + +static void pause_fn(int cpu_id) +{ + volatile int i = 0; + + while (pause_test_running) { + pause_short(); + i++; + } + + pause_loop_count[cpu_id] = i; +} + +#define ITERS 1000000 + +static void test_pause(int argc, char **argv) +{ + volatile int i; + int count; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (!cpu_has_pause_short) + return; + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + if (!start_all_cpus(pause_fn)) + report_abort("Failed to start secondary cpus"); + + for (i = 0; i < ITERS; i++) + ; + + pause_test_running = false; + + stop_all_cpus(); + + count = 0; + for (i = 0; i < NR_CPUS; i++) + count += pause_loop_count[i]; + + report(true, "busy-loops on CPU:%d vs pause_short-loops on others %ld%%", smp_processor_id(), (long)ITERS * 100 / count); +} + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "start_cpus", test_start_cpus }, + { "ipi_cpus", test_ipi_cpus }, + { "time_sync", test_time_sync }, + { "cpu_relax", test_relax }, + { "pause", test_pause }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + bool all; + int i; + + all = argc == 1 || !strcmp(argv[1], "all"); + + report_prefix_push("smp"); + + for (i = 0; hctests[i].name != NULL; i++) { + if (all || strcmp(argv[1], hctests[i].name) == 0) { + report_prefix_push(hctests[i].name); + hctests[i].func(argc, argv); + report_prefix_pop(); + } + } + + report_prefix_pop(); + return report_summary(); +} diff --git a/powerpc/tm.c b/powerpc/tm.c index 6b1ceeb6e..efbcf1f12 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -89,7 +89,7 @@ static void test_h_cede_tm(int argc, char **argv) if (argc > 2) report_abort("Unsupported argument: '%s'", argv[2]); - if (!start_all_cpus(halt, 0)) + if (!start_all_cpus(halt)) report_abort("Failed to start secondary cpus"); if (!enable_tm()) @@ -133,7 +133,7 @@ int main(int argc, char **argv) report_skip("TM is not available"); goto done; } - report(cpus_with_tm == nr_cpus, + report(cpus_with_tm == nr_cpus_present, "TM available in all 'ibm,pa-features' properties"); all = argc == 1 || !strcmp(argv[1], "all"); diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 9fdc86b66..ddce409a8 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -74,6 +74,14 @@ file = emulator.elf [interrupts] file = interrupts.elf +[smp] +file = smp.elf +smp = 2 + +[smp-smt] +file = smp.elf +smp = 8,threads=4 + [h_cede_tm] file = tm.elf machine = pseries From patchwork Tue Mar 19 07:59:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=T5Uh9x5B; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPhD1t7Yz1yWv for ; Tue, 19 Mar 2024 19:16:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=T5Uh9x5B; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPhD0JXcz3vlj for ; Tue, 19 Mar 2024 19:16:44 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=T5Uh9x5B; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c2a; helo=mail-oo1-xc2a.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) (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 4TzPLF5c35z3vcT for ; Tue, 19 Mar 2024 19:01:09 +1100 (AEDT) Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-5a21859a4b8so2348865eaf.0 for ; Tue, 19 Mar 2024 01:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835267; x=1711440067; darn=lists.ozlabs.org; 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=hLN2zrrkD0RDiFTSfzL8j8/r0UbtD91MkKEokRwP4k4=; b=T5Uh9x5Bobmg7sBuWa1EEFeUQ+giDtBkAEOqyKG9UX5KIgVVakeZTB/n8+k2XWkaK7 7OYV58bMG1spENIlavXWJuJ+5OUSAHRsVqKs4C+U7IKN8zX/4BcFp/nwt3N3VqQoDvjz 8Ac4mKYCTyPk9Ct8OEqpgqncvj7tMz3hkfy/Ssl0JgnzdpeLnqCdN/KsMMQx83Fn5Z+E lnzq8DNH21DBAWW53oldHZvuK86OPKNHjo5GwFGk+Qm+dVaUfV0XXaVItKb1iSseeiF/ nNn0ylulwKvmXvf/D+qUEj7KftvHx5w4dM+2sNc5YhVio1Jj3orSXeoaovHMh6PlnlOQ LFBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835267; x=1711440067; 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=hLN2zrrkD0RDiFTSfzL8j8/r0UbtD91MkKEokRwP4k4=; b=vayew27yyWkOHAs7C6HKPcJqY57pt3ZTuTELXQzokmRr1600qKfscv13MDSwv4Ipi8 djlF0H+VxQojvOdaz1ShQRqtFS+KRsu3X5DFgVZsLuWfza78vyX5HnK3e2vwIHUpTIAO s23BY9ELfV8MIUBKyUQgLABGRuMtlJbEvQ2Cg2DzhaVYs3teRXFZ6/BbxswRAt3cRv8d S5UuzsAqaZ8bUcjtKSPH5Zd5po37eZKgideLG5gz7r44Thk2DO6hBk6a1P9e7bsjzvrx YSH6fzGozuLErgblloSDVB4wi0YHu+phFzOzpuBujh6qbpGSO3UaVdm1y8buv3Ry6uqL yQlw== X-Forwarded-Encrypted: i=1; AJvYcCXPyg02m10Xw1IBm8YXSOUSfrCdE8vChF/DzZjuKlCHMVgXPbuwzq2FkY6pcQvebjCvqXwgQDF49zMTt86I7+tNgkNHsNvfuMZuq1pCZw== X-Gm-Message-State: AOJu0YyxXyF9n7MzZGu8//NRpMAXUhEkIVl4jaZThhIPUKVsLJkGRGTg bkafdLnk1Dxce4Ua2b51bUJ0CdyCsafjhjbwlz7obfbn3RVL+9SaoO3uHeBKkek= X-Google-Smtp-Source: AGHT+IFeHmGB4ze6kUtSa/hewyRt16k7UnWrqRYoKu2IK3oRrizTCfSNflyjrRy8gEqvoy5Wcy9Hqw== X-Received: by 2002:a4a:7614:0:b0:5a4:75f2:54d0 with SMTP id t20-20020a4a7614000000b005a475f254d0mr9007064ooc.9.1710835266777; Tue, 19 Mar 2024 01:01:06 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:05 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 23/35] powerpc: Permit ACCEL=tcg,thread=single Date: Tue, 19 Mar 2024 17:59:14 +1000 Message-ID: <20240319075926.2422707-24-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Modify run script to permit single vs mttcg threading, add a thread=single smp case to unittests.cfg. Signed-off-by: Nicholas Piggin --- powerpc/run | 4 ++-- powerpc/unittests.cfg | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/powerpc/run b/powerpc/run index 172f32a46..27abf1ef6 100755 --- a/powerpc/run +++ b/powerpc/run @@ -36,8 +36,8 @@ if ! $qemu -machine '?' 2>&1 | grep $MACHINE > /dev/null; then exit 2 fi +A="-accel $ACCEL$ACCEL_PROPS" M="-machine $MACHINE" -M+=",accel=$ACCEL$ACCEL_PROPS" B="" D="" @@ -54,7 +54,7 @@ if [[ "$MACHINE" == "powernv"* ]] ; then D+="-device ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10" fi -command="$qemu -nodefaults $M $B $D" +command="$qemu -nodefaults $A $M $B $D" command+=" -display none -serial stdio -kernel" command="$(migration_cmd) $(timeout_cmd) $command" diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index ddce409a8..71bfc935d 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -82,6 +82,12 @@ smp = 2 file = smp.elf smp = 8,threads=4 +# mttcg is the default most places, so add a thread=single test +[smp-thread-single] +file = smp.elf +smp = 8,threads=4 +accel = tcg,thread=single + [h_cede_tm] file = tm.elf machine = pseries From patchwork Tue Mar 19 07:59:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gAVUnxBU; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPj148GCz1yWv for ; Tue, 19 Mar 2024 19:17:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gAVUnxBU; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPj1109Lz3w89 for ; Tue, 19 Mar 2024 19:17:25 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=gAVUnxBU; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::431; helo=mail-pf1-x431.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (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 4TzPLN08kPz3vYq for ; Tue, 19 Mar 2024 19:01:15 +1100 (AEDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6e6b54a28ebso5147491b3a.2 for ; Tue, 19 Mar 2024 01:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835273; x=1711440073; darn=lists.ozlabs.org; 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=T2v3m6/HzaZ1rQ7x7lB6tdszFjgJSQvXgFZcRwhVCtA=; b=gAVUnxBUocep/lidSuHLSivYJPXNeoKf2aUCcjvAhEQcQkmk3rw51wM3PJHHYFq6qc SOeEJTmWz/aG6aeEw8LzLdrjmwPNESUzW/NIR34fMAeRjd6iL7lQq+OYiUjLx0emEp8x NLcMrntTMIc0W9GVXn2dQad8lbvjhklw/bqzSFxp5rDFFX9I6iG6dQjOrfQNV8vn7+mw 9E3Eq3A2PgLdWgoz4CHJvkOHl2a5OsKDrPm5IGZQ+Q/mZ7CET++1PmcguUz+EEDcYhnw 7hkaZ6YTL2TfX7tcE+HwcENKKyfyrIsWvnpJpAQMLyesFNpJ/20LEQfOsQJTZ8e9+L/9 8JgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835273; x=1711440073; 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=T2v3m6/HzaZ1rQ7x7lB6tdszFjgJSQvXgFZcRwhVCtA=; b=QnEoOeItdSbcOggSbsPPc/YeSnamUrJm49hYSB6MKHsoVsnQqEQV94v/YaB1U/qbe1 2fquH9RuSNXbppdmZPxbxO+carTsmQ/KUNi6r9fnNdVYVN3S9SVyzKfxHgPUI5Uk0qm8 4ddQCi7F5Td4u+zrv+dcgouQQVfl2Y9g/uoqLX5415zjuWeb1G2ulNg0wX1OpkP6r6B/ d43FDqA8Xq0ALw8igLeT7Uvqljfmx0xQ/Vqj4AJk7QgKheGlmZTALyiE/C0MK7ajMrrY J9lTPYuQT8fqjCJ8htadjO/Y+nq1AgxfVpuXh5/ptYjsTRKKblOaN6RY1Q3UDSFJMS/Y Ubtg== X-Forwarded-Encrypted: i=1; AJvYcCXvYFkWdfpFC2wI6W7NXuscjMIo39S36PEXFwb/493J7V/2j2ASgisjtaMc3GZhQxSQPZwWk+kXpjVdXeduvQxyThzapkPmp4RpMfL6Uw== X-Gm-Message-State: AOJu0YznMKIXwRIAyXBkQXPtDWdcpaB8fHUWVrQ1QBVG+nxTACd9NnRk kQuqVlkw8fv9drS0i1x+3mML/SowCgL/Wc7B6Gjh3g+DY5GR83Gt X-Google-Smtp-Source: AGHT+IHdwH83NuMcW/BwylTDBox7NJE3DY6u/Tq9cnPn3D+qzkwPfiyEb4jrVhG+XmeamI42Xsmw8Q== X-Received: by 2002:a05:6a00:398a:b0:6e6:b155:b9a3 with SMTP id fi10-20020a056a00398a00b006e6b155b9a3mr14286931pfb.11.1710835273174; Tue, 19 Mar 2024 01:01:13 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:10 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 24/35] powerpc: Avoid using larx/stcx. in spinlocks when only one CPU is running Date: Tue, 19 Mar 2024 17:59:15 +1000 Message-ID: <20240319075926.2422707-25-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The test harness uses spinlocks if they are implemented with larx/stcx. it can prevent some test scenarios such as testing migration of a reservation. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/smp.h | 1 + lib/powerpc/smp.c | 5 +++++ lib/powerpc/spinlock.c | 29 +++++++++++++++++++++++++++++ lib/ppc64/asm/spinlock.h | 7 ++++++- powerpc/Makefile.common | 1 + 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 lib/powerpc/spinlock.c diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index 4519e5436..6ef3ae521 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -15,6 +15,7 @@ struct cpu { extern int nr_cpus_present; extern int nr_cpus_online; +extern bool multithreaded; extern struct cpu cpus[]; register struct cpu *__current_cpu asm("r13"); diff --git a/lib/powerpc/smp.c b/lib/powerpc/smp.c index a3bf85d44..f3b2a3faf 100644 --- a/lib/powerpc/smp.c +++ b/lib/powerpc/smp.c @@ -276,6 +276,8 @@ static void start_each_secondary(int fdtnode, u64 regval __unused, void *info) start_core(fdtnode, datap->entry); } +bool multithreaded = false; + /* * Start all stopped cpus on the guest at entry with register 3 set to r3 * We expect that we come in with only one thread currently started @@ -290,6 +292,7 @@ bool start_all_cpus(secondary_entry_fn entry) assert(nr_cpus_online == 1); assert(nr_started == 1); + multithreaded = true; ret = dt_for_each_cpu_node(start_each_secondary, &data); assert(ret == 0); assert(nr_started == nr_cpus_present); @@ -308,8 +311,10 @@ bool start_all_cpus(secondary_entry_fn entry) void stop_all_cpus(void) { + assert(multithreaded); while (nr_cpus_online > 1) cpu_relax(); mb(); nr_started = 1; + multithreaded = false; } diff --git a/lib/powerpc/spinlock.c b/lib/powerpc/spinlock.c new file mode 100644 index 000000000..623a1f2c1 --- /dev/null +++ b/lib/powerpc/spinlock.c @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: LGPL-2.0 */ +#include +#include + +/* + * Skip the atomic when single-threaded, which helps avoid larx/stcx. in + * the harness when testing tricky larx/stcx. sequences (e.g., migration + * vs reservation). + */ +void spin_lock(struct spinlock *lock) +{ + if (!multithreaded) { + assert(lock->v == 0); + lock->v = 1; + } else { + while (__sync_lock_test_and_set(&lock->v, 1)) + ; + } +} + +void spin_unlock(struct spinlock *lock) +{ + assert(lock->v == 1); + if (!multithreaded) { + lock->v = 0; + } else { + __sync_lock_release(&lock->v); + } +} diff --git a/lib/ppc64/asm/spinlock.h b/lib/ppc64/asm/spinlock.h index f59eed191..b952386da 100644 --- a/lib/ppc64/asm/spinlock.h +++ b/lib/ppc64/asm/spinlock.h @@ -1,6 +1,11 @@ #ifndef _ASMPPC64_SPINLOCK_H_ #define _ASMPPC64_SPINLOCK_H_ -#include +struct spinlock { + unsigned int v; +}; + +void spin_lock(struct spinlock *lock); +void spin_unlock(struct spinlock *lock); #endif /* _ASMPPC64_SPINLOCK_H_ */ diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 744dfc1f7..02af54b83 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -48,6 +48,7 @@ cflatobjs += lib/powerpc/rtas.o cflatobjs += lib/powerpc/processor.o cflatobjs += lib/powerpc/handlers.o cflatobjs += lib/powerpc/smp.o +cflatobjs += lib/powerpc/spinlock.o OBJDIRS += lib/powerpc From patchwork Tue Mar 19 07:59:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ND1weUgu; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPjp5j1dz1yWv for ; Tue, 19 Mar 2024 19:18:06 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ND1weUgu; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPjp4cGNz3w98 for ; Tue, 19 Mar 2024 19:18:06 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=ND1weUgu; dkim-atps=neutral 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=lists.ozlabs.org) 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 4TzPLR3vFqz3vdH for ; Tue, 19 Mar 2024 19:01:19 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e709e0c123so2190353b3a.1 for ; Tue, 19 Mar 2024 01:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835278; x=1711440078; darn=lists.ozlabs.org; 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=EKEBox+vdt7TX5zGaH92d+WWNZbgSBw4KxF++MKBLcs=; b=ND1weUguPJFIllQhl+34M9Ckam3qRSJN7BBoMSjUaXiZbODo2PlHBckN9hDSUcOXag PTHVMwHtRgXhdKvZNFp20l9rUkEhhcPEhzwexCv6OY8Poi6YtuxCTzBT2hh9kw8zQZad E/Pha58IRqpNbvnhSlQEjeLfua0dBH0AwkEcDElYQk1Cpli5i9hMQb/8E3CGC8DvbAwz dT8C0+RGHOF/QSzj7MdPC9Hih0CCSJr2+iY3sI8n0JJqW12x5vtr6KJgclTtZWDDBvWV Pf7WByZ6pW/gTB6/SMwhCnsdkaGmSCU2P237RBikqPAO++TJuXDoTEOsXs9UJKSI4edr Hw0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835278; x=1711440078; 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=EKEBox+vdt7TX5zGaH92d+WWNZbgSBw4KxF++MKBLcs=; b=XgtROfqxQ3CLBEKwJPondBsYTvls1fhY+edLlheGwxa9miVI19ljG0WJVwXPEsdxfN x8+sC/dUXTdYpxnf6kgvd1ZI+eht3G0aIC4frzQVo2jByduPW5Dr5NpRXS0kkfq9/a6b qZv1TUx8Nsvf4ERqzWXh2sGW6nJsGSYAdBNnRUcZhswwbvBA3mPKYCIj+TUzeR1uSpA2 sUPQdeZkJ2ChjRpWJGxaifbsKX0ZMuQTEDEhrFrdhZLjCt7O3cnEOlxFnTxkgdEazqps 6FiBNOOxsF8jvp/OmI++A3QDmOG6PqaGfSHDol+qll/4+15UjrmAviKMEyk6RrrX+N1P XFBw== X-Forwarded-Encrypted: i=1; AJvYcCX7rRIl5YJ8MLkfA7bmookxLVMF0s/Dbloe+nvCgtDmse9+gfoRSzN/YiB2LuDNX0kxz2yaUq4gLtwZ5ezVX6sXkNaD1wtgG67vP3u0zg== X-Gm-Message-State: AOJu0Yyg1ZO0JmKX2xXf5fN73G9ihc4DJuPBfyL0L6TbgiymfLIt6yBA cftyuL58nc848doN0lNpdaOuc4IEN49fsvxaUAID79tsDJZNLh7n X-Google-Smtp-Source: AGHT+IETtMoSfTs/sCtASEGTW8OsW81ComWtRGXeNLihqpIqSFxLmEv5BeRairFKKzRsTA71IzZfRw== X-Received: by 2002:aa7:88cf:0:b0:6e7:2154:72ec with SMTP id k15-20020aa788cf000000b006e7215472ecmr2191188pff.17.1710835277711; Tue, 19 Mar 2024 01:01:17 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:17 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 25/35] powerpc: Add atomics tests Date: Tue, 19 Mar 2024 17:59:16 +1000 Message-ID: <20240319075926.2422707-26-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Signed-off-by: Nicholas Piggin --- powerpc/Makefile.common | 1 + powerpc/atomics.c | 374 ++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 9 + 3 files changed, 384 insertions(+) create mode 100644 powerpc/atomics.c diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 02af54b83..b6f9b3b85 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -11,6 +11,7 @@ tests-common = \ $(TEST_DIR)/spapr_hcall.elf \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ + $(TEST_DIR)/atomics.elf \ $(TEST_DIR)/tm.elf \ $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ diff --git a/powerpc/atomics.c b/powerpc/atomics.c new file mode 100644 index 000000000..c3d1cef52 --- /dev/null +++ b/powerpc/atomics.c @@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test some powerpc instructions + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool do_migrate; +static bool do_record; + +#define RSV_SIZE 128 + +static uint8_t granule[RSV_SIZE] __attribute((__aligned__(RSV_SIZE))); + +static void spin_lock(unsigned int *lock) +{ + unsigned int old; + + asm volatile ("1:" + "lwarx %0,0,%2;" + "cmpwi %0,0;" + "bne 1b;" + "stwcx. %1,0,%2;" + "bne- 1b;" + "lwsync;" + : "=&r"(old) : "r"(1), "r"(lock) : "cr0", "memory"); +} + +static void spin_unlock(unsigned int *lock) +{ + asm volatile("lwsync;" + "stw %1,%0;" + : "+m"(*lock) : "r"(0) : "memory"); +} + +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; + +static void interrupt_handler(struct pt_regs *regs, void *opaque) +{ + assert(!got_interrupt); + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); +} + +static void test_lwarx_stwcx(int argc, char *argv[]) +{ + unsigned int *var = (unsigned int *)granule; + unsigned int old; + unsigned int result; + + *var = 0; + asm volatile ("1:" + "lwarx %0,0,%2;" + "stwcx. %1,0,%2;" + "bne- 1b;" + : "=&r"(old) : "r"(1), "r"(var) : "cr0", "memory"); + report(old == 0 && *var == 1, "simple update"); + + *var = 0; + asm volatile ("li %0,0;" + "stwcx. %1,0,%2;" + "stwcx. %1,0,%2;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result) + : "r"(1), "r"(var) : "cr0", "memory"); + report(result == 0 && *var == 0, "failed stwcx. (no reservation)"); + + *var = 0; + asm volatile ("li %0,0;" + "lwarx %1,0,%4;" + "stw %3,0(%4);" + "stwcx. %2,0,%4;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result), "=&r"(old) + : "r"(1), "r"(2), "r"(var) : "cr0", "memory"); + /* This is implementation specific, so don't fail */ + if (result == 0 && *var == 2) + report(true, "failed stwcx. (intervening store)"); + else + report(true, "succeeded stwcx. (intervening store)"); + + handle_exception(0x600, interrupt_handler, NULL); + handle_exception(0x700, interrupt_handler, NULL); + + /* Implementations may not necessarily invoke the alignment interrupt */ + old = 10; + *var = 0; + asm volatile ( + "lwarx %0,0,%1;" + : "+&r"(old) : "r"((char *)var + 1)); + report(old == 10 && got_interrupt && recorded_regs.trap == 0x600, "unaligned lwarx causes fault"); + got_interrupt = false; + + /* + * Unaligned stwcx. is more difficult to test, at least under QEMU, + * the store does not proceed if there is no matching reservation, so + * the alignment handler does not get invoked. This is okay according + * to the Power ISA (unalignment does not necessarily invoke the + * alignment interrupt). But POWER CPUs do cause alignment interrupt. + */ + *var = 0; + asm volatile ( + "lwarx %0,0,%2;" + "stwcx. %1,0,%3;" + : "=&r"(old) : "r"(1), "r"(var), "r"((char *)var+1) : "cr0", "memory"); + report(old == 0 && *var == 0 && got_interrupt && recorded_regs.trap == 0x600, "unaligned stwcx. causes fault"); + got_interrupt = false; + + handle_exception(0x600, NULL, NULL); + +} + +static void test_lqarx_stqcx(int argc, char *argv[]) +{ + union { + __int128_t var; + struct { +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + unsigned long var1; + unsigned long var2; +#else + unsigned long var2; + unsigned long var1; +#endif + }; + } var __attribute__((aligned(16))); + register unsigned long new1 asm("r8"); + register unsigned long new2 asm("r9"); + register unsigned long old1 asm("r10"); + register unsigned long old2 asm("r11"); + unsigned int result; + + var.var1 = 1; + var.var2 = 2; + + (void)new2; + (void)old2; + + old1 = 0; + old2 = 0; + new1 = 3; + new2 = 4; + asm volatile ("1:" + "lqarx %0,0,%4;" + "stqcx. %2,0,%4;" + "bne- 1b;" + : "=&r"(old1), "=&r"(old2) + : "r"(new1), "r"(new2), "r"(&var) + : "cr0", "memory"); + + report(old1 == 2 && old2 == 1 && var.var1 == 4 && var.var2 == 3, + "simple update"); + + var.var1 = 1; + var.var2 = 2; + new1 = 3; + new2 = 4; + asm volatile ("li %0,0;" + "stqcx. %1,0,%3;" + "stqcx. %1,0,%3;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result) + : "r"(new1), "r"(new2), "r"(&var) + : "cr0", "memory"); + report(result == 0 && var.var1 == 1 && var.var2 == 2, + "failed stqcx. (no reservation)"); + + var.var1 = 1; + var.var2 = 2; + new1 = 3; + new2 = 4; + asm volatile ("li %0,0;" + "lqarx %1,0,%6;" + "std %5,0(%6);" + "stqcx. %3,0,%6;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result), "=&r"(old1), "=&r"(old2) + : "r"(new1), "r"(new2), "r"(0), "r"(&var) + : "cr0", "memory"); + /* This is implementation specific, so don't fail */ + if (result == 0 && (var.var1 == 0 || var.var2 == 0)) + report(true, "failed stqcx. (intervening store)"); + else + report(true, "succeeded stqcx. (intervening store)"); +} + +static void test_migrate_reserve(int argc, char *argv[]) +{ + unsigned int *var = (unsigned int *)granule; + unsigned int old; + int i; + int succeed = 0; + + if (!do_migrate) + return; + + for (i = 0; i < 10; i++) { + *var = 0x12345; + asm volatile ("lwarx %0,0,%1" : "=&r"(old) : "r"(var) : "memory"); + migrate_quiet(); + asm volatile ("stwcx. %0,0,%1" : : "r"(0xf00d), "r"(var) : "cr0", "memory"); + if (*var == 0xf00d) + succeed++; + } + + if (do_record) { + /* + * Running under TCG record-replay, reservations must not + * be lost by migration + */ + report(succeed > 0, "migrated reservation is not lost"); + } else { + report(succeed == 0, "migrated reservation is lost"); + } + + report_prefix_pop(); +} + +#define ITERS 10000000 +static int test_counter = 0; +static void test_inc_perf(int argc, char *argv[]) +{ + int i; + uint64_t tb1, tb2; + + tb1 = get_tb(); + for (i = 0; i < ITERS; i++) + __atomic_fetch_add(&test_counter, 1, __ATOMIC_RELAXED); + tb2 = get_tb(); + report(true, "atomic add takes %ldns", (tb2 - tb1) * 1000000000 / ITERS / tb_hz); + + tb1 = get_tb(); + for (i = 0; i < ITERS; i++) + __atomic_fetch_add(&test_counter, 1, __ATOMIC_SEQ_CST); + tb2 = get_tb(); + report(true, "sequentially conssistent atomic add takes %ldns", (tb2 - tb1) * 1000000000 / ITERS / tb_hz); +} + +static long smp_inc_counter = 0; +static int smp_inc_started; + +static void smp_inc_fn(int cpu_id) +{ + long i; + + atomic_fetch_inc(&smp_inc_started); + while (smp_inc_started < nr_cpus_present) + cpu_relax(); + + for (i = 0; i < ITERS; i++) + atomic_fetch_inc(&smp_inc_counter); + atomic_fetch_dec(&smp_inc_started); +} + +static void test_smp_inc(int argc, char **argv) +{ + if (nr_cpus_present < 2) + return; + + if (!start_all_cpus(smp_inc_fn)) + report_abort("Failed to start secondary cpus"); + + while (smp_inc_started < nr_cpus_present - 1) + cpu_relax(); + smp_inc_fn(smp_processor_id()); + while (smp_inc_started > 0) + cpu_relax(); + + stop_all_cpus(); + + report(smp_inc_counter == nr_cpus_present * ITERS, "counter lost no increments"); +} + +static long smp_lock_counter __attribute__((aligned(128))) = 0; +static unsigned int smp_lock __attribute__((aligned(128))); +static int smp_lock_started; + +static void smp_lock_fn(int cpu_id) +{ + long i; + + atomic_fetch_inc(&smp_lock_started); + while (smp_lock_started < nr_cpus_present) + cpu_relax(); + + for (i = 0; i < ITERS; i++) { + spin_lock(&smp_lock); + smp_lock_counter++; + spin_unlock(&smp_lock); + } + atomic_fetch_dec(&smp_lock_started); +} + +static void test_smp_lock(int argc, char **argv) +{ + if (nr_cpus_present < 2) + return; + + if (!start_all_cpus(smp_lock_fn)) + report_abort("Failed to start secondary cpus"); + + while (smp_lock_started < nr_cpus_present - 1) + cpu_relax(); + smp_lock_fn(smp_processor_id()); + while (smp_lock_started > 0) + cpu_relax(); + + stop_all_cpus(); + + report(smp_lock_counter == nr_cpus_present * ITERS, "counter lost no increments"); +} + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "lwarx/stwcx", test_lwarx_stwcx }, + { "lqarx/stqcx", test_lqarx_stqcx }, + { "migration", test_migrate_reserve }, + { "performance", test_inc_perf }, + { "SMP-atomic", test_smp_inc }, + { "SMP-lock", test_smp_lock }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + int i; + int all; + + all = argc == 1 || !strcmp(argv[1], "all"); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-r") == 0) { + do_record = true; + } + if (strcmp(argv[i], "-m") == 0) { + do_migrate = true; + } + } + + report_prefix_push("atomics"); + + for (i = 0; hctests[i].name != NULL; i++) { + if (all || strcmp(argv[1], hctests[i].name) == 0) { + report_prefix_push(hctests[i].name); + hctests[i].func(argc, argv); + report_prefix_pop(); + } + } + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 71bfc935d..803a636cb 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -88,6 +88,15 @@ file = smp.elf smp = 8,threads=4 accel = tcg,thread=single +[atomics] +file = atomics.elf + +[atomics-migration] +file = atomics.elf +machine = pseries +extra_params = -append "'migration -m'" +groups = migration + [h_cede_tm] file = tm.elf machine = pseries From patchwork Tue Mar 19 07:59:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Yvdb00ff; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPkc12KGz1yWv for ; Tue, 19 Mar 2024 19:18:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Yvdb00ff; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPkb5lH2z3vx1 for ; Tue, 19 Mar 2024 19:18:47 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=Yvdb00ff; dkim-atps=neutral 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=lists.ozlabs.org) 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 4TzPLW2BGNz3cbl for ; Tue, 19 Mar 2024 19:01:23 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e6b5aa0b52so4342396b3a.3 for ; Tue, 19 Mar 2024 01:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835281; x=1711440081; darn=lists.ozlabs.org; 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=KASY5yJX/YZElgAuA5smCL49JGSesaeXw9ivSKaFgEo=; b=Yvdb00ffnURkqgOd6c6YoHV17Y/4EP023jg5tVYDWkggLti6R0PIT2npTRTTNrzI/h RyJEP9Oj6G6mOFmSI76JZ40FOckaSxymOsimHGrLp5WuCVvBswVuM+wX/nXLdML/EZFJ GbEOwOZSErZi6VGkkkqIdqehDOpN+npg7SppqQtVpuNnreK/P4lHhIom2YmQ45RhCZZM SjZ0tnAg9T0RT2zMeKeV/cDVVAeodX52lWCICKsRM2U0fYkSo4CPt8ncyuO8/oaOtyDT pgaeE2NeBRG7Rs0MII9Lg4prPzPZFTBaN1HuW81EyDrFvRT9SRtlEGoUDPVyH/Tpx+px U7uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835281; x=1711440081; 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=KASY5yJX/YZElgAuA5smCL49JGSesaeXw9ivSKaFgEo=; b=JngPCSMtPsVvPXaD6HKa5PwZzBriaElyYB5HeiDhz2IbNleQQIXd/wkLtVRgF3BTGg 63rnjTigTuJxMnLJRJljW43i9p/aT+wXn/dwS8FCs5/Uq3tje8WRJ2WIkSGhNgJHkkYu 1pvyVI8jkk4BFpa/k6OclyvDw1GYB21WW8DUsf+tPooVSuR5a04iptwI/PnKTqrmTkqr 5j8N4zddnin0V14P9a4FqPTY5nogc+0U8pn1VRdwNIAC9jos8aVSGH1oAoGsEMr/EzxF xZXTLaOBMmisrzYK7hOQXd83un9UHrfh4V2zmG4zFfpwZ8BcIypbfnvjI05eg6g3vAoH qotw== X-Forwarded-Encrypted: i=1; AJvYcCUSHrW2/YIWe8GNl/Vp+zOdIodJvJG/cMrGpRIz9HfrQQWjyk2rAwTJBAj+eByv5gAHxkI1T9nGQkJ1a8mmqqZxuUvtrBInnE51Tya49g== X-Gm-Message-State: AOJu0YwDLQFLOpwrG/zQgnekHPIMhrmhFP+hW0g83n/dVf0VjqmWlw5U Q2GvKwqQAB43BKA+pv3VvRMru5C4U/iutJV4U7G7mO0BVqwgvnTa X-Google-Smtp-Source: AGHT+IGHBD/AyBj1T6HpHC7VcH1ci3Ci5qkdmGQasHq5ScsNDCs4FIGaxahBV7TI4fEAydcN0ZZ/DA== X-Received: by 2002:a05:6a00:4fd5:b0:6e6:946b:a983 with SMTP id le21-20020a056a004fd500b006e6946ba983mr17989675pfb.10.1710835281431; Tue, 19 Mar 2024 01:01:21 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:21 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 26/35] powerpc: Add timebase tests Date: Tue, 19 Mar 2024 17:59:17 +1000 Message-ID: <20240319075926.2422707-27-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This has a known failure on QEMU TCG machines where the decrementer interrupt is not lowered when the DEC wraps from -ve to +ve. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/reg.h | 1 + powerpc/Makefile.common | 1 + powerpc/timebase.c | 329 ++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 8 + 4 files changed, 339 insertions(+) create mode 100644 powerpc/timebase.c diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index d2ca964c4..12f9e8ac6 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -35,6 +35,7 @@ #define SPR_HSRR1 0x13b #define SPR_LPCR 0x13e #define LPCR_HDICE UL(0x1) +#define LPCR_LD UL(0x20000) #define SPR_HEIR 0x153 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index b6f9b3b85..1348f658b 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -15,6 +15,7 @@ tests-common = \ $(TEST_DIR)/tm.elf \ $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ + $(TEST_DIR)/timebase.elf \ $(TEST_DIR)/interrupts.elf tests-all = $(tests-common) $(tests) diff --git a/powerpc/timebase.c b/powerpc/timebase.c new file mode 100644 index 000000000..1908ca838 --- /dev/null +++ b/powerpc/timebase.c @@ -0,0 +1,329 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test Timebase + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + * + * This contains tests of timebase facility, TB, DEC, etc. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int dec_bits = 0; + +static void cpu_dec_bits(int fdtnode, u64 regval __unused, void *arg __unused) +{ + const struct fdt_property *prop; + int plen; + + prop = fdt_get_property(dt_fdt(), fdtnode, "ibm,dec-bits", &plen); + if (!prop) { + dec_bits = 32; + return; + } + + /* Sanity check for the property layout (first two bytes are header) */ + assert(plen == 4); + + dec_bits = fdt32_to_cpu(*(uint32_t *)prop->data); +} + +/* Check amount of CPUs nodes that have the TM flag */ +static int find_dec_bits(void) +{ + int ret; + + ret = dt_for_each_cpu_node(cpu_dec_bits, NULL); + if (ret < 0) + return ret; + + return dec_bits; +} + + +static bool do_migrate = false; +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; + +static uint64_t dec_max; +static uint64_t dec_min; + +static void test_tb(int argc, char **argv) +{ + uint64_t tb; + + tb = get_tb(); + if (do_migrate) + migrate(); + report(get_tb() >= tb, "timebase is incrementing"); +} + +static void dec_stop_handler(struct pt_regs *regs, void *data) +{ + mtspr(SPR_DEC, dec_max); +} + +static void dec_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->msr &= ~MSR_EE; +} + +static void test_dec(int argc, char **argv) +{ + uint64_t tb1, tb2, dec; + int i; + + handle_exception(0x900, &dec_handler, NULL); + + for (i = 0; i < 100; i++) { + tb1 = get_tb(); + mtspr(SPR_DEC, dec_max); + dec = mfspr(SPR_DEC); + tb2 = get_tb(); + if (tb2 - tb1 < dec_max - dec) + break; + } + report(tb2 - tb1 >= dec_max - dec, "decrementer remains within TB after mtDEC"); + + tb1 = get_tb(); + mtspr(SPR_DEC, dec_max); + mdelay(1000); + dec = mfspr(SPR_DEC); + tb2 = get_tb(); + report(tb2 - tb1 >= dec_max - dec, "decrementer remains within TB after 1s"); + + mtspr(SPR_DEC, dec_max); + local_irq_enable(); + local_irq_disable(); + if (mfspr(SPR_DEC) <= dec_max) { + report(!got_interrupt, "no interrupt on decrementer positive"); + } + got_interrupt = false; + + mtspr(SPR_DEC, 1); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer underflow"); + got_interrupt = false; + + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer still underflown"); + got_interrupt = false; + + mtspr(SPR_DEC, 0); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "DEC deal with set to 0"); + got_interrupt = false; + + /* Test for level-triggered decrementer */ + mtspr(SPR_DEC, -1ULL); + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer write MSB"); + got_interrupt = false; + + mtspr(SPR_DEC, dec_max); + local_irq_enable(); + if (do_migrate) + migrate(); + mtspr(SPR_DEC, -1); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer write MSB with irqs on"); + got_interrupt = false; + + mtspr(SPR_DEC, dec_min + 1); + mdelay(100); + local_irq_enable(); + local_irq_disable(); + report(!got_interrupt, "no interrupt after wrap to positive"); + got_interrupt = false; + + handle_exception(0x900, NULL, NULL); +} + +static void test_hdec(int argc, char **argv) +{ + uint64_t tb1, tb2, hdec; + + if (!machine_is_powernv()) { + report_skip("skipping on !powernv machine"); + return; + } + + handle_exception(0x900, &dec_stop_handler, NULL); + handle_exception(0x980, &dec_handler, NULL); + + mtspr(SPR_HDEC, dec_max); + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_HDICE); + + tb1 = get_tb(); + mtspr(SPR_HDEC, dec_max); + hdec = mfspr(SPR_HDEC); + tb2 = get_tb(); + report(tb2 - tb1 >= dec_max - hdec, "hdecrementer remains within TB"); + + tb1 = get_tb(); + mtspr(SPR_HDEC, dec_max); + mdelay(1000); + hdec = mfspr(SPR_HDEC); + tb2 = get_tb(); + report(tb2 - tb1 >= dec_max - hdec, "hdecrementer remains within TB after 1s"); + + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + local_irq_disable(); + if (mfspr(SPR_HDEC) <= dec_max) { + report(!got_interrupt, "no interrupt on decrementer positive"); + } + got_interrupt = false; + + mtspr(SPR_HDEC, 1); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + /* HDEC is edge triggered so ensure it still fires */ + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on hdecrementer underflow"); + got_interrupt = false; + + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(!got_interrupt, "no interrupt on hdecrementer still underflown"); + got_interrupt = false; + + mtspr(SPR_HDEC, -1ULL); + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "no interrupt on hdecrementer underflown write MSB"); + got_interrupt = false; + + mtspr(SPR_HDEC, 0); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + /* HDEC is edge triggered so ensure it still fires */ + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "HDEC deal with set to 0"); + got_interrupt = false; + + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + if (do_migrate) + migrate(); + mtspr(SPR_HDEC, -1ULL); + local_irq_disable(); + report(got_interrupt, "interrupt on hdecrementer write MSB with irqs on"); + got_interrupt = false; + + mtspr(SPR_HDEC, dec_max); + got_interrupt = false; + mtspr(SPR_HDEC, dec_min + 1); + if (do_migrate) + migrate(); + mdelay(100); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "got interrupt after wrap to positive"); + got_interrupt = false; + + mtspr(SPR_HDEC, -1ULL); + local_irq_enable(); + local_irq_disable(); + got_interrupt = false; + mtspr(SPR_HDEC, dec_min + 1000000); + if (do_migrate) + migrate(); + mdelay(100); + mtspr(SPR_HDEC, -1ULL); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "edge re-armed after wrap to positive"); + got_interrupt = false; + + mtspr(SPR_LPCR, mfspr(SPR_LPCR) & ~LPCR_HDICE); + + handle_exception(0x900, NULL, NULL); + handle_exception(0x980, NULL, NULL); +} + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "tb", test_tb }, + { "dec", test_dec }, + { "hdec", test_hdec }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + bool all; + int i; + + all = argc == 1 || !strcmp(argv[1], "all"); + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-w")) { + do_migrate = true; + if (!all && argc == 2) + all = true; + } + } + + find_dec_bits(); + dec_max = (1ULL << (dec_bits - 1)) - 1; + dec_min = (1ULL << (dec_bits - 1)); + + if (machine_is_powernv() && dec_bits > 32) { + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_LD); + } + + report_prefix_push("timebase"); + + for (i = 0; hctests[i].name != NULL; i++) { + if (all || strcmp(argv[1], hctests[i].name) == 0) { + report_prefix_push(hctests[i].name); + hctests[i].func(argc, argv); + report_prefix_pop(); + } + } + + report_prefix_pop(); + + if (machine_is_powernv() && dec_bits > 32) { + mtspr(SPR_LPCR, mfspr(SPR_LPCR) & ~LPCR_LD); + } + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 803a636cb..0be787f67 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -97,6 +97,14 @@ machine = pseries extra_params = -append "'migration -m'" groups = migration +[timebase] +file = timebase.elf + +[timebase-icount] +file = timebase.elf +accel = tcg +extra_params = -icount shift=5 + [h_cede_tm] file = tm.elf machine = pseries From patchwork Tue Mar 19 07:59:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YFPvRKGb; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPlX3glhz1yWv for ; Tue, 19 Mar 2024 19:19:36 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YFPvRKGb; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPlX2fWDz3vp1 for ; Tue, 19 Mar 2024 19:19:36 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=YFPvRKGb; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c33; helo=mail-oo1-xc33.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) (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 4TzPLb4PBbz3dWS for ; Tue, 19 Mar 2024 19:01:27 +1100 (AEDT) Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5a477c48fdeso2535320eaf.2 for ; Tue, 19 Mar 2024 01:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835285; x=1711440085; darn=lists.ozlabs.org; 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=P82grlYdo2S9GJOy7oBthEeuMNI/PcwAuBdV3I1rDuk=; b=YFPvRKGb2Z8X+aq5YvZimos+7QDq5L7fUk3sg1pKdsqCDAeFudg/Y4v4fH9VEcYqrI 8/JCT1YJ0oCwphTNLoy/EQTf6RPGtFy2IGihPortJGkBOBbNz+T7bQs0YyBatNB+Hy4O nDHFCIEZ9QMrazp7pzdoz541bbYunBEuLONaHQQOBbM16zHmQk0N6aeqLO58mavyjPl/ czCt7fSWe7jyEhYI6KCInIGiQALe9TaFZjN84K1B/ov0zT6VnjeAT2+oeulLoL8OObZ5 arI0Q2tjMlIZmuyoJV0yHlmK14jxUUyXdLQo+GUNwyENPHs8X8JS4UK9DworBqonkbBL KspQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835285; x=1711440085; 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=P82grlYdo2S9GJOy7oBthEeuMNI/PcwAuBdV3I1rDuk=; b=jYn86u/jGCnJdom8/rdWY1IIAw3VzvoEZC4oR2mXTmoKIoNVCg7RZzaANsyI026CjK 03fNCpOnkhmHq7DIxgUtob/pVeof9udEoNqhxMtvBBIiqdoKW4F/0rLkAjJVcYTz0VIx vaU5+uxCKEW7RJWD7tqEVC5H233Rn/nG0hW0+D3G4T6tZZNoAs458noqGDg/QU5ibkFj RjtUtrbmrao/XU2r+8HDlzcGBjXSs5PYCL8jfUth2/0+RvNM97JvqTizm2un1dkmROCD OV0ewKXdAuji7eciWV9rVZzTD6WTtQN6FULSOECfHb8TH3+8x22/gOipflvZ7JCDsIMu FhJQ== X-Forwarded-Encrypted: i=1; AJvYcCXUNWqJ3OnF7soct6wAlUEXU9MjBlE+GmFZuBRs6YcTVqPwEj0FD00WJfOYiF6ewGInz9XUzDZk5gOSJ/mVuZzpsgkA81o53nrWRhn81w== X-Gm-Message-State: AOJu0YypGOvzBWHpuznTxooiZjtHxBbyPb40d+li9XkxnhnN9sKv37e9 ZA8cWz7Cmj6tkfYD/K7/IZJ1y75trZhrxaVl00GwIGeSJ4MCah4F X-Google-Smtp-Source: AGHT+IFyTDdfP84a3SZu7N9TSBm/IG6IOYDj60esquJYMg8VjS3P49gHLLtADUggRi5sNnvpFOGMqg== X-Received: by 2002:a05:6870:9a17:b0:221:bc5b:ec51 with SMTP id fo23-20020a0568709a1700b00221bc5bec51mr14373469oab.15.1710835285397; Tue, 19 Mar 2024 01:01:25 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:25 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 27/35] powerpc: Add MMU support Date: Tue, 19 Mar 2024 17:59:18 +1000 Message-ID: <20240319075926.2422707-28-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add support for radix MMU, 4kB and 64kB pages. This also adds MMU interrupt test cases, and runs the interrupts test entirely with MMU enabled if it is available (aside from machine check tests). Acked-by: Andrew Jones (configure changes) Signed-off-by: Nicholas Piggin --- configure | 39 +++-- lib/powerpc/asm/hcall.h | 6 + lib/powerpc/asm/processor.h | 1 + lib/powerpc/asm/reg.h | 3 + lib/powerpc/asm/smp.h | 2 + lib/powerpc/processor.c | 9 ++ lib/powerpc/setup.c | 4 + lib/ppc64/asm/mmu.h | 11 ++ lib/ppc64/asm/page.h | 66 ++++++++- lib/ppc64/asm/pgtable-hwdef.h | 66 +++++++++ lib/ppc64/asm/pgtable.h | 125 ++++++++++++++++ lib/ppc64/mmu.c | 272 ++++++++++++++++++++++++++++++++++ lib/ppc64/opal-calls.S | 4 +- powerpc/Makefile.common | 2 + powerpc/Makefile.ppc64 | 1 + powerpc/interrupts.c | 96 ++++++++++-- 16 files changed, 680 insertions(+), 27 deletions(-) create mode 100644 lib/ppc64/asm/mmu.h create mode 100644 lib/ppc64/asm/pgtable-hwdef.h create mode 100644 lib/ppc64/asm/pgtable.h create mode 100644 lib/ppc64/mmu.c diff --git a/configure b/configure index 49f047cb2..e19ba6f0c 100755 --- a/configure +++ b/configure @@ -245,29 +245,35 @@ fi if [ -z "$page_size" ]; then if [ "$efi" = 'y' ] && [ "$arch" = "arm64" ]; then page_size="4096" - elif [ "$arch" = "arm64" ]; then + elif [ "$arch" = "arm64" ] || [ "$arch" = "ppc64" ]; then page_size="65536" elif [ "$arch" = "arm" ]; then page_size="4096" fi else - if [ "$arch" != "arm64" ]; then - echo "--page-size is not supported for $arch" - usage - fi - if [ "${page_size: -1}" = "K" ] || [ "${page_size: -1}" = "k" ]; then page_size=$(( ${page_size%?} * 1024 )) fi - if [ "$page_size" != "4096" ] && [ "$page_size" != "16384" ] && - [ "$page_size" != "65536" ]; then - echo "arm64 doesn't support page size of $page_size" + + if [ "$arch" = "arm64" ]; then + if [ "$page_size" != "4096" ] && [ "$page_size" != "16384" ] && + [ "$page_size" != "65536" ]; then + echo "arm64 doesn't support page size of $page_size" + usage + fi + if [ "$efi" = 'y' ] && [ "$page_size" != "4096" ]; then + echo "efi must use 4K pages" + exit 1 + fi + elif [ "$arch" = "ppc64" ]; then + if [ "$page_size" != "4096" ] && [ "$page_size" != "65536" ]; then + echo "ppc64 doesn't support page size of $page_size" + usage + fi + else + echo "--page-size is not supported for $arch" usage fi - if [ "$efi" = 'y' ] && [ "$page_size" != "4096" ]; then - echo "efi must use 4K pages" - exit 1 - fi fi [ -z "$processor" ] && processor="$arch" @@ -472,6 +478,13 @@ cat <> lib/config.h #define CONFIG_UART_EARLY_BASE ${arm_uart_early_addr} #define CONFIG_ERRATA_FORCE ${errata_force} + +EOF +fi + +if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] || [ "$arch" = "ppc64" ]; then +cat <> lib/config.h + #define CONFIG_PAGE_SIZE _AC(${page_size}, UL) EOF diff --git a/lib/powerpc/asm/hcall.h b/lib/powerpc/asm/hcall.h index e0f5009e3..3b44dd204 100644 --- a/lib/powerpc/asm/hcall.h +++ b/lib/powerpc/asm/hcall.h @@ -24,6 +24,12 @@ #define H_PUT_TERM_CHAR 0x58 #define H_RANDOM 0x300 #define H_SET_MODE 0x31C +#define H_REGISTER_PROCESS_TABLE 0x37C + +#define PTBL_NEW 0x18 +#define PTBL_UNREGISTER 0x10 +#define PTBL_RADIX 0x04 +#define PTBL_GTSE 0x01 #define KVMPPC_HCALL_BASE 0xf000 #define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index a3859b5d4..d348239c5 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -14,6 +14,7 @@ extern bool cpu_has_hv; extern bool cpu_has_power_mce; extern bool cpu_has_siar; extern bool cpu_has_heai; +extern bool cpu_has_radix; extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; extern bool cpu_has_pause_short; diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 12f9e8ac6..b2fab4313 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -11,6 +11,7 @@ #define SPR_SRR0 0x01a #define SPR_SRR1 0x01b #define SRR1_PREFIX UL(0x20000000) +#define SPR_PIDR 0x030 #define SPR_FSCR 0x099 #define FSCR_PREFIX UL(0x2000) #define SPR_HFSCR 0x0be @@ -36,7 +37,9 @@ #define SPR_LPCR 0x13e #define LPCR_HDICE UL(0x1) #define LPCR_LD UL(0x20000) +#define SPR_LPIDR 0x13f #define SPR_HEIR 0x153 +#define SPR_PTCR 0x1d0 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) #define MMCR0_PMAE UL(0x04000000) diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index 6ef3ae521..820c05e9e 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -3,6 +3,7 @@ #include #include +#include typedef void (*secondary_entry_fn)(int cpu_id); @@ -11,6 +12,7 @@ struct cpu { unsigned long stack; unsigned long exception_stack; secondary_entry_fn entry; + pgd_t *pgtable; } __attribute__((packed)); /* used by asm */ extern int nr_cpus_present; diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index a6ce3c905..09f6bb9d8 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -13,6 +13,7 @@ #include #include #include +#include #include static struct { @@ -47,6 +48,14 @@ void do_handle_exception(struct pt_regs *regs) __current_cpu = (struct cpu *)mfspr(SPR_SPRG0); + /* + * We run with AIL=0, so interrupts taken with MMU disabled. + * Enable here. + */ + assert(!(mfmsr() & (MSR_IR|MSR_DR))); + if (mmu_enabled()) + mtmsr(mfmsr() | (MSR_IR|MSR_DR)); + v = regs->trap >> 5; if (v < 128 && handlers[v].func) { diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 16f009152..ba659cc2b 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -102,6 +102,7 @@ bool cpu_has_hv; bool cpu_has_power_mce; /* POWER CPU machine checks */ bool cpu_has_siar; bool cpu_has_heai; +bool cpu_has_radix; bool cpu_has_prefix; bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ bool cpu_has_pause_short; @@ -124,6 +125,7 @@ static void cpu_init_params(void) cpu_has_sc_lev = true; cpu_has_pause_short = true; case PVR_VER_POWER9: + cpu_has_radix = true; case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: case PVR_VER_POWER8: @@ -198,6 +200,7 @@ void cpu_init(struct cpu *cpu, int cpu_id) cpu->stack += SZ_64K - 64; cpu->exception_stack = (unsigned long)memalign(SZ_4K, SZ_64K); cpu->exception_stack += SZ_64K - 64; + cpu->pgtable = NULL; } void setup(const void *fdt) @@ -216,6 +219,7 @@ void setup(const void *fdt) cpu->server_no = fdt_boot_cpuid_phys(fdt); cpu->exception_stack = (unsigned long)boot_exception_stack; cpu->exception_stack += SZ_64K - 64; + cpu->pgtable = NULL; mtspr(SPR_SPRG0, (unsigned long)cpu); __current_cpu = cpu; diff --git a/lib/ppc64/asm/mmu.h b/lib/ppc64/asm/mmu.h new file mode 100644 index 000000000..fadeee4bc --- /dev/null +++ b/lib/ppc64/asm/mmu.h @@ -0,0 +1,11 @@ +#ifndef _ASMPOWERPC_MMU_H_ +#define _ASMPOWERPC_MMU_H_ + +#include + +bool vm_available(void); +bool mmu_enabled(void); +void mmu_enable(pgd_t *pgtable); +void mmu_disable(void); + +#endif diff --git a/lib/ppc64/asm/page.h b/lib/ppc64/asm/page.h index 1a8b62711..c497d86b9 100644 --- a/lib/ppc64/asm/page.h +++ b/lib/ppc64/asm/page.h @@ -1 +1,65 @@ -#include +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMPPC64_PAGE_H_ +#define _ASMPPC64_PAGE_H_ +/* + * Adapted from + * lib/arm64/asm/page.h and Linux kernel defines. + * + * Copyright (C) 2017, Red Hat Inc, Andrew Jones + */ + +#include +#include +#include + +#define VA_BITS 52 + +#define PAGE_SIZE CONFIG_PAGE_SIZE +#if PAGE_SIZE == SZ_64K +#define PAGE_SHIFT 16 +#elif PAGE_SIZE == SZ_4K +#define PAGE_SHIFT 12 +#else +#error Unsupported PAGE_SIZE +#endif +#define PAGE_MASK (~(PAGE_SIZE-1)) + +#ifndef __ASSEMBLY__ + +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) + +typedef u64 pteval_t; +typedef u64 pmdval_t; +typedef u64 pudval_t; +typedef u64 pgdval_t; +typedef struct { pteval_t pte; } pte_t; +typedef struct { pmdval_t pmd; } pmd_t; +typedef struct { pudval_t pud; } pud_t; +typedef struct { pgdval_t pgd; } pgd_t; +typedef struct { pteval_t pgprot; } pgprot_t; + +#define pte_val(x) ((x).pte) +#define pmd_val(x) ((x).pmd) +#define pud_val(x) ((x).pud) +#define pgd_val(x) ((x).pgd) +#define pgprot_val(x) ((x).pgprot) + +#define __pte(x) ((pte_t) { (x) } ) +#define __pmd(x) ((pmd_t) { (x) } ) +#define __pud(x) ((pud_t) { (x) } ) +#define __pgd(x) ((pgd_t) { (x) } ) +#define __pgprot(x) ((pgprot_t) { (x) } ) + +#define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x))) +#define __pa(x) __virt_to_phys((unsigned long)(x)) + +#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) +#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) + +extern phys_addr_t __virt_to_phys(unsigned long addr); +extern unsigned long __phys_to_virt(phys_addr_t addr); + +extern void *__ioremap(phys_addr_t phys_addr, size_t size); + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMPPC64_PAGE_H_ */ diff --git a/lib/ppc64/asm/pgtable-hwdef.h b/lib/ppc64/asm/pgtable-hwdef.h new file mode 100644 index 000000000..7cb2c7476 --- /dev/null +++ b/lib/ppc64/asm/pgtable-hwdef.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMPPC64_PGTABLE_HWDEF_H_ +#define _ASMPPC64_PGTABLE_HWDEF_H_ +/* + * Copyright (C) 2024, IBM Inc, Nicholas Piggin + * + * Derived from Linux kernel MMU code. + */ + +#include + +#define UL(x) _AC(x, UL) + +/* + * Book3S-64 Radix page table + */ +#define PGDIR_SHIFT 39 +#define PUD_SHIFT 30 +#define PMD_SHIFT 21 + +#define PTRS_PER_PGD (SZ_64K / 8) +#define PTRS_PER_PUD (SZ_4K / 8) +#define PTRS_PER_PMD (SZ_4K / 8) +#if PAGE_SIZE == SZ_4K +#define PTRS_PER_PTE (SZ_4K / 8) +#else /* 64K */ +#define PTRS_PER_PTE (256 / 8) +#endif + +#define PGDIR_SIZE (UL(1) << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE-1)) + +#define PUD_SIZE (UL(1) << PUD_SHIFT) +#define PUD_MASK (~(PUD_SIZE-1)) + +#define PMD_SIZE (UL(1) << PMD_SHIFT) +#define PMD_MASK (~(PMD_SIZE-1)) + +#define _PAGE_VALID 0x8000000000000000UL +#define _PAGE_PTE 0x4000000000000000UL + +#define _PAGE_EXEC 0x00001 /* execute permission */ +#define _PAGE_WRITE 0x00002 /* write access allowed */ +#define _PAGE_READ 0x00004 /* read access allowed */ +#define _PAGE_PRIVILEGED 0x00008 /* kernel access only */ +#define _PAGE_SAO 0x00010 /* Strong access order */ +#define _PAGE_NON_IDEMPOTENT 0x00020 /* non idempotent memory */ +#define _PAGE_TOLERANT 0x00030 /* tolerant memory, cache inhibited */ +#define _PAGE_DIRTY 0x00080 /* C: page changed */ +#define _PAGE_ACCESSED 0x00100 /* R: page referenced */ + +/* + * Software bits + */ +#define _PAGE_SW0 0x2000000000000000UL +#define _PAGE_SW1 0x00800UL +#define _PAGE_SW2 0x00400UL +#define _PAGE_SW3 0x00200UL + +/* + * Highest possible physical address. + */ +#define PHYS_MASK_SHIFT (48) +#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) + +#endif /* _ASMPPC64_PGTABLE_HWDEF_H_ */ diff --git a/lib/ppc64/asm/pgtable.h b/lib/ppc64/asm/pgtable.h new file mode 100644 index 000000000..a6ee0d4cd --- /dev/null +++ b/lib/ppc64/asm/pgtable.h @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMARM64_PGTABLE_H_ +#define _ASMARM64_PGTABLE_H_ +/* + * Copyright (C) 2024, IBM Inc, Nicholas Piggin + * + * Derived from Linux kernel MMU code. + */ +#include +#include +#include +#include +#include +#include + +#include + +/* + * We can convert va <=> pa page table addresses with simple casts + * because we always allocate their pages with alloc_page(), and + * alloc_page() always returns identity mapped pages. + */ +#define pgtable_va(x) ((void *)(unsigned long)(x)) +#define pgtable_pa(x) ((unsigned long)(x)) + +#define pgd_none(pgd) (!pgd_val(pgd)) +#define pud_none(pud) (!pud_val(pud)) +#define pmd_none(pmd) (!pmd_val(pmd)) +#define pte_none(pte) (!pte_val(pte)) + +#define pgd_valid(pgd) (pgd_val(pgd) & cpu_to_be64(_PAGE_VALID)) +#define pud_valid(pud) (pud_val(pud) & cpu_to_be64(_PAGE_VALID)) +#define pmd_valid(pmd) (pmd_val(pmd) & cpu_to_be64(_PAGE_VALID)) +#define pte_valid(pte) (pte_val(pte) & cpu_to_be64(_PAGE_VALID)) + +#define pmd_huge(pmd) false + +static inline pud_t *pgd_page_vaddr(pgd_t pgd) +{ + return pgtable_va(be64_to_cpu(pgd_val(pgd)) & PHYS_MASK & ~0xfffULL); +} + +static inline pmd_t *pud_page_vaddr(pud_t pud) +{ + return pgtable_va(be64_to_cpu(pud_val(pud)) & PHYS_MASK & ~0xfffULL); +} + +static inline pte_t *pmd_page_vaddr(pmd_t pmd) +{ + return pgtable_va(be64_to_cpu(pmd_val(pmd)) & PHYS_MASK & ~0xfffULL); +} + +#define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1)) +#define pgd_offset(pt, addr) ((pt) + pgd_index(addr)) +#define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) +#define pud_offset(pgd, addr) (pgd_page_vaddr(*(pgd)) + pud_index(addr)) +#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) +#define pmd_offset(pud, addr) (pud_page_vaddr(*(pud)) + pmd_index(addr)) +#define pte_index(addr) (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) +#define pte_offset(pmd, addr) (pmd_page_vaddr(*(pmd)) + pte_index(addr)) + +#define pgd_free(pgd) free(pgd) +static inline pgd_t *pgd_alloc_one(void) +{ + size_t sz = PTRS_PER_PGD * sizeof(pgd_t); + pgd_t *pgd = memalign_pages(sz, sz); + memset(pgd, 0, sz); + return pgd; +} + +#define pud_free(pud) free(pud) +static inline pud_t *pud_alloc_one(void) +{ + size_t sz = PTRS_PER_PGD * sizeof(pud_t); + pud_t *pud = memalign_pages(sz, sz); + memset(pud, 0, sz); + return pud; +} +static inline pud_t *pud_alloc(pgd_t *pgd, unsigned long addr) +{ + if (pgd_none(*pgd)) { + pgd_t entry; + pgd_val(entry) = cpu_to_be64(pgtable_pa(pud_alloc_one()) | _PAGE_VALID | (12 - 3) /* 4k pud page */); + WRITE_ONCE(*pgd, entry); + } + return pud_offset(pgd, addr); +} + +#define pmd_free(pmd) free(pmd) +static inline pmd_t *pmd_alloc_one(void) +{ + size_t sz = PTRS_PER_PMD * sizeof(pmd_t); + pmd_t *pmd = memalign_pages(sz, sz); + memset(pmd, 0, sz); + return pmd; +} +static inline pmd_t *pmd_alloc(pud_t *pud, unsigned long addr) +{ + if (pud_none(*pud)) { + pud_t entry; + pud_val(entry) = cpu_to_be64(pgtable_pa(pmd_alloc_one()) | _PAGE_VALID | (12 - 3) /* 4k pmd page */); + WRITE_ONCE(*pud, entry); + } + return pmd_offset(pud, addr); +} + +#define pte_free(pte) free(pte) +static inline pte_t *pte_alloc_one(void) +{ + size_t sz = PTRS_PER_PTE * sizeof(pte_t); + pte_t *pte = memalign_pages(sz, sz); + memset(pte, 0, sz); + return pte; +} +static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr) +{ + if (pmd_none(*pmd)) { + pmd_t entry; + pmd_val(entry) = cpu_to_be64(pgtable_pa(pte_alloc_one()) | _PAGE_VALID | (21 - PAGE_SHIFT) /* 4k/256B pte page */); + WRITE_ONCE(*pmd, entry); + } + return pte_offset(pmd, addr); +} + +#endif /* _ASMPPC64_PGTABLE_H_ */ diff --git a/lib/ppc64/mmu.c b/lib/ppc64/mmu.c new file mode 100644 index 000000000..7e445fdaf --- /dev/null +++ b/lib/ppc64/mmu.c @@ -0,0 +1,272 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Radix MMU support + * + * Copyright (C) 2024, IBM Inc, Nicholas Piggin + * + * Derived from Linux kernel MMU code. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "alloc_page.h" +#include "vmalloc.h" +#include +#include + +#include + +static pgd_t *identity_pgd; + +bool vm_available(void) +{ + return cpu_has_radix; +} + +bool mmu_enabled(void) +{ + return current_cpu()->pgtable != NULL; +} + +void mmu_enable(pgd_t *pgtable) +{ + struct cpu *cpu = current_cpu(); + + if (!pgtable) + pgtable = identity_pgd; + + cpu->pgtable = pgtable; + + mtmsr(mfmsr() | (MSR_IR|MSR_DR)); +} + +void mmu_disable(void) +{ + struct cpu *cpu = current_cpu(); + + cpu->pgtable = NULL; + + mtmsr(mfmsr() & ~(MSR_IR|MSR_DR)); +} + +static inline void tlbie(unsigned long rb, unsigned long rs, int ric, int prs, int r) +{ + asm volatile(".machine push ; .machine power9; ptesync ; tlbie %0,%1,%2,%3,%4 ; eieio ; tlbsync ; ptesync ; .machine pop" :: "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r) : "memory"); +} + +static void flush_tlb_page(uintptr_t vaddr) +{ + unsigned long rb; + unsigned long ap; + + /* AP should come from dt (for pseries, at least) */ + if (PAGE_SIZE == SZ_4K) + ap = 0; + else if (PAGE_SIZE == SZ_64K) + ap = 5; + else if (PAGE_SIZE == SZ_2M) + ap = 1; + else if (PAGE_SIZE == SZ_1G) + ap = 2; + else + assert(0); + + rb = vaddr & ~((1UL << 12) - 1); + rb |= ap << 5; + + tlbie(rb, 0, 0, 1, 1); +} + +static pteval_t *get_pte(pgd_t *pgtable, uintptr_t vaddr) +{ + pgd_t *pgd = pgd_offset(pgtable, vaddr); + pud_t *pud = pud_alloc(pgd, vaddr); + pmd_t *pmd = pmd_alloc(pud, vaddr); + pte_t *pte = pte_alloc(pmd, vaddr); + + return &pte_val(*pte); +} + +static pteval_t *install_pte(pgd_t *pgtable, uintptr_t vaddr, pteval_t pte) +{ + pteval_t *p_pte = get_pte(pgtable, vaddr); + + if (READ_ONCE(*p_pte) & cpu_to_be64(_PAGE_VALID)) { + WRITE_ONCE(*p_pte, 0); + flush_tlb_page(vaddr); + } + + WRITE_ONCE(*p_pte, cpu_to_be64(pte)); + + return p_pte; +} + +static pteval_t *install_page_prot(pgd_t *pgtable, phys_addr_t phys, + uintptr_t vaddr, pgprot_t prot) +{ + pteval_t pte = phys; + pte |= _PAGE_VALID | _PAGE_PTE; + pte |= pgprot_val(prot); + return install_pte(pgtable, vaddr, pte); +} + +pteval_t *install_page(pgd_t *pgtable, phys_addr_t phys, void *virt) +{ + return install_page_prot(pgtable, phys, (uintptr_t)virt, + __pgprot(_PAGE_VALID | _PAGE_PTE | + _PAGE_READ | _PAGE_WRITE | + _PAGE_EXEC | _PAGE_ACCESSED | + _PAGE_DIRTY)); +} + +static pteval_t *follow_pte(pgd_t *pgtable, uintptr_t vaddr) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + pgd = pgd_offset(pgtable, vaddr); + if (!pgd_valid(*pgd)) + return NULL; + + pud = pud_offset(pgd, vaddr); + if (!pud_valid(*pud)) + return NULL; + + pmd = pmd_offset(pud, vaddr); + if (!pmd_valid(*pmd)) + return NULL; + if (pmd_huge(*pmd)) + return &pmd_val(*pmd); + + pte = pte_offset(pmd, vaddr); + if (!pte_valid(*pte)) + return NULL; + + return &pte_val(*pte); +} + +phys_addr_t virt_to_pte_phys(pgd_t *pgtable, void *virt) +{ + phys_addr_t mask; + pteval_t *pteval; + + pteval = follow_pte(pgtable, (uintptr_t)virt); + if (!pteval) { + install_page(pgtable, (phys_addr_t)(unsigned long)virt, virt); + return (phys_addr_t)(unsigned long)virt; + } + + if (pmd_huge(__pmd(*pteval))) + mask = PMD_MASK; + else + mask = PAGE_MASK; + + return (be64_to_cpu(*pteval) & PHYS_MASK & mask) | + ((phys_addr_t)(unsigned long)virt & ~mask); +} + +struct partition_table_entry { + uint64_t dw0; + uint64_t dw1; +}; + +static struct partition_table_entry *partition_table; + +struct process_table_entry { + uint64_t dw0; + uint64_t dw1; +}; + +static struct process_table_entry *process_table; + +void *setup_mmu(phys_addr_t phys_end, void *unused) +{ + phys_addr_t addr; + uint64_t dw0, dw1; + + if (identity_pgd) + goto enable; + + assert_msg(cpu_has_radix, "MMU support requires radix MMU."); + + /* 32G address is reserved for vmalloc, cap phys_end at 31G */ + if (phys_end > (31ul << 30)) { + /* print warning */ + phys_end = 31ul << 30; + } + + init_alloc_vpage((void *)(32ul << 30)); + + process_table = memalign_pages(SZ_4K, SZ_4K); + memset(process_table, 0, SZ_4K); + + identity_pgd = pgd_alloc_one(); + + dw0 = (unsigned long)identity_pgd; + dw0 |= 16UL - 3; /* 64K pgd size */ + dw0 |= (0x2UL << 61) | (0x5UL << 5); /* 52-bit virt */ + process_table[1].dw0 = cpu_to_be64(dw0); + + if (machine_is_pseries()) { + int ret; + + ret = hcall(H_REGISTER_PROCESS_TABLE, PTBL_NEW | PTBL_RADIX | PTBL_GTSE, process_table, 0, 0 /* 4K size */); + assert_msg(!ret, "H_REGISTER_PROCESS_TABLE failed! err=%d\n", ret); + } else if (machine_is_powernv()) { + partition_table = memalign_pages(SZ_4K, SZ_4K); + memset(partition_table, 0, SZ_4K); + + mtspr(SPR_PTCR, (unsigned long)partition_table); /* 4KB size */ + + /* Reuse dw0 for partition table */ + dw0 |= 1ULL << 63; /* Host radix */ + dw1 = (unsigned long)process_table; /* 4K size */ + partition_table[0].dw0 = cpu_to_be64(dw0); + partition_table[0].dw1 = cpu_to_be64(dw1); + + mtspr(SPR_LPIDR, 0); + /* Set LPCR[UPRT] and LPCR[HR] for radix */ + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | (1ULL << 22) | (1ULL << 20)); + } else { + /* Only pseries and powernv support radix so far */ + assert(0); + } + + for (addr = 0; addr < phys_end; addr += PAGE_SIZE) + install_page(identity_pgd, addr, __va(addr)); + +enable: + /* PID=1 is used because PID=0 is also mapped in quadrant 3 */ + mtspr(SPR_PIDR, 1); + + mmu_enable(identity_pgd); + + return identity_pgd; +} + +phys_addr_t __virt_to_phys(unsigned long addr) +{ + if (mmu_enabled()) { + pgd_t *pgtable = current_cpu()->pgtable; + return virt_to_pte_phys(pgtable, (void *)addr); + } + return addr; +} + +unsigned long __phys_to_virt(phys_addr_t addr) +{ + /* + * We don't guarantee that phys_to_virt(virt_to_phys(vaddr)) == vaddr, but + * the default page tables do identity map all physical addresses, which + * means phys_to_virt(virt_to_phys((void *)paddr)) == paddr. + */ + assert(!mmu_enabled() || __virt_to_phys(addr) == addr); + return addr; +} diff --git a/lib/ppc64/opal-calls.S b/lib/ppc64/opal-calls.S index 8cb4c3e91..bc9c51f84 100644 --- a/lib/ppc64/opal-calls.S +++ b/lib/ppc64/opal-calls.S @@ -25,8 +25,8 @@ opal_call: mfmsr r12 std r12,-16(r1) /* use redzone */ - /* switch to BE when we enter OPAL */ - li r11,(1 << MSR_LE_BIT) + /* switch to BE and real-mode when we enter OPAL */ + li r11,(1 << MSR_LE_BIT) | MSR_IR | MSR_DR ori r11,r11,(1 << MSR_EE_BIT) andc r12,r12,r11 mtspr SPR_HSRR1,r12 diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 1348f658b..5871da47a 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -41,6 +41,8 @@ cflatobjs += lib/util.o cflatobjs += lib/getchar.o cflatobjs += lib/alloc_phys.o cflatobjs += lib/alloc.o +cflatobjs += lib/alloc_page.o +cflatobjs += lib/vmalloc.o cflatobjs += lib/devicetree.o cflatobjs += lib/migrate.o cflatobjs += lib/powerpc/io.o diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 index a18a9628f..2466471f9 100644 --- a/powerpc/Makefile.ppc64 +++ b/powerpc/Makefile.ppc64 @@ -18,6 +18,7 @@ reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 cflatobjs += lib/ppc64/stack.o +cflatobjs += lib/ppc64/mmu.o cflatobjs += lib/ppc64/opal.o cflatobjs += lib/ppc64/opal-calls.o diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c index 552c48ef2..6bed26e41 100644 --- a/powerpc/interrupts.c +++ b/powerpc/interrupts.c @@ -14,6 +14,9 @@ #include #include #include +#include +#include "alloc_phys.h" +#include "vmalloc.h" static volatile bool got_interrupt; static volatile struct pt_regs recorded_regs; @@ -44,6 +47,7 @@ static void test_mce(void) unsigned long addr = -4ULL; uint8_t tmp; bool is_fetch; + bool mmu = mmu_enabled(); report_prefix_push("mce"); @@ -53,6 +57,9 @@ static void test_mce(void) handle_exception(0x400, fault_handler, NULL); handle_exception(0x480, fault_handler, NULL); + if (mmu) + mmu_disable(); + if (machine_is_powernv()) { enable_mcheck(); } else { @@ -71,7 +78,6 @@ static void test_mce(void) is_fetch = false; asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); - report(got_interrupt, "MCE on access to invalid real address"); if (got_interrupt) { report(mfspr(SPR_DAR) == addr, "MCE sets DAR correctly"); @@ -90,6 +96,9 @@ static void test_mce(void) got_interrupt = false; } + if (mmu) + mmu_enable(NULL); + handle_exception(0x200, NULL, NULL); handle_exception(0x300, NULL, NULL); handle_exception(0x380, NULL, NULL); @@ -99,29 +108,36 @@ static void test_mce(void) report_prefix_pop(); } -static void dseg_handler(struct pt_regs *regs, void *data) +static void dside_handler(struct pt_regs *regs, void *data) { got_interrupt = true; memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); regs_advance_insn(regs); - regs->msr &= ~MSR_DR; } -static void test_dseg(void) +static void iside_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->nip = regs->link; +} + +static void test_dseg_nommu(void) { uint64_t msr, tmp; - report_prefix_push("data segment"); + report_prefix_push("dseg"); /* Some HV start in radix mode and need 0x300 */ - handle_exception(0x300, &dseg_handler, NULL); - handle_exception(0x380, &dseg_handler, NULL); + handle_exception(0x300, &dside_handler, NULL); + handle_exception(0x380, &dside_handler, NULL); asm volatile( " mfmsr %0 \n \ - ori %0,%0,%2 \n \ - mtmsrd %0 \n \ - lbz %1,0(0) " + ori %1,%0,%2 \n \ + mtmsrd %1 \n \ + lbz %1,0(0) \n \ + mtmsrd %0 " : "=r"(msr), "=r"(tmp) : "i"(MSR_DR): "memory"); report(got_interrupt, "interrupt on NULL dereference"); @@ -133,6 +149,61 @@ static void test_dseg(void) report_prefix_pop(); } +static void test_mmu(void) +{ + uint64_t tmp, addr; + phys_addr_t base, top; + + if (!mmu_enabled()) { + test_dseg_nommu(); + return; + } + + phys_alloc_get_unused(&base, &top); + + report_prefix_push("dsi"); + addr = top + PAGE_SIZE; + handle_exception(0x300, &dside_handler, NULL); + asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); + report(got_interrupt, "dsi on out of range dereference"); + report(mfspr(SPR_DAR) == addr, "DAR set correctly"); + report(mfspr(SPR_DSISR) & (1ULL << 30), "DSISR set correctly"); + got_interrupt = false; + handle_exception(0x300, NULL, NULL); + report_prefix_pop(); + + report_prefix_push("dseg"); + addr = -4ULL; + handle_exception(0x380, &dside_handler, NULL); + asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); + report(got_interrupt, "dseg on out of range dereference"); + report(mfspr(SPR_DAR) == addr, "DAR set correctly"); + got_interrupt = false; + handle_exception(0x380, NULL, NULL); + report_prefix_pop(); + + report_prefix_push("isi"); + addr = top + PAGE_SIZE; + handle_exception(0x400, &iside_handler, NULL); + asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); + report(got_interrupt, "isi on out of range fetch"); + report(recorded_regs.nip == addr, "SRR0 set correctly"); + report(recorded_regs.msr & (1ULL << 30), "SRR1 set correctly"); + got_interrupt = false; + handle_exception(0x400, NULL, NULL); + report_prefix_pop(); + + report_prefix_push("iseg"); + addr = -4ULL; + handle_exception(0x480, &iside_handler, NULL); + asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); + report(got_interrupt, "isi on out of range fetch"); + report(recorded_regs.nip == addr, "SRR0 set correctly"); + got_interrupt = false; + handle_exception(0x480, NULL, NULL); + report_prefix_pop(); +} + static void dec_handler(struct pt_regs *regs, void *data) { got_interrupt = true; @@ -400,9 +471,12 @@ int main(int argc, char **argv) { report_prefix_push("interrupts"); + if (vm_available()) + setup_vm(); + if (cpu_has_power_mce) test_mce(); - test_dseg(); + test_mmu(); test_illegal(); test_dec(); test_sc(); From patchwork Tue Mar 19 07:59:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JsmuShZz; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPmV1SHfz1yWs for ; Tue, 19 Mar 2024 19:20:26 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JsmuShZz; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPmT2F9sz3vyD for ; Tue, 19 Mar 2024 19:20:25 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=JsmuShZz; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::430; helo=mail-pf1-x430.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 4TzPLh4prYz3vdl for ; Tue, 19 Mar 2024 19:01:32 +1100 (AEDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6e6eb891db9so4849794b3a.3 for ; Tue, 19 Mar 2024 01:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835291; x=1711440091; darn=lists.ozlabs.org; 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=jtkbIYHcs9Z7wd6d39OXgdj3kfUKXbm4ZJQ1x4xi+EM=; b=JsmuShZzuyqzIUKNCU2sEct7STa3JKV29ZWzQmgQG+nJguLa2kJe5hH7T3K2HPyAZv rjdg7ngjHl1VQ1fmBjaNoNzLOGOu8nptb3OrBbcVgqVgqwxZDDaU/7zEQmEQM88Qq/nT geuW7Ojtoaq3Dxwye1HIwWfZ180SATQePpUDN59xmU9By8aMjfXsyVMy8HRZPKoq+Yx+ 3xnZZ2+dzqe9n+/aBxcfHe0NXPMGDX6xipGwYwjWt/6hiY4b2MGQimyMWa0OTRyKhX3X uKEf1koG/uGJi99gkq2Mk0Fubw99negDVK5AxU90YmP+5YDT3DtwudEOknzfi9Sm7oug AcBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835291; x=1711440091; 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=jtkbIYHcs9Z7wd6d39OXgdj3kfUKXbm4ZJQ1x4xi+EM=; b=dJjn+hUw6oX6M8q3QleldgDjUg0lkLTsr4JCdZBPGq5yj67K/Qf0MSB9XaVHdg3prG kf1/koiqpn9pIVrW3uCOTyRmXLxHBLYX79Qx+olNXaUuTuc+MjUz39PcsJyzKcGvmwfu T2qW5i8oG7plTE8twAm6sE1xPuFYANRwPpJ+P++Y0r6rd29vDj/misBPR1Dkir5fnoIf Vw6p6f3w5RFoinOYjzSZsb8Gu40Zeb0WEr9FhlCfghbtRPzBAgww7aFRpWUoausszLU5 WI8rqPCzCxrw+pVifl8YE+kqME/BGF1hjHrI5Cft5X0sNiqTO+E95EbUVs6TKj+dozgP X3TA== X-Forwarded-Encrypted: i=1; AJvYcCXgBkttKSFgRqwaaC834Xm/2EiSdt2k1g/1CwZNXt0Rt0xePGQEsR7+xzcJsdYGPlg/INiRWEC4zRcbSIMHyPecwQLA1skvuwfJqU0u8A== X-Gm-Message-State: AOJu0YykElU0+a84tjUkbFSk/2RxXKvZ4k7Ja/GKFemes4WYq0dcu52/ Knsqq+AMBpBEmZ10kIh9QEYCpa5/NeMBrEXL4HF2I5K5/JAG0ZsW X-Google-Smtp-Source: AGHT+IHh8d74HAxWLNZuLT7882WxsnK+rCPvG3s+cIXFd6F5jOkgfb78HhHkZfJKKDCSzgvliCjSZQ== X-Received: by 2002:a05:6a00:b82:b0:6e6:843f:1d05 with SMTP id g2-20020a056a000b8200b006e6843f1d05mr19243112pfj.25.1710835290863; Tue, 19 Mar 2024 01:01:30 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:30 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 28/35] common/sieve: Use vmalloc.h for setup_mmu definition Date: Tue, 19 Mar 2024 17:59:19 +1000 Message-ID: <20240319075926.2422707-29-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , linux-s390@vger.kernel.org, =?utf-8?q?Nico_B=C3=B6hr?= , Janosch Frank , kvm@vger.kernel.org, David Hildenbrand , Nicholas Piggin , Andrew Jones , Paolo Bonzini , Claudio Imbrenda , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" There is no good reason to put setup_vm in libcflat.h when it's defined in vmalloc.h. Cc: Paolo Bonzini Cc: Thomas Huth Cc: Janosch Frank Cc: Claudio Imbrenda Cc: Nico Böhr Cc: David Hildenbrand Cc: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org Acked-by: Andrew Jones Signed-off-by: Nicholas Piggin --- common/sieve.c | 1 + lib/libcflat.h | 2 -- lib/s390x/io.c | 1 + lib/s390x/uv.h | 1 + lib/x86/vm.h | 1 + s390x/mvpg.c | 1 + s390x/selftest.c | 1 + x86/pmu.c | 1 + x86/pmu_lbr.c | 1 + x86/vmexit.c | 1 + x86/vmware_backdoors.c | 1 + 11 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/sieve.c b/common/sieve.c index 8150f2d98..8fe05ef13 100644 --- a/common/sieve.c +++ b/common/sieve.c @@ -1,5 +1,6 @@ #include "alloc.h" #include "libcflat.h" +#include "vmalloc.h" static int sieve(char* data, int size) { diff --git a/lib/libcflat.h b/lib/libcflat.h index 700f43527..8c8dd0286 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -152,8 +152,6 @@ do { \ void binstr(unsigned long x, char out[BINSTR_SZ]); void print_binstr(unsigned long x); -extern void setup_vm(void); - #endif /* !__ASSEMBLY__ */ #define SZ_256 (1 << 8) diff --git a/lib/s390x/io.c b/lib/s390x/io.c index fb7b7ddaa..2b28ccaa0 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -10,6 +10,7 @@ */ #include #include +#include #include #include #include diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h index 286933caa..00a370410 100644 --- a/lib/s390x/uv.h +++ b/lib/s390x/uv.h @@ -4,6 +4,7 @@ #include #include +#include bool uv_os_is_guest(void); bool uv_os_is_host(void); diff --git a/lib/x86/vm.h b/lib/x86/vm.h index 4b714bad7..cf39787aa 100644 --- a/lib/x86/vm.h +++ b/lib/x86/vm.h @@ -2,6 +2,7 @@ #define _X86_VM_H_ #include "processor.h" +#include "vmalloc.h" #include "asm/page.h" #include "asm/io.h" #include "asm/bitops.h" diff --git a/s390x/mvpg.c b/s390x/mvpg.c index 296338d4f..a0cfc575a 100644 --- a/s390x/mvpg.c +++ b/s390x/mvpg.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/s390x/selftest.c b/s390x/selftest.c index 92ed4e5d3..3eaae9b06 100644 --- a/s390x/selftest.c +++ b/s390x/selftest.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/x86/pmu.c b/x86/pmu.c index 47a1a602a..7062c1ad9 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -6,6 +6,7 @@ #include "x86/apic.h" #include "x86/desc.h" #include "x86/isr.h" +#include "vmalloc.h" #include "alloc.h" #include "libcflat.h" diff --git a/x86/pmu_lbr.c b/x86/pmu_lbr.c index 40b63fa3d..c6f010847 100644 --- a/x86/pmu_lbr.c +++ b/x86/pmu_lbr.c @@ -2,6 +2,7 @@ #include "x86/processor.h" #include "x86/pmu.h" #include "x86/desc.h" +#include "vmalloc.h" #define N 1000000 diff --git a/x86/vmexit.c b/x86/vmexit.c index eb5d3023a..48a38f60f 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -1,6 +1,7 @@ #include "libcflat.h" #include "acpi.h" #include "smp.h" +#include "vmalloc.h" #include "pci.h" #include "x86/vm.h" #include "x86/desc.h" diff --git a/x86/vmware_backdoors.c b/x86/vmware_backdoors.c index bc1002056..f8cf7ecb1 100644 --- a/x86/vmware_backdoors.c +++ b/x86/vmware_backdoors.c @@ -6,6 +6,7 @@ #include "x86/desc.h" #include "x86/isr.h" #include "alloc.h" +#include "vmalloc.h" #include "setjmp.h" #include "usermode.h" #include "fault_test.h" From patchwork Tue Mar 19 07:59:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=i+rjl5T1; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPnG3yjZz1yWs for ; Tue, 19 Mar 2024 19:21:06 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=i+rjl5T1; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPnG2ssNz3wG8 for ; Tue, 19 Mar 2024 19:21:06 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=i+rjl5T1; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c2d; helo=mail-oo1-xc2d.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) (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 4TzPLp2jmpz3vZd for ; Tue, 19 Mar 2024 19:01:38 +1100 (AEDT) Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5a47cecb98bso2294399eaf.0 for ; Tue, 19 Mar 2024 01:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835295; x=1711440095; darn=lists.ozlabs.org; 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=LpZgTnYuZKPgrO02ZjnJJrbhmA4KtBA17GzWdnvK/1M=; b=i+rjl5T1Ol5AJH4IFxwR6XMvXm9xPL0cr9zGZWXqgv1HAkoBEWy/IpT5nyJ03tHt3/ G2EPuA/KoK4SQiFVraznxp8VQ/37alvtV7t8Mi8jerPW6FiyybwX2k2xI/fG0pT/DWG9 8Alg7jShORqZlDuPvcwfOmt/Hm0VYOvMPvOiENYxdNjVptpamb9yJ3lOUCVZRx/YGORf lhXoc7XN6PT/IagWcVRlAUP7Zmzj/oLnxAg+bnHkm6jmfuiJDLDH744sKmksd+IE2WqB ruVWKMreSs863m05evWgUMT4vBxL1v8xwZ35UkWKt3+kJ2/LI8hrUTy7tUWOimnanv/l xADw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835295; x=1711440095; 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=LpZgTnYuZKPgrO02ZjnJJrbhmA4KtBA17GzWdnvK/1M=; b=rRuojp9iU4qpFv1t0r2di/KnaXot60yUtQHzcEiF6IpKyn5PSdJHMUKIP6ZB3Lhot1 2UK2j95EGbkjqvj0KUv/MQvxjRk8LWecNnR0H9Nube+ogaFNxmmMUchIbn8kdywcX0oy n2vN/6VO/AvolcCMlm26Dp0vFti+7woVWemCx9S6hZ9BrkOxOPZ40xMFDSzGyLazWtMp uGhFkHlECZZUgnFMCwIYs4LKz45Xb4JksKy2a7m7CkPHa25UZHFw99jzaHYlrC0IRCyp z7oxdG4it11slTqJunxMGcobM3hFKEMzj2grQq9B0p5foNqxK5wS5jSOdlUL7O0PpBv2 J4ug== X-Forwarded-Encrypted: i=1; AJvYcCVGPFxIJxN0g6AO9YTluhLM1maFMqsnInWHPTbOhPALhRRKsOFLZZg4MsEBeBcZvIU1IZanLXHvEgqqJjCi03XBQuSzqMellZdwsygfbg== X-Gm-Message-State: AOJu0YwCWYmtHocyG8LEDGVLHlPeCWW6T9dy2/Z4vABu1nRiwcM9hxui UCc6gcB+BEdGUZr54/pAAko/0mprWvxSkPAbYeUDJkrlIBsqOw171zjVXGZN3Tk= X-Google-Smtp-Source: AGHT+IERNdDPUTYaefvVXw56YB3Bqcd2KOnOd0Tcbbwlalm3iIbsADM2+wRouKxCGs7kkgkSLuGLrA== X-Received: by 2002:a05:6358:199d:b0:17e:6a4d:777 with SMTP id v29-20020a056358199d00b0017e6a4d0777mr1597844rwn.19.1710835294996; Tue, 19 Mar 2024 01:01:34 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:34 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 29/35] common/sieve: Support machines without MMU Date: Tue, 19 Mar 2024 17:59:20 +1000 Message-ID: <20240319075926.2422707-30-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Not all powerpc CPUs provide MMU support. Define vm_available() that is true by default but archs can override it. Use this to run VM tests. Cc: Paolo Bonzini Cc: Thomas Huth Cc: kvm@vger.kernel.org Reviewed-by: Andrew Jones Signed-off-by: Nicholas Piggin --- common/sieve.c | 14 ++++++++------ lib/ppc64/asm/mmu.h | 1 - lib/ppc64/mmu.c | 2 +- lib/vmalloc.c | 7 +++++++ lib/vmalloc.h | 2 ++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/common/sieve.c b/common/sieve.c index 8fe05ef13..db084691a 100644 --- a/common/sieve.c +++ b/common/sieve.c @@ -40,12 +40,14 @@ int main(void) printf("starting sieve\n"); test_sieve("static", static_data, STATIC_SIZE); - setup_vm(); - test_sieve("mapped", static_data, STATIC_SIZE); - for (i = 0; i < 3; ++i) { - v = malloc(VSIZE); - test_sieve("virtual", v, VSIZE); - free(v); + if (vm_available()) { + setup_vm(); + test_sieve("mapped", static_data, STATIC_SIZE); + for (i = 0; i < 3; ++i) { + v = malloc(VSIZE); + test_sieve("virtual", v, VSIZE); + free(v); + } } return 0; diff --git a/lib/ppc64/asm/mmu.h b/lib/ppc64/asm/mmu.h index fadeee4bc..eaff0f1f7 100644 --- a/lib/ppc64/asm/mmu.h +++ b/lib/ppc64/asm/mmu.h @@ -3,7 +3,6 @@ #include -bool vm_available(void); bool mmu_enabled(void); void mmu_enable(pgd_t *pgtable); void mmu_disable(void); diff --git a/lib/ppc64/mmu.c b/lib/ppc64/mmu.c index 7e445fdaf..ac9c0a285 100644 --- a/lib/ppc64/mmu.c +++ b/lib/ppc64/mmu.c @@ -23,7 +23,7 @@ static pgd_t *identity_pgd; -bool vm_available(void) +bool vm_available(void) /* weak override */ { return cpu_has_radix; } diff --git a/lib/vmalloc.c b/lib/vmalloc.c index 572682576..cf2ef7a70 100644 --- a/lib/vmalloc.c +++ b/lib/vmalloc.c @@ -206,10 +206,17 @@ void init_alloc_vpage(void *top) spin_unlock(&lock); } +bool __attribute__((__weak__)) vm_available(void) +{ + return true; +} + void __setup_vm(void *opaque) { phys_addr_t base, top; + assert_msg(vm_available(), "Virtual memory not available. Must check vm_available() before calling setup_vm()"); + if (alloc_ops == &vmalloc_ops) return; diff --git a/lib/vmalloc.h b/lib/vmalloc.h index 0269fdde9..e81be39f4 100644 --- a/lib/vmalloc.h +++ b/lib/vmalloc.h @@ -17,6 +17,8 @@ extern void setup_vm(void); /* As above, plus passes an opaque value to setup_mmu(). */ extern void __setup_vm(void *opaque); +/* common/ tests must check availability before calling setup_vm() */ +extern bool vm_available(void); /* Set up paging */ extern void *setup_mmu(phys_addr_t top, void *opaque); /* Walk the page table and resolve the virtual address to a physical address */ From patchwork Tue Mar 19 07:59:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UNREkCU/; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPp40PvJz1yWs for ; Tue, 19 Mar 2024 19:21:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UNREkCU/; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPp34NjKz3w18 for ; Tue, 19 Mar 2024 19:21:47 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=UNREkCU/; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c2b; helo=mail-oo1-xc2b.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) (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 4TzPLt1T5Kz3vfN for ; Tue, 19 Mar 2024 19:01:42 +1100 (AEDT) Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5a46ec4050eso2762360eaf.2 for ; Tue, 19 Mar 2024 01:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835299; x=1711440099; darn=lists.ozlabs.org; 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=DHV3i4Gba0d6WT/j4EZFJfZJO1H61IDlaezqmWnREy8=; b=UNREkCU/v70xrTUa8rIeh0n4wiDI5Itc6UanCFp2KOsohlaiKL7jsHKhJt/hLOZWEO NMnYFGIZKQBhreaafxtt6uo/MsTkPRjklIImMqDCr0mX8SnLKVYd41n91Jov1WD2CsxR 3RVwhoSnhd27SJxpwlVXXQ3GquPNFZtQWA+jZFRMB+YfwGtlo9nCRcuBHaIlRPC0s0Gn UkfGgvOoRrGGxXVE9AK55Q69PHOvp2PNuLE5tJyTvwnliwswbnEe4Fr8LKsZs0sXG+uj yY5Ee3HjEmxpDlGEkyiyCImZMXa7thgLFv0F9V6v4ubmSLE3WEHASOUs/1sgT9JwWVaK AJdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835299; x=1711440099; 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=DHV3i4Gba0d6WT/j4EZFJfZJO1H61IDlaezqmWnREy8=; b=DHRebIK5fq67/VTNhpnl6YzFxGkXe4ArVT4wN7CoKqLvSWn11hRNqhXXrb+YBdk5t5 7rmEsyek7L7mXyOpYF5FjPSNxpbd/18hR8hZMtzeSuzgPaQIfhTPtocVruyyzHBOQz5w jjSO9lf6RS2DnBNaD+paK/LR1UVgzusH73N3iXXTaccM0CCqEohXUYB+LOObfQgXlTPR Lr2hHXNUmpcNub9iz2C1GV53gwACwOvfqzTbFAFfw3kFBjaiJUnZRzjKYZltmB0/OwHL ZGJAuCRGGfhukP/C/I4L6VOvYqZZkGTayoEkkQBkLAUT8Sj5/gE6y5FPqMvzUCOrwi0i Vvsw== X-Forwarded-Encrypted: i=1; AJvYcCWthuh6lY1JGvl7lP7dURo6mmp4be31S8f3nohwuyGgSG3lEh+HeD+Ap7yzURJHi+L0+0kfSwDYuRm/vtm6VlKhkxBY2S7v9YFTx6wlMQ== X-Gm-Message-State: AOJu0Yxg7ijdLD8owWaNjZj1r3jB/nqOxW3Wx6IFW52B0uln5DwOh/eg AoMx1nzlLVMx5Fu2tc4QRduGp9V90a2Zw6/o+sinrL89CJwBtGcO X-Google-Smtp-Source: AGHT+IEXs0E8Qb6RA4bkQO4VYmb+dtVmkchk4sJqMglG8DUv1dLfuBOTpKPRWovT8+dXEQ7h57Mfvw== X-Received: by 2002:a05:6358:56a2:b0:17e:9ca7:c3a2 with SMTP id o34-20020a05635856a200b0017e9ca7c3a2mr12938120rwf.21.1710835299085; Tue, 19 Mar 2024 01:01:39 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:38 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 30/35] powerpc: Add sieve.c common test Date: Tue, 19 Mar 2024 17:59:21 +1000 Message-ID: <20240319075926.2422707-31-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Now that sieve copes with lack of MMU support, it can be run by powerpc. Signed-off-by: Nicholas Piggin --- powerpc/Makefile.common | 1 + powerpc/sieve.c | 1 + powerpc/unittests.cfg | 3 +++ 3 files changed, 5 insertions(+) create mode 120000 powerpc/sieve.c diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 5871da47a..410a675d9 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -8,6 +8,7 @@ tests-common = \ $(TEST_DIR)/selftest.elf \ $(TEST_DIR)/selftest-migration.elf \ $(TEST_DIR)/memory-verify.elf \ + $(TEST_DIR)/sieve.elf \ $(TEST_DIR)/spapr_hcall.elf \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ diff --git a/powerpc/sieve.c b/powerpc/sieve.c new file mode 120000 index 000000000..fe299f309 --- /dev/null +++ b/powerpc/sieve.c @@ -0,0 +1 @@ +../common/sieve.c \ No newline at end of file diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 0be787f67..351da46a6 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -121,3 +121,6 @@ file = sprs.elf machine = pseries extra_params = -append '-w' groups = migration + +[sieve] +file = sieve.elf From patchwork Tue Mar 19 07:59:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IQCuiW7k; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPps0BlTz1yWs for ; Tue, 19 Mar 2024 19:22:29 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IQCuiW7k; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPpr6Fflz3w1f for ; Tue, 19 Mar 2024 19:22:28 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=IQCuiW7k; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c30; helo=mail-oo1-xc30.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) (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 4TzPLx61Sqz3vfb for ; Tue, 19 Mar 2024 19:01:45 +1100 (AEDT) Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5a47abe2ff7so2046510eaf.0 for ; Tue, 19 Mar 2024 01:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835303; x=1711440103; darn=lists.ozlabs.org; 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=4V9DMm5uSUsFZwShNvLzFyDowiDRUN/JREmEJLYYvh4=; b=IQCuiW7kON66KRvf+L0vvsEiWHcnjCyzTUagfgb/I3lEyXp2CHkk8JrEGBsBhQ7kUm 4x3umogBv+Hse5UyvqzWEw2a4XqtXf/YT8x5H2bAC0CMEAkVnDVgCGPHvcoGV672wMMm 6X4+8RSlWz80fdPT6KmmbxPjgJA1YTlI3jXxlz80M+DMqhRRMawmj1JsBhWVHvC6BnFK uHeXoey9JpPWBJpavYYNhTB4hqDVqg3rjJMrGjkxkA891gy7ROFRsWUpCeqHj5nzh9Ei qzR2I+qxgQFRoQAnVS06bdlLfzXR69oR2OezqU3NsqcIA1sm0dfzwbHF/i1pXMcM99qS V8dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835303; x=1711440103; 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=4V9DMm5uSUsFZwShNvLzFyDowiDRUN/JREmEJLYYvh4=; b=JTo3i0jnmLCf9GgFTbfok/OimlngazVseTH53VxkFVNNzlIKqEj6uCdvD4Lg4X5avZ BzeBBmZOibDvOsP7DWFpBwlwtpfiHUxJ1FSU2JPOSE+qs0+uKeC5e5UwpLiQW4kFqDwe 0nO1BruA/+BTqulYHxFCC24Jp22T1O89EFa884IQkeU8ih20HfnaTHzfT39LN5gDE6zT lPpnkhMTlBCJs3kd0Fgo9U1bblsGDI/rhTaY7dtBANoJGQyj8RGcdOggu0sdsjGpGYGQ I+UElnWySjosIqAGj0TzyVJYAYT0Fkc6sgfUUONwiYyURf5ObzvUK5rXgsZRinSQQjJb Im4A== X-Forwarded-Encrypted: i=1; AJvYcCXwdpIzJsAftVSPI/PxUdCG9QMSse3/U+svmkFCZbIerJVD6ggbhVDUxKyPhc+1UUehVbVNQ2WzqFKMxu5nn7+Jnvf/q/n48Be8cbls+A== X-Gm-Message-State: AOJu0YzuJn26tn4Gdi1WUA1G2o49lgLXadqvDu5wHkjM5cry9+DaggAH JKRFdDOJm4hR4RfRiM44aU1ZgFSyKnyZGyCEqgNUOEUgoIv9p6kPM80fdpeQeEY= X-Google-Smtp-Source: AGHT+IEt+NscoRi6n00XI5VhxDOMyWtBlUHhlXL3LXHFPBG6XVtQ3ppVYZJ8b1XdLMEXBihI+PjOIQ== X-Received: by 2002:a05:6358:64a0:b0:176:99f3:8d11 with SMTP id g32-20020a05635864a000b0017699f38d11mr8312869rwh.32.1710835302950; Tue, 19 Mar 2024 01:01:42 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:42 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 31/35] powerpc: add usermode support Date: Tue, 19 Mar 2024 17:59:22 +1000 Message-ID: <20240319075926.2422707-32-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The biggest difficulty for user mode is MMU support. Otherwise it is a simple matter of setting and clearing MSR[PR] with rfid and sc respectively. Some common harness operations will fail in usermode, so some workarounds are reqiured (e.g., puts() can't be used directly). A usermode privileged instruction interrupt test is added. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 9 +++++++++ lib/powerpc/asm/reg.h | 1 + lib/powerpc/asm/smp.h | 1 + lib/powerpc/io.c | 7 +++++++ lib/powerpc/processor.c | 38 +++++++++++++++++++++++++++++++++++++ lib/powerpc/rtas.c | 3 +++ lib/powerpc/setup.c | 8 ++++++-- lib/powerpc/spinlock.c | 4 ++++ lib/ppc64/mmu.c | 2 ++ powerpc/interrupts.c | 28 +++++++++++++++++++++++++++ 10 files changed, 99 insertions(+), 2 deletions(-) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index d348239c5..749155696 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -19,6 +19,8 @@ extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; extern bool cpu_has_pause_short; +bool in_usermode(void); + static inline uint64_t mfspr(int nr) { uint64_t ret; @@ -51,6 +53,8 @@ static inline void local_irq_enable(void) { unsigned long msr; + assert(!in_usermode()); + asm volatile( " mfmsr %0 \n \ ori %0,%0,%1 \n \ @@ -62,6 +66,8 @@ static inline void local_irq_disable(void) { unsigned long msr; + assert(!in_usermode()); + asm volatile( " mfmsr %0 \n \ andc %0,%0,%1 \n \ @@ -90,4 +96,7 @@ static inline bool machine_is_pseries(void) void enable_mcheck(void); void disable_mcheck(void); +void enter_usermode(void); +void exit_usermode(void); + #endif /* _ASMPOWERPC_PROCESSOR_H_ */ diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index b2fab4313..69ef21adb 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -58,5 +58,6 @@ #define MSR_SE UL(0x0400) /* Single Step Enable */ #define MSR_EE UL(0x8000) #define MSR_ME UL(0x1000) +#define MSR_PR UL(0x4000) #endif diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index 820c05e9e..b96a55903 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -11,6 +11,7 @@ struct cpu { unsigned long server_no; unsigned long stack; unsigned long exception_stack; + bool in_user; secondary_entry_fn entry; pgd_t *pgtable; } __attribute__((packed)); /* used by asm */ diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c index cb7f2f050..5c2810884 100644 --- a/lib/powerpc/io.c +++ b/lib/powerpc/io.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "io.h" static struct spinlock print_lock; @@ -41,10 +42,16 @@ void io_init(void) void puts(const char *s) { + bool user = in_usermode(); + + if (user) + exit_usermode(); spin_lock(&print_lock); while (*s) putchar(*s++); spin_unlock(&print_lock); + if (user) + enter_usermode(); } /* diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index 09f6bb9d8..6c3000d5c 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -47,6 +47,8 @@ void do_handle_exception(struct pt_regs *regs) unsigned char v; __current_cpu = (struct cpu *)mfspr(SPR_SPRG0); + if (in_usermode()) + current_cpu()->in_user = false; /* * We run with AIL=0, so interrupts taken with MMU disabled. @@ -60,6 +62,8 @@ void do_handle_exception(struct pt_regs *regs) if (v < 128 && handlers[v].func) { handlers[v].func(regs, handlers[v].data); + if (regs->msr & MSR_PR) + current_cpu()->in_user = true; return; } @@ -169,3 +173,37 @@ void disable_mcheck(void) { rfid_msr(mfmsr() & ~MSR_ME); } + +bool in_usermode(void) +{ + return current_cpu()->in_user; +} + +static void usermode_sc_handler(struct pt_regs *regs, void *data) +{ + regs->msr &= ~(MSR_PR|MSR_EE); + /* Interrupt return handler will keep in_user clear */ +} + +void enter_usermode(void) +{ + assert_msg(!in_usermode(), "enter_usermode called with in_usermode"); + /* mfmsr would fault in usermode anyway */ + assert_msg(!(mfmsr() & MSR_PR), "enter_usermode called from user mode"); + assert_msg(!(mfmsr() & MSR_EE), "enter_usermode called with interrupts enabled"); + assert_msg((mfmsr() & (MSR_IR|MSR_DR)) == (MSR_IR|MSR_DR), + "enter_usermode called with virtual memory disabled"); + + handle_exception(0xc00, usermode_sc_handler, NULL); + rfid_msr(mfmsr() | (MSR_PR|MSR_IR|MSR_DR|MSR_EE)); + current_cpu()->in_user = true; +} + +void exit_usermode(void) +{ + assert_msg(in_usermode(), "enter_usermode called with !in_usermode"); + asm volatile("sc 0" ::: "memory"); + handle_exception(0xc00, NULL, NULL); + assert(!in_usermode()); + assert(!(mfmsr() & MSR_PR)); +} diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c index b477a38e0..9c1e0affc 100644 --- a/lib/powerpc/rtas.c +++ b/lib/powerpc/rtas.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -137,6 +138,8 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) va_list list; int ret; + assert_msg(!in_usermode(), "May not make RTAS call from user mode\n"); + spin_lock(&rtas_lock); va_start(list, outputs); diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index ba659cc2b..30b988a5c 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -201,8 +201,11 @@ void cpu_init(struct cpu *cpu, int cpu_id) cpu->exception_stack = (unsigned long)memalign(SZ_4K, SZ_64K); cpu->exception_stack += SZ_64K - 64; cpu->pgtable = NULL; + cpu->in_user = false; } +bool is_hvmode; + void setup(const void *fdt) { void *freemem = &stacktop; @@ -211,8 +214,6 @@ void setup(const void *fdt) u32 fdt_size; int ret; - cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); - memset(cpus, 0xff, sizeof(cpus)); cpu = &cpus[0]; @@ -220,10 +221,13 @@ void setup(const void *fdt) cpu->exception_stack = (unsigned long)boot_exception_stack; cpu->exception_stack += SZ_64K - 64; cpu->pgtable = NULL; + cpu->in_user = false; mtspr(SPR_SPRG0, (unsigned long)cpu); __current_cpu = cpu; + cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); + enable_mcheck(); /* diff --git a/lib/powerpc/spinlock.c b/lib/powerpc/spinlock.c index 623a1f2c1..2c4904a33 100644 --- a/lib/powerpc/spinlock.c +++ b/lib/powerpc/spinlock.c @@ -9,6 +9,8 @@ */ void spin_lock(struct spinlock *lock) { + assert(!in_usermode()); + if (!multithreaded) { assert(lock->v == 0); lock->v = 1; @@ -20,7 +22,9 @@ void spin_lock(struct spinlock *lock) void spin_unlock(struct spinlock *lock) { + assert(!in_usermode()); assert(lock->v == 1); + if (!multithreaded) { lock->v = 0; } else { diff --git a/lib/ppc64/mmu.c b/lib/ppc64/mmu.c index ac9c0a285..4129f726c 100644 --- a/lib/ppc64/mmu.c +++ b/lib/ppc64/mmu.c @@ -42,6 +42,7 @@ void mmu_enable(pgd_t *pgtable) cpu->pgtable = pgtable; + assert(!in_usermode()); mtmsr(mfmsr() | (MSR_IR|MSR_DR)); } @@ -51,6 +52,7 @@ void mmu_disable(void) cpu->pgtable = NULL; + assert(!in_usermode()); mtmsr(mfmsr() & ~(MSR_IR|MSR_DR)); } diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c index 6bed26e41..ba965ff76 100644 --- a/powerpc/interrupts.c +++ b/powerpc/interrupts.c @@ -326,6 +326,33 @@ static void test_illegal(void) report_prefix_pop(); } +static void dec_ignore_handler(struct pt_regs *regs, void *data) +{ + mtspr(SPR_DEC, 0x7fffffff); +} + +static void test_privileged(void) +{ + unsigned long msr; + + if (!mmu_enabled()) + return; + + report_prefix_push("privileged instruction"); + + handle_exception(0x700, &program_handler, NULL); + handle_exception(0x900, &dec_ignore_handler, NULL); + enter_usermode(); + asm volatile("mfmsr %0" : "=r"(msr) :: "memory"); + exit_usermode(); + report(got_interrupt, "interrupt on privileged instruction"); + got_interrupt = false; + handle_exception(0x900, NULL, NULL); + handle_exception(0x700, NULL, NULL); + + report_prefix_pop(); +} + static void sc_handler(struct pt_regs *regs, void *data) { got_interrupt = true; @@ -478,6 +505,7 @@ int main(int argc, char **argv) test_mce(); test_mmu(); test_illegal(); + test_privileged(); test_dec(); test_sc(); test_trace(); From patchwork Tue Mar 19 07:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=l1Guxon7; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPqn4zfTz1yWs for ; Tue, 19 Mar 2024 19:23:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=l1Guxon7; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPqn0QMgz3wL8 for ; Tue, 19 Mar 2024 19:23:17 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=l1Guxon7; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 4TzPM10QFBz3vfn for ; Tue, 19 Mar 2024 19:01:48 +1100 (AEDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6e6b729669bso4772709b3a.3 for ; Tue, 19 Mar 2024 01:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835307; x=1711440107; darn=lists.ozlabs.org; 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=PmZN7Ir1LEfEzs9Fyf2uW6pBrgvIJMn8Ymcola25hXQ=; b=l1Guxon7B7ZTefihc8xNHsiciqTPy1dWxh04yBCfGZ/yZ6Nv+xpY7D+GvG0JwFh88w ZXP22fsEFDcF0jfv54VsKwYQ2x8clUwTnlToLkRcUma4Exj7whOIUC+0WO/UDR9EfUFv BjeWSxP/wLyKSpxoOAAxPFJc7Sn2SMqENOHVlM0YZgOuebayDg8eXKIE3Pvb/QOSfuwm Y8HonSAaCf1YWJ0kVkgjbcxEfKng1Lk6ayQzOWOjE7Ru2AuGuqc1lHHvGpW1KzfE6G0R 790dXz9VF1Hjmg6+00lRFuFbv3LWdAFG+g/hzb//8xpyoYWTPD84ZhcL0VP+PxoKLEpf Ybvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835307; x=1711440107; 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=PmZN7Ir1LEfEzs9Fyf2uW6pBrgvIJMn8Ymcola25hXQ=; b=YB/G4O+eOTbZ10DoYUdo9gz7Hsk3TDDVO1YioXOX7HQoXdC5e3oCtrl69EVSuaUm6n zg0lZ66PES5M9eYc0giH2dyXFSpyGbwi6JrdT4I8zgvtSW86FEanrIRT9fKz6BkxXG6+ uDowghQxgh5WKGpjmsUHnnZO7nZg0r5oAHmCmYxmL2ciqoLOBpiCWWaQi0D9WLP0HS7d NjzWO1YOJGb3gW3uAvIIN7fKddRqJTpfY1lEdLesHbkXIFNHB0o1uA/nvEetwNfcYyT2 KtU/Ze4VMpf2rdTPbiquPDJcjgBiVexC1pFSv23JGRiQEJ9MX4P5VjKWBWTGza0CSulU q+Ug== X-Forwarded-Encrypted: i=1; AJvYcCVYmKEfd05kCz0FCVzLDK6bB8RIMEiyfXAsMXawMA4E8MGT5AlQWeLNZoE5keYsE8hI2y7/xRFkeiZB6tOVASPOu/+NDKwAVi1rziZb9w== X-Gm-Message-State: AOJu0YzCfxxTdSkundLoM7X787AspC5ayd9tD5GWLnbtBenffBNWwvj1 9Pw/yGBfGcwMvsw7AttDUoZ7gKiASP2cX3qOrdpQY18Vl9rEmQORYXgH1Z5/0H0= X-Google-Smtp-Source: AGHT+IHLJ2eezryS8JMXqRnrz5Pjx1Siaj39ZzgzWxzYFlDKNofq2rNeAj1Xq+PRll0GUhZr7hiMSg== X-Received: by 2002:a05:6a00:1482:b0:6e7:2379:dd18 with SMTP id v2-20020a056a00148200b006e72379dd18mr2403162pfu.0.1710835307131; Tue, 19 Mar 2024 01:01:47 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:46 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 32/35] powerpc: add pmu tests Date: Tue, 19 Mar 2024 17:59:23 +1000 Message-ID: <20240319075926.2422707-33-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add some initial PMU testing. - PMC5/6 tests - PMAE / PMI test - BHRB basic tests Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 2 + lib/powerpc/asm/reg.h | 9 + lib/powerpc/asm/setup.h | 1 + lib/powerpc/setup.c | 23 +++ powerpc/Makefile.common | 3 +- powerpc/pmu.c | 336 ++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 3 + 7 files changed, 376 insertions(+), 1 deletion(-) create mode 100644 powerpc/pmu.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index 749155696..28239c610 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -14,6 +14,8 @@ extern bool cpu_has_hv; extern bool cpu_has_power_mce; extern bool cpu_has_siar; extern bool cpu_has_heai; +extern bool cpu_has_bhrb; +extern bool cpu_has_p10_bhrb; extern bool cpu_has_radix; extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 69ef21adb..602fba1b6 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -40,10 +40,19 @@ #define SPR_LPIDR 0x13f #define SPR_HEIR 0x153 #define SPR_PTCR 0x1d0 +#define SPR_MMCRA 0x312 +#define MMCRA_BHRBRD UL(0x0000002000000000) +#define MMCRA_IFM_MASK UL(0x00000000c0000000) +#define SPR_PMC5 0x317 +#define SPR_PMC6 0x318 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) +#define MMCR0_FCP UL(0x20000000) #define MMCR0_PMAE UL(0x04000000) +#define MMCR0_BHRBA UL(0x00200000) +#define MMCR0_FCPC UL(0x00001000) #define MMCR0_PMAO UL(0x00000080) +#define MMCR0_FC56 UL(0x00000010) #define SPR_SIAR 0x31c /* Machine State Register definitions: */ diff --git a/lib/powerpc/asm/setup.h b/lib/powerpc/asm/setup.h index 9ca318ce6..8f0b58ed0 100644 --- a/lib/powerpc/asm/setup.h +++ b/lib/powerpc/asm/setup.h @@ -10,6 +10,7 @@ #define NR_CPUS 8 /* arbitrarily set for now */ extern uint64_t tb_hz; +extern uint64_t cpu_hz; #define NR_MEM_REGIONS 8 #define MR_F_PRIMARY (1U << 0) diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 30b988a5c..42ba06ad1 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -32,6 +32,7 @@ u32 initrd_size; u32 cpu_to_hwid[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) }; int nr_cpus_present; uint64_t tb_hz; +uint64_t cpu_hz; struct mem_region mem_regions[NR_MEM_REGIONS]; phys_addr_t __physical_start, __physical_end; @@ -41,6 +42,7 @@ struct cpu_set_params { unsigned icache_bytes; unsigned dcache_bytes; uint64_t tb_hz; + uint64_t cpu_hz; }; static void cpu_set(int fdtnode, u64 regval, void *info) @@ -94,6 +96,22 @@ static void cpu_set(int fdtnode, u64 regval, void *info) data = (u32 *)prop->data; params->tb_hz = fdt32_to_cpu(*data); + prop = fdt_get_property(dt_fdt(), fdtnode, + "ibm,extended-clock-frequency", NULL); + if (prop) { + data = (u32 *)prop->data; + params->cpu_hz = fdt32_to_cpu(*data); + params->cpu_hz <<= 32; + data = (u32 *)prop->data + 1; + params->cpu_hz |= fdt32_to_cpu(*data); + } else { + prop = fdt_get_property(dt_fdt(), fdtnode, + "clock-frequency", NULL); + assert(prop != NULL); + data = (u32 *)prop->data; + params->cpu_hz = fdt32_to_cpu(*data); + } + read_common_info = true; } } @@ -102,6 +120,8 @@ bool cpu_has_hv; bool cpu_has_power_mce; /* POWER CPU machine checks */ bool cpu_has_siar; bool cpu_has_heai; +bool cpu_has_bhrb; +bool cpu_has_p10_bhrb; bool cpu_has_radix; bool cpu_has_prefix; bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ @@ -118,12 +138,14 @@ static void cpu_init_params(void) __icache_bytes = params.icache_bytes; __dcache_bytes = params.dcache_bytes; tb_hz = params.tb_hz; + cpu_hz = params.cpu_hz; switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_POWER10: cpu_has_prefix = true; cpu_has_sc_lev = true; cpu_has_pause_short = true; + cpu_has_p10_bhrb = true; case PVR_VER_POWER9: cpu_has_radix = true; case PVR_VER_POWER8E: @@ -132,6 +154,7 @@ static void cpu_init_params(void) cpu_has_power_mce = true; cpu_has_heai = true; cpu_has_siar = true; + cpu_has_bhrb = true; break; default: break; diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 410a675d9..64a3d93e4 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -17,7 +17,8 @@ tests-common = \ $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ $(TEST_DIR)/timebase.elf \ - $(TEST_DIR)/interrupts.elf + $(TEST_DIR)/interrupts.elf \ + $(TEST_DIR)/pmu.elf tests-all = $(tests-common) $(tests) all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) diff --git a/powerpc/pmu.c b/powerpc/pmu.c new file mode 100644 index 000000000..484155b1d --- /dev/null +++ b/powerpc/pmu.c @@ -0,0 +1,336 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test PMU + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "alloc_phys.h" +#include "vmalloc.h" + +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; +static volatile unsigned long recorded_mmcr0; + +static void reset_mmcr0(void) +{ + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_PMAE | MMCR0_PMAO)); +} + +static __attribute__((__noinline__)) unsigned long pmc5_count_nr_insns(unsigned long nr) +{ + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile("mtctr %0 ; 1: bdnz 1b" :: "r"(nr) : "ctr"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + + return mfspr(SPR_PMC5); +} + +static void test_pmc56(void) +{ + unsigned long tmp; + + report_prefix_push("pmc56"); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_PMC6, 0); + report(mfspr(SPR_PMC5) == 0, "PMC5 zeroed"); + report(mfspr(SPR_PMC6) == 0, "PMC6 zeroed"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_FC); + msleep(100); + report(mfspr(SPR_PMC5) == 0, "PMC5 frozen"); + report(mfspr(SPR_PMC6) == 0, "PMC6 frozen"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_FC56); + mdelay(100); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + report(mfspr(SPR_PMC5) != 0, "PMC5 counting"); + report(mfspr(SPR_PMC6) != 0, "PMC6 counting"); + + /* Dynamic frequency scaling could cause to be out, so don't fail. */ + tmp = mfspr(SPR_PMC6); + report(true, "PMC6 ratio to reported clock frequency is %ld%%", tmp * 1000 / cpu_hz); + + tmp = pmc5_count_nr_insns(100); + tmp = pmc5_count_nr_insns(1000) - tmp; + report(tmp == 900, "PMC5 counts instructions precisely"); + + report_prefix_pop(); +} + +static void dec_ignore_handler(struct pt_regs *regs, void *data) +{ + mtspr(SPR_DEC, 0x7fffffff); +} + +static void pmi_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + recorded_mmcr0 = mfspr(SPR_MMCR0); + if (mfspr(SPR_MMCR0) & MMCR0_PMAO) { + /* This may cause infinite interrupts, so clear it. */ + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAO); + } +} + +static void test_pmi(void) +{ + report_prefix_push("pmi"); + handle_exception(0x900, &dec_ignore_handler, NULL); + handle_exception(0xf00, &pmi_handler, NULL); + reset_mmcr0(); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_PMAO); + mtmsr(mfmsr() | MSR_EE); + mtmsr(mfmsr() & ~MSR_EE); + report(got_interrupt, "PMAO caused interrupt"); + handle_exception(0xf00, NULL, NULL); + handle_exception(0x900, NULL, NULL); + report_prefix_pop(); +} + +static void clrbhrb(void) +{ + asm volatile("clrbhrb" ::: "memory"); +} + +static inline unsigned long mfbhrbe(int nr) +{ + unsigned long e; + + asm volatile("mfbhrbe %0,%1" : "=r"(e) : "i"(nr) : "memory"); + + return e; +} + +extern unsigned char dummy_branch_1[]; +extern unsigned char dummy_branch_2[]; + +static __attribute__((__noinline__)) void bhrb_dummy(int i) +{ + asm volatile( + " cmpdi %0,1 \n\t" + " beq 1f \n\t" + ".global dummy_branch_1 \n\t" + "dummy_branch_1: \n\t" + " b 2f \n\t" + "1: trap \n\t" + ".global dummy_branch_2 \n\t" + "dummy_branch_2: \n\t" + "2: bne 3f \n\t" + " trap \n\t" + "3: nop \n\t" + : : "r"(i)); +} + +#define NR_BHRBE 16 +static unsigned long bhrbe[NR_BHRBE]; +static int nr_bhrbe; + +static void run_and_load_bhrb(void) +{ + int i; + + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAE); + clrbhrb(); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_BHRBA); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FCP | MMCR0_FCPC)); + mtspr(SPR_MMCRA, mfspr(SPR_MMCRA) & ~(MMCRA_BHRBRD | MMCRA_IFM_MASK)); + + if (cpu_has_p10_bhrb) { + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + enter_usermode(); + bhrb_dummy(0); + exit_usermode(); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + } else { + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + mtmsr(mfmsr()); + asm volatile(".rept 100 ; nop ; .endr"); + bhrb_dummy(0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + } + + bhrbe[0] = mfbhrbe(0); + bhrbe[1] = mfbhrbe(1); + bhrbe[2] = mfbhrbe(2); + bhrbe[3] = mfbhrbe(3); + bhrbe[4] = mfbhrbe(4); + bhrbe[5] = mfbhrbe(5); + bhrbe[6] = mfbhrbe(6); + bhrbe[7] = mfbhrbe(7); + bhrbe[8] = mfbhrbe(8); + bhrbe[9] = mfbhrbe(9); + bhrbe[10] = mfbhrbe(10); + bhrbe[11] = mfbhrbe(11); + bhrbe[12] = mfbhrbe(12); + bhrbe[13] = mfbhrbe(13); + bhrbe[14] = mfbhrbe(14); + bhrbe[15] = mfbhrbe(15); + + for (i = 0; i < NR_BHRBE; i++) { + bhrbe[i] &= ~0x1UL; /* remove prediction bit */ + if (!bhrbe[i]) + break; + } + nr_bhrbe = i; +} + +static void illegal_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + regs_advance_insn(regs); +} + +static void test_bhrb(void) +{ + int i; + + if (cpu_has_p10_bhrb && !vm_available()) + return; + + report_prefix_push("bhrb"); + + /* TCG doesn't impelment BHRB yet */ + handle_exception(0x700, &illegal_handler, NULL); + handle_exception(0xe40, &illegal_handler, NULL); + clrbhrb(); + handle_exception(0x700, NULL, NULL); + handle_exception(0xe40, NULL, NULL); + if (got_interrupt) { + got_interrupt = false; + report_skip("BHRB support missing"); + report_prefix_pop(); + return; + } + + handle_exception(0x900, &illegal_handler, NULL); + + if (vm_available()) { + handle_exception(0x900, &dec_ignore_handler, NULL); + setup_vm(); + } + reset_mmcr0(); + clrbhrb(); + if (cpu_has_p10_bhrb) { + enter_usermode(); + bhrb_dummy(0); + exit_usermode(); + } else { + bhrb_dummy(0); + } + report(mfbhrbe(0) == 0, "BHRB is frozen"); + + /* + * BHRB may be cleared at any time (e.g., by OS or hypervisor) + * so this test could be occasionally incorrect. Try several + * times before giving up... + */ + + if (cpu_has_p10_bhrb) { + /* + * BHRB should have 8 entries: + * 1. enter_usermode blr + * 2. enter_usermode blr target + * 3. bl dummy + * 4. dummy unconditional + * 5. dummy conditional + * 6. dummy blr + * 7. dummy blr target + * 8. exit_usermode bl + * + * POWER10 often gives 4 entries, if other threads are + * running on the core, it seems to struggle. + */ + for (i = 0; i < 200; i++) { + run_and_load_bhrb(); + if (nr_bhrbe == 8) + break; + if (i > 100 && nr_bhrbe == 4) + break; + } + if (nr_bhrbe != 8) + printf("nr_bhrbe=%d\n", nr_bhrbe); + report(nr_bhrbe, "BHRB has been written"); + if (nr_bhrbe == 8) { + report(nr_bhrbe == 8, "BHRB has written 8 entries"); + report(bhrbe[4] == (unsigned long)dummy_branch_1, + "correct unconditional branch address"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } else if (nr_bhrbe == 4) { + /* POWER10 workaround */ + report(nr_bhrbe == 4, "BHRB has written 4 entries"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } + } else { + /* + * BHRB should have 6 entries: + * 1. bl dummy + * 2. dummy unconditional + * 3. dummy conditional + * 4. dummy blr + * 5. dummy blr target + * 6. Final b loop before disabled. + * + * POWER9 often gives 4 entries, if other threads are + * running on the core, it seems to struggle. + */ + for (i = 0; i < 200; i++) { + run_and_load_bhrb(); + if (nr_bhrbe == 6) + break; + if (i > 100 && nr_bhrbe == 4) + break; + } + report(nr_bhrbe, "BHRB has been written"); + report(nr_bhrbe == 6, "BHRB has written 6 entries"); + if (nr_bhrbe == 6) { + report(bhrbe[4] == (unsigned long)dummy_branch_1, + "correct unconditional branch address"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } else if (nr_bhrbe == 4) { + /* POWER9 workaround */ + report(nr_bhrbe == 4, "BHRB has written 4 entries"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } + } + + handle_exception(0x900, NULL, NULL); + + report_prefix_pop(); +} + +int main(int argc, char **argv) +{ + report_prefix_push("pmu"); + + test_pmc56(); + test_pmi(); + if (cpu_has_bhrb) + test_bhrb(); + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 351da46a6..379aa166b 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -74,6 +74,9 @@ file = emulator.elf [interrupts] file = interrupts.elf +[pmu] +file = pmu.elf + [smp] file = smp.elf smp = 2 From patchwork Tue Mar 19 07:59:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=PNhUYA8X; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPrZ0c3rz1yWs for ; Tue, 19 Mar 2024 19:23:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=PNhUYA8X; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPrY6jPpz779v for ; Tue, 19 Mar 2024 19:23:57 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=PNhUYA8X; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::329; helo=mail-ot1-x329.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (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 4TzPM94LVXz3vgG for ; Tue, 19 Mar 2024 19:01:57 +1100 (AEDT) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6e6888358dfso997958a34.2 for ; Tue, 19 Mar 2024 01:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835314; x=1711440114; darn=lists.ozlabs.org; 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=lYCFo5qndkhUTKD0ju2V6NpbPZWgrF0rvNKi9F72sCM=; b=PNhUYA8XMAoMA8FLKRfZTtSwEi1IEzl7Sn/a4wKdUCEWTK9tryhP8RfqBN38lkZ9KH kR/WqxAgxL2TeKZBPrO5Fx4pDva7WlAz2okT1E1lIcP1KBVP/sZW0PbMhAPh3X3slv1Y 8o4Ic5UJ4AUh54r+M6kDQkmRl1eoqZYWQnsKlf0vAUGwbPyWmA1zQ+rM9fhuNnC/diLU IabwMis2JCW5NH9SH9MA+rQGGS4vofH0L4BIlvdpcG5z9XBFHGroQvWRM+yKUkvmx+sA 50r42qmDD6L2dccFMssD+MfhHY+0toYAXFzEQSZHucTyMkvX1bQaM9yT3mysu3Re3yu1 TQOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835314; x=1711440114; 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=lYCFo5qndkhUTKD0ju2V6NpbPZWgrF0rvNKi9F72sCM=; b=NWbfeNZBnkPQjtbW6Xq8uXl+RDYaTXzSo8bArIdAYuyOM4b/WxRL9+BMbpoJ1D6SzS +kIFq7SPGQ7JaRy7mE7RYo7hVUT/vKP5IPfYzSkOMtmnU+4Id2hvKZMmoynQVFWqFaIQ dZ9u7L1AnYXwP536wR571hKGDvzBXqJZgul4ntTbFVhwbQXRdzkfOg219HpNt2mwK2QZ K0373S5g2KHNue1GDrD7c+bzNFXOdBNLsfUqNOAH2pQv+L7cb+DCdkd9abE1RB7utHIm cofhIVsCtpE0175SMexKSS8g2+PXAicw5ukmnqFu0SX52/5Zv+gpDjO50KZtRstEtWHm cXmg== X-Forwarded-Encrypted: i=1; AJvYcCU7EJ9GTAK3SurtLNUC/dJAcF8zonQXrGK9LMjdupGykqvlIWorSZRAUUYVzLvkHRSQvFpyF0jab/vp+ETv/w1H2MRX1Ug7JpSCySXQog== X-Gm-Message-State: AOJu0YxPc7qg52xQyoq68u3ZmMfZabASDlcN9trVNOUqhaIqnaLwfUK2 zuUVxceAKIokRp7qEtL7Df67wSA/yijoNrjf6GjzsNEkY0y1VaOm X-Google-Smtp-Source: AGHT+IF70kukuIUslOKRONbnfx6Q5qzHIC6G6YQbr4o/AriQpKZiTDdR6gDB2b8R+nXV1Kt8v8DJvA== X-Received: by 2002:a05:6870:e308:b0:220:932f:1a1e with SMTP id z8-20020a056870e30800b00220932f1a1emr17263158oad.12.1710835314432; Tue, 19 Mar 2024 01:01:54 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:53 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 33/35] configure: Make arch_libdir a first-class entity Date: Tue, 19 Mar 2024 17:59:24 +1000 Message-ID: <20240319075926.2422707-34-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , linux-s390@vger.kernel.org, =?utf-8?q?Nico_B=C3=B6hr?= , Janosch Frank , kvm@vger.kernel.org, David Hildenbrand , Alexandru Elisei , Nicholas Piggin , Andrew Jones , Eric Auger , kvm-riscv@lists.infradead.org, kvmarm@lists.linux.dev, Paolo Bonzini , Claudio Imbrenda , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" arch_libdir was brought in to improve the heuristic determination of the lib/ directory based on arch and testdir names, but it did not entirely clean that mess up. Remove the arch_libdir->arch->testdir heuristic and just require everybody sets arch_libdir correctly. Fail if the lib/arch or lib/arch/asm directories can not be found. Cc: Alexandru Elisei Cc: Claudio Imbrenda Cc: David Hildenbrand Cc: Eric Auger Cc: Janosch Frank Cc: Laurent Vivier Cc: Nico Böhr Cc: Paolo Bonzini Cc: Thomas Huth Cc: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org Cc: kvmarm@lists.linux.dev Cc: kvm-riscv@lists.infradead.org Cc: linuxppc-dev@lists.ozlabs.org Reviewed-by: Andrew Jones Signed-off-by: Nicholas Piggin --- Makefile | 2 +- configure | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4f35fffc6..4e0f54543 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ include config.mak VPATH = $(SRCDIR) libdirs-get = $(shell [ -d "lib/$(1)" ] && echo "lib/$(1) lib/$(1)/asm") -ARCH_LIBDIRS := $(call libdirs-get,$(ARCH_LIBDIR)) $(call libdirs-get,$(TEST_DIR)) +ARCH_LIBDIRS := $(call libdirs-get,$(ARCH_LIBDIR)) OBJDIRS := $(ARCH_LIBDIRS) DESTDIR := $(PREFIX)/share/kvm-unit-tests/ diff --git a/configure b/configure index e19ba6f0c..a1308db8e 100755 --- a/configure +++ b/configure @@ -216,7 +216,6 @@ fi arch_name=$arch [ "$arch" = "aarch64" ] && arch="arm64" [ "$arch_name" = "arm64" ] && arch_name="aarch64" -arch_libdir=$arch if [ "$arch" = "riscv" ]; then echo "riscv32 or riscv64 must be specified" @@ -286,8 +285,10 @@ fi if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then testdir=x86 + arch_libdir=x86 elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then testdir=arm + arch_libdir=$arch if [ "$target" = "qemu" ]; then arm_uart_early_addr=0x09000000 elif [ "$target" = "kvmtool" ]; then @@ -336,6 +337,7 @@ elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then fi elif [ "$arch" = "ppc64" ]; then testdir=powerpc + arch_libdir=ppc64 firmware="$testdir/boot_rom.bin" if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then echo "You must provide endianness (big or little)!" @@ -346,6 +348,7 @@ elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then arch_libdir=riscv elif [ "$arch" = "s390x" ]; then testdir=s390x + arch_libdir=s390x else echo "arch $arch is not supported!" arch= @@ -355,6 +358,10 @@ if [ ! -d "$srcdir/$testdir" ]; then echo "$srcdir/$testdir does not exist!" exit 1 fi +if [ ! -d "$srcdir/lib/$arch_libdir" ]; then + echo "$srcdir/lib/$arch_libdir does not exist!" + exit 1 +fi if [ "$efi" = "y" ] && [ -f "$srcdir/$testdir/efi/run" ]; then ln -fs "$srcdir/$testdir/efi/run" $testdir-run @@ -417,10 +424,11 @@ fi # link lib/asm for the architecture rm -f lib/asm asm="asm-generic" -if [ -d "$srcdir/lib/$arch/asm" ]; then - asm="$srcdir/lib/$arch/asm" -elif [ -d "$srcdir/lib/$testdir/asm" ]; then - asm="$srcdir/lib/$testdir/asm" +if [ -d "$srcdir/lib/$arch_libdir/asm" ]; then + asm="$srcdir/lib/$arch_libdir/asm" +else + echo "$srcdir/lib/$arch_libdir/asm does not exist" + exit 1 fi mkdir -p lib ln -sf "$asm" lib/asm From patchwork Tue Mar 19 07:59:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=M+qe49ug; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPsM51GFz1yWs for ; Tue, 19 Mar 2024 19:24:39 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=M+qe49ug; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPsM2b5mz77D5 for ; Tue, 19 Mar 2024 19:24:39 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=M+qe49ug; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::434; helo=mail-pf1-x434.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 4TzPMF4hr0z3vfG for ; Tue, 19 Mar 2024 19:02:01 +1100 (AEDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6e6b5aa0b52so4342819b3a.3 for ; Tue, 19 Mar 2024 01:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835319; x=1711440119; darn=lists.ozlabs.org; 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=J+/9bL5rkLRt+ywh8KxjJUBQahnHNuSgOqEY6sVhOgU=; b=M+qe49ugjkLUht53aC7NFG6HcdkHrqQbeIOdWebcB+mNDA12YXWuxmIP9Fuz9KkLW+ qB4U8SmjgdHQ0xLL2/1f19cf/Xkzv10FIPglCKlwPRbQLZrOPGByYl7liHm6SaPVCz6Z ELkIFXoz169V0rqKizlmFWlOOBGtKaEAz0xX/35RIXOVxUPrT7Gr+hfM/3B+JplH7eyN vhysofa87HE9Vvmh5RDFEEwssdvHcOUTFSVkspaeD02CSfrPP3SPSf6JyzV5iBQ2QaIR nrTMCouyuqpO+qN0N7AuygjRzjYCszPkVpA2l8NLkA88uOq5JGeSExymCG61qDswuENe zzjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835319; x=1711440119; 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=J+/9bL5rkLRt+ywh8KxjJUBQahnHNuSgOqEY6sVhOgU=; b=SfZtsJevVTe9vzPMWfEqo9DfIE0eh+WoB3wCACg6UGjjwuo67WY52BdXAGtQDtfnTp tQ5qEYRttLuk5d5SULl/AfeF0FVdkrYcEL1gkaPEkrFhO4poQGOw4Mv+teZrxXv8OqvT iWew6HF4i5EAWQVd0qlFoebk49edAYogPDHNLqfLCMoWaEbek8pJYW4ToMuCnVyBED5E XBR1P+E6cVFGKIU13cvMaSUuB2jz24aZ43vHvaymxwuK8v59bObrNyNOOn/RTiomiLuA TW8sWogHUB+vLjMAnSV0fWZ7NKUDB63qAD434EGaOX62MlN0pDvx8Su8SqUlrihrNlbA tLPA== X-Forwarded-Encrypted: i=1; AJvYcCW6HhtrCSg70Qhsfyfpem85X9vuo42dcZL8ewVE3YMqyop9i8smUdRMuxZ3/4eBIyYaETFLGWsWfOr7i2fObQWOfKe4mPVivvQlotWkCw== X-Gm-Message-State: AOJu0Yzotx6CQ7i741Z/GFidED7yUs4hRj0Wb+gnftrFWxS/7iXsahju g9LHrBLocWTFco4ibf9MVxBtD/99OhNPIIeYgCcvfyqUD/7d0C88 X-Google-Smtp-Source: AGHT+IFE6JpXVtvdmQCUC//cdTcrmiBimRnyFdmWR9zoLmfjmKjqOP9WpgzA3NddQp8U6BhbnG3F3A== X-Received: by 2002:a05:6a00:2309:b0:6e6:bb2b:882c with SMTP id h9-20020a056a00230900b006e6bb2b882cmr16437075pfh.13.1710835318793; Tue, 19 Mar 2024 01:01:58 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:01:58 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 34/35] powerpc: Remove remnants of ppc64 directory and build structure Date: Tue, 19 Mar 2024 17:59:25 +1000 Message-ID: <20240319075926.2422707-35-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This moves merges ppc64 directories and files into powerpc, and merges the 3 makefiles into one. The configure --arch=powerpc option is aliased to ppc64 for good measure. Signed-off-by: Nicholas Piggin --- MAINTAINERS | 1 - configure | 3 +- lib/{ppc64 => powerpc}/asm-offsets.c | 0 lib/{ppc64 => powerpc}/asm/asm-offsets.h | 0 lib/{ppc64 => powerpc}/asm/atomic.h | 0 lib/{ppc64 => powerpc}/asm/barrier.h | 4 +- lib/{ppc64 => powerpc}/asm/bitops.h | 4 +- lib/{ppc64 => powerpc}/asm/io.h | 4 +- lib/{ppc64 => powerpc}/asm/mmu.h | 0 lib/{ppc64 => powerpc}/asm/opal.h | 4 +- lib/{ppc64 => powerpc}/asm/page.h | 6 +- lib/{ppc64 => powerpc}/asm/pgtable-hwdef.h | 6 +- lib/{ppc64 => powerpc}/asm/pgtable.h | 2 +- lib/{ppc64 => powerpc}/asm/ptrace.h | 6 +- lib/{ppc64 => powerpc}/asm/spinlock.h | 6 +- lib/powerpc/asm/stack.h | 3 + lib/{ppc64 => powerpc}/asm/vpa.h | 0 lib/{ppc64 => powerpc}/mmu.c | 0 lib/{ppc64 => powerpc}/opal-calls.S | 0 lib/{ppc64 => powerpc}/opal.c | 0 lib/{ppc64 => powerpc}/stack.c | 0 lib/ppc64/.gitignore | 1 - lib/ppc64/asm/handlers.h | 1 - lib/ppc64/asm/hcall.h | 1 - lib/ppc64/asm/memory_areas.h | 6 -- lib/ppc64/asm/ppc_asm.h | 1 - lib/ppc64/asm/processor.h | 1 - lib/ppc64/asm/reg.h | 1 - lib/ppc64/asm/rtas.h | 1 - lib/ppc64/asm/setup.h | 1 - lib/ppc64/asm/smp.h | 1 - lib/ppc64/asm/stack.h | 11 -- powerpc/Makefile | 111 ++++++++++++++++++++- powerpc/Makefile.common | 95 ------------------ powerpc/Makefile.ppc64 | 31 ------ 35 files changed, 136 insertions(+), 176 deletions(-) rename lib/{ppc64 => powerpc}/asm-offsets.c (100%) rename lib/{ppc64 => powerpc}/asm/asm-offsets.h (100%) rename lib/{ppc64 => powerpc}/asm/atomic.h (100%) rename lib/{ppc64 => powerpc}/asm/barrier.h (83%) rename lib/{ppc64 => powerpc}/asm/bitops.h (69%) rename lib/{ppc64 => powerpc}/asm/io.h (50%) rename lib/{ppc64 => powerpc}/asm/mmu.h (100%) rename lib/{ppc64 => powerpc}/asm/opal.h (90%) rename lib/{ppc64 => powerpc}/asm/page.h (94%) rename lib/{ppc64 => powerpc}/asm/pgtable-hwdef.h (93%) rename lib/{ppc64 => powerpc}/asm/pgtable.h (99%) rename lib/{ppc64 => powerpc}/asm/ptrace.h (89%) rename lib/{ppc64 => powerpc}/asm/spinlock.h (54%) rename lib/{ppc64 => powerpc}/asm/vpa.h (100%) rename lib/{ppc64 => powerpc}/mmu.c (100%) rename lib/{ppc64 => powerpc}/opal-calls.S (100%) rename lib/{ppc64 => powerpc}/opal.c (100%) rename lib/{ppc64 => powerpc}/stack.c (100%) delete mode 100644 lib/ppc64/.gitignore delete mode 100644 lib/ppc64/asm/handlers.h delete mode 100644 lib/ppc64/asm/hcall.h delete mode 100644 lib/ppc64/asm/memory_areas.h delete mode 100644 lib/ppc64/asm/ppc_asm.h delete mode 100644 lib/ppc64/asm/processor.h delete mode 100644 lib/ppc64/asm/reg.h delete mode 100644 lib/ppc64/asm/rtas.h delete mode 100644 lib/ppc64/asm/setup.h delete mode 100644 lib/ppc64/asm/smp.h delete mode 100644 lib/ppc64/asm/stack.h delete mode 100644 powerpc/Makefile.common delete mode 100644 powerpc/Makefile.ppc64 diff --git a/MAINTAINERS b/MAINTAINERS index a2fa437da..1309863f2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -92,7 +92,6 @@ S: Maintained L: linuxppc-dev@lists.ozlabs.org F: powerpc/ F: lib/powerpc/ -F: lib/ppc64/ RISCV M: Andrew Jones diff --git a/configure b/configure index a1308db8e..8508396af 100755 --- a/configure +++ b/configure @@ -215,6 +215,7 @@ fi arch_name=$arch [ "$arch" = "aarch64" ] && arch="arm64" +[ "$arch" = "powerpc" ] && arch="ppc64" [ "$arch_name" = "arm64" ] && arch_name="aarch64" if [ "$arch" = "riscv" ]; then @@ -337,7 +338,7 @@ elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then fi elif [ "$arch" = "ppc64" ]; then testdir=powerpc - arch_libdir=ppc64 + arch_libdir=powerpc firmware="$testdir/boot_rom.bin" if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then echo "You must provide endianness (big or little)!" diff --git a/lib/ppc64/asm-offsets.c b/lib/powerpc/asm-offsets.c similarity index 100% rename from lib/ppc64/asm-offsets.c rename to lib/powerpc/asm-offsets.c diff --git a/lib/ppc64/asm/asm-offsets.h b/lib/powerpc/asm/asm-offsets.h similarity index 100% rename from lib/ppc64/asm/asm-offsets.h rename to lib/powerpc/asm/asm-offsets.h diff --git a/lib/ppc64/asm/atomic.h b/lib/powerpc/asm/atomic.h similarity index 100% rename from lib/ppc64/asm/atomic.h rename to lib/powerpc/asm/atomic.h diff --git a/lib/ppc64/asm/barrier.h b/lib/powerpc/asm/barrier.h similarity index 83% rename from lib/ppc64/asm/barrier.h rename to lib/powerpc/asm/barrier.h index 475434b6a..22349d691 100644 --- a/lib/ppc64/asm/barrier.h +++ b/lib/powerpc/asm/barrier.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_BARRIER_H_ -#define _ASMPPC64_BARRIER_H_ +#ifndef _ASMPOWERPC_BARRIER_H_ +#define _ASMPOWERPC_BARRIER_H_ #define cpu_relax() asm volatile("or 1,1,1 ; or 2,2,2" ::: "memory") #define pause_short() asm volatile(".long 0x7c40003c" ::: "memory") diff --git a/lib/ppc64/asm/bitops.h b/lib/powerpc/asm/bitops.h similarity index 69% rename from lib/ppc64/asm/bitops.h rename to lib/powerpc/asm/bitops.h index c93d64bb9..dc1b8cd3f 100644 --- a/lib/ppc64/asm/bitops.h +++ b/lib/powerpc/asm/bitops.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_BITOPS_H_ -#define _ASMPPC64_BITOPS_H_ +#ifndef _ASMPOWERPC_BITOPS_H_ +#define _ASMPOWERPC_BITOPS_H_ #ifndef _BITOPS_H_ #error only can be included directly diff --git a/lib/ppc64/asm/io.h b/lib/powerpc/asm/io.h similarity index 50% rename from lib/ppc64/asm/io.h rename to lib/powerpc/asm/io.h index 08d7297c3..cfe099f01 100644 --- a/lib/ppc64/asm/io.h +++ b/lib/powerpc/asm/io.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_IO_H_ -#define _ASMPPC64_IO_H_ +#ifndef _ASMPOWERPC_IO_H_ +#define _ASMPOWERPC_IO_H_ #define __iomem diff --git a/lib/ppc64/asm/mmu.h b/lib/powerpc/asm/mmu.h similarity index 100% rename from lib/ppc64/asm/mmu.h rename to lib/powerpc/asm/mmu.h diff --git a/lib/ppc64/asm/opal.h b/lib/powerpc/asm/opal.h similarity index 90% rename from lib/ppc64/asm/opal.h rename to lib/powerpc/asm/opal.h index 6c3e9ffe2..44e62d80d 100644 --- a/lib/ppc64/asm/opal.h +++ b/lib/powerpc/asm/opal.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef _ASMPPC64_OPAL_H_ -#define _ASMPPC64_OPAL_H_ +#ifndef _ASMPOWERPC_OPAL_H_ +#define _ASMPOWERPC_OPAL_H_ #include diff --git a/lib/ppc64/asm/page.h b/lib/powerpc/asm/page.h similarity index 94% rename from lib/ppc64/asm/page.h rename to lib/powerpc/asm/page.h index c497d86b9..19bf9c677 100644 --- a/lib/ppc64/asm/page.h +++ b/lib/powerpc/asm/page.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _ASMPPC64_PAGE_H_ -#define _ASMPPC64_PAGE_H_ +#ifndef _ASMPOWERPC_PAGE_H_ +#define _ASMPOWERPC_PAGE_H_ /* * Adapted from * lib/arm64/asm/page.h and Linux kernel defines. @@ -62,4 +62,4 @@ extern unsigned long __phys_to_virt(phys_addr_t addr); extern void *__ioremap(phys_addr_t phys_addr, size_t size); #endif /* !__ASSEMBLY__ */ -#endif /* _ASMPPC64_PAGE_H_ */ +#endif /* _ASMPOWERPC_PAGE_H_ */ diff --git a/lib/ppc64/asm/pgtable-hwdef.h b/lib/powerpc/asm/pgtable-hwdef.h similarity index 93% rename from lib/ppc64/asm/pgtable-hwdef.h rename to lib/powerpc/asm/pgtable-hwdef.h index 7cb2c7476..84618809d 100644 --- a/lib/ppc64/asm/pgtable-hwdef.h +++ b/lib/powerpc/asm/pgtable-hwdef.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _ASMPPC64_PGTABLE_HWDEF_H_ -#define _ASMPPC64_PGTABLE_HWDEF_H_ +#ifndef _ASMPOWERPC_PGTABLE_HWDEF_H_ +#define _ASMPOWERPC_PGTABLE_HWDEF_H_ /* * Copyright (C) 2024, IBM Inc, Nicholas Piggin * @@ -63,4 +63,4 @@ #define PHYS_MASK_SHIFT (48) #define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) -#endif /* _ASMPPC64_PGTABLE_HWDEF_H_ */ +#endif /* _ASMPOWERPC_PGTABLE_HWDEF_H_ */ diff --git a/lib/ppc64/asm/pgtable.h b/lib/powerpc/asm/pgtable.h similarity index 99% rename from lib/ppc64/asm/pgtable.h rename to lib/powerpc/asm/pgtable.h index a6ee0d4cd..d4f2c826a 100644 --- a/lib/ppc64/asm/pgtable.h +++ b/lib/powerpc/asm/pgtable.h @@ -122,4 +122,4 @@ static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr) return pte_offset(pmd, addr); } -#endif /* _ASMPPC64_PGTABLE_H_ */ +#endif /* _ASMPOWERPC_PGTABLE_H_ */ diff --git a/lib/ppc64/asm/ptrace.h b/lib/powerpc/asm/ptrace.h similarity index 89% rename from lib/ppc64/asm/ptrace.h rename to lib/powerpc/asm/ptrace.h index db263a59e..39ea950e7 100644 --- a/lib/ppc64/asm/ptrace.h +++ b/lib/powerpc/asm/ptrace.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_PTRACE_H_ -#define _ASMPPC64_PTRACE_H_ +#ifndef _ASMPOWERPC_PTRACE_H_ +#define _ASMPOWERPC_PTRACE_H_ #define KERNEL_REDZONE_SIZE 288 #define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */ @@ -38,4 +38,4 @@ static inline void regs_advance_insn(struct pt_regs *regs) #endif /* __ASSEMBLY__ */ -#endif /* _ASMPPC64_PTRACE_H_ */ +#endif /* _ASMPOWERPC_PTRACE_H_ */ diff --git a/lib/ppc64/asm/spinlock.h b/lib/powerpc/asm/spinlock.h similarity index 54% rename from lib/ppc64/asm/spinlock.h rename to lib/powerpc/asm/spinlock.h index b952386da..9dbe716fd 100644 --- a/lib/ppc64/asm/spinlock.h +++ b/lib/powerpc/asm/spinlock.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_SPINLOCK_H_ -#define _ASMPPC64_SPINLOCK_H_ +#ifndef _ASMPOWERPC_SPINLOCK_H_ +#define _ASMPOWERPC_SPINLOCK_H_ struct spinlock { unsigned int v; @@ -8,4 +8,4 @@ struct spinlock { void spin_lock(struct spinlock *lock); void spin_unlock(struct spinlock *lock); -#endif /* _ASMPPC64_SPINLOCK_H_ */ +#endif /* _ASMPOWERPC_SPINLOCK_H_ */ diff --git a/lib/powerpc/asm/stack.h b/lib/powerpc/asm/stack.h index e1c46ee09..eea139a45 100644 --- a/lib/powerpc/asm/stack.h +++ b/lib/powerpc/asm/stack.h @@ -5,4 +5,7 @@ #error Do not directly include . Just use . #endif +#define HAVE_ARCH_BACKTRACE +#define HAVE_ARCH_BACKTRACE_FRAME + #endif diff --git a/lib/ppc64/asm/vpa.h b/lib/powerpc/asm/vpa.h similarity index 100% rename from lib/ppc64/asm/vpa.h rename to lib/powerpc/asm/vpa.h diff --git a/lib/ppc64/mmu.c b/lib/powerpc/mmu.c similarity index 100% rename from lib/ppc64/mmu.c rename to lib/powerpc/mmu.c diff --git a/lib/ppc64/opal-calls.S b/lib/powerpc/opal-calls.S similarity index 100% rename from lib/ppc64/opal-calls.S rename to lib/powerpc/opal-calls.S diff --git a/lib/ppc64/opal.c b/lib/powerpc/opal.c similarity index 100% rename from lib/ppc64/opal.c rename to lib/powerpc/opal.c diff --git a/lib/ppc64/stack.c b/lib/powerpc/stack.c similarity index 100% rename from lib/ppc64/stack.c rename to lib/powerpc/stack.c diff --git a/lib/ppc64/.gitignore b/lib/ppc64/.gitignore deleted file mode 100644 index 84872bf19..000000000 --- a/lib/ppc64/.gitignore +++ /dev/null @@ -1 +0,0 @@ -asm-offsets.[hs] diff --git a/lib/ppc64/asm/handlers.h b/lib/ppc64/asm/handlers.h deleted file mode 100644 index 92e6fb247..000000000 --- a/lib/ppc64/asm/handlers.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/handlers.h" diff --git a/lib/ppc64/asm/hcall.h b/lib/ppc64/asm/hcall.h deleted file mode 100644 index daabaca51..000000000 --- a/lib/ppc64/asm/hcall.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/hcall.h" diff --git a/lib/ppc64/asm/memory_areas.h b/lib/ppc64/asm/memory_areas.h deleted file mode 100644 index b9fd46b9e..000000000 --- a/lib/ppc64/asm/memory_areas.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _ASMPPC64_MEMORY_AREAS_H_ -#define _ASMPPC64_MEMORY_AREAS_H_ - -#include - -#endif diff --git a/lib/ppc64/asm/ppc_asm.h b/lib/ppc64/asm/ppc_asm.h deleted file mode 100644 index e3929eeee..000000000 --- a/lib/ppc64/asm/ppc_asm.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/ppc_asm.h" diff --git a/lib/ppc64/asm/processor.h b/lib/ppc64/asm/processor.h deleted file mode 100644 index 066a51a00..000000000 --- a/lib/ppc64/asm/processor.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/processor.h" diff --git a/lib/ppc64/asm/reg.h b/lib/ppc64/asm/reg.h deleted file mode 100644 index bc407b555..000000000 --- a/lib/ppc64/asm/reg.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/reg.h" diff --git a/lib/ppc64/asm/rtas.h b/lib/ppc64/asm/rtas.h deleted file mode 100644 index fe77f635c..000000000 --- a/lib/ppc64/asm/rtas.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/rtas.h" diff --git a/lib/ppc64/asm/setup.h b/lib/ppc64/asm/setup.h deleted file mode 100644 index 201929859..000000000 --- a/lib/ppc64/asm/setup.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/setup.h" diff --git a/lib/ppc64/asm/smp.h b/lib/ppc64/asm/smp.h deleted file mode 100644 index 67ced7567..000000000 --- a/lib/ppc64/asm/smp.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/smp.h" diff --git a/lib/ppc64/asm/stack.h b/lib/ppc64/asm/stack.h deleted file mode 100644 index 94fd1021c..000000000 --- a/lib/ppc64/asm/stack.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _ASMPPC64_STACK_H_ -#define _ASMPPC64_STACK_H_ - -#ifndef _STACK_H_ -#error Do not directly include . Just use . -#endif - -#define HAVE_ARCH_BACKTRACE -#define HAVE_ARCH_BACKTRACE_FRAME - -#endif diff --git a/powerpc/Makefile b/powerpc/Makefile index 8a007ab54..9f13d436d 100644 --- a/powerpc/Makefile +++ b/powerpc/Makefile @@ -1 +1,110 @@ -include $(SRCDIR)/$(TEST_DIR)/Makefile.$(ARCH) +# +# powerpc makefile +# +# Authors: Andrew Jones +# +tests = \ + $(TEST_DIR)/selftest.elf \ + $(TEST_DIR)/selftest-migration.elf \ + $(TEST_DIR)/memory-verify.elf \ + $(TEST_DIR)/sieve.elf \ + $(TEST_DIR)/spapr_vpa.elf \ + $(TEST_DIR)/spapr_hcall.elf \ + $(TEST_DIR)/rtas.elf \ + $(TEST_DIR)/emulator.elf \ + $(TEST_DIR)/atomics.elf \ + $(TEST_DIR)/tm.elf \ + $(TEST_DIR)/smp.elf \ + $(TEST_DIR)/sprs.elf \ + $(TEST_DIR)/timebase.elf \ + $(TEST_DIR)/interrupts.elf \ + $(TEST_DIR)/pmu.elf + +all: directories $(TEST_DIR)/boot_rom.bin $(tests) + +cstart.o = $(TEST_DIR)/cstart64.o +reloc.o = $(TEST_DIR)/reloc64.o + +OBJDIRS += lib/powerpc +cflatobjs += lib/powerpc/stack.o +cflatobjs += lib/powerpc/mmu.o +cflatobjs += lib/powerpc/opal.o +cflatobjs += lib/powerpc/opal-calls.o +cflatobjs += lib/util.o +cflatobjs += lib/getchar.o +cflatobjs += lib/alloc_phys.o +cflatobjs += lib/alloc.o +cflatobjs += lib/alloc_page.o +cflatobjs += lib/vmalloc.o +cflatobjs += lib/devicetree.o +cflatobjs += lib/migrate.o +cflatobjs += lib/powerpc/io.o +cflatobjs += lib/powerpc/hcall.o +cflatobjs += lib/powerpc/setup.o +cflatobjs += lib/powerpc/rtas.o +cflatobjs += lib/powerpc/processor.o +cflatobjs += lib/powerpc/handlers.o +cflatobjs += lib/powerpc/smp.o +cflatobjs += lib/powerpc/spinlock.o + +################################################################## + +bits = 64 + +ifeq ($(ENDIAN),little) + arch_CFLAGS = -mlittle-endian + arch_LDFLAGS = -EL +else + arch_CFLAGS = -mbig-endian + arch_LDFLAGS = -EB +endif + +mabi_no_altivec := $(call cc-option,-mabi=no-altivec,"") + +CFLAGS += -std=gnu99 +CFLAGS += -ffreestanding +CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) +CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib +CFLAGS += -Wa,-mregnames + +# We want to keep intermediate files +.PRECIOUS: %.o + +asm-offsets = lib/powerpc/asm-offsets.h +include $(SRCDIR)/scripts/asm-offsets.mak + +%.aux.o: $(SRCDIR)/lib/auxinfo.c + $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\" + +FLATLIBS = $(libcflat) $(LIBFDT_archive) +%.elf: CFLAGS += $(arch_CFLAGS) +%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n +%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o) %.aux.o + $(LD) $(LDFLAGS) -o $@ \ + -T $(SRCDIR)/powerpc/flat.lds --build-id=none \ + $(filter %.o, $^) $(FLATLIBS) + @chmod a-x $@ + @echo -n Checking $@ for unsupported reloc types... + @if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then \ + false; \ + else \ + echo " looks good."; \ + fi + +$(TEST_DIR)/boot_rom.bin: $(TEST_DIR)/boot_rom.elf + dd if=/dev/zero of=$@ bs=256 count=1 + $(OBJCOPY) -O binary $^ $@.tmp + cat $@.tmp >> $@ + $(RM) $@.tmp + +$(TEST_DIR)/boot_rom.elf: CFLAGS = -mbig-endian +$(TEST_DIR)/boot_rom.elf: $(TEST_DIR)/boot_rom.o + $(LD) -EB -nostdlib -Ttext=0x100 --entry=start --build-id=none -o $@ $< + @chmod a-x $@ + +arch_clean: asm_offsets_clean + $(RM) $(TEST_DIR)/*.{o,elf} $(TEST_DIR)/boot_rom.bin \ + $(TEST_DIR)/.*.d lib/powerpc/.*.d + +generated-files = $(asm-offsets) +$(tests:.elf=.o) $(cstart.o) $(cflatobjs): $(generated-files) diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common deleted file mode 100644 index 64a3d93e4..000000000 --- a/powerpc/Makefile.common +++ /dev/null @@ -1,95 +0,0 @@ -# -# powerpc common makefile -# -# Authors: Andrew Jones -# - -tests-common = \ - $(TEST_DIR)/selftest.elf \ - $(TEST_DIR)/selftest-migration.elf \ - $(TEST_DIR)/memory-verify.elf \ - $(TEST_DIR)/sieve.elf \ - $(TEST_DIR)/spapr_hcall.elf \ - $(TEST_DIR)/rtas.elf \ - $(TEST_DIR)/emulator.elf \ - $(TEST_DIR)/atomics.elf \ - $(TEST_DIR)/tm.elf \ - $(TEST_DIR)/smp.elf \ - $(TEST_DIR)/sprs.elf \ - $(TEST_DIR)/timebase.elf \ - $(TEST_DIR)/interrupts.elf \ - $(TEST_DIR)/pmu.elf - -tests-all = $(tests-common) $(tests) -all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) - -################################################################## - -mabi_no_altivec := $(call cc-option,-mabi=no-altivec,"") - -CFLAGS += -std=gnu99 -CFLAGS += -ffreestanding -CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) -CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -CFLAGS += -Wa,-mregnames - -# We want to keep intermediate files -.PRECIOUS: %.o - -asm-offsets = lib/$(ARCH)/asm-offsets.h -include $(SRCDIR)/scripts/asm-offsets.mak - -cflatobjs += lib/util.o -cflatobjs += lib/getchar.o -cflatobjs += lib/alloc_phys.o -cflatobjs += lib/alloc.o -cflatobjs += lib/alloc_page.o -cflatobjs += lib/vmalloc.o -cflatobjs += lib/devicetree.o -cflatobjs += lib/migrate.o -cflatobjs += lib/powerpc/io.o -cflatobjs += lib/powerpc/hcall.o -cflatobjs += lib/powerpc/setup.o -cflatobjs += lib/powerpc/rtas.o -cflatobjs += lib/powerpc/processor.o -cflatobjs += lib/powerpc/handlers.o -cflatobjs += lib/powerpc/smp.o -cflatobjs += lib/powerpc/spinlock.o - -OBJDIRS += lib/powerpc - -%.aux.o: $(SRCDIR)/lib/auxinfo.c - $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\" - -FLATLIBS = $(libcflat) $(LIBFDT_archive) -%.elf: CFLAGS += $(arch_CFLAGS) -%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n -%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o) %.aux.o - $(LD) $(LDFLAGS) -o $@ \ - -T $(SRCDIR)/powerpc/flat.lds --build-id=none \ - $(filter %.o, $^) $(FLATLIBS) - @chmod a-x $@ - @echo -n Checking $@ for unsupported reloc types... - @if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then \ - false; \ - else \ - echo " looks good."; \ - fi - -$(TEST_DIR)/boot_rom.bin: $(TEST_DIR)/boot_rom.elf - dd if=/dev/zero of=$@ bs=256 count=1 - $(OBJCOPY) -O binary $^ $@.tmp - cat $@.tmp >> $@ - $(RM) $@.tmp - -$(TEST_DIR)/boot_rom.elf: CFLAGS = -mbig-endian -$(TEST_DIR)/boot_rom.elf: $(TEST_DIR)/boot_rom.o - $(LD) -EB -nostdlib -Ttext=0x100 --entry=start --build-id=none -o $@ $< - @chmod a-x $@ - -powerpc_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf} $(TEST_DIR)/boot_rom.bin \ - $(TEST_DIR)/.*.d lib/powerpc/.*.d - -generated-files = $(asm-offsets) -$(tests-all:.elf=.o) $(cstart.o) $(cflatobjs): $(generated-files) diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 deleted file mode 100644 index 2466471f9..000000000 --- a/powerpc/Makefile.ppc64 +++ /dev/null @@ -1,31 +0,0 @@ -# -# ppc64 makefile -# -# Authors: Andrew Jones -# -bits = 64 - -ifeq ($(ENDIAN),little) - arch_CFLAGS = -mlittle-endian - arch_LDFLAGS = -EL -else - arch_CFLAGS = -mbig-endian - arch_LDFLAGS = -EB -endif - -cstart.o = $(TEST_DIR)/cstart64.o -reloc.o = $(TEST_DIR)/reloc64.o - -OBJDIRS += lib/ppc64 -cflatobjs += lib/ppc64/stack.o -cflatobjs += lib/ppc64/mmu.o -cflatobjs += lib/ppc64/opal.o -cflatobjs += lib/ppc64/opal-calls.o - -# ppc64 specific tests -tests = $(TEST_DIR)/spapr_vpa.elf - -include $(SRCDIR)/$(TEST_DIR)/Makefile.common - -arch_clean: powerpc_clean - $(RM) lib/ppc64/.*.d From patchwork Tue Mar 19 07:59:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1913440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JC73S4c9; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzPtH6c1Wz1yWn for ; Tue, 19 Mar 2024 19:25:27 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JC73S4c9; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TzPtH5Qvpz3w3N for ; Tue, 19 Mar 2024 19:25:27 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=20230601 header.b=JC73S4c9; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::430; helo=mail-pf1-x430.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 4TzPMJ486gz3vgG for ; Tue, 19 Mar 2024 19:02:04 +1100 (AEDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso3171443b3a.1 for ; Tue, 19 Mar 2024 01:02:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710835323; x=1711440123; darn=lists.ozlabs.org; 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=qexXpkpnrPosSamG4rwhfxX05W0nrjIaC9l6HzJDgrY=; b=JC73S4c9futZDemDmz1NN56JmDHAqoRK8vHIC6O8qJJ1BHK8lJLJnzjakKhKr5b+WC M7Ge7WhAwoBn85fGZbRpv5HBEZjgUuipWuezNzdzIvD62xj1DfroOCARbMw0eZ/sUhUC D11j8Vi8c6SSi3U/FHFDlTkX3c+IKPGuPPZ60w51PnTq+J/KGQzzWRMtYT5yv97KRXlW yZTNsL8uwnZod7E23PSo9pMpWr2TPEMI84ZKHX9Pxfvee7Ja5VjvmUCNt2bnX/9L7qXy 9zjLxLXqQMv0rsHV5qOmAtrdpZCgYl01QXdByqqoapaMilAWXjXvgAvFxC3KGt9G0LTn Hplg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710835323; x=1711440123; 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=qexXpkpnrPosSamG4rwhfxX05W0nrjIaC9l6HzJDgrY=; b=VdCKcd72gdej6xzyo6j3zWB9HDRgfJCV+lghOFA7TT58p5ZevsADestGIKeVD4lU9V frrT9Q3/ABt9+kcSaeuZRDNLNu8EGYrosqviCPavlmwookRDSV1o3m53nyciPTGjOBg2 fN+I97sn4kAjU+Bo9YdOUPSzO2NMKlz67du4gbFx0QKbX8E9n1VveUKsEUK6CqQcY8kG MgvOs/wUjLp/Iz2VGh+X3zvmngkpN6P+ABqMzcfr6rPCtakKE7P3Vui+Truc/aNQu+dn PM2e9EC0RgOS6ekTvo6s5s/U4b957BNYddOqOqPq1myHndFZfOV3WHb9pe5bQDSp38EU zEGw== X-Forwarded-Encrypted: i=1; AJvYcCVpFgNq5TzGERV/vdlOYD8ao9sLOxL/++ltDLIxb/tz9Ys7EL/+OqSEvZCfxP9DtK7jh7VdIXV90ZPWQLQDQvk3Viz9YX1Bh0nlkIxecQ== X-Gm-Message-State: AOJu0YyicDllIIrB0tDP5PtytKJ8NfD31AlB/6VeMJSqMPzJ5d5tSxVi tctW0oX0XqZXExB9Z/tRJB26ZwUuBIazHvLz90iTg5bWh5jNefGg X-Google-Smtp-Source: AGHT+IHs8YWGPGhmUNPd0Btq9HERv+NAaHotqwxHbqd2DVNc7XUkljS2Bi/D/KDM1wOxpVIcJpG6LA== X-Received: by 2002:a05:6a00:1a89:b0:6e6:c256:9d49 with SMTP id e9-20020a056a001a8900b006e6c2569d49mr2457020pfv.0.1710835322806; Tue, 19 Mar 2024 01:02:02 -0700 (PDT) Received: from wheely.local0.net (193-116-208-39.tpgi.com.au. [193.116.208.39]) by smtp.gmail.com with ESMTPSA id q23-20020a62ae17000000b006e5c464c0a9sm9121283pff.23.2024.03.19.01.01.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 01:02:02 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v7 35/35] powerpc: gitlab CI update Date: Tue, 19 Mar 2024 17:59:26 +1000 Message-ID: <20240319075926.2422707-36-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240319075926.2422707-1-npiggin@gmail.com> References: <20240319075926.2422707-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: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This adds testing for the powernv machine, and adds a gitlab-ci test group instead of specifying all tests in .gitlab-ci.yml. Signed-off-by: Nicholas Piggin --- .gitlab-ci.yml | 20 ++++++++------------ powerpc/unittests.cfg | 14 ++++++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bd34da04f..e3638b088 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -97,12 +97,10 @@ build-ppc64be: - cd build - ../configure --arch=ppc64 --endian=big --cross-prefix=powerpc64-linux-gnu- - make -j2 - - ACCEL=tcg ./run_tests.sh - selftest-setup selftest-migration selftest-migration-skip spapr_hcall - rtas-get-time-of-day rtas-get-time-of-day-base rtas-set-time-of-day - emulator - | tee results.txt - - if grep -q FAIL results.txt ; then exit 1 ; fi + - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt + - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt build-ppc64le: extends: .intree_template @@ -110,12 +108,10 @@ build-ppc64le: - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat - ./configure --arch=ppc64 --endian=little --cross-prefix=powerpc64-linux-gnu- - make -j2 - - ACCEL=tcg ./run_tests.sh - selftest-setup selftest-migration selftest-migration-skip spapr_hcall - rtas-get-time-of-day rtas-get-time-of-day-base rtas-set-time-of-day - emulator - | tee results.txt - - if grep -q FAIL results.txt ; then exit 1 ; fi + - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt + - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt # build-riscv32: # Fedora doesn't package a riscv32 compiler for QEMU. Oh, well. diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 379aa166b..f6ddc4a7f 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -16,12 +16,12 @@ file = selftest.elf smp = 2 extra_params = -m 1g -append 'setup smp=2 mem=1024' -groups = selftest +groups = selftest gitlab-ci [selftest-migration] file = selftest-migration.elf machine = pseries -groups = selftest migration +groups = selftest migration gitlab-ci # TODO: Remove accel=kvm once the following TCG migration fix has been merged: # https://lore.kernel.org/qemu-devel/20240219061731.232570-1-npiggin@gmail.com/ accel = kvm @@ -29,7 +29,7 @@ accel = kvm [selftest-migration-skip] file = selftest-migration.elf machine = pseries -groups = selftest migration +groups = selftest migration gitlab-ci extra_params = -append "skip" # This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream @@ -42,6 +42,7 @@ groups = migration [spapr_hcall] file = spapr_hcall.elf machine = pseries +groups = gitlab-ci [spapr_vpa] file = spapr_vpa.elf @@ -52,24 +53,25 @@ file = rtas.elf machine = pseries timeout = 5 extra_params = -append "get-time-of-day date=$(date +%s)" -groups = rtas +groups = rtas gitlab-ci [rtas-get-time-of-day-base] file = rtas.elf machine = pseries timeout = 5 extra_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)" -groups = rtas +groups = rtas gitlab-ci [rtas-set-time-of-day] file = rtas.elf machine = pseries extra_params = -append "set-time-of-day" timeout = 5 -groups = rtas +groups = rtas gitlab-ci [emulator] file = emulator.elf +groups = gitlab-ci [interrupts] file = interrupts.elf