1. 01 2月, 2020 3 次提交
    • M
      lib/zlib: add s390 hardware support for kernel zlib_deflate · aa5b395b
      Mikhail Zaslonko 提交于
      Patch series "S390 hardware support for kernel zlib", v3.
      
      With IBM z15 mainframe the new DFLTCC instruction is available.  It
      implements deflate algorithm in hardware (Nest Acceleration Unit - NXU)
      with estimated compression and decompression performance orders of
      magnitude faster than the current zlib.
      
      This patchset adds s390 hardware compression support to kernel zlib.
      The code is based on the userspace zlib implementation:
      
      	https://github.com/madler/zlib/pull/410
      
      The coding style is also preserved for future maintainability.  There is
      only limited set of userspace zlib functions represented in kernel.
      Apart from that, all the memory allocation should be performed in
      advance.  Thus, the workarea structures are extended with the parameter
      lists required for the DEFLATE CONVENTION CALL instruction.
      
      Since kernel zlib itself does not support gzip headers, only Adler-32
      checksum is processed (also can be produced by DFLTCC facility).  Like
      it was implemented for userspace, kernel zlib will compress in hardware
      on level 1, and in software on all other levels.  Decompression will
      always happen in hardware (when enabled).
      
      Two DFLTCC compression calls produce the same results only when they
      both are made on machines of the same generation, and when the
      respective buffers have the same offset relative to the start of the
      page.  Therefore care should be taken when using hardware compression
      when reproducible results are desired.  However it does always produce
      the standard conform output which can be inflated anyway.
      
      The new kernel command line parameter 'dfltcc' is introduced to
      configure s390 zlib hardware support:
      
          Format: { on | off | def_only | inf_only | always }
           on:       s390 zlib hardware support for compression on
                     level 1 and decompression (default)
           off:      No s390 zlib hardware support
           def_only: s390 zlib hardware support for deflate
                     only (compression on level 1)
           inf_only: s390 zlib hardware support for inflate
                     only (decompression)
           always:   Same as 'on' but ignores the selected compression
                     level always using hardware support (used for debugging)
      
      The main purpose of the integration of the NXU support into the kernel
      zlib is the use of hardware deflate in btrfs filesystem with on-the-fly
      compression enabled.  Apart from that, hardware support can also be used
      during boot for decompressing the kernel or the ramdisk image
      
      With the patch for btrfs expanding zlib buffer from 1 to 4 pages (patch
      6) the following performance results have been achieved using the
      ramdisk with btrfs.  These are relative numbers based on throughput rate
      and compression ratio for zlib level 1:
      
        Input data              Deflate rate   Inflate rate   Compression ratio
                                NXU/Software   NXU/Software   NXU/Software
        stream of zeroes        1.46           1.02           1.00
        random ASCII data       10.44          3.00           0.96
        ASCII text (dickens)    6,21           3.33           0.94
        binary data (vmlinux)   8,37           3.90           1.02
      
      This means that s390 hardware deflate can provide up to 10 times faster
      compression (on level 1) and up to 4 times faster decompression (refers
      to all compression levels) for btrfs zlib.
      
      Disclaimer: Performance results are based on IBM internal tests using DD
      command-line utility on btrfs on a Fedora 30 based internal driver in
      native LPAR on a z15 system.  Results may vary based on individual
      workload, configuration and software levels.
      
      This patch (of 9):
      
      Create zlib_dfltcc library with the s390 DEFLATE CONVERSION CALL
      implementation and related compression functions.  Update zlib_deflate
      functions with the hooks for s390 hardware support and adjust workspace
      structures with extra parameter lists required for hardware deflate.
      
      Link: http://lkml.kernel.org/r/20200103223334.20669-2-zaslonko@linux.ibm.comSigned-off-by: NIlya Leoshkevich <iii@linux.ibm.com>
      Signed-off-by: NMikhail Zaslonko <zaslonko@linux.ibm.com>
      Co-developed-by: NIlya Leoshkevich <iii@linux.ibm.com>
      Cc: Chris Mason <clm@fb.com>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: David Sterba <dsterba@suse.com>
      Cc: Eduard Shishkin <edward6@linux.ibm.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Josef Bacik <josef@toxicpanda.com>
      Cc: Richard Purdie <rpurdie@rpsys.net>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      aa5b395b
    • G
      lib/test_kasan.c: fix memory leak in kmalloc_oob_krealloc_more() · 3e21d9a5
      Gustavo A. R. Silva 提交于
      In case memory resources for _ptr2_ were allocated, release them before
      return.
      
      Notice that in case _ptr1_ happens to be NULL, krealloc() behaves
      exactly like kmalloc().
      
      Addresses-Coverity-ID: 1490594 ("Resource leak")
      Link: http://lkml.kernel.org/r/20200123160115.GA4202@embeddedor
      Fixes: 3f15801c ("lib: add kasan test module")
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      Reviewed-by: NDmitry Vyukov <dvyukov@google.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      3e21d9a5
    • A
      lib/test_bitmap: correct test data offsets for 32-bit · 69334ca5
      Andy Shevchenko 提交于
      On 32-bit platform the size of long is only 32 bits which makes wrong
      offset in the array of 64 bit size.
      
      Calculate offset based on BITS_PER_LONG.
      
      Link: http://lkml.kernel.org/r/20200109103601.45929-1-andriy.shevchenko@linux.intel.com
      Fixes: 30544ed5 ("lib/bitmap: introduce bitmap_replace() helper")
      Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Reported-by: NGuenter Roeck <linux@roeck-us.net>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Yury Norov <yury.norov@gmail.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      69334ca5
  2. 27 1月, 2020 1 次提交
  3. 25 1月, 2020 1 次提交
  4. 24 1月, 2020 1 次提交
  5. 22 1月, 2020 1 次提交
    • J
      crypto: chacha20poly1305 - add back missing test vectors and test chunking · 72c79437
      Jason A. Donenfeld 提交于
      When this was originally ported, the 12-byte nonce vectors were left out
      to keep things simple. I agree that we don't need nor want a library
      interface for 12-byte nonces. But these test vectors were specially
      crafted to look at issues in the underlying primitives and related
      interactions.  Therefore, we actually want to keep around all of the
      test vectors, and simply have a helper function to test them with.
      
      Secondly, the sglist-based chunking code in the library interface is
      rather complicated, so this adds a developer-only test for ensuring that
      all the book keeping is correct, across a wide array of possibilities.
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      72c79437
  6. 18 1月, 2020 3 次提交
  7. 17 1月, 2020 4 次提交
    • M
      debugobjects: Fix various data races · 35fd7a63
      Marco Elver 提交于
      The counters obj_pool_free, and obj_nr_tofree, and the flag obj_freeing are
      read locklessly outside the pool_lock critical sections. If read with plain
      accesses, this would result in data races.
      
      This is addressed as follows:
      
       * reads outside critical sections become READ_ONCE()s (pairing with
         WRITE_ONCE()s added);
      
       * writes become WRITE_ONCE()s (pairing with READ_ONCE()s added); since
         writes happen inside critical sections, only the write and not the read
         of RMWs needs to be atomic, thus WRITE_ONCE(var, var +/- X) is
         sufficient.
      
      The data races were reported by KCSAN:
      
        BUG: KCSAN: data-race in __free_object / fill_pool
      
        write to 0xffffffff8beb04f8 of 4 bytes by interrupt on cpu 1:
         __free_object+0x1ee/0x8e0 lib/debugobjects.c:404
         __debug_check_no_obj_freed+0x199/0x330 lib/debugobjects.c:969
         debug_check_no_obj_freed+0x3c/0x44 lib/debugobjects.c:994
         slab_free_hook mm/slub.c:1422 [inline]
      
        read to 0xffffffff8beb04f8 of 4 bytes by task 1 on cpu 2:
         fill_pool+0x3d/0x520 lib/debugobjects.c:135
         __debug_object_init+0x3c/0x810 lib/debugobjects.c:536
         debug_object_init lib/debugobjects.c:591 [inline]
         debug_object_activate+0x228/0x320 lib/debugobjects.c:677
         debug_rcu_head_queue kernel/rcu/rcu.h:176 [inline]
      
        BUG: KCSAN: data-race in __debug_object_init / fill_pool
      
        read to 0xffffffff8beb04f8 of 4 bytes by task 10 on cpu 6:
         fill_pool+0x3d/0x520 lib/debugobjects.c:135
         __debug_object_init+0x3c/0x810 lib/debugobjects.c:536
         debug_object_init_on_stack+0x39/0x50 lib/debugobjects.c:606
         init_timer_on_stack_key kernel/time/timer.c:742 [inline]
      
        write to 0xffffffff8beb04f8 of 4 bytes by task 1 on cpu 3:
         alloc_object lib/debugobjects.c:258 [inline]
         __debug_object_init+0x717/0x810 lib/debugobjects.c:544
         debug_object_init lib/debugobjects.c:591 [inline]
         debug_object_activate+0x228/0x320 lib/debugobjects.c:677
         debug_rcu_head_queue kernel/rcu/rcu.h:176 [inline]
      
        BUG: KCSAN: data-race in free_obj_work / free_object
      
        read to 0xffffffff9140c190 of 4 bytes by task 10 on cpu 6:
         free_object+0x4b/0xd0 lib/debugobjects.c:426
         debug_object_free+0x190/0x210 lib/debugobjects.c:824
         destroy_timer_on_stack kernel/time/timer.c:749 [inline]
      
        write to 0xffffffff9140c190 of 4 bytes by task 93 on cpu 1:
         free_obj_work+0x24f/0x480 lib/debugobjects.c:313
         process_one_work+0x454/0x8d0 kernel/workqueue.c:2264
         worker_thread+0x9a/0x780 kernel/workqueue.c:2410
      Reported-by: NQian Cai <cai@lca.pw>
      Signed-off-by: NMarco Elver <elver@google.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Link: https://lore.kernel.org/r/20200116185529.11026-1-elver@google.com
      35fd7a63
    • P
      livepatch/samples/selftest: Use klp_shadow_alloc() API correctly · be6da984
      Petr Mladek 提交于
      The commit e91c2518 ("livepatch: Initialize shadow variables
      safely by a custom callback") leads to the following static checker
      warning:
      
        samples/livepatch/livepatch-shadow-fix1.c:86 livepatch_fix1_dummy_alloc()
        error: 'klp_shadow_alloc()' 'leak' too small (4 vs 8)
      
      It is because klp_shadow_alloc() is used a wrong way:
      
        int *leak;
        shadow_leak = klp_shadow_alloc(d, SV_LEAK, sizeof(leak), GFP_KERNEL,
      				 shadow_leak_ctor, leak);
      
      The code is supposed to store the "leak" pointer into the shadow variable.
      3rd parameter correctly passes size of the data (size of pointer). But
      the 5th parameter is wrong. It should pass pointer to the data (pointer
      to the pointer) but it passes the pointer directly.
      
      It works because shadow_leak_ctor() handle "ctor_data" as the data
      instead of pointer to the data. But it is semantically wrong and
      confusing.
      
      The same problem is also in the module used by selftests. In this case,
      "pvX" variables are introduced. They represent the data stored in
      the shadow variables.
      Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      Reviewed-by: NJoe Lawrence <joe.lawrence@redhat.com>
      Acked-by: NMiroslav Benes <mbenes@suse.cz>
      Reviewed-by: NKamalesh Babulal <kamalesh@linux.vnet.ibm.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      be6da984
    • P
      livepatch/selftest: Clean up shadow variable names and type · c24c57a4
      Petr Mladek 提交于
      The shadow variable selftest is quite tricky. Especially it is problematic
      to understand what values are stored, returned, and printed.
      
      Make it easier to understand by using "int *var, **sv" variables
      consistently everywhere instead of the generic "void *", "ret",
      and "ctor_data".
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      Reviewed-by: NJoe Lawrence <joe.lawrence@redhat.com>
      Acked-by: NMiroslav Benes <mbenes@suse.cz>
      Reviewed-by: NKamalesh Babulal <kamalesh@linux.vnet.ibm.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      c24c57a4
    • C
      49a101d7
  8. 16 1月, 2020 3 次提交
    • H
      crypto: curve25519 - Fix selftest build error · a8bdf2c4
      Herbert Xu 提交于
      If CRYPTO_CURVE25519 is y, CRYPTO_LIB_CURVE25519_GENERIC will be
      y, but CRYPTO_LIB_CURVE25519 may be set to m, this causes build
      errors:
      
      lib/crypto/curve25519-selftest.o: In function `curve25519':
      curve25519-selftest.c:(.text.unlikely+0xc): undefined reference to `curve25519_arch'
      lib/crypto/curve25519-selftest.o: In function `curve25519_selftest':
      curve25519-selftest.c:(.init.text+0x17e): undefined reference to `curve25519_base_arch'
      
      This is because the curve25519 self-test code is being controlled
      by the GENERIC option rather than the overall CURVE25519 option,
      as is the case with blake2s.  To recap, the GENERIC and ARCH options
      for CURVE25519 are internal only and selected by users such as
      the Crypto API, or the externally visible CURVE25519 option which
      in turn is selected by wireguard.  The self-test is specific to the
      the external CURVE25519 option and should not be enabled by the
      Crypto API.
      
      This patch fixes this by splitting the GENERIC module from the
      CURVE25519 module with the latter now containing just the self-test.
      Reported-by: NHulk Robot <hulkci@huawei.com>
      Fixes: aa127963 ("crypto: lib/curve25519 - re-add selftests")
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      Reviewed-by: NJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      a8bdf2c4
    • J
      crypto: x86/poly1305 - wire up faster implementations for kernel · d7d7b853
      Jason A. Donenfeld 提交于
      These x86_64 vectorized implementations support AVX, AVX-2, and AVX512F.
      The AVX-512F implementation is disabled on Skylake, due to throttling,
      but it is quite fast on >= Cannonlake.
      
      On the left is cycle counts on a Core i7 6700HQ using the AVX-2
      codepath, comparing this implementation ("new") to the implementation in
      the current crypto api ("old"). On the right are benchmarks on a Xeon
      Gold 5120 using the AVX-512 codepath. The new implementation is faster
      on all benchmarks.
      
              AVX-2                  AVX-512
            ---------              -----------
      
          size    old     new      size   old     new
          ----    ----    ----     ----   ----    ----
          0       70      68       0      74      70
          16      92      90       16     96      92
          32      134     104      32     136     106
          48      172     120      48     184     124
          64      218     136      64     218     138
          80      254     158      80     260     160
          96      298     174      96     300     176
          112     342     192      112    342     194
          128     388     212      128    384     212
          144     428     228      144    420     226
          160     466     246      160    464     248
          176     510     264      176    504     264
          192     550     282      192    544     282
          208     594     302      208    582     300
          224     628     316      224    624     318
          240     676     334      240    662     338
          256     716     354      256    708     358
          272     764     374      272    748     372
          288     802     352      288    788     358
          304     420     366      304    422     370
          320     428     360      320    432     364
          336     484     378      336    486     380
          352     426     384      352    434     390
          368     478     400      368    480     408
          384     488     394      384    490     398
          400     542     408      400    542     412
          416     486     416      416    492     426
          432     534     430      432    538     436
          448     544     422      448    546     432
          464     600     438      464    600     448
          480     540     448      480    548     456
          496     594     464      496    594     476
          512     602     456      512    606     470
          528     656     476      528    656     480
          544     600     480      544    606     498
          560     650     494      560    652     512
          576     664     490      576    662     508
          592     714     508      592    716     522
          608     656     514      608    664     538
          624     708     532      624    710     552
          640     716     524      640    720     516
          656     770     536      656    772     526
          672     716     548      672    722     544
          688     770     562      688    768     556
          704     774     552      704    778     556
          720     826     568      720    832     568
          736     768     574      736    780     584
          752     822     592      752    826     600
          768     830     584      768    836     560
          784     884     602      784    888     572
          800     828     610      800    838     588
          816     884     628      816    884     604
          832     888     618      832    894     598
          848     942     632      848    946     612
          864     884     644      864    896     628
          880     936     660      880    942     644
          896     948     652      896    952     608
          912     1000    664      912    1004    616
          928     942     676      928    954     634
          944     994     690      944    1000    646
          960     1002    680      960    1008    646
          976     1054    694      976    1062    658
          992     1002    706      992    1012    674
          1008    1052    720      1008   1058    690
      
      This commit wires in the prior implementation from Andy, and makes the
      following changes to be suitable for kernel land.
      
        - Some cosmetic and structural changes, like renaming labels to
          .Lname, constants, and other Linux conventions, as well as making
          the code easy for us to maintain moving forward.
      
        - CPU feature checking is done in C by the glue code.
      
        - We avoid jumping into the middle of functions, to appease objtool,
          and instead parameterize shared code.
      
        - We maintain frame pointers so that stack traces make sense.
      
        - We remove the dependency on the perl xlate code, which transforms
          the output into things that assemblers we don't care about use.
      
      Importantly, none of our changes affect the arithmetic or core code, but
      just involve the differing environment of kernel space.
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: NSamuel Neves <sneves@dei.uc.pt>
      Co-developed-by: NSamuel Neves <sneves@dei.uc.pt>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      d7d7b853
    • J
      crypto: poly1305 - add new 32 and 64-bit generic versions · 1c08a104
      Jason A. Donenfeld 提交于
      These two C implementations from Zinc -- a 32x32 one and a 64x64 one,
      depending on the platform -- come from Andrew Moon's public domain
      poly1305-donna portable code, modified for usage in the kernel. The
      precomputation in the 32-bit version and the use of 64x64 multiplies in
      the 64-bit version make these perform better than the code it replaces.
      Moon's code is also very widespread and has received many eyeballs of
      scrutiny.
      
      There's a bit of interference between the x86 implementation, which
      relies on internal details of the old scalar implementation. In the next
      commit, the x86 implementation will be replaced with a faster one that
      doesn't rely on this, so none of this matters much. But for now, to keep
      this passing the tests, we inline the bits of the old implementation
      that the x86 implementation relied on. Also, since we now support a
      slightly larger key space, via the union, some offsets had to be fixed
      up.
      
      Nonce calculation was folded in with the emit function, to take
      advantage of 64x64 arithmetic. However, Adiantum appeared to rely on no
      nonce handling in emit, so this path was conditionalized. We also
      introduced a new struct, poly1305_core_key, to represent the precise
      amount of space that particular implementation uses.
      
      Testing with kbench9000, depending on the CPU, the update function for
      the 32x32 version has been improved by 4%-7%, and for the 64x64 by
      19%-30%. The 32x32 gains are small, but I think there's great value in
      having a parallel implementation to the 64x64 one so that the two can be
      compared side-by-side as nice stand-alone units.
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      1c08a104
  9. 14 1月, 2020 9 次提交
  10. 11 1月, 2020 1 次提交
  11. 10 1月, 2020 5 次提交
  12. 09 1月, 2020 1 次提交
  13. 06 1月, 2020 1 次提交
  14. 27 12月, 2019 1 次提交
  15. 21 12月, 2019 1 次提交
    • D
      sbitmap: only queue kyber's wait callback if not already active · df034c93
      David Jeffery 提交于
      Under heavy loads where the kyber I/O scheduler hits the token limits for
      its scheduling domains, kyber can become stuck.  When active requests
      complete, kyber may not be woken up leaving the I/O requests in kyber
      stuck.
      
      This stuck state is due to a race condition with kyber and the sbitmap
      functions it uses to run a callback when enough requests have completed.
      The running of a sbt_wait callback can race with the attempt to insert the
      sbt_wait.  Since sbitmap_del_wait_queue removes the sbt_wait from the list
      first then sets the sbq field to NULL, kyber can see the item as not on a
      list but the call to sbitmap_add_wait_queue will see sbq as non-NULL. This
      results in the sbt_wait being inserted onto the wait list but ws_active
      doesn't get incremented.  So the sbitmap queue does not know there is a
      waiter on a wait list.
      
      Since sbitmap doesn't think there is a waiter, kyber may never be
      informed that there are domain tokens available and the I/O never advances.
      With the sbt_wait on a wait list, kyber believes it has an active waiter
      so cannot insert a new waiter when reaching the domain's full state.
      
      This race can be fixed by only adding the sbt_wait to the queue if the
      sbq field is NULL.  If sbq is not NULL, there is already an action active
      which will trigger the re-running of kyber.  Let it run and add the
      sbt_wait to the wait list if still needing to wait.
      Reviewed-by: NOmar Sandoval <osandov@fb.com>
      Signed-off-by: NDavid Jeffery <djeffery@redhat.com>
      Reported-by: NJohn Pittman <jpittman@redhat.com>
      Tested-by: NJohn Pittman <jpittman@redhat.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      df034c93
  16. 18 12月, 2019 1 次提交
  17. 17 12月, 2019 1 次提交
  18. 10 12月, 2019 1 次提交
  19. 08 12月, 2019 1 次提交