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 A87904949FE for ; Tue, 12 May 2026 08:39:19 +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=1778575162; cv=none; b=CTolX5FETUYZBs4KzKomy7nCH9map9U0xfMITEBo3W1IED/3h9ACjDlr/s4Qf349BlM0ekD0GA5aTVuftcUdy4ihAwlAewW+T652QHdlH+Ajc7LhAvMuceeCMSpFMSJrYEflO9U/k5HU8ppe9utg28IwCc4fXw7sOgU7b/HzIms= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778575162; c=relaxed/simple; bh=FvfBZWIlAw9ky6AZ5eGNfQVP6tnTj3c636j3XbkjmMs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=K6DueygCk2jt5RY1rhEdsUF10h1VejK/wV9ze+IQ1kD6CfE4JwDpu0Zxhw1MwJWM5yzY1rlvKw/uQcJxKT4WXcYB6UGelPVGK8UnNjn3Zo/iF3x7GZ+KLbWN4/JEN19pwPdnhPQ8dyI9X0PwZLQ+WTGMVu5TfFpX9fyJvd1mVmg= 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=syMrMo26; 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="syMrMo26" 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 64BK75AO3187033; Tue, 12 May 2026 08:38:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=5sxv/0 Ch6PR0mG5AQ8JlBNTIDLRquw0yy14xGIrhaUo=; b=syMrMo26fTm+jZgrO/ZfA/ w+ksIAm8KCLDMZ+8iM98SOjF8h9g2FCipqK09jKrd6+FipU4hVmwAiYYZiujYoq/ nEya9HtEssyi+NPEMM1DtJgt4ncRGhqqI3b4ksd6OhoFNTHvoGYecFshbT8r9bGe wLKZJZnfM55CgYdgyZd8bbWdsLuzz5LrqmTHa9iuVuobKY2iufEMRsSmcdw2VnDU KyJuxfCI0UI4ollKOwBH1bEbUHoH+JqG/WniCqrnkycMnwl/zLXk3CsRwjkzEY+6 t1Do6QhBqMWcVpRPD8icRWBZKbuZR1XrhageQuqAAExOdV+QycLhV/s3XtrSAKYA == 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 4e3nv5a69v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 May 2026 08:38:22 +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 64C8OOqj030234; Tue, 12 May 2026 08:38:21 GMT Received: from smtprelay05.dal12v.mail.ibm.com ([172.16.1.7]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgjbcf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 May 2026 08:38:21 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay05.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64C8cKD029426324 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 May 2026 08:38:21 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9EA0958055; Tue, 12 May 2026 08:38:20 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C5C358054; Tue, 12 May 2026 08:38:17 +0000 (GMT) Received: from [9.123.0.169] (unknown [9.123.0.169]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 12 May 2026 08:38:16 +0000 (GMT) Message-ID: <75769ad1-5aab-48da-9dd7-7646d50b24bf@linux.ibm.com> Date: Tue, 12 May 2026 14:08:15 +0530 Precedence: bulk X-Mailing-List: kvm-ppc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] target/ppc/kvm: Fix const violation when trimming CPU alias suffix Content-Language: en-GB To: Vaibhav Jain , qemu-devel@nongnu.org, kvm-ppc@vger.kernel.org, qemu-ppc@nongnu.org Cc: Amit Machhiwal , Chinmay Rath , Glenn Miles , Paolo Bonzini , Shivaprasad G Bhat , Gautam Menghani References: <20260511131018.102168-1-vaibhav@linux.ibm.com> From: Harsh Prateek Bora In-Reply-To: <20260511131018.102168-1-vaibhav@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=cPHQdFeN c=1 sm=1 tr=0 ts=6a02e6fe cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=f7IdgyKtn90A:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=Qj0HYR67M3tMq7YF4SsA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: Rzmuu_Onr7BMyxuE7m1L7Pzskp7sUWyK X-Proofpoint-GUID: Rzmuu_Onr7BMyxuE7m1L7Pzskp7sUWyK X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTEyMDA4NiBTYWx0ZWRfX+yzViU6imD/s im05NWOauvS0OU2S5oJTcL9ZBDnh+NuKyj+dXoLSGsTiIn7wlIjfERcOFhjYztTajMKedfWR1zf yjaA5JcDzwUZ+Nbzos6c2fIZVMSRBEArBflEyFv4WJWf+e24fJXjs53KrEzJlqlPK/anzBnAMBo uJiif6lu+EDqJzmipi00dGIw0hRAIdodBsNIpb5l/EeXpVnxfRilQaF+BV+4OIJ/RXaAULiyus5 7fXsmOk9fJ2kSl0HCY9PBQQ2w8Wbdg89mEIHA9kPiq3PrmUwogCaHNyqqVyZlFHqgXCDE9FlrTg S5x+c2zQK8jif+U7PyXs+oe+pplh3hqVpBsgSfEu7Fxo+5m9x7TibWjogV6eD5WOflMvXFZon0x nhmaZOg1eRlXmPfrdmVuRf4/MqomJt9GYctw2i5grYmRJSHEmjdwfqbRxUoLgli7w/HH6qbOuA3 x9002G9zX2dNdYhTUnQ== 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_05,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1011 spamscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605120086 Hi Vaibhav, Thanks for taking a look ... On 11/05/26 6:40 pm, Vaibhav Jain wrote: > 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; IIUC, g_strndup will abort the program in case of OOM eventually making it a dead code. We may consider using g_try_strndup at all if needed. Also, not sure if we really need unlikely() and a typecast may be needed for (suffix - cname). However, can we keep OOM related changes in a separate patch and keep only GCC16 build breakage fix in this patch retaining the original patch authorship with delta changes attributed alongside respective SoB? Thanks Harsh > + } else { > + return 0; > } > - break; > } > } >