From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01460C47422 for ; Fri, 26 Jan 2024 10:22:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B13C6B0093; Fri, 26 Jan 2024 05:22:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 661296B0095; Fri, 26 Jan 2024 05:22:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 531676B0098; Fri, 26 Jan 2024 05:22:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 443AE6B0093 for ; Fri, 26 Jan 2024 05:22:57 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 07E46C0EE0 for ; Fri, 26 Jan 2024 10:22:57 +0000 (UTC) X-FDA: 81721073994.10.3AF65B4 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf03.hostedemail.com (Postfix) with ESMTP id 69ECD20012 for ; Fri, 26 Jan 2024 10:22:54 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Rr8jM/xB"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of "SRS0=zAkC=JE=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=zAkC=JE=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706264575; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lADEY+p1KGZWmglNiNl4oHXzs8zb9ACRKkYj+xXG1nk=; b=TycbXn12Ls5n3j1THX957cbJG6MKSlvKpp5zwdoefhAWnhGUpULMRxtZKlaM9zzn6bx9WL Hy+LwkXrh1PJHKeC9XWv9RlyYfP/TAf61BLMCEsT6j7ooYtokH/jMpqrQQeiqlkDdTSRm6 KTYic0PVjyX7imIW2iYmnOssDbnTbHc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Rr8jM/xB"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of "SRS0=zAkC=JE=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=zAkC=JE=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706264575; a=rsa-sha256; cv=none; b=aI6O3SQGRxVrpIvt5M/Q3JcLvu3S1Gd20xpZ2ixJ2PP2c3ZLlwniLGMKikFQj2kVy8dnhS iKzkrZkqf35erpim8fzhTb/FpdRWyA2giHp78vafNr2/ZXOmYNzS7gIMg5yhjDe4Y4E3d7 FeRxrWsk7gGOfnhURnsigHnNYo+g4xw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C3824CE36CB; Fri, 26 Jan 2024 10:22:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13E9DC433C7; Fri, 26 Jan 2024 10:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706264568; bh=2yHvncHSVJo2fldrlH58Avr7g4fyvv+ZyNJ9oKYuJBI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=Rr8jM/xBgj710Y8VtRhuliF9EHa23otdr9J8UgjKzWLvHcKfyT3uY/V6cL7V1g7fR xeJKrXjnaYDZ0anF1MIX16yoyGtv25RUfeuDFNvsUqzLJCsSbfopa+mfAqCujJWgcG y0TOBNetFB+0vMhkBleNhYx99DiYQMXWZmn/89/giQWAULk1vExrw8Bv801OL9sHXc sZX8sCmcH2FFDB1fq6yzW92ugbO3g3VhXOMsBIR+T4DsGt1wnQ1tXRiuGFSMRxty+Q 2izbLAh4gnMCacvXiYT/sN9zC/U1G8g94x1DdZ6mbH5eQbcr+iw1/QE0hfMhzfPrJR R9DMK+isV3I+A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id A3F81CE1408; Fri, 26 Jan 2024 02:22:47 -0800 (PST) Date: Fri, 26 Jan 2024 02:22:47 -0800 From: "Paul E. McKenney" To: Suren Baghdasaryan Cc: kernel test robot , Matthew Wilcox , oe-kbuild-all@lists.linux.dev, Linux Memory Management List , Andrew Morton Subject: Re: [linux-next:master 1589/1892] fs/proc/task_mmu.c:143:45: sparse: sparse: incorrect type in argument 1 (different address spaces) Message-ID: <68dc8592-6a5d-4cbe-bb8c-e0f4b5517684@paulmck-laptop> Reply-To: paulmck@kernel.org References: <202401251829.0m6Eo4LI-lkp@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 69ECD20012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ss9i6asdsywh7h56kxbjmjbwde889581 X-HE-Tag: 1706264573-322769 X-HE-Meta: U2FsdGVkX18lFU7BCCZ/6jFOr7Os0g3ub/bMcV669TuTdLe4sbi1TUUwWXK0c4/qAYl+4hbVmDNOwVU+oxDVCMc6x+XzVkzVbLKIrOBGvf2Dh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uBvMY8WQ4QaEoMqmJxC54Q0LTzYpP5SI8inzbW9fhIU0AS7xorMaj1Mxv3eRM30pAMWVhWlN8ArGktIUK9vSlfsPjjYvLyTfHN4SYlYRAMCouXJNK+9aEnGUKMTEgNF9Kl9xi94aY+w4dXk6TFMPT7x9+kV5e/BLtuCEDwtZNV4P8jfDFxxIJzyK6Th4eAY/yjVElvmhZh4GUcQfz0C88xCLdfwPRI4Bv6fhv00zGv0EZAioDWGjOg1om4osCTqNzFSM3PM5wGzsuRf1kiUobcz1KIKhW9E49nUV6V+0mb4/IUPsaQiNfCfm8XH+aKGm5Wvi+V1iWP1MHLU+gMFsxht9eWCOP/3WAzh2Vl4nmjFP5MBv86oLo7+QSKhZnDXrFRiEn3Z4g8UcQEiHLaJV90hlWfJafeBEo9oTuB7xBaFCA15b6MJTtY4VEd0QZBmNOob1ObDCqlSlojCBP41Uh2MzTwNf25gAo6RVo4W4qE0e961oENw7cK0BN6gjHkXmUZlcWO1v6GJuOOqAyGzOdwy0RluZWOmkU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Jan 25, 2024 at 06:24:05PM -0800, Suren Baghdasaryan wrote: > On Thu, Jan 25, 2024 at 4:35 PM Paul E. McKenney wrote: > > > > On Thu, Jan 25, 2024 at 03:17:17PM -0800, Suren Baghdasaryan wrote: > > > On Thu, Jan 25, 2024 at 2:44 PM Paul E. McKenney wrote: > > > > > > > > On Thu, Jan 25, 2024 at 01:27:34PM -0800, Suren Baghdasaryan wrote: > > > > > On Thu, Jan 25, 2024 at 2:23 AM kernel test robot wrote: > > > > > > > > > > > > tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master > > > > > > head: 01af33cc9894b4489fb68fa35c40e9fe85df63dc > > > > > > commit: 0c30c4cd953025979b7689e49844837f762303ec [1589/1892] mm/maps: read proc/pid/maps under RCU > > > > > > config: x86_64-randconfig-121-20240125 (https://download.01.org/0day-ci/archive/20240125/202401251829.0m6Eo4LI-lkp@intel.com/config) > > > > > > compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) > > > > > > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240125/202401251829.0m6Eo4LI-lkp@intel.com/reproduce) > > > > > > > > > > > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > > > > > > the same patch/commit), kindly add following tags > > > > > > | Reported-by: kernel test robot > > > > > > | Closes: https://lore.kernel.org/oe-kbuild-all/202401251829.0m6Eo4LI-lkp@intel.com/ > > > > > > > > > > > > sparse warnings: (new ones prefixed by >>) > > > > > > >> fs/proc/task_mmu.c:143:45: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct file [noderef] __rcu **f @@ got struct file ** @@ > > > > > > > > > > Uh, this is a problem. > > > > > I missed that get_file_rcu() is used only with mm->exe_file and > > > > > vma->vm_file is not really RCU-safe. It's freed via a call to fput() > > > > > which schedules its freeing using schedule_delayed_work(..., 1) but I > > > > > don't think that constitutes RCU grace period. Paul, Matthew, could > > > > > you please confirm? In the meantime I'm going to ask Andrew to remove > > > > > my patchset from mm-unstable to be safe. > > > > > > > > Sadly, no, schedule_delayed_work() does not imply an RCU grace period. > > > > > > > > There is a queue_rcu_work() that schedules work after a grace period, > > > > which could be combined with a timer to get the delay. > > > > > > > > Another approach would be to use get_state_synchronize_rcu() before > > > > the schedule_delayed_work() in fput(), then do cond_synchronize_rcu() > > > > in delayed_fput(). This would require adding an unsigned long to > > > > struct file to keep track of which grace period a given struct file > > > > needed to wait for. > > > > > > > > Perhaps something like this: > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > void fput(struct file *file) > > > > { > > > > if (atomic_long_dec_and_test(&file->f_count)) { > > > > struct task_struct *task = current; > > > > > > > > if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) { > > > > init_task_work(&file->f_rcuhead, ____fput); > > > > if (!task_work_add(task, &file->f_rcuhead, TWA_RESUME)) > > > > return; > > > > /* > > > > * After this task has run exit_task_work(), > > > > * task_work_add() will fail. Fall through to delayed > > > > * fput to avoid leaking *file. > > > > */ > > > > } > > > > > > > > file->f_rcu_seq = get_state_synchronize_rcu(); > > > > if (llist_add(&file->f_llist, &delayed_fput_list)) > > > > schedule_delayed_work(&delayed_fput_work, 1); > > > > } > > > > } > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > And this: > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > static void delayed_fput(struct work_struct *unused) > > > > { > > > > struct llist_node *node = llist_del_all(&delayed_fput_list); > > > > struct file *f, *t; > > > > > > > > llist_for_each_entry_safe(f, t, node, f_llist) { > > > > cond_synchronize_rcu(f->f_rcu_seq); > > > > __fput(f); > > > > } > > > > } > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > Note that if you called fput() on a long sequence of struct file > > > > structures, the cond_synchronize_rcu() would be a near-noop almost all the > > > > time, actually blocking at most about every once per every few jiffies. > > > > After all, once a grace period has been waited for, it covers all of > > > > the struct file structures that were passed to fput() during a given > > > > RCU grace period. > > > > > > > > Still, it would add the occasional delay. And it would increase the > > > > size of struct file, though there are workarounds for that, if size > > > > is an issue. > > > > > > > > Thoughts? > > > > > > Thanks for the suggestion, Paul. I'm worried about this occasional > > > delay but otherwise this seems like a nice and simple approach. > > > > One potential saving grace is that the more heavily loaded the mechanism, > > the smaller a fraction of the cond_synchronize_rcu() calls will do > > a delay. > > > > > Do you > > > guys think that making *all* files RCU-safe with this approach is > > > warranted? For my particular case I need only vma->vm_file to be > > > RCU-safe but maybe there are other cases which would benefit from > > > this? > > > > To this, I can only give an unqualified "I don't know". :-( > > > > But if there is some condition that can be sampled on a per-file-structure > > basis, you could use that to invoke cond_synchronize_rcu() only when > > needed. Or send only those file structures that need the extra delay > > through queue_rcu_work(), perhaps by accumulating a list of them. > > Thanks Paul! You gave me enough food for thought. Let me see if I can > come up with something usable. Do we have the same problem with the task_work_add() path in fput()? Thanx, Paul > Cheers, > Suren. > > > > > Thanx, Paul > > > > > > > > fs/proc/task_mmu.c:143:45: sparse: expected struct file [noderef] __rcu **f > > > > > > fs/proc/task_mmu.c:143:45: sparse: got struct file ** > > > > > > fs/proc/task_mmu.c: note: in included file (through include/linux/rbtree.h, include/linux/mm_types.h, include/linux/mmzone.h, ...): > > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbalance in 'get_vma_snapshot' - unexpected unlock > > > > > > fs/proc/task_mmu.c:264:22: sparse: sparse: context imbalance in 'm_start' - different lock contexts for basic block > > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbalance in 'm_stop' - unexpected unlock > > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbalance in 'smaps_pte_range' - unexpected unlock > > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbalance in 'clear_refs_pte_range' - unexpected unlock > > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbalance in 'pagemap_pmd_range' - unexpected unlock > > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbalance in 'pagemap_scan_pmd_entry' - unexpected unlock > > > > > > fs/proc/task_mmu.c: note: in included file (through arch/x86/include/asm/uaccess.h, include/linux/uaccess.h, include/linux/sched/task.h, ...): > > > > > > arch/x86/include/asm/uaccess_64.h:88:24: sparse: sparse: cast removes address space '__user' of expression > > > > > > arch/x86/include/asm/uaccess_64.h:88:24: sparse: sparse: cast removes address space '__user' of expression > > > > > > > > > > > > vim +143 fs/proc/task_mmu.c > > > > > > > > > > > > 132 > > > > > > 133 /* > > > > > > 134 * Take VMA snapshot and pin vm_file and anon_name as they are used by > > > > > > 135 * show_map_vma. > > > > > > 136 */ > > > > > > 137 static int get_vma_snapshot(struct proc_maps_private *priv, struct vm_area_struct *vma) > > > > > > 138 { > > > > > > 139 struct vm_area_struct *copy = &priv->vma_copy; > > > > > > 140 int ret = -EAGAIN; > > > > > > 141 > > > > > > 142 memcpy(copy, vma, sizeof(*vma)); > > > > > > > 143 if (copy->vm_file && !get_file_rcu(©->vm_file)) > > > > > > 144 goto out; > > > > > > 145 > > > > > > 146 if (!anon_vma_name_get_if_valid(copy)) > > > > > > 147 goto put_file; > > > > > > 148 > > > > > > 149 if (priv->mm_wr_seq == mmap_write_seq_read(priv->mm)) > > > > > > 150 return 0; > > > > > > 151 > > > > > > 152 /* Address space got modified, vma might be stale. Wait and retry. */ > > > > > > 153 rcu_read_unlock(); > > > > > > 154 ret = mmap_read_lock_killable(priv->mm); > > > > > > 155 mmap_write_seq_record(priv->mm, &priv->mm_wr_seq); > > > > > > 156 mmap_read_unlock(priv->mm); > > > > > > 157 rcu_read_lock(); > > > > > > 158 > > > > > > 159 if (!ret) > > > > > > 160 ret = -EAGAIN; /* no other errors, ok to retry */ > > > > > > 161 > > > > > > 162 anon_vma_name_put_if_valid(copy); > > > > > > 163 put_file: > > > > > > 164 if (copy->vm_file) > > > > > > 165 fput(copy->vm_file); > > > > > > 166 out: > > > > > > 167 return ret; > > > > > > 168 } > > > > > > 169 > > > > > > > > > > > > -- > > > > > > 0-DAY CI Kernel Test Service > > > > > > https://github.com/intel/lkp-tests/wiki