1. 23 Mar, 2021 2 commits
    • Hans Petter Selasky's avatar
      MFC dfb33cb0: · 3e4fe9ca
      Hans Petter Selasky authored
      Allocating the LinuxKPI current structure from a software interrupt thread
      must be done using the M_NOWAIT flag after 1ae20f7c .
      
      Sponsored by:	Mellanox Technologies // NVIDIA Networking
      
      (cherry picked from commit dfb33cb0)
      3e4fe9ca
    • Hans Petter Selasky's avatar
      MFC d1cbe790: · 093204e2
      Hans Petter Selasky authored
      Allocating the LinuxKPI current structure from an interrupt thread must be
      done using the M_NOWAIT flag after 1ae20f7c .
      
      Sponsored by:	Mellanox Technologies // NVIDIA Networking
      
      (cherry picked from commit d1cbe790)
      093204e2
  2. 02 Feb, 2021 1 commit
    • Bjoern A. Zeeb's avatar
      LinuxKPI: implement devres() framework parts and two examples · ff119f7c
      Bjoern A. Zeeb authored
      This code implements a version of the devres framework found
      working for various iwlwifi use cases and also providing functions
      for ttm_page_alloc_dma.c from DRM.
      
      Part of the framework replicates the consumed KPI, while others
      are internal helper functions.
      
      In addition the simple devm_k*malloc() consumers were implemented
      and kvasprintf() was enhanced to also work for the devm_kasprintf()
      case.
      Addmittingly lkpi_devm_kmalloc_release() could be avoided but for
      the overall understanding of the code and possible memory tracing
      it may still be helpful.
      
      Further devsres consumer are implemented for iwlwifi but will follow
      later as the main reason for this change is to sort out overlap with
      DRM.
      
      Sponsored-by:	The FreeBSD Foundation
      Obtained-from:	bz_iwlwifi
      MFC After:	3 days
      Reviewed-by:	hselasky, manu
      Differential Revision:	https://reviews.freebsd.org/D28189
      
      (cherry picked from commit fa765ca7)
      ff119f7c
  3. 09 Nov, 2020 1 commit
  4. 01 Sep, 2020 1 commit
  5. 14 Aug, 2020 1 commit
    • Emmanuel Vadot's avatar
      linuxkpi: Add a few wait_bit functions · 0e123c13
      Emmanuel Vadot authored
      The linux function does a lot more than that as multiple waitqueue could be fetch
      from a static table based on the hash of the argument but since in DRM it's only used
      in one place just add a single variable.
      We will probably need to change that in the futur but it's ok with DRM even with current
      linux.
      
      Reviewed by:	hselasky
      MFC after:	1 week
      Sponsored by:	The FreeBSD Foundation
      Differential Revision:	https://reviews.freebsd.org/D26054
      0e123c13
  6. 07 Aug, 2020 1 commit
  7. 25 May, 2020 1 commit
  8. 04 May, 2020 1 commit
    • Hans Petter Selasky's avatar
      Fix warning about sleeping with non-sleepable lock when allocating · 42f8ef4b
      Hans Petter Selasky authored
      "current" from linux_cdev_pager_populate() in the LinuxKPI:
      
      Backtrace:
      witness_debugger()
      witness_warn()
      uma_zalloc_arg()
      malloc()
      linux_alloc_current()
      linux_cdev_pager_populate()
      vm_fault()
      vm_fault_trap()
      trap_pfault()
      trap()
      calltrap()
      
      Suggested by:	avg@
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      42f8ef4b
  9. 03 Mar, 2020 1 commit
  10. 27 Feb, 2020 1 commit
  11. 15 Feb, 2020 1 commit
  12. 28 Jan, 2020 1 commit
  13. 15 Jan, 2020 1 commit
  14. 03 Jan, 2020 1 commit
  15. 22 Dec, 2019 1 commit
    • Jeff Roberson's avatar
      Make page busy state deterministic on free. Pages must be xbusy when · 3cf3b4e6
      Jeff Roberson authored
      removed from objects including calls to free.  Pages must not be xbusy
      when freed and not on an object.  Strengthen assertions to match these
      expectations.  In practice very little code had to change busy handling
      to meet these rules but we can now make stronger guarantees to busy
      holders and avoid conditionally dropping busy in free.
      
      Refine vm_page_remove() and vm_page_replace() semantics now that we have
      stronger guarantees about busy state.  This removes redundant and
      potentially problematic code that has proliferated.
      
      Discussed with:	markj
      Reviewed by:	kib
      Differential Revision:	https://reviews.freebsd.org/D22822
      3cf3b4e6
  16. 15 Oct, 2019 1 commit
  17. 09 Sep, 2019 1 commit
    • Mark Johnston's avatar
      Change synchonization rules for vm_page reference counting. · fee2a2fa
      Mark Johnston authored
      There are several mechanisms by which a vm_page reference is held,
      preventing the page from being freed back to the page allocator.  In
      particular, holding the page's object lock is sufficient to prevent the
      page from being freed; holding the busy lock or a wiring is sufficent as
      well.  These references are protected by the page lock, which must
      therefore be acquired for many per-page operations.  This results in
      false sharing since the page locks are external to the vm_page
      structures themselves and each lock protects multiple structures.
      
      Transition to using an atomically updated per-page reference counter.
      The object's reference is counted using a flag bit in the counter.  A
      second flag bit is used to atomically block new references via
      pmap_extract_and_hold() while removing managed mappings of a page.
      Thus, the reference count of a page is guaranteed not to increase if the
      page is unbusied, unmapped, and the object's write lock is held.  As
      a consequence of this, the page lock no longer protects a page's
      identity; operations which move pages between objects are now
      synchronized solely by the objects' locks.
      
      The vm_page_wire() and vm_page_unwire() KPIs are changed.  The former
      requires that either the object lock or the busy lock is held.  The
      latter no longer has a return value and may free the page if it releases
      the last reference to that page.  vm_page_unwire_noq() behaves the same
      as before; the caller is responsible for checking its return value and
      freeing or enqueuing the page as appropriate.  vm_page_wire_mapped() is
      introduced for use in pmap_extract_and_hold().  It fails if the page is
      concurrently being unmapped, typically triggering a fallback to the
      fault handler.  vm_page_wire() no longer requires the page lock and
      vm_page_unwire() now internally acquires the page lock when releasing
      the last wiring of a page (since the page lock still protects a page's
      queue state).  In particular, synchronization details are no longer
      leaked into the caller.
      
      The change excises the page lock from several frequently executed code
      paths.  In particular, vm_object_terminate() no longer bounces between
      page locks as it releases an object's pages, and direct I/O and
      sendfile(SF_NOCACHE) completions no longer require the page lock.  In
      these latter cases we now get linear scalability in the common scenario
      where different threads are operating on different files.
      
      __FreeBSD_version is bumped.  The DRM ports have been updated to
      accomodate the KPI changes.
      
      Reviewed by:	jeff (earlier version)
      Tested by:	gallatin (earlier version), pho
      Sponsored by:	Netflix
      Differential Revision:	https://reviews.freebsd.org/D20486
      fee2a2fa
  18. 21 May, 2019 1 commit
    • Conrad Meyer's avatar
      Include eventhandler.h in more compilation units · e12be321
      Conrad Meyer authored
      This was enumerated with exhaustive search for sys/eventhandler.h includes,
      cross-referenced against EVENTHANDLER_* usage with the comm(1) utility.  Manual
      checking was performed to avoid redundant includes in some drivers where a
      common os_bsd.h (for example) included sys/eventhandler.h indirectly, but it is
      possible some of these are redundant with driver-specific headers in ways I
      didn't notice.
      
      (These CUs did not show up as missing eventhandler.h in tinderbox.)
      
      X-MFC-With:	r347984
      e12be321
  19. 16 May, 2019 1 commit
    • Johannes Lundberg's avatar
      LinuxKPI: Update access_ok macro for v5.0. · 47e2723a
      Johannes Lundberg authored
      Check LINUXKPI_VERSION macro for backwards compatibility.
      It's recommended to update any drivers that depend on the older KPI
      so we can deprecate < 5.0 code as we update to newer Linux version.
      This patch is part of D19565
      
      Reviewed by:	hps
      Approved by:	imp (mentor), hps
      MFC after:	1 week
      47e2723a
  20. 14 May, 2019 1 commit
  21. 06 May, 2019 1 commit
    • Hans Petter Selasky's avatar
      Allow controlling pr_debug at runtime in the LinuxKPI. · 4580f5ea
      Hans Petter Selasky authored
      Turning on pr_debug at compile time make it non-optional at runtime.
      This often means that the amount of the debugging is unbearable.
      Allow developer to turn on pr_debug output only when needed.
      
      Build tested drm-current-kmod prior to commit.
      
      MFC after:		1 week
      Submitted by:		kib@
      Sponsored by:		Mellanox Technologies
      4580f5ea
  22. 25 Apr, 2019 1 commit
  23. 20 Apr, 2019 1 commit
  24. 30 Dec, 2018 4 commits
    • Konstantin Belousov's avatar
      Fix 32bit gcc builds after r342625. · 9362b6a3
      Konstantin Belousov authored
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      9362b6a3
    • Konstantin Belousov's avatar
      Fix linux_destroy_dev() behaviour when there are still files open from · f823a36e
      Konstantin Belousov authored
      the destroying cdev.
      
      Currently linux_destroy_dev() waits for the reference count on the
      linux cdev to drain, and each open file hold the reference.
      Practically it means that linux_destroy_dev() is blocked until all
      userspace processes that have the cdev open, exit.  FreeBSD devfs does
      not have such problem, because device refcount only prevents freeing
      of the cdev memory, and separate 'active methods' counter blocks
      destroy_dev() until all threads leave the cdevsw methods.  After that,
      attempts to enter cdevsw methods are refused with an error.
      
      Implement somewhat similar mechanism for LinuxKPI cdevs.  Demote cdev
      refcount to only mean a hold on the linux cdev memory.  Add sirefs
      count to track both number of threads inside the cdev methods, and for
      single-bit indicator that cdev is being destroyed.  In the later case,
      the call is redirected to the dummy cdev.
      
      Reviewed by:	markj
      Discussed with:	hselasky
      Tested by:	zeising
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      Differential revision:	https://reviews.freebsd.org/D18606
      f823a36e
    • Konstantin Belousov's avatar
      Implement zap_vma_ptes() for managed device objects. · e5a3393a
      Konstantin Belousov authored
      Reviewed by:	markj
      Discussed with:	hselasky
      Tested by:	zeising
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      Differential revision:	https://reviews.freebsd.org/D18606
      e5a3393a
    • Konstantin Belousov's avatar
      Use IDX_TO_OFF(). · 069598b9
      Konstantin Belousov authored
      Reviewed by:	markj
      Discussed with:	hselasky
      Tested by:	zeising
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      Differential revision:	https://reviews.freebsd.org/D18606
      069598b9
  25. 05 Dec, 2018 1 commit
  26. 03 Dec, 2018 1 commit
    • Konstantin Belousov's avatar
      Improve procstat reporting for the linux cdev file descriptors. · f1863400
      Konstantin Belousov authored
      If there is a vnode attached to the linux file, use it to fill
      kinfo_file.  Otherwise, report a new KF_TYPE_DEV file type, without
      supplying any type-specific information.
      
      KF_TYPE_DEV is supposed to be used by most devfs-specific file types.
      
      Sponsored by:	Mellanox Technologies
      MFC after:	1 week
      f1863400
  27. 30 Oct, 2018 1 commit
  28. 30 Mar, 2018 1 commit
    • Hans Petter Selasky's avatar
      Optimise use of Giant in the LinuxKPI. · 4b706099
      Hans Petter Selasky authored
      - Make sure Giant is locked when calling PCI device methods.
      Newbus currently requires this.
      
      - Avoid unlocking Giant right before aquiring the sleepqueue lock.
      This can save a task switch.
      
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      4b706099
  29. 23 Mar, 2018 1 commit
  30. 09 Mar, 2018 1 commit
    • Hans Petter Selasky's avatar
      Implement proper support for complete_all() in the LinuxKPI. · be15e133
      Hans Petter Selasky authored
      When complete_all() is called there might be multiple waiters. The
      current implementation could only handle one waiter. Make sure the
      completion is sticky when complete_all() is called to be compatible
      with Linux.
      
      Found by:	Johannes Lundberg <johalun0@gmail.com>
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      Sponsored by:	Limelight Networks
      be15e133
  31. 02 Mar, 2018 1 commit
  32. 22 Feb, 2018 1 commit
    • Hans Petter Selasky's avatar
      Return correct error code to user-space when a system call receives a · 94944062
      Hans Petter Selasky authored
      signal in the LinuxKPI.
      
      The read(), write() and mmap() system calls can return either EINTR or
      ERESTART upon receiving a signal. Add code to figure out the correct
      return value by temporarily storing the return code from the relevant
      FreeBSD kernel APIs in the Linux task structure.
      
      MFC after:	3 days
      Sponsored by:	Mellanox Technologies
      94944062
  33. 18 Feb, 2018 1 commit
  34. 01 Feb, 2018 2 commits
  35. 26 Jan, 2018 1 commit
    • Hans Petter Selasky's avatar
      Decouple Linux files from the belonging character device right after open · e23ae408
      Hans Petter Selasky authored
      in the LinuxKPI. This is done by calling finit() just before returning a magic
      value of ENXIO in the "linux_dev_fdopen" function.
      
      The Linux file structure should mimic the BSD file structure as much as
      possible. This patch decouples the Linux file structure from the belonging
      character device right after the "linux_dev_fdopen" function has returned.
      This fixes an issue which allows a Linux file handle to exist after a
      character device has been destroyed and removed from the directory index
      of /dev. Only when the reference count of the BSD file handle reaches zero,
      the Linux file handle is destroyed. This fixes use-after-free issues related
      to accessing the Linux file structure after the character device has been
      destroyed.
      
      While at it add a missing NULL check for non-present file operation.
      Calling a NULL pointer will result in a segmentation fault.
      
      Reviewed by:	kib @
      MFC after:	1 week
      Sponsored by:	Mellanox Technologies
      e23ae408