Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4845481rdb; Fri, 15 Sep 2023 14:16:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdoq3lxXP9YiVzI/9Vjcv8jfnt+icRAM2MJ/sOeClq3SoMLqpl3ICGKGBPj2zLxAdwlIr7 X-Received: by 2002:a17:902:d2d2:b0:1c4:bc8:4b64 with SMTP id n18-20020a170902d2d200b001c40bc84b64mr3186404plc.5.1694812599488; Fri, 15 Sep 2023 14:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694812599; cv=none; d=google.com; s=arc-20160816; b=N0nKXprD7jhzD1jRQOHZscbQYTYll4Yv8vlUihcj/RNYCuFGIAp7vr/+vPY5kYg80T 0XLB1OX1T+BzYrkpzLJA8J43a/rpIR6eHJiYjwSSkmxrVTrR/M4d4cqjhQxWAz15fQh7 2Npp3entFRcrQU7mNqTJd80aDbfFVd6OPXJAY1iU+fuCTbc+SAgI/cKun67IzUPQI+p8 jeRvjkkJ9oiXVQL7TxAZ1dMfU9Q3oXJa4X+wdb5oA3fJTwMOLigJcF22hJoraPEqF0G6 TgoWGecscI+B7CQM9KKNDmRjYAEylOEKEigxVcy+FkozfXA0T8DHEHI4RXSUFNC3K5dw 8cgA== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id j4-20020a170903028400b001bf7289d2b2si3849547plr.315.2023.09.15.14.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 14:16:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; 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:2 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 agentk.vger.email (Postfix) with ESMTP id 693978225F3D; Fri, 15 Sep 2023 09:06:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234741AbjIOQFh (ORCPT + 99 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 Content-Transfer-Encoding: 8bit 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 09:06:12 -0700 (PDT) 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 = { -- 2.42.0