From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A476BC48BF6 for ; Mon, 26 Feb 2024 10:22:57 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iJGAT5Cx; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TjxX02XrTz3vsX for ; Mon, 26 Feb 2024 21:22:56 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iJGAT5Cx; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4TjxK62Cxbz3vYx for ; Mon, 26 Feb 2024 21:13:30 +1100 (AEDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6e4560664b5so2294666b3a.1 for ; Mon, 26 Feb 2024 02:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708942407; x=1709547207; darn=lists.ozlabs.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=56iBudlm9U8d1gus42bi1dKHG12FVRnvk/I1w3JRqyc=; b=iJGAT5Cx1rTLRVn7e54cwC2ocsaPXVLvPYFrfBrWUJHDv6IlNv3XtCbx+nI7YOUb+N 4ZFRUMHkCOAlqIJk6oaC/fgVvnAzvLXpzDG0TqcVC65fx5YkTWp8RDBa8EC5sIu6fQOG IDJoDMKArkWVat6KnXegauidKmn3ggcDnjOMNuFFIJ0sx6+F4oV+5hFWITVcv03cevhm O/d541Dfm/U6KyuBYdR9BQ4Uh5on5yhpFoFtYUwknTQsuJCnFGNL/vK6hKfZ3RhNbgNz ZH8/9tDko2pfCQ/QXA0+vcoGI3zj4FaDcnsSQo6rHhYAZ1IYXds6qI8TOhddskWtT4U4 NhaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708942407; x=1709547207; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=56iBudlm9U8d1gus42bi1dKHG12FVRnvk/I1w3JRqyc=; b=jneQBaST3JnqU6GzTh8ftJP1mvZIbIF643Y5H7B/DmWit3jjGYDgg268HGokh91H34 jE4oqLyf6BDWlUDv6D5Y0bY+SOJz1VIhQPWNVnxheQAoiGw2/7SsKanXv8J8LSrvABeA L7hy0O0lk5kdtRRf7jny1HOG031M3v/R8TOWI/bJ3RP5K0nRoZiGnf5XyQqxZoElkb63 MGTrIyD4E2e122bP75/XZ14M+KAZNjlNCbxofXNAzaSCzdTpAhIwvdppcdMCxfH7b9/e EbJKx2bg4pUqBBvd2wJwL3UEYZ66I+UhhNxkEkebpcNJ0ncCAfKMf4vFwmzhwqWtae1i 3Caw== X-Forwarded-Encrypted: i=1; AJvYcCW13a2BXIqyjLPcbNwMATWrtxDLKEfAvH2R7tAhXP/yNuZbfNzRurgV1FqalUWdILERsr3lW6v31FkXMVXmHr1q06O3VL2HVE4NRg6rnA== X-Gm-Message-State: AOJu0Yx0Y5G46qeTct8hib9ozhYDRNxaaGPdIgLeq7T5zXRuI6w6ncZy l/RMo6FUqOaerj3IO0xeoD6dUfJBYOJC8JjpNmuRZ5zCo0kF55Mi X-Google-Smtp-Source: AGHT+IFCEmru53h8ykn6ZFvyv19vcFj2ApRKFuuSf+y+EfsDSVWG/xsHvEixEPxFldkroBR47nCwmA== X-Received: by 2002:a05:6a20:9e4b:b0:1a0:e13f:c69 with SMTP id mt11-20020a056a209e4b00b001a0e13f0c69mr9729563pzb.8.1708942407554; Mon, 26 Feb 2024 02:13:27 -0800 (PST) Received: from wheely.local0.net (220-235-194-103.tpgi.com.au. [220.235.194.103]) by smtp.gmail.com with ESMTPSA id x24-20020aa784d8000000b006e463414493sm3626693pfn.105.2024.02.26.02.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 02:13:27 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH 13/32] powerpc/sprs: Test hypervisor registers on powernv machine Date: Mon, 26 Feb 2024 20:11:59 +1000 Message-ID: <20240226101218.1472843-14-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240226101218.1472843-1-npiggin@gmail.com> References: <20240226101218.1472843-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Joel Stanley , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" This enables HV privilege registers to be tested with the powernv machine. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- powerpc/sprs.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/powerpc/sprs.c b/powerpc/sprs.c index cb1d6c980..0a82418d6 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -199,16 +199,16 @@ static const struct spr sprs_power_common[1024] = { [190] = { "HFSCR", 64, HV_RW, }, [256] = { "VRSAVE", 32, RW, }, [259] = { "SPRG3", 64, RO, }, -[284] = { "TBL", 32, HV_WO, }, -[285] = { "TBU", 32, HV_WO, }, -[286] = { "TBU40", 64, HV_WO, }, +[284] = { "TBL", 32, HV_WO, }, /* Things can go a bit wonky with */ +[285] = { "TBU", 32, HV_WO, }, /* Timebase changing. Should save */ +[286] = { "TBU40", 64, HV_WO, }, /* and restore it. */ [304] = { "HSPRG0", 64, HV_RW, }, [305] = { "HSPRG1", 64, HV_RW, }, [306] = { "HDSISR", 32, HV_RW, SPR_INT, }, [307] = { "HDAR", 64, HV_RW, SPR_INT, }, [308] = { "SPURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, [309] = { "PURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, -[313] = { "HRMOR", 64, HV_RW, }, +[313] = { "HRMOR", 64, HV_RW, SPR_HARNESS, }, /* Harness can't cope with HRMOR changing */ [314] = { "HSRR0", 64, HV_RW, SPR_INT, }, [315] = { "HSRR1", 64, HV_RW, SPR_INT, }, [318] = { "LPCR", 64, HV_RW, }, @@ -306,7 +306,7 @@ static const struct spr sprs_power9_10[1024] = { [921] = { "TSCR", 32, HV_RW, }, [922] = { "TTR", 64, HV_RW, }, [1006]= { "TRACE", 64, WO, }, -[1008]= { "HID", 64, HV_RW, }, +[1008]= { "HID", 64, HV_RW, SPR_HARNESS, }, /* HILE would be unhelpful to change */ }; /* This covers POWER8 and POWER9 PMUs */ @@ -350,6 +350,22 @@ static const struct spr sprs_power10_pmu[1024] = { static struct spr sprs[1024]; +static bool spr_read_perms(int spr) +{ + if (cpu_has_hv) + return !!(sprs[spr].access & SPR_HV_READ); + else + return !!(sprs[spr].access & SPR_OS_READ); +} + +static bool spr_write_perms(int spr) +{ + if (cpu_has_hv) + return !!(sprs[spr].access & SPR_HV_WRITE); + else + return !!(sprs[spr].access & SPR_OS_WRITE); +} + static void setup_sprs(void) { int i; @@ -461,7 +477,7 @@ static void get_sprs(uint64_t *v) int i; for (i = 0; i < 1024; i++) { - if (!(sprs[i].access & SPR_OS_READ)) + if (!spr_read_perms(i)) continue; v[i] = __mfspr(i); } @@ -472,8 +488,9 @@ static void set_sprs(uint64_t val) int i; for (i = 0; i < 1024; i++) { - if (!(sprs[i].access & SPR_OS_WRITE)) + if (!spr_write_perms(i)) continue; + if (sprs[i].type & SPR_HARNESS) continue; __mtspr(i, val); @@ -561,7 +578,7 @@ int main(int argc, char **argv) for (i = 0; i < 1024; i++) { bool pass = true; - if (!(sprs[i].access & SPR_OS_READ)) + if (!spr_read_perms(i)) continue; if (sprs[i].width == 32) { -- 2.42.0