OSDN Git Service

sagit-ice-cold/kernel_xiaomi_msm8998.git
4 years agoqos: Don't allow userspace to impose restrictions on CPU idle levels
Sultan Alsawaf [Fri, 3 May 2019 07:34:19 +0000 (00:34 -0700)]
qos: Don't allow userspace to impose restrictions on CPU idle levels

Giving userspace intimate control over CPU latency requirements is
nonsense. Userspace can't even stop itself from being preempted, so
there's no reason for it to have access to a mechanism primarily used to
eliminate CPU delays on the order of microseconds.

Remove userspace's ability to send pm_qos requests so that it can't hurt
power consumption.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Remove sync debug name generation from hot path
Sultan Alsawaf [Thu, 18 Apr 2019 03:06:20 +0000 (20:06 -0700)]
msm: kgsl: Remove sync debug name generation from hot path

Generating a sync debug name with snprintf in a hot path results in
excessive CPU time wasted on unneeded debug info. Remove the name
generation entirely to cut down CPU waste in the GPU's rendering hot
path.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Remove sync debug name generation from hot path
Sultan Alsawaf [Thu, 18 Apr 2019 03:05:02 +0000 (20:05 -0700)]
msm: mdss: Remove sync debug name generation from hot path

Generating a sync debug name with snprintf in a hot path results in
excessive CPU time wasted on unneeded debug info. Remove the name
generation entirely to cut down CPU waste in the frame render hot path.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agosynaptics_dsx_force: Require low latency
Siarhei Vishniakou [Thu, 28 Jun 2018 09:53:18 +0000 (10:53 +0100)]
synaptics_dsx_force: Require low latency

Currently, CPU can enter deep sleep while waiting for data on the i2c
bug. That means an i2c read of 8 bytes can take as long as 10 ms, which
would overrun the desired interrupt handling time.
Use pm qos to require low latency and prevent CPU from entering deep
sleep while handling touch interrupts.

Bug: 110939384
Test: look at the i2c read traces:
1) ./external/chromium-trace/systrace.py --atrace-categories=view,wm,am,app,gfx,i2c,sched,irq,video,power,input,workq,freq
2) perform a fling
3) review the i2c read duration on the touchscreen bus

Change-Id: Icf8ab09324003a85af70517769ced3bae52f705c
Signed-Off-By: Siarhei Vishniakou <svv@google.com>
Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: adapted for synaptics_dsx_force]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agomsm: clock-osm: Use CLKFLAG_NO_RATE_CACHE for pwrcl and perfcl clk
Sultan Alsawaf [Mon, 17 Jul 2017 02:52:13 +0000 (19:52 -0700)]
msm: clock-osm: Use CLKFLAG_NO_RATE_CACHE for pwrcl and perfcl clk

Clusters can have frequency change requests ignored when
they come online without having this flag set.
This can result in clusters running at their default frequency
instead of the frequency chosen by the CPU governor.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agobase: dd: Continue probe deferral forever as needed after late_initcall
Sultan Alsawaf [Mon, 15 Apr 2019 03:50:47 +0000 (20:50 -0700)]
base: dd: Continue probe deferral forever as needed after late_initcall

Currently, the probe deferral mechanism gives up on deferring probe
after late_initcall is complete, which could leave some very
slow-to-start drivers broken after the kernel finishes starting up.

Since we don't want to leave behind any drivers that still need probing
after late_initcall, continue the probe deferral sequence forever after
late_initcall until there are no more devices left that are requesting
probe deferral.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoqpnp-fg-gen3: Limit how frequently fg data can be queried
Sultan Alsawaf [Sat, 20 Jul 2019 17:22:54 +0000 (10:22 -0700)]
qpnp-fg-gen3: Limit how frequently fg data can be queried

Querying the fuelgauge for data is expensive, so doing it frequently can
result in a significant increase in power consumption. The fuelgauge
also only generates fresh statistics once per second.

Limit how frequently data queries can be sent to 2 seconds in order to
prevent fuelgauge queries from consuming too much power. Only do this
while there is no USB cable connected to the device, since the charging
drivers need fresh statistics when there's a USB cable connected.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoARM: dts: msm: Disable PM8005 GPIOs
Sultan Alsawaf [Mon, 13 Aug 2018 21:18:29 +0000 (14:18 -0700)]
ARM: dts: msm: Disable PM8005 GPIOs

All of these are disabled and not used on wahoo. Fixes the following init
errors:
[    0.310877] c0      1 qcom,qpnp-pin 800f000.qcom,spmi:qcom,pm8005@4:gpios: qpnp_pin_probe: no device nodes specified in topology
[    0.310901] c0      1 qcom,qpnp-pin: probe of 800f000.qcom,spmi:qcom,pm8005@4:gpios failed with error -22

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoARM: dts: msm8998: Set GPU idle timeout to 64 ms
Sultan Alsawaf [Sun, 12 Aug 2018 02:44:19 +0000 (19:44 -0700)]
ARM: dts: msm8998: Set GPU idle timeout to 64 ms

This matches the ULPS timeout used in MDSS; no need to keep the GPU
running after the display has decided to enter a low-power state.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: ipa3: Fix redundant wakelock releases in error paths
Sultan Alsawaf [Sat, 30 Jun 2018 03:04:40 +0000 (12:04 +0900)]
msm: ipa3: Fix redundant wakelock releases in error paths

In the error paths here, these functions are re-scheduled when they fail;
in other words, these functions are run repeatedly until they succeed.

Since the ipa3 wakelock is released before checking for errors, it can be
released more than once when there is an error and the function that errors
out needs to be re-run.

To fix this, only release the ipa3 wakelock upon success in these functions.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agonet: ipc_router: Decrement ref count for remote port
Deepak Kumar Singh [Wed, 19 Sep 2018 11:45:17 +0000 (17:15 +0530)]
net: ipc_router: Decrement ref count for remote port

Ref count for remote port pointer is not being decremented
at function exit thereby causing memory leak of 128 byte.

Decrementing ref count for remote port pointer after its usage is done.

CRs-Fixed: 2315498
Change-Id: Ida00220201f3dba589a65d9b2ba84b83d6b00004
Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
[wight554: fix conflict]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agousb: pd: Fix memory leak in usbpd_create()
Jack Pham [Wed, 14 Nov 2018 20:01:02 +0000 (12:01 -0800)]
usb: pd: Fix memory leak in usbpd_create()

In both the usbpd_create() failure path and usbpd_destroy(),
some associated allocations, namely the string allocated from
dev_set_name() as well as the resource-mananaged dual_role_instance
structure were not getting freed. These were detected by kmemleak.

unreferenced object 0xffffffe158c37c80 (size 128):
  comm "kworker/6:1", pid 198, jiffies 4294938493 (age 469.090s)
  hex dump (first 32 bytes):
    75 73 62 70 64 30 00 6b 6b 6b 6b 6b 6b 6b 6b 6b  usbpd0.kkkkkkkkk
    6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
  backtrace:
    [<ffffff894d897f38>] kmemleak_alloc+0x60/0xc0
    [<ffffff894ca3ca98>] __kmalloc_track_caller+0x220/0x3bc
    [<ffffff894cc12d00>] kvasprintf+0x80/0x10c
    [<ffffff894cc12dfc>] kvasprintf_const+0x70/0xe4
    [<ffffff894d8892d8>] kobject_set_name_vargs+0x5c/0xe8
    [<ffffff894cf3afdc>] dev_set_name+0x84/0xb0
    [<ffffff894d16aa6c>] usbpd_create+0x84/0x700
    [<ffffff894d172d14>] pdphy_probe+0x21c/0x2ec
    [<ffffff894cf42d88>] platform_drv_probe+0x5c/0xb0
    [<ffffff894cf40208>] driver_probe_device+0x2e8/0x41c
    [<ffffff894cf40c80>] __device_attach_driver+0xcc/0x144
    [<ffffff894cf3e374>] bus_for_each_drv+0x80/0xc8
    [<ffffff894cf40464>] __device_attach+0xa4/0x154
    [<ffffff894cf40534>] device_initial_probe+0x20/0x2c
    [<ffffff894cf3e518>] bus_probe_device+0x34/0x8c
    [<ffffff894cf40a1c>] deferred_probe_work_func+0xcc/0x16c

unreferenced object 0xffffffe158c00580 (size 128):
  comm "kworker/6:1", pid 198, jiffies 4294938493 (age 469.090s)
  hex dump (first 32 bytes):
    78 5d c9 58 e1 ff ff ff 78 5d c9 58 e1 ff ff ff  x].X....x].X....
    24 ef 0c 4d 89 ff ff ff 80 b0 3a 59 e1 ff ff ff  $..M......:Y....
  backtrace:
    [<ffffff894d897f38>] kmemleak_alloc+0x60/0xc0
    [<ffffff894ca3ca98>] __kmalloc_track_caller+0x220/0x3bc
    [<ffffff894cf44198>] devres_alloc_node+0x34/0x70
    [<ffffff894d0cedec>] devm_dual_role_instance_register+0x40/0x178
    [<ffffff894d16af6c>] usbpd_create+0x584/0x700
    [<ffffff894d172d14>] pdphy_probe+0x21c/0x2ec
    [<ffffff894cf42d88>] platform_drv_probe+0x5c/0xb0
    [<ffffff894cf40208>] driver_probe_device+0x2e8/0x41c
    [<ffffff894cf40c80>] __device_attach_driver+0xcc/0x144
    [<ffffff894cf3e374>] bus_for_each_drv+0x80/0xc8
    [<ffffff894cf40464>] __device_attach+0xa4/0x154
    [<ffffff894cf40534>] device_initial_probe+0x20/0x2c
    [<ffffff894cf3e518>] bus_probe_device+0x34/0x8c
    [<ffffff894cf40a1c>] deferred_probe_work_func+0xcc/0x16c
    [<ffffff894c8d1c64>] process_one_work+0x1c0/0x3d4
    [<ffffff894c8d19a4>] process_scheduled_works+0x28/0x40

Both of these can be fixed by making sure to use put_device()
instead of simply kfree(pd), as that will make sure to call
additional cleanup routines for the associated objects.

Change-Id: Id755ddef66308c7d10217b2b8ef56c47421188a5
Signed-off-by: Jack Pham <jackp@codeaurora.org>
4 years agousb: dwc3-msm: Fix memory leak of dwc3 child device
Jack Pham [Sun, 25 Nov 2018 01:36:41 +0000 (17:36 -0800)]
usb: dwc3-msm: Fix memory leak of dwc3 child device

In case of failed probe or driver removal, the dwc3 child device
is left with an extra reference count and hence does not get
cleaned up properly, resulting in a memory leak. kmemleak reports
the following (and others):

unreferenced object 0xffffffdf5934a600 (size 128):
  comm "kworker/2:1", pid 83, jiffies 4294938474 (age 2208.110s)
  hex dump (first 32 bytes):
    00 00 60 0a 00 00 00 00 ff cc 60 0a 00 00 00 00  ..`.......`.....
    a0 5f 2b 7d df ff ff ff 00 02 00 00 00 00 00 00  ._+}............
  backtrace:
    [<ffffff9aeb4a0cb8>] kmemleak_alloc+0x60/0xc0
    [<ffffff9aea63b51c>] __kmalloc+0x220/0x3bc
    [<ffffff9aeafdd5b8>] of_device_alloc+0x98/0x1a8
    [<ffffff9aeafdd87c>] of_platform_device_create_pdata+0x58/0xcc
    [<ffffff9aeafddc38>] of_platform_bus_create+0x220/0x438
    [<ffffff9aeafdded8>] of_platform_populate+0x88/0x104
    [<ffffff9aeacf10f8>] dwc3_msm_probe+0xc7c/0x12f0
    [<ffffff9aeab46514>] platform_drv_probe+0x5c/0xb0
    [<ffffff9aeab43994>] driver_probe_device+0x2e8/0x41c
    [<ffffff9aeab4440c>] __device_attach_driver+0xcc/0x144
    [<ffffff9aeab41b00>] bus_for_each_drv+0x80/0xc8
    [<ffffff9aeab43bf0>] __device_attach+0xa4/0x154
    [<ffffff9aeab43cc0>] device_initial_probe+0x20/0x2c
    [<ffffff9aeab41ca4>] bus_probe_device+0x34/0x8c
    [<ffffff9aeab441a8>] deferred_probe_work_func+0xcc/0x16c
    [<ffffff9aea4d1fe4>] process_one_work+0x1c0/0x3d4

Plug this by adding a call to platform_device_put() which balances
the implicit get_device() from the of_find_device_by_node() call
done during probe.

Change-Id: I1e590cfe14ebbb66005b41f6dfa6a56df9489288
Signed-off-by: Jack Pham <jackp@codeaurora.org>
4 years agomsm: pcie: Fix uninitialized pointer usage in msm_pcie_debug_info()
Sultan Alsawaf [Wed, 31 May 2017 22:39:11 +0000 (15:39 -0700)]
msm: pcie: Fix uninitialized pointer usage in msm_pcie_debug_info()

pdev is used uninitialized in the PCIE_DBG_FS() invocations above its
initialization. Fix it.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: camera: isp: Fix memory leaks in vfe probe
Sultan Alsawaf [Tue, 21 Mar 2017 17:42:56 +0000 (10:42 -0700)]
msm: camera: isp: Fix memory leaks in vfe probe

Memory is needlessly allocated to vfe_parent_dev and vfe_parent_dev->common_sd
and never freed.

Since the allocated memory is not used anywhere outside of vfe_probe(),
and since it's unnecessary, just remove the allocations entirely and use a
stack variable instead.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: mdss: Don't cache the address of a stack variable in timings init
Sultan Alsawaf [Tue, 21 Mar 2017 17:12:10 +0000 (10:12 -0700)]
msm: mdss: Don't cache the address of a stack variable in timings init

When the panel timings are parsed, a stack-allocated variable is used to
store the parsed data; however, this creates two problems. The first
problem is that this creates a memory leak since a kstrdup() address is
stored into the stack-allocated variable at the end of the
mdss_dsi_panel_timing_from_dt() function. The second problem this creates
is that the address of the stack-allocated variable is stored into the
current_timing struct member (inside mdss_dsi_panel_timing_switch()) for
future use in the driver.

Since the data that current_timing points to is expected to persist long
after init, allocate memory for the timing settings to fix the issues.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agosoc: qcom: watchdog_v2: Fix memory leaks when memory_dump_v2 isn't built
Sultan Alsawaf [Tue, 21 Mar 2017 08:06:00 +0000 (01:06 -0700)]
soc: qcom: watchdog_v2: Fix memory leaks when memory_dump_v2 isn't built

When the memory_dump_v2.c driver isn't built (CONFIG_MSM_MEMORY_DUMP_V2=n),
an inline version of msm_dump_data_register() will be used that does
nothing. This means that all memory allocated with the intention of going
to msm_dump_data_register() will be leaked.

Fix this by ignoring the entire code block when CONFIG_MSM_MEMORY_DUMP_V2
is disabled.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Julian Liu <wlootlxt123@gmail.com>
4 years agopinctrl: qcom: Update irq handle for GPIO pins
Archana Sathyakumar [Wed, 26 Jul 2017 13:37:51 +0000 (07:37 -0600)]
pinctrl: qcom: Update irq handle for GPIO pins

Default handle_irq for tlmm irq chip is handle_edge_irq. For direct
connect GPIOs, the handle_irq is not changed unlike non-direct connect
GPIOs. This causes an interrupt storm for level trigger types as
handle_edge_irq does not mask the interrupt within the function. Change
this to handle_fasteoi_irq such that both level and edge interrupts are
handled correctly.

Change-Id: I79f0d4d92145f85a8043875301400ecf36b46c7b
Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
4 years agocrypto: Make CRYPTO_DEV_QCE depend on CRYPTO_DEV_QCRYPTO being disabled
Sultan Alsawaf [Thu, 17 May 2018 02:57:56 +0000 (19:57 -0700)]
crypto: Make CRYPTO_DEV_QCE depend on CRYPTO_DEV_QCRYPTO being disabled

CRYPTO_DEV_QCE and CRYPTO_DEV_QCRYPTO both yield a qcrypto.o with
matching platform device names, so one of them gets ignored by the
platform device driver since it's redundant.

CRYPTO_DEV_QCRYPTO's qcrypto.o is the up-to-date one, so it should take
precedence and disable CRYPTO_DEV_QCE when it's built.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agocpuidle: don't disable cpuidle when entering suspend
Tim Murray [Wed, 21 Sep 2016 20:11:25 +0000 (13:11 -0700)]
cpuidle: don't disable cpuidle when entering suspend

cpuidle was disabled while entering suspend as part of commit
8651f97bd951d0bb1c10fa24e3fa3455193f3548 in order to work around some
ACPI bugs. However, there's no reason to do this on modern
platforms. Leaving cpuidle enabled can result in improved power
consumption if dpm_resume_noirq runs for a significant time.

Change-Id: Ie182785b176f448698c0264eba554d1e315e8a06

4 years agomsm: msm_bus: Don't enable QoS clocks when none are present
Sultan Alsawaf [Mon, 15 Apr 2019 01:07:37 +0000 (18:07 -0700)]
msm: msm_bus: Don't enable QoS clocks when none are present

There's no point in enabling these when are none of them for certain
clients.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Mark dispatcher thread as performance-critical
Sultan Alsawaf [Sun, 16 Jun 2019 16:55:07 +0000 (09:55 -0700)]
msm: kgsl: Mark dispatcher thread as performance-critical

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Dispatch commands using a master kthread
Sultan Alsawaf [Sun, 16 Jun 2019 16:54:40 +0000 (09:54 -0700)]
msm: kgsl: Dispatch commands using a master kthread

Instead of coordinating between a worker when dispatching commands and
abusing a mutex lock for synchronization, it's faster to keep a single
kthread dispatching commands whenever needed. This reduces GPU
processing latency.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoRevert "msm: kgsl: Defer issue commands to worker thread"
wloot [Sun, 16 Jun 2019 17:11:59 +0000 (01:11 +0800)]
Revert "msm: kgsl: Defer issue commands to worker thread"

This reverts commit 71c3b2e17c6fb4d1b040d3c8c75d76b78a050cce.

4 years agosynaptics_dsx_force: Mark IRQs as performance critical
Sultan Alsawaf [Wed, 17 Apr 2019 18:13:45 +0000 (11:13 -0700)]
synaptics_dsx_force: Mark IRQs as performance critical

Touch latency is pretty important; let's service the touch IRQs and
associated kthreads on fast CPUs to improve touch responsiveness.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: adapted wahoo ts change for synaptics_dsx_force]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agokernel: Force trivial, unbound kthreads onto low-power CPUs
Sultan Alsawaf [Wed, 30 May 2018 00:57:40 +0000 (17:57 -0700)]
kernel: Force trivial, unbound kthreads onto low-power CPUs

In order to reduce power consumption, force all non-perf-critical, unbound
kthreads onto the low-power CPUs. Note that init (pid == 1) must be
explicitly excluded from this so that all processes forked from init have a
sane default CPU affinity mask.

Signed-off-by: Sultan Alsawaf <sultanxda@gmail.com>
Signed-off-by: Julian Liu <wlootlxt123@gmail.com>
4 years agoinput: fingerprint: Mark IRQ as performance critical
Sultan Alsawaf [Wed, 30 May 2018 00:24:10 +0000 (17:24 -0700)]
input: fingerprint: Mark IRQ as performance critical

In order to improve fingerprint wake performance, mark the fingerprint
reader's IRQ as performance-critical.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
[wight554: apply fpc1020 change on fpc1268 ang goodix]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agomsm: mdss: Mark IRQ and important kthreads as performance critical
Sultan Alsawaf [Wed, 30 May 2018 00:19:45 +0000 (17:19 -0700)]
msm: mdss: Mark IRQ and important kthreads as performance critical

These items are in the critical path for rendering frames to the display
(they exhibit increased CPU usage when heavy frame rendering takes place),
so mark them as performance-critical.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: kgsl: Mark IRQ and worker thread as performance critical
Sultan Alsawaf [Wed, 30 May 2018 00:11:29 +0000 (17:11 -0700)]
msm: kgsl: Mark IRQ and worker thread as performance critical

These items are in the critical path for rendering frames to the display,
so mark them as performance-critical.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agokernel: Add API to mark IRQs and kthreads as performance critical
Sultan Alsawaf [Sat, 20 Jul 2019 07:10:53 +0000 (00:10 -0700)]
kernel: Add API to mark IRQs and kthreads as performance critical

On devices with a CPU that contains heterogeneous cores (e.g.,
big.LITTLE), it can be beneficial to place some performance-critical
IRQs and kthreads onto the performance CPU cluster in order to improve
performance.

This commit adds the following APIs:
-kthread_run_perf_critical() to create and start a perf-critical kthread
-irq_set_perf_affinity() to mark an active IRQ as perf-critical
-IRQF_PERF_CRITICAL to schedule an IRQ and any threads it may have onto
 performance CPUs
-PF_PERF_CRITICAL to mark a process (mainly a kthread) as performance
 critical (this is used by kthread_run_perf_critical())

In order to accommodate this new API, the following changes are made:
-Performance-critical IRQs are distributed evenly among online CPUs
 available in cpu_perf_mask
-Performance-critical IRQs have their affinities reaffined upon exit
 from suspend (since the affinities are broken when non-boot CPUs are
 disabled)
-Performance-critical IRQs and their threads have their affinities reset
 upon entering suspend, so that upon immediate suspend exit (when only
 the boot CPU is online), interrupts can be processed and interrupt
 threads can be scheduled onto an online CPU (otherwise we'd hit a
 kernel BUG)
-__set_cpus_allowed_ptr() is modified to enforce a performance-critical
 kthread's affinity
-Perf-critical IRQs are marked with IRQD_AFFINITY_MANAGED so userspace
 can't mess with their affinity

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agocpumask: Add cpumasks for big and LITTLE CPU clusters
Sultan Alsawaf [Mon, 15 Apr 2019 03:19:37 +0000 (20:19 -0700)]
cpumask: Add cpumasks for big and LITTLE CPU clusters

Add cpu_lp_mask and cpu_perf_mask to represent the CPUs that belong to
each cluster in a dual-cluster, heterogeneous system.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agoMakefile: Use O3 optimization level for Clang LTO
Danny Lin [Tue, 6 Aug 2019 03:06:40 +0000 (03:06 +0000)]
Makefile: Use O3 optimization level for Clang LTO

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
4 years agosdfat: optimize for size
Julian Liu [Tue, 17 Sep 2019 21:05:36 +0000 (05:05 +0800)]
sdfat: optimize for size

4 years agodts: xiaomi: msm8998: disable unused codecs
Raphiel Rollerscaperers [Mon, 25 Mar 2019 14:17:07 +0000 (21:17 +0700)]
dts: xiaomi: msm8998: disable unused codecs

We're using tas2599, thus this device can't probed.

Change-Id: I085b63f23714f3beb30067517f9d73d0dfeac882
[wight554: apply sdm845 change on our dts]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agodts: xiaomi: msm8998: disable unused remote debugger drivers
Volodymyr Zhdanov [Wed, 10 Jul 2019 17:47:30 +0000 (20:47 +0300)]
dts: xiaomi: msm8998: disable unused remote debugger drivers

4 years agodts: xiaomi: msm8998: properly disable tavil sound card
Volodymyr Zhdanov [Wed, 10 Jul 2019 10:12:05 +0000 (13:12 +0300)]
dts: xiaomi: msm8998: properly disable tavil sound card

* the node we use now is declared in qrd dts
* while at it, disable tavil codec either

4 years agoARM: dts: msm8998: Remove few bottom frequencies of low energy efficiency
Julian Liu [Tue, 17 Sep 2019 20:51:15 +0000 (04:51 +0800)]
ARM: dts: msm8998: Remove few bottom frequencies of low energy efficiency

4 years agoqcacld-3.0: optimize for size
Yaroslav Furman [Sun, 20 Jan 2019 10:36:08 +0000 (13:36 +0300)]
qcacld-3.0: optimize for size

- Add -Os flag.
- Add -g0, drops most of the debug that we don't really care about.

Saves about 120kb, which isn't much, but appretiated anyway.

Signed-off-by: Yaroslav Furman <yaro330@gmail.com>
4 years agoBACKPORT: security: Implement Clang's stack initialization
Kees Cook [Wed, 10 Apr 2019 15:48:31 +0000 (08:48 -0700)]
BACKPORT: security: Implement Clang's stack initialization

CONFIG_INIT_STACK_ALL turns on stack initialization based on
-ftrivial-auto-var-init in Clang builds, which has greater coverage
than CONFIG_GCC_PLUGINS_STRUCTLEAK_BYREF_ALL.

-ftrivial-auto-var-init Clang option provides trivial initializers for
uninitialized local variables, variable fields and padding.

It has three possible values:
  pattern - uninitialized locals are filled with a fixed pattern
    (mostly 0xAA on 64-bit platforms, see https://reviews.llvm.org/D54604
    for more details, but 0x000000AA for 32-bit pointers) likely to cause
    crashes when uninitialized value is used;
  zero (it's still debated whether this flag makes it to the official
    Clang release) - uninitialized locals are filled with zeroes;
  uninitialized (default) - uninitialized locals are left intact.

This patch uses only the "pattern" mode when CONFIG_INIT_STACK_ALL is
enabled.

Developers have the possibility to opt-out of this feature on a
per-variable basis by using __attribute__((uninitialized)), but such
use should be well justified in comments.

The Android 4.14 backport drops CC_HAS_AUTO_VAR_INIT, because Kconfig
is too old to support compiler feature checks.

Change-Id: I9dca079dd015d3cea0446bbdb916e04f4199c626
Co-developed-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Tested-by: Alexander Potapenko <glider@google.com>
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
(cherry picked from commit 709a972efb01efaeb97cad1adc87fe400119c8ab)
Bug: 133428616
Signed-off-by: Alexander Potapenko <glider@google.com>
[wight554: properly call cc option not to mess up with gcc]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agoBACKPORT: security: Create "kernel hardening" config area
Kees Cook [Wed, 10 Apr 2019 15:23:44 +0000 (08:23 -0700)]
BACKPORT: security: Create "kernel hardening" config area

Right now kernel hardening options are scattered around various Kconfig
files. This can be a central place to collect these kinds of options
going forward. This is initially populated with the memory initialization
options from the gcc-plugins.

The Android backport only adds INIT_STACK_NONE, as GCC plugins are
unavailable in the Android 4.14 tree.

Change-Id: Ic11cb574d2b447e30b0d93977a6707b53744e1cf
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>
(cherry picked from commit 9f671e58159adea641f76c56d1f0bbdcb3c524ff)
Bug: 133428616
Signed-off-by: Alexander Potapenko <glider@google.com>
4 years agokbuild: use LLVM integrated assembler for C files
Stefan Agner [Sun, 30 Dec 2018 13:47:24 +0000 (14:47 +0100)]
kbuild: use LLVM integrated assembler for C files

Now that all inline assembly can be assembled by LLVM's integrated
assembler, lets use the integreated assembler for c files.

Signed-off-by: Stefan Agner <stefan@agner.ch>
[wight554: adapted for this tree]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agoFROMLIST: BACKPORT: arm64: select ARCH_SUPPORTS_LTO_CLANG
Sami Tolvanen [Thu, 2 Nov 2017 16:34:42 +0000 (09:34 -0700)]
FROMLIST: BACKPORT: arm64: select ARCH_SUPPORTS_LTO_CLANG

Allow CONFIG_LTO_CLANG to be enabled for the architecture.

Bug: 62093296
Bug: 67506682
Change-Id: Id8e06b49877c4de2f15b51fc432d601b83b2c68f
(am from https://patchwork.kernel.org/patch/10060333/)
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoarm64: vdso: disable LTO
Sami Tolvanen [Tue, 19 Dec 2017 16:55:23 +0000 (08:55 -0800)]
arm64: vdso: disable LTO

Due to a bug in clang, vdso fails to build when both LTO_CLANG and
CC_OPTIMIZE_FOR_SIZE are enabled:

  https://bugs.llvm.org/show_bug.cgi?id=32155

Disable LTO for vdso to work around the problem.

Bug: 62093296
Bug: 67506682
Change-Id: I1d0279535fd389db4c829e4556f9ef728f240a34
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoarm64: disable ARM64_ERRATUM_843419 for clang LTO
Sami Tolvanen [Mon, 29 Jan 2018 19:19:19 +0000 (11:19 -0800)]
arm64: disable ARM64_ERRATUM_843419 for clang LTO

CONFIG_LTO_CLANG depends on GNU gold, which can generate ADR_PREL_PG_HI21
relocations with --fix-cortex-a53-843419, even when -code-model=large has
been passed to LLVMgold.

Since ARM64_ERRATUM_843419 disables kernel support for these relocations,
disable the erratum when LTO is used.

Bug: 67506682
Change-Id: I5d419cae432a26af5b6eff362b869639c64c6fb3
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoFROMLIST: BACKPORT: arm64: make mrs_s and msr_s macros work with LTO
Alex Matveev [Tue, 14 Nov 2017 23:06:17 +0000 (15:06 -0800)]
FROMLIST: BACKPORT: arm64: make mrs_s and msr_s macros work with LTO

Clang's integrated assembler does not allow assembly macros defined
in one inline asm block using the .macro directive to be used across
separate asm blocks. LLVM developers consider this a feature and not a
bug, recommending code refactoring:

  https://bugs.llvm.org/show_bug.cgi?id=19749

As binutils doesn't allow macros to be redefined, this change uses
UNDEFINE_MRS_S and UNDEFINE_MSR_S to define corresponding macros
in-place and workaround gcc and clang limitations on redefining macros
across different assembler blocks.

Bug: 62093296
Bug: 67506682
Change-Id: I803fff57f639b0921ef81f90ec4befe802e7eecf
(am from https://patchwork.kernel.org/patch/10060343/)
Signed-off-by: Alex Matveev <alxmtvv@gmail.com>
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Subhajeet Muhuri <kenny3fcb@gmail.com>
4 years agoarm64: sysreg: Fix use of XZR in write_sysreg_s
Will Deacon [Mon, 17 Oct 2016 12:38:14 +0000 (13:38 +0100)]
arm64: sysreg: Fix use of XZR in write_sysreg_s

Commit 8a71f0c656e0 ("arm64: sysreg: replace open-coded mrs_s/msr_s with
{read,write}_sysreg_s") introduced a write_sysreg_s macro for writing
to system registers that are not supported by binutils.

Unfortunately, this was implemented with the wrong template (%0 vs %x0),
so in the case that we are writing a constant 0, we will generate
invalid instruction syntax and bail with a cryptic assembler error:

  | Error: constant expression required

This patch fixes the template.

Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
4 years agoarm64: sysreg: replace open-coded mrs_s/msr_s with {read,write}_sysreg_s
Will Deacon [Tue, 6 Sep 2016 13:04:45 +0000 (14:04 +0100)]
arm64: sysreg: replace open-coded mrs_s/msr_s with {read,write}_sysreg_s

Similar to our {read,write}_sysreg accessors for architected, named
system registers, this patch introduces {read,write}_sysreg_s variants
that can take arbitrary sys_reg output and therefore access IMPDEF
registers or registers that unsupported by binutils.

Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: kdrag0n <dragon@khronodragon.com>
Signed-off-by: celtare21 <celtare21@gmail.com>
4 years agoinit: ensure initcall ordering with LTO
Sami Tolvanen [Fri, 8 Dec 2017 23:49:24 +0000 (15:49 -0800)]
init: ensure initcall ordering with LTO

With LTO, the compiler doesn't necessarily obey link order for
initcalls, and the initcall variable needs to be globally unique
to avoid naming collisions.

In order to preserve the correct order, we add each variable
into its own section and generate a linker script (in
scripts/link-vmlinux.sh) to ensure the order remains correct.  We
also add a __COUNTER__ prefix to the name, so we can retain the
order of initcalls within each compilation unit, and __LINE__ to
make the names more unique.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
[wight554: backport to 4.4]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agoFROMLIST: efi/libstub: disable LTO
Sami Tolvanen [Mon, 1 May 2017 18:08:05 +0000 (11:08 -0700)]
FROMLIST: efi/libstub: disable LTO

With CONFIG_LTO_CLANG, we produce LLVM IR instead of object files. Since LTO
is not really needed here and the Makefile assumes we produce an object file,
disable LTO for libstub.

Bug: 62093296
Bug: 67506682
Change-Id: Ieaa3d7e2c694655788f480f4351bf7c4d3fce090
(am from https://patchwork.kernel.org/patch/10060309/)
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoFROMLIST: scripts/mod: disable LTO for empty.c
Sami Tolvanen [Mon, 10 Apr 2017 19:32:24 +0000 (12:32 -0700)]
FROMLIST: scripts/mod: disable LTO for empty.c

With CONFIG_LTO_CLANG, clang generates LLVM IR instead of ELF object
files. As empty.o is used for probing target properties, disable LTO
for it to produce an object file instead.

Bug: 62093296
Bug: 67506682
Change-Id: I0c7ac7ee0134465cac4a8c3a9c7e8b6347076a2b
(am from https://patchwork.kernel.org/patch/10060317/)
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoANDROID: kbuild: disable LTO_CLANG with KASAN
Sami Tolvanen [Fri, 14 Sep 2018 16:17:55 +0000 (09:17 -0700)]
ANDROID: kbuild: disable LTO_CLANG with KASAN

Using LTO with KASAN currently results in "inlinable function call
in a function with debug info must have a !dbg location" errors for
memset and several of the __asan_report_* functions.

As combining these options doesn't provide significant benefits,
this change disables LTO_CLANG when KASAN is selected.

Bug: 113246877
Change-Id: I06cd27d1e9ab74627de4771548453abe3593fcb5
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoFROMLIST: BACKPORT: kbuild: fix dynamic ftrace with clang LTO
Sami Tolvanen [Fri, 16 Jun 2017 19:52:57 +0000 (12:52 -0700)]
FROMLIST: BACKPORT: kbuild: fix dynamic ftrace with clang LTO

With CONFIG_LTO_CLANG enabled, LLVM IR won't be compiled into object
files until modpost_link. This change postpones calls to recordmcount
until after this step.

In order to exclude ftrace_process_locs from inspection, we add a new
code section .text..ftrace, which we tell recordmcount to ignore, and
a __norecordmcount attribute for moving functions to this section.

Bug: 62093296
Bug: 67506682
Change-Id: Iba2c053968206acf533fadab1eb34a743b5088ee
(am from https://patchwork.kernel.org/patch/10060327/)
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoANDROID: kbuild: add support for clang LTO
Sami Tolvanen [Tue, 28 Nov 2017 16:48:49 +0000 (08:48 -0800)]
ANDROID: kbuild: add support for clang LTO

This change adds the configuration option CONFIG_LTO_CLANG, and
build system support for clang's Link Time Optimization (LTO). In
preparation for LTO support for other compilers, potentially common
parts of the changes are gated behind CONFIG_LTO instead.

With -flto, instead of object files, clang produces LLVM bitcode,
which is compiled into a native object at link time, allowing the
final binary to be optimized globally. For more details, see:

  https://llvm.org/docs/LinkTimeOptimization.html

While the kernel normally uses GNU ld for linking, LLVM supports LTO
only with lld or GNU gold linkers. This patch set assumes lld will
be used.

Bug: 62093296
Bug: 67506682
Bug: 133186739
Change-Id: Ibcd9fc7ec501b4f30b43b4877897615645f8655f
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
[kenny3fcb: Add LLD linking support from commit: https://github.com/kdrag0n/proton_bluecross/commit/aba52591410b75e6d21df015d1c3ebba051677e3,
substitute CC_IS_CLANG with clang-ifversion check taken from kernel 4.9 version of this commit,
add ld-name macro from https://github.com/aosp-mirror/kernel_common/commit/552777bdc1d775bee1ffde43c23ab0b2c4501f35, replace gold with lld referring the above kdrag0n's commit,
substitute LD_IS_LLD with ld-name check,
add back lto-flags check from kernel 4.9 version of this commit]
Signed-off-by: Subhajeet Muhuri <kenny3fcb@gmail.com>
[wight554: add ThinLTO support from upstream version of commit,
check for clang 8.0 instead of 5.0 for LD=ld.lld compatibility]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agokbuild: clean up link rule of composite modules
Masahiro Yamada [Mon, 19 Mar 2018 11:26:13 +0000 (20:26 +0900)]
kbuild: clean up link rule of composite modules

cmd_link_multi-link is used only for cmd_link_multi-m.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: improve linker compatibility with lib-ksyms.o build
Nicholas Piggin [Wed, 23 Nov 2016 16:41:40 +0000 (03:41 +1100)]
kbuild: improve linker compatibility with lib-ksyms.o build

lib-ksyms.o is created by linking an empty input file with a linker
script containing the interesting bits. Currently the empty input file
is an archive containing nothing, however this causes the gold linker
to segfault.

I have opened a bug against gold

  https://sourceware.org/bugzilla/show_bug.cgi?id=20767

However this can be worked around by assembling an empty file to link
with instead. The resulting lib-ksyms.o is slightly larger (seemingly
due to empty .text, .data, .bss setions added), but final linked
output should not be changed.

Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years agokbuild: remove CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
Masahiro Yamada [Wed, 9 May 2018 07:23:50 +0000 (16:23 +0900)]
kbuild: remove CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX

CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX was selected by BLACKFIN, METAG.
They were removed by commit 4ba66a976072 ("arch: remove blackfin port"),
commit bb6fb6dfcc17 ("metag: Remove arch/metag/"), respectively.

No more architecture enables CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX.
Clean up the rest of scripts, and remove the Kconfig entry.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
4 years agokbuild: cmd_export_list: tighten the sed script
Nicolas Pitre [Thu, 17 Nov 2016 00:28:39 +0000 (19:28 -0500)]
kbuild: cmd_export_list: tighten the sed script

When LTO is used, some ___ksymtab_string sections are seen by this sed
script, creating lines containing a single ) such as:

EXPORT(foo)
)
)
EXPORT(bar)

Let's make it so the + character is also required for any line to be
printed.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years ago{chiron,sagit}_defconfig: Enable CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
Subhajeet Muhuri [Mon, 17 Dec 2018 07:54:46 +0000 (13:24 +0530)]
{chiron,sagit}_defconfig: Enable CONFIG_LD_DEAD_CODE_DATA_ELIMINATION

Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agokbuild: reword help of LD_DEAD_CODE_DATA_ELIMINATION
Masahiro Yamada [Sat, 23 Jun 2018 16:41:51 +0000 (01:41 +0900)]
kbuild: reword help of LD_DEAD_CODE_DATA_ELIMINATION

Since commit 5d20ee3192a5 ("kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION
to be selectable if enabled"), HAVE_LD_DEAD_CODE_DATA_ELIMINATION is
supposed to be selected by architectures that are capable of this
functionality.  LD_DEAD_CODE_DATA_ELIMINATION is now users' selection.
Update the help message.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agoarm64: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected
Subhajeet Muhuri [Mon, 17 Dec 2018 07:50:22 +0000 (13:20 +0530)]
arm64: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Referring: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4c1d9bb0b5d3c0b3468ac8e68a05972eb957630f

After enabling LD_DEAD_CODE_DATA_ELIMINATION from defconfig,
resulting kernel is almost 200kB smaller

Before LD_DEAD_CODE_DATA_ELIMINATION:

   text    data     bss     dec     hex filename
18067341 7279769 3927748 29274858 1beb2ea vmlinux
22190806 2251638 3927748 28370192 1b0e510 vmlinux.o

After LD_DEAD_CODE_DATA_ELIMINATION:

   text    data     bss     dec     hex filename
17690697 7189217 3900064 28779978 1b725ca vmlinux
22176305 2245781 3920524 28342610 1b07952 vmlinux.o

Signed-off-by: Subhajeet Muhuri <kenny3fcb@gmail.com>
4 years agokbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if enabled
Nicholas Piggin [Wed, 9 May 2018 13:00:00 +0000 (23:00 +1000)]
kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if enabled

Architectures that are capable can select
HAVE_LD_DEAD_CODE_DATA_ELIMINATION to enable selection of that
option (as an EXPERT kernel option).

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: LD_DEAD_CODE_DATA_ELIMINATION no -ffunction-sections/-fdata-sections for...
Nicholas Piggin [Wed, 9 May 2018 12:59:59 +0000 (22:59 +1000)]
kbuild: LD_DEAD_CODE_DATA_ELIMINATION no -ffunction-sections/-fdata-sections for module build

Modules do not tend to cope with -ffunction-sections, even though they
do not link with -gc-sections. It may be possible for unused symbols to
be trimmed from modules, but in general that would take much more work
in architecture module linker scripts.

For now, enable these only for kernel build.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: Fix asm-generic/vmlinux.lds.h for LD_DEAD_CODE_DATA_ELIMINATION
Nicholas Piggin [Wed, 9 May 2018 12:59:58 +0000 (22:59 +1000)]
kbuild: Fix asm-generic/vmlinux.lds.h for LD_DEAD_CODE_DATA_ELIMINATION

KEEP more tables, and add the function/data section wildcard to more
section selections.

This is a little ad-hoc at the moment, but kernel code should be moved
to consistently use .text..x (note: double dots) for explicit sections
and all references to it in the linker script can be made with
TEXT_MAIN, and similarly for other sections.

For now, let's see if major architectures move to enabling this option
then we can do some refactoring passes. Otherwise if it remains unused
or superseded by LTO, this may not be required.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agoFROMLIST: BACKPORT: arm64: keep .altinstructions and .altinstr_replacement
Sami Tolvanen [Tue, 10 Oct 2017 17:56:17 +0000 (10:56 -0700)]
FROMLIST: BACKPORT: arm64: keep .altinstructions and .altinstr_replacement

Make sure the linker doesn't remove .altinstructions or
.altinstr_replacement when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is
enabled.

Bug: 62093296
Bug: 67506682
Change-Id: I73f8a96679083909ec6865ee87519163ac7dcbe3
(am from https://patchwork.kernel.org/patch/10085799/)
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoarm64: fix LD_DEAD_CODE_DATA_ELIMINATION
Sami Tolvanen [Tue, 13 Feb 2018 22:00:14 +0000 (14:00 -0800)]
arm64: fix LD_DEAD_CODE_DATA_ELIMINATION

Keep .entry.tramp.text to avoid the "Entry trampoline text too big"
error while linking.

Bug: 62093296
Bug: 67506682
Change-Id: Idab3216244bd2f8537bb2a5bb47e25e8588394da
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agoFROMLIST: kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION
Sami Tolvanen [Tue, 10 Oct 2017 17:58:53 +0000 (10:58 -0700)]
FROMLIST: kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION

Don't remove .head.text or .exitcall.exit when linking with --gc-sections,
and include .init.text.* in .init.text and .init.rodata.* in .init.rodata.

Bug: 62093296
Bug: 67506682
Change-Id: Ia0f9e735d04c2322dcc8bcfc94241f0551b149c4
(am from https://patchwork.kernel.org/patch/10085773/)
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
4 years agokbuild: linker script do not match C names unless LD_DEAD_CODE_DATA_ELIMINATION is...
Nicholas Piggin [Wed, 26 Jul 2017 12:46:27 +0000 (22:46 +1000)]
kbuild: linker script do not match C names unless LD_DEAD_CODE_DATA_ELIMINATION is configured

The .data and .bss sections were modified in the generic linker script to
pull in sections named .data.<C identifier>, which are generated by gcc with
-ffunction-sections and -fdata-sections options.

The problem with this pattern is it can also match section names that Linux
defines explicitly, e.g., .data.unlikely. This can cause Linux sections to
get moved into the wrong place.

The way to avoid this is to use ".." separators for explicit section names
(the dot character is valid in a section name but not a C identifier).
However currently there are sections which don't follow this rule, so for
now just disable the wild card by default.

Example: http://marc.info/?l=linux-arm-kernel&m=150106824024221&w=2

Cc: <stable@vger.kernel.org> # 4.9
Fixes: b67067f1176df ("kbuild: allow archs to select link dead code/data elimination")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: keep data tables through dead code elimination
Nicholas Piggin [Wed, 23 Nov 2016 16:41:41 +0000 (03:41 +1100)]
kbuild: keep data tables through dead code elimination

When CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled we must ensure
that we still keep various programatically-accessed tables.

[npiggin: Fold Paul's patches into one, and add a few more tables.
 diff symbol tables of allyesconfig with/without -gc-sections shows up
 lost tables quite easily.]

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years agokbuild: avoid conflict between -ffunction-sections and -pg on gcc-4.7
Masahiro Yamada [Fri, 14 Apr 2017 06:17:26 +0000 (15:17 +0900)]
kbuild: avoid conflict between -ffunction-sections and -pg on gcc-4.7

Arnd Bergmann reported:
  "When ftrace is enabled and we build with gcc-4.7 or older, we
  get a warning for each file on architectures that select
  CONFIG_LD_DEAD_CODE_DATA_ELIMINATION:

  warning: -ffunction-sections disabled; it makes profiling impossible [enabled by default]
  "

Since commit c3f0d0bc5b01 ("kbuild, LLVMLinux: Add -Werror to
cc-option to support clang"), warnings are treated as errors in
cc-option checks.  CC_FLAGS_FTRACE is blindly added to KBUILD_CFLAGS,
so $(call cc-option,-ffunction-sections,) should be moved below it
in order to detect the conflict between the two options.

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: -ffunction-sections fix for archs with conflicting sections
Nicholas Piggin [Wed, 14 Sep 2016 02:24:03 +0000 (12:24 +1000)]
kbuild: -ffunction-sections fix for archs with conflicting sections

Enabling -ffunction-sections modified the generic linker script to
pull .text.* sections into regular TEXT_TEXT section, conflicting
with some architectures. Revert that change and require archs that
enable the option to ensure they have no conflicting section names,
and do the appropriate merging.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Fixes: b67067f1176d ("kbuild: allow archs to select link dead code/data elimination")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years agokbuild: allow archs to select link dead code/data elimination
Nicholas Piggin [Wed, 24 Aug 2016 12:29:20 +0000 (22:29 +1000)]
kbuild: allow archs to select link dead code/data elimination

Introduce LD_DEAD_CODE_DATA_ELIMINATION option for architectures to
select to build with -ffunction-sections, -fdata-sections, and link
with --gc-sections. It requires some work (documented) to ensure all
unreferenced entrypoints are live, and requires toolchain and build
verification, so it is made a per-arch option for now.

On a random powerpc64le build, this yelds a significant size saving,
it boots and runs fine, but there is a lot I haven't tested as yet, so
these savings may be reduced if there are bugs in the link.

    text      data        bss        dec   filename
11169741   1180744    1923176 14273661   vmlinux
10445269   1004127    1919707 13369103   vmlinux.dce

~700K text, ~170K data, 6% removed from kernel image size.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
Signed-off-by: Subhajeet Muhuri <kenny3fcb@gmail.com>
4 years agokbuild: clean up archive rule of built-in.a
Masahiro Yamada [Mon, 19 Mar 2018 11:26:12 +0000 (20:26 +0900)]
kbuild: clean up archive rule of built-in.a

With the incremental linking entirely dropped, we can simplify
the Makefile.

While I am here, I renamed cmd_link_o_target to cmd_ar_builtin.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: remove partial section mismatch detection for built-in.a
Masahiro Yamada [Mon, 19 Mar 2018 11:26:11 +0000 (20:26 +0900)]
kbuild: remove partial section mismatch detection for built-in.a

When built-in.o was incrementally linked with 'ld -r', the section
mismatch analysis for the individual built-in.o was possible when
CONFIG_DEBUG_SECTION_MISMATCH was enabled.

With the migration to the thin archive, built-in.a (former, built-in.o)
is no longer an ELF file.  So, the modpost does nothing useful.
scripts/mod/modpost.c just checks the header to bail out, as follows:

        /* Is this a valid ELF file? */
        if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
            (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
            (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
            (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
                /* Not an ELF file - silently ignore it */
                return 0;
        }

We have the full analysis in the final link stage anyway, so we would
not miss the section mismatching.

I do not see a good reason to require extra linking only for the
purpose of the per-directory analysis.  Just get rid of this part.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: link $(real-obj-y) instead of $(obj-y) into built-in.a
Masahiro Yamada [Mon, 19 Mar 2018 11:26:08 +0000 (20:26 +0900)]
kbuild: link $(real-obj-y) instead of $(obj-y) into built-in.a

In Kbuild, Makefiles can add the same object to obj-y multiple
times.  So,

   obj-y += foo.o
   obj-y += foo.o

is fine.

However, this is not true when the same object is added multiple
times via composite objects.  For example,

   obj-y    += foo.o bar.o
   foo-objs := foo-bar-common.o foo-only.o
   bar-objs := foo-bar-common.o bar-only.o

causes build error because two instances of foo-bar-common.o are
linked into the vmlinux.

Makefiles tend to invent ugly work-around, for example
  - lib/zstd/Makefile
  - drivers/net/ethernet/cavium/liquidio/Makefile

The technique used in Kbuild to avoid the multiple definition error
is to use $(filter $(obj-y), $^).  Here, $^ lists the names of all
the prerequisites with duplicated names removed.

By replacing it with $(filter $(real-obj-y), $^) we can do likewise
for composite objects.  For built-in objects, we do not need to keep
the composite object structure.  We can simply expand them, and link
$(real-obj-y) to built-in.a.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years ago[kbuild] handle exports in lib-y objects reliably
Al Viro [Fri, 15 Jan 2016 19:01:22 +0000 (14:01 -0500)]
[kbuild] handle exports in lib-y objects reliably

Collect the symbols exported by anything that goes into lib.a and
add an empty object (lib-exports.o) with explicit undefs for each
of those to obj-y.

That allows to relax the rules regarding the use of exports in
lib-* objects - right now an object with export can be in lib-*
only if we are guaranteed that there always will be users in
built-in parts of the tree, otherwise it needs to be in obj-*.
As the result, we have an unholy mix of lib- and obj- in lib/Makefile
and (especially) in arch/*/lib/Makefile.  Moreover, a change in
generic part of the kernel can lead to mysteriously missing exports
on some configs.  With this change we don't have to worry about
that anymore.

One side effect is that built-in.o now pulls everything with exports
from the corresponding lib.a (if such exists).  That's exactly what
we want for linking vmlinux and fortunately it's almost the only thing
built-in.o is used in.  arch/ia64/hp/sim/boot/bootloader is the only
exception and it's easy to get rid of now - just turn everything in
arch/ia64/lib into lib-* and don't bother with arch/ia64/lib/built-in.o
anymore.

[AV: stylistic fix from Michal folded in]

Acked-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
4 years agokbuild: rename real-objs-y/m to real-obj-y/m
Masahiro Yamada [Mon, 19 Mar 2018 11:26:07 +0000 (20:26 +0900)]
kbuild: rename real-objs-y/m to real-obj-y/m

When I was refactoring Makefiles, I stupidly mistook 'real-obj-y' for
'real-objs-y' over and over again.  Finally, I decide to rename it to
'real-obj-y'.  This is consistent with 'obj-y', 'subdir-obj-y'.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: drop $(extra-y) from real-objs-y
Masahiro Yamada [Thu, 23 Nov 2017 14:25:26 +0000 (23:25 +0900)]
kbuild: drop $(extra-y) from real-objs-y

$(real-objs-y) in only used in scripts/Makefile.build to form
"targets", but $(extra-y) is added to "targets" in another line.
We do not need to add $(extra-y) twice.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: Allow to specify composite modules with modname-m
Michal Marek [Tue, 27 Oct 2015 13:02:24 +0000 (14:02 +0100)]
kbuild: Allow to specify composite modules with modname-m

This allows to write

  drm-$(CONFIG_AGP) += drm_agpsupport.o

without having to handle CONFIG_AGP=y vs. CONFIG_AGP=m. Only support
this syntax for modules, since built-in code depending on something
modular cannot work and init/Makefile actually relies on the current
semantics. There are a few drivers which adapted to the current
semantics out of necessity; these are fixed to also work when the
respective subsystem is modular.

Acked-by: Peter Chen <peter.chen@freescale.com> [chipidea]
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years agokbuild: create built-in.o automatically if parent directory wants it
Masahiro Yamada [Tue, 7 Nov 2017 16:31:46 +0000 (01:31 +0900)]
kbuild: create built-in.o automatically if parent directory wants it

"obj-y += foo/" syntax requires Kbuild to visit the "foo" subdirectory
and link built-in.o from that directory.  This means foo/Makefile is
responsible for creating built-in.o even if there is no object to
link (in this case, built-in.o is an empty archive).

We have had several fixups like commit 4b024242e8a4 ("kbuild: Fix
linking error built-in.o no such file or directory"), then ended up
with a complex condition as follows:

  ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),)
  builtin-target := $(obj)/built-in.o
  endif

We still have more cases not covered by the above, so we need to add
  obj- := dummy.o
in several places just for creating empty built-in.o.

A key point is, the parent Makefile knows whether built-in.o is needed
or not.  If a subdirectory needs to create built-in.o, its parent can
tell the fact when descending.

If non-empty $(need-builtin) flag is passed from the parent, built-in.o
should be created.  $(obj-y) should be still checked to support the
single target "%/".  All of ugly tricks will go away.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
4 years agokbuild: rename built-in.o to built-in.a
Nicholas Piggin [Sat, 10 Feb 2018 14:25:04 +0000 (00:25 +1000)]
kbuild: rename built-in.o to built-in.a

Incremental linking is gone, so rename built-in.o to built-in.a, which
is the usual extension for archive files.

This patch does two things, first is a simple search/replace:

git grep -l 'built-in\.o' | xargs sed -i 's/built-in\.o/built-in\.a/g'

The second is to invert nesting of nested text manipulations to avoid
filtering built-in.a out from libs-y2:

-libs-y2 := $(filter-out %.a, $(patsubst %/, %/built-in.a, $(libs-y)))
+libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y)))

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: remove incremental linking option
Nicholas Piggin [Sat, 10 Feb 2018 14:25:03 +0000 (00:25 +1000)]
kbuild: remove incremental linking option

This removes the old `ld -r` incremental link option, which has not
been selected by any architecture since June 2017.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: handle libs-y archives separately from built-in.o archives
Nicholas Piggin [Mon, 19 Jun 2017 15:52:05 +0000 (01:52 +1000)]
kbuild: handle libs-y archives separately from built-in.o archives

The thin archives build currently puts all lib.a and built-in.o
files together and links them with --whole-archive.

This works because thin archives can recursively refer to thin
archives. However some architectures include libgcc.a, which may
not be a thin archive, or it may not be constructed with the "P"
option, in which case its contents do not get linked correctly.

So don't pull .a libs into the root built-in.o archive. These
libs should already have symbol tables and indexes built, so they
can be direct linker inputs. Move them out of the --whole-archive
option, which restore the conditional linking behaviour of lib.a
to thin archives builds.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: thin archives make default for all archs
Nicholas Piggin [Fri, 9 Jun 2017 05:24:17 +0000 (15:24 +1000)]
kbuild: thin archives make default for all archs

Make thin archives build the default, but keep the config option
to allow exemptions if any breakage can't be quickly solved.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Subhajeet Muhuri <kenny3fcb@gmail.com>
4 years agokbuild: thin archives use P option to ar
Nicholas Piggin [Fri, 9 Jun 2017 05:24:14 +0000 (15:24 +1000)]
kbuild: thin archives use P option to ar

The P option makes ar do full path name matching and can prevent ar
from discarding files with duplicate names in some cases of creating
thin archives from thin archives. The sh architecture in particular
loses some object files from its kernel/cpu/sh*/ directories without
this option.

This could be a bug in binutils ar, but the P option should not cause
any negative effects so it is safe to use to work around this with.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: thin archives for multi-y targets
Nicholas Piggin [Wed, 23 Nov 2016 16:41:38 +0000 (03:41 +1100)]
kbuild: thin archives for multi-y targets

THIN_ARCHIVES builds archives for built-in.o targets, have it build
multi-y targets as archives as well.

This saves another ~15% of the size of intermediate artifacts in the
build tree. After this patch, the linker is only used in final link,
and special cases like vdsos.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years agokbuild: thin archives final link close --whole-archives option
Nicholas Piggin [Fri, 9 Jun 2017 05:24:13 +0000 (15:24 +1000)]
kbuild: thin archives final link close --whole-archives option

Close the --whole-archives option with --no-whole-archive. Some
architectures end up including additional .o and files multiple
times after this, and they get duplicate symbols when they are
brought under the --whole-archives option.

This matches more closely with the incremental final link.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
4 years agokbuild: minor improvement for thin archives build
Nicholas Piggin [Wed, 23 Nov 2016 16:41:43 +0000 (03:41 +1100)]
kbuild: minor improvement for thin archives build

The root built-in.o archive is currently generated before all object
files are built for the final link, due to final build of init/ after
version update. In practice it seems like it doesn't matter because
the archive symbol table does not change, but it is more logical to
create the final archive as the last step.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years agokbuild: allow architectures to use thin archives instead of ld -r
Stephen Rothwell [Wed, 24 Aug 2016 12:29:19 +0000 (22:29 +1000)]
kbuild: allow architectures to use thin archives instead of ld -r

ld -r is an incremental link used to create built-in.o files in build
subdirectories. It produces relocatable object files containing all
its input files, and these are are then pulled together and relocated
in the final link. Aside from the bloat, this constrains the final
link relocations, which has bitten large powerpc builds with
unresolvable relocations in the final link.

Alan Modra has recommended the kernel use thin archives for linking.
This is an alternative and means that the linker has more information
available to it when it links the kernel.

This patch enables a config option architectures can select, which
causes all built-in.o files to be built as thin archives. built-in.o
files in subdirectories do not get symbol table or index attached,
which improves speed and size. The final link pass creates a
built-in.o archive in the root output directory which includes the
symbol table and index. The linker then uses takes this file to link.

The --whole-archive linker option is required, because the linker now
has visibility to every individual object file, and it will otherwise
just completely avoid including those without external references
(consider a file with EXPORT_SYMBOL or initcall or hardware exceptions
as its only entry points). The traditional built works "by luck" as
built-in.o files are large enough that they're going to get external
references. However this optimisation is unpredictable for the kernel
(due to above external references), ineffective at culling unused, and
costly because the .o files have to be searched for references.
Superior alternatives for link-time culling should be used instead.

Build characteristics for inclink vs thinarc, on a small powerpc64le
pseries VM with a modest .config:

                                  inclink       thinarc
sizes
vmlinux                        15 618 680    15 625 028
sum of all built-in.o          56 091 808     1 054 334
sum excluding root built-in.o                   151 430

find -name built-in.o | xargs rm ; time make vmlinux
real                              22.772s       21.143s
user                              13.280s       13.430s
sys                                4.310s        2.750s

- Final kernel pulled in only about 6K more, which shows how
  ineffective the object file culling is.
- Build performance looks improved due to less pagecache activity.
  On IO constrained systems it could be a bigger win.
- Build size saving is significant.

Side note, the toochain understands archives, so there's some tricks,
$ ar t built-in.o          # list all files you linked with
$ size built-in.o          # and their sizes
$ objdump -d built-in.o    # disassembly (unrelocated) with filenames

Implementation by sfr, minor tweaks by npiggin.

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
4 years agomsm: mdss: dsi: Fix missing display state api for maple
0ranko0P [Mon, 28 Oct 2019 16:02:02 +0000 (00:02 +0800)]
msm: mdss: dsi: Fix missing display state api for maple

4 years agoblock: Add Maple IO scheduler
0ranko0P [Mon, 28 Oct 2019 15:32:52 +0000 (23:32 +0800)]
block: Add Maple IO scheduler

4 years agoblock: Add Zen IO scheduler
0ranko0P [Mon, 28 Oct 2019 15:12:21 +0000 (23:12 +0800)]
block: Add Zen IO scheduler

4 years agomsm: qpnp-haptic: Fix missing cmhw implementation after merge xiaomi
0ranko0P [Mon, 28 Oct 2019 11:39:40 +0000 (19:39 +0800)]
msm: qpnp-haptic: Fix missing cmhw implementation after merge xiaomi
changes

4 years agoqpnp-haptic: expose vibrate function
flar2 [Wed, 14 Jun 2017 02:14:35 +0000 (22:14 -0400)]
qpnp-haptic: expose vibrate function

Change-Id: I91604f6b946940c7a2681720c683010538b222e8
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
4 years agotreewide: Kill more warnings about debugfs failure if disabled
Volodymyr Zhdanov [Tue, 2 Jul 2019 10:30:43 +0000 (13:30 +0300)]
treewide: Kill more warnings about debugfs failure if disabled

4 years agotreewide: Don't warn about debugfs failure if disabled
0ctobot [Sun, 16 Jun 2019 20:08:51 +0000 (16:08 -0400)]
treewide: Don't warn about debugfs failure if disabled

Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
[wight554: backport to 4.4]
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agowakeup: Enable debugfs usage for Android even when debugfs is disabled
Sultan Alsawaf [Sat, 20 Jul 2019 17:10:24 +0000 (10:10 -0700)]
wakeup: Enable debugfs usage for Android even when debugfs is disabled

Android userspace needs this driver's debugfs entry, so enable it.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
4 years agomsm: vidc: Fix broken debugfs creation error checks and error paths
Sultan Alsawaf [Fri, 1 Jun 2018 00:03:33 +0000 (17:03 -0700)]
msm: vidc: Fix broken debugfs creation error checks and error paths

The debugfs helper functions do not always return NULL when they fail;
instead, they can return an error number casted as a pointer, so that their
users have the option to determine the exact cause of failure.

Use the IS_ERR_OR_NULL() helper when checking for debugfs errors to fix the
error checks.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Volodymyr Zhdanov <wight554@gmail.com>
4 years agodefconfig: Disable profiling subsystem
Julian Liu [Fri, 16 Aug 2019 09:28:41 +0000 (17:28 +0800)]
defconfig: Disable profiling subsystem

4 years agodefconfig: Enable IP_NF_TARGET_TTL
Julian Liu [Tue, 3 Sep 2019 02:55:58 +0000 (10:55 +0800)]
defconfig: Enable IP_NF_TARGET_TTL

* regen

4 years agoscripts: Don't append "+" to localversion
Sultan Alsawaf [Mon, 14 May 2018 05:35:12 +0000 (22:35 -0700)]
scripts: Don't append "+" to localversion

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>