From nobody Fri Oct 18 08:37:40 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; dmarc=fail(p=none dis=none) header.from=koconnor.net Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1642617998849130.8858821537682; Wed, 19 Jan 2022 10:46:38 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 0E27B16E3F9B; Wed, 19 Jan 2022 18:46:35 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 31B0016E36D3 for ; Wed, 19 Jan 2022 18:45:25 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Wed, 19 Jan 2022 10:45:25 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.gmail.com with ESMTPSA id z5sm295438qkj.41.2022.01.19.10.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 10:45:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9LZgXWV9NR50kP8COPzYTBoOTBdFxsoZV52iAwEyydY=; b=MWgjZaOM/Y5PMBWV3tITHRy0o4fuEagjKe2Uxfu/sOqHy2Xs4/xYZkLodZE/nh5Hei QS1lx02k+Xmb1r/2c7JP33oFBN34EJvXX+lLKMe5l6tj6RYbfZh5wxIa1L2qN5r6MJ6i 4cw3f8Fn61VV4RmEVQbKVK7P0nv+/bOyrdkzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9LZgXWV9NR50kP8COPzYTBoOTBdFxsoZV52iAwEyydY=; b=GZel+VZySV+d0scJlJGiW6/dvOXN7zpkcNY1sQXI5mbpdja76zDgKCHEYbB0qVa8GW T8a1ohQykl4ObfCIT7uoQ3T6FnKeQjRejiO/6jQLxRD1N9famk+IytlcTo73hIpOqWkP BlWXEyL1KrPp53uuN8+a0N2hxKNMiewOia6gWNsSN8WwV+NNFlV1SdnFdfZXWzYWwK6x AdszaanBPyQIaSUtozhtqzTP4O0gbRj6LrgIZutJz9yW/ScqW4rcVOxkda3ljSpJelxR b7MJU9k7y6EuiwkCnZHKBqeG9rvqpikN8VJt8d6QXrZ0Vtnmlp+F09lq5DNOC1EUgBkh ZWPA== X-Gm-Message-State: AOAM533lvGVjxHN8A3smaAIa7FMTo2rkd7X6HCxv95FwAOV0eKxVa/qs ZBTCkIpQl6+rHR92ZpG6vYMeiwpk7ghKXQ== X-Google-Smtp-Source: ABdhPJzg71yTgFQ8vev+qLplgeyYfzxBeIoMilGV/rn4/UX1wC1idQhtaRIJxn/Pl7ThwVpInEg3xA== X-Received: by 2002:a05:6214:252e:: with SMTP id gg14mr2969829qvb.89.1642617924061; Wed, 19 Jan 2022 10:45:24 -0800 (PST) From: Kevin O'Connor To: seabios@seabios.org Date: Wed, 19 Jan 2022 13:45:13 -0500 Message-Id: <20220119184513.1828156-6-kevin@koconnor.net> In-Reply-To: <20220119184513.1828156-1-kevin@koconnor.net> References: <20220119184513.1828156-1-kevin@koconnor.net> MIME-Version: 1.0 X-Spam-Level: ** Message-ID-Hash: PHMYDBEXIDSMYSRAGZQWPYZ6J2GKT6QT X-Message-ID-Hash: PHMYDBEXIDSMYSRAGZQWPYZ6J2GKT6QT X-MailFrom: kevin@koconnor.net 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: Alexander Graf X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCH 5/5] nvme: Build the page list in the existing dma buffer List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642617999999100001 Content-Type: text/plain; charset="utf-8" Commit 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists") introduced multi-page requests using the NVMe PRP mechanism. To store the list and "first page to write to" hints, it added fields to the NVMe namespace struct. Unfortunately, that struct resides in fseg which is read-only at runtime. While KVM ignores the read-only part and allows writes, real hardware and TCG adhere to the semantics and ignore writes to the fseg region. The net effect of that is that reads and writes were always happening on address 0, unless they went through the bounce buffer logic. This patch builds the PRP maintenance data in the existing "dma bounce buffer" and only builds it when needed. Fixes: 01f2736cc905d ("nvme: Pass large I/O requests as PRP lists") Reported-by: Matt DeVillier Signed-off-by: Alexander Graf Signed-off-by: Kevin O'Connor --- src/hw/nvme-int.h | 6 ------ src/hw/nvme.c | 51 +++++++++++++++++------------------------------ 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h index 9564c17..f0d717d 100644 --- a/src/hw/nvme-int.h +++ b/src/hw/nvme-int.h @@ -10,8 +10,6 @@ #include "types.h" // u32 #include "pcidevice.h" // struct pci_device =20 -#define NVME_MAX_PRPL_ENTRIES 15 /* Allows requests up to 64kb */ - /* Data structures */ =20 /* The register file of a NVMe host controller. This struct follows the na= ming @@ -122,10 +120,6 @@ struct nvme_namespace { =20 /* Page aligned buffer of size NVME_PAGE_SIZE. */ char *dma_buffer; - - /* Page List */ - u32 prpl_len; - u64 prpl[NVME_MAX_PRPL_ENTRIES]; }; =20 /* Data structures for NVMe admin identify commands */ diff --git a/src/hw/nvme.c b/src/hw/nvme.c index 3a73784..39b9138 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -470,35 +470,19 @@ nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, = void *buf, u16 count, return res; } =20 -static void nvme_reset_prpl(struct nvme_namespace *ns) -{ - ns->prpl_len =3D 0; -} - -static int nvme_add_prpl(struct nvme_namespace *ns, u64 base) -{ - if (ns->prpl_len >=3D NVME_MAX_PRPL_ENTRIES) - return -1; - - ns->prpl[ns->prpl_len++] =3D base; - - return 0; -} +#define NVME_MAX_PRPL_ENTRIES 15 /* Allows requests up to 64kb */ =20 // Transfer data using page list (if applicable) static int nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count, int write) { - int first_page =3D 1; u32 base =3D (long)buf; s32 size; =20 if (count > ns->max_req_size) count =3D ns->max_req_size; =20 - nvme_reset_prpl(ns); - size =3D count * ns->block_size; /* Special case for transfers that fit into PRP1, but are unaligned */ if (((size + (base & ~NVME_PAGE_MASK)) <=3D NVME_PAGE_SIZE)) @@ -512,28 +496,29 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, vo= id *buf, u16 count, if (size & (ns->block_size - 1ULL)) return nvme_bounce_xfer(ns, lba, buf, count, write); =20 - for (; size > 0; base +=3D NVME_PAGE_SIZE, size -=3D NVME_PAGE_SIZE) { - if (first_page) { - /* First page is special */ - first_page =3D 0; - continue; - } - if (nvme_add_prpl(ns, base)) - return nvme_bounce_xfer(ns, lba, buf, count, write); - } - - void *prp2; if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) { - /* We need to describe more than 2 pages, rely on PRP List */ - prp2 =3D ns->prpl; + /* We need to describe more than 2 pages, build PRP List */ + u32 prpl_len =3D 0; + u64 *prpl =3D (void*)ns->dma_buffer; + int first_page =3D 1; + for (; size > 0; base +=3D NVME_PAGE_SIZE, size -=3D NVME_PAGE_SIZ= E) { + if (first_page) { + /* First page is special */ + first_page =3D 0; + continue; + } + if (prpl_len >=3D NVME_MAX_PRPL_ENTRIES) + return nvme_bounce_xfer(ns, lba, buf, count, write); + prpl[prpl_len++] =3D base; + } + return nvme_io_xfer(ns, lba, buf, prpl, count, write); } else if ((ns->block_size * count) > NVME_PAGE_SIZE) { /* Directly embed the 2nd page if we only need 2 pages */ - prp2 =3D (void *)(long)ns->prpl[0]; + return nvme_io_xfer(ns, lba, buf, buf + NVME_PAGE_SIZE, count, wri= te); } else { /* One page is enough, don't expose anything else */ - prp2 =3D NULL; + return nvme_io_xfer(ns, lba, buf, NULL, count, write); } - return nvme_io_xfer(ns, lba, buf, prp2, count, write); } =20 static int --=20 2.31.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org