Comments

Kernel – 5.6-rc3 – OK with Patched VMware, not with Patched NVIDIA.. — 1 Comment

  1. From 9caba3eee922d974f269667ee632b5e33ba12a91 Mon Sep 17 00:00:00 2001
    From: Dark Shenada
    Date: Sat, 14 Mar 2020 17:31:51 +0800
    Subject: [PATCH] Kernel 5.6rc3 support for nvidia 440.64

    Rework patch from
    https://github.com/Tk-Glitch/PKGBUILDS/nvidia-all/patches/kernel-5.6.patch

    Signed-off-by: Dark Shenada
    Signed-off-by: Dark Shenada

    common/inc/nv-procfs.h | 52 ++++++++++++++++++++++++++
    common/inc/nv-time.h | 82 +++++++++++++++++++++++++++++++++++++++++
    conftest.sh | 10 +++++
    nvidia/linux_nvswitch.c | 3 ++
    nvidia/nv-procfs.c | 65 ++++++++++++++++++++++++++++++++
    nvidia/nvidia.Kbuild | 1 +
    nvidia/os-interface.c | 6 +++
    7 files changed, 219 insertions(+)

    diff –git a/common/inc/nv-procfs.h b/common/inc/nv-procfs.h
    index 8b53f86..4c5aceb 100644
    — a/common/inc/nv-procfs.h
    +++ b/common/inc/nv-procfs.h
    @@ -28,6 +28,18 @@

    #define IS_EXERCISE_ERROR_FORWARDING_ENABLED() (EXERCISE_ERROR_FORWARDING)

    +#if defined(NV_HAVE_PROC_OPS)
    +#define NV_CREATE_PROC_FILE(filename,parent,__name,__data) \
    + ({ \
    + struct proc_dir_entry *__entry; \
    + int mode = (S_IFREG | S_IRUGO); \
    + const struct proc_ops *fops = &nv_procfs_##__name##_fops; \
    + if (fops->proc_write != 0) \
    + mode |= S_IWUSR; \
    + __entry = proc_create_data(filename, mode, parent, fops, __data);\
    + __entry; \
    + })
    +#else
    #define NV_CREATE_PROC_FILE(filename,parent,__name,__data) \
    ({ \
    struct proc_dir_entry *__entry; \
    @@ -38,6 +50,7 @@
    __entry = proc_create_data(filename, mode, parent, fops, __data);\
    __entry; \
    })
    +#endif

    /*
    * proc_mkdir_mode exists in Linux 2.6.9, but isn’t exported until Linux 3.0.
    @@ -77,6 +90,44 @@
    remove_proc_entry(entry->name, entry->parent);
    #endif

    +#if defined(NV_HAVE_PROC_OPS)
    +#define NV_DEFINE_SINGLE_PROCFS_FILE(name, open_callback, close_callback) \
    + static int nv_procfs_open_##name( \
    + struct inode *inode, \
    + struct file *filep \
    + ) \
    + { \
    + int ret; \
    + ret = single_open(filep, nv_procfs_read_##name, \
    + NV_PDE_DATA(inode)); \
    + if (ret < 0) \
    + { \
    + return ret; \
    + } \
    + ret = open_callback(); \
    + if (ret < 0) \
    + { \
    + single_release(inode, filep); \
    + } \
    + return ret; \
    + } \
    + \
    + static int nv_procfs_release_##name( \
    + struct inode *inode, \
    + struct file *filep \
    + ) \
    + { \
    + close_callback(); \
    + return single_release(inode, filep); \
    + } \
    + \
    + static const struct proc_ops nv_procfs_##name##_fops = { \
    + .proc_open = nv_procfs_open_##name, \
    + .proc_read = seq_read, \
    + .proc_lseek = seq_lseek, \
    + .proc_release = nv_procfs_release_##name, \
    + };
    +#else
    #define NV_DEFINE_SINGLE_PROCFS_FILE(name, open_callback, close_callback) \
    static int nv_procfs_open_##name( \
    struct inode *inode, \
    @@ -114,6 +165,7 @@
    .llseek = seq_lseek, \
    .release = nv_procfs_release_##name, \
    };
    +#endif

    #endif /* CONFIG_PROC_FS */

    diff –git a/common/inc/nv-time.h b/common/inc/nv-time.h
    index 968b873..fc01ae6 100644
    — a/common/inc/nv-time.h
    +++ b/common/inc/nv-time.h
    @@ -26,6 +26,88 @@
    #include "conftest.h"

    #include
    +#include
    +
    +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
    +typedef __kernel_long_t __kernel_time_t;
    +
    +#ifndef _STRUCT_TIMESPEC
    +#define _STRUCT_TIMESPEC
    +struct timespec {
    + __kernel_old_time_t tv_sec; /* seconds */
    + long tv_nsec; /* nanoseconds */
    +};
    +#endif
    +
    +struct timeval {
    + __kernel_old_time_t tv_sec; /* seconds */
    + __kernel_suseconds_t tv_usec; /* microseconds */
    +};
    +
    +struct itimerspec {
    + struct timespec it_interval;/* timer period */
    + struct timespec it_value; /* timer expiration */
    +};
    +
    +struct itimerval {
    + struct timeval it_interval;/* timer interval */
    + struct timeval it_value; /* current value */
    +};
    +
    +#if __BITS_PER_LONG == 64
    +
    +/* timespec64 is defined as timespec here */
    +static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
    +{
    + return *(const struct timespec *)&ts64;
    +}
    +
    +static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
    +{
    + return *(const struct timespec64 *)&ts;
    +}
    +
    +#else
    +static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
    +{
    + struct timespec ret;
    +
    + ret.tv_sec = (time_t)ts64.tv_sec;
    + ret.tv_nsec = ts64.tv_nsec;
    + return ret;
    +}
    +
    +static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
    +{
    + struct timespec64 ret;
    +
    + ret.tv_sec = ts.tv_sec;
    + ret.tv_nsec = ts.tv_nsec;
    + return ret;
    +}
    +#endif // __BITS_PER_LONG == 64
    +
    +static inline void getnstimeofday(struct timespec *ts)
    +{
    + struct timespec64 ts64;
    +
    + ktime_get_real_ts64(&ts64);
    + *ts = timespec64_to_timespec(ts64);
    +}
    +
    +static inline s64 timespec_to_ns(const struct timespec *ts)
    +{
    + return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
    +}
    +
    +static inline void getrawmonotonic(struct timespec *ts)
    +{
    + struct timespec64 ts64;
    +
    + ktime_get_raw_ts64(&ts64);
    + *ts = timespec64_to_timespec(ts64);
    +}
    +#endif // LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)

    static inline void nv_gettimeofday(struct timeval *tv)
    {
    diff –git a/conftest.sh b/conftest.sh
    index 57d85a4..3e612e5 100644
    — a/conftest.sh
    +++ b/conftest.sh
    @@ -806,6 +806,16 @@ compile_test() {
    compile_check_conftest “$CODE” “NV_FILE_OPERATIONS_HAS_IOCTL” “” “types”
    ;;

    + proc_ops)
    + CODE=”
    + #include
    + int conftest_proc_ops(void) {
    + return offsetof(struct proc_ops, proc_open);
    + }”
    +
    + compile_check_conftest “$CODE” “NV_HAVE_PROC_OPS” “” “types”
    + ;;
    +
    sg_alloc_table)
    #
    # sg_alloc_table_from_pages added by commit efc42bc98058
    diff –git a/nvidia/linux_nvswitch.c b/nvidia/linux_nvswitch.c
    index 1d2c1bc..388d64f 100644
    — a/nvidia/linux_nvswitch.c
    +++ b/nvidia/linux_nvswitch.c
    @@ -26,6 +26,9 @@
    #include “conftest.h”
    #include “nvmisc.h”
    #include “nv-linux.h”
    +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
    +#include “nv-time.h”
    +#endif
    #include “nv-procfs.h”
    #include “nvlink_common.h”
    #include “nvlink_errors.h”
    diff –git a/nvidia/nv-procfs.c b/nvidia/nv-procfs.c
    index 064d727..a7308d3 100644
    — a/nvidia/nv-procfs.c
    +++ b/nvidia/nv-procfs.c
    @@ -452,6 +452,15 @@ done:
    return ((status = KERNEL_VERSION(5, 6, 0)
    + struct timespec64 ts;
    +
    + jiffies_to_timespec64(jiffies, &ts);
    +#else
    struct timespec ts;

    jiffies_to_timespec(jiffies, &ts);
    +#endif

    *nseconds = ((NvU64)ts.tv_sec * NSEC_PER_SEC + (NvU64)ts.tv_nsec);
    }

    2.25.1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.