From patchwork Thu Dec 14 12:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13492952 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 343B0C46CA3 for ; Thu, 14 Dec 2023 12:09:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.654527.1021550 (Exim 4.92) (envelope-from ) id 1rDkWM-0002ll-E9; Thu, 14 Dec 2023 12:08:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 654527.1021550; Thu, 14 Dec 2023 12:08:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rDkWL-0002hP-V2; Thu, 14 Dec 2023 12:08:53 +0000 Received: by outflank-mailman (input) for mailman id 654527; Thu, 14 Dec 2023 12:08:51 +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 1rDkWJ-0000tI-Kj for xen-devel@lists.xenproject.org; Thu, 14 Dec 2023 12:08:51 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a19fd92-9a79-11ee-9b0f-b553b5be7939; Thu, 14 Dec 2023 13:08:49 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id D060B4EE0C91; Thu, 14 Dec 2023 13:08:48 +0100 (CET) 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: 8a19fd92-9a79-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Simone Ballarin Subject: [PATCH 9/9] xen: add SAF deviation for safe cast removal. Date: Thu, 14 Dec 2023 13:07:51 +0100 Message-Id: <36e996b864853dba26a9c9fb9c9c674e92cc935e.1702555387.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 11.8 whose headline states: "A conversion shall not remove any const, volatile or _Atomic qualification from the type pointed to by a pointer". In function __hvm_copy, the const qualifier is cast away to comply with its function signature. There's no modification of the pointee during its execution, therefore its use can be deemed as safe. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin --- docs/misra/safe.json | 8 ++++++++ xen/arch/x86/hvm/hvm.c | 1 + 2 files changed, 9 insertions(+) diff --git a/docs/misra/safe.json b/docs/misra/safe.json index 952324f85c..e748bc6cf5 100644 --- a/docs/misra/safe.json +++ b/docs/misra/safe.json @@ -28,6 +28,14 @@ }, { "id": "SAF-3-safe", + "analyser": { + "eclair": "MC3R1.R11.8" + }, + "name": "MC3R1.R11.8: removal of const qualifier to comply with function signature", + "text": "It is safe to cast away const qualifiers to comply with function signature if the function does not modify the pointee." + }, + { + "id": "SAF-4-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 523e0df57c..414853254f 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3413,6 +3413,7 @@ static enum hvm_translation_result __hvm_copy( enum hvm_translation_result hvm_copy_to_guest_phys( paddr_t paddr, const void *buf, unsigned int size, struct vcpu *v) { + /* SAF-3-safe */ return __hvm_copy((void *)buf /* HVMCOPY_to_guest doesn't modify */, paddr, size, v, HVMCOPY_to_guest | HVMCOPY_phys, 0, NULL);