lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221214180025.163207-1-luben.tuikov@amd.com>
Date:   Wed, 14 Dec 2022 13:00:25 -0500
From:   Luben Tuikov <luben.tuikov@....com>
To:     <iommu@...ts.linux.dev>
CC:     Luben Tuikov <luben.tuikov@....com>,
        Christoph Hellwig <hch@....de>,
        "Robin Murphy" <robin.murphy@....com>,
        Alex Deucher <Alexander.Deucher@....com>,
        Christian König <christian.koenig@....com>,
        "Linux Kernel Mailing List" <linux-kernel@...r.kernel.org>
Subject: [PATCH] dma-direct: Optimize get_required_mask

Optimize dma_direct_get_required_mask(), in that we don't need to multiply by
two if we don't subtract 1 from the exponent. That is,

    (1 << (n - 1)) * 2 - 1 <==>
    2^(n-1) * 2^1 - 1       = (by rule of exponents)
    2^n - 1                 <==>
    (1 << n) - 1.

Cc: Christoph Hellwig <hch@....de>
Cc: Robin Murphy <robin.murphy@....com>
Cc: Alex Deucher <Alexander.Deucher@....com>
Cc: Christian König <christian.koenig@....com>
Cc: iommu@...ts.linux.dev
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Signed-off-by: Luben Tuikov <luben.tuikov@....com>
---
 kernel/dma/direct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 63859a101ed831..bb416a3949dac0 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -41,7 +41,7 @@ u64 dma_direct_get_required_mask(struct device *dev)
 	phys_addr_t phys = (phys_addr_t)(max_pfn - 1) << PAGE_SHIFT;
 	u64 max_dma = phys_to_dma_direct(dev, phys);
 
-	return (1ULL << (fls64(max_dma) - 1)) * 2 - 1;
+	return (1ULL << fls64(max_dma)) - 1;
 }
 
 static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask,

base-commit: e2ca6ba6ba0152361aa4fcbf6067db71b2c7a770
-- 
2.39.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ