Commit Graph

34 Commits

Author SHA1 Message Date
Greg Kroah-Hartman
b3fb80bdc6 Merge 6.12.19 into android16-6.12
GKI (arm64) relevant 48 out of 271 changes, affecting 92 files +576/-223
  5b414ed3bb Revert "of: reserved-memory: Fix using wrong number of cells to get property 'alignment'" [1 file, +2/-2]
  48a934fc47 Revert "mm/page_alloc.c: don't show protection in zone's ->lowmem_reserve[] for empty zone" [1 file, +1/-2]
  88310caff6 Bluetooth: Add check for mgmt_alloc_skb() in mgmt_remote_name() [1 file, +2/-0]
  7841180342 Bluetooth: Add check for mgmt_alloc_skb() in mgmt_device_connected() [1 file, +3/-0]
  2d448dbd47 userfaultfd: do not block on locking a large folio with raised refcount [1 file, +16/-1]
  f57e89c1cb block: fix conversion of GPT partition name to 7-bit [1 file, +1/-1]
  9426f38372 mm/page_alloc: fix uninitialized variable [1 file, +1/-0]
  79636d2981 mm: abort vma_modify() on merge out of memory failure [1 file, +8/-4]
  605f53f13b mm: don't skip arch_sync_kernel_mappings() in error paths [2 files, +6/-4]
  9ed33c7bac mm: fix finish_fault() handling for large folios [1 file, +10/-5]
  576a2f4c43 hwpoison, memory_hotplug: lock folio before unmap hwpoisoned folio [1 file, +4/-1]
  2e66d69941 mm: memory-hotplug: check folio ref count first in do_migrate_range [1 file, +7/-13]
  3c63fb6ef7 nvme-pci: use sgls for all user requests if possible [2 files, +13/-4]
  9dedafd86e nvme-ioctl: fix leaked requests on mapping error [1 file, +8/-4]
  084819b0d8 net: gso: fix ownership in __udp_gso_segment [1 file, +6/-2]
  1688acf477 perf/core: Fix pmus_lock vs. pmus_srcu ordering [1 file, +2/-2]
  a899adf706 HID: hid-steam: Fix use-after-free when detaching device [1 file, +1/-1]
  8aa8a40c76 ppp: Fix KMSAN uninit-value warning with bpf [1 file, +19/-9]
  b71cd95764 ethtool: linkstate: migrate linkstate functions to support multi-PHY setups [1 file, +15/-8]
  9c1d09cdbc net: ethtool: plumb PHY stats to PHY drivers [7 files, +167/-2]
  639c703529 net: ethtool: netlink: Allow NULL nlattrs when getting a phy_device [9 files, +19/-18]
  30e8aee778 vlan: enforce underlying device type [1 file, +2/-1]
  5d609f0d2f exfat: fix just enough dentries but allocate a new cluster to dir [1 file, +1/-1]
  c897b8ec46 exfat: fix soft lockup in exfat_clear_bitmap [3 files, +16/-7]
  611015122d exfat: short-circuit zero-byte writes in exfat_file_write_iter [1 file, +1/-1]
  2b484789e9 net-timestamp: support TCP GSO case for a few missing flags [1 file, +7/-4]
  b08e290324 ublk: set_params: properly check if parameters can be applied [1 file, +5/-2]
  b5741e4b9e sched/fair: Fix potential memory corruption in child_cfs_rq_on_list [1 file, +4/-2]
  39c2b2767e xhci: Restrict USB4 tunnel detection for USB3 devices to Intel hosts [1 file, +8/-0]
  4ea3319f3e usb: hub: lack of clearing xHC resources [1 file, +33/-0]
  0cab185c73 usb: quirks: Add DELAY_INIT and NO_LPM for Prolific Mass Storage Card Reader [1 file, +4/-0]
  079a3e52f3 usb: typec: ucsi: Fix NULL pointer access [1 file, +7/-6]
  840afbea3f usb: gadget: u_ether: Set is_suspend flag if remote wakeup fails [1 file, +2/-2]
  ced69d88eb usb: dwc3: Set SUSPENDENABLE soon after phy init [3 files, +45/-30]
  35db1f1829 usb: dwc3: gadget: Prevent irq storm when TH re-executes [2 files, +13/-13]
  b387312527 usb: typec: ucsi: increase timeout for PPM reset operations [1 file, +1/-1]
  4bf6c57a89 usb: gadget: Set self-powered based on MaxPower and bmAttributes [1 file, +11/-5]
  dcd7ffdefb usb: gadget: Fix setting self-powered state on suspend [1 file, +2/-1]
  395011ee82 usb: gadget: Check bmAttributes only if configuration is valid [1 file, +1/-1]
  012b98cdb5 acpi: typec: ucsi: Introduce a ->poll_cci method [7 files, +25/-12]
  d7015bb3c5 xhci: pci: Fix indentation in the PCI device ID definitions [1 file, +4/-4]
  ea39f99864 usb: xhci: Enable the TRB overfetch quirk on VIA VL805 [3 files, +10/-5]
  4e8df56636 char: misc: deallocate static minor in error path [1 file, +1/-1]
  b50e18791f drivers: core: fix device leak in __fw_devlink_relax_cycles() [1 file, +1/-0]
  a684bad77e mm: hugetlb: Add huge page size param to huge_ptep_get_and_clear() [16 files, +46/-28]
  6ad9643aa5 fs/netfs/read_pgpriv2: skip folio queues without `marks3` [1 file, +3/-2]
  5bc6e5b10f fs/netfs/read_collect: fix crash due to uninitialized `prev` variable [1 file, +11/-10]
  86b7ebddab uprobes: Fix race in uprobe_free_utask [1 file, +1/-1]

Changes in 6.12.19
        x86/amd_nb: Use rdmsr_safe() in amd_get_mmconfig_range()
        rust: block: fix formatting in GenDisk doc
        drm/i915/dsi: convert to struct intel_display
        drm/i915/dsi: Use TRANS_DDI_FUNC_CTL's own port width macro
        gpio: vf610: use generic device_get_match_data()
        gpio: vf610: add locking to gpio direction functions
        cifs: Remove symlink member from cifs_open_info_data union
        smb311: failure to open files of length 1040 when mounting with SMB3.1.1 POSIX extensions
        btrfs: fix data overwriting bug during buffered write when block size < page size
        x86/microcode/AMD: Add some forgotten models to the SHA check
        loongarch: Use ASM_REACHABLE
        rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`
        rust: sort global Rust flags
        rust: types: avoid repetition in `{As,From}Bytes` impls
        rust: enable `clippy::undocumented_unsafe_blocks` lint
        rust: enable `clippy::unnecessary_safety_comment` lint
        rust: enable `clippy::unnecessary_safety_doc` lint
        rust: enable `clippy::ignored_unit_patterns` lint
        rust: enable `rustdoc::unescaped_backticks` lint
        rust: init: remove unneeded `#[allow(clippy::disallowed_names)]`
        rust: sync: remove unneeded `#[allow(clippy::non_send_fields_in_send_ty)]`
        rust: introduce `.clippy.toml`
        rust: replace `clippy::dbg_macro` with `disallowed_macros`
        rust: provide proper code documentation titles
        rust: enable Clippy's `check-private-items`
        Documentation: rust: add coding guidelines on lints
        rust: start using the `#[expect(...)]` attribute
        Documentation: rust: discuss `#[expect(...)]` in the guidelines
        rust: error: make conversion functions public
        rust: error: optimize error type to use nonzero
        rust: alloc: add `Allocator` trait
        rust: alloc: separate `aligned_size` from `krealloc_aligned`
        rust: alloc: rename `KernelAllocator` to `Kmalloc`
        rust: alloc: implement `ReallocFunc`
        rust: alloc: make `allocator` module public
        rust: alloc: implement `Allocator` for `Kmalloc`
        rust: alloc: add module `allocator_test`
        rust: alloc: implement `Vmalloc` allocator
        rust: alloc: implement `KVmalloc` allocator
        rust: alloc: add __GFP_NOWARN to `Flags`
        rust: alloc: implement kernel `Box`
        rust: treewide: switch to our kernel `Box` type
        rust: alloc: remove extension of std's `Box`
        rust: alloc: add `Box` to prelude
        rust: alloc: introduce `ArrayLayout`
        rust: alloc: implement kernel `Vec` type
        rust: alloc: implement `IntoIterator` for `Vec`
        rust: alloc: implement `collect` for `IntoIter`
        rust: treewide: switch to the kernel `Vec` type
        rust: alloc: remove `VecExt` extension
        rust: alloc: add `Vec` to prelude
        rust: error: use `core::alloc::LayoutError`
        rust: error: check for config `test` in `Error::name`
        rust: alloc: implement `contains` for `Flags`
        rust: alloc: implement `Cmalloc` in module allocator_test
        rust: str: test: replace `alloc::format`
        rust: alloc: update module comment of alloc.rs
        kbuild: rust: remove the `alloc` crate and `GlobalAlloc`
        MAINTAINERS: add entry for the Rust `alloc` module
        drm/panic: avoid reimplementing Iterator::find
        drm/panic: remove unnecessary borrow in alignment_pattern
        drm/panic: prefer eliding lifetimes
        drm/panic: remove redundant field when assigning value
        drm/panic: correctly indent continuation of line in list item
        drm/panic: allow verbose boolean for clarity
        drm/panic: allow verbose version check
        rust: kbuild: expand rusttest target for macros
        rust: fix size_t in bindgen prototypes of C builtins
        rust: map `__kernel_size_t` and friends also to usize/isize
        rust: use custom FFI integer types
        rust: alloc: Fix `ArrayLayout` allocations
        Revert "of: reserved-memory: Fix using wrong number of cells to get property 'alignment'"
        tracing: tprobe-events: Fix a memory leak when tprobe with $retval
        tracing: tprobe-events: Reject invalid tracepoint name
        stmmac: loongson: Pass correct arg to PCI function
        LoongArch: Convert unreachable() to BUG()
        LoongArch: Use polling play_dead() when resuming from hibernation
        LoongArch: Set max_pfn with the PFN of the last page
        LoongArch: KVM: Add interrupt checking for AVEC
        LoongArch: KVM: Reload guest CSR registers after sleep
        LoongArch: KVM: Fix GPA size issue about VM
        HID: appleir: Fix potential NULL dereference at raw event handle
        ksmbd: fix type confusion via race condition when using ipc_msg_send_request
        ksmbd: fix out-of-bounds in parse_sec_desc()
        ksmbd: fix use-after-free in smb2_lock
        ksmbd: fix bug on trap in smb2_lock
        gpio: rcar: Use raw_spinlock to protect register access
        gpio: aggregator: protect driver attr handlers against module unload
        ALSA: seq: Avoid module auto-load handling at event delivery
        ALSA: hda: intel: Add Dell ALC3271 to power_save denylist
        ALSA: hda/realtek - add supported Mic Mute LED for Lenovo platform
        ALSA: hda/realtek: update ALC222 depop optimize
        btrfs: fix a leaked chunk map issue in read_one_chunk()
        hwmon: (peci/dimmtemp) Do not provide fake thresholds data
        drm/amd/display: Fix null check for pipe_ctx->plane_state in resource_build_scaling_params
        drm/amdkfd: Fix NULL Pointer Dereference in KFD queue
        drm/amd/pm: always allow ih interrupt from fw
        drm/imagination: avoid deadlock on fence release
        drm/imagination: Hold drm_gem_gpuva lock for unmap
        drm/imagination: only init job done fences once
        drm/radeon: Fix rs400_gpu_init for ATI mobility radeon Xpress 200M
        Revert "mm/page_alloc.c: don't show protection in zone's ->lowmem_reserve[] for empty zone"
        Revert "selftests/mm: remove local __NR_* definitions"
        platform/x86: thinkpad_acpi: Add battery quirk for ThinkPad X131e
        x86/boot: Sanitize boot params before parsing command line
        x86/cacheinfo: Validate CPUID leaf 0x2 EDX output
        x86/cpu: Validate CPUID leaf 0x2 EDX output
        x86/cpu: Properly parse CPUID leaf 0x2 TLB descriptor 0x63
        drm/xe: Add staging tree for VM binds
        drm/xe/hmm: Style- and include fixes
        drm/xe/hmm: Don't dereference struct page pointers without notifier lock
        drm/xe/vm: Fix a misplaced #endif
        drm/xe/vm: Validate userptr during gpu vma prefetching
        mptcp: fix 'scheduling while atomic' in mptcp_pm_nl_append_new_local_addr
        drm/xe: Fix GT "for each engine" workarounds
        drm/xe: Fix fault mode invalidation with unbind
        drm/xe/userptr: properly setup pfn_flags_mask
        drm/xe/userptr: Unmap userptrs in the mmu notifier
        Bluetooth: Add check for mgmt_alloc_skb() in mgmt_remote_name()
        Bluetooth: Add check for mgmt_alloc_skb() in mgmt_device_connected()
        wifi: cfg80211: regulatory: improve invalid hints checking
        wifi: nl80211: reject cooked mode if it is set along with other flags
        selftests/damon/damos_quota_goal: handle minimum quota that cannot be further reduced
        selftests/damon/damos_quota: make real expectation of quota exceeds
        selftests/damon/damon_nr_regions: set ops update for merge results check to 100ms
        selftests/damon/damon_nr_regions: sort collected regiosn before checking with min/max boundaries
        rapidio: add check for rio_add_net() in rio_scan_alloc_net()
        rapidio: fix an API misues when rio_add_net() fails
        dma: kmsan: export kmsan_handle_dma() for modules
        s390/traps: Fix test_monitor_call() inline assembly
        NFS: fix nfs_release_folio() to not deadlock via kcompactd writeback
        userfaultfd: do not block on locking a large folio with raised refcount
        block: fix conversion of GPT partition name to 7-bit
        mm/page_alloc: fix uninitialized variable
        mm: abort vma_modify() on merge out of memory failure
        mm: memory-failure: update ttu flag inside unmap_poisoned_folio
        mm: don't skip arch_sync_kernel_mappings() in error paths
        mm: fix finish_fault() handling for large folios
        hwpoison, memory_hotplug: lock folio before unmap hwpoisoned folio
        mm: memory-hotplug: check folio ref count first in do_migrate_range
        wifi: iwlwifi: mvm: clean up ROC on failure
        wifi: iwlwifi: mvm: don't try to talk to a dead firmware
        wifi: iwlwifi: limit printed string from FW file
        wifi: iwlwifi: Free pages allocated when failing to build A-MSDU
        wifi: iwlwifi: Fix A-MSDU TSO preparation
        HID: google: fix unused variable warning under !CONFIG_ACPI
        HID: intel-ish-hid: Fix use-after-free issue in hid_ishtp_cl_remove()
        HID: intel-ish-hid: Fix use-after-free issue in ishtp_hid_remove()
        coredump: Only sort VMAs when core_sort_vma sysctl is set
        nvme-pci: add support for sgl metadata
        nvme-pci: use sgls for all user requests if possible
        nvme-ioctl: fix leaked requests on mapping error
        wifi: mac80211: Support parsing EPCS ML element
        wifi: mac80211: fix MLE non-inheritance parsing
        wifi: mac80211: fix vendor-specific inheritance
        drm/fbdev-helper: Move color-mode lookup into 4CC format helper
        drm/fbdev: Add memory-agnostic fbdev client
        drm: Add client-agnostic setup helper
        drm/fbdev-ttm: Support struct drm_driver.fbdev_probe
        drm/nouveau: Run DRM default client setup
        drm/nouveau: select FW caching
        bluetooth: btusb: Initialize .owner field of force_poll_sync_fops
        nvme-tcp: add basic support for the C2HTermReq PDU
        nvme-tcp: fix potential memory corruption in nvme_tcp_recv_pdu()
        nvmet-tcp: Fix a possible sporadic response drops in weakly ordered arch
        ALSA: hda/realtek: Remove (revert) duplicate Ally X config
        net: gso: fix ownership in __udp_gso_segment
        caif_virtio: fix wrong pointer check in cfv_probe()
        perf/core: Fix pmus_lock vs. pmus_srcu ordering
        hwmon: (pmbus) Initialise page count in pmbus_identify()
        hwmon: (ntc_thermistor) Fix the ncpXXxh103 sensor table
        hwmon: (ad7314) Validate leading zero bits and return error
        tracing: probe-events: Remove unused MAX_ARG_BUF_LEN macro
        drm/imagination: Fix timestamps in firmware traces
        ALSA: usx2y: validate nrpacks module parameter on probe
        llc: do not use skb_get() before dev_queue_xmit()
        hwmon: fix a NULL vs IS_ERR_OR_NULL() check in xgene_hwmon_probe()
        drm/sched: Fix preprocessor guard
        be2net: fix sleeping while atomic bugs in be_ndo_bridge_getlink
        net: hns3: make sure ptp clock is unregister and freed if hclge_ptp_get_cycle returns an error
        drm/i915/color: Extract intel_color_modeset()
        drm/i915: Plumb 'dsb' all way to the plane hooks
        drm/xe: Remove double pageflip
        HID: hid-steam: Fix use-after-free when detaching device
        net: ipa: Fix v4.7 resource group names
        net: ipa: Fix QSB data for v4.7
        net: ipa: Enable checksum for IPA_ENDPOINT_AP_MODEM_{RX,TX} for v4.7
        ppp: Fix KMSAN uninit-value warning with bpf
        ethtool: linkstate: migrate linkstate functions to support multi-PHY setups
        net: ethtool: plumb PHY stats to PHY drivers
        net: ethtool: netlink: Allow NULL nlattrs when getting a phy_device
        vlan: enforce underlying device type
        x86/sgx: Fix size overflows in sgx_encl_create()
        exfat: fix just enough dentries but allocate a new cluster to dir
        exfat: fix soft lockup in exfat_clear_bitmap
        exfat: short-circuit zero-byte writes in exfat_file_write_iter
        net-timestamp: support TCP GSO case for a few missing flags
        ublk: set_params: properly check if parameters can be applied
        sched/fair: Fix potential memory corruption in child_cfs_rq_on_list
        nvme-tcp: fix signedness bug in nvme_tcp_init_connection()
        net: dsa: mt7530: Fix traffic flooding for MMIO devices
        mctp i3c: handle NULL header address
        net: ipv6: fix dst ref loop in ila lwtunnel
        net: ipv6: fix missing dst ref drop in ila lwtunnel
        gpio: rcar: Fix missing of_node_put() call
        Revert "drivers/card_reader/rtsx_usb: Restore interrupt based detection"
        usb: renesas_usbhs: Call clk_put()
        xhci: Restrict USB4 tunnel detection for USB3 devices to Intel hosts
        usb: renesas_usbhs: Use devm_usb_get_phy()
        usb: hub: lack of clearing xHC resources
        usb: quirks: Add DELAY_INIT and NO_LPM for Prolific Mass Storage Card Reader
        usb: typec: ucsi: Fix NULL pointer access
        usb: renesas_usbhs: Flush the notify_hotplug_work
        usb: gadget: u_ether: Set is_suspend flag if remote wakeup fails
        usb: atm: cxacru: fix a flaw in existing endpoint checks
        usb: dwc3: Set SUSPENDENABLE soon after phy init
        usb: dwc3: gadget: Prevent irq storm when TH re-executes
        usb: typec: ucsi: increase timeout for PPM reset operations
        usb: typec: tcpci_rt1711h: Unmask alert interrupts to fix functionality
        usb: gadget: Set self-powered based on MaxPower and bmAttributes
        usb: gadget: Fix setting self-powered state on suspend
        usb: gadget: Check bmAttributes only if configuration is valid
        kbuild: userprogs: use correct lld when linking through clang
        acpi: typec: ucsi: Introduce a ->poll_cci method
        rust: finish using custom FFI integer types
        rust: map `long` to `isize` and `char` to `u8`
        xhci: pci: Fix indentation in the PCI device ID definitions
        usb: xhci: Enable the TRB overfetch quirk on VIA VL805
        KVM: SVM: Set RFLAGS.IF=1 in C code, to get VMRUN out of the STI shadow
        KVM: SVM: Save host DR masks on CPUs with DebugSwap
        KVM: SVM: Drop DEBUGCTL[5:2] from guest's effective value
        KVM: SVM: Suppress DEBUGCTL.BTF on AMD
        KVM: x86: Snapshot the host's DEBUGCTL in common x86
        KVM: SVM: Manually context switch DEBUGCTL if LBR virtualization is disabled
        KVM: x86: Snapshot the host's DEBUGCTL after disabling IRQs
        KVM: x86: Explicitly zero EAX and EBX when PERFMON_V2 isn't supported by KVM
        cdx: Fix possible UAF error in driver_override_show()
        mei: me: add panther lake P DID
        mei: vsc: Use "wakeuphostint" when getting the host wakeup GPIO
        intel_th: pci: Add Arrow Lake support
        intel_th: pci: Add Panther Lake-H support
        intel_th: pci: Add Panther Lake-P/U support
        char: misc: deallocate static minor in error path
        drivers: core: fix device leak in __fw_devlink_relax_cycles()
        slimbus: messaging: Free transaction ID in delayed interrupt scenario
        bus: mhi: host: pci_generic: Use pci_try_reset_function() to avoid deadlock
        eeprom: digsy_mtc: Make GPIO lookup table match the device
        drivers: virt: acrn: hsm: Use kzalloc to avoid info leak in pmcmd_ioctl
        iio: filter: admv8818: Force initialization of SDO
        iio: light: apds9306: fix max_scale_nano values
        iio: dac: ad3552r: clear reset status flag
        iio: adc: ad7192: fix channel select
        iio: adc: at91-sama5d2_adc: fix sama7g5 realbits value
        mm: hugetlb: Add huge page size param to huge_ptep_get_and_clear()
        arm64: hugetlb: Fix huge_ptep_get_and_clear() for non-present ptes
        fs/netfs/read_pgpriv2: skip folio queues without `marks3`
        fs/netfs/read_collect: fix crash due to uninitialized `prev` variable
        kbuild: hdrcheck: fix cross build with clang
        ALSA: hda: realtek: fix incorrect IS_REACHABLE() usage
        nvme-tcp: Fix a C2HTermReq error message
        docs: rust: remove spurious item in `expect` list
        Revert "KVM: e500: always restore irqs"
        Revert "KVM: PPC: e500: Use __kvm_faultin_pfn() to handle page faults"
        Revert "KVM: PPC: e500: Mark "struct page" pfn accessed before dropping mmu_lock"
        Revert "KVM: PPC: e500: Mark "struct page" dirty in kvmppc_e500_shadow_map()"
        KVM: e500: always restore irqs
        uprobes: Fix race in uprobe_free_utask
        selftests/bpf: Clean up open-coded gettid syscall invocations
        x86/mm: Don't disable PCID when INVLPG has been fixed by microcode
        wifi: iwlwifi: pcie: Fix TSO preparation
        Linux 6.12.19

Change-Id: Ia0c2b2c6a95b53a66e21505ed6ba756c6b0a2388
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2025-04-17 03:02:04 -07:00
Greg Kroah-Hartman
dfed1574cd Merge 1ef4cf5f98 ("rust: alloc: update module comment of alloc.rs") into android16-6.12
Steps on the way to 6.12.18

Resolves merge conflicts in:
	rust/kernel/types.rs
	scripts/Makefile.build

Change-Id: I1a0d7a30074e2532f53b9c9d4cf0e8346d57ffef
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
[Re-resolved rust/kernel/types.rs <mmaurer@google.com>]
Signed-off-by: Matthew Maurer <mmaurer@google.com>
2025-04-07 05:41:55 -07:00
Gary Guo
641ecd0d0a rust: use custom FFI integer types
commit d072acda4862f095ec9056979b654cc06a22cc68 upstream.

Currently FFI integer types are defined in libcore. This commit creates
the `ffi` crate and asks bindgen to use that crate for FFI integer types
instead of `core::ffi`.

This commit is preparatory and no type changes are made in this commit
yet.

Signed-off-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20240913213041.395655-4-gary@garyguo.net
[ Added `rustdoc`, `rusttest` and KUnit tests support. Rebased on top of
  `rust-next` (e.g. migrated more `core::ffi` cases). Reworded crate
  docs slightly and formatted. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-13 13:01:49 +01:00
Danilo Krummrich
e64a79b9a5 rust: treewide: switch to the kernel Vec type
commit 58eff8e872bd04ccb3adcf99aec7334ffad06cfd upstream.

Now that we got the kernel `Vec` in place, convert all existing `Vec`
users to make use of it.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20241004154149.93856-20-dakr@kernel.org
[ Converted `kasan_test_rust.rs` too, as discussed. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-13 13:01:46 +01:00
Danilo Krummrich
34eb8dcb62 rust: alloc: remove extension of std's Box
commit e8c6ccdbcaaf31f26c0fffd4073edd0b0147cdc6 upstream.

Now that all existing `Box` users were moved to the kernel `Box` type,
remove the `BoxExt` extension and all other related extensions.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20241004154149.93856-14-dakr@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-13 13:01:45 +01:00
Miguel Ojeda
c6447d4d83 rust: enable clippy::ignored_unit_patterns lint
commit 3fcc23397628c2357dbe66df59644e09f72ac725 upstream.

In Rust 1.73.0, Clippy introduced the `ignored_unit_patterns` lint [1]:

> Matching with `()` explicitly instead of `_` outlines the fact that
> the pattern contains no data. Also it would detect a type change
> that `_` would ignore.

There is only a single case that requires a change:

    error: matching over `()` is more explicit
       --> rust/kernel/types.rs:176:45
        |
    176 |         ScopeGuard::new_with_data((), move |_| cleanup())
        |                                             ^ help: use `()` instead of `_`: `()`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
        = note: requested on the command line with `-D clippy::ignored-unit-patterns`

Thus clean it up and enable the lint -- no functional change intended.

Link: https://rust-lang.github.io/rust-clippy/master/index.html#/ignored_unit_patterns [1]
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Tested-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20240904204347.168520-8-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-13 13:01:41 +01:00
Miguel Ojeda
4e7072490d rust: enable clippy::undocumented_unsafe_blocks lint
commit db4f72c904cb116e2bf56afdd67fc5167a607a7b upstream.

Checking that we are not missing any `// SAFETY` comments in our `unsafe`
blocks is something we have wanted to do for a long time, as well as
cleaning up the remaining cases that were not documented [1].

Back when Rust for Linux started, this was something that could have
been done via a script, like Rust's `tidy`. Soon after, in Rust 1.58.0,
Clippy implemented the `undocumented_unsafe_blocks` lint [2].

Even though the lint has a few false positives, e.g. in some cases where
attributes appear between the comment and the `unsafe` block [3], there
are workarounds and the lint seems quite usable already.

Thus enable the lint now.

We still have a few cases to clean up, so just allow those for the moment
by writing a `TODO` comment -- some of those may be good candidates for
new contributors.

Link: https://github.com/Rust-for-Linux/linux/issues/351 [1]
Link: https://rust-lang.github.io/rust-clippy/master/#/undocumented_unsafe_blocks [2]
Link: https://github.com/rust-lang/rust-clippy/issues/13189 [3]
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Tested-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20240904204347.168520-5-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-13 13:01:41 +01:00
Miguel Ojeda
870de86d87 rust: types: avoid repetition in {As,From}Bytes impls
commit 567cdff53e71de56ae67eaf4309db38778b7bcd3 upstream.

In order to provide `// SAFETY` comments for every `unsafe impl`, we would
need to repeat them, which is not very useful and would be harder to read.

We could perhaps allow the lint (ideally within a small module), but we
can take the chance to avoid the repetition of the `impl`s themselves
too by using a small local macro, like in other places where we have
had to do this sort of thing.

Thus add the straightforward `impl_{from,as}bytes!` macros and use them
to implement `FromBytes`.

This, in turn, will allow us in the next patch to place a `// SAFETY`
comment that defers to the actual invocation of the macro.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Tested-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20240904204347.168520-4-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-03-13 13:01:40 +01:00
Alice Ryhl
a19681d360 UPSTREAM: rust: types: add Opaque::try_ffi_init
This will be used by the miscdevice abstractions, as the C function
`misc_register` is fallible.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Link: https://lore.kernel.org/r/20241001-b4-miscdevice-v2-1-330d760041fa@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 370906207
(cherry picked from commit a69dc41a4211b0da311ae3a3b79dd4497c9dfb60)
Change-Id: Ib2945bfaa6fb043ccaa7ccdf59fa212e228ad965
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-01-16 03:32:01 -08:00
Alice Ryhl
f58fd7a85d UPSTREAM: rust: types: add NotThreadSafe
This introduces a new marker type for types that shouldn't be thread
safe. By adding a field of this type to a struct, it becomes non-Send
and non-Sync, which means that it cannot be accessed in any way from
threads other than the one it was created on.

This is useful for APIs that require globals such as `current` to remain
constant while the value exists.

We update two existing users in the Kernel to use this helper:

 * `Task::current()` - moving the return type of this value to a
   different thread would not be safe as you can no longer be guaranteed
   that the `current` pointer remains valid.
 * Lock guards. Mutexes and spinlocks should be unlocked on the same
   thread as where they were locked, so we enforce this using the Send
   trait.

There are also additional users in later patches of this patchset. See
[1] and [2] for the discussion that led to the introduction of this
patch.

Link: https://lore.kernel.org/all/nFDPJFnzE9Q5cqY7FwSMByRH2OAn_BpI4H53NQfWIlN6I2qfmAqnkp2wRqn0XjMO65OyZY4h6P4K2nAGKJpAOSzksYXaiAK_FoH_8QbgBI4=@proton.me/ [1]
Link: https://lore.kernel.org/all/nFDPJFnzE9Q5cqY7FwSMByRH2OAn_BpI4H53NQfWIlN6I2qfmAqnkp2wRqn0XjMO65OyZY4h6P4K2nAGKJpAOSzksYXaiAK_FoH_8QbgBI4=@proton.me/ [2]
Suggested-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Björn Roy Baron <bjorn3_gh@protonmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240915-alice-file-v10-1-88484f7a3dcf@google.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

Bug: 370906207
(cherry picked from commit e7572e5deaf3bc36818f19ba35ac8e0c454c8bac)
Change-Id: I5c0a0f9d0479bb375e5d9f35a026355b82ac5d4e
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-01-16 03:32:01 -08:00
Kartik Prajapati
96fff2dc29 rust: types: add ARef::into_raw
Add a method for `ARef` that is analogous to `Arc::into_raw`. It is the
inverse operation of `ARef::from_raw`, and allows you to convert the
`ARef` back into a raw pointer while retaining ownership of the
refcount.

This new function will be used by [1] for converting the type in an
`ARef` using `ARef::from_raw(ARef::into_raw(me).cast())`. Alice has
also needed the same function for other use-cases in the past, but [1]
is the first to go upstream.

This was implemented independently by Kartik and Alice. The two versions
were merged by Alice, so all mistakes are Alice's.

Link: https://lore.kernel.org/r/20240801-vma-v3-1-db6c1c0afda9@google.com [1]
Link: https://github.com/Rust-for-Linux/linux/issues/1044
Signed-off-by: Kartik Prajapati <kartikprajapati987@gmail.com>
Co-developed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
[ Reworded to correct the author reference and changed tag to Link
  since it is not a bug. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-08-25 14:44:39 +02:00
Benno Lossin
7adcdd5722 rust: types: improve ForeignOwnable documentation
There are no guarantees for the pointer returned by `into_foreign`.
This is simply because there is no safety documentation stating any
guarantees. Therefore dereferencing and all other operations for that
pointer are not allowed in a general context (i.e. when the concrete
type implementing the trait is not known).
This might be confusing, therefore add normal documentation to state
that there are no guarantees given for the pointer.

Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240730182251.1466684-1-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-08-18 23:10:53 +02:00
Alice Ryhl
6c2d0ad53b rust: implement ForeignOwnable for Pin<Box<T>>
We already implement ForeignOwnable for Box<T>, but it may be useful to
store pinned data in a ForeignOwnable container. This patch makes that
possible.

This will be used together with upcoming miscdev abstractions, which
Binder will use when binderfs is disabled.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20240730-foreign-ownable-pin-box-v1-1-b1d70cdae541@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-08-18 23:10:53 +02:00
Alice Ryhl
b33bf37adb rust: uaccess: add typed accessors for userspace pointers
Add safe methods for reading and writing Rust values to and from
userspace pointers.

The C methods for copying to/from userspace use a function called
`check_object_size` to verify that the kernel pointer is not dangling.
However, this check is skipped when the length is a compile-time
constant, with the assumption that such cases trivially have a correct
kernel pointer.

In this patch, we apply the same optimization to the typed accessors.
For both methods, the size of the operation is known at compile time to
be size_of of the type being read or written. Since the C side doesn't
provide a variant that skips only this check, we create custom helpers
for this purpose.

The majority of reads and writes to userspace pointers in the Rust
Binder driver uses these accessor methods. Benchmarking has found that
skipping the `check_object_size` check makes a big difference for the
cases being skipped here. (And that the check doesn't make a difference
for the cases that use the raw read/write methods.)

This code is based on something that was originally written by Wedson on
the old rust branch. It was modified by Alice to skip the
`check_object_size` check, and to update various comments, including the
notes about kernel pointers in `WritableToBytes`.

Co-developed-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240528-alice-mm-v7-3-78222c31b8f4@google.com
[ Wrapped docs to 100 and added a few intra-doc links. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-08 23:44:01 +02:00
Boqun Feng
be2ca1e039 rust: types: Make Opaque::get const
To support a potential usage:

    static foo: Opaque<Foo> = ..; // Or defined in an extern block.

    ...

    fn bar() {
        let ptr = foo.get();
    }

`Opaque::get` need to be `const`, otherwise compiler will complain
because calls on statics are limited to const functions.

Also `Opaque::get` should be naturally `const` since it's a composition
of two `const` functions: `UnsafeCell::get` and `ptr::cast`.

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Wedson Almeida Filho <walmeida@microsoft.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20240401214543.1242286-1-boqun.feng@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-05-05 13:19:37 +02:00
Wedson Almeida Filho
5ab560ce12 rust: alloc: update VecExt to take allocation flags
We also rename the methods by removing the `try_` prefix since the names
are available due to our usage of the `no_global_oom_handling` config
when building the `alloc` crate.

Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20240328013603.206764-8-wedsonaf@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-04-16 22:50:04 +02:00
Obei Sideg
5bc818419a rust: types: add try_from_foreign() method
Currently `ForeignOwnable::from_foreign()` only works for non-null
pointers for the existing `impl`s (e.g. `Box`, `Arc`). In turn, this
means callers may write code like:

```rust
// `p` is a pointer that may be null.
if p.is_null() {
    None
} else {
    unsafe { Some(Self::from_foreign(ptr)) }
}
```

Add a `try_from_foreign()` method to the trait with a default
implementation that returns `None` if `ptr` is null, otherwise
`Some(from_foreign(ptr))`, so that it can be used by callers instead.

Link: https://github.com/Rust-for-Linux/linux/issues/1057
Signed-off-by: Obei Sideg <linux@obei.io>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Link: https://lore.kernel.org/r/0100018d53f737f8-80c1fe97-0019-40d7-ab69-b1b192785cd7-000000@email.amazonses.com
[ Fixed intra-doc links, improved `SAFETY` comment and reworded commit. ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-02-25 19:17:31 +01:00
Valentin Obst
6269fadf35 rust: kernel: add blank lines in front of code blocks
Throughout the code base, blank lines are used before starting a code
block. Adapt outliers to improve consistency within the kernel crate.

Signed-off-by: Valentin Obst <kernel@valentinobst.de>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240131-doc-fixes-v3-v3-9-0c8af94ed7de@valentinobst.de
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-02-18 21:22:27 +01:00
Linus Torvalds
a031fe8d1d Merge tag 'rust-6.6' of https://github.com/Rust-for-Linux/linux
Pull rust updates from Miguel Ojeda:
 "In terms of lines, most changes this time are on the pinned-init API
  and infrastructure. While we have a Rust version upgrade, and thus a
  bunch of changes from the vendored 'alloc' crate as usual, this time
  those do not account for many lines.

  Toolchain and infrastructure:

   - Upgrade to Rust 1.71.1. This is the second such upgrade, which is a
     smaller jump compared to the last time.

     This version allows us to remove the '__rust_*' allocator functions
     -- the compiler now generates them as expected, thus now our
     'KernelAllocator' is used.

     It also introduces the 'offset_of!' macro in the standard library
     (as an unstable feature) which we will need soon. So far, we were
     using a declarative macro as a prerequisite in some not-yet-landed
     patch series, which did not support sub-fields (i.e. nested
     structs):

         #[repr(C)]
         struct S {
             a: u16,
             b: (u8, u8),
         }

         assert_eq!(offset_of!(S, b.1), 3);

   - Upgrade to bindgen 0.65.1. This is the first time we upgrade its
     version.

     Given it is a fairly big jump, it comes with a fair number of
     improvements/changes that affect us, such as a fix needed to
     support LLVM 16 as well as proper support for '__noreturn' C
     functions, which are now mapped to return the '!' type in Rust:

         void __noreturn f(void); // C
         pub fn f() -> !;         // Rust

   - 'scripts/rust_is_available.sh' improvements and fixes.

     This series takes care of all the issues known so far and adds a
     few new checks to cover for even more cases, plus adds some more
     help texts. All this together will hopefully make problematic
     setups easier to identify and to be solved by users building the
     kernel.

     In addition, it adds a test suite which covers all branches of the
     shell script, as well as tests for the issues found so far.

   - Support rust-analyzer for out-of-tree modules too.

   - Give 'cfg's to rust-analyzer for the 'core' and 'alloc' crates.

   - Drop 'scripts/is_rust_module.sh' since it is not needed anymore.

  Macros crate:

   - New 'paste!' proc macro.

     This macro is a more flexible version of 'concat_idents!': it
     allows the resulting identifier to be used to declare new items and
     it allows to transform the identifiers before concatenating them,
     e.g.

         let x_1 = 42;
         paste!(let [<x _2>] = [<x _1>];);
         assert!(x_1 == x_2);

     The macro is then used for several of the pinned-init API changes
     in this pull.

  Pinned-init API:

   - Make '#[pin_data]' compatible with conditional compilation of
     fields, allowing to write code like:

         #[pin_data]
         pub struct Foo {
             #[cfg(CONFIG_BAR)]
             a: Bar,
             #[cfg(not(CONFIG_BAR))]
             a: Baz,
         }

   - New '#[derive(Zeroable)]' proc macro for the 'Zeroable' trait,
     which allows 'unsafe' implementations for structs where every field
     implements the 'Zeroable' trait, e.g.:

         #[derive(Zeroable)]
         pub struct DriverData {
             id: i64,
             buf_ptr: *mut u8,
             len: usize,
         }

   - Add '..Zeroable::zeroed()' syntax to the 'pin_init!' macro for
     zeroing all other fields, e.g.:

         pin_init!(Buf {
             buf: [1; 64],
             ..Zeroable::zeroed()
         });

   - New '{,pin_}init_array_from_fn()' functions to create array
     initializers given a generator function, e.g.:

         let b: Box<[usize; 1_000]> = Box::init::<Error>(
             init_array_from_fn(|i| i)
         ).unwrap();

         assert_eq!(b.len(), 1_000);
         assert_eq!(b[123], 123);

   - New '{,pin_}chain' methods for '{,Pin}Init<T, E>' that allow to
     execute a closure on the value directly after initialization, e.g.:

         let foo = init!(Foo {
             buf <- init::zeroed()
         }).chain(|foo| {
             foo.setup();
             Ok(())
         });

   - Support arbitrary paths in init macros, instead of just identifiers
     and generic types.

   - Implement the 'Zeroable' trait for the 'UnsafeCell<T>' and
     'Opaque<T>' types.

   - Make initializer values inaccessible after initialization.

   - Make guards in the init macros hygienic.

  'allocator' module:

   - Use 'krealloc_aligned()' in 'KernelAllocator::alloc' preventing
     misaligned allocations when the Rust 1.71.1 upgrade is applied
     later in this pull.

     The equivalent fix for the previous compiler version (where
     'KernelAllocator' is not yet used) was merged into 6.5 already,
     which added the 'krealloc_aligned()' function used here.

   - Implement 'KernelAllocator::{realloc, alloc_zeroed}' for
     performance, using 'krealloc_aligned()' too, which forwards the
     call to the C API.

  'types' module:

   - Make 'Opaque' be '!Unpin', removing the need to add a
     'PhantomPinned' field to Rust structs that contain C structs which
     must not be moved.

   - Make 'Opaque' use 'UnsafeCell' as the outer type, rather than
     inner.

  Documentation:

   - Suggest obtaining the source code of the Rust's 'core' library
     using the tarball instead of the repository.

  MAINTAINERS:

   - Andreas and Alice, from Samsung and Google respectively, are
     joining as reviewers of the "RUST" entry.

  As well as a few other minor changes and cleanups"

* tag 'rust-6.6' of https://github.com/Rust-for-Linux/linux: (42 commits)
  rust: init: update expanded macro explanation
  rust: init: add `{pin_}chain` functions to `{Pin}Init<T, E>`
  rust: init: make `PinInit<T, E>` a supertrait of `Init<T, E>`
  rust: init: implement `Zeroable` for `UnsafeCell<T>` and `Opaque<T>`
  rust: init: add support for arbitrary paths in init macros
  rust: init: add functions to create array initializers
  rust: init: add `..Zeroable::zeroed()` syntax for zeroing all missing fields
  rust: init: make initializer values inaccessible after initializing
  rust: init: wrap type checking struct initializers in a closure
  rust: init: make guards in the init macros hygienic
  rust: add derive macro for `Zeroable`
  rust: init: make `#[pin_data]` compatible with conditional compilation of fields
  rust: init: consolidate init macros
  docs: rust: clarify what 'rustup override' does
  docs: rust: update instructions for obtaining 'core' source
  docs: rust: add command line to rust-analyzer section
  scripts: generate_rust_analyzer: provide `cfg`s for `core` and `alloc`
  rust: bindgen: upgrade to 0.65.1
  rust: enable `no_mangle_with_rust_abi` Clippy lint
  rust: upgrade to Rust 1.71.1
  ...
2023-08-29 08:19:46 -07:00
Linus Torvalds
815c24a085 Merge tag 'linux-kselftest-kunit-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kunit updates from Shuah Khan:

 - add support for running Rust documentation tests as KUnit tests

 - make init, str, sync, types doctests compilable/testable

 - add support for attributes API which include speed, modules
   attributes, ability to filter and report attributes

 - add support for marking tests slow using attributes API

 - add attributes API documentation

 - fix a wild-memory-access bug in kunit_filter_suites() and a possible
   memory leak in kunit_filter_suites()

 - add support for counting number of test suites in a module, list
   action to kunit test modules, and test filtering on module tests

* tag 'linux-kselftest-kunit-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (25 commits)
  kunit: fix struct kunit_attr header
  kunit: replace KUNIT_TRIGGER_STATIC_STUB maro with KUNIT_STATIC_STUB_REDIRECT
  kunit: Allow kunit test modules to use test filtering
  kunit: Make 'list' action available to kunit test modules
  kunit: Report the count of test suites in a module
  kunit: fix uninitialized variables bug in attributes filtering
  kunit: fix possible memory leak in kunit_filter_suites()
  kunit: fix wild-memory-access bug in kunit_filter_suites()
  kunit: Add documentation of KUnit test attributes
  kunit: add tests for filtering attributes
  kunit: time: Mark test as slow using test attributes
  kunit: memcpy: Mark tests as slow using test attributes
  kunit: tool: Add command line interface to filter and report attributes
  kunit: Add ability to filter attributes
  kunit: Add module attribute
  kunit: Add speed attribute
  kunit: Add test attributes API structure
  MAINTAINERS: add Rust KUnit files to the KUnit entry
  rust: support running Rust documentation tests as KUnit ones
  rust: types: make doctests compilable/testable
  ...
2023-08-28 18:56:38 -07:00
Benno Lossin
0b4e3b6f6b rust: types: make Opaque be !Unpin
Adds a `PhantomPinned` field to `Opaque<T>`. This removes the last Rust
guarantee: the assumption that the type `T` can be freely moved. This is
not the case for many types from the C side (e.g. if they contain a
`struct list_head`). This change removes the need to add a
`PhantomPinned` field manually to Rust structs that contain C structs
which must not be moved.

Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Link: https://lore.kernel.org/r/20230630150216.109789-1-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-08-10 01:18:34 +02:00
Alice Ryhl
35cad617df rust: make UnsafeCell the outer type in Opaque
When combining `UnsafeCell` with `MaybeUninit`, it is idiomatic to use
`UnsafeCell` as the outer type. Intuitively, this is because a
`MaybeUninit<T>` might not contain a `T`, but we always want the effect
of the `UnsafeCell`, even if the inner value is uninitialized.

Now, strictly speaking, this doesn't really make a difference. The
compiler will always apply the `UnsafeCell` effect even if the inner
value is uninitialized. But I think we should follow the convention
here.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Link: https://lore.kernel.org/r/20230614115328.2825961-1-aliceryhl@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-08-10 01:18:34 +02:00
Alice Ryhl
1d24eb2d53 rust: delete ForeignOwnable::borrow_mut
We discovered that the current design of `borrow_mut` is problematic.
This patch removes it until a better solution can be found.

Specifically, the current design gives you access to a `&mut T`, which
lets you change where the `ForeignOwnable` points (e.g., with
`core::mem::swap`). No upcoming user of this API intended to make that
possible, making all of them unsound.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Fixes: 0fc4424d24 ("rust: types: introduce `ForeignOwnable`")
Link: https://lore.kernel.org/r/20230706094615.3080784-1-aliceryhl@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-08-04 17:10:50 +02:00
Miguel Ojeda
ed615fb8ee rust: types: make doctests compilable/testable
Rust documentation tests are going to be build/run-tested
with the KUnit integration added in a future patch, thus
update them to make them compilable/testable so that we
may start enforcing it.

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Björn Roy Baron <bjorn3_gh@protonmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2023-07-19 09:32:47 -06:00
Alice Ryhl
be7724cdbb rust: specify when ARef is thread safe
An `ARef` behaves just like the `Arc` when it comes to thread safety, so
we can reuse the thread safety comments from `Arc` here.

This is necessary because without this change, the Rust compiler will
assume that things are not thread safe even though they are.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20230531145939.3714886-4-aliceryhl@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-05-31 18:53:10 +02:00
Wedson Almeida Filho
f1fbd6a864 rust: introduce ARef
This is an owned reference to an object that is always ref-counted. This
is meant to be used in wrappers for C types that have their own ref
counting functions, for example, tasks, files, inodes, dentries, etc.

Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://lore.kernel.org/r/20230411054543.21278-8-wedsonaf@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-04-22 00:20:00 +02:00
Benno Lossin
692e8935e2 rust: types: add Opaque::ffi_init
This function allows to easily initialize `Opaque` with the pin-init
API. `Opaque::ffi_init` takes a closure and returns a pin-initializer.
This pin-initiailizer calls the given closure with a pointer to the
inner `T`.

Co-developed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20230408122429.1103522-14-y86-dev@protonmail.com
[ Fixed typo. ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-04-12 18:41:05 +02:00
Benno Lossin
3ff6e785ad rust: types: add Opaque::raw_get
This function mirrors `UnsafeCell::raw_get`. It avoids creating a
reference and allows solely using raw pointers.
The `pin-init` API will be using this, since uninitialized memory
requires raw pointers.

Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20230408122429.1103522-6-y86-dev@protonmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-04-12 18:41:05 +02:00
Wedson Almeida Filho
7118594466 rust: types: implement ForeignOwnable for the unit type
This allows us to use the unit type `()` when we have no object whose
ownership must be managed but one implementing the `ForeignOwnable`
trait is needed.

Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-02-01 13:24:36 +01:00
Wedson Almeida Filho
26949bac1e rust: types: implement ForeignOwnable for Box<T>
This allows us to hand ownership of Rust dynamically allocated
objects to the C side of the kernel.

Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Reviewed-by: Alice Ferrazzi <alice.ferrazzi@miraclelinux.com>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-02-01 13:24:19 +01:00
Wedson Almeida Filho
0fc4424d24 rust: types: introduce ForeignOwnable
It was originally called `PointerWrapper`. It is used to convert
a Rust object to a pointer representation (void *) that can be
stored on the C side, used, and eventually returned to Rust.

Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-02-01 13:24:07 +01:00
Wedson Almeida Filho
4d4692a2ff rust: types: introduce ScopeGuard
This allows us to run some code when the guard is dropped (e.g.,
implicitly when it goes out of scope). We can also prevent the
guard from running by calling its `dismiss()` method.

Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-02-01 00:14:01 +01:00
Wedson Almeida Filho
b9ecf9b9ac rust: types: add Opaque type
Add the `Opaque` type, which is meant to be used with FFI objects
that are never interpreted by Rust code, e.g.:

    struct Waiter {
        completion: Opaque<bindings::completion>,
        next: *mut Waiter,
    }

It has the advantage that the objects don't have to be
zero-initialised before calling their init functions, making
the code performance closer to C.

Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-12-04 01:59:16 +01:00
Wedson Almeida Filho
ba20915bae rust: types: add Either type
Introduce the new `types` module of the `kernel` crate with
`Either` as its first type.

`Either<L, R>` is a sum type that always holds either a value
of type `L` (`Left` variant) or `R` (`Right` variant).

For instance:

    struct Executor {
        queue: Either<BoxedQueue, &'static Queue>,
    }

Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-12-04 01:59:16 +01:00