Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net

Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+3008 -1455
+5 -5
Documentation/filesystems/cifs/ksmbd.rst
··· 50 50 -------------------------------- 51 51 52 52 ksmbd.mountd is userspace process to, transfer user account and password that 53 - are registered using ksmbd.adduser(part of utils for user space). Further it 53 + are registered using ksmbd.adduser (part of utils for user space). Further it 54 54 allows sharing information parameters that parsed from smb.conf to ksmbd in 55 55 kernel. For the execution part it has a daemon which is continuously running 56 56 and connected to the kernel interface using netlink socket, it waits for the 57 - requests(dcerpc and share/user info). It handles RPC calls (at a minimum few 57 + requests (dcerpc and share/user info). It handles RPC calls (at a minimum few 58 58 dozen) that are most important for file server from NetShareEnum and 59 59 NetServerGetInfo. Complete DCE/RPC response is prepared from the user space 60 60 and passed over to the associated kernel thread for the client. ··· 154 154 1. Enable all component prints 155 155 # sudo ksmbd.control -d "all" 156 156 157 - 2. Enable one of components(smb, auth, vfs, oplock, ipc, conn, rdma) 157 + 2. Enable one of components (smb, auth, vfs, oplock, ipc, conn, rdma) 158 158 # sudo ksmbd.control -d "smb" 159 159 160 - 3. Show what prints are enable. 161 - # cat/sys/class/ksmbd-control/debug 160 + 3. Show what prints are enabled. 161 + # cat /sys/class/ksmbd-control/debug 162 162 [smb] auth vfs oplock ipc conn [rdma] 163 163 164 164 4. Disable prints:
+56 -39
Documentation/filesystems/netfs_library.rst
··· 1 1 .. SPDX-License-Identifier: GPL-2.0 2 2 3 3 ================================= 4 - NETWORK FILESYSTEM HELPER LIBRARY 4 + Network Filesystem Helper Library 5 5 ================================= 6 6 7 7 .. Contents: ··· 37 37 38 38 The following services are provided: 39 39 40 - * Handles transparent huge pages (THPs). 40 + * Handle folios that span multiple pages. 41 41 42 - * Insulates the netfs from VM interface changes. 42 + * Insulate the netfs from VM interface changes. 43 43 44 - * Allows the netfs to arbitrarily split reads up into pieces, even ones that 45 - don't match page sizes or page alignments and that may cross pages. 44 + * Allow the netfs to arbitrarily split reads up into pieces, even ones that 45 + don't match folio sizes or folio alignments and that may cross folios. 46 46 47 - * Allows the netfs to expand a readahead request in both directions to meet 48 - its needs. 47 + * Allow the netfs to expand a readahead request in both directions to meet its 48 + needs. 49 49 50 - * Allows the netfs to partially fulfil a read, which will then be resubmitted. 50 + * Allow the netfs to partially fulfil a read, which will then be resubmitted. 51 51 52 - * Handles local caching, allowing cached data and server-read data to be 52 + * Handle local caching, allowing cached data and server-read data to be 53 53 interleaved for a single request. 54 54 55 - * Handles clearing of bufferage that aren't on the server. 55 + * Handle clearing of bufferage that aren't on the server. 56 56 57 57 * Handle retrying of reads that failed, switching reads from the cache to the 58 58 server as necessary. ··· 70 70 71 71 Three read helpers are provided:: 72 72 73 - * void netfs_readahead(struct readahead_control *ractl, 74 - const struct netfs_read_request_ops *ops, 75 - void *netfs_priv);`` 76 - * int netfs_readpage(struct file *file, 77 - struct page *page, 78 - const struct netfs_read_request_ops *ops, 79 - void *netfs_priv); 80 - * int netfs_write_begin(struct file *file, 81 - struct address_space *mapping, 82 - loff_t pos, 83 - unsigned int len, 84 - unsigned int flags, 85 - struct page **_page, 86 - void **_fsdata, 87 - const struct netfs_read_request_ops *ops, 88 - void *netfs_priv); 73 + void netfs_readahead(struct readahead_control *ractl, 74 + const struct netfs_read_request_ops *ops, 75 + void *netfs_priv); 76 + int netfs_readpage(struct file *file, 77 + struct folio *folio, 78 + const struct netfs_read_request_ops *ops, 79 + void *netfs_priv); 80 + int netfs_write_begin(struct file *file, 81 + struct address_space *mapping, 82 + loff_t pos, 83 + unsigned int len, 84 + unsigned int flags, 85 + struct folio **_folio, 86 + void **_fsdata, 87 + const struct netfs_read_request_ops *ops, 88 + void *netfs_priv); 89 89 90 90 Each corresponds to a VM operation, with the addition of a couple of parameters 91 91 for the use of the read helpers: ··· 103 103 For ->readahead() and ->readpage(), the network filesystem should just jump 104 104 into the corresponding read helper; whereas for ->write_begin(), it may be a 105 105 little more complicated as the network filesystem might want to flush 106 - conflicting writes or track dirty data and needs to put the acquired page if an 107 - error occurs after calling the helper. 106 + conflicting writes or track dirty data and needs to put the acquired folio if 107 + an error occurs after calling the helper. 108 108 109 109 The helpers manage the read request, calling back into the network filesystem 110 110 through the suppplied table of operations. Waits will be performed as ··· 253 253 void (*issue_op)(struct netfs_read_subrequest *subreq); 254 254 bool (*is_still_valid)(struct netfs_read_request *rreq); 255 255 int (*check_write_begin)(struct file *file, loff_t pos, unsigned len, 256 - struct page *page, void **_fsdata); 256 + struct folio *folio, void **_fsdata); 257 257 void (*done)(struct netfs_read_request *rreq); 258 258 void (*cleanup)(struct address_space *mapping, void *netfs_priv); 259 259 }; ··· 313 313 314 314 There is no return value; the netfs_subreq_terminated() function should be 315 315 called to indicate whether or not the operation succeeded and how much data 316 - it transferred. The filesystem also should not deal with setting pages 316 + it transferred. The filesystem also should not deal with setting folios 317 317 uptodate, unlocking them or dropping their refs - the helpers need to deal 318 318 with this as they have to coordinate with copying to the local cache. 319 319 320 - Note that the helpers have the pages locked, but not pinned. It is possible 321 - to use the ITER_XARRAY iov iterator to refer to the range of the inode that 322 - is being operated upon without the need to allocate large bvec tables. 320 + Note that the helpers have the folios locked, but not pinned. It is 321 + possible to use the ITER_XARRAY iov iterator to refer to the range of the 322 + inode that is being operated upon without the need to allocate large bvec 323 + tables. 323 324 324 325 * ``is_still_valid()`` 325 326 ··· 331 330 * ``check_write_begin()`` 332 331 333 332 [Optional] This is called from the netfs_write_begin() helper once it has 334 - allocated/grabbed the page to be modified to allow the filesystem to flush 333 + allocated/grabbed the folio to be modified to allow the filesystem to flush 335 334 conflicting state before allowing it to be modified. 336 335 337 - It should return 0 if everything is now fine, -EAGAIN if the page should be 336 + It should return 0 if everything is now fine, -EAGAIN if the folio should be 338 337 regrabbed and any other error code to abort the operation. 339 338 340 339 * ``done`` 341 340 342 - [Optional] This is called after the pages in the request have all been 341 + [Optional] This is called after the folios in the request have all been 343 342 unlocked (and marked uptodate if applicable). 344 343 345 344 * ``cleanup`` ··· 391 390 * If NETFS_SREQ_CLEAR_TAIL was set, a short read will be cleared to the 392 391 end of the slice instead of reissuing. 393 392 394 - * Once the data is read, the pages that have been fully read/cleared: 393 + * Once the data is read, the folios that have been fully read/cleared: 395 394 396 395 * Will be marked uptodate. 397 396 ··· 399 398 400 399 * Unlocked 401 400 402 - * Any pages that need writing to the cache will then have DIO writes issued. 401 + * Any folios that need writing to the cache will then have DIO writes issued. 403 402 404 403 * Synchronous operations will wait for reading to be complete. 405 404 406 - * Writes to the cache will proceed asynchronously and the pages will have the 405 + * Writes to the cache will proceed asynchronously and the folios will have the 407 406 PG_fscache mark removed when that completes. 408 407 409 408 * The request structures will be cleaned up when everything has completed. ··· 452 451 bool seek_data, 453 452 netfs_io_terminated_t term_func, 454 453 void *term_func_priv); 454 + 455 + int (*prepare_write)(struct netfs_cache_resources *cres, 456 + loff_t *_start, size_t *_len, loff_t i_size); 455 457 456 458 int (*write)(struct netfs_cache_resources *cres, 457 459 loff_t start_pos, ··· 513 509 indicating whether the termination is definitely happening in the caller's 514 510 context. 515 511 512 + * ``prepare_write()`` 513 + 514 + [Required] Called to adjust a write to the cache and check that there is 515 + sufficient space in the cache. The start and length values indicate the 516 + size of the write that netfslib is proposing, and this can be adjusted by 517 + the cache to respect DIO boundaries. The file size is passed for 518 + information. 519 + 516 520 * ``write()`` 517 521 518 522 [Required] Called to write to the cache. The start file offset is given ··· 537 525 there isn't a read request structure as well, such as writing dirty data to the 538 526 cache. 539 527 528 + 529 + API Function Reference 530 + ====================== 531 + 540 532 .. kernel-doc:: include/linux/netfs.h 533 + .. kernel-doc:: fs/netfs/read_helper.c
+5 -2
MAINTAINERS
··· 15994 15994 15995 15995 RANDOM NUMBER DRIVER 15996 15996 M: "Theodore Ts'o" <tytso@mit.edu> 15997 + M: Jason A. Donenfeld <Jason@zx2c4.com> 15997 15998 S: Maintained 15998 15999 F: drivers/char/random.c 15999 16000 ··· 16639 16638 16640 16639 S390 IUCV NETWORK LAYER 16641 16640 M: Julian Wiedmann <jwi@linux.ibm.com> 16642 - M: Karsten Graul <kgraul@linux.ibm.com> 16641 + M: Alexandra Winter <wintera@linux.ibm.com> 16642 + M: Wenjia Zhang <wenjia@linux.ibm.com> 16643 16643 L: linux-s390@vger.kernel.org 16644 16644 L: netdev@vger.kernel.org 16645 16645 S: Supported ··· 16651 16649 16652 16650 S390 NETWORK DRIVERS 16653 16651 M: Julian Wiedmann <jwi@linux.ibm.com> 16654 - M: Karsten Graul <kgraul@linux.ibm.com> 16652 + M: Alexandra Winter <wintera@linux.ibm.com> 16653 + M: Wenjia Zhang <wenjia@linux.ibm.com> 16655 16654 L: linux-s390@vger.kernel.org 16656 16655 L: netdev@vger.kernel.org 16657 16656 S: Supported
+1 -1
Makefile
··· 2 2 VERSION = 5 3 3 PATCHLEVEL = 16 4 4 SUBLEVEL = 0 5 - EXTRAVERSION = -rc2 5 + EXTRAVERSION = -rc3 6 6 NAME = Gobble Gobble 7 7 8 8 # *DOCUMENTATION*
+10
arch/Kconfig
··· 991 991 and vice-versa 32-bit applications to call 64-bit mmap(). 992 992 Required for applications doing different bitness syscalls. 993 993 994 + config PAGE_SIZE_LESS_THAN_64KB 995 + def_bool y 996 + depends on !ARM64_64K_PAGES 997 + depends on !IA64_PAGE_SIZE_64KB 998 + depends on !PAGE_SIZE_64KB 999 + depends on !PARISC_PAGE_SIZE_64KB 1000 + depends on !PPC_64K_PAGES 1001 + depends on !PPC_256K_PAGES 1002 + depends on !PAGE_SIZE_256KB 1003 + 994 1004 # This allows to use a set of generic functions to determine mmap base 995 1005 # address by giving priority to top-down scheme only if the process 996 1006 # is not in legacy mode (compat task, unlimited stack size or
+2 -2
arch/arm64/include/asm/kvm_arm.h
··· 91 91 #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) 92 92 93 93 /* TCR_EL2 Registers bits */ 94 - #define TCR_EL2_RES1 ((1 << 31) | (1 << 23)) 94 + #define TCR_EL2_RES1 ((1U << 31) | (1 << 23)) 95 95 #define TCR_EL2_TBI (1 << 20) 96 96 #define TCR_EL2_PS_SHIFT 16 97 97 #define TCR_EL2_PS_MASK (7 << TCR_EL2_PS_SHIFT) ··· 276 276 #define CPTR_EL2_TFP_SHIFT 10 277 277 278 278 /* Hyp Coprocessor Trap Register */ 279 - #define CPTR_EL2_TCPAC (1 << 31) 279 + #define CPTR_EL2_TCPAC (1U << 31) 280 280 #define CPTR_EL2_TAM (1 << 30) 281 281 #define CPTR_EL2_TTA (1 << 20) 282 282 #define CPTR_EL2_TFP (1 << CPTR_EL2_TFP_SHIFT)
+14
arch/arm64/kvm/hyp/include/hyp/switch.h
··· 403 403 404 404 static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm_vcpu *vcpu); 405 405 406 + static void early_exit_filter(struct kvm_vcpu *vcpu, u64 *exit_code); 407 + 406 408 /* 407 409 * Allow the hypervisor to handle the exit with an exit handler if it has one. 408 410 * ··· 431 429 */ 432 430 static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) 433 431 { 432 + /* 433 + * Save PSTATE early so that we can evaluate the vcpu mode 434 + * early on. 435 + */ 436 + vcpu->arch.ctxt.regs.pstate = read_sysreg_el2(SYS_SPSR); 437 + 438 + /* 439 + * Check whether we want to repaint the state one way or 440 + * another. 441 + */ 442 + early_exit_filter(vcpu, exit_code); 443 + 434 444 if (ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ) 435 445 vcpu->arch.fault.esr_el2 = read_sysreg_el2(SYS_ESR); 436 446
+6 -1
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
··· 70 70 static inline void __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt) 71 71 { 72 72 ctxt->regs.pc = read_sysreg_el2(SYS_ELR); 73 - ctxt->regs.pstate = read_sysreg_el2(SYS_SPSR); 73 + /* 74 + * Guest PSTATE gets saved at guest fixup time in all 75 + * cases. We still need to handle the nVHE host side here. 76 + */ 77 + if (!has_vhe() && ctxt->__hyp_running_vcpu) 78 + ctxt->regs.pstate = read_sysreg_el2(SYS_SPSR); 74 79 75 80 if (cpus_have_final_cap(ARM64_HAS_RAS_EXTN)) 76 81 ctxt_sys_reg(ctxt, DISR_EL1) = read_sysreg_s(SYS_VDISR_EL2);
+1 -7
arch/arm64/kvm/hyp/nvhe/switch.c
··· 233 233 * Returns false if the guest ran in AArch32 when it shouldn't have, and 234 234 * thus should exit to the host, or true if a the guest run loop can continue. 235 235 */ 236 - static bool handle_aarch32_guest(struct kvm_vcpu *vcpu, u64 *exit_code) 236 + static void early_exit_filter(struct kvm_vcpu *vcpu, u64 *exit_code) 237 237 { 238 238 struct kvm *kvm = kern_hyp_va(vcpu->kvm); 239 239 ··· 248 248 vcpu->arch.target = -1; 249 249 *exit_code &= BIT(ARM_EXIT_WITH_SERROR_BIT); 250 250 *exit_code |= ARM_EXCEPTION_IL; 251 - return false; 252 251 } 253 - 254 - return true; 255 252 } 256 253 257 254 /* Switch to the guest for legacy non-VHE systems */ ··· 312 315 do { 313 316 /* Jump in the fire! */ 314 317 exit_code = __guest_enter(vcpu); 315 - 316 - if (unlikely(!handle_aarch32_guest(vcpu, &exit_code))) 317 - break; 318 318 319 319 /* And we're baaack! */ 320 320 } while (fixup_guest_exit(vcpu, &exit_code));
+4
arch/arm64/kvm/hyp/vhe/switch.c
··· 112 112 return hyp_exit_handlers; 113 113 } 114 114 115 + static void early_exit_filter(struct kvm_vcpu *vcpu, u64 *exit_code) 116 + { 117 + } 118 + 115 119 /* Switch to the guest for VHE systems running in EL2 */ 116 120 static int __kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) 117 121 {
+1 -1
arch/mips/Kconfig
··· 3097 3097 config PGTABLE_LEVELS 3098 3098 int 3099 3099 default 4 if PAGE_SIZE_4KB && MIPS_VA_BITS_48 3100 - default 3 if 64BIT && !PAGE_SIZE_64KB 3100 + default 3 if 64BIT && (!PAGE_SIZE_64KB || MIPS_VA_BITS_48) 3101 3101 default 2 3102 3102 3103 3103 config MIPS_AUTO_PFN_OFFSET
+1 -1
arch/mips/boot/compressed/Makefile
··· 52 52 53 53 vmlinuzobjs-$(CONFIG_KERNEL_XZ) += $(obj)/ashldi3.o 54 54 55 - vmlinuzobjs-$(CONFIG_KERNEL_ZSTD) += $(obj)/bswapdi.o 55 + vmlinuzobjs-$(CONFIG_KERNEL_ZSTD) += $(obj)/bswapdi.o $(obj)/ashldi3.o 56 56 57 57 targets := $(notdir $(vmlinuzobjs-y)) 58 58
+2 -2
arch/mips/kernel/cpu-probe.c
··· 1734 1734 1735 1735 static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu) 1736 1736 { 1737 - decode_configs(c); 1738 - 1739 1737 /* All Loongson processors covered here define ExcCode 16 as GSExc. */ 1740 1738 c->options |= MIPS_CPU_GSEXCEX; 1741 1739 ··· 1794 1796 panic("Unknown Loongson Processor ID!"); 1795 1797 break; 1796 1798 } 1799 + 1800 + decode_configs(c); 1797 1801 } 1798 1802 #else 1799 1803 static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu) { }
+1 -1
arch/mips/kernel/proc.c
··· 185 185 seq_puts(m, " tx39_cache"); 186 186 if (cpu_has_octeon_cache) 187 187 seq_puts(m, " octeon_cache"); 188 - if (cpu_has_fpu) 188 + if (raw_cpu_has_fpu) 189 189 seq_puts(m, " fpu"); 190 190 if (cpu_has_32fpr) 191 191 seq_puts(m, " 32fpr");
+3 -3
arch/powerpc/kernel/head_32.h
··· 202 202 mfspr r1, SPRN_SPRG_THREAD 203 203 lwz r1, TASK_CPU - THREAD(r1) 204 204 slwi r1, r1, 3 205 - addis r1, r1, emergency_ctx@ha 205 + addis r1, r1, emergency_ctx-PAGE_OFFSET@ha 206 206 #else 207 - lis r1, emergency_ctx@ha 207 + lis r1, emergency_ctx-PAGE_OFFSET@ha 208 208 #endif 209 - lwz r1, emergency_ctx@l(r1) 209 + lwz r1, emergency_ctx-PAGE_OFFSET@l(r1) 210 210 addi r1, r1, THREAD_SIZE - INT_FRAME_SIZE 211 211 EXCEPTION_PROLOG_2 0 vmap_stack_overflow 212 212 prepare_transfer_to_handler
+4 -1
arch/powerpc/kvm/book3s_hv_builtin.c
··· 695 695 "r" (0) : "memory"); 696 696 } 697 697 asm volatile("ptesync": : :"memory"); 698 + // POWER9 congruence-class TLBIEL leaves ERAT. Flush it now. 698 699 asm volatile(PPC_RADIX_INVALIDATE_ERAT_GUEST : : :"memory"); 699 700 } else { 700 701 for (set = 0; set < kvm->arch.tlb_sets; ++set) { ··· 706 705 rb += PPC_BIT(51); /* increment set number */ 707 706 } 708 707 asm volatile("ptesync": : :"memory"); 709 - asm volatile(PPC_ISA_3_0_INVALIDATE_ERAT : : :"memory"); 708 + // POWER9 congruence-class TLBIEL leaves ERAT. Flush it now. 709 + if (cpu_has_feature(CPU_FTR_ARCH_300)) 710 + asm volatile(PPC_ISA_3_0_INVALIDATE_ERAT : : :"memory"); 710 711 } 711 712 } 712 713
+3 -5
arch/riscv/include/asm/kvm_host.h
··· 12 12 #include <linux/types.h> 13 13 #include <linux/kvm.h> 14 14 #include <linux/kvm_types.h> 15 + #include <asm/csr.h> 15 16 #include <asm/kvm_vcpu_fp.h> 16 17 #include <asm/kvm_vcpu_timer.h> 17 18 18 - #ifdef CONFIG_64BIT 19 - #define KVM_MAX_VCPUS (1U << 16) 20 - #else 21 - #define KVM_MAX_VCPUS (1U << 9) 22 - #endif 19 + #define KVM_MAX_VCPUS \ 20 + ((HGATP_VMID_MASK >> HGATP_VMID_SHIFT) + 1) 23 21 24 22 #define KVM_HALT_POLL_NS_DEFAULT 500000 25 23
+6
arch/riscv/kvm/mmu.c
··· 453 453 void kvm_arch_flush_shadow_memslot(struct kvm *kvm, 454 454 struct kvm_memory_slot *slot) 455 455 { 456 + gpa_t gpa = slot->base_gfn << PAGE_SHIFT; 457 + phys_addr_t size = slot->npages << PAGE_SHIFT; 458 + 459 + spin_lock(&kvm->mmu_lock); 460 + stage2_unmap_range(kvm, gpa, size, false); 461 + spin_unlock(&kvm->mmu_lock); 456 462 } 457 463 458 464 void kvm_arch_commit_memory_region(struct kvm *kvm,
-6
arch/x86/include/asm/fpu/api.h
··· 102 102 */ 103 103 extern int cpu_has_xfeatures(u64 xfeatures_mask, const char **feature_name); 104 104 105 - /* 106 - * Tasks that are not using SVA have mm->pasid set to zero to note that they 107 - * will not have the valid bit set in MSR_IA32_PASID while they are running. 108 - */ 109 - #define PASID_DISABLED 0 110 - 111 105 /* Trap handling */ 112 106 extern int fpu__exception_code(struct fpu *fpu, int trap_nr); 113 107 extern void fpu_sync_fpstate(struct fpu *fpu);
+1 -1
arch/x86/kernel/setup.c
··· 742 742 return 0; 743 743 } 744 744 745 - static char *prepare_command_line(void) 745 + static char * __init prepare_command_line(void) 746 746 { 747 747 #ifdef CONFIG_CMDLINE_BOOL 748 748 #ifdef CONFIG_CMDLINE_OVERRIDE
-1
arch/x86/kvm/ioapic.h
··· 81 81 unsigned long irq_states[IOAPIC_NUM_PINS]; 82 82 struct kvm_io_device dev; 83 83 struct kvm *kvm; 84 - void (*ack_notifier)(void *opaque, int irq); 85 84 spinlock_t lock; 86 85 struct rtc_status rtc_status; 87 86 struct delayed_work eoi_inject;
-1
arch/x86/kvm/irq.h
··· 56 56 struct kvm_io_device dev_master; 57 57 struct kvm_io_device dev_slave; 58 58 struct kvm_io_device dev_elcr; 59 - void (*ack_notifier)(void *opaque, int irq); 60 59 unsigned long irq_states[PIC_NUM_PINS]; 61 60 }; 62 61
+1 -1
arch/x86/kvm/lapic.c
··· 707 707 static int apic_has_interrupt_for_ppr(struct kvm_lapic *apic, u32 ppr) 708 708 { 709 709 int highest_irr; 710 - if (apic->vcpu->arch.apicv_active) 710 + if (kvm_x86_ops.sync_pir_to_irr) 711 711 highest_irr = static_call(kvm_x86_sync_pir_to_irr)(apic->vcpu); 712 712 else 713 713 highest_irr = apic_find_highest_irr(apic);
+52 -45
arch/x86/kvm/mmu/mmu.c
··· 1582 1582 flush = kvm_handle_gfn_range(kvm, range, kvm_unmap_rmapp); 1583 1583 1584 1584 if (is_tdp_mmu_enabled(kvm)) 1585 - flush |= kvm_tdp_mmu_unmap_gfn_range(kvm, range, flush); 1585 + flush = kvm_tdp_mmu_unmap_gfn_range(kvm, range, flush); 1586 1586 1587 1587 return flush; 1588 1588 } ··· 2173 2173 iterator->shadow_addr = root; 2174 2174 iterator->level = vcpu->arch.mmu->shadow_root_level; 2175 2175 2176 - if (iterator->level == PT64_ROOT_4LEVEL && 2176 + if (iterator->level >= PT64_ROOT_4LEVEL && 2177 2177 vcpu->arch.mmu->root_level < PT64_ROOT_4LEVEL && 2178 2178 !vcpu->arch.mmu->direct_map) 2179 - --iterator->level; 2179 + iterator->level = PT32E_ROOT_LEVEL; 2180 2180 2181 2181 if (iterator->level == PT32E_ROOT_LEVEL) { 2182 2182 /* ··· 4855 4855 struct kvm_mmu *context = &vcpu->arch.guest_mmu; 4856 4856 struct kvm_mmu_role_regs regs = { 4857 4857 .cr0 = cr0, 4858 - .cr4 = cr4, 4858 + .cr4 = cr4 & ~X86_CR4_PKE, 4859 4859 .efer = efer, 4860 4860 }; 4861 4861 union kvm_mmu_role new_role; ··· 4919 4919 context->direct_map = false; 4920 4920 4921 4921 update_permission_bitmask(context, true); 4922 - update_pkru_bitmask(context); 4922 + context->pkru_mask = 0; 4923 4923 reset_rsvds_bits_mask_ept(vcpu, context, execonly); 4924 4924 reset_ept_shadow_zero_bits_mask(vcpu, context, execonly); 4925 4925 } ··· 5025 5025 /* 5026 5026 * Invalidate all MMU roles to force them to reinitialize as CPUID 5027 5027 * information is factored into reserved bit calculations. 5028 + * 5029 + * Correctly handling multiple vCPU models with respect to paging and 5030 + * physical address properties) in a single VM would require tracking 5031 + * all relevant CPUID information in kvm_mmu_page_role. That is very 5032 + * undesirable as it would increase the memory requirements for 5033 + * gfn_track (see struct kvm_mmu_page_role comments). For now that 5034 + * problem is swept under the rug; KVM's CPUID API is horrific and 5035 + * it's all but impossible to solve it without introducing a new API. 5028 5036 */ 5029 5037 vcpu->arch.root_mmu.mmu_role.ext.valid = 0; 5030 5038 vcpu->arch.guest_mmu.mmu_role.ext.valid = 0; ··· 5040 5032 kvm_mmu_reset_context(vcpu); 5041 5033 5042 5034 /* 5043 - * KVM does not correctly handle changing guest CPUID after KVM_RUN, as 5044 - * MAXPHYADDR, GBPAGES support, AMD reserved bit behavior, etc.. aren't 5045 - * tracked in kvm_mmu_page_role. As a result, KVM may miss guest page 5046 - * faults due to reusing SPs/SPTEs. Alert userspace, but otherwise 5047 - * sweep the problem under the rug. 5048 - * 5049 - * KVM's horrific CPUID ABI makes the problem all but impossible to 5050 - * solve, as correctly handling multiple vCPU models (with respect to 5051 - * paging and physical address properties) in a single VM would require 5052 - * tracking all relevant CPUID information in kvm_mmu_page_role. That 5053 - * is very undesirable as it would double the memory requirements for 5054 - * gfn_track (see struct kvm_mmu_page_role comments), and in practice 5055 - * no sane VMM mucks with the core vCPU model on the fly. 5035 + * Changing guest CPUID after KVM_RUN is forbidden, see the comment in 5036 + * kvm_arch_vcpu_ioctl(). 5056 5037 */ 5057 - if (vcpu->arch.last_vmentry_cpu != -1) { 5058 - pr_warn_ratelimited("KVM: KVM_SET_CPUID{,2} after KVM_RUN may cause guest instability\n"); 5059 - pr_warn_ratelimited("KVM: KVM_SET_CPUID{,2} will fail after KVM_RUN starting with Linux 5.16\n"); 5060 - } 5038 + KVM_BUG_ON(vcpu->arch.last_vmentry_cpu != -1, vcpu->kvm); 5061 5039 } 5062 5040 5063 5041 void kvm_mmu_reset_context(struct kvm_vcpu *vcpu) ··· 5363 5369 5364 5370 void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva) 5365 5371 { 5366 - kvm_mmu_invalidate_gva(vcpu, vcpu->arch.mmu, gva, INVALID_PAGE); 5372 + kvm_mmu_invalidate_gva(vcpu, vcpu->arch.walk_mmu, gva, INVALID_PAGE); 5367 5373 ++vcpu->stat.invlpg; 5368 5374 } 5369 5375 EXPORT_SYMBOL_GPL(kvm_mmu_invlpg); ··· 5848 5854 void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm, 5849 5855 const struct kvm_memory_slot *slot) 5850 5856 { 5851 - bool flush = false; 5852 - 5853 5857 if (kvm_memslots_have_rmaps(kvm)) { 5854 5858 write_lock(&kvm->mmu_lock); 5855 5859 /* ··· 5855 5863 * logging at a 4k granularity and never creates collapsible 5856 5864 * 2m SPTEs during dirty logging. 5857 5865 */ 5858 - flush = slot_handle_level_4k(kvm, slot, kvm_mmu_zap_collapsible_spte, true); 5859 - if (flush) 5866 + if (slot_handle_level_4k(kvm, slot, kvm_mmu_zap_collapsible_spte, true)) 5860 5867 kvm_arch_flush_remote_tlbs_memslot(kvm, slot); 5861 5868 write_unlock(&kvm->mmu_lock); 5862 5869 } 5863 5870 5864 5871 if (is_tdp_mmu_enabled(kvm)) { 5865 5872 read_lock(&kvm->mmu_lock); 5866 - flush = kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot, flush); 5867 - if (flush) 5868 - kvm_arch_flush_remote_tlbs_memslot(kvm, slot); 5873 + kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot); 5869 5874 read_unlock(&kvm->mmu_lock); 5870 5875 } 5871 5876 } ··· 6171 6182 mmu_audit_disable(); 6172 6183 } 6173 6184 6185 + /* 6186 + * Calculate the effective recovery period, accounting for '0' meaning "let KVM 6187 + * select a halving time of 1 hour". Returns true if recovery is enabled. 6188 + */ 6189 + static bool calc_nx_huge_pages_recovery_period(uint *period) 6190 + { 6191 + /* 6192 + * Use READ_ONCE to get the params, this may be called outside of the 6193 + * param setters, e.g. by the kthread to compute its next timeout. 6194 + */ 6195 + bool enabled = READ_ONCE(nx_huge_pages); 6196 + uint ratio = READ_ONCE(nx_huge_pages_recovery_ratio); 6197 + 6198 + if (!enabled || !ratio) 6199 + return false; 6200 + 6201 + *period = READ_ONCE(nx_huge_pages_recovery_period_ms); 6202 + if (!*period) { 6203 + /* Make sure the period is not less than one second. */ 6204 + ratio = min(ratio, 3600u); 6205 + *period = 60 * 60 * 1000 / ratio; 6206 + } 6207 + return true; 6208 + } 6209 + 6174 6210 static int set_nx_huge_pages_recovery_param(const char *val, const struct kernel_param *kp) 6175 6211 { 6176 6212 bool was_recovery_enabled, is_recovery_enabled; 6177 6213 uint old_period, new_period; 6178 6214 int err; 6179 6215 6180 - was_recovery_enabled = nx_huge_pages_recovery_ratio; 6181 - old_period = nx_huge_pages_recovery_period_ms; 6216 + was_recovery_enabled = calc_nx_huge_pages_recovery_period(&old_period); 6182 6217 6183 6218 err = param_set_uint(val, kp); 6184 6219 if (err) 6185 6220 return err; 6186 6221 6187 - is_recovery_enabled = nx_huge_pages_recovery_ratio; 6188 - new_period = nx_huge_pages_recovery_period_ms; 6222 + is_recovery_enabled = calc_nx_huge_pages_recovery_period(&new_period); 6189 6223 6190 - if (READ_ONCE(nx_huge_pages) && is_recovery_enabled && 6224 + if (is_recovery_enabled && 6191 6225 (!was_recovery_enabled || old_period > new_period)) { 6192 6226 struct kvm *kvm; 6193 6227 ··· 6274 6262 6275 6263 static long get_nx_lpage_recovery_timeout(u64 start_time) 6276 6264 { 6277 - uint ratio = READ_ONCE(nx_huge_pages_recovery_ratio); 6278 - uint period = READ_ONCE(nx_huge_pages_recovery_period_ms); 6265 + bool enabled; 6266 + uint period; 6279 6267 6280 - if (!period && ratio) { 6281 - /* Make sure the period is not less than one second. */ 6282 - ratio = min(ratio, 3600u); 6283 - period = 60 * 60 * 1000 / ratio; 6284 - } 6268 + enabled = calc_nx_huge_pages_recovery_period(&period); 6285 6269 6286 - return READ_ONCE(nx_huge_pages) && ratio 6287 - ? start_time + msecs_to_jiffies(period) - get_jiffies_64() 6288 - : MAX_SCHEDULE_TIMEOUT; 6270 + return enabled ? start_time + msecs_to_jiffies(period) - get_jiffies_64() 6271 + : MAX_SCHEDULE_TIMEOUT; 6289 6272 } 6290 6273 6291 6274 static int kvm_nx_lpage_recovery_worker(struct kvm *kvm, uintptr_t data)
+14 -24
arch/x86/kvm/mmu/tdp_mmu.c
··· 317 317 struct kvm_mmu_page *sp = sptep_to_sp(rcu_dereference(pt)); 318 318 int level = sp->role.level; 319 319 gfn_t base_gfn = sp->gfn; 320 - u64 old_child_spte; 321 - u64 *sptep; 322 - gfn_t gfn; 323 320 int i; 324 321 325 322 trace_kvm_mmu_prepare_zap_page(sp); ··· 324 327 tdp_mmu_unlink_page(kvm, sp, shared); 325 328 326 329 for (i = 0; i < PT64_ENT_PER_PAGE; i++) { 327 - sptep = rcu_dereference(pt) + i; 328 - gfn = base_gfn + i * KVM_PAGES_PER_HPAGE(level); 330 + u64 *sptep = rcu_dereference(pt) + i; 331 + gfn_t gfn = base_gfn + i * KVM_PAGES_PER_HPAGE(level); 332 + u64 old_child_spte; 329 333 330 334 if (shared) { 331 335 /* ··· 372 374 shared); 373 375 } 374 376 375 - kvm_flush_remote_tlbs_with_address(kvm, gfn, 377 + kvm_flush_remote_tlbs_with_address(kvm, base_gfn, 376 378 KVM_PAGES_PER_HPAGE(level + 1)); 377 379 378 380 call_rcu(&sp->rcu_head, tdp_mmu_free_sp_rcu_callback); ··· 1031 1033 { 1032 1034 struct kvm_mmu_page *root; 1033 1035 1034 - for_each_tdp_mmu_root(kvm, root, range->slot->as_id) 1035 - flush |= zap_gfn_range(kvm, root, range->start, range->end, 1036 - range->may_block, flush, false); 1036 + for_each_tdp_mmu_root_yield_safe(kvm, root, range->slot->as_id, false) 1037 + flush = zap_gfn_range(kvm, root, range->start, range->end, 1038 + range->may_block, flush, false); 1037 1039 1038 1040 return flush; 1039 1041 } ··· 1362 1364 * Clear leaf entries which could be replaced by large mappings, for 1363 1365 * GFNs within the slot. 1364 1366 */ 1365 - static bool zap_collapsible_spte_range(struct kvm *kvm, 1367 + static void zap_collapsible_spte_range(struct kvm *kvm, 1366 1368 struct kvm_mmu_page *root, 1367 - const struct kvm_memory_slot *slot, 1368 - bool flush) 1369 + const struct kvm_memory_slot *slot) 1369 1370 { 1370 1371 gfn_t start = slot->base_gfn; 1371 1372 gfn_t end = start + slot->npages; ··· 1375 1378 1376 1379 tdp_root_for_each_pte(iter, root, start, end) { 1377 1380 retry: 1378 - if (tdp_mmu_iter_cond_resched(kvm, &iter, flush, true)) { 1379 - flush = false; 1381 + if (tdp_mmu_iter_cond_resched(kvm, &iter, false, true)) 1380 1382 continue; 1381 - } 1382 1383 1383 1384 if (!is_shadow_present_pte(iter.old_spte) || 1384 1385 !is_last_spte(iter.old_spte, iter.level)) ··· 1388 1393 pfn, PG_LEVEL_NUM)) 1389 1394 continue; 1390 1395 1396 + /* Note, a successful atomic zap also does a remote TLB flush. */ 1391 1397 if (!tdp_mmu_zap_spte_atomic(kvm, &iter)) { 1392 1398 /* 1393 1399 * The iter must explicitly re-read the SPTE because ··· 1397 1401 iter.old_spte = READ_ONCE(*rcu_dereference(iter.sptep)); 1398 1402 goto retry; 1399 1403 } 1400 - flush = true; 1401 1404 } 1402 1405 1403 1406 rcu_read_unlock(); 1404 - 1405 - return flush; 1406 1407 } 1407 1408 1408 1409 /* 1409 1410 * Clear non-leaf entries (and free associated page tables) which could 1410 1411 * be replaced by large mappings, for GFNs within the slot. 1411 1412 */ 1412 - bool kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm, 1413 - const struct kvm_memory_slot *slot, 1414 - bool flush) 1413 + void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm, 1414 + const struct kvm_memory_slot *slot) 1415 1415 { 1416 1416 struct kvm_mmu_page *root; 1417 1417 1418 1418 lockdep_assert_held_read(&kvm->mmu_lock); 1419 1419 1420 1420 for_each_tdp_mmu_root_yield_safe(kvm, root, slot->as_id, true) 1421 - flush = zap_collapsible_spte_range(kvm, root, slot, flush); 1422 - 1423 - return flush; 1421 + zap_collapsible_spte_range(kvm, root, slot); 1424 1422 } 1425 1423 1426 1424 /*
+2 -3
arch/x86/kvm/mmu/tdp_mmu.h
··· 64 64 struct kvm_memory_slot *slot, 65 65 gfn_t gfn, unsigned long mask, 66 66 bool wrprot); 67 - bool kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm, 68 - const struct kvm_memory_slot *slot, 69 - bool flush); 67 + void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm, 68 + const struct kvm_memory_slot *slot); 70 69 71 70 bool kvm_tdp_mmu_write_protect_gfn(struct kvm *kvm, 72 71 struct kvm_memory_slot *slot, gfn_t gfn,
+9 -7
arch/x86/kvm/svm/avic.c
··· 989 989 static void avic_set_running(struct kvm_vcpu *vcpu, bool is_run) 990 990 { 991 991 struct vcpu_svm *svm = to_svm(vcpu); 992 + int cpu = get_cpu(); 992 993 994 + WARN_ON(cpu != vcpu->cpu); 993 995 svm->avic_is_running = is_run; 994 996 995 - if (!kvm_vcpu_apicv_active(vcpu)) 996 - return; 997 - 998 - if (is_run) 999 - avic_vcpu_load(vcpu, vcpu->cpu); 1000 - else 1001 - avic_vcpu_put(vcpu); 997 + if (kvm_vcpu_apicv_active(vcpu)) { 998 + if (is_run) 999 + avic_vcpu_load(vcpu, cpu); 1000 + else 1001 + avic_vcpu_put(vcpu); 1002 + } 1003 + put_cpu(); 1002 1004 } 1003 1005 1004 1006 void svm_vcpu_blocking(struct kvm_vcpu *vcpu)
+86 -75
arch/x86/kvm/svm/sev.c
··· 1543 1543 return false; 1544 1544 } 1545 1545 1546 - static int sev_lock_for_migration(struct kvm *kvm) 1546 + static int sev_lock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm) 1547 1547 { 1548 - struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; 1548 + struct kvm_sev_info *dst_sev = &to_kvm_svm(dst_kvm)->sev_info; 1549 + struct kvm_sev_info *src_sev = &to_kvm_svm(src_kvm)->sev_info; 1550 + int r = -EBUSY; 1551 + 1552 + if (dst_kvm == src_kvm) 1553 + return -EINVAL; 1549 1554 1550 1555 /* 1551 - * Bail if this VM is already involved in a migration to avoid deadlock 1552 - * between two VMs trying to migrate to/from each other. 1556 + * Bail if these VMs are already involved in a migration to avoid 1557 + * deadlock between two VMs trying to migrate to/from each other. 1553 1558 */ 1554 - if (atomic_cmpxchg_acquire(&sev->migration_in_progress, 0, 1)) 1559 + if (atomic_cmpxchg_acquire(&dst_sev->migration_in_progress, 0, 1)) 1555 1560 return -EBUSY; 1556 1561 1557 - mutex_lock(&kvm->lock); 1562 + if (atomic_cmpxchg_acquire(&src_sev->migration_in_progress, 0, 1)) 1563 + goto release_dst; 1558 1564 1565 + r = -EINTR; 1566 + if (mutex_lock_killable(&dst_kvm->lock)) 1567 + goto release_src; 1568 + if (mutex_lock_killable(&src_kvm->lock)) 1569 + goto unlock_dst; 1559 1570 return 0; 1571 + 1572 + unlock_dst: 1573 + mutex_unlock(&dst_kvm->lock); 1574 + release_src: 1575 + atomic_set_release(&src_sev->migration_in_progress, 0); 1576 + release_dst: 1577 + atomic_set_release(&dst_sev->migration_in_progress, 0); 1578 + return r; 1560 1579 } 1561 1580 1562 - static void sev_unlock_after_migration(struct kvm *kvm) 1581 + static void sev_unlock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm) 1563 1582 { 1564 - struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; 1583 + struct kvm_sev_info *dst_sev = &to_kvm_svm(dst_kvm)->sev_info; 1584 + struct kvm_sev_info *src_sev = &to_kvm_svm(src_kvm)->sev_info; 1565 1585 1566 - mutex_unlock(&kvm->lock); 1567 - atomic_set_release(&sev->migration_in_progress, 0); 1586 + mutex_unlock(&dst_kvm->lock); 1587 + mutex_unlock(&src_kvm->lock); 1588 + atomic_set_release(&dst_sev->migration_in_progress, 0); 1589 + atomic_set_release(&src_sev->migration_in_progress, 0); 1568 1590 } 1569 1591 1570 1592 ··· 1629 1607 dst->asid = src->asid; 1630 1608 dst->handle = src->handle; 1631 1609 dst->pages_locked = src->pages_locked; 1610 + dst->enc_context_owner = src->enc_context_owner; 1632 1611 1633 1612 src->asid = 0; 1634 1613 src->active = false; 1635 1614 src->handle = 0; 1636 1615 src->pages_locked = 0; 1616 + src->enc_context_owner = NULL; 1637 1617 1638 - INIT_LIST_HEAD(&dst->regions_list); 1639 - list_replace_init(&src->regions_list, &dst->regions_list); 1618 + list_cut_before(&dst->regions_list, &src->regions_list, &src->regions_list); 1640 1619 } 1641 1620 1642 1621 static int sev_es_migrate_from(struct kvm *dst, struct kvm *src) ··· 1689 1666 bool charged = false; 1690 1667 int ret; 1691 1668 1692 - ret = sev_lock_for_migration(kvm); 1693 - if (ret) 1694 - return ret; 1695 - 1696 - if (sev_guest(kvm)) { 1697 - ret = -EINVAL; 1698 - goto out_unlock; 1699 - } 1700 - 1701 1669 source_kvm_file = fget(source_fd); 1702 1670 if (!file_is_kvm(source_kvm_file)) { 1703 1671 ret = -EBADF; ··· 1696 1682 } 1697 1683 1698 1684 source_kvm = source_kvm_file->private_data; 1699 - ret = sev_lock_for_migration(source_kvm); 1685 + ret = sev_lock_two_vms(kvm, source_kvm); 1700 1686 if (ret) 1701 1687 goto out_fput; 1702 1688 1703 - if (!sev_guest(source_kvm)) { 1689 + if (sev_guest(kvm) || !sev_guest(source_kvm)) { 1704 1690 ret = -EINVAL; 1705 - goto out_source; 1691 + goto out_unlock; 1706 1692 } 1707 1693 1708 1694 src_sev = &to_kvm_svm(source_kvm)->sev_info; 1695 + 1696 + /* 1697 + * VMs mirroring src's encryption context rely on it to keep the 1698 + * ASID allocated, but below we are clearing src_sev->asid. 1699 + */ 1700 + if (src_sev->num_mirrored_vms) { 1701 + ret = -EBUSY; 1702 + goto out_unlock; 1703 + } 1704 + 1709 1705 dst_sev->misc_cg = get_current_misc_cg(); 1710 1706 cg_cleanup_sev = dst_sev; 1711 1707 if (dst_sev->misc_cg != src_sev->misc_cg) { ··· 1752 1728 sev_misc_cg_uncharge(cg_cleanup_sev); 1753 1729 put_misc_cg(cg_cleanup_sev->misc_cg); 1754 1730 cg_cleanup_sev->misc_cg = NULL; 1755 - out_source: 1756 - sev_unlock_after_migration(source_kvm); 1731 + out_unlock: 1732 + sev_unlock_two_vms(kvm, source_kvm); 1757 1733 out_fput: 1758 1734 if (source_kvm_file) 1759 1735 fput(source_kvm_file); 1760 - out_unlock: 1761 - sev_unlock_after_migration(kvm); 1762 1736 return ret; 1763 1737 } 1764 1738 ··· 1975 1953 { 1976 1954 struct file *source_kvm_file; 1977 1955 struct kvm *source_kvm; 1978 - struct kvm_sev_info source_sev, *mirror_sev; 1956 + struct kvm_sev_info *source_sev, *mirror_sev; 1979 1957 int ret; 1980 1958 1981 1959 source_kvm_file = fget(source_fd); 1982 1960 if (!file_is_kvm(source_kvm_file)) { 1983 1961 ret = -EBADF; 1984 - goto e_source_put; 1962 + goto e_source_fput; 1985 1963 } 1986 1964 1987 1965 source_kvm = source_kvm_file->private_data; 1988 - mutex_lock(&source_kvm->lock); 1966 + ret = sev_lock_two_vms(kvm, source_kvm); 1967 + if (ret) 1968 + goto e_source_fput; 1989 1969 1990 - if (!sev_guest(source_kvm)) { 1970 + /* 1971 + * Mirrors of mirrors should work, but let's not get silly. Also 1972 + * disallow out-of-band SEV/SEV-ES init if the target is already an 1973 + * SEV guest, or if vCPUs have been created. KVM relies on vCPUs being 1974 + * created after SEV/SEV-ES initialization, e.g. to init intercepts. 1975 + */ 1976 + if (sev_guest(kvm) || !sev_guest(source_kvm) || 1977 + is_mirroring_enc_context(source_kvm) || kvm->created_vcpus) { 1991 1978 ret = -EINVAL; 1992 - goto e_source_unlock; 1979 + goto e_unlock; 1993 1980 } 1994 - 1995 - /* Mirrors of mirrors should work, but let's not get silly */ 1996 - if (is_mirroring_enc_context(source_kvm) || source_kvm == kvm) { 1997 - ret = -EINVAL; 1998 - goto e_source_unlock; 1999 - } 2000 - 2001 - memcpy(&source_sev, &to_kvm_svm(source_kvm)->sev_info, 2002 - sizeof(source_sev)); 2003 1981 2004 1982 /* 2005 1983 * The mirror kvm holds an enc_context_owner ref so its asid can't 2006 1984 * disappear until we're done with it 2007 1985 */ 1986 + source_sev = &to_kvm_svm(source_kvm)->sev_info; 2008 1987 kvm_get_kvm(source_kvm); 2009 - 2010 - fput(source_kvm_file); 2011 - mutex_unlock(&source_kvm->lock); 2012 - mutex_lock(&kvm->lock); 2013 - 2014 - /* 2015 - * Disallow out-of-band SEV/SEV-ES init if the target is already an 2016 - * SEV guest, or if vCPUs have been created. KVM relies on vCPUs being 2017 - * created after SEV/SEV-ES initialization, e.g. to init intercepts. 2018 - */ 2019 - if (sev_guest(kvm) || kvm->created_vcpus) { 2020 - ret = -EINVAL; 2021 - goto e_mirror_unlock; 2022 - } 1988 + source_sev->num_mirrored_vms++; 2023 1989 2024 1990 /* Set enc_context_owner and copy its encryption context over */ 2025 1991 mirror_sev = &to_kvm_svm(kvm)->sev_info; 2026 1992 mirror_sev->enc_context_owner = source_kvm; 2027 1993 mirror_sev->active = true; 2028 - mirror_sev->asid = source_sev.asid; 2029 - mirror_sev->fd = source_sev.fd; 2030 - mirror_sev->es_active = source_sev.es_active; 2031 - mirror_sev->handle = source_sev.handle; 1994 + mirror_sev->asid = source_sev->asid; 1995 + mirror_sev->fd = source_sev->fd; 1996 + mirror_sev->es_active = source_sev->es_active; 1997 + mirror_sev->handle = source_sev->handle; 1998 + INIT_LIST_HEAD(&mirror_sev->regions_list); 1999 + ret = 0; 2000 + 2032 2001 /* 2033 2002 * Do not copy ap_jump_table. Since the mirror does not share the same 2034 2003 * KVM contexts as the original, and they may have different 2035 2004 * memory-views. 2036 2005 */ 2037 2006 2038 - mutex_unlock(&kvm->lock); 2039 - return 0; 2040 - 2041 - e_mirror_unlock: 2042 - mutex_unlock(&kvm->lock); 2043 - kvm_put_kvm(source_kvm); 2044 - return ret; 2045 - e_source_unlock: 2046 - mutex_unlock(&source_kvm->lock); 2047 - e_source_put: 2007 + e_unlock: 2008 + sev_unlock_two_vms(kvm, source_kvm); 2009 + e_source_fput: 2048 2010 if (source_kvm_file) 2049 2011 fput(source_kvm_file); 2050 2012 return ret; ··· 2040 2034 struct list_head *head = &sev->regions_list; 2041 2035 struct list_head *pos, *q; 2042 2036 2037 + WARN_ON(sev->num_mirrored_vms); 2038 + 2043 2039 if (!sev_guest(kvm)) 2044 2040 return; 2045 2041 2046 2042 /* If this is a mirror_kvm release the enc_context_owner and skip sev cleanup */ 2047 2043 if (is_mirroring_enc_context(kvm)) { 2048 - kvm_put_kvm(sev->enc_context_owner); 2044 + struct kvm *owner_kvm = sev->enc_context_owner; 2045 + struct kvm_sev_info *owner_sev = &to_kvm_svm(owner_kvm)->sev_info; 2046 + 2047 + mutex_lock(&owner_kvm->lock); 2048 + if (!WARN_ON(!owner_sev->num_mirrored_vms)) 2049 + owner_sev->num_mirrored_vms--; 2050 + mutex_unlock(&owner_kvm->lock); 2051 + kvm_put_kvm(owner_kvm); 2049 2052 return; 2050 2053 } 2051 - 2052 - mutex_lock(&kvm->lock); 2053 2054 2054 2055 /* 2055 2056 * Ensure that all guest tagged cache entries are flushed before ··· 2076 2063 cond_resched(); 2077 2064 } 2078 2065 } 2079 - 2080 - mutex_unlock(&kvm->lock); 2081 2066 2082 2067 sev_unbind_asid(kvm, sev->handle); 2083 2068 sev_asid_free(sev);
-1
arch/x86/kvm/svm/svm.c
··· 4651 4651 .load_eoi_exitmap = svm_load_eoi_exitmap, 4652 4652 .hwapic_irr_update = svm_hwapic_irr_update, 4653 4653 .hwapic_isr_update = svm_hwapic_isr_update, 4654 - .sync_pir_to_irr = kvm_lapic_find_highest_irr, 4655 4654 .apicv_post_state_restore = avic_post_state_restore, 4656 4655 4657 4656 .set_tss_addr = svm_set_tss_addr,
+1
arch/x86/kvm/svm/svm.h
··· 79 79 struct list_head regions_list; /* List of registered regions */ 80 80 u64 ap_jump_table; /* SEV-ES AP Jump Table address */ 81 81 struct kvm *enc_context_owner; /* Owner of copied encryption context */ 82 + unsigned long num_mirrored_vms; /* Number of VMs sharing this ASID */ 82 83 struct misc_cg *misc_cg; /* For misc cgroup accounting */ 83 84 atomic_t migration_in_progress; 84 85 };
+22 -27
arch/x86/kvm/vmx/nested.c
··· 1162 1162 WARN_ON(!enable_vpid); 1163 1163 1164 1164 /* 1165 - * If VPID is enabled and used by vmc12, but L2 does not have a unique 1166 - * TLB tag (ASID), i.e. EPT is disabled and KVM was unable to allocate 1167 - * a VPID for L2, flush the current context as the effective ASID is 1168 - * common to both L1 and L2. 1169 - * 1170 - * Defer the flush so that it runs after vmcs02.EPTP has been set by 1171 - * KVM_REQ_LOAD_MMU_PGD (if nested EPT is enabled) and to avoid 1172 - * redundant flushes further down the nested pipeline. 1173 - * 1174 - * If a TLB flush isn't required due to any of the above, and vpid12 is 1175 - * changing then the new "virtual" VPID (vpid12) will reuse the same 1176 - * "real" VPID (vpid02), and so needs to be flushed. There's no direct 1177 - * mapping between vpid02 and vpid12, vpid02 is per-vCPU and reused for 1178 - * all nested vCPUs. Remember, a flush on VM-Enter does not invalidate 1179 - * guest-physical mappings, so there is no need to sync the nEPT MMU. 1165 + * VPID is enabled and in use by vmcs12. If vpid12 is changing, then 1166 + * emulate a guest TLB flush as KVM does not track vpid12 history nor 1167 + * is the VPID incorporated into the MMU context. I.e. KVM must assume 1168 + * that the new vpid12 has never been used and thus represents a new 1169 + * guest ASID that cannot have entries in the TLB. 1180 1170 */ 1181 - if (!nested_has_guest_tlb_tag(vcpu)) { 1182 - kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); 1183 - } else if (is_vmenter && 1184 - vmcs12->virtual_processor_id != vmx->nested.last_vpid) { 1171 + if (is_vmenter && vmcs12->virtual_processor_id != vmx->nested.last_vpid) { 1185 1172 vmx->nested.last_vpid = vmcs12->virtual_processor_id; 1186 - vpid_sync_context(nested_get_vpid02(vcpu)); 1173 + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); 1174 + return; 1187 1175 } 1176 + 1177 + /* 1178 + * If VPID is enabled, used by vmc12, and vpid12 is not changing but 1179 + * does not have a unique TLB tag (ASID), i.e. EPT is disabled and 1180 + * KVM was unable to allocate a VPID for L2, flush the current context 1181 + * as the effective ASID is common to both L1 and L2. 1182 + */ 1183 + if (!nested_has_guest_tlb_tag(vcpu)) 1184 + kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); 1188 1185 } 1189 1186 1190 1187 static bool is_bitwise_subset(u64 superset, u64 subset, u64 mask) ··· 3341 3344 }; 3342 3345 u32 failed_index; 3343 3346 3344 - if (kvm_check_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu)) 3345 - kvm_vcpu_flush_tlb_current(vcpu); 3347 + kvm_service_local_tlb_flush_requests(vcpu); 3346 3348 3347 3349 evaluate_pending_interrupts = exec_controls_get(vmx) & 3348 3350 (CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING); ··· 4498 4502 (void)nested_get_evmcs_page(vcpu); 4499 4503 } 4500 4504 4501 - /* Service the TLB flush request for L2 before switching to L1. */ 4502 - if (kvm_check_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu)) 4503 - kvm_vcpu_flush_tlb_current(vcpu); 4505 + /* Service pending TLB flush requests for L2 before switching to L1. */ 4506 + kvm_service_local_tlb_flush_requests(vcpu); 4504 4507 4505 4508 /* 4506 4509 * VCPU_EXREG_PDPTR will be clobbered in arch/x86/kvm/vmx/vmx.h between ··· 4852 4857 if (!vmx->nested.cached_vmcs12) 4853 4858 goto out_cached_vmcs12; 4854 4859 4860 + vmx->nested.shadow_vmcs12_cache.gpa = INVALID_GPA; 4855 4861 vmx->nested.cached_shadow_vmcs12 = kzalloc(VMCS12_SIZE, GFP_KERNEL_ACCOUNT); 4856 4862 if (!vmx->nested.cached_shadow_vmcs12) 4857 4863 goto out_cached_shadow_vmcs12; ··· 5285 5289 struct gfn_to_hva_cache *ghc = &vmx->nested.vmcs12_cache; 5286 5290 struct vmcs_hdr hdr; 5287 5291 5288 - if (ghc->gpa != vmptr && 5289 - kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, vmptr, VMCS12_SIZE)) { 5292 + if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, vmptr, VMCS12_SIZE)) { 5290 5293 /* 5291 5294 * Reads from an unbacked page return all 1s, 5292 5295 * which means that the 32 bits located at the
+11 -9
arch/x86/kvm/vmx/posted_intr.c
··· 5 5 #include <asm/cpu.h> 6 6 7 7 #include "lapic.h" 8 + #include "irq.h" 8 9 #include "posted_intr.h" 9 10 #include "trace.h" 10 11 #include "vmx.h" ··· 78 77 pi_set_on(pi_desc); 79 78 } 80 79 80 + static bool vmx_can_use_vtd_pi(struct kvm *kvm) 81 + { 82 + return irqchip_in_kernel(kvm) && enable_apicv && 83 + kvm_arch_has_assigned_device(kvm) && 84 + irq_remapping_cap(IRQ_POSTING_CAP); 85 + } 86 + 81 87 void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu) 82 88 { 83 89 struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu); 84 90 85 - if (!kvm_arch_has_assigned_device(vcpu->kvm) || 86 - !irq_remapping_cap(IRQ_POSTING_CAP) || 87 - !kvm_vcpu_apicv_active(vcpu)) 91 + if (!vmx_can_use_vtd_pi(vcpu->kvm)) 88 92 return; 89 93 90 94 /* Set SN when the vCPU is preempted */ ··· 147 141 struct pi_desc old, new; 148 142 struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu); 149 143 150 - if (!kvm_arch_has_assigned_device(vcpu->kvm) || 151 - !irq_remapping_cap(IRQ_POSTING_CAP) || 152 - !kvm_vcpu_apicv_active(vcpu)) 144 + if (!vmx_can_use_vtd_pi(vcpu->kvm)) 153 145 return 0; 154 146 155 147 WARN_ON(irqs_disabled()); ··· 274 270 struct vcpu_data vcpu_info; 275 271 int idx, ret = 0; 276 272 277 - if (!kvm_arch_has_assigned_device(kvm) || 278 - !irq_remapping_cap(IRQ_POSTING_CAP) || 279 - !kvm_vcpu_apicv_active(kvm->vcpus[0])) 273 + if (!vmx_can_use_vtd_pi(kvm)) 280 274 return 0; 281 275 282 276 idx = srcu_read_lock(&kvm->irq_srcu);
+41 -25
arch/x86/kvm/vmx/vmx.c
··· 2918 2918 } 2919 2919 } 2920 2920 2921 + static inline int vmx_get_current_vpid(struct kvm_vcpu *vcpu) 2922 + { 2923 + if (is_guest_mode(vcpu)) 2924 + return nested_get_vpid02(vcpu); 2925 + return to_vmx(vcpu)->vpid; 2926 + } 2927 + 2921 2928 static void vmx_flush_tlb_current(struct kvm_vcpu *vcpu) 2922 2929 { 2923 2930 struct kvm_mmu *mmu = vcpu->arch.mmu; ··· 2937 2930 if (enable_ept) 2938 2931 ept_sync_context(construct_eptp(vcpu, root_hpa, 2939 2932 mmu->shadow_root_level)); 2940 - else if (!is_guest_mode(vcpu)) 2941 - vpid_sync_context(to_vmx(vcpu)->vpid); 2942 2933 else 2943 - vpid_sync_context(nested_get_vpid02(vcpu)); 2934 + vpid_sync_context(vmx_get_current_vpid(vcpu)); 2944 2935 } 2945 2936 2946 2937 static void vmx_flush_tlb_gva(struct kvm_vcpu *vcpu, gva_t addr) 2947 2938 { 2948 2939 /* 2949 - * vpid_sync_vcpu_addr() is a nop if vmx->vpid==0, see the comment in 2940 + * vpid_sync_vcpu_addr() is a nop if vpid==0, see the comment in 2950 2941 * vmx_flush_tlb_guest() for an explanation of why this is ok. 2951 2942 */ 2952 - vpid_sync_vcpu_addr(to_vmx(vcpu)->vpid, addr); 2943 + vpid_sync_vcpu_addr(vmx_get_current_vpid(vcpu), addr); 2953 2944 } 2954 2945 2955 2946 static void vmx_flush_tlb_guest(struct kvm_vcpu *vcpu) 2956 2947 { 2957 2948 /* 2958 - * vpid_sync_context() is a nop if vmx->vpid==0, e.g. if enable_vpid==0 2959 - * or a vpid couldn't be allocated for this vCPU. VM-Enter and VM-Exit 2960 - * are required to flush GVA->{G,H}PA mappings from the TLB if vpid is 2949 + * vpid_sync_context() is a nop if vpid==0, e.g. if enable_vpid==0 or a 2950 + * vpid couldn't be allocated for this vCPU. VM-Enter and VM-Exit are 2951 + * required to flush GVA->{G,H}PA mappings from the TLB if vpid is 2961 2952 * disabled (VM-Enter with vpid enabled and vpid==0 is disallowed), 2962 2953 * i.e. no explicit INVVPID is necessary. 2963 2954 */ 2964 - vpid_sync_context(to_vmx(vcpu)->vpid); 2955 + vpid_sync_context(vmx_get_current_vpid(vcpu)); 2965 2956 } 2966 2957 2967 2958 void vmx_ept_load_pdptrs(struct kvm_vcpu *vcpu) ··· 6267 6262 { 6268 6263 struct vcpu_vmx *vmx = to_vmx(vcpu); 6269 6264 int max_irr; 6270 - bool max_irr_updated; 6265 + bool got_posted_interrupt; 6271 6266 6272 - if (KVM_BUG_ON(!vcpu->arch.apicv_active, vcpu->kvm)) 6267 + if (KVM_BUG_ON(!enable_apicv, vcpu->kvm)) 6273 6268 return -EIO; 6274 6269 6275 6270 if (pi_test_on(&vmx->pi_desc)) { ··· 6279 6274 * But on x86 this is just a compiler barrier anyway. 6280 6275 */ 6281 6276 smp_mb__after_atomic(); 6282 - max_irr_updated = 6277 + got_posted_interrupt = 6283 6278 kvm_apic_update_irr(vcpu, vmx->pi_desc.pir, &max_irr); 6284 - 6285 - /* 6286 - * If we are running L2 and L1 has a new pending interrupt 6287 - * which can be injected, this may cause a vmexit or it may 6288 - * be injected into L2. Either way, this interrupt will be 6289 - * processed via KVM_REQ_EVENT, not RVI, because we do not use 6290 - * virtual interrupt delivery to inject L1 interrupts into L2. 6291 - */ 6292 - if (is_guest_mode(vcpu) && max_irr_updated) 6293 - kvm_make_request(KVM_REQ_EVENT, vcpu); 6294 6279 } else { 6295 6280 max_irr = kvm_lapic_find_highest_irr(vcpu); 6281 + got_posted_interrupt = false; 6296 6282 } 6297 - vmx_hwapic_irr_update(vcpu, max_irr); 6283 + 6284 + /* 6285 + * Newly recognized interrupts are injected via either virtual interrupt 6286 + * delivery (RVI) or KVM_REQ_EVENT. Virtual interrupt delivery is 6287 + * disabled in two cases: 6288 + * 6289 + * 1) If L2 is running and the vCPU has a new pending interrupt. If L1 6290 + * wants to exit on interrupts, KVM_REQ_EVENT is needed to synthesize a 6291 + * VM-Exit to L1. If L1 doesn't want to exit, the interrupt is injected 6292 + * into L2, but KVM doesn't use virtual interrupt delivery to inject 6293 + * interrupts into L2, and so KVM_REQ_EVENT is again needed. 6294 + * 6295 + * 2) If APICv is disabled for this vCPU, assigned devices may still 6296 + * attempt to post interrupts. The posted interrupt vector will cause 6297 + * a VM-Exit and the subsequent entry will call sync_pir_to_irr. 6298 + */ 6299 + if (!is_guest_mode(vcpu) && kvm_vcpu_apicv_active(vcpu)) 6300 + vmx_set_rvi(max_irr); 6301 + else if (got_posted_interrupt) 6302 + kvm_make_request(KVM_REQ_EVENT, vcpu); 6303 + 6298 6304 return max_irr; 6299 6305 } 6300 6306 ··· 7777 7761 ple_window_shrink = 0; 7778 7762 } 7779 7763 7780 - if (!cpu_has_vmx_apicv()) { 7764 + if (!cpu_has_vmx_apicv()) 7781 7765 enable_apicv = 0; 7766 + if (!enable_apicv) 7782 7767 vmx_x86_ops.sync_pir_to_irr = NULL; 7783 - } 7784 7768 7785 7769 if (cpu_has_vmx_tsc_scaling()) { 7786 7770 kvm_has_tsc_control = true;
+53 -13
arch/x86/kvm/x86.c
··· 3258 3258 static_call(kvm_x86_tlb_flush_guest)(vcpu); 3259 3259 } 3260 3260 3261 + 3262 + static inline void kvm_vcpu_flush_tlb_current(struct kvm_vcpu *vcpu) 3263 + { 3264 + ++vcpu->stat.tlb_flush; 3265 + static_call(kvm_x86_tlb_flush_current)(vcpu); 3266 + } 3267 + 3268 + /* 3269 + * Service "local" TLB flush requests, which are specific to the current MMU 3270 + * context. In addition to the generic event handling in vcpu_enter_guest(), 3271 + * TLB flushes that are targeted at an MMU context also need to be serviced 3272 + * prior before nested VM-Enter/VM-Exit. 3273 + */ 3274 + void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu) 3275 + { 3276 + if (kvm_check_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu)) 3277 + kvm_vcpu_flush_tlb_current(vcpu); 3278 + 3279 + if (kvm_check_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu)) 3280 + kvm_vcpu_flush_tlb_guest(vcpu); 3281 + } 3282 + EXPORT_SYMBOL_GPL(kvm_service_local_tlb_flush_requests); 3283 + 3261 3284 static void record_steal_time(struct kvm_vcpu *vcpu) 3262 3285 { 3263 3286 struct gfn_to_hva_cache *ghc = &vcpu->arch.st.cache; ··· 4156 4133 case KVM_CAP_SGX_ATTRIBUTE: 4157 4134 #endif 4158 4135 case KVM_CAP_VM_COPY_ENC_CONTEXT_FROM: 4136 + case KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM: 4159 4137 case KVM_CAP_SREGS2: 4160 4138 case KVM_CAP_EXIT_ON_EMULATION_FAILURE: 4161 4139 case KVM_CAP_VCPU_ATTRIBUTES: ··· 4472 4448 static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu, 4473 4449 struct kvm_lapic_state *s) 4474 4450 { 4475 - if (vcpu->arch.apicv_active) 4476 - static_call(kvm_x86_sync_pir_to_irr)(vcpu); 4451 + static_call_cond(kvm_x86_sync_pir_to_irr)(vcpu); 4477 4452 4478 4453 return kvm_apic_get_state(vcpu, s); 4479 4454 } ··· 5147 5124 struct kvm_cpuid __user *cpuid_arg = argp; 5148 5125 struct kvm_cpuid cpuid; 5149 5126 5127 + /* 5128 + * KVM does not correctly handle changing guest CPUID after KVM_RUN, as 5129 + * MAXPHYADDR, GBPAGES support, AMD reserved bit behavior, etc.. aren't 5130 + * tracked in kvm_mmu_page_role. As a result, KVM may miss guest page 5131 + * faults due to reusing SPs/SPTEs. In practice no sane VMM mucks with 5132 + * the core vCPU model on the fly, so fail. 5133 + */ 5134 + r = -EINVAL; 5135 + if (vcpu->arch.last_vmentry_cpu != -1) 5136 + goto out; 5137 + 5150 5138 r = -EFAULT; 5151 5139 if (copy_from_user(&cpuid, cpuid_arg, sizeof(cpuid))) 5152 5140 goto out; ··· 5167 5133 case KVM_SET_CPUID2: { 5168 5134 struct kvm_cpuid2 __user *cpuid_arg = argp; 5169 5135 struct kvm_cpuid2 cpuid; 5136 + 5137 + /* 5138 + * KVM_SET_CPUID{,2} after KVM_RUN is forbidded, see the comment in 5139 + * KVM_SET_CPUID case above. 5140 + */ 5141 + r = -EINVAL; 5142 + if (vcpu->arch.last_vmentry_cpu != -1) 5143 + goto out; 5170 5144 5171 5145 r = -EFAULT; 5172 5146 if (copy_from_user(&cpuid, cpuid_arg, sizeof(cpuid))) ··· 9570 9528 if (irqchip_split(vcpu->kvm)) 9571 9529 kvm_scan_ioapic_routes(vcpu, vcpu->arch.ioapic_handled_vectors); 9572 9530 else { 9573 - if (vcpu->arch.apicv_active) 9574 - static_call(kvm_x86_sync_pir_to_irr)(vcpu); 9531 + static_call_cond(kvm_x86_sync_pir_to_irr)(vcpu); 9575 9532 if (ioapic_in_kernel(vcpu->kvm)) 9576 9533 kvm_ioapic_scan_entry(vcpu, vcpu->arch.ioapic_handled_vectors); 9577 9534 } ··· 9689 9648 /* Flushing all ASIDs flushes the current ASID... */ 9690 9649 kvm_clear_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); 9691 9650 } 9692 - if (kvm_check_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu)) 9693 - kvm_vcpu_flush_tlb_current(vcpu); 9694 - if (kvm_check_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu)) 9695 - kvm_vcpu_flush_tlb_guest(vcpu); 9651 + kvm_service_local_tlb_flush_requests(vcpu); 9696 9652 9697 9653 if (kvm_check_request(KVM_REQ_REPORT_TPR_ACCESS, vcpu)) { 9698 9654 vcpu->run->exit_reason = KVM_EXIT_TPR_ACCESS; ··· 9840 9802 9841 9803 /* 9842 9804 * This handles the case where a posted interrupt was 9843 - * notified with kvm_vcpu_kick. 9805 + * notified with kvm_vcpu_kick. Assigned devices can 9806 + * use the POSTED_INTR_VECTOR even if APICv is disabled, 9807 + * so do it even if APICv is disabled on this vCPU. 9844 9808 */ 9845 - if (kvm_lapic_enabled(vcpu) && vcpu->arch.apicv_active) 9846 - static_call(kvm_x86_sync_pir_to_irr)(vcpu); 9809 + if (kvm_lapic_enabled(vcpu)) 9810 + static_call_cond(kvm_x86_sync_pir_to_irr)(vcpu); 9847 9811 9848 9812 if (kvm_vcpu_exit_request(vcpu)) { 9849 9813 vcpu->mode = OUTSIDE_GUEST_MODE; ··· 9889 9849 if (likely(exit_fastpath != EXIT_FASTPATH_REENTER_GUEST)) 9890 9850 break; 9891 9851 9892 - if (vcpu->arch.apicv_active) 9893 - static_call(kvm_x86_sync_pir_to_irr)(vcpu); 9852 + if (kvm_lapic_enabled(vcpu)) 9853 + static_call_cond(kvm_x86_sync_pir_to_irr)(vcpu); 9894 9854 9895 9855 if (unlikely(kvm_vcpu_exit_request(vcpu))) { 9896 9856 exit_fastpath = EXIT_FASTPATH_EXIT_HANDLED;
+1 -6
arch/x86/kvm/x86.h
··· 103 103 104 104 #define MSR_IA32_CR_PAT_DEFAULT 0x0007040600070406ULL 105 105 106 + void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu); 106 107 int kvm_check_nested_events(struct kvm_vcpu *vcpu); 107 108 108 109 static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu) ··· 184 183 static inline bool mmu_is_nested(struct kvm_vcpu *vcpu) 185 184 { 186 185 return vcpu->arch.walk_mmu == &vcpu->arch.nested_mmu; 187 - } 188 - 189 - static inline void kvm_vcpu_flush_tlb_current(struct kvm_vcpu *vcpu) 190 - { 191 - ++vcpu->stat.tlb_flush; 192 - static_call(kvm_x86_tlb_flush_current)(vcpu); 193 186 } 194 187 195 188 static inline int is_pae(struct kvm_vcpu *vcpu)
+2 -1
block/blk-mq.c
··· 860 860 if (iob->need_ts) 861 861 __blk_mq_end_request_acct(rq, now); 862 862 863 + rq_qos_done(rq->q, rq); 864 + 863 865 WRITE_ONCE(rq->state, MQ_RQ_IDLE); 864 866 if (!refcount_dec_and_test(&rq->ref)) 865 867 continue; 866 868 867 869 blk_crypto_free_request(rq); 868 870 blk_pm_mark_last_busy(rq); 869 - rq_qos_done(rq->q, rq); 870 871 871 872 if (nr_tags == TAG_COMP_BATCH || cur_hctx != rq->mq_hctx) { 872 873 if (cur_hctx)
+1 -2
drivers/block/virtio_blk.c
··· 316 316 struct request *req = bd->rq; 317 317 struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); 318 318 unsigned long flags; 319 - unsigned int num; 319 + int num; 320 320 int qid = hctx->queue_num; 321 321 bool notify = false; 322 322 blk_status_t status; ··· 1049 1049 .feature_table_size = ARRAY_SIZE(features), 1050 1050 .feature_table_legacy = features_legacy, 1051 1051 .feature_table_size_legacy = ARRAY_SIZE(features_legacy), 1052 - .suppress_used_validation = true, 1053 1052 .driver.name = KBUILD_MODNAME, 1054 1053 .driver.owner = THIS_MODULE, 1055 1054 .id_table = id_table,
+2
drivers/block/zram/zram_drv.c
··· 1853 1853 .owner = THIS_MODULE 1854 1854 }; 1855 1855 1856 + #ifdef CONFIG_ZRAM_WRITEBACK 1856 1857 static const struct block_device_operations zram_wb_devops = { 1857 1858 .open = zram_open, 1858 1859 .submit_bio = zram_submit_bio, 1859 1860 .swap_slot_free_notify = zram_slot_free_notify, 1860 1861 .owner = THIS_MODULE 1861 1862 }; 1863 + #endif 1862 1864 1863 1865 static DEVICE_ATTR_WO(compact); 1864 1866 static DEVICE_ATTR_RW(disksize);
+33 -8
drivers/char/ipmi/ipmi_msghandler.c
··· 191 191 struct work_struct remove_work; 192 192 }; 193 193 194 + static struct workqueue_struct *remove_work_wq; 195 + 194 196 static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user, int *index) 195 197 __acquires(user->release_barrier) 196 198 { ··· 1299 1297 struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount); 1300 1298 1301 1299 /* SRCU cleanup must happen in task context. */ 1302 - schedule_work(&user->remove_work); 1300 + queue_work(remove_work_wq, &user->remove_work); 1303 1301 } 1304 1302 1305 1303 static void _ipmi_destroy_user(struct ipmi_user *user) ··· 3920 3918 /* We didn't find a user, deliver an error response. */ 3921 3919 ipmi_inc_stat(intf, unhandled_commands); 3922 3920 3923 - msg->data[0] = ((netfn + 1) << 2) | (msg->rsp[4] & 0x3); 3924 - msg->data[1] = msg->rsp[2]; 3925 - msg->data[2] = msg->rsp[4] & ~0x3; 3921 + msg->data[0] = (netfn + 1) << 2; 3922 + msg->data[0] |= msg->rsp[2] & 0x3; /* rqLUN */ 3923 + msg->data[1] = msg->rsp[1]; /* Addr */ 3924 + msg->data[2] = msg->rsp[2] & ~0x3; /* rqSeq */ 3925 + msg->data[2] |= msg->rsp[0] & 0x3; /* rsLUN */ 3926 3926 msg->data[3] = cmd; 3927 3927 msg->data[4] = IPMI_INVALID_CMD_COMPLETION_CODE; 3928 3928 msg->data_size = 5; ··· 4459 4455 msg->rsp[2] = IPMI_ERR_UNSPECIFIED; 4460 4456 msg->rsp_size = 3; 4461 4457 } else if (msg->type == IPMI_SMI_MSG_TYPE_IPMB_DIRECT) { 4462 - /* commands must have at least 3 bytes, responses 4. */ 4463 - if (is_cmd && (msg->rsp_size < 3)) { 4458 + /* commands must have at least 4 bytes, responses 5. */ 4459 + if (is_cmd && (msg->rsp_size < 4)) { 4464 4460 ipmi_inc_stat(intf, invalid_commands); 4465 4461 goto out; 4466 4462 } 4467 - if (!is_cmd && (msg->rsp_size < 4)) 4468 - goto return_unspecified; 4463 + if (!is_cmd && (msg->rsp_size < 5)) { 4464 + ipmi_inc_stat(intf, invalid_ipmb_responses); 4465 + /* Construct a valid error response. */ 4466 + msg->rsp[0] = msg->data[0] & 0xfc; /* NetFN */ 4467 + msg->rsp[0] |= (1 << 2); /* Make it a response */ 4468 + msg->rsp[0] |= msg->data[2] & 3; /* rqLUN */ 4469 + msg->rsp[1] = msg->data[1]; /* Addr */ 4470 + msg->rsp[2] = msg->data[2] & 0xfc; /* rqSeq */ 4471 + msg->rsp[2] |= msg->data[0] & 0x3; /* rsLUN */ 4472 + msg->rsp[3] = msg->data[3]; /* Cmd */ 4473 + msg->rsp[4] = IPMI_ERR_UNSPECIFIED; 4474 + msg->rsp_size = 5; 4475 + } 4469 4476 } else if ((msg->data_size >= 2) 4470 4477 && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2)) 4471 4478 && (msg->data[1] == IPMI_SEND_MSG_CMD) ··· 5046 5031 if (rv) { 5047 5032 rv->done = free_smi_msg; 5048 5033 rv->user_data = NULL; 5034 + rv->type = IPMI_SMI_MSG_TYPE_NORMAL; 5049 5035 atomic_inc(&smi_msg_inuse_count); 5050 5036 } 5051 5037 return rv; ··· 5399 5383 5400 5384 atomic_notifier_chain_register(&panic_notifier_list, &panic_block); 5401 5385 5386 + remove_work_wq = create_singlethread_workqueue("ipmi-msghandler-remove-wq"); 5387 + if (!remove_work_wq) { 5388 + pr_err("unable to create ipmi-msghandler-remove-wq workqueue"); 5389 + rv = -ENOMEM; 5390 + goto out; 5391 + } 5392 + 5402 5393 initialized = true; 5403 5394 5404 5395 out: ··· 5431 5408 int count; 5432 5409 5433 5410 if (initialized) { 5411 + destroy_workqueue(remove_work_wq); 5412 + 5434 5413 atomic_notifier_chain_unregister(&panic_notifier_list, 5435 5414 &panic_block); 5436 5415
+3 -3
drivers/iommu/amd/iommu_v2.c
··· 929 929 { 930 930 int ret; 931 931 932 - pr_info("AMD IOMMUv2 driver by Joerg Roedel <jroedel@suse.de>\n"); 933 - 934 932 if (!amd_iommu_v2_supported()) { 935 - pr_info("AMD IOMMUv2 functionality not available on this system\n"); 933 + pr_info("AMD IOMMUv2 functionality not available on this system - This is not a bug.\n"); 936 934 /* 937 935 * Load anyway to provide the symbols to other modules 938 936 * which may use AMD IOMMUv2 optionally. ··· 944 946 goto out; 945 947 946 948 amd_iommu_register_ppr_notifier(&ppr_nb); 949 + 950 + pr_info("AMD IOMMUv2 loaded and initialized\n"); 947 951 948 952 return 0; 949 953
+3 -2
drivers/iommu/intel/cap_audit.c
··· 144 144 { 145 145 struct dmar_drhd_unit *d; 146 146 struct intel_iommu *i; 147 + int rc = 0; 147 148 148 149 rcu_read_lock(); 149 150 if (list_empty(&dmar_drhd_units)) ··· 170 169 */ 171 170 if (intel_cap_smts_sanity() && 172 171 !intel_cap_flts_sanity() && !intel_cap_slts_sanity()) 173 - return -EOPNOTSUPP; 172 + rc = -EOPNOTSUPP; 174 173 175 174 out: 176 175 rcu_read_unlock(); 177 - return 0; 176 + return rc; 178 177 } 179 178 180 179 int intel_cap_audit(enum cap_audit_type type, struct intel_iommu *iommu)
+2 -4
drivers/iommu/intel/iommu.c
··· 1339 1339 pte = &pte[pfn_level_offset(pfn, level)]; 1340 1340 1341 1341 do { 1342 - unsigned long level_pfn; 1342 + unsigned long level_pfn = pfn & level_mask(level); 1343 1343 1344 1344 if (!dma_pte_present(pte)) 1345 1345 goto next; 1346 - 1347 - level_pfn = pfn & level_mask(level); 1348 1346 1349 1347 /* If range covers entire pagetable, free it */ 1350 1348 if (start_pfn <= level_pfn && ··· 1364 1366 freelist); 1365 1367 } 1366 1368 next: 1367 - pfn += level_size(level); 1369 + pfn = level_pfn + level_size(level); 1368 1370 } while (!first_pte_in_page(++pte) && pfn <= last_pfn); 1369 1371 1370 1372 if (first_pte)
+2 -2
drivers/iommu/rockchip-iommu.c
··· 200 200 #define DTE_HI_MASK2 GENMASK(7, 4) 201 201 #define DTE_HI_SHIFT1 24 /* shift bit 8 to bit 32 */ 202 202 #define DTE_HI_SHIFT2 32 /* shift bit 4 to bit 36 */ 203 - #define PAGE_DESC_HI_MASK1 GENMASK_ULL(39, 36) 204 - #define PAGE_DESC_HI_MASK2 GENMASK_ULL(35, 32) 203 + #define PAGE_DESC_HI_MASK1 GENMASK_ULL(35, 32) 204 + #define PAGE_DESC_HI_MASK2 GENMASK_ULL(39, 36) 205 205 206 206 static inline phys_addr_t rk_dte_pt_address_v2(u32 dte) 207 207 {
+1 -3
drivers/net/Kconfig
··· 567 567 config VMXNET3 568 568 tristate "VMware VMXNET3 ethernet driver" 569 569 depends on PCI && INET 570 - depends on !(PAGE_SIZE_64KB || ARM64_64K_PAGES || \ 571 - IA64_PAGE_SIZE_64KB || PARISC_PAGE_SIZE_64KB || \ 572 - PPC_64K_PAGES) 570 + depends on PAGE_SIZE_LESS_THAN_64KB 573 571 help 574 572 This driver supports VMware's vmxnet3 virtual ethernet NIC. 575 573 To compile this driver as a module, choose M here: the
+14
drivers/net/dsa/b53/b53_spi.c
··· 349 349 }; 350 350 MODULE_DEVICE_TABLE(of, b53_spi_of_match); 351 351 352 + static const struct spi_device_id b53_spi_ids[] = { 353 + { .name = "bcm5325" }, 354 + { .name = "bcm5365" }, 355 + { .name = "bcm5395" }, 356 + { .name = "bcm5397" }, 357 + { .name = "bcm5398" }, 358 + { .name = "bcm53115" }, 359 + { .name = "bcm53125" }, 360 + { .name = "bcm53128" }, 361 + { /* sentinel */ } 362 + }; 363 + MODULE_DEVICE_TABLE(spi, b53_spi_ids); 364 + 352 365 static struct spi_driver b53_spi_driver = { 353 366 .driver = { 354 367 .name = "b53-switch", ··· 370 357 .probe = b53_spi_probe, 371 358 .remove = b53_spi_remove, 372 359 .shutdown = b53_spi_shutdown, 360 + .id_table = b53_spi_ids, 373 361 }; 374 362 375 363 module_spi_driver(b53_spi_driver);
+220 -32
drivers/net/dsa/mv88e6xxx/serdes.c
··· 50 50 } 51 51 52 52 static int mv88e6xxx_serdes_pcs_get_state(struct mv88e6xxx_chip *chip, 53 - u16 status, u16 lpa, 53 + u16 ctrl, u16 status, u16 lpa, 54 54 struct phylink_link_state *state) 55 55 { 56 + state->link = !!(status & MV88E6390_SGMII_PHY_STATUS_LINK); 57 + 56 58 if (status & MV88E6390_SGMII_PHY_STATUS_SPD_DPL_VALID) { 57 - state->link = !!(status & MV88E6390_SGMII_PHY_STATUS_LINK); 59 + /* The Spped and Duplex Resolved register is 1 if AN is enabled 60 + * and complete, or if AN is disabled. So with disabled AN we 61 + * still get here on link up. But we want to set an_complete 62 + * only if AN was enabled, thus we look at BMCR_ANENABLE. 63 + * (According to 802.3-2008 section 22.2.4.2.10, we should be 64 + * able to get this same value from BMSR_ANEGCAPABLE, but tests 65 + * show that these Marvell PHYs don't conform to this part of 66 + * the specificaion - BMSR_ANEGCAPABLE is simply always 1.) 67 + */ 68 + state->an_complete = !!(ctrl & BMCR_ANENABLE); 58 69 state->duplex = status & 59 70 MV88E6390_SGMII_PHY_STATUS_DUPLEX_FULL ? 60 71 DUPLEX_FULL : DUPLEX_HALF; ··· 92 81 dev_err(chip->dev, "invalid PHY speed\n"); 93 82 return -EINVAL; 94 83 } 84 + } else if (state->link && 85 + state->interface != PHY_INTERFACE_MODE_SGMII) { 86 + /* If Speed and Duplex Resolved register is 0 and link is up, it 87 + * means that AN was enabled, but link partner had it disabled 88 + * and the PHY invoked the Auto-Negotiation Bypass feature and 89 + * linked anyway. 90 + */ 91 + state->duplex = DUPLEX_FULL; 92 + if (state->interface == PHY_INTERFACE_MODE_2500BASEX) 93 + state->speed = SPEED_2500; 94 + else 95 + state->speed = SPEED_1000; 95 96 } else { 96 97 state->link = false; 97 98 } ··· 191 168 int mv88e6352_serdes_pcs_get_state(struct mv88e6xxx_chip *chip, int port, 192 169 int lane, struct phylink_link_state *state) 193 170 { 194 - u16 lpa, status; 171 + u16 lpa, status, ctrl; 195 172 int err; 173 + 174 + err = mv88e6352_serdes_read(chip, MII_BMCR, &ctrl); 175 + if (err) { 176 + dev_err(chip->dev, "can't read Serdes PHY control: %d\n", err); 177 + return err; 178 + } 196 179 197 180 err = mv88e6352_serdes_read(chip, 0x11, &status); 198 181 if (err) { ··· 212 183 return err; 213 184 } 214 185 215 - return mv88e6xxx_serdes_pcs_get_state(chip, status, lpa, state); 186 + return mv88e6xxx_serdes_pcs_get_state(chip, ctrl, status, lpa, state); 216 187 } 217 188 218 189 int mv88e6352_serdes_pcs_an_restart(struct mv88e6xxx_chip *chip, int port, ··· 912 883 static int mv88e6390_serdes_pcs_get_state_sgmii(struct mv88e6xxx_chip *chip, 913 884 int port, int lane, struct phylink_link_state *state) 914 885 { 915 - u16 lpa, status; 886 + u16 lpa, status, ctrl; 916 887 int err; 888 + 889 + err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS, 890 + MV88E6390_SGMII_BMCR, &ctrl); 891 + if (err) { 892 + dev_err(chip->dev, "can't read Serdes PHY control: %d\n", err); 893 + return err; 894 + } 917 895 918 896 err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS, 919 897 MV88E6390_SGMII_PHY_STATUS, &status); ··· 936 900 return err; 937 901 } 938 902 939 - return mv88e6xxx_serdes_pcs_get_state(chip, status, lpa, state); 903 + return mv88e6xxx_serdes_pcs_get_state(chip, ctrl, status, lpa, state); 940 904 } 941 905 942 906 static int mv88e6390_serdes_pcs_get_state_10g(struct mv88e6xxx_chip *chip, ··· 1307 1271 } 1308 1272 } 1309 1273 1310 - static int mv88e6393x_serdes_port_errata(struct mv88e6xxx_chip *chip, int lane) 1274 + static int mv88e6393x_serdes_power_lane(struct mv88e6xxx_chip *chip, int lane, 1275 + bool on) 1311 1276 { 1312 - u16 reg, pcs; 1277 + u16 reg; 1278 + int err; 1279 + 1280 + err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS, 1281 + MV88E6393X_SERDES_CTRL1, &reg); 1282 + if (err) 1283 + return err; 1284 + 1285 + if (on) 1286 + reg &= ~(MV88E6393X_SERDES_CTRL1_TX_PDOWN | 1287 + MV88E6393X_SERDES_CTRL1_RX_PDOWN); 1288 + else 1289 + reg |= MV88E6393X_SERDES_CTRL1_TX_PDOWN | 1290 + MV88E6393X_SERDES_CTRL1_RX_PDOWN; 1291 + 1292 + return mv88e6390_serdes_write(chip, lane, MDIO_MMD_PHYXS, 1293 + MV88E6393X_SERDES_CTRL1, reg); 1294 + } 1295 + 1296 + static int mv88e6393x_serdes_erratum_4_6(struct mv88e6xxx_chip *chip, int lane) 1297 + { 1298 + u16 reg; 1313 1299 int err; 1314 1300 1315 1301 /* mv88e6393x family errata 4.6: ··· 1342 1284 * It seems that after this workaround the SERDES is automatically 1343 1285 * powered up (the bit is cleared), so power it down. 1344 1286 */ 1345 - if (lane == MV88E6393X_PORT0_LANE || lane == MV88E6393X_PORT9_LANE || 1346 - lane == MV88E6393X_PORT10_LANE) { 1347 - err = mv88e6390_serdes_read(chip, lane, 1348 - MDIO_MMD_PHYXS, 1349 - MV88E6393X_SERDES_POC, &reg); 1350 - if (err) 1351 - return err; 1287 + err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS, 1288 + MV88E6393X_SERDES_POC, &reg); 1289 + if (err) 1290 + return err; 1352 1291 1353 - reg &= ~MV88E6393X_SERDES_POC_PDOWN; 1354 - reg |= MV88E6393X_SERDES_POC_RESET; 1292 + reg &= ~MV88E6393X_SERDES_POC_PDOWN; 1293 + reg |= MV88E6393X_SERDES_POC_RESET; 1355 1294 1356 - err = mv88e6390_serdes_write(chip, lane, MDIO_MMD_PHYXS, 1357 - MV88E6393X_SERDES_POC, reg); 1358 - if (err) 1359 - return err; 1295 + err = mv88e6390_serdes_write(chip, lane, MDIO_MMD_PHYXS, 1296 + MV88E6393X_SERDES_POC, reg); 1297 + if (err) 1298 + return err; 1360 1299 1361 - err = mv88e6390_serdes_power_sgmii(chip, lane, false); 1362 - if (err) 1363 - return err; 1364 - } 1300 + err = mv88e6390_serdes_power_sgmii(chip, lane, false); 1301 + if (err) 1302 + return err; 1303 + 1304 + return mv88e6393x_serdes_power_lane(chip, lane, false); 1305 + } 1306 + 1307 + int mv88e6393x_serdes_setup_errata(struct mv88e6xxx_chip *chip) 1308 + { 1309 + int err; 1310 + 1311 + err = mv88e6393x_serdes_erratum_4_6(chip, MV88E6393X_PORT0_LANE); 1312 + if (err) 1313 + return err; 1314 + 1315 + err = mv88e6393x_serdes_erratum_4_6(chip, MV88E6393X_PORT9_LANE); 1316 + if (err) 1317 + return err; 1318 + 1319 + return mv88e6393x_serdes_erratum_4_6(chip, MV88E6393X_PORT10_LANE); 1320 + } 1321 + 1322 + static int mv88e6393x_serdes_erratum_4_8(struct mv88e6xxx_chip *chip, int lane) 1323 + { 1324 + u16 reg, pcs; 1325 + int err; 1365 1326 1366 1327 /* mv88e6393x family errata 4.8: 1367 1328 * When a SERDES port is operating in 1000BASE-X or SGMII mode link may ··· 1411 1334 MV88E6393X_ERRATA_4_8_REG, reg); 1412 1335 } 1413 1336 1414 - int mv88e6393x_serdes_setup_errata(struct mv88e6xxx_chip *chip) 1337 + static int mv88e6393x_serdes_erratum_5_2(struct mv88e6xxx_chip *chip, int lane, 1338 + u8 cmode) 1415 1339 { 1340 + static const struct { 1341 + u16 dev, reg, val, mask; 1342 + } fixes[] = { 1343 + { MDIO_MMD_VEND1, 0x8093, 0xcb5a, 0xffff }, 1344 + { MDIO_MMD_VEND1, 0x8171, 0x7088, 0xffff }, 1345 + { MDIO_MMD_VEND1, 0x80c9, 0x311a, 0xffff }, 1346 + { MDIO_MMD_VEND1, 0x80a2, 0x8000, 0xff7f }, 1347 + { MDIO_MMD_VEND1, 0x80a9, 0x0000, 0xfff0 }, 1348 + { MDIO_MMD_VEND1, 0x80a3, 0x0000, 0xf8ff }, 1349 + { MDIO_MMD_PHYXS, MV88E6393X_SERDES_POC, 1350 + MV88E6393X_SERDES_POC_RESET, MV88E6393X_SERDES_POC_RESET }, 1351 + }; 1352 + int err, i; 1353 + u16 reg; 1354 + 1355 + /* mv88e6393x family errata 5.2: 1356 + * For optimal signal integrity the following sequence should be applied 1357 + * to SERDES operating in 10G mode. These registers only apply to 10G 1358 + * operation and have no effect on other speeds. 1359 + */ 1360 + if (cmode != MV88E6393X_PORT_STS_CMODE_10GBASER) 1361 + return 0; 1362 + 1363 + for (i = 0; i < ARRAY_SIZE(fixes); ++i) { 1364 + err = mv88e6390_serdes_read(chip, lane, fixes[i].dev, 1365 + fixes[i].reg, &reg); 1366 + if (err) 1367 + return err; 1368 + 1369 + reg &= ~fixes[i].mask; 1370 + reg |= fixes[i].val; 1371 + 1372 + err = mv88e6390_serdes_write(chip, lane, fixes[i].dev, 1373 + fixes[i].reg, reg); 1374 + if (err) 1375 + return err; 1376 + } 1377 + 1378 + return 0; 1379 + } 1380 + 1381 + static int mv88e6393x_serdes_fix_2500basex_an(struct mv88e6xxx_chip *chip, 1382 + int lane, u8 cmode, bool on) 1383 + { 1384 + u16 reg; 1416 1385 int err; 1417 1386 1418 - err = mv88e6393x_serdes_port_errata(chip, MV88E6393X_PORT0_LANE); 1387 + if (cmode != MV88E6XXX_PORT_STS_CMODE_2500BASEX) 1388 + return 0; 1389 + 1390 + /* Inband AN is broken on Amethyst in 2500base-x mode when set by 1391 + * standard mechanism (via cmode). 1392 + * We can get around this by configuring the PCS mode to 1000base-x 1393 + * and then writing value 0x58 to register 1e.8000. (This must be done 1394 + * while SerDes receiver and transmitter are disabled, which is, when 1395 + * this function is called.) 1396 + * It seem that when we do this configuration to 2500base-x mode (by 1397 + * changing PCS mode to 1000base-x and frequency to 3.125 GHz from 1398 + * 1.25 GHz) and then configure to sgmii or 1000base-x, the device 1399 + * thinks that it already has SerDes at 1.25 GHz and does not change 1400 + * the 1e.8000 register, leaving SerDes at 3.125 GHz. 1401 + * To avoid this, change PCS mode back to 2500base-x when disabling 1402 + * SerDes from 2500base-x mode. 1403 + */ 1404 + err = mv88e6390_serdes_read(chip, lane, MDIO_MMD_PHYXS, 1405 + MV88E6393X_SERDES_POC, &reg); 1419 1406 if (err) 1420 1407 return err; 1421 1408 1422 - err = mv88e6393x_serdes_port_errata(chip, MV88E6393X_PORT9_LANE); 1409 + reg &= ~(MV88E6393X_SERDES_POC_PCS_MASK | MV88E6393X_SERDES_POC_AN); 1410 + if (on) 1411 + reg |= MV88E6393X_SERDES_POC_PCS_1000BASEX | 1412 + MV88E6393X_SERDES_POC_AN; 1413 + else 1414 + reg |= MV88E6393X_SERDES_POC_PCS_2500BASEX; 1415 + reg |= MV88E6393X_SERDES_POC_RESET; 1416 + 1417 + err = mv88e6390_serdes_write(chip, lane, MDIO_MMD_PHYXS, 1418 + MV88E6393X_SERDES_POC, reg); 1423 1419 if (err) 1424 1420 return err; 1425 1421 1426 - return mv88e6393x_serdes_port_errata(chip, MV88E6393X_PORT10_LANE); 1422 + err = mv88e6390_serdes_write(chip, lane, MDIO_MMD_VEND1, 0x8000, 0x58); 1423 + if (err) 1424 + return err; 1425 + 1426 + return 0; 1427 1427 } 1428 1428 1429 1429 int mv88e6393x_serdes_power(struct mv88e6xxx_chip *chip, int port, int lane, 1430 1430 bool on) 1431 1431 { 1432 1432 u8 cmode = chip->ports[port].cmode; 1433 + int err; 1433 1434 1434 1435 if (port != 0 && port != 9 && port != 10) 1435 1436 return -EOPNOTSUPP; 1437 + 1438 + if (on) { 1439 + err = mv88e6393x_serdes_erratum_4_8(chip, lane); 1440 + if (err) 1441 + return err; 1442 + 1443 + err = mv88e6393x_serdes_erratum_5_2(chip, lane, cmode); 1444 + if (err) 1445 + return err; 1446 + 1447 + err = mv88e6393x_serdes_fix_2500basex_an(chip, lane, cmode, 1448 + true); 1449 + if (err) 1450 + return err; 1451 + 1452 + err = mv88e6393x_serdes_power_lane(chip, lane, true); 1453 + if (err) 1454 + return err; 1455 + } 1436 1456 1437 1457 switch (cmode) { 1438 1458 case MV88E6XXX_PORT_STS_CMODE_SGMII: 1439 1459 case MV88E6XXX_PORT_STS_CMODE_1000BASEX: 1440 1460 case MV88E6XXX_PORT_STS_CMODE_2500BASEX: 1441 - return mv88e6390_serdes_power_sgmii(chip, lane, on); 1461 + err = mv88e6390_serdes_power_sgmii(chip, lane, on); 1462 + break; 1442 1463 case MV88E6393X_PORT_STS_CMODE_5GBASER: 1443 1464 case MV88E6393X_PORT_STS_CMODE_10GBASER: 1444 - return mv88e6390_serdes_power_10g(chip, lane, on); 1465 + err = mv88e6390_serdes_power_10g(chip, lane, on); 1466 + break; 1445 1467 } 1446 1468 1447 - return 0; 1469 + if (err) 1470 + return err; 1471 + 1472 + if (!on) { 1473 + err = mv88e6393x_serdes_power_lane(chip, lane, false); 1474 + if (err) 1475 + return err; 1476 + 1477 + err = mv88e6393x_serdes_fix_2500basex_an(chip, lane, cmode, 1478 + false); 1479 + } 1480 + 1481 + return err; 1448 1482 }
+4
drivers/net/dsa/mv88e6xxx/serdes.h
··· 93 93 #define MV88E6393X_SERDES_POC_PCS_MASK 0x0007 94 94 #define MV88E6393X_SERDES_POC_RESET BIT(15) 95 95 #define MV88E6393X_SERDES_POC_PDOWN BIT(5) 96 + #define MV88E6393X_SERDES_POC_AN BIT(3) 97 + #define MV88E6393X_SERDES_CTRL1 0xf003 98 + #define MV88E6393X_SERDES_CTRL1_TX_PDOWN BIT(9) 99 + #define MV88E6393X_SERDES_CTRL1_RX_PDOWN BIT(8) 96 100 97 101 #define MV88E6393X_ERRATA_4_8_REG 0xF074 98 102 #define MV88E6393X_ERRATA_4_8_BIT BIT(14)
+8 -1
drivers/net/dsa/rtl8365mb.c
··· 107 107 #define RTL8365MB_LEARN_LIMIT_MAX_8365MB_VC 2112 108 108 109 109 /* Family-specific data and limits */ 110 + #define RTL8365MB_PHYADDRMAX 7 110 111 #define RTL8365MB_NUM_PHYREGS 32 111 112 #define RTL8365MB_PHYREGMAX (RTL8365MB_NUM_PHYREGS - 1) 112 113 #define RTL8365MB_MAX_NUM_PORTS (RTL8365MB_CPU_PORT_NUM_8365MB_VC + 1) ··· 177 176 #define RTL8365MB_INDIRECT_ACCESS_STATUS_REG 0x1F01 178 177 #define RTL8365MB_INDIRECT_ACCESS_ADDRESS_REG 0x1F02 179 178 #define RTL8365MB_INDIRECT_ACCESS_ADDRESS_OCPADR_5_1_MASK GENMASK(4, 0) 180 - #define RTL8365MB_INDIRECT_ACCESS_ADDRESS_PHYNUM_MASK GENMASK(6, 5) 179 + #define RTL8365MB_INDIRECT_ACCESS_ADDRESS_PHYNUM_MASK GENMASK(7, 5) 181 180 #define RTL8365MB_INDIRECT_ACCESS_ADDRESS_OCPADR_9_6_MASK GENMASK(11, 8) 182 181 #define RTL8365MB_PHY_BASE 0x2000 183 182 #define RTL8365MB_INDIRECT_ACCESS_WRITE_DATA_REG 0x1F03 ··· 680 679 u16 val; 681 680 int ret; 682 681 682 + if (phy > RTL8365MB_PHYADDRMAX) 683 + return -EINVAL; 684 + 683 685 if (regnum > RTL8365MB_PHYREGMAX) 684 686 return -EINVAL; 685 687 ··· 707 703 { 708 704 u32 ocp_addr; 709 705 int ret; 706 + 707 + if (phy > RTL8365MB_PHYADDRMAX) 708 + return -EINVAL; 710 709 711 710 if (regnum > RTL8365MB_PHYREGMAX) 712 711 return -EINVAL;
+14 -13
drivers/net/ethernet/aquantia/atlantic/aq_common.h
··· 40 40 41 41 #define AQ_DEVICE_ID_AQC113DEV 0x00C0 42 42 #define AQ_DEVICE_ID_AQC113CS 0x94C0 43 + #define AQ_DEVICE_ID_AQC113CA 0x34C0 43 44 #define AQ_DEVICE_ID_AQC114CS 0x93C0 44 45 #define AQ_DEVICE_ID_AQC113 0x04C0 45 46 #define AQ_DEVICE_ID_AQC113C 0x14C0 46 47 #define AQ_DEVICE_ID_AQC115C 0x12C0 48 + #define AQ_DEVICE_ID_AQC116C 0x11C0 47 49 48 50 #define HW_ATL_NIC_NAME "Marvell (aQuantia) AQtion 10Gbit Network Adapter" 49 51 ··· 55 53 56 54 #define AQ_NIC_RATE_10G BIT(0) 57 55 #define AQ_NIC_RATE_5G BIT(1) 58 - #define AQ_NIC_RATE_5GSR BIT(2) 59 - #define AQ_NIC_RATE_2G5 BIT(3) 60 - #define AQ_NIC_RATE_1G BIT(4) 61 - #define AQ_NIC_RATE_100M BIT(5) 62 - #define AQ_NIC_RATE_10M BIT(6) 63 - #define AQ_NIC_RATE_1G_HALF BIT(7) 64 - #define AQ_NIC_RATE_100M_HALF BIT(8) 65 - #define AQ_NIC_RATE_10M_HALF BIT(9) 56 + #define AQ_NIC_RATE_2G5 BIT(2) 57 + #define AQ_NIC_RATE_1G BIT(3) 58 + #define AQ_NIC_RATE_100M BIT(4) 59 + #define AQ_NIC_RATE_10M BIT(5) 60 + #define AQ_NIC_RATE_1G_HALF BIT(6) 61 + #define AQ_NIC_RATE_100M_HALF BIT(7) 62 + #define AQ_NIC_RATE_10M_HALF BIT(8) 66 63 67 - #define AQ_NIC_RATE_EEE_10G BIT(10) 68 - #define AQ_NIC_RATE_EEE_5G BIT(11) 69 - #define AQ_NIC_RATE_EEE_2G5 BIT(12) 70 - #define AQ_NIC_RATE_EEE_1G BIT(13) 71 - #define AQ_NIC_RATE_EEE_100M BIT(14) 64 + #define AQ_NIC_RATE_EEE_10G BIT(9) 65 + #define AQ_NIC_RATE_EEE_5G BIT(10) 66 + #define AQ_NIC_RATE_EEE_2G5 BIT(11) 67 + #define AQ_NIC_RATE_EEE_1G BIT(12) 68 + #define AQ_NIC_RATE_EEE_100M BIT(13) 72 69 #define AQ_NIC_RATE_EEE_MSK (AQ_NIC_RATE_EEE_10G |\ 73 70 AQ_NIC_RATE_EEE_5G |\ 74 71 AQ_NIC_RATE_EEE_2G5 |\
+2
drivers/net/ethernet/aquantia/atlantic/aq_hw.h
··· 80 80 }; 81 81 82 82 struct aq_stats_s { 83 + u64 brc; 84 + u64 btc; 83 85 u64 uprc; 84 86 u64 mprc; 85 87 u64 bprc;
+22 -12
drivers/net/ethernet/aquantia/atlantic/aq_nic.c
··· 316 316 aq_macsec_init(self); 317 317 #endif 318 318 319 - mutex_lock(&self->fwreq_mutex); 320 - err = self->aq_fw_ops->get_mac_permanent(self->aq_hw, addr); 321 - mutex_unlock(&self->fwreq_mutex); 322 - if (err) 323 - goto err_exit; 319 + if (platform_get_ethdev_address(&self->pdev->dev, self->ndev) != 0) { 320 + // If DT has none or an invalid one, ask device for MAC address 321 + mutex_lock(&self->fwreq_mutex); 322 + err = self->aq_fw_ops->get_mac_permanent(self->aq_hw, addr); 323 + mutex_unlock(&self->fwreq_mutex); 324 324 325 - eth_hw_addr_set(self->ndev, addr); 325 + if (err) 326 + goto err_exit; 326 327 327 - if (!is_valid_ether_addr(self->ndev->dev_addr) || 328 - !aq_nic_is_valid_ether_addr(self->ndev->dev_addr)) { 329 - netdev_warn(self->ndev, "MAC is invalid, will use random."); 330 - eth_hw_addr_random(self->ndev); 328 + if (is_valid_ether_addr(addr) && 329 + aq_nic_is_valid_ether_addr(addr)) { 330 + eth_hw_addr_set(self->ndev, addr); 331 + } else { 332 + netdev_warn(self->ndev, "MAC is invalid, will use random."); 333 + eth_hw_addr_random(self->ndev); 334 + } 331 335 } 332 336 333 337 #if defined(AQ_CFG_MAC_ADDR_PERMANENT) ··· 909 905 data[++i] = stats->mbtc; 910 906 data[++i] = stats->bbrc; 911 907 data[++i] = stats->bbtc; 912 - data[++i] = stats->ubrc + stats->mbrc + stats->bbrc; 913 - data[++i] = stats->ubtc + stats->mbtc + stats->bbtc; 908 + if (stats->brc) 909 + data[++i] = stats->brc; 910 + else 911 + data[++i] = stats->ubrc + stats->mbrc + stats->bbrc; 912 + if (stats->btc) 913 + data[++i] = stats->btc; 914 + else 915 + data[++i] = stats->ubtc + stats->mbtc + stats->bbtc; 914 916 data[++i] = stats->dma_pkt_rc; 915 917 data[++i] = stats->dma_pkt_tc; 916 918 data[++i] = stats->dma_oct_rc;
+6 -1
drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c
··· 49 49 { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113), }, 50 50 { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113C), }, 51 51 { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC115C), }, 52 + { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC113CA), }, 53 + { PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_AQC116C), }, 52 54 53 55 {} 54 56 }; ··· 87 85 { AQ_DEVICE_ID_AQC113CS, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, }, 88 86 { AQ_DEVICE_ID_AQC114CS, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, }, 89 87 { AQ_DEVICE_ID_AQC113C, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, }, 90 - { AQ_DEVICE_ID_AQC115C, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, }, 88 + { AQ_DEVICE_ID_AQC115C, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc115c, }, 89 + { AQ_DEVICE_ID_AQC113CA, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc113, }, 90 + { AQ_DEVICE_ID_AQC116C, AQ_HWREV_ANY, &hw_atl2_ops, &hw_atl2_caps_aqc116c, }, 91 + 91 92 }; 92 93 93 94 MODULE_DEVICE_TABLE(pci, aq_pci_tbl);
-3
drivers/net/ethernet/aquantia/atlantic/aq_vec.c
··· 362 362 { 363 363 unsigned int count; 364 364 365 - WARN_ONCE(!aq_vec_is_valid_tc(self, tc), 366 - "Invalid tc %u (#rx=%u, #tx=%u)\n", 367 - tc, self->rx_rings, self->tx_rings); 368 365 if (!aq_vec_is_valid_tc(self, tc)) 369 366 return 0; 370 367
+13 -2
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.c
··· 867 867 int hw_atl_utils_update_stats(struct aq_hw_s *self) 868 868 { 869 869 struct aq_stats_s *cs = &self->curr_stats; 870 + struct aq_stats_s curr_stats = *cs; 870 871 struct hw_atl_utils_mbox mbox; 872 + bool corrupted_stats = false; 871 873 872 874 hw_atl_utils_mpi_read_stats(self, &mbox); 873 875 874 - #define AQ_SDELTA(_N_) (self->curr_stats._N_ += \ 875 - mbox.stats._N_ - self->last_stats._N_) 876 + #define AQ_SDELTA(_N_) \ 877 + do { \ 878 + if (!corrupted_stats && \ 879 + ((s64)(mbox.stats._N_ - self->last_stats._N_)) >= 0) \ 880 + curr_stats._N_ += mbox.stats._N_ - self->last_stats._N_; \ 881 + else \ 882 + corrupted_stats = true; \ 883 + } while (0) 876 884 877 885 if (self->aq_link_status.mbps) { 878 886 AQ_SDELTA(uprc); ··· 900 892 AQ_SDELTA(bbrc); 901 893 AQ_SDELTA(bbtc); 902 894 AQ_SDELTA(dpc); 895 + 896 + if (!corrupted_stats) 897 + *cs = curr_stats; 903 898 } 904 899 #undef AQ_SDELTA 905 900
-3
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
··· 132 132 if (speed & AQ_NIC_RATE_5G) 133 133 rate |= FW2X_RATE_5G; 134 134 135 - if (speed & AQ_NIC_RATE_5GSR) 136 - rate |= FW2X_RATE_5G; 137 - 138 135 if (speed & AQ_NIC_RATE_2G5) 139 136 rate |= FW2X_RATE_2G5; 140 137
+18 -4
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c
··· 65 65 AQ_NIC_RATE_5G | 66 66 AQ_NIC_RATE_2G5 | 67 67 AQ_NIC_RATE_1G | 68 - AQ_NIC_RATE_1G_HALF | 69 68 AQ_NIC_RATE_100M | 70 - AQ_NIC_RATE_100M_HALF | 71 - AQ_NIC_RATE_10M | 72 - AQ_NIC_RATE_10M_HALF, 69 + AQ_NIC_RATE_10M, 70 + }; 71 + 72 + const struct aq_hw_caps_s hw_atl2_caps_aqc115c = { 73 + DEFAULT_BOARD_BASIC_CAPABILITIES, 74 + .media_type = AQ_HW_MEDIA_TYPE_TP, 75 + .link_speed_msk = AQ_NIC_RATE_2G5 | 76 + AQ_NIC_RATE_1G | 77 + AQ_NIC_RATE_100M | 78 + AQ_NIC_RATE_10M, 79 + }; 80 + 81 + const struct aq_hw_caps_s hw_atl2_caps_aqc116c = { 82 + DEFAULT_BOARD_BASIC_CAPABILITIES, 83 + .media_type = AQ_HW_MEDIA_TYPE_TP, 84 + .link_speed_msk = AQ_NIC_RATE_1G | 85 + AQ_NIC_RATE_100M | 86 + AQ_NIC_RATE_10M, 73 87 }; 74 88 75 89 static u32 hw_atl2_sem_act_rslvr_get(struct aq_hw_s *self)
+2
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.h
··· 9 9 #include "aq_common.h" 10 10 11 11 extern const struct aq_hw_caps_s hw_atl2_caps_aqc113; 12 + extern const struct aq_hw_caps_s hw_atl2_caps_aqc115c; 13 + extern const struct aq_hw_caps_s hw_atl2_caps_aqc116c; 12 14 extern const struct aq_hw_ops hw_atl2_ops; 13 15 14 16 #endif /* HW_ATL2_H */
+34 -4
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h
··· 239 239 u8 minor; 240 240 u16 build; 241 241 } phy; 242 - u32 rsvd; 242 + u32 drv_iface_ver:4; 243 + u32 rsvd:28; 243 244 }; 244 245 245 246 struct link_status_s { ··· 425 424 u16 rsvd2; 426 425 }; 427 426 428 - struct statistics_s { 427 + struct statistics_a0_s { 429 428 struct { 430 429 u32 link_up; 431 430 u32 link_down; ··· 456 455 } msm; 457 456 u32 main_loop_cycles; 458 457 u32 reserve_fw_gap; 458 + }; 459 + 460 + struct __packed statistics_b0_s { 461 + u64 rx_good_octets; 462 + u64 rx_pause_frames; 463 + u64 rx_good_frames; 464 + u64 rx_errors; 465 + u64 rx_unicast_frames; 466 + u64 rx_multicast_frames; 467 + u64 rx_broadcast_frames; 468 + 469 + u64 tx_good_octets; 470 + u64 tx_pause_frames; 471 + u64 tx_good_frames; 472 + u64 tx_errors; 473 + u64 tx_unicast_frames; 474 + u64 tx_multicast_frames; 475 + u64 tx_broadcast_frames; 476 + 477 + u32 main_loop_cycles; 478 + }; 479 + 480 + struct __packed statistics_s { 481 + union __packed { 482 + struct statistics_a0_s a0; 483 + struct statistics_b0_s b0; 484 + }; 459 485 }; 460 486 461 487 struct filter_caps_s { ··· 573 545 u32 rsvd5; 574 546 }; 575 547 576 - struct fw_interface_out { 548 + struct __packed fw_interface_out { 577 549 struct transaction_counter_s transaction_id; 578 550 struct version_s version; 579 551 struct link_status_s link_status; ··· 597 569 struct core_dump_s core_dump; 598 570 u32 rsvd11; 599 571 struct statistics_s stats; 600 - u32 rsvd12; 601 572 struct filter_caps_s filter_caps; 602 573 struct device_caps_s device_caps; 603 574 u32 rsvd13; ··· 618 591 #define AQ_HOST_MODE_SLEEP_PROXY 2U 619 592 #define AQ_HOST_MODE_LOW_POWER 3U 620 593 #define AQ_HOST_MODE_SHUTDOWN 4U 594 + 595 + #define AQ_A2_FW_INTERFACE_A0 0 596 + #define AQ_A2_FW_INTERFACE_B0 1 621 597 622 598 int hw_atl2_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops); 623 599
+86 -22
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c
··· 84 84 if (cnt > AQ_A2_FW_READ_TRY_MAX) 85 85 return -ETIME; 86 86 if (tid1.transaction_cnt_a != tid1.transaction_cnt_b) 87 - udelay(1); 87 + mdelay(1); 88 88 } while (tid1.transaction_cnt_a != tid1.transaction_cnt_b); 89 89 90 90 hw_atl2_mif_shared_buf_read(self, offset, (u32 *)data, dwords); ··· 154 154 { 155 155 link_options->rate_10G = !!(speed & AQ_NIC_RATE_10G); 156 156 link_options->rate_5G = !!(speed & AQ_NIC_RATE_5G); 157 - link_options->rate_N5G = !!(speed & AQ_NIC_RATE_5GSR); 157 + link_options->rate_N5G = link_options->rate_5G; 158 158 link_options->rate_2P5G = !!(speed & AQ_NIC_RATE_2G5); 159 159 link_options->rate_N2P5G = link_options->rate_2P5G; 160 160 link_options->rate_1G = !!(speed & AQ_NIC_RATE_1G); ··· 192 192 rate |= AQ_NIC_RATE_10G; 193 193 if (lkp_link_caps->rate_5G) 194 194 rate |= AQ_NIC_RATE_5G; 195 - if (lkp_link_caps->rate_N5G) 196 - rate |= AQ_NIC_RATE_5GSR; 197 195 if (lkp_link_caps->rate_2P5G) 198 196 rate |= AQ_NIC_RATE_2G5; 199 197 if (lkp_link_caps->rate_1G) ··· 333 335 return 0; 334 336 } 335 337 336 - static int aq_a2_fw_update_stats(struct aq_hw_s *self) 338 + static void aq_a2_fill_a0_stats(struct aq_hw_s *self, 339 + struct statistics_s *stats) 337 340 { 338 341 struct hw_atl2_priv *priv = (struct hw_atl2_priv *)self->priv; 339 - struct statistics_s stats; 342 + struct aq_stats_s *cs = &self->curr_stats; 343 + struct aq_stats_s curr_stats = *cs; 344 + bool corrupted_stats = false; 340 345 341 - hw_atl2_shared_buffer_read_safe(self, stats, &stats); 342 - 343 - #define AQ_SDELTA(_N_, _F_) (self->curr_stats._N_ += \ 344 - stats.msm._F_ - priv->last_stats.msm._F_) 346 + #define AQ_SDELTA(_N, _F) \ 347 + do { \ 348 + if (!corrupted_stats && \ 349 + ((s64)(stats->a0.msm._F - priv->last_stats.a0.msm._F)) >= 0) \ 350 + curr_stats._N += stats->a0.msm._F - priv->last_stats.a0.msm._F;\ 351 + else \ 352 + corrupted_stats = true; \ 353 + } while (0) 345 354 346 355 if (self->aq_link_status.mbps) { 347 356 AQ_SDELTA(uprc, rx_unicast_frames); ··· 367 362 AQ_SDELTA(mbtc, tx_multicast_octets); 368 363 AQ_SDELTA(bbrc, rx_broadcast_octets); 369 364 AQ_SDELTA(bbtc, tx_broadcast_octets); 365 + 366 + if (!corrupted_stats) 367 + *cs = curr_stats; 370 368 } 371 369 #undef AQ_SDELTA 372 - self->curr_stats.dma_pkt_rc = 373 - hw_atl_stats_rx_dma_good_pkt_counter_get(self); 374 - self->curr_stats.dma_pkt_tc = 375 - hw_atl_stats_tx_dma_good_pkt_counter_get(self); 376 - self->curr_stats.dma_oct_rc = 377 - hw_atl_stats_rx_dma_good_octet_counter_get(self); 378 - self->curr_stats.dma_oct_tc = 379 - hw_atl_stats_tx_dma_good_octet_counter_get(self); 380 - self->curr_stats.dpc = hw_atl_rpb_rx_dma_drop_pkt_cnt_get(self); 370 + 371 + } 372 + 373 + static void aq_a2_fill_b0_stats(struct aq_hw_s *self, 374 + struct statistics_s *stats) 375 + { 376 + struct hw_atl2_priv *priv = (struct hw_atl2_priv *)self->priv; 377 + struct aq_stats_s *cs = &self->curr_stats; 378 + struct aq_stats_s curr_stats = *cs; 379 + bool corrupted_stats = false; 380 + 381 + #define AQ_SDELTA(_N, _F) \ 382 + do { \ 383 + if (!corrupted_stats && \ 384 + ((s64)(stats->b0._F - priv->last_stats.b0._F)) >= 0) \ 385 + curr_stats._N += stats->b0._F - priv->last_stats.b0._F; \ 386 + else \ 387 + corrupted_stats = true; \ 388 + } while (0) 389 + 390 + if (self->aq_link_status.mbps) { 391 + AQ_SDELTA(uprc, rx_unicast_frames); 392 + AQ_SDELTA(mprc, rx_multicast_frames); 393 + AQ_SDELTA(bprc, rx_broadcast_frames); 394 + AQ_SDELTA(erpr, rx_errors); 395 + AQ_SDELTA(brc, rx_good_octets); 396 + 397 + AQ_SDELTA(uptc, tx_unicast_frames); 398 + AQ_SDELTA(mptc, tx_multicast_frames); 399 + AQ_SDELTA(bptc, tx_broadcast_frames); 400 + AQ_SDELTA(erpt, tx_errors); 401 + AQ_SDELTA(btc, tx_good_octets); 402 + 403 + if (!corrupted_stats) 404 + *cs = curr_stats; 405 + } 406 + #undef AQ_SDELTA 407 + } 408 + 409 + static int aq_a2_fw_update_stats(struct aq_hw_s *self) 410 + { 411 + struct hw_atl2_priv *priv = (struct hw_atl2_priv *)self->priv; 412 + struct aq_stats_s *cs = &self->curr_stats; 413 + struct statistics_s stats; 414 + struct version_s version; 415 + int err; 416 + 417 + err = hw_atl2_shared_buffer_read_safe(self, version, &version); 418 + if (err) 419 + return err; 420 + 421 + err = hw_atl2_shared_buffer_read_safe(self, stats, &stats); 422 + if (err) 423 + return err; 424 + 425 + if (version.drv_iface_ver == AQ_A2_FW_INTERFACE_A0) 426 + aq_a2_fill_a0_stats(self, &stats); 427 + else 428 + aq_a2_fill_b0_stats(self, &stats); 429 + 430 + cs->dma_pkt_rc = hw_atl_stats_rx_dma_good_pkt_counter_get(self); 431 + cs->dma_pkt_tc = hw_atl_stats_tx_dma_good_pkt_counter_get(self); 432 + cs->dma_oct_rc = hw_atl_stats_rx_dma_good_octet_counter_get(self); 433 + cs->dma_oct_tc = hw_atl_stats_tx_dma_good_octet_counter_get(self); 434 + cs->dpc = hw_atl_rpb_rx_dma_drop_pkt_cnt_get(self); 381 435 382 436 memcpy(&priv->last_stats, &stats, sizeof(stats)); 383 437 ··· 563 499 hw_atl2_shared_buffer_read_safe(self, version, &version); 564 500 565 501 /* A2 FW version is stored in reverse order */ 566 - return version.mac.major << 24 | 567 - version.mac.minor << 16 | 568 - version.mac.build; 502 + return version.bundle.major << 24 | 503 + version.bundle.minor << 16 | 504 + version.bundle.build; 569 505 } 570 506 571 507 int hw_atl2_utils_get_action_resolve_table_caps(struct aq_hw_s *self,
+2
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
··· 4550 4550 4551 4551 fsl_mc_portal_free(priv->mc_io); 4552 4552 4553 + destroy_workqueue(priv->dpaa2_ptp_wq); 4554 + 4553 4555 dev_dbg(net_dev->dev.parent, "Removed interface %s\n", net_dev->name); 4554 4556 4555 4557 free_netdev(net_dev);
+6 -22
drivers/net/ethernet/ibm/ibmvnic.c
··· 628 628 old_buff_size = adapter->prev_rx_buf_sz; 629 629 new_buff_size = adapter->cur_rx_buf_sz; 630 630 631 - /* Require buff size to be exactly same for now */ 632 - if (old_buff_size != new_buff_size) 633 - return false; 634 - 635 - if (old_num_pools == new_num_pools && old_pool_size == new_pool_size) 636 - return true; 637 - 638 - if (old_num_pools < adapter->min_rx_queues || 639 - old_num_pools > adapter->max_rx_queues || 640 - old_pool_size < adapter->min_rx_add_entries_per_subcrq || 641 - old_pool_size > adapter->max_rx_add_entries_per_subcrq) 631 + if (old_buff_size != new_buff_size || 632 + old_num_pools != new_num_pools || 633 + old_pool_size != new_pool_size) 642 634 return false; 643 635 644 636 return true; ··· 866 874 old_mtu = adapter->prev_mtu; 867 875 new_mtu = adapter->req_mtu; 868 876 869 - /* Require MTU to be exactly same to reuse pools for now */ 870 - if (old_mtu != new_mtu) 871 - return false; 872 - 873 - if (old_num_pools == new_num_pools && old_pool_size == new_pool_size) 874 - return true; 875 - 876 - if (old_num_pools < adapter->min_tx_queues || 877 - old_num_pools > adapter->max_tx_queues || 878 - old_pool_size < adapter->min_tx_entries_per_subcrq || 879 - old_pool_size > adapter->max_tx_entries_per_subcrq) 877 + if (old_mtu != new_mtu || 878 + old_num_pools != new_num_pools || 879 + old_pool_size != new_pool_size) 880 880 return false; 881 881 882 882 return true;
+1
drivers/net/ethernet/intel/ice/ice_xsk.c
··· 383 383 while (i--) { 384 384 dma = xsk_buff_xdp_get_dma(*xdp); 385 385 rx_desc->read.pkt_addr = cpu_to_le64(dma); 386 + rx_desc->wb.status_error0 = 0; 386 387 387 388 rx_desc++; 388 389 xdp++;
+1 -1
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
··· 7454 7454 7455 7455 shared = num_present_cpus() - priv->nthreads; 7456 7456 if (shared > 0) 7457 - bitmap_fill(&priv->lock_map, 7457 + bitmap_set(&priv->lock_map, 0, 7458 7458 min_t(int, shared, MVPP2_MAX_THREADS)); 7459 7459 7460 7460 for (i = 0; i < MVPP2_MAX_THREADS; i++) {
+1 -1
drivers/net/ethernet/marvell/octeontx2/af/rvu.c
··· 2341 2341 goto free_regions; 2342 2342 break; 2343 2343 default: 2344 - return err; 2344 + goto free_regions; 2345 2345 } 2346 2346 2347 2347 mw->mbox_wq = alloc_workqueue(name,
+3 -3
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
··· 670 670 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_T, SPEED_1000, 671 671 ETHTOOL_LINK_MODE_1000baseT_Full_BIT); 672 672 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_CX_SGMII, SPEED_1000, 673 - ETHTOOL_LINK_MODE_1000baseKX_Full_BIT); 673 + ETHTOOL_LINK_MODE_1000baseX_Full_BIT); 674 674 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_KX, SPEED_1000, 675 675 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT); 676 676 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_T, SPEED_10000, ··· 682 682 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KR, SPEED_10000, 683 683 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); 684 684 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CR, SPEED_10000, 685 - ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); 685 + ETHTOOL_LINK_MODE_10000baseCR_Full_BIT); 686 686 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_SR, SPEED_10000, 687 - ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); 687 + ETHTOOL_LINK_MODE_10000baseSR_Full_BIT); 688 688 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_20GBASE_KR2, SPEED_20000, 689 689 ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT, 690 690 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT);
+7 -2
drivers/net/ethernet/mellanox/mlx4/en_netdev.c
··· 2286 2286 bool carry_xdp_prog) 2287 2287 { 2288 2288 struct bpf_prog *xdp_prog; 2289 - int i, t; 2289 + int i, t, ret; 2290 2290 2291 - mlx4_en_copy_priv(tmp, priv, prof); 2291 + ret = mlx4_en_copy_priv(tmp, priv, prof); 2292 + if (ret) { 2293 + en_warn(priv, "%s: mlx4_en_copy_priv() failed, return\n", 2294 + __func__); 2295 + return ret; 2296 + } 2292 2297 2293 2298 if (mlx4_en_alloc_resources(tmp)) { 2294 2299 en_warn(priv,
+1 -1
drivers/net/ethernet/mellanox/mlx5/core/cmd.c
··· 341 341 case MLX5_CMD_OP_DEALLOC_SF: 342 342 case MLX5_CMD_OP_DESTROY_UCTX: 343 343 case MLX5_CMD_OP_DESTROY_UMEM: 344 + case MLX5_CMD_OP_MODIFY_RQT: 344 345 return MLX5_CMD_STAT_OK; 345 346 346 347 case MLX5_CMD_OP_QUERY_HCA_CAP: ··· 447 446 case MLX5_CMD_OP_MODIFY_TIS: 448 447 case MLX5_CMD_OP_QUERY_TIS: 449 448 case MLX5_CMD_OP_CREATE_RQT: 450 - case MLX5_CMD_OP_MODIFY_RQT: 451 449 case MLX5_CMD_OP_QUERY_RQT: 452 450 453 451 case MLX5_CMD_OP_CREATE_FLOW_TABLE:
+40 -1
drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
··· 13 13 unsigned int max_nch; 14 14 u32 drop_rqn; 15 15 16 + struct mlx5e_packet_merge_param pkt_merge_param; 17 + struct rw_semaphore pkt_merge_param_sem; 18 + 16 19 struct mlx5e_rss *rss[MLX5E_MAX_NUM_RSS]; 17 20 bool rss_active; 18 21 u32 rss_rqns[MLX5E_INDIR_RQT_SIZE]; ··· 395 392 if (err) 396 393 goto out; 397 394 395 + /* Separated from the channels RQs, does not share pkt_merge state with them */ 398 396 mlx5e_tir_builder_build_rqt(builder, res->mdev->mlx5e_res.hw_objs.td.tdn, 399 397 mlx5e_rqt_get_rqtn(&res->ptp.rqt), 400 398 inner_ft_support); ··· 450 446 res->features = features; 451 447 res->max_nch = max_nch; 452 448 res->drop_rqn = drop_rqn; 449 + 450 + res->pkt_merge_param = *init_pkt_merge_param; 451 + init_rwsem(&res->pkt_merge_param_sem); 453 452 454 453 err = mlx5e_rx_res_rss_init_def(res, init_pkt_merge_param, init_nch); 455 454 if (err) ··· 520 513 return mlx5e_tir_get_tirn(&res->ptp.tir); 521 514 } 522 515 523 - u32 mlx5e_rx_res_get_rqtn_direct(struct mlx5e_rx_res *res, unsigned int ix) 516 + static u32 mlx5e_rx_res_get_rqtn_direct(struct mlx5e_rx_res *res, unsigned int ix) 524 517 { 525 518 return mlx5e_rqt_get_rqtn(&res->channels[ix].direct_rqt); 526 519 } ··· 663 656 if (!builder) 664 657 return -ENOMEM; 665 658 659 + down_write(&res->pkt_merge_param_sem); 660 + res->pkt_merge_param = *pkt_merge_param; 661 + 666 662 mlx5e_tir_builder_build_packet_merge(builder, pkt_merge_param); 667 663 668 664 final_err = 0; ··· 691 681 } 692 682 } 693 683 684 + up_write(&res->pkt_merge_param_sem); 694 685 mlx5e_tir_builder_free(builder); 695 686 return final_err; 696 687 } ··· 699 688 struct mlx5e_rss_params_hash mlx5e_rx_res_get_current_hash(struct mlx5e_rx_res *res) 700 689 { 701 690 return mlx5e_rss_get_hash(res->rss[0]); 691 + } 692 + 693 + int mlx5e_rx_res_tls_tir_create(struct mlx5e_rx_res *res, unsigned int rxq, 694 + struct mlx5e_tir *tir) 695 + { 696 + bool inner_ft_support = res->features & MLX5E_RX_RES_FEATURE_INNER_FT; 697 + struct mlx5e_tir_builder *builder; 698 + u32 rqtn; 699 + int err; 700 + 701 + builder = mlx5e_tir_builder_alloc(false); 702 + if (!builder) 703 + return -ENOMEM; 704 + 705 + rqtn = mlx5e_rx_res_get_rqtn_direct(res, rxq); 706 + 707 + mlx5e_tir_builder_build_rqt(builder, res->mdev->mlx5e_res.hw_objs.td.tdn, rqtn, 708 + inner_ft_support); 709 + mlx5e_tir_builder_build_direct(builder); 710 + mlx5e_tir_builder_build_tls(builder); 711 + down_read(&res->pkt_merge_param_sem); 712 + mlx5e_tir_builder_build_packet_merge(builder, &res->pkt_merge_param); 713 + err = mlx5e_tir_init(tir, builder, res->mdev, false); 714 + up_read(&res->pkt_merge_param_sem); 715 + 716 + mlx5e_tir_builder_free(builder); 717 + 718 + return err; 702 719 }
+3 -3
drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h
··· 37 37 u32 mlx5e_rx_res_get_tirn_rss_inner(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt); 38 38 u32 mlx5e_rx_res_get_tirn_ptp(struct mlx5e_rx_res *res); 39 39 40 - /* RQTN getters for modules that create their own TIRs */ 41 - u32 mlx5e_rx_res_get_rqtn_direct(struct mlx5e_rx_res *res, unsigned int ix); 42 - 43 40 /* Activate/deactivate API */ 44 41 void mlx5e_rx_res_channels_activate(struct mlx5e_rx_res *res, struct mlx5e_channels *chs); 45 42 void mlx5e_rx_res_channels_deactivate(struct mlx5e_rx_res *res); ··· 66 69 /* Workaround for hairpin */ 67 70 struct mlx5e_rss_params_hash mlx5e_rx_res_get_current_hash(struct mlx5e_rx_res *res); 68 71 72 + /* Accel TIRs */ 73 + int mlx5e_rx_res_tls_tir_create(struct mlx5e_rx_res *res, unsigned int rxq, 74 + struct mlx5e_tir *tir); 69 75 #endif /* __MLX5_EN_RX_RES_H__ */
+1 -1
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.c
··· 191 191 eseg->swp_inner_l3_offset = skb_inner_network_offset(skb) / 2; 192 192 eseg->swp_inner_l4_offset = 193 193 (skb->csum_start + skb->head - skb->data) / 2; 194 - if (skb->protocol == htons(ETH_P_IPV6)) 194 + if (inner_ip_hdr(skb)->version == 6) 195 195 eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6; 196 196 break; 197 197 default:
+1 -23
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c
··· 100 100 return resp_list; 101 101 } 102 102 103 - static int mlx5e_ktls_create_tir(struct mlx5_core_dev *mdev, struct mlx5e_tir *tir, u32 rqtn) 104 - { 105 - struct mlx5e_tir_builder *builder; 106 - int err; 107 - 108 - builder = mlx5e_tir_builder_alloc(false); 109 - if (!builder) 110 - return -ENOMEM; 111 - 112 - mlx5e_tir_builder_build_rqt(builder, mdev->mlx5e_res.hw_objs.td.tdn, rqtn, false); 113 - mlx5e_tir_builder_build_direct(builder); 114 - mlx5e_tir_builder_build_tls(builder); 115 - err = mlx5e_tir_init(tir, builder, mdev, false); 116 - 117 - mlx5e_tir_builder_free(builder); 118 - 119 - return err; 120 - } 121 - 122 103 static void accel_rule_handle_work(struct work_struct *work) 123 104 { 124 105 struct mlx5e_ktls_offload_context_rx *priv_rx; ··· 590 609 struct mlx5_core_dev *mdev; 591 610 struct mlx5e_priv *priv; 592 611 int rxq, err; 593 - u32 rqtn; 594 612 595 613 tls_ctx = tls_get_ctx(sk); 596 614 priv = netdev_priv(netdev); ··· 615 635 priv_rx->sw_stats = &priv->tls->sw_stats; 616 636 mlx5e_set_ktls_rx_priv_ctx(tls_ctx, priv_rx); 617 637 618 - rqtn = mlx5e_rx_res_get_rqtn_direct(priv->rx_res, rxq); 619 - 620 - err = mlx5e_ktls_create_tir(mdev, &priv_rx->tir, rqtn); 638 + err = mlx5e_rx_res_tls_tir_create(priv->rx_res, rxq, &priv_rx->tir); 621 639 if (err) 622 640 goto err_create_tir; 623 641
+4
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
··· 1086 1086 &MLX5E_STATS_GRP(pme), 1087 1087 &MLX5E_STATS_GRP(channels), 1088 1088 &MLX5E_STATS_GRP(per_port_buff_congest), 1089 + #ifdef CONFIG_MLX5_EN_IPSEC 1090 + &MLX5E_STATS_GRP(ipsec_sw), 1091 + &MLX5E_STATS_GRP(ipsec_hw), 1092 + #endif 1089 1093 }; 1090 1094 1091 1095 static unsigned int mlx5e_ul_rep_stats_grps_num(struct mlx5e_priv *priv)
+3 -5
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
··· 544 544 u16 klm_entries, u16 index) 545 545 { 546 546 struct mlx5e_shampo_hd *shampo = rq->mpwqe.shampo; 547 - u16 entries, pi, i, header_offset, err, wqe_bbs, new_entries; 547 + u16 entries, pi, header_offset, err, wqe_bbs, new_entries; 548 548 u32 lkey = rq->mdev->mlx5e_res.hw_objs.mkey; 549 549 struct page *page = shampo->last_page; 550 550 u64 addr = shampo->last_addr; 551 551 struct mlx5e_dma_info *dma_info; 552 552 struct mlx5e_umr_wqe *umr_wqe; 553 - int headroom; 553 + int headroom, i; 554 554 555 555 headroom = rq->buff.headroom; 556 556 new_entries = klm_entries - (shampo->pi & (MLX5_UMR_KLM_ALIGNMENT - 1)); ··· 602 602 603 603 err_unmap: 604 604 while (--i >= 0) { 605 - if (--index < 0) 606 - index = shampo->hd_per_wq - 1; 607 - dma_info = &shampo->info[index]; 605 + dma_info = &shampo->info[--index]; 608 606 if (!(i & (MLX5E_SHAMPO_WQ_HEADER_PER_PAGE - 1))) { 609 607 dma_info->addr = ALIGN_DOWN(dma_info->addr, PAGE_SIZE); 610 608 mlx5e_page_release(rq, dma_info, true);
+2 -2
drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c
··· 130 130 /* If vports min rate divider is 0 but their group has bw_share configured, then 131 131 * need to set bw_share for vports to minimal value. 132 132 */ 133 - if (!group_level && !max_guarantee && group->bw_share) 133 + if (!group_level && !max_guarantee && group && group->bw_share) 134 134 return 1; 135 135 return 0; 136 136 } ··· 419 419 return err; 420 420 421 421 /* Recalculate bw share weights of old and new groups */ 422 - if (vport->qos.bw_share) { 422 + if (vport->qos.bw_share || new_group->bw_share) { 423 423 esw_qos_normalize_vports_min_rate(esw, curr_group, extack); 424 424 esw_qos_normalize_vports_min_rate(esw, new_group, extack); 425 425 }
+16 -4
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
··· 329 329 esw_is_indir_table(struct mlx5_eswitch *esw, struct mlx5_flow_attr *attr) 330 330 { 331 331 struct mlx5_esw_flow_attr *esw_attr = attr->esw_attr; 332 + bool result = false; 332 333 int i; 333 334 334 - for (i = esw_attr->split_count; i < esw_attr->out_count; i++) 335 + /* Indirect table is supported only for flows with in_port uplink 336 + * and the destination is vport on the same eswitch as the uplink, 337 + * return false in case at least one of destinations doesn't meet 338 + * this criteria. 339 + */ 340 + for (i = esw_attr->split_count; i < esw_attr->out_count; i++) { 335 341 if (esw_attr->dests[i].rep && 336 342 mlx5_esw_indir_table_needed(esw, attr, esw_attr->dests[i].rep->vport, 337 - esw_attr->dests[i].mdev)) 338 - return true; 339 - return false; 343 + esw_attr->dests[i].mdev)) { 344 + result = true; 345 + } else { 346 + result = false; 347 + break; 348 + } 349 + } 350 + return result; 340 351 } 341 352 342 353 static int ··· 2523 2512 struct mlx5_eswitch *esw = master->priv.eswitch; 2524 2513 struct mlx5_flow_table_attr ft_attr = { 2525 2514 .max_fte = 1, .prio = 0, .level = 0, 2515 + .flags = MLX5_FLOW_TABLE_OTHER_VPORT, 2526 2516 }; 2527 2517 struct mlx5_flow_namespace *egress_ns; 2528 2518 struct mlx5_flow_table *acl;
+3 -2
drivers/net/ethernet/mellanox/mlx5/core/health.c
··· 840 840 841 841 health->timer.expires = jiffies + msecs_to_jiffies(poll_interval_ms); 842 842 add_timer(&health->timer); 843 + 844 + if (mlx5_core_is_pf(dev) && MLX5_CAP_MCAM_REG(dev, mrtc)) 845 + queue_delayed_work(health->wq, &health->update_fw_log_ts_work, 0); 843 846 } 844 847 845 848 void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health) ··· 910 907 INIT_WORK(&health->fatal_report_work, mlx5_fw_fatal_reporter_err_work); 911 908 INIT_WORK(&health->report_work, mlx5_fw_reporter_err_work); 912 909 INIT_DELAYED_WORK(&health->update_fw_log_ts_work, mlx5_health_log_ts_update); 913 - if (mlx5_core_is_pf(dev)) 914 - queue_delayed_work(health->wq, &health->update_fw_log_ts_work, 0); 915 910 916 911 return 0; 917 912
+1
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
··· 608 608 if (port_sel->tunnel) 609 609 mlx5_destroy_ttc_table(port_sel->inner.ttc); 610 610 mlx5_lag_destroy_definers(ldev); 611 + memset(port_sel, 0, sizeof(*port_sel)); 611 612 }
+2 -3
drivers/net/ethernet/mellanox/mlx5/core/lib/tout.c
··· 31 31 dev->timeouts->to[type] = val; 32 32 } 33 33 34 - static void tout_set_def_val(struct mlx5_core_dev *dev) 34 + void mlx5_tout_set_def_val(struct mlx5_core_dev *dev) 35 35 { 36 36 int i; 37 37 38 - for (i = MLX5_TO_FW_PRE_INIT_TIMEOUT_MS; i < MAX_TIMEOUT_TYPES; i++) 38 + for (i = 0; i < MAX_TIMEOUT_TYPES; i++) 39 39 tout_set(dev, tout_def_sw_val[i], i); 40 40 } 41 41 ··· 45 45 if (!dev->timeouts) 46 46 return -ENOMEM; 47 47 48 - tout_set_def_val(dev); 49 48 return 0; 50 49 } 51 50
+1
drivers/net/ethernet/mellanox/mlx5/core/lib/tout.h
··· 34 34 void mlx5_tout_cleanup(struct mlx5_core_dev *dev); 35 35 void mlx5_tout_query_iseg(struct mlx5_core_dev *dev); 36 36 int mlx5_tout_query_dtor(struct mlx5_core_dev *dev); 37 + void mlx5_tout_set_def_val(struct mlx5_core_dev *dev); 37 38 u64 _mlx5_tout_ms(struct mlx5_core_dev *dev, enum mlx5_timeouts_types type); 38 39 39 40 #define mlx5_tout_ms(dev, type) _mlx5_tout_ms(dev, MLX5_TO_##type##_MS)
+15 -15
drivers/net/ethernet/mellanox/mlx5/core/main.c
··· 992 992 if (mlx5_core_is_pf(dev)) 993 993 pcie_print_link_status(dev->pdev); 994 994 995 - err = mlx5_tout_init(dev); 996 - if (err) { 997 - mlx5_core_err(dev, "Failed initializing timeouts, aborting\n"); 998 - return err; 999 - } 995 + mlx5_tout_set_def_val(dev); 1000 996 1001 997 /* wait for firmware to accept initialization segments configurations 1002 998 */ ··· 1001 1005 if (err) { 1002 1006 mlx5_core_err(dev, "Firmware over %llu MS in pre-initializing state, aborting\n", 1003 1007 mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT)); 1004 - goto err_tout_cleanup; 1008 + return err; 1005 1009 } 1006 1010 1007 1011 err = mlx5_cmd_init(dev); 1008 1012 if (err) { 1009 1013 mlx5_core_err(dev, "Failed initializing command interface, aborting\n"); 1010 - goto err_tout_cleanup; 1014 + return err; 1011 1015 } 1012 1016 1013 1017 mlx5_tout_query_iseg(dev); ··· 1071 1075 1072 1076 mlx5_set_driver_version(dev); 1073 1077 1074 - mlx5_start_health_poll(dev); 1075 - 1076 1078 err = mlx5_query_hca_caps(dev); 1077 1079 if (err) { 1078 1080 mlx5_core_err(dev, "query hca failed\n"); 1079 - goto stop_health; 1081 + goto reclaim_boot_pages; 1080 1082 } 1083 + 1084 + mlx5_start_health_poll(dev); 1081 1085 1082 1086 return 0; 1083 1087 1084 - stop_health: 1085 - mlx5_stop_health_poll(dev, boot); 1086 1088 reclaim_boot_pages: 1087 1089 mlx5_reclaim_startup_pages(dev); 1088 1090 err_disable_hca: ··· 1088 1094 err_cmd_cleanup: 1089 1095 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN); 1090 1096 mlx5_cmd_cleanup(dev); 1091 - err_tout_cleanup: 1092 - mlx5_tout_cleanup(dev); 1093 1097 1094 1098 return err; 1095 1099 } ··· 1106 1114 mlx5_core_disable_hca(dev, 0); 1107 1115 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN); 1108 1116 mlx5_cmd_cleanup(dev); 1109 - mlx5_tout_cleanup(dev); 1110 1117 1111 1118 return 0; 1112 1119 } ··· 1467 1476 mlx5_debugfs_root); 1468 1477 INIT_LIST_HEAD(&priv->traps); 1469 1478 1479 + err = mlx5_tout_init(dev); 1480 + if (err) { 1481 + mlx5_core_err(dev, "Failed initializing timeouts, aborting\n"); 1482 + goto err_timeout_init; 1483 + } 1484 + 1470 1485 err = mlx5_health_init(dev); 1471 1486 if (err) 1472 1487 goto err_health_init; ··· 1498 1501 err_pagealloc_init: 1499 1502 mlx5_health_cleanup(dev); 1500 1503 err_health_init: 1504 + mlx5_tout_cleanup(dev); 1505 + err_timeout_init: 1501 1506 debugfs_remove(dev->priv.dbg_root); 1502 1507 mutex_destroy(&priv->pgdir_mutex); 1503 1508 mutex_destroy(&priv->alloc_mutex); ··· 1517 1518 mlx5_adev_cleanup(dev); 1518 1519 mlx5_pagealloc_cleanup(dev); 1519 1520 mlx5_health_cleanup(dev); 1521 + mlx5_tout_cleanup(dev); 1520 1522 debugfs_remove_recursive(dev->priv.dbg_root); 1521 1523 mutex_destroy(&priv->pgdir_mutex); 1522 1524 mutex_destroy(&priv->alloc_mutex);
+1 -1
drivers/net/ethernet/natsemi/xtsonic.c
··· 120 120 .ndo_set_mac_address = eth_mac_addr, 121 121 }; 122 122 123 - static int __init sonic_probe1(struct net_device *dev) 123 + static int sonic_probe1(struct net_device *dev) 124 124 { 125 125 unsigned int silicon_revision; 126 126 struct sonic_local *lp = netdev_priv(dev);
+8 -2
drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
··· 1077 1077 sds_mbx_size = sizeof(struct qlcnic_sds_mbx); 1078 1078 context_id = recv_ctx->context_id; 1079 1079 num_sds = adapter->drv_sds_rings - QLCNIC_MAX_SDS_RINGS; 1080 - ahw->hw_ops->alloc_mbx_args(&cmd, adapter, 1081 - QLCNIC_CMD_ADD_RCV_RINGS); 1080 + err = ahw->hw_ops->alloc_mbx_args(&cmd, adapter, 1081 + QLCNIC_CMD_ADD_RCV_RINGS); 1082 + if (err) { 1083 + dev_err(&adapter->pdev->dev, 1084 + "Failed to alloc mbx args %d\n", err); 1085 + return err; 1086 + } 1087 + 1082 1088 cmd.req.arg[1] = 0 | (num_sds << 8) | (context_id << 16); 1083 1089 1084 1090 /* set up status rings, mbx 2-81 */
+6 -5
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 5532 5532 netdev_features_t features) 5533 5533 { 5534 5534 struct stmmac_priv *priv = netdev_priv(netdev); 5535 - bool sph_en; 5536 - u32 chan; 5537 5535 5538 5536 /* Keep the COE Type in case of csum is supporting */ 5539 5537 if (features & NETIF_F_RXCSUM) ··· 5543 5545 */ 5544 5546 stmmac_rx_ipc(priv, priv->hw); 5545 5547 5546 - sph_en = (priv->hw->rx_csum > 0) && priv->sph; 5548 + if (priv->sph_cap) { 5549 + bool sph_en = (priv->hw->rx_csum > 0) && priv->sph; 5550 + u32 chan; 5547 5551 5548 - for (chan = 0; chan < priv->plat->rx_queues_to_use; chan++) 5549 - stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan); 5552 + for (chan = 0; chan < priv->plat->rx_queues_to_use; chan++) 5553 + stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan); 5554 + } 5550 5555 5551 5556 return 0; 5552 5557 }
+1 -1
drivers/net/usb/lan78xx.c
··· 2398 2398 if (dev->domain_data.phyirq > 0) 2399 2399 phydev->irq = dev->domain_data.phyirq; 2400 2400 else 2401 - phydev->irq = 0; 2401 + phydev->irq = PHY_POLL; 2402 2402 netdev_dbg(dev->net, "phydev->irq = %d\n", phydev->irq); 2403 2403 2404 2404 /* set to AUTOMDIX */
-1
drivers/net/virtio_net.c
··· 3425 3425 .feature_table_size = ARRAY_SIZE(features), 3426 3426 .feature_table_legacy = features_legacy, 3427 3427 .feature_table_size_legacy = ARRAY_SIZE(features_legacy), 3428 - .suppress_used_validation = true, 3429 3428 .driver.name = KBUILD_MODNAME, 3430 3429 .driver.owner = THIS_MODULE, 3431 3430 .id_table = id_table,
+2
drivers/net/vrf.c
··· 497 497 /* strip the ethernet header added for pass through VRF device */ 498 498 __skb_pull(skb, skb_network_offset(skb)); 499 499 500 + memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); 500 501 ret = vrf_ip6_local_out(net, skb->sk, skb); 501 502 if (unlikely(net_xmit_eval(ret))) 502 503 dev->stats.tx_errors++; ··· 580 579 RT_SCOPE_LINK); 581 580 } 582 581 582 + memset(IPCB(skb), 0, sizeof(*IPCB(skb))); 583 583 ret = vrf_ip_local_out(dev_net(skb_dst(skb)->dev), skb->sk, skb); 584 584 if (unlikely(net_xmit_eval(ret))) 585 585 vrf_dev->stats.tx_errors++;
+1 -1
drivers/net/wireguard/allowedips.c
··· 163 163 return exact; 164 164 } 165 165 166 - static inline void connect_node(struct allowedips_node **parent, u8 bit, struct allowedips_node *node) 166 + static inline void connect_node(struct allowedips_node __rcu **parent, u8 bit, struct allowedips_node *node) 167 167 { 168 168 node->parent_bit_packed = (unsigned long)parent | bit; 169 169 rcu_assign_pointer(*parent, node);
+21 -18
drivers/net/wireguard/device.c
··· 98 98 { 99 99 struct wg_device *wg = netdev_priv(dev); 100 100 struct wg_peer *peer; 101 + struct sk_buff *skb; 101 102 102 103 mutex_lock(&wg->device_update_lock); 103 104 list_for_each_entry(peer, &wg->peer_list, peer_list) { ··· 109 108 wg_noise_reset_last_sent_handshake(&peer->last_sent_handshake); 110 109 } 111 110 mutex_unlock(&wg->device_update_lock); 112 - skb_queue_purge(&wg->incoming_handshakes); 111 + while ((skb = ptr_ring_consume(&wg->handshake_queue.ring)) != NULL) 112 + kfree_skb(skb); 113 + atomic_set(&wg->handshake_queue_len, 0); 113 114 wg_socket_reinit(wg, NULL, NULL); 114 115 return 0; 115 116 } ··· 238 235 destroy_workqueue(wg->handshake_receive_wq); 239 236 destroy_workqueue(wg->handshake_send_wq); 240 237 destroy_workqueue(wg->packet_crypt_wq); 241 - wg_packet_queue_free(&wg->decrypt_queue); 242 - wg_packet_queue_free(&wg->encrypt_queue); 238 + wg_packet_queue_free(&wg->handshake_queue, true); 239 + wg_packet_queue_free(&wg->decrypt_queue, false); 240 + wg_packet_queue_free(&wg->encrypt_queue, false); 243 241 rcu_barrier(); /* Wait for all the peers to be actually freed. */ 244 242 wg_ratelimiter_uninit(); 245 243 memzero_explicit(&wg->static_identity, sizeof(wg->static_identity)); 246 - skb_queue_purge(&wg->incoming_handshakes); 247 244 free_percpu(dev->tstats); 248 - free_percpu(wg->incoming_handshakes_worker); 249 245 kvfree(wg->index_hashtable); 250 246 kvfree(wg->peer_hashtable); 251 247 mutex_unlock(&wg->device_update_lock); ··· 300 298 init_rwsem(&wg->static_identity.lock); 301 299 mutex_init(&wg->socket_update_lock); 302 300 mutex_init(&wg->device_update_lock); 303 - skb_queue_head_init(&wg->incoming_handshakes); 304 301 wg_allowedips_init(&wg->peer_allowedips); 305 302 wg_cookie_checker_init(&wg->cookie_checker, wg); 306 303 INIT_LIST_HEAD(&wg->peer_list); ··· 317 316 if (!dev->tstats) 318 317 goto err_free_index_hashtable; 319 318 320 - wg->incoming_handshakes_worker = 321 - wg_packet_percpu_multicore_worker_alloc( 322 - wg_packet_handshake_receive_worker, wg); 323 - if (!wg->incoming_handshakes_worker) 324 - goto err_free_tstats; 325 - 326 319 wg->handshake_receive_wq = alloc_workqueue("wg-kex-%s", 327 320 WQ_CPU_INTENSIVE | WQ_FREEZABLE, 0, dev->name); 328 321 if (!wg->handshake_receive_wq) 329 - goto err_free_incoming_handshakes; 322 + goto err_free_tstats; 330 323 331 324 wg->handshake_send_wq = alloc_workqueue("wg-kex-%s", 332 325 WQ_UNBOUND | WQ_FREEZABLE, 0, dev->name); ··· 342 347 if (ret < 0) 343 348 goto err_free_encrypt_queue; 344 349 345 - ret = wg_ratelimiter_init(); 350 + ret = wg_packet_queue_init(&wg->handshake_queue, wg_packet_handshake_receive_worker, 351 + MAX_QUEUED_INCOMING_HANDSHAKES); 346 352 if (ret < 0) 347 353 goto err_free_decrypt_queue; 354 + 355 + ret = wg_ratelimiter_init(); 356 + if (ret < 0) 357 + goto err_free_handshake_queue; 348 358 349 359 ret = register_netdevice(dev); 350 360 if (ret < 0) ··· 367 367 368 368 err_uninit_ratelimiter: 369 369 wg_ratelimiter_uninit(); 370 + err_free_handshake_queue: 371 + wg_packet_queue_free(&wg->handshake_queue, false); 370 372 err_free_decrypt_queue: 371 - wg_packet_queue_free(&wg->decrypt_queue); 373 + wg_packet_queue_free(&wg->decrypt_queue, false); 372 374 err_free_encrypt_queue: 373 - wg_packet_queue_free(&wg->encrypt_queue); 375 + wg_packet_queue_free(&wg->encrypt_queue, false); 374 376 err_destroy_packet_crypt: 375 377 destroy_workqueue(wg->packet_crypt_wq); 376 378 err_destroy_handshake_send: 377 379 destroy_workqueue(wg->handshake_send_wq); 378 380 err_destroy_handshake_receive: 379 381 destroy_workqueue(wg->handshake_receive_wq); 380 - err_free_incoming_handshakes: 381 - free_percpu(wg->incoming_handshakes_worker); 382 382 err_free_tstats: 383 383 free_percpu(dev->tstats); 384 384 err_free_index_hashtable: ··· 398 398 static void wg_netns_pre_exit(struct net *net) 399 399 { 400 400 struct wg_device *wg; 401 + struct wg_peer *peer; 401 402 402 403 rtnl_lock(); 403 404 list_for_each_entry(wg, &device_list, device_list) { ··· 408 407 mutex_lock(&wg->device_update_lock); 409 408 rcu_assign_pointer(wg->creating_net, NULL); 410 409 wg_socket_reinit(wg, NULL, NULL); 410 + list_for_each_entry(peer, &wg->peer_list, peer_list) 411 + wg_socket_clear_peer_endpoint_src(peer); 411 412 mutex_unlock(&wg->device_update_lock); 412 413 } 413 414 }
+3 -6
drivers/net/wireguard/device.h
··· 39 39 40 40 struct wg_device { 41 41 struct net_device *dev; 42 - struct crypt_queue encrypt_queue, decrypt_queue; 42 + struct crypt_queue encrypt_queue, decrypt_queue, handshake_queue; 43 43 struct sock __rcu *sock4, *sock6; 44 44 struct net __rcu *creating_net; 45 45 struct noise_static_identity static_identity; 46 - struct workqueue_struct *handshake_receive_wq, *handshake_send_wq; 47 - struct workqueue_struct *packet_crypt_wq; 48 - struct sk_buff_head incoming_handshakes; 49 - int incoming_handshake_cpu; 50 - struct multicore_worker __percpu *incoming_handshakes_worker; 46 + struct workqueue_struct *packet_crypt_wq,*handshake_receive_wq, *handshake_send_wq; 51 47 struct cookie_checker cookie_checker; 52 48 struct pubkey_hashtable *peer_hashtable; 53 49 struct index_hashtable *index_hashtable; 54 50 struct allowedips peer_allowedips; 55 51 struct mutex device_update_lock, socket_update_lock; 56 52 struct list_head device_list, peer_list; 53 + atomic_t handshake_queue_len; 57 54 unsigned int num_peers, device_update_gen; 58 55 u32 fwmark; 59 56 u16 incoming_port;
+4 -4
drivers/net/wireguard/main.c
··· 17 17 #include <linux/genetlink.h> 18 18 #include <net/rtnetlink.h> 19 19 20 - static int __init mod_init(void) 20 + static int __init wg_mod_init(void) 21 21 { 22 22 int ret; 23 23 ··· 60 60 return ret; 61 61 } 62 62 63 - static void __exit mod_exit(void) 63 + static void __exit wg_mod_exit(void) 64 64 { 65 65 wg_genetlink_uninit(); 66 66 wg_device_uninit(); ··· 68 68 wg_allowedips_slab_uninit(); 69 69 } 70 70 71 - module_init(mod_init); 72 - module_exit(mod_exit); 71 + module_init(wg_mod_init); 72 + module_exit(wg_mod_exit); 73 73 MODULE_LICENSE("GPL v2"); 74 74 MODULE_DESCRIPTION("WireGuard secure network tunnel"); 75 75 MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
+3 -3
drivers/net/wireguard/queueing.c
··· 38 38 return 0; 39 39 } 40 40 41 - void wg_packet_queue_free(struct crypt_queue *queue) 41 + void wg_packet_queue_free(struct crypt_queue *queue, bool purge) 42 42 { 43 43 free_percpu(queue->worker); 44 - WARN_ON(!__ptr_ring_empty(&queue->ring)); 45 - ptr_ring_cleanup(&queue->ring, NULL); 44 + WARN_ON(!purge && !__ptr_ring_empty(&queue->ring)); 45 + ptr_ring_cleanup(&queue->ring, purge ? (void(*)(void*))kfree_skb : NULL); 46 46 } 47 47 48 48 #define NEXT(skb) ((skb)->prev)
+1 -1
drivers/net/wireguard/queueing.h
··· 23 23 /* queueing.c APIs: */ 24 24 int wg_packet_queue_init(struct crypt_queue *queue, work_func_t function, 25 25 unsigned int len); 26 - void wg_packet_queue_free(struct crypt_queue *queue); 26 + void wg_packet_queue_free(struct crypt_queue *queue, bool purge); 27 27 struct multicore_worker __percpu * 28 28 wg_packet_percpu_multicore_worker_alloc(work_func_t function, void *ptr); 29 29
+2 -2
drivers/net/wireguard/ratelimiter.c
··· 176 176 (1U << 14) / sizeof(struct hlist_head))); 177 177 max_entries = table_size * 8; 178 178 179 - table_v4 = kvzalloc(table_size * sizeof(*table_v4), GFP_KERNEL); 179 + table_v4 = kvcalloc(table_size, sizeof(*table_v4), GFP_KERNEL); 180 180 if (unlikely(!table_v4)) 181 181 goto err_kmemcache; 182 182 183 183 #if IS_ENABLED(CONFIG_IPV6) 184 - table_v6 = kvzalloc(table_size * sizeof(*table_v6), GFP_KERNEL); 184 + table_v6 = kvcalloc(table_size, sizeof(*table_v6), GFP_KERNEL); 185 185 if (unlikely(!table_v6)) { 186 186 kvfree(table_v4); 187 187 goto err_kmemcache;
+22 -15
drivers/net/wireguard/receive.c
··· 116 116 return; 117 117 } 118 118 119 - under_load = skb_queue_len(&wg->incoming_handshakes) >= 120 - MAX_QUEUED_INCOMING_HANDSHAKES / 8; 119 + under_load = atomic_read(&wg->handshake_queue_len) >= 120 + MAX_QUEUED_INCOMING_HANDSHAKES / 8; 121 121 if (under_load) { 122 122 last_under_load = ktime_get_coarse_boottime_ns(); 123 123 } else if (last_under_load) { ··· 212 212 213 213 void wg_packet_handshake_receive_worker(struct work_struct *work) 214 214 { 215 - struct wg_device *wg = container_of(work, struct multicore_worker, 216 - work)->ptr; 215 + struct crypt_queue *queue = container_of(work, struct multicore_worker, work)->ptr; 216 + struct wg_device *wg = container_of(queue, struct wg_device, handshake_queue); 217 217 struct sk_buff *skb; 218 218 219 - while ((skb = skb_dequeue(&wg->incoming_handshakes)) != NULL) { 219 + while ((skb = ptr_ring_consume_bh(&queue->ring)) != NULL) { 220 220 wg_receive_handshake_packet(wg, skb); 221 221 dev_kfree_skb(skb); 222 + atomic_dec(&wg->handshake_queue_len); 222 223 cond_resched(); 223 224 } 224 225 } ··· 554 553 case cpu_to_le32(MESSAGE_HANDSHAKE_INITIATION): 555 554 case cpu_to_le32(MESSAGE_HANDSHAKE_RESPONSE): 556 555 case cpu_to_le32(MESSAGE_HANDSHAKE_COOKIE): { 557 - int cpu; 556 + int cpu, ret = -EBUSY; 558 557 559 - if (skb_queue_len(&wg->incoming_handshakes) > 560 - MAX_QUEUED_INCOMING_HANDSHAKES || 561 - unlikely(!rng_is_initialized())) { 558 + if (unlikely(!rng_is_initialized())) 559 + goto drop; 560 + if (atomic_read(&wg->handshake_queue_len) > MAX_QUEUED_INCOMING_HANDSHAKES / 2) { 561 + if (spin_trylock_bh(&wg->handshake_queue.ring.producer_lock)) { 562 + ret = __ptr_ring_produce(&wg->handshake_queue.ring, skb); 563 + spin_unlock_bh(&wg->handshake_queue.ring.producer_lock); 564 + } 565 + } else 566 + ret = ptr_ring_produce_bh(&wg->handshake_queue.ring, skb); 567 + if (ret) { 568 + drop: 562 569 net_dbg_skb_ratelimited("%s: Dropping handshake packet from %pISpfsc\n", 563 570 wg->dev->name, skb); 564 571 goto err; 565 572 } 566 - skb_queue_tail(&wg->incoming_handshakes, skb); 567 - /* Queues up a call to packet_process_queued_handshake_ 568 - * packets(skb): 569 - */ 570 - cpu = wg_cpumask_next_online(&wg->incoming_handshake_cpu); 573 + atomic_inc(&wg->handshake_queue_len); 574 + cpu = wg_cpumask_next_online(&wg->handshake_queue.last_cpu); 575 + /* Queues up a call to packet_process_queued_handshake_packets(skb): */ 571 576 queue_work_on(cpu, wg->handshake_receive_wq, 572 - &per_cpu_ptr(wg->incoming_handshakes_worker, cpu)->work); 577 + &per_cpu_ptr(wg->handshake_queue.worker, cpu)->work); 573 578 break; 574 579 } 575 580 case cpu_to_le32(MESSAGE_DATA):
+1 -1
drivers/net/wireguard/socket.c
··· 308 308 { 309 309 write_lock_bh(&peer->endpoint_lock); 310 310 memset(&peer->endpoint.src6, 0, sizeof(peer->endpoint.src6)); 311 - dst_cache_reset(&peer->endpoint_cache); 311 + dst_cache_reset_now(&peer->endpoint_cache); 312 312 write_unlock_bh(&peer->endpoint_lock); 313 313 } 314 314
+6
drivers/net/wireless/intel/iwlwifi/fw/uefi.c
··· 86 86 if (len < tlv_len) { 87 87 IWL_ERR(trans, "invalid TLV len: %zd/%u\n", 88 88 len, tlv_len); 89 + kfree(reduce_power_data); 89 90 reduce_power_data = ERR_PTR(-EINVAL); 90 91 goto out; 91 92 } ··· 106 105 IWL_DEBUG_FW(trans, 107 106 "Couldn't allocate (more) reduce_power_data\n"); 108 107 108 + kfree(reduce_power_data); 109 109 reduce_power_data = ERR_PTR(-ENOMEM); 110 110 goto out; 111 111 } ··· 136 134 done: 137 135 if (!size) { 138 136 IWL_DEBUG_FW(trans, "Empty REDUCE_POWER, skipping.\n"); 137 + /* Better safe than sorry, but 'reduce_power_data' should 138 + * always be NULL if !size. 139 + */ 140 + kfree(reduce_power_data); 139 141 reduce_power_data = ERR_PTR(-ENOENT); 140 142 goto out; 141 143 }
+15 -7
drivers/net/wireless/intel/iwlwifi/iwl-drv.c
··· 1313 1313 const struct iwl_op_mode_ops *ops = op->ops; 1314 1314 struct dentry *dbgfs_dir = NULL; 1315 1315 struct iwl_op_mode *op_mode = NULL; 1316 + int retry, max_retry = !!iwlwifi_mod_params.fw_restart * IWL_MAX_INIT_RETRY; 1317 + 1318 + for (retry = 0; retry <= max_retry; retry++) { 1316 1319 1317 1320 #ifdef CONFIG_IWLWIFI_DEBUGFS 1318 - drv->dbgfs_op_mode = debugfs_create_dir(op->name, 1319 - drv->dbgfs_drv); 1320 - dbgfs_dir = drv->dbgfs_op_mode; 1321 + drv->dbgfs_op_mode = debugfs_create_dir(op->name, 1322 + drv->dbgfs_drv); 1323 + dbgfs_dir = drv->dbgfs_op_mode; 1321 1324 #endif 1322 1325 1323 - op_mode = ops->start(drv->trans, drv->trans->cfg, &drv->fw, dbgfs_dir); 1326 + op_mode = ops->start(drv->trans, drv->trans->cfg, 1327 + &drv->fw, dbgfs_dir); 1328 + 1329 + if (op_mode) 1330 + return op_mode; 1331 + 1332 + IWL_ERR(drv, "retry init count %d\n", retry); 1324 1333 1325 1334 #ifdef CONFIG_IWLWIFI_DEBUGFS 1326 - if (!op_mode) { 1327 1335 debugfs_remove_recursive(drv->dbgfs_op_mode); 1328 1336 drv->dbgfs_op_mode = NULL; 1329 - } 1330 1337 #endif 1338 + } 1331 1339 1332 - return op_mode; 1340 + return NULL; 1333 1341 } 1334 1342 1335 1343 static void _iwl_op_mode_stop(struct iwl_drv *drv)
+3
drivers/net/wireless/intel/iwlwifi/iwl-drv.h
··· 89 89 #define IWL_EXPORT_SYMBOL(sym) 90 90 #endif 91 91 92 + /* max retry for init flow */ 93 + #define IWL_MAX_INIT_RETRY 2 94 + 92 95 #endif /* __iwl_drv_h__ */
+23 -1
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
··· 16 16 #include <net/ieee80211_radiotap.h> 17 17 #include <net/tcp.h> 18 18 19 + #include "iwl-drv.h" 19 20 #include "iwl-op-mode.h" 20 21 #include "iwl-io.h" 21 22 #include "mvm.h" ··· 1118 1117 { 1119 1118 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1120 1119 int ret; 1120 + int retry, max_retry = 0; 1121 1121 1122 1122 mutex_lock(&mvm->mutex); 1123 - ret = __iwl_mvm_mac_start(mvm); 1123 + 1124 + /* we are starting the mac not in error flow, and restart is enabled */ 1125 + if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) && 1126 + iwlwifi_mod_params.fw_restart) { 1127 + max_retry = IWL_MAX_INIT_RETRY; 1128 + /* 1129 + * This will prevent mac80211 recovery flows to trigger during 1130 + * init failures 1131 + */ 1132 + set_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 1133 + } 1134 + 1135 + for (retry = 0; retry <= max_retry; retry++) { 1136 + ret = __iwl_mvm_mac_start(mvm); 1137 + if (!ret) 1138 + break; 1139 + 1140 + IWL_ERR(mvm, "mac start retry %d\n", retry); 1141 + } 1142 + clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 1143 + 1124 1144 mutex_unlock(&mvm->mutex); 1125 1145 1126 1146 return ret;
+3
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
··· 1123 1123 * @IWL_MVM_STATUS_FIRMWARE_RUNNING: firmware is running 1124 1124 * @IWL_MVM_STATUS_NEED_FLUSH_P2P: need to flush P2P bcast STA 1125 1125 * @IWL_MVM_STATUS_IN_D3: in D3 (or at least about to go into it) 1126 + * @IWL_MVM_STATUS_STARTING: starting mac, 1127 + * used to disable restart flow while in STARTING state 1126 1128 */ 1127 1129 enum iwl_mvm_status { 1128 1130 IWL_MVM_STATUS_HW_RFKILL, ··· 1136 1134 IWL_MVM_STATUS_FIRMWARE_RUNNING, 1137 1135 IWL_MVM_STATUS_NEED_FLUSH_P2P, 1138 1136 IWL_MVM_STATUS_IN_D3, 1137 + IWL_MVM_STATUS_STARTING, 1139 1138 }; 1140 1139 1141 1140 /* Keep track of completed init configuration */
+5
drivers/net/wireless/intel/iwlwifi/mvm/ops.c
··· 686 686 int ret; 687 687 688 688 rtnl_lock(); 689 + wiphy_lock(mvm->hw->wiphy); 689 690 mutex_lock(&mvm->mutex); 690 691 691 692 ret = iwl_run_init_mvm_ucode(mvm); ··· 702 701 iwl_mvm_stop_device(mvm); 703 702 704 703 mutex_unlock(&mvm->mutex); 704 + wiphy_unlock(mvm->hw->wiphy); 705 705 rtnl_unlock(); 706 706 707 707 if (ret < 0) ··· 1602 1600 */ 1603 1601 if (!mvm->fw_restart && fw_error) { 1604 1602 iwl_fw_error_collect(&mvm->fwrt, false); 1603 + } else if (test_bit(IWL_MVM_STATUS_STARTING, 1604 + &mvm->status)) { 1605 + IWL_ERR(mvm, "Starting mac, retry will be triggered anyway\n"); 1605 1606 } else if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1606 1607 struct iwl_mvm_reprobe *reprobe; 1607 1608
+8 -2
drivers/net/wireless/intel/iwlwifi/pcie/drv.c
··· 1339 1339 u16 mac_type, u8 mac_step, 1340 1340 u16 rf_type, u8 cdb, u8 rf_id, u8 no_160, u8 cores) 1341 1341 { 1342 + int num_devices = ARRAY_SIZE(iwl_dev_info_table); 1342 1343 int i; 1343 1344 1344 - for (i = ARRAY_SIZE(iwl_dev_info_table) - 1; i >= 0; i--) { 1345 + if (!num_devices) 1346 + return NULL; 1347 + 1348 + for (i = num_devices - 1; i >= 0; i--) { 1345 1349 const struct iwl_dev_info *dev_info = &iwl_dev_info_table[i]; 1346 1350 1347 1351 if (dev_info->device != (u16)IWL_CFG_ANY && ··· 1446 1442 */ 1447 1443 if (iwl_trans->trans_cfg->rf_id && 1448 1444 iwl_trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000 && 1449 - !CSR_HW_RFID_TYPE(iwl_trans->hw_rf_id) && get_crf_id(iwl_trans)) 1445 + !CSR_HW_RFID_TYPE(iwl_trans->hw_rf_id) && get_crf_id(iwl_trans)) { 1446 + ret = -EINVAL; 1450 1447 goto out_free_trans; 1448 + } 1451 1449 1452 1450 dev_info = iwl_pci_find_dev_info(pdev->device, pdev->subsystem_device, 1453 1451 CSR_HW_REV_TYPE(iwl_trans->hw_rev),
+1 -2
drivers/net/wireless/mediatek/mt76/mt7615/pci_mac.c
··· 143 143 if (!wcid) 144 144 wcid = &dev->mt76.global_wcid; 145 145 146 - pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb); 147 - 148 146 if ((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) && msta) { 149 147 struct mt7615_phy *phy = &dev->phy; 150 148 ··· 162 164 if (id < 0) 163 165 return id; 164 166 167 + pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb); 165 168 mt7615_mac_write_txwi(dev, txwi_ptr, tx_info->skb, wcid, sta, 166 169 pid, key, false); 167 170
+15 -13
drivers/net/wireless/mediatek/mt76/mt7615/usb_sdio.c
··· 43 43 static void 44 44 mt7663_usb_sdio_write_txwi(struct mt7615_dev *dev, struct mt76_wcid *wcid, 45 45 enum mt76_txq_id qid, struct ieee80211_sta *sta, 46 + struct ieee80211_key_conf *key, int pid, 46 47 struct sk_buff *skb) 47 48 { 48 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 49 - struct ieee80211_key_conf *key = info->control.hw_key; 50 - __le32 *txwi; 51 - int pid; 49 + __le32 *txwi = (__le32 *)(skb->data - MT_USB_TXD_SIZE); 52 50 53 - if (!wcid) 54 - wcid = &dev->mt76.global_wcid; 55 - 56 - pid = mt76_tx_status_skb_add(&dev->mt76, wcid, skb); 57 - 58 - txwi = (__le32 *)(skb->data - MT_USB_TXD_SIZE); 59 51 memset(txwi, 0, MT_USB_TXD_SIZE); 60 52 mt7615_mac_write_txwi(dev, txwi, skb, wcid, sta, pid, key, false); 61 53 skb_push(skb, MT_USB_TXD_SIZE); ··· 186 194 struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); 187 195 struct sk_buff *skb = tx_info->skb; 188 196 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 197 + struct ieee80211_key_conf *key = info->control.hw_key; 189 198 struct mt7615_sta *msta; 190 - int pad; 199 + int pad, err, pktid; 191 200 192 201 msta = wcid ? container_of(wcid, struct mt7615_sta, wcid) : NULL; 202 + if (!wcid) 203 + wcid = &dev->mt76.global_wcid; 204 + 193 205 if ((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) && 194 206 msta && !msta->rate_probe) { 195 207 /* request to configure sampling rate */ ··· 203 207 spin_unlock_bh(&dev->mt76.lock); 204 208 } 205 209 206 - mt7663_usb_sdio_write_txwi(dev, wcid, qid, sta, skb); 210 + pktid = mt76_tx_status_skb_add(&dev->mt76, wcid, skb); 211 + mt7663_usb_sdio_write_txwi(dev, wcid, qid, sta, key, pktid, skb); 207 212 if (mt76_is_usb(mdev)) { 208 213 u32 len = skb->len; 209 214 ··· 214 217 pad = round_up(skb->len, 4) - skb->len; 215 218 } 216 219 217 - return mt76_skb_adjust_pad(skb, pad); 220 + err = mt76_skb_adjust_pad(skb, pad); 221 + if (err) 222 + /* Release pktid in case of error. */ 223 + idr_remove(&wcid->pktid, pktid); 224 + 225 + return err; 218 226 } 219 227 EXPORT_SYMBOL_GPL(mt7663_usb_sdio_tx_prepare_skb); 220 228
+7 -1
drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c
··· 72 72 bool ampdu = IEEE80211_SKB_CB(tx_info->skb)->flags & IEEE80211_TX_CTL_AMPDU; 73 73 enum mt76_qsel qsel; 74 74 u32 flags; 75 + int err; 75 76 76 77 mt76_insert_hdr_pad(tx_info->skb); 77 78 ··· 107 106 ewma_pktlen_add(&msta->pktlen, tx_info->skb->len); 108 107 } 109 108 110 - return mt76x02u_skb_dma_info(tx_info->skb, WLAN_PORT, flags); 109 + err = mt76x02u_skb_dma_info(tx_info->skb, WLAN_PORT, flags); 110 + if (err && wcid) 111 + /* Release pktid in case of error. */ 112 + idr_remove(&wcid->pktid, pid); 113 + 114 + return err; 111 115 } 112 116 EXPORT_SYMBOL_GPL(mt76x02u_tx_prepare_skb); 113 117
+7 -8
drivers/net/wireless/mediatek/mt76/mt7915/mac.c
··· 1151 1151 } 1152 1152 } 1153 1153 1154 - pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb); 1154 + t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); 1155 + t->skb = tx_info->skb; 1155 1156 1157 + id = mt76_token_consume(mdev, &t); 1158 + if (id < 0) 1159 + return id; 1160 + 1161 + pid = mt76_tx_status_skb_add(mdev, wcid, tx_info->skb); 1156 1162 mt7915_mac_write_txwi(dev, txwi_ptr, tx_info->skb, wcid, pid, key, 1157 1163 false); 1158 1164 ··· 1183 1177 1184 1178 txp->bss_idx = mvif->idx; 1185 1179 } 1186 - 1187 - t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); 1188 - t->skb = tx_info->skb; 1189 - 1190 - id = mt76_token_consume(mdev, &t); 1191 - if (id < 0) 1192 - return id; 1193 1180 1194 1181 txp->token = cpu_to_le16(id); 1195 1182 if (test_bit(MT_WCID_FLAG_4ADDR, &wcid->flags))
+2 -2
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
··· 176 176 if (ht_cap->ht_supported) 177 177 mode |= PHY_MODE_GN; 178 178 179 - if (he_cap->has_he) 179 + if (he_cap && he_cap->has_he) 180 180 mode |= PHY_MODE_AX_24G; 181 181 } else if (band == NL80211_BAND_5GHZ) { 182 182 mode |= PHY_MODE_A; ··· 187 187 if (vht_cap->vht_supported) 188 188 mode |= PHY_MODE_AC; 189 189 190 - if (he_cap->has_he) 190 + if (he_cap && he_cap->has_he) 191 191 mode |= PHY_MODE_AX_5G; 192 192 } 193 193
+12 -9
drivers/net/wireless/mediatek/mt76/mt7921/sdio_mac.c
··· 142 142 static void 143 143 mt7921s_write_txwi(struct mt7921_dev *dev, struct mt76_wcid *wcid, 144 144 enum mt76_txq_id qid, struct ieee80211_sta *sta, 145 + struct ieee80211_key_conf *key, int pid, 145 146 struct sk_buff *skb) 146 147 { 147 - struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 148 - struct ieee80211_key_conf *key = info->control.hw_key; 149 - __le32 *txwi; 150 - int pid; 148 + __le32 *txwi = (__le32 *)(skb->data - MT_SDIO_TXD_SIZE); 151 149 152 - pid = mt76_tx_status_skb_add(&dev->mt76, wcid, skb); 153 - txwi = (__le32 *)(skb->data - MT_SDIO_TXD_SIZE); 154 150 memset(txwi, 0, MT_SDIO_TXD_SIZE); 155 151 mt7921_mac_write_txwi(dev, txwi, skb, wcid, key, pid, false); 156 152 skb_push(skb, MT_SDIO_TXD_SIZE); ··· 159 163 { 160 164 struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76); 161 165 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb); 166 + struct ieee80211_key_conf *key = info->control.hw_key; 162 167 struct sk_buff *skb = tx_info->skb; 163 - int pad; 168 + int err, pad, pktid; 164 169 165 170 if (unlikely(tx_info->skb->len <= ETH_HLEN)) 166 171 return -EINVAL; ··· 178 181 } 179 182 } 180 183 181 - mt7921s_write_txwi(dev, wcid, qid, sta, skb); 184 + pktid = mt76_tx_status_skb_add(&dev->mt76, wcid, skb); 185 + mt7921s_write_txwi(dev, wcid, qid, sta, key, pktid, skb); 182 186 183 187 mt7921_skb_add_sdio_hdr(skb, MT7921_SDIO_DATA); 184 188 pad = round_up(skb->len, 4) - skb->len; 185 189 186 - return mt76_skb_adjust_pad(skb, pad); 190 + err = mt76_skb_adjust_pad(skb, pad); 191 + if (err) 192 + /* Release pktid in case of error. */ 193 + idr_remove(&wcid->pktid, pktid); 194 + 195 + return err; 187 196 } 188 197 189 198 void mt7921s_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue_entry *e)
+1 -1
drivers/net/wireless/mediatek/mt76/tx.c
··· 173 173 if (!(cb->flags & MT_TX_CB_DMA_DONE)) 174 174 continue; 175 175 176 - if (!time_is_after_jiffies(cb->jiffies + 176 + if (time_is_after_jiffies(cb->jiffies + 177 177 MT_TX_STATUS_SKB_TIMEOUT)) 178 178 continue; 179 179 }
+3
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
··· 25 25 if (status == -ENODEV || status == -ENOENT) 26 26 return true; 27 27 28 + if (!test_bit(DEVICE_STATE_STARTED, &rt2x00dev->flags)) 29 + return false; 30 + 28 31 if (status == -EPROTO || status == -ETIMEDOUT) 29 32 rt2x00dev->num_proto_errs++; 30 33 else
+1 -1
drivers/net/wireless/realtek/rtw89/fw.c
··· 91 91 info->section_num = GET_FW_HDR_SEC_NUM(fw); 92 92 info->hdr_len = RTW89_FW_HDR_SIZE + 93 93 info->section_num * RTW89_FW_SECTION_HDR_SIZE; 94 - SET_FW_HDR_PART_SIZE(fw, FWDL_SECTION_PER_PKT_LEN); 95 94 96 95 bin = fw + info->hdr_len; 97 96 ··· 274 275 } 275 276 276 277 skb_put_data(skb, fw, len); 278 + SET_FW_HDR_PART_SIZE(skb->data, FWDL_SECTION_PER_PKT_LEN); 277 279 rtw89_h2c_pkt_set_hdr_fwdl(rtwdev, skb, FWCMD_TYPE_H2C, 278 280 H2C_CAT_MAC, H2C_CL_MAC_FWDL, 279 281 H2C_FUNC_MAC_FWHDR_DL, len);
+4 -2
drivers/net/wireless/realtek/rtw89/fw.h
··· 282 282 le32_get_bits(*((__le32 *)(fwhdr) + 6), GENMASK(15, 8)) 283 283 #define GET_FW_HDR_CMD_VERSERION(fwhdr) \ 284 284 le32_get_bits(*((__le32 *)(fwhdr) + 7), GENMASK(31, 24)) 285 - #define SET_FW_HDR_PART_SIZE(fwhdr, val) \ 286 - le32p_replace_bits((__le32 *)(fwhdr) + 7, val, GENMASK(15, 0)) 285 + static inline void SET_FW_HDR_PART_SIZE(void *fwhdr, u32 val) 286 + { 287 + le32p_replace_bits((__le32 *)fwhdr + 7, val, GENMASK(15, 0)); 288 + } 287 289 288 290 #define SET_CTRL_INFO_MACID(table, val) \ 289 291 le32p_replace_bits((__le32 *)(table) + 0, val, GENMASK(6, 0))
+2 -2
drivers/scsi/mpt3sas/mpt3sas_base.c
··· 639 639 mpi_request->IOCParameter = MPI26_SET_IOC_PARAMETER_SYNC_TIMESTAMP; 640 640 current_time = ktime_get_real(); 641 641 TimeStamp = ktime_to_ms(current_time); 642 - mpi_request->Reserved7 = cpu_to_le32(TimeStamp & 0xFFFFFFFF); 643 - mpi_request->IOCParameterValue = cpu_to_le32(TimeStamp >> 32); 642 + mpi_request->Reserved7 = cpu_to_le32(TimeStamp >> 32); 643 + mpi_request->IOCParameterValue = cpu_to_le32(TimeStamp & 0xFFFFFFFF); 644 644 init_completion(&ioc->scsih_cmds.done); 645 645 ioc->put_smid_default(ioc, smid); 646 646 dinitprintk(ioc, ioc_info(ioc,
+4
drivers/scsi/mpt3sas/mpt3sas_base.h
··· 142 142 143 143 #define MPT_MAX_CALLBACKS 32 144 144 145 + #define MPT_MAX_HBA_NUM_PHYS 32 146 + 145 147 #define INTERNAL_CMDS_COUNT 10 /* reserved cmds */ 146 148 /* reserved for issuing internally framed scsi io cmds */ 147 149 #define INTERNAL_SCSIIO_CMDS_COUNT 3 ··· 800 798 * @enclosure_handle: handle for this a member of an enclosure 801 799 * @device_info: bitwise defining capabilities of this sas_host/expander 802 800 * @responding: used in _scsih_expander_device_mark_responding 801 + * @nr_phys_allocated: Allocated memory for this many count phys 803 802 * @phy: a list of phys that make up this sas_host/expander 804 803 * @sas_port_list: list of ports attached to this sas_host/expander 805 804 * @port: hba port entry containing node's port number info ··· 816 813 u16 enclosure_handle; 817 814 u64 enclosure_logical_id; 818 815 u8 responding; 816 + u8 nr_phys_allocated; 819 817 struct hba_port *port; 820 818 struct _sas_phy *phy; 821 819 struct list_head sas_port_list;
+57 -2
drivers/scsi/mpt3sas/mpt3sas_scsih.c
··· 3869 3869 3870 3870 shost_for_each_device(sdev, ioc->shost) { 3871 3871 sas_device_priv_data = sdev->hostdata; 3872 - if (!sas_device_priv_data) 3872 + if (!sas_device_priv_data || !sas_device_priv_data->sas_target) 3873 3873 continue; 3874 3874 if (sas_device_priv_data->sas_target->sas_address 3875 3875 != sas_address) ··· 6406 6406 int i, j, count = 0, lcount = 0; 6407 6407 int ret; 6408 6408 u64 sas_addr; 6409 + u8 num_phys; 6409 6410 6410 6411 drsprintk(ioc, ioc_info(ioc, 6411 6412 "updating ports for sas_host(0x%016llx)\n", 6412 6413 (unsigned long long)ioc->sas_hba.sas_address)); 6414 + 6415 + mpt3sas_config_get_number_hba_phys(ioc, &num_phys); 6416 + if (!num_phys) { 6417 + ioc_err(ioc, "failure at %s:%d/%s()!\n", 6418 + __FILE__, __LINE__, __func__); 6419 + return; 6420 + } 6421 + 6422 + if (num_phys > ioc->sas_hba.nr_phys_allocated) { 6423 + ioc_err(ioc, "failure at %s:%d/%s()!\n", 6424 + __FILE__, __LINE__, __func__); 6425 + return; 6426 + } 6427 + ioc->sas_hba.num_phys = num_phys; 6413 6428 6414 6429 port_table = kcalloc(ioc->sas_hba.num_phys, 6415 6430 sizeof(struct hba_port), GFP_KERNEL); ··· 6626 6611 ioc->sas_hba.phy[i].hba_vphy = 1; 6627 6612 } 6628 6613 6614 + /* 6615 + * Add new HBA phys to STL if these new phys got added as part 6616 + * of HBA Firmware upgrade/downgrade operation. 6617 + */ 6618 + if (!ioc->sas_hba.phy[i].phy) { 6619 + if ((mpt3sas_config_get_phy_pg0(ioc, &mpi_reply, 6620 + &phy_pg0, i))) { 6621 + ioc_err(ioc, "failure at %s:%d/%s()!\n", 6622 + __FILE__, __LINE__, __func__); 6623 + continue; 6624 + } 6625 + ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & 6626 + MPI2_IOCSTATUS_MASK; 6627 + if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { 6628 + ioc_err(ioc, "failure at %s:%d/%s()!\n", 6629 + __FILE__, __LINE__, __func__); 6630 + continue; 6631 + } 6632 + ioc->sas_hba.phy[i].phy_id = i; 6633 + mpt3sas_transport_add_host_phy(ioc, 6634 + &ioc->sas_hba.phy[i], phy_pg0, 6635 + ioc->sas_hba.parent_dev); 6636 + continue; 6637 + } 6629 6638 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle; 6630 6639 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i]. 6631 6640 AttachedDevHandle); ··· 6660 6621 mpt3sas_transport_update_links(ioc, ioc->sas_hba.sas_address, 6661 6622 attached_handle, i, link_rate, 6662 6623 ioc->sas_hba.phy[i].port); 6624 + } 6625 + /* 6626 + * Clear the phy details if this phy got disabled as part of 6627 + * HBA Firmware upgrade/downgrade operation. 6628 + */ 6629 + for (i = ioc->sas_hba.num_phys; 6630 + i < ioc->sas_hba.nr_phys_allocated; i++) { 6631 + if (ioc->sas_hba.phy[i].phy && 6632 + ioc->sas_hba.phy[i].phy->negotiated_linkrate >= 6633 + SAS_LINK_RATE_1_5_GBPS) 6634 + mpt3sas_transport_update_links(ioc, 6635 + ioc->sas_hba.sas_address, 0, i, 6636 + MPI2_SAS_NEG_LINK_RATE_PHY_DISABLED, NULL); 6663 6637 } 6664 6638 out: 6665 6639 kfree(sas_iounit_pg0); ··· 6706 6654 __FILE__, __LINE__, __func__); 6707 6655 return; 6708 6656 } 6709 - ioc->sas_hba.phy = kcalloc(num_phys, 6657 + 6658 + ioc->sas_hba.nr_phys_allocated = max_t(u8, 6659 + MPT_MAX_HBA_NUM_PHYS, num_phys); 6660 + ioc->sas_hba.phy = kcalloc(ioc->sas_hba.nr_phys_allocated, 6710 6661 sizeof(struct _sas_phy), GFP_KERNEL); 6711 6662 if (!ioc->sas_hba.phy) { 6712 6663 ioc_err(ioc, "failure at %s:%d/%s()!\n",
+1 -1
drivers/scsi/qla2xxx/qla_edif.c
··· 865 865 "APP request entry - portid=%06x.\n", tdid.b24); 866 866 867 867 /* Ran out of space */ 868 - if (pcnt > app_req.num_ports) 868 + if (pcnt >= app_req.num_ports) 869 869 break; 870 870 871 871 if (tdid.b24 != 0 && tdid.b24 != fcport->d_id.b24)
+26 -17
drivers/scsi/scsi_debug.c
··· 1189 1189 __func__, off_dst, scsi_bufflen(scp), act_len, 1190 1190 scsi_get_resid(scp)); 1191 1191 n = scsi_bufflen(scp) - (off_dst + act_len); 1192 - scsi_set_resid(scp, min_t(int, scsi_get_resid(scp), n)); 1192 + scsi_set_resid(scp, min_t(u32, scsi_get_resid(scp), n)); 1193 1193 return 0; 1194 1194 } 1195 1195 ··· 1562 1562 unsigned char pq_pdt; 1563 1563 unsigned char *arr; 1564 1564 unsigned char *cmd = scp->cmnd; 1565 - int alloc_len, n, ret; 1565 + u32 alloc_len, n; 1566 + int ret; 1566 1567 bool have_wlun, is_disk, is_zbc, is_disk_zbc; 1567 1568 1568 1569 alloc_len = get_unaligned_be16(cmd + 3); ··· 1586 1585 kfree(arr); 1587 1586 return check_condition_result; 1588 1587 } else if (0x1 & cmd[1]) { /* EVPD bit set */ 1589 - int lu_id_num, port_group_id, target_dev_id, len; 1588 + int lu_id_num, port_group_id, target_dev_id; 1589 + u32 len; 1590 1590 char lu_id_str[6]; 1591 1591 int host_no = devip->sdbg_host->shost->host_no; 1592 1592 ··· 1678 1676 kfree(arr); 1679 1677 return check_condition_result; 1680 1678 } 1681 - len = min(get_unaligned_be16(arr + 2) + 4, alloc_len); 1679 + len = min_t(u32, get_unaligned_be16(arr + 2) + 4, alloc_len); 1682 1680 ret = fill_from_dev_buffer(scp, arr, 1683 - min(len, SDEBUG_MAX_INQ_ARR_SZ)); 1681 + min_t(u32, len, SDEBUG_MAX_INQ_ARR_SZ)); 1684 1682 kfree(arr); 1685 1683 return ret; 1686 1684 } ··· 1716 1714 } 1717 1715 put_unaligned_be16(0x2100, arr + n); /* SPL-4 no version claimed */ 1718 1716 ret = fill_from_dev_buffer(scp, arr, 1719 - min_t(int, alloc_len, SDEBUG_LONG_INQ_SZ)); 1717 + min_t(u32, alloc_len, SDEBUG_LONG_INQ_SZ)); 1720 1718 kfree(arr); 1721 1719 return ret; 1722 1720 } ··· 1731 1729 unsigned char *cmd = scp->cmnd; 1732 1730 unsigned char arr[SCSI_SENSE_BUFFERSIZE]; /* assume >= 18 bytes */ 1733 1731 bool dsense = !!(cmd[1] & 1); 1734 - int alloc_len = cmd[4]; 1735 - int len = 18; 1732 + u32 alloc_len = cmd[4]; 1733 + u32 len = 18; 1736 1734 int stopped_state = atomic_read(&devip->stopped); 1737 1735 1738 1736 memset(arr, 0, sizeof(arr)); ··· 1776 1774 arr[7] = 0xa; 1777 1775 } 1778 1776 } 1779 - return fill_from_dev_buffer(scp, arr, min_t(int, len, alloc_len)); 1777 + return fill_from_dev_buffer(scp, arr, min_t(u32, len, alloc_len)); 1780 1778 } 1781 1779 1782 1780 static int resp_start_stop(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ··· 2314 2312 { 2315 2313 int pcontrol, pcode, subpcode, bd_len; 2316 2314 unsigned char dev_spec; 2317 - int alloc_len, offset, len, target_dev_id; 2315 + u32 alloc_len, offset, len; 2316 + int target_dev_id; 2318 2317 int target = scp->device->id; 2319 2318 unsigned char *ap; 2320 2319 unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; ··· 2471 2468 arr[0] = offset - 1; 2472 2469 else 2473 2470 put_unaligned_be16((offset - 2), arr + 0); 2474 - return fill_from_dev_buffer(scp, arr, min_t(int, alloc_len, offset)); 2471 + return fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, offset)); 2475 2472 } 2476 2473 2477 2474 #define SDEBUG_MAX_MSELECT_SZ 512 ··· 2502 2499 __func__, param_len, res); 2503 2500 md_len = mselect6 ? (arr[0] + 1) : (get_unaligned_be16(arr + 0) + 2); 2504 2501 bd_len = mselect6 ? arr[3] : get_unaligned_be16(arr + 6); 2505 - if (md_len > 2) { 2502 + off = bd_len + (mselect6 ? 4 : 8); 2503 + if (md_len > 2 || off >= res) { 2506 2504 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); 2507 2505 return check_condition_result; 2508 2506 } 2509 - off = bd_len + (mselect6 ? 4 : 8); 2510 2507 mpage = arr[off] & 0x3f; 2511 2508 ps = !!(arr[off] & 0x80); 2512 2509 if (ps) { ··· 2586 2583 static int resp_log_sense(struct scsi_cmnd *scp, 2587 2584 struct sdebug_dev_info *devip) 2588 2585 { 2589 - int ppc, sp, pcode, subpcode, alloc_len, len, n; 2586 + int ppc, sp, pcode, subpcode; 2587 + u32 alloc_len, len, n; 2590 2588 unsigned char arr[SDEBUG_MAX_LSENSE_SZ]; 2591 2589 unsigned char *cmd = scp->cmnd; 2592 2590 ··· 2657 2653 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); 2658 2654 return check_condition_result; 2659 2655 } 2660 - len = min_t(int, get_unaligned_be16(arr + 2) + 4, alloc_len); 2656 + len = min_t(u32, get_unaligned_be16(arr + 2) + 4, alloc_len); 2661 2657 return fill_from_dev_buffer(scp, arr, 2662 - min_t(int, len, SDEBUG_MAX_INQ_ARR_SZ)); 2658 + min_t(u32, len, SDEBUG_MAX_INQ_ARR_SZ)); 2663 2659 } 2664 2660 2665 2661 static inline bool sdebug_dev_is_zoned(struct sdebug_dev_info *devip) ··· 4434 4430 put_unaligned_be64(sdebug_capacity - 1, arr + 8); 4435 4431 4436 4432 rep_len = (unsigned long)desc - (unsigned long)arr; 4437 - ret = fill_from_dev_buffer(scp, arr, min_t(int, alloc_len, rep_len)); 4433 + ret = fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, rep_len)); 4438 4434 4439 4435 fini: 4440 4436 read_unlock(macc_lckp); ··· 4657 4653 struct sdeb_zone_state *zsp) 4658 4654 { 4659 4655 enum sdebug_z_cond zc; 4656 + struct sdeb_store_info *sip = devip2sip(devip, false); 4660 4657 4661 4658 if (zbc_zone_is_conv(zsp)) 4662 4659 return; ··· 4668 4663 4669 4664 if (zsp->z_cond == ZC4_CLOSED) 4670 4665 devip->nr_closed--; 4666 + 4667 + if (zsp->z_wp > zsp->z_start) 4668 + memset(sip->storep + zsp->z_start * sdebug_sector_size, 0, 4669 + (zsp->z_wp - zsp->z_start) * sdebug_sector_size); 4671 4670 4672 4671 zsp->z_non_seq_resource = false; 4673 4672 zsp->z_wp = zsp->z_start;
+1 -1
drivers/scsi/scsi_sysfs.c
··· 812 812 813 813 mutex_lock(&sdev->state_mutex); 814 814 if (sdev->sdev_state == SDEV_RUNNING && state == SDEV_RUNNING) { 815 - ret = count; 815 + ret = 0; 816 816 } else { 817 817 ret = scsi_device_set_state(sdev, state); 818 818 if (ret == 0 && state == SDEV_RUNNING)
+1
drivers/scsi/ufs/ufs-mediatek.c
··· 1189 1189 } 1190 1190 link = device_link_add(dev, &reset_pdev->dev, 1191 1191 DL_FLAG_AUTOPROBE_CONSUMER); 1192 + put_device(&reset_pdev->dev); 1192 1193 if (!link) { 1193 1194 dev_notice(dev, "add reset device_link fail\n"); 1194 1195 goto skip_reset;
+1 -1
drivers/scsi/ufs/ufshpb.c
··· 331 331 cdb[0] = UFSHPB_READ; 332 332 333 333 if (hba->dev_quirks & UFS_DEVICE_QUIRK_SWAP_L2P_ENTRY_FOR_HPB_READ) 334 - ppn_tmp = swab64(ppn); 334 + ppn_tmp = (__force __be64)swab64((__force u64)ppn); 335 335 336 336 /* ppn value is stored as big-endian in the host memory */ 337 337 memcpy(&cdb[6], &ppn_tmp, sizeof(__be64));
-1
drivers/scsi/virtio_scsi.c
··· 977 977 static struct virtio_driver virtio_scsi_driver = { 978 978 .feature_table = features, 979 979 .feature_table_size = ARRAY_SIZE(features), 980 - .suppress_used_validation = true, 981 980 .driver.name = KBUILD_MODNAME, 982 981 .driver.owner = THIS_MODULE, 983 982 .id_table = id_table,
+8 -8
drivers/target/target_core_fabric_configfs.c
··· 520 520 { 521 521 struct se_lun *lun = item_to_lun(item); 522 522 523 - if (!lun || !lun->lun_se_dev) 523 + if (!lun->lun_se_dev) 524 524 return -ENODEV; 525 525 526 526 return core_alua_show_tg_pt_gp_info(lun, page); ··· 531 531 { 532 532 struct se_lun *lun = item_to_lun(item); 533 533 534 - if (!lun || !lun->lun_se_dev) 534 + if (!lun->lun_se_dev) 535 535 return -ENODEV; 536 536 537 537 return core_alua_store_tg_pt_gp_info(lun, page, count); ··· 542 542 { 543 543 struct se_lun *lun = item_to_lun(item); 544 544 545 - if (!lun || !lun->lun_se_dev) 545 + if (!lun->lun_se_dev) 546 546 return -ENODEV; 547 547 548 548 return core_alua_show_offline_bit(lun, page); ··· 553 553 { 554 554 struct se_lun *lun = item_to_lun(item); 555 555 556 - if (!lun || !lun->lun_se_dev) 556 + if (!lun->lun_se_dev) 557 557 return -ENODEV; 558 558 559 559 return core_alua_store_offline_bit(lun, page, count); ··· 564 564 { 565 565 struct se_lun *lun = item_to_lun(item); 566 566 567 - if (!lun || !lun->lun_se_dev) 567 + if (!lun->lun_se_dev) 568 568 return -ENODEV; 569 569 570 570 return core_alua_show_secondary_status(lun, page); ··· 575 575 { 576 576 struct se_lun *lun = item_to_lun(item); 577 577 578 - if (!lun || !lun->lun_se_dev) 578 + if (!lun->lun_se_dev) 579 579 return -ENODEV; 580 580 581 581 return core_alua_store_secondary_status(lun, page, count); ··· 586 586 { 587 587 struct se_lun *lun = item_to_lun(item); 588 588 589 - if (!lun || !lun->lun_se_dev) 589 + if (!lun->lun_se_dev) 590 590 return -ENODEV; 591 591 592 592 return core_alua_show_secondary_write_metadata(lun, page); ··· 597 597 { 598 598 struct se_lun *lun = item_to_lun(item); 599 599 600 - if (!lun || !lun->lun_se_dev) 600 + if (!lun->lun_se_dev) 601 601 return -ENODEV; 602 602 603 603 return core_alua_store_secondary_write_metadata(lun, page, count);
+7 -7
drivers/target/target_core_spc.c
··· 40 40 * 41 41 * See spc4r17 section 6.4.2 Table 135 42 42 */ 43 - spin_lock(&lun->lun_tg_pt_gp_lock); 44 - tg_pt_gp = lun->lun_tg_pt_gp; 43 + rcu_read_lock(); 44 + tg_pt_gp = rcu_dereference(lun->lun_tg_pt_gp); 45 45 if (tg_pt_gp) 46 46 buf[5] |= tg_pt_gp->tg_pt_gp_alua_access_type; 47 - spin_unlock(&lun->lun_tg_pt_gp_lock); 47 + rcu_read_unlock(); 48 48 } 49 49 50 50 static u16 ··· 325 325 * Get the PROTOCOL IDENTIFIER as defined by spc4r17 326 326 * section 7.5.1 Table 362 327 327 */ 328 - spin_lock(&lun->lun_tg_pt_gp_lock); 329 - tg_pt_gp = lun->lun_tg_pt_gp; 328 + rcu_read_lock(); 329 + tg_pt_gp = rcu_dereference(lun->lun_tg_pt_gp); 330 330 if (!tg_pt_gp) { 331 - spin_unlock(&lun->lun_tg_pt_gp_lock); 331 + rcu_read_unlock(); 332 332 goto check_lu_gp; 333 333 } 334 334 tg_pt_gp_id = tg_pt_gp->tg_pt_gp_id; 335 - spin_unlock(&lun->lun_tg_pt_gp_lock); 335 + rcu_read_unlock(); 336 336 337 337 buf[off] = tpg->proto_id << 4; 338 338 buf[off++] |= 0x1; /* CODE SET == Binary */
+3
drivers/usb/core/quirks.c
··· 434 434 { USB_DEVICE(0x1532, 0x0116), .driver_info = 435 435 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, 436 436 437 + /* Lenovo Powered USB-C Travel Hub (4X90S92381, RTL8153 GigE) */ 438 + { USB_DEVICE(0x17ef, 0x721e), .driver_info = USB_QUIRK_NO_LPM }, 439 + 437 440 /* Lenovo ThinkCenter A630Z TI024Gen3 usb-audio */ 438 441 { USB_DEVICE(0x17ef, 0xa012), .driver_info = 439 442 USB_QUIRK_DISCONNECT_SUSPEND },
+5 -2
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 591 591 vringh_kiov_cleanup(&vdpasim->vqs[i].in_iov); 592 592 } 593 593 594 - put_iova_domain(&vdpasim->iova); 595 - iova_cache_put(); 594 + if (vdpa_get_dma_dev(vdpa)) { 595 + put_iova_domain(&vdpasim->iova); 596 + iova_cache_put(); 597 + } 598 + 596 599 kvfree(vdpasim->buffer); 597 600 if (vdpasim->iommu) 598 601 vhost_iotlb_free(vdpasim->iommu);
+1 -1
drivers/vhost/vdpa.c
··· 1014 1014 1015 1015 mutex_lock(&d->mutex); 1016 1016 filep->private_data = NULL; 1017 + vhost_vdpa_clean_irq(v); 1017 1018 vhost_vdpa_reset(v); 1018 1019 vhost_dev_stop(&v->vdev); 1019 1020 vhost_vdpa_iotlb_free(v); 1020 1021 vhost_vdpa_free_domain(v); 1021 1022 vhost_vdpa_config_put(v); 1022 - vhost_vdpa_clean_irq(v); 1023 1023 vhost_dev_cleanup(&v->vdev); 1024 1024 kfree(v->vdev.vqs); 1025 1025 mutex_unlock(&d->mutex);
+2 -6
drivers/vhost/vsock.c
··· 511 511 512 512 vhost_disable_notify(&vsock->dev, vq); 513 513 do { 514 - u32 len; 515 - 516 514 if (!vhost_vsock_more_replies(vsock)) { 517 515 /* Stop tx until the device processes already 518 516 * pending replies. Leave tx virtqueue ··· 538 540 continue; 539 541 } 540 542 541 - len = pkt->len; 543 + total_len += sizeof(pkt->hdr) + pkt->len; 542 544 543 545 /* Deliver to monitoring devices all received packets */ 544 546 virtio_transport_deliver_tap_pkt(pkt); ··· 551 553 else 552 554 virtio_transport_free_pkt(pkt); 553 555 554 - len += sizeof(pkt->hdr); 555 - vhost_add_used(vq, head, len); 556 - total_len += len; 556 + vhost_add_used(vq, head, 0); 557 557 added = true; 558 558 } while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len))); 559 559
-60
drivers/virtio/virtio_ring.c
··· 14 14 #include <linux/spinlock.h> 15 15 #include <xen/xen.h> 16 16 17 - static bool force_used_validation = false; 18 - module_param(force_used_validation, bool, 0444); 19 - 20 17 #ifdef DEBUG 21 18 /* For development, we want to crash whenever the ring is screwed. */ 22 19 #define BAD_RING(_vq, fmt, args...) \ ··· 181 184 size_t event_size_in_bytes; 182 185 } packed; 183 186 }; 184 - 185 - /* Per-descriptor in buffer length */ 186 - u32 *buflen; 187 187 188 188 /* How to notify other side. FIXME: commonalize hcalls! */ 189 189 bool (*notify)(struct virtqueue *vq); ··· 490 496 unsigned int i, n, avail, descs_used, prev, err_idx; 491 497 int head; 492 498 bool indirect; 493 - u32 buflen = 0; 494 499 495 500 START_USE(vq); 496 501 ··· 571 578 VRING_DESC_F_NEXT | 572 579 VRING_DESC_F_WRITE, 573 580 indirect); 574 - buflen += sg->length; 575 581 } 576 582 } 577 583 /* Last one doesn't continue. */ ··· 609 617 vq->split.desc_state[head].indir_desc = desc; 610 618 else 611 619 vq->split.desc_state[head].indir_desc = ctx; 612 - 613 - /* Store in buffer length if necessary */ 614 - if (vq->buflen) 615 - vq->buflen[head] = buflen; 616 620 617 621 /* Put entry in available array (but don't update avail->idx until they 618 622 * do sync). */ ··· 782 794 } 783 795 if (unlikely(!vq->split.desc_state[i].data)) { 784 796 BAD_RING(vq, "id %u is not a head!\n", i); 785 - return NULL; 786 - } 787 - if (vq->buflen && unlikely(*len > vq->buflen[i])) { 788 - BAD_RING(vq, "used len %d is larger than in buflen %u\n", 789 - *len, vq->buflen[i]); 790 797 return NULL; 791 798 } 792 799 ··· 1062 1079 unsigned int i, n, err_idx; 1063 1080 u16 head, id; 1064 1081 dma_addr_t addr; 1065 - u32 buflen = 0; 1066 1082 1067 1083 head = vq->packed.next_avail_idx; 1068 1084 desc = alloc_indirect_packed(total_sg, gfp); ··· 1091 1109 desc[i].addr = cpu_to_le64(addr); 1092 1110 desc[i].len = cpu_to_le32(sg->length); 1093 1111 i++; 1094 - if (n >= out_sgs) 1095 - buflen += sg->length; 1096 1112 } 1097 1113 } 1098 1114 ··· 1144 1164 vq->packed.desc_state[id].indir_desc = desc; 1145 1165 vq->packed.desc_state[id].last = id; 1146 1166 1147 - /* Store in buffer length if necessary */ 1148 - if (vq->buflen) 1149 - vq->buflen[id] = buflen; 1150 - 1151 1167 vq->num_added += 1; 1152 1168 1153 1169 pr_debug("Added buffer head %i to %p\n", head, vq); ··· 1179 1203 __le16 head_flags, flags; 1180 1204 u16 head, id, prev, curr, avail_used_flags; 1181 1205 int err; 1182 - u32 buflen = 0; 1183 1206 1184 1207 START_USE(vq); 1185 1208 ··· 1258 1283 1 << VRING_PACKED_DESC_F_AVAIL | 1259 1284 1 << VRING_PACKED_DESC_F_USED; 1260 1285 } 1261 - if (n >= out_sgs) 1262 - buflen += sg->length; 1263 1286 } 1264 1287 } 1265 1288 ··· 1276 1303 vq->packed.desc_state[id].data = data; 1277 1304 vq->packed.desc_state[id].indir_desc = ctx; 1278 1305 vq->packed.desc_state[id].last = prev; 1279 - 1280 - /* Store in buffer length if necessary */ 1281 - if (vq->buflen) 1282 - vq->buflen[id] = buflen; 1283 1306 1284 1307 /* 1285 1308 * A driver MUST NOT make the first descriptor in the list ··· 1461 1492 } 1462 1493 if (unlikely(!vq->packed.desc_state[id].data)) { 1463 1494 BAD_RING(vq, "id %u is not a head!\n", id); 1464 - return NULL; 1465 - } 1466 - if (vq->buflen && unlikely(*len > vq->buflen[id])) { 1467 - BAD_RING(vq, "used len %d is larger than in buflen %u\n", 1468 - *len, vq->buflen[id]); 1469 1495 return NULL; 1470 1496 } 1471 1497 ··· 1668 1704 struct vring_virtqueue *vq; 1669 1705 struct vring_packed_desc *ring; 1670 1706 struct vring_packed_desc_event *driver, *device; 1671 - struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver); 1672 1707 dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; 1673 1708 size_t ring_size_in_bytes, event_size_in_bytes; 1674 1709 ··· 1757 1794 if (!vq->packed.desc_extra) 1758 1795 goto err_desc_extra; 1759 1796 1760 - if (!drv->suppress_used_validation || force_used_validation) { 1761 - vq->buflen = kmalloc_array(num, sizeof(*vq->buflen), 1762 - GFP_KERNEL); 1763 - if (!vq->buflen) 1764 - goto err_buflen; 1765 - } else { 1766 - vq->buflen = NULL; 1767 - } 1768 - 1769 1797 /* No callback? Tell other side not to bother us. */ 1770 1798 if (!callback) { 1771 1799 vq->packed.event_flags_shadow = VRING_PACKED_EVENT_FLAG_DISABLE; ··· 1769 1815 spin_unlock(&vdev->vqs_list_lock); 1770 1816 return &vq->vq; 1771 1817 1772 - err_buflen: 1773 - kfree(vq->packed.desc_extra); 1774 1818 err_desc_extra: 1775 1819 kfree(vq->packed.desc_state); 1776 1820 err_desc_state: ··· 2176 2224 void (*callback)(struct virtqueue *), 2177 2225 const char *name) 2178 2226 { 2179 - struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver); 2180 2227 struct vring_virtqueue *vq; 2181 2228 2182 2229 if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) ··· 2235 2284 if (!vq->split.desc_extra) 2236 2285 goto err_extra; 2237 2286 2238 - if (!drv->suppress_used_validation || force_used_validation) { 2239 - vq->buflen = kmalloc_array(vring.num, sizeof(*vq->buflen), 2240 - GFP_KERNEL); 2241 - if (!vq->buflen) 2242 - goto err_buflen; 2243 - } else { 2244 - vq->buflen = NULL; 2245 - } 2246 - 2247 2287 /* Put everything in free lists. */ 2248 2288 vq->free_head = 0; 2249 2289 memset(vq->split.desc_state, 0, vring.num * ··· 2245 2303 spin_unlock(&vdev->vqs_list_lock); 2246 2304 return &vq->vq; 2247 2305 2248 - err_buflen: 2249 - kfree(vq->split.desc_extra); 2250 2306 err_extra: 2251 2307 kfree(vq->split.desc_state); 2252 2308 err_state:
+6 -2
fs/erofs/utils.c
··· 150 150 * however in order to avoid some race conditions, add a 151 151 * DBG_BUGON to observe this in advance. 152 152 */ 153 - DBG_BUGON(xa_erase(&sbi->managed_pslots, grp->index) != grp); 153 + DBG_BUGON(__xa_erase(&sbi->managed_pslots, grp->index) != grp); 154 154 155 155 /* last refcount should be connected with its managed pslot. */ 156 156 erofs_workgroup_unfreeze(grp, 0); ··· 165 165 unsigned int freed = 0; 166 166 unsigned long index; 167 167 168 + xa_lock(&sbi->managed_pslots); 168 169 xa_for_each(&sbi->managed_pslots, index, grp) { 169 170 /* try to shrink each valid workgroup */ 170 171 if (!erofs_try_to_release_workgroup(sbi, grp)) 171 172 continue; 173 + xa_unlock(&sbi->managed_pslots); 172 174 173 175 ++freed; 174 176 if (!--nr_shrink) 175 - break; 177 + return freed; 178 + xa_lock(&sbi->managed_pslots); 176 179 } 180 + xa_unlock(&sbi->managed_pslots); 177 181 return freed; 178 182 } 179 183
+50 -23
fs/io_uring.c
··· 1278 1278 1279 1279 static bool io_match_task(struct io_kiocb *head, struct task_struct *task, 1280 1280 bool cancel_all) 1281 + __must_hold(&req->ctx->timeout_lock) 1281 1282 { 1282 1283 struct io_kiocb *req; 1283 1284 ··· 1292 1291 return true; 1293 1292 } 1294 1293 return false; 1294 + } 1295 + 1296 + static bool io_match_linked(struct io_kiocb *head) 1297 + { 1298 + struct io_kiocb *req; 1299 + 1300 + io_for_each_link(req, head) { 1301 + if (req->flags & REQ_F_INFLIGHT) 1302 + return true; 1303 + } 1304 + return false; 1305 + } 1306 + 1307 + /* 1308 + * As io_match_task() but protected against racing with linked timeouts. 1309 + * User must not hold timeout_lock. 1310 + */ 1311 + static bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task, 1312 + bool cancel_all) 1313 + { 1314 + bool matched; 1315 + 1316 + if (task && head->task != task) 1317 + return false; 1318 + if (cancel_all) 1319 + return true; 1320 + 1321 + if (head->flags & REQ_F_LINK_TIMEOUT) { 1322 + struct io_ring_ctx *ctx = head->ctx; 1323 + 1324 + /* protect against races with linked timeouts */ 1325 + spin_lock_irq(&ctx->timeout_lock); 1326 + matched = io_match_linked(head); 1327 + spin_unlock_irq(&ctx->timeout_lock); 1328 + } else { 1329 + matched = io_match_linked(head); 1330 + } 1331 + return matched; 1295 1332 } 1296 1333 1297 1334 static inline bool req_has_async_data(struct io_kiocb *req) ··· 4366 4327 kfree(nxt); 4367 4328 if (++i == nbufs) 4368 4329 return i; 4330 + cond_resched(); 4369 4331 } 4370 4332 i++; 4371 4333 kfree(buf); ··· 5739 5699 int posted = 0, i; 5740 5700 5741 5701 spin_lock(&ctx->completion_lock); 5742 - spin_lock_irq(&ctx->timeout_lock); 5743 5702 for (i = 0; i < (1U << ctx->cancel_hash_bits); i++) { 5744 5703 struct hlist_head *list; 5745 5704 5746 5705 list = &ctx->cancel_hash[i]; 5747 5706 hlist_for_each_entry_safe(req, tmp, list, hash_node) { 5748 - if (io_match_task(req, tsk, cancel_all)) 5707 + if (io_match_task_safe(req, tsk, cancel_all)) 5749 5708 posted += io_poll_remove_one(req); 5750 5709 } 5751 5710 } 5752 - spin_unlock_irq(&ctx->timeout_lock); 5753 5711 spin_unlock(&ctx->completion_lock); 5754 5712 5755 5713 if (posted) ··· 6195 6157 6196 6158 if (get_timespec64(&data->ts, u64_to_user_ptr(sqe->addr))) 6197 6159 return -EFAULT; 6160 + 6161 + if (data->ts.tv_sec < 0 || data->ts.tv_nsec < 0) 6162 + return -EINVAL; 6198 6163 6199 6164 data->mode = io_translate_timeout_mode(flags); 6200 6165 hrtimer_init(&data->timer, io_timeout_get_clock(data), data->mode); ··· 6923 6882 static void io_req_task_link_timeout(struct io_kiocb *req, bool *locked) 6924 6883 { 6925 6884 struct io_kiocb *prev = req->timeout.prev; 6926 - int ret; 6885 + int ret = -ENOENT; 6927 6886 6928 6887 if (prev) { 6929 - ret = io_try_cancel_userdata(req, prev->user_data); 6888 + if (!(req->task->flags & PF_EXITING)) 6889 + ret = io_try_cancel_userdata(req, prev->user_data); 6930 6890 io_req_complete_post(req, ret ?: -ETIME, 0); 6931 6891 io_put_req(prev); 6932 6892 } else { ··· 9299 9257 struct io_buffer *buf; 9300 9258 unsigned long index; 9301 9259 9302 - xa_for_each(&ctx->io_buffers, index, buf) { 9260 + xa_for_each(&ctx->io_buffers, index, buf) 9303 9261 __io_remove_buffers(ctx, buf, index, -1U); 9304 - cond_resched(); 9305 - } 9306 9262 } 9307 9263 9308 9264 static void io_req_caches_free(struct io_ring_ctx *ctx) ··· 9604 9564 { 9605 9565 struct io_kiocb *req = container_of(work, struct io_kiocb, work); 9606 9566 struct io_task_cancel *cancel = data; 9607 - bool ret; 9608 9567 9609 - if (!cancel->all && (req->flags & REQ_F_LINK_TIMEOUT)) { 9610 - struct io_ring_ctx *ctx = req->ctx; 9611 - 9612 - /* protect against races with linked timeouts */ 9613 - spin_lock_irq(&ctx->timeout_lock); 9614 - ret = io_match_task(req, cancel->task, cancel->all); 9615 - spin_unlock_irq(&ctx->timeout_lock); 9616 - } else { 9617 - ret = io_match_task(req, cancel->task, cancel->all); 9618 - } 9619 - return ret; 9568 + return io_match_task_safe(req, cancel->task, cancel->all); 9620 9569 } 9621 9570 9622 9571 static __cold bool io_cancel_defer_files(struct io_ring_ctx *ctx, ··· 9616 9587 LIST_HEAD(list); 9617 9588 9618 9589 spin_lock(&ctx->completion_lock); 9619 - spin_lock_irq(&ctx->timeout_lock); 9620 9590 list_for_each_entry_reverse(de, &ctx->defer_list, list) { 9621 - if (io_match_task(de->req, task, cancel_all)) { 9591 + if (io_match_task_safe(de->req, task, cancel_all)) { 9622 9592 list_cut_position(&list, &ctx->defer_list, &de->list); 9623 9593 break; 9624 9594 } 9625 9595 } 9626 - spin_unlock_irq(&ctx->timeout_lock); 9627 9596 spin_unlock(&ctx->completion_lock); 9628 9597 if (list_empty(&list)) 9629 9598 return false;
+16 -10
fs/iomap/buffered-io.c
··· 205 205 struct readahead_control *rac; 206 206 }; 207 207 208 - static loff_t iomap_read_inline_data(const struct iomap_iter *iter, 208 + /** 209 + * iomap_read_inline_data - copy inline data into the page cache 210 + * @iter: iteration structure 211 + * @page: page to copy to 212 + * 213 + * Copy the inline data in @iter into @page and zero out the rest of the page. 214 + * Only a single IOMAP_INLINE extent is allowed at the end of each file. 215 + * Returns zero for success to complete the read, or the usual negative errno. 216 + */ 217 + static int iomap_read_inline_data(const struct iomap_iter *iter, 209 218 struct page *page) 210 219 { 211 220 const struct iomap *iomap = iomap_iter_srcmap(iter); ··· 223 214 void *addr; 224 215 225 216 if (PageUptodate(page)) 226 - return PAGE_SIZE - poff; 217 + return 0; 227 218 228 219 if (WARN_ON_ONCE(size > PAGE_SIZE - poff)) 229 220 return -EIO; ··· 240 231 memset(addr + size, 0, PAGE_SIZE - poff - size); 241 232 kunmap_local(addr); 242 233 iomap_set_range_uptodate(page, poff, PAGE_SIZE - poff); 243 - return PAGE_SIZE - poff; 234 + return 0; 244 235 } 245 236 246 237 static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter, ··· 266 257 sector_t sector; 267 258 268 259 if (iomap->type == IOMAP_INLINE) 269 - return min(iomap_read_inline_data(iter, page), length); 260 + return iomap_read_inline_data(iter, page); 270 261 271 262 /* zero post-eof blocks as the page may be mapped */ 272 263 iop = iomap_page_create(iter->inode, page); ··· 379 370 ctx->cur_page_in_bio = false; 380 371 } 381 372 ret = iomap_readpage_iter(iter, ctx, done); 373 + if (ret <= 0) 374 + return ret; 382 375 } 383 376 384 377 return done; ··· 591 580 static int iomap_write_begin_inline(const struct iomap_iter *iter, 592 581 struct page *page) 593 582 { 594 - int ret; 595 - 596 583 /* needs more work for the tailpacking case; disable for now */ 597 584 if (WARN_ON_ONCE(iomap_iter_srcmap(iter)->offset != 0)) 598 585 return -EIO; 599 - ret = iomap_read_inline_data(iter, page); 600 - if (ret < 0) 601 - return ret; 602 - return 0; 586 + return iomap_read_inline_data(iter, page); 603 587 } 604 588 605 589 static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
+17 -13
fs/ksmbd/smb2pdu.c
··· 1697 1697 negblob_off = le16_to_cpu(req->SecurityBufferOffset); 1698 1698 negblob_len = le16_to_cpu(req->SecurityBufferLength); 1699 1699 if (negblob_off < offsetof(struct smb2_sess_setup_req, Buffer) || 1700 - negblob_len < offsetof(struct negotiate_message, NegotiateFlags)) 1701 - return -EINVAL; 1700 + negblob_len < offsetof(struct negotiate_message, NegotiateFlags)) { 1701 + rc = -EINVAL; 1702 + goto out_err; 1703 + } 1702 1704 1703 1705 negblob = (struct negotiate_message *)((char *)&req->hdr.ProtocolId + 1704 1706 negblob_off); ··· 4459 4457 &stat); 4460 4458 file_info = (struct smb2_file_stream_info *)rsp->Buffer; 4461 4459 4460 + buf_free_len = 4461 + smb2_calc_max_out_buf_len(work, 8, 4462 + le32_to_cpu(req->OutputBufferLength)); 4463 + if (buf_free_len < 0) 4464 + goto out; 4465 + 4462 4466 xattr_list_len = ksmbd_vfs_listxattr(path->dentry, &xattr_list); 4463 4467 if (xattr_list_len < 0) { 4464 4468 goto out; ··· 4472 4464 ksmbd_debug(SMB, "empty xattr in the file\n"); 4473 4465 goto out; 4474 4466 } 4475 - 4476 - buf_free_len = 4477 - smb2_calc_max_out_buf_len(work, 8, 4478 - le32_to_cpu(req->OutputBufferLength)); 4479 - if (buf_free_len < 0) 4480 - goto out; 4481 4467 4482 4468 while (idx < xattr_list_len) { 4483 4469 stream_name = xattr_list + idx; ··· 4498 4496 ":%s", &stream_name[XATTR_NAME_STREAM_LEN]); 4499 4497 4500 4498 next = sizeof(struct smb2_file_stream_info) + streamlen * 2; 4501 - if (next > buf_free_len) 4499 + if (next > buf_free_len) { 4500 + kfree(stream_buf); 4502 4501 break; 4502 + } 4503 4503 4504 4504 file_info = (struct smb2_file_stream_info *)&rsp->Buffer[nbytes]; 4505 4505 streamlen = smbConvertToUTF16((__le16 *)file_info->StreamName, ··· 4518 4514 file_info->NextEntryOffset = cpu_to_le32(next); 4519 4515 } 4520 4516 4517 + out: 4521 4518 if (!S_ISDIR(stat.mode) && 4522 4519 buf_free_len >= sizeof(struct smb2_file_stream_info) + 7 * 2) { 4523 4520 file_info = (struct smb2_file_stream_info *) ··· 4527 4522 "::$DATA", 7, conn->local_nls, 0); 4528 4523 streamlen *= 2; 4529 4524 file_info->StreamNameLength = cpu_to_le32(streamlen); 4530 - file_info->StreamSize = 0; 4531 - file_info->StreamAllocationSize = 0; 4525 + file_info->StreamSize = cpu_to_le64(stat.size); 4526 + file_info->StreamAllocationSize = cpu_to_le64(stat.blocks << 9); 4532 4527 nbytes += sizeof(struct smb2_file_stream_info) + streamlen; 4533 4528 } 4534 4529 4535 4530 /* last entry offset should be 0 */ 4536 4531 file_info->NextEntryOffset = 0; 4537 - out: 4538 4532 kvfree(xattr_list); 4539 4533 4540 4534 rsp->OutputBufferLength = cpu_to_le32(nbytes); ··· 5072 5068 if (addition_info & ~(OWNER_SECINFO | GROUP_SECINFO | DACL_SECINFO | 5073 5069 PROTECTED_DACL_SECINFO | 5074 5070 UNPROTECTED_DACL_SECINFO)) { 5075 - pr_err("Unsupported addition info: 0x%x)\n", 5071 + ksmbd_debug(SMB, "Unsupported addition info: 0x%x)\n", 5076 5072 addition_info); 5077 5073 5078 5074 pntsd->revision = cpu_to_le16(1);
+2 -2
fs/netfs/read_helper.c
··· 1008 1008 } 1009 1009 EXPORT_SYMBOL(netfs_readpage); 1010 1010 1011 - /** 1012 - * netfs_skip_folio_read - prep a folio for writing without reading first 1011 + /* 1012 + * Prepare a folio for writing without reading first 1013 1013 * @folio: The folio being prepared 1014 1014 * @pos: starting position for the write 1015 1015 * @len: length of write
+1
fs/nfs/inode.c
··· 219 219 NFS_INO_DATA_INVAL_DEFER); 220 220 else if (nfsi->cache_validity & NFS_INO_INVALID_DATA) 221 221 nfsi->cache_validity &= ~NFS_INO_DATA_INVAL_DEFER; 222 + trace_nfs_set_cache_invalid(inode, 0); 222 223 } 223 224 EXPORT_SYMBOL_GPL(nfs_set_cache_invalid); 224 225
+3 -1
fs/nfs/nfs42proc.c
··· 289 289 loff_t newsize = pos + len; 290 290 loff_t end = newsize - 1; 291 291 292 - truncate_pagecache_range(inode, pos, end); 292 + WARN_ON_ONCE(invalidate_inode_pages2_range(inode->i_mapping, 293 + pos >> PAGE_SHIFT, end >> PAGE_SHIFT)); 294 + 293 295 spin_lock(&inode->i_lock); 294 296 if (newsize > i_size_read(inode)) 295 297 i_size_write(inode, newsize);
+1 -2
fs/nfs/nfs42xdr.c
··· 1434 1434 status = decode_clone(xdr); 1435 1435 if (status) 1436 1436 goto out; 1437 - status = decode_getfattr(xdr, res->dst_fattr, res->server); 1438 - 1437 + decode_getfattr(xdr, res->dst_fattr, res->server); 1439 1438 out: 1440 1439 res->rpc_status = status; 1441 1440 return status;
+4
fs/nfs/nfs4state.c
··· 1998 1998 dprintk("%s: exit with error %d for server %s\n", 1999 1999 __func__, -EPROTONOSUPPORT, clp->cl_hostname); 2000 2000 return -EPROTONOSUPPORT; 2001 + case -ENOSPC: 2002 + if (clp->cl_cons_state == NFS_CS_SESSION_INITING) 2003 + nfs_mark_client_ready(clp, -EIO); 2004 + return -EIO; 2001 2005 case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery 2002 2006 * in nfs4_exchange_id */ 2003 2007 default:
+1
fs/nfs/nfstrace.h
··· 162 162 DEFINE_NFS_INODE_EVENT(nfs_fsync_enter); 163 163 DEFINE_NFS_INODE_EVENT_DONE(nfs_fsync_exit); 164 164 DEFINE_NFS_INODE_EVENT(nfs_access_enter); 165 + DEFINE_NFS_INODE_EVENT_DONE(nfs_set_cache_invalid); 165 166 166 167 TRACE_EVENT(nfs_access_exit, 167 168 TP_PROTO(
+1
fs/ntfs/Kconfig
··· 52 52 config NTFS_RW 53 53 bool "NTFS write support" 54 54 depends on NTFS_FS 55 + depends on PAGE_SIZE_LESS_THAN_64KB 55 56 help 56 57 This enables the partial, but safe, write support in the NTFS driver. 57 58
+7 -10
fs/xfs/libxfs/xfs_attr.c
··· 1077 1077 1078 1078 state = xfs_da_state_alloc(args); 1079 1079 if (statep != NULL) 1080 - *statep = NULL; 1080 + *statep = state; 1081 1081 1082 1082 /* 1083 1083 * Search to see if name exists, and get back a pointer to it. 1084 1084 */ 1085 1085 error = xfs_da3_node_lookup_int(state, &retval); 1086 - if (error) { 1087 - xfs_da_state_free(state); 1088 - return error; 1089 - } 1086 + if (error) 1087 + retval = error; 1090 1088 1091 - if (statep != NULL) 1092 - *statep = state; 1093 - else 1089 + if (!statep) 1094 1090 xfs_da_state_free(state); 1091 + 1095 1092 return retval; 1096 1093 } 1097 1094 ··· 1109 1112 */ 1110 1113 retval = xfs_attr_node_hasname(args, &dac->da_state); 1111 1114 if (retval != -ENOATTR && retval != -EEXIST) 1112 - return retval; 1115 + goto error; 1113 1116 1114 1117 if (retval == -ENOATTR && (args->attr_flags & XATTR_REPLACE)) 1115 1118 goto error; ··· 1334 1337 1335 1338 error = xfs_attr_node_hasname(args, state); 1336 1339 if (error != -EEXIST) 1337 - return error; 1340 + goto out; 1338 1341 error = 0; 1339 1342 1340 1343 ASSERT((*state)->path.blk[(*state)->path.active - 1].bp != NULL);
-21
fs/xfs/xfs_icache.c
··· 289 289 trace_xfs_perag_clear_inode_tag(mp, pag->pag_agno, tag, _RET_IP_); 290 290 } 291 291 292 - static inline void 293 - xfs_inew_wait( 294 - struct xfs_inode *ip) 295 - { 296 - wait_queue_head_t *wq = bit_waitqueue(&ip->i_flags, __XFS_INEW_BIT); 297 - DEFINE_WAIT_BIT(wait, &ip->i_flags, __XFS_INEW_BIT); 298 - 299 - do { 300 - prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); 301 - if (!xfs_iflags_test(ip, XFS_INEW)) 302 - break; 303 - schedule(); 304 - } while (true); 305 - finish_wait(wq, &wait.wq_entry); 306 - } 307 - 308 292 /* 309 293 * When we recycle a reclaimable inode, we need to re-initialise the VFS inode 310 294 * part of the structure. This is made more complex by the fact we store ··· 352 368 ASSERT(!rwsem_is_locked(&inode->i_rwsem)); 353 369 error = xfs_reinit_inode(mp, inode); 354 370 if (error) { 355 - bool wake; 356 - 357 371 /* 358 372 * Re-initializing the inode failed, and we are in deep 359 373 * trouble. Try to re-add it to the reclaim list. 360 374 */ 361 375 rcu_read_lock(); 362 376 spin_lock(&ip->i_flags_lock); 363 - wake = !!__xfs_iflags_test(ip, XFS_INEW); 364 377 ip->i_flags &= ~(XFS_INEW | XFS_IRECLAIM); 365 - if (wake) 366 - wake_up_bit(&ip->i_flags, __XFS_INEW_BIT); 367 378 ASSERT(ip->i_flags & XFS_IRECLAIMABLE); 368 379 spin_unlock(&ip->i_flags_lock); 369 380 rcu_read_unlock();
+1 -3
fs/xfs/xfs_inode.h
··· 231 231 #define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */ 232 232 #define XFS_ISTALE (1 << 1) /* inode has been staled */ 233 233 #define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */ 234 - #define __XFS_INEW_BIT 3 /* inode has just been allocated */ 235 - #define XFS_INEW (1 << __XFS_INEW_BIT) 234 + #define XFS_INEW (1 << 3) /* inode has just been allocated */ 236 235 #define XFS_IPRESERVE_DM_FIELDS (1 << 4) /* has legacy DMAPI fields set */ 237 236 #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */ 238 237 #define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */ ··· 491 492 xfs_iflags_clear(ip, XFS_INEW); 492 493 barrier(); 493 494 unlock_new_inode(VFS_I(ip)); 494 - wake_up_bit(&ip->i_flags, __XFS_INEW_BIT); 495 495 } 496 496 497 497 static inline void xfs_setup_existing_inode(struct xfs_inode *ip)
+2
include/linux/kprobes.h
··· 153 153 struct kretprobe_holder *rph; 154 154 }; 155 155 156 + #define KRETPROBE_MAX_DATA_SIZE 4096 157 + 156 158 struct kretprobe_instance { 157 159 union { 158 160 struct freelist_node freelist;
+4 -1
include/linux/mlx5/mlx5_ifc.h
··· 9698 9698 u8 regs_84_to_68[0x11]; 9699 9699 u8 tracer_registers[0x4]; 9700 9700 9701 - u8 regs_63_to_32[0x20]; 9701 + u8 regs_63_to_46[0x12]; 9702 + u8 mrtc[0x1]; 9703 + u8 regs_44_to_32[0xd]; 9704 + 9702 9705 u8 regs_31_to_0[0x20]; 9703 9706 }; 9704 9707
+13 -6
include/linux/netdevice.h
··· 4053 4053 static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu) 4054 4054 { 4055 4055 spin_lock(&txq->_xmit_lock); 4056 - txq->xmit_lock_owner = cpu; 4056 + /* Pairs with READ_ONCE() in __dev_queue_xmit() */ 4057 + WRITE_ONCE(txq->xmit_lock_owner, cpu); 4057 4058 } 4058 4059 4059 4060 static inline bool __netif_tx_acquire(struct netdev_queue *txq) ··· 4071 4070 static inline void __netif_tx_lock_bh(struct netdev_queue *txq) 4072 4071 { 4073 4072 spin_lock_bh(&txq->_xmit_lock); 4074 - txq->xmit_lock_owner = smp_processor_id(); 4073 + /* Pairs with READ_ONCE() in __dev_queue_xmit() */ 4074 + WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id()); 4075 4075 } 4076 4076 4077 4077 static inline bool __netif_tx_trylock(struct netdev_queue *txq) 4078 4078 { 4079 4079 bool ok = spin_trylock(&txq->_xmit_lock); 4080 - if (likely(ok)) 4081 - txq->xmit_lock_owner = smp_processor_id(); 4080 + 4081 + if (likely(ok)) { 4082 + /* Pairs with READ_ONCE() in __dev_queue_xmit() */ 4083 + WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id()); 4084 + } 4082 4085 return ok; 4083 4086 } 4084 4087 4085 4088 static inline void __netif_tx_unlock(struct netdev_queue *txq) 4086 4089 { 4087 - txq->xmit_lock_owner = -1; 4090 + /* Pairs with READ_ONCE() in __dev_queue_xmit() */ 4091 + WRITE_ONCE(txq->xmit_lock_owner, -1); 4088 4092 spin_unlock(&txq->_xmit_lock); 4089 4093 } 4090 4094 4091 4095 static inline void __netif_tx_unlock_bh(struct netdev_queue *txq) 4092 4096 { 4093 - txq->xmit_lock_owner = -1; 4097 + /* Pairs with READ_ONCE() in __dev_queue_xmit() */ 4098 + WRITE_ONCE(txq->xmit_lock_owner, -1); 4094 4099 spin_unlock_bh(&txq->_xmit_lock); 4095 4100 } 4096 4101
+4 -10
include/linux/siphash.h
··· 29 29 } 30 30 31 31 u64 __siphash_aligned(const void *data, size_t len, const siphash_key_t *key); 32 - #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 33 32 u64 __siphash_unaligned(const void *data, size_t len, const siphash_key_t *key); 34 - #endif 35 33 36 34 u64 siphash_1u64(const u64 a, const siphash_key_t *key); 37 35 u64 siphash_2u64(const u64 a, const u64 b, const siphash_key_t *key); ··· 82 84 static inline u64 siphash(const void *data, size_t len, 83 85 const siphash_key_t *key) 84 86 { 85 - #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 86 - if (!IS_ALIGNED((unsigned long)data, SIPHASH_ALIGNMENT)) 87 + if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) || 88 + !IS_ALIGNED((unsigned long)data, SIPHASH_ALIGNMENT)) 87 89 return __siphash_unaligned(data, len, key); 88 - #endif 89 90 return ___siphash_aligned(data, len, key); 90 91 } 91 92 ··· 95 98 96 99 u32 __hsiphash_aligned(const void *data, size_t len, 97 100 const hsiphash_key_t *key); 98 - #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 99 101 u32 __hsiphash_unaligned(const void *data, size_t len, 100 102 const hsiphash_key_t *key); 101 - #endif 102 103 103 104 u32 hsiphash_1u32(const u32 a, const hsiphash_key_t *key); 104 105 u32 hsiphash_2u32(const u32 a, const u32 b, const hsiphash_key_t *key); ··· 132 137 static inline u32 hsiphash(const void *data, size_t len, 133 138 const hsiphash_key_t *key) 134 139 { 135 - #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 136 - if (!IS_ALIGNED((unsigned long)data, HSIPHASH_ALIGNMENT)) 140 + if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) || 141 + !IS_ALIGNED((unsigned long)data, HSIPHASH_ALIGNMENT)) 137 142 return __hsiphash_unaligned(data, len, key); 138 - #endif 139 143 return ___hsiphash_aligned(data, len, key); 140 144 } 141 145
-2
include/linux/virtio.h
··· 152 152 * @feature_table_size: number of entries in the feature table array. 153 153 * @feature_table_legacy: same as feature_table but when working in legacy mode. 154 154 * @feature_table_size_legacy: number of entries in feature table legacy array. 155 - * @suppress_used_validation: set to not have core validate used length 156 155 * @probe: the function to call when a device is found. Returns 0 or -errno. 157 156 * @scan: optional function to call after successful probe; intended 158 157 * for virtio-scsi to invoke a scan. ··· 168 169 unsigned int feature_table_size; 169 170 const unsigned int *feature_table_legacy; 170 171 unsigned int feature_table_size_legacy; 171 - bool suppress_used_validation; 172 172 int (*validate)(struct virtio_device *dev); 173 173 int (*probe)(struct virtio_device *dev); 174 174 void (*scan)(struct virtio_device *dev);
+1 -1
include/net/busy_poll.h
··· 133 133 if (unlikely(READ_ONCE(sk->sk_napi_id) != skb->napi_id)) 134 134 WRITE_ONCE(sk->sk_napi_id, skb->napi_id); 135 135 #endif 136 - sk_rx_queue_set(sk, skb); 136 + sk_rx_queue_update(sk, skb); 137 137 } 138 138 139 139 static inline void __sk_mark_napi_id_once(struct sock *sk, unsigned int napi_id)
+11
include/net/dst_cache.h
··· 80 80 } 81 81 82 82 /** 83 + * dst_cache_reset_now - invalidate the cache contents immediately 84 + * @dst_cache: the cache 85 + * 86 + * The caller must be sure there are no concurrent users, as this frees 87 + * all dst_cache users immediately, rather than waiting for the next 88 + * per-cpu usage like dst_cache_reset does. Most callers should use the 89 + * higher speed lazily-freed dst_cache_reset function instead. 90 + */ 91 + void dst_cache_reset_now(struct dst_cache *dst_cache); 92 + 93 + /** 83 94 * dst_cache_init - initialize the cache, allocating the required storage 84 95 * @dst_cache: the cache 85 96 * @gfp: allocation flags
+3 -1
include/net/fib_rules.h
··· 69 69 int (*action)(struct fib_rule *, 70 70 struct flowi *, int, 71 71 struct fib_lookup_arg *); 72 - bool (*suppress)(struct fib_rule *, 72 + bool (*suppress)(struct fib_rule *, int, 73 73 struct fib_lookup_arg *); 74 74 int (*match)(struct fib_rule *, 75 75 struct flowi *, int); ··· 218 218 struct fib_lookup_arg *arg)); 219 219 220 220 INDIRECT_CALLABLE_DECLARE(bool fib6_rule_suppress(struct fib_rule *rule, 221 + int flags, 221 222 struct fib_lookup_arg *arg)); 222 223 INDIRECT_CALLABLE_DECLARE(bool fib4_rule_suppress(struct fib_rule *rule, 224 + int flags, 223 225 struct fib_lookup_arg *arg)); 224 226 #endif
+1 -1
include/net/ip_fib.h
··· 438 438 #ifdef CONFIG_IP_ROUTE_CLASSID 439 439 static inline int fib_num_tclassid_users(struct net *net) 440 440 { 441 - return net->ipv4.fib_num_tclassid_users; 441 + return atomic_read(&net->ipv4.fib_num_tclassid_users); 442 442 } 443 443 #else 444 444 static inline int fib_num_tclassid_users(struct net *net)
+1 -1
include/net/netns/ipv4.h
··· 65 65 bool fib_has_custom_local_routes; 66 66 bool fib_offload_disabled; 67 67 #ifdef CONFIG_IP_ROUTE_CLASSID 68 - int fib_num_tclassid_users; 68 + atomic_t fib_num_tclassid_users; 69 69 #endif 70 70 struct hlist_head *fib_table_hash; 71 71 struct sock *fibnl;
+23 -7
include/net/sock.h
··· 1943 1943 return -1; 1944 1944 } 1945 1945 1946 - static inline void sk_rx_queue_set(struct sock *sk, const struct sk_buff *skb) 1946 + static inline void __sk_rx_queue_set(struct sock *sk, 1947 + const struct sk_buff *skb, 1948 + bool force_set) 1947 1949 { 1948 1950 #ifdef CONFIG_SOCK_RX_QUEUE_MAPPING 1949 1951 if (skb_rx_queue_recorded(skb)) { 1950 1952 u16 rx_queue = skb_get_rx_queue(skb); 1951 1953 1952 - if (unlikely(READ_ONCE(sk->sk_rx_queue_mapping) != rx_queue)) 1954 + if (force_set || 1955 + unlikely(READ_ONCE(sk->sk_rx_queue_mapping) != rx_queue)) 1953 1956 WRITE_ONCE(sk->sk_rx_queue_mapping, rx_queue); 1954 1957 } 1955 1958 #endif 1959 + } 1960 + 1961 + static inline void sk_rx_queue_set(struct sock *sk, const struct sk_buff *skb) 1962 + { 1963 + __sk_rx_queue_set(sk, skb, true); 1964 + } 1965 + 1966 + static inline void sk_rx_queue_update(struct sock *sk, const struct sk_buff *skb) 1967 + { 1968 + __sk_rx_queue_set(sk, skb, false); 1956 1969 } 1957 1970 1958 1971 static inline void sk_rx_queue_clear(struct sock *sk) ··· 2470 2457 * @sk: socket 2471 2458 * 2472 2459 * Use the per task page_frag instead of the per socket one for 2473 - * optimization when we know that we're in the normal context and owns 2460 + * optimization when we know that we're in process context and own 2474 2461 * everything that's associated with %current. 2475 2462 * 2476 - * gfpflags_allow_blocking() isn't enough here as direct reclaim may nest 2477 - * inside other socket operations and end up recursing into sk_page_frag() 2478 - * while it's already in use. 2463 + * Both direct reclaim and page faults can nest inside other 2464 + * socket operations and end up recursing into sk_page_frag() 2465 + * while it's already in use: explicitly avoid task page_frag 2466 + * usage if the caller is potentially doing any of them. 2467 + * This assumes that page fault handlers use the GFP_NOFS flags. 2479 2468 * 2480 2469 * Return: a per task page_frag if context allows that, 2481 2470 * otherwise a per socket one. 2482 2471 */ 2483 2472 static inline struct page_frag *sk_page_frag(struct sock *sk) 2484 2473 { 2485 - if (gfpflags_normal_context(sk->sk_allocation)) 2474 + if ((sk->sk_allocation & (__GFP_DIRECT_RECLAIM | __GFP_MEMALLOC | __GFP_FS)) == 2475 + (__GFP_DIRECT_RECLAIM | __GFP_FS)) 2486 2476 return &current->task_frag; 2487 2477 2488 2478 return &sk->sk_frag;
+1 -1
include/sound/soc-acpi.h
··· 147 147 */ 148 148 /* Descriptor for SST ASoC machine driver */ 149 149 struct snd_soc_acpi_mach { 150 - const u8 id[ACPI_ID_LEN]; 150 + u8 id[ACPI_ID_LEN]; 151 151 const struct snd_soc_acpi_codecs *comp_ids; 152 152 const u32 link_mask; 153 153 const struct snd_soc_acpi_link_adr *links;
+1 -1
include/trace/events/rpcgss.h
··· 8 8 #undef TRACE_SYSTEM 9 9 #define TRACE_SYSTEM rpcgss 10 10 11 - #if !defined(_TRACE_RPCRDMA_H) || defined(TRACE_HEADER_MULTI_READ) 11 + #if !defined(_TRACE_RPCGSS_H) || defined(TRACE_HEADER_MULTI_READ) 12 12 #define _TRACE_RPCGSS_H 13 13 14 14 #include <linux/tracepoint.h>
+1 -1
include/uapi/linux/if_ether.h
··· 117 117 #define ETH_P_IFE 0xED3E /* ForCES inter-FE LFB type */ 118 118 #define ETH_P_AF_IUCV 0xFBFB /* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */ 119 119 120 - #define ETH_P_802_3_MIN 0x0600 /* If the value in the ethernet type is less than this value 120 + #define ETH_P_802_3_MIN 0x0600 /* If the value in the ethernet type is more than this value 121 121 * then the frame is Ethernet II. Else it is 802.3 */ 122 122 123 123 /*
+7
kernel/cpu.c
··· 31 31 #include <linux/smpboot.h> 32 32 #include <linux/relay.h> 33 33 #include <linux/slab.h> 34 + #include <linux/scs.h> 34 35 #include <linux/percpu-rwsem.h> 35 36 #include <linux/cpuset.h> 36 37 ··· 587 586 { 588 587 struct task_struct *idle = idle_thread_get(cpu); 589 588 int ret; 589 + 590 + /* 591 + * Reset stale stack state from the last time this CPU was online. 592 + */ 593 + scs_task_reset(idle); 594 + kasan_unpoison_task_stack(idle); 590 595 591 596 /* 592 597 * Some architectures have to walk the irq descriptors to
+3
kernel/events/core.c
··· 9759 9759 continue; 9760 9760 if (event->attr.config != entry->type) 9761 9761 continue; 9762 + /* Cannot deliver synchronous signal to other task. */ 9763 + if (event->attr.sigtrap) 9764 + continue; 9762 9765 if (perf_tp_event_match(event, &data, regs)) 9763 9766 perf_swevent_event(event, count, &data, regs); 9764 9767 }
+3
kernel/kprobes.c
··· 2086 2086 } 2087 2087 } 2088 2088 2089 + if (rp->data_size > KRETPROBE_MAX_DATA_SIZE) 2090 + return -E2BIG; 2091 + 2089 2092 rp->kp.pre_handler = pre_handler_kretprobe; 2090 2093 rp->kp.post_handler = NULL; 2091 2094
+91 -95
kernel/locking/rwsem.c
··· 105 105 * atomic_long_cmpxchg() will be used to obtain writer lock. 106 106 * 107 107 * There are three places where the lock handoff bit may be set or cleared. 108 - * 1) rwsem_mark_wake() for readers. 109 - * 2) rwsem_try_write_lock() for writers. 110 - * 3) Error path of rwsem_down_write_slowpath(). 108 + * 1) rwsem_mark_wake() for readers -- set, clear 109 + * 2) rwsem_try_write_lock() for writers -- set, clear 110 + * 3) rwsem_del_waiter() -- clear 111 111 * 112 112 * For all the above cases, wait_lock will be held. A writer must also 113 113 * be the first one in the wait_list to be eligible for setting the handoff ··· 334 334 struct task_struct *task; 335 335 enum rwsem_waiter_type type; 336 336 unsigned long timeout; 337 + 338 + /* Writer only, not initialized in reader */ 339 + bool handoff_set; 337 340 }; 338 341 #define rwsem_first_waiter(sem) \ 339 342 list_first_entry(&sem->wait_list, struct rwsem_waiter, list) ··· 345 342 RWSEM_WAKE_ANY, /* Wake whatever's at head of wait list */ 346 343 RWSEM_WAKE_READERS, /* Wake readers only */ 347 344 RWSEM_WAKE_READ_OWNED /* Waker thread holds the read lock */ 348 - }; 349 - 350 - enum writer_wait_state { 351 - WRITER_NOT_FIRST, /* Writer is not first in wait list */ 352 - WRITER_FIRST, /* Writer is first in wait list */ 353 - WRITER_HANDOFF /* Writer is first & handoff needed */ 354 345 }; 355 346 356 347 /* ··· 362 365 */ 363 366 #define MAX_READERS_WAKEUP 0x100 364 367 368 + static inline void 369 + rwsem_add_waiter(struct rw_semaphore *sem, struct rwsem_waiter *waiter) 370 + { 371 + lockdep_assert_held(&sem->wait_lock); 372 + list_add_tail(&waiter->list, &sem->wait_list); 373 + /* caller will set RWSEM_FLAG_WAITERS */ 374 + } 375 + 376 + /* 377 + * Remove a waiter from the wait_list and clear flags. 378 + * 379 + * Both rwsem_mark_wake() and rwsem_try_write_lock() contain a full 'copy' of 380 + * this function. Modify with care. 381 + */ 382 + static inline void 383 + rwsem_del_waiter(struct rw_semaphore *sem, struct rwsem_waiter *waiter) 384 + { 385 + lockdep_assert_held(&sem->wait_lock); 386 + list_del(&waiter->list); 387 + if (likely(!list_empty(&sem->wait_list))) 388 + return; 389 + 390 + atomic_long_andnot(RWSEM_FLAG_HANDOFF | RWSEM_FLAG_WAITERS, &sem->count); 391 + } 392 + 365 393 /* 366 394 * handle the lock release when processes blocked on it that can now run 367 395 * - if we come here from up_xxxx(), then the RWSEM_FLAG_WAITERS bit must ··· 398 376 * preferably when the wait_lock is released 399 377 * - woken process blocks are discarded from the list after having task zeroed 400 378 * - writers are only marked woken if downgrading is false 379 + * 380 + * Implies rwsem_del_waiter() for all woken readers. 401 381 */ 402 382 static void rwsem_mark_wake(struct rw_semaphore *sem, 403 383 enum rwsem_wake_type wake_type, ··· 514 490 515 491 adjustment = woken * RWSEM_READER_BIAS - adjustment; 516 492 lockevent_cond_inc(rwsem_wake_reader, woken); 517 - if (list_empty(&sem->wait_list)) { 518 - /* hit end of list above */ 519 - adjustment -= RWSEM_FLAG_WAITERS; 520 - } 521 493 522 - /* 523 - * When we've woken a reader, we no longer need to force writers 524 - * to give up the lock and we can clear HANDOFF. 525 - */ 526 - if (woken && (atomic_long_read(&sem->count) & RWSEM_FLAG_HANDOFF)) 527 - adjustment -= RWSEM_FLAG_HANDOFF; 494 + oldcount = atomic_long_read(&sem->count); 495 + if (list_empty(&sem->wait_list)) { 496 + /* 497 + * Combined with list_move_tail() above, this implies 498 + * rwsem_del_waiter(). 499 + */ 500 + adjustment -= RWSEM_FLAG_WAITERS; 501 + if (oldcount & RWSEM_FLAG_HANDOFF) 502 + adjustment -= RWSEM_FLAG_HANDOFF; 503 + } else if (woken) { 504 + /* 505 + * When we've woken a reader, we no longer need to force 506 + * writers to give up the lock and we can clear HANDOFF. 507 + */ 508 + if (oldcount & RWSEM_FLAG_HANDOFF) 509 + adjustment -= RWSEM_FLAG_HANDOFF; 510 + } 528 511 529 512 if (adjustment) 530 513 atomic_long_add(adjustment, &sem->count); ··· 563 532 * race conditions between checking the rwsem wait list and setting the 564 533 * sem->count accordingly. 565 534 * 566 - * If wstate is WRITER_HANDOFF, it will make sure that either the handoff 567 - * bit is set or the lock is acquired with handoff bit cleared. 535 + * Implies rwsem_del_waiter() on success. 568 536 */ 569 537 static inline bool rwsem_try_write_lock(struct rw_semaphore *sem, 570 - enum writer_wait_state wstate) 538 + struct rwsem_waiter *waiter) 571 539 { 540 + bool first = rwsem_first_waiter(sem) == waiter; 572 541 long count, new; 573 542 574 543 lockdep_assert_held(&sem->wait_lock); ··· 577 546 do { 578 547 bool has_handoff = !!(count & RWSEM_FLAG_HANDOFF); 579 548 580 - if (has_handoff && wstate == WRITER_NOT_FIRST) 581 - return false; 549 + if (has_handoff) { 550 + if (!first) 551 + return false; 552 + 553 + /* First waiter inherits a previously set handoff bit */ 554 + waiter->handoff_set = true; 555 + } 582 556 583 557 new = count; 584 558 585 559 if (count & RWSEM_LOCK_MASK) { 586 - if (has_handoff || (wstate != WRITER_HANDOFF)) 560 + if (has_handoff || (!rt_task(waiter->task) && 561 + !time_after(jiffies, waiter->timeout))) 587 562 return false; 588 563 589 564 new |= RWSEM_FLAG_HANDOFF; ··· 606 569 * We have either acquired the lock with handoff bit cleared or 607 570 * set the handoff bit. 608 571 */ 609 - if (new & RWSEM_FLAG_HANDOFF) 572 + if (new & RWSEM_FLAG_HANDOFF) { 573 + waiter->handoff_set = true; 574 + lockevent_inc(rwsem_wlock_handoff); 610 575 return false; 576 + } 611 577 578 + /* 579 + * Have rwsem_try_write_lock() fully imply rwsem_del_waiter() on 580 + * success. 581 + */ 582 + list_del(&waiter->list); 612 583 rwsem_set_owner(sem); 613 584 return true; 614 585 } ··· 1001 956 } 1002 957 adjustment += RWSEM_FLAG_WAITERS; 1003 958 } 1004 - list_add_tail(&waiter.list, &sem->wait_list); 959 + rwsem_add_waiter(sem, &waiter); 1005 960 1006 961 /* we're now waiting on the lock, but no longer actively locking */ 1007 962 count = atomic_long_add_return(adjustment, &sem->count); ··· 1047 1002 return sem; 1048 1003 1049 1004 out_nolock: 1050 - list_del(&waiter.list); 1051 - if (list_empty(&sem->wait_list)) { 1052 - atomic_long_andnot(RWSEM_FLAG_WAITERS|RWSEM_FLAG_HANDOFF, 1053 - &sem->count); 1054 - } 1005 + rwsem_del_waiter(sem, &waiter); 1055 1006 raw_spin_unlock_irq(&sem->wait_lock); 1056 1007 __set_current_state(TASK_RUNNING); 1057 1008 lockevent_inc(rwsem_rlock_fail); ··· 1061 1020 rwsem_down_write_slowpath(struct rw_semaphore *sem, int state) 1062 1021 { 1063 1022 long count; 1064 - enum writer_wait_state wstate; 1065 1023 struct rwsem_waiter waiter; 1066 - struct rw_semaphore *ret = sem; 1067 1024 DEFINE_WAKE_Q(wake_q); 1068 1025 1069 1026 /* do optimistic spinning and steal lock if possible */ ··· 1077 1038 waiter.task = current; 1078 1039 waiter.type = RWSEM_WAITING_FOR_WRITE; 1079 1040 waiter.timeout = jiffies + RWSEM_WAIT_TIMEOUT; 1041 + waiter.handoff_set = false; 1080 1042 1081 1043 raw_spin_lock_irq(&sem->wait_lock); 1082 - 1083 - /* account for this before adding a new element to the list */ 1084 - wstate = list_empty(&sem->wait_list) ? WRITER_FIRST : WRITER_NOT_FIRST; 1085 - 1086 - list_add_tail(&waiter.list, &sem->wait_list); 1044 + rwsem_add_waiter(sem, &waiter); 1087 1045 1088 1046 /* we're now waiting on the lock */ 1089 - if (wstate == WRITER_NOT_FIRST) { 1047 + if (rwsem_first_waiter(sem) != &waiter) { 1090 1048 count = atomic_long_read(&sem->count); 1091 1049 1092 1050 /* ··· 1119 1083 /* wait until we successfully acquire the lock */ 1120 1084 set_current_state(state); 1121 1085 for (;;) { 1122 - if (rwsem_try_write_lock(sem, wstate)) { 1086 + if (rwsem_try_write_lock(sem, &waiter)) { 1123 1087 /* rwsem_try_write_lock() implies ACQUIRE on success */ 1124 1088 break; 1125 1089 } 1126 1090 1127 1091 raw_spin_unlock_irq(&sem->wait_lock); 1092 + 1093 + if (signal_pending_state(state, current)) 1094 + goto out_nolock; 1128 1095 1129 1096 /* 1130 1097 * After setting the handoff bit and failing to acquire ··· 1137 1098 * In this case, we attempt to acquire the lock again 1138 1099 * without sleeping. 1139 1100 */ 1140 - if (wstate == WRITER_HANDOFF) { 1101 + if (waiter.handoff_set) { 1141 1102 enum owner_state owner_state; 1142 1103 1143 1104 preempt_disable(); ··· 1148 1109 goto trylock_again; 1149 1110 } 1150 1111 1151 - /* Block until there are no active lockers. */ 1152 - for (;;) { 1153 - if (signal_pending_state(state, current)) 1154 - goto out_nolock; 1155 - 1156 - schedule(); 1157 - lockevent_inc(rwsem_sleep_writer); 1158 - set_current_state(state); 1159 - /* 1160 - * If HANDOFF bit is set, unconditionally do 1161 - * a trylock. 1162 - */ 1163 - if (wstate == WRITER_HANDOFF) 1164 - break; 1165 - 1166 - if ((wstate == WRITER_NOT_FIRST) && 1167 - (rwsem_first_waiter(sem) == &waiter)) 1168 - wstate = WRITER_FIRST; 1169 - 1170 - count = atomic_long_read(&sem->count); 1171 - if (!(count & RWSEM_LOCK_MASK)) 1172 - break; 1173 - 1174 - /* 1175 - * The setting of the handoff bit is deferred 1176 - * until rwsem_try_write_lock() is called. 1177 - */ 1178 - if ((wstate == WRITER_FIRST) && (rt_task(current) || 1179 - time_after(jiffies, waiter.timeout))) { 1180 - wstate = WRITER_HANDOFF; 1181 - lockevent_inc(rwsem_wlock_handoff); 1182 - break; 1183 - } 1184 - } 1112 + schedule(); 1113 + lockevent_inc(rwsem_sleep_writer); 1114 + set_current_state(state); 1185 1115 trylock_again: 1186 1116 raw_spin_lock_irq(&sem->wait_lock); 1187 1117 } 1188 1118 __set_current_state(TASK_RUNNING); 1189 - list_del(&waiter.list); 1190 1119 raw_spin_unlock_irq(&sem->wait_lock); 1191 1120 lockevent_inc(rwsem_wlock); 1192 - 1193 - return ret; 1121 + return sem; 1194 1122 1195 1123 out_nolock: 1196 1124 __set_current_state(TASK_RUNNING); 1197 1125 raw_spin_lock_irq(&sem->wait_lock); 1198 - list_del(&waiter.list); 1199 - 1200 - if (unlikely(wstate == WRITER_HANDOFF)) 1201 - atomic_long_add(-RWSEM_FLAG_HANDOFF, &sem->count); 1202 - 1203 - if (list_empty(&sem->wait_list)) 1204 - atomic_long_andnot(RWSEM_FLAG_WAITERS, &sem->count); 1205 - else 1126 + rwsem_del_waiter(sem, &waiter); 1127 + if (!list_empty(&sem->wait_list)) 1206 1128 rwsem_mark_wake(sem, RWSEM_WAKE_ANY, &wake_q); 1207 1129 raw_spin_unlock_irq(&sem->wait_lock); 1208 1130 wake_up_q(&wake_q); 1209 1131 lockevent_inc(rwsem_wlock_fail); 1210 - 1211 1132 return ERR_PTR(-EINTR); 1212 1133 } 1213 1134 ··· 1248 1249 1249 1250 DEBUG_RWSEMS_WARN_ON(sem->magic != sem, sem); 1250 1251 1251 - /* 1252 - * Optimize for the case when the rwsem is not locked at all. 1253 - */ 1254 - tmp = RWSEM_UNLOCKED_VALUE; 1255 - do { 1252 + tmp = atomic_long_read(&sem->count); 1253 + while (!(tmp & RWSEM_READ_FAILED_MASK)) { 1256 1254 if (atomic_long_try_cmpxchg_acquire(&sem->count, &tmp, 1257 - tmp + RWSEM_READER_BIAS)) { 1255 + tmp + RWSEM_READER_BIAS)) { 1258 1256 rwsem_set_reader_owned(sem); 1259 1257 return 1; 1260 1258 } 1261 - } while (!(tmp & RWSEM_READ_FAILED_MASK)); 1259 + } 1262 1260 return 0; 1263 1261 } 1264 1262
-4
kernel/sched/core.c
··· 8619 8619 idle->flags |= PF_IDLE | PF_KTHREAD | PF_NO_SETAFFINITY; 8620 8620 kthread_set_per_cpu(idle, cpu); 8621 8621 8622 - scs_task_reset(idle); 8623 - kasan_unpoison_task_stack(idle); 8624 - 8625 8622 #ifdef CONFIG_SMP 8626 8623 /* 8627 8624 * It's possible that init_idle() gets called multiple times on a task, ··· 8774 8777 finish_arch_post_lock_switch(); 8775 8778 } 8776 8779 8777 - scs_task_reset(current); 8778 8780 /* finish_cpu(), as ran on the BP, will clean up the active_mm state */ 8779 8781 } 8780 8782
+18 -6
kernel/trace/trace.h
··· 1366 1366 if (eflags & EVENT_FILE_FL_TRIGGER_COND) 1367 1367 *tt = event_triggers_call(file, buffer, entry, event); 1368 1368 1369 - if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) || 1370 - (unlikely(file->flags & EVENT_FILE_FL_FILTERED) && 1371 - !filter_match_preds(file->filter, entry))) { 1372 - __trace_event_discard_commit(buffer, event); 1373 - return true; 1374 - } 1369 + if (likely(!(file->flags & (EVENT_FILE_FL_SOFT_DISABLED | 1370 + EVENT_FILE_FL_FILTERED | 1371 + EVENT_FILE_FL_PID_FILTER)))) 1372 + return false; 1373 + 1374 + if (file->flags & EVENT_FILE_FL_SOFT_DISABLED) 1375 + goto discard; 1376 + 1377 + if (file->flags & EVENT_FILE_FL_FILTERED && 1378 + !filter_match_preds(file->filter, entry)) 1379 + goto discard; 1380 + 1381 + if ((file->flags & EVENT_FILE_FL_PID_FILTER) && 1382 + trace_event_ignore_this_pid(file)) 1383 + goto discard; 1375 1384 1376 1385 return false; 1386 + discard: 1387 + __trace_event_discard_commit(buffer, event); 1388 + return true; 1377 1389 } 1378 1390 1379 1391 /**
+12
kernel/trace/trace_events.c
··· 2678 2678 trace_create_new_event(struct trace_event_call *call, 2679 2679 struct trace_array *tr) 2680 2680 { 2681 + struct trace_pid_list *no_pid_list; 2682 + struct trace_pid_list *pid_list; 2681 2683 struct trace_event_file *file; 2684 + unsigned int first; 2682 2685 2683 2686 file = kmem_cache_alloc(file_cachep, GFP_TRACE); 2684 2687 if (!file) 2685 2688 return NULL; 2689 + 2690 + pid_list = rcu_dereference_protected(tr->filtered_pids, 2691 + lockdep_is_held(&event_mutex)); 2692 + no_pid_list = rcu_dereference_protected(tr->filtered_no_pids, 2693 + lockdep_is_held(&event_mutex)); 2694 + 2695 + if (!trace_pid_list_first(pid_list, &first) || 2696 + !trace_pid_list_first(no_pid_list, &first)) 2697 + file->flags |= EVENT_FILE_FL_PID_FILTER; 2686 2698 2687 2699 file->event_call = call; 2688 2700 file->tr = tr;
+1 -1
kernel/trace/trace_events_hist.c
··· 3757 3757 3758 3758 if (strcmp(field->type, hist_field->type) != 0) { 3759 3759 if (field->size != hist_field->size || 3760 - field->is_signed != hist_field->is_signed) 3760 + (!field->is_string && field->is_signed != hist_field->is_signed)) 3761 3761 return -EINVAL; 3762 3762 } 3763 3763
+3
kernel/trace/tracing_map.c
··· 15 15 #include <linux/jhash.h> 16 16 #include <linux/slab.h> 17 17 #include <linux/sort.h> 18 + #include <linux/kmemleak.h> 18 19 19 20 #include "tracing_map.h" 20 21 #include "trace.h" ··· 308 307 for (i = 0; i < a->n_pages; i++) { 309 308 if (!a->pages[i]) 310 309 break; 310 + kmemleak_free(a->pages[i]); 311 311 free_page((unsigned long)a->pages[i]); 312 312 } 313 313 ··· 344 342 a->pages[i] = (void *)get_zeroed_page(GFP_KERNEL); 345 343 if (!a->pages[i]) 346 344 goto free; 345 + kmemleak_alloc(a->pages[i], PAGE_SIZE, 1, GFP_KERNEL); 347 346 } 348 347 out: 349 348 return a;
+6 -6
lib/siphash.c
··· 49 49 SIPROUND; \ 50 50 return (v0 ^ v1) ^ (v2 ^ v3); 51 51 52 + #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 52 53 u64 __siphash_aligned(const void *data, size_t len, const siphash_key_t *key) 53 54 { 54 55 const u8 *end = data + len - (len % sizeof(u64)); ··· 81 80 POSTAMBLE 82 81 } 83 82 EXPORT_SYMBOL(__siphash_aligned); 83 + #endif 84 84 85 - #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 86 85 u64 __siphash_unaligned(const void *data, size_t len, const siphash_key_t *key) 87 86 { 88 87 const u8 *end = data + len - (len % sizeof(u64)); ··· 114 113 POSTAMBLE 115 114 } 116 115 EXPORT_SYMBOL(__siphash_unaligned); 117 - #endif 118 116 119 117 /** 120 118 * siphash_1u64 - compute 64-bit siphash PRF value of a u64 ··· 250 250 HSIPROUND; \ 251 251 return (v0 ^ v1) ^ (v2 ^ v3); 252 252 253 + #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 253 254 u32 __hsiphash_aligned(const void *data, size_t len, const hsiphash_key_t *key) 254 255 { 255 256 const u8 *end = data + len - (len % sizeof(u64)); ··· 281 280 HPOSTAMBLE 282 281 } 283 282 EXPORT_SYMBOL(__hsiphash_aligned); 283 + #endif 284 284 285 - #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 286 285 u32 __hsiphash_unaligned(const void *data, size_t len, 287 286 const hsiphash_key_t *key) 288 287 { ··· 314 313 HPOSTAMBLE 315 314 } 316 315 EXPORT_SYMBOL(__hsiphash_unaligned); 317 - #endif 318 316 319 317 /** 320 318 * hsiphash_1u32 - compute 64-bit hsiphash PRF value of a u32 ··· 418 418 HSIPROUND; \ 419 419 return v1 ^ v3; 420 420 421 + #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 421 422 u32 __hsiphash_aligned(const void *data, size_t len, const hsiphash_key_t *key) 422 423 { 423 424 const u8 *end = data + len - (len % sizeof(u32)); ··· 439 438 HPOSTAMBLE 440 439 } 441 440 EXPORT_SYMBOL(__hsiphash_aligned); 441 + #endif 442 442 443 - #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 444 443 u32 __hsiphash_unaligned(const void *data, size_t len, 445 444 const hsiphash_key_t *key) 446 445 { ··· 462 461 HPOSTAMBLE 463 462 } 464 463 EXPORT_SYMBOL(__hsiphash_unaligned); 465 - #endif 466 464 467 465 /** 468 466 * hsiphash_1u32 - compute 32-bit hsiphash PRF value of a u32
+4 -1
net/core/dev.c
··· 4093 4093 if (dev->flags & IFF_UP) { 4094 4094 int cpu = smp_processor_id(); /* ok because BHs are off */ 4095 4095 4096 - if (txq->xmit_lock_owner != cpu) { 4096 + /* Other cpus might concurrently change txq->xmit_lock_owner 4097 + * to -1 or to their cpu id, but not to our id. 4098 + */ 4099 + if (READ_ONCE(txq->xmit_lock_owner) != cpu) { 4097 4100 if (dev_xmit_recursion()) 4098 4101 goto recursion_alert; 4099 4102
+19
net/core/dst_cache.c
··· 162 162 free_percpu(dst_cache->cache); 163 163 } 164 164 EXPORT_SYMBOL_GPL(dst_cache_destroy); 165 + 166 + void dst_cache_reset_now(struct dst_cache *dst_cache) 167 + { 168 + int i; 169 + 170 + if (!dst_cache->cache) 171 + return; 172 + 173 + dst_cache->reset_ts = jiffies; 174 + for_each_possible_cpu(i) { 175 + struct dst_cache_pcpu *idst = per_cpu_ptr(dst_cache->cache, i); 176 + struct dst_entry *dst = idst->dst; 177 + 178 + idst->cookie = 0; 179 + idst->dst = NULL; 180 + dst_release(dst); 181 + } 182 + } 183 + EXPORT_SYMBOL_GPL(dst_cache_reset_now);
+1 -1
net/core/fib_rules.c
··· 323 323 if (!err && ops->suppress && INDIRECT_CALL_MT(ops->suppress, 324 324 fib6_rule_suppress, 325 325 fib4_rule_suppress, 326 - rule, arg)) 326 + rule, flags, arg)) 327 327 continue; 328 328 329 329 if (err != -EAGAIN) {
+1 -1
net/ipv4/fib_frontend.c
··· 1582 1582 int error; 1583 1583 1584 1584 #ifdef CONFIG_IP_ROUTE_CLASSID 1585 - net->ipv4.fib_num_tclassid_users = 0; 1585 + atomic_set(&net->ipv4.fib_num_tclassid_users, 0); 1586 1586 #endif 1587 1587 error = ip_fib_net_init(net); 1588 1588 if (error < 0)
+3 -2
net/ipv4/fib_rules.c
··· 141 141 } 142 142 143 143 INDIRECT_CALLABLE_SCOPE bool fib4_rule_suppress(struct fib_rule *rule, 144 + int flags, 144 145 struct fib_lookup_arg *arg) 145 146 { 146 147 struct fib_result *result = (struct fib_result *) arg->result; ··· 264 263 if (tb[FRA_FLOW]) { 265 264 rule4->tclassid = nla_get_u32(tb[FRA_FLOW]); 266 265 if (rule4->tclassid) 267 - net->ipv4.fib_num_tclassid_users++; 266 + atomic_inc(&net->ipv4.fib_num_tclassid_users); 268 267 } 269 268 #endif 270 269 ··· 296 295 297 296 #ifdef CONFIG_IP_ROUTE_CLASSID 298 297 if (((struct fib4_rule *)rule)->tclassid) 299 - net->ipv4.fib_num_tclassid_users--; 298 + atomic_dec(&net->ipv4.fib_num_tclassid_users); 300 299 #endif 301 300 net->ipv4.fib_has_custom_rules = true; 302 301
+2 -2
net/ipv4/fib_semantics.c
··· 220 220 { 221 221 #ifdef CONFIG_IP_ROUTE_CLASSID 222 222 if (fib_nh->nh_tclassid) 223 - net->ipv4.fib_num_tclassid_users--; 223 + atomic_dec(&net->ipv4.fib_num_tclassid_users); 224 224 #endif 225 225 fib_nh_common_release(&fib_nh->nh_common); 226 226 } ··· 632 632 #ifdef CONFIG_IP_ROUTE_CLASSID 633 633 nh->nh_tclassid = cfg->fc_flow; 634 634 if (nh->nh_tclassid) 635 - net->ipv4.fib_num_tclassid_users++; 635 + atomic_inc(&net->ipv4.fib_num_tclassid_users); 636 636 #endif 637 637 #ifdef CONFIG_IP_ROUTE_MULTIPATH 638 638 nh->fib_nh_weight = nh_weight;
+2 -2
net/ipv6/fib6_rules.c
··· 267 267 } 268 268 269 269 INDIRECT_CALLABLE_SCOPE bool fib6_rule_suppress(struct fib_rule *rule, 270 + int flags, 270 271 struct fib_lookup_arg *arg) 271 272 { 272 273 struct fib6_result *res = arg->result; ··· 295 294 return false; 296 295 297 296 suppress_route: 298 - if (!(arg->flags & FIB_LOOKUP_NOREF)) 299 - ip6_rt_put(rt); 297 + ip6_rt_put_flags(rt, flags); 300 298 return true; 301 299 } 302 300
+3 -3
net/ipv6/ip6_offload.c
··· 247 247 * memcmp() alone below is sufficient, right? 248 248 */ 249 249 if ((first_word & htonl(0xF00FFFFF)) || 250 - !ipv6_addr_equal(&iph->saddr, &iph2->saddr) || 251 - !ipv6_addr_equal(&iph->daddr, &iph2->daddr) || 252 - *(u16 *)&iph->nexthdr != *(u16 *)&iph2->nexthdr) { 250 + !ipv6_addr_equal(&iph->saddr, &iph2->saddr) || 251 + !ipv6_addr_equal(&iph->daddr, &iph2->daddr) || 252 + *(u16 *)&iph->nexthdr != *(u16 *)&iph2->nexthdr) { 253 253 not_same_flow: 254 254 NAPI_GRO_CB(p)->same_flow = 0; 255 255 continue;
+5 -4
net/mctp/route.c
··· 949 949 } 950 950 951 951 static int mctp_route_remove(struct mctp_dev *mdev, mctp_eid_t daddr_start, 952 - unsigned int daddr_extent) 952 + unsigned int daddr_extent, unsigned char type) 953 953 { 954 954 struct net *net = dev_net(mdev->dev); 955 955 struct mctp_route *rt, *tmp; ··· 966 966 967 967 list_for_each_entry_safe(rt, tmp, &net->mctp.routes, list) { 968 968 if (rt->dev == mdev && 969 - rt->min == daddr_start && rt->max == daddr_end) { 969 + rt->min == daddr_start && rt->max == daddr_end && 970 + rt->type == type) { 970 971 list_del_rcu(&rt->list); 971 972 /* TODO: immediate RTM_DELROUTE */ 972 973 mctp_route_release(rt); ··· 985 984 986 985 int mctp_route_remove_local(struct mctp_dev *mdev, mctp_eid_t addr) 987 986 { 988 - return mctp_route_remove(mdev, addr, 0); 987 + return mctp_route_remove(mdev, addr, 0, RTN_LOCAL); 989 988 } 990 989 991 990 /* removes all entries for a given device */ ··· 1193 1192 if (rtm->rtm_type != RTN_UNICAST) 1194 1193 return -EINVAL; 1195 1194 1196 - rc = mctp_route_remove(mdev, daddr_start, rtm->rtm_dst_len); 1195 + rc = mctp_route_remove(mdev, daddr_start, rtm->rtm_dst_len, RTN_UNICAST); 1197 1196 return rc; 1198 1197 } 1199 1198
+1 -1
net/mctp/test/utils.c
··· 12 12 static netdev_tx_t mctp_test_dev_tx(struct sk_buff *skb, 13 13 struct net_device *ndev) 14 14 { 15 - kfree(skb); 15 + kfree_skb(skb); 16 16 return NETDEV_TX_OK; 17 17 } 18 18
+62 -35
net/mpls/af_mpls.c
··· 409 409 goto err; 410 410 411 411 /* Find the output device */ 412 - out_dev = rcu_dereference(nh->nh_dev); 412 + out_dev = nh->nh_dev; 413 413 if (!mpls_output_possible(out_dev)) 414 414 goto tx_err; 415 415 ··· 698 698 (dev->addr_len != nh->nh_via_alen)) 699 699 goto errout; 700 700 701 - RCU_INIT_POINTER(nh->nh_dev, dev); 701 + nh->nh_dev = dev; 702 702 703 703 if (!(dev->flags & IFF_UP)) { 704 704 nh->nh_flags |= RTNH_F_DEAD; ··· 1491 1491 kfree(mdev); 1492 1492 } 1493 1493 1494 - static void mpls_ifdown(struct net_device *dev, int event) 1494 + static int mpls_ifdown(struct net_device *dev, int event) 1495 1495 { 1496 1496 struct mpls_route __rcu **platform_label; 1497 1497 struct net *net = dev_net(dev); 1498 - u8 alive, deleted; 1499 1498 unsigned index; 1500 1499 1501 1500 platform_label = rtnl_dereference(net->mpls.platform_label); 1502 1501 for (index = 0; index < net->mpls.platform_labels; index++) { 1503 1502 struct mpls_route *rt = rtnl_dereference(platform_label[index]); 1503 + bool nh_del = false; 1504 + u8 alive = 0; 1504 1505 1505 1506 if (!rt) 1506 1507 continue; 1507 1508 1508 - alive = 0; 1509 - deleted = 0; 1509 + if (event == NETDEV_UNREGISTER) { 1510 + u8 deleted = 0; 1511 + 1512 + for_nexthops(rt) { 1513 + if (!nh->nh_dev || nh->nh_dev == dev) 1514 + deleted++; 1515 + if (nh->nh_dev == dev) 1516 + nh_del = true; 1517 + } endfor_nexthops(rt); 1518 + 1519 + /* if there are no more nexthops, delete the route */ 1520 + if (deleted == rt->rt_nhn) { 1521 + mpls_route_update(net, index, NULL, NULL); 1522 + continue; 1523 + } 1524 + 1525 + if (nh_del) { 1526 + size_t size = sizeof(*rt) + rt->rt_nhn * 1527 + rt->rt_nh_size; 1528 + struct mpls_route *orig = rt; 1529 + 1530 + rt = kmalloc(size, GFP_KERNEL); 1531 + if (!rt) 1532 + return -ENOMEM; 1533 + memcpy(rt, orig, size); 1534 + } 1535 + } 1536 + 1510 1537 change_nexthops(rt) { 1511 1538 unsigned int nh_flags = nh->nh_flags; 1512 1539 1513 - if (rtnl_dereference(nh->nh_dev) != dev) 1540 + if (nh->nh_dev != dev) 1514 1541 goto next; 1515 1542 1516 1543 switch (event) { ··· 1550 1523 break; 1551 1524 } 1552 1525 if (event == NETDEV_UNREGISTER) 1553 - RCU_INIT_POINTER(nh->nh_dev, NULL); 1526 + nh->nh_dev = NULL; 1554 1527 1555 1528 if (nh->nh_flags != nh_flags) 1556 1529 WRITE_ONCE(nh->nh_flags, nh_flags); 1557 1530 next: 1558 1531 if (!(nh_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN))) 1559 1532 alive++; 1560 - if (!rtnl_dereference(nh->nh_dev)) 1561 - deleted++; 1562 1533 } endfor_nexthops(rt); 1563 1534 1564 1535 WRITE_ONCE(rt->rt_nhn_alive, alive); 1565 1536 1566 - /* if there are no more nexthops, delete the route */ 1567 - if (event == NETDEV_UNREGISTER && deleted == rt->rt_nhn) 1568 - mpls_route_update(net, index, NULL, NULL); 1537 + if (nh_del) 1538 + mpls_route_update(net, index, rt, NULL); 1569 1539 } 1540 + 1541 + return 0; 1570 1542 } 1571 1543 1572 1544 static void mpls_ifup(struct net_device *dev, unsigned int flags) ··· 1585 1559 alive = 0; 1586 1560 change_nexthops(rt) { 1587 1561 unsigned int nh_flags = nh->nh_flags; 1588 - struct net_device *nh_dev = 1589 - rtnl_dereference(nh->nh_dev); 1590 1562 1591 1563 if (!(nh_flags & flags)) { 1592 1564 alive++; 1593 1565 continue; 1594 1566 } 1595 - if (nh_dev != dev) 1567 + if (nh->nh_dev != dev) 1596 1568 continue; 1597 1569 alive++; 1598 1570 nh_flags &= ~flags; ··· 1621 1597 return NOTIFY_OK; 1622 1598 1623 1599 switch (event) { 1600 + int err; 1601 + 1624 1602 case NETDEV_DOWN: 1625 - mpls_ifdown(dev, event); 1603 + err = mpls_ifdown(dev, event); 1604 + if (err) 1605 + return notifier_from_errno(err); 1626 1606 break; 1627 1607 case NETDEV_UP: 1628 1608 flags = dev_get_flags(dev); ··· 1637 1609 break; 1638 1610 case NETDEV_CHANGE: 1639 1611 flags = dev_get_flags(dev); 1640 - if (flags & (IFF_RUNNING | IFF_LOWER_UP)) 1612 + if (flags & (IFF_RUNNING | IFF_LOWER_UP)) { 1641 1613 mpls_ifup(dev, RTNH_F_DEAD | RTNH_F_LINKDOWN); 1642 - else 1643 - mpls_ifdown(dev, event); 1614 + } else { 1615 + err = mpls_ifdown(dev, event); 1616 + if (err) 1617 + return notifier_from_errno(err); 1618 + } 1644 1619 break; 1645 1620 case NETDEV_UNREGISTER: 1646 - mpls_ifdown(dev, event); 1621 + err = mpls_ifdown(dev, event); 1622 + if (err) 1623 + return notifier_from_errno(err); 1647 1624 mdev = mpls_dev_get(dev); 1648 1625 if (mdev) { 1649 1626 mpls_dev_sysctl_unregister(dev, mdev); ··· 1659 1626 case NETDEV_CHANGENAME: 1660 1627 mdev = mpls_dev_get(dev); 1661 1628 if (mdev) { 1662 - int err; 1663 - 1664 1629 mpls_dev_sysctl_unregister(dev, mdev); 1665 1630 err = mpls_dev_sysctl_register(dev, mdev); 1666 1631 if (err) ··· 2025 1994 nla_put_via(skb, nh->nh_via_table, mpls_nh_via(rt, nh), 2026 1995 nh->nh_via_alen)) 2027 1996 goto nla_put_failure; 2028 - dev = rtnl_dereference(nh->nh_dev); 1997 + dev = nh->nh_dev; 2029 1998 if (dev && nla_put_u32(skb, RTA_OIF, dev->ifindex)) 2030 1999 goto nla_put_failure; 2031 2000 if (nh->nh_flags & RTNH_F_LINKDOWN) ··· 2043 2012 goto nla_put_failure; 2044 2013 2045 2014 for_nexthops(rt) { 2046 - dev = rtnl_dereference(nh->nh_dev); 2015 + dev = nh->nh_dev; 2047 2016 if (!dev) 2048 2017 continue; 2049 2018 ··· 2154 2123 static bool mpls_rt_uses_dev(struct mpls_route *rt, 2155 2124 const struct net_device *dev) 2156 2125 { 2157 - struct net_device *nh_dev; 2158 - 2159 2126 if (rt->rt_nhn == 1) { 2160 2127 struct mpls_nh *nh = rt->rt_nh; 2161 2128 2162 - nh_dev = rtnl_dereference(nh->nh_dev); 2163 - if (dev == nh_dev) 2129 + if (nh->nh_dev == dev) 2164 2130 return true; 2165 2131 } else { 2166 2132 for_nexthops(rt) { 2167 - nh_dev = rtnl_dereference(nh->nh_dev); 2168 - if (nh_dev == dev) 2133 + if (nh->nh_dev == dev) 2169 2134 return true; 2170 2135 } endfor_nexthops(rt); 2171 2136 } ··· 2249 2222 size_t nhsize = 0; 2250 2223 2251 2224 for_nexthops(rt) { 2252 - if (!rtnl_dereference(nh->nh_dev)) 2225 + if (!nh->nh_dev) 2253 2226 continue; 2254 2227 nhsize += nla_total_size(sizeof(struct rtnexthop)); 2255 2228 /* RTA_VIA */ ··· 2495 2468 nla_put_via(skb, nh->nh_via_table, mpls_nh_via(rt, nh), 2496 2469 nh->nh_via_alen)) 2497 2470 goto nla_put_failure; 2498 - dev = rtnl_dereference(nh->nh_dev); 2471 + dev = nh->nh_dev; 2499 2472 if (dev && nla_put_u32(skb, RTA_OIF, dev->ifindex)) 2500 2473 goto nla_put_failure; 2501 2474 ··· 2534 2507 rt0 = mpls_rt_alloc(1, lo->addr_len, 0); 2535 2508 if (IS_ERR(rt0)) 2536 2509 goto nort0; 2537 - RCU_INIT_POINTER(rt0->rt_nh->nh_dev, lo); 2510 + rt0->rt_nh->nh_dev = lo; 2538 2511 rt0->rt_protocol = RTPROT_KERNEL; 2539 2512 rt0->rt_payload_type = MPT_IPV4; 2540 2513 rt0->rt_ttl_propagate = MPLS_TTL_PROP_DEFAULT; ··· 2548 2521 rt2 = mpls_rt_alloc(1, lo->addr_len, 0); 2549 2522 if (IS_ERR(rt2)) 2550 2523 goto nort2; 2551 - RCU_INIT_POINTER(rt2->rt_nh->nh_dev, lo); 2524 + rt2->rt_nh->nh_dev = lo; 2552 2525 rt2->rt_protocol = RTPROT_KERNEL; 2553 2526 rt2->rt_payload_type = MPT_IPV6; 2554 2527 rt2->rt_ttl_propagate = MPLS_TTL_PROP_DEFAULT;
+1 -1
net/mpls/internal.h
··· 87 87 }; 88 88 89 89 struct mpls_nh { /* next hop label forwarding entry */ 90 - struct net_device __rcu *nh_dev; 90 + struct net_device *nh_dev; 91 91 92 92 /* nh_flags is accessed under RCU in the packet path; it is 93 93 * modified handling netdev events with rtnl lock held
+5
net/netlink/af_netlink.c
··· 1848 1848 if (msg->msg_flags & MSG_OOB) 1849 1849 return -EOPNOTSUPP; 1850 1850 1851 + if (len == 0) { 1852 + pr_warn_once("Zero length message leads to an empty skb\n"); 1853 + return -ENODATA; 1854 + } 1855 + 1851 1856 err = scm_send(sock, msg, &scm, true); 1852 1857 if (err < 0) 1853 1858 return err;
+1 -1
net/rds/tcp.c
··· 500 500 sk->sk_userlocks |= SOCK_SNDBUF_LOCK; 501 501 } 502 502 if (rtn->rcvbuf_size > 0) { 503 - sk->sk_sndbuf = rtn->rcvbuf_size; 503 + sk->sk_rcvbuf = rtn->rcvbuf_size; 504 504 sk->sk_userlocks |= SOCK_RCVBUF_LOCK; 505 505 } 506 506 release_sock(sk);
+9 -5
net/rxrpc/conn_client.c
··· 135 135 return bundle; 136 136 } 137 137 138 + static void rxrpc_free_bundle(struct rxrpc_bundle *bundle) 139 + { 140 + rxrpc_put_peer(bundle->params.peer); 141 + kfree(bundle); 142 + } 143 + 138 144 void rxrpc_put_bundle(struct rxrpc_bundle *bundle) 139 145 { 140 146 unsigned int d = bundle->debug_id; 141 147 unsigned int u = atomic_dec_return(&bundle->usage); 142 148 143 149 _debug("PUT B=%x %u", d, u); 144 - if (u == 0) { 145 - rxrpc_put_peer(bundle->params.peer); 146 - kfree(bundle); 147 - } 150 + if (u == 0) 151 + rxrpc_free_bundle(bundle); 148 152 } 149 153 150 154 /* ··· 332 328 return candidate; 333 329 334 330 found_bundle_free: 335 - kfree(candidate); 331 + rxrpc_free_bundle(candidate); 336 332 found_bundle: 337 333 rxrpc_get_bundle(bundle); 338 334 spin_unlock(&local->client_bundles_lock);
+9 -5
net/rxrpc/peer_object.c
··· 299 299 return peer; 300 300 } 301 301 302 + static void rxrpc_free_peer(struct rxrpc_peer *peer) 303 + { 304 + rxrpc_put_local(peer->local); 305 + kfree_rcu(peer, rcu); 306 + } 307 + 302 308 /* 303 309 * Set up a new incoming peer. There shouldn't be any other matching peers 304 310 * since we've already done a search in the list from the non-reentrant context ··· 371 365 spin_unlock_bh(&rxnet->peer_hash_lock); 372 366 373 367 if (peer) 374 - kfree(candidate); 368 + rxrpc_free_peer(candidate); 375 369 else 376 370 peer = candidate; 377 371 } ··· 426 420 list_del_init(&peer->keepalive_link); 427 421 spin_unlock_bh(&rxnet->peer_hash_lock); 428 422 429 - rxrpc_put_local(peer->local); 430 - kfree_rcu(peer, rcu); 423 + rxrpc_free_peer(peer); 431 424 } 432 425 433 426 /* ··· 462 457 if (n == 0) { 463 458 hash_del_rcu(&peer->hash_link); 464 459 list_del_init(&peer->keepalive_link); 465 - rxrpc_put_local(peer->local); 466 - kfree_rcu(peer, rcu); 460 + rxrpc_free_peer(peer); 467 461 } 468 462 } 469 463
+6 -2
net/smc/smc_close.c
··· 195 195 int old_state; 196 196 long timeout; 197 197 int rc = 0; 198 + int rc1 = 0; 198 199 199 200 timeout = current->flags & PF_EXITING ? 200 201 0 : sock_flag(sk, SOCK_LINGER) ? ··· 233 232 /* actively shutdown clcsock before peer close it, 234 233 * prevent peer from entering TIME_WAIT state. 235 234 */ 236 - if (smc->clcsock && smc->clcsock->sk) 237 - rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR); 235 + if (smc->clcsock && smc->clcsock->sk) { 236 + rc1 = kernel_sock_shutdown(smc->clcsock, 237 + SHUT_RDWR); 238 + rc = rc ? rc : rc1; 239 + } 238 240 } else { 239 241 /* peer event has changed the state */ 240 242 goto again;
+3 -4
net/smc/smc_core.c
··· 625 625 void smc_lgr_cleanup_early(struct smc_connection *conn) 626 626 { 627 627 struct smc_link_group *lgr = conn->lgr; 628 - struct list_head *lgr_list; 629 628 spinlock_t *lgr_lock; 630 629 631 630 if (!lgr) 632 631 return; 633 632 634 633 smc_conn_free(conn); 635 - lgr_list = smc_lgr_list_head(lgr, &lgr_lock); 634 + smc_lgr_list_head(lgr, &lgr_lock); 636 635 spin_lock_bh(lgr_lock); 637 636 /* do not use this link group for new connections */ 638 - if (!list_empty(lgr_list)) 639 - list_del_init(lgr_list); 637 + if (!list_empty(&lgr->list)) 638 + list_del_init(&lgr->list); 640 639 spin_unlock_bh(lgr_lock); 641 640 __smc_lgr_terminate(lgr, true); 642 641 }
+5 -5
net/sunrpc/xprtsock.c
··· 1720 1720 } 1721 1721 1722 1722 #ifdef CONFIG_DEBUG_LOCK_ALLOC 1723 - static struct lock_class_key xs_key[2]; 1724 - static struct lock_class_key xs_slock_key[2]; 1723 + static struct lock_class_key xs_key[3]; 1724 + static struct lock_class_key xs_slock_key[3]; 1725 1725 1726 1726 static inline void xs_reclassify_socketu(struct socket *sock) 1727 1727 { 1728 1728 struct sock *sk = sock->sk; 1729 1729 1730 1730 sock_lock_init_class_and_name(sk, "slock-AF_LOCAL-RPC", 1731 - &xs_slock_key[1], "sk_lock-AF_LOCAL-RPC", &xs_key[1]); 1731 + &xs_slock_key[0], "sk_lock-AF_LOCAL-RPC", &xs_key[0]); 1732 1732 } 1733 1733 1734 1734 static inline void xs_reclassify_socket4(struct socket *sock) ··· 1736 1736 struct sock *sk = sock->sk; 1737 1737 1738 1738 sock_lock_init_class_and_name(sk, "slock-AF_INET-RPC", 1739 - &xs_slock_key[0], "sk_lock-AF_INET-RPC", &xs_key[0]); 1739 + &xs_slock_key[1], "sk_lock-AF_INET-RPC", &xs_key[1]); 1740 1740 } 1741 1741 1742 1742 static inline void xs_reclassify_socket6(struct socket *sock) ··· 1744 1744 struct sock *sk = sock->sk; 1745 1745 1746 1746 sock_lock_init_class_and_name(sk, "slock-AF_INET6-RPC", 1747 - &xs_slock_key[1], "sk_lock-AF_INET6-RPC", &xs_key[1]); 1747 + &xs_slock_key[2], "sk_lock-AF_INET6-RPC", &xs_key[2]); 1748 1748 } 1749 1749 1750 1750 static inline void xs_reclassify_socket(int family, struct socket *sock)
+2 -2
net/tls/tls_sw.c
··· 521 521 memcpy(&rec->iv_data[iv_offset], tls_ctx->tx.iv, 522 522 prot->iv_size + prot->salt_size); 523 523 524 - xor_iv_with_seq(prot, rec->iv_data, tls_ctx->tx.rec_seq); 524 + xor_iv_with_seq(prot, rec->iv_data + iv_offset, tls_ctx->tx.rec_seq); 525 525 526 526 sge->offset += prot->prepend_size; 527 527 sge->length -= prot->prepend_size; ··· 1499 1499 else 1500 1500 memcpy(iv + iv_offset, tls_ctx->rx.iv, prot->salt_size); 1501 1501 1502 - xor_iv_with_seq(prot, iv, tls_ctx->rx.rec_seq); 1502 + xor_iv_with_seq(prot, iv + iv_offset, tls_ctx->rx.rec_seq); 1503 1503 1504 1504 /* Prepare AAD */ 1505 1505 tls_make_aad(aad, rxm->full_len - prot->overhead_size +
-1
net/vmw_vsock/virtio_transport.c
··· 731 731 static struct virtio_driver virtio_vsock_driver = { 732 732 .feature_table = features, 733 733 .feature_table_size = ARRAY_SIZE(features), 734 - .suppress_used_validation = true, 735 734 .driver.name = KBUILD_MODNAME, 736 735 .driver.owner = THIS_MODULE, 737 736 .id_table = id_table,
+10
sound/hda/intel-dsp-config.c
··· 252 252 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE, 253 253 .device = 0x02c8, 254 254 }, 255 + { 256 + .flags = FLAG_SOF, 257 + .device = 0x02c8, 258 + .codec_hid = "ESSX8336", 259 + }, 255 260 /* Cometlake-H */ 256 261 { 257 262 .flags = FLAG_SOF, ··· 280 275 { 281 276 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE, 282 277 .device = 0x06c8, 278 + }, 279 + { 280 + .flags = FLAG_SOF, 281 + .device = 0x06c8, 282 + .codec_hid = "ESSX8336", 283 283 }, 284 284 #endif 285 285
+11 -1
sound/pci/hda/hda_intel.c
··· 335 335 ((pci)->device == 0x0c0c) || \ 336 336 ((pci)->device == 0x0d0c) || \ 337 337 ((pci)->device == 0x160c) || \ 338 - ((pci)->device == 0x490d)) 338 + ((pci)->device == 0x490d) || \ 339 + ((pci)->device == 0x4f90) || \ 340 + ((pci)->device == 0x4f91) || \ 341 + ((pci)->device == 0x4f92)) 339 342 340 343 #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98) 341 344 ··· 2475 2472 .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE}, 2476 2473 /* DG1 */ 2477 2474 { PCI_DEVICE(0x8086, 0x490d), 2475 + .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE}, 2476 + /* DG2 */ 2477 + { PCI_DEVICE(0x8086, 0x4f90), 2478 + .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE}, 2479 + { PCI_DEVICE(0x8086, 0x4f91), 2480 + .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE}, 2481 + { PCI_DEVICE(0x8086, 0x4f92), 2478 2482 .driver_data = AZX_DRIVER_SKL | AZX_DCAPS_INTEL_SKYLAKE}, 2479 2483 /* Alderlake-S */ 2480 2484 { PCI_DEVICE(0x8086, 0x7ad0),
+9
sound/pci/hda/hda_local.h
··· 438 438 #define for_each_hda_codec_node(nid, codec) \ 439 439 for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++) 440 440 441 + /* Set the codec power_state flag to indicate to allow unsol event handling; 442 + * see hda_codec_unsol_event() in hda_bind.c. Calling this might confuse the 443 + * state tracking, so use with care. 444 + */ 445 + static inline void snd_hda_codec_allow_unsol_events(struct hda_codec *codec) 446 + { 447 + codec->core.dev.power.power_state = PMSG_ON; 448 + } 449 + 441 450 /* 442 451 * get widget capabilities 443 452 */
+5
sound/pci/hda/patch_cs8409.c
··· 750 750 if (cs42l42->full_scale_vol) 751 751 cs8409_i2c_write(cs42l42, 0x2001, 0x01); 752 752 753 + /* we have to explicitly allow unsol event handling even during the 754 + * resume phase so that the jack event is processed properly 755 + */ 756 + snd_hda_codec_allow_unsol_events(cs42l42->codec); 757 + 753 758 cs42l42_enable_jack_detect(cs42l42); 754 759 } 755 760
+2 -1
sound/pci/hda/patch_hdmi.c
··· 4380 4380 HDA_CODEC_ENTRY(0x80862812, "Tigerlake HDMI", patch_i915_tgl_hdmi), 4381 4381 HDA_CODEC_ENTRY(0x80862814, "DG1 HDMI", patch_i915_tgl_hdmi), 4382 4382 HDA_CODEC_ENTRY(0x80862815, "Alderlake HDMI", patch_i915_tgl_hdmi), 4383 - HDA_CODEC_ENTRY(0x8086281c, "Alderlake-P HDMI", patch_i915_tgl_hdmi), 4384 4383 HDA_CODEC_ENTRY(0x80862816, "Rocketlake HDMI", patch_i915_tgl_hdmi), 4384 + HDA_CODEC_ENTRY(0x80862819, "DG2 HDMI", patch_i915_tgl_hdmi), 4385 4385 HDA_CODEC_ENTRY(0x8086281a, "Jasperlake HDMI", patch_i915_icl_hdmi), 4386 4386 HDA_CODEC_ENTRY(0x8086281b, "Elkhartlake HDMI", patch_i915_icl_hdmi), 4387 + HDA_CODEC_ENTRY(0x8086281c, "Alderlake-P HDMI", patch_i915_tgl_hdmi), 4387 4388 HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi), 4388 4389 HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi), 4389 4390 HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
+3 -29
sound/soc/codecs/cs35l41-spi.c
··· 42 42 43 43 MODULE_DEVICE_TABLE(spi, cs35l41_id_spi); 44 44 45 - static void cs35l41_spi_otp_setup(struct cs35l41_private *cs35l41, 46 - bool is_pre_setup, unsigned int *freq) 47 - { 48 - struct spi_device *spi; 49 - u32 orig_spi_freq; 50 - 51 - spi = to_spi_device(cs35l41->dev); 52 - 53 - if (!spi) { 54 - dev_err(cs35l41->dev, "%s: No SPI device\n", __func__); 55 - return; 56 - } 57 - 58 - if (is_pre_setup) { 59 - orig_spi_freq = spi->max_speed_hz; 60 - if (orig_spi_freq > CS35L41_SPI_MAX_FREQ_OTP) { 61 - spi->max_speed_hz = CS35L41_SPI_MAX_FREQ_OTP; 62 - spi_setup(spi); 63 - } 64 - *freq = orig_spi_freq; 65 - } else { 66 - if (spi->max_speed_hz != *freq) { 67 - spi->max_speed_hz = *freq; 68 - spi_setup(spi); 69 - } 70 - } 71 - } 72 - 73 45 static int cs35l41_spi_probe(struct spi_device *spi) 74 46 { 75 47 const struct regmap_config *regmap_config = &cs35l41_regmap_spi; ··· 53 81 if (!cs35l41) 54 82 return -ENOMEM; 55 83 84 + spi->max_speed_hz = CS35L41_SPI_MAX_FREQ; 85 + spi_setup(spi); 86 + 56 87 spi_set_drvdata(spi, cs35l41); 57 88 cs35l41->regmap = devm_regmap_init_spi(spi, regmap_config); 58 89 if (IS_ERR(cs35l41->regmap)) { ··· 66 91 67 92 cs35l41->dev = &spi->dev; 68 93 cs35l41->irq = spi->irq; 69 - cs35l41->otp_setup = cs35l41_spi_otp_setup; 70 94 71 95 return cs35l41_probe(cs35l41, pdata); 72 96 }
-7
sound/soc/codecs/cs35l41.c
··· 302 302 const struct cs35l41_otp_packed_element_t *otp_map; 303 303 struct cs35l41_private *cs35l41 = data; 304 304 int bit_offset, word_offset, ret, i; 305 - unsigned int orig_spi_freq; 306 305 unsigned int bit_sum = 8; 307 306 u32 otp_val, otp_id_reg; 308 307 u32 *otp_mem; ··· 325 326 goto err_otp_unpack; 326 327 } 327 328 328 - if (cs35l41->otp_setup) 329 - cs35l41->otp_setup(cs35l41, true, &orig_spi_freq); 330 - 331 329 ret = regmap_bulk_read(cs35l41->regmap, CS35L41_OTP_MEM0, otp_mem, 332 330 CS35L41_OTP_SIZE_WORDS); 333 331 if (ret < 0) { 334 332 dev_err(cs35l41->dev, "Read OTP Mem failed: %d\n", ret); 335 333 goto err_otp_unpack; 336 334 } 337 - 338 - if (cs35l41->otp_setup) 339 - cs35l41->otp_setup(cs35l41, false, &orig_spi_freq); 340 335 341 336 otp_map = otp_map_match->map; 342 337
+1 -3
sound/soc/codecs/cs35l41.h
··· 726 726 #define CS35L41_FS2_WINDOW_MASK 0x00FFF800 727 727 #define CS35L41_FS2_WINDOW_SHIFT 12 728 728 729 - #define CS35L41_SPI_MAX_FREQ_OTP 4000000 729 + #define CS35L41_SPI_MAX_FREQ 4000000 730 730 731 731 #define CS35L41_RX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE) 732 732 #define CS35L41_TX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE) ··· 764 764 int irq; 765 765 /* GPIO for /RST */ 766 766 struct gpio_desc *reset_gpio; 767 - void (*otp_setup)(struct cs35l41_private *cs35l41, bool is_pre_setup, 768 - unsigned int *freq); 769 767 }; 770 768 771 769 int cs35l41_probe(struct cs35l41_private *cs35l41,
+1
sound/soc/codecs/rk817_codec.c
··· 539 539 MODULE_DESCRIPTION("ASoC RK817 codec driver"); 540 540 MODULE_AUTHOR("binyuan <kevan.lan@rock-chips.com>"); 541 541 MODULE_LICENSE("GPL v2"); 542 + MODULE_ALIAS("platform:rk817-codec");
+6
sound/soc/intel/common/soc-acpi-intel-cml-match.c
··· 81 81 .sof_fw_filename = "sof-cml.ri", 82 82 .sof_tplg_filename = "sof-cml-da7219-max98390.tplg", 83 83 }, 84 + { 85 + .id = "ESSX8336", 86 + .drv_name = "sof-essx8336", 87 + .sof_fw_filename = "sof-cml.ri", 88 + .sof_tplg_filename = "sof-cml-es8336.tplg", 89 + }, 84 90 {}, 85 91 }; 86 92 EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_cml_machines);
+3 -1
sound/soc/soc-acpi.c
··· 20 20 21 21 if (comp_ids) { 22 22 for (i = 0; i < comp_ids->num_codecs; i++) { 23 - if (acpi_dev_present(comp_ids->codecs[i], NULL, -1)) 23 + if (acpi_dev_present(comp_ids->codecs[i], NULL, -1)) { 24 + strscpy(machine->id, comp_ids->codecs[i], ACPI_ID_LEN); 24 25 return true; 26 + } 25 27 } 26 28 } 27 29
+7
sound/soc/sof/intel/hda.c
··· 58 58 return -EINVAL; 59 59 } 60 60 61 + /* DAI already configured, reset it before reconfiguring it */ 62 + if (sof_dai->configured) { 63 + ret = hda_ctrl_dai_widget_free(w); 64 + if (ret < 0) 65 + return ret; 66 + } 67 + 61 68 config = &sof_dai->dai_config[sof_dai->current_config]; 62 69 63 70 /*
+146 -33
sound/soc/tegra/tegra186_dspk.c
··· 26 26 { TEGRA186_DSPK_CODEC_CTRL, 0x03000000 }, 27 27 }; 28 28 29 - static int tegra186_dspk_get_control(struct snd_kcontrol *kcontrol, 29 + static int tegra186_dspk_get_fifo_th(struct snd_kcontrol *kcontrol, 30 30 struct snd_ctl_elem_value *ucontrol) 31 31 { 32 32 struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 33 33 struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 34 34 35 - if (strstr(kcontrol->id.name, "FIFO Threshold")) 36 - ucontrol->value.integer.value[0] = dspk->rx_fifo_th; 37 - else if (strstr(kcontrol->id.name, "OSR Value")) 38 - ucontrol->value.integer.value[0] = dspk->osr_val; 39 - else if (strstr(kcontrol->id.name, "LR Polarity Select")) 40 - ucontrol->value.integer.value[0] = dspk->lrsel; 41 - else if (strstr(kcontrol->id.name, "Channel Select")) 42 - ucontrol->value.integer.value[0] = dspk->ch_sel; 43 - else if (strstr(kcontrol->id.name, "Mono To Stereo")) 44 - ucontrol->value.integer.value[0] = dspk->mono_to_stereo; 45 - else if (strstr(kcontrol->id.name, "Stereo To Mono")) 46 - ucontrol->value.integer.value[0] = dspk->stereo_to_mono; 35 + ucontrol->value.integer.value[0] = dspk->rx_fifo_th; 47 36 48 37 return 0; 49 38 } 50 39 51 - static int tegra186_dspk_put_control(struct snd_kcontrol *kcontrol, 40 + static int tegra186_dspk_put_fifo_th(struct snd_kcontrol *kcontrol, 52 41 struct snd_ctl_elem_value *ucontrol) 53 42 { 54 43 struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 55 44 struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 56 - int val = ucontrol->value.integer.value[0]; 45 + int value = ucontrol->value.integer.value[0]; 57 46 58 - if (strstr(kcontrol->id.name, "FIFO Threshold")) 59 - dspk->rx_fifo_th = val; 60 - else if (strstr(kcontrol->id.name, "OSR Value")) 61 - dspk->osr_val = val; 62 - else if (strstr(kcontrol->id.name, "LR Polarity Select")) 63 - dspk->lrsel = val; 64 - else if (strstr(kcontrol->id.name, "Channel Select")) 65 - dspk->ch_sel = val; 66 - else if (strstr(kcontrol->id.name, "Mono To Stereo")) 67 - dspk->mono_to_stereo = val; 68 - else if (strstr(kcontrol->id.name, "Stereo To Mono")) 69 - dspk->stereo_to_mono = val; 47 + if (value == dspk->rx_fifo_th) 48 + return 0; 49 + 50 + dspk->rx_fifo_th = value; 51 + 52 + return 1; 53 + } 54 + 55 + static int tegra186_dspk_get_osr_val(struct snd_kcontrol *kcontrol, 56 + struct snd_ctl_elem_value *ucontrol) 57 + { 58 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 59 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 60 + 61 + ucontrol->value.enumerated.item[0] = dspk->osr_val; 70 62 71 63 return 0; 64 + } 65 + 66 + static int tegra186_dspk_put_osr_val(struct snd_kcontrol *kcontrol, 67 + struct snd_ctl_elem_value *ucontrol) 68 + { 69 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 70 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 71 + unsigned int value = ucontrol->value.enumerated.item[0]; 72 + 73 + if (value == dspk->osr_val) 74 + return 0; 75 + 76 + dspk->osr_val = value; 77 + 78 + return 1; 79 + } 80 + 81 + static int tegra186_dspk_get_pol_sel(struct snd_kcontrol *kcontrol, 82 + struct snd_ctl_elem_value *ucontrol) 83 + { 84 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 85 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 86 + 87 + ucontrol->value.enumerated.item[0] = dspk->lrsel; 88 + 89 + return 0; 90 + } 91 + 92 + static int tegra186_dspk_put_pol_sel(struct snd_kcontrol *kcontrol, 93 + struct snd_ctl_elem_value *ucontrol) 94 + { 95 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 96 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 97 + unsigned int value = ucontrol->value.enumerated.item[0]; 98 + 99 + if (value == dspk->lrsel) 100 + return 0; 101 + 102 + dspk->lrsel = value; 103 + 104 + return 1; 105 + } 106 + 107 + static int tegra186_dspk_get_ch_sel(struct snd_kcontrol *kcontrol, 108 + struct snd_ctl_elem_value *ucontrol) 109 + { 110 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 111 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 112 + 113 + ucontrol->value.enumerated.item[0] = dspk->ch_sel; 114 + 115 + return 0; 116 + } 117 + 118 + static int tegra186_dspk_put_ch_sel(struct snd_kcontrol *kcontrol, 119 + struct snd_ctl_elem_value *ucontrol) 120 + { 121 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 122 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 123 + unsigned int value = ucontrol->value.enumerated.item[0]; 124 + 125 + if (value == dspk->ch_sel) 126 + return 0; 127 + 128 + dspk->ch_sel = value; 129 + 130 + return 1; 131 + } 132 + 133 + static int tegra186_dspk_get_mono_to_stereo(struct snd_kcontrol *kcontrol, 134 + struct snd_ctl_elem_value *ucontrol) 135 + { 136 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 137 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 138 + 139 + ucontrol->value.enumerated.item[0] = dspk->mono_to_stereo; 140 + 141 + return 0; 142 + } 143 + 144 + static int tegra186_dspk_put_mono_to_stereo(struct snd_kcontrol *kcontrol, 145 + struct snd_ctl_elem_value *ucontrol) 146 + { 147 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 148 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 149 + unsigned int value = ucontrol->value.enumerated.item[0]; 150 + 151 + if (value == dspk->mono_to_stereo) 152 + return 0; 153 + 154 + dspk->mono_to_stereo = value; 155 + 156 + return 1; 157 + } 158 + 159 + static int tegra186_dspk_get_stereo_to_mono(struct snd_kcontrol *kcontrol, 160 + struct snd_ctl_elem_value *ucontrol) 161 + { 162 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 163 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 164 + 165 + ucontrol->value.enumerated.item[0] = dspk->stereo_to_mono; 166 + 167 + return 0; 168 + } 169 + 170 + static int tegra186_dspk_put_stereo_to_mono(struct snd_kcontrol *kcontrol, 171 + struct snd_ctl_elem_value *ucontrol) 172 + { 173 + struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol); 174 + struct tegra186_dspk *dspk = snd_soc_component_get_drvdata(codec); 175 + unsigned int value = ucontrol->value.enumerated.item[0]; 176 + 177 + if (value == dspk->stereo_to_mono) 178 + return 0; 179 + 180 + dspk->stereo_to_mono = value; 181 + 182 + return 1; 72 183 } 73 184 74 185 static int __maybe_unused tegra186_dspk_runtime_suspend(struct device *dev) ··· 390 279 static const struct snd_kcontrol_new tegrat186_dspk_controls[] = { 391 280 SOC_SINGLE_EXT("FIFO Threshold", SND_SOC_NOPM, 0, 392 281 TEGRA186_DSPK_RX_FIFO_DEPTH - 1, 0, 393 - tegra186_dspk_get_control, tegra186_dspk_put_control), 282 + tegra186_dspk_get_fifo_th, tegra186_dspk_put_fifo_th), 394 283 SOC_ENUM_EXT("OSR Value", tegra186_dspk_osr_enum, 395 - tegra186_dspk_get_control, tegra186_dspk_put_control), 284 + tegra186_dspk_get_osr_val, tegra186_dspk_put_osr_val), 396 285 SOC_ENUM_EXT("LR Polarity Select", tegra186_dspk_lrsel_enum, 397 - tegra186_dspk_get_control, tegra186_dspk_put_control), 286 + tegra186_dspk_get_pol_sel, tegra186_dspk_put_pol_sel), 398 287 SOC_ENUM_EXT("Channel Select", tegra186_dspk_ch_sel_enum, 399 - tegra186_dspk_get_control, tegra186_dspk_put_control), 288 + tegra186_dspk_get_ch_sel, tegra186_dspk_put_ch_sel), 400 289 SOC_ENUM_EXT("Mono To Stereo", tegra186_dspk_mono_conv_enum, 401 - tegra186_dspk_get_control, tegra186_dspk_put_control), 290 + tegra186_dspk_get_mono_to_stereo, 291 + tegra186_dspk_put_mono_to_stereo), 402 292 SOC_ENUM_EXT("Stereo To Mono", tegra186_dspk_stereo_conv_enum, 403 - tegra186_dspk_get_control, tegra186_dspk_put_control), 293 + tegra186_dspk_get_stereo_to_mono, 294 + tegra186_dspk_put_stereo_to_mono), 404 295 }; 405 296 406 297 static const struct snd_soc_component_driver tegra186_dspk_cmpnt = {
+112 -32
sound/soc/tegra/tegra210_admaif.c
··· 424 424 .trigger = tegra_admaif_trigger, 425 425 }; 426 426 427 - static int tegra_admaif_get_control(struct snd_kcontrol *kcontrol, 428 - struct snd_ctl_elem_value *ucontrol) 427 + static int tegra210_admaif_pget_mono_to_stereo(struct snd_kcontrol *kcontrol, 428 + struct snd_ctl_elem_value *ucontrol) 429 429 { 430 430 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 431 - struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 432 431 struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 433 - long *uctl_val = &ucontrol->value.integer.value[0]; 432 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 434 433 435 - if (strstr(kcontrol->id.name, "Playback Mono To Stereo")) 436 - *uctl_val = admaif->mono_to_stereo[ADMAIF_TX_PATH][ec->reg]; 437 - else if (strstr(kcontrol->id.name, "Capture Mono To Stereo")) 438 - *uctl_val = admaif->mono_to_stereo[ADMAIF_RX_PATH][ec->reg]; 439 - else if (strstr(kcontrol->id.name, "Playback Stereo To Mono")) 440 - *uctl_val = admaif->stereo_to_mono[ADMAIF_TX_PATH][ec->reg]; 441 - else if (strstr(kcontrol->id.name, "Capture Stereo To Mono")) 442 - *uctl_val = admaif->stereo_to_mono[ADMAIF_RX_PATH][ec->reg]; 434 + ucontrol->value.enumerated.item[0] = 435 + admaif->mono_to_stereo[ADMAIF_TX_PATH][ec->reg]; 443 436 444 437 return 0; 445 438 } 446 439 447 - static int tegra_admaif_put_control(struct snd_kcontrol *kcontrol, 448 - struct snd_ctl_elem_value *ucontrol) 440 + static int tegra210_admaif_pput_mono_to_stereo(struct snd_kcontrol *kcontrol, 441 + struct snd_ctl_elem_value *ucontrol) 449 442 { 450 443 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 451 - struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 452 444 struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 453 - int value = ucontrol->value.integer.value[0]; 445 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 446 + unsigned int value = ucontrol->value.enumerated.item[0]; 454 447 455 - if (strstr(kcontrol->id.name, "Playback Mono To Stereo")) 456 - admaif->mono_to_stereo[ADMAIF_TX_PATH][ec->reg] = value; 457 - else if (strstr(kcontrol->id.name, "Capture Mono To Stereo")) 458 - admaif->mono_to_stereo[ADMAIF_RX_PATH][ec->reg] = value; 459 - else if (strstr(kcontrol->id.name, "Playback Stereo To Mono")) 460 - admaif->stereo_to_mono[ADMAIF_TX_PATH][ec->reg] = value; 461 - else if (strstr(kcontrol->id.name, "Capture Stereo To Mono")) 462 - admaif->stereo_to_mono[ADMAIF_RX_PATH][ec->reg] = value; 448 + if (value == admaif->mono_to_stereo[ADMAIF_TX_PATH][ec->reg]) 449 + return 0; 450 + 451 + admaif->mono_to_stereo[ADMAIF_TX_PATH][ec->reg] = value; 452 + 453 + return 1; 454 + } 455 + 456 + static int tegra210_admaif_cget_mono_to_stereo(struct snd_kcontrol *kcontrol, 457 + struct snd_ctl_elem_value *ucontrol) 458 + { 459 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 460 + struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 461 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 462 + 463 + ucontrol->value.enumerated.item[0] = 464 + admaif->mono_to_stereo[ADMAIF_RX_PATH][ec->reg]; 463 465 464 466 return 0; 467 + } 468 + 469 + static int tegra210_admaif_cput_mono_to_stereo(struct snd_kcontrol *kcontrol, 470 + struct snd_ctl_elem_value *ucontrol) 471 + { 472 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 473 + struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 474 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 475 + unsigned int value = ucontrol->value.enumerated.item[0]; 476 + 477 + if (value == admaif->mono_to_stereo[ADMAIF_RX_PATH][ec->reg]) 478 + return 0; 479 + 480 + admaif->mono_to_stereo[ADMAIF_RX_PATH][ec->reg] = value; 481 + 482 + return 1; 483 + } 484 + 485 + static int tegra210_admaif_pget_stereo_to_mono(struct snd_kcontrol *kcontrol, 486 + struct snd_ctl_elem_value *ucontrol) 487 + { 488 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 489 + struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 490 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 491 + 492 + ucontrol->value.enumerated.item[0] = 493 + admaif->stereo_to_mono[ADMAIF_TX_PATH][ec->reg]; 494 + 495 + return 0; 496 + } 497 + 498 + static int tegra210_admaif_pput_stereo_to_mono(struct snd_kcontrol *kcontrol, 499 + struct snd_ctl_elem_value *ucontrol) 500 + { 501 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 502 + struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 503 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 504 + unsigned int value = ucontrol->value.enumerated.item[0]; 505 + 506 + if (value == admaif->stereo_to_mono[ADMAIF_TX_PATH][ec->reg]) 507 + return 0; 508 + 509 + admaif->stereo_to_mono[ADMAIF_TX_PATH][ec->reg] = value; 510 + 511 + return 1; 512 + } 513 + 514 + static int tegra210_admaif_cget_stereo_to_mono(struct snd_kcontrol *kcontrol, 515 + struct snd_ctl_elem_value *ucontrol) 516 + { 517 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 518 + struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 519 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 520 + 521 + ucontrol->value.enumerated.item[0] = 522 + admaif->stereo_to_mono[ADMAIF_RX_PATH][ec->reg]; 523 + 524 + return 0; 525 + } 526 + 527 + static int tegra210_admaif_cput_stereo_to_mono(struct snd_kcontrol *kcontrol, 528 + struct snd_ctl_elem_value *ucontrol) 529 + { 530 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 531 + struct tegra_admaif *admaif = snd_soc_component_get_drvdata(cmpnt); 532 + struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value; 533 + unsigned int value = ucontrol->value.enumerated.item[0]; 534 + 535 + if (value == admaif->stereo_to_mono[ADMAIF_RX_PATH][ec->reg]) 536 + return 0; 537 + 538 + admaif->stereo_to_mono[ADMAIF_RX_PATH][ec->reg] = value; 539 + 540 + return 1; 465 541 } 466 542 467 543 static int tegra_admaif_dai_probe(struct snd_soc_dai *dai) ··· 635 559 } 636 560 637 561 #define TEGRA_ADMAIF_CIF_CTRL(reg) \ 638 - NV_SOC_ENUM_EXT("ADMAIF" #reg " Playback Mono To Stereo", reg - 1,\ 639 - tegra_admaif_get_control, tegra_admaif_put_control, \ 562 + NV_SOC_ENUM_EXT("ADMAIF" #reg " Playback Mono To Stereo", reg - 1, \ 563 + tegra210_admaif_pget_mono_to_stereo, \ 564 + tegra210_admaif_pput_mono_to_stereo, \ 640 565 tegra_admaif_mono_conv_text), \ 641 - NV_SOC_ENUM_EXT("ADMAIF" #reg " Playback Stereo To Mono", reg - 1,\ 642 - tegra_admaif_get_control, tegra_admaif_put_control, \ 566 + NV_SOC_ENUM_EXT("ADMAIF" #reg " Playback Stereo To Mono", reg - 1, \ 567 + tegra210_admaif_pget_stereo_to_mono, \ 568 + tegra210_admaif_pput_stereo_to_mono, \ 643 569 tegra_admaif_stereo_conv_text), \ 644 - NV_SOC_ENUM_EXT("ADMAIF" #reg " Capture Mono To Stereo", reg - 1, \ 645 - tegra_admaif_get_control, tegra_admaif_put_control, \ 570 + NV_SOC_ENUM_EXT("ADMAIF" #reg " Capture Mono To Stereo", reg - 1, \ 571 + tegra210_admaif_cget_mono_to_stereo, \ 572 + tegra210_admaif_cput_mono_to_stereo, \ 646 573 tegra_admaif_mono_conv_text), \ 647 - NV_SOC_ENUM_EXT("ADMAIF" #reg " Capture Stereo To Mono", reg - 1, \ 648 - tegra_admaif_get_control, tegra_admaif_put_control, \ 574 + NV_SOC_ENUM_EXT("ADMAIF" #reg " Capture Stereo To Mono", reg - 1, \ 575 + tegra210_admaif_cget_stereo_to_mono, \ 576 + tegra210_admaif_cput_stereo_to_mono, \ 649 577 tegra_admaif_stereo_conv_text) 650 578 651 579 static struct snd_kcontrol_new tegra210_admaif_controls[] = {
+3
sound/soc/tegra/tegra210_adx.c
··· 193 193 struct soc_mixer_control *mc = 194 194 (struct soc_mixer_control *)kcontrol->private_value;; 195 195 196 + if (value == bytes_map[mc->reg]) 197 + return 0; 198 + 196 199 if (value >= 0 && value <= 255) { 197 200 /* update byte map and enable slot */ 198 201 bytes_map[mc->reg] = value;
+7 -4
sound/soc/tegra/tegra210_ahub.c
··· 62 62 unsigned int *item = uctl->value.enumerated.item; 63 63 unsigned int value = e->values[item[0]]; 64 64 unsigned int i, bit_pos, reg_idx = 0, reg_val = 0; 65 + int change = 0; 65 66 66 67 if (item[0] >= e->items) 67 68 return -EINVAL; ··· 87 86 88 87 /* Update widget power if state has changed */ 89 88 if (snd_soc_component_test_bits(cmpnt, update[i].reg, 90 - update[i].mask, update[i].val)) 91 - snd_soc_dapm_mux_update_power(dapm, kctl, item[0], e, 92 - &update[i]); 89 + update[i].mask, 90 + update[i].val)) 91 + change |= snd_soc_dapm_mux_update_power(dapm, kctl, 92 + item[0], e, 93 + &update[i]); 93 94 } 94 95 95 - return 0; 96 + return change; 96 97 } 97 98 98 99 static struct snd_soc_dai_driver tegra210_ahub_dais[] = {
+3
sound/soc/tegra/tegra210_amx.c
··· 222 222 int reg = mc->reg; 223 223 int value = ucontrol->value.integer.value[0]; 224 224 225 + if (value == bytes_map[reg]) 226 + return 0; 227 + 225 228 if (value >= 0 && value <= 255) { 226 229 /* Update byte map and enable slot */ 227 230 bytes_map[reg] = value;
+150 -36
sound/soc/tegra/tegra210_dmic.c
··· 156 156 return 0; 157 157 } 158 158 159 - static int tegra210_dmic_get_control(struct snd_kcontrol *kcontrol, 160 - struct snd_ctl_elem_value *ucontrol) 159 + static int tegra210_dmic_get_boost_gain(struct snd_kcontrol *kcontrol, 160 + struct snd_ctl_elem_value *ucontrol) 161 161 { 162 162 struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 163 163 struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 164 164 165 - if (strstr(kcontrol->id.name, "Boost Gain Volume")) 166 - ucontrol->value.integer.value[0] = dmic->boost_gain; 167 - else if (strstr(kcontrol->id.name, "Channel Select")) 168 - ucontrol->value.integer.value[0] = dmic->ch_select; 169 - else if (strstr(kcontrol->id.name, "Mono To Stereo")) 170 - ucontrol->value.integer.value[0] = dmic->mono_to_stereo; 171 - else if (strstr(kcontrol->id.name, "Stereo To Mono")) 172 - ucontrol->value.integer.value[0] = dmic->stereo_to_mono; 173 - else if (strstr(kcontrol->id.name, "OSR Value")) 174 - ucontrol->value.integer.value[0] = dmic->osr_val; 175 - else if (strstr(kcontrol->id.name, "LR Polarity Select")) 176 - ucontrol->value.integer.value[0] = dmic->lrsel; 165 + ucontrol->value.integer.value[0] = dmic->boost_gain; 177 166 178 167 return 0; 179 168 } 180 169 181 - static int tegra210_dmic_put_control(struct snd_kcontrol *kcontrol, 182 - struct snd_ctl_elem_value *ucontrol) 170 + static int tegra210_dmic_put_boost_gain(struct snd_kcontrol *kcontrol, 171 + struct snd_ctl_elem_value *ucontrol) 183 172 { 184 173 struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 185 174 struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 186 175 int value = ucontrol->value.integer.value[0]; 187 176 188 - if (strstr(kcontrol->id.name, "Boost Gain Volume")) 189 - dmic->boost_gain = value; 190 - else if (strstr(kcontrol->id.name, "Channel Select")) 191 - dmic->ch_select = ucontrol->value.integer.value[0]; 192 - else if (strstr(kcontrol->id.name, "Mono To Stereo")) 193 - dmic->mono_to_stereo = value; 194 - else if (strstr(kcontrol->id.name, "Stereo To Mono")) 195 - dmic->stereo_to_mono = value; 196 - else if (strstr(kcontrol->id.name, "OSR Value")) 197 - dmic->osr_val = value; 198 - else if (strstr(kcontrol->id.name, "LR Polarity Select")) 199 - dmic->lrsel = value; 177 + if (value == dmic->boost_gain) 178 + return 0; 179 + 180 + dmic->boost_gain = value; 181 + 182 + return 1; 183 + } 184 + 185 + static int tegra210_dmic_get_ch_select(struct snd_kcontrol *kcontrol, 186 + struct snd_ctl_elem_value *ucontrol) 187 + { 188 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 189 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 190 + 191 + ucontrol->value.enumerated.item[0] = dmic->ch_select; 200 192 201 193 return 0; 194 + } 195 + 196 + static int tegra210_dmic_put_ch_select(struct snd_kcontrol *kcontrol, 197 + struct snd_ctl_elem_value *ucontrol) 198 + { 199 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 200 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 201 + unsigned int value = ucontrol->value.enumerated.item[0]; 202 + 203 + if (value == dmic->ch_select) 204 + return 0; 205 + 206 + dmic->ch_select = value; 207 + 208 + return 1; 209 + } 210 + 211 + static int tegra210_dmic_get_mono_to_stereo(struct snd_kcontrol *kcontrol, 212 + struct snd_ctl_elem_value *ucontrol) 213 + { 214 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 215 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 216 + 217 + ucontrol->value.enumerated.item[0] = dmic->mono_to_stereo; 218 + 219 + return 0; 220 + } 221 + 222 + static int tegra210_dmic_put_mono_to_stereo(struct snd_kcontrol *kcontrol, 223 + struct snd_ctl_elem_value *ucontrol) 224 + { 225 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 226 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 227 + unsigned int value = ucontrol->value.enumerated.item[0]; 228 + 229 + if (value == dmic->mono_to_stereo) 230 + return 0; 231 + 232 + dmic->mono_to_stereo = value; 233 + 234 + return 1; 235 + } 236 + 237 + static int tegra210_dmic_get_stereo_to_mono(struct snd_kcontrol *kcontrol, 238 + struct snd_ctl_elem_value *ucontrol) 239 + { 240 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 241 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 242 + 243 + ucontrol->value.enumerated.item[0] = dmic->stereo_to_mono; 244 + 245 + return 0; 246 + } 247 + 248 + static int tegra210_dmic_put_stereo_to_mono(struct snd_kcontrol *kcontrol, 249 + struct snd_ctl_elem_value *ucontrol) 250 + { 251 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 252 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 253 + unsigned int value = ucontrol->value.enumerated.item[0]; 254 + 255 + if (value == dmic->stereo_to_mono) 256 + return 0; 257 + 258 + dmic->stereo_to_mono = value; 259 + 260 + return 1; 261 + } 262 + 263 + static int tegra210_dmic_get_osr_val(struct snd_kcontrol *kcontrol, 264 + struct snd_ctl_elem_value *ucontrol) 265 + { 266 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 267 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 268 + 269 + ucontrol->value.enumerated.item[0] = dmic->osr_val; 270 + 271 + return 0; 272 + } 273 + 274 + static int tegra210_dmic_put_osr_val(struct snd_kcontrol *kcontrol, 275 + struct snd_ctl_elem_value *ucontrol) 276 + { 277 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 278 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 279 + unsigned int value = ucontrol->value.enumerated.item[0]; 280 + 281 + if (value == dmic->osr_val) 282 + return 0; 283 + 284 + dmic->osr_val = value; 285 + 286 + return 1; 287 + } 288 + 289 + static int tegra210_dmic_get_pol_sel(struct snd_kcontrol *kcontrol, 290 + struct snd_ctl_elem_value *ucontrol) 291 + { 292 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 293 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 294 + 295 + ucontrol->value.enumerated.item[0] = dmic->lrsel; 296 + 297 + return 0; 298 + } 299 + 300 + static int tegra210_dmic_put_pol_sel(struct snd_kcontrol *kcontrol, 301 + struct snd_ctl_elem_value *ucontrol) 302 + { 303 + struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 304 + struct tegra210_dmic *dmic = snd_soc_component_get_drvdata(comp); 305 + unsigned int value = ucontrol->value.enumerated.item[0]; 306 + 307 + if (value == dmic->lrsel) 308 + return 0; 309 + 310 + dmic->lrsel = value; 311 + 312 + return 1; 202 313 } 203 314 204 315 static const struct snd_soc_dai_ops tegra210_dmic_dai_ops = { ··· 398 287 399 288 static const struct snd_kcontrol_new tegra210_dmic_controls[] = { 400 289 SOC_SINGLE_EXT("Boost Gain Volume", 0, 0, MAX_BOOST_GAIN, 0, 401 - tegra210_dmic_get_control, tegra210_dmic_put_control), 290 + tegra210_dmic_get_boost_gain, 291 + tegra210_dmic_put_boost_gain), 402 292 SOC_ENUM_EXT("Channel Select", tegra210_dmic_ch_enum, 403 - tegra210_dmic_get_control, tegra210_dmic_put_control), 293 + tegra210_dmic_get_ch_select, tegra210_dmic_put_ch_select), 404 294 SOC_ENUM_EXT("Mono To Stereo", 405 - tegra210_dmic_mono_conv_enum, tegra210_dmic_get_control, 406 - tegra210_dmic_put_control), 295 + tegra210_dmic_mono_conv_enum, 296 + tegra210_dmic_get_mono_to_stereo, 297 + tegra210_dmic_put_mono_to_stereo), 407 298 SOC_ENUM_EXT("Stereo To Mono", 408 - tegra210_dmic_stereo_conv_enum, tegra210_dmic_get_control, 409 - tegra210_dmic_put_control), 299 + tegra210_dmic_stereo_conv_enum, 300 + tegra210_dmic_get_stereo_to_mono, 301 + tegra210_dmic_put_stereo_to_mono), 410 302 SOC_ENUM_EXT("OSR Value", tegra210_dmic_osr_enum, 411 - tegra210_dmic_get_control, tegra210_dmic_put_control), 303 + tegra210_dmic_get_osr_val, tegra210_dmic_put_osr_val), 412 304 SOC_ENUM_EXT("LR Polarity Select", tegra210_dmic_lrsel_enum, 413 - tegra210_dmic_get_control, tegra210_dmic_put_control), 305 + tegra210_dmic_get_pol_sel, tegra210_dmic_put_pol_sel), 414 306 }; 415 307 416 308 static const struct snd_soc_component_driver tegra210_dmic_compnt = {
+240 -84
sound/soc/tegra/tegra210_i2s.c
··· 302 302 return 0; 303 303 } 304 304 305 + static int tegra210_i2s_get_loopback(struct snd_kcontrol *kcontrol, 306 + struct snd_ctl_elem_value *ucontrol) 307 + { 308 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 309 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 310 + 311 + ucontrol->value.integer.value[0] = i2s->loopback; 312 + 313 + return 0; 314 + } 315 + 316 + static int tegra210_i2s_put_loopback(struct snd_kcontrol *kcontrol, 317 + struct snd_ctl_elem_value *ucontrol) 318 + { 319 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 320 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 321 + int value = ucontrol->value.integer.value[0]; 322 + 323 + if (value == i2s->loopback) 324 + return 0; 325 + 326 + i2s->loopback = value; 327 + 328 + regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, I2S_CTRL_LPBK_MASK, 329 + i2s->loopback << I2S_CTRL_LPBK_SHIFT); 330 + 331 + return 1; 332 + } 333 + 334 + static int tegra210_i2s_get_fsync_width(struct snd_kcontrol *kcontrol, 335 + struct snd_ctl_elem_value *ucontrol) 336 + { 337 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 338 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 339 + 340 + ucontrol->value.integer.value[0] = i2s->fsync_width; 341 + 342 + return 0; 343 + } 344 + 345 + static int tegra210_i2s_put_fsync_width(struct snd_kcontrol *kcontrol, 346 + struct snd_ctl_elem_value *ucontrol) 347 + { 348 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 349 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 350 + int value = ucontrol->value.integer.value[0]; 351 + 352 + if (value == i2s->fsync_width) 353 + return 0; 354 + 355 + i2s->fsync_width = value; 356 + 357 + /* 358 + * Frame sync width is used only for FSYNC modes and not 359 + * applicable for LRCK modes. Reset value for this field is "0", 360 + * which means the width is one bit clock wide. 361 + * The width requirement may depend on the codec and in such 362 + * cases mixer control is used to update custom values. A value 363 + * of "N" here means, width is "N + 1" bit clock wide. 364 + */ 365 + regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, 366 + I2S_CTRL_FSYNC_WIDTH_MASK, 367 + i2s->fsync_width << I2S_FSYNC_WIDTH_SHIFT); 368 + 369 + return 1; 370 + } 371 + 372 + static int tegra210_i2s_cget_stereo_to_mono(struct snd_kcontrol *kcontrol, 373 + struct snd_ctl_elem_value *ucontrol) 374 + { 375 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 376 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 377 + 378 + ucontrol->value.enumerated.item[0] = i2s->stereo_to_mono[I2S_TX_PATH]; 379 + 380 + return 0; 381 + } 382 + 383 + static int tegra210_i2s_cput_stereo_to_mono(struct snd_kcontrol *kcontrol, 384 + struct snd_ctl_elem_value *ucontrol) 385 + { 386 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 387 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 388 + unsigned int value = ucontrol->value.enumerated.item[0]; 389 + 390 + if (value == i2s->stereo_to_mono[I2S_TX_PATH]) 391 + return 0; 392 + 393 + i2s->stereo_to_mono[I2S_TX_PATH] = value; 394 + 395 + return 1; 396 + } 397 + 398 + static int tegra210_i2s_cget_mono_to_stereo(struct snd_kcontrol *kcontrol, 399 + struct snd_ctl_elem_value *ucontrol) 400 + { 401 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 402 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 403 + 404 + ucontrol->value.enumerated.item[0] = i2s->mono_to_stereo[I2S_TX_PATH]; 405 + 406 + return 0; 407 + } 408 + 409 + static int tegra210_i2s_cput_mono_to_stereo(struct snd_kcontrol *kcontrol, 410 + struct snd_ctl_elem_value *ucontrol) 411 + { 412 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 413 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 414 + unsigned int value = ucontrol->value.enumerated.item[0]; 415 + 416 + if (value == i2s->mono_to_stereo[I2S_TX_PATH]) 417 + return 0; 418 + 419 + i2s->mono_to_stereo[I2S_TX_PATH] = value; 420 + 421 + return 1; 422 + } 423 + 424 + static int tegra210_i2s_pget_stereo_to_mono(struct snd_kcontrol *kcontrol, 425 + struct snd_ctl_elem_value *ucontrol) 426 + { 427 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 428 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 429 + 430 + ucontrol->value.enumerated.item[0] = i2s->stereo_to_mono[I2S_RX_PATH]; 431 + 432 + return 0; 433 + } 434 + 435 + static int tegra210_i2s_pput_stereo_to_mono(struct snd_kcontrol *kcontrol, 436 + struct snd_ctl_elem_value *ucontrol) 437 + { 438 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 439 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 440 + unsigned int value = ucontrol->value.enumerated.item[0]; 441 + 442 + if (value == i2s->stereo_to_mono[I2S_RX_PATH]) 443 + return 0; 444 + 445 + i2s->stereo_to_mono[I2S_RX_PATH] = value; 446 + 447 + return 1; 448 + } 449 + 450 + static int tegra210_i2s_pget_mono_to_stereo(struct snd_kcontrol *kcontrol, 451 + struct snd_ctl_elem_value *ucontrol) 452 + { 453 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 454 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 455 + 456 + ucontrol->value.enumerated.item[0] = i2s->mono_to_stereo[I2S_RX_PATH]; 457 + 458 + return 0; 459 + } 460 + 461 + static int tegra210_i2s_pput_mono_to_stereo(struct snd_kcontrol *kcontrol, 462 + struct snd_ctl_elem_value *ucontrol) 463 + { 464 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 465 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 466 + unsigned int value = ucontrol->value.enumerated.item[0]; 467 + 468 + if (value == i2s->mono_to_stereo[I2S_RX_PATH]) 469 + return 0; 470 + 471 + i2s->mono_to_stereo[I2S_RX_PATH] = value; 472 + 473 + return 1; 474 + } 475 + 476 + static int tegra210_i2s_pget_fifo_th(struct snd_kcontrol *kcontrol, 477 + struct snd_ctl_elem_value *ucontrol) 478 + { 479 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 480 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 481 + 482 + ucontrol->value.integer.value[0] = i2s->rx_fifo_th; 483 + 484 + return 0; 485 + } 486 + 487 + static int tegra210_i2s_pput_fifo_th(struct snd_kcontrol *kcontrol, 488 + struct snd_ctl_elem_value *ucontrol) 489 + { 490 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 491 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 492 + int value = ucontrol->value.integer.value[0]; 493 + 494 + if (value == i2s->rx_fifo_th) 495 + return 0; 496 + 497 + i2s->rx_fifo_th = value; 498 + 499 + return 1; 500 + } 501 + 502 + static int tegra210_i2s_get_bclk_ratio(struct snd_kcontrol *kcontrol, 503 + struct snd_ctl_elem_value *ucontrol) 504 + { 505 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 506 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 507 + 508 + ucontrol->value.integer.value[0] = i2s->bclk_ratio; 509 + 510 + return 0; 511 + } 512 + 513 + static int tegra210_i2s_put_bclk_ratio(struct snd_kcontrol *kcontrol, 514 + struct snd_ctl_elem_value *ucontrol) 515 + { 516 + struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 517 + struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 518 + int value = ucontrol->value.integer.value[0]; 519 + 520 + if (value == i2s->bclk_ratio) 521 + return 0; 522 + 523 + i2s->bclk_ratio = value; 524 + 525 + return 1; 526 + } 527 + 305 528 static int tegra210_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai, 306 529 unsigned int ratio) 307 530 { 308 531 struct tegra210_i2s *i2s = snd_soc_dai_get_drvdata(dai); 309 532 310 533 i2s->bclk_ratio = ratio; 311 - 312 - return 0; 313 - } 314 - 315 - static int tegra210_i2s_get_control(struct snd_kcontrol *kcontrol, 316 - struct snd_ctl_elem_value *ucontrol) 317 - { 318 - struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 319 - struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 320 - long *uctl_val = &ucontrol->value.integer.value[0]; 321 - 322 - if (strstr(kcontrol->id.name, "Loopback")) 323 - *uctl_val = i2s->loopback; 324 - else if (strstr(kcontrol->id.name, "FSYNC Width")) 325 - *uctl_val = i2s->fsync_width; 326 - else if (strstr(kcontrol->id.name, "Capture Stereo To Mono")) 327 - *uctl_val = i2s->stereo_to_mono[I2S_TX_PATH]; 328 - else if (strstr(kcontrol->id.name, "Capture Mono To Stereo")) 329 - *uctl_val = i2s->mono_to_stereo[I2S_TX_PATH]; 330 - else if (strstr(kcontrol->id.name, "Playback Stereo To Mono")) 331 - *uctl_val = i2s->stereo_to_mono[I2S_RX_PATH]; 332 - else if (strstr(kcontrol->id.name, "Playback Mono To Stereo")) 333 - *uctl_val = i2s->mono_to_stereo[I2S_RX_PATH]; 334 - else if (strstr(kcontrol->id.name, "Playback FIFO Threshold")) 335 - *uctl_val = i2s->rx_fifo_th; 336 - else if (strstr(kcontrol->id.name, "BCLK Ratio")) 337 - *uctl_val = i2s->bclk_ratio; 338 - 339 - return 0; 340 - } 341 - 342 - static int tegra210_i2s_put_control(struct snd_kcontrol *kcontrol, 343 - struct snd_ctl_elem_value *ucontrol) 344 - { 345 - struct snd_soc_component *compnt = snd_soc_kcontrol_component(kcontrol); 346 - struct tegra210_i2s *i2s = snd_soc_component_get_drvdata(compnt); 347 - int value = ucontrol->value.integer.value[0]; 348 - 349 - if (strstr(kcontrol->id.name, "Loopback")) { 350 - i2s->loopback = value; 351 - 352 - regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, 353 - I2S_CTRL_LPBK_MASK, 354 - i2s->loopback << I2S_CTRL_LPBK_SHIFT); 355 - 356 - } else if (strstr(kcontrol->id.name, "FSYNC Width")) { 357 - /* 358 - * Frame sync width is used only for FSYNC modes and not 359 - * applicable for LRCK modes. Reset value for this field is "0", 360 - * which means the width is one bit clock wide. 361 - * The width requirement may depend on the codec and in such 362 - * cases mixer control is used to update custom values. A value 363 - * of "N" here means, width is "N + 1" bit clock wide. 364 - */ 365 - i2s->fsync_width = value; 366 - 367 - regmap_update_bits(i2s->regmap, TEGRA210_I2S_CTRL, 368 - I2S_CTRL_FSYNC_WIDTH_MASK, 369 - i2s->fsync_width << I2S_FSYNC_WIDTH_SHIFT); 370 - 371 - } else if (strstr(kcontrol->id.name, "Capture Stereo To Mono")) { 372 - i2s->stereo_to_mono[I2S_TX_PATH] = value; 373 - } else if (strstr(kcontrol->id.name, "Capture Mono To Stereo")) { 374 - i2s->mono_to_stereo[I2S_TX_PATH] = value; 375 - } else if (strstr(kcontrol->id.name, "Playback Stereo To Mono")) { 376 - i2s->stereo_to_mono[I2S_RX_PATH] = value; 377 - } else if (strstr(kcontrol->id.name, "Playback Mono To Stereo")) { 378 - i2s->mono_to_stereo[I2S_RX_PATH] = value; 379 - } else if (strstr(kcontrol->id.name, "Playback FIFO Threshold")) { 380 - i2s->rx_fifo_th = value; 381 - } else if (strstr(kcontrol->id.name, "BCLK Ratio")) { 382 - i2s->bclk_ratio = value; 383 - } 384 534 385 535 return 0; 386 536 } ··· 748 598 tegra210_i2s_stereo_conv_text); 749 599 750 600 static const struct snd_kcontrol_new tegra210_i2s_controls[] = { 751 - SOC_SINGLE_EXT("Loopback", 0, 0, 1, 0, tegra210_i2s_get_control, 752 - tegra210_i2s_put_control), 753 - SOC_SINGLE_EXT("FSYNC Width", 0, 0, 255, 0, tegra210_i2s_get_control, 754 - tegra210_i2s_put_control), 601 + SOC_SINGLE_EXT("Loopback", 0, 0, 1, 0, tegra210_i2s_get_loopback, 602 + tegra210_i2s_put_loopback), 603 + SOC_SINGLE_EXT("FSYNC Width", 0, 0, 255, 0, 604 + tegra210_i2s_get_fsync_width, 605 + tegra210_i2s_put_fsync_width), 755 606 SOC_ENUM_EXT("Capture Stereo To Mono", tegra210_i2s_stereo_conv_enum, 756 - tegra210_i2s_get_control, tegra210_i2s_put_control), 607 + tegra210_i2s_cget_stereo_to_mono, 608 + tegra210_i2s_cput_stereo_to_mono), 757 609 SOC_ENUM_EXT("Capture Mono To Stereo", tegra210_i2s_mono_conv_enum, 758 - tegra210_i2s_get_control, tegra210_i2s_put_control), 610 + tegra210_i2s_cget_mono_to_stereo, 611 + tegra210_i2s_cput_mono_to_stereo), 759 612 SOC_ENUM_EXT("Playback Stereo To Mono", tegra210_i2s_stereo_conv_enum, 760 - tegra210_i2s_get_control, tegra210_i2s_put_control), 613 + tegra210_i2s_pget_mono_to_stereo, 614 + tegra210_i2s_pput_mono_to_stereo), 761 615 SOC_ENUM_EXT("Playback Mono To Stereo", tegra210_i2s_mono_conv_enum, 762 - tegra210_i2s_get_control, tegra210_i2s_put_control), 616 + tegra210_i2s_pget_stereo_to_mono, 617 + tegra210_i2s_pput_stereo_to_mono), 763 618 SOC_SINGLE_EXT("Playback FIFO Threshold", 0, 0, I2S_RX_FIFO_DEPTH - 1, 764 - 0, tegra210_i2s_get_control, tegra210_i2s_put_control), 765 - SOC_SINGLE_EXT("BCLK Ratio", 0, 0, INT_MAX, 0, tegra210_i2s_get_control, 766 - tegra210_i2s_put_control), 619 + 0, tegra210_i2s_pget_fifo_th, tegra210_i2s_pput_fifo_th), 620 + SOC_SINGLE_EXT("BCLK Ratio", 0, 0, INT_MAX, 0, 621 + tegra210_i2s_get_bclk_ratio, 622 + tegra210_i2s_put_bclk_ratio), 767 623 }; 768 624 769 625 static const struct snd_soc_dapm_widget tegra210_i2s_widgets[] = {
+19 -7
sound/soc/tegra/tegra210_mixer.c
··· 192 192 return 0; 193 193 } 194 194 195 - static int tegra210_mixer_put_gain(struct snd_kcontrol *kcontrol, 196 - struct snd_ctl_elem_value *ucontrol) 195 + static int tegra210_mixer_apply_gain(struct snd_kcontrol *kcontrol, 196 + struct snd_ctl_elem_value *ucontrol, 197 + bool instant_gain) 197 198 { 198 199 struct soc_mixer_control *mc = 199 200 (struct soc_mixer_control *)kcontrol->private_value; 200 201 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 201 202 struct tegra210_mixer *mixer = snd_soc_component_get_drvdata(cmpnt); 202 203 unsigned int reg = mc->reg, id; 203 - bool instant_gain = false; 204 204 int err; 205 - 206 - if (strstr(kcontrol->id.name, "Instant Gain Volume")) 207 - instant_gain = true; 208 205 209 206 /* Save gain value for specific MIXER input */ 210 207 id = (reg - TEGRA210_MIXER_GAIN_CFG_RAM_ADDR_0) / 211 208 TEGRA210_MIXER_GAIN_CFG_RAM_ADDR_STRIDE; 209 + 210 + if (mixer->gain_value[id] == ucontrol->value.integer.value[0]) 211 + return 0; 212 212 213 213 mixer->gain_value[id] = ucontrol->value.integer.value[0]; 214 214 ··· 219 219 } 220 220 221 221 return 1; 222 + } 223 + 224 + static int tegra210_mixer_put_gain(struct snd_kcontrol *kcontrol, 225 + struct snd_ctl_elem_value *ucontrol) 226 + { 227 + return tegra210_mixer_apply_gain(kcontrol, ucontrol, false); 228 + } 229 + 230 + static int tegra210_mixer_put_instant_gain(struct snd_kcontrol *kcontrol, 231 + struct snd_ctl_elem_value *ucontrol) 232 + { 233 + return tegra210_mixer_apply_gain(kcontrol, ucontrol, true); 222 234 } 223 235 224 236 static int tegra210_mixer_set_audio_cif(struct tegra210_mixer *mixer, ··· 400 388 SOC_SINGLE_EXT("RX" #id " Instant Gain Volume", \ 401 389 MIXER_GAIN_CFG_RAM_ADDR((id) - 1), 0, \ 402 390 0x20000, 0, tegra210_mixer_get_gain, \ 403 - tegra210_mixer_put_gain), 391 + tegra210_mixer_put_instant_gain), 404 392 405 393 /* Volume controls for all MIXER inputs */ 406 394 static const struct snd_kcontrol_new tegra210_mixer_gain_ctls[] = {
+22 -8
sound/soc/tegra/tegra210_mvc.c
··· 136 136 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 137 137 struct tegra210_mvc *mvc = snd_soc_component_get_drvdata(cmpnt); 138 138 unsigned int value; 139 - u8 mute_mask; 139 + u8 new_mask, old_mask; 140 140 int err; 141 141 142 142 pm_runtime_get_sync(cmpnt->dev); ··· 148 148 if (err < 0) 149 149 goto end; 150 150 151 - mute_mask = ucontrol->value.integer.value[0]; 151 + regmap_read(mvc->regmap, TEGRA210_MVC_CTRL, &value); 152 + 153 + old_mask = (value >> TEGRA210_MVC_MUTE_SHIFT) & TEGRA210_MUTE_MASK_EN; 154 + new_mask = ucontrol->value.integer.value[0]; 155 + 156 + if (new_mask == old_mask) { 157 + err = 0; 158 + goto end; 159 + } 152 160 153 161 err = regmap_update_bits(mvc->regmap, mc->reg, 154 162 TEGRA210_MVC_MUTE_MASK, 155 - mute_mask << TEGRA210_MVC_MUTE_SHIFT); 163 + new_mask << TEGRA210_MVC_MUTE_SHIFT); 156 164 if (err < 0) 157 165 goto end; 158 166 ··· 203 195 unsigned int reg = mc->reg; 204 196 unsigned int value; 205 197 u8 chan; 206 - int err; 198 + int err, old_volume; 207 199 208 200 pm_runtime_get_sync(cmpnt->dev); 209 201 ··· 215 207 goto end; 216 208 217 209 chan = (reg - TEGRA210_MVC_TARGET_VOL) / REG_SIZE; 210 + old_volume = mvc->volume[chan]; 218 211 219 212 tegra210_mvc_conv_vol(mvc, chan, 220 213 ucontrol->value.integer.value[0]); 214 + 215 + if (mvc->volume[chan] == old_volume) { 216 + err = 0; 217 + goto end; 218 + } 221 219 222 220 /* Configure init volume same as target volume */ 223 221 regmap_write(mvc->regmap, ··· 289 275 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 290 276 struct tegra210_mvc *mvc = snd_soc_component_get_drvdata(cmpnt); 291 277 292 - ucontrol->value.integer.value[0] = mvc->curve_type; 278 + ucontrol->value.enumerated.item[0] = mvc->curve_type; 293 279 294 280 return 0; 295 281 } ··· 299 285 { 300 286 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 301 287 struct tegra210_mvc *mvc = snd_soc_component_get_drvdata(cmpnt); 302 - int value; 288 + unsigned int value; 303 289 304 290 regmap_read(mvc->regmap, TEGRA210_MVC_ENABLE, &value); 305 291 if (value & TEGRA210_MVC_EN) { ··· 308 294 return -EINVAL; 309 295 } 310 296 311 - if (mvc->curve_type == ucontrol->value.integer.value[0]) 297 + if (mvc->curve_type == ucontrol->value.enumerated.item[0]) 312 298 return 0; 313 299 314 - mvc->curve_type = ucontrol->value.integer.value[0]; 300 + mvc->curve_type = ucontrol->value.enumerated.item[0]; 315 301 316 302 tegra210_mvc_reset_vol_settings(mvc, cmpnt->dev); 317 303
+93 -28
sound/soc/tegra/tegra210_sfc.c
··· 3244 3244 return tegra210_sfc_write_coeff_ram(cmpnt); 3245 3245 } 3246 3246 3247 - static int tegra210_sfc_get_control(struct snd_kcontrol *kcontrol, 3247 + static int tegra210_sfc_iget_stereo_to_mono(struct snd_kcontrol *kcontrol, 3248 3248 struct snd_ctl_elem_value *ucontrol) 3249 3249 { 3250 3250 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3251 3251 struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3252 3252 3253 - if (strstr(kcontrol->id.name, "Input Stereo To Mono")) 3254 - ucontrol->value.integer.value[0] = 3255 - sfc->stereo_to_mono[SFC_RX_PATH]; 3256 - else if (strstr(kcontrol->id.name, "Input Mono To Stereo")) 3257 - ucontrol->value.integer.value[0] = 3258 - sfc->mono_to_stereo[SFC_RX_PATH]; 3259 - else if (strstr(kcontrol->id.name, "Output Stereo To Mono")) 3260 - ucontrol->value.integer.value[0] = 3261 - sfc->stereo_to_mono[SFC_TX_PATH]; 3262 - else if (strstr(kcontrol->id.name, "Output Mono To Stereo")) 3263 - ucontrol->value.integer.value[0] = 3264 - sfc->mono_to_stereo[SFC_TX_PATH]; 3253 + ucontrol->value.enumerated.item[0] = sfc->stereo_to_mono[SFC_RX_PATH]; 3265 3254 3266 3255 return 0; 3267 3256 } 3268 3257 3269 - static int tegra210_sfc_put_control(struct snd_kcontrol *kcontrol, 3258 + static int tegra210_sfc_iput_stereo_to_mono(struct snd_kcontrol *kcontrol, 3270 3259 struct snd_ctl_elem_value *ucontrol) 3271 3260 { 3272 3261 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3273 3262 struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3274 - int value = ucontrol->value.integer.value[0]; 3263 + unsigned int value = ucontrol->value.enumerated.item[0]; 3275 3264 3276 - if (strstr(kcontrol->id.name, "Input Stereo To Mono")) 3277 - sfc->stereo_to_mono[SFC_RX_PATH] = value; 3278 - else if (strstr(kcontrol->id.name, "Input Mono To Stereo")) 3279 - sfc->mono_to_stereo[SFC_RX_PATH] = value; 3280 - else if (strstr(kcontrol->id.name, "Output Stereo To Mono")) 3281 - sfc->stereo_to_mono[SFC_TX_PATH] = value; 3282 - else if (strstr(kcontrol->id.name, "Output Mono To Stereo")) 3283 - sfc->mono_to_stereo[SFC_TX_PATH] = value; 3284 - else 3265 + if (value == sfc->stereo_to_mono[SFC_RX_PATH]) 3285 3266 return 0; 3267 + 3268 + sfc->stereo_to_mono[SFC_RX_PATH] = value; 3269 + 3270 + return 1; 3271 + } 3272 + 3273 + static int tegra210_sfc_iget_mono_to_stereo(struct snd_kcontrol *kcontrol, 3274 + struct snd_ctl_elem_value *ucontrol) 3275 + { 3276 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3277 + struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3278 + 3279 + ucontrol->value.enumerated.item[0] = sfc->mono_to_stereo[SFC_RX_PATH]; 3280 + 3281 + return 0; 3282 + } 3283 + 3284 + static int tegra210_sfc_iput_mono_to_stereo(struct snd_kcontrol *kcontrol, 3285 + struct snd_ctl_elem_value *ucontrol) 3286 + { 3287 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3288 + struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3289 + unsigned int value = ucontrol->value.enumerated.item[0]; 3290 + 3291 + if (value == sfc->mono_to_stereo[SFC_RX_PATH]) 3292 + return 0; 3293 + 3294 + sfc->mono_to_stereo[SFC_RX_PATH] = value; 3295 + 3296 + return 1; 3297 + } 3298 + 3299 + static int tegra210_sfc_oget_stereo_to_mono(struct snd_kcontrol *kcontrol, 3300 + struct snd_ctl_elem_value *ucontrol) 3301 + { 3302 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3303 + struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3304 + 3305 + ucontrol->value.enumerated.item[0] = sfc->stereo_to_mono[SFC_TX_PATH]; 3306 + 3307 + return 0; 3308 + } 3309 + 3310 + static int tegra210_sfc_oput_stereo_to_mono(struct snd_kcontrol *kcontrol, 3311 + struct snd_ctl_elem_value *ucontrol) 3312 + { 3313 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3314 + struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3315 + unsigned int value = ucontrol->value.enumerated.item[0]; 3316 + 3317 + if (value == sfc->stereo_to_mono[SFC_TX_PATH]) 3318 + return 0; 3319 + 3320 + sfc->stereo_to_mono[SFC_TX_PATH] = value; 3321 + 3322 + return 1; 3323 + } 3324 + 3325 + static int tegra210_sfc_oget_mono_to_stereo(struct snd_kcontrol *kcontrol, 3326 + struct snd_ctl_elem_value *ucontrol) 3327 + { 3328 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3329 + struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3330 + 3331 + ucontrol->value.enumerated.item[0] = sfc->mono_to_stereo[SFC_TX_PATH]; 3332 + 3333 + return 0; 3334 + } 3335 + 3336 + static int tegra210_sfc_oput_mono_to_stereo(struct snd_kcontrol *kcontrol, 3337 + struct snd_ctl_elem_value *ucontrol) 3338 + { 3339 + struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol); 3340 + struct tegra210_sfc *sfc = snd_soc_component_get_drvdata(cmpnt); 3341 + unsigned int value = ucontrol->value.enumerated.item[0]; 3342 + 3343 + if (value == sfc->mono_to_stereo[SFC_TX_PATH]) 3344 + return 0; 3345 + 3346 + sfc->mono_to_stereo[SFC_TX_PATH] = value; 3286 3347 3287 3348 return 1; 3288 3349 } ··· 3445 3384 3446 3385 static const struct snd_kcontrol_new tegra210_sfc_controls[] = { 3447 3386 SOC_ENUM_EXT("Input Stereo To Mono", tegra210_sfc_stereo_conv_enum, 3448 - tegra210_sfc_get_control, tegra210_sfc_put_control), 3387 + tegra210_sfc_iget_stereo_to_mono, 3388 + tegra210_sfc_iput_stereo_to_mono), 3449 3389 SOC_ENUM_EXT("Input Mono To Stereo", tegra210_sfc_mono_conv_enum, 3450 - tegra210_sfc_get_control, tegra210_sfc_put_control), 3390 + tegra210_sfc_iget_mono_to_stereo, 3391 + tegra210_sfc_iput_mono_to_stereo), 3451 3392 SOC_ENUM_EXT("Output Stereo To Mono", tegra210_sfc_stereo_conv_enum, 3452 - tegra210_sfc_get_control, tegra210_sfc_put_control), 3393 + tegra210_sfc_oget_stereo_to_mono, 3394 + tegra210_sfc_oput_stereo_to_mono), 3453 3395 SOC_ENUM_EXT("Output Mono To Stereo", tegra210_sfc_mono_conv_enum, 3454 - tegra210_sfc_get_control, tegra210_sfc_put_control), 3396 + tegra210_sfc_oget_mono_to_stereo, 3397 + tegra210_sfc_oput_mono_to_stereo), 3455 3398 }; 3456 3399 3457 3400 static const struct snd_soc_component_driver tegra210_sfc_cmpnt = {
+1 -21
tools/include/linux/kernel.h
··· 7 7 #include <assert.h> 8 8 #include <linux/build_bug.h> 9 9 #include <linux/compiler.h> 10 + #include <linux/math.h> 10 11 #include <endian.h> 11 12 #include <byteswap.h> 12 13 13 14 #ifndef UINT_MAX 14 15 #define UINT_MAX (~0U) 15 16 #endif 16 - 17 - #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 18 17 19 18 #define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1) 20 19 #define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) ··· 49 50 typeof(y) _min2 = (y); \ 50 51 (void) (&_min1 == &_min2); \ 51 52 _min1 < _min2 ? _min1 : _min2; }) 52 - #endif 53 - 54 - #ifndef roundup 55 - #define roundup(x, y) ( \ 56 - { \ 57 - const typeof(y) __y = y; \ 58 - (((x) + (__y - 1)) / __y) * __y; \ 59 - } \ 60 - ) 61 53 #endif 62 54 63 55 #ifndef BUG_ON ··· 93 103 int scnprintf_pad(char * buf, size_t size, const char * fmt, ...); 94 104 95 105 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) 96 - 97 - /* 98 - * This looks more complex than it should be. But we need to 99 - * get the type for the ~ right in round_down (it needs to be 100 - * as wide as the result!), and we want to evaluate the macro 101 - * arguments just once each. 102 - */ 103 - #define __round_mask(x, y) ((__typeof__(x))((y)-1)) 104 - #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 105 - #define round_down(x, y) ((x) & ~__round_mask(x, y)) 106 106 107 107 #define current_gfp_context(k) 0 108 108 #define synchronize_rcu()
+25
tools/include/linux/math.h
··· 1 + #ifndef _TOOLS_MATH_H 2 + #define _TOOLS_MATH_H 3 + 4 + /* 5 + * This looks more complex than it should be. But we need to 6 + * get the type for the ~ right in round_down (it needs to be 7 + * as wide as the result!), and we want to evaluate the macro 8 + * arguments just once each. 9 + */ 10 + #define __round_mask(x, y) ((__typeof__(x))((y)-1)) 11 + #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 12 + #define round_down(x, y) ((x) & ~__round_mask(x, y)) 13 + 14 + #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 15 + 16 + #ifndef roundup 17 + #define roundup(x, y) ( \ 18 + { \ 19 + const typeof(y) __y = y; \ 20 + (((x) + (__y - 1)) / __y) * __y; \ 21 + } \ 22 + ) 23 + #endif 24 + 25 + #endif
+3
tools/testing/radix-tree/linux/lockdep.h
··· 1 1 #ifndef _LINUX_LOCKDEP_H 2 2 #define _LINUX_LOCKDEP_H 3 + 4 + #include <linux/spinlock.h> 5 + 3 6 struct lock_class_key { 4 7 unsigned int a; 5 8 };
+30
tools/testing/selftests/kvm/kvm_create_max_vcpus.c
··· 12 12 #include <stdio.h> 13 13 #include <stdlib.h> 14 14 #include <string.h> 15 + #include <sys/resource.h> 15 16 16 17 #include "test_util.h" 17 18 ··· 41 40 { 42 41 int kvm_max_vcpu_id = kvm_check_cap(KVM_CAP_MAX_VCPU_ID); 43 42 int kvm_max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS); 43 + /* 44 + * Number of file descriptors reqired, KVM_CAP_MAX_VCPUS for vCPU fds + 45 + * an arbitrary number for everything else. 46 + */ 47 + int nr_fds_wanted = kvm_max_vcpus + 100; 48 + struct rlimit rl; 44 49 45 50 pr_info("KVM_CAP_MAX_VCPU_ID: %d\n", kvm_max_vcpu_id); 46 51 pr_info("KVM_CAP_MAX_VCPUS: %d\n", kvm_max_vcpus); 52 + 53 + /* 54 + * Check that we're allowed to open nr_fds_wanted file descriptors and 55 + * try raising the limits if needed. 56 + */ 57 + TEST_ASSERT(!getrlimit(RLIMIT_NOFILE, &rl), "getrlimit() failed!"); 58 + 59 + if (rl.rlim_cur < nr_fds_wanted) { 60 + rl.rlim_cur = nr_fds_wanted; 61 + if (rl.rlim_max < nr_fds_wanted) { 62 + int old_rlim_max = rl.rlim_max; 63 + rl.rlim_max = nr_fds_wanted; 64 + 65 + int r = setrlimit(RLIMIT_NOFILE, &rl); 66 + if (r < 0) { 67 + printf("RLIMIT_NOFILE hard limit is too low (%d, wanted %d)\n", 68 + old_rlim_max, nr_fds_wanted); 69 + exit(KSFT_SKIP); 70 + } 71 + } else { 72 + TEST_ASSERT(!setrlimit(RLIMIT_NOFILE, &rl), "setrlimit() failed!"); 73 + } 74 + } 47 75 48 76 /* 49 77 * Upstream KVM prior to 4.8 does not support KVM_CAP_MAX_VCPU_ID.
+1 -1
tools/testing/selftests/kvm/kvm_page_table_test.c
··· 280 280 #ifdef __s390x__ 281 281 alignment = max(0x100000, alignment); 282 282 #endif 283 - guest_test_phys_mem = align_down(guest_test_virt_mem, alignment); 283 + guest_test_phys_mem = align_down(guest_test_phys_mem, alignment); 284 284 285 285 /* Set up the shared data structure test_args */ 286 286 test_args.vm = vm;
+71 -69
tools/testing/selftests/kvm/x86_64/hyperv_features.c
··· 165 165 vcpu_set_cpuid(vm, VCPU_ID, cpuid); 166 166 } 167 167 168 - static void guest_test_msrs_access(struct kvm_vm *vm, struct msr_data *msr, 169 - struct kvm_cpuid2 *best) 168 + static void guest_test_msrs_access(void) 170 169 { 171 170 struct kvm_run *run; 171 + struct kvm_vm *vm; 172 172 struct ucall uc; 173 173 int stage = 0, r; 174 174 struct kvm_cpuid_entry2 feat = { ··· 180 180 struct kvm_cpuid_entry2 dbg = { 181 181 .function = HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 182 182 }; 183 - struct kvm_enable_cap cap = {0}; 184 - 185 - run = vcpu_state(vm, VCPU_ID); 183 + struct kvm_cpuid2 *best; 184 + vm_vaddr_t msr_gva; 185 + struct kvm_enable_cap cap = { 186 + .cap = KVM_CAP_HYPERV_ENFORCE_CPUID, 187 + .args = {1} 188 + }; 189 + struct msr_data *msr; 186 190 187 191 while (true) { 192 + vm = vm_create_default(VCPU_ID, 0, guest_msr); 193 + 194 + msr_gva = vm_vaddr_alloc_page(vm); 195 + memset(addr_gva2hva(vm, msr_gva), 0x0, getpagesize()); 196 + msr = addr_gva2hva(vm, msr_gva); 197 + 198 + vcpu_args_set(vm, VCPU_ID, 1, msr_gva); 199 + vcpu_enable_cap(vm, VCPU_ID, &cap); 200 + 201 + vcpu_set_hv_cpuid(vm, VCPU_ID); 202 + 203 + best = kvm_get_supported_hv_cpuid(); 204 + 205 + vm_init_descriptor_tables(vm); 206 + vcpu_init_descriptor_tables(vm, VCPU_ID); 207 + vm_install_exception_handler(vm, GP_VECTOR, guest_gp_handler); 208 + 209 + run = vcpu_state(vm, VCPU_ID); 210 + 188 211 switch (stage) { 189 212 case 0: 190 213 /* ··· 338 315 * capability enabled and guest visible CPUID bit unset. 339 316 */ 340 317 cap.cap = KVM_CAP_HYPERV_SYNIC2; 318 + cap.args[0] = 0; 341 319 vcpu_enable_cap(vm, VCPU_ID, &cap); 342 320 break; 343 321 case 22: ··· 485 461 486 462 switch (get_ucall(vm, VCPU_ID, &uc)) { 487 463 case UCALL_SYNC: 488 - TEST_ASSERT(uc.args[1] == stage, 489 - "Unexpected stage: %ld (%d expected)\n", 490 - uc.args[1], stage); 464 + TEST_ASSERT(uc.args[1] == 0, 465 + "Unexpected stage: %ld (0 expected)\n", 466 + uc.args[1]); 491 467 break; 492 468 case UCALL_ABORT: 493 469 TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0], ··· 498 474 } 499 475 500 476 stage++; 477 + kvm_vm_free(vm); 501 478 } 502 479 } 503 480 504 - static void guest_test_hcalls_access(struct kvm_vm *vm, struct hcall_data *hcall, 505 - void *input, void *output, struct kvm_cpuid2 *best) 481 + static void guest_test_hcalls_access(void) 506 482 { 507 483 struct kvm_run *run; 484 + struct kvm_vm *vm; 508 485 struct ucall uc; 509 486 int stage = 0, r; 510 487 struct kvm_cpuid_entry2 feat = { ··· 518 493 struct kvm_cpuid_entry2 dbg = { 519 494 .function = HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 520 495 }; 521 - 522 - run = vcpu_state(vm, VCPU_ID); 496 + struct kvm_enable_cap cap = { 497 + .cap = KVM_CAP_HYPERV_ENFORCE_CPUID, 498 + .args = {1} 499 + }; 500 + vm_vaddr_t hcall_page, hcall_params; 501 + struct hcall_data *hcall; 502 + struct kvm_cpuid2 *best; 523 503 524 504 while (true) { 505 + vm = vm_create_default(VCPU_ID, 0, guest_hcall); 506 + 507 + vm_init_descriptor_tables(vm); 508 + vcpu_init_descriptor_tables(vm, VCPU_ID); 509 + vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler); 510 + 511 + /* Hypercall input/output */ 512 + hcall_page = vm_vaddr_alloc_pages(vm, 2); 513 + hcall = addr_gva2hva(vm, hcall_page); 514 + memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize()); 515 + 516 + hcall_params = vm_vaddr_alloc_page(vm); 517 + memset(addr_gva2hva(vm, hcall_params), 0x0, getpagesize()); 518 + 519 + vcpu_args_set(vm, VCPU_ID, 2, addr_gva2gpa(vm, hcall_page), hcall_params); 520 + vcpu_enable_cap(vm, VCPU_ID, &cap); 521 + 522 + vcpu_set_hv_cpuid(vm, VCPU_ID); 523 + 524 + best = kvm_get_supported_hv_cpuid(); 525 + 526 + run = vcpu_state(vm, VCPU_ID); 527 + 525 528 switch (stage) { 526 529 case 0: 527 530 hcall->control = 0xdeadbeef; ··· 659 606 660 607 switch (get_ucall(vm, VCPU_ID, &uc)) { 661 608 case UCALL_SYNC: 662 - TEST_ASSERT(uc.args[1] == stage, 663 - "Unexpected stage: %ld (%d expected)\n", 664 - uc.args[1], stage); 609 + TEST_ASSERT(uc.args[1] == 0, 610 + "Unexpected stage: %ld (0 expected)\n", 611 + uc.args[1]); 665 612 break; 666 613 case UCALL_ABORT: 667 614 TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0], ··· 672 619 } 673 620 674 621 stage++; 622 + kvm_vm_free(vm); 675 623 } 676 624 } 677 625 678 626 int main(void) 679 627 { 680 - struct kvm_cpuid2 *best; 681 - struct kvm_vm *vm; 682 - vm_vaddr_t msr_gva, hcall_page, hcall_params; 683 - struct kvm_enable_cap cap = { 684 - .cap = KVM_CAP_HYPERV_ENFORCE_CPUID, 685 - .args = {1} 686 - }; 687 - 688 - /* Test MSRs */ 689 - vm = vm_create_default(VCPU_ID, 0, guest_msr); 690 - 691 - msr_gva = vm_vaddr_alloc_page(vm); 692 - memset(addr_gva2hva(vm, msr_gva), 0x0, getpagesize()); 693 - vcpu_args_set(vm, VCPU_ID, 1, msr_gva); 694 - vcpu_enable_cap(vm, VCPU_ID, &cap); 695 - 696 - vcpu_set_hv_cpuid(vm, VCPU_ID); 697 - 698 - best = kvm_get_supported_hv_cpuid(); 699 - 700 - vm_init_descriptor_tables(vm); 701 - vcpu_init_descriptor_tables(vm, VCPU_ID); 702 - vm_install_exception_handler(vm, GP_VECTOR, guest_gp_handler); 703 - 704 628 pr_info("Testing access to Hyper-V specific MSRs\n"); 705 - guest_test_msrs_access(vm, addr_gva2hva(vm, msr_gva), 706 - best); 707 - kvm_vm_free(vm); 708 - 709 - /* Test hypercalls */ 710 - vm = vm_create_default(VCPU_ID, 0, guest_hcall); 711 - 712 - vm_init_descriptor_tables(vm); 713 - vcpu_init_descriptor_tables(vm, VCPU_ID); 714 - vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler); 715 - 716 - /* Hypercall input/output */ 717 - hcall_page = vm_vaddr_alloc_pages(vm, 2); 718 - memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize()); 719 - 720 - hcall_params = vm_vaddr_alloc_page(vm); 721 - memset(addr_gva2hva(vm, hcall_params), 0x0, getpagesize()); 722 - 723 - vcpu_args_set(vm, VCPU_ID, 2, addr_gva2gpa(vm, hcall_page), hcall_params); 724 - vcpu_enable_cap(vm, VCPU_ID, &cap); 725 - 726 - vcpu_set_hv_cpuid(vm, VCPU_ID); 727 - 728 - best = kvm_get_supported_hv_cpuid(); 629 + guest_test_msrs_access(); 729 630 730 631 pr_info("Testing access to Hyper-V hypercalls\n"); 731 - guest_test_hcalls_access(vm, addr_gva2hva(vm, hcall_params), 732 - addr_gva2hva(vm, hcall_page), 733 - addr_gva2hva(vm, hcall_page) + getpagesize(), 734 - best); 735 - 736 - kvm_vm_free(vm); 632 + guest_test_hcalls_access(); 737 633 }
+155 -10
tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
··· 54 54 return vm; 55 55 } 56 56 57 - static struct kvm_vm *__vm_create(void) 57 + static struct kvm_vm *aux_vm_create(bool with_vcpus) 58 58 { 59 59 struct kvm_vm *vm; 60 60 int i; 61 61 62 62 vm = vm_create(VM_MODE_DEFAULT, 0, O_RDWR); 63 + if (!with_vcpus) 64 + return vm; 65 + 63 66 for (i = 0; i < NR_MIGRATE_TEST_VCPUS; ++i) 64 67 vm_vcpu_add(vm, i); 65 68 ··· 92 89 { 93 90 struct kvm_vm *src_vm; 94 91 struct kvm_vm *dst_vms[NR_MIGRATE_TEST_VMS]; 95 - int i; 92 + int i, ret; 96 93 97 94 src_vm = sev_vm_create(es); 98 95 for (i = 0; i < NR_MIGRATE_TEST_VMS; ++i) 99 - dst_vms[i] = __vm_create(); 96 + dst_vms[i] = aux_vm_create(true); 100 97 101 98 /* Initial migration from the src to the first dst. */ 102 99 sev_migrate_from(dst_vms[0]->fd, src_vm->fd); ··· 105 102 sev_migrate_from(dst_vms[i]->fd, dst_vms[i - 1]->fd); 106 103 107 104 /* Migrate the guest back to the original VM. */ 108 - sev_migrate_from(src_vm->fd, dst_vms[NR_MIGRATE_TEST_VMS - 1]->fd); 105 + ret = __sev_migrate_from(src_vm->fd, dst_vms[NR_MIGRATE_TEST_VMS - 1]->fd); 106 + TEST_ASSERT(ret == -1 && errno == EIO, 107 + "VM that was migrated from should be dead. ret %d, errno: %d\n", ret, 108 + errno); 109 109 110 110 kvm_vm_free(src_vm); 111 111 for (i = 0; i < NR_MIGRATE_TEST_VMS; ++i) ··· 152 146 153 147 for (i = 0; i < NR_LOCK_TESTING_THREADS; ++i) 154 148 pthread_join(pt[i], NULL); 149 + for (i = 0; i < NR_LOCK_TESTING_THREADS; ++i) 150 + kvm_vm_free(input[i].vm); 155 151 } 156 152 157 153 static void test_sev_migrate_parameters(void) ··· 165 157 sev_vm = sev_vm_create(/* es= */ false); 166 158 sev_es_vm = sev_vm_create(/* es= */ true); 167 159 vm_no_vcpu = vm_create(VM_MODE_DEFAULT, 0, O_RDWR); 168 - vm_no_sev = __vm_create(); 160 + vm_no_sev = aux_vm_create(true); 169 161 sev_es_vm_no_vmsa = vm_create(VM_MODE_DEFAULT, 0, O_RDWR); 170 162 sev_ioctl(sev_es_vm_no_vmsa->fd, KVM_SEV_ES_INIT, NULL); 171 163 vm_vcpu_add(sev_es_vm_no_vmsa, 1); 172 - 173 164 174 165 ret = __sev_migrate_from(sev_vm->fd, sev_es_vm->fd); 175 166 TEST_ASSERT( ··· 198 191 TEST_ASSERT(ret == -1 && errno == EINVAL, 199 192 "Migrations require SEV enabled. ret %d, errno: %d\n", ret, 200 193 errno); 194 + 195 + kvm_vm_free(sev_vm); 196 + kvm_vm_free(sev_es_vm); 197 + kvm_vm_free(sev_es_vm_no_vmsa); 198 + kvm_vm_free(vm_no_vcpu); 199 + kvm_vm_free(vm_no_sev); 200 + } 201 + 202 + static int __sev_mirror_create(int dst_fd, int src_fd) 203 + { 204 + struct kvm_enable_cap cap = { 205 + .cap = KVM_CAP_VM_COPY_ENC_CONTEXT_FROM, 206 + .args = { src_fd } 207 + }; 208 + 209 + return ioctl(dst_fd, KVM_ENABLE_CAP, &cap); 210 + } 211 + 212 + 213 + static void sev_mirror_create(int dst_fd, int src_fd) 214 + { 215 + int ret; 216 + 217 + ret = __sev_mirror_create(dst_fd, src_fd); 218 + TEST_ASSERT(!ret, "Copying context failed, ret: %d, errno: %d\n", ret, errno); 219 + } 220 + 221 + static void test_sev_mirror(bool es) 222 + { 223 + struct kvm_vm *src_vm, *dst_vm; 224 + struct kvm_sev_launch_start start = { 225 + .policy = es ? SEV_POLICY_ES : 0 226 + }; 227 + int i; 228 + 229 + src_vm = sev_vm_create(es); 230 + dst_vm = aux_vm_create(false); 231 + 232 + sev_mirror_create(dst_vm->fd, src_vm->fd); 233 + 234 + /* Check that we can complete creation of the mirror VM. */ 235 + for (i = 0; i < NR_MIGRATE_TEST_VCPUS; ++i) 236 + vm_vcpu_add(dst_vm, i); 237 + sev_ioctl(dst_vm->fd, KVM_SEV_LAUNCH_START, &start); 238 + if (es) 239 + sev_ioctl(dst_vm->fd, KVM_SEV_LAUNCH_UPDATE_VMSA, NULL); 240 + 241 + kvm_vm_free(src_vm); 242 + kvm_vm_free(dst_vm); 243 + } 244 + 245 + static void test_sev_mirror_parameters(void) 246 + { 247 + struct kvm_vm *sev_vm, *sev_es_vm, *vm_no_vcpu, *vm_with_vcpu; 248 + int ret; 249 + 250 + sev_vm = sev_vm_create(/* es= */ false); 251 + sev_es_vm = sev_vm_create(/* es= */ true); 252 + vm_with_vcpu = aux_vm_create(true); 253 + vm_no_vcpu = aux_vm_create(false); 254 + 255 + ret = __sev_mirror_create(sev_vm->fd, sev_vm->fd); 256 + TEST_ASSERT( 257 + ret == -1 && errno == EINVAL, 258 + "Should not be able copy context to self. ret: %d, errno: %d\n", 259 + ret, errno); 260 + 261 + ret = __sev_mirror_create(sev_vm->fd, sev_es_vm->fd); 262 + TEST_ASSERT( 263 + ret == -1 && errno == EINVAL, 264 + "Should not be able copy context to SEV enabled VM. ret: %d, errno: %d\n", 265 + ret, errno); 266 + 267 + ret = __sev_mirror_create(sev_es_vm->fd, sev_vm->fd); 268 + TEST_ASSERT( 269 + ret == -1 && errno == EINVAL, 270 + "Should not be able copy context to SEV-ES enabled VM. ret: %d, errno: %d\n", 271 + ret, errno); 272 + 273 + ret = __sev_mirror_create(vm_no_vcpu->fd, vm_with_vcpu->fd); 274 + TEST_ASSERT(ret == -1 && errno == EINVAL, 275 + "Copy context requires SEV enabled. ret %d, errno: %d\n", ret, 276 + errno); 277 + 278 + ret = __sev_mirror_create(vm_with_vcpu->fd, sev_vm->fd); 279 + TEST_ASSERT( 280 + ret == -1 && errno == EINVAL, 281 + "SEV copy context requires no vCPUS on the destination. ret: %d, errno: %d\n", 282 + ret, errno); 283 + 284 + kvm_vm_free(sev_vm); 285 + kvm_vm_free(sev_es_vm); 286 + kvm_vm_free(vm_with_vcpu); 287 + kvm_vm_free(vm_no_vcpu); 288 + } 289 + 290 + static void test_sev_move_copy(void) 291 + { 292 + struct kvm_vm *dst_vm, *sev_vm, *mirror_vm, *dst_mirror_vm; 293 + int ret; 294 + 295 + sev_vm = sev_vm_create(/* es= */ false); 296 + dst_vm = aux_vm_create(true); 297 + mirror_vm = aux_vm_create(false); 298 + dst_mirror_vm = aux_vm_create(false); 299 + 300 + sev_mirror_create(mirror_vm->fd, sev_vm->fd); 301 + ret = __sev_migrate_from(dst_vm->fd, sev_vm->fd); 302 + TEST_ASSERT(ret == -1 && errno == EBUSY, 303 + "Cannot migrate VM that has mirrors. ret %d, errno: %d\n", ret, 304 + errno); 305 + 306 + /* The mirror itself can be migrated. */ 307 + sev_migrate_from(dst_mirror_vm->fd, mirror_vm->fd); 308 + ret = __sev_migrate_from(dst_vm->fd, sev_vm->fd); 309 + TEST_ASSERT(ret == -1 && errno == EBUSY, 310 + "Cannot migrate VM that has mirrors. ret %d, errno: %d\n", ret, 311 + errno); 312 + 313 + /* 314 + * mirror_vm is not a mirror anymore, dst_mirror_vm is. Thus, 315 + * the owner can be copied as soon as dst_mirror_vm is gone. 316 + */ 317 + kvm_vm_free(dst_mirror_vm); 318 + sev_migrate_from(dst_vm->fd, sev_vm->fd); 319 + 320 + kvm_vm_free(mirror_vm); 321 + kvm_vm_free(dst_vm); 322 + kvm_vm_free(sev_vm); 201 323 } 202 324 203 325 int main(int argc, char *argv[]) 204 326 { 205 - test_sev_migrate_from(/* es= */ false); 206 - test_sev_migrate_from(/* es= */ true); 207 - test_sev_migrate_locking(); 208 - test_sev_migrate_parameters(); 327 + if (kvm_check_cap(KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM)) { 328 + test_sev_migrate_from(/* es= */ false); 329 + test_sev_migrate_from(/* es= */ true); 330 + test_sev_migrate_locking(); 331 + test_sev_migrate_parameters(); 332 + if (kvm_check_cap(KVM_CAP_VM_COPY_ENC_CONTEXT_FROM)) 333 + test_sev_move_copy(); 334 + } 335 + if (kvm_check_cap(KVM_CAP_VM_COPY_ENC_CONTEXT_FROM)) { 336 + test_sev_mirror(/* es= */ false); 337 + test_sev_mirror(/* es= */ true); 338 + test_sev_mirror_parameters(); 339 + } 209 340 return 0; 210 341 }
+2 -2
tools/testing/selftests/net/fcnal-test.sh
··· 4042 4042 ################################################################################ 4043 4043 # main 4044 4044 4045 - TESTS_IPV4="ipv4_ping ipv4_tcp ipv4_udp ipv4_addr_bind ipv4_runtime ipv4_netfilter" 4046 - TESTS_IPV6="ipv6_ping ipv6_tcp ipv6_udp ipv6_addr_bind ipv6_runtime ipv6_netfilter" 4045 + TESTS_IPV4="ipv4_ping ipv4_tcp ipv4_udp ipv4_bind ipv4_runtime ipv4_netfilter" 4046 + TESTS_IPV6="ipv6_ping ipv6_tcp ipv6_udp ipv6_bind ipv6_runtime ipv6_netfilter" 4047 4047 TESTS_OTHER="use_cases" 4048 4048 4049 4049 PAUSE_ON_FAIL=no
+28 -2
tools/testing/selftests/wireguard/netns.sh
··· 276 276 n1 wg set wg0 peer "$pub2" endpoint 192.168.241.2:7 277 277 ip2 link del wg0 278 278 ip2 link del wg1 279 - ! n0 ping -W 1 -c 10 -f 192.168.241.2 || false # Should not crash kernel 279 + read _ _ tx_bytes_before < <(n0 wg show wg1 transfer) 280 + ! n0 ping -W 1 -c 10 -f 192.168.241.2 || false 281 + sleep 1 282 + read _ _ tx_bytes_after < <(n0 wg show wg1 transfer) 283 + (( tx_bytes_after - tx_bytes_before < 70000 )) 280 284 281 285 ip0 link del wg1 282 286 ip1 link del wg0 ··· 613 609 kill $ncat_pid 614 610 ip0 link del wg0 615 611 612 + # Ensure that dst_cache references don't outlive netns lifetime 613 + ip1 link add dev wg0 type wireguard 614 + ip2 link add dev wg0 type wireguard 615 + configure_peers 616 + ip1 link add veth1 type veth peer name veth2 617 + ip1 link set veth2 netns $netns2 618 + ip1 addr add fd00:aa::1/64 dev veth1 619 + ip2 addr add fd00:aa::2/64 dev veth2 620 + ip1 link set veth1 up 621 + ip2 link set veth2 up 622 + waitiface $netns1 veth1 623 + waitiface $netns2 veth2 624 + ip1 -6 route add default dev veth1 via fd00:aa::2 625 + ip2 -6 route add default dev veth2 via fd00:aa::1 626 + n1 wg set wg0 peer "$pub2" endpoint [fd00:aa::2]:2 627 + n2 wg set wg0 peer "$pub1" endpoint [fd00:aa::1]:1 628 + n1 ping6 -c 1 fd00::2 629 + pp ip netns delete $netns1 630 + pp ip netns delete $netns2 631 + pp ip netns add $netns1 632 + pp ip netns add $netns2 633 + 616 634 # Ensure there aren't circular reference loops 617 635 ip1 link add wg1 type wireguard 618 636 ip2 link add wg2 type wireguard ··· 653 627 done < /dev/kmsg 654 628 alldeleted=1 655 629 for object in "${!objects[@]}"; do 656 - if [[ ${objects["$object"]} != *createddestroyed ]]; then 630 + if [[ ${objects["$object"]} != *createddestroyed && ${objects["$object"]} != *createdcreateddestroyeddestroyed ]]; then 657 631 echo "Error: $object: merely ${objects["$object"]}" >&3 658 632 alldeleted=0 659 633 fi
+1 -1
tools/testing/selftests/wireguard/qemu/debug.config
··· 47 47 CONFIG_TRACE_IRQFLAGS=y 48 48 CONFIG_DEBUG_BUGVERBOSE=y 49 49 CONFIG_DEBUG_LIST=y 50 - CONFIG_DEBUG_PI_LIST=y 50 + CONFIG_DEBUG_PLIST=y 51 51 CONFIG_PROVE_RCU=y 52 52 CONFIG_SPARSE_RCU_POINTER=y 53 53 CONFIG_RCU_CPU_STALL_TIMEOUT=21
+1
tools/testing/selftests/wireguard/qemu/kernel.config
··· 66 66 CONFIG_SYSFS=y 67 67 CONFIG_TMPFS=y 68 68 CONFIG_CONSOLE_LOGLEVEL_DEFAULT=15 69 + CONFIG_LOG_BUF_SHIFT=18 69 70 CONFIG_PRINTK_TIME=y 70 71 CONFIG_BLK_DEV_INITRD=y 71 72 CONFIG_LEGACY_VSYSCALL_NONE=y
+37 -19
virt/kvm/kvm_main.c
··· 1531 1531 1532 1532 static int kvm_set_memslot(struct kvm *kvm, 1533 1533 const struct kvm_userspace_memory_region *mem, 1534 - struct kvm_memory_slot *old, 1535 1534 struct kvm_memory_slot *new, int as_id, 1536 1535 enum kvm_mr_change change) 1537 1536 { 1538 - struct kvm_memory_slot *slot; 1537 + struct kvm_memory_slot *slot, old; 1539 1538 struct kvm_memslots *slots; 1540 1539 int r; 1541 1540 ··· 1565 1566 * Note, the INVALID flag needs to be in the appropriate entry 1566 1567 * in the freshly allocated memslots, not in @old or @new. 1567 1568 */ 1568 - slot = id_to_memslot(slots, old->id); 1569 + slot = id_to_memslot(slots, new->id); 1569 1570 slot->flags |= KVM_MEMSLOT_INVALID; 1570 1571 1571 1572 /* ··· 1596 1597 kvm_copy_memslots(slots, __kvm_memslots(kvm, as_id)); 1597 1598 } 1598 1599 1600 + /* 1601 + * Make a full copy of the old memslot, the pointer will become stale 1602 + * when the memslots are re-sorted by update_memslots(), and the old 1603 + * memslot needs to be referenced after calling update_memslots(), e.g. 1604 + * to free its resources and for arch specific behavior. This needs to 1605 + * happen *after* (re)acquiring slots_arch_lock. 1606 + */ 1607 + slot = id_to_memslot(slots, new->id); 1608 + if (slot) { 1609 + old = *slot; 1610 + } else { 1611 + WARN_ON_ONCE(change != KVM_MR_CREATE); 1612 + memset(&old, 0, sizeof(old)); 1613 + old.id = new->id; 1614 + old.as_id = as_id; 1615 + } 1616 + 1617 + /* Copy the arch-specific data, again after (re)acquiring slots_arch_lock. */ 1618 + memcpy(&new->arch, &old.arch, sizeof(old.arch)); 1619 + 1599 1620 r = kvm_arch_prepare_memory_region(kvm, new, mem, change); 1600 1621 if (r) 1601 1622 goto out_slots; ··· 1623 1604 update_memslots(slots, new, change); 1624 1605 slots = install_new_memslots(kvm, as_id, slots); 1625 1606 1626 - kvm_arch_commit_memory_region(kvm, mem, old, new, change); 1607 + kvm_arch_commit_memory_region(kvm, mem, &old, new, change); 1608 + 1609 + /* Free the old memslot's metadata. Note, this is the full copy!!! */ 1610 + if (change == KVM_MR_DELETE) 1611 + kvm_free_memslot(kvm, &old); 1627 1612 1628 1613 kvfree(slots); 1629 1614 return 0; 1630 1615 1631 1616 out_slots: 1632 1617 if (change == KVM_MR_DELETE || change == KVM_MR_MOVE) { 1633 - slot = id_to_memslot(slots, old->id); 1618 + slot = id_to_memslot(slots, new->id); 1634 1619 slot->flags &= ~KVM_MEMSLOT_INVALID; 1635 1620 slots = install_new_memslots(kvm, as_id, slots); 1636 1621 } else { ··· 1649 1626 struct kvm_memory_slot *old, int as_id) 1650 1627 { 1651 1628 struct kvm_memory_slot new; 1652 - int r; 1653 1629 1654 1630 if (!old->npages) 1655 1631 return -EINVAL; ··· 1661 1639 */ 1662 1640 new.as_id = as_id; 1663 1641 1664 - r = kvm_set_memslot(kvm, mem, old, &new, as_id, KVM_MR_DELETE); 1665 - if (r) 1666 - return r; 1667 - 1668 - kvm_free_memslot(kvm, old); 1669 - return 0; 1642 + return kvm_set_memslot(kvm, mem, &new, as_id, KVM_MR_DELETE); 1670 1643 } 1671 1644 1672 1645 /* ··· 1689 1672 id = (u16)mem->slot; 1690 1673 1691 1674 /* General sanity checks */ 1692 - if (mem->memory_size & (PAGE_SIZE - 1)) 1675 + if ((mem->memory_size & (PAGE_SIZE - 1)) || 1676 + (mem->memory_size != (unsigned long)mem->memory_size)) 1693 1677 return -EINVAL; 1694 1678 if (mem->guest_phys_addr & (PAGE_SIZE - 1)) 1695 1679 return -EINVAL; ··· 1736 1718 if (!old.npages) { 1737 1719 change = KVM_MR_CREATE; 1738 1720 new.dirty_bitmap = NULL; 1739 - memset(&new.arch, 0, sizeof(new.arch)); 1740 1721 } else { /* Modify an existing slot. */ 1741 1722 if ((new.userspace_addr != old.userspace_addr) || 1742 1723 (new.npages != old.npages) || ··· 1749 1732 else /* Nothing to change. */ 1750 1733 return 0; 1751 1734 1752 - /* Copy dirty_bitmap and arch from the current memslot. */ 1735 + /* Copy dirty_bitmap from the current memslot. */ 1753 1736 new.dirty_bitmap = old.dirty_bitmap; 1754 - memcpy(&new.arch, &old.arch, sizeof(new.arch)); 1755 1737 } 1756 1738 1757 1739 if ((change == KVM_MR_CREATE) || (change == KVM_MR_MOVE)) { ··· 1776 1760 bitmap_set(new.dirty_bitmap, 0, new.npages); 1777 1761 } 1778 1762 1779 - r = kvm_set_memslot(kvm, mem, &old, &new, as_id, change); 1763 + r = kvm_set_memslot(kvm, mem, &new, as_id, change); 1780 1764 if (r) 1781 1765 goto out_bitmap; 1782 1766 ··· 2931 2915 int r; 2932 2916 gpa_t gpa = ghc->gpa + offset; 2933 2917 2934 - BUG_ON(len + offset > ghc->len); 2918 + if (WARN_ON_ONCE(len + offset > ghc->len)) 2919 + return -EINVAL; 2935 2920 2936 2921 if (slots->generation != ghc->generation) { 2937 2922 if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len)) ··· 2969 2952 int r; 2970 2953 gpa_t gpa = ghc->gpa + offset; 2971 2954 2972 - BUG_ON(len + offset > ghc->len); 2955 + if (WARN_ON_ONCE(len + offset > ghc->len)) 2956 + return -EINVAL; 2973 2957 2974 2958 if (slots->generation != ghc->generation) { 2975 2959 if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len))