Files
msm-5.15/arch/arm64/mm/ioremap.c
Greg Kroah-Hartman 910b540ffa Merge 5.15.41 into android13-5.15
Changes in 5.15.41
	batman-adv: Don't skb_split skbuffs with frag_list
	iwlwifi: iwl-dbg: Use del_timer_sync() before freeing
	hwmon: (tmp401) Add OF device ID table
	mac80211: Reset MBSSID parameters upon connection
	net: Fix features skip in for_each_netdev_feature()
	net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware when deleted
	net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups
	net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0
	net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters
	fbdev: simplefb: Cleanup fb_info in .fb_destroy rather than .remove
	fbdev: efifb: Cleanup fb_info in .fb_destroy rather than .remove
	fbdev: vesafb: Cleanup fb_info in .fb_destroy rather than .remove
	platform/surface: aggregator: Fix initialization order when compiling as builtin module
	ice: Fix race during aux device (un)plugging
	ice: fix PTP stale Tx timestamps cleanup
	ipv4: drop dst in multicast routing path
	drm/nouveau: Fix a potential theorical leak in nouveau_get_backlight_name()
	netlink: do not reset transport header in netlink_recvmsg()
	net: chelsio: cxgb4: Avoid potential negative array offset
	fbdev: efifb: Fix a use-after-free due early fb_info cleanup
	sfc: Use swap() instead of open coding it
	net: sfc: fix memory leak due to ptp channel
	mac80211_hwsim: call ieee80211_tx_prepare_skb under RCU protection
	nfs: fix broken handling of the softreval mount option
	ionic: fix missing pci_release_regions() on error in ionic_probe()
	dim: initialize all struct fields
	hwmon: (ltq-cputemp) restrict it to SOC_XWAY
	procfs: prevent unprivileged processes accessing fdinfo dir
	selftests: vm: Makefile: rename TARGETS to VMTARGETS
	arm64: vdso: fix makefile dependency on vdso.so
	virtio: fix virtio transitional ids
	s390/ctcm: fix variable dereferenced before check
	s390/ctcm: fix potential memory leak
	s390/lcs: fix variable dereferenced before check
	net/sched: act_pedit: really ensure the skb is writable
	net: ethernet: mediatek: ppe: fix wrong size passed to memset()
	net: bcmgenet: Check for Wake-on-LAN interrupt probe deferral
	drm/vc4: hdmi: Fix build error for implicit function declaration
	net: dsa: bcm_sf2: Fix Wake-on-LAN with mac_link_down()
	net/smc: non blocking recvmsg() return -EAGAIN when no data and signal_pending
	net: sfc: ef10: fix memory leak in efx_ef10_mtd_probe()
	tls: Fix context leak on tls_device_down
	drm/vmwgfx: Fix fencing on SVGAv3
	gfs2: Fix filesystem block deallocation for short writes
	hwmon: (f71882fg) Fix negative temperature
	RDMA/irdma: Fix deadlock in irdma_cleanup_cm_core()
	iommu: arm-smmu: disable large page mappings for Nvidia arm-smmu
	ASoC: max98090: Reject invalid values in custom control put()
	ASoC: max98090: Generate notifications on changes for custom control
	ASoC: ops: Validate input values in snd_soc_put_volsw_range()
	s390: disable -Warray-bounds
	ASoC: SOF: Fix NULL pointer exception in sof_pci_probe callback
	net: emaclite: Don't advertise 1000BASE-T and do auto negotiation
	net: sfp: Add tx-fault workaround for Huawei MA5671A SFP ONT
	secure_seq: use the 64 bits of the siphash for port offset calculation
	tcp: use different parts of the port_offset for index and offset
	tcp: resalt the secret every 10 seconds
	tcp: add small random increments to the source port
	tcp: dynamically allocate the perturb table used by source ports
	tcp: increase source port perturb table to 2^16
	tcp: drop the hash_32() part from the index calculation
	interconnect: Restore sync state by ignoring ipa-virt in provider count
	firmware_loader: use kernel credentials when reading firmware
	KVM: PPC: Book3S PR: Enable MSR_DR for switch_mmu_context()
	usb: xhci-mtk: fix fs isoc's transfer error
	x86/mm: Fix marking of unused sub-pmd ranges
	tty/serial: digicolor: fix possible null-ptr-deref in digicolor_uart_probe()
	tty: n_gsm: fix buffer over-read in gsm_dlci_data()
	tty: n_gsm: fix mux activation issues in gsm_config()
	usb: cdc-wdm: fix reading stuck on device close
	usb: typec: tcpci: Don't skip cleanup in .remove() on error
	usb: typec: tcpci_mt6360: Update for BMC PHY setting
	USB: serial: pl2303: add device id for HP LM930 Display
	USB: serial: qcserial: add support for Sierra Wireless EM7590
	USB: serial: option: add Fibocom L610 modem
	USB: serial: option: add Fibocom MA510 modem
	slimbus: qcom: Fix IRQ check in qcom_slim_probe
	fsl_lpuart: Don't enable interrupts too early
	serial: 8250_mtk: Fix UART_EFR register address
	serial: 8250_mtk: Fix register address for XON/XOFF character
	ceph: fix setting of xattrs on async created inodes
	Revert "mm/memory-failure.c: skip huge_zero_page in memory_failure()"
	mm/huge_memory: do not overkill when splitting huge_zero_page
	drm/vmwgfx: Disable command buffers on svga3 without gbobjects
	drm/nouveau/tegra: Stop using iommu_present()
	i40e: i40e_main: fix a missing check on list iterator
	net: atlantic: always deep reset on pm op, fixing up my null deref regression
	net: phy: Fix race condition on link status change
	writeback: Avoid skipping inode writeback
	cgroup/cpuset: Remove cpus_allowed/mems_allowed setup in cpuset_init_smp()
	arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map
	net: phy: micrel: Do not use kszphy_suspend/resume for KSZ8061
	net: phy: micrel: Pass .probe for KS8737
	SUNRPC: Ensure that the gssproxy client can start in a connected state
	drm/vmwgfx: Initialize drm_mode_fb_cmd2
	Revert "drm/amd/pm: keep the BACO feature enabled for suspend"
	dma-buf: call dma_buf_stats_setup after dmabuf is in valid list
	mm/hwpoison: use pr_err() instead of dump_page() in get_any_page()
	SUNRPC: Ensure we flush any closed sockets before xs_xprt_free()
	ping: fix address binding wrt vrf
	usb: gadget: uvc: rename function to be more consistent
	usb: gadget: uvc: allow for application to cleanly shutdown
	Linux 5.15.41

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Ia65cdbbddf553237d6a3a38efb9bcb2fcc3990ec
2022-05-18 11:31:34 +02:00

273 lines
6.3 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Based on arch/arm/mm/ioremap.c
*
* (C) Copyright 1995 1996 Linus Torvalds
* Hacked for ARM by Phil Blundell <philb@gnu.org>
* Hacked to allow all architectures to build, and various cleanups
* by Russell King
* Copyright (C) 2012 ARM Ltd.
*/
#define pr_fmt(fmt) "ioremap: " fmt
#include <linux/export.h>
#include <linux/mm.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/arm-smccc.h>
#include <asm/fixmap.h>
#include <asm/tlbflush.h>
#include <asm/hypervisor.h>
struct ioremap_guard_ref {
refcount_t count;
};
static DEFINE_STATIC_KEY_FALSE(ioremap_guard_key);
static DEFINE_XARRAY(ioremap_guard_array);
static DEFINE_MUTEX(ioremap_guard_lock);
static bool ioremap_guard;
static int __init ioremap_guard_setup(char *str)
{
ioremap_guard = true;
return 0;
}
early_param("ioremap_guard", ioremap_guard_setup);
static void fixup_fixmap(void)
{
pte_t *ptep = __get_fixmap_pte(FIX_EARLYCON_MEM_BASE);
if (!ptep)
return;
ioremap_phys_range_hook(__pte_to_phys(*ptep), PAGE_SIZE,
__pgprot(pte_val(*ptep) & PTE_ATTRINDX_MASK));
}
void kvm_init_ioremap_services(void)
{
struct arm_smccc_res res;
if (!ioremap_guard)
return;
/* We need all the functions to be implemented */
if (!kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_INFO) ||
!kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_ENROLL) ||
!kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_MAP) ||
!kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_UNMAP))
return;
arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID,
0, 0, 0, &res);
if (res.a0 != PAGE_SIZE)
return;
arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_ENROLL_FUNC_ID,
&res);
if (res.a0 == SMCCC_RET_SUCCESS) {
static_branch_enable(&ioremap_guard_key);
fixup_fixmap();
pr_info("Using KVM MMIO guard for ioremap\n");
} else {
pr_warn("KVM MMIO guard registration failed (%ld)\n", res.a0);
}
}
void ioremap_phys_range_hook(phys_addr_t phys_addr, size_t size, pgprot_t prot)
{
if (!static_branch_unlikely(&ioremap_guard_key))
return;
if (pfn_valid(__phys_to_pfn(phys_addr)))
return;
mutex_lock(&ioremap_guard_lock);
while (size) {
u64 pfn = phys_addr >> PAGE_SHIFT;
struct ioremap_guard_ref *ref;
struct arm_smccc_res res;
ref = xa_load(&ioremap_guard_array, pfn);
if (ref) {
refcount_inc(&ref->count);
goto next;
}
/*
* It is acceptable for the allocation to fail, specially
* if trying to ioremap something very early on, like with
* earlycon, which happens long before kmem_cache_init.
* This page will be permanently accessible, similar to a
* saturated refcount.
*/
if (slab_is_available())
ref = kzalloc(sizeof(*ref), GFP_KERNEL);
if (ref) {
refcount_set(&ref->count, 1);
if (xa_err(xa_store(&ioremap_guard_array, pfn, ref,
GFP_KERNEL))) {
kfree(ref);
ref = NULL;
}
}
arm_smccc_1_1_hvc(ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID,
phys_addr, prot, &res);
if (res.a0 != SMCCC_RET_SUCCESS) {
pr_warn_ratelimited("Failed to register %llx\n",
phys_addr);
xa_erase(&ioremap_guard_array, pfn);
kfree(ref);
goto out;
}
next:
size -= PAGE_SIZE;
phys_addr += PAGE_SIZE;
}
out:
mutex_unlock(&ioremap_guard_lock);
}
void iounmap_phys_range_hook(phys_addr_t phys_addr, size_t size)
{
if (!static_branch_unlikely(&ioremap_guard_key))
return;
VM_BUG_ON(phys_addr & ~PAGE_MASK || size & ~PAGE_MASK);
mutex_lock(&ioremap_guard_lock);
while (size) {
u64 pfn = phys_addr >> PAGE_SHIFT;
struct ioremap_guard_ref *ref;
struct arm_smccc_res res;
ref = xa_load(&ioremap_guard_array, pfn);
if (!ref) {
pr_warn_ratelimited("%llx not tracked, left mapped\n",
phys_addr);
goto next;
}
if (!refcount_dec_and_test(&ref->count))
goto next;
xa_erase(&ioremap_guard_array, pfn);
kfree(ref);
arm_smccc_1_1_hvc(ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_UNMAP_FUNC_ID,
phys_addr, &res);
if (res.a0 != SMCCC_RET_SUCCESS) {
pr_warn_ratelimited("Failed to unregister %llx\n",
phys_addr);
goto out;
}
next:
size -= PAGE_SIZE;
phys_addr += PAGE_SIZE;
}
out:
mutex_unlock(&ioremap_guard_lock);
}
static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size,
pgprot_t prot, void *caller)
{
unsigned long last_addr;
unsigned long offset = phys_addr & ~PAGE_MASK;
int err;
unsigned long addr;
struct vm_struct *area;
/*
* Page align the mapping address and size, taking account of any
* offset.
*/
phys_addr &= PAGE_MASK;
size = PAGE_ALIGN(size + offset);
/*
* Don't allow wraparound, zero size or outside PHYS_MASK.
*/
last_addr = phys_addr + size - 1;
if (!size || last_addr < phys_addr || (last_addr & ~PHYS_MASK))
return NULL;
/*
* Don't allow RAM to be mapped.
*/
if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr))))
return NULL;
area = get_vm_area_caller(size, VM_IOREMAP, caller);
if (!area)
return NULL;
addr = (unsigned long)area->addr;
area->phys_addr = phys_addr;
err = ioremap_page_range(addr, addr + size, phys_addr, prot);
if (err) {
vunmap((void *)addr);
return NULL;
}
return (void __iomem *)(offset + addr);
}
void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot)
{
return __ioremap_caller(phys_addr, size, prot,
__builtin_return_address(0));
}
EXPORT_SYMBOL(__ioremap);
void iounmap(volatile void __iomem *io_addr)
{
unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
/*
* We could get an address outside vmalloc range in case
* of ioremap_cache() reusing a RAM mapping.
*/
if (is_vmalloc_addr((void *)addr))
vunmap((void *)addr);
}
EXPORT_SYMBOL(iounmap);
void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
{
/* For normal memory we already have a cacheable mapping. */
if (pfn_is_map_memory(__phys_to_pfn(phys_addr)))
return (void __iomem *)__phys_to_virt(phys_addr);
return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),
__builtin_return_address(0));
}
EXPORT_SYMBOL(ioremap_cache);
/*
* Must be called after early_fixmap_init
*/
void __init early_ioremap_init(void)
{
early_ioremap_setup();
}
bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
unsigned long flags)
{
unsigned long pfn = PHYS_PFN(offset);
return pfn_is_map_memory(pfn);
}