Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp346328rwb; Thu, 27 Jul 2023 13:47:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlF1k6kxF94HWQu2m/i4YQwZuYwLIhIGVRgHSvR6VlH6sn1A1azIcrKxWA8IsIfyzTHfmiq6 X-Received: by 2002:a05:6a00:1591:b0:668:9bf9:fa8d with SMTP id u17-20020a056a00159100b006689bf9fa8dmr329154pfk.16.1690490842066; Thu, 27 Jul 2023 13:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690490842; cv=none; d=google.com; s=arc-20160816; b=UGNqAgjDus00PldW4hCk80OyaeH8GakknUdPwg4NFrMkprbpR6CclMGR7Ne7e5cEbX uimpgH6E/Li+S+aPNSLoy2442d02LLSNNdACDSvbaUQtxp9tZkxH5uxsWnWxJzu81kP6 xZjo88l6vTUZSCMUczRRp8YgAUt5ZPcfP+X1Eil16oqwCvCTpadeqoj1gs0D9DbYnqie BblHvMtJ3FDmNfaWHlI7YFJvIkA3OmKmozjPGhEiSOpC+UiUZQOhC7Ssj4vYOcYMpPzL fppbWnkXbsVF+eE9OWEmCJwPvBP8ztJiPhjf2nu1Eq5ufLnvb02PqIEDMdUHO141Ss8A qcWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=M6fNNlhfLLjy6Ffe5VEja4cq8lrssWOW4WwBPHdA3f4=; fh=zMFvIk0YgVUDfTXvRfrpSWJvKzlr4xZWkau8ISv+PNs=; b=AuIMjisohUyUW8xFrK1+MpRdFQd5pVA4JDhymFV0HANy9Ro8CKsX8y3hhVyBpAeLGY nXD0c3OvlfjhckrQV2FXfCa1XoPaF4YcIJm9bdBJ/a+WPuK3vLU0iBIJDUEH51XXyg8m QRgQjH6kHvbH+YauPVAGebE82kySCVBlA7QI5qFn71L0+reP66EYCnlqjdWIpEAFHsyY H+/c9VN1Yl9ro+Oda0DkvJ6Sm6/D6gx0hxpBaPpgFaiLdbUl9uXEoiV6bAl2hiI10CXI qXT2mRRIcxvGRFP5uuXciKrdD/iBuXGPPHjJLFvFs2ug45/R7Syd0RInGRu+a7jHzb5H nLng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dobhaGqR; 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 dc11-20020a056a0035cb00b0066675b3f21esi1761454pfb.36.2023.07.27.13.47.10; Thu, 27 Jul 2023 13:47:22 -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=dobhaGqR; 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 S232062AbjG0TSj (ORCPT + 99 others); Thu, 27 Jul 2023 15:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbjG0TSh (ORCPT ); Thu, 27 Jul 2023 15:18:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9D82273D for ; Thu, 27 Jul 2023 12:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690485470; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M6fNNlhfLLjy6Ffe5VEja4cq8lrssWOW4WwBPHdA3f4=; b=dobhaGqRXEWYdD0ZcTijndX7IWIim3j+AULa7r6qdoAjLMSO534O5fXFDYHDK4+bo12Gt5 6toQm1kfPcx3ZjKu5knR0A2Qlc9hCh5HGp9Q3BjmCZZIQbtr3zAiBYAkBCwTYEPFZ+xIDu bgTqDz3COYflY4p786K8fvY1d/8Q038= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-8AEu_gAQONWMOX8SdypInw-1; Thu, 27 Jul 2023 15:17:48 -0400 X-MC-Unique: 8AEu_gAQONWMOX8SdypInw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3143ac4a562so678676f8f.2 for ; Thu, 27 Jul 2023 12:17:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690485467; x=1691090267; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=M6fNNlhfLLjy6Ffe5VEja4cq8lrssWOW4WwBPHdA3f4=; b=lrvD9cYFB8bAiofVOjT4URwrkPRJS7OMEtdu1sEPrTquRhVlGS2hcxF4h5xdEBlZmp 8/AU0BVF6ubBxuN+TYjRm53ayW4K+A47yMsP35xyh23FkNN+MpZz7n06gtw/TWWhm3pn wjAxERVR4hJSGOko9Kcs/C48DaudINf9CHr6tFj3kLhgwU8gTR6Zk1BkIVxpz03XM32l LD0vnd9WC3s4XvDj8mWPzap0p1ukB6IamvAEFxRKvhOKE01QKDNtfg94qfKU1xCIL3ht J8syVtxgiIyLVYiu0yLXC/ElKY5vM3eq8iOD9G9GpH4cL6hwIQdc0h+YHmA1YmcYrBXH 2b9w== X-Gm-Message-State: ABy/qLZty17vgr32QfRMq2vhoJUZgCmVnmrmpu+RcM9TxpJhsHg8wOQ/ i1lRTjF+XDIslZRWPJGjYxxfltTyIUij5bIE2x16mcRL8o2wL2Ys7mt3X6IlBpjMEWk2pL2fvl8 oYHQuCjvstqqHzGK2OEUhXDKE X-Received: by 2002:adf:f502:0:b0:316:f25c:d0c0 with SMTP id q2-20020adff502000000b00316f25cd0c0mr98057wro.16.1690485467576; Thu, 27 Jul 2023 12:17:47 -0700 (PDT) X-Received: by 2002:adf:f502:0:b0:316:f25c:d0c0 with SMTP id q2-20020adff502000000b00316f25cd0c0mr98042wro.16.1690485467134; Thu, 27 Jul 2023 12:17:47 -0700 (PDT) Received: from ?IPV6:2003:d8:2f43:4700:d2cd:2b81:d4e6:8b2a? (p200300d82f434700d2cd2b81d4e68b2a.dip0.t-ipconnect.de. [2003:d8:2f43:4700:d2cd:2b81:d4e6:8b2a]) by smtp.gmail.com with ESMTPSA id u17-20020a5d5151000000b0030fa3567541sm2828536wrt.48.2023.07.27.12.17.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jul 2023 12:17:46 -0700 (PDT) Message-ID: <30e58727-0a6a-4461-e9b1-f64d6eea026c@redhat.com> Date: Thu, 27 Jul 2023 21:17:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: Peter Xu Cc: liubo , akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, hughd@google.com, willy@infradead.org References: <20230726073409.631838-1-liubo254@huawei.com> <5a2c9ae4-50f5-3301-3b50-f57026e1f8e8@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] smaps: Fix the abnormal memory statistics obtained through /proc/pid/smaps In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, 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 27.07.23 20:59, Peter Xu wrote: > 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? > For example in follow_page() if (vma_is_secretmem(vma)) return NULL; if (WARN_ON_ONCE(foll_flags & FOLL_PIN)) return NULL; Maybe you can elaborate why you think we should *not* be using vm_normal_page_pmd() and instead some arbitrary GUP internal helper? I don't get it. >> >>> >>> 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.. This is GUP internal, not some arbitrary code, so to me a *completely* different discussion. > > 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. Historical these were not the semantics, so I won't change them. FOLL_FORCE | FOLL_WRITE always had a special taste to it (COW ...). > > 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. FOLL_NUMA naming was nowadays wrong to begin with (not to mention, confusing a we learned). There are other reasons why we have PROT_NONE -- mprotect(), for example. We could have a flag that goes the other way around: FOLL_IGNORE_PROTNONE ... which surprisingly then ends up being exactly what FOLL_FORCE means without FOLL_WRITE, and what this patch does. Does that make sense to you? > > 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. smaps needs to be changed in any case IMHO. And I'm absolutely not in favor of revicing FOLL_NUMA. -- Cheers, David / dhildenb