From patchwork Fri Nov 22 21:11:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Johannesmeyer X-Patchwork-Id: 13883634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 929BDE69191 for ; Fri, 22 Nov 2024 21:11:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3E196B0088; Fri, 22 Nov 2024 16:11:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC6516B0089; Fri, 22 Nov 2024 16:11:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCA416B008A; Fri, 22 Nov 2024 16:11:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A08776B0088 for ; Fri, 22 Nov 2024 16:11:50 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 62385161987 for ; Fri, 22 Nov 2024 21:11:50 +0000 (UTC) X-FDA: 82814976300.30.FF21A94 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by imf29.hostedemail.com (Postfix) with ESMTP id A6294120019 for ; Fri, 22 Nov 2024 21:10:34 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gOm7w5tQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of bjohannesmeyer@gmail.com designates 209.85.208.53 as permitted sender) smtp.mailfrom=bjohannesmeyer@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732309721; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ujlMhj3nrkjMEnTUfH0KLv8YxE/6CvGqSF8Yncy0GFs=; b=rYe4rU4lmnpFiDPh2evBw/8aCWDxJ79qOp9yR50a5ii6Kwy3TmB0xY9aAM14BLzJxkmXXa s4j+DLY+1aNjFhX5/izXLxQl8I5tlbTzxxALdvtSHE0n7MsCHX7JLLXO3y+t+oBvLkueR+ mx/50rF5zyuaDXEXjmerbkdvaLW4yvs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gOm7w5tQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of bjohannesmeyer@gmail.com designates 209.85.208.53 as permitted sender) smtp.mailfrom=bjohannesmeyer@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732309721; a=rsa-sha256; cv=none; b=nYHbDKeMThK2hJl9/939GZD4dAFlREaDMs36zimT07gCXXj1SFBV/YORa/tRxubuIVqhUN DpTxlg0861JDclO8KOVsxz7/gOSsSfMAFGYKpdCGm3BmtDRarh9XL62mR8HCM98jGG5Vtg kNG94elC1hiCFdnH6EkKrsUJ8hNYU+k= Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5cfadf851e2so3241484a12.2 for ; Fri, 22 Nov 2024 13:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732309907; x=1732914707; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ujlMhj3nrkjMEnTUfH0KLv8YxE/6CvGqSF8Yncy0GFs=; b=gOm7w5tQvJGzGD6hIwPr0SsDjvisSkv4MRcVTEOAMiMeeoU2EGeiOajSsUeNqEWu7S PJjB5vEusBEuxOgiSuIiJ/N7EPIoKEg7QTelm9MYkSwsOq/iXnFjl3f9F3LozPsV3+m+ HMw1+HAuSd8amULuHUFsIMFbpjZoM1x8QeI7X8to5lXpwVmZbiij4+KihzFv2GyDtedt AYJv7O1Rha+Zp2rZAsWbtUnYlOTs9BRvRs/VH4glYOglsZRGO/jgMo+ZuEQHzUgWadGP NecpP5EfEnTnw2IRGi9iaJSKaf3yMjH1QKwNTUJuCL74w4D9y8Au8oyZkdD8R7B3qS3s ytdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732309907; x=1732914707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ujlMhj3nrkjMEnTUfH0KLv8YxE/6CvGqSF8Yncy0GFs=; b=oDiRLWB/+KsmpXeHvQPv9UVvkpelxwwqzAF6qFuSganfIGIy7CldGDjYEoN952Eo/m cCJU1kfHoMqLY98EK1m9ZI2NamM46pdrZW/1Zg6lpFETK9atQNkMyhUh+tVN15Xc3nca krisXu3/oL2qtQYu62vF/1V0EdnK/MuDM0bj7vxG2nBgEXnSiDz3iFFgJoZSF5p0dIEL Ocxjysy7CMZsrH6AJxHr6Fe0VWEAtyflx4bN6n8zRgzWnaNFo5pLC63X/uBzrbXBALt+ Ijp9bXKDCfNIDsds1v5Kx9Viagr8UiH9tv3aXQ9e5Cpb7YCybpZjqQqE/1Amymy8+6FH VCkg== X-Forwarded-Encrypted: i=1; AJvYcCWtvp77Socx3lfX8c03BOe187puVqgzh5/O1vPlEeX7sjYYx//0oJLIGqOvGfmFyP/YXyOoQL7uYg==@kvack.org X-Gm-Message-State: AOJu0Yx9XiYpzI+dHg/ye7oE0qYRn/QV32n22c0OpRERbEOLHmZmiPq/ Wua2U0MMb5k4phhPT6YgV+/CImd+HscJEarHguvnoMM0HGhKx3Ac X-Gm-Gg: ASbGncvVfWwouBWHk9iMInjqOe5SVjpMayQdEkaJLXlP+EHqlVc6pJt18f/11lybbbZ eA+fNE1sgSHm3sTmdBqmh+vUpOEETuT07mIjvv8CVQjDMf8QJAzUXbWrVSugmih6kv8Q4ZCBLjQ fJGkq/v7FkuZNZSbDyk+s5ewn/wlIVNELImPojEtfodhYF33OCAJ6U+BUt4KgviL1XQ2it+j2vE Axc6hcMkBE7nrXsFVsu0J2CDWUpl9Nf0eernW3U60AdqnlZeTEaYCfwUu9qvKBsiUvy3AH1sgi0 qOg= X-Google-Smtp-Source: AGHT+IGxEcNdIJkavgQwkyu+9SNy7MVzcGeBojSJ6weJDwmHgDhnLOEF6/aIOKsiwU/UbCHwfH9hVw== X-Received: by 2002:a05:6402:5187:b0:5cf:d8ea:42d0 with SMTP id 4fb4d7f45d1cf-5d020601597mr3425670a12.12.1732309906975; Fri, 22 Nov 2024 13:11:46 -0800 (PST) Received: from rex.hwlab.vusec.net (lab-4.lab.cs.vu.nl. [192.33.36.4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d01d3a3d77sm1276636a12.7.2024.11.22.13.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 13:11:46 -0800 (PST) From: Brian Johannesmeyer To: Keith Busch , Christoph Hellwig , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Brian Johannesmeyer , Raphael Isemann , Cristiano Giuffrida , Herbert Bos , Greg KH Subject: [PATCH v3 2/3] dmapool: Use pool_find_block() in pool_block_err() Date: Fri, 22 Nov 2024 22:11:42 +0100 Message-Id: <20241122211144.4186080-2-bjohannesmeyer@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241122211144.4186080-1-bjohannesmeyer@gmail.com> References: <20241122211144.4186080-1-bjohannesmeyer@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 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sr +jIhjMZtL7W+FKci46Brk/X0ANyNJPnoS2RU0tTFly76xMtRWxN654sAJmUjQbnqPE0gJOErS6h3IiQmj0U1caxquP2r63k4L/3xds61r+ZwfM0YxWe+yUXE1erq9xEeKx7eTjtTn9d9S6HRCGxnySrJInm00egToPsFGmgLxj6ytyQ4R8/e0EJ/oow2r4xkbJi1uZSCX3/MGXm8gHy0h9dBu7VhB4X2yBDsL4MqdU59D1WAAAT6u+J6FsFgeycOaMyxiu/uzYanl2nZI6+SZV9nH3dOKfm8OERKwlcmcns+knXQ47lNc98/1O5bCjy4jwPIjS8QprlzXCyafh0SjT+BR1d4OCGglby3bS37VmeISrOYTWwnJCCQIreFubyckYE8RyTV2mKjlQ3ewQEXD2M25ffgduU+YXazW/X2rkUZX9F+U1NCWppBE3JiJ9TOwFy41pi1X3RGj7aQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In the previous patch, the `pool_find_block()` function was added to translate a virtual address into the corresponding `struct dma_block`. The existing `pool_find_page()` function performs a similar role by translating a DMA address into the `struct dma_page` containing it. To reduce redundant code and improve consistency, remove the `pool_find_page()` function and update `pool_block_err()` to use `pool_find_block()` instead. Doing so eliminates duplicate functionality and consolidates the block lookup process. Co-developed-by: Raphael Isemann Signed-off-by: Raphael Isemann Signed-off-by: Brian Johannesmeyer --- mm/dmapool.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/mm/dmapool.c b/mm/dmapool.c index 3790ca4a631d..f2b96be25412 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c @@ -141,39 +141,25 @@ static void pool_check_block(struct dma_pool *pool, struct dma_block *block, memset(block->vaddr, POOL_POISON_ALLOCATED, pool->size); } -static struct dma_page *pool_find_page(struct dma_pool *pool, dma_addr_t dma) -{ - struct dma_page *page; - - list_for_each_entry(page, &pool->page_list, page_list) { - if (dma < page->dma) - continue; - if ((dma - page->dma) < pool->allocation) - return page; - } - return NULL; -} - static bool pool_block_err(struct dma_pool *pool, void *vaddr, dma_addr_t dma) { - struct dma_block *block = pool->next_block; - struct dma_page *page; + struct dma_block *block = pool_find_block(pool, vaddr); - page = pool_find_page(pool, dma); - if (!page) { - dev_err(pool->dev, "%s %s, %p/%pad (bad dma)\n", - __func__, pool->name, vaddr, &dma); + if (!block) { + dev_err(pool->dev, "%s %s, invalid block %p\n", + __func__, pool->name, vaddr); return true; } - while (block) { - if (block->vaddr != vaddr) { - block = block->next_block; - continue; + struct dma_block *iter = pool->next_block; + + while (iter) { + if (iter == block) { + dev_err(pool->dev, "%s %s, dma %pad already free\n", + __func__, pool->name, &dma); + return true; } - dev_err(pool->dev, "%s %s, dma %pad already free\n", - __func__, pool->name, &dma); - return true; + iter = iter->next_block; } memset(vaddr, POOL_POISON_FREED, pool->size);