Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv: Optimize bitops with Zbb extension #49

Closed
wants to merge 1 commit into from

Conversation

bjoto
Copy link

@bjoto bjoto commented Sep 20, 2023

Pull request for series with
subject: riscv: Optimize bitops with Zbb extension
version: 2
url: https://patchwork.kernel.org/project/linux-riscv/list/?series=785828

@bjoto
Copy link
Author

bjoto commented Sep 20, 2023

Upstream branch: 8eb8fe6
series: https://patchwork.kernel.org/project/linux-riscv/list/?series=785828
version: 2

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/linux-riscv/list/?series=785828
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: riscv: Rearrange hwcap.h and cpufeature.h
Using index info to reconstruct a base tree...
M	arch/riscv/include/asm/cpufeature.h
M	arch/riscv/include/asm/hwcap.h
Falling back to patching base and 3-way merge...
Auto-merging arch/riscv/include/asm/hwcap.h
CONFLICT (content): Merge conflict in arch/riscv/include/asm/hwcap.h
Auto-merging arch/riscv/include/asm/cpufeature.h
Patch failed at 0001 riscv: Rearrange hwcap.h and cpufeature.h
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc arch/riscv/include/asm/hwcap.h
index b7b58258f6c7,141b7109c25c..000000000000
--- a/arch/riscv/include/asm/hwcap.h
+++ b/arch/riscv/include/asm/hwcap.h
@@@ -67,76 -64,4 +64,79 @@@
  #define RISCV_ISA_EXT_SxAIA		RISCV_ISA_EXT_SSAIA
  #endif
  
++<<<<<<< HEAD
 +#ifndef __ASSEMBLY__
 +
 +#include <linux/jump_label.h>
 +
 +unsigned long riscv_get_elf_hwcap(void);
 +
 +struct riscv_isa_ext_data {
 +	const unsigned int id;
 +	const char *name;
 +	const char *property;
 +};
 +
 +extern const struct riscv_isa_ext_data riscv_isa_ext[];
 +extern const size_t riscv_isa_ext_count;
 +extern bool riscv_isa_fallback;
 +
 +unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
 +
 +#define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext)
 +
 +bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit);
 +#define riscv_isa_extension_available(isa_bitmap, ext)	\
 +	__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
 +
 +static __always_inline bool
 +riscv_has_extension_likely(const unsigned long ext)
 +{
 +	compiletime_assert(ext < RISCV_ISA_EXT_MAX,
 +			   "ext must be < RISCV_ISA_EXT_MAX");
 +
 +	if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
 +		asm_volatile_goto(
 +		ALTERNATIVE("j	%l[l_no]", "nop", 0, %[ext], 1)
 +		:
 +		: [ext] "i" (ext)
 +		:
 +		: l_no);
 +	} else {
 +		if (!__riscv_isa_extension_available(NULL, ext))
 +			goto l_no;
 +	}
 +
 +	return true;
 +l_no:
 +	return false;
 +}
 +
 +static __always_inline bool
 +riscv_has_extension_unlikely(const unsigned long ext)
 +{
 +	compiletime_assert(ext < RISCV_ISA_EXT_MAX,
 +			   "ext must be < RISCV_ISA_EXT_MAX");
 +
 +	if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
 +		asm_volatile_goto(
 +		ALTERNATIVE("nop", "j	%l[l_yes]", 0, %[ext], 1)
 +		:
 +		: [ext] "i" (ext)
 +		:
 +		: l_yes);
 +	} else {
 +		if (__riscv_isa_extension_available(NULL, ext))
 +			goto l_yes;
 +	}
 +
 +	return false;
 +l_yes:
 +	return true;
 +}
 +
 +#endif
 +
++=======
++>>>>>>> riscv: Rearrange hwcap.h and cpufeature.h
  #endif /* _ASM_RISCV_HWCAP_H */

@bjoto bjoto force-pushed the fixes_base branch 2 times, most recently from bf0d912 to 251d44a Compare September 21, 2023 10:46
@bjoto bjoto added V3 and removed V2 labels Sep 26, 2023
@bjoto bjoto force-pushed the fixes_base branch 2 times, most recently from 93cfc25 to 44ed8c6 Compare October 4, 2023 15:27
@bjoto bjoto force-pushed the fixes_base branch 5 times, most recently from e91e31a to 06d5bb0 Compare October 17, 2023 15:11
@bjoto bjoto added V4 and removed V3 labels Oct 30, 2023
@bjoto
Copy link
Author

bjoto commented Oct 31, 2023

At least one diff in series https://patchwork.kernel.org/project/linux-riscv/list/?series=797472 expired. Closing PR.

@bjoto bjoto closed this Oct 31, 2023
@bjoto bjoto deleted the series/785828=>fixes branch November 2, 2023 06:42
bjoto pushed a commit that referenced this pull request Mar 13, 2024
bnxt_alloc_mem() dereferences ::vnic_info in the variable declaration
block, but allocates it much later. As a result, the following crash
happens on my setup:

 BUG: kernel NULL pointer dereference, address: 0000000000000090
 fbcon: Taking over console
 #PF: supervisor write access in kernel mode
 #PF: error_code (0x0002) - not-present page
 PGD 12f382067 P4D 0
 Oops: 8002 [#1] PREEMPT SMP NOPTI
 CPU: 47 PID: 2516 Comm: NetworkManager Not tainted 6.8.0-rc5-libeth+ #49
 Hardware name: Intel Corporation M50CYP2SBSTD/M58CYP2SBSTD, BIOS SE5C620.86B.01.01.0088.2305172341 05/17/2023
 RIP: 0010:bnxt_alloc_mem+0x1609/0x1910 [bnxt_en]
 Code: 81 c8 48 83 c8 08 31 c9 e9 d7 fe ff ff c7 44 24 Oc 00 00 00 00 49 89 d5 e9 2d fe ff ff 41 89 c6 e9 88 00 00 00 48 8b 44 24 50 <80> 88 90 00 00 00 Od 8b 43 74 a8 02 75 1e f6 83 14 02 00 00 80 74
 RSP: 0018:ff3f25580f3432c8 EFLAGS: 00010246
 RAX: 0000000000000000 RBX: ff15a5cfc45249e0 RCX: 0000002079777000
 RDX: ff15a5dfb9767000 RSI: 0000000000000000 RDI: 0000000000000000
 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
 R10: ff15a5dfb9777000 R11: ffffff8000000000 R12: 0000000000000000
 R13: 0000000000000000 R14: 0000000000000020 R15: ff15a5cfce34f540
 FS:  000007fb9a160500(0000) GS:ff15a5dfbefc0000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CRO: 0000000080050033
 CR2: 0000000000000090 CR3: 0000000109efc00Z CR4: 0000000000771ef0
 DR0: 0000000000000000 DR1: 0000000000000000 DRZ: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
 PKRU: 55555554

 Call Trace:
 <TASK>
 ? __die_body+0x68/0xb0
 ? page_fault_oops+0x3a6/0x400
 ? exc_page_fault+0x7a/0x1b0
 ? asm_exc_page_fault+0x26/8x30
 ? bnxt_alloc_mem+0x1609/0x1910 [bnxt_en]
 ? bnxt_alloc_mem+0x1389/8x1918 [bnxt_en]
 _bnxt_open_nic+0x198/0xa50 [bnxt_en]
 ? bnxt_hurm_if_change+0x287/0x3d0 [bnxt_en]
 bnxt_open+0xeb/0x1b0 [bnxt_en]
 _dev_open+0x12e/0x1f0
 _dev_change_flags+0xb0/0x200
 dev_change_flags+0x25/0x60
 do_setlink+0x463/0x1260
 ? sock_def_readable+0x14/0xc0
 ? rtnl_getlink+0x4b9/0x590
 ? _nla_validate_parse+0x91/0xfa0
 rtnl_newlink+0xbac/0xe40
 <...>

Don't create a variable and dereference the first array member directly
since it's used only once in the code.

Fixes: ef4ee64 ("bnxt_en: Define BNXT_VNIC_DEFAULT for the default vnic index")
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Link: https://lore.kernel.org/r/20240226144911.1297336-1-aleksander.lobakin@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
bjoto pushed a commit that referenced this pull request Apr 26, 2024
If stack_depot_save_flags() allocates memory it always drops
__GFP_NOLOCKDEP flag.  So when KASAN tries to track __GFP_NOLOCKDEP
allocation we may end up with lockdep splat like bellow:

======================================================
 WARNING: possible circular locking dependency detected
 6.9.0-rc3+ #49 Not tainted
 ------------------------------------------------------
 kswapd0/149 is trying to acquire lock:
 ffff88811346a920
(&xfs_nondir_ilock_class){++++}-{4:4}, at: xfs_reclaim_inode+0x3ac/0x590
[xfs]

 but task is already holding lock:
 ffffffff8bb33100 (fs_reclaim){+.+.}-{0:0}, at:
balance_pgdat+0x5d9/0xad0

 which lock already depends on the new lock.

 the existing dependency chain (in reverse order) is:
 -> #1 (fs_reclaim){+.+.}-{0:0}:
        __lock_acquire+0x7da/0x1030
        lock_acquire+0x15d/0x400
        fs_reclaim_acquire+0xb5/0x100
 prepare_alloc_pages.constprop.0+0xc5/0x230
        __alloc_pages+0x12a/0x3f0
        alloc_pages_mpol+0x175/0x340
        stack_depot_save_flags+0x4c5/0x510
        kasan_save_stack+0x30/0x40
        kasan_save_track+0x10/0x30
        __kasan_slab_alloc+0x83/0x90
        kmem_cache_alloc+0x15e/0x4a0
        __alloc_object+0x35/0x370
        __create_object+0x22/0x90
 __kmalloc_node_track_caller+0x477/0x5b0
        krealloc+0x5f/0x110
        xfs_iext_insert_raw+0x4b2/0x6e0 [xfs]
        xfs_iext_insert+0x2e/0x130 [xfs]
        xfs_iread_bmbt_block+0x1a9/0x4d0 [xfs]
        xfs_btree_visit_block+0xfb/0x290 [xfs]
        xfs_btree_visit_blocks+0x215/0x2c0 [xfs]
        xfs_iread_extents+0x1a2/0x2e0 [xfs]
 xfs_buffered_write_iomap_begin+0x376/0x10a0 [xfs]
        iomap_iter+0x1d1/0x2d0
 iomap_file_buffered_write+0x120/0x1a0
        xfs_file_buffered_write+0x128/0x4b0 [xfs]
        vfs_write+0x675/0x890
        ksys_write+0xc3/0x160
        do_syscall_64+0x94/0x170
 entry_SYSCALL_64_after_hwframe+0x71/0x79

Always preserve __GFP_NOLOCKDEP to fix this.

Link: https://lkml.kernel.org/r/20240418141133.22950-1-ryabinin.a.a@gmail.com
Fixes: cd11016 ("mm, kasan: stackdepot implementation. Enable stackdepot for SLAB")
Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Reported-by: Xiubo Li <xiubli@redhat.com>
Closes: https://lore.kernel.org/all/a0caa289-ca02-48eb-9bf2-d86fd47b71f4@redhat.com/
Reported-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Closes: https://lore.kernel.org/all/f9ff999a-e170-b66b-7caf-293f2b147ac2@opensource.wdc.com/
Suggested-by: Dave Chinner <david@fromorbit.com>
Tested-by: Xiubo Li <xiubli@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant