Commit cafe8816b217b98dc3f268d3b77445da498beb4f

Authored by Tejun Heo
1 parent 61ace7fa2f

percpu: use negative for auto for pcpu_setup_first_chunk() arguments

Impact: argument semantic cleanup

In pcpu_setup_first_chunk(), zero @unit_size and @dyn_size meant
auto-sizing.  It's okay for @unit_size as 0 doesn't make sense but 0
dynamic reserve size is valid.  Alos, if arch @dyn_size is calculated
from other parameters, it might end up passing in 0 @dyn_size and
malfunction when the size is automatically adjusted.

This patch makes both @unit_size and @dyn_size ssize_t and use -1 for
auto sizing.

Signed-off-by: Tejun Heo <tj@kernel.org>

Showing 3 changed files with 29 additions and 24 deletions Side-by-side Diff

arch/x86/kernel/setup_percpu.c
... ... @@ -344,7 +344,7 @@
344 344 pr_info("PERCPU: Allocated %d 4k pages, static data %zu bytes\n",
345 345 pcpu4k_nr_static_pages, static_size);
346 346  
347   - ret = pcpu_setup_first_chunk(pcpu4k_get_page, static_size, 0, 0, NULL,
  347 + ret = pcpu_setup_first_chunk(pcpu4k_get_page, static_size, -1, -1, NULL,
348 348 pcpu4k_populate_pte);
349 349 goto out_free_ar;
350 350  
include/linux/percpu.h
... ... @@ -117,8 +117,9 @@
117 117 typedef void (*pcpu_populate_pte_fn_t)(unsigned long addr);
118 118  
119 119 extern size_t __init pcpu_setup_first_chunk(pcpu_get_page_fn_t get_page_fn,
120   - size_t static_size, size_t unit_size,
121   - size_t dyn_size, void *base_addr,
  120 + size_t static_size,
  121 + ssize_t unit_size, ssize_t dyn_size,
  122 + void *base_addr,
122 123 pcpu_populate_pte_fn_t populate_pte_fn);
123 124  
124 125 /*
... ... @@ -824,8 +824,8 @@
824 824 * pcpu_setup_first_chunk - initialize the first percpu chunk
825 825 * @get_page_fn: callback to fetch page pointer
826 826 * @static_size: the size of static percpu area in bytes
827   - * @unit_size: unit size in bytes, must be multiple of PAGE_SIZE, 0 for auto
828   - * @dyn_size: free size for dynamic allocation in bytes, 0 for auto
  827 + * @unit_size: unit size in bytes, must be multiple of PAGE_SIZE, -1 for auto
  828 + * @dyn_size: free size for dynamic allocation in bytes, -1 for auto
829 829 * @base_addr: mapped address, NULL for auto
830 830 * @populate_pte_fn: callback to allocate pagetable, NULL if unnecessary
831 831 *
832 832  
... ... @@ -842,13 +842,14 @@
842 842 * indicates end of pages for the cpu. Note that @get_page_fn() must
843 843 * return the same number of pages for all cpus.
844 844 *
845   - * @unit_size, if non-zero, determines unit size and must be aligned
846   - * to PAGE_SIZE and equal to or larger than @static_size + @dyn_size.
  845 + * @unit_size, if non-negative, specifies unit size and must be
  846 + * aligned to PAGE_SIZE and equal to or larger than @static_size +
  847 + * @dyn_size.
847 848 *
848   - * @dyn_size determines the number of free bytes after the static
849   - * area in the first chunk. If zero, whatever left is available.
850   - * Specifying non-zero value make percpu leave the area after
851   - * @static_size + @dyn_size alone.
  849 + * @dyn_size, if non-negative, limits the number of bytes available
  850 + * for dynamic allocation in the first chunk. Specifying non-negative
  851 + * value make percpu leave alone the area beyond @static_size +
  852 + * @dyn_size.
852 853 *
853 854 * Non-null @base_addr means that the caller already allocated virtual
854 855 * region for the first chunk and mapped it. percpu must not mess
... ... @@ -863,8 +864,9 @@
863 864 * percpu access.
864 865 */
865 866 size_t __init pcpu_setup_first_chunk(pcpu_get_page_fn_t get_page_fn,
866   - size_t static_size, size_t unit_size,
867   - size_t dyn_size, void *base_addr,
  867 + size_t static_size,
  868 + ssize_t unit_size, ssize_t dyn_size,
  869 + void *base_addr,
868 870 pcpu_populate_pte_fn_t populate_pte_fn)
869 871 {
870 872 static struct vm_struct first_vm;
871 873  
... ... @@ -877,13 +879,17 @@
877 879 /* santiy checks */
878 880 BUILD_BUG_ON(ARRAY_SIZE(smap) >= PCPU_DFL_MAP_ALLOC);
879 881 BUG_ON(!static_size);
880   - BUG_ON(!unit_size && dyn_size);
881   - BUG_ON(unit_size && unit_size < static_size + dyn_size);
882   - BUG_ON(unit_size & ~PAGE_MASK);
883   - BUG_ON(base_addr && !unit_size);
  882 + if (unit_size >= 0) {
  883 + BUG_ON(unit_size < static_size +
  884 + (dyn_size >= 0 ? dyn_size : 0));
  885 + BUG_ON(unit_size & ~PAGE_MASK);
  886 + } else {
  887 + BUG_ON(dyn_size >= 0);
  888 + BUG_ON(base_addr);
  889 + }
884 890 BUG_ON(base_addr && populate_pte_fn);
885 891  
886   - if (unit_size)
  892 + if (unit_size >= 0)
887 893 pcpu_unit_pages = unit_size >> PAGE_SHIFT;
888 894 else
889 895 pcpu_unit_pages = max_t(int, PCPU_MIN_UNIT_SIZE >> PAGE_SHIFT,
... ... @@ -894,6 +900,9 @@
894 900 pcpu_chunk_struct_size = sizeof(struct pcpu_chunk)
895 901 + num_possible_cpus() * pcpu_unit_pages * sizeof(struct page *);
896 902  
  903 + if (dyn_size < 0)
  904 + dyn_size = pcpu_unit_size - static_size;
  905 +
897 906 /*
898 907 * Allocate chunk slots. The additional last slot is for
899 908 * empty chunks.
... ... @@ -909,12 +918,7 @@
909 918 schunk->vm = &first_vm;
910 919 schunk->map = smap;
911 920 schunk->map_alloc = ARRAY_SIZE(smap);
912   -
913   - if (dyn_size)
914   - schunk->free_size = dyn_size;
915   - else
916   - schunk->free_size = pcpu_unit_size - static_size;
917   -
  921 + schunk->free_size = dyn_size;
918 922 schunk->contig_hint = schunk->free_size;
919 923  
920 924 schunk->map[schunk->map_used++] = -static_size;