From nobody Tue Feb 10 11:14:23 2026 Received: from fhigh-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD76223A9BD for ; Sat, 10 Jan 2026 01:39:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768009166; cv=none; b=M6PdBftkzrwmzhBWfzXdMCSmIVbawjxvw/H+MRaDKWCWbUa4GLaqKX03F3+FNT1Y20fX6mnruVsbZDB+AJwkAymypMu/rHvbnJccLhQloAEydYrCgCyKvRtvXpeqQO65moG0r70jY8PDnDyt4egeczQvAsXpusYrhrhRGx0XOWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768009166; c=relaxed/simple; bh=Ri/rGuPzpK+ccPzTpOGc/avVpk40zMgJ9QhoG11EIzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H/fyx90taO6bNIpb2/GOTzfpDFwylnqW8Dan/bnKLgGKg68Wjt+xbBwcgYkhmzI7f9dE9EI5Kl7tX8CUa7WZftd1EU3SFDEetra0WXLG+sx+R6YoeAWfu7YzL/a0ADjAXVLJVbiL3IcOydbWuIoU5FAMPk/LMj6KvfCS1YdG9I0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=NMjw86Id; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Qowb2bcg; arc=none smtp.client-ip=103.168.172.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="NMjw86Id"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Qowb2bcg" Received: from phl-compute-09.internal (phl-compute-09.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5891B14000FB; Fri, 9 Jan 2026 20:39:24 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Fri, 09 Jan 2026 20:39:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1768009164; x= 1768095564; bh=VgBfqooDKEgNn8IDcbep9PMHlwrIxlzMxOmAvkjasI8=; b=N Mjw86Id/9FB/VY0dvinhzilc8OPFxYaJoav2doDI3kQRioOx5p8BxKuqTNnDm2em D8wgGTajYy0Dlex5veqc/joU2lhYrMgGL5XCsXhQdFNtNjo3y0hLAvGpIJi8C9Gh XDteoWskFoxFiLjtCcnYKrjhcZDHCIzGj0KkS8TKCo2bkmsZRvIpRa4ZIfwFwTKU XE/KoxV99hTfhMNOzojgZ/8AxJtjsQkAqou+8Cm32sXQHqekjbyW7ninvtjmPz+O 7GKYBFsjLDsWF18yhSyHHULluXclZTXRpGorcBiy+Pi7Fp+DVGsXZHWTLu8xROtc X7SQyaZTXKjyRBqpovydg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1768009164; x=1768095564; bh=V gBfqooDKEgNn8IDcbep9PMHlwrIxlzMxOmAvkjasI8=; b=Qowb2bcgRyBKpxJc7 Nb2D/NLJ7L9XF+Na2HjYeCwE/kvqwF6KhNm8Bt5nuacoy+Gd1t49ryDpTiTPLwPL SLvMFNiws9VeEMp+xA+9zGg1H90hVt30XsMqqHWiBH3eB6m9l9GiszW/ETHNLPVA syyxe8GJO5lUoevg2D27QWdfyrUqgCo+ya56ySDG6l/lFyigC6L9cL79DY13Lj+n mQfFboxrHhLnJtJm06ercs8DPK0652GywZHfaVpYJp03Vo8BCyt8XqwxlRXhv1C7 98suxPz7e6jCrWFXq2DuLdoyQhy5xYEiQ3jtcv3gphJfCZUmYasKJosUkedKuP6a uN2sQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduuddtfeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghkrghs hhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrghtthgvrhhnpeejvdetteduhf eivdehgeeivdekgfektdelfedtteeljeekvdeukeehkedvgffgveenucffohhmrghinhep khgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjphdpnhgspghr tghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidufe elgedquggvvhgvlheslhhishhtshdrshhouhhrtggvfhhorhhgvgdrnhgvthdprhgtphht thhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtph htthhopehjghhgsehnvhhiughirgdrtghomh X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jan 2026 20:39:23 -0500 (EST) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, jgg@nvidia.com Subject: [PATCH 7/8] firewire: ohci: split page allocation from dma mapping Date: Sat, 10 Jan 2026 10:39:10 +0900 Message-ID: <20260110013911.19160-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260110013911.19160-1-o-takashi@sakamocchi.jp> References: <20260110013911.19160-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 1394 OHCI PCI driver had long been the only user of dma_alloc_pages(). Although tee subsystem recently started using it, they are still a few users of the infrequently-used function. In the discussion for dma-mapping function, Jason Gunthorpe shows his opinion about the design of public API for the function. According to it, the users provide physical address to the function, then receive DMA mapping address, regardless of the location of mapping target. With the above aspects, this commit eliminates the use of dma_alloc_pages() from this subsystem. Link: https://lore.kernel.org/lkml/20250905174324.GI616306@nvidia.com/ Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 77 +++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index f6da4cd7d123..e34965acb925 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -539,18 +539,22 @@ static void ar_context_link_page(struct ar_context *c= tx, unsigned int index) static void ar_context_release(struct ar_context *ctx) { struct device *dev =3D ctx->ohci->card.device; - unsigned int i; =20 if (!ctx->buffer) return; =20 - vunmap(ctx->buffer); + for (int i =3D 0; i < AR_BUFFERS; ++i) { + dma_addr_t dma_addr =3D page_private(ctx->pages[i]); =20 - for (i =3D 0; i < AR_BUFFERS; i++) { - if (ctx->pages[i]) - dma_free_pages(dev, PAGE_SIZE, ctx->pages[i], - ar_buffer_bus(ctx, i), DMA_FROM_DEVICE); + dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE); + set_page_private(ctx->pages[i], 0); } + + vunmap(ctx->buffer); + ctx->buffer =3D NULL; + + release_pages(ctx->pages, AR_BUFFERS); + memset(ctx->pages, 0, sizeof(ctx->pages)); } =20 static void ar_context_abort(struct ar_context *ctx, const char *error_msg) @@ -845,31 +849,57 @@ static int ar_context_init(struct ar_context *ctx, st= ruct fw_ohci *ohci, { struct device *dev =3D ohci->card.device; unsigned int i; - dma_addr_t dma_addr; struct page *pages[AR_BUFFERS + AR_WRAPAROUND_PAGES]; + void *vaddr; struct descriptor *d; =20 ctx->regs =3D regs; ctx->ohci =3D ohci; INIT_WORK(&ctx->work, ohci_ar_context_work); =20 - for (i =3D 0; i < AR_BUFFERS; i++) { - ctx->pages[i] =3D dma_alloc_pages(dev, PAGE_SIZE, &dma_addr, - DMA_FROM_DEVICE, GFP_KERNEL); - if (!ctx->pages[i]) - goto out_of_memory; - set_page_private(ctx->pages[i], dma_addr); - dma_sync_single_for_device(dev, dma_addr, PAGE_SIZE, - DMA_FROM_DEVICE); + // Retrieve noncontiguous pages. The descriptors for 1394 OHCI AR DMA con= texts have a set + // of address and length per each. The reason to use pages is to construc= t contiguous + // address range in kernel virtual address space. + unsigned long nr_populated =3D alloc_pages_bulk(GFP_KERNEL | GFP_DMA32, A= R_BUFFERS, pages); + + if (nr_populated !=3D AR_BUFFERS) { + release_pages(pages, nr_populated); + return -ENOMEM; } =20 - for (i =3D 0; i < AR_BUFFERS; i++) - pages[i] =3D ctx->pages[i]; + // Map the pages into contiguous kernel virtual addresses so that the pac= ket data + // across the pages can be referred as being contiguous, especially acros= s the last + // and first pages. for (i =3D 0; i < AR_WRAPAROUND_PAGES; i++) - pages[AR_BUFFERS + i] =3D ctx->pages[i]; - ctx->buffer =3D vmap(pages, ARRAY_SIZE(pages), VM_MAP, PAGE_KERNEL); - if (!ctx->buffer) - goto out_of_memory; + pages[AR_BUFFERS + i] =3D pages[i]; + vaddr =3D vmap(pages, ARRAY_SIZE(pages), VM_MAP, PAGE_KERNEL); + if (!vaddr) { + release_pages(pages, nr_populated); + return -ENOMEM; + } + + // Retrieve DMA mapping addresses for the pages. They are not contiguous.= Maintain the cache + // coherency for the pages by hand. + for (i =3D 0; i < AR_BUFFERS; i++) { + // The dma_map_phys() with a physical address per page is available here= , instead. + dma_addr_t dma_addr =3D dma_map_page(dev, pages[i], 0, PAGE_SIZE, DMA_FR= OM_DEVICE); + if (dma_mapping_error(dev, dma_addr)) + break; + set_page_private(pages[i], dma_addr); + dma_sync_single_for_device(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE); + } + if (i < AR_BUFFERS) { + while (i-- > 0) { + dma_addr_t dma_addr =3D page_private(pages[i]); + dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE); + } + vunmap(vaddr); + release_pages(pages, nr_populated); + return -ENOMEM; + } + + ctx->buffer =3D vaddr; + memcpy(ctx->pages, pages, sizeof(ctx->pages)); =20 ctx->descriptors =3D ohci->misc_buffer + descriptors_offset; ctx->descriptors_bus =3D ohci->misc_buffer_bus + descriptors_offset; @@ -886,11 +916,6 @@ static int ar_context_init(struct ar_context *ctx, str= uct fw_ohci *ohci, } =20 return 0; - -out_of_memory: - ar_context_release(ctx); - - return -ENOMEM; } =20 static void ar_context_run(struct ar_context *ctx) --=20 2.51.0