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 38639C47DDB for ; Fri, 26 Jan 2024 03:39:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC9966B0088; Thu, 25 Jan 2024 22:39:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA11D6B0089; Thu, 25 Jan 2024 22:39:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9682A6B008A; Thu, 25 Jan 2024 22:39:55 -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 5F78F6B0088 for ; Thu, 25 Jan 2024 22:39:55 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 014F3A0348 for ; Fri, 26 Jan 2024 02:24:18 +0000 (UTC) X-FDA: 81719867838.23.4490FEA Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by imf24.hostedemail.com (Postfix) with ESMTP id 3C45E18000F for ; Fri, 26 Jan 2024 02:24:17 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=W+Ox6SjY; spf=pass (imf24.hostedemail.com: domain of surenb@google.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706235857; a=rsa-sha256; cv=none; b=a1Uy5eOvJ3HbHxVG/AdHDQoovJt22kGoweZN11FXPNNKmPDOGQnTpGxD41Qx0XrJLztJ50 vdfoN4vprz0R8y74sbKA3mD6zKMCSEepyWvlVq9o4ojkN79UjBai3OvkfV41l605HYWkz2 Oh9/fK3Q2i4ej9f3BO8PJwlKI9DW6M8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=W+Ox6SjY; spf=pass (imf24.hostedemail.com: domain of surenb@google.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706235857; h=from:from:sender: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=pPs1aBX3lVBfn3SAANt3qn2t+DVZGWgp9ShsyXxUPnM=; b=EtQ+X4vXbLktM9pcuXggEcY+Ej/DtG5SFNUz1i+sq43dmcbwinbHzus6OTlZoL112uZdHO XgOyZl/JnLa4kLoDZuN9EeAxRZrXl09rOWkgfdWPSOq1HN92PBguS/lSQCC5Y2uA5qDTOL h7/L8knoWFsj/NgRp87cGMU/RmITAK8= Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-5ffdf06e009so49714577b3.3 for ; Thu, 25 Jan 2024 18:24:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706235856; x=1706840656; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pPs1aBX3lVBfn3SAANt3qn2t+DVZGWgp9ShsyXxUPnM=; b=W+Ox6SjYdR4qGJP7seQ75DIKDnz6oSGmiHAxCVzeAWmzuASoMNFZrOWo9yOtk/ZbYk fuWc+x9liep+tF4s+Sr9P13V7ZYpUbKmc863Z3tNlml4I+cd+Jrv8fmixIe+SVNacaYp aUo/wbBeQbhsyeFeFEHhaxBs86ByBSl8Erk7qdmZ/C71mBzv5+/C7Egnj7fFLujpspqB KOlZ5UHm3Y9pYWoEzJJlrGPVtCfVfQXhBl1s9UAERDfbga8tF9VzHUmxVUhyOCTqQy5l 0DRkCkdd4koMh7z3K0BE/6YpnQSlHN9ppaFftGNxFeRaLRGlTI2oQV7/09tiOiHUOg5A lW7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706235856; x=1706840656; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pPs1aBX3lVBfn3SAANt3qn2t+DVZGWgp9ShsyXxUPnM=; b=VpWCqO6vJEYwodrJqN/QZFQ02SakxRONDXuHo6EZsYzGv2GQ8QkIw+24NGaqTFvf9v z8PUtQca724YFIig0D+T/+RfuIA+R5+Kf3+m//SN1dihB6TGBnmpPFNZZcVtwQko4TY7 FvMPd+n2lhxxNAASjjJY07CcnoI/JNyZJDVxrZMtswZQZyd+SWSuXelxRHK799s6j1k1 VTR/HgMUBtzJnBH6XC3tvALP/e6WSvg7l5G5Rrd/CRojnq/Drb8feJjvR/klYjoxgJyS rNGMxGSvJxAlPEY3Hk9DVUWnEjNHPny1cSCpiCyM0LU88gY2Kl1opSAPS07KDyD6YLS4 FswA== X-Gm-Message-State: AOJu0YwAJNpSiJJK5248FDhr+mMPatj5K5peyFud7icYcnNSUNm9Ksqn +i81LiAH5NLZOlcBc5jU+xyyhL37fx5ZekPaQWVXJf+nkxQVRb6DyMIMy3sxmlbEUFSjxPHHS2P dPJuWJu5rGnupBp3/dWIL6e8fFn+baOm3MhmS X-Google-Smtp-Source: AGHT+IErE5xInKlfhob4haiGG8dYHPZmqVFJJkPiXYmjsN7Ol9aGEdn40DDaYoBrLZfzqUdg8ujTYgJuTQdNCzxu3ys= X-Received: by 2002:a81:4c56:0:b0:602:cb1e:9894 with SMTP id z83-20020a814c56000000b00602cb1e9894mr75057ywa.88.1706235855942; Thu, 25 Jan 2024 18:24:15 -0800 (PST) MIME-Version: 1.0 References: <202401251829.0m6Eo4LI-lkp@intel.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 25 Jan 2024 18:24:05 -0800 Message-ID: Subject: Re: [linux-next:master 1589/1892] fs/proc/task_mmu.c:143:45: sparse: sparse: incorrect type in argument 1 (different address spaces) To: paulmck@kernel.org Cc: kernel test robot , Matthew Wilcox , oe-kbuild-all@lists.linux.dev, Linux Memory Management List , Andrew Morton Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3C45E18000F X-Stat-Signature: njdwc8oinux43yg1iixstr994fe4z17q X-Rspam-User: X-HE-Tag: 1706235857-695916 X-HE-Meta: U2FsdGVkX18yccMqQBH7pdmS9R8gmD44wFeMCGxkfIn6vC+QqxV495Dxekm40tu/F3lo4ppKiovV6uY3nck0asPlEMcyGPzNa8hnnqObYc6wjd9PNNs9AkGScm5af6dMIvctq0S5R8N7kbDS74LYf0dNB8Zl6D+SAVVOkJZtOxCOdU2lDrJ+V0xJ4/znccp91RVrZ9T+V1RXQfTv7OLJcBPxPpO9rr0+YKZyYkN5IDb7/oC4ny9Lea6fe341HsQ6Ahp0IC9nvMZzx7u2eBsyX6eFzjLAliTW9pKfl9qgHSOZj+fkHn4Wo+iYyvB47mBHXshvklADbBg9CuCvVPXQ7yaHftiQpzEDlRYWiPL128++aZqD5MWE8p28VtOrHslHQHVfjASkG3UoOrAWI3q88qymATlrrfMQUeT0HdLrdJvaiq7PgR0xpSgFgikGMIcUNSHcsffirx960GSyfgiprb/iBHlQrR9+QRKMM3aCVnKPiaPNtAABEACC1Ws87Ol1fRXn7TLoBSp6uL/tjbjQRhSWBkCAdscAIPrJwAXdbKx+BavnWeUoY44dHohksJE6+TNUnE8IzsgjPrCQI9Rmn+bORqwsGWv6J1LXI8uIhsfKXCteY2Gb928ZyhadIzAw0DjqijH5BlPFnYZFzaJA1vsueyPRkWXOzO0T5q0oO8ISQoT0TR1ZFjxYJB9TWk1PegEki22qYH+Uf2lH9pSBL454SQjYHOmCdj597iyNWv+Lwom8iLY38L3N9Up8YdxT0M2zol+gBqE+H9cRb9rvgFqu1KJ5DCdmAhVKKJrxaQNVQKpqPpczDKaMrpI40zwH9Ww4l7nTQa0vfjTVurg80CdsJnyEqqTXYNdzlSVLGk3moGeyxrNA52AHMc1tdcKBkNdu2SSMD9WuGb9/qOLBN63yQ/NkkAwOvE8LteVP4CeRxIishoXSTZpRYDlcqzdZWjnEclAQzcbkdKnmbr/ 3GL9bKfq iIbFYFLCEDSCi6cnquWEN7NwxgxmzkI/xtRXH2hMyuLlWnOl7MjuABhLFKQ0aH/Nm0A3NcHo6j3UiLyzLI5AbyeEwYN4z3yQiGFEbjbupB1YdfwlJmDcYPhdOKTki5axE6F7OMaG6tiepT24GvUMOKbvG9l6u16IF8HUVLC+ibSITwR6a2lCGVLz6GJ88+mnVDZPr5AiuJdtfG7QJ7Na6REm7pxaVO0ivxudVFPCGGMeB85Iw6xTAjvJ/LpanTA3h/bb4eGxXTBtRgOAl1yq/mQk+SM2bSIto9/VCnnhdiamj9PQwZ+G+FkPHap4SAJwKE3/Q4nGj/r3IdNfP91PIBeGg1pUOddV6CEAocSvwGKLv3zvb2xUqZ16G3dOTzDEeLL+zhP+IutucsOAkLMUME7C1AKRztZq/a05l4O4zVe85fDTre1kH5xKsVQ== 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 4:35=E2=80=AFPM 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=E2=80=AFPM 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=E2=80=AFAM kernel test robot wrote: > > > > > > > > > > tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linu= x-next.git master > > > > > head: 01af33cc9894b4489fb68fa35c40e9fe85df63dc > > > > > commit: 0c30c4cd953025979b7689e49844837f762303ec [1589/1892] mm/m= aps: read proc/pid/maps under RCU > > > > > config: x86_64-randconfig-121-20240125 (https://download.01.org/0= day-ci/archive/20240125/202401251829.0m6Eo4LI-lkp@intel.com/config) > > > > > compiler: clang version 17.0.6 (https://github.com/llvm/llvm-proj= ect 6009708b4367171ccdbf4b5905cb6a803753fe18) > > > > > reproduce (this is a W=3D1 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.0m6E= o4LI-lkp@intel.com/ > > > > > > > > > > sparse warnings: (new ones prefixed by >>) > > > > > >> fs/proc/task_mmu.c:143:45: sparse: sparse: incorrect type in a= rgument 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 remo= ve > > > > 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 =3D current; > > > > > > if (likely(!in_interrupt() && !(task->flags & PF_KTHR= EAD))) { > > > init_task_work(&file->f_rcuhead, ____fput); > > > if (!task_work_add(task, &file->f_rcuhead, TW= A_RESUME)) > > > return; > > > /* > > > * After this task has run exit_task_work(), > > > * task_work_add() will fail. Fall through t= o delayed > > > * fput to avoid leaking *file. > > > */ > > > } > > > > > > file->f_rcu_seq =3D 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 =3D 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 al= l the > > > time, actually blocking at most about every once per every few jiffie= s. > > > 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-structur= e > 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. Cheers, Suren. > > Thanx, Paul > > > > > > fs/proc/task_mmu.c:143:45: sparse: expected struct file [n= oderef] __rcu **f > > > > > fs/proc/task_mmu.c:143:45: sparse: got struct file ** > > > > > fs/proc/task_mmu.c: note: in included file (through include/li= nux/rbtree.h, include/linux/mm_types.h, include/linux/mmzone.h, ...): > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbala= nce in 'get_vma_snapshot' - unexpected unlock > > > > > fs/proc/task_mmu.c:264:22: sparse: sparse: context imbalance i= n 'm_start' - different lock contexts for basic block > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbala= nce in 'm_stop' - unexpected unlock > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbala= nce in 'smaps_pte_range' - unexpected unlock > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbala= nce in 'clear_refs_pte_range' - unexpected unlock > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbala= nce in 'pagemap_pmd_range' - unexpected unlock > > > > > include/linux/rcupdate.h:781:9: sparse: sparse: context imbala= nce in 'pagemap_scan_pmd_entry' - unexpected unlock > > > > > fs/proc/task_mmu.c: note: in included file (through arch/x86/i= nclude/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 the= y are used by > > > > > 135 * show_map_vma. > > > > > 136 */ > > > > > 137 static int get_vma_snapshot(struct proc_maps_private *pri= v, struct vm_area_struct *vma) > > > > > 138 { > > > > > 139 struct vm_area_struct *copy =3D &priv->vma_copy; > > > > > 140 int ret =3D -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 =3D=3D mmap_write_seq_read(pr= iv->mm)) > > > > > 150 return 0; > > > > > 151 > > > > > 152 /* Address space got modified, vma might be stale= . Wait and retry. */ > > > > > 153 rcu_read_unlock(); > > > > > 154 ret =3D 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 =3D -EAGAIN; /* no other errors, ok t= o 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