Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp284311rdb; Mon, 22 Jan 2024 22:07:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1JH4/J8ad3pEF5Jua+tREJcQx04s/o9SaXmU5SLe2ItuboQZcROk+lhonUnnNa24T0pQO X-Received: by 2002:a05:620a:c05:b0:783:3b03:4a11 with SMTP id l5-20020a05620a0c0500b007833b034a11mr5563236qki.119.1705990047084; Mon, 22 Jan 2024 22:07:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705990047; cv=pass; d=google.com; s=arc-20160816; b=RtYopFA+1LsPKpghqKb3JxnnrlGkesjfDI73/LPRgtDa+SgZ53U77YVQXt3qWpq9W9 PDhJhzaBM0mzchCw9ExT3TEID1oT+J5GLPuQWwV6zmTBKsJProD6bKMcm6LPZmKpqIQa F6RIutFRTyREZ2TxO5Pirizv0Y6NXeDac1+yVz0HLPM/jpXkbEHqrh0ULZ3uYJ05u6Lh HeRo6d3fG2CJI2N8LZkuvDmZ6uqDV8MbErBc6Pm5K/RrKl3crTFsNn51HbkKgzdizVR8 Z0rjBW/Q3KSE76olu+u79bqplCvFZYPsnSB2SHJSox/nbHBrPgk+1hqXFeTlPwj4niOB jg4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=WxZ+A3znnzHtmYf2gcEZb4fN+U5N81/SctsD0rg3+jg=; fh=JdtsixMHsbtWQo1xUG6V5/D2MlH0aZ1RXHeKEr0bSws=; b=xnRZhPGmaNeC+/hW/C2gQwf2wcABGhh6HXd2QInEDp42lvszbbw+3SOkFH9UY+S96+ fQdEW4KW5fN676kuFyfT3Y8CWswyo8cSWl8BN2UgIyj0Oz1ukITVfx8SUFEvHCFI4e5X X/blcALlJQRG56yyVPm9gdxZRoQ0wih37LOQyhb4wxc9yZhfQZHyLDDu09LXouYcVnBq c2PGpFVCASfpzdKBg7WGV6TSirO6Ffoa9ls7E5gw40rgYNrqS2eKhoVGJQ3drsFX4Hxw KzGa9lqr0xAbvW8fQXrZL7rGpsLd8PpaM3TjguQoDkE6D4hJXFNOBkKjZkWK7PmFpQ1U sEbQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=p5L1Jpul; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-34749-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34749-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j7-20020a05620a146700b007839a42c28dsi4985352qkl.320.2024.01.22.22.07.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:07:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34749-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=p5L1Jpul; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-34749-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34749-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C47FF1C22F51 for ; Tue, 23 Jan 2024 06:07:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C791C4EB21; Tue, 23 Jan 2024 06:07:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="p5L1Jpul" Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FB5F4EB25 for ; Tue, 23 Jan 2024 06:07:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705990036; cv=none; b=EuoXCX0SViO2KLN0Kw+5cq6/HDMUlH8Ff1x5m9WioGtOwCxPrrAil04SsD+A17nk9I5j/3+z0SzSdBguQlLFwaP6JcGyTA1eE6Tn4SOTGVMgIbivDctZt769J+F7nPD0PwlBmlsn1AxIAEJKV0CUXPzSHdJZ7QVehBVT2bGFzMg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705990036; c=relaxed/simple; bh=27Aj8d6q/ybatyrtxw+UPq7m9vsdWQLbU30eyMwD+zk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DgyvBt1OCibfBIbfG5jcpWw7lTrCvEQ90mO0FamMwmuep+0p+LW/F+i0CSMYueGhCytVfwyzBz2XFG84fQXK4PQsQhjBWokokrQ9G8/Z38vm4spaCXBO695dB//DlkKjaqBI8tgUEOD8U8dUolCiCHhvC8tCuDnKhZU0WzfXEjA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=p5L1Jpul; arc=none smtp.client-ip=209.85.128.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6002317a427so9633437b3.2 for ; Mon, 22 Jan 2024 22:07:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705990033; x=1706594833; darn=vger.kernel.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=WxZ+A3znnzHtmYf2gcEZb4fN+U5N81/SctsD0rg3+jg=; b=p5L1JpulbK5k6Oa6x4qysS3HBIVVZRrpceglU2ZdXMfC5yHpsRvX/sM+vc8l8lJt9X niJu05Dti+ydLMq0QVI9qbl5wwoha9ZnNlb6t26l4DIzKElvXePnaGfV6/fnmSEU2EKu VS+9F1qTXML9xM+5bWLQ//nYrS2xTjTNBSkz8F8BTGXN+F2FUTBk6s2TPqAzhVDUIcgo OfAgjVmWjPL+WgQh/ltR5zwYeTm9VubH0BYVHa6Wd/uff+D/NQ3h0SMf5XQG7m1tTplN mQK2n+PS5sc5ab5/fr+lBl3l6Kl0H/moQP5nlmdOasW3VLmKlbCscupI0OphLBBTzO10 ys7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705990033; x=1706594833; 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=WxZ+A3znnzHtmYf2gcEZb4fN+U5N81/SctsD0rg3+jg=; b=dnIpzwOgZ+hYDFcQbt1ueuBGoeJ4xXH/zLtxMjmVaf0etqYehtkXkTkharUJ1h1hej HhZyzH8FSIoSnjOij6kkQtmBWFnoIgK7semMSKSbY1lAMykfv4KEepcfSnb+JfH3ytUK p6YSNs05bEDGENslKLHYIENRDstGjaCKMrxC3XYiunXHtdsQPxlIETUEzLZr2c13By06 s+4skC8VqDTXC1uPDX5WoknkJ6bPWlzDyqYDfqnvTRqa3SiJBXM0h+VWCJBlZkp+xE9y hPjHIclUDjHtqFfir0jKlGqcEjRKRdIEIjSfwLDCAAGkQhrQAg4ndTCtAgNpUt0/IPDH aMAA== X-Gm-Message-State: AOJu0YzCM9XvFdA/zgrtztARNdxYoefN8n0S6+DivScDX+i7QwK0aaiO /IKgTQz7mrQsyAIk2Zh4Lc+g32u621OF35g3JsnzFjtA/DVOyEXCyUWm50rmdeXoqdblB5GS8Of zRoSHhD7S2A0RuvrgVbjwyxgBNnvJ8HKviNZX X-Received: by 2002:a81:a1c5:0:b0:5ff:aa81:cf4b with SMTP id y188-20020a81a1c5000000b005ffaa81cf4bmr3863649ywg.83.1705990033272; Mon, 22 Jan 2024 22:07:13 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240122071324.2099712-3-surenb@google.com> <20240123053629.365673-1-sj@kernel.org> In-Reply-To: <20240123053629.365673-1-sj@kernel.org> From: Suren Baghdasaryan Date: Mon, 22 Jan 2024 22:07:01 -0800 Message-ID: Subject: Re: [PATCH 3/3] mm/maps: read proc/pid/maps under RCU To: SeongJae Park Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, dchinner@redhat.com, casey@schaufler-ca.com, ben.wolsieffer@hefring.com, paulmck@kernel.org, david@redhat.com, avagin@google.com, usama.anjum@collabora.com, peterx@redhat.com, hughd@google.com, ryan.roberts@arm.com, wangkefeng.wang@huawei.com, Liam.Howlett@oracle.com, yuzhao@google.com, axelrasmussen@google.com, lstoakes@gmail.com, talumbau@google.com, willy@infradead.org, vbabka@suse.cz, mgorman@techsingularity.net, jhubbard@nvidia.com, vishal.moola@gmail.com, mathieu.desnoyers@efficios.com, dhowells@redhat.com, jgg@ziepe.ca, sidhartha.kumar@oracle.com, andriy.shevchenko@linux.intel.com, yangxingui@huawei.com, keescook@chromium.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 22, 2024 at 9:36=E2=80=AFPM SeongJae Park wrote= : > > Hi Suren, > > On Sun, 21 Jan 2024 23:13:24 -0800 Suren Baghdasaryan = wrote: > > > With maple_tree supporting vma tree traversal under RCU and per-vma loc= ks > > making vma access RCU-safe, /proc/pid/maps can be read under RCU and > > without the need to read-lock mmap_lock. However vma content can change > > from under us, therefore we make a copy of the vma and we pin pointer > > fields used when generating the output (currently only vm_file and > > anon_name). Afterwards we check for concurrent address space > > modifications, wait for them to end and retry. That last check is neede= d > > to avoid possibility of missing a vma during concurrent maple_tree > > node replacement, which might report a NULL when a vma is replaced > > with another one. While we take the mmap_lock for reading during such > > contention, we do that momentarily only to record new mm_wr_seq counter= . > > This change is designed to reduce mmap_lock contention and prevent a > > process reading /proc/pid/maps files (often a low priority task, such a= s > > monitoring/data collection services) from blocking address space update= s. > > > > Note that this change has a userspace visible disadvantage: it allows f= or > > sub-page data tearing as opposed to the previous mechanism where data > > tearing could happen only between pages of generated output data. > > Since current userspace considers data tearing between pages to be > > acceptable, we assume is will be able to handle sub-page data tearing > > as well. > > > > Signed-off-by: Suren Baghdasaryan > > --- > > fs/proc/internal.h | 2 + > > fs/proc/task_mmu.c | 114 ++++++++++++++++++++++++++++++++++++++++++--- > > 2 files changed, 109 insertions(+), 7 deletions(-) > > > > diff --git a/fs/proc/internal.h b/fs/proc/internal.h > > index a71ac5379584..e0247225bb68 100644 > > --- a/fs/proc/internal.h > > +++ b/fs/proc/internal.h > > @@ -290,6 +290,8 @@ struct proc_maps_private { > > struct task_struct *task; > > struct mm_struct *mm; > > struct vma_iterator iter; > > + unsigned long mm_wr_seq; > > + struct vm_area_struct vma_copy; > > #ifdef CONFIG_NUMA > > struct mempolicy *task_mempolicy; > > #endif > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > > index 3f78ebbb795f..3886d04afc01 100644 > > --- a/fs/proc/task_mmu.c > > +++ b/fs/proc/task_mmu.c > > @@ -126,11 +126,96 @@ static void release_task_mempolicy(struct proc_ma= ps_private *priv) > > } > > #endif > > > > -static struct vm_area_struct *proc_get_vma(struct proc_maps_private *p= riv, > > - loff_t *ppos) > > +#ifdef CONFIG_PER_VMA_LOCK > > + > > +static const struct seq_operations proc_pid_maps_op; > > +/* > > + * Take VMA snapshot and pin vm_file and anon_name as they are used by > > + * show_map_vma. > > + */ > > +static int get_vma_snapshow(struct proc_maps_private *priv, struct vm_= area_struct *vma) > > { > > + struct vm_area_struct *copy =3D &priv->vma_copy; > > + int ret =3D -EAGAIN; > > + > > + memcpy(copy, vma, sizeof(*vma)); > > + if (copy->vm_file && !get_file_rcu(©->vm_file)) > > + goto out; > > + > > + if (copy->anon_name && !anon_vma_name_get_rcu(copy)) > > + goto put_file; > > From today updated mm-unstable which containing this patch, I'm getting b= elow > build error when CONFIG_ANON_VMA_NAME is not set. Seems this patch needs= to > handle the case? Hi SeongJae, Thanks for reporting! I'll post an updated version fixing this config. Suren. > > .../linux/fs/proc/task_mmu.c: In function =E2=80=98get_vma_snapshow= =E2=80=99: > .../linux/fs/proc/task_mmu.c:145:19: error: =E2=80=98struct vm_area_s= truct=E2=80=99 has no member named =E2=80=98anon_name=E2=80=99; did you mea= n =E2=80=98anon_vma=E2=80=99? > 145 | if (copy->anon_name && !anon_vma_name_get_rcu(copy)) > | ^~~~~~~~~ > | anon_vma > .../linux/fs/proc/task_mmu.c:161:19: error: =E2=80=98struct vm_area_s= truct=E2=80=99 has no member named =E2=80=98anon_name=E2=80=99; did you mea= n =E2=80=98anon_vma=E2=80=99? > 161 | if (copy->anon_name) > | ^~~~~~~~~ > | anon_vma > .../linux/fs/proc/task_mmu.c:162:41: error: =E2=80=98struct vm_area_s= truct=E2=80=99 has no member named =E2=80=98anon_name=E2=80=99; did you mea= n =E2=80=98anon_vma=E2=80=99? > 162 | anon_vma_name_put(copy->anon_name); > | ^~~~~~~~~ > | anon_vma > .../linux/fs/proc/task_mmu.c: In function =E2=80=98put_vma_snapshot= =E2=80=99: > .../linux/fs/proc/task_mmu.c:174:18: error: =E2=80=98struct vm_area_s= truct=E2=80=99 has no member named =E2=80=98anon_name=E2=80=99; did you mea= n =E2=80=98anon_vma=E2=80=99? > 174 | if (vma->anon_name) > | ^~~~~~~~~ > | anon_vma > .../linux/fs/proc/task_mmu.c:175:40: error: =E2=80=98struct vm_area_s= truct=E2=80=99 has no member named =E2=80=98anon_name=E2=80=99; did you mea= n =E2=80=98anon_vma=E2=80=99? > 175 | anon_vma_name_put(vma->anon_name); > | ^~~~~~~~~ > | anon_vma > > [...] > > > Thanks, > SJ