tools/power turbostat: Fix added raw MSR output
Subsystems (18)
Sasha Levin
maintainerPATCH 1/43 tools/power turbostat: Fix added raw MSR output
From: Doug Smythies <[email protected]>
[ Upstream commit e5f4e68eed85fa8495d78cd966eecc2b27bb9e53 ]
When using --Summary mode, added MSRs in raw mode always print zeros. Print the actual register contents.
Example, with patch:
note the added column:
--add msr0x64f,u32,package,raw,REASON
Where:
0x64F is MSR_CORE_PERF_LIMIT_REASONS
Busy% Bzy_MHz PkgTmp PkgWatt CorWatt REASON 0.00 4800 35 1.42 0.76 0x00000000 0.00 4801 34 1.42 0.76 0x00000000 80.08 4531 66 108.17 107.52 0x08000000 98.69 4530 66 133.21 132.54 0x08000000 99.28 4505 66 128.26 127.60 0x0c000400 99.65 4486 68 124.91 124.25 0x0c000400 99.63 4483 68 124.90 124.25 0x0c000400 79.34 4481 41 99.80 99.13 0x0c000000 0.00 4801 41 1.40 0.73 0x0c000000
Where, for the test processor (i5-10600K):
PKG Limit #1: 125.000 Watts, 8.000000 sec
MSR bit 26 = log; bit 10 = status
PKG Limit #2: 136.000 Watts, 0.002441 sec
MSR bit 27 = log; bit 11 = status
Example, without patch:
Busy% Bzy_MHz PkgTmp PkgWatt CorWatt REASON 0.01 4800 35 1.43 0.77 0x00000000 0.00 4801 35 1.39 0.73 0x00000000 83.49 4531 66 112.71 112.06 0x00000000 98.69 4530 68 133.35 132.69 0x00000000 99.31 4500 67 127.96 127.30 0x00000000 99.63 4483 69 124.91 124.25 0x00000000 99.61 4481 69 124.90 124.25 0x00000000 99.61 4481 71 124.92 124.25 0x00000000 59.35 4479 42 75.03 74.37 0x00000000 0.00 4800 42 1.39 0.73 0x00000000 0.00 4801 42 1.42 0.76 0x00000000
c000000
[lenb: simplified patch to apply only to package scope]
--- tools/power/x86/turbostat/turbostat.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/power/x86/turbostat/turbostat.c +4 -3
@@ -2444,9 +2444,10 @@ int sum_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status;for (i =0 , mp = sys.pp; mp; i++, mp = mp->next) { -if (mp->format ==FORMAT_RAW ) -continue ; - average.packages.counter[i] += p->counter[i]; +if ((mp->format ==FORMAT_RAW ) && (topo.num_packages ==0 )) + average.packages.counter[i] = p->counter[i]; +else + average.packages.counter[i] += p->counter[i]; }return 0 ; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 2/43 tools/power turbostat: Increase the limit for fd opened
From: Wyes Karny <[email protected]>
[ Upstream commit 3ac1d14d0583a2de75d49a5234d767e2590384dd ]
When running turbostat, a system with 512 cpus reaches the limit for maximum number of file descriptors that can be opened. To solve this problem, the limit is raised to 2^15, which is a large enough number.
Below data is collected from AMD server systems while running turbostat:
|-----------+-------------------------------| | # of cpus | # of opened fds for turbostat | |-----------+-------------------------------| | 128 | 260 | |-----------+-------------------------------| | 192 | 388 | |-----------+-------------------------------| | 512 | 1028 | |-----------+-------------------------------|
So, the new max limit would be sufficient up to 2^14 cpus (but this also depends on how many counters are enabled).
--- tools/power/x86/turbostat/turbostat.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/power/x86/turbostat/turbostat.c +21 -0
@@ -53,6 +53,8 @@#define NAME_BYTES 20#define PATH_BYTES 128 +#define MAX_NOFILE 0x8000 +enum counter_scope {SCOPE_CPU ,SCOPE_CORE ,SCOPE_PACKAGE };enum counter_type {COUNTER_ITEMS ,COUNTER_CYCLES ,COUNTER_SECONDS ,COUNTER_USEC };enum counter_format {FORMAT_RAW ,FORMAT_DELTA ,FORMAT_PERCENT };
@@ -6705,6 +6707,22 @@ void cmdline(int argc, char **argv) } } +void set_rlimit (void ) +{ +struct rlimit limit; + +if (getrlimit (RLIMIT_NOFILE , &limit) <0 ) +err (1 ,"Failed to get rlimit" ); + +if (limit.rlim_max <MAX_NOFILE ) + limit.rlim_max =MAX_NOFILE ; +if (limit.rlim_cur <MAX_NOFILE ) + limit.rlim_cur =MAX_NOFILE ; + +if (setrlimit (RLIMIT_NOFILE , &limit) <0 ) +err (1 ,"Failed to set rlimit" ); +} +int main (int argc,char **argv) {int fd, ret;
@@ -6730,6 +6748,9 @@ int main(int argc, char **argv)probe_sysfs (); +if (!getuid ()) +set_rlimit (); +turbostat_init ();msr_sum_record ();
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 3/43 tools/power turbostat: Fix Bzy_MHz documentation typo
In reply to Sasha LevinFrom: Peng Liu <[email protected]>
[ Upstream commit 0b13410b52c4636aacb6964a4253a797c0fa0d16 ]
The code calculates Bzy_MHz by multiplying TSC_delta * APERF_delta/MPERF_delta The man page erroneously showed that TSC_delta was divided.
--- tools/power/x86/turbostat/turbostat.8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.8 +1 -1
@@ -370,7 +370,7 @@ below the processor's base frequency. Busy% = MPERF_delta/TSC_delta -Bzy_MHz = TSC_delta/APERF_delta/MPERF_delta/measurement_interval +Bzy_MHz = TSC_delta*APERF_delta/MPERF_delta/measurement_interval Note that these calculations depend on TSC_delta, so they are not reliable during intervals when TSC_MHz is not running at the base frequency.
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 4/43 tools/power turbostat: Do not print negative LPI residency
In reply to Sasha LevinFrom: Chen Yu <[email protected]>
[ Upstream commit 227ed18f456a68bbb69807294a9089208663a6d3 ]
turbostat prints the abnormal SYS%LPI across suspend-to-idle:
SYS%LPI = 114479815993277.50
This is reproduced by:
Run a freeze cycle, e.g. "sleepgraph -m freeze -rtcwake 15". Then do a reboot. After boot up, launch the suspend-idle-idle and check the SYS%LPI field.
The slp_so residence counter is in LPIT table, and BIOS does not clears this register across reset. The PMC expects the OS to calculate the LPI residency based on the delta. However, there is an firmware issue that the LPIT gets cleared to 0 during the second suspend to idle after the reboot, which brings negative delta value.
[lenb: updated to print "neg" upon this BIOS failure]
--- tools/power/x86/turbostat/turbostat.c | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-)
tools/power/x86/turbostat/turbostat.c +21 -9
@@ -991,8 +991,8 @@ struct pkg_data {unsigned long long pc8;unsigned long long pc9;unsigned long long pc10; -unsigned long long cpu_lpi; -unsigned long long sys_lpi; +long long cpu_lpi; +long long sys_lpi;unsigned long long pkg_wtd_core_c0;unsigned long long pkg_any_core_c0;unsigned long long pkg_any_gfxe_c0;
@@ -1978,12 +1978,22 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_dataif (DO_BIC (BIC_Pkgpc10)) outp +=sprintf (outp,"%s%.2f" , (printed++ ? delim :"" ),100.0 * p->pc10 / tsc); -if (DO_BIC (BIC_CPU_LPI )) - outp += -sprintf (outp,"%s%.2f" , (printed++ ? delim :"" ),100.0 * p->cpu_lpi /1000000.0 / interval_float); -if (DO_BIC (BIC_SYS_LPI )) - outp += -sprintf (outp,"%s%.2f" , (printed++ ? delim :"" ),100.0 * p->sys_lpi /1000000.0 / interval_float); +if (DO_BIC (BIC_CPU_LPI )) { +if (p->cpu_lpi >=0 ) + outp += +sprintf (outp,"%s%.2f" , (printed++ ? delim :"" ), +100.0 * p->cpu_lpi /1000000.0 / interval_float); +else + outp +=sprintf (outp,"%s(neg)" , (printed++ ? delim :"" )); + } +if (DO_BIC (BIC_SYS_LPI )) { +if (p->sys_lpi >=0 ) + outp += +sprintf (outp,"%s%.2f" , (printed++ ? delim :"" ), +100.0 * p->sys_lpi /1000000.0 / interval_float); +else + outp +=sprintf (outp,"%s(neg)" , (printed++ ? delim :"" )); + }if (DO_BIC (BIC_PkgWatt)) outp +=
@@ -3832,7 +3842,8 @@ void re_initialize(void) {free_all_buffers ();setup_all_buffers (false); -fprintf (outf,"turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n" , topo.num_cpus, topo.allowed_cpus); +fprintf (outf,"turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n" , topo.num_cpus, + topo.allowed_cpus); }void set_max_cpu_num (void )
@@ -6145,6 +6156,7 @@ void topology_update(void) topo.allowed_packages =0 ;for_all_cpus (update_topo,ODD_COUNTERS ); } +void setup_all_buffers (bool startup) {topology_probe (startup);
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 5/43 tools/power turbostat: Expand probe_intel_uncore_frequency()
In reply to Sasha LevinFrom: Len Brown <[email protected]>
[ Upstream commit bb6181fa6bc942aac3f7f2fa8e3831952a2ef118 ]
Print current frequency along with the current (and initial) limits
Probe and print uncore config also for machines using the new cluster API
--- tools/power/x86/turbostat/turbostat.c | 84 ++++++++++++++++++++------- 1 file changed, 63 insertions(+), 21 deletions(-)
tools/power/x86/turbostat/turbostat.c +63 -21
@@ -4581,20 +4581,15 @@ static void dump_sysfs_file(char *path)static void probe_intel_uncore_frequency (void ) {int i, j; -char path[128 ]; +char path[256 ];if (!genuine_intel)return ; -if (access ("/sys/devices/system/cpu/intel_uncore_frequency/package_00_die_00" ,R_OK )) -return ; - -/* Cluster level sysfs not supported yet. */ -if (!access ("/sys/devices/system/cpu/intel_uncore_frequency/uncore00" ,R_OK )) -return ; +if (access ("/sys/devices/system/cpu/intel_uncore_frequency/package_00_die_00/current_freq_khz" ,R_OK )) + goto probe_cluster; -if (!access ("/sys/devices/system/cpu/intel_uncore_frequency/package_00_die_00/current_freq_khz" ,R_OK )) -BIC_PRESENT (BIC_UNCORE_MHZ ); +BIC_PRESENT (BIC_UNCORE_MHZ );if (quiet)return ;
@@ -4602,26 +4597,73 @@ static void probe_intel_uncore_frequency(void)for (i =0 ; i < topo.num_packages; ++i) {for (j =0 ; j < topo.num_die; ++j) {int k, l; +char path_base[128 ]; + +sprintf (path_base,"/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d" , i, + j); -sprintf (path,"/sys/devices/system/cpu/intel_uncore_frequency/package_0%d_die_0%d/min_freq_khz" , - i, j); +sprintf (path,"%s/min_freq_khz" , path_base); k =read_sysfs_int (path); -sprintf (path,"/sys/devices/system/cpu/intel_uncore_frequency/package_0%d_die_0%d/max_freq_khz" , - i, j); +sprintf (path,"%s/max_freq_khz" , path_base); l =read_sysfs_int (path); -fprintf (outf,"Uncore Frequency pkg%d die%d: %d - %d MHz " , i, j, k /1000 , l /1000 ); +fprintf (outf,"Uncore Frequency package%d die%d: %d - %d MHz " , i, j, k /1000 , l /1000 ); -sprintf (path, -"/sys/devices/system/cpu/intel_uncore_frequency/package_0%d_die_0%d/initial_min_freq_khz" , - i, j); +sprintf (path,"%s/initial_min_freq_khz" , path_base); k =read_sysfs_int (path); -sprintf (path, -"/sys/devices/system/cpu/intel_uncore_frequency/package_0%d_die_0%d/initial_max_freq_khz" , - i, j); +sprintf (path,"%s/initial_max_freq_khz" , path_base); l =read_sysfs_int (path); -fprintf (outf,"(%d - %d MHz)\n" , k /1000 , l /1000 ); +fprintf (outf,"(%d - %d MHz)" , k /1000 , l /1000 ); + +sprintf (path,"%s/current_freq_khz" , path_base); + k =read_sysfs_int (path); +fprintf (outf," %d MHz\n" , k /1000 ); } } +return ; + +probe_cluster: +if (access ("/sys/devices/system/cpu/intel_uncore_frequency/uncore00/current_freq_khz" ,R_OK )) +return ; + +if (quiet) +return ; + +for (i =0 ;; ++i) { +int k, l; +char path_base[128 ]; +int package_id, domain_id, cluster_id; + +sprintf (path_base,"/sys/devices/system/cpu/intel_uncore_frequency/uncore%02d" , i); + +if (access (path_base,R_OK )) +break ; + +sprintf (path,"%s/package_id" , path_base); + package_id =read_sysfs_int (path); + +sprintf (path,"%s/domain_id" , path_base); + domain_id =read_sysfs_int (path); + +sprintf (path,"%s/fabric_cluster_id" , path_base); + cluster_id =read_sysfs_int (path); + +sprintf (path,"%s/min_freq_khz" , path_base); + k =read_sysfs_int (path); +sprintf (path,"%s/max_freq_khz" , path_base); + l =read_sysfs_int (path); +fprintf (outf,"Uncore Frequency package%d domain%d cluster%d: %d - %d MHz " , package_id, domain_id, + cluster_id, k /1000 , l /1000 ); + +sprintf (path,"%s/initial_min_freq_khz" , path_base); + k =read_sysfs_int (path); +sprintf (path,"%s/initial_max_freq_khz" , path_base); + l =read_sysfs_int (path); +fprintf (outf,"(%d - %d MHz)" , k /1000 , l /1000 ); + +sprintf (path,"%s/current_freq_khz" , path_base); + k =read_sysfs_int (path); +fprintf (outf," %d MHz\n" , k /1000 ); + } }static void probe_graphics (void )
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 6/43 tools/power turbostat: Print ucode revision only if valid
In reply to Sasha LevinFrom: Patryk Wlazlyn <[email protected]>
[ Upstream commit fb5ceca046efc84f69fcf9779a013f8a0e63bbff ]
If the MSR read were to fail, turbostat would print "microcode 0x0"
--- tools/power/x86/turbostat/turbostat.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tools/power/x86/turbostat/turbostat.c +9 -3
@@ -5679,6 +5679,7 @@ void process_cpuid()unsigned int eax, ebx, ecx, edx;unsigned int fms, family, model, stepping, ecx_flags, edx_flags;unsigned long long ucode_patch =0 ; +bool ucode_patch_valid = false; eax = ebx = ecx = edx =0 ;
@@ -5708,6 +5709,8 @@ void process_cpuid()if (get_msr (sched_getcpu (),MSR_IA32_UCODE_REV , &ucode_patch))warnx ("get_msr(UCODE)" ); +else + ucode_patch_valid = true;/* * check max extended function levels of CPUID.
@@ -5718,9 +5721,12 @@ void process_cpuid()__cpuid (0x80000000 , max_extended_level, ebx, ecx, edx);if (!quiet) { -fprintf (outf,"CPUID(1): family:model:stepping 0x%x:%x:%x (%d:%d:%d) microcode 0x%x\n" , - family, model, stepping, family, model, stepping, - (unsigned int )((ucode_patch >>32 ) &0xFFFFFFFF )); +fprintf (outf,"CPUID(1): family:model:stepping 0x%x:%x:%x (%d:%d:%d)" , + family, model, stepping, family, model, stepping); +if (ucode_patch_valid) +fprintf (outf," microcode 0x%x" , (unsigned int )((ucode_patch >>32 ) &0xFFFFFFFF )); +fputc ('\n' , outf); +fprintf (outf,"CPUID(0x80000000): max_extended_levels: 0x%x\n" , max_extended_level); fprintf(outf, "CPUID(1): %s %s %s %s %s %s %s %s %s %s\n", ecx_flags & (1 << 0) ? "SSE3" : "-",
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 7/43 tools/power turbostat: Fix warning upon failed /dev/cpu_dma_latency read
In reply to Sasha LevinFrom: Len Brown <[email protected]>
[ Upstream commit b6fe938317eed58e8c687bd5965a956e15fb5828 ]
Previously a failed read of /dev/cpu_dma_latency erroneously complained
turbostat: capget(CAP_SYS_ADMIN) failed, try "# setcap cap_sys_admin=ep ./turbostat
This went unnoticed because this file is typically visible to root, and turbostat was typically run as root.
Going forward, when a non-root user can run turbostat... Complain about failed read access to this file only if --debug is used.
--- tools/power/x86/turbostat/turbostat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +2 -1
@@ -5545,7 +5545,8 @@ void print_dev_latency(void) fd =open (path,O_RDONLY );if (fd <0 ) { -warnx ("capget(CAP_SYS_ADMIN) failed, try \"# setcap cap_sys_admin=ep %s\"" , progname); +if (debug) +warnx ("Read %s failed" , path);return ; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 8/43 btrfs: make btrfs_clear_delalloc_extent() free delalloc reserve
In reply to Sasha LevinFrom: Boris Burkov <[email protected]>
[ Upstream commit 3c6f0c5ecc8910d4ffb0dfe85609ebc0c91c8f34 ]
Currently, this call site in btrfs_clear_delalloc_extent() only converts the reservation. We are marking it not delalloc, so I don't think it makes sense to keep the rsv around. This is a path where we are not sure to join a transaction, so it leads to incorrect free-ing during umount.
Helps with the pass rate of generic/269 and generic/475.
--- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
@@ -2523,7 +2523,7 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode,*/ if (bits &EXTENT_CLEAR_META_RESV && root != fs_info->tree_root) -btrfs_delalloc_release_metadata (inode, len, false); +btrfs_delalloc_release_metadata (inode, len, true);/* For sanity tests. */ if (btrfs_is_testing (fs_info))
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 9/43 btrfs: always clear PERTRANS metadata during commit
In reply to Sasha LevinFrom: Boris Burkov <[email protected]>
[ Upstream commit 6e68de0bb0ed59e0554a0c15ede7308c47351e2d ]
It is possible to clear a root's IN_TRANS tag from the radix tree, but not clear its PERTRANS, if there is some error in between. Eliminate that possibility by moving the free up to where we clear the tag.
--- fs/btrfs/transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/transaction.c +1 -1
@@ -1496,6 +1496,7 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)radix_tree_tag_clear (&fs_info->fs_roots_radix, (unsigned long )root->root_key.objectid,BTRFS_ROOT_TRANS_TAG ); +btrfs_qgroup_free_meta_all_pertrans (root);spin_unlock (&fs_info->fs_roots_radix_lock);btrfs_free_log (trans, root);
@@ -1520,7 +1521,6 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)if (ret2)return ret2;spin_lock (&fs_info->fs_roots_radix_lock); -btrfs_qgroup_free_meta_all_pertrans (root); } }spin_unlock (&fs_info->fs_roots_radix_lock);
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 10/43 memblock tests: fix undefined reference to `early_pfn_to_nid'
In reply to Sasha LevinFrom: Wei Yang <[email protected]>
[ Upstream commit 7d8ed162e6a92268d4b2b84d364a931216102c8e ]
commit 6a9531c3a880 ("memblock: fix crash when reserved memory is not added to memory") introduce the usage of early_pfn_to_nid, which is not defined in memblock tests.
The original definition of early_pfn_to_nid is defined in mm.h, so let add this in the corresponding mm.h.
--- tools/include/linux/mm.h | 5 +++++ 1 file changed, 5 insertions(+)
tools/include/linux/mm.h +5 -0
@@ -37,4 +37,9 @@ static inline void totalram_pages_add(long count) { } +static inline int early_pfn_to_nid (unsigned long pfn) +{ +return 0 ; +} +#endif
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 11/43 memblock tests: fix undefined reference to `panic'
In reply to Sasha LevinFrom: Wei Yang <[email protected]>
[ Upstream commit e0f5a8e74be88f2476e58b25d3b49a9521bdc4ec ]
commit e96c6b8f212a ("memblock: report failures when memblock_can_resize is not set") introduced the usage of panic, which is not defined in memblock test.
Let's define it directly in panic.h to fix it.
--- tools/include/linux/kernel.h | 1 + tools/include/linux/panic.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tools/include/linux/panic.h
tools/include/linux/kernel.h +1 -0
@@ -8,6 +8,7 @@#include <linux/build_bug.h> #include <linux/compiler.h> #include <linux/math.h> +#include <linux/panic.h> #include <endian.h> #include <byteswap.h>
tools/include/linux/panic.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_PANIC_H +#define _TOOLS_LINUX_PANIC_H + +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> + +static inline void panic (const char *fmt, ...) +{ +va_list argp; + +va_start (argp, fmt); +vfprintf (stderr, fmt, argp); +va_end (argp); +exit (-1 ); +} + +#endif
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 12/43 memblock tests: fix undefined reference to `BIT'
In reply to Sasha LevinFrom: Wei Yang <[email protected]>
[ Upstream commit 592447f6cb3c20d606d6c5d8e6af68e99707b786 ]
commit 772dd0342727 ("mm: enumerate all gfp flags") define gfp flags with the help of BIT, while gfp_types.h doesn't include header file for the definition. This through an error on building memblock tests.
Let's include linux/bits.h to fix it.
--- include/linux/gfp_types.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/gfp_types.h +2 -0
@@ -2,6 +2,8 @@#ifndef __LINUX_GFP_TYPES_H#define __LINUX_GFP_TYPES_H +#include <linux/bits.h> +/* The typedef is in types.h but we want the documentation here */ #if 0 /**
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 13/43 nouveau/gsp: Avoid addressing beyond end of rpc->entries
In reply to Sasha LevinFrom: Kees Cook <[email protected]>
[ Upstream commit 838ae9f45c4e43b4633d8b0ad1fbedff9ecf177d ]
Using the end of rpc->entries[] for addressing runs into both compile-time and run-time detection of accessing beyond the end of the array. Use the base pointer instead, since was allocated with the additional bytes for storing the strings. Avoids the following warning in future GCC releases with support for __counted_by:
In function 'fortify_memcpy_chk',
inlined from 'r535_gsp_rpc_set_registry' at ../drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1123:3:
../include/linux/fortify-string.h:553:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
553 | __write_overflow_field(p_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~for this code:
strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES];
...
memcpy(strings, r535_registry_entries[i].name, name_len);--- drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c +1 -1
@@ -1112,7 +1112,7 @@ r535_gsp_rpc_set_registry(struct nvkm_gsp *gsp) rpc->numEntries =NV_GSP_REG_NUM_ENTRIES ; str_offset = offsetof(typeof(*rpc), entries[NV_GSP_REG_NUM_ENTRIES]); - strings = (char *)&rpc->entries[NV_GSP_REG_NUM_ENTRIES ]; + strings = (char *)rpc + str_offset;for (i =0 ; i <NV_GSP_REG_NUM_ENTRIES ; i++) {int name_len =strlen (r535_registry_entries[i].name) +1 ;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 14/43 scsi: target: Fix SELinux error when systemd-modules loads the target module
In reply to Sasha LevinFrom: Maurizio Lombardi <[email protected]>
[ Upstream commit 97a54ef596c3fd24ec2b227ba8aaf2cf5415e779 ]
If the systemd-modules service loads the target module, the credentials of that userspace process will be used to validate the access to the target db directory. SELinux will prevent it, reporting an error like the following:
kernel: audit: type=1400 audit(1676301082.205:4): avc: denied { read } for pid=1020 comm="systemd-modules" name="target" dev="dm-3" ino=4657583 scontext=system_u:system_r:systemd_modules_load_t:s0 tcontext=system_u:object_r:targetd_etc_rw_t:s0 tclass=dir permissive=0
Fix the error by using the kernel credentials to access the db directory
--- drivers/target/target_core_configfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/target/target_core_configfs.c +12 -0
@@ -3672,6 +3672,8 @@ static int __init target_core_init_configfs(void) {struct configfs_subsystem *subsys = &target_core_fabrics;struct t10_alua_lu_gp *lu_gp; +struct cred *kern_cred; +const struct cred *old_cred;int ret; pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
@@ -3748,11 +3750,21 @@ static int __init target_core_init_configfs(void)if (ret <0 ) goto out; +/* We use the kernel credentials to access the target directory */ + kern_cred =prepare_kernel_cred (&init_task); +if (!kern_cred) { + ret = -ENOMEM ; + goto out; + } + old_cred =override_creds (kern_cred);target_init_dbroot (); +revert_creds (old_cred); +put_cred (kern_cred);return 0 ; out: +target_xcopy_release_pt ();configfs_unregister_subsystem (subsys);core_dev_release_virtual_lun0 ();rd_module_exit ();
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 15/43 scsi: hisi_sas: Handle the NCQ error returned by D2H frame
In reply to Sasha LevinFrom: Xiang Chen <[email protected]>
[ Upstream commit 358e919a351f2ea4b412e7dac6b1c23ec10bd4f5 ]
We find that some disks use D2H frame instead of SDB frame to return NCQ error. Currently, only the I/O corresponding to the D2H frame is processed in this scenario, which does not meet the processing requirements of the NCQ error scenario. So we set dev_status to HISI_SAS_DEV_NCQ_ERR and abort all I/Os of the disk in this scenario.
--- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +9 -1
@@ -2244,7 +2244,15 @@ slot_err_v3_hw(struct hisi_hba *hisi_hba, struct sas_task *task,case SAS_PROTOCOL_SATA |SAS_PROTOCOL_STP :if ((dw0 &CMPLT_HDR_RSPNS_XFRD_MSK ) && (sipc_rx_err_type &RX_FIS_STATUS_ERR_MSK )) { - ts->stat =SAS_PROTO_RESPONSE ; +if (task->ata_task.use_ncq) { +struct domain_device *device = task->dev; +struct hisi_sas_device *sas_dev = device->lldd_dev; + + sas_dev->dev_status =HISI_SAS_DEV_NCQ_ERR ; + slot->abort =1 ; + }else { + ts->stat =SAS_PROTO_RESPONSE ; + } }else if (dma_rx_err_type &RX_DATA_LEN_UNDERFLOW_MSK ) { ts->residual = trans_tx_fail_type; ts->stat =SAS_DATA_UNDERRUN ;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 16/43 blk-iocost: avoid out of bounds shift
In reply to Sasha LevinFrom: Rik van Riel <[email protected]>
[ Upstream commit beaa51b36012fad5a4d3c18b88a617aea7a9b96d ]
UBSAN catches undefined behavior in blk-iocost, where sometimes iocg->delay is shifted right by a number that is too large, resulting in undefined behavior on some architectures.
[ 186.556576] ------------[ cut here ]------------ UBSAN: shift-out-of-bounds in block/blk-iocost.c:1366:23 shift exponent 64 is too large for 64-bit type 'u64' (aka 'unsigned long long') CPU: 16 PID: 0 Comm: swapper/16 Tainted: G S E N 6.9.0-0_fbk700_debug_rc2_kbuilder_0_gc85af715cac0 #1 Hardware name: Quanta Twin Lakes MP/Twin Lakes Passive MP, BIOS F09_3A23 12/08/2020 Call Trace: <IRQ> dump_stack_lvl+0x8f/0xe0 __ubsan_handle_shift_out_of_bounds+0x22c/0x280 iocg_kick_delay+0x30b/0x310 ioc_timer_fn+0x2fb/0x1f80 __run_timer_base+0x1b6/0x250
...
Avoid that undefined behavior by simply taking the "delay = 0" branch if the shift is too large.
I am not sure what the symptoms of an undefined value delay will be, but I suspect it could be more than a little annoying to debug.
--- block/blk-iocost.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
block/blk-iocost.c +4 -3
@@ -1347,7 +1347,7 @@ static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now) {struct ioc *ioc = iocg->ioc;struct blkcg_gq *blkg =iocg_to_blkg (iocg); -u64 tdelta, delay, new_delay; +u64 tdelta, delay, new_delay, shift;s64 vover, vover_pct;u32 hwa;
@@ -1362,8 +1362,9 @@ static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now)/* calculate the current delay in effect - 1/2 every second */ tdelta = now->now - iocg->delay_at; -if (iocg->delay) - delay = iocg->delay >>div64_u64 (tdelta,USEC_PER_SEC ); + shift =div64_u64 (tdelta,USEC_PER_SEC ); +if (iocg->delay && shift <BITS_PER_LONG ) + delay = iocg->delay >> shift;else delay =0 ;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 17/43 accel/ivpu: Remove d3hot_after_power_off WA
In reply to Sasha LevinFrom: Jacek Lawrynowicz <[email protected]>
[ Upstream commit e3caadf1f9dfc9d62b5ffc3bd73ebac0c8f26b3f ]
Always enter D3hot after entering D0i3 an all platforms. This minimizes power usage.
--- drivers/accel/ivpu/ivpu_drv.c | 20 ++++++++++---------- drivers/accel/ivpu/ivpu_drv.h | 3 +-- drivers/accel/ivpu/ivpu_hw_37xx.c | 4 +--- drivers/accel/ivpu/ivpu_pm.c | 7 ++----- 4 files changed, 14 insertions(+), 20 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +10 -10
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only /* -* Copyright (C) 2020-2023 Intel Corporation +* Copyright (C) 2020-2024 Intel Corporation */ #include <linux/firmware.h>
@@ -371,12 +371,15 @@ int ivpu_shutdown(struct ivpu_device *vdev) {int ret; -ivpu_prepare_for_reset (vdev); +/* Save PCI state before powering down as it sometimes gets corrupted if NPU hangs */ +pci_save_state (to_pci_dev (vdev->drm.dev)); ret =ivpu_hw_power_down (vdev);if (ret)ivpu_warn (vdev,"Failed to power down HW: %d\n" , ret); +pci_set_power_state (to_pci_dev (vdev->drm.dev), PCI_D3hot); +return ret; }
@@ -543,11 +546,11 @@ static int ivpu_dev_init(struct ivpu_device *vdev)/* Power up early so the rest of init code can access VPU registers */ ret =ivpu_hw_power_up (vdev);if (ret) - goto err_power_down; + goto err_shutdown; ret =ivpu_mmu_global_context_init (vdev);if (ret) - goto err_power_down; + goto err_shutdown; ret =ivpu_mmu_init (vdev);if (ret)
@@ -584,10 +587,8 @@ static int ivpu_dev_init(struct ivpu_device *vdev)ivpu_mmu_reserved_context_fini (vdev); err_mmu_gctx_fini:ivpu_mmu_global_context_fini (vdev); -err_power_down: -ivpu_hw_power_down (vdev); -if (IVPU_WA (d3hot_after_power_off)) -pci_set_power_state (to_pci_dev (vdev->drm.dev), PCI_D3hot); +err_shutdown: +ivpu_shutdown (vdev); err_xa_destroy:xa_destroy (&vdev->submitted_jobs_xa);xa_destroy (&vdev->context_xa);
@@ -610,9 +611,8 @@ static void ivpu_bo_unbind_all_user_contexts(struct ivpu_device *vdev)static void ivpu_dev_fini (struct ivpu_device *vdev) {ivpu_pm_disable (vdev); +ivpu_prepare_for_reset (vdev);ivpu_shutdown (vdev); -if (IVPU_WA (d3hot_after_power_off)) -pci_set_power_state (to_pci_dev (vdev->drm.dev), PCI_D3hot);ivpu_jobs_abort_all (vdev);ivpu_job_done_consumer_fini (vdev);
drivers/accel/ivpu/ivpu_drv.h +1 -2
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* Copyright (C) 2020-2023 Intel Corporation +* Copyright (C) 2020-2024 Intel Corporation */ #ifndef __IVPU_DRV_H__
@@ -87,7 +87,6 @@struct ivpu_wa_table {bool punit_disabled;bool clear_runtime_mem; -bool d3hot_after_power_off;bool interrupt_clear_with_0;bool disable_clock_relinquish;bool disable_d0i3_msg;
drivers/accel/ivpu/ivpu_hw_37xx.c +1 -3
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only /* -* Copyright (C) 2020-2023 Intel Corporation +* Copyright (C) 2020-2024 Intel Corporation */ #include "ivpu_drv.h"
@@ -75,7 +75,6 @@ static void ivpu_hw_wa_init(struct ivpu_device *vdev) { vdev->wa.punit_disabled = false; vdev->wa.clear_runtime_mem = false; - vdev->wa.d3hot_after_power_off = true;REGB_WR32 (VPU_37XX_BUTTRESS_INTERRUPT_STAT ,BUTTRESS_ALL_IRQ_MASK );if (REGB_RD32 (VPU_37XX_BUTTRESS_INTERRUPT_STAT ) ==BUTTRESS_ALL_IRQ_MASK ) {
@@ -86,7 +85,6 @@ static void ivpu_hw_wa_init(struct ivpu_device *vdev)IVPU_PRINT_WA (punit_disabled);IVPU_PRINT_WA (clear_runtime_mem); -IVPU_PRINT_WA (d3hot_after_power_off);IVPU_PRINT_WA (interrupt_clear_with_0); }
drivers/accel/ivpu/ivpu_pm.c +2 -5
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only /* -* Copyright (C) 2020-2023 Intel Corporation +* Copyright (C) 2020-2024 Intel Corporation */ #include <linux/highmem.h>
@@ -58,15 +58,12 @@ static int ivpu_suspend(struct ivpu_device *vdev) {int ret; -/* Save PCI state before powering down as it sometimes gets corrupted if NPU hangs */ -pci_save_state (to_pci_dev (vdev->drm.dev)); +ivpu_prepare_for_reset (vdev); ret =ivpu_shutdown (vdev);if (ret)ivpu_err (vdev,"Failed to shutdown VPU: %d\n" , ret); -pci_set_power_state (to_pci_dev (vdev->drm.dev), PCI_D3hot); -return ret; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 18/43 accel/ivpu: Improve clarity of MMU error messages
In reply to Sasha LevinFrom: "Wachowski, Karol" <[email protected]>
[ Upstream commit 3556f922612caf4c9b97cf7337626f8342b3dea3 ]
This patch improves readability and clarity of MMU error messages. Previously, the error strings were somewhat confusing and could lead to ambiguous interpretations, making it difficult to diagnose issues.
--- drivers/accel/ivpu/ivpu_mmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/accel/ivpu/ivpu_mmu.c +4 -4
@@ -278,7 +278,7 @@ static const char *ivpu_mmu_event_to_str(u32 cmd)case IVPU_MMU_EVT_F_VMS_FETCH :return "Fetch of VMS caused external abort" ;default : -return "Unknown CMDQ command" ; +return "Unknown event" ; } }
@@ -286,15 +286,15 @@ static const char *ivpu_mmu_cmdq_err_to_str(u32 err) {switch (err) {case IVPU_MMU_CERROR_NONE : -return "No CMDQ Error" ; +return "No error" ;case IVPU_MMU_CERROR_ILL :return "Illegal command" ;case IVPU_MMU_CERROR_ABT : -return "External abort on CMDQ read" ; +return "External abort on command queue read" ;case IVPU_MMU_CERROR_ATC_INV_SYNC :return "Sync failed to complete ATS invalidation" ;default : -return "Unknown CMDQ Error" ; +return "Unknown error" ; } }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 19/43 accel/ivpu: Fix missed error message after VPU rename
In reply to Sasha LevinFrom: Jacek Lawrynowicz <[email protected]>
[ Upstream commit 0d298e23292b7a5b58c5589fe33b96e95363214f ]
Change "VPU" to "NPU" in ivpu_suspend() so it matches all other error messages.
--- drivers/accel/ivpu/ivpu_pm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_pm.c +1 -1
@@ -62,7 +62,7 @@ static int ivpu_suspend(struct ivpu_device *vdev) ret =ivpu_shutdown (vdev);if (ret) -ivpu_err (vdev,"Failed to shutdown VPU: %d\n" , ret); +ivpu_err (vdev,"Failed to shutdown NPU: %d\n" , ret);return ret; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 20/43 platform/x86: acer-wmi: Add support for Acer PH18-71
In reply to Sasha LevinFrom: Bernhard Rosenkränzer <[email protected]>
[ Upstream commit b45d0d01da542be280d935d87b71465028cdcb1f ]
Add Acer Predator PH18-71 to acer_quirks with predator_v4 to support mode button and fan speed sensor.
--- drivers/platform/x86/acer-wmi.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/platform/x86/acer-wmi.c +9 -0
@@ -597,6 +597,15 @@ static const struct dmi_system_id acer_quirks[] __initconst = { }, .driver_data = &quirk_acer_predator_v4, }, + { + .callback = dmi_matched, + .ident = "Acer Predator PH18-71", + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Predator PH18-71"), + }, + .driver_data = &quirk_acer_predator_v4, + }, { .callback = set_force_caps, .ident = "Acer Aspire Switch 10E SW3-016",
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 21/43 gpu: host1x: Do not setup DMA for virtual devices
In reply to Sasha LevinFrom: Thierry Reding <[email protected]>
[ Upstream commit 8ab58f6841b19423231c5db3378691ec80c778f8 ]
The host1x devices are virtual compound devices and do not perform DMA accesses themselves, so they do not need to be set up for DMA.
Ideally we would also not need to set up DMA masks for the virtual devices, but we currently still need those for legacy support on old hardware.
--- drivers/gpu/host1x/bus.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/gpu/host1x/bus.c +0 -8
@@ -351,11 +351,6 @@ static int host1x_device_uevent(const struct device *dev,return 0 ; } -static int host1x_dma_configure (struct device *dev) -{ -return of_dma_configure (dev, dev->of_node, true); -} -static const struct dev_pm_ops host1x_device_pm_ops = { .suspend = pm_generic_suspend, .resume = pm_generic_resume,
@@ -369,7 +364,6 @@ struct bus_type host1x_bus_type = { .name = "host1x", .match = host1x_device_match, .uevent = host1x_device_uevent, - .dma_configure = host1x_dma_configure, .pm = &host1x_device_pm_ops, };
@@ -458,8 +452,6 @@ static int host1x_device_add(struct host1x *host1x, device->dev.bus = &host1x_bus_type; device->dev.parent = host1x->dev; -of_dma_configure (&device->dev, host1x->dev->of_node, true); - device->dev.dma_parms = &device->dma_parms;dma_set_max_seg_size (&device->dev,UINT_MAX );
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 22/43 MIPS: scall: Save thread_info.syscall unconditionally on entry
In reply to Sasha LevinFrom: Jiaxun Yang <[email protected]>
[ Upstream commit 4370b673ccf240bf7587b0cb8e6726a5ccaf1f17 ]
thread_info.syscall is used by syscall_get_nr to supply syscall nr over a thread stack frame.
Previously, thread_info.syscall is only saved at syscall_trace_enter when syscall tracing is enabled. However rest of the kernel code do expect syscall_get_nr to be available without syscall tracing. The previous design breaks collect_syscall.
Move saving process to syscall entry to fix it.
--- arch/mips/include/asm/ptrace.h | 2 +- arch/mips/kernel/asm-offsets.c | 1 + arch/mips/kernel/ptrace.c | 15 ++++++--------- arch/mips/kernel/scall32-o32.S | 23 +++++++++++++---------- arch/mips/kernel/scall64-n32.S | 3 ++- arch/mips/kernel/scall64-n64.S | 3 ++- arch/mips/kernel/scall64-o32.S | 33 +++++++++++++++++---------------- 7 files changed, 42 insertions(+), 38 deletions(-)
arch/mips/include/asm/ptrace.h +1 -1
@@ -159,7 +159,7 @@ extern unsigned long exception_ip(struct pt_regs *regs);#define exception_ip (regs) exception_ip(regs)#define profile_pc (regs) instruction_pointer(regs) -extern asmlinkage long syscall_trace_enter (struct pt_regs *regs,long syscall); +extern asmlinkage long syscall_trace_enter (struct pt_regs *regs); extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);extern void die (const char *,struct pt_regs *)__noreturn ;
arch/mips/kernel/asm-offsets.c +1 -0
@@ -101,6 +101,7 @@ void output_thread_info_defines(void)OFFSET (TI_CPU , thread_info, cpu);OFFSET (TI_PRE_COUNT , thread_info, preempt_count);OFFSET (TI_REGS , thread_info, regs); +OFFSET (TI_SYSCALL , thread_info, syscall);DEFINE (_THREAD_SIZE,THREAD_SIZE );DEFINE (_THREAD_MASK,THREAD_MASK );DEFINE (_IRQ_STACK_SIZE,IRQ_STACK_SIZE );
arch/mips/kernel/ptrace.c +6 -9
@@ -1317,16 +1317,13 @@ long arch_ptrace(struct task_struct *child, long request,* Notification of system call entry/exit * - triggered by current->work.syscall_trace */ -asmlinkage long syscall_trace_enter (struct pt_regs *regs,long syscall) +asmlinkage long syscall_trace_enter (struct pt_regs *regs) {user_exit (); -current_thread_info ()->syscall = syscall; -if (test_thread_flag (TIF_SYSCALL_TRACE )) {if (ptrace_report_syscall_entry (regs))return -1 ; - syscall =current_thread_info ()->syscall; }#ifdef CONFIG_SECCOMP
@@ -1335,7 +1332,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)struct seccomp_data sd;unsigned long args[6 ]; - sd.nr = syscall; + sd.nr =current_thread_info ()->syscall; sd.arch =syscall_get_arch (current);syscall_get_arguments (current, regs, args);for (i =0 ; i <6 ; i++)
@@ -1345,23 +1342,23 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall) ret =__secure_computing (&sd);if (ret ==-1 )return ret; - syscall = current_thread_info()->syscall; }#endif if (unlikely (test_thread_flag (TIF_SYSCALL_TRACEPOINT )))trace_sys_enter (regs, regs->regs[2 ]); -audit_syscall_entry (syscall, regs->regs[4 ], regs->regs[5 ], +audit_syscall_entry (current_thread_info ()->syscall, + regs->regs[4 ], regs->regs[5 ], regs->regs[6 ], regs->regs[7 ]);/* * Negative syscall numbers are mistaken for rejected syscalls, but * won't have had the return value set appropriately, so we do so now. */ -if (syscall <0 ) +if (current_thread_info ()->syscall <0 )syscall_set_return_value (current, regs, -ENOSYS ,0 ); -return syscall; +return current_thread_info ()->syscall; }/*
arch/mips/kernel/scall32-o32.S +13 -10
@@ -77,6 +77,18 @@ loads_done: PTR_WD load_a7, bad_stack_a7 .previous + /* + * syscall number is in v0 unless we called syscall(__NR_###) + * where the real syscall number is in a0 + */ + subu t2, v0, __NR_O32_Linux + bnez t2, 1f /* __NR_syscall at offset 0 */ + LONG_S a0, TI_SYSCALL($28) # Save a0 as syscall number + b 2f +1: + LONG_S v0, TI_SYSCALL($28) # Save v0 as syscall number +2: + lw t0, TI_FLAGS($28) # syscall tracing enabled? li t1, _TIF_WORK_SYSCALL_ENTRY and t0, t1
@@ -114,16 +126,7 @@ syscall_trace_entry: SAVE_STATIC move a0, sp - /* - * syscall number is in v0 unless we called syscall(__NR_###) - * where the real syscall number is in a0 - */ - move a1, v0 - subu t2, v0, __NR_O32_Linux - bnez t2, 1f /* __NR_syscall at offset 0 */ - lw a1, PT_R4(sp) - -1: jal syscall_trace_enter + jal syscall_trace_enter bltz v0, 1f # seccomp failed? Skip syscall
arch/mips/kernel/scall64-n32.S +2 -1
@@ -44,6 +44,8 @@ NESTED(handle_sysn32, PT_SIZE, sp) sd a3, PT_R26(sp) # save a3 for syscall restarting + LONG_S v0, TI_SYSCALL($28) # Store syscall number + li t1, _TIF_WORK_SYSCALL_ENTRY LONG_L t0, TI_FLAGS($28) # syscall tracing enabled? and t0, t1, t0
@@ -72,7 +74,6 @@ syscall_common: n32_syscall_trace_entry: SAVE_STATIC move a0, sp - move a1, v0 jal syscall_trace_enter bltz v0, 1f # seccomp failed? Skip syscall
arch/mips/kernel/scall64-n64.S +2 -1
@@ -46,6 +46,8 @@ NESTED(handle_sys64, PT_SIZE, sp) sd a3, PT_R26(sp) # save a3 for syscall restarting + LONG_S v0, TI_SYSCALL($28) # Store syscall number + li t1, _TIF_WORK_SYSCALL_ENTRY LONG_L t0, TI_FLAGS($28) # syscall tracing enabled? and t0, t1, t0
@@ -82,7 +84,6 @@ n64_syscall_exit: syscall_trace_entry: SAVE_STATIC move a0, sp - move a1, v0 jal syscall_trace_enter bltz v0, 1f # seccomp failed? Skip syscall
arch/mips/kernel/scall64-o32.S +17 -16
@@ -79,6 +79,22 @@ loads_done: PTR_WD load_a7, bad_stack_a7 .previous + /* + * absolute syscall number is in v0 unless we called syscall(__NR_###) + * where the real syscall number is in a0 + * note: NR_syscall is the first O32 syscall but the macro is + * only defined when compiling with -mabi=32 (CONFIG_32BIT) + * therefore __NR_O32_Linux is used (4000) + */ + + subu t2, v0, __NR_O32_Linux + bnez t2, 1f /* __NR_syscall at offset 0 */ + LONG_S a0, TI_SYSCALL($28) # Save a0 as syscall number + b 2f +1: + LONG_S v0, TI_SYSCALL($28) # Save v0 as syscall number +2: + li t1, _TIF_WORK_SYSCALL_ENTRY LONG_L t0, TI_FLAGS($28) # syscall tracing enabled? and t0, t1, t0
@@ -113,22 +129,7 @@ trace_a_syscall: sd a7, PT_R11(sp) # For indirect syscalls move a0, sp - /* - * absolute syscall number is in v0 unless we called syscall(__NR_###) - * where the real syscall number is in a0 - * note: NR_syscall is the first O32 syscall but the macro is - * only defined when compiling with -mabi=32 (CONFIG_32BIT) - * therefore __NR_O32_Linux is used (4000) - */ - .set push - .set reorder - subu t1, v0, __NR_O32_Linux - move a1, v0 - bnez t1, 1f /* __NR_syscall at offset 0 */ - ld a1, PT_R4(sp) /* Arg1 for __NR_syscall case */ - .set pop - -1: jal syscall_trace_enter + jal syscall_trace_enter bltz v0, 1f # seccomp failed? Skip syscall
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 23/43 tools/power/turbostat: Fix uncore frequency file string
In reply to Sasha LevinFrom: Justin Ernst <[email protected]>
[ Upstream commit 60add818ab2543b7e4f2bfeaacf2504743c1eb50 ]
Running turbostat on a 16 socket HPE Scale-up Compute 3200 (SapphireRapids) fails with:
turbostat: /sys/devices/system/cpu/intel_uncore_frequency/package_010_die_00/current_freq_khz: open failed: No such file or directory
We observe the sysfs uncore frequency directories named:
...
package_09_die_00/
package_10_die_00/
package_11_die_00/
...
package_15_die_00/
The culprit is an incorrect sprintf format string "package_0%d_die_0%d" used with each instance of reading uncore frequency files. uncore-frequency-common.c creates the sysfs directory with the format "package_%02d_die_%02d". Once the package value reaches double digits, the formats diverge.
Change each instance of "package_0%d_die_0%d" to "package_%02d_die_%02d".
[lenb: deleted the probe part of this patch, as it was already fixed]
--- tools/power/x86/turbostat/turbostat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +1 -1
@@ -2612,7 +2612,7 @@ unsigned long long get_uncore_mhz(int package, int die) {char path[128 ]; -sprintf (path,"/sys/devices/system/cpu/intel_uncore_frequency/package_0%d_die_0%d/current_freq_khz" , package, +sprintf (path,"/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/current_freq_khz" , package, die);return (snapshot_sysfs_counter (path) /1000 );
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 24/43 net: add copy_safe_from_sockptr() helper
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit 6309863b31dd80317cd7d6824820b44e254e2a9c ]
copy_from_sockptr() helper is unsafe, unless callers did the prior check against user provided optlen.
Too many callers get this wrong, lets add a helper to fix them and avoid future copy/paste bugs.
Instead of :
if (optlen < sizeof(opt)) {
err = -EINVAL;
break;
}
if (copy_from_sockptr(&opt, optval, sizeof(opt)) {
err = -EFAULT;
break;
}Use :
err = copy_safe_from_sockptr(&opt, sizeof(opt),
optval, optlen);
if (err)
break;--- include/linux/sockptr.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
include/linux/sockptr.h +25 -0
@@ -50,11 +50,36 @@ static inline int copy_from_sockptr_offset(void *dst, sockptr_t src,return 0 ; } +/* Deprecated. +* This is unsafe, unless caller checked user provided optlen. +* Prefer copy_safe_from_sockptr() instead. +*/ static inline int copy_from_sockptr (void *dst,sockptr_t src,size_t size) {return copy_from_sockptr_offset (dst, src,0 , size); } +/** +* copy_safe_from_sockptr: copy a struct from sockptr +* @dst: Destination address, in kernel space. This buffer must be @ksize +* bytes long. +* @ksize: Size of @dst struct. +* @optval: Source address. (in user or kernel space) +* @optlen: Size of @optval data. +* +* Returns: +* * -EINVAL: @optlen < @ksize +* * -EFAULT: access to userspace failed. +* * 0 : @ksize bytes were copied +*/ +static inline int copy_safe_from_sockptr (void *dst,size_t ksize, +sockptr_t optval,unsigned int optlen) +{ +if (optlen < ksize) +return -EINVAL ; +return copy_from_sockptr (dst, optval, ksize); +} +static inline int copy_struct_from_sockptr (void *dst,size_t ksize,sockptr_t src,size_t usize) {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 25/43 nfc: llcp: fix nfc_llcp_setsockopt() unsafe copies
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit 7a87441c9651ba37842f4809224aca13a554a26f ]
syzbot reported unsafe calls to copy_from_sockptr() [1]
Use copy_safe_from_sockptr() instead.
[1]
BUG: KASAN: slab-out-of-bounds in copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] BUG: KASAN: slab-out-of-bounds in copy_from_sockptr include/linux/sockptr.h:55 [inline] BUG: KASAN: slab-out-of-bounds in nfc_llcp_setsockopt+0x6c2/0x850 net/nfc/llcp_sock.c:255 Read of size 4 at addr ffff88801caa1ec3 by task syz-executor459/5078 CPU: 0 PID: 5078 Comm: syz-executor459 Not tainted 6.8.0-syzkaller-08951-gfe46a7dd189e #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114 print_address_description mm/kasan/report.c:377 [inline] print_report+0x169/0x550 mm/kasan/report.c:488 kasan_report+0x143/0x180 mm/kasan/report.c:601 copy_from_sockptr_offset include/linux/sockptr.h:49 [inline] copy_from_sockptr include/linux/sockptr.h:55 [inline] nfc_llcp_setsockopt+0x6c2/0x850 net/nfc/llcp_sock.c:255 do_sock_setsockopt+0x3b1/0x720 net/socket.c:2311 __sys_setsockopt+0x1ae/0x250 net/socket.c:2334 __do_sys_setsockopt net/socket.c:2343 [inline] __se_sys_setsockopt net/socket.c:2340 [inline] __x64_sys_setsockopt+0xb5/0xd0 net/socket.c:2340 do_syscall_64+0xfd/0x240 entry_SYSCALL_64_after_hwframe+0x6d/0x75 RIP: 0033:0x7f7fac07fd89 Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 91 18 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fff660eb788 EFLAGS: 00000246 ORIG_RAX: 0000000000000036 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f7fac07fd89 RDX: 0000000000000000 RSI: 0000000000000118 RDI: 0000000000000004 RBP: 0000000000000000 R08: 0000000000000002 R09: 0000000000000000 R10: 0000000020000a80 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
--- net/nfc/llcp_sock.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/nfc/llcp_sock.c +6 -6
@@ -252,10 +252,10 @@ static int nfc_llcp_setsockopt(struct socket *sock, int level, int optname,break ; } -if (copy_from_sockptr (&opt, optval,sizeof (u32))) { - err = -EFAULT ; + err =copy_safe_from_sockptr (&opt,sizeof (opt), + optval, optlen); +if (err)break ; - }if (opt >LLCP_MAX_RW ) { err = -EINVAL ;
@@ -274,10 +274,10 @@ static int nfc_llcp_setsockopt(struct socket *sock, int level, int optname,break ; } -if (copy_from_sockptr (&opt, optval,sizeof (u32))) { - err = -EFAULT ; + err =copy_safe_from_sockptr (&opt,sizeof (opt), + optval, optlen); +if (err)break ; - }if (opt >LLCP_MAX_MIUX ) { err = -EINVAL ;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 26/43 drm/amdgpu: Refine IB schedule error logging
In reply to Sasha LevinFrom: Lijo Lazar <[email protected]>
[ Upstream commit 4b18a91faf1752f9bd69a4ed3aed2c8f6e5b0528 ]
Downgrade to debug information when IBs are skipped. Also, use dev_* to identify the device.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5 -2
@@ -300,12 +300,15 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)dma_fence_set_error (finished, -ECANCELED );if (finished->error <0 ) { -DRM_INFO ("Skip scheduling IBs!\n" ); +dev_dbg (adev->dev,"Skip scheduling IBs in ring(%s)" , + ring->name); }else { r =amdgpu_ib_schedule (ring, job->num_ibs, job->ibs, job, &fence);if (r) -DRM_ERROR ("Error scheduling IBs (%d)\n" , r); +dev_err (adev->dev, +"Error scheduling IBs (%d) in ring(%s)" , r, + ring->name); } job->job_run_counter++;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 27/43 drm/amd/display: add DCN 351 version for microcode load
In reply to Sasha LevinFrom: Li Ma <[email protected]>
[ Upstream commit d4396924c3d44f34d0643f650e70892e07f3677f ]
There is a new DCN veriosn 3.5.1 need to load
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -0
@@ -147,6 +147,9 @@ MODULE_FIRMWARE(FIRMWARE_NAVI12_DMCU);#define FIRMWARE_DCN_35_DMUB "amdgpu/dcn_3_5_dmcub.bin"MODULE_FIRMWARE (FIRMWARE_DCN_35_DMUB ); +#define FIRMWARE_DCN_351_DMUB "amdgpu/dcn_3_5_1_dmcub.bin" +MODULE_FIRMWARE (FIRMWARE_DCN_351_DMUB ); +/* Number of bytes in PSP header for firmware. */ #define PSP_HEADER_BYTES 0x100
@@ -4776,6 +4779,9 @@ static int dm_init_microcode(struct amdgpu_device *adev)case IP_VERSION (3 ,5 ,0 ): fw_name_dmub =FIRMWARE_DCN_35_DMUB ;break ; +case IP_VERSION (3 ,5 ,1 ): + fw_name_dmub =FIRMWARE_DCN_351_DMUB ; +break ;default :/* ASIC doesn't support DMUB. */ return 0 ;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 28/43 drm/amdgpu: add smu 14.0.1 discovery support
In reply to Sasha LevinFrom: Yifan Zhang <[email protected]>
[ Upstream commit 533eefb9be76c3b23d220ee18edfda8eb56cefff ]
This patch to add smu 14.0.1 support
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -0
@@ -1867,6 +1867,7 @@ static int amdgpu_discovery_set_smu_ip_blocks(struct amdgpu_device *adev)amdgpu_device_ip_block_add (adev, &smu_v13_0_ip_block);break ;case IP_VERSION (14 ,0 ,0 ): +case IP_VERSION (14 ,0 ,1 ):amdgpu_device_ip_block_add (adev, &smu_v14_0_ip_block);break ;default :
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 29/43 drm/amdgpu: implement IRQ_STATE_ENABLE for SDMA v4.4.2
In reply to Sasha LevinFrom: Tao Zhou <[email protected]>
[ Upstream commit f886b49feaae30acd599e37d4284836024b0f3ed ]
SDMA_CNTL is not set in some cases, driver configures it by itself.
v2: simplify code
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +3 -13
@@ -1600,19 +1600,9 @@ static int sdma_v4_4_2_set_ecc_irq_state(struct amdgpu_device *adev,u32 sdma_cntl; sdma_cntl =RREG32_SDMA (type, regSDMA_CNTL); -switch (state) { -case AMDGPU_IRQ_STATE_DISABLE : - sdma_cntl =REG_SET_FIELD (sdma_cntl,SDMA_CNTL , -DRAM_ECC_INT_ENABLE ,0 ); -WREG32_SDMA (type, regSDMA_CNTL, sdma_cntl); -break ; -/* sdma ecc interrupt is enabled by default -* driver doesn't need to do anything to -* enable the interrupt */ -case AMDGPU_IRQ_STATE_ENABLE : -default : -break ; - } + sdma_cntl =REG_SET_FIELD (sdma_cntl,SDMA_CNTL ,DRAM_ECC_INT_ENABLE , + state ==AMDGPU_IRQ_STATE_ENABLE ?1 :0 ); +WREG32_SDMA (type, regSDMA_CNTL, sdma_cntl);return 0 ; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 30/43 drm/amd/display: Skip on writeback when it's not applicable
In reply to Sasha LevinFrom: Alex Hung <[email protected]>
[ Upstream commit ecedd99a9369fb5cde601ae9abd58bca2739f1ae ]
[WHY]
dynamic memory safety error detector (KASAN) catches and generates error messages "BUG: KASAN: slab-out-of-bounds" as writeback connector does not support certain features which are not initialized.
[HOW]
Skip them when connector type is DRM_MODE_CONNECTOR_WRITEBACK.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -1
@@ -3028,6 +3028,10 @@ static int dm_resume(void *handle)/* Do mst topology probing after resuming cached state*/ drm_connector_list_iter_begin (ddev, &iter);drm_for_each_connector_iter (connector, &iter) { + +if (connector->connector_type ==DRM_MODE_CONNECTOR_WRITEBACK ) +continue ; + aconnector =to_amdgpu_dm_connector (connector);if (aconnector->dc_link->type != dc_connection_mst_branch || aconnector->mst_root)
@@ -5879,6 +5883,9 @@ get_highest_refresh_rate_mode(struct amdgpu_dm_connector *aconnector, &aconnector->base.probed_modes : &aconnector->base.modes; +if (aconnector->base.connector_type ==DRM_MODE_CONNECTOR_WRITEBACK ) +return NULL ; +if (aconnector->freesync_vid_base.clock !=0 )return &aconnector->freesync_vid_base;
@@ -8633,10 +8640,10 @@ static void amdgpu_dm_commit_audio(struct drm_device *dev,if (!drm_atomic_crtc_needs_modeset (new_crtc_state))continue ; +notify:if (connector->connector_type ==DRM_MODE_CONNECTOR_WRITEBACK )continue ; -notify: aconnector =to_amdgpu_dm_connector (connector);mutex_lock (&adev->dm.audio_lock);
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 31/43 drm/amd/pm: fix the high voltage issue after unload
In reply to Sasha LevinFrom: Kenneth Feng <[email protected]>
[ Upstream commit 3818708e9c9712e2ba4006bc23502ee7b031bd3f ]
fix the high voltage issue after unload on smu 13.0.10
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 26 ++++++++++-------- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 27 +++++++++++++++++-- drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h | 1 + .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 8 +++++- 4 files changed, 48 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -11
@@ -4120,18 +4120,22 @@ int amdgpu_device_init(struct amdgpu_device *adev, adev->ip_blocks[i].status.hw = true; } } + }else if (amdgpu_ip_version (adev,MP1_HWIP ,0 ) ==IP_VERSION (13 ,0 ,10 ) && + !amdgpu_device_has_display_hardware (adev)) { + r =psp_gpu_reset (adev); }else { - tmp = amdgpu_reset_method; -/* It should do a default reset when loading or reloading the driver, -* regardless of the module parameter reset_method. -*/ - amdgpu_reset_method =AMD_RESET_METHOD_NONE ; - r =amdgpu_asic_reset (adev); - amdgpu_reset_method = tmp; -if (r) { -dev_err (adev->dev,"asic reset on init failed\n" ); - goto failed; - } + tmp = amdgpu_reset_method; +/* It should do a default reset when loading or reloading the driver, +* regardless of the module parameter reset_method. +*/ + amdgpu_reset_method =AMD_RESET_METHOD_NONE ; + r =amdgpu_asic_reset (adev); + amdgpu_reset_method = tmp; + } + +if (r) { +dev_err (adev->dev,"asic reset on init failed\n" ); + goto failed; } }
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +25 -2
@@ -734,7 +734,7 @@ static int smu_early_init(void *handle) smu->adev = adev; smu->pm_enabled = !!amdgpu_dpm; smu->is_apu = false; - smu->smu_baco.state =SMU_BACO_STATE_EXIT ; + smu->smu_baco.state =SMU_BACO_STATE_NONE ; smu->smu_baco.platform_support = false; smu->user_dpm_profile.fan_mode =-1 ;
@@ -1954,10 +1954,25 @@ static int smu_smc_hw_cleanup(struct smu_context *smu)return 0 ; } +static int smu_reset_mp1_state (struct smu_context *smu) +{ +struct amdgpu_device *adev = smu->adev; +int ret =0 ; + +if ((!adev->in_runpm) && (!adev->in_suspend) && + (!amdgpu_in_reset (adev)) &&amdgpu_ip_version (adev,MP1_HWIP ,0 ) == +IP_VERSION (13 ,0 ,10 ) && + !amdgpu_device_has_display_hardware (adev)) + ret =smu_set_mp1_state (smu,PP_MP1_STATE_UNLOAD ); + +return ret; +} +static int smu_hw_fini (void *handle) {struct amdgpu_device *adev = (struct amdgpu_device *)handle;struct smu_context *smu = adev->powerplay.pp_handle; +int ret;if (amdgpu_sriov_vf (adev) && !amdgpu_sriov_is_pp_one_vf (adev))return 0 ;
@@ -1975,7 +1990,15 @@ static int smu_hw_fini(void *handle) adev->pm.dpm_enabled = false; -return smu_smc_hw_cleanup (smu); + ret =smu_smc_hw_cleanup (smu); +if (ret) +return ret; + + ret =smu_reset_mp1_state (smu); +if (ret) +return ret; + +return 0 ; }static void smu_late_fini (void *handle)
drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h +1 -0
@@ -424,6 +424,7 @@ enum smu_reset_mode {enum smu_baco_state {SMU_BACO_STATE_ENTER =0 ,SMU_BACO_STATE_EXIT , +SMU_BACO_STATE_NONE , };struct smu_baco_context {
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +7 -1
@@ -2751,7 +2751,13 @@ static int smu_v13_0_0_set_mp1_state(struct smu_context *smu,switch (mp1_state) {case PP_MP1_STATE_UNLOAD : - ret =smu_cmn_set_mp1_state (smu, mp1_state); + ret =smu_cmn_send_smc_msg_with_param (smu, + SMU_MSG_PrepareMp1ForUnload, +0x55 ,NULL ); + +if (!ret && smu->smu_baco.state ==SMU_BACO_STATE_EXIT ) + ret =smu_v13_0_disable_pmfw_state (smu); +break ;default :/* Ignore others */
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 32/43 drm/amdgpu: Fix VCN allocation in CPX partition
In reply to Sasha LevinFrom: Lijo Lazar <[email protected]>
[ Upstream commit f7e232de51bb1b45646e5b7dc4ebcf13510f2630 ]
VCN need not be shared in CPX mode always for all GFX 9.4.3 SOC SKUs. In certain configs, VCN instance can be exclusively allocated to a partition even under CPX mode.
--- drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +11 -4
@@ -62,6 +62,11 @@ void aqua_vanjaram_doorbell_index_init(struct amdgpu_device *adev) adev->doorbell_index.max_assignment =AMDGPU_DOORBELL_LAYOUT1_MAX_ASSIGNMENT <<1 ; } +static bool aqua_vanjaram_xcp_vcn_shared (struct amdgpu_device *adev) +{ +return (adev->xcp_mgr->num_xcps > adev->vcn.num_vcn_inst); +} +static void aqua_vanjaram_set_xcp_id (struct amdgpu_device *adev,uint32_t inst_idx,struct amdgpu_ring *ring) {
@@ -87,7 +92,7 @@ static void aqua_vanjaram_set_xcp_id(struct amdgpu_device *adev,case AMDGPU_RING_TYPE_VCN_ENC :case AMDGPU_RING_TYPE_VCN_JPEG : ip_blk =AMDGPU_XCP_VCN ; -if (adev->xcp_mgr->mode ==AMDGPU_CPX_PARTITION_MODE ) +if (aqua_vanjaram_xcp_vcn_shared (adev)) inst_mask =1 << (inst_idx *2 );break ;default :
@@ -140,10 +145,12 @@ static int aqua_vanjaram_xcp_sched_list_update(aqua_vanjaram_xcp_gpu_sched_update (adev, ring, ring->xcp_id); -/* VCN is shared by two partitions under CPX MODE */ +/* VCN may be shared by two partitions under CPX MODE in certain +* configs. +*/ if ((ring->funcs->type ==AMDGPU_RING_TYPE_VCN_ENC || - ring->funcs->type ==AMDGPU_RING_TYPE_VCN_JPEG ) && - adev->xcp_mgr->mode ==AMDGPU_CPX_PARTITION_MODE ) + ring->funcs->type ==AMDGPU_RING_TYPE_VCN_JPEG ) && +aqua_vanjaram_xcp_vcn_shared (adev))aqua_vanjaram_xcp_gpu_sched_update (adev, ring, ring->xcp_id +1 ); }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 33/43 amd/amdkfd: sync all devices to wait all processes being evicted
In reply to Sasha LevinFrom: Zhigang Luo <[email protected]>
[ Upstream commit d06af584be5a769d124b7302b32a033e9559761d ]
If there are more than one device doing reset in parallel, the first device will call kfd_suspend_all_processes() to evict all processes on all devices, this call takes time to finish. other device will start reset and recover without waiting. if the process has not been evicted before doing recover, it will be restored, then caused page fault.
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +6 -11
@@ -944,7 +944,6 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm) {struct kfd_node *node;int i; -int count;if (!kfd->init_complete)return ;
@@ -952,12 +951,10 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)/* for runtime suspend, skip locking kfd */ if (!run_pm) {mutex_lock (&kfd_processes_mutex); - count = ++kfd_locked; -mutex_unlock (&kfd_processes_mutex); -/* For first KFD device suspend all the KFD processes */ -if (count ==1 ) +if (++kfd_locked ==1 )kfd_suspend_all_processes (); +mutex_unlock (&kfd_processes_mutex); }for (i =0 ; i < kfd->num_nodes; i++) {
@@ -968,7 +965,7 @@ void kgd2kfd_suspend(struct kfd_dev *kfd, bool run_pm)int kgd2kfd_resume (struct kfd_dev *kfd,bool run_pm) { -int ret, count, i; +int ret, i;if (!kfd->init_complete)return 0 ;
@@ -982,12 +979,10 @@ int kgd2kfd_resume(struct kfd_dev *kfd, bool run_pm)/* for runtime resume, skip unlocking kfd */ if (!run_pm) {mutex_lock (&kfd_processes_mutex); - count = --kfd_locked; -mutex_unlock (&kfd_processes_mutex); - -WARN_ONCE (count <0 ,"KFD suspend / resume ref. error" ); -if (count ==0 ) +if (--kfd_locked ==0 ) ret =kfd_resume_all_processes (); +WARN_ONCE (kfd_locked <0 ,"KFD suspend / resume ref. error" ); +mutex_unlock (&kfd_processes_mutex); }return ret;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 34/43 selftests: timers: Fix valid-adjtimex signed left-shift undefined behavior
In reply to Sasha LevinFrom: John Stultz <[email protected]>
[ Upstream commit 076361362122a6d8a4c45f172ced5576b2d4a50d ]
The struct adjtimex freq field takes a signed value who's units are in shifted (<<16) parts-per-million.
Unfortunately for negative adjustments, the straightforward use of:
freq = ppm << 16 trips undefined behavior warnings with clang:
valid-adjtimex.c:66:6: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
-499<<16,
~~~~^
valid-adjtimex.c:67:6: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
-450<<16,
~~~~^..
Fix it by using a multiply by (1 << 16) instead of shifting negative values in the valid-adjtimex test case. Align the values for better readability.
--- .../testing/selftests/timers/valid-adjtimex.c | 73 +++++++++---------- 1 file changed, 36 insertions(+), 37 deletions(-)
tools/testing/selftests/timers/valid-adjtimex.c +36 -37
@@ -21,9 +21,6 @@* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ - - -#include <stdio.h> #include <stdlib.h> #include <time.h>
@@ -62,45 +59,47 @@ int clear_time_state(void)#define NUM_FREQ_OUTOFRANGE 4#define NUM_FREQ_INVALID 2 +#define SHIFTED_PPM (1 << 16) +long valid_freq[NUM_FREQ_VALID ] = { --499 <<16 , --450 <<16 , --400 <<16 , --350 <<16 , --300 <<16 , --250 <<16 , --200 <<16 , --150 <<16 , --100 <<16 , --75 <<16 , --50 <<16 , --25 <<16 , --10 <<16 , --5 <<16 , --1 <<16 , +-499 *SHIFTED_PPM , +-450 *SHIFTED_PPM , +-400 *SHIFTED_PPM , +-350 *SHIFTED_PPM , +-300 *SHIFTED_PPM , +-250 *SHIFTED_PPM , +-200 *SHIFTED_PPM , +-150 *SHIFTED_PPM , +-100 *SHIFTED_PPM , +-75 *SHIFTED_PPM , +-50 *SHIFTED_PPM , +-25 *SHIFTED_PPM , +-10 *SHIFTED_PPM , +-5 *SHIFTED_PPM , +-1 *SHIFTED_PPM ,-1000 , -1 <<16 , -5 <<16 , -10 <<16 , -25 <<16 , -50 <<16 , -75 <<16 , -100 <<16 , -150 <<16 , -200 <<16 , -250 <<16 , -300 <<16 , -350 <<16 , -400 <<16 , -450 <<16 , -499 <<16 , +1 *SHIFTED_PPM , +5 *SHIFTED_PPM , +10 *SHIFTED_PPM , +25 *SHIFTED_PPM , +50 *SHIFTED_PPM , +75 *SHIFTED_PPM , +100 *SHIFTED_PPM , +150 *SHIFTED_PPM , +200 *SHIFTED_PPM , +250 *SHIFTED_PPM , +300 *SHIFTED_PPM , +350 *SHIFTED_PPM , +400 *SHIFTED_PPM , +450 *SHIFTED_PPM , +499 *SHIFTED_PPM , };long outofrange_freq[NUM_FREQ_OUTOFRANGE ] = { --1000 <<16 , --550 <<16 , -550 <<16 , -1000 <<16 , +-1000 *SHIFTED_PPM , +-550 *SHIFTED_PPM , +550 *SHIFTED_PPM , +1000 *SHIFTED_PPM , };#define LONG_MAX (~0UL>>1)
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 35/43 Drivers: hv: vmbus: Leak pages if set_memory_encrypted() fails
In reply to Sasha LevinFrom: Rick Edgecombe <[email protected]>
[ Upstream commit 03f5a999adba062456c8c818a683beb1b498983a ]
In CoCo VMs it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues.
VMBus code could free decrypted pages if set_memory_encrypted()/decrypted() fails. Leak the pages if this happens.
Message-ID: <[email protected]>
--- drivers/hv/connection.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/hv/connection.c +22 -7
@@ -237,8 +237,17 @@ int vmbus_connect(void) vmbus_connection.monitor_pages[0], 1); ret |=set_memory_decrypted ((unsigned long ) vmbus_connection.monitor_pages[1 ],1 ); -if (ret) +if (ret) { +/* +* If set_memory_decrypted() fails, the encryption state +* of the memory is unknown. So leak the memory instead +* of risking returning decrypted memory to the free list. +* For simplicity, always handle both pages the same. +*/ + vmbus_connection.monitor_pages[0 ] =NULL ; + vmbus_connection.monitor_pages[1 ] =NULL ; goto cleanup; + }/* * Set_memory_decrypted() will change the memory contents if
@@ -337,13 +346,19 @@ void vmbus_disconnect(void) vmbus_connection.int_page =NULL ; } -set_memory_encrypted ((unsigned long )vmbus_connection.monitor_pages[0 ],1 ); -set_memory_encrypted ((unsigned long )vmbus_connection.monitor_pages[1 ],1 ); +if (vmbus_connection.monitor_pages[0 ]) { +if (!set_memory_encrypted ( + (unsigned long )vmbus_connection.monitor_pages[0 ],1 )) +hv_free_hyperv_page (vmbus_connection.monitor_pages[0 ]); + vmbus_connection.monitor_pages[0 ] =NULL ; + } -hv_free_hyperv_page (vmbus_connection.monitor_pages[0 ]); -hv_free_hyperv_page (vmbus_connection.monitor_pages[1 ]); - vmbus_connection.monitor_pages[0 ] =NULL ; - vmbus_connection.monitor_pages[1 ] =NULL ; +if (vmbus_connection.monitor_pages[1 ]) { +if (!set_memory_encrypted ( + (unsigned long )vmbus_connection.monitor_pages[1 ],1 )) +hv_free_hyperv_page (vmbus_connection.monitor_pages[1 ]); + vmbus_connection.monitor_pages[1 ] =NULL ; + } }/*
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 36/43 Drivers: hv: vmbus: Track decrypted status in vmbus_gpadl
In reply to Sasha LevinFrom: Rick Edgecombe <[email protected]>
[ Upstream commit 211f514ebf1ef5de37b1cf6df9d28a56cfd242ca ]
In CoCo VMs it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues.
In order to make sure callers of vmbus_establish_gpadl() and vmbus_teardown_gpadl() don't return decrypted/shared pages to allocators, add a field in struct vmbus_gpadl to keep track of the decryption status of the buffers. This will allow the callers to know if they should free or leak the pages.
Message-ID: <[email protected]>
--- drivers/hv/channel.c | 25 +++++++++++++++++++++---- include/linux/hyperv.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-)
drivers/hv/channel.c +21 -4
@@ -436,9 +436,18 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel, (atomic_inc_return (&vmbus_connection.next_gpadl_handle) -1 ); ret =create_gpadl_header (type, kbuffer, size, send_offset, &msginfo); -if (ret) +if (ret) { + gpadl->decrypted = false;return ret; + } +/* +* Set the "decrypted" flag to true for the set_memory_decrypted() +* success case. In the failure case, the encryption state of the +* memory is unknown. Leave "decrypted" as true to ensure the +* memory will be leaked instead of going back on the free list. +*/ + gpadl->decrypted = true; ret =set_memory_decrypted ((unsigned long )kbuffer,PFN_UP (size));if (ret) {
@@ -527,9 +536,15 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,kfree (msginfo); -if (ret) -set_memory_encrypted ((unsigned long )kbuffer, -PFN_UP (size)); +if (ret) { +/* +* If set_memory_encrypted() fails, the decrypted flag is +* left as true so the memory is leaked instead of being +* put back on the free list. +*/ +if (!set_memory_encrypted ((unsigned long )kbuffer,PFN_UP (size))) + gpadl->decrypted = false; + }return ret; }
@@ -850,6 +865,8 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, struct vmbus_gpadl *gpadif (ret)pr_warn ("Fail to set mem host visibility in GPADL teardown %d.\n" , ret); + gpadl->decrypted = ret; +return ret; }EXPORT_SYMBOL_GPL (vmbus_teardown_gpadl);
include/linux/hyperv.h +1 -0
@@ -832,6 +832,7 @@ struct vmbus_gpadl {u32 gpadl_handle;u32 size;void *buffer; +bool decrypted; };struct vmbus_channel {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 37/43 hv_netvsc: Don't free decrypted memory
In reply to Sasha LevinFrom: Rick Edgecombe <[email protected]>
[ Upstream commit bbf9ac34677b57506a13682b31a2a718934c0e31 ]
In CoCo VMs it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues.
The netvsc driver could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the gpadl to decide whether to free the memory.
Message-ID: <[email protected]>
--- drivers/net/hyperv/netvsc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/hyperv/netvsc.c +5 -2
@@ -154,8 +154,11 @@ static void free_netvsc_device(struct rcu_head *head)int i;kfree (nvdev->extension); -vfree (nvdev->recv_buf); -vfree (nvdev->send_buf); + +if (!nvdev->recv_buf_gpadl_handle.decrypted) +vfree (nvdev->recv_buf); +if (!nvdev->send_buf_gpadl_handle.decrypted) +vfree (nvdev->send_buf);bitmap_free (nvdev->send_section_map);for (i =0 ; i <VRSS_CHANNEL_MAX ; i++) {
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 38/43 uio_hv_generic: Don't free decrypted memory
In reply to Sasha LevinFrom: Rick Edgecombe <[email protected]>
[ Upstream commit 3d788b2fbe6a1a1a9e3db09742b90809d51638b7 ]
In CoCo VMs it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues.
The VMBus device UIO driver could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the gpadl to decide whether to free the memory.
Message-ID: <[email protected]>
--- drivers/uio/uio_hv_generic.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/uio/uio_hv_generic.c +8 -4
@@ -181,12 +181,14 @@ hv_uio_cleanup(struct hv_device *dev, struct hv_uio_private_data *pdata) {if (pdata->send_gpadl.gpadl_handle) {vmbus_teardown_gpadl (dev->channel, &pdata->send_gpadl); -vfree (pdata->send_buf); +if (!pdata->send_gpadl.decrypted) +vfree (pdata->send_buf); }if (pdata->recv_gpadl.gpadl_handle) {vmbus_teardown_gpadl (dev->channel, &pdata->recv_gpadl); -vfree (pdata->recv_buf); +if (!pdata->recv_gpadl.decrypted) +vfree (pdata->recv_buf); } }
@@ -295,7 +297,8 @@ hv_uio_probe(struct hv_device *dev, ret =vmbus_establish_gpadl (channel, pdata->recv_buf,RECV_BUFFER_SIZE , &pdata->recv_gpadl);if (ret) { -vfree (pdata->recv_buf); +if (!pdata->recv_gpadl.decrypted) +vfree (pdata->recv_buf); goto fail_close; }
@@ -317,7 +320,8 @@ hv_uio_probe(struct hv_device *dev, ret =vmbus_establish_gpadl (channel, pdata->send_buf,SEND_BUFFER_SIZE , &pdata->send_gpadl);if (ret) { -vfree (pdata->send_buf); +if (!pdata->send_gpadl.decrypted) +vfree (pdata->send_buf); goto fail_close; }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 39/43 Drivers: hv: vmbus: Don't free ring buffers that couldn't be re-encrypted
In reply to Sasha LevinFrom: Michael Kelley <[email protected]>
[ Upstream commit 30d18df6567be09c1433e81993e35e3da573ac48 ]
In CoCo VMs it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues.
The VMBus ring buffer code could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the struct vmbus_gpadl for the ring buffers to decide whether to free the memory.
Message-ID: <[email protected]>
--- drivers/hv/channel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hv/channel.c +3 -1
@@ -153,7 +153,9 @@ void vmbus_free_ring(struct vmbus_channel *channel)hv_ringbuffer_cleanup (&channel->inbound);if (channel->ringbuffer_page) { -__free_pages (channel->ringbuffer_page, +/* In a CoCo VM leak the memory if it didn't get re-encrypted */ +if (!channel->ringbuffer_gpadlhandle.decrypted) +__free_pages (channel->ringbuffer_page,get_order (channel->ringbuffer_pagecount <<PAGE_SHIFT )); channel->ringbuffer_page =NULL ;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 40/43 drm/xe/xe_migrate: Cast to output precision before multiplying operands
In reply to Sasha LevinFrom: Himal Prasad Ghimiray <[email protected]>
[ Upstream commit 9cb46b31f3d08ed3fce86349e8c12f96d7c88717 ]
Addressing potential overflow in result of multiplication of two lower precision (u32) operands before widening it to higher precision (u64).
-v2
Fix commit message and description. (Rodrigo)
--- drivers/gpu/drm/xe/xe_migrate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_migrate.c +4 -4
@@ -216,7 +216,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,if (vm->flags &XE_VM_FLAG_64K && level ==1 ) flags =XE_PDE_64K ; - entry = vm->pt_ops->pde_encode_bo (bo, map_ofs + (level -1 ) * + entry = vm->pt_ops->pde_encode_bo (bo, map_ofs + (u64)(level -1 ) *XE_PAGE_SIZE , pat_index);xe_map_wr (xe, &bo->vmap, map_ofs +XE_PAGE_SIZE * level, u64, entry | flags);
@@ -224,7 +224,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,/* Write PDE's that point to our BO. */ for (i =0 ; i < num_entries - num_level; i++) { - entry = vm->pt_ops->pde_encode_bo (bo, i *XE_PAGE_SIZE , + entry = vm->pt_ops->pde_encode_bo (bo, (u64 )i *XE_PAGE_SIZE , pat_index); xe_map_wr(xe, &bo->vmap, map_ofs + XE_PAGE_SIZE +
@@ -280,7 +280,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,#define VM_SA_UPDATE_UNIT_SIZE (XE_PAGE_SIZE / NUM_VMUSA_UNIT_PER_PAGE)#define NUM_VMUSA_WRITES_PER_UNIT (VM_SA_UPDATE_UNIT_SIZE / sizeof(u64))drm_suballoc_manager_init (&m->vm_update_sa, - (map_ofs /XE_PAGE_SIZE -NUM_KERNEL_PDE ) * + (size_t )(map_ofs /XE_PAGE_SIZE -NUM_KERNEL_PDE ) *NUM_VMUSA_UNIT_PER_PAGE ,0 ); m->pt_bo = bo;
@@ -479,7 +479,7 @@ static void emit_pte(struct xe_migrate *m,struct xe_vm *vm = m->q->vm;u16 pat_index;u32 ptes; -u64 ofs = at_pt *XE_PAGE_SIZE ; +u64 ofs = (u64 )at_pt *XE_PAGE_SIZE ;u64 cur_ofs;/* Indirect access needs compression enabled uncached PAT index */
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 41/43 drm/xe: Label RING_CONTEXT_CONTROL as masked
In reply to Sasha LevinFrom: Ashutosh Dixit <[email protected]>
[ Upstream commit f76646c83f028c62853c23dac49204232e903597 ]
RING_CONTEXT_CONTROL is a masked register.
v2: Also clean up setting register value (Lucas)
--- drivers/gpu/drm/xe/regs/xe_engine_regs.h | 2 +- drivers/gpu/drm/xe/xe_lrc.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/regs/xe_engine_regs.h +1 -1
@@ -120,7 +120,7 @@#define RING_EXECLIST_STATUS_LO (base) XE_REG((base) + 0x234)#define RING_EXECLIST_STATUS_HI (base) XE_REG((base) + 0x234 + 4) -#define RING_CONTEXT_CONTROL (base) XE_REG((base) + 0x244) +#define RING_CONTEXT_CONTROL (base) XE_REG((base) + 0x244, XE_REG_OPTION_MASKED)#define CTX_CTRL_INHIBIT_SYN_CTX_SWITCH REG_BIT(3)#define CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT REG_BIT(0)
drivers/gpu/drm/xe/xe_lrc.c +2 -3
@@ -525,9 +525,8 @@ static const u8 *reg_offsets(struct xe_device *xe, enum xe_engine_class class)static void set_context_control (u32 *regs,struct xe_hw_engine *hwe) { - regs[CTX_CONTEXT_CONTROL ] =_MASKED_BIT_ENABLE (CTX_CTRL_INHIBIT_SYN_CTX_SWITCH ) | -_MASKED_BIT_DISABLE (CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT ) | -CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT ; + regs[CTX_CONTEXT_CONTROL ] =_MASKED_BIT_ENABLE (CTX_CTRL_INHIBIT_SYN_CTX_SWITCH | +CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT );/* TODO: Timestamp */ }
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 42/43 smb3: fix broken reconnect when password changing on the server by allowing password rotation
In reply to Sasha LevinFrom: Steve French <[email protected]>
[ Upstream commit 35f834265e0dc78b003aa0d1af65cafb89666b76 ]
There are various use cases that are becoming more common in which password changes are scheduled on a server(s) periodically but the clients connected to this server need to stay connected (even in the face of brief network reconnects) due to mounts which can not be easily unmounted and mounted at will, and servers that do password rotation do not always have the ability to tell the clients exactly when to the new password will be effective, so add support for an alt password ("password2=") on mount (and also remount) so that we can anticipate the upcoming change to the server without risking breaking existing mounts.
An alternative would have been to use the kernel keyring for this but the processes doing the reconnect do not have access to the keyring but do have access to the ses structure.
--- fs/smb/client/cifsglob.h | 1 + fs/smb/client/connect.c | 8 ++++++++ fs/smb/client/fs_context.c | 21 +++++++++++++++++++++ fs/smb/client/fs_context.h | 2 ++ fs/smb/client/misc.c | 1 + fs/smb/client/smb2pdu.c | 11 +++++++++++ 6 files changed, 44 insertions(+)
fs/smb/client/cifsglob.h +1 -0
@@ -1063,6 +1063,7 @@ struct cifs_ses {and after mount option parsing we fill it */ char *domainName;char *password; +char *password2;/* When key rotation used, new password may be set before it expires */ char workstation_name[CIFS_MAX_WORKSTATION_LEN ];struct session_key auth_key;struct ntlmssp_auth *ntlmssp;/* ciphertext, flags, server challenge */
fs/smb/client/connect.c +8 -0
@@ -2186,6 +2186,7 @@ cifs_set_cifscreds(struct smb3_fs_context *ctx, struct cifs_ses *ses) } ++delim; +/* BB consider adding support for password2 (Key Rotation) for multiuser in future */ ctx->password =kstrndup (delim, len,GFP_KERNEL );if (!ctx->password) { cifs_dbg(FYI, "Unable to allocate %zd bytes for password\n",
@@ -2209,6 +2210,7 @@ cifs_set_cifscreds(struct smb3_fs_context *ctx, struct cifs_ses *ses)kfree (ctx->username); ctx->username =NULL ;kfree_sensitive (ctx->password); +/* no need to free ctx->password2 since not allocated in this path */ ctx->password =NULL ; goto out_key_put; }
@@ -2320,6 +2322,12 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)if (!ses->password) goto get_ses_fail; } +/* ctx->password freed at unmount */ +if (ctx->password2) { + ses->password2 =kstrdup (ctx->password2,GFP_KERNEL ); +if (!ses->password2) + goto get_ses_fail; + }if (ctx->domainname) { ses->domainName =kstrdup (ctx->domainname,GFP_KERNEL );if (!ses->domainName)
fs/smb/client/fs_context.c +21 -0
@@ -162,6 +162,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {fsparam_string ("username" , Opt_user),fsparam_string ("pass" , Opt_pass),fsparam_string ("password" , Opt_pass), +fsparam_string ("password2" , Opt_pass2),fsparam_string ("ip" , Opt_ip),fsparam_string ("addr" , Opt_ip), fsparam_string("domain", Opt_domain),
@@ -315,6 +316,7 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx new_ctx->nodename =NULL ; new_ctx->username =NULL ; new_ctx->password =NULL ; + new_ctx->password2 =NULL ; new_ctx->server_hostname =NULL ; new_ctx->domainname =NULL ; new_ctx->UNC =NULL ;
@@ -327,6 +329,7 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctxDUP_CTX_STR (prepath);DUP_CTX_STR (username);DUP_CTX_STR (password); +DUP_CTX_STR (password2);DUP_CTX_STR (server_hostname);DUP_CTX_STR (UNC );DUP_CTX_STR (source);
@@ -875,6 +878,8 @@ static int smb3_reconfigure(struct fs_context *fc)else {kfree_sensitive (ses->password); ses->password =kstrdup (ctx->password,GFP_KERNEL ); +kfree_sensitive (ses->password2); + ses->password2 =kstrdup (ctx->password2,GFP_KERNEL ); }STEAL_STRING (cifs_sb, ctx, domainname);STEAL_STRING (cifs_sb, ctx, nodename);
@@ -1275,6 +1280,18 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, goto cifs_parse_mount_err; }break ; +case Opt_pass2: +kfree_sensitive (ctx->password2); + ctx->password2 =NULL ; +if (strlen (param->string) ==0 ) +break ; + + ctx->password2 =kstrdup (param->string,GFP_KERNEL ); +if (ctx->password2 ==NULL ) { +cifs_errorf (fc,"OOM when copying password2 string\n" ); + goto cifs_parse_mount_err; + } +break ;case Opt_ip:if (strlen (param->string) ==0 ) { ctx->got_ip = false;
@@ -1574,6 +1591,8 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, cifs_parse_mount_err:kfree_sensitive (ctx->password); ctx->password =NULL ; +kfree_sensitive (ctx->password2); + ctx->password2 =NULL ;return -EINVAL ; }
@@ -1678,6 +1697,8 @@ smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx) ctx->username =NULL ;kfree_sensitive (ctx->password); ctx->password =NULL ; +kfree_sensitive (ctx->password2); + ctx->password2 =NULL ;kfree (ctx->server_hostname); ctx->server_hostname =NULL ;kfree (ctx->UNC);
fs/smb/client/fs_context.h +2 -0
@@ -138,6 +138,7 @@ enum cifs_param { Opt_source, Opt_user, Opt_pass, + Opt_pass2, Opt_ip, Opt_domain, Opt_srcaddr,
@@ -169,6 +170,7 @@ struct smb3_fs_context {char *username;char *password; +char *password2;char *domainname;char *source;char *server_hostname;
fs/smb/client/misc.c +1 -0
@@ -101,6 +101,7 @@ sesInfoFree(struct cifs_ses *buf_to_free)kfree (buf_to_free->serverDomain);kfree (buf_to_free->serverNOS);kfree_sensitive (buf_to_free->password); +kfree_sensitive (buf_to_free->password2);kfree (buf_to_free->user_name);kfree (buf_to_free->domainName);kfree_sensitive (buf_to_free->auth_key.response);
fs/smb/client/smb2pdu.c +11 -0
@@ -367,6 +367,17 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, } rc =cifs_setup_session (0 , ses, server, nls_codepage); +if ((rc == -EACCES ) || (rc == -EKEYEXPIRED ) || (rc == -EKEYREVOKED )) { +/* +* Try alternate password for next reconnect (key rotation +* could be enabled on the server e.g.) if an alternate +* password is available and the current password is expired, +* but do not swap on non pwd related errors like host down +*/ +if (ses->password2) +swap (ses->password2, ses->password); + } +if ((rc == -EACCES ) && !tcon->retry) {mutex_unlock (&ses->session_mutex); rc = -EHOSTDOWN ;
Signature · 1 line
2.43.0
Sasha Levin
maintainerPATCH 43/43 iommu: mtk: fix module autoloading
In reply to Sasha LevinFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit 7537e31df80cb58c27f3b6fef702534ea87a5957 ]
Add MODULE_DEVICE_TABLE(), so modules could be properly autoloaded based on the alias from of_device_id table.
--- drivers/iommu/mtk_iommu.c | 1 + drivers/iommu/mtk_iommu_v1.c | 1 + 2 files changed, 2 insertions(+)
drivers/iommu/mtk_iommu.c +1 -0
@@ -1789,6 +1789,7 @@ static const struct of_device_id mtk_iommu_of_ids[] = { { .compatible = "mediatek,mt8365-m4u", .data = &mt8365_data}, {} }; +MODULE_DEVICE_TABLE (of, mtk_iommu_of_ids);static struct platform_driver mtk_iommu_driver = { .probe = mtk_iommu_probe,
drivers/iommu/mtk_iommu_v1.c +1 -0
@@ -599,6 +599,7 @@ static const struct of_device_id mtk_iommu_v1_of_ids[] = { { .compatible = "mediatek,mt2701-m4u", }, {} }; +MODULE_DEVICE_TABLE (of, mtk_iommu_v1_of_ids);static const struct component_master_ops mtk_iommu_v1_com_ops = { .bind = mtk_iommu_v1_bind,
Signature · 1 line
2.43.0