From d61df691370488306c8f2661180c48ccaf6d45b4 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 20 Feb 2022 18:55:46 -0500 Subject: [PATCH] Fixes for 5.16 Signed-off-by: Sasha Levin --- ...-fix-memory-leak-in-vmbus_add_channe.patch | 57 ++++++++ ...hid-elo-fix-memory-leak-in-elo_probe.patch | 38 +++++ ...t-truncate-the-perfevtseln-msr-when-.patch | 52 +++++++ ...ctoring-find_arch_event-to-pmc_perf_.patch | 131 ++++++++++++++++++ ...amd64_raw_event_mask-for-perf_type_r.patch | 39 ++++++ ...nic-fix-missing-put_device-in-ingeni.patch | 46 ++++++ queue-5.16/series | 6 + 7 files changed, 369 insertions(+) create mode 100644 queue-5.16/drivers-hv-vmbus-fix-memory-leak-in-vmbus_add_channe.patch create mode 100644 queue-5.16/hid-elo-fix-memory-leak-in-elo_probe.patch create mode 100644 queue-5.16/kvm-x86-pmu-don-t-truncate-the-perfevtseln-msr-when-.patch create mode 100644 queue-5.16/kvm-x86-pmu-refactoring-find_arch_event-to-pmc_perf_.patch create mode 100644 queue-5.16/kvm-x86-pmu-use-amd64_raw_event_mask-for-perf_type_r.patch create mode 100644 queue-5.16/mtd-rawnand-ingenic-fix-missing-put_device-in-ingeni.patch diff --git a/queue-5.16/drivers-hv-vmbus-fix-memory-leak-in-vmbus_add_channe.patch b/queue-5.16/drivers-hv-vmbus-fix-memory-leak-in-vmbus_add_channe.patch new file mode 100644 index 00000000000..a558ed31130 --- /dev/null +++ b/queue-5.16/drivers-hv-vmbus-fix-memory-leak-in-vmbus_add_channe.patch @@ -0,0 +1,57 @@ +From eda10af7cff1737043b6d8bbc6ebba886acf4316 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 4 Feb 2022 01:30:08 +0800 +Subject: Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Miaoqian Lin + +[ Upstream commit 8bc69f86328e87a0ffa79438430cc82f3aa6a194 ] + +kobject_init_and_add() takes reference even when it fails. +According to the doc of kobject_init_and_add(): + + If this function returns an error, kobject_put() must be called to + properly clean up the memory associated with the object. + +Fix memory leak by calling kobject_put(). + +Fixes: c2e5df616e1a ("vmbus: add per-channel sysfs info") +Signed-off-by: Miaoqian Lin +Reviewed-by: Juan Vazquez +Link: https://lore.kernel.org/r/20220203173008.43480-1-linmq006@gmail.com +Signed-off-by: Wei Liu +Signed-off-by: Sasha Levin +--- + drivers/hv/vmbus_drv.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c +index 392c1ac4f8193..44bd0b6ff5059 100644 +--- a/drivers/hv/vmbus_drv.c ++++ b/drivers/hv/vmbus_drv.c +@@ -2027,8 +2027,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) + kobj->kset = dev->channels_kset; + ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL, + "%u", relid); +- if (ret) ++ if (ret) { ++ kobject_put(kobj); + return ret; ++ } + + ret = sysfs_create_group(kobj, &vmbus_chan_group); + +@@ -2037,6 +2039,7 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) + * The calling functions' error handling paths will cleanup the + * empty channel directory. + */ ++ kobject_put(kobj); + dev_err(device, "Unable to set up channel sysfs files\n"); + return ret; + } +-- +2.34.1 + diff --git a/queue-5.16/hid-elo-fix-memory-leak-in-elo_probe.patch b/queue-5.16/hid-elo-fix-memory-leak-in-elo_probe.patch new file mode 100644 index 00000000000..d3d32d884ee --- /dev/null +++ b/queue-5.16/hid-elo-fix-memory-leak-in-elo_probe.patch @@ -0,0 +1,38 @@ +From 659ef7c6a717ac0af3e19ede49282c821b90ffa3 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 22 Jan 2022 17:48:26 +0800 +Subject: HID: elo: fix memory leak in elo_probe + +From: Dongliang Mu + +[ Upstream commit 817b8b9c5396d2b2d92311b46719aad5d3339dbe ] + +When hid_parse() in elo_probe() fails, it forgets to call usb_put_dev to +decrease the refcount. + +Fix this by adding usb_put_dev() in the error handling code of elo_probe(). + +Fixes: fbf42729d0e9 ("HID: elo: update the reference count of the usb device structure") +Reported-by: syzkaller +Signed-off-by: Dongliang Mu +Signed-off-by: Jiri Kosina +Signed-off-by: Sasha Levin +--- + drivers/hid/hid-elo.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/drivers/hid/hid-elo.c b/drivers/hid/hid-elo.c +index 8e960d7b233b3..9b42b0cdeef06 100644 +--- a/drivers/hid/hid-elo.c ++++ b/drivers/hid/hid-elo.c +@@ -262,6 +262,7 @@ static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id) + + return 0; + err_free: ++ usb_put_dev(udev); + kfree(priv); + return ret; + } +-- +2.34.1 + diff --git a/queue-5.16/kvm-x86-pmu-don-t-truncate-the-perfevtseln-msr-when-.patch b/queue-5.16/kvm-x86-pmu-don-t-truncate-the-perfevtseln-msr-when-.patch new file mode 100644 index 00000000000..3a5b62b6db9 --- /dev/null +++ b/queue-5.16/kvm-x86-pmu-don-t-truncate-the-perfevtseln-msr-when-.patch @@ -0,0 +1,52 @@ +From 50d24326c9d0811af198b6310a146f454306165d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 2 Feb 2022 17:48:12 -0800 +Subject: KVM: x86/pmu: Don't truncate the PerfEvtSeln MSR when creating a perf + event + +From: Jim Mattson + +[ Upstream commit b8bfee85f1307426e0242d654f3a14c06ef639c5 ] + +AMD's event select is 3 nybbles, with the high nybble in bits 35:32 of +a PerfEvtSeln MSR. Don't drop the high nybble when setting up the +config field of a perf_event_attr structure for a call to +perf_event_create_kernel_counter(). + +Fixes: ca724305a2b0 ("KVM: x86/vPMU: Implement AMD vPMU code for KVM") +Reported-by: Stephane Eranian +Signed-off-by: Jim Mattson +Message-Id: <20220203014813.2130559-1-jmattson@google.com> +Reviewed-by: David Dunn +Signed-off-by: Paolo Bonzini +Signed-off-by: Sasha Levin +--- + arch/x86/kvm/pmu.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c +index 3b3ccf5b11064..944137ed1f901 100644 +--- a/arch/x86/kvm/pmu.c ++++ b/arch/x86/kvm/pmu.c +@@ -95,7 +95,7 @@ static void kvm_perf_overflow_intr(struct perf_event *perf_event, + } + + static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type, +- unsigned config, bool exclude_user, ++ u64 config, bool exclude_user, + bool exclude_kernel, bool intr, + bool in_tx, bool in_tx_cp) + { +@@ -173,7 +173,8 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc) + + void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) + { +- unsigned config, type = PERF_TYPE_RAW; ++ u64 config; ++ u32 type = PERF_TYPE_RAW; + struct kvm *kvm = pmc->vcpu->kvm; + struct kvm_pmu_event_filter *filter; + int i; +-- +2.34.1 + diff --git a/queue-5.16/kvm-x86-pmu-refactoring-find_arch_event-to-pmc_perf_.patch b/queue-5.16/kvm-x86-pmu-refactoring-find_arch_event-to-pmc_perf_.patch new file mode 100644 index 00000000000..29a02aa49df --- /dev/null +++ b/queue-5.16/kvm-x86-pmu-refactoring-find_arch_event-to-pmc_perf_.patch @@ -0,0 +1,131 @@ +From c4d0e7ca507d3065f092bc2721085d65e1ec7c11 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 30 Nov 2021 15:42:17 +0800 +Subject: KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id() + +From: Like Xu + +[ Upstream commit 7c174f305cbee6bdba5018aae02b84369e7ab995 ] + +The find_arch_event() returns a "unsigned int" value, +which is used by the pmc_reprogram_counter() to +program a PERF_TYPE_HARDWARE type perf_event. + +The returned value is actually the kernel defined generic +perf_hw_id, let's rename it to pmc_perf_hw_id() with simpler +incoming parameters for better self-explanation. + +Signed-off-by: Like Xu +Message-Id: <20211130074221.93635-3-likexu@tencent.com> +Signed-off-by: Paolo Bonzini +Signed-off-by: Sasha Levin +--- + arch/x86/kvm/pmu.c | 8 +------- + arch/x86/kvm/pmu.h | 3 +-- + arch/x86/kvm/svm/pmu.c | 8 ++++---- + arch/x86/kvm/vmx/pmu_intel.c | 9 +++++---- + 4 files changed, 11 insertions(+), 17 deletions(-) + +diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c +index 09873f6488f7c..3b3ccf5b11064 100644 +--- a/arch/x86/kvm/pmu.c ++++ b/arch/x86/kvm/pmu.c +@@ -174,7 +174,6 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc) + void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) + { + unsigned config, type = PERF_TYPE_RAW; +- u8 event_select, unit_mask; + struct kvm *kvm = pmc->vcpu->kvm; + struct kvm_pmu_event_filter *filter; + int i; +@@ -206,17 +205,12 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) + if (!allow_event) + return; + +- event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT; +- unit_mask = (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8; +- + if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE | + ARCH_PERFMON_EVENTSEL_INV | + ARCH_PERFMON_EVENTSEL_CMASK | + HSW_IN_TX | + HSW_IN_TX_CHECKPOINTED))) { +- config = kvm_x86_ops.pmu_ops->find_arch_event(pmc_to_pmu(pmc), +- event_select, +- unit_mask); ++ config = kvm_x86_ops.pmu_ops->pmc_perf_hw_id(pmc); + if (config != PERF_COUNT_HW_MAX) + type = PERF_TYPE_HARDWARE; + } +diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h +index 59d6b76203d5b..dd7dbb1c5048d 100644 +--- a/arch/x86/kvm/pmu.h ++++ b/arch/x86/kvm/pmu.h +@@ -24,8 +24,7 @@ struct kvm_event_hw_type_mapping { + }; + + struct kvm_pmu_ops { +- unsigned (*find_arch_event)(struct kvm_pmu *pmu, u8 event_select, +- u8 unit_mask); ++ unsigned int (*pmc_perf_hw_id)(struct kvm_pmc *pmc); + unsigned (*find_fixed_event)(int idx); + bool (*pmc_is_enabled)(struct kvm_pmc *pmc); + struct kvm_pmc *(*pmc_idx_to_pmc)(struct kvm_pmu *pmu, int pmc_idx); +diff --git a/arch/x86/kvm/svm/pmu.c b/arch/x86/kvm/svm/pmu.c +index b4095dfeeee62..7fadfe3c67e73 100644 +--- a/arch/x86/kvm/svm/pmu.c ++++ b/arch/x86/kvm/svm/pmu.c +@@ -134,10 +134,10 @@ static inline struct kvm_pmc *get_gp_pmc_amd(struct kvm_pmu *pmu, u32 msr, + return &pmu->gp_counters[msr_to_index(msr)]; + } + +-static unsigned amd_find_arch_event(struct kvm_pmu *pmu, +- u8 event_select, +- u8 unit_mask) ++static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc) + { ++ u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT; ++ u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8; + int i; + + for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++) +@@ -319,7 +319,7 @@ static void amd_pmu_reset(struct kvm_vcpu *vcpu) + } + + struct kvm_pmu_ops amd_pmu_ops = { +- .find_arch_event = amd_find_arch_event, ++ .pmc_perf_hw_id = amd_pmc_perf_hw_id, + .find_fixed_event = amd_find_fixed_event, + .pmc_is_enabled = amd_pmc_is_enabled, + .pmc_idx_to_pmc = amd_pmc_idx_to_pmc, +diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c +index 1b7456b2177b9..60563a45f3eb8 100644 +--- a/arch/x86/kvm/vmx/pmu_intel.c ++++ b/arch/x86/kvm/vmx/pmu_intel.c +@@ -68,10 +68,11 @@ static void global_ctrl_changed(struct kvm_pmu *pmu, u64 data) + reprogram_counter(pmu, bit); + } + +-static unsigned intel_find_arch_event(struct kvm_pmu *pmu, +- u8 event_select, +- u8 unit_mask) ++static unsigned int intel_pmc_perf_hw_id(struct kvm_pmc *pmc) + { ++ struct kvm_pmu *pmu = pmc_to_pmu(pmc); ++ u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT; ++ u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8; + int i; + + for (i = 0; i < ARRAY_SIZE(intel_arch_events); i++) +@@ -703,7 +704,7 @@ static void intel_pmu_cleanup(struct kvm_vcpu *vcpu) + } + + struct kvm_pmu_ops intel_pmu_ops = { +- .find_arch_event = intel_find_arch_event, ++ .pmc_perf_hw_id = intel_pmc_perf_hw_id, + .find_fixed_event = intel_find_fixed_event, + .pmc_is_enabled = intel_pmc_is_enabled, + .pmc_idx_to_pmc = intel_pmc_idx_to_pmc, +-- +2.34.1 + diff --git a/queue-5.16/kvm-x86-pmu-use-amd64_raw_event_mask-for-perf_type_r.patch b/queue-5.16/kvm-x86-pmu-use-amd64_raw_event_mask-for-perf_type_r.patch new file mode 100644 index 00000000000..9f0a24abbc3 --- /dev/null +++ b/queue-5.16/kvm-x86-pmu-use-amd64_raw_event_mask-for-perf_type_r.patch @@ -0,0 +1,39 @@ +From 1c72f85d072ad001dc60ef991f7b4cf0e3ffba45 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 2 Feb 2022 17:48:13 -0800 +Subject: KVM: x86/pmu: Use AMD64_RAW_EVENT_MASK for PERF_TYPE_RAW + +From: Jim Mattson + +[ Upstream commit 710c476514313c74045c41c0571bb5178fd16e3d ] + +AMD's event select is 3 nybbles, with the high nybble in bits 35:32 of +a PerfEvtSeln MSR. Don't mask off the high nybble when configuring a +RAW perf event. + +Fixes: ca724305a2b0 ("KVM: x86/vPMU: Implement AMD vPMU code for KVM") +Signed-off-by: Jim Mattson +Message-Id: <20220203014813.2130559-2-jmattson@google.com> +Reviewed-by: David Dunn +Signed-off-by: Paolo Bonzini +Signed-off-by: Sasha Levin +--- + arch/x86/kvm/pmu.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c +index 944137ed1f901..de955ca58d17c 100644 +--- a/arch/x86/kvm/pmu.c ++++ b/arch/x86/kvm/pmu.c +@@ -217,7 +217,7 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel) + } + + if (type == PERF_TYPE_RAW) +- config = eventsel & X86_RAW_EVENT_MASK; ++ config = eventsel & AMD64_RAW_EVENT_MASK; + + if (pmc->current_config == eventsel && pmc_resume_counter(pmc)) + return; +-- +2.34.1 + diff --git a/queue-5.16/mtd-rawnand-ingenic-fix-missing-put_device-in-ingeni.patch b/queue-5.16/mtd-rawnand-ingenic-fix-missing-put_device-in-ingeni.patch new file mode 100644 index 00000000000..0a8a6ba4510 --- /dev/null +++ b/queue-5.16/mtd-rawnand-ingenic-fix-missing-put_device-in-ingeni.patch @@ -0,0 +1,46 @@ +From 86b435f74bee28251bff1916233b0aa368e87caa Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 30 Dec 2021 07:27:51 +0000 +Subject: mtd: rawnand: ingenic: Fix missing put_device in ingenic_ecc_get + +From: Miaoqian Lin + +[ Upstream commit ba1b71b008e97fd747845ff3a818420b11bbe830 ] + +If of_find_device_by_node() succeeds, ingenic_ecc_get() doesn't have +a corresponding put_device(). Thus add put_device() to fix the exception +handling. + +Fixes: 15de8c6efd0e ("mtd: rawnand: ingenic: Separate top-level and SoC specific code") +Signed-off-by: Miaoqian Lin +Reviewed-by: Paul Cercueil +Signed-off-by: Miquel Raynal +Link: https://lore.kernel.org/linux-mtd/20211230072751.21622-1-linmq006@gmail.com +Signed-off-by: Sasha Levin +--- + drivers/mtd/nand/raw/ingenic/ingenic_ecc.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c b/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c +index efe0ffe4f1abc..9054559e52dda 100644 +--- a/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c ++++ b/drivers/mtd/nand/raw/ingenic/ingenic_ecc.c +@@ -68,9 +68,14 @@ static struct ingenic_ecc *ingenic_ecc_get(struct device_node *np) + struct ingenic_ecc *ecc; + + pdev = of_find_device_by_node(np); +- if (!pdev || !platform_get_drvdata(pdev)) ++ if (!pdev) + return ERR_PTR(-EPROBE_DEFER); + ++ if (!platform_get_drvdata(pdev)) { ++ put_device(&pdev->dev); ++ return ERR_PTR(-EPROBE_DEFER); ++ } ++ + ecc = platform_get_drvdata(pdev); + clk_prepare_enable(ecc->clk); + +-- +2.34.1 + diff --git a/queue-5.16/series b/queue-5.16/series index 8bf551808e1..36398adc823 100644 --- a/queue-5.16/series +++ b/queue-5.16/series @@ -167,3 +167,9 @@ mtd-parsers-qcom-fix-kernel-panic-on-skipped-partition.patch mtd-parsers-qcom-fix-missing-free-for-pparts-in-cleanup.patch mtd-phram-prevent-divide-by-zero-bug-in-phram_setup.patch mtd-rawnand-brcmnand-fixed-incorrect-sub-page-ecc-status.patch +hid-elo-fix-memory-leak-in-elo_probe.patch +mtd-rawnand-ingenic-fix-missing-put_device-in-ingeni.patch +drivers-hv-vmbus-fix-memory-leak-in-vmbus_add_channe.patch +kvm-x86-pmu-refactoring-find_arch_event-to-pmc_perf_.patch +kvm-x86-pmu-don-t-truncate-the-perfevtseln-msr-when-.patch +kvm-x86-pmu-use-amd64_raw_event_mask-for-perf_type_r.patch -- 2.47.3