[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] PCI: deviate MISRA R11.8 for the one-time SBDF initialization
- To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
- Date: Wed, 18 Nov 2026 00:06:59 +0200
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WfdT4opn+PqZahDCW+jN3XeR3CU8vc7tUOLTzTaeTWg=; b=mpxFhY757tqBdo5pd5mw8MVUuwdaelUB3Sy3KngN7cxcT1GjkYfkQy17a6ykhub2S10gNagjIA6Tt7kJBGYw503RcLG/OQJP0daM8zZbRbpkTBcTLLMyWlhk5kEF5/cppFMhU1VHH+vb9D40R6/3xbqml/JAImkti0XRriGo5Wfr2OcTrixlk6WfeB4GtLx/GPxKe74ffTpUuzpGutdO/Z2crGzuNO5D+RD/l1qEzDR5veDLMvqqd8O52zoJQZtqbiUwaAZBaj0epoEmAx4X457zRo8An/CRBtPud3kl5rrNXvnJNjolaZNZ5LHJS7KPMhoKpy3QGy7yAekMxzDv7w==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DTC8zlF077YOz5mZkcL3n4LuuuQfikiY7w+zI/rDLoLS+LOWYnDK8NgFdpH12MoQYA2KS36UGBOnTzJHGFDRM31q/3WAWA93+P7udD20B0+qXlotHitfEAJz0IEMePws0iHuC/mRdU15J+zoBF8H/SdQbYoCqhbWlO4/6okQJ90MiJkN73yE/F3kqcr8rdcCaJh8+vRn4tqzXM3Ibb2kdX+Mgl8O8i0s1vphNM3MSuD9faMfnOhV4K6olpnEY4omXetuwf5uM/GgKMd1++H4nU9XzBrkSiALmonIBI498zPR9mtF3Tu66yiQSvJ6+BamJPwJfp4ulkkFBBYzQ70PPA==
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
- Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
- Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>
- Delivery-date: Tue, 17 Nov 2026 22:07:18 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 11/17/26 22:55, Dmytro Prokopchuk1 wrote:
MISRA C Rule 11.8 states: "A cast shall not remove any const or volatile
qualification from the type pointed to by a pointer".
alloc_pdev() writes the device identity once. seg, bus and devfn are
members of a const union, so that write goes through a cast that removes
const. Three such casts performed the same initialization.
Store the whole sbdf in one assignment and document that cast with
one-line SAF-15-safe comment.
No functional changes.
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3081067362
---
docs/misra/safe.json | 8 ++++++++
xen/drivers/passthrough/pci.c | 5 ++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/docs/misra/safe.json b/docs/misra/safe.json
index 3584cb90c6..3503d2e808 100644
--- a/docs/misra/safe.json
+++ b/docs/misra/safe.json
@@ -124,6 +124,14 @@
},
{
"id": "SAF-15-safe",
+ "analyser": {
+ "eclair": "MC3A2.R11.8"
+ },
+ "name": "Rule 11.8: one-time init of a const PCI identity",
+ "text": "The cast removes const only to initialize the const pci_dev
identity fields (seg, bus, devfn). The const qualification prevents any later assignment, and this
is the only write, performed before the device is published on alldevs_list."
+ },
+ {
+ "id": "SAF-16-safe",
"analyser": {},
"name": "Sentinel",
"text": "Next ID to be used"
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 578472d068..14d59b1293 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -329,9 +329,8 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8
bus, u8 devfn)
if ( !pdev )
return NULL;
- *(u16*) &pdev->seg = pseg->nr;
- *((u8*) &pdev->bus) = bus;
- *((u8*) &pdev->devfn) = devfn;
+ /* SAF-15-safe R11.8 one-time init of the const PCI identity */
+ *(pci_sbdf_t *)&pdev->sbdf = PCI_SBDF(pseg->nr, bus, devfn);
pdev->domain = NULL;
INIT_LIST_HEAD(&pdev->vf_list);
This can be used as alternative to this Jan's patch:
https://lists.xenproject.org/archives/html/xen-devel/2026-09/msg00048.html
BR, Dmytro.
|