Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp332987rwb; Thu, 27 Jul 2023 13:31:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlFzIpdS24Uy3/yjRuXmXdqlCgQPmV6y8LL6MxP9t66neMiUCKs4Sr5+MqIMhvY6t3GMlmm2 X-Received: by 2002:aa7:ca43:0:b0:522:405e:dc1a with SMTP id j3-20020aa7ca43000000b00522405edc1amr55496edt.41.1690489915388; Thu, 27 Jul 2023 13:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690489915; cv=none; d=google.com; s=arc-20160816; b=Ll/M7HTwwiGlzqq/fZ2mm22zi8ti2Qj4qizHxTlDjAmorrvb5zOUIATnPyFaBmX5EO JWLfeOSEVMKGDeZjS0iY9IgBeW6Tv5YEO3Ih5WqTDK8IVokZeZNdHeuWcHXQwYXrG+SE WUoz/9z2R6Tge/h1KvIVHB0fY2y6TojvOKBayxVKPNZdg3DpIctSi+DmoYtE85Lum9bP p5d01NITA0aSwgxEcOMzs8SWotdK5ZBHWM4K6fnrOEnsCj1dh8O7BSaEvv/Ka+3FfjKS Kv/O6uNziWtIHuNvh0cxFtkqO0FpV9d1MBHm8bRQMEn/8M0SxDJ7oDpTMStiYn7yi2YZ YXqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uMOQdXUv2yVWKzk+yt3Uwzdo1xJhdejfXEHNT0nP2D4=; fh=YKgoKmAuGYA/Su4S9gY5rfCtDTdqq178If4u9r6PrhY=; b=hrziyhkBKITYL0K92isqZvTr4OEJ/8vGzFD6nm1hHdRcy6ud+JyTjRgwdbLxGwrHmZ /Ej02zwF5D25vSE3ntLE/elgYnsuwaYzWSJOUIqHy3WoIo8jkmZhGS67ykIwhXmFzHpS R8XJtEPL7Y42E0TQ3jsGdzLRcLUTrLt6ih3yEUfe4p/SGfd5GyNx439i/1UfjdLipj6N W7Iy9HwTuu9dLilCAFY/45y8KRJH3BDehwr5i6wV+/MzXlkHKP8k4mZPM1RGpif2xtIe Ttv0NpQ88aEW689lwRqUO2fYVL0N+mooObvJ0hGMFtPgvkCvWh95M739cDhRJbbsKB5O Ufmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hnDKKPVX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j26-20020aa7ca5a000000b005221da47f59si1344261edt.172.2023.07.27.13.31.30; Thu, 27 Jul 2023 13:31:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hnDKKPVX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbjG0TAe (ORCPT + 99 others); Thu, 27 Jul 2023 15:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231807AbjG0TAU (ORCPT ); Thu, 27 Jul 2023 15:00:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD3D213A for ; Thu, 27 Jul 2023 11:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690484369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uMOQdXUv2yVWKzk+yt3Uwzdo1xJhdejfXEHNT0nP2D4=; b=hnDKKPVXtH2Kl49Ugtdpxda3aHoDgldsUkJF95vEFLlHM/J2dSWJYiMkudAdbsdXsSCIFu 4bVYaatkaHOpay+fBPmj0KdmncorKaeGnyUvr84/76+ieMfWzl0iikKOKLCayc2V57EOnx NQ49gRTHwreWzmwSiPNmcXQUN7coXxw= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-KhrzhSWBOhKAKpKk_jZiDA-1; Thu, 27 Jul 2023 14:59:28 -0400 X-MC-Unique: KhrzhSWBOhKAKpKk_jZiDA-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-4862bf9cfeaso46006e0c.1 for ; Thu, 27 Jul 2023 11:59:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690484368; x=1691089168; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uMOQdXUv2yVWKzk+yt3Uwzdo1xJhdejfXEHNT0nP2D4=; b=MPu0w7s+ikkv5o6CdLvKLmydjHM/RQmUXMbaISdJI5sh4Qdfbd7XqR2tmzE9oFAlPA wlsp6F2SMsMKo7hxJHbBlIchFVf2BgE0H0ya3kajQpg5D/a6Q0pTmOFk7zBOe6NGBO3x IJ6n26DgQdE9+KMlMixXD5jvGZyRoqJrXRcds7B02271floEehOofSmNftjL0hPZ7jIR 80ozZHcR9+pZhIJ4EP/bUduhckVbaMjwBzZ+f4XkrnfKVZ1CiL+orD+7j0J2TM0Qh2di OhvRxLbIdC4xMlRKXKXo1Da3NGHPVU/MWTcSbtHIsxPLRrQ8WKzInAgRb6zPunAM1Lsm u1IQ== X-Gm-Message-State: ABy/qLapUkoyrR0qr3naUYMHChVp4e9q0JIwI7WF3vVjISS/AFmk98W+ uMWpP1whqGBjmkIZbEfiWGbz0i3UDDeS3YtZxS1GOe6iuRL8NgSxGEN52uo/pe8CWdyhdSJH1su jzIBlIaLAHm0Hzw1QOq7zXnl3 X-Received: by 2002:a05:6122:985:b0:471:c1e9:f9bb with SMTP id g5-20020a056122098500b00471c1e9f9bbmr399988vkd.0.1690484367919; Thu, 27 Jul 2023 11:59:27 -0700 (PDT) X-Received: by 2002:a05:6122:985:b0:471:c1e9:f9bb with SMTP id g5-20020a056122098500b00471c1e9f9bbmr399978vkd.0.1690484367623; Thu, 27 Jul 2023 11:59:27 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id z4-20020a0cf244000000b0063cf8ae182esm613643qvl.60.2023.07.27.11.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 11:59:27 -0700 (PDT) Date: Thu, 27 Jul 2023 14:59:25 -0400 From: Peter Xu To: David Hildenbrand Cc: liubo , akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, hughd@google.com, willy@infradead.org Subject: Re: [PATCH] smaps: Fix the abnormal memory statistics obtained through /proc/pid/smaps Message-ID: References: <20230726073409.631838-1-liubo254@huawei.com> <5a2c9ae4-50f5-3301-3b50-f57026e1f8e8@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5a2c9ae4-50f5-3301-3b50-f57026e1f8e8@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 27, 2023 at 07:27:02PM +0200, David Hildenbrand wrote: > > > > > > This was wrong from the very start. If we're not in GUP, we shouldn't call > > > GUP functions. > > > > My understanding is !GET && !PIN is also called gup.. otherwise we don't > > need GET and it can just be always implied. > > That's not the point. The point is that _arbitrary_ code shouldn't call into > GUP internal helper functions, where they bypass, for example, any sanity > checks. What's the sanity checks that you're referring to? > > > > > The other proof is try_grab_page() doesn't fail hard on !GET && !PIN. So I > > don't know whether that's "wrong" to be used.. > > > > To me, that is arbitrary code using a GUP internal helper and, therefore, > wrong. > > > Back to the topic: I'd say either of the patches look good to solve the > > problem. If p2pdma pages are mapped as PFNMAP/MIXEDMAP (?), I guess > > vm_normal_page_pmd() proposed here will also work on it, so nothing I see > > wrong on 2nd one yet. > > > > It looks nicer indeed to not have FOLL_FORCE here, but it also makes me > > just wonder whether we should document NUMA behavior for FOLL_* somewhere, > > because we have an implication right now on !FOLL_FORCE over NUMA, which is > > not obvious to me.. > > Yes, we probably should. For get_use_pages() and friends that behavior was > always like that and it makes sense: usually it represent application > behavior. > > > > > And to look more over that aspect, see follow_page(): previously we can > > follow a page for protnone (as it never applies FOLL_NUMA) but now it won't > > (it never applies FOLL_FORCE, either, so it seems "accidentally" implies > > FOLL_NUMA now). Not sure whether it's intended, though.. > > That was certainly an oversight, thanks for spotting that. That patch was > not supposed to change semantics: > > diff --git a/mm/gup.c b/mm/gup.c > index 76d222ccc3ff..ac926e19ff72 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -851,6 +851,13 @@ struct page *follow_page(struct vm_area_struct *vma, > unsigned long address, > if (WARN_ON_ONCE(foll_flags & FOLL_PIN)) > return NULL; > > + /* > + * In contrast to get_user_pages() and friends, we don't want to > + * fail if the PTE is PROT_NONE: see gup_can_follow_protnone(). > + */ > + if (!(foll_flags & FOLL_WRITE)) > + foll_flags |= FOLL_FORCE; > + > page = follow_page_mask(vma, address, foll_flags, &ctx); > if (ctx.pgmap) > put_dev_pagemap(ctx.pgmap); This seems to be slightly against your other solution though for smaps, where we want to avoid abusing FOLL_FORCE.. isn't it.. Why read only? That'll always attach FOLL_FORCE to all follow page call sites indeed for now, but just curious - logically "I want to fetch the page even if protnone" is orthogonal to do with write permission here to me. I still worry about further abuse of FOLL_FORCE, I believe you also worry that so you proposed the other way for the smaps issue. Do you think we can just revive FOLL_NUMA? That'll be very clear to me from that aspect that we do still have valid use cases for it. The very least is if with above we should really document FOLL_FORCE - we should mention NUMA effects. But that's ... really confusing. Thinking about that I personally prefer a revival of FOLL_NUMA, then smaps issue all go away. Thanks, -- Peter Xu