From nobody Thu Apr 25 19:19:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=nutanix.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1619083269909485.8952998288154; Thu, 22 Apr 2021 02:21:09 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 32A2416A098D; Thu, 22 Apr 2021 09:21:06 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 19FA016A098B for ; Thu, 22 Apr 2021 09:20:48 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mx0a-002c1b01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13M9HKxT001337; Thu, 22 Apr 2021 02:20:42 -0700 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mx0a-002c1b01.pphosted.com with ESMTP id 3827n33md4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Apr 2021 02:20:42 -0700 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by MWHPR02MB2702.namprd02.prod.outlook.com (2603:10b6:300:107::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20; Thu, 22 Apr 2021 09:20:39 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) ([fe80::3591:14f:bb39:4797]) by MW2PR02MB3723.namprd02.prod.outlook.com ([fe80::3591:14f:bb39:4797%3]) with mapi id 15.20.4065.021; Thu, 22 Apr 2021 09:20:39 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=hc2pniIWrYxgHKFuRQ8dvQKaGB7jhZDzdItRqh09asc=; b=fOjeC5Ox6jKiOo3O6CCTaumJH54tZerxlVON8tfEeuSDAKLrw6mclhDDO1Sj8BrJNhnF KmwRdgNeKGoFcJzoQjk96Fjd0to0HCV1HsTLgU1FLUgoScyVfl6aDbFD0kqb4q2e1sJv MCeV7+b4RVD5BrkXB/bTe5BgV0Arfjz5OCdL0r4Ck+BIpmMK5LTJCDolqFTLQEHuPwQn I9Bjs9CMIh69D413/DipsKwjNjMvWm0J2Cy7gQg+CNDkeYdxKxS7QEte9/iBGBPwtVfe tMINqiA7T8l0Fhu3ZesOmUOwhdzje+8ezEvryqeVcqElOhw73f7lUqWn+VZRd4EYB6K7 fA== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WeVJ+swf/g2V4r84gY46y9FFnLfuS2MuGQXsfJsD/4LuhhLVuNUfIOEMVWYWxCZlktHimKxgGzn5t1w3+T9Ffi/CY3IfI/6CFobX6WxOBx6H1VmLIlTDD47T0ccSMflGBNPFy2lktUvJ+VLXgKj97jm9sJqmmOGVY21XNkIrMpZLahhlK+KQDWqri5SO4Zvl7dDv6xEfzwXM5ep+5MoT/VhwPF+1C/NKOY6I3s406RZoVTXk9zcwk5raZVM5M2wnjgmy4nQlp5El7RLOQfxYOUQWu8+C8LCT1Zoba+hw2I0vydlqTNaZuwdEhiv89anLOhwgftCPy79S8HHOb82waQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hc2pniIWrYxgHKFuRQ8dvQKaGB7jhZDzdItRqh09asc=; b=TnO5hMteHpLMfw+BEvZlkw+856XvsaZAEayNiF30n6vRZ/J2fBvWPrVfesaXm2Am1T1Om9zYdlQm9+83zXK9gtfvtjAG66usjEDeCnkfg5rB9dm1jknEfYX8Y6yXGJxLkcQea55+WcflqOJmJj13DLf4oWj5gVeot/KOv9tiPAkVYXJ8NT74ptvgpsFJwWz8CVfxR0OpMRaivOVyWR/hT4w0Gi1veT2773Df1UNgqx+vuL1P7ZiabldF6/A777DTw9RiVcv6A3cqBm8oq8qB6IqGPZGiqGwpMtCRTIAnpFvtg31AgFygsfV/tEeP4eVMrKsN0R9RsgBZd1zI4mMerA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none From: Thanos Makatos To: seabios@seabios.org Date: Thu, 22 Apr 2021 09:19:37 +0000 Message-Id: <20210422091936.76378-1-thanos.makatos@nutanix.com> X-ClientProxiedBy: BY3PR05CA0034.namprd05.prod.outlook.com (2603:10b6:a03:39b::9) To MW2PR02MB3723.namprd02.prod.outlook.com (2603:10b6:907:2::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0c66d65-033c-485b-d212-08d9056fe4cd X-MS-TrafficTypeDiagnostic: MWHPR02MB2702: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-proofpoint-crosstenant: true X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TWJgixhIQiNCmbpe+emli95rakSgbkarNpOAdH+NsFR0HJrLS2been0S05pxiDQqfGP/iiRJMBX34AE9JdkhRYRiPyxSIdRRfVPToWnQfsZPb6YoDiEK/oUmJdYhZcReAy/NA5FXafkU3/xydMAkDxCEbUoyN8dTaIoMTrbm82QhWq6n3zG5QavHM6DWFey906KNAUYtqjKOO6/Ut/nIi9uywBZBUcX4WPedQwHkjNMjSJvGYdQJLhWD8ZHwXzFYS2cjjzyILrYgAzGNAeqCPCFPUbbO1abPUi9FYh9nlpXkN14drLfkfF0KIUI6wJMkKCwyIxQUA+uzTf1DJ/ys8WrT8nO6tFlsKbpGuobax3HBsHWL0fBEFozCfbiu1ffE/LRZHJWMDlZUdNhdYCjdZc9OOQetYJ1qgieMOBYcFykimXzKbJD+GvGdz8QfJ2fUHI0VI9r3LZsce7U8FLBp32Cn1fW1xAg6fBsHG73w3TpSoBQHHhox5LzZC/ft9qKk3whSOtAjTSWLg59IC6oBhYwGSN8kLaTA4VbWT3SmANrxkDmZntvqCQxZBIYJPVTuBX5Owk7yQlQcpQ3IQJCfBKc4+JMundCeu0bu6kZDGLnbStcLcgWGgqOMlTnkbKoKClEHsJdG2TSwp46G6ze8Hg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW2PR02MB3723.namprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(396003)(136003)(39860400002)(376002)(366004)(86362001)(1076003)(6916009)(6486002)(2616005)(8676002)(83380400001)(316002)(36756003)(44832011)(54906003)(478600001)(2906002)(26005)(956004)(38100700002)(4326008)(107886003)(8936002)(66476007)(66946007)(38350700002)(16526019)(7696005)(186003)(52116002)(5660300002)(66556008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?xEJdzfRdP+uadQ9tPR7MdA9Dr0mQ0Ej2LYUcNTGr1B9UqGlIBOiOBoNiN9/p?= =?us-ascii?Q?jZujex4z5m+FV1Y/ts4hourwdyWnAlXwtoVEzf5gmY2D/X6omt3GFV8bta5T?= =?us-ascii?Q?Olh/k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SDzi57Nlba?= =?us-ascii?Q?IAgXUhsKpcM8PxAUlOmj2kDJbdn4lazVMI813SS86C4B/yKwSv20A5ALrkHX?= =?us-ascii?Q?Jf4IA9c3HaD22X51fp44UWlFfe1NK5PZsiOnYjssu/AauwikiPCew8Z16TuB?= =?us-ascii?Q?3nXXQnwcPixzn5PMO+c3Kx557SgaEGUZKPvIU2tSV/lmToILjBgf8ZJ9l4/B?= =?us-ascii?Q?zAd7rReDY1wpYe9yNmREge0mA+7RlzvxGt1+Uzf4rnN2olh+zw/R8Bvekt2Y?= =?us-ascii?Q?L1W1fADc77LodY2uU3+YMGUgyR+ZfsHjr6cELZrqwgMTwz3ptXVvUbQpsCWb?= =?us-ascii?Q?XdGASGYQDIrn7h3vuwpuGAp4?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0c66d65-033c-485b-d212-08d9056fe4cd X-MS-Exchange-CrossTenant-AuthSource: MW2PR02MB3723.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 09:20:39.0446 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RoETXrQ12piCC7uUH776EO5TYt/m9BmTPp3uwyyTAC+l551ynYnoJJSE+iPP5e4/iacDQgDJw9J+u+InknUzMV6Nu6L6V7UO3UQkgsCEQ+c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB2702 X-Proofpoint-GUID: CDLGexZtZB3z2_VnGPVcpO6bmLX7IxdI X-Proofpoint-ORIG-GUID: CDLGexZtZB3z2_VnGPVcpO6bmLX7IxdI X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-04-22_01:2021-04-21,2021-04-21 signatures=0 X-Proofpoint-Spam-Reason: safe Message-ID-Hash: 2Q7NPH7TJNHK6JGPHQL7755HILO23ISN X-Message-ID-Hash: 2Q7NPH7TJNHK6JGPHQL7755HILO23ISN X-MailFrom: thanos.makatos@nutanix.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: john.levon@nutanix.com, swapnil.ingle@nutanix.com, changpeng.liu@intel.com, kraxel@redhat.com, Thanos Makatos , Thanos Makatos X-Mailman-Version: 3.3.4b1 Precedence: list Subject: [SeaBIOS] [PATCH RESEND] nvme: look for NVMe namespace in boot rom file List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: + X-Spam-Level: * Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Thanos Makatos This patch allows specifying an NVMe namespace ID in the boot ROM file in the form /pci@0cf8/*@*/nvme/ns@*, where the 2nd component is the PCI device and the last component is the namespace ID. E.g. booting from namespace 2: boot order: 1: /pci@i0cf8/pci4e58,0001@6/nvme/ns@2 2: /rom@genroms/bootfail.bin 3: HAL ... |3ffa9000| Searching bootorder for: /pci@i0cf8/*@6/nvme/ns@2 |3ffa9000| NS 2 prio 1 |3ffa9000| phys_alloc zone=3D0x3ffbfeb8 size=3D80 align=3D10 ret=3D3ffa= c6e0 (detail=3D0x3ffac6b0) |3ffa9000| phys_alloc zone=3D0x3ffbfeb8 size=3D24 align=3D10 ret=3D3ffa= c690 (detail=3D0x3ffac660) |3ffa9000| Registering bootable: NVMe NS 2: 19073 MiB (39062500 512-byte blocks + 0-byte metadata) (type:2 prio:1 data:f4050) |3ffa9000| NVMe initialization complete! \3ffa9000/ End thread If we find a specific namespace we're looking for then we stop probing all other namespaces as there's no point in doing so. If a namespace is not specified in the boot ROM file then we default to the old way of booting from NVMe. As a future optimization we can avoid keeping information for all namespaces and operate on a single namespace at at time. This way we won't run out of memory even if the NVMe controller has the maximum number of namespaces (2^32 - 1). The corresponding QEMU patches haven't been upstreamed yet. Signed-off-by: Thanos Makatos -- Resending patch since it never reached the list, including a more detailed commit message. --- src/boot.c | 12 ++++++++++++ src/hw/nvme.c | 49 +++++++++++++++++++++++++++++++++++++++---------- src/util.h | 1 + 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/boot.c b/src/boot.c index 1effd80..6c2a150 100644 --- a/src/boot.c +++ b/src/boot.c @@ -325,6 +325,18 @@ int bootprio_find_mmio_device(void *mmio) return find_prio(desc); } =20 +int bootprio_find_nvme_device(struct pci_device *pci, u32 ns_id) +{ + if (CONFIG_CSM) + return csm_bootprio_pci(pci); + if (!CONFIG_BOOTORDER) + return -1; + char desc[256], *p; + p =3D build_pci_path(desc, sizeof(desc), "*", pci); + snprintf(p, desc+sizeof(desc)-p, "/nvme/ns@%u", ns_id); + return find_prio(desc); +} + int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun) { if (!CONFIG_BOOTORDER) diff --git a/src/hw/nvme.c b/src/hw/nvme.c index f26b811..b35a273 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -233,10 +233,23 @@ nvme_admin_identify_ns(struct nvme_ctrl *ctrl, u32 ns= _id) ns_id)->ns; } =20 -static void +static char* +nvme_ns_desc(const struct nvme_namespace *ns, u32 ns_id) +{ + return znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-byte " + "blocks + %u-byte metadata)\n", + ns_id, (ns->lba_count * ns->block_size) = >> 20, + ns->lba_count, ns->block_size, + ns->metadata_size); +} + +/* Returns 0 if the namespace is usable, -1 otherwise. */ +static int nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_namespace *ns, u32 ns_id, u8 mdts) { + int ret =3D -1; + ns->ctrl =3D ctrl; ns->ns_id =3D ns_id; =20 @@ -288,16 +301,14 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_nam= espace *ns, u32 ns_id, =20 ns->dma_buffer =3D zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE); =20 - char *desc =3D znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-by= te " - "blocks + %u-byte metadata)\n", - ns_id, (ns->lba_count * ns->block_size) >> 20, - ns->lba_count, ns->block_size, ns->metadata_size= ); - + char *desc =3D nvme_ns_desc(ns, ns_id); dprintf(3, "%s", desc); - boot_add_hd(&ns->drive, desc, bootprio_find_pci_device(ctrl->pci)); + free(desc); + ret =3D 0; =20 free_buffer: free (id); + return ret; } =20 =20 @@ -635,10 +646,28 @@ nvme_controller_enable(struct nvme_ctrl *ctrl) memset(ctrl->ns, 0, sizeof(*ctrl->ns) * ctrl->ns_count); =20 /* Populate namespace IDs */ - int ns_idx; - for (ns_idx =3D 0; ns_idx < ctrl->ns_count; ns_idx++) { - nvme_probe_ns(ctrl, &ctrl->ns[ns_idx], ns_idx + 1, identify->mdts); + int ns_idx, first_ns_idx =3D -1, prio =3D -1; + for (ns_idx =3D 0; ns_idx < ctrl->ns_count && prio =3D=3D -1; ns_idx++= ) { + if (!nvme_probe_ns(ctrl, &ctrl->ns[ns_idx], ns_idx + 1, identify->= mdts)) { + /* Check whether the NS is explicitly specified. */ + if (first_ns_idx =3D=3D -1) { + first_ns_idx =3D ns_idx; + } + prio =3D bootprio_find_nvme_device(ctrl->pci, ns_idx + 1); + } } + /* no NS specified, use the first one */ + if (prio !=3D -1) { + ns_idx--; + } else if (first_ns_idx !=3D -1) { + ns_idx =3D first_ns_idx; + dprintf(3, "no NVMe NS specified, defaulting to NS %u\n", ns_idx += 1); + prio =3D bootprio_find_pci_device(ctrl->pci); + } + if (prio !=3D -1) { + boot_add_hd(&ctrl->ns[ns_idx].drive, + nvme_ns_desc(&ctrl->ns[ns_idx], ns_idx + 1), prio); + } =20 dprintf(3, "NVMe initialization complete!\n"); return 0; diff --git a/src/util.h b/src/util.h index 0de3522..ad2d0ef 100644 --- a/src/util.h +++ b/src/util.h @@ -31,6 +31,7 @@ u8 is_bootprio_strict(void); struct pci_device; int bootprio_find_pci_device(struct pci_device *pci); int bootprio_find_mmio_device(void *mmio); +int bootprio_find_nvme_device(struct pci_device *pci, u32 ns_id); int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun); int bootprio_find_scsi_mmio_device(void *mmio, int target, int lun); int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave= ); --=20 2.22.3 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org