All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simone Ballarin <simone.ballarin@bugseng.com>
To: xen-devel@lists.xenproject.org
Cc: consulting@bugseng.com,
	"Maria Celeste Cesario" <maria.celeste.cesario@bugseng.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Julien Grall" <julien@xen.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Wei Liu" <wl@xen.org>,
	"Bertrand Marquis" <bertrand.marquis@arm.com>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Simone Ballarin" <simone.ballarin@bugseng.com>
Subject: [PATCH v2 4/6] xen: add SAF deviation for safe cast removal
Date: Tue, 19 Dec 2023 12:05:12 +0100	[thread overview]
Message-ID: <dff9e788e04aa04970cfbb70d09f4d1baf725506.1702982442.git.maria.celeste.cesario@bugseng.com> (raw)
In-Reply-To: <cover.1702982442.git.maria.celeste.cesario@bugseng.com>

From: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com>

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".

Add SAF-3-safe deviation: removal of const qualifier to comply with function signature.

Signed-off-by: Maria Celeste Cesario  <maria.celeste.cesario@bugseng.com>
Signed-off-by: Simone Ballarin  <simone.ballarin@bugseng.com>
---
Changes in v2:
- reword SAF-3-safe text;
- merge comments on __hvm_copy;
- add SAF-3-safe comment in x86/hvm.c:3433;
- add SAF-3-safe comment on arm/guestcopy.c raw_copy_to_guest and
  raw_copy_to_guest_flush_dcache.
---
 docs/misra/safe.json     | 8 ++++++++
 xen/arch/arm/guestcopy.c | 2 ++
 xen/arch/x86/hvm/hvm.c   | 6 ++++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/docs/misra/safe.json b/docs/misra/safe.json
index 952324f85c..96b964293a 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": "A single function could either read or write through a passed in pointer, depending on how it is called. It is deemed safe to cast away a const qualifier when passing a pointer to such a function, when the other parameters guarantee read-only operation."
+        },
+        {
+            "id": "SAF-4-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c
index 6716b03561..cf80ac46b1 100644
--- a/xen/arch/arm/guestcopy.c
+++ b/xen/arch/arm/guestcopy.c
@@ -109,6 +109,7 @@ static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len,
 
 unsigned long raw_copy_to_guest(void *to, const void *from, unsigned int len)
 {
+    /* SAF-3-safe COPY_to_guest doesn't modify from */
     return copy_guest((void *)from, (vaddr_t)to, len,
                       GVA_INFO(current), COPY_to_guest | COPY_linear);
 }
@@ -116,6 +117,7 @@ unsigned long raw_copy_to_guest(void *to, const void *from, unsigned int len)
 unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from,
                                              unsigned int len)
 {
+    /* SAF-3-safe COPY_to_guest doesn't modify from */
     return copy_guest((void *)from, (vaddr_t)to, len, GVA_INFO(current),
                       COPY_to_guest | COPY_flush_dcache | COPY_linear);
 }
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 523e0df57c..324893fbcc 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3413,7 +3413,8 @@ 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)
 {
-    return __hvm_copy((void *)buf /* HVMCOPY_to_guest doesn't modify */,
+    /* SAF-3-safe HVMCOPY_to_guest doesn't modify buf */
+    return __hvm_copy((void *)buf,
                       paddr, size, v,
                       HVMCOPY_to_guest | HVMCOPY_phys, 0, NULL);
 }
@@ -3429,7 +3430,8 @@ enum hvm_translation_result hvm_copy_to_guest_linear(
     unsigned long addr, const void *buf, unsigned int size, uint32_t pfec,
     pagefault_info_t *pfinfo)
 {
-    return __hvm_copy((void *)buf /* HVMCOPY_to_guest doesn't modify */,
+    /* SAF-3-safe HVMCOPY_to_guest doesn't modify buf */
+    return __hvm_copy((void *)buf,
                       addr, size, current, HVMCOPY_to_guest | HVMCOPY_linear,
                       PFEC_page_present | PFEC_write_access | pfec, pfinfo);
 }
-- 
2.40.0



  parent reply	other threads:[~2023-12-19 11:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 11:05 [PATCH v2 0/6] xen: address violations of MISRA C:2012 Rule 11.8 Simone Ballarin
2023-12-19 11:05 ` [PATCH v2 1/6] xen/arm: " Simone Ballarin
2023-12-20  1:02   ` Stefano Stabellini
2023-12-19 11:05 ` [PATCH v2 2/6] xen/ppc: " Simone Ballarin
2024-02-23 23:19   ` Stefano Stabellini
2024-02-26 19:33     ` Shawn Anastasio
2023-12-19 11:05 ` [PATCH v2 3/6] xen: add deviations for " Simone Ballarin
2023-12-20  1:04   ` Stefano Stabellini
2023-12-20 10:50   ` Jan Beulich
2023-12-20 11:39     ` Nicola Vetrini
2023-12-19 11:05 ` Simone Ballarin [this message]
2023-12-19 11:28   ` [PATCH v2 4/6] xen: add SAF deviation for safe cast removal Jan Beulich
2023-12-19 15:03     ` Nicola Vetrini
2023-12-19 11:05 ` [PATCH v2 5/6] xen: remove unused function ERR_CAST Simone Ballarin
2023-12-19 11:24   ` Jan Beulich
2023-12-20  1:07   ` Stefano Stabellini
2023-12-19 11:05 ` [PATCH v2 6/6] xen/common: address violations of MISRA C:2012 Rule 11.8 Simone Ballarin
2023-12-19 16:25   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dff9e788e04aa04970cfbb70d09f4d1baf725506.1702982442.git.maria.celeste.cesario@bugseng.com \
    --to=simone.ballarin@bugseng.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bertrand.marquis@arm.com \
    --cc=consulting@bugseng.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=maria.celeste.cesario@bugseng.com \
    --cc=michal.orzel@amd.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.