From patchwork Thu Sep 5 11:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792177 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 A0186CD5BAA for ; Thu, 5 Sep 2024 11:23:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZq-0008Qh-CI; Thu, 05 Sep 2024 07:23:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3hpTZZggKClMH2z8yC3519916z.x97Bz7F-yzGz689818F.9C1@flex--whendrik.bounces.google.com>) id 1smAZf-0008Eu-EQ for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:22:51 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3hpTZZggKClMH2z8yC3519916z.x97Bz7F-yzGz689818F.9C1@flex--whendrik.bounces.google.com>) id 1smAZd-0002xE-EZ for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:22:51 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-e17bb508bb9so1963061276.2 for ; Thu, 05 Sep 2024 04:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535367; x=1726140167; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=WFONln33w8RztWsDe8hthoqY7bBuV5gzQ95yPuNFG3Q=; b=hWVYq0igro+Z6wWhG9MSjUEYdLZrwOnmCZ9JPPurLNmLBgtJ244wl9TwTsiA9oQeY+ C5easSEUuWYSNopZvJVdLOj3gI6QYYqELwSOAnhAqun4ue3GJtqKMRx4BxEuJkTHzcKX s0Shr1A/xovTpGeWNA5nCP05QuGD3pcFd6eFh/kT2qMjT6oeMDqw76aGlAEc5/SP5pqS lFcIJ0RHyX4Z0nrjxV4ofKpb4GW83ZMlLtpFz8exxn28zlWqfC1JIbhX+8fZTfYwAgPD U5uhvigUs5REYnQiMTXA1w5FMM+QVLJscXI3Jv3TDc8HuN9MzTTjqcpolLEpjsXPrWsU OuoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535367; x=1726140167; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=WFONln33w8RztWsDe8hthoqY7bBuV5gzQ95yPuNFG3Q=; b=vi8vvZ54il8Jli7KB2FrkdKZhHDinnsTAQkTgwXgKOYTcE/FEZ06ZbCHaMcb2RK5MI 6b31xbAqktIL7SX85Ij3+JL7HFRn3tMrXeBTi83FzFaQPmUVmJzVEaoe3KgQeVA4SaMp HuoblS2lpQCTgqV7EpwyzGTe81r8f+kY0RLCMxsNvmHXxOqPVRowPAwM8optKVEWvO96 TFzE+pzmpiRmPzxUA2dyHTSzYPR7uV5vh8ZUCOZm3Ue/1koaVlna3ASt4mFmRuR0Mbwk IsosFTP6/NBSTCuOxeAaDDG1F/V/C5pKekcrvzQx7sXawm7BK2zZTt8NumweN+zdP6/k cbsA== X-Gm-Message-State: AOJu0Yy1bYlgZ+aCMEkiLPs/IVR26OLsrTvo0BhEGzHSO8DTdd2+YM+R Jrux9kuU81AitFtMgQNjtnnXWAxA2wu7MJCLiolb/cbsQWIyZiL6SuerxaC9Fe5zsQTDP1Sziqr GLUqJNVw5HjrHqwnbkRcy7MGQ5vwFIgv1ok5/AENraM2Y1Z3vrPWRhMUQkJquTiIg8UnJgIOyg1 o6bnOMvwu6xQYXsv5XaBH+eAv1kEGlyo8GmWGA1Hj3Ag== X-Google-Smtp-Source: AGHT+IHHgE/p+v3ZgUFP4oOLPGTTSGhaG1an7WqKnEeO7eru4aSFbDwnNJhuymW4SII74UqDldsGt+b+Dfc6ug== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:a5b:1:0:b0:e17:8e4f:981a with SMTP id 3f1490d57ef6-e1a7a3d0178mr944904276.11.1725535366854; Thu, 05 Sep 2024 04:22:46 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:30 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-2-whendrik@google.com> Subject: [PATCH v2 1/8] i386: Add Intel RDT device and State to config. From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3hpTZZggKClMH2z8yC3519916z.x97Bz7F-yzGz689818F.9C1@flex--whendrik.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Change config to show RDT, add minimal code to the rdt.c module to make sure things still compile. Signed-off-by: Hendrik Wüthrich --- hw/i386/Kconfig | 4 ++ hw/i386/meson.build | 1 + hw/i386/rdt.c | 96 +++++++++++++++++++++++++++++++++++++++++++ include/hw/i386/rdt.h | 25 +++++++++++ target/i386/cpu.h | 3 ++ 5 files changed, 129 insertions(+) create mode 100644 hw/i386/rdt.c create mode 100644 include/hw/i386/rdt.h diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index f4a33b6c08..4dd05ed6f2 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -10,6 +10,9 @@ config SGX bool depends on KVM +config RDT + bool + config PC bool imply APPLESMC @@ -26,6 +29,7 @@ config PC imply QXL imply SEV imply SGX + imply RDT imply TEST_DEVICES imply TPM_CRB imply TPM_TIS_ISA diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 03aad10df7..fdbf5962b5 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -21,6 +21,7 @@ i386_ss.add(when: 'CONFIG_VMPORT', if_true: files('vmport.c')) i386_ss.add(when: 'CONFIG_VTD', if_true: files('intel_iommu.c')) i386_ss.add(when: 'CONFIG_SGX', if_true: files('sgx-epc.c','sgx.c'), if_false: files('sgx-stub.c')) +i386_ss.add(when: 'CONFIG_RDT', if_true: files('rdt.c')) i386_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-common.c')) i386_ss.add(when: 'CONFIG_PC', if_true: files( diff --git a/hw/i386/rdt.c b/hw/i386/rdt.c new file mode 100644 index 0000000000..934f7fbf75 --- /dev/null +++ b/hw/i386/rdt.c @@ -0,0 +1,96 @@ +/* + * Intel Resource Director Technology (RDT). + * + * Copyright 2024 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "hw/i386/rdt.h" +#include "qemu/osdep.h" /* Needs to be included before isa.h* / +#include "hw/isa/isa.h" +#include "hw/qdev-properties.h" +#include "qom/object.h" + +/* Max counts for allocation masks or CBMs. In other words, the size of respective MSRs*/ +#define RDT_MAX_L3_MASK_COUNT 128 +#define RDT_MAX_L2_MASK_COUNT 48 +#define RDT_MAX_MBA_THRTL_COUNT 31 + +#define TYPE_RDT "rdt" +#define RDT_NUM_RMID_PROP "rmids" + +OBJECT_DECLARE_TYPE(RDTState, RDTStateClass, RDT); + +struct RDTMonitor { + uint64_t count_local; + uint64_t count_remote; + uint64_t count_l3; +}; + +struct RDTAllocation { + uint32_t active_cos; +}; + +struct RDTStatePerCore { + uint32_t active_rmid; + GArray *monitors; + + /*Parent RDTState*/ + RDTState *rdtstate; +}; + +/*One instance of RDT-internal state to be shared by all cores*/ +struct RDTState { + ISADevice parent; + + /*Max amount of RMIDs*/ + uint32_t rmids; + + /*Per core state*/ + RDTStatePerCore *rdtInstances; + RDTAllocation *allocations; + + /*RDT Allocation bitmask MSRs*/ + uint32_t msr_L3_ia32_mask_n[RDT_MAX_L3_MASK_COUNT]; + uint32_t msr_L2_ia32_mask_n[RDT_MAX_L2_MASK_COUNT]; + uint32_t ia32_L2_qos_ext_bw_thrtl_n[RDT_MAX_MBA_THRTL_COUNT]; +}; + +struct RDTStateClass { +}; + +OBJECT_DEFINE_TYPE(RDTState, rdt, RDT, ISA_DEVICE); + +static Property rdt_properties[] = { + DEFINE_PROP_UINT32(RDT_NUM_RMID_PROP, RDTState, rmids, 256), + DEFINE_PROP_END_OF_LIST(), +}; + +static void rdt_init(Object *obj) +{ +} + +static void rdt_finalize(Object *obj) +{ +} + +static void rdt_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->hotpluggable = false; + dc->desc = "RDT"; + dc->user_creatable = true; + + device_class_set_props(dc, rdt_properties); +} + diff --git a/include/hw/i386/rdt.h b/include/hw/i386/rdt.h new file mode 100644 index 0000000000..a21d95b265 --- /dev/null +++ b/include/hw/i386/rdt.h @@ -0,0 +1,25 @@ +/* + * Intel Resource Director Technology (RDT). + * + * Copyright 2024 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef HW_RDT_H +#define HW_RDT_H + +typedef struct RDTState RDTState; +typedef struct RDTStatePerCore RDTStatePerCore; +typedef struct RDTMonitor RDTMonitor; +typedef struct RDTAllocation RDTAllocation; + +#endif diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 1e121acef5..a2941f98eb 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2143,6 +2143,9 @@ struct ArchCPU { struct MemoryRegion *cpu_as_root, *cpu_as_mem, *smram; Notifier machine_done; + /* Help the RDT MSRs find the RDT device */ + struct RDTStatePerCore *rdt; + struct kvm_msrs *kvm_msr_buf; int32_t node_id; /* NUMA node this CPU belongs to */ From patchwork Thu Sep 5 11:22:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792180 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 654B7CD5BAA for ; Thu, 5 Sep 2024 11:24:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZq-0008PZ-3Q; Thu, 05 Sep 2024 07:23:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3iJTZZggKClUJ41A0E573BB381.zB9D19H-01I18ABA3AH.BE3@flex--whendrik.bounces.google.com>) id 1smAZk-0008HU-21 for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:22:56 -0400 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3iJTZZggKClUJ41A0E573BB381.zB9D19H-01I18ABA3AH.BE3@flex--whendrik.bounces.google.com>) id 1smAZh-0002xh-RD for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:22:55 -0400 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-428ea5b1479so5057795e9.0 for ; Thu, 05 Sep 2024 04:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535369; x=1726140169; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=adQIItV2Bd4wpCPsRoA7kna0L5g0qP2kQ/G7mcrHEY8=; b=oaNLpMa0dd4cUyh+1mQbdLhi/p5zPWtNX/TpMwqBklQbHEuSdj4gwvpUB5PiNIqnTe DVk5ak7wc+MixDoBB/oa5VGY78RTDT67JIqctCCdz917ZA4U8fUdpfO4woK6uzv1sjXQ Je8a2aXUjy1IQiCZpFVBjAJyqrjmJ/PC1HPaiwOG/ZWWr/xxAxsEC6F546YP6m7T57bz yf6V8cifBFgJd1XZmCgX3vtWT6QDA9+rgc6bzOlIAAdC+obHVpu6s2Ovg4rn8PKbKPON gtnpQSlTVsedUzUjFqJxOhriTyJPHw7/46nk8FOn9N/239Z+g8kc1QQmT5SuDVbmRMCP F+CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535369; x=1726140169; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=adQIItV2Bd4wpCPsRoA7kna0L5g0qP2kQ/G7mcrHEY8=; b=i/bKNSCa9nVLlTIgVE7hLkvVwj20ookTnb0UwsJ5NOMcW8Mv93wVRZuC2wHI+KlYSO V9gT1uLsAoKng2MKP6rCO2Pop1ILDKCtphLgiRU+pydXX0iACAaroPAxJwNc/4mo6HRt va/DDTztxEHOtuy127ThizzhkuI0S/GVAXMfQerWCQdH1cd9Jb4i6HcXGjtPKie611t6 bTgqOkTaZDRZeb/VY3DS7BWlTqX4PTBu31RYCYHH2jBmP6mcqgGa1Ps0bWItLW2fgu5C ilDocdcl+kHc9I6vAKwGSrCKhS+NOfcVh185iB7egvc8L408We9yVnCKtJ8/aMfOqLG6 FsIw== X-Gm-Message-State: AOJu0YyZBy7JbMX3J992oTGVNBWEuUjCPRQkeUA8j1A4KHqAApjey50+ 2IsGm1eIU42Vf0Ssv+WvJT33/ahYSkP5KY/sqpanROUgjGKNBJxd1U4jxy4pr88Ugh8MpNibBQq gq1hUBsVgG3nPxAYyCVNeEPE/Ni1y0m+W/ucVNM2vVIXVTV3kRL1hGp5q2LL0TigP7nOQR2DV8u Yz5YrFTSZJ+rFSuegZR//fjpuONkXo8/iz34Ib5jmTfg== X-Google-Smtp-Source: AGHT+IEaDUZLVXxp1TJ0G0UGU5ZqHYGZNTMxVFURQxuTNATCDysB9TInrmx8xEad+QB8vg9S34gFODTW+JRPeQ== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:a05:600c:997:b0:42a:b897:826f with SMTP id 5b1f17b1804b1-42bbb436477mr506185e9.5.1725535368898; Thu, 05 Sep 2024 04:22:48 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:31 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-3-whendrik@google.com> Subject: [PATCH v2 2/8] i386: Add init and realize functionality for RDT device. From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2a00:1450:4864:20::34a; envelope-from=3iJTZZggKClUJ41A0E573BB381.zB9D19H-01I18ABA3AH.BE3@flex--whendrik.bounces.google.com; helo=mail-wm1-x34a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Add code to initialize all necessary state for the RDT device. Signed-off-by: Hendrik Wüthrich --- hw/i386/rdt.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hw/i386/rdt.c b/hw/i386/rdt.c index 934f7fbf75..c395ab91a9 100644 --- a/hw/i386/rdt.c +++ b/hw/i386/rdt.c @@ -19,6 +19,7 @@ #include "hw/isa/isa.h" #include "hw/qdev-properties.h" #include "qom/object.h" +#include "target/i386/cpu.h" /* Max counts for allocation masks or CBMs. In other words, the size of respective MSRs*/ #define RDT_MAX_L3_MASK_COUNT 128 @@ -79,8 +80,36 @@ static void rdt_init(Object *obj) { } +static void rdt_realize(DeviceState *dev, Error **errp) +{ + CPUState *cs = first_cpu; + RDTState *rdtDev = RDT(dev); + + rdtDev->rdtInstances = g_malloc(sizeof(RDTStatePerCore) * cs->nr_cores); + CPU_FOREACH(cs) { + RDTStatePerCore *rdt = &rdtDev->rdtInstances[cs->cpu_index]; + X86CPU *cpu = X86_CPU(cs); + + rdt->rdtstate = rdtDev; + cpu->rdt = rdt; + + rdt->monitors = g_malloc(sizeof(RDTMonitor) * rdtDev->rmids); + rdt->rdtstate->allocations = g_malloc(sizeof(RDTAllocation) * rdtDev->rmids); + } +} + static void rdt_finalize(Object *obj) { + CPUState *cs; + RDTState *rdt = RDT(obj); + + CPU_FOREACH(cs) { + RDTStatePerCore *rdtInstance = &rdt->rdtInstances[cs->cpu_index]; + g_free(rdtInstance->monitors); + g_free(rdtInstance->rdtstate->allocations); + } + + g_free(rdt->rdtInstances); } static void rdt_class_init(ObjectClass *klass, void *data) @@ -90,6 +119,7 @@ static void rdt_class_init(ObjectClass *klass, void *data) dc->hotpluggable = false; dc->desc = "RDT"; dc->user_creatable = true; + dc->realize = rdt_realize; device_class_set_props(dc, rdt_properties); } From patchwork Thu Sep 5 11:22:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792181 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 745B0CD5BAA for ; Thu, 5 Sep 2024 11:24:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZr-0008TM-1k; Thu, 05 Sep 2024 07:23:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3i5TZZggKClgM74D3H8A6EE6B4.2ECG4CK-34L4BDED6DK.EH6@flex--whendrik.bounces.google.com>) id 1smAZl-0008KC-IO for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:00 -0400 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3i5TZZggKClgM74D3H8A6EE6B4.2ECG4CK-34L4BDED6DK.EH6@flex--whendrik.bounces.google.com>) id 1smAZi-0002yB-IA for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:22:57 -0400 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-42c80412dc1so5769525e9.2 for ; Thu, 05 Sep 2024 04:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535371; x=1726140171; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=lFaNWg8OWFczEyq2WHl6zYa8BiQZim1ugNOx63N6xVc=; b=O7OPOD7zWqtW63IP4Iz3suheIY9UL3wiMlO9+AM+3S6xW5pYsOIXzzeKo0tHnYBgA8 KvK9mHbfUUv50hxDdi0a7+wrPkfLdjbiv6uByxKC8bw0vMyxWtoJSMEF0osUlODQwYdM nmFQ+nB3x6KePBqWGJ0w5qhr6clTo+TgI0RtpbSWs7FFazvTQ93Wh0E30x3P8sbUuW50 sfqbYgwq87S3Pm4+nWAC3e4cjYGfxs/lf6idxfu5RBJIuae6nKzi3vmIEXvvKEn+xAkH VzhYotOjcLC999ny89aDHicJVX1vkcqfv0omnXegeoY4Mr3OmE4eBxUCsKw7VxQM3maE 7Yww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535371; x=1726140171; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=lFaNWg8OWFczEyq2WHl6zYa8BiQZim1ugNOx63N6xVc=; b=a8w29vlpXKQHZs0RbuooiHJrDzBVjVaHTB6ZBoPCwr3dtqyeL6v/laaxmawKg7rXs4 ieyu9ujTYsYexhqP+xlf5BNGEjMMdi8sWjjnv27v/1FHtVoDk3MfvFHiLUbxQdRn5HEw c7SIwoyUtenx8B6XinhUqx6MIPBbwbTBfVh1b8SagfpO9MHYVVBm14l9bFuZwS8uFPH+ Z4y/i0vYivy5J5W6XRNF8sagYAMTrjNiFIaMyfFK/yOiUL+ROgEdhn6MW52pGw1WhXNL Omiq6PuxjG2syTEoXKFIX9rIr1GYFGiSr3F4FXNB9CA3My/e2o3rcxY60qnvxSe04awt yWcQ== X-Gm-Message-State: AOJu0Yzeo8NLnROwQndZ/FZqRdev2Y3fLmSGKngiriWrlu3D+NQwnvZn Y0smgBe4yNjWiuQqoG7ZI+QFm9d1rB5Uo13ilWpUJezCEEEukoViuu7nO2GE0fosOnSrVm1jiBL eRykFvuE4VatucVee/7g6PVi0EVKVnhGfD5NzTSeJfBEYsH5vkdeTRz1ZKGdhzldXCQOdYU5dR9 L9CVMCtucGWYzyihVNxduda/mQpFi9freoiUbrtdyEzQ== X-Google-Smtp-Source: AGHT+IE9PM3K8A/rfhGKcerdF03Vl+fPELu1Yj80Mt8JhiPeDAXc6RQEz6Zwv3oaiunPrlVRlUyd51T8EZRbfQ== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:adf:ee52:0:b0:374:bd06:7ea3 with SMTP id ffacd0b85a97d-374bd067f89mr24038f8f.2.1725535371198; Thu, 05 Sep 2024 04:22:51 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:32 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-4-whendrik@google.com> Subject: [PATCH v2 3/8] i386: Add RDT functionality From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2a00:1450:4864:20::349; envelope-from=3i5TZZggKClgM74D3H8A6EE6B4.2ECG4CK-34L4BDED6DK.EH6@flex--whendrik.bounces.google.com; helo=mail-wm1-x349.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Add RDT code to Associate CLOSID with RMID / set RMID for monitoring, write COS, and read monitoring data. This patch does not add code for the guest to interact through these things with MSRs, only the actual ability for the RDT device to do them. Signed-off-by: Hendrik Wüthrich --- hw/i386/rdt.c | 124 ++++++++++++++++++++++++++++++++++++++++++ include/hw/i386/rdt.h | 16 ++++++ 2 files changed, 140 insertions(+) diff --git a/hw/i386/rdt.c b/hw/i386/rdt.c index c395ab91a9..288f1fd107 100644 --- a/hw/i386/rdt.c +++ b/hw/i386/rdt.c @@ -21,6 +21,11 @@ #include "qom/object.h" #include "target/i386/cpu.h" +/* RDT Monitoring Event Codes */ +#define RDT_EVENT_L3_OCCUPANCY 1 +#define RDT_EVENT_L3_REMOTE_BW 2 +#define RDT_EVENT_L3_LOCAL_BW 3 + /* Max counts for allocation masks or CBMs. In other words, the size of respective MSRs*/ #define RDT_MAX_L3_MASK_COUNT 128 #define RDT_MAX_L2_MASK_COUNT 48 @@ -29,6 +34,9 @@ #define TYPE_RDT "rdt" #define RDT_NUM_RMID_PROP "rmids" +#define QM_CTR_ERROR (1ULL << 63) +#define QM_CTR_UNAVAILABLE (1ULL << 62) + OBJECT_DECLARE_TYPE(RDTState, RDTStateClass, RDT); struct RDTMonitor { @@ -69,6 +77,122 @@ struct RDTState { struct RDTStateClass { }; +bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc) { + X86CPU *cpu = X86_CPU(current_cpu); + RDTStatePerCore *rdt = cpu->rdt; + RDTAllocation *alloc; + + uint32_t cos_id = (msr_ia32_pqr_assoc & 0xffff0000) >> 16; + uint32_t rmid = msr_ia32_pqr_assoc & 0xffff; + + if (cos_id > RDT_MAX_L3_MASK_COUNT || cos_id > RDT_MAX_L2_MASK_COUNT || + cos_id > RDT_MAX_MBA_THRTL_COUNT || rmid > rdt_max_rmid(rdt)) { + return false; + } + + rdt->active_rmid = rmid; + + alloc = &rdt->rdtstate->allocations[rmid]; + + alloc->active_cos = cos_id; + + return true; +} + +uint32_t rdt_read_l3_mask(uint32_t pos) +{ + X86CPU *cpu = X86_CPU(current_cpu); + RDTStatePerCore *rdt = cpu->rdt; + + uint32_t val = rdt->rdtstate->msr_L3_ia32_mask_n[pos]; + return val; +} + +uint32_t rdt_read_l2_mask(uint32_t pos) +{ + X86CPU *cpu = X86_CPU(current_cpu); + RDTStatePerCore *rdt = cpu->rdt; + + uint32_t val = rdt->rdtstate->msr_L2_ia32_mask_n[pos]; + return val; +} + +uint32_t rdt_read_mba_thrtl(uint32_t pos) +{ + X86CPU *cpu = X86_CPU(current_cpu); + RDTStatePerCore *rdt = cpu->rdt; + + uint32_t val = rdt->rdtstate->ia32_L2_qos_ext_bw_thrtl_n[pos]; + return val; +} + +void rdt_write_msr_l3_mask(uint32_t pos, uint32_t val) { + X86CPU *cpu = X86_CPU(current_cpu); + RDTStatePerCore *rdt = cpu->rdt; + + rdt->rdtstate->msr_L3_ia32_mask_n[pos] = val; +} + +void rdt_write_msr_l2_mask(uint32_t pos, uint32_t val) { + X86CPU *cpu = X86_CPU(current_cpu); + RDTStatePerCore *rdt = cpu->rdt; + + rdt->rdtstate->msr_L2_ia32_mask_n[pos] = val; +} + +void rdt_write_mba_thrtl(uint32_t pos, uint32_t val) { + X86CPU *cpu = X86_CPU(current_cpu); + RDTStatePerCore *rdt = cpu->rdt; + + rdt->rdtstate->ia32_L2_qos_ext_bw_thrtl_n[pos] = val; +} + +uint32_t rdt_max_rmid(RDTStatePerCore *rdt) +{ + RDTState *rdtdev = rdt->rdtstate; + return rdtdev->rmids - 1; +} + +uint64_t rdt_read_event_count(RDTStatePerCore *rdtInstance, uint32_t rmid, uint32_t event_id) +{ + CPUState *cs; + RDTMonitor *mon; + RDTState *rdt = rdtInstance->rdtstate; + + uint32_t count_l3 = 0; + uint32_t count_local = 0; + uint32_t count_remote = 0; + + if (!rdt) { + return 0; + } + + CPU_FOREACH(cs) { + rdtInstance = &rdt->rdtInstances[cs->cpu_index]; + if (rmid >= rdtInstance->monitors->len) { + return QM_CTR_ERROR; + } + mon = &g_array_index(rdtInstance->monitors, RDTMonitor, rmid); + count_l3 += mon->count_l3; + count_local += mon->count_local; + count_remote += mon->count_remote; + } + + switch (event_id) { + case RDT_EVENT_L3_OCCUPANCY: + return count_l3 == 0 ? QM_CTR_UNAVAILABLE : count_l3; + break; + case RDT_EVENT_L3_REMOTE_BW: + return count_remote == 0 ? QM_CTR_UNAVAILABLE : count_remote; + break; + case RDT_EVENT_L3_LOCAL_BW: + return count_local == 0 ? QM_CTR_UNAVAILABLE : count_local; + break; + default: + return QM_CTR_ERROR; + } +} + OBJECT_DEFINE_TYPE(RDTState, rdt, RDT, ISA_DEVICE); static Property rdt_properties[] = { diff --git a/include/hw/i386/rdt.h b/include/hw/i386/rdt.h index a21d95b265..14b1c64b72 100644 --- a/include/hw/i386/rdt.h +++ b/include/hw/i386/rdt.h @@ -17,9 +17,25 @@ #ifndef HW_RDT_H #define HW_RDT_H +#include +#include + typedef struct RDTState RDTState; typedef struct RDTStatePerCore RDTStatePerCore; typedef struct RDTMonitor RDTMonitor; typedef struct RDTAllocation RDTAllocation; +bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc); + +void rdt_write_msr_l3_mask(uint32_t pos, uint32_t val); +void rdt_write_msr_l2_mask(uint32_t pos, uint32_t val); +void rdt_write_mba_thrtl(uint32_t pos, uint32_t val); + +uint32_t rdt_read_l3_mask(uint32_t pos); +uint32_t rdt_read_l2_mask(uint32_t pos); +uint32_t rdt_read_mba_thrtl(uint32_t pos); + +uint64_t rdt_read_event_count(RDTStatePerCore *rdt, uint32_t rmid, uint32_t event_id); +uint32_t rdt_max_rmid(RDTStatePerCore *rdt); + #endif From patchwork Thu Sep 5 11:22:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792179 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 7C7D0CD5BAA for ; Thu, 5 Sep 2024 11:24:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZr-0008V4-Dh; Thu, 05 Sep 2024 07:23:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3jZTZZggKCloO96F5JAC8GG8D6.4GEI6EM-56N6DFGF8FM.GJ8@flex--whendrik.bounces.google.com>) id 1smAZp-0008LZ-4w for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:01 -0400 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3jZTZZggKCloO96F5JAC8GG8D6.4GEI6EM-56N6DFGF8FM.GJ8@flex--whendrik.bounces.google.com>) id 1smAZl-0002yW-9K for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:00 -0400 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-374c581ce35so390039f8f.3 for ; Thu, 05 Sep 2024 04:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535374; x=1726140174; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=zCigvg6qxJM1SCQofdH94q2bhvwsYEgiSEWRDdMjOTY=; b=OwalraMAihR2B0cWm8IpBrFlkC2jTtF7CfQAjqokOvql66LgrA8Boc7GQFjZXmDMHg lLSQ41bf/w76cPFwsYTu8R8ueUFPUkQhouBiph9NcC/HkBiZr8O3R2F/2W4NesbM2DCw 9omopRT1MUAZ4DCfFbvuoKNqa3TKmTpaQug60f2l8k2Bu9sib8lYtmgsgXP+dSm0es8j EJTC8oMpUKgxFbyB7SmfbJXGvJrrbFwUomEpsjWAQAER0djqHq/ZtYMZcP0n6a6qoouT LOD7UWV0E64ATDXsV/M9n/FhKf7GDuFSAeVxy9Ts5O4NakS7czrmkn8Hz/MiiVwyb3Ld VL7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535374; x=1726140174; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=zCigvg6qxJM1SCQofdH94q2bhvwsYEgiSEWRDdMjOTY=; b=fFSb+sO4ch8qnW5hp7cTxwBTjJRnP1N5TDNF6o7GAWGmfVUqrLtdZamlzH7qoL7SVG xR+cTn6EUzmYh19fFv5ylTsQ3RBIJI06nMRqXfFqU/s8Zh2YK4tlSB4RHJEd81cJoWFe G7n3mEReCngoWuMIit7Vei2QSD1R3wbyX+JL1I266LvLCIUIBaXsoBtgugihwuJz90ri fNqIw1HtlK5zOwldaO3jg+eMlTeyNGg4V87NH3K7MSVo26Ez8LI+WsrCXAjEBGlwt7NJ wIfiuLwPmsirjJCqXd4xGy9w1A6dxa1AMREEMxudOZOMEFoTe3lEnumaFXc9T6fTnA2n oeFQ== X-Gm-Message-State: AOJu0YyY5dSVDjD2JMKBa4aWMn4EwROiV3SWH7uGujhve5zBx02OJFMs rpLGIDJ0UMu9aOcH+yztf6BXA3T184pUPQl0jYZSixHiuYJp1Q/PiE9zWKuF+iDv3OJU+A69ih0 qUyGek0VlCGrm/8bzi8ajA59QnIejEtciYp17GOuF47asVgNGb+/5Z12lATf1e+MB3VgBlNRd9b ol/SkfycD+7VzqqGE/2zNZdmFcKs9YSawFk7764+Z6aQ== X-Google-Smtp-Source: AGHT+IGUCeJ5pqlusSMAD9m8/pn8+ka9wvYb7z11WwlHWbbDqUNRIRCl3VUDSCer0XVp/buXu+F6C5rTMgVWRQ== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:a5d:56c2:0:b0:374:cef0:fd45 with SMTP id ffacd0b85a97d-374cef1007amr17833f8f.11.1725535373445; Thu, 05 Sep 2024 04:22:53 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:33 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-5-whendrik@google.com> Subject: [PATCH v2 4/8] i386: Add RDT device interface through MSRs From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2a00:1450:4864:20::449; envelope-from=3jZTZZggKCloO96F5JAC8GG8D6.4GEI6EM-56N6DFGF8FM.GJ8@flex--whendrik.bounces.google.com; helo=mail-wr1-x449.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Implement rdmsr and wrmsr for the following MSRs: * MSR_IA32_PQR_ASSOC * MSR_IA32_QM_EVTSEL * MSR_IA32_QM_CTR * IA32_L3_QOS_Mask_n * IA32_L2_QOS_Mask_n * IA32_L2_QoS_Ext_BW_Thrtl_n This allows for the guest to call RDT-internal functions to associate an RMID with a CLOSID / set an active RMID for monitoring, read monitoring data, and set classes of service. Signed-off-by: Hendrik Wüthrich --- hw/i386/rdt.c | 22 ++++---- include/hw/i386/rdt.h | 4 ++ target/i386/cpu.h | 14 +++++ target/i386/tcg/sysemu/misc_helper.c | 84 ++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 12 deletions(-) diff --git a/hw/i386/rdt.c b/hw/i386/rdt.c index 288f1fd107..d3713073c5 100644 --- a/hw/i386/rdt.c +++ b/hw/i386/rdt.c @@ -77,6 +77,10 @@ struct RDTState { struct RDTStateClass { }; +uint32_t rdt_get_cpuid_10_1_edx_cos_max(void) { return RDT_MAX_L3_MASK_COUNT; } +uint32_t rdt_get_cpuid_10_2_edx_cos_max(void) { return RDT_MAX_L2_MASK_COUNT; } +uint32_t rdt_get_cpuid_10_3_edx_cos_max(void) { return RDT_MAX_MBA_THRTL_COUNT; } + bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc) { X86CPU *cpu = X86_CPU(current_cpu); RDTStatePerCore *rdt = cpu->rdt; @@ -86,7 +90,7 @@ bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc) { uint32_t rmid = msr_ia32_pqr_assoc & 0xffff; if (cos_id > RDT_MAX_L3_MASK_COUNT || cos_id > RDT_MAX_L2_MASK_COUNT || - cos_id > RDT_MAX_MBA_THRTL_COUNT || rmid > rdt_max_rmid(rdt)) { + cos_id > RDT_MAX_MBA_THRTL_COUNT || rmid > rdt_max_rmid(rdt)) { return false; } @@ -104,8 +108,7 @@ uint32_t rdt_read_l3_mask(uint32_t pos) X86CPU *cpu = X86_CPU(current_cpu); RDTStatePerCore *rdt = cpu->rdt; - uint32_t val = rdt->rdtstate->msr_L3_ia32_mask_n[pos]; - return val; + return rdt->rdtstate->msr_L3_ia32_mask_n[pos]; } uint32_t rdt_read_l2_mask(uint32_t pos) @@ -113,8 +116,7 @@ uint32_t rdt_read_l2_mask(uint32_t pos) X86CPU *cpu = X86_CPU(current_cpu); RDTStatePerCore *rdt = cpu->rdt; - uint32_t val = rdt->rdtstate->msr_L2_ia32_mask_n[pos]; - return val; + return rdt->rdtstate->msr_L2_ia32_mask_n[pos]; } uint32_t rdt_read_mba_thrtl(uint32_t pos) @@ -122,8 +124,7 @@ uint32_t rdt_read_mba_thrtl(uint32_t pos) X86CPU *cpu = X86_CPU(current_cpu); RDTStatePerCore *rdt = cpu->rdt; - uint32_t val = rdt->rdtstate->ia32_L2_qos_ext_bw_thrtl_n[pos]; - return val; + return rdt->rdtstate->ia32_L2_qos_ext_bw_thrtl_n[pos]; } void rdt_write_msr_l3_mask(uint32_t pos, uint32_t val) { @@ -153,7 +154,8 @@ uint32_t rdt_max_rmid(RDTStatePerCore *rdt) return rdtdev->rmids - 1; } -uint64_t rdt_read_event_count(RDTStatePerCore *rdtInstance, uint32_t rmid, uint32_t event_id) +uint64_t rdt_read_event_count(RDTStatePerCore *rdtInstance, + uint32_t rmid, uint32_t event_id) { CPUState *cs; RDTMonitor *mon; @@ -181,13 +183,10 @@ uint64_t rdt_read_event_count(RDTStatePerCore *rdtInstance, uint32_t rmid, uint3 switch (event_id) { case RDT_EVENT_L3_OCCUPANCY: return count_l3 == 0 ? QM_CTR_UNAVAILABLE : count_l3; - break; case RDT_EVENT_L3_REMOTE_BW: return count_remote == 0 ? QM_CTR_UNAVAILABLE : count_remote; - break; case RDT_EVENT_L3_LOCAL_BW: return count_local == 0 ? QM_CTR_UNAVAILABLE : count_local; - break; default: return QM_CTR_ERROR; } @@ -247,4 +246,3 @@ static void rdt_class_init(ObjectClass *klass, void *data) device_class_set_props(dc, rdt_properties); } - diff --git a/include/hw/i386/rdt.h b/include/hw/i386/rdt.h index 14b1c64b72..ec82a149f2 100644 --- a/include/hw/i386/rdt.h +++ b/include/hw/i386/rdt.h @@ -25,6 +25,10 @@ typedef struct RDTStatePerCore RDTStatePerCore; typedef struct RDTMonitor RDTMonitor; typedef struct RDTAllocation RDTAllocation; +uint32_t rdt_get_cpuid_10_1_edx_cos_max(void); +uint32_t rdt_get_cpuid_10_2_edx_cos_max(void); +uint32_t rdt_get_cpuid_10_3_edx_cos_max(void); + bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc); void rdt_write_msr_l3_mask(uint32_t pos, uint32_t val); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a2941f98eb..e722fd4622 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -574,6 +574,17 @@ typedef enum X86Seg { #define MSR_IA32_VMX_TRUE_ENTRY_CTLS 0x00000490 #define MSR_IA32_VMX_VMFUNC 0x00000491 +#define MSR_IA32_QM_EVTSEL 0x0c8d +#define MSR_IA32_QM_CTR 0x0c8e +#define MSR_IA32_PQR_ASSOC 0x0c8f + +#define MSR_IA32_L3_CBM_BASE 0x0c90 +#define MSR_IA32_L3_MASKS_END 0x0d0f +#define MSR_IA32_L2_CBM_BASE 0x0d10 +#define MSR_IA32_L2_CBM_END 0x0d4f +#define MSR_IA32_L2_QOS_Ext_BW_Thrtl_BASE 0xd50 +#define MSR_IA32_L2_QOS_Ext_BW_Thrtl_END 0xd80 + #define MSR_APIC_START 0x00000800 #define MSR_APIC_END 0x000008ff @@ -1778,6 +1789,9 @@ typedef struct CPUArchState { uint64_t msr_ia32_feature_control; uint64_t msr_ia32_sgxlepubkeyhash[4]; + uint64_t msr_ia32_qm_evtsel; + uint64_t msr_ia32_pqr_assoc; + uint64_t msr_fixed_ctr_ctrl; uint64_t msr_global_ctrl; uint64_t msr_global_status; diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/misc_helper.c index 094aa56a20..bbfd5c0219 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -25,6 +25,7 @@ #include "exec/address-spaces.h" #include "exec/exec-all.h" #include "tcg/helper-tcg.h" +#include "hw/i386/rdt.h" #include "hw/i386/apic.h" void helper_outb(CPUX86State *env, uint32_t port, uint32_t data) @@ -293,6 +294,47 @@ void helper_wrmsr(CPUX86State *env) env->msr_bndcfgs = val; cpu_sync_bndcs_hflags(env); break; + case MSR_IA32_QM_EVTSEL: + env->msr_ia32_qm_evtsel = val; + break; + case MSR_IA32_PQR_ASSOC: + { + env->msr_ia32_pqr_assoc = val; + + if (!rdt_associate_rmid_cos(val)) + goto error; + break; + } + case MSR_IA32_L3_CBM_BASE ... MSR_IA32_L3_MASKS_END: + { + uint32_t pos = (uint32_t)env->regs[R_ECX] - MSR_IA32_L3_CBM_BASE; + + if (pos >= rdt_get_cpuid_10_1_edx_cos_max()) { + goto error; + } + rdt_write_msr_l3_mask(pos, val); + break; + } + case MSR_IA32_L2_CBM_BASE ... MSR_IA32_L2_CBM_END: + { + uint32_t pos = (uint32_t)env->regs[R_ECX] - MSR_IA32_L2_CBM_BASE; + + if (pos >= rdt_get_cpuid_10_2_edx_cos_max()) { + goto error; + } + rdt_write_msr_l2_mask(pos, val); + break; + } + case MSR_IA32_L2_QOS_Ext_BW_Thrtl_BASE ... MSR_IA32_L2_QOS_Ext_BW_Thrtl_END: + { + uint32_t pos = (uint32_t)env->regs[R_ECX] - MSR_IA32_L2_QOS_Ext_BW_Thrtl_BASE; + + if (pos >= rdt_get_cpuid_10_3_edx_cos_max()) { + goto error; + } + rdt_write_mba_thrtl(pos, val); + break; + } case MSR_APIC_START ... MSR_APIC_END: { int ret; int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START; @@ -472,6 +514,47 @@ void helper_rdmsr(CPUX86State *env) val = (cs->nr_threads * cs->nr_cores) | (cs->nr_cores << 16); break; } + case MSR_IA32_QM_CTR: + val = rdt_read_event_count(x86_cpu->rdt, + (env->msr_ia32_qm_evtsel >> 32) & 0xff, + env->msr_ia32_qm_evtsel & 0xff); + break; + case MSR_IA32_QM_EVTSEL: + val = env->msr_ia32_qm_evtsel; + break; + case MSR_IA32_PQR_ASSOC: + val = env->msr_ia32_pqr_assoc; + break; + case MSR_IA32_L3_CBM_BASE ... MSR_IA32_L3_MASKS_END: + { + uint32_t pos = (uint32_t)env->regs[R_ECX] - MSR_IA32_L3_CBM_BASE; + + if (pos >= rdt_get_cpuid_10_1_edx_cos_max()) { + raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC()); + } + val = rdt_read_l3_mask(pos); + break; + } + case MSR_IA32_L2_CBM_BASE ... MSR_IA32_L2_CBM_END: + { + uint32_t pos = (uint32_t)env->regs[R_ECX] - MSR_IA32_L2_CBM_BASE; + + if (pos >= rdt_get_cpuid_10_2_edx_cos_max()) { + raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC()); + } + val = rdt_read_l2_mask(pos); + break; + } + case MSR_IA32_L2_QOS_Ext_BW_Thrtl_BASE ... MSR_IA32_L2_QOS_Ext_BW_Thrtl_END: + { + uint32_t pos = (uint32_t)env->regs[R_ECX] - MSR_IA32_L2_QOS_Ext_BW_Thrtl_BASE; + + if (pos >= rdt_get_cpuid_10_3_edx_cos_max()) { + raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC()); + } + val = rdt_read_mba_thrtl(pos); + break; + } case MSR_APIC_START ... MSR_APIC_END: { int ret; int index = (uint32_t)env->regs[R_ECX] - MSR_APIC_START; @@ -499,6 +582,7 @@ void helper_rdmsr(CPUX86State *env) } env->regs[R_EAX] = (uint32_t)(val); env->regs[R_EDX] = (uint32_t)(val >> 32); + return; } void helper_flush_page(CPUX86State *env, target_ulong addr) From patchwork Thu Sep 5 11:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792182 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 C8332CD5BA9 for ; Thu, 5 Sep 2024 11:24:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZq-0008SD-Od; Thu, 05 Sep 2024 07:23:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3j5TZZggKClwQB8H7LCEAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--whendrik.bounces.google.com>) id 1smAZp-0008Le-4w for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:01 -0400 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3j5TZZggKClwQB8H7LCEAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--whendrik.bounces.google.com>) id 1smAZn-0002yv-2f for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:00 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6b41e02c293so31876367b3.0 for ; Thu, 05 Sep 2024 04:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535375; x=1726140175; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=MSiRcbL75mpfkirQNgRVAzM3JHWeGu9JpxRYqebZqac=; b=vattIqlmTixljg0+dOrShhBDL1azCZJAMMRs/DvaDcR6jMfnGy1Gkf3tvFJxUlGUC+ sgbyTNF5E7f4R2VM2nccr9TNdz1kLEW6HDioH2btU5lVpPuAbf9kpIGPz1n9wqhrHv2V Bp1kUtDaWsOHn78SVH9ZJ4eSwkxnXD/ZQRQO8hT9uJxt6wdFW1H90U40tIU4Efy4RBGl fJcu9h+Ytsy6v1EKpEtBgYeklUEH7+GRsiP7oouUDcEM1vthungspWaobsBKYcmAiUgH jWt/2FbLvEzvCIESOZUhKARBDBivgWouUEqphFriN3gchLXKDqHFfLTJwA2GLFZCtqMU qbjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535375; x=1726140175; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=MSiRcbL75mpfkirQNgRVAzM3JHWeGu9JpxRYqebZqac=; b=oz2H4g6Oe5OWUvBombuO9OeqTqM1Nz8A1WdKlGowDXyS1qm5PKCPLZ0iwtq8VcRzyv MIcY7C1IDbmpBSXAHm2kYKi+aRs/nkpQiiGGTso/WLyp+q29rQ9DE7PCOvMlXsTHZky9 8HcLSjjbOkQtXJICUckwEnWJ+XHyuGXsGG1e6nmkwb+BALTAsZR5kEgiySjpA5avnpsr xWBX4mMmTPhKZu3hERyRgNzI0qVDyBXanyRMGJ8O5+8mp7AX0OBF+ZSOSVm69lHIpMfw YYFtmjvZW0/ZW3EgCrR7sjxeGi0Nk3xnpCvnvXqS9sbN5dOGIF4JAWIAQgGOjd9/lqad arVA== X-Gm-Message-State: AOJu0Yy4nuA6UvoMgb1mbq5a2oIp6ManK9Vl8hRm1TuT0VkgHlZ/CHnR zK1Jsf/phZGIMg1tk0oW2f8bTPV7UkaQ8xESk2Vn5q/VHByrtJHWYBJDKBff9Jh4GUu90NZiJss r6cJ3GBPuv1I1C0TzTbRYfH2nzDxBQf7x8njP55p5kZWU40gH659fN8qA7BHEmBWo1DzVaczcu9 gvWOGc8DKgBmWqhUtI/IQ1mfa7SSaJRLgFdCJDJyQ6LA== X-Google-Smtp-Source: AGHT+IF/K6DXYvpGUzetxdrmLF/OK3g9Ok1Y3yW0uLXsnE5YO1ihzOQhb6G+ZeCNLIRhPclyg+2FU/3LApzpww== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:a05:690c:6a11:b0:6d6:88a1:2e58 with SMTP id 00721157ae682-6d688a13207mr12637037b3.8.1725535375470; Thu, 05 Sep 2024 04:22:55 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:34 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-6-whendrik@google.com> Subject: [PATCH v2 5/8] i386: Add CPUID enumeration for RDT From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2607:f8b0:4864:20::1149; envelope-from=3j5TZZggKClwQB8H7LCEAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--whendrik.bounces.google.com; helo=mail-yw1-x1149.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Add CPUID enumeration for intel RDT monitoring and allocation, as well as the flags used in the enumeration code. Signed-off-by: Hendrik Wüthrich --- hw/i386/rdt.c | 33 +++++++++++++++++++++++ include/hw/i386/rdt.h | 31 +++++++++++++++++++++ target/i386/cpu.c | 63 +++++++++++++++++++++++++++++++++++++++++++ target/i386/cpu.h | 5 ++++ 4 files changed, 132 insertions(+) diff --git a/hw/i386/rdt.c b/hw/i386/rdt.c index d3713073c5..3dddeeaba3 100644 --- a/hw/i386/rdt.c +++ b/hw/i386/rdt.c @@ -31,6 +31,20 @@ #define RDT_MAX_L2_MASK_COUNT 48 #define RDT_MAX_MBA_THRTL_COUNT 31 +/* RDT L3 Allocation features */ +#define CPUID_10_1_EAX_CBM_LENGTH 0xf +#define CPUID_10_1_EBX_CBM 0x0 +#define CPUID_10_1_ECX_CDP 0x0 // to enable, it would be (1U << 2) +#define CPUID_10_1_EDX_COS_MAX MAX_L3_MASK_COUNT +/* RDT L2 Allocation features*/ +#define CPUID_10_2_EAX_CBM_LENGTH 0xf +#define CPUID_10_2_EBX_CBM 0x0 +#define CPUID_10_2_EDX_COS_MAX MAX_L2_MASK_COUNT +/* RDT MBA features */ +#define CPUID_10_3_EAX_THRTL_MAX 89 +#define CPUID_10_3_ECX_LINEAR_RESPONSE (1U << 2) +#define CPUID_10_3_EDX_COS_MAX MAX_MBA_THRTL_COUNT + #define TYPE_RDT "rdt" #define RDT_NUM_RMID_PROP "rmids" @@ -77,8 +91,27 @@ struct RDTState { struct RDTStateClass { }; +uint32_t rdt_get_cpuid_15_0_edx_l3(void) { return CPUID_15_1_EDX_L3_OCCUPANCY | CPUID_15_1_EDX_L3_TOTAL_BW | CPUID_15_1_EDX_L3_LOCAL_BW; } + +uint32_t rdt_cpuid_15_1_edx_l3_total_bw_enabled(void) { return CPUID_15_1_EDX_L3_TOTAL_BW; } +uint32_t rdt_cpuid_15_1_edx_l3_local_bw_enabled(void) { return CPUID_15_1_EDX_L3_LOCAL_BW; } +uint32_t rdt_cpuid_15_1_edx_l3_occupancy_enabled(void) { return CPUID_15_1_EDX_L3_OCCUPANCY; } + +uint32_t rdt_cpuid_10_0_ebx_l3_cat_enabled(void) { return CPUID_10_0_EBX_L3_CAT; } +uint32_t rdt_cpuid_10_0_ebx_l2_cat_enabled(void) { return CPUID_10_0_EBX_L2_CAT; } +uint32_t rdt_cpuid_10_0_ebx_l2_mba_enabled(void) { return CPUID_10_0_EBX_MBA; } + +uint32_t rdt_get_cpuid_10_1_eax_cbm_length(void) { return CPUID_10_1_EAX_CBM_LENGTH; } +uint32_t rdt_cpuid_10_1_ebx_cbm_enabled(void) { return CPUID_10_1_EBX_CBM; } +uint32_t rdt_cpuid_10_1_ecx_cdp_enabled(void) { return CPUID_10_1_ECX_CDP; } uint32_t rdt_get_cpuid_10_1_edx_cos_max(void) { return RDT_MAX_L3_MASK_COUNT; } + +uint32_t rdt_get_cpuid_10_2_eax_cbm_length(void) { return CPUID_10_2_EAX_CBM_LENGTH; } +uint32_t rdt_cpuid_10_2_ebx_cbm_enabled(void) { return CPUID_10_2_EBX_CBM; } uint32_t rdt_get_cpuid_10_2_edx_cos_max(void) { return RDT_MAX_L2_MASK_COUNT; } + +uint32_t rdt_get_cpuid_10_3_eax_thrtl_max(void) { return CPUID_10_3_EAX_THRTL_MAX; } +uint32_t rdt_cpuid_10_3_eax_linear_response_enabled(void) { return CPUID_10_3_ECX_LINEAR_RESPONSE; } uint32_t rdt_get_cpuid_10_3_edx_cos_max(void) { return RDT_MAX_MBA_THRTL_COUNT; } bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc) { diff --git a/include/hw/i386/rdt.h b/include/hw/i386/rdt.h index ec82a149f2..57d2fa5b77 100644 --- a/include/hw/i386/rdt.h +++ b/include/hw/i386/rdt.h @@ -20,13 +20,44 @@ #include #include +/* RDT L3 Cache Monitoring Technology */ +#define CPUID_15_0_EDX_L3 (1U << 1) +#define CPUID_15_1_EDX_L3_OCCUPANCY (1U << 0) +#define CPUID_15_1_EDX_L3_TOTAL_BW (1U << 1) +#define CPUID_15_1_EDX_L3_LOCAL_BW (1U << 2) + +/* RDT Cache Allocation Technology */ +#define CPUID_10_0_EBX_L3_CAT (1U << 1) +#define CPUID_10_0_EBX_L2_CAT (1U << 2) +#define CPUID_10_0_EBX_MBA (1U << 3) +#define CPUID_10_0_EDX CPUID_10_0_EBX_L3_CAT | CPUID_10_0_EBX_L2_CAT | CPUID_10_0_EBX_MBA + typedef struct RDTState RDTState; typedef struct RDTStatePerCore RDTStatePerCore; typedef struct RDTMonitor RDTMonitor; typedef struct RDTAllocation RDTAllocation; +uint32_t rdt_get_cpuid_15_0_edx_l3(void); + +uint32_t rdt_cpuid_15_1_edx_l3_total_bw_enabled(void); +uint32_t rdt_cpuid_15_1_edx_l3_local_bw_enabled(void); +uint32_t rdt_cpuid_15_1_edx_l3_occupancy_enabled(void); + +uint32_t rdt_cpuid_10_0_ebx_l3_cat_enabled(void); +uint32_t rdt_cpuid_10_0_ebx_l2_cat_enabled(void); +uint32_t rdt_cpuid_10_0_ebx_l2_mba_enabled(void); + +uint32_t rdt_get_cpuid_10_1_eax_cbm_length(void); +uint32_t rdt_cpuid_10_1_ebx_cbm_enabled(void); +uint32_t rdt_cpuid_10_1_ecx_cdp_enabled(void); uint32_t rdt_get_cpuid_10_1_edx_cos_max(void); + +uint32_t rdt_get_cpuid_10_2_eax_cbm_length(void); +uint32_t rdt_cpuid_10_2_ebx_cbm_enabled(void); uint32_t rdt_get_cpuid_10_2_edx_cos_max(void); + +uint32_t rdt_get_cpuid_10_3_eax_thrtl_max(void); +uint32_t rdt_cpuid_10_3_eax_linear_response_enabled(void); uint32_t rdt_get_cpuid_10_3_edx_cos_max(void); bool rdt_associate_rmid_cos(uint64_t msr_ia32_pqr_assoc); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4688d140c2..a5c4e3c463 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -42,6 +42,7 @@ #include "hw/boards.h" #include "hw/i386/sgx-epc.h" #endif +#include "hw/i386/rdt.h" #include "disas/capstone.h" #include "cpu-internal.h" @@ -6629,6 +6630,68 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, assert(!(*eax & ~0x1f)); *ebx &= 0xffff; /* The count doesn't need to be reliable. */ break; +#ifndef CONFIG_USER_ONLY + case 0xF: + /* Shared Resource Monitoring Enumeration Leaf */ + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; + if (!(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_PQM)) + break; + assert(cpu->rdt); + /* Non-zero count is ResId */ + switch (count) { + /* Monitoring Resource Type Enumeration */ + case 0: + *edx = env->features[FEAT_RDT_15_0_EDX]; + *ebx = rdt_max_rmid(cpu->rdt); + break; + case 1: + *ebx = 1; + *ecx = rdt_max_rmid(cpu->rdt); + *edx = rdt_cpuid_15_1_edx_l3_total_bw_enabled() | + rdt_cpuid_15_1_edx_l3_local_bw_enabled() | + rdt_cpuid_15_1_edx_l3_occupancy_enabled(); + break; + } + break; + case 0x10: + /* Shared Resource Director Technology Allocation Enumeration Leaf */ + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; + if (!(env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_PQE)) + break; + assert(cpu->rdt); + /* Non-zero count is ResId */ + switch (count) { + /* Cache Allocation Technology Available Resource Types */ + case 0: + *ebx |= rdt_cpuid_10_0_ebx_l3_cat_enabled(); + *ebx |= rdt_cpuid_10_0_ebx_l2_cat_enabled(); + *ebx |= rdt_cpuid_10_0_ebx_l2_mba_enabled(); + break; + case 1: + *eax = rdt_get_cpuid_10_1_eax_cbm_length(); + *ebx = rdt_cpuid_10_1_ebx_cbm_enabled(); + *ecx |= rdt_cpuid_10_1_ecx_cdp_enabled(); + *edx = rdt_get_cpuid_10_1_edx_cos_max(); + break; + case 2: + *eax = rdt_get_cpuid_10_2_eax_cbm_length(); + *ebx = rdt_cpuid_10_2_ebx_cbm_enabled(); + *edx = rdt_get_cpuid_10_2_edx_cos_max(); + break; + case 3: + *eax = rdt_get_cpuid_10_3_eax_thrtl_max(); + *ecx = rdt_cpuid_10_3_eax_linear_response_enabled(); + *edx = rdt_get_cpuid_10_3_edx_cos_max(); + break; + } + break; +#endif case 0x1C: if (cpu->enable_pmu && (env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_ARCH_LBR)) { x86_cpu_get_supported_cpuid(0x1C, 0, eax, ebx, ecx, edx); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index e722fd4622..14c1d7d66b 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -673,6 +673,7 @@ typedef enum FeatureWord { FEAT_XSAVE_XSS_HI, /* CPUID[EAX=0xd,ECX=1].EDX */ FEAT_7_1_EDX, /* CPUID[EAX=7,ECX=1].EDX */ FEAT_7_2_EDX, /* CPUID[EAX=7,ECX=2].EDX */ + FEAT_RDT_15_0_EDX, /* CPUID[EAX=0xf,ECX=0].EDX (RDT CMT/MBM) */ FEATURE_WORDS, } FeatureWord; @@ -843,8 +844,12 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); #define CPUID_7_0_EBX_INVPCID (1U << 10) /* Restricted Transactional Memory */ #define CPUID_7_0_EBX_RTM (1U << 11) +/* Resource Director Technology Monitoring */ +#define CPUID_7_0_EBX_PQM (1U << 12) /* Memory Protection Extension */ #define CPUID_7_0_EBX_MPX (1U << 14) +/* Resource Director Technology Allocation */ +#define CPUID_7_0_EBX_PQE (1U << 15) /* AVX-512 Foundation */ #define CPUID_7_0_EBX_AVX512F (1U << 16) /* AVX-512 Doubleword & Quadword Instruction */ From patchwork Thu Sep 5 11:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792176 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 87638CD5BA9 for ; Thu, 5 Sep 2024 11:23:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZt-0000D1-L2; Thu, 05 Sep 2024 07:23:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3kZTZZggKCl4SDAJ9NEGCKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--whendrik.bounces.google.com>) id 1smAZq-0008Qx-D2 for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:02 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3kZTZZggKCl4SDAJ9NEGCKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--whendrik.bounces.google.com>) id 1smAZn-0002zM-N1 for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:02 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e03623b24ddso1851150276.1 for ; Thu, 05 Sep 2024 04:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535378; x=1726140178; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=ObfI1qjsjD3CazvP1CUjFiKi6o6xv4BVYTjj0LflWMA=; b=vWJ48TdY1OjyE9YKcSAcu38SswQf9ya2kPHbRtAQ/6S7L6vqi7nWhn43bpgZVrELp/ a9/iEQCzcSsn18vBOe4DXXaaT7nM3Znbj3p2xk3m4Y1FMWdOiovPvirlE0mU5z+3yEW8 JX6IMBsmh0yBJ+J1AnJHnNcTSu1yPmn9jczhrL6G6Kmp2EBCWOG1G3LLagdwTXol0YiW NraRzJFQLWiDgEqwJGZtCmsrs6x9s4tcI5Pp10IDhm1j2I1opHZPIZFu14xbpO2r4zXo cL7MbTq9iTR5KJOj8/QgB4Jeo9wpHGgoVRnsBBSgrJlj4mSCR1Cv1vLIALnaUnOVm3O4 DwAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535378; x=1726140178; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=ObfI1qjsjD3CazvP1CUjFiKi6o6xv4BVYTjj0LflWMA=; b=RnJj+o+ygFJIf3kk7s5qbZF0ZwiDTHUHnei6EYVFZE1HEkLK0APlNFk2QOc5uR7E8s wrOm8BRQbjeo9XIMTDFJgc2Sjab8via7JzmmCkUetkn5IAQEfLIBxeUdE/BbOGzreZgo bXOZe4DdQUjD4w5gndXGrYnu2Irt5JdT3TNnA8VThIJCoyqtWd9TWKWnROIonpOytDr8 9m5ItPT4B3tw0dzIaah2+myL1bJTGYtPlJZQZh89JZFAMgDdfGJKroeyjAJlLRMwiGbz l1IE/OOtWQ2JYMcx8sUq+GmKEDtyDAiXTagewzvNE7yL/7P7O/8NyJNo3NdFF1VMzhyR SS/w== X-Gm-Message-State: AOJu0YyeaPSw5eG8udJbQrU1s02fYD8TEg5b7iWbqoU3C727EwRHvDp0 CkXHm+iDrCmUzHgHJAdqqTQDfHX7HyL08zQpXm16XLz4ZXCvlGYMbXEpoSJ33q+EG8YVzZSDuCU jtbxefkctM3MaHmiosCh3CUc5HKZwtF2Nj5d2uEbHP5eO5qWb48uDVk49SKQSzLG3d+58sgs19E HOhq+beao4n4YQPTeXUfTSwt2COS7HkYNhIJR35+vThg== X-Google-Smtp-Source: AGHT+IFCDzMleyBHegtwLc/Sjf0wVNg6dVmQOx3JGgoGiKLObTOLdyrqPdxxbG0xvKHxjJudBH+fR3dgthXW7A== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:a25:c4c2:0:b0:e1a:6eac:3d0f with SMTP id 3f1490d57ef6-e1a7a1b67e6mr99025276.8.1725535377649; Thu, 05 Sep 2024 04:22:57 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:35 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-7-whendrik@google.com> Subject: [PATCH v2 6/8] i386: Add RDT feature flags. From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3kZTZZggKCl4SDAJ9NEGCKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--whendrik.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Add RDT features to feature word / TCG. Signed-off-by: Hendrik Wüthrich --- target/i386/cpu.c | 30 ++++++++++++++++++++++++++++-- target/i386/cpu.h | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a5c4e3c463..36e19bfa8c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -864,7 +864,8 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, CPUID_7_0_EBX_CLFLUSHOPT | \ CPUID_7_0_EBX_CLWB | CPUID_7_0_EBX_MPX | CPUID_7_0_EBX_FSGSBASE | \ CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_RDSEED | \ - CPUID_7_0_EBX_SHA_NI | CPUID_7_0_EBX_KERNEL_FEATURES) + CPUID_7_0_EBX_SHA_NI | CPUID_7_0_EBX_KERNEL_FEATURES | \ + CPUID_7_0_EBX_PQM | CPUID_7_0_EBX_PQE) /* missing: CPUID_7_0_EBX_HLE CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM */ @@ -900,6 +901,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, #define TCG_SGX_12_0_EAX_FEATURES 0 #define TCG_SGX_12_0_EBX_FEATURES 0 #define TCG_SGX_12_1_EAX_FEATURES 0 +#define TCG_RDT_15_0_EDX_FEATURES CPUID_15_0_EDX_L3 #if defined CONFIG_USER_ONLY #define CPUID_8000_0008_EBX_KERNEL_FEATURES (CPUID_8000_0008_EBX_IBPB | \ @@ -1057,7 +1059,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { "fsgsbase", "tsc-adjust", "sgx", "bmi1", "hle", "avx2", NULL, "smep", "bmi2", "erms", "invpcid", "rtm", - NULL, NULL, "mpx", NULL, + "rdt-m", NULL, "mpx", "rdt-a", "avx512f", "avx512dq", "rdseed", "adx", "smap", "avx512ifma", "pcommit", "clflushopt", "clwb", "intel-pt", "avx512pf", "avx512er", @@ -1607,6 +1609,30 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { }, .tcg_features = TCG_SGX_12_1_EAX_FEATURES, }, + + [FEAT_RDT_10_0_EBX] = { + .type = CPUID_FEATURE_WORD, + .feat_names = { + NULL, "l3-cat", "l2-cat", "mba" + }, + .cpuid = { + .eax = 0x10, + .needs_ecx = true, .ecx = 0, + .reg = R_EBX, + } + }, + [FEAT_RDT_15_0_EDX] = { + .type = CPUID_FEATURE_WORD, + .feat_names = { + [1] = "l3-cmt" + }, + .cpuid = { + .eax = 0xf, + .needs_ecx = true, .ecx = 0, + .reg = R_EDX, + }, + .tcg_features = TCG_RDT_15_0_EDX_FEATURES, + }, }; typedef struct FeatureMask { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 14c1d7d66b..99a5288061 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -673,7 +673,9 @@ typedef enum FeatureWord { FEAT_XSAVE_XSS_HI, /* CPUID[EAX=0xd,ECX=1].EDX */ FEAT_7_1_EDX, /* CPUID[EAX=7,ECX=1].EDX */ FEAT_7_2_EDX, /* CPUID[EAX=7,ECX=2].EDX */ + FEAT_RDT_15_0_EBX, /* CPUID[EAX=0xf,ECX=0].EBX (RDT CMT/MBM) */ FEAT_RDT_15_0_EDX, /* CPUID[EAX=0xf,ECX=0].EDX (RDT CMT/MBM) */ + FEAT_RDT_10_0_EBX, /* CPUID[EAX=0x10,ECX=0].EBX (RDT CAT/MBA) */ FEATURE_WORDS, } FeatureWord; From patchwork Thu Sep 5 11:22:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792178 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 C1DE6CD5BAA for ; Thu, 5 Sep 2024 11:24:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZu-0000IQ-Tk; Thu, 05 Sep 2024 07:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3lJTZZggKCmEVGDMCQHJFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--whendrik.bounces.google.com>) id 1smAZt-0000BA-65 for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:05 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3lJTZZggKCmEVGDMCQHJFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--whendrik.bounces.google.com>) id 1smAZr-000305-MZ for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:04 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6d3e062dbeeso21751757b3.0 for ; Thu, 05 Sep 2024 04:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535380; x=1726140180; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=YlsjdAW6J5vVTpFBfjWCX8gwxASE5xgLrF4n+X8CTEM=; b=bSmGRoDVHw1tb53HMztE0ot+ne9qDbEqW+gkJOjgdD8mZ581aiOO7eqoqlHm9bfNV4 UHAYiXpCLR/2kh2LOIUvY7UwvIHUDhL3YQu4q80SdQEqH/fzDjCHbiOOOnObEdr/9ick GLcl9tcCLt1AnNaIgCgbJicJYYm5Thj6xva9qYfDEtCvWGVB6I3O829U2R9p7XayFOem TEl1Np6ZNchWhmiYlHqqadQtOj1dv45xsEQlNZQ9HQYlm8FU85aAjxiXJq3LgOYfhtuF o2o+mVn54gTQokCcahzXdJj71mxbhDEzvEjKXrDspN+/iVlMdrtOwHbAwl0HNKnxW63E YscA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535380; x=1726140180; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=YlsjdAW6J5vVTpFBfjWCX8gwxASE5xgLrF4n+X8CTEM=; b=bgOIjEyoEBWS9DpA+PDaBihWCH3DxldldeAOnzJjUB3j9BXn/k/VbRZEfgPkROqhyA M1r8tPK82PZsD6l/iZpKy8iXYKr2/aqh/VSYr5H/uwYWPii2BBSvRzlHKqbfpYz4zVTF ZtVZypOHBAa/2DK6fUSi5MkdSCPoKGJ7m3dndKfznGEfTz0Y0aJ82TTNPToBVtB6YDnM +DUjCbfwVjZSqpH/bQ/MhigvhQb8PGIk750GCyN5IBi88WT+/oY2z3WAiSmceWtvLUgQ KtkS3vRoXg2j6XkALxwmycRrBmNNxMO4qi9hAmMDw6eqDPdcpKw6Ep6mFSCdpNtuFc0L FBTw== X-Gm-Message-State: AOJu0Yzbn6OL+LuNkixcSvLud0icJCuqLjbUVOuRqSqQhsGpJ6efr8z8 swg9dfmzBctt0P/yku+7HQj3WxQz6071ITYG0VqcjtUn0UNlZAZpxTuLEQIwDwbDMjoQaW7Tgaa FkY+ylyLb7k2TQ38zauVmxp10ZwjWVK8xoRygQGd8IvgGfxiy38++HILVgiOOJjMAjvFiVca5Nw 4XRoSr62khdrULYlViOb4y1EK5pOLTMWJ+W4oYp91dbA== X-Google-Smtp-Source: AGHT+IGvEqdxwxXcxkTHGsgHbdBq/O0o7N5ZKqrD0KrW26E5SCkQjSzGuzeVaEXURysMVkupaKE7TbQFQrUyWQ== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:a81:690a:0:b0:6d3:e7e6:8462 with SMTP id 00721157ae682-6db25f47b18mr1464427b3.1.1725535380134; Thu, 05 Sep 2024 04:23:00 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:36 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-8-whendrik@google.com> Subject: [PATCH v2 7/8] i386/cpu: Adjust CPUID level for RDT features From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3lJTZZggKCmEVGDMCQHJFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--whendrik.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Adjust minimum CPUID level if RDT monitoring or allocation features are enabled to ensure that CPUID will return them. Signed-off-by: Hendrik Wüthrich --- target/i386/cpu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 36e19bfa8c..7c8bf707c2 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7562,6 +7562,16 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) if (env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_SGX) { x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x12); } + + /* RDT monitoring requires CPUID[0xF] */ + if (env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_PQM) { + x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0xF); + } + + /* RDT allocation requires CPUID[0x10] */ + if (env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_PQE) { + x86_cpu_adjust_level(cpu, &env->cpuid_min_level, 0x10); + } } /* Set cpuid_*level* based on cpuid_min_*level, if not explicitly set */ From patchwork Thu Sep 5 11:22:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hendrik Wuethrich X-Patchwork-Id: 13792183 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 8E9E7CD5BA9 for ; Thu, 5 Sep 2024 11:24:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smAZv-0000JY-1Y; Thu, 05 Sep 2024 07:23:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3lpTZZggKCmMXIFOESJLHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--whendrik.bounces.google.com>) id 1smAZt-0000BW-8n for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:05 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3lpTZZggKCmMXIFOESJLHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--whendrik.bounces.google.com>) id 1smAZr-00030O-Pg for qemu-devel@nongnu.org; Thu, 05 Sep 2024 07:23:05 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6d475205628so26690387b3.0 for ; Thu, 05 Sep 2024 04:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725535382; x=1726140182; darn=nongnu.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=sUIKZZlpr0KfcGjHDI4XoRscrAb+aelmj8CI87q4Re4=; b=xmwiJRZsoNiIn7gEdhyrbtMOUZGEe9vElS7UnOeF5nejtv54hIuMP9xP2D2mhT5GiH pCPyzQ6AJM1oy1a41SSJoWxAEF0tXFWMzM9PNIihtuaUeDRAB41erYCKxicmCf4mMxEW rdpmziankbsAdq+X7612c1GHPOq2mpL9FZdGqXGZEERsw+N4S3ktvQWXKgD1j25OyBDW J1nwOBDc0W9SLgzBWWAEv/BGHjb8PsxPXx563kZU4RFMqx3k9GxiOs/lpI9wEdaE2REO hv/gndh+JlEW1iS4BiTLQbTLc6e1xYHI7bw9EPKRMeFmBVYsuIabORjitqz3xXGKX5/j /8Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725535382; x=1726140182; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=sUIKZZlpr0KfcGjHDI4XoRscrAb+aelmj8CI87q4Re4=; b=Z0mzdk1SDimXMnrutflEGBXoVdTgIEd9vk1WYXX2vUiZ34EeFPUdDws2EdDm9xb49d HOj275E53hioHAfGD6orf8oPmztRBMfmsKdG5D1N5UZ4c2kC9PWnuiQCilYfcrWV9hIg TjwqsOpYl85HD3Yxfl8SZBqUkwDPlBWHh7M07qcYP+wgUYsfbTPusIUcDNZJjNvXS1iJ 7KYVmzbSrMqLz1BJi2IcO+/dw6WOrln3bdNS6WnwLWd0KUt6oTW0ybybmkJiEUya9AnO xHla1LKq8SaM2yfaeC3x+3DLFrszM8RwbhJo62jQhsfqp0ocKFDdGj24T2IkNHiEOcoh N80A== X-Gm-Message-State: AOJu0Yxvos1VNG++6ISYNQLdwLHC0Lwjo5fQcTbOPUKfGeLoSm5Rf4AX Ur5eT7iyTc37NRI+J5lEhfAcAMA3p3x0YK+CxQI/eKFIEkaWxz3Gm3NJLL0S1A2gfhmC8V0NETn TcZ00swde8Yz0LBxUyS79bBAYE05fE/Wyb0TS5iNMEJ/8tTsTkxIRFS0/psKM7aV2kDPVLUWiPy tah0EPOIBokR6w+Y4f9+XQsgU2EHgpgs/umcYb9/cS+Q== X-Google-Smtp-Source: AGHT+IGmeHQ+41Z3kVOPocZoLAuHqAweDU9d+GaHg+LGxfzt08A2bmKQIyMSwz3YL1SSGQudX9NsAYgchB+y0Q== X-Received: from whendrik-specialist-workstation.c.googlers.com ([fda3:e722:ac3:cc00:130:7cd9:ac11:98f1]) (user=whendrik job=sendgmr) by 2002:a05:690c:6382:b0:69b:c01:82a5 with SMTP id 00721157ae682-6d40ff0d1ccmr8721437b3.7.1725535382249; Thu, 05 Sep 2024 04:23:02 -0700 (PDT) Date: Thu, 5 Sep 2024 11:22:37 +0000 In-Reply-To: <20240905112237.3586972-1-whendrik@google.com> Mime-Version: 1.0 References: <20240905112237.3586972-1-whendrik@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905112237.3586972-9-whendrik@google.com> Subject: [PATCH v2 8/8] i386/cpu: Adjust level for RDT on full_cpuid_auto_level From: Hendrik Wuethrich To: qemu-devel@nongnu.org, Jonathan.Cameron@huawei.com, eduardo@habkost.net, richard.henderson@linaro.org, marcel.apfelbaum@gmail.com, mst@redhat.com, pbonzini@redhat.com Cc: peternewman@google.com, " =?utf-8?b?4oCqSGVuZHJpayBXw7x0aHJpY2g=?= " Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3lpTZZggKCmMXIFOESJLHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--whendrik.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: ‪Hendrik Wüthrich Make sure that RDT monitoring and allocation features are included in in full_cpuid_auto_level. Signed-off-by: Hendrik Wüthrich --- target/i386/cpu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7c8bf707c2..649540e971 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -875,6 +875,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, #else #define TCG_7_0_ECX_RDPID 0 #endif + #define TCG_7_0_ECX_FEATURES (CPUID_7_0_ECX_UMIP | CPUID_7_0_ECX_PKU | \ /* CPUID_7_0_ECX_OSPKE is dynamic */ \ CPUID_7_0_ECX_LA57 | CPUID_7_0_ECX_PKS | CPUID_7_0_ECX_VAES | \ @@ -7520,6 +7521,8 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) x86_cpu_adjust_feat_level(cpu, FEAT_C000_0001_EDX); x86_cpu_adjust_feat_level(cpu, FEAT_SVM); x86_cpu_adjust_feat_level(cpu, FEAT_XSAVE); + x86_cpu_adjust_feat_level(cpu, FEAT_RDT_15_0_EDX); + x86_cpu_adjust_feat_level(cpu, FEAT_RDT_10_0_EBX); /* Intel Processor Trace requires CPUID[0x14] */ if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT)) {