From patchwork Fri Feb 23 15:51:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569303 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 129BA8288F for ; Fri, 23 Feb 2024 15:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703502; cv=none; b=LZT1mlujlEPlAUExHKDQsE24t6KUyJVGngCKlUpI+Xr5j3DfUjbyy455dDrBV6HJttq42jXRk5NHQTWfMJ+rR2UHoLN3NjBSE+jWrUFlvF3ZnkJr7Se0uunjEd5MWulR89Akf2cSwDBswizK9TdsbwjgM3RsbSTRcFk+imgySvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703502; c=relaxed/simple; bh=lEQ6K0Q+ikRwyl81me4BlSv2NGdOq8DunwtRX35EskI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=u9IB0+ZzVKZKNz9RxhNLh9YE8Hf5vouCBm07Uak3B5BZ9entfTdxczpWztENQpNM0T0NZRX8cguFjofSee37R9xYBsuV+OcvE/eNHxgDduVg32L/Dhz1fmS9XjudV34Sh+vweuT+U1ocVZU9L3p32v/2UQ+KdwNHjmxMm6nZ/60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=A4ku1+tm; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="A4ku1+tm" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r4OBPHXt5GQvSmvvE0fniEaHSM6+gtKcQZ+u11vU2bk=; b=A4ku1+tmZLNHs+VypE1+ThUkgTv3VIvMQpZQ7vc+UOXaU+yf/83l6NtPXB5rPzzlhdMm/L q/CCg+VWoenenUoEZJoVr9JgcAuOgs+ANg9JrJzQJTmpxjudEakda2GnE7qQCANL25+JWm 96RMMBnBZ9l7oSIeSfID2Ym4JmUhUP8= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 01/14] runtime: Update MAX_SMP probe Date: Fri, 23 Feb 2024 16:51:27 +0100 Message-ID: <20240223155125.368512-17-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT Arm's MAX_SMP probing must have stopped working at some point due to QEMU's error message changing, but nobody noticed. Also, the probing should work for at least x86 now too, so the comment isn't correct anymore either. We could probably just delete this probe thing, but in case it could still serve some purpose we can also keep it, but updated for later QEMU, and only enabled when a new run_tests.sh command line option is provided. Signed-off-by: Andrew Jones --- run_tests.sh | 5 ++++- scripts/runtime.bash | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index abb0ab773362..bb3024ff95b1 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -44,7 +44,7 @@ fi only_tests="" list_tests="" -args=$(getopt -u -o ag:htj:vl -l all,group:,help,tap13,parallel:,verbose,list -- $*) +args=$(getopt -u -o ag:htj:vl -l all,group:,help,tap13,parallel:,verbose,list,probe-maxsmp -- $*) [ $? -ne 0 ] && exit 2; set -- $args; while [ $# -gt 0 ]; do @@ -78,6 +78,9 @@ while [ $# -gt 0 ]; do -l | --list) list_tests="yes" ;; + --probe-maxsmp) + probe_maxsmp + ;; --) ;; *) diff --git a/scripts/runtime.bash b/scripts/runtime.bash index c73fb0240d12..f2e43bb1ed60 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -200,12 +200,13 @@ function run() # # Probe for MAX_SMP, in case it's less than the number of host cpus. # -# This probing currently only works for ARM, as x86 bails on another -# error first, so this check is only run for ARM and ARM64. The -# parameter expansion takes the last number from the QEMU error -# message, which gives the allowable MAX_SMP. -if [[ $ARCH == 'arm' || $ARCH == 'arm64' ]] && - smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'exceeds max CPUs'); then - smp=${smp##*(} - MAX_SMP=${smp:0:-1} -fi +function probe_maxsmp() +{ + local smp + + if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'Invalid SMP CPUs'); then + smp=${smp##* } + echo "Restricting MAX_SMP from ($MAX_SMP) to the max supported ($smp)" >&2 + MAX_SMP=$smp + fi +} From patchwork Fri Feb 23 15:51:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569304 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13AC082D81 for ; Fri, 23 Feb 2024 15:51:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703506; cv=none; b=YXO6pd9qzzOE5GUnWp0v5xzrcr2NKouMGZBtjQgNKvAd0aDMrCNIUIobInf0ERJkQ8MiM1eZ+g9n6l2Upxean6FT7GiS4j0SK0ty8g6uq122mWVP59cEQ+EcL+8WHvx6xn3HKgzbSP8LSjeEoQ4XVzswhGL9B2X5ENcIywEC5Ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703506; c=relaxed/simple; bh=3LDznxWjy7yNqKOljjbACMiXY3NHVbc6pQf9X3Yw9ao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=qPhELtGv5aNDBm0W/rmnCMo/TQ2TzaDQnDKh1RUU693bm+bH0JDmSA+G/WqnTjCNrKB/LEAl6rfkN3zOHuoLM3Zvd1y3m69/Fu1hlfR2IrWjRbYz/hee9SUxAFV5a42o1xOhrzhqF/EnA8wC0XvKpsGn+m3XAicIq5oREcaDxpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jdTzvQZL; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jdTzvQZL" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YaaM1tdWXQy3CMwa8iTfOjIIZAX3H3bey75zFrrIGnE=; b=jdTzvQZL2aBcYeJMW+XQ1w6zw9n5fmgJ6tavu/N6OUR8cad1nn+PTkLS+6CHXO2r8/Knz3 sj7VjSijuMNBWvWFU/5XfmTJIp6/E0UDiiWhJMvKn+JlE/2ccR/ijRh0+aLIDhWzQGhdEZ dh98w05A1/GBboR8ppzWSWC1BgDOmGI= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 02/14] runtime: Add yet another 'no kernel' error message Date: Fri, 23 Feb 2024 16:51:28 +0100 Message-ID: <20240223155125.368512-18-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT When booting an Arm machine with the -bios command line option we get yet another error message from QEMU when using _NO_FILE_4Uhere_ to probe command line support. Add it to the check in premature_failure() Signed-off-by: Andrew Jones --- scripts/runtime.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/runtime.bash b/scripts/runtime.bash index f2e43bb1ed60..255e756f2cb2 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -18,7 +18,7 @@ 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" && + grep -q -e "could not \(load\|open\) kernel" -e "error loading" -e "failed to load" && return 1 RUNTIME_log_stderr <<< "$log" From patchwork Fri Feb 23 15:51:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569305 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B06382C94 for ; Fri, 23 Feb 2024 15:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703510; cv=none; b=Vrrr4WxbnlcwjnW7NYrlMyel0mYnnc26W0d42KCKa67aQFFjOmxb0iITvAoQQWnOJxFabiAkFqRCviR4K6U2lF7aEdo52MycdcLS+OGNeGYTVc2T7UCc0lSABY5mcgUndux87ZoPiTxA0DHHtQn/ext2/5RFEeSgyVt39gvH240= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703510; c=relaxed/simple; bh=iAcqRhpWnmxPRht06kZJBZfd6TfGtdgpBsS5jPtRCzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=f6BaUAbTlXkHtex7rjUqF8XLaTqWR97DAu3HpPn4qEYLCYQstg4Z0hShzOXq6tCL15KnLUnhWNh/iUFbAkdzI/0cAMLOkkHvuPKh9nHbI30xyP2OGKaVNzdiWunlCMzE9S9xjmTtjN4/IWORhVQezuAGBMFUH0lRVVxkoFaCszc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=T+xQGVyr; arc=none smtp.client-ip=91.218.175.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="T+xQGVyr" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703506; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gZtRLPtvNLuRe5mE7VJYVBFfuNR+bm5yOU8r9yvFXgU=; b=T+xQGVyrSfPDJVz6hAUVaaupPU0DDvzNwldSsjrNMFNIjPpbltm8Z9255w2IUN+S4zr0m6 R02KfqnHaCP9gsGZpYJAqzpc9Nz6dRA3qBgNlbe7t3pzUBmKw2Ht7ICUclycV+wIrbj1Rk ZEFW5QzU0Ql2YS1s5lSm6CQCRbUFgV0= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 03/14] arm64: efi: Don't create dummy test Date: Fri, 23 Feb 2024 16:51:29 +0100 Message-ID: <20240223155125.368512-19-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT The purpose of the _NO_FILE_4Uhere_ kernel is to check that all the QEMU command line options that have been pulled together by the scripts will work. Since booting with UEFI and the -kernel command line is supported by QEMU, then we don't need to create a dummy test for _NO_FILE_4Uhere_ and go all the way into UEFI's shell and execute it to prove the command line is OK, since we would have failed much before all that if it wasn't. Just run QEMU "normally", i.e. no EFI_RUN=y, but add the UEFI -bios and its file system command line options, in order to check the full command line. Signed-off-by: Andrew Jones --- arm/efi/run | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arm/efi/run b/arm/efi/run index 6872c337c945..e629abde5273 100755 --- a/arm/efi/run +++ b/arm/efi/run @@ -53,7 +53,14 @@ while (( "$#" )); do done if [ "$EFI_CASE" = "_NO_FILE_4Uhere_" ]; then - EFI_CASE=dummy + EFI_CASE_DIR="$EFI_TEST/dummy" + mkdir -p "$EFI_CASE_DIR" + $TEST_DIR/run \ + $EFI_CASE \ + -bios "$EFI_UEFI" \ + -drive file.dir="$EFI_CASE_DIR/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ + "${qemu_args[@]}" + exit fi : "${EFI_CASE_DIR:="$EFI_TEST/$EFI_CASE"}" From patchwork Fri Feb 23 15:51:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569306 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53E8483A03 for ; Fri, 23 Feb 2024 15:51:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703513; cv=none; b=ELjozpSkMC1zobLi+V9LRymHuLWXn0vh0hQpEKtVB1A3D6+CI5s2OPha+KKzSMadjPSBoeJKTfHrcSxCRk84LDuReM2lQvmabD41VHRymzlX2rNZPcNSA2+5sO6UQAXOekN+jn8DTowRGNteHZD8zjEUAW5RJJz09KSrGFP/V0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703513; c=relaxed/simple; bh=GPrAyHLVf2wc88m9XK+4/DbNDHYGrAjShKzfIawstR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=k0QEPuwMqKSTfaVfTw/sj4/3Wh/sdp9y95wlmR4R1q4G18I+ed9A6O4VJcvZafGqla3K77f0oI3vXOfq2h4NF7rkAuuU4BGY3r6P+YwBXkquVsQ/tWTh8YJcEDRA21xtNpw9NXPBF60xTKpJ8jHBk9wzpwNDF+fVNr2il56xHxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FC5TcbP6; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FC5TcbP6" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m99aX8Q0esPhIRcjJL5DRMkAA/e1dGPeO2kzwVCYgCo=; b=FC5TcbP6lvNWVtIs6U0lASGxTSvUTHHFZW5xcMfBxMkORp6mPZ0BfcLjLPpjqDwW7WY+ew dpf2YMy9ifmWkMGcMqtWMJgmQtLO1bjZXPrREY1M46FZjciQS2F61RlfzSQUHzJ2uv9kPT cZjZIq5Ge9UfbHBLZRE+Yfwux5CkrHU= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 04/14] arm64: efi: Make running tests on EFI can be parallel Date: Fri, 23 Feb 2024 16:51:30 +0100 Message-ID: <20240223155125.368512-20-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT From: Shaoqin Huang Currently running tests on EFI in parallel can cause part of tests to fail, this is because arm/efi/run script use the EFI_CASE to create the subdir under the efi-tests, and the EFI_CASE is the filename of the test, when running tests in parallel, the multiple tests exist in the same filename will execute at the same time, which will use the same directory and write the test specific things into it, this cause chaotic and make some tests fail. For example, if we running the pmu-sw-incr and pmu-chained-counters and other pmu tests on EFI at the same time, the EFI_CASE will be pmu. So they will write their $cmd_args to the $EFI/TEST/pmu/startup.nsh at the same time, which will corrupt the startup.nsh file. And we can get the log which outputs: * pmu-sw-incr.log: - ABORT: pmu: Unknown sub-test 'pmu-mem-acce' * pmu-chained-counters.log - ABORT: pmu: Unknown sub-test 'pmu-mem-access-reliab' And the efi-tests/pmu/startup.nsh: @echo -off setvar fdtfile -guid 97ef3e03-7329-4a6a-b9ba-6c1fdcc5f823 -rt =L"dtb" pmu.efi pmu-mem-access-reliability setvar fdtfile -guid 97ef3e03-7329-4a6a-b9ba-6c1fdcc5f823 -rt =L"dtb" pmu.efi pmu-chained-sw-incr As you can see, when multiple tests write to the same startup.nsh file, it causes the issue. To Fix this issue, use the testname instead of the filename to create the subdir under the efi-tests. We use the EFI_TESTNAME to replace the EFI_CASE in script. Since every testname is specific, now the tests can be run parallel. It also considers when user directly use the arm/efi/run to run test, in this case, still use the filename. Besides, replace multiple $EFI_TEST/$EFI_CASE to the $EFI_CASE_DIR, this makes the script looks more clean and we don'e need to replace many EFI_CASE to EFI_TESTNAME. Reviewed-by: Andrew Jones Signed-off-by: Shaoqin Huang Signed-off-by: Andrew Jones --- arm/efi/run | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arm/efi/run b/arm/efi/run index e629abde5273..8b6512520026 100755 --- a/arm/efi/run +++ b/arm/efi/run @@ -25,6 +25,8 @@ fi : "${EFI_UEFI:=$DEFAULT_UEFI}" : "${EFI_TEST:=efi-tests}" : "${EFI_CASE:=$(basename $1 .efi)}" +: "${EFI_TESTNAME:=$TESTNAME}" +: "${EFI_TESTNAME:=$EFI_CASE}" : "${EFI_VAR_GUID:=97ef3e03-7329-4a6a-b9ba-6c1fdcc5f823}" [ "$EFI_USE_ACPI" = "y" ] || EFI_USE_DTB=y @@ -63,20 +65,20 @@ if [ "$EFI_CASE" = "_NO_FILE_4Uhere_" ]; then exit fi -: "${EFI_CASE_DIR:="$EFI_TEST/$EFI_CASE"}" +: "${EFI_CASE_DIR:="$EFI_TEST/$EFI_TESTNAME"}" mkdir -p "$EFI_CASE_DIR" -cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_TEST/$EFI_CASE/" -echo "@echo -off" > "$EFI_TEST/$EFI_CASE/startup.nsh" +cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_DIR/" +echo "@echo -off" > "$EFI_CASE_DIR/startup.nsh" if [ "$EFI_USE_DTB" = "y" ]; then qemu_args+=(-machine acpi=off) FDT_BASENAME="dtb" - $(EFI_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_TEST/$EFI_CASE/$FDT_BASENAME" "${qemu_args[@]}") - echo "setvar fdtfile -guid $EFI_VAR_GUID -rt =L\"$FDT_BASENAME\"" >> "$EFI_TEST/$EFI_CASE/startup.nsh" + $(EFI_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_CASE_DIR/$FDT_BASENAME" "${qemu_args[@]}") + echo "setvar fdtfile -guid $EFI_VAR_GUID -rt =L\"$FDT_BASENAME\"" >> "$EFI_CASE_DIR/startup.nsh" fi -echo "$EFI_CASE.efi" "${cmd_args[@]}" >> "$EFI_TEST/$EFI_CASE/startup.nsh" +echo "$EFI_CASE.efi" "${cmd_args[@]}" >> "$EFI_CASE_DIR/startup.nsh" EFI_RUN=y $TEST_DIR/run \ -bios "$EFI_UEFI" \ - -drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ + -drive file.dir="$EFI_CASE_DIR/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ "${qemu_args[@]}" From patchwork Fri Feb 23 15:51:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569307 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA1F282D9D for ; Fri, 23 Feb 2024 15:51:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703518; cv=none; b=u37EiaftBCxeoYKvHL9Zh9zsndkq5KeTZs4iKNpokS+jxu5jQqDqQzwMcHoyyNPeD/h90/nlhHlmQyPxZCwX/6EMqGRUFVoecSz3NSRmSOlK6IDUjq6VUHgAWyhU0yonLIMHjFevwE+XdiFt67obIX/l3As5iqcIAIn8Vjemg4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703518; c=relaxed/simple; bh=BoBz/S/wtgNn0b2w3x5Xyyoegeq7eW2pC44M0/GD4LM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=SeHbB0QDLIUliplJjMLQ3NEY8V0B0B4xG0BPTfZVt3w6UehB3NjQUXXwArJzCQ6g8BYKVRpm6OvwSyjxuLi0nyJSGodhF49441plt/CJWWyogzLtyB5eRi/3ly8hxdhubq/vVXQM7KjRVfW1AnWuCMzFNQuMo9Mgp6JFfR/cTws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jXaPvmoE; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jXaPvmoE" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ulzjyiK3ZcBO8GfguKNO7JW+HXX1i+VA6rmcrThM2TI=; b=jXaPvmoE4p4CTkg4OqmI0GFPxSJWBsWKrkq+oDvD0aqI+ru/yAt+nukIU4Q63wws0Y54Pv bBB/FcelDw1YOAT6V/RYa6G8Fy4Q65UR1+eKb2CfKyVM9wAlHxge90FQ6maMZGcOb5RJPZ +0fRJzAbM0Rc7pP4WXSvqHAxXJJvjmw= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 05/14] arm64: efi: Remove redundant dtb generation Date: Fri, 23 Feb 2024 16:51:31 +0100 Message-ID: <20240223155125.368512-21-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT When a line in bash is written as $(some-line) Then 'some-line' will be evaluated and then whatever some-line outputs will be evaluated. The dtb is getting generated twice since the line that should generate it is within $() and the output of that is the command itself (since arm/run outputs its command), so the command gets executed again. Remove the $() to just execute dtb generation once. While mucking with arm/efi/run tidy it a bit by by removing the unused sourcing of common.bash and the unnecessary 'set -e' (we check for and propagate errors ourselves). Finally, make one reorganization change and some whitespace fixes. Fixes: 2607d2d6946a ("arm64: Add an efi/run script") Fixes: 2e080dafec2a ("arm64: Use the provided fdt when booting through EFI") Signed-off-by: Andrew Jones --- arm/efi/run | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/arm/efi/run b/arm/efi/run index 8b6512520026..e45cecfa3265 100755 --- a/arm/efi/run +++ b/arm/efi/run @@ -1,7 +1,5 @@ #!/bin/bash -set -e - if [ $# -eq 0 ]; then echo "Usage $0 TEST_CASE [QEMU_ARGS]" exit 2 @@ -13,7 +11,6 @@ if [ ! -f config.mak ]; then fi source config.mak source scripts/arch-run.bash -source scripts/common.bash if [ -f /usr/share/qemu-efi-aarch64/QEMU_EFI.fd ]; then DEFAULT_UEFI=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd @@ -27,6 +24,7 @@ fi : "${EFI_CASE:=$(basename $1 .efi)}" : "${EFI_TESTNAME:=$TESTNAME}" : "${EFI_TESTNAME:=$EFI_CASE}" +: "${EFI_CASE_DIR:="$EFI_TEST/$EFI_TESTNAME"}" : "${EFI_VAR_GUID:=97ef3e03-7329-4a6a-b9ba-6c1fdcc5f823}" [ "$EFI_USE_ACPI" = "y" ] || EFI_USE_DTB=y @@ -65,20 +63,18 @@ if [ "$EFI_CASE" = "_NO_FILE_4Uhere_" ]; then exit fi -: "${EFI_CASE_DIR:="$EFI_TEST/$EFI_TESTNAME"}" mkdir -p "$EFI_CASE_DIR" - cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_DIR/" echo "@echo -off" > "$EFI_CASE_DIR/startup.nsh" if [ "$EFI_USE_DTB" = "y" ]; then qemu_args+=(-machine acpi=off) FDT_BASENAME="dtb" - $(EFI_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_CASE_DIR/$FDT_BASENAME" "${qemu_args[@]}") + EFI_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_CASE_DIR/$FDT_BASENAME" "${qemu_args[@]}" echo "setvar fdtfile -guid $EFI_VAR_GUID -rt =L\"$FDT_BASENAME\"" >> "$EFI_CASE_DIR/startup.nsh" fi echo "$EFI_CASE.efi" "${cmd_args[@]}" >> "$EFI_CASE_DIR/startup.nsh" EFI_RUN=y $TEST_DIR/run \ - -bios "$EFI_UEFI" \ - -drive file.dir="$EFI_CASE_DIR/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ - "${qemu_args[@]}" + -bios "$EFI_UEFI" \ + -drive file.dir="$EFI_CASE_DIR/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ + "${qemu_args[@]}" From patchwork Fri Feb 23 15:51:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569308 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0260C83CC4 for ; Fri, 23 Feb 2024 15:52:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703526; cv=none; b=nWkR1RcPaFy0y/aaeMuEJs93u6bWbwOjE4N05spVePVFQDBkeL8bYPcsprOH9YF4O56WQH7Odnx9opuwSxTSuzFnO1xtuGkHq3QVUEPzSMwkS9cYXwUlMn8l1b1SG21JzdYcwUzO+ir5rF1h8TIEGezmJcZ98/m9ndzw8NFQ6PY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703526; c=relaxed/simple; bh=DY31vysK7cGz6Q2P/b3MdEQHR+Sh51exbDF6lXeYq3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=FmoKAqvk51p8ezbljDQOwWE61H4xMQfMWBpZht9i+CW5om0UuDuvwOGtumsC/SK/OggjFK32nrV04qSWtySrKZohDV+2kV8mmh/j4w7e0WtwjO6JK9GYTpR6ol8ZAWSypiweEAnFaz6iW5Hnpp5zEkJf1I9QmbnGv9c5rw0x30M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DFPs0tCq; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DFPs0tCq" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6q8qa7mmXpxaf2/inv83q75exjACEJX7PdelrGH+xj4=; b=DFPs0tCqL10Foq3qnkG1aEfRZhOO3QjGlMR1lPoJN+HZ7VeR3QJkwdVd/PRZjgzQ4fnYAQ TdHRJVZ58+3NBn+A4lfH4RzQt9FoQk+jtpzgYGnP0tNgSnE7TxHtoMXqsfZSigafYHhcr9 mxZbEG4eHbgf0lply7BlLfJRWUW+cdk= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 06/14] arm64: efi: Move run code into a function Date: Fri, 23 Feb 2024 16:51:32 +0100 Message-ID: <20240223155125.368512-22-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT Push the run code in arm/efi/run into a function named uefi_shell_run() since it will create an EFI file system, copy the test and possibly the DTB there, and create a startup.nsh which executes the test from the UEFI shell. Pushing this code into a function allows additional execution paths to be created in the script. Also rename EFI_RUN to UEFI_SHELL_RUN to pass the information on to arm/run that it's being called from uefi_shell_run(). Signed-off-by: Andrew Jones --- arm/efi/run | 33 +++++++++++++++++++-------------- arm/run | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arm/efi/run b/arm/efi/run index e45cecfa3265..494ba9e7efe7 100755 --- a/arm/efi/run +++ b/arm/efi/run @@ -63,18 +63,23 @@ if [ "$EFI_CASE" = "_NO_FILE_4Uhere_" ]; then exit fi -mkdir -p "$EFI_CASE_DIR" -cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_DIR/" -echo "@echo -off" > "$EFI_CASE_DIR/startup.nsh" -if [ "$EFI_USE_DTB" = "y" ]; then - qemu_args+=(-machine acpi=off) - FDT_BASENAME="dtb" - EFI_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_CASE_DIR/$FDT_BASENAME" "${qemu_args[@]}" - echo "setvar fdtfile -guid $EFI_VAR_GUID -rt =L\"$FDT_BASENAME\"" >> "$EFI_CASE_DIR/startup.nsh" -fi -echo "$EFI_CASE.efi" "${cmd_args[@]}" >> "$EFI_CASE_DIR/startup.nsh" +uefi_shell_run() +{ + mkdir -p "$EFI_CASE_DIR" + cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_DIR/" + echo "@echo -off" > "$EFI_CASE_DIR/startup.nsh" + if [ "$EFI_USE_DTB" = "y" ]; then + qemu_args+=(-machine acpi=off) + FDT_BASENAME="dtb" + UEFI_SHELL_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_CASE_DIR/$FDT_BASENAME" "${qemu_args[@]}" + echo "setvar fdtfile -guid $EFI_VAR_GUID -rt =L\"$FDT_BASENAME\"" >> "$EFI_CASE_DIR/startup.nsh" + fi + echo "$EFI_CASE.efi" "${cmd_args[@]}" >> "$EFI_CASE_DIR/startup.nsh" + + UEFI_SHELL_RUN=y $TEST_DIR/run \ + -bios "$EFI_UEFI" \ + -drive file.dir="$EFI_CASE_DIR/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ + "${qemu_args[@]}" +} -EFI_RUN=y $TEST_DIR/run \ - -bios "$EFI_UEFI" \ - -drive file.dir="$EFI_CASE_DIR/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ - "${qemu_args[@]}" +uefi_shell_run diff --git a/arm/run b/arm/run index ac64b3b461a2..40c2ca66ba7e 100755 --- a/arm/run +++ b/arm/run @@ -60,7 +60,7 @@ if ! $qemu $M -chardev '?' | grep -q testdev; then exit 2 fi -if [ "$EFI_RUN" != "y" ]; then +if [ "$UEFI_SHELL_RUN" != "y" ]; then chr_testdev='-device virtio-serial-device' chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd' fi @@ -75,7 +75,7 @@ command="$qemu -nodefaults $M $A -cpu $processor $chr_testdev $pci_testdev" command+=" -display none -serial stdio" command="$(migration_cmd) $(timeout_cmd) $command" -if [ "$EFI_RUN" = "y" ]; then +if [ "$UEFI_SHELL_RUN" = "y" ]; then ENVIRON_DEFAULT=n run_qemu_status $command "$@" else run_qemu $command -kernel "$@" From patchwork Fri Feb 23 15:51:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569309 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 508F682D6D for ; Fri, 23 Feb 2024 15:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703535; cv=none; b=PmrZr1BD3BpYcq6wXSkeWLBlUsloA1O/X0MiUgjlo6bhN2MQm5aefupvl406A/FQsRG4F0XMVkokD5BMT+kLHI4OmKclYyE+wKoAsMaf54JPe0vS0Rpvz6w+b/J0FDBRQQnshu0Zgi+h5kqjlVwuRWo+qCnP9SqIpGkbftxa1ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703535; c=relaxed/simple; bh=pbhRCFWKrwLmCtktpDAGcl7va/xUmhq1PnDLXV/IAw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=QgmX7Nnd2FGUbnUu1uFKwbTAegBvOgA+kRTwDq0OY7FvbkntXZhdfG+UTUL3cVkAxosSuLTp7vgO6zf+3HO5XYQ0gAVOe3iFw25Zc79TPyj2G0ZxS9hdy3Yszr825/AbTreKyXIl10UMT1Gv06fRgz3Nb0TU13GQqo5Hm8CfZRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XpIEBOdb; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XpIEBOdb" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RhisSx5x/V7b9Y0kHLu8YVQTirjJ97CAwr4agFIIB1Y=; b=XpIEBOdbXXUZz9GBnf+YnwPnuelMz0R6AIyG3MoHt6rcR3vOruHZCgq7ZXWFwRyXA6J31l 6WfVy31xHZfbN/A02bnGHDwTJw9KPGGX+BA8IIy0eM3m5RBq15e0+8KC2EIYSJGrdOl9WW 1MOO9/gx9NfcHxTjJezk2bi8tnPaQ+0= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 07/14] arm64: efi: Remove EFI_USE_DTB Date: Fri, 23 Feb 2024 16:51:33 +0100 Message-ID: <20240223155125.368512-23-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT We don't need two variables for one boolean property. Just use !EFI_USE_ACPI to infer efi-use-dtb. Signed-off-by: Andrew Jones --- arm/efi/run | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arm/efi/run b/arm/efi/run index 494ba9e7efe7..b7a8418a07f8 100755 --- a/arm/efi/run +++ b/arm/efi/run @@ -27,8 +27,6 @@ fi : "${EFI_CASE_DIR:="$EFI_TEST/$EFI_TESTNAME"}" : "${EFI_VAR_GUID:=97ef3e03-7329-4a6a-b9ba-6c1fdcc5f823}" -[ "$EFI_USE_ACPI" = "y" ] || EFI_USE_DTB=y - if [ ! -f "$EFI_UEFI" ]; then echo "UEFI firmware not found." echo "Please specify the path with the env variable EFI_UEFI" @@ -68,7 +66,7 @@ uefi_shell_run() mkdir -p "$EFI_CASE_DIR" cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_DIR/" echo "@echo -off" > "$EFI_CASE_DIR/startup.nsh" - if [ "$EFI_USE_DTB" = "y" ]; then + if [ "$EFI_USE_ACPI" != "y" ]; then qemu_args+=(-machine acpi=off) FDT_BASENAME="dtb" UEFI_SHELL_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_CASE_DIR/$FDT_BASENAME" "${qemu_args[@]}" From patchwork Fri Feb 23 15:51:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569310 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6160583A0F for ; Fri, 23 Feb 2024 15:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703539; cv=none; b=adyap6Rb8M1czrnus/cQY2OqUIuNWgBmpd+AgIgDqrjiQpdLuJnsvwEmXDXq+Z2VOfcAFuKuLnED03Zd/0UFqB2DHZqo04cVIi/NkawuyLJ1SHZuleTPSJuIhvHxO+kozUL41l+b4xS1OWH3fm1ciwBStLRPUEI1KoILSxBP0ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703539; c=relaxed/simple; bh=mXnxA8GpBHOStiU9ED8il/47Ba3BP3xeZUtQkc10dcQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=EUcRTz0FmrUqvvk9pMjMtBt8994fwle6LG70Yn6GErbtqOubzzxageuMCGroW88Kk2D8kpYbuU1syuA/FCuGToaKKh89pAXNCNq/sW8BQY8Zdr3k5eoNH41EfZV+7FXf4ei0Ir7GvOHLk80jxbs8Yul85dJNVaohTxBE4FQSYvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tIsZsxx1; arc=none smtp.client-ip=95.215.58.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tIsZsxx1" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dIhBoE+ztxgrIn9LX6XotPKIWxQt8o1cjxufO8kGC80=; b=tIsZsxx1YDpyhEv348ww4GOLdc/GMnYpTLb3ZZ6ydraBUG5cjzw5yBk5tgnIfU7ACM5WKb i5DwqE4vNJdW2suldTQ7DOikWBMhL8VIPbO1kzgyfuMZsazBJcbMvSmDtl/PuTLiswFQKT 1VTyMKYTj/MTCe2VTZ8m7LPWaNYIPQw= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 08/14] arm64: efi: Improve device tree discovery Date: Fri, 23 Feb 2024 16:51:34 +0100 Message-ID: <20240223155125.368512-24-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT Zero is a valid address for the device tree so add an fdt_valid data member to determine when the address is valid or not. Also, check the device tree GUID when the environment variable is missing. The latter change allows directly loading the unit test with QEMU's '-kernel' command line parameter, which is much faster than putting the test in the EFI file system and then running it from the UEFI shell. Signed-off-by: Andrew Jones --- lib/arm/setup.c | 3 ++- lib/efi.c | 28 +++++++++++++++++----------- lib/efi.h | 3 ++- lib/linux/efi.h | 2 ++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 0382cbdaf5a1..76aae4627a7b 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -342,7 +342,8 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) } memregions_add(&r); } - if (fdt) { + + if (efi_bootinfo->fdt_valid) { /* Move the FDT to the base of free memory */ fdt_size = fdt_totalsize(fdt); ret = fdt_move(fdt, (void *)free_mem_start, fdt_size); diff --git a/lib/efi.c b/lib/efi.c index d94f0fa16fc0..0785bd3e8916 100644 --- a/lib/efi.c +++ b/lib/efi.c @@ -6,13 +6,13 @@ * * SPDX-License-Identifier: LGPL-2.0-or-later */ - -#include "efi.h" +#include #include -#include #include -#include +#include #include +#include "efi.h" +#include "libfdt/libfdt.h" /* From lib/argv.c */ extern int __argc, __envc; @@ -283,18 +283,24 @@ static void* efi_get_var(efi_handle_t handle, struct efi_loaded_image_64 *image, return val; } -static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image) +static bool efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image, void **fdt) { efi_char16_t var[] = ENV_VARNAME_DTBFILE; efi_char16_t *val; - void *fdt = NULL; - int fdtsize; + int fdtsize = 0; + + *fdt = NULL; val = efi_get_var(handle, image, var); - if (val) - efi_load_image(handle, image, &fdt, &fdtsize, val); + if (val) { + efi_load_image(handle, image, fdt, &fdtsize, val); + if (fdtsize == 0) + return false; + } else if (efi_get_system_config_table(DEVICE_TREE_GUID, fdt) != EFI_SUCCESS) { + return false; + } - return fdt; + return fdt_check_header(*fdt) == 0; } efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) @@ -335,7 +341,7 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) } setup_args(cmdline_ptr); - efi_bootinfo.fdt = efi_get_fdt(handle, image); + efi_bootinfo.fdt_valid = efi_get_fdt(handle, image, &efi_bootinfo.fdt); /* Set up efi_bootinfo */ efi_bootinfo.mem_map.map = ↦ efi_bootinfo.mem_map.map_size = &map_size; diff --git a/lib/efi.h b/lib/efi.h index db46d45068ee..4bd01f7199ce 100644 --- a/lib/efi.h +++ b/lib/efi.h @@ -30,7 +30,8 @@ */ typedef struct { struct efi_boot_memmap mem_map; - const void *fdt; + void *fdt; + bool fdt_valid; } efi_bootinfo_t; efi_status_t _relocate(long ldbase, Elf64_Dyn *dyn, efi_handle_t handle, diff --git a/lib/linux/efi.h b/lib/linux/efi.h index 410f0b1a0da1..92d798f79767 100644 --- a/lib/linux/efi.h +++ b/lib/linux/efi.h @@ -66,6 +66,8 @@ typedef guid_t efi_guid_t; #define ACPI_TABLE_GUID EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) #define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81) +#define DEVICE_TREE_GUID EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0) + #define LOADED_IMAGE_PROTOCOL_GUID EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) typedef struct { From patchwork Fri Feb 23 15:51:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569311 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 888E283CD2 for ; Fri, 23 Feb 2024 15:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703541; cv=none; b=DkC51D0AK1ZirP9sky6QZq4TwmrTLX+INr55RVXDglFmxNCY3lZX3ljTMxntDLmz0my94oMZbgazApvLg43IgSqU+OcR+zdpgwZlvE4rw6k4UDPnxRuHnkXVcL9tZSlQ9btdz77BeMMfhqieKk+sRX+EbuBXQtg5pGSjZDprYgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703541; c=relaxed/simple; bh=xin4Ma602BK3JDlW/sBwEZSrxoI+t+Q1OLYq70BO+co=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=CGDK6IxXATggudvRgLo702+Jw50AAB8nNHmWbIPLsBheVIuWnp+50IUca5r+xUo8/5nueWnhkY2v5LK9zuTb1Xl5LEoLSUOojvzvYfScLAOFF2/nc6LJaTPggnowxSSgJudPZ0mBJCQ/M9aGUGxVWzNA5jTJi7scw6eEIVMhyis= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cZsHC+5A; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cZsHC+5A" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JqRuCfOS78D2tqOlNEUkzy1K+Rijz3OoIyyC33mXe98=; b=cZsHC+5AA3oqc01lWZODRP6dKn1sKe0MgW+tvB7hMTTLoaJqnwqt29CFyOMHUFwuHPeDQC ZbFuMHvKWKZizQMgr83TYRclNOVRhmr2DSdXLcFz3wUSBgTzeTD3jsV8gd6645ZHvojHTw DWK81irWNjjBnXlqYnkS9XGgor18BYM= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 09/14] lib/efi: Add support for loading the initrd Date: Fri, 23 Feb 2024 16:51:35 +0100 Message-ID: <20240223155125.368512-25-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT When loading non-efi tests with QEMU's '-kernel' option we also load an environ with the '-initrd' option. Now that efi tests can also be loaded with the '-kernel' option also provide the '-initrd' environ. For EFI, we use the EFI_LOAD_FILE2_PROTOCOL_GUID protocol to load LINUX_EFI_INITRD_MEDIA_GUID. Each architecture which wants to use the initrd for the environ will need to call setup_env() on the initrd data. As usual, the new efi function is heavily influenced by Linux's implementation. Signed-off-by: Andrew Jones --- lib/efi.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/linux/efi.h | 27 ++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/lib/efi.c b/lib/efi.c index 0785bd3e8916..edfcc80ef114 100644 --- a/lib/efi.c +++ b/lib/efi.c @@ -14,6 +14,10 @@ #include "efi.h" #include "libfdt/libfdt.h" +/* From each arch */ +extern char *initrd; +extern u32 initrd_size; + /* From lib/argv.c */ extern int __argc, __envc; extern char *__argv[100]; @@ -303,6 +307,65 @@ static bool efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image, return fdt_check_header(*fdt) == 0; } +static const struct { + struct efi_vendor_dev_path vendor; + struct efi_generic_dev_path end; +} __packed initrd_dev_path = { + { + { + EFI_DEV_MEDIA, + EFI_DEV_MEDIA_VENDOR, + sizeof(struct efi_vendor_dev_path), + }, + LINUX_EFI_INITRD_MEDIA_GUID + }, { + EFI_DEV_END_PATH, + EFI_DEV_END_ENTIRE, + sizeof(struct efi_generic_dev_path) + } +}; + +static void efi_load_initrd(void) +{ + efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID; + efi_device_path_protocol_t *dp; + efi_load_file2_protocol_t *lf2; + efi_handle_t handle; + efi_status_t status; + unsigned long file_size = 0; + + initrd = NULL; + initrd_size = 0; + + dp = (efi_device_path_protocol_t *)&initrd_dev_path; + status = efi_bs_call(locate_device_path, &lf2_proto_guid, &dp, &handle); + if (status != EFI_SUCCESS) + return; + + status = efi_bs_call(handle_protocol, handle, &lf2_proto_guid, (void **)&lf2); + assert(status == EFI_SUCCESS); + + status = efi_call_proto(lf2, load_file, dp, false, &file_size, NULL); + assert(status == EFI_BUFFER_TOO_SMALL); + + status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, file_size, (void **)&initrd); + assert(status == EFI_SUCCESS); + + status = efi_call_proto(lf2, load_file, dp, false, &file_size, (void *)initrd); + assert(status == EFI_SUCCESS); + + initrd_size = (u32)file_size; + + /* + * UEFI appends initrd=initrd to the command line when an initrd is present. + * Remove it in order to avoid confusing unit tests. + */ + if (!strcmp(__argv[__argc - 1], "initrd=initrd")) { + __argv[__argc - 1] = NULL; + __argc -= 1; + } +} + efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) { int ret; @@ -341,6 +404,8 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) } setup_args(cmdline_ptr); + efi_load_initrd(); + efi_bootinfo.fdt_valid = efi_get_fdt(handle, image, &efi_bootinfo.fdt); /* Set up efi_bootinfo */ efi_bootinfo.mem_map.map = ↦ diff --git a/lib/linux/efi.h b/lib/linux/efi.h index 92d798f79767..8fa23ad078ce 100644 --- a/lib/linux/efi.h +++ b/lib/linux/efi.h @@ -70,6 +70,9 @@ typedef guid_t efi_guid_t; #define LOADED_IMAGE_PROTOCOL_GUID EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) +#define EFI_LOAD_FILE2_PROTOCOL_GUID EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d) +#define LINUX_EFI_INITRD_MEDIA_GUID EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68) + typedef struct { efi_guid_t guid; void *table; @@ -248,6 +251,12 @@ struct efi_generic_dev_path { u16 length; } __packed; +struct efi_vendor_dev_path { + struct efi_generic_dev_path header; + efi_guid_t vendorguid; + u8 vendordata[]; +} __packed; + typedef struct efi_generic_dev_path efi_device_path_protocol_t; /* @@ -449,6 +458,19 @@ typedef struct _efi_simple_file_system_protocol efi_simple_file_system_protocol_ typedef struct _efi_file_protocol efi_file_protocol_t; typedef efi_simple_file_system_protocol_t efi_file_io_interface_t; typedef efi_file_protocol_t efi_file_t; +typedef union efi_load_file_protocol efi_load_file_protocol_t; +typedef union efi_load_file_protocol efi_load_file2_protocol_t; + +union efi_load_file_protocol { + struct { + efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *, + efi_device_path_protocol_t *, + bool, unsigned long *, void *); + }; + struct { + u32 load_file; + } mixed_mode; +}; typedef efi_status_t efi_simple_file_system_protocol_open_volume( efi_simple_file_system_protocol_t *this, @@ -544,7 +566,12 @@ typedef struct { efi_char16_t file_name[1]; } efi_file_info_t; +#define efi_fn_call(inst, func, ...) (inst)->func(__VA_ARGS__) #define efi_bs_call(func, ...) efi_system_table->boottime->func(__VA_ARGS__) #define efi_rs_call(func, ...) efi_system_table->runtime->func(__VA_ARGS__) +#define efi_call_proto(inst, func, ...) ({ \ + __typeof__(inst) __inst = (inst); \ + efi_fn_call(__inst, func, __inst, ##__VA_ARGS__); \ +}) #endif /* __LINUX_UEFI_H */ From patchwork Fri Feb 23 15:51:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569312 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F013B83CA7 for ; Fri, 23 Feb 2024 15:52:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703543; cv=none; b=ANy9dboW9g1HtzGmR/uDTLEZGdF4tV2vpLbubB17aWIH1Iio2biI1X+UT+IDQkqY5K3vcP9Z59cAryZ8sJ4PRg8xVoth/6yivaIpdwRS0Znj2mL6Ov9r0Ke3CVlkCHMZ4Kw3cWU03bPYlz3IMa3pRYk/MiWqCggRJWj06hJeb3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703543; c=relaxed/simple; bh=4LvUa2Wgz6FZhOGeW+doUnVPuZuAG43h3jiaaC3EotU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=RrEp+gXZn7LtvFulh7WVgbyWg83gD5Sd/ZFwZyShrED/z46iIFjIv/9FCS+cRxfuv7NiXrmkI/sizT7Q/E6odKY10E04+qIZugY3lD0YjlpzuyWo42LL4LseHzR3W3OoFWkdLsxM4cE3Nx2oBTO+85d7DrDSBeSxpufR8wulqWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Qr2symrO; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Qr2symrO" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H5FXdyIupFdjpkYcbqHBIRSta2xqkl0+hNZNYX2TJWw=; b=Qr2symrOzOCdu2cv9cMyIst3GdzqDWbfUTDXowrTHTED8kJxzBnrURnEKs1H4MJsApcPyd Wriv4uB6SUBF3kQGsss3MY4KBcg6ikAFna60T9FmMAzp0+TileBb0yEHXo5UR0Zl/7DZJz m+lalogmDUngOfMRWUTV6tjniAUytyA= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 10/14] arm64: efi: Allow running tests directly Date: Fri, 23 Feb 2024 16:51:36 +0100 Message-ID: <20240223155125.368512-26-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT Since it's possible to run tests with UEFI and the QEMU -kernel option (and now the DTB will be found and even the environ will be set up from an initrd if given with the -initrd option), then we can skip the loading of EFI tests into a file system and booting to the shell to run them. Just run them directly. Running directly is waaaaaay faster than booting the shell first. We keep the UEFI shell as the default behavior, though, and provide a new configure option to enable the direct running. Signed-off-by: Andrew Jones --- arm/efi/run | 17 +++++++++++++++-- arm/run | 4 +++- configure | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/arm/efi/run b/arm/efi/run index b7a8418a07f8..af7b593c2bb8 100755 --- a/arm/efi/run +++ b/arm/efi/run @@ -18,10 +18,12 @@ elif [ -f /usr/share/edk2/aarch64/QEMU_EFI.silent.fd ]; then DEFAULT_UEFI=/usr/share/edk2/aarch64/QEMU_EFI.silent.fd fi +KERNEL_NAME=$1 + : "${EFI_SRC:=$TEST_DIR}" : "${EFI_UEFI:=$DEFAULT_UEFI}" : "${EFI_TEST:=efi-tests}" -: "${EFI_CASE:=$(basename $1 .efi)}" +: "${EFI_CASE:=$(basename $KERNEL_NAME .efi)}" : "${EFI_TESTNAME:=$TESTNAME}" : "${EFI_TESTNAME:=$EFI_CASE}" : "${EFI_CASE_DIR:="$EFI_TEST/$EFI_TESTNAME"}" @@ -80,4 +82,15 @@ uefi_shell_run() "${qemu_args[@]}" } -uefi_shell_run +if [ "$EFI_DIRECT" = "y" ]; then + if [ "$EFI_USE_ACPI" != "y" ]; then + qemu_args+=(-machine acpi=off) + fi + $TEST_DIR/run \ + $KERNEL_NAME \ + -append "$(basename $KERNEL_NAME) ${cmd_args[@]}" \ + -bios "$EFI_UEFI" \ + "${qemu_args[@]}" +else + uefi_shell_run +fi diff --git a/arm/run b/arm/run index 40c2ca66ba7e..efdd44ce86a7 100755 --- a/arm/run +++ b/arm/run @@ -60,7 +60,7 @@ if ! $qemu $M -chardev '?' | grep -q testdev; then exit 2 fi -if [ "$UEFI_SHELL_RUN" != "y" ]; then +if [ "$UEFI_SHELL_RUN" != "y" ] && [ "$EFI_USE_ACPI" != "y" ]; then chr_testdev='-device virtio-serial-device' chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd' fi @@ -77,6 +77,8 @@ command="$(migration_cmd) $(timeout_cmd) $command" if [ "$UEFI_SHELL_RUN" = "y" ]; then ENVIRON_DEFAULT=n run_qemu_status $command "$@" +elif [ "$EFI_USE_ACPI" = "y" ]; then + run_qemu_status $command -kernel "$@" else run_qemu $command -kernel "$@" fi diff --git a/configure b/configure index 05e6702eab06..bf263b22b558 100755 --- a/configure +++ b/configure @@ -32,6 +32,7 @@ enable_dump=no page_size= earlycon= efi= +efi_direct= # Enable -Werror by default for git repositories only (i.e. developer builds) if [ -e "$srcdir"/.git ]; then @@ -89,6 +90,11 @@ usage() { --[enable|disable]-efi Boot and run from UEFI (disabled by default, x86_64 and arm64 only) --[enable|disable]-werror Select whether to compile with the -Werror compiler flag + --[enable|disable]-efi-direct + Select whether to run EFI tests directly with QEMU's -kernel + option. When not enabled, tests will be placed in an EFI file + system and run from the UEFI shell. Igorned when efi isn't enabled. + (arm64 only) EOF exit 1 } @@ -168,6 +174,12 @@ while [[ "$1" = -* ]]; do --disable-efi) efi=n ;; + --enable-efi-direct) + efi_direct=y + ;; + --disable-efi-direct) + efi_direct=n + ;; --enable-werror) werror=-Werror ;; @@ -185,6 +197,10 @@ while [[ "$1" = -* ]]; do esac done +if [ -z "$efi" ] || [ "$efi" = "n" ]; then + [ "$efi_direct" = "y" ] && efi_direct= +fi + if [ -n "$host_key_document" ] && [ ! -f "$host_key_document" ]; then echo "Host key document doesn't exist at the specified location." exit 1 @@ -423,6 +439,7 @@ GENPROTIMG=${GENPROTIMG-genprotimg} HOST_KEY_DOCUMENT=$host_key_document CONFIG_DUMP=$enable_dump CONFIG_EFI=$efi +EFI_DIRECT=$efi_direct CONFIG_WERROR=$werror GEN_SE_HEADER=$gen_se_header EOF From patchwork Fri Feb 23 15:51:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569313 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F92A839F1 for ; Fri, 23 Feb 2024 15:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703548; cv=none; b=fz5P31FAUB/iINPQBCqNV97+IycyOwpJBrWFqkHHZ/oDq1K4YHJx6osY1sa9Lg14alCmXyKdrET5kPt0YXmedexkZRNL7TdZ5AAXcp+lDD1Ke7pMy5teP/KxyIVQwE1MsGGXuRIboyxnII5wqAsqK5Ob6c53UYKtUub6VCPnWbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703548; c=relaxed/simple; bh=4sTNAa6MnoYrfkKq/iDV5maKOG8CDnDHXU6m+7P7+jE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=ZdII63yWzfnMS4gXo6H04zXAJEIFL/vVvvx9FiFuFVuI15BpNcVNMHL/aiw0WmmxAy8DZgdkflfkhT3iGi9TEyvIod3PUXcDrrgorI6fO1se3iY/Fytb1hJkdufUZ90az3m1AdgyV9o3OPNfq/weGuZU1/cmQcnqHvD3RTG0Da4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=JKHgzige; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JKHgzige" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pOyBAmSuH+i2SPph24jGVrUxKJ627tNATtbobG5uL1c=; b=JKHgzigeXyCLk+SyC3Jap0+8CQOZX+dvmELbpDVASmQACOdoxjmWQjmkMqGGWWzTjNAn+J VgbJ4KEoNegTdtSnM06Gg6S3ZfjBvptsKQRY43/6zClxQbe8Q7DGnd/mCurOyq6GIzdcNT 4I69h/tah2GHr6gkwFP2DBMyGwLs1DI= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 11/14] arm/arm64: Factor out some initial setup Date: Fri, 23 Feb 2024 16:51:37 +0100 Message-ID: <20240223155125.368512-27-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT Factor out some initial setup code into separate functions in order to share more code between setup() and setup_efi(). Signed-off-by: Andrew Jones --- lib/arm/setup.c | 81 ++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 76aae4627a7b..f96ee04ddd68 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -182,32 +182,57 @@ static void mem_init(phys_addr_t freemem_start) page_alloc_ops_enable(); } -void setup(const void *fdt, phys_addr_t freemem_start) +static void freemem_push_fdt(void **freemem, const void *fdt) { - void *freemem; - const char *bootargs, *tmp; u32 fdt_size; int ret; - assert(sizeof(long) == 8 || freemem_start < (3ul << 30)); - freemem = (void *)(unsigned long)freemem_start; - - /* Move the FDT to the base of free memory */ fdt_size = fdt_totalsize(fdt); - ret = fdt_move(fdt, freemem, fdt_size); + ret = fdt_move(fdt, *freemem, fdt_size); assert(ret == 0); - ret = dt_init(freemem); + ret = dt_init(*freemem); assert(ret == 0); - freemem += fdt_size; + *freemem += fdt_size; +} + +static void freemem_push_dt_initrd(void **freemem) +{ + const char *tmp; + int ret; - /* Move the initrd to the top of the FDT */ ret = dt_get_initrd(&tmp, &initrd_size); assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); if (ret == 0) { - initrd = freemem; + initrd = *freemem; memmove(initrd, tmp, initrd_size); - freemem += initrd_size; + *freemem += initrd_size; } +} + +static void initrd_setup(void) +{ + char *env; + + if (!initrd) + return; + + /* environ is currently the only file in the initrd */ + env = malloc(initrd_size); + memcpy(env, initrd, initrd_size); + setup_env(env, initrd_size); +} + +void setup(const void *fdt, phys_addr_t freemem_start) +{ + void *freemem; + const char *bootargs; + int ret; + + assert(sizeof(long) == 8 || freemem_start < (3ul << 30)); + freemem = (void *)(unsigned long)freemem_start; + + freemem_push_fdt(&freemem, fdt); + freemem_push_dt_initrd(&freemem); memregions_init(arm_mem_regions, NR_MEM_REGIONS); memregions_add_dt_regions(MAX_DT_MEM_REGIONS); @@ -229,12 +254,7 @@ void setup(const void *fdt, phys_addr_t freemem_start) assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); setup_args_progname(bootargs); - if (initrd) { - /* environ is currently the only file in the initrd */ - char *env = malloc(initrd_size); - memcpy(env, initrd, initrd_size); - setup_env(env, initrd_size); - } + initrd_setup(); if (!(auxinfo.flags & AUXINFO_MMU_OFF)) setup_vm(); @@ -277,7 +297,6 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) uintptr_t text = (uintptr_t)&_text, etext = ALIGN((uintptr_t)&_etext, 4096); uintptr_t data = (uintptr_t)&_data, edata = ALIGN((uintptr_t)&_edata, 4096); const void *fdt = efi_bootinfo->fdt; - int fdt_size, ret; /* * Record the largest free EFI_CONVENTIONAL_MEMORY region @@ -344,14 +363,13 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) } if (efi_bootinfo->fdt_valid) { - /* Move the FDT to the base of free memory */ - fdt_size = fdt_totalsize(fdt); - ret = fdt_move(fdt, (void *)free_mem_start, fdt_size); - assert(ret == 0); - ret = dt_init((void *)free_mem_start); - assert(ret == 0); - free_mem_start += ALIGN(fdt_size, EFI_PAGE_SIZE); - free_mem_pages -= ALIGN(fdt_size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT; + unsigned long old_start = free_mem_start; + void *freemem = (void *)free_mem_start; + + freemem_push_fdt(&freemem, fdt); + + free_mem_start = ALIGN((unsigned long)freemem, EFI_PAGE_SIZE); + free_mem_pages = (free_mem_start - old_start) >> EFI_PAGE_SHIFT; } __phys_end &= PHYS_MASK; @@ -419,13 +437,8 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo) io_init(); timer_save_state(); - if (initrd) { - /* environ is currently the only file in the initrd */ - char *env = malloc(initrd_size); - memcpy(env, initrd, initrd_size); - setup_env(env, initrd_size); - } + initrd_setup(); if (!(auxinfo.flags & AUXINFO_MMU_OFF)) setup_vm(); From patchwork Fri Feb 23 15:51:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569314 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0475E84FC6 for ; Fri, 23 Feb 2024 15:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703551; cv=none; b=mdukbZkZlB9u0zxe0Fuc3bI/4HQUaTjc0t0hS6zgOPRnrONVXlOQldrGQ+ZqfgxG3V6ywiin7HPFvG+8xAtY9z11oMumJr5B+RuHzHw0PQe65wGcRyr4ctzkrwQoDfAJGqstXUXKyXs21ZVqRidclugQzpVDuqw1QsAmH4KSFb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703551; c=relaxed/simple; bh=wpDhFfTN6nJKNBehoP3s6/g3ERYTTnU4O47Znkkop/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=JCQLVWHZrHbpnaw8tDbjtpjYjfJ1FecrDWldqICNYTQKgn4T7EZXmuDFgALx3WgI/SShfIqvyllBRwewtkH442RvK8bWjg74GlZi+8OEJaGPnLbiHJ7fw9tITXPTqy8V9yNZZu+ZoyiLb4zyBtDkJMo9FpgNRUiS9eXtwWiz1Tk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=KZVDuybP; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="KZVDuybP" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rYIHvI1GLAd4wT4WngttIKyGQENqRKMJxOIUlux1SQg=; b=KZVDuybPaLYI8cqhd1QFh+LAxp88DjjBEKA8QYeXq85QsU4l1WJ7U8UpcBaaN+23ZKgeGE 1K6vDCRpBs6DI0nli9AzZorQltIi1GdCa9hqzDEUIcLdAyTDDWoef88fitZGIOPj4Ol128 VhjCu3Z4IPMXqGWRXTqG+Xv99fRiKv8= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 12/14] arm/arm64: Factor out allocator init from mem_init Date: Fri, 23 Feb 2024 16:51:38 +0100 Message-ID: <20240223155125.368512-28-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT The allocator init is identical for mem_init() and efi_mem_init(). Share it. Signed-off-by: Andrew Jones --- lib/arm/setup.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/arm/setup.c b/lib/arm/setup.c index f96ee04ddd68..d0be4c437708 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -136,9 +136,28 @@ static void arm_memregions_add_assumed(void) #endif } -static void mem_init(phys_addr_t freemem_start) +static void mem_allocator_init(phys_addr_t freemem_start, phys_addr_t freemem_end) { phys_addr_t base, top; + + freemem_start = PAGE_ALIGN(freemem_start); + freemem_end &= PAGE_MASK; + + phys_alloc_init(freemem_start, freemem_end - freemem_start); + phys_alloc_set_minimum_alignment(SMP_CACHE_BYTES); + + phys_alloc_get_unused(&base, &top); + base = PAGE_ALIGN(base); + top &= PAGE_MASK; + assert(sizeof(long) == 8 || !(base >> 32)); + if (sizeof(long) != 8 && (top >> 32) != 0) + top = ((uint64_t)1 << 32); + page_alloc_init_area(0, base >> PAGE_SHIFT, top >> PAGE_SHIFT); + page_alloc_ops_enable(); +} + +static void mem_init(phys_addr_t freemem_start) +{ struct mem_region *freemem, *r, mem = { .start = (phys_addr_t)-1, }; @@ -169,17 +188,7 @@ static void mem_init(phys_addr_t freemem_start) __phys_offset = mem.start; /* PHYS_OFFSET */ __phys_end = mem.end; /* PHYS_END */ - phys_alloc_init(freemem_start, freemem->end - freemem_start); - phys_alloc_set_minimum_alignment(SMP_CACHE_BYTES); - - phys_alloc_get_unused(&base, &top); - base = PAGE_ALIGN(base); - top = top & PAGE_MASK; - assert(sizeof(long) == 8 || !(base >> 32)); - if (sizeof(long) != 8 && (top >> 32) != 0) - top = ((uint64_t)1 << 32); - page_alloc_init_area(0, base >> PAGE_SHIFT, top >> PAGE_SHIFT); - page_alloc_ops_enable(); + mem_allocator_init(freemem_start, freemem->end); } static void freemem_push_fdt(void **freemem, const void *fdt) @@ -292,7 +301,6 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) struct efi_boot_memmap *map = &(efi_bootinfo->mem_map); efi_memory_desc_t *buffer = *map->map; efi_memory_desc_t *d = NULL; - phys_addr_t base, top; struct mem_region r; uintptr_t text = (uintptr_t)&_text, etext = ALIGN((uintptr_t)&_etext, 4096); uintptr_t data = (uintptr_t)&_data, edata = ALIGN((uintptr_t)&_edata, 4096); @@ -380,17 +388,7 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) assert(sizeof(long) == 8 || free_mem_start < (3ul << 30)); - phys_alloc_init(free_mem_start, free_mem_pages << EFI_PAGE_SHIFT); - phys_alloc_set_minimum_alignment(SMP_CACHE_BYTES); - - phys_alloc_get_unused(&base, &top); - base = PAGE_ALIGN(base); - top = top & PAGE_MASK; - assert(sizeof(long) == 8 || !(base >> 32)); - if (sizeof(long) != 8 && (top >> 32) != 0) - top = ((uint64_t)1 << 32); - page_alloc_init_area(0, base >> PAGE_SHIFT, top >> PAGE_SHIFT); - page_alloc_ops_enable(); + mem_allocator_init(free_mem_start, free_mem_start + (free_mem_pages << EFI_PAGE_SHIFT)); return EFI_SUCCESS; } From patchwork Fri Feb 23 15:51:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569315 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BB7485647 for ; Fri, 23 Feb 2024 15:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703554; cv=none; b=Skw3yZnxBqxHc3kIJ41qed42tdeHktGWa3msol9u4FNhz5zsoCDlnQ1Qox08KCnV+ct5vLE6UNaQ/MWZjYZnCxhPBxRO4+/heE3Z3asHjA/IRAm+m5pGqT1Z/xOPGMPTCheugdKMQfdTC/iaEKJl6vpF/OdYnsXx3sZ2Rg3Dc7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703554; c=relaxed/simple; bh=MTPlTatfIghDuZ553cISvbEgjkp8435gVtWr1e6Hliw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=gFCP7+8EgSQPAjUdlwvbCjP/DueiMP5agK5uTeNTL5lN7uuPlahwf6Dyt1qhD2vTfULaEf+efLpA8SZJtqBzAQlCTOE4qLIPxcr8JkBuBG0N897Wgw5oauXbgM01iWkcJjvWDFkMhLNt+eOkNc5y1AN8bqs+k29D0rQYacEJTEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=eG5Q7r5Y; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="eG5Q7r5Y" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PBD1ohiKpXGdC4CTOzC92NNH+OTPx9G6EKUZO37Av4c=; b=eG5Q7r5YCAIHScpVm7u5cj47/Z0QP+BmfBAv5FsA/5B/Uf6JgHupdwCrnIC5pm9xU6V5aa VW45ixCt/RZkZipEL3SvEW9ajODpCDzAIaKxNbldHm5vfvEgINy5YTcEOtOI/6wee57cbS T9V2gP2i4tWIERz0Elf52GVLSsIScu0= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 13/14] arm64: Simplify efi_mem_init Date: Fri, 23 Feb 2024 16:51:39 +0100 Message-ID: <20240223155125.368512-29-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT Reduce the EFI mem_map loop to only setting flags and finding the largest free memory region. Then, apply memregions_split() for the code/data region split and do the rest of the things that used to be done in the EFI mem_map loop in a separate mem_region loop. Signed-off-by: Andrew Jones --- lib/arm/setup.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/arm/setup.c b/lib/arm/setup.c index d0be4c437708..631597b343f1 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -301,9 +301,7 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) struct efi_boot_memmap *map = &(efi_bootinfo->mem_map); efi_memory_desc_t *buffer = *map->map; efi_memory_desc_t *d = NULL; - struct mem_region r; - uintptr_t text = (uintptr_t)&_text, etext = ALIGN((uintptr_t)&_etext, 4096); - uintptr_t data = (uintptr_t)&_data, edata = ALIGN((uintptr_t)&_edata, 4096); + struct mem_region r, *code, *data; const void *fdt = efi_bootinfo->fdt; /* @@ -337,21 +335,7 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) r.flags = MR_F_IO; break; case EFI_LOADER_CODE: - if (r.start <= text && r.end > text) { - /* This is the unit test region. Flag the code separately. */ - phys_addr_t tmp = r.end; - - assert(etext <= data); - assert(edata <= r.end); - r.flags = MR_F_CODE; - r.end = data; - memregions_add(&r); - r.start = data; - r.end = tmp; - r.flags = 0; - } else { - r.flags = MR_F_RESERVED; - } + r.flags = MR_F_CODE; break; case EFI_CONVENTIONAL_MEMORY: if (free_mem_pages < d->num_pages) { @@ -361,15 +345,27 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) break; } - if (!(r.flags & MR_F_IO)) { - if (r.start < __phys_offset) - __phys_offset = r.start; - if (r.end > __phys_end) - __phys_end = r.end; - } memregions_add(&r); } + memregions_split((unsigned long)&_etext, &code, &data); + assert(code && (code->flags & MR_F_CODE)); + if (data) + data->flags &= ~MR_F_CODE; + + for (struct mem_region *m = mem_regions; m->end; ++m) { + if (m != code && (m->flags & MR_F_CODE)) + m->flags = MR_F_RESERVED; + + if (!(m->flags & MR_F_IO)) { + if (m->start < __phys_offset) + __phys_offset = m->start; + if (m->end > __phys_end) + __phys_end = m->end; + } + } + __phys_end &= PHYS_MASK; + if (efi_bootinfo->fdt_valid) { unsigned long old_start = free_mem_start; void *freemem = (void *)free_mem_start; @@ -380,7 +376,6 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) free_mem_pages = (free_mem_start - old_start) >> EFI_PAGE_SHIFT; } - __phys_end &= PHYS_MASK; asm_mmu_disable(); if (free_mem_pages == 0) From patchwork Fri Feb 23 15:51:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13569316 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5C7582C7E for ; Fri, 23 Feb 2024 15:52:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703560; cv=none; b=EXyFV6CrkmFCZpsCNyWjJ0JA06ehAVNygyw09pSk6ibypVitlocFEVElr1/d59n87tc2oo5ygL6cLEUNebVYY+r7Ry5RA+DONWrR4XGHC7T1fCO1MO/JYfaS//4oNy7l6y/09fe+sU/kSJYfpLqj/ks5OohAqzXYBtGwBy0JUkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703560; c=relaxed/simple; bh=5jLTrsvHP15/Wz1GlFMWRvMxJYOArtuWBJDxqVfFJD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Pyn8sExB9xn5O2QHjCoimRZhHpnfbJGZ+jeVKHg/2t7Ar3X2KlQJ0Y8SpP2L/CQq/NYajx32bZxSw4b3x1TxxX+YCGEg+MeP7T0I/w1JYHv4wCV3x3TLeKzk7O7i0++UampXZVy/EnphbYbtvhC/PGc1ZcjJZBszpKz3ZTwe8S8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NSf5eY60; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NSf5eY60" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708703557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=prhJrEEyjZ+UcC+HrmtwYVmqBHKB1vxR1mBsPDD9RRo=; b=NSf5eY60KifFl5AMvfSAQlclI1n9EomXof33qovka5R/kMVsqB54mOpRH5pWfV+2SH7bBm kxPLQD83FzeRbbp6IXb6tB6v+/wnwQDQrjtGssUToNwkfFWrugOPIIS5njSkmPCAit/ZAg FGWa8ROjT8ARLFftmcR0PQKH8EX9IC4= From: Andrew Jones To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: alexandru.elisei@arm.com, eric.auger@redhat.com, nikos.nikoleris@arm.com, shahuang@redhat.com, pbonzini@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH 14/14] arm64: Add memregions_efi_init Date: Fri, 23 Feb 2024 16:51:40 +0100 Message-ID: <20240223155125.368512-30-andrew.jones@linux.dev> In-Reply-To: <20240223155125.368512-16-andrew.jones@linux.dev> References: <20240223155125.368512-16-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Migadu-Flow: FLOW_OUT Provide a memregions function which initialized memregions from an EFI memory map. The function also points out the largest conventional memory region by returning a pointer to it in the freemem parameter. Immediately apply this function to arm64's efi_mem_init(). riscv will make use of it as well. Signed-off-by: Andrew Jones --- lib/arm/setup.c | 76 ++++++++---------------------------------------- lib/memregions.c | 57 ++++++++++++++++++++++++++++++++++++ lib/memregions.h | 5 ++++ 3 files changed, 74 insertions(+), 64 deletions(-) diff --git a/lib/arm/setup.c b/lib/arm/setup.c index 631597b343f1..521928186fb0 100644 --- a/lib/arm/setup.c +++ b/lib/arm/setup.c @@ -295,58 +295,13 @@ static efi_status_t setup_rsdp(efi_bootinfo_t *efi_bootinfo) static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) { - int i; - unsigned long free_mem_pages = 0; - unsigned long free_mem_start = 0; - struct efi_boot_memmap *map = &(efi_bootinfo->mem_map); - efi_memory_desc_t *buffer = *map->map; - efi_memory_desc_t *d = NULL; - struct mem_region r, *code, *data; - const void *fdt = efi_bootinfo->fdt; - - /* - * Record the largest free EFI_CONVENTIONAL_MEMORY region - * which will be used to set up the memory allocator, so that - * the memory allocator can work in the largest free - * continuous memory region. - */ - for (i = 0; i < *(map->map_size); i += *(map->desc_size)) { - d = (efi_memory_desc_t *)(&((u8 *)buffer)[i]); - - r.start = d->phys_addr; - r.end = d->phys_addr + d->num_pages * EFI_PAGE_SIZE; - r.flags = 0; - - switch (d->type) { - case EFI_RESERVED_TYPE: - case EFI_LOADER_DATA: - case EFI_BOOT_SERVICES_CODE: - case EFI_BOOT_SERVICES_DATA: - case EFI_RUNTIME_SERVICES_CODE: - case EFI_RUNTIME_SERVICES_DATA: - case EFI_UNUSABLE_MEMORY: - case EFI_ACPI_RECLAIM_MEMORY: - case EFI_ACPI_MEMORY_NVS: - case EFI_PAL_CODE: - r.flags = MR_F_RESERVED; - break; - case EFI_MEMORY_MAPPED_IO: - case EFI_MEMORY_MAPPED_IO_PORT_SPACE: - r.flags = MR_F_IO; - break; - case EFI_LOADER_CODE: - r.flags = MR_F_CODE; - break; - case EFI_CONVENTIONAL_MEMORY: - if (free_mem_pages < d->num_pages) { - free_mem_pages = d->num_pages; - free_mem_start = d->phys_addr; - } - break; - } + struct mem_region *freemem_mr = NULL, *code, *data; + phys_addr_t freemem_start; + void *freemem; - memregions_add(&r); - } + memregions_efi_init(&efi_bootinfo->mem_map, &freemem_mr); + if (!freemem_mr) + return EFI_OUT_OF_RESOURCES; memregions_split((unsigned long)&_etext, &code, &data); assert(code && (code->flags & MR_F_CODE)); @@ -366,24 +321,17 @@ static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo) } __phys_end &= PHYS_MASK; - if (efi_bootinfo->fdt_valid) { - unsigned long old_start = free_mem_start; - void *freemem = (void *)free_mem_start; + freemem = (void *)PAGE_ALIGN(freemem_mr->start); - freemem_push_fdt(&freemem, fdt); + if (efi_bootinfo->fdt_valid) + freemem_push_fdt(&freemem, efi_bootinfo->fdt); - free_mem_start = ALIGN((unsigned long)freemem, EFI_PAGE_SIZE); - free_mem_pages = (free_mem_start - old_start) >> EFI_PAGE_SHIFT; - } + freemem_start = PAGE_ALIGN((unsigned long)freemem); + assert(sizeof(long) == 8 || freemem_start < (3ul << 30)); asm_mmu_disable(); - if (free_mem_pages == 0) - return EFI_OUT_OF_RESOURCES; - - assert(sizeof(long) == 8 || free_mem_start < (3ul << 30)); - - mem_allocator_init(free_mem_start, free_mem_start + (free_mem_pages << EFI_PAGE_SHIFT)); + mem_allocator_init(freemem_start, freemem_mr->end); return EFI_SUCCESS; } diff --git a/lib/memregions.c b/lib/memregions.c index 96de86b27333..23c366c0f77d 100644 --- a/lib/memregions.c +++ b/lib/memregions.c @@ -80,3 +80,60 @@ void memregions_add_dt_regions(size_t max_nr) }); } } + +#ifdef CONFIG_EFI +/* + * Add memory regions based on the EFI memory map. Also set a pointer to the + * memory region which corresponds to the largest EFI_CONVENTIONAL_MEMORY + * region, as that region is the largest free, continuous region, making it + * a good choice for the memory allocator. + */ +void memregions_efi_init(struct efi_boot_memmap *mem_map, + struct mem_region **freemem) +{ + u8 *buffer = (u8 *)*mem_map->map; + u64 freemem_pages = 0; + + *freemem = NULL; + + for (int i = 0; i < *mem_map->map_size; i += *mem_map->desc_size) { + efi_memory_desc_t *d = (efi_memory_desc_t *)&buffer[i]; + struct mem_region r = { + .start = d->phys_addr, + .end = d->phys_addr + d->num_pages * EFI_PAGE_SIZE, + .flags = 0, + }; + + switch (d->type) { + case EFI_RESERVED_TYPE: + case EFI_LOADER_DATA: + case EFI_BOOT_SERVICES_CODE: + case EFI_BOOT_SERVICES_DATA: + case EFI_RUNTIME_SERVICES_CODE: + case EFI_RUNTIME_SERVICES_DATA: + case EFI_UNUSABLE_MEMORY: + case EFI_ACPI_RECLAIM_MEMORY: + case EFI_ACPI_MEMORY_NVS: + case EFI_PAL_CODE: + r.flags = MR_F_RESERVED; + break; + case EFI_MEMORY_MAPPED_IO: + case EFI_MEMORY_MAPPED_IO_PORT_SPACE: + r.flags = MR_F_IO; + break; + case EFI_LOADER_CODE: + r.flags = MR_F_CODE; + break; + case EFI_CONVENTIONAL_MEMORY: + if (freemem_pages < d->num_pages) { + freemem_pages = d->num_pages; + *freemem = memregions_add(&r); + continue; + } + break; + } + + memregions_add(&r); + } +} +#endif /* CONFIG_EFI */ diff --git a/lib/memregions.h b/lib/memregions.h index 9a8e33182fe5..dc42bb66cc3e 100644 --- a/lib/memregions.h +++ b/lib/memregions.h @@ -26,4 +26,9 @@ uint32_t memregions_get_flags(phys_addr_t paddr); void memregions_split(phys_addr_t addr, struct mem_region **r1, struct mem_region **r2); void memregions_add_dt_regions(size_t max_nr); +#ifdef CONFIG_EFI +#include +void memregions_efi_init(struct efi_boot_memmap *mem_map, struct mem_region **freemem); +#endif + #endif /* _MEMREGIONS_H_ */