From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2DFFC433FE for ; Thu, 10 Nov 2022 21:27:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAD276B0074; Thu, 10 Nov 2022 16:27:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5E178E0002; Thu, 10 Nov 2022 16:27:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D24838E0001; Thu, 10 Nov 2022 16:27:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C15776B0074 for ; Thu, 10 Nov 2022 16:27:55 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9C0211C616D for ; Thu, 10 Nov 2022 21:27:55 +0000 (UTC) X-FDA: 80118820110.08.87B28CB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 2C3001C0003 for ; Thu, 10 Nov 2022 21:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668115674; 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=D15edAydLnVTLab35CTaj6y/l/B1rXYhW6svf54p2rE=; b=e3srHlVJD4WATsBO42i/PTF78ZnGOuvEzBJKIqtTk40B13nqWBM+OPDu5MUTBF3PRgFWOO BJBRNH0BDh8kFFkKcu2BNeNdSAdDnWov74EafLqb75xe/qUIf8zYCBRHqAZ4iyz0y2ZpLe QMTQKmcOWzZb/8XbdulDd9BgYJdljQQ= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-237-SkPvSLddOv-UEgHKjQk_rA-1; Thu, 10 Nov 2022 16:27:53 -0500 X-MC-Unique: SkPvSLddOv-UEgHKjQk_rA-1 Received: by mail-qk1-f197.google.com with SMTP id h8-20020a05620a284800b006b5c98f09fbso3194356qkp.21 for ; Thu, 10 Nov 2022 13:27:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=D15edAydLnVTLab35CTaj6y/l/B1rXYhW6svf54p2rE=; b=mkE5Iyza26z2ESTUa/EfSmzalKJXuJe8XDR9RrYztk+W3ohUvHzD0Lssxd1/D6qpqU g3854NN/NH0knAbpUFwrK+pTJubFYIGEqdUSOwX/YxXEALWnlkg9kNQ0I05D0Q1ZcoFc F9+dx7A0ebTSWT3vtoLsgP0oMVR82BJpV/qzI26mCiPZ0Z2F9FLxt4OP25fXPsIhKist Li/RwJW+nNjruUlITmULj/LuEiu6HgLyg3eosSb0r0a6tHrY1Y1CqiWKxbBvtYjRm0LY 9x1+jQ+hLX9exDWb4Ent1KgFFzLYOZQDQ9XpRilyjIm1n/6YHbVn4G2gIxgFB/F0hSUH oDdQ== X-Gm-Message-State: ACrzQf2Uh50ZDHhPNg/deimhXhjEduvQRCI8IaZ9ZhiaiLrJdtabij8F PlmLKrx/U/8UmeElid5462W1cVuZt8KYao+cALX9yPODOSHlawr6W7yFngovmJwqe9uehvdVilg W3RmLfOyTOpU= X-Received: by 2002:ac8:53ce:0:b0:3a5:122:fb79 with SMTP id c14-20020ac853ce000000b003a50122fb79mr1948894qtq.452.1668115672720; Thu, 10 Nov 2022 13:27:52 -0800 (PST) X-Google-Smtp-Source: AMsMyM4YgTRj2nHC6NVvXZhdEJ/UnFY/bgoDMZtxAZubI5MaeEgeSKEQau4bSHlu5U0LdokZQ5DbKg== X-Received: by 2002:ac8:53ce:0:b0:3a5:122:fb79 with SMTP id c14-20020ac853ce000000b003a50122fb79mr1948872qtq.452.1668115672499; Thu, 10 Nov 2022 13:27:52 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id t19-20020ac865d3000000b003a527d29a41sm186487qto.75.2022.11.10.13.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 13:27:51 -0800 (PST) Date: Thu, 10 Nov 2022 16:27:50 -0500 From: Peter Xu To: Nadav Amit Cc: Mike Kravetz , Linux-MM , kernel list , Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Rik van Riel , Vlastimil Babka , Matthew Wilcox , Andrew Morton Subject: Re: [PATCH v8 2/2] mm: remove zap_page_range and change callers to use zap_vma_range Message-ID: References: <20221108011910.350887-1-mike.kravetz@oracle.com> <20221108011910.350887-3-mike.kravetz@oracle.com> <7140E1D7-B1B9-4462-ADDA-E313A7A90A68@gmail.com> MIME-Version: 1.0 In-Reply-To: <7140E1D7-B1B9-4462-ADDA-E313A7A90A68@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668115675; a=rsa-sha256; cv=none; b=XHxubnkHVM4GULR2270Fl1sA+fZ8viOo883tyPaFISt77/Brb9025cSjZIdluXXW+X0qko x4CWOLs3HUyDa4T2RArTDhNK7fdprksKIn3fWtO/gIitooSjy4O7cOBOjfq6dPFgfhY/ju MnoNvGBTycfeDYOmcgM2EgInx5cSnRY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e3srHlVJ; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668115675; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D15edAydLnVTLab35CTaj6y/l/B1rXYhW6svf54p2rE=; b=6s/nsFTPSsfPlvORa8moz7ri+B8V/GLwsaVThdU09wGYbijZd2hsEyIrAp5s1Wq0clSRSu LdKcPTVlnX8rxK30Jp9ogb2l+OWewGRYFB2o1we4sP44tJfJz6WwOWrp27Ydao4NBTmc9x 9vHRdt/ubdTtah6089jm2aX3Q+lTB/w= Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e3srHlVJ; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: mntmzwx7dj7gob857dbnkxe8edpbfwki X-Rspamd-Queue-Id: 2C3001C0003 X-HE-Tag: 1668115674-446128 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, Nadav, On Thu, Nov 10, 2022 at 01:09:43PM -0800, Nadav Amit wrote: > But, are the callers really able to guarantee that the ranges are all in a > single VMA? I am not familiar with the users, but how for instance > tcp_zerocopy_receive() can guarantee that no one did some mprotect() of some > sorts that caused the original VMA to be split? Let me try to answer this one for Mike.. We have two callers in tcp zerocopy code for this function: tcp_zerocopy_vm_insert_batch_error[2095] zap_page_range(vma, *address, maybe_zap_len); tcp_zerocopy_receive[2237] zap_page_range(vma, address, total_bytes_to_map); Both of them take the mmap lock for read, so firstly mprotect is not possible. The 1st call has: mmap_read_lock(current->mm); vma = vma_lookup(current->mm, address); if (!vma || vma->vm_ops != &tcp_vm_ops) { mmap_read_unlock(current->mm); return -EINVAL; } vma_len = min_t(unsigned long, zc->length, vma->vm_end - address); avail_len = min_t(u32, vma_len, inq); total_bytes_to_map = avail_len & ~(PAGE_SIZE - 1); if (total_bytes_to_map) { if (!(zc->flags & TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT)) zap_page_range(vma, address, total_bytes_to_map); Here total_bytes_to_map comes from avail_len <--- vma_len, which is a min() of the rest vma range. So total_bytes_to_map will never go beyond the vma. The 2nd call uses maybe_zap_len as len, we need to look two layers of the callers, but ultimately it's something smaller than total_bytes_to_map we discussed. Hopefully it proves 100% safety on tcp zerocopy. -- Peter Xu