From nobody Sat Feb 7 05:53:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=mailbox.org ARC-Seal: i=1; a=rsa-sha256; t=1654988055; cv=none; d=zohomail.com; s=zohoarc; b=YoWVgqmkCjeSwVcV2HSqcRQQnA9s4FUWs4hdTFdCEX8Fzk//qB7XsB73ZCuKEl1/js4lUlwz8jPjri/vlYvcpqG9+DRx1r8BC438GWBR2AJVasjFghTMLZ+PDW8mIIeyQVx9B14BCRT3fsMSY4doVbRHiRdev9R5aUfLCvN9Ldc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654988055; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=6zW25GgyjSpNgdM+GycZVm9NfcQEtIvwhzmqzoYHtPg=; b=fdmpE9IhV/fb9sIlhx0ciYjJZrtHo3I/4txaZdWlXaNk1TixIRFv5zH9mH3Msm9H5KNdMdNB9qoUp9jUsybv37Ole/uLy2vjD1LCAXpd9BpVyfaQwzP3YyV/Crf0hBZL6IR6Gjv2/jO/kw4QrsCDirjjUIS3bZyTrTNuFOqe5v0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654988054134881.4240375250565; Sat, 11 Jun 2022 15:54:14 -0700 (PDT) Received: from localhost ([::1]:38156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o09zg-0008OM-K2 for importer@patchew.org; Sat, 11 Jun 2022 18:54:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o09k2-000520-LH; Sat, 11 Jun 2022 18:38:02 -0400 Received: from mout-p-102.mailbox.org ([80.241.56.152]:56636) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1o09k0-0008Ni-ER; Sat, 11 Jun 2022 18:38:02 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4LLCQW1r4Gz9ss1; Sun, 12 Jun 2022 00:37:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1654987075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6zW25GgyjSpNgdM+GycZVm9NfcQEtIvwhzmqzoYHtPg=; b=drFjN0GAJevyp3lioSsar7Dsg890t8gr8AsP4CLc2wNnIqNRtm/o9AwWu+FVfYtROL4civ BESRPUM2+GyYE+3J+bfZUf2qB7jhsixWnTRYuOagIhJV/XwOTu/rrVZ+HcXb6BbR2uH42F PeWrBEKR5tmOgtJ8FPRhAhRdqMdMo+GFg1GekoRiMyhRDYZ3xW17X0VV6t/8WOoB/CWIR/ 1875EKBLUu1yl4Se2Aab3Uzuz9G1HVHSreZY4CXYGJyMGriOAgGd7yyCMtzgMZn/OiXyEr Vbiq8atEfrx2P45O4WGv69AuQvGXSm30udAk/9bj4ylPSSG/sOVFwGsAPycrQQ== From: Mauricio Sandt DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1654987075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6zW25GgyjSpNgdM+GycZVm9NfcQEtIvwhzmqzoYHtPg=; b=drFjN0GAJevyp3lioSsar7Dsg890t8gr8AsP4CLc2wNnIqNRtm/o9AwWu+FVfYtROL4civ BESRPUM2+GyYE+3J+bfZUf2qB7jhsixWnTRYuOagIhJV/XwOTu/rrVZ+HcXb6BbR2uH42F PeWrBEKR5tmOgtJ8FPRhAhRdqMdMo+GFg1GekoRiMyhRDYZ3xW17X0VV6t/8WOoB/CWIR/ 1875EKBLUu1yl4Se2Aab3Uzuz9G1HVHSreZY4CXYGJyMGriOAgGd7yyCMtzgMZn/OiXyEr Vbiq8atEfrx2P45O4WGv69AuQvGXSm30udAk/9bj4ylPSSG/sOVFwGsAPycrQQ== To: qemu-devel@nongnu.org Cc: Keith Busch , Klaus Jensen , qemu-block@nongnu.org, Mauricio Sandt Subject: [PATCH] hw/nvme: Add options to override hardcoded values Date: Sun, 12 Jun 2022 00:35:09 +0200 Message-Id: <20220611223509.32280-1-mauricio@mailbox.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MBO-RS-META: tx1x6j1mysrcby1zba6wna991cfum1pr X-MBO-RS-ID: 1aceab315bb02a07492 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=80.241.56.152; envelope-from=mauricio@mailbox.org; helo=mout-p-102.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 11 Jun 2022 18:52:28 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @mailbox.org) X-ZM-MESSAGEID: 1654988056705100001 Content-Type: text/plain; charset="utf-8" This small patch is the result of some recent malware research I did in a QEMU VM. The malware used multiple ways of querying info from the VM disk and I needed a clean way to change those values from the hypervisor. I believe this functionality could be useful to more people from multiple fields, sometimes you just want to change some default values and having them hardcoded in the sourcecode makes that much harder. This patch adds three config parameters to the nvme device, all of them are optional to not break anything. If any of them are not specified, the previous (before this patch) default is used. -model - This takes a string and sets it as the devices model name. If you don't specify this parameter, the default is "QEMU NVMe Ctrl". -firmware - The firmware version string, max 8 ascii characters. The default is whatever `QEMU_VERSION` evaluates to. -nqn_override - Allows to set a custom nqn on the nvme device. Only used if there is no subsystem. This string should be in the same format as the default "nqn.2019-08.org.qemu:...", but there is no validation for that. Its up to the user to provide a valid string. Signed-off-by: Mauricio Sandt --- hw/nvme/ctrl.c | 16 +++++++++++++--- hw/nvme/nvme.h | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 1e6e0fcad9..0e67217a63 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -6697,8 +6697,13 @@ static void nvme_init_subnqn(NvmeCtrl *n) NvmeIdCtrl *id =3D &n->id_ctrl; =20 if (!subsys) { - snprintf((char *)id->subnqn, sizeof(id->subnqn), + if (n->params.nqn_override) { + snprintf((char *)id->subnqn, sizeof(id->subnqn), + "%s", n->params.nqn_override); + } else { + snprintf((char *)id->subnqn, sizeof(id->subnqn), "nqn.2019-08.org.qemu:%s", n->params.serial); + } } else { pstrcpy((char *)id->subnqn, sizeof(id->subnqn), (char*)subsys->sub= nqn); } @@ -6712,8 +6717,10 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *p= ci_dev) =20 id->vid =3D cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID)); id->ssvid =3D cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR= _ID)); - strpadcpy((char *)id->mn, sizeof(id->mn), "QEMU NVMe Ctrl", ' '); - strpadcpy((char *)id->fr, sizeof(id->fr), QEMU_VERSION, ' '); + strpadcpy((char *)id->mn, sizeof(id->mn), + n->params.model ? n->params.model : "QEMU NVMe Ctrl", ' '); + strpadcpy((char *)id->fr, sizeof(id->fr), + n->params.firmware ? n->params.firmware : QEMU_VERSION, ' '); strpadcpy((char *)id->sn, sizeof(id->sn), n->params.serial, ' '); =20 id->cntlid =3D cpu_to_le16(n->cntlid); @@ -6913,6 +6920,9 @@ static Property nvme_props[] =3D { DEFINE_PROP_LINK("subsys", NvmeCtrl, subsys, TYPE_NVME_SUBSYS, NvmeSubsystem *), DEFINE_PROP_STRING("serial", NvmeCtrl, params.serial), + DEFINE_PROP_STRING("model", NvmeCtrl, params.model), + DEFINE_PROP_STRING("nqn_override", NvmeCtrl, params.nqn_override), + DEFINE_PROP_STRING("firmware", NvmeCtrl, params.firmware), DEFINE_PROP_UINT32("cmb_size_mb", NvmeCtrl, params.cmb_size_mb, 0), DEFINE_PROP_UINT32("num_queues", NvmeCtrl, params.num_queues, 0), DEFINE_PROP_UINT32("max_ioqpairs", NvmeCtrl, params.max_ioqpairs, 64), diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index e41771604f..45bcf3e02e 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -394,6 +394,9 @@ typedef struct NvmeCQueue { =20 typedef struct NvmeParams { char *serial; + char *model; + char *firmware; + char *nqn_override; uint32_t num_queues; /* deprecated since 5.1 */ uint32_t max_ioqpairs; uint16_t msix_qsize; --=20 2.25.1