···376376Julien Thierry <julien.thierry.kdev@gmail.com> <julien.thierry@arm.com>377377Iskren Chernev <me@iskren.info> <iskren.chernev@gmail.com>378378Kalle Valo <kvalo@kernel.org> <kvalo@codeaurora.org>379379+Kalle Valo <kvalo@kernel.org> <quic_kvalo@quicinc.com>379380Kalyan Thota <quic_kalyant@quicinc.com> <kalyan_t@codeaurora.org>380381Karthikeyan Periyasamy <quic_periyasa@quicinc.com> <periyasa@codeaurora.org>381382Kathiravan T <quic_kathirav@quicinc.com> <kathirav@codeaurora.org>
+2-4
CREDITS
···25152515D: Initial implementation of VC's, pty's and select()2516251625172517N: Pavel Machek25182518-E: pavel@ucw.cz25182518+E: pavel@kernel.org25192519P: 4096R/92DFCE96 4FA7 9EEF FCD4 C44F C585 B8C7 C060 2241 92DF CE9625202520-D: Softcursor for vga, hypertech cdrom support, vcsa bugfix, nbd,25212521-D: sun4/330 port, capabilities for elf, speedup for rm on ext2, USB,25222522-D: work on suspend-to-ram/disk, killing duplicates from ioctl32,25202520+D: NBD, Sun4/330 port, USB, work on suspend-to-ram/disk,25232521D: Altera SoCFPGA and Nokia N900 support.25242522S: Czech Republic25252523
···77title: Qualcomm Technologies ath10k wireless devices8899maintainers:1010- - Kalle Valo <kvalo@kernel.org>1110 - Jeff Johnson <jjohnson@kernel.org>12111312description:
···88title: Qualcomm Technologies ath11k wireless devices (PCIe)991010maintainers:1111- - Kalle Valo <kvalo@kernel.org>1211 - Jeff Johnson <jjohnson@kernel.org>13121413description: |
···88title: Qualcomm Technologies ath11k wireless devices991010maintainers:1111- - Kalle Valo <kvalo@kernel.org>1211 - Jeff Johnson <jjohnson@kernel.org>13121413description: |
···991010maintainers:1111 - Jeff Johnson <jjohnson@kernel.org>1212- - Kalle Valo <kvalo@kernel.org>13121413description: |1514 Qualcomm Technologies IEEE 802.11be PCIe devices with WSI interface.
···991010maintainers:1111 - Jeff Johnson <quic_jjohnson@quicinc.com>1212- - Kalle Valo <kvalo@kernel.org>13121413description:1514 Qualcomm Technologies IEEE 802.11be PCIe devices.
···11+Submitting patches to bcachefs:22+===============================33+44+Patches must be tested before being submitted, either with the xfstests suite55+[0], or the full bcachefs test suite in ktest [1], depending on what's being66+touched. Note that ktest wraps xfstests and will be an easier method to running77+it for most users; it includes single-command wrappers for all the mainstream88+in-kernel local filesystems.99+1010+Patches will undergo more testing after being merged (including1111+lockdep/kasan/preempt/etc. variants), these are not generally required to be1212+run by the submitter - but do put some thought into what you're changing and1313+which tests might be relevant, e.g. are you dealing with tricky memory layout1414+work? kasan, are you doing locking work? then lockdep; and ktest includes1515+single-command variants for the debug build types you'll most likely need.1616+1717+The exception to this rule is incomplete WIP/RFC patches: if you're working on1818+something nontrivial, it's encouraged to send out a WIP patch to let people1919+know what you're doing and make sure you're on the right track. Just make sure2020+it includes a brief note as to what's done and what's incomplete, to avoid2121+confusion.2222+2323+Rigorous checkpatch.pl adherence is not required (many of its warnings are2424+considered out of date), but try not to deviate too much without reason.2525+2626+Focus on writing code that reads well and is organized well; code should be2727+aesthetically pleasing.2828+2929+CI:3030+===3131+3232+Instead of running your tests locally, when running the full test suite it's3333+prefereable to let a server farm do it in parallel, and then have the results3434+in a nice test dashboard (which can tell you which failures are new, and3535+presents results in a git log view, avoiding the need for most bisecting).3636+3737+That exists [2], and community members may request an account. If you work for3838+a big tech company, you'll need to help out with server costs to get access -3939+but the CI is not restricted to running bcachefs tests: it runs any ktest test4040+(which generally makes it easy to wrap other tests that can run in qemu).4141+4242+Other things to think about:4343+============================4444+4545+- How will we debug this code? Is there sufficient introspection to diagnose4646+ when something starts acting wonky on a user machine?4747+4848+ We don't necessarily need every single field of every data structure visible4949+ with introspection, but having the important fields of all the core data5050+ types wired up makes debugging drastically easier - a bit of thoughtful5151+ foresight greatly reduces the need to have people build custom kernels with5252+ debug patches.5353+5454+ More broadly, think about all the debug tooling that might be needed.5555+5656+- Does it make the codebase more or less of a mess? Can we also try to do some5757+ organizing, too?5858+5959+- Do new tests need to be written? New assertions? How do we know and verify6060+ that the code is correct, and what happens if something goes wrong?6161+6262+ We don't yet have automated code coverage analysis or easy fault injection -6363+ but for now, pretend we did and ask what they might tell us.6464+6565+ Assertions are hugely important, given that we don't yet have a systems6666+ language that can do ergonomic embedded correctness proofs. Hitting an assert6767+ in testing is much better than wandering off into undefined behaviour la-la6868+ land - use them. Use them judiciously, and not as a replacement for proper6969+ error handling, but use them.7070+7171+- Does it need to be performance tested? Should we add new peformance counters?7272+7373+ bcachefs has a set of persistent runtime counters which can be viewed with7474+ the 'bcachefs fs top' command; this should give users a basic idea of what7575+ their filesystem is currently doing. If you're doing a new feature or looking7676+ at old code, think if anything should be added.7777+7878+- If it's a new on disk format feature - have upgrades and downgrades been7979+ tested? (Automated tests exists but aren't in the CI, due to the hassle of8080+ disk image management; coordinate to have them run.)8181+8282+Mailing list, IRC:8383+==================8484+8585+Patches should hit the list [3], but much discussion and code review happens on8686+IRC as well [4]; many people appreciate the more conversational approach and8787+quicker feedback.8888+8989+Additionally, we have a lively user community doing excellent QA work, which9090+exists primarily on IRC. Please make use of that resource; user feedback is9191+important for any nontrivial feature, and documenting it in commit messages9292+would be a good idea.9393+9494+[0]: git://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git9595+[1]: https://evilpiepirate.org/git/ktest.git/9696+[2]: https://evilpiepirate.org/~testdashboard/ci/9797+[3]: linux-bcachefs@vger.kernel.org9898+[4]: irc.oftc.net#bcache, #bcachefs-dev
···14191419S390:14201420^^^^^1421142114221422-Returns -EINVAL if the VM has the KVM_VM_S390_UCONTROL flag set.14221422+Returns -EINVAL or -EEXIST if the VM has the KVM_VM_S390_UCONTROL flag set.14231423Returns -EINVAL if called on a protected VM.14241424142514254.36 KVM_SET_TSS_ADDR
+10-12
MAINTAINERS
···22092209F: sound/soc/codecs/ssm3515.c2210221022112211ARM/APPLE MACHINE SUPPORT22122212-M: Hector Martin <marcan@marcan.st>22132212M: Sven Peter <sven@svenpeter.dev>22142213R: Alyssa Rosenzweig <alyssa@rosenzweig.io>22152214L: asahi@lists.linux.dev···36543655F: drivers/phy/qualcomm/phy-ath79-usb.c3655365636563657ATHEROS ATH GENERIC UTILITIES36573657-M: Kalle Valo <kvalo@kernel.org>36583658M: Jeff Johnson <jjohnson@kernel.org>36593659L: linux-wireless@vger.kernel.org36603660S: Supported···39533955L: linux-bcachefs@vger.kernel.org39543956S: Supported39553957C: irc://irc.oftc.net/bcache39583958+P: Documentation/filesystems/bcachefs/SubmittingPatches.rst39563959T: git https://evilpiepirate.org/git/bcachefs.git39573960F: fs/bcachefs/39583961F: Documentation/filesystems/bcachefs/···9417941894189419FREEZER94199420M: "Rafael J. Wysocki" <rafael@kernel.org>94209420-M: Pavel Machek <pavel@ucw.cz>94219421+M: Pavel Machek <pavel@kernel.org>94219422L: linux-pm@vger.kernel.org94229423S: Supported94239424F: Documentation/power/freezing-of-tasks.rst···98779878F: drivers/staging/gpib/9878987998799880GPIO ACPI SUPPORT98809880-M: Mika Westerberg <mika.westerberg@linux.intel.com>98819881+M: Mika Westerberg <westeri@kernel.org>98819882M: Andy Shevchenko <andriy.shevchenko@linux.intel.com>98829883L: linux-gpio@vger.kernel.org98839884L: linux-acpi@vger.kernel.org···10252102531025310254HIBERNATION (aka Software Suspend, aka swsusp)1025410255M: "Rafael J. Wysocki" <rafael@kernel.org>1025510255-M: Pavel Machek <pavel@ucw.cz>1025610256+M: Pavel Machek <pavel@kernel.org>1025610257L: linux-pm@vger.kernel.org1025710258S: Supported1025810259B: https://bugzilla.kernel.org···1312313124F: scripts/leaking_addresses.pl13124131251312513126LED SUBSYSTEM1312613126-M: Pavel Machek <pavel@ucw.cz>1312713127M: Lee Jones <lee@kernel.org>1312813128+M: Pavel Machek <pavel@kernel.org>1312813129L: linux-leds@vger.kernel.org1312913130S: Maintained1313013131T: git git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds.git···1643716438X: drivers/net/wireless/16438164391643916440NETWORKING DRIVERS (WIRELESS)1644016440-M: Kalle Valo <kvalo@kernel.org>1644116441+M: Johannes Berg <johannes@sipsolutions.net>1644116442L: linux-wireless@vger.kernel.org1644216443S: Maintained1644316444W: https://wireless.wiki.kernel.org/···1650816509F: include/linux/netlink.h1650916510F: include/linux/netpoll.h1651016511F: include/linux/rtnetlink.h1651216512+F: include/linux/sctp.h1651116513F: include/linux/seq_file_net.h1651216514F: include/linux/skbuff*1651316515F: include/net/···1652516525F: include/uapi/linux/netlink.h1652616526F: include/uapi/linux/netlink_diag.h1652716527F: include/uapi/linux/rtnetlink.h1652816528+F: include/uapi/linux/sctp.h1652816529F: lib/net_utils.c1652916530F: lib/random32.c1653016531F: net/···1682416823F: kernel/time/tick*.*16825168241682616825NOKIA N900 CAMERA SUPPORT (ET8EK8 SENSOR, AD5820 FOCUS)1682716827-M: Pavel Machek <pavel@ucw.cz>1682616826+M: Pavel Machek <pavel@kernel.org>1682816827M: Sakari Ailus <sakari.ailus@iki.fi>1682916828L: linux-media@vger.kernel.org1683016829S: Maintained···1935619355F: drivers/media/tuners/qt1010*19357193561935819357QUALCOMM ATH12K WIRELESS DRIVER1935919359-M: Kalle Valo <kvalo@kernel.org>1936019358M: Jeff Johnson <jjohnson@kernel.org>1936119359L: ath12k@lists.infradead.org1936219360S: Supported···1936519365N: ath12k19366193661936719367QUALCOMM ATHEROS ATH10K WIRELESS DRIVER1936819368-M: Kalle Valo <kvalo@kernel.org>1936919368M: Jeff Johnson <jjohnson@kernel.org>1937019369L: ath10k@lists.infradead.org1937119370S: Supported···1937419375N: ath10k19375193761937619377QUALCOMM ATHEROS ATH11K WIRELESS DRIVER1937719377-M: Kalle Valo <kvalo@kernel.org>1937819378M: Jeff Johnson <jjohnson@kernel.org>1937919379L: ath11k@lists.infradead.org1938019380S: Supported···2284722849SUSPEND TO RAM2284822850M: "Rafael J. Wysocki" <rafael@kernel.org>2284922851M: Len Brown <len.brown@intel.com>2285022850-M: Pavel Machek <pavel@ucw.cz>2285222852+M: Pavel Machek <pavel@kernel.org>2285122853L: linux-pm@vger.kernel.org2285222854S: Supported2285322855B: https://bugzilla.kernel.org
···7474/*7575 * This is used to ensure we don't load something for the wrong architecture.7676 */7777-#define elf_check_arch(x) ((x)->e_machine == EM_ALPHA)7777+#define elf_check_arch(x) (((x)->e_machine == EM_ALPHA) && !((x)->e_flags & EF_ALPHA_32BIT))78787979/*8080 * These are used to set parameters in the core dumps.···136136 ( i_ == IMPLVER_EV5 ? "ev56" \137137 : amask (AMASK_CIX) ? "ev6" : "ev67"); \138138})139139-140140-#define SET_PERSONALITY(EX) \141141- set_personality(((EX).e_flags & EF_ALPHA_32BIT) \142142- ? PER_LINUX_32BIT : PER_LINUX)143139144140extern int alpha_l1i_cacheshape;145141extern int alpha_l1d_cacheshape;
+1-1
arch/alpha/include/asm/pgtable.h
···360360361361extern void paging_init(void);362362363363-/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT. */363363+/* We have our own get_unmapped_area */364364#define HAVE_ARCH_UNMAPPED_AREA365365366366#endif /* _ALPHA_PGTABLE_H */
+2-6
arch/alpha/include/asm/processor.h
···88#ifndef __ASM_ALPHA_PROCESSOR_H99#define __ASM_ALPHA_PROCESSOR_H10101111-#include <linux/personality.h> /* for ADDR_LIMIT_32BIT */1212-1311/*1412 * We have a 42-bit user address space: 4TB user VM...1513 */1614#define TASK_SIZE (0x40000000000UL)17151818-#define STACK_TOP \1919- (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)1616+#define STACK_TOP (0x00120000000UL)20172118#define STACK_TOP_MAX 0x00120000000UL22192320/* This decides where the kernel will search for a free chunk of vm2421 * space during mmap's.2522 */2626-#define TASK_UNMAPPED_BASE \2727- ((current->personality & ADDR_LIMIT_32BIT) ? 0x40000000 : TASK_SIZE / 2)2323+#define TASK_UNMAPPED_BASE (TASK_SIZE / 2)28242925/* This is dead. Everything has been moved to thread_info. */3026struct thread_struct { };
+2-9
arch/alpha/kernel/osf_sys.c
···12101210 return ret;12111211}1212121212131213-/* Get an address range which is currently unmapped. Similar to the12141214- generic version except that we know how to honor ADDR_LIMIT_32BIT. */12131213+/* Get an address range which is currently unmapped. */1215121412161215static unsigned long12171216arch_get_unmapped_area_1(unsigned long addr, unsigned long len,···12291230 unsigned long len, unsigned long pgoff,12301231 unsigned long flags, vm_flags_t vm_flags)12311232{12321232- unsigned long limit;12331233-12341234- /* "32 bit" actually means 31 bit, since pointers sign extend. */12351235- if (current->personality & ADDR_LIMIT_32BIT)12361236- limit = 0x80000000;12371237- else12381238- limit = TASK_SIZE;12331233+ unsigned long limit = TASK_SIZE;1239123412401235 if (len > limit)12411236 return -ENOMEM;
+11-38
arch/arm64/kvm/arch_timer.c
···471471472472 trace_kvm_timer_emulate(ctx, should_fire);473473474474- if (should_fire != ctx->irq.level) {474474+ if (should_fire != ctx->irq.level)475475 kvm_timer_update_irq(ctx->vcpu, should_fire, ctx);476476- return;477477- }478476479477 kvm_timer_update_status(ctx, should_fire);480478···759761 timer_irq(map->direct_ptimer),760762 &arch_timer_irq_ops);761763 WARN_ON_ONCE(ret);762762-763763- /*764764- * The virtual offset behaviour is "interesting", as it765765- * always applies when HCR_EL2.E2H==0, but only when766766- * accessed from EL1 when HCR_EL2.E2H==1. So make sure we767767- * track E2H when putting the HV timer in "direct" mode.768768- */769769- if (map->direct_vtimer == vcpu_hvtimer(vcpu)) {770770- struct arch_timer_offset *offs = &map->direct_vtimer->offset;771771-772772- if (vcpu_el2_e2h_is_set(vcpu))773773- offs->vcpu_offset = NULL;774774- else775775- offs->vcpu_offset = &__vcpu_sys_reg(vcpu, CNTVOFF_EL2);776776- }777764 }778765}779766···959976 * which allows trapping of the timer registers even with NV2.960977 * Still, this is still worse than FEAT_NV on its own. Meh.961978 */962962- if (!vcpu_el2_e2h_is_set(vcpu)) {963963- if (cpus_have_final_cap(ARM64_HAS_ECV))964964- return;965965-966966- /*967967- * A non-VHE guest hypervisor doesn't have any direct access968968- * to its timers: the EL2 registers trap (and the HW is969969- * fully emulated), while the EL0 registers access memory970970- * despite the access being notionally direct. Boo.971971- *972972- * We update the hardware timer registers with the973973- * latest value written by the guest to the VNCR page974974- * and let the hardware take care of the rest.975975- */976976- write_sysreg_el0(__vcpu_sys_reg(vcpu, CNTV_CTL_EL0), SYS_CNTV_CTL);977977- write_sysreg_el0(__vcpu_sys_reg(vcpu, CNTV_CVAL_EL0), SYS_CNTV_CVAL);978978- write_sysreg_el0(__vcpu_sys_reg(vcpu, CNTP_CTL_EL0), SYS_CNTP_CTL);979979- write_sysreg_el0(__vcpu_sys_reg(vcpu, CNTP_CVAL_EL0), SYS_CNTP_CVAL);980980- } else {979979+ if (!cpus_have_final_cap(ARM64_HAS_ECV)) {981980 /*982981 * For a VHE guest hypervisor, the EL2 state is directly983983- * stored in the host EL1 timers, while the emulated EL0982982+ * stored in the host EL1 timers, while the emulated EL1984983 * state is stored in the VNCR page. The latter could have985984 * been updated behind our back, and we must reset the986985 * emulation of the timers.986986+ *987987+ * A non-VHE guest hypervisor doesn't have any direct access988988+ * to its timers: the EL2 registers trap despite being989989+ * notionally direct (we use the EL1 HW, as for VHE), while990990+ * the EL1 registers access memory.991991+ *992992+ * In both cases, process the emulated timers on each guest993993+ * exit. Boo.987994 */988995 struct timer_map map;989996 get_timer_map(vcpu, &map);
+20
arch/arm64/kvm/arm.c
···22902290 break;22912291 case -ENODEV:22922292 case -ENXIO:22932293+ /*22942294+ * No VGIC? No pKVM for you.22952295+ *22962296+ * Protected mode assumes that VGICv3 is present, so no point22972297+ * in trying to hobble along if vgic initialization fails.22982298+ */22992299+ if (is_protected_kvm_enabled())23002300+ goto out;23012301+23022302+ /*23032303+ * Otherwise, userspace could choose to implement a GIC for its23042304+ * guest on non-cooperative hardware.23052305+ */22932306 vgic_present = false;22942307 err = 0;22952308 break;···24132400 kvm_nvhe_sym(id_aa64smfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64SMFR0_EL1);24142401 kvm_nvhe_sym(__icache_flags) = __icache_flags;24152402 kvm_nvhe_sym(kvm_arm_vmid_bits) = kvm_arm_vmid_bits;24032403+24042404+ /*24052405+ * Flush entire BSS since part of its data containing init symbols is read24062406+ * while the MMU is off.24072407+ */24082408+ kvm_flush_dcache_to_poc(kvm_ksym_ref(__hyp_bss_start),24092409+ kvm_ksym_ref(__hyp_bss_end) - kvm_ksym_ref(__hyp_bss_start));24162410}2417241124182412static int __init kvm_hyp_init_protection(u32 hyp_va_bits)
···6767 if (!tmp)6868 return -ENOMEM;69697070+ swap(kvm->arch.nested_mmus, tmp);7171+7072 /*7173 * If we went through a realocation, adjust the MMU back-pointers in7274 * the previously initialised kvm_pgtable structures.7375 */7476 if (kvm->arch.nested_mmus != tmp)7577 for (int i = 0; i < kvm->arch.nested_mmus_size; i++)7676- tmp[i].pgt->mmu = &tmp[i];7878+ kvm->arch.nested_mmus[i].pgt->mmu = &kvm->arch.nested_mmus[i];77797880 for (int i = kvm->arch.nested_mmus_size; !ret && i < num_mmus; i++)7979- ret = init_nested_s2_mmu(kvm, &tmp[i]);8181+ ret = init_nested_s2_mmu(kvm, &kvm->arch.nested_mmus[i]);80828183 if (ret) {8284 for (int i = kvm->arch.nested_mmus_size; i < num_mmus; i++)8383- kvm_free_stage2_pgd(&tmp[i]);8585+ kvm_free_stage2_pgd(&kvm->arch.nested_mmus[i]);84868587 return ret;8688 }87898890 kvm->arch.nested_mmus_size = num_mmus;8989- kvm->arch.nested_mmus = tmp;90919192 return 0;9293}
···7676#define cpu_family_string() __cpu_family[raw_smp_processor_id()]7777#define cpu_full_name_string() __cpu_full_name[raw_smp_processor_id()]78787979-struct seq_file;8080-struct notifier_block;8181-8282-extern int register_proc_cpuinfo_notifier(struct notifier_block *nb);8383-extern int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v);8484-8585-#define proc_cpuinfo_notifier(fn, pri) \8686-({ \8787- static struct notifier_block fn##_nb = { \8888- .notifier_call = fn, \8989- .priority = pri \9090- }; \9191- \9292- register_proc_cpuinfo_notifier(&fn##_nb); \9393-})9494-9595-struct proc_cpuinfo_notifier_args {9696- struct seq_file *m;9797- unsigned long n;9898-};9999-10079static inline bool cpus_are_siblings(int cpua, int cpub)10180{10281 struct cpuinfo_loongarch *infoa = &cpu_data[cpua];
+2
arch/loongarch/include/asm/smp.h
···7777#define SMP_IRQ_WORK BIT(ACTION_IRQ_WORK)7878#define SMP_CLEAR_VECTOR BIT(ACTION_CLEAR_VECTOR)79798080+struct seq_file;8181+8082struct secondary_data {8183 unsigned long stack;8284 unsigned long thread_info;
+15-13
arch/loongarch/kernel/genex.S
···18181919 .align 52020SYM_FUNC_START(__arch_cpu_idle)2121- /* start of rollback region */2222- LONG_L t0, tp, TI_FLAGS2323- nop2424- andi t0, t0, _TIF_NEED_RESCHED2525- bnez t0, 1f2626- nop2727- nop2828- nop2121+ /* start of idle interrupt region */2222+ ori t0, zero, CSR_CRMD_IE2323+ /* idle instruction needs irq enabled */2424+ csrxchg t0, t0, LOONGARCH_CSR_CRMD2525+ /*2626+ * If an interrupt lands here; between enabling interrupts above and2727+ * going idle on the next instruction, we must *NOT* go idle since the2828+ * interrupt could have set TIF_NEED_RESCHED or caused an timer to need2929+ * reprogramming. Fall through -- see handle_vint() below -- and have3030+ * the idle loop take care of things.3131+ */2932 idle 03030- /* end of rollback region */3333+ /* end of idle interrupt region */31341: jr ra3235SYM_FUNC_END(__arch_cpu_idle)3336···3835 UNWIND_HINT_UNDEFINED3936 BACKUP_T0T14037 SAVE_ALL4141- la_abs t1, __arch_cpu_idle3838+ la_abs t1, 1b4239 LONG_L t0, sp, PT_ERA4343- /* 32 byte rollback region */4444- ori t0, t0, 0x1f4545- xori t0, t0, 0x1f4040+ /* 3 instructions idle interrupt region */4141+ ori t0, t0, 0b11004642 bne t0, t1, 1f4743 LONG_S t0, sp, PT_ERA48441: move a0, sp
···303303 * TOE=0: Trap on Exception.304304 * TIT=0: Trap on Timer.305305 */306306- if (env & CSR_GCFG_GCIP_ALL)306306+ if (env & CSR_GCFG_GCIP_SECURE)307307 gcfg |= CSR_GCFG_GCI_SECURE;308308- if (env & CSR_GCFG_MATC_ROOT)308308+ if (env & CSR_GCFG_MATP_ROOT)309309 gcfg |= CSR_GCFG_MATC_ROOT;310310311311 write_csr_gcfg(gcfg);
+1-1
arch/loongarch/kvm/switch.S
···8585 * Guest CRMD comes from separate GCSR_CRMD register8686 */8787 ori t0, zero, CSR_PRMD_PIE8888- csrxchg t0, t0, LOONGARCH_CSR_PRMD8888+ csrwr t0, LOONGARCH_CSR_PRMD89899090 /* Set PVM bit to setup ertn to guest context */9191 ori t0, zero, CSR_GSTAT_PVM
-3
arch/loongarch/kvm/vcpu.c
···1548154815491549 /* Restore timer state regardless */15501550 kvm_restore_timer(vcpu);15511551-15521552- /* Control guest page CCA attribute */15531553- change_csr_gcfg(CSR_GCFG_MATC_MASK, CSR_GCFG_MATC_ROOT);15541551 kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);1555155215561553 /* Restore hardware PMU CSRs */
···2323/**2424 * struct gmap_struct - guest address space2525 * @list: list head for the mm->context gmap list2626- * @crst_list: list of all crst tables used in the guest address space2726 * @mm: pointer to the parent mm_struct2827 * @guest_to_host: radix tree with guest to host address translation2928 * @host_to_guest: radix tree with pointer to segment table entries···3435 * @guest_handle: protected virtual machine handle for the ultravisor3536 * @host_to_rmap: radix tree with gmap_rmap lists3637 * @children: list of shadow gmap structures3737- * @pt_list: list of all page tables used in the shadow guest address space3838 * @shadow_lock: spinlock to protect the shadow gmap list3939 * @parent: pointer to the parent gmap for shadow guest address spaces4040 * @orig_asce: ASCE for which the shadow page table has been created···4345 */4446struct gmap {4547 struct list_head list;4646- struct list_head crst_list;4748 struct mm_struct *mm;4849 struct radix_tree_root guest_to_host;4950 struct radix_tree_root host_to_guest;···5861 /* Additional data for shadow guest address spaces */5962 struct radix_tree_root host_to_rmap;6063 struct list_head children;6161- struct list_head pt_list;6264 spinlock_t shadow_lock;6365 struct gmap *parent;6466 unsigned long orig_asce;···102106void gmap_remove(struct gmap *gmap);103107struct gmap *gmap_get(struct gmap *gmap);104108void gmap_put(struct gmap *gmap);109109+void gmap_free(struct gmap *gmap);110110+struct gmap *gmap_alloc(unsigned long limit);105111106112int gmap_map_segment(struct gmap *gmap, unsigned long from,107113 unsigned long to, unsigned long len);108114int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);109115unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);110110-unsigned long gmap_translate(struct gmap *, unsigned long gaddr);111116int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);112112-int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags);113117void gmap_discard(struct gmap *, unsigned long from, unsigned long to);114118void __gmap_zap(struct gmap *, unsigned long gaddr);115119void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);116120117121int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val);118122119119-struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,120120- int edat_level);121121-int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level);123123+void gmap_unshadow(struct gmap *sg);122124int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t,123125 int fake);124126int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,···125131 int fake);126132int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,127133 int fake);128128-int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,129129- unsigned long *pgt, int *dat_protection, int *fake);130134int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte);131135132136void gmap_register_pte_notifier(struct gmap_notifier *);133137void gmap_unregister_pte_notifier(struct gmap_notifier *);134138135135-int gmap_mprotect_notify(struct gmap *, unsigned long start,136136- unsigned long len, int prot);139139+int gmap_protect_one(struct gmap *gmap, unsigned long gaddr, int prot, unsigned long bits);137140138141void gmap_sync_dirty_log_pmd(struct gmap *gmap, unsigned long dirty_bitmap[4],139142 unsigned long gaddr, unsigned long vmaddr);140143int s390_disable_cow_sharing(void);141141-void s390_unlist_old_asce(struct gmap *gmap);142144int s390_replace_asce(struct gmap *gmap);143145void s390_uv_destroy_pfns(unsigned long count, unsigned long *pfns);144146int __s390_uv_destroy_range(struct mm_struct *mm, unsigned long start,145147 unsigned long end, bool interruptible);148148+int kvm_s390_wiggle_split_folio(struct mm_struct *mm, struct folio *folio, bool split);149149+unsigned long *gmap_table_walk(struct gmap *gmap, unsigned long gaddr, int level);146150147151/**148152 * s390_uv_destroy_range - Destroy a range of pages in the given mm.
+5-1
arch/s390/include/asm/kvm_host.h
···3030#define KVM_S390_ESCA_CPU_SLOTS 2483131#define KVM_MAX_VCPUS 25532323333+#define KVM_INTERNAL_MEM_SLOTS 13434+3335/*3436 * These seem to be used for allocating ->chip in the routing table, which we3537 * don't use. 1 is as small as we can get to reduce the needed memory. If we···933931 u8 reserved928[0x1000 - 0x928]; /* 0x0928 */934932};935933934934+struct vsie_page;935935+936936struct kvm_s390_vsie {937937 struct mutex mutex;938938 struct radix_tree_root addr_to_page;939939 int page_count;940940 int next;941941- struct page *pages[KVM_MAX_VCPUS];941941+ struct vsie_page *pages[KVM_MAX_VCPUS];942942};943943944944struct kvm_s390_gisa_iam {
+18-3
arch/s390/include/asm/pgtable.h
···420420#define PGSTE_HC_BIT 0x0020000000000000UL421421#define PGSTE_GR_BIT 0x0004000000000000UL422422#define PGSTE_GC_BIT 0x0002000000000000UL423423-#define PGSTE_UC_BIT 0x0000800000000000UL /* user dirty (migration) */424424-#define PGSTE_IN_BIT 0x0000400000000000UL /* IPTE notify bit */425425-#define PGSTE_VSIE_BIT 0x0000200000000000UL /* ref'd in a shadow table */423423+#define PGSTE_ST2_MASK 0x0000ffff00000000UL424424+#define PGSTE_UC_BIT 0x0000000000008000UL /* user dirty (migration) */425425+#define PGSTE_IN_BIT 0x0000000000004000UL /* IPTE notify bit */426426+#define PGSTE_VSIE_BIT 0x0000000000002000UL /* ref'd in a shadow table */426427427428/* Guest Page State used for virtualization */428429#define _PGSTE_GPS_ZERO 0x0000000080000000UL···2007200620082007#define pmd_pgtable(pmd) \20092008 ((pgtable_t)__va(pmd_val(pmd) & -sizeof(pte_t)*PTRS_PER_PTE))20092009+20102010+static inline unsigned long gmap_pgste_get_pgt_addr(unsigned long *pgt)20112011+{20122012+ unsigned long *pgstes, res;20132013+20142014+ pgstes = pgt + _PAGE_ENTRIES;20152015+20162016+ res = (pgstes[0] & PGSTE_ST2_MASK) << 16;20172017+ res |= pgstes[1] & PGSTE_ST2_MASK;20182018+ res |= (pgstes[2] & PGSTE_ST2_MASK) >> 16;20192019+ res |= (pgstes[3] & PGSTE_ST2_MASK) >> 32;20202020+20212021+ return res;20222022+}2010202320112024#endif /* _S390_PAGE_H */
+3-3
arch/s390/include/asm/uv.h
···628628}629629630630int uv_pin_shared(unsigned long paddr);631631-int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb);632632-int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr);633631int uv_destroy_folio(struct folio *folio);634632int uv_destroy_pte(pte_t pte);635633int uv_convert_from_secure_pte(pte_t pte);636636-int gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr);634634+int make_folio_secure(struct folio *folio, struct uv_cb_header *uvcb);635635+int uv_convert_from_secure(unsigned long paddr);636636+int uv_convert_from_secure_folio(struct folio *folio);637637638638void setup_uv(void);639639
+29-263
arch/s390/kernel/uv.c
···1919#include <asm/sections.h>2020#include <asm/uv.h>21212222-#if !IS_ENABLED(CONFIG_KVM)2323-unsigned long __gmap_translate(struct gmap *gmap, unsigned long gaddr)2424-{2525- return 0;2626-}2727-2828-int gmap_fault(struct gmap *gmap, unsigned long gaddr,2929- unsigned int fault_flags)3030-{3131- return 0;3232-}3333-#endif3434-3522/* the bootdata_preserved fields come from ones in arch/s390/boot/uv.c */3623int __bootdata_preserved(prot_virt_guest);3724EXPORT_SYMBOL(prot_virt_guest);···146159 folio_put(folio);147160 return rc;148161}162162+EXPORT_SYMBOL(uv_destroy_folio);149163150164/*151165 * The present PTE still indirectly holds a folio reference through the mapping.···163175 *164176 * @paddr: Absolute host address of page to be exported165177 */166166-static int uv_convert_from_secure(unsigned long paddr)178178+int uv_convert_from_secure(unsigned long paddr)167179{168180 struct uv_cb_cfs uvcb = {169181 .header.cmd = UVC_CMD_CONV_FROM_SEC_STOR,···175187 return -EINVAL;176188 return 0;177189}190190+EXPORT_SYMBOL_GPL(uv_convert_from_secure);178191179192/*180193 * The caller must already hold a reference to the folio.181194 */182182-static int uv_convert_from_secure_folio(struct folio *folio)195195+int uv_convert_from_secure_folio(struct folio *folio)183196{184197 int rc;185198···195206 folio_put(folio);196207 return rc;197208}209209+EXPORT_SYMBOL_GPL(uv_convert_from_secure_folio);198210199211/*200212 * The present PTE still indirectly holds a folio reference through the mapping.···227237 return res;228238}229239230230-static int make_folio_secure(struct folio *folio, struct uv_cb_header *uvcb)240240+/**241241+ * make_folio_secure() - make a folio secure242242+ * @folio: the folio to make secure243243+ * @uvcb: the uvcb that describes the UVC to be used244244+ *245245+ * The folio @folio will be made secure if possible, @uvcb will be passed246246+ * as-is to the UVC.247247+ *248248+ * Return: 0 on success;249249+ * -EBUSY if the folio is in writeback or has too many references;250250+ * -E2BIG if the folio is large;251251+ * -EAGAIN if the UVC needs to be attempted again;252252+ * -ENXIO if the address is not mapped;253253+ * -EINVAL if the UVC failed for other reasons.254254+ *255255+ * Context: The caller must hold exactly one extra reference on the folio256256+ * (it's the same logic as split_folio())257257+ */258258+int make_folio_secure(struct folio *folio, struct uv_cb_header *uvcb)231259{232260 int expected, cc = 0;233261262262+ if (folio_test_large(folio))263263+ return -E2BIG;234264 if (folio_test_writeback(folio))235235- return -EAGAIN;236236- expected = expected_folio_refs(folio);265265+ return -EBUSY;266266+ expected = expected_folio_refs(folio) + 1;237267 if (!folio_ref_freeze(folio, expected))238268 return -EBUSY;239269 set_bit(PG_arch_1, &folio->flags);···277267 return -EAGAIN;278268 return uvcb->rc == 0x10a ? -ENXIO : -EINVAL;279269}280280-281281-/**282282- * should_export_before_import - Determine whether an export is needed283283- * before an import-like operation284284- * @uvcb: the Ultravisor control block of the UVC to be performed285285- * @mm: the mm of the process286286- *287287- * Returns whether an export is needed before every import-like operation.288288- * This is needed for shared pages, which don't trigger a secure storage289289- * exception when accessed from a different guest.290290- *291291- * Although considered as one, the Unpin Page UVC is not an actual import,292292- * so it is not affected.293293- *294294- * No export is needed also when there is only one protected VM, because the295295- * page cannot belong to the wrong VM in that case (there is no "other VM"296296- * it can belong to).297297- *298298- * Return: true if an export is needed before every import, otherwise false.299299- */300300-static bool should_export_before_import(struct uv_cb_header *uvcb, struct mm_struct *mm)301301-{302302- /*303303- * The misc feature indicates, among other things, that importing a304304- * shared page from a different protected VM will automatically also305305- * transfer its ownership.306306- */307307- if (uv_has_feature(BIT_UV_FEAT_MISC))308308- return false;309309- if (uvcb->cmd == UVC_CMD_UNPIN_PAGE_SHARED)310310- return false;311311- return atomic_read(&mm->context.protected_count) > 1;312312-}313313-314314-/*315315- * Drain LRU caches: the local one on first invocation and the ones of all316316- * CPUs on successive invocations. Returns "true" on the first invocation.317317- */318318-static bool drain_lru(bool *drain_lru_called)319319-{320320- /*321321- * If we have tried a local drain and the folio refcount322322- * still does not match our expected safe value, try with a323323- * system wide drain. This is needed if the pagevecs holding324324- * the page are on a different CPU.325325- */326326- if (*drain_lru_called) {327327- lru_add_drain_all();328328- /* We give up here, don't retry immediately. */329329- return false;330330- }331331- /*332332- * We are here if the folio refcount does not match the333333- * expected safe value. The main culprits are usually334334- * pagevecs. With lru_add_drain() we drain the pagevecs335335- * on the local CPU so that hopefully the refcount will336336- * reach the expected safe value.337337- */338338- lru_add_drain();339339- *drain_lru_called = true;340340- /* The caller should try again immediately */341341- return true;342342-}343343-344344-/*345345- * Requests the Ultravisor to make a page accessible to a guest.346346- * If it's brought in the first time, it will be cleared. If347347- * it has been exported before, it will be decrypted and integrity348348- * checked.349349- */350350-int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb)351351-{352352- struct vm_area_struct *vma;353353- bool drain_lru_called = false;354354- spinlock_t *ptelock;355355- unsigned long uaddr;356356- struct folio *folio;357357- pte_t *ptep;358358- int rc;359359-360360-again:361361- rc = -EFAULT;362362- mmap_read_lock(gmap->mm);363363-364364- uaddr = __gmap_translate(gmap, gaddr);365365- if (IS_ERR_VALUE(uaddr))366366- goto out;367367- vma = vma_lookup(gmap->mm, uaddr);368368- if (!vma)369369- goto out;370370- /*371371- * Secure pages cannot be huge and userspace should not combine both.372372- * In case userspace does it anyway this will result in an -EFAULT for373373- * the unpack. The guest is thus never reaching secure mode. If374374- * userspace is playing dirty tricky with mapping huge pages later375375- * on this will result in a segmentation fault.376376- */377377- if (is_vm_hugetlb_page(vma))378378- goto out;379379-380380- rc = -ENXIO;381381- ptep = get_locked_pte(gmap->mm, uaddr, &ptelock);382382- if (!ptep)383383- goto out;384384- if (pte_present(*ptep) && !(pte_val(*ptep) & _PAGE_INVALID) && pte_write(*ptep)) {385385- folio = page_folio(pte_page(*ptep));386386- rc = -EAGAIN;387387- if (folio_test_large(folio)) {388388- rc = -E2BIG;389389- } else if (folio_trylock(folio)) {390390- if (should_export_before_import(uvcb, gmap->mm))391391- uv_convert_from_secure(PFN_PHYS(folio_pfn(folio)));392392- rc = make_folio_secure(folio, uvcb);393393- folio_unlock(folio);394394- }395395-396396- /*397397- * Once we drop the PTL, the folio may get unmapped and398398- * freed immediately. We need a temporary reference.399399- */400400- if (rc == -EAGAIN || rc == -E2BIG)401401- folio_get(folio);402402- }403403- pte_unmap_unlock(ptep, ptelock);404404-out:405405- mmap_read_unlock(gmap->mm);406406-407407- switch (rc) {408408- case -E2BIG:409409- folio_lock(folio);410410- rc = split_folio(folio);411411- folio_unlock(folio);412412- folio_put(folio);413413-414414- switch (rc) {415415- case 0:416416- /* Splitting succeeded, try again immediately. */417417- goto again;418418- case -EAGAIN:419419- /* Additional folio references. */420420- if (drain_lru(&drain_lru_called))421421- goto again;422422- return -EAGAIN;423423- case -EBUSY:424424- /* Unexpected race. */425425- return -EAGAIN;426426- }427427- WARN_ON_ONCE(1);428428- return -ENXIO;429429- case -EAGAIN:430430- /*431431- * If we are here because the UVC returned busy or partial432432- * completion, this is just a useless check, but it is safe.433433- */434434- folio_wait_writeback(folio);435435- folio_put(folio);436436- return -EAGAIN;437437- case -EBUSY:438438- /* Additional folio references. */439439- if (drain_lru(&drain_lru_called))440440- goto again;441441- return -EAGAIN;442442- case -ENXIO:443443- if (gmap_fault(gmap, gaddr, FAULT_FLAG_WRITE))444444- return -EFAULT;445445- return -EAGAIN;446446- }447447- return rc;448448-}449449-EXPORT_SYMBOL_GPL(gmap_make_secure);450450-451451-int gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr)452452-{453453- struct uv_cb_cts uvcb = {454454- .header.cmd = UVC_CMD_CONV_TO_SEC_STOR,455455- .header.len = sizeof(uvcb),456456- .guest_handle = gmap->guest_handle,457457- .gaddr = gaddr,458458- };459459-460460- return gmap_make_secure(gmap, gaddr, &uvcb);461461-}462462-EXPORT_SYMBOL_GPL(gmap_convert_to_secure);463463-464464-/**465465- * gmap_destroy_page - Destroy a guest page.466466- * @gmap: the gmap of the guest467467- * @gaddr: the guest address to destroy468468- *469469- * An attempt will be made to destroy the given guest page. If the attempt470470- * fails, an attempt is made to export the page. If both attempts fail, an471471- * appropriate error is returned.472472- */473473-int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr)474474-{475475- struct vm_area_struct *vma;476476- struct folio_walk fw;477477- unsigned long uaddr;478478- struct folio *folio;479479- int rc;480480-481481- rc = -EFAULT;482482- mmap_read_lock(gmap->mm);483483-484484- uaddr = __gmap_translate(gmap, gaddr);485485- if (IS_ERR_VALUE(uaddr))486486- goto out;487487- vma = vma_lookup(gmap->mm, uaddr);488488- if (!vma)489489- goto out;490490- /*491491- * Huge pages should not be able to become secure492492- */493493- if (is_vm_hugetlb_page(vma))494494- goto out;495495-496496- rc = 0;497497- folio = folio_walk_start(&fw, vma, uaddr, 0);498498- if (!folio)499499- goto out;500500- /*501501- * See gmap_make_secure(): large folios cannot be secure. Small502502- * folio implies FW_LEVEL_PTE.503503- */504504- if (folio_test_large(folio) || !pte_write(fw.pte))505505- goto out_walk_end;506506- rc = uv_destroy_folio(folio);507507- /*508508- * Fault handlers can race; it is possible that two CPUs will fault509509- * on the same secure page. One CPU can destroy the page, reboot,510510- * re-enter secure mode and import it, while the second CPU was511511- * stuck at the beginning of the handler. At some point the second512512- * CPU will be able to progress, and it will not be able to destroy513513- * the page. In that case we do not want to terminate the process,514514- * we instead try to export the page.515515- */516516- if (rc)517517- rc = uv_convert_from_secure_folio(folio);518518-out_walk_end:519519- folio_walk_end(&fw, vma);520520-out:521521- mmap_read_unlock(gmap->mm);522522- return rc;523523-}524524-EXPORT_SYMBOL_GPL(gmap_destroy_page);270270+EXPORT_SYMBOL_GPL(make_folio_secure);525271526272/*527273 * To be called with the folio locked or with an extra reference! This will
···1616#include <asm/gmap.h>1717#include <asm/dat-bits.h>1818#include "kvm-s390.h"1919+#include "gmap.h"1920#include "gaccess.h"20212122/*···13941393}1395139413961395/**13961396+ * shadow_pgt_lookup() - find a shadow page table13971397+ * @sg: pointer to the shadow guest address space structure13981398+ * @saddr: the address in the shadow aguest address space13991399+ * @pgt: parent gmap address of the page table to get shadowed14001400+ * @dat_protection: if the pgtable is marked as protected by dat14011401+ * @fake: pgt references contiguous guest memory block, not a pgtable14021402+ *14031403+ * Returns 0 if the shadow page table was found and -EAGAIN if the page14041404+ * table was not found.14051405+ *14061406+ * Called with sg->mm->mmap_lock in read.14071407+ */14081408+static int shadow_pgt_lookup(struct gmap *sg, unsigned long saddr, unsigned long *pgt,14091409+ int *dat_protection, int *fake)14101410+{14111411+ unsigned long pt_index;14121412+ unsigned long *table;14131413+ struct page *page;14141414+ int rc;14151415+14161416+ spin_lock(&sg->guest_table_lock);14171417+ table = gmap_table_walk(sg, saddr, 1); /* get segment pointer */14181418+ if (table && !(*table & _SEGMENT_ENTRY_INVALID)) {14191419+ /* Shadow page tables are full pages (pte+pgste) */14201420+ page = pfn_to_page(*table >> PAGE_SHIFT);14211421+ pt_index = gmap_pgste_get_pgt_addr(page_to_virt(page));14221422+ *pgt = pt_index & ~GMAP_SHADOW_FAKE_TABLE;14231423+ *dat_protection = !!(*table & _SEGMENT_ENTRY_PROTECT);14241424+ *fake = !!(pt_index & GMAP_SHADOW_FAKE_TABLE);14251425+ rc = 0;14261426+ } else {14271427+ rc = -EAGAIN;14281428+ }14291429+ spin_unlock(&sg->guest_table_lock);14301430+ return rc;14311431+}14321432+14331433+/**13971434 * kvm_s390_shadow_fault - handle fault on a shadow page table13981435 * @vcpu: virtual cpu13991436 * @sg: pointer to the shadow guest address space structure···14541415 int dat_protection, fake;14551416 int rc;1456141714181418+ if (KVM_BUG_ON(!gmap_is_shadow(sg), vcpu->kvm))14191419+ return -EFAULT;14201420+14571421 mmap_read_lock(sg->mm);14581422 /*14591423 * We don't want any guest-2 tables to change - so the parent···14651423 */14661424 ipte_lock(vcpu->kvm);1467142514681468- rc = gmap_shadow_pgt_lookup(sg, saddr, &pgt, &dat_protection, &fake);14261426+ rc = shadow_pgt_lookup(sg, saddr, &pgt, &dat_protection, &fake);14691427 if (rc)14701428 rc = kvm_s390_shadow_tables(sg, saddr, &pgt, &dat_protection,14711429 &fake);
+142
arch/s390/kvm/gmap-vsie.c
···11+// SPDX-License-Identifier: GPL-2.022+/*33+ * Guest memory management for KVM/s390 nested VMs.44+ *55+ * Copyright IBM Corp. 2008, 2020, 202466+ *77+ * Author(s): Claudio Imbrenda <imbrenda@linux.ibm.com>88+ * Martin Schwidefsky <schwidefsky@de.ibm.com>99+ * David Hildenbrand <david@redhat.com>1010+ * Janosch Frank <frankja@linux.vnet.ibm.com>1111+ */1212+1313+#include <linux/compiler.h>1414+#include <linux/kvm.h>1515+#include <linux/kvm_host.h>1616+#include <linux/pgtable.h>1717+#include <linux/pagemap.h>1818+#include <linux/mman.h>1919+2020+#include <asm/lowcore.h>2121+#include <asm/gmap.h>2222+#include <asm/uv.h>2323+2424+#include "kvm-s390.h"2525+#include "gmap.h"2626+2727+/**2828+ * gmap_find_shadow - find a specific asce in the list of shadow tables2929+ * @parent: pointer to the parent gmap3030+ * @asce: ASCE for which the shadow table is created3131+ * @edat_level: edat level to be used for the shadow translation3232+ *3333+ * Returns the pointer to a gmap if a shadow table with the given asce is3434+ * already available, ERR_PTR(-EAGAIN) if another one is just being created,3535+ * otherwise NULL3636+ *3737+ * Context: Called with parent->shadow_lock held3838+ */3939+static struct gmap *gmap_find_shadow(struct gmap *parent, unsigned long asce, int edat_level)4040+{4141+ struct gmap *sg;4242+4343+ lockdep_assert_held(&parent->shadow_lock);4444+ list_for_each_entry(sg, &parent->children, list) {4545+ if (!gmap_shadow_valid(sg, asce, edat_level))4646+ continue;4747+ if (!sg->initialized)4848+ return ERR_PTR(-EAGAIN);4949+ refcount_inc(&sg->ref_count);5050+ return sg;5151+ }5252+ return NULL;5353+}5454+5555+/**5656+ * gmap_shadow - create/find a shadow guest address space5757+ * @parent: pointer to the parent gmap5858+ * @asce: ASCE for which the shadow table is created5959+ * @edat_level: edat level to be used for the shadow translation6060+ *6161+ * The pages of the top level page table referred by the asce parameter6262+ * will be set to read-only and marked in the PGSTEs of the kvm process.6363+ * The shadow table will be removed automatically on any change to the6464+ * PTE mapping for the source table.6565+ *6666+ * Returns a guest address space structure, ERR_PTR(-ENOMEM) if out of memory,6767+ * ERR_PTR(-EAGAIN) if the caller has to retry and ERR_PTR(-EFAULT) if the6868+ * parent gmap table could not be protected.6969+ */7070+struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, int edat_level)7171+{7272+ struct gmap *sg, *new;7373+ unsigned long limit;7474+ int rc;7575+7676+ if (KVM_BUG_ON(parent->mm->context.allow_gmap_hpage_1m, (struct kvm *)parent->private) ||7777+ KVM_BUG_ON(gmap_is_shadow(parent), (struct kvm *)parent->private))7878+ return ERR_PTR(-EFAULT);7979+ spin_lock(&parent->shadow_lock);8080+ sg = gmap_find_shadow(parent, asce, edat_level);8181+ spin_unlock(&parent->shadow_lock);8282+ if (sg)8383+ return sg;8484+ /* Create a new shadow gmap */8585+ limit = -1UL >> (33 - (((asce & _ASCE_TYPE_MASK) >> 2) * 11));8686+ if (asce & _ASCE_REAL_SPACE)8787+ limit = -1UL;8888+ new = gmap_alloc(limit);8989+ if (!new)9090+ return ERR_PTR(-ENOMEM);9191+ new->mm = parent->mm;9292+ new->parent = gmap_get(parent);9393+ new->private = parent->private;9494+ new->orig_asce = asce;9595+ new->edat_level = edat_level;9696+ new->initialized = false;9797+ spin_lock(&parent->shadow_lock);9898+ /* Recheck if another CPU created the same shadow */9999+ sg = gmap_find_shadow(parent, asce, edat_level);100100+ if (sg) {101101+ spin_unlock(&parent->shadow_lock);102102+ gmap_free(new);103103+ return sg;104104+ }105105+ if (asce & _ASCE_REAL_SPACE) {106106+ /* only allow one real-space gmap shadow */107107+ list_for_each_entry(sg, &parent->children, list) {108108+ if (sg->orig_asce & _ASCE_REAL_SPACE) {109109+ spin_lock(&sg->guest_table_lock);110110+ gmap_unshadow(sg);111111+ spin_unlock(&sg->guest_table_lock);112112+ list_del(&sg->list);113113+ gmap_put(sg);114114+ break;115115+ }116116+ }117117+ }118118+ refcount_set(&new->ref_count, 2);119119+ list_add(&new->list, &parent->children);120120+ if (asce & _ASCE_REAL_SPACE) {121121+ /* nothing to protect, return right away */122122+ new->initialized = true;123123+ spin_unlock(&parent->shadow_lock);124124+ return new;125125+ }126126+ spin_unlock(&parent->shadow_lock);127127+ /* protect after insertion, so it will get properly invalidated */128128+ mmap_read_lock(parent->mm);129129+ rc = __kvm_s390_mprotect_many(parent, asce & _ASCE_ORIGIN,130130+ ((asce & _ASCE_TABLE_LENGTH) + 1),131131+ PROT_READ, GMAP_NOTIFY_SHADOW);132132+ mmap_read_unlock(parent->mm);133133+ spin_lock(&parent->shadow_lock);134134+ new->initialized = true;135135+ if (rc) {136136+ list_del(&new->list);137137+ gmap_free(new);138138+ new = ERR_PTR(rc);139139+ }140140+ spin_unlock(&parent->shadow_lock);141141+ return new;142142+}
+212
arch/s390/kvm/gmap.c
···11+// SPDX-License-Identifier: GPL-2.022+/*33+ * Guest memory management for KVM/s39044+ *55+ * Copyright IBM Corp. 2008, 2020, 202466+ *77+ * Author(s): Claudio Imbrenda <imbrenda@linux.ibm.com>88+ * Martin Schwidefsky <schwidefsky@de.ibm.com>99+ * David Hildenbrand <david@redhat.com>1010+ * Janosch Frank <frankja@linux.vnet.ibm.com>1111+ */1212+1313+#include <linux/compiler.h>1414+#include <linux/kvm.h>1515+#include <linux/kvm_host.h>1616+#include <linux/pgtable.h>1717+#include <linux/pagemap.h>1818+1919+#include <asm/lowcore.h>2020+#include <asm/gmap.h>2121+#include <asm/uv.h>2222+2323+#include "gmap.h"2424+2525+/**2626+ * should_export_before_import - Determine whether an export is needed2727+ * before an import-like operation2828+ * @uvcb: the Ultravisor control block of the UVC to be performed2929+ * @mm: the mm of the process3030+ *3131+ * Returns whether an export is needed before every import-like operation.3232+ * This is needed for shared pages, which don't trigger a secure storage3333+ * exception when accessed from a different guest.3434+ *3535+ * Although considered as one, the Unpin Page UVC is not an actual import,3636+ * so it is not affected.3737+ *3838+ * No export is needed also when there is only one protected VM, because the3939+ * page cannot belong to the wrong VM in that case (there is no "other VM"4040+ * it can belong to).4141+ *4242+ * Return: true if an export is needed before every import, otherwise false.4343+ */4444+static bool should_export_before_import(struct uv_cb_header *uvcb, struct mm_struct *mm)4545+{4646+ /*4747+ * The misc feature indicates, among other things, that importing a4848+ * shared page from a different protected VM will automatically also4949+ * transfer its ownership.5050+ */5151+ if (uv_has_feature(BIT_UV_FEAT_MISC))5252+ return false;5353+ if (uvcb->cmd == UVC_CMD_UNPIN_PAGE_SHARED)5454+ return false;5555+ return atomic_read(&mm->context.protected_count) > 1;5656+}5757+5858+static int __gmap_make_secure(struct gmap *gmap, struct page *page, void *uvcb)5959+{6060+ struct folio *folio = page_folio(page);6161+ int rc;6262+6363+ /*6464+ * Secure pages cannot be huge and userspace should not combine both.6565+ * In case userspace does it anyway this will result in an -EFAULT for6666+ * the unpack. The guest is thus never reaching secure mode.6767+ * If userspace plays dirty tricks and decides to map huge pages at a6868+ * later point in time, it will receive a segmentation fault or6969+ * KVM_RUN will return -EFAULT.7070+ */7171+ if (folio_test_hugetlb(folio))7272+ return -EFAULT;7373+ if (folio_test_large(folio)) {7474+ mmap_read_unlock(gmap->mm);7575+ rc = kvm_s390_wiggle_split_folio(gmap->mm, folio, true);7676+ mmap_read_lock(gmap->mm);7777+ if (rc)7878+ return rc;7979+ folio = page_folio(page);8080+ }8181+8282+ if (!folio_trylock(folio))8383+ return -EAGAIN;8484+ if (should_export_before_import(uvcb, gmap->mm))8585+ uv_convert_from_secure(folio_to_phys(folio));8686+ rc = make_folio_secure(folio, uvcb);8787+ folio_unlock(folio);8888+8989+ /*9090+ * In theory a race is possible and the folio might have become9191+ * large again before the folio_trylock() above. In that case, no9292+ * action is performed and -EAGAIN is returned; the callers will9393+ * have to try again later.9494+ * In most cases this implies running the VM again, getting the same9595+ * exception again, and make another attempt in this function.9696+ * This is expected to happen extremely rarely.9797+ */9898+ if (rc == -E2BIG)9999+ return -EAGAIN;100100+ /* The folio has too many references, try to shake some off */101101+ if (rc == -EBUSY) {102102+ mmap_read_unlock(gmap->mm);103103+ kvm_s390_wiggle_split_folio(gmap->mm, folio, false);104104+ mmap_read_lock(gmap->mm);105105+ return -EAGAIN;106106+ }107107+108108+ return rc;109109+}110110+111111+/**112112+ * gmap_make_secure() - make one guest page secure113113+ * @gmap: the guest gmap114114+ * @gaddr: the guest address that needs to be made secure115115+ * @uvcb: the UVCB specifying which operation needs to be performed116116+ *117117+ * Context: needs to be called with kvm->srcu held.118118+ * Return: 0 on success, < 0 in case of error (see __gmap_make_secure()).119119+ */120120+int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb)121121+{122122+ struct kvm *kvm = gmap->private;123123+ struct page *page;124124+ int rc = 0;125125+126126+ lockdep_assert_held(&kvm->srcu);127127+128128+ page = gfn_to_page(kvm, gpa_to_gfn(gaddr));129129+ mmap_read_lock(gmap->mm);130130+ if (page)131131+ rc = __gmap_make_secure(gmap, page, uvcb);132132+ kvm_release_page_clean(page);133133+ mmap_read_unlock(gmap->mm);134134+135135+ return rc;136136+}137137+138138+int gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr)139139+{140140+ struct uv_cb_cts uvcb = {141141+ .header.cmd = UVC_CMD_CONV_TO_SEC_STOR,142142+ .header.len = sizeof(uvcb),143143+ .guest_handle = gmap->guest_handle,144144+ .gaddr = gaddr,145145+ };146146+147147+ return gmap_make_secure(gmap, gaddr, &uvcb);148148+}149149+150150+/**151151+ * __gmap_destroy_page() - Destroy a guest page.152152+ * @gmap: the gmap of the guest153153+ * @page: the page to destroy154154+ *155155+ * An attempt will be made to destroy the given guest page. If the attempt156156+ * fails, an attempt is made to export the page. If both attempts fail, an157157+ * appropriate error is returned.158158+ *159159+ * Context: must be called holding the mm lock for gmap->mm160160+ */161161+static int __gmap_destroy_page(struct gmap *gmap, struct page *page)162162+{163163+ struct folio *folio = page_folio(page);164164+ int rc;165165+166166+ /*167167+ * See gmap_make_secure(): large folios cannot be secure. Small168168+ * folio implies FW_LEVEL_PTE.169169+ */170170+ if (folio_test_large(folio))171171+ return -EFAULT;172172+173173+ rc = uv_destroy_folio(folio);174174+ /*175175+ * Fault handlers can race; it is possible that two CPUs will fault176176+ * on the same secure page. One CPU can destroy the page, reboot,177177+ * re-enter secure mode and import it, while the second CPU was178178+ * stuck at the beginning of the handler. At some point the second179179+ * CPU will be able to progress, and it will not be able to destroy180180+ * the page. In that case we do not want to terminate the process,181181+ * we instead try to export the page.182182+ */183183+ if (rc)184184+ rc = uv_convert_from_secure_folio(folio);185185+186186+ return rc;187187+}188188+189189+/**190190+ * gmap_destroy_page() - Destroy a guest page.191191+ * @gmap: the gmap of the guest192192+ * @gaddr: the guest address to destroy193193+ *194194+ * An attempt will be made to destroy the given guest page. If the attempt195195+ * fails, an attempt is made to export the page. If both attempts fail, an196196+ * appropriate error is returned.197197+ *198198+ * Context: may sleep.199199+ */200200+int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr)201201+{202202+ struct page *page;203203+ int rc = 0;204204+205205+ mmap_read_lock(gmap->mm);206206+ page = gfn_to_page(gmap->private, gpa_to_gfn(gaddr));207207+ if (page)208208+ rc = __gmap_destroy_page(gmap, page);209209+ kvm_release_page_clean(page);210210+ mmap_read_unlock(gmap->mm);211211+ return rc;212212+}
+39
arch/s390/kvm/gmap.h
···11+/* SPDX-License-Identifier: GPL-2.0 */22+/*33+ * KVM guest address space mapping code44+ *55+ * Copyright IBM Corp. 2007, 2016, 202566+ * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>77+ * Claudio Imbrenda <imbrenda@linux.ibm.com>88+ */99+1010+#ifndef ARCH_KVM_S390_GMAP_H1111+#define ARCH_KVM_S390_GMAP_H1212+1313+#define GMAP_SHADOW_FAKE_TABLE 1ULL1414+1515+int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb);1616+int gmap_convert_to_secure(struct gmap *gmap, unsigned long gaddr);1717+int gmap_destroy_page(struct gmap *gmap, unsigned long gaddr);1818+struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, int edat_level);1919+2020+/**2121+ * gmap_shadow_valid - check if a shadow guest address space matches the2222+ * given properties and is still valid2323+ * @sg: pointer to the shadow guest address space structure2424+ * @asce: ASCE for which the shadow table is requested2525+ * @edat_level: edat level to be used for the shadow translation2626+ *2727+ * Returns 1 if the gmap shadow is still valid and matches the given2828+ * properties, the caller can continue using it. Returns 0 otherwise, the2929+ * caller has to request a new shadow gmap in this case.3030+ *3131+ */3232+static inline int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level)3333+{3434+ if (sg->removed)3535+ return 0;3636+ return sg->orig_asce == asce && sg->edat_level == edat_level;3737+}3838+3939+#endif
+4-3
arch/s390/kvm/intercept.c
···2121#include "gaccess.h"2222#include "trace.h"2323#include "trace-s390.h"2424+#include "gmap.h"24252526u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu)2627{···368367 reg2, &srcaddr, GACC_FETCH, 0);369368 if (rc)370369 return kvm_s390_inject_prog_cond(vcpu, rc);371371- rc = gmap_fault(vcpu->arch.gmap, srcaddr, 0);370370+ rc = kvm_s390_handle_dat_fault(vcpu, srcaddr, 0);372371 if (rc != 0)373372 return rc;374373···377376 reg1, &dstaddr, GACC_STORE, 0);378377 if (rc)379378 return kvm_s390_inject_prog_cond(vcpu, rc);380380- rc = gmap_fault(vcpu->arch.gmap, dstaddr, FAULT_FLAG_WRITE);379379+ rc = kvm_s390_handle_dat_fault(vcpu, dstaddr, FOLL_WRITE);381380 if (rc != 0)382381 return rc;383382···550549 * If the unpin did not succeed, the guest will exit again for the UVC551550 * and we will retry the unpin.552551 */553553- if (rc == -EINVAL)552552+ if (rc == -EINVAL || rc == -ENXIO)554553 return 0;555554 /*556555 * If we got -EAGAIN here, we simply return it. It will eventually
+11-8
arch/s390/kvm/interrupt.c
···28932893 struct kvm_kernel_irq_routing_entry *e,28942894 const struct kvm_irq_routing_entry *ue)28952895{28962896- u64 uaddr;28962896+ u64 uaddr_s, uaddr_i;28972897+ int idx;2897289828982899 switch (ue->type) {28992900 /* we store the userspace addresses instead of the guest addresses */···29022901 if (kvm_is_ucontrol(kvm))29032902 return -EINVAL;29042903 e->set = set_adapter_int;29052905- uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr);29062906- if (uaddr == -EFAULT)29042904+29052905+ idx = srcu_read_lock(&kvm->srcu);29062906+ uaddr_s = gpa_to_hva(kvm, ue->u.adapter.summary_addr);29072907+ uaddr_i = gpa_to_hva(kvm, ue->u.adapter.ind_addr);29082908+ srcu_read_unlock(&kvm->srcu, idx);29092909+29102910+ if (kvm_is_error_hva(uaddr_s) || kvm_is_error_hva(uaddr_i))29072911 return -EFAULT;29082908- e->adapter.summary_addr = uaddr;29092909- uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.ind_addr);29102910- if (uaddr == -EFAULT)29112911- return -EFAULT;29122912- e->adapter.ind_addr = uaddr;29122912+ e->adapter.summary_addr = uaddr_s;29132913+ e->adapter.ind_addr = uaddr_i;29132914 e->adapter.summary_offset = ue->u.adapter.summary_offset;29142915 e->adapter.ind_offset = ue->u.adapter.ind_offset;29152916 e->adapter.adapter_id = ue->u.adapter.adapter_id;
+197-40
arch/s390/kvm/kvm-s390.c
···5050#include "kvm-s390.h"5151#include "gaccess.h"5252#include "pci.h"5353+#include "gmap.h"53545455#define CREATE_TRACE_POINTS5556#include "trace.h"···34293428 VM_EVENT(kvm, 3, "vm created with type %lu", type);3430342934313430 if (type & KVM_VM_S390_UCONTROL) {34313431+ struct kvm_userspace_memory_region2 fake_memslot = {34323432+ .slot = KVM_S390_UCONTROL_MEMSLOT,34333433+ .guest_phys_addr = 0,34343434+ .userspace_addr = 0,34353435+ .memory_size = ALIGN_DOWN(TASK_SIZE, _SEGMENT_SIZE),34363436+ .flags = 0,34373437+ };34383438+34323439 kvm->arch.gmap = NULL;34333440 kvm->arch.mem_limit = KVM_S390_NO_MEM_LIMIT;34413441+ /* one flat fake memslot covering the whole address-space */34423442+ mutex_lock(&kvm->slots_lock);34433443+ KVM_BUG_ON(kvm_set_internal_memslot(kvm, &fake_memslot), kvm);34443444+ mutex_unlock(&kvm->slots_lock);34343445 } else {34353446 if (sclp.hamax == U64_MAX)34363447 kvm->arch.mem_limit = TASK_SIZE_MAX;···45114498 return kvm_s390_test_cpuflags(vcpu, CPUSTAT_IBS);45124499}4513450045014501+static int __kvm_s390_fixup_fault_sync(struct gmap *gmap, gpa_t gaddr, unsigned int flags)45024502+{45034503+ struct kvm *kvm = gmap->private;45044504+ gfn_t gfn = gpa_to_gfn(gaddr);45054505+ bool unlocked;45064506+ hva_t vmaddr;45074507+ gpa_t tmp;45084508+ int rc;45094509+45104510+ if (kvm_is_ucontrol(kvm)) {45114511+ tmp = __gmap_translate(gmap, gaddr);45124512+ gfn = gpa_to_gfn(tmp);45134513+ }45144514+45154515+ vmaddr = gfn_to_hva(kvm, gfn);45164516+ rc = fixup_user_fault(gmap->mm, vmaddr, FAULT_FLAG_WRITE, &unlocked);45174517+ if (!rc)45184518+ rc = __gmap_link(gmap, gaddr, vmaddr);45194519+ return rc;45204520+}45214521+45224522+/**45234523+ * __kvm_s390_mprotect_many() - Apply specified protection to guest pages45244524+ * @gmap: the gmap of the guest45254525+ * @gpa: the starting guest address45264526+ * @npages: how many pages to protect45274527+ * @prot: indicates access rights: PROT_NONE, PROT_READ or PROT_WRITE45284528+ * @bits: pgste notification bits to set45294529+ *45304530+ * Returns: 0 in case of success, < 0 in case of error - see gmap_protect_one()45314531+ *45324532+ * Context: kvm->srcu and gmap->mm need to be held in read mode45334533+ */45344534+int __kvm_s390_mprotect_many(struct gmap *gmap, gpa_t gpa, u8 npages, unsigned int prot,45354535+ unsigned long bits)45364536+{45374537+ unsigned int fault_flag = (prot & PROT_WRITE) ? FAULT_FLAG_WRITE : 0;45384538+ gpa_t end = gpa + npages * PAGE_SIZE;45394539+ int rc;45404540+45414541+ for (; gpa < end; gpa = ALIGN(gpa + 1, rc)) {45424542+ rc = gmap_protect_one(gmap, gpa, prot, bits);45434543+ if (rc == -EAGAIN) {45444544+ __kvm_s390_fixup_fault_sync(gmap, gpa, fault_flag);45454545+ rc = gmap_protect_one(gmap, gpa, prot, bits);45464546+ }45474547+ if (rc < 0)45484548+ return rc;45494549+ }45504550+45514551+ return 0;45524552+}45534553+45544554+static int kvm_s390_mprotect_notify_prefix(struct kvm_vcpu *vcpu)45554555+{45564556+ gpa_t gaddr = kvm_s390_get_prefix(vcpu);45574557+ int idx, rc;45584558+45594559+ idx = srcu_read_lock(&vcpu->kvm->srcu);45604560+ mmap_read_lock(vcpu->arch.gmap->mm);45614561+45624562+ rc = __kvm_s390_mprotect_many(vcpu->arch.gmap, gaddr, 2, PROT_WRITE, GMAP_NOTIFY_MPROT);45634563+45644564+ mmap_read_unlock(vcpu->arch.gmap->mm);45654565+ srcu_read_unlock(&vcpu->kvm->srcu, idx);45664566+45674567+ return rc;45684568+}45694569+45144570static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu)45154571{45164572retry:···45954513 */45964514 if (kvm_check_request(KVM_REQ_REFRESH_GUEST_PREFIX, vcpu)) {45974515 int rc;45984598- rc = gmap_mprotect_notify(vcpu->arch.gmap,45994599- kvm_s390_get_prefix(vcpu),46004600- PAGE_SIZE * 2, PROT_WRITE);45164516+45174517+ rc = kvm_s390_mprotect_notify_prefix(vcpu);46014518 if (rc) {46024519 kvm_make_request(KVM_REQ_REFRESH_GUEST_PREFIX, vcpu);46034520 return rc;···48474766 return kvm_s390_inject_prog_irq(vcpu, &pgm_info);48484767}4849476847694769+static void kvm_s390_assert_primary_as(struct kvm_vcpu *vcpu)47704770+{47714771+ KVM_BUG(current->thread.gmap_teid.as != PSW_BITS_AS_PRIMARY, vcpu->kvm,47724772+ "Unexpected program interrupt 0x%x, TEID 0x%016lx",47734773+ current->thread.gmap_int_code, current->thread.gmap_teid.val);47744774+}47754775+47764776+/*47774777+ * __kvm_s390_handle_dat_fault() - handle a dat fault for the gmap of a vcpu47784778+ * @vcpu: the vCPU whose gmap is to be fixed up47794779+ * @gfn: the guest frame number used for memslots (including fake memslots)47804780+ * @gaddr: the gmap address, does not have to match @gfn for ucontrol gmaps47814781+ * @flags: FOLL_* flags47824782+ *47834783+ * Return: 0 on success, < 0 in case of error.47844784+ * Context: The mm lock must not be held before calling. May sleep.47854785+ */47864786+int __kvm_s390_handle_dat_fault(struct kvm_vcpu *vcpu, gfn_t gfn, gpa_t gaddr, unsigned int flags)47874787+{47884788+ struct kvm_memory_slot *slot;47894789+ unsigned int fault_flags;47904790+ bool writable, unlocked;47914791+ unsigned long vmaddr;47924792+ struct page *page;47934793+ kvm_pfn_t pfn;47944794+ int rc;47954795+47964796+ slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);47974797+ if (!slot || slot->flags & KVM_MEMSLOT_INVALID)47984798+ return vcpu_post_run_addressing_exception(vcpu);47994799+48004800+ fault_flags = flags & FOLL_WRITE ? FAULT_FLAG_WRITE : 0;48014801+ if (vcpu->arch.gmap->pfault_enabled)48024802+ flags |= FOLL_NOWAIT;48034803+ vmaddr = __gfn_to_hva_memslot(slot, gfn);48044804+48054805+try_again:48064806+ pfn = __kvm_faultin_pfn(slot, gfn, flags, &writable, &page);48074807+48084808+ /* Access outside memory, inject addressing exception */48094809+ if (is_noslot_pfn(pfn))48104810+ return vcpu_post_run_addressing_exception(vcpu);48114811+ /* Signal pending: try again */48124812+ if (pfn == KVM_PFN_ERR_SIGPENDING)48134813+ return -EAGAIN;48144814+48154815+ /* Needs I/O, try to setup async pfault (only possible with FOLL_NOWAIT) */48164816+ if (pfn == KVM_PFN_ERR_NEEDS_IO) {48174817+ trace_kvm_s390_major_guest_pfault(vcpu);48184818+ if (kvm_arch_setup_async_pf(vcpu))48194819+ return 0;48204820+ vcpu->stat.pfault_sync++;48214821+ /* Could not setup async pfault, try again synchronously */48224822+ flags &= ~FOLL_NOWAIT;48234823+ goto try_again;48244824+ }48254825+ /* Any other error */48264826+ if (is_error_pfn(pfn))48274827+ return -EFAULT;48284828+48294829+ /* Success */48304830+ mmap_read_lock(vcpu->arch.gmap->mm);48314831+ /* Mark the userspace PTEs as young and/or dirty, to avoid page fault loops */48324832+ rc = fixup_user_fault(vcpu->arch.gmap->mm, vmaddr, fault_flags, &unlocked);48334833+ if (!rc)48344834+ rc = __gmap_link(vcpu->arch.gmap, gaddr, vmaddr);48354835+ scoped_guard(spinlock, &vcpu->kvm->mmu_lock) {48364836+ kvm_release_faultin_page(vcpu->kvm, page, false, writable);48374837+ }48384838+ mmap_read_unlock(vcpu->arch.gmap->mm);48394839+ return rc;48404840+}48414841+48424842+static int vcpu_dat_fault_handler(struct kvm_vcpu *vcpu, unsigned long gaddr, unsigned int flags)48434843+{48444844+ unsigned long gaddr_tmp;48454845+ gfn_t gfn;48464846+48474847+ gfn = gpa_to_gfn(gaddr);48484848+ if (kvm_is_ucontrol(vcpu->kvm)) {48494849+ /*48504850+ * This translates the per-vCPU guest address into a48514851+ * fake guest address, which can then be used with the48524852+ * fake memslots that are identity mapping userspace.48534853+ * This allows ucontrol VMs to use the normal fault48544854+ * resolution path, like normal VMs.48554855+ */48564856+ mmap_read_lock(vcpu->arch.gmap->mm);48574857+ gaddr_tmp = __gmap_translate(vcpu->arch.gmap, gaddr);48584858+ mmap_read_unlock(vcpu->arch.gmap->mm);48594859+ if (gaddr_tmp == -EFAULT) {48604860+ vcpu->run->exit_reason = KVM_EXIT_S390_UCONTROL;48614861+ vcpu->run->s390_ucontrol.trans_exc_code = gaddr;48624862+ vcpu->run->s390_ucontrol.pgm_code = PGM_SEGMENT_TRANSLATION;48634863+ return -EREMOTE;48644864+ }48654865+ gfn = gpa_to_gfn(gaddr_tmp);48664866+ }48674867+ return __kvm_s390_handle_dat_fault(vcpu, gfn, gaddr, flags);48684868+}48694869+48504870static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)48514871{48524872 unsigned int flags = 0;48534873 unsigned long gaddr;48544854- int rc = 0;4855487448564875 gaddr = current->thread.gmap_teid.addr * PAGE_SIZE;48574876 if (kvm_s390_cur_gmap_fault_is_write())···49624781 vcpu->stat.exit_null++;49634782 break;49644783 case PGM_NON_SECURE_STORAGE_ACCESS:49654965- KVM_BUG(current->thread.gmap_teid.as != PSW_BITS_AS_PRIMARY, vcpu->kvm,49664966- "Unexpected program interrupt 0x%x, TEID 0x%016lx",49674967- current->thread.gmap_int_code, current->thread.gmap_teid.val);47844784+ kvm_s390_assert_primary_as(vcpu);49684785 /*49694786 * This is normal operation; a page belonging to a protected49704787 * guest has not been imported yet. Try to import the page into···49734794 break;49744795 case PGM_SECURE_STORAGE_ACCESS:49754796 case PGM_SECURE_STORAGE_VIOLATION:49764976- KVM_BUG(current->thread.gmap_teid.as != PSW_BITS_AS_PRIMARY, vcpu->kvm,49774977- "Unexpected program interrupt 0x%x, TEID 0x%016lx",49784978- current->thread.gmap_int_code, current->thread.gmap_teid.val);47974797+ kvm_s390_assert_primary_as(vcpu);49794798 /*49804799 * This can happen after a reboot with asynchronous teardown;49814800 * the new guest (normal or protected) will run on top of the···50024825 case PGM_REGION_FIRST_TRANS:50034826 case PGM_REGION_SECOND_TRANS:50044827 case PGM_REGION_THIRD_TRANS:50055005- KVM_BUG(current->thread.gmap_teid.as != PSW_BITS_AS_PRIMARY, vcpu->kvm,50065006- "Unexpected program interrupt 0x%x, TEID 0x%016lx",50075007- current->thread.gmap_int_code, current->thread.gmap_teid.val);50085008- if (vcpu->arch.gmap->pfault_enabled) {50095009- rc = gmap_fault(vcpu->arch.gmap, gaddr, flags | FAULT_FLAG_RETRY_NOWAIT);50105010- if (rc == -EFAULT)50115011- return vcpu_post_run_addressing_exception(vcpu);50125012- if (rc == -EAGAIN) {50135013- trace_kvm_s390_major_guest_pfault(vcpu);50145014- if (kvm_arch_setup_async_pf(vcpu))50155015- return 0;50165016- vcpu->stat.pfault_sync++;50175017- } else {50185018- return rc;50195019- }50205020- }50215021- rc = gmap_fault(vcpu->arch.gmap, gaddr, flags);50225022- if (rc == -EFAULT) {50235023- if (kvm_is_ucontrol(vcpu->kvm)) {50245024- vcpu->run->exit_reason = KVM_EXIT_S390_UCONTROL;50255025- vcpu->run->s390_ucontrol.trans_exc_code = gaddr;50265026- vcpu->run->s390_ucontrol.pgm_code = 0x10;50275027- return -EREMOTE;50285028- }50295029- return vcpu_post_run_addressing_exception(vcpu);50305030- }50315031- break;48284828+ kvm_s390_assert_primary_as(vcpu);48294829+ return vcpu_dat_fault_handler(vcpu, gaddr, flags);50324830 default:50334831 KVM_BUG(1, vcpu->kvm, "Unexpected program interrupt 0x%x, TEID 0x%016lx",50344832 current->thread.gmap_int_code, current->thread.gmap_teid.val);50354833 send_sig(SIGSEGV, current, 0);50364834 break;50374835 }50385038- return rc;48364836+ return 0;50394837}5040483850414839static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)···58895737 }58905738#endif58915739 case KVM_S390_VCPU_FAULT: {58925892- r = gmap_fault(vcpu->arch.gmap, arg, 0);57405740+ idx = srcu_read_lock(&vcpu->kvm->srcu);57415741+ r = vcpu_dat_fault_handler(vcpu, arg, 0);57425742+ srcu_read_unlock(&vcpu->kvm->srcu, idx);58935743 break;58945744 }58955745 case KVM_ENABLE_CAP:···60075853{60085854 gpa_t size;6009585560106010- if (kvm_is_ucontrol(kvm))58565856+ if (kvm_is_ucontrol(kvm) && new->id < KVM_USER_MEM_SLOTS)60115857 return -EINVAL;6012585860135859 /* When we are protected, we should not change the memory slots */···60585904 enum kvm_mr_change change)60595905{60605906 int rc = 0;59075907+59085908+ if (kvm_is_ucontrol(kvm))59095909+ return;6061591060625911 switch (change) {60635912 case KVM_MR_DELETE:
···1717#include <linux/sched/mm.h>1818#include <linux/mmu_notifier.h>1919#include "kvm-s390.h"2020+#include "gmap.h"20212122bool kvm_s390_pv_is_protected(struct kvm *kvm)2223{···639638 .tweak[1] = offset,640639 };641640 int ret = gmap_make_secure(kvm->arch.gmap, addr, &uvcb);641641+ unsigned long vmaddr;642642+ bool unlocked;642643643644 *rc = uvcb.header.rc;644645 *rrc = uvcb.header.rrc;646646+647647+ if (ret == -ENXIO) {648648+ mmap_read_lock(kvm->mm);649649+ vmaddr = gfn_to_hva(kvm, gpa_to_gfn(addr));650650+ if (kvm_is_error_hva(vmaddr)) {651651+ ret = -EFAULT;652652+ } else {653653+ ret = fixup_user_fault(kvm->mm, vmaddr, FAULT_FLAG_WRITE, &unlocked);654654+ if (!ret)655655+ ret = __gmap_link(kvm->arch.gmap, addr, vmaddr);656656+ }657657+ mmap_read_unlock(kvm->mm);658658+ if (!ret)659659+ return -EAGAIN;660660+ return ret;661661+ }645662646663 if (ret && ret != -EAGAIN)647664 KVM_UV_EVENT(kvm, 3, "PROTVIRT VM UNPACK: failed addr %llx with rc %x rrc %x",···678659679660 KVM_UV_EVENT(kvm, 3, "PROTVIRT VM UNPACK: start addr %lx size %lx",680661 addr, size);662662+663663+ guard(srcu)(&kvm->srcu);681664682665 while (offset < size) {683666 ret = unpack_one(kvm, addr, tweak, offset, rc, rrc);
+68-38
arch/s390/kvm/vsie.c
···1313#include <linux/bitmap.h>1414#include <linux/sched/signal.h>1515#include <linux/io.h>1616+#include <linux/mman.h>16171718#include <asm/gmap.h>1819#include <asm/mmu_context.h>···2322#include <asm/facility.h>2423#include "kvm-s390.h"2524#include "gaccess.h"2525+#include "gmap.h"2626+2727+enum vsie_page_flags {2828+ VSIE_PAGE_IN_USE = 0,2929+};26302731struct vsie_page {2832 struct kvm_s390_sie_block scb_s; /* 0x0000 */···5246 gpa_t gvrd_gpa; /* 0x0240 */5347 gpa_t riccbd_gpa; /* 0x0248 */5448 gpa_t sdnx_gpa; /* 0x0250 */5555- __u8 reserved[0x0700 - 0x0258]; /* 0x0258 */4949+ /*5050+ * guest address of the original SCB. Remains set for free vsie5151+ * pages, so we can properly look them up in our addr_to_page5252+ * radix tree.5353+ */5454+ gpa_t scb_gpa; /* 0x0258 */5555+ /*5656+ * Flags: must be set/cleared atomically after the vsie page can be5757+ * looked up by other CPUs.5858+ */5959+ unsigned long flags; /* 0x0260 */6060+ __u8 reserved[0x0700 - 0x0268]; /* 0x0268 */5661 struct kvm_s390_crypto_cb crycb; /* 0x0700 */5762 __u8 fac[S390_ARCH_FAC_LIST_SIZE_BYTE]; /* 0x0800 */5863};···601584 struct kvm *kvm = gmap->private;602585 struct vsie_page *cur;603586 unsigned long prefix;604604- struct page *page;605587 int i;606588607589 if (!gmap_is_shadow(gmap))···610594 * therefore we can safely reference them all the time.611595 */612596 for (i = 0; i < kvm->arch.vsie.page_count; i++) {613613- page = READ_ONCE(kvm->arch.vsie.pages[i]);614614- if (!page)597597+ cur = READ_ONCE(kvm->arch.vsie.pages[i]);598598+ if (!cur)615599 continue;616616- cur = page_to_virt(page);617600 if (READ_ONCE(cur->gmap) != gmap)618601 continue;619602 prefix = cur->scb_s.prefix << GUEST_PREFIX_SHIFT;···13601345 return rc;13611346}1362134713481348+/* Try getting a given vsie page, returning "true" on success. */13491349+static inline bool try_get_vsie_page(struct vsie_page *vsie_page)13501350+{13511351+ if (test_bit(VSIE_PAGE_IN_USE, &vsie_page->flags))13521352+ return false;13531353+ return !test_and_set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);13541354+}13551355+13561356+/* Put a vsie page acquired through get_vsie_page / try_get_vsie_page. */13571357+static void put_vsie_page(struct vsie_page *vsie_page)13581358+{13591359+ clear_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);13601360+}13611361+13631362/*13641363 * Get or create a vsie page for a scb address.13651364 *···13841355static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)13851356{13861357 struct vsie_page *vsie_page;13871387- struct page *page;13881358 int nr_vcpus;1389135913901360 rcu_read_lock();13911391- page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);13611361+ vsie_page = radix_tree_lookup(&kvm->arch.vsie.addr_to_page, addr >> 9);13921362 rcu_read_unlock();13931393- if (page) {13941394- if (page_ref_inc_return(page) == 2)13951395- return page_to_virt(page);13961396- page_ref_dec(page);13631363+ if (vsie_page) {13641364+ if (try_get_vsie_page(vsie_page)) {13651365+ if (vsie_page->scb_gpa == addr)13661366+ return vsie_page;13671367+ /*13681368+ * We raced with someone reusing + putting this vsie13691369+ * page before we grabbed it.13701370+ */13711371+ put_vsie_page(vsie_page);13721372+ }13971373 }1398137413991375 /*···1409137514101376 mutex_lock(&kvm->arch.vsie.mutex);14111377 if (kvm->arch.vsie.page_count < nr_vcpus) {14121412- page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);14131413- if (!page) {13781378+ vsie_page = (void *)__get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);13791379+ if (!vsie_page) {14141380 mutex_unlock(&kvm->arch.vsie.mutex);14151381 return ERR_PTR(-ENOMEM);14161382 }14171417- page_ref_inc(page);14181418- kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = page;13831383+ __set_bit(VSIE_PAGE_IN_USE, &vsie_page->flags);13841384+ kvm->arch.vsie.pages[kvm->arch.vsie.page_count] = vsie_page;14191385 kvm->arch.vsie.page_count++;14201386 } else {14211387 /* reuse an existing entry that belongs to nobody */14221388 while (true) {14231423- page = kvm->arch.vsie.pages[kvm->arch.vsie.next];14241424- if (page_ref_inc_return(page) == 2)13891389+ vsie_page = kvm->arch.vsie.pages[kvm->arch.vsie.next];13901390+ if (try_get_vsie_page(vsie_page))14251391 break;14261426- page_ref_dec(page);14271392 kvm->arch.vsie.next++;14281393 kvm->arch.vsie.next %= nr_vcpus;14291394 }14301430- radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);13951395+ if (vsie_page->scb_gpa != ULONG_MAX)13961396+ radix_tree_delete(&kvm->arch.vsie.addr_to_page,13971397+ vsie_page->scb_gpa >> 9);14311398 }14321432- page->index = addr;14331433- /* double use of the same address */14341434- if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9, page)) {14351435- page_ref_dec(page);13991399+ /* Mark it as invalid until it resides in the tree. */14001400+ vsie_page->scb_gpa = ULONG_MAX;14011401+14021402+ /* Double use of the same address or allocation failure. */14031403+ if (radix_tree_insert(&kvm->arch.vsie.addr_to_page, addr >> 9,14041404+ vsie_page)) {14051405+ put_vsie_page(vsie_page);14361406 mutex_unlock(&kvm->arch.vsie.mutex);14371407 return NULL;14381408 }14091409+ vsie_page->scb_gpa = addr;14391410 mutex_unlock(&kvm->arch.vsie.mutex);1440141114411441- vsie_page = page_to_virt(page);14421412 memset(&vsie_page->scb_s, 0, sizeof(struct kvm_s390_sie_block));14431413 release_gmap_shadow(vsie_page);14441414 vsie_page->fault_addr = 0;14451415 vsie_page->scb_s.ihcpu = 0xffffU;14461416 return vsie_page;14471447-}14481448-14491449-/* put a vsie page acquired via get_vsie_page */14501450-static void put_vsie_page(struct kvm *kvm, struct vsie_page *vsie_page)14511451-{14521452- struct page *page = pfn_to_page(__pa(vsie_page) >> PAGE_SHIFT);14531453-14541454- page_ref_dec(page);14551417}1456141814571419int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)···15001470out_unpin_scb:15011471 unpin_scb(vcpu, vsie_page, scb_addr);15021472out_put:15031503- put_vsie_page(vcpu->kvm, vsie_page);14731473+ put_vsie_page(vsie_page);1504147415051475 return rc < 0 ? rc : 0;15061476}···15161486void kvm_s390_vsie_destroy(struct kvm *kvm)15171487{15181488 struct vsie_page *vsie_page;15191519- struct page *page;15201489 int i;1521149015221491 mutex_lock(&kvm->arch.vsie.mutex);15231492 for (i = 0; i < kvm->arch.vsie.page_count; i++) {15241524- page = kvm->arch.vsie.pages[i];14931493+ vsie_page = kvm->arch.vsie.pages[i];15251494 kvm->arch.vsie.pages[i] = NULL;15261526- vsie_page = page_to_virt(page);15271495 release_gmap_shadow(vsie_page);15281496 /* free the radix tree entry */15291529- radix_tree_delete(&kvm->arch.vsie.addr_to_page, page->index >> 9);15301530- __free_page(page);14971497+ if (vsie_page->scb_gpa != ULONG_MAX)14981498+ radix_tree_delete(&kvm->arch.vsie.addr_to_page,14991499+ vsie_page->scb_gpa >> 9);15001500+ free_page((unsigned long)vsie_page);15311501 }15321502 kvm->arch.vsie.page_count = 0;15331503 mutex_unlock(&kvm->arch.vsie.mutex);
+150-531
arch/s390/mm/gmap.c
···2424#include <asm/page.h>2525#include <asm/tlb.h>26262727+/*2828+ * The address is saved in a radix tree directly; NULL would be ambiguous,2929+ * since 0 is a valid address, and NULL is returned when nothing was found.3030+ * The lower bits are ignored by all users of the macro, so it can be used3131+ * to distinguish a valid address 0 from a NULL.3232+ */3333+#define VALID_GADDR_FLAG 13434+#define IS_GADDR_VALID(gaddr) ((gaddr) & VALID_GADDR_FLAG)3535+#define MAKE_VALID_GADDR(gaddr) (((gaddr) & HPAGE_MASK) | VALID_GADDR_FLAG)3636+2737#define GMAP_SHADOW_FAKE_TABLE 1ULL28382939static struct page *gmap_alloc_crst(void)···5343 *5444 * Returns a guest address space structure.5545 */5656-static struct gmap *gmap_alloc(unsigned long limit)4646+struct gmap *gmap_alloc(unsigned long limit)5747{5848 struct gmap *gmap;5949 struct page *page;···8070 gmap = kzalloc(sizeof(struct gmap), GFP_KERNEL_ACCOUNT);8171 if (!gmap)8272 goto out;8383- INIT_LIST_HEAD(&gmap->crst_list);8473 INIT_LIST_HEAD(&gmap->children);8585- INIT_LIST_HEAD(&gmap->pt_list);8674 INIT_RADIX_TREE(&gmap->guest_to_host, GFP_KERNEL_ACCOUNT);8775 INIT_RADIX_TREE(&gmap->host_to_guest, GFP_ATOMIC | __GFP_ACCOUNT);8876 INIT_RADIX_TREE(&gmap->host_to_rmap, GFP_ATOMIC | __GFP_ACCOUNT);···9082 page = gmap_alloc_crst();9183 if (!page)9284 goto out_free;9393- page->index = 0;9494- list_add(&page->lru, &gmap->crst_list);9585 table = page_to_virt(page);9686 crst_table_init(table, etype);9787 gmap->table = table;···10397out:10498 return NULL;10599}100100+EXPORT_SYMBOL_GPL(gmap_alloc);106101107102/**108103 * gmap_create - create a guest address space···192185 } while (nr > 0);193186}194187188188+static void gmap_free_crst(unsigned long *table, bool free_ptes)189189+{190190+ bool is_segment = (table[0] & _SEGMENT_ENTRY_TYPE_MASK) == 0;191191+ int i;192192+193193+ if (is_segment) {194194+ if (!free_ptes)195195+ goto out;196196+ for (i = 0; i < _CRST_ENTRIES; i++)197197+ if (!(table[i] & _SEGMENT_ENTRY_INVALID))198198+ page_table_free_pgste(page_ptdesc(phys_to_page(table[i])));199199+ } else {200200+ for (i = 0; i < _CRST_ENTRIES; i++)201201+ if (!(table[i] & _REGION_ENTRY_INVALID))202202+ gmap_free_crst(__va(table[i] & PAGE_MASK), free_ptes);203203+ }204204+205205+out:206206+ free_pages((unsigned long)table, CRST_ALLOC_ORDER);207207+}208208+195209/**196210 * gmap_free - free a guest address space197211 * @gmap: pointer to the guest address space structure198212 *199213 * No locks required. There are no references to this gmap anymore.200214 */201201-static void gmap_free(struct gmap *gmap)215215+void gmap_free(struct gmap *gmap)202216{203203- struct page *page, *next;204204-205217 /* Flush tlb of all gmaps (if not already done for shadows) */206218 if (!(gmap_is_shadow(gmap) && gmap->removed))207219 gmap_flush_tlb(gmap);208220 /* Free all segment & region tables. */209209- list_for_each_entry_safe(page, next, &gmap->crst_list, lru)210210- __free_pages(page, CRST_ALLOC_ORDER);221221+ gmap_free_crst(gmap->table, gmap_is_shadow(gmap));222222+211223 gmap_radix_tree_free(&gmap->guest_to_host);212224 gmap_radix_tree_free(&gmap->host_to_guest);213225214226 /* Free additional data for a shadow gmap */215227 if (gmap_is_shadow(gmap)) {216216- struct ptdesc *ptdesc, *n;217217-218218- /* Free all page tables. */219219- list_for_each_entry_safe(ptdesc, n, &gmap->pt_list, pt_list)220220- page_table_free_pgste(ptdesc);221228 gmap_rmap_radix_tree_free(&gmap->host_to_rmap);222229 /* Release reference to the parent */223230 gmap_put(gmap->parent);···239218240219 kfree(gmap);241220}221221+EXPORT_SYMBOL_GPL(gmap_free);242222243223/**244224 * gmap_get - increase reference counter for guest address space···320298 crst_table_init(new, init);321299 spin_lock(&gmap->guest_table_lock);322300 if (*table & _REGION_ENTRY_INVALID) {323323- list_add(&page->lru, &gmap->crst_list);324301 *table = __pa(new) | _REGION_ENTRY_LENGTH |325302 (*table & _REGION_ENTRY_TYPE_MASK);326326- page->index = gaddr;327303 page = NULL;328304 }329305 spin_unlock(&gmap->guest_table_lock);···330310 return 0;331311}332312333333-/**334334- * __gmap_segment_gaddr - find virtual address from segment pointer335335- * @entry: pointer to a segment table entry in the guest address space336336- *337337- * Returns the virtual address in the guest address space for the segment338338- */339339-static unsigned long __gmap_segment_gaddr(unsigned long *entry)313313+static unsigned long host_to_guest_lookup(struct gmap *gmap, unsigned long vmaddr)340314{341341- struct page *page;342342- unsigned long offset;315315+ return (unsigned long)radix_tree_lookup(&gmap->host_to_guest, vmaddr >> PMD_SHIFT);316316+}343317344344- offset = (unsigned long) entry / sizeof(unsigned long);345345- offset = (offset & (PTRS_PER_PMD - 1)) * PMD_SIZE;346346- page = pmd_pgtable_page((pmd_t *) entry);347347- return page->index + offset;318318+static unsigned long host_to_guest_delete(struct gmap *gmap, unsigned long vmaddr)319319+{320320+ return (unsigned long)radix_tree_delete(&gmap->host_to_guest, vmaddr >> PMD_SHIFT);321321+}322322+323323+static pmd_t *host_to_guest_pmd_delete(struct gmap *gmap, unsigned long vmaddr,324324+ unsigned long *gaddr)325325+{326326+ *gaddr = host_to_guest_delete(gmap, vmaddr);327327+ if (IS_GADDR_VALID(*gaddr))328328+ return (pmd_t *)gmap_table_walk(gmap, *gaddr, 1);329329+ return NULL;348330}349331350332/**···358336 */359337static int __gmap_unlink_by_vmaddr(struct gmap *gmap, unsigned long vmaddr)360338{361361- unsigned long *entry;339339+ unsigned long gaddr;362340 int flush = 0;341341+ pmd_t *pmdp;363342364343 BUG_ON(gmap_is_shadow(gmap));365344 spin_lock(&gmap->guest_table_lock);366366- entry = radix_tree_delete(&gmap->host_to_guest, vmaddr >> PMD_SHIFT);367367- if (entry) {368368- flush = (*entry != _SEGMENT_ENTRY_EMPTY);369369- *entry = _SEGMENT_ENTRY_EMPTY;345345+346346+ pmdp = host_to_guest_pmd_delete(gmap, vmaddr, &gaddr);347347+ if (pmdp) {348348+ flush = (pmd_val(*pmdp) != _SEGMENT_ENTRY_EMPTY);349349+ *pmdp = __pmd(_SEGMENT_ENTRY_EMPTY);370350 }351351+371352 spin_unlock(&gmap->guest_table_lock);372353 return flush;373354}···489464EXPORT_SYMBOL_GPL(__gmap_translate);490465491466/**492492- * gmap_translate - translate a guest address to a user space address493493- * @gmap: pointer to guest mapping meta data structure494494- * @gaddr: guest address495495- *496496- * Returns user space address which corresponds to the guest address or497497- * -EFAULT if no such mapping exists.498498- * This function does not establish potentially missing page table entries.499499- */500500-unsigned long gmap_translate(struct gmap *gmap, unsigned long gaddr)501501-{502502- unsigned long rc;503503-504504- mmap_read_lock(gmap->mm);505505- rc = __gmap_translate(gmap, gaddr);506506- mmap_read_unlock(gmap->mm);507507- return rc;508508-}509509-EXPORT_SYMBOL_GPL(gmap_translate);510510-511511-/**512467 * gmap_unlink - disconnect a page table from the gmap shadow tables513468 * @mm: pointer to the parent mm_struct514469 * @table: pointer to the host page table···587582 spin_lock(&gmap->guest_table_lock);588583 if (*table == _SEGMENT_ENTRY_EMPTY) {589584 rc = radix_tree_insert(&gmap->host_to_guest,590590- vmaddr >> PMD_SHIFT, table);585585+ vmaddr >> PMD_SHIFT,586586+ (void *)MAKE_VALID_GADDR(gaddr));591587 if (!rc) {592588 if (pmd_leaf(*pmd)) {593589 *table = (pmd_val(*pmd) &···611605 radix_tree_preload_end();612606 return rc;613607}614614-615615-/**616616- * fixup_user_fault_nowait - manually resolve a user page fault without waiting617617- * @mm: mm_struct of target mm618618- * @address: user address619619- * @fault_flags:flags to pass down to handle_mm_fault()620620- * @unlocked: did we unlock the mmap_lock while retrying621621- *622622- * This function behaves similarly to fixup_user_fault(), but it guarantees623623- * that the fault will be resolved without waiting. The function might drop624624- * and re-acquire the mm lock, in which case @unlocked will be set to true.625625- *626626- * The guarantee is that the fault is handled without waiting, but the627627- * function itself might sleep, due to the lock.628628- *629629- * Context: Needs to be called with mm->mmap_lock held in read mode, and will630630- * return with the lock held in read mode; @unlocked will indicate whether631631- * the lock has been dropped and re-acquired. This is the same behaviour as632632- * fixup_user_fault().633633- *634634- * Return: 0 on success, -EAGAIN if the fault cannot be resolved without635635- * waiting, -EFAULT if the fault cannot be resolved, -ENOMEM if out of636636- * memory.637637- */638638-static int fixup_user_fault_nowait(struct mm_struct *mm, unsigned long address,639639- unsigned int fault_flags, bool *unlocked)640640-{641641- struct vm_area_struct *vma;642642- unsigned int test_flags;643643- vm_fault_t fault;644644- int rc;645645-646646- fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT;647647- test_flags = fault_flags & FAULT_FLAG_WRITE ? VM_WRITE : VM_READ;648648-649649- vma = find_vma(mm, address);650650- if (unlikely(!vma || address < vma->vm_start))651651- return -EFAULT;652652- if (unlikely(!(vma->vm_flags & test_flags)))653653- return -EFAULT;654654-655655- fault = handle_mm_fault(vma, address, fault_flags, NULL);656656- /* the mm lock has been dropped, take it again */657657- if (fault & VM_FAULT_COMPLETED) {658658- *unlocked = true;659659- mmap_read_lock(mm);660660- return 0;661661- }662662- /* the mm lock has not been dropped */663663- if (fault & VM_FAULT_ERROR) {664664- rc = vm_fault_to_errno(fault, 0);665665- BUG_ON(!rc);666666- return rc;667667- }668668- /* the mm lock has not been dropped because of FAULT_FLAG_RETRY_NOWAIT */669669- if (fault & VM_FAULT_RETRY)670670- return -EAGAIN;671671- /* nothing needed to be done and the mm lock has not been dropped */672672- return 0;673673-}674674-675675-/**676676- * __gmap_fault - resolve a fault on a guest address677677- * @gmap: pointer to guest mapping meta data structure678678- * @gaddr: guest address679679- * @fault_flags: flags to pass down to handle_mm_fault()680680- *681681- * Context: Needs to be called with mm->mmap_lock held in read mode. Might682682- * drop and re-acquire the lock. Will always return with the lock held.683683- */684684-static int __gmap_fault(struct gmap *gmap, unsigned long gaddr, unsigned int fault_flags)685685-{686686- unsigned long vmaddr;687687- bool unlocked;688688- int rc = 0;689689-690690-retry:691691- unlocked = false;692692-693693- vmaddr = __gmap_translate(gmap, gaddr);694694- if (IS_ERR_VALUE(vmaddr))695695- return vmaddr;696696-697697- if (fault_flags & FAULT_FLAG_RETRY_NOWAIT)698698- rc = fixup_user_fault_nowait(gmap->mm, vmaddr, fault_flags, &unlocked);699699- else700700- rc = fixup_user_fault(gmap->mm, vmaddr, fault_flags, &unlocked);701701- if (rc)702702- return rc;703703- /*704704- * In the case that fixup_user_fault unlocked the mmap_lock during705705- * fault-in, redo __gmap_translate() to avoid racing with a706706- * map/unmap_segment.707707- * In particular, __gmap_translate(), fixup_user_fault{,_nowait}(),708708- * and __gmap_link() must all be called atomically in one go; if the709709- * lock had been dropped in between, a retry is needed.710710- */711711- if (unlocked)712712- goto retry;713713-714714- return __gmap_link(gmap, gaddr, vmaddr);715715-}716716-717717-/**718718- * gmap_fault - resolve a fault on a guest address719719- * @gmap: pointer to guest mapping meta data structure720720- * @gaddr: guest address721721- * @fault_flags: flags to pass down to handle_mm_fault()722722- *723723- * Returns 0 on success, -ENOMEM for out of memory conditions, -EFAULT if the724724- * vm address is already mapped to a different guest segment, and -EAGAIN if725725- * FAULT_FLAG_RETRY_NOWAIT was specified and the fault could not be processed726726- * immediately.727727- */728728-int gmap_fault(struct gmap *gmap, unsigned long gaddr, unsigned int fault_flags)729729-{730730- int rc;731731-732732- mmap_read_lock(gmap->mm);733733- rc = __gmap_fault(gmap, gaddr, fault_flags);734734- mmap_read_unlock(gmap->mm);735735- return rc;736736-}737737-EXPORT_SYMBOL_GPL(gmap_fault);608608+EXPORT_SYMBOL(__gmap_link);738609739610/*740611 * this function is assumed to be called with mmap_lock held···736853 *737854 * Note: Can also be called for shadow gmaps.738855 */739739-static inline unsigned long *gmap_table_walk(struct gmap *gmap,740740- unsigned long gaddr, int level)856856+unsigned long *gmap_table_walk(struct gmap *gmap, unsigned long gaddr, int level)741857{742858 const int asce_type = gmap->asce & _ASCE_TYPE_MASK;743859 unsigned long *table = gmap->table;···787905 }788906 return table;789907}908908+EXPORT_SYMBOL(gmap_table_walk);790909791910/**792911 * gmap_pte_op_walk - walk the gmap page table, get the page table lock···9841101 * @prot: indicates access rights: PROT_NONE, PROT_READ or PROT_WRITE9851102 * @bits: pgste notification bits to set9861103 *987987- * Returns 0 if successfully protected, -ENOMEM if out of memory and988988- * -EFAULT if gaddr is invalid (or mapping for shadows is missing).11041104+ * Returns:11051105+ * PAGE_SIZE if a small page was successfully protected;11061106+ * HPAGE_SIZE if a large page was successfully protected;11071107+ * -ENOMEM if out of memory;11081108+ * -EFAULT if gaddr is invalid (or mapping for shadows is missing);11091109+ * -EAGAIN if the guest mapping is missing and should be fixed by the caller.9891110 *990990- * Called with sg->mm->mmap_lock in read.11111111+ * Context: Called with sg->mm->mmap_lock in read.9911112 */992992-static int gmap_protect_range(struct gmap *gmap, unsigned long gaddr,993993- unsigned long len, int prot, unsigned long bits)11131113+int gmap_protect_one(struct gmap *gmap, unsigned long gaddr, int prot, unsigned long bits)9941114{995995- unsigned long vmaddr, dist;9961115 pmd_t *pmdp;997997- int rc;11161116+ int rc = 0;99811179991118 BUG_ON(gmap_is_shadow(gmap));10001000- while (len) {10011001- rc = -EAGAIN;10021002- pmdp = gmap_pmd_op_walk(gmap, gaddr);10031003- if (pmdp) {10041004- if (!pmd_leaf(*pmdp)) {10051005- rc = gmap_protect_pte(gmap, gaddr, pmdp, prot,10061006- bits);10071007- if (!rc) {10081008- len -= PAGE_SIZE;10091009- gaddr += PAGE_SIZE;10101010- }10111011- } else {10121012- rc = gmap_protect_pmd(gmap, gaddr, pmdp, prot,10131013- bits);10141014- if (!rc) {10151015- dist = HPAGE_SIZE - (gaddr & ~HPAGE_MASK);10161016- len = len < dist ? 0 : len - dist;10171017- gaddr = (gaddr & HPAGE_MASK) + HPAGE_SIZE;10181018- }10191019- }10201020- gmap_pmd_op_end(gmap, pmdp);10211021- }10221022- if (rc) {10231023- if (rc == -EINVAL)10241024- return rc;1025111910261026- /* -EAGAIN, fixup of userspace mm and gmap */10271027- vmaddr = __gmap_translate(gmap, gaddr);10281028- if (IS_ERR_VALUE(vmaddr))10291029- return vmaddr;10301030- rc = gmap_pte_op_fixup(gmap, gaddr, vmaddr, prot);10311031- if (rc)10321032- return rc;10331033- }11201120+ pmdp = gmap_pmd_op_walk(gmap, gaddr);11211121+ if (!pmdp)11221122+ return -EAGAIN;11231123+11241124+ if (!pmd_leaf(*pmdp)) {11251125+ rc = gmap_protect_pte(gmap, gaddr, pmdp, prot, bits);11261126+ if (!rc)11271127+ rc = PAGE_SIZE;11281128+ } else {11291129+ rc = gmap_protect_pmd(gmap, gaddr, pmdp, prot, bits);11301130+ if (!rc)11311131+ rc = HPAGE_SIZE;10341132 }10351035- return 0;10361036-}11331133+ gmap_pmd_op_end(gmap, pmdp);1037113410381038-/**10391039- * gmap_mprotect_notify - change access rights for a range of ptes and10401040- * call the notifier if any pte changes again10411041- * @gmap: pointer to guest mapping meta data structure10421042- * @gaddr: virtual address in the guest address space10431043- * @len: size of area10441044- * @prot: indicates access rights: PROT_NONE, PROT_READ or PROT_WRITE10451045- *10461046- * Returns 0 if for each page in the given range a gmap mapping exists,10471047- * the new access rights could be set and the notifier could be armed.10481048- * If the gmap mapping is missing for one or more pages -EFAULT is10491049- * returned. If no memory could be allocated -ENOMEM is returned.10501050- * This function establishes missing page table entries.10511051- */10521052-int gmap_mprotect_notify(struct gmap *gmap, unsigned long gaddr,10531053- unsigned long len, int prot)10541054-{10551055- int rc;10561056-10571057- if ((gaddr & ~PAGE_MASK) || (len & ~PAGE_MASK) || gmap_is_shadow(gmap))10581058- return -EINVAL;10591059- if (!MACHINE_HAS_ESOP && prot == PROT_READ)10601060- return -EINVAL;10611061- mmap_read_lock(gmap->mm);10621062- rc = gmap_protect_range(gmap, gaddr, len, prot, GMAP_NOTIFY_MPROT);10631063- mmap_read_unlock(gmap->mm);10641135 return rc;10651136}10661066-EXPORT_SYMBOL_GPL(gmap_mprotect_notify);11371137+EXPORT_SYMBOL_GPL(gmap_protect_one);1067113810681139/**10691140 * gmap_read_table - get an unsigned long value from a guest page table using···12511414 __gmap_unshadow_pgt(sg, raddr, __va(pgt));12521415 /* Free page table */12531416 ptdesc = page_ptdesc(phys_to_page(pgt));12541254- list_del(&ptdesc->pt_list);12551417 page_table_free_pgste(ptdesc);12561418}12571419···12781442 __gmap_unshadow_pgt(sg, raddr, __va(pgt));12791443 /* Free page table */12801444 ptdesc = page_ptdesc(phys_to_page(pgt));12811281- list_del(&ptdesc->pt_list);12821445 page_table_free_pgste(ptdesc);12831446 }12841447}···13071472 __gmap_unshadow_sgt(sg, raddr, __va(sgt));13081473 /* Free segment table */13091474 page = phys_to_page(sgt);13101310- list_del(&page->lru);13111475 __free_pages(page, CRST_ALLOC_ORDER);13121476}13131477···13341500 __gmap_unshadow_sgt(sg, raddr, __va(sgt));13351501 /* Free segment table */13361502 page = phys_to_page(sgt);13371337- list_del(&page->lru);13381503 __free_pages(page, CRST_ALLOC_ORDER);13391504 }13401505}···13631530 __gmap_unshadow_r3t(sg, raddr, __va(r3t));13641531 /* Free region 3 table */13651532 page = phys_to_page(r3t);13661366- list_del(&page->lru);13671533 __free_pages(page, CRST_ALLOC_ORDER);13681534}13691535···13901558 __gmap_unshadow_r3t(sg, raddr, __va(r3t));13911559 /* Free region 3 table */13921560 page = phys_to_page(r3t);13931393- list_del(&page->lru);13941561 __free_pages(page, CRST_ALLOC_ORDER);13951562 }13961563}···14191588 __gmap_unshadow_r2t(sg, raddr, __va(r2t));14201589 /* Free region 2 table */14211590 page = phys_to_page(r2t);14221422- list_del(&page->lru);14231591 __free_pages(page, CRST_ALLOC_ORDER);14241592}14251593···14501620 r1t[i] = _REGION1_ENTRY_EMPTY;14511621 /* Free region 2 table */14521622 page = phys_to_page(r2t);14531453- list_del(&page->lru);14541623 __free_pages(page, CRST_ALLOC_ORDER);14551624 }14561625}···14601631 *14611632 * Called with sg->guest_table_lock14621633 */14631463-static void gmap_unshadow(struct gmap *sg)16341634+void gmap_unshadow(struct gmap *sg)14641635{14651636 unsigned long *table;14661637···14861657 break;14871658 }14881659}14891489-14901490-/**14911491- * gmap_find_shadow - find a specific asce in the list of shadow tables14921492- * @parent: pointer to the parent gmap14931493- * @asce: ASCE for which the shadow table is created14941494- * @edat_level: edat level to be used for the shadow translation14951495- *14961496- * Returns the pointer to a gmap if a shadow table with the given asce is14971497- * already available, ERR_PTR(-EAGAIN) if another one is just being created,14981498- * otherwise NULL14991499- */15001500-static struct gmap *gmap_find_shadow(struct gmap *parent, unsigned long asce,15011501- int edat_level)15021502-{15031503- struct gmap *sg;15041504-15051505- list_for_each_entry(sg, &parent->children, list) {15061506- if (sg->orig_asce != asce || sg->edat_level != edat_level ||15071507- sg->removed)15081508- continue;15091509- if (!sg->initialized)15101510- return ERR_PTR(-EAGAIN);15111511- refcount_inc(&sg->ref_count);15121512- return sg;15131513- }15141514- return NULL;15151515-}15161516-15171517-/**15181518- * gmap_shadow_valid - check if a shadow guest address space matches the15191519- * given properties and is still valid15201520- * @sg: pointer to the shadow guest address space structure15211521- * @asce: ASCE for which the shadow table is requested15221522- * @edat_level: edat level to be used for the shadow translation15231523- *15241524- * Returns 1 if the gmap shadow is still valid and matches the given15251525- * properties, the caller can continue using it. Returns 0 otherwise, the15261526- * caller has to request a new shadow gmap in this case.15271527- *15281528- */15291529-int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level)15301530-{15311531- if (sg->removed)15321532- return 0;15331533- return sg->orig_asce == asce && sg->edat_level == edat_level;15341534-}15351535-EXPORT_SYMBOL_GPL(gmap_shadow_valid);15361536-15371537-/**15381538- * gmap_shadow - create/find a shadow guest address space15391539- * @parent: pointer to the parent gmap15401540- * @asce: ASCE for which the shadow table is created15411541- * @edat_level: edat level to be used for the shadow translation15421542- *15431543- * The pages of the top level page table referred by the asce parameter15441544- * will be set to read-only and marked in the PGSTEs of the kvm process.15451545- * The shadow table will be removed automatically on any change to the15461546- * PTE mapping for the source table.15471547- *15481548- * Returns a guest address space structure, ERR_PTR(-ENOMEM) if out of memory,15491549- * ERR_PTR(-EAGAIN) if the caller has to retry and ERR_PTR(-EFAULT) if the15501550- * parent gmap table could not be protected.15511551- */15521552-struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,15531553- int edat_level)15541554-{15551555- struct gmap *sg, *new;15561556- unsigned long limit;15571557- int rc;15581558-15591559- BUG_ON(parent->mm->context.allow_gmap_hpage_1m);15601560- BUG_ON(gmap_is_shadow(parent));15611561- spin_lock(&parent->shadow_lock);15621562- sg = gmap_find_shadow(parent, asce, edat_level);15631563- spin_unlock(&parent->shadow_lock);15641564- if (sg)15651565- return sg;15661566- /* Create a new shadow gmap */15671567- limit = -1UL >> (33 - (((asce & _ASCE_TYPE_MASK) >> 2) * 11));15681568- if (asce & _ASCE_REAL_SPACE)15691569- limit = -1UL;15701570- new = gmap_alloc(limit);15711571- if (!new)15721572- return ERR_PTR(-ENOMEM);15731573- new->mm = parent->mm;15741574- new->parent = gmap_get(parent);15751575- new->private = parent->private;15761576- new->orig_asce = asce;15771577- new->edat_level = edat_level;15781578- new->initialized = false;15791579- spin_lock(&parent->shadow_lock);15801580- /* Recheck if another CPU created the same shadow */15811581- sg = gmap_find_shadow(parent, asce, edat_level);15821582- if (sg) {15831583- spin_unlock(&parent->shadow_lock);15841584- gmap_free(new);15851585- return sg;15861586- }15871587- if (asce & _ASCE_REAL_SPACE) {15881588- /* only allow one real-space gmap shadow */15891589- list_for_each_entry(sg, &parent->children, list) {15901590- if (sg->orig_asce & _ASCE_REAL_SPACE) {15911591- spin_lock(&sg->guest_table_lock);15921592- gmap_unshadow(sg);15931593- spin_unlock(&sg->guest_table_lock);15941594- list_del(&sg->list);15951595- gmap_put(sg);15961596- break;15971597- }15981598- }15991599- }16001600- refcount_set(&new->ref_count, 2);16011601- list_add(&new->list, &parent->children);16021602- if (asce & _ASCE_REAL_SPACE) {16031603- /* nothing to protect, return right away */16041604- new->initialized = true;16051605- spin_unlock(&parent->shadow_lock);16061606- return new;16071607- }16081608- spin_unlock(&parent->shadow_lock);16091609- /* protect after insertion, so it will get properly invalidated */16101610- mmap_read_lock(parent->mm);16111611- rc = gmap_protect_range(parent, asce & _ASCE_ORIGIN,16121612- ((asce & _ASCE_TABLE_LENGTH) + 1) * PAGE_SIZE,16131613- PROT_READ, GMAP_NOTIFY_SHADOW);16141614- mmap_read_unlock(parent->mm);16151615- spin_lock(&parent->shadow_lock);16161616- new->initialized = true;16171617- if (rc) {16181618- list_del(&new->list);16191619- gmap_free(new);16201620- new = ERR_PTR(rc);16211621- }16221622- spin_unlock(&parent->shadow_lock);16231623- return new;16241624-}16251625-EXPORT_SYMBOL_GPL(gmap_shadow);16601660+EXPORT_SYMBOL(gmap_unshadow);1626166116271662/**16281663 * gmap_shadow_r2t - create an empty shadow region 2 table···15201827 page = gmap_alloc_crst();15211828 if (!page)15221829 return -ENOMEM;15231523- page->index = r2t & _REGION_ENTRY_ORIGIN;15241524- if (fake)15251525- page->index |= GMAP_SHADOW_FAKE_TABLE;15261830 s_r2t = page_to_phys(page);15271831 /* Install shadow region second table */15281832 spin_lock(&sg->guest_table_lock);···15411851 _REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_INVALID;15421852 if (sg->edat_level >= 1)15431853 *table |= (r2t & _REGION_ENTRY_PROTECT);15441544- list_add(&page->lru, &sg->crst_list);15451854 if (fake) {15461855 /* nothing to protect for fake tables */15471856 *table &= ~_REGION_ENTRY_INVALID;···16001911 page = gmap_alloc_crst();16011912 if (!page)16021913 return -ENOMEM;16031603- page->index = r3t & _REGION_ENTRY_ORIGIN;16041604- if (fake)16051605- page->index |= GMAP_SHADOW_FAKE_TABLE;16061914 s_r3t = page_to_phys(page);16071915 /* Install shadow region second table */16081916 spin_lock(&sg->guest_table_lock);···16211935 _REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_INVALID;16221936 if (sg->edat_level >= 1)16231937 *table |= (r3t & _REGION_ENTRY_PROTECT);16241624- list_add(&page->lru, &sg->crst_list);16251938 if (fake) {16261939 /* nothing to protect for fake tables */16271940 *table &= ~_REGION_ENTRY_INVALID;···16801995 page = gmap_alloc_crst();16811996 if (!page)16821997 return -ENOMEM;16831683- page->index = sgt & _REGION_ENTRY_ORIGIN;16841684- if (fake)16851685- page->index |= GMAP_SHADOW_FAKE_TABLE;16861998 s_sgt = page_to_phys(page);16871999 /* Install shadow region second table */16882000 spin_lock(&sg->guest_table_lock);···17012019 _REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INVALID;17022020 if (sg->edat_level >= 1)17032021 *table |= sgt & _REGION_ENTRY_PROTECT;17041704- list_add(&page->lru, &sg->crst_list);17052022 if (fake) {17062023 /* nothing to protect for fake tables */17072024 *table &= ~_REGION_ENTRY_INVALID;···17332052}17342053EXPORT_SYMBOL_GPL(gmap_shadow_sgt);1735205417361736-/**17371737- * gmap_shadow_pgt_lookup - find a shadow page table17381738- * @sg: pointer to the shadow guest address space structure17391739- * @saddr: the address in the shadow aguest address space17401740- * @pgt: parent gmap address of the page table to get shadowed17411741- * @dat_protection: if the pgtable is marked as protected by dat17421742- * @fake: pgt references contiguous guest memory block, not a pgtable17431743- *17441744- * Returns 0 if the shadow page table was found and -EAGAIN if the page17451745- * table was not found.17461746- *17471747- * Called with sg->mm->mmap_lock in read.17481748- */17491749-int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,17501750- unsigned long *pgt, int *dat_protection,17511751- int *fake)20552055+static void gmap_pgste_set_pgt_addr(struct ptdesc *ptdesc, unsigned long pgt_addr)17522056{17531753- unsigned long *table;17541754- struct page *page;17551755- int rc;20572057+ unsigned long *pgstes = page_to_virt(ptdesc_page(ptdesc));1756205817571757- BUG_ON(!gmap_is_shadow(sg));17581758- spin_lock(&sg->guest_table_lock);17591759- table = gmap_table_walk(sg, saddr, 1); /* get segment pointer */17601760- if (table && !(*table & _SEGMENT_ENTRY_INVALID)) {17611761- /* Shadow page tables are full pages (pte+pgste) */17621762- page = pfn_to_page(*table >> PAGE_SHIFT);17631763- *pgt = page->index & ~GMAP_SHADOW_FAKE_TABLE;17641764- *dat_protection = !!(*table & _SEGMENT_ENTRY_PROTECT);17651765- *fake = !!(page->index & GMAP_SHADOW_FAKE_TABLE);17661766- rc = 0;17671767- } else {17681768- rc = -EAGAIN;17691769- }17701770- spin_unlock(&sg->guest_table_lock);17711771- return rc;20592059+ pgstes += _PAGE_ENTRIES;1772206020612061+ pgstes[0] &= ~PGSTE_ST2_MASK;20622062+ pgstes[1] &= ~PGSTE_ST2_MASK;20632063+ pgstes[2] &= ~PGSTE_ST2_MASK;20642064+ pgstes[3] &= ~PGSTE_ST2_MASK;20652065+20662066+ pgstes[0] |= (pgt_addr >> 16) & PGSTE_ST2_MASK;20672067+ pgstes[1] |= pgt_addr & PGSTE_ST2_MASK;20682068+ pgstes[2] |= (pgt_addr << 16) & PGSTE_ST2_MASK;20692069+ pgstes[3] |= (pgt_addr << 32) & PGSTE_ST2_MASK;17732070}17741774-EXPORT_SYMBOL_GPL(gmap_shadow_pgt_lookup);1775207117762072/**17772073 * gmap_shadow_pgt - instantiate a shadow page table···17772119 ptdesc = page_table_alloc_pgste(sg->mm);17782120 if (!ptdesc)17792121 return -ENOMEM;17801780- ptdesc->pt_index = pgt & _SEGMENT_ENTRY_ORIGIN;21222122+ origin = pgt & _SEGMENT_ENTRY_ORIGIN;17812123 if (fake)17821782- ptdesc->pt_index |= GMAP_SHADOW_FAKE_TABLE;21242124+ origin |= GMAP_SHADOW_FAKE_TABLE;21252125+ gmap_pgste_set_pgt_addr(ptdesc, origin);17832126 s_pgt = page_to_phys(ptdesc_page(ptdesc));17842127 /* Install shadow page table */17852128 spin_lock(&sg->guest_table_lock);···17992140 /* mark as invalid as long as the parent table is not protected */18002141 *table = (unsigned long) s_pgt | _SEGMENT_ENTRY |18012142 (pgt & _SEGMENT_ENTRY_PROTECT) | _SEGMENT_ENTRY_INVALID;18021802- list_add(&ptdesc->pt_list, &sg->pt_list);18032143 if (fake) {18042144 /* nothing to protect for fake tables */18052145 *table &= ~_SEGMENT_ENTRY_INVALID;···19762318 pte_t *pte, unsigned long bits)19772319{19782320 unsigned long offset, gaddr = 0;19791979- unsigned long *table;19802321 struct gmap *gmap, *sg, *next;1981232219822323 offset = ((unsigned long) pte) & (255 * sizeof(pte_t));···19832326 rcu_read_lock();19842327 list_for_each_entry_rcu(gmap, &mm->context.gmap_list, list) {19852328 spin_lock(&gmap->guest_table_lock);19861986- table = radix_tree_lookup(&gmap->host_to_guest,19871987- vmaddr >> PMD_SHIFT);19881988- if (table)19891989- gaddr = __gmap_segment_gaddr(table) + offset;23292329+ gaddr = host_to_guest_lookup(gmap, vmaddr) + offset;19902330 spin_unlock(&gmap->guest_table_lock);19911991- if (!table)23312331+ if (!IS_GADDR_VALID(gaddr))19922332 continue;1993233319942334 if (!list_empty(&gmap->children) && (bits & PGSTE_VSIE_BIT)) {···20452391 rcu_read_lock();20462392 list_for_each_entry_rcu(gmap, &mm->context.gmap_list, list) {20472393 spin_lock(&gmap->guest_table_lock);20482048- pmdp = (pmd_t *)radix_tree_delete(&gmap->host_to_guest,20492049- vmaddr >> PMD_SHIFT);23942394+ pmdp = host_to_guest_pmd_delete(gmap, vmaddr, &gaddr);20502395 if (pmdp) {20512051- gaddr = __gmap_segment_gaddr((unsigned long *)pmdp);20522396 pmdp_notify_gmap(gmap, pmdp, gaddr);20532397 WARN_ON(pmd_val(*pmdp) & ~(_SEGMENT_ENTRY_HARDWARE_BITS_LARGE |20542398 _SEGMENT_ENTRY_GMAP_UC |···20902438 */20912439void gmap_pmdp_idte_local(struct mm_struct *mm, unsigned long vmaddr)20922440{20932093- unsigned long *entry, gaddr;24412441+ unsigned long gaddr;20942442 struct gmap *gmap;20952443 pmd_t *pmdp;2096244420972445 rcu_read_lock();20982446 list_for_each_entry_rcu(gmap, &mm->context.gmap_list, list) {20992447 spin_lock(&gmap->guest_table_lock);21002100- entry = radix_tree_delete(&gmap->host_to_guest,21012101- vmaddr >> PMD_SHIFT);21022102- if (entry) {21032103- pmdp = (pmd_t *)entry;21042104- gaddr = __gmap_segment_gaddr(entry);24482448+ pmdp = host_to_guest_pmd_delete(gmap, vmaddr, &gaddr);24492449+ if (pmdp) {21052450 pmdp_notify_gmap(gmap, pmdp, gaddr);21062106- WARN_ON(*entry & ~(_SEGMENT_ENTRY_HARDWARE_BITS_LARGE |21072107- _SEGMENT_ENTRY_GMAP_UC |21082108- _SEGMENT_ENTRY));24512451+ WARN_ON(pmd_val(*pmdp) & ~(_SEGMENT_ENTRY_HARDWARE_BITS_LARGE |24522452+ _SEGMENT_ENTRY_GMAP_UC |24532453+ _SEGMENT_ENTRY));21092454 if (MACHINE_HAS_TLB_GUEST)21102455 __pmdp_idte(gaddr, pmdp, IDTE_GUEST_ASCE,21112456 gmap->asce, IDTE_LOCAL);21122457 else if (MACHINE_HAS_IDTE)21132458 __pmdp_idte(gaddr, pmdp, 0, 0, IDTE_LOCAL);21142114- *entry = _SEGMENT_ENTRY_EMPTY;24592459+ *pmdp = __pmd(_SEGMENT_ENTRY_EMPTY);21152460 }21162461 spin_unlock(&gmap->guest_table_lock);21172462 }···21232474 */21242475void gmap_pmdp_idte_global(struct mm_struct *mm, unsigned long vmaddr)21252476{21262126- unsigned long *entry, gaddr;24772477+ unsigned long gaddr;21272478 struct gmap *gmap;21282479 pmd_t *pmdp;2129248021302481 rcu_read_lock();21312482 list_for_each_entry_rcu(gmap, &mm->context.gmap_list, list) {21322483 spin_lock(&gmap->guest_table_lock);21332133- entry = radix_tree_delete(&gmap->host_to_guest,21342134- vmaddr >> PMD_SHIFT);21352135- if (entry) {21362136- pmdp = (pmd_t *)entry;21372137- gaddr = __gmap_segment_gaddr(entry);24842484+ pmdp = host_to_guest_pmd_delete(gmap, vmaddr, &gaddr);24852485+ if (pmdp) {21382486 pmdp_notify_gmap(gmap, pmdp, gaddr);21392139- WARN_ON(*entry & ~(_SEGMENT_ENTRY_HARDWARE_BITS_LARGE |21402140- _SEGMENT_ENTRY_GMAP_UC |21412141- _SEGMENT_ENTRY));24872487+ WARN_ON(pmd_val(*pmdp) & ~(_SEGMENT_ENTRY_HARDWARE_BITS_LARGE |24882488+ _SEGMENT_ENTRY_GMAP_UC |24892489+ _SEGMENT_ENTRY));21422490 if (MACHINE_HAS_TLB_GUEST)21432491 __pmdp_idte(gaddr, pmdp, IDTE_GUEST_ASCE,21442492 gmap->asce, IDTE_GLOBAL);···21432497 __pmdp_idte(gaddr, pmdp, 0, 0, IDTE_GLOBAL);21442498 else21452499 __pmdp_csp(pmdp);21462146- *entry = _SEGMENT_ENTRY_EMPTY;25002500+ *pmdp = __pmd(_SEGMENT_ENTRY_EMPTY);21472501 }21482502 spin_unlock(&gmap->guest_table_lock);21492503 }···25892943EXPORT_SYMBOL_GPL(__s390_uv_destroy_range);2590294425912945/**25922592- * s390_unlist_old_asce - Remove the topmost level of page tables from the25932593- * list of page tables of the gmap.25942594- * @gmap: the gmap whose table is to be removed25952595- *25962596- * On s390x, KVM keeps a list of all pages containing the page tables of the25972597- * gmap (the CRST list). This list is used at tear down time to free all25982598- * pages that are now not needed anymore.25992599- *26002600- * This function removes the topmost page of the tree (the one pointed to by26012601- * the ASCE) from the CRST list.26022602- *26032603- * This means that it will not be freed when the VM is torn down, and needs26042604- * to be handled separately by the caller, unless a leak is actually26052605- * intended. Notice that this function will only remove the page from the26062606- * list, the page will still be used as a top level page table (and ASCE).26072607- */26082608-void s390_unlist_old_asce(struct gmap *gmap)26092609-{26102610- struct page *old;26112611-26122612- old = virt_to_page(gmap->table);26132613- spin_lock(&gmap->guest_table_lock);26142614- list_del(&old->lru);26152615- /*26162616- * Sometimes the topmost page might need to be "removed" multiple26172617- * times, for example if the VM is rebooted into secure mode several26182618- * times concurrently, or if s390_replace_asce fails after calling26192619- * s390_remove_old_asce and is attempted again later. In that case26202620- * the old asce has been removed from the list, and therefore it26212621- * will not be freed when the VM terminates, but the ASCE is still26222622- * in use and still pointed to.26232623- * A subsequent call to replace_asce will follow the pointer and try26242624- * to remove the same page from the list again.26252625- * Therefore it's necessary that the page of the ASCE has valid26262626- * pointers, so list_del can work (and do nothing) without26272627- * dereferencing stale or invalid pointers.26282628- */26292629- INIT_LIST_HEAD(&old->lru);26302630- spin_unlock(&gmap->guest_table_lock);26312631-}26322632-EXPORT_SYMBOL_GPL(s390_unlist_old_asce);26332633-26342634-/**26352946 * s390_replace_asce - Try to replace the current ASCE of a gmap with a copy26362947 * @gmap: the gmap whose ASCE needs to be replaced26372948 *···26073004 struct page *page;26083005 void *table;2609300626102610- s390_unlist_old_asce(gmap);26112611-26123007 /* Replacing segment type ASCEs would cause serious issues */26133008 if ((gmap->asce & _ASCE_TYPE_MASK) == _ASCE_TYPE_SEGMENT)26143009 return -EINVAL;···26143013 page = gmap_alloc_crst();26153014 if (!page)26163015 return -ENOMEM;26172617- page->index = 0;26183016 table = page_to_virt(page);26193017 memcpy(table, gmap->table, 1UL << (CRST_ALLOC_ORDER + PAGE_SHIFT));26202620-26212621- /*26222622- * The caller has to deal with the old ASCE, but here we make sure26232623- * the new one is properly added to the CRST list, so that26242624- * it will be freed when the VM is torn down.26252625- */26262626- spin_lock(&gmap->guest_table_lock);26272627- list_add(&page->lru, &gmap->crst_list);26282628- spin_unlock(&gmap->guest_table_lock);2629301826303019 /* Set new table origin while preserving existing ASCE control bits */26313020 asce = (gmap->asce & ~_ASCE_ORIGIN) | __pa(table);···26263035 return 0;26273036}26283037EXPORT_SYMBOL_GPL(s390_replace_asce);30383038+30393039+/**30403040+ * kvm_s390_wiggle_split_folio() - try to drain extra references to a folio and optionally split30413041+ * @mm: the mm containing the folio to work on30423042+ * @folio: the folio30433043+ * @split: whether to split a large folio30443044+ *30453045+ * Context: Must be called while holding an extra reference to the folio;30463046+ * the mm lock should not be held.30473047+ */30483048+int kvm_s390_wiggle_split_folio(struct mm_struct *mm, struct folio *folio, bool split)30493049+{30503050+ int rc;30513051+30523052+ lockdep_assert_not_held(&mm->mmap_lock);30533053+ folio_wait_writeback(folio);30543054+ lru_add_drain_all();30553055+ if (split) {30563056+ folio_lock(folio);30573057+ rc = split_folio(folio);30583058+ folio_unlock(folio);30593059+30603060+ if (rc != -EBUSY)30613061+ return rc;30623062+ }30633063+ return -EAGAIN;30643064+}30653065+EXPORT_SYMBOL_GPL(kvm_s390_wiggle_split_folio);
-2
arch/s390/mm/pgalloc.c
···176176 }177177 table = ptdesc_to_virt(ptdesc);178178 __arch_set_page_dat(table, 1);179179- /* pt_list is used by gmap only */180180- INIT_LIST_HEAD(&ptdesc->pt_list);181179 memset64((u64 *)table, _PAGE_INVALID, PTRS_PER_PTE);182180 memset64((u64 *)table + PTRS_PER_PTE, 0, PTRS_PER_PTE);183181 return table;
+2-1
arch/x86/Kconfig
···25992599 depends on CPU_SUP_AMD && X86_6426002600 default y26012601 help26022602- Compile the kernel with support for the retbleed=ibpb mitigation.26022602+ Compile the kernel with support for the retbleed=ibpb and26032603+ spec_rstack_overflow={ibpb,ibpb-vmexit} mitigations.2603260426042605config MITIGATION_IBRS_ENTRY26052606 bool "Enable IBRS on kernel entry"
+1
arch/x86/boot/compressed/Makefile
···2525# avoid errors with '-march=i386', and future flags may depend on the target to2626# be valid.2727KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)2828+KBUILD_CFLAGS += -std=gnu112829KBUILD_CFLAGS += -fno-strict-aliasing -fPIE2930KBUILD_CFLAGS += -Wundef3031KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
+14-7
arch/x86/kernel/cpu/bugs.c
···1115111511161116 case RETBLEED_MITIGATION_IBPB:11171117 setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);11181118+ setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);11191119+ mitigate_smt = true;1118112011191121 /*11201122 * IBPB on entry already obviates the need for···11251123 */11261124 setup_clear_cpu_cap(X86_FEATURE_UNRET);11271125 setup_clear_cpu_cap(X86_FEATURE_RETHUNK);11281128-11291129- setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);11301130- mitigate_smt = true;1131112611321127 /*11331128 * There is no need for RSB filling: entry_ibpb() ensures···26452646 if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY)) {26462647 if (has_microcode) {26472648 setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);26492649+ setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);26482650 srso_mitigation = SRSO_MITIGATION_IBPB;2649265126502652 /*···26552655 */26562656 setup_clear_cpu_cap(X86_FEATURE_UNRET);26572657 setup_clear_cpu_cap(X86_FEATURE_RETHUNK);26582658+26592659+ /*26602660+ * There is no need for RSB filling: entry_ibpb() ensures26612661+ * all predictions, including the RSB, are invalidated,26622662+ * regardless of IBPB implementation.26632663+ */26642664+ setup_clear_cpu_cap(X86_FEATURE_RSB_VMEXIT);26582665 }26592666 } else {26602667 pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");···2670266326712664ibpb_on_vmexit:26722665 case SRSO_CMD_IBPB_ON_VMEXIT:26732673- if (IS_ENABLED(CONFIG_MITIGATION_SRSO)) {26742674- if (!boot_cpu_has(X86_FEATURE_ENTRY_IBPB) && has_microcode) {26662666+ if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY)) {26672667+ if (has_microcode) {26752668 setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);26762669 srso_mitigation = SRSO_MITIGATION_IBPB_ON_VMEXIT;26772670···26832676 setup_clear_cpu_cap(X86_FEATURE_RSB_VMEXIT);26842677 }26852678 } else {26862686- pr_err("WARNING: kernel not compiled with MITIGATION_SRSO.\n");26872687- }26792679+ pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");26802680+ }26882681 break;26892682 default:26902683 break;
···71207120 kmem_cache_destroy(mmu_page_header_cache);71217121}7122712271237123+static void kvm_wake_nx_recovery_thread(struct kvm *kvm)71247124+{71257125+ /*71267126+ * The NX recovery thread is spawned on-demand at the first KVM_RUN and71277127+ * may not be valid even though the VM is globally visible. Do nothing,71287128+ * as such a VM can't have any possible NX huge pages.71297129+ */71307130+ struct vhost_task *nx_thread = READ_ONCE(kvm->arch.nx_huge_page_recovery_thread);71317131+71327132+ if (nx_thread)71337133+ vhost_task_wake(nx_thread);71347134+}71357135+71237136static int get_nx_huge_pages(char *buffer, const struct kernel_param *kp)71247137{71257138 if (nx_hugepage_mitigation_hard_disabled)···71937180 kvm_mmu_zap_all_fast(kvm);71947181 mutex_unlock(&kvm->slots_lock);7195718271967196- vhost_task_wake(kvm->arch.nx_huge_page_recovery_thread);71837183+ kvm_wake_nx_recovery_thread(kvm);71977184 }71987185 mutex_unlock(&kvm_lock);71997186 }···73287315 mutex_lock(&kvm_lock);7329731673307317 list_for_each_entry(kvm, &vm_list, vm_list)73317331- vhost_task_wake(kvm->arch.nx_huge_page_recovery_thread);73187318+ kvm_wake_nx_recovery_thread(kvm);7332731973337320 mutex_unlock(&kvm_lock);73347321 }···74647451{74657452 struct kvm_arch *ka = container_of(once, struct kvm_arch, nx_once);74667453 struct kvm *kvm = container_of(ka, struct kvm, arch);74547454+ struct vhost_task *nx_thread;7467745574687456 kvm->arch.nx_huge_page_last = get_jiffies_64();74697469- kvm->arch.nx_huge_page_recovery_thread = vhost_task_create(74707470- kvm_nx_huge_page_recovery_worker, kvm_nx_huge_page_recovery_worker_kill,74717471- kvm, "kvm-nx-lpage-recovery");74577457+ nx_thread = vhost_task_create(kvm_nx_huge_page_recovery_worker,74587458+ kvm_nx_huge_page_recovery_worker_kill,74597459+ kvm, "kvm-nx-lpage-recovery");7472746074737473- if (kvm->arch.nx_huge_page_recovery_thread)74747474- vhost_task_start(kvm->arch.nx_huge_page_recovery_thread);74617461+ if (!nx_thread)74627462+ return;74637463+74647464+ vhost_task_start(nx_thread);74657465+74667466+ /* Make the task visible only once it is fully started. */74677467+ WRITE_ONCE(kvm->arch.nx_huge_page_recovery_thread, nx_thread);74757468}7476746974777470int kvm_mmu_post_init_vm(struct kvm *kvm)
···100100 push %r10101101 push %r9102102 push %r8103103-#ifdef CONFIG_FRAME_POINTER104104- pushq $0 /* Dummy push for stack alignment. */105105-#endif106103#endif107104 /* Set the vendor specific function. */108105 call __xen_hypercall_setfunc···114117 pop %ebx115118 pop %eax116119#else117117- lea xen_hypercall_amd(%rip), %rbx118118- cmp %rax, %rbx119119-#ifdef CONFIG_FRAME_POINTER120120- pop %rax /* Dummy pop. */121121-#endif120120+ lea xen_hypercall_amd(%rip), %rcx121121+ cmp %rax, %rcx122122 pop %r8123123 pop %r9124124 pop %r10···126132 pop %rcx127133 pop %rax128134#endif135135+ FRAME_END129136 /* Use correct hypercall function. */130137 jz xen_hypercall_amd131138 jmp xen_hypercall_intel
+5
drivers/accel/amdxdna/amdxdna_pci_drv.c
···21212222#define AMDXDNA_AUTOSUSPEND_DELAY 5000 /* milliseconds */23232424+MODULE_FIRMWARE("amdnpu/1502_00/npu.sbin");2525+MODULE_FIRMWARE("amdnpu/17f0_10/npu.sbin");2626+MODULE_FIRMWARE("amdnpu/17f0_11/npu.sbin");2727+MODULE_FIRMWARE("amdnpu/17f0_20/npu.sbin");2828+2429/*2530 * Bind the driver base on (vendor_id, device_id) pair and later use the2631 * (device_id, rev_id) pair as a key to select the devices. The devices with
+6-2
drivers/accel/ivpu/ivpu_drv.c
···397397 if (ivpu_fw_is_cold_boot(vdev)) {398398 ret = ivpu_pm_dct_init(vdev);399399 if (ret)400400- goto err_diagnose_failure;400400+ goto err_disable_ipc;401401402402 ret = ivpu_hw_sched_init(vdev);403403 if (ret)404404- goto err_diagnose_failure;404404+ goto err_disable_ipc;405405 }406406407407 return 0;408408409409+err_disable_ipc:410410+ ivpu_ipc_disable(vdev);411411+ ivpu_hw_irq_disable(vdev);412412+ disable_irq(vdev->irq);409413err_diagnose_failure:410414 ivpu_hw_diagnose_failure(vdev);411415 ivpu_mmu_evtq_dump(vdev);
···17171818config ARM_AIROHA_SOC_CPUFREQ1919 tristate "Airoha EN7581 SoC CPUFreq support"2020- depends on (ARCH_AIROHA && OF) || COMPILE_TEST2020+ depends on ARCH_AIROHA || COMPILE_TEST2121+ depends on OF2122 select PM_OPP2223 default ARCH_AIROHA2324 help
+10-10
drivers/cpufreq/amd-pstate.c
···699699 if (min_perf < lowest_nonlinear_perf)700700 min_perf = lowest_nonlinear_perf;701701702702- max_perf = cap_perf;702702+ max_perf = cpudata->max_limit_perf;703703 if (max_perf < min_perf)704704 max_perf = min_perf;705705···747747 guard(mutex)(&amd_pstate_driver_lock);748748749749 ret = amd_pstate_cpu_boost_update(policy, state);750750- policy->boost_enabled = !ret ? state : false;751750 refresh_frequency_limits(policy);752751753752 return ret;···821822822823static void amd_pstate_update_limits(unsigned int cpu)823824{824824- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);825825+ struct cpufreq_policy *policy = NULL;825826 struct amd_cpudata *cpudata;826827 u32 prev_high = 0, cur_high = 0;827828 int ret;828829 bool highest_perf_changed = false;829830831831+ if (!amd_pstate_prefcore)832832+ return;833833+834834+ policy = cpufreq_cpu_get(cpu);830835 if (!policy)831836 return;832837833838 cpudata = policy->driver_data;834839835835- if (!amd_pstate_prefcore)836836- return;837837-838840 guard(mutex)(&amd_pstate_driver_lock);839841840842 ret = amd_get_highest_perf(cpu, &cur_high);841841- if (ret)842842- goto free_cpufreq_put;843843+ if (ret) {844844+ cpufreq_cpu_put(policy);845845+ return;846846+ }843847844848 prev_high = READ_ONCE(cpudata->prefcore_ranking);845849 highest_perf_changed = (prev_high != cur_high);···852850 if (cur_high < CPPC_MAX_PERF)853851 sched_set_itmt_core_prio((int)cur_high, cpu);854852 }855855-856856-free_cpufreq_put:857853 cpufreq_cpu_put(policy);858854859855 if (!highest_perf_changed)
+2-1
drivers/cpufreq/cpufreq.c
···15711571 policy->cdev = of_cpufreq_cooling_register(policy);1572157215731573 /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */15741574- if (policy->boost_enabled != cpufreq_boost_enabled()) {15741574+ if (cpufreq_driver->set_boost &&15751575+ policy->boost_enabled != cpufreq_boost_enabled()) {15751576 policy->boost_enabled = cpufreq_boost_enabled();15761577 ret = cpufreq_driver->set_boost(policy, policy->boost_enabled);15771578 if (ret) {
+1-1
drivers/firmware/Kconfig
···106106 select ISCSI_BOOT_SYSFS107107 select ISCSI_IBFT_FIND if X86108108 depends on ACPI && SCSI && SCSI_LOWLEVEL109109- default n109109+ default n110110 help111111 This option enables support for detection and exposing of iSCSI112112 Boot Firmware Table (iBFT) via sysfs to userspace. If you wish to
+4-1
drivers/firmware/iscsi_ibft.c
···310310 str += sprintf_ipaddr(str, nic->ip_addr);311311 break;312312 case ISCSI_BOOT_ETH_SUBNET_MASK:313313- val = cpu_to_be32(~((1 << (32-nic->subnet_mask_prefix))-1));313313+ if (nic->subnet_mask_prefix > 32)314314+ val = cpu_to_be32(~0);315315+ else316316+ val = cpu_to_be32(~((1 << (32-nic->subnet_mask_prefix))-1));314317 str += sprintf(str, "%pI4", &val);315318 break;316319 case ISCSI_BOOT_ETH_PREFIX_LEN:
+1
drivers/gpio/Kconfig
···338338339339config GPIO_GRGPIO340340 tristate "Aeroflex Gaisler GRGPIO support"341341+ depends on OF || COMPILE_TEST341342 select GPIO_GENERIC342343 select IRQ_DOMAIN343344 help
-19
drivers/gpio/gpio-pca953x.c
···841841 DECLARE_BITMAP(trigger, MAX_LINE);842842 int ret;843843844844- if (chip->driver_data & PCA_PCAL) {845845- /* Read the current interrupt status from the device */846846- ret = pca953x_read_regs(chip, PCAL953X_INT_STAT, trigger);847847- if (ret)848848- return false;849849-850850- /* Check latched inputs and clear interrupt status */851851- ret = pca953x_read_regs(chip, chip->regs->input, cur_stat);852852- if (ret)853853- return false;854854-855855- /* Apply filter for rising/falling edge selection */856856- bitmap_replace(new_stat, chip->irq_trig_fall, chip->irq_trig_raise, cur_stat, gc->ngpio);857857-858858- bitmap_and(pending, new_stat, trigger, gc->ngpio);859859-860860- return !bitmap_empty(pending, gc->ngpio);861861- }862862-863844 ret = pca953x_read_regs(chip, chip->regs->input, cur_stat);864845 if (ret)865846 return false;
+8-5
drivers/gpio/gpio-sim.c
···10281028 struct configfs_subsystem *subsys = dev->group.cg_subsys;10291029 struct gpio_sim_bank *bank;10301030 struct gpio_sim_line *line;10311031+ struct config_item *item;1031103210321033 /*10331033- * The device only needs to depend on leaf line entries. This is10341034+ * The device only needs to depend on leaf entries. This is10341035 * sufficient to lock up all the configfs entries that the10351036 * instantiated, alive device depends on.10361037 */10371038 list_for_each_entry(bank, &dev->bank_list, siblings) {10381039 list_for_each_entry(line, &bank->line_list, siblings) {10401040+ item = line->hog ? &line->hog->item10411041+ : &line->group.cg_item;10421042+10391043 if (lock)10401040- WARN_ON(configfs_depend_item_unlocked(10411041- subsys, &line->group.cg_item));10441044+ WARN_ON(configfs_depend_item_unlocked(subsys,10451045+ item));10421046 else10431043- configfs_undepend_item_unlocked(10441044- &line->group.cg_item);10471047+ configfs_undepend_item_unlocked(item);10451048 }10461049 }10471050}
···2133213321342134 dc_enable_stereo(dc, context, dc_streams, context->stream_count);2135213521362136- if (context->stream_count > get_seamless_boot_stream_count(context) ||21362136+ if (get_seamless_boot_stream_count(context) == 0 ||21372137 context->stream_count == 0) {21382138 /* Must wait for no flips to be pending before doing optimize bw */21392139 hwss_wait_for_no_pipes_pending(dc, context);
···195195 if (enabled)196196 vgacrdf_test |= AST_IO_VGACRDF_DP_VIDEO_ENABLE;197197198198- for (i = 0; i < 200; ++i) {198198+ for (i = 0; i < 1000; ++i) {199199 if (i)200200 mdelay(1);201201 vgacrdf = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xdf,
+3-11
drivers/gpu/drm/display/drm_dp_cec.c
···311311 if (!aux->transfer)312312 return;313313314314-#ifndef CONFIG_MEDIA_CEC_RC315315- /*316316- * CEC_CAP_RC is part of CEC_CAP_DEFAULTS, but it is stripped by317317- * cec_allocate_adapter() if CONFIG_MEDIA_CEC_RC is undefined.318318- *319319- * Do this here as well to ensure the tests against cec_caps are320320- * correct.321321- */322322- cec_caps &= ~CEC_CAP_RC;323323-#endif324314 cancel_delayed_work_sync(&aux->cec.unregister_work);325315326316 mutex_lock(&aux->cec.lock);···327337 num_las = CEC_MAX_LOG_ADDRS;328338329339 if (aux->cec.adap) {330330- if (aux->cec.adap->capabilities == cec_caps &&340340+ /* Check if the adapter properties have changed */341341+ if ((aux->cec.adap->capabilities & CEC_CAP_MONITOR_ALL) ==342342+ (cec_caps & CEC_CAP_MONITOR_ALL) &&331343 aux->cec.adap->available_log_addrs == num_las) {332344 /* Unchanged, so just set the phys addr */333345 cec_s_phys_addr(aux->cec.adap, source_physical_address, false);
···119119 drm_puts(&p, "\n**** GuC CT ****\n");120120 xe_guc_ct_snapshot_print(ss->guc.ct, &p);121121122122- /*123123- * Don't add a new section header here because the mesa debug decoder124124- * tool expects the context information to be in the 'GuC CT' section.125125- */126126- /* drm_puts(&p, "\n**** Contexts ****\n"); */122122+ drm_puts(&p, "\n**** Contexts ****\n");127123 xe_guc_exec_queue_snapshot_print(ss->ge, &p);128124129125 drm_puts(&p, "\n**** Job ****\n");···391395/**392396 * xe_print_blob_ascii85 - print a BLOB to some useful location in ASCII85393397 *394394- * The output is split to multiple lines because some print targets, e.g. dmesg395395- * cannot handle arbitrarily long lines. Note also that printing to dmesg in396396- * piece-meal fashion is not possible, each separate call to drm_puts() has a397397- * line-feed automatically added! Therefore, the entire output line must be398398- * constructed in a local buffer first, then printed in one atomic output call.398398+ * The output is split into multiple calls to drm_puts() because some print399399+ * targets, e.g. dmesg, cannot handle arbitrarily long lines. These targets may400400+ * add newlines, as is the case with dmesg: each drm_puts() call creates a401401+ * separate line.399402 *400403 * There is also a scheduler yield call to prevent the 'task has been stuck for401404 * 120s' kernel hang check feature from firing when printing to a slow target402405 * such as dmesg over a serial port.403406 *404404- * TODO: Add compression prior to the ASCII85 encoding to shrink huge buffers down.405405- *406407 * @p: the printer object to output to407408 * @prefix: optional prefix to add to output string409409+ * @suffix: optional suffix to add at the end. 0 disables it and is410410+ * not added to the output, which is useful when using multiple calls411411+ * to dump data to @p408412 * @blob: the Binary Large OBject to dump out409413 * @offset: offset in bytes to skip from the front of the BLOB, must be a multiple of sizeof(u32)410414 * @size: the size in bytes of the BLOB, must be a multiple of sizeof(u32)411415 */412412-void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix,416416+void xe_print_blob_ascii85(struct drm_printer *p, const char *prefix, char suffix,413417 const void *blob, size_t offset, size_t size)414418{415419 const u32 *blob32 = (const u32 *)blob;416420 char buff[ASCII85_BUFSZ], *line_buff;417421 size_t line_pos = 0;418422419419- /*420420- * Splitting blobs across multiple lines is not compatible with the mesa421421- * debug decoder tool. Note that even dropping the explicit '\n' below422422- * doesn't help because the GuC log is so big some underlying implementation423423- * still splits the lines at 512K characters. So just bail completely for424424- * the moment.425425- */426426- return;427427-428423#define DMESG_MAX_LINE_LEN 800429429-#define MIN_SPACE (ASCII85_BUFSZ + 2) /* 85 + "\n\0" */424424+ /* Always leave space for the suffix char and the \0 */425425+#define MIN_SPACE (ASCII85_BUFSZ + 2) /* 85 + "<suffix>\0" */430426431427 if (size & 3)432428 drm_printf(p, "Size not word aligned: %zu", size);···450462 line_pos += strlen(line_buff + line_pos);451463452464 if ((line_pos + MIN_SPACE) >= DMESG_MAX_LINE_LEN) {453453- line_buff[line_pos++] = '\n';454465 line_buff[line_pos++] = 0;455466456467 drm_puts(p, line_buff);···461474 }462475 }463476464464- if (line_pos) {465465- line_buff[line_pos++] = '\n';466466- line_buff[line_pos++] = 0;477477+ if (suffix)478478+ line_buff[line_pos++] = suffix;467479480480+ if (line_pos) {481481+ line_buff[line_pos++] = 0;468482 drm_puts(p, line_buff);469483 }470484
···570570571571config HID_LENOVO572572 tristate "Lenovo / Thinkpad devices"573573+ depends on ACPI574574+ select ACPI_PLATFORM_PROFILE573575 select NEW_LEDS574576 select LEDS_CLASS575577 help···11691167 tristate "Topre REALFORCE keyboards"11701168 depends on HID11711169 help11721172- Say Y for N-key rollover support on Topre REALFORCE R2 108/87 key keyboards.11701170+ Say Y for N-key rollover support on Topre REALFORCE R2 108/87 key and11711171+ Topre REALFORCE R3S 87 key keyboards.1173117211741173config HID_THINGM11751174 tristate "ThingM blink(1) USB RGB LED"···1377137413781375source "drivers/hid/bpf/Kconfig"1379137613801380-endif # HID13811381-13821382-source "drivers/hid/usbhid/Kconfig"13831383-13841377source "drivers/hid/i2c-hid/Kconfig"1385137813861379source "drivers/hid/intel-ish-hid/Kconfig"···13861387source "drivers/hid/surface-hid/Kconfig"1387138813881389source "drivers/hid/intel-thc-hid/Kconfig"13901390+13911391+endif # HID13921392+13931393+# USB support may be used with HID disabled13941394+13951395+source "drivers/hid/usbhid/Kconfig"1389139613901397endif # HID_SUPPORT
-1
drivers/hid/amd-sfh-hid/Kconfig
···5566config AMD_SFH_HID77 tristate "AMD Sensor Fusion Hub"88- depends on HID98 depends on X86109 help1110 If you say yes to this option, support will be included for the
···106106 "%s::%s",107107 dev_name(&input->dev),108108 info->led_name);109109+ if (!led->cdev.name)110110+ return -ENOMEM;109111110112 ret = devm_led_classdev_register(&hdev->dev, &led->cdev);111113 if (ret)
+1-1
drivers/hid/i2c-hid/Kconfig
···22menuconfig I2C_HID33 tristate "I2C HID support"44 default y55- depends on I2C && INPUT && HID55+ depends on I2C6677if I2C_HID88
-1
drivers/hid/intel-ish-hid/Kconfig
···66 tristate "Intel Integrated Sensor Hub"77 default n88 depends on X8699- depends on HID109 help1110 The Integrated Sensor Hub (ISH) enables the ability to offload1211 sensor polling and algorithm processing to a dedicated low power
···517517 /* ISH FW is dead */518518 if (!ish_is_input_ready(dev))519519 return -EPIPE;520520+521521+ /* Send clock sync at once after reset */522522+ ishtp_dev->prev_sync = 0;523523+520524 /*521525 * Set HOST2ISH.ILUP. Apparently we need this BEFORE sending522526 * RESET_NOTIFY_ACK - FW will be checking for it···581577 */582578static void _ish_sync_fw_clock(struct ishtp_device *dev)583579{584584- static unsigned long prev_sync;585585- uint64_t usec;580580+ struct ipc_time_update_msg time = {};586581587587- if (prev_sync && time_before(jiffies, prev_sync + 20 * HZ))582582+ if (dev->prev_sync && time_before(jiffies, dev->prev_sync + 20 * HZ))588583 return;589584590590- prev_sync = jiffies;591591- usec = ktime_to_us(ktime_get_boottime());592592- ipc_send_mng_msg(dev, MNG_SYNC_FW_CLOCK, &usec, sizeof(uint64_t));585585+ dev->prev_sync = jiffies;586586+ /* The fields of time would be updated while sending message */587587+ ipc_send_mng_msg(dev, MNG_SYNC_FW_CLOCK, &time, sizeof(time));593588}594589595590/**
···253253 unsigned int ipc_tx_cnt;254254 unsigned long long ipc_tx_bytes_cnt;255255256256+ /* Time of the last clock sync */257257+ unsigned long prev_sync;256258 const struct ishtp_hw_ops *ops;257259 size_t mtu;258260 uint32_t ishtp_msg_hdr;
-1
drivers/hid/intel-thc-hid/Kconfig
···77config INTEL_THC_HID88 tristate "Intel Touch Host Controller"99 depends on ACPI1010- select HID1110 help1211 THC (Touch Host Controller) is the name of the IP block in PCH that1312 interfaces with Touch Devices (ex: touchscreen, touchpad etc.). It
-2
drivers/hid/surface-hid/Kconfig
···11# SPDX-License-Identifier: GPL-2.0+22menu "Surface System Aggregator Module HID support"33 depends on SURFACE_AGGREGATOR44- depends on INPUT5465config SURFACE_HID76 tristate "HID transport driver for Surface System Aggregator Module"···38393940config SURFACE_HID_CORE4041 tristate4141- select HID
+1-2
drivers/hid/usbhid/Kconfig
···55config USB_HID66 tristate "USB HID transport layer"77 default y88- depends on USB && INPUT99- select HID88+ depends on HID109 help1110 Say Y here if you want to connect USB keyboards,1211 mice, joysticks, graphic tablets, or any other HID based devices
+76-39
drivers/i2c/i2c-core-base.c
···13001300 info.flags |= I2C_CLIENT_SLAVE;13011301 }1302130213031303- info.flags |= I2C_CLIENT_USER;13041304-13051303 client = i2c_new_client_device(adap, &info);13061304 if (IS_ERR(client))13071305 return PTR_ERR(client);1308130613071307+ /* Keep track of the added device */13081308+ mutex_lock(&adap->userspace_clients_lock);13091309+ list_add_tail(&client->detected, &adap->userspace_clients);13101310+ mutex_unlock(&adap->userspace_clients_lock);13091311 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",13101312 info.type, info.addr);1311131313121314 return count;13131315}13141316static DEVICE_ATTR_WO(new_device);13151315-13161316-static int __i2c_find_user_addr(struct device *dev, const void *addrp)13171317-{13181318- struct i2c_client *client = i2c_verify_client(dev);13191319- unsigned short addr = *(unsigned short *)addrp;13201320-13211321- return client && client->flags & I2C_CLIENT_USER &&13221322- i2c_encode_flags_to_addr(client) == addr;13231323-}1324131713251318/*13261319 * And of course let the users delete the devices they instantiated, if···13291336 const char *buf, size_t count)13301337{13311338 struct i2c_adapter *adap = to_i2c_adapter(dev);13321332- struct device *child_dev;13391339+ struct i2c_client *client, *next;13331340 unsigned short addr;13341341 char end;13351342 int res;···13451352 return -EINVAL;13461353 }1347135413481348- mutex_lock(&core_lock);13491355 /* Make sure the device was added through sysfs */13501350- child_dev = device_find_child(&adap->dev, &addr, __i2c_find_user_addr);13511351- if (child_dev) {13521352- i2c_unregister_device(i2c_verify_client(child_dev));13531353- put_device(child_dev);13541354- } else {13551355- dev_err(dev, "Can't find userspace-created device at %#x\n", addr);13561356- count = -ENOENT;13571357- }13581358- mutex_unlock(&core_lock);13561356+ res = -ENOENT;13571357+ mutex_lock_nested(&adap->userspace_clients_lock,13581358+ i2c_adapter_depth(adap));13591359+ list_for_each_entry_safe(client, next, &adap->userspace_clients,13601360+ detected) {13611361+ if (i2c_encode_flags_to_addr(client) == addr) {13621362+ dev_info(dev, "%s: Deleting device %s at 0x%02hx\n",13631363+ "delete_device", client->name, client->addr);1359136413601360- return count;13651365+ list_del(&client->detected);13661366+ i2c_unregister_device(client);13671367+ res = count;13681368+ break;13691369+ }13701370+ }13711371+ mutex_unlock(&adap->userspace_clients_lock);13721372+13731373+ if (res < 0)13741374+ dev_err(dev, "%s: Can't find device in list\n",13751375+ "delete_device");13761376+ return res;13611377}13621378static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL,13631379 delete_device_store);···15371535 adap->locked_flags = 0;15381536 rt_mutex_init(&adap->bus_lock);15391537 rt_mutex_init(&adap->mux_lock);15381538+ mutex_init(&adap->userspace_clients_lock);15391539+ INIT_LIST_HEAD(&adap->userspace_clients);1540154015411541 /* Set default timeout to 1 second if not already set */15421542 if (adap->timeout == 0)···17041700}17051701EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);1706170217031703+static void i2c_do_del_adapter(struct i2c_driver *driver,17041704+ struct i2c_adapter *adapter)17051705+{17061706+ struct i2c_client *client, *_n;17071707+17081708+ /* Remove the devices we created ourselves as the result of hardware17091709+ * probing (using a driver's detect method) */17101710+ list_for_each_entry_safe(client, _n, &driver->clients, detected) {17111711+ if (client->adapter == adapter) {17121712+ dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",17131713+ client->name, client->addr);17141714+ list_del(&client->detected);17151715+ i2c_unregister_device(client);17161716+ }17171717+ }17181718+}17191719+17071720static int __unregister_client(struct device *dev, void *dummy)17081721{17091722 struct i2c_client *client = i2c_verify_client(dev);···17361715 return 0;17371716}1738171717181718+static int __process_removed_adapter(struct device_driver *d, void *data)17191719+{17201720+ i2c_do_del_adapter(to_i2c_driver(d), data);17211721+ return 0;17221722+}17231723+17391724/**17401725 * i2c_del_adapter - unregister I2C adapter17411726 * @adap: the adapter being unregistered···17531726void i2c_del_adapter(struct i2c_adapter *adap)17541727{17551728 struct i2c_adapter *found;17291729+ struct i2c_client *client, *next;1756173017571731 /* First make sure that this adapter was ever added */17581732 mutex_lock(&core_lock);···17651737 }1766173817671739 i2c_acpi_remove_space_handler(adap);17401740+ /* Tell drivers about this removal */17411741+ mutex_lock(&core_lock);17421742+ bus_for_each_drv(&i2c_bus_type, NULL, adap,17431743+ __process_removed_adapter);17441744+ mutex_unlock(&core_lock);17451745+17461746+ /* Remove devices instantiated from sysfs */17471747+ mutex_lock_nested(&adap->userspace_clients_lock,17481748+ i2c_adapter_depth(adap));17491749+ list_for_each_entry_safe(client, next, &adap->userspace_clients,17501750+ detected) {17511751+ dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,17521752+ client->addr);17531753+ list_del(&client->detected);17541754+ i2c_unregister_device(client);17551755+ }17561756+ mutex_unlock(&adap->userspace_clients_lock);1768175717691758 /* Detach any active clients. This can't fail, thus we do not17701759 * check the returned value. This is a two-pass process, because17711760 * we can't remove the dummy devices during the first pass: they17721761 * could have been instantiated by real devices wishing to clean17731762 * them up properly, so we give them a chance to do that first. */17741774- mutex_lock(&core_lock);17751763 device_for_each_child(&adap->dev, NULL, __unregister_client);17761764 device_for_each_child(&adap->dev, NULL, __unregister_dummy);17771777- mutex_unlock(&core_lock);1778176517791766 /* device name is gone after device_unregister */17801767 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);···20091966 /* add the driver to the list of i2c drivers in the driver core */20101967 driver->driver.owner = owner;20111968 driver->driver.bus = &i2c_bus_type;19691969+ INIT_LIST_HEAD(&driver->clients);2012197020131971 /* When registration returns, the driver core20141972 * will have called probe() for all matching-but-unbound devices.···20271983}20281984EXPORT_SYMBOL(i2c_register_driver);2029198520302030-static int __i2c_unregister_detected_client(struct device *dev, void *argp)19861986+static int __process_removed_driver(struct device *dev, void *data)20311987{20322032- struct i2c_client *client = i2c_verify_client(dev);20332033-20342034- if (client && client->flags & I2C_CLIENT_AUTO)20352035- i2c_unregister_device(client);20362036-19881988+ if (dev->type == &i2c_adapter_type)19891989+ i2c_do_del_adapter(data, to_i2c_adapter(dev));20371990 return 0;20381991}20391992···20412000 */20422001void i2c_del_driver(struct i2c_driver *driver)20432002{20442044- mutex_lock(&core_lock);20452045- /* Satisfy __must_check, function can't fail */20462046- if (driver_for_each_device(&driver->driver, NULL, NULL,20472047- __i2c_unregister_detected_client)) {20482048- }20492049- mutex_unlock(&core_lock);20032003+ i2c_for_each_dev(driver, __process_removed_driver);2050200420512005 driver_unregister(&driver->driver);20522006 pr_debug("driver [%s] unregistered\n", driver->driver.name);···24682432 /* Finally call the custom detection function */24692433 memset(&info, 0, sizeof(struct i2c_board_info));24702434 info.addr = addr;24712471- info.flags = I2C_CLIENT_AUTO;24722435 err = driver->detect(temp_client, &info);24732436 if (err) {24742437 /* -ENODEV is returned if the detection fails. We catch it···24942459 dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n",24952460 info.type, info.addr);24962461 client = i2c_new_client_device(adapter, &info);24972497- if (IS_ERR(client))24622462+ if (!IS_ERR(client))24632463+ list_add_tail(&client->detected, &driver->clients);24642464+ else24982465 dev_err(&adapter->dev, "Failed creating %s at 0x%02x\n",24992466 info.type, info.addr);25002467 }
···159159}160160161161static struct regmap *device_node_get_regmap(struct device_node *np,162162+ bool create_regmap,162163 bool check_res)163164{164165 struct syscon *entry, *syscon = NULL;···173172 }174173175174 if (!syscon) {176176- if (of_device_is_compatible(np, "syscon"))175175+ if (create_regmap)177176 syscon = of_syscon_register(np, check_res);178177 else179178 syscon = ERR_PTR(-EINVAL);···234233}235234EXPORT_SYMBOL_GPL(of_syscon_register_regmap);236235236236+/**237237+ * device_node_to_regmap() - Get or create a regmap for specified device node238238+ * @np: Device tree node239239+ *240240+ * Get a regmap for the specified device node. If there's not an existing241241+ * regmap, then one is instantiated. This function should not be used if the242242+ * device node has a custom regmap driver or has resources (clocks, resets) to243243+ * be managed. Use syscon_node_to_regmap() instead for those cases.244244+ *245245+ * Return: regmap ptr on success, negative error code on failure.246246+ */237247struct regmap *device_node_to_regmap(struct device_node *np)238248{239239- return device_node_get_regmap(np, false);249249+ return device_node_get_regmap(np, true, false);240250}241251EXPORT_SYMBOL_GPL(device_node_to_regmap);242252253253+/**254254+ * syscon_node_to_regmap() - Get or create a regmap for specified syscon device node255255+ * @np: Device tree node256256+ *257257+ * Get a regmap for the specified device node. If there's not an existing258258+ * regmap, then one is instantiated if the node is a generic "syscon". This259259+ * function is safe to use for a syscon registered with260260+ * of_syscon_register_regmap().261261+ *262262+ * Return: regmap ptr on success, negative error code on failure.263263+ */243264struct regmap *syscon_node_to_regmap(struct device_node *np)244265{245245- return device_node_get_regmap(np, true);266266+ return device_node_get_regmap(np, of_device_is_compatible(np, "syscon"), true);246267}247268EXPORT_SYMBOL_GPL(syscon_node_to_regmap);248269
···21052105 /* hand second half of page back to the ring */21062106 ixgbe_reuse_rx_page(rx_ring, rx_buffer);21072107 } else {21082108- if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {21082108+ if (skb && IXGBE_CB(skb)->dma == rx_buffer->dma) {21092109 /* the page has been released from the ring */21102110 IXGBE_CB(skb)->page_released = true;21112111 } else {
···22642264 /* Allow the MAC to stop its clock if the PHY has the capability */22652265 pl->mac_tx_clk_stop = phy_eee_tx_clock_stop_capable(phy) > 0;2266226622672267- /* Explicitly configure whether the PHY is allowed to stop it's22682268- * receive clock.22692269- */22702270- ret = phy_eee_rx_clock_stop(phy, pl->config->eee_rx_clk_stop_enable);22712271- if (ret == -EOPNOTSUPP)22722272- ret = 0;22672267+ if (pl->mac_supports_eee_ops) {22682268+ /* Explicitly configure whether the PHY is allowed to stop it's22692269+ * receive clock.22702270+ */22712271+ ret = phy_eee_rx_clock_stop(phy,22722272+ pl->config->eee_rx_clk_stop_enable);22732273+ if (ret == -EOPNOTSUPP)22742274+ ret = 0;22752275+ }2273227622742277 return ret;22752278}
+2-2
drivers/net/pse-pd/pse_core.c
···319319 goto out;320320 mW = ret;321321322322- ret = pse_pi_get_voltage(rdev);322322+ ret = _pse_pi_get_voltage(rdev);323323 if (!ret) {324324 dev_err(pcdev->dev, "Voltage null\n");325325 ret = -ERANGE;···356356357357 id = rdev_get_id(rdev);358358 mutex_lock(&pcdev->lock);359359- ret = pse_pi_get_voltage(rdev);359359+ ret = _pse_pi_get_voltage(rdev);360360 if (!ret) {361361 dev_err(pcdev->dev, "Voltage null\n");362362 ret = -ERANGE;
+3-1
drivers/net/team/team_core.c
···26392639 ctx.data.u32_val = nla_get_u32(attr_data);26402640 break;26412641 case TEAM_OPTION_TYPE_STRING:26422642- if (nla_len(attr_data) > TEAM_STRING_MAX_LEN) {26422642+ if (nla_len(attr_data) > TEAM_STRING_MAX_LEN ||26432643+ !memchr(nla_data(attr_data), '\0',26442644+ nla_len(attr_data))) {26432645 err = -EINVAL;26442646 goto team_put;26452647 }
+5-2
drivers/net/vxlan/vxlan_core.c
···29022902 struct vxlan_dev *vxlan = netdev_priv(dev);29032903 int err;2904290429052905- if (vxlan->cfg.flags & VXLAN_F_VNIFILTER)29062906- vxlan_vnigroup_init(vxlan);29052905+ if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) {29062906+ err = vxlan_vnigroup_init(vxlan);29072907+ if (err)29082908+ return err;29092909+ }2907291029082911 err = gro_cells_init(&vxlan->gro_cells, dev);29092912 if (err)
+45-16
drivers/net/wireless/ath/ath12k/wmi.c
···48514851 return reg_rule_ptr;48524852}4853485348544854+static u8 ath12k_wmi_ignore_num_extra_rules(struct ath12k_wmi_reg_rule_ext_params *rule,48554855+ u32 num_reg_rules)48564856+{48574857+ u8 num_invalid_5ghz_rules = 0;48584858+ u32 count, start_freq;48594859+48604860+ for (count = 0; count < num_reg_rules; count++) {48614861+ start_freq = le32_get_bits(rule[count].freq_info, REG_RULE_START_FREQ);48624862+48634863+ if (start_freq >= ATH12K_MIN_6G_FREQ)48644864+ num_invalid_5ghz_rules++;48654865+ }48664866+48674867+ return num_invalid_5ghz_rules;48684868+}48694869+48544870static int ath12k_pull_reg_chan_list_ext_update_ev(struct ath12k_base *ab,48554871 struct sk_buff *skb,48564872 struct ath12k_reg_info *reg_info)···48774861 u32 num_2g_reg_rules, num_5g_reg_rules;48784862 u32 num_6g_reg_rules_ap[WMI_REG_CURRENT_MAX_AP_TYPE];48794863 u32 num_6g_reg_rules_cl[WMI_REG_CURRENT_MAX_AP_TYPE][WMI_REG_MAX_CLIENT_TYPE];48644864+ u8 num_invalid_5ghz_ext_rules;48804865 u32 total_reg_rules = 0;48814866 int ret, i, j;48824867···49704953 }4971495449724955 memcpy(reg_info->alpha2, &ev->alpha2, REG_ALPHA2_LEN);49734973-49744974- /* FIXME: Currently FW includes 6G reg rule also in 5G rule49754975- * list for country US.49764976- * Having same 6G reg rule in 5G and 6G rules list causes49774977- * intersect check to be true, and same rules will be shown49784978- * multiple times in iw cmd. So added hack below to avoid49794979- * parsing 6G rule from 5G reg rule list, and this can be49804980- * removed later, after FW updates to remove 6G reg rule49814981- * from 5G rules list.49824982- */49834983- if (memcmp(reg_info->alpha2, "US", 2) == 0) {49844984- reg_info->num_5g_reg_rules = REG_US_5G_NUM_REG_RULES;49854985- num_5g_reg_rules = reg_info->num_5g_reg_rules;49864986- }4987495649884957 reg_info->dfs_region = le32_to_cpu(ev->dfs_region);49894958 reg_info->phybitmap = le32_to_cpu(ev->phybitmap);···50735070 }50745071 }5075507250735073+ ext_wmi_reg_rule += num_2g_reg_rules;50745074+50755075+ /* Firmware might include 6 GHz reg rule in 5 GHz rule list50765076+ * for few countries along with separate 6 GHz rule.50775077+ * Having same 6 GHz reg rule in 5 GHz and 6 GHz rules list50785078+ * causes intersect check to be true, and same rules will be50795079+ * shown multiple times in iw cmd.50805080+ * Hence, avoid parsing 6 GHz rule from 5 GHz reg rule list50815081+ */50825082+ num_invalid_5ghz_ext_rules = ath12k_wmi_ignore_num_extra_rules(ext_wmi_reg_rule,50835083+ num_5g_reg_rules);50845084+50855085+ if (num_invalid_5ghz_ext_rules) {50865086+ ath12k_dbg(ab, ATH12K_DBG_WMI,50875087+ "CC: %s 5 GHz reg rules number %d from fw, %d number of invalid 5 GHz rules",50885088+ reg_info->alpha2, reg_info->num_5g_reg_rules,50895089+ num_invalid_5ghz_ext_rules);50905090+50915091+ num_5g_reg_rules = num_5g_reg_rules - num_invalid_5ghz_ext_rules;50925092+ reg_info->num_5g_reg_rules = num_5g_reg_rules;50935093+ }50945094+50765095 if (num_5g_reg_rules) {50775077- ext_wmi_reg_rule += num_2g_reg_rules;50785096 reg_info->reg_rules_5g_ptr =50795097 create_ext_reg_rules_from_wmi(num_5g_reg_rules,50805098 ext_wmi_reg_rule);···51075083 }51085084 }5109508551105110- ext_wmi_reg_rule += num_5g_reg_rules;50865086+ /* We have adjusted the number of 5 GHz reg rules above. But still those50875087+ * many rules needs to be adjusted in ext_wmi_reg_rule.50885088+ *50895089+ * NOTE: num_invalid_5ghz_ext_rules will be 0 for rest other cases.50905090+ */50915091+ ext_wmi_reg_rule += (num_5g_reg_rules + num_invalid_5ghz_ext_rules);5111509251125093 for (i = 0; i < WMI_REG_CURRENT_MAX_AP_TYPE; i++) {51135094 reg_info->reg_rules_6g_ap_ptr[i] =
···1700170017011701 status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0,17021702 &result);17031703- if (status < 0)17031703+17041704+ /*17051705+ * It's either a kernel error or the host observed a connection17061706+ * lost. In either case it's not possible communicate with the17071707+ * controller and thus enter the error code path.17081708+ */17091709+ if (status < 0 || status == NVME_SC_HOST_PATH_ERROR)17041710 return status;1705171117061712 /*
+25-10
drivers/nvme/host/fc.c
···781781static void782782nvme_fc_ctrl_connectivity_loss(struct nvme_fc_ctrl *ctrl)783783{784784+ enum nvme_ctrl_state state;785785+ unsigned long flags;786786+784787 dev_info(ctrl->ctrl.device,785788 "NVME-FC{%d}: controller connectivity lost. Awaiting "786789 "Reconnect", ctrl->cnum);787790788788- switch (nvme_ctrl_state(&ctrl->ctrl)) {791791+ spin_lock_irqsave(&ctrl->lock, flags);792792+ set_bit(ASSOC_FAILED, &ctrl->flags);793793+ state = nvme_ctrl_state(&ctrl->ctrl);794794+ spin_unlock_irqrestore(&ctrl->lock, flags);795795+796796+ switch (state) {789797 case NVME_CTRL_NEW:790798 case NVME_CTRL_LIVE:791799 /*···20872079 nvme_fc_complete_rq(rq);2088208020892081check_error:20902090- if (terminate_assoc && ctrl->ctrl.state != NVME_CTRL_RESETTING)20822082+ if (terminate_assoc &&20832083+ nvme_ctrl_state(&ctrl->ctrl) != NVME_CTRL_RESETTING)20912084 queue_work(nvme_reset_wq, &ctrl->ioerr_work);20922085}20932086···25422533static void25432534nvme_fc_error_recovery(struct nvme_fc_ctrl *ctrl, char *errmsg)25442535{25362536+ enum nvme_ctrl_state state = nvme_ctrl_state(&ctrl->ctrl);25372537+25452538 /*25462539 * if an error (io timeout, etc) while (re)connecting, the remote25472540 * port requested terminating of the association (disconnect_ls)···25512540 * the controller. Abort any ios on the association and let the25522541 * create_association error path resolve things.25532542 */25542554- if (ctrl->ctrl.state == NVME_CTRL_CONNECTING) {25432543+ if (state == NVME_CTRL_CONNECTING) {25552544 __nvme_fc_abort_outstanding_ios(ctrl, true);25562556- set_bit(ASSOC_FAILED, &ctrl->flags);25572545 dev_warn(ctrl->ctrl.device,25582546 "NVME-FC{%d}: transport error during (re)connect\n",25592547 ctrl->cnum);···25602550 }2561255125622552 /* Otherwise, only proceed if in LIVE state - e.g. on first error */25632563- if (ctrl->ctrl.state != NVME_CTRL_LIVE)25532553+ if (state != NVME_CTRL_LIVE)25642554 return;2565255525662556 dev_warn(ctrl->ctrl.device,···31773167 else31783168 ret = nvme_fc_recreate_io_queues(ctrl);31793169 }31803180- if (!ret && test_bit(ASSOC_FAILED, &ctrl->flags))31813181- ret = -EIO;31823170 if (ret)31833171 goto out_term_aen_ops;3184317231853185- changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);31733173+ spin_lock_irqsave(&ctrl->lock, flags);31743174+ if (!test_bit(ASSOC_FAILED, &ctrl->flags))31753175+ changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);31763176+ else31773177+ ret = -EIO;31783178+ spin_unlock_irqrestore(&ctrl->lock, flags);31793179+31803180+ if (ret)31813181+ goto out_term_aen_ops;3186318231873183 ctrl->ctrl.nr_reconnects = 0;31883184···35943578 list_add_tail(&ctrl->ctrl_list, &rport->ctrl_list);35953579 spin_unlock_irqrestore(&rport->lock, flags);3596358035973597- if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RESETTING) ||35983598- !nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {35813581+ if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {35993582 dev_err(ctrl->ctrl.device,36003583 "NVME-FC{%d}: failed to init ctrl state\n", ctrl->cnum);36013584 goto fail_ctrl;
+3-9
drivers/nvme/host/pci.c
···21532153 return 0;2154215421552155out_free_bufs:21562156- while (--i >= 0) {21572157- size_t size = le32_to_cpu(descs[i].size) * NVME_CTRL_PAGE_SIZE;21582158-21592159- dma_free_attrs(dev->dev, size, bufs[i],21602160- le64_to_cpu(descs[i].addr),21612161- DMA_ATTR_NO_KERNEL_MAPPING | DMA_ATTR_NO_WARN);21622162- }21632163-21642156 kfree(bufs);21652157out_free_descs:21662158 dma_free_coherent(dev->dev, descs_size, descs, descs_dma);···31393147 * because of high power consumption (> 2 Watt) in s2idle31403148 * sleep. Only some boards with Intel CPU are affected.31413149 */31423142- if (dmi_match(DMI_BOARD_NAME, "GMxPXxx") ||31503150+ if (dmi_match(DMI_BOARD_NAME, "DN50Z-140HC-YD") ||31513151+ dmi_match(DMI_BOARD_NAME, "GMxPXxx") ||31523152+ dmi_match(DMI_BOARD_NAME, "GXxMRXx") ||31433153 dmi_match(DMI_BOARD_NAME, "PH4PG31") ||31443154 dmi_match(DMI_BOARD_NAME, "PH4PRX1_PH6PRX1") ||31453155 dmi_match(DMI_BOARD_NAME, "PH6PG01_PH6PG71"))
···108108 pci_read_config_dword(pdev, pdev->l1ss + PCI_L1SS_CTL2, cap++);109109 pci_read_config_dword(pdev, pdev->l1ss + PCI_L1SS_CTL1, cap++);110110111111- if (parent->state_saved)112112- return;113113-114111 /*115112 * Save parent's L1 substate configuration so we have it for116113 * pci_restore_aspm_l1ss_state(pdev) to restore.
···872872 case 0x1a: /* start stop unit in progress */873873 case 0x1b: /* sanitize in progress */874874 case 0x1d: /* configuration in progress */875875- case 0x24: /* depopulation in progress */876876- case 0x25: /* depopulation restore in progress */877875 action = ACTION_DELAYED_RETRY;878876 break;879877 case 0x0a: /* ALUA state transition */880878 action = ACTION_DELAYED_REPREP;881879 break;880880+ /*881881+ * Depopulation might take many hours,882882+ * thus it is not worthwhile to retry.883883+ */884884+ case 0x24: /* depopulation in progress */885885+ case 0x25: /* depopulation restore in progress */886886+ fallthrough;882887 default:883888 action = ACTION_FAIL;884889 break;
+7
drivers/scsi/scsi_lib_test.c
···6767 };6868 int i;69697070+ /* Success */7171+ sc.result = 0;7272+ KUNIT_EXPECT_EQ(test, 0, scsi_check_passthrough(&sc, &failures));7373+ KUNIT_EXPECT_EQ(test, 0, scsi_check_passthrough(&sc, NULL));7474+ /* Command failed but caller did not pass in a failures array */7575+ scsi_build_sense(&sc, 0, ILLEGAL_REQUEST, 0x91, 0x36);7676+ KUNIT_EXPECT_EQ(test, 0, scsi_check_passthrough(&sc, NULL));7077 /* Match end of array */7178 scsi_build_sense(&sc, 0, ILLEGAL_REQUEST, 0x91, 0x36);7279 KUNIT_EXPECT_EQ(test, -EAGAIN, scsi_check_passthrough(&sc, &failures));
+1-1
drivers/scsi/scsi_scan.c
···246246 }247247 ret = sbitmap_init_node(&sdev->budget_map,248248 scsi_device_max_queue_depth(sdev),249249- new_shift, GFP_KERNEL,249249+ new_shift, GFP_NOIO,250250 sdev->request_queue->node, false, true);251251 if (!ret)252252 sbitmap_resize(&sdev->budget_map, depth);
···6161 The resulting code will be significantly slower than normal; you6262 probably shouldn't select this option unless you're a developer.63636464+config BCACHEFS_INJECT_TRANSACTION_RESTARTS6565+ bool "Randomly inject transaction restarts"6666+ depends on BCACHEFS_DEBUG6767+ help6868+ Randomly inject transaction restarts in a few core paths - may have a6969+ significant performance penalty7070+6471config BCACHEFS_TESTS6572 bool "bcachefs unit and performance tests"6673 depends on BCACHEFS_FS
+25-22
fs/bcachefs/alloc_background.c
···18031803 u64 open;18041804 u64 need_journal_commit;18051805 u64 discarded;18061806- u64 need_journal_commit_this_dev;18071806};1808180718091808static int bch2_discard_one_bucket(struct btree_trans *trans,···18261827 goto out;18271828 }1828182918291829- if (bch2_bucket_needs_journal_commit(&c->buckets_waiting_for_journal,18301830- c->journal.flushed_seq_ondisk,18311831- pos.inode, pos.offset)) {18321832- s->need_journal_commit++;18331833- s->need_journal_commit_this_dev++;18301830+ u64 seq_ready = bch2_bucket_journal_seq_ready(&c->buckets_waiting_for_journal,18311831+ pos.inode, pos.offset);18321832+ if (seq_ready > c->journal.flushed_seq_ondisk) {18331833+ if (seq_ready > c->journal.flushing_seq)18341834+ s->need_journal_commit++;18341835 goto out;18351836 }18361837···18641865 discard_locked = true;18651866 }1866186718671867- if (!bkey_eq(*discard_pos_done, iter.pos) &&18681868- ca->mi.discard && !c->opts.nochanges) {18691869- /*18701870- * This works without any other locks because this is the only18711871- * thread that removes items from the need_discard tree18721872- */18731873- bch2_trans_unlock_long(trans);18741874- blkdev_issue_discard(ca->disk_sb.bdev,18751875- k.k->p.offset * ca->mi.bucket_size,18761876- ca->mi.bucket_size,18771877- GFP_KERNEL);18781878- *discard_pos_done = iter.pos;18681868+ if (!bkey_eq(*discard_pos_done, iter.pos)) {18791869 s->discarded++;18701870+ *discard_pos_done = iter.pos;1880187118811881- ret = bch2_trans_relock_notrace(trans);18821882- if (ret)18831883- goto out;18721872+ if (ca->mi.discard && !c->opts.nochanges) {18731873+ /*18741874+ * This works without any other locks because this is the only18751875+ * thread that removes items from the need_discard tree18761876+ */18771877+ bch2_trans_unlock_long(trans);18781878+ blkdev_issue_discard(ca->disk_sb.bdev,18791879+ k.k->p.offset * ca->mi.bucket_size,18801880+ ca->mi.bucket_size,18811881+ GFP_KERNEL);18821882+ ret = bch2_trans_relock_notrace(trans);18831883+ if (ret)18841884+ goto out;18851885+ }18841886 }1885188718861888 SET_BCH_ALLOC_V4_NEED_DISCARD(&a->v, false);···19281928 POS(ca->dev_idx, 0),19291929 POS(ca->dev_idx, U64_MAX), 0, k,19301930 bch2_discard_one_bucket(trans, ca, &iter, &discard_pos_done, &s, false)));19311931+19321932+ if (s.need_journal_commit > dev_buckets_available(ca, BCH_WATERMARK_normal))19331933+ bch2_journal_flush_async(&c->journal, NULL);1931193419321935 trace_discard_buckets(c, s.seen, s.open, s.need_journal_commit, s.discarded,19331936 bch2_err_str(ret));···20272024 break;20282025 }2029202620302030- trace_discard_buckets(c, s.seen, s.open, s.need_journal_commit, s.discarded, bch2_err_str(ret));20272027+ trace_discard_buckets_fast(c, s.seen, s.open, s.need_journal_commit, s.discarded, bch2_err_str(ret));2031202820322029 bch2_trans_put(trans);20332030 percpu_ref_put(&ca->io_ref);
+7-3
fs/bcachefs/alloc_foreground.c
···205205 return false;206206 }207207208208- if (bch2_bucket_needs_journal_commit(&c->buckets_waiting_for_journal,209209- c->journal.flushed_seq_ondisk, bucket.inode, bucket.offset)) {208208+ u64 journal_seq_ready =209209+ bch2_bucket_journal_seq_ready(&c->buckets_waiting_for_journal,210210+ bucket.inode, bucket.offset);211211+ if (journal_seq_ready > c->journal.flushed_seq_ondisk) {212212+ if (journal_seq_ready > c->journal.flushing_seq)213213+ s->need_journal_commit++;210214 s->skipped_need_journal_commit++;211215 return false;212216 }···574570 ? bch2_bucket_alloc_freelist(trans, ca, watermark, &s, cl)575571 : bch2_bucket_alloc_early(trans, ca, watermark, &s, cl);576572577577- if (s.skipped_need_journal_commit * 2 > avail)573573+ if (s.need_journal_commit * 2 > avail)578574 bch2_journal_flush_async(&c->journal, NULL);579575580576 if (!ob && s.btree_bitmap != BTREE_BITMAP_ANY) {
···748748 rcu_read_unlock();749749 mutex_lock(&bc->table.mutex);750750 mutex_unlock(&bc->table.mutex);751751- rcu_read_lock();752751 continue;753752 }754753 for (i = 0; i < tbl->size; i++)
+4
fs/bcachefs/btree_trans_commit.c
···99999910001000 bch2_trans_verify_not_unlocked_or_in_restart(trans);1001100110021002+ ret = trans_maybe_inject_restart(trans, _RET_IP_);10031003+ if (unlikely(ret))10041004+ goto out_reset;10051005+10021006 if (!trans->nr_updates &&10031007 !trans->journal_entries_u64s)10041008 goto out_reset;
···381381not_found:382382 if (flags & BTREE_TRIGGER_check_repair) {383383 ret = bch2_indirect_extent_missing_error(trans, p, *idx, next_idx, false);384384+ if (ret == -BCH_ERR_missing_indirect_extent)385385+ ret = 0;384386 if (ret)385387 goto err;386388 }
···726726 if (IS_ERR(pcl))727727 return PTR_ERR(pcl);728728729729- lockref_init(&pcl->lockref, 1); /* one ref for this request */729729+ lockref_init(&pcl->lockref); /* one ref for this request */730730 pcl->algorithmformat = map->m_algorithmformat;731731 pcl->length = 0;732732 pcl->partial = true;
+16
fs/file_table.c
···194194 * refcount bumps we should reinitialize the reused file first.195195 */196196 file_ref_init(&f->f_ref, 1);197197+ /*198198+ * Disable permission and pre-content events for all files by default.199199+ * They may be enabled later by file_set_fsnotify_mode_from_watchers().200200+ */201201+ file_set_fsnotify_mode(f, FMODE_NONOTIFY_PERM);197202 return 0;198203}199204···380375 if (IS_ERR(file)) {381376 ihold(inode);382377 path_put(&path);378378+ return file;383379 }380380+ /*381381+ * Disable all fsnotify events for pseudo files by default.382382+ * They may be enabled by caller with file_set_fsnotify_mode().383383+ */384384+ file_set_fsnotify_mode(file, FMODE_NONOTIFY);384385 return file;385386}386387EXPORT_SYMBOL(alloc_file_pseudo);···411400 return file;412401 }413402 file_init_path(file, &path, fops);403403+ /*404404+ * Disable all fsnotify events for pseudo files by default.405405+ * They may be enabled by caller with file_set_fsnotify_mode().406406+ */407407+ file_set_fsnotify_mode(file, FMODE_NONOTIFY);414408 return file;415409}416410EXPORT_SYMBOL_GPL(alloc_file_pseudo_noaccount);
···380380 error = check_nfsd_access(exp, rqstp, may_bypass_gss);381381 if (error)382382 goto out;383383-384384- svc_xprt_set_valid(rqstp->rq_xprt);383383+ /* During LOCALIO call to fh_verify will be called with a NULL rqstp */384384+ if (rqstp)385385+ svc_xprt_set_valid(rqstp->rq_xprt);385386386387 /* Finally, check access permissions. */387388 error = nfsd_permission(cred, exp, dentry, access);
+12-6
fs/notify/fsnotify.c
···648648 * Later, fsnotify permission hooks do not check if there are permission event649649 * watches, but that there were permission event watches at open time.650650 */651651-void file_set_fsnotify_mode(struct file *file)651651+void file_set_fsnotify_mode_from_watchers(struct file *file)652652{653653 struct dentry *dentry = file->f_path.dentry, *parent;654654 struct super_block *sb = dentry->d_sb;···665665 */666666 if (likely(!fsnotify_sb_has_priority_watchers(sb,667667 FSNOTIFY_PRIO_CONTENT))) {668668- file->f_mode |= FMODE_NONOTIFY_PERM;668668+ file_set_fsnotify_mode(file, FMODE_NONOTIFY_PERM);669669 return;670670 }671671···676676 if ((!d_is_dir(dentry) && !d_is_reg(dentry)) ||677677 likely(!fsnotify_sb_has_priority_watchers(sb,678678 FSNOTIFY_PRIO_PRE_CONTENT))) {679679- file->f_mode |= FMODE_NONOTIFY | FMODE_NONOTIFY_PERM;679679+ file_set_fsnotify_mode(file, FMODE_NONOTIFY | FMODE_NONOTIFY_PERM);680680 return;681681 }682682···686686 */687687 mnt_mask = READ_ONCE(real_mount(file->f_path.mnt)->mnt_fsnotify_mask);688688 if (unlikely(fsnotify_object_watched(d_inode(dentry), mnt_mask,689689- FSNOTIFY_PRE_CONTENT_EVENTS)))689689+ FSNOTIFY_PRE_CONTENT_EVENTS))) {690690+ /* Enable pre-content events */691691+ file_set_fsnotify_mode(file, 0);690692 return;693693+ }691694692695 /* Is parent watching for pre-content events on this file? */693696 if (dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED) {694697 parent = dget_parent(dentry);695698 p_mask = fsnotify_inode_watches_children(d_inode(parent));696699 dput(parent);697697- if (p_mask & FSNOTIFY_PRE_CONTENT_EVENTS)700700+ if (p_mask & FSNOTIFY_PRE_CONTENT_EVENTS) {701701+ /* Enable pre-content events */702702+ file_set_fsnotify_mode(file, 0);698703 return;704704+ }699705 }700706 /* Nobody watching for pre-content events from this file */701701- file->f_mode |= FMODE_NONOTIFY | FMODE_NONOTIFY_PERM;707707+ file_set_fsnotify_mode(file, FMODE_NONOTIFY | FMODE_NONOTIFY_PERM);702708}703709#endif704710
+6-5
fs/open.c
···905905 f->f_sb_err = file_sample_sb_err(f);906906907907 if (unlikely(f->f_flags & O_PATH)) {908908- f->f_mode = FMODE_PATH | FMODE_OPENED | FMODE_NONOTIFY;908908+ f->f_mode = FMODE_PATH | FMODE_OPENED;909909+ file_set_fsnotify_mode(f, FMODE_NONOTIFY);909910 f->f_op = &empty_fops;910911 return 0;911912 }···936935937936 /*938937 * Set FMODE_NONOTIFY_* bits according to existing permission watches.939939- * If FMODE_NONOTIFY was already set for an fanotify fd, this doesn't940940- * change anything.938938+ * If FMODE_NONOTIFY mode was already set for an fanotify fd or for a939939+ * pseudo file, this call will not change the mode.941940 */942942- file_set_fsnotify_mode(f);941941+ file_set_fsnotify_mode_from_watchers(f);943942 error = fsnotify_open_perm(f);944943 if (error)945944 goto cleanup_all;···11231122 if (!IS_ERR(f)) {11241123 int error;1125112411261126- f->f_mode |= FMODE_NONOTIFY;11251125+ file_set_fsnotify_mode(f, FMODE_NONOTIFY);11271126 error = vfs_open(path, f);11281127 if (error) {11291128 fput(f);
+11-1
fs/pidfs.c
···287287 switch (cmd) {288288 case FS_IOC_GETVERSION:289289 case PIDFD_GET_CGROUP_NAMESPACE:290290- case PIDFD_GET_INFO:291290 case PIDFD_GET_IPC_NAMESPACE:292291 case PIDFD_GET_MNT_NAMESPACE:293292 case PIDFD_GET_NET_NAMESPACE:···297298 case PIDFD_GET_USER_NAMESPACE:298299 case PIDFD_GET_PID_NAMESPACE:299300 return true;301301+ }302302+303303+ /* Extensible ioctls require some more careful checks. */304304+ switch (_IOC_NR(cmd)) {305305+ case _IOC_NR(PIDFD_GET_INFO):306306+ /*307307+ * Try to prevent performing a pidfd ioctl when someone308308+ * erronously mistook the file descriptor for a pidfd.309309+ * This is not perfect but will catch most cases.310310+ */311311+ return (_IOC_TYPE(cmd) == _IOC_TYPE(PIDFD_GET_INFO));300312 }301313302314 return false;
···191191 __v; \192192})193193194194+#ifdef __CHECKER__195195+#define __BUILD_BUG_ON_ZERO_MSG(e, msg) (0)196196+#else /* __CHECKER__ */197197+#define __BUILD_BUG_ON_ZERO_MSG(e, msg) ((int)sizeof(struct {_Static_assert(!(e), msg);}))198198+#endif /* __CHECKER__ */199199+200200+/* &a[0] degrades to a pointer: a different type from an array */201201+#define __is_array(a) (!__same_type((a), &(a)[0]))202202+#define __must_be_array(a) __BUILD_BUG_ON_ZERO_MSG(!__is_array(a), \203203+ "must be array")204204+205205+#define __is_byte_array(a) (__is_array(a) && sizeof((a)[0]) == 1)206206+#define __must_be_byte_array(a) __BUILD_BUG_ON_ZERO_MSG(!__is_byte_array(a), \207207+ "must be byte array")208208+209209+/* Require C Strings (i.e. NUL-terminated) lack the "nonstring" attribute. */210210+#define __must_be_cstr(p) \211211+ __BUILD_BUG_ON_ZERO_MSG(__annotated(p, nonstring), "must be cstr (NUL-terminated)")212212+194213#endif /* __KERNEL__ */195214196215/**···249230 .popsection;250231251232#define __ADDRESSABLE_ASM_STR(sym) __stringify(__ADDRESSABLE_ASM(sym))252252-253253-#ifdef __CHECKER__254254-#define __BUILD_BUG_ON_ZERO_MSG(e, msg) (0)255255-#else /* __CHECKER__ */256256-#define __BUILD_BUG_ON_ZERO_MSG(e, msg) ((int)sizeof(struct {_Static_assert(!(e), msg);}))257257-#endif /* __CHECKER__ */258258-259259-/* &a[0] degrades to a pointer: a different type from an array */260260-#define __must_be_array(a) __BUILD_BUG_ON_ZERO_MSG(__same_type((a), &(a)[0]), "must be array")261261-262262-/* Require C Strings (i.e. NUL-terminated) lack the "nonstring" attribute. */263263-#define __must_be_cstr(p) \264264- __BUILD_BUG_ON_ZERO_MSG(__annotated(p, nonstring), "must be cstr (NUL-terminated)")265233266234/*267235 * This returns a constant expression while determining if an argument is
+19-1
include/linux/fs.h
···222222#define FMODE_FSNOTIFY_HSM(mode) 0223223#endif224224225225-226225/*227226 * Attribute flags. These should be or-ed together to figure out what228227 * has been changed!···790791791792static inline void inode_set_cached_link(struct inode *inode, char *link, int linklen)792793{794794+ int testlen;795795+796796+ /*797797+ * TODO: patch it into a debug-only check if relevant macros show up.798798+ * In the meantime, since we are suffering strlen even on production kernels799799+ * to find the right length, do a fixup if the wrong value got passed.800800+ */801801+ testlen = strlen(link);802802+ if (testlen != linklen) {803803+ WARN_ONCE(1, "bad length passed for symlink [%s] (got %d, expected %d)",804804+ link, linklen, testlen);805805+ linklen = testlen;806806+ }793807 inode->i_link = link;794808 inode->i_linklen = linklen;795809 inode->i_opflags |= IOP_CACHED_LINK;···31503138 if (unlikely(!exe_file || FMODE_FSNOTIFY_HSM(exe_file->f_mode)))31513139 return;31523140 allow_write_access(exe_file);31413141+}31423142+31433143+static inline void file_set_fsnotify_mode(struct file *file, fmode_t mode)31443144+{31453145+ file->f_mode &= ~FMODE_FSNOTIFY_MASK;31463146+ file->f_mode |= mode;31533147}3154314831553149static inline bool inode_is_open_for_write(const struct inode *inode)
···244244 * @id_table: List of I2C devices supported by this driver245245 * @detect: Callback for device detection246246 * @address_list: The I2C addresses to probe (for detect)247247+ * @clients: List of detected clients we created (for i2c-core use only)247248 * @flags: A bitmask of flags defined in &enum i2c_driver_flags248249 *249250 * The driver.owner field should be set to the module owner of this driver.···299298 /* Device detection callback for automatic device creation */300299 int (*detect)(struct i2c_client *client, struct i2c_board_info *info);301300 const unsigned short *address_list;301301+ struct list_head clients;302302303303 u32 flags;304304};···315313 * @dev: Driver model device node for the slave.316314 * @init_irq: IRQ that was set at initialization317315 * @irq: indicates the IRQ generated by this device (if any)316316+ * @detected: member of an i2c_driver.clients list or i2c-core's317317+ * userspace_devices list318318 * @slave_cb: Callback when I2C slave mode of an adapter is used. The adapter319319 * calls it to pass on slave events to the slave driver.320320 * @devres_group_id: id of the devres group that will be created for resources···336332#define I2C_CLIENT_SLAVE 0x20 /* we are the slave */337333#define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */338334#define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */339339-#define I2C_CLIENT_AUTO 0x100 /* client was auto-detected */340340-#define I2C_CLIENT_USER 0x200 /* client was userspace-created */341335#define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */342336 /* Must match I2C_M_STOP|IGNORE_NAK */343337···347345 struct device dev; /* the device structure */348346 int init_irq; /* irq set at initialization */349347 int irq; /* irq issued by device */348348+ struct list_head detected;350349#if IS_ENABLED(CONFIG_I2C_SLAVE)351350 i2c_slave_cb_t slave_cb; /* callback for slave mode */352351#endif···753750 int nr;754751 char name[48];755752 struct completion dev_released;753753+754754+ struct mutex userspace_clients_lock;755755+ struct list_head userspace_clients;756756757757 struct i2c_bus_recovery_info *bus_recovery_info;758758 const struct i2c_adapter_quirks *quirks;
···398398#endif399399}400400401401-static inline struct net *read_pnet_rcu(possible_net_t *pnet)401401+static inline struct net *read_pnet_rcu(const possible_net_t *pnet)402402{403403#ifdef CONFIG_NET_NS404404 return rcu_dereference(pnet->net);
+7-2
include/net/route.h
···382382static inline int ip4_dst_hoplimit(const struct dst_entry *dst)383383{384384 int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);385385- struct net *net = dev_net(dst->dev);386385387387- if (hoplimit == 0)386386+ if (hoplimit == 0) {387387+ const struct net *net;388388+389389+ rcu_read_lock();390390+ net = dev_net_rcu(dst->dev);388391 hoplimit = READ_ONCE(net->ipv4.sysctl_ip_default_ttl);392392+ rcu_read_unlock();393393+ }389394 return hoplimit;390395}391396
+8-1
include/uapi/drm/amdgpu_drm.h
···411411/* GFX12 and later: */412412#define AMDGPU_TILING_GFX12_SWIZZLE_MODE_SHIFT 0413413#define AMDGPU_TILING_GFX12_SWIZZLE_MODE_MASK 0x7414414-/* These are DCC recompression setting for memory management: */414414+/* These are DCC recompression settings for memory management: */415415#define AMDGPU_TILING_GFX12_DCC_MAX_COMPRESSED_BLOCK_SHIFT 3416416#define AMDGPU_TILING_GFX12_DCC_MAX_COMPRESSED_BLOCK_MASK 0x3 /* 0:64B, 1:128B, 2:256B */417417#define AMDGPU_TILING_GFX12_DCC_NUMBER_TYPE_SHIFT 5418418#define AMDGPU_TILING_GFX12_DCC_NUMBER_TYPE_MASK 0x7 /* CB_COLOR0_INFO.NUMBER_TYPE */419419#define AMDGPU_TILING_GFX12_DCC_DATA_FORMAT_SHIFT 8420420#define AMDGPU_TILING_GFX12_DCC_DATA_FORMAT_MASK 0x3f /* [0:4]:CB_COLOR0_INFO.FORMAT, [5]:MM */421421+/* When clearing the buffer or moving it from VRAM to GTT, don't compress and set DCC metadata422422+ * to uncompressed. Set when parts of an allocation bypass DCC and read raw data. */423423+#define AMDGPU_TILING_GFX12_DCC_WRITE_COMPRESS_DISABLE_SHIFT 14424424+#define AMDGPU_TILING_GFX12_DCC_WRITE_COMPRESS_DISABLE_MASK 0x1425425+/* bit gap */426426+#define AMDGPU_TILING_GFX12_SCANOUT_SHIFT 63427427+#define AMDGPU_TILING_GFX12_SCANOUT_MASK 0x1421428422429/* Set/Get helpers for tiling flags. */423430#define AMDGPU_TILING_SET(field, value) \
+2
include/uapi/linux/ethtool.h
···682682 * @ETH_SS_STATS_ETH_CTRL: names of IEEE 802.3 MAC Control statistics683683 * @ETH_SS_STATS_RMON: names of RMON statistics684684 * @ETH_SS_STATS_PHY: names of PHY(dev) statistics685685+ * @ETH_SS_TS_FLAGS: hardware timestamping flags685686 *686687 * @ETH_SS_COUNT: number of defined string sets687688 */···709708 ETH_SS_STATS_ETH_CTRL,710709 ETH_SS_STATS_RMON,711710 ETH_SS_STATS_PHY,711711+ ETH_SS_TS_FLAGS,712712713713 /* add new constants above here */714714 ETH_SS_COUNT
···285285}286286287287extern void __futex_unqueue(struct futex_q *q);288288-extern void __futex_queue(struct futex_q *q, struct futex_hash_bucket *hb);288288+extern void __futex_queue(struct futex_q *q, struct futex_hash_bucket *hb,289289+ struct task_struct *task);289290extern int futex_unqueue(struct futex_q *q);290291291292/**292293 * futex_queue() - Enqueue the futex_q on the futex_hash_bucket293294 * @q: The futex_q to enqueue294295 * @hb: The destination hash bucket296296+ * @task: Task queueing this futex295297 *296298 * The hb->lock must be held by the caller, and is released here. A call to297299 * futex_queue() is typically paired with exactly one call to futex_unqueue(). The···301299 * or nothing if the unqueue is done as part of the wake process and the unqueue302300 * state is implicit in the state of woken task (see futex_wait_requeue_pi() for303301 * an example).302302+ *303303+ * Note that @task may be NULL, for async usage of futexes.304304 */305305-static inline void futex_queue(struct futex_q *q, struct futex_hash_bucket *hb)305305+static inline void futex_queue(struct futex_q *q, struct futex_hash_bucket *hb,306306+ struct task_struct *task)306307 __releases(&hb->lock)307308{308308- __futex_queue(q, hb);309309+ __futex_queue(q, hb, task);309310 spin_unlock(&hb->lock);310311}311312
+1-1
kernel/futex/pi.c
···982982 /*983983 * Only actually queue now that the atomic ops are done:984984 */985985- __futex_queue(&q, hb);985985+ __futex_queue(&q, hb, current);986986987987 if (trylock) {988988 ret = rt_mutex_futex_trylock(&q.pi_state->pi_mutex);
+2-2
kernel/futex/waitwake.c
···349349 * access to the hash list and forcing another memory barrier.350350 */351351 set_current_state(TASK_INTERRUPTIBLE|TASK_FREEZABLE);352352- futex_queue(q, hb);352352+ futex_queue(q, hb, current);353353354354 /* Arm the timer */355355 if (timeout)···460460 * next futex. Queue each futex at this moment so hb can461461 * be unlocked.462462 */463463- futex_queue(q, hb);463463+ futex_queue(q, hb, current);464464 continue;465465 }466466
+2
kernel/sched/debug.c
···12621262 if (task_has_dl_policy(p)) {12631263 P(dl.runtime);12641264 P(dl.deadline);12651265+ } else if (fair_policy(p->policy)) {12661266+ P(se.slice);12651267 }12661268#ifdef CONFIG_SCHED_CLASS_EXT12671269 __PS("ext.enabled", task_on_scx(p));
+19
kernel/sched/fair.c
···53855385static void set_delayed(struct sched_entity *se)53865386{53875387 se->sched_delayed = 1;53885388+53895389+ /*53905390+ * Delayed se of cfs_rq have no tasks queued on them.53915391+ * Do not adjust h_nr_runnable since dequeue_entities()53925392+ * will account it for blocked tasks.53935393+ */53945394+ if (!entity_is_task(se))53955395+ return;53965396+53885397 for_each_sched_entity(se) {53895398 struct cfs_rq *cfs_rq = cfs_rq_of(se);53905399···54065397static void clear_delayed(struct sched_entity *se)54075398{54085399 se->sched_delayed = 0;54005400+54015401+ /*54025402+ * Delayed se of cfs_rq have no tasks queued on them.54035403+ * Do not adjust h_nr_runnable since a dequeue has54045404+ * already accounted for it or an enqueue of a task54055405+ * below it will account for it in enqueue_task_fair().54065406+ */54075407+ if (!entity_is_task(se))54085408+ return;54095409+54095410 for_each_sched_entity(se) {54105411 struct cfs_rq *cfs_rq = cfs_rq_of(se);54115412
+12
kernel/seccomp.c
···749749 if (WARN_ON_ONCE(!fprog))750750 return false;751751752752+ /* Our single exception to filtering. */753753+#ifdef __NR_uretprobe754754+#ifdef SECCOMP_ARCH_COMPAT755755+ if (sd->arch == SECCOMP_ARCH_NATIVE)756756+#endif757757+ if (sd->nr == __NR_uretprobe)758758+ return true;759759+#endif760760+752761 for (pc = 0; pc < fprog->len; pc++) {753762 struct sock_filter *insn = &fprog->filter[pc];754763 u16 code = insn->code;···10321023 */10331024static const int mode1_syscalls[] = {10341025 __NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, __NR_seccomp_sigreturn,10261026+#ifdef __NR_uretprobe10271027+ __NR_uretprobe,10281028+#endif10351029 -1, /* negative terminated */10361030};10371031
+4-2
kernel/time/clocksource.c
···373373 cpumask_clear(&cpus_ahead);374374 cpumask_clear(&cpus_behind);375375 cpus_read_lock();376376- preempt_disable();376376+ migrate_disable();377377 clocksource_verify_choose_cpus();378378 if (cpumask_empty(&cpus_chosen)) {379379- preempt_enable();379379+ migrate_enable();380380 cpus_read_unlock();381381 pr_warn("Not enough CPUs to check clocksource '%s'.\n", cs->name);382382 return;···384384 testcpu = smp_processor_id();385385 pr_info("Checking clocksource %s synchronization from CPU %d to CPUs %*pbl.\n",386386 cs->name, testcpu, cpumask_pr_args(&cpus_chosen));387387+ preempt_disable();387388 for_each_cpu(cpu, &cpus_chosen) {388389 if (cpu == testcpu)389390 continue;···404403 cs_nsec_min = cs_nsec;405404 }406405 preempt_enable();406406+ migrate_enable();407407 cpus_read_unlock();408408 if (!cpumask_empty(&cpus_ahead))409409 pr_warn(" CPUs %*pbl ahead of CPU %d for clocksource %s.\n",
+9-1
kernel/time/timer_migration.c
···1675167516761676 } while (i < tmigr_hierarchy_levels);1677167716781678+ /* Assert single root */16791679+ WARN_ON_ONCE(!err && !group->parent && !list_is_singular(&tmigr_level_list[top]));16801680+16781681 while (i > 0) {16791682 group = stack[--i];16801683···17191716 WARN_ON_ONCE(top == 0);1720171717211718 lvllist = &tmigr_level_list[top];17221722- if (group->num_children == 1 && list_is_singular(lvllist)) {17191719+17201720+ /*17211721+ * Newly created root level should have accounted the upcoming17221722+ * CPU's child group and pre-accounted the old root.17231723+ */17241724+ if (group->num_children == 2 && list_is_singular(lvllist)) {17231725 /*17241726 * The target CPU must never do the prepare work, except17251727 * on early boot when the boot CPU is the target. Otherwise
+1-1
kernel/trace/trace_functions_graph.c
···198198 * returning from the function.199199 */200200 if (ftrace_graph_notrace_addr(trace->func)) {201201- *task_var |= TRACE_GRAPH_NOTRACE_BIT;201201+ *task_var |= TRACE_GRAPH_NOTRACE;202202 /*203203 * Need to return 1 to have the return called204204 * that will clear the NOTRACE bit.
+4-2
lib/stackinit_kunit.c
···7575 */7676#ifdef CONFIG_M68K7777#define FILL_SIZE_STRING 87878+#define FILL_SIZE_ARRAY 27879#else7980#define FILL_SIZE_STRING 168181+#define FILL_SIZE_ARRAY 88082#endif81838284#define INIT_CLONE_SCALAR /**/···347345 short three;348346 unsigned long four;349347 struct big_struct {350350- unsigned long array[8];348348+ unsigned long array[FILL_SIZE_ARRAY];351349 } big;352350};353351354354-/* Mismatched sizes, with one and two being small */352352+/* Mismatched sizes, with three and four being small */355353union test_small_end {356354 short one;357355 unsigned long two;
···1818#include <linux/if_ether.h>1919#include <linux/jiffies.h>2020#include <linux/kref.h>2121+#include <linux/list.h>2122#include <linux/minmax.h>2223#include <linux/netdevice.h>2324#include <linux/nl80211.h>···2726#include <linux/rcupdate.h>2827#include <linux/rtnetlink.h>2928#include <linux/skbuff.h>2929+#include <linux/slab.h>3030#include <linux/stddef.h>3131#include <linux/string.h>3232#include <linux/types.h>···4240#include "originator.h"4341#include "routing.h"4442#include "send.h"4343+4444+/**4545+ * struct batadv_v_metric_queue_entry - list of hardif neighbors which require4646+ * and metric update4747+ */4848+struct batadv_v_metric_queue_entry {4949+ /** @hardif_neigh: hardif neighbor scheduled for metric update */5050+ struct batadv_hardif_neigh_node *hardif_neigh;5151+5252+ /** @list: list node for metric_queue */5353+ struct list_head list;5454+};45554656/**4757 * batadv_v_elp_start_timer() - restart timer for ELP periodic work···7359/**7460 * batadv_v_elp_get_throughput() - get the throughput towards a neighbour7561 * @neigh: the neighbour for which the throughput has to be obtained6262+ * @pthroughput: calculated throughput towards the given neighbour in multiples6363+ * of 100kpbs (a value of '1' equals 0.1Mbps, '10' equals 1Mbps, etc).7664 *7777- * Return: The throughput towards the given neighbour in multiples of 100kpbs7878- * (a value of '1' equals 0.1Mbps, '10' equals 1Mbps, etc).6565+ * Return: true when value behind @pthroughput was set7966 */8080-static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)6767+static bool batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh,6868+ u32 *pthroughput)8169{8270 struct batadv_hard_iface *hard_iface = neigh->if_incoming;7171+ struct net_device *soft_iface = hard_iface->soft_iface;8372 struct ethtool_link_ksettings link_settings;8473 struct net_device *real_netdev;8574 struct station_info sinfo;8675 u32 throughput;8776 int ret;88777878+ /* don't query throughput when no longer associated with any7979+ * batman-adv interface8080+ */8181+ if (!soft_iface)8282+ return false;8383+8984 /* if the user specified a customised value for this interface, then9085 * return it directly9186 */9287 throughput = atomic_read(&hard_iface->bat_v.throughput_override);9393- if (throughput != 0)9494- return throughput;8888+ if (throughput != 0) {8989+ *pthroughput = throughput;9090+ return true;9191+ }95929693 /* if this is a wireless device, then ask its throughput through9794 * cfg80211 API···129104 * possible to delete this neighbor. For now set130105 * the throughput metric to 0.131106 */132132- return 0;107107+ *pthroughput = 0;108108+ return true;133109 }134110 if (ret)135111 goto default_throughput;136112137137- if (sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT))138138- return sinfo.expected_throughput / 100;113113+ if (sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT)) {114114+ *pthroughput = sinfo.expected_throughput / 100;115115+ return true;116116+ }139117140118 /* try to estimate the expected throughput based on reported tx141119 * rates142120 */143143- if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE))144144- return cfg80211_calculate_bitrate(&sinfo.txrate) / 3;121121+ if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {122122+ *pthroughput = cfg80211_calculate_bitrate(&sinfo.txrate) / 3;123123+ return true;124124+ }145125146126 goto default_throughput;147127 }148128129129+ /* only use rtnl_trylock because the elp worker will be cancelled while130130+ * the rntl_lock is held. the cancel_delayed_work_sync() would otherwise131131+ * wait forever when the elp work_item was started and it is then also132132+ * trying to rtnl_lock133133+ */134134+ if (!rtnl_trylock())135135+ return false;136136+149137 /* if not a wifi interface, check if this device provides data via150138 * ethtool (e.g. an Ethernet adapter)151139 */152152- rtnl_lock();153140 ret = __ethtool_get_link_ksettings(hard_iface->net_dev, &link_settings);154141 rtnl_unlock();155142 if (ret == 0) {···172135 hard_iface->bat_v.flags &= ~BATADV_FULL_DUPLEX;173136174137 throughput = link_settings.base.speed;175175- if (throughput && throughput != SPEED_UNKNOWN)176176- return throughput * 10;138138+ if (throughput && throughput != SPEED_UNKNOWN) {139139+ *pthroughput = throughput * 10;140140+ return true;141141+ }177142 }178143179144default_throughput:180145 if (!(hard_iface->bat_v.flags & BATADV_WARNING_DEFAULT)) {181181- batadv_info(hard_iface->soft_iface,146146+ batadv_info(soft_iface,182147 "WiFi driver or ethtool info does not provide information about link speeds on interface %s, therefore defaulting to hardcoded throughput values of %u.%1u Mbps. Consider overriding the throughput manually or checking your driver.\n",183148 hard_iface->net_dev->name,184149 BATADV_THROUGHPUT_DEFAULT_VALUE / 10,···189150 }190151191152 /* if none of the above cases apply, return the base_throughput */192192- return BATADV_THROUGHPUT_DEFAULT_VALUE;153153+ *pthroughput = BATADV_THROUGHPUT_DEFAULT_VALUE;154154+ return true;193155}194156195157/**196158 * batadv_v_elp_throughput_metric_update() - worker updating the throughput197159 * metric of a single hop neighbour198198- * @work: the work queue item160160+ * @neigh: the neighbour to probe199161 */200200-void batadv_v_elp_throughput_metric_update(struct work_struct *work)162162+static void163163+batadv_v_elp_throughput_metric_update(struct batadv_hardif_neigh_node *neigh)201164{202202- struct batadv_hardif_neigh_node_bat_v *neigh_bat_v;203203- struct batadv_hardif_neigh_node *neigh;165165+ u32 throughput;166166+ bool valid;204167205205- neigh_bat_v = container_of(work, struct batadv_hardif_neigh_node_bat_v,206206- metric_work);207207- neigh = container_of(neigh_bat_v, struct batadv_hardif_neigh_node,208208- bat_v);168168+ valid = batadv_v_elp_get_throughput(neigh, &throughput);169169+ if (!valid)170170+ return;209171210210- ewma_throughput_add(&neigh->bat_v.throughput,211211- batadv_v_elp_get_throughput(neigh));212212-213213- /* decrement refcounter to balance increment performed before scheduling214214- * this task215215- */216216- batadv_hardif_neigh_put(neigh);172172+ ewma_throughput_add(&neigh->bat_v.throughput, throughput);217173}218174219175/**···282248 */283249static void batadv_v_elp_periodic_work(struct work_struct *work)284250{251251+ struct batadv_v_metric_queue_entry *metric_entry;252252+ struct batadv_v_metric_queue_entry *metric_safe;285253 struct batadv_hardif_neigh_node *hardif_neigh;286254 struct batadv_hard_iface *hard_iface;287255 struct batadv_hard_iface_bat_v *bat_v;288256 struct batadv_elp_packet *elp_packet;257257+ struct list_head metric_queue;289258 struct batadv_priv *bat_priv;290259 struct sk_buff *skb;291260 u32 elp_interval;292292- bool ret;293261294262 bat_v = container_of(work, struct batadv_hard_iface_bat_v, elp_wq.work);295263 hard_iface = container_of(bat_v, struct batadv_hard_iface, bat_v);···327291328292 atomic_inc(&hard_iface->bat_v.elp_seqno);329293294294+ INIT_LIST_HEAD(&metric_queue);295295+330296 /* The throughput metric is updated on each sent packet. This way, if a331297 * node is dead and no longer sends packets, batman-adv is still able to332298 * react timely to its death.···353315354316 /* Reading the estimated throughput from cfg80211 is a task that355317 * may sleep and that is not allowed in an rcu protected356356- * context. Therefore schedule a task for that.318318+ * context. Therefore add it to metric_queue and process it319319+ * outside rcu protected context.357320 */358358- ret = queue_work(batadv_event_workqueue,359359- &hardif_neigh->bat_v.metric_work);360360-361361- if (!ret)321321+ metric_entry = kzalloc(sizeof(*metric_entry), GFP_ATOMIC);322322+ if (!metric_entry) {362323 batadv_hardif_neigh_put(hardif_neigh);324324+ continue;325325+ }326326+327327+ metric_entry->hardif_neigh = hardif_neigh;328328+ list_add(&metric_entry->list, &metric_queue);363329 }364330 rcu_read_unlock();331331+332332+ list_for_each_entry_safe(metric_entry, metric_safe, &metric_queue, list) {333333+ batadv_v_elp_throughput_metric_update(metric_entry->hardif_neigh);334334+335335+ batadv_hardif_neigh_put(metric_entry->hardif_neigh);336336+ list_del(&metric_entry->list);337337+ kfree(metric_entry);338338+ }365339366340restart_timer:367341 batadv_v_elp_start_timer(hard_iface);
···596596 * neighbor597597 */598598 unsigned long last_unicast_tx;599599-600600- /** @metric_work: work queue callback item for metric update */601601- struct work_struct metric_work;602599};603600604601/**
+1-2
net/bluetooth/hidp/Kconfig
···11# SPDX-License-Identifier: GPL-2.0-only22config BT_HIDP33 tristate "HIDP protocol support"44- depends on BT_BREDR && INPUT && HID_SUPPORT55- select HID44+ depends on BT_BREDR && HID65 help76 HIDP (Human Interface Device Protocol) is a transport layer87 for HID reports. HIDP is required for the Bluetooth Human
+79-90
net/bluetooth/l2cap_core.c
···119119{120120 struct l2cap_chan *c;121121122122- mutex_lock(&conn->chan_lock);123122 c = __l2cap_get_chan_by_scid(conn, cid);124123 if (c) {125124 /* Only lock if chan reference is not 0 */···126127 if (c)127128 l2cap_chan_lock(c);128129 }129129- mutex_unlock(&conn->chan_lock);130130131131 return c;132132}···138140{139141 struct l2cap_chan *c;140142141141- mutex_lock(&conn->chan_lock);142143 c = __l2cap_get_chan_by_dcid(conn, cid);143144 if (c) {144145 /* Only lock if chan reference is not 0 */···145148 if (c)146149 l2cap_chan_lock(c);147150 }148148- mutex_unlock(&conn->chan_lock);149151150152 return c;151153}···414418 if (!conn)415419 return;416420417417- mutex_lock(&conn->chan_lock);421421+ mutex_lock(&conn->lock);418422 /* __set_chan_timer() calls l2cap_chan_hold(chan) while scheduling419423 * this work. No need to call l2cap_chan_hold(chan) here again.420424 */···435439 l2cap_chan_unlock(chan);436440 l2cap_chan_put(chan);437441438438- mutex_unlock(&conn->chan_lock);442442+ mutex_unlock(&conn->lock);439443}440444441445struct l2cap_chan *l2cap_chan_create(void)···637641638642void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)639643{640640- mutex_lock(&conn->chan_lock);644644+ mutex_lock(&conn->lock);641645 __l2cap_chan_add(conn, chan);642642- mutex_unlock(&conn->chan_lock);646646+ mutex_unlock(&conn->lock);643647}644648645649void l2cap_chan_del(struct l2cap_chan *chan, int err)···727731 if (!conn)728732 return;729733730730- mutex_lock(&conn->chan_lock);734734+ mutex_lock(&conn->lock);731735 __l2cap_chan_list(conn, func, data);732732- mutex_unlock(&conn->chan_lock);736736+ mutex_unlock(&conn->lock);733737}734738735739EXPORT_SYMBOL_GPL(l2cap_chan_list);···741745 struct hci_conn *hcon = conn->hcon;742746 struct l2cap_chan *chan;743747744744- mutex_lock(&conn->chan_lock);748748+ mutex_lock(&conn->lock);745749746750 list_for_each_entry(chan, &conn->chan_l, list) {747751 l2cap_chan_lock(chan);···750754 l2cap_chan_unlock(chan);751755 }752756753753- mutex_unlock(&conn->chan_lock);757757+ mutex_unlock(&conn->lock);754758}755759756760static void l2cap_chan_le_connect_reject(struct l2cap_chan *chan)···944948 return id;945949}946950951951+static void l2cap_send_acl(struct l2cap_conn *conn, struct sk_buff *skb,952952+ u8 flags)953953+{954954+ /* Check if the hcon still valid before attempting to send */955955+ if (hci_conn_valid(conn->hcon->hdev, conn->hcon))956956+ hci_send_acl(conn->hchan, skb, flags);957957+ else958958+ kfree_skb(skb);959959+}960960+947961static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,948962 void *data)949963{···976970 bt_cb(skb)->force_active = BT_POWER_FORCE_ACTIVE_ON;977971 skb->priority = HCI_PRIO_MAX;978972979979- hci_send_acl(conn->hchan, skb, flags);973973+ l2cap_send_acl(conn, skb, flags);980974}981975982976static void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb)···1503149715041498 BT_DBG("conn %p", conn);1505149915061506- mutex_lock(&conn->chan_lock);15071507-15081500 list_for_each_entry_safe(chan, tmp, &conn->chan_l, list) {15091501 l2cap_chan_lock(chan);15101502···1571156715721568 l2cap_chan_unlock(chan);15731569 }15741574-15751575- mutex_unlock(&conn->chan_lock);15761570}1577157115781572static void l2cap_le_conn_ready(struct l2cap_conn *conn)···16161614 if (hcon->type == ACL_LINK)16171615 l2cap_request_info(conn);1618161616191619- mutex_lock(&conn->chan_lock);16171617+ mutex_lock(&conn->lock);1620161816211619 list_for_each_entry(chan, &conn->chan_l, list) {16221620···16341632 l2cap_chan_unlock(chan);16351633 }1636163416371637- mutex_unlock(&conn->chan_lock);16351635+ mutex_unlock(&conn->lock);1638163616391637 if (hcon->type == LE_LINK)16401638 l2cap_le_conn_ready(conn);···1649164716501648 BT_DBG("conn %p", conn);1651164916521652- mutex_lock(&conn->chan_lock);16531653-16541650 list_for_each_entry(chan, &conn->chan_l, list) {16551651 if (test_bit(FLAG_FORCE_RELIABLE, &chan->flags))16561652 l2cap_chan_set_err(chan, err);16571653 }16581658-16591659- mutex_unlock(&conn->chan_lock);16601654}1661165516621656static void l2cap_info_timeout(struct work_struct *work)···16631665 conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;16641666 conn->info_ident = 0;1665166716681668+ mutex_lock(&conn->lock);16661669 l2cap_conn_start(conn);16701670+ mutex_unlock(&conn->lock);16671671}1668167216691673/*···1757175717581758 BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);1759175917601760+ mutex_lock(&conn->lock);17611761+17601762 kfree_skb(conn->rx_skb);1761176317621764 skb_queue_purge(&conn->pending_rx);···17771775 /* Force the connection to be immediately dropped */17781776 hcon->disc_timeout = 0;1779177717801780- mutex_lock(&conn->chan_lock);17811781-17821778 /* Kill channels */17831779 list_for_each_entry_safe(chan, l, &conn->chan_l, list) {17841780 l2cap_chan_hold(chan);···17901790 l2cap_chan_put(chan);17911791 }1792179217931793- mutex_unlock(&conn->chan_lock);17941794-17951795- hci_chan_del(conn->hchan);17961796-17971793 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT)17981794 cancel_delayed_work_sync(&conn->info_timer);1799179518001800- hcon->l2cap_data = NULL;17961796+ hci_chan_del(conn->hchan);18011797 conn->hchan = NULL;17981798+17991799+ hcon->l2cap_data = NULL;18001800+ mutex_unlock(&conn->lock);18021801 l2cap_conn_put(conn);18031802}18041803···2915291629162917 BT_DBG("conn %p", conn);2917291829182918- mutex_lock(&conn->chan_lock);29192919-29202919 list_for_each_entry(chan, &conn->chan_l, list) {29212920 if (chan->chan_type != L2CAP_CHAN_RAW)29222921 continue;···29292932 if (chan->ops->recv(chan, nskb))29302933 kfree_skb(nskb);29312934 }29322932-29332933- mutex_unlock(&conn->chan_lock);29342935}2935293629362937/* ---- L2CAP signalling commands ---- */···39473952 goto response;39483953 }3949395439503950- mutex_lock(&conn->chan_lock);39513955 l2cap_chan_lock(pchan);3952395639533957 /* Check if the ACL is secure enough (if not SDP) */···40534059 }4054406040554061 l2cap_chan_unlock(pchan);40564056- mutex_unlock(&conn->chan_lock);40574062 l2cap_chan_put(pchan);40584063}40594064···40914098 BT_DBG("dcid 0x%4.4x scid 0x%4.4x result 0x%2.2x status 0x%2.2x",40924099 dcid, scid, result, status);4093410040944094- mutex_lock(&conn->chan_lock);40954095-40964101 if (scid) {40974102 chan = __l2cap_get_chan_by_scid(conn, scid);40984098- if (!chan) {40994099- err = -EBADSLT;41004100- goto unlock;41014101- }41034103+ if (!chan)41044104+ return -EBADSLT;41024105 } else {41034106 chan = __l2cap_get_chan_by_ident(conn, cmd->ident);41044104- if (!chan) {41054105- err = -EBADSLT;41064106- goto unlock;41074107- }41074107+ if (!chan)41084108+ return -EBADSLT;41084109 }4109411041104111 chan = l2cap_chan_hold_unless_zero(chan);41114111- if (!chan) {41124112- err = -EBADSLT;41134113- goto unlock;41144114- }41124112+ if (!chan)41134113+ return -EBADSLT;4115411441164115 err = 0;41174116···4140415541414156 l2cap_chan_unlock(chan);41424157 l2cap_chan_put(chan);41434143-41444144-unlock:41454145- mutex_unlock(&conn->chan_lock);4146415841474159 return err;41484160}···4428444644294447 chan->ops->set_shutdown(chan);4430444844314431- l2cap_chan_unlock(chan);44324432- mutex_lock(&conn->chan_lock);44334433- l2cap_chan_lock(chan);44344449 l2cap_chan_del(chan, ECONNRESET);44354435- mutex_unlock(&conn->chan_lock);4436445044374451 chan->ops->close(chan);44384452···44654487 return 0;44664488 }4467448944684468- l2cap_chan_unlock(chan);44694469- mutex_lock(&conn->chan_lock);44704470- l2cap_chan_lock(chan);44714490 l2cap_chan_del(chan, 0);44724472- mutex_unlock(&conn->chan_lock);4473449144744492 chan->ops->close(chan);44754493···46634689 BT_DBG("dcid 0x%4.4x mtu %u mps %u credits %u result 0x%2.2x",46644690 dcid, mtu, mps, credits, result);4665469146664666- mutex_lock(&conn->chan_lock);46674667-46684692 chan = __l2cap_get_chan_by_ident(conn, cmd->ident);46694669- if (!chan) {46704670- err = -EBADSLT;46714671- goto unlock;46724672- }46934693+ if (!chan)46944694+ return -EBADSLT;4673469546744696 err = 0;46754697···47124742 }4713474347144744 l2cap_chan_unlock(chan);47154715-47164716-unlock:47174717- mutex_unlock(&conn->chan_lock);4718474547194746 return err;47204747}···48244857 goto response;48254858 }4826485948274827- mutex_lock(&conn->chan_lock);48284860 l2cap_chan_lock(pchan);4829486148304862 if (!smp_sufficient_security(conn->hcon, pchan->sec_level,···4889492348904924response_unlock:48914925 l2cap_chan_unlock(pchan);48924892- mutex_unlock(&conn->chan_lock);48934926 l2cap_chan_put(pchan);4894492748954928 if (result == L2CAP_CR_PEND)···50225057 goto response;50235058 }5024505950255025- mutex_lock(&conn->chan_lock);50265060 l2cap_chan_lock(pchan);5027506150285062 if (!smp_sufficient_security(conn->hcon, pchan->sec_level,···5096513250975133unlock:50985134 l2cap_chan_unlock(pchan);50995099- mutex_unlock(&conn->chan_lock);51005135 l2cap_chan_put(pchan);5101513651025137response:···5131516851325169 BT_DBG("mtu %u mps %u credits %u result 0x%4.4x", mtu, mps, credits,51335170 result);51345134-51355135- mutex_lock(&conn->chan_lock);5136517151375172 cmd_len -= sizeof(*rsp);51385173···5216525552175256 l2cap_chan_unlock(chan);52185257 }52195219-52205220- mutex_unlock(&conn->chan_lock);5221525852225259 return err;52235260}···53295370 if (cmd_len < sizeof(*rej))53305371 return -EPROTO;5331537253325332- mutex_lock(&conn->chan_lock);53335333-53345373 chan = __l2cap_get_chan_by_ident(conn, cmd->ident);53355374 if (!chan)53365375 goto done;···53435386 l2cap_chan_put(chan);5344538753455388done:53465346- mutex_unlock(&conn->chan_lock);53475389 return 0;53485390}53495391···6797684167986842 BT_DBG("");6799684368446844+ mutex_lock(&conn->lock);68456845+68006846 while ((skb = skb_dequeue(&conn->pending_rx)))68016847 l2cap_recv_frame(conn, skb);68486848+68496849+ mutex_unlock(&conn->lock);68026850}6803685168046852static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)···68416881 conn->local_fixed_chan |= L2CAP_FC_SMP_BREDR;6842688268436883 mutex_init(&conn->ident_lock);68446844- mutex_init(&conn->chan_lock);68846884+ mutex_init(&conn->lock);6845688568466886 INIT_LIST_HEAD(&conn->chan_l);68476887 INIT_LIST_HEAD(&conn->users);···70327072 }70337073 }7034707470357035- mutex_lock(&conn->chan_lock);70757075+ mutex_lock(&conn->lock);70367076 l2cap_chan_lock(chan);7037707770387078 if (cid && __l2cap_get_chan_by_dcid(conn, cid)) {···7073711370747114chan_unlock:70757115 l2cap_chan_unlock(chan);70767076- mutex_unlock(&conn->chan_lock);71167116+ mutex_unlock(&conn->lock);70777117done:70787118 hci_dev_unlock(hdev);70797119 hci_dev_put(hdev);···7285732572867326 BT_DBG("conn %p status 0x%2.2x encrypt %u", conn, status, encrypt);7287732772887288- mutex_lock(&conn->chan_lock);73287328+ mutex_lock(&conn->lock);7289732972907330 list_for_each_entry(chan, &conn->chan_l, list) {72917331 l2cap_chan_lock(chan);···73597399 l2cap_chan_unlock(chan);73607400 }7361740173627362- mutex_unlock(&conn->chan_lock);74027402+ mutex_unlock(&conn->lock);73637403}7364740473657405/* Append fragment into frame respecting the maximum len of rx_skb */···74267466 conn->rx_len = 0;74277467}7428746874697469+struct l2cap_conn *l2cap_conn_hold_unless_zero(struct l2cap_conn *c)74707470+{74717471+ if (!c)74727472+ return NULL;74737473+74747474+ BT_DBG("conn %p orig refcnt %u", c, kref_read(&c->ref));74757475+74767476+ if (!kref_get_unless_zero(&c->ref))74777477+ return NULL;74787478+74797479+ return c;74807480+}74817481+74297482void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)74307483{74317431- struct l2cap_conn *conn = hcon->l2cap_data;74847484+ struct l2cap_conn *conn;74327485 int len;74867486+74877487+ /* Lock hdev to access l2cap_data to avoid race with l2cap_conn_del */74887488+ hci_dev_lock(hcon->hdev);74897489+74907490+ conn = hcon->l2cap_data;7433749174347492 if (!conn)74357493 conn = l2cap_conn_add(hcon);7436749474377437- if (!conn)74387438- goto drop;74957495+ conn = l2cap_conn_hold_unless_zero(conn);74967496+74977497+ hci_dev_unlock(hcon->hdev);74987498+74997499+ if (!conn) {75007500+ kfree_skb(skb);75017501+ return;75027502+ }7439750374407504 BT_DBG("conn %p len %u flags 0x%x", conn, skb->len, flags);75057505+75067506+ mutex_lock(&conn->lock);7441750774427508 switch (flags) {74437509 case ACL_START:···74897503 if (len == skb->len) {74907504 /* Complete frame received */74917505 l2cap_recv_frame(conn, skb);74927492- return;75067506+ goto unlock;74937507 }7494750874957509 BT_DBG("Start: total len %d, frag len %u", len, skb->len);···7553756775547568drop:75557569 kfree_skb(skb);75707570+unlock:75717571+ mutex_unlock(&conn->lock);75727572+ l2cap_conn_put(conn);75567573}7557757475587575static struct hci_cb l2cap_cb = {
+7-8
net/bluetooth/l2cap_sock.c
···13261326 /* prevent sk structure from being freed whilst unlocked */13271327 sock_hold(sk);1328132813291329- chan = l2cap_pi(sk)->chan;13301329 /* prevent chan structure from being freed whilst unlocked */13311331- l2cap_chan_hold(chan);13301330+ chan = l2cap_chan_hold_unless_zero(l2cap_pi(sk)->chan);13311331+ if (!chan)13321332+ goto shutdown_already;1332133313331334 BT_DBG("chan %p state %s", chan, state_to_string(chan->state));13341335···13591358 release_sock(sk);1360135913611360 l2cap_chan_lock(chan);13621362- conn = chan->conn;13631363- if (conn)13641364- /* prevent conn structure from being freed */13651365- l2cap_conn_get(conn);13611361+ /* prevent conn structure from being freed */13621362+ conn = l2cap_conn_hold_unless_zero(chan->conn);13661363 l2cap_chan_unlock(chan);1367136413681365 if (conn)13691366 /* mutex lock must be taken before l2cap_chan_lock() */13701370- mutex_lock(&conn->chan_lock);13671367+ mutex_lock(&conn->lock);1371136813721369 l2cap_chan_lock(chan);13731370 l2cap_chan_close(chan, 0);13741371 l2cap_chan_unlock(chan);1375137213761373 if (conn) {13771377- mutex_unlock(&conn->chan_lock);13741374+ mutex_unlock(&conn->lock);13781375 l2cap_conn_put(conn);13791376 }13801377
···418418{419419 int hlen = LL_RESERVED_SPACE(dev);420420 int tlen = dev->needed_tailroom;421421- struct sock *sk = dev_net(dev)->ipv6.ndisc_sk;422421 struct sk_buff *skb;423422424423 skb = alloc_skb(hlen + sizeof(struct ipv6hdr) + len + tlen, GFP_ATOMIC);425425- if (!skb) {426426- ND_PRINTK(0, err, "ndisc: %s failed to allocate an skb\n",427427- __func__);424424+ if (!skb)428425 return NULL;429429- }430426431427 skb->protocol = htons(ETH_P_IPV6);432428 skb->dev = dev;···433437 /* Manually assign socket ownership as we avoid calling434438 * sock_alloc_send_pskb() to bypass wmem buffer limits435439 */436436- skb_set_owner_w(skb, sk);440440+ rcu_read_lock();441441+ skb_set_owner_w(skb, dev_net_rcu(dev)->ipv6.ndisc_sk);442442+ rcu_read_unlock();437443438444 return skb;439445}···471473void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,472474 const struct in6_addr *saddr)473475{474474- struct dst_entry *dst = skb_dst(skb);475475- struct net *net = dev_net(skb->dev);476476- struct sock *sk = net->ipv6.ndisc_sk;477477- struct inet6_dev *idev;478478- int err;479476 struct icmp6hdr *icmp6h = icmp6_hdr(skb);477477+ struct dst_entry *dst = skb_dst(skb);478478+ struct inet6_dev *idev;479479+ struct net *net;480480+ struct sock *sk;481481+ int err;480482 u8 type;481483482484 type = icmp6h->icmp6_type;483485486486+ rcu_read_lock();487487+488488+ net = dev_net_rcu(skb->dev);489489+ sk = net->ipv6.ndisc_sk;484490 if (!dst) {485491 struct flowi6 fl6;486492 int oif = skb->dev->ifindex;···492490 icmpv6_flow_init(sk, &fl6, type, saddr, daddr, oif);493491 dst = icmp6_dst_alloc(skb->dev, &fl6);494492 if (IS_ERR(dst)) {493493+ rcu_read_unlock();495494 kfree_skb(skb);496495 return;497496 }···507504508505 ip6_nd_hdr(skb, saddr, daddr, READ_ONCE(inet6_sk(sk)->hop_limit), skb->len);509506510510- rcu_read_lock();511507 idev = __in6_dev_get(dst->dev);512508 IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);513509···16961694 bool ret;1697169516981696 if (netif_is_l3_master(skb->dev)) {16991699- dev = __dev_get_by_index(dev_net(skb->dev), IPCB(skb)->iif);16971697+ dev = dev_get_by_index_rcu(dev_net(skb->dev), IPCB(skb)->iif);17001698 if (!dev)17011699 return;17021700 }
+6-1
net/ipv6/route.c
···31963196{31973197 struct net_device *dev = dst->dev;31983198 unsigned int mtu = dst_mtu(dst);31993199- struct net *net = dev_net(dev);31993199+ struct net *net;3200320032013201 mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr);3202320232033203+ rcu_read_lock();32043204+32053205+ net = dev_net_rcu(dev);32033206 if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss)32043207 mtu = net->ipv6.sysctl.ip6_rt_min_advmss;32083208+32093209+ rcu_read_unlock();3205321032063211 /*32073212 * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and
···21012101{21022102 struct ovs_header *ovs_header;21032103 struct ovs_vport_stats vport_stats;21042104+ struct net *net_vport;21042105 int err;2105210621062107 ovs_header = genlmsg_put(skb, portid, seq, &dp_vport_genl_family,···21182117 nla_put_u32(skb, OVS_VPORT_ATTR_IFINDEX, vport->dev->ifindex))21192118 goto nla_put_failure;2120211921212121- if (!net_eq(net, dev_net(vport->dev))) {21222122- int id = peernet2id_alloc(net, dev_net(vport->dev), gfp);21202120+ rcu_read_lock();21212121+ net_vport = dev_net_rcu(vport->dev);21222122+ if (!net_eq(net, net_vport)) {21232123+ int id = peernet2id_alloc(net, net_vport, GFP_ATOMIC);2123212421242125 if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id))21252125- goto nla_put_failure;21262126+ goto nla_put_failure_unlock;21262127 }21282128+ rcu_read_unlock();2127212921282130 ovs_vport_get_stats(vport, &vport_stats);21292131 if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS,···21472143 genlmsg_end(skb, ovs_header);21482144 return 0;2149214521462146+nla_put_failure_unlock:21472147+ rcu_read_unlock();21502148nla_put_failure:21512149 err = -EMSGSIZE;21522150error:
+3-4
net/rxrpc/ar-internal.h
···327327 * packet with a maximum set of jumbo subpackets or a PING ACK padded328328 * out to 64K with zeropages for PMTUD.329329 */330330- struct kvec kvec[RXRPC_MAX_NR_JUMBO > 3 + 16 ?331331- RXRPC_MAX_NR_JUMBO : 3 + 16];330330+ struct kvec kvec[1 + RXRPC_MAX_NR_JUMBO > 3 + 16 ?331331+ 1 + RXRPC_MAX_NR_JUMBO : 3 + 16];332332};333333334334/*···874874#define RXRPC_TXBUF_RESENT 0x100 /* Set if has been resent */875875 __be16 cksum; /* Checksum to go in header */876876 bool jumboable; /* Can be non-terminal jumbo subpacket */877877- u8 nr_kvec; /* Amount of kvec[] used */878878- struct kvec kvec[1];877877+ void *data; /* Data with preceding jumbo header */879878};880879881880static inline bool rxrpc_sending_to_server(const struct rxrpc_txbuf *txb)
+35-15
net/rxrpc/output.c
···428428static size_t rxrpc_prepare_data_subpacket(struct rxrpc_call *call,429429 struct rxrpc_send_data_req *req,430430 struct rxrpc_txbuf *txb,431431+ struct rxrpc_wire_header *whdr,431432 rxrpc_serial_t serial, int subpkt)432433{433433- struct rxrpc_wire_header *whdr = txb->kvec[0].iov_base;434434- struct rxrpc_jumbo_header *jumbo = (void *)(whdr + 1) - sizeof(*jumbo);434434+ struct rxrpc_jumbo_header *jumbo = txb->data - sizeof(*jumbo);435435 enum rxrpc_req_ack_trace why;436436 struct rxrpc_connection *conn = call->conn;437437- struct kvec *kv = &call->local->kvec[subpkt];437437+ struct kvec *kv = &call->local->kvec[1 + subpkt];438438 size_t len = txb->pkt_len;439439 bool last;440440 u8 flags;···491491 }492492dont_set_request_ack:493493494494- /* The jumbo header overlays the wire header in the txbuf. */494494+ /* There's a jumbo header prepended to the data if we need it. */495495 if (subpkt < req->n - 1)496496 flags |= RXRPC_JUMBO_PACKET;497497 else498498 flags &= ~RXRPC_JUMBO_PACKET;499499 if (subpkt == 0) {500500 whdr->flags = flags;501501- whdr->serial = htonl(txb->serial);502501 whdr->cksum = txb->cksum;503503- whdr->serviceId = htons(conn->service_id);504504- kv->iov_base = whdr;505505- len += sizeof(*whdr);502502+ kv->iov_base = txb->data;506503 } else {507504 jumbo->flags = flags;508505 jumbo->pad = 0;···532535/*533536 * Prepare a (jumbo) packet for transmission.534537 */535535-static size_t rxrpc_prepare_data_packet(struct rxrpc_call *call, struct rxrpc_send_data_req *req)538538+static size_t rxrpc_prepare_data_packet(struct rxrpc_call *call,539539+ struct rxrpc_send_data_req *req,540540+ struct rxrpc_wire_header *whdr)536541{537542 struct rxrpc_txqueue *tq = req->tq;538543 rxrpc_serial_t serial;···547548548549 /* Each transmission of a Tx packet needs a new serial number */549550 serial = rxrpc_get_next_serials(call->conn, req->n);551551+552552+ whdr->epoch = htonl(call->conn->proto.epoch);553553+ whdr->cid = htonl(call->cid);554554+ whdr->callNumber = htonl(call->call_id);555555+ whdr->seq = htonl(seq);556556+ whdr->serial = htonl(serial);557557+ whdr->type = RXRPC_PACKET_TYPE_DATA;558558+ whdr->flags = 0;559559+ whdr->userStatus = 0;560560+ whdr->securityIndex = call->security_ix;561561+ whdr->_rsvd = 0;562562+ whdr->serviceId = htons(call->conn->service_id);550563551564 call->tx_last_serial = serial + req->n - 1;552565 call->tx_last_sent = req->now;···587576 if (i + 1 == req->n)588577 /* Only sample the last subpacket in a jumbo. */589578 __set_bit(ix, &tq->rtt_samples);590590- len += rxrpc_prepare_data_subpacket(call, req, txb, serial, i);579579+ len += rxrpc_prepare_data_subpacket(call, req, txb, whdr, serial, i);591580 serial++;592581 seq++;593582 i++;···629618 }630619631620 rxrpc_set_keepalive(call, req->now);621621+ page_frag_free(whdr);632622 return len;633623}634624···638626 */639627void rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_send_data_req *req)640628{629629+ struct rxrpc_wire_header *whdr;641630 struct rxrpc_connection *conn = call->conn;642631 enum rxrpc_tx_point frag;643632 struct rxrpc_txqueue *tq = req->tq;644633 struct rxrpc_txbuf *txb;645634 struct msghdr msg;646635 rxrpc_seq_t seq = req->seq;647647- size_t len;636636+ size_t len = sizeof(*whdr);648637 bool new_call = test_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags);649638 int ret, stat_ix;650639651640 _enter("%x,%x-%x", tq->qbase, seq, seq + req->n - 1);652641642642+ whdr = page_frag_alloc(&call->local->tx_alloc, sizeof(*whdr), GFP_NOFS);643643+ if (!whdr)644644+ return; /* Drop the packet if no memory. */645645+646646+ call->local->kvec[0].iov_base = whdr;647647+ call->local->kvec[0].iov_len = sizeof(*whdr);648648+653649 stat_ix = umin(req->n, ARRAY_SIZE(call->rxnet->stat_tx_jumbo)) - 1;654650 atomic_inc(&call->rxnet->stat_tx_jumbo[stat_ix]);655651656656- len = rxrpc_prepare_data_packet(call, req);652652+ len += rxrpc_prepare_data_packet(call, req, whdr);657653 txb = tq->bufs[seq & RXRPC_TXQ_MASK];658654659659- iov_iter_kvec(&msg.msg_iter, WRITE, call->local->kvec, req->n, len);655655+ iov_iter_kvec(&msg.msg_iter, WRITE, call->local->kvec, 1 + req->n, len);660656661657 msg.msg_name = &call->peer->srx.transport;662658 msg.msg_namelen = call->peer->srx.transport_len;···715695716696 if (ret == -EMSGSIZE) {717697 rxrpc_inc_stat(call->rxnet, stat_tx_data_send_msgsize);718718- trace_rxrpc_tx_packet(call->debug_id, call->local->kvec[0].iov_base, frag);698698+ trace_rxrpc_tx_packet(call->debug_id, whdr, frag);719699 ret = 0;720700 } else if (ret < 0) {721701 rxrpc_inc_stat(call->rxnet, stat_tx_data_send_fail);722702 trace_rxrpc_tx_fail(call->debug_id, txb->serial, ret, frag);723703 } else {724724- trace_rxrpc_tx_packet(call->debug_id, call->local->kvec[0].iov_base, frag);704704+ trace_rxrpc_tx_packet(call->debug_id, whdr, frag);725705 }726706727707 rxrpc_tx_backoff(call, ret);
···479479 sock->file = file;480480 file->private_data = sock;481481 stream_open(SOCK_INODE(sock), file);482482+ /*483483+ * Disable permission and pre-content events, but enable legacy484484+ * inotify events for legacy users.485485+ */486486+ file_set_fsnotify_mode(file, FMODE_NONOTIFY_PERM);482487 return file;483488}484489EXPORT_SYMBOL(sock_alloc_file);
+7-1
net/vmw_vsock/af_vsock.c
···824824 */825825 lock_sock_nested(sk, level);826826827827- sock_orphan(sk);827827+ /* Indicate to vsock_remove_sock() that the socket is being released and828828+ * can be removed from the bound_table. Unlike transport reassignment829829+ * case, where the socket must remain bound despite vsock_remove_sock()830830+ * being called from the transport release() callback.831831+ */832832+ sock_set_flag(sk, SOCK_DEAD);828833829834 if (vsk->transport)830835 vsk->transport->release(vsk);831836 else if (sock_type_connectible(sk->sk_type))832837 vsock_remove_sock(vsk);833838839839+ sock_orphan(sk);834840 sk->sk_shutdown = SHUTDOWN_MASK;835841836842 skb_queue_purge(&sk->sk_receive_queue);
···3131ifdef CONFIG_CC_IS_CLANG3232# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.3333KBUILD_CFLAGS += -Wno-gnu3434+3535+# Clang checks for overflow/truncation with '%p', while GCC does not:3636+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1112193737+KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)3838+KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)3439else35403641# gcc inanely warns about local variables called 'main'···110105KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)111106ifdef CONFIG_CC_IS_GCC112107KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)113113-else114114-# Clang checks for overflow/truncation with '%p', while GCC does not:115115-# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219116116-KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)117117-KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)118108endif119109KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)120110···133133KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare134134KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)135135KBUILD_CFLAGS += -Wno-enum-compare-conditional136136-KBUILD_CFLAGS += -Wno-enum-enum-conversion137136endif138137139138endif···155156KBUILD_CFLAGS += -Wno-missing-field-initializers156157KBUILD_CFLAGS += -Wno-type-limits157158KBUILD_CFLAGS += -Wno-shift-negative-value159159+160160+ifdef CONFIG_CC_IS_CLANG161161+KBUILD_CFLAGS += -Wno-enum-enum-conversion162162+endif158163159164ifdef CONFIG_CC_IS_GCC160165KBUILD_CFLAGS += -Wno-maybe-uninitialized
+1-1
scripts/Makefile.lib
···305305# These are shared by some Makefile.* files.306306307307ifdef CONFIG_LTO_CLANG308308-# Run $(LD) here to covert LLVM IR to ELF in the following cases:308308+# Run $(LD) here to convert LLVM IR to ELF in the following cases:309309# - when this object needs objtool processing, as objtool cannot process LLVM IR310310# - when this is a single-object module, as modpost cannot process LLVM IR311311cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
+18
scripts/generate_rust_target.rs
···165165 let option = "CONFIG_".to_owned() + option;166166 self.0.contains_key(&option)167167 }168168+169169+ /// Is the rustc version at least `major.minor.patch`?170170+ fn rustc_version_atleast(&self, major: u32, minor: u32, patch: u32) -> bool {171171+ let check_version = 100000 * major + 100 * minor + patch;172172+ let actual_version = self173173+ .0174174+ .get("CONFIG_RUSTC_VERSION")175175+ .unwrap()176176+ .parse::<u32>()177177+ .unwrap();178178+ check_version <= actual_version179179+ }168180}169181170182fn main() {···194182 }195183 } else if cfg.has("X86_64") {196184 ts.push("arch", "x86_64");185185+ if cfg.rustc_version_atleast(1, 86, 0) {186186+ ts.push("rustc-abi", "x86-softfloat");187187+ }197188 ts.push(198189 "data-layout",199190 "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",···230215 panic!("32-bit x86 only works under UML");231216 }232217 ts.push("arch", "x86");218218+ if cfg.rustc_version_atleast(1, 86, 0) {219219+ ts.push("rustc-abi", "x86-softfloat");220220+ }233221 ts.push(234222 "data-layout",235223 "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
+35
scripts/mod/modpost.c
···507507 info->modinfo_len = sechdrs[i].sh_size;508508 } else if (!strcmp(secname, ".export_symbol")) {509509 info->export_symbol_secndx = i;510510+ } else if (!strcmp(secname, ".no_trim_symbol")) {511511+ info->no_trim_symbol = (void *)hdr + sechdrs[i].sh_offset;512512+ info->no_trim_symbol_len = sechdrs[i].sh_size;510513 }511514512515 if (sechdrs[i].sh_type == SHT_SYMTAB) {···15691566 /* strip trailing .o */15701567 mod = new_module(modname, strlen(modname) - strlen(".o"));1571156815691569+ /* save .no_trim_symbol section for later use */15701570+ if (info.no_trim_symbol_len) {15711571+ mod->no_trim_symbol = xmalloc(info.no_trim_symbol_len);15721572+ memcpy(mod->no_trim_symbol, info.no_trim_symbol,15731573+ info.no_trim_symbol_len);15741574+ mod->no_trim_symbol_len = info.no_trim_symbol_len;15751575+ }15761576+15721577 if (!mod->is_vmlinux) {15731578 license = get_modinfo(&info, "license");15741579 if (!license)···17371726 }1738172717391728 free(buf);17291729+}17301730+17311731+/*17321732+ * Keep symbols recorded in the .no_trim_symbol section. This is necessary to17331733+ * prevent CONFIG_TRIM_UNUSED_KSYMS from dropping EXPORT_SYMBOL because17341734+ * symbol_get() relies on the symbol being present in the ksymtab for lookups.17351735+ */17361736+static void keep_no_trim_symbols(struct module *mod)17371737+{17381738+ unsigned long size = mod->no_trim_symbol_len;17391739+17401740+ for (char *s = mod->no_trim_symbol; s; s = next_string(s , &size)) {17411741+ struct symbol *sym;17421742+17431743+ /*17441744+ * If find_symbol() returns NULL, this symbol is not provided17451745+ * by any module, and symbol_get() will fail.17461746+ */17471747+ sym = find_symbol(s);17481748+ if (sym)17491749+ sym->used = true;17501750+ }17401751}1741175217421753static void check_modname_len(struct module *mod)···22872254 read_symbols_from_files(files_source);2288225522892256 list_for_each_entry(mod, &modules, list) {22572257+ keep_no_trim_symbols(mod);22582258+22902259 if (mod->dump_file || mod->is_vmlinux)22912260 continue;22922261
+6
scripts/mod/modpost.h
···111111 *112112 * @dump_file: path to the .symvers file if loaded from a file113113 * @aliases: list head for module_aliases114114+ * @no_trim_symbol: .no_trim_symbol section data115115+ * @no_trim_symbol_len: length of the .no_trim_symbol section114116 */115117struct module {116118 struct list_head list;···130128 // Actual imported namespaces131129 struct list_head imported_namespaces;132130 struct list_head aliases;131131+ char *no_trim_symbol;132132+ unsigned int no_trim_symbol_len;133133 char name[];134134};135135···145141 char *strtab;146142 char *modinfo;147143 unsigned int modinfo_len;144144+ char *no_trim_symbol;145145+ unsigned int no_trim_symbol_len;148146149147 /* support for 32bit section numbers */150148
···6363 # Clear VPATH and srcroot because the source files reside in the output6464 # directory.6565 # shellcheck disable=SC2016 # $(MAKE), $(CC), and $(build) will be expanded by Make6666- "${MAKE}" run-command KBUILD_RUN_COMMAND='+$(MAKE) HOSTCC=$(CC) VPATH= srcroot=. $(build)='"${destdir}"/scripts6666+ "${MAKE}" run-command KBUILD_RUN_COMMAND='+$(MAKE) HOSTCC="$(CC)" VPATH= srcroot=. $(build)='"${destdir}"/scripts67676868 rm -f "${destdir}/scripts/Kbuild"6969fi
+112-33
security/tomoyo/common.c
···19811981}1982198219831983/**19841984+ * tomoyo_numscan - sscanf() which stores the length of a decimal integer value.19851985+ *19861986+ * @str: String to scan.19871987+ * @head: Leading string that must start with.19881988+ * @width: Pointer to "int" for storing length of a decimal integer value after @head.19891989+ * @tail: Optional character that must match after a decimal integer value.19901990+ *19911991+ * Returns whether @str starts with @head and a decimal value follows @head.19921992+ */19931993+static bool tomoyo_numscan(const char *str, const char *head, int *width, const char tail)19941994+{19951995+ const char *cp;19961996+ const int n = strlen(head);19971997+19981998+ if (!strncmp(str, head, n)) {19991999+ cp = str + n;20002000+ while (*cp && *cp >= '0' && *cp <= '9')20012001+ cp++;20022002+ if (*cp == tail || !tail) {20032003+ *width = cp - (str + n);20042004+ return *width != 0;20052005+ }20062006+ }20072007+ *width = 0;20082008+ return 0;20092009+}20102010+20112011+/**20122012+ * tomoyo_patternize_path - Make patterns for file path. Used by learning mode.20132013+ *20142014+ * @buffer: Destination buffer.20152015+ * @len: Size of @buffer.20162016+ * @entry: Original line.20172017+ *20182018+ * Returns nothing.20192019+ */20202020+static void tomoyo_patternize_path(char *buffer, const int len, char *entry)20212021+{20222022+ int width;20232023+ char *cp = entry;20242024+20252025+ /* Nothing to do if this line is not for "file" related entry. */20262026+ if (strncmp(entry, "file ", 5))20272027+ goto flush;20282028+ /*20292029+ * Nothing to do if there is no colon in this line, for this rewriting20302030+ * applies to only filesystems where numeric values in the path are volatile.20312031+ */20322032+ cp = strchr(entry + 5, ':');20332033+ if (!cp) {20342034+ cp = entry;20352035+ goto flush;20362036+ }20372037+ /* Flush e.g. "file ioctl" part. */20382038+ while (*cp != ' ')20392039+ cp--;20402040+ *cp++ = '\0';20412041+ tomoyo_addprintf(buffer, len, "%s ", entry);20422042+ /* e.g. file ioctl pipe:[$INO] $CMD */20432043+ if (tomoyo_numscan(cp, "pipe:[", &width, ']')) {20442044+ cp += width + 7;20452045+ tomoyo_addprintf(buffer, len, "pipe:[\\$]");20462046+ goto flush;20472047+ }20482048+ /* e.g. file ioctl socket:[$INO] $CMD */20492049+ if (tomoyo_numscan(cp, "socket:[", &width, ']')) {20502050+ cp += width + 9;20512051+ tomoyo_addprintf(buffer, len, "socket:[\\$]");20522052+ goto flush;20532053+ }20542054+ if (!strncmp(cp, "proc:/self", 10)) {20552055+ /* e.g. file read proc:/self/task/$TID/fdinfo/$FD */20562056+ cp += 10;20572057+ tomoyo_addprintf(buffer, len, "proc:/self");20582058+ } else if (tomoyo_numscan(cp, "proc:/", &width, 0)) {20592059+ /* e.g. file read proc:/$PID/task/$TID/fdinfo/$FD */20602060+ /*20612061+ * Don't patternize $PID part if $PID == 1, for several20622062+ * programs access only files in /proc/1/ directory.20632063+ */20642064+ cp += width + 6;20652065+ if (width == 1 && *(cp - 1) == '1')20662066+ tomoyo_addprintf(buffer, len, "proc:/1");20672067+ else20682068+ tomoyo_addprintf(buffer, len, "proc:/\\$");20692069+ } else {20702070+ goto flush;20712071+ }20722072+ /* Patternize $TID part if "/task/" follows. */20732073+ if (tomoyo_numscan(cp, "/task/", &width, 0)) {20742074+ cp += width + 6;20752075+ tomoyo_addprintf(buffer, len, "/task/\\$");20762076+ }20772077+ /* Patternize $FD part if "/fd/" or "/fdinfo/" follows. */20782078+ if (tomoyo_numscan(cp, "/fd/", &width, 0)) {20792079+ cp += width + 4;20802080+ tomoyo_addprintf(buffer, len, "/fd/\\$");20812081+ } else if (tomoyo_numscan(cp, "/fdinfo/", &width, 0)) {20822082+ cp += width + 8;20832083+ tomoyo_addprintf(buffer, len, "/fdinfo/\\$");20842084+ }20852085+flush:20862086+ /* Flush remaining part if any. */20872087+ if (*cp)20882088+ tomoyo_addprintf(buffer, len, "%s", cp);20892089+}20902090+20912091+/**19842092 * tomoyo_add_entry - Add an ACL to current thread's domain. Used by learning mode.19852093 *19862094 * @domain: Pointer to "struct tomoyo_domain_info".···21112003 if (!cp)21122004 return;21132005 *cp++ = '\0';21142114- len = strlen(cp) + 1;20062006+ /* Reserve some space for potentially using patterns. */20072007+ len = strlen(cp) + 16;21152008 /* strstr() will return NULL if ordering is wrong. */21162009 if (*cp == 'f') {21172010 argv0 = strstr(header, " argv[]={ \"");···21292020 if (symlink)21302021 len += tomoyo_truncate(symlink + 1) + 1;21312022 }21322132- buffer = kmalloc(len, GFP_NOFS);20232023+ buffer = kmalloc(len, GFP_NOFS | __GFP_ZERO);21332024 if (!buffer)21342025 return;21352135- snprintf(buffer, len - 1, "%s", cp);21362136- if (*cp == 'f' && strchr(buffer, ':')) {21372137- /* Automatically replace 2 or more digits with \$ pattern. */21382138- char *cp2;21392139-21402140- /* e.g. file read proc:/$PID/stat */21412141- cp = strstr(buffer, " proc:/");21422142- if (cp && simple_strtoul(cp + 7, &cp2, 10) >= 10 && *cp2 == '/') {21432143- *(cp + 7) = '\\';21442144- *(cp + 8) = '$';21452145- memmove(cp + 9, cp2, strlen(cp2) + 1);21462146- goto ok;21472147- }21482148- /* e.g. file ioctl pipe:[$INO] $CMD */21492149- cp = strstr(buffer, " pipe:[");21502150- if (cp && simple_strtoul(cp + 7, &cp2, 10) >= 10 && *cp2 == ']') {21512151- *(cp + 7) = '\\';21522152- *(cp + 8) = '$';21532153- memmove(cp + 9, cp2, strlen(cp2) + 1);21542154- goto ok;21552155- }21562156- /* e.g. file ioctl socket:[$INO] $CMD */21572157- cp = strstr(buffer, " socket:[");21582158- if (cp && simple_strtoul(cp + 9, &cp2, 10) >= 10 && *cp2 == ']') {21592159- *(cp + 9) = '\\';21602160- *(cp + 10) = '$';21612161- memmove(cp + 11, cp2, strlen(cp2) + 1);21622162- goto ok;21632163- }21642164- }21652165-ok:20262026+ tomoyo_patternize_path(buffer, len, cp);21662027 if (realpath)21672028 tomoyo_addprintf(buffer, len, " exec.%s", realpath);21682029 if (argv0)
+1-1
security/tomoyo/domain.c
···920920#ifdef CONFIG_MMU921921 /*922922 * This is called at execve() time in order to dig around923923- * in the argv/environment of the new proceess923923+ * in the argv/environment of the new process924924 * (represented by bprm).925925 */926926 mmap_read_lock(bprm->mm);
···549549 .id = LSM_ID_TOMOYO,550550};551551552552-/*553553- * tomoyo_security_ops is a "struct security_operations" which is used for554554- * registering TOMOYO.555555- */552552+/* tomoyo_hooks is used for registering TOMOYO. */556553static struct security_hook_list tomoyo_hooks[] __ro_after_init = {557554 LSM_HOOK_INIT(cred_prepare, tomoyo_cred_prepare),558555 LSM_HOOK_INIT(bprm_committed_creds, tomoyo_bprm_committed_creds),
···10711071}1072107210731073/*10741074- * Called after the VM is otherwise initialized, but just before adding it to10751075- * the vm_list.10761076- */10771077-int __weak kvm_arch_post_init_vm(struct kvm *kvm)10781078-{10791079- return 0;10801080-}10811081-10821082-/*10831074 * Called just after removing the VM from the vm_list, but before doing any10841075 * other destruction.10851076 */···11901199 if (r)11911200 goto out_err_no_debugfs;1192120111931193- r = kvm_arch_post_init_vm(kvm);11941194- if (r)11951195- goto out_err;11961196-11971202 mutex_lock(&kvm_lock);11981203 list_add(&kvm->vm_list, &vm_list);11991204 mutex_unlock(&kvm_lock);···1199121212001213 return kvm;1201121412021202-out_err:12031203- kvm_destroy_vm_debugfs(kvm);12041215out_err_no_debugfs:12051216 kvm_coalesced_mmio_free(kvm);12061217out_no_coalesced_mmio:···19561971 return -EINVAL;19571972 if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)19581973 return -EINVAL;19591959- if ((mem->memory_size >> PAGE_SHIFT) > KVM_MEM_MAX_NR_PAGES)19741974+19751975+ /*19761976+ * The size of userspace-defined memory regions is restricted in order19771977+ * to play nice with dirty bitmap operations, which are indexed with an19781978+ * "unsigned int". KVM's internal memory regions don't support dirty19791979+ * logging, and so are exempt.19801980+ */19811981+ if (id < KVM_USER_MEM_SLOTS &&19821982+ (mem->memory_size >> PAGE_SHIFT) > KVM_MEM_MAX_NR_PAGES)19601983 return -EINVAL;1961198419621985 slots = __kvm_memslots(kvm, as_id);