From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED2CFC04A68 for ; Wed, 27 Jul 2022 17:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234012AbiG0RDx (ORCPT ); Wed, 27 Jul 2022 13:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237635AbiG0RD0 (ORCPT ); Wed, 27 Jul 2022 13:03:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4001C6D9CF; Wed, 27 Jul 2022 09:38:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 933F9601C0; Wed, 27 Jul 2022 16:38:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EAB1C433C1; Wed, 27 Jul 2022 16:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939920; bh=MwyX3wjA57F6sEfsuEZsMG8VT9p23XwcnOQyULZiTZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JA8psd9P70iAI/vRwFBI2J7CJ12J9ffDgu26C+qTf2WDNQYmXOFQkN6YSAcLPiyY4 FkVYTFeVBgg/emVV3WbqCWDCwcGFPNS0dZzqwXmXRoUMcWM8LqsYVbJ1mSieKNFcmB bwIhOokTh63j3vIh1gn8K6n7fREJwLujh+BDKqlg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fabien Dessenne , Linus Walleij Subject: [PATCH 5.15 001/201] pinctrl: stm32: fix optional IRQ support to gpios Date: Wed, 27 Jul 2022 18:08:25 +0200 Message-Id: <20220727161027.029748200@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Fabien Dessenne commit a1d4ef1adf8bbd302067534ead671a94759687ed upstream. To act as an interrupt controller, a gpio bank relies on the "interrupt-parent" of the pin controller. When this optional "interrupt-parent" misses, do not create any IRQ domain. This fixes a "NULL pointer in stm32_gpio_domain_alloc()" kernel crash when the interrupt-parent =3D property is not declared in the Device Tree. Fixes: 0eb9f683336d ("pinctrl: Add IRQ support to STM32 gpios") Signed-off-by: Fabien Dessenne Link: https://lore.kernel.org/r/20220627142350.742973-1-fabien.dessenne@fos= s.st.com Signed-off-by: Linus Walleij Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/stm32/pinctrl-stm32.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/drivers/pinctrl/stm32/pinctrl-stm32.c +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c @@ -1299,15 +1299,17 @@ static int stm32_gpiolib_register_bank(s bank->bank_ioport_nr =3D bank_ioport_nr; spin_lock_init(&bank->lock); =20 - /* create irq hierarchical domain */ - bank->fwnode =3D of_node_to_fwnode(np); + if (pctl->domain) { + /* create irq hierarchical domain */ + bank->fwnode =3D of_node_to_fwnode(np); + + bank->domain =3D irq_domain_create_hierarchy(pctl->domain, 0, STM32_GPIO= _IRQ_LINE, + bank->fwnode, &stm32_gpio_domain_ops, + bank); =20 - bank->domain =3D irq_domain_create_hierarchy(pctl->domain, 0, - STM32_GPIO_IRQ_LINE, bank->fwnode, - &stm32_gpio_domain_ops, bank); - - if (!bank->domain) - return -ENODEV; + if (!bank->domain) + return -ENODEV; + } =20 err =3D gpiochip_add_data(&bank->gpio_chip, bank); if (err) { @@ -1477,6 +1479,8 @@ int stm32_pctl_probe(struct platform_dev pctl->domain =3D stm32_pctrl_get_irq_domain(np); if (IS_ERR(pctl->domain)) return PTR_ERR(pctl->domain); + if (!pctl->domain) + dev_warn(dev, "pinctrl without interrupt support\n"); =20 /* hwspinlock is optional */ hwlock_id =3D of_hwspin_lock_get_id(pdev->dev.of_node, 0); From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 743C8C19F28 for ; Wed, 27 Jul 2022 17:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241232AbiG0RAx (ORCPT ); Wed, 27 Jul 2022 13:00:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241455AbiG0Q7t (ORCPT ); Wed, 27 Jul 2022 12:59:49 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C012F69F18; Wed, 27 Jul 2022 09:37:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 3D98ECE22F9; Wed, 27 Jul 2022 16:37:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39491C433C1; Wed, 27 Jul 2022 16:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939819; bh=X7YZ4jGDuMVR9dtEomIpdQIuhNKxLJZH3GRt0XrdJUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ys96mjamdt4a0KU3zdQemcShR1ePX3tPkHVA3Q6DK3lWGjoXfIeiDTK/pa31Ge1OP HuzmOVKpkWX9olp4Cj3DyNy0lpBjWY2yWSNFJlCMgpvo4W5qs2rTTvW8AGLcZeLWBc c/wmvvSVe5J5mkLeI1lJjiNvPng5cV+tiPeNMpX0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Dooks , Bin Meng , Palmer Dabbelt Subject: [PATCH 5.15 002/201] riscv: add as-options for modules with assembly compontents Date: Wed, 27 Jul 2022 18:08:26 +0200 Message-Id: <20220727161027.059148282@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ben Dooks commit c1f6eff304e4dfa4558b6a8c6b2d26a91db6c998 upstream. When trying to load modules built for RISC-V which include assembly files the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'" due to R_RISCV_ALIGN relocations being generated by the assembler. The R_RISCV_ALIGN relocations can be removed at the expense of code space by adding -mno-relax to gcc and as. In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading") -mno-relax is added to the build variable KBUILD_CFLAGS_MODULE. See [1] for more info. The issue is that when kbuild builds a .S file, it invokes gcc with the -mno-relax flag, but this is not being passed through to the assembler. Adding -Wa,-mno-relax to KBUILD_AFLAGS_MODULE ensures that the assembler is invoked correctly. This may have now been fixed in gcc[2] and this addition should not stop newer gcc and as from working. [1] https://github.com/riscv/riscv-elf-psabi-doc/issues/183 [2] https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d= 86ef521857 Signed-off-by: Ben Dooks Reviewed-by: Bin Meng Link: https://lore.kernel.org/r/20220529152200.609809-1-ben.dooks@codethink= .co.uk Fixes: ab1ef68e5401 ("RISC-V: Add sections of PLT and GOT for kernel module= ") Cc: stable@vger.kernel.org Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/riscv/Makefile | 1 + 1 file changed, 1 insertion(+) --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -75,6 +75,7 @@ ifeq ($(CONFIG_PERF_EVENTS),y) endif =20 KBUILD_CFLAGS_MODULE +=3D $(call cc-option,-mno-relax) +KBUILD_AFLAGS_MODULE +=3D $(call as-option,-Wa$(comma)-mno-relax) =20 # GCC versions that support the "-mstrict-align" option default to allowing # unaligned accesses. While unaligned accesses are explicitly allowed in = the From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64C89C3F6B0 for ; Wed, 27 Jul 2022 17:00:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241227AbiG0RAu (ORCPT ); Wed, 27 Jul 2022 13:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241394AbiG0Q7i (ORCPT ); Wed, 27 Jul 2022 12:59:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0634691EC; Wed, 27 Jul 2022 09:37:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1C715601BE; Wed, 27 Jul 2022 16:37:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23A57C433C1; Wed, 27 Jul 2022 16:37:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939850; bh=iAiwTopTIPQy7eUcBAtaiuzXfEMLf7WvnhWcgS1CENQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=16FNtv9pDWuwgmQQEn38YhY2v4k5P4wQZBx0UxGslFepwPanc1Tjqa01ywjJ6SYr7 8S2JahsPAaVsrLAFHlsy9Q7kwOir01Ssws02PBwfLyPiROUsqik/GYFV7kPabACP1i MiutUe4v4Q1T2Nbu0+Q6jFtl49ifQaMY6+77wfpo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ido Schimmel , Amit Cohen , Nicolas Dichtel , David Ahern , "David S. Miller" Subject: [PATCH 5.15 003/201] mlxsw: spectrum_router: Fix IPv4 nexthop gateway indication Date: Wed, 27 Jul 2022 18:08:27 +0200 Message-Id: <20220727161027.098193723@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ido Schimmel commit e5ec6a2513383fe2ecc2ee3b5f51d97acbbcd4d8 upstream. mlxsw needs to distinguish nexthops with a gateway from connected nexthops in order to write the former to the adjacency table of the device. The check used to rely on the fact that nexthops with a gateway have a 'link' scope whereas connected nexthops have a 'host' scope. This is no longer correct after commit 747c14307214 ("ip: fix dflt addr selection for connected nexthop"). Fix that by instead checking the address family of the gateway IP. This is a more direct way and also consistent with the IPv6 counterpart in mlxsw_sp_rt6_is_gateway(). Cc: stable@vger.kernel.org Fixes: 747c14307214 ("ip: fix dflt addr selection for connected nexthop") Fixes: 597cfe4fc339 ("nexthop: Add support for IPv4 nexthops") Signed-off-by: Ido Schimmel Reviewed-by: Amit Cohen Reviewed-by: Nicolas Dichtel Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -5196,7 +5196,7 @@ static bool mlxsw_sp_fi_is_gateway(const { const struct fib_nh *nh =3D fib_info_nh(fi, 0); =20 - return nh->fib_nh_scope =3D=3D RT_SCOPE_LINK || + return nh->fib_nh_gw_family || mlxsw_sp_nexthop4_ipip_type(mlxsw_sp, nh, NULL); } From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46973C04A68 for ; Wed, 27 Jul 2022 17:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241258AbiG0RCX (ORCPT ); Wed, 27 Jul 2022 13:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232795AbiG0RBq (ORCPT ); Wed, 27 Jul 2022 13:01:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 953CB6BC1C; Wed, 27 Jul 2022 09:38:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 53190601BE; Wed, 27 Jul 2022 16:38:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F294C433D6; Wed, 27 Jul 2022 16:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939886; bh=T5DNPEG6pVCv0mZuUdiT16dtsq5c62BWvkJUSFQFrys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VcfniOkNvxFybIufn7OSF2YR/ykBrUwy5zcb3YzGAHWJr0LycKPvNG/kf05sFSXgV anOBOlqUjq6E+YRcQrSlXGT841ooU6aBqkQkNoq2I5XRmXn08b76bhp7/XOXkUu86b Qpcap6eshuJT45+jFnqOJXSMvalzKZ5q2jrSTrPM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Snowberg , Mimi Zohar , John Haxby , Linus Torvalds Subject: [PATCH 5.15 004/201] lockdown: Fix kexec lockdown bypass with ima policy Date: Wed, 27 Jul 2022 18:08:28 +0200 Message-Id: <20220727161027.136489560@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Eric Snowberg commit 543ce63b664e2c2f9533d089a4664b559c3e6b5b upstream. The lockdown LSM is primarily used in conjunction with UEFI Secure Boot. This LSM may also be used on machines without UEFI. It can also be enabled when UEFI Secure Boot is disabled. One of lockdown's features is to prevent kexec from loading untrusted kernels. Lockdown can be enabled through a bootparam or after the kernel has booted through securityfs. If IMA appraisal is used with the "ima_appraise=3Dlog" boot param, lockdown can be defeated with kexec on any machine when Secure Boot is disabled or unavailable. IMA prevents setting "ima_appraise=3Dlog" from the boot param when Secure Boot is enabled, but this does not cover cases where lockdown is used without Secure Boot. To defeat lockdown, boot without Secure Boot and add ima_appraise=3Dlog to the kernel command line; then: $ echo "integrity" > /sys/kernel/security/lockdown $ echo "appraise func=3DKEXEC_KERNEL_CHECK appraise_type=3Dimasig" > \ /sys/kernel/security/ima/policy $ kexec -ls unsigned-kernel Add a call to verify ima appraisal is set to "enforce" whenever lockdown is enabled. This fixes CVE-2022-21505. Cc: stable@vger.kernel.org Fixes: 29d3c1c8dfe7 ("kexec: Allow kexec_file() with appropriate IMA policy= when locked down") Signed-off-by: Eric Snowberg Acked-by: Mimi Zohar Reviewed-by: John Haxby Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- security/integrity/ima/ima_policy.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -2034,6 +2034,10 @@ bool ima_appraise_signature(enum kernel_ if (id >=3D READING_MAX_ID) return false; =20 + if (id =3D=3D READING_KEXEC_IMAGE && !(ima_appraise & IMA_APPRAISE_ENFORC= E) + && security_locked_down(LOCKDOWN_KEXEC)) + return false; + func =3D read_idmap[id] ?: FILE_CHECK; =20 rcu_read_lock(); From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DCAFC19F2B for ; Wed, 27 Jul 2022 17:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241334AbiG0RDK (ORCPT ); Wed, 27 Jul 2022 13:03:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241210AbiG0RCs (ORCPT ); Wed, 27 Jul 2022 13:02:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C6316D2EC; Wed, 27 Jul 2022 09:38:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A34B3601C0; Wed, 27 Jul 2022 16:38:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B497DC433D6; Wed, 27 Jul 2022 16:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939903; bh=edNZKyHFUMxosSRtD1YkMoP8MphrB+Np2JM4Q6FEj2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Esuvcrdt6Bir+saa6Ieg8Gim1mt3fgT05NnL58UCQ220PmQxBgDiE8MNNPKh/TQc/ UXGJuuuei3h8C7b2in8PB/y4nm/jnvoPaWrWIGlTelITcKZAN1EBM7NM3MOImNxFeG N8PevkFBlV8DXRcq1tHDp0uW8PkWZjFjRpSMCKq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , Dmitry Osipenko Subject: [PATCH 5.15 005/201] drm/ttm: fix locking in vmap/vunmap TTM GEM helpers Date: Wed, 27 Jul 2022 18:08:29 +0200 Message-Id: <20220727161027.174517267@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian K=C3=B6nig commit dbd0da2453c694f2f74651834d90fb280b57f151 upstream. I've stumbled over this while reviewing patches for DMA-buf and it looks like we completely messed the locking up here. In general most TTM function should only be called while holding the appropriate BO resv lock. Without this we could break the internal buffer object state here. Only compile tested! Signed-off-by: Christian K=C3=B6nig Fixes: 43676605f890 ("drm/ttm: Add vmap/vunmap to TTM and TTM GEM helpers") Cc: stable@vger.kernel.org Reviewed-by: Dmitry Osipenko Link: https://patchwork.freedesktop.org/patch/msgid/20220715111533.467012-1= -christian.koenig@amd.com Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/drm_gem_ttm_helper.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/drm_gem_ttm_helper.c +++ b/drivers/gpu/drm/drm_gem_ttm_helper.c @@ -64,8 +64,13 @@ int drm_gem_ttm_vmap(struct drm_gem_obje struct dma_buf_map *map) { struct ttm_buffer_object *bo =3D drm_gem_ttm_of_gem(gem); + int ret; =20 - return ttm_bo_vmap(bo, map); + dma_resv_lock(gem->resv, NULL); + ret =3D ttm_bo_vmap(bo, map); + dma_resv_unlock(gem->resv); + + return ret; } EXPORT_SYMBOL(drm_gem_ttm_vmap); =20 @@ -82,7 +87,9 @@ void drm_gem_ttm_vunmap(struct drm_gem_o { struct ttm_buffer_object *bo =3D drm_gem_ttm_of_gem(gem); =20 + dma_resv_lock(gem->resv, NULL); ttm_bo_vunmap(bo, map); + dma_resv_unlock(gem->resv); } EXPORT_SYMBOL(drm_gem_ttm_vunmap); =20 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFA96C04A68 for ; Wed, 27 Jul 2022 17:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241287AbiG0RDR (ORCPT ); Wed, 27 Jul 2022 13:03:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241238AbiG0RCu (ORCPT ); Wed, 27 Jul 2022 13:02:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 117DF6D2F6; Wed, 27 Jul 2022 09:38:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C19FB601C3; Wed, 27 Jul 2022 16:38:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 980F4C433D7; Wed, 27 Jul 2022 16:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939906; bh=nN5fYg0LLRzInfWznAMDU7I5OPF9nTmCG09U3YzKTx0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WtV9nZOlhQgXNsPo8dQB2hnGnDML79xW8e8sH+TCOEhZpyd/psMVS7pZp+nynrogm d6g39q/Xdlq+nUk/UNU7eAtkhtXEoXAl/leT5Gd+0tNNtfer5fiHHHglRLog0SiaxL d77hdPt1g9VynFSA0l7ELCn/Bp6ipURclmAsCU0g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniele Palmas , Manivannan Sadhasivam , Manivannan Sadhasivam , Fabio Porcedda Subject: [PATCH 5.15 006/201] bus: mhi: host: pci_generic: add Telit FN980 v1 hardware revision Date: Wed, 27 Jul 2022 18:08:30 +0200 Message-Id: <20220727161027.212350496@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniele Palmas commit a96ef8b504efb2ad445dfb6d54f9488c3ddf23d2 upstream. Add Telit FN980 v1 hardware revision: 01:00.0 Unassigned class [ff00]: Qualcomm Device [17cb:0306] Subsystem: Device [1c5d:2000] Signed-off-by: Daniele Palmas Reviewed-by: Manivannan Sadhasivam Link: https://lore.kernel.org/r/20220427072648.17635-1-dnlplm@gmail.com [mani: Added "host" to the subject] Signed-off-by: Manivannan Sadhasivam Signed-off-by: Fabio Porcedda Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/bus/mhi/pci_generic.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) --- a/drivers/bus/mhi/pci_generic.c +++ b/drivers/bus/mhi/pci_generic.c @@ -406,7 +406,45 @@ static const struct mhi_pci_dev_info mhi .mru_default =3D 32768, }; =20 +static const struct mhi_channel_config mhi_telit_fn980_hw_v1_channels[] = =3D { + MHI_CHANNEL_CONFIG_UL(14, "QMI", 32, 0), + MHI_CHANNEL_CONFIG_DL(15, "QMI", 32, 0), + MHI_CHANNEL_CONFIG_UL(20, "IPCR", 16, 0), + MHI_CHANNEL_CONFIG_DL_AUTOQUEUE(21, "IPCR", 16, 0), + MHI_CHANNEL_CONFIG_HW_UL(100, "IP_HW0", 128, 1), + MHI_CHANNEL_CONFIG_HW_DL(101, "IP_HW0", 128, 2), +}; + +static struct mhi_event_config mhi_telit_fn980_hw_v1_events[] =3D { + MHI_EVENT_CONFIG_CTRL(0, 128), + MHI_EVENT_CONFIG_HW_DATA(1, 1024, 100), + MHI_EVENT_CONFIG_HW_DATA(2, 2048, 101) +}; + +static struct mhi_controller_config modem_telit_fn980_hw_v1_config =3D { + .max_channels =3D 128, + .timeout_ms =3D 20000, + .num_channels =3D ARRAY_SIZE(mhi_telit_fn980_hw_v1_channels), + .ch_cfg =3D mhi_telit_fn980_hw_v1_channels, + .num_events =3D ARRAY_SIZE(mhi_telit_fn980_hw_v1_events), + .event_cfg =3D mhi_telit_fn980_hw_v1_events, +}; + +static const struct mhi_pci_dev_info mhi_telit_fn980_hw_v1_info =3D { + .name =3D "telit-fn980-hwv1", + .fw =3D "qcom/sdx55m/sbl1.mbn", + .edl =3D "qcom/sdx55m/edl.mbn", + .config =3D &modem_telit_fn980_hw_v1_config, + .bar_num =3D MHI_PCI_DEFAULT_BAR_NUM, + .dma_data_width =3D 32, + .mru_default =3D 32768, + .sideband_wake =3D false, +}; + static const struct pci_device_id mhi_pci_id_table[] =3D { + /* Telit FN980 hardware revision v1 */ + { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x0306, 0x1C5D, 0x2000), + .driver_data =3D (kernel_ulong_t) &mhi_telit_fn980_hw_v1_info }, { PCI_DEVICE(PCI_VENDOR_ID_QCOM, 0x0306), .driver_data =3D (kernel_ulong_t) &mhi_qcom_sdx55_info }, { PCI_DEVICE(PCI_VENDOR_ID_QCOM, 0x0304), From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE7EC19F2D for ; Wed, 27 Jul 2022 17:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232046AbiG0REr (ORCPT ); Wed, 27 Jul 2022 13:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240940AbiG0RDe (ORCPT ); Wed, 27 Jul 2022 13:03:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A624E6D9F8; Wed, 27 Jul 2022 09:38:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9D053601BE; Wed, 27 Jul 2022 16:38:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9D41C433D6; Wed, 27 Jul 2022 16:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939909; bh=OS08X1bnDa4+HnJGrtjV3F+yCxi6uiRBItisFmmT+G0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hrgjREdHf+kUczppSNj3OuYstBVkCMcN1Z2yJvNwaEacYKxbVQ2hrvjxhkGwplX9L LCSmzylDQOhHeDbfLkZfOO2+ee4IP2SV9g9p4Pcps6PgGDWKe9CA/OEcfwmZ4amqI/ 2x6ZiRyM8oFPptAWWN6IoN/Z2WFPDoT+VaXVTbQ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniele Palmas , Manivannan Sadhasivam , Manivannan Sadhasivam , Fabio Porcedda Subject: [PATCH 5.15 007/201] bus: mhi: host: pci_generic: add Telit FN990 Date: Wed, 27 Jul 2022 18:08:31 +0200 Message-Id: <20220727161027.254650517@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniele Palmas commit 77fc41204734042861210b9d05338c9b8360affb upstream. Add Telit FN990: 01:00.0 Unassigned class [ff00]: Qualcomm Device 0308 Subsystem: Device 1c5d:2010 Signed-off-by: Daniele Palmas Reviewed-by: Manivannan Sadhasivam Link: https://lore.kernel.org/r/20220502112036.443618-1-dnlplm@gmail.com [mani: Added "host" to the subject] Signed-off-by: Manivannan Sadhasivam Signed-off-by: Fabio Porcedda Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/bus/mhi/pci_generic.c | 41 +++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 41 insertions(+) --- a/drivers/bus/mhi/pci_generic.c +++ b/drivers/bus/mhi/pci_generic.c @@ -441,6 +441,44 @@ static const struct mhi_pci_dev_info mhi .sideband_wake =3D false, }; =20 +static const struct mhi_channel_config mhi_telit_fn990_channels[] =3D { + MHI_CHANNEL_CONFIG_UL_SBL(2, "SAHARA", 32, 0), + MHI_CHANNEL_CONFIG_DL_SBL(3, "SAHARA", 32, 0), + MHI_CHANNEL_CONFIG_UL(4, "DIAG", 64, 1), + MHI_CHANNEL_CONFIG_DL(5, "DIAG", 64, 1), + MHI_CHANNEL_CONFIG_UL(12, "MBIM", 32, 0), + MHI_CHANNEL_CONFIG_DL(13, "MBIM", 32, 0), + MHI_CHANNEL_CONFIG_UL(32, "DUN", 32, 0), + MHI_CHANNEL_CONFIG_DL(33, "DUN", 32, 0), + MHI_CHANNEL_CONFIG_HW_UL(100, "IP_HW0_MBIM", 128, 2), + MHI_CHANNEL_CONFIG_HW_DL(101, "IP_HW0_MBIM", 128, 3), +}; + +static struct mhi_event_config mhi_telit_fn990_events[] =3D { + MHI_EVENT_CONFIG_CTRL(0, 128), + MHI_EVENT_CONFIG_DATA(1, 128), + MHI_EVENT_CONFIG_HW_DATA(2, 1024, 100), + MHI_EVENT_CONFIG_HW_DATA(3, 2048, 101) +}; + +static const struct mhi_controller_config modem_telit_fn990_config =3D { + .max_channels =3D 128, + .timeout_ms =3D 20000, + .num_channels =3D ARRAY_SIZE(mhi_telit_fn990_channels), + .ch_cfg =3D mhi_telit_fn990_channels, + .num_events =3D ARRAY_SIZE(mhi_telit_fn990_events), + .event_cfg =3D mhi_telit_fn990_events, +}; + +static const struct mhi_pci_dev_info mhi_telit_fn990_info =3D { + .name =3D "telit-fn990", + .config =3D &modem_telit_fn990_config, + .bar_num =3D MHI_PCI_DEFAULT_BAR_NUM, + .dma_data_width =3D 32, + .sideband_wake =3D false, + .mru_default =3D 32768, +}; + static const struct pci_device_id mhi_pci_id_table[] =3D { /* Telit FN980 hardware revision v1 */ { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x0306, 0x1C5D, 0x2000), @@ -449,6 +487,9 @@ static const struct pci_device_id mhi_pc .driver_data =3D (kernel_ulong_t) &mhi_qcom_sdx55_info }, { PCI_DEVICE(PCI_VENDOR_ID_QCOM, 0x0304), .driver_data =3D (kernel_ulong_t) &mhi_qcom_sdx24_info }, + /* Telit FN990 */ + { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x0308, 0x1c5d, 0x2010), + .driver_data =3D (kernel_ulong_t) &mhi_telit_fn990_info }, { PCI_DEVICE(0x1eac, 0x1001), /* EM120R-GL (sdx24) */ .driver_data =3D (kernel_ulong_t) &mhi_quectel_em1xx_info }, { PCI_DEVICE(0x1eac, 0x1002), /* EM160R-GL (sdx24) */ From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DDFCC04A68 for ; Wed, 27 Jul 2022 17:03:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbiG0RDo (ORCPT ); Wed, 27 Jul 2022 13:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232874AbiG0RDH (ORCPT ); Wed, 27 Jul 2022 13:03:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B3606D572; Wed, 27 Jul 2022 09:38:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 595BA601CE; Wed, 27 Jul 2022 16:38:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66D5AC433D6; Wed, 27 Jul 2022 16:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939911; bh=+kCkmqrmQ+ezg/La72IVCkAR8CRuOOBy4ZA/yaCOHtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TD49W+aqMwWTUmQvgk18oduiuVI0WnBY90Y2k4fehujqGHGN03xTC59+lBtyD/V5j vxg4A7LCaQGTbUJIkTatO41BlEbxYBK0s8sMjDgEi/dA4AF9cgOrAY49jREAhgyGwa 28WGMDiqVBqaCB3WxcI8nQSr1guEv/U3pTaI/sx4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "sidhartha.kumar@oracle.com, stable@vger.kernel.org, Oleksandr Tymoshenko" , Oleksandr Tymoshenko Subject: [PATCH 5.15 008/201] Revert "selftest/vm: verify remap destination address in mremap_test" Date: Wed, 27 Jul 2022 18:08:32 +0200 Message-Id: <20220727161027.294082875@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Oleksandr Tymoshenko This reverts commit 0b4e16093e081a3ab08b0d6cedf79b249f41b248. The upstream commit 18d609daa546 ("selftest/vm: verify remap destination address in mremap_test") was backported as commit 2688d967ec65 ("selftest/vm: verify remap destination address in mremap_test"). Repeated backport introduced the duplicate of function is_remap_region_valid to the file breakign the vm selftest build. Fixes: 0b4e16093e08 ("selftest/vm: verify remap destination address in mrem= ap_test") Signed-off-by: Oleksandr Tymoshenko Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- tools/testing/selftests/vm/mremap_test.c | 24 ------------------------ 1 file changed, 24 deletions(-) --- a/tools/testing/selftests/vm/mremap_test.c +++ b/tools/testing/selftests/vm/mremap_test.c @@ -66,30 +66,6 @@ enum { .expect_failure =3D should_fail \ } =20 -/* - * Returns false if the requested remap region overlaps with an - * existing mapping (e.g text, stack) else returns true. - */ -static bool is_remap_region_valid(void *addr, unsigned long long size) -{ - void *remap_addr =3D NULL; - bool ret =3D true; - - /* Use MAP_FIXED_NOREPLACE flag to ensure region is not mapped */ - remap_addr =3D mmap(addr, size, PROT_READ | PROT_WRITE, - MAP_FIXED_NOREPLACE | MAP_ANONYMOUS | MAP_SHARED, - -1, 0); - - if (remap_addr =3D=3D MAP_FAILED) { - if (errno =3D=3D EEXIST) - ret =3D false; - } else { - munmap(remap_addr, size); - } - - return ret; -} - /* Returns mmap_min_addr sysctl tunable from procfs */ static unsigned long long get_mmap_min_addr(void) { From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B52FC04A68 for ; Wed, 27 Jul 2022 17:03:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241343AbiG0RDe (ORCPT ); Wed, 27 Jul 2022 13:03:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234629AbiG0RDG (ORCPT ); Wed, 27 Jul 2022 13:03:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BF8F6D574; Wed, 27 Jul 2022 09:38:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 19C4F601D6; Wed, 27 Jul 2022 16:38:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 241D2C433D6; Wed, 27 Jul 2022 16:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939914; bh=vTlGGWAnLSpNTe7twsSarNTbWCHfWyWaJ4QfxcvQ92Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qTX68yfT+6v4bcYaeMlgk4IYFgHRwPel/d9HtsVsNmqouIB++X5jHorIBkUQ+Gnr6 U4KY5bT9lkNSn6xaXQe4isl2XdC5+fAK5g0mjstFAfTc4YEiRJktefTPYxad9ZhaAi dYNmPFaz6gBe9zKbsF+OVYrOTyUBgNBbPu5Xkq5Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "sidhartha.kumar@oracle.com, stable@vger.kernel.org, Oleksandr Tymoshenko" , Oleksandr Tymoshenko Subject: [PATCH 5.15 009/201] Revert "selftest/vm: verify mmap addr in mremap_test" Date: Wed, 27 Jul 2022 18:08:33 +0200 Message-Id: <20220727161027.337601368@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Oleksandr Tymoshenko This reverts commit e8b9989597daac896b3400b7005f24bf15233d9a. The upstream commit 9c85a9bae267 ("selftest/vm: verify mmap addr in mremap_test") was backported as commit a17404fcbfd0 ("selftest/vm: verify mmap addr in mremap_test"). Repeated backport introduced the duplicate of function get_mmap_min_addr to the file breakign the vm selftest build. Fixes: e8b9989597da ("selftest/vm: verify mmap addr in mremap_test") Signed-off-by: Oleksandr Tymoshenko Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- tools/testing/selftests/vm/mremap_test.c | 29 --------------------------= --- 1 file changed, 29 deletions(-) --- a/tools/testing/selftests/vm/mremap_test.c +++ b/tools/testing/selftests/vm/mremap_test.c @@ -66,35 +66,6 @@ enum { .expect_failure =3D should_fail \ } =20 -/* Returns mmap_min_addr sysctl tunable from procfs */ -static unsigned long long get_mmap_min_addr(void) -{ - FILE *fp; - int n_matched; - static unsigned long long addr; - - if (addr) - return addr; - - fp =3D fopen("/proc/sys/vm/mmap_min_addr", "r"); - if (fp =3D=3D NULL) { - ksft_print_msg("Failed to open /proc/sys/vm/mmap_min_addr: %s\n", - strerror(errno)); - exit(KSFT_SKIP); - } - - n_matched =3D fscanf(fp, "%llu", &addr); - if (n_matched !=3D 1) { - ksft_print_msg("Failed to read /proc/sys/vm/mmap_min_addr: %s\n", - strerror(errno)); - fclose(fp); - exit(KSFT_SKIP); - } - - fclose(fp); - return addr; -} - /* * Returns false if the requested remap region overlaps with an * existing mapping (e.g text, stack) else returns true. From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7E98C19F28 for ; Wed, 27 Jul 2022 17:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233140AbiG0RDt (ORCPT ); Wed, 27 Jul 2022 13:03:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232385AbiG0RDQ (ORCPT ); Wed, 27 Jul 2022 13:03:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D9636D9C2; Wed, 27 Jul 2022 09:38:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CFBCF60B68; Wed, 27 Jul 2022 16:38:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBA54C433C1; Wed, 27 Jul 2022 16:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939917; bh=Pyg9mJW8D9qeURa9xoUZFw426rog098zh/2yXBWjFrU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WWwpuI/o5d2ahiPMyIidmw0Lcsc9TdiVXg5ken4hpT+H/09FtW5zY4aG/Wnu6lNH1 VZ77esVB5b2NYoPqk3UiBBgEsANdyLUVz7eHY+qFEpiFKWC+n9W73hrBD56AYWabL4 UBq+tobMil0OqxSwUZlP3EJWUS+ctY/qEuX22lRI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Jeffrey Hugo , Dexuan Cui , Wei Liu , Carl Vanderlip Subject: [PATCH 5.15 010/201] PCI: hv: Fix multi-MSI to allow more than one MSI vector Date: Wed, 27 Jul 2022 18:08:34 +0200 Message-Id: <20220727161027.367763215@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jeffrey Hugo commit 08e61e861a0e47e5e1a3fb78406afd6b0cea6b6d upstream. If the allocation of multiple MSI vectors for multi-MSI fails in the core PCI framework, the framework will retry the allocation as a single MSI vector, assuming that meets the min_vecs specified by the requesting driver. Hyper-V advertises that multi-MSI is supported, but reuses the VECTOR domain to implement that for x86. The VECTOR domain does not support multi-MSI, so the alloc will always fail and fallback to a single MSI allocation. In short, Hyper-V advertises a capability it does not implement. Hyper-V can support multi-MSI because it coordinates with the hypervisor to map the MSIs in the IOMMU's interrupt remapper, which is something the VECTOR domain does not have. Therefore the fix is simple - copy what the x86 IOMMU drivers (AMD/Intel-IR) do by removing X86_IRQ_ALLOC_CONTIGUOUS_VECTORS after calling the VECTOR domain's pci_msi_prepare(). 5.15 backport - adds the hv_msi_prepare wrapper function Fixes: 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for Microsoft = Hyper-V VMs") Signed-off-by: Jeffrey Hugo Reviewed-by: Dexuan Cui Link: https://lore.kernel.org/r/1649856981-14649-1-git-send-email-quic_jhug= o@quicinc.com Signed-off-by: Wei Liu Signed-off-by: Carl Vanderlip Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pci/controller/pci-hyperv.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1204,6 +1204,21 @@ static void hv_irq_mask(struct irq_data pci_msi_mask_irq(data); } =20 +static int hv_msi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *info) +{ + int ret =3D pci_msi_prepare(domain, dev, nvec, info); + + /* + * By using the interrupt remapper in the hypervisor IOMMU, contiguous + * CPU vectors is not needed for multi-MSI + */ + if (info->type =3D=3D X86_IRQ_ALLOC_TYPE_PCI_MSI) + info->flags &=3D ~X86_IRQ_ALLOC_CONTIGUOUS_VECTORS; + + return ret; +} + /** * hv_irq_unmask() - "Unmask" the IRQ by setting its current * affinity. @@ -1601,7 +1616,7 @@ static struct irq_chip hv_msi_irq_chip =3D }; =20 static struct msi_domain_ops hv_msi_ops =3D { - .msi_prepare =3D pci_msi_prepare, + .msi_prepare =3D hv_msi_prepare, .msi_free =3D hv_msi_free, }; From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCF47C19F2B for ; Wed, 27 Jul 2022 17:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235888AbiG0RAF (ORCPT ); Wed, 27 Jul 2022 13:00:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241206AbiG0Q65 (ORCPT ); Wed, 27 Jul 2022 12:58:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E318F675BD; Wed, 27 Jul 2022 09:37:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF9C061AA9; Wed, 27 Jul 2022 16:37:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECAEEC433D7; Wed, 27 Jul 2022 16:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939822; bh=5nBEjBIzLOia/efdCOlZmxwgl2SbuzyDpTTIsEyjpK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3jC98VpC6flz+VJUkUp4lOghgH5ndOq2iI25/TQF6BV+PWdYkQRwEipJHKl+M3UE 3ZvMm4CkjnUBD8quZBY7qAq6wL+ttIM37DfHNTs7eCidw59iuRWIDtLp8BfgdsJxTP yIaSirws7Vx6UOSNIqN40ZF6AOMbfPTkVH2jtHu0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Jeffrey Hugo , Michael Kelley , Wei Liu , Carl Vanderlip Subject: [PATCH 5.15 011/201] PCI: hv: Fix hv_arch_irq_unmask() for multi-MSI Date: Wed, 27 Jul 2022 18:08:35 +0200 Message-Id: <20220727161027.412476761@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jeffrey Hugo commit 455880dfe292a2bdd3b4ad6a107299fce610e64b upstream. In the multi-MSI case, hv_arch_irq_unmask() will only operate on the first MSI of the N allocated. This is because only the first msi_desc is cached and it is shared by all the MSIs of the multi-MSI block. This means that hv_arch_irq_unmask() gets the correct address, but the wrong data (always 0). This can break MSIs. Lets assume MSI0 is vector 34 on CPU0, and MSI1 is vector 33 on CPU0. hv_arch_irq_unmask() is called on MSI0. It uses a hypercall to configure the MSI address and data (0) to vector 34 of CPU0. This is correct. Then hv_arch_irq_unmask is called on MSI1. It uses another hypercall to configure the MSI address and data (0) to vector 33 of CPU0. This is wrong, and results in both MSI0 and MSI1 being routed to vector 33. Linux will observe extra instances of MSI1 and no instances of MSI0 despite the endpoint device behaving correctly. For the multi-MSI case, we need unique address and data info for each MSI, but the cached msi_desc does not provide that. However, that information can be gotten from the int_desc cached in the chip_data by compose_msi_msg(). Fix the multi-MSI case to use that cached information instead. Since hv_set_msi_entry_from_desc() is no longer applicable, remove it. 5.15 backport - no changes to code, but merge conflict due to refactor. Signed-off-by: Jeffrey Hugo Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/1651068453-29588-1-git-send-email-quic_jhug= o@quicinc.com Signed-off-by: Wei Liu Signed-off-by: Carl Vanderlip Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/mshyperv.h | 7 ------- drivers/pci/controller/pci-hyperv.c | 5 ++++- 2 files changed, 4 insertions(+), 8 deletions(-) --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -176,13 +176,6 @@ bool hv_vcpu_is_preempted(int vcpu); static inline void hv_apic_init(void) {} #endif =20 -static inline void hv_set_msi_entry_from_desc(union hv_msi_entry *msi_entr= y, - struct msi_desc *msi_desc) -{ - msi_entry->address.as_uint32 =3D msi_desc->msg.address_lo; - msi_entry->data.as_uint32 =3D msi_desc->msg.data; -} - struct irq_domain *hv_create_pci_msi_domain(void); =20 int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vecto= r, --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1234,6 +1234,7 @@ static void hv_irq_unmask(struct irq_dat struct msi_desc *msi_desc =3D irq_data_get_msi_desc(data); struct irq_cfg *cfg =3D irqd_cfg(data); struct hv_retarget_device_interrupt *params; + struct tran_int_desc *int_desc; struct hv_pcibus_device *hbus; struct cpumask *dest; cpumask_var_t tmp; @@ -1248,6 +1249,7 @@ static void hv_irq_unmask(struct irq_dat pdev =3D msi_desc_to_pci_dev(msi_desc); pbus =3D pdev->bus; hbus =3D container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); + int_desc =3D data->chip_data; =20 spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags); =20 @@ -1255,7 +1257,8 @@ static void hv_irq_unmask(struct irq_dat memset(params, 0, sizeof(*params)); params->partition_id =3D HV_PARTITION_ID_SELF; params->int_entry.source =3D HV_INTERRUPT_SOURCE_MSI; - hv_set_msi_entry_from_desc(¶ms->int_entry.msi_entry, msi_desc); + params->int_entry.msi_entry.address.as_uint32 =3D int_desc->address & 0xf= fffffff; + params->int_entry.msi_entry.data.as_uint32 =3D int_desc->data; params->device_id =3D (hbus->hdev->dev_instance.b[5] << 24) | (hbus->hdev->dev_instance.b[4] << 16) | (hbus->hdev->dev_instance.b[7] << 8) | From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6752C04A68 for ; Wed, 27 Jul 2022 17:01:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238361AbiG0RBY (ORCPT ); Wed, 27 Jul 2022 13:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241492AbiG0Q7x (ORCPT ); Wed, 27 Jul 2022 12:59:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4C15691D9; Wed, 27 Jul 2022 09:37:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AB0DC61ACF; Wed, 27 Jul 2022 16:37:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4FA1C433B5; Wed, 27 Jul 2022 16:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939825; bh=CyJDOAFbwxtuupOzya6XMcjIY+cX2xf5OaMm8Kb0NLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qnFzpLyQmmFYvmjs4/wtNTg4+IEmaQuRqpbYQuwJaSWLz3ezSBFJLm8BlLI7sNrwz tFl2CrKWWmm8WkXLq8JwooT7/zruG+EIxqqf75EJ9sLYAer/DEuJtodoBFnJDhb/2M VUX9HxHuG7ziUxcc+H7XptUoSBFyLJZmjCd3I5QM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Jeffrey Hugo , Dexuan Cui , Michael Kelley , Wei Liu , Carl Vanderlip Subject: [PATCH 5.15 012/201] PCI: hv: Reuse existing IRTE allocation in compose_msi_msg() Date: Wed, 27 Jul 2022 18:08:36 +0200 Message-Id: <20220727161027.451675981@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jeffrey Hugo commit b4b77778ecc5bfbd4e77de1b2fd5c1dd3c655f1f upstream. Currently if compose_msi_msg() is called multiple times, it will free any previous IRTE allocation, and generate a new allocation. While nothing prevents this from occurring, it is extraneous when Linux could just reuse the existing allocation and avoid a bunch of overhead. However, when future IRTE allocations operate on blocks of MSIs instead of a single line, freeing the allocation will impact all of the lines. This could cause an issue where an allocation of N MSIs occurs, then some of the lines are retargeted, and finally the allocation is freed/reallocated. The freeing of the allocation removes all of the configuration for the entire block, which requires all the lines to be retargeted, which might not happen since some lines might already be unmasked/active. Signed-off-by: Jeffrey Hugo Reviewed-by: Dexuan Cui Tested-by: Dexuan Cui Tested-by: Michael Kelley Link: https://lore.kernel.org/r/1652282582-21595-1-git-send-email-quic_jhug= o@quicinc.com Signed-off-by: Wei Liu Signed-off-by: Carl Vanderlip Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pci/controller/pci-hyperv.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1458,6 +1458,15 @@ static void hv_compose_msi_msg(struct ir u32 size; int ret; =20 + /* Reuse the previous allocation */ + if (data->chip_data) { + int_desc =3D data->chip_data; + msg->address_hi =3D int_desc->address >> 32; + msg->address_lo =3D int_desc->address & 0xffffffff; + msg->data =3D int_desc->data; + return; + } + pdev =3D msi_desc_to_pci_dev(irq_data_get_msi_desc(data)); dest =3D irq_data_get_effective_affinity_mask(data); pbus =3D pdev->bus; @@ -1467,13 +1476,6 @@ static void hv_compose_msi_msg(struct ir if (!hpdev) goto return_null_message; =20 - /* Free any previous message that might have already been composed. */ - if (data->chip_data) { - int_desc =3D data->chip_data; - data->chip_data =3D NULL; - hv_int_desc_free(hpdev, int_desc); - } - int_desc =3D kzalloc(sizeof(*int_desc), GFP_ATOMIC); if (!int_desc) goto drop_reference; From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D113C19F2B for ; Wed, 27 Jul 2022 17:01:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241259AbiG0RBF (ORCPT ); Wed, 27 Jul 2022 13:01:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241476AbiG0Q7w (ORCPT ); Wed, 27 Jul 2022 12:59:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D96B869F2C; Wed, 27 Jul 2022 09:37:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 46681B8200C; Wed, 27 Jul 2022 16:37:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A223BC433C1; Wed, 27 Jul 2022 16:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939828; bh=o5MEAFf0pMJkybVP0AJTLDjQ/Vb5msp0ru0Amwqev1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=soqLluZkIm+MXF/uaDs1t061nCaGom6tjFwiuqL4o1nSFbMR9KfalrwOwQiD5I+nP 8oIE8eTUbbtPhDmKsBiXfEpgvtVpV5A3sVtsc4QKE1CmijwGqkg2jMZ49mAkURN8Ht d5K3HVEvfII7D22kZOWl4Drp4OW5oiHzpv/tOoPI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Dexuan Cui , Jeffrey Hugo , Michael Kelley , Wei Liu , Carl Vanderlip Subject: [PATCH 5.15 013/201] PCI: hv: Fix interrupt mapping for multi-MSI Date: Wed, 27 Jul 2022 18:08:37 +0200 Message-Id: <20220727161027.482458055@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jeffrey Hugo commit a2bad844a67b1c7740bda63e87453baf63c3a7f7 upstream. According to Dexuan, the hypervisor folks beleive that multi-msi allocations are not correct. compose_msi_msg() will allocate multi-msi one by one. However, multi-msi is a block of related MSIs, with alignment requirements. In order for the hypervisor to allocate properly aligned and consecutive entries in the IOMMU Interrupt Remapping Table, there should be a single mapping request that requests all of the multi-msi vectors in one shot. Dexuan suggests detecting the multi-msi case and composing a single request related to the first MSI. Then for the other MSIs in the same block, use the cached information. This appears to be viable, so do it. 5.15 backport - add hv_msi_get_int_vector helper function. Fixed merge conflict due to delivery_mode name change (APIC_DELIVERY_MODE_FIXED is the value given to DELIVERY_MODE on x86). Removed unused variable in hv_compose_msi_msg. Fixed reference to msi_desc->pci to point to the same is_msix variable. Suggested-by: Dexuan Cui Signed-off-by: Jeffrey Hugo Reviewed-by: Dexuan Cui Tested-by: Michael Kelley Link: https://lore.kernel.org/r/1652282599-21643-1-git-send-email-quic_jhug= o@quicinc.com Signed-off-by: Wei Liu Signed-off-by: Carl Vanderlip Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pci/controller/pci-hyperv.c | 68 ++++++++++++++++++++++++++++++-= ----- 1 file changed, 57 insertions(+), 11 deletions(-) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1142,6 +1142,10 @@ static void hv_int_desc_free(struct hv_p u8 buffer[sizeof(struct pci_delete_interrupt)]; } ctxt; =20 + if (!int_desc->vector_count) { + kfree(int_desc); + return; + } memset(&ctxt, 0, sizeof(ctxt)); int_pkt =3D (struct pci_delete_interrupt *)&ctxt.pkt.message; int_pkt->message_type.type =3D @@ -1204,6 +1208,13 @@ static void hv_irq_mask(struct irq_data pci_msi_mask_irq(data); } =20 +static unsigned int hv_msi_get_int_vector(struct irq_data *data) +{ + struct irq_cfg *cfg =3D irqd_cfg(data); + + return cfg->vector; +} + static int hv_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *info) { @@ -1359,12 +1370,12 @@ static void hv_pci_compose_compl(void *c =20 static u32 hv_compose_msi_req_v1( struct pci_create_interrupt *int_pkt, struct cpumask *affinity, - u32 slot, u8 vector) + u32 slot, u8 vector, u8 vector_count) { int_pkt->message_type.type =3D PCI_CREATE_INTERRUPT_MESSAGE; int_pkt->wslot.slot =3D slot; int_pkt->int_desc.vector =3D vector; - int_pkt->int_desc.vector_count =3D 1; + int_pkt->int_desc.vector_count =3D vector_count; int_pkt->int_desc.delivery_mode =3D APIC_DELIVERY_MODE_FIXED; =20 /* @@ -1387,14 +1398,14 @@ static int hv_compose_msi_req_get_cpu(st =20 static u32 hv_compose_msi_req_v2( struct pci_create_interrupt2 *int_pkt, struct cpumask *affinity, - u32 slot, u8 vector) + u32 slot, u8 vector, u8 vector_count) { int cpu; =20 int_pkt->message_type.type =3D PCI_CREATE_INTERRUPT_MESSAGE2; int_pkt->wslot.slot =3D slot; int_pkt->int_desc.vector =3D vector; - int_pkt->int_desc.vector_count =3D 1; + int_pkt->int_desc.vector_count =3D vector_count; int_pkt->int_desc.delivery_mode =3D APIC_DELIVERY_MODE_FIXED; cpu =3D hv_compose_msi_req_get_cpu(affinity); int_pkt->int_desc.processor_array[0] =3D @@ -1406,7 +1417,7 @@ static u32 hv_compose_msi_req_v2( =20 static u32 hv_compose_msi_req_v3( struct pci_create_interrupt3 *int_pkt, struct cpumask *affinity, - u32 slot, u32 vector) + u32 slot, u32 vector, u8 vector_count) { int cpu; =20 @@ -1414,7 +1425,7 @@ static u32 hv_compose_msi_req_v3( int_pkt->wslot.slot =3D slot; int_pkt->int_desc.vector =3D vector; int_pkt->int_desc.reserved =3D 0; - int_pkt->int_desc.vector_count =3D 1; + int_pkt->int_desc.vector_count =3D vector_count; int_pkt->int_desc.delivery_mode =3D APIC_DELIVERY_MODE_FIXED; cpu =3D hv_compose_msi_req_get_cpu(affinity); int_pkt->int_desc.processor_array[0] =3D @@ -1437,7 +1448,6 @@ static u32 hv_compose_msi_req_v3( */ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) { - struct irq_cfg *cfg =3D irqd_cfg(data); struct hv_pcibus_device *hbus; struct vmbus_channel *channel; struct hv_pci_dev *hpdev; @@ -1446,6 +1456,8 @@ static void hv_compose_msi_msg(struct ir struct cpumask *dest; struct compose_comp_ctxt comp; struct tran_int_desc *int_desc; + struct msi_desc *msi_desc; + u8 vector, vector_count; struct { struct pci_packet pci_pkt; union { @@ -1467,7 +1479,8 @@ static void hv_compose_msi_msg(struct ir return; } =20 - pdev =3D msi_desc_to_pci_dev(irq_data_get_msi_desc(data)); + msi_desc =3D irq_data_get_msi_desc(data); + pdev =3D msi_desc_to_pci_dev(msi_desc); dest =3D irq_data_get_effective_affinity_mask(data); pbus =3D pdev->bus; hbus =3D container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); @@ -1480,6 +1493,36 @@ static void hv_compose_msi_msg(struct ir if (!int_desc) goto drop_reference; =20 + if (!msi_desc->msi_attrib.is_msix && msi_desc->nvec_used > 1) { + /* + * If this is not the first MSI of Multi MSI, we already have + * a mapping. Can exit early. + */ + if (msi_desc->irq !=3D data->irq) { + data->chip_data =3D int_desc; + int_desc->address =3D msi_desc->msg.address_lo | + (u64)msi_desc->msg.address_hi << 32; + int_desc->data =3D msi_desc->msg.data + + (data->irq - msi_desc->irq); + msg->address_hi =3D msi_desc->msg.address_hi; + msg->address_lo =3D msi_desc->msg.address_lo; + msg->data =3D int_desc->data; + put_pcichild(hpdev); + return; + } + /* + * The vector we select here is a dummy value. The correct + * value gets sent to the hypervisor in unmask(). This needs + * to be aligned with the count, and also not zero. Multi-msi + * is powers of 2 up to 32, so 32 will always work here. + */ + vector =3D 32; + vector_count =3D msi_desc->nvec_used; + } else { + vector =3D hv_msi_get_int_vector(data); + vector_count =3D 1; + } + memset(&ctxt, 0, sizeof(ctxt)); init_completion(&comp.comp_pkt.host_event); ctxt.pci_pkt.completion_func =3D hv_pci_compose_compl; @@ -1490,7 +1533,8 @@ static void hv_compose_msi_msg(struct ir size =3D hv_compose_msi_req_v1(&ctxt.int_pkts.v1, dest, hpdev->desc.win_slot.slot, - cfg->vector); + vector, + vector_count); break; =20 case PCI_PROTOCOL_VERSION_1_2: @@ -1498,14 +1542,16 @@ static void hv_compose_msi_msg(struct ir size =3D hv_compose_msi_req_v2(&ctxt.int_pkts.v2, dest, hpdev->desc.win_slot.slot, - cfg->vector); + vector, + vector_count); break; =20 case PCI_PROTOCOL_VERSION_1_4: size =3D hv_compose_msi_req_v3(&ctxt.int_pkts.v3, dest, hpdev->desc.win_slot.slot, - cfg->vector); + vector, + vector_count); break; =20 default: From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30498C04A68 for ; Wed, 27 Jul 2022 17:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232550AbiG0RAR (ORCPT ); Wed, 27 Jul 2022 13:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241260AbiG0Q7V (ORCPT ); Wed, 27 Jul 2022 12:59:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4552067CAF; Wed, 27 Jul 2022 09:37:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 25840B821B6; Wed, 27 Jul 2022 16:37:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AA25C433D6; Wed, 27 Jul 2022 16:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939830; bh=hfbxyf/DUJ3IQqVUNeTv9mC8aZK0OZHI4xKyS0XTpjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p7GEPPuyz47XWza4DJ1OjkR870T7yfBGuy/ClwfHjvxNMpe48bIP5wH+2svNcqKN5 /qXViuAYXNjwFmO95B/jrDJKgApeqJUoXTfI5kcLLq17RCtkA6NXkUPk5tTQfzmpA5 DCN1/eUpMdC+9g/zKWWGs65B19lcErHlJgI0pKNU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH 5.15 014/201] serial: mvebu-uart: correctly report configured baudrate value Date: Wed, 27 Jul 2022 18:08:38 +0200 Message-Id: <20220727161027.512869711@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pali Roh=C3=A1r commit 4f532c1e25319e42996ec18a1f473fd50c8e575d upstream. Functions tty_termios_encode_baud_rate() and uart_update_timeout() should be called with the baudrate value which was set to hardware. Linux then report exact values via ioctl(TCGETS2) to userspace. Change mvebu_uart_baud_rate_set() function to return baudrate value which was set to hardware and propagate this value to above mentioned functions. With this change userspace would see precise value in termios c_ospeed field. Fixes: 68a0db1d7da2 ("serial: mvebu-uart: add function to change baudrate") Cc: stable Reviewed-by: Ilpo J=C3=A4rvinen Signed-off-by: Pali Roh=C3=A1r Link: https://lore.kernel.org/r/20220628100922.10717-1-pali@kernel.org Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/tty/serial/mvebu-uart.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) --- a/drivers/tty/serial/mvebu-uart.c +++ b/drivers/tty/serial/mvebu-uart.c @@ -442,13 +442,13 @@ static void mvebu_uart_shutdown(struct u } } =20 -static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int b= aud) +static unsigned int mvebu_uart_baud_rate_set(struct uart_port *port, unsig= ned int baud) { unsigned int d_divisor, m_divisor; u32 brdv, osamp; =20 if (!port->uartclk) - return -EOPNOTSUPP; + return 0; =20 /* * The baudrate is derived from the UART clock thanks to two divisors: @@ -472,7 +472,7 @@ static int mvebu_uart_baud_rate_set(stru osamp &=3D ~OSAMP_DIVISORS_MASK; writel(osamp, port->membase + UART_OSAMP); =20 - return 0; + return DIV_ROUND_CLOSEST(port->uartclk, d_divisor * m_divisor); } =20 static void mvebu_uart_set_termios(struct uart_port *port, @@ -509,15 +509,11 @@ static void mvebu_uart_set_termios(struc max_baud =3D 230400; =20 baud =3D uart_get_baud_rate(port, termios, old, min_baud, max_baud); - if (mvebu_uart_baud_rate_set(port, baud)) { - /* No clock available, baudrate cannot be changed */ - if (old) - baud =3D uart_get_baud_rate(port, old, NULL, - min_baud, max_baud); - } else { - tty_termios_encode_baud_rate(termios, baud, baud); - uart_update_timeout(port, termios->c_cflag, baud); - } + baud =3D mvebu_uart_baud_rate_set(port, baud); + + /* In case baudrate cannot be changed, report previous old value */ + if (baud =3D=3D 0 && old) + baud =3D tty_termios_baud_rate(old); =20 /* Only the following flag changes are supported */ if (old) { @@ -528,6 +524,11 @@ static void mvebu_uart_set_termios(struc termios->c_cflag |=3D CS8; } =20 + if (baud !=3D 0) { + tty_termios_encode_baud_rate(termios, baud, baud); + uart_update_timeout(port, termios->c_cflag, baud); + } + spin_unlock_irqrestore(&port->lock, flags); } =20 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 775A1C04A68 for ; Wed, 27 Jul 2022 17:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241150AbiG0RBN (ORCPT ); Wed, 27 Jul 2022 13:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241237AbiG0Q7S (ORCPT ); Wed, 27 Jul 2022 12:59:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7875967CA2; Wed, 27 Jul 2022 09:37:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E9728B821B9; Wed, 27 Jul 2022 16:37:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45CE6C433D6; Wed, 27 Jul 2022 16:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939833; bh=A+9qkfHI1uzPf8aIiO4/BScgVXhICqsdEbBGCMa+qkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OISQhVI9APaO4FoPugu/gumDlxhqJIATAAmg8nDKTaHlq5R4HNhj0VXfK2OSqUfcn AUqJw2h8wKMBX8L7qPKWONXtE4IpJ2A0JJbKfVvtlhRc27CV6TTpuK7odyVFx52+Qr 0N1mJlzLbnohMWrto4BkADS7mH7Roh8sHrKEu7U8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sebastian Andrzej Siewior Subject: [PATCH 5.15 015/201] batman-adv: Use netif_rx_any_context() any. Date: Wed, 27 Jul 2022 18:08:39 +0200 Message-Id: <20220727161027.554866834@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sebastian Andrzej Siewior This reverts the stable commit e65d78b12fbc0 ("batman-adv: Use netif_rx().") The commit message says: | Since commit | baebdf48c3600 ("net: dev: Makes sure netif_rx() can be invoked in any = context.") | | the function netif_rx() can be used in preemptible/thread context as | well as in interrupt context. This commit (baebdf48c3600) has not been backported to the 5.15 stable series and therefore, the commit which builds upon it, must not be backported either. Revert the backport and use netif_rx_any_context() again. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/batman-adv/bridge_loop_avoidance.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -443,7 +443,7 @@ static void batadv_bla_send_claim(struct batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES, skb->len + ETH_HLEN); =20 - netif_rx(skb); + netif_rx_any_context(skb); out: batadv_hardif_put(primary_if); } From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7E91C19F28 for ; Wed, 27 Jul 2022 17:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241051AbiG0RAY (ORCPT ); Wed, 27 Jul 2022 13:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241278AbiG0Q7Y (ORCPT ); Wed, 27 Jul 2022 12:59:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 973AB56BAB; Wed, 27 Jul 2022 09:37:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BBC01B821C6; Wed, 27 Jul 2022 16:37:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29CA4C433C1; Wed, 27 Jul 2022 16:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939836; bh=b50X13tPwRaIQrRXxckQEC9kAycAWKdZsivSy60YEyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j5tGmjnwvdYJQQraQGH4ZX8yEFpMlK7EubqV3BRj798qLgcXgl8OsbcWGPdEB4nae yISnU3BPLWZvTjXhyjChao3p6819MXLpr0ou+gOt+R+zOzBWI2D9iS4OOCL2NMimnB WDy/hgs7QEYNH9mKzY37QW0lxKZcNWS3/X3k5qug= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Sean Wang" , Sean Wang Subject: [PATCH 5.15 016/201] Revert "mt76: mt7921: Fix the error handling path of mt7921_pci_probe()" Date: Wed, 27 Jul 2022 18:08:40 +0200 Message-Id: <20220727161027.585937125@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sean Wang This reverts commit 663457f421d41e9d2fcb1e84baf43d1433f80c08 that is the commit 44c4237cf3436bda2b185ff728123651ad133f69 upstream. Because there was mistake in '649178c0493e ("mt76: mt7921e: fix possible probe failure after reboot")' that caused WiFi reset cannot work well as the reported issue "PROBLEM: [Stable v5.15.42+] [mt7921] Wake after suspend locks up system when mt7921-driver is used on a Lenovo ThinkPad E15 G3" described in http://lists.infradead.org/pipermail/linux-mediatek/2022-June/042668.html So we need to revert the patch first to avoid the conflict of reverting '649178c0493e ("mt76: mt7921e: fix possible probe failure after reboot")' and will be applied back later after fixing. Signed-off-by: Sean Wang Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -254,10 +254,8 @@ static int mt7921_pci_probe(struct pci_d dev->bus_ops =3D dev->mt76.bus; bus_ops =3D devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), GFP_KERNEL); - if (!bus_ops) { - ret =3D -ENOMEM; - goto err_free_dev; - } + if (!bus_ops) + return -ENOMEM; =20 bus_ops->rr =3D mt7921_rr; bus_ops->wr =3D mt7921_wr; @@ -266,7 +264,7 @@ static int mt7921_pci_probe(struct pci_d =20 ret =3D __mt7921_mcu_drv_pmctrl(dev); if (ret) - goto err_free_dev; + return ret; =20 mdev->rev =3D (mt7921_l1_rr(dev, MT_HW_CHIPID) << 16) | (mt7921_l1_rr(dev, MT_HW_REV) & 0xff); From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9E7EC04A68 for ; Wed, 27 Jul 2022 17:01:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232876AbiG0RBS (ORCPT ); Wed, 27 Jul 2022 13:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241309AbiG0Q72 (ORCPT ); Wed, 27 Jul 2022 12:59:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE41368DD8; Wed, 27 Jul 2022 09:37:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 85377B821CB; Wed, 27 Jul 2022 16:37:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4A97C433B5; Wed, 27 Jul 2022 16:37:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939839; bh=dn8ZAqGjBauFKEy5Hv58FqR37Pcs2CW1cj02eXOIhOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDhxCj2Y491em7DQ7ZtzP/+JCLIFnAaxJFaifvhu70c0Xh6i40yyxsnT7V9RfcA3w kF2g0yT7Z0y3lKR1sy9PxlcD26YYdPwjW/l3uRk85ioidcYaLoDiaxli7XhDXNkC74 PWdvZOc6boz6j8k0bEnDR8PxF65wXQy6bx7v+c6k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Sean Wang" , Sean Wang Subject: [PATCH 5.15 017/201] Revert "mt76: mt7921e: fix possible probe failure after reboot" Date: Wed, 27 Jul 2022 18:08:41 +0200 Message-Id: <20220727161027.624512400@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sean Wang This reverts commit 649178c0493e4080b2b226b0ef9fa2d834b1b412 that is the commit 602cc0c9618a819ab00ea3c9400742a0ca318380 upstream. Because there was mistake in '649178c0493e ("mt76: mt7921e: fix possible probe failure after reboot")' that caused WiFi reset cannot work well as the reported issue "PROBLEM: [Stable v5.15.42+] [mt7921] Wake after suspend locks up system when mt7921-driver is used on a Lenovo ThinkPad E15 G3" described in http://lists.infradead.org/pipermail/linux-mediatek/2022-June/042668.html So, we need to revert it before fixing and landing it again on the stable tree from upstream. Signed-off-by: Sean Wang Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/wireless/mediatek/mt76/mt7921/dma.c | 115 +++++++++++++++++++= +++ drivers/net/wireless/mediatek/mt76/mt7921/mcu.c | 20 +-- drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 121 -------------------= ----- 3 files changed, 125 insertions(+), 131 deletions(-) --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c @@ -118,6 +118,109 @@ static void mt7921_dma_prefetch(struct m mt76_wr(dev, MT_WFDMA0_TX_RING17_EXT_CTRL, PREFETCH(0x380, 0x4)); } =20 +static u32 __mt7921_reg_addr(struct mt7921_dev *dev, u32 addr) +{ + static const struct { + u32 phys; + u32 mapped; + u32 size; + } fixed_map[] =3D { + { 0x00400000, 0x80000, 0x10000}, /* WF_MCU_SYSRAM */ + { 0x00410000, 0x90000, 0x10000}, /* WF_MCU_SYSRAM (configure register) */ + { 0x40000000, 0x70000, 0x10000}, /* WF_UMAC_SYSRAM */ + { 0x54000000, 0x02000, 0x1000 }, /* WFDMA PCIE0 MCU DMA0 */ + { 0x55000000, 0x03000, 0x1000 }, /* WFDMA PCIE0 MCU DMA1 */ + { 0x58000000, 0x06000, 0x1000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */ + { 0x59000000, 0x07000, 0x1000 }, /* WFDMA PCIE1 MCU DMA1 */ + { 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */ + { 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */ + { 0x7c060000, 0xe0000, 0x10000}, /* CONN_INFRA, conn_host_csr_top */ + { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */ + { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */ + { 0x820c0000, 0x08000, 0x4000 }, /* WF_UMAC_TOP (PLE) */ + { 0x820c8000, 0x0c000, 0x2000 }, /* WF_UMAC_TOP (PSE) */ + { 0x820cc000, 0x0e000, 0x2000 }, /* WF_UMAC_TOP (PP) */ + { 0x820ce000, 0x21c00, 0x0200 }, /* WF_LMAC_TOP (WF_SEC) */ + { 0x820cf000, 0x22000, 0x1000 }, /* WF_LMAC_TOP (WF_PF) */ + { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ + { 0x820e0000, 0x20000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ + { 0x820e1000, 0x20400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ + { 0x820e2000, 0x20800, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ + { 0x820e3000, 0x20c00, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ + { 0x820e4000, 0x21000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ + { 0x820e5000, 0x21400, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ + { 0x820e7000, 0x21e00, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ + { 0x820e9000, 0x23400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ + { 0x820ea000, 0x24000, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ + { 0x820eb000, 0x24200, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ + { 0x820ec000, 0x24600, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ + { 0x820ed000, 0x24800, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ + { 0x820f0000, 0xa0000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ + { 0x820f1000, 0xa0600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ + { 0x820f2000, 0xa0800, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ + { 0x820f3000, 0xa0c00, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */ + { 0x820f4000, 0xa1000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */ + { 0x820f5000, 0xa1400, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */ + { 0x820f7000, 0xa1e00, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */ + { 0x820f9000, 0xa3400, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ + { 0x820fa000, 0xa4000, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */ + { 0x820fb000, 0xa4200, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */ + { 0x820fc000, 0xa4600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_INT) */ + { 0x820fd000, 0xa4800, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */ + }; + int i; + + if (addr < 0x100000) + return addr; + + for (i =3D 0; i < ARRAY_SIZE(fixed_map); i++) { + u32 ofs; + + if (addr < fixed_map[i].phys) + continue; + + ofs =3D addr - fixed_map[i].phys; + if (ofs > fixed_map[i].size) + continue; + + return fixed_map[i].mapped + ofs; + } + + if ((addr >=3D 0x18000000 && addr < 0x18c00000) || + (addr >=3D 0x70000000 && addr < 0x78000000) || + (addr >=3D 0x7c000000 && addr < 0x7c400000)) + return mt7921_reg_map_l1(dev, addr); + + dev_err(dev->mt76.dev, "Access currently unsupported address %08x\n", + addr); + + return 0; +} + +static u32 mt7921_rr(struct mt76_dev *mdev, u32 offset) +{ + struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); + u32 addr =3D __mt7921_reg_addr(dev, offset); + + return dev->bus_ops->rr(mdev, addr); +} + +static void mt7921_wr(struct mt76_dev *mdev, u32 offset, u32 val) +{ + struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); + u32 addr =3D __mt7921_reg_addr(dev, offset); + + dev->bus_ops->wr(mdev, addr, val); +} + +static u32 mt7921_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) +{ + struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); + u32 addr =3D __mt7921_reg_addr(dev, offset); + + return dev->bus_ops->rmw(mdev, addr, mask, val); +} + static int mt7921_dma_disable(struct mt7921_dev *dev, bool force) { if (force) { @@ -277,8 +380,20 @@ int mt7921_wpdma_reinit_cond(struct mt79 =20 int mt7921_dma_init(struct mt7921_dev *dev) { + struct mt76_bus_ops *bus_ops; int ret; =20 + dev->bus_ops =3D dev->mt76.bus; + bus_ops =3D devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), + GFP_KERNEL); + if (!bus_ops) + return -ENOMEM; + + bus_ops->rr =3D mt7921_rr; + bus_ops->wr =3D mt7921_wr; + bus_ops->rmw =3D mt7921_rmw; + dev->mt76.bus =3D bus_ops; + mt76_dma_attach(&dev->mt76); =20 ret =3D mt7921_dma_disable(dev, true); --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c @@ -1308,6 +1308,8 @@ int mt7921_mcu_sta_update(struct mt7921_ =20 int __mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev) { + struct mt76_phy *mphy =3D &dev->mt76.phy; + struct mt76_connac_pm *pm =3D &dev->pm; int i, err =3D 0; =20 for (i =3D 0; i < MT7921_DRV_OWN_RETRY_COUNT; i++) { @@ -1320,8 +1322,16 @@ int __mt7921_mcu_drv_pmctrl(struct mt792 if (i =3D=3D MT7921_DRV_OWN_RETRY_COUNT) { dev_err(dev->mt76.dev, "driver own failed\n"); err =3D -EIO; + goto out; } =20 + mt7921_wpdma_reinit_cond(dev); + clear_bit(MT76_STATE_PM, &mphy->state); + + pm->stats.last_wake_event =3D jiffies; + pm->stats.doze_time +=3D pm->stats.last_wake_event - + pm->stats.last_doze_event; +out: return err; } =20 @@ -1337,16 +1347,6 @@ int mt7921_mcu_drv_pmctrl(struct mt7921_ goto out; =20 err =3D __mt7921_mcu_drv_pmctrl(dev); - if (err < 0) - goto out; - - mt7921_wpdma_reinit_cond(dev); - clear_bit(MT76_STATE_PM, &mphy->state); - - pm->stats.last_wake_event =3D jiffies; - pm->stats.doze_time +=3D pm->stats.last_wake_event - - pm->stats.last_doze_event; - out: mutex_unlock(&pm->mutex); =20 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -88,110 +88,6 @@ static void mt7921_irq_tasklet(unsigned napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN]); } =20 -static u32 __mt7921_reg_addr(struct mt7921_dev *dev, u32 addr) -{ - static const struct { - u32 phys; - u32 mapped; - u32 size; - } fixed_map[] =3D { - { 0x00400000, 0x80000, 0x10000}, /* WF_MCU_SYSRAM */ - { 0x00410000, 0x90000, 0x10000}, /* WF_MCU_SYSRAM (configure register) */ - { 0x40000000, 0x70000, 0x10000}, /* WF_UMAC_SYSRAM */ - { 0x54000000, 0x02000, 0x1000 }, /* WFDMA PCIE0 MCU DMA0 */ - { 0x55000000, 0x03000, 0x1000 }, /* WFDMA PCIE0 MCU DMA1 */ - { 0x58000000, 0x06000, 0x1000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */ - { 0x59000000, 0x07000, 0x1000 }, /* WFDMA PCIE1 MCU DMA1 */ - { 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */ - { 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */ - { 0x7c060000, 0xe0000, 0x10000}, /* CONN_INFRA, conn_host_csr_top */ - { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */ - { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */ - { 0x820c0000, 0x08000, 0x4000 }, /* WF_UMAC_TOP (PLE) */ - { 0x820c8000, 0x0c000, 0x2000 }, /* WF_UMAC_TOP (PSE) */ - { 0x820cc000, 0x0e000, 0x2000 }, /* WF_UMAC_TOP (PP) */ - { 0x820ce000, 0x21c00, 0x0200 }, /* WF_LMAC_TOP (WF_SEC) */ - { 0x820cf000, 0x22000, 0x1000 }, /* WF_LMAC_TOP (WF_PF) */ - { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ - { 0x820e0000, 0x20000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ - { 0x820e1000, 0x20400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ - { 0x820e2000, 0x20800, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ - { 0x820e3000, 0x20c00, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ - { 0x820e4000, 0x21000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ - { 0x820e5000, 0x21400, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ - { 0x820e7000, 0x21e00, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ - { 0x820e9000, 0x23400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ - { 0x820ea000, 0x24000, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ - { 0x820eb000, 0x24200, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ - { 0x820ec000, 0x24600, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ - { 0x820ed000, 0x24800, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ - { 0x820f0000, 0xa0000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ - { 0x820f1000, 0xa0600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ - { 0x820f2000, 0xa0800, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ - { 0x820f3000, 0xa0c00, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */ - { 0x820f4000, 0xa1000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */ - { 0x820f5000, 0xa1400, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */ - { 0x820f7000, 0xa1e00, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */ - { 0x820f9000, 0xa3400, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ - { 0x820fa000, 0xa4000, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */ - { 0x820fb000, 0xa4200, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */ - { 0x820fc000, 0xa4600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_INT) */ - { 0x820fd000, 0xa4800, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */ - }; - int i; - - if (addr < 0x100000) - return addr; - - for (i =3D 0; i < ARRAY_SIZE(fixed_map); i++) { - u32 ofs; - - if (addr < fixed_map[i].phys) - continue; - - ofs =3D addr - fixed_map[i].phys; - if (ofs > fixed_map[i].size) - continue; - - return fixed_map[i].mapped + ofs; - } - - if ((addr >=3D 0x18000000 && addr < 0x18c00000) || - (addr >=3D 0x70000000 && addr < 0x78000000) || - (addr >=3D 0x7c000000 && addr < 0x7c400000)) - return mt7921_reg_map_l1(dev, addr); - - dev_err(dev->mt76.dev, "Access currently unsupported address %08x\n", - addr); - - return 0; -} - -static u32 mt7921_rr(struct mt76_dev *mdev, u32 offset) -{ - struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); - u32 addr =3D __mt7921_reg_addr(dev, offset); - - return dev->bus_ops->rr(mdev, addr); -} - -static void mt7921_wr(struct mt76_dev *mdev, u32 offset, u32 val) -{ - struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); - u32 addr =3D __mt7921_reg_addr(dev, offset); - - dev->bus_ops->wr(mdev, addr, val); -} - -static u32 mt7921_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) -{ - struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); - u32 addr =3D __mt7921_reg_addr(dev, offset); - - return dev->bus_ops->rmw(mdev, addr, mask, val); -} - - static int mt7921_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -214,7 +110,6 @@ static int mt7921_pci_probe(struct pci_d .sta_remove =3D mt7921_mac_sta_remove, .update_survey =3D mt7921_update_channel, }; - struct mt76_bus_ops *bus_ops; struct mt7921_dev *dev; struct mt76_dev *mdev; int ret; @@ -250,22 +145,6 @@ static int mt7921_pci_probe(struct pci_d =20 mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]); tasklet_init(&dev->irq_tasklet, mt7921_irq_tasklet, (unsigned long)dev); - - dev->bus_ops =3D dev->mt76.bus; - bus_ops =3D devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), - GFP_KERNEL); - if (!bus_ops) - return -ENOMEM; - - bus_ops->rr =3D mt7921_rr; - bus_ops->wr =3D mt7921_wr; - bus_ops->rmw =3D mt7921_rmw; - dev->mt76.bus =3D bus_ops; - - ret =3D __mt7921_mcu_drv_pmctrl(dev); - if (ret) - return ret; - mdev->rev =3D (mt7921_l1_rr(dev, MT_HW_CHIPID) << 16) | (mt7921_l1_rr(dev, MT_HW_REV) & 0xff); dev_err(mdev->dev, "ASIC revision: %04x\n", mdev->rev); From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB340C04A68 for ; Wed, 27 Jul 2022 17:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240269AbiG0RPJ (ORCPT ); Wed, 27 Jul 2022 13:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239962AbiG0ROD (ORCPT ); Wed, 27 Jul 2022 13:14:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257215B782; Wed, 27 Jul 2022 09:42:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B9A70600BE; Wed, 27 Jul 2022 16:37:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A0BDC433D7; Wed, 27 Jul 2022 16:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939842; bh=/gnLGNBCQtU5nsVMtZ2c0IAQvO/MXOZbfG3A4EoszBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/PQMy43CaO+vyVuzRIrVUmQWcASz8La4k4XFO4fxztGWSvdkw/p67RThx6klvxV2 dwfVZTYVNIth9WODzlDEj1uXxLmoxPhFFTvLh3alw7ev3OkqtyHG57Cd9SsREZrv4n Jpk8HU/EA9VwNuxLGq2WQFOSKlaA2AlOTg/fc+fI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Deren Wu , Lorenzo Bianconi , Sean Wang , Felix Fietkau Subject: [PATCH 5.15 018/201] mt76: mt7921: use physical addr to unify register access Date: Wed, 27 Jul 2022 18:08:42 +0200 Message-Id: <20220727161027.663437430@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sean Wang commit f1e2eef111018a4f0d280656be4351c37e9e554b upstream. Use physical address to unify the register access and reorder the entries in fixed_map table to accelerate the address lookup for MT7921e. Cosmetics the patch with adding an extra space to make all entries in the array style consistent. Tested-by: Deren Wu Acked-by: Lorenzo Bianconi Signed-off-by: Sean Wang Signed-off-by: Felix Fietkau Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/wireless/mediatek/mt76/mt7921/dma.c | 27 +++++++++++-------= ----- drivers/net/wireless/mediatek/mt76/mt7921/regs.h | 22 +++++++++--------- 2 files changed, 25 insertions(+), 24 deletions(-) --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c @@ -125,36 +125,37 @@ static u32 __mt7921_reg_addr(struct mt79 u32 mapped; u32 size; } fixed_map[] =3D { - { 0x00400000, 0x80000, 0x10000}, /* WF_MCU_SYSRAM */ - { 0x00410000, 0x90000, 0x10000}, /* WF_MCU_SYSRAM (configure register) */ - { 0x40000000, 0x70000, 0x10000}, /* WF_UMAC_SYSRAM */ + { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ + { 0x820ed000, 0x24800, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ + { 0x820e4000, 0x21000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ + { 0x820e7000, 0x21e00, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ + { 0x820eb000, 0x24200, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ + { 0x820e2000, 0x20800, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ + { 0x820e3000, 0x20c00, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ + { 0x820e5000, 0x21400, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ + { 0x00400000, 0x80000, 0x10000 }, /* WF_MCU_SYSRAM */ + { 0x00410000, 0x90000, 0x10000 }, /* WF_MCU_SYSRAM (configure register) = */ + { 0x40000000, 0x70000, 0x10000 }, /* WF_UMAC_SYSRAM */ { 0x54000000, 0x02000, 0x1000 }, /* WFDMA PCIE0 MCU DMA0 */ { 0x55000000, 0x03000, 0x1000 }, /* WFDMA PCIE0 MCU DMA1 */ { 0x58000000, 0x06000, 0x1000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */ { 0x59000000, 0x07000, 0x1000 }, /* WFDMA PCIE1 MCU DMA1 */ { 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */ { 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */ - { 0x7c060000, 0xe0000, 0x10000}, /* CONN_INFRA, conn_host_csr_top */ + { 0x7c060000, 0xe0000, 0x10000 }, /* CONN_INFRA, conn_host_csr_top */ { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */ { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */ { 0x820c0000, 0x08000, 0x4000 }, /* WF_UMAC_TOP (PLE) */ { 0x820c8000, 0x0c000, 0x2000 }, /* WF_UMAC_TOP (PSE) */ - { 0x820cc000, 0x0e000, 0x2000 }, /* WF_UMAC_TOP (PP) */ + { 0x820cc000, 0x0e000, 0x1000 }, /* WF_UMAC_TOP (PP) */ + { 0x820cd000, 0x0f000, 0x1000 }, /* WF_MDP_TOP */ { 0x820ce000, 0x21c00, 0x0200 }, /* WF_LMAC_TOP (WF_SEC) */ { 0x820cf000, 0x22000, 0x1000 }, /* WF_LMAC_TOP (WF_PF) */ - { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ { 0x820e0000, 0x20000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ { 0x820e1000, 0x20400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ - { 0x820e2000, 0x20800, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ - { 0x820e3000, 0x20c00, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ - { 0x820e4000, 0x21000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ - { 0x820e5000, 0x21400, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ - { 0x820e7000, 0x21e00, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ { 0x820e9000, 0x23400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ { 0x820ea000, 0x24000, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ - { 0x820eb000, 0x24200, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ { 0x820ec000, 0x24600, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ - { 0x820ed000, 0x24800, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ { 0x820f0000, 0xa0000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ { 0x820f1000, 0xa0600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ { 0x820f2000, 0xa0800, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ --- a/drivers/net/wireless/mediatek/mt76/mt7921/regs.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/regs.h @@ -14,7 +14,7 @@ #define MT_MCU_INT_EVENT_SER_TRIGGER BIT(2) #define MT_MCU_INT_EVENT_RESET_DONE BIT(3) =20 -#define MT_PLE_BASE 0x8000 +#define MT_PLE_BASE 0x820c0000 #define MT_PLE(ofs) (MT_PLE_BASE + (ofs)) =20 #define MT_PLE_FL_Q0_CTRL MT_PLE(0x3e0) @@ -25,7 +25,7 @@ #define MT_PLE_AC_QEMPTY(_n) MT_PLE(0x500 + 0x40 * (_n)) #define MT_PLE_AMSDU_PACK_MSDU_CNT(n) MT_PLE(0x10e0 + ((n) << 2)) =20 -#define MT_MDP_BASE 0xf000 +#define MT_MDP_BASE 0x820cd000 #define MT_MDP(ofs) (MT_MDP_BASE + (ofs)) =20 #define MT_MDP_DCR0 MT_MDP(0x000) @@ -48,7 +48,7 @@ #define MT_MDP_TO_WM 1 =20 /* TMAC: band 0(0x21000), band 1(0xa1000) */ -#define MT_WF_TMAC_BASE(_band) ((_band) ? 0xa1000 : 0x21000) +#define MT_WF_TMAC_BASE(_band) ((_band) ? 0x820f4000 : 0x820e4000) #define MT_WF_TMAC(_band, ofs) (MT_WF_TMAC_BASE(_band) + (ofs)) =20 #define MT_TMAC_TCR0(_band) MT_WF_TMAC(_band, 0) @@ -73,7 +73,7 @@ #define MT_TMAC_TRCR0(_band) MT_WF_TMAC(_band, 0x09c) #define MT_TMAC_TFCR0(_band) MT_WF_TMAC(_band, 0x1e0) =20 -#define MT_WF_DMA_BASE(_band) ((_band) ? 0xa1e00 : 0x21e00) +#define MT_WF_DMA_BASE(_band) ((_band) ? 0x820f7000 : 0x820e7000) #define MT_WF_DMA(_band, ofs) (MT_WF_DMA_BASE(_band) + (ofs)) =20 #define MT_DMA_DCR0(_band) MT_WF_DMA(_band, 0x000) @@ -81,7 +81,7 @@ #define MT_DMA_DCR0_RXD_G5_EN BIT(23) =20 /* LPON: band 0(0x24200), band 1(0xa4200) */ -#define MT_WF_LPON_BASE(_band) ((_band) ? 0xa4200 : 0x24200) +#define MT_WF_LPON_BASE(_band) ((_band) ? 0x820fb000 : 0x820eb000) #define MT_WF_LPON(_band, ofs) (MT_WF_LPON_BASE(_band) + (ofs)) =20 #define MT_LPON_UTTR0(_band) MT_WF_LPON(_band, 0x080) @@ -92,7 +92,7 @@ #define MT_LPON_TCR_SW_WRITE BIT(0) =20 /* MIB: band 0(0x24800), band 1(0xa4800) */ -#define MT_WF_MIB_BASE(_band) ((_band) ? 0xa4800 : 0x24800) +#define MT_WF_MIB_BASE(_band) ((_band) ? 0x820fd000 : 0x820ed000) #define MT_WF_MIB(_band, ofs) (MT_WF_MIB_BASE(_band) + (ofs)) =20 #define MT_MIB_SCR1(_band) MT_WF_MIB(_band, 0x004) @@ -141,7 +141,7 @@ #define MT_MIB_ARNG(_band, n) MT_WF_MIB(_band, 0x0b0 + ((n) << 2)) #define MT_MIB_ARNCR_RANGE(val, n) (((val) >> ((n) << 3)) & GENMASK(7, 0)) =20 -#define MT_WTBLON_TOP_BASE 0x34000 +#define MT_WTBLON_TOP_BASE 0x820d4000 #define MT_WTBLON_TOP(ofs) (MT_WTBLON_TOP_BASE + (ofs)) #define MT_WTBLON_TOP_WDUCR MT_WTBLON_TOP(0x200) #define MT_WTBLON_TOP_WDUCR_GROUP GENMASK(2, 0) @@ -151,7 +151,7 @@ #define MT_WTBL_UPDATE_ADM_COUNT_CLEAR BIT(12) #define MT_WTBL_UPDATE_BUSY BIT(31) =20 -#define MT_WTBL_BASE 0x38000 +#define MT_WTBL_BASE 0x820d8000 #define MT_WTBL_LMAC_ID GENMASK(14, 8) #define MT_WTBL_LMAC_DW GENMASK(7, 2) #define MT_WTBL_LMAC_OFFS(_id, _dw) (MT_WTBL_BASE | \ @@ -159,7 +159,7 @@ FIELD_PREP(MT_WTBL_LMAC_DW, _dw)) =20 /* AGG: band 0(0x20800), band 1(0xa0800) */ -#define MT_WF_AGG_BASE(_band) ((_band) ? 0xa0800 : 0x20800) +#define MT_WF_AGG_BASE(_band) ((_band) ? 0x820f2000 : 0x820e2000) #define MT_WF_AGG(_band, ofs) (MT_WF_AGG_BASE(_band) + (ofs)) =20 #define MT_AGG_AWSCR0(_band, _n) MT_WF_AGG(_band, 0x05c + (_n) * 4) @@ -190,7 +190,7 @@ #define MT_AGG_ATCR3(_band) MT_WF_AGG(_band, 0x0f4) =20 /* ARB: band 0(0x20c00), band 1(0xa0c00) */ -#define MT_WF_ARB_BASE(_band) ((_band) ? 0xa0c00 : 0x20c00) +#define MT_WF_ARB_BASE(_band) ((_band) ? 0x820f3000 : 0x820e3000) #define MT_WF_ARB(_band, ofs) (MT_WF_ARB_BASE(_band) + (ofs)) =20 #define MT_ARB_SCR(_band) MT_WF_ARB(_band, 0x080) @@ -200,7 +200,7 @@ #define MT_ARB_DRNGR0(_band, _n) MT_WF_ARB(_band, 0x194 + (_n) * 4) =20 /* RMAC: band 0(0x21400), band 1(0xa1400) */ -#define MT_WF_RMAC_BASE(_band) ((_band) ? 0xa1400 : 0x21400) +#define MT_WF_RMAC_BASE(_band) ((_band) ? 0x820f5000 : 0x820e5000) #define MT_WF_RMAC(_band, ofs) (MT_WF_RMAC_BASE(_band) + (ofs)) =20 #define MT_WF_RFCR(_band) MT_WF_RMAC(_band, 0x000) From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72B52C04A68 for ; Wed, 27 Jul 2022 17:00:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241166AbiG0RAf (ORCPT ); Wed, 27 Jul 2022 13:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241346AbiG0Q7c (ORCPT ); Wed, 27 Jul 2022 12:59:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94F2568DF5; Wed, 27 Jul 2022 09:37:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 46BA7B821D0; Wed, 27 Jul 2022 16:37:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94D4BC433D6; Wed, 27 Jul 2022 16:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939845; bh=BP4OMKVsOePY1i69JQhtu/Fb3lc9mK8sI72IZCqljyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGfJdT//P8svQ/ICRnpNr7b154AaBXEMVUh5HqF+ZJiaWJnZI92i3i2lcqfhIQYQ9 Br2WEOlA1JFdDTuhFpgADu9G0KWYFsld3dWy+AhGjxbmpE97ac3+2Tjqur2KUX4sHt 1ze1oDT97bhib2ah1kxr6cUX9o7HtGIUjzWibADY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Kai-Chuan Hsieh , Deren Wu , Sean Wang , Felix Fietkau Subject: [PATCH 5.15 019/201] mt76: mt7921e: fix possible probe failure after reboot Date: Wed, 27 Jul 2022 18:08:43 +0200 Message-Id: <20220727161027.707488510@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sean Wang commit 602cc0c9618a819ab00ea3c9400742a0ca318380 upstream. It doesn't guarantee the mt7921e gets started with ASPM L0 after each machine reboot on every platform. If mt7921e gets started with not ASPM L0, it would be possible that the driver encounters time to time failure in mt7921_pci_probe, like a weird chip identifier is read [ 215.514503] mt7921e 0000:05:00.0: ASIC revision: feed0000 [ 216.604741] mt7921e: probe of 0000:05:00.0 failed with error -110 or failing to init hardware because the driver is not allowed to access the register until the device is in ASPM L0 state. So, we call __mt7921e_mcu_drv_pmctrl in early mt7921_pci_probe to force the device to bring back to the L0 state for we can safely access registers in any case. In the patch, we move all functions from dma.c to pci.c and register mt76 bus operation earilier, that is the __mt7921e_mcu_drv_pmctrl depends on. Fixes: bf3747ae2e25 ("mt76: mt7921: enable aspm by default") Reported-by: Kai-Chuan Hsieh Co-developed-by: Deren Wu Signed-off-by: Deren Wu Signed-off-by: Sean Wang Signed-off-by: Felix Fietkau Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/wireless/mediatek/mt76/mt7921/dma.c | 116 ----------------= ---- drivers/net/wireless/mediatek/mt76/mt7921/mcu.c | 18 ++- drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h | 1=20 drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 121 ++++++++++++++++= +++++ 4 files changed, 136 insertions(+), 120 deletions(-) --- a/drivers/net/wireless/mediatek/mt76/mt7921/dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/dma.c @@ -118,110 +118,6 @@ static void mt7921_dma_prefetch(struct m mt76_wr(dev, MT_WFDMA0_TX_RING17_EXT_CTRL, PREFETCH(0x380, 0x4)); } =20 -static u32 __mt7921_reg_addr(struct mt7921_dev *dev, u32 addr) -{ - static const struct { - u32 phys; - u32 mapped; - u32 size; - } fixed_map[] =3D { - { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ - { 0x820ed000, 0x24800, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ - { 0x820e4000, 0x21000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ - { 0x820e7000, 0x21e00, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ - { 0x820eb000, 0x24200, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ - { 0x820e2000, 0x20800, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ - { 0x820e3000, 0x20c00, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ - { 0x820e5000, 0x21400, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ - { 0x00400000, 0x80000, 0x10000 }, /* WF_MCU_SYSRAM */ - { 0x00410000, 0x90000, 0x10000 }, /* WF_MCU_SYSRAM (configure register) = */ - { 0x40000000, 0x70000, 0x10000 }, /* WF_UMAC_SYSRAM */ - { 0x54000000, 0x02000, 0x1000 }, /* WFDMA PCIE0 MCU DMA0 */ - { 0x55000000, 0x03000, 0x1000 }, /* WFDMA PCIE0 MCU DMA1 */ - { 0x58000000, 0x06000, 0x1000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */ - { 0x59000000, 0x07000, 0x1000 }, /* WFDMA PCIE1 MCU DMA1 */ - { 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */ - { 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */ - { 0x7c060000, 0xe0000, 0x10000 }, /* CONN_INFRA, conn_host_csr_top */ - { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */ - { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */ - { 0x820c0000, 0x08000, 0x4000 }, /* WF_UMAC_TOP (PLE) */ - { 0x820c8000, 0x0c000, 0x2000 }, /* WF_UMAC_TOP (PSE) */ - { 0x820cc000, 0x0e000, 0x1000 }, /* WF_UMAC_TOP (PP) */ - { 0x820cd000, 0x0f000, 0x1000 }, /* WF_MDP_TOP */ - { 0x820ce000, 0x21c00, 0x0200 }, /* WF_LMAC_TOP (WF_SEC) */ - { 0x820cf000, 0x22000, 0x1000 }, /* WF_LMAC_TOP (WF_PF) */ - { 0x820e0000, 0x20000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ - { 0x820e1000, 0x20400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ - { 0x820e9000, 0x23400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ - { 0x820ea000, 0x24000, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ - { 0x820ec000, 0x24600, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ - { 0x820f0000, 0xa0000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ - { 0x820f1000, 0xa0600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ - { 0x820f2000, 0xa0800, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ - { 0x820f3000, 0xa0c00, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */ - { 0x820f4000, 0xa1000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */ - { 0x820f5000, 0xa1400, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */ - { 0x820f7000, 0xa1e00, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */ - { 0x820f9000, 0xa3400, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ - { 0x820fa000, 0xa4000, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */ - { 0x820fb000, 0xa4200, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */ - { 0x820fc000, 0xa4600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_INT) */ - { 0x820fd000, 0xa4800, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */ - }; - int i; - - if (addr < 0x100000) - return addr; - - for (i =3D 0; i < ARRAY_SIZE(fixed_map); i++) { - u32 ofs; - - if (addr < fixed_map[i].phys) - continue; - - ofs =3D addr - fixed_map[i].phys; - if (ofs > fixed_map[i].size) - continue; - - return fixed_map[i].mapped + ofs; - } - - if ((addr >=3D 0x18000000 && addr < 0x18c00000) || - (addr >=3D 0x70000000 && addr < 0x78000000) || - (addr >=3D 0x7c000000 && addr < 0x7c400000)) - return mt7921_reg_map_l1(dev, addr); - - dev_err(dev->mt76.dev, "Access currently unsupported address %08x\n", - addr); - - return 0; -} - -static u32 mt7921_rr(struct mt76_dev *mdev, u32 offset) -{ - struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); - u32 addr =3D __mt7921_reg_addr(dev, offset); - - return dev->bus_ops->rr(mdev, addr); -} - -static void mt7921_wr(struct mt76_dev *mdev, u32 offset, u32 val) -{ - struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); - u32 addr =3D __mt7921_reg_addr(dev, offset); - - dev->bus_ops->wr(mdev, addr, val); -} - -static u32 mt7921_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) -{ - struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); - u32 addr =3D __mt7921_reg_addr(dev, offset); - - return dev->bus_ops->rmw(mdev, addr, mask, val); -} - static int mt7921_dma_disable(struct mt7921_dev *dev, bool force) { if (force) { @@ -381,20 +277,8 @@ int mt7921_wpdma_reinit_cond(struct mt79 =20 int mt7921_dma_init(struct mt7921_dev *dev) { - struct mt76_bus_ops *bus_ops; int ret; =20 - dev->bus_ops =3D dev->mt76.bus; - bus_ops =3D devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), - GFP_KERNEL); - if (!bus_ops) - return -ENOMEM; - - bus_ops->rr =3D mt7921_rr; - bus_ops->wr =3D mt7921_wr; - bus_ops->rmw =3D mt7921_rmw; - dev->mt76.bus =3D bus_ops; - mt76_dma_attach(&dev->mt76); =20 ret =3D mt7921_dma_disable(dev, true); --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c @@ -1306,10 +1306,8 @@ int mt7921_mcu_sta_update(struct mt7921_ return mt76_connac_mcu_sta_cmd(&dev->mphy, &info); } =20 -int __mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev) +int __mt7921e_mcu_drv_pmctrl(struct mt7921_dev *dev) { - struct mt76_phy *mphy =3D &dev->mt76.phy; - struct mt76_connac_pm *pm =3D &dev->pm; int i, err =3D 0; =20 for (i =3D 0; i < MT7921_DRV_OWN_RETRY_COUNT; i++) { @@ -1322,9 +1320,21 @@ int __mt7921_mcu_drv_pmctrl(struct mt792 if (i =3D=3D MT7921_DRV_OWN_RETRY_COUNT) { dev_err(dev->mt76.dev, "driver own failed\n"); err =3D -EIO; - goto out; } =20 + return err; +} + +int __mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev) +{ + struct mt76_phy *mphy =3D &dev->mt76.phy; + struct mt76_connac_pm *pm =3D &dev->pm; + int err; + + err =3D __mt7921e_mcu_drv_pmctrl(dev); + if (err < 0) + goto out; + mt7921_wpdma_reinit_cond(dev); clear_bit(MT76_STATE_PM, &mphy->state); =20 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h @@ -374,6 +374,7 @@ int mt7921_mcu_uni_rx_ba(struct mt7921_d bool enable); void mt7921_scan_work(struct work_struct *work); int mt7921_mcu_uni_bss_ps(struct mt7921_dev *dev, struct ieee80211_vif *vi= f); +int __mt7921e_mcu_drv_pmctrl(struct mt7921_dev *dev); int __mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev); int mt7921_mcu_drv_pmctrl(struct mt7921_dev *dev); int mt7921_mcu_fw_pmctrl(struct mt7921_dev *dev); --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -88,6 +88,110 @@ static void mt7921_irq_tasklet(unsigned napi_schedule(&dev->mt76.napi[MT_RXQ_MAIN]); } =20 +static u32 __mt7921_reg_addr(struct mt7921_dev *dev, u32 addr) +{ + static const struct { + u32 phys; + u32 mapped; + u32 size; + } fixed_map[] =3D { + { 0x820d0000, 0x30000, 0x10000 }, /* WF_LMAC_TOP (WF_WTBLON) */ + { 0x820ed000, 0x24800, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_MIB) */ + { 0x820e4000, 0x21000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_TMAC) */ + { 0x820e7000, 0x21e00, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_DMA) */ + { 0x820eb000, 0x24200, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_LPON) */ + { 0x820e2000, 0x20800, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_AGG) */ + { 0x820e3000, 0x20c00, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_ARB) */ + { 0x820e5000, 0x21400, 0x0800 }, /* WF_LMAC_TOP BN0 (WF_RMAC) */ + { 0x00400000, 0x80000, 0x10000 }, /* WF_MCU_SYSRAM */ + { 0x00410000, 0x90000, 0x10000 }, /* WF_MCU_SYSRAM (configure register) = */ + { 0x40000000, 0x70000, 0x10000 }, /* WF_UMAC_SYSRAM */ + { 0x54000000, 0x02000, 0x1000 }, /* WFDMA PCIE0 MCU DMA0 */ + { 0x55000000, 0x03000, 0x1000 }, /* WFDMA PCIE0 MCU DMA1 */ + { 0x58000000, 0x06000, 0x1000 }, /* WFDMA PCIE1 MCU DMA0 (MEM_DMA) */ + { 0x59000000, 0x07000, 0x1000 }, /* WFDMA PCIE1 MCU DMA1 */ + { 0x7c000000, 0xf0000, 0x10000 }, /* CONN_INFRA */ + { 0x7c020000, 0xd0000, 0x10000 }, /* CONN_INFRA, WFDMA */ + { 0x7c060000, 0xe0000, 0x10000 }, /* CONN_INFRA, conn_host_csr_top */ + { 0x80020000, 0xb0000, 0x10000 }, /* WF_TOP_MISC_OFF */ + { 0x81020000, 0xc0000, 0x10000 }, /* WF_TOP_MISC_ON */ + { 0x820c0000, 0x08000, 0x4000 }, /* WF_UMAC_TOP (PLE) */ + { 0x820c8000, 0x0c000, 0x2000 }, /* WF_UMAC_TOP (PSE) */ + { 0x820cc000, 0x0e000, 0x1000 }, /* WF_UMAC_TOP (PP) */ + { 0x820cd000, 0x0f000, 0x1000 }, /* WF_MDP_TOP */ + { 0x820ce000, 0x21c00, 0x0200 }, /* WF_LMAC_TOP (WF_SEC) */ + { 0x820cf000, 0x22000, 0x1000 }, /* WF_LMAC_TOP (WF_PF) */ + { 0x820e0000, 0x20000, 0x0400 }, /* WF_LMAC_TOP BN0 (WF_CFG) */ + { 0x820e1000, 0x20400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_TRB) */ + { 0x820e9000, 0x23400, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_WTBLOFF) */ + { 0x820ea000, 0x24000, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_ETBF) */ + { 0x820ec000, 0x24600, 0x0200 }, /* WF_LMAC_TOP BN0 (WF_INT) */ + { 0x820f0000, 0xa0000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_CFG) */ + { 0x820f1000, 0xa0600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_TRB) */ + { 0x820f2000, 0xa0800, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_AGG) */ + { 0x820f3000, 0xa0c00, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_ARB) */ + { 0x820f4000, 0xa1000, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_TMAC) */ + { 0x820f5000, 0xa1400, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_RMAC) */ + { 0x820f7000, 0xa1e00, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_DMA) */ + { 0x820f9000, 0xa3400, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_WTBLOFF) */ + { 0x820fa000, 0xa4000, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_ETBF) */ + { 0x820fb000, 0xa4200, 0x0400 }, /* WF_LMAC_TOP BN1 (WF_LPON) */ + { 0x820fc000, 0xa4600, 0x0200 }, /* WF_LMAC_TOP BN1 (WF_INT) */ + { 0x820fd000, 0xa4800, 0x0800 }, /* WF_LMAC_TOP BN1 (WF_MIB) */ + }; + int i; + + if (addr < 0x100000) + return addr; + + for (i =3D 0; i < ARRAY_SIZE(fixed_map); i++) { + u32 ofs; + + if (addr < fixed_map[i].phys) + continue; + + ofs =3D addr - fixed_map[i].phys; + if (ofs > fixed_map[i].size) + continue; + + return fixed_map[i].mapped + ofs; + } + + if ((addr >=3D 0x18000000 && addr < 0x18c00000) || + (addr >=3D 0x70000000 && addr < 0x78000000) || + (addr >=3D 0x7c000000 && addr < 0x7c400000)) + return mt7921_reg_map_l1(dev, addr); + + dev_err(dev->mt76.dev, "Access currently unsupported address %08x\n", + addr); + + return 0; +} + +static u32 mt7921_rr(struct mt76_dev *mdev, u32 offset) +{ + struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); + u32 addr =3D __mt7921_reg_addr(dev, offset); + + return dev->bus_ops->rr(mdev, addr); +} + +static void mt7921_wr(struct mt76_dev *mdev, u32 offset, u32 val) +{ + struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); + u32 addr =3D __mt7921_reg_addr(dev, offset); + + dev->bus_ops->wr(mdev, addr, val); +} + +static u32 mt7921_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val) +{ + struct mt7921_dev *dev =3D container_of(mdev, struct mt7921_dev, mt76); + u32 addr =3D __mt7921_reg_addr(dev, offset); + + return dev->bus_ops->rmw(mdev, addr, mask, val); +} + static int mt7921_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -110,6 +214,7 @@ static int mt7921_pci_probe(struct pci_d .sta_remove =3D mt7921_mac_sta_remove, .update_survey =3D mt7921_update_channel, }; + struct mt76_bus_ops *bus_ops; struct mt7921_dev *dev; struct mt76_dev *mdev; int ret; @@ -145,6 +250,22 @@ static int mt7921_pci_probe(struct pci_d =20 mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]); tasklet_init(&dev->irq_tasklet, mt7921_irq_tasklet, (unsigned long)dev); + + dev->bus_ops =3D dev->mt76.bus; + bus_ops =3D devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), + GFP_KERNEL); + if (!bus_ops) + return -ENOMEM; + + bus_ops->rr =3D mt7921_rr; + bus_ops->wr =3D mt7921_wr; + bus_ops->rmw =3D mt7921_rmw; + dev->mt76.bus =3D bus_ops; + + ret =3D __mt7921e_mcu_drv_pmctrl(dev); + if (ret) + return ret; + mdev->rev =3D (mt7921_l1_rr(dev, MT_HW_CHIPID) << 16) | (mt7921_l1_rr(dev, MT_HW_REV) & 0xff); dev_err(mdev->dev, "ASIC revision: %04x\n", mdev->rev); From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52389C19F2C for ; Wed, 27 Jul 2022 17:02:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237980AbiG0RCP (ORCPT ); Wed, 27 Jul 2022 13:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241206AbiG0RBo (ORCPT ); Wed, 27 Jul 2022 13:01:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9395C6BC05; Wed, 27 Jul 2022 09:38:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DEDCBB821B6; Wed, 27 Jul 2022 16:37:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 506BFC433C1; Wed, 27 Jul 2022 16:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939847; bh=WujFwljSuwH2VXyG++3F5nOsrXX2VIrrQKO+07kLxmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ts46/PJ4ltL9VNnoQOreO0gmrtyv5NoT+HNZBH+CkHGNl5JsJgRkAeGWp/AfYf2sV +VrLQkrXjm8VilWKDujcSHKgg4zhDDbZmQqBT7hBMxo9oBWoNv/GTECiHkYGn5yXqF q3e0y4YAuu4XGBaqXNdbXBQ4muxzqHtML2Ja2Rr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Christophe JAILLET , Felix Fietkau Subject: [PATCH 5.15 020/201] mt76: mt7921: Fix the error handling path of mt7921_pci_probe() Date: Wed, 27 Jul 2022 18:08:44 +0200 Message-Id: <20220727161027.748066262@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Christophe JAILLET commit 4e90db5e21eb3bb272fe47386dc3506755e209e9 upstream. In case of error, some resources must be freed, as already done above and below the devm_kmemdup() and __mt7921e_mcu_drv_pmctrl() calls added in the commit in Fixes:. Fixes: 602cc0c9618a ("mt76: mt7921e: fix possible probe failure after reboo= t") Signed-off-by: Christophe JAILLET Signed-off-by: Felix Fietkau Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -254,8 +254,10 @@ static int mt7921_pci_probe(struct pci_d dev->bus_ops =3D dev->mt76.bus; bus_ops =3D devm_kmemdup(dev->mt76.dev, dev->bus_ops, sizeof(*bus_ops), GFP_KERNEL); - if (!bus_ops) - return -ENOMEM; + if (!bus_ops) { + ret =3D -ENOMEM; + goto err_free_dev; + } =20 bus_ops->rr =3D mt7921_rr; bus_ops->wr =3D mt7921_wr; @@ -264,7 +266,7 @@ static int mt7921_pci_probe(struct pci_d =20 ret =3D __mt7921e_mcu_drv_pmctrl(dev); if (ret) - return ret; + goto err_free_dev; =20 mdev->rev =3D (mt7921_l1_rr(dev, MT_HW_CHIPID) << 16) | (mt7921_l1_rr(dev, MT_HW_REV) & 0xff); From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB8CAC04A68 for ; Wed, 27 Jul 2022 17:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239729AbiG0RAo (ORCPT ); Wed, 27 Jul 2022 13:00:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241398AbiG0Q7j (ORCPT ); Wed, 27 Jul 2022 12:59:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41AEB691F0; Wed, 27 Jul 2022 09:37:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B156AB821A6; Wed, 27 Jul 2022 16:37:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06B94C433C1; Wed, 27 Jul 2022 16:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939853; bh=H6Ls8YFqH71j1ApB6PrAmK28ZzaHYIEAR7Jz0lr46Oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bx/f/pBjgSrYYCOxq3YSTYzW0G/tH5PBjFmWpmohv0l+lRPcGXnc9mJjIRoH1eAJY oyX/jf20UNFD7jv2zA7uBYs4LsK+4tHsQAud8COnJMtc9MyJEwX2CtbBWWMvbv4eee zgkzMutm89/NWVQGxbUX4m4VpYix588qN8vuveLk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Chandan Babu R , Christoph Hellwig , Leah Rumancik Subject: [PATCH 5.15 021/201] xfs: fix maxlevels comparisons in the btree staging code Date: Wed, 27 Jul 2022 18:08:45 +0200 Message-Id: <20220727161027.780172627@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: "Darrick J. Wong" [ Upstream commit 78e8ec83a404d63dcc86b251f42e4ee8aff27465 ] The btree geometry computation function has an off-by-one error in that it does not allow maximally tall btrees (nlevels =3D=3D XFS_BTREE_MAXLEVELS= ). This can result in repairs failing unnecessarily on very fragmented filesystems. Subsequent patches to remove MAXLEVELS usage in favor of the per-btree type computations will make this a much more likely occurrence. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/xfs/libxfs/xfs_btree_staging.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/xfs/libxfs/xfs_btree_staging.c +++ b/fs/xfs/libxfs/xfs_btree_staging.c @@ -662,7 +662,7 @@ xfs_btree_bload_compute_geometry( xfs_btree_bload_ensure_slack(cur, &bbl->node_slack, 1); =20 bbl->nr_records =3D nr_this_level =3D nr_records; - for (cur->bc_nlevels =3D 1; cur->bc_nlevels < XFS_BTREE_MAXLEVELS;) { + for (cur->bc_nlevels =3D 1; cur->bc_nlevels <=3D XFS_BTREE_MAXLEVELS;) { uint64_t level_blocks; uint64_t dontcare64; unsigned int level =3D cur->bc_nlevels - 1; @@ -724,7 +724,7 @@ xfs_btree_bload_compute_geometry( nr_this_level =3D level_blocks; } =20 - if (cur->bc_nlevels =3D=3D XFS_BTREE_MAXLEVELS) + if (cur->bc_nlevels > XFS_BTREE_MAXLEVELS) return -EOVERFLOW; =20 bbl->btree_height =3D cur->bc_nlevels; From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDDC3C19F28 for ; Wed, 27 Jul 2022 17:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241220AbiG0RAq (ORCPT ); Wed, 27 Jul 2022 13:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241409AbiG0Q7k (ORCPT ); Wed, 27 Jul 2022 12:59:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D5F691FB; Wed, 27 Jul 2022 09:37:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ACE1FB821B9; Wed, 27 Jul 2022 16:37:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D79B4C433C1; Wed, 27 Jul 2022 16:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939856; bh=QIwyvBHzMft5hHeUPCGfaHE9IruANW/3bkRMmqt8OuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FgdCR/7bqOYCGgky5TC4bmy3rHzWkFma3TG0icixcYElcYRQOpfAwur5VGwJ97y73 R39/Kts+dqQp2QtoyW+ML6ncgRkCwxTa9EVKMXwKwjhsBw3MoVR9gxM9ShXfcuRSZg lfQlPmKHhbWjFaNe4TQYMinRZEpPr1z0J5zaLwco= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , Dave Chinner , "Darrick J. Wong" , Leah Rumancik Subject: [PATCH 5.15 022/201] xfs: fold perag loop iteration logic into helper function Date: Wed, 27 Jul 2022 18:08:46 +0200 Message-Id: <20220727161027.823297023@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Brian Foster [ Upstream commit bf2307b195135ed9c95eebb38920d8bd41843092 ] Fold the loop iteration logic into a helper in preparation for further fixups. No functional change in this patch. [backport: dependency for f1788b5e5ee25bedf00bb4d25f82b93820d61189] Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/xfs/libxfs/xfs_ag.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -124,12 +124,22 @@ void xfs_perag_put(struct xfs_perag *pag * for_each_perag_from() because they terminate at sb_agcount where there = are * no perag structures in tree beyond end_agno. */ +static inline struct xfs_perag * +xfs_perag_next( + struct xfs_perag *pag, + xfs_agnumber_t *next_agno) +{ + struct xfs_mount *mp =3D pag->pag_mount; + + *next_agno =3D pag->pag_agno + 1; + xfs_perag_put(pag); + return xfs_perag_get(mp, *next_agno); +} + #define for_each_perag_range(mp, next_agno, end_agno, pag) \ for ((pag) =3D xfs_perag_get((mp), (next_agno)); \ (pag) !=3D NULL && (next_agno) <=3D (end_agno); \ - (next_agno) =3D (pag)->pag_agno + 1, \ - xfs_perag_put(pag), \ - (pag) =3D xfs_perag_get((mp), (next_agno))) + (pag) =3D xfs_perag_next((pag), &(next_agno))) =20 #define for_each_perag_from(mp, next_agno, pag) \ for_each_perag_range((mp), (next_agno), (mp)->m_sb.sb_agcount, (pag)) From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1494C04A68 for ; Wed, 27 Jul 2022 17:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232367AbiG0RCq (ORCPT ); Wed, 27 Jul 2022 13:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241082AbiG0RCM (ORCPT ); Wed, 27 Jul 2022 13:02:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393FE6C11C; Wed, 27 Jul 2022 09:38:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AC080B8200D; Wed, 27 Jul 2022 16:37:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E12BBC433D7; Wed, 27 Jul 2022 16:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939859; bh=mPEUpCltEvoeCnadERliB+25tv9OoFIoS22pvdNZNYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tTm3X+xbNMxO5dsZcTY44AV3pkiF91hYYiqet1h3813doI7SczY5c2Fj2bUMF7J/5 xCTJHONCZO9644Eq7gVB5mLleodrooOjEKTvbj6FWtQ4bxyRUKcEdiKRjdVtdey/1G rvLHquyFb/7da+yNxre5RF0BBnlqOR36J7omOdJU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , Dave Chinner , "Darrick J. Wong" , Leah Rumancik Subject: [PATCH 5.15 023/201] xfs: rename the next_agno perag iteration variable Date: Wed, 27 Jul 2022 18:08:47 +0200 Message-Id: <20220727161027.866105909@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Brian Foster [ Upstream commit f1788b5e5ee25bedf00bb4d25f82b93820d61189 ] Rename the next_agno variable to be consistent across the several iteration macros and shorten line length. [backport: dependency for 8ed004eb9d07a5d6114db3e97a166707c186262d] Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/xfs/libxfs/xfs_ag.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -127,22 +127,22 @@ void xfs_perag_put(struct xfs_perag *pag static inline struct xfs_perag * xfs_perag_next( struct xfs_perag *pag, - xfs_agnumber_t *next_agno) + xfs_agnumber_t *agno) { struct xfs_mount *mp =3D pag->pag_mount; =20 - *next_agno =3D pag->pag_agno + 1; + *agno =3D pag->pag_agno + 1; xfs_perag_put(pag); - return xfs_perag_get(mp, *next_agno); + return xfs_perag_get(mp, *agno); } =20 -#define for_each_perag_range(mp, next_agno, end_agno, pag) \ - for ((pag) =3D xfs_perag_get((mp), (next_agno)); \ - (pag) !=3D NULL && (next_agno) <=3D (end_agno); \ - (pag) =3D xfs_perag_next((pag), &(next_agno))) +#define for_each_perag_range(mp, agno, end_agno, pag) \ + for ((pag) =3D xfs_perag_get((mp), (agno)); \ + (pag) !=3D NULL && (agno) <=3D (end_agno); \ + (pag) =3D xfs_perag_next((pag), &(agno))) =20 -#define for_each_perag_from(mp, next_agno, pag) \ - for_each_perag_range((mp), (next_agno), (mp)->m_sb.sb_agcount, (pag)) +#define for_each_perag_from(mp, agno, pag) \ + for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount, (pag)) =20 =20 #define for_each_perag(mp, agno, pag) \ From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8950C19F2B for ; Wed, 27 Jul 2022 17:01:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235113AbiG0RBJ (ORCPT ); Wed, 27 Jul 2022 13:01:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241480AbiG0Q7w (ORCPT ); Wed, 27 Jul 2022 12:59:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E255469F31; Wed, 27 Jul 2022 09:37:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6183FB821CB; Wed, 27 Jul 2022 16:37:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF687C433D6; Wed, 27 Jul 2022 16:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939862; bh=x6twVJUTKOoXyXY/6nUmkDDzHd1kvJiKG2CYgWRP7kw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qT1lL6vQMzQDpaELapVTY4wTKc4rFJ2OgLQMxGlvK8VItS9I8TgUYsl4zv3ogWJBB s1qCQRhpm+m6UAOVfjUif77ZgH1rSkdYIRcbIuyZHfOxInt9yo/oI42YjIZuCT0fXe S14X3nIb7AvTcghNblZNsWEKTMzgR7GLapJifHMI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , Dave Chinner , "Darrick J. Wong" , Leah Rumancik Subject: [PATCH 5.15 024/201] xfs: terminate perag iteration reliably on agcount Date: Wed, 27 Jul 2022 18:08:48 +0200 Message-Id: <20220727161027.897328210@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Brian Foster [ Upstream commit 8ed004eb9d07a5d6114db3e97a166707c186262d ] The for_each_perag_from() iteration macro relies on sb_agcount to process every perag currently within EOFS from a given starting point. It's perfectly valid to have perag structures beyond sb_agcount, however, such as if a growfs is in progress. If a perag loop happens to race with growfs in this manner, it will actually attempt to process the post-EOFS perag where ->pag_agno =3D=3D sb_agcount. This is reproduced by xfs/104 and manifests as the following assert failure in superblock write verifier context: XFS: Assertion failed: agno < mp->m_sb.sb_agcount, file: fs/xfs/libxfs/xfs= _types.c, line: 22 Update the corresponding macro to only process perags that are within the current sb_agcount. Fixes: 58d43a7e3263 ("xfs: pass perags around in fsmap data dev functions") Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/xfs/libxfs/xfs_ag.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -142,7 +142,7 @@ xfs_perag_next( (pag) =3D xfs_perag_next((pag), &(agno))) =20 #define for_each_perag_from(mp, agno, pag) \ - for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount, (pag)) + for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount - 1, (pag)) =20 =20 #define for_each_perag(mp, agno, pag) \ From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6C96C19F28 for ; Wed, 27 Jul 2022 17:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231513AbiG0RBd (ORCPT ); Wed, 27 Jul 2022 13:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236197AbiG0Q75 (ORCPT ); Wed, 27 Jul 2022 12:59:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4C6A6A9D7; Wed, 27 Jul 2022 09:37:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 77962601CD; Wed, 27 Jul 2022 16:37:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E7F3C433C1; Wed, 27 Jul 2022 16:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939864; bh=I5DTKrP2Y6N/lxCCIGd2q5PUInTDb42tcimBsKjacpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s2Z3PHOMuzJ+T41boi6pZsQxD+xd7Ny2VNqnBzuVccHl31+90h1LuVFLBYfmHmfrr hqbi/vHjFjUxcyrJDE3GUbWYPoc1AKp/iuBtcgBAaIBDC0Yv160N1cv+T8F94cfN1Q SnvFzcWxnWP0+eEz4YOfOlgvUw9UfiX9T7XnzYmI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , Dave Chinner , "Darrick J. Wong" , Leah Rumancik Subject: [PATCH 5.15 025/201] xfs: fix perag reference leak on iteration race with growfs Date: Wed, 27 Jul 2022 18:08:49 +0200 Message-Id: <20220727161027.934257844@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Brian Foster [ Upstream commit 892a666fafa19ab04b5e948f6c92f98f1dafb489 ] The for_each_perag*() set of macros are hacky in that some (i.e. those based on sb_agcount) rely on the assumption that perag iteration terminates naturally with a NULL perag at the specified end_agno. Others allow for the final AG to have a valid perag and require the calling function to clean up any potential leftover xfs_perag reference on termination of the loop. Aside from providing a subtly inconsistent interface, the former variant is racy with growfs because growfs can create discoverable post-eofs perags before the final superblock update that completes the grow operation and increases sb_agcount. This leads to the following assert failure (reproduced by xfs/104) in the perag free path during unmount: XFS: Assertion failed: atomic_read(&pag->pag_ref) =3D=3D 0, file: fs/xfs/l= ibxfs/xfs_ag.c, line: 195 This occurs because one of the many for_each_perag() loops in the code that is expected to terminate with a NULL pag (and thus has no post-loop xfs_perag_put() check) raced with a growfs and found a non-NULL post-EOFS perag, but terminated naturally based on the end_agno check without releasing the post-EOFS perag. Rework the iteration logic to lift the agno check from the main for loop conditional to the iteration helper function. The for loop now purely terminates on a NULL pag and xfs_perag_next() avoids taking a reference to any perag beyond end_agno in the first place. Fixes: f250eedcf762 ("xfs: make for_each_perag... a first class citizen") Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/xfs/libxfs/xfs_ag.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -116,30 +116,26 @@ void xfs_perag_put(struct xfs_perag *pag =20 /* * Perag iteration APIs - * - * XXX: for_each_perag_range() usage really needs an iterator to clean up = when - * we terminate at end_agno because we may have taken a reference to the p= erag - * beyond end_agno. Right now callers have to be careful to catch and clea= n that - * up themselves. This is not necessary for the callers of for_each_perag(= ) and - * for_each_perag_from() because they terminate at sb_agcount where there = are - * no perag structures in tree beyond end_agno. */ static inline struct xfs_perag * xfs_perag_next( struct xfs_perag *pag, - xfs_agnumber_t *agno) + xfs_agnumber_t *agno, + xfs_agnumber_t end_agno) { struct xfs_mount *mp =3D pag->pag_mount; =20 *agno =3D pag->pag_agno + 1; xfs_perag_put(pag); + if (*agno > end_agno) + return NULL; return xfs_perag_get(mp, *agno); } =20 #define for_each_perag_range(mp, agno, end_agno, pag) \ for ((pag) =3D xfs_perag_get((mp), (agno)); \ - (pag) !=3D NULL && (agno) <=3D (end_agno); \ - (pag) =3D xfs_perag_next((pag), &(agno))) + (pag) !=3D NULL; \ + (pag) =3D xfs_perag_next((pag), &(agno), (end_agno))) =20 #define for_each_perag_from(mp, agno, pag) \ for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount - 1, (pag)) From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABB85C19F28 for ; Wed, 27 Jul 2022 17:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241264AbiG0RBu (ORCPT ); Wed, 27 Jul 2022 13:01:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241243AbiG0RAz (ORCPT ); Wed, 27 Jul 2022 13:00:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD046B249; Wed, 27 Jul 2022 09:37:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2A4C6603F2; Wed, 27 Jul 2022 16:37:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B2DAC433D7; Wed, 27 Jul 2022 16:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939872; bh=9gQy/2TtoYzwkDBx0KaJhGl6Nd2Cd9T0Qtfah1XWqgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZeCbgjZ+wL0oX8l3jj0zQr7DsP+AFrXlLaKL6ZUVa0FW4BUGcrGKIvODHykjy+j0t wMkzfKXhJaw0OhB4Ia6KtLpfkfIauoekcxD5BuMmvCgxZnK11LrwOxzqqi+ZnHWJAX BBaIdgilJHHEWxmwVPZvMpPk5R+ooQ2FFKkbaBgY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "Darrick J. Wong" , Leah Rumancik Subject: [PATCH 5.15 026/201] xfs: prevent a WARN_ONCE() in xfs_ioc_attr_list() Date: Wed, 27 Jul 2022 18:08:50 +0200 Message-Id: <20220727161027.976166418@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dan Carpenter [ Upstream commit 6ed6356b07714e0198be3bc3ecccc8b40a212de4 ] The "bufsize" comes from the root user. If "bufsize" is negative then, because of type promotion, neither of the validation checks at the start of the function are able to catch it: if (bufsize < sizeof(struct xfs_attrlist) || bufsize > XFS_XATTR_LIST_MAX) return -EINVAL; This means "bufsize" will trigger (WARN_ON_ONCE(size > INT_MAX)) in kvmalloc_node(). Fix this by changing the type from int to size_t. Signed-off-by: Dan Carpenter Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/xfs/xfs_ioctl.c | 2 +- fs/xfs/xfs_ioctl.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -372,7 +372,7 @@ int xfs_ioc_attr_list( struct xfs_inode *dp, void __user *ubuf, - int bufsize, + size_t bufsize, int flags, struct xfs_attrlist_cursor __user *ucursor) { --- a/fs/xfs/xfs_ioctl.h +++ b/fs/xfs/xfs_ioctl.h @@ -38,8 +38,9 @@ xfs_readlink_by_handle( int xfs_ioc_attrmulti_one(struct file *parfilp, struct inode *inode, uint32_t opcode, void __user *uname, void __user *value, uint32_t *len, uint32_t flags); -int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf, int bufsize, - int flags, struct xfs_attrlist_cursor __user *ucursor); +int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf, + size_t bufsize, int flags, + struct xfs_attrlist_cursor __user *ucursor); =20 extern struct dentry * xfs_handle_to_dentry( From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A353C04A68 for ; Wed, 27 Jul 2022 17:01:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231837AbiG0RBx (ORCPT ); Wed, 27 Jul 2022 13:01:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241267AbiG0RBH (ORCPT ); Wed, 27 Jul 2022 13:01:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C39BB57221; Wed, 27 Jul 2022 09:37:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04AAD601C0; Wed, 27 Jul 2022 16:37:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EE86C433D6; Wed, 27 Jul 2022 16:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939875; bh=zl8nkHP5kUCeFYDnIhWo5vo26zKl4GVTupTw4VrhxM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UXVQmMUGbGv1Wg5JS0zzQDFbRmB0mRaXG5EK0DAM8L4AtQeX+mPhRfoE2ebPiQx5V j15kLZoAwJHNbwmeq2affDrbtyroAqtWgst1xqw4Z1IsVntb9eOb6WKzLlPOIK8DKq pEq0C/Th/5QMsR/GuobA3b+7ab9gvi7vLEvz3lfM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hayes Wang , Jakub Kicinski Subject: [PATCH 5.15 027/201] r8152: fix a WOL issue Date: Wed, 27 Jul 2022 18:08:51 +0200 Message-Id: <20220727161028.026683186@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Hayes Wang commit cdf0b86b250fd3c1c3e120c86583ea510c52e4ce upstream. This fixes that the platform is waked by an unexpected packet. The size and range of FIFO is different when the device enters S3 state, so it is necessary to correct some settings when suspending. Regardless of jumbo frame, set RMS to 1522 and MTPS to MTPS_DEFAULT. Besides, enable MCU_BORW_EN to update the method of calculating the pointer of data. Then, the hardware could get the correct data. Fixes: 195aae321c82 ("r8152: support new chips") Signed-off-by: Hayes Wang Link: https://lore.kernel.org/r/20220718082120.10957-391-nic_swsd@realtek.c= om Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/usb/r8152.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -32,7 +32,7 @@ #define NETNEXT_VERSION "12" =20 /* Information for net */ -#define NET_VERSION "12" +#define NET_VERSION "13" =20 #define DRIVER_VERSION "v1." NETNEXT_VERSION "." NET_VERSION #define DRIVER_AUTHOR "Realtek linux nic maintainers " @@ -5915,7 +5915,8 @@ static void r8153_enter_oob(struct r8152 =20 wait_oob_link_list_ready(tp); =20 - ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu)); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1522); + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_DEFAULT); =20 switch (tp->version) { case RTL_VER_03: @@ -5951,6 +5952,10 @@ static void r8153_enter_oob(struct r8152 ocp_data |=3D NOW_IS_OOB | DIS_MCU_CLROOB; ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); =20 + ocp_data =3D ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); + ocp_data |=3D MCU_BORW_EN; + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); + rxdy_gated_en(tp, false); =20 ocp_data =3D ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR); @@ -6553,6 +6558,9 @@ static void rtl8156_down(struct r8152 *t rtl_disable(tp); rtl_reset_bmu(tp); =20 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, 1522); + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_DEFAULT); + /* Clear teredo wake event. bit[15:8] is the teredo wakeup * type. Set it to zero. bits[7:0] are the W1C bits about * the events. Set them to all 1 to clear them. @@ -6563,6 +6571,10 @@ static void rtl8156_down(struct r8152 *t ocp_data |=3D NOW_IS_OOB; ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data); =20 + ocp_data =3D ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7); + ocp_data |=3D MCU_BORW_EN; + ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data); + rtl_rx_vlan_en(tp, true); rxdy_gated_en(tp, false); From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDDB2C04A68 for ; Wed, 27 Jul 2022 17:01:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241279AbiG0RB5 (ORCPT ); Wed, 27 Jul 2022 13:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237919AbiG0RBU (ORCPT ); Wed, 27 Jul 2022 13:01:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5742857230; Wed, 27 Jul 2022 09:38:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D1F71601CD; Wed, 27 Jul 2022 16:37:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEAE1C433C1; Wed, 27 Jul 2022 16:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939878; bh=b4toqc/QbDYniqKpZ6WSq9fi4n5gdJWLetTFuuGFIp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FdPUUlpOFZimCE4bEBumTsiMHBvYXc7NYtvaYzopY9TgYnn9reR8lMIakB8aAduHn x5R+SoYkh1KQJ+UdGRwXLRdEquPcBDhr6L8uXdmFHEqd8ft/YmAyBjjUuYIhb5B4H5 GBL0q3Skd4fcX82oG+/PjWjNiMgIw4L8jh8H246I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" Subject: [PATCH 5.15 028/201] ip: Fix data-races around sysctl_ip_default_ttl. Date: Wed, 27 Jul 2022 18:08:52 +0200 Message-Id: <20220727161028.070987983@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima commit 8281b7ec5c56b71cb2cc5a1728b41607be66959c upstream. While reading sysctl_ip_default_ttl, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/netronome/nfp/flower/action.c | 2 +- include/net/route.h | 2 +- net/ipv4/ip_sockglue.c | 2 +- net/ipv4/netfilter/nf_reject_ipv4.c | 4 ++-- net/ipv4/proc.c | 2 +- net/netfilter/nf_synproxy_core.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) --- a/drivers/net/ethernet/netronome/nfp/flower/action.c +++ b/drivers/net/ethernet/netronome/nfp/flower/action.c @@ -472,7 +472,7 @@ nfp_fl_set_tun(struct nfp_app *app, stru set_tun->ttl =3D ip4_dst_hoplimit(&rt->dst); ip_rt_put(rt); } else { - set_tun->ttl =3D net->ipv4.sysctl_ip_default_ttl; + set_tun->ttl =3D READ_ONCE(net->ipv4.sysctl_ip_default_ttl); } } =20 --- a/include/net/route.h +++ b/include/net/route.h @@ -360,7 +360,7 @@ static inline int ip4_dst_hoplimit(const struct net *net =3D dev_net(dst->dev); =20 if (hoplimit =3D=3D 0) - hoplimit =3D net->ipv4.sysctl_ip_default_ttl; + hoplimit =3D READ_ONCE(net->ipv4.sysctl_ip_default_ttl); return hoplimit; } =20 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -1597,7 +1597,7 @@ static int do_ip_getsockopt(struct sock { struct net *net =3D sock_net(sk); val =3D (inet->uc_ttl =3D=3D -1 ? - net->ipv4.sysctl_ip_default_ttl : + READ_ONCE(net->ipv4.sysctl_ip_default_ttl) : inet->uc_ttl); break; } --- a/net/ipv4/netfilter/nf_reject_ipv4.c +++ b/net/ipv4/netfilter/nf_reject_ipv4.c @@ -62,7 +62,7 @@ struct sk_buff *nf_reject_skb_v4_tcp_res =20 skb_reserve(nskb, LL_MAX_HEADER); niph =3D nf_reject_iphdr_put(nskb, oldskb, IPPROTO_TCP, - net->ipv4.sysctl_ip_default_ttl); + READ_ONCE(net->ipv4.sysctl_ip_default_ttl)); nf_reject_ip_tcphdr_put(nskb, oldskb, oth); niph->tot_len =3D htons(nskb->len); ip_send_check(niph); @@ -115,7 +115,7 @@ struct sk_buff *nf_reject_skb_v4_unreach =20 skb_reserve(nskb, LL_MAX_HEADER); niph =3D nf_reject_iphdr_put(nskb, oldskb, IPPROTO_ICMP, - net->ipv4.sysctl_ip_default_ttl); + READ_ONCE(net->ipv4.sysctl_ip_default_ttl)); =20 skb_reset_transport_header(nskb); icmph =3D skb_put_zero(nskb, sizeof(struct icmphdr)); --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c @@ -387,7 +387,7 @@ static int snmp_seq_show_ipstats(struct =20 seq_printf(seq, "\nIp: %d %d", IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2, - net->ipv4.sysctl_ip_default_ttl); + READ_ONCE(net->ipv4.sysctl_ip_default_ttl)); =20 BUILD_BUG_ON(offsetof(struct ipstats_mib, mibs) !=3D 0); snmp_get_cpu_field64_batch(buff64, snmp4_ipstats_list, --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -427,7 +427,7 @@ synproxy_build_ip(struct net *net, struc iph->tos =3D 0; iph->id =3D 0; iph->frag_off =3D htons(IP_DF); - iph->ttl =3D net->ipv4.sysctl_ip_default_ttl; + iph->ttl =3D READ_ONCE(net->ipv4.sysctl_ip_default_ttl); iph->protocol =3D IPPROTO_TCP; iph->check =3D 0; iph->saddr =3D saddr; From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10FEBC04A68 for ; Wed, 27 Jul 2022 17:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241248AbiG0RCT (ORCPT ); Wed, 27 Jul 2022 13:02:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241235AbiG0RBo (ORCPT ); Wed, 27 Jul 2022 13:01:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D29A6BC09; Wed, 27 Jul 2022 09:38:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6B164B8200C; Wed, 27 Jul 2022 16:38:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3F9AC433C1; Wed, 27 Jul 2022 16:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939881; bh=qXw/I2fUS2IOujk0ZA76gow/5hHBvGsPgEnrGSVqpQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pzp1FQipyKLzRX2dBOhu7krkxH0o3zpO89m7WJPFIZXGRF5INJs7fllqMKcNUQBuD qJRvUelN+Vr9q9nyzI5V6nW78NOIwBfEMhvlkTou72cJEwkH5MQyuPuulRYRDY/k1G lDJFCPwPiJaqYHARTfmUKAQRGw+34bxBKLMK9jOs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangyu Hua , Steffen Klassert , Sasha Levin Subject: [PATCH 5.15 029/201] xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup() Date: Wed, 27 Jul 2022 18:08:53 +0200 Message-Id: <20220727161028.109685397@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Hangyu Hua [ Upstream commit f85daf0e725358be78dfd208dea5fd665d8cb901 ] xfrm_policy_lookup() will call xfrm_pol_hold_rcu() to get a refcount of pols[0]. This refcount can be dropped in xfrm_expand_policies() when xfrm_expand_policies() return error. pols[0]'s refcount is balanced in here. But xfrm_bundle_lookup() will also call xfrm_pols_put() with num_pols =3D=3D 1 to drop this refcount when xfrm_expand_policies() return error. This patch also fix an illegal address access. pols[0] will save a error point when xfrm_policy_lookup fails. This lead to xfrm_pols_put to resolve an illegal address in xfrm_bundle_lookup's error path. Fix these by setting num_pols =3D 0 in xfrm_expand_policies()'s error path. Fixes: 80c802f3073e ("xfrm: cache bundles instead of policies for outgoing = flows") Signed-off-by: Hangyu Hua Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/xfrm/xfrm_policy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index a6271b955e11..fb198f9490a0 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -2678,8 +2678,10 @@ static int xfrm_expand_policies(const struct flowi *= fl, u16 family, *num_xfrms =3D 0; return 0; } - if (IS_ERR(pols[0])) + if (IS_ERR(pols[0])) { + *num_pols =3D 0; return PTR_ERR(pols[0]); + } =20 *num_xfrms =3D pols[0]->xfrm_nr; =20 @@ -2694,6 +2696,7 @@ static int xfrm_expand_policies(const struct flowi *f= l, u16 family, if (pols[1]) { if (IS_ERR(pols[1])) { xfrm_pols_put(pols, *num_pols); + *num_pols =3D 0; return PTR_ERR(pols[1]); } (*num_pols)++; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F876C04A68 for ; Wed, 27 Jul 2022 17:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239871AbiG0RC3 (ORCPT ); Wed, 27 Jul 2022 13:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237639AbiG0RBr (ORCPT ); Wed, 27 Jul 2022 13:01:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4BA46BC1F; Wed, 27 Jul 2022 09:38:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 887C760BF0; Wed, 27 Jul 2022 16:38:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 908F2C433D6; Wed, 27 Jul 2022 16:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939883; bh=jsF4LpQm777PxNt5/h+cNChfYSEvUrbp0KZNEszQamk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PAaNFg6GaUl/XrPcHT7UpcdI/iGYBILQio/DDLDIn95f46skOCyojzGf4P1xDWgbL ethI215yo7A11Sl0uG284PxQoy+bPA2p5lG/8zNR5Oa+BjFNvYjeghGVE3x5vQbLjE dvrkny7CTUMSoezowXfkfxa1Uv1xFoVFIuRWYH7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaoqian Lin , Linus Walleij , Sebastian Reichel , Sasha Levin Subject: [PATCH 5.15 030/201] power/reset: arm-versatile: Fix refcount leak in versatile_reboot_probe Date: Wed, 27 Jul 2022 18:08:54 +0200 Message-Id: <20220727161028.138866860@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Miaoqian Lin [ Upstream commit 80192eff64eee9b3bc0594a47381937b94b9d65a ] of_find_matching_node_and_match() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak. Fixes: 0e545f57b708 ("power: reset: driver for the Versatile syscon reboot") Signed-off-by: Miaoqian Lin Reviewed-by: Linus Walleij Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/power/reset/arm-versatile-reboot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/power/reset/arm-versatile-reboot.c b/drivers/power/res= et/arm-versatile-reboot.c index 08d0a07b58ef..c7624d7611a7 100644 --- a/drivers/power/reset/arm-versatile-reboot.c +++ b/drivers/power/reset/arm-versatile-reboot.c @@ -146,6 +146,7 @@ static int __init versatile_reboot_probe(void) versatile_reboot_type =3D (enum versatile_reboot)reboot_id->data; =20 syscon_regmap =3D syscon_node_to_regmap(np); + of_node_put(np); if (IS_ERR(syscon_regmap)) return PTR_ERR(syscon_regmap); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEC0CC04A68 for ; Wed, 27 Jul 2022 17:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235835AbiG0RCd (ORCPT ); Wed, 27 Jul 2022 13:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241071AbiG0RBw (ORCPT ); Wed, 27 Jul 2022 13:01:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 993A36BC3F; Wed, 27 Jul 2022 09:38:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4003B601C0; Wed, 27 Jul 2022 16:38:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27189C4347C; Wed, 27 Jul 2022 16:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939889; bh=qciahCULP5+MXiyz1Szl9JSLA7bcPoY9oSWj26A68Xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mMSNVCkjX2r/G326sSryVgNeYUc6wkWzf98wPqQtIhcWnPgTIQS0LODgfceY41jJQ orwlpZwyCWAEuTppqhVFBbmpvzlkycYSxb/2+Lmc21q7b/QiXVeeJYLp7ZJdd/8cwH dTgkZ22kFxgxmGGDmF46oz8WXFwF08F4JyKoiMYU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mustafa Ismail , Shiraz Saleem , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.15 031/201] RDMA/irdma: Do not advertise 1GB page size for x722 Date: Wed, 27 Jul 2022 18:08:55 +0200 Message-Id: <20220727161028.176894618@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Mustafa Ismail [ Upstream commit 5e8afb8792f3b6ae7ccf700f8c19225382636401 ] x722 does not support 1GB page size but the irdma driver incorrectly advertises 1GB page size support for x722 device to ib_core to compute the best page size to use on this MR. This could lead to incorrect start offsets computed by hardware on the MR. Fixes: b48c24c2d710 ("RDMA/irdma: Implement device supported verb APIs") Signed-off-by: Mustafa Ismail Signed-off-by: Shiraz Saleem Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/infiniband/hw/irdma/i40iw_hw.c | 1 + drivers/infiniband/hw/irdma/icrdma_hw.c | 1 + drivers/infiniband/hw/irdma/irdma.h | 1 + drivers/infiniband/hw/irdma/verbs.c | 4 ++-- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/irdma/i40iw_hw.c b/drivers/infiniband/hw= /irdma/i40iw_hw.c index 64148ad8a604..040d4e2b9767 100644 --- a/drivers/infiniband/hw/irdma/i40iw_hw.c +++ b/drivers/infiniband/hw/irdma/i40iw_hw.c @@ -202,6 +202,7 @@ void i40iw_init_hw(struct irdma_sc_dev *dev) dev->hw_attrs.uk_attrs.max_hw_read_sges =3D I40IW_MAX_SGE_RD; dev->hw_attrs.max_hw_device_pages =3D I40IW_MAX_PUSH_PAGE_COUNT; dev->hw_attrs.uk_attrs.max_hw_inline =3D I40IW_MAX_INLINE_DATA_SIZE; + dev->hw_attrs.page_size_cap =3D SZ_4K | SZ_2M; dev->hw_attrs.max_hw_ird =3D I40IW_MAX_IRD_SIZE; dev->hw_attrs.max_hw_ord =3D I40IW_MAX_ORD_SIZE; dev->hw_attrs.max_hw_wqes =3D I40IW_MAX_WQ_ENTRIES; diff --git a/drivers/infiniband/hw/irdma/icrdma_hw.c b/drivers/infiniband/h= w/irdma/icrdma_hw.c index cf53b17510cd..5986fd906308 100644 --- a/drivers/infiniband/hw/irdma/icrdma_hw.c +++ b/drivers/infiniband/hw/irdma/icrdma_hw.c @@ -139,6 +139,7 @@ void icrdma_init_hw(struct irdma_sc_dev *dev) dev->cqp_db =3D dev->hw_regs[IRDMA_CQPDB]; dev->cq_ack_db =3D dev->hw_regs[IRDMA_CQACK]; dev->irq_ops =3D &icrdma_irq_ops; + dev->hw_attrs.page_size_cap =3D SZ_4K | SZ_2M | SZ_1G; dev->hw_attrs.max_hw_ird =3D ICRDMA_MAX_IRD_SIZE; dev->hw_attrs.max_hw_ord =3D ICRDMA_MAX_ORD_SIZE; dev->hw_attrs.max_stat_inst =3D ICRDMA_MAX_STATS_COUNT; diff --git a/drivers/infiniband/hw/irdma/irdma.h b/drivers/infiniband/hw/ir= dma/irdma.h index 46c12334c735..4789e85d717b 100644 --- a/drivers/infiniband/hw/irdma/irdma.h +++ b/drivers/infiniband/hw/irdma/irdma.h @@ -127,6 +127,7 @@ struct irdma_hw_attrs { u64 max_hw_outbound_msg_size; u64 max_hw_inbound_msg_size; u64 max_mr_size; + u64 page_size_cap; u32 min_hw_qp_id; u32 min_hw_aeq_size; u32 max_hw_aeq_size; diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/ir= dma/verbs.c index 8a3ac4257e86..0eef46428691 100644 --- a/drivers/infiniband/hw/irdma/verbs.c +++ b/drivers/infiniband/hw/irdma/verbs.c @@ -29,7 +29,7 @@ static int irdma_query_device(struct ib_device *ibdev, props->vendor_part_id =3D pcidev->device; =20 props->hw_ver =3D rf->pcidev->revision; - props->page_size_cap =3D SZ_4K | SZ_2M | SZ_1G; + props->page_size_cap =3D hw_attrs->page_size_cap; props->max_mr_size =3D hw_attrs->max_mr_size; props->max_qp =3D rf->max_qp - rf->used_qps; props->max_qp_wr =3D hw_attrs->max_qp_wr; @@ -2776,7 +2776,7 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *= pd, u64 start, u64 len, =20 if (req.reg_type =3D=3D IRDMA_MEMREG_TYPE_MEM) { iwmr->page_size =3D ib_umem_find_best_pgsz(region, - SZ_4K | SZ_2M | SZ_1G, + iwdev->rf->sc_dev.hw_attrs.page_size_cap, virt); if (unlikely(!iwmr->page_size)) { kfree(iwmr); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B726C04A68 for ; Wed, 27 Jul 2022 17:03:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241201AbiG0RDh (ORCPT ); Wed, 27 Jul 2022 13:03:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241283AbiG0RDG (ORCPT ); Wed, 27 Jul 2022 13:03:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BECC6D576; Wed, 27 Jul 2022 09:38:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F3743B8200C; Wed, 27 Jul 2022 16:38:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29269C433C1; Wed, 27 Jul 2022 16:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939894; bh=Jut1UrqA484SZyvoDgmLDM1uXbmIRUU2CmoC0FX+9io=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rlg4T+H7QNleuv+7wI7fnyMPbv42GtE4r8tKKOg0Q88KOcUOrS5UKzxE/ayWpAGyP 8xkr8P57bgs0W+d1BmuJVgSjhkIJKAWGM7B+xo9yoYQh6h9y95EkQWxUHARRTRlLt7 2K4FfA0NqBq1ArbQ5GO5mq3IpEPMp6F6gQhIjY0I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mustafa Ismail , Shiraz Saleem , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.15 032/201] RDMA/irdma: Fix sleep from invalid context BUG Date: Wed, 27 Jul 2022 18:08:56 +0200 Message-Id: <20220727161028.215848380@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Mustafa Ismail [ Upstream commit cc0315564d6eec91c716d314b743321be24c70b3 ] Taking the qos_mutex to process RoCEv2 QP's on netdev events causes a kernel splat. Fix this by removing the handling for RoCEv2 in irdma_cm_teardown_connections that uses the mutex. This handling is only needed for iWARP to avoid having connections established while the link is down or having connections remain functional after the IP address is removed. BUG: sleeping function called from invalid context at kernel/locking/mute= x. Call Trace: kernel: dump_stack+0x66/0x90 kernel: ___might_sleep.cold.92+0x8d/0x9a kernel: mutex_lock+0x1c/0x40 kernel: irdma_cm_teardown_connections+0x28e/0x4d0 [irdma] kernel: ? check_preempt_curr+0x7a/0x90 kernel: ? select_idle_sibling+0x22/0x3c0 kernel: ? select_task_rq_fair+0x94c/0xc90 kernel: ? irdma_exec_cqp_cmd+0xc27/0x17c0 [irdma] kernel: ? __wake_up_common+0x7a/0x190 kernel: irdma_if_notify+0x3cc/0x450 [irdma] kernel: ? sched_clock_cpu+0xc/0xb0 kernel: irdma_inet6addr_event+0xc6/0x150 [irdma] Fixes: 146b9756f14c ("RDMA/irdma: Add connection manager") Signed-off-by: Mustafa Ismail Signed-off-by: Shiraz Saleem Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/infiniband/hw/irdma/cm.c | 50 -------------------------------- 1 file changed, 50 deletions(-) diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma= /cm.c index 632f65e53b63..60d4e9c151ff 100644 --- a/drivers/infiniband/hw/irdma/cm.c +++ b/drivers/infiniband/hw/irdma/cm.c @@ -4221,10 +4221,6 @@ void irdma_cm_teardown_connections(struct irdma_devi= ce *iwdev, u32 *ipaddr, struct irdma_cm_node *cm_node; struct list_head teardown_list; struct ib_qp_attr attr; - struct irdma_sc_vsi *vsi =3D &iwdev->vsi; - struct irdma_sc_qp *sc_qp; - struct irdma_qp *qp; - int i; =20 INIT_LIST_HEAD(&teardown_list); =20 @@ -4241,52 +4237,6 @@ void irdma_cm_teardown_connections(struct irdma_devi= ce *iwdev, u32 *ipaddr, irdma_cm_disconn(cm_node->iwqp); irdma_rem_ref_cm_node(cm_node); } - if (!iwdev->roce_mode) - return; - - INIT_LIST_HEAD(&teardown_list); - for (i =3D 0; i < IRDMA_MAX_USER_PRIORITY; i++) { - mutex_lock(&vsi->qos[i].qos_mutex); - list_for_each_safe (list_node, list_core_temp, - &vsi->qos[i].qplist) { - u32 qp_ip[4]; - - sc_qp =3D container_of(list_node, struct irdma_sc_qp, - list); - if (sc_qp->qp_uk.qp_type !=3D IRDMA_QP_TYPE_ROCE_RC) - continue; - - qp =3D sc_qp->qp_uk.back_qp; - if (!disconnect_all) { - if (nfo->ipv4) - qp_ip[0] =3D qp->udp_info.local_ipaddr[3]; - else - memcpy(qp_ip, - &qp->udp_info.local_ipaddr[0], - sizeof(qp_ip)); - } - - if (disconnect_all || - (nfo->vlan_id =3D=3D (qp->udp_info.vlan_tag & VLAN_VID_MASK) && - !memcmp(qp_ip, ipaddr, nfo->ipv4 ? 4 : 16))) { - spin_lock(&iwdev->rf->qptable_lock); - if (iwdev->rf->qp_table[sc_qp->qp_uk.qp_id]) { - irdma_qp_add_ref(&qp->ibqp); - list_add(&qp->teardown_entry, - &teardown_list); - } - spin_unlock(&iwdev->rf->qptable_lock); - } - } - mutex_unlock(&vsi->qos[i].qos_mutex); - } - - list_for_each_safe (list_node, list_core_temp, &teardown_list) { - qp =3D container_of(list_node, struct irdma_qp, teardown_entry); - attr.qp_state =3D IB_QPS_ERR; - irdma_modify_qp_roce(&qp->ibqp, &attr, IB_QP_STATE, NULL); - irdma_qp_rem_ref(&qp->ibqp); - } } =20 /** --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB252C19F2C for ; Wed, 27 Jul 2022 17:02:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241263AbiG0RC6 (ORCPT ); Wed, 27 Jul 2022 13:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241313AbiG0RCV (ORCPT ); Wed, 27 Jul 2022 13:02:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5E95720E; Wed, 27 Jul 2022 09:38:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 074A8601BE; Wed, 27 Jul 2022 16:38:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17DC7C433D6; Wed, 27 Jul 2022 16:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939897; bh=9daQcHA1ca8CTNZjEp82Tejpl/6LJe3wwlznXAHn6+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zO9pPOrXHn0xtO4+e2Urx8D79TP6VAVwuuoHjwkuVDIEpTjWbOb9ugtHxk9Df0DHV cTd2dZZpDktPGJxvkxWEbC33FDt+R/0Agdj5+DkuzR8MHLZm/7JtsARXaMhWgn8Wwu FVAn5IqLqor3jmIZxP9VV0RpmD28oKYWrOZ8T4fg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= , Sergio Paracuellos , Linus Walleij , Sasha Levin Subject: [PATCH 5.15 033/201] pinctrl: ralink: rename MT7628(an) functions to MT76X8 Date: Wed, 27 Jul 2022 18:08:57 +0200 Message-Id: <20220727161028.254123565@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ar=C4=B1n=C3=A7 =C3=9CNAL [ Upstream commit 150438c86f55989632005b92c94f4aa2ec562ed6 ] The functions that include "MT7628(an)" are for MT7628 and MT7688 SoCs. Rename them to MT76X8 to refer to both of the SoCs. Signed-off-by: Ar=C4=B1n=C3=A7 =C3=9CNAL Reviewed-by: Sergio Paracuellos Acked-by: Sergio Paracuellos Link: https://lore.kernel.org/r/20220414173916.5552-2-arinc.unal@arinc9.com Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/ralink/pinctrl-mt7620.c | 218 ++++++++++++------------ 1 file changed, 109 insertions(+), 109 deletions(-) diff --git a/drivers/pinctrl/ralink/pinctrl-mt7620.c b/drivers/pinctrl/rali= nk/pinctrl-mt7620.c index 6853b5b8b0fe..d3f9feec1f74 100644 --- a/drivers/pinctrl/ralink/pinctrl-mt7620.c +++ b/drivers/pinctrl/ralink/pinctrl-mt7620.c @@ -112,260 +112,260 @@ static struct rt2880_pmx_group mt7620a_pinmux_data[= ] =3D { { 0 } }; =20 -static struct rt2880_pmx_func pwm1_grp_mt7628[] =3D { +static struct rt2880_pmx_func pwm1_grp_mt76x8[] =3D { FUNC("sdxc d6", 3, 19, 1), FUNC("utif", 2, 19, 1), FUNC("gpio", 1, 19, 1), FUNC("pwm1", 0, 19, 1), }; =20 -static struct rt2880_pmx_func pwm0_grp_mt7628[] =3D { +static struct rt2880_pmx_func pwm0_grp_mt76x8[] =3D { FUNC("sdxc d7", 3, 18, 1), FUNC("utif", 2, 18, 1), FUNC("gpio", 1, 18, 1), FUNC("pwm0", 0, 18, 1), }; =20 -static struct rt2880_pmx_func uart2_grp_mt7628[] =3D { +static struct rt2880_pmx_func uart2_grp_mt76x8[] =3D { FUNC("sdxc d5 d4", 3, 20, 2), FUNC("pwm", 2, 20, 2), FUNC("gpio", 1, 20, 2), FUNC("uart2", 0, 20, 2), }; =20 -static struct rt2880_pmx_func uart1_grp_mt7628[] =3D { +static struct rt2880_pmx_func uart1_grp_mt76x8[] =3D { FUNC("sw_r", 3, 45, 2), FUNC("pwm", 2, 45, 2), FUNC("gpio", 1, 45, 2), FUNC("uart1", 0, 45, 2), }; =20 -static struct rt2880_pmx_func i2c_grp_mt7628[] =3D { +static struct rt2880_pmx_func i2c_grp_mt76x8[] =3D { FUNC("-", 3, 4, 2), FUNC("debug", 2, 4, 2), FUNC("gpio", 1, 4, 2), FUNC("i2c", 0, 4, 2), }; =20 -static struct rt2880_pmx_func refclk_grp_mt7628[] =3D { FUNC("refclk", 0, = 37, 1) }; -static struct rt2880_pmx_func perst_grp_mt7628[] =3D { FUNC("perst", 0, 36= , 1) }; -static struct rt2880_pmx_func wdt_grp_mt7628[] =3D { FUNC("wdt", 0, 38, 1)= }; -static struct rt2880_pmx_func spi_grp_mt7628[] =3D { FUNC("spi", 0, 7, 4) = }; +static struct rt2880_pmx_func refclk_grp_mt76x8[] =3D { FUNC("refclk", 0, = 37, 1) }; +static struct rt2880_pmx_func perst_grp_mt76x8[] =3D { FUNC("perst", 0, 36= , 1) }; +static struct rt2880_pmx_func wdt_grp_mt76x8[] =3D { FUNC("wdt", 0, 38, 1)= }; +static struct rt2880_pmx_func spi_grp_mt76x8[] =3D { FUNC("spi", 0, 7, 4) = }; =20 -static struct rt2880_pmx_func sd_mode_grp_mt7628[] =3D { +static struct rt2880_pmx_func sd_mode_grp_mt76x8[] =3D { FUNC("jtag", 3, 22, 8), FUNC("utif", 2, 22, 8), FUNC("gpio", 1, 22, 8), FUNC("sdxc", 0, 22, 8), }; =20 -static struct rt2880_pmx_func uart0_grp_mt7628[] =3D { +static struct rt2880_pmx_func uart0_grp_mt76x8[] =3D { FUNC("-", 3, 12, 2), FUNC("-", 2, 12, 2), FUNC("gpio", 1, 12, 2), FUNC("uart0", 0, 12, 2), }; =20 -static struct rt2880_pmx_func i2s_grp_mt7628[] =3D { +static struct rt2880_pmx_func i2s_grp_mt76x8[] =3D { FUNC("antenna", 3, 0, 4), FUNC("pcm", 2, 0, 4), FUNC("gpio", 1, 0, 4), FUNC("i2s", 0, 0, 4), }; =20 -static struct rt2880_pmx_func spi_cs1_grp_mt7628[] =3D { +static struct rt2880_pmx_func spi_cs1_grp_mt76x8[] =3D { FUNC("-", 3, 6, 1), FUNC("refclk", 2, 6, 1), FUNC("gpio", 1, 6, 1), FUNC("spi cs1", 0, 6, 1), }; =20 -static struct rt2880_pmx_func spis_grp_mt7628[] =3D { +static struct rt2880_pmx_func spis_grp_mt76x8[] =3D { FUNC("pwm_uart2", 3, 14, 4), FUNC("utif", 2, 14, 4), FUNC("gpio", 1, 14, 4), FUNC("spis", 0, 14, 4), }; =20 -static struct rt2880_pmx_func gpio_grp_mt7628[] =3D { +static struct rt2880_pmx_func gpio_grp_mt76x8[] =3D { FUNC("pcie", 3, 11, 1), FUNC("refclk", 2, 11, 1), FUNC("gpio", 1, 11, 1), FUNC("gpio", 0, 11, 1), }; =20 -static struct rt2880_pmx_func p4led_kn_grp_mt7628[] =3D { +static struct rt2880_pmx_func p4led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 30, 1), FUNC("utif", 2, 30, 1), FUNC("gpio", 1, 30, 1), FUNC("p4led_kn", 0, 30, 1), }; =20 -static struct rt2880_pmx_func p3led_kn_grp_mt7628[] =3D { +static struct rt2880_pmx_func p3led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 31, 1), FUNC("utif", 2, 31, 1), FUNC("gpio", 1, 31, 1), FUNC("p3led_kn", 0, 31, 1), }; =20 -static struct rt2880_pmx_func p2led_kn_grp_mt7628[] =3D { +static struct rt2880_pmx_func p2led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 32, 1), FUNC("utif", 2, 32, 1), FUNC("gpio", 1, 32, 1), FUNC("p2led_kn", 0, 32, 1), }; =20 -static struct rt2880_pmx_func p1led_kn_grp_mt7628[] =3D { +static struct rt2880_pmx_func p1led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 33, 1), FUNC("utif", 2, 33, 1), FUNC("gpio", 1, 33, 1), FUNC("p1led_kn", 0, 33, 1), }; =20 -static struct rt2880_pmx_func p0led_kn_grp_mt7628[] =3D { +static struct rt2880_pmx_func p0led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 34, 1), FUNC("rsvd", 2, 34, 1), FUNC("gpio", 1, 34, 1), FUNC("p0led_kn", 0, 34, 1), }; =20 -static struct rt2880_pmx_func wled_kn_grp_mt7628[] =3D { +static struct rt2880_pmx_func wled_kn_grp_mt76x8[] =3D { FUNC("rsvd", 3, 35, 1), FUNC("rsvd", 2, 35, 1), FUNC("gpio", 1, 35, 1), FUNC("wled_kn", 0, 35, 1), }; =20 -static struct rt2880_pmx_func p4led_an_grp_mt7628[] =3D { +static struct rt2880_pmx_func p4led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 39, 1), FUNC("utif", 2, 39, 1), FUNC("gpio", 1, 39, 1), FUNC("p4led_an", 0, 39, 1), }; =20 -static struct rt2880_pmx_func p3led_an_grp_mt7628[] =3D { +static struct rt2880_pmx_func p3led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 40, 1), FUNC("utif", 2, 40, 1), FUNC("gpio", 1, 40, 1), FUNC("p3led_an", 0, 40, 1), }; =20 -static struct rt2880_pmx_func p2led_an_grp_mt7628[] =3D { +static struct rt2880_pmx_func p2led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 41, 1), FUNC("utif", 2, 41, 1), FUNC("gpio", 1, 41, 1), FUNC("p2led_an", 0, 41, 1), }; =20 -static struct rt2880_pmx_func p1led_an_grp_mt7628[] =3D { +static struct rt2880_pmx_func p1led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 42, 1), FUNC("utif", 2, 42, 1), FUNC("gpio", 1, 42, 1), FUNC("p1led_an", 0, 42, 1), }; =20 -static struct rt2880_pmx_func p0led_an_grp_mt7628[] =3D { +static struct rt2880_pmx_func p0led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 43, 1), FUNC("rsvd", 2, 43, 1), FUNC("gpio", 1, 43, 1), FUNC("p0led_an", 0, 43, 1), }; =20 -static struct rt2880_pmx_func wled_an_grp_mt7628[] =3D { +static struct rt2880_pmx_func wled_an_grp_mt76x8[] =3D { FUNC("rsvd", 3, 44, 1), FUNC("rsvd", 2, 44, 1), FUNC("gpio", 1, 44, 1), FUNC("wled_an", 0, 44, 1), }; =20 -#define MT7628_GPIO_MODE_MASK 0x3 - -#define MT7628_GPIO_MODE_P4LED_KN 58 -#define MT7628_GPIO_MODE_P3LED_KN 56 -#define MT7628_GPIO_MODE_P2LED_KN 54 -#define MT7628_GPIO_MODE_P1LED_KN 52 -#define MT7628_GPIO_MODE_P0LED_KN 50 -#define MT7628_GPIO_MODE_WLED_KN 48 -#define MT7628_GPIO_MODE_P4LED_AN 42 -#define MT7628_GPIO_MODE_P3LED_AN 40 -#define MT7628_GPIO_MODE_P2LED_AN 38 -#define MT7628_GPIO_MODE_P1LED_AN 36 -#define MT7628_GPIO_MODE_P0LED_AN 34 -#define MT7628_GPIO_MODE_WLED_AN 32 -#define MT7628_GPIO_MODE_PWM1 30 -#define MT7628_GPIO_MODE_PWM0 28 -#define MT7628_GPIO_MODE_UART2 26 -#define MT7628_GPIO_MODE_UART1 24 -#define MT7628_GPIO_MODE_I2C 20 -#define MT7628_GPIO_MODE_REFCLK 18 -#define MT7628_GPIO_MODE_PERST 16 -#define MT7628_GPIO_MODE_WDT 14 -#define MT7628_GPIO_MODE_SPI 12 -#define MT7628_GPIO_MODE_SDMODE 10 -#define MT7628_GPIO_MODE_UART0 8 -#define MT7628_GPIO_MODE_I2S 6 -#define MT7628_GPIO_MODE_CS1 4 -#define MT7628_GPIO_MODE_SPIS 2 -#define MT7628_GPIO_MODE_GPIO 0 - -static struct rt2880_pmx_group mt7628an_pinmux_data[] =3D { - GRP_G("pwm1", pwm1_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_PWM1), - GRP_G("pwm0", pwm0_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_PWM0), - GRP_G("uart2", uart2_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_UART2), - GRP_G("uart1", uart1_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_UART1), - GRP_G("i2c", i2c_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_I2C), - GRP("refclk", refclk_grp_mt7628, 1, MT7628_GPIO_MODE_REFCLK), - GRP("perst", perst_grp_mt7628, 1, MT7628_GPIO_MODE_PERST), - GRP("wdt", wdt_grp_mt7628, 1, MT7628_GPIO_MODE_WDT), - GRP("spi", spi_grp_mt7628, 1, MT7628_GPIO_MODE_SPI), - GRP_G("sdmode", sd_mode_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_SDMODE), - GRP_G("uart0", uart0_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_UART0), - GRP_G("i2s", i2s_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_I2S), - GRP_G("spi cs1", spi_cs1_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_CS1), - GRP_G("spis", spis_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_SPIS), - GRP_G("gpio", gpio_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_GPIO), - GRP_G("wled_an", wled_an_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_WLED_AN), - GRP_G("p0led_an", p0led_an_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P0LED_AN), - GRP_G("p1led_an", p1led_an_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P1LED_AN), - GRP_G("p2led_an", p2led_an_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P2LED_AN), - GRP_G("p3led_an", p3led_an_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P3LED_AN), - GRP_G("p4led_an", p4led_an_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P4LED_AN), - GRP_G("wled_kn", wled_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_WLED_KN), - GRP_G("p0led_kn", p0led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P0LED_KN), - GRP_G("p1led_kn", p1led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P1LED_KN), - GRP_G("p2led_kn", p2led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P2LED_KN), - GRP_G("p3led_kn", p3led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P3LED_KN), - GRP_G("p4led_kn", p4led_kn_grp_mt7628, MT7628_GPIO_MODE_MASK, - 1, MT7628_GPIO_MODE_P4LED_KN), +#define MT76X8_GPIO_MODE_MASK 0x3 + +#define MT76X8_GPIO_MODE_P4LED_KN 58 +#define MT76X8_GPIO_MODE_P3LED_KN 56 +#define MT76X8_GPIO_MODE_P2LED_KN 54 +#define MT76X8_GPIO_MODE_P1LED_KN 52 +#define MT76X8_GPIO_MODE_P0LED_KN 50 +#define MT76X8_GPIO_MODE_WLED_KN 48 +#define MT76X8_GPIO_MODE_P4LED_AN 42 +#define MT76X8_GPIO_MODE_P3LED_AN 40 +#define MT76X8_GPIO_MODE_P2LED_AN 38 +#define MT76X8_GPIO_MODE_P1LED_AN 36 +#define MT76X8_GPIO_MODE_P0LED_AN 34 +#define MT76X8_GPIO_MODE_WLED_AN 32 +#define MT76X8_GPIO_MODE_PWM1 30 +#define MT76X8_GPIO_MODE_PWM0 28 +#define MT76X8_GPIO_MODE_UART2 26 +#define MT76X8_GPIO_MODE_UART1 24 +#define MT76X8_GPIO_MODE_I2C 20 +#define MT76X8_GPIO_MODE_REFCLK 18 +#define MT76X8_GPIO_MODE_PERST 16 +#define MT76X8_GPIO_MODE_WDT 14 +#define MT76X8_GPIO_MODE_SPI 12 +#define MT76X8_GPIO_MODE_SDMODE 10 +#define MT76X8_GPIO_MODE_UART0 8 +#define MT76X8_GPIO_MODE_I2S 6 +#define MT76X8_GPIO_MODE_CS1 4 +#define MT76X8_GPIO_MODE_SPIS 2 +#define MT76X8_GPIO_MODE_GPIO 0 + +static struct rt2880_pmx_group mt76x8_pinmux_data[] =3D { + GRP_G("pwm1", pwm1_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_PWM1), + GRP_G("pwm0", pwm0_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_PWM0), + GRP_G("uart2", uart2_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_UART2), + GRP_G("uart1", uart1_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_UART1), + GRP_G("i2c", i2c_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_I2C), + GRP("refclk", refclk_grp_mt76x8, 1, MT76X8_GPIO_MODE_REFCLK), + GRP("perst", perst_grp_mt76x8, 1, MT76X8_GPIO_MODE_PERST), + GRP("wdt", wdt_grp_mt76x8, 1, MT76X8_GPIO_MODE_WDT), + GRP("spi", spi_grp_mt76x8, 1, MT76X8_GPIO_MODE_SPI), + GRP_G("sdmode", sd_mode_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_SDMODE), + GRP_G("uart0", uart0_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_UART0), + GRP_G("i2s", i2s_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_I2S), + GRP_G("spi cs1", spi_cs1_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_CS1), + GRP_G("spis", spis_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_SPIS), + GRP_G("gpio", gpio_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_GPIO), + GRP_G("wled_an", wled_an_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_WLED_AN), + GRP_G("p0led_an", p0led_an_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P0LED_AN), + GRP_G("p1led_an", p1led_an_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P1LED_AN), + GRP_G("p2led_an", p2led_an_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P2LED_AN), + GRP_G("p3led_an", p3led_an_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P3LED_AN), + GRP_G("p4led_an", p4led_an_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P4LED_AN), + GRP_G("wled_kn", wled_kn_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_WLED_KN), + GRP_G("p0led_kn", p0led_kn_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P0LED_KN), + GRP_G("p1led_kn", p1led_kn_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P1LED_KN), + GRP_G("p2led_kn", p2led_kn_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P2LED_KN), + GRP_G("p3led_kn", p3led_kn_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P3LED_KN), + GRP_G("p4led_kn", p4led_kn_grp_mt76x8, MT76X8_GPIO_MODE_MASK, + 1, MT76X8_GPIO_MODE_P4LED_KN), { 0 } }; =20 static int mt7620_pinmux_probe(struct platform_device *pdev) { if (is_mt76x8()) - return rt2880_pinmux_init(pdev, mt7628an_pinmux_data); + return rt2880_pinmux_init(pdev, mt76x8_pinmux_data); else return rt2880_pinmux_init(pdev, mt7620a_pinmux_data); } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01EADC19F2B for ; Wed, 27 Jul 2022 17:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237183AbiG0RDI (ORCPT ); Wed, 27 Jul 2022 13:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbiG0RCi (ORCPT ); Wed, 27 Jul 2022 13:02:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646666C13E; Wed, 27 Jul 2022 09:38:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B5D23B821A6; Wed, 27 Jul 2022 16:38:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3B63C433C1; Wed, 27 Jul 2022 16:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939900; bh=7+QOaPl6X2wUo779kjghaLkfqQGV8c0zdFf9/rbyZD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tez8VNiVeDmIW6U4AWIlTmahWlAbbJJUUDWHWToE3c4dUyr4BEi1nwogEpACxailM NSIGwT93aNgJX7BbEP6ZIEHz9NZ51RobjDdaKrSoMCVHkxk5TppsWhjo3mfKhZgZ9B DH+XF0pR1YcF+Akm1186XN/od7R9cCTt6DslbVGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= , Sergio Paracuellos , Linus Walleij , Sasha Levin Subject: [PATCH 5.15 034/201] pinctrl: ralink: rename pinctrl-rt2880 to pinctrl-ralink Date: Wed, 27 Jul 2022 18:08:58 +0200 Message-Id: <20220727161028.284052945@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ar=C4=B1n=C3=A7 =C3=9CNAL [ Upstream commit 6b3dd85b0bdec1a8308fa5dcbafcd5d55b5f3608 ] pinctrl-rt2880.c and pinmux.h make up the Ralink pinctrl driver. Rename pinctrl-rt2880.c to pinctrl-ralink.c. Rename pinmux.h to pinctrl-ralink.h. Fix references to it. Rename functions that include "rt2880" to "ralink". Remove PINCTRL_RT2880 symbol and make the existing PINCTRL_RALINK symbol compile pinctrl-ralink.c. Change the bool to "Ralink pinctrl driver". Signed-off-by: Ar=C4=B1n=C3=A7 =C3=9CNAL Reviewed-by: Sergio Paracuellos Acked-by: Sergio Paracuellos Link: https://lore.kernel.org/r/20220414173916.5552-3-arinc.unal@arinc9.com Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/ralink/Kconfig | 16 ++-- drivers/pinctrl/ralink/Makefile | 2 +- drivers/pinctrl/ralink/pinctrl-mt7620.c | 92 +++++++++---------- drivers/pinctrl/ralink/pinctrl-mt7621.c | 30 +++--- .../{pinctrl-rt2880.c =3D> pinctrl-ralink.c} | 90 +++++++++--------- .../ralink/{pinmux.h =3D> pinctrl-ralink.h} | 16 ++-- drivers/pinctrl/ralink/pinctrl-rt288x.c | 20 ++-- drivers/pinctrl/ralink/pinctrl-rt305x.c | 44 ++++----- drivers/pinctrl/ralink/pinctrl-rt3883.c | 28 +++--- 9 files changed, 167 insertions(+), 171 deletions(-) rename drivers/pinctrl/ralink/{pinctrl-rt2880.c =3D> pinctrl-ralink.c} (73= %) rename drivers/pinctrl/ralink/{pinmux.h =3D> pinctrl-ralink.h} (75%) diff --git a/drivers/pinctrl/ralink/Kconfig b/drivers/pinctrl/ralink/Kconfig index a76ee3deb8c3..d0f0a8f2b9b7 100644 --- a/drivers/pinctrl/ralink/Kconfig +++ b/drivers/pinctrl/ralink/Kconfig @@ -3,37 +3,33 @@ menu "Ralink pinctrl drivers" depends on RALINK =20 config PINCTRL_RALINK - bool "Ralink pin control support" - default y if RALINK - -config PINCTRL_RT2880 - bool "RT2880 pinctrl driver for RALINK/Mediatek SOCs" + bool "Ralink pinctrl driver" select PINMUX select GENERIC_PINCONF =20 config PINCTRL_MT7620 bool "mt7620 pinctrl driver for RALINK/Mediatek SOCs" depends on RALINK && SOC_MT7620 - select PINCTRL_RT2880 + select PINCTRL_RALINK =20 config PINCTRL_MT7621 bool "mt7621 pinctrl driver for RALINK/Mediatek SOCs" depends on RALINK && SOC_MT7621 - select PINCTRL_RT2880 + select PINCTRL_RALINK =20 config PINCTRL_RT288X bool "RT288X pinctrl driver for RALINK/Mediatek SOCs" depends on RALINK && SOC_RT288X - select PINCTRL_RT2880 + select PINCTRL_RALINK =20 config PINCTRL_RT305X bool "RT305X pinctrl driver for RALINK/Mediatek SOCs" depends on RALINK && SOC_RT305X - select PINCTRL_RT2880 + select PINCTRL_RALINK =20 config PINCTRL_RT3883 bool "RT3883 pinctrl driver for RALINK/Mediatek SOCs" depends on RALINK && SOC_RT3883 - select PINCTRL_RT2880 + select PINCTRL_RALINK =20 endmenu diff --git a/drivers/pinctrl/ralink/Makefile b/drivers/pinctrl/ralink/Makef= ile index a15610206ced..2c1323b74e96 100644 --- a/drivers/pinctrl/ralink/Makefile +++ b/drivers/pinctrl/ralink/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_PINCTRL_RT2880) +=3D pinctrl-rt2880.o +obj-$(CONFIG_PINCTRL_RALINK) +=3D pinctrl-ralink.o =20 obj-$(CONFIG_PINCTRL_MT7620) +=3D pinctrl-mt7620.o obj-$(CONFIG_PINCTRL_MT7621) +=3D pinctrl-mt7621.o diff --git a/drivers/pinctrl/ralink/pinctrl-mt7620.c b/drivers/pinctrl/rali= nk/pinctrl-mt7620.c index d3f9feec1f74..51b863d85c51 100644 --- a/drivers/pinctrl/ralink/pinctrl-mt7620.c +++ b/drivers/pinctrl/ralink/pinctrl-mt7620.c @@ -5,7 +5,7 @@ #include #include #include -#include "pinmux.h" +#include "pinctrl-ralink.h" =20 #define MT7620_GPIO_MODE_UART0_SHIFT 2 #define MT7620_GPIO_MODE_UART0_MASK 0x7 @@ -54,20 +54,20 @@ #define MT7620_GPIO_MODE_EPHY 15 #define MT7620_GPIO_MODE_PA 20 =20 -static struct rt2880_pmx_func i2c_grp[] =3D { FUNC("i2c", 0, 1, 2) }; -static struct rt2880_pmx_func spi_grp[] =3D { FUNC("spi", 0, 3, 4) }; -static struct rt2880_pmx_func uartlite_grp[] =3D { FUNC("uartlite", 0, 15,= 2) }; -static struct rt2880_pmx_func mdio_grp[] =3D { +static struct ralink_pmx_func i2c_grp[] =3D { FUNC("i2c", 0, 1, 2) }; +static struct ralink_pmx_func spi_grp[] =3D { FUNC("spi", 0, 3, 4) }; +static struct ralink_pmx_func uartlite_grp[] =3D { FUNC("uartlite", 0, 15,= 2) }; +static struct ralink_pmx_func mdio_grp[] =3D { FUNC("mdio", MT7620_GPIO_MODE_MDIO, 22, 2), FUNC("refclk", MT7620_GPIO_MODE_MDIO_REFCLK, 22, 2), }; -static struct rt2880_pmx_func rgmii1_grp[] =3D { FUNC("rgmii1", 0, 24, 12)= }; -static struct rt2880_pmx_func refclk_grp[] =3D { FUNC("spi refclk", 0, 37,= 3) }; -static struct rt2880_pmx_func ephy_grp[] =3D { FUNC("ephy", 0, 40, 5) }; -static struct rt2880_pmx_func rgmii2_grp[] =3D { FUNC("rgmii2", 0, 60, 12)= }; -static struct rt2880_pmx_func wled_grp[] =3D { FUNC("wled", 0, 72, 1) }; -static struct rt2880_pmx_func pa_grp[] =3D { FUNC("pa", 0, 18, 4) }; -static struct rt2880_pmx_func uartf_grp[] =3D { +static struct ralink_pmx_func rgmii1_grp[] =3D { FUNC("rgmii1", 0, 24, 12)= }; +static struct ralink_pmx_func refclk_grp[] =3D { FUNC("spi refclk", 0, 37,= 3) }; +static struct ralink_pmx_func ephy_grp[] =3D { FUNC("ephy", 0, 40, 5) }; +static struct ralink_pmx_func rgmii2_grp[] =3D { FUNC("rgmii2", 0, 60, 12)= }; +static struct ralink_pmx_func wled_grp[] =3D { FUNC("wled", 0, 72, 1) }; +static struct ralink_pmx_func pa_grp[] =3D { FUNC("pa", 0, 18, 4) }; +static struct ralink_pmx_func uartf_grp[] =3D { FUNC("uartf", MT7620_GPIO_MODE_UARTF, 7, 8), FUNC("pcm uartf", MT7620_GPIO_MODE_PCM_UARTF, 7, 8), FUNC("pcm i2s", MT7620_GPIO_MODE_PCM_I2S, 7, 8), @@ -76,20 +76,20 @@ static struct rt2880_pmx_func uartf_grp[] =3D { FUNC("gpio uartf", MT7620_GPIO_MODE_GPIO_UARTF, 7, 4), FUNC("gpio i2s", MT7620_GPIO_MODE_GPIO_I2S, 7, 4), }; -static struct rt2880_pmx_func wdt_grp[] =3D { +static struct ralink_pmx_func wdt_grp[] =3D { FUNC("wdt rst", 0, 17, 1), FUNC("wdt refclk", 0, 17, 1), }; -static struct rt2880_pmx_func pcie_rst_grp[] =3D { +static struct ralink_pmx_func pcie_rst_grp[] =3D { FUNC("pcie rst", MT7620_GPIO_MODE_PCIE_RST, 36, 1), FUNC("pcie refclk", MT7620_GPIO_MODE_PCIE_REF, 36, 1) }; -static struct rt2880_pmx_func nd_sd_grp[] =3D { +static struct ralink_pmx_func nd_sd_grp[] =3D { FUNC("nand", MT7620_GPIO_MODE_NAND, 45, 15), FUNC("sd", MT7620_GPIO_MODE_SD, 47, 13) }; =20 -static struct rt2880_pmx_group mt7620a_pinmux_data[] =3D { +static struct ralink_pmx_group mt7620a_pinmux_data[] =3D { GRP("i2c", i2c_grp, 1, MT7620_GPIO_MODE_I2C), GRP("uartf", uartf_grp, MT7620_GPIO_MODE_UART0_MASK, MT7620_GPIO_MODE_UART0_SHIFT), @@ -112,166 +112,166 @@ static struct rt2880_pmx_group mt7620a_pinmux_data[= ] =3D { { 0 } }; =20 -static struct rt2880_pmx_func pwm1_grp_mt76x8[] =3D { +static struct ralink_pmx_func pwm1_grp_mt76x8[] =3D { FUNC("sdxc d6", 3, 19, 1), FUNC("utif", 2, 19, 1), FUNC("gpio", 1, 19, 1), FUNC("pwm1", 0, 19, 1), }; =20 -static struct rt2880_pmx_func pwm0_grp_mt76x8[] =3D { +static struct ralink_pmx_func pwm0_grp_mt76x8[] =3D { FUNC("sdxc d7", 3, 18, 1), FUNC("utif", 2, 18, 1), FUNC("gpio", 1, 18, 1), FUNC("pwm0", 0, 18, 1), }; =20 -static struct rt2880_pmx_func uart2_grp_mt76x8[] =3D { +static struct ralink_pmx_func uart2_grp_mt76x8[] =3D { FUNC("sdxc d5 d4", 3, 20, 2), FUNC("pwm", 2, 20, 2), FUNC("gpio", 1, 20, 2), FUNC("uart2", 0, 20, 2), }; =20 -static struct rt2880_pmx_func uart1_grp_mt76x8[] =3D { +static struct ralink_pmx_func uart1_grp_mt76x8[] =3D { FUNC("sw_r", 3, 45, 2), FUNC("pwm", 2, 45, 2), FUNC("gpio", 1, 45, 2), FUNC("uart1", 0, 45, 2), }; =20 -static struct rt2880_pmx_func i2c_grp_mt76x8[] =3D { +static struct ralink_pmx_func i2c_grp_mt76x8[] =3D { FUNC("-", 3, 4, 2), FUNC("debug", 2, 4, 2), FUNC("gpio", 1, 4, 2), FUNC("i2c", 0, 4, 2), }; =20 -static struct rt2880_pmx_func refclk_grp_mt76x8[] =3D { FUNC("refclk", 0, = 37, 1) }; -static struct rt2880_pmx_func perst_grp_mt76x8[] =3D { FUNC("perst", 0, 36= , 1) }; -static struct rt2880_pmx_func wdt_grp_mt76x8[] =3D { FUNC("wdt", 0, 38, 1)= }; -static struct rt2880_pmx_func spi_grp_mt76x8[] =3D { FUNC("spi", 0, 7, 4) = }; +static struct ralink_pmx_func refclk_grp_mt76x8[] =3D { FUNC("refclk", 0, = 37, 1) }; +static struct ralink_pmx_func perst_grp_mt76x8[] =3D { FUNC("perst", 0, 36= , 1) }; +static struct ralink_pmx_func wdt_grp_mt76x8[] =3D { FUNC("wdt", 0, 38, 1)= }; +static struct ralink_pmx_func spi_grp_mt76x8[] =3D { FUNC("spi", 0, 7, 4) = }; =20 -static struct rt2880_pmx_func sd_mode_grp_mt76x8[] =3D { +static struct ralink_pmx_func sd_mode_grp_mt76x8[] =3D { FUNC("jtag", 3, 22, 8), FUNC("utif", 2, 22, 8), FUNC("gpio", 1, 22, 8), FUNC("sdxc", 0, 22, 8), }; =20 -static struct rt2880_pmx_func uart0_grp_mt76x8[] =3D { +static struct ralink_pmx_func uart0_grp_mt76x8[] =3D { FUNC("-", 3, 12, 2), FUNC("-", 2, 12, 2), FUNC("gpio", 1, 12, 2), FUNC("uart0", 0, 12, 2), }; =20 -static struct rt2880_pmx_func i2s_grp_mt76x8[] =3D { +static struct ralink_pmx_func i2s_grp_mt76x8[] =3D { FUNC("antenna", 3, 0, 4), FUNC("pcm", 2, 0, 4), FUNC("gpio", 1, 0, 4), FUNC("i2s", 0, 0, 4), }; =20 -static struct rt2880_pmx_func spi_cs1_grp_mt76x8[] =3D { +static struct ralink_pmx_func spi_cs1_grp_mt76x8[] =3D { FUNC("-", 3, 6, 1), FUNC("refclk", 2, 6, 1), FUNC("gpio", 1, 6, 1), FUNC("spi cs1", 0, 6, 1), }; =20 -static struct rt2880_pmx_func spis_grp_mt76x8[] =3D { +static struct ralink_pmx_func spis_grp_mt76x8[] =3D { FUNC("pwm_uart2", 3, 14, 4), FUNC("utif", 2, 14, 4), FUNC("gpio", 1, 14, 4), FUNC("spis", 0, 14, 4), }; =20 -static struct rt2880_pmx_func gpio_grp_mt76x8[] =3D { +static struct ralink_pmx_func gpio_grp_mt76x8[] =3D { FUNC("pcie", 3, 11, 1), FUNC("refclk", 2, 11, 1), FUNC("gpio", 1, 11, 1), FUNC("gpio", 0, 11, 1), }; =20 -static struct rt2880_pmx_func p4led_kn_grp_mt76x8[] =3D { +static struct ralink_pmx_func p4led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 30, 1), FUNC("utif", 2, 30, 1), FUNC("gpio", 1, 30, 1), FUNC("p4led_kn", 0, 30, 1), }; =20 -static struct rt2880_pmx_func p3led_kn_grp_mt76x8[] =3D { +static struct ralink_pmx_func p3led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 31, 1), FUNC("utif", 2, 31, 1), FUNC("gpio", 1, 31, 1), FUNC("p3led_kn", 0, 31, 1), }; =20 -static struct rt2880_pmx_func p2led_kn_grp_mt76x8[] =3D { +static struct ralink_pmx_func p2led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 32, 1), FUNC("utif", 2, 32, 1), FUNC("gpio", 1, 32, 1), FUNC("p2led_kn", 0, 32, 1), }; =20 -static struct rt2880_pmx_func p1led_kn_grp_mt76x8[] =3D { +static struct ralink_pmx_func p1led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 33, 1), FUNC("utif", 2, 33, 1), FUNC("gpio", 1, 33, 1), FUNC("p1led_kn", 0, 33, 1), }; =20 -static struct rt2880_pmx_func p0led_kn_grp_mt76x8[] =3D { +static struct ralink_pmx_func p0led_kn_grp_mt76x8[] =3D { FUNC("jtag", 3, 34, 1), FUNC("rsvd", 2, 34, 1), FUNC("gpio", 1, 34, 1), FUNC("p0led_kn", 0, 34, 1), }; =20 -static struct rt2880_pmx_func wled_kn_grp_mt76x8[] =3D { +static struct ralink_pmx_func wled_kn_grp_mt76x8[] =3D { FUNC("rsvd", 3, 35, 1), FUNC("rsvd", 2, 35, 1), FUNC("gpio", 1, 35, 1), FUNC("wled_kn", 0, 35, 1), }; =20 -static struct rt2880_pmx_func p4led_an_grp_mt76x8[] =3D { +static struct ralink_pmx_func p4led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 39, 1), FUNC("utif", 2, 39, 1), FUNC("gpio", 1, 39, 1), FUNC("p4led_an", 0, 39, 1), }; =20 -static struct rt2880_pmx_func p3led_an_grp_mt76x8[] =3D { +static struct ralink_pmx_func p3led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 40, 1), FUNC("utif", 2, 40, 1), FUNC("gpio", 1, 40, 1), FUNC("p3led_an", 0, 40, 1), }; =20 -static struct rt2880_pmx_func p2led_an_grp_mt76x8[] =3D { +static struct ralink_pmx_func p2led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 41, 1), FUNC("utif", 2, 41, 1), FUNC("gpio", 1, 41, 1), FUNC("p2led_an", 0, 41, 1), }; =20 -static struct rt2880_pmx_func p1led_an_grp_mt76x8[] =3D { +static struct ralink_pmx_func p1led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 42, 1), FUNC("utif", 2, 42, 1), FUNC("gpio", 1, 42, 1), FUNC("p1led_an", 0, 42, 1), }; =20 -static struct rt2880_pmx_func p0led_an_grp_mt76x8[] =3D { +static struct ralink_pmx_func p0led_an_grp_mt76x8[] =3D { FUNC("jtag", 3, 43, 1), FUNC("rsvd", 2, 43, 1), FUNC("gpio", 1, 43, 1), FUNC("p0led_an", 0, 43, 1), }; =20 -static struct rt2880_pmx_func wled_an_grp_mt76x8[] =3D { +static struct ralink_pmx_func wled_an_grp_mt76x8[] =3D { FUNC("rsvd", 3, 44, 1), FUNC("rsvd", 2, 44, 1), FUNC("gpio", 1, 44, 1), @@ -308,7 +308,7 @@ static struct rt2880_pmx_func wled_an_grp_mt76x8[] =3D { #define MT76X8_GPIO_MODE_SPIS 2 #define MT76X8_GPIO_MODE_GPIO 0 =20 -static struct rt2880_pmx_group mt76x8_pinmux_data[] =3D { +static struct ralink_pmx_group mt76x8_pinmux_data[] =3D { GRP_G("pwm1", pwm1_grp_mt76x8, MT76X8_GPIO_MODE_MASK, 1, MT76X8_GPIO_MODE_PWM1), GRP_G("pwm0", pwm0_grp_mt76x8, MT76X8_GPIO_MODE_MASK, @@ -365,9 +365,9 @@ static struct rt2880_pmx_group mt76x8_pinmux_data[] =3D= { static int mt7620_pinmux_probe(struct platform_device *pdev) { if (is_mt76x8()) - return rt2880_pinmux_init(pdev, mt76x8_pinmux_data); + return ralink_pinmux_init(pdev, mt76x8_pinmux_data); else - return rt2880_pinmux_init(pdev, mt7620a_pinmux_data); + return ralink_pinmux_init(pdev, mt7620a_pinmux_data); } =20 static const struct of_device_id mt7620_pinmux_match[] =3D { diff --git a/drivers/pinctrl/ralink/pinctrl-mt7621.c b/drivers/pinctrl/rali= nk/pinctrl-mt7621.c index 7d96144c474e..14b89cb43d4c 100644 --- a/drivers/pinctrl/ralink/pinctrl-mt7621.c +++ b/drivers/pinctrl/ralink/pinctrl-mt7621.c @@ -3,7 +3,7 @@ #include #include #include -#include "pinmux.h" +#include "pinctrl-ralink.h" =20 #define MT7621_GPIO_MODE_UART1 1 #define MT7621_GPIO_MODE_I2C 2 @@ -34,40 +34,40 @@ #define MT7621_GPIO_MODE_SDHCI_SHIFT 18 #define MT7621_GPIO_MODE_SDHCI_GPIO 1 =20 -static struct rt2880_pmx_func uart1_grp[] =3D { FUNC("uart1", 0, 1, 2) }; -static struct rt2880_pmx_func i2c_grp[] =3D { FUNC("i2c", 0, 3, 2) }; -static struct rt2880_pmx_func uart3_grp[] =3D { +static struct ralink_pmx_func uart1_grp[] =3D { FUNC("uart1", 0, 1, 2) }; +static struct ralink_pmx_func i2c_grp[] =3D { FUNC("i2c", 0, 3, 2) }; +static struct ralink_pmx_func uart3_grp[] =3D { FUNC("uart3", 0, 5, 4), FUNC("i2s", 2, 5, 4), FUNC("spdif3", 3, 5, 4), }; -static struct rt2880_pmx_func uart2_grp[] =3D { +static struct ralink_pmx_func uart2_grp[] =3D { FUNC("uart2", 0, 9, 4), FUNC("pcm", 2, 9, 4), FUNC("spdif2", 3, 9, 4), }; -static struct rt2880_pmx_func jtag_grp[] =3D { FUNC("jtag", 0, 13, 5) }; -static struct rt2880_pmx_func wdt_grp[] =3D { +static struct ralink_pmx_func jtag_grp[] =3D { FUNC("jtag", 0, 13, 5) }; +static struct ralink_pmx_func wdt_grp[] =3D { FUNC("wdt rst", 0, 18, 1), FUNC("wdt refclk", 2, 18, 1), }; -static struct rt2880_pmx_func pcie_rst_grp[] =3D { +static struct ralink_pmx_func pcie_rst_grp[] =3D { FUNC("pcie rst", MT7621_GPIO_MODE_PCIE_RST, 19, 1), FUNC("pcie refclk", MT7621_GPIO_MODE_PCIE_REF, 19, 1) }; -static struct rt2880_pmx_func mdio_grp[] =3D { FUNC("mdio", 0, 20, 2) }; -static struct rt2880_pmx_func rgmii2_grp[] =3D { FUNC("rgmii2", 0, 22, 12)= }; -static struct rt2880_pmx_func spi_grp[] =3D { +static struct ralink_pmx_func mdio_grp[] =3D { FUNC("mdio", 0, 20, 2) }; +static struct ralink_pmx_func rgmii2_grp[] =3D { FUNC("rgmii2", 0, 22, 12)= }; +static struct ralink_pmx_func spi_grp[] =3D { FUNC("spi", 0, 34, 7), FUNC("nand1", 2, 34, 7), }; -static struct rt2880_pmx_func sdhci_grp[] =3D { +static struct ralink_pmx_func sdhci_grp[] =3D { FUNC("sdhci", 0, 41, 8), FUNC("nand2", 2, 41, 8), }; -static struct rt2880_pmx_func rgmii1_grp[] =3D { FUNC("rgmii1", 0, 49, 12)= }; +static struct ralink_pmx_func rgmii1_grp[] =3D { FUNC("rgmii1", 0, 49, 12)= }; =20 -static struct rt2880_pmx_group mt7621_pinmux_data[] =3D { +static struct ralink_pmx_group mt7621_pinmux_data[] =3D { GRP("uart1", uart1_grp, 1, MT7621_GPIO_MODE_UART1), GRP("i2c", i2c_grp, 1, MT7621_GPIO_MODE_I2C), GRP_G("uart3", uart3_grp, MT7621_GPIO_MODE_UART3_MASK, @@ -92,7 +92,7 @@ static struct rt2880_pmx_group mt7621_pinmux_data[] =3D { =20 static int mt7621_pinmux_probe(struct platform_device *pdev) { - return rt2880_pinmux_init(pdev, mt7621_pinmux_data); + return ralink_pinmux_init(pdev, mt7621_pinmux_data); } =20 static const struct of_device_id mt7621_pinmux_match[] =3D { diff --git a/drivers/pinctrl/ralink/pinctrl-rt2880.c b/drivers/pinctrl/rali= nk/pinctrl-ralink.c similarity index 73% rename from drivers/pinctrl/ralink/pinctrl-rt2880.c rename to drivers/pinctrl/ralink/pinctrl-ralink.c index 96fc06d1b8b9..841f23f55c95 100644 --- a/drivers/pinctrl/ralink/pinctrl-rt2880.c +++ b/drivers/pinctrl/ralink/pinctrl-ralink.c @@ -19,23 +19,23 @@ #include #include =20 -#include "pinmux.h" +#include "pinctrl-ralink.h" #include "../core.h" #include "../pinctrl-utils.h" =20 #define SYSC_REG_GPIO_MODE 0x60 #define SYSC_REG_GPIO_MODE2 0x64 =20 -struct rt2880_priv { +struct ralink_priv { struct device *dev; =20 struct pinctrl_pin_desc *pads; struct pinctrl_desc *desc; =20 - struct rt2880_pmx_func **func; + struct ralink_pmx_func **func; int func_count; =20 - struct rt2880_pmx_group *groups; + struct ralink_pmx_group *groups; const char **group_names; int group_count; =20 @@ -43,27 +43,27 @@ struct rt2880_priv { int max_pins; }; =20 -static int rt2880_get_group_count(struct pinctrl_dev *pctrldev) +static int ralink_get_group_count(struct pinctrl_dev *pctrldev) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); =20 return p->group_count; } =20 -static const char *rt2880_get_group_name(struct pinctrl_dev *pctrldev, +static const char *ralink_get_group_name(struct pinctrl_dev *pctrldev, unsigned int group) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); =20 return (group >=3D p->group_count) ? NULL : p->group_names[group]; } =20 -static int rt2880_get_group_pins(struct pinctrl_dev *pctrldev, +static int ralink_get_group_pins(struct pinctrl_dev *pctrldev, unsigned int group, const unsigned int **pins, unsigned int *num_pins) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); =20 if (group >=3D p->group_count) return -EINVAL; @@ -74,35 +74,35 @@ static int rt2880_get_group_pins(struct pinctrl_dev *pc= trldev, return 0; } =20 -static const struct pinctrl_ops rt2880_pctrl_ops =3D { - .get_groups_count =3D rt2880_get_group_count, - .get_group_name =3D rt2880_get_group_name, - .get_group_pins =3D rt2880_get_group_pins, +static const struct pinctrl_ops ralink_pctrl_ops =3D { + .get_groups_count =3D ralink_get_group_count, + .get_group_name =3D ralink_get_group_name, + .get_group_pins =3D ralink_get_group_pins, .dt_node_to_map =3D pinconf_generic_dt_node_to_map_all, .dt_free_map =3D pinconf_generic_dt_free_map, }; =20 -static int rt2880_pmx_func_count(struct pinctrl_dev *pctrldev) +static int ralink_pmx_func_count(struct pinctrl_dev *pctrldev) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); =20 return p->func_count; } =20 -static const char *rt2880_pmx_func_name(struct pinctrl_dev *pctrldev, +static const char *ralink_pmx_func_name(struct pinctrl_dev *pctrldev, unsigned int func) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); =20 return p->func[func]->name; } =20 -static int rt2880_pmx_group_get_groups(struct pinctrl_dev *pctrldev, +static int ralink_pmx_group_get_groups(struct pinctrl_dev *pctrldev, unsigned int func, const char * const **groups, unsigned int * const num_groups) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); =20 if (p->func[func]->group_count =3D=3D 1) *groups =3D &p->group_names[p->func[func]->groups[0]]; @@ -114,10 +114,10 @@ static int rt2880_pmx_group_get_groups(struct pinctrl= _dev *pctrldev, return 0; } =20 -static int rt2880_pmx_group_enable(struct pinctrl_dev *pctrldev, +static int ralink_pmx_group_enable(struct pinctrl_dev *pctrldev, unsigned int func, unsigned int group) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); u32 mode =3D 0; u32 reg =3D SYSC_REG_GPIO_MODE; int i; @@ -158,11 +158,11 @@ static int rt2880_pmx_group_enable(struct pinctrl_dev= *pctrldev, return 0; } =20 -static int rt2880_pmx_group_gpio_request_enable(struct pinctrl_dev *pctrld= ev, +static int ralink_pmx_group_gpio_request_enable(struct pinctrl_dev *pctrld= ev, struct pinctrl_gpio_range *range, unsigned int pin) { - struct rt2880_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); + struct ralink_priv *p =3D pinctrl_dev_get_drvdata(pctrldev); =20 if (!p->gpio[pin]) { dev_err(p->dev, "pin %d is not set to gpio mux\n", pin); @@ -172,28 +172,28 @@ static int rt2880_pmx_group_gpio_request_enable(struc= t pinctrl_dev *pctrldev, return 0; } =20 -static const struct pinmux_ops rt2880_pmx_group_ops =3D { - .get_functions_count =3D rt2880_pmx_func_count, - .get_function_name =3D rt2880_pmx_func_name, - .get_function_groups =3D rt2880_pmx_group_get_groups, - .set_mux =3D rt2880_pmx_group_enable, - .gpio_request_enable =3D rt2880_pmx_group_gpio_request_enable, +static const struct pinmux_ops ralink_pmx_group_ops =3D { + .get_functions_count =3D ralink_pmx_func_count, + .get_function_name =3D ralink_pmx_func_name, + .get_function_groups =3D ralink_pmx_group_get_groups, + .set_mux =3D ralink_pmx_group_enable, + .gpio_request_enable =3D ralink_pmx_group_gpio_request_enable, }; =20 -static struct pinctrl_desc rt2880_pctrl_desc =3D { +static struct pinctrl_desc ralink_pctrl_desc =3D { .owner =3D THIS_MODULE, - .name =3D "rt2880-pinmux", - .pctlops =3D &rt2880_pctrl_ops, - .pmxops =3D &rt2880_pmx_group_ops, + .name =3D "ralink-pinmux", + .pctlops =3D &ralink_pctrl_ops, + .pmxops =3D &ralink_pmx_group_ops, }; =20 -static struct rt2880_pmx_func gpio_func =3D { +static struct ralink_pmx_func gpio_func =3D { .name =3D "gpio", }; =20 -static int rt2880_pinmux_index(struct rt2880_priv *p) +static int ralink_pinmux_index(struct ralink_priv *p) { - struct rt2880_pmx_group *mux =3D p->groups; + struct ralink_pmx_group *mux =3D p->groups; int i, j, c =3D 0; =20 /* count the mux functions */ @@ -248,7 +248,7 @@ static int rt2880_pinmux_index(struct rt2880_priv *p) return 0; } =20 -static int rt2880_pinmux_pins(struct rt2880_priv *p) +static int ralink_pinmux_pins(struct ralink_priv *p) { int i, j; =20 @@ -311,10 +311,10 @@ static int rt2880_pinmux_pins(struct rt2880_priv *p) return 0; } =20 -int rt2880_pinmux_init(struct platform_device *pdev, - struct rt2880_pmx_group *data) +int ralink_pinmux_init(struct platform_device *pdev, + struct ralink_pmx_group *data) { - struct rt2880_priv *p; + struct ralink_priv *p; struct pinctrl_dev *dev; int err; =20 @@ -322,23 +322,23 @@ int rt2880_pinmux_init(struct platform_device *pdev, return -ENOTSUPP; =20 /* setup the private data */ - p =3D devm_kzalloc(&pdev->dev, sizeof(struct rt2880_priv), GFP_KERNEL); + p =3D devm_kzalloc(&pdev->dev, sizeof(struct ralink_priv), GFP_KERNEL); if (!p) return -ENOMEM; =20 p->dev =3D &pdev->dev; - p->desc =3D &rt2880_pctrl_desc; + p->desc =3D &ralink_pctrl_desc; p->groups =3D data; platform_set_drvdata(pdev, p); =20 /* init the device */ - err =3D rt2880_pinmux_index(p); + err =3D ralink_pinmux_index(p); if (err) { dev_err(&pdev->dev, "failed to load index\n"); return err; } =20 - err =3D rt2880_pinmux_pins(p); + err =3D ralink_pinmux_pins(p); if (err) { dev_err(&pdev->dev, "failed to load pins\n"); return err; diff --git a/drivers/pinctrl/ralink/pinmux.h b/drivers/pinctrl/ralink/pinct= rl-ralink.h similarity index 75% rename from drivers/pinctrl/ralink/pinmux.h rename to drivers/pinctrl/ralink/pinctrl-ralink.h index 0046abe3bcc7..134969409585 100644 --- a/drivers/pinctrl/ralink/pinmux.h +++ b/drivers/pinctrl/ralink/pinctrl-ralink.h @@ -3,8 +3,8 @@ * Copyright (C) 2012 John Crispin */ =20 -#ifndef _RT288X_PINMUX_H__ -#define _RT288X_PINMUX_H__ +#ifndef _PINCTRL_RALINK_H__ +#define _PINCTRL_RALINK_H__ =20 #define FUNC(name, value, pin_first, pin_count) \ { name, value, pin_first, pin_count } @@ -19,9 +19,9 @@ .func =3D _func, .gpio =3D _gpio, \ .func_count =3D ARRAY_SIZE(_func) } =20 -struct rt2880_pmx_group; +struct ralink_pmx_group; =20 -struct rt2880_pmx_func { +struct ralink_pmx_func { const char *name; const char value; =20 @@ -35,7 +35,7 @@ struct rt2880_pmx_func { int enabled; }; =20 -struct rt2880_pmx_group { +struct ralink_pmx_group { const char *name; int enabled; =20 @@ -43,11 +43,11 @@ struct rt2880_pmx_group { const char mask; const char gpio; =20 - struct rt2880_pmx_func *func; + struct ralink_pmx_func *func; int func_count; }; =20 -int rt2880_pinmux_init(struct platform_device *pdev, - struct rt2880_pmx_group *data); +int ralink_pinmux_init(struct platform_device *pdev, + struct ralink_pmx_group *data); =20 #endif diff --git a/drivers/pinctrl/ralink/pinctrl-rt288x.c b/drivers/pinctrl/rali= nk/pinctrl-rt288x.c index 0744aebbace5..40c45140ff8a 100644 --- a/drivers/pinctrl/ralink/pinctrl-rt288x.c +++ b/drivers/pinctrl/ralink/pinctrl-rt288x.c @@ -4,7 +4,7 @@ #include #include #include -#include "pinmux.h" +#include "pinctrl-ralink.h" =20 #define RT2880_GPIO_MODE_I2C BIT(0) #define RT2880_GPIO_MODE_UART0 BIT(1) @@ -15,15 +15,15 @@ #define RT2880_GPIO_MODE_SDRAM BIT(6) #define RT2880_GPIO_MODE_PCI BIT(7) =20 -static struct rt2880_pmx_func i2c_func[] =3D { FUNC("i2c", 0, 1, 2) }; -static struct rt2880_pmx_func spi_func[] =3D { FUNC("spi", 0, 3, 4) }; -static struct rt2880_pmx_func uartlite_func[] =3D { FUNC("uartlite", 0, 7,= 8) }; -static struct rt2880_pmx_func jtag_func[] =3D { FUNC("jtag", 0, 17, 5) }; -static struct rt2880_pmx_func mdio_func[] =3D { FUNC("mdio", 0, 22, 2) }; -static struct rt2880_pmx_func sdram_func[] =3D { FUNC("sdram", 0, 24, 16) = }; -static struct rt2880_pmx_func pci_func[] =3D { FUNC("pci", 0, 40, 32) }; +static struct ralink_pmx_func i2c_func[] =3D { FUNC("i2c", 0, 1, 2) }; +static struct ralink_pmx_func spi_func[] =3D { FUNC("spi", 0, 3, 4) }; +static struct ralink_pmx_func uartlite_func[] =3D { FUNC("uartlite", 0, 7,= 8) }; +static struct ralink_pmx_func jtag_func[] =3D { FUNC("jtag", 0, 17, 5) }; +static struct ralink_pmx_func mdio_func[] =3D { FUNC("mdio", 0, 22, 2) }; +static struct ralink_pmx_func sdram_func[] =3D { FUNC("sdram", 0, 24, 16) = }; +static struct ralink_pmx_func pci_func[] =3D { FUNC("pci", 0, 40, 32) }; =20 -static struct rt2880_pmx_group rt2880_pinmux_data_act[] =3D { +static struct ralink_pmx_group rt2880_pinmux_data_act[] =3D { GRP("i2c", i2c_func, 1, RT2880_GPIO_MODE_I2C), GRP("spi", spi_func, 1, RT2880_GPIO_MODE_SPI), GRP("uartlite", uartlite_func, 1, RT2880_GPIO_MODE_UART0), @@ -36,7 +36,7 @@ static struct rt2880_pmx_group rt2880_pinmux_data_act[] = =3D { =20 static int rt288x_pinmux_probe(struct platform_device *pdev) { - return rt2880_pinmux_init(pdev, rt2880_pinmux_data_act); + return ralink_pinmux_init(pdev, rt2880_pinmux_data_act); } =20 static const struct of_device_id rt288x_pinmux_match[] =3D { diff --git a/drivers/pinctrl/ralink/pinctrl-rt305x.c b/drivers/pinctrl/rali= nk/pinctrl-rt305x.c index 5d8fa156c003..25527ca1ccaa 100644 --- a/drivers/pinctrl/ralink/pinctrl-rt305x.c +++ b/drivers/pinctrl/ralink/pinctrl-rt305x.c @@ -5,7 +5,7 @@ #include #include #include -#include "pinmux.h" +#include "pinctrl-ralink.h" =20 #define RT305X_GPIO_MODE_UART0_SHIFT 2 #define RT305X_GPIO_MODE_UART0_MASK 0x7 @@ -31,9 +31,9 @@ #define RT3352_GPIO_MODE_LNA 18 #define RT3352_GPIO_MODE_PA 20 =20 -static struct rt2880_pmx_func i2c_func[] =3D { FUNC("i2c", 0, 1, 2) }; -static struct rt2880_pmx_func spi_func[] =3D { FUNC("spi", 0, 3, 4) }; -static struct rt2880_pmx_func uartf_func[] =3D { +static struct ralink_pmx_func i2c_func[] =3D { FUNC("i2c", 0, 1, 2) }; +static struct ralink_pmx_func spi_func[] =3D { FUNC("spi", 0, 3, 4) }; +static struct ralink_pmx_func uartf_func[] =3D { FUNC("uartf", RT305X_GPIO_MODE_UARTF, 7, 8), FUNC("pcm uartf", RT305X_GPIO_MODE_PCM_UARTF, 7, 8), FUNC("pcm i2s", RT305X_GPIO_MODE_PCM_I2S, 7, 8), @@ -42,28 +42,28 @@ static struct rt2880_pmx_func uartf_func[] =3D { FUNC("gpio uartf", RT305X_GPIO_MODE_GPIO_UARTF, 7, 4), FUNC("gpio i2s", RT305X_GPIO_MODE_GPIO_I2S, 7, 4), }; -static struct rt2880_pmx_func uartlite_func[] =3D { FUNC("uartlite", 0, 15= , 2) }; -static struct rt2880_pmx_func jtag_func[] =3D { FUNC("jtag", 0, 17, 5) }; -static struct rt2880_pmx_func mdio_func[] =3D { FUNC("mdio", 0, 22, 2) }; -static struct rt2880_pmx_func rt5350_led_func[] =3D { FUNC("led", 0, 22, 5= ) }; -static struct rt2880_pmx_func rt5350_cs1_func[] =3D { +static struct ralink_pmx_func uartlite_func[] =3D { FUNC("uartlite", 0, 15= , 2) }; +static struct ralink_pmx_func jtag_func[] =3D { FUNC("jtag", 0, 17, 5) }; +static struct ralink_pmx_func mdio_func[] =3D { FUNC("mdio", 0, 22, 2) }; +static struct ralink_pmx_func rt5350_led_func[] =3D { FUNC("led", 0, 22, 5= ) }; +static struct ralink_pmx_func rt5350_cs1_func[] =3D { FUNC("spi_cs1", 0, 27, 1), FUNC("wdg_cs1", 1, 27, 1), }; -static struct rt2880_pmx_func sdram_func[] =3D { FUNC("sdram", 0, 24, 16) = }; -static struct rt2880_pmx_func rt3352_rgmii_func[] =3D { +static struct ralink_pmx_func sdram_func[] =3D { FUNC("sdram", 0, 24, 16) = }; +static struct ralink_pmx_func rt3352_rgmii_func[] =3D { FUNC("rgmii", 0, 24, 12) }; -static struct rt2880_pmx_func rgmii_func[] =3D { FUNC("rgmii", 0, 40, 12) = }; -static struct rt2880_pmx_func rt3352_lna_func[] =3D { FUNC("lna", 0, 36, 2= ) }; -static struct rt2880_pmx_func rt3352_pa_func[] =3D { FUNC("pa", 0, 38, 2) = }; -static struct rt2880_pmx_func rt3352_led_func[] =3D { FUNC("led", 0, 40, 5= ) }; -static struct rt2880_pmx_func rt3352_cs1_func[] =3D { +static struct ralink_pmx_func rgmii_func[] =3D { FUNC("rgmii", 0, 40, 12) = }; +static struct ralink_pmx_func rt3352_lna_func[] =3D { FUNC("lna", 0, 36, 2= ) }; +static struct ralink_pmx_func rt3352_pa_func[] =3D { FUNC("pa", 0, 38, 2) = }; +static struct ralink_pmx_func rt3352_led_func[] =3D { FUNC("led", 0, 40, 5= ) }; +static struct ralink_pmx_func rt3352_cs1_func[] =3D { FUNC("spi_cs1", 0, 45, 1), FUNC("wdg_cs1", 1, 45, 1), }; =20 -static struct rt2880_pmx_group rt3050_pinmux_data[] =3D { +static struct ralink_pmx_group rt3050_pinmux_data[] =3D { GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C), GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI), GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK, @@ -76,7 +76,7 @@ static struct rt2880_pmx_group rt3050_pinmux_data[] =3D { { 0 } }; =20 -static struct rt2880_pmx_group rt3352_pinmux_data[] =3D { +static struct ralink_pmx_group rt3352_pinmux_data[] =3D { GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C), GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI), GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK, @@ -92,7 +92,7 @@ static struct rt2880_pmx_group rt3352_pinmux_data[] =3D { { 0 } }; =20 -static struct rt2880_pmx_group rt5350_pinmux_data[] =3D { +static struct ralink_pmx_group rt5350_pinmux_data[] =3D { GRP("i2c", i2c_func, 1, RT305X_GPIO_MODE_I2C), GRP("spi", spi_func, 1, RT305X_GPIO_MODE_SPI), GRP("uartf", uartf_func, RT305X_GPIO_MODE_UART0_MASK, @@ -107,11 +107,11 @@ static struct rt2880_pmx_group rt5350_pinmux_data[] = =3D { static int rt305x_pinmux_probe(struct platform_device *pdev) { if (soc_is_rt5350()) - return rt2880_pinmux_init(pdev, rt5350_pinmux_data); + return ralink_pinmux_init(pdev, rt5350_pinmux_data); else if (soc_is_rt305x() || soc_is_rt3350()) - return rt2880_pinmux_init(pdev, rt3050_pinmux_data); + return ralink_pinmux_init(pdev, rt3050_pinmux_data); else if (soc_is_rt3352()) - return rt2880_pinmux_init(pdev, rt3352_pinmux_data); + return ralink_pinmux_init(pdev, rt3352_pinmux_data); else return -EINVAL; } diff --git a/drivers/pinctrl/ralink/pinctrl-rt3883.c b/drivers/pinctrl/rali= nk/pinctrl-rt3883.c index 3e0e1b4caa64..0b8674dbe188 100644 --- a/drivers/pinctrl/ralink/pinctrl-rt3883.c +++ b/drivers/pinctrl/ralink/pinctrl-rt3883.c @@ -3,7 +3,7 @@ #include #include #include -#include "pinmux.h" +#include "pinctrl-ralink.h" =20 #define RT3883_GPIO_MODE_UART0_SHIFT 2 #define RT3883_GPIO_MODE_UART0_MASK 0x7 @@ -39,9 +39,9 @@ #define RT3883_GPIO_MODE_LNA_G_GPIO 0x3 #define RT3883_GPIO_MODE_LNA_G _RT3883_GPIO_MODE_LNA_G(RT3883_GPIO_MODE_L= NA_G_MASK) =20 -static struct rt2880_pmx_func i2c_func[] =3D { FUNC("i2c", 0, 1, 2) }; -static struct rt2880_pmx_func spi_func[] =3D { FUNC("spi", 0, 3, 4) }; -static struct rt2880_pmx_func uartf_func[] =3D { +static struct ralink_pmx_func i2c_func[] =3D { FUNC("i2c", 0, 1, 2) }; +static struct ralink_pmx_func spi_func[] =3D { FUNC("spi", 0, 3, 4) }; +static struct ralink_pmx_func uartf_func[] =3D { FUNC("uartf", RT3883_GPIO_MODE_UARTF, 7, 8), FUNC("pcm uartf", RT3883_GPIO_MODE_PCM_UARTF, 7, 8), FUNC("pcm i2s", RT3883_GPIO_MODE_PCM_I2S, 7, 8), @@ -50,21 +50,21 @@ static struct rt2880_pmx_func uartf_func[] =3D { FUNC("gpio uartf", RT3883_GPIO_MODE_GPIO_UARTF, 7, 4), FUNC("gpio i2s", RT3883_GPIO_MODE_GPIO_I2S, 7, 4), }; -static struct rt2880_pmx_func uartlite_func[] =3D { FUNC("uartlite", 0, 15= , 2) }; -static struct rt2880_pmx_func jtag_func[] =3D { FUNC("jtag", 0, 17, 5) }; -static struct rt2880_pmx_func mdio_func[] =3D { FUNC("mdio", 0, 22, 2) }; -static struct rt2880_pmx_func lna_a_func[] =3D { FUNC("lna a", 0, 32, 3) }; -static struct rt2880_pmx_func lna_g_func[] =3D { FUNC("lna g", 0, 35, 3) }; -static struct rt2880_pmx_func pci_func[] =3D { +static struct ralink_pmx_func uartlite_func[] =3D { FUNC("uartlite", 0, 15= , 2) }; +static struct ralink_pmx_func jtag_func[] =3D { FUNC("jtag", 0, 17, 5) }; +static struct ralink_pmx_func mdio_func[] =3D { FUNC("mdio", 0, 22, 2) }; +static struct ralink_pmx_func lna_a_func[] =3D { FUNC("lna a", 0, 32, 3) }; +static struct ralink_pmx_func lna_g_func[] =3D { FUNC("lna g", 0, 35, 3) }; +static struct ralink_pmx_func pci_func[] =3D { FUNC("pci-dev", 0, 40, 32), FUNC("pci-host2", 1, 40, 32), FUNC("pci-host1", 2, 40, 32), FUNC("pci-fnc", 3, 40, 32) }; -static struct rt2880_pmx_func ge1_func[] =3D { FUNC("ge1", 0, 72, 12) }; -static struct rt2880_pmx_func ge2_func[] =3D { FUNC("ge2", 0, 84, 12) }; +static struct ralink_pmx_func ge1_func[] =3D { FUNC("ge1", 0, 72, 12) }; +static struct ralink_pmx_func ge2_func[] =3D { FUNC("ge2", 0, 84, 12) }; =20 -static struct rt2880_pmx_group rt3883_pinmux_data[] =3D { +static struct ralink_pmx_group rt3883_pinmux_data[] =3D { GRP("i2c", i2c_func, 1, RT3883_GPIO_MODE_I2C), GRP("spi", spi_func, 1, RT3883_GPIO_MODE_SPI), GRP("uartf", uartf_func, RT3883_GPIO_MODE_UART0_MASK, @@ -83,7 +83,7 @@ static struct rt2880_pmx_group rt3883_pinmux_data[] =3D { =20 static int rt3883_pinmux_probe(struct platform_device *pdev) { - return rt2880_pinmux_init(pdev, rt3883_pinmux_data); + return ralink_pinmux_init(pdev, rt3883_pinmux_data); } =20 static const struct of_device_id rt3883_pinmux_match[] =3D { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97A47C04A68 for ; Wed, 27 Jul 2022 17:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230201AbiG0RIa (ORCPT ); Wed, 27 Jul 2022 13:08:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232632AbiG0RHv (ORCPT ); Wed, 27 Jul 2022 13:07:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40AEE1E3FC; Wed, 27 Jul 2022 09:40:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 367B2601D6; Wed, 27 Jul 2022 16:40:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47539C433D6; Wed, 27 Jul 2022 16:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940015; bh=lBNpbwAz4MluJai4tIGarwcVNMTQu6FMGiQvNRLpuZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0v2ybIRzGtFF3APpg9+2a/iPtG7DdU2gvZCwjIFd01xOQFmic7ccfKc1SSexi8ZpI WaUfmz1M6c4nmJcyysDlm6KQy9CB3o+9/0PyA60PbrzPIm2S/e5QXN0T48etfMaJJO 3R3+XtLzloww7sO7VX88dfNrpnFHaF7LRmcu5Quo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hacash Robot , William Dean , Linus Walleij , Sasha Levin Subject: [PATCH 5.15 035/201] pinctrl: ralink: Check for null return of devm_kcalloc Date: Wed, 27 Jul 2022 18:08:59 +0200 Message-Id: <20220727161028.328779969@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: William Dean [ Upstream commit c3b821e8e406d5650e587b7ac624ac24e9b780a8 ] Because of the possible failure of the allocation, data->domains might be NULL pointer and will cause the dereference of the NULL pointer later. Therefore, it might be better to check it and directly return -ENOMEM without releasing data manually if fails, because the comment of the devm_kmalloc() says "Memory allocated with this function is automatically freed on driver detach.". Fixes: a86854d0c599b ("treewide: devm_kzalloc() -> devm_kcalloc()") Reported-by: Hacash Robot Signed-off-by: William Dean Link: https://lore.kernel.org/r/20220710154922.2610876-1-williamsukatube@16= 3.com Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/ralink/pinctrl-ralink.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pinctrl/ralink/pinctrl-ralink.c b/drivers/pinctrl/rali= nk/pinctrl-ralink.c index 841f23f55c95..3a8268a43d74 100644 --- a/drivers/pinctrl/ralink/pinctrl-ralink.c +++ b/drivers/pinctrl/ralink/pinctrl-ralink.c @@ -266,6 +266,8 @@ static int ralink_pinmux_pins(struct ralink_priv *p) p->func[i]->pin_count, sizeof(int), GFP_KERNEL); + if (!p->func[i]->pins) + return -ENOMEM; for (j =3D 0; j < p->func[i]->pin_count; j++) p->func[i]->pins[j] =3D p->func[i]->pin_first + j; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42761C3F6B0 for ; Wed, 27 Jul 2022 17:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241370AbiG0REH (ORCPT ); Wed, 27 Jul 2022 13:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236432AbiG0RDc (ORCPT ); Wed, 27 Jul 2022 13:03:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 261DA6D9DC; Wed, 27 Jul 2022 09:38:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4D10960BA0; Wed, 27 Jul 2022 16:38:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A873C433C1; Wed, 27 Jul 2022 16:38:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939922; bh=6J4syHcTuHSgwitrU92rEQ+oRjZ/UBbuCf8zt0tUKaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dqjMjZ+a+aZHZGK/MlrrfyLaAS63OXg1h0gtJbVxDwRvoGDNLmamAd+SNJ1+JVnmX vXpIWEphhWkegKVnjD7X7NTwI8vRPV19Yf23TIYpHFNim/rtJT71HxEQ1EvEhMoFAD jsPm8kQp5BqXe/KUQOzLnNhhAIQ3mZiihTRqK4x4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Jihong , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.15 036/201] perf/core: Fix data race between perf_event_set_output() and perf_mmap_close() Date: Wed, 27 Jul 2022 18:09:00 +0200 Message-Id: <20220727161028.367591172@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra [ Upstream commit 68e3c69803dada336893640110cb87221bb01dcf ] Yang Jihing reported a race between perf_event_set_output() and perf_mmap_close(): CPU1 CPU2 perf_mmap_close(e2) if (atomic_dec_and_test(&e2->rb->mmap_count)) // 1 - > 0 detach_rest =3D true ioctl(e1, IOC_SET_OUTPUT, e2) perf_event_set_output(e1, e2) ... list_for_each_entry_rcu(e, &e2->rb->event_list, rb_entry) ring_buffer_attach(e, NULL); // e1 isn't yet added and // therefore not detached ring_buffer_attach(e1, e2->rb) list_add_rcu(&e1->rb_entry, &e2->rb->event_list) After this; e1 is attached to an unmapped rb and a subsequent perf_mmap() will loop forever more: again: mutex_lock(&e->mmap_mutex); if (event->rb) { ... if (!atomic_inc_not_zero(&e->rb->mmap_count)) { ... mutex_unlock(&e->mmap_mutex); goto again; } } The loop in perf_mmap_close() holds e2->mmap_mutex, while the attach in perf_event_set_output() holds e1->mmap_mutex. As such there is no serialization to avoid this race. Change perf_event_set_output() to take both e1->mmap_mutex and e2->mmap_mutex to alleviate that problem. Additionally, have the loop in perf_mmap() detach the rb directly, this avoids having to wait for the concurrent perf_mmap_close() to get around to doing it to make progress. Fixes: 9bb5d40cd93c ("perf: Fix mmap() accounting hole") Reported-by: Yang Jihong Signed-off-by: Peter Zijlstra (Intel) Tested-by: Yang Jihong Link: https://lkml.kernel.org/r/YsQ3jm2GR38SW7uD@worktop.programming.kicks-= ass.net Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/events/core.c | 45 ++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index d7e05d937560..c6c7a4d80573 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6355,10 +6355,10 @@ static int perf_mmap(struct file *file, struct vm_a= rea_struct *vma) =20 if (!atomic_inc_not_zero(&event->rb->mmap_count)) { /* - * Raced against perf_mmap_close() through - * perf_event_set_output(). Try again, hope for better - * luck. + * Raced against perf_mmap_close(); remove the + * event and try again. */ + ring_buffer_attach(event, NULL); mutex_unlock(&event->mmap_mutex); goto again; } @@ -11892,14 +11892,25 @@ static int perf_copy_attr(struct perf_event_attr = __user *uattr, goto out; } =20 +static void mutex_lock_double(struct mutex *a, struct mutex *b) +{ + if (b < a) + swap(a, b); + + mutex_lock(a); + mutex_lock_nested(b, SINGLE_DEPTH_NESTING); +} + static int perf_event_set_output(struct perf_event *event, struct perf_event *output_= event) { struct perf_buffer *rb =3D NULL; int ret =3D -EINVAL; =20 - if (!output_event) + if (!output_event) { + mutex_lock(&event->mmap_mutex); goto set; + } =20 /* don't allow circular references */ if (event =3D=3D output_event) @@ -11937,8 +11948,15 @@ perf_event_set_output(struct perf_event *event, st= ruct perf_event *output_event) event->pmu !=3D output_event->pmu) goto out; =20 + /* + * Hold both mmap_mutex to serialize against perf_mmap_close(). Since + * output_event is already on rb->event_list, and the list iteration + * restarts after every removal, it is guaranteed this new event is + * observed *OR* if output_event is already removed, it's guaranteed we + * observe !rb->mmap_count. + */ + mutex_lock_double(&event->mmap_mutex, &output_event->mmap_mutex); set: - mutex_lock(&event->mmap_mutex); /* Can't redirect output if we've got an active mmap() */ if (atomic_read(&event->mmap_count)) goto unlock; @@ -11948,6 +11966,12 @@ perf_event_set_output(struct perf_event *event, st= ruct perf_event *output_event) rb =3D ring_buffer_get(output_event); if (!rb) goto unlock; + + /* did we race against perf_mmap_close() */ + if (!atomic_read(&rb->mmap_count)) { + ring_buffer_put(rb); + goto unlock; + } } =20 ring_buffer_attach(event, rb); @@ -11955,20 +11979,13 @@ perf_event_set_output(struct perf_event *event, s= truct perf_event *output_event) ret =3D 0; unlock: mutex_unlock(&event->mmap_mutex); + if (output_event) + mutex_unlock(&output_event->mmap_mutex); =20 out: return ret; } =20 -static void mutex_lock_double(struct mutex *a, struct mutex *b) -{ - if (b < a) - swap(a, b); - - mutex_lock(a); - mutex_lock_nested(b, SINGLE_DEPTH_NESTING); -} - static int perf_event_set_clock(struct perf_event *event, clockid_t clk_id) { bool nmi_safe =3D false; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1BECC04A68 for ; Wed, 27 Jul 2022 17:05:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241391AbiG0RFr (ORCPT ); Wed, 27 Jul 2022 13:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241580AbiG0REc (ORCPT ); Wed, 27 Jul 2022 13:04:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30BBD4E607; Wed, 27 Jul 2022 09:39:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B95EB601CD; Wed, 27 Jul 2022 16:39:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C442DC433D7; Wed, 27 Jul 2022 16:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939954; bh=SfAAi25jBlgvjYljMD4I14ml56dBnB6TVuJGEZX53iA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XXVfH6Fe0appdcsZhet4Xqamb9ZEcVeEzpI9+RWURSCQkcmT/CZZJBLxG/rfMgnYs Iyp6K3PtsRLH9Jh5P+1P2QQ6YCAJACCHKlgqWZxY97R977EKyehv1dKIgjm64PtTty a31T9gJ5MlLobPcXujELuXyodGd1US4GwAm+gN4Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 037/201] ipv4/tcp: do not use per netns ctl sockets Date: Wed, 27 Jul 2022 18:09:01 +0200 Message-Id: <20220727161028.405847629@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Eric Dumazet [ Upstream commit 37ba017dcc3b1123206808979834655ddcf93251 ] TCP ipv4 uses per-cpu/per-netns ctl sockets in order to send RST and some ACK packets (on behalf of TIMEWAIT sockets). This adds memory and cpu costs, which do not seem needed. Now typical servers have 256 or more cores, this adds considerable tax to netns users. tcp sockets are used from BH context, are not receiving packets, and do not store any persistent state but the 'struct net' pointer in order to be able to use IPv4 output functions. Note that I attempted a related change in the past, that had to be hot-fixed in commit bdbbb8527b6f ("ipv4: tcp: get rid of ugly unicast= _sock") This patch could very well surface old bugs, on layers not taking care of sk->sk_kern_sock properly. Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/netns/ipv4.h | 1 - net/ipv4/tcp_ipv4.c | 61 ++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 6c5b2efc4f17..d60a10cfc382 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -74,7 +74,6 @@ struct netns_ipv4 { struct sock *mc_autojoin_sk; =20 struct inet_peer_base *peers; - struct sock * __percpu *tcp_sk; struct fqdir *fqdir; =20 u8 sysctl_icmp_echo_ignore_all; diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 5d94822fd506..b9a9f288bfa6 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -91,6 +91,8 @@ static int tcp_v4_md5_hash_hdr(char *md5_hash, const stru= ct tcp_md5sig_key *key, struct inet_hashinfo tcp_hashinfo; EXPORT_SYMBOL(tcp_hashinfo); =20 +static DEFINE_PER_CPU(struct sock *, ipv4_tcp_sk); + static u32 tcp_v4_init_seq(const struct sk_buff *skb) { return secure_tcp_seq(ip_hdr(skb)->daddr, @@ -807,7 +809,8 @@ static void tcp_v4_send_reset(const struct sock *sk, st= ruct sk_buff *skb) arg.tos =3D ip_hdr(skb)->tos; arg.uid =3D sock_net_uid(net, sk && sk_fullsock(sk) ? sk : NULL); local_bh_disable(); - ctl_sk =3D this_cpu_read(*net->ipv4.tcp_sk); + ctl_sk =3D this_cpu_read(ipv4_tcp_sk); + sock_net_set(ctl_sk, net); if (sk) { ctl_sk->sk_mark =3D (sk->sk_state =3D=3D TCP_TIME_WAIT) ? inet_twsk(sk)->tw_mark : sk->sk_mark; @@ -822,6 +825,7 @@ static void tcp_v4_send_reset(const struct sock *sk, st= ruct sk_buff *skb) transmit_time); =20 ctl_sk->sk_mark =3D 0; + sock_net_set(ctl_sk, &init_net); __TCP_INC_STATS(net, TCP_MIB_OUTSEGS); __TCP_INC_STATS(net, TCP_MIB_OUTRSTS); local_bh_enable(); @@ -905,7 +909,8 @@ static void tcp_v4_send_ack(const struct sock *sk, arg.tos =3D tos; arg.uid =3D sock_net_uid(net, sk_fullsock(sk) ? sk : NULL); local_bh_disable(); - ctl_sk =3D this_cpu_read(*net->ipv4.tcp_sk); + ctl_sk =3D this_cpu_read(ipv4_tcp_sk); + sock_net_set(ctl_sk, net); ctl_sk->sk_mark =3D (sk->sk_state =3D=3D TCP_TIME_WAIT) ? inet_twsk(sk)->tw_mark : sk->sk_mark; ctl_sk->sk_priority =3D (sk->sk_state =3D=3D TCP_TIME_WAIT) ? @@ -918,6 +923,7 @@ static void tcp_v4_send_ack(const struct sock *sk, transmit_time); =20 ctl_sk->sk_mark =3D 0; + sock_net_set(ctl_sk, &init_net); __TCP_INC_STATS(net, TCP_MIB_OUTSEGS); local_bh_enable(); } @@ -3103,41 +3109,14 @@ EXPORT_SYMBOL(tcp_prot); =20 static void __net_exit tcp_sk_exit(struct net *net) { - int cpu; - if (net->ipv4.tcp_congestion_control) bpf_module_put(net->ipv4.tcp_congestion_control, net->ipv4.tcp_congestion_control->owner); - - for_each_possible_cpu(cpu) - inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.tcp_sk, cpu)); - free_percpu(net->ipv4.tcp_sk); } =20 static int __net_init tcp_sk_init(struct net *net) { - int res, cpu, cnt; - - net->ipv4.tcp_sk =3D alloc_percpu(struct sock *); - if (!net->ipv4.tcp_sk) - return -ENOMEM; - - for_each_possible_cpu(cpu) { - struct sock *sk; - - res =3D inet_ctl_sock_create(&sk, PF_INET, SOCK_RAW, - IPPROTO_TCP, net); - if (res) - goto fail; - sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); - - /* Please enforce IP_DF and IPID=3D=3D0 for RST and - * ACK sent in SYN-RECV and TIME-WAIT state. - */ - inet_sk(sk)->pmtudisc =3D IP_PMTUDISC_DO; - - *per_cpu_ptr(net->ipv4.tcp_sk, cpu) =3D sk; - } + int cnt; =20 net->ipv4.sysctl_tcp_ecn =3D 2; net->ipv4.sysctl_tcp_ecn_fallback =3D 1; @@ -3221,10 +3200,6 @@ static int __net_init tcp_sk_init(struct net *net) net->ipv4.tcp_congestion_control =3D &tcp_reno; =20 return 0; -fail: - tcp_sk_exit(net); - - return res; } =20 static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list) @@ -3318,6 +3293,24 @@ static void __init bpf_iter_register(void) =20 void __init tcp_v4_init(void) { + int cpu, res; + + for_each_possible_cpu(cpu) { + struct sock *sk; + + res =3D inet_ctl_sock_create(&sk, PF_INET, SOCK_RAW, + IPPROTO_TCP, &init_net); + if (res) + panic("Failed to create the TCP control socket.\n"); + sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); + + /* Please enforce IP_DF and IPID=3D=3D0 for RST and + * ACK sent in SYN-RECV and TIME-WAIT state. + */ + inet_sk(sk)->pmtudisc =3D IP_PMTUDISC_DO; + + per_cpu(ipv4_tcp_sk, cpu) =3D sk; + } if (register_pernet_subsys(&tcp_sk_ops)) panic("Failed to create the TCP control socket.\n"); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59F70C19F2C for ; Wed, 27 Jul 2022 17:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241464AbiG0RGx (ORCPT ); Wed, 27 Jul 2022 13:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241430AbiG0RGS (ORCPT ); Wed, 27 Jul 2022 13:06:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D986FA37; Wed, 27 Jul 2022 09:39:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 549A5601C0; Wed, 27 Jul 2022 16:39:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 383BBC433D6; Wed, 27 Jul 2022 16:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939984; bh=jbEMALo+xvgRCp9VzneVZGqOAaFCUwn5qV2cXVD6yeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ph/X5fUEVZXZyrhVbIR+5hsueFRKiVhRIgwu9mz1xRuXpr65KC6iCoIiNfvd6HT8G JJRBRPLsu2M9lo9wJWMp5OkWU0lWPYqYivbZ9dDr9APCC0NS9IyEaY5LUkDfHZJjUG 9AfaGF/Rvx+QVuUJwXze74rNo16aIar3TcJx9IOM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joao Martins , Joe Jin , Dongli Zhang , David Ahern , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 038/201] net: tun: split run_ebpf_filter() and pskb_trim() into different "if statement" Date: Wed, 27 Jul 2022 18:09:02 +0200 Message-Id: <20220727161028.445637095@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dongli Zhang [ Upstream commit 45a15d89fbcd280571eba8e5ca309e14ba6afa8f ] No functional change. Just to split the if statement into different conditions to use kfree_skb_reason() to trace the reason later. Cc: Joao Martins Cc: Joe Jin Signed-off-by: Dongli Zhang Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/tun.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index ea60453fe69a..f92d6a12831f 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1097,7 +1097,10 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb,= struct net_device *dev) goto drop; =20 len =3D run_ebpf_filter(tun, skb, len); - if (len =3D=3D 0 || pskb_trim(skb, len)) + if (len =3D=3D 0) + goto drop; + + if (pskb_trim(skb, len)) goto drop; =20 if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC))) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 057CFC04A68 for ; Wed, 27 Jul 2022 17:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241482AbiG0RHb (ORCPT ); Wed, 27 Jul 2022 13:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241466AbiG0RHA (ORCPT ); Wed, 27 Jul 2022 13:07:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D86171712; Wed, 27 Jul 2022 09:39:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 24E7160D3F; Wed, 27 Jul 2022 16:39:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0317AC433D6; Wed, 27 Jul 2022 16:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939998; bh=ogRQLmRcUxAnHMtNQRsc6RmOSVJ3DdWt26BXgbblRnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJ76krb92Bhy8aVulxkHE5v+am4CyGXleRLVjOacak/LrnPRr6u73g25hofO1l4XD KO7XoKpw9MvdBdHT2KMxWKJLGvdZkTD9n3mhi65ZTNduTQdONTDESlBVFd4JxA6lCa JWB8whm4KBHUW/czlL1Q83naPDrlcR8SRiEhaJlY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Suren Baghdasaryan , Johannes Weiner , Michal Hocko , Lukas Middendorf , Antti Palosaari , Luis Chamberlain , Kees Cook , Iurii Zaikin , Dave Hansen , Vlastimil Babka , Mel Gorman , Jonathan Corbet , Zhang Yi , Fengfei Xi , Mike Rapoport , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.15 039/201] mm/pagealloc: sysctl: change watermark_scale_factor max limit to 30% Date: Wed, 27 Jul 2022 18:09:03 +0200 Message-Id: <20220727161028.485121602@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Suren Baghdasaryan [ Upstream commit 39c65a94cd9661532be150e88f8b02f4a6844a35 ] For embedded systems with low total memory, having to run applications with relatively large memory requirements, 10% max limitation for watermark_scale_factor poses an issue of triggering direct reclaim every time such application is started. This results in slow application startup times and bad end-user experience. By increasing watermark_scale_factor max limit we allow vendors more flexibility to choose the right level of kswapd aggressiveness for their device and workload requirements. Link: https://lkml.kernel.org/r/20211124193604.2758863-1-surenb@google.com Signed-off-by: Suren Baghdasaryan Acked-by: Johannes Weiner Cc: Michal Hocko Cc: Lukas Middendorf Cc: Antti Palosaari Cc: Luis Chamberlain Cc: Kees Cook Cc: Iurii Zaikin Cc: Dave Hansen Cc: Vlastimil Babka Cc: Mel Gorman Cc: Jonathan Corbet Cc: Zhang Yi Cc: Fengfei Xi Cc: Mike Rapoport Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- Documentation/admin-guide/sysctl/vm.rst | 2 +- kernel/sysctl.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-= guide/sysctl/vm.rst index 5e795202111f..f4804ce37c58 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -948,7 +948,7 @@ how much memory needs to be free before kswapd goes bac= k to sleep. =20 The unit is in fractions of 10,000. The default value of 10 means the distances between watermarks are 0.1% of the available memory in the -node/system. The maximum value is 1000, or 10% of memory. +node/system. The maximum value is 3000, or 30% of memory. =20 A high rate of threads entering direct reclaim (allocstall) or kswapd going to sleep prematurely (kswapd_low_wmark_hit_quickly) can indicate diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 25c18b2df684..347a90a878b3 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -122,6 +122,7 @@ static unsigned long long_max =3D LONG_MAX; static int one_hundred =3D 100; static int two_hundred =3D 200; static int one_thousand =3D 1000; +static int three_thousand =3D 3000; #ifdef CONFIG_PRINTK static int ten_thousand =3D 10000; #endif @@ -2971,7 +2972,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D watermark_scale_factor_sysctl_handler, .extra1 =3D SYSCTL_ONE, - .extra2 =3D &one_thousand, + .extra2 =3D &three_thousand, }, { .procname =3D "percpu_pagelist_high_fraction", --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0C63C04A68 for ; Wed, 27 Jul 2022 17:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237218AbiG0RHi (ORCPT ); Wed, 27 Jul 2022 13:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241438AbiG0RHI (ORCPT ); Wed, 27 Jul 2022 13:07:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C6675A2E0; Wed, 27 Jul 2022 09:40:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1DBA601CE; Wed, 27 Jul 2022 16:40:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF912C433D6; Wed, 27 Jul 2022 16:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940001; bh=NGCbIjZGnxN/pKGcG4bGbwGkwcV7hNwpSI69Ay5vQbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRYVs5gxhChB6qlRgGQ/FRIA5I7fd2fp24VUbeLIpD7y3NhjnFX384aNO6QgMFgXn uHsnnVQrZmc0DxwPx6DrWLmEx6XCUoJBPAcBEm2rHXA0Tk0L79zpQV9Xm6Vyg1Kecf YQ6vVGLFIaciKdwhOD2h5rF7DtILR8tEF+s0UlRk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoming Ni , Luis Chamberlain , Kees Cook , Al Viro , Amir Goldstein , Andy Shevchenko , Benjamin LaHaise , "Eric W. Biederman" , Iurii Zaikin , Jan Kara , Paul Turner , Peter Zijlstra , Petr Mladek , Qing Wang , Sebastian Reichel , Sergey Senozhatsky , Stephen Kitt , Tetsuo Handa , Antti Palosaari , Arnd Bergmann , Benjamin Herrenschmidt , Clemens Ladisch , David Airlie , Jani Nikula , Joel Becker , Joonas Lahtinen , Joseph Qi , Julia Lawall , Lukas Middendorf , Mark Fasheh , Phillip Potter , Rodrigo Vivi , Douglas Gilbert , "James E.J. Bottomley" , Jani Nikula , John Ogness , "Martin K. Petersen" , "Rafael J. Wysocki" , "Steven Rostedt (VMware)" , Suren Baghdasaryan , "Theodore Tso" , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.15 040/201] sysctl: move some boundary constants from sysctl.c to sysctl_vals Date: Wed, 27 Jul 2022 18:09:04 +0200 Message-Id: <20220727161028.534205480@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xiaoming Ni [ Upstream commit 78e36f3b0dae586f623c4a37ec5eb5496f5abbe1 ] sysctl has helpers which let us specify boundary values for a min or max int value. Since these are used for a boundary check only they don't change, so move these variables to sysctl_vals to avoid adding duplicate variables. This will help with our cleanup of kernel/sysctl.c. [akpm@linux-foundation.org: update it for "mm/pagealloc: sysctl: change wat= ermark_scale_factor max limit to 30%"] [mcgrof@kernel.org: major rebase] Link: https://lkml.kernel.org/r/20211123202347.818157-3-mcgrof@kernel.org Signed-off-by: Xiaoming Ni Signed-off-by: Luis Chamberlain Reviewed-by: Kees Cook Cc: Al Viro Cc: Amir Goldstein Cc: Andy Shevchenko Cc: Benjamin LaHaise Cc: "Eric W. Biederman" Cc: Greg Kroah-Hartman Cc: Iurii Zaikin Cc: Jan Kara Cc: Paul Turner Cc: Peter Zijlstra Cc: Petr Mladek Cc: Qing Wang Cc: Sebastian Reichel Cc: Sergey Senozhatsky Cc: Stephen Kitt Cc: Tetsuo Handa Cc: Antti Palosaari Cc: Arnd Bergmann Cc: Benjamin Herrenschmidt Cc: Clemens Ladisch Cc: David Airlie Cc: Jani Nikula Cc: Joel Becker Cc: Joonas Lahtinen Cc: Joseph Qi Cc: Julia Lawall Cc: Lukas Middendorf Cc: Mark Fasheh Cc: Phillip Potter Cc: Rodrigo Vivi Cc: Douglas Gilbert Cc: James E.J. Bottomley Cc: Jani Nikula Cc: John Ogness Cc: Martin K. Petersen Cc: "Rafael J. Wysocki" Cc: Steven Rostedt (VMware) Cc: Suren Baghdasaryan Cc: "Theodore Ts'o" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/proc/proc_sysctl.c | 2 +- include/linux/sysctl.h | 13 +++++++++--- kernel/sysctl.c | 45 ++++++++++++++++++------------------------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 5d66faecd4ef..013fc5931bc3 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -25,7 +25,7 @@ static const struct file_operations proc_sys_dir_file_ope= rations; static const struct inode_operations proc_sys_dir_operations; =20 /* shared constants to be used in various sysctls */ -const int sysctl_vals[] =3D { 0, 1, INT_MAX }; +const int sysctl_vals[] =3D { -1, 0, 1, 2, 4, 100, 200, 1000, 3000, INT_MA= X }; EXPORT_SYMBOL(sysctl_vals); =20 /* Support for permanently empty directories */ diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 1fa2b69c6fc3..fa372b4c2313 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -38,9 +38,16 @@ struct ctl_table_header; struct ctl_dir; =20 /* Keep the same order as in fs/proc/proc_sysctl.c */ -#define SYSCTL_ZERO ((void *)&sysctl_vals[0]) -#define SYSCTL_ONE ((void *)&sysctl_vals[1]) -#define SYSCTL_INT_MAX ((void *)&sysctl_vals[2]) +#define SYSCTL_NEG_ONE ((void *)&sysctl_vals[0]) +#define SYSCTL_ZERO ((void *)&sysctl_vals[1]) +#define SYSCTL_ONE ((void *)&sysctl_vals[2]) +#define SYSCTL_TWO ((void *)&sysctl_vals[3]) +#define SYSCTL_FOUR ((void *)&sysctl_vals[4]) +#define SYSCTL_ONE_HUNDRED ((void *)&sysctl_vals[5]) +#define SYSCTL_TWO_HUNDRED ((void *)&sysctl_vals[6]) +#define SYSCTL_ONE_THOUSAND ((void *)&sysctl_vals[7]) +#define SYSCTL_THREE_THOUSAND ((void *)&sysctl_vals[8]) +#define SYSCTL_INT_MAX ((void *)&sysctl_vals[9]) =20 extern const int sysctl_vals[]; =20 diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 347a90a878b3..23c08bf3db58 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -113,16 +113,9 @@ static int sixty =3D 60; #endif =20 -static int __maybe_unused neg_one =3D -1; -static int __maybe_unused two =3D 2; -static int __maybe_unused four =3D 4; static unsigned long zero_ul; static unsigned long one_ul =3D 1; static unsigned long long_max =3D LONG_MAX; -static int one_hundred =3D 100; -static int two_hundred =3D 200; -static int one_thousand =3D 1000; -static int three_thousand =3D 3000; #ifdef CONFIG_PRINTK static int ten_thousand =3D 10000; #endif @@ -1973,7 +1966,7 @@ static struct ctl_table kern_table[] =3D { .maxlen =3D sizeof(int), .mode =3D 0644, .proc_handler =3D proc_dointvec_minmax, - .extra1 =3D &neg_one, + .extra1 =3D SYSCTL_NEG_ONE, .extra2 =3D SYSCTL_ONE, }, #endif @@ -2315,7 +2308,7 @@ static struct ctl_table kern_table[] =3D { .mode =3D 0644, .proc_handler =3D proc_dointvec_minmax_sysadmin, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two, + .extra2 =3D SYSCTL_TWO, }, #endif { @@ -2575,7 +2568,7 @@ static struct ctl_table kern_table[] =3D { .maxlen =3D sizeof(int), .mode =3D 0644, .proc_handler =3D proc_dointvec_minmax, - .extra1 =3D &neg_one, + .extra1 =3D SYSCTL_NEG_ONE, }, #endif #ifdef CONFIG_RT_MUTEXES @@ -2637,7 +2630,7 @@ static struct ctl_table kern_table[] =3D { .mode =3D 0644, .proc_handler =3D perf_cpu_time_max_percent_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &one_hundred, + .extra2 =3D SYSCTL_ONE_HUNDRED, }, { .procname =3D "perf_event_max_stack", @@ -2655,7 +2648,7 @@ static struct ctl_table kern_table[] =3D { .mode =3D 0644, .proc_handler =3D perf_event_max_stack_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &one_thousand, + .extra2 =3D SYSCTL_ONE_THOUSAND, }, #endif { @@ -2686,7 +2679,7 @@ static struct ctl_table kern_table[] =3D { .mode =3D 0644, .proc_handler =3D bpf_unpriv_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two, + .extra2 =3D SYSCTL_TWO, }, { .procname =3D "bpf_stats_enabled", @@ -2740,7 +2733,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D overcommit_policy_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two, + .extra2 =3D SYSCTL_TWO, }, { .procname =3D "panic_on_oom", @@ -2749,7 +2742,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D proc_dointvec_minmax, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two, + .extra2 =3D SYSCTL_TWO, }, { .procname =3D "oom_kill_allocating_task", @@ -2794,7 +2787,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D dirty_background_ratio_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &one_hundred, + .extra2 =3D SYSCTL_ONE_HUNDRED, }, { .procname =3D "dirty_background_bytes", @@ -2811,7 +2804,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D dirty_ratio_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &one_hundred, + .extra2 =3D SYSCTL_ONE_HUNDRED, }, { .procname =3D "dirty_bytes", @@ -2851,7 +2844,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D proc_dointvec_minmax, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two_hundred, + .extra2 =3D SYSCTL_TWO_HUNDRED, }, #ifdef CONFIG_NUMA { @@ -2910,7 +2903,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0200, .proc_handler =3D drop_caches_sysctl_handler, .extra1 =3D SYSCTL_ONE, - .extra2 =3D &four, + .extra2 =3D SYSCTL_FOUR, }, #ifdef CONFIG_COMPACTION { @@ -2927,7 +2920,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D compaction_proactiveness_sysctl_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &one_hundred, + .extra2 =3D SYSCTL_ONE_HUNDRED, }, { .procname =3D "extfrag_threshold", @@ -2972,7 +2965,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D watermark_scale_factor_sysctl_handler, .extra1 =3D SYSCTL_ONE, - .extra2 =3D &three_thousand, + .extra2 =3D SYSCTL_THREE_THOUSAND, }, { .procname =3D "percpu_pagelist_high_fraction", @@ -3051,7 +3044,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D sysctl_min_unmapped_ratio_sysctl_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &one_hundred, + .extra2 =3D SYSCTL_ONE_HUNDRED, }, { .procname =3D "min_slab_ratio", @@ -3060,7 +3053,7 @@ static struct ctl_table vm_table[] =3D { .mode =3D 0644, .proc_handler =3D sysctl_min_slab_ratio_sysctl_handler, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &one_hundred, + .extra2 =3D SYSCTL_ONE_HUNDRED, }, #endif #ifdef CONFIG_SMP @@ -3350,7 +3343,7 @@ static struct ctl_table fs_table[] =3D { .mode =3D 0600, .proc_handler =3D proc_dointvec_minmax, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two, + .extra2 =3D SYSCTL_TWO, }, { .procname =3D "protected_regular", @@ -3359,7 +3352,7 @@ static struct ctl_table fs_table[] =3D { .mode =3D 0600, .proc_handler =3D proc_dointvec_minmax, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two, + .extra2 =3D SYSCTL_TWO, }, { .procname =3D "suid_dumpable", @@ -3368,7 +3361,7 @@ static struct ctl_table fs_table[] =3D { .mode =3D 0644, .proc_handler =3D proc_dointvec_minmax_coredump, .extra1 =3D SYSCTL_ZERO, - .extra2 =3D &two, + .extra2 =3D SYSCTL_TWO, }, #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71154C04A68 for ; Wed, 27 Jul 2022 17:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232170AbiG0RH5 (ORCPT ); Wed, 27 Jul 2022 13:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241419AbiG0RHP (ORCPT ); Wed, 27 Jul 2022 13:07:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB18BD1; Wed, 27 Jul 2022 09:40:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6BC67B821A6; Wed, 27 Jul 2022 16:40:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D32F9C433C1; Wed, 27 Jul 2022 16:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940004; bh=UVdnEHSMp5ExBeMfrrQ5QNvyN24fpRBs4MST/dzI4vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lPDprHZlni39s+m+ccupZogOBuU86QfcGgjVojOwXe9/SEyzd4BZ+awCMpQ7/gy/j rnlFthvzQ4vxMzAbHiY3OhScUslWZdQYIe/GGRe7gRIPumL9gsWkmokCGTT64lPh9k Gt1dRyNirCM/SezGopl88rHtH6P2crwi4+lSJXuQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 041/201] tcp: Fix data-races around sysctl_tcp_ecn. Date: Wed, 27 Jul 2022 18:09:05 +0200 Message-Id: <20220727161028.582019415@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 4785a66702f086cf2ea84bdbe6ec921f274bd9f2 ] While reading sysctl_tcp_ecn, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c | 2 +- net/ipv4/syncookies.c | 2 +- net/ipv4/sysctl_net_ipv4.c | 2 ++ net/ipv4/tcp_input.c | 2 +- net/ipv4/tcp_output.c | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c b/= drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c index 4af5561cbfc5..7c760aa65540 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c @@ -1392,7 +1392,7 @@ static void chtls_pass_accept_request(struct sock *sk, th_ecn =3D tcph->ece && tcph->cwr; if (th_ecn) { ect =3D !INET_ECN_is_not_ect(ip_dsfield); - ecn_ok =3D sock_net(sk)->ipv4.sysctl_tcp_ecn; + ecn_ok =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn); if ((!ect && ecn_ok) || tcp_ca_needs_ecn(sk)) inet_rsk(oreq)->ecn_ok =3D 1; } diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 10b469aee492..fd1dc86ba512 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -275,7 +275,7 @@ bool cookie_ecn_ok(const struct tcp_options_received *t= cp_opt, if (!ecn_ok) return false; =20 - if (net->ipv4.sysctl_tcp_ecn) + if (READ_ONCE(net->ipv4.sysctl_tcp_ecn)) return true; =20 return dst_feature(dst, RTAX_FEATURE_ECN); diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index 616658e7c796..ead5db7e24ea 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -689,6 +689,8 @@ static struct ctl_table ipv4_net_table[] =3D { .maxlen =3D sizeof(u8), .mode =3D 0644, .proc_handler =3D proc_dou8vec_minmax, + .extra1 =3D SYSCTL_ZERO, + .extra2 =3D SYSCTL_TWO, }, { .procname =3D "tcp_ecn_fallback", diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 0ff2f620f8e4..ae06923fe8d0 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6669,7 +6669,7 @@ static void tcp_ecn_create_request(struct request_soc= k *req, =20 ect =3D !INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield); ecn_ok_dst =3D dst_feature(dst, DST_FEATURE_ECN_MASK); - ecn_ok =3D net->ipv4.sysctl_tcp_ecn || ecn_ok_dst; + ecn_ok =3D READ_ONCE(net->ipv4.sysctl_tcp_ecn) || ecn_ok_dst; =20 if (((!ect || th->res1) && ecn_ok) || tcp_ca_needs_ecn(listen_sk) || (ecn_ok_dst & DST_FEATURE_ECN_CA) || diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 509aab1b7ac9..0bd5c334ccce 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -324,7 +324,7 @@ static void tcp_ecn_send_syn(struct sock *sk, struct sk= _buff *skb) { struct tcp_sock *tp =3D tcp_sk(sk); bool bpf_needs_ecn =3D tcp_bpf_ca_needs_ecn(sk); - bool use_ecn =3D sock_net(sk)->ipv4.sysctl_tcp_ecn =3D=3D 1 || + bool use_ecn =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn) =3D=3D 1 || tcp_ca_needs_ecn(sk) || bpf_needs_ecn; =20 if (!use_ecn) { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55EFAC04A68 for ; Wed, 27 Jul 2022 17:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239296AbiG0RIC (ORCPT ); Wed, 27 Jul 2022 13:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237264AbiG0RHS (ORCPT ); Wed, 27 Jul 2022 13:07:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 018E22719; Wed, 27 Jul 2022 09:40:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4DAE8B821D8; Wed, 27 Jul 2022 16:40:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF80BC433C1; Wed, 27 Jul 2022 16:40:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940007; bh=1fP8eZdtcz8+F/rW5eMH6q182a0JuHnCnMUQtc++Bfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=itVuLwn9Xc3sZoFnuCDsDN7nlUV9HQRKvKP3j6MM8LgWnfAbnXFWvOvgGoepPd5MY mxoDD5jTWbV1wKHjiH/0oGRc4vqp+e22n7VX3+CwbyQPMLu30K4q6PUAsCYQ237jaQ Hlu7vfljk92QA/0jRlQrxYyQ0AWvEAwpCqcTBSjw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Kazlauskas , Qingqing Zhuo , Jude Shih , Daniel Wheeler , Alex Deucher , Sasha Levin Subject: [PATCH 5.15 042/201] drm/amd/display: Support for DMUB HPD interrupt handling Date: Wed, 27 Jul 2022 18:09:06 +0200 Message-Id: <20220727161028.621335564@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jude Shih [ Upstream commit e27c41d5b0681c597ac1894f4e02cf626e062250 ] [WHY] To add support for HPD interrupt handling from DMUB. HPD interrupt could be triggered from outbox1 from DMUB [HOW] 1) Use queue_work to handle hpd task from outbox1 2) Add handle_hpd_irq_helper to share interrupt handling code between legacy and DMUB HPD from outbox1 3) Added DMUB HPD handling in dmub_srv_stat_get_notification(). HPD handling callback function and wake up the DMUB thread. Reviewed-by: Nicholas Kazlauskas Acked-by: Qingqing Zhuo Signed-off-by: Jude Shih Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 171 +++++++++++++++++- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 40 ++++ 2 files changed, 203 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.c index d35a6f6d158e..19048f0d83a4 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -215,6 +215,8 @@ static void handle_cursor_update(struct drm_plane *plan= e, static const struct drm_format_info * amd_get_format_info(const struct drm_mode_fb_cmd2 *cmd); =20 +static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector); + static bool is_timing_unchanged_for_freesync(struct drm_crtc_state *old_crtc_state, struct drm_crtc_state *new_crtc_state); @@ -618,6 +620,116 @@ static void dm_dcn_vertical_interrupt0_high_irq(void = *interrupt_params) } #endif =20 +/** + * dmub_aux_setconfig_reply_callback - Callback for AUX or SET_CONFIG comm= and. + * @adev: amdgpu_device pointer + * @notify: dmub notification structure + * + * Dmub AUX or SET_CONFIG command completion processing callback + * Copies dmub notification to DM which is to be read by AUX command. + * issuing thread and also signals the event to wake up the thread. + */ +void dmub_aux_setconfig_callback(struct amdgpu_device *adev, struct dmub_n= otification *notify) +{ + if (adev->dm.dmub_notify) + memcpy(adev->dm.dmub_notify, notify, sizeof(struct dmub_notification)); + if (notify->type =3D=3D DMUB_NOTIFICATION_AUX_REPLY) + complete(&adev->dm.dmub_aux_transfer_done); +} + +/** + * dmub_hpd_callback - DMUB HPD interrupt processing callback. + * @adev: amdgpu_device pointer + * @notify: dmub notification structure + * + * Dmub Hpd interrupt processing callback. Gets displayindex through the + * ink index and calls helper to do the processing. + */ +void dmub_hpd_callback(struct amdgpu_device *adev, struct dmub_notificatio= n *notify) +{ + struct amdgpu_dm_connector *aconnector; + struct drm_connector *connector; + struct drm_connector_list_iter iter; + struct dc_link *link; + uint8_t link_index =3D 0; + struct drm_device *dev =3D adev->dm.ddev; + + if (adev =3D=3D NULL) + return; + + if (notify =3D=3D NULL) { + DRM_ERROR("DMUB HPD callback notification was NULL"); + return; + } + + if (notify->link_index > adev->dm.dc->link_count) { + DRM_ERROR("DMUB HPD index (%u)is abnormal", notify->link_index); + return; + } + + drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); + + link_index =3D notify->link_index; + + link =3D adev->dm.dc->links[link_index]; + + drm_connector_list_iter_begin(dev, &iter); + drm_for_each_connector_iter(connector, &iter) { + aconnector =3D to_amdgpu_dm_connector(connector); + if (link && aconnector->dc_link =3D=3D link) { + DRM_INFO("DMUB HPD callback: link_index=3D%u\n", link_index); + handle_hpd_irq_helper(aconnector); + break; + } + } + drm_connector_list_iter_end(&iter); + drm_modeset_unlock(&dev->mode_config.connection_mutex); + +} + +/** + * register_dmub_notify_callback - Sets callback for DMUB notify + * @adev: amdgpu_device pointer + * @type: Type of dmub notification + * @callback: Dmub interrupt callback function + * @dmub_int_thread_offload: offload indicator + * + * API to register a dmub callback handler for a dmub notification + * Also sets indicator whether callback processing to be offloaded. + * to dmub interrupt handling thread + * Return: true if successfully registered, false if there is existing reg= istration + */ +bool register_dmub_notify_callback(struct amdgpu_device *adev, enum dmub_n= otification_type type, +dmub_notify_interrupt_callback_t callback, bool dmub_int_thread_offload) +{ + if (callback !=3D NULL && type < ARRAY_SIZE(adev->dm.dmub_thread_offload)= ) { + adev->dm.dmub_callback[type] =3D callback; + adev->dm.dmub_thread_offload[type] =3D dmub_int_thread_offload; + } else + return false; + + return true; +} + +static void dm_handle_hpd_work(struct work_struct *work) +{ + struct dmub_hpd_work *dmub_hpd_wrk; + + dmub_hpd_wrk =3D container_of(work, struct dmub_hpd_work, handle_hpd_work= ); + + if (!dmub_hpd_wrk->dmub_notify) { + DRM_ERROR("dmub_hpd_wrk dmub_notify is NULL"); + return; + } + + if (dmub_hpd_wrk->dmub_notify->type < ARRAY_SIZE(dmub_hpd_wrk->adev->dm.d= mub_callback)) { + dmub_hpd_wrk->adev->dm.dmub_callback[dmub_hpd_wrk->dmub_notify->type](dm= ub_hpd_wrk->adev, + dmub_hpd_wrk->dmub_notify); + } + kfree(dmub_hpd_wrk); + +} + #define DMUB_TRACE_MAX_READ 64 /** * dm_dmub_outbox1_low_irq() - Handles Outbox interrupt @@ -634,18 +746,33 @@ static void dm_dmub_outbox1_low_irq(void *interrupt_p= arams) struct amdgpu_display_manager *dm =3D &adev->dm; struct dmcub_trace_buf_entry entry =3D { 0 }; uint32_t count =3D 0; + struct dmub_hpd_work *dmub_hpd_wrk; =20 if (dc_enable_dmub_notifications(adev->dm.dc)) { + dmub_hpd_wrk =3D kzalloc(sizeof(*dmub_hpd_wrk), GFP_ATOMIC); + if (!dmub_hpd_wrk) { + DRM_ERROR("Failed to allocate dmub_hpd_wrk"); + return; + } + INIT_WORK(&dmub_hpd_wrk->handle_hpd_work, dm_handle_hpd_work); + if (irq_params->irq_src =3D=3D DC_IRQ_SOURCE_DMCUB_OUTBOX) { do { dc_stat_get_dmub_notification(adev->dm.dc, ¬ify); - } while (notify.pending_notification); + if (notify.type > ARRAY_SIZE(dm->dmub_thread_offload)) { + DRM_ERROR("DM: notify type %d larger than the array size %ld !", noti= fy.type, + ARRAY_SIZE(dm->dmub_thread_offload)); + continue; + } + if (dm->dmub_thread_offload[notify.type] =3D=3D true) { + dmub_hpd_wrk->dmub_notify =3D ¬ify; + dmub_hpd_wrk->adev =3D adev; + queue_work(adev->dm.delayed_hpd_wq, &dmub_hpd_wrk->handle_hpd_work); + } else { + dm->dmub_callback[notify.type](adev, ¬ify); + } =20 - if (adev->dm.dmub_notify) - memcpy(adev->dm.dmub_notify, ¬ify, sizeof(struct dmub_notification)= ); - if (notify.type =3D=3D DMUB_NOTIFICATION_AUX_REPLY) - complete(&adev->dm.dmub_aux_transfer_done); - // TODO : HPD Implementation + } while (notify.pending_notification); =20 } else { DRM_ERROR("DM: Failed to receive correct outbox IRQ !"); @@ -1287,7 +1414,25 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) DRM_INFO("amdgpu: fail to allocate adev->dm.dmub_notify"); goto error; } + + adev->dm.delayed_hpd_wq =3D create_singlethread_workqueue("amdgpu_dm_hpd= _wq"); + if (!adev->dm.delayed_hpd_wq) { + DRM_ERROR("amdgpu: failed to create hpd offload workqueue.\n"); + goto error; + } + amdgpu_dm_outbox_init(adev); +#if defined(CONFIG_DRM_AMD_DC_DCN) + if (!register_dmub_notify_callback(adev, DMUB_NOTIFICATION_AUX_REPLY, + dmub_aux_setconfig_callback, false)) { + DRM_ERROR("amdgpu: fail to register dmub aux callback"); + goto error; + } + if (!register_dmub_notify_callback(adev, DMUB_NOTIFICATION_HPD, dmub_hpd= _callback, true)) { + DRM_ERROR("amdgpu: fail to register dmub hpd callback"); + goto error; + } +#endif } =20 if (amdgpu_dm_initialize_drm_device(adev)) { @@ -1369,6 +1514,8 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) if (dc_enable_dmub_notifications(adev->dm.dc)) { kfree(adev->dm.dmub_notify); adev->dm.dmub_notify =3D NULL; + destroy_workqueue(adev->dm.delayed_hpd_wq); + adev->dm.delayed_hpd_wq =3D NULL; } =20 if (adev->dm.dmub_bo) @@ -2654,9 +2801,8 @@ void amdgpu_dm_update_connector_after_detect( dc_sink_release(sink); } =20 -static void handle_hpd_irq(void *param) +static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector) { - struct amdgpu_dm_connector *aconnector =3D (struct amdgpu_dm_connector *)= param; struct drm_connector *connector =3D &aconnector->base; struct drm_device *dev =3D connector->dev; enum dc_connection_type new_connection_type =3D dc_connection_none; @@ -2715,6 +2861,15 @@ static void handle_hpd_irq(void *param) =20 } =20 +static void handle_hpd_irq(void *param) +{ + struct amdgpu_dm_connector *aconnector =3D (struct amdgpu_dm_connector *)= param; + + handle_hpd_irq_helper(aconnector); + +} + + static void dm_handle_hpd_rx_irq(struct amdgpu_dm_connector *aconnector) { uint8_t esi[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] =3D { 0 }; diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.h index 46d6e65f6bd4..da87ca77023d 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -47,6 +47,8 @@ #define AMDGPU_DM_MAX_CRTC 6 =20 #define AMDGPU_DM_MAX_NUM_EDP 2 + +#define AMDGPU_DMUB_NOTIFICATION_MAX 5 /* #include "include/amdgpu_dal_power_if.h" #include "amdgpu_dm_irq.h" @@ -86,6 +88,21 @@ struct dm_compressor_info { uint64_t gpu_addr; }; =20 +typedef void (*dmub_notify_interrupt_callback_t)(struct amdgpu_device *ade= v, struct dmub_notification *notify); + +/** + * struct dmub_hpd_work - Handle time consuming work in low priority outbo= x IRQ + * + * @handle_hpd_work: Work to be executed in a separate thread to handle hp= d_low_irq + * @dmub_notify: notification for callback function + * @adev: amdgpu_device pointer + */ +struct dmub_hpd_work { + struct work_struct handle_hpd_work; + struct dmub_notification *dmub_notify; + struct amdgpu_device *adev; +}; + /** * struct vblank_control_work - Work data for vblank control * @work: Kernel work data for the work event @@ -190,8 +207,30 @@ struct amdgpu_display_manager { */ struct dmub_srv *dmub_srv; =20 + /** + * @dmub_notify: + * + * Notification from DMUB. + */ + struct dmub_notification *dmub_notify; =20 + /** + * @dmub_callback: + * + * Callback functions to handle notification from DMUB. + */ + + dmub_notify_interrupt_callback_t dmub_callback[AMDGPU_DMUB_NOTIFICATION_M= AX]; + + /** + * @dmub_thread_offload: + * + * Flag to indicate if callback is offload. + */ + + bool dmub_thread_offload[AMDGPU_DMUB_NOTIFICATION_MAX]; + /** * @dmub_fb_info: * @@ -439,6 +478,7 @@ struct amdgpu_display_manager { */ struct list_head da_list; struct completion dmub_aux_transfer_done; + struct workqueue_struct *delayed_hpd_wq; =20 /** * @brightness: --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABEA0C04A68 for ; Wed, 27 Jul 2022 17:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232342AbiG0RIJ (ORCPT ); Wed, 27 Jul 2022 13:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240940AbiG0RH2 (ORCPT ); Wed, 27 Jul 2022 13:07:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5704213DE6; Wed, 27 Jul 2022 09:40:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4F586B8200D; Wed, 27 Jul 2022 16:40:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97C84C433C1; Wed, 27 Jul 2022 16:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940010; bh=VMLCUBZCobyAXdrRzT/Jh16eeai0MEhj4Z65pThCLuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8RwktXznhvsZhGpCljxpvlt2lDM64Df4zFNBP8v43T6Vl1TbDRhD1JuNQUOpkv+r tC/JF4uC31FUlPEoaPm594hsGmrcLcFCVAIuQUhh0G36DtA518qBemHvx5ovRFw2+T Wcnhr1BS37F4A9AsNIZWmaoOmRu6J3zxptmtxZMQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikita Lipski , Wayne Lin , Nicholas Kazlauskas , Daniel Wheeler , Alex Deucher , Sasha Levin Subject: [PATCH 5.15 043/201] drm/amd/display: Add option to defer works of hpd_rx_irq Date: Wed, 27 Jul 2022 18:09:07 +0200 Message-Id: <20220727161028.661523908@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Wayne Lin [ Upstream commit 410ad92d7fecd30de7456c19e326e272c2153ff2 ] [Why & How] Due to some code flow constraints, we need to defer dc_lock needed works from dc_link_handle_hpd_rx_irq(). Thus, do following changes: * Change allow_hpd_rx_irq() from static to public * Change handle_automated_test() from static to public * Extract link lost handling flow out from dc_link_handle_hpd_rx_irq() and put those into a new function dc_link_dp_handle_link_loss() * Add one option parameter to decide whether defer works within dc_link_handle_hpd_rx_irq() Acked-by: Mikita Lipski Signed-off-by: Wayne Lin Reviewed-by: Nicholas Kazlauskas Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- .../gpu/drm/amd/display/dc/core/dc_link_dp.c | 92 ++++++++++++------- drivers/gpu/drm/amd/display/dc/dc_link.h | 3 + 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c b/drivers/gpu= /drm/amd/display/dc/core/dc_link_dp.c index 05f81d44aa6c..9b6111eb9ca4 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c @@ -2743,7 +2743,7 @@ void decide_link_settings(struct dc_stream_state *str= eam, } =20 /*************************Short Pulse IRQ***************************/ -static bool allow_hpd_rx_irq(const struct dc_link *link) +bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link) { /* * Don't handle RX IRQ unless one of following is met: @@ -3177,7 +3177,7 @@ static void dp_test_get_audio_test_data(struct dc_lin= k *link, bool disable_video } } =20 -static void handle_automated_test(struct dc_link *link) +void dc_link_dp_handle_automated_test(struct dc_link *link) { union test_request test_request; union test_response test_response; @@ -3226,17 +3226,50 @@ static void handle_automated_test(struct dc_link *l= ink) sizeof(test_response)); } =20 -bool dc_link_handle_hpd_rx_irq(struct dc_link *link, union hpd_irq_data *o= ut_hpd_irq_dpcd_data, bool *out_link_loss) +void dc_link_dp_handle_link_loss(struct dc_link *link) +{ + int i; + struct pipe_ctx *pipe_ctx; + + for (i =3D 0; i < MAX_PIPES; i++) { + pipe_ctx =3D &link->dc->current_state->res_ctx.pipe_ctx[i]; + if (pipe_ctx && pipe_ctx->stream && pipe_ctx->stream->link =3D=3D link) + break; + } + + if (pipe_ctx =3D=3D NULL || pipe_ctx->stream =3D=3D NULL) + return; + + for (i =3D 0; i < MAX_PIPES; i++) { + pipe_ctx =3D &link->dc->current_state->res_ctx.pipe_ctx[i]; + if (pipe_ctx && pipe_ctx->stream && !pipe_ctx->stream->dpms_off && + pipe_ctx->stream->link =3D=3D link && !pipe_ctx->prev_odm_pipe) { + core_link_disable_stream(pipe_ctx); + } + } + + for (i =3D 0; i < MAX_PIPES; i++) { + pipe_ctx =3D &link->dc->current_state->res_ctx.pipe_ctx[i]; + if (pipe_ctx && pipe_ctx->stream && !pipe_ctx->stream->dpms_off && + pipe_ctx->stream->link =3D=3D link && !pipe_ctx->prev_odm_pipe) { + core_link_enable_stream(link->dc->current_state, pipe_ctx); + } + } +} + +static bool handle_hpd_rx_irq(struct dc_link *link, union hpd_irq_data *ou= t_hpd_irq_dpcd_data, bool *out_link_loss, + bool defer_handling, bool *has_left_work) { union hpd_irq_data hpd_irq_dpcd_data =3D { { { {0} } } }; union device_service_irq device_service_clear =3D { { 0 } }; enum dc_status result; bool status =3D false; - struct pipe_ctx *pipe_ctx; - int i; =20 if (out_link_loss) *out_link_loss =3D false; + + if (has_left_work) + *has_left_work =3D false; /* For use cases related to down stream connection status change, * PSR and device auto test, refer to function handle_sst_hpd_irq * in DAL2.1*/ @@ -3268,11 +3301,14 @@ bool dc_link_handle_hpd_rx_irq(struct dc_link *link= , union hpd_irq_data *out_hpd &device_service_clear.raw, sizeof(device_service_clear.raw)); device_service_clear.raw =3D 0; - handle_automated_test(link); + if (defer_handling && has_left_work) + *has_left_work =3D true; + else + dc_link_dp_handle_automated_test(link); return false; } =20 - if (!allow_hpd_rx_irq(link)) { + if (!dc_link_dp_allow_hpd_rx_irq(link)) { DC_LOG_HW_HPD_IRQ("%s: skipping HPD handling on %d\n", __func__, link->link_index); return false; @@ -3286,12 +3322,18 @@ bool dc_link_handle_hpd_rx_irq(struct dc_link *link= , union hpd_irq_data *out_hpd * so do not handle as a normal sink status change interrupt. */ =20 - if (hpd_irq_dpcd_data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY) + if (hpd_irq_dpcd_data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY) { + if (defer_handling && has_left_work) + *has_left_work =3D true; return true; + } =20 /* check if we have MST msg and return since we poll for it */ - if (hpd_irq_dpcd_data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) + if (hpd_irq_dpcd_data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) { + if (defer_handling && has_left_work) + *has_left_work =3D true; return false; + } =20 /* For now we only handle 'Downstream port status' case. * If we got sink count changed it means @@ -3308,29 +3350,10 @@ bool dc_link_handle_hpd_rx_irq(struct dc_link *link= , union hpd_irq_data *out_hpd sizeof(hpd_irq_dpcd_data), "Status: "); =20 - for (i =3D 0; i < MAX_PIPES; i++) { - pipe_ctx =3D &link->dc->current_state->res_ctx.pipe_ctx[i]; - if (pipe_ctx && pipe_ctx->stream && pipe_ctx->stream->link =3D=3D link) - break; - } - - if (pipe_ctx =3D=3D NULL || pipe_ctx->stream =3D=3D NULL) - return false; - - - for (i =3D 0; i < MAX_PIPES; i++) { - pipe_ctx =3D &link->dc->current_state->res_ctx.pipe_ctx[i]; - if (pipe_ctx && pipe_ctx->stream && !pipe_ctx->stream->dpms_off && - pipe_ctx->stream->link =3D=3D link && !pipe_ctx->prev_odm_pipe) - core_link_disable_stream(pipe_ctx); - } - - for (i =3D 0; i < MAX_PIPES; i++) { - pipe_ctx =3D &link->dc->current_state->res_ctx.pipe_ctx[i]; - if (pipe_ctx && pipe_ctx->stream && !pipe_ctx->stream->dpms_off && - pipe_ctx->stream->link =3D=3D link && !pipe_ctx->prev_odm_pipe) - core_link_enable_stream(link->dc->current_state, pipe_ctx); - } + if (defer_handling && has_left_work) + *has_left_work =3D true; + else + dc_link_dp_handle_link_loss(link); =20 status =3D false; if (out_link_loss) @@ -3356,6 +3379,11 @@ bool dc_link_handle_hpd_rx_irq(struct dc_link *link,= union hpd_irq_data *out_hpd return status; } =20 +bool dc_link_handle_hpd_rx_irq(struct dc_link *link, union hpd_irq_data *o= ut_hpd_irq_dpcd_data, bool *out_link_loss) +{ + return handle_hpd_rx_irq(link, out_hpd_irq_dpcd_data, out_link_loss, fals= e, NULL); +} + /*query dpcd for version and mst cap addresses*/ bool is_mst_supported(struct dc_link *link) { diff --git a/drivers/gpu/drm/amd/display/dc/dc_link.h b/drivers/gpu/drm/amd= /display/dc/dc_link.h index 83845d006c54..0efa2bc8639b 100644 --- a/drivers/gpu/drm/amd/display/dc/dc_link.h +++ b/drivers/gpu/drm/amd/display/dc/dc_link.h @@ -308,6 +308,9 @@ bool dc_link_wait_for_t12(struct dc_link *link); enum dc_status read_hpd_rx_irq_data( struct dc_link *link, union hpd_irq_data *irq_data); +void dc_link_dp_handle_automated_test(struct dc_link *link); +void dc_link_dp_handle_link_loss(struct dc_link *link); +bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link); =20 struct dc_sink_init_data; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE810C19F2C for ; Wed, 27 Jul 2022 17:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237862AbiG0RI1 (ORCPT ); Wed, 27 Jul 2022 13:08:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbiG0RHv (ORCPT ); Wed, 27 Jul 2022 13:07:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40A791E3CA; Wed, 27 Jul 2022 09:40:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2F6B4B821A6; Wed, 27 Jul 2022 16:40:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7426BC433D6; Wed, 27 Jul 2022 16:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940012; bh=+h+gwRdGWwGx5T79uwU2v5LX43yylfttSA57ZGp5D9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=amaD8GjqMhQXKVxa0WssXNb0Gru+crOHDoTfscdGcw0ut0PC8MUSRj73uMpJA5Yba oqL0fGKko+yC0/+AlTkXYueORkVlOSrkGHm3jplzfNpmsb9bV5qVwydkusbI6/F0/T MzMMq4Sv02Nri2h2rqPqWTWihI8NQVdjp+ewfh9Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Kazlauskas , Mikita Lipski , Wayne Lin , Daniel Wheeler , Alex Deucher , Sasha Levin Subject: [PATCH 5.15 044/201] drm/amd/display: Fork thread to offload work of hpd_rx_irq Date: Wed, 27 Jul 2022 18:09:08 +0200 Message-Id: <20220727161028.712609252@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Wayne Lin [ Upstream commit 8e794421bc981586d0af4e959ec76d668c793a55 ] [Why] Currently, we will try to get dm.dc_lock in handle_hpd_rx_irq() when link lost happened, which is risky and could cause deadlock. e.g. If we are under procedure to enable MST streams and then monitor happens to toggle short hpd to notify link lost, then handle_hpd_rx_irq() will get blocked due to stream enabling flow has dc_lock. However, under MST, enabling streams involves communication with remote sinks which need to use handle_hpd_rx_irq() to handle sideband messages. Thus, we have deadlock here. [How] Target is to have handle_hpd_rx_irq() finished as soon as possilble. Hence we can react to interrupt quickly. Besides, we should avoid to grabe dm.dc_lock within handle_hpd_rx_irq() to avoid deadlock situation. Firstly, revert patches which introduced to use dm.dc_lock in handle_hpd_rx_irq(): * commit ("drm/amd/display: NULL pointer error during ") * commit ("drm/amd/display: Only one display lights up while using MST") * commit ("drm/amd/display: take dc_lock in short pulse handler only") Instead, create work to handle irq events which needs dm.dc_lock. Besides: * Create struct hpd_rx_irq_offload_work_queue for each link to handle its short hpd events * Avoid to handle link lost/ automated test if the link is disconnected * Defer dc_lock needed works in dc_link_handle_hpd_rx_irq(). This function should just handle simple stuff for us (e.g. DPCD R/W). However, deferred works should still be handled by the order that dc_link_handle_hpd_rx_irq() used to be. * Change function name dm_handle_hpd_rx_irq() to dm_handle_mst_sideband_msg() to be more specific Reviewed-by: Nicholas Kazlauskas Acked-by: Mikita Lipski Signed-off-by: Wayne Lin Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 203 ++++++++++++++---- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 49 ++++- .../gpu/drm/amd/display/dc/core/dc_link_dp.c | 9 +- drivers/gpu/drm/amd/display/dc/dc_link.h | 6 +- 4 files changed, 219 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 19048f0d83a4..ce647302a1ec 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -1236,6 +1236,83 @@ static void vblank_control_worker(struct work_struct= *work) } =20 #endif + +static void dm_handle_hpd_rx_offload_work(struct work_struct *work) +{ + struct hpd_rx_irq_offload_work *offload_work; + struct amdgpu_dm_connector *aconnector; + struct dc_link *dc_link; + struct amdgpu_device *adev; + enum dc_connection_type new_connection_type =3D dc_connection_none; + unsigned long flags; + + offload_work =3D container_of(work, struct hpd_rx_irq_offload_work, work); + aconnector =3D offload_work->offload_wq->aconnector; + + if (!aconnector) { + DRM_ERROR("Can't retrieve aconnector in hpd_rx_irq_offload_work"); + goto skip; + } + + adev =3D drm_to_adev(aconnector->base.dev); + dc_link =3D aconnector->dc_link; + + mutex_lock(&aconnector->hpd_lock); + if (!dc_link_detect_sink(dc_link, &new_connection_type)) + DRM_ERROR("KMS: Failed to detect connector\n"); + mutex_unlock(&aconnector->hpd_lock); + + if (new_connection_type =3D=3D dc_connection_none) + goto skip; + + if (amdgpu_in_reset(adev)) + goto skip; + + mutex_lock(&adev->dm.dc_lock); + if (offload_work->data.bytes.device_service_irq.bits.AUTOMATED_TEST) + dc_link_dp_handle_automated_test(dc_link); + else if ((dc_link->connector_signal !=3D SIGNAL_TYPE_EDP) && + hpd_rx_irq_check_link_loss_status(dc_link, &offload_work->data) && + dc_link_dp_allow_hpd_rx_irq(dc_link)) { + dc_link_dp_handle_link_loss(dc_link); + spin_lock_irqsave(&offload_work->offload_wq->offload_lock, flags); + offload_work->offload_wq->is_handling_link_loss =3D false; + spin_unlock_irqrestore(&offload_work->offload_wq->offload_lock, flags); + } + mutex_unlock(&adev->dm.dc_lock); + +skip: + kfree(offload_work); + +} + +static struct hpd_rx_irq_offload_work_queue *hpd_rx_irq_create_workqueue(s= truct dc *dc) +{ + int max_caps =3D dc->caps.max_links; + int i =3D 0; + struct hpd_rx_irq_offload_work_queue *hpd_rx_offload_wq =3D NULL; + + hpd_rx_offload_wq =3D kcalloc(max_caps, sizeof(*hpd_rx_offload_wq), GFP_K= ERNEL); + + if (!hpd_rx_offload_wq) + return NULL; + + + for (i =3D 0; i < max_caps; i++) { + hpd_rx_offload_wq[i].wq =3D + create_singlethread_workqueue("amdgpu_dm_hpd_rx_offload_wq"); + + if (hpd_rx_offload_wq[i].wq =3D=3D NULL) { + DRM_ERROR("create amdgpu_dm_hpd_rx_offload_wq fail!"); + return NULL; + } + + spin_lock_init(&hpd_rx_offload_wq[i].offload_lock); + } + + return hpd_rx_offload_wq; +} + static int amdgpu_dm_init(struct amdgpu_device *adev) { struct dc_init_data init_data; @@ -1362,6 +1439,12 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) =20 dc_hardware_init(adev->dm.dc); =20 + adev->dm.hpd_rx_offload_wq =3D hpd_rx_irq_create_workqueue(adev->dm.dc); + if (!adev->dm.hpd_rx_offload_wq) { + DRM_ERROR("amdgpu: failed to create hpd rx offload workqueue.\n"); + goto error; + } + #if defined(CONFIG_DRM_AMD_DC_DCN) if ((adev->flags & AMD_IS_APU) && (adev->asic_type >=3D CHIP_CARRIZO)) { struct dc_phy_addr_space_config pa_config; @@ -1541,6 +1624,18 @@ static void amdgpu_dm_fini(struct amdgpu_device *ade= v) adev->dm.freesync_module =3D NULL; } =20 + if (adev->dm.hpd_rx_offload_wq) { + for (i =3D 0; i < adev->dm.dc->caps.max_links; i++) { + if (adev->dm.hpd_rx_offload_wq[i].wq) { + destroy_workqueue(adev->dm.hpd_rx_offload_wq[i].wq); + adev->dm.hpd_rx_offload_wq[i].wq =3D NULL; + } + } + + kfree(adev->dm.hpd_rx_offload_wq); + adev->dm.hpd_rx_offload_wq =3D NULL; + } + mutex_destroy(&adev->dm.audio_lock); mutex_destroy(&adev->dm.dc_lock); =20 @@ -2160,6 +2255,16 @@ static enum dc_status amdgpu_dm_commit_zero_streams(= struct dc *dc) return res; } =20 +static void hpd_rx_irq_work_suspend(struct amdgpu_display_manager *dm) +{ + int i; + + if (dm->hpd_rx_offload_wq) { + for (i =3D 0; i < dm->dc->caps.max_links; i++) + flush_workqueue(dm->hpd_rx_offload_wq[i].wq); + } +} + static int dm_suspend(void *handle) { struct amdgpu_device *adev =3D handle; @@ -2181,6 +2286,8 @@ static int dm_suspend(void *handle) =20 amdgpu_dm_irq_suspend(adev); =20 + hpd_rx_irq_work_suspend(dm); + return ret; } =20 @@ -2191,6 +2298,8 @@ static int dm_suspend(void *handle) =20 amdgpu_dm_irq_suspend(adev); =20 + hpd_rx_irq_work_suspend(dm); + dc_set_power_state(dm->dc, DC_ACPI_CM_POWER_STATE_D3); =20 return 0; @@ -2869,8 +2978,7 @@ static void handle_hpd_irq(void *param) =20 } =20 - -static void dm_handle_hpd_rx_irq(struct amdgpu_dm_connector *aconnector) +static void dm_handle_mst_sideband_msg(struct amdgpu_dm_connector *aconnec= tor) { uint8_t esi[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] =3D { 0 }; uint8_t dret; @@ -2948,6 +3056,25 @@ static void dm_handle_hpd_rx_irq(struct amdgpu_dm_co= nnector *aconnector) DRM_DEBUG_DRIVER("Loop exceeded max iterations\n"); } =20 +static void schedule_hpd_rx_offload_work(struct hpd_rx_irq_offload_work_qu= eue *offload_wq, + union hpd_irq_data hpd_irq_data) +{ + struct hpd_rx_irq_offload_work *offload_work =3D + kzalloc(sizeof(*offload_work), GFP_KERNEL); + + if (!offload_work) { + DRM_ERROR("Failed to allocate hpd_rx_irq_offload_work.\n"); + return; + } + + INIT_WORK(&offload_work->work, dm_handle_hpd_rx_offload_work); + offload_work->data =3D hpd_irq_data; + offload_work->offload_wq =3D offload_wq; + + queue_work(offload_wq->wq, &offload_work->work); + DRM_DEBUG_KMS("queue work to handle hpd_rx offload work"); +} + static void handle_hpd_rx_irq(void *param) { struct amdgpu_dm_connector *aconnector =3D (struct amdgpu_dm_connector *)= param; @@ -2959,14 +3086,16 @@ static void handle_hpd_rx_irq(void *param) enum dc_connection_type new_connection_type =3D dc_connection_none; struct amdgpu_device *adev =3D drm_to_adev(dev); union hpd_irq_data hpd_irq_data; - bool lock_flag =3D 0; + bool link_loss =3D false; + bool has_left_work =3D false; + int idx =3D aconnector->base.index; + struct hpd_rx_irq_offload_work_queue *offload_wq =3D &adev->dm.hpd_rx_off= load_wq[idx]; =20 memset(&hpd_irq_data, 0, sizeof(hpd_irq_data)); =20 if (adev->dm.disable_hpd_irq) return; =20 - /* * TODO:Temporary add mutex to protect hpd interrupt not have a gpio * conflict, after implement i2c helper, this mutex should be @@ -2974,43 +3103,41 @@ static void handle_hpd_rx_irq(void *param) */ mutex_lock(&aconnector->hpd_lock); =20 - read_hpd_rx_irq_data(dc_link, &hpd_irq_data); + result =3D dc_link_handle_hpd_rx_irq(dc_link, &hpd_irq_data, + &link_loss, true, &has_left_work); =20 - if ((dc_link->cur_link_settings.lane_count !=3D LANE_COUNT_UNKNOWN) || - (dc_link->type =3D=3D dc_connection_mst_branch)) { - if (hpd_irq_data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY) { - result =3D true; - dm_handle_hpd_rx_irq(aconnector); - goto out; - } else if (hpd_irq_data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) { - result =3D false; - dm_handle_hpd_rx_irq(aconnector); + if (!has_left_work) + goto out; + + if (hpd_irq_data.bytes.device_service_irq.bits.AUTOMATED_TEST) { + schedule_hpd_rx_offload_work(offload_wq, hpd_irq_data); + goto out; + } + + if (dc_link_dp_allow_hpd_rx_irq(dc_link)) { + if (hpd_irq_data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY || + hpd_irq_data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) { + dm_handle_mst_sideband_msg(aconnector); goto out; } - } =20 - /* - * TODO: We need the lock to avoid touching DC state while it's being - * modified during automated compliance testing, or when link loss - * happens. While this should be split into subhandlers and proper - * interfaces to avoid having to conditionally lock like this in the - * outer layer, we need this workaround temporarily to allow MST - * lightup in some scenarios to avoid timeout. - */ - if (!amdgpu_in_reset(adev) && - (hpd_rx_irq_check_link_loss_status(dc_link, &hpd_irq_data) || - hpd_irq_data.bytes.device_service_irq.bits.AUTOMATED_TEST)) { - mutex_lock(&adev->dm.dc_lock); - lock_flag =3D 1; - } + if (link_loss) { + bool skip =3D false; =20 -#ifdef CONFIG_DRM_AMD_DC_HDCP - result =3D dc_link_handle_hpd_rx_irq(dc_link, &hpd_irq_data, NULL); -#else - result =3D dc_link_handle_hpd_rx_irq(dc_link, NULL, NULL); -#endif - if (!amdgpu_in_reset(adev) && lock_flag) - mutex_unlock(&adev->dm.dc_lock); + spin_lock(&offload_wq->offload_lock); + skip =3D offload_wq->is_handling_link_loss; + + if (!skip) + offload_wq->is_handling_link_loss =3D true; + + spin_unlock(&offload_wq->offload_lock); + + if (!skip) + schedule_hpd_rx_offload_work(offload_wq, hpd_irq_data); + + goto out; + } + } =20 out: if (result && !is_mst_root_connector) { @@ -3095,6 +3222,10 @@ static void register_hpd_handlers(struct amdgpu_devi= ce *adev) amdgpu_dm_irq_register_interrupt(adev, &int_params, handle_hpd_rx_irq, (void *) aconnector); + + if (adev->dm.hpd_rx_offload_wq) + adev->dm.hpd_rx_offload_wq[connector->index].aconnector =3D + aconnector; } } } diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.h index da87ca77023d..cd059af033b4 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -171,6 +171,48 @@ struct dal_allocation { u64 gpu_addr; }; =20 +/** + * struct hpd_rx_irq_offload_work_queue - Work queue to handle hpd_rx_irq + * offload work + */ +struct hpd_rx_irq_offload_work_queue { + /** + * @wq: workqueue structure to queue offload work. + */ + struct workqueue_struct *wq; + /** + * @offload_lock: To protect fields of offload work queue. + */ + spinlock_t offload_lock; + /** + * @is_handling_link_loss: Used to prevent inserting link loss event when + * we're handling link loss + */ + bool is_handling_link_loss; + /** + * @aconnector: The aconnector that this work queue is attached to + */ + struct amdgpu_dm_connector *aconnector; +}; + +/** + * struct hpd_rx_irq_offload_work - hpd_rx_irq offload work structure + */ +struct hpd_rx_irq_offload_work { + /** + * @work: offload work + */ + struct work_struct work; + /** + * @data: reference irq data which is used while handling offload work + */ + union hpd_irq_data data; + /** + * @offload_wq: offload work queue that this work is queued to + */ + struct hpd_rx_irq_offload_work_queue *offload_wq; +}; + /** * struct amdgpu_display_manager - Central amdgpu display manager device * @@ -461,7 +503,12 @@ struct amdgpu_display_manager { */ struct crc_rd_work *crc_rd_wrk; #endif - + /** + * @hpd_rx_offload_wq: + * + * Work queue to offload works of hpd_rx_irq + */ + struct hpd_rx_irq_offload_work_queue *hpd_rx_offload_wq; /** * @mst_encoders: * diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c b/drivers/gpu= /drm/amd/display/dc/core/dc_link_dp.c index 9b6111eb9ca4..6d5dc5ab3d8c 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_link_dp.c @@ -2075,7 +2075,7 @@ static struct dc_link_settings get_max_link_cap(struc= t dc_link *link) return max_link_cap; } =20 -enum dc_status read_hpd_rx_irq_data( +static enum dc_status read_hpd_rx_irq_data( struct dc_link *link, union hpd_irq_data *irq_data) { @@ -3257,7 +3257,7 @@ void dc_link_dp_handle_link_loss(struct dc_link *link) } } =20 -static bool handle_hpd_rx_irq(struct dc_link *link, union hpd_irq_data *ou= t_hpd_irq_dpcd_data, bool *out_link_loss, +bool dc_link_handle_hpd_rx_irq(struct dc_link *link, union hpd_irq_data *o= ut_hpd_irq_dpcd_data, bool *out_link_loss, bool defer_handling, bool *has_left_work) { union hpd_irq_data hpd_irq_dpcd_data =3D { { { {0} } } }; @@ -3379,11 +3379,6 @@ static bool handle_hpd_rx_irq(struct dc_link *link, = union hpd_irq_data *out_hpd_ return status; } =20 -bool dc_link_handle_hpd_rx_irq(struct dc_link *link, union hpd_irq_data *o= ut_hpd_irq_dpcd_data, bool *out_link_loss) -{ - return handle_hpd_rx_irq(link, out_hpd_irq_dpcd_data, out_link_loss, fals= e, NULL); -} - /*query dpcd for version and mst cap addresses*/ bool is_mst_supported(struct dc_link *link) { diff --git a/drivers/gpu/drm/amd/display/dc/dc_link.h b/drivers/gpu/drm/amd= /display/dc/dc_link.h index 0efa2bc8639b..9b7c32f7fd86 100644 --- a/drivers/gpu/drm/amd/display/dc/dc_link.h +++ b/drivers/gpu/drm/amd/display/dc/dc_link.h @@ -296,7 +296,8 @@ enum dc_status dc_link_allocate_mst_payload(struct pipe= _ctx *pipe_ctx); * false - no change in Downstream port status. No further action required * from DM. */ bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link, - union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss); + union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss, + bool defer_handling, bool *has_left_work); =20 /* * On eDP links this function call will stall until T12 has elapsed. @@ -305,9 +306,6 @@ bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link, */ bool dc_link_wait_for_t12(struct dc_link *link); =20 -enum dc_status read_hpd_rx_irq_data( - struct dc_link *link, - union hpd_irq_data *irq_data); void dc_link_dp_handle_automated_test(struct dc_link *link); void dc_link_dp_handle_link_loss(struct dc_link *link); bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0399C19F2B for ; Wed, 27 Jul 2022 17:04:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbiG0REy (ORCPT ); Wed, 27 Jul 2022 13:04:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235417AbiG0RDe (ORCPT ); Wed, 27 Jul 2022 13:03:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38FB76D9EE; Wed, 27 Jul 2022 09:38:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 598D7601D6; Wed, 27 Jul 2022 16:38:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36F10C433D6; Wed, 27 Jul 2022 16:38:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939925; bh=jSckFS0i9OG7p5Fsqnfo73gIynmNIj8KU+9KEroWCQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0K7yqRFlaP9ibQnX1QM1aPdPULk5medUVIydHAbuo68UtY7T6QJ5gjSkH+5r57U8T j+pCyi3qSBN3f2ojQTlkTdBTFG17FG+M/8giF1Tgi3yDNmJCvuniEy69FUYHw5ebrk 9cdYnPEmAGTghODJmh0LnYoPM1AyWiCPgL/GKEmQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harry Wentland , Alex Deucher , Sasha Levin Subject: [PATCH 5.15 045/201] drm/amdgpu/display: add quirk handling for stutter mode Date: Wed, 27 Jul 2022 18:09:09 +0200 Message-Id: <20220727161028.743348076@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alex Deucher [ Upstream commit 3ce51649cdf23ab463494df2bd6d1e9529ebdc6a ] Stutter mode is a power saving feature on GPUs, however at least one early raven system exhibits stability issues with it. Add a quirk to disable it for that system. Bug: https://bugzilla.kernel.org/show_bug.cgi?id=3D214417 Fixes: 005440066f929b ("drm/amdgpu: enable gfxoff again on raven series (v2= )") Reviewed-by: Harry Wentland Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.c index ce647302a1ec..873cb0051952 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -1313,6 +1313,37 @@ static struct hpd_rx_irq_offload_work_queue *hpd_rx_= irq_create_workqueue(struct return hpd_rx_offload_wq; } =20 +struct amdgpu_stutter_quirk { + u16 chip_vendor; + u16 chip_device; + u16 subsys_vendor; + u16 subsys_device; + u8 revision; +}; + +static const struct amdgpu_stutter_quirk amdgpu_stutter_quirk_list[] =3D { + /* https://bugzilla.kernel.org/show_bug.cgi?id=3D214417 */ + { 0x1002, 0x15dd, 0x1002, 0x15dd, 0xc8 }, + { 0, 0, 0, 0, 0 }, +}; + +static bool dm_should_disable_stutter(struct pci_dev *pdev) +{ + const struct amdgpu_stutter_quirk *p =3D amdgpu_stutter_quirk_list; + + while (p && p->chip_device !=3D 0) { + if (pdev->vendor =3D=3D p->chip_vendor && + pdev->device =3D=3D p->chip_device && + pdev->subsystem_vendor =3D=3D p->subsys_vendor && + pdev->subsystem_device =3D=3D p->subsys_device && + pdev->revision =3D=3D p->revision) { + return true; + } + ++p; + } + return false; +} + static int amdgpu_dm_init(struct amdgpu_device *adev) { struct dc_init_data init_data; @@ -1421,6 +1452,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) =20 if (adev->asic_type !=3D CHIP_CARRIZO && adev->asic_type !=3D CHIP_STONEY) adev->dm.dc->debug.disable_stutter =3D amdgpu_pp_feature_mask & PP_STUTT= ER_MODE ? false : true; + if (dm_should_disable_stutter(adev->pdev)) + adev->dm.dc->debug.disable_stutter =3D true; =20 if (amdgpu_dc_debug_mask & DC_DISABLE_STUTTER) adev->dm.dc->debug.disable_stutter =3D true; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C70BC19F28 for ; Wed, 27 Jul 2022 17:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238330AbiG0RE7 (ORCPT ); Wed, 27 Jul 2022 13:04:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241293AbiG0RDt (ORCPT ); Wed, 27 Jul 2022 13:03:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 351D659243; Wed, 27 Jul 2022 09:38:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CED8FB8200C; Wed, 27 Jul 2022 16:38:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27571C433C1; Wed, 27 Jul 2022 16:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939928; bh=JwfJW2ukWURVYGvjwNjCvPygdx8i2v4juOJY2PSaQ+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tXrNf/2hf/RP/P82PCGwi7OdqR6svrakzv4gI5M2Z9h+sxd61olWCvYg2nnEYEm7f 44Gw8nNygl3AVKceVUIqJ/4TR5boGMrxqdWiSyc1EjvjtXs3osfpn+C4yitiW0NeK4 KPvsUzG5840gQy3XN055IK8kF3vLOVfMeuPp4WLo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fangzhi Zuo , Solomon Chiu , Daniel Wheeler , Alex Deucher , Sasha Levin Subject: [PATCH 5.15 046/201] drm/amd/display: Ignore First MST Sideband Message Return Error Date: Wed, 27 Jul 2022 18:09:10 +0200 Message-Id: <20220727161028.781697992@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Fangzhi Zuo [ Upstream commit acea108fa067d140bd155161a79b1fcd967f4137 ] [why] First MST sideband message returns AUX_RET_ERROR_HPD_DISCON on certain intel platform. Aux transaction considered failure if HPD unexpected pulled low. The actual aux transaction success in such case, hence do not return error. [how] Not returning error when AUX_RET_ERROR_HPD_DISCON detected on the first sideband message. v2: squash in additional DMI entries v3: squash in static fix Signed-off-by: Fangzhi Zuo Acked-by: Solomon Chiu Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 39 +++++++++++++++++++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 8 ++++ .../display/amdgpu_dm/amdgpu_dm_mst_types.c | 17 ++++++++ 3 files changed, 64 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 873cb0051952..7150afacbc4f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -70,6 +70,7 @@ #include #include #include +#include =20 #include #include @@ -1344,6 +1345,41 @@ static bool dm_should_disable_stutter(struct pci_dev= *pdev) return false; } =20 +static const struct dmi_system_id hpd_disconnect_quirk_table[] =3D { + { + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Precision 3660"), + }, + }, + { + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Precision 3260"), + }, + }, + { + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Precision 3460"), + }, + }, + {} +}; + +static void retrieve_dmi_info(struct amdgpu_display_manager *dm) +{ + const struct dmi_system_id *dmi_id; + + dm->aux_hpd_discon_quirk =3D false; + + dmi_id =3D dmi_first_match(hpd_disconnect_quirk_table); + if (dmi_id) { + dm->aux_hpd_discon_quirk =3D true; + DRM_INFO("aux_hpd_discon_quirk attached\n"); + } +} + static int amdgpu_dm_init(struct amdgpu_device *adev) { struct dc_init_data init_data; @@ -1435,6 +1471,9 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) init_data.flags.power_down_display_on_boot =3D true; =20 INIT_LIST_HEAD(&adev->dm.da_list); + + retrieve_dmi_info(&adev->dm); + /* Display Core create. */ adev->dm.dc =3D dc_create(&init_data); =20 diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gp= u/drm/amd/display/amdgpu_dm/amdgpu_dm.h index cd059af033b4..f9c3e5a41713 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -539,6 +539,14 @@ struct amdgpu_display_manager { * last successfully applied backlight values. */ u32 actual_brightness[AMDGPU_DM_MAX_NUM_EDP]; + + /** + * @aux_hpd_discon_quirk: + * + * quirk for hpd discon while aux is on-going. + * occurred on certain intel platform + */ + bool aux_hpd_discon_quirk; }; =20 enum dsc_clock_force_state { diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/= drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c index 74885ff77f96..652cf108b3c2 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c @@ -55,6 +55,8 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux, ssize_t result =3D 0; struct aux_payload payload; enum aux_return_code_type operation_result; + struct amdgpu_device *adev; + struct ddc_service *ddc; =20 if (WARN_ON(msg->size > 16)) return -E2BIG; @@ -71,6 +73,21 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux, result =3D dc_link_aux_transfer_raw(TO_DM_AUX(aux)->ddc_service, &payload, &operation_result); =20 + /* + * w/a on certain intel platform where hpd is unexpected to pull low duri= ng + * 1st sideband message transaction by return AUX_RET_ERROR_HPD_DISCON + * aux transaction is succuess in such case, therefore bypass the error + */ + ddc =3D TO_DM_AUX(aux)->ddc_service; + adev =3D ddc->ctx->driver_context; + if (adev->dm.aux_hpd_discon_quirk) { + if (msg->address =3D=3D DP_SIDEBAND_MSG_DOWN_REQ_BASE && + operation_result =3D=3D AUX_RET_ERROR_HPD_DISCON) { + result =3D 0; + operation_result =3D AUX_RET_SUCCESS; + } + } + if (payload.write && result >=3D 0) result =3D msg->size; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E474C04A68 for ; Wed, 27 Jul 2022 17:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229598AbiG0RFF (ORCPT ); Wed, 27 Jul 2022 13:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241400AbiG0REL (ORCPT ); Wed, 27 Jul 2022 13:04:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D48E6E88B; Wed, 27 Jul 2022 09:39:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04F7D601CD; Wed, 27 Jul 2022 16:38:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D07F6C433D6; Wed, 27 Jul 2022 16:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939931; bh=gwizZq9ZKJfacNy3ZHHGP30UdHE5Ee0t3vfEcqGt4H4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zB3BAjhMpoh4iqi+db9Y0vkTyrVLfetLFoZcUpWDZhgh2co3cw4zpFhORQezLkIoq 6hgWBcKw96yrzz34XesDrAoABXtiFxFiaoDodhaHpI/CCBUkx3udNmH3oz6x8byIOH A7nwNhKDGIjWhlPhNIZv0xsMkSmgurxMyMNQVASo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kashyap Desai , sumit.saxena@broadcom.com, chandrakanth.patil@broadcom.com, linux-block@vger.kernel.org, Hannes Reinecke , Guangwu Zhang , Bart Van Assche , Ming Lei , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.15 047/201] scsi: megaraid: Clear READ queue maps nr_queues Date: Wed, 27 Jul 2022 18:09:11 +0200 Message-Id: <20220727161028.830121884@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ming Lei [ Upstream commit 8312cd3a7b835ae3033a679e5f0014a40e7891c5 ] The megaraid SCSI driver sets set->nr_maps as 3 if poll_queues is > 0, and blk-mq actually initializes each map's nr_queues as nr_hw_queues. Consequently the driver has to clear READ queue map's nr_queues, otherwise the queue map becomes broken if poll_queues is set as non-zero. Link: https://lore.kernel.org/r/20220706125942.528533-1-ming.lei@redhat.com Fixes: 9e4bec5b2a23 ("scsi: megaraid_sas: mq_poll support") Cc: Kashyap Desai Cc: sumit.saxena@broadcom.com Cc: chandrakanth.patil@broadcom.com Cc: linux-block@vger.kernel.org Cc: Hannes Reinecke Reported-by: Guangwu Zhang Tested-by: Guangwu Zhang Reviewed-by: Bart Van Assche Signed-off-by: Ming Lei Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/scsi/megaraid/megaraid_sas_base.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megar= aid/megaraid_sas_base.c index bb3f78013a13..88e164e3d2ea 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -3196,6 +3196,9 @@ static int megasas_map_queues(struct Scsi_Host *shost) qoff +=3D map->nr_queues; offset +=3D map->nr_queues; =20 + /* we never use READ queue, so can't cheat blk-mq */ + shost->tag_set.map[HCTX_TYPE_READ].nr_queues =3D 0; + /* Setup Poll hctx */ map =3D &shost->tag_set.map[HCTX_TYPE_POLL]; map->nr_queues =3D instance->iopoll_q_count; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A70AC04A68 for ; Wed, 27 Jul 2022 17:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241329AbiG0RFX (ORCPT ); Wed, 27 Jul 2022 13:05:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241472AbiG0RET (ORCPT ); Wed, 27 Jul 2022 13:04:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E7A56E8A9; Wed, 27 Jul 2022 09:39:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 86C13B821B6; Wed, 27 Jul 2022 16:38:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D04B4C433D6; Wed, 27 Jul 2022 16:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939934; bh=NIaVVLE+pEn8Ee5MvqbaxjbH8CI2HF9VkpWMB7V+KKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1FokX5ckaCjighnTfT0/wfWGnDurcnCc3kwNcQbe2I3P5+OHvRfOXw7WOd0qQ1UpM /1Ve9dGkpVOXGgEcd13e+NRDLiMX7bCWAoznzo3EjoKrPgy/gRgX9wwzWPFrzpjUAw wYpiVyjJIOyO7ApPTt0KFKV+Bkmk/m967TE+mRFM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alim Akhtar , Bean Huo , Bjorn Andersson , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.15 048/201] scsi: ufs: core: Drop loglevel of WriteBoost message Date: Wed, 27 Jul 2022 18:09:12 +0200 Message-Id: <20220727161028.870672255@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Bjorn Andersson [ Upstream commit 2ae57c995003a7840cb6b5ec5f0c06193695321b ] Commit '3b5f3c0d0548 ("scsi: ufs: core: Tidy up WB configuration code")' changed the log level of the write boost enable/disable notification from debug to info. This results in a lot of noise in the kernel log during normal operation. Drop it back to debug level to avoid this. Link: https://lore.kernel.org/r/20220709000027.3929970-1-bjorn.andersson@li= naro.org Fixes: 3b5f3c0d0548 ("scsi: ufs: core: Tidy up WB configuration code") Reviewed-by: Alim Akhtar Acked-by: Bean Huo Signed-off-by: Bjorn Andersson Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/scsi/ufs/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 5c9a31f18b7f..4a7248421bcd 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -5638,7 +5638,7 @@ int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable) } =20 hba->dev_info.wb_enabled =3D enable; - dev_info(hba->dev, "%s Write Booster %s\n", + dev_dbg(hba->dev, "%s Write Booster %s\n", __func__, enable ? "enabled" : "disabled"); =20 return ret; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8851FC04A68 for ; Wed, 27 Jul 2022 17:05:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232288AbiG0RF1 (ORCPT ); Wed, 27 Jul 2022 13:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241480AbiG0REU (ORCPT ); Wed, 27 Jul 2022 13:04:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE61A6E8AE; Wed, 27 Jul 2022 09:39:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8D48760BAF; Wed, 27 Jul 2022 16:38:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D4B7C4347C; Wed, 27 Jul 2022 16:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939937; bh=QipLENRbmLpjRNNqpZHNq2yd88w3mvICFXc2xDS2GzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uwB5zqo9YHPojMukS+gRoQNL1JCBNE2G23dM3bmiWl3Yp6BVduCtfEy78tDAVm+Eo YCT7f2BD2Xx5YNII9oQD1rGbyUaheRvrbbnaFAsy5MzkUGUV4xcWYEV6EXrJcLnHYs aqQRzNpqfdlV/do+7LRYYMTgV8mI+W6Rxpthz6eQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni , Sasha Levin Subject: [PATCH 5.15 049/201] nvme: check for duplicate identifiers earlier Date: Wed, 27 Jul 2022 18:09:13 +0200 Message-Id: <20220727161028.923733857@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Christoph Hellwig [ Upstream commit e2d77d2e11c4f1e70a1a24cc8fe63ff3dc9b53ef ] Lift the check for duplicate identifiers into nvme_init_ns_head, which avoids pointless error unwinding in case they don't match, and also matches where we check identifier validity for the multipath case. Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Chaitanya Kulkarni Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/nvme/host/core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 29b56ea01132..8fca84d44446 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3686,13 +3686,6 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struc= t nvme_ctrl *ctrl, head->ids =3D *ids; kref_init(&head->ref); =20 - ret =3D nvme_subsys_check_duplicate_ids(ctrl->subsys, &head->ids); - if (ret) { - dev_err(ctrl->device, - "duplicate IDs for nsid %d\n", nsid); - goto out_cleanup_srcu; - } - if (head->ids.csi) { ret =3D nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); if (ret) @@ -3731,6 +3724,12 @@ static int nvme_init_ns_head(struct nvme_ns *ns, uns= igned nsid, mutex_lock(&ctrl->subsys->lock); head =3D nvme_find_ns_head(ctrl, nsid); if (!head) { + ret =3D nvme_subsys_check_duplicate_ids(ctrl->subsys, ids); + if (ret) { + dev_err(ctrl->device, + "duplicate IDs for nsid %d\n", nsid); + goto out_unlock; + } head =3D nvme_alloc_ns_head(ctrl, nsid, ids); if (IS_ERR(head)) { ret =3D PTR_ERR(head); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FBF9C04A68 for ; Wed, 27 Jul 2022 17:05:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241192AbiG0RFe (ORCPT ); Wed, 27 Jul 2022 13:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241500AbiG0REW (ORCPT ); Wed, 27 Jul 2022 13:04:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63DE56E8B7; Wed, 27 Jul 2022 09:39:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 72176601CE; Wed, 27 Jul 2022 16:39:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EA79C433C1; Wed, 27 Jul 2022 16:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939939; bh=9FCF1x1SQRRZNClD09Kcp9xA8mgHRhj/2fAz1e3g2F8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FhFgeJCDlVtrBOrWddp/uk5xUB+QB7Plfl+6QIDgD46r3CABz8StjgGlmxladHFKd 6u1632DEHn3cINxNd7nqvSMmEZNJ19joVtojsglEUJRE/H5tecziOICk0sKildzg1C ItAzHtQy174KEBMTtFBR/1LMu36mKfMRSkS3HXiw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Israel Rukshin , Keith Busch , Max Gurtovoy , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.15 050/201] nvme: fix block device naming collision Date: Wed, 27 Jul 2022 18:09:14 +0200 Message-Id: <20220727161028.969627813@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Israel Rukshin [ Upstream commit 6961b5e02876b3b47f030a1f1ee8fd3e631ac270 ] The issue exists when multipath is enabled and the namespace is shared, but all the other controller checks at nvme_is_unique_nsid() are false. The reason for this issue is that nvme_is_unique_nsid() returns false when is called from nvme_mpath_alloc_disk() due to an uninitialized value of head->shared. The patch fixes it by setting head->shared before nvme_mpath_alloc_disk() is called. Fixes: 5974ea7ce0f9 ("nvme: allow duplicate NSIDs for private namespaces") Signed-off-by: Israel Rukshin Reviewed-by: Keith Busch Reviewed-by: Max Gurtovoy Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/nvme/host/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 8fca84d44446..0c9cdbaf5cd6 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3660,7 +3660,7 @@ static int nvme_add_ns_cdev(struct nvme_ns *ns) } =20 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, - unsigned nsid, struct nvme_ns_ids *ids) + unsigned nsid, struct nvme_ns_ids *ids, bool is_shared) { struct nvme_ns_head *head; size_t size =3D sizeof(*head); @@ -3684,6 +3684,7 @@ static struct nvme_ns_head *nvme_alloc_ns_head(struct= nvme_ctrl *ctrl, head->subsys =3D ctrl->subsys; head->ns_id =3D nsid; head->ids =3D *ids; + head->shared =3D is_shared; kref_init(&head->ref); =20 if (head->ids.csi) { @@ -3730,12 +3731,11 @@ static int nvme_init_ns_head(struct nvme_ns *ns, un= signed nsid, "duplicate IDs for nsid %d\n", nsid); goto out_unlock; } - head =3D nvme_alloc_ns_head(ctrl, nsid, ids); + head =3D nvme_alloc_ns_head(ctrl, nsid, ids, is_shared); if (IS_ERR(head)) { ret =3D PTR_ERR(head); goto out_unlock; } - head->shared =3D is_shared; } else { ret =3D -EINVAL; if (!is_shared || !head->shared) { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19E31C04A68 for ; Wed, 27 Jul 2022 17:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235187AbiG0RFN (ORCPT ); Wed, 27 Jul 2022 13:05:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241440AbiG0REP (ORCPT ); Wed, 27 Jul 2022 13:04:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B826C6E899; Wed, 27 Jul 2022 09:39:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E726601C0; Wed, 27 Jul 2022 16:39:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76407C433D7; Wed, 27 Jul 2022 16:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939942; bh=giqDU7zsSjegWF/j8kJdmRjlOFOf2/ZA0i2RNKPQALM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wz1omDRPOy2AiSsbo2jv/hhOBqsy8bMgqWtti7hbSFnv3UMLMGP7W58q/1MJiy3L+ p1U4i0XRUBd3HfcJPZm8T7eTwAhS/FowJHwvAzZ8C2H4ztFu+dyJbinR2wUn1VOWL7 eTKiXefJoooCseboJzzOQeikW5pp3OTkWFEKZSwY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dima Ruinskiy , Sasha Neftin , "Chia-Lin Kao (AceLan)" , Naama Meir , Tony Nguyen , Sasha Levin Subject: [PATCH 5.15 051/201] e1000e: Enable GPT clock before sending message to CSME Date: Wed, 27 Jul 2022 18:09:15 +0200 Message-Id: <20220727161029.008245517@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sasha Neftin [ Upstream commit b49feacbeffc7635cc6692cbcc6a1eae2c17da6f ] On corporate (CSME) ADL systems, the Ethernet Controller may stop working ("HW unit hang") after exiting from the s0ix state. The reason is that CSME misses the message sent by the host. Enabling the dynamic GPT clock solves this problem. This clock is cleared upon HW initialization. Fixes: 3e55d231716e ("e1000e: Add handshake with the CSME to support S0ix") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=3D214821 Reviewed-by: Dima Ruinskiy Signed-off-by: Sasha Neftin Tested-by: Chia-Lin Kao (AceLan) Tested-by: Naama Meir Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/intel/e1000e/netdev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ether= net/intel/e1000e/netdev.c index ce48e630fe55..0fba6ccecf12 100644 --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -6499,6 +6499,10 @@ static void e1000e_s0ix_exit_flow(struct e1000_adapt= er *adapter) =20 if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID && hw->mac.type >=3D e1000_pch_adp) { + /* Keep the GPT clock enabled for CSME */ + mac_data =3D er32(FEXTNVM); + mac_data |=3D BIT(3); + ew32(FEXTNVM, mac_data); /* Request ME unconfigure the device from S0ix */ mac_data =3D er32(H2ME); mac_data &=3D ~E1000_H2ME_START_DPG; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE409C04A68 for ; Wed, 27 Jul 2022 17:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241362AbiG0RFh (ORCPT ); Wed, 27 Jul 2022 13:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241549AbiG0RE2 (ORCPT ); Wed, 27 Jul 2022 13:04:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FBB15A140; Wed, 27 Jul 2022 09:39:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 023B3B821AC; Wed, 27 Jul 2022 16:39:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E086C433C1; Wed, 27 Jul 2022 16:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939945; bh=e20EUWmZgSZbpAgmRG7IFoz3qsJJw30BAVwpb8YR1jw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Onm12+Ntc2zTUETcmCzs0dCqxmY7QzK/v6vNA2iugZdFl3bAeKnFFtqjRoEQ8fuCU lqPFJUr/rqX3lmmk+312U3KkBKb57hWjx3a8P2H4fVAUvQxfnraP2SCizq0hoZbyNY Wp4sdMlw/JNASuzo08C0EOIMXB3YJF05wOognOpU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sasha Neftin , Naama Meir , Tony Nguyen , Sasha Levin Subject: [PATCH 5.15 052/201] Revert "e1000e: Fix possible HW unit hang after an s0ix exit" Date: Wed, 27 Jul 2022 18:09:16 +0200 Message-Id: <20220727161029.051627351@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sasha Neftin [ Upstream commit 6cfa45361d3eac31ba67d7d0bbef547151450106 ] This reverts commit 1866aa0d0d6492bc2f8d22d0df49abaccf50cddd. Commit 1866aa0d0d64 ("e1000e: Fix possible HW unit hang after an s0ix exit") was a workaround for CSME problem to handle messages comes via H2ME mailbox. This problem has been fixed by patch "e1000e: Enable the GPT clock before sending message to the CSME". Fixes: 3e55d231716e ("e1000e: Add handshake with the CSME to support S0ix") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=3D214821 Signed-off-by: Sasha Neftin Tested-by: Naama Meir Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/intel/e1000e/hw.h | 1 - drivers/net/ethernet/intel/e1000e/ich8lan.c | 4 ---- drivers/net/ethernet/intel/e1000e/ich8lan.h | 1 - drivers/net/ethernet/intel/e1000e/netdev.c | 26 --------------------- 4 files changed, 32 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/= intel/e1000e/hw.h index 13382df2f2ef..bcf680e83811 100644 --- a/drivers/net/ethernet/intel/e1000e/hw.h +++ b/drivers/net/ethernet/intel/e1000e/hw.h @@ -630,7 +630,6 @@ struct e1000_phy_info { bool disable_polarity_correction; bool is_mdix; bool polarity_correction; - bool reset_disable; bool speed_downgraded; bool autoneg_wait_to_complete; }; diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethe= rnet/intel/e1000e/ich8lan.c index e6c8e6d5234f..9466f65a6da7 100644 --- a/drivers/net/ethernet/intel/e1000e/ich8lan.c +++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c @@ -2050,10 +2050,6 @@ static s32 e1000_check_reset_block_ich8lan(struct e1= 000_hw *hw) bool blocked =3D false; int i =3D 0; =20 - /* Check the PHY (LCD) reset flag */ - if (hw->phy.reset_disable) - return true; - while ((blocked =3D !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) && (i++ < 30)) usleep_range(10000, 11000); diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.h b/drivers/net/ethe= rnet/intel/e1000e/ich8lan.h index 638a3ddd7ada..2504b11c3169 100644 --- a/drivers/net/ethernet/intel/e1000e/ich8lan.h +++ b/drivers/net/ethernet/intel/e1000e/ich8lan.h @@ -271,7 +271,6 @@ #define I217_CGFREG_ENABLE_MTA_RESET 0x0002 #define I217_MEMPWR PHY_REG(772, 26) #define I217_MEMPWR_DISABLE_SMB_RELEASE 0x0010 -#define I217_MEMPWR_MOEM 0x1000 =20 /* Receive Address Initial CRC Calculation */ #define E1000_PCH_RAICC(_n) (0x05F50 + ((_n) * 4)) diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ether= net/intel/e1000e/netdev.c index 0fba6ccecf12..407bbb4cc236 100644 --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -6996,21 +6996,8 @@ static __maybe_unused int e1000e_pm_suspend(struct d= evice *dev) struct net_device *netdev =3D pci_get_drvdata(to_pci_dev(dev)); struct e1000_adapter *adapter =3D netdev_priv(netdev); struct pci_dev *pdev =3D to_pci_dev(dev); - struct e1000_hw *hw =3D &adapter->hw; - u16 phy_data; int rc; =20 - if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID && - hw->mac.type >=3D e1000_pch_adp) { - /* Mask OEM Bits / Gig Disable / Restart AN (772_26[12] =3D 1) */ - e1e_rphy(hw, I217_MEMPWR, &phy_data); - phy_data |=3D I217_MEMPWR_MOEM; - e1e_wphy(hw, I217_MEMPWR, phy_data); - - /* Disable LCD reset */ - hw->phy.reset_disable =3D true; - } - e1000e_flush_lpic(pdev); =20 e1000e_pm_freeze(dev); @@ -7032,8 +7019,6 @@ static __maybe_unused int e1000e_pm_resume(struct dev= ice *dev) struct net_device *netdev =3D pci_get_drvdata(to_pci_dev(dev)); struct e1000_adapter *adapter =3D netdev_priv(netdev); struct pci_dev *pdev =3D to_pci_dev(dev); - struct e1000_hw *hw =3D &adapter->hw; - u16 phy_data; int rc; =20 /* Introduce S0ix implementation */ @@ -7044,17 +7029,6 @@ static __maybe_unused int e1000e_pm_resume(struct de= vice *dev) if (rc) return rc; =20 - if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID && - hw->mac.type >=3D e1000_pch_adp) { - /* Unmask OEM Bits / Gig Disable / Restart AN 772_26[12] =3D 0 */ - e1e_rphy(hw, I217_MEMPWR, &phy_data); - phy_data &=3D ~I217_MEMPWR_MOEM; - e1e_wphy(hw, I217_MEMPWR, phy_data); - - /* Enable LCD reset */ - hw->phy.reset_disable =3D false; - } - return e1000e_pm_thaw(dev); } =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3E8CC04A68 for ; Wed, 27 Jul 2022 17:05:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241386AbiG0RFp (ORCPT ); Wed, 27 Jul 2022 13:05:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241557AbiG0REa (ORCPT ); Wed, 27 Jul 2022 13:04:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1714E5A15E; Wed, 27 Jul 2022 09:39:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D5F73B821C5; Wed, 27 Jul 2022 16:39:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FD2DC433D6; Wed, 27 Jul 2022 16:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939948; bh=dCvMNa0Ys6cuvhVxigehd63DciVmN1fTCsj0DT0s+xc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1W27+mAEA2DzYLIyytbVqaEKaOuviNSINji80gIm/3wyLUaDMQ8prw3oZZtPZ1wLd 1Ur8JarOvyf+ey+cleblOK5ZHS9+UwMQ05e8y+yhkhTEC51T0Dfsiq54ELHIVKK2FS Lue8TENMuxUJgy1r/edQinNpV4f8G6nc6PWpLdw0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lennert Buytenhek , Naama Meir , Sasha Neftin , Tony Nguyen , Sasha Levin Subject: [PATCH 5.15 053/201] igc: Reinstate IGC_REMOVED logic and implement it properly Date: Wed, 27 Jul 2022 18:09:17 +0200 Message-Id: <20220727161029.102794395@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lennert Buytenhek [ Upstream commit 7c1ddcee5311f3315096217881d2dbe47cc683f9 ] The initially merged version of the igc driver code (via commit 146740f9abc4, "igc: Add support for PF") contained the following IGC_REMOVED checks in the igc_rd32/wr32() MMIO accessors: u32 igc_rd32(struct igc_hw *hw, u32 reg) { u8 __iomem *hw_addr =3D READ_ONCE(hw->hw_addr); u32 value =3D 0; if (IGC_REMOVED(hw_addr)) return ~value; value =3D readl(&hw_addr[reg]); /* reads should not return all F's */ if (!(~value) && (!reg || !(~readl(hw_addr)))) hw->hw_addr =3D NULL; return value; } And: #define wr32(reg, val) \ do { \ u8 __iomem *hw_addr =3D READ_ONCE((hw)->hw_addr); \ if (!IGC_REMOVED(hw_addr)) \ writel((val), &hw_addr[(reg)]); \ } while (0) E.g. igb has similar checks in its MMIO accessors, and has a similar macro E1000_REMOVED, which is implemented as follows: #define E1000_REMOVED(h) unlikely(!(h)) These checks serve to detect and take note of an 0xffffffff MMIO read return from the device, which can be caused by a PCIe link flap or some other kind of PCI bus error, and to avoid performing MMIO reads and writes from that point onwards. However, the IGC_REMOVED macro was not originally implemented: #ifndef IGC_REMOVED #define IGC_REMOVED(a) (0) #endif /* IGC_REMOVED */ This led to the IGC_REMOVED logic to be removed entirely in a subsequent commit (commit 3c215fb18e70, "igc: remove IGC_REMOVED function"), with the rationale that such checks matter only for virtualization and that igc does not support virtualization -- but a PCIe device can become detached even without virtualization being in use, and without proper checks, a PCIe bus error affecting an igc adapter will lead to various NULL pointer dereferences, as the first access after the error will set hw->hw_addr to NULL, and subsequent accesses will blindly dereference this now-NULL pointer. This patch reinstates the IGC_REMOVED checks in igc_rd32/wr32(), and implements IGC_REMOVED the way it is done for igb, by checking for the unlikely() case of hw_addr being NULL. This change prevents the oopses seen when a PCIe link flap occurs on an igc adapter. Fixes: 146740f9abc4 ("igc: Add support for PF") Signed-off-by: Lennert Buytenhek Tested-by: Naama Meir Acked-by: Sasha Neftin Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/intel/igc/igc_main.c | 3 +++ drivers/net/ethernet/intel/igc/igc_regs.h | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethern= et/intel/igc/igc_main.c index f99819fc559d..2a84f57ea68b 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -6159,6 +6159,9 @@ u32 igc_rd32(struct igc_hw *hw, u32 reg) u8 __iomem *hw_addr =3D READ_ONCE(hw->hw_addr); u32 value =3D 0; =20 + if (IGC_REMOVED(hw_addr)) + return ~value; + value =3D readl(&hw_addr[reg]); =20 /* reads should not return all F's */ diff --git a/drivers/net/ethernet/intel/igc/igc_regs.h b/drivers/net/ethern= et/intel/igc/igc_regs.h index e197a33d93a0..026c3b65fc37 100644 --- a/drivers/net/ethernet/intel/igc/igc_regs.h +++ b/drivers/net/ethernet/intel/igc/igc_regs.h @@ -306,7 +306,8 @@ u32 igc_rd32(struct igc_hw *hw, u32 reg); #define wr32(reg, val) \ do { \ u8 __iomem *hw_addr =3D READ_ONCE((hw)->hw_addr); \ - writel((val), &hw_addr[(reg)]); \ + if (!IGC_REMOVED(hw_addr)) \ + writel((val), &hw_addr[(reg)]); \ } while (0) =20 #define rd32(reg) (igc_rd32(hw, reg)) @@ -318,4 +319,6 @@ do { \ =20 #define array_rd32(reg, offset) (igc_rd32(hw, (reg) + ((offset) << 2))) =20 +#define IGC_REMOVED(h) unlikely(!(h)) + #endif --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B9A0C19F28 for ; Wed, 27 Jul 2022 17:05:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241376AbiG0RFl (ORCPT ); Wed, 27 Jul 2022 13:05:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241551AbiG0RE3 (ORCPT ); Wed, 27 Jul 2022 13:04:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71D436F7CA; Wed, 27 Jul 2022 09:39:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F0B4560B9E; Wed, 27 Jul 2022 16:39:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D383AC433B5; Wed, 27 Jul 2022 16:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939951; bh=2OV7QM4VRlC9VoPMrR3G1NY2dsKHxkkbtdoeD4eJBoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=chvFBWab/OsCzhk9jzeZs/zp4WeoWKyyDpM/Z5+yDrCdzdnT3pXGzcikcdqUFq0CD Y1o/WWRJwlGnpucFipSRvaCteggcPjduGjH+in/RanQP+ta2BBaOtjCSHLTKcNYXR9 s3d9nF+YYn9WwV6IiLM6jflp0xLjNn0B8OiyMY98= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 054/201] ip: Fix data-races around sysctl_ip_no_pmtu_disc. Date: Wed, 27 Jul 2022 18:09:18 +0200 Message-Id: <20220727161029.152740326@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 0968d2a441bf6afb551fd99e60fa65ed67068963 ] While reading sysctl_ip_no_pmtu_disc, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/af_inet.c | 2 +- net/ipv4/icmp.c | 2 +- net/ipv6/af_inet6.c | 2 +- net/xfrm/xfrm_state.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 44f21278003d..781c595f6880 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -338,7 +338,7 @@ static int inet_create(struct net *net, struct socket *= sock, int protocol, inet->hdrincl =3D 1; } =20 - if (net->ipv4.sysctl_ip_no_pmtu_disc) + if (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc)) inet->pmtudisc =3D IP_PMTUDISC_DONT; else inet->pmtudisc =3D IP_PMTUDISC_WANT; diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index a5cc89506c1e..609c4ff7edc6 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -887,7 +887,7 @@ static bool icmp_unreach(struct sk_buff *skb) * values please see * Documentation/networking/ip-sysctl.rst */ - switch (net->ipv4.sysctl_ip_no_pmtu_disc) { + switch (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc)) { default: net_dbg_ratelimited("%pI4: fragmentation needed and DF set\n", &iph->daddr); diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index dab4a047590b..3a91d0d40aec 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -226,7 +226,7 @@ static int inet6_create(struct net *net, struct socket = *sock, int protocol, RCU_INIT_POINTER(inet->mc_list, NULL); inet->rcv_tos =3D 0; =20 - if (net->ipv4.sysctl_ip_no_pmtu_disc) + if (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc)) inet->pmtudisc =3D IP_PMTUDISC_DONT; else inet->pmtudisc =3D IP_PMTUDISC_WANT; diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index f7bfa1916968..b1a04a22166f 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -2619,7 +2619,7 @@ int __xfrm_init_state(struct xfrm_state *x, bool init= _replay, bool offload) int err; =20 if (family =3D=3D AF_INET && - xs_net(x)->ipv4.sysctl_ip_no_pmtu_disc) + READ_ONCE(xs_net(x)->ipv4.sysctl_ip_no_pmtu_disc)) x->props.flags |=3D XFRM_STATE_NOPMTUDISC; =20 err =3D -EPROTONOSUPPORT; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F8E5C04A68 for ; Wed, 27 Jul 2022 17:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241401AbiG0RFw (ORCPT ); Wed, 27 Jul 2022 13:05:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241597AbiG0REf (ORCPT ); Wed, 27 Jul 2022 13:04:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 608A74C63C; Wed, 27 Jul 2022 09:39:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 224FBB821A6; Wed, 27 Jul 2022 16:39:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 824CEC433D6; Wed, 27 Jul 2022 16:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939956; bh=tcohENSnTn9ApzQNJ8s34HgLrmRyd8mviR5F0X8TjaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=03ji6bmeSqvep22fdaLDq5zqjFJ/vwCD7wTiPTISFyR1z8K49hX5vAzLPGe+d+jIx JfLUViF4QysrgK3XXgIvk3C0oi6RAlILp5EO2YSZn94fMXi4uSW5JixRss5pKzen4+ jWKRbPxs2BFYmfSVjiEC9A/bRe32GwegnOGxYWpY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 055/201] ip: Fix data-races around sysctl_ip_fwd_use_pmtu. Date: Wed, 27 Jul 2022 18:09:19 +0200 Message-Id: <20220727161029.193381837@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 60c158dc7b1f0558f6cadd5b50d0386da0000d50 ] While reading sysctl_ip_fwd_use_pmtu, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: f87c10a8aa1e ("ipv4: introduce ip_dst_mtu_maybe_forward and protect = forwarding path against pmtu spoofing") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/ip.h | 2 +- net/ipv4/route.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index a77a9e1c6c04..c69dd114f367 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -441,7 +441,7 @@ static inline unsigned int ip_dst_mtu_maybe_forward(con= st struct dst_entry *dst, struct net *net =3D dev_net(dst->dev); unsigned int mtu; =20 - if (net->ipv4.sysctl_ip_fwd_use_pmtu || + if (READ_ONCE(net->ipv4.sysctl_ip_fwd_use_pmtu) || ip_mtu_locked(dst) || !forwarding) { mtu =3D rt->rt_pmtu; diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 1db2fda22830..7f08a30256c5 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1404,7 +1404,7 @@ u32 ip_mtu_from_fib_result(struct fib_result *res, __= be32 daddr) struct fib_info *fi =3D res->fi; u32 mtu =3D 0; =20 - if (dev_net(dev)->ipv4.sysctl_ip_fwd_use_pmtu || + if (READ_ONCE(dev_net(dev)->ipv4.sysctl_ip_fwd_use_pmtu) || fi->fib_metrics->metrics[RTAX_LOCK - 1] & (1 << RTAX_MTU)) mtu =3D fi->fib_mtu; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17B70C19F2B for ; Wed, 27 Jul 2022 17:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241412AbiG0RF5 (ORCPT ); Wed, 27 Jul 2022 13:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241608AbiG0REk (ORCPT ); Wed, 27 Jul 2022 13:04:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B344E60E; Wed, 27 Jul 2022 09:39:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 65190601D2; Wed, 27 Jul 2022 16:39:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 695E4C433C1; Wed, 27 Jul 2022 16:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939959; bh=2vd55fXTxnJeCDvZnoUJYpKKNmBwqMVbZenpWU+mA8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wSuAwFsuP01GGiN2LZAc76kvJ84rCx1Uwq0lsekEwQ/A3xaERPqqr3uy60Ar7M4Mb 7Nh0fwoxASgSdkDw8t44qJNY0aAjAbzslvbbimPjSzSXnuchxnCIyAZIoKCuy/F8Tq 5riijQRnTCNPO5Xe2cVFfgbASSy/wnUG5kQ/6KTA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 056/201] ip: Fix data-races around sysctl_ip_fwd_update_priority. Date: Wed, 27 Jul 2022 18:09:20 +0200 Message-Id: <20220727161029.244221383@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 7bf9e18d9a5e99e3c83482973557e9f047b051e7 ] While reading sysctl_ip_fwd_update_priority, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 432e05d32892 ("net: ipv4: Control SKB reprioritization after forward= ing") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 3 ++- net/ipv4/ip_forward.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/driver= s/net/ethernet/mellanox/mlxsw/spectrum_router.c index 6ef4ca8599ac..d17156c11ef8 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -9787,13 +9787,14 @@ static int mlxsw_sp_dscp_init(struct mlxsw_sp *mlxs= w_sp) static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) { struct net *net =3D mlxsw_sp_net(mlxsw_sp); - bool usp =3D net->ipv4.sysctl_ip_fwd_update_priority; char rgcr_pl[MLXSW_REG_RGCR_LEN]; u64 max_rifs; + bool usp; =20 if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_RIFS)) return -EIO; max_rifs =3D MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); + usp =3D READ_ONCE(net->ipv4.sysctl_ip_fwd_update_priority); =20 mlxsw_reg_rgcr_pack(rgcr_pl, true, true); mlxsw_reg_rgcr_max_router_interfaces_set(rgcr_pl, max_rifs); diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c index 00ec819f949b..29730edda220 100644 --- a/net/ipv4/ip_forward.c +++ b/net/ipv4/ip_forward.c @@ -151,7 +151,7 @@ int ip_forward(struct sk_buff *skb) !skb_sec_path(skb)) ip_rt_send_redirect(skb); =20 - if (net->ipv4.sysctl_ip_fwd_update_priority) + if (READ_ONCE(net->ipv4.sysctl_ip_fwd_update_priority)) skb->priority =3D rt_tos2priority(iph->tos); =20 return NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD, --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1ABC2C04A68 for ; Wed, 27 Jul 2022 17:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235956AbiG0RGA (ORCPT ); Wed, 27 Jul 2022 13:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241626AbiG0REm (ORCPT ); Wed, 27 Jul 2022 13:04:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15F5F5927A; Wed, 27 Jul 2022 09:39:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C90CEB821AC; Wed, 27 Jul 2022 16:39:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23130C433D6; Wed, 27 Jul 2022 16:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939962; bh=zabfjyerw6QbzUSnX0HwRyGRgOfy+xn5BL/F/fPADCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cfhwxoZJusBEgsOZEhtQrYogPMtxCxpFCQR0qww/YHi2ub910EhzjUAOskalGznzl xP+oGnt4nW+kDX1XTmy3zFih6urxdFLHKXAFHKAJFZgc+tXijFYuqAwdLb5oLXzXg9 gCqHYZIEfCPoCTD1+693dY0I5cilL8xyTJJWOPPM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 057/201] ip: Fix data-races around sysctl_ip_nonlocal_bind. Date: Wed, 27 Jul 2022 18:09:21 +0200 Message-Id: <20220727161029.275946881@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 289d3b21fb0bfc94c4e98f10635bba1824e5f83c ] While reading sysctl_ip_nonlocal_bind, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/inet_sock.h | 2 +- net/sctp/protocol.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index d81b7f85819e..defd77baf74a 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -373,7 +373,7 @@ static inline bool inet_get_convert_csum(struct sock *s= k) static inline bool inet_can_nonlocal_bind(struct net *net, struct inet_sock *inet) { - return net->ipv4.sysctl_ip_nonlocal_bind || + return READ_ONCE(net->ipv4.sysctl_ip_nonlocal_bind) || inet->freebind || inet->transparent; } =20 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index ec0f52567c16..9987decdead2 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -359,7 +359,7 @@ static int sctp_v4_available(union sctp_addr *addr, str= uct sctp_sock *sp) if (addr->v4.sin_addr.s_addr !=3D htonl(INADDR_ANY) && ret !=3D RTN_LOCAL && !sp->inet.freebind && - !net->ipv4.sysctl_ip_nonlocal_bind) + !READ_ONCE(net->ipv4.sysctl_ip_nonlocal_bind)) return 0; =20 if (ipv6_only_sock(sctp_opt2sk(sp))) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDAA8C04A68 for ; Wed, 27 Jul 2022 17:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235198AbiG0RGS (ORCPT ); Wed, 27 Jul 2022 13:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233068AbiG0REs (ORCPT ); Wed, 27 Jul 2022 13:04:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 183A75A2C1; Wed, 27 Jul 2022 09:39:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 94EC8B8200C; Wed, 27 Jul 2022 16:39:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA5B5C433D7; Wed, 27 Jul 2022 16:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939965; bh=dKxg26OoA3nUfbPZ8osDPGwHpVFBvL21XATFAJ+7CZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PtDQxORWSSkZhEZfwp1lj7e7vlPSk3Wa7gVjSB6sCCsHOnEonYXqEKEeUa0GtzGCz uPfz9xsrbA1ORKbX1dQmRQsokqiEHj1cQj6pTwLUxB4ZMDayqRAlnVvTOZ6uIFX7wg PUP6cFHEbknzDkTySkGL+PMK7zzefpek9byZpR9U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 058/201] ip: Fix a data-race around sysctl_ip_autobind_reuse. Date: Wed, 27 Jul 2022 18:09:22 +0200 Message-Id: <20220727161029.325785703@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 0db232765887d9807df8bcb7b6f29b2871539eab ] While reading sysctl_ip_autobind_reuse, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 4b01a9674231 ("tcp: bind(0) remove the SO_REUSEADDR restriction when= ephemeral ports are exhausted.") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_soc= k.c index 62a67fdc344c..d3bbb344bbe1 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -259,7 +259,7 @@ inet_csk_find_open_port(struct sock *sk, struct inet_bi= nd_bucket **tb_ret, int * goto other_half_scan; } =20 - if (net->ipv4.sysctl_ip_autobind_reuse && !relax) { + if (READ_ONCE(net->ipv4.sysctl_ip_autobind_reuse) && !relax) { /* We still have a chance to connect to different destinations */ relax =3D true; goto ports_exhausted; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB4C2C19F28 for ; Wed, 27 Jul 2022 17:06:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235532AbiG0RGZ (ORCPT ); Wed, 27 Jul 2022 13:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238438AbiG0RE7 (ORCPT ); Wed, 27 Jul 2022 13:04:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C036F7D4; Wed, 27 Jul 2022 09:39:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5E243B821AC; Wed, 27 Jul 2022 16:39:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A91FEC433D6; Wed, 27 Jul 2022 16:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939968; bh=zSYvAerbupXqigQKBiJfaZeSHJ9yktXMLHZL9mYt6fM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uh+GDDOZP2WsdjL3cpwyl7YraM2OPkcu4Bp7Ln/Lrzgomy/GW9c7TnqFIyrictXgc 9j4isNG9l+c4gk/2jSuB8eV+oupZR5Vz2UsOvYuKRbk14IkAh4PAvw+p8v4oA0C1IV qjtyucpIWg6i/BnbbOCZj2AYrhPSzZojRWcc9jPo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 059/201] ip: Fix a data-race around sysctl_fwmark_reflect. Date: Wed, 27 Jul 2022 18:09:23 +0200 Message-Id: <20220727161029.366572443@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 85d0b4dbd74b95cc492b1f4e34497d3f894f5d9a ] While reading sysctl_fwmark_reflect, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: e110861f8609 ("net: add a sysctl to reflect the fwmark on replies") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/ip.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/ip.h b/include/net/ip.h index c69dd114f367..a0ac57af82dc 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -379,7 +379,7 @@ void ipfrag_init(void); void ip_static_sysctl_init(void); =20 #define IP4_REPLY_MARK(net, mark) \ - ((net)->ipv4.sysctl_fwmark_reflect ? (mark) : 0) + (READ_ONCE((net)->ipv4.sysctl_fwmark_reflect) ? (mark) : 0) =20 static inline bool ip_is_fragment(const struct iphdr *iph) { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40BF5C04A68 for ; Wed, 27 Jul 2022 17:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241286AbiG0RGa (ORCPT ); Wed, 27 Jul 2022 13:06:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231635AbiG0RFB (ORCPT ); Wed, 27 Jul 2022 13:05:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6578C6F7DA; Wed, 27 Jul 2022 09:39:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7371B601D6; Wed, 27 Jul 2022 16:39:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F83FC433D6; Wed, 27 Jul 2022 16:39:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939970; bh=gtY/Rqy/GVzMeNvc/9VE/6vVIldRHE5s4g5Il/UMIFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fkf/7GRlLWWYOJlt9u5IOeSqzPVRMLFMC+nb430ZVlRtF+3F6po949kXl7uDbyemx bjpyjiQfXsU92YOMWCY4kgroLjtAEeYC4U2DxpL9aNxF9mvfBf3+mbOYmX1yVyI4hg I88zMlR92d5+eHXjR51n177XYAnlKGUGE2J2cPck= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 060/201] tcp/dccp: Fix a data-race around sysctl_tcp_fwmark_accept. Date: Wed, 27 Jul 2022 18:09:24 +0200 Message-Id: <20220727161029.407078794@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 1a0008f9df59451d0a17806c1ee1a19857032fa8 ] While reading sysctl_tcp_fwmark_accept, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 84f39b08d786 ("net: support marking accepting TCP sockets") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/inet_sock.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index defd77baf74a..33344d54ad65 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -107,7 +107,8 @@ static inline struct inet_request_sock *inet_rsk(const = struct request_sock *sk) =20 static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff = *skb) { - if (!sk->sk_mark && sock_net(sk)->ipv4.sysctl_tcp_fwmark_accept) + if (!sk->sk_mark && + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fwmark_accept)) return skb->mark; =20 return sk->sk_mark; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D59DFC04A68 for ; Wed, 27 Jul 2022 17:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241441AbiG0RGh (ORCPT ); Wed, 27 Jul 2022 13:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241346AbiG0RFe (ORCPT ); Wed, 27 Jul 2022 13:05:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FDF46F7F3; Wed, 27 Jul 2022 09:39:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CBEA4B8200C; Wed, 27 Jul 2022 16:39:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C28CC433C1; Wed, 27 Jul 2022 16:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939973; bh=+9ai9f+qaUfhsEY0EKFWl33A3SDMmS9FeTKWF298N/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PS8qGlJBrNVxLyBqsje1SPoV2Z7sZL71TzWgEIcXQF4DrXPBBdCZNuZDTg5LSRTkG bkmrSKxUToN/fpJR+LeeZWNBDUKxfrWG6OEqNRoZRyjgA566TCd13zO6MLzmJLq8jP mswYhTiJI/2X430f8jh7EZFKUwNsubgvigg0M/9A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 061/201] tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() Date: Wed, 27 Jul 2022 18:09:25 +0200 Message-Id: <20220727161029.439867505@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Eric Dumazet [ Upstream commit fdb5fd7f736ec7ae9fb36d2842ea6d9ebc4e7269 ] inet_request_bound_dev_if() reads sk->sk_bound_dev_if twice while listener socket is not locked. Another cpu could change this field under us. Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/inet_sock.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 33344d54ad65..e71827aa2dfb 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -117,14 +117,15 @@ static inline u32 inet_request_mark(const struct sock= *sk, struct sk_buff *skb) static inline int inet_request_bound_dev_if(const struct sock *sk, struct sk_buff *skb) { + int bound_dev_if =3D READ_ONCE(sk->sk_bound_dev_if); #ifdef CONFIG_NET_L3_MASTER_DEV struct net *net =3D sock_net(sk); =20 - if (!sk->sk_bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept) + if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept) return l3mdev_master_ifindex_by_index(net, skb->skb_iif); #endif =20 - return sk->sk_bound_dev_if; + return bound_dev_if; } =20 static inline int inet_sk_bound_l3mdev(const struct sock *sk) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 275ABC04A68 for ; Wed, 27 Jul 2022 17:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231165AbiG0RGj (ORCPT ); Wed, 27 Jul 2022 13:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241367AbiG0RFk (ORCPT ); Wed, 27 Jul 2022 13:05:40 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92FF36FA03; Wed, 27 Jul 2022 09:39:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id EF76CCE2311; Wed, 27 Jul 2022 16:39:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC56FC433C1; Wed, 27 Jul 2022 16:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939976; bh=674Qol5JQCIYt6EHb/3ISoH7vwQdVNwHkzMbSSZKRHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RUBFxeUTbz92cA0wDI8OjL4VGBByhw6QdI95L81Zs5ezVeFdmmipgpWXLjiu1Nnk7 gB5tx9K5C7aLQHpaHU/4QTE7rpTaPHto04Er8PnaT1N5oDdAO+mae+8gzsd+vz20qU oT640nqALKrFTyXe0Mh2n5Hn8tKbGkdKmMZTsbFw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 062/201] tcp: Fix data-races around sysctl_tcp_l3mdev_accept. Date: Wed, 27 Jul 2022 18:09:26 +0200 Message-Id: <20220727161029.487106444@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 08a75f10679470552a3a443f9aefd1399604d31d ] While reading sysctl_tcp_l3mdev_accept, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 6dd9a14e92e5 ("net: Allow accepted sockets to be bound to l3mdev dom= ain") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/inet_hashtables.h | 2 +- include/net/inet_sock.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 98e1ec1a14f0..749bb1e46087 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h @@ -207,7 +207,7 @@ static inline bool inet_sk_bound_dev_eq(struct net *net= , int bound_dev_if, int dif, int sdif) { #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) - return inet_bound_dev_eq(!!net->ipv4.sysctl_tcp_l3mdev_accept, + return inet_bound_dev_eq(!!READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept), bound_dev_if, dif, sdif); #else return inet_bound_dev_eq(true, bound_dev_if, dif, sdif); diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index e71827aa2dfb..c307a547d2cb 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -121,7 +121,7 @@ static inline int inet_request_bound_dev_if(const struc= t sock *sk, #ifdef CONFIG_NET_L3_MASTER_DEV struct net *net =3D sock_net(sk); =20 - if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept) + if (!bound_dev_if && READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept)) return l3mdev_master_ifindex_by_index(net, skb->skb_iif); #endif =20 @@ -133,7 +133,7 @@ static inline int inet_sk_bound_l3mdev(const struct soc= k *sk) #ifdef CONFIG_NET_L3_MASTER_DEV struct net *net =3D sock_net(sk); =20 - if (!net->ipv4.sysctl_tcp_l3mdev_accept) + if (!READ_ONCE(net->ipv4.sysctl_tcp_l3mdev_accept)) return l3mdev_master_ifindex_by_index(net, sk->sk_bound_dev_if); #endif --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65443C19F2B for ; Wed, 27 Jul 2022 17:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235465AbiG0RGr (ORCPT ); Wed, 27 Jul 2022 13:06:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241408AbiG0RFz (ORCPT ); Wed, 27 Jul 2022 13:05:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E556FA12; Wed, 27 Jul 2022 09:39:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5CE4CB821AC; Wed, 27 Jul 2022 16:39:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA178C433C1; Wed, 27 Jul 2022 16:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939979; bh=Aid4IAVsSs6Fbb/FVel6SEzfAF0WvHKpepDi6p/fNCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1qQqs0Q4SIZta5N6CCg0evgKadDOkMXB5omcpUqCZkmwDQnMwQTNSVA/z6kfIYFzx Mn1VzLg/LK3yaFXzpaIQBYdOEx27MfPaw9RgHMpN/KVLR6B+B+OaFCm8gr0VeS3yj1 Q9AKVDAbbIfc3GL/qwxJvkhHFRer9bJaT26Rlht8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 063/201] tcp: Fix data-races around sysctl_tcp_mtu_probing. Date: Wed, 27 Jul 2022 18:09:27 +0200 Message-Id: <20220727161029.536150791@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit f47d00e077e7d61baf69e46dde3210c886360207 ] While reading sysctl_tcp_mtu_probing, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 5d424d5a674f ("[TCP]: MTU probing") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 0bd5c334ccce..1acfd4298a01 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1765,7 +1765,7 @@ void tcp_mtup_init(struct sock *sk) struct inet_connection_sock *icsk =3D inet_csk(sk); struct net *net =3D sock_net(sk); =20 - icsk->icsk_mtup.enabled =3D net->ipv4.sysctl_tcp_mtu_probing > 1; + icsk->icsk_mtup.enabled =3D READ_ONCE(net->ipv4.sysctl_tcp_mtu_probing) >= 1; icsk->icsk_mtup.search_high =3D tp->rx_opt.mss_clamp + sizeof(struct tcph= dr) + icsk->icsk_af_ops->net_header_len; icsk->icsk_mtup.search_low =3D tcp_mss_to_mtu(sk, net->ipv4.sysctl_tcp_ba= se_mss); diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 20cf4a98c69d..98bb00e29e1e 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -163,7 +163,7 @@ static void tcp_mtu_probing(struct inet_connection_sock= *icsk, struct sock *sk) int mss; =20 /* Black hole detection */ - if (!net->ipv4.sysctl_tcp_mtu_probing) + if (!READ_ONCE(net->ipv4.sysctl_tcp_mtu_probing)) return; =20 if (!icsk->icsk_mtup.enabled) { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F1D1C04A68 for ; Wed, 27 Jul 2022 17:06:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241462AbiG0RGu (ORCPT ); Wed, 27 Jul 2022 13:06:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235096AbiG0RGO (ORCPT ); Wed, 27 Jul 2022 13:06:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42FE36FA1E; Wed, 27 Jul 2022 09:39:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 93779601D6; Wed, 27 Jul 2022 16:39:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 773A9C433D6; Wed, 27 Jul 2022 16:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939982; bh=vGECSNQYe+TmL3K/N9ppIzMcy/1IbI0ocNu9D1LRQFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iYhX3fAy7QS73g7dZRE6wSKPlXOfnqNUxqDEf5tsh9ynQqhgzpUcs3JUO2PVrYoN4 3uUhqsth9jgzd9ii4XtC7qfq7p0vIBgcIGNKFutMs7/nmsQDJ9OJEjWg8TypGmT6vV MWibUqyP0tq6VoJU49QpjEI/Wpuc03xGOKpkFDMk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 064/201] tcp: Fix data-races around sysctl_tcp_base_mss. Date: Wed, 27 Jul 2022 18:09:28 +0200 Message-Id: <20220727161029.569159430@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 88d78bc097cd8ebc6541e93316c9d9bf651b13e8 ] While reading sysctl_tcp_base_mss, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 5d424d5a674f ("[TCP]: MTU probing") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 1acfd4298a01..53277a9a2300 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1768,7 +1768,7 @@ void tcp_mtup_init(struct sock *sk) icsk->icsk_mtup.enabled =3D READ_ONCE(net->ipv4.sysctl_tcp_mtu_probing) >= 1; icsk->icsk_mtup.search_high =3D tp->rx_opt.mss_clamp + sizeof(struct tcph= dr) + icsk->icsk_af_ops->net_header_len; - icsk->icsk_mtup.search_low =3D tcp_mss_to_mtu(sk, net->ipv4.sysctl_tcp_ba= se_mss); + icsk->icsk_mtup.search_low =3D tcp_mss_to_mtu(sk, READ_ONCE(net->ipv4.sys= ctl_tcp_base_mss)); icsk->icsk_mtup.probe_size =3D 0; if (icsk->icsk_mtup.enabled) icsk->icsk_mtup.probe_timestamp =3D tcp_jiffies32; diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 98bb00e29e1e..04063c7e33ba 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -171,7 +171,7 @@ static void tcp_mtu_probing(struct inet_connection_sock= *icsk, struct sock *sk) icsk->icsk_mtup.probe_timestamp =3D tcp_jiffies32; } else { mss =3D tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1; - mss =3D min(net->ipv4.sysctl_tcp_base_mss, mss); + mss =3D min(READ_ONCE(net->ipv4.sysctl_tcp_base_mss), mss); mss =3D max(mss, net->ipv4.sysctl_tcp_mtu_probe_floor); mss =3D max(mss, net->ipv4.sysctl_tcp_min_snd_mss); icsk->icsk_mtup.search_low =3D tcp_mss_to_mtu(sk, mss); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC1A4C04A68 for ; Wed, 27 Jul 2022 17:07:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241470AbiG0RHJ (ORCPT ); Wed, 27 Jul 2022 13:07:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235916AbiG0RGe (ORCPT ); Wed, 27 Jul 2022 13:06:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A9DA5A2D5; Wed, 27 Jul 2022 09:39:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1750B601D6; Wed, 27 Jul 2022 16:39:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24C7CC433D7; Wed, 27 Jul 2022 16:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939987; bh=TATulhQ6PDV7T1GG9tmYc92+FXrrd4JzmDN+m3hLabw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xWYgKCfLFwq1FB2j7QmwGQUSD+r1VTWyaiS7N4TzzphsyM5kcXE6iL33NKKYemnda NFZKbJTTU+HWZvcg+luTKU8b1jO5UH379jlEVxCRndOBQ8RbRvTxjUjhO40NZCtRp5 irRZxqrBn3eayapk0CmQajbdNcAB2rFXZis2u3kg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 065/201] tcp: Fix data-races around sysctl_tcp_min_snd_mss. Date: Wed, 27 Jul 2022 18:09:29 +0200 Message-Id: <20220727161029.616497689@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 78eb166cdefcc3221c8c7c1e2d514e91a2eb5014 ] While reading sysctl_tcp_min_snd_mss, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 5f3e2bf008c2 ("tcp: add tcp_min_snd_mss sysctl") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_output.c | 3 ++- net/ipv4/tcp_timer.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 53277a9a2300..b4a8a5b9350f 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1722,7 +1722,8 @@ static inline int __tcp_mtu_to_mss(struct sock *sk, i= nt pmtu) mss_now -=3D icsk->icsk_ext_hdr_len; =20 /* Then reserve room for full set of TCP options and 8 bytes of data */ - mss_now =3D max(mss_now, sock_net(sk)->ipv4.sysctl_tcp_min_snd_mss); + mss_now =3D max(mss_now, + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_snd_mss)); return mss_now; } =20 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 04063c7e33ba..39107bb730b0 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -173,7 +173,7 @@ static void tcp_mtu_probing(struct inet_connection_sock= *icsk, struct sock *sk) mss =3D tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1; mss =3D min(READ_ONCE(net->ipv4.sysctl_tcp_base_mss), mss); mss =3D max(mss, net->ipv4.sysctl_tcp_mtu_probe_floor); - mss =3D max(mss, net->ipv4.sysctl_tcp_min_snd_mss); + mss =3D max(mss, READ_ONCE(net->ipv4.sysctl_tcp_min_snd_mss)); icsk->icsk_mtup.search_low =3D tcp_mss_to_mtu(sk, mss); } tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14A37C19F28 for ; Wed, 27 Jul 2022 17:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241472AbiG0RHQ (ORCPT ); Wed, 27 Jul 2022 13:07:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241403AbiG0RGk (ORCPT ); Wed, 27 Jul 2022 13:06:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50E7070E65; Wed, 27 Jul 2022 09:39:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 98E2AB821AC; Wed, 27 Jul 2022 16:39:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEEF5C433C1; Wed, 27 Jul 2022 16:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939990; bh=5aJJgCNUDtk8qpGPzgPquBcPXcbJrkVDOJVjGB4GzcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eYl0sz1saERghcwJEfRxlv5okcSbgQa3iuLpWG4n1c8am2uce4eDcP3hJGIK5doh/ smQsG9eI4JTHLIckmF0I/Vgx0Oe8ZwFNj5COSTMIYEl6TZXdNH+N6UYmR+HCWtxI2J BgzY1SzHJOmEtc8AJgj4V278xGUEbnEc7N9cjCs4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 066/201] tcp: Fix a data-race around sysctl_tcp_mtu_probe_floor. Date: Wed, 27 Jul 2022 18:09:30 +0200 Message-Id: <20220727161029.656239525@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 8e92d4423615a5257d0d871fc067aa561f597deb ] While reading sysctl_tcp_mtu_probe_floor, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: c04b79b6cfd7 ("tcp: add new tcp_mtu_probe_floor sysctl") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 39107bb730b0..4f3b9ab222b6 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -172,7 +172,7 @@ static void tcp_mtu_probing(struct inet_connection_sock= *icsk, struct sock *sk) } else { mss =3D tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1; mss =3D min(READ_ONCE(net->ipv4.sysctl_tcp_base_mss), mss); - mss =3D max(mss, net->ipv4.sysctl_tcp_mtu_probe_floor); + mss =3D max(mss, READ_ONCE(net->ipv4.sysctl_tcp_mtu_probe_floor)); mss =3D max(mss, READ_ONCE(net->ipv4.sysctl_tcp_min_snd_mss)); icsk->icsk_mtup.search_low =3D tcp_mss_to_mtu(sk, mss); } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA211C04A68 for ; Wed, 27 Jul 2022 17:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235604AbiG0RHU (ORCPT ); Wed, 27 Jul 2022 13:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230274AbiG0RGs (ORCPT ); Wed, 27 Jul 2022 13:06:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A467270E78; Wed, 27 Jul 2022 09:39:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 458CAB821D4; Wed, 27 Jul 2022 16:39:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5B09C433D7; Wed, 27 Jul 2022 16:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939993; bh=dfRlc9rDIq6AaZtwh3GAvt2adWv8tRCRgYIoRf8jL2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KgsGxDKsdtAFgx9wbp05A1s920C9WqMHonuRGFRgobYglPQaMgaLd4ULk/1roANcC E4/AD1+oLcZEa8H9drMKW/s4WdDIM/2pDJY5ZdiLtc7kvLp5qWrrY3Nkpb3iK/S6Pn LQydcZUWDkumbthUfYwg0rqb6poTtP9QdgzmUw9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 067/201] tcp: Fix a data-race around sysctl_tcp_probe_threshold. Date: Wed, 27 Jul 2022 18:09:31 +0200 Message-Id: <20220727161029.703695453@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 92c0aa4175474483d6cf373314343d4e624e882a ] While reading sysctl_tcp_probe_threshold, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 6b58e0a5f32d ("ipv4: Use binary search to choose tcp PMTU probe_size= ") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index b4a8a5b9350f..0ba48c43c06f 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2363,7 +2363,7 @@ static int tcp_mtu_probe(struct sock *sk) * probing process by not resetting search range to its orignal. */ if (probe_size > tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_high) || - interval < net->ipv4.sysctl_tcp_probe_threshold) { + interval < READ_ONCE(net->ipv4.sysctl_tcp_probe_threshold)) { /* Check whether enough time has elaplased for * another round of probing. */ --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B06AC04A68 for ; Wed, 27 Jul 2022 17:07:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241187AbiG0RH0 (ORCPT ); Wed, 27 Jul 2022 13:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238204AbiG0RGt (ORCPT ); Wed, 27 Jul 2022 13:06:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E6A71703; Wed, 27 Jul 2022 09:39:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 58942601C0; Wed, 27 Jul 2022 16:39:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 642D1C433D6; Wed, 27 Jul 2022 16:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939995; bh=RGzRJ+I7eDB9UWnPcmHTSTSTB9q06ObmvjfqfDSoMsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tDgCmqtVChH5lMzjd1rY5gr2kgYArsf5K/rC70UNUfzGtcvSEGt112QmhLD9ylwpk p460Sylg/ljAPBm/Oeb32TQ06QoEctzwjN1/d8c9+MjvrZYGKHJIGzsGLNLy5u0jrm pSGrGMSBQO0KvjUd+s+OjX752lQEXU+xhyVCOKls= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 068/201] tcp: Fix a data-race around sysctl_tcp_probe_interval. Date: Wed, 27 Jul 2022 18:09:32 +0200 Message-Id: <20220727161029.748203468@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 2a85388f1d94a9f8b5a529118a2c5eaa0520d85c ] While reading sysctl_tcp_probe_interval, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 05cbc0db03e8 ("ipv4: Create probe timer for tcp PMTU as per RFC4821") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 0ba48c43c06f..3fa2bfbc250d 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2281,7 +2281,7 @@ static inline void tcp_mtu_check_reprobe(struct sock = *sk) u32 interval; s32 delta; =20 - interval =3D net->ipv4.sysctl_tcp_probe_interval; + interval =3D READ_ONCE(net->ipv4.sysctl_tcp_probe_interval); delta =3D tcp_jiffies32 - icsk->icsk_mtup.probe_timestamp; if (unlikely(delta >=3D interval * HZ)) { int mss =3D tcp_current_mss(sk); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96385C19F28 for ; Wed, 27 Jul 2022 17:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241542AbiG0RNN (ORCPT ); Wed, 27 Jul 2022 13:13:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237315AbiG0RM1 (ORCPT ); Wed, 27 Jul 2022 13:12:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5E0B75395; Wed, 27 Jul 2022 09:41:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 69F61B821BA; Wed, 27 Jul 2022 16:41:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C97A5C433C1; Wed, 27 Jul 2022 16:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940116; bh=MqCc0ciLdhTySaAZJ8iBq1nKYb0UgeE4CQTs/ipDFI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OVxY2w0QE3y077r/LtPDwLFSSt6aYwUwKEOXadn18bh0kpKvgQki5ljwyS87EPdIN aJ3QKsNyEs7PqfuRtUha0ag7H4Go2EaomEPqIM+NBa81lqxhK5NY0EqTOhBqs1uVax fHuEGAp5aMH2GrO0TfobY2CcUf656lgN5h22vXJ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Biao Huang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 069/201] net: stmmac: fix pm runtime issue in stmmac_dvr_remove() Date: Wed, 27 Jul 2022 18:09:33 +0200 Message-Id: <20220727161029.797686433@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Biao Huang [ Upstream commit 0d9a15913b871e03fdd3b3d90a2e665fb22f9bcf ] If netif is running when stmmac_dvr_remove is invoked, the unregister_netdev will call ndo_stop(stmmac_release) and vlan_kill_rx_filter(stmmac_vlan_rx_kill_vid). Currently, stmmac_dvr_remove() will disable pm runtime before unregister_netdev. When stmmac_vlan_rx_kill_vid is invoked, pm_runtime_resume_and_get in it returns EACCESS error number, and reports: dwmac-mediatek 11021000.ethernet eth0: stmmac_dvr_remove: removing driver dwmac-mediatek 11021000.ethernet eth0: FPE workqueue stop dwmac-mediatek 11021000.ethernet eth0: failed to kill vid 0081/0 Move the pm_runtime_disable to the end of stmmac_dvr_remove to fix this issue. Fixes: 6449520391dfc ("net: stmmac: properly handle with runtime pm in stmm= ac_dvr_remove()") Signed-off-by: Biao Huang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 9c1e19ea6fcd..95e1307cfda2 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -7279,8 +7279,6 @@ int stmmac_dvr_remove(struct device *dev) netdev_info(priv->dev, "%s: removing driver", __func__); =20 pm_runtime_get_sync(dev); - pm_runtime_disable(dev); - pm_runtime_put_noidle(dev); =20 stmmac_stop_all_dma(priv); stmmac_mac_set(priv, priv->ioaddr, false); @@ -7307,6 +7305,9 @@ int stmmac_dvr_remove(struct device *dev) mutex_destroy(&priv->lock); bitmap_free(priv->af_xdp_zc_qps); =20 + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + return 0; } EXPORT_SYMBOL_GPL(stmmac_dvr_remove); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E5B6C04A68 for ; Wed, 27 Jul 2022 17:08:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241446AbiG0RIf (ORCPT ); Wed, 27 Jul 2022 13:08:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237673AbiG0RHw (ORCPT ); Wed, 27 Jul 2022 13:07:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23DA04E609; Wed, 27 Jul 2022 09:40:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0ACC860D3C; Wed, 27 Jul 2022 16:40:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 123F5C433D6; Wed, 27 Jul 2022 16:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940018; bh=Xd3Ruhz90sS4nMtEn5T2f4REu/L1TQxJ8JzAp/2+XaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iH1BiLMska++rh+V1huD+UmhUHUXo7OzHNHksomOg+g+5Ve4jYx/3G8QbQgt7Zfck sayczo26M7wDcL6jex+mdfO45jU4+f9WZ9KwCyjRzXqRhUVoUnMOnJdqdn5/0r/vgQ 0B65FmZxRSEbZOl1PCV7Rjo8gBwlgqlIr5CklqbY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Biao Huang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 070/201] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Date: Wed, 27 Jul 2022 18:09:34 +0200 Message-Id: <20220727161029.846082694@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Biao Huang [ Upstream commit f4c7d8948e866918d61493264dbbd67e45ef2bda ] Current stmmac driver will prepare/enable ptp_ref clock in stmmac_init_tstamp_counter(). The stmmac_pltfr_noirq_suspend will disable it once in suspend flow. But in resume flow, stmmac_pltfr_noirq_resume --> stmmac_init_tstamp_counter stmmac_resume --> stmmac_hw_setup --> stmmac_init_ptp --> stmmac_init_tsta= mp_counter ptp_ref clock reference counter increases twice, which leads to unbalance ptp clock when resume back. Move ptp_ref clock prepare/enable out of stmmac_init_tstamp_counter to fix = it. Fixes: 0735e639f129d ("net: stmmac: skip only stmmac_ptp_register when resu= me from suspend") Signed-off-by: Biao Huang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 17 ++++++++--------- .../ethernet/stmicro/stmmac/stmmac_platform.c | 8 +++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 95e1307cfda2..b4f83c865568 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -844,19 +844,10 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *pr= iv, u32 systime_flags) struct timespec64 now; u32 sec_inc =3D 0; u64 temp =3D 0; - int ret; =20 if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) return -EOPNOTSUPP; =20 - ret =3D clk_prepare_enable(priv->plat->clk_ptp_ref); - if (ret < 0) { - netdev_warn(priv->dev, - "failed to enable PTP reference clock: %pe\n", - ERR_PTR(ret)); - return ret; - } - stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags); priv->systime_flags =3D systime_flags; =20 @@ -3325,6 +3316,14 @@ static int stmmac_hw_setup(struct net_device *dev, b= ool ptp_register) =20 stmmac_mmc_setup(priv); =20 + if (ptp_register) { + ret =3D clk_prepare_enable(priv->plat->clk_ptp_ref); + if (ret < 0) + netdev_warn(priv->dev, + "failed to enable PTP reference clock: %pe\n", + ERR_PTR(ret)); + } + ret =3D stmmac_init_ptp(priv); if (ret =3D=3D -EOPNOTSUPP) netdev_warn(priv->dev, "PTP not supported by HW\n"); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/driver= s/net/ethernet/stmicro/stmmac/stmmac_platform.c index 11e1055e8260..9f5cac4000da 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -815,7 +815,13 @@ static int __maybe_unused stmmac_pltfr_noirq_resume(st= ruct device *dev) if (ret) return ret; =20 - stmmac_init_tstamp_counter(priv, priv->systime_flags); + ret =3D clk_prepare_enable(priv->plat->clk_ptp_ref); + if (ret < 0) { + netdev_warn(priv->dev, + "failed to enable PTP reference clock: %pe\n", + ERR_PTR(ret)); + return ret; + } } =20 return 0; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51449C04A68 for ; Wed, 27 Jul 2022 17:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241231AbiG0RK3 (ORCPT ); Wed, 27 Jul 2022 13:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241601AbiG0RJS (ORCPT ); Wed, 27 Jul 2022 13:09:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D1850044; Wed, 27 Jul 2022 09:40:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7BC7960DDB; Wed, 27 Jul 2022 16:40:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82859C433D6; Wed, 27 Jul 2022 16:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940053; bh=nO9vN98lzG+8FMhdNslgASCIMtubLetqdATFaeG8C6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pxi2Kg1zAOhs45d6rLvGHU12cwiKum404hulsITdtAqewZtItxPwuG4OjhaRGg5rJ WWqRCXal/ZsTOk4HqjreEOqVM4bZ+O0XPVtLjT3uYPBGVpomkC8zAh3QHTH0wMjw0Y t0yFxnFM3PrQjU4aIvXAn0WYBIVG/PDZJ4nAwT6I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Trimarchi , Dario Binacchi , Sascha Hauer , Miquel Raynal , Sasha Levin Subject: [PATCH 5.15 071/201] mtd: rawnand: gpmi: validate controller clock rate Date: Wed, 27 Jul 2022 18:09:35 +0200 Message-Id: <20220727161029.886728305@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dario Binacchi [ Upstream commit 15e27d197a7ea69b4643791ca2f8467fdd998359 ] What to do when the real rate of the gpmi clock is not equal to the required one? The solutions proposed in [1] did not lead to a conclusion on how to validate the clock rate, so, inspired by the document [2], I consider the rate correct only if not lower or equal to the rate of the previous edo mode. In fact, in chapter 4.16.2 (NV-DDR) of the document [2], it is written that "If the host selects timing mode n, then its clock period shall be faster than the clock period of timing mode n-1 and slower than or equal to the clock period of timing mode n.". I thought that it could therefore also be used in this case, without therefore having to define the valid rate ranges empirically. For example, suppose that gpmi_nfc_compute_timings() is called to set edo mode 5 (100MHz) but the rate returned by clk_round_rate() is 80MHz (edo mode 4). In this case gpmi_nfc_compute_timings() will return error, and will be called again to set edo mode 4, which this time will be successful. [1] https://lore.kernel.org/r/20210702065350.209646-5-ebiggers@kernel.org [2] http://www.onfi.org/-/media/client/onfi/specs/onfi_3_0_gold.pdf?la=3Den Co-developed-by: Michael Trimarchi Signed-off-by: Michael Trimarchi Signed-off-by: Dario Binacchi Tested-by: Sascha Hauer Reviewed-by: Sascha Hauer Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20220118095434.35081-4-dario.binacc= hi@amarulasolutions.com Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/= raw/gpmi-nand/gpmi-nand.c index b72b387c08ef..62f4988c2a5f 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -644,8 +644,8 @@ static int bch_set_geometry(struct gpmi_nand_data *this) * RDN_DELAY =3D ----------------------- {3} * RP */ -static void gpmi_nfc_compute_timings(struct gpmi_nand_data *this, - const struct nand_sdr_timings *sdr) +static int gpmi_nfc_compute_timings(struct gpmi_nand_data *this, + const struct nand_sdr_timings *sdr) { struct gpmi_nfc_hardware_timing *hw =3D &this->hw; struct resources *r =3D &this->resources; @@ -657,23 +657,33 @@ static void gpmi_nfc_compute_timings(struct gpmi_nand= _data *this, int sample_delay_ps, sample_delay_factor; u16 busy_timeout_cycles; u8 wrn_dly_sel; + unsigned long clk_rate, min_rate; =20 if (sdr->tRC_min >=3D 30000) { /* ONFI non-EDO modes [0-3] */ hw->clk_rate =3D 22000000; + min_rate =3D 0; wrn_dly_sel =3D BV_GPMI_CTRL1_WRN_DLY_SEL_4_TO_8NS; } else if (sdr->tRC_min >=3D 25000) { /* ONFI EDO mode 4 */ hw->clk_rate =3D 80000000; + min_rate =3D 22000000; wrn_dly_sel =3D BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY; } else { /* ONFI EDO mode 5 */ hw->clk_rate =3D 100000000; + min_rate =3D 80000000; wrn_dly_sel =3D BV_GPMI_CTRL1_WRN_DLY_SEL_NO_DELAY; } =20 - hw->clk_rate =3D clk_round_rate(r->clock[0], hw->clk_rate); + clk_rate =3D clk_round_rate(r->clock[0], hw->clk_rate); + if (clk_rate <=3D min_rate) { + dev_err(this->dev, "clock setting: expected %ld, got %ld\n", + hw->clk_rate, clk_rate); + return -ENOTSUPP; + } =20 + hw->clk_rate =3D clk_rate; /* SDR core timings are given in picoseconds */ period_ps =3D div_u64((u64)NSEC_PER_SEC * 1000, hw->clk_rate); =20 @@ -714,6 +724,7 @@ static void gpmi_nfc_compute_timings(struct gpmi_nand_d= ata *this, hw->ctrl1n |=3D BF_GPMI_CTRL1_RDN_DELAY(sample_delay_factor) | BM_GPMI_CTRL1_DLL_ENABLE | (use_half_period ? BM_GPMI_CTRL1_HALF_PERIOD : 0); + return 0; } =20 static int gpmi_nfc_apply_timings(struct gpmi_nand_data *this) @@ -769,6 +780,7 @@ static int gpmi_setup_interface(struct nand_chip *chip,= int chipnr, { struct gpmi_nand_data *this =3D nand_get_controller_data(chip); const struct nand_sdr_timings *sdr; + int ret; =20 /* Retrieve required NAND timings */ sdr =3D nand_get_sdr_timings(conf); @@ -784,7 +796,9 @@ static int gpmi_setup_interface(struct nand_chip *chip,= int chipnr, return 0; =20 /* Do the actual derivation of the controller timings */ - gpmi_nfc_compute_timings(this, sdr); + ret =3D gpmi_nfc_compute_timings(this, sdr); + if (ret) + return ret; =20 this->hw.must_apply_timings =3D true; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74698C04A68 for ; Wed, 27 Jul 2022 17:11:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231326AbiG0RLo (ORCPT ); Wed, 27 Jul 2022 13:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241545AbiG0RKf (ORCPT ); Wed, 27 Jul 2022 13:10:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FFF55B05D; Wed, 27 Jul 2022 09:41:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CC061601C0; Wed, 27 Jul 2022 16:41:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D64CBC433C1; Wed, 27 Jul 2022 16:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940085; bh=nd8DyLqag7jTxEYrgZmLlRg8gkbWYfUvoQZaK/Chyxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tWty93t8hkawQJiMM2K8hJCr3kGXIDQOg6M/sRzuH8MEJNg573KTE+lFKlRha1/Qz rqB3QzlyUmDeiyedc5WvU3HIhPEZD4y/JXoQTLwQ2iHWhCuEd7GnKz57s7ecC6iMPK 1vdt0I+Nh4PgaQr6FID0jNnDF/bx1whRAHaauaOA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sascha Hauer , Han Xu , =?UTF-8?q?Tomasz=20Mo=C5=84?= , Richard Weinberger , Sasha Levin Subject: [PATCH 5.15 072/201] mtd: rawnand: gpmi: Set WAIT_FOR_READY timeout based on program/erase times Date: Wed, 27 Jul 2022 18:09:36 +0200 Message-Id: <20220727161029.918070306@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sascha Hauer [ Upstream commit 0fddf9ad06fd9f439f137139861556671673e31c ] 06781a5026350 Fixes the calculation of the DEVICE_BUSY_TIMEOUT register value from busy_timeout_cycles. busy_timeout_cycles is calculated wrong though: It is calculated based on the maximum page read time, but the timeout is also used for page write and block erase operations which require orders of magnitude bigger timeouts. Fix this by calculating busy_timeout_cycles from the maximum of tBERS_max and tPROG_max. This is for now the easiest and most obvious way to fix the driver. There's room for improvements though: The NAND_OP_WAITRDY_INSTR tells us the desired timeout for the current operation, so we could program the timeout dynamically for each operation instead of setting a fixed timeout. Also we could wire up the interrupt handler to actually detect and forward timeouts occurred when waiting for the chip being ready. As a sidenote I verified that the change in 06781a5026350 is really correct. I wired up the interrupt handler in my tree and measured the time between starting the operation and the timeout interrupt handler coming in. The time increases 41us with each step in the timeout register which corresponds to 4096 clock cycles with the 99MHz clock that I have. Fixes: 06781a5026350 ("mtd: rawnand: gpmi: Fix setting busy timeout setting= ") Fixes: b1206122069aa ("mtd: rawniand: gpmi: use core timings instead of an = empirical derivation") Cc: stable@vger.kernel.org Signed-off-by: Sascha Hauer Acked-by: Han Xu Tested-by: Tomasz Mo=C5=84 Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/= raw/gpmi-nand/gpmi-nand.c index 62f4988c2a5f..aef722dfdef5 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -655,9 +655,10 @@ static int gpmi_nfc_compute_timings(struct gpmi_nand_d= ata *this, unsigned int tRP_ps; bool use_half_period; int sample_delay_ps, sample_delay_factor; - u16 busy_timeout_cycles; + unsigned int busy_timeout_cycles; u8 wrn_dly_sel; unsigned long clk_rate, min_rate; + u64 busy_timeout_ps; =20 if (sdr->tRC_min >=3D 30000) { /* ONFI non-EDO modes [0-3] */ @@ -690,7 +691,8 @@ static int gpmi_nfc_compute_timings(struct gpmi_nand_da= ta *this, addr_setup_cycles =3D TO_CYCLES(sdr->tALS_min, period_ps); data_setup_cycles =3D TO_CYCLES(sdr->tDS_min, period_ps); data_hold_cycles =3D TO_CYCLES(sdr->tDH_min, period_ps); - busy_timeout_cycles =3D TO_CYCLES(sdr->tWB_max + sdr->tR_max, period_ps); + busy_timeout_ps =3D max(sdr->tBERS_max, sdr->tPROG_max); + busy_timeout_cycles =3D TO_CYCLES(busy_timeout_ps, period_ps); =20 hw->timing0 =3D BF_GPMI_TIMING0_ADDRESS_SETUP(addr_setup_cycles) | BF_GPMI_TIMING0_DATA_HOLD(data_hold_cycles) | --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F6FCC19F2B for ; Wed, 27 Jul 2022 17:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238430AbiG0RMo (ORCPT ); Wed, 27 Jul 2022 13:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235944AbiG0RMD (ORCPT ); Wed, 27 Jul 2022 13:12:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 584AB51429; Wed, 27 Jul 2022 09:41:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6C8B2B821D9; Wed, 27 Jul 2022 16:41:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE040C433C1; Wed, 27 Jul 2022 16:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940099; bh=oHaWvLUlNE/w6zzvKBBtSl3owPSHfyWK62wsrNEUzMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iMGln1XY9TW2QNCCrxXiV1W3A0+aXxjaqtZiV5JQpLPYddh5rpITDZox91mpAJ//J NGOH7WCNtTzRmjK6idsMUV9MtTHkg7QSB4IOlSgjqWlF34nMs1NoEn001zHmll/1jk /QiTGATr5KrSAnRqo6F5T5MWPwi2GbK8Jql9A0o8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liang He , Vladimir Oltean , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 073/201] net: dsa: microchip: ksz_common: Fix refcount leak bug Date: Wed, 27 Jul 2022 18:09:37 +0200 Message-Id: <20220727161029.958988535@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Liang He [ Upstream commit a14bd7475452c51835dd5a0cee4c8fa48dd0b539 ] In ksz_switch_register(), we should call of_node_put() for the reference returned by of_get_child_by_name() which has increased the refcount. Fixes: 912aae27c6af ("net: dsa: microchip: really look for phy-mode in port= nodes") Signed-off-by: Liang He Reviewed-by: Vladimir Oltean Link: https://lore.kernel.org/r/20220714153138.375919-1-windhl@126.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/dsa/microchip/ksz_common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 7c2968a639eb..4c4e6990c0ae 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -414,18 +414,21 @@ int ksz_switch_register(struct ksz_device *dev, ports =3D of_get_child_by_name(dev->dev->of_node, "ethernet-ports"); if (!ports) ports =3D of_get_child_by_name(dev->dev->of_node, "ports"); - if (ports) + if (ports) { for_each_available_child_of_node(ports, port) { if (of_property_read_u32(port, "reg", &port_num)) continue; if (!(dev->port_mask & BIT(port_num))) { of_node_put(port); + of_node_put(ports); return -EINVAL; } of_get_phy_mode(port, &dev->ports[port_num].interface); } + of_node_put(ports); + } dev->synclko_125 =3D of_property_read_bool(dev->dev->of_node, "microchip,synclko-125"); } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38C79C04A68 for ; Wed, 27 Jul 2022 17:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbiG0RMt (ORCPT ); Wed, 27 Jul 2022 13:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236728AbiG0RME (ORCPT ); Wed, 27 Jul 2022 13:12:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 736345142C; Wed, 27 Jul 2022 09:41:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 19EECB821C6; Wed, 27 Jul 2022 16:41:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6920EC433C1; Wed, 27 Jul 2022 16:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940101; bh=bd5gYaHzduW2SH4yfuMVkYTJ4C4Z4l9hyNNt7ZVn/HA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KT+Iko7nbcQO7DxwWDWJ2k2K1eZ7Swmapb8vsoO3NKpwDu6FMjadhyTRYomETOrcr v0rgeS++FFoWfl5cey3RTH8EmJr7PvnAaBTxXm48kGkSRKGYtNz8/fcfvn1N2RgUvW nhpGwIMwGbg/NM2LL3y2NfACDyM3oCZ9aXmV6dZ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 074/201] net: skb: introduce kfree_skb_reason() Date: Wed, 27 Jul 2022 18:09:38 +0200 Message-Id: <20220727161029.996916473@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit c504e5c2f9648a1e5c2be01e8c3f59d394192bd3 ] Introduce the interface kfree_skb_reason(), which is able to pass the reason why the skb is dropped to 'kfree_skb' tracepoint. Add the 'reason' field to 'trace_kfree_skb', therefor user can get more detail information about abnormal skb with 'drop_monitor' or eBPF. All drop reasons are defined in the enum 'skb_drop_reason', and they will be print as string in 'kfree_skb' tracepoint in format of 'reason: XXX'. ( Maybe the reasons should be defined in a uapi header file, so that user space can use them? ) Signed-off-by: Menglong Dong Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 23 ++++++++++++++++++++++- include/trace/events/skb.h | 36 +++++++++++++++++++++++++++++------- net/core/dev.c | 3 ++- net/core/drop_monitor.c | 10 +++++++--- net/core/skbuff.c | 12 +++++++----- 5 files changed, 67 insertions(+), 17 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index e213acaa91ec..029bc228bcf9 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -304,6 +304,17 @@ struct sk_buff_head { =20 struct sk_buff; =20 +/* The reason of skb drop, which is used in kfree_skb_reason(). + * en...maybe they should be splited by group? + * + * Each item here should also be in 'TRACE_SKB_DROP_REASON', which is + * used to translate the reason to string. + */ +enum skb_drop_reason { + SKB_DROP_REASON_NOT_SPECIFIED, + SKB_DROP_REASON_MAX, +}; + /* To allow 64K frame to be packed as single skb without frag_list we * require 64K/PAGE_SIZE pages plus 1 additional page to allow for * buffers which do not start on a page boundary. @@ -1074,8 +1085,18 @@ static inline bool skb_unref(struct sk_buff *skb) return true; } =20 +void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason); + +/** + * kfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason + * @skb: buffer to free + */ +static inline void kfree_skb(struct sk_buff *skb) +{ + kfree_skb_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED); +} + void skb_release_head_state(struct sk_buff *skb); -void kfree_skb(struct sk_buff *skb); void kfree_skb_list(struct sk_buff *segs); void skb_dump(const char *level, const struct sk_buff *skb, bool full_pkt); void skb_tx_error(struct sk_buff *skb); diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 9e92f22eb086..294c61bbe44b 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -9,29 +9,51 @@ #include #include =20 +#define TRACE_SKB_DROP_REASON \ + EM(SKB_DROP_REASON_NOT_SPECIFIED, NOT_SPECIFIED) \ + EMe(SKB_DROP_REASON_MAX, MAX) + +#undef EM +#undef EMe + +#define EM(a, b) TRACE_DEFINE_ENUM(a); +#define EMe(a, b) TRACE_DEFINE_ENUM(a); + +TRACE_SKB_DROP_REASON + +#undef EM +#undef EMe +#define EM(a, b) { a, #b }, +#define EMe(a, b) { a, #b } + /* * Tracepoint for free an sk_buff: */ TRACE_EVENT(kfree_skb, =20 - TP_PROTO(struct sk_buff *skb, void *location), + TP_PROTO(struct sk_buff *skb, void *location, + enum skb_drop_reason reason), =20 - TP_ARGS(skb, location), + TP_ARGS(skb, location, reason), =20 TP_STRUCT__entry( - __field( void *, skbaddr ) - __field( void *, location ) - __field( unsigned short, protocol ) + __field(void *, skbaddr) + __field(void *, location) + __field(unsigned short, protocol) + __field(enum skb_drop_reason, reason) ), =20 TP_fast_assign( __entry->skbaddr =3D skb; __entry->location =3D location; __entry->protocol =3D ntohs(skb->protocol); + __entry->reason =3D reason; ), =20 - TP_printk("skbaddr=3D%p protocol=3D%u location=3D%p", - __entry->skbaddr, __entry->protocol, __entry->location) + TP_printk("skbaddr=3D%p protocol=3D%u location=3D%p reason: %s", + __entry->skbaddr, __entry->protocol, __entry->location, + __print_symbolic(__entry->reason, + TRACE_SKB_DROP_REASON)) ); =20 TRACE_EVENT(consume_skb, diff --git a/net/core/dev.c b/net/core/dev.c index 6111506a4105..12b1811cb488 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5005,7 +5005,8 @@ static __latent_entropy void net_tx_action(struct sof= tirq_action *h) if (likely(get_kfree_skb_cb(skb)->reason =3D=3D SKB_REASON_CONSUMED)) trace_consume_skb(skb); else - trace_kfree_skb(skb, net_tx_action); + trace_kfree_skb(skb, net_tx_action, + SKB_DROP_REASON_NOT_SPECIFIED); =20 if (skb->fclone !=3D SKB_FCLONE_UNAVAILABLE) __kfree_skb(skb); diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index 1d99b731e5b2..78202141930f 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c @@ -110,7 +110,8 @@ static u32 net_dm_queue_len =3D 1000; =20 struct net_dm_alert_ops { void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb, - void *location); + void *location, + enum skb_drop_reason reason); void (*napi_poll_probe)(void *ignore, struct napi_struct *napi, int work, int budget); void (*work_item_func)(struct work_struct *work); @@ -262,7 +263,9 @@ static void trace_drop_common(struct sk_buff *skb, void= *location) spin_unlock_irqrestore(&data->lock, flags); } =20 -static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, void *l= ocation) +static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, + void *location, + enum skb_drop_reason reason) { trace_drop_common(skb, location); } @@ -494,7 +497,8 @@ static const struct net_dm_alert_ops net_dm_alert_summa= ry_ops =3D { =20 static void net_dm_packet_trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, - void *location) + void *location, + enum skb_drop_reason reason) { ktime_t tstamp =3D ktime_get_real(); struct per_cpu_dm_data *data; diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 7ef0f5a8ab03..5ebef94e14dc 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -759,21 +759,23 @@ void __kfree_skb(struct sk_buff *skb) EXPORT_SYMBOL(__kfree_skb); =20 /** - * kfree_skb - free an sk_buff + * kfree_skb_reason - free an sk_buff with special reason * @skb: buffer to free + * @reason: reason why this skb is dropped * * Drop a reference to the buffer and free it if the usage count has - * hit zero. + * hit zero. Meanwhile, pass the drop reason to 'kfree_skb' + * tracepoint. */ -void kfree_skb(struct sk_buff *skb) +void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) { if (!skb_unref(skb)) return; =20 - trace_kfree_skb(skb, __builtin_return_address(0)); + trace_kfree_skb(skb, __builtin_return_address(0), reason); __kfree_skb(skb); } -EXPORT_SYMBOL(kfree_skb); +EXPORT_SYMBOL(kfree_skb_reason); =20 void kfree_skb_list(struct sk_buff *segs) { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6936C04A68 for ; Wed, 27 Jul 2022 17:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241571AbiG0RMv (ORCPT ); Wed, 27 Jul 2022 13:12:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237345AbiG0RME (ORCPT ); Wed, 27 Jul 2022 13:12:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE75D74E20; Wed, 27 Jul 2022 09:41:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 421C5B821D6; Wed, 27 Jul 2022 16:41:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44949C433C1; Wed, 27 Jul 2022 16:41:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940104; bh=e5SyryGEC220qyDAHi0iMFQrru4rfLU/teuOzDcSVNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DG4rJCg0VVxmA0tX9xHOI6200Zf7kDksiPzg8jW3H2RFqGC9hmGGGACbhpi42zxJx +hMT5KMn5KNPVTMoKmyRGvaYBB481mD+3J7lhwsx3riuD+uuiupHNxKHgLWml7wYlF Ytnnf03DHbB6Jbv3g5TKIU8ryFO9YGFNivCQUTt4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 075/201] net: skb: use kfree_skb_reason() in tcp_v4_rcv() Date: Wed, 27 Jul 2022 18:09:39 +0200 Message-Id: <20220727161030.046443697@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit 85125597419aec3aa7b8f3b8713e415f997796f2 ] Replace kfree_skb() with kfree_skb_reason() in tcp_v4_rcv(). Following drop reasons are added: SKB_DROP_REASON_NO_SOCKET SKB_DROP_REASON_PKT_TOO_SMALL SKB_DROP_REASON_TCP_CSUM SKB_DROP_REASON_TCP_FILTER After this patch, 'kfree_skb' event will print message like this: $ TASK-PID CPU# ||||| TIMESTAMP FUNCTION $ | | | ||||| | | -0 [000] ..s1. 36.113438: kfree_skb: skbaddr=3D(__= __ptrval____) protocol=3D2048 location=3D(____ptrval____) reason: NO_SOCKET The reason of skb drop is printed too. Signed-off-by: Menglong Dong Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 4 ++++ net/ipv4/tcp_ipv4.c | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 029bc228bcf9..5305af6cc86f 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -312,6 +312,10 @@ struct sk_buff; */ enum skb_drop_reason { SKB_DROP_REASON_NOT_SPECIFIED, + SKB_DROP_REASON_NO_SOCKET, + SKB_DROP_REASON_PKT_TOO_SMALL, + SKB_DROP_REASON_TCP_CSUM, + SKB_DROP_REASON_TCP_FILTER, SKB_DROP_REASON_MAX, }; =20 diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 294c61bbe44b..faa7d068a7bc 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -11,6 +11,10 @@ =20 #define TRACE_SKB_DROP_REASON \ EM(SKB_DROP_REASON_NOT_SPECIFIED, NOT_SPECIFIED) \ + EM(SKB_DROP_REASON_NO_SOCKET, NO_SOCKET) \ + EM(SKB_DROP_REASON_PKT_TOO_SMALL, PKT_TOO_SMALL) \ + EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ + EM(SKB_DROP_REASON_TCP_FILTER, TCP_FILTER) \ EMe(SKB_DROP_REASON_MAX, MAX) =20 #undef EM diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index b9a9f288bfa6..d901858aa440 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1976,8 +1976,10 @@ int tcp_v4_rcv(struct sk_buff *skb) const struct tcphdr *th; bool refcounted; struct sock *sk; + int drop_reason; int ret; =20 + drop_reason =3D SKB_DROP_REASON_NOT_SPECIFIED; if (skb->pkt_type !=3D PACKET_HOST) goto discard_it; =20 @@ -1989,8 +1991,10 @@ int tcp_v4_rcv(struct sk_buff *skb) =20 th =3D (const struct tcphdr *)skb->data; =20 - if (unlikely(th->doff < sizeof(struct tcphdr) / 4)) + if (unlikely(th->doff < sizeof(struct tcphdr) / 4)) { + drop_reason =3D SKB_DROP_REASON_PKT_TOO_SMALL; goto bad_packet; + } if (!pskb_may_pull(skb, th->doff * 4)) goto discard_it; =20 @@ -2093,8 +2097,10 @@ int tcp_v4_rcv(struct sk_buff *skb) =20 nf_reset_ct(skb); =20 - if (tcp_filter(sk, skb)) + if (tcp_filter(sk, skb)) { + drop_reason =3D SKB_DROP_REASON_TCP_FILTER; goto discard_and_relse; + } th =3D (const struct tcphdr *)skb->data; iph =3D ip_hdr(skb); tcp_v4_fill_cb(skb, iph, th); @@ -2131,6 +2137,7 @@ int tcp_v4_rcv(struct sk_buff *skb) return ret; =20 no_tcp_socket: + drop_reason =3D SKB_DROP_REASON_NO_SOCKET; if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) goto discard_it; =20 @@ -2138,6 +2145,7 @@ int tcp_v4_rcv(struct sk_buff *skb) =20 if (tcp_checksum_complete(skb)) { csum_error: + drop_reason =3D SKB_DROP_REASON_TCP_CSUM; trace_tcp_bad_csum(skb); __TCP_INC_STATS(net, TCP_MIB_CSUMERRORS); bad_packet: @@ -2148,7 +2156,7 @@ int tcp_v4_rcv(struct sk_buff *skb) =20 discard_it: /* Discard frame. */ - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return 0; =20 discard_and_relse: --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22ADCC19F28 for ; Wed, 27 Jul 2022 17:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241475AbiG0RMz (ORCPT ); Wed, 27 Jul 2022 13:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241474AbiG0RMJ (ORCPT ); Wed, 27 Jul 2022 13:12:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93E6351420; Wed, 27 Jul 2022 09:41:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 20ED2614A3; Wed, 27 Jul 2022 16:41:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31161C433C1; Wed, 27 Jul 2022 16:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940107; bh=UJGErmSItXRIZuDAwHn2eChFK9M7zB+QgDchWKCYkyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RGRGjW55zpe+Nv4aVCtk7nBRZoMQ6o1NfzcYyEVn9EJN3xZqePvDaM05Or5WI+bKh 1+4PkFr8Mx5lD281n9nwSxfvVWqbWj8xvWrHlpXnSbh2aaplm496JG95cUHHCC7DjD RNyw7LjchhRBGUlpBmyWB3xr2jZuH6A5ZNdTRIMI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 076/201] net: skb: use kfree_skb_reason() in __udp4_lib_rcv() Date: Wed, 27 Jul 2022 18:09:40 +0200 Message-Id: <20220727161030.093229958@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit 1c7fab70df085d866a3765955f397ca2b4025b15 ] Replace kfree_skb() with kfree_skb_reason() in __udp4_lib_rcv. New drop reason 'SKB_DROP_REASON_UDP_CSUM' is added for udp csum error. Signed-off-by: Menglong Dong Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/ipv4/udp.c | 10 ++++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 5305af6cc86f..66aac2006868 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -316,6 +316,7 @@ enum skb_drop_reason { SKB_DROP_REASON_PKT_TOO_SMALL, SKB_DROP_REASON_TCP_CSUM, SKB_DROP_REASON_TCP_FILTER, + SKB_DROP_REASON_UDP_CSUM, SKB_DROP_REASON_MAX, }; =20 diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index faa7d068a7bc..3e042ca2cedb 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -15,6 +15,7 @@ EM(SKB_DROP_REASON_PKT_TOO_SMALL, PKT_TOO_SMALL) \ EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ EM(SKB_DROP_REASON_TCP_FILTER, TCP_FILTER) \ + EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ EMe(SKB_DROP_REASON_MAX, MAX) =20 #undef EM diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 835b9d6e4e68..4ad4daa16cce 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2411,6 +2411,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_ta= ble *udptable, __be32 saddr, daddr; struct net *net =3D dev_net(skb->dev); bool refcounted; + int drop_reason; + + drop_reason =3D SKB_DROP_REASON_NOT_SPECIFIED; =20 /* * Validate the packet. @@ -2466,6 +2469,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_ta= ble *udptable, if (udp_lib_checksum_complete(skb)) goto csum_error; =20 + drop_reason =3D SKB_DROP_REASON_NO_SOCKET; __UDP_INC_STATS(net, UDP_MIB_NOPORTS, proto =3D=3D IPPROTO_UDPLITE); icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); =20 @@ -2473,10 +2477,11 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_= table *udptable, * Hmm. We got an UDP packet to a port to which we * don't wanna listen. Ignore it. */ - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return 0; =20 short_packet: + drop_reason =3D SKB_DROP_REASON_PKT_TOO_SMALL; net_dbg_ratelimited("UDP%s: short packet: From %pI4:%u %d/%d to %pI4:%u\n= ", proto =3D=3D IPPROTO_UDPLITE ? "Lite" : "", &saddr, ntohs(uh->source), @@ -2489,6 +2494,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_ta= ble *udptable, * RFC1122: OK. Discards the bad packet silently (as far as * the network is concerned, anyway) as per 4.1.3.4 (MUST). */ + drop_reason =3D SKB_DROP_REASON_UDP_CSUM; net_dbg_ratelimited("UDP%s: bad checksum. From %pI4:%u to %pI4:%u ulen %d= \n", proto =3D=3D IPPROTO_UDPLITE ? "Lite" : "", &saddr, ntohs(uh->source), &daddr, ntohs(uh->dest), @@ -2496,7 +2502,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_ta= ble *udptable, __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, proto =3D=3D IPPROTO_UDPLITE); drop: __UDP_INC_STATS(net, UDP_MIB_INERRORS, proto =3D=3D IPPROTO_UDPLITE); - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return 0; } =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16CC8C04A68 for ; Wed, 27 Jul 2022 17:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240080AbiG0RNQ (ORCPT ); Wed, 27 Jul 2022 13:13:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241532AbiG0RMh (ORCPT ); Wed, 27 Jul 2022 13:12:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DA7A5141E; Wed, 27 Jul 2022 09:41:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 854FDB821D7; Wed, 27 Jul 2022 16:41:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6FE6C433C1; Wed, 27 Jul 2022 16:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940110; bh=dX2+usKkMs6QVDHsG9LU9bsX+tJXsNK7ZQnTcmsdsNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wBevXiK/YNMuk4afnU7hC2fZ1D12Ti2Mmv+rW59POCjyr75Swfvz85JSepTqyr4V5 dgZrF9f8nhXIso8LOxiwVdfMJL3o6yfTz3fQbLzx8DQvJtWWPCck/2gFlycEGBgLV4 lCdGkSRHeaPA6/RxJFffjOIUi30esBaC+plMGmWI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , David Ahern , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 077/201] net: socket: rename SKB_DROP_REASON_SOCKET_FILTER Date: Wed, 27 Jul 2022 18:09:41 +0200 Message-Id: <20220727161030.135220141@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit 364df53c081d93fcfd6b91085ff2650c7f17b3c7 ] Rename SKB_DROP_REASON_SOCKET_FILTER, which is used as the reason of skb drop out of socket filter before it's part of a released kernel. It will be used for more protocols than just TCP in future series. Signed-off-by: Menglong Dong Reviewed-by: David Ahern Link: https://lore.kernel.org/all/20220127091308.91401-2-imagedong@tencent.= com/ Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 2 +- include/trace/events/skb.h | 2 +- net/ipv4/tcp_ipv4.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 66aac2006868..f92f05c9d72d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -315,7 +315,7 @@ enum skb_drop_reason { SKB_DROP_REASON_NO_SOCKET, SKB_DROP_REASON_PKT_TOO_SMALL, SKB_DROP_REASON_TCP_CSUM, - SKB_DROP_REASON_TCP_FILTER, + SKB_DROP_REASON_SOCKET_FILTER, SKB_DROP_REASON_UDP_CSUM, SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 3e042ca2cedb..a8a64b97504d 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -14,7 +14,7 @@ EM(SKB_DROP_REASON_NO_SOCKET, NO_SOCKET) \ EM(SKB_DROP_REASON_PKT_TOO_SMALL, PKT_TOO_SMALL) \ EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ - EM(SKB_DROP_REASON_TCP_FILTER, TCP_FILTER) \ + EM(SKB_DROP_REASON_SOCKET_FILTER, SOCKET_FILTER) \ EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ EMe(SKB_DROP_REASON_MAX, MAX) =20 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index d901858aa440..235ae91bfd5a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2098,7 +2098,7 @@ int tcp_v4_rcv(struct sk_buff *skb) nf_reset_ct(skb); =20 if (tcp_filter(sk, skb)) { - drop_reason =3D SKB_DROP_REASON_TCP_FILTER; + drop_reason =3D SKB_DROP_REASON_SOCKET_FILTER; goto discard_and_relse; } th =3D (const struct tcphdr *)skb->data; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FAE0C04A68 for ; Wed, 27 Jul 2022 17:13:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241563AbiG0RNS (ORCPT ); Wed, 27 Jul 2022 13:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236884AbiG0RMm (ORCPT ); Wed, 27 Jul 2022 13:12:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF87B7539E; Wed, 27 Jul 2022 09:42:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 928EEB821DB; Wed, 27 Jul 2022 16:41:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B619BC433D7; Wed, 27 Jul 2022 16:41:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940113; bh=scrNFbmgOZf8SLm+fKyCrg0Y7HaLGnqW0jwrPYjZklk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dWxE5rsi440CrrcFtB3v6khL0uXN52UtCTywtF2esDXa3vp1vhW1z1CjiGU41cv0s t9bbkPsVegM67o2hUO7bZ56CBMLFmXHQcgQ8kt3killfSu3At8PKKvu3RizntFVpDE EMEtlfFakTSxkqFTpwve6T4wgB7Tt448E4WIaARY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , David Ahern , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 078/201] net: skb_drop_reason: add document for drop reasons Date: Wed, 27 Jul 2022 18:09:42 +0200 Message-Id: <20220727161030.183977949@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit 88590b369354092183bcba04e2368010c462557f ] Add document for following existing drop reasons: SKB_DROP_REASON_NOT_SPECIFIED SKB_DROP_REASON_NO_SOCKET SKB_DROP_REASON_PKT_TOO_SMALL SKB_DROP_REASON_TCP_CSUM SKB_DROP_REASON_SOCKET_FILTER SKB_DROP_REASON_UDP_CSUM Signed-off-by: Menglong Dong Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index f92f05c9d72d..f329c617eb96 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -311,12 +311,12 @@ struct sk_buff; * used to translate the reason to string. */ enum skb_drop_reason { - SKB_DROP_REASON_NOT_SPECIFIED, - SKB_DROP_REASON_NO_SOCKET, - SKB_DROP_REASON_PKT_TOO_SMALL, - SKB_DROP_REASON_TCP_CSUM, - SKB_DROP_REASON_SOCKET_FILTER, - SKB_DROP_REASON_UDP_CSUM, + SKB_DROP_REASON_NOT_SPECIFIED, /* drop reason is not specified */ + SKB_DROP_REASON_NO_SOCKET, /* socket not found */ + SKB_DROP_REASON_PKT_TOO_SMALL, /* packet size is too small */ + SKB_DROP_REASON_TCP_CSUM, /* TCP checksum error */ + SKB_DROP_REASON_SOCKET_FILTER, /* dropped by socket filter */ + SKB_DROP_REASON_UDP_CSUM, /* UDP checksum error */ SKB_DROP_REASON_MAX, }; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4448CC04A68 for ; Wed, 27 Jul 2022 17:08:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241450AbiG0RIj (ORCPT ); Wed, 27 Jul 2022 13:08:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241451AbiG0RH4 (ORCPT ); Wed, 27 Jul 2022 13:07:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A1061658D; Wed, 27 Jul 2022 09:40:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C9B6A601CE; Wed, 27 Jul 2022 16:40:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D63E8C433C1; Wed, 27 Jul 2022 16:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940021; bh=B28QdpMn8RV/RTfUkpe7kvUhoTVi3QlwDrWpHF7ZnbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nFVGA9RXG/FSAzOFiROn3vNbK4fG26lys57yx9EG8W9BGHSWxnEbR/BdWZ+EMiC5n 0Ji/GEzYtDlpGlbwie1hr+Z0gJpzJ7ijaCyLr8FnGrSEUU5hH9wbxjWKjZ0RSzKwmk eufznZSqz2pJsv2zCDM6xbY+KzzljBj9Fgt9T2h0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 079/201] net: netfilter: use kfree_drop_reason() for NF_DROP Date: Wed, 27 Jul 2022 18:09:43 +0200 Message-Id: <20220727161030.222475094@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit 2df3041ba3be950376e8c25a8f6da22f7fcc765c ] Replace kfree_skb() with kfree_skb_reason() in nf_hook_slow() when skb is dropped by reason of NF_DROP. Following new drop reasons are introduced: SKB_DROP_REASON_NETFILTER_DROP Signed-off-by: Menglong Dong Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/netfilter/core.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index f329c617eb96..b63da0d1a4b2 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -317,6 +317,7 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_CSUM, /* TCP checksum error */ SKB_DROP_REASON_SOCKET_FILTER, /* dropped by socket filter */ SKB_DROP_REASON_UDP_CSUM, /* UDP checksum error */ + SKB_DROP_REASON_NETFILTER_DROP, /* dropped by netfilter */ SKB_DROP_REASON_MAX, }; =20 diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index a8a64b97504d..3d89f7b09a43 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -16,6 +16,7 @@ EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ EM(SKB_DROP_REASON_SOCKET_FILTER, SOCKET_FILTER) \ EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ + EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP) \ EMe(SKB_DROP_REASON_MAX, MAX) =20 #undef EM diff --git a/net/netfilter/core.c b/net/netfilter/core.c index 60332fdb6dd4..cca0762a9010 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c @@ -592,7 +592,8 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_st= ate *state, case NF_ACCEPT: break; case NF_DROP: - kfree_skb(skb); + kfree_skb_reason(skb, + SKB_DROP_REASON_NETFILTER_DROP); ret =3D NF_DROP_GETERR(verdict); if (ret =3D=3D 0) ret =3D -EPERM; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3F8EC04A68 for ; Wed, 27 Jul 2022 17:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241469AbiG0RIy (ORCPT ); Wed, 27 Jul 2022 13:08:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232344AbiG0RIQ (ORCPT ); Wed, 27 Jul 2022 13:08:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC6E76111C; Wed, 27 Jul 2022 09:40:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A1D9B60D3B; Wed, 27 Jul 2022 16:40:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8E88C433C1; Wed, 27 Jul 2022 16:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940029; bh=zlHJOWkPsDeDylpjq8ckd+8CGod2vzFec7FDbG9SG6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NC/gwvXybhri5+S9+zi4dyA0iq7HS1g7n5MsKbAYllk7U6R8mLduSNNwVGv8mMm8p WEteyeM0tpHELTkEnoly9LgFXxOOBQycv6RIrZhMg3RVU6nkuCvn7La/0VX7wWKn/7 q+cVVmVkiHfh86WgSK0fFtt5cF0OmLJM00nmnNjc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , David Ahern , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 080/201] net: ipv4: use kfree_skb_reason() in ip_rcv_core() Date: Wed, 27 Jul 2022 18:09:44 +0200 Message-Id: <20220727161030.270068330@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit 33cba42985c8144eef78d618fc1e51aaa074b169 ] Replace kfree_skb() with kfree_skb_reason() in ip_rcv_core(). Three new drop reasons are introduced: SKB_DROP_REASON_OTHERHOST SKB_DROP_REASON_IP_CSUM SKB_DROP_REASON_IP_INHDR Signed-off-by: Menglong Dong Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 9 +++++++++ include/trace/events/skb.h | 3 +++ net/ipv4/ip_input.c | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index b63da0d1a4b2..514fb8074f78 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -318,6 +318,15 @@ enum skb_drop_reason { SKB_DROP_REASON_SOCKET_FILTER, /* dropped by socket filter */ SKB_DROP_REASON_UDP_CSUM, /* UDP checksum error */ SKB_DROP_REASON_NETFILTER_DROP, /* dropped by netfilter */ + SKB_DROP_REASON_OTHERHOST, /* packet don't belong to current + * host (interface is in promisc + * mode) + */ + SKB_DROP_REASON_IP_CSUM, /* IP checksum error */ + SKB_DROP_REASON_IP_INHDR, /* there is something wrong with + * IP header (see + * IPSTATS_MIB_INHDRERRORS) + */ SKB_DROP_REASON_MAX, }; =20 diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 3d89f7b09a43..f2b1778485f0 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -17,6 +17,9 @@ EM(SKB_DROP_REASON_SOCKET_FILTER, SOCKET_FILTER) \ EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP) \ + EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ + EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ + EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ EMe(SKB_DROP_REASON_MAX, MAX) =20 #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 3a025c011971..7be18de32e16 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -436,13 +436,16 @@ static int ip_rcv_finish(struct net *net, struct sock= *sk, struct sk_buff *skb) static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) { const struct iphdr *iph; + int drop_reason; u32 len; =20 /* When the interface is in promisc. mode, drop all the crap * that it receives, do not try to analyse it. */ - if (skb->pkt_type =3D=3D PACKET_OTHERHOST) + if (skb->pkt_type =3D=3D PACKET_OTHERHOST) { + drop_reason =3D SKB_DROP_REASON_OTHERHOST; goto drop; + } =20 __IP_UPD_PO_STATS(net, IPSTATS_MIB_IN, skb->len); =20 @@ -452,6 +455,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb,= struct net *net) goto out; } =20 + drop_reason =3D SKB_DROP_REASON_NOT_SPECIFIED; if (!pskb_may_pull(skb, sizeof(struct iphdr))) goto inhdr_error; =20 @@ -488,6 +492,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb,= struct net *net) =20 len =3D ntohs(iph->tot_len); if (skb->len < len) { + drop_reason =3D SKB_DROP_REASON_PKT_TOO_SMALL; __IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS); goto drop; } else if (len < (iph->ihl*4)) @@ -516,11 +521,14 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *sk= b, struct net *net) return skb; =20 csum_error: + drop_reason =3D SKB_DROP_REASON_IP_CSUM; __IP_INC_STATS(net, IPSTATS_MIB_CSUMERRORS); inhdr_error: + if (drop_reason =3D=3D SKB_DROP_REASON_NOT_SPECIFIED) + drop_reason =3D SKB_DROP_REASON_IP_INHDR; __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); drop: - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); out: return NULL; } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6DA8C04A68 for ; Wed, 27 Jul 2022 17:09:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236569AbiG0RJB (ORCPT ); Wed, 27 Jul 2022 13:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233057AbiG0RIS (ORCPT ); Wed, 27 Jul 2022 13:08:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9579271736; Wed, 27 Jul 2022 09:40:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5F744601CE; Wed, 27 Jul 2022 16:40:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DED9C433C1; Wed, 27 Jul 2022 16:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940031; bh=s4VD1Qty460fbquy3y0AEgSCliLKVLMtsxx+mKAyKt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TT+HmD9JyjIC6fISoHn5tizNK9Je5UoFP6IC4lph7xdabebA8DfClfAH92NdMTRmZ bt4L5eAo8q/EiMKxNyzRrsIB2TEmDlD6mEYRWb6/TGJqrcMAJ74UIQQeOsMXFi7DMK GivTcypcVRulr6KoinqQueP+tw11FEVAsaIPAsyQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Menglong Dong , David Ahern , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 081/201] net: ipv4: use kfree_skb_reason() in ip_rcv_finish_core() Date: Wed, 27 Jul 2022 18:09:45 +0200 Message-Id: <20220727161031.089349214@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Menglong Dong [ Upstream commit c1f166d1f7eef212096a98b22f5acf92f9af353d ] Replace kfree_skb() with kfree_skb_reason() in ip_rcv_finish_core(), following drop reasons are introduced: SKB_DROP_REASON_IP_RPFILTER SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST Signed-off-by: Menglong Dong Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/skbuff.h | 9 +++++++++ include/trace/events/skb.h | 3 +++ net/ipv4/ip_input.c | 14 ++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 514fb8074f78..cbd719e5329a 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -327,6 +327,15 @@ enum skb_drop_reason { * IP header (see * IPSTATS_MIB_INHDRERRORS) */ + SKB_DROP_REASON_IP_RPFILTER, /* IP rpfilter validate failed. + * see the document for rp_filter + * in ip-sysctl.rst for more + * information + */ + SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, /* destination address of L2 + * is multicast, but L3 is + * unicast. + */ SKB_DROP_REASON_MAX, }; =20 diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index f2b1778485f0..485a1d3034a4 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -20,6 +20,9 @@ EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ + EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER) \ + EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, \ + UNICAST_IN_L2_MULTICAST) \ EMe(SKB_DROP_REASON_MAX, MAX) =20 #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 7be18de32e16..d5222c0fa87c 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -318,8 +318,10 @@ static int ip_rcv_finish_core(struct net *net, struct = sock *sk, { const struct iphdr *iph =3D ip_hdr(skb); int (*edemux)(struct sk_buff *skb); + int err, drop_reason; struct rtable *rt; - int err; + + drop_reason =3D SKB_DROP_REASON_NOT_SPECIFIED; =20 if (ip_can_use_hint(skb, iph, hint)) { err =3D ip_route_use_hint(skb, iph->daddr, iph->saddr, iph->tos, @@ -396,19 +398,23 @@ static int ip_rcv_finish_core(struct net *net, struct= sock *sk, * so-called "hole-196" attack) so do it for both. */ if (in_dev && - IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) + IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) { + drop_reason =3D SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST; goto drop; + } } =20 return NET_RX_SUCCESS; =20 drop: - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return NET_RX_DROP; =20 drop_error: - if (err =3D=3D -EXDEV) + if (err =3D=3D -EXDEV) { + drop_reason =3D SKB_DROP_REASON_IP_RPFILTER; __NET_INC_STATS(net, LINUX_MIB_IPRPFILTER); + } goto drop; } =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80B77C19F2D for ; Wed, 27 Jul 2022 17:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239411AbiG0RKB (ORCPT ); Wed, 27 Jul 2022 13:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237264AbiG0RIs (ORCPT ); Wed, 27 Jul 2022 13:08:48 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38D2572ED0; Wed, 27 Jul 2022 09:40:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 2AC80CE230F; Wed, 27 Jul 2022 16:40:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B604C433C1; Wed, 27 Jul 2022 16:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940034; bh=Zp7O+qA6v8hNhs/CuX4OQqC8NTPMh5+4zcXaPfJnW5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lXmxulfV38spYBck0YF1gC4WKcUOfg5rxHyjEQLQE7qjBPvp9/c7FTDLNkGHaIKwW wUX5+JSJvMQxQhSO7YnGoljNh974+KZT1uqy8irSZaagKf4FPGrAoYCjTunHdTixYa eE3tBYMb+hDQliBgEeiu+PAQub+6Q0mQ6KRDdQOo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vadim Pasternak , Wolfram Sang , Sasha Levin Subject: [PATCH 5.15 082/201] i2c: mlxcpld: Fix register setting for 400KHz frequency Date: Wed, 27 Jul 2022 18:09:46 +0200 Message-Id: <20220727161031.138829059@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Vadim Pasternak [ Upstream commit e1f77ecc75aaee6bed04e8fd7830e00032af012e ] Fix setting of 'Half Cycle' register for 400KHz frequency. Fixes: fa1049135c15 ("i2c: mlxcpld: Modify register setting for 400KHz freq= uency") Signed-off-by: Vadim Pasternak Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/i2c/busses/i2c-mlxcpld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxc= pld.c index 015e11c4663f..077d716c73ca 100644 --- a/drivers/i2c/busses/i2c-mlxcpld.c +++ b/drivers/i2c/busses/i2c-mlxcpld.c @@ -49,7 +49,7 @@ #define MLXCPLD_LPCI2C_NACK_IND 2 =20 #define MLXCPLD_I2C_FREQ_1000KHZ_SET 0x04 -#define MLXCPLD_I2C_FREQ_400KHZ_SET 0x0c +#define MLXCPLD_I2C_FREQ_400KHZ_SET 0x0e #define MLXCPLD_I2C_FREQ_100KHZ_SET 0x42 =20 enum mlxcpld_i2c_frequency { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC8CFC19F2C for ; Wed, 27 Jul 2022 17:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238533AbiG0RJ5 (ORCPT ); Wed, 27 Jul 2022 13:09:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241459AbiG0RIr (ORCPT ); Wed, 27 Jul 2022 13:08:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24AB55A8B0; Wed, 27 Jul 2022 09:40:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C349F60D38; Wed, 27 Jul 2022 16:40:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D272CC433C1; Wed, 27 Jul 2022 16:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940037; bh=OEykdUPXVNQvb/VQCM+52YVDVEsWYbSFVHjVP5N/vg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=voQ18kONvvwG4sy0T0+VmJoWs1zV9WTMM7DKs7doqGdG/xzhYKRcogxhvWKThAyuM uipin1FpYH+sA2U2b36m1LFSGRkSqERG7HTxi3Pw6Z9SSMJh6G2ellOESkBg+YNJUa 68i+c7yPSFqhK1q0NOgJ7jgySXEK0JeBR7hB5RIU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Hancock , Shubhrajyoti Datta , Michal Simek , Wolfram Sang , Sasha Levin Subject: [PATCH 5.15 083/201] i2c: cadence: Change large transfer count reset logic to be unconditional Date: Wed, 27 Jul 2022 18:09:47 +0200 Message-Id: <20220727161031.177855279@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Robert Hancock [ Upstream commit 4ca8ca873d454635c20d508261bfc0081af75cf8 ] Problems were observed on the Xilinx ZynqMP platform with large I2C reads. When a read of 277 bytes was performed, the controller NAKed the transfer after only 252 bytes were transferred and returned an ENXIO error on the transfer. There is some code in cdns_i2c_master_isr to handle this case by resetting the transfer count in the controller before it reaches 0, to allow larger transfers to work, but it was conditional on the CDNS_I2C_BROKEN_HOLD_BIT quirk being set on the controller, and ZynqMP uses the r1p14 version of the core where this quirk is not being set. The requirement to do this to support larger reads seems like an inherently required workaround due to the core only having an 8-bit transfer size register, so it does not appear that this should be conditional on the broken HOLD bit quirk which is used elsewhere in the driver. Remove the dependency on the CDNS_I2C_BROKEN_HOLD_BIT for this transfer size reset logic to fix this problem. Fixes: 63cab195bf49 ("i2c: removed work arounds in i2c driver for Zynq Ultr= ascale+ MPSoC") Signed-off-by: Robert Hancock Reviewed-by: Shubhrajyoti Datta Acked-by: Michal Simek Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/i2c/busses/i2c-cadence.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cade= nce.c index 3d6f8ee355bf..630cfa4ddd46 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -388,9 +388,9 @@ static irqreturn_t cdns_i2c_slave_isr(void *ptr) */ static irqreturn_t cdns_i2c_master_isr(void *ptr) { - unsigned int isr_status, avail_bytes, updatetx; + unsigned int isr_status, avail_bytes; unsigned int bytes_to_send; - bool hold_quirk; + bool updatetx; struct cdns_i2c *id =3D ptr; /* Signal completion only after everything is updated */ int done_flag =3D 0; @@ -410,11 +410,7 @@ static irqreturn_t cdns_i2c_master_isr(void *ptr) * Check if transfer size register needs to be updated again for a * large data receive operation. */ - updatetx =3D 0; - if (id->recv_count > id->curr_recv_count) - updatetx =3D 1; - - hold_quirk =3D (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) && updatetx; + updatetx =3D id->recv_count > id->curr_recv_count; =20 /* When receiving, handle data interrupt and completion interrupt */ if (id->p_recv_buf && @@ -445,7 +441,7 @@ static irqreturn_t cdns_i2c_master_isr(void *ptr) break; } =20 - if (cdns_is_holdquirk(id, hold_quirk)) + if (cdns_is_holdquirk(id, updatetx)) break; } =20 @@ -456,7 +452,7 @@ static irqreturn_t cdns_i2c_master_isr(void *ptr) * maintain transfer size non-zero while performing a large * receive operation. */ - if (cdns_is_holdquirk(id, hold_quirk)) { + if (cdns_is_holdquirk(id, updatetx)) { /* wait while fifo is full */ while (cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET) !=3D (id->curr_recv_count - CDNS_I2C_FIFO_DEPTH)) @@ -478,22 +474,6 @@ static irqreturn_t cdns_i2c_master_isr(void *ptr) CDNS_I2C_XFER_SIZE_OFFSET); id->curr_recv_count =3D id->recv_count; } - } else if (id->recv_count && !hold_quirk && - !id->curr_recv_count) { - - /* Set the slave address in address register*/ - cdns_i2c_writereg(id->p_msg->addr & CDNS_I2C_ADDR_MASK, - CDNS_I2C_ADDR_OFFSET); - - if (id->recv_count > CDNS_I2C_TRANSFER_SIZE) { - cdns_i2c_writereg(CDNS_I2C_TRANSFER_SIZE, - CDNS_I2C_XFER_SIZE_OFFSET); - id->curr_recv_count =3D CDNS_I2C_TRANSFER_SIZE; - } else { - cdns_i2c_writereg(id->recv_count, - CDNS_I2C_XFER_SIZE_OFFSET); - id->curr_recv_count =3D id->recv_count; - } } =20 /* Clear hold (if not repeated start) and signal completion */ --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75E8DC04A68 for ; Wed, 27 Jul 2022 17:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241395AbiG0RKE (ORCPT ); Wed, 27 Jul 2022 13:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241487AbiG0RIy (ORCPT ); Wed, 27 Jul 2022 13:08:54 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D127D4D153; Wed, 27 Jul 2022 09:40:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id CC100CE22F9; Wed, 27 Jul 2022 16:40:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8996EC433C1; Wed, 27 Jul 2022 16:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940040; bh=9YoCgJ40rzOqNOclYBRcgD4FzYAA8Mvm+m3wKZjwpPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdnNKzkDXsiZ06lgdBBzwIcZ+EcK+3mitbxol4e0C46SAnXPmXX7rYiZQEqYlDfJm HIqkwir5qJLTfRJJu5AZ8Zk/Pfq6g8HqFGRVHdbrCWd1PBC1Q55VRfg67uwfV6kEnM 78xJMylC+wfVxh57zGhzW6Hmf2joLIxqyiaNynqs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kan Liang , Adrian Hunter , Ian Rogers , Jin Yao , Jiri Olsa , Namhyung Kim , Thomas Richter , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.15 084/201] perf tests: Fix Convert perf time to TSC test for hybrid Date: Wed, 27 Jul 2022 18:09:48 +0200 Message-Id: <20220727161031.227950259@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Adrian Hunter [ Upstream commit deb44a6249f696106645c63c0603eab08a6122af ] The test does not always correctly determine the number of events for hybrids, nor allow for more than 1 evsel when parsing. Fix by iterating the events actually created and getting the correct evsel for the events processed. Fixes: d9da6f70eb235110 ("perf tests: Support 'Convert perf time to TSC' te= st for hybrid") Reviewed-by: Kan Liang Signed-off-by: Adrian Hunter Cc: Ian Rogers Cc: Jin Yao Cc: Jiri Olsa Cc: Namhyung Kim Cc: Thomas Richter Link: https://lore.kernel.org/r/20220713123459.24145-3-adrian.hunter@intel.= com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- tools/perf/tests/perf-time-to-tsc.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-ti= me-to-tsc.c index 7c56bc1f4cff..89d25befb171 100644 --- a/tools/perf/tests/perf-time-to-tsc.c +++ b/tools/perf/tests/perf-time-to-tsc.c @@ -20,8 +20,6 @@ #include "tsc.h" #include "mmap.h" #include "tests.h" -#include "pmu.h" -#include "pmu-hybrid.h" =20 #define CHECK__(x) { \ while ((x) < 0) { \ @@ -84,18 +82,8 @@ int test__perf_time_to_tsc(struct test *test __maybe_unu= sed, int subtest __maybe =20 evlist__config(evlist, &opts, NULL); =20 - evsel =3D evlist__first(evlist); - - evsel->core.attr.comm =3D 1; - evsel->core.attr.disabled =3D 1; - evsel->core.attr.enable_on_exec =3D 0; - - /* - * For hybrid "cycles:u", it creates two events. - * Init the second evsel here. - */ - if (perf_pmu__has_hybrid() && perf_pmu__hybrid_mounted("cpu_atom")) { - evsel =3D evsel__next(evsel); + /* For hybrid "cycles:u", it creates two events */ + evlist__for_each_entry(evlist, evsel) { evsel->core.attr.comm =3D 1; evsel->core.attr.disabled =3D 1; evsel->core.attr.enable_on_exec =3D 0; @@ -141,10 +129,12 @@ int test__perf_time_to_tsc(struct test *test __maybe_= unused, int subtest __maybe goto next_event; =20 if (strcmp(event->comm.comm, comm1) =3D=3D 0) { + CHECK_NOT_NULL__(evsel =3D evlist__event2evsel(evlist, event)); CHECK__(evsel__parse_sample(evsel, event, &sample)); comm1_time =3D sample.time; } if (strcmp(event->comm.comm, comm2) =3D=3D 0) { + CHECK_NOT_NULL__(evsel =3D evlist__event2evsel(evlist, event)); CHECK__(evsel__parse_sample(evsel, event, &sample)); comm2_time =3D sample.time; } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 558E5C04A68 for ; Wed, 27 Jul 2022 17:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239576AbiG0RKP (ORCPT ); Wed, 27 Jul 2022 13:10:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241491AbiG0RJG (ORCPT ); Wed, 27 Jul 2022 13:09:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 632775B054; Wed, 27 Jul 2022 09:40:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6C90460BAF; Wed, 27 Jul 2022 16:40:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75563C433D6; Wed, 27 Jul 2022 16:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940042; bh=NEa48WcsFvIgqPqblPrCpFOSbs6qiZ9b5ObRDAzNO18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n2Dn9yvr/EGFFqnqZjgKQv74lOy4ZaTIjU8wimDblEumOBVvVVDBQsNkS/JR2EC6v DntyAk5T2mcWupgqChXTm+Bj5iYtXY0Vyq49NJ+H8gRulPoFdZaVsAeXAjJ+2AKPbX ID+xIi1j6HF02qa9Em28jqIJePO2mDY/o7vR3Xz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cedric Wassenaar , Junxiao Chang , Florian Fainelli , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 085/201] net: stmmac: fix dma queue left shift overflow issue Date: Wed, 27 Jul 2022 18:09:49 +0200 Message-Id: <20220727161031.268059384@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Junxiao Chang [ Upstream commit 613b065ca32e90209024ec4a6bb5ca887ee70980 ] When queue number is > 4, left shift overflows due to 32 bits integer variable. Mask calculation is wrong for MTL_RXQ_DMA_MAP1. If CONFIG_UBSAN is enabled, kernel dumps below warning: [ 10.363842] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ 10.363882] UBSAN: shift-out-of-bounds in /build/linux-intel-iotg-5.15-8= e6Tf4/ linux-intel-iotg-5.15-5.15.0/drivers/net/ethernet/stmicro/stmmac/dwmac4_cor= e.c:224:12 [ 10.363929] shift exponent 40 is too large for 32-bit type 'unsigned int' [ 10.363953] CPU: 1 PID: 599 Comm: NetworkManager Not tainted 5.15.0-1003= -intel-iotg [ 10.363956] Hardware name: ADLINK Technology Inc. LEC-EL/LEC-EL, BIOS 0.= 15.11 12/22/2021 [ 10.363958] Call Trace: [ 10.363960] [ 10.363963] dump_stack_lvl+0x4a/0x5f [ 10.363971] dump_stack+0x10/0x12 [ 10.363974] ubsan_epilogue+0x9/0x45 [ 10.363976] __ubsan_handle_shift_out_of_bounds.cold+0x61/0x10e [ 10.363979] ? wake_up_klogd+0x4a/0x50 [ 10.363983] ? vprintk_emit+0x8f/0x240 [ 10.363986] dwmac4_map_mtl_dma.cold+0x42/0x91 [stmmac] [ 10.364001] stmmac_mtl_configuration+0x1ce/0x7a0 [stmmac] [ 10.364009] ? dwmac410_dma_init_channel+0x70/0x70 [stmmac] [ 10.364020] stmmac_hw_setup.cold+0xf/0xb14 [stmmac] [ 10.364030] ? page_pool_alloc_pages+0x4d/0x70 [ 10.364034] ? stmmac_clear_tx_descriptors+0x6e/0xe0 [stmmac] [ 10.364042] stmmac_open+0x39e/0x920 [stmmac] [ 10.364050] __dev_open+0xf0/0x1a0 [ 10.364054] __dev_change_flags+0x188/0x1f0 [ 10.364057] dev_change_flags+0x26/0x60 [ 10.364059] do_setlink+0x908/0xc40 [ 10.364062] ? do_setlink+0xb10/0xc40 [ 10.364064] ? __nla_validate_parse+0x4c/0x1a0 [ 10.364068] __rtnl_newlink+0x597/0xa10 [ 10.364072] ? __nla_reserve+0x41/0x50 [ 10.364074] ? __kmalloc_node_track_caller+0x1d0/0x4d0 [ 10.364079] ? pskb_expand_head+0x75/0x310 [ 10.364082] ? nla_reserve_64bit+0x21/0x40 [ 10.364086] ? skb_free_head+0x65/0x80 [ 10.364089] ? security_sock_rcv_skb+0x2c/0x50 [ 10.364094] ? __cond_resched+0x19/0x30 [ 10.364097] ? kmem_cache_alloc_trace+0x15a/0x420 [ 10.364100] rtnl_newlink+0x49/0x70 This change fixes MTL_RXQ_DMA_MAP1 mask issue and channel/queue mapping warning. Fixes: d43042f4da3e ("net: stmmac: mapping mtl rx to dma channel") BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=3D216195 Reported-by: Cedric Wassenaar Signed-off-by: Junxiao Chang Reviewed-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/ne= t/ethernet/stmicro/stmmac/dwmac4_core.c index b21745368983..412abfabd28b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -219,6 +219,9 @@ static void dwmac4_map_mtl_dma(struct mac_device_info *= hw, u32 queue, u32 chan) if (queue =3D=3D 0 || queue =3D=3D 4) { value &=3D ~MTL_RXQ_DMA_Q04MDMACH_MASK; value |=3D MTL_RXQ_DMA_Q04MDMACH(chan); + } else if (queue > 4) { + value &=3D ~MTL_RXQ_DMA_QXMDMACH_MASK(queue - 4); + value |=3D MTL_RXQ_DMA_QXMDMACH(chan, queue - 4); } else { value &=3D ~MTL_RXQ_DMA_QXMDMACH_MASK(queue); value |=3D MTL_RXQ_DMA_QXMDMACH(chan, queue); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFB47C19F28 for ; Wed, 27 Jul 2022 17:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241471AbiG0RKK (ORCPT ); Wed, 27 Jul 2022 13:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241494AbiG0RJH (ORCPT ); Wed, 27 Jul 2022 13:09:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86D5550070; Wed, 27 Jul 2022 09:40:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 328F0601CE; Wed, 27 Jul 2022 16:40:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F8D2C433C1; Wed, 27 Jul 2022 16:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940045; bh=GBLhn2OafOSRHiZdxxixnE1Zh/XffNtLQVF4iym9OZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMg7QcorZUb+Yz1FLB3d/5axaHx3+Ui0JmrBhCx7VS86NIGBuUISwWpJwO2kmtfTe i4Sx8NLIk/SXNyTkUe1QBOqUvGH5mUK2Mq+anbTGLBzsUrgUUSi60AGMb82a3pbTUe UgnVTgWN4ahRE7YfePiKJ/RMvDDMivwFVAnVcdzA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Mikityanskiy , Tariq Toukan , Jakub Kicinski , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 086/201] net/tls: Fix race in TLS device down flow Date: Wed, 27 Jul 2022 18:09:50 +0200 Message-Id: <20220727161031.305424966@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Tariq Toukan [ Upstream commit f08d8c1bb97c48f24a82afaa2fd8c140f8d3da8b ] Socket destruction flow and tls_device_down function sync against each other using tls_device_lock and the context refcount, to guarantee the device resources are freed via tls_dev_del() by the end of tls_device_down. In the following unfortunate flow, this won't happen: - refcount is decreased to zero in tls_device_sk_destruct. - tls_device_down starts, skips the context as refcount is zero, going all the way until it flushes the gc work, and returns without freeing the device resources. - only then, tls_device_queue_ctx_destruction is called, queues the gc work and frees the context's device resources. Solve it by decreasing the refcount in the socket's destruction flow under the tls_device_lock, for perfect synchronization. This does not slow down the common likely destructor flow, in which both the refcount is decreased and the spinlock is acquired, anyway. Fixes: e8f69799810c ("net/tls: Add generic NIC offload infrastructure") Reviewed-by: Maxim Mikityanskiy Signed-off-by: Tariq Toukan Reviewed-by: Jakub Kicinski Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/tls/tls_device.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 4775431cbd38..4e33150cfb9e 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -97,13 +97,16 @@ static void tls_device_queue_ctx_destruction(struct tls= _context *ctx) unsigned long flags; =20 spin_lock_irqsave(&tls_device_lock, flags); + if (unlikely(!refcount_dec_and_test(&ctx->refcount))) + goto unlock; + list_move_tail(&ctx->list, &tls_device_gc_list); =20 /* schedule_work inside the spinlock * to make sure tls_device_down waits for that work. */ schedule_work(&tls_device_gc_work); - +unlock: spin_unlock_irqrestore(&tls_device_lock, flags); } =20 @@ -194,8 +197,7 @@ void tls_device_sk_destruct(struct sock *sk) clean_acked_data_disable(inet_csk(sk)); } =20 - if (refcount_dec_and_test(&tls_ctx->refcount)) - tls_device_queue_ctx_destruction(tls_ctx); + tls_device_queue_ctx_destruction(tls_ctx); } EXPORT_SYMBOL_GPL(tls_device_sk_destruct); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8C7EC04A68 for ; Wed, 27 Jul 2022 17:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241492AbiG0RKT (ORCPT ); Wed, 27 Jul 2022 13:10:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241542AbiG0RJK (ORCPT ); Wed, 27 Jul 2022 13:09:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA68250063; Wed, 27 Jul 2022 09:40:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EC12360D3D; Wed, 27 Jul 2022 16:40:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0577FC433C1; Wed, 27 Jul 2022 16:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940048; bh=FQxLPzvBoA8moseFHIyvnkKdcTwqNUzEN00yHZI4IG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dj/t3GzHuKkyITVNY3tDGii28Gpx5iMFMzDF3Wo5vgbATNqjLiY8BmFUDfSEKbzzn +iuTzIWdQ2DHLfy+38+4FxupYV8XoyiekksVYrZ3Mn4GMpZ4G965tgFjd3NlgGgpaH Wf1SljSPptwhFxpvxyz/IWPtO7sl4teY9dOjPmXk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 087/201] igmp: Fix data-races around sysctl_igmp_llm_reports. Date: Wed, 27 Jul 2022 18:09:51 +0200 Message-Id: <20220727161031.345518560@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit f6da2267e71106474fbc0943dc24928b9cb79119 ] While reading sysctl_igmp_llm_reports, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. This test can be packed into a helper, so such changes will be in the follow-up series after net is merged into net-next. if (ipv4_is_local_multicast(pmc->multiaddr) && !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) Fixes: df2cf4a78e48 ("IGMP: Inhibit reports for local multicast groups") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/igmp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 930f6c41f519..ccfbc0a8f11c 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -467,7 +467,8 @@ static struct sk_buff *add_grec(struct sk_buff *skb, st= ruct ip_mc_list *pmc, =20 if (pmc->multiaddr =3D=3D IGMP_ALL_HOSTS) return skb; - if (ipv4_is_local_multicast(pmc->multiaddr) && !net->ipv4.sysctl_igmp_llm= _reports) + if (ipv4_is_local_multicast(pmc->multiaddr) && + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) return skb; =20 mtu =3D READ_ONCE(dev->mtu); @@ -593,7 +594,7 @@ static int igmpv3_send_report(struct in_device *in_dev,= struct ip_mc_list *pmc) if (pmc->multiaddr =3D=3D IGMP_ALL_HOSTS) continue; if (ipv4_is_local_multicast(pmc->multiaddr) && - !net->ipv4.sysctl_igmp_llm_reports) + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) continue; spin_lock_bh(&pmc->lock); if (pmc->sfcount[MCAST_EXCLUDE]) @@ -736,7 +737,8 @@ static int igmp_send_report(struct in_device *in_dev, s= truct ip_mc_list *pmc, if (type =3D=3D IGMPV3_HOST_MEMBERSHIP_REPORT) return igmpv3_send_report(in_dev, pmc); =20 - if (ipv4_is_local_multicast(group) && !net->ipv4.sysctl_igmp_llm_reports) + if (ipv4_is_local_multicast(group) && + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) return 0; =20 if (type =3D=3D IGMP_HOST_LEAVE_MESSAGE) @@ -920,7 +922,8 @@ static bool igmp_heard_report(struct in_device *in_dev,= __be32 group) =20 if (group =3D=3D IGMP_ALL_HOSTS) return false; - if (ipv4_is_local_multicast(group) && !net->ipv4.sysctl_igmp_llm_reports) + if (ipv4_is_local_multicast(group) && + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) return false; =20 rcu_read_lock(); @@ -1045,7 +1048,7 @@ static bool igmp_heard_query(struct in_device *in_dev= , struct sk_buff *skb, if (im->multiaddr =3D=3D IGMP_ALL_HOSTS) continue; if (ipv4_is_local_multicast(im->multiaddr) && - !net->ipv4.sysctl_igmp_llm_reports) + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) continue; spin_lock_bh(&im->lock); if (im->tm_running) @@ -1296,7 +1299,8 @@ static void __igmp_group_dropped(struct ip_mc_list *i= m, gfp_t gfp) #ifdef CONFIG_IP_MULTICAST if (im->multiaddr =3D=3D IGMP_ALL_HOSTS) return; - if (ipv4_is_local_multicast(im->multiaddr) && !net->ipv4.sysctl_igmp_llm_= reports) + if (ipv4_is_local_multicast(im->multiaddr) && + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) return; =20 reporter =3D im->reporter; @@ -1338,7 +1342,8 @@ static void igmp_group_added(struct ip_mc_list *im) #ifdef CONFIG_IP_MULTICAST if (im->multiaddr =3D=3D IGMP_ALL_HOSTS) return; - if (ipv4_is_local_multicast(im->multiaddr) && !net->ipv4.sysctl_igmp_llm_= reports) + if (ipv4_is_local_multicast(im->multiaddr) && + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) return; =20 if (in_dev->dead) @@ -1642,7 +1647,7 @@ static void ip_mc_rejoin_groups(struct in_device *in_= dev) if (im->multiaddr =3D=3D IGMP_ALL_HOSTS) continue; if (ipv4_is_local_multicast(im->multiaddr) && - !net->ipv4.sysctl_igmp_llm_reports) + !READ_ONCE(net->ipv4.sysctl_igmp_llm_reports)) continue; =20 /* a failover is happening and switches --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9001C04A68 for ; Wed, 27 Jul 2022 17:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241535AbiG0RKX (ORCPT ); Wed, 27 Jul 2022 13:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241594AbiG0RJR (ORCPT ); Wed, 27 Jul 2022 13:09:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DE7A74350; Wed, 27 Jul 2022 09:40:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4F9DEB8200D; Wed, 27 Jul 2022 16:40:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4AC3C433D6; Wed, 27 Jul 2022 16:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940051; bh=LKVDuINe2R8fHUioAcMA427TizSk5+ImKmFLRQAlKzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vy/Vp7Mzy4yhIbgeLN4GFyeW2pz5/005rMH9tSW7vycHCLPXAbDTucgIhynajarxf 5Sf82cmdmBZMPi7RKWFpHWY+TnwW3OsWD35vwQwora1lwH0L0tkxOuyZtWNCOgReB6 /ztREc6zTz8N53Qru/hd65GKy/f4UZZw5FA31sXo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 088/201] igmp: Fix a data-race around sysctl_igmp_max_memberships. Date: Wed, 27 Jul 2022 18:09:52 +0200 Message-Id: <20220727161031.394982405@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 6305d821e3b9b5379d348528e5b5faf316383bc2 ] While reading sysctl_igmp_max_memberships, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/igmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index ccfbc0a8f11c..8920ae3751d1 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -2197,7 +2197,7 @@ static int __ip_mc_join_group(struct sock *sk, struct= ip_mreqn *imr, count++; } err =3D -ENOBUFS; - if (count >=3D net->ipv4.sysctl_igmp_max_memberships) + if (count >=3D READ_ONCE(net->ipv4.sysctl_igmp_max_memberships)) goto done; iml =3D sock_kmalloc(sk, sizeof(*iml), GFP_KERNEL); if (!iml) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F765C04A68 for ; Wed, 27 Jul 2022 17:10:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241541AbiG0RKd (ORCPT ); Wed, 27 Jul 2022 13:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241621AbiG0RJU (ORCPT ); Wed, 27 Jul 2022 13:09:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04DB04C639; Wed, 27 Jul 2022 09:40:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ECBAEB821AC; Wed, 27 Jul 2022 16:40:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 539C2C433C1; Wed, 27 Jul 2022 16:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940056; bh=sKZP2mYqjo4WOulxsCq2wPhmo/rksLNmsICaNcomTXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=npsl9ltSJrpwpAHKVOgCsx3JGbNhbWlOIHkmDCulvh3fUIJaSVsIq9BNR6XLwA6z3 ibSsz0FoPW6AnKAFPQipRhqUa0K7qjTvoq3Tf+TNxmNNqkEGzsZVOubRdqBTUJi00S DVNl25nTd95FObWM841MjVOpPan0zWrICEVW9k4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 089/201] igmp: Fix data-races around sysctl_igmp_max_msf. Date: Wed, 27 Jul 2022 18:09:53 +0200 Message-Id: <20220727161031.436175071@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 6ae0f2e553737b8cce49a1372573c81130ffa80e ] While reading sysctl_igmp_max_msf, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/igmp.c | 2 +- net/ipv4/ip_sockglue.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 8920ae3751d1..9f4674244aff 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -2384,7 +2384,7 @@ int ip_mc_source(int add, int omode, struct sock *sk,= struct } /* else, add a new source to the filter */ =20 - if (psl && psl->sl_count >=3D net->ipv4.sysctl_igmp_max_msf) { + if (psl && psl->sl_count >=3D READ_ONCE(net->ipv4.sysctl_igmp_max_msf)) { err =3D -ENOBUFS; goto done; } diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 8268e427f889..38f296afb663 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -782,7 +782,7 @@ static int ip_set_mcast_msfilter(struct sock *sk, sockp= tr_t optval, int optlen) /* numsrc >=3D (4G-140)/128 overflow in 32 bits */ err =3D -ENOBUFS; if (gsf->gf_numsrc >=3D 0x1ffffff || - gsf->gf_numsrc > sock_net(sk)->ipv4.sysctl_igmp_max_msf) + gsf->gf_numsrc > READ_ONCE(sock_net(sk)->ipv4.sysctl_igmp_max_msf)) goto out_free_gsf; =20 err =3D -EINVAL; @@ -832,7 +832,7 @@ static int compat_ip_set_mcast_msfilter(struct sock *sk= , sockptr_t optval, =20 /* numsrc >=3D (4G-140)/128 overflow in 32 bits */ err =3D -ENOBUFS; - if (n > sock_net(sk)->ipv4.sysctl_igmp_max_msf) + if (n > READ_ONCE(sock_net(sk)->ipv4.sysctl_igmp_max_msf)) goto out_free_gsf; err =3D set_mcast_msfilter(sk, gf32->gf_interface, n, gf32->gf_fmode, &gf32->gf_group, gf32->gf_slist_flex); @@ -1242,7 +1242,7 @@ static int do_ip_setsockopt(struct sock *sk, int leve= l, int optname, } /* numsrc >=3D (1G-4) overflow in 32 bits */ if (msf->imsf_numsrc >=3D 0x3ffffffcU || - msf->imsf_numsrc > net->ipv4.sysctl_igmp_max_msf) { + msf->imsf_numsrc > READ_ONCE(net->ipv4.sysctl_igmp_max_msf)) { kfree(msf); err =3D -ENOBUFS; break; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B32A0C04A68 for ; Wed, 27 Jul 2022 17:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240271AbiG0RKr (ORCPT ); Wed, 27 Jul 2022 13:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241664AbiG0RJZ (ORCPT ); Wed, 27 Jul 2022 13:09:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D90317437D; Wed, 27 Jul 2022 09:41:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E73D7B821D2; Wed, 27 Jul 2022 16:41:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54256C433C1; Wed, 27 Jul 2022 16:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940059; bh=TJ7lSjhNZhHZWqjTPBeUQE7e2CXAbgfjDfZB53K4Vgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lVwMNYB4zvlYDlqNjbHg3e8l5Ym9L8g/wy5CRZJMTHrmQ7GtFqhswREXxjd1o3mV1 q0ZlvFnYu9fWbBTE5lv5qg+BhcY7J0HbJVIbr5FJtyrO4BdbXLNOfWZhqFojDtSkgr iR33X1wNrRJp7qBYcDia8tGo8BpVTfInUYuU18lM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 090/201] tcp: Fix data-races around keepalive sysctl knobs. Date: Wed, 27 Jul 2022 18:09:54 +0200 Message-Id: <20220727161031.478958779@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit f2f316e287e6c2e3a1c5bab8d9b77ee03daa0463 ] While reading sysctl_tcp_keepalive_(time|probes|intvl), they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/tcp.h | 9 ++++++--- net/smc/smc_llc.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 3b97db2d438f..cae0c9102eda 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1469,21 +1469,24 @@ static inline int keepalive_intvl_when(const struct= tcp_sock *tp) { struct net *net =3D sock_net((struct sock *)tp); =20 - return tp->keepalive_intvl ? : net->ipv4.sysctl_tcp_keepalive_intvl; + return tp->keepalive_intvl ? : + READ_ONCE(net->ipv4.sysctl_tcp_keepalive_intvl); } =20 static inline int keepalive_time_when(const struct tcp_sock *tp) { struct net *net =3D sock_net((struct sock *)tp); =20 - return tp->keepalive_time ? : net->ipv4.sysctl_tcp_keepalive_time; + return tp->keepalive_time ? : + READ_ONCE(net->ipv4.sysctl_tcp_keepalive_time); } =20 static inline int keepalive_probes(const struct tcp_sock *tp) { struct net *net =3D sock_net((struct sock *)tp); =20 - return tp->keepalive_probes ? : net->ipv4.sysctl_tcp_keepalive_probes; + return tp->keepalive_probes ? : + READ_ONCE(net->ipv4.sysctl_tcp_keepalive_probes); } =20 static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp) diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c index ee1f0fdba085..0ef15f8fba90 100644 --- a/net/smc/smc_llc.c +++ b/net/smc/smc_llc.c @@ -1787,7 +1787,7 @@ void smc_llc_lgr_init(struct smc_link_group *lgr, str= uct smc_sock *smc) init_waitqueue_head(&lgr->llc_flow_waiter); init_waitqueue_head(&lgr->llc_msg_waiter); mutex_init(&lgr->llc_conf_mutex); - lgr->llc_testlink_time =3D net->ipv4.sysctl_tcp_keepalive_time; + lgr->llc_testlink_time =3D READ_ONCE(net->ipv4.sysctl_tcp_keepalive_time); } =20 /* called after lgr was removed from lgr_list */ --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06712C04A68 for ; Wed, 27 Jul 2022 17:10:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbiG0RKx (ORCPT ); Wed, 27 Jul 2022 13:10:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241701AbiG0RJc (ORCPT ); Wed, 27 Jul 2022 13:09:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C377743C9; Wed, 27 Jul 2022 09:41:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2672A601C3; Wed, 27 Jul 2022 16:41:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F233C433B5; Wed, 27 Jul 2022 16:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940062; bh=fVvNtlgbgAe6ClvXquGjijDpiSBJVzaHL91Kx5ew4Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qSCoePc2Gi9gJwFYn4Ivn6fHIEXdZPDtMQ4/B9PrmWSIOptuzfOI5wWAFwNG4eMbL s7z6Ejw+ysdpZ46xMVJb2i54IlGYF4n+gijF+JXQWg9BeWKbLs/W3U51AO4c7qYHsw EmNcpNIl66pYI8ret3/ox+Owhzar0uGQfV4bxnJA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 091/201] tcp: Fix data-races around sysctl_tcp_syn(ack)?_retries. Date: Wed, 27 Jul 2022 18:09:55 +0200 Message-Id: <20220727161031.529543535@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 20a3b1c0f603e8c55c3396abd12dfcfb523e4d3c ] While reading sysctl_tcp_syn(ack)?_retries, they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/inet_connection_sock.c | 3 ++- net/ipv4/tcp.c | 3 ++- net/ipv4/tcp_timer.c | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_soc= k.c index d3bbb344bbe1..a53f9bf7886f 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -829,7 +829,8 @@ static void reqsk_timer_handler(struct timer_list *t) =20 icsk =3D inet_csk(sk_listener); net =3D sock_net(sk_listener); - max_syn_ack_retries =3D icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_s= ynack_retries; + max_syn_ack_retries =3D icsk->icsk_syn_retries ? : + READ_ONCE(net->ipv4.sysctl_tcp_synack_retries); /* Normally all the openreqs are young and become mature * (i.e. converted to established socket) for first timeout. * If synack was not acknowledged for 1 second, it means diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 4ac53c8f0583..e22a61b2ba82 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3974,7 +3974,8 @@ static int do_tcp_getsockopt(struct sock *sk, int lev= el, val =3D keepalive_probes(tp); break; case TCP_SYNCNT: - val =3D icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retries; + val =3D icsk->icsk_syn_retries ? : + READ_ONCE(net->ipv4.sysctl_tcp_syn_retries); break; case TCP_LINGER2: val =3D tp->linger2; diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 4f3b9ab222b6..a234704e8163 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -239,7 +239,8 @@ static int tcp_write_timeout(struct sock *sk) if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { if (icsk->icsk_retransmits) __dst_negative_advice(sk); - retry_until =3D icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retr= ies; + retry_until =3D icsk->icsk_syn_retries ? : + READ_ONCE(net->ipv4.sysctl_tcp_syn_retries); expired =3D icsk->icsk_retransmits >=3D retry_until; } else { if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1, 0)) { @@ -406,12 +407,15 @@ abort: tcp_write_err(sk); static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock= *req) { struct inet_connection_sock *icsk =3D inet_csk(sk); - int max_retries =3D icsk->icsk_syn_retries ? : - sock_net(sk)->ipv4.sysctl_tcp_synack_retries + 1; /* add one more ret= ry for fastopen */ struct tcp_sock *tp =3D tcp_sk(sk); + int max_retries; =20 req->rsk_ops->syn_ack_timeout(req); =20 + /* add one more retry for fastopen */ + max_retries =3D icsk->icsk_syn_retries ? : + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_synack_retries) + 1; + if (req->num_timeout >=3D max_retries) { tcp_write_err(sk); return; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A60BC04A68 for ; Wed, 27 Jul 2022 17:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241556AbiG0RK5 (ORCPT ); Wed, 27 Jul 2022 13:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241716AbiG0RJh (ORCPT ); Wed, 27 Jul 2022 13:09:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9C01743DB; Wed, 27 Jul 2022 09:41:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E9672614AD; Wed, 27 Jul 2022 16:41:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3C23C433C1; Wed, 27 Jul 2022 16:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940065; bh=ilUh0IvKwTJ3bPPNwTZW/MfnPkQl5fCqOhNvsYei6tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NQP95Cqqx3Gm/fjtgO0KLlrqyZkrM4IwreesxsslPnYvdw9ntdw06aID8PbumhCeu 6+ql3BLUZtZ7PG7Za9d55Cr1WYTwglTD9JBPOVfFAGzHviCfK691E4un5QTTvFaGSG 8tk58SXgtEqlCDJ4p3hDJqO6bw4v1453aeB4Taqo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 092/201] tcp: Fix data-races around sysctl_tcp_syncookies. Date: Wed, 27 Jul 2022 18:09:56 +0200 Message-Id: <20220727161031.573205678@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit f2e383b5bb6bbc60a0b94b87b3e49a2b1aefd11e ] While reading sysctl_tcp_syncookies, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/core/filter.c | 4 ++-- net/ipv4/syncookies.c | 3 ++- net/ipv4/tcp_input.c | 20 ++++++++++++-------- net/ipv6/syncookies.c | 3 ++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 8b2bc855714b..ac64395611ae 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6734,7 +6734,7 @@ BPF_CALL_5(bpf_tcp_check_syncookie, struct sock *, sk= , void *, iph, u32, iph_len if (sk->sk_protocol !=3D IPPROTO_TCP || sk->sk_state !=3D TCP_LISTEN) return -EINVAL; =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_syncookies) + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies)) return -EINVAL; =20 if (!th->ack || th->rst || th->syn) @@ -6809,7 +6809,7 @@ BPF_CALL_5(bpf_tcp_gen_syncookie, struct sock *, sk, = void *, iph, u32, iph_len, if (sk->sk_protocol !=3D IPPROTO_TCP || sk->sk_state !=3D TCP_LISTEN) return -EINVAL; =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_syncookies) + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies)) return -ENOENT; =20 if (!th->syn || th->ack || th->fin || th->rst) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index fd1dc86ba512..8eee771d2aca 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -342,7 +342,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk= _buff *skb) struct flowi4 fl4; u32 tsoff =3D 0; =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_syncookies || !th->ack || th->rst) + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies) || + !th->ack || th->rst) goto out; =20 if (tcp_synq_no_recent_overflow(sk)) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index ae06923fe8d0..134e36f46e91 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6735,11 +6735,14 @@ static bool tcp_syn_flood_action(const struct sock = *sk, const char *proto) { struct request_sock_queue *queue =3D &inet_csk(sk)->icsk_accept_queue; const char *msg =3D "Dropping request"; - bool want_cookie =3D false; struct net *net =3D sock_net(sk); + bool want_cookie =3D false; + u8 syncookies; + + syncookies =3D READ_ONCE(net->ipv4.sysctl_tcp_syncookies); =20 #ifdef CONFIG_SYN_COOKIES - if (net->ipv4.sysctl_tcp_syncookies) { + if (syncookies) { msg =3D "Sending cookies"; want_cookie =3D true; __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPREQQFULLDOCOOKIES); @@ -6747,8 +6750,7 @@ static bool tcp_syn_flood_action(const struct sock *s= k, const char *proto) #endif __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPREQQFULLDROP); =20 - if (!queue->synflood_warned && - net->ipv4.sysctl_tcp_syncookies !=3D 2 && + if (!queue->synflood_warned && syncookies !=3D 2 && xchg(&queue->synflood_warned, 1) =3D=3D 0) net_info_ratelimited("%s: Possible SYN flooding on port %d. %s. Check S= NMP counters.\n", proto, sk->sk_num, msg); @@ -6797,7 +6799,7 @@ u16 tcp_get_syncookie_mss(struct request_sock_ops *rs= k_ops, struct tcp_sock *tp =3D tcp_sk(sk); u16 mss; =20 - if (sock_net(sk)->ipv4.sysctl_tcp_syncookies !=3D 2 && + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies) !=3D 2 && !inet_csk_reqsk_queue_is_full(sk)) return 0; =20 @@ -6831,13 +6833,15 @@ int tcp_conn_request(struct request_sock_ops *rsk_o= ps, bool want_cookie =3D false; struct dst_entry *dst; struct flowi fl; + u8 syncookies; + + syncookies =3D READ_ONCE(net->ipv4.sysctl_tcp_syncookies); =20 /* TW buckets are converted to open requests without * limitations, they conserve resources and peer is * evidently real one. */ - if ((net->ipv4.sysctl_tcp_syncookies =3D=3D 2 || - inet_csk_reqsk_queue_is_full(sk)) && !isn) { + if ((syncookies =3D=3D 2 || inet_csk_reqsk_queue_is_full(sk)) && !isn) { want_cookie =3D tcp_syn_flood_action(sk, rsk_ops->slab_name); if (!want_cookie) goto drop; @@ -6887,7 +6891,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, =20 if (!want_cookie && !isn) { /* Kill the following clause, if you dislike this way. */ - if (!net->ipv4.sysctl_tcp_syncookies && + if (!syncookies && (net->ipv4.sysctl_max_syn_backlog - inet_csk_reqsk_queue_len(sk) < (net->ipv4.sysctl_max_syn_backlog >> 2)) && !tcp_peer_is_proven(req, dst)) { diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c index ca92dd6981de..12ae817aaf2e 100644 --- a/net/ipv6/syncookies.c +++ b/net/ipv6/syncookies.c @@ -141,7 +141,8 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk= _buff *skb) __u8 rcv_wscale; u32 tsoff =3D 0; =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_syncookies || !th->ack || th->rst) + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies) || + !th->ack || th->rst) goto out; =20 if (tcp_synq_no_recent_overflow(sk)) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34E1DC04A68 for ; Wed, 27 Jul 2022 17:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240245AbiG0RLC (ORCPT ); Wed, 27 Jul 2022 13:11:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241753AbiG0RJm (ORCPT ); Wed, 27 Jul 2022 13:09:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3F61501BF; Wed, 27 Jul 2022 09:41:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C5D80601CE; Wed, 27 Jul 2022 16:41:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF276C433D6; Wed, 27 Jul 2022 16:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940068; bh=4nPOBYRVh1TeKFhmDIyIk4pggIEMowzCSYFN4GeClBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p2q7R4/qg6V+3FgIzzUAF7MTTylqVSiEWg1/M/FiIE5JOdJBzXEFnaRlIGgbTXhhY QZkZujKsSOQzMc6orUbF+z32N81np+bg0o3n4FT7oiOBkC1XXy0ykk6qyM2M0moTNN eizXFmVqras/+6bG2B6cfaIu0Y8hh8fr7w7KRAps= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 093/201] tcp: Fix data-races around sysctl_tcp_migrate_req. Date: Wed, 27 Jul 2022 18:09:57 +0200 Message-Id: <20220727161031.613409590@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 4177f545895b1da08447a80692f30617154efa6e ] While reading sysctl_tcp_migrate_req, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: f9ac779f881c ("net: Introduce net.ipv4.tcp_migrate_req.") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/core/sock_reuseport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c index 3f00a28fe762..5daa1fa54249 100644 --- a/net/core/sock_reuseport.c +++ b/net/core/sock_reuseport.c @@ -387,7 +387,7 @@ void reuseport_stop_listen_sock(struct sock *sk) prog =3D rcu_dereference_protected(reuse->prog, lockdep_is_held(&reuseport_lock)); =20 - if (sock_net(sk)->ipv4.sysctl_tcp_migrate_req || + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req) || (prog && prog->expected_attach_type =3D=3D BPF_SK_REUSEPORT_SELECT_O= R_MIGRATE)) { /* Migration capable, move sk from the listening section * to the closed section. @@ -545,7 +545,7 @@ struct sock *reuseport_migrate_sock(struct sock *sk, hash =3D migrating_sk->sk_hash; prog =3D rcu_dereference(reuse->prog); if (!prog || prog->expected_attach_type !=3D BPF_SK_REUSEPORT_SELECT_OR_M= IGRATE) { - if (sock_net(sk)->ipv4.sysctl_tcp_migrate_req) + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_migrate_req)) goto select_by_hash; goto failure; } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A252CC04A68 for ; Wed, 27 Jul 2022 17:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236894AbiG0RLY (ORCPT ); Wed, 27 Jul 2022 13:11:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236728AbiG0RJ4 (ORCPT ); Wed, 27 Jul 2022 13:09:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A682747A5; Wed, 27 Jul 2022 09:41:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 842AFB8200C; Wed, 27 Jul 2022 16:41:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3913C43148; Wed, 27 Jul 2022 16:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940071; bh=1pglrrwycW2z8U297nLs5MoMbieH2foR75zOwcWSSas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G7SdClG//wN0irUM0ACqgy4dJz4AMBmgsAX2imKSXf2mtGD3Jw6kJi1fCTeRdghdZ jSZxF/b5/ojdKYL/rphueuptPXyGoHOOKKaOjv40lfZD8MEqlcTesYROeVCdxpFoAC hhbyyGORNADG1bwYXAxHafb8qOjzNRKRND2MfQ0k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 094/201] tcp: Fix data-races around sysctl_tcp_reordering. Date: Wed, 27 Jul 2022 18:09:58 +0200 Message-Id: <20220727161031.653048318@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 46778cd16e6a5ad1b2e3a91f6c057c907379418e ] While reading sysctl_tcp_reordering, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_input.c | 10 +++++++--- net/ipv4/tcp_metrics.c | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e22a61b2ba82..480fac19a074 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -447,7 +447,7 @@ void tcp_init_sock(struct sock *sk) tp->snd_cwnd_clamp =3D ~0; tp->mss_cache =3D TCP_MSS_DEFAULT; =20 - tp->reordering =3D sock_net(sk)->ipv4.sysctl_tcp_reordering; + tp->reordering =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering); tcp_assign_congestion_control(sk); =20 tp->tsoffset =3D 0; diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 134e36f46e91..06802295e170 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -2131,6 +2131,7 @@ void tcp_enter_loss(struct sock *sk) struct tcp_sock *tp =3D tcp_sk(sk); struct net *net =3D sock_net(sk); bool new_recovery =3D icsk->icsk_ca_state < TCP_CA_Recovery; + u8 reordering; =20 tcp_timeout_mark_lost(sk); =20 @@ -2151,10 +2152,12 @@ void tcp_enter_loss(struct sock *sk) /* Timeout in disordered state after receiving substantial DUPACKs * suggests that the degree of reordering is over-estimated. */ + reordering =3D READ_ONCE(net->ipv4.sysctl_tcp_reordering); if (icsk->icsk_ca_state <=3D TCP_CA_Disorder && - tp->sacked_out >=3D net->ipv4.sysctl_tcp_reordering) + tp->sacked_out >=3D reordering) tp->reordering =3D min_t(unsigned int, tp->reordering, - net->ipv4.sysctl_tcp_reordering); + reordering); + tcp_set_ca_state(sk, TCP_CA_Loss); tp->high_seq =3D tp->snd_nxt; tcp_ecn_queue_cwr(tp); @@ -3457,7 +3460,8 @@ static inline bool tcp_may_raise_cwnd(const struct so= ck *sk, const int flag) * new SACK or ECE mark may first advance cwnd here and later reduce * cwnd in tcp_fastretrans_alert() based on more states. */ - if (tcp_sk(sk)->reordering > sock_net(sk)->ipv4.sysctl_tcp_reordering) + if (tcp_sk(sk)->reordering > + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering)) return flag & FLAG_FORWARD_PROGRESS; =20 return flag & FLAG_DATA_ACKED; diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 7029b0e98edb..a501150deaa3 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -428,7 +428,8 @@ void tcp_update_metrics(struct sock *sk) if (!tcp_metric_locked(tm, TCP_METRIC_REORDERING)) { val =3D tcp_metric_get(tm, TCP_METRIC_REORDERING); if (val < tp->reordering && - tp->reordering !=3D net->ipv4.sysctl_tcp_reordering) + tp->reordering !=3D + READ_ONCE(net->ipv4.sysctl_tcp_reordering)) tcp_metric_set(tm, TCP_METRIC_REORDERING, tp->reordering); } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9A27C19F2B for ; Wed, 27 Jul 2022 17:11:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241405AbiG0RLH (ORCPT ); Wed, 27 Jul 2022 13:11:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241776AbiG0RJp (ORCPT ); Wed, 27 Jul 2022 13:09:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AA4F747A3; Wed, 27 Jul 2022 09:41:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 867AB601C3; Wed, 27 Jul 2022 16:41:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E761C433D7; Wed, 27 Jul 2022 16:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940073; bh=D4RGWKHHtCys79tC8EX20FMQBOv7f6u/bkm0+LkZim8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icfj+tE8FKmk89/5p5x7hN3geMPcP6X24I1HqC9Bdsx7OgJe1YdJud2j/d0sY+NTS WFSpv08CyMa5LaEQqWarbtJWY6yQ7nTouFtUvOt5iWZgYZx33BVRARKeim5RHr1Kj4 Fqr6ig5MlbC+3OaABrpcl6pCSqkM40Rd4SQzv1BM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 095/201] tcp: Fix data-races around some timeout sysctl knobs. Date: Wed, 27 Jul 2022 18:09:59 +0200 Message-Id: <20220727161031.694020677@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 39e24435a776e9de5c6dd188836cf2523547804b ] While reading these sysctl knobs, they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers. - tcp_retries1 - tcp_retries2 - tcp_orphan_retries - tcp_fin_timeout Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/tcp.h | 3 ++- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 10 +++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index cae0c9102eda..caecc020e521 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1499,7 +1499,8 @@ static inline u32 keepalive_time_elapsed(const struct= tcp_sock *tp) =20 static inline int tcp_fin_time(const struct sock *sk) { - int fin_timeout =3D tcp_sk(sk)->linger2 ? : sock_net(sk)->ipv4.sysctl_tcp= _fin_timeout; + int fin_timeout =3D tcp_sk(sk)->linger2 ? : + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fin_timeout); const int rto =3D inet_csk(sk)->icsk_rto; =20 if (fin_timeout < (rto << 2) - (rto >> 1)) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 480fac19a074..f853f34dfb79 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3980,7 +3980,7 @@ static int do_tcp_getsockopt(struct sock *sk, int lev= el, case TCP_LINGER2: val =3D tp->linger2; if (val >=3D 0) - val =3D (val ? : net->ipv4.sysctl_tcp_fin_timeout) / HZ; + val =3D (val ? : READ_ONCE(net->ipv4.sysctl_tcp_fin_timeout)) / HZ; break; case TCP_DEFER_ACCEPT: val =3D retrans_to_secs(icsk->icsk_accept_queue.rskq_defer_accept, diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 3fa2bfbc250d..fcccf56ae9f7 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -4093,7 +4093,7 @@ void tcp_send_probe0(struct sock *sk) =20 icsk->icsk_probes_out++; if (err <=3D 0) { - if (icsk->icsk_backoff < net->ipv4.sysctl_tcp_retries2) + if (icsk->icsk_backoff < READ_ONCE(net->ipv4.sysctl_tcp_retries2)) icsk->icsk_backoff++; timeout =3D tcp_probe0_when(sk, TCP_RTO_MAX); } else { diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index a234704e8163..ec5277becc6a 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -143,7 +143,7 @@ static int tcp_out_of_resources(struct sock *sk, bool d= o_reset) */ static int tcp_orphan_retries(struct sock *sk, bool alive) { - int retries =3D sock_net(sk)->ipv4.sysctl_tcp_orphan_retries; /* May be z= ero. */ + int retries =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_orphan_retries); = /* May be zero. */ =20 /* We know from an ICMP that something is wrong. */ if (sk->sk_err_soft && !alive) @@ -243,14 +243,14 @@ static int tcp_write_timeout(struct sock *sk) READ_ONCE(net->ipv4.sysctl_tcp_syn_retries); expired =3D icsk->icsk_retransmits >=3D retry_until; } else { - if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1, 0)) { + if (retransmits_timed_out(sk, READ_ONCE(net->ipv4.sysctl_tcp_retries1), = 0)) { /* Black hole detection */ tcp_mtu_probing(icsk, sk); =20 __dst_negative_advice(sk); } =20 - retry_until =3D net->ipv4.sysctl_tcp_retries2; + retry_until =3D READ_ONCE(net->ipv4.sysctl_tcp_retries2); if (sock_flag(sk, SOCK_DEAD)) { const bool alive =3D icsk->icsk_rto < TCP_RTO_MAX; =20 @@ -381,7 +381,7 @@ static void tcp_probe_timer(struct sock *sk) msecs_to_jiffies(icsk->icsk_user_timeout)) goto abort; =20 - max_probes =3D sock_net(sk)->ipv4.sysctl_tcp_retries2; + max_probes =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_retries2); if (sock_flag(sk, SOCK_DEAD)) { const bool alive =3D inet_csk_rto_backoff(icsk, TCP_RTO_MAX) < TCP_RTO_M= AX; =20 @@ -589,7 +589,7 @@ void tcp_retransmit_timer(struct sock *sk) } inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, tcp_clamp_rto_to_user_timeout(sk), TCP_RTO_MAX); - if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1 + 1, 0)) + if (retransmits_timed_out(sk, READ_ONCE(net->ipv4.sysctl_tcp_retries1) + = 1, 0)) __sk_dst_reset(sk); =20 out:; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0B22C04A68 for ; Wed, 27 Jul 2022 17:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241558AbiG0RLL (ORCPT ); Wed, 27 Jul 2022 13:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241835AbiG0RJw (ORCPT ); Wed, 27 Jul 2022 13:09:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79EC747BA; Wed, 27 Jul 2022 09:41:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6942C60D3B; Wed, 27 Jul 2022 16:41:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FF75C433C1; Wed, 27 Jul 2022 16:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940076; bh=OSWP3tpzDQLa4+c1qd6OeUMHvX9asp4gxZJtIF6jX0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRa7gpMNzR3naIjaTL7VMHfulVgRo0vtFgKYOxktV2O3w1LF6JlXAqv07t/6y23Z+ rOt19WdTmQ/eCRDjTq9v6fZP9uj7Haq29lBHThrNJYFHiAUp0K2gJ6DaSPnHq1/1Rk O9Jscq3kkq8qDwBoUjAQnvUuQqttujj58LAiYcJw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 096/201] tcp: Fix a data-race around sysctl_tcp_notsent_lowat. Date: Wed, 27 Jul 2022 18:10:00 +0200 Message-Id: <20220727161031.732774489@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 55be873695ed8912eb77ff46d1d1cadf028bd0f3 ] While reading sysctl_tcp_notsent_lowat, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: c9bee3b7fdec ("tcp: TCP_NOTSENT_LOWAT socket option") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/tcp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index caecc020e521..0c609d10c320 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1994,7 +1994,7 @@ void __tcp_v4_send_check(struct sk_buff *skb, __be32 = saddr, __be32 daddr); static inline u32 tcp_notsent_lowat(const struct tcp_sock *tp) { struct net *net =3D sock_net((struct sock *)tp); - return tp->notsent_lowat ?: net->ipv4.sysctl_tcp_notsent_lowat; + return tp->notsent_lowat ?: READ_ONCE(net->ipv4.sysctl_tcp_notsent_lowat); } =20 bool tcp_stream_memory_free(const struct sock *sk, int wake); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB800C04A68 for ; Wed, 27 Jul 2022 17:11:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241494AbiG0RLc (ORCPT ); Wed, 27 Jul 2022 13:11:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241486AbiG0RKP (ORCPT ); Wed, 27 Jul 2022 13:10:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8CE550716; Wed, 27 Jul 2022 09:41:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F2E5BB821AC; Wed, 27 Jul 2022 16:41:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BD23C43141; Wed, 27 Jul 2022 16:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940079; bh=njFzzC6MTd3uWhSnu3HWPeCo5XsQIZZJ7INHpwE674k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=052Rw/fQRlq4dXPWOAoNfz4IaOmv1/1zlB7krAAOV1MnOiFw/ShzI4LzHHqDE4wAF 4lRLTPfwkejKMygrJGcXSNQpMn8aqXb4vrsN81a+oVw0xyWa+vkFiJvvwSWJLr6qDe cTWJHNYOmpADj+9JmROpcbw83EBXmT7jkNxWQS7o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 097/201] tcp: Fix a data-race around sysctl_tcp_tw_reuse. Date: Wed, 27 Jul 2022 18:10:01 +0200 Message-Id: <20220727161031.780390256@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit cbfc6495586a3f09f6f07d9fb3c7cafe807e3c55 ] While reading sysctl_tcp_tw_reuse, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 235ae91bfd5a..fba02cf6b468 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -108,10 +108,10 @@ static u32 tcp_v4_init_ts_off(const struct net *net, = const struct sk_buff *skb) =20 int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp) { + int reuse =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_tw_reuse); const struct inet_timewait_sock *tw =3D inet_twsk(sktw); const struct tcp_timewait_sock *tcptw =3D tcp_twsk(sktw); struct tcp_sock *tp =3D tcp_sk(sk); - int reuse =3D sock_net(sk)->ipv4.sysctl_tcp_tw_reuse; =20 if (reuse =3D=3D 2) { /* Still does not detect *everything* that goes through --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28402C04A68 for ; Wed, 27 Jul 2022 17:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241515AbiG0RLi (ORCPT ); Wed, 27 Jul 2022 13:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241525AbiG0RKW (ORCPT ); Wed, 27 Jul 2022 13:10:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE715B055; Wed, 27 Jul 2022 09:41:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A4A4AB821D5; Wed, 27 Jul 2022 16:41:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F760C433D6; Wed, 27 Jul 2022 16:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940082; bh=gf2m7bk8/Z0H/ebaJBMAgiohAbiIeqWxDTIVNmShfDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ecXfmink/t4Vuph2dKa2tbmE/9mXSTGQqHf0FX85v1TVg84+hcoYm5afGMxYPcoMW RlitZkPto3nDaiye1x+/nDu/CR3Vzb3gu6sybiAKdZnRVSez3ETx5u/tZO0bzrri0p Q48llKlSk4nhgZWpCtAC9CBpZVQRaRHv5tR7NnGo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 098/201] tcp: Fix data-races around sysctl_max_syn_backlog. Date: Wed, 27 Jul 2022 18:10:02 +0200 Message-Id: <20220727161031.817953575@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 79539f34743d3e14cc1fa6577d326a82cc64d62f ] While reading sysctl_max_syn_backlog, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 06802295e170..d9e534c6fd0c 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6894,10 +6894,12 @@ int tcp_conn_request(struct request_sock_ops *rsk_o= ps, tcp_rsk(req)->ts_off =3D af_ops->init_ts_off(net, skb); =20 if (!want_cookie && !isn) { + int max_syn_backlog =3D READ_ONCE(net->ipv4.sysctl_max_syn_backlog); + /* Kill the following clause, if you dislike this way. */ if (!syncookies && - (net->ipv4.sysctl_max_syn_backlog - inet_csk_reqsk_queue_len(sk) < - (net->ipv4.sysctl_max_syn_backlog >> 2)) && + (max_syn_backlog - inet_csk_reqsk_queue_len(sk) < + (max_syn_backlog >> 2)) && !tcp_peer_is_proven(req, dst)) { /* Without syncookies last quarter of * backlog is filled with destinations, --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ADCBC04A68 for ; Wed, 27 Jul 2022 17:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231434AbiG0RLx (ORCPT ); Wed, 27 Jul 2022 13:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbiG0RLT (ORCPT ); Wed, 27 Jul 2022 13:11:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3811474DCD; Wed, 27 Jul 2022 09:41:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7803AB821D4; Wed, 27 Jul 2022 16:41:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B199BC433C1; Wed, 27 Jul 2022 16:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940088; bh=0kYquqDGhF8Z1zRpTW2BhTWtRXVOwSnNBp010GmvBlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D1d6s3zmfXxDwQs4GghpmFC214OgxFmxEN0qPc15JEaoYA3JZswzXjoCajywa+H64 Ty4tqdygo82ocrYdR5o7DwRUbDM3pw8qn0Whl4ZgtsQbV8W/+9OXwi9EOW3FPL5jJH 6zP93/vqa5VDkeo61uFThIpHI5rNUKY2Al7KQ6P8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , Yuchung Cheng , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 099/201] tcp: Fix data-races around sysctl_tcp_fastopen. Date: Wed, 27 Jul 2022 18:10:03 +0200 Message-Id: <20220727161031.855970463@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 5a54213318c43f4009ae158347aa6016e3b9b55a ] While reading sysctl_tcp_fastopen, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 2100c8d2d9db ("net-tcp: Fast Open base") Signed-off-by: Kuniyuki Iwashima Acked-by: Yuchung Cheng Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/af_inet.c | 2 +- net/ipv4/tcp.c | 6 ++++-- net/ipv4/tcp_fastopen.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 781c595f6880..e4b2ced66261 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -220,7 +220,7 @@ int inet_listen(struct socket *sock, int backlog) * because the socket was in TCP_LISTEN state previously but * was shutdown() rather than close(). */ - tcp_fastopen =3D sock_net(sk)->ipv4.sysctl_tcp_fastopen; + tcp_fastopen =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen); if ((tcp_fastopen & TFO_SERVER_WO_SOCKOPT1) && (tcp_fastopen & TFO_SERVER_ENABLE) && !inet_csk(sk)->icsk_accept_queue.fastopenq.max_qlen) { diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index f853f34dfb79..1abdb8712655 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1159,7 +1159,8 @@ static int tcp_sendmsg_fastopen(struct sock *sk, stru= ct msghdr *msg, struct sockaddr *uaddr =3D msg->msg_name; int err, flags; =20 - if (!(sock_net(sk)->ipv4.sysctl_tcp_fastopen & TFO_CLIENT_ENABLE) || + if (!(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & + TFO_CLIENT_ENABLE) || (uaddr && msg->msg_namelen >=3D sizeof(uaddr->sa_family) && uaddr->sa_family =3D=3D AF_UNSPEC)) return -EOPNOTSUPP; @@ -3626,7 +3627,8 @@ static int do_tcp_setsockopt(struct sock *sk, int lev= el, int optname, case TCP_FASTOPEN_CONNECT: if (val > 1 || val < 0) { err =3D -EINVAL; - } else if (net->ipv4.sysctl_tcp_fastopen & TFO_CLIENT_ENABLE) { + } else if (READ_ONCE(net->ipv4.sysctl_tcp_fastopen) & + TFO_CLIENT_ENABLE) { if (sk->sk_state =3D=3D TCP_CLOSE) tp->fastopen_connect =3D val; else diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 59412d6354a0..936544a4753e 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -338,7 +338,7 @@ static bool tcp_fastopen_no_cookie(const struct sock *s= k, const struct dst_entry *dst, int flag) { - return (sock_net(sk)->ipv4.sysctl_tcp_fastopen & flag) || + return (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & flag) || tcp_sk(sk)->fastopen_no_cookie || (dst && dst_metric(dst, RTAX_FASTOPEN_NO_COOKIE)); } @@ -353,7 +353,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct s= k_buff *skb, const struct dst_entry *dst) { bool syn_data =3D TCP_SKB_CB(skb)->end_seq !=3D TCP_SKB_CB(skb)->seq + 1; - int tcp_fastopen =3D sock_net(sk)->ipv4.sysctl_tcp_fastopen; + int tcp_fastopen =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen); struct tcp_fastopen_cookie valid_foc =3D { .len =3D -1 }; struct sock *child; int ret =3D 0; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76D96C04A68 for ; Wed, 27 Jul 2022 17:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232680AbiG0RLt (ORCPT ); Wed, 27 Jul 2022 13:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238191AbiG0RLT (ORCPT ); Wed, 27 Jul 2022 13:11:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAD0374DDB; Wed, 27 Jul 2022 09:41:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 90D14601C3; Wed, 27 Jul 2022 16:41:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94DB3C433D7; Wed, 27 Jul 2022 16:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940091; bh=bU2/xVGvLwc56ejQkjV+akjbrJs3moE20KEfmebPPyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z6O+Aq1BZK7rj4lFS4YxwN6H2vv0R0u09UQW1joLBAdITJcsM2LElYn5n/CIaS0lc 9aoVBQssq1Bx6ON/e1KYwJi4apto6YxxWlPtsuQTPCAdqMzW2vUmjTzZ9PZ6Jeb84q v+QMv4uyzyTs2yO/ojdkw46lq7Ysp2i2YvqAEVKk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 100/201] tcp: Fix data-races around sysctl_tcp_fastopen_blackhole_timeout. Date: Wed, 27 Jul 2022 18:10:04 +0200 Message-Id: <20220727161031.886161020@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 021266ec640c7a4527e6cd4b7349a512b351de1d ] While reading sysctl_tcp_fastopen_blackhole_timeout, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: cf1ef3f0719b ("net/tcp_fastopen: Disable active side TFO in certain = scenarios") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_fastopen.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 936544a4753e..6e0a8ef5e816 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -495,7 +495,7 @@ void tcp_fastopen_active_disable(struct sock *sk) { struct net *net =3D sock_net(sk); =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_fastopen_blackhole_timeout) + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen_blackhole_timeout)) return; =20 /* Paired with READ_ONCE() in tcp_fastopen_active_should_disable() */ @@ -516,7 +516,8 @@ void tcp_fastopen_active_disable(struct sock *sk) */ bool tcp_fastopen_active_should_disable(struct sock *sk) { - unsigned int tfo_bh_timeout =3D sock_net(sk)->ipv4.sysctl_tcp_fastopen_bl= ackhole_timeout; + unsigned int tfo_bh_timeout =3D + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen_blackhole_timeout); unsigned long timeout; int tfo_da_times; int multiplier; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5018C04A68 for ; Wed, 27 Jul 2022 17:12:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232800AbiG0RMZ (ORCPT ); Wed, 27 Jul 2022 13:12:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241325AbiG0RLp (ORCPT ); Wed, 27 Jul 2022 13:11:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0580D5141D; Wed, 27 Jul 2022 09:41:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EEAAAB821C5; Wed, 27 Jul 2022 16:41:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 551A2C433C1; Wed, 27 Jul 2022 16:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940093; bh=xcRkLHyCPVW45pzjC+BD+ePo1H07buCXLbvYrUCnzl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zmSMAQ2DQF3KXBOLaIAfUmngbOGgz3wY615vG7ByKzKjNxbdtQFYhfmJSwKQMwk9a 5TSK0RGdjEDCvJolOEcdiTwSHXsKz/SQxKUN9kzkyg9tNPm6Z9ss2b5GDj94o8Um3+ ELlgIzKJvQK/mC0Brtqyn2AcM7fnRFMpNolWHqgY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Przemyslaw Patynowski , Jesse Brandeburg , Konrad Jankowski , Tony Nguyen , Sasha Levin Subject: [PATCH 5.15 101/201] iavf: Fix handling of dummy receive descriptors Date: Wed, 27 Jul 2022 18:10:05 +0200 Message-Id: <20220727161031.924437707@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Przemyslaw Patynowski [ Upstream commit a9f49e0060301a9bfebeca76739158d0cf91cdf6 ] Fix memory leak caused by not handling dummy receive descriptor properly. iavf_get_rx_buffer now sets the rx_buffer return value for dummy receive descriptors. Without this patch, when the hardware writes a dummy descriptor, iavf would not free the page allocated for the previous receive buffer. This is an unlikely event but can still happen. [Jesse: massaged commit message] Fixes: efa14c398582 ("iavf: allow null RX descriptors") Signed-off-by: Przemyslaw Patynowski Signed-off-by: Jesse Brandeburg Tested-by: Konrad Jankowski Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/intel/iavf/iavf_txrx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/iavf/iavf_txrx.c b/drivers/net/ethe= rnet/intel/iavf/iavf_txrx.c index 3525eab8e9f9..5448ed0e0357 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_txrx.c +++ b/drivers/net/ethernet/intel/iavf/iavf_txrx.c @@ -1250,11 +1250,10 @@ static struct iavf_rx_buffer *iavf_get_rx_buffer(st= ruct iavf_ring *rx_ring, { struct iavf_rx_buffer *rx_buffer; =20 - if (!size) - return NULL; - rx_buffer =3D &rx_ring->rx_bi[rx_ring->next_to_clean]; prefetchw(rx_buffer->page); + if (!size) + return rx_buffer; =20 /* we are reusing so sync this buffer for CPU use */ dma_sync_single_range_for_cpu(rx_ring->dev, --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C869C04A68 for ; Wed, 27 Jul 2022 17:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236018AbiG0RMf (ORCPT ); Wed, 27 Jul 2022 13:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241566AbiG0RLv (ORCPT ); Wed, 27 Jul 2022 13:11:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91E175073D; Wed, 27 Jul 2022 09:41:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B5CF6B821D5; Wed, 27 Jul 2022 16:41:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13399C433B5; Wed, 27 Jul 2022 16:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940096; bh=75Zf2TJhZZOBtHD1hLzRORjmMYG60PXKLcJYV2d+7+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A1rYxXPe4gIkGO5c+y3XYetCWAHONNcUzYl7YymWTtiJXpdv4JgKgy1sCIOBPAVOS yciK9vK86wlvOkiznRmHqmwPmtlmBacDxG+aPGSSEO2ZzSdxoglpHWljkuFUPLR2bN ZUvJ6S887gEwdWO9wvJ3AWix6cEjCOkpaB1GQpq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Gregory CLEMENT , Sasha Levin Subject: [PATCH 5.15 102/201] pinctrl: armada-37xx: Use temporary variable for struct device Date: Wed, 27 Jul 2022 18:10:06 +0200 Message-Id: <20220727161031.966419418@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko [ Upstream commit 50cf2ed284e49028a885aa56c3ea50714c635879 ] Use temporary variable for struct device to make code neater. Signed-off-by: Andy Shevchenko Reviewed-by: Gregory CLEMENT Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 56 +++++++++------------ 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/= mvebu/pinctrl-armada-37xx.c index 85a0052bb0e6..e1f76b4ddf23 100644 --- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c @@ -341,12 +341,12 @@ static int armada_37xx_pmx_set_by_name(struct pinctrl= _dev *pctldev, struct armada_37xx_pin_group *grp) { struct armada_37xx_pinctrl *info =3D pinctrl_dev_get_drvdata(pctldev); + struct device *dev =3D info->dev; unsigned int reg =3D SELECTION; unsigned int mask =3D grp->reg_mask; int func, val; =20 - dev_dbg(info->dev, "enable function %s group %s\n", - name, grp->name); + dev_dbg(dev, "enable function %s group %s\n", name, grp->name); =20 func =3D match_string(grp->funcs, NB_FUNCS, name); if (func < 0) @@ -722,16 +722,16 @@ static unsigned int armada_37xx_irq_startup(struct ir= q_data *d) static int armada_37xx_irqchip_register(struct platform_device *pdev, struct armada_37xx_pinctrl *info) { - struct device_node *np =3D info->dev->of_node; struct gpio_chip *gc =3D &info->gpio_chip; struct irq_chip *irqchip =3D &info->irq_chip; struct gpio_irq_chip *girq =3D &gc->irq; struct device *dev =3D &pdev->dev; + struct device_node *np; struct resource res; int ret =3D -ENODEV, i, nr_irq_parent; =20 /* Check if we have at least one gpio-controller child node */ - for_each_child_of_node(info->dev->of_node, np) { + for_each_child_of_node(dev->of_node, np) { if (of_property_read_bool(np, "gpio-controller")) { ret =3D 0; break; @@ -750,12 +750,12 @@ static int armada_37xx_irqchip_register(struct platfo= rm_device *pdev, return 0; } =20 - if (of_address_to_resource(info->dev->of_node, 1, &res)) { + if (of_address_to_resource(dev->of_node, 1, &res)) { dev_err(dev, "cannot find IO resource\n"); return -ENOENT; } =20 - info->base =3D devm_ioremap_resource(info->dev, &res); + info->base =3D devm_ioremap_resource(dev, &res); if (IS_ERR(info->base)) return PTR_ERR(info->base); =20 @@ -774,8 +774,7 @@ static int armada_37xx_irqchip_register(struct platform= _device *pdev, * the chained irq with all of them. */ girq->num_parents =3D nr_irq_parent; - girq->parents =3D devm_kcalloc(&pdev->dev, nr_irq_parent, - sizeof(*girq->parents), GFP_KERNEL); + girq->parents =3D devm_kcalloc(dev, nr_irq_parent, sizeof(*girq->parents)= , GFP_KERNEL); if (!girq->parents) return -ENOMEM; for (i =3D 0; i < nr_irq_parent; i++) { @@ -794,11 +793,12 @@ static int armada_37xx_irqchip_register(struct platfo= rm_device *pdev, static int armada_37xx_gpiochip_register(struct platform_device *pdev, struct armada_37xx_pinctrl *info) { + struct device *dev =3D &pdev->dev; struct device_node *np; struct gpio_chip *gc; int ret =3D -ENODEV; =20 - for_each_child_of_node(info->dev->of_node, np) { + for_each_child_of_node(dev->of_node, np) { if (of_find_property(np, "gpio-controller", NULL)) { ret =3D 0; break; @@ -811,19 +811,16 @@ static int armada_37xx_gpiochip_register(struct platf= orm_device *pdev, =20 gc =3D &info->gpio_chip; gc->ngpio =3D info->data->nr_pins; - gc->parent =3D &pdev->dev; + gc->parent =3D dev; gc->base =3D -1; gc->of_node =3D np; gc->label =3D info->data->name; =20 ret =3D armada_37xx_irqchip_register(pdev, info); - if (ret) - return ret; - ret =3D devm_gpiochip_add_data(&pdev->dev, gc, info); if (ret) return ret; =20 - return 0; + return devm_gpiochip_add_data(dev, gc, info); } =20 /** @@ -874,13 +871,13 @@ static int armada_37xx_add_function(struct armada_37x= x_pmx_func *funcs, static int armada_37xx_fill_group(struct armada_37xx_pinctrl *info) { int n, num =3D 0, funcsize =3D info->data->nr_pins; + struct device *dev =3D info->dev; =20 for (n =3D 0; n < info->ngroups; n++) { struct armada_37xx_pin_group *grp =3D &info->groups[n]; int i, j, f; =20 - grp->pins =3D devm_kcalloc(info->dev, - grp->npins + grp->extra_npins, + grp->pins =3D devm_kcalloc(dev, grp->npins + grp->extra_npins, sizeof(*grp->pins), GFP_KERNEL); if (!grp->pins) @@ -898,8 +895,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pi= nctrl *info) ret =3D armada_37xx_add_function(info->funcs, &funcsize, grp->funcs[f]); if (ret =3D=3D -EOVERFLOW) - dev_err(info->dev, - "More functions than pins(%d)\n", + dev_err(dev, "More functions than pins(%d)\n", info->data->nr_pins); if (ret < 0) continue; @@ -925,6 +921,7 @@ static int armada_37xx_fill_group(struct armada_37xx_pi= nctrl *info) static int armada_37xx_fill_func(struct armada_37xx_pinctrl *info) { struct armada_37xx_pmx_func *funcs =3D info->funcs; + struct device *dev =3D info->dev; int n; =20 for (n =3D 0; n < info->nfuncs; n++) { @@ -932,8 +929,7 @@ static int armada_37xx_fill_func(struct armada_37xx_pin= ctrl *info) const char **groups; int g; =20 - funcs[n].groups =3D devm_kcalloc(info->dev, - funcs[n].ngroups, + funcs[n].groups =3D devm_kcalloc(dev, funcs[n].ngroups, sizeof(*(funcs[n].groups)), GFP_KERNEL); if (!funcs[n].groups) @@ -962,6 +958,7 @@ static int armada_37xx_pinctrl_register(struct platform= _device *pdev, const struct armada_37xx_pin_data *pin_data =3D info->data; struct pinctrl_desc *ctrldesc =3D &info->pctl; struct pinctrl_pin_desc *pindesc, *pdesc; + struct device *dev =3D &pdev->dev; int pin, ret; =20 info->groups =3D pin_data->groups; @@ -973,9 +970,7 @@ static int armada_37xx_pinctrl_register(struct platform= _device *pdev, ctrldesc->pmxops =3D &armada_37xx_pmx_ops; ctrldesc->confops =3D &armada_37xx_pinconf_ops; =20 - pindesc =3D devm_kcalloc(&pdev->dev, - pin_data->nr_pins, sizeof(*pindesc), - GFP_KERNEL); + pindesc =3D devm_kcalloc(dev, pin_data->nr_pins, sizeof(*pindesc), GFP_KE= RNEL); if (!pindesc) return -ENOMEM; =20 @@ -994,14 +989,10 @@ static int armada_37xx_pinctrl_register(struct platfo= rm_device *pdev, * we allocate functions for number of pins and hope there are * fewer unique functions than pins available */ - info->funcs =3D devm_kcalloc(&pdev->dev, - pin_data->nr_pins, - sizeof(struct armada_37xx_pmx_func), - GFP_KERNEL); + info->funcs =3D devm_kcalloc(dev, pin_data->nr_pins, sizeof(*info->funcs)= , GFP_KERNEL); if (!info->funcs) return -ENOMEM; =20 - ret =3D armada_37xx_fill_group(info); if (ret) return ret; @@ -1010,9 +1001,9 @@ static int armada_37xx_pinctrl_register(struct platfo= rm_device *pdev, if (ret) return ret; =20 - info->pctl_dev =3D devm_pinctrl_register(&pdev->dev, ctrldesc, info); + info->pctl_dev =3D devm_pinctrl_register(dev, ctrldesc, info); if (IS_ERR(info->pctl_dev)) { - dev_err(&pdev->dev, "could not register pinctrl driver\n"); + dev_err(dev, "could not register pinctrl driver\n"); return PTR_ERR(info->pctl_dev); } =20 @@ -1143,8 +1134,7 @@ static int __init armada_37xx_pinctrl_probe(struct pl= atform_device *pdev) struct regmap *regmap; int ret; =20 - info =3D devm_kzalloc(dev, sizeof(struct armada_37xx_pinctrl), - GFP_KERNEL); + info =3D devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); if (!info) return -ENOMEM; =20 @@ -1152,7 +1142,7 @@ static int __init armada_37xx_pinctrl_probe(struct pl= atform_device *pdev) =20 regmap =3D syscon_node_to_regmap(np); if (IS_ERR(regmap)) { - dev_err(&pdev->dev, "cannot get regmap\n"); + dev_err(dev, "cannot get regmap\n"); return PTR_ERR(regmap); } info->regmap =3D regmap; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E82FFC19F28 for ; Wed, 27 Jul 2022 17:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241759AbiG0RSb (ORCPT ); Wed, 27 Jul 2022 13:18:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241706AbiG0RRz (ORCPT ); Wed, 27 Jul 2022 13:17:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA3A07968F; Wed, 27 Jul 2022 09:43:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F3349B821C5; Wed, 27 Jul 2022 16:43:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19929C433C1; Wed, 27 Jul 2022 16:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940211; bh=VYoj6IEjQrE/YjSKAbjbTBde62Fy24vqoUFL94YJ+Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NGa5Klau1Pc/V1i+H0k7rRK9jdRvG8piGoZOhk1S18J8/Gi5d2/ZAr8EalGYrpexO Rvjszn+wjWkjnetngryaM452tfs9bzV4+oAHcbirMw1dgOyMW969FbtYnWMmpHC5K+ bJOQJQy9IZ1tqnrgKxbDcUe0sS59wCVDZ3DrX2LM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Gregory CLEMENT , Sasha Levin Subject: [PATCH 5.15 103/201] pinctrl: armada-37xx: Make use of the devm_platform_ioremap_resource() Date: Wed, 27 Jul 2022 18:10:07 +0200 Message-Id: <20220727161032.016701897@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko [ Upstream commit 49bdef501728acbfadc7eeafafb4f6c3fea415eb ] Use the devm_platform_ioremap_resource() helper instead of calling of_address_to_resource() and devm_ioremap_resource() separately. Signed-off-by: Andy Shevchenko Reviewed-by: Gregory CLEMENT Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/= mvebu/pinctrl-armada-37xx.c index e1f76b4ddf23..40bcf05123eb 100644 --- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c @@ -727,7 +727,6 @@ static int armada_37xx_irqchip_register(struct platform= _device *pdev, struct gpio_irq_chip *girq =3D &gc->irq; struct device *dev =3D &pdev->dev; struct device_node *np; - struct resource res; int ret =3D -ENODEV, i, nr_irq_parent; =20 /* Check if we have at least one gpio-controller child node */ @@ -750,12 +749,7 @@ static int armada_37xx_irqchip_register(struct platfor= m_device *pdev, return 0; } =20 - if (of_address_to_resource(dev->of_node, 1, &res)) { - dev_err(dev, "cannot find IO resource\n"); - return -ENOENT; - } - - info->base =3D devm_ioremap_resource(dev, &res); + info->base =3D devm_platform_ioremap_resource(pdev, 1); if (IS_ERR(info->base)) return PTR_ERR(info->base); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43A18C04A68 for ; Wed, 27 Jul 2022 17:13:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241449AbiG0RNf (ORCPT ); Wed, 27 Jul 2022 13:13:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbiG0RMq (ORCPT ); Wed, 27 Jul 2022 13:12:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E1A753BD; Wed, 27 Jul 2022 09:42:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 456CDB821D5; Wed, 27 Jul 2022 16:42:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FD9FC433C1; Wed, 27 Jul 2022 16:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940119; bh=BXg5fLLfCrboKcDhCRE6/09nN66VrHApWnu3zne7LGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JKEUadedFeR/cSTp3aoKAhDGVlJ61gorXWN3PmWrzIt+CsUh8I2m8dhNBDfno5KWj 7wTSr8ZDFAh7zzbYAk+mpCT3XhhjrBdo0Dbwa84uqxPhFkhdRwWEptGxjhoepzmEGi L7IzTZzomZzyszCe9qrUaLs87MtE10GJuc7MXZdM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Gregory CLEMENT , Sasha Levin Subject: [PATCH 5.15 104/201] pinctrl: armada-37xx: Convert to use dev_err_probe() Date: Wed, 27 Jul 2022 18:10:08 +0200 Message-Id: <20220727161032.059592834@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andy Shevchenko [ Upstream commit 06cb10ea0cd5c5f4db9627a33ab47fec32cb5960 ] It's fine to call dev_err_probe() in ->probe() when error code is known. Convert the driver to use dev_err_probe(). Signed-off-by: Andy Shevchenko Reviewed-by: Gregory CLEMENT Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/= mvebu/pinctrl-armada-37xx.c index 40bcf05123eb..7d0d2771a9ac 100644 --- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c @@ -736,10 +736,8 @@ static int armada_37xx_irqchip_register(struct platfor= m_device *pdev, break; } } - if (ret) { - dev_err(dev, "no gpio-controller child node\n"); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "no gpio-controller child node\n"); =20 nr_irq_parent =3D of_irq_count(np); spin_lock_init(&info->irq_lock); @@ -996,10 +994,8 @@ static int armada_37xx_pinctrl_register(struct platfor= m_device *pdev, return ret; =20 info->pctl_dev =3D devm_pinctrl_register(dev, ctrldesc, info); - if (IS_ERR(info->pctl_dev)) { - dev_err(dev, "could not register pinctrl driver\n"); - return PTR_ERR(info->pctl_dev); - } + if (IS_ERR(info->pctl_dev)) + return dev_err_probe(dev, PTR_ERR(info->pctl_dev), "could not register p= inctrl driver\n"); =20 return 0; } @@ -1135,10 +1131,8 @@ static int __init armada_37xx_pinctrl_probe(struct p= latform_device *pdev) info->dev =3D dev; =20 regmap =3D syscon_node_to_regmap(np); - if (IS_ERR(regmap)) { - dev_err(dev, "cannot get regmap\n"); - return PTR_ERR(regmap); - } + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), "cannot get regmap\n"); info->regmap =3D regmap; =20 info->data =3D of_device_get_match_data(dev); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 799A0C04A68 for ; Wed, 27 Jul 2022 17:15:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238226AbiG0RPU (ORCPT ); Wed, 27 Jul 2022 13:15:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241663AbiG0ROK (ORCPT ); Wed, 27 Jul 2022 13:14:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6A5B76EB9; Wed, 27 Jul 2022 09:42:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 18635614EA; Wed, 27 Jul 2022 16:42:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 277A3C433D6; Wed, 27 Jul 2022 16:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940149; bh=z2V8vFHMnhOnE4/gebZpZ4UaFOeyJaDeG+40vnJokD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P/q7eqcS+cMPv34Oa8SOLqWi5ld6L7CCDJMnp1ryup92LAgPZdZfqQ2iyMphfssVV 3XtEGFoxtXoGtutjh0xvdgJYSJQvftHVVtUaW6df18n4kh3Kh+/bjxHHbvWL3llTsd hlcFrBAPy06BYwVH+7TdKYC/MRMuCka7j5beJUXw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , Linus Walleij , Sasha Levin Subject: [PATCH 5.15 105/201] pinctrl: armada-37xx: use raw spinlocks for regmap to avoid invalid wait context Date: Wed, 27 Jul 2022 18:10:09 +0200 Message-Id: <20220727161032.096638768@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Vladimir Oltean [ Upstream commit 4546760619cfa9b718fe2059ceb07101cf9ff61e ] The irqchip->irq_set_type method is called by __irq_set_trigger() under the desc->lock raw spinlock. The armada-37xx implementation, armada_37xx_irq_set_type(), uses an MMIO regmap created by of_syscon_register(), which uses plain spinlocks (the kind that are sleepable on RT). Therefore, this is an invalid locking scheme for which we get a kernel splat stating just that ("[ BUG: Invalid wait context ]"), because the context in which the plain spinlock may sleep is atomic due to the raw spinlock. We need to go raw spinlocks all the way. Make this driver create its own MMIO regmap, with use_raw_spinlock=3Dtrue, and stop relying on syscon to provide it. This patch depends on commit 67021f25d952 ("regmap: teach regmap to use raw spinlocks if requested in the config"). Cc: # 5.15+ Fixes: 2f227605394b ("pinctrl: armada-37xx: Add irqchip support") Signed-off-by: Vladimir Oltean Link: https://lore.kernel.org/r/20220716233745.1704677-3-vladimir.oltean@nx= p.com Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 27 ++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/= mvebu/pinctrl-armada-37xx.c index 7d0d2771a9ac..7338bc353347 100644 --- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c @@ -1116,25 +1116,40 @@ static const struct of_device_id armada_37xx_pinctr= l_of_match[] =3D { { }, }; =20 +static const struct regmap_config armada_37xx_pinctrl_regmap_config =3D { + .reg_bits =3D 32, + .val_bits =3D 32, + .reg_stride =3D 4, + .use_raw_spinlock =3D true, +}; + static int __init armada_37xx_pinctrl_probe(struct platform_device *pdev) { struct armada_37xx_pinctrl *info; struct device *dev =3D &pdev->dev; - struct device_node *np =3D dev->of_node; struct regmap *regmap; + void __iomem *base; int ret; =20 + base =3D devm_platform_get_and_ioremap_resource(pdev, 0, NULL); + if (IS_ERR(base)) { + dev_err(dev, "failed to ioremap base address: %pe\n", base); + return PTR_ERR(base); + } + + regmap =3D devm_regmap_init_mmio(dev, base, + &armada_37xx_pinctrl_regmap_config); + if (IS_ERR(regmap)) { + dev_err(dev, "failed to create regmap: %pe\n", regmap); + return PTR_ERR(regmap); + } + info =3D devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); if (!info) return -ENOMEM; =20 info->dev =3D dev; - - regmap =3D syscon_node_to_regmap(np); - if (IS_ERR(regmap)) - return dev_err_probe(dev, PTR_ERR(regmap), "cannot get regmap\n"); info->regmap =3D regmap; - info->data =3D of_device_get_match_data(dev); =20 ret =3D armada_37xx_pinctrl_register(pdev, info); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B6E5C04A68 for ; Wed, 27 Jul 2022 17:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232036AbiG0RQ7 (ORCPT ); Wed, 27 Jul 2022 13:16:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241671AbiG0RQK (ORCPT ); Wed, 27 Jul 2022 13:16:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 158CE7858C; Wed, 27 Jul 2022 09:43:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 529AFB821D6; Wed, 27 Jul 2022 16:43:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4256C433D7; Wed, 27 Jul 2022 16:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940180; bh=VS7Kwf68vVLhN3/JM0Y6LtduQnkhHZwpCEeasFfSBQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4u16NrhH70Wmoc//44IrrAL1bGnEWuuccqKFX+SRD6gOD8i+s/g+OKQLO/bKHZSH T0xs2pwgJEb1YCV1cqSFBGzNeeqcx8cHs9evlgr/NrnQjObyDLxeOi3ZZ7BQTlKMTz PsAXkSR1nopGqfbFToRzBEMskONICtcD3AaQNXiU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dawid Lukwinski , Jan Sokolowski , Konrad Jankowski , Tony Nguyen , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 106/201] i40e: Fix erroneous adapter reinitialization during recovery process Date: Wed, 27 Jul 2022 18:10:10 +0200 Message-Id: <20220727161032.148382227@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dawid Lukwinski [ Upstream commit f838a63369818faadec4ad1736cfbd20ab5da00e ] Fix an issue when driver incorrectly detects state of recovery process and erroneously reinitializes interrupts, which results in a kernel error and call trace message. The issue was caused by a combination of two factors: 1. Assuming the EMP reset issued after completing firmware recovery means the whole recovery process is complete. 2. Erroneous reinitialization of interrupt vector after detecting the above mentioned EMP reset. Fixes (1) by changing how recovery state change is detected and (2) by adjusting the conditional expression to ensure using proper interrupt reinitialization method, depending on the situation. Fixes: 4ff0ee1af016 ("i40e: Introduce recovery mode support") Signed-off-by: Dawid Lukwinski Signed-off-by: Jan Sokolowski Tested-by: Konrad Jankowski Signed-off-by: Tony Nguyen Link: https://lore.kernel.org/r/20220715214542.2968762-1-anthony.l.nguyen@i= ntel.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/intel/i40e/i40e_main.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethe= rnet/intel/i40e/i40e_main.c index 02594e4d6258..c801b128e5b2 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -10631,7 +10631,7 @@ static int i40e_reset(struct i40e_pf *pf) **/ static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquir= ed) { - int old_recovery_mode_bit =3D test_bit(__I40E_RECOVERY_MODE, pf->state); + const bool is_recovery_mode_reported =3D i40e_check_recovery_mode(pf); struct i40e_vsi *vsi =3D pf->vsi[pf->lan_vsi]; struct i40e_hw *hw =3D &pf->hw; i40e_status ret; @@ -10639,13 +10639,11 @@ static void i40e_rebuild(struct i40e_pf *pf, bool= reinit, bool lock_acquired) int v; =20 if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) && - i40e_check_recovery_mode(pf)) { + is_recovery_mode_reported) i40e_set_ethtool_ops(pf->vsi[pf->lan_vsi]->netdev); - } =20 if (test_bit(__I40E_DOWN, pf->state) && - !test_bit(__I40E_RECOVERY_MODE, pf->state) && - !old_recovery_mode_bit) + !test_bit(__I40E_RECOVERY_MODE, pf->state)) goto clear_recovery; dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); =20 @@ -10672,13 +10670,12 @@ static void i40e_rebuild(struct i40e_pf *pf, bool= reinit, bool lock_acquired) * accordingly with regard to resources initialization * and deinitialization */ - if (test_bit(__I40E_RECOVERY_MODE, pf->state) || - old_recovery_mode_bit) { + if (test_bit(__I40E_RECOVERY_MODE, pf->state)) { if (i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities)) goto end_unlock; =20 - if (test_bit(__I40E_RECOVERY_MODE, pf->state)) { + if (is_recovery_mode_reported) { /* we're staying in recovery mode so we'll reinitialize * misc vector here */ --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6D6BC04A68 for ; Wed, 27 Jul 2022 17:17:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbiG0RRk (ORCPT ); Wed, 27 Jul 2022 13:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241656AbiG0RQr (ORCPT ); Wed, 27 Jul 2022 13:16:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E625C95B; Wed, 27 Jul 2022 09:43:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E82FB60D3B; Wed, 27 Jul 2022 16:43:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0053FC433D6; Wed, 27 Jul 2022 16:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940194; bh=c9s70STEPcpvDZalC6QpagPkoFuKsN/joFPCxLWbenc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hbh2bz42nt4zgCZunMB+YditNjuU45rZg0FT/mloBhGtFpEuP1T8HI5NdHud8craC csSCTOyz3OoYFFmHDAfaAEXSp/K1Q1XR6qC+po2HVtSJ2Srciuy9NkdPJBEIE+NhcJ Ql5+sCfcdfngftM7gfnjoszsGGPtiRlx5yADiLYQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Piotr Skajewski , Marek Szlosek , Tony Nguyen , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 107/201] ixgbe: Add locking to prevent panic when setting sriov_numvfs to zero Date: Wed, 27 Jul 2022 18:10:11 +0200 Message-Id: <20220727161032.187952434@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Piotr Skajewski [ Upstream commit 1e53834ce541d4fe271cdcca7703e50be0a44f8a ] It is possible to disable VFs while the PF driver is processing requests from the VF driver. This can result in a panic. BUG: unable to handle kernel paging request at 000000000000106c PGD 0 P4D 0 Oops: 0000 [#1] SMP NOPTI CPU: 8 PID: 0 Comm: swapper/8 Kdump: loaded Tainted: G I --------- - Hardware name: Dell Inc. PowerEdge R740/06WXJT, BIOS 2.8.2 08/27/2020 RIP: 0010:ixgbe_msg_task+0x4c8/0x1690 [ixgbe] Code: 00 00 48 8d 04 40 48 c1 e0 05 89 7c 24 24 89 fd 48 89 44 24 10 83 ff 01 0f 84 b8 04 00 00 4c 8b 64 24 10 4d 03 a5 48 22 00 00 <41> 80 7c 24 4c 00 0f 84 8a 03 00 00 0f b7 c7 83 f8 08 0f 84 8f 0a RSP: 0018:ffffb337869f8df8 EFLAGS: 00010002 RAX: 0000000000001020 RBX: 0000000000000000 RCX: 000000000000002b RDX: 0000000000000002 RSI: 0000000000000008 RDI: 0000000000000006 RBP: 0000000000000006 R08: 0000000000000002 R09: 0000000000029780 R10: 00006957d8f42832 R11: 0000000000000000 R12: 0000000000001020 R13: ffff8a00e8978ac0 R14: 000000000000002b R15: ffff8a00e8979c80 FS: 0000000000000000(0000) GS:ffff8a07dfd00000(0000) knlGS:00000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000000000106c CR3: 0000000063e10004 CR4: 00000000007726e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: ? ttwu_do_wakeup+0x19/0x140 ? try_to_wake_up+0x1cd/0x550 ? ixgbevf_update_xcast_mode+0x71/0xc0 [ixgbevf] ixgbe_msix_other+0x17e/0x310 [ixgbe] __handle_irq_event_percpu+0x40/0x180 handle_irq_event_percpu+0x30/0x80 handle_irq_event+0x36/0x53 handle_edge_irq+0x82/0x190 handle_irq+0x1c/0x30 do_IRQ+0x49/0xd0 common_interrupt+0xf/0xf This can be eventually be reproduced with the following script: while : do echo 63 > /sys/class/net//device/sriov_numvfs sleep 1 echo 0 > /sys/class/net//device/sriov_numvfs sleep 1 done Add lock when disabling SR-IOV to prevent process VF mailbox communication. Fixes: d773d1310625 ("ixgbe: Fix memory leak when SR-IOV VFs are direct ass= igned") Signed-off-by: Piotr Skajewski Tested-by: Marek Szlosek Signed-off-by: Tony Nguyen Link: https://lore.kernel.org/r/20220715214456.2968711-1-anthony.l.nguyen@i= ntel.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 1 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 3 +++ drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h b/drivers/net/etherne= t/intel/ixgbe/ixgbe.h index a604552fa634..c375a5d54b40 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h @@ -770,6 +770,7 @@ struct ixgbe_adapter { #ifdef CONFIG_IXGBE_IPSEC struct ixgbe_ipsec *ipsec; #endif /* CONFIG_IXGBE_IPSEC */ + spinlock_t vfs_lock; }; =20 static inline u8 ixgbe_max_rss_indices(struct ixgbe_adapter *adapter) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/et= hernet/intel/ixgbe/ixgbe_main.c index 750b02bb2fdc..8cb20af51ecd 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -6397,6 +6397,9 @@ static int ixgbe_sw_init(struct ixgbe_adapter *adapte= r, /* n-tuple support exists, always init our spinlock */ spin_lock_init(&adapter->fdir_perfect_lock); =20 + /* init spinlock to avoid concurrency of VF resources */ + spin_lock_init(&adapter->vfs_lock); + #ifdef CONFIG_IXGBE_DCB ixgbe_init_dcb(adapter); #endif diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/e= thernet/intel/ixgbe/ixgbe_sriov.c index aaebdae8b5ff..0078ae592616 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c @@ -204,10 +204,13 @@ void ixgbe_enable_sriov(struct ixgbe_adapter *adapter= , unsigned int max_vfs) int ixgbe_disable_sriov(struct ixgbe_adapter *adapter) { unsigned int num_vfs =3D adapter->num_vfs, vf; + unsigned long flags; int rss; =20 + spin_lock_irqsave(&adapter->vfs_lock, flags); /* set num VFs to 0 to prevent access to vfinfo */ adapter->num_vfs =3D 0; + spin_unlock_irqrestore(&adapter->vfs_lock, flags); =20 /* put the reference to all of the vf devices */ for (vf =3D 0; vf < num_vfs; ++vf) { @@ -1305,8 +1308,10 @@ static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapt= er *adapter, u32 vf) void ixgbe_msg_task(struct ixgbe_adapter *adapter) { struct ixgbe_hw *hw =3D &adapter->hw; + unsigned long flags; u32 vf; =20 + spin_lock_irqsave(&adapter->vfs_lock, flags); for (vf =3D 0; vf < adapter->num_vfs; vf++) { /* process any reset requests */ if (!ixgbe_check_for_rst(hw, vf)) @@ -1320,6 +1325,7 @@ void ixgbe_msg_task(struct ixgbe_adapter *adapter) if (!ixgbe_check_for_ack(hw, vf)) ixgbe_rcv_ack_from_vf(adapter, vf); } + spin_unlock_irqrestore(&adapter->vfs_lock, flags); } =20 void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11DB3C04A68 for ; Wed, 27 Jul 2022 17:18:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241756AbiG0RR5 (ORCPT ); Wed, 27 Jul 2022 13:17:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231937AbiG0RRN (ORCPT ); Wed, 27 Jul 2022 13:17:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EED4BCA; Wed, 27 Jul 2022 09:43:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 80C51B821C5; Wed, 27 Jul 2022 16:43:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C94C3C433D7; Wed, 27 Jul 2022 16:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940197; bh=reqS1FC7SNHKb5oM0t/Ti65oP22ffR5nY0X7/alNUK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gvOevyWHlkigzhZXUQCNVBU8qm+Y2kRnR3HSNnr26IWG7llpescgjpI0uYt5KnzJp F2Q8wx8HZ4DeHDu9zyK+eq68zhI4P5VdLFCVtKYLIQkdjfhpzuNY9MPoEhd1plUwcZ ql+NQjozZNIAHYqxoYSTIGmTnq2yBhy5BM2efJ7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wong Vee Khee , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 108/201] net: stmmac: remove redunctant disable xPCS EEE call Date: Wed, 27 Jul 2022 18:10:12 +0200 Message-Id: <20220727161032.236526995@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Wong Vee Khee [ Upstream commit da791bac104a3169b05b54270afe75daacba4641 ] Disable is done in stmmac_init_eee() on the event of MAC link down. Since setting enable/disable EEE via ethtool will eventually trigger a MAC down, removing this redunctant call in stmmac_ethtool.c to avoid calling xpcs_config_eee() twice. Fixes: d4aeaed80b0e ("net: stmmac: trigger PCS EEE to turn off on link down= ") Signed-off-by: Wong Vee Khee Link: https://lore.kernel.org/r/20220715122402.1017470-1-vee.khee.wong@linu= x.intel.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers= /net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 8f563b446d5c..dc31501fec8f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -800,14 +800,6 @@ static int stmmac_ethtool_op_set_eee(struct net_device= *dev, netdev_warn(priv->dev, "Setting EEE tx-lpi is not supported\n"); =20 - if (priv->hw->xpcs) { - ret =3D xpcs_config_eee(priv->hw->xpcs, - priv->plat->mult_fact_100ns, - edata->eee_enabled); - if (ret) - return ret; - } - if (!edata->eee_enabled) stmmac_disable_eee_mode(priv); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44A3DC04A68 for ; Wed, 27 Jul 2022 17:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239737AbiG0RSC (ORCPT ); Wed, 27 Jul 2022 13:18:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233394AbiG0RRN (ORCPT ); Wed, 27 Jul 2022 13:17:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BB7A78DD9; Wed, 27 Jul 2022 09:43:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9C152601C3; Wed, 27 Jul 2022 16:43:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3378C433C1; Wed, 27 Jul 2022 16:43:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940200; bh=eud4DlPytkXEZKbDVsexOqCQ7QIhHImI570wrqSzK54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsWSOJtVdYaRtjRMaEnOD9sEyakXXBDlRJ9IpQvgC1QFMr/I04hj654rTgzKREVil U1G/O9Zvjfl5EIOfONaCnD4/3L5ufx7ygDqaEpfqr8qfmWSPIQCstJoOqm93WY58fL y70AarN2zpgKoHCRmoanMYeTeRpDzIuPvo2i/V8k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Haibo Chen , Andy Shevchenko , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.15 109/201] gpio: pca953x: only use single read/write for No AI mode Date: Wed, 27 Jul 2022 18:10:13 +0200 Message-Id: <20220727161032.282415792@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Haibo Chen [ Upstream commit db8edaa09d7461ec08672a92a2eef63d5882bb79 ] For the device use NO AI mode(not support auto address increment), only use the single read/write when config the regmap. We meet issue on PCA9557PW on i.MX8QXP/DXL evk board, this device do not support AI mode, but when do the regmap sync, regmap will sync 3 byte data to register 1, logically this means write first data to register 1, write second data to register 2, write third data to register 3. But this device do not support AI mode, finally, these three data write only into register 1 one by one. the reault is the value of register 1 alway equal to the latest data, here is the third data, no operation happened on register 2 and register 3. This is not what we expect. Fixes: 49427232764d ("gpio: pca953x: Perform basic regmap conversion") Signed-off-by: Haibo Chen Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpio/gpio-pca953x.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 33683295a0bf..f334c8556a22 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -351,6 +351,9 @@ static const struct regmap_config pca953x_i2c_regmap = =3D { .reg_bits =3D 8, .val_bits =3D 8, =20 + .use_single_read =3D true, + .use_single_write =3D true, + .readable_reg =3D pca953x_readable_register, .writeable_reg =3D pca953x_writeable_register, .volatile_reg =3D pca953x_volatile_register, --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63961C04A68 for ; Wed, 27 Jul 2022 17:18:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238161AbiG0RSN (ORCPT ); Wed, 27 Jul 2022 13:18:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbiG0RRd (ORCPT ); Wed, 27 Jul 2022 13:17:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3D2D78DED; Wed, 27 Jul 2022 09:43:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3D7D7B821C6; Wed, 27 Jul 2022 16:43:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B570C433D6; Wed, 27 Jul 2022 16:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940202; bh=OUAQxsIyHhoQKpoTT2pFpB3kZknsg4snkdYeH8FRRwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/QMINbtrPXhR3jCwIODQer0XYcI1xrUdOT5EWwBmj1FImmNjfuyJ2OR5lVel2QhW hBrgtQG0DTG/Vk7Oizz41aHl4qXeEnsw9XO/8mROePgK5RLnt5orMN4gKp1EuDg6KH l+gk0Hrnck1mQzy0gxYHfxPSEQihbMpzrrzW8AMI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Haibo Chen , Andy Shevchenko , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.15 110/201] gpio: pca953x: use the correct range when do regmap sync Date: Wed, 27 Jul 2022 18:10:14 +0200 Message-Id: <20220727161032.319284427@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Haibo Chen [ Upstream commit 2abc17a93867dc816f0ed9d32021dda8078e7330 ] regmap will sync a range of registers, here use the correct range to make sure the sync do not touch other unexpected registers. Find on pca9557pw on imx8qxp/dxl evk board, this device support 8 pin, so only need one register(8 bits) to cover all the 8 pins's property setting. But when sync the output, we find it actually update two registers, output register and the following register. Fixes: b76574300504 ("gpio: pca953x: Restore registers after suspend/resume= cycle") Fixes: ec82d1eba346 ("gpio: pca953x: Zap ad-hoc reg_output cache") Fixes: 0f25fda840a9 ("gpio: pca953x: Zap ad-hoc reg_direction cache") Signed-off-by: Haibo Chen Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpio/gpio-pca953x.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index f334c8556a22..60b7616dd4aa 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -900,12 +900,12 @@ static int device_pca95xx_init(struct pca953x_chip *c= hip, u32 invert) int ret; =20 ret =3D regcache_sync_region(chip->regmap, chip->regs->output, - chip->regs->output + NBANK(chip)); + chip->regs->output + NBANK(chip) - 1); if (ret) goto out; =20 ret =3D regcache_sync_region(chip->regmap, chip->regs->direction, - chip->regs->direction + NBANK(chip)); + chip->regs->direction + NBANK(chip) - 1); if (ret) goto out; =20 @@ -1118,14 +1118,14 @@ static int pca953x_regcache_sync(struct device *dev) * sync these registers first and only then sync the rest. */ regaddr =3D pca953x_recalc_addr(chip, chip->regs->direction, 0); - ret =3D regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip)= ); + ret =3D regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip)= - 1); if (ret) { dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret); return ret; } =20 regaddr =3D pca953x_recalc_addr(chip, chip->regs->output, 0); - ret =3D regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip)= ); + ret =3D regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip)= - 1); if (ret) { dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret); return ret; @@ -1135,7 +1135,7 @@ static int pca953x_regcache_sync(struct device *dev) if (chip->driver_data & PCA_PCAL) { regaddr =3D pca953x_recalc_addr(chip, PCAL953X_IN_LATCH, 0); ret =3D regcache_sync_region(chip->regmap, regaddr, - regaddr + NBANK(chip)); + regaddr + NBANK(chip) - 1); if (ret) { dev_err(dev, "Failed to sync INT latch registers: %d\n", ret); @@ -1144,7 +1144,7 @@ static int pca953x_regcache_sync(struct device *dev) =20 regaddr =3D pca953x_recalc_addr(chip, PCAL953X_INT_MASK, 0); ret =3D regcache_sync_region(chip->regmap, regaddr, - regaddr + NBANK(chip)); + regaddr + NBANK(chip) - 1); if (ret) { dev_err(dev, "Failed to sync INT mask registers: %d\n", ret); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF856C04A68 for ; Wed, 27 Jul 2022 17:18:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241747AbiG0RSQ (ORCPT ); Wed, 27 Jul 2022 13:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236186AbiG0RRf (ORCPT ); Wed, 27 Jul 2022 13:17:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2D56167DD; Wed, 27 Jul 2022 09:43:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4CAE160D3B; Wed, 27 Jul 2022 16:43:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5904BC433D6; Wed, 27 Jul 2022 16:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940205; bh=BFJdDl0BVAGoHtb4izvkJFUW5xUjgpjEeVVSQdffYQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sElQG5aIgPMovYcRXuIC3ujk1ZkZRsAgyWcMJAHPluzSFSh3+XXojGGMeljEZGTlQ KDXBu1Zh8DeFD/kM8xBGuPyKtyyBApfCx13fNd+yG0p+JJTaz9EXrznVl7tP46E7i5 iS/haC5TBqvpYJUuamH1UK2c60hmTFAijGqfC8DE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Haibo Chen , Andy Shevchenko , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.15 111/201] gpio: pca953x: use the correct register address when regcache sync during init Date: Wed, 27 Jul 2022 18:10:15 +0200 Message-Id: <20220727161032.356154881@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Haibo Chen [ Upstream commit b8c768ccdd8338504fb78370747728d5002b1b5a ] For regcache_sync_region, we need to use pca953x_recalc_addr() to get the real register address. Fixes: ec82d1eba346 ("gpio: pca953x: Zap ad-hoc reg_output cache") Fixes: 0f25fda840a9 ("gpio: pca953x: Zap ad-hoc reg_direction cache") Signed-off-by: Haibo Chen Reviewed-by: Andy Shevchenko Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpio/gpio-pca953x.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 60b7616dd4aa..64befd6f702b 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -897,15 +897,18 @@ static int pca953x_irq_setup(struct pca953x_chip *chi= p, static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert) { DECLARE_BITMAP(val, MAX_LINE); + u8 regaddr; int ret; =20 - ret =3D regcache_sync_region(chip->regmap, chip->regs->output, - chip->regs->output + NBANK(chip) - 1); + regaddr =3D pca953x_recalc_addr(chip, chip->regs->output, 0); + ret =3D regcache_sync_region(chip->regmap, regaddr, + regaddr + NBANK(chip) - 1); if (ret) goto out; =20 - ret =3D regcache_sync_region(chip->regmap, chip->regs->direction, - chip->regs->direction + NBANK(chip) - 1); + regaddr =3D pca953x_recalc_addr(chip, chip->regs->direction, 0); + ret =3D regcache_sync_region(chip->regmap, regaddr, + regaddr + NBANK(chip) - 1); if (ret) goto out; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDC4BC04A68 for ; Wed, 27 Jul 2022 17:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238225AbiG0RSV (ORCPT ); Wed, 27 Jul 2022 13:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241743AbiG0RRg (ORCPT ); Wed, 27 Jul 2022 13:17:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A223878DF3; Wed, 27 Jul 2022 09:43:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2FA9D600BE; Wed, 27 Jul 2022 16:43:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36DFCC433C1; Wed, 27 Jul 2022 16:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940208; bh=OLyJjvqfkmOB7Z4Do0ij+T15ipP6P7LbGFLh2CjXnI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rWJ6w2Mk7gcRoOI3GvbDF0bT/CcSSDPa+Tl5MUYub/cjFZLCVCY5ADGNcoGxPdjfg 35vjqwlan5WKsKLwNLqFfLzT0IXS2ez7UtShui9NbD0mHWJeUVvqShjqtLW29md6We HWdGwnCWqPfCaiYnbxnT7OPYbRBmkCa6xNY03tPE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hristo Venev , Paolo Abeni , Sasha Levin Subject: [PATCH 5.15 112/201] be2net: Fix buffer overflow in be_get_module_eeprom Date: Wed, 27 Jul 2022 18:10:16 +0200 Message-Id: <20220727161032.405254698@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Hristo Venev [ Upstream commit d7241f679a59cfe27f92cb5c6272cb429fb1f7ec ] be_cmd_read_port_transceiver_data assumes that it is given a buffer that is at least PAGE_DATA_LEN long, or twice that if the module supports SFF 8472. However, this is not always the case. Fix this by passing the desired offset and length to be_cmd_read_port_transceiver_data so that we only copy the bytes once. Fixes: e36edd9d26cf ("be2net: add ethtool "-m" option support") Signed-off-by: Hristo Venev Link: https://lore.kernel.org/r/20220716085134.6095-1-hristo@venev.name Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/emulex/benet/be_cmds.c | 10 +++--- drivers/net/ethernet/emulex/benet/be_cmds.h | 2 +- .../net/ethernet/emulex/benet/be_ethtool.c | 31 ++++++++++++------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethe= rnet/emulex/benet/be_cmds.c index 649c5c429bd7..1288b5e3d220 100644 --- a/drivers/net/ethernet/emulex/benet/be_cmds.c +++ b/drivers/net/ethernet/emulex/benet/be_cmds.c @@ -2287,7 +2287,7 @@ int be_cmd_get_beacon_state(struct be_adapter *adapte= r, u8 port_num, u32 *state) =20 /* Uses sync mcc */ int be_cmd_read_port_transceiver_data(struct be_adapter *adapter, - u8 page_num, u8 *data) + u8 page_num, u32 off, u32 len, u8 *data) { struct be_dma_mem cmd; struct be_mcc_wrb *wrb; @@ -2321,10 +2321,10 @@ int be_cmd_read_port_transceiver_data(struct be_ada= pter *adapter, req->port =3D cpu_to_le32(adapter->hba_port_num); req->page_num =3D cpu_to_le32(page_num); status =3D be_mcc_notify_wait(adapter); - if (!status) { + if (!status && len > 0) { struct be_cmd_resp_port_type *resp =3D cmd.va; =20 - memcpy(data, resp->page_data, PAGE_DATA_LEN); + memcpy(data, resp->page_data + off, len); } err: mutex_unlock(&adapter->mcc_lock); @@ -2415,7 +2415,7 @@ int be_cmd_query_cable_type(struct be_adapter *adapte= r) int status; =20 status =3D be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, - page_data); + 0, PAGE_DATA_LEN, page_data); if (!status) { switch (adapter->phy.interface_type) { case PHY_TYPE_QSFP: @@ -2440,7 +2440,7 @@ int be_cmd_query_sfp_info(struct be_adapter *adapter) int status; =20 status =3D be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, - page_data); + 0, PAGE_DATA_LEN, page_data); if (!status) { strlcpy(adapter->phy.vendor_name, page_data + SFP_VENDOR_NAME_OFFSET, SFP_VENDOR_NAME_LEN - 1); diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.h b/drivers/net/ethe= rnet/emulex/benet/be_cmds.h index c30d6d6f0f3a..9e17d6a7ab8c 100644 --- a/drivers/net/ethernet/emulex/benet/be_cmds.h +++ b/drivers/net/ethernet/emulex/benet/be_cmds.h @@ -2427,7 +2427,7 @@ int be_cmd_set_beacon_state(struct be_adapter *adapte= r, u8 port_num, u8 beacon, int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state); int be_cmd_read_port_transceiver_data(struct be_adapter *adapter, - u8 page_num, u8 *data); + u8 page_num, u32 off, u32 len, u8 *data); int be_cmd_query_cable_type(struct be_adapter *adapter); int be_cmd_query_sfp_info(struct be_adapter *adapter); int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *= cmd, diff --git a/drivers/net/ethernet/emulex/benet/be_ethtool.c b/drivers/net/e= thernet/emulex/benet/be_ethtool.c index f9955308b93d..010a0024f3ce 100644 --- a/drivers/net/ethernet/emulex/benet/be_ethtool.c +++ b/drivers/net/ethernet/emulex/benet/be_ethtool.c @@ -1342,7 +1342,7 @@ static int be_get_module_info(struct net_device *netd= ev, return -EOPNOTSUPP; =20 status =3D be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, - page_data); + 0, PAGE_DATA_LEN, page_data); if (!status) { if (!page_data[SFP_PLUS_SFF_8472_COMP]) { modinfo->type =3D ETH_MODULE_SFF_8079; @@ -1360,25 +1360,32 @@ static int be_get_module_eeprom(struct net_device *= netdev, { struct be_adapter *adapter =3D netdev_priv(netdev); int status; + u32 begin, end; =20 if (!check_privilege(adapter, MAX_PRIVILEGES)) return -EOPNOTSUPP; =20 - status =3D be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, - data); - if (status) - goto err; + begin =3D eeprom->offset; + end =3D eeprom->offset + eeprom->len; + + if (begin < PAGE_DATA_LEN) { + status =3D be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, begin, + min_t(u32, end, PAGE_DATA_LEN) - begin, + data); + if (status) + goto err; + + data +=3D PAGE_DATA_LEN - begin; + begin =3D PAGE_DATA_LEN; + } =20 - if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) { - status =3D be_cmd_read_port_transceiver_data(adapter, - TR_PAGE_A2, - data + - PAGE_DATA_LEN); + if (end > PAGE_DATA_LEN) { + status =3D be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A2, + begin - PAGE_DATA_LEN, + end - begin, data); if (status) goto err; } - if (eeprom->offset) - memcpy(data, data + eeprom->offset, eeprom->len); err: return be_cmd_status(status); } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 960BDC04A68 for ; Wed, 27 Jul 2022 17:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241568AbiG0RNc (ORCPT ); Wed, 27 Jul 2022 13:13:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235886AbiG0RMo (ORCPT ); Wed, 27 Jul 2022 13:12:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98348753AB; Wed, 27 Jul 2022 09:42:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5E87261479; Wed, 27 Jul 2022 16:42:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DEB1C433D7; Wed, 27 Jul 2022 16:42:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940121; bh=dnuIqpfVolZ/SRhE1Fh9uNWTlG4nWV2M9XborI/p1IU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1NWJPxFcO8SDhFwHWq/9rxNjCu1GWbEZPykcVlEZe0JJF1UdFoIrNLD3wUqbvwP0L 3Qbeyu6BVnmwROlmPD+7QJkTUnQ+2DRqV2YgcWMDgWYPbdUgl0ZtAeS9Bfw7s1f6it IB23xPfk7tF4NuyjMhi1QxI0YzScAE1MRJiV9U+0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksij Rempel , Vladimir Oltean , Florian Fainelli , Paolo Abeni , Sasha Levin Subject: [PATCH 5.15 113/201] net: dsa: sja1105: silent spi_device_id warnings Date: Wed, 27 Jul 2022 18:10:17 +0200 Message-Id: <20220727161032.446516534@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Oleksij Rempel [ Upstream commit 855fe49984a8a3899f07ae1d149d46cd8d4acb52 ] Add spi_device_id entries to silent following warnings: SPI driver sja1105 has no spi_device_id for nxp,sja1105e SPI driver sja1105 has no spi_device_id for nxp,sja1105t SPI driver sja1105 has no spi_device_id for nxp,sja1105p SPI driver sja1105 has no spi_device_id for nxp,sja1105q SPI driver sja1105 has no spi_device_id for nxp,sja1105r SPI driver sja1105 has no spi_device_id for nxp,sja1105s SPI driver sja1105 has no spi_device_id for nxp,sja1110a SPI driver sja1105 has no spi_device_id for nxp,sja1110b SPI driver sja1105 has no spi_device_id for nxp,sja1110c SPI driver sja1105 has no spi_device_id for nxp,sja1110d Fixes: 5fa6863ba692 ("spi: Check we have a spi_device_id for each DT compat= ible") Signed-off-by: Oleksij Rempel Reviewed-by: Vladimir Oltean Reviewed-by: Florian Fainelli Link: https://lore.kernel.org/r/20220717135831.2492844-1-o.rempel@pengutron= ix.de Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/dsa/sja1105/sja1105_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja11= 05/sja1105_main.c index 924c3f129992..1a2a7536ff8a 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3372,12 +3372,28 @@ static const struct of_device_id sja1105_dt_ids[] = =3D { }; MODULE_DEVICE_TABLE(of, sja1105_dt_ids); =20 +static const struct spi_device_id sja1105_spi_ids[] =3D { + { "sja1105e" }, + { "sja1105t" }, + { "sja1105p" }, + { "sja1105q" }, + { "sja1105r" }, + { "sja1105s" }, + { "sja1110a" }, + { "sja1110b" }, + { "sja1110c" }, + { "sja1110d" }, + { }, +}; +MODULE_DEVICE_TABLE(spi, sja1105_spi_ids); + static struct spi_driver sja1105_driver =3D { .driver =3D { .name =3D "sja1105", .owner =3D THIS_MODULE, .of_match_table =3D of_match_ptr(sja1105_dt_ids), }, + .id_table =3D sja1105_spi_ids, .probe =3D sja1105_probe, .remove =3D sja1105_remove, .shutdown =3D sja1105_shutdown, --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C654C3F6B0 for ; Wed, 27 Jul 2022 17:13:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241610AbiG0RNn (ORCPT ); Wed, 27 Jul 2022 13:13:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241578AbiG0RMz (ORCPT ); Wed, 27 Jul 2022 13:12:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 460757644C; Wed, 27 Jul 2022 09:42:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2847560D3B; Wed, 27 Jul 2022 16:42:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 367F5C433C1; Wed, 27 Jul 2022 16:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940124; bh=4ErHXwOhPcEPwMUnQeYwhJKbusd/k1X5rqkKC/8iioU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CsrXCQwd8PkjBOnihqLPPLaqb8f/Xph2B1P0bcejRdl8legb/No6TKxZeF8ilo3jN 54FwqPAGnuMqnC6fVwj2+2M6tgq2m1o2MyMOGKw72dZV8YEJTNXYd3lHsdW10pDjz4 IHTQwdL8zRoNkhUUz4l6QtmATcjc0MvSLk5d+zRE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksij Rempel , Vladimir Oltean , Paolo Abeni , Sasha Levin Subject: [PATCH 5.15 114/201] net: dsa: vitesse-vsc73xx: silent spi_device_id warnings Date: Wed, 27 Jul 2022 18:10:18 +0200 Message-Id: <20220727161032.483840946@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Oleksij Rempel [ Upstream commit 1774559f07993e1cac33c2406e99049d4bdea6c8 ] Add spi_device_id entries to silent SPI warnings. Fixes: 5fa6863ba692 ("spi: Check we have a spi_device_id for each DT compat= ible") Signed-off-by: Oleksij Rempel Reviewed-by: Vladimir Oltean Link: https://lore.kernel.org/r/20220717135831.2492844-2-o.rempel@pengutron= ix.de Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/dsa/vitesse-vsc73xx-spi.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/dsa/vitesse-vsc73xx-spi.c b/drivers/net/dsa/vitess= e-vsc73xx-spi.c index 645398901e05..922ae22fad66 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-spi.c +++ b/drivers/net/dsa/vitesse-vsc73xx-spi.c @@ -207,10 +207,20 @@ static const struct of_device_id vsc73xx_of_match[] = =3D { }; MODULE_DEVICE_TABLE(of, vsc73xx_of_match); =20 +static const struct spi_device_id vsc73xx_spi_ids[] =3D { + { "vsc7385" }, + { "vsc7388" }, + { "vsc7395" }, + { "vsc7398" }, + { }, +}; +MODULE_DEVICE_TABLE(spi, vsc73xx_spi_ids); + static struct spi_driver vsc73xx_spi_driver =3D { .probe =3D vsc73xx_spi_probe, .remove =3D vsc73xx_spi_remove, .shutdown =3D vsc73xx_spi_shutdown, + .id_table =3D vsc73xx_spi_ids, .driver =3D { .name =3D "vsc73xx-spi", .of_match_table =3D vsc73xx_of_match, --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2807BC19F28 for ; Wed, 27 Jul 2022 17:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236826AbiG0RN5 (ORCPT ); Wed, 27 Jul 2022 13:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241591AbiG0RNN (ORCPT ); Wed, 27 Jul 2022 13:13:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FAC676472; Wed, 27 Jul 2022 09:42:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E7DAB601C0; Wed, 27 Jul 2022 16:42:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03162C433D6; Wed, 27 Jul 2022 16:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940127; bh=laAW4N7hZQuQqUG5fJRWifvSw1PQRaXRy9+COPCqzQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fwjQRWywWPb813Edb7g7dEmq7EUlZumNKyWzNG+8rXTqE3LZ2efYsnq/pKZidpeZy 6E2SgpIhyBu23jgP8cYVgEGIOUPjvlDqDc2yfJUE/+5+G3l8uUc16BYE0FoGdwvXb5 rBwYIa966SS935Dq1eKX3h913/7KEXHW6R+zqf0E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liang He , Laurentiu Palcu , Sasha Levin Subject: [PATCH 5.15 115/201] drm/imx/dcss: Add missing of_node_put() in fail path Date: Wed, 27 Jul 2022 18:10:19 +0200 Message-Id: <20220727161032.530165830@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Liang He [ Upstream commit 02c87df2480ac855d88ee308ce3fa857d9bd55a8 ] In dcss_dev_create() and dcss_dev_destroy(), we should call of_node_put() in fail path or before the dcss's destroy as of_graph_get_port_by_id() has increased the refcount. Fixes: 9021c317b770 ("drm/imx: Add initial support for DCSS on iMX8MQ") Signed-off-by: Liang He Reviewed-by: Laurentiu Palcu Signed-off-by: Laurentiu Palcu Link: https://patchwork.freedesktop.org/patch/msgid/20220714081337.374761-1= -windhl@126.com Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/imx/dcss/dcss-dev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/imx/dcss/dcss-dev.c b/drivers/gpu/drm/imx/dcss= /dcss-dev.c index c849533ca83e..3f5750cc2673 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-dev.c +++ b/drivers/gpu/drm/imx/dcss/dcss-dev.c @@ -207,6 +207,7 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bo= ol hdmi_output) =20 ret =3D dcss_submodules_init(dcss); if (ret) { + of_node_put(dcss->of_port); dev_err(dev, "submodules initialization failed\n"); goto clks_err; } @@ -237,6 +238,8 @@ void dcss_dev_destroy(struct dcss_dev *dcss) dcss_clocks_disable(dcss); } =20 + of_node_put(dcss->of_port); + pm_runtime_disable(dcss->dev); =20 dcss_submodules_stop(dcss); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A00E6C04A68 for ; Wed, 27 Jul 2022 17:14:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236328AbiG0ROF (ORCPT ); Wed, 27 Jul 2022 13:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241569AbiG0RNc (ORCPT ); Wed, 27 Jul 2022 13:13:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3555576951; Wed, 27 Jul 2022 09:42:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 63CE5B821A6; Wed, 27 Jul 2022 16:42:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCD7DC433B5; Wed, 27 Jul 2022 16:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940130; bh=deshV2X/m340dN/SVCmmSE8XyFHZN1oMpbGKKrA4AUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0qWDFwCfuc3UIivllqszgWxyp6r+0uyIx9F5YLsGgFS5BB9CWHK0II1JrjsrzwAzJ Ab00O/MYbb5R3cK9oLGrkrA+Yb9SMJZ9/cPwhcdaT7EdNxB6tSXM5l170RkyzlAFG1 ZXzLoie9gVT3X6uesJDb/l4aNCnnA55YbN1Z8sKQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 116/201] ipv4: Fix a data-race around sysctl_fib_multipath_use_neigh. Date: Wed, 27 Jul 2022 18:10:20 +0200 Message-Id: <20220727161032.577503809@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 87507bcb4f5de16bb419e9509d874f4db6c0ad0f ] While reading sysctl_fib_multipath_use_neigh, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: a6db4494d218 ("net: ipv4: Consider failed nexthops in multipath rout= es") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/fib_semantics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 674694d8ac61..55de6fa83dea 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -2233,7 +2233,7 @@ void fib_select_multipath(struct fib_result *res, int= hash) } =20 change_nexthops(fi) { - if (net->ipv4.sysctl_fib_multipath_use_neigh) { + if (READ_ONCE(net->ipv4.sysctl_fib_multipath_use_neigh)) { if (!fib_good_nh(nexthop_nh)) continue; if (!first) { --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C50A4C25B06 for ; Wed, 27 Jul 2022 17:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbiG0RO5 (ORCPT ); Wed, 27 Jul 2022 13:14:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241583AbiG0RNn (ORCPT ); Wed, 27 Jul 2022 13:13:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D1CB5B79F; Wed, 27 Jul 2022 09:42:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A1914601CE; Wed, 27 Jul 2022 16:42:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A880BC433C1; Wed, 27 Jul 2022 16:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940133; bh=l1ue5a0jyDSRmPddXPGgCmTdqIau5TtnOYUWQww6OZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pu33QJ+LBJ1Z6PVTe+RvOZVl8+Dep7Uz+nwWn6HD6yQi0yw9N7I+m738ACwNR/4P0 i8ccO6CTlTVeiRSELqmvciQPYUIleuNE16hHffdDxlfcIZ+LtotBc3/N6bf6TAt2gL vUQGTvT/g8YLD7DWnLkt3tRLkPwF8sKdLJqWl3us= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 117/201] ipv4: Fix data-races around sysctl_fib_multipath_hash_policy. Date: Wed, 27 Jul 2022 18:10:21 +0200 Message-Id: <20220727161032.626425136@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 7998c12a08c97cc26660532c9f90a34bd7d8da5a ] While reading sysctl_fib_multipath_hash_policy, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: bf4e0a3db97e ("net: ipv4: add support for ECMP hash policy choice") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +- net/ipv4/route.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/driver= s/net/ethernet/mellanox/mlxsw/spectrum_router.c index d17156c11ef8..6cdf0e232b1c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -9588,7 +9588,7 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *m= lxsw_sp, unsigned long *fields =3D config->fields; u32 hash_fields; =20 - switch (net->ipv4.sysctl_fib_multipath_hash_policy) { + switch (READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_policy)) { case 0: mlxsw_sp_mp4_hash_outer_addr(config); break; diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 7f08a30256c5..ade6cb309c40 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2048,7 +2048,7 @@ int fib_multipath_hash(const struct net *net, const s= truct flowi4 *fl4, struct flow_keys hash_keys; u32 mhash =3D 0; =20 - switch (net->ipv4.sysctl_fib_multipath_hash_policy) { + switch (READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_policy)) { case 0: memset(&hash_keys, 0, sizeof(hash_keys)); hash_keys.control.addr_type =3D FLOW_DISSECTOR_KEY_IPV4_ADDRS; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 901AEC3F6B0 for ; Wed, 27 Jul 2022 17:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241634AbiG0ROI (ORCPT ); Wed, 27 Jul 2022 13:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238131AbiG0RNl (ORCPT ); Wed, 27 Jul 2022 13:13:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F6525B78C; Wed, 27 Jul 2022 09:42:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6B1D360D3B; Wed, 27 Jul 2022 16:42:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79991C433D6; Wed, 27 Jul 2022 16:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940135; bh=QMlouGdUSHtpzVpbNT1n810JgfCBDB50pAHdCH7HfUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K6qaPdM/zUPU5HLzE8hYEhQFZ9D/iUNJj2ERHOjl15Pk72IjfSP+qu2by3veba5Q9 OuVtDzWaOdmzsKeWd9WofJ0VyC2+MrVrk9GPSG2AGE0I9cKdihqweF+kcmasd6TBY5 KgVD92X0dGFHqlljpSRvcSuMAedRvMqY8G8fIBaA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , Ido Schimmel , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 118/201] ipv4: Fix data-races around sysctl_fib_multipath_hash_fields. Date: Wed, 27 Jul 2022 18:10:22 +0200 Message-Id: <20220727161032.665812955@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 8895a9c2ac76fb9d3922fed4fe092c8ec5e5cccc ] While reading sysctl_fib_multipath_hash_fields, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: ce5c9c20d364 ("ipv4: Add a sysctl to control multipath hash fields") Signed-off-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +- net/ipv4/route.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/driver= s/net/ethernet/mellanox/mlxsw/spectrum_router.c index 6cdf0e232b1c..55de90d5ae59 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -9606,7 +9606,7 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *m= lxsw_sp, mlxsw_sp_mp_hash_inner_l3(config); break; case 3: - hash_fields =3D net->ipv4.sysctl_fib_multipath_hash_fields; + hash_fields =3D READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields); /* Outer */ MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP); MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index ade6cb309c40..ca59b61fd3a3 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1929,7 +1929,7 @@ static u32 fib_multipath_custom_hash_outer(const stru= ct net *net, const struct sk_buff *skb, bool *p_has_inner) { - u32 hash_fields =3D net->ipv4.sysctl_fib_multipath_hash_fields; + u32 hash_fields =3D READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields); struct flow_keys keys, hash_keys; =20 if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK)) @@ -1958,7 +1958,7 @@ static u32 fib_multipath_custom_hash_inner(const stru= ct net *net, const struct sk_buff *skb, bool has_inner) { - u32 hash_fields =3D net->ipv4.sysctl_fib_multipath_hash_fields; + u32 hash_fields =3D READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields); struct flow_keys keys, hash_keys; =20 /* We assume the packet carries an encapsulation, but if none was @@ -2018,7 +2018,7 @@ static u32 fib_multipath_custom_hash_skb(const struct= net *net, static u32 fib_multipath_custom_hash_fl4(const struct net *net, const struct flowi4 *fl4) { - u32 hash_fields =3D net->ipv4.sysctl_fib_multipath_hash_fields; + u32 hash_fields =3D READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_fields); struct flow_keys hash_keys; =20 if (!(hash_fields & FIB_MULTIPATH_HASH_FIELD_OUTER_MASK)) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9146EC19F2B for ; Wed, 27 Jul 2022 17:15:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236215AbiG0RPB (ORCPT ); Wed, 27 Jul 2022 13:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234073AbiG0RNy (ORCPT ); Wed, 27 Jul 2022 13:13:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BD1276963; Wed, 27 Jul 2022 09:42:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D5BD3B821BA; Wed, 27 Jul 2022 16:42:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BE25C433C1; Wed, 27 Jul 2022 16:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940138; bh=TLs54fR9ZjrgFajJSrQMbGvCC1KeHOx8HI9w8RnTpT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1b+dhEhgd3QrfxOkQ1TAnGIwNO45ieCg7/VlJcc6mRi+VDPXNVu8mKaQ5UmMKquk5 TSdDXePBIwxllPQ13BYHtcNmZm22zCgXpoNMUvxCn1hIMB35/E6uKYv8io8CA5HGBa 15gOptq315507pwVtRRoSCJ6S7QjzLAOSSnc9ux0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 119/201] ip: Fix data-races around sysctl_ip_prot_sock. Date: Wed, 27 Jul 2022 18:10:23 +0200 Message-Id: <20220727161032.705219293@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 9b55c20f83369dd54541d9ddbe3a018a8377f451 ] sysctl_ip_prot_sock is accessed concurrently, and there is always a chance of data-race. So, all readers and writers need some basic protection to avoid load/store-tearing. Fixes: 4548b683b781 ("Introduce a sysctl that modifies the value of PROT_SO= CK.") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/ip.h | 2 +- net/ipv4/sysctl_net_ipv4.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index a0ac57af82dc..8462ced0c21e 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -352,7 +352,7 @@ static inline bool sysctl_dev_name_is_allowed(const cha= r *name) =20 static inline bool inet_port_requires_bind_service(struct net *net, unsign= ed short port) { - return port < net->ipv4.sysctl_ip_prot_sock; + return port < READ_ONCE(net->ipv4.sysctl_ip_prot_sock); } =20 #else diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index ead5db7e24ea..a36728277e32 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -97,7 +97,7 @@ static int ipv4_local_port_range(struct ctl_table *table,= int write, * port limit. */ if ((range[1] < range[0]) || - (range[0] < net->ipv4.sysctl_ip_prot_sock)) + (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock))) ret =3D -EINVAL; else set_local_port_range(net, range); @@ -123,7 +123,7 @@ static int ipv4_privileged_ports(struct ctl_table *tabl= e, int write, .extra2 =3D &ip_privileged_port_max, }; =20 - pports =3D net->ipv4.sysctl_ip_prot_sock; + pports =3D READ_ONCE(net->ipv4.sysctl_ip_prot_sock); =20 ret =3D proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); =20 @@ -135,7 +135,7 @@ static int ipv4_privileged_ports(struct ctl_table *tabl= e, int write, if (range[0] < pports) ret =3D -EINVAL; else - net->ipv4.sysctl_ip_prot_sock =3D pports; + WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports); } =20 return ret; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE981C19F2B for ; Wed, 27 Jul 2022 17:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238167AbiG0RPF (ORCPT ); Wed, 27 Jul 2022 13:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241591AbiG0RN6 (ORCPT ); Wed, 27 Jul 2022 13:13:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4223476E88; Wed, 27 Jul 2022 09:42:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E38D1601C0; Wed, 27 Jul 2022 16:42:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F05DAC433D6; Wed, 27 Jul 2022 16:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940141; bh=WMU2kinNtWQ/73H85dgKkTJ4LBz1q10ztaXSSw5i3A4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B3uvtnTYbsz9a45dsk05py3/iuNDQ4zyCEbKS0GkrBvI8VZ5FXfH/hz9uWtj52l95 R9lNqSK63puzL9wFmUzwLnrgdOMYD6bhLUBa3X6UlohTW12LlfP58nt6QNvLhOx7pM R2ua7z7Y4c6POMWbi9e9+8Qj8sqfSZoGZhcoSknE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 120/201] udp: Fix a data-race around sysctl_udp_l3mdev_accept. Date: Wed, 27 Jul 2022 18:10:24 +0200 Message-Id: <20220727161032.745681985@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 3d72bb4188c708bb16758c60822fc4dda7a95174 ] While reading sysctl_udp_l3mdev_accept, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 63a6fff353d0 ("net: Avoid receiving packets with an l3mdev on unboun= d UDP sockets") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/udp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/udp.h b/include/net/udp.h index 909ecf447e0f..438b1b01a56c 100644 --- a/include/net/udp.h +++ b/include/net/udp.h @@ -262,7 +262,7 @@ static inline bool udp_sk_bound_dev_eq(struct net *net,= int bound_dev_if, int dif, int sdif) { #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) - return inet_bound_dev_eq(!!net->ipv4.sysctl_udp_l3mdev_accept, + return inet_bound_dev_eq(!!READ_ONCE(net->ipv4.sysctl_udp_l3mdev_accept), bound_dev_if, dif, sdif); #else return inet_bound_dev_eq(true, bound_dev_if, dif, sdif); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D77FC04A68 for ; Wed, 27 Jul 2022 17:15:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241499AbiG0RPP (ORCPT ); Wed, 27 Jul 2022 13:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241629AbiG0ROH (ORCPT ); Wed, 27 Jul 2022 13:14:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30EF076E9E; Wed, 27 Jul 2022 09:42:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A8F6461494; Wed, 27 Jul 2022 16:42:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5F3CC433D6; Wed, 27 Jul 2022 16:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940144; bh=rgp9Sjl5vf3cDHOahT05ecTSCc7mB1HYzcffHKemhxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yzmYc0wr0u6QolNnAtfdfTZsgeLlg6x58m2C/4mIsFThErUo0STBiTzNXExptPLty Am8njM1SL6FtcTh8obJxxA8kNt1oiopz03bvAW8YlDz61o4rGm0rYwgYNRe4tBKPKR H5K4ljMZi9eBzU5dxiEIuEIINkbTuPppMZ+CkRuk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 121/201] tcp: Fix data-races around sysctl knobs related to SYN option. Date: Wed, 27 Jul 2022 18:10:25 +0200 Message-Id: <20220727161032.775961702@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 3666f666e99600518ab20982af04a078bbdad277 ] While reading these knobs, they can be changed concurrently. Thus, we need to add READ_ONCE() to their readers. - tcp_sack - tcp_window_scaling - tcp_timestamps Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- .../ethernet/chelsio/inline_crypto/chtls/chtls_cm.c | 6 +++--- net/core/secure_seq.c | 4 ++-- net/ipv4/syncookies.c | 6 +++--- net/ipv4/tcp_input.c | 6 +++--- net/ipv4/tcp_output.c | 10 +++++----- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c b/= drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c index 7c760aa65540..ddfe9208529a 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c @@ -1236,8 +1236,8 @@ static struct sock *chtls_recv_sock(struct sock *lsk, csk->sndbuf =3D newsk->sk_sndbuf; csk->smac_idx =3D ((struct port_info *)netdev_priv(ndev))->smt_idx; RCV_WSCALE(tp) =3D select_rcv_wscale(tcp_full_space(newsk), - sock_net(newsk)-> - ipv4.sysctl_tcp_window_scaling, + READ_ONCE(sock_net(newsk)-> + ipv4.sysctl_tcp_window_scaling), tp->window_clamp); neigh_release(n); inet_inherit_port(&tcp_hashinfo, lsk, newsk); @@ -1384,7 +1384,7 @@ static void chtls_pass_accept_request(struct sock *sk, #endif } if (req->tcpopt.wsf <=3D 14 && - sock_net(sk)->ipv4.sysctl_tcp_window_scaling) { + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling)) { inet_rsk(oreq)->wscale_ok =3D 1; inet_rsk(oreq)->snd_wscale =3D req->tcpopt.wsf; } diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c index 7131cd1fb2ad..189eea1372d5 100644 --- a/net/core/secure_seq.c +++ b/net/core/secure_seq.c @@ -64,7 +64,7 @@ u32 secure_tcpv6_ts_off(const struct net *net, .daddr =3D *(struct in6_addr *)daddr, }; =20 - if (net->ipv4.sysctl_tcp_timestamps !=3D 1) + if (READ_ONCE(net->ipv4.sysctl_tcp_timestamps) !=3D 1) return 0; =20 ts_secret_init(); @@ -120,7 +120,7 @@ EXPORT_SYMBOL(secure_ipv6_port_ephemeral); #ifdef CONFIG_INET u32 secure_tcp_ts_off(const struct net *net, __be32 saddr, __be32 daddr) { - if (net->ipv4.sysctl_tcp_timestamps !=3D 1) + if (READ_ONCE(net->ipv4.sysctl_tcp_timestamps) !=3D 1) return 0; =20 ts_secret_init(); diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 8eee771d2aca..940839264025 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -249,12 +249,12 @@ bool cookie_timestamp_decode(const struct net *net, return true; } =20 - if (!net->ipv4.sysctl_tcp_timestamps) + if (!READ_ONCE(net->ipv4.sysctl_tcp_timestamps)) return false; =20 tcp_opt->sack_ok =3D (options & TS_OPT_SACK) ? TCP_SACK_SEEN : 0; =20 - if (tcp_opt->sack_ok && !net->ipv4.sysctl_tcp_sack) + if (tcp_opt->sack_ok && !READ_ONCE(net->ipv4.sysctl_tcp_sack)) return false; =20 if ((options & TS_OPT_WSCALE_MASK) =3D=3D TS_OPT_WSCALE_MASK) @@ -263,7 +263,7 @@ bool cookie_timestamp_decode(const struct net *net, tcp_opt->wscale_ok =3D 1; tcp_opt->snd_wscale =3D options & TS_OPT_WSCALE_MASK; =20 - return net->ipv4.sysctl_tcp_window_scaling !=3D 0; + return READ_ONCE(net->ipv4.sysctl_tcp_window_scaling) !=3D 0; } EXPORT_SYMBOL(cookie_timestamp_decode); =20 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index d9e534c6fd0c..dd10a317709f 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4053,7 +4053,7 @@ void tcp_parse_options(const struct net *net, break; case TCPOPT_WINDOW: if (opsize =3D=3D TCPOLEN_WINDOW && th->syn && - !estab && net->ipv4.sysctl_tcp_window_scaling) { + !estab && READ_ONCE(net->ipv4.sysctl_tcp_window_scaling)) { __u8 snd_wscale =3D *(__u8 *)ptr; opt_rx->wscale_ok =3D 1; if (snd_wscale > TCP_MAX_WSCALE) { @@ -4069,7 +4069,7 @@ void tcp_parse_options(const struct net *net, case TCPOPT_TIMESTAMP: if ((opsize =3D=3D TCPOLEN_TIMESTAMP) && ((estab && opt_rx->tstamp_ok) || - (!estab && net->ipv4.sysctl_tcp_timestamps))) { + (!estab && READ_ONCE(net->ipv4.sysctl_tcp_timestamps)))) { opt_rx->saw_tstamp =3D 1; opt_rx->rcv_tsval =3D get_unaligned_be32(ptr); opt_rx->rcv_tsecr =3D get_unaligned_be32(ptr + 4); @@ -4077,7 +4077,7 @@ void tcp_parse_options(const struct net *net, break; case TCPOPT_SACK_PERM: if (opsize =3D=3D TCPOLEN_SACK_PERM && th->syn && - !estab && net->ipv4.sysctl_tcp_sack) { + !estab && READ_ONCE(net->ipv4.sysctl_tcp_sack)) { opt_rx->sack_ok =3D TCP_SACK_SEEN; tcp_sack_reset(opt_rx); } diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index fcccf56ae9f7..a08fcf15372a 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -790,18 +790,18 @@ static unsigned int tcp_syn_options(struct sock *sk, = struct sk_buff *skb, opts->mss =3D tcp_advertise_mss(sk); remaining -=3D TCPOLEN_MSS_ALIGNED; =20 - if (likely(sock_net(sk)->ipv4.sysctl_tcp_timestamps && !*md5)) { + if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps) && !*md5))= { opts->options |=3D OPTION_TS; opts->tsval =3D tcp_skb_timestamp(skb) + tp->tsoffset; opts->tsecr =3D tp->rx_opt.ts_recent; remaining -=3D TCPOLEN_TSTAMP_ALIGNED; } - if (likely(sock_net(sk)->ipv4.sysctl_tcp_window_scaling)) { + if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling))) { opts->ws =3D tp->rx_opt.rcv_wscale; opts->options |=3D OPTION_WSCALE; remaining -=3D TCPOLEN_WSCALE_ALIGNED; } - if (likely(sock_net(sk)->ipv4.sysctl_tcp_sack)) { + if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_sack))) { opts->options |=3D OPTION_SACK_ADVERTISE; if (unlikely(!(OPTION_TS & opts->options))) remaining -=3D TCPOLEN_SACKPERM_ALIGNED; @@ -3649,7 +3649,7 @@ static void tcp_connect_init(struct sock *sk) * See tcp_input.c:tcp_rcv_state_process case TCP_SYN_SENT. */ tp->tcp_header_len =3D sizeof(struct tcphdr); - if (sock_net(sk)->ipv4.sysctl_tcp_timestamps) + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps)) tp->tcp_header_len +=3D TCPOLEN_TSTAMP_ALIGNED; =20 #ifdef CONFIG_TCP_MD5SIG @@ -3685,7 +3685,7 @@ static void tcp_connect_init(struct sock *sk) tp->advmss - (tp->rx_opt.ts_recent_stamp ? tp->tcp_header_len - size= of(struct tcphdr) : 0), &tp->rcv_wnd, &tp->window_clamp, - sock_net(sk)->ipv4.sysctl_tcp_window_scaling, + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling), &rcv_wscale, rcv_wnd); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5802DC04A68 for ; Wed, 27 Jul 2022 17:15:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241618AbiG0RPm (ORCPT ); Wed, 27 Jul 2022 13:15:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241688AbiG0ROP (ORCPT ); Wed, 27 Jul 2022 13:14:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F8B45B79A; Wed, 27 Jul 2022 09:42:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E803CB821A6; Wed, 27 Jul 2022 16:42:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DF1EC433D6; Wed, 27 Jul 2022 16:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940146; bh=d8KCOZQRtS3YyGHEzP8Y+vF/hcnKWbNeTEIuHdOAJqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GtYDW0uL9E51Lbe6ygW8Jwe9rsSO0Kx+PGGCpseURFPlHVwjR6x5DCwN3kVo8XhtV FaM60i6xOXsdfRScQNSgRi0RCoI3uPQnMyMHA7N+N31T4JpZoX0rFJMQUTR/x62rJj oOPfbO52jvfJW8f7qu2MVJg5YS+Pf1KaUuQmjiBk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 122/201] tcp: Fix a data-race around sysctl_tcp_early_retrans. Date: Wed, 27 Jul 2022 18:10:26 +0200 Message-Id: <20220727161032.815549109@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 52e65865deb6a36718a463030500f16530eaab74 ] While reading sysctl_tcp_early_retrans, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: eed530b6c676 ("tcp: early retransmit") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index a08fcf15372a..3b71d8735995 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2739,7 +2739,7 @@ bool tcp_schedule_loss_probe(struct sock *sk, bool ad= vancing_rto) if (rcu_access_pointer(tp->fastopen_rsk)) return false; =20 - early_retrans =3D sock_net(sk)->ipv4.sysctl_tcp_early_retrans; + early_retrans =3D READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_early_retrans); /* Schedule a loss probe in 2*RTT for SACK capable connections * not in loss recovery, that are either limited by cwnd or application. */ --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74A30C04A68 for ; Wed, 27 Jul 2022 17:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241606AbiG0RPf (ORCPT ); Wed, 27 Jul 2022 13:15:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241695AbiG0ROS (ORCPT ); Wed, 27 Jul 2022 13:14:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FDE55C343; Wed, 27 Jul 2022 09:42:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9047BB8200D; Wed, 27 Jul 2022 16:42:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2A04C433B5; Wed, 27 Jul 2022 16:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940152; bh=PTRFrZDRpHKYilPDjVYSyUzsHuQy8mpEheU4eS0zltc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FQ1vD2S7/1J8MA41qDrH/y9RMJH/Sllv5b2EBpO6Ob4IwK673cKo9zQymCILasTiQ s4mRci3iLp0h9xO5s6jD04vWTP1sqlOXRr6Flf/JzGqqvlaQXDklGNKSyre4/rEq4X XOnBYSYtMxnQqCS1szxPTUG7taTH8tG6Y/2/TkCA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 123/201] tcp: Fix data-races around sysctl_tcp_recovery. Date: Wed, 27 Jul 2022 18:10:27 +0200 Message-Id: <20220727161032.863019347@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit e7d2ef837e14a971a05f60ea08c47f3fed1a36e4 ] While reading sysctl_tcp_recovery, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 4f41b1c58a32 ("tcp: use RACK to detect losses") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_input.c | 3 ++- net/ipv4/tcp_recovery.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index dd10a317709f..1cc0aca39c04 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -2087,7 +2087,8 @@ static inline void tcp_init_undo(struct tcp_sock *tp) =20 static bool tcp_is_rack(const struct sock *sk) { - return sock_net(sk)->ipv4.sysctl_tcp_recovery & TCP_RACK_LOSS_DETECTION; + return READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_recovery) & + TCP_RACK_LOSS_DETECTION; } =20 /* If we detect SACK reneging, forget all SACK information diff --git a/net/ipv4/tcp_recovery.c b/net/ipv4/tcp_recovery.c index fd113f6226ef..ac14216f6204 100644 --- a/net/ipv4/tcp_recovery.c +++ b/net/ipv4/tcp_recovery.c @@ -19,7 +19,8 @@ static u32 tcp_rack_reo_wnd(const struct sock *sk) return 0; =20 if (tp->sacked_out >=3D tp->reordering && - !(sock_net(sk)->ipv4.sysctl_tcp_recovery & TCP_RACK_NO_DUPTHRESH)) + !(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_recovery) & + TCP_RACK_NO_DUPTHRESH)) return 0; } =20 @@ -192,7 +193,8 @@ void tcp_rack_update_reo_wnd(struct sock *sk, struct ra= te_sample *rs) { struct tcp_sock *tp =3D tcp_sk(sk); =20 - if (sock_net(sk)->ipv4.sysctl_tcp_recovery & TCP_RACK_STATIC_REO_WND || + if ((READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_recovery) & + TCP_RACK_STATIC_REO_WND) || !rs->prior_delivered) return; =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEC54C04A68 for ; Wed, 27 Jul 2022 17:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241642AbiG0RPv (ORCPT ); Wed, 27 Jul 2022 13:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241752AbiG0RO0 (ORCPT ); Wed, 27 Jul 2022 13:14:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A95E35C35B; Wed, 27 Jul 2022 09:42:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 810F0B821D2; Wed, 27 Jul 2022 16:42:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9535C433D7; Wed, 27 Jul 2022 16:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940155; bh=WFxdTAFTDOeA3kkSiLosrw9dd3leJML+aRruvvmgrDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tvMpLGoc/BczxqdrKNQsj9lHJH/G8sTmtz4RVzqxqmr72INCHpTLEK/RbV2II5v+8 6aMtD3Z0SPaM5IulCr8hlwu04/V2mbPjpPOq29Onttq/7OkN2uxNTkhqJkw0cFPBW5 0D6YBccss0YGZ+4FZag25qhHUkl4+PAU5reDeVsM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 124/201] tcp: Fix a data-race around sysctl_tcp_thin_linear_timeouts. Date: Wed, 27 Jul 2022 18:10:28 +0200 Message-Id: <20220727161032.901741719@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 7c6f2a86ca590d5187a073d987e9599985fb1c7c ] While reading sysctl_tcp_thin_linear_timeouts, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 36e31b0af587 ("net: TCP thin linear timeouts") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index ec5277becc6a..50bba370486e 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -578,7 +578,7 @@ void tcp_retransmit_timer(struct sock *sk) * linear-timeout retransmissions into a black hole */ if (sk->sk_state =3D=3D TCP_ESTABLISHED && - (tp->thin_lto || net->ipv4.sysctl_tcp_thin_linear_timeouts) && + (tp->thin_lto || READ_ONCE(net->ipv4.sysctl_tcp_thin_linear_timeouts)= ) && tcp_stream_is_thin(tp) && icsk->icsk_retransmits <=3D TCP_THIN_LINEAR_RETRIES) { icsk->icsk_backoff =3D 0; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FFE7C04A68 for ; Wed, 27 Jul 2022 17:15:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241631AbiG0RPr (ORCPT ); Wed, 27 Jul 2022 13:15:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241726AbiG0ROW (ORCPT ); Wed, 27 Jul 2022 13:14:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6551F77577; Wed, 27 Jul 2022 09:42:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 33ABFB821BA; Wed, 27 Jul 2022 16:42:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85717C433B5; Wed, 27 Jul 2022 16:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940157; bh=/sNS45vza5QLdinTFdHl9PLVW8EEHm8+8B8Nb2az7V0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VNLhIFWZpWL/n3AfTFITq+bH3/R8HBzaQI5SFsMxdBhD9oLiYkl5qlX9ahvj84hCS C6Fj4zZDOZ+q4w7MwrQGlnUaeNJ24LTSjSuDHAtIely/Mo3bs6Ngq1gYPJJbq8cT7d kmAkLfn7mM+sbQPNOeihQyDXIbAWe+iduHPBA78A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 125/201] tcp: Fix data-races around sysctl_tcp_slow_start_after_idle. Date: Wed, 27 Jul 2022 18:10:29 +0200 Message-Id: <20220727161032.941053058@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 4845b5713ab18a1bb6e31d1fbb4d600240b8b691 ] While reading sysctl_tcp_slow_start_after_idle, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 35089bb203f4 ("[TCP]: Add tcp_slow_start_after_idle sysctl.") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/tcp.h | 4 ++-- net/ipv4/tcp_output.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 0c609d10c320..8ce8aafeef0f 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1390,8 +1390,8 @@ static inline void tcp_slow_start_after_idle_check(st= ruct sock *sk) struct tcp_sock *tp =3D tcp_sk(sk); s32 delta; =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle || tp->packets_o= ut || - ca_ops->cong_control) + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) || + tp->packets_out || ca_ops->cong_control) return; delta =3D tcp_jiffies32 - tp->lsndtime; if (delta > inet_csk(sk)->icsk_rto) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 3b71d8735995..94f7841f7bfb 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1901,7 +1901,7 @@ static void tcp_cwnd_validate(struct sock *sk, bool i= s_cwnd_limited) if (tp->packets_out > tp->snd_cwnd_used) tp->snd_cwnd_used =3D tp->packets_out; =20 - if (sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle && + if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) && (s32)(tcp_jiffies32 - tp->snd_cwnd_stamp) >=3D inet_csk(sk)->icsk_rt= o && !ca_ops->cong_control) tcp_cwnd_application_limited(sk); --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5026C04A68 for ; Wed, 27 Jul 2022 17:16:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236042AbiG0RQA (ORCPT ); Wed, 27 Jul 2022 13:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241781AbiG0ROa (ORCPT ); Wed, 27 Jul 2022 13:14:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9C7477A4B; Wed, 27 Jul 2022 09:42:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E127EB821AC; Wed, 27 Jul 2022 16:42:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B8DFC433D6; Wed, 27 Jul 2022 16:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940160; bh=oNYGdc6nlfLoM3lLt0p/2uV0z9jZovLnyhIp7KDsDi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dGeZvN2XFj2fBF0l2WiMxYMFx2h5XmzCnWpxwaYlN5b/c3mKTPpp/w1U0cxmzmkG/ +Ozbt884NArVIlcuGJbz2KE2HSCNRUrBW2Tqt37s0pxbiMIMI0RCguryarUf1VdWC2 77XRLnQay1aih7dA/EoYSGFp8ejA3UQsEcI1iEik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 126/201] tcp: Fix a data-race around sysctl_tcp_retrans_collapse. Date: Wed, 27 Jul 2022 18:10:30 +0200 Message-Id: <20220727161032.986676187@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 1a63cb91f0c2fcdeced6d6edee8d1d886583d139 ] While reading sysctl_tcp_retrans_collapse, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 94f7841f7bfb..caf9283f9b0f 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3108,7 +3108,7 @@ static void tcp_retrans_try_collapse(struct sock *sk,= struct sk_buff *to, struct sk_buff *skb =3D to, *tmp; bool first =3D true; =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_retrans_collapse) + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_retrans_collapse)) return; if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN) return; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 897E1C04A68 for ; Wed, 27 Jul 2022 17:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241665AbiG0RQE (ORCPT ); Wed, 27 Jul 2022 13:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241782AbiG0ROa (ORCPT ); Wed, 27 Jul 2022 13:14:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 461415B7BC; Wed, 27 Jul 2022 09:42:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BFB2CB821D5; Wed, 27 Jul 2022 16:42:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11619C433D6; Wed, 27 Jul 2022 16:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940163; bh=GbhDpoG66pcZmVI2I4jhiCBBRcEPAZrdFjjlqZK29js=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y2f+EnYCY/WT20t3SzQE2W7+qccdVHQYfytiIM0WHEaL4X0CFm2tT/T0pZB9aiuVs 4zWtUckVC5z45/FdFGQJTkvDUrrnV9EPeJJsxMcTrUKID2LTufMVFpBEeSPmRLB+77 GTc2/EbHPxQC2pleDHYGQpyXyOrmzdMEvWdFGU4A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 127/201] tcp: Fix a data-race around sysctl_tcp_stdurg. Date: Wed, 27 Jul 2022 18:10:31 +0200 Message-Id: <20220727161033.027113259@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 4e08ed41cb1194009fc1a916a59ce3ed4afd77cd ] While reading sysctl_tcp_stdurg, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 1cc0aca39c04..6309a4eb3acd 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5542,7 +5542,7 @@ static void tcp_check_urg(struct sock *sk, const stru= ct tcphdr *th) struct tcp_sock *tp =3D tcp_sk(sk); u32 ptr =3D ntohs(th->urg_ptr); =20 - if (ptr && !sock_net(sk)->ipv4.sysctl_tcp_stdurg) + if (ptr && !READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_stdurg)) ptr--; ptr +=3D ntohl(th->seq); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2081C04A68 for ; Wed, 27 Jul 2022 17:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241667AbiG0RQJ (ORCPT ); Wed, 27 Jul 2022 13:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241795AbiG0ROb (ORCPT ); Wed, 27 Jul 2022 13:14:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1CF77572; Wed, 27 Jul 2022 09:42:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 840D0B8200D; Wed, 27 Jul 2022 16:42:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCF52C433C1; Wed, 27 Jul 2022 16:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940166; bh=p1mKswKA82g8eOfFbK/W8nJGLiC3+vljUyxkXSYih3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uNqOzLmIDn/YDoY5rCW7shrh6nsaF6GMnPW8scN16kjuF4zFxpyKLoQLsLG6ssaRb Qm4X8Ejq0UEjqnvPIBfuk6djqqAAFfLHt1rorWCaunSI5sIjNAgJ9Dy3hf2pPg7Ta+ DFXvBI4GHduHvnVd7qsq4FUuS4BZZlWfjcIMNpBk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 128/201] tcp: Fix a data-race around sysctl_tcp_rfc1337. Date: Wed, 27 Jul 2022 18:10:32 +0200 Message-Id: <20220727161033.079405045@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 0b484c91911e758e53656d570de58c2ed81ec6f2 ] While reading sysctl_tcp_rfc1337, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_minisocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 13783fc58e03..39d8101e8f99 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -180,7 +180,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *t= w, struct sk_buff *skb, * Oh well... nobody has a sufficient solution to this * protocol bug yet. */ - if (twsk_net(tw)->ipv4.sysctl_tcp_rfc1337 =3D=3D 0) { + if (!READ_ONCE(twsk_net(tw)->ipv4.sysctl_tcp_rfc1337)) { kill: inet_twsk_deschedule_put(tw); return TCP_TW_SUCCESS; --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08050C04A68 for ; Wed, 27 Jul 2022 17:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241679AbiG0RQL (ORCPT ); Wed, 27 Jul 2022 13:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241836AbiG0ROi (ORCPT ); Wed, 27 Jul 2022 13:14:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E470B77A70; Wed, 27 Jul 2022 09:42:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5191DB8200C; Wed, 27 Jul 2022 16:42:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B788EC433D6; Wed, 27 Jul 2022 16:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940169; bh=IFTfDq/nVu8Qnxd+Azjs3hp0b6V9a7EczhZA0GvkXpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FDP++Xiqpvj+y2Apfh1BE3djzNU8/pMAtZzufWuv8YI3+Iin3/5UP2H46YSn0ThFr DJobb31Hhj6yGPAIgoPXMsC0W7TgFpbg/HURAQgrAFNFaUrepo/RDk6jtxXHuqNNQ8 Fxx4NLTCyp2PLLUvjXY/gvDGOvAalG3jKBtSmeOI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 129/201] tcp: Fix a data-race around sysctl_tcp_abort_on_overflow. Date: Wed, 27 Jul 2022 18:10:33 +0200 Message-Id: <20220727161033.123532033@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit 2d17d9c7382327d00aeaea35af44e9b26d53206e ] While reading sysctl_tcp_abort_on_overflow, it can be changed concurrently. Thus, we need to add READ_ONCE() to its reader. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_minisocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 39d8101e8f99..41368e77fbb8 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -789,7 +789,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_b= uff *skb, if (sk !=3D req->rsk_listener) __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMIGRATEREQFAILURE); =20 - if (!sock_net(sk)->ipv4.sysctl_tcp_abort_on_overflow) { + if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_abort_on_overflow)) { inet_rsk(req)->acked =3D 1; return NULL; } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B9DDC04A68 for ; Wed, 27 Jul 2022 17:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241692AbiG0RQO (ORCPT ); Wed, 27 Jul 2022 13:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241897AbiG0ROo (ORCPT ); Wed, 27 Jul 2022 13:14:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7835378208; Wed, 27 Jul 2022 09:42:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 255BFB821A6; Wed, 27 Jul 2022 16:42:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73CA4C433C1; Wed, 27 Jul 2022 16:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940171; bh=Tw6UWWkLeLNhHN4n5Og//nBQliGEATcfi0b3897XIO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VA3U2LDjuDHisz5cmwhw/91Oy0a72eTBQmXOVFFQFmMMucWxE2FY27SFFSiQ25w5q 25bUJ1M2s0F3E7f1sBVaErMoGREgSmHw8LEsv7wquHYzJeqRB26afRdXKBt0TZiWSu fCjZxtISQtNCrISkmKtcVzbpZ1kbcAr9LKGKOBMw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 130/201] tcp: Fix data-races around sysctl_tcp_max_reordering. Date: Wed, 27 Jul 2022 18:10:34 +0200 Message-Id: <20220727161033.171437127@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kuniyuki Iwashima [ Upstream commit a11e5b3e7a59fde1a90b0eaeaa82320495cf8cae ] While reading sysctl_tcp_max_reordering, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: dca145ffaa8d ("tcp: allow for bigger reordering level") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/ipv4/tcp_input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 6309a4eb3acd..2d21d8bf3b8c 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -1043,7 +1043,7 @@ static void tcp_check_sack_reordering(struct sock *sk= , const u32 low_seq, tp->undo_marker ? tp->undo_retrans : 0); #endif tp->reordering =3D min_t(u32, (metric + mss - 1) / mss, - sock_net(sk)->ipv4.sysctl_tcp_max_reordering); + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_max_reordering)); } =20 /* This exciting event is worth to be remembered. 8) */ @@ -2022,7 +2022,7 @@ static void tcp_check_reno_reordering(struct sock *sk= , const int addend) return; =20 tp->reordering =3D min_t(u32, tp->packets_out + addend, - sock_net(sk)->ipv4.sysctl_tcp_max_reordering); + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_max_reordering)); tp->reord_seen++; NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRENOREORDER); } --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65CAEC04A68 for ; Wed, 27 Jul 2022 17:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232124AbiG0RQc (ORCPT ); Wed, 27 Jul 2022 13:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236728AbiG0RPC (ORCPT ); Wed, 27 Jul 2022 13:15:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A57B078220; Wed, 27 Jul 2022 09:42:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E2BC6B8200D; Wed, 27 Jul 2022 16:42:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33294C433D6; Wed, 27 Jul 2022 16:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940174; bh=BYO7tIJ/ygk6lWF6pkc7YfJY1wS5uocuaZiaB1xDZH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IKhMzIwUr27bjmZbor9qhvCaa2RcnKPZeBCONjKV74bgcaSEGVWZRJulga9cU274Z NJW34QX7tUO8zv+cQ53PoUBN0s0+5ON7XKGeMEy/w1dNI4j9lJsWsEbQHXCFCi2ILR JtWQavzAOxfVqGDid2FlnShOYQnqTUpqsr32wskM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Srinivas Neeli , Bartosz Golaszewski , Sasha Levin Subject: [PATCH 5.15 131/201] gpio: gpio-xilinx: Fix integer overflow Date: Wed, 27 Jul 2022 18:10:35 +0200 Message-Id: <20220727161033.221183811@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Srinivas Neeli [ Upstream commit 32c094a09d5829ad9b02cdf667569aefa8de0ea6 ] Current implementation is not able to configure more than 32 pins due to incorrect data type. So type casting with unsigned long to avoid it. Fixes: 02b3f84d9080 ("xilinx: Switch to use bitmap APIs") Signed-off-by: Srinivas Neeli Signed-off-by: Bartosz Golaszewski Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpio/gpio-xilinx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index a1b66338d077..db616ae560a3 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -99,7 +99,7 @@ static inline void xgpio_set_value32(unsigned long *map, = int bit, u32 v) const unsigned long offset =3D (bit % BITS_PER_LONG) & BIT(5); =20 map[index] &=3D ~(0xFFFFFFFFul << offset); - map[index] |=3D v << offset; + map[index] |=3D (unsigned long)v << offset; } =20 static inline int xgpio_regoffset(struct xgpio_instance *chip, int ch) --=20 2.35.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 990AFC04A68 for ; Wed, 27 Jul 2022 17:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233880AbiG0RQf (ORCPT ); Wed, 27 Jul 2022 13:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241590AbiG0RPb (ORCPT ); Wed, 27 Jul 2022 13:15:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 518155C37F; Wed, 27 Jul 2022 09:43:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 96EE1B821AC; Wed, 27 Jul 2022 16:42:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2D11C433C1; Wed, 27 Jul 2022 16:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940177; bh=D6lvZDOlW//hEWRg9C+IUetipLsoLf/v/3N28GN55mQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nLq+Yo3k/kenBQnhpM6yd+mPMqVwcePi5EoGVDPf5WPtDuoKO58ZtZvlbrRZMHdHJ o34qvx9AwR11TJI59WMgVauMEBm49V/+qRgyVjm2X1fEGpUdBRL+omCfpy7L1zA57+ T6X+2P7OiK3RCePNgEe/k5x1Gl3ER/8iqWnyBWqw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Gavin Shan , Oliver Upton , Andrew Jones , Paolo Bonzini Subject: [PATCH 5.15 132/201] KVM: selftests: Fix target thread to be migrated in rseq_test Date: Wed, 27 Jul 2022 18:10:36 +0200 Message-Id: <20220727161033.268900056@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Gavin Shan commit e923b0537d28e15c9d31ce8b38f810b325816903 upstream. In rseq_test, there are two threads, which are vCPU thread and migration worker separately. Unfortunately, the test has the wrong PID passed to sched_setaffinity() in the migration worker. It forces migration on the migration worker because zeroed PID represents the calling thread, which is the migration worker itself. It means the vCPU thread is never enforced to migration and it can migrate at any time, which eventually leads to failure as the following logs show. host# uname -r 5.19.0-rc6-gavin+ host# # cat /proc/cpuinfo | grep processor | tail -n 1 processor : 223 host# pwd /home/gavin/sandbox/linux.main/tools/testing/selftests/kvm host# for i in `seq 1 100`; do \ echo "--------> $i"; ./rseq_test; done --------> 1 --------> 2 --------> 3 --------> 4 --------> 5 --------> 6 =3D=3D=3D=3D Test Assertion Failure =3D=3D=3D=3D rseq_test.c:265: rseq_cpu =3D=3D cpu pid=3D3925 tid=3D3925 errno=3D4 - Interrupted system call 1 0x0000000000401963: main at rseq_test.c:265 (discriminator 2) 2 0x0000ffffb044affb: ?? ??:0 3 0x0000ffffb044b0c7: ?? ??:0 4 0x0000000000401a6f: _start at ??:? rseq CPU =3D 4, sched CPU =3D 27 Fix the issue by passing correct parameter, TID of the vCPU thread, to sched_setaffinity() in the migration worker. Fixes: 61e52f1630f5 ("KVM: selftests: Add a test for KVM_RUN+rseq to detect= task migration bugs") Suggested-by: Sean Christopherson Signed-off-by: Gavin Shan Reviewed-by: Oliver Upton Message-Id: <20220719020830.3479482-1-gshan@redhat.com> Reviewed-by: Andrew Jones Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- tools/testing/selftests/kvm/rseq_test.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/rseq_test.c b/tools/testing/selfte= sts/kvm/rseq_test.c index 4158da0da2bb..2237d1aac801 100644 --- a/tools/testing/selftests/kvm/rseq_test.c +++ b/tools/testing/selftests/kvm/rseq_test.c @@ -82,8 +82,9 @@ static int next_cpu(int cpu) return cpu; } =20 -static void *migration_worker(void *ign) +static void *migration_worker(void *__rseq_tid) { + pid_t rseq_tid =3D (pid_t)(unsigned long)__rseq_tid; cpu_set_t allowed_mask; int r, i, cpu; =20 @@ -106,7 +107,7 @@ static void *migration_worker(void *ign) * stable, i.e. while changing affinity is in-progress. */ smp_wmb(); - r =3D sched_setaffinity(0, sizeof(allowed_mask), &allowed_mask); + r =3D sched_setaffinity(rseq_tid, sizeof(allowed_mask), &allowed_mask); TEST_ASSERT(!r, "sched_setaffinity failed, errno =3D %d (%s)", errno, strerror(errno)); smp_wmb(); @@ -231,7 +232,8 @@ int main(int argc, char *argv[]) vm =3D vm_create_default(VCPU_ID, 0, guest_code); ucall_init(vm, NULL); =20 - pthread_create(&migration_thread, NULL, migration_worker, 0); + pthread_create(&migration_thread, NULL, migration_worker, + (void *)(unsigned long)gettid()); =20 for (i =3D 0; !done; i++) { vcpu_run(vm, VCPU_ID); --=20 2.37.1 From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F28E3C04A68 for ; Wed, 27 Jul 2022 17:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiG0RQu (ORCPT ); Wed, 27 Jul 2022 13:16:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241655AbiG0RPz (ORCPT ); Wed, 27 Jul 2022 13:15:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B39AB7859D; Wed, 27 Jul 2022 09:43:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7374E614DE; Wed, 27 Jul 2022 16:43:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C314C433C1; Wed, 27 Jul 2022 16:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940182; bh=Nz5k/Pa4IhuCRVsu7UChZptB4Ka9QpSOYr0VI7yB1mQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cEqTm86UdqkLIy9bKS1+KzteD3jMRCzwWOyAT8HkE0Ob5P1YH7hxu+Ic4RORl4hjf q7/BTD/6XWAntzM2wQ2nf/ka5CUv4VRlN/fCzmtQB12JLZ1OtAkXWQHXZfANouymi3 OeOGnsQpLQ4e4boFF+k9nQcoyq492p/YgSkhXwSw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Marc Kleine-Budde , Mark Brown Subject: [PATCH 5.15 133/201] spi: bcm2835: bcm2835_spi_handle_err(): fix NULL pointer deref for non DMA transfers Date: Wed, 27 Jul 2022 18:10:37 +0200 Message-Id: <20220727161033.307712918@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Kleine-Budde commit 4ceaa684459d414992acbefb4e4c31f2dfc50641 upstream. In case a IRQ based transfer times out the bcm2835_spi_handle_err() function is called. Since commit 1513ceee70f2 ("spi: bcm2835: Drop dma_pending flag") the TX and RX DMA transfers are unconditionally canceled, leading to NULL pointer derefs if ctlr->dma_tx or ctlr->dma_rx are not set. Fix the NULL pointer deref by checking that ctlr->dma_tx and ctlr->dma_rx are valid pointers before accessing them. Fixes: 1513ceee70f2 ("spi: bcm2835: Drop dma_pending flag") Cc: Lukas Wunner Signed-off-by: Marc Kleine-Budde Link: https://lore.kernel.org/r/20220719072234.2782764-1-mkl@pengutronix.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/spi/spi-bcm2835.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -1138,10 +1138,14 @@ static void bcm2835_spi_handle_err(struc struct bcm2835_spi *bs =3D spi_controller_get_devdata(ctlr); =20 /* if an error occurred and we have an active dma, then terminate */ - dmaengine_terminate_sync(ctlr->dma_tx); - bs->tx_dma_active =3D false; - dmaengine_terminate_sync(ctlr->dma_rx); - bs->rx_dma_active =3D false; + if (ctlr->dma_tx) { + dmaengine_terminate_sync(ctlr->dma_tx); + bs->tx_dma_active =3D false; + } + if (ctlr->dma_rx) { + dmaengine_terminate_sync(ctlr->dma_rx); + bs->rx_dma_active =3D false; + } bcm2835_spi_undo_prologue(bs); =20 /* and reset */ From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF3CBC04A68 for ; Wed, 27 Jul 2022 17:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241738AbiG0RRF (ORCPT ); Wed, 27 Jul 2022 13:17:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241701AbiG0RQW (ORCPT ); Wed, 27 Jul 2022 13:16:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D29CF5C950; Wed, 27 Jul 2022 09:43:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4DD4E601CE; Wed, 27 Jul 2022 16:43:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FAB9C433D6; Wed, 27 Jul 2022 16:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940185; bh=SVt23Q0d84gwrhaqA8w8sNWD9r1w9t4co/Eki16M7MI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FlTcmQhNBvC+AHzLzg80H6GbQwxRE7bkhyh9v9jWK3LWdzIYtcJSMsq9uemWxpZRB C4N+ck4MdD/Q6htQ1nz30NN5L02Qtyg+6s3ir6jK6R7oiksN7TSuH9gPrncH71s5jG tQQ98FOQsghUHx44HaX5s2QedkS5yLC7rgf6OuxA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Bonzini , Alexey Kardashevskiy Subject: [PATCH 5.15 134/201] KVM: Dont null dereference ops->destroy Date: Wed, 27 Jul 2022 18:10:38 +0200 Message-Id: <20220727161033.348145340@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alexey Kardashevskiy commit e8bc2427018826e02add7b0ed0fc625a60390ae5 upstream. A KVM device cleanup happens in either of two callbacks: 1) destroy() which is called when the VM is being destroyed; 2) release() which is called when a device fd is closed. Most KVM devices use 1) but Book3s's interrupt controller KVM devices (XICS, XIVE, XIVE-native) use 2) as they need to close and reopen during the machine execution. The error handling in kvm_ioctl_create_device() assumes destroy() is always defined which leads to NULL dereference as discovered by Syzkaller. This adds a checks for destroy!=3DNULL and adds a missing release(). This is not changing kvm_destroy_devices() as devices with defined release() should have been removed from the KVM devices list by then. Suggested-by: Paolo Bonzini Signed-off-by: Alexey Kardashevskiy Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- virt/kvm/kvm_main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4172,8 +4172,11 @@ static int kvm_ioctl_create_device(struc kvm_put_kvm_no_destroy(kvm); mutex_lock(&kvm->lock); list_del(&dev->vm_node); + if (ops->release) + ops->release(dev); mutex_unlock(&kvm->lock); - ops->destroy(dev); + if (ops->destroy) + ops->destroy(dev); return ret; } From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FFE4C19F2B for ; Wed, 27 Jul 2022 17:17:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241629AbiG0RRZ (ORCPT ); Wed, 27 Jul 2022 13:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236728AbiG0RQd (ORCPT ); Wed, 27 Jul 2022 13:16:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9F8B78DC3; Wed, 27 Jul 2022 09:43:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 37496601C3; Wed, 27 Jul 2022 16:43:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CB3DC433C1; Wed, 27 Jul 2022 16:43:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940188; bh=0ziMNeRtCw7COVqd3tKBPmGOKRrhnAWnyhUBOdfxxG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1Eczm/yb6nX05EvFeQaq/aJKz+6w6nB6kKSULm4Buh9zmF9iSGTHBcezx+fvFnOm gBVDr5JNLCblkAOqyIOw+/dUkx7/Y5CCWy2ZYnWUUeN8iBpEI3Sf3BNHaS4ggvp3fP Pul32SOW0f3WBP8xKgW1D29kdi545W/c7oK3x+sA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wang Cheng , syzbot+217f792c92599518a2ab@syzkaller.appspotmail.com, David Rientjes , Vlastimil Babka , Andrew Morton Subject: [PATCH 5.15 135/201] mm/mempolicy: fix uninit-value in mpol_rebind_policy() Date: Wed, 27 Jul 2022 18:10:39 +0200 Message-Id: <20220727161033.395873394@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Wang Cheng commit 018160ad314d75b1409129b2247b614a9f35894c upstream. mpol_set_nodemask()(mm/mempolicy.c) does not set up nodemask when pol->mode is MPOL_LOCAL. Check pol->mode before access pol->w.cpuset_mems_allowed in mpol_rebind_policy()(mm/mempolicy.c). BUG: KMSAN: uninit-value in mpol_rebind_policy mm/mempolicy.c:352 [inline] BUG: KMSAN: uninit-value in mpol_rebind_task+0x2ac/0x2c0 mm/mempolicy.c:368 mpol_rebind_policy mm/mempolicy.c:352 [inline] mpol_rebind_task+0x2ac/0x2c0 mm/mempolicy.c:368 cpuset_change_task_nodemask kernel/cgroup/cpuset.c:1711 [inline] cpuset_attach+0x787/0x15e0 kernel/cgroup/cpuset.c:2278 cgroup_migrate_execute+0x1023/0x1d20 kernel/cgroup/cgroup.c:2515 cgroup_migrate kernel/cgroup/cgroup.c:2771 [inline] cgroup_attach_task+0x540/0x8b0 kernel/cgroup/cgroup.c:2804 __cgroup1_procs_write+0x5cc/0x7a0 kernel/cgroup/cgroup-v1.c:520 cgroup1_tasks_write+0x94/0xb0 kernel/cgroup/cgroup-v1.c:539 cgroup_file_write+0x4c2/0x9e0 kernel/cgroup/cgroup.c:3852 kernfs_fop_write_iter+0x66a/0x9f0 fs/kernfs/file.c:296 call_write_iter include/linux/fs.h:2162 [inline] new_sync_write fs/read_write.c:503 [inline] vfs_write+0x1318/0x2030 fs/read_write.c:590 ksys_write+0x28b/0x510 fs/read_write.c:643 __do_sys_write fs/read_write.c:655 [inline] __se_sys_write fs/read_write.c:652 [inline] __x64_sys_write+0xdb/0x120 fs/read_write.c:652 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x54/0xd0 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x44/0xae Uninit was created at: slab_post_alloc_hook mm/slab.h:524 [inline] slab_alloc_node mm/slub.c:3251 [inline] slab_alloc mm/slub.c:3259 [inline] kmem_cache_alloc+0x902/0x11c0 mm/slub.c:3264 mpol_new mm/mempolicy.c:293 [inline] do_set_mempolicy+0x421/0xb70 mm/mempolicy.c:853 kernel_set_mempolicy mm/mempolicy.c:1504 [inline] __do_sys_set_mempolicy mm/mempolicy.c:1510 [inline] __se_sys_set_mempolicy+0x44c/0xb60 mm/mempolicy.c:1507 __x64_sys_set_mempolicy+0xd8/0x110 mm/mempolicy.c:1507 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x54/0xd0 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x44/0xae KMSAN: uninit-value in mpol_rebind_task (2) https://syzkaller.appspot.com/bug?id=3Dd6eb90f952c2a5de9ea718a1b873c55cb13b= 59dc This patch seems to fix below bug too. KMSAN: uninit-value in mpol_rebind_mm (2) https://syzkaller.appspot.com/bug?id=3Df2fecd0d7013f54ec4162f60743a2b28df40= 926b The uninit-value is pol->w.cpuset_mems_allowed in mpol_rebind_policy(). When syzkaller reproducer runs to the beginning of mpol_new(), mpol_new() mm/mempolicy.c do_mbind() mm/mempolicy.c kernel_mbind() mm/mempolicy.c `mode` is 1(MPOL_PREFERRED), nodes_empty(*nodes) is `true` and `flags` is 0. Then mode =3D MPOL_LOCAL; ... policy->mode =3D mode; policy->flags =3D flags; will be executed. So in mpol_set_nodemask(), mpol_set_nodemask() mm/mempolicy.c do_mbind() kernel_mbind() pol->mode is 4 (MPOL_LOCAL), that `nodemask` in `pol` is not initialized, which will be accessed in mpol_rebind_policy(). Link: https://lkml.kernel.org/r/20220512123428.fq3wofedp6oiotd4@ppc.localdo= main Signed-off-by: Wang Cheng Reported-by: Tested-by: Cc: David Rientjes Cc: Vlastimil Babka Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -347,7 +347,7 @@ static void mpol_rebind_preferred(struct */ static void mpol_rebind_policy(struct mempolicy *pol, const nodemask_t *ne= wmask) { - if (!pol) + if (!pol || pol->mode =3D=3D MPOL_LOCAL) return; if (!mpol_store_user_nodemask(pol) && nodes_equal(pol->w.cpuset_mems_allowed, *newmask)) From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDD62C19F28 for ; Wed, 27 Jul 2022 17:17:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241720AbiG0RRg (ORCPT ); Wed, 27 Jul 2022 13:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241652AbiG0RQr (ORCPT ); Wed, 27 Jul 2022 13:16:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E47EC78DCE; Wed, 27 Jul 2022 09:43:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DA22CB8200C; Wed, 27 Jul 2022 16:43:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26EE5C433D7; Wed, 27 Jul 2022 16:43:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940191; bh=njurI18qD1t1r66D78QE8tvSsJDqwpTLVeo3OeAw6N4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RYtvxZDwY1pk3cQUVots/Xr++2B+LTLdwdgso2YunB0xXqo/hHkdxHXBbDxb/ORwo vDVeANNHtb0WTzNf3ylvmilU2mLet8lsrCwydBGqBXdojf0cOZLnKQIHQktikjMXl/ iS3cpR3c216T+PesZKqU2s0Fafjq4RIjf7TcTJEs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Eric Dumazet , Daniel Borkmann Subject: [PATCH 5.15 136/201] bpf: Make sure mac_header was set before using it Date: Wed, 27 Jul 2022 18:10:40 +0200 Message-Id: <20220727161033.442229540@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Eric Dumazet commit 0326195f523a549e0a9d7fd44c70b26fd7265090 upstream. Classic BPF has a way to load bytes starting from the mac header. Some skbs do not have a mac header, and skb_mac_header() in this case is returning a pointer that 65535 bytes after skb->head. Existing range check in bpf_internal_load_pointer_neg_helper() was properly kicking and no illegal access was happening. New sanity check in skb_mac_header() is firing, so we need to avoid it. WARNING: CPU: 1 PID: 28990 at include/linux/skbuff.h:2785 skb_mac_header in= clude/linux/skbuff.h:2785 [inline] WARNING: CPU: 1 PID: 28990 at include/linux/skbuff.h:2785 bpf_internal_load= _pointer_neg_helper+0x1b1/0x1c0 kernel/bpf/core.c:74 Modules linked in: CPU: 1 PID: 28990 Comm: syz-executor.0 Not tainted 5.19.0-rc4-syzkaller-008= 65-g4874fb9484be #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Goo= gle 06/29/2022 RIP: 0010:skb_mac_header include/linux/skbuff.h:2785 [inline] RIP: 0010:bpf_internal_load_pointer_neg_helper+0x1b1/0x1c0 kernel/bpf/core.= c:74 Code: ff ff 45 31 f6 e9 5a ff ff ff e8 aa 27 40 00 e9 3b ff ff ff e8 90 27 = 40 00 e9 df fe ff ff e8 86 27 40 00 eb 9e e8 2f 2c f3 ff <0f> 0b eb b1 e8 9= 6 27 40 00 e9 79 fe ff ff 90 41 57 41 56 41 55 41 RSP: 0018:ffffc9000309f668 EFLAGS: 00010216 RAX: 0000000000000118 RBX: ffffffffffeff00c RCX: ffffc9000e417000 RDX: 0000000000040000 RSI: ffffffff81873f21 RDI: 0000000000000003 RBP: ffff8880842878c0 R08: 0000000000000003 R09: 000000000000ffff R10: 000000000000ffff R11: 0000000000000001 R12: 0000000000000004 R13: ffff88803ac56c00 R14: 000000000000ffff R15: dffffc0000000000 FS: 00007f5c88a16700(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fdaa9f6c058 CR3: 000000003a82c000 CR4: 00000000003506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: ____bpf_skb_load_helper_32 net/core/filter.c:276 [inline] bpf_skb_load_helper_32+0x191/0x220 net/core/filter.c:264 Fixes: f9aefd6b2aa3 ("net: warn if mac header was not set") Reported-by: syzbot Signed-off-by: Eric Dumazet Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220707123900.945305-1-edumazet@google.c= om Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/bpf/core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -66,11 +66,13 @@ void *bpf_internal_load_pointer_neg_help { u8 *ptr =3D NULL; =20 - if (k >=3D SKF_NET_OFF) + if (k >=3D SKF_NET_OFF) { ptr =3D skb_network_header(skb) + k - SKF_NET_OFF; - else if (k >=3D SKF_LL_OFF) + } else if (k >=3D SKF_LL_OFF) { + if (unlikely(!skb_mac_header_was_set(skb))) + return NULL; ptr =3D skb_mac_header(skb) + k - SKF_LL_OFF; - + } if (ptr >=3D skb->head && ptr + size <=3D skb_tail_pointer(skb)) return ptr; From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BDEEC19F28 for ; Wed, 27 Jul 2022 17:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242001AbiG0RWw (ORCPT ); Wed, 27 Jul 2022 13:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241816AbiG0RUY (ORCPT ); Wed, 27 Jul 2022 13:20:24 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21B1A5FD1; Wed, 27 Jul 2022 09:45:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id ED54ECE2314; Wed, 27 Jul 2022 16:45:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7732C433C1; Wed, 27 Jul 2022 16:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940308; bh=avZDDaQpycf6zwWtz0rxv7VLnt+N8pteV3NItPBxSkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0nh48BIiOlRSO2ZD/xX61AgzmFkWCJk5mNP0hoKy9oofFNCymrYHMFBl/h1xGFBQA kOktJ+YzNaHOZxuxI3eWz5TDpSlclw3KQL0Lnw6L2a6x+x3r2RghBrkY4jyGX0p+3d Afq+b9dVWPSPkFKrmzC2hxxaxk+w71T65/+l9ob4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Juri Lelli , "Peter Zijlstra (Intel)" Subject: [PATCH 5.15 137/201] sched/deadline: Fix BUG_ON condition for deboosted tasks Date: Wed, 27 Jul 2022 18:10:41 +0200 Message-Id: <20220727161033.482502962@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Juri Lelli commit ddfc710395cccc61247348df9eb18ea50321cbed upstream. Tasks the are being deboosted from SCHED_DEADLINE might enter enqueue_task_dl() one last time and hit an erroneous BUG_ON condition: since they are not boosted anymore, the if (is_dl_boosted()) branch is not taken, but the else if (!dl_prio) is and inside this one we BUG_ON(!is_dl_boosted), which is of course false (BUG_ON triggered) otherwise we had entered the if branch above. Long story short, the current condition doesn't make sense and always leads to triggering of a BUG. Fix this by only checking enqueue flags, properly: ENQUEUE_REPLENISH has to be present, but additional flags are not a problem. Fixes: 64be6f1f5f71 ("sched/deadline: Don't replenish from a !SCHED_DEADLIN= E entity") Signed-off-by: Juri Lelli Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20220714151908.533052-1-juri.lelli@redhat.c= om Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/sched/deadline.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1561,7 +1561,10 @@ static void enqueue_task_dl(struct rq *r * the throttle. */ p->dl.dl_throttled =3D 0; - BUG_ON(!is_dl_boosted(&p->dl) || flags !=3D ENQUEUE_REPLENISH); + if (!(flags & ENQUEUE_REPLENISH)) + printk_deferred_once("sched: DL de-boosted task PID %d: REPLENISH flag = missing\n", + task_pid_nr(p)); + return; } From nobody Wed Apr 15 02:54:32 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE8D9C04A68 for ; Wed, 27 Jul 2022 17:18:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbiG0RSw (ORCPT ); Wed, 27 Jul 2022 13:18:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241757AbiG0RR5 (ORCPT ); Wed, 27 Jul 2022 13:17:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B274D15D; Wed, 27 Jul 2022 09:43:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AB468B8200C; Wed, 27 Jul 2022 16:43:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 081BDC433D6; Wed, 27 Jul 2022 16:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940214; bh=xzLNXcz4miuOscNHT52+ulkgeYXs8Noj2UPKsvKI/sE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pxdYjgHKZ8s8YgmKdXT8Z/SsL4lDHSGwv+EWvf8wMNFN+FdH8ZD83u/FlTHRY3UpH sFtJaLR44fepa2T/VF+VKLbEvWIl8FU8zaededKFyTYjIfjnpE0Y7nu2FwYbPiUI4o zhTp9Jwuu0cEMjOrXxmtdzaRFKAoxOv29inWdkVE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pawan Gupta , "Peter Zijlstra (Intel)" , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.15 138/201] x86/bugs: Warn when "ibrs" mitigation is selected on Enhanced IBRS parts Date: Wed, 27 Jul 2022 18:10:42 +0200 Message-Id: <20220727161033.522685816@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Pawan Gupta commit eb23b5ef9131e6d65011de349a4d25ef1b3d4314 upstream. IBRS mitigation for spectre_v2 forces write to MSR_IA32_SPEC_CTRL at every kernel entry/exit. On Enhanced IBRS parts setting MSR_IA32_SPEC_CTRL[IBRS] only once at boot is sufficient. MSR writes at every kernel entry/exit incur unnecessary performance loss. When Enhanced IBRS feature is present, print a warning about this unnecessary performance loss. Signed-off-by: Pawan Gupta Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thadeu Lima de Souza Cascardo Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/2a5eaf54583c2bfe0edc4fea64006656256cca17.16= 57814857.git.pawan.kumar.gupta@linux.intel.com Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/kernel/cpu/bugs.c | 3 +++ 1 file changed, 3 insertions(+) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -968,6 +968,7 @@ static inline const char *spectre_v2_mod #define SPECTRE_V2_LFENCE_MSG "WARNING: LFENCE mitigation is not recommend= ed for this CPU, data leaks possible!\n" #define SPECTRE_V2_EIBRS_EBPF_MSG "WARNING: Unprivileged eBPF is enabled w= ith eIBRS on, data leaks possible via Spectre v2 BHB attacks!\n" #define SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG "WARNING: Unprivileged eBPF i= s enabled with eIBRS+LFENCE mitigation and SMT, data leaks possible via Spe= ctre v2 BHB attacks!\n" +#define SPECTRE_V2_IBRS_PERF_MSG "WARNING: IBRS mitigation selected on Enh= anced IBRS CPU, this may cause unnecessary performance loss\n" =20 #ifdef CONFIG_BPF_SYSCALL void unpriv_ebpf_notify(int new_state) @@ -1408,6 +1409,8 @@ static void __init spectre_v2_select_mit =20 case SPECTRE_V2_IBRS: setup_force_cpu_cap(X86_FEATURE_KERNEL_IBRS); + if (boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) + pr_warn(SPECTRE_V2_IBRS_PERF_MSG); break; =20 case SPECTRE_V2_LFENCE: From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEB9CC04A68 for ; Wed, 27 Jul 2022 17:20:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241880AbiG0RUt (ORCPT ); Wed, 27 Jul 2022 13:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241848AbiG0RTJ (ORCPT ); Wed, 27 Jul 2022 13:19:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C268F7A532; Wed, 27 Jul 2022 09:44:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4AF23600BE; Wed, 27 Jul 2022 16:44:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F185C433D6; Wed, 27 Jul 2022 16:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940245; bh=A3+YHfCrvIpMgnEHozcBVwDMUO4GeUXh7Zbh9Kt9iD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=weE8mLVp3W6imSUgeeTwR3VZJa8hR0LONwsEb4L5NvSqXCYyVRZkL9RS1znhzIq3j TQDRgjv4kzCVrvcfFMtpKFLMdOSHzV9NXvQxCeeTFqChH5K+uFeZqGUXeWl4lIk/TN 5LneZ37vVZYI4oLi8tebGz1LUxOkBNqJvGdkbDBo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Aring , David Teigland , Sasha Levin Subject: [PATCH 5.15 139/201] dlm: fix pending remove if msg allocation fails Date: Wed, 27 Jul 2022 18:10:43 +0200 Message-Id: <20220727161033.570162032@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alexander Aring [ Upstream commit ba58995909b5098ca4003af65b0ccd5a8d13dd25 ] This patch unsets ls_remove_len and ls_remove_name if a message allocation of a remove messages fails. In this case we never send a remove message out but set the per ls ls_remove_len ls_remove_name variable for a pending remove. Unset those variable should indicate possible waiters in wait_pending_remove() that no pending remove is going on at this moment. Cc: stable@vger.kernel.org Signed-off-by: Alexander Aring Signed-off-by: David Teigland Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/dlm/lock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c index bb9e85e8819c..9f93496d2cc9 100644 --- a/fs/dlm/lock.c +++ b/fs/dlm/lock.c @@ -4065,13 +4065,14 @@ static void send_repeat_remove(struct dlm_ls *ls, c= har *ms_name, int len) rv =3D _create_message(ls, sizeof(struct dlm_message) + len, dir_nodeid, DLM_MSG_REMOVE, &ms, &mh); if (rv) - return; + goto out; =20 memcpy(ms->m_extra, name, len); ms->m_hash =3D hash; =20 send_message(mh, ms); =20 +out: spin_lock(&ls->ls_remove_spin); ls->ls_remove_len =3D 0; memset(ls->ls_remove_name, 0, DLM_RESNAME_MAXLEN); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8E25C04A68 for ; Wed, 27 Jul 2022 17:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241683AbiG0RVq (ORCPT ); Wed, 27 Jul 2022 13:21:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241971AbiG0RTZ (ORCPT ); Wed, 27 Jul 2022 13:19:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 470C019C38; Wed, 27 Jul 2022 09:44:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AF41160D38; Wed, 27 Jul 2022 16:44:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6016C433C1; Wed, 27 Jul 2022 16:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940277; bh=JA3AAXwVN9ZQJj2fDN/opwjpde8xtFKG4pPy60HWmnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R/ekXHqdA4PHHk8ikIAul5Fjl+D/s8SH6jx0dlSNrimCnjeJOWRu0MQ5g0nRdZdfp kl+tO57h2p7MatHqox3GXEcpztxg6/w4HNseIB5PfCwtwfpM//AHO1nTapEnj3LYXB ChDkndB6qmiZcxQPtgGMWk7BZ/OtztL1Y7T/gzEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.15 140/201] x86/uaccess: Implement macros for CMPXCHG on user addresses Date: Wed, 27 Jul 2022 18:10:44 +0200 Message-Id: <20220727161033.609774999@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra [ Upstream commit 989b5db215a2f22f89d730b607b071d964780f10 ] Add support for CMPXCHG loops on userspace addresses. Provide both an "unsafe" version for tight loops that do their own uaccess begin/end, as well as a "safe" version for use cases where the CMPXCHG is not buried in a loop, e.g. KVM will resume the guest instead of looping when emulation of a guest atomic accesses fails the CMPXCHG. Provide 8-byte versions for 32-bit kernels so that KVM can do CMPXCHG on guest PAE PTEs, which are accessed via userspace addresses. Guard the asm_volatile_goto() variation with CC_HAS_ASM_GOTO_TIED_OUTPUT, the "+m" constraint fails on some compilers that otherwise support CC_HAS_ASM_GOTO_OUTPUT. Cc: stable@vger.kernel.org Signed-off-by: Peter Zijlstra (Intel) Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Message-Id: <20220202004945.2540433-3-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/uaccess.h | 142 +++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index bb1430283c72..2f4c9c168b11 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -414,6 +414,103 @@ do { \ =20 #endif // CONFIG_CC_ASM_GOTO_OUTPUT =20 +#ifdef CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT +#define __try_cmpxchg_user_asm(itype, ltype, _ptr, _pold, _new, label) ({ \ + bool success; \ + __typeof__(_ptr) _old =3D (__typeof__(_ptr))(_pold); \ + __typeof__(*(_ptr)) __old =3D *_old; \ + __typeof__(*(_ptr)) __new =3D (_new); \ + asm_volatile_goto("\n" \ + "1: " LOCK_PREFIX "cmpxchg"itype" %[new], %[ptr]\n"\ + _ASM_EXTABLE_UA(1b, %l[label]) \ + : CC_OUT(z) (success), \ + [ptr] "+m" (*_ptr), \ + [old] "+a" (__old) \ + : [new] ltype (__new) \ + : "memory" \ + : label); \ + if (unlikely(!success)) \ + *_old =3D __old; \ + likely(success); }) + +#ifdef CONFIG_X86_32 +#define __try_cmpxchg64_user_asm(_ptr, _pold, _new, label) ({ \ + bool success; \ + __typeof__(_ptr) _old =3D (__typeof__(_ptr))(_pold); \ + __typeof__(*(_ptr)) __old =3D *_old; \ + __typeof__(*(_ptr)) __new =3D (_new); \ + asm_volatile_goto("\n" \ + "1: " LOCK_PREFIX "cmpxchg8b %[ptr]\n" \ + _ASM_EXTABLE_UA(1b, %l[label]) \ + : CC_OUT(z) (success), \ + "+A" (__old), \ + [ptr] "+m" (*_ptr) \ + : "b" ((u32)__new), \ + "c" ((u32)((u64)__new >> 32)) \ + : "memory" \ + : label); \ + if (unlikely(!success)) \ + *_old =3D __old; \ + likely(success); }) +#endif // CONFIG_X86_32 +#else // !CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT +#define __try_cmpxchg_user_asm(itype, ltype, _ptr, _pold, _new, label) ({ \ + int __err =3D 0; \ + bool success; \ + __typeof__(_ptr) _old =3D (__typeof__(_ptr))(_pold); \ + __typeof__(*(_ptr)) __old =3D *_old; \ + __typeof__(*(_ptr)) __new =3D (_new); \ + asm volatile("\n" \ + "1: " LOCK_PREFIX "cmpxchg"itype" %[new], %[ptr]\n"\ + CC_SET(z) \ + "2:\n" \ + _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, \ + %[errout]) \ + : CC_OUT(z) (success), \ + [errout] "+r" (__err), \ + [ptr] "+m" (*_ptr), \ + [old] "+a" (__old) \ + : [new] ltype (__new) \ + : "memory", "cc"); \ + if (unlikely(__err)) \ + goto label; \ + if (unlikely(!success)) \ + *_old =3D __old; \ + likely(success); }) + +#ifdef CONFIG_X86_32 +/* + * Unlike the normal CMPXCHG, hardcode ECX for both success/fail and error. + * There are only six GPRs available and four (EAX, EBX, ECX, and EDX) are + * hardcoded by CMPXCHG8B, leaving only ESI and EDI. If the compiler uses + * both ESI and EDI for the memory operand, compilation will fail if the e= rror + * is an input+output as there will be no register available for input. + */ +#define __try_cmpxchg64_user_asm(_ptr, _pold, _new, label) ({ \ + int __result; \ + __typeof__(_ptr) _old =3D (__typeof__(_ptr))(_pold); \ + __typeof__(*(_ptr)) __old =3D *_old; \ + __typeof__(*(_ptr)) __new =3D (_new); \ + asm volatile("\n" \ + "1: " LOCK_PREFIX "cmpxchg8b %[ptr]\n" \ + "mov $0, %%ecx\n\t" \ + "setz %%cl\n" \ + "2:\n" \ + _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, %%ecx) \ + : [result]"=3Dc" (__result), \ + "+A" (__old), \ + [ptr] "+m" (*_ptr) \ + : "b" ((u32)__new), \ + "c" ((u32)((u64)__new >> 32)) \ + : "memory", "cc"); \ + if (unlikely(__result < 0)) \ + goto label; \ + if (unlikely(!__result)) \ + *_old =3D __old; \ + likely(__result); }) +#endif // CONFIG_X86_32 +#endif // CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT + /* FIXME: this hack is definitely wrong -AK */ struct __large_struct { unsigned long buf[100]; }; #define __m(x) (*(struct __large_struct __user *)(x)) @@ -506,6 +603,51 @@ do { \ } while (0) #endif // CONFIG_CC_HAS_ASM_GOTO_OUTPUT =20 +extern void __try_cmpxchg_user_wrong_size(void); + +#ifndef CONFIG_X86_32 +#define __try_cmpxchg64_user_asm(_ptr, _oldp, _nval, _label) \ + __try_cmpxchg_user_asm("q", "r", (_ptr), (_oldp), (_nval), _label) +#endif + +/* + * Force the pointer to u to match the size expected by the asm help= er. + * clang/LLVM compiles all cases and only discards the unused paths after + * processing errors, which breaks i386 if the pointer is an 8-byte value. + */ +#define unsafe_try_cmpxchg_user(_ptr, _oldp, _nval, _label) ({ \ + bool __ret; \ + __chk_user_ptr(_ptr); \ + switch (sizeof(*(_ptr))) { \ + case 1: __ret =3D __try_cmpxchg_user_asm("b", "q", \ + (__force u8 *)(_ptr), (_oldp), \ + (_nval), _label); \ + break; \ + case 2: __ret =3D __try_cmpxchg_user_asm("w", "r", \ + (__force u16 *)(_ptr), (_oldp), \ + (_nval), _label); \ + break; \ + case 4: __ret =3D __try_cmpxchg_user_asm("l", "r", \ + (__force u32 *)(_ptr), (_oldp), \ + (_nval), _label); \ + break; \ + case 8: __ret =3D __try_cmpxchg64_user_asm((__force u64 *)(_ptr), (_oldp)= ,\ + (_nval), _label); \ + break; \ + default: __try_cmpxchg_user_wrong_size(); \ + } \ + __ret; }) + +/* "Returns" 0 on success, 1 on failure, -EFAULT if the access faults. */ +#define __try_cmpxchg_user(_ptr, _oldp, _nval, _label) ({ \ + int __ret =3D -EFAULT; \ + __uaccess_begin_nospec(); \ + __ret =3D !unsafe_try_cmpxchg_user(_ptr, _oldp, _nval, _label); \ +_label: \ + __uaccess_end(); \ + __ret; \ + }) + /* * We want the unsafe accessors to always be inlined and use * the error labels - thus the macro games. --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04D2AC04A68 for ; Wed, 27 Jul 2022 17:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241837AbiG0RWF (ORCPT ); Wed, 27 Jul 2022 13:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242019AbiG0RTf (ORCPT ); Wed, 27 Jul 2022 13:19:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0F295C9C1; Wed, 27 Jul 2022 09:44:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0301461479; Wed, 27 Jul 2022 16:44:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1322FC433B5; Wed, 27 Jul 2022 16:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940291; bh=LaAiy6oA8wRBDndG/jd576RVds9v/VmyZte9tl5TmaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JU8227mjhqPSOSgldRhf8+wRZGMTlCCvztAPqhh7Qnme6FzHt4P6QJFzPo4W48Ci+ 6B5+l0f0YHgbYCGSp5j9Lk1dBzm+AO7GW2+uIRZVI/Uuhr50Xw7TaRiG+ZYvuqAW3u jqCPu2Vh4eEi3EnWqviEVGgoL3kcqx4BIvy79EyI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Sasha Levin Subject: [PATCH 5.15 141/201] x86/extable: Tidy up redundant handler functions Date: Wed, 27 Jul 2022 18:10:45 +0200 Message-Id: <20220727161033.656172234@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner [ Upstream commit 326b567f82df0c4c8f50092b9af9a3014616fb3c ] No need to have the same code all over the place. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20210908132524.963232825@linutronix.de Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/mm/extable.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index e1664e9f969c..d9a1046f3a98 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -39,9 +39,8 @@ __visible bool ex_handler_fault(const struct exception_ta= ble_entry *fixup, unsigned long error_code, unsigned long fault_addr) { - regs->ip =3D ex_fixup_addr(fixup); regs->ax =3D trapnr; - return true; + return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); } EXPORT_SYMBOL_GPL(ex_handler_fault); =20 @@ -76,8 +75,7 @@ __visible bool ex_handler_uaccess(const struct exception_= table_entry *fixup, unsigned long fault_addr) { WARN_ONCE(trapnr =3D=3D X86_TRAP_GP, "General protection fault in user ac= cess. Non-canonical address?"); - regs->ip =3D ex_fixup_addr(fixup); - return true; + return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); } EXPORT_SYMBOL(ex_handler_uaccess); =20 @@ -87,9 +85,7 @@ __visible bool ex_handler_copy(const struct exception_tab= le_entry *fixup, unsigned long fault_addr) { WARN_ONCE(trapnr =3D=3D X86_TRAP_GP, "General protection fault in user ac= cess. Non-canonical address?"); - regs->ip =3D ex_fixup_addr(fixup); - regs->ax =3D trapnr; - return true; + return ex_handler_fault(fixup, regs, trapnr, error_code, fault_addr); } EXPORT_SYMBOL(ex_handler_copy); =20 @@ -103,10 +99,9 @@ __visible bool ex_handler_rdmsr_unsafe(const struct exc= eption_table_entry *fixup show_stack_regs(regs); =20 /* Pretend that the read succeeded and returned 0. */ - regs->ip =3D ex_fixup_addr(fixup); regs->ax =3D 0; regs->dx =3D 0; - return true; + return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); } EXPORT_SYMBOL(ex_handler_rdmsr_unsafe); =20 @@ -121,8 +116,7 @@ __visible bool ex_handler_wrmsr_unsafe(const struct exc= eption_table_entry *fixup show_stack_regs(regs); =20 /* Pretend that the write succeeded. */ - regs->ip =3D ex_fixup_addr(fixup); - return true; + return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); } EXPORT_SYMBOL(ex_handler_wrmsr_unsafe); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96B3EC04A68 for ; Wed, 27 Jul 2022 17:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237549AbiG0RWM (ORCPT ); Wed, 27 Jul 2022 13:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242068AbiG0RTm (ORCPT ); Wed, 27 Jul 2022 13:19:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FF065D0FA; Wed, 27 Jul 2022 09:44:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7E219B8200D; Wed, 27 Jul 2022 16:44:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1513C433C1; Wed, 27 Jul 2022 16:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940294; bh=XM8LLTq/A9czvkII5l07LJYXoWg9J2CU3JwouMlRan8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xWb5bwGwRet9OPFGmR9/rIMrV0LwL7iMBziUP9btNlnC0j0j81zpQNG2p72fvweAn J1I1Y/TIZi6qXpn0UUA6yPwI5bflv6422HBZqH8lfgxt2TJgCH70Ks90IGkQyDd2ip iLBclFkuhqJDsQV8mqTCAWdlshJZL7ux2m5m0+DM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Sasha Levin Subject: [PATCH 5.15 142/201] x86/extable: Get rid of redundant macros Date: Wed, 27 Jul 2022 18:10:46 +0200 Message-Id: <20220727161033.703449241@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner [ Upstream commit 32fd8b59f91fcd3bf9459aa72d90345735cc2588 ] No point in defining the identical macros twice depending on C or assembly mode. They are still identical. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20210908132525.023659534@linutronix.de Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/asm.h | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h index 3ad3da9a7d97..719955e658a2 100644 --- a/arch/x86/include/asm/asm.h +++ b/arch/x86/include/asm/asm.h @@ -132,18 +132,6 @@ .long (handler) - . ; \ .popsection =20 -# define _ASM_EXTABLE(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_default) - -# define _ASM_EXTABLE_UA(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess) - -# define _ASM_EXTABLE_CPY(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_copy) - -# define _ASM_EXTABLE_FAULT(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault) - # ifdef CONFIG_KPROBES # define _ASM_NOKPROBE(entry) \ .pushsection "_kprobe_blacklist","aw" ; \ @@ -164,18 +152,6 @@ " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \ " .popsection\n" =20 -# define _ASM_EXTABLE(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_default) - -# define _ASM_EXTABLE_UA(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess) - -# define _ASM_EXTABLE_CPY(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_copy) - -# define _ASM_EXTABLE_FAULT(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault) - /* For C file, we already have NOKPROBE_SYMBOL macro */ =20 /* @@ -188,6 +164,18 @@ register unsigned long current_stack_pointer asm(_ASM_= SP); #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer) #endif /* __ASSEMBLY__ */ =20 +#define _ASM_EXTABLE(from, to) \ + _ASM_EXTABLE_HANDLE(from, to, ex_handler_default) + +#define _ASM_EXTABLE_UA(from, to) \ + _ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess) + +#define _ASM_EXTABLE_CPY(from, to) \ + _ASM_EXTABLE_HANDLE(from, to, ex_handler_copy) + +#define _ASM_EXTABLE_FAULT(from, to) \ + _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault) + #endif /* __KERNEL__ */ =20 #endif /* _ASM_X86_ASM_H */ --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 174F0C04A68 for ; Wed, 27 Jul 2022 17:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237715AbiG0RWP (ORCPT ); Wed, 27 Jul 2022 13:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242104AbiG0RTr (ORCPT ); Wed, 27 Jul 2022 13:19:47 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 671185247E; Wed, 27 Jul 2022 09:45:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 79AEECE2309; Wed, 27 Jul 2022 16:44:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C76EC433C1; Wed, 27 Jul 2022 16:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940296; bh=rOrmLFrxGWYV871MsyQQEIzigWMtnhgSC8ReLXbMgD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GSOjbKE3wU4s/4uEmDrTxwG3K8jSudBzGARySogdGE83epLpnYTM4cW/w/CAsa4/S EhhEIf5AtA1IQVcfZSgQhg9WwKFoMNT78yVlrWngb9i0vyZE8OjpB4tIkVUAhGMsxG FebxHdrvZct/f4a98IzvROwNZqEV/vIM0SRVhFdI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Sasha Levin Subject: [PATCH 5.15 143/201] x86/mce: Deduplicate exception handling Date: Wed, 27 Jul 2022 18:10:47 +0200 Message-Id: <20220727161033.735314528@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner [ Upstream commit e42404afc4ca856c48f1e05752541faa3587c472 ] Prepare code for further simplification. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20210908132525.096452100@linutronix.de Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/kernel/cpu/mce/core.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 848cfb013f58..d8da3acf1ffd 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -382,13 +382,16 @@ static int msr_to_offset(u32 msr) return -1; } =20 -__visible bool ex_handler_rdmsr_fault(const struct exception_table_entry *= fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr) { - pr_emerg("MSR access error: RDMSR from 0x%x at rIP: 0x%lx (%pS)\n", - (unsigned int)regs->cx, regs->ip, (void *)regs->ip); + if (wrmsr) { + pr_emerg("MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at= rIP: 0x%lx (%pS)\n", + (unsigned int)regs->cx, (unsigned int)regs->dx, (unsigned int)regs->ax, + regs->ip, (void *)regs->ip); + } else { + pr_emerg("MSR access error: RDMSR from 0x%x at rIP: 0x%lx (%pS)\n", + (unsigned int)regs->cx, regs->ip, (void *)regs->ip); + } =20 show_stack_regs(regs); =20 @@ -396,7 +399,14 @@ __visible bool ex_handler_rdmsr_fault(const struct exc= eption_table_entry *fixup, =20 while (true) cpu_relax(); +} =20 +__visible bool ex_handler_rdmsr_fault(const struct exception_table_entry *= fixup, + struct pt_regs *regs, int trapnr, + unsigned long error_code, + unsigned long fault_addr) +{ + ex_handler_msr_mce(regs, false); return true; } =20 @@ -441,17 +451,7 @@ __visible bool ex_handler_wrmsr_fault(const struct exc= eption_table_entry *fixup, unsigned long error_code, unsigned long fault_addr) { - pr_emerg("MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at = rIP: 0x%lx (%pS)\n", - (unsigned int)regs->cx, (unsigned int)regs->dx, (unsigned int)regs->ax, - regs->ip, (void *)regs->ip); - - show_stack_regs(regs); - - panic("MCA architectural violation!\n"); - - while (true) - cpu_relax(); - + ex_handler_msr_mce(regs, true); return true; } =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FC66C04A68 for ; Wed, 27 Jul 2022 17:22:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231824AbiG0RWX (ORCPT ); Wed, 27 Jul 2022 13:22:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242135AbiG0RTu (ORCPT ); Wed, 27 Jul 2022 13:19:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E30D85246E; Wed, 27 Jul 2022 09:45:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 29880B8200D; Wed, 27 Jul 2022 16:45:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 523CDC433C1; Wed, 27 Jul 2022 16:44:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940299; bh=1HCOeZQQWYffxviSOb/W6afWqRhKiLC1RthFBclkymQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ym9AzaqxqPDF23xy3ehiX88WIelGGiUQbj34HYRuO1D0IUEpUoZnKtjQo7q0p9yUB +GD9hRz9wl49FtnjWaMLpZtQ/N102MctEx/b3BDPvlJYISDROd0qoM/MNwo+c3+dpM d2yrJEwqIOs08PNCmFZz9tb8uoprguiKNreNzJQ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.15 144/201] x86/extable: Rework the exception table mechanics Date: Wed, 27 Jul 2022 18:10:48 +0200 Message-Id: <20220727161033.775548242@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner [ Upstream commit 46d28947d9876fc0f8f93d3c69813ef6e9852595 ] The exception table entries contain the instruction address, the fixup address and the handler address. All addresses are relative. Storing the handler address has a few downsides: 1) Most handlers need to be exported 2) Handlers can be defined everywhere and there is no overview about the handler types 3) MCE needs to check the handler type to decide whether an in kernel #MC can be recovered. The functionality of the handler itself is not in any way special, but for these checks there need to be separate functions which in the worst case have to be exported. Some of these 'recoverable' exception fixups are pretty obscure and just reuse some other handler to spare code. That obfuscates e.g. the #MC safe copy functions. Cleaning that up would require more handlers and exports Rework the exception fixup mechanics by storing a fixup type number instead of the handler address and invoke the proper handler for each fixup type. Also teach the extable sort to leave the type field alone. This makes most handlers static except for special cases like the MCE MSR fixup and the BPF fixup. This allows to add more types for cleaning up the obscure places without adding more handler code and exports. There is a marginal code size reduction for a production config and it removes _eight_ exported symbols. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Acked-by: Alexei Starovoitov Link: https://lkml.kernel.org/r/20210908132525.211958725@linutronix.de Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/asm.h | 22 ++-- arch/x86/include/asm/extable.h | 44 +++++--- arch/x86/include/asm/extable_fixup_types.h | 19 ++++ arch/x86/include/asm/fpu/internal.h | 4 +- arch/x86/include/asm/msr.h | 4 +- arch/x86/include/asm/segment.h | 2 +- arch/x86/kernel/cpu/mce/core.c | 24 +--- arch/x86/kernel/cpu/mce/internal.h | 10 -- arch/x86/kernel/cpu/mce/severity.c | 21 ++-- arch/x86/mm/extable.c | 123 +++++++++------------ arch/x86/net/bpf_jit_comp.c | 11 +- scripts/sorttable.c | 4 +- 12 files changed, 133 insertions(+), 155 deletions(-) create mode 100644 arch/x86/include/asm/extable_fixup_types.h diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h index 719955e658a2..6aadb9a620ee 100644 --- a/arch/x86/include/asm/asm.h +++ b/arch/x86/include/asm/asm.h @@ -122,14 +122,17 @@ =20 #ifdef __KERNEL__ =20 +# include + /* Exception table entry */ #ifdef __ASSEMBLY__ -# define _ASM_EXTABLE_HANDLE(from, to, handler) \ + +# define _ASM_EXTABLE_TYPE(from, to, type) \ .pushsection "__ex_table","a" ; \ .balign 4 ; \ .long (from) - . ; \ .long (to) - . ; \ - .long (handler) - . ; \ + .long type ; \ .popsection =20 # ifdef CONFIG_KPROBES @@ -143,13 +146,13 @@ # endif =20 #else /* ! __ASSEMBLY__ */ -# define _EXPAND_EXTABLE_HANDLE(x) #x -# define _ASM_EXTABLE_HANDLE(from, to, handler) \ + +# define _ASM_EXTABLE_TYPE(from, to, type) \ " .pushsection \"__ex_table\",\"a\"\n" \ " .balign 4\n" \ " .long (" #from ") - .\n" \ " .long (" #to ") - .\n" \ - " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n" \ + " .long " __stringify(type) " \n" \ " .popsection\n" =20 /* For C file, we already have NOKPROBE_SYMBOL macro */ @@ -165,17 +168,16 @@ register unsigned long current_stack_pointer asm(_ASM= _SP); #endif /* __ASSEMBLY__ */ =20 #define _ASM_EXTABLE(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_default) + _ASM_EXTABLE_TYPE(from, to, EX_TYPE_DEFAULT) =20 #define _ASM_EXTABLE_UA(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess) + _ASM_EXTABLE_TYPE(from, to, EX_TYPE_UACCESS) =20 #define _ASM_EXTABLE_CPY(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_copy) + _ASM_EXTABLE_TYPE(from, to, EX_TYPE_COPY) =20 #define _ASM_EXTABLE_FAULT(from, to) \ - _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault) + _ASM_EXTABLE_TYPE(from, to, EX_TYPE_FAULT) =20 #endif /* __KERNEL__ */ - #endif /* _ASM_X86_ASM_H */ diff --git a/arch/x86/include/asm/extable.h b/arch/x86/include/asm/extable.h index 1f0cbc52937c..93f400eb728f 100644 --- a/arch/x86/include/asm/extable.h +++ b/arch/x86/include/asm/extable.h @@ -1,12 +1,18 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef _ASM_X86_EXTABLE_H #define _ASM_X86_EXTABLE_H + +#include + /* - * The exception table consists of triples of addresses relative to the - * exception table entry itself. The first address is of an instruction - * that is allowed to fault, the second is the target at which the program - * should continue. The third is a handler function to deal with the fault - * caused by the instruction in the first field. + * The exception table consists of two addresses relative to the + * exception table entry itself and a type selector field. + * + * The first address is of an instruction that is allowed to fault, the + * second is the target at which the program should continue. + * + * The type entry is used by fixup_exception() to select the handler to + * deal with the fault caused by the instruction in the first field. * * All the routines below use bits of fixup code that are out of line * with the main instruction path. This means when everything is well, @@ -15,7 +21,7 @@ */ =20 struct exception_table_entry { - int insn, fixup, handler; + int insn, fixup, type; }; struct pt_regs; =20 @@ -25,21 +31,27 @@ struct pt_regs; do { \ (a)->fixup =3D (b)->fixup + (delta); \ (b)->fixup =3D (tmp).fixup - (delta); \ - (a)->handler =3D (b)->handler + (delta); \ - (b)->handler =3D (tmp).handler - (delta); \ + (a)->type =3D (b)->type; \ + (b)->type =3D (tmp).type; \ } while (0) =20 -enum handler_type { - EX_HANDLER_NONE, - EX_HANDLER_FAULT, - EX_HANDLER_UACCESS, - EX_HANDLER_OTHER -}; - extern int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_code, unsigned long fault_addr); extern int fixup_bug(struct pt_regs *regs, int trapnr); -extern enum handler_type ex_get_fault_handler_type(unsigned long ip); +extern int ex_get_fixup_type(unsigned long ip); extern void early_fixup_exception(struct pt_regs *regs, int trapnr); =20 +#ifdef CONFIG_X86_MCE +extern void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr); +#else +static inline void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr) { } +#endif + +#if defined(CONFIG_BPF_JIT) && defined(CONFIG_X86_64) +bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs = *regs); +#else +static inline bool ex_handler_bpf(const struct exception_table_entry *x, + struct pt_regs *regs) { return false; } +#endif + #endif diff --git a/arch/x86/include/asm/extable_fixup_types.h b/arch/x86/include/= asm/extable_fixup_types.h new file mode 100644 index 000000000000..0adc117618e6 --- /dev/null +++ b/arch/x86/include/asm/extable_fixup_types.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_EXTABLE_FIXUP_TYPES_H +#define _ASM_X86_EXTABLE_FIXUP_TYPES_H + +#define EX_TYPE_NONE 0 +#define EX_TYPE_DEFAULT 1 +#define EX_TYPE_FAULT 2 +#define EX_TYPE_UACCESS 3 +#define EX_TYPE_COPY 4 +#define EX_TYPE_CLEAR_FS 5 +#define EX_TYPE_FPU_RESTORE 6 +#define EX_TYPE_WRMSR 7 +#define EX_TYPE_RDMSR 8 +#define EX_TYPE_BPF 9 + +#define EX_TYPE_WRMSR_IN_MCE 10 +#define EX_TYPE_RDMSR_IN_MCE 11 + +#endif diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu= /internal.h index 5a18694a89b2..ce6fc4f8d1d1 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -126,7 +126,7 @@ extern void save_fpregs_to_fpstate(struct fpu *fpu); #define kernel_insn(insn, output, input...) \ asm volatile("1:" #insn "\n\t" \ "2:\n" \ - _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_fprestore) \ + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_FPU_RESTORE) \ : output : input) =20 static inline int fnsave_to_user_sigframe(struct fregs_state __user *fx) @@ -253,7 +253,7 @@ static inline void fxsave(struct fxregs_state *fx) XRSTORS, X86_FEATURE_XSAVES) \ "\n" \ "3:\n" \ - _ASM_EXTABLE_HANDLE(661b, 3b, ex_handler_fprestore)\ + _ASM_EXTABLE_TYPE(661b, 3b, EX_TYPE_FPU_RESTORE) \ : \ : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ : "memory") diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index a3f87f1015d3..6b52182e178a 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -92,7 +92,7 @@ static __always_inline unsigned long long __rdmsr(unsigne= d int msr) =20 asm volatile("1: rdmsr\n" "2:\n" - _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_rdmsr_unsafe) + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_RDMSR) : EAX_EDX_RET(val, low, high) : "c" (msr)); =20 return EAX_EDX_VAL(val, low, high); @@ -102,7 +102,7 @@ static __always_inline void __wrmsr(unsigned int msr, u= 32 low, u32 high) { asm volatile("1: wrmsr\n" "2:\n" - _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wrmsr_unsafe) + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR) : : "c" (msr), "a"(low), "d" (high) : "memory"); } =20 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h index 72044026eb3c..8dd8e8ec9fa5 100644 --- a/arch/x86/include/asm/segment.h +++ b/arch/x86/include/asm/segment.h @@ -339,7 +339,7 @@ static inline void __loadsegment_fs(unsigned short valu= e) "1: movw %0, %%fs \n" "2: \n" =20 - _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_clear_fs) + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_CLEAR_FS) =20 : : "rm" (value) : "memory"); } diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index d8da3acf1ffd..773037e5fd76 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -382,7 +382,7 @@ static int msr_to_offset(u32 msr) return -1; } =20 -static void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr) +void ex_handler_msr_mce(struct pt_regs *regs, bool wrmsr) { if (wrmsr) { pr_emerg("MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at= rIP: 0x%lx (%pS)\n", @@ -401,15 +401,6 @@ static void ex_handler_msr_mce(struct pt_regs *regs, b= ool wrmsr) cpu_relax(); } =20 -__visible bool ex_handler_rdmsr_fault(const struct exception_table_entry *= fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) -{ - ex_handler_msr_mce(regs, false); - return true; -} - /* MSR access wrappers used for error injection */ static noinstr u64 mce_rdmsrl(u32 msr) { @@ -439,22 +430,13 @@ static noinstr u64 mce_rdmsrl(u32 msr) */ asm volatile("1: rdmsr\n" "2:\n" - _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_rdmsr_fault) + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_RDMSR_IN_MCE) : EAX_EDX_RET(val, low, high) : "c" (msr)); =20 =20 return EAX_EDX_VAL(val, low, high); } =20 -__visible bool ex_handler_wrmsr_fault(const struct exception_table_entry *= fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) -{ - ex_handler_msr_mce(regs, true); - return true; -} - static noinstr void mce_wrmsrl(u32 msr, u64 v) { u32 low, high; @@ -479,7 +461,7 @@ static noinstr void mce_wrmsrl(u32 msr, u64 v) /* See comment in mce_rdmsrl() */ asm volatile("1: wrmsr\n" "2:\n" - _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wrmsr_fault) + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR_IN_MCE) : : "c" (msr), "a"(low), "d" (high) : "memory"); } =20 diff --git a/arch/x86/kernel/cpu/mce/internal.h b/arch/x86/kernel/cpu/mce/i= nternal.h index 88dcc79cfb07..80dc94313bcf 100644 --- a/arch/x86/kernel/cpu/mce/internal.h +++ b/arch/x86/kernel/cpu/mce/internal.h @@ -186,14 +186,4 @@ extern bool amd_filter_mce(struct mce *m); static inline bool amd_filter_mce(struct mce *m) { return false; }; #endif =20 -__visible bool ex_handler_rdmsr_fault(const struct exception_table_entry *= fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr); - -__visible bool ex_handler_wrmsr_fault(const struct exception_table_entry *= fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr); - #endif /* __X86_MCE_INTERNAL_H__ */ diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/s= everity.c index 17e631443116..74fe763bffda 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -265,25 +265,24 @@ static bool is_copy_from_user(struct pt_regs *regs) */ static int error_context(struct mce *m, struct pt_regs *regs) { - enum handler_type t; - if ((m->cs & 3) =3D=3D 3) return IN_USER; if (!mc_recoverable(m->mcgstatus)) return IN_KERNEL; =20 - t =3D ex_get_fault_handler_type(m->ip); - if (t =3D=3D EX_HANDLER_FAULT) { - m->kflags |=3D MCE_IN_KERNEL_RECOV; - return IN_KERNEL_RECOV; - } - if (t =3D=3D EX_HANDLER_UACCESS && regs && is_copy_from_user(regs)) { - m->kflags |=3D MCE_IN_KERNEL_RECOV; + switch (ex_get_fixup_type(m->ip)) { + case EX_TYPE_UACCESS: + case EX_TYPE_COPY: + if (!regs || !is_copy_from_user(regs)) + return IN_KERNEL; m->kflags |=3D MCE_IN_KERNEL_COPYIN; + fallthrough; + case EX_TYPE_FAULT: + m->kflags |=3D MCE_IN_KERNEL_RECOV; return IN_KERNEL_RECOV; + default: + return IN_KERNEL; } - - return IN_KERNEL; } =20 static int mce_severity_amd_smca(struct mce *m, enum context err_ctx) diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index d9a1046f3a98..5db46df409b5 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -9,40 +9,25 @@ #include #include =20 -typedef bool (*ex_handler_t)(const struct exception_table_entry *, - struct pt_regs *, int, unsigned long, - unsigned long); - static inline unsigned long ex_fixup_addr(const struct exception_table_entry *x) { return (unsigned long)&x->fixup + x->fixup; } -static inline ex_handler_t -ex_fixup_handler(const struct exception_table_entry *x) -{ - return (ex_handler_t)((unsigned long)&x->handler + x->handler); -} =20 -__visible bool ex_handler_default(const struct exception_table_entry *fixu= p, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_default(const struct exception_table_entry *fixup, + struct pt_regs *regs) { regs->ip =3D ex_fixup_addr(fixup); return true; } -EXPORT_SYMBOL(ex_handler_default); =20 -__visible bool ex_handler_fault(const struct exception_table_entry *fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_fault(const struct exception_table_entry *fixup, + struct pt_regs *regs, int trapnr) { regs->ax =3D trapnr; - return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); + return ex_handler_default(fixup, regs); } -EXPORT_SYMBOL_GPL(ex_handler_fault); =20 /* * Handler for when we fail to restore a task's FPU state. We should neve= r get @@ -54,10 +39,8 @@ EXPORT_SYMBOL_GPL(ex_handler_fault); * of vulnerability by restoring from the initial state (essentially, zero= ing * out all the FPU registers) if we can't restore from the task's FPU stat= e. */ -__visible bool ex_handler_fprestore(const struct exception_table_entry *fi= xup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_fprestore(const struct exception_table_entry *fixup, + struct pt_regs *regs) { regs->ip =3D ex_fixup_addr(fixup); =20 @@ -67,32 +50,23 @@ __visible bool ex_handler_fprestore(const struct except= ion_table_entry *fixup, __restore_fpregs_from_fpstate(&init_fpstate, xfeatures_mask_fpstate()); return true; } -EXPORT_SYMBOL_GPL(ex_handler_fprestore); =20 -__visible bool ex_handler_uaccess(const struct exception_table_entry *fixu= p, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_uaccess(const struct exception_table_entry *fixup, + struct pt_regs *regs, int trapnr) { WARN_ONCE(trapnr =3D=3D X86_TRAP_GP, "General protection fault in user ac= cess. Non-canonical address?"); - return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); + return ex_handler_default(fixup, regs); } -EXPORT_SYMBOL(ex_handler_uaccess); =20 -__visible bool ex_handler_copy(const struct exception_table_entry *fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_copy(const struct exception_table_entry *fixup, + struct pt_regs *regs, int trapnr) { WARN_ONCE(trapnr =3D=3D X86_TRAP_GP, "General protection fault in user ac= cess. Non-canonical address?"); - return ex_handler_fault(fixup, regs, trapnr, error_code, fault_addr); + return ex_handler_fault(fixup, regs, trapnr); } -EXPORT_SYMBOL(ex_handler_copy); =20 -__visible bool ex_handler_rdmsr_unsafe(const struct exception_table_entry = *fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_rdmsr_unsafe(const struct exception_table_entry *fi= xup, + struct pt_regs *regs) { if (pr_warn_once("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%= lx (%pS)\n", (unsigned int)regs->cx, regs->ip, (void *)regs->ip)) @@ -101,14 +75,11 @@ __visible bool ex_handler_rdmsr_unsafe(const struct ex= ception_table_entry *fixup /* Pretend that the read succeeded and returned 0. */ regs->ax =3D 0; regs->dx =3D 0; - return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); + return ex_handler_default(fixup, regs); } -EXPORT_SYMBOL(ex_handler_rdmsr_unsafe); =20 -__visible bool ex_handler_wrmsr_unsafe(const struct exception_table_entry = *fixup, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_wrmsr_unsafe(const struct exception_table_entry *fi= xup, + struct pt_regs *regs) { if (pr_warn_once("unchecked MSR access error: WRMSR to 0x%x (tried to wri= te 0x%08x%08x) at rIP: 0x%lx (%pS)\n", (unsigned int)regs->cx, (unsigned int)regs->dx, @@ -116,44 +87,29 @@ __visible bool ex_handler_wrmsr_unsafe(const struct ex= ception_table_entry *fixup show_stack_regs(regs); =20 /* Pretend that the write succeeded. */ - return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); + return ex_handler_default(fixup, regs); } -EXPORT_SYMBOL(ex_handler_wrmsr_unsafe); =20 -__visible bool ex_handler_clear_fs(const struct exception_table_entry *fix= up, - struct pt_regs *regs, int trapnr, - unsigned long error_code, - unsigned long fault_addr) +static bool ex_handler_clear_fs(const struct exception_table_entry *fixup, + struct pt_regs *regs) { if (static_cpu_has(X86_BUG_NULL_SEG)) asm volatile ("mov %0, %%fs" : : "rm" (__USER_DS)); asm volatile ("mov %0, %%fs" : : "rm" (0)); - return ex_handler_default(fixup, regs, trapnr, error_code, fault_addr); + return ex_handler_default(fixup, regs); } -EXPORT_SYMBOL(ex_handler_clear_fs); =20 -enum handler_type ex_get_fault_handler_type(unsigned long ip) +int ex_get_fixup_type(unsigned long ip) { - const struct exception_table_entry *e; - ex_handler_t handler; + const struct exception_table_entry *e =3D search_exception_tables(ip); =20 - e =3D search_exception_tables(ip); - if (!e) - return EX_HANDLER_NONE; - handler =3D ex_fixup_handler(e); - if (handler =3D=3D ex_handler_fault) - return EX_HANDLER_FAULT; - else if (handler =3D=3D ex_handler_uaccess || handler =3D=3D ex_handler_c= opy) - return EX_HANDLER_UACCESS; - else - return EX_HANDLER_OTHER; + return e ? e->type : EX_TYPE_NONE; } =20 int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_= code, unsigned long fault_addr) { const struct exception_table_entry *e; - ex_handler_t handler; =20 #ifdef CONFIG_PNPBIOS if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) { @@ -173,8 +129,33 @@ int fixup_exception(struct pt_regs *regs, int trapnr, = unsigned long error_code, if (!e) return 0; =20 - handler =3D ex_fixup_handler(e); - return handler(e, regs, trapnr, error_code, fault_addr); + switch (e->type) { + case EX_TYPE_DEFAULT: + return ex_handler_default(e, regs); + case EX_TYPE_FAULT: + return ex_handler_fault(e, regs, trapnr); + case EX_TYPE_UACCESS: + return ex_handler_uaccess(e, regs, trapnr); + case EX_TYPE_COPY: + return ex_handler_copy(e, regs, trapnr); + case EX_TYPE_CLEAR_FS: + return ex_handler_clear_fs(e, regs); + case EX_TYPE_FPU_RESTORE: + return ex_handler_fprestore(e, regs); + case EX_TYPE_RDMSR: + return ex_handler_rdmsr_unsafe(e, regs); + case EX_TYPE_WRMSR: + return ex_handler_wrmsr_unsafe(e, regs); + case EX_TYPE_BPF: + return ex_handler_bpf(e, regs); + case EX_TYPE_RDMSR_IN_MCE: + ex_handler_msr_mce(regs, false); + break; + case EX_TYPE_WRMSR_IN_MCE: + ex_handler_msr_mce(regs, true); + break; + } + BUG(); } =20 extern unsigned int early_recursion_flag; diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 131f7ceb54dc..4f3a60037150 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -832,9 +832,7 @@ static int emit_atomic(u8 **pprog, u8 atomic_op, return 0; } =20 -static bool ex_handler_bpf(const struct exception_table_entry *x, - struct pt_regs *regs, int trapnr, - unsigned long error_code, unsigned long fault_addr) +bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs = *regs) { u32 reg =3D x->fixup >> 8; =20 @@ -1344,12 +1342,7 @@ st: if (is_imm8(insn->off)) } ex->insn =3D delta; =20 - delta =3D (u8 *)ex_handler_bpf - (u8 *)&ex->handler; - if (!is_simm32(delta)) { - pr_err("extable->handler doesn't fit into 32-bit\n"); - return -EFAULT; - } - ex->handler =3D delta; + ex->type =3D EX_TYPE_BPF; =20 if (dst_reg > BPF_REG_9) { pr_err("verifier error\n"); diff --git a/scripts/sorttable.c b/scripts/sorttable.c index 6ee4fa882919..278bb53b325c 100644 --- a/scripts/sorttable.c +++ b/scripts/sorttable.c @@ -240,7 +240,7 @@ static void x86_sort_relative_table(char *extab_image, = int image_size) =20 w(r(loc) + i, loc); w(r(loc + 1) + i + 4, loc + 1); - w(r(loc + 2) + i + 8, loc + 2); + /* Don't touch the fixup type */ =20 i +=3D sizeof(uint32_t) * 3; } @@ -253,7 +253,7 @@ static void x86_sort_relative_table(char *extab_image, = int image_size) =20 w(r(loc) - i, loc); w(r(loc + 1) - (i + 4), loc + 1); - w(r(loc + 2) - (i + 8), loc + 2); + /* Don't touch the fixup type */ =20 i +=3D sizeof(uint32_t) * 3; } --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDD1FC04A68 for ; Wed, 27 Jul 2022 17:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241867AbiG0RWS (ORCPT ); Wed, 27 Jul 2022 13:22:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242133AbiG0RTu (ORCPT ); Wed, 27 Jul 2022 13:19:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D99F5244F; Wed, 27 Jul 2022 09:45:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3E94860D3B; Wed, 27 Jul 2022 16:45:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46D4AC433C1; Wed, 27 Jul 2022 16:45:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940302; bh=gKdiTShjdV4qFP0ikFKCW4jh3SAdJPkniJlckYo/GPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vLXBbmnupgUSEeMSOFFFELWDmipgUZwxBe0ej3kvBczLa/7PcyDMMOf0QozCE7L/K XWfs7glOCjFvuLgKMJ4wixQQspL5vEnIcfKp1UODcbLAY2Ax74nDhilFIlWi4NqKuy lUwdaIC7L/cvJvUsNWi5POkx8RAYSylSPaHEHcnM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov , Sasha Levin Subject: [PATCH 5.15 145/201] x86/extable: Provide EX_TYPE_DEFAULT_MCE_SAFE and EX_TYPE_FAULT_MCE_SAFE Date: Wed, 27 Jul 2022 18:10:49 +0200 Message-Id: <20220727161033.823638585@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner [ Upstream commit 2cadf5248b9316d3c8af876e795d61c55476f6e9 ] Provide exception fixup types which can be used to identify fixups which allow in kernel #MC recovery and make them invoke the existing handlers. These will be used at places where #MC recovery is handled correctly by the caller. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Link: https://lkml.kernel.org/r/20210908132525.269689153@linutronix.de Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/extable_fixup_types.h | 3 +++ arch/x86/kernel/cpu/mce/severity.c | 2 ++ arch/x86/mm/extable.c | 2 ++ 3 files changed, 7 insertions(+) diff --git a/arch/x86/include/asm/extable_fixup_types.h b/arch/x86/include/= asm/extable_fixup_types.h index 0adc117618e6..409524d5d2eb 100644 --- a/arch/x86/include/asm/extable_fixup_types.h +++ b/arch/x86/include/asm/extable_fixup_types.h @@ -16,4 +16,7 @@ #define EX_TYPE_WRMSR_IN_MCE 10 #define EX_TYPE_RDMSR_IN_MCE 11 =20 +#define EX_TYPE_DEFAULT_MCE_SAFE 12 +#define EX_TYPE_FAULT_MCE_SAFE 13 + #endif diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/s= everity.c index 74fe763bffda..d9b77a74f8d2 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -278,6 +278,8 @@ static int error_context(struct mce *m, struct pt_regs = *regs) m->kflags |=3D MCE_IN_KERNEL_COPYIN; fallthrough; case EX_TYPE_FAULT: + case EX_TYPE_FAULT_MCE_SAFE: + case EX_TYPE_DEFAULT_MCE_SAFE: m->kflags |=3D MCE_IN_KERNEL_RECOV; return IN_KERNEL_RECOV; default: diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index 5db46df409b5..f37e290e6d0a 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -131,8 +131,10 @@ int fixup_exception(struct pt_regs *regs, int trapnr, = unsigned long error_code, =20 switch (e->type) { case EX_TYPE_DEFAULT: + case EX_TYPE_DEFAULT_MCE_SAFE: return ex_handler_default(e, regs); case EX_TYPE_FAULT: + case EX_TYPE_FAULT_MCE_SAFE: return ex_handler_fault(e, regs, trapnr); case EX_TYPE_UACCESS: return ex_handler_uaccess(e, regs, trapnr); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48607C04A68 for ; Wed, 27 Jul 2022 17:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237276AbiG0RW3 (ORCPT ); Wed, 27 Jul 2022 13:22:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242149AbiG0RTv (ORCPT ); Wed, 27 Jul 2022 13:19:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72C802EC; Wed, 27 Jul 2022 09:45:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A5985B821A6; Wed, 27 Jul 2022 16:45:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EAD0C433C1; Wed, 27 Jul 2022 16:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940305; bh=2hJsBTzn0+OHhp5WVfO8GDI7HZLUvR3ikSXny/yDIsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1F5fmpQgenq6cr6zoj0Lnttiq7v4ebiYVASNoHnHs8C62OCLrm2X8glCwKT+4GqS 3Fikp0S1XqHSXbQ/G7ugAKFBfgJ/JejxSoQe7AM0q71DGmAp1frM3W23fThnA9LffL 2DFc5C28QaJxYxbByiF2blo0uEL0xRuJIjjdhv1Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Josh Poimboeuf , Sasha Levin Subject: [PATCH 5.15 146/201] bitfield.h: Fix "type of reg too small for mask" test Date: Wed, 27 Jul 2022 18:10:50 +0200 Message-Id: <20220727161033.869119344@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra [ Upstream commit bff8c3848e071d387d8b0784dc91fa49cd563774 ] The test: 'mask > (typeof(_reg))~0ull' only works correctly when both sides are unsigned, consider: - 0xff000000 vs (int)~0ull - 0x000000ff vs (int)~0ull Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20211110101324.950210584@infradead.org Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/linux/bitfield.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 4e035aca6f7e..6093fa6db260 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -41,6 +41,22 @@ =20 #define __bf_shf(x) (__builtin_ffsll(x) - 1) =20 +#define __scalar_type_to_unsigned_cases(type) \ + unsigned type: (unsigned type)0, \ + signed type: (unsigned type)0 + +#define __unsigned_scalar_typeof(x) typeof( \ + _Generic((x), \ + char: (unsigned char)0, \ + __scalar_type_to_unsigned_cases(char), \ + __scalar_type_to_unsigned_cases(short), \ + __scalar_type_to_unsigned_cases(int), \ + __scalar_type_to_unsigned_cases(long), \ + __scalar_type_to_unsigned_cases(long long), \ + default: (x))) + +#define __bf_cast_unsigned(type, x) ((__unsigned_scalar_typeof(type))(x)) + #define __BF_FIELD_CHECK(_mask, _reg, _val, _pfx) \ ({ \ BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ @@ -49,7 +65,8 @@ BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \ ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \ _pfx "value too large for the field"); \ - BUILD_BUG_ON_MSG((_mask) > (typeof(_reg))~0ull, \ + BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \ + __bf_cast_unsigned(_reg, ~0ull), \ _pfx "type of reg too small for mask"); \ __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \ (1ULL << __bf_shf(_mask))); \ --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01CB9C04A68 for ; Wed, 27 Jul 2022 17:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241647AbiG0RSo (ORCPT ); Wed, 27 Jul 2022 13:18:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234942AbiG0RR7 (ORCPT ); Wed, 27 Jul 2022 13:17:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2268B7969C; Wed, 27 Jul 2022 09:43:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A87E1601C0; Wed, 27 Jul 2022 16:43:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5324C433B5; Wed, 27 Jul 2022 16:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940217; bh=Wb98pt5vbxzdyRZeVuY7M2SeMywrValO8GqXhGqdCnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RzXDZLB20+/82n6gHRx3h6RvIGZ/wCJtDu3guT8/jqbXNyatPmJhFSAgmI5vDh2S1 JAxdyg/AH3n7rv/50koem9rKEtj57ENUh5daGJBdwV+BqAVv880gLrh6FgKaabpxcw /L+pZR0ZJ3G60OOX0NVKCgI/ou7onjCKGzHtpEds= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Josh Poimboeuf , Sasha Levin Subject: [PATCH 5.15 147/201] x86/entry_32: Remove .fixup usage Date: Wed, 27 Jul 2022 18:10:51 +0200 Message-Id: <20220727161033.918279310@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra [ Upstream commit aa93e2ad7464ffb90155a5ffdde963816f86d5dc ] Where possible, push the .fixup into code, at the tail of functions. This is hard for macros since they're used in multiple functions, therefore introduce a new extable handler to pop zeros. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20211110101325.245184699@infradead.org Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/entry/entry_32.S | 28 +++++++--------------- arch/x86/include/asm/extable_fixup_types.h | 2 ++ arch/x86/mm/extable.c | 14 +++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index 5bd3baf36d87..2cba70f9753b 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -270,17 +270,9 @@ 3: popl %fs addl $(4 + \pop), %esp /* pop the unused "gs" slot */ IRET_FRAME -.pushsection .fixup, "ax" -4: movl $0, (%esp) - jmp 1b -5: movl $0, (%esp) - jmp 2b -6: movl $0, (%esp) - jmp 3b -.popsection - _ASM_EXTABLE(1b, 4b) - _ASM_EXTABLE(2b, 5b) - _ASM_EXTABLE(3b, 6b) + _ASM_EXTABLE_TYPE(1b, 1b, EX_TYPE_POP_ZERO) + _ASM_EXTABLE_TYPE(2b, 2b, EX_TYPE_POP_ZERO) + _ASM_EXTABLE_TYPE(3b, 3b, EX_TYPE_POP_ZERO) .endm =20 .macro RESTORE_ALL_NMI cr3_reg:req pop=3D0 @@ -923,10 +915,8 @@ SYM_FUNC_START(entry_SYSENTER_32) sti sysexit =20 -.pushsection .fixup, "ax" -2: movl $0, PT_FS(%esp) - jmp 1b -.popsection +2: movl $0, PT_FS(%esp) + jmp 1b _ASM_EXTABLE(1b, 2b) =20 .Lsysenter_fix_flags: @@ -994,8 +984,7 @@ restore_all_switch_stack: */ iret =20 -.section .fixup, "ax" -SYM_CODE_START(asm_iret_error) +.Lasm_iret_error: pushl $0 # no error code pushl $iret_error =20 @@ -1012,9 +1001,8 @@ SYM_CODE_START(asm_iret_error) #endif =20 jmp handle_exception -SYM_CODE_END(asm_iret_error) -.previous - _ASM_EXTABLE(.Lirq_return, asm_iret_error) + + _ASM_EXTABLE(.Lirq_return, .Lasm_iret_error) SYM_FUNC_END(entry_INT80_32) =20 .macro FIXUP_ESPFIX_STACK diff --git a/arch/x86/include/asm/extable_fixup_types.h b/arch/x86/include/= asm/extable_fixup_types.h index 409524d5d2eb..4d709a2768bb 100644 --- a/arch/x86/include/asm/extable_fixup_types.h +++ b/arch/x86/include/asm/extable_fixup_types.h @@ -19,4 +19,6 @@ #define EX_TYPE_DEFAULT_MCE_SAFE 12 #define EX_TYPE_FAULT_MCE_SAFE 13 =20 +#define EX_TYPE_POP_ZERO 14 + #endif diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index f37e290e6d0a..f59a4d017070 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -99,6 +99,18 @@ static bool ex_handler_clear_fs(const struct exception_t= able_entry *fixup, return ex_handler_default(fixup, regs); } =20 +static bool ex_handler_pop_zero(const struct exception_table_entry *fixup, + struct pt_regs *regs) +{ + /* + * Typically used for when "pop %seg" traps, in which case we'll clear + * the stack slot and re-try the instruction, which will then succeed + * to pop zero. + */ + *((unsigned long *)regs->sp) =3D 0; + return ex_handler_default(fixup, regs); +} + int ex_get_fixup_type(unsigned long ip) { const struct exception_table_entry *e =3D search_exception_tables(ip); @@ -156,6 +168,8 @@ int fixup_exception(struct pt_regs *regs, int trapnr, u= nsigned long error_code, case EX_TYPE_WRMSR_IN_MCE: ex_handler_msr_mce(regs, true); break; + case EX_TYPE_POP_ZERO: + return ex_handler_pop_zero(e, regs); } BUG(); } --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87248C19F28 for ; Wed, 27 Jul 2022 17:18:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241796AbiG0RSy (ORCPT ); Wed, 27 Jul 2022 13:18:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241764AbiG0RSO (ORCPT ); Wed, 27 Jul 2022 13:18:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E094679EC1; Wed, 27 Jul 2022 09:43:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 226DCB821BA; Wed, 27 Jul 2022 16:43:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E978C433D6; Wed, 27 Jul 2022 16:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940219; bh=ZvMHQuwhlJyiVYjn+uTUQOX3msmfEm5zHTUGTE2FyAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XN5h+ivYJPpopnWvGP3Fal8i4z+43nD8X+ALlqRV+ZdPF7M4ySm1SUiO7L+ocM2+R oKocYFKi1ah487Q9MEQKoqR+FpbZZj8tXEr9+slL2GbZj9/k5Y+FwmvGbWey8cbheg aVmgZH7fDq896aBOAihRLu8rnNBRH1/AVxvU+0UY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Josh Poimboeuf , Nick Desaulniers , Sasha Levin Subject: [PATCH 5.15 148/201] x86/extable: Extend extable functionality Date: Wed, 27 Jul 2022 18:10:52 +0200 Message-Id: <20220727161033.965478749@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra [ Upstream commit 4b5305decc8436bfe363d1c1773e8fa1c828b14d ] In order to remove further .fixup usage, extend the extable infrastructure to take additional information from the extable entry sites. Specifically add _ASM_EXTABLE_TYPE_REG() and EX_TYPE_IMM_REG that extend the existing _ASM_EXTABLE_TYPE() by taking an additional register argument and encoding that and an s16 immediate into the existing s32 type field. This limits the actual types to the first byte, 255 seem plenty. Also add a few flags into the type word, specifically CLEAR_AX and CLEAR_DX which clear the return and extended return register. Notes: - due to the % in our register names it's hard to make it more generally usable as arm64 did. - the s16 is far larger than used in these patches, future extentions can easily shrink this to get more bits. - without the bitfield fix this will not compile, because: 0xFF > -1 and we can't even extract the TYPE field. [nathanchance: Build fix for clang-lto builds: https://lkml.kernel.org/r/20211210234953.3420108-1-nathan@kernel.org ] Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Josh Poimboeuf Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers Link: https://lore.kernel.org/r/20211110101325.303890153@infradead.org Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/asm.h | 37 ++++++++++++ arch/x86/include/asm/extable.h | 6 +- arch/x86/include/asm/extable_fixup_types.h | 24 ++++++++ arch/x86/include/asm/insn-eval.h | 2 + arch/x86/lib/insn-eval.c | 66 ++++++++++++++-------- arch/x86/mm/extable.c | 40 +++++++++++-- arch/x86/net/bpf_jit_comp.c | 2 +- 7 files changed, 145 insertions(+), 32 deletions(-) diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h index 6aadb9a620ee..8cbdfd77a390 100644 --- a/arch/x86/include/asm/asm.h +++ b/arch/x86/include/asm/asm.h @@ -147,6 +147,33 @@ =20 #else /* ! __ASSEMBLY__ */ =20 +# define DEFINE_EXTABLE_TYPE_REG \ + ".macro extable_type_reg type:req reg:req\n" \ + ".set found, 0\n" \ + ".set regnr, 0\n" \ + ".irp rs,rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15\n"= \ + ".ifc \\reg, %%\\rs\n" \ + ".set found, found+1\n" \ + ".long \\type + (regnr << 8)\n" \ + ".endif\n" \ + ".set regnr, regnr+1\n" \ + ".endr\n" \ + ".set regnr, 0\n" \ + ".irp rs,eax,ecx,edx,ebx,esp,ebp,esi,edi,r8d,r9d,r10d,r11d,r12d,r13d,r14d= ,r15d\n" \ + ".ifc \\reg, %%\\rs\n" \ + ".set found, found+1\n" \ + ".long \\type + (regnr << 8)\n" \ + ".endif\n" \ + ".set regnr, regnr+1\n" \ + ".endr\n" \ + ".if (found !=3D 1)\n" \ + ".error \"extable_type_reg: bad register argument\"\n" \ + ".endif\n" \ + ".endm\n" + +# define UNDEFINE_EXTABLE_TYPE_REG \ + ".purgem extable_type_reg\n" + # define _ASM_EXTABLE_TYPE(from, to, type) \ " .pushsection \"__ex_table\",\"a\"\n" \ " .balign 4\n" \ @@ -155,6 +182,16 @@ " .long " __stringify(type) " \n" \ " .popsection\n" =20 +# define _ASM_EXTABLE_TYPE_REG(from, to, type, reg) \ + " .pushsection \"__ex_table\",\"a\"\n" \ + " .balign 4\n" \ + " .long (" #from ") - .\n" \ + " .long (" #to ") - .\n" \ + DEFINE_EXTABLE_TYPE_REG \ + "extable_type_reg reg=3D" __stringify(reg) ", type=3D" __stringify(type) = " \n"\ + UNDEFINE_EXTABLE_TYPE_REG \ + " .popsection\n" + /* For C file, we already have NOKPROBE_SYMBOL macro */ =20 /* diff --git a/arch/x86/include/asm/extable.h b/arch/x86/include/asm/extable.h index 93f400eb728f..155c991ba95e 100644 --- a/arch/x86/include/asm/extable.h +++ b/arch/x86/include/asm/extable.h @@ -21,7 +21,7 @@ */ =20 struct exception_table_entry { - int insn, fixup, type; + int insn, fixup, data; }; struct pt_regs; =20 @@ -31,8 +31,8 @@ struct pt_regs; do { \ (a)->fixup =3D (b)->fixup + (delta); \ (b)->fixup =3D (tmp).fixup - (delta); \ - (a)->type =3D (b)->type; \ - (b)->type =3D (tmp).type; \ + (a)->data =3D (b)->data; \ + (b)->data =3D (tmp).data; \ } while (0) =20 extern int fixup_exception(struct pt_regs *regs, int trapnr, diff --git a/arch/x86/include/asm/extable_fixup_types.h b/arch/x86/include/= asm/extable_fixup_types.h index 4d709a2768bb..944f8329022a 100644 --- a/arch/x86/include/asm/extable_fixup_types.h +++ b/arch/x86/include/asm/extable_fixup_types.h @@ -2,6 +2,29 @@ #ifndef _ASM_X86_EXTABLE_FIXUP_TYPES_H #define _ASM_X86_EXTABLE_FIXUP_TYPES_H =20 +/* + * Our IMM is signed, as such it must live at the top end of the word. Als= o, + * since C99 hex constants are of ambigious type, force cast the mask to '= int' + * so that FIELD_GET() will DTRT and sign extend the value when it extract= s it. + */ +#define EX_DATA_TYPE_MASK ((int)0x000000FF) +#define EX_DATA_REG_MASK ((int)0x00000F00) +#define EX_DATA_FLAG_MASK ((int)0x0000F000) +#define EX_DATA_IMM_MASK ((int)0xFFFF0000) + +#define EX_DATA_REG_SHIFT 8 +#define EX_DATA_FLAG_SHIFT 12 +#define EX_DATA_IMM_SHIFT 16 + +#define EX_DATA_FLAG(flag) ((flag) << EX_DATA_FLAG_SHIFT) +#define EX_DATA_IMM(imm) ((imm) << EX_DATA_IMM_SHIFT) + +/* flags */ +#define EX_FLAG_CLEAR_AX EX_DATA_FLAG(1) +#define EX_FLAG_CLEAR_DX EX_DATA_FLAG(2) +#define EX_FLAG_CLEAR_AX_DX EX_DATA_FLAG(3) + +/* types */ #define EX_TYPE_NONE 0 #define EX_TYPE_DEFAULT 1 #define EX_TYPE_FAULT 2 @@ -20,5 +43,6 @@ #define EX_TYPE_FAULT_MCE_SAFE 13 =20 #define EX_TYPE_POP_ZERO 14 +#define EX_TYPE_IMM_REG 15 /* reg :=3D (long)imm */ =20 #endif diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-e= val.h index 4ec3613551e3..3df123f437c9 100644 --- a/arch/x86/include/asm/insn-eval.h +++ b/arch/x86/include/asm/insn-eval.h @@ -15,6 +15,8 @@ #define INSN_CODE_SEG_OPND_SZ(params) (params & 0xf) #define INSN_CODE_SEG_PARAMS(oper_sz, addr_sz) (oper_sz | (addr_sz << 4)) =20 +int pt_regs_offset(struct pt_regs *regs, int regno); + bool insn_has_rep_prefix(struct insn *insn); void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs); int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs); diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index eb3ccffb9b9d..7760d228041b 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -412,32 +412,39 @@ static short get_segment_selector(struct pt_regs *reg= s, int seg_reg_idx) #endif /* CONFIG_X86_64 */ } =20 -static int get_reg_offset(struct insn *insn, struct pt_regs *regs, - enum reg_type type) +static const int pt_regoff[] =3D { + offsetof(struct pt_regs, ax), + offsetof(struct pt_regs, cx), + offsetof(struct pt_regs, dx), + offsetof(struct pt_regs, bx), + offsetof(struct pt_regs, sp), + offsetof(struct pt_regs, bp), + offsetof(struct pt_regs, si), + offsetof(struct pt_regs, di), +#ifdef CONFIG_X86_64 + offsetof(struct pt_regs, r8), + offsetof(struct pt_regs, r9), + offsetof(struct pt_regs, r10), + offsetof(struct pt_regs, r11), + offsetof(struct pt_regs, r12), + offsetof(struct pt_regs, r13), + offsetof(struct pt_regs, r14), + offsetof(struct pt_regs, r15), +#endif +}; + +int pt_regs_offset(struct pt_regs *regs, int regno) { + if ((unsigned)regno < ARRAY_SIZE(pt_regoff)) + return pt_regoff[regno]; + return -EDOM; +} + +static int get_regno(struct insn *insn, enum reg_type type) +{ + int nr_registers =3D ARRAY_SIZE(pt_regoff); int regno =3D 0; =20 - static const int regoff[] =3D { - offsetof(struct pt_regs, ax), - offsetof(struct pt_regs, cx), - offsetof(struct pt_regs, dx), - offsetof(struct pt_regs, bx), - offsetof(struct pt_regs, sp), - offsetof(struct pt_regs, bp), - offsetof(struct pt_regs, si), - offsetof(struct pt_regs, di), -#ifdef CONFIG_X86_64 - offsetof(struct pt_regs, r8), - offsetof(struct pt_regs, r9), - offsetof(struct pt_regs, r10), - offsetof(struct pt_regs, r11), - offsetof(struct pt_regs, r12), - offsetof(struct pt_regs, r13), - offsetof(struct pt_regs, r14), - offsetof(struct pt_regs, r15), -#endif - }; - int nr_registers =3D ARRAY_SIZE(regoff); /* * Don't possibly decode a 32-bit instructions as * reading a 64-bit-only register. @@ -505,7 +512,18 @@ static int get_reg_offset(struct insn *insn, struct pt= _regs *regs, WARN_ONCE(1, "decoded an instruction with an invalid register"); return -EINVAL; } - return regoff[regno]; + return regno; +} + +static int get_reg_offset(struct insn *insn, struct pt_regs *regs, + enum reg_type type) +{ + int regno =3D get_regno(insn, type); + + if (regno < 0) + return regno; + + return pt_regs_offset(regs, regno); } =20 /** diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index f59a4d017070..251732113624 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -2,12 +2,25 @@ #include #include #include +#include #include =20 #include #include #include #include +#include + +static inline unsigned long *pt_regs_nr(struct pt_regs *regs, int nr) +{ + int reg_offset =3D pt_regs_offset(regs, nr); + static unsigned long __dummy; + + if (WARN_ON_ONCE(reg_offset < 0)) + return &__dummy; + + return (unsigned long *)((unsigned long)regs + reg_offset); +} =20 static inline unsigned long ex_fixup_addr(const struct exception_table_entry *x) @@ -15,10 +28,15 @@ ex_fixup_addr(const struct exception_table_entry *x) return (unsigned long)&x->fixup + x->fixup; } =20 -static bool ex_handler_default(const struct exception_table_entry *fixup, +static bool ex_handler_default(const struct exception_table_entry *e, struct pt_regs *regs) { - regs->ip =3D ex_fixup_addr(fixup); + if (e->data & EX_FLAG_CLEAR_AX) + regs->ax =3D 0; + if (e->data & EX_FLAG_CLEAR_DX) + regs->dx =3D 0; + + regs->ip =3D ex_fixup_addr(e); return true; } =20 @@ -111,17 +129,25 @@ static bool ex_handler_pop_zero(const struct exceptio= n_table_entry *fixup, return ex_handler_default(fixup, regs); } =20 +static bool ex_handler_imm_reg(const struct exception_table_entry *fixup, + struct pt_regs *regs, int reg, int imm) +{ + *pt_regs_nr(regs, reg) =3D (long)imm; + return ex_handler_default(fixup, regs); +} + int ex_get_fixup_type(unsigned long ip) { const struct exception_table_entry *e =3D search_exception_tables(ip); =20 - return e ? e->type : EX_TYPE_NONE; + return e ? FIELD_GET(EX_DATA_TYPE_MASK, e->data) : EX_TYPE_NONE; } =20 int fixup_exception(struct pt_regs *regs, int trapnr, unsigned long error_= code, unsigned long fault_addr) { const struct exception_table_entry *e; + int type, reg, imm; =20 #ifdef CONFIG_PNPBIOS if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) { @@ -141,7 +167,11 @@ int fixup_exception(struct pt_regs *regs, int trapnr, = unsigned long error_code, if (!e) return 0; =20 - switch (e->type) { + type =3D FIELD_GET(EX_DATA_TYPE_MASK, e->data); + reg =3D FIELD_GET(EX_DATA_REG_MASK, e->data); + imm =3D FIELD_GET(EX_DATA_IMM_MASK, e->data); + + switch (type) { case EX_TYPE_DEFAULT: case EX_TYPE_DEFAULT_MCE_SAFE: return ex_handler_default(e, regs); @@ -170,6 +200,8 @@ int fixup_exception(struct pt_regs *regs, int trapnr, u= nsigned long error_code, break; case EX_TYPE_POP_ZERO: return ex_handler_pop_zero(e, regs); + case EX_TYPE_IMM_REG: + return ex_handler_imm_reg(e, regs, reg, imm); } BUG(); } diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 4f3a60037150..dccaab2113f9 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -1342,7 +1342,7 @@ st: if (is_imm8(insn->off)) } ex->insn =3D delta; =20 - ex->type =3D EX_TYPE_BPF; + ex->data =3D EX_TYPE_BPF; =20 if (dst_reg > BPF_REG_9) { pr_err("verifier error\n"); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D1C5C04A68 for ; Wed, 27 Jul 2022 17:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241803AbiG0RS4 (ORCPT ); Wed, 27 Jul 2022 13:18:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241719AbiG0RSP (ORCPT ); Wed, 27 Jul 2022 13:18:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1709751A18; Wed, 27 Jul 2022 09:43:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 55514600BE; Wed, 27 Jul 2022 16:43:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C52CC433D6; Wed, 27 Jul 2022 16:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940222; bh=c59alnyliArV4i4Px+c5O5zxXdRrdJ6MsB7Ex49Djd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wcwyKgrujaRv1yDeFjcUZWlC29PE/pdiFDk2tFfmIYtBOPPN40dXqQUyqCpg4qC+r bX0OPztXDVVwzLtiRbo17e8migvs98xeP9FbPg/0VHr3lviR4Pz26Tl05aosUS32dM iC7oR4YbwJk3n+mBRmKq1xCLxrIiEIDzI2kvqZQM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Josh Poimboeuf , Sasha Levin Subject: [PATCH 5.15 149/201] x86/msr: Remove .fixup usage Date: Wed, 27 Jul 2022 18:10:53 +0200 Message-Id: <20220727161034.001689487@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra [ Upstream commit d52a7344bdfa9c3442d3f86fb3501d9343726c76 ] Rework the MSR accessors to remove .fixup usage. Add two new extable types (to the 4 already existing msr ones) using the new register infrastructure to record which register should get the error value. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20211110101325.364084212@infradead.org Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/extable_fixup_types.h | 23 +++++----- arch/x86/include/asm/msr.h | 26 ++++------- arch/x86/mm/extable.c | 51 ++++++++++++---------- 3 files changed, 47 insertions(+), 53 deletions(-) diff --git a/arch/x86/include/asm/extable_fixup_types.h b/arch/x86/include/= asm/extable_fixup_types.h index 944f8329022a..9d597fe1017d 100644 --- a/arch/x86/include/asm/extable_fixup_types.h +++ b/arch/x86/include/asm/extable_fixup_types.h @@ -32,17 +32,16 @@ #define EX_TYPE_COPY 4 #define EX_TYPE_CLEAR_FS 5 #define EX_TYPE_FPU_RESTORE 6 -#define EX_TYPE_WRMSR 7 -#define EX_TYPE_RDMSR 8 -#define EX_TYPE_BPF 9 - -#define EX_TYPE_WRMSR_IN_MCE 10 -#define EX_TYPE_RDMSR_IN_MCE 11 - -#define EX_TYPE_DEFAULT_MCE_SAFE 12 -#define EX_TYPE_FAULT_MCE_SAFE 13 - -#define EX_TYPE_POP_ZERO 14 -#define EX_TYPE_IMM_REG 15 /* reg :=3D (long)imm */ +#define EX_TYPE_BPF 7 +#define EX_TYPE_WRMSR 8 +#define EX_TYPE_RDMSR 9 +#define EX_TYPE_WRMSR_SAFE 10 /* reg :=3D -EIO */ +#define EX_TYPE_RDMSR_SAFE 11 /* reg :=3D -EIO */ +#define EX_TYPE_WRMSR_IN_MCE 12 +#define EX_TYPE_RDMSR_IN_MCE 13 +#define EX_TYPE_DEFAULT_MCE_SAFE 14 +#define EX_TYPE_FAULT_MCE_SAFE 15 +#define EX_TYPE_POP_ZERO 16 +#define EX_TYPE_IMM_REG 17 /* reg :=3D (long)imm */ =20 #endif diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 6b52182e178a..d42e6c6b47b1 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -137,17 +137,11 @@ static inline unsigned long long native_read_msr_safe= (unsigned int msr, { DECLARE_ARGS(val, low, high); =20 - asm volatile("2: rdmsr ; xor %[err],%[err]\n" - "1:\n\t" - ".section .fixup,\"ax\"\n\t" - "3: mov %[fault],%[err]\n\t" - "xorl %%eax, %%eax\n\t" - "xorl %%edx, %%edx\n\t" - "jmp 1b\n\t" - ".previous\n\t" - _ASM_EXTABLE(2b, 3b) + asm volatile("1: rdmsr ; xor %[err],%[err]\n" + "2:\n\t" + _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_RDMSR_SAFE, %[err]) : [err] "=3Dr" (*err), EAX_EDX_RET(val, low, high) - : "c" (msr), [fault] "i" (-EIO)); + : "c" (msr)); if (tracepoint_enabled(read_msr)) do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), *err); return EAX_EDX_VAL(val, low, high); @@ -169,15 +163,11 @@ native_write_msr_safe(unsigned int msr, u32 low, u32 = high) { int err; =20 - asm volatile("2: wrmsr ; xor %[err],%[err]\n" - "1:\n\t" - ".section .fixup,\"ax\"\n\t" - "3: mov %[fault],%[err] ; jmp 1b\n\t" - ".previous\n\t" - _ASM_EXTABLE(2b, 3b) + asm volatile("1: wrmsr ; xor %[err],%[err]\n" + "2:\n\t" + _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_WRMSR_SAFE, %[err]) : [err] "=3Da" (err) - : "c" (msr), "0" (low), "d" (high), - [fault] "i" (-EIO) + : "c" (msr), "0" (low), "d" (high) : "memory"); if (tracepoint_enabled(write_msr)) do_trace_write_msr(msr, ((u64)high << 32 | low), err); diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index 251732113624..1c558f8e8c07 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -83,28 +83,29 @@ static bool ex_handler_copy(const struct exception_tabl= e_entry *fixup, return ex_handler_fault(fixup, regs, trapnr); } =20 -static bool ex_handler_rdmsr_unsafe(const struct exception_table_entry *fi= xup, - struct pt_regs *regs) +static bool ex_handler_msr(const struct exception_table_entry *fixup, + struct pt_regs *regs, bool wrmsr, bool safe, int reg) { - if (pr_warn_once("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%= lx (%pS)\n", + if (!safe && wrmsr && + pr_warn_once("unchecked MSR access error: WRMSR to 0x%x (tried to wri= te 0x%08x%08x) at rIP: 0x%lx (%pS)\n", + (unsigned int)regs->cx, (unsigned int)regs->dx, + (unsigned int)regs->ax, regs->ip, (void *)regs->ip)) + show_stack_regs(regs); + + if (!safe && !wrmsr && + pr_warn_once("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%= lx (%pS)\n", (unsigned int)regs->cx, regs->ip, (void *)regs->ip)) show_stack_regs(regs); =20 - /* Pretend that the read succeeded and returned 0. */ - regs->ax =3D 0; - regs->dx =3D 0; - return ex_handler_default(fixup, regs); -} + if (!wrmsr) { + /* Pretend that the read succeeded and returned 0. */ + regs->ax =3D 0; + regs->dx =3D 0; + } =20 -static bool ex_handler_wrmsr_unsafe(const struct exception_table_entry *fi= xup, - struct pt_regs *regs) -{ - if (pr_warn_once("unchecked MSR access error: WRMSR to 0x%x (tried to wri= te 0x%08x%08x) at rIP: 0x%lx (%pS)\n", - (unsigned int)regs->cx, (unsigned int)regs->dx, - (unsigned int)regs->ax, regs->ip, (void *)regs->ip)) - show_stack_regs(regs); + if (safe) + *pt_regs_nr(regs, reg) =3D -EIO; =20 - /* Pretend that the write succeeded. */ return ex_handler_default(fixup, regs); } =20 @@ -186,18 +187,22 @@ int fixup_exception(struct pt_regs *regs, int trapnr,= unsigned long error_code, return ex_handler_clear_fs(e, regs); case EX_TYPE_FPU_RESTORE: return ex_handler_fprestore(e, regs); - case EX_TYPE_RDMSR: - return ex_handler_rdmsr_unsafe(e, regs); - case EX_TYPE_WRMSR: - return ex_handler_wrmsr_unsafe(e, regs); case EX_TYPE_BPF: return ex_handler_bpf(e, regs); - case EX_TYPE_RDMSR_IN_MCE: - ex_handler_msr_mce(regs, false); - break; + case EX_TYPE_WRMSR: + return ex_handler_msr(e, regs, true, false, reg); + case EX_TYPE_RDMSR: + return ex_handler_msr(e, regs, false, false, reg); + case EX_TYPE_WRMSR_SAFE: + return ex_handler_msr(e, regs, true, true, reg); + case EX_TYPE_RDMSR_SAFE: + return ex_handler_msr(e, regs, false, true, reg); case EX_TYPE_WRMSR_IN_MCE: ex_handler_msr_mce(regs, true); break; + case EX_TYPE_RDMSR_IN_MCE: + ex_handler_msr_mce(regs, false); + break; case EX_TYPE_POP_ZERO: return ex_handler_pop_zero(e, regs); case EX_TYPE_IMM_REG: --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7455FC19F28 for ; Wed, 27 Jul 2022 17:19:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233214AbiG0RTy (ORCPT ); Wed, 27 Jul 2022 13:19:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240113AbiG0RSX (ORCPT ); Wed, 27 Jul 2022 13:18:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D795C9C3; Wed, 27 Jul 2022 09:43:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BCBE7B8200C; Wed, 27 Jul 2022 16:43:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CF11C433C1; Wed, 27 Jul 2022 16:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940225; bh=fQbnzm2Dq9Za4ZflIcr2EXIrw0q4yIR4IjS0LUqj6cU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JvL7+CEQ+TkQlw9ljrObHvmbq/XD9aLIP7ycTmD+OJCv30JZdAJCP+U9Nip17/940 hJD0+x9jxGW/cScFLMCsoeGTDT67F5yLnc1S147e2rCRgR1UYP7PQSlTod9AGq7Iva 1W/EiipzEjI28JKfdntvgs7RkEFZ5J7SIAsX/A7Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Josh Poimboeuf , Sasha Levin Subject: [PATCH 5.15 150/201] x86/futex: Remove .fixup usage Date: Wed, 27 Jul 2022 18:10:54 +0200 Message-Id: <20220727161034.050152608@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra [ Upstream commit 4c132d1d844a53fc4e4b5c34e36ef10d6124b783 ] Use the new EX_TYPE_IMM_REG to store -EFAULT into the designated 'ret' register, this removes the need for anonymous .fixup code. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20211110101325.426016322@infradead.org Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/extable_fixup_types.h | 2 ++ arch/x86/include/asm/futex.h | 28 +++++++--------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/arch/x86/include/asm/extable_fixup_types.h b/arch/x86/include/= asm/extable_fixup_types.h index 9d597fe1017d..7469038de100 100644 --- a/arch/x86/include/asm/extable_fixup_types.h +++ b/arch/x86/include/asm/extable_fixup_types.h @@ -42,6 +42,8 @@ #define EX_TYPE_DEFAULT_MCE_SAFE 14 #define EX_TYPE_FAULT_MCE_SAFE 15 #define EX_TYPE_POP_ZERO 16 + #define EX_TYPE_IMM_REG 17 /* reg :=3D (long)imm */ +#define EX_TYPE_EFAULT_REG (EX_TYPE_IMM_REG | EX_DATA_IMM(-EFAULT)) =20 #endif diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h index f9c00110a69a..99d345b686fa 100644 --- a/arch/x86/include/asm/futex.h +++ b/arch/x86/include/asm/futex.h @@ -17,13 +17,9 @@ do { \ int oldval =3D 0, ret; \ asm volatile("1:\t" insn "\n" \ "2:\n" \ - "\t.section .fixup,\"ax\"\n" \ - "3:\tmov\t%3, %1\n" \ - "\tjmp\t2b\n" \ - "\t.previous\n" \ - _ASM_EXTABLE_UA(1b, 3b) \ + _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, %1) \ : "=3Dr" (oldval), "=3Dr" (ret), "+m" (*uaddr) \ - : "i" (-EFAULT), "0" (oparg), "1" (0)); \ + : "0" (oparg), "1" (0)); \ if (ret) \ goto label; \ *oval =3D oldval; \ @@ -39,15 +35,11 @@ do { \ "3:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \ "\tjnz\t2b\n" \ "4:\n" \ - "\t.section .fixup,\"ax\"\n" \ - "5:\tmov\t%5, %1\n" \ - "\tjmp\t4b\n" \ - "\t.previous\n" \ - _ASM_EXTABLE_UA(1b, 5b) \ - _ASM_EXTABLE_UA(3b, 5b) \ + _ASM_EXTABLE_TYPE_REG(1b, 4b, EX_TYPE_EFAULT_REG, %1) \ + _ASM_EXTABLE_TYPE_REG(3b, 4b, EX_TYPE_EFAULT_REG, %1) \ : "=3D&a" (oldval), "=3D&r" (ret), \ "+m" (*uaddr), "=3D&r" (tem) \ - : "r" (oparg), "i" (-EFAULT), "1" (0)); \ + : "r" (oparg), "1" (0)); \ if (ret) \ goto label; \ *oval =3D oldval; \ @@ -95,15 +87,11 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uv= al, u32 __user *uaddr, if (!user_access_begin(uaddr, sizeof(u32))) return -EFAULT; asm volatile("\n" - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" + "1:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" "2:\n" - "\t.section .fixup, \"ax\"\n" - "3:\tmov %3, %0\n" - "\tjmp 2b\n" - "\t.previous\n" - _ASM_EXTABLE_UA(1b, 3b) + _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, %0) \ : "+r" (ret), "=3Da" (oldval), "+m" (*uaddr) - : "i" (-EFAULT), "r" (newval), "1" (oldval) + : "r" (newval), "1" (oldval) : "memory" ); user_access_end(); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC861C25B06 for ; Wed, 27 Jul 2022 17:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240059AbiG0RT7 (ORCPT ); Wed, 27 Jul 2022 13:19:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241755AbiG0RSa (ORCPT ); Wed, 27 Jul 2022 13:18:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE8D5C9D5; Wed, 27 Jul 2022 09:43:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B91A8B821A6; Wed, 27 Jul 2022 16:43:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 076FDC433D7; Wed, 27 Jul 2022 16:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940228; bh=0ucAd0MVzOEGl6VOE3Lt6pJMcebyDiezvpzd9ZbChPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TDcpHejqaMO42lD/18ZtGixIRmEPvoYGrypjhWBPKzU+KuSmuhEh6BWK4vYzkfFZW MqHz4u+i3JxqykINSDuhKzd372Mw0KdrIFzMNW2ck3It96PuGd64J6OKbJrOYKEV1J JizkeeFNewLO2FKeduIwU0QIqnj5r5HyzcrnBVQs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.15 151/201] KVM: x86: Use __try_cmpxchg_user() to emulate atomic accesses Date: Wed, 27 Jul 2022 18:10:55 +0200 Message-Id: <20220727161034.082862959@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sean Christopherson [ Upstream commit 1c2361f667f3648855ceae25f1332c18413fdb9f ] Use the recently introduce __try_cmpxchg_user() to emulate atomic guest accesses via the associated userspace address instead of mapping the backing pfn into kernel address space. Using kvm_vcpu_map() is unsafe as it does not coordinate with KVM's mmu_notifier to ensure the hva=3D>pfn translation isn't changed/unmapped in the memremap() path, i.e. when there's no struct page and thus no elevated refcount. Fixes: 42e35f8072c3 ("KVM/X86: Use kvm_vcpu_map in emulator_cmpxchg_emulate= d") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20220202004945.2540433-5-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/kvm/x86.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4525d0b25a43..f9802ceed60a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6894,15 +6894,8 @@ static int emulator_write_emulated(struct x86_emulat= e_ctxt *ctxt, exception, &write_emultor); } =20 -#define CMPXCHG_TYPE(t, ptr, old, new) \ - (cmpxchg((t *)(ptr), *(t *)(old), *(t *)(new)) =3D=3D *(t *)(old)) - -#ifdef CONFIG_X86_64 -# define CMPXCHG64(ptr, old, new) CMPXCHG_TYPE(u64, ptr, old, new) -#else -# define CMPXCHG64(ptr, old, new) \ - (cmpxchg64((u64 *)(ptr), *(u64 *)(old), *(u64 *)(new)) =3D=3D *(u64 *)(ol= d)) -#endif +#define emulator_try_cmpxchg_user(t, ptr, old, new) \ + (__try_cmpxchg_user((t __user *)(ptr), (t *)(old), *(t *)(new), efault ##= t)) =20 static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt, unsigned long addr, @@ -6911,12 +6904,11 @@ static int emulator_cmpxchg_emulated(struct x86_emu= late_ctxt *ctxt, unsigned int bytes, struct x86_exception *exception) { - struct kvm_host_map map; struct kvm_vcpu *vcpu =3D emul_to_vcpu(ctxt); u64 page_line_mask; + unsigned long hva; gpa_t gpa; - char *kaddr; - bool exchanged; + int r; =20 /* guests cmpxchg8b have to be emulated atomically */ if (bytes > 8 || (bytes & (bytes - 1))) @@ -6940,31 +6932,32 @@ static int emulator_cmpxchg_emulated(struct x86_emu= late_ctxt *ctxt, if (((gpa + bytes - 1) & page_line_mask) !=3D (gpa & page_line_mask)) goto emul_write; =20 - if (kvm_vcpu_map(vcpu, gpa_to_gfn(gpa), &map)) + hva =3D kvm_vcpu_gfn_to_hva(vcpu, gpa_to_gfn(gpa)); + if (kvm_is_error_hva(addr)) goto emul_write; =20 - kaddr =3D map.hva + offset_in_page(gpa); + hva +=3D offset_in_page(gpa); =20 switch (bytes) { case 1: - exchanged =3D CMPXCHG_TYPE(u8, kaddr, old, new); + r =3D emulator_try_cmpxchg_user(u8, hva, old, new); break; case 2: - exchanged =3D CMPXCHG_TYPE(u16, kaddr, old, new); + r =3D emulator_try_cmpxchg_user(u16, hva, old, new); break; case 4: - exchanged =3D CMPXCHG_TYPE(u32, kaddr, old, new); + r =3D emulator_try_cmpxchg_user(u32, hva, old, new); break; case 8: - exchanged =3D CMPXCHG64(kaddr, old, new); + r =3D emulator_try_cmpxchg_user(u64, hva, old, new); break; default: BUG(); } =20 - kvm_vcpu_unmap(vcpu, &map, true); - - if (!exchanged) + if (r < 0) + goto emul_write; + if (r) return X86EMUL_CMPXCHG_FAILED; =20 kvm_page_track_write(vcpu, gpa, new, bytes); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05D0BC25B06 for ; Wed, 27 Jul 2022 17:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241805AbiG0RUN (ORCPT ); Wed, 27 Jul 2022 13:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237215AbiG0RSe (ORCPT ); Wed, 27 Jul 2022 13:18:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC5479EEA; Wed, 27 Jul 2022 09:43:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E42C1601C0; Wed, 27 Jul 2022 16:43:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED82DC433C1; Wed, 27 Jul 2022 16:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940231; bh=OWV/hf/XEBSjkRGgk5wImacYpr3pIY3T3KqtCGvljDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qpXXo788UaxafTWgDNCNuMxH6NacvSrN5zjmYZmQFI9sjeiRymXzIikkkKLfnptLN v4/kOPq70f2FxEn9RQUK1o/mfySWeN0qQEMBbPAbEZXfx+z13gd1Fdz9Trj45701NG j9ohS/bAkNhS0xp2NdU0FwLp17jnYps2qpRWYM+c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Sasha Levin Subject: [PATCH 5.15 152/201] xhci: dbc: refactor xhci_dbc_init() Date: Wed, 27 Jul 2022 18:10:56 +0200 Message-Id: <20220727161034.130364605@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Mathias Nyman [ Upstream commit 534675942e901959b5d8dc11ea526c4e48817d8e ] Refactor xhci_dbc_init(), splitting it into logical parts closer to the Linux device model. - Create the fake dbc device, depends on xhci strucure - Allocate a dbc structure, xhci agnostic - Call xhci_dbc_tty_probe(), similar to actual probe. Adjustments to xhci_dbc_exit and xhci_dbc_remove are also needed as a result to the xhci_dbc_init() changes Mostly non-functional changes, except for creating the dbc sysfs entry earlier, together with the dbc structure. Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220216095153.1303105-2-mathias.nyman@linu= x.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/usb/host/xhci-dbgcap.c | 124 ++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index ccb0156fcebe..6a437862b498 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -924,49 +924,6 @@ static void xhci_do_dbc_exit(struct xhci_hcd *xhci) spin_unlock_irqrestore(&xhci->lock, flags); } =20 -static int xhci_do_dbc_init(struct xhci_hcd *xhci) -{ - u32 reg; - struct xhci_dbc *dbc; - unsigned long flags; - void __iomem *base; - int dbc_cap_offs; - - base =3D &xhci->cap_regs->hc_capbase; - dbc_cap_offs =3D xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG); - if (!dbc_cap_offs) - return -ENODEV; - - dbc =3D kzalloc(sizeof(*dbc), GFP_KERNEL); - if (!dbc) - return -ENOMEM; - - dbc->regs =3D base + dbc_cap_offs; - - /* We will avoid using DbC in xhci driver if it's in use. */ - reg =3D readl(&dbc->regs->control); - if (reg & DBC_CTRL_DBC_ENABLE) { - kfree(dbc); - return -EBUSY; - } - - spin_lock_irqsave(&xhci->lock, flags); - if (xhci->dbc) { - spin_unlock_irqrestore(&xhci->lock, flags); - kfree(dbc); - return -EBUSY; - } - xhci->dbc =3D dbc; - spin_unlock_irqrestore(&xhci->lock, flags); - - dbc->xhci =3D xhci; - dbc->dev =3D xhci_to_hcd(xhci)->self.sysdev; - INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); - spin_lock_init(&dbc->lock); - - return 0; -} - static ssize_t dbc_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -1026,44 +983,95 @@ static ssize_t dbc_store(struct device *dev, =20 static DEVICE_ATTR_RW(dbc); =20 -int xhci_dbc_init(struct xhci_hcd *xhci) +struct xhci_dbc * +xhci_alloc_dbc(struct device *dev, void __iomem *base) { + struct xhci_dbc *dbc; int ret; - struct device *dev =3D xhci_to_hcd(xhci)->self.controller; =20 - ret =3D xhci_do_dbc_init(xhci); + dbc =3D kzalloc(sizeof(*dbc), GFP_KERNEL); + if (!dbc) + return NULL; + + dbc->regs =3D base; + dbc->dev =3D dev; + + if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) + return NULL; + + INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events); + spin_lock_init(&dbc->lock); + + ret =3D device_create_file(dev, &dev_attr_dbc); if (ret) - goto init_err3; + goto err; + + return dbc; +err: + kfree(dbc); + return NULL; +} + +/* undo what xhci_alloc_dbc() did */ +void xhci_dbc_remove(struct xhci_dbc *dbc) +{ + if (!dbc) + return; + /* stop hw, stop wq and call dbc->ops->stop() */ + xhci_dbc_stop(dbc); + + /* remove sysfs files */ + device_remove_file(dbc->dev, &dev_attr_dbc); + + kfree(dbc); +} + +int xhci_dbc_init(struct xhci_hcd *xhci) +{ + struct device *dev; + void __iomem *base; + int ret; + int dbc_cap_offs; + + /* create all parameters needed resembling a dbc device */ + dev =3D xhci_to_hcd(xhci)->self.controller; + base =3D &xhci->cap_regs->hc_capbase; + + dbc_cap_offs =3D xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG); + if (!dbc_cap_offs) + return -ENODEV; + + /* already allocated and in use */ + if (xhci->dbc) + return -EBUSY; + + xhci->dbc =3D xhci_alloc_dbc(dev, base); + if (!xhci->dbc) + return -ENOMEM; =20 ret =3D xhci_dbc_tty_probe(xhci); if (ret) goto init_err2; =20 - ret =3D device_create_file(dev, &dev_attr_dbc); - if (ret) - goto init_err1; - return 0; =20 -init_err1: - xhci_dbc_tty_remove(xhci->dbc); init_err2: xhci_do_dbc_exit(xhci); -init_err3: return ret; } =20 void xhci_dbc_exit(struct xhci_hcd *xhci) { - struct device *dev =3D xhci_to_hcd(xhci)->self.controller; + unsigned long flags; =20 if (!xhci->dbc) return; =20 - device_remove_file(dev, &dev_attr_dbc); xhci_dbc_tty_remove(xhci->dbc); - xhci_dbc_stop(xhci->dbc); - xhci_do_dbc_exit(xhci); + xhci_dbc_remove(xhci->dbc); + spin_lock_irqsave(&xhci->lock, flags); + xhci->dbc =3D NULL; + spin_unlock_irqrestore(&xhci->lock, flags); } =20 #ifdef CONFIG_PM --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 140B0C04A68 for ; Wed, 27 Jul 2022 17:20:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241835AbiG0RUa (ORCPT ); Wed, 27 Jul 2022 13:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241793AbiG0RSl (ORCPT ); Wed, 27 Jul 2022 13:18:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA68479EF2; Wed, 27 Jul 2022 09:43:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CA3F9601CE; Wed, 27 Jul 2022 16:43:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D31EFC433C1; Wed, 27 Jul 2022 16:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940234; bh=y884BdKINCrdyRmIMxHI65XF4GdItYKtWbvXi4nbEpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mCzzMVhEEEKqSoVG7Sn2wYWDFhq7bn9D1ZBgSadoIgyKdbyuGjdJZaOSrzhhQhaHl 9oD8vPvaKArEX9X7tePdc7pBlVSZRaaTcOZpjAqcRNCDBZHd2kbwn9mBYvM3hNKf3S 7gYog8pbW23yfm4/UarjFFwMobxB8LNEZWtpUoiI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Sasha Levin Subject: [PATCH 5.15 153/201] xhci: dbc: create and remove dbc structure in dbgtty driver. Date: Wed, 27 Jul 2022 18:10:57 +0200 Message-Id: <20220727161034.170996847@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Mathias Nyman [ Upstream commit 5ce036b98dd3301fc43bb06a6383ef07b6c776bc ] Turn the dbgtty closer to a device driver by allocating the dbc structure in its own xhci_dbc_tty_probe() function, and freeing it in xhci_dbc_tty_remove() Remove xhci_do_dbc_exit() as its no longer needed. allocate and create the dbc strcuture in xhci_dbc_tty_probe() Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220216095153.1303105-3-mathias.nyman@linu= x.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/usb/host/xhci-dbgcap.c | 26 +++----------------------- drivers/usb/host/xhci-dbgcap.h | 5 ++++- drivers/usb/host/xhci-dbgtty.c | 22 +++++++++++++++------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index 6a437862b498..f4da5708a40f 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -914,16 +914,6 @@ static void xhci_dbc_handle_events(struct work_struct = *work) mod_delayed_work(system_wq, &dbc->event_work, 1); } =20 -static void xhci_do_dbc_exit(struct xhci_hcd *xhci) -{ - unsigned long flags; - - spin_lock_irqsave(&xhci->lock, flags); - kfree(xhci->dbc); - xhci->dbc =3D NULL; - spin_unlock_irqrestore(&xhci->lock, flags); -} - static ssize_t dbc_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -984,7 +974,7 @@ static ssize_t dbc_store(struct device *dev, static DEVICE_ATTR_RW(dbc); =20 struct xhci_dbc * -xhci_alloc_dbc(struct device *dev, void __iomem *base) +xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_dr= iver *driver) { struct xhci_dbc *dbc; int ret; @@ -995,6 +985,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base) =20 dbc->regs =3D base; dbc->dev =3D dev; + dbc->driver =3D driver; =20 if (readl(&dbc->regs->control) & DBC_CTRL_DBC_ENABLE) return NULL; @@ -1045,18 +1036,8 @@ int xhci_dbc_init(struct xhci_hcd *xhci) if (xhci->dbc) return -EBUSY; =20 - xhci->dbc =3D xhci_alloc_dbc(dev, base); - if (!xhci->dbc) - return -ENOMEM; - - ret =3D xhci_dbc_tty_probe(xhci); - if (ret) - goto init_err2; - - return 0; + ret =3D xhci_dbc_tty_probe(dev, base + dbc_cap_offs, xhci); =20 -init_err2: - xhci_do_dbc_exit(xhci); return ret; } =20 @@ -1068,7 +1049,6 @@ void xhci_dbc_exit(struct xhci_hcd *xhci) return; =20 xhci_dbc_tty_remove(xhci->dbc); - xhci_dbc_remove(xhci->dbc); spin_lock_irqsave(&xhci->lock, flags); xhci->dbc =3D NULL; spin_unlock_irqrestore(&xhci->lock, flags); diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index c70b78d504eb..5d8c7815491c 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -196,8 +196,11 @@ static inline struct dbc_ep *get_out_ep(struct xhci_db= c *dbc) #ifdef CONFIG_USB_XHCI_DBGCAP int xhci_dbc_init(struct xhci_hcd *xhci); void xhci_dbc_exit(struct xhci_hcd *xhci); -int xhci_dbc_tty_probe(struct xhci_hcd *xhci); +int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_= hcd *xhci); void xhci_dbc_tty_remove(struct xhci_dbc *dbc); +struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res, + const struct dbc_driver *driver); +void xhci_dbc_remove(struct xhci_dbc *dbc); struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc, unsigned int direction, gfp_t flags); diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c index eb46e642e87a..18bcc96853ae 100644 --- a/drivers/usb/host/xhci-dbgtty.c +++ b/drivers/usb/host/xhci-dbgtty.c @@ -468,9 +468,9 @@ static const struct dbc_driver dbc_driver =3D { .disconnect =3D xhci_dbc_tty_unregister_device, }; =20 -int xhci_dbc_tty_probe(struct xhci_hcd *xhci) +int xhci_dbc_tty_probe(struct device *dev, void __iomem *base, struct xhci= _hcd *xhci) { - struct xhci_dbc *dbc =3D xhci->dbc; + struct xhci_dbc *dbc; struct dbc_port *port; int status; =20 @@ -485,13 +485,22 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci) goto out; } =20 - dbc->driver =3D &dbc_driver; - dbc->priv =3D port; + dbc_tty_driver->driver_state =3D port; + + dbc =3D xhci_alloc_dbc(dev, base, &dbc_driver); + if (!dbc) { + status =3D -ENOMEM; + goto out2; + } =20 + dbc->priv =3D port; =20 - dbc_tty_driver->driver_state =3D port; + /* get rid of xhci once this is a real driver binding to a device */ + xhci->dbc =3D dbc; =20 return 0; +out2: + kfree(port); out: /* dbc_tty_exit will be called by module_exit() in the future */ dbc_tty_exit(); @@ -506,8 +515,7 @@ void xhci_dbc_tty_remove(struct xhci_dbc *dbc) { struct dbc_port *port =3D dbc_to_port(dbc); =20 - dbc->driver =3D NULL; - dbc->priv =3D NULL; + xhci_dbc_remove(dbc); kfree(port); =20 /* dbc_tty_exit will be called by module_exit() in the future */ --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7627AC04A68 for ; Wed, 27 Jul 2022 17:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241863AbiG0RUl (ORCPT ); Wed, 27 Jul 2022 13:20:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241655AbiG0RSt (ORCPT ); Wed, 27 Jul 2022 13:18:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B6979EFD; Wed, 27 Jul 2022 09:43:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9E03E601C3; Wed, 27 Jul 2022 16:43:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAF77C433D6; Wed, 27 Jul 2022 16:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940237; bh=gZtPCMQ0JD9Ip4j75/GtiuMQLZb64IKyLIRcJaTpJzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAhagIZXgDd+pGcjRjNB+F7Fqu6UAqQ+V2tjbX8exDNcXaHZ0keHku2r1Sp8ivyMR J8l+d2fbbFPG3vKd/+oTAymn8Sa/sLr7ytTvoS5U7Qh73EBXeC34lyfvXJpbz1BqN5 y55kituK6kne9qwiqL2mniwY1KDHm30GcKdmlUlk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Sasha Levin Subject: [PATCH 5.15 154/201] xhci: dbc: Rename xhci_dbc_init and xhci_dbc_exit Date: Wed, 27 Jul 2022 18:10:58 +0200 Message-Id: <20220727161034.207557773@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Mathias Nyman [ Upstream commit 5c44d9d7570b244ca08fef817c4c90aa7a1f1b5f ] These names give the impression the functions are related to module init calls, but are in fact creating and removing the dbc fake device Rename them to xhci_create_dbc_dev() and xhci_remove_dbc_dev(). We will need the _init and _exit names for actual dbc module init and exit calls. No functional changes Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220216095153.1303105-4-mathias.nyman@linu= x.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/usb/host/xhci-dbgcap.c | 5 +++-- drivers/usb/host/xhci-dbgcap.h | 8 ++++---- drivers/usb/host/xhci.c | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index f4da5708a40f..46c8f3c187f7 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -1017,7 +1017,8 @@ void xhci_dbc_remove(struct xhci_dbc *dbc) kfree(dbc); } =20 -int xhci_dbc_init(struct xhci_hcd *xhci) + +int xhci_create_dbc_dev(struct xhci_hcd *xhci) { struct device *dev; void __iomem *base; @@ -1041,7 +1042,7 @@ int xhci_dbc_init(struct xhci_hcd *xhci) return ret; } =20 -void xhci_dbc_exit(struct xhci_hcd *xhci) +void xhci_remove_dbc_dev(struct xhci_hcd *xhci) { unsigned long flags; =20 diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h index 5d8c7815491c..8b5b363a0719 100644 --- a/drivers/usb/host/xhci-dbgcap.h +++ b/drivers/usb/host/xhci-dbgcap.h @@ -194,8 +194,8 @@ static inline struct dbc_ep *get_out_ep(struct xhci_dbc= *dbc) } =20 #ifdef CONFIG_USB_XHCI_DBGCAP -int xhci_dbc_init(struct xhci_hcd *xhci); -void xhci_dbc_exit(struct xhci_hcd *xhci); +int xhci_create_dbc_dev(struct xhci_hcd *xhci); +void xhci_remove_dbc_dev(struct xhci_hcd *xhci); int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_= hcd *xhci); void xhci_dbc_tty_remove(struct xhci_dbc *dbc); struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res, @@ -211,12 +211,12 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci); int xhci_dbc_resume(struct xhci_hcd *xhci); #endif /* CONFIG_PM */ #else -static inline int xhci_dbc_init(struct xhci_hcd *xhci) +static inline int xhci_create_dbc_dev(struct xhci_hcd *xhci) { return 0; } =20 -static inline void xhci_dbc_exit(struct xhci_hcd *xhci) +static inline void xhci_remove_dbc_dev(struct xhci_hcd *xhci) { } =20 diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 94fe7d64e762..a4e99f8668b3 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -693,7 +693,7 @@ int xhci_run(struct usb_hcd *hcd) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_run for USB2 roothub"); =20 - xhci_dbc_init(xhci); + xhci_create_dbc_dev(xhci); =20 xhci_debugfs_init(xhci); =20 @@ -723,7 +723,7 @@ static void xhci_stop(struct usb_hcd *hcd) return; } =20 - xhci_dbc_exit(xhci); + xhci_remove_dbc_dev(xhci); =20 spin_lock_irq(&xhci->lock); xhci->xhc_state |=3D XHCI_STATE_HALTED; --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BE83C04A68 for ; Wed, 27 Jul 2022 17:20:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241809AbiG0RUr (ORCPT ); Wed, 27 Jul 2022 13:20:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241827AbiG0RTG (ORCPT ); Wed, 27 Jul 2022 13:19:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763777A514; Wed, 27 Jul 2022 09:44:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 48393B821AC; Wed, 27 Jul 2022 16:44:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 976ABC433C1; Wed, 27 Jul 2022 16:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940240; bh=e7ZRv2aecf6ctDZd+OHUCvxL1ffQxSvAwxPQGF0uR9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOjdlK3HMhWoQlbvLvHWtMf+oW0JoE9xZSx3b8AFWx8yEcR2omLXyr7URaLHBq674 OsWR863HSNmScvTw3fg6LIrm6XlciLaFiX40vJjhRr8xUVBj6eea9mDH3Y0T3JEVnh /KeVPHWZ88dC5NYb8d+0y0ycbgqxXPZZEYZai1iI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Chris Chiu , Kishon Vijay Abraham I , Sasha Levin Subject: [PATCH 5.15 155/201] xhci: Set HCD flag to defer primary roothub registration Date: Wed, 27 Jul 2022 18:10:59 +0200 Message-Id: <20220727161034.246013417@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kishon Vijay Abraham I [ Upstream commit b7a4f9b5d0e4b6dd937678c546c0b322dd1a4054 ] Set "HCD_FLAG_DEFER_RH_REGISTER" to hcd->flags in xhci_run() to defer registering primary roothub in usb_add_hcd() if xhci has two roothubs. This will make sure both primary roothub and secondary roothub will be registered along with the second HCD. This is required for cold plugged USB devices to be detected in certain PCIe USB cards (like Inateck USB card connected to AM64 EVM or J7200 EVM). This patch has been added and reverted earier as it triggered a race in usb device enumeration. That race is now fixed in 5.16-rc3, and in stable back to 5.4 commit 6cca13de26ee ("usb: hub: Fix locking issues with address0_mutex") commit 6ae6dc22d2d1 ("usb: hub: Fix usb enumeration issue due to address0 race") [minor rebase change, and commit message update -Mathias] CC: stable@vger.kernel.org # 5.4+ Suggested-by: Mathias Nyman Tested-by: Chris Chiu Signed-off-by: Kishon Vijay Abraham I Link: https://lore.kernel.org/r/20220510091630.16564-3-kishon@ti.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/usb/host/xhci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index a4e99f8668b3..d76c10f9ad80 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -693,6 +693,8 @@ int xhci_run(struct usb_hcd *hcd) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_run for USB2 roothub"); =20 + set_bit(HCD_FLAG_DEFER_RH_REGISTER, &hcd->flags); + xhci_create_dbc_dev(xhci); =20 xhci_debugfs_init(xhci); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12FCFC19F28 for ; Wed, 27 Jul 2022 17:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241884AbiG0RUz (ORCPT ); Wed, 27 Jul 2022 13:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241850AbiG0RTJ (ORCPT ); Wed, 27 Jul 2022 13:19:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E4B17A525; Wed, 27 Jul 2022 09:44:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0D021B8200C; Wed, 27 Jul 2022 16:44:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72CA0C433D7; Wed, 27 Jul 2022 16:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940242; bh=UzOKAaZyLZP7WTuLlXyLJCkvlAGxGJPoJsJrNSK4noo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ifghb2ngg8J3xtLVQaz59X0pu2nGWsRM2ulzzGNkMcXXq741/lKNaHNrs3n+A+Cb/ 1go7ewDIWDWf4f4jG+X9Ir3JnaiEuY5ng8yrCo2D1pjUw5aygRHpX72EIPtaIpfaRA lpMd33T9Y0uPa+ktFEQ9Vl1cCxqPV2Wb6vKLj7i8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Wang , Felix Fietkau , Sasha Levin Subject: [PATCH 5.15 156/201] mt76: fix use-after-free by removing a non-RCU wcid pointer Date: Wed, 27 Jul 2022 18:11:00 +0200 Message-Id: <20220727161034.293946361@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Felix Fietkau [ Upstream commit 51fb1278aa57ae0fc54adaa786e1965362bed4fb ] Fixes an issue caught by KASAN about use-after-free in mt76_txq_schedule by protecting mtxq->wcid with rcu_lock between mt76_txq_schedule and sta_info_[alloc, free]. [18853.876689] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [18853.876751] BUG: KASAN: use-after-free in mt76_txq_schedule+0x204/0xaf8 = [mt76] [18853.876773] Read of size 8 at addr ffffffaf989a2138 by task mt76-tx phy0= /883 [18853.876786] [18853.876810] CPU: 5 PID: 883 Comm: mt76-tx phy0 Not tainted 5.10.100-fix-= 510-56778d365941-kasan #5 0b01fbbcf41a530f52043508fec2e31a4215 [18853.876840] Call trace: [18853.876861] dump_backtrace+0x0/0x3ec [18853.876878] show_stack+0x20/0x2c [18853.876899] dump_stack+0x11c/0x1ac [18853.876918] print_address_description+0x74/0x514 [18853.876934] kasan_report+0x134/0x174 [18853.876948] __asan_report_load8_noabort+0x44/0x50 [18853.876976] mt76_txq_schedule+0x204/0xaf8 [mt76 074e03e4640e97fe7405ee1= fab547b81c4fa45d2] [18853.877002] mt76_txq_schedule_all+0x2c/0x48 [mt76 074e03e4640e97fe7405e= e1fab547b81c4fa45d2] [18853.877030] mt7921_tx_worker+0xa0/0x1cc [mt7921_common f0875ebac9d7b475= 4e1010549e7db50fbd90a047] [18853.877054] __mt76_worker_fn+0x190/0x22c [mt76 074e03e4640e97fe7405ee1f= ab547b81c4fa45d2] [18853.877071] kthread+0x2f8/0x3b8 [18853.877087] ret_from_fork+0x10/0x30 [18853.877098] [18853.877112] Allocated by task 941: [18853.877131] kasan_save_stack+0x38/0x68 [18853.877147] __kasan_kmalloc+0xd4/0xfc [18853.877163] kasan_kmalloc+0x10/0x1c [18853.877177] __kmalloc+0x264/0x3c4 [18853.877294] sta_info_alloc+0x460/0xf88 [mac80211] [18853.877410] ieee80211_prep_connection+0x204/0x1ee0 [mac80211] [18853.877523] ieee80211_mgd_auth+0x6c4/0xa4c [mac80211] [18853.877635] ieee80211_auth+0x20/0x2c [mac80211] [18853.877733] rdev_auth+0x7c/0x438 [cfg80211] [18853.877826] cfg80211_mlme_auth+0x26c/0x390 [cfg80211] [18853.877919] nl80211_authenticate+0x6d4/0x904 [cfg80211] [18853.877938] genl_rcv_msg+0x748/0x93c [18853.877954] netlink_rcv_skb+0x160/0x2a8 [18853.877969] genl_rcv+0x3c/0x54 [18853.877985] netlink_unicast_kernel+0x104/0x1ec [18853.877999] netlink_unicast+0x178/0x268 [18853.878015] netlink_sendmsg+0x3cc/0x5f0 [18853.878030] sock_sendmsg+0xb4/0xd8 [18853.878043] ____sys_sendmsg+0x2f8/0x53c [18853.878058] ___sys_sendmsg+0xe8/0x150 [18853.878071] __sys_sendmsg+0xc4/0x1f4 [18853.878087] __arm64_compat_sys_sendmsg+0x88/0x9c [18853.878101] el0_svc_common+0x1b4/0x390 [18853.878115] do_el0_svc_compat+0x8c/0xdc [18853.878131] el0_svc_compat+0x10/0x1c [18853.878146] el0_sync_compat_handler+0xa8/0xcc [18853.878161] el0_sync_compat+0x188/0x1c0 [18853.878171] [18853.878183] Freed by task 10927: [18853.878200] kasan_save_stack+0x38/0x68 [18853.878215] kasan_set_track+0x28/0x3c [18853.878228] kasan_set_free_info+0x24/0x48 [18853.878244] __kasan_slab_free+0x11c/0x154 [18853.878259] kasan_slab_free+0x14/0x24 [18853.878273] slab_free_freelist_hook+0xac/0x1b0 [18853.878287] kfree+0x104/0x390 [18853.878402] sta_info_free+0x198/0x210 [mac80211] [18853.878515] __sta_info_destroy_part2+0x230/0x2d4 [mac80211] [18853.878628] __sta_info_flush+0x300/0x37c [mac80211] [18853.878740] ieee80211_set_disassoc+0x2cc/0xa7c [mac80211] [18853.878851] ieee80211_mgd_deauth+0x4a4/0x10a0 [mac80211] [18853.878962] ieee80211_deauth+0x20/0x2c [mac80211] [18853.879057] rdev_deauth+0x7c/0x438 [cfg80211] [18853.879150] cfg80211_mlme_deauth+0x274/0x414 [cfg80211] [18853.879243] cfg80211_mlme_down+0xe4/0x118 [cfg80211] [18853.879335] cfg80211_disconnect+0x218/0x2d8 [cfg80211] [18853.879427] __cfg80211_leave+0x17c/0x240 [cfg80211] [18853.879519] cfg80211_leave+0x3c/0x58 [cfg80211] [18853.879611] wiphy_suspend+0xdc/0x200 [cfg80211] [18853.879628] dpm_run_callback+0x58/0x408 [18853.879642] __device_suspend+0x4cc/0x864 [18853.879658] async_suspend+0x34/0xf4 [18853.879673] async_run_entry_fn+0xe0/0x37c [18853.879689] process_one_work+0x508/0xb98 [18853.879702] worker_thread+0x7f4/0xcd4 [18853.879717] kthread+0x2f8/0x3b8 [18853.879731] ret_from_fork+0x10/0x30 [18853.879741] [18853.879757] The buggy address belongs to the object at ffffffaf989a2000 [18853.879757] which belongs to the cache kmalloc-8k of size 8192 [18853.879774] The buggy address is located 312 bytes inside of [18853.879774] 8192-byte region [ffffffaf989a2000, ffffffaf989a4000) [18853.879787] The buggy address belongs to the page: [18853.879807] page:000000004bda2a59 refcount:1 mapcount:0 mapping:00000000= 00000000 index:0x0 pfn:0x1d89a0 [18853.879823] head:000000004bda2a59 order:3 compound_mapcount:0 compound_p= incount:0 [18853.879839] flags: 0x8000000000010200(slab|head) [18853.879857] raw: 8000000000010200 ffffffffbc89e208 ffffffffb7fb5208 ffff= ffaec000cc80 [18853.879873] raw: 0000000000000000 0000000000010001 00000001ffffffff 0000= 000000000000 [18853.879885] page dumped because: kasan: bad access detected [18853.879896] [18853.879907] Memory state around the buggy address: [18853.879922] ffffffaf989a2000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb= fb fb [18853.879935] ffffffaf989a2080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb= fb fb [18853.879948] >ffffffaf989a2100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb= fb fb [18853.879961] ^ [18853.879973] ffffffaf989a2180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb= fb fb [18853.879986] ffffffaf989a2200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb= fb fb [18853.879998] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Cc: stable@vger.kernel.org Reported-by: Sean Wang Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/wireless/mediatek/mt76/mac80211.c | 2 +- drivers/net/wireless/mediatek/mt76/mt76.h | 2 +- drivers/net/wireless/mediatek/mt76/mt7603/main.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7615/main.c | 2 +- drivers/net/wireless/mediatek/mt76/mt76x02_util.c | 4 +++- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 2 +- drivers/net/wireless/mediatek/mt76/tx.c | 9 ++++----- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wi= reless/mediatek/mt76/mac80211.c index d03aedc3286b..029599d68ca7 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -1100,7 +1100,7 @@ mt76_sta_add(struct mt76_dev *dev, struct ieee80211_v= if *vif, continue; =20 mtxq =3D (struct mt76_txq *)sta->txq[i]->drv_priv; - mtxq->wcid =3D wcid; + mtxq->wcid =3D wcid->idx; } =20 ewma_signal_init(&wcid->rssi); diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wirele= ss/mediatek/mt76/mt76.h index 6e4d69715927..d1f00706d41e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -263,7 +263,7 @@ struct mt76_wcid { }; =20 struct mt76_txq { - struct mt76_wcid *wcid; + u16 wcid; =20 u16 agg_ssn; bool send_bar; diff --git a/drivers/net/wireless/mediatek/mt76/mt7603/main.c b/drivers/net= /wireless/mediatek/mt76/mt7603/main.c index 7f52a4a11cea..0b7b87b4cc21 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7603/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7603/main.c @@ -74,7 +74,7 @@ mt7603_add_interface(struct ieee80211_hw *hw, struct ieee= 80211_vif *vif) mt7603_wtbl_init(dev, idx, mvif->idx, bc_addr); =20 mtxq =3D (struct mt76_txq *)vif->txq->drv_priv; - mtxq->wcid =3D &mvif->sta.wcid; + mtxq->wcid =3D idx; rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); =20 out: diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/main.c b/drivers/net= /wireless/mediatek/mt76/mt7615/main.c index 60a41d082961..7c52a4d85cea 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/main.c @@ -235,7 +235,7 @@ static int mt7615_add_interface(struct ieee80211_hw *hw, rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); if (vif->txq) { mtxq =3D (struct mt76_txq *)vif->txq->drv_priv; - mtxq->wcid =3D &mvif->sta.wcid; + mtxq->wcid =3D idx; } =20 ret =3D mt7615_mcu_add_dev_info(phy, vif, true); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c b/drivers/ne= t/wireless/mediatek/mt76/mt76x02_util.c index ccdbab341271..db7a4ffcad55 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c @@ -288,7 +288,8 @@ mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80= 211_vif *vif, mvif->group_wcid.idx =3D MT_VIF_WCID(idx); mvif->group_wcid.hw_key_idx =3D -1; mtxq =3D (struct mt76_txq *)vif->txq->drv_priv; - mtxq->wcid =3D &mvif->group_wcid; + rcu_assign_pointer(dev->mt76.wcid[MT_VIF_WCID(idx)], &mvif->group_wcid); + mtxq->wcid =3D MT_VIF_WCID(idx); } =20 int @@ -341,6 +342,7 @@ void mt76x02_remove_interface(struct ieee80211_hw *hw, struct mt76x02_vif *mvif =3D (struct mt76x02_vif *)vif->drv_priv; =20 dev->mt76.vif_mask &=3D ~BIT(mvif->idx); + rcu_assign_pointer(dev->mt76.wcid[mvif->group_wcid.idx], NULL); } EXPORT_SYMBOL_GPL(mt76x02_remove_interface); =20 diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net= /wireless/mediatek/mt76/mt7915/main.c index c25f8da590dd..6aca470e2401 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c @@ -243,7 +243,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw, rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); if (vif->txq) { mtxq =3D (struct mt76_txq *)vif->txq->drv_priv; - mtxq->wcid =3D &mvif->sta.wcid; + mtxq->wcid =3D idx; } =20 if (vif->type !=3D NL80211_IFTYPE_AP && diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net= /wireless/mediatek/mt76/mt7921/main.c index 13a7ae3d8351..6cb65391427f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c @@ -283,7 +283,7 @@ static int mt7921_add_interface(struct ieee80211_hw *hw, rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); if (vif->txq) { mtxq =3D (struct mt76_txq *)vif->txq->drv_priv; - mtxq->wcid =3D &mvif->sta.wcid; + mtxq->wcid =3D idx; } =20 out: diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless= /mediatek/mt76/tx.c index f0f7a913eaab..dce6f6b5f071 100644 --- a/drivers/net/wireless/mediatek/mt76/tx.c +++ b/drivers/net/wireless/mediatek/mt76/tx.c @@ -406,12 +406,11 @@ mt76_txq_stopped(struct mt76_queue *q) =20 static int mt76_txq_send_burst(struct mt76_phy *phy, struct mt76_queue *q, - struct mt76_txq *mtxq) + struct mt76_txq *mtxq, struct mt76_wcid *wcid) { struct mt76_dev *dev =3D phy->dev; struct ieee80211_txq *txq =3D mtxq_to_txq(mtxq); enum mt76_txq_id qid =3D mt76_txq_get_qid(txq); - struct mt76_wcid *wcid =3D mtxq->wcid; struct ieee80211_tx_info *info; struct sk_buff *skb; int n_frames =3D 1; @@ -491,8 +490,8 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_= txq_id qid) break; =20 mtxq =3D (struct mt76_txq *)txq->drv_priv; - wcid =3D mtxq->wcid; - if (wcid && test_bit(MT_WCID_FLAG_PS, &wcid->flags)) + wcid =3D rcu_dereference(dev->wcid[mtxq->wcid]); + if (!wcid || test_bit(MT_WCID_FLAG_PS, &wcid->flags)) continue; =20 spin_lock_bh(&q->lock); @@ -511,7 +510,7 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_= txq_id qid) } =20 if (!mt76_txq_stopped(q)) - n_frames =3D mt76_txq_send_burst(phy, q, mtxq); + n_frames =3D mt76_txq_send_burst(phy, q, mtxq, wcid); =20 spin_unlock_bh(&q->lock); =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F8D1C04A68 for ; Wed, 27 Jul 2022 17:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233248AbiG0RU6 (ORCPT ); Wed, 27 Jul 2022 13:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241899AbiG0RTS (ORCPT ); Wed, 27 Jul 2022 13:19:18 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFB1C7A524; Wed, 27 Jul 2022 09:44:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6402BB8200C; Wed, 27 Jul 2022 16:44:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36566C433D6; Wed, 27 Jul 2022 16:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940248; bh=wNIplsC///Z+1aLsiUGI7BR3SSo4CPpuOnzTbHZt7Zg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YSJrcV21spXwIq9Ks7zoYJnNwXVVvTodcRSZe4PmjZ4X4RUpx7vitFJ9gOJbN+51z rh8EEP5CZ8zruLVUOEKIuv00m5qIvWdIM1rBKauKNDWLkcDwAUxUhB1Uwdn3f3UkEQ sRU+DxEoda/6jHkzU+5PCJmBPvbKXiW+FcGWRBVQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg , Luca Coelho , Sasha Levin Subject: [PATCH 5.15 157/201] iwlwifi: fw: uefi: add missing include guards Date: Wed, 27 Jul 2022 18:11:01 +0200 Message-Id: <20220727161034.339315972@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Johannes Berg [ Upstream commit 91000fdf82195b66350b4f88413c2e8b5f94d994 ] We still don't use #pragma once in the kernel, but even if we did it'd be missing. Add the missing include guards. Signed-off-by: Johannes Berg Fixes: 84c3c9952afb ("iwlwifi: move UEFI code to a separate file") Signed-off-by: Luca Coelho Link: https://lore.kernel.org/r/iwlwifi.20211024181719.7fc9988ed49b.I87e300= fab664047581e51fb9b02744c75320d08c@changeid Signed-off-by: Luca Coelho Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/wireless/intel/iwlwifi/fw/uefi.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.h b/drivers/net/wir= eless/intel/iwlwifi/fw/uefi.h index 45d0b36d79b5..d552c656ac9f 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.h @@ -2,7 +2,8 @@ /* * Copyright(c) 2021 Intel Corporation */ - +#ifndef __iwl_fw_uefi__ +#define __iwl_fw_uefi__ =20 #define IWL_UEFI_OEM_PNVM_NAME L"UefiCnvWlanOemSignedPnvm" #define IWL_UEFI_REDUCED_POWER_NAME L"UefiCnvWlanReducedPower" @@ -40,3 +41,5 @@ void *iwl_uefi_get_reduced_power(struct iwl_trans *trans,= size_t *len) return ERR_PTR(-EOPNOTSUPP); } #endif /* CONFIG_EFI */ + +#endif /* __iwl_fw_uefi__ */ --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FF34C04A68 for ; Wed, 27 Jul 2022 17:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241978AbiG0RWf (ORCPT ); Wed, 27 Jul 2022 13:22:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241913AbiG0RTT (ORCPT ); Wed, 27 Jul 2022 13:19:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF22E5D0D5; Wed, 27 Jul 2022 09:44:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 39B7F60DDB; Wed, 27 Jul 2022 16:44:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F3A3C433C1; Wed, 27 Jul 2022 16:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940251; bh=8TAjTG3BVgjt6+mej6insq8utXxrMq0kT2BsFUAqqQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=orB/p/fmPQKpEBjcW4pJNSJdhZiBxIGfzcwgSbu/xdi8nvcPIaAcgfggg+nYlDQES 9xWPWUallzFOSaoBkagHs6ahwKvCncZcZMVQ+P1RqrPJRDEuBWBfkbCrdbQ83ivywk NEsmsPHxfL5Y8FNVdOrrzl77Rpc3Epj15iVnvx2I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Adam Guerin , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 158/201] crypto: qat - set to zero DH parameters before free Date: Wed, 27 Jul 2022 18:11:02 +0200 Message-Id: <20220727161034.370335483@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit 1731160ff7c7bbb11bb1aacb14dd25e18d522779 ] Set to zero the context buffers containing the DH key before they are freed. This is a defense in depth measure that avoids keys to be recovered from memory in case the system is compromised between the free of the buffer and when that area of memory (containing keys) gets overwritten. Cc: stable@vger.kernel.org Fixes: c9839143ebbf ("crypto: qat - Add DH support") Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index b0b78445418b..5633f9df3b6f 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -420,14 +420,17 @@ static int qat_dh_set_params(struct qat_dh_ctx *ctx, = struct dh *params) static void qat_dh_clear_ctx(struct device *dev, struct qat_dh_ctx *ctx) { if (ctx->g) { + memset(ctx->g, 0, ctx->p_size); dma_free_coherent(dev, ctx->p_size, ctx->g, ctx->dma_g); ctx->g =3D NULL; } if (ctx->xa) { + memset(ctx->xa, 0, ctx->p_size); dma_free_coherent(dev, ctx->p_size, ctx->xa, ctx->dma_xa); ctx->xa =3D NULL; } if (ctx->p) { + memset(ctx->p, 0, ctx->p_size); dma_free_coherent(dev, ctx->p_size, ctx->p, ctx->dma_p); ctx->p =3D NULL; } --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F915C04A68 for ; Wed, 27 Jul 2022 17:21:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235035AbiG0RVE (ORCPT ); Wed, 27 Jul 2022 13:21:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241925AbiG0RTV (ORCPT ); Wed, 27 Jul 2022 13:19:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 734F150721; Wed, 27 Jul 2022 09:44:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 057E4B821AC; Wed, 27 Jul 2022 16:44:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B3BAC433C1; Wed, 27 Jul 2022 16:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940254; bh=ExWebhwnzEVWFIDCEFYoZ68tGImeblCF9aJvnPOKp+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P70lwEOTvRwp/7j88lmbR4yMy+DRIrBVxSlfO6LxjDZ6wPPsnhOD2LT6LzvP+Wozw SzkK87BK7l34QvnDcD7NFGO+K+gxF0P3HumI7fpP1/xrXbrC+kSIxMDhURnNPOLm9V isJ5oHlHaryGtupVPzKZdp7Rz8S8NYeCOFoJLkVo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Giovanni Cabiddu , Marco Chiappero , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 159/201] crypto: qat - use pre-allocated buffers in datapath Date: Wed, 27 Jul 2022 18:11:03 +0200 Message-Id: <20220727161034.418781055@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit e0831e7af4e03f2715de102e18e9179ec0a81562 ] In order to do DMAs, the QAT device requires that the scatterlist structures are mapped and translated into a format that the firmware can understand. This is defined as the composition of a scatter gather list (SGL) descriptor header, the struct qat_alg_buf_list, plus a variable number of flat buffer descriptors, the struct qat_alg_buf. The allocation and mapping of these data structures is done each time a request is received from the skcipher and aead APIs. In an OOM situation, this behaviour might lead to a dead-lock if an allocation fails. Based on the conversation in [1], increase the size of the aead and skcipher request contexts to include an SGL descriptor that can handle a maximum of 4 flat buffers. If requests exceed 4 entries buffers, memory is allocated dynamically. [1] https://lore.kernel.org/linux-crypto/20200722072932.GA27544@gondor.apan= a.org.au/ Cc: stable@vger.kernel.org Fixes: d370cec32194 ("crypto: qat - Intel(R) QAT crypto interface") Reported-by: Mikulas Patocka Signed-off-by: Giovanni Cabiddu Reviewed-by: Marco Chiappero Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/qat_algs.c | 64 +++++++++++++--------- drivers/crypto/qat/qat_common/qat_crypto.h | 24 ++++++++ 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/= qat_common/qat_algs.c index f998ed58457c..ec635fe44c1f 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c @@ -46,19 +46,6 @@ static DEFINE_MUTEX(algs_lock); static unsigned int active_devs; =20 -struct qat_alg_buf { - u32 len; - u32 resrvd; - u64 addr; -} __packed; - -struct qat_alg_buf_list { - u64 resrvd; - u32 num_bufs; - u32 num_mapped_bufs; - struct qat_alg_buf bufers[]; -} __packed __aligned(64); - /* Common content descriptor */ struct qat_alg_cd { union { @@ -693,7 +680,10 @@ static void qat_alg_free_bufl(struct qat_crypto_instan= ce *inst, bl->bufers[i].len, DMA_BIDIRECTIONAL); =20 dma_unmap_single(dev, blp, sz, DMA_TO_DEVICE); - kfree(bl); + + if (!qat_req->buf.sgl_src_valid) + kfree(bl); + if (blp !=3D blpout) { /* If out of place operation dma unmap only data */ int bufless =3D blout->num_bufs - blout->num_mapped_bufs; @@ -704,7 +694,9 @@ static void qat_alg_free_bufl(struct qat_crypto_instanc= e *inst, DMA_BIDIRECTIONAL); } dma_unmap_single(dev, blpout, sz_out, DMA_TO_DEVICE); - kfree(blout); + + if (!qat_req->buf.sgl_dst_valid) + kfree(blout); } } =20 @@ -721,15 +713,24 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_inst= ance *inst, dma_addr_t blp =3D DMA_MAPPING_ERROR; dma_addr_t bloutp =3D DMA_MAPPING_ERROR; struct scatterlist *sg; - size_t sz_out, sz =3D struct_size(bufl, bufers, n + 1); + size_t sz_out, sz =3D struct_size(bufl, bufers, n); + int node =3D dev_to_node(&GET_DEV(inst->accel_dev)); =20 if (unlikely(!n)) return -EINVAL; =20 - bufl =3D kzalloc_node(sz, GFP_ATOMIC, - dev_to_node(&GET_DEV(inst->accel_dev))); - if (unlikely(!bufl)) - return -ENOMEM; + qat_req->buf.sgl_src_valid =3D false; + qat_req->buf.sgl_dst_valid =3D false; + + if (n > QAT_MAX_BUFF_DESC) { + bufl =3D kzalloc_node(sz, GFP_ATOMIC, node); + if (unlikely(!bufl)) + return -ENOMEM; + } else { + bufl =3D &qat_req->buf.sgl_src.sgl_hdr; + memset(bufl, 0, sizeof(struct qat_alg_buf_list)); + qat_req->buf.sgl_src_valid =3D true; + } =20 for_each_sg(sgl, sg, n, i) bufl->bufers[i].addr =3D DMA_MAPPING_ERROR; @@ -760,12 +761,18 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_inst= ance *inst, struct qat_alg_buf *bufers; =20 n =3D sg_nents(sglout); - sz_out =3D struct_size(buflout, bufers, n + 1); + sz_out =3D struct_size(buflout, bufers, n); sg_nctr =3D 0; - buflout =3D kzalloc_node(sz_out, GFP_ATOMIC, - dev_to_node(&GET_DEV(inst->accel_dev))); - if (unlikely(!buflout)) - goto err_in; + + if (n > QAT_MAX_BUFF_DESC) { + buflout =3D kzalloc_node(sz_out, GFP_ATOMIC, node); + if (unlikely(!buflout)) + goto err_in; + } else { + buflout =3D &qat_req->buf.sgl_dst.sgl_hdr; + memset(buflout, 0, sizeof(struct qat_alg_buf_list)); + qat_req->buf.sgl_dst_valid =3D true; + } =20 bufers =3D buflout->bufers; for_each_sg(sglout, sg, n, i) @@ -810,7 +817,9 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instan= ce *inst, dma_unmap_single(dev, buflout->bufers[i].addr, buflout->bufers[i].len, DMA_BIDIRECTIONAL); - kfree(buflout); + + if (!qat_req->buf.sgl_dst_valid) + kfree(buflout); =20 err_in: if (!dma_mapping_error(dev, blp)) @@ -823,7 +832,8 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instan= ce *inst, bufl->bufers[i].len, DMA_BIDIRECTIONAL); =20 - kfree(bufl); + if (!qat_req->buf.sgl_src_valid) + kfree(bufl); =20 dev_err(dev, "Failed to map buf for dma\n"); return -ENOMEM; diff --git a/drivers/crypto/qat/qat_common/qat_crypto.h b/drivers/crypto/qa= t/qat_common/qat_crypto.h index b6a4c95ae003..0928f159ea99 100644 --- a/drivers/crypto/qat/qat_common/qat_crypto.h +++ b/drivers/crypto/qat/qat_common/qat_crypto.h @@ -21,6 +21,26 @@ struct qat_crypto_instance { atomic_t refctr; }; =20 +#define QAT_MAX_BUFF_DESC 4 + +struct qat_alg_buf { + u32 len; + u32 resrvd; + u64 addr; +} __packed; + +struct qat_alg_buf_list { + u64 resrvd; + u32 num_bufs; + u32 num_mapped_bufs; + struct qat_alg_buf bufers[]; +} __packed; + +struct qat_alg_fixed_buf_list { + struct qat_alg_buf_list sgl_hdr; + struct qat_alg_buf descriptors[QAT_MAX_BUFF_DESC]; +} __packed __aligned(64); + struct qat_crypto_request_buffs { struct qat_alg_buf_list *bl; dma_addr_t blp; @@ -28,6 +48,10 @@ struct qat_crypto_request_buffs { dma_addr_t bloutp; size_t sz; size_t sz_out; + bool sgl_src_valid; + bool sgl_dst_valid; + struct qat_alg_fixed_buf_list sgl_src; + struct qat_alg_fixed_buf_list sgl_dst; }; =20 struct qat_crypto_request; --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67A45C04A68 for ; Wed, 27 Jul 2022 17:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241984AbiG0RWh (ORCPT ); Wed, 27 Jul 2022 13:22:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241926AbiG0RTV (ORCPT ); Wed, 27 Jul 2022 13:19:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92CF6208; Wed, 27 Jul 2022 09:44:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2273060D38; Wed, 27 Jul 2022 16:44:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C50FC433C1; Wed, 27 Jul 2022 16:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940257; bh=+9KYwtAfBnvIPRxmG1LUJjQiRGL2lwUX5bl1iyruOVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oKM8lL3NeqtlpZaezCfn4IObXyycZdKVJWTBT5ZKlSay2r7oP8UZvviLhxtUhjWks TLl7uc3X/rgvP8EsUhoMPUqDnA2Eq0oa4qVqsc07vzL9E0prkjaFWXzCd33CtWafv5 mltdWbwOHFRb83+s3LOFcIKeH/zKipgVr570L1G4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Marco Chiappero , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 160/201] crypto: qat - refactor submission logic Date: Wed, 27 Jul 2022 18:11:04 +0200 Message-Id: <20220727161034.469428961@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit af88d3c109aa5edfaa11c9a26d9c0ff21ddf501c ] All the algorithms in qat_algs.c and qat_asym_algs.c use the same pattern to submit messages to the HW queues. Move the submission loop to a new function, qat_alg_send_message(), and share it between the symmetric and the asymmetric algorithms. As part of this rework, since the number of retries before returning an error is inconsistent between the symmetric and asymmetric implementations, set it to a value that works for both (i.e. 20, was 10 in qat_algs.c and 100 in qat_asym_algs.c) In addition fix the return code reported when the HW queues are full. In that case return -ENOSPC instead of -EBUSY. Including stable in CC since (1) the error code returned if the HW queues are full is incorrect and (2) to facilitate the backport of the next fix "crypto: qat - add backlog mechanism". Cc: stable@vger.kernel.org Signed-off-by: Giovanni Cabiddu Reviewed-by: Marco Chiappero Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/Makefile | 1 + drivers/crypto/qat/qat_common/qat_algs.c | 68 +++++++++---------- drivers/crypto/qat/qat_common/qat_algs_send.c | 21 ++++++ drivers/crypto/qat/qat_common/qat_algs_send.h | 10 +++ drivers/crypto/qat/qat_common/qat_asym_algs.c | 50 +++++++++----- drivers/crypto/qat/qat_common/qat_crypto.h | 5 ++ 6 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 drivers/crypto/qat/qat_common/qat_algs_send.c create mode 100644 drivers/crypto/qat/qat_common/qat_algs_send.h diff --git a/drivers/crypto/qat/qat_common/Makefile b/drivers/crypto/qat/qa= t_common/Makefile index 9c57abdf56b7..fc477f016213 100644 --- a/drivers/crypto/qat/qat_common/Makefile +++ b/drivers/crypto/qat/qat_common/Makefile @@ -15,6 +15,7 @@ intel_qat-objs :=3D adf_cfg.o \ qat_crypto.o \ qat_algs.o \ qat_asym_algs.o \ + qat_algs_send.o \ qat_uclo.o \ qat_hal.o =20 diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/= qat_common/qat_algs.c index ec635fe44c1f..6017ae82c713 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c @@ -17,7 +17,7 @@ #include #include #include "adf_accel_devices.h" -#include "adf_transport.h" +#include "qat_algs_send.h" #include "adf_common_drv.h" #include "qat_crypto.h" #include "icp_qat_hw.h" @@ -939,6 +939,17 @@ void qat_alg_callback(void *resp) qat_req->cb(qat_resp, qat_req); } =20 +static int qat_alg_send_sym_message(struct qat_crypto_request *qat_req, + struct qat_crypto_instance *inst) +{ + struct qat_alg_req req; + + req.fw_req =3D (u32 *)&qat_req->req; + req.tx_ring =3D inst->sym_tx; + + return qat_alg_send_message(&req); +} + static int qat_alg_aead_dec(struct aead_request *areq) { struct crypto_aead *aead_tfm =3D crypto_aead_reqtfm(areq); @@ -949,7 +960,7 @@ static int qat_alg_aead_dec(struct aead_request *areq) struct icp_qat_fw_la_auth_req_params *auth_param; struct icp_qat_fw_la_bulk_req *msg; int digst_size =3D crypto_aead_authsize(aead_tfm); - int ret, ctr =3D 0; + int ret; u32 cipher_len; =20 cipher_len =3D areq->cryptlen - digst_size; @@ -975,15 +986,12 @@ static int qat_alg_aead_dec(struct aead_request *areq) auth_param =3D (void *)((u8 *)cipher_param + sizeof(*cipher_param)); auth_param->auth_off =3D 0; auth_param->auth_len =3D areq->assoclen + cipher_param->cipher_length; - do { - ret =3D adf_send_message(ctx->inst->sym_tx, (u32 *)msg); - } while (ret =3D=3D -EAGAIN && ctr++ < 10); =20 - if (ret =3D=3D -EAGAIN) { + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); - return -EBUSY; - } - return -EINPROGRESS; + + return ret; } =20 static int qat_alg_aead_enc(struct aead_request *areq) @@ -996,7 +1004,7 @@ static int qat_alg_aead_enc(struct aead_request *areq) struct icp_qat_fw_la_auth_req_params *auth_param; struct icp_qat_fw_la_bulk_req *msg; u8 *iv =3D areq->iv; - int ret, ctr =3D 0; + int ret; =20 if (areq->cryptlen % AES_BLOCK_SIZE !=3D 0) return -EINVAL; @@ -1023,15 +1031,11 @@ static int qat_alg_aead_enc(struct aead_request *ar= eq) auth_param->auth_off =3D 0; auth_param->auth_len =3D areq->assoclen + areq->cryptlen; =20 - do { - ret =3D adf_send_message(ctx->inst->sym_tx, (u32 *)msg); - } while (ret =3D=3D -EAGAIN && ctr++ < 10); - - if (ret =3D=3D -EAGAIN) { + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); - return -EBUSY; - } - return -EINPROGRESS; + + return ret; } =20 static int qat_alg_skcipher_rekey(struct qat_alg_skcipher_ctx *ctx, @@ -1184,7 +1188,7 @@ static int qat_alg_skcipher_encrypt(struct skcipher_r= equest *req) struct qat_crypto_request *qat_req =3D skcipher_request_ctx(req); struct icp_qat_fw_la_cipher_req_params *cipher_param; struct icp_qat_fw_la_bulk_req *msg; - int ret, ctr =3D 0; + int ret; =20 if (req->cryptlen =3D=3D 0) return 0; @@ -1208,15 +1212,11 @@ static int qat_alg_skcipher_encrypt(struct skcipher= _request *req) =20 qat_alg_set_req_iv(qat_req); =20 - do { - ret =3D adf_send_message(ctx->inst->sym_tx, (u32 *)msg); - } while (ret =3D=3D -EAGAIN && ctr++ < 10); - - if (ret =3D=3D -EAGAIN) { + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); - return -EBUSY; - } - return -EINPROGRESS; + + return ret; } =20 static int qat_alg_skcipher_blk_encrypt(struct skcipher_request *req) @@ -1253,7 +1253,7 @@ static int qat_alg_skcipher_decrypt(struct skcipher_r= equest *req) struct qat_crypto_request *qat_req =3D skcipher_request_ctx(req); struct icp_qat_fw_la_cipher_req_params *cipher_param; struct icp_qat_fw_la_bulk_req *msg; - int ret, ctr =3D 0; + int ret; =20 if (req->cryptlen =3D=3D 0) return 0; @@ -1278,15 +1278,11 @@ static int qat_alg_skcipher_decrypt(struct skcipher= _request *req) qat_alg_set_req_iv(qat_req); qat_alg_update_iv(qat_req); =20 - do { - ret =3D adf_send_message(ctx->inst->sym_tx, (u32 *)msg); - } while (ret =3D=3D -EAGAIN && ctr++ < 10); - - if (ret =3D=3D -EAGAIN) { + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); - return -EBUSY; - } - return -EINPROGRESS; + + return ret; } =20 static int qat_alg_skcipher_blk_decrypt(struct skcipher_request *req) diff --git a/drivers/crypto/qat/qat_common/qat_algs_send.c b/drivers/crypto= /qat/qat_common/qat_algs_send.c new file mode 100644 index 000000000000..78f1bb8c26c0 --- /dev/null +++ b/drivers/crypto/qat/qat_common/qat_algs_send.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) +/* Copyright(c) 2022 Intel Corporation */ +#include "adf_transport.h" +#include "qat_algs_send.h" +#include "qat_crypto.h" + +#define ADF_MAX_RETRIES 20 + +int qat_alg_send_message(struct qat_alg_req *req) +{ + int ret =3D 0, ctr =3D 0; + + do { + ret =3D adf_send_message(req->tx_ring, req->fw_req); + } while (ret =3D=3D -EAGAIN && ctr++ < ADF_MAX_RETRIES); + + if (ret =3D=3D -EAGAIN) + return -ENOSPC; + + return -EINPROGRESS; +} diff --git a/drivers/crypto/qat/qat_common/qat_algs_send.h b/drivers/crypto= /qat/qat_common/qat_algs_send.h new file mode 100644 index 000000000000..3fa685d0c293 --- /dev/null +++ b/drivers/crypto/qat/qat_common/qat_algs_send.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */ +/* Copyright(c) 2022 Intel Corporation */ +#ifndef QAT_ALGS_SEND_H +#define QAT_ALGS_SEND_H + +#include "qat_crypto.h" + +int qat_alg_send_message(struct qat_alg_req *req); + +#endif diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index 5633f9df3b6f..08b8d83e070a 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -12,6 +12,7 @@ #include #include "icp_qat_fw_pke.h" #include "adf_accel_devices.h" +#include "qat_algs_send.h" #include "adf_transport.h" #include "adf_common_drv.h" #include "qat_crypto.h" @@ -137,6 +138,17 @@ struct qat_asym_request { void (*cb)(struct icp_qat_fw_pke_resp *resp); } __aligned(64); =20 +static int qat_alg_send_asym_message(struct qat_asym_request *qat_req, + struct qat_crypto_instance *inst) +{ + struct qat_alg_req req; + + req.fw_req =3D (u32 *)&qat_req->req; + req.tx_ring =3D inst->pke_tx; + + return qat_alg_send_message(&req); +} + static void qat_dh_cb(struct icp_qat_fw_pke_resp *resp) { struct qat_asym_request *req =3D (void *)(__force long)resp->opaque; @@ -213,7 +225,7 @@ static int qat_dh_compute_value(struct kpp_request *req) struct qat_asym_request *qat_req =3D PTR_ALIGN(kpp_request_ctx(req), 64); struct icp_qat_fw_pke_request *msg =3D &qat_req->req; - int ret, ctr =3D 0; + int ret; int n_input_params =3D 0; =20 if (unlikely(!ctx->xa)) @@ -338,13 +350,13 @@ static int qat_dh_compute_value(struct kpp_request *r= eq) msg->input_param_count =3D n_input_params; msg->output_param_count =3D 1; =20 - do { - ret =3D adf_send_message(ctx->inst->pke_tx, (u32 *)msg); - } while (ret =3D=3D -EBUSY && ctr++ < 100); + ret =3D qat_alg_send_asym_message(qat_req, ctx->inst); + if (ret =3D=3D -ENOSPC) + goto unmap_all; =20 - if (!ret) - return -EINPROGRESS; + return ret; =20 +unmap_all: if (!dma_mapping_error(dev, qat_req->phy_out)) dma_unmap_single(dev, qat_req->phy_out, sizeof(struct qat_dh_output_params), @@ -645,7 +657,7 @@ static int qat_rsa_enc(struct akcipher_request *req) struct qat_asym_request *qat_req =3D PTR_ALIGN(akcipher_request_ctx(req), 64); struct icp_qat_fw_pke_request *msg =3D &qat_req->req; - int ret, ctr =3D 0; + int ret; =20 if (unlikely(!ctx->n || !ctx->e)) return -EINVAL; @@ -735,13 +747,14 @@ static int qat_rsa_enc(struct akcipher_request *req) msg->pke_mid.opaque =3D (u64)(__force long)qat_req; msg->input_param_count =3D 3; msg->output_param_count =3D 1; - do { - ret =3D adf_send_message(ctx->inst->pke_tx, (u32 *)msg); - } while (ret =3D=3D -EBUSY && ctr++ < 100); =20 - if (!ret) - return -EINPROGRESS; + ret =3D qat_alg_send_asym_message(qat_req, ctx->inst); + if (ret =3D=3D -ENOSPC) + goto unmap_all; + + return ret; =20 +unmap_all: if (!dma_mapping_error(dev, qat_req->phy_out)) dma_unmap_single(dev, qat_req->phy_out, sizeof(struct qat_rsa_output_params), @@ -779,7 +792,7 @@ static int qat_rsa_dec(struct akcipher_request *req) struct qat_asym_request *qat_req =3D PTR_ALIGN(akcipher_request_ctx(req), 64); struct icp_qat_fw_pke_request *msg =3D &qat_req->req; - int ret, ctr =3D 0; + int ret; =20 if (unlikely(!ctx->n || !ctx->d)) return -EINVAL; @@ -887,13 +900,14 @@ static int qat_rsa_dec(struct akcipher_request *req) msg->input_param_count =3D 3; =20 msg->output_param_count =3D 1; - do { - ret =3D adf_send_message(ctx->inst->pke_tx, (u32 *)msg); - } while (ret =3D=3D -EBUSY && ctr++ < 100); =20 - if (!ret) - return -EINPROGRESS; + ret =3D qat_alg_send_asym_message(qat_req, ctx->inst); + if (ret =3D=3D -ENOSPC) + goto unmap_all; + + return ret; =20 +unmap_all: if (!dma_mapping_error(dev, qat_req->phy_out)) dma_unmap_single(dev, qat_req->phy_out, sizeof(struct qat_rsa_output_params), diff --git a/drivers/crypto/qat/qat_common/qat_crypto.h b/drivers/crypto/qa= t/qat_common/qat_crypto.h index 0928f159ea99..0dcba6fc358c 100644 --- a/drivers/crypto/qat/qat_common/qat_crypto.h +++ b/drivers/crypto/qat/qat_common/qat_crypto.h @@ -9,6 +9,11 @@ #include "adf_accel_devices.h" #include "icp_qat_fw_la.h" =20 +struct qat_alg_req { + u32 *fw_req; + struct adf_etr_ring_data *tx_ring; +}; + struct qat_crypto_instance { struct adf_etr_ring_data *sym_tx; struct adf_etr_ring_data *sym_rx; --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2631BC19F28 for ; Wed, 27 Jul 2022 17:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237853AbiG0RVP (ORCPT ); Wed, 27 Jul 2022 13:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241937AbiG0RTW (ORCPT ); Wed, 27 Jul 2022 13:19:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7B18102C; Wed, 27 Jul 2022 09:44:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 81FDBB8200D; Wed, 27 Jul 2022 16:44:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4B4AC433C1; Wed, 27 Jul 2022 16:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940260; bh=BpLrPQP3pUCcqiOoA3Bje3bW8VidC0Xr73YT5Hg91gs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OMtT+35r9piJq1qqvBha+V5rRkk8SfwoPXXFfDu31//F2UMzN5tHb0ZXF/q/t+rsb lvDSgXHGTIqe9Hh2daHaiTW/yQKJFp61g425RWQCdNrt64I8IFr+esb8A1s2MTAyVf D06xTbw0RUsEcsjfON9T50Tyjnh0i0Ovavk5O9rA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Kyle Sanderson , Giovanni Cabiddu , Marco Chiappero , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 161/201] crypto: qat - add backlog mechanism Date: Wed, 27 Jul 2022 18:11:05 +0200 Message-Id: <20220727161034.515042280@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit 38682383973280e5be2802ba8a8d4a636d36cb19 ] The implementations of the crypto algorithms (aead, skcipher, etc) in the QAT driver do not properly support requests with the CRYPTO_TFM_REQ_MAY_BACKLOG flag set. If the HW queue is full, the driver returns -EBUSY but does not enqueue the request. This can result in applications like dm-crypt waiting indefinitely for the completion of a request that was never submitted to the hardware. Fix this by adding a software backlog queue: if the ring buffer is more than eighty percent full, then the request is enqueued to a backlog list and the error code -EBUSY is returned back to the caller. Requests in the backlog queue are resubmitted at a later time, in the context of the callback of a previously submitted request. The request for which -EBUSY is returned is then marked as -EINPROGRESS once submitted to the HW queues. The submission loop inside the function qat_alg_send_message() has been modified to decide which submission policy to use based on the request flags. If the request does not have the CRYPTO_TFM_REQ_MAY_BACKLOG set, the previous behaviour has been preserved. Based on a patch by Vishnu Das Ramachandran Cc: stable@vger.kernel.org Fixes: d370cec32194 ("crypto: qat - Intel(R) QAT crypto interface") Reported-by: Mikulas Patocka Reported-by: Kyle Sanderson Signed-off-by: Giovanni Cabiddu Reviewed-by: Marco Chiappero Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/adf_transport.c | 11 +++ drivers/crypto/qat/qat_common/adf_transport.h | 1 + .../qat/qat_common/adf_transport_internal.h | 1 + drivers/crypto/qat/qat_common/qat_algs.c | 24 ++++--- drivers/crypto/qat/qat_common/qat_algs_send.c | 67 ++++++++++++++++++- drivers/crypto/qat/qat_common/qat_algs_send.h | 1 + drivers/crypto/qat/qat_common/qat_asym_algs.c | 23 ++++--- drivers/crypto/qat/qat_common/qat_crypto.c | 3 + drivers/crypto/qat/qat_common/qat_crypto.h | 10 +++ 9 files changed, 123 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/qat/qat_common/adf_transport.c b/drivers/crypto= /qat/qat_common/adf_transport.c index 8ba28409fb74..630d0483c4e0 100644 --- a/drivers/crypto/qat/qat_common/adf_transport.c +++ b/drivers/crypto/qat/qat_common/adf_transport.c @@ -8,6 +8,9 @@ #include "adf_cfg.h" #include "adf_common_drv.h" =20 +#define ADF_MAX_RING_THRESHOLD 80 +#define ADF_PERCENT(tot, percent) (((tot) * (percent)) / 100) + static inline u32 adf_modulo(u32 data, u32 shift) { u32 div =3D data >> shift; @@ -77,6 +80,11 @@ static void adf_disable_ring_irq(struct adf_etr_bank_dat= a *bank, u32 ring) bank->irq_mask); } =20 +bool adf_ring_nearly_full(struct adf_etr_ring_data *ring) +{ + return atomic_read(ring->inflights) > ring->threshold; +} + int adf_send_message(struct adf_etr_ring_data *ring, u32 *msg) { struct adf_hw_csr_ops *csr_ops =3D GET_CSR_OPS(ring->bank->accel_dev); @@ -217,6 +225,7 @@ int adf_create_ring(struct adf_accel_dev *accel_dev, co= nst char *section, struct adf_etr_bank_data *bank; struct adf_etr_ring_data *ring; char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES]; + int max_inflights; u32 ring_num; int ret; =20 @@ -263,6 +272,8 @@ int adf_create_ring(struct adf_accel_dev *accel_dev, co= nst char *section, ring->ring_size =3D adf_verify_ring_size(msg_size, num_msgs); ring->head =3D 0; ring->tail =3D 0; + max_inflights =3D ADF_MAX_INFLIGHTS(ring->ring_size, ring->msg_size); + ring->threshold =3D ADF_PERCENT(max_inflights, ADF_MAX_RING_THRESHOLD); atomic_set(ring->inflights, 0); ret =3D adf_init_ring(ring); if (ret) diff --git a/drivers/crypto/qat/qat_common/adf_transport.h b/drivers/crypto= /qat/qat_common/adf_transport.h index 2c95f1697c76..e6ef6f9b7691 100644 --- a/drivers/crypto/qat/qat_common/adf_transport.h +++ b/drivers/crypto/qat/qat_common/adf_transport.h @@ -14,6 +14,7 @@ int adf_create_ring(struct adf_accel_dev *accel_dev, cons= t char *section, const char *ring_name, adf_callback_fn callback, int poll_mode, struct adf_etr_ring_data **ring_ptr); =20 +bool adf_ring_nearly_full(struct adf_etr_ring_data *ring); int adf_send_message(struct adf_etr_ring_data *ring, u32 *msg); void adf_remove_ring(struct adf_etr_ring_data *ring); #endif diff --git a/drivers/crypto/qat/qat_common/adf_transport_internal.h b/drive= rs/crypto/qat/qat_common/adf_transport_internal.h index 501bcf0f1809..8b2c92ba7ca1 100644 --- a/drivers/crypto/qat/qat_common/adf_transport_internal.h +++ b/drivers/crypto/qat/qat_common/adf_transport_internal.h @@ -22,6 +22,7 @@ struct adf_etr_ring_data { spinlock_t lock; /* protects ring data struct */ u16 head; u16 tail; + u32 threshold; u8 ring_number; u8 ring_size; u8 msg_size; diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/= qat_common/qat_algs.c index 6017ae82c713..873533dc43a7 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c @@ -935,19 +935,25 @@ void qat_alg_callback(void *resp) struct icp_qat_fw_la_resp *qat_resp =3D resp; struct qat_crypto_request *qat_req =3D (void *)(__force long)qat_resp->opaque_data; + struct qat_instance_backlog *backlog =3D qat_req->alg_req.backlog; =20 qat_req->cb(qat_resp, qat_req); + + qat_alg_send_backlog(backlog); } =20 static int qat_alg_send_sym_message(struct qat_crypto_request *qat_req, - struct qat_crypto_instance *inst) + struct qat_crypto_instance *inst, + struct crypto_async_request *base) { - struct qat_alg_req req; + struct qat_alg_req *alg_req =3D &qat_req->alg_req; =20 - req.fw_req =3D (u32 *)&qat_req->req; - req.tx_ring =3D inst->sym_tx; + alg_req->fw_req =3D (u32 *)&qat_req->req; + alg_req->tx_ring =3D inst->sym_tx; + alg_req->base =3D base; + alg_req->backlog =3D &inst->backlog; =20 - return qat_alg_send_message(&req); + return qat_alg_send_message(alg_req); } =20 static int qat_alg_aead_dec(struct aead_request *areq) @@ -987,7 +993,7 @@ static int qat_alg_aead_dec(struct aead_request *areq) auth_param->auth_off =3D 0; auth_param->auth_len =3D areq->assoclen + cipher_param->cipher_length; =20 - ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst, &areq->base); if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); =20 @@ -1031,7 +1037,7 @@ static int qat_alg_aead_enc(struct aead_request *areq) auth_param->auth_off =3D 0; auth_param->auth_len =3D areq->assoclen + areq->cryptlen; =20 - ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst, &areq->base); if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); =20 @@ -1212,7 +1218,7 @@ static int qat_alg_skcipher_encrypt(struct skcipher_r= equest *req) =20 qat_alg_set_req_iv(qat_req); =20 - ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst, &req->base); if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); =20 @@ -1278,7 +1284,7 @@ static int qat_alg_skcipher_decrypt(struct skcipher_r= equest *req) qat_alg_set_req_iv(qat_req); qat_alg_update_iv(qat_req); =20 - ret =3D qat_alg_send_sym_message(qat_req, ctx->inst); + ret =3D qat_alg_send_sym_message(qat_req, ctx->inst, &req->base); if (ret =3D=3D -ENOSPC) qat_alg_free_bufl(ctx->inst, qat_req); =20 diff --git a/drivers/crypto/qat/qat_common/qat_algs_send.c b/drivers/crypto= /qat/qat_common/qat_algs_send.c index 78f1bb8c26c0..ff5b4347f783 100644 --- a/drivers/crypto/qat/qat_common/qat_algs_send.c +++ b/drivers/crypto/qat/qat_common/qat_algs_send.c @@ -6,7 +6,7 @@ =20 #define ADF_MAX_RETRIES 20 =20 -int qat_alg_send_message(struct qat_alg_req *req) +static int qat_alg_send_message_retry(struct qat_alg_req *req) { int ret =3D 0, ctr =3D 0; =20 @@ -19,3 +19,68 @@ int qat_alg_send_message(struct qat_alg_req *req) =20 return -EINPROGRESS; } + +void qat_alg_send_backlog(struct qat_instance_backlog *backlog) +{ + struct qat_alg_req *req, *tmp; + + spin_lock_bh(&backlog->lock); + list_for_each_entry_safe(req, tmp, &backlog->list, list) { + if (adf_send_message(req->tx_ring, req->fw_req)) { + /* The HW ring is full. Do nothing. + * qat_alg_send_backlog() will be invoked again by + * another callback. + */ + break; + } + list_del(&req->list); + req->base->complete(req->base, -EINPROGRESS); + } + spin_unlock_bh(&backlog->lock); +} + +static void qat_alg_backlog_req(struct qat_alg_req *req, + struct qat_instance_backlog *backlog) +{ + INIT_LIST_HEAD(&req->list); + + spin_lock_bh(&backlog->lock); + list_add_tail(&req->list, &backlog->list); + spin_unlock_bh(&backlog->lock); +} + +static int qat_alg_send_message_maybacklog(struct qat_alg_req *req) +{ + struct qat_instance_backlog *backlog =3D req->backlog; + struct adf_etr_ring_data *tx_ring =3D req->tx_ring; + u32 *fw_req =3D req->fw_req; + + /* If any request is already backlogged, then add to backlog list */ + if (!list_empty(&backlog->list)) + goto enqueue; + + /* If ring is nearly full, then add to backlog list */ + if (adf_ring_nearly_full(tx_ring)) + goto enqueue; + + /* If adding request to HW ring fails, then add to backlog list */ + if (adf_send_message(tx_ring, fw_req)) + goto enqueue; + + return -EINPROGRESS; + +enqueue: + qat_alg_backlog_req(req, backlog); + + return -EBUSY; +} + +int qat_alg_send_message(struct qat_alg_req *req) +{ + u32 flags =3D req->base->flags; + + if (flags & CRYPTO_TFM_REQ_MAY_BACKLOG) + return qat_alg_send_message_maybacklog(req); + else + return qat_alg_send_message_retry(req); +} diff --git a/drivers/crypto/qat/qat_common/qat_algs_send.h b/drivers/crypto= /qat/qat_common/qat_algs_send.h index 3fa685d0c293..5ce9f4f69d8f 100644 --- a/drivers/crypto/qat/qat_common/qat_algs_send.h +++ b/drivers/crypto/qat/qat_common/qat_algs_send.h @@ -6,5 +6,6 @@ #include "qat_crypto.h" =20 int qat_alg_send_message(struct qat_alg_req *req); +void qat_alg_send_backlog(struct qat_instance_backlog *backlog); =20 #endif diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index 08b8d83e070a..ff7249c093c9 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -136,17 +136,21 @@ struct qat_asym_request { } areq; int err; void (*cb)(struct icp_qat_fw_pke_resp *resp); + struct qat_alg_req alg_req; } __aligned(64); =20 static int qat_alg_send_asym_message(struct qat_asym_request *qat_req, - struct qat_crypto_instance *inst) + struct qat_crypto_instance *inst, + struct crypto_async_request *base) { - struct qat_alg_req req; + struct qat_alg_req *alg_req =3D &qat_req->alg_req; =20 - req.fw_req =3D (u32 *)&qat_req->req; - req.tx_ring =3D inst->pke_tx; + alg_req->fw_req =3D (u32 *)&qat_req->req; + alg_req->tx_ring =3D inst->pke_tx; + alg_req->base =3D base; + alg_req->backlog =3D &inst->backlog; =20 - return qat_alg_send_message(&req); + return qat_alg_send_message(alg_req); } =20 static void qat_dh_cb(struct icp_qat_fw_pke_resp *resp) @@ -350,7 +354,7 @@ static int qat_dh_compute_value(struct kpp_request *req) msg->input_param_count =3D n_input_params; msg->output_param_count =3D 1; =20 - ret =3D qat_alg_send_asym_message(qat_req, ctx->inst); + ret =3D qat_alg_send_asym_message(qat_req, inst, &req->base); if (ret =3D=3D -ENOSPC) goto unmap_all; =20 @@ -557,8 +561,11 @@ void qat_alg_asym_callback(void *_resp) { struct icp_qat_fw_pke_resp *resp =3D _resp; struct qat_asym_request *areq =3D (void *)(__force long)resp->opaque; + struct qat_instance_backlog *backlog =3D areq->alg_req.backlog; =20 areq->cb(resp); + + qat_alg_send_backlog(backlog); } =20 #define PKE_RSA_EP_512 0x1c161b21 @@ -748,7 +755,7 @@ static int qat_rsa_enc(struct akcipher_request *req) msg->input_param_count =3D 3; msg->output_param_count =3D 1; =20 - ret =3D qat_alg_send_asym_message(qat_req, ctx->inst); + ret =3D qat_alg_send_asym_message(qat_req, inst, &req->base); if (ret =3D=3D -ENOSPC) goto unmap_all; =20 @@ -901,7 +908,7 @@ static int qat_rsa_dec(struct akcipher_request *req) =20 msg->output_param_count =3D 1; =20 - ret =3D qat_alg_send_asym_message(qat_req, ctx->inst); + ret =3D qat_alg_send_asym_message(qat_req, inst, &req->base); if (ret =3D=3D -ENOSPC) goto unmap_all; =20 diff --git a/drivers/crypto/qat/qat_common/qat_crypto.c b/drivers/crypto/qa= t/qat_common/qat_crypto.c index 3efbb3883601..59e122afa434 100644 --- a/drivers/crypto/qat/qat_common/qat_crypto.c +++ b/drivers/crypto/qat/qat_common/qat_crypto.c @@ -328,6 +328,9 @@ static int qat_crypto_create_instances(struct adf_accel= _dev *accel_dev) &inst->pke_rx); if (ret) goto err; + + INIT_LIST_HEAD(&inst->backlog.list); + spin_lock_init(&inst->backlog.lock); } return 0; err: diff --git a/drivers/crypto/qat/qat_common/qat_crypto.h b/drivers/crypto/qa= t/qat_common/qat_crypto.h index 0dcba6fc358c..245b6d9a3650 100644 --- a/drivers/crypto/qat/qat_common/qat_crypto.h +++ b/drivers/crypto/qat/qat_common/qat_crypto.h @@ -9,9 +9,17 @@ #include "adf_accel_devices.h" #include "icp_qat_fw_la.h" =20 +struct qat_instance_backlog { + struct list_head list; + spinlock_t lock; /* protects backlog list */ +}; + struct qat_alg_req { u32 *fw_req; struct adf_etr_ring_data *tx_ring; + struct crypto_async_request *base; + struct list_head list; + struct qat_instance_backlog *backlog; }; =20 struct qat_crypto_instance { @@ -24,6 +32,7 @@ struct qat_crypto_instance { unsigned long state; int id; atomic_t refctr; + struct qat_instance_backlog backlog; }; =20 #define QAT_MAX_BUFF_DESC 4 @@ -82,6 +91,7 @@ struct qat_crypto_request { u8 iv[AES_BLOCK_SIZE]; }; bool encryption; + struct qat_alg_req alg_req; }; =20 static inline bool adf_hw_dev_has_crypto(struct adf_accel_dev *accel_dev) --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9C23C04A68 for ; Wed, 27 Jul 2022 17:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241894AbiG0RVI (ORCPT ); Wed, 27 Jul 2022 13:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241942AbiG0RTW (ORCPT ); Wed, 27 Jul 2022 13:19:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16435B3; Wed, 27 Jul 2022 09:44:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B4C14B8200C; Wed, 27 Jul 2022 16:44:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D20FCC433D7; Wed, 27 Jul 2022 16:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940263; bh=9I/JEJjN3N7i7yzhTwu3g+bbof/43fJ1qkVXXeHxttY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXcPsFMGsvMwj7MlKZBxHU6vXJow3kdsub/fCNsm/XngXyoNRv5rLdrvjh9ZfY/pK aSdDSmrXVVfwbSJciinh/fcacREsw1xrLyCk84Sjzfvy96ruH0GNpGn5EZIxdZLOuM WzQpx9FcSHV9P098F1JFjkRH3PqEG1N19YsNghcw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Adam Guerin , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 162/201] crypto: qat - fix memory leak in RSA Date: Wed, 27 Jul 2022 18:11:06 +0200 Message-Id: <20220727161034.556503544@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit 80a52e1ee7757b742f96bfb0d58f0c14eb6583d0 ] When an RSA key represented in form 2 (as defined in PKCS #1 V2.1) is used, some components of the private key persist even after the TFM is released. Replace the explicit calls to free the buffers in qat_rsa_exit_tfm() with a call to qat_rsa_clear_ctx() which frees all buffers referenced in the TFM context. Cc: stable@vger.kernel.org Fixes: 879f77e9071f ("crypto: qat - Add RSA CRT mode") Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index ff7249c093c9..2bc02c75398e 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -1257,18 +1257,8 @@ static void qat_rsa_exit_tfm(struct crypto_akcipher = *tfm) struct qat_rsa_ctx *ctx =3D akcipher_tfm_ctx(tfm); struct device *dev =3D &GET_DEV(ctx->inst->accel_dev); =20 - if (ctx->n) - dma_free_coherent(dev, ctx->key_sz, ctx->n, ctx->dma_n); - if (ctx->e) - dma_free_coherent(dev, ctx->key_sz, ctx->e, ctx->dma_e); - if (ctx->d) { - memset(ctx->d, '\0', ctx->key_sz); - dma_free_coherent(dev, ctx->key_sz, ctx->d, ctx->dma_d); - } + qat_rsa_clear_ctx(dev, ctx); qat_crypto_put_instance(ctx->inst); - ctx->n =3D NULL; - ctx->e =3D NULL; - ctx->d =3D NULL; } =20 static struct akcipher_alg rsa =3D { --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A382CC19F28 for ; Wed, 27 Jul 2022 17:21:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241346AbiG0RVe (ORCPT ); Wed, 27 Jul 2022 13:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241948AbiG0RTW (ORCPT ); Wed, 27 Jul 2022 13:19:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CA845FCF; Wed, 27 Jul 2022 09:44:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CE48660DDB; Wed, 27 Jul 2022 16:44:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD377C433D6; Wed, 27 Jul 2022 16:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940266; bh=IWqERPbPXuzAJi43HWMg9GWZIDPCSP25alnEokDZ0nA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e2zhw20u7yt1LsqR5otxUMzsMD5eq/tiMiUmEyxAyBc+8Y+uc0x9NQBQph/7YbXcO cIFe1XSTY647FR+1VG3l3w2XtJrJEf3JYNpSQcCmY1sclCISwYyMQ5w4oaGL/SSHLZ LWD3skAvBnVzG0Nbtdnr2AfE9vLNbuhDyHcSygPk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Adam Guerin , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 163/201] crypto: qat - remove dma_free_coherent() for RSA Date: Wed, 27 Jul 2022 18:11:07 +0200 Message-Id: <20220727161034.597326974@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit 3dfaf0071ed74d7a9c6b3c9ea4df7a6f8e423c2a ] After commit f5ff79fddf0e ("dma-mapping: remove CONFIG_DMA_REMAP"), if the algorithms are enabled, the driver crashes with a BUG_ON while executing vunmap() in the context of a tasklet. This is due to the fact that the function dma_free_coherent() cannot be called in an interrupt context (see Documentation/core-api/dma-api-howto.rst). The functions qat_rsa_enc() and qat_rsa_dec() allocate memory with dma_alloc_coherent() if the source or the destination buffers are made of multiple flat buffers or of a size that is not compatible with the hardware. This memory is then freed with dma_free_coherent() in the context of a tasklet invoked to handle the response for the corresponding request. Replace allocations with dma_alloc_coherent() in the functions qat_rsa_enc() and qat_rsa_dec() with kmalloc() + dma_map_single(). Cc: stable@vger.kernel.org Fixes: a990532023b9 ("crypto: qat - Add support for RSA algorithm") Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 137 ++++++++---------- 1 file changed, 60 insertions(+), 77 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index 2bc02c75398e..b31372bddb96 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -529,25 +529,22 @@ static void qat_rsa_cb(struct icp_qat_fw_pke_resp *re= sp) =20 err =3D (err =3D=3D ICP_QAT_FW_COMN_STATUS_FLAG_OK) ? 0 : -EINVAL; =20 - if (req->src_align) - dma_free_coherent(dev, req->ctx.rsa->key_sz, req->src_align, - req->in.rsa.enc.m); - else - dma_unmap_single(dev, req->in.rsa.enc.m, req->ctx.rsa->key_sz, - DMA_TO_DEVICE); + kfree_sensitive(req->src_align); + + dma_unmap_single(dev, req->in.rsa.enc.m, req->ctx.rsa->key_sz, + DMA_TO_DEVICE); =20 areq->dst_len =3D req->ctx.rsa->key_sz; if (req->dst_align) { scatterwalk_map_and_copy(req->dst_align, areq->dst, 0, areq->dst_len, 1); =20 - dma_free_coherent(dev, req->ctx.rsa->key_sz, req->dst_align, - req->out.rsa.enc.c); - } else { - dma_unmap_single(dev, req->out.rsa.enc.c, req->ctx.rsa->key_sz, - DMA_FROM_DEVICE); + kfree_sensitive(req->dst_align); } =20 + dma_unmap_single(dev, req->out.rsa.enc.c, req->ctx.rsa->key_sz, + DMA_FROM_DEVICE); + dma_unmap_single(dev, req->phy_in, sizeof(struct qat_rsa_input_params), DMA_TO_DEVICE); dma_unmap_single(dev, req->phy_out, @@ -664,6 +661,7 @@ static int qat_rsa_enc(struct akcipher_request *req) struct qat_asym_request *qat_req =3D PTR_ALIGN(akcipher_request_ctx(req), 64); struct icp_qat_fw_pke_request *msg =3D &qat_req->req; + u8 *vaddr; int ret; =20 if (unlikely(!ctx->n || !ctx->e)) @@ -701,40 +699,39 @@ static int qat_rsa_enc(struct akcipher_request *req) */ if (sg_is_last(req->src) && req->src_len =3D=3D ctx->key_sz) { qat_req->src_align =3D NULL; - qat_req->in.rsa.enc.m =3D dma_map_single(dev, sg_virt(req->src), - req->src_len, DMA_TO_DEVICE); - if (unlikely(dma_mapping_error(dev, qat_req->in.rsa.enc.m))) - return ret; - + vaddr =3D sg_virt(req->src); } else { int shift =3D ctx->key_sz - req->src_len; =20 - qat_req->src_align =3D dma_alloc_coherent(dev, ctx->key_sz, - &qat_req->in.rsa.enc.m, - GFP_KERNEL); + qat_req->src_align =3D kzalloc(ctx->key_sz, GFP_KERNEL); if (unlikely(!qat_req->src_align)) return ret; =20 scatterwalk_map_and_copy(qat_req->src_align + shift, req->src, 0, req->src_len, 0); + vaddr =3D qat_req->src_align; } - if (sg_is_last(req->dst) && req->dst_len =3D=3D ctx->key_sz) { - qat_req->dst_align =3D NULL; - qat_req->out.rsa.enc.c =3D dma_map_single(dev, sg_virt(req->dst), - req->dst_len, - DMA_FROM_DEVICE); =20 - if (unlikely(dma_mapping_error(dev, qat_req->out.rsa.enc.c))) - goto unmap_src; + qat_req->in.rsa.enc.m =3D dma_map_single(dev, vaddr, ctx->key_sz, + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(dev, qat_req->in.rsa.enc.m))) + goto unmap_src; =20 + if (sg_is_last(req->dst) && req->dst_len =3D=3D ctx->key_sz) { + qat_req->dst_align =3D NULL; + vaddr =3D sg_virt(req->dst); } else { - qat_req->dst_align =3D dma_alloc_coherent(dev, ctx->key_sz, - &qat_req->out.rsa.enc.c, - GFP_KERNEL); + qat_req->dst_align =3D kzalloc(ctx->key_sz, GFP_KERNEL); if (unlikely(!qat_req->dst_align)) goto unmap_src; - + vaddr =3D qat_req->dst_align; } + + qat_req->out.rsa.enc.c =3D dma_map_single(dev, vaddr, ctx->key_sz, + DMA_FROM_DEVICE); + if (unlikely(dma_mapping_error(dev, qat_req->out.rsa.enc.c))) + goto unmap_dst; + qat_req->in.rsa.in_tab[3] =3D 0; qat_req->out.rsa.out_tab[1] =3D 0; qat_req->phy_in =3D dma_map_single(dev, &qat_req->in.rsa.enc.m, @@ -772,21 +769,15 @@ static int qat_rsa_enc(struct akcipher_request *req) sizeof(struct qat_rsa_input_params), DMA_TO_DEVICE); unmap_dst: - if (qat_req->dst_align) - dma_free_coherent(dev, ctx->key_sz, qat_req->dst_align, - qat_req->out.rsa.enc.c); - else - if (!dma_mapping_error(dev, qat_req->out.rsa.enc.c)) - dma_unmap_single(dev, qat_req->out.rsa.enc.c, - ctx->key_sz, DMA_FROM_DEVICE); + if (!dma_mapping_error(dev, qat_req->out.rsa.enc.c)) + dma_unmap_single(dev, qat_req->out.rsa.enc.c, + ctx->key_sz, DMA_FROM_DEVICE); + kfree_sensitive(qat_req->dst_align); unmap_src: - if (qat_req->src_align) - dma_free_coherent(dev, ctx->key_sz, qat_req->src_align, - qat_req->in.rsa.enc.m); - else - if (!dma_mapping_error(dev, qat_req->in.rsa.enc.m)) - dma_unmap_single(dev, qat_req->in.rsa.enc.m, - ctx->key_sz, DMA_TO_DEVICE); + if (!dma_mapping_error(dev, qat_req->in.rsa.enc.m)) + dma_unmap_single(dev, qat_req->in.rsa.enc.m, ctx->key_sz, + DMA_TO_DEVICE); + kfree_sensitive(qat_req->src_align); return ret; } =20 @@ -799,6 +790,7 @@ static int qat_rsa_dec(struct akcipher_request *req) struct qat_asym_request *qat_req =3D PTR_ALIGN(akcipher_request_ctx(req), 64); struct icp_qat_fw_pke_request *msg =3D &qat_req->req; + u8 *vaddr; int ret; =20 if (unlikely(!ctx->n || !ctx->d)) @@ -846,40 +838,37 @@ static int qat_rsa_dec(struct akcipher_request *req) */ if (sg_is_last(req->src) && req->src_len =3D=3D ctx->key_sz) { qat_req->src_align =3D NULL; - qat_req->in.rsa.dec.c =3D dma_map_single(dev, sg_virt(req->src), - req->dst_len, DMA_TO_DEVICE); - if (unlikely(dma_mapping_error(dev, qat_req->in.rsa.dec.c))) - return ret; - + vaddr =3D sg_virt(req->src); } else { int shift =3D ctx->key_sz - req->src_len; =20 - qat_req->src_align =3D dma_alloc_coherent(dev, ctx->key_sz, - &qat_req->in.rsa.dec.c, - GFP_KERNEL); + qat_req->src_align =3D kzalloc(ctx->key_sz, GFP_KERNEL); if (unlikely(!qat_req->src_align)) return ret; =20 scatterwalk_map_and_copy(qat_req->src_align + shift, req->src, 0, req->src_len, 0); + vaddr =3D qat_req->src_align; } - if (sg_is_last(req->dst) && req->dst_len =3D=3D ctx->key_sz) { - qat_req->dst_align =3D NULL; - qat_req->out.rsa.dec.m =3D dma_map_single(dev, sg_virt(req->dst), - req->dst_len, - DMA_FROM_DEVICE); =20 - if (unlikely(dma_mapping_error(dev, qat_req->out.rsa.dec.m))) - goto unmap_src; + qat_req->in.rsa.dec.c =3D dma_map_single(dev, vaddr, ctx->key_sz, + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(dev, qat_req->in.rsa.dec.c))) + goto unmap_src; =20 + if (sg_is_last(req->dst) && req->dst_len =3D=3D ctx->key_sz) { + qat_req->dst_align =3D NULL; + vaddr =3D sg_virt(req->dst); } else { - qat_req->dst_align =3D dma_alloc_coherent(dev, ctx->key_sz, - &qat_req->out.rsa.dec.m, - GFP_KERNEL); + qat_req->dst_align =3D kzalloc(ctx->key_sz, GFP_KERNEL); if (unlikely(!qat_req->dst_align)) goto unmap_src; - + vaddr =3D qat_req->dst_align; } + qat_req->out.rsa.dec.m =3D dma_map_single(dev, vaddr, ctx->key_sz, + DMA_FROM_DEVICE); + if (unlikely(dma_mapping_error(dev, qat_req->out.rsa.dec.m))) + goto unmap_dst; =20 if (ctx->crt_mode) qat_req->in.rsa.in_tab[6] =3D 0; @@ -925,21 +914,15 @@ static int qat_rsa_dec(struct akcipher_request *req) sizeof(struct qat_rsa_input_params), DMA_TO_DEVICE); unmap_dst: - if (qat_req->dst_align) - dma_free_coherent(dev, ctx->key_sz, qat_req->dst_align, - qat_req->out.rsa.dec.m); - else - if (!dma_mapping_error(dev, qat_req->out.rsa.dec.m)) - dma_unmap_single(dev, qat_req->out.rsa.dec.m, - ctx->key_sz, DMA_FROM_DEVICE); + if (!dma_mapping_error(dev, qat_req->out.rsa.dec.m)) + dma_unmap_single(dev, qat_req->out.rsa.dec.m, + ctx->key_sz, DMA_FROM_DEVICE); + kfree_sensitive(qat_req->dst_align); unmap_src: - if (qat_req->src_align) - dma_free_coherent(dev, ctx->key_sz, qat_req->src_align, - qat_req->in.rsa.dec.c); - else - if (!dma_mapping_error(dev, qat_req->in.rsa.dec.c)) - dma_unmap_single(dev, qat_req->in.rsa.dec.c, - ctx->key_sz, DMA_TO_DEVICE); + if (!dma_mapping_error(dev, qat_req->in.rsa.dec.c)) + dma_unmap_single(dev, qat_req->in.rsa.dec.c, ctx->key_sz, + DMA_TO_DEVICE); + kfree_sensitive(qat_req->src_align); return ret; } =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53B42C04A68 for ; Wed, 27 Jul 2022 17:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbiG0RVa (ORCPT ); Wed, 27 Jul 2022 13:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241953AbiG0RTX (ORCPT ); Wed, 27 Jul 2022 13:19:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB5AE2DB; Wed, 27 Jul 2022 09:44:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 89348614DE; Wed, 27 Jul 2022 16:44:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97EE9C433C1; Wed, 27 Jul 2022 16:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940269; bh=7upjMH8v1lO5gmKMhprbMT2ertIoz1OLzCcHbMIlJ5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a9wrgTcGpwHM3xK0wXXvLh07g1SZMGfLtKODCqvvPQzB4QCNiw8Fn28FXB91DpHEZ B7GoRlBvFYSRPFXWewA/6RYgzS8GfupSgnq4rCLiq5QLmPasflwDiVfzOQeJqvkZaN LK3SweJX3WzODq3eg2ZtwogwGYaxkbkonR/YlKto= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Adam Guerin , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 164/201] crypto: qat - remove dma_free_coherent() for DH Date: Wed, 27 Jul 2022 18:11:08 +0200 Message-Id: <20220727161034.637741056@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit 029aa4624a7fe35233bdd3d1354dc7be260380bf ] The functions qat_dh_compute_value() allocates memory with dma_alloc_coherent() if the source or the destination buffers are made of multiple flat buffers or of a size that is not compatible with the hardware. This memory is then freed with dma_free_coherent() in the context of a tasklet invoked to handle the response for the corresponding request. According to Documentation/core-api/dma-api-howto.rst, the function dma_free_coherent() cannot be called in an interrupt context. Replace allocations with dma_alloc_coherent() in the function qat_dh_compute_value() with kmalloc() + dma_map_single(). Cc: stable@vger.kernel.org Fixes: c9839143ebbf ("crypto: qat - Add DH support") Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 83 ++++++++----------- 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index b31372bddb96..25bbd22085c3 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -164,26 +164,21 @@ static void qat_dh_cb(struct icp_qat_fw_pke_resp *res= p) err =3D (err =3D=3D ICP_QAT_FW_COMN_STATUS_FLAG_OK) ? 0 : -EINVAL; =20 if (areq->src) { - if (req->src_align) - dma_free_coherent(dev, req->ctx.dh->p_size, - req->src_align, req->in.dh.in.b); - else - dma_unmap_single(dev, req->in.dh.in.b, - req->ctx.dh->p_size, DMA_TO_DEVICE); + dma_unmap_single(dev, req->in.dh.in.b, req->ctx.dh->p_size, + DMA_TO_DEVICE); + kfree_sensitive(req->src_align); } =20 areq->dst_len =3D req->ctx.dh->p_size; if (req->dst_align) { scatterwalk_map_and_copy(req->dst_align, areq->dst, 0, areq->dst_len, 1); - - dma_free_coherent(dev, req->ctx.dh->p_size, req->dst_align, - req->out.dh.r); - } else { - dma_unmap_single(dev, req->out.dh.r, req->ctx.dh->p_size, - DMA_FROM_DEVICE); + kfree_sensitive(req->dst_align); } =20 + dma_unmap_single(dev, req->out.dh.r, req->ctx.dh->p_size, + DMA_FROM_DEVICE); + dma_unmap_single(dev, req->phy_in, sizeof(struct qat_dh_input_params), DMA_TO_DEVICE); dma_unmap_single(dev, req->phy_out, @@ -231,6 +226,7 @@ static int qat_dh_compute_value(struct kpp_request *req) struct icp_qat_fw_pke_request *msg =3D &qat_req->req; int ret; int n_input_params =3D 0; + u8 *vaddr; =20 if (unlikely(!ctx->xa)) return -EINVAL; @@ -287,27 +283,24 @@ static int qat_dh_compute_value(struct kpp_request *r= eq) */ if (sg_is_last(req->src) && req->src_len =3D=3D ctx->p_size) { qat_req->src_align =3D NULL; - qat_req->in.dh.in.b =3D dma_map_single(dev, - sg_virt(req->src), - req->src_len, - DMA_TO_DEVICE); - if (unlikely(dma_mapping_error(dev, - qat_req->in.dh.in.b))) - return ret; - + vaddr =3D sg_virt(req->src); } else { int shift =3D ctx->p_size - req->src_len; =20 - qat_req->src_align =3D dma_alloc_coherent(dev, - ctx->p_size, - &qat_req->in.dh.in.b, - GFP_KERNEL); + qat_req->src_align =3D kzalloc(ctx->p_size, GFP_KERNEL); if (unlikely(!qat_req->src_align)) return ret; =20 scatterwalk_map_and_copy(qat_req->src_align + shift, req->src, 0, req->src_len, 0); + + vaddr =3D qat_req->src_align; } + + qat_req->in.dh.in.b =3D dma_map_single(dev, vaddr, ctx->p_size, + DMA_TO_DEVICE); + if (unlikely(dma_mapping_error(dev, qat_req->in.dh.in.b))) + goto unmap_src; } /* * dst can be of any size in valid range, but HW expects it to be the @@ -318,20 +311,18 @@ static int qat_dh_compute_value(struct kpp_request *r= eq) */ if (sg_is_last(req->dst) && req->dst_len =3D=3D ctx->p_size) { qat_req->dst_align =3D NULL; - qat_req->out.dh.r =3D dma_map_single(dev, sg_virt(req->dst), - req->dst_len, - DMA_FROM_DEVICE); - - if (unlikely(dma_mapping_error(dev, qat_req->out.dh.r))) - goto unmap_src; - + vaddr =3D sg_virt(req->dst); } else { - qat_req->dst_align =3D dma_alloc_coherent(dev, ctx->p_size, - &qat_req->out.dh.r, - GFP_KERNEL); + qat_req->dst_align =3D kzalloc(ctx->p_size, GFP_KERNEL); if (unlikely(!qat_req->dst_align)) goto unmap_src; + + vaddr =3D qat_req->dst_align; } + qat_req->out.dh.r =3D dma_map_single(dev, vaddr, ctx->p_size, + DMA_FROM_DEVICE); + if (unlikely(dma_mapping_error(dev, qat_req->out.dh.r))) + goto unmap_dst; =20 qat_req->in.dh.in_tab[n_input_params] =3D 0; qat_req->out.dh.out_tab[1] =3D 0; @@ -371,23 +362,17 @@ static int qat_dh_compute_value(struct kpp_request *r= eq) sizeof(struct qat_dh_input_params), DMA_TO_DEVICE); unmap_dst: - if (qat_req->dst_align) - dma_free_coherent(dev, ctx->p_size, qat_req->dst_align, - qat_req->out.dh.r); - else - if (!dma_mapping_error(dev, qat_req->out.dh.r)) - dma_unmap_single(dev, qat_req->out.dh.r, ctx->p_size, - DMA_FROM_DEVICE); + if (!dma_mapping_error(dev, qat_req->out.dh.r)) + dma_unmap_single(dev, qat_req->out.dh.r, ctx->p_size, + DMA_FROM_DEVICE); + kfree_sensitive(qat_req->dst_align); unmap_src: if (req->src) { - if (qat_req->src_align) - dma_free_coherent(dev, ctx->p_size, qat_req->src_align, - qat_req->in.dh.in.b); - else - if (!dma_mapping_error(dev, qat_req->in.dh.in.b)) - dma_unmap_single(dev, qat_req->in.dh.in.b, - ctx->p_size, - DMA_TO_DEVICE); + if (!dma_mapping_error(dev, qat_req->in.dh.in.b)) + dma_unmap_single(dev, qat_req->in.dh.in.b, + ctx->p_size, + DMA_TO_DEVICE); + kfree_sensitive(qat_req->src_align); } return ret; } --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B790C04A68 for ; Wed, 27 Jul 2022 17:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235930AbiG0RVk (ORCPT ); Wed, 27 Jul 2022 13:21:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241963AbiG0RTY (ORCPT ); Wed, 27 Jul 2022 13:19:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BC28BF6B; Wed, 27 Jul 2022 09:44:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DCDF6B8200C; Wed, 27 Jul 2022 16:44:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 474CCC433D7; Wed, 27 Jul 2022 16:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940271; bh=/0a/0Z9dUlo8grhA3fXLHeVFNp9BdkiWV92ue3bNBfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1HJHjIsbk8dQkrOhC2KHGGm6VEbetw5o8IWzMgOiYoDJ/4g4dJDOW20n4DW7RyvUf ivxPB4SDlVT3plb7Gca1/d0Dvhu+eDqJ2zZZjLcqZDaXXDWQMIOZsjFQMR5TVmRUBz uW4WLkvlCkMmRDhTLSOe/Lw54c8FinYf4oeQc8do= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Adam Guerin , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 165/201] crypto: qat - add param check for RSA Date: Wed, 27 Jul 2022 18:11:09 +0200 Message-Id: <20220727161034.673218890@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit 9714061423b8b24b8afb31b8eb4df977c63f19c4 ] Reject requests with a source buffer that is bigger than the size of the key. This is to prevent a possible integer underflow that might happen when copying the source scatterlist into a linear buffer. Cc: stable@vger.kernel.org Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index 25bbd22085c3..947eeff181b4 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -656,6 +656,10 @@ static int qat_rsa_enc(struct akcipher_request *req) req->dst_len =3D ctx->key_sz; return -EOVERFLOW; } + + if (req->src_len > ctx->key_sz) + return -EINVAL; + memset(msg, '\0', sizeof(*msg)); ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(msg->pke_hdr, ICP_QAT_FW_COMN_REQ_FLAG_SET); @@ -785,6 +789,10 @@ static int qat_rsa_dec(struct akcipher_request *req) req->dst_len =3D ctx->key_sz; return -EOVERFLOW; } + + if (req->src_len > ctx->key_sz) + return -EINVAL; + memset(msg, '\0', sizeof(*msg)); ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(msg->pke_hdr, ICP_QAT_FW_COMN_REQ_FLAG_SET); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44446C19F28 for ; Wed, 27 Jul 2022 17:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241768AbiG0RVy (ORCPT ); Wed, 27 Jul 2022 13:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241969AbiG0RTZ (ORCPT ); Wed, 27 Jul 2022 13:19:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBAEE17E13; Wed, 27 Jul 2022 09:44:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 988B9B821A6; Wed, 27 Jul 2022 16:44:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F11D3C433C1; Wed, 27 Jul 2022 16:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940274; bh=OGCj6S1xjd9XwIbJO81L93cBRcKmCDMbwE+p77sNUko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bsZeo27anj1n1HkU1kXIcD7cGAfzERxiglpGvldORqTskkcl9BLgHQc7fMs7e77qp 3OKu6A3CrOi5UXIfKp7H9/iLkIknJJpOqD7wkycTueB8Uf00/5uqGGw2L4Xg9ed7kN ojJdtktSw68f8EY0idPynv03MX/vyrZ7Qa2IV1B0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Adam Guerin , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 166/201] crypto: qat - add param check for DH Date: Wed, 27 Jul 2022 18:11:10 +0200 Message-Id: <20220727161034.710630601@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit 2acbb8771f6ac82422886e63832ee7a0f4b1635b ] Reject requests with a source buffer that is bigger than the size of the key. This is to prevent a possible integer underflow that might happen when copying the source scatterlist into a linear buffer. Cc: stable@vger.kernel.org Signed-off-by: Giovanni Cabiddu Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto= /qat/qat_common/qat_asym_algs.c index 947eeff181b4..7173a2a0a484 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -235,6 +235,10 @@ static int qat_dh_compute_value(struct kpp_request *re= q) req->dst_len =3D ctx->p_size; return -EOVERFLOW; } + + if (req->src_len > ctx->p_size) + return -EINVAL; + memset(msg, '\0', sizeof(*msg)); ICP_QAT_FW_PKE_HDR_VALID_FLAG_SET(msg->pke_hdr, ICP_QAT_FW_COMN_REQ_FLAG_SET); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C41C04A68 for ; Wed, 27 Jul 2022 17:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237889AbiG0RVn (ORCPT ); Wed, 27 Jul 2022 13:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241974AbiG0RTZ (ORCPT ); Wed, 27 Jul 2022 13:19:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDC411A80F; Wed, 27 Jul 2022 09:44:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8D01F601C3; Wed, 27 Jul 2022 16:44:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93407C433C1; Wed, 27 Jul 2022 16:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940280; bh=L0zad5tuT0Tpll3f1lgIxg3OEeQjJgTPBhyabtixlR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ErE0F4jedhdpXdbrkLBFmMdC5wgHje8PzjH8t4AJPqV/UEJrLOhsjqU06S1aqRJfD T36a3nIcXlQENnY/hPFibKZyqpHLjTd2GWPy+0d9vlzr2lcAfeCd+cci+5PDPtTmx7 nnSLSgIbbhqnJMfOjniqUDegaGX3BCZ+8NPXH59E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Giovanni Cabiddu , Marco Chiappero , Adam Guerin , Wojciech Ziemba , Herbert Xu , Sasha Levin Subject: [PATCH 5.15 167/201] crypto: qat - re-enable registration of algorithms Date: Wed, 27 Jul 2022 18:11:11 +0200 Message-Id: <20220727161034.749849280@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Giovanni Cabiddu [ Upstream commit d09144745959bf7852ccafd73243dd7d1eaeb163 ] Re-enable the registration of algorithms after fixes to (1) use pre-allocated buffers in the datapath and (2) support the CRYPTO_TFM_REQ_MAY_BACKLOG flag. This reverts commit 8893d27ffcaf6ec6267038a177cb87bcde4dd3de. Cc: stable@vger.kernel.org Signed-off-by: Giovanni Cabiddu Reviewed-by: Marco Chiappero Reviewed-by: Adam Guerin Reviewed-by: Wojciech Ziemba Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/crypto/qat/qat_4xxx/adf_drv.c | 7 ------- drivers/crypto/qat/qat_common/qat_crypto.c | 7 ------- 2 files changed, 14 deletions(-) diff --git a/drivers/crypto/qat/qat_4xxx/adf_drv.c b/drivers/crypto/qat/qat= _4xxx/adf_drv.c index 8fd44703115f..359fb7989dfb 100644 --- a/drivers/crypto/qat/qat_4xxx/adf_drv.c +++ b/drivers/crypto/qat/qat_4xxx/adf_drv.c @@ -52,13 +52,6 @@ static int adf_crypto_dev_config(struct adf_accel_dev *a= ccel_dev) if (ret) goto err; =20 - /* Temporarily set the number of crypto instances to zero to avoid - * registering the crypto algorithms. - * This will be removed when the algorithms will support the - * CRYPTO_TFM_REQ_MAY_BACKLOG flag - */ - instances =3D 0; - for (i =3D 0; i < instances; i++) { val =3D i; bank =3D i * 2; diff --git a/drivers/crypto/qat/qat_common/qat_crypto.c b/drivers/crypto/qa= t/qat_common/qat_crypto.c index 59e122afa434..994e43fab0a4 100644 --- a/drivers/crypto/qat/qat_common/qat_crypto.c +++ b/drivers/crypto/qat/qat_common/qat_crypto.c @@ -136,13 +136,6 @@ int qat_crypto_dev_config(struct adf_accel_dev *accel_= dev) if (ret) goto err; =20 - /* Temporarily set the number of crypto instances to zero to avoid - * registering the crypto algorithms. - * This will be removed when the algorithms will support the - * CRYPTO_TFM_REQ_MAY_BACKLOG flag - */ - instances =3D 0; - for (i =3D 0; i < instances; i++) { val =3D i; snprintf(key, sizeof(key), ADF_CY "%d" ADF_RING_ASYM_BANK_NUM, i); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1D8BC19F2B for ; Wed, 27 Jul 2022 17:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241939AbiG0RV6 (ORCPT ); Wed, 27 Jul 2022 13:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241980AbiG0RT0 (ORCPT ); Wed, 27 Jul 2022 13:19:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 784B120191; Wed, 27 Jul 2022 09:44:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EDE69B8200C; Wed, 27 Jul 2022 16:44:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A011C433D6; Wed, 27 Jul 2022 16:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940282; bh=oiSt1wyU14n0g8HwuwyUHAl3vR2Y3DGXQRQ94FaTDOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AfRX+p0Iu3sVrtt2twRMgypv98bfK4VKWyF+NJmS+eFfpvJmkbZ85Mmj+qATdtJe3 H1F2bso4cYV4q2nA52RzKw/p9Fcah0j0dFqpitAMvRh5zZrRB6Y/LEaPzjb8dk+jjf 4QGSCkbD2yQ5403ySj9dRSvQkqypjVj+m/Z/UcSc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yuezhang Mo , Andy Wu , Aoyama Wataru , Daniel Palmer , Sungjong Seo , Namjae Jeon , Sasha Levin Subject: [PATCH 5.15 168/201] exfat: fix referencing wrong parent directory information after renaming Date: Wed, 27 Jul 2022 18:11:12 +0200 Message-Id: <20220727161034.786986554@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Yuezhang Mo [ Upstream commit d8dad2588addd1d861ce19e7df3b702330f0c7e3 ] During renaming, the parent directory information maybe updated. But the file/directory still references to the old parent directory information. This bug will cause 2 problems. (1) The renamed file can not be written. [10768.175172] exFAT-fs (sda1): error, failed to bmap (inode : 7afd50e4= iblock : 0, err : -5) [10768.184285] exFAT-fs (sda1): Filesystem has been set read-only ash: write error: Input/output error (2) Some dentries of the renamed file/directory are not set to deleted after removing the file/directory. exfat_update_parent_info() is a workaround for the wrong parent directory information being used after renaming. Now that bug is fixed, this is no longer needed, so remove it. Fixes: 5f2aa075070c ("exfat: add inode operations") Cc: stable@vger.kernel.org # v5.7+ Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru Reviewed-by: Daniel Palmer Reviewed-by: Sungjong Seo Signed-off-by: Namjae Jeon Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/exfat/namei.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 9d8ada781250..939737ba520d 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -1069,6 +1069,7 @@ static int exfat_rename_file(struct inode *inode, str= uct exfat_chain *p_dir, =20 exfat_remove_entries(inode, p_dir, oldentry, 0, num_old_entries); + ei->dir =3D *p_dir; ei->entry =3D newentry; } else { if (exfat_get_entry_type(epold) =3D=3D TYPE_FILE) { @@ -1159,28 +1160,6 @@ static int exfat_move_file(struct inode *inode, stru= ct exfat_chain *p_olddir, return 0; } =20 -static void exfat_update_parent_info(struct exfat_inode_info *ei, - struct inode *parent_inode) -{ - struct exfat_sb_info *sbi =3D EXFAT_SB(parent_inode->i_sb); - struct exfat_inode_info *parent_ei =3D EXFAT_I(parent_inode); - loff_t parent_isize =3D i_size_read(parent_inode); - - /* - * the problem that struct exfat_inode_info caches wrong parent info. - * - * because of flag-mismatch of ei->dir, - * there is abnormal traversing cluster chain. - */ - if (unlikely(parent_ei->flags !=3D ei->dir.flags || - parent_isize !=3D EXFAT_CLU_TO_B(ei->dir.size, sbi) || - parent_ei->start_clu !=3D ei->dir.dir)) { - exfat_chain_set(&ei->dir, parent_ei->start_clu, - EXFAT_B_TO_CLU_ROUND_UP(parent_isize, sbi), - parent_ei->flags); - } -} - /* rename or move a old file into a new file */ static int __exfat_rename(struct inode *old_parent_inode, struct exfat_inode_info *ei, struct inode *new_parent_inode, @@ -1211,8 +1190,6 @@ static int __exfat_rename(struct inode *old_parent_in= ode, return -ENOENT; } =20 - exfat_update_parent_info(ei, old_parent_inode); - exfat_chain_dup(&olddir, &ei->dir); dentry =3D ei->entry; =20 @@ -1233,8 +1210,6 @@ static int __exfat_rename(struct inode *old_parent_in= ode, goto out; } =20 - exfat_update_parent_info(new_ei, new_parent_inode); - p_dir =3D &(new_ei->dir); new_entry =3D new_ei->entry; ep =3D exfat_get_dentry(sb, p_dir, new_entry, &new_bh, NULL); --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 221A7C04A68 for ; Wed, 27 Jul 2022 17:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241944AbiG0RWD (ORCPT ); Wed, 27 Jul 2022 13:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241987AbiG0RT3 (ORCPT ); Wed, 27 Jul 2022 13:19:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C28A323153; Wed, 27 Jul 2022 09:44:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 47B6D601C3; Wed, 27 Jul 2022 16:44:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F904C433D6; Wed, 27 Jul 2022 16:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940285; bh=YVIFpYhYR7TrLZMwL/dPwTtMcZHNQKpHAC6jaoFSOE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lCXygaYp2/Uk88bluhUnpU30YOFnE8u855bFxaRqRIIXkkqMgLQQdODxM6+dNsRN8 EuZTQV62mw/uZzses/8mgfutBj29nFAcFPn+IAfPDzeqBIMtXHtkayYfBBRYTImlxZ J/w78o+LqfogPx4UQ3txtMUD+1lBZtz7XXXKpIUs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Rothwell , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.15 169/201] tracing: Have event format check not flag %p* on __get_dynamic_array() Date: Wed, 27 Jul 2022 18:11:13 +0200 Message-Id: <20220727161034.837596500@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Steven Rostedt (Google) [ Upstream commit 499f12168aebd6da8fa32c9b7d6203ca9b5eb88d ] The print fmt check against trace events to make sure that the format does not use pointers that may be freed from the time of the trace to the time the event is read, gives a false positive on %pISpc when reading data that was saved in __get_dynamic_array() when it is perfectly fine to do so, as the data being read is on the ring buffer. Link: https://lore.kernel.org/all/20220407144524.2a592ed6@canb.auug.org.au/ Cc: stable@vger.kernel.org Fixes: 5013f454a352c ("tracing: Add check of trace event print fmts for der= eferencing pointers") Reported-by: Stephen Rothwell Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/trace/trace_events.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index c072e8b9849c..ea3fbfa87fdd 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -407,7 +407,14 @@ static void test_event_printk(struct trace_event_call = *call) a =3D strchr(fmt + i, '&'); if ((a && (a < r)) || test_field(r, call)) dereference_flags &=3D ~(1ULL << arg); + } else if ((r =3D strstr(fmt + i, "__get_dynamic_array(")) && + (!c || r < c)) { + dereference_flags &=3D ~(1ULL << arg); + } else if ((r =3D strstr(fmt + i, "__get_sockaddr(")) && + (!c || r < c)) { + dereference_flags &=3D ~(1ULL << arg); } + next_arg: i--; arg++; --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03FCCC04A68 for ; Wed, 27 Jul 2022 17:22:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231834AbiG0RWk (ORCPT ); Wed, 27 Jul 2022 13:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242001AbiG0RTb (ORCPT ); Wed, 27 Jul 2022 13:19:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0D522AE17; Wed, 27 Jul 2022 09:44:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 14C6E61479; Wed, 27 Jul 2022 16:44:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20142C433C1; Wed, 27 Jul 2022 16:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940288; bh=roAxcCl7YYnNnFsxMV/IrRFJsK0GSPZxSVawqBUG7PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dM099xVRo5kq9W9EJSHHFm0kyqrgfF8hU/SbwWqhHG4GajZ8PYOcjSSJsAbVnx1K3 Zc9YDk/YLi4JO6AHnLSaX4TcZu0HGag4qeNfFaJfUDnpsl2xd+JS3MtpQgorSkTuWo DRzaQo66vO0tYFJ57oVJhies8EL9LK40Nv1z5Zhc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" , Sasha Levin Subject: [PATCH 5.15 170/201] tracing: Place trace_pid_list logic into abstract functions Date: Wed, 27 Jul 2022 18:11:14 +0200 Message-Id: <20220727161034.871219706@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Steven Rostedt (VMware) [ Upstream commit 6954e415264eeb5ee6be0d22d789ad12c995ee64 ] Instead of having the logic that does trace_pid_list open coded, wrap it in abstract functions. This will allow a rewrite of the logic that implements the trace_pid_list without affecting the users. Note, this causes a change in behavior. Every time a pid is written into the set_*_pid file, it creates a new list and uses RCU to update it. If pid_max is lowered, but there was a pid currently in the list that was higher than pid_max, those pids will now be removed on updating the list. The old behavior kept that from happening. The rewrite of the pid_list logic will no longer depend on pid_max, and will return the old behavior. Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/trace/Makefile | 1 + kernel/trace/ftrace.c | 6 +- kernel/trace/pid_list.c | 160 ++++++++++++++++++++++++++++++++++++ kernel/trace/pid_list.h | 13 +++ kernel/trace/trace.c | 78 ++++++------------ kernel/trace/trace.h | 14 +++- kernel/trace/trace_events.c | 6 +- 7 files changed, 217 insertions(+), 61 deletions(-) create mode 100644 kernel/trace/pid_list.c create mode 100644 kernel/trace/pid_list.h diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 6de5d4d63165..bedc5caceec7 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_TRACING) +=3D trace_output.o obj-$(CONFIG_TRACING) +=3D trace_seq.o obj-$(CONFIG_TRACING) +=3D trace_stat.o obj-$(CONFIG_TRACING) +=3D trace_printk.o +obj-$(CONFIG_TRACING) +=3D pid_list.o obj-$(CONFIG_TRACING_MAP) +=3D tracing_map.o obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) +=3D preemptirq_delay_test.o obj-$(CONFIG_SYNTH_EVENT_GEN_TEST) +=3D synth_event_gen_test.o diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 53a1af21d25c..e215a9c96971 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -7184,10 +7184,10 @@ static void clear_ftrace_pids(struct trace_array *t= r, int type) synchronize_rcu(); =20 if ((type & TRACE_PIDS) && pid_list) - trace_free_pid_list(pid_list); + trace_pid_list_free(pid_list); =20 if ((type & TRACE_NO_PIDS) && no_pid_list) - trace_free_pid_list(no_pid_list); + trace_pid_list_free(no_pid_list); } =20 void ftrace_clear_pids(struct trace_array *tr) @@ -7428,7 +7428,7 @@ pid_write(struct file *filp, const char __user *ubuf, =20 if (filtered_pids) { synchronize_rcu(); - trace_free_pid_list(filtered_pids); + trace_pid_list_free(filtered_pids); } else if (pid_list && !other_pids) { /* Register a probe to set whether to ignore the tracing of a task */ register_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr); diff --git a/kernel/trace/pid_list.c b/kernel/trace/pid_list.c new file mode 100644 index 000000000000..4483ef70b562 --- /dev/null +++ b/kernel/trace/pid_list.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 VMware Inc, Steven Rostedt + */ +#include +#include +#include "trace.h" + +/** + * trace_pid_list_is_set - test if the pid is set in the list + * @pid_list: The pid list to test + * @pid: The pid to to see if set in the list. + * + * Tests if @pid is is set in the @pid_list. This is usually called + * from the scheduler when a task is scheduled. Its pid is checked + * if it should be traced or not. + * + * Return true if the pid is in the list, false otherwise. + */ +bool trace_pid_list_is_set(struct trace_pid_list *pid_list, unsigned int p= id) +{ + /* + * If pid_max changed after filtered_pids was created, we + * by default ignore all pids greater than the previous pid_max. + */ + if (pid >=3D pid_list->pid_max) + return false; + + return test_bit(pid, pid_list->pids); +} + +/** + * trace_pid_list_set - add a pid to the list + * @pid_list: The pid list to add the @pid to. + * @pid: The pid to add. + * + * Adds @pid to @pid_list. This is usually done explicitly by a user + * adding a task to be traced, or indirectly by the fork function + * when children should be traced and a task's pid is in the list. + * + * Return 0 on success, negative otherwise. + */ +int trace_pid_list_set(struct trace_pid_list *pid_list, unsigned int pid) +{ + /* Sorry, but we don't support pid_max changing after setting */ + if (pid >=3D pid_list->pid_max) + return -EINVAL; + + set_bit(pid, pid_list->pids); + + return 0; +} + +/** + * trace_pid_list_clear - remove a pid from the list + * @pid_list: The pid list to remove the @pid from. + * @pid: The pid to remove. + * + * Removes @pid from @pid_list. This is usually done explicitly by a user + * removing tasks from tracing, or indirectly by the exit function + * when a task that is set to be traced exits. + * + * Return 0 on success, negative otherwise. + */ +int trace_pid_list_clear(struct trace_pid_list *pid_list, unsigned int pid) +{ + /* Sorry, but we don't support pid_max changing after setting */ + if (pid >=3D pid_list->pid_max) + return -EINVAL; + + clear_bit(pid, pid_list->pids); + + return 0; +} + +/** + * trace_pid_list_next - return the next pid in the list + * @pid_list: The pid list to examine. + * @pid: The pid to start from + * @next: The pointer to place the pid that is set starting from @pid. + * + * Looks for the next consecutive pid that is in @pid_list starting + * at the pid specified by @pid. If one is set (including @pid), then + * that pid is placed into @next. + * + * Return 0 when a pid is found, -1 if there are no more pids included. + */ +int trace_pid_list_next(struct trace_pid_list *pid_list, unsigned int pid, + unsigned int *next) +{ + pid =3D find_next_bit(pid_list->pids, pid_list->pid_max, pid); + + if (pid < pid_list->pid_max) { + *next =3D pid; + return 0; + } + return -1; +} + +/** + * trace_pid_list_first - return the first pid in the list + * @pid_list: The pid list to examine. + * @pid: The pointer to place the pid first found pid that is set. + * + * Looks for the first pid that is set in @pid_list, and places it + * into @pid if found. + * + * Return 0 when a pid is found, -1 if there are no pids set. + */ +int trace_pid_list_first(struct trace_pid_list *pid_list, unsigned int *pi= d) +{ + unsigned int first; + + first =3D find_first_bit(pid_list->pids, pid_list->pid_max); + + if (first < pid_list->pid_max) { + *pid =3D first; + return 0; + } + return -1; +} + +/** + * trace_pid_list_alloc - create a new pid_list + * + * Allocates a new pid_list to store pids into. + * + * Returns the pid_list on success, NULL otherwise. + */ +struct trace_pid_list *trace_pid_list_alloc(void) +{ + struct trace_pid_list *pid_list; + + pid_list =3D kmalloc(sizeof(*pid_list), GFP_KERNEL); + if (!pid_list) + return NULL; + + pid_list->pid_max =3D READ_ONCE(pid_max); + + pid_list->pids =3D vzalloc((pid_list->pid_max + 7) >> 3); + if (!pid_list->pids) { + kfree(pid_list); + return NULL; + } + return pid_list; +} + +/** + * trace_pid_list_free - Frees an allocated pid_list. + * + * Frees the memory for a pid_list that was allocated. + */ +void trace_pid_list_free(struct trace_pid_list *pid_list) +{ + if (!pid_list) + return; + + vfree(pid_list->pids); + kfree(pid_list); +} diff --git a/kernel/trace/pid_list.h b/kernel/trace/pid_list.h new file mode 100644 index 000000000000..80d0ecfe1536 --- /dev/null +++ b/kernel/trace/pid_list.h @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Do not include this file directly. */ + +#ifndef _TRACE_INTERNAL_PID_LIST_H +#define _TRACE_INTERNAL_PID_LIST_H + +struct trace_pid_list { + int pid_max; + unsigned long *pids; +}; + +#endif /* _TRACE_INTERNAL_PID_LIST_H */ diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index f752f2574630..abbe8489faae 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -516,12 +516,6 @@ int call_filter_check_discard(struct trace_event_call = *call, void *rec, return 0; } =20 -void trace_free_pid_list(struct trace_pid_list *pid_list) -{ - vfree(pid_list->pids); - kfree(pid_list); -} - /** * trace_find_filtered_pid - check if a pid exists in a filtered_pid list * @filtered_pids: The list of pids to check @@ -532,14 +526,7 @@ void trace_free_pid_list(struct trace_pid_list *pid_li= st) bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids, pid_t search= _pid) { - /* - * If pid_max changed after filtered_pids was created, we - * by default ignore all pids greater than the previous pid_max. - */ - if (search_pid >=3D filtered_pids->pid_max) - return false; - - return test_bit(search_pid, filtered_pids->pids); + return trace_pid_list_is_set(filtered_pids, search_pid); } =20 /** @@ -596,15 +583,11 @@ void trace_filter_add_remove_task(struct trace_pid_li= st *pid_list, return; } =20 - /* Sorry, but we don't support pid_max changing after setting */ - if (task->pid >=3D pid_list->pid_max) - return; - /* "self" is set for forks, and NULL for exits */ if (self) - set_bit(task->pid, pid_list->pids); + trace_pid_list_set(pid_list, task->pid); else - clear_bit(task->pid, pid_list->pids); + trace_pid_list_clear(pid_list, task->pid); } =20 /** @@ -621,18 +604,19 @@ void trace_filter_add_remove_task(struct trace_pid_li= st *pid_list, */ void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos) { - unsigned long pid =3D (unsigned long)v; + long pid =3D (unsigned long)v; + unsigned int next; =20 (*pos)++; =20 /* pid already is +1 of the actual previous bit */ - pid =3D find_next_bit(pid_list->pids, pid_list->pid_max, pid); + if (trace_pid_list_next(pid_list, pid, &next) < 0) + return NULL; =20 - /* Return pid + 1 to allow zero to be represented */ - if (pid < pid_list->pid_max) - return (void *)(pid + 1); + pid =3D next; =20 - return NULL; + /* Return pid + 1 to allow zero to be represented */ + return (void *)(pid + 1); } =20 /** @@ -649,12 +633,14 @@ void *trace_pid_next(struct trace_pid_list *pid_list,= void *v, loff_t *pos) void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos) { unsigned long pid; + unsigned int first; loff_t l =3D 0; =20 - pid =3D find_first_bit(pid_list->pids, pid_list->pid_max); - if (pid >=3D pid_list->pid_max) + if (trace_pid_list_first(pid_list, &first) < 0) return NULL; =20 + pid =3D first; + /* Return pid + 1 so that zero can be the exit value */ for (pid++; pid && l < *pos; pid =3D (unsigned long)trace_pid_next(pid_list, (void *)pid, &l)) @@ -690,7 +676,7 @@ int trace_pid_write(struct trace_pid_list *filtered_pid= s, unsigned long val; int nr_pids =3D 0; ssize_t read =3D 0; - ssize_t ret =3D 0; + ssize_t ret; loff_t pos; pid_t pid; =20 @@ -703,34 +689,23 @@ int trace_pid_write(struct trace_pid_list *filtered_p= ids, * the user. If the operation fails, then the current list is * not modified. */ - pid_list =3D kmalloc(sizeof(*pid_list), GFP_KERNEL); + pid_list =3D trace_pid_list_alloc(); if (!pid_list) { trace_parser_put(&parser); return -ENOMEM; } =20 - pid_list->pid_max =3D READ_ONCE(pid_max); - - /* Only truncating will shrink pid_max */ - if (filtered_pids && filtered_pids->pid_max > pid_list->pid_max) - pid_list->pid_max =3D filtered_pids->pid_max; - - pid_list->pids =3D vzalloc((pid_list->pid_max + 7) >> 3); - if (!pid_list->pids) { - trace_parser_put(&parser); - kfree(pid_list); - return -ENOMEM; - } - if (filtered_pids) { /* copy the current bits to the new max */ - for_each_set_bit(pid, filtered_pids->pids, - filtered_pids->pid_max) { - set_bit(pid, pid_list->pids); + ret =3D trace_pid_list_first(filtered_pids, &pid); + while (!ret) { + trace_pid_list_set(pid_list, pid); + ret =3D trace_pid_list_next(filtered_pids, pid + 1, &pid); nr_pids++; } } =20 + ret =3D 0; while (cnt > 0) { =20 pos =3D 0; @@ -746,12 +721,13 @@ int trace_pid_write(struct trace_pid_list *filtered_p= ids, ret =3D -EINVAL; if (kstrtoul(parser.buffer, 0, &val)) break; - if (val >=3D pid_list->pid_max) - break; =20 pid =3D (pid_t)val; =20 - set_bit(pid, pid_list->pids); + if (trace_pid_list_set(pid_list, pid) < 0) { + ret =3D -1; + break; + } nr_pids++; =20 trace_parser_clear(&parser); @@ -760,13 +736,13 @@ int trace_pid_write(struct trace_pid_list *filtered_p= ids, trace_parser_put(&parser); =20 if (ret < 0) { - trace_free_pid_list(pid_list); + trace_pid_list_free(pid_list); return ret; } =20 if (!nr_pids) { /* Cleared the list of pids */ - trace_free_pid_list(pid_list); + trace_pid_list_free(pid_list); read =3D ret; pid_list =3D NULL; } diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 421374c304fc..d6763366a320 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -22,6 +22,8 @@ #include #include =20 +#include "pid_list.h" + #ifdef CONFIG_FTRACE_SYSCALLS #include /* For NR_SYSCALLS */ #include /* some archs define it here */ @@ -191,10 +193,14 @@ struct trace_options { struct trace_option_dentry *topts; }; =20 -struct trace_pid_list { - int pid_max; - unsigned long *pids; -}; +struct trace_pid_list *trace_pid_list_alloc(void); +void trace_pid_list_free(struct trace_pid_list *pid_list); +bool trace_pid_list_is_set(struct trace_pid_list *pid_list, unsigned int p= id); +int trace_pid_list_set(struct trace_pid_list *pid_list, unsigned int pid); +int trace_pid_list_clear(struct trace_pid_list *pid_list, unsigned int pid= ); +int trace_pid_list_first(struct trace_pid_list *pid_list, unsigned int *pi= d); +int trace_pid_list_next(struct trace_pid_list *pid_list, unsigned int pid, + unsigned int *next); =20 enum { TRACE_PIDS =3D BIT(0), diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index ea3fbfa87fdd..c4f654efb77a 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -900,10 +900,10 @@ static void __ftrace_clear_event_pids(struct trace_ar= ray *tr, int type) tracepoint_synchronize_unregister(); =20 if ((type & TRACE_PIDS) && pid_list) - trace_free_pid_list(pid_list); + trace_pid_list_free(pid_list); =20 if ((type & TRACE_NO_PIDS) && no_pid_list) - trace_free_pid_list(no_pid_list); + trace_pid_list_free(no_pid_list); } =20 static void ftrace_clear_event_pids(struct trace_array *tr, int type) @@ -1982,7 +1982,7 @@ event_pid_write(struct file *filp, const char __user = *ubuf, =20 if (filtered_pids) { tracepoint_synchronize_unregister(); - trace_free_pid_list(filtered_pids); + trace_pid_list_free(filtered_pids); } else if (pid_list && !other_pids) { register_pid_events(tr); } --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DBF0C19F28 for ; Wed, 27 Jul 2022 17:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242106AbiG0R1T (ORCPT ); Wed, 27 Jul 2022 13:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242070AbiG0R06 (ORCPT ); Wed, 27 Jul 2022 13:26:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 508FF7E312; Wed, 27 Jul 2022 09:46:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B7547600BE; Wed, 27 Jul 2022 16:46:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C318EC433C1; Wed, 27 Jul 2022 16:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940394; bh=9lAlWYIreBqMVyYbmM7NsAPiX5t/podqVbEtNIGuWOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nt29/CD3lMsOaC7XQ01+TL2DCw64rgEuOx4FArQC+mjNUqeC3gyXZWfPQ31doaZ73 0/RvGjA2IJujX32jsSgE1raeKZdhcLLzNxwD6mdg3lBjlaP2k65o2IyhCE8hPGkgqR DRjtPLvZVdj8xlCuYqK/T/+uOuaoFuCqMAVD1UAQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Baik Song An , Hong Yeon Kim , Taeung Song , linuxgeek@linuxgeek.io, Wonhyuk Yang , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.15 171/201] tracing: Fix return value of trace_pid_write() Date: Wed, 27 Jul 2022 18:11:15 +0200 Message-Id: <20220727161034.910245226@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Wonhyuk Yang [ Upstream commit b27f266f74fbda4ee36c2b2b04d15992860cf23b ] Setting set_event_pid with trailing whitespace lead to endless write system calls like below. $ strace echo "123 " > /sys/kernel/debug/tracing/set_event_pid execve("/usr/bin/echo", ["echo", "123 "], ...) =3D 0 ... write(1, "123 \n", 5) =3D 4 write(1, "\n", 1) =3D 0 write(1, "\n", 1) =3D 0 write(1, "\n", 1) =3D 0 write(1, "\n", 1) =3D 0 write(1, "\n", 1) =3D 0 .... This is because, the result of trace_get_user's are not returned when it read at least one pid. To fix it, update read variable even if parser->idx =3D=3D 0. The result of applied patch is below. $ strace echo "123 " > /sys/kernel/debug/tracing/set_event_pid execve("/usr/bin/echo", ["echo", "123 "], ...) =3D 0 ... write(1, "123 \n", 5) =3D 5 close(1) =3D 0 Link: https://lkml.kernel.org/r/20220503050546.288911-1-vvghjk1234@gmail.com Cc: Ingo Molnar Cc: Baik Song An Cc: Hong Yeon Kim Cc: Taeung Song Cc: linuxgeek@linuxgeek.io Cc: stable@vger.kernel.org Fixes: 4909010788640 ("tracing: Add set_event_pid directory for future use") Signed-off-by: Wonhyuk Yang Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/trace/trace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index abbe8489faae..d93f9c59f50e 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -711,13 +711,16 @@ int trace_pid_write(struct trace_pid_list *filtered_p= ids, pos =3D 0; =20 ret =3D trace_get_user(&parser, ubuf, cnt, &pos); - if (ret < 0 || !trace_parser_loaded(&parser)) + if (ret < 0) break; =20 read +=3D ret; ubuf +=3D ret; cnt -=3D ret; =20 + if (!trace_parser_loaded(&parser)) + break; + ret =3D -EINVAL; if (kstrtoul(parser.buffer, 0, &val)) break; @@ -743,7 +746,6 @@ int trace_pid_write(struct trace_pid_list *filtered_pid= s, if (!nr_pids) { /* Cleared the list of pids */ trace_pid_list_free(pid_list); - read =3D ret; pid_list =3D NULL; } =20 --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70E2BC04A68 for ; Wed, 27 Jul 2022 17:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241830AbiG0RWt (ORCPT ); Wed, 27 Jul 2022 13:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241742AbiG0RUG (ORCPT ); Wed, 27 Jul 2022 13:20:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFC25FE5; Wed, 27 Jul 2022 09:45:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6A72960D38; Wed, 27 Jul 2022 16:45:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A882C433D6; Wed, 27 Jul 2022 16:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940310; bh=zGCAgJhBf44iFooeQHPvXDPv29VQrkH+AaDCuOzx3rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gwWZYoPUUyYcqhSxkJNKvyXXSHS0z5Sn9cV9bL9XYS9ptWr24KyitbiUOT/JB2wyt chIJM/5eLeP+e2hI0A53p7OYaJ4KDZGEfqpdwkRxjDI6vX6VLdyMdTQPdeV0GfnfMQ bTlyKNtDT7JX4375GBuGFqsx8Emd5gsdyHkF2RMc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Whitchurch , Richard Weinberger , Sasha Levin Subject: [PATCH 5.15 172/201] um: virtio_uml: Allow probing from devicetree Date: Wed, 27 Jul 2022 18:11:16 +0200 Message-Id: <20220727161034.940412654@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Vincent Whitchurch [ Upstream commit db0dd9cee82270e032123169ceff659eced5115d ] Allow the virtio_uml device to be probed from the devicetree so that sub-devices can be specified using the standard virtio bindings, for example: virtio@1 { compatible =3D "virtio,uml"; socket-path =3D "i2c.sock"; virtio-device-id =3D <0x22>; i2c-controller { compatible =3D "virtio,device22"; #address-cells =3D <0x01>; #size-cells =3D <0x00>; light-sensor@01 { compatible =3D "ti,opt3001"; reg =3D <0x01>; }; }; }; Signed-off-by: Vincent Whitchurch Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/um/drivers/virtio_uml.c | 50 +++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c index 7755cb4ff9fc..ba562d68dc04 100644 --- a/arch/um/drivers/virtio_uml.c +++ b/arch/um/drivers/virtio_uml.c @@ -21,6 +21,7 @@ * Based on Virtio MMIO driver by Pawel Moll, copyright 2011-2014, ARM Ltd. */ #include +#include #include #include #include @@ -49,6 +50,7 @@ struct virtio_uml_platform_data { struct virtio_uml_device { struct virtio_device vdev; struct platform_device *pdev; + struct virtio_uml_platform_data *pdata; =20 spinlock_t sock_lock; int sock, req_fd, irq; @@ -149,7 +151,7 @@ static int vhost_user_recv(struct virtio_uml_device *vu= _dev, if (rc =3D=3D -ECONNRESET && vu_dev->registered) { struct virtio_uml_platform_data *pdata; =20 - pdata =3D vu_dev->pdev->dev.platform_data; + pdata =3D vu_dev->pdata; =20 virtio_break_device(&vu_dev->vdev); schedule_work(&pdata->conn_broken_wk); @@ -1115,21 +1117,63 @@ void virtio_uml_set_no_vq_suspend(struct virtio_dev= ice *vdev, no_vq_suspend ? "dis" : "en"); } =20 +static void vu_of_conn_broken(struct work_struct *wk) +{ + /* + * We can't remove the device from the devicetree so the only thing we + * can do is warn. + */ + WARN_ON(1); +} + /* Platform device */ =20 +static struct virtio_uml_platform_data * +virtio_uml_create_pdata(struct platform_device *pdev) +{ + struct device_node *np =3D pdev->dev.of_node; + struct virtio_uml_platform_data *pdata; + int ret; + + if (!np) + return ERR_PTR(-EINVAL); + + pdata =3D devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + INIT_WORK(&pdata->conn_broken_wk, vu_of_conn_broken); + pdata->pdev =3D pdev; + + ret =3D of_property_read_string(np, "socket-path", &pdata->socket_path); + if (ret) + return ERR_PTR(ret); + + ret =3D of_property_read_u32(np, "virtio-device-id", + &pdata->virtio_device_id); + if (ret) + return ERR_PTR(ret); + + return pdata; +} + static int virtio_uml_probe(struct platform_device *pdev) { struct virtio_uml_platform_data *pdata =3D pdev->dev.platform_data; struct virtio_uml_device *vu_dev; int rc; =20 - if (!pdata) - return -EINVAL; + if (!pdata) { + pdata =3D virtio_uml_create_pdata(pdev); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + } =20 vu_dev =3D kzalloc(sizeof(*vu_dev), GFP_KERNEL); if (!vu_dev) return -ENOMEM; =20 + vu_dev->pdata =3D pdata; vu_dev->vdev.dev.parent =3D &pdev->dev; vu_dev->vdev.dev.release =3D virtio_uml_release_dev; vu_dev->vdev.config =3D &virtio_uml_config_ops; --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87547C04A68 for ; Wed, 27 Jul 2022 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242031AbiG0RYL (ORCPT ); Wed, 27 Jul 2022 13:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241956AbiG0RXZ (ORCPT ); Wed, 27 Jul 2022 13:23:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F39117AB3C; Wed, 27 Jul 2022 09:45:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6834FB8200C; Wed, 27 Jul 2022 16:45:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A86F4C433D7; Wed, 27 Jul 2022 16:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940342; bh=FP2F7zyyKo6KwfdNeVpY3GPe5U5gotHLjQ3RQIvnQQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0YlhmCiiGGdZWnRpMfueYGIXgmqc2sYATgKm9Ayo3oloGeDEKPUGzwb/nTu+vZDL0 +y/WM898aJ1K7R94iHojM5EIpTAFDVXPjlb7zzgfB+95RFSoiNrMXzNJpHn4+jut3p AwwX457MzXpB2Vdv3+nB8f/ksXtMOGvf2swlcBIc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg , Richard Weinberger , Sasha Levin Subject: [PATCH 5.15 173/201] um: virtio_uml: Fix broken device handling in time-travel Date: Wed, 27 Jul 2022 18:11:17 +0200 Message-Id: <20220727161034.977809905@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Johannes Berg [ Upstream commit af9fb41ed315ce95f659f0b10b4d59a71975381d ] If a device implementation crashes, virtio_uml will mark it as dead by calling virtio_break_device() and scheduling the work that will remove it. This still seems like the right thing to do, but it's done directly while reading the message, and if time-travel is used, this is in the time-travel handler, outside of the normal Linux machinery. Therefore, we cannot acquire locks or do normal "linux-y" things because e.g. lockdep will be confused about the context. Move handling this situation out of the read function and into the actual IRQ handler and response handling instead, so that in the case of time-travel we don't call it in the wrong context. Chances are the system will still crash immediately, since the device implementation crashing may also cause the time- travel controller to go down, but at least all of that now happens without strange warnings from lockdep. Fixes: c8177aba37ca ("um: time-travel: rework interrupt handling in ext mod= e") Cc: stable@vger.kernel.org Signed-off-by: Johannes Berg Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/um/drivers/virtio_uml.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c index ba562d68dc04..82ff3785bf69 100644 --- a/arch/um/drivers/virtio_uml.c +++ b/arch/um/drivers/virtio_uml.c @@ -63,6 +63,7 @@ struct virtio_uml_device { =20 u8 config_changed_irq:1; uint64_t vq_irq_vq_map; + int recv_rc; }; =20 struct virtio_uml_vq_info { @@ -148,14 +149,6 @@ static int vhost_user_recv(struct virtio_uml_device *v= u_dev, =20 rc =3D vhost_user_recv_header(fd, msg); =20 - if (rc =3D=3D -ECONNRESET && vu_dev->registered) { - struct virtio_uml_platform_data *pdata; - - pdata =3D vu_dev->pdata; - - virtio_break_device(&vu_dev->vdev); - schedule_work(&pdata->conn_broken_wk); - } if (rc) return rc; size =3D msg->header.size; @@ -164,6 +157,21 @@ static int vhost_user_recv(struct virtio_uml_device *v= u_dev, return full_read(fd, &msg->payload, size, false); } =20 +static void vhost_user_check_reset(struct virtio_uml_device *vu_dev, + int rc) +{ + struct virtio_uml_platform_data *pdata =3D vu_dev->pdata; + + if (rc !=3D -ECONNRESET) + return; + + if (!vu_dev->registered) + return; + + virtio_break_device(&vu_dev->vdev); + schedule_work(&pdata->conn_broken_wk); +} + static int vhost_user_recv_resp(struct virtio_uml_device *vu_dev, struct vhost_user_msg *msg, size_t max_payload_size) @@ -171,8 +179,10 @@ static int vhost_user_recv_resp(struct virtio_uml_devi= ce *vu_dev, int rc =3D vhost_user_recv(vu_dev, vu_dev->sock, msg, max_payload_size, true); =20 - if (rc) + if (rc) { + vhost_user_check_reset(vu_dev, rc); return rc; + } =20 if (msg->header.flags !=3D (VHOST_USER_FLAG_REPLY | VHOST_USER_VERSION)) return -EPROTO; @@ -369,6 +379,7 @@ static irqreturn_t vu_req_read_message(struct virtio_um= l_device *vu_dev, sizeof(msg.msg.payload) + sizeof(msg.extra_payload)); =20 + vu_dev->recv_rc =3D rc; if (rc) return IRQ_NONE; =20 @@ -412,7 +423,9 @@ static irqreturn_t vu_req_interrupt(int irq, void *data) if (!um_irq_timetravel_handler_used()) ret =3D vu_req_read_message(vu_dev, NULL); =20 - if (vu_dev->vq_irq_vq_map) { + if (vu_dev->recv_rc) { + vhost_user_check_reset(vu_dev, vu_dev->recv_rc); + } else if (vu_dev->vq_irq_vq_map) { struct virtqueue *vq; =20 virtio_device_for_each_vq((&vu_dev->vdev), vq) { --=20 2.35.1 From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD6FEC04A68 for ; Wed, 27 Jul 2022 17:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232229AbiG0RZr (ORCPT ); Wed, 27 Jul 2022 13:25:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242243AbiG0RYp (ORCPT ); Wed, 27 Jul 2022 13:24:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86115F9A6; Wed, 27 Jul 2022 09:46:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C293C60DDB; Wed, 27 Jul 2022 16:46:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF6EEC433D6; Wed, 27 Jul 2022 16:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940372; bh=7cxcXXPeU7k5QbBJxp1iNTuJ664l3od0idVpycl5vRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OGFVrkB6f3JJo5Zp6bZVlArSwn85rMEegMFIKf/oZwZ7dTpfMTW1++T5ECb3m6j7I ywBhsEDGQbJe7r1JYwxyUqfuv9LFzirV62NMihCsD9Z7wDhDb7M/JvLM0uPTpbAJvj AHUV7ycPOAPxDa7kFCTyWurJcjg7aqw5/oKQ+cSg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 5.15 174/201] Bluetooth: Add bt_skb_sendmsg helper Date: Wed, 27 Jul 2022 18:11:18 +0200 Message-Id: <20220727161035.014956207@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz commit 38f64f650dc0e44c146ff88d15a7339efa325918 upstream. bt_skb_sendmsg helps takes care of allocation the skb and copying the the contents of msg over to the skb while checking for possible errors so it should be safe to call it without holding lock_sock. Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/bluetooth/bluetooth.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -422,6 +422,34 @@ out: return NULL; } =20 +/* Shall not be called with lock_sock held */ +static inline struct sk_buff *bt_skb_sendmsg(struct sock *sk, + struct msghdr *msg, + size_t len, size_t mtu, + size_t headroom, size_t tailroom) +{ + struct sk_buff *skb; + size_t size =3D min_t(size_t, len, mtu); + int err; + + skb =3D bt_skb_send_alloc(sk, size + headroom + tailroom, + msg->msg_flags & MSG_DONTWAIT, &err); + if (!skb) + return ERR_PTR(err); + + skb_reserve(skb, headroom); + skb_tailroom_reserve(skb, mtu, tailroom); + + if (!copy_from_iter_full(skb_put(skb, size), size, &msg->msg_iter)) { + kfree_skb(skb); + return ERR_PTR(-EFAULT); + } + + skb->priority =3D sk->sk_priority; + + return skb; +} + int bt_to_errno(u16 code); =20 void hci_sock_set_flag(struct sock *sk, int nr); From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29F01C04A68 for ; Wed, 27 Jul 2022 17:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242138AbiG0R00 (ORCPT ); Wed, 27 Jul 2022 13:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242359AbiG0RY6 (ORCPT ); Wed, 27 Jul 2022 13:24:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83E827D1FE; Wed, 27 Jul 2022 09:46:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2D32960D3B; Wed, 27 Jul 2022 16:46:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BA28C433D6; Wed, 27 Jul 2022 16:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940377; bh=4ghA5FEC/uW3xtlrEE/rw7ykV6N69eTp+mhyE3BWyMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/BIgZBqlzZwvaFyiKJvGShSKKCvQs8emW65JdrrXFrnJktoDaBon8ke5dNiwZZ0V s7Y3LDbuZnDSKOVHDoWDa9xt5PGkiktOyuI3akrVI2x1h0R4Vnr9Yl0SZqzX8CYb16 QASYuVRDLDBJ77G0kpf9KBRqFwcU5+T7NIc5lims= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 5.15 175/201] Bluetooth: Add bt_skb_sendmmsg helper Date: Wed, 27 Jul 2022 18:11:19 +0200 Message-Id: <20220727161035.054038988@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz commit 97e4e80299844bb5f6ce5a7540742ffbffae3d97 upstream. This works similarly to bt_skb_sendmsg but can split the msg into multiple skb fragments which is useful for stream sockets. Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/bluetooth/bluetooth.h | 38 +++++++++++++++++++++++++++++++++= +++++ 1 file changed, 38 insertions(+) --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -450,6 +450,44 @@ static inline struct sk_buff *bt_skb_sen return skb; } =20 +/* Similar to bt_skb_sendmsg but can split the msg into multiple fragments + * accourding to the MTU. + */ +static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk, + struct msghdr *msg, + size_t len, size_t mtu, + size_t headroom, size_t tailroom) +{ + struct sk_buff *skb, **frag; + + skb =3D bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom); + if (IS_ERR_OR_NULL(skb)) + return skb; + + len -=3D skb->len; + if (!len) + return skb; + + /* Add remaining data over MTU as continuation fragments */ + frag =3D &skb_shinfo(skb)->frag_list; + while (len) { + struct sk_buff *tmp; + + tmp =3D bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom); + if (IS_ERR_OR_NULL(tmp)) { + kfree_skb(skb); + return tmp; + } + + len -=3D tmp->len; + + *frag =3D tmp; + frag =3D &(*frag)->next; + } + + return skb; +} + int bt_to_errno(u16 code); =20 void hci_sock_set_flag(struct sock *sk, int nr); From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04178C19F28 for ; Wed, 27 Jul 2022 17:25:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233851AbiG0RZz (ORCPT ); Wed, 27 Jul 2022 13:25:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242250AbiG0RYp (ORCPT ); Wed, 27 Jul 2022 13:24:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20E957CB56; Wed, 27 Jul 2022 09:46:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9C46AB821A6; Wed, 27 Jul 2022 16:46:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDB01C433C1; Wed, 27 Jul 2022 16:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940380; bh=5gHN7mv2FgbxJ3XV/9doGF8tQrvMiH029+WBDE84Jso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dyQLvU76Ta1Uhk4phHA0dVUAAj7wberuJpxjEqC0+5wksjcUfQ2NZ3RaLLvDMUAw7 uBtn7U2j/6NKSy84qc3m2s766OXMlabVj69O8LwDKjpHXHljoEp8lZ3iyOtpR8IQAt Apz8KA6y74WiIG2/YF7Wz77y/5Zpp+9Ywydkrxvg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 5.15 176/201] Bluetooth: SCO: Replace use of memcpy_from_msg with bt_skb_sendmsg Date: Wed, 27 Jul 2022 18:11:20 +0200 Message-Id: <20220727161035.093748254@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz commit 0771cbb3b97d3c1d68eecd7f00055f599954c34e upstream. This makes use of bt_skb_sendmsg instead of allocating a different buffer to be used with memcpy_from_msg which cause one extra copy. Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/bluetooth/sco.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -280,27 +280,19 @@ static int sco_connect(struct hci_dev *h return err; } =20 -static int sco_send_frame(struct sock *sk, void *buf, int len, - unsigned int msg_flags) +static int sco_send_frame(struct sock *sk, struct sk_buff *skb) { struct sco_conn *conn =3D sco_pi(sk)->conn; - struct sk_buff *skb; - int err; =20 /* Check outgoing MTU */ - if (len > conn->mtu) + if (skb->len > conn->mtu) return -EINVAL; =20 - BT_DBG("sk %p len %d", sk, len); + BT_DBG("sk %p len %d", sk, skb->len); =20 - skb =3D bt_skb_send_alloc(sk, len, msg_flags & MSG_DONTWAIT, &err); - if (!skb) - return err; - - memcpy(skb_put(skb, len), buf, len); hci_send_sco(conn->hcon, skb); =20 - return len; + return skb->len; } =20 static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb) @@ -727,7 +719,7 @@ static int sco_sock_sendmsg(struct socke size_t len) { struct sock *sk =3D sock->sk; - void *buf; + struct sk_buff *skb; int err; =20 BT_DBG("sock %p, sk %p", sock, sk); @@ -739,24 +731,20 @@ static int sco_sock_sendmsg(struct socke if (msg->msg_flags & MSG_OOB) return -EOPNOTSUPP; =20 - buf =3D kmalloc(len, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - if (memcpy_from_msg(buf, msg, len)) { - kfree(buf); - return -EFAULT; - } + skb =3D bt_skb_sendmsg(sk, msg, len, len, 0, 0); + if (IS_ERR_OR_NULL(skb)) + return PTR_ERR(skb); =20 lock_sock(sk); =20 if (sk->sk_state =3D=3D BT_CONNECTED) - err =3D sco_send_frame(sk, buf, len, msg->msg_flags); + err =3D sco_send_frame(sk, skb); else err =3D -ENOTCONN; =20 release_sock(sk); - kfree(buf); + if (err) + kfree_skb(skb); return err; } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CA3DC04A68 for ; Wed, 27 Jul 2022 17:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242101AbiG0R05 (ORCPT ); Wed, 27 Jul 2022 13:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242103AbiG0R0C (ORCPT ); Wed, 27 Jul 2022 13:26:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E42F7E005; Wed, 27 Jul 2022 09:46:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 55981B821AC; Wed, 27 Jul 2022 16:46:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7BF6C433D7; Wed, 27 Jul 2022 16:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940383; bh=n3F8lmh2d1J+/JTqlyh1/WfUM4sggvcBvuWMKYpAjF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UpYh/XntK0vuPGRHWVwfaSMpiuvXRrRTKnLey0aUyrHAIIXDIXBBB+vnSnB/J9mKM 0YzOXsIxlL3hMCxK0Jiw5k8hb3v/G6h47+MQywh+aCsA9pj0XGm14c6YSkLrE7iv0F bz/VtejntZjRJdlYp2lxwZO3DnqWQ2ixoLWjJrLg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 5.15 177/201] Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg Date: Wed, 27 Jul 2022 18:11:21 +0200 Message-Id: <20220727161035.125034455@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz commit 81be03e026dc0c16dc1c64e088b2a53b73caa895 upstream. This makes use of bt_skb_sendmmsg instead using memcpy_from_msg which is not considered safe to be used when lock_sock is held. Also make rfcomm_dlc_send handle skb with fragments and queue them all atomically. Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/bluetooth/rfcomm/core.c | 50 +++++++++++++++++++++++++++++++++++++--= ----- net/bluetooth/rfcomm/sock.c | 50 ++++++++++-----------------------------= ----- 2 files changed, 55 insertions(+), 45 deletions(-) --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -549,22 +549,58 @@ struct rfcomm_dlc *rfcomm_dlc_exists(bda return dlc; } =20 +static int rfcomm_dlc_send_frag(struct rfcomm_dlc *d, struct sk_buff *frag) +{ + int len =3D frag->len; + + BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); + + if (len > d->mtu) + return -EINVAL; + + rfcomm_make_uih(frag, d->addr); + __skb_queue_tail(&d->tx_queue, frag); + + return len; +} + int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb) { - int len =3D skb->len; + unsigned long flags; + struct sk_buff *frag, *next; + int len; =20 if (d->state !=3D BT_CONNECTED) return -ENOTCONN; =20 - BT_DBG("dlc %p mtu %d len %d", d, d->mtu, len); + frag =3D skb_shinfo(skb)->frag_list; + skb_shinfo(skb)->frag_list =3D NULL; =20 - if (len > d->mtu) - return -EINVAL; + /* Queue all fragments atomically. */ + spin_lock_irqsave(&d->tx_queue.lock, flags); + + len =3D rfcomm_dlc_send_frag(d, skb); + if (len < 0 || !frag) + goto unlock; + + for (; frag; frag =3D next) { + int ret; + + next =3D frag->next; + + ret =3D rfcomm_dlc_send_frag(d, frag); + if (ret < 0) { + kfree_skb(frag); + goto unlock; + } + + len +=3D ret; + } =20 - rfcomm_make_uih(skb, d->addr); - skb_queue_tail(&d->tx_queue, skb); +unlock: + spin_unlock_irqrestore(&d->tx_queue.lock, flags); =20 - if (!test_bit(RFCOMM_TX_THROTTLED, &d->flags)) + if (len > 0 && !test_bit(RFCOMM_TX_THROTTLED, &d->flags)) rfcomm_schedule(); return len; } --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -575,47 +575,21 @@ static int rfcomm_sock_sendmsg(struct so lock_sock(sk); =20 sent =3D bt_sock_wait_ready(sk, msg->msg_flags); - if (sent) - goto done; - - while (len) { - size_t size =3D min_t(size_t, len, d->mtu); - int err; - - skb =3D sock_alloc_send_skb(sk, size + RFCOMM_SKB_RESERVE, - msg->msg_flags & MSG_DONTWAIT, &err); - if (!skb) { - if (sent =3D=3D 0) - sent =3D err; - break; - } - skb_reserve(skb, RFCOMM_SKB_HEAD_RESERVE); - - err =3D memcpy_from_msg(skb_put(skb, size), msg, size); - if (err) { - kfree_skb(skb); - if (sent =3D=3D 0) - sent =3D err; - break; - } - - skb->priority =3D sk->sk_priority; - - err =3D rfcomm_dlc_send(d, skb); - if (err < 0) { - kfree_skb(skb); - if (sent =3D=3D 0) - sent =3D err; - break; - } - - sent +=3D size; - len -=3D size; - } =20 -done: release_sock(sk); =20 + if (sent) + return sent; + + skb =3D bt_skb_sendmmsg(sk, msg, len, d->mtu, RFCOMM_SKB_HEAD_RESERVE, + RFCOMM_SKB_TAIL_RESERVE); + if (IS_ERR_OR_NULL(skb)) + return PTR_ERR(skb); + + sent =3D rfcomm_dlc_send(d, skb); + if (sent < 0) + kfree_skb(skb); + return sent; } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DD5BC04A68 for ; Wed, 27 Jul 2022 17:26:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242104AbiG0R0U (ORCPT ); Wed, 27 Jul 2022 13:26:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242343AbiG0RY4 (ORCPT ); Wed, 27 Jul 2022 13:24:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 949B77CB51; Wed, 27 Jul 2022 09:46:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2040CB821DA; Wed, 27 Jul 2022 16:46:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B7F0C433C1; Wed, 27 Jul 2022 16:46:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940385; bh=S8SWVllnVkzSgkTz6JoTxKs8jyHatnSGmDp56hMozCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ViuQZ4g11jv9QH6J3Qp1gF06UowyF/aLzh73IrFbYixuss3ldurwoUqdozmx4EhYt /DGUoMMFQsvMefzWna3hdBs6Xkl2B4Xppblh7JJBBmU8DZIqy3fSbNTRgOHLHEIOTV NqjJKDNe1MP0y1Ah7/s5OB8LSMcMWzdIA55yXzTY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Tedd Ho-Jeong An , Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 5.15 178/201] Bluetooth: Fix passing NULL to PTR_ERR Date: Wed, 27 Jul 2022 18:11:22 +0200 Message-Id: <20220727161035.173668564@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz commit 266191aa8d14b84958aaeb5e96ee4e97839e3d87 upstream. Passing NULL to PTR_ERR will result in 0 (success), also since the likes of bt_skb_sendmsg does never return NULL it is safe to replace the instances of IS_ERR_OR_NULL with IS_ERR when checking its return. Reported-by: Dan Carpenter Tested-by: Tedd Ho-Jeong An Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/bluetooth/bluetooth.h | 2 +- net/bluetooth/rfcomm/sock.c | 2 +- net/bluetooth/sco.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -474,7 +474,7 @@ static inline struct sk_buff *bt_skb_sen struct sk_buff *tmp; =20 tmp =3D bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom); - if (IS_ERR_OR_NULL(tmp)) { + if (IS_ERR(tmp)) { kfree_skb(skb); return tmp; } --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -583,7 +583,7 @@ static int rfcomm_sock_sendmsg(struct so =20 skb =3D bt_skb_sendmmsg(sk, msg, len, d->mtu, RFCOMM_SKB_HEAD_RESERVE, RFCOMM_SKB_TAIL_RESERVE); - if (IS_ERR_OR_NULL(skb)) + if (IS_ERR(skb)) return PTR_ERR(skb); =20 sent =3D rfcomm_dlc_send(d, skb); --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -732,7 +732,7 @@ static int sco_sock_sendmsg(struct socke return -EOPNOTSUPP; =20 skb =3D bt_skb_sendmsg(sk, msg, len, len, 0, 0); - if (IS_ERR_OR_NULL(skb)) + if (IS_ERR(skb)) return PTR_ERR(skb); =20 lock_sock(sk); From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEA2C04A68 for ; Wed, 27 Jul 2022 17:26:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbiG0R0B (ORCPT ); Wed, 27 Jul 2022 13:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242324AbiG0RYy (ORCPT ); Wed, 27 Jul 2022 13:24:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 420077D1DC; Wed, 27 Jul 2022 09:46:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C28BCB821BE; Wed, 27 Jul 2022 16:46:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E63FC433C1; Wed, 27 Jul 2022 16:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940388; bh=8wseduYSB04klnmbB3qO5dWg7kVn28vt/87y7JL97D4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uCM6svHfXDhLOC4Pdi5YxlyIO09BwIK7ubU9Eu6O60yEOUsrvrE7w05hMzIZBd2J7 j4uyhHkA/sU8m3yyYSoWvfaCGgz2hzJX3y9eWUVl1Oihvcjow7ebMM+fBs23buw51r lkmxoOM5vJ6fg8NHkE58hYQ532UEIrKXQUg2ljfA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tedd Ho-Jeong An , Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 5.15 179/201] Bluetooth: SCO: Fix sco_send_frame returning skb->len Date: Wed, 27 Jul 2022 18:11:23 +0200 Message-Id: <20220727161035.212051689@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz commit 037ce005af6b8a3e40ee07c6e9266c8997e6a4d6 upstream. The skb in modified by hci_send_sco which pushes SCO headers thus changing skb->len causing sco_sock_sendmsg to fail. Fixes: 0771cbb3b97d ("Bluetooth: SCO: Replace use of memcpy_from_msg with b= t_skb_sendmsg") Tested-by: Tedd Ho-Jeong An Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- net/bluetooth/sco.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -283,16 +283,17 @@ static int sco_connect(struct hci_dev *h static int sco_send_frame(struct sock *sk, struct sk_buff *skb) { struct sco_conn *conn =3D sco_pi(sk)->conn; + int len =3D skb->len; =20 /* Check outgoing MTU */ - if (skb->len > conn->mtu) + if (len > conn->mtu) return -EINVAL; =20 - BT_DBG("sk %p len %d", sk, skb->len); + BT_DBG("sk %p len %d", sk, len); =20 hci_send_sco(conn->hcon, skb); =20 - return skb->len; + return len; } =20 static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb) @@ -743,7 +744,8 @@ static int sco_sock_sendmsg(struct socke err =3D -ENOTCONN; =20 release_sock(sk); - if (err) + + if (err < 0) kfree_skb(skb); return err; } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5713AC04A68 for ; Wed, 27 Jul 2022 17:26:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242116AbiG0R0K (ORCPT ); Wed, 27 Jul 2022 13:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242345AbiG0RY4 (ORCPT ); Wed, 27 Jul 2022 13:24:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE2667D1F4; Wed, 27 Jul 2022 09:46:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F375260DDB; Wed, 27 Jul 2022 16:46:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 091E4C433D6; Wed, 27 Jul 2022 16:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940391; bh=h6k8ja6jrl5KWyFSSA41/040OlijOASIOH7TtWmIBKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U+t2Ve8G4Uw9LoXEvkHI9yNtCxDrtkF21Cd+gK2MQhl3AmF9A/Yn8mT71hiafTMOM C39KVqzGV4InpktvHhD9p5T6rJkX45dc0h4y5AT9TuLqPjeUh39rNcF3ZTQrC78wnu iVw2K0pOyCJKRFQl54If+bG1ZDsqsHdyqG0FYrQE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Menzel , Luiz Augusto von Dentz , Marcel Holtmann , Harshit Mogalapalli Subject: [PATCH 5.15 180/201] Bluetooth: Fix bt_skb_sendmmsg not allocating partial chunks Date: Wed, 27 Jul 2022 18:11:24 +0200 Message-Id: <20220727161035.261838671@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz commit 29fb608396d6a62c1b85acc421ad7a4399085b9f upstream. Since bt_skb_sendmmsg can be used with the likes of SOCK_STREAM it shall return the partial chunks it could allocate instead of freeing everything as otherwise it can cause problems like bellow. Fixes: 81be03e026dc ("Bluetooth: RFCOMM: Replace use of memcpy_from_msg wit= h bt_skb_sendmmsg") Reported-by: Paul Menzel Link: https://lore.kernel.org/r/d7206e12-1b99-c3be-84f4-df22af427ef5@molgen= .mpg.de BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=3D215594 Signed-off-by: Luiz Augusto von Dentz Tested-by: Paul Menzel (Nokia N9 (MeeGo/Harmattan) Signed-off-by: Marcel Holtmann Cc: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- include/net/bluetooth/bluetooth.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -475,8 +475,7 @@ static inline struct sk_buff *bt_skb_sen =20 tmp =3D bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom); if (IS_ERR(tmp)) { - kfree_skb(skb); - return tmp; + return skb; } =20 len -=3D tmp->len; From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB237C04A68 for ; Wed, 27 Jul 2022 17:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242013AbiG0RXC (ORCPT ); Wed, 27 Jul 2022 13:23:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235333AbiG0RVO (ORCPT ); Wed, 27 Jul 2022 13:21:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C198751A1B; Wed, 27 Jul 2022 09:45:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 08F9AB821A6; Wed, 27 Jul 2022 16:45:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67594C433C1; Wed, 27 Jul 2022 16:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940313; bh=1YJj+zf8oi0rxQU45OyHdE/CCMttpqbIvrrCYGyaOQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxWWuAbRn5PlWl5w4uG3Hvvw9jlQXL0UbE257FJATS5182g8+1QvHaLP7hioyabwv 65nf+S5gWapbsL0Vzkgqc0hYnUnjH7oDKwR10DXUceS2+GlzpztkPDLPPAss7MeESv GUC7AF6DZJYFLjBPmgEwMjPRAl+z/DiBQ20OkfpY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wang Yugui , Sungjong Seo , Namjae Jeon Subject: [PATCH 5.15 181/201] exfat: use updated exfat_chain directly during renaming Date: Wed, 27 Jul 2022 18:11:25 +0200 Message-Id: <20220727161035.302903018@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sungjong Seo commit 204e6ceaa1035cb7b92b156517e88842ebb4c7ff upstream. In order for a file to access its own directory entry set, exfat_inode_info(ei) has two copied values. One is ei->dir, which is a snapshot of exfat_chain of the parent directory, and the other is ei->entry, which is the offset of the start of the directory entry set in the parent directory. Since the parent directory can be updated after the snapshot point, it should be used only for accessing one's own directory entry set. However, as of now, during renaming, it could try to traverse or to allocate clusters via snapshot values, it does not make sense. This potential problem has been revealed when exfat_update_parent_info() was removed by commit d8dad2588add ("exfat: fix referencing wrong parent directory information after renaming"). However, I don't think it's good idea to bring exfat_update_parent_info() back. Instead, let's use the updated exfat_chain of parent directory diectly. Fixes: d8dad2588add ("exfat: fix referencing wrong parent directory informa= tion after renaming") Reported-by: Wang Yugui Signed-off-by: Sungjong Seo Tested-by: Wang Yugui Signed-off-by: Namjae Jeon Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- fs/exfat/namei.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -1190,7 +1190,9 @@ static int __exfat_rename(struct inode * return -ENOENT; } =20 - exfat_chain_dup(&olddir, &ei->dir); + exfat_chain_set(&olddir, EXFAT_I(old_parent_inode)->start_clu, + EXFAT_B_TO_CLU_ROUND_UP(i_size_read(old_parent_inode), sbi), + EXFAT_I(old_parent_inode)->flags); dentry =3D ei->entry; =20 ep =3D exfat_get_dentry(sb, &olddir, dentry, &old_bh, NULL); From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48856C04A68 for ; Wed, 27 Jul 2022 17:23:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233589AbiG0RXM (ORCPT ); Wed, 27 Jul 2022 13:23:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241932AbiG0RVt (ORCPT ); Wed, 27 Jul 2022 13:21:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7935D5F119; Wed, 27 Jul 2022 09:45:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D7FFFB821C6; Wed, 27 Jul 2022 16:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 484F7C433D7; Wed, 27 Jul 2022 16:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940316; bh=q+ehiNDbz3MqQd5JBHu7bhdKpk+g3BTj6YabfJtgHlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qL6x2LW/UjwPKIFOBPddvTiYv2Nk8eIz0LPwy7L7OquYuOSSIgCUzeCEJcmmTCFIv Ekv7uvpn5p3jfDfaU3fhkdGQ8QZiQabUFGtN5Cd9mBWzrrmZS7+To8MX15K8ajG57K aTupOSs6W+cGzu966wF2YOt8OOWykT+6EAgeLe80= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aurabindo Jayamohanan Pillai , Pavle Kotarac , Daniel Wheeler , Nicholas Kazlauskas , Alex Deucher , "Limonciello, Mario" Subject: [PATCH 5.15 182/201] drm/amd/display: Reset DMCUB before HW init Date: Wed, 27 Jul 2022 18:11:26 +0200 Message-Id: <20220727161035.332980447@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Nicholas Kazlauskas commit 791255ca9fbe38042cfd55df5deb116dc11fef18 upstream. [Why] If the firmware wasn't reset by PSP or HW and is currently running then the firmware will hang or perform underfined behavior when we modify its firmware state underneath it. [How] Reset DMCUB before setting up cache windows and performing HW init. Reviewed-by: Aurabindo Jayamohanan Pillai Acked-by: Pavle Kotarac Tested-by: Daniel Wheeler Signed-off-by: Nicholas Kazlauskas Signed-off-by: Alex Deucher Cc: "Limonciello, Mario" Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -1028,6 +1028,11 @@ static int dm_dmub_hw_init(struct amdgpu return 0; } =20 + /* Reset DMCUB if it was previously running - before we overwrite its mem= ory. */ + status =3D dmub_srv_hw_reset(dmub_srv); + if (status !=3D DMUB_STATUS_OK) + DRM_WARN("Error resetting DMUB HW: %d\n", status); + hdr =3D (const struct dmcub_firmware_header_v1_0 *)dmub_fw->data; =20 fw_inst_const =3D dmub_fw->data + From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0566DC04A68 for ; Wed, 27 Jul 2022 17:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241928AbiG0RW6 (ORCPT ); Wed, 27 Jul 2022 13:22:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241819AbiG0RU6 (ORCPT ); Wed, 27 Jul 2022 13:20:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA254664CF; Wed, 27 Jul 2022 09:45:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B1C12B8200D; Wed, 27 Jul 2022 16:45:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AB90C433C1; Wed, 27 Jul 2022 16:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940319; bh=q4FJTfADqyAATI/6Vy4O68t1Bj6HIZ0dpHIGC62mgoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XJUjcuBb60YyGq92FQOmdfX05hFWVIalbcPwUlKAghWcZ5/V0ie9H+C03pf1FUygJ A2EneKa3AXGFR9U1v4FiF8VUhAcyp2qZbYADWqtGv9T4CCHcXRFnr4NSWeg0KxSeJQ D5qYsyf1ZEnEittk0HGW6bMiYN50fjOsbU+yh2Fg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bhawanpreet Lakha , Mikita Lipski , Nicholas Kazlauskas , Daniel Wheeler , Alex Deucher , Mario Limonciello Subject: [PATCH 5.15 183/201] drm/amd/display: Optimize bandwidth on following fast update Date: Wed, 27 Jul 2022 18:11:27 +0200 Message-Id: <20220727161035.371672809@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Nicholas Kazlauskas commit 34316c1e561db0b24e341029f04a5a5bead9a7bc upstream. [Why] The current call to optimize_bandwidth never occurs because flip is always pending from the FULL and FAST updates. [How] Optimize on the following flip when it's a FAST update and we know we aren't going to be modifying the clocks again. Reviewed-by: Bhawanpreet Lakha Acked-by: Mikita Lipski Signed-off-by: Nicholas Kazlauskas Tested-by: Daniel Wheeler Signed-off-by: Alex Deucher Cc: Mario Limonciello Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/amd/display/dc/core/dc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) --- a/drivers/gpu/drm/amd/display/dc/core/dc.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c @@ -1788,6 +1788,11 @@ void dc_post_update_surfaces_to_stream(s =20 post_surface_trace(dc); =20 + if (dc->ctx->dce_version >=3D DCE_VERSION_MAX) + TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk); + else + TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce); + if (is_flip_pending_in_pipes(dc, context)) return; =20 @@ -2974,6 +2979,9 @@ void dc_commit_updates_for_stream(struct if (new_pipe->plane_state && new_pipe->plane_state !=3D old_pipe->plane= _state) new_pipe->plane_state->force_full_update =3D true; } + } else if (update_type =3D=3D UPDATE_TYPE_FAST) { + /* Previous frame finished and HW is ready for optimization. */ + dc_post_update_surfaces_to_stream(dc); } =20 =20 @@ -3030,15 +3038,6 @@ void dc_commit_updates_for_stream(struct pipe_ctx->plane_state->force_full_update =3D false; } } - /*let's use current_state to update watermark etc*/ - if (update_type >=3D UPDATE_TYPE_FULL) { - dc_post_update_surfaces_to_stream(dc); - - if (dc_ctx->dce_version >=3D DCE_VERSION_MAX) - TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk); - else - TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce); - } =20 return; From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39EC9C04A68 for ; Wed, 27 Jul 2022 17:22:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241641AbiG0RWz (ORCPT ); Wed, 27 Jul 2022 13:22:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241848AbiG0RUy (ORCPT ); Wed, 27 Jul 2022 13:20:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61BC45F110; Wed, 27 Jul 2022 09:45:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6A8A3B821D4; Wed, 27 Jul 2022 16:45:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9504C433C1; Wed, 27 Jul 2022 16:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940322; bh=MxIqrIPmkawLpmAgdInOx6a9yL6SrBN/IMRL0oRRGK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UJNMiQE9V9mvm9y0uGs2s8kkY/DBmF7XSbQGPTlzjDv8x04KAWZUEgZFfcVstQFXU yt11ojcdAtTXNb09uwJcUgI8RC8CmSSZxZlgNofJGs/1pmU04DjEnOhekA3oHIsDyV DDdFd3xvv9ig2gopy3L2oxCCeIpSnh21bwN3v1JQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom St Denis , Harry Wentland , Nicholas Kazlauskas , Alex Deucher , Mario Limonciello Subject: [PATCH 5.15 184/201] drm/amd/display: Fix surface optimization regression on Carrizo Date: Wed, 27 Jul 2022 18:11:28 +0200 Message-Id: <20220727161035.401781717@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Nicholas Kazlauskas commit 62e5a7e2333a9f5395f6a9db766b7b06c949fe7a upstream. [Why] DCE legacy optimization path isn't well tested under new DC optimization flow which can result in underflow occuring when initializing X11 on Carrizo. [How] Retain the legacy optimization flow for DCE and keep the new one for DCN to satisfy optimizations being correctly applied for ASIC that can support it. Fixes: 34316c1e561db0 ("drm/amd/display: Optimize bandwidth on following fa= st update") Reported-by: Tom St Denis Tested-by: Tom St Denis Reviewed-by: Harry Wentland Signed-off-by: Nicholas Kazlauskas Signed-off-by: Alex Deucher Cc: Mario Limonciello Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/amd/display/dc/core/dc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/gpu/drm/amd/display/dc/core/dc.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c @@ -2979,8 +2979,13 @@ void dc_commit_updates_for_stream(struct if (new_pipe->plane_state && new_pipe->plane_state !=3D old_pipe->plane= _state) new_pipe->plane_state->force_full_update =3D true; } - } else if (update_type =3D=3D UPDATE_TYPE_FAST) { - /* Previous frame finished and HW is ready for optimization. */ + } else if (update_type =3D=3D UPDATE_TYPE_FAST && dc_ctx->dce_version >= =3D DCE_VERSION_MAX) { + /* + * Previous frame finished and HW is ready for optimization. + * + * Only relevant for DCN behavior where we can guarantee the optimization + * is safe to apply - retain the legacy behavior for DCE. + */ dc_post_update_surfaces_to_stream(dc); } =20 @@ -3039,6 +3044,12 @@ void dc_commit_updates_for_stream(struct } } =20 + /* Legacy optimization path for DCE. */ + if (update_type >=3D UPDATE_TYPE_FULL && dc_ctx->dce_version < DCE_VERSIO= N_MAX) { + dc_post_update_surfaces_to_stream(dc); + TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce); + } + return; =20 } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E217C04A68 for ; Wed, 27 Jul 2022 17:23:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232351AbiG0RXI (ORCPT ); Wed, 27 Jul 2022 13:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241718AbiG0RVt (ORCPT ); Wed, 27 Jul 2022 13:21:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61FE95F112; Wed, 27 Jul 2022 09:45:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8BB87600BE; Wed, 27 Jul 2022 16:45:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92E2AC433D6; Wed, 27 Jul 2022 16:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940325; bh=+uMl4FLl097Loyy9TApm/tAdFNX8flz7zh2/oIFqi54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xo9fmTFqLpx6WqxqinBPhjyK2EfaZdq0upewc9U4io8tEwnw4NsTO1xntMd2pZucx a3J+lOAVaCWLbMPg40F5Fyjs7y0CKH2wOXpZfYUCpCEkZakCp8dxMSK/1xWtNWILcz 17JDwJjEe+4U9zKqiDtI1xWxbvGLIV/chBMdMh3s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov Subject: [PATCH 5.15 185/201] x86/amd: Use IBPB for firmware calls Date: Wed, 27 Jul 2022 18:11:29 +0200 Message-Id: <20220727161035.433409425@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra commit 28a99e95f55c61855983d36a88c05c178d966bb7 upstream. On AMD IBRS does not prevent Retbleed; as such use IBPB before a firmware call to flush the branch history state. And because in order to do an EFI call, the kernel maps a whole lot of the kernel page table into the EFI page table, do an IBPB just in case in order to prevent the scenario of poisoning the BTB and causing an EFI call using the unprotected RET there. [ bp: Massage. ] Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20220715194550.793957-1-cascardo@canonical.= com Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/nospec-branch.h | 2 ++ arch/x86/kernel/cpu/bugs.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -300,6 +300,7 @@ #define X86_FEATURE_RETPOLINE_LFENCE (11*32+13) /* "" Use LFENCE for Spect= re variant 2 */ #define X86_FEATURE_RETHUNK (11*32+14) /* "" Use REturn THUNK */ #define X86_FEATURE_UNRET (11*32+15) /* "" AMD BTB untrain return */ +#define X86_FEATURE_USE_IBPB_FW (11*32+16) /* "" Use IBPB during runtime = firmware calls */ =20 /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -298,6 +298,8 @@ do { \ alternative_msr_write(MSR_IA32_SPEC_CTRL, \ spec_ctrl_current() | SPEC_CTRL_IBRS, \ X86_FEATURE_USE_IBRS_FW); \ + alternative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB, \ + X86_FEATURE_USE_IBPB_FW); \ } while (0) =20 #define firmware_restrict_branch_speculation_end() \ --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1512,7 +1512,16 @@ static void __init spectre_v2_select_mit * the CPU supports Enhanced IBRS, kernel might un-intentionally not * enable IBRS around firmware calls. */ - if (boot_cpu_has(X86_FEATURE_IBRS) && !spectre_v2_in_ibrs_mode(mode)) { + if (boot_cpu_has_bug(X86_BUG_RETBLEED) && + (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || + boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON)) { + + if (retbleed_cmd !=3D RETBLEED_CMD_IBPB) { + setup_force_cpu_cap(X86_FEATURE_USE_IBPB_FW); + pr_info("Enabling Speculation Barrier for firmware calls\n"); + } + + } else if (boot_cpu_has(X86_FEATURE_IBRS) && !spectre_v2_in_ibrs_mode(mod= e)) { setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW); pr_info("Enabling Restricted Speculation for firmware calls\n"); } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37062C04A68 for ; Wed, 27 Jul 2022 17:23:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242028AbiG0RX1 (ORCPT ); Wed, 27 Jul 2022 13:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238415AbiG0RWf (ORCPT ); Wed, 27 Jul 2022 13:22:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2337C6A9F6; Wed, 27 Jul 2022 09:45:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6C9D060D38; Wed, 27 Jul 2022 16:45:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 784BFC433D6; Wed, 27 Jul 2022 16:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940327; bh=SNZo9zZvoKvtkMCRfTolSwauE3cA8JC25YoaHnMIbc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KwiNkWRKLwqhIvLGrhSMJqU5KPCBy9zDdDqYgg3DUCSZPaK8hYznzQg/W5gcrYr0i wOMxwjjCAALylJi6RqgiRwIbZ1A7IoTJouCnkVZeSaZ6WrBpeYrZOF6Mv13/ISTrgU 1qOT5F0werVvAjwsXN7Gz1hVNiKVS0jujpgiha7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Zijlstra , Kees Cook Subject: [PATCH 5.15 186/201] x86/alternative: Report missing return thunk details Date: Wed, 27 Jul 2022 18:11:30 +0200 Message-Id: <20220727161035.480770452@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kees Cook commit 65cdf0d623bedf0e069bb64ed52e8bb20105e2ba upstream. Debugging missing return thunks is easier if we can see where they're happening. Suggested-by: Peter Zijlstra Signed-off-by: Kees Cook Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/lkml/Ys66hwtFcGbYmoiZ@hirez.programming.kicks= -ass.net/ Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/kernel/alternative.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -554,7 +554,9 @@ void __init_or_module noinline apply_ret dest =3D addr + insn.length + insn.immediate.value; =20 if (__static_call_fixup(addr, op, dest) || - WARN_ON_ONCE(dest !=3D &__x86_return_thunk)) + WARN_ONCE(dest !=3D &__x86_return_thunk, + "missing return thunk: %pS-%pS: %*ph", + addr, dest, 5, addr)) continue; =20 DPRINTK("return thunk at: %pS (%px) len: %d to: %pS", From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45D92C04A68 for ; Wed, 27 Jul 2022 17:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbiG0RXt (ORCPT ); Wed, 27 Jul 2022 13:23:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242017AbiG0RXH (ORCPT ); Wed, 27 Jul 2022 13:23:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFA507AB10; Wed, 27 Jul 2022 09:45:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F33A6155E; Wed, 27 Jul 2022 16:45:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47005C433D7; Wed, 27 Jul 2022 16:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940330; bh=7yvDQWnND4ZyWhVfrWdvzBV3QLcB2BtDLr3nL9fwep4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJlUT+Jvodi9VGlYg80XE+KBL7nbu5Cb1Yl/Ja2THRlMXK1Uso4fdx0kRfhILqCE6 6MIIfV518fZ+nlFXfFo7K4RSOShXU6XPJW7Ahkm/rO4kTumJo+sIrTRb3WEFGtLezn WGxhkFv89+kWlu/sJwfFBRSc481GDNNu99zodY9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Noam Rathaus , David Howells , Linus Torvalds Subject: [PATCH 5.15 187/201] watchqueue: make sure to serialize wqueue->defunct properly Date: Wed, 27 Jul 2022 18:11:31 +0200 Message-Id: <20220727161035.521196235@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Linus Torvalds commit 353f7988dd8413c47718f7ca79c030b6fb62cfe5 upstream. When the pipe is closed, we mark the associated watchqueue defunct by calling watch_queue_clear(). However, while that is protected by the watchqueue lock, new watchqueue entries aren't actually added under that lock at all: they use the pipe->rd_wait.lock instead, and looking up that pipe happens without any locking. The watchqueue code uses the RCU read-side section to make sure that the wqueue entry itself hasn't disappeared, but that does not protect the pipe_info in any way. So make sure to actually hold the wqueue lock when posting watch events, properly serializing against the pipe being torn down. Reported-by: Noam Rathaus Cc: Greg KH Cc: David Howells Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/watch_queue.c | 53 +++++++++++++++++++++++++++++++++++-----------= ----- 1 file changed, 37 insertions(+), 16 deletions(-) --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -34,6 +34,27 @@ MODULE_LICENSE("GPL"); #define WATCH_QUEUE_NOTE_SIZE 128 #define WATCH_QUEUE_NOTES_PER_PAGE (PAGE_SIZE / WATCH_QUEUE_NOTE_SIZE) =20 +/* + * This must be called under the RCU read-lock, which makes + * sure that the wqueue still exists. It can then take the lock, + * and check that the wqueue hasn't been destroyed, which in + * turn makes sure that the notification pipe still exists. + */ +static inline bool lock_wqueue(struct watch_queue *wqueue) +{ + spin_lock_bh(&wqueue->lock); + if (unlikely(wqueue->defunct)) { + spin_unlock_bh(&wqueue->lock); + return false; + } + return true; +} + +static inline void unlock_wqueue(struct watch_queue *wqueue) +{ + spin_unlock_bh(&wqueue->lock); +} + static void watch_queue_pipe_buf_release(struct pipe_inode_info *pipe, struct pipe_buffer *buf) { @@ -69,6 +90,10 @@ static const struct pipe_buf_operations =20 /* * Post a notification to a watch queue. + * + * Must be called with the RCU lock for reading, and the + * watch_queue lock held, which guarantees that the pipe + * hasn't been released. */ static bool post_one_notification(struct watch_queue *wqueue, struct watch_notification *n) @@ -85,9 +110,6 @@ static bool post_one_notification(struct =20 spin_lock_irq(&pipe->rd_wait.lock); =20 - if (wqueue->defunct) - goto out; - mask =3D pipe->ring_size - 1; head =3D pipe->head; tail =3D pipe->tail; @@ -203,7 +225,10 @@ void __post_watch_notification(struct wa if (security_post_notification(watch->cred, cred, n) < 0) continue; =20 - post_one_notification(wqueue, n); + if (lock_wqueue(wqueue)) { + post_one_notification(wqueue, n); + unlock_wqueue(wqueue);; + } } =20 rcu_read_unlock(); @@ -465,11 +490,12 @@ int add_watch_to_object(struct watch *wa return -EAGAIN; } =20 - spin_lock_bh(&wqueue->lock); - kref_get(&wqueue->usage); - kref_get(&watch->usage); - hlist_add_head(&watch->queue_node, &wqueue->watches); - spin_unlock_bh(&wqueue->lock); + if (lock_wqueue(wqueue)) { + kref_get(&wqueue->usage); + kref_get(&watch->usage); + hlist_add_head(&watch->queue_node, &wqueue->watches); + unlock_wqueue(wqueue); + } =20 hlist_add_head(&watch->list_node, &wlist->watchers); return 0; @@ -523,20 +549,15 @@ found: =20 wqueue =3D rcu_dereference(watch->queue); =20 - /* We don't need the watch list lock for the next bit as RCU is - * protecting *wqueue from deallocation. - */ - if (wqueue) { + if (lock_wqueue(wqueue)) { post_one_notification(wqueue, &n.watch); =20 - spin_lock_bh(&wqueue->lock); - if (!hlist_unhashed(&watch->queue_node)) { hlist_del_init_rcu(&watch->queue_node); put_watch(watch); } =20 - spin_unlock_bh(&wqueue->lock); + unlock_wqueue(wqueue); } =20 if (wlist->release_watch) { From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F34EC04A68 for ; Wed, 27 Jul 2022 17:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242041AbiG0RXj (ORCPT ); Wed, 27 Jul 2022 13:23:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242000AbiG0RWw (ORCPT ); Wed, 27 Jul 2022 13:22:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2A26F7FA; Wed, 27 Jul 2022 09:45:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A896CB821A6; Wed, 27 Jul 2022 16:45:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AF18C433C1; Wed, 27 Jul 2022 16:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940333; bh=STSC/uyrBVz7rV5fTY9o9fyE0PYLOMybtV5+kYBr4eA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/m29RHoOtuWpNtqe253DAMuyvyLoEq52jYrVGqIWwtYq4JnYSpPLvR8yj5rwgiEB EqOJz83uuwx738xiSquFr+F8Ja5//02ImBbCYGDfvJx7rDI6CCENWMIuNluDW5jfUG hM2BWx7iHzR2KWKXxlQpQNsMcc09xwhgLoT2OuGs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Zapolskiy , Johan Hovold , Jiri Slaby Subject: [PATCH 5.15 188/201] tty: drivers/tty/, stop using tty_schedule_flip() Date: Wed, 27 Jul 2022 18:11:32 +0200 Message-Id: <20220727161035.559931107@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jiri Slaby commit 5f6a85158ccacc3f09744b3aafe8b11ab3b6c6f6 upstream. Since commit a9c3f68f3cd8d (tty: Fix low_latency BUG) in 2014, tty_flip_buffer_push() is only a wrapper to tty_schedule_flip(). We are going to remove the latter (as it is used less), so call the former in drivers/tty/. Cc: Vladimir Zapolskiy Reviewed-by: Johan Hovold Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20211122111648.30379-2-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/tty/goldfish.c | 2 +- drivers/tty/moxa.c | 4 ++-- drivers/tty/serial/lpc32xx_hs.c | 2 +- drivers/tty/vt/keyboard.c | 6 +++--- drivers/tty/vt/vt.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) --- a/drivers/tty/goldfish.c +++ b/drivers/tty/goldfish.c @@ -151,7 +151,7 @@ static irqreturn_t goldfish_tty_interrup address =3D (unsigned long)(void *)buf; goldfish_tty_rw(qtty, address, count, 0); =20 - tty_schedule_flip(&qtty->port); + tty_flip_buffer_push(&qtty->port); return IRQ_HANDLED; } =20 --- a/drivers/tty/moxa.c +++ b/drivers/tty/moxa.c @@ -1383,7 +1383,7 @@ static int moxa_poll_port(struct moxa_po if (inited && !tty_throttled(tty) && MoxaPortRxQueue(p) > 0) { /* RX */ MoxaPortReadData(p); - tty_schedule_flip(&p->port); + tty_flip_buffer_push(&p->port); } } else { clear_bit(EMPTYWAIT, &p->statusflags); @@ -1408,7 +1408,7 @@ static int moxa_poll_port(struct moxa_po =20 if (tty && (intr & IntrBreak) && !I_IGNBRK(tty)) { /* BREAK */ tty_insert_flip_char(&p->port, 0, TTY_BREAK); - tty_schedule_flip(&p->port); + tty_flip_buffer_push(&p->port); } =20 if (intr & IntrLine) --- a/drivers/tty/serial/lpc32xx_hs.c +++ b/drivers/tty/serial/lpc32xx_hs.c @@ -341,7 +341,7 @@ static irqreturn_t serial_lpc32xx_interr LPC32XX_HSUART_IIR(port->membase)); port->icount.overrun++; tty_insert_flip_char(tport, 0, TTY_OVERRUN); - tty_schedule_flip(tport); + tty_flip_buffer_push(tport); } =20 /* Data received? */ --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -324,13 +324,13 @@ int kbd_rate(struct kbd_repeat *rpt) static void put_queue(struct vc_data *vc, int ch) { tty_insert_flip_char(&vc->port, ch, 0); - tty_schedule_flip(&vc->port); + tty_flip_buffer_push(&vc->port); } =20 static void puts_queue(struct vc_data *vc, const char *cp) { tty_insert_flip_string(&vc->port, cp, strlen(cp)); - tty_schedule_flip(&vc->port); + tty_flip_buffer_push(&vc->port); } =20 static void applkey(struct vc_data *vc, int key, char mode) @@ -584,7 +584,7 @@ static void fn_inc_console(struct vc_dat static void fn_send_intr(struct vc_data *vc) { tty_insert_flip_char(&vc->port, 0, TTY_BREAK); - tty_schedule_flip(&vc->port); + tty_flip_buffer_push(&vc->port); } =20 static void fn_scroll_forw(struct vc_data *vc) --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1833,7 +1833,7 @@ static void csi_m(struct vc_data *vc) static void respond_string(const char *p, size_t len, struct tty_port *por= t) { tty_insert_flip_string(port, p, len); - tty_schedule_flip(port); + tty_flip_buffer_push(port); } =20 static void cursor_report(struct vc_data *vc, struct tty_struct *tty) From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C70CC19F2B for ; Wed, 27 Jul 2022 17:23:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235333AbiG0RXe (ORCPT ); Wed, 27 Jul 2022 13:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241920AbiG0RWw (ORCPT ); Wed, 27 Jul 2022 13:22:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7488D71705; Wed, 27 Jul 2022 09:45:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 87E27B8200D; Wed, 27 Jul 2022 16:45:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6C6BC433C1; Wed, 27 Jul 2022 16:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940336; bh=tfSNXRv4yqw1SkN0l+CRvzEBIXcTpg4fxT2kkmH1BAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mu//rNjnKv91BdkgCAHefU+0YivpM8v3XpPJ5Nq7YxppDeW8+Gv/ioZ9Q1YJ5ZHqF xElVqPWpnlFEZoALFgXdtvL0BNPhbVUw4YlH/74zSE2NdIILxw4tZoQucFCY4jwXa4 /juvkwPC2R1Jf9YwdgX8iWwlBckFN8uwsWIxOZAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Henderson , Ivan Kokshaysky , Matt Turner , William Hubbs , Chris Brannon , Kirk Reiser , Samuel Thibault , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Johan Hovold , Jiri Slaby Subject: [PATCH 5.15 189/201] tty: the rest, stop using tty_schedule_flip() Date: Wed, 27 Jul 2022 18:11:33 +0200 Message-Id: <20220727161035.599193527@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jiri Slaby commit b68b914494df4f79b4e9b58953110574af1cb7a2 upstream. Since commit a9c3f68f3cd8d (tty: Fix low_latency BUG) in 2014, tty_flip_buffer_push() is only a wrapper to tty_schedule_flip(). We are going to remove the latter (as it is used less), so call the former in the rest of the users. Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: William Hubbs Cc: Chris Brannon Cc: Kirk Reiser Cc: Samuel Thibault Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger Cc: Alexander Gordeev Reviewed-by: Johan Hovold Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20211122111648.30379-3-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/alpha/kernel/srmcons.c | 2 +- drivers/accessibility/speakup/spk_ttyio.c | 4 ++-- drivers/s390/char/keyboard.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) --- a/arch/alpha/kernel/srmcons.c +++ b/arch/alpha/kernel/srmcons.c @@ -59,7 +59,7 @@ srmcons_do_receive_chars(struct tty_port } while((result.bits.status & 1) && (++loops < 10)); =20 if (count) - tty_schedule_flip(port); + tty_flip_buffer_push(port); =20 return count; } --- a/drivers/accessibility/speakup/spk_ttyio.c +++ b/drivers/accessibility/speakup/spk_ttyio.c @@ -88,7 +88,7 @@ static int spk_ttyio_receive_buf2(struct } =20 if (!ldisc_data->buf_free) - /* ttyio_in will tty_schedule_flip */ + /* ttyio_in will tty_flip_buffer_push */ return 0; =20 /* Make sure the consumer has read buf before we have seen @@ -312,7 +312,7 @@ static unsigned char ttyio_in(struct spk mb(); ldisc_data->buf_free =3D true; /* Let TTY push more characters */ - tty_schedule_flip(tty->port); + tty_flip_buffer_push(tty->port); =20 return rv; } --- a/drivers/s390/char/keyboard.h +++ b/drivers/s390/char/keyboard.h @@ -56,7 +56,7 @@ static inline void kbd_put_queue(struct tty_port *port, int ch) { tty_insert_flip_char(port, ch, 0); - tty_schedule_flip(port); + tty_flip_buffer_push(port); } =20 static inline void @@ -64,5 +64,5 @@ kbd_puts_queue(struct tty_port *port, ch { while (*cp) tty_insert_flip_char(port, *cp++, 0); - tty_schedule_flip(port); + tty_flip_buffer_push(port); } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F1EDC04A68 for ; Wed, 27 Jul 2022 17:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242045AbiG0RXp (ORCPT ); Wed, 27 Jul 2022 13:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242008AbiG0RW6 (ORCPT ); Wed, 27 Jul 2022 13:22:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AD197AB02; Wed, 27 Jul 2022 09:45:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 94F5561561; Wed, 27 Jul 2022 16:45:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FB81C433D6; Wed, 27 Jul 2022 16:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940339; bh=vTiLwE0dkZkmLTjWT9JEPftwV50J2xM5ZrnPnwkywy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PiXj7e11cQ0bu71s/SvF0X2mnysvYsu5smg0vZntc3reH+/zyoj/03VrjciUf6r4/ 3ZVlFZxetjyW+Di9PI/5bAulembE1AQTri5gzZxaRnQmRdMOjhBJRJ2S8633dqlydn Fobs72vv5Assl9KS+YmuNPi9beTBHzr5OJgpiwgU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold , Jiri Slaby Subject: [PATCH 5.15 190/201] tty: drop tty_schedule_flip() Date: Wed, 27 Jul 2022 18:11:34 +0200 Message-Id: <20220727161035.639661748@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jiri Slaby commit 5db96ef23bda6c2a61a51693c85b78b52d03f654 upstream. Since commit a9c3f68f3cd8d (tty: Fix low_latency BUG) in 2014, tty_flip_buffer_push() is only a wrapper to tty_schedule_flip(). All users were converted in the previous patches, so remove tty_schedule_flip() completely while inlining its body into tty_flip_buffer_push(). One less exported function. Reviewed-by: Johan Hovold Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20211122111648.30379-4-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/tty/tty_buffer.c | 30 ++++++++---------------------- include/linux/tty_flip.h | 1 - 2 files changed, 8 insertions(+), 23 deletions(-) --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -403,27 +403,6 @@ int __tty_insert_flip_char(struct tty_po EXPORT_SYMBOL(__tty_insert_flip_char); =20 /** - * tty_schedule_flip - push characters to ldisc - * @port: tty port to push from - * - * Takes any pending buffers and transfers their ownership to the - * ldisc side of the queue. It then schedules those characters for - * processing by the line discipline. - */ - -void tty_schedule_flip(struct tty_port *port) -{ - struct tty_bufhead *buf =3D &port->buf; - - /* paired w/ acquire in flush_to_ldisc(); ensures - * flush_to_ldisc() sees buffer data. - */ - smp_store_release(&buf->tail->commit, buf->tail->used); - queue_work(system_unbound_wq, &buf->work); -} -EXPORT_SYMBOL(tty_schedule_flip); - -/** * tty_prepare_flip_string - make room for characters * @port: tty port * @chars: return pointer for character write area @@ -567,7 +546,14 @@ static void flush_to_ldisc(struct work_s =20 void tty_flip_buffer_push(struct tty_port *port) { - tty_schedule_flip(port); + struct tty_bufhead *buf =3D &port->buf; + + /* + * Paired w/ acquire in flush_to_ldisc(); ensures flush_to_ldisc() sees + * buffer data. + */ + smp_store_release(&buf->tail->commit, buf->tail->used); + queue_work(system_unbound_wq, &buf->work); } EXPORT_SYMBOL(tty_flip_buffer_push); =20 --- a/include/linux/tty_flip.h +++ b/include/linux/tty_flip.h @@ -17,7 +17,6 @@ extern int tty_insert_flip_string_fixed_ extern int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars, size_t size); extern void tty_flip_buffer_push(struct tty_port *port); -void tty_schedule_flip(struct tty_port *port); int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char f= lag); =20 static inline int tty_insert_flip_char(struct tty_port *port, From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F846C04A68 for ; Wed, 27 Jul 2022 17:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbiG0RYH (ORCPT ); Wed, 27 Jul 2022 13:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241218AbiG0RXZ (ORCPT ); Wed, 27 Jul 2022 13:23:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EBE57AB37; Wed, 27 Jul 2022 09:45:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0C83CB821D4; Wed, 27 Jul 2022 16:45:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CDD8C433D6; Wed, 27 Jul 2022 16:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940344; bh=ldw96dGsFJ0B4MSp/TdyOqJFrUeIP3kEdt1tO4sswc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZOW4IUiowWkmXexR0vyWCFRr33ehVMMqRt3/YYN0dtZNJ4mA+ljUKCu2En9A+1WtN 9RAMmAnA+Np4mALGOQQKqmXonwU+/TpK5f0pdYiyqifl6Sxekh76Xo+evdZRc8yhj4 PcWIWgGkOT73OQy4NEkGGglZ+5Jce5RJD9T9x3is= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hillf Danton , =?UTF-8?q?=E4=B8=80=E5=8F=AA=E7=8B=97?= , Dan Carpenter , Jiri Slaby Subject: [PATCH 5.15 191/201] tty: extract tty_flip_buffer_commit() from tty_flip_buffer_push() Date: Wed, 27 Jul 2022 18:11:35 +0200 Message-Id: <20220727161035.683750816@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Slaby commit 716b10580283fda66f2b88140e3964f8a7f9da89 upstream. We will need this new helper in the next patch. Cc: Hillf Danton Cc: =E4=B8=80=E5=8F=AA=E7=8B=97 Cc: Dan Carpenter Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20220707082558.9250-1-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/tty/tty_buffer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -533,6 +533,15 @@ static void flush_to_ldisc(struct work_s =20 } =20 +static inline void tty_flip_buffer_commit(struct tty_buffer *tail) +{ + /* + * Paired w/ acquire in flush_to_ldisc(); ensures flush_to_ldisc() sees + * buffer data. + */ + smp_store_release(&tail->commit, tail->used); +} + /** * tty_flip_buffer_push - terminal * @port: tty port to push @@ -548,11 +557,7 @@ void tty_flip_buffer_push(struct tty_por { struct tty_bufhead *buf =3D &port->buf; =20 - /* - * Paired w/ acquire in flush_to_ldisc(); ensures flush_to_ldisc() sees - * buffer data. - */ - smp_store_release(&buf->tail->commit, buf->tail->used); + tty_flip_buffer_commit(buf->tail); queue_work(system_unbound_wq, &buf->work); } EXPORT_SYMBOL(tty_flip_buffer_push); From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE10DC19F28 for ; Wed, 27 Jul 2022 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242091AbiG0RYQ (ORCPT ); Wed, 27 Jul 2022 13:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242029AbiG0RX1 (ORCPT ); Wed, 27 Jul 2022 13:23:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F6FD7AC03; Wed, 27 Jul 2022 09:45:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2CFB860D38; Wed, 27 Jul 2022 16:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35E5CC433D7; Wed, 27 Jul 2022 16:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940347; bh=tERZppFqcEhedvwOcLJyBDztk0AV46GCOnRXiuvGQrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gy5SWLPIsiPgZHr/SjqoQ2yEfk2zmk2GERGX8Dv0XjGiJS0gKvgTCvPZAd+nT3X1r gbam32LF303l2uW4uGf4KWITtSQoquKO8MFCEyu+4gL5M+LOqXhV4W9jVyMpIGRM2l 40W8th61ByYzft+O8nKLkgBg68SLywktF7+GPnFs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?=E4=B8=80=E5=8F=AA=E7=8B=97?= , Dan Carpenter , Hillf Danton , Jiri Slaby Subject: [PATCH 5.15 192/201] tty: use new tty_insert_flip_string_and_push_buffer() in pty_write() Date: Wed, 27 Jul 2022 18:11:36 +0200 Message-Id: <20220727161035.722436889@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Slaby commit a501ab75e7624d133a5a3c7ec010687c8b961d23 upstream. There is a race in pty_write(). pty_write() can be called in parallel with e.g. ioctl(TIOCSTI) or ioctl(TCXONC) which also inserts chars to the buffer. Provided, tty_flip_buffer_push() in pty_write() is called outside the lock, it can commit inconsistent tail. This can lead to out of bounds writes and other issues. See the Link below. To fix this, we have to introduce a new helper called tty_insert_flip_string_and_push_buffer(). It does both tty_insert_flip_string() and tty_flip_buffer_commit() under the port lock. It also calls queue_work(), but outside the lock. See 71a174b39f10 (pty: do tty_flip_buffer_push without port->lock in pty_write) for the reasons. Keep the helper internal-only (in drivers' tty.h). It is not intended to be used widely. Link: https://seclists.org/oss-sec/2022/q2/155 Fixes: 71a174b39f10 (pty: do tty_flip_buffer_push without port->lock in pty= _write) Cc: =E4=B8=80=E5=8F=AA=E7=8B=97 Cc: Dan Carpenter Suggested-by: Hillf Danton Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20220707082558.9250-2-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/tty/pty.c | 14 ++------------ drivers/tty/tty.h | 3 +++ drivers/tty/tty_buffer.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -111,21 +111,11 @@ static void pty_unthrottle(struct tty_st static int pty_write(struct tty_struct *tty, const unsigned char *buf, int= c) { struct tty_struct *to =3D tty->link; - unsigned long flags; =20 - if (tty->flow.stopped) + if (tty->flow.stopped || !c) return 0; =20 - if (c > 0) { - spin_lock_irqsave(&to->port->lock, flags); - /* Stuff the data into the input queue of the other end */ - c =3D tty_insert_flip_string(to->port, buf, c); - spin_unlock_irqrestore(&to->port->lock, flags); - /* And shovel */ - if (c) - tty_flip_buffer_push(to->port); - } - return c; + return tty_insert_flip_string_and_push_buffer(to->port, buf, c); } =20 /** --- a/drivers/tty/tty.h +++ b/drivers/tty/tty.h @@ -111,4 +111,7 @@ static inline void tty_audit_tiocsti(str =20 ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *); =20 +int tty_insert_flip_string_and_push_buffer(struct tty_port *port, + const unsigned char *chars, size_t cnt); + #endif --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -563,6 +563,37 @@ void tty_flip_buffer_push(struct tty_por EXPORT_SYMBOL(tty_flip_buffer_push); =20 /** + * tty_insert_flip_string_and_push_buffer - add characters to the tty buff= er and + * push + * @port: tty port + * @chars: characters + * @size: size + * + * The function combines tty_insert_flip_string() and tty_flip_buffer_push= () + * with the exception of properly holding the @port->lock. + * + * To be used only internally (by pty currently). + * + * Returns: the number added. + */ +int tty_insert_flip_string_and_push_buffer(struct tty_port *port, + const unsigned char *chars, size_t size) +{ + struct tty_bufhead *buf =3D &port->buf; + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + size =3D tty_insert_flip_string(port, chars, size); + if (size) + tty_flip_buffer_commit(buf->tail); + spin_unlock_irqrestore(&port->lock, flags); + + queue_work(system_unbound_wq, &buf->work); + + return size; +} + +/** * tty_buffer_init - prepare a tty buffer structure * @port: tty port to initialise * From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9A98C04A68 for ; Wed, 27 Jul 2022 17:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230238AbiG0RZJ (ORCPT ); Wed, 27 Jul 2022 13:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241993AbiG0RX3 (ORCPT ); Wed, 27 Jul 2022 13:23:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A2837AC13; Wed, 27 Jul 2022 09:45:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0A309601D2; Wed, 27 Jul 2022 16:45:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17624C433C1; Wed, 27 Jul 2022 16:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940350; bh=/DE94iSpnRoKGxTdCHkKpVV3Z0O7VoGmiHYgXKyAVEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IU+XamX5uo25avdv9UNm0on2dEVs22+posL+caI7sy0qQTqBds2CF5/GkKYPwfASC GmrWemztMBz3IrvcHxm6zyqqZJUsDj2KRWBMyZK8zNcAKHz2iPjOd/uIWOEXehx2Gc Ll53Q0fyBVNQ0YF1Uildd9gjTQoE1XGM7IlYbN+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jose Alonso , "David S. Miller" Subject: [PATCH 5.15 193/201] net: usb: ax88179_178a needs FLAG_SEND_ZLP Date: Wed, 27 Jul 2022 18:11:37 +0200 Message-Id: <20220727161035.761975836@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jose Alonso commit 36a15e1cb134c0395261ba1940762703f778438c upstream. The extra byte inserted by usbnet.c when (length % dev->maxpacket =3D=3D 0) is causing problems to device. This patch sets FLAG_SEND_ZLP to avoid this. Tested with: 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet Problems observed: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1) Using ssh/sshfs. The remote sshd daemon can abort with the message: "message authentication code incorrect" This happens because the tcp message sent is corrupted during the USB "Bulk out". The device calculate the tcp checksum and send a valid tcp message to the remote sshd. Then the encryption detects the error and aborts. 2) NETDEV WATCHDOG: ... (ax88179_178a): transmit queue 0 timed out 3) Stop normal work without any log message. The "Bulk in" continue receiving packets normally. The host sends "Bulk out" and the device responds with -ECONNRESET. (The netusb.c code tx_complete ignore -ECONNRESET) Under normal conditions these errors take days to happen and in intense usage take hours. A test with ping gives packet loss, showing that something is wrong: ping -4 -s 462 {destination} # 462 =3D 512 - 42 - 8 Not all packets fail. My guess is that the device tries to find another packet starting at the extra byte and will fail or not depending on the next bytes (old buffer content). =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Signed-off-by: Jose Alonso Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/net/usb/ax88179_178a.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -1796,7 +1796,7 @@ static const struct driver_info ax88179_ .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1809,7 +1809,7 @@ static const struct driver_info ax88178a .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1822,7 +1822,7 @@ static const struct driver_info cypress_ .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1835,7 +1835,7 @@ static const struct driver_info dlink_du .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1848,7 +1848,7 @@ static const struct driver_info sitecom_ .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1861,7 +1861,7 @@ static const struct driver_info samsung_ .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1874,7 +1874,7 @@ static const struct driver_info lenovo_i .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1887,7 +1887,7 @@ static const struct driver_info belkin_i .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1900,7 +1900,7 @@ static const struct driver_info toshiba_ .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; @@ -1913,7 +1913,7 @@ static const struct driver_info mct_info .link_reset =3D ax88179_link_reset, .reset =3D ax88179_reset, .stop =3D ax88179_stop, - .flags =3D FLAG_ETHER | FLAG_FRAMING_AX, + .flags =3D FLAG_ETHER | FLAG_FRAMING_AX | FLAG_SEND_ZLP, .rx_fixup =3D ax88179_rx_fixup, .tx_fixup =3D ax88179_tx_fixup, }; From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0B04C19F2C for ; Wed, 27 Jul 2022 17:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238094AbiG0RZO (ORCPT ); Wed, 27 Jul 2022 13:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232621AbiG0RXu (ORCPT ); Wed, 27 Jul 2022 13:23:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F6537AC39; Wed, 27 Jul 2022 09:45:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6E88600BE; Wed, 27 Jul 2022 16:45:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C78CFC4314E; Wed, 27 Jul 2022 16:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940353; bh=Fu+RQZP2lBIVjrGU4m9Qhg1VGiP+0En1tD5IuKWsy6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UUwdUa7oDJdFxOucTc1dWM/2pSfx1/Qyu2e7Lq830lI1Dk0+ugcm1gKdQS2oXAJoO t6Z4WkVy4Hj+6SEKsiA4ka33Rw8GFT5saBrv41o1s3k5FQWd7En/kZzixUlnVu29dx /njQ6NOFlz2oMqVQr0/LKGX/B1mJSE+b3qyrP1fQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sedat Dilek , Linus Torvalds Subject: [PATCH 5.15 194/201] watch-queue: remove spurious double semicolon Date: Wed, 27 Jul 2022 18:11:38 +0200 Message-Id: <20220727161035.807389817@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Linus Torvalds commit 44e29e64cf1ac0cffb152e0532227ea6d002aa28 upstream. Sedat Dilek noticed that I had an extraneous semicolon at the end of a line in the previous patch. It's harmless, but unintentional, and while compilers just treat it as an extra empty statement, for all I know some other tooling might warn about it. So clean it up before other people notice too ;) Fixes: 353f7988dd84 ("watchqueue: make sure to serialize 'wqueue->defunct' = properly") Reported-by: Sedat Dilek Signed-off-by: Linus Torvalds Reported-by: Sedat Dilek Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- kernel/watch_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -227,7 +227,7 @@ void __post_watch_notification(struct wa =20 if (lock_wqueue(wqueue)) { post_one_notification(wqueue, n); - unlock_wqueue(wqueue);; + unlock_wqueue(wqueue); } } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED2C1C04A68 for ; Wed, 27 Jul 2022 17:25:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241951AbiG0RZZ (ORCPT ); Wed, 27 Jul 2022 13:25:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241817AbiG0RX6 (ORCPT ); Wed, 27 Jul 2022 13:23:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABB687B1DB; Wed, 27 Jul 2022 09:46:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 20668B821D6; Wed, 27 Jul 2022 16:45:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75E79C433D6; Wed, 27 Jul 2022 16:45:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940355; bh=q8Ov8be4qwisSLNLiF3Apy5coHceXShTJRLQIfONrDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=drQAAgXWKcq+GzrPaJx/syqcYXxegbLs1SgdInqi+UrqAC6V8bA8eRYwz8nKgJEC8 mkpyunXFadYyZ3KKC5EqdljZpL236vOCAS9joLGC+GQcMEq/96z/Dp6A9dP4KmkWEU YDfgCBlZZQ+XTtM69BIi/jl0MAmACRoov7dwZgbM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jude Shih , Anson Jacob , Daniel Wheeler , Nicholas Kazlauskas , Alex Deucher Subject: [PATCH 5.15 195/201] drm/amd/display: Dont lock connection_mutex for DMUB HPD Date: Wed, 27 Jul 2022 18:11:39 +0200 Message-Id: <20220727161035.852969586@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Nicholas Kazlauskas commit d82b3266ef88dc10fe0e7031b2bd8ba7eedb7e59 upstream. [Why] Per DRM spec we only need to hold that lock when touching connector->state - which we do not do in that handler. Taking this locking introduces unnecessary dependencies with other threads which is bad for performance and opens up the potential for a deadlock since there are multiple locks being held at once. [How] Remove the connection_mutex lock/unlock routine and just iterate over the drm connectors normally. The iter helpers implicitly lock the connection list so this is safe to do. DC link access also does not need to be guarded since the link table is static at creation - we don't dynamically add or remove links, just streams. Fixes: e27c41d5b068 ("drm/amd/display: Support for DMUB HPD interrupt handl= ing") Reviewed-by: Jude Shih Acked-by: Anson Jacob Tested-by: Daniel Wheeler Signed-off-by: Nicholas Kazlauskas Signed-off-by: Alex Deucher Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ---- 1 file changed, 4 deletions(-) --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -668,10 +668,7 @@ void dmub_hpd_callback(struct amdgpu_dev return; } =20 - drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); - link_index =3D notify->link_index; - link =3D adev->dm.dc->links[link_index]; =20 drm_connector_list_iter_begin(dev, &iter); @@ -684,7 +681,6 @@ void dmub_hpd_callback(struct amdgpu_dev } } drm_connector_list_iter_end(&iter); - drm_modeset_unlock(&dev->mode_config.connection_mutex); =20 } From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB4B1C04A68 for ; Wed, 27 Jul 2022 17:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241491AbiG0RZX (ORCPT ); Wed, 27 Jul 2022 13:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241820AbiG0RX6 (ORCPT ); Wed, 27 Jul 2022 13:23:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91C5F5F13F; Wed, 27 Jul 2022 09:46:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0123BB821BA; Wed, 27 Jul 2022 16:46:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4408AC433D6; Wed, 27 Jul 2022 16:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940358; bh=cy4gpRA98YLj8Iyj6Bl+z9CYy3YNiqaOtdXfRIfQZKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XRj997LZjg/sid8Y45sUp1bcA121KfkfAJ6ub909ep5RhlzhptgR9tPvtzQBWsexB QwHWoVGKRRgAMtOvIqG4Wrjca8TELkHP1frklogU6x1KmnkzcD7NZur2ZyCSNMjP+L CrjM1qJYAxhEeophfElVC/AQapajT4rdaWF3/GeM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harry Wentland , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , Alex Deucher Subject: [PATCH 5.15 196/201] drm/amd/display: invalid parameter check in dmub_hpd_callback Date: Wed, 27 Jul 2022 18:11:40 +0200 Message-Id: <20220727161035.901178428@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jos=C3=A9 Exp=C3=B3sito commit 978ffac878fd64039f95798b15b430032d2d89d5 upstream. The function performs a check on the "adev" input parameter, however, it is used before the check. Initialize the "dev" variable after the sanity check to avoid a possible NULL pointer dereference. Fixes: e27c41d5b0681 ("drm/amd/display: Support for DMUB HPD interrupt hand= ling") Addresses-Coverity-ID: 1493909 ("Null pointer dereference") Reviewed-by: Harry Wentland Signed-off-by: Jos=C3=A9 Exp=C3=B3sito Signed-off-by: Alex Deucher Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -653,7 +653,7 @@ void dmub_hpd_callback(struct amdgpu_dev struct drm_connector_list_iter iter; struct dc_link *link; uint8_t link_index =3D 0; - struct drm_device *dev =3D adev->dm.ddev; + struct drm_device *dev; =20 if (adev =3D=3D NULL) return; @@ -670,6 +670,7 @@ void dmub_hpd_callback(struct amdgpu_dev =20 link_index =3D notify->link_index; link =3D adev->dm.dc->links[link_index]; + dev =3D adev->dm.ddev; =20 drm_connector_list_iter_begin(dev, &iter); drm_for_each_connector_iter(connector, &iter) { From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61733C04A68 for ; Wed, 27 Jul 2022 17:25:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240168AbiG0RZa (ORCPT ); Wed, 27 Jul 2022 13:25:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237123AbiG0RYA (ORCPT ); Wed, 27 Jul 2022 13:24:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2049D7B1E6; Wed, 27 Jul 2022 09:46:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DB47E60DDB; Wed, 27 Jul 2022 16:46:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E884FC433D6; Wed, 27 Jul 2022 16:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940361; bh=gvB9qFkp5oTwRe9KAeYPBcwDLw972dcraVKHBnGj8A8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UwdtsLiQoct0rlXj4k2A/OUHMDlnMeLYzm4ghbKvgwBe2DmmrMbTPsUEE1DpsF9EB ny7EB7wAGTbegE31y9rwqzQGqSinXtAkLy1UroWg6f0JaVLeni7Q9L8amKE7BaMbUU r76isaXs/4UXtc37uKE0ioGrWL7ONbVaVVKXdCBM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bernardo Meurer Costa , Nick Desaulniers , "Peter Zijlstra (Intel)" , Nathan Chancellor Subject: [PATCH 5.15 197/201] x86/extable: Prefer local labels in .set directives Date: Wed, 27 Jul 2022 18:11:41 +0200 Message-Id: <20220727161035.940264257@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Nick Desaulniers commit 334865b2915c33080624e0d06f1c3e917036472c upstream. Bernardo reported an error that Nathan bisected down to (x86_64) defconfig+LTO_CLANG_FULL+X86_PMEM_LEGACY. LTO vmlinux.o ld.lld: error: :1:13: redefinition of 'found' .set found, 0 ^ :29:1: while in macro instantiation extable_type_reg reg=3D%eax, type=3D(17 | ((0) << 16)) ^ This appears to be another LTO specific issue similar to what was folded into commit 4b5305decc84 ("x86/extable: Extend extable functionality"), where the `.set found, 0` in DEFINE_EXTABLE_TYPE_REG in arch/x86/include/asm/asm.h conflicts with the symbol for the static function `found` in arch/x86/kernel/pmem.c. Assembler .set directive declare symbols with global visibility, so the assembler may not rename such symbols in the event of a conflict. LTO could rename static functions if there was a conflict in C sources, but it cannot see into symbols defined in inline asm. The symbols are also retained in the symbol table, regardless of LTO. Give the symbols .L prefixes making them locally visible, so that they may be renamed for LTO to avoid conflicts, and to drop them from the symbol table regardless of LTO. Fixes: 4b5305decc84 ("x86/extable: Extend extable functionality") Reported-by: Bernardo Meurer Costa Debugged-by: Nathan Chancellor Signed-off-by: Nick Desaulniers Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor Link: https://lore.kernel.org/r/20220329202148.2379697-1-ndesaulniers@googl= e.com Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/asm.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/arch/x86/include/asm/asm.h +++ b/arch/x86/include/asm/asm.h @@ -149,24 +149,24 @@ =20 # define DEFINE_EXTABLE_TYPE_REG \ ".macro extable_type_reg type:req reg:req\n" \ - ".set found, 0\n" \ - ".set regnr, 0\n" \ + ".set .Lfound, 0\n" \ + ".set .Lregnr, 0\n" \ ".irp rs,rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15\n"= \ ".ifc \\reg, %%\\rs\n" \ - ".set found, found+1\n" \ - ".long \\type + (regnr << 8)\n" \ + ".set .Lfound, .Lfound+1\n" \ + ".long \\type + (.Lregnr << 8)\n" \ ".endif\n" \ - ".set regnr, regnr+1\n" \ + ".set .Lregnr, .Lregnr+1\n" \ ".endr\n" \ - ".set regnr, 0\n" \ + ".set .Lregnr, 0\n" \ ".irp rs,eax,ecx,edx,ebx,esp,ebp,esi,edi,r8d,r9d,r10d,r11d,r12d,r13d,r14d= ,r15d\n" \ ".ifc \\reg, %%\\rs\n" \ - ".set found, found+1\n" \ - ".long \\type + (regnr << 8)\n" \ + ".set .Lfound, .Lfound+1\n" \ + ".long \\type + (.Lregnr << 8)\n" \ ".endif\n" \ - ".set regnr, regnr+1\n" \ + ".set .Lregnr, .Lregnr+1\n" \ ".endr\n" \ - ".if (found !=3D 1)\n" \ + ".if (.Lfound !=3D 1)\n" \ ".error \"extable_type_reg: bad register argument\"\n" \ ".endif\n" \ ".endm\n" From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48F6AC04A68 for ; Wed, 27 Jul 2022 17:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242036AbiG0RZd (ORCPT ); Wed, 27 Jul 2022 13:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242135AbiG0RYb (ORCPT ); Wed, 27 Jul 2022 13:24:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F81F7B789; Wed, 27 Jul 2022 09:46:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4A101B821C5; Wed, 27 Jul 2022 16:46:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A684DC433C1; Wed, 27 Jul 2022 16:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940364; bh=Waml6J/VeBRBz7TwxuUTAlIY34ndmXwlkyv6V9eG/6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ztKNkuYEWiUvqUTW52jxn/84ccyrs7HMULRvc+PMdx64//zCxafCMsm2bgpgZj9MZ n7KP9NR+vEY5FHAP0Ekk3YB2RQM4tAE3U236Hkrcd0LNR9N+qbaOZACkhKdFXu6t1i srLGKHuNONFe6lK+KlzpgwTsrVphl9wVhw/3f7fo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Levitsky , Sean Christopherson , Vitaly Kuznetsov , Paolo Bonzini Subject: [PATCH 5.15 198/201] KVM: x86: fix typo in __try_cmpxchg_user causing non-atomicness Date: Wed, 27 Jul 2022 18:11:42 +0200 Message-Id: <20220727161035.989812551@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky commit 33fbe6befa622c082f7d417896832856814bdde0 upstream. This shows up as a TDP MMU leak when running nested. Non-working cmpxchg o= n L0 relies makes L1 install two different shadow pages under same spte, and one= of them is leaked. Fixes: 1c2361f667f36 ("KVM: x86: Use __try_cmpxchg_user() to emulate atomic= accesses") Signed-off-by: Maxim Levitsky Message-Id: <20220512101420.306759-1-mlevitsk@redhat.com> Reviewed-by: Sean Christopherson Reviewed-by: Vitaly Kuznetsov Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6933,7 +6933,7 @@ static int emulator_cmpxchg_emulated(str goto emul_write; =20 hva =3D kvm_vcpu_gfn_to_hva(vcpu, gpa_to_gfn(gpa)); - if (kvm_is_error_hva(addr)) + if (kvm_is_error_hva(hva)) goto emul_write; =20 hva +=3D offset_in_page(gpa); From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 065C8C04A68 for ; Wed, 27 Jul 2022 17:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242050AbiG0RZh (ORCPT ); Wed, 27 Jul 2022 13:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242127AbiG0RYa (ORCPT ); Wed, 27 Jul 2022 13:24:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9053E7B783; Wed, 27 Jul 2022 09:46:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 09BFFB821A6; Wed, 27 Jul 2022 16:46:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6732FC4314B; Wed, 27 Jul 2022 16:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940366; bh=hcMIUtGOhA2zAhTnvG6zDqVyHPDT5753U0ywcU6I810=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HJvSCjaqqTkuVx5TxRQgDiun9K1Cdpmjtg53atBJsYoEnUZfYMOdPRhdG0o0Hwa3u +D8elDzREEwIm4uptqU9kMVItP7sMyajxuMNwI0ykKvtHJQnwrTyDC3l6GhS0l1vxM l1v8o8J8MIM7RGsTNDvJ8SHfQqHnUn0mxA1Kp3LM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Beulich , Paolo Bonzini Subject: [PATCH 5.15 199/201] x86: drop bogus "cc" clobber from __try_cmpxchg_user_asm() Date: Wed, 27 Jul 2022 18:11:43 +0200 Message-Id: <20220727161036.039919451@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jan Beulich commit 1df931d95f4dc1c11db1123e85d4e08156e46ef9 upstream. As noted (and fixed) a couple of times in the past, "=3D@cc" outputs and clobbering of "cc" don't work well together. The compiler appears to mean to reject such, but doesn't - in its upstream form - quite manage to yet for "cc". Furthermore two similar macros don't clobber "cc", and clobbering "cc" is pointless in asm()-s for x86 anyway - the compiler always assumes status flags to be clobbered there. Fixes: 989b5db215a2 ("x86/uaccess: Implement macros for CMPXCHG on user add= resses") Signed-off-by: Jan Beulich Message-Id: <485c0c0b-a3a7-0b7c-5264-7d00c01de032@suse.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/include/asm/uaccess.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -471,7 +471,7 @@ do { \ [ptr] "+m" (*_ptr), \ [old] "+a" (__old) \ : [new] ltype (__new) \ - : "memory", "cc"); \ + : "memory"); \ if (unlikely(__err)) \ goto label; \ if (unlikely(!success)) \ From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA3A7C04A68 for ; Wed, 27 Jul 2022 17:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240356AbiG0RZm (ORCPT ); Wed, 27 Jul 2022 13:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242208AbiG0RYk (ORCPT ); Wed, 27 Jul 2022 13:24:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFDA67C1A3; Wed, 27 Jul 2022 09:46:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C686BB821BE; Wed, 27 Jul 2022 16:46:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24760C433C1; Wed, 27 Jul 2022 16:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940369; bh=shgkTiZDpmlnjyo4+9wTAq+VzpGLrb6OW/DecDopaRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2UVM6bzIW9HP7wtnqrw/XFfmTF91m2ZTlUKlQOJ6GQfHXaNRuUrYc7e3YbTqBDa0h WaJGjcis00Fgsj/BFh4VEuZ+XYaPVJB9vctkxPUhJ9OtioZ2Ilm6T3uQdfdQELAm1V CVOy1ap82MrwlHoeJMWi05r0D05F1FUOTCt3YPEs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harry Wentland , Dan Carpenter , Alex Deucher Subject: [PATCH 5.15 200/201] drm/amdgpu: Off by one in dm_dmub_outbox1_low_irq() Date: Wed, 27 Jul 2022 18:11:44 +0200 Message-Id: <20220727161036.086600544@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dan Carpenter commit a35faec3db0e13aac8ea720bc1a3503081dd5a3d upstream. The > ARRAY_SIZE() should be >=3D ARRAY_SIZE() to prevent an out of bounds access. Fixes: e27c41d5b068 ("drm/amd/display: Support for DMUB HPD interrupt handl= ing") Reviewed-by: Harry Wentland Signed-off-by: Dan Carpenter Signed-off-by: Alex Deucher Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -757,7 +757,7 @@ static void dm_dmub_outbox1_low_irq(void if (irq_params->irq_src =3D=3D DC_IRQ_SOURCE_DMCUB_OUTBOX) { do { dc_stat_get_dmub_notification(adev->dm.dc, ¬ify); - if (notify.type > ARRAY_SIZE(dm->dmub_thread_offload)) { + if (notify.type >=3D ARRAY_SIZE(dm->dmub_thread_offload)) { DRM_ERROR("DM: notify type %d larger than the array size %ld !", noti= fy.type, ARRAY_SIZE(dm->dmub_thread_offload)); continue; From nobody Wed Apr 15 02:54:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AC36C19F2C for ; Wed, 27 Jul 2022 17:26:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242032AbiG0R0F (ORCPT ); Wed, 27 Jul 2022 13:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242332AbiG0RYz (ORCPT ); Wed, 27 Jul 2022 13:24:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8097C7D1E2; Wed, 27 Jul 2022 09:46:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 246AAB8200C; Wed, 27 Jul 2022 16:46:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 878EFC433D6; Wed, 27 Jul 2022 16:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940374; bh=wNjRyq7KpwfqI2CRIrmBaDbajqCGVlD03RMmAjecJuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VcfGaEdZBeBM9ANRFJc9QirKQMp1kbT+7Wx1XGh0ocBAWYMG5YK4ZJ7fKbHVaw2n0 YtNbtarYOVFS6zdmsHTzor9IpOPOb+nwo91lTZ/a17JDUbc4kaLP/Bxn1PymIFhebB xGWD9hefAXcH33JKBnBDb8AMGjWz6MGxENRwXhnQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , "Peter Zijlstra (Intel)" , Borislav Petkov Subject: [PATCH 5.15 201/201] x86/entry_32: Fix segment exceptions Date: Wed, 27 Jul 2022 18:11:45 +0200 Message-Id: <20220727161036.135965948@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra commit 9cdbeec4096804083944d05da96bbaf59a1eb4f9 upstream. The LKP robot reported that commit in Fixes: caused a failure. Turns out the ldt_gdt_32 selftest turns into an infinite loop trying to clear the segment. As discovered by Sean, what happens is that PARANOID_EXIT_TO_KERNEL_MODE in the handle_exception_return path overwrites the entry stack data with the task stack data, restoring the "bad" segment value. Instead of having the exception retry the instruction, have it emulate the full instruction. Replace EX_TYPE_POP_ZERO with EX_TYPE_POP_REG which will do the equivalent of: POP %reg; MOV $imm, %reg. In order to encode the segment registers, add them as registers 8-11 for 32-bit. By setting regs->[defg]s the (nested) RESTORE_REGS will pop this value at the end of the exception handler and by increasing regs->sp, it will have skipped the stack slot. This was debugged by Sean Christopherson . [ bp: Add EX_REG_GS too. ] Fixes: aa93e2ad7464 ("x86/entry_32: Remove .fixup usage") Reported-by: kernel test robot Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/Yd1l0gInc4zRcnt/@hirez.programming.kicks-as= s.net Signed-off-by: Greg Kroah-Hartman Tested-by: Bagas Sanjaya Tested-by: Florian Fainelli Tested-by: Linux Kernel Functional Testing Tested-by: Shuah Khan --- arch/x86/entry/entry_32.S | 13 +++++++++---- arch/x86/include/asm/extable_fixup_types.h | 11 ++++++++++- arch/x86/lib/insn-eval.c | 5 +++++ arch/x86/mm/extable.c | 17 +++-------------- 4 files changed, 27 insertions(+), 19 deletions(-) --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -268,11 +268,16 @@ 1: popl %ds 2: popl %es 3: popl %fs - addl $(4 + \pop), %esp /* pop the unused "gs" slot */ +4: addl $(4 + \pop), %esp /* pop the unused "gs" slot */ IRET_FRAME - _ASM_EXTABLE_TYPE(1b, 1b, EX_TYPE_POP_ZERO) - _ASM_EXTABLE_TYPE(2b, 2b, EX_TYPE_POP_ZERO) - _ASM_EXTABLE_TYPE(3b, 3b, EX_TYPE_POP_ZERO) + + /* + * There is no _ASM_EXTABLE_TYPE_REG() for ASM, however since this is + * ASM the registers are known and we can trivially hard-code them. + */ + _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_POP_ZERO|EX_REG_DS) + _ASM_EXTABLE_TYPE(2b, 3b, EX_TYPE_POP_ZERO|EX_REG_ES) + _ASM_EXTABLE_TYPE(3b, 4b, EX_TYPE_POP_ZERO|EX_REG_FS) .endm =20 .macro RESTORE_ALL_NMI cr3_reg:req pop=3D0 --- a/arch/x86/include/asm/extable_fixup_types.h +++ b/arch/x86/include/asm/extable_fixup_types.h @@ -16,9 +16,16 @@ #define EX_DATA_FLAG_SHIFT 12 #define EX_DATA_IMM_SHIFT 16 =20 +#define EX_DATA_REG(reg) ((reg) << EX_DATA_REG_SHIFT) #define EX_DATA_FLAG(flag) ((flag) << EX_DATA_FLAG_SHIFT) #define EX_DATA_IMM(imm) ((imm) << EX_DATA_IMM_SHIFT) =20 +/* segment regs */ +#define EX_REG_DS EX_DATA_REG(8) +#define EX_REG_ES EX_DATA_REG(9) +#define EX_REG_FS EX_DATA_REG(10) +#define EX_REG_GS EX_DATA_REG(11) + /* flags */ #define EX_FLAG_CLEAR_AX EX_DATA_FLAG(1) #define EX_FLAG_CLEAR_DX EX_DATA_FLAG(2) @@ -41,7 +48,9 @@ #define EX_TYPE_RDMSR_IN_MCE 13 #define EX_TYPE_DEFAULT_MCE_SAFE 14 #define EX_TYPE_FAULT_MCE_SAFE 15 -#define EX_TYPE_POP_ZERO 16 + +#define EX_TYPE_POP_REG 16 /* sp +=3D sizeof(long) */ +#define EX_TYPE_POP_ZERO (EX_TYPE_POP_REG | EX_DATA_IMM(0)) =20 #define EX_TYPE_IMM_REG 17 /* reg :=3D (long)imm */ #define EX_TYPE_EFAULT_REG (EX_TYPE_IMM_REG | EX_DATA_IMM(-EFAULT)) --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -430,6 +430,11 @@ static const int pt_regoff[] =3D { offsetof(struct pt_regs, r13), offsetof(struct pt_regs, r14), offsetof(struct pt_regs, r15), +#else + offsetof(struct pt_regs, ds), + offsetof(struct pt_regs, es), + offsetof(struct pt_regs, fs), + offsetof(struct pt_regs, gs), #endif }; =20 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -118,18 +118,6 @@ static bool ex_handler_clear_fs(const st return ex_handler_default(fixup, regs); } =20 -static bool ex_handler_pop_zero(const struct exception_table_entry *fixup, - struct pt_regs *regs) -{ - /* - * Typically used for when "pop %seg" traps, in which case we'll clear - * the stack slot and re-try the instruction, which will then succeed - * to pop zero. - */ - *((unsigned long *)regs->sp) =3D 0; - return ex_handler_default(fixup, regs); -} - static bool ex_handler_imm_reg(const struct exception_table_entry *fixup, struct pt_regs *regs, int reg, int imm) { @@ -203,8 +191,9 @@ int fixup_exception(struct pt_regs *regs case EX_TYPE_RDMSR_IN_MCE: ex_handler_msr_mce(regs, false); break; - case EX_TYPE_POP_ZERO: - return ex_handler_pop_zero(e, regs); + case EX_TYPE_POP_REG: + regs->sp +=3D sizeof(long); + fallthrough; case EX_TYPE_IMM_REG: return ex_handler_imm_reg(e, regs, reg, imm); }