From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 444253A1CE6 for ; Mon, 11 May 2026 13:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778505042; cv=none; b=DoFKOqJi/fW4BdDLMLc/pzpEqVQ9HX2b1KmSQXwd9vtKRZCLhTtFzpRkZdbZ8o7zzKrueUiXoIvKcVuPu4mQJchDOryX/ie+igQFUTS8lSUzLtpDNHbzckttZcq+15LRk1t1LpPjjiCObD4V0TJhvdYB42u0zsFSVfy+g3YCxN8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778505042; c=relaxed/simple; bh=PrDKAKDLg2NXSgf8Cuww999ayn9DBtLk8liXY/9lCG0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oFLHjSEDvUsal9AXgrIsJF+L+hVLShumSYQwinZCnDFt1ZEzlRAZskxZml43j6tCJu2jghHBMWrJvVQqK293IfUznKM5pm3FIvl/IuS99ZD15G4I+Ub5WIBROqmxI6oYMTuQqPePM6Bi6TQoU9KFRgakBAr9k+wqHckverqSbfM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=bygiy7zT; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="bygiy7zT" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64AHxh0C4053403; Mon, 11 May 2026 13:10:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=8W1eSUObOb38Gg7xpAW90Ao5nxFvWMS8zQ3eb7VAq kk=; b=bygiy7zTHz7kWIr/8gJwpX0XkGbCnC1gPfcbAvrJrn1hwmQs/RZXXxk3y grGzeJG1xugyL29+eDOhqLkhTGb/7B3mcxJRyzIbqz4kqEqyXMSH++0vxv52m7aI mzqO9JsOGJoJkuDv9weggDw+OOrzkhxRrJRpBSUt2mFuQSC+zEpWftOA2hK31bRT NYk6KpZkjBdhwjEBzppvtg0Gkrojsi0iuYJkCeP2gHhJWZwSmqoOBREgA5AEvcab KY9VuOMfQ6mbwiXmrSnigjc3nXfDkY1fuL7Qd8pjvVH93ME+mX9I5ghrM5s39FXE YkN4cz0Ui/GBI6nq6oKF022Prn8zQ== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e1ve70dhb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2026 13:10:34 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64BD9TTN023683; Mon, 11 May 2026 13:10:33 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4e2hfg56j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2026 13:10:33 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64BDAVd628639906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 May 2026 13:10:32 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D016E5805A; Mon, 11 May 2026 13:10:31 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 096B25805C; Mon, 11 May 2026 13:10:27 +0000 (GMT) Received: from vaibhav?linux.ibm.com (unknown [9.39.25.174]) by smtpav02.dal12v.mail.ibm.com (Postfix) with SMTP; Mon, 11 May 2026 13:10:26 +0000 (GMT) Received: by vaibhav@linux.ibm.com (sSMTP sendmail emulation); Mon, 11 May 2026 18:40:24 +0530 From: Vaibhav Jain To: qemu-devel@nongnu.org, kvm-ppc@vger.kernel.org, qemu-ppc@nongnu.org Cc: Vaibhav Jain , Amit Machhiwal , Chinmay Rath , Glenn Miles , Paolo Bonzini , Shivaprasad G Bhat , Harsh Prateek Bora Subject: [PATCH v2] target/ppc/kvm: Fix const violation when trimming CPU alias suffix Date: Mon, 11 May 2026 18:40:16 +0530 Message-ID: <20260511131018.102168-1-vaibhav@linux.ibm.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: kvm-ppc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTExMDE0NSBTYWx0ZWRfX6Tw6Qp5uZMvo iNxgcWZEatbE8J+A/FJpS3H0eyFTIq/yC10x8Dg9ewuWTwQHf68yWEmKy/1v/91uWAAC/U8io/9 GgG1sZqGeFktMqqnmKOsUoSqISsETQn/FnZ+FeAvENKVRRiS6CsoRCaoOoRpLHayKFgBBnb1mKs U250W3/vTMv6yZ5W5whdbALAXFgOt/PjCNE6D+LlgtoKonH6o4/l7ps/eY+Gm/hYcKBMc83RS4w qFJGAkR6RuY9xOeu29x0oUfLvwn1TB843QRlqcZb9YxeLSJjZaI9sDear3hWPskqfkpXaJePiAg hPOCXQ3Utkl274C9PYRwlFsv7Tr7bQ/82EUS5d/njuYeBYSUdjmWIeZ3spDsP0cqr2kP5vy17Jg 0QgOfAMFlbCdjwptz5SRNuD/z2Du8AE5JafrhcCD/GiZCAhkWrWPs7VqfFTezzUujlGce2LxDOT I5OW0tOEupaXQfZRdxg== X-Proofpoint-GUID: 1vJvpab_VU8opN_HPgf23E4LvDnTdMID X-Proofpoint-ORIG-GUID: 1vJvpab_VU8opN_HPgf23E4LvDnTdMID X-Authority-Analysis: v=2.4 cv=CeQ4Irrl c=1 sm=1 tr=0 ts=6a01d54a cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=AeOTFisfVSLvIChBu_YA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_03,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1011 adultscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 phishscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605110145 GCC 16 tightens diagnostics around const correctness and now correctly rejects attempts to modify strings referenced through const-qualified pointers. In kvm_ppc_register_host_cpu_type(), ppc_cpu_aliases[i].model is defined as const char *, but the code was using strstr() on it and then modifying the returned pointer in-place to strip POWERPC_CPU_TYPE_SUFFIX. This results in a write through a pointer derived from const data, triggering a build failure with GCC 16: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] suffix = strstr(ppc_cpu_aliases[i].model, POWERPC_CPU_TYPE_SUFFIX); ^ Fix this by copying only the needed suffix from the object class-name to 'ppc_cpu_aliases.model' using g_strdup and g_strndup, which maintains the constness of the allocated buffer assigned to 'ppc_cpu_aliases.model' member of the 'ppc_cpu_aliases' struct array. The patch also adds error handling for possible memory allocation failure while calling g_str{n}dup functions so that the error is properly propogated back from kvm_arch_init(). Signed-off-by: Amit Machhiwal Signed-off-by: Vaibhav Jain (IBM) --- Change-log: v1->v2: https://lore.kernel.org/all/20260504134344.38958-1-amachhiw@linux.ibm.com * Avoid pointer aliasing * Handle memory allocation failure error --- target/ppc/kvm.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 25c28ad089..42cd4f4fff 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -170,9 +170,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) cap_rpt_invalidate = kvm_vm_check_extension(s, KVM_CAP_PPC_RPT_INVALIDATE); cap_ail_mode_3 = kvm_vm_check_extension(s, KVM_CAP_PPC_AIL_MODE_3); - kvm_ppc_register_host_cpu_type(); - return 0; + return kvm_ppc_register_host_cpu_type(); } int kvm_arch_irqchip_create(KVMState *s) @@ -2654,14 +2653,17 @@ static int kvm_ppc_register_host_cpu_type(void) dc = DEVICE_CLASS(ppc_cpu_get_family_class(pvr_pcc)); for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) { if (g_ascii_strcasecmp(ppc_cpu_aliases[i].alias, dc->desc) == 0) { - char *suffix; + const gchar *suffix, *cname = object_class_get_name(oc); + + suffix = g_strstr_len(cname, -1, POWERPC_CPU_TYPE_SUFFIX); + ppc_cpu_aliases[i].model = unlikely(suffix) ? + g_strndup(cname, suffix - cname) : g_strdup(cname); - ppc_cpu_aliases[i].model = g_strdup(object_class_get_name(oc)); - suffix = strstr(ppc_cpu_aliases[i].model, POWERPC_CPU_TYPE_SUFFIX); - if (suffix) { - *suffix = 0; + if (!ppc_cpu_aliases[i].model) { + return -ENOMEM; + } else { + return 0; } - break; } } -- 2.54.0