From patchwork Wed Jun 12 05:23: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: 13694426 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1309C15BB for ; Wed, 12 Jun 2024 05:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169816; cv=none; b=MYth9+Rp0Z6s8l6bnajMu5AyIB+EDZHMesLM7bdG153ZW414/OMZB50IS5V/WhVi/ny3x4plwKEjEpUIy+JNOVkP/CZzfa8nWudE8L4nvytbW7bVBOGeOY8IRE4cf4J/wGBUUuyHVg2vbaEYsvZKVdjsFzWtnKj2Fh3D9Z/Qink= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169816; c=relaxed/simple; bh=izqDl4kXsZEuJhy3PRwmpOV9WGA9iKHbBfjl4oEXfZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V0f7dZKjTGtAi4URMh0isNZPZdIyyzcwcoVc/ehnoW/Jh0e1KuwwO+9TNKFkywJkfscJlG457gG0wSM66+Z3tO9Y/WVzUB6SmOe1+bp8E9LTLoOT7ckUyTttKt7SqOAqjHnP23Ut/ldOszxNJ1oji/eU0Ad7vImemWDlLZhyktU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TZo77Jad; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TZo77Jad" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-6e41550ae5bso3430928a12.3 for ; Tue, 11 Jun 2024 22:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169814; x=1718774614; darn=vger.kernel.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=3LYx9pWe+IXQn9iXJjFIm9X9Ha+gW+XiixBi0YYKAco=; b=TZo77JadVft9ZwMj0eFgiXZljPwmJYZ/hGE65prn8rC65PxG4IXN5YWoBvpktKJ/T/ UZvMBnyTqtADrHnTN5WE1cd8GboRHWN2fLFtInLXrEv1v/h6uJ5iqpkhqiBRJmKtZxLz QEbYR09hBWxgI+IZkgp8ihka41Q2knzXDYj/r7FtBVm+cZWnPqCoVwOKaz+eMgP5mkPo wuPQH1cqb1OGqZTxxmDxuzij5WVQOTk/zngv/OsbuLb1n0X03MmZ9gN36oH69DRYGtAe 7R6Elu1kyb+7RauKJU5/dEtJqkwEDu/BBNXxm4yG375NPV4HmXDnZoo/sCEdh5+Mj6dy Gn0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169814; x=1718774614; 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=3LYx9pWe+IXQn9iXJjFIm9X9Ha+gW+XiixBi0YYKAco=; b=ROoBLivbjQXyahBAUuidpPhVL5MZLPxr29pjDTuR8KCOaUPFEGw0xD9sJmIMTPnrKe 5kh3RoFknj15pEY86kbjGR10mFlli/zyqCMFRI2NH3Z+mh/LGhq3cK15IoNkcEAVu5pp a09hipiAeVDYoTEkwtGZe2dDt7AqQLK3RSwrn/YZlAIX2ZyaliF561+WRiDPxposgmFH 8ZhY5gzT1EaYZNlSmT1N+4kXNIcxH1ZrWtFjVCWZWt+0SNKQRT2DDxQoB49x6os5AkK9 AFHNWUwFglD99h1BoA9LrtMfQtBoivcumPlfFHMABsTqjXWNUDHnpbHYC7SBTmMnxb0N vQyg== X-Forwarded-Encrypted: i=1; AJvYcCU+7bSkXEDL5D3O94bORP7CVenRptendqN3GWjHWI5mSWjeKfFdn/bHgCdKQhCMmfzWqo6q+IZN6vVQk2DSqrcD+Zyl X-Gm-Message-State: AOJu0YwPcl1M7G3qKXzCI/VoYuZYWsNTgUEy6gcwkhk4BJ+NfR6i2SeQ BBUGhInj7bSyID8EVuLhxefiIrDakSnCfpPkrDCK8t9Wkhez47ez X-Google-Smtp-Source: AGHT+IFKLAKOMwGgrW3gptnRK9NG8WToNY0soeikvGZ3tFM78QRkaQ5c6Eratbtmd2B75aByNiO65g== X-Received: by 2002:a05:6a20:8402:b0:1b5:8d94:907a with SMTP id adf61e73a8af0-1b8a9b9e15amr986922637.14.1718169814157; Tue, 11 Jun 2024 22:23:34 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:33 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 01/15] powerpc: Add facility to query TCG or KVM host Date: Wed, 12 Jun 2024 15:23:06 +1000 Message-ID: <20240612052322.218726-2-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use device tree properties to determine whether KVM or TCG is in use. Logically these are not the inverse of one another, because KVM can run on a TCG processor (if TCG is emulating HV mode, or it is using the nested hypervisor APIs in pseries / spapr). And kvm-unit-tests can run on that KVM. This can be a problem because some issues relate to TCG CPU emulation some to the spapr hypervisor implementation, some to KVM, some to real hardware, so the TCG test is best-effort for now and is set to the opposite of KVM. The two independent variables are added because we may be able to more accurately determine this in future. Use this facility to restrict some of the known test failures to TCG. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 3 +++ lib/powerpc/setup.c | 26 ++++++++++++++++++++++++++ powerpc/interrupts.c | 6 ++++-- powerpc/sprs.c | 2 +- powerpc/tm.c | 2 +- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index a3859b5d4..a660344cb 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -10,6 +10,9 @@ void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *); void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ +extern bool host_is_tcg; +extern bool host_is_kvm; + extern bool cpu_has_hv; extern bool cpu_has_power_mce; extern bool cpu_has_siar; diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 622b99e5d..86e2e144c 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -208,6 +208,9 @@ void cpu_init(struct cpu *cpu, int cpu_id) cpu->exception_stack += SZ_64K - 64; } +bool host_is_tcg; +bool host_is_kvm; + void setup(const void *fdt) { void *freemem = &stacktop; @@ -259,6 +262,29 @@ void setup(const void *fdt) assert(ret == 0); freemem += fdt_size; + if (!fdt_node_check_compatible(fdt, 0, "qemu,pseries")) { + assert(!cpu_has_hv); + + /* + * host_is_tcg incorrectly does not get set when running + * KVM on a TCG host (using powernv HV emulation or spapr + * nested HV). + */ + ret = fdt_subnode_offset(fdt, 0, "hypervisor"); + if (ret < 0) { + host_is_tcg = true; + host_is_kvm = false; + } else { + /* KVM is the only supported hypervisor */ + assert(!fdt_node_check_compatible(fdt, ret, "linux,kvm")); + host_is_tcg = false; + host_is_kvm = true; + } + } else { + assert(cpu_has_hv); + host_is_tcg = true; + host_is_kvm = false; + } ret = dt_get_initrd(&tmp, &initrd_size); assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); if (ret == 0) { diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c index 552c48ef2..3e3622e59 100644 --- a/powerpc/interrupts.c +++ b/powerpc/interrupts.c @@ -72,7 +72,8 @@ 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"); + /* KVM does not MCE on access outside partition scope */ + report_kfail(host_is_kvm, 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) @@ -82,7 +83,8 @@ static void test_mce(void) is_fetch = true; asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); - report(got_interrupt, "MCE on fetch from invalid real address"); + /* KVM does not MCE on access outside partition scope */ + report_kfail(host_is_kvm, 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) diff --git a/powerpc/sprs.c b/powerpc/sprs.c index a85011ad5..dc810b8da 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -590,7 +590,7 @@ int main(int argc, char **argv) if (sprs[i].width == 32 && !(before[i] >> 32) && !(after[i] >> 32)) { /* known failure KVM migration of CTRL */ - report_kfail(i == 136, pass, + report_kfail(host_is_kvm && i == 136, pass, "%-10s(%4d):\t 0x%08lx <==> 0x%08lx", sprs[i].name, i, before[i], after[i]); diff --git a/powerpc/tm.c b/powerpc/tm.c index 507eaf492..d4f436147 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -135,7 +135,7 @@ int main(int argc, char **argv) } /* kvm-unit-tests can limit number of CPUs present */ /* KVM does not report TM in secondary threads in POWER9 */ - report_kfail(true, cpus_with_tm >= nr_cpus_present, + report_kfail(host_is_kvm, cpus_with_tm >= nr_cpus_present, "TM available in all 'ibm,pa-features' properties"); all = argc == 1 || !strcmp(argv[1], "all"); From patchwork Wed Jun 12 05:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13694427 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D287B381D1 for ; Wed, 12 Jun 2024 05:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169820; cv=none; b=VSFghVtQ9mqmBBbO0rRJ6Pkd0lY47qhqWx6amWUAQsczE50jn8QXZ3gbVPJ0nhGW56uTgZ7KjxU3Qz+AZd55xTghxSRzzHxW+z2XmaUOcGURCswQ90sULYCTaQX31EreUmLQrtb3RcmKpxaLgZvx8nJoHhtyUFLoGnkLMjZJldg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169820; c=relaxed/simple; bh=+ScCurVEWUKotJeooFkjjvzfCuuU2ogVvfsP+wsN+w0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GziWpHw6BIDeAL6zHCWI8sGTZdO1z8mLCvTz9e7wBwg9DP2MXcReBKNWgRZKBqWQkScplDndSWyrT8xyeZ/q980nY4hs889cwtxytAmZWOCSLmmJ3Zev7zXHLrhlk+9KR2MRTANixBYBG6nzZ10ld9Q5lfYpCGVNBqJ2RO3wOX4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lQwl4idk; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lQwl4idk" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f70131063cso15954985ad.2 for ; Tue, 11 Jun 2024 22:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169818; x=1718774618; darn=vger.kernel.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=P6o6vcMPhrMsQvHR0Sulq6bI+NxqfPhtmmQVrS2XJ3c=; b=lQwl4idkhEezbV01rFxypUcarkZ81Jp4wYV0LievfDUEn5fNAsBCexGAz/ki1Xb6Ej K/yRxvfBAcFy/qjVJ4O51sA735MsEN1+87an29v1p0hxy2368q6Iy4J0JRPHxtEgLeIN PtaxI/DlgU9lGutf5goccg0k3ZkhycRHJpKMeUhIeW8Z9eP7AebxSpRicX2ZreTNblCZ 0o5YOwOpkEzcpRbrwrh/TB0p+dzCUzukYY7EiNDgpoX3lGsgvG/I5tJWEKi0oQ+NlMQO iJGJGKbFgBYH1BJrEovBoZQROmaoKrftAuxzeTSwnmoxo5qw/h4lIMaJsjfcsT+OZYDS M+/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169818; x=1718774618; 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=P6o6vcMPhrMsQvHR0Sulq6bI+NxqfPhtmmQVrS2XJ3c=; b=SlvSAPDhiy28pTOg5PchJX1zuiNn67zt+Dnd3rImo1hHxYU9yANgj5kybKKQbndBWs 1Ak8Qx2gkkFnbYwT1jvQM4wOBebcHLGI/ksusp2ZVs48oEBV95VocMXhN10OY37PVK57 xQulBMSdQ3YtWjWcfcizCqD/lUUE2woKjfX5auq7h+s+7SGjmgCkp8YbUH/0ck7iCUli iqXGY0vn1pqohRtYx1f7fYvn36iXN/17/8sHKibrfA8/0ajBFyrKQBztG7vukOiz0C4R nDz8i+LyYJeCdf6TfA7AUiUTZdleW5DWY6n48GObD5CNH1bqJjP7XzlFgFiyDBSffyb/ rVvQ== X-Forwarded-Encrypted: i=1; AJvYcCUiCxcFUr33j5FC7drtRQPDWhGYt/vQLd4It8/eIHNV1FRP7nUSK6XstI30Vc5vQTW/WI5bzAnqWGdfmWYjNgA2e0BG X-Gm-Message-State: AOJu0Yx3wEdMQPp06A4fsN0HPPJSHK2jSIhQjSmLpkho5MaTm5rYIIrj uMGQtzdC+3ZY8VtXCk/zuUJ/cmz8NGYyhvlhHtrK6KFlhGnUB05Q X-Google-Smtp-Source: AGHT+IG5VgiIxFWxzOA75TpFCafQj3g9NocE+hXCOTXILYOOMpRJ+OKI0SRDda6pn31WxBLaFGBXiA== X-Received: by 2002:a17:902:654e:b0:1f7:1a9:bf0c with SMTP id d9443c01a7336-1f83b713856mr7027815ad.52.1718169817948; Tue, 11 Jun 2024 22:23:37 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:37 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 02/15] powerpc: Add atomics tests Date: Wed, 12 Jun 2024 15:23:07 +1000 Message-ID: <20240612052322.218726-3-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add some tests for larx/stcx. operations for certain edge cases including migration, as well as some simple performance tests. Signed-off-by: Nicholas Piggin --- powerpc/Makefile.common | 1 + powerpc/atomics.c | 386 ++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 10 ++ 3 files changed, 397 insertions(+) create mode 100644 powerpc/atomics.c diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 16f14577e..b52037c0d 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..abbfff4b4 --- /dev/null +++ b/powerpc/atomics.c @@ -0,0 +1,386 @@ +// SPDX-License-Identifier: GPL-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"); + /* + * An unaligned larx/stcx. is not required by the ISA to cause an + * exception, and in TCG the stcx does not though it does on POWER CPUs. + */ + report_kfail(host_is_tcg, 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 5c458996b..407090ac4 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -83,6 +83,16 @@ file = smp.elf smp = 8,threads=4 accel = tcg,thread=single +[atomics] +file = atomics.elf +smp = 2 + +[atomics-migration] +file = atomics.elf +machine = pseries +extra_params = -append "migration -m" +groups = migration + [h_cede_tm] file = tm.elf machine = pseries From patchwork Wed Jun 12 05:23: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: 13694428 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6955938FB6 for ; Wed, 12 Jun 2024 05:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169824; cv=none; b=NifWnoxs7n2wKjfjAzj/4lYpQ2H9gyUl2i6Ql071WePd6NP7fDe3IGGeFdDGKtMTvYLiCh+/LviV5ChPg/VT8pSpXVdGubaqUyrQU3BBiU4CIfTDvu0X9xAd2MonIyV6s7wfZQK3OCXQ+cAddIOUjUqoFGsc8sawE9kiISEnlFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169824; c=relaxed/simple; bh=yqWAXhfaSK2mAxRgZqbrvnM4/uXm4ki/juOnOEftRNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cHzkXd2IUB2XUuZwCC4R8M21LaIsVUVwX+VWCwKDsWdwpgY8GbgoQTCBF9pyxRSPdueSBXjwEAoWnACHF1daCtk1RqWB/mDEB33KZDlDBK4ib1aPd6Mv2X/mXCjE97g2XMquF72VU2EUFk7EsOoxn9hg2GhGHF5/ohlFMZoCrxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PAEXXF/d; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PAEXXF/d" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f44b5b9de6so50859805ad.3 for ; Tue, 11 Jun 2024 22:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169822; x=1718774622; darn=vger.kernel.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=haAk4/M1J9JDArGrPClDIKuuC6VQG/d2q4r8JMhKYn8=; b=PAEXXF/d+Zkf01sou1PRJAd/1qiKPoKIibhJQE3xhTGPo9GIyeqkFJl+L/B8sWqniP q1qlzMGrwvr/fOxVaO6x3Zw68BiG9BPciGWvp5aqigBOQ1r33MKorp1cn7wyKdhRdcCj BmOBBe6DXMZ3E2JH1XE/B+BVxMBHthAQ0wsfqurQAIyXst8lfVHySAmvh6r81bCYUoWs hdmbCe0UGJfyP37gXqP/rdR81tmZWRBYY4qM2QA0FmLvsqjrTNZc8jvfP9bh3kB3YH4l +41pobAw/Qa4pRuxBspn+F5SQ6oDR7a85igfiRjE2WoAGKD6ubmBoCh0wvRVGDjfDpLi X+Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169822; x=1718774622; 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=haAk4/M1J9JDArGrPClDIKuuC6VQG/d2q4r8JMhKYn8=; b=LiqOFZARORK4F56xXljDrxbT6ATzM5StSjMcTArhEe6cUdk14hCxHVs1kiEpGazbfp 7UNlTtNqlNN7QEix9Xs3Q4CD1/fYIvXQOR5D11JXDwsRhdJ0g1A+Rpaw9XtOZ7X/Xsvu 4jDdm4R+2Jl5iiv9hx4GPN9Rntu1f57jO2fZnxBXkNeGl1PYpDK4CfVmr7jAmrxlFBvN ekWkvmA7gzfYtRtXeE7zUboelkNy6Pk9TP79Pl/4MFuHG6PKuxVOyvop0mLUPlMlkMfV 1s/alH/4k1RuaBMnd3akMaRHz4wCUb/s0caAHMibO1o/Bv89Qf171pcVCWGfmRwmL+tH nRjg== X-Forwarded-Encrypted: i=1; AJvYcCWXSiA0mw2WkVzznExkNO4rXOLAhvu+Nnr/1TmWyfmh+Vseko1pfdtHoQPz6W1ZgImFWy/hDc/PRpleLNYoaNQENEC/ X-Gm-Message-State: AOJu0YwqdGbEr73NaHrZ8ObbQcmZnpaIjlOY2JwIgCFPqAPK6hrwViuG zAiJYTj06IhslKOoqdQ7jf5SNMQpQpeJzmvHdWkq9wo5j3Nydnwz X-Google-Smtp-Source: AGHT+IEdXOGJLCqjb/vKq4Ola4i+8h/XoizmI2Rkhts4Rv5jVEEOGcPh8P504W7qOgtMUuMTfEc55Q== X-Received: by 2002:a17:902:da8a:b0:1f7:2134:e8a4 with SMTP id d9443c01a7336-1f83b6ed52cmr9684655ad.49.1718169821710; Tue, 11 Jun 2024 22:23:41 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:41 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 03/15] powerpc: Add timebase tests Date: Wed, 12 Jun 2024 15:23:08 +1000 Message-ID: <20240612052322.218726-4-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 350 ++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 8 + 4 files changed, 360 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 b52037c0d..6f50f6b6c 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..1e6343999 --- /dev/null +++ b/powerpc/timebase.c @@ -0,0 +1,350 @@ +// SPDX-License-Identifier: GPL-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); + + /* Check all CPU nodes have the same value of dec-bits */ + if (dec_bits) + assert(dec_bits == fdt32_to_cpu(*(uint32_t *)prop->data)); + else + 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; + int i; + + tb = get_tb(); + report(get_tb() >= tb, "timebase is not going backwards"); + if (do_migrate) { + tb = get_tb(); + migrate(); + report(get_tb() >= tb, + "timebase is not going backwards over migration"); + } + + for (i = 0; i < 100; i++) { + if (get_tb() > tb) + break; + } + 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; + } + /* POWER CPUs can have a slight (few ticks) variation here */ + report_kfail(!host_is_tcg, 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(); + /* TCG does not model this correctly */ + report_kfail(host_is_tcg, !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("test reqiures 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 407090ac4..9af933b14 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -93,6 +93,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 Wed Jun 12 05:23: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: 13694429 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ABB436124 for ; Wed, 12 Jun 2024 05:23:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169829; cv=none; b=HkieVjhRgsV7RjVolNWlIkmy1KtlHzwzeDjq1uUVCLbHQqG7D8HHLxsNIjCfnPjgxc+Vcu21H01DQP3YNamCQnq1thj/uSVEyJgjAfRIiqVLIk6WbX3V/2RbyTtMao6byScjfZe/0tI1WyRiQYvrRfKAQDqsQYwGGETUvEB4w+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169829; c=relaxed/simple; bh=hDNALPb7NGC8QeRZEjtiAZkK5S5NQL14qdsNqzHsnZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a48TOItFWOEdgIFGUdxjJ1JcBrgx7ZKDOPn6FJ4uEjtHEIgQ76EtvIY271swVQrnIXKgIhE99qKrajKpdIxm/0z2AVotq2hl4HAFYxcAUnPjlqtNCNVgfG65JVFvwmgOSekQvXi+mLXz3uE3fHcau1oTubZ6W65hChh/8icrYa8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g+gM8evr; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g+gM8evr" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70109d34a16so6016681b3a.2 for ; Tue, 11 Jun 2024 22:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169826; x=1718774626; darn=vger.kernel.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=xhPjItoOLT9MZcLkgDbHfLmHHoL9C7BQ3TKtEXJSLng=; b=g+gM8evrGBObKbOA+EaXlcY8fVxkJwEEB1gyjf7xzae/ttP5pGWbsHDYb+S9iEiKgI 2978jp9DXaJPC/7Y+2hCyeDSn5a6UYYywkWSbP/m1hagsT5inj3dCuzny203eAQdxVxU TUW+BG/GbEcU7cgV+tQ+J8cGLZdxhPTqnfCbk3AKyfCa3v6n5ePLcNLEjigdwTtRKS3R aoCddv4ZIbmHR5LFioj1uSgc+vrfSthFDug+BA7kH9c6bDL2nB+/btuSc7FPipvEJWBY FVrr+9xrnB6yBp+WAOl4hK7Yf0bS6ETDPoFfPi2UR3UlwIjT2HExwyxs6aMgWlBZn3vb +B2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169826; x=1718774626; 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=xhPjItoOLT9MZcLkgDbHfLmHHoL9C7BQ3TKtEXJSLng=; b=eW29jDrJ2wHaDmSEp+xITj/I5Lnb0ZUZINVctc5+moWyayQ48v9dCrbh83xN4tGH6B Ttcjfq5iDkq4UUbcwqbA0LV69BRcEPlBLEy/f57tXZ5qIG48zUPrRYfFuo5Pc+F5eNAW QGHcUWwaJtgGmU5DWBvieHFg89U1vXlwuss23+Lo/Xw1gxLuEkZBQHPum/k0wRf8vuTo uVuv1gN18Nsv+gnpmpbnhYsOPi9b+INyI1r7HtGypexFm59OpZz97nYTzQi3+iGDjkhu D1mOs0d0LbK5f28xVnMW9OJCirrwCm8AMgL1jIym7AkAq41dsrvqRnPrN4jo6ENaNnAR kzIw== X-Forwarded-Encrypted: i=1; AJvYcCV7IRSx0msaAqqQgfC5m2cMzNidTUSXQ6pmt2d9tSRT2HsDppPzG66MI8iydXo+SD9JWQTJHZQv84jK+uV9yqvCmQVF X-Gm-Message-State: AOJu0YxnksCwn8ST+NrQ2gguj6mvKWnobdd3xHxRzYo1dLzA6vtGw8fL HZE3ybeKQ+PxxlpwffIgwdo2msqoMwlw7GI1XoAzMktJ5xDbFTl0 X-Google-Smtp-Source: AGHT+IFK3O/ij9cbKdJASDLR1nCH8EIbKlJ7nnxHaYwEUUSzZS9+U4vmOzeykwD3kgtlt/RtFgSwDQ== X-Received: by 2002:a05:6a20:da89:b0:1b6:d9fa:8be with SMTP id adf61e73a8af0-1b8a9c55093mr1062615637.40.1718169825933; Tue, 11 Jun 2024 22:23:45 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:45 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 04/15] powerpc: Add MMU support Date: Wed, 12 Jun 2024 15:23:09 +1000 Message-ID: <20240612052322.218726-5-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 44 ++++-- 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 | 8 +- lib/ppc64/asm/mmu.h | 87 ++++++++++++ lib/ppc64/asm/page.h | 66 ++++++++- lib/ppc64/asm/pgtable-hwdef.h | 66 +++++++++ lib/ppc64/asm/pgtable.h | 125 ++++++++++++++++ lib/ppc64/mmu.c | 258 ++++++++++++++++++++++++++++++++++ lib/ppc64/opal-calls.S | 4 +- powerpc/Makefile.common | 4 +- powerpc/Makefile.ppc64 | 1 + powerpc/interrupts.c | 95 +++++++++++-- powerpc/mmu.c | 225 +++++++++++++++++++++++++++++ powerpc/unittests.cfg | 4 + 18 files changed, 978 insertions(+), 30 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 create mode 100644 powerpc/mmu.c diff --git a/configure b/configure index 0e0a28825..db15e85d6 100755 --- a/configure +++ b/configure @@ -74,8 +74,9 @@ usage() { Allow PV guests to be dumped. Requires at least z16. (s390x only) --page-size=PAGE_SIZE - Specify the page size (translation granule) (4k, 16k or - 64k, default is 4k, arm64 only) + Specify the page size (translation granule). PAGE_SIZE can be + 4k [default], 16k, 64k for arm64. + 4k [default], 64k for ppc64. --earlycon=EARLYCON Specify the UART name, type and address (optional, arm and arm64 only). The specified address will overwrite the UART @@ -245,25 +246,33 @@ fi if [ -z "$page_size" ]; then if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then page_size="4096" + elif [ "$arch" = "ppc64" ]; then + page_size="65536" 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 +481,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 a660344cb..b4f195856 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -17,6 +17,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 c45988bfa..bc2a68935 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; }; 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 86e2e144c..b7450e5e5 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -103,6 +103,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; @@ -125,6 +126,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: @@ -202,10 +204,11 @@ 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 = (unsigned long)memalign_pages(SZ_4K, SZ_64K); cpu->stack += SZ_64K - 64; - cpu->exception_stack = (unsigned long)memalign(SZ_4K, SZ_64K); + cpu->exception_stack = (unsigned long)memalign_pages(SZ_4K, SZ_64K); cpu->exception_stack += SZ_64K - 64; + cpu->pgtable = NULL; } bool host_is_tcg; @@ -227,6 +230,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 += EXCEPTION_STACK_SIZE - 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..32f1abab6 --- /dev/null +++ b/lib/ppc64/asm/mmu.h @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#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); + +static inline void tlbie(unsigned long rb, unsigned long rs, int ric, int prs, int r) +{ + /* MMU is radix (>= POWER9), so can use P9 tlbie directly */ + asm volatile( +" .machine push \n" +" .machine power9 \n" +" ptesync \n" +" tlbie %0,%1,%2,%3,%4 \n" +" eieio \n" +" tlbsync \n" +" ptesync \n" +" .machine pop " + :: "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r) : "memory"); +} + +static inline void tlbiel(unsigned long rb, unsigned long rs, int ric, int prs, int r) +{ + asm volatile( +" .machine push \n" +" .machine power9 \n" +" ptesync \n" +" tlbiel %0,%1,%2,%3,%4 \n" +" ptesync \n" +" .machine pop " + :: "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r) : "memory"); +} + +static inline void flush_tlb_page(uintptr_t vaddr) +{ + unsigned long rb; + unsigned long rs = (1ULL << 32); /* pid */ + 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, rs, 0, 1, 1); +} + +static inline void flush_tlb_page_local(uintptr_t vaddr) +{ + unsigned long rb; + unsigned long rs = (1ULL << 32); /* pid */ + 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; + + tlbiel(rb, rs, 0, 1, 1); +} + +#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..0f4b1068a --- /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..9e62cc800 --- /dev/null +++ b/lib/ppc64/mmu.c @@ -0,0 +1,258 @@ +// 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 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) +{ + if (!pgtable) + pgtable = identity_pgd; + + 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; + + if (!pgtable) + pgtable = identity_pgd; + + 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); + + /* 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); + + } else { + /* Only pseries and powernv support radix so far */ + assert(0); + } + + /* + * Avoid mapping page 0 so NULL dereferences fault. Test images + * run relocated well above 0, so nothing useful here except + * real-mode interrupt entry code. + */ + for (addr = PAGE_SIZE; addr < phys_end; addr += PAGE_SIZE) + install_page(identity_pgd, addr, __va(addr)); + +enable: + if (machine_is_powernv()) { + mtspr(SPR_PTCR, (unsigned long)partition_table); /* 4KB size */ + + mtspr(SPR_LPIDR, 0); + /* Set LPCR[UPRT] and LPCR[HR] for radix */ + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | (1ULL << 22) | (1ULL << 20)); + } + + /* 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 6f50f6b6c..d8db19580 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -16,7 +16,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)/mmu.elf tests-all = $(tests-common) $(tests) all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) @@ -42,6 +43,7 @@ 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 3e3622e59..66b4cd626 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 { @@ -92,6 +99,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); @@ -101,29 +111,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"); @@ -135,6 +152,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; @@ -402,9 +474,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(); diff --git a/powerpc/mmu.c b/powerpc/mmu.c new file mode 100644 index 000000000..4c6b6a17c --- /dev/null +++ b/powerpc/mmu.c @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * MMU Tests + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile bool tlbie_test_running = true; +static volatile bool tlbie_test_failed = false; +static int tlbie_fn_started; + +static void *memory; + +static void trap_handler(struct pt_regs *regs, void *opaque) +{ + tlbie_test_failed = true; + regs_advance_insn(regs); +} + +static void tlbie_fn(int cpu_id) +{ + volatile char *m = memory; + + setup_mmu(0, NULL); + + atomic_fetch_inc(&tlbie_fn_started); + while (tlbie_test_running) { + unsigned long tmp; + + /* + * This is intended to execuse a QEMU TCG bug by forming a + * large TB which can prevent async work from running while the + * TB executes, so it could miss a broadcast TLB invalidation + * and pick up a stale translation. + */ + asm volatile (".rept 256 ; lbz %0,0(%1) ; tdnei %0,0 ; .endr" : "=&r"(tmp) : "r"(m)); + } +} + +#define ITERS 100000 + +static void test_tlbie(int argc, char **argv) +{ + void *m[2]; + phys_addr_t p[2]; + pteval_t pteval[2]; + pteval_t *ptep; + 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; + } + + handle_exception(0x700, &trap_handler, NULL); + + m[0] = alloc_page(); + p[0] = virt_to_phys(m[0]); + memset(m[0], 0, PAGE_SIZE); + m[1] = alloc_page(); + p[1] = virt_to_phys(m[1]); + memset(m[1], 0, PAGE_SIZE); + + memory = alloc_vpages(1); + ptep = install_page(NULL, p[0], memory); + pteval[0] = *ptep; + assert(ptep == install_page(NULL, p[1], memory)); + pteval[1] = *ptep; + assert(ptep == install_page(NULL, p[0], memory)); + assert(pteval[0] == *ptep); + flush_tlb_page((unsigned long)memory); + + if (!start_all_cpus(tlbie_fn)) + report_abort("Failed to start secondary cpus"); + + while (tlbie_fn_started < nr_cpus_present - 1) { + cpu_relax(); + } + + for (i = 0; i < ITERS; i++) { + *ptep = pteval[1]; + flush_tlb_page((unsigned long)memory); + *(long *)m[0] = -1; + barrier(); + *(long *)m[0] = 0; + barrier(); + *ptep = pteval[0]; + flush_tlb_page((unsigned long)memory); + *(long *)m[1] = -1; + barrier(); + *(long *)m[1] = 0; + barrier(); + if (tlbie_test_failed) + break; + } + + tlbie_test_running = false; + + stop_all_cpus(); + + handle_exception(0x700, NULL, NULL); + + /* TCG has a known race invalidating other CPUs */ + report_kfail(host_is_tcg, !tlbie_test_failed, "tlbie"); +} + +#define THIS_ITERS 100000 + +static void test_tlbie_this_cpu(int argc, char **argv) +{ + void *m[2]; + phys_addr_t p[2]; + pteval_t pteval[2]; + pteval_t *ptep; + int i; + bool success; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + m[0] = alloc_page(); + p[0] = virt_to_phys(m[0]); + memset(m[0], 0, PAGE_SIZE); + m[1] = alloc_page(); + p[1] = virt_to_phys(m[1]); + memset(m[1], 0, PAGE_SIZE); + + memory = alloc_vpages(1); + ptep = install_page(NULL, p[0], memory); + pteval[0] = *ptep; + assert(ptep == install_page(NULL, p[1], memory)); + pteval[1] = *ptep; + assert(ptep == install_page(NULL, p[0], memory)); + assert(pteval[0] == *ptep); + flush_tlb_page((unsigned long)memory); + + *(long *)m[0] = 0; + *(long *)m[1] = -1; + + success = true; + for (i = 0; i < THIS_ITERS; i++) { + if (*(long *)memory != 0) { + success = false; + break; + } + *ptep = pteval[1]; + flush_tlb_page_local((unsigned long)memory); + if (*(long *)memory != -1) { + success = false; + break; + } + *ptep = pteval[0]; + flush_tlb_page_local((unsigned long)memory); + } + report(success, "tlbiel"); + + success = true; + flush_tlb_page((unsigned long)memory); + for (i = 0; i < THIS_ITERS; i++) { + if (*(long *)memory != 0) { + success = false; + break; + } + *ptep = pteval[1]; + flush_tlb_page((unsigned long)memory); + if (*(long *)memory != -1) { + success = false; + break; + } + *ptep = pteval[0]; + flush_tlb_page((unsigned long)memory); + } + report(success, "tlbie"); +} + + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "tlbi-this-cpu", test_tlbie_this_cpu }, + { "tlbi-other-cpu", test_tlbie }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + bool all; + int i; + + if (!vm_available()) { + report_skip("MMU is only supported for radix"); + return 0; + } + + setup_vm(); + + all = argc == 1 || !strcmp(argv[1], "all"); + + report_prefix_push("mmu"); + + 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 9af933b14..9af88d2ae 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -69,6 +69,10 @@ file = emulator.elf [interrupts] file = interrupts.elf +[mmu] +file = mmu.elf +smp = 2 + [smp] file = smp.elf smp = 2 From patchwork Wed Jun 12 05:23: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: 13694430 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2285E3BBF6 for ; Wed, 12 Jun 2024 05:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169831; cv=none; b=uetn9qNAHxlWxuoZikeDWuZ5sR1hiAno19xKjg8JtjXFwD5p62Ixm5WRzz7iX6DSUzse8ddevySovPGfwifKjQZNoi6trFXVRT5HrubJC6Hl4PW0FLVEi/T10Fat+4GoDEf4PT1zzXrP5TTl+UYCyfh0rw9/lI21g6ZlVOk7UMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169831; c=relaxed/simple; bh=FubDrlJDZVUQJl/U+53sKZswuwaTppA8aML8RXPLzYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hb5pdfLDQKRoAcoanArBlDK6A+jqXmZwYkO/bowsnSthgnjBv3zetjNEz7/uNwSd0LAVimE5AgSR9xsy/M9hHGwPmhRfPL0AXNffbgK8MO33NA/xshd8L2Au2WsmV+rbOfK9XVCeFY0bj8otrvMNW8MUJXBsaUBPb2000lRPCoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E4g6w7OB; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E4g6w7OB" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f6fabe9da3so30513275ad.0 for ; Tue, 11 Jun 2024 22:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169829; x=1718774629; darn=vger.kernel.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=whEhZTtPT00OFJB/07kvSJ13rQAZJafg7Gn5tcNqzNY=; b=E4g6w7OBJ8EzCc+iG9G22xMHDgJ+5f+N9HddxeYRdfibO9DqnXLXxhbMTBzmz4wPFv +DQCjXImnaXJ1X+5axG3Onhgu2YPGiEYcTGjLj1nBPNHuyohRqtOnXWExaSLNqxUYXhF 90z5yzHY4D6fAKApm9M0fudQXK/D61h+w1ARR0IMvcJDke7a/zG6WR596wqqt/tvYZok +2X/XzirQ200Xt4FcJWV57RSUUx6t1QpUOflbckVIGulSb50uqExWM5zkFhpleQUN9cO ZitMKn9WXn8mTPDdAl4KEqEELEUQ11/1sU0uv3gnMtVTCs4r45ThuDKRqzrCrhN2LiU9 kqnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169829; x=1718774629; 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=whEhZTtPT00OFJB/07kvSJ13rQAZJafg7Gn5tcNqzNY=; b=rE2tOG9jCkNethmgtbjSxTn7u9X0qjfbOuAlfdW/bHrqUZ6JGIuYSTmvTwlECX0JZp IzXgfYVuwSNbNv9hLK+jEAs1ZpoVgvwKn3omVvp9K8hRZzP8kRKOt8yPhDCwyZGxdnAf cdSR5jN+KdonTzDsHyM2l81HqUM1Q+sfDe5JviHem2kK3mvJ0ZKAY0LnPHDfL9naSkNU 4Sb9/ypeqk4DbCUq4KXcp8jWqYws68vwBkZgnY95/IJJw/YsktHSwkzQrnkzWphn9eSP zwcac1DbJX21Al6nNaBhORkC0RrdusWUvRf+Ysx5DZecD+9W7sj6UwK80rENc7uig4aJ ogXg== X-Forwarded-Encrypted: i=1; AJvYcCUz3wC3AyjbIybQwL0ZiwFLnIxNBcZ0/pxvCVRqA2n+PCmPHW9Djkp+t5um+AoFBZX//WS0ism3rR5fhNlS7X40fwyx X-Gm-Message-State: AOJu0Yxv/HZb0uwG6XOW72MCjwp8bwy2drwVFqbspoXPeLTuOwKr+8vH ESA/gD2Nlccfosr74tI9vcn20QTog+tXjLage8K6w9WprtFddXh+ X-Google-Smtp-Source: AGHT+IHf8iskGQ6DNM8Nf1fvjQgzr4swkoP/BW0g4dMf4f28rpBqyuTlnjIcqMfwWwIRw7lvEIHdzw== X-Received: by 2002:a17:902:e80f:b0:1f6:fcd9:5b86 with SMTP id d9443c01a7336-1f83b56617cmr10187605ad.12.1718169829461; Tue, 11 Jun 2024 22:23:49 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:49 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 05/15] common/sieve: Support machines without MMU Date: Wed, 12 Jun 2024 15:23:10 +1000 Message-ID: <20240612052322.218726-6-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Reviewed-by: Thomas Huth 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 32f1abab6..2bf94e498 100644 --- a/lib/ppc64/asm/mmu.h +++ b/lib/ppc64/asm/mmu.h @@ -4,7 +4,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 9e62cc800..6f9f4130f 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 Wed Jun 12 05:23: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: 13694431 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8622B3BBF6 for ; Wed, 12 Jun 2024 05:23:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169834; cv=none; b=CDWm+ofBv9G289qO8tX8NMCpK41Bc2SBKlAPxFj7wBr0TOKCT+h0qZGOgsYZ/OlUxl4Y20d57n/iNqE3ao16HumW3RIOjKEtd96S17uBPNrjJxkQQ9Srs6uk4WQXl52wTuPGimZJTLsRVBgQ0fL7irhr0v2OqqUnNthV/gWvot4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169834; c=relaxed/simple; bh=HmQqNDMlSHLY+95ZE540v3IC83aHplhjs/SF/I6B96Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TYCaZb6y8KNK6mV4Vuv4zB6TzwAqH7LbbrgJSi3IZgXGISXyD+wLCJEPZK3t7MvCGYIXDrLnVWsRMtW58fJu0J51HhGxQ/aeO/O8PgBGj3Qs96/thgFDZZLXziJeU5Ww1/dA3gM3pUPASnNFHbFpI0/FkWzIsotU+bFk/RCpB3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Z7D++ZRL; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z7D++ZRL" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1f692d6e990so60579205ad.3 for ; Tue, 11 Jun 2024 22:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169833; x=1718774633; darn=vger.kernel.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=cTVzxmkOngiwY2AMcf/1w5MP+3nR1mu8fLqrjh5W7lM=; b=Z7D++ZRLdGYyoD/vdh8YCpVfIUR1r4SJkquben2rEFX2MS7UfS36PV6/iYdudac24c c9nXs5GHIpa+IyKoSWBZBaFmo8um19z+MkJEFH5EFNAwdP/0yhZyJn/GM23u9GEB/xN2 MCY795Ldk7slUMEIt7SO7pplS9LIFIijdNvKWC1XBu3oOhVD7oqrgDrB9rE2wKgBZ50s /5xkw+76YQMP8epEw3n2AURw/Z6nLSHEwKi7rWVtY5ka01tvsY2AnhTL5aLR3pCozbHU NX7B2S5E270Nvavg7W+RTr3WC3xEOWTxyKXp10czv3sXhDUE93whUmZUIAiN+J4IHq2p pg/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169833; x=1718774633; 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=cTVzxmkOngiwY2AMcf/1w5MP+3nR1mu8fLqrjh5W7lM=; b=UCksVPWYeA0G+EGR1cm9Q7pXyv/PI1Yc/sm8Cc4JciSjS483ZhU56NviHqKqwrSyUg sxqED2aSmq1zLYuNqAdiyoJNTBrF3pSlm0Mks/VOq6JYMAPBIMFE+oNKgehStGBNfVZD TL7PKJE6AUEAls90bR0ETrpYFSGr85A8PhJokhkhlXe5md6OiM7ZzV3K2n0nvhqE1vyM Coq59wv7Jsbibvi7w3by2jgVdFOqHI+8X6z25nwW0ztqXqjfZSFAHnswmB1O79nSXkWm LxicaX8G/ri0tzOyYQaadK+iykQtNm6xmEFeMcpFFghb+AskBDkNiKvr8h7Yzafvwz8H f+2A== X-Forwarded-Encrypted: i=1; AJvYcCU2BM7DDLUhgFcVb02bC2L0gCtrzHNvZ+QlchgWofwD7ujNL5OViA0pKiZlK/M9cAiA/p1qcpIzwWsQidNOrbyQS3wH X-Gm-Message-State: AOJu0YwOVlGx5SVei8zWXJEggcpKYPOA8LkFSyWh7X1ZvvZLNu/gnlXn sE7sv1IvccYAkpzSknUZyS6jYU4uNVDjiATch7r/hA5Wj/8tSD0L X-Google-Smtp-Source: AGHT+IFT4vVNxGrh0/Ssaxl+Nv3a6M4E9eQlhkw95iQGq43XTwW8DEHnaM1OPRJ7I6K4NvAm1pkm3Q== X-Received: by 2002:a17:902:d2d1:b0:1f7:38c5:1f1a with SMTP id d9443c01a7336-1f83b565bc2mr9422475ad.11.1718169832831; Tue, 11 Jun 2024 22:23:52 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:52 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 06/15] powerpc: Add sieve.c common test Date: Wed, 12 Jun 2024 15:23:11 +1000 Message-ID: <20240612052322.218726-7-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that sieve copes with lack of MMU support, it can be run by powerpc. Reviewed-by: Thomas Huth 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 d8db19580..900b1f00b 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 9af88d2ae..149f963f3 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 Wed Jun 12 05:23: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: 13694432 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DA35381D9 for ; Wed, 12 Jun 2024 05:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169838; cv=none; b=q7n2041plVVfelZ5mdOtjZXUim8HMpR94z5Y60Ot6BPIYitXDO0QEDsAdeabhNy2bPNH8Ds3ff2wKJfQ0m5INWFqg59rUYNVkRkwmolYCyUJ8ncBcKLivD6W4mATtIOrXusCHo+eFZfVErCEVKl9RQ7ge/4hgQFq8LwNo8/fycU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169838; c=relaxed/simple; bh=Vfe6PHX898mJxb7zxyeWS2hgnLlIZ9z1JeLepshuOWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TjqEwS7a06BXVUrAw5/corkeeWvHiJY7n8ziYVhBDYIIzLqC6BELmuDsmhl+KPU3GG6DS3PqAPQHEeD5AMkv2gX9kYedTLPffQMiUStU9VjC7bd1CgCxUcPepSFLkeYIZGV8NYvOIDr/VTi09KzD/abhCM3XAt2CLPqI/0Dj8/c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VUMSEovo; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VUMSEovo" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-6c4926bf9bbso1299537a12.2 for ; Tue, 11 Jun 2024 22:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169836; x=1718774636; darn=vger.kernel.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=D8/CNw5jyd7VS+tHQzKTa3xNFmIwglcsZDjLDhI8+6I=; b=VUMSEovoM7lHyIyaGodGT+jfVG0FM88Di+VAfUtE/4w4nxhWP2Yxco0nuFeEuFp2Nv 77Qt/LUKcRUT4G2TR02/9sLx+uHDesRPa3V2zCIAINghKwKviws4UEozkwjPapgUJ3S1 DqflIqX9tUcnkcBACuaQ2PdleQY8Kbt2H+MbPG9crjzghH4MZaB3gMtilA3Fll9VJPyO tJy9rKF2RhtLCnG+oHACLCavZ3u01LY1ezdGvFlpIy7dByyUTvnOhXmAydZcB4G6hKpv IxQBjcc/YAHUI6gjXEFQSgaGiD9hHAp55jWD2Cc5+bZMJ1PHrjYOgoHT4XcF9pnNLp8r bMXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169836; x=1718774636; 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=D8/CNw5jyd7VS+tHQzKTa3xNFmIwglcsZDjLDhI8+6I=; b=tFgti7i9Qor/KoM8t2K3D1vloGoawl7UzuSsd5PJ1yRdrfVbsZZ+IU0iP0wCA8IVIT ZuNono07VnJHeCrP2KzH23KXPNg1+RCUtcL1fkB/cgGL+AbKveQyZKAIpaVV8V9FtotF jQNgnMGjcimuwhRIqaZ9vBgV4BCxxNz+quKiNx02COOicuz3bBzgtUZnXfsSef9d94uU 5dbC8MjfW5NXcXicA4tGzrye6ACGPiinoJTqjQDxFwyR6gHZyyW/cOyBtHSO1SA5Ipws BVmADDuNMGJbO0gOZTgED7xFBMv39TL3pY8bSMXdSpwhQUmYRE2avaF6RNin8fPyfL1q LbOw== X-Forwarded-Encrypted: i=1; AJvYcCUfInazX+fy7DRUvOPFnFMUVdbLYkx3t06IxWhs8fS0HSGeYUE6uD8/TI+H/Hin5UBQeuHNimS8sOln7W3YLfcQMn0D X-Gm-Message-State: AOJu0Ywa3z6tjyyjEhCqSlsTIHliazisHHNUmgJhDc4q4t8hWMNc4xD6 B5BiXiUp0CsRjLUv2jk2wIC9boWf4oIYXIlWQk/mk/sf56M+ANrx X-Google-Smtp-Source: AGHT+IFS9FRhv3/niWXE0r4xCxU4swY0zi2eP3yaAz4BQwq0k3AX4FFiyQYrEuZBRAMb3V4+32tdig== X-Received: by 2002:a05:6a20:3d89:b0:1b6:7d90:1c96 with SMTP id adf61e73a8af0-1b8a9b589c6mr1095866637.22.1718169836301; Tue, 11 Jun 2024 22:23:56 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:56 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 07/15] powerpc: add usermode support Date: Wed, 12 Jun 2024 15:23:12 +1000 Message-ID: <20240612052322.218726-8-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Reviewed-by: Thomas Huth 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 | 7 +++++-- lib/ppc64/mmu.c | 2 ++ powerpc/interrupts.c | 28 +++++++++++++++++++++++++++ 9 files changed, 94 insertions(+), 2 deletions(-) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index b4f195856..9609c9c67 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -22,6 +22,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; @@ -54,6 +56,8 @@ static inline void local_irq_enable(void) { unsigned long msr; + assert(!in_usermode()); + asm volatile( " mfmsr %0 \n \ ori %0,%0,%1 \n \ @@ -65,6 +69,8 @@ static inline void local_irq_disable(void) { unsigned long msr; + assert(!in_usermode()); + asm volatile( " mfmsr %0 \n \ andc %0,%0,%1 \n \ @@ -93,4 +99,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 bc2a68935..9ec416e25 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; }; 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 b7450e5e5..c1f0f9adf 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -209,10 +209,12 @@ void cpu_init(struct cpu *cpu, int cpu_id) cpu->exception_stack = (unsigned long)memalign_pages(SZ_4K, SZ_64K); cpu->exception_stack += SZ_64K - 64; cpu->pgtable = NULL; + cpu->in_user = false; } bool host_is_tcg; bool host_is_kvm; +bool is_hvmode; void setup(const void *fdt) { @@ -222,8 +224,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]; @@ -231,10 +231,13 @@ void setup(const void *fdt) cpu->exception_stack = (unsigned long)boot_exception_stack; cpu->exception_stack += EXCEPTION_STACK_SIZE - 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/ppc64/mmu.c b/lib/ppc64/mmu.c index 6f9f4130f..f2aebf584 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 66b4cd626..4c136a842 100644 --- a/powerpc/interrupts.c +++ b/powerpc/interrupts.c @@ -329,6 +329,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; @@ -481,6 +508,7 @@ int main(int argc, char **argv) test_mce(); test_mmu(); test_illegal(); + test_privileged(); test_dec(); test_sc(); test_trace(); From patchwork Wed Jun 12 05:23: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: 13694433 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16DC5374D1 for ; Wed, 12 Jun 2024 05:24:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169843; cv=none; b=uc5nJbl2RhuaPe3o3XXD+gT+QDTBhRt2ZHuf79TX0Saf9vkfhamhP2gCZHkg1kWN3u2VKnSSNS/aOGyn629nzVnZplvnyLwLTMXNld5xjeNnTR9DfSEwFTXKfOPdQKQEld0bdOPV9bzDIOjBARj6OrhpOyeXgdncockossJaVq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169843; c=relaxed/simple; bh=WvRFcgThdSWlWudDuYSlUKx0klDkj9y9gZGQ/ZbIYCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZI57gTEDFtARhIG3P/d43+mnA7xo4n7uRIPSl5k4WDndJKxuBp0WuOg9CSkrtjv8RpJc8hQ+BrcZ65giQDObQp23bf1aeUruqUd7/uH1H/4l+skt6AHcXV7p8nh5E+SYesW4zbzdhxvL7nloMnpo98SPDrdJMoBkWGSbGLy8lZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SY2cq0Uf; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SY2cq0Uf" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-6e7b121be30so2947831a12.1 for ; Tue, 11 Jun 2024 22:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169840; x=1718774640; darn=vger.kernel.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=lUZ7haKJPLcNY+7dMPiQw+LV6uqcYGY2ey80/7sMZ+I=; b=SY2cq0UfsftwF4W6ZPE8VpcdHkK5p4ZO9DORxQHq15iPpvfqhFcTeTxR3XgmHyTV75 Qvmojxob5XVMgW2V498N+UL7wIf7wQMqlLEaFZSq9xJ1bB5e8ooFmbpo/RXr+SYIwmIt uJ1lo/0Ddw7VZcXOZxc9AJrBYgWjCuyrSx8vo+msMd0xRJA5GsBm9qxO6ErmtwXQ3hHK jQV+vLXQZAUB05a/+M4jfU2m/vodOZ+3/x8N5SAGET9jZPfzlw7zi2kJ600e7s+voEeN UeXSkbuD61P6A4u6M1jMrUmSbemwperO9LHyGNLhFrz+99AcVvyHXwGrBaBpyQB/ojtk /Q+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169840; x=1718774640; 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=lUZ7haKJPLcNY+7dMPiQw+LV6uqcYGY2ey80/7sMZ+I=; b=li7VcRHjlyhOfq880QH2/WV+7rLQKTaWdjfEKrAtI/Ga14QGj4MJzkGffXtYsuTUl7 QemmYVOu8IzZibV9GK44dDCbj3gRenC+dFWv8fJ/1F6Bd1aiuJUb9Tn7uoaZKFOBUzJM YvdGZn7WhfHe6Xg0JulIGkys22fsfj+xEvxy3teKa9M/8vh7ZWvUa434uemOLLL0pKAS mTszIoG0VhXVBgp6XVpPSWM3iCKHgC02Oy24VfyXS9mhtE/WMIC3osWlDbxjI45bteng H0oITv6/0wjFXNfukJI4ZzSffccPgDKl7tI+xSnszBKhALGdeP5ajJE8cET8D6VUTTQJ 7E/w== X-Forwarded-Encrypted: i=1; AJvYcCUvc55lbsBpits0ws20VSdSjcuU4Ba0V3xMdV/B3WzDc2kF+3dpEY/S2RpCnGbwBk6XkPB80eV55TPipybGi3aDNs6l X-Gm-Message-State: AOJu0YyBDFiwan5yFJj74gGmxTxn7fEyk7JBBL3To9ixS0im053slJfy gJMF30tyMo2pDd6S/YZPhu7XCdrr/itDSkDjWDGZHYfWzKVmYL3le7dnWQ== X-Google-Smtp-Source: AGHT+IHvAfJikW4Ez/0OAetIgGBwLgBggFBQVnLUaJ30/eTVGEc5FkBqrZlhRtPVzYC15fp7UGQcdQ== X-Received: by 2002:a17:903:2307:b0:1f7:3e75:20c3 with SMTP id d9443c01a7336-1f83b6fcd7cmr10415445ad.42.1718169840184; Tue, 11 Jun 2024 22:24:00 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:23:59 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 08/15] powerpc: add pmu tests Date: Wed, 12 Jun 2024 15:23:13 +1000 Message-ID: <20240612052322.218726-9-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 20 ++ powerpc/Makefile.common | 3 +- powerpc/pmu.c | 562 ++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 3 + 7 files changed, 599 insertions(+), 1 deletion(-) create mode 100644 powerpc/pmu.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index 9609c9c67..09535f8c3 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -17,6 +17,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 c1f0f9adf..ef4ebdbce 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -33,6 +33,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; @@ -42,6 +43,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) @@ -95,6 +97,19 @@ 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) { + u64 *data64 = (u64 *)prop->data; + params->cpu_hz = fdt64_to_cpu(*data64); + } 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; } } @@ -103,6 +118,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 */ @@ -119,12 +136,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: @@ -133,6 +152,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 900b1f00b..0d271cdb6 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -18,7 +18,8 @@ tests-common = \ $(TEST_DIR)/sprs.elf \ $(TEST_DIR)/timebase.elf \ $(TEST_DIR)/interrupts.elf \ - $(TEST_DIR)/mmu.elf + $(TEST_DIR)/mmu.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..bdc45e167 --- /dev/null +++ b/powerpc/pmu.c @@ -0,0 +1,562 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Test PMU + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#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 illegal_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + regs_advance_insn(regs); +} + +static void fault_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + regs_advance_insn(regs); +} + +static void sc_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; +} + +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_pmc5(void) +{ + unsigned long pmc5; + unsigned long mmcr; + + reset_mmcr0(); + mmcr = mfspr(SPR_MMCR0); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mmcr & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 20 ; nop ; .endr" ::: "memory"); + mtspr(SPR_MMCR0, mmcr); + pmc5 = mfspr(SPR_PMC5); + + report_kfail(true, pmc5 == 21, "PMC5 counts instructions exactly %ld", pmc5); +} + +static void test_pmc5_with_branch(void) +{ + unsigned long pmc5; + unsigned long mmcr; + + reset_mmcr0(); + mmcr = mfspr(SPR_MMCR0); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mmcr & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 20 ; b $+4 ; .endr" ::: "memory"); + mtspr(SPR_MMCR0, mmcr); + pmc5 = mfspr(SPR_PMC5); + + /* TCG and POWER9 do not count instructions around faults correctly */ + report_kfail(true, pmc5 == 21, "PMC5 counts instructions with branch %ld", pmc5); +} + +static void test_pmc5_with_cond_branch(void) +{ + unsigned long pmc5; + unsigned long mmcr; + + reset_mmcr0(); + mmcr = mfspr(SPR_MMCR0); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mmcr & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 10 ; nop ; .endr ; cmpdi %0,1 ; beq 1f ; .rep 10 ; nop ; .endr ; 1:" : : "r"(0) : "memory", "cr0"); + mtspr(SPR_MMCR0, mmcr); + pmc5 = mfspr(SPR_PMC5); + + /* TCG and POWER9 do not count instructions around faults correctly */ + report_kfail(true, pmc5 == 24, + "PMC5 counts instructions wth conditional branch %ld", pmc5); +} + +static void test_pmc5_with_ill(void) +{ + unsigned long pmc5_1, pmc5_2; + + handle_exception(0x700, &illegal_handler, NULL); + handle_exception(0xe40, &illegal_handler, NULL); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".long 0x0" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_1 = mfspr(SPR_PMC5); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 10 ; nop ; .endr ; .long 0x0 ; .rep 10 ; nop ; .endr " ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_2 = mfspr(SPR_PMC5); + + /* TCG and POWER9 do not count instructions around faults correctly */ + report_kfail(true, pmc5_1 + 20 == pmc5_2, + "PMC5 counts instructions with illegal instruction"); + + handle_exception(0x700, NULL, NULL); + handle_exception(0xe40, NULL, NULL); +} + +static void test_pmc5_with_fault(void) +{ + unsigned long pmc5_1, pmc5_2; + unsigned long tmp; + + setup_vm(); + + handle_exception(0x300, &fault_handler, NULL); + handle_exception(0x380, &fault_handler, NULL); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile("ld %0,0(%1)" : "=r"(tmp) : "r"(NULL) : "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_1 = mfspr(SPR_PMC5); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 10 ; nop ; .endr ; ld %0,0(%1) ; .rep 10 ; nop ; .endr " : "=r"(tmp) : "r"(NULL) : "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_2 = mfspr(SPR_PMC5); + + /* TCG and POWER9 do not count instructions around faults correctly */ + report_kfail(true, pmc5_1 + 20 == pmc5_2, "PMC5 counts instructions with fault"); + + handle_exception(0x300, NULL, NULL); + handle_exception(0x380, NULL, NULL); +} + +static void test_pmc5_with_sc(void) +{ + unsigned long pmc5_1, pmc5_2; + + handle_exception(0xc00, &sc_handler, NULL); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile("sc 0" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_1 = mfspr(SPR_PMC5); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 10 ; nop ; .endr ; sc 0 ; .rep 10 ; nop ; .endr" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_2 = mfspr(SPR_PMC5); + + /* TCG does not count instructions around syscalls correctly */ + report_kfail(host_is_tcg, pmc5_1 + 20 == pmc5_2, + "PMC5 counts instructions with syscall"); + + handle_exception(0xc00, NULL, NULL); +} + +extern char next_insn[]; + +static void test_pmc5_with_rfid(void) +{ + unsigned long pmc5; + unsigned long mmcr; + + mtspr(SPR_SRR0, (unsigned long)next_insn); + mtspr(SPR_SRR1, mfmsr()); + reset_mmcr0(); + mmcr = mfspr(SPR_MMCR0); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mmcr & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile("rfid ; trap ; .global next_insn ; next_insn: " ::: "memory"); + mtspr(SPR_MMCR0, mmcr); + pmc5 = mfspr(SPR_PMC5); + + /* TCG does not count instructions around syscalls correctly */ + report_kfail(host_is_tcg, pmc5 == 2, + "PMC5 counts instructions with rfid %ld", pmc5); +} + +static void test_pmc5_with_ldat(void) +{ + unsigned long pmc5_1, pmc5_2; + register unsigned long r4 asm("r4"); + register unsigned long r5 asm("r5"); + register unsigned long r6 asm("r6"); + uint64_t val; + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 20 ; nop ; .endr" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + pmc5_1 = mfspr(SPR_PMC5); + + val = 0xdeadbeef; + r4 = 0; + r5 = 0xdeadbeef; + r6 = 100; + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 10 ; nop ; .endr ; ldat %0,%3,0x10 ; .rep 10 ; nop ; .endr" : "=r"(r4), "+r"(r5), "+r"(r6) : "r"(&val) : "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + pmc5_2 = mfspr(SPR_PMC5); + assert(r4 == 0xdeadbeef); + assert(val == 0xdeadbeef); + + /* TCG does not count instructions around syscalls correctly */ + report_kfail(host_is_tcg, pmc5_1 != pmc5_2 + 1, + "PMC5 counts instructions with ldat"); +} + +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 %ld", tmp); + + test_pmc5(); + test_pmc5_with_branch(); + test_pmc5_with_cond_branch(); + test_pmc5_with_ill(); + test_pmc5_with_fault(); + test_pmc5_with_sc(); + test_pmc5_with_rfid(); + test_pmc5_with_ldat(); + + 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"); + got_interrupt = false; + 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 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; + } + + 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; + } + report(nr_bhrbe, "BHRB has been written"); + report_kfail(!host_is_tcg, nr_bhrbe == 8, + "BHRB has written 8 entries"); + if (nr_bhrbe == 8) { + 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_kfail(!host_is_tcg, 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 149f963f3..79a123e9f 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -73,6 +73,9 @@ file = interrupts.elf file = mmu.elf smp = 2 +[pmu] +file = pmu.elf + [smp] file = smp.elf smp = 2 From patchwork Wed Jun 12 05:23:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13694434 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 818F938FA0; Wed, 12 Jun 2024 05:24:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169849; cv=none; b=Yaqey5vBDds4PV/2b0eH9LybCH8X1n5hsCjR7PjYy2LigJQROdL6Tweln0L6gTf0p5qApgC9qVh5SYZZYT4t/COX+3ceW+dLHzDDoUhAmd/izHpeOX11jSpOWID8AT5uer2CVtviYAFCUA4yClWThZfFi/7N+sAJ50kWVEDqDdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169849; c=relaxed/simple; bh=RymY7PnAv6b7tpTyJmoUZ0kfNOhoGlBV1AlNrgFlVCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K046YaYIAF9KCq7IG/0N4mh5SUQgUXE62iJ3nwfAHB4CNiYLM5NRMrab4rvOrjPdHuM55KhauVuCb20Rgmtswe5+3/9Q00dBfRV8xT16DYp726MhA6ti9i9SlrPsXqgWc5WZg4slSeYwA1mnUtJlFBmIzU4+v1xtB7xu8e/q+k4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XQcBGwsn; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XQcBGwsn" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f717608231so20668255ad.2; Tue, 11 Jun 2024 22:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169847; x=1718774647; darn=vger.kernel.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=cQuI8YGQgLmsUNQvvWuFnLsfcid8kBB0k+CZ86TDvAk=; b=XQcBGwsnhOJqNLYHTSb6anx7s+7va6ZUZYYZGHEsPidBjhvozmPeJvinrxYzzNvu34 8f3IaiYfkUCBs4s3Anc5HeV6MKlkDXlR+0hSjdxyaq2Ass3Fz+OSQoEHX4AVd58ByOyd RRx/wT3RW1PB28/5efNPJ9wYbneaQGb4jEDxPmpWzOTndMjyi8rYiE2WSaoyEOgHnHpH 4YOZr/JCWjRAZtTiKfGZ14v7I/QU2EIH9q9MSXsT4nC9DFQzUSCBkBhkZVrmPNECgp4R IojzGCoYwBmhQfA1QsTh7X/w0r3uIQAFUKvlBhl/R+rgbj4r2uKTFkR7fSFFeUyMky49 NhNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169847; x=1718774647; 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=cQuI8YGQgLmsUNQvvWuFnLsfcid8kBB0k+CZ86TDvAk=; b=qSHYEfN/LUoTpKEktHBi3QzRFfBze6dd5wPSVoI+un8UWaH+CyzbAUeafRyu9D+i6n +FrLvV1l1SFVGmut8unkXHEFvSpLpPYIq1mciYijL5howjzefQWvt2ICN6Sm7js7oAT6 uTte+J+194cnPZLIACmYRrLZJkMJPYNQJuJ8b3GOMTqVbSGNmD5JAHysMQuGwBOoY4JG RzNUtIvY1BQhXC9p1MM2+ijc3O951ahZFHcBOZjTQiuI/y1nTcPlYEMz6Dxih8zESf3i k0D6HQwLphjEl8l24c/9hpBS2Tug6zrtDnGnj7UTiNB6+ACn5ixo+2ycvoazyvpAlNoW AdEA== X-Forwarded-Encrypted: i=1; AJvYcCVcEp1eYxG9XmD2Yf1VR9o6lnKxZpibp+85KkXJl9caminWoFURki02NfGXJCBOj5tpDym5wUO0kESgv7BYqNiLmqMWi4pBiF+A6ux2EhVvZt3N9QLmZ1+kXCFQbDPnVw== X-Gm-Message-State: AOJu0Yyp/oTkuf2lgN9l3DArV7kdOAtLPLoVxVhxwqpV7YF2A8iNitmS cbGUXkdgy9W/XCNIcTYiQUMVeU2GyCcVfAwDicQhe/FNatpc2YYB X-Google-Smtp-Source: AGHT+IGibBQ31aFbHM2KNIyG3WXGmC6uDThIWGe0iAzdMLifnbTThBiAhC+djmwgDB3YyNkgibzPkg== X-Received: by 2002:a17:902:ceca:b0:1f7:969:7e87 with SMTP id d9443c01a7336-1f83b666b52mr10420065ad.35.1718169846856; Tue, 11 Jun 2024 22:24:06 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:24:06 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Alexandru Elisei , Claudio Imbrenda , David Hildenbrand , Eric Auger , Janosch Frank , =?utf-8?q?Nico_B=C3=B6hr?= , Paolo Bonzini , linux-s390@vger.kernel.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org Subject: [kvm-unit-tests PATCH v10 09/15] configure: Make arch_libdir a first-class entity Date: Wed, 12 Jun 2024 15:23:14 +1000 Message-ID: <20240612052322.218726-10-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 5b7998b79..7fe93dfd8 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 db15e85d6..b93723142 100755 --- a/configure +++ b/configure @@ -217,7 +217,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" @@ -285,8 +284,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 @@ -335,6 +336,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)!" @@ -345,6 +347,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= @@ -354,6 +357,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 @@ -416,10 +423,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 Wed Jun 12 05:23: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: 13694435 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13B21374FF for ; Wed, 12 Jun 2024 05:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169855; cv=none; b=T2+YZaINLIK/VQP2iCS9B/gDRJiBAyX8sIUMR2wHD5mZUP3alp7Sf5zGjTxf0ray9Uuc1jqhVG8VZAmpiMKGQCRsV4GbOkAlpbraGGLcKRfshSuJ3XuYK02IJI1VSeC3nsvGCeDgMoyLFwFCqIghytaeBwmh4W1ea0a5psZRdoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169855; c=relaxed/simple; bh=JDjuk04RM2H7qLXu1Elsq6p1gF4XIagVw12rcbJ79GU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ha04Zg9hmiUzn+jGLQTedBeTTYtJO9o4B1gqGSkLUhljWIJFFvJozSfpeDH4k+qm6oWHISvqSvB+AzI2xCMhPhRg8aLhD5XMym2OcDpmvTIRGiYaX3ZWSqRqGOa5ThbNl5C4vBBWheu4PsNWAtkgSCNADhYQNG5MnyehCj05ynE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OEXdxGt7; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OEXdxGt7" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-627ebbefd85so74048167b3.3 for ; Tue, 11 Jun 2024 22:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169852; x=1718774652; darn=vger.kernel.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=axlwTKTDIJ/jMD9TeyI5nqm+rD+tdc5ndfpTm15pQzQ=; b=OEXdxGt74AoOgIzlsnMbgTjO+VYiklD/bNtVpSFinlYxWEECX3U8u3ko8fwj/JpuGG qKjhxNoe2E81TYI+wvMHxxVzDcVvM1oJxlAWlq39htvzt1ctUkQvMmOP1SjHcnFhnA9d YEYWvp3ncF93in7JDpu0DGud179JJAQAscHJH5Uuak63Au4zr9e4G6S4YGnMZpzAmOMa Vb9bSXEAID5CHSR3CURWw1fDyJxOPA1Wx35n3GqfAedpO4J5p2H9d5r6EAjCYpPsRLoT PSWFll+j2Yk23jdbvBAiaQKAbNu3b9BtHrqRr/Fj4R9oRntTC5YS9qUtqjL4IaRofSUX 5o+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169852; x=1718774652; 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=axlwTKTDIJ/jMD9TeyI5nqm+rD+tdc5ndfpTm15pQzQ=; b=IAtz3Zia86ZfvUYCCaiXjEE7jbWqOKuAP6GnoEw9EHsz+UpQGyrGGQ9LBjgXuPO+jJ wReqsvJJpNcUt6jb7kawF1wMbcRTeQ36dO042E+RdM1dnEcILxLgnWP7vtRItEJrfhJG bgbD2wJgAphGemW+jdcSJ44pLTFdQKL2CB03pSdOYD3NDZKxCsxW1/Ik9NmoRnTF0n1V Ef6hKcgFFCR3TuRil/CSIb4Co0/StbLqZ5E038PBYfUuFKuLFkXmq1IgzIMwMIJa0YUc Uk6L80I6JYashItFFkDDq9PsHsK0ADmDmXn98LaSo7eNfIEJPCZhHYP0OzzJAVkosCSx OqbQ== X-Forwarded-Encrypted: i=1; AJvYcCUUJEqWtdaExz0FJcdir0V9xxbND0OkpbN0XPNGhkzMbIm3uXC1QBgK4LTiHg+E3i+W5nOqhq8+TwY1kNdDdsD9i1ae X-Gm-Message-State: AOJu0YwYUYwhhDdMjLcDOJpGkET1IUTsWOMoN8UDj0JH1RiO5WzmRaDq 5ghMip7DzMD/ee/PDL/OPJLZ0F42A2dvTXCCobVgOGNeg5XT1W+squFvcA== X-Google-Smtp-Source: AGHT+IG4PyBRCV9DY/ihMqcw9JEJ7X64+EqTs20peeFk5dddaif2ZMT+q2iIBFFLhLEZyqdsYqORsg== X-Received: by 2002:a0d:d486:0:b0:61a:e903:8d4f with SMTP id 00721157ae682-62fbd79c186mr7652877b3.37.1718169850328; Tue, 11 Jun 2024 22:24:10 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:24:09 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 10/15] powerpc: Remove remnants of ppc64 directory and build structure Date: Wed, 12 Jun 2024 15:23:15 +1000 Message-ID: <20240612052322.218726-11-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Acked-by: Thomas Huth 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/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/spinlock.h | 6 -- lib/ppc64/asm/stack.h | 11 -- powerpc/Makefile | 111 ++++++++++++++++++++- powerpc/Makefile.common | 95 ------------------ powerpc/Makefile.ppc64 | 31 ------ 36 files changed, 139 insertions(+), 179 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%) create mode 100644 lib/powerpc/asm/spinlock.h 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/spinlock.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 6ceea991a..1b4aea258 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 b93723142..5b7e7aee4 100755 --- a/configure +++ b/configure @@ -216,6 +216,7 @@ fi arch_name=$arch [ "$arch" = "aarch64" ] && arch="arm64" +[ "$arch" = "powerpc" ] && arch="ppc64" [ "$arch_name" = "arm64" ] && arch_name="aarch64" if [ "$arch" = "riscv" ]; then @@ -336,7 +337,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 0f4b1068a..3f8c6fe34 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/powerpc/asm/spinlock.h b/lib/powerpc/asm/spinlock.h new file mode 100644 index 000000000..da259ff4b --- /dev/null +++ b/lib/powerpc/asm/spinlock.h @@ -0,0 +1,6 @@ +#ifndef _ASMPOWERPC_SPINLOCK_H_ +#define _ASMPOWERPC_SPINLOCK_H_ + +#include + +#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/spinlock.h b/lib/ppc64/asm/spinlock.h deleted file mode 100644 index f59eed191..000000000 --- a/lib/ppc64/asm/spinlock.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _ASMPPC64_SPINLOCK_H_ -#define _ASMPPC64_SPINLOCK_H_ - -#include - -#endif /* _ASMPPC64_SPINLOCK_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..41e752b07 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)/mmu.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 + +################################################################## + +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 0d271cdb6..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)/mmu.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 %.aux.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 - -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 Wed Jun 12 05:23: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: 13694436 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC25E38382 for ; Wed, 12 Jun 2024 05:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169856; cv=none; b=LxGUK8q497bsVKnRYg73s0dn4amzI+LL5iC6Wy9AhJCZeYwqZqyEvtohm3LCSUOsDn3geGv1aq6gH6wbjUVG43kR6Y+adqM1+0R8BBXJ4UA3c89phPdubMs+o7nyoGYlqYCem/7RnhKLyxwT/1Y7K7wFADEtcbeKjNjWj96Z8Qw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169856; c=relaxed/simple; bh=SHjqplac++yHtEn1s8AlqDEGds4GZUuAxu/gZUEhfvw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b2ROGOOB9/ErwWPnTFNuWn/5Sru8lC3dqvML6fKPDXQqbqKUHlsWA9zNQP++5BmX9DniJzRx/xawMfNudEjIFG/ZYbgE4b5FFGt0ALyLJe4vNvWfIuwSy4SDeTr4tHyLLaQbrN73yWBWPHpilWknN3171w2p0ww7tt0YCcuKQ2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kM3UgXYI; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kM3UgXYI" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1f6b0a40721so46406855ad.2 for ; Tue, 11 Jun 2024 22:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169854; x=1718774654; darn=vger.kernel.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=j9L1xoCrCRrB/Q3jS6x86SGj+fZqpLObyaxaO3glOSo=; b=kM3UgXYISj/oBvUzOoWB7y3Aakc05gP1XTIrOt4KVqsQ5+AVnbAj5e4QUBPflWqZtv 39krRWgT7wWL3bU/hECMa369sO37xbmS+oQXeAtriYUF1HEhFYutvysqK7QGGSNbTNHB 98MzPeUwocSZaVe4+NTmoY3fnBfoQNPFzPDNDiWLvfk7Vg/+9Rj56tT6qIDS2xo4uZUT MxIVVZkRzdAxxHaJiK7YKciETa1w70RodXubUV33nxh3iWoZ+33ypinbIAC24KFT25Do O/7L9q1ZcJ7zw+raOilJgvoUHVLaXqJASfGwq90XupsxYA7ldhTQq2gqsnjoJ/0dFXl0 56Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169854; x=1718774654; 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=j9L1xoCrCRrB/Q3jS6x86SGj+fZqpLObyaxaO3glOSo=; b=W4Rgyei5TT0TqyGitBmGLTPJhVunk1oJ43zwSsyj/OFXS7WPzjK9MkOvMSEPpPYT/q NM2gFmdd+fsPr+RFDgm5atqNbZNCARzg4WOpoSvVaVAaUVk9cUg/6Pt0cV3AMRlWyhm7 fqHEaeA9WHRrO+VdsFviDPKGt9FHhvpI6XTt6DbinpRGNmZZ5aT+VSf+deuHZkGrRcVu ayK3DEeK6GNBPIx2oLmdtAZ+f9Etibcl2eg1a9KSAzlCVGZJCoRXw5wPBTElmSFm07Hb fxdSAGdkhkBQtpNOYAusz09+aPonXpR6udTIKiFyCgjOMONLY8M38YoG4pwEkABP0kcT e1Zw== X-Forwarded-Encrypted: i=1; AJvYcCXV7mxIdPsWfAz+czFJK4O3QhOlMdcSuAr2XDVP+Jbg0WwSMLCii8uP6aoGWfA4UpD2qPC67SDnkWMQAFXNRRlwePZe X-Gm-Message-State: AOJu0Yzb+6ohlf0l0hV6QPT+cBAnW8QaUyH0e3Bzr6soTRMU059ATYNX bM2boYnjBpOueDOa/uisNcQv3AtEB7kPmkRr3adX9bbF6YbjNAGl X-Google-Smtp-Source: AGHT+IF8CsFWZGDaDZHuKFtw+srSJbMsiTXWPPYRhmdRUZYG4Gukwaaw6xFQ5qU3hAIn3lKjcBbrYg== X-Received: by 2002:a17:902:eccc:b0:1f8:3c9e:3b92 with SMTP id d9443c01a7336-1f83c9e3cf9mr6771865ad.23.1718169854003; Tue, 11 Jun 2024 22:24:14 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:24:13 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 11/15] powerpc: gitlab CI update Date: Wed, 12 Jun 2024 15:23:16 +1000 Message-ID: <20240612052322.218726-12-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds testing for the powernv machine. To control overhead, ppc64be is used to test powernv and 64k page size, ppc64le is used to test pseries and 4k page size. Change to using a gitlab-ci test group instead of specifying all tests in .gitlab-ci.yml, and adds a few additional tests (smp, atomics) that are known to work in CI. Signed-off-by: Nicholas Piggin --- .gitlab-ci.yml | 32 ++++++++------------------------ powerpc/unittests.cfg | 34 +++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0e4d6205f..b5fc0cb7d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -96,22 +96,14 @@ build-arm: build-ppc64be: extends: .outoftree_template script: - - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat + - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu - mkdir build - cd build - - ../configure --arch=ppc64 --endian=big --cross-prefix=powerpc64-linux-gnu- + - ../configure --arch=ppc64 --endian=big --page-size=64k --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 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 @@ -119,17 +111,9 @@ 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 # build-riscv32: # Fedora doesn't package a riscv32 compiler for QEMU. Oh, well. diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 79a123e9f..89455b618 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -16,17 +16,25 @@ 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 +# QEMU 7.0 (Fedora 37) in gitlab CI has known migration bugs in TCG, so +# make a kvm-only version for CI +[selftest-migration-ci] +file = selftest-migration.elf +machine = pseries +groups = nodefault selftest migration gitlab-ci +accel = kvm + [selftest-migration-skip] file = selftest-migration.elf machine = pseries -groups = selftest migration +groups = selftest migration gitlab-ci extra_params = -append "skip" [migration-memory] @@ -37,6 +45,7 @@ groups = migration [spapr_hcall] file = spapr_hcall.elf machine = pseries +groups = gitlab-ci [spapr_vpa] file = spapr_vpa.elf @@ -47,38 +56,43 @@ 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 +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [interrupts] file = interrupts.elf +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [mmu] file = mmu.elf smp = 2 +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [pmu] file = pmu.elf [smp] file = smp.elf smp = 2 +groups = gitlab-ci [smp-smt] file = smp.elf @@ -90,19 +104,22 @@ file = smp.elf smp = 8,threads=4 accel = tcg,thread=single +# QEMU 7.0 (Fedora 37) in gitlab CI does not do well with SMP atomics [atomics] file = atomics.elf -smp = 2 +groups = gitlab-ci [atomics-migration] file = atomics.elf machine = pseries extra_params = -append "migration -m" -groups = migration +groups = migration gitlab-ci +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [timebase] file = timebase.elf +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [timebase-icount] file = timebase.elf accel = tcg @@ -116,14 +133,17 @@ smp = 2,threads=2 extra_params = -machine cap-htm=on -append "h_cede_tm" groups = h_cede_tm +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [sprs] file = sprs.elf +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [sprs-migration] file = sprs.elf machine = pseries extra_params = -append '-w' groups = migration +# Too costly to run in CI [sieve] file = sieve.elf From patchwork Wed Jun 12 05:23: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: 13694437 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29DF938382 for ; Wed, 12 Jun 2024 05:24:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169859; cv=none; b=gGTH8PIvgzZMLKDVr5CVyuyHI5vzWWZHJ9bIBBHHvsFLvtXiuk1WFrFH29PwVlDniEW5zI2L/0gngVR/piBe41SmKRXT1gEx1pwW1NbZyICnrySU7Sg2EPU34wLkqx0vl8ItMqz+ZJRTaGMgJElBkRwNH/uiQbrV3l3iHg2Orrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169859; c=relaxed/simple; bh=Crr7kDwPWvntzfO+2p4xcjuyMJ9kb9pI7leZk5jIgZA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lwL1yrkQrpidycQRIMGXTLp4BfU7vhCb0INKWDd8AvRCYd+HdZjmlhyTtCW9/aCGBmxyp6Tb2b0dA5oK79CI+uaNhbOlI8WxgeH2FmTHN6V1JFp29avwMUvPeHN/xQprIizUKA0wFD0mVmwnjufuk3/zuG68N9MIUxvSJ5ysyWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fao7eFn7; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fao7eFn7" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1f64ecb1766so49618595ad.1 for ; Tue, 11 Jun 2024 22:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169857; x=1718774657; darn=vger.kernel.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=5+0ku7WxXf8a4yF3c/GUIfqXl1O0gtCpT9pSJtDXNTg=; b=fao7eFn7qBEZAA4AG4q/LjEn/t6Lq5NhPDESegYxRVVcpvWUC/yVG+GrOkZ1HE00OQ LHMVGBPC7AEvtYDuCu4ZEkbm5Az4x3vugfoRN91ClhV803mcvR0W8PVNT5M4C8JG8k1P LxgEp99wiqGcEfN7NJ/7Y01Z6PhE6VL48IaNO6lQ3utJ3yPBSnwQ5o3PFb43FtVq7V7/ X0cfX8xrf8CuIuW76WoGCom6U25cZl44Iwat/QRUXQ6SiFLxY+OMluM6kR2P2xeGbkNW EPUjjLO8lWdVmp/J1LxFX3ZDpYnLTl/ZX45GrV09c35RetAzn08e8DYRrB5gt6Lg0q// FkCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169857; x=1718774657; 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=5+0ku7WxXf8a4yF3c/GUIfqXl1O0gtCpT9pSJtDXNTg=; b=PoCmSC0F3G3BM3EbxMk1Smvz37Ahj9Q6t52RjKL4Q2PydDEdpuq6kro4OC43JVPzcy bH13VpEpd4qy4l2hs5t+DAtj33ISRtxsAnzK3LhmiyKfHfPSvDCrnvnZMiaofLr9xmg8 qA6puXzPiYriFksIfyAbM6yMztgXBLUfa2KPJCE6lCWZTpLFuEZCLYIRA24aE5KnluYf TutGix6hcoLv/+iSmFtDfEHjXDKaRTe/LTxV1z+a7yPKVtZeU8EN8iapm0e4UjMn1Imw 31wRYa18Uzb1kM7mczgoVx+s6dKJ5D8IgAJGkihoW7HW9QLgAY00CErW8eD/P3an7SXI PF8g== X-Forwarded-Encrypted: i=1; AJvYcCWGLTeguBczYeQftXJnNh2rqzS1AMSiCbSETXjYkGx88W3Go7cGyJfKXesU5ipw0xu4XRnDvzConUpTvq48JFy6X5jQ X-Gm-Message-State: AOJu0YwWYaHNGDhKdQCKyg88Pov9UCyfYkY7edVGxwvIKrRjQWwz2OSs wyIrbaRsTi9tkh7JzR2XhaUoUYRrpQkG/MP2dtRw742bzz+7H0Jt X-Google-Smtp-Source: AGHT+IGCLL/DTPwhOwjk642AnhNGlQKNEEILHB9BJlkhVGPvbyRYZRdbWL10EC7mbPbpB1nAF0YMiw== X-Received: by 2002:a17:902:82cb:b0:1f7:210d:cbc with SMTP id d9443c01a7336-1f83b7df5b7mr6622685ad.56.1718169857338; Tue, 11 Jun 2024 22:24:17 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:24:17 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 12/15] scripts/arch-run.bash: Fix run_panic() success exit status Date: Wed, 12 Jun 2024 15:23:17 +1000 Message-ID: <20240612052322.218726-13-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 run_qemu_status() looks for "EXIT: STATUS=%d" if the harness command returned 1, to determine the final status of the test. In the case of panic tests, QEMU should terminate before successful exit status is known, so the run_panic() command must produce the "EXIT: STATUS" line. With this change, running a panic test returns 0 on success (panic), and the run_test.sh unit test correctly displays it as PASS rather than FAIL. Signed-off-by: Nicholas Piggin Acked-by: Andrew Jones --- scripts/arch-run.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 8643bab3b..9bf2f0bbd 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -378,6 +378,7 @@ run_panic () else # some QEMU versions report multiple panic events echo "PASS: guest panicked" + echo "EXIT: STATUS=1" ret=1 fi From patchwork Wed Jun 12 05:23: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: 13694438 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F1BD4437D for ; Wed, 12 Jun 2024 05:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169862; cv=none; b=F0DerilZplTF3tsaD3t/vamGHjfytKsFdHIwgL7JSUiXodF3DN23PIx3abN4Vhg4FRFHosiLQxHZ+3sRo1cj4IXqlTizD2bCTdcZsBQsqKkP4MJDqh0M6gD+ZEQIZRAsL7orcAlitSOKKQuXZ5UFgWYT4YHBHjQmT1Akj0uISts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169862; c=relaxed/simple; bh=S9VIH50LhKDvHH1wBXgLHxLxSyb9oXivoJxd3qTSHgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mx602BWAqaeEEGTeGn9Aw/alrPplCJuXyXYy7ASfz9iJtHOFaiw5D5+DSGz8icmJGk7pnKcYZsordi8U+jVnkcEbuAmI1f0zWYUGD10I9OdnbSzspvSsneBRK4/9pJSzicfm+EpFcTlH203lB8lWXxpjjcog90huFRdKc6ew4mw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CzKklzZg; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CzKklzZg" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1f70509b811so24221495ad.1 for ; Tue, 11 Jun 2024 22:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169861; x=1718774661; darn=vger.kernel.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=ov2H6CvAf7+nJ+8vHcgazEvP35meWrkDmpE16so9J0U=; b=CzKklzZgh00hvugrtMT78Fg3PrfMx9SL24wW7TfJN1EvgPjxiEf7g9t224c1qsuMyb sO59BH6Pp9TfFYfPFZOPaZZU8gusP4206yxVZRyyK4beiWrqkw7qxIijCLxjyqYOAvWV FVDM14Mum1sVOF5CBWHobiVuV4WCiGjfPqBgm2QeG9TjpG3MJfYaCvN0LfDKUEUgzvFr F4p8BajJTsuIqrgdD+BsF96nZh7DW2DfRRs9RFTdSmL+TmJYuOpJQK/6iqlxF8a3Tq8Q Ukt84nIwL3JgpxpJ6ZIVmTvElj1gqkb8041/hNBJ6Tzf2FvOmBdzkeZUGXBXQXStAOXd oErQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169861; x=1718774661; 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=ov2H6CvAf7+nJ+8vHcgazEvP35meWrkDmpE16so9J0U=; b=l9fQ+TaMErSDyzpI63XawM/COrRI/qSM3IILhfrOSBDgO2iG+AvKmymUx93PYvmbww 2HajRWmhbKGtYIJe8jnKbIkRNks2P3gfSepAb0CeaEWoFA+u9yYELYAuqDNaXqEFOS/c WSopu0+tHwDE/lPyXzdFHrtwTpX7rjzOJKIeWb8gCiGL7z6FA/Vqx/NBskHTw1dclxtU XaiJeYGztRR2VYZeWtNNa1XOE2xJjAxQaLYV4JLsJKWd7I/RA3ANypcHjtWDlw8i+Kzt +6ivTliyHTm2cEWjoRCXpJU+nUU3CsxG1DmX56zKrwHSDtX46Dh9nJhp/EJlSQdR+k6W K7SQ== X-Forwarded-Encrypted: i=1; AJvYcCWqrN7FninmvqwfSAKqKsmD/JNQPQkeqgjrWxzWgaxtKL1qvbz8vPCAUno881tqkAFHUvdUovoru5I2IqLhBrEZYlCY X-Gm-Message-State: AOJu0YzM6xPjIU29Da+w0rF+3LbtjERvseYRgp/H5qfNr4DSYfTwDZGy HtzrWoakpDWEVqIyiC7BHn3HychmWCNgfpclqVlczUS6enJfX/Vo X-Google-Smtp-Source: AGHT+IFK+RWCn1upQXe3RKipRXNTH/O9r+U30yabOqdDmeKU44uJZ/dinNzYARKqzW7k18zx2pJJVQ== X-Received: by 2002:a17:903:1c4:b0:1f7:178d:6990 with SMTP id d9443c01a7336-1f83b5eb0fdmr11078365ad.22.1718169860868; Tue, 11 Jun 2024 22:24:20 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:24:20 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 13/15] powerpc: Add a panic test Date: Wed, 12 Jun 2024 15:23:18 +1000 Message-ID: <20240612052322.218726-14-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds a simple panic test for pseries and powernv that works with TCG (unlike the s390x panic tests), making it easier to test this part of the harness code. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- lib/powerpc/asm/rtas.h | 1 + lib/powerpc/rtas.c | 16 ++++++++++++++++ powerpc/run | 2 +- powerpc/selftest.c | 18 ++++++++++++++++-- powerpc/unittests.cfg | 5 +++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/powerpc/asm/rtas.h b/lib/powerpc/asm/rtas.h index 364bf9355..2dcb2f1b3 100644 --- a/lib/powerpc/asm/rtas.h +++ b/lib/powerpc/asm/rtas.h @@ -26,6 +26,7 @@ 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_os_panic(void); extern void rtas_stop_self(void); #endif /* __ASSEMBLY__ */ diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c index 9c1e0affc..98eee24f4 100644 --- a/lib/powerpc/rtas.c +++ b/lib/powerpc/rtas.c @@ -182,3 +182,19 @@ void rtas_power_off(void) ret = rtas_call_unlocked(&args, token, 2, 1, NULL, -1, -1); printf("RTAS power-off returned %d\n", ret); } + +void rtas_os_panic(void) +{ + struct rtas_args args; + uint32_t token; + int ret; + + ret = rtas_token("ibm,os-term", &token); + if (ret) { + puts("RTAS ibm,os-term not available\n"); + return; + } + + ret = rtas_call_unlocked(&args, token, 1, 1, NULL, "rtas_os_panic"); + printf("RTAS ibm,os-term returned %d\n", ret); +} diff --git a/powerpc/run b/powerpc/run index 27abf1ef6..4cdc7d16c 100755 --- a/powerpc/run +++ b/powerpc/run @@ -56,7 +56,7 @@ fi command="$qemu -nodefaults $A $M $B $D" command+=" -display none -serial stdio -kernel" -command="$(migration_cmd) $(timeout_cmd) $command" +command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command" # powerpc tests currently exit with rtas-poweroff, which exits with 0. # run_qemu treats that as a failure exit and returns 1, so we need diff --git a/powerpc/selftest.c b/powerpc/selftest.c index 8d1a2c767..101cfcdef 100644 --- a/powerpc/selftest.c +++ b/powerpc/selftest.c @@ -7,6 +7,7 @@ */ #include #include +#include #include #include @@ -47,6 +48,17 @@ static void check_setup(int argc, char **argv) report_abort("missing input"); } +static void do_panic(void) +{ + if (machine_is_pseries()) { + rtas_os_panic(); + } else { + /* Cause a checkstop with MSR[ME] disabled */ + *((char *)0x10000000000) = 0; + } + report_fail("survived panic"); +} + int main(int argc, char **argv) { report_prefix_push("selftest"); @@ -57,9 +69,11 @@ int main(int argc, char **argv) report_prefix_push(argv[1]); if (strcmp(argv[1], "setup") == 0) { - check_setup(argc-2, &argv[2]); - + } else if (strcmp(argv[1], "panic") == 0) { + do_panic(); + } else { + report_abort("unknown test %s", argv[1]); } return report_summary(); diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 89455b618..9e7df22f4 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -18,6 +18,11 @@ smp = 2 extra_params = -m 1g -append 'setup smp=2 mem=1024' groups = selftest gitlab-ci +[selftest-panic] +file = selftest.elf +extra_params = -append 'panic' +groups = selftest panic gitlab-ci + [selftest-migration] file = selftest-migration.elf machine = pseries From patchwork Wed Jun 12 05:23:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13694439 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 249E8376EC for ; Wed, 12 Jun 2024 05:24:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169866; cv=none; b=QDG1OL5/1UDVvl+pYv/t3gf5NtqIOaqi/pAgR8fg5FXcpS7o0iGVBM1Tkf9ELOE3Kobvbx5uHUyarGsTD74E14vpQYmPJMv5uNHerL19hmCAz7EH8wkLU/5B4oOTm7egkIk9cnb7N2kGpfG99V2FWmsaplkSxP/Y3MuJ3kJdSYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169866; c=relaxed/simple; bh=yDuGrupJPqU/qH7mA60OyALH8EV2F1waSBvyey8sFNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XIGcZNvIsJiN7snS0IFtLPRRwtTTg3HLGrhBuCRAnSr3BYBSrz58h0JVr3g/z0885DinCPd6vShG8ryiqijIDnP/St2CD9hGoR8+qmdZ3dJZk5ZEd7jKhWH53TBQBAnDLzZTH2qOzLuJSauZgIl84VH2JYLrdJ4KrUC4ZfdXFHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HTefxumO; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HTefxumO" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-6bce380eb96so1388224a12.0 for ; Tue, 11 Jun 2024 22:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169864; x=1718774664; darn=vger.kernel.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=5Bc9UTJvjHe4RlGMnD7m65uYeeccHrpEGPbkyj3pP6o=; b=HTefxumOXDO0aX0NMszPojoBrcoC1T+11V96S6bTbKPSOtoAAVMvcvsb67W3lT8CDH 6J/CkPR3GBBhX1D10u+dgSghA/I5gY8Bil01/3i/TqmfLPHZemRNgT0UyRHljPYz4ORN 9mFw2AhxuYwT03DYtilgPZNv8yjs8SyB72E2Mcq5Gnw5S2L0tYT2WBgAEHBcOjDRtqMu NhzhccUqf3mp/eWWJxq8U31CWpA9YWTaSzRmUAOroRBCPkHcVshGCtsA/hzm6d9/kn6T T9aPAdgsqDtsksuy7OP4yyMcLby3eUU0UsKQOsi3tmGeWt1CJAPgmkmOCNzN1EEHqDpm l1xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169864; x=1718774664; 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=5Bc9UTJvjHe4RlGMnD7m65uYeeccHrpEGPbkyj3pP6o=; b=Br81FmeRkJmC8Bat3UtOrDdGT2IyR4kO/sCqd08F6PtstftWWn9VDs1KeHDKn6i9MF DbUuWRyN0YXKw1UVacXgerNSTkGoVeoITPztCKVzT+n8M/DS0p/7+WZvbroRnKBggUBB VKUqUohLuYmc5RbzJ+rLFwuknhyJcOujsdWvKa4QzS7/IGAJki7cECMqej8m7CUskayg BqDUtLzqyTFr3gNLTGVwGWMsPLyEJBY/JexQ+9Ck+EcgkWMv8K3pFDY1nziF+/ty6nv8 V8Hgl9+v16pSvDgY0MCfutLDKvcPTaQ1tw+TKXXnwTGTJEV12VaSbGlUm0QWjRF0TlBF WmeQ== X-Forwarded-Encrypted: i=1; AJvYcCWorSUZynq95jWTz388F3w39HCcRSxYbDdVtslQnwOsxRM9m5BA7fLXxUOVs1UTFEOTxICRgnbR/C6uBhopXZmqgAdC X-Gm-Message-State: AOJu0YwjB9R0raKwEtY0PKR7SgnaWZIAJq4vlCvyELyn1QwAhZgkheZd YPyfGNzpW1T8mF1oeXVqT4mAKYHEuw/+3Fctw0wg7V1onmB1FfEN X-Google-Smtp-Source: AGHT+IH9+Xd6lUiJ24ooIzSZ6C97JAO5455r4+dra0H8lUoyTuJiwIb7nGdiQKLtXGs25ppqqhR9FA== X-Received: by 2002:a05:6a20:7489:b0:1b5:ba37:9dac with SMTP id adf61e73a8af0-1b8a9c50fa1mr1037167637.57.1718169864462; Tue, 11 Jun 2024 22:24:24 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:24:24 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 14/15] powerpc/gitlab-ci: Upgrade powerpc to Fedora 40 Date: Wed, 12 Jun 2024 15:23:19 +1000 Message-ID: <20240612052322.218726-15-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 QEMU has fixed a number of powerpc test fails in Fedora 40, so upgrade to that image. Other architectures seem to be okay with Fedora 40 except for x86-64, which fails some xsave and realmode tests, so only change powerpc to start with. Signed-off-by: Nicholas Piggin --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5fc0cb7d..ffb3767ec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -95,6 +95,7 @@ build-arm: build-ppc64be: extends: .outoftree_template + image: fedora:40 script: - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu - mkdir build @@ -107,6 +108,7 @@ build-ppc64be: build-ppc64le: extends: .intree_template + image: fedora:40 script: - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat - ./configure --arch=ppc64 --endian=little --cross-prefix=powerpc64-linux-gnu- From patchwork Wed Jun 12 05:23: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: 13694440 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3D0E374C3 for ; Wed, 12 Jun 2024 05:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169870; cv=none; b=ISrhs0RFggjCYHHl5DTlpuFwuQHwerZ2mjWT0ypJMYvFInoBbxZOZ77fY12+LXT6GE2ThHIfXPRijG2bSJg7PgHRpZ4qj9LhehZJYHWZoxhU6ld4QkfrqZf61o4d9qzZ3M4Y31i3MH2us+8npPBkx/dY6VXm1GPTfqxkq4N6IGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169870; c=relaxed/simple; bh=Wp09YmZaYT4E1tUG9MaYjVy7/1+vq3LPpePDvc5kwKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C74jyfbfTORFR5p+KEE5LyCu0X1m4JFYxwBPW9myeRQS1WkcRfKAfQ9SrnmV9BE3Tu3Fl9rDfy3Y+o+5eNNiz4mMXiKS3Af20zrkQJiLt4BAy9UcQo6nKaoys9O/ceiQIxG+9N45dPzVh2dWvSIPw8I1SSYpZxJdIyOLHTslTFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BRW5k8t2; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BRW5k8t2" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1f4a5344ec7so4559115ad.1 for ; Tue, 11 Jun 2024 22:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718169868; x=1718774668; darn=vger.kernel.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=TlQRgBFNQaoTa6dz8Jq/4j8RyKmazPn0sRYigP/0Fhw=; b=BRW5k8t277PYYN7ZuY7XqJr5JoY4jYwSAMj87VyrzJ+r3IBXCkW9RkzBxD7XjRHcpX tat7yYBForRNJeNccCHAmEvoV2GNl1Zmuqm7tCJb7TFyn4EMaElJD7Izxu03fpkAbw73 nZMK+t7d1CKbbaPqdObOwBJsIOoX+coYpsXhcgbheos0RUSoFQoOzdX02bnPNSGyzpkZ Fi3h/JjyWXiuQ/GljyguhWoZY4uoEx6tD0Bs1wUDCEvG+lgjHh7c4yAJIAgG4CIgSfKx cIN5EjSUT9iJUn4toA+/ssWmOwwmsi7yYlHZOGM0m7QeztmbTM6+3JKyzh03+H11jhE+ prag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718169868; x=1718774668; 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=TlQRgBFNQaoTa6dz8Jq/4j8RyKmazPn0sRYigP/0Fhw=; b=haT3o1hKfcU58WPFncCjgClnXle64f8G4tx37jULB5FaH/GaiFv99F7/bWHyLEXyAJ fKImyqZiwq7Y5A6Uiw02o5f2Q8fYMp67p0PidEXnLGDXCOrkBtIU1KlROcljtDBc3YDK bC09ZmlZAXd+LCtsbz+J6iayfzBt6xKWiHKr2WkTf9M/8jHzkUmK35uEJxVj3LXvpAy5 algHQke4hyySSK1w5/+R8aBZxJsTN3iAV6frpIBJAwSQrVtL+RNnet7qD/+UAMxyAIw6 gK0rabax6FOTjj43r/lx9MqLmvK7qw0lECwFbRXb4ZpYuxvtDKVEY9surhqAiUpEYct3 JlFQ== X-Forwarded-Encrypted: i=1; AJvYcCXHIZw9+ifM828KDOnqzURHA0RNh38kFPxzBR9U0cl60IKcb2Mvon8x+obmxg69+Az/HeIRMWveh51zYbQwpgQG7Fsn X-Gm-Message-State: AOJu0Yw25lpWTrY6yAITPNpi1CZHUy6Kt1f+nzPr5VwFwlgY34OUKWCR P2sqpyDjCcc8g2Z5aspm8aXJFQmcYNCcoV9OaIDm4Hw/xIM7kM81 X-Google-Smtp-Source: AGHT+IEqLz5Dn4PKUTWY9xRYytx04I5xM9up7gD53spppmLeXqURYzOa8OHXdMBNI8YPHgpkyPGQjw== X-Received: by 2002:a17:902:c404:b0:1f7:2185:d2d9 with SMTP id d9443c01a7336-1f728791b33mr72648115ad.5.1718169868000; Tue, 11 Jun 2024 22:24:28 -0700 (PDT) Received: from wheely.local0.net (220-235-199-47.tpgi.com.au. [220.235.199.47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd75f711sm112170705ad.11.2024.06.11.22.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:24:27 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , Laurent Vivier , Andrew Jones , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH v10 15/15] powerpc/gitlab-ci: Enable more tests with Fedora 40 Date: Wed, 12 Jun 2024 15:23:20 +1000 Message-ID: <20240612052322.218726-16-npiggin@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com> References: <20240612052322.218726-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With Fedora 40 (QEMU 8.2), more tests can be enabled. Signed-off-by: Nicholas Piggin --- .gitlab-ci.yml | 2 +- powerpc/unittests.cfg | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ffb3767ec..ee14330a3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -110,7 +110,7 @@ build-ppc64le: extends: .intree_template image: fedora:40 script: - - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat + - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat jq - ./configure --arch=ppc64 --endian=little --cross-prefix=powerpc64-linux-gnu- - make -j2 - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 9e7df22f4..27092b185 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -28,7 +28,7 @@ file = selftest-migration.elf machine = pseries groups = selftest migration -# QEMU 7.0 (Fedora 37) in gitlab CI has known migration bugs in TCG, so +# QEMU 8.2 (Fedora 40) in gitlab CI has known migration bugs in TCG, so # make a kvm-only version for CI [selftest-migration-ci] file = selftest-migration.elf @@ -81,18 +81,18 @@ groups = rtas gitlab-ci file = emulator.elf groups = gitlab-ci -# QEMU 7.0 (Fedora 37) in gitlab CI fails this +# QEMU 8.2 in Fedora 40 fails because it allows supervisor to change MSR[ME] [interrupts] file = interrupts.elf -# QEMU 7.0 (Fedora 37) in gitlab CI fails this [mmu] file = mmu.elf smp = 2 +groups = gitlab-ci -# QEMU 7.0 (Fedora 37) in gitlab CI fails this [pmu] file = pmu.elf +groups = gitlab-ci [smp] file = smp.elf @@ -120,15 +120,15 @@ machine = pseries extra_params = -append "migration -m" groups = migration gitlab-ci -# QEMU 7.0 (Fedora 37) in gitlab CI fails this [timebase] file = timebase.elf +groups = gitlab-ci -# QEMU 7.0 (Fedora 37) in gitlab CI fails this [timebase-icount] file = timebase.elf accel = tcg extra_params = -icount shift=5 +groups = gitlab-ci [h_cede_tm] file = tm.elf @@ -138,16 +138,15 @@ smp = 2,threads=2 extra_params = -machine cap-htm=on -append "h_cede_tm" groups = h_cede_tm -# QEMU 7.0 (Fedora 37) in gitlab CI fails this [sprs] file = sprs.elf +groups = gitlab-ci -# QEMU 7.0 (Fedora 37) in gitlab CI fails this [sprs-migration] file = sprs.elf machine = pseries extra_params = -append '-w' -groups = migration +groups = migration gitlab-ci # Too costly to run in CI [sieve]