Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp389867lqr; Wed, 5 Jun 2024 08:56:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX47jgp8SMK45scMpaHspI6xPh+Z+D9IFwX72mOeoUzxEwYpdgUVrdrGN67FxUZOvBmoDZf9R3hvtcybuzC9yv/EjzPqAFD0rJuLLRcmw== X-Google-Smtp-Source: AGHT+IFYAinTAGe67EQ5KNByuUvjhX8xtXXob9gOt4Tollkl51GVNSQdP7IK0J0rvN0ChzO/a9B+ X-Received: by 2002:a17:902:e801:b0:1f2:fe82:21e9 with SMTP id d9443c01a7336-1f6a5a6af43mr34234555ad.46.1717602988512; Wed, 05 Jun 2024 08:56:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717602988; cv=pass; d=google.com; s=arc-20160816; b=uuG/Zillk6vlLObUI8Y3JKq80HnmPgakQJpj0844Y/kgzpWrkreSSUU/YNZ/lhx9vS X2G0YzstK3S1sSTAeCawCzHFbuzFHepf646/pPAOAMYh6RTeVorCjfn085na5hxuRc1i MYV9sHn7QY8J1NgDIXnBiWWDjDvkWpZ+YjfVwcF6fVX58LTp2BOGltPhYH0fKmVcJ82p UOUe/Co65/Tgi0FM/wmycH9QerdCVse2MUCXK3LuZecj2hyQKCfFT67/1fsQzk7PnWbX ts9L+DtLpy3kXexFfGHjBryk/CZtm9yjveEoUH3RFolDOz+no5QvPqzLvIiZF4DkCkl0 P5dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8SLS2mVzgKo7z4DKJciMiqN7f3TQqan2EAaLyoLnxNQ=; fh=K9WwTcWfA/vnUUWKEtcdnVeqpoARKN6e8qCAhpfZrX0=; b=vassP1p3qkhFaJSs//gTxg8YZ5GGlYF79mjjJA/dfovgOkwCBRp/3UWddjS9HqIa5r jjRcvCeqPUcXIaU07e5CtH9yWgdexj0LdRfRoEFIsoLlL5bz3Q2k8xMny/jifUwZ+RjA j3CF+bSa2bbZjA3W9HfTQy8eKM19DocO2Mj0b+l0f/V2+BhlqvT7KWM3k7+Pc4mpuZZU mO1RS4x6duv4+9Eb0tUUOKpREcKfJXoYSv1VVFpv3uDMAJmadef4sA7lO6X90H88NiIm 6p37zVFZSlqImGdRXe/jQsFBzuqAQvgw/4T3BNx6TtAW/HUWizOcviLScNtadrFslsUz PZ/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DoNzVDCB; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-202828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202828-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f66c399a86si67087795ad.251.2024.06.05.08.56.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 08:56:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DoNzVDCB; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-202828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202828-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 71784B283E8 for ; Wed, 5 Jun 2024 15:25:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3C13482DB; Wed, 5 Jun 2024 15:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DoNzVDCB" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C64D720B20 for ; Wed, 5 Jun 2024 15:25:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717601117; cv=none; b=b7lji8bVsI06Kdvn4u6r9piuwV8DByDcQ1m3a2W80Iz+j+VY6F7Mz5T8drcuN/L3ONtXd4v+go1AyYInTyzMUwNluHlxJP/pve2Nj1X314eFuGPAMwYdZSv1rzBsTF8dp0K0ZmGTR7I8Q2lci2XYgSKBWKC+yprzHZ2HUCfMNa8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717601117; c=relaxed/simple; bh=kGdBQb9DP47D8JHH/7IbJAetPXS61ZW00e/eAYL9h1I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z8WDUVkOs/tDPHyeVVpmcctluLAsjU9vSB4IX7nxZdePWSw4sY2RswD2TivrHXsgP1vQlTbUhm4/nx4zWBHl9q6tdjoEJKDfnBahGnR6Gpwl9Cjg4+R6Rhr/SUdsHd5h4gyNi7N0+CAZQCMhfTkQBHgGc9OIziVjV4R3UUl/G9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DoNzVDCB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717601114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8SLS2mVzgKo7z4DKJciMiqN7f3TQqan2EAaLyoLnxNQ=; b=DoNzVDCBEG+6oaQRQN89rybbdyF+/aCWlnI0LU3/lXwCnb7lN+QMRAzqMNoEey9QsNQYkz 2phCndrwsC0Nej577RoCzTQmXiX5iiJ1Xo/MoxpsOuf6v34aaD8ZGgOC6jps8+5/D34COj ocNjhqJbLDO1HvAJ6Jri63lZAU74V5w= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-YHQSxMhbM8KyAxTaeLdr7A-1; Wed, 05 Jun 2024 11:25:11 -0400 X-MC-Unique: YHQSxMhbM8KyAxTaeLdr7A-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6af678b31b8so6858606d6.2 for ; Wed, 05 Jun 2024 08:25:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717601111; x=1718205911; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8SLS2mVzgKo7z4DKJciMiqN7f3TQqan2EAaLyoLnxNQ=; b=Ci2V/MpCC4m3HZ9drQb39AFjPZpiOvXZeTFiu3hG01htGpSQkCgiQsppv62BUqnv0p nADYmSqg2WGN+yrcxW1ihdLPUBFjI8k78QdkD7zuOoB6D6hefSi+Aklg2OthgF8PkBcI J9AA4R/bRgvGgx8//I+lXO36twd9p4BkCwlZahVASacEA6ZL2lxdVz65iOoadWotzS5E lQqopy8TZn+BiXFcfM7IhTAt7832+2W58SHpvEDgelhmQwtGSZF2WFakwPceSEs+I5MV V9/VEL6eouYR6k+Q/aO2jJz1nJo/Wfy3zaYfen0h9OEytbyNd508NJZUtXdEVK+hU3hD 4O6A== X-Forwarded-Encrypted: i=1; AJvYcCWPesO8os2/uQ5itSdU2/XHgOlxr61Iql2mumiO9JbvcUD0wo4ObdngXONCGtvDIspFpiP0aQzWY7PLOkqkKC5DVAbbtzv1r2p6RhXU X-Gm-Message-State: AOJu0Yynn/NAwwq9zwzkdaeoOxZsPM7bgBKxFVmxn/6pXecZ+VMYInsH lUhYUFejUmzLewwGgJqFaS33Bfx/c6b0nsNOfnxZQoRrvjQKmNHNK7K4JX/04HO/mkaLjplJmQ+ 0YuVNqpYfc4JiG9j1j5uzXc9y/u6bls4L82KyEGgpJgaki9d/3aoZN+VjBy/nKA== X-Received: by 2002:a05:620a:178a:b0:794:ef5d:9e92 with SMTP id af79cd13be357-79523fccf54mr261012185a.6.1717601110213; Wed, 05 Jun 2024 08:25:10 -0700 (PDT) X-Received: by 2002:a05:620a:178a:b0:794:ef5d:9e92 with SMTP id af79cd13be357-79523fccf54mr261007385a.6.1717601109404; Wed, 05 Jun 2024 08:25:09 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7951955c4f8sm131120585a.50.2024.06.05.08.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 08:25:08 -0700 (PDT) Date: Wed, 5 Jun 2024 11:25:07 -0400 From: Peter Xu To: Yang Shi Cc: oliver.sang@intel.com, paulmck@kernel.org, david@redhat.com, willy@infradead.org, riel@surriel.com, vivek.kasireddy@intel.com, cl@linux.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 1/2] mm: page_ref: remove folio_try_get_rcu() Message-ID: References: <20240604234858.948986-1-yang@os.amperecomputing.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240604234858.948986-1-yang@os.amperecomputing.com> On Tue, Jun 04, 2024 at 04:48:57PM -0700, Yang Shi wrote: > The below bug was reported on a non-SMP kernel: > > [ 275.267158][ T4335] ------------[ cut here ]------------ > [ 275.267949][ T4335] kernel BUG at include/linux/page_ref.h:275! > [ 275.268526][ T4335] invalid opcode: 0000 [#1] KASAN PTI > [ 275.269001][ T4335] CPU: 0 PID: 4335 Comm: trinity-c3 Not tainted 6.7.0-rc4-00061-gefa7df3e3bb5 #1 > [ 275.269787][ T4335] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 > [ 275.270679][ T4335] RIP: 0010:try_get_folio (include/linux/page_ref.h:275 (discriminator 3) mm/gup.c:79 (discriminator 3)) > [ 275.272813][ T4335] RSP: 0018:ffffc90005dcf650 EFLAGS: 00010202 > [ 275.273346][ T4335] RAX: 0000000000000246 RBX: ffffea00066e0000 RCX: 0000000000000000 > [ 275.274032][ T4335] RDX: fffff94000cdc007 RSI: 0000000000000004 RDI: ffffea00066e0034 > [ 275.274719][ T4335] RBP: ffffea00066e0000 R08: 0000000000000000 R09: fffff94000cdc006 > [ 275.275404][ T4335] R10: ffffea00066e0037 R11: 0000000000000000 R12: 0000000000000136 > [ 275.276106][ T4335] R13: ffffea00066e0034 R14: dffffc0000000000 R15: ffffea00066e0008 > [ 275.276790][ T4335] FS: 00007fa2f9b61740(0000) GS:ffffffff89d0d000(0000) knlGS:0000000000000000 > [ 275.277570][ T4335] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 275.278143][ T4335] CR2: 00007fa2f6c00000 CR3: 0000000134b04000 CR4: 00000000000406f0 > [ 275.278833][ T4335] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > [ 275.279521][ T4335] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > [ 275.280201][ T4335] Call Trace: > [ 275.280499][ T4335] > [ 275.280751][ T4335] ? die (arch/x86/kernel/dumpstack.c:421 arch/x86/kernel/dumpstack.c:434 arch/x86/kernel/dumpstack.c:447) > [ 275.281087][ T4335] ? do_trap (arch/x86/kernel/traps.c:112 arch/x86/kernel/traps.c:153) > [ 275.281463][ T4335] ? try_get_folio (include/linux/page_ref.h:275 (discriminator 3) mm/gup.c:79 (discriminator 3)) > [ 275.281884][ T4335] ? try_get_folio (include/linux/page_ref.h:275 (discriminator 3) mm/gup.c:79 (discriminator 3)) > [ 275.282300][ T4335] ? do_error_trap (arch/x86/kernel/traps.c:174) > [ 275.282711][ T4335] ? try_get_folio (include/linux/page_ref.h:275 (discriminator 3) mm/gup.c:79 (discriminator 3)) > [ 275.283129][ T4335] ? handle_invalid_op (arch/x86/kernel/traps.c:212) > [ 275.283561][ T4335] ? try_get_folio (include/linux/page_ref.h:275 (discriminator 3) mm/gup.c:79 (discriminator 3)) > [ 275.283990][ T4335] ? exc_invalid_op (arch/x86/kernel/traps.c:264) > [ 275.284415][ T4335] ? asm_exc_invalid_op (arch/x86/include/asm/idtentry.h:568) > [ 275.284859][ T4335] ? try_get_folio (include/linux/page_ref.h:275 (discriminator 3) mm/gup.c:79 (discriminator 3)) > [ 275.285278][ T4335] try_grab_folio (mm/gup.c:148) > [ 275.285684][ T4335] __get_user_pages (mm/gup.c:1297 (discriminator 1)) > [ 275.286111][ T4335] ? __pfx___get_user_pages (mm/gup.c:1188) > [ 275.286579][ T4335] ? __pfx_validate_chain (kernel/locking/lockdep.c:3825) > [ 275.287034][ T4335] ? mark_lock (kernel/locking/lockdep.c:4656 (discriminator 1)) > [ 275.287416][ T4335] __gup_longterm_locked (mm/gup.c:1509 mm/gup.c:2209) > [ 275.288192][ T4335] ? __pfx___gup_longterm_locked (mm/gup.c:2204) > [ 275.288697][ T4335] ? __pfx_lock_acquire (kernel/locking/lockdep.c:5722) > [ 275.289135][ T4335] ? __pfx___might_resched (kernel/sched/core.c:10106) > [ 275.289595][ T4335] pin_user_pages_remote (mm/gup.c:3350) > [ 275.290041][ T4335] ? __pfx_pin_user_pages_remote (mm/gup.c:3350) > [ 275.290545][ T4335] ? find_held_lock (kernel/locking/lockdep.c:5244 (discriminator 1)) > [ 275.290961][ T4335] ? mm_access (kernel/fork.c:1573) > [ 275.291353][ T4335] process_vm_rw_single_vec+0x142/0x360 > [ 275.291900][ T4335] ? __pfx_process_vm_rw_single_vec+0x10/0x10 > [ 275.292471][ T4335] ? mm_access (kernel/fork.c:1573) > [ 275.292859][ T4335] process_vm_rw_core+0x272/0x4e0 > [ 275.293384][ T4335] ? hlock_class (arch/x86/include/asm/bitops.h:227 arch/x86/include/asm/bitops.h:239 include/asm-generic/bitops/instrumented-non-atomic.h:142 kernel/locking/lockdep.c:228) > [ 275.293780][ T4335] ? __pfx_process_vm_rw_core+0x10/0x10 > [ 275.294350][ T4335] process_vm_rw (mm/process_vm_access.c:284) > [ 275.294748][ T4335] ? __pfx_process_vm_rw (mm/process_vm_access.c:259) > [ 275.295197][ T4335] ? __task_pid_nr_ns (include/linux/rcupdate.h:306 (discriminator 1) include/linux/rcupdate.h:780 (discriminator 1) kernel/pid.c:504 (discriminator 1)) > [ 275.295634][ T4335] __x64_sys_process_vm_readv (mm/process_vm_access.c:291) > [ 275.296139][ T4335] ? syscall_enter_from_user_mode (kernel/entry/common.c:94 kernel/entry/common.c:112) > [ 275.296642][ T4335] do_syscall_64 (arch/x86/entry/common.c:51 (discriminator 1) arch/x86/entry/common.c:82 (discriminator 1)) > [ 275.297032][ T4335] ? __task_pid_nr_ns (include/linux/rcupdate.h:306 (discriminator 1) include/linux/rcupdate.h:780 (discriminator 1) kernel/pid.c:504 (discriminator 1)) > [ 275.297470][ T4335] ? lockdep_hardirqs_on_prepare (kernel/locking/lockdep.c:4300 kernel/locking/lockdep.c:4359) > [ 275.297988][ T4335] ? do_syscall_64 (arch/x86/include/asm/cpufeature.h:171 arch/x86/entry/common.c:97) > [ 275.298389][ T4335] ? lockdep_hardirqs_on_prepare (kernel/locking/lockdep.c:4300 kernel/locking/lockdep.c:4359) > [ 275.298906][ T4335] ? do_syscall_64 (arch/x86/include/asm/cpufeature.h:171 arch/x86/entry/common.c:97) > [ 275.299304][ T4335] ? do_syscall_64 (arch/x86/include/asm/cpufeature.h:171 arch/x86/entry/common.c:97) > [ 275.299703][ T4335] ? do_syscall_64 (arch/x86/include/asm/cpufeature.h:171 arch/x86/entry/common.c:97) > [ 275.300115][ T4335] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:129) > > This BUG is the VM_BUG_ON(!in_atomic() && !irqs_disabled()) assertion in > folio_ref_try_add_rcu() for non-SMP kernel. > > The process_vm_readv() calls GUP to pin the THP. An optimization for > pinning THP instroduced by commit 57edfcfd3419 ("mm/gup: accelerate thp > gup even for "pages != NULL"") calls try_grab_folio() to pin the THP, > but try_grab_folio() is supposed to be called in atomic context for > non-SMP kernel, for example, irq disabled or preemption disabled, due to > the optimization introduced by commit e286781d5f2e ("mm: speculative > page references"). > > The commit efa7df3e3bb5 ("mm: align larger anonymous mappings on THP > boundaries") is not actually the root cause although it was bisected to. > It just makes the problem exposed more likely. > > The follow up discussion suggested the optimization for non-SMP kernel > may be out-dated and not worth it anymore [1]. So removing the > optimization to silence the BUG. > > However calling try_grab_folio() in GUP slow path actually is > unnecessary, so the following patch will clean this up. > > [1] https://lore.kernel.org/linux-mm/821cf1d6-92b9-4ac4-bacc-d8f2364ac14f@paulmck-laptop/ > Fixes: 57edfcfd3419 ("mm/gup: accelerate thp gup even for "pages != NULL"") > Reported-by: kernel test robot > Cc: linux-stable v6.6+ > Signed-off-by: Yang Shi Just to mention, IMHO it'll still be nicer if we keep the 1st fix patch only have the folio_ref_try_add_rcu() changes, it'll be easier for backport. Now this patch contains not only that but also logically a cleanup patch that replaces old rcu calls to folio_try_get(). But squashing these may mean we need explicit backport to 6.6 depending on whether those lines changed, meanwhile the cleanup part may not be justfied to be backported in the first place. I'll leave that to you to decide, no strong feelings here. Acked-by: Peter Xu Thanks, -- Peter Xu