From patchwork Fri Sep 15 16:00:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Wolsieffer X-Patchwork-Id: 140668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1300756vqi; Fri, 15 Sep 2023 13:25:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZETWgntP7F7vyH+dgQsNyDhu8WtIE2DfD+gvgyakIys+f43Jw1l7QdEi+bhaZ7uADLm6d X-Received: by 2002:a05:6a20:8e19:b0:10f:be0:4dce with SMTP id y25-20020a056a208e1900b0010f0be04dcemr2640459pzj.8.1694809553350; Fri, 15 Sep 2023 13:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694809553; cv=none; d=google.com; s=arc-20160816; b=JpjqyDsd6At0EJdnqLzKgtJeTs0rzold4IL7YhIoOgAGhmIdtgZUagJWQ2jzVdqaht wbvETKqf0HqDO2JDXg7lrhCIyg8oTGwkPTIVIBilG44eC0YbvxcyGFxIQ4LTKTLXiI3y W7OdDZ5vgchBxwB7Fv96cRV838dVa2bxZVq6aEixyA1FpOgj0n+ZCarg3IFQsLnN1/5u +Idxh1yePBZhVo3S6s48mGI2yAus0ueOQhxa7bJWF3zomNnJzd6+US1Jpqv9uyEXBVz5 +f2IBYZX9c9SNjMzbfbEZ/rTh26NqMop8/5mAV0XLIeMLA16QfGZVlSvrGz4PLhoOtgZ /HBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=fk8or89hqXtZNxRZ7/0FlKmmKA1FK/3FeO0U6tr3+Qw=; fh=dynC5zpaoXQxGdVVA5MA3h+fq0mJLXVPI7OApFZW/wU=; b=Ppb4U+jYJ1pi+JHV+A1PfzHWTRF+PjhE74Ost51dpTu0JmScqmhx7nke6a5H8tAABu mo9s5fCK6AVTFXM6SDzb+rHbERmGZrOb5Z/7bXgNqM0GzG1nPHp5y2RDKrmARyYb8J0b nM8bBuxF1yhOh1kKt2yhHxICO/q8wBLS+rEbagrME4Td2QJnVqU4jHRvniKQ2AEcvaf3 rRoVdqMEPIIR9mnL8PJCDmkajL2e+o8DiYVI1zxuzbi69BqPOcnCXARFDHsi/AacootG /hr+I37CqCSSoGhgr0ZPVLYWASDpt7SSL+m+DtGhxqv5achmON/DVbrbpKcbCiYsdaIG FrUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b=gGn6NV2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id b9-20020a056a000cc900b00690158afc78si3998105pfv.284.2023.09.15.13.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 13:25:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b=gGn6NV2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 9F3F583B6FB4; Fri, 15 Sep 2023 09:06:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234865AbjIOQFh (ORCPT + 30 others); Fri, 15 Sep 2023 12:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236369AbjIOQFd (ORCPT ); Fri, 15 Sep 2023 12:05:33 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABCC72102 for ; Fri, 15 Sep 2023 09:05:23 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-770819c1db6so149092585a.2 for ; Fri, 15 Sep 2023 09:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hefring-com.20230601.gappssmtp.com; s=20230601; t=1694793922; x=1695398722; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fk8or89hqXtZNxRZ7/0FlKmmKA1FK/3FeO0U6tr3+Qw=; b=gGn6NV2E8bWZ9T5PsSi6eJ+t8/YYsopEEcY7XaOm5C0k3Fk2qZ/raXM+RKIjzlWvZs SckIpabPqYym/8yBNqP9MoUftyiq7C+L48d0CAL24qhmTdgem64BWpWDEOGqkXuKiEKF BV6eGsq9L+4b2BkJ+CIrd2AGCKBnslwRg7WpXyMXtlDcbWe0VQPwDicDgcQnY/RXM6L4 H+6hMIjZ2KtkeJig2zea4u/iUmKfReHM/hx80UT99xXs0ZCjpg5fX5DVYd0xhb9vloIB Ekxnwh+ERVDxXaeTQppJrHRYdi8H3Vgup61ly5WcHsulsUW7jPRdBFx3IY/Snz5TP8fG Lw7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694793922; x=1695398722; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fk8or89hqXtZNxRZ7/0FlKmmKA1FK/3FeO0U6tr3+Qw=; b=isBrMBFAzHjXxIku1Px42Dm5riQXj4XnSfQp+K73RvKhtQALwtqpAvRXpHGfO4GWIr sNoKdNuuCFs8lj35rQr8G4ZbI/jTH7dB4clThfChPxexMnnTLLQOfrqPLH0asQlbglX/ iWR+PTz1QBgptr4ysP6VWxTVRo2oR+FI5QEK+2kds4Twj/7t2Nm3ejKSN4HwmTZ1gN36 KfotAZTm8gPvFj53aA7g+b4394GWXPJ2sMfxf+9QN3avcbaANYMkIz4L/SjL1Avuvrru q5xZgbYtEYV2oQE3Jb8dwC0xpZK58JujA8E+9cW8/PScJwNvgXlRed1w/RlQnMG4Rl0H XlDQ== X-Gm-Message-State: AOJu0Yyi+4zMHNwbWlHoHlg9IYh53zNAO/Oykj24DGdOmwgsmsSWtyV/ F0UpvmfTwUu32i5ag4YpLSep7DJ8vilyXVQ8XQ7UPw== X-Received: by 2002:a05:620a:280c:b0:76f:12fa:c1ac with SMTP id f12-20020a05620a280c00b0076f12fac1acmr2187595qkp.28.1694793922431; Fri, 15 Sep 2023 09:05:22 -0700 (PDT) Received: from localhost.localdomain ([50.212.55.89]) by smtp.gmail.com with ESMTPSA id v5-20020ae9e305000000b0076d9e298928sm1311009qkf.66.2023.09.15.09.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:05:21 -0700 (PDT) From: Ben Wolsieffer To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Vlastimil Babka , "Liam R. Howlett" , Andrew Morton , Oleg Nesterov , Giulio Benetti , "Matthew Wilcox (Oracle)" , Davidlohr Bueso , Ben Wolsieffer Subject: [PATCH] proc: nommu: fix empty /proc//maps Date: Fri, 15 Sep 2023 12:00:56 -0400 Message-ID: <20230915160055.971059-2-ben.wolsieffer@hefring.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 09:06:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777125006663275968 X-GMAIL-MSGID: 1777136622220295483 On no-MMU, /proc//maps reads as an empty file. This happens because find_vma(mm, 0) always returns NULL (assuming no vma actually contains the zero address, which is normally the case). To fix this bug and improve the maintainability in the future, this patch makes the no-MMU implementation as similar as possible to the MMU implementation. The only remaining differences are the lack of hold/release_task_mempolicy and the extra code to shoehorn the gate vma into the iterator. This has been tested on top of 6.5.3 on an STM32F746. Fixes: 0c563f148043 ("proc: remove VMA rbtree use from nommu") Signed-off-by: Ben Wolsieffer --- fs/proc/internal.h | 2 -- fs/proc/task_nommu.c | 37 ++++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 9dda7e54b2d0..9a8f32f21ff5 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -289,9 +289,7 @@ struct proc_maps_private { struct inode *inode; struct task_struct *task; struct mm_struct *mm; -#ifdef CONFIG_MMU struct vma_iterator iter; -#endif #ifdef CONFIG_NUMA struct mempolicy *task_mempolicy; #endif diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index 061bd3f82756..d3e19080df4a 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c @@ -188,15 +188,28 @@ static int show_map(struct seq_file *m, void *_p) return nommu_vma_show(m, _p); } -static void *m_start(struct seq_file *m, loff_t *pos) +static struct vm_area_struct *proc_get_vma(struct proc_maps_private *priv, + loff_t *ppos) +{ + struct vm_area_struct *vma = vma_next(&priv->iter); + + if (vma) { + *ppos = vma->vm_start; + } else { + *ppos = -1UL; + } + + return vma; +} + +static void *m_start(struct seq_file *m, loff_t *ppos) { struct proc_maps_private *priv = m->private; + unsigned long last_addr = *ppos; struct mm_struct *mm; - struct vm_area_struct *vma; - unsigned long addr = *pos; - /* See m_next(). Zero at the start or after lseek. */ - if (addr == -1UL) + /* See proc_get_vma(). Zero at the start or after lseek. */ + if (last_addr == -1UL) return NULL; /* pin the task and mm whilst we play with them */ @@ -218,12 +231,9 @@ static void *m_start(struct seq_file *m, loff_t *pos) return ERR_PTR(-EINTR); } - /* start the next element from addr */ - vma = find_vma(mm, addr); - if (vma) - return vma; + vma_iter_init(&priv->iter, mm, last_addr); - return NULL; + return proc_get_vma(priv, ppos); } static void m_stop(struct seq_file *m, void *v) @@ -240,12 +250,9 @@ static void m_stop(struct seq_file *m, void *v) priv->task = NULL; } -static void *m_next(struct seq_file *m, void *_p, loff_t *pos) +static void *m_next(struct seq_file *m, void *_p, loff_t *ppos) { - struct vm_area_struct *vma = _p; - - *pos = vma->vm_end; - return find_vma(vma->vm_mm, vma->vm_end); + return proc_get_vma(m->private, ppos); } static const struct seq_operations proc_pid_maps_ops = {