From nobody Fri Oct 31 09:29:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1748359632; cv=none; d=zohomail.com; s=zohoarc; b=J/hUiIKxe2RKwTQ8pCps0jgRQ3SDWQXwSF3SvGAeVCQ3ZZgwHTK+UasLVSR1x941UhFwhmPPKxvHlt3AGmLPXYH9a84wt1z6k8mDMjfZ4ECFn17OT0mdrKlDIF320WsiuMimPBUUpwvjPVW7c7W8n5gtYQ7hoMgG1YiJysvvB18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748359632; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7EiuJMdCLjFWOEnoMYbjUzW+ITRH6U+JRE5WHKaDcw4=; b=RDXeF+QpGnFhCZIa0JMSj9Uwj8bR7avruzEY2Jcs9ZXe0WPRv9lqDNJygeY0bQC0sJR4v18iRz2rmTd20yG8rN+PQ+yIa4HtkjMUh50+zx5qnEpmwVo6Q8zUmZ8m0WhL8gfWFpllPZmhwgsk4fhKH++fleemG7zdNVK0K5RO1eA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748359632930996.1758244188675; Tue, 27 May 2025 08:27:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.998565.1379328 (Exim 4.92) (envelope-from ) id 1uJwCh-0001wR-Sz; Tue, 27 May 2025 15:26:59 +0000 Received: by outflank-mailman (output) from mailman id 998565.1379328; Tue, 27 May 2025 15:26:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCh-0001w9-ON; Tue, 27 May 2025 15:26:59 +0000 Received: by outflank-mailman (input) for mailman id 998565; Tue, 27 May 2025 15:26:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCg-0001GX-T7 for xen-devel@lists.xenproject.org; Tue, 27 May 2025 15:26:58 +0000 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [2a00:1450:4864:20::531]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 06c2159b-3b0f-11f0-b894-0df219b8e170; Tue, 27 May 2025 17:26:57 +0200 (CEST) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5efe8d9ebdfso6763637a12.3 for ; Tue, 27 May 2025 08:26:57 -0700 (PDT) Received: from rossla-pc.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6049d482cc7sm3442712a12.19.2025.05.27.08.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 08:26:44 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 06c2159b-3b0f-11f0-b894-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1748359616; x=1748964416; darn=lists.xenproject.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=7EiuJMdCLjFWOEnoMYbjUzW+ITRH6U+JRE5WHKaDcw4=; b=I7Efd4m+AeIF8SnpByKXCXsQg+4anwVbyB5WwWzbZ4k/xftCa7UaOfVwNWW8ocqbGS Co6ROjBiaaSYS2eq7u0Dvh7o5grbA89U/+OIh9F6YIVowjJvhpH9jkNNEKfn42FtvJ7i Hp/gdnQoKWVgJ2jNV5uwfgXcVbrIVUfOloQJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748359616; x=1748964416; 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=7EiuJMdCLjFWOEnoMYbjUzW+ITRH6U+JRE5WHKaDcw4=; b=oNWcX4rFNtU17tZvXchbknyyVFoNHUyKWF4qqcxnZLP4mKuXR/WPjLziqGYR6xeWq0 7xsOfN/7ZJ7n4MBGgapxPqWgU11Lsy6ScNrQKhvTf19rDgse3EqnMmaNU11zLuZH3NLn M7W/4ylUaJ+P7jnyxX0vx0IWI1TS7oxLYxUJcHxiFgwEsZ83nHXJELTH1tOpTuNid7NN mpDOAjaHuI9ShDczdpBSW6V9Sao+AZRjEU8VBzOpi6OTQuhlaBdzljDFL1xJ4/NVnmpq 87II/Z9oIVqKFXnUwApmjdkcxHwK0nTCJYpp/q5OI/hXFlyHweW2fBo6mn/YNIM3TDx+ y4XA== X-Gm-Message-State: AOJu0YyTSOQZtMSIvK5jv9IBhDeYpx199LG6VgI0nNVbqr0K4G9dViPm PsQAYrjH8ZY/ySIRYQbEimJYWAI40Ap75orp4xT1+29+iHobZuHIp9SSbWrLKO2hy0HkfGvoaTV jsWA= X-Gm-Gg: ASbGncufOhz3OaJMXxinb06JGEwuABhesCHi6QDeD5h2bGssF8xxe6lcJ9y8hY52WwM BdcUBgLSf4zOHv5g9u/0h9FvL6mNHM7bpVk8ZeOOAmwweTkvfFDfOCXWkez53caDCdU+4gPyuHI kGf1dDccWfGUwc+UMKWNZsv5r3Ib7svz+LZjW71bMjc4lbA/vNhwVGsoa0xOd/FZkBDp355q8Lf mgEXxIU0hSfEiR2Q1hb6pCJCGAtVV4sipAax0gKi2s6GTb6gMajyWKxz2bJDQVxeMIwBkJxpwCg Q1LNUCoBcm7G3Q8nDoTl+PWPusf28jIUGgxGUVINziGqHITY40j+XXzotGfeGgsT1vS+1CDFtgc = X-Google-Smtp-Source: AGHT+IHYE2hnovzy6W1PgNLaxLFKR7wewuV0GiqQDMScRgK3xO82ngXX7l+Zt1GJ0pZEMQ86Wh/Frg== X-Received: by 2002:a05:6402:84f:b0:5ff:ef95:333a with SMTP id 4fb4d7f45d1cf-602d953574emr10518215a12.13.1748359605055; Tue, 27 May 2025 08:26:45 -0700 (PDT) From: Ross Lagerwall To: xen-devel@lists.xenproject.org Cc: Ross Lagerwall , Jan Beulich , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v3 1/5] x86/pmstat: Check size of PMSTAT_get_pxstat buffers Date: Tue, 27 May 2025 16:26:31 +0100 Message-ID: <20250527152635.2451449-2-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527152635.2451449-1-ross.lagerwall@citrix.com> References: <20250527152635.2451449-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1748359639981116600 Content-Type: text/plain; charset="utf-8" Check that the total number of states passed in and hence the size of buffers is sufficient to avoid writing more than the caller has allocated. The interface is not explicit about whether getpx.total is expected to be set by the caller in this case but since it is always set in libxenctrl it seems reasonable to check it and make it explicit. Signed-off-by: Ross Lagerwall Fixes: c06a7db0c547 ("X86 and IA64: Update cpufreq statistic logic for supp= orting both x86 and ia64") Reviewed-by: Jan Beulich --- In v3: * Fix if condition * Move some header comments from patch 2 * Clarify some comments xen/drivers/acpi/pmstat.c | 7 +++++-- xen/include/public/sysctl.h | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index c51b9ca358c2..0d570e28bf11 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -103,8 +103,11 @@ int do_get_pm_info(struct xen_sysctl_get_pmstat *op) =20 cpufreq_residency_update(op->cpuid, pxpt->u.cur); =20 - ct =3D pmpt->perf.state_count; - if ( copy_to_guest(op->u.getpx.trans_pt, pxpt->u.trans_pt, ct*ct) ) + ct =3D min(pmpt->perf.state_count, op->u.getpx.total + 0U); + + /* Avoid partial copying of 2-D array */ + if ( ct =3D=3D op->u.getpx.total && + copy_to_guest(op->u.getpx.trans_pt, pxpt->u.trans_pt, ct * ct= ) ) { spin_unlock(cpufreq_statistic_lock); ret =3D -EFAULT; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 9eca72865b87..906a3364fbd9 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -215,11 +215,22 @@ typedef struct pm_px_val pm_px_val_t; DEFINE_XEN_GUEST_HANDLE(pm_px_val_t); =20 struct pm_px_stat { - uint8_t total; /* total Px states */ + /* + * IN: Number of elements in pt, number of rows/columns in trans_pt + * (PMSTAT_get_pxstat) + * OUT: total Px states (PMSTAT_get_max_px, PMSTAT_get_pxstat) + */ + uint8_t total; uint8_t usable; /* usable Px states */ uint8_t last; /* last Px state */ uint8_t cur; /* current Px state */ - XEN_GUEST_HANDLE_64(uint64) trans_pt; /* Px transition table */ + /* + * OUT: Px transition table. This should have total * total elements. + * As it is a 2-D array, this will not be copied if it is smaller= than + * the hypervisor's Px transition table. (PMSTAT_get_pxstat) + */ + XEN_GUEST_HANDLE_64(uint64) trans_pt; + /* OUT: This should have total elements (PMSTAT_get_pxstat) */ XEN_GUEST_HANDLE_64(pm_px_val_t) pt; }; =20 --=20 2.49.0 From nobody Fri Oct 31 09:29:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1748359620; cv=none; d=zohomail.com; s=zohoarc; b=ExfqRQ7w6DavFjl5B6ofpEkIT0NYs2WSPtKMe014W4cmU3U+W4Y9AKc9lk92vtiU/g+2AijDddftf7a3JGkuLPzjRf5pMuqulQzuyavCCXjZR7QwsYYY25gjoDUxMQBlgDilWy5m4fUO4kTYndY0joSnfClY1OTlYthV8Vpu+9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748359620; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qTriMCUpsmVzD3Jivpx0DCt9g1tummWqKXoec3hAy9A=; b=E1C0qRvLH6dNn9Bv0+p4VLPe0+gLW9gwahUwYgMJqOyYq7WTQ+esrfodJXgvOC5PFmEKHZnAg0aUGjP3oGhNDqHNoKG2fGvnbSHoChlMhfSXgxftz7kQLDaRVMuRlYpU32eYEAnG4OZX1gDEHnxv6UtL+xAUUUD4ZFhslKIipys= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17483596201689.357633786289739; Tue, 27 May 2025 08:27:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.998559.1379288 (Exim 4.92) (envelope-from ) id 1uJwCX-0000oB-KX; Tue, 27 May 2025 15:26:49 +0000 Received: by outflank-mailman (output) from mailman id 998559.1379288; Tue, 27 May 2025 15:26:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCX-0000o4-HZ; Tue, 27 May 2025 15:26:49 +0000 Received: by outflank-mailman (input) for mailman id 998559; Tue, 27 May 2025 15:26:48 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCW-0000Yz-71 for xen-devel@lists.xenproject.org; Tue, 27 May 2025 15:26:48 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 011ee120-3b0f-11f0-a2fd-13f23c93f187; Tue, 27 May 2025 17:26:47 +0200 (CEST) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-603fdd728ccso5129860a12.2 for ; Tue, 27 May 2025 08:26:47 -0700 (PDT) Received: from rossla-pc.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6049d482cc7sm3442712a12.19.2025.05.27.08.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 08:26:46 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 011ee120-3b0f-11f0-a2fd-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1748359607; x=1748964407; darn=lists.xenproject.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=qTriMCUpsmVzD3Jivpx0DCt9g1tummWqKXoec3hAy9A=; b=gXnb4CsWQqhjfuAPOKpuGa3LrOWxPjlU0tx4QjfbpqirRKIyrl6VtyKPmv4BQISD2m MzRafvAq2FRv6qjC32W6gCYQzubiCw5OYDxdV392YBgNEnXbbvdWGiT0OZc02x5EBO3Z PVzB8NGBDDDj9kBCqAh0a3yYRxBiSOwgWK+fc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748359607; x=1748964407; 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=qTriMCUpsmVzD3Jivpx0DCt9g1tummWqKXoec3hAy9A=; b=jEF/WuVuk3ZUS5EFR+b1P75/8LWWPxIDLMpmOMU+ko5/jUSGycfDMr+h6olwrxjUKd +3bS/bvNQEb47nDT+JiiyCCcFMHl6+e2jrkm3WwYSqIQmvqxPBgyEFVSpsLhkXfvw+ja hPxnpef1M1/rl/o1dkroZhKM1BiUPC1l3RF4Q9JpTmwsi7pzaJws5JZuFD6um5AeB7j1 RzbkQ7utOsatsjy0qdqiYg3fP/LXShu+trSMUhNEKjSTxVtCHsL5AL3Q2rHCjwI6eDiv +0vLD5pQKVH4WGjnH9Ic+o6uo2APW6Es+C/Im5BT1Qe1JIR7ko3FtcmwKV6OvRuxHjpz +qYw== X-Gm-Message-State: AOJu0YwkGMMVbvNMAZXHyozvKPeYoSeyUdsJcr0fzMjaauMCofIqcHDJ SvqwsQe3NHfGPPy4D3OhHJWBdGt3zi2cesNt5u7t0+cOwD+MO+QNUIvx93+djULg3/ANCJgtSHJ zOe8= X-Gm-Gg: ASbGnctepFZWtoq+sWix6w4DvuGZG7+HOKZWP4zbWACxoUc9lvLXPu+4Y1U6l0B03LN QEBG2i1yco+TBokKRBVcJDuzuSHeyNkhvQJuDmVPUUwg2ALzItiTjARuaqkD+Pwvs86J3GelR3d LXKFsG9Maez1/ko37ultR88KW06XxBxdYIRg8xc6TmMM63H8ueUiJrMqBUpmU8krChbAPpsz1a8 OphVltAp0srYq7Hm3JhURuIOTK/AI40jOYv9NgWASc4KVXuLPXz+56Mu/Z1glJpEzZ813ZZXQCY OFKE8N3JKIhITw4v6CyWRTg9c3Xe1fUjkI46adiMj8UsHJlYidGkuzWLOsKUQJXYm/fuVxqRx1Q = X-Google-Smtp-Source: AGHT+IGPiRyn9Jyzp+w5FlpiZc0eFrl84dMxOvxZYx6V5NsGForpQSY6lEG2moiGtlnV3uaoTQHBYQ== X-Received: by 2002:a05:6402:520b:b0:604:e33f:e5ac with SMTP id 4fb4d7f45d1cf-604e33fe6efmr4416878a12.2.1748359606947; Tue, 27 May 2025 08:26:46 -0700 (PDT) From: Ross Lagerwall To: xen-devel@lists.xenproject.org Cc: Ross Lagerwall , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v3 2/5] public/sysctl: Clarify usage of pm_{px,cx}_stat Date: Tue, 27 May 2025 16:26:32 +0100 Message-ID: <20250527152635.2451449-3-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527152635.2451449-1-ross.lagerwall@citrix.com> References: <20250527152635.2451449-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1748359625745116600 Content-Type: text/plain; charset="utf-8" Suggested-by: Jan Beulich Signed-off-by: Ross Lagerwall Acked-by: Jan Beulich --- In v3: * Moved some changes to patch 1 * Clarified some comments xen/include/public/sysctl.h | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 906a3364fbd9..b1e3a48194d8 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -221,9 +221,9 @@ struct pm_px_stat { * OUT: total Px states (PMSTAT_get_max_px, PMSTAT_get_pxstat) */ uint8_t total; - uint8_t usable; /* usable Px states */ - uint8_t last; /* last Px state */ - uint8_t cur; /* current Px state */ + uint8_t usable; /* OUT: usable Px states (PMSTAT_get_pxstat) */ + uint8_t last; /* OUT: last Px state (PMSTAT_get_pxstat) */ + uint8_t cur; /* OUT: current Px state (PMSTAT_get_pxstat) */ /* * OUT: Px transition table. This should have total * total elements. * As it is a 2-D array, this will not be copied if it is smaller= than @@ -235,14 +235,33 @@ struct pm_px_stat { }; =20 struct pm_cx_stat { - uint32_t nr; /* entry nr in triggers & residencies, including C0 */ - uint32_t last; /* last Cx state */ - uint64_aligned_t idle_time; /* idle time from boot */ - XEN_GUEST_HANDLE_64(uint64) triggers; /* Cx trigger counts */ - XEN_GUEST_HANDLE_64(uint64) residencies; /* Cx residencies */ - uint32_t nr_pc; /* entry nr in pc[] */ - uint32_t nr_cc; /* entry nr in cc[] */ /* + * IN: Number of elements in triggers, residencies (PMSTAT_get_cxstat) + * OUT: entry nr in triggers & residencies, including C0 + * (PMSTAT_get_cxstat, PMSTAT_get_max_cx) + */ + uint32_t nr; + uint32_t last; /* OUT: last Cx state (PMSTAT_get_cxstat) */ + /* OUT: idle time from boot (PMSTAT_get_cxstat)*/ + uint64_aligned_t idle_time; + /* OUT: Cx trigger counts, nr elements (PMSTAT_get_cxstat) */ + XEN_GUEST_HANDLE_64(uint64) triggers; + /* OUT: Cx residencies, nr elements (PMSTAT_get_cxstat) */ + XEN_GUEST_HANDLE_64(uint64) residencies; + /* + * IN: entry nr in pc[] (PMSTAT_get_cxstat) + * OUT: Required size of pc[] for all known to Xen entries to be writt= en + * (PMSTAT_get_cxstat) + */ + uint32_t nr_pc; + /* + * IN: entry nr in cc[] (PMSTAT_get_cxstat) + * OUT: Required size of cc[] for all known to Xen entries to be writt= en + * (PMSTAT_get_cxstat) + */ + uint32_t nr_cc; + /* + * OUT: (PMSTAT_get_cxstat) * These two arrays may (and generally will) have unused slots; slots = not * having a corresponding hardware register will not be written by the * hypervisor. It is therefore up to the caller to put a suitable sent= inel --=20 2.49.0 From nobody Fri Oct 31 09:29:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1748359624; cv=none; d=zohomail.com; s=zohoarc; b=msUA/gQK+F1mdkk3nLgqh8NqETD+vCrW1sSXl/4FwMd4wyoaz1W48HyZUMbKxcq8KBttEhqgNKRAE/+vqf+dKK+04gDJjz0OvLbH1nsUFMMbB67g5/fivHjw6c7jayudAqJXl91zemyEDNA7e55LvooEQK/7emEi+k/NXReoH2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748359624; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AAAB6Ax8rjWfGs7QV2koFNVF7HO+1ITwf906wvazW68=; b=BVq2SmGxzaDqEqc1qZMkNetV6kEKAWA4YSnQx7wx/VwsAf4A59hMlbjE6liYCtPBgsQn8/UMOP15SyKf8gRRfe8i/3I61LJkXRkHVesh53LXLANJp+R7qBVzLetI/POVg44SIrT/8aqiipF6kvE5d8FzL88PC+bxEPy7PwFeHyw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748359624842685.2912775183911; Tue, 27 May 2025 08:27:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.998560.1379298 (Exim 4.92) (envelope-from ) id 1uJwCZ-00013O-RN; Tue, 27 May 2025 15:26:51 +0000 Received: by outflank-mailman (output) from mailman id 998560.1379298; Tue, 27 May 2025 15:26:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCZ-00013D-OT; Tue, 27 May 2025 15:26:51 +0000 Received: by outflank-mailman (input) for mailman id 998560; Tue, 27 May 2025 15:26:50 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCY-0000Yz-8P for xen-devel@lists.xenproject.org; Tue, 27 May 2025 15:26:50 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 024560e4-3b0f-11f0-a2fd-13f23c93f187; Tue, 27 May 2025 17:26:49 +0200 (CEST) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-604bf67b515so3630672a12.0 for ; Tue, 27 May 2025 08:26:49 -0700 (PDT) Received: from rossla-pc.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6049d482cc7sm3442712a12.19.2025.05.27.08.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 08:26:48 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 024560e4-3b0f-11f0-a2fd-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1748359609; x=1748964409; darn=lists.xenproject.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=AAAB6Ax8rjWfGs7QV2koFNVF7HO+1ITwf906wvazW68=; b=dZ4Awufab2w/KJq4Rdzh1jIMy+U/lig1k9ldY0Jj0Qm/k/78tu7YyydLTNjVTsJADw wZpoIiTtpmdauBmwloznPR7VkkDrGNqavPlRzjuO4vu3ZfB3CoytM1cAS3vNaThYi5Ll WFEP/lI4O12hgp9RjNYP2Sza+RuYpUnHe0Hto= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748359609; x=1748964409; 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=AAAB6Ax8rjWfGs7QV2koFNVF7HO+1ITwf906wvazW68=; b=rvw7vzvN3vTNGl48sfo5skcJ/1cZ2Kxsec1R0RB9B/vwOWuMB0hrAFIZf9Ulv0GMSF Jy+ZhFcq0XW/Ym/N8Tx7C8FHg3naC1M2uiZe9JObzvIeB28XqLxjhCWGXw/B9cvqB1db 1HQm2KKpcMuJxTnC1MyzztFpXQllct823uJahb/vVZlU3eGtaL23RNVfvCmdbKwqoBGX hdeXvlrR7c7qVOlsCj1qcXwn7GOfu8W44BqoJwICP+nVo0TcCe6zv5stewUyVPs6WZCH AwN4T6e+zgjqRCi58EkeghpMITxbQDVfAruNazLQjCzP3IrXmYUYn22Cof6oI7632RTo UjmA== X-Gm-Message-State: AOJu0YzB/8oI7tx7TiUvxm1QU1yvyKYWEUuVm25P9uCMF7Pj2JnAiww2 4szIcXAccHqKPoWMwX6xI3ckxTLElX2HAn1ZCHKgcJgy1qpI3ceQye/XUoPmRbTRjYjkfjBrkg9 xGos= X-Gm-Gg: ASbGnctSb9GGO2yzY/nK7JSQBqY3sKfN1vJbSBZiDHadpvXlMyc1DUTCyE3py2mmVNh 0fxwBjnJ9TUH2G+BZmfOfyVfSROh81L+GfSoBLfwFgaj/QYYtipq+sDP2+u4WNR7N+JNjtka5+Q 6r7BIkHxPG8kzsBKr2dcy54li2xV4lxtNFn+9O7Ye4yKHTCzyVzsD9HE7Tj399wZGGr0yZ7MKDx sIaCpfKftnUrNyLMx9IIcAaAbnoFXQW+1eOxRCFI5orX5xV+WA71hNKZt0to7ELxw1XliD8r/1a sHk6REzbedLq1Iv97zJu9E5mkeh0bE0sDZKKnIoNOTxTXTo72zaRjtgiiWr+fx7N9LDXJgUY4Zo = X-Google-Smtp-Source: AGHT+IF6W+B3q07a3sgflbxcPGboBeFgqOuctbLzCA5Hi8E3OAZoFx+1iizjtjmFdXDygdJOzzIA0w== X-Received: by 2002:aa7:ccd6:0:b0:601:8335:e96b with SMTP id 4fb4d7f45d1cf-602da8dde90mr8762324a12.34.1748359608950; Tue, 27 May 2025 08:26:48 -0700 (PDT) From: Ross Lagerwall To: xen-devel@lists.xenproject.org Cc: Ross Lagerwall , Jan Beulich Subject: [PATCH v3 3/5] cpufreq: Avoid potential buffer overrun and leak Date: Tue, 27 May 2025 16:26:33 +0100 Message-ID: <20250527152635.2451449-4-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527152635.2451449-1-ross.lagerwall@citrix.com> References: <20250527152635.2451449-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1748359629732116600 Content-Type: text/plain; charset="utf-8" If set_px_pminfo is called a second time with a larger state_count than the first call, calls to PMSTAT_get_pxstat will read beyond the end of the pt and trans_pt buffers allocated in cpufreq_statistic_init() since they would have been allocated with the original state_count. Secondly, the states array leaks on each subsequent call of set_px_pminfo. Fix both these issues by ignoring subsequent calls to set_px_pminfo if it completed successfully previously. Return success rather than an error to avoid errors in the dom0 kernel log when reloading the xen_acpi_processor module. At the same time, fix a leak of the states array on error. Signed-off-by: Ross Lagerwall Reviewed-by: Jan Beulich --- In v3: * Return success rather than an error when called a second time * Use XFREE xen/drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 19e29923356a..635f6e8c61a5 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -517,7 +517,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processo= r_performance *perf) } } =20 - if ( perf->flags & XEN_PX_PSS ) + if ( perf->flags & XEN_PX_PSS && !pxpt->states ) { /* capability check */ if ( perf->state_count <=3D 1 ) @@ -534,6 +534,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processo= r_performance *perf) } if ( copy_from_guest(pxpt->states, perf->states, perf->state_count= ) ) { + XFREE(pxpt->states); ret =3D -EFAULT; goto out; } --=20 2.49.0 From nobody Fri Oct 31 09:29:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1748359627; cv=none; d=zohomail.com; s=zohoarc; b=PzPzMosoY56Ek2KE5XD99gOmu858rJr2rhZ1og0Wxq9ve8xX6BEae+j65WkRtS2+t8FCYIWVjxHKf/qSWR2DCT/P7uYQsBtZc2VNMei+6PnjqaYSUfu/BULyoAnw58+R3wMqnN185P8J34q6YPIqBjU3DnZ8YxDIUmVGq44yT2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748359627; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nVr7GtnMIQOWD4+rFj7EsFStMBOYAHWO5pkXs+hAwww=; b=iqzqpDldHFPk/7mF+F+WdPJFOJWqaN3AV7d/V6bn6orHEsh6b/3QR0F5wo3pK1GaNxt2jxbdy0lj0QVGl9w/hkcAYam8n9JdjKx9oR0VqDdXkz+W/NqJD/jV0J7WvlEFbqjMnyqkqdRaqsUQblAMnzaUoeHbnM5rAZJ0OWohXEA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748359627989581.1047337348003; Tue, 27 May 2025 08:27:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.998561.1379308 (Exim 4.92) (envelope-from ) id 1uJwCd-0001L9-4s; Tue, 27 May 2025 15:26:55 +0000 Received: by outflank-mailman (output) from mailman id 998561.1379308; Tue, 27 May 2025 15:26:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCd-0001Kp-1F; Tue, 27 May 2025 15:26:55 +0000 Received: by outflank-mailman (input) for mailman id 998561; Tue, 27 May 2025 15:26:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCb-0001GX-4Y for xen-devel@lists.xenproject.org; Tue, 27 May 2025 15:26:53 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 03270ecf-3b0f-11f0-b894-0df219b8e170; Tue, 27 May 2025 17:26:51 +0200 (CEST) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5fbfdf7d353so4655936a12.0 for ; Tue, 27 May 2025 08:26:51 -0700 (PDT) Received: from rossla-pc.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6049d482cc7sm3442712a12.19.2025.05.27.08.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 08:26:50 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 03270ecf-3b0f-11f0-b894-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1748359610; x=1748964410; darn=lists.xenproject.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=nVr7GtnMIQOWD4+rFj7EsFStMBOYAHWO5pkXs+hAwww=; b=gh0R4KGom0tb89yJwqHZYqQV/ZFYD1iTL1bmQY3Q8AhmTx2YxA30+FdkZSOM7dW8xe QizyAQ4Qpw8NTI7koGvE8PX+7JLdbptm0oJYFedHLGthxTmQnzzVL86Z2wXAW6unZ1QQ ZWzRQ2o8b+b2dlLHAEC9r1glJAXc9EmZhHZ2Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748359610; x=1748964410; 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=nVr7GtnMIQOWD4+rFj7EsFStMBOYAHWO5pkXs+hAwww=; b=VfMYFdXVCkIDXUXQz8mad+1KaMzMANZTYE7tSeWgmmSARaJ0Okp1pwz55xNDvZLrOq tgsinfZrAZfcSstWQAQteryZFAnPQk3vakBODzIxDObEutYssG2ftEK5vvufNNILnh8C DLqvSgtcEoWVcvs9zseY8BgA9xDeyRChDMMecVuRPkjvfGeorsxHqFM0mAVmX2SMy8eK lJARNOh/Z2YM2R+xHhMSMxqucXcXlNSxgtweeVQBwldwXM1EF4dEvrhuKok+6+n007Is NbIZkcEvWmDyG1Py+27cLRGELHazXNp56AkdsxVWYqR6QzDY8yL1l1MIt6BG/zQ+lWvB rHZg== X-Gm-Message-State: AOJu0YzGYkzu2Tkacfqx/YILcr1zwGyGdxHEqzxilQLqN9XuzbBihwvy hE7E4aykNn9FpAMZLl6ZipyKkyuMeELzzYNEzZcGIPOPxUv3zIe3ersa2j2w+pm+3llSKioGD/c E5zM= X-Gm-Gg: ASbGncuEkJy9yj3SazCfpOorV+V/wu+yYs/cciOydFao5zt9qwjEcuDJm8urTGBw0Kp dVAQXdsNx+Zrx+ijdH4N8yGPI94eCpttTtq4jqvaoGiFzBcymByqO6atVInN7F88JhJmsvuobLB 85pOer8gB/b3Gj9vUD3IynQmlidpvfkZ84CSm5l/gDIYY3OWmzyE2jCfDD+5pSct+vtl03YUuO4 nOT2sLk3Xua/9bFkbFhaOEt8N7jA1MQh9nZkFMXHSfNUJoNQRk8ppoBk+Dv50ddyfxqPfg0rIwt c+XPZb5X6q4v+ZFJkE8eSC9+FAZ2Vhr+2qo/7HLE9pVvwN8M5GOB0byOj7Uc915jjX73YVCtFtw = X-Google-Smtp-Source: AGHT+IEbEqJnJpwWGP8JbPpoco9C+hNCmnaaNfW2gX0K5XBjHWhjLa3skuvniV1lilvf6tP1E56FWQ== X-Received: by 2002:a05:6402:2809:b0:604:e99e:b765 with SMTP id 4fb4d7f45d1cf-604e99eb86dmr2814956a12.9.1748359610418; Tue, 27 May 2025 08:26:50 -0700 (PDT) From: Ross Lagerwall To: xen-devel@lists.xenproject.org Cc: Ross Lagerwall , Anthony PERARD , Juergen Gross , Jan Beulich Subject: [PATCH v3 4/5] libxc/PM: Ensure pxstat buffers are correctly sized Date: Tue, 27 May 2025 16:26:34 +0100 Message-ID: <20250527152635.2451449-5-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527152635.2451449-1-ross.lagerwall@citrix.com> References: <20250527152635.2451449-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1748359633990116600 Content-Type: text/plain; charset="utf-8" xc_pm_get_pxstat() requires the caller to allocate the pt and trans_pt buffers but then calls xc_pm_get_max_px() to determine how big they are (and hence how much Xen will copy into them). This is susceptible to races if xc_pm_get_max_px() changes so avoid the problem by requiring the caller to also pass in the size of the buffers. Suggested-by: Jan Beulich Signed-off-by: Ross Lagerwall Reviewed-by: Anthony PERARD --- In v3: * Fix DECLARE_NAMED_HYPERCALL_BOUNCE size tools/libs/ctrl/xc_pm.c | 21 ++++++++++----------- tools/misc/xenpm.c | 1 + 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index ff7b5ada053f..0bd79031044f 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -46,35 +46,34 @@ int xc_pm_get_pxstat(xc_interface *xch, int cpuid, stru= ct xc_px_stat *pxpt) { struct xen_sysctl sysctl =3D {}; /* Sizes unknown until xc_pm_get_max_px */ - DECLARE_NAMED_HYPERCALL_BOUNCE(trans, pxpt->trans_pt, 0, XC_HYPERCALL_= BUFFER_BOUNCE_BOTH); - DECLARE_NAMED_HYPERCALL_BOUNCE(pt, pxpt->pt, 0, XC_HYPERCALL_BUFFER_BO= UNCE_BOTH); + DECLARE_NAMED_HYPERCALL_BOUNCE(trans, pxpt->trans_pt, + pxpt->total * pxpt->total * sizeof(uint= 64_t), + XC_HYPERCALL_BUFFER_BOUNCE_BOTH); + DECLARE_NAMED_HYPERCALL_BOUNCE(pt, pxpt->pt, + pxpt->total * sizeof(struct xc_px_val), + XC_HYPERCALL_BUFFER_BOUNCE_BOTH); =20 - int max_px, ret; + int ret; =20 if ( !pxpt->trans_pt || !pxpt->pt ) { errno =3D EINVAL; return -1; } - if ( (ret =3D xc_pm_get_max_px(xch, cpuid, &max_px)) !=3D 0) - return ret; - - HYPERCALL_BOUNCE_SET_SIZE(trans, max_px * max_px * sizeof(uint64_t)); - HYPERCALL_BOUNCE_SET_SIZE(pt, max_px * sizeof(struct xc_px_val)); =20 if ( xc_hypercall_bounce_pre(xch, trans) ) - return ret; + return -1; =20 if ( xc_hypercall_bounce_pre(xch, pt) ) { xc_hypercall_bounce_post(xch, trans); - return ret; + return -1; } =20 sysctl.cmd =3D XEN_SYSCTL_get_pmstat; sysctl.u.get_pmstat.type =3D PMSTAT_get_pxstat; sysctl.u.get_pmstat.cpuid =3D cpuid; - sysctl.u.get_pmstat.u.getpx.total =3D max_px; + sysctl.u.get_pmstat.u.getpx.total =3D pxpt->total; set_xen_guest_handle(sysctl.u.get_pmstat.u.getpx.trans_pt, trans); set_xen_guest_handle(sysctl.u.get_pmstat.u.getpx.pt, pt); =20 diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index db658ebaddd5..de319329e6b0 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -319,6 +319,7 @@ static int get_pxstat_by_cpuid(xc_interface *xc_handle,= int cpuid, struct xc_px_ if ( !pxstat) return -EINVAL; =20 + pxstat->total =3D max_px_num; pxstat->trans_pt =3D malloc(max_px_num * max_px_num * sizeof(uint64_t)); if ( !pxstat->trans_pt ) --=20 2.49.0 From nobody Fri Oct 31 09:29:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1748359631; cv=none; d=zohomail.com; s=zohoarc; b=bSiNcEUCALfKurFPKVVh0IwMIpKOd271wtcd5HpAbpbqCd1Nh+WevsB36NB/AoCUFTG9iI+Qscq999VADB6Sv5/POI3i+JNgq4pv9inz0xVqE8hBu4rpVS/XjDwdzPyMudMtrkUJMS3Bb0RUsjnukJ6iYeP6AlVLBckyZL4H8nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748359631; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z+VEb8t0VEsYQfvMjLE4L2oQ6RvTwDmIbkwe2PQDnDw=; b=N8rwkvErHgQeZzULaoSbvDWJDDf7ZBSaIr8ahpaKo6l4eGiyc92vJg0zi8byLYQA4/OkE92Z2nLCCoICVt8FadfbCL62UrElwefFzGJXNmSt8QrvzayiM6aPDWo/Fa+mipcR7cbZpo4/bD3CLkpxGTE8SLOnuGdlvQp3p5v8C6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748359631544476.2351579828679; Tue, 27 May 2025 08:27:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.998562.1379314 (Exim 4.92) (envelope-from ) id 1uJwCd-0001Rp-Js; Tue, 27 May 2025 15:26:55 +0000 Received: by outflank-mailman (output) from mailman id 998562.1379314; Tue, 27 May 2025 15:26:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCd-0001Pv-EP; Tue, 27 May 2025 15:26:55 +0000 Received: by outflank-mailman (input) for mailman id 998562; Tue, 27 May 2025 15:26:54 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uJwCc-0001GX-9e for xen-devel@lists.xenproject.org; Tue, 27 May 2025 15:26:54 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 04068e36-3b0f-11f0-b894-0df219b8e170; Tue, 27 May 2025 17:26:52 +0200 (CEST) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-602039559d8so6967152a12.1 for ; Tue, 27 May 2025 08:26:52 -0700 (PDT) Received: from rossla-pc.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6049d482cc7sm3442712a12.19.2025.05.27.08.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 May 2025 08:26:51 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 04068e36-3b0f-11f0-b894-0df219b8e170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1748359612; x=1748964412; darn=lists.xenproject.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=z+VEb8t0VEsYQfvMjLE4L2oQ6RvTwDmIbkwe2PQDnDw=; b=CH8auMAvQtviTHcGhPc3AN8TeobWt8Bjg8DS3y6Gck5YLMVVsqsaugkpBCp7eSzacA MG+Rz+VBYkA/tP6N9GLEEmhxLsfkh8Q4fdGntXo2qP7hKD/ntnKjTHrRe1emT9dwDOur GxxVPp8NKJC1s66zcRRV/ZcuM8rJHciFEfT3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748359612; x=1748964412; 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=z+VEb8t0VEsYQfvMjLE4L2oQ6RvTwDmIbkwe2PQDnDw=; b=EoBxk+W1uv62FgD/mcOxDVl5sTANfKsKOGb7JKFCShs209oEQbsyPBZXOFpfn27LqH 58DVe9EBTY9U5IoA4OjWV+SVMI4VkkNJtk3JwYoelvQZSS6ekyXPq/WF8L3OAHNJ4Qtd 4G/iwUbMqvNvUE4eZyapLO3WH1/GdJV5elbrlVQ/ayXrwlkyQpdR2K8o5V6MVSs6VXH6 vKxMEDTM6Eky+RBPOyaFxM80tqrQuqn3nki2yRw7V2DxVzoCPIAo69PV5447nOpOwT4l ml2K4z0bPxM8vxHJVErmX7kAZiwuoYQb25vHlR4UE7ZEs28iDJwdRbZKwH8yC2Ui/bk1 C9zQ== X-Gm-Message-State: AOJu0YxKBOUS8QiYRUXiR3jUK5liyDCaEuZnnUV0u1ZtLxHNxzosNhec tkUJX+Oq4/lDTaN5QrVELw7oorRDG92cwYYtmWrAixzxN5XwSBE1oMDa//urV0v0hgV+WACuRQM 5wyA= X-Gm-Gg: ASbGncsRK+zsmQvHH4lZy1SFuwetU5rEjfTYxsU+vzoD8N+d/UZlEs0R6PuE/PNTiTk 5XeHRSBndd4AIhdIq6kWZKcsGZc3V+g8nGkyEpPJgzLhsg5sCXpPGxUdujnxTFTYBeSk5QNllHc LvWuWdECozzDX36qrHw8hXDmcaaljv7Xa6vEhRd7q0BOHEJ8Zik/gdIjV2JGl/zcfq/W39v0e1m g2C5k1VlwqdqTOJ25eE++mqxw+D7wcOK3UKxE1Sb/bpcpDVV1j7CJZ+/8J9kqNCdJUVGPLdtDIV +IGLndeArFRjUmAr8UeQ7IE3TP/3cWXT+PPPaNqTu6yqaas07uBqU6hs/3Gfb4uYO7R+Ae9fXCU = X-Google-Smtp-Source: AGHT+IHmacdcV8Xv0A2x8fYmDlkSIjjTWVtLBb7+07rSusdS1QTYhHRiXc70jGeNg3TJSWPuYpLYXQ== X-Received: by 2002:a05:6402:34d6:b0:5fb:455f:ac40 with SMTP id 4fb4d7f45d1cf-602d9061f6amr12010075a12.4.1748359611915; Tue, 27 May 2025 08:26:51 -0700 (PDT) From: Ross Lagerwall To: xen-devel@lists.xenproject.org Cc: Ross Lagerwall , Anthony PERARD Subject: [PATCH v3 5/5] libxc/PM: Retry get_pxstat if data is incomplete Date: Tue, 27 May 2025 16:26:35 +0100 Message-ID: <20250527152635.2451449-6-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527152635.2451449-1-ross.lagerwall@citrix.com> References: <20250527152635.2451449-1-ross.lagerwall@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1748359637888116600 Content-Type: text/plain; charset="utf-8" If the total returned by Xen is more than the number of elements allocated, it means that the buffer was too small and so the data is incomplete. Retry to get all the data. Signed-off-by: Ross Lagerwall Reviewed-by: Anthony PERARD --- tools/misc/xenpm.c | 49 +++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index de319329e6b0..d5387f5f0693 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -312,29 +312,42 @@ static int get_pxstat_by_cpuid(xc_interface *xc_handl= e, int cpuid, struct xc_px_ int ret =3D 0; int max_px_num =3D 0; =20 - ret =3D xc_pm_get_max_px(xc_handle, cpuid, &max_px_num); - if ( ret ) - return -errno; - if ( !pxstat) return -EINVAL; =20 - pxstat->total =3D max_px_num; - pxstat->trans_pt =3D malloc(max_px_num * max_px_num * - sizeof(uint64_t)); - if ( !pxstat->trans_pt ) - return -ENOMEM; - pxstat->pt =3D malloc(max_px_num * sizeof(struct xc_px_val)); - if ( !pxstat->pt ) + for ( ; ; ) { - free(pxstat->trans_pt); - return -ENOMEM; - } + ret =3D xc_pm_get_max_px(xc_handle, cpuid, &max_px_num); + if ( ret ) + return -errno; =20 - ret =3D xc_pm_get_pxstat(xc_handle, cpuid, pxstat); - if( ret ) - { - ret =3D -errno; + pxstat->total =3D max_px_num; + pxstat->trans_pt =3D malloc(max_px_num * max_px_num * + sizeof(uint64_t)); + if ( !pxstat->trans_pt ) + return -ENOMEM; + pxstat->pt =3D malloc(max_px_num * sizeof(struct xc_px_val)); + if ( !pxstat->pt ) + { + free(pxstat->trans_pt); + return -ENOMEM; + } + + ret =3D xc_pm_get_pxstat(xc_handle, cpuid, pxstat); + if ( ret ) + { + ret =3D -errno; + free(pxstat->trans_pt); + free(pxstat->pt); + pxstat->trans_pt =3D NULL; + pxstat->pt =3D NULL; + break; + } + + if ( pxstat->total <=3D max_px_num ) + break; + + /* get_max_px changed under our feet so the data is incomplete. */ free(pxstat->trans_pt); free(pxstat->pt); pxstat->trans_pt =3D NULL; --=20 2.49.0