linux/arch/powerpc
Nicolin Chen 1e9d90dbed dma-mapping: introduce dma_get_seg_boundary_nr_pages()
We found that callers of dma_get_seg_boundary mostly do an ALIGN
with page mask and then do a page shift to get number of pages:
    ALIGN(boundary + 1, 1 << shift) >> shift

However, the boundary might be as large as ULONG_MAX, which means
that a device has no specific boundary limit. So either "+ 1" or
passing it to ALIGN() would potentially overflow.

According to kernel defines:
    #define ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
    #define ALIGN(x, a)	ALIGN_MASK(x, (typeof(x))(a) - 1)

We can simplify the logic here into a helper function doing:
  ALIGN(boundary + 1, 1 << shift) >> shift
= ALIGN_MASK(b + 1, (1 << s) - 1) >> s
= {[b + 1 + (1 << s) - 1] & ~[(1 << s) - 1]} >> s
= [b + 1 + (1 << s) - 1] >> s
= [b + (1 << s)] >> s
= (b >> s) + 1

This patch introduces and applies dma_get_seg_boundary_nr_pages()
as an overflow-free helper for the dma_get_seg_boundary() callers
to get numbers of pages. It also takes care of the NULL dev case
for non-DMA API callers.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Acked-by: Niklas Schnelle <schnelle@linux.ibm.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Signed-off-by: Christoph Hellwig <hch@lst.de>
2020-09-03 18:12:15 +02:00
..
boot Kbuild updates for v5.9 2020-08-09 14:10:26 -07:00
configs powerpc/configs: Add BLK_DEV_NVME to pseries_defconfig 2020-07-29 23:47:53 +10:00
crypto powerpc: Replace HTTP links with HTTPS ones 2020-07-22 00:01:23 +10:00
include A set of fixes for lockdep, tracing and RCU: 2020-08-30 11:43:50 -07:00
kernel dma-mapping: introduce dma_get_seg_boundary_nr_pages() 2020-09-03 18:12:15 +02:00
kexec powerpc/kexec_file: Enable early kernel OPAL calls 2020-07-29 23:47:55 +10:00
kvm KVM: Pass MMU notifier range flags to kvm_unmap_hva_range() 2020-08-21 18:03:47 -04:00
lib powerpc/test_emulate_step: Add testcases for divde[.] and divdeu[.] instructions 2020-07-29 23:47:52 +10:00
math-emu
mm Revert "powerpc/64s: Remove PROT_SAO support" 2020-08-24 14:12:53 +10:00
net treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
oprofile maccess: rename probe_user_{read,write} to copy_{from,to}_user_nofault 2020-06-17 10:57:41 -07:00
perf powerpc/perf: Fix reading of MSR[HV/PR] bits in trace-imc 2020-08-27 17:41:45 +10:00
platforms powerpc/32s: Disable VMAP stack which CONFIG_ADB_PMU 2020-08-28 12:03:18 +10:00
purgatory powerpc/kexec_file: Enable early kernel OPAL calls 2020-07-29 23:47:55 +10:00
sysdev powerpc: fix function annotations to avoid section mismatch warnings with gcc-10 2020-07-30 10:50:07 +10:00
tools powerpc/64s: allow for clang's objdump differences 2020-07-27 00:01:29 +10:00
xmon Kbuild updates for v5.9 2020-08-09 14:10:26 -07:00
Kbuild powerpc/kexec: Move kexec files into a dedicated subdir. 2019-11-21 15:41:34 +11:00
Kconfig powerpc/64s: Disallow PROT_SAO in LPARs by default 2020-08-24 14:12:54 +10:00
Kconfig.debug powerpc: Remove Xilinx PPC405/PPC440 support 2020-05-28 23:24:34 +10:00
Makefile powerpc/4xx: ppc4xx compile flag optimizations 2020-06-22 14:19:12 +10:00
Makefile.postlink powerpc: Do not consider weak unresolved symbol relocations as bad 2020-01-31 20:17:22 +11:00