Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1298494rwb; Thu, 10 Nov 2022 14:11:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM4jyeAe41+i2OeYZalZdjZgvWfxLq3bxbrIRjecgdE9AuGloRz4ZI7RQfNNyTJCAI2Rjg6a X-Received: by 2002:a05:6402:606:b0:463:bef9:b64a with SMTP id n6-20020a056402060600b00463bef9b64amr3654909edv.422.1668118288785; Thu, 10 Nov 2022 14:11:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668118288; cv=none; d=google.com; s=arc-20160816; b=ZQNBzYhP0D1am+zB1RsaO71Q3uM4LlvdgdEcgv0YyZqeUg2Mw7W+HrftEW8Bkmql/4 kV0RXnKdu9JoyEjti8GBJcHSvwaQ5WUsjAYZjccA2h2AmNshQh/PzIfJO/q1S9F7XvqS 2b8ghjIvaBcb3RwCCrqLILfDH1uF+YrpnpUNKl0g3m+f+zPJxoFgFpcvhnu+7ijjQ/nA 9KtMX4aJtPoTtUjWJOL/oDmU79KferwTe1UfxeayjRXJhlt36xtR+88AHRlGGHmNN4BD 34JuFUwHm7wD3+J2linTGKhNGOfWW3f55JJhJdzd5tumLLDID/wh7yKr/jSku0AMhAo0 7I8A== 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=D15edAydLnVTLab35CTaj6y/l/B1rXYhW6svf54p2rE=; b=D6ifV0GoN/4YjDfFb/2pwjumVKueaY6FGDGoQTm+qNj570tLlD4QsaNI3cyehPDmOp Pg6CTdPqBZP/ap7gVVXfhSZ175R6tlAH4ZBGDrjGsGveBtmmxjxHCQ2X2CI1/sBbZh4d LfdJes1H/8K76XBpSxGZzm4A5t+lCrva3GyfcEvzlnSXAC+IyJj1ysr+iG0aZ6/hsxuk hJ5MB16EQO1ETs9zXhNyCpgua9fVZ5skCWFcR2Smpn2kuhxoy0Tr7AoA5nqwei/bi+de qrDGeFzepDiYcpRxmlNuN8OOAv7cUpHi4zfakxfVDs80HAY9Z5CEz3RbJ2zB/7u0bv12 Vv+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e3srHlVJ; 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 k9-20020a17090646c900b007ae4717bf1esi329539ejs.99.2022.11.10.14.11.06; Thu, 10 Nov 2022 14:11:28 -0800 (PST) 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=e3srHlVJ; 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 S231995AbiKJV24 (ORCPT + 92 others); Thu, 10 Nov 2022 16:28:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbiKJV2y (ORCPT ); Thu, 10 Nov 2022 16:28:54 -0500 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 113159D for ; Thu, 10 Nov 2022 13:27:54 -0800 (PST) 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-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-558-Ok3OKilTN2eynda0tkOhUw-1; Thu, 10 Nov 2022 16:27:53 -0500 X-MC-Unique: Ok3OKilTN2eynda0tkOhUw-1 Received: by mail-qt1-f199.google.com with SMTP id s14-20020a05622a1a8e00b00397eacd9c1aso2353419qtc.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=7g/KDNjSpgK/qXhyhzYdPfDIQRxXsisVtmskKufUzTUY6ac9Dx25aSmmRXL7HqZzRX qb+/Wx1bqi+UeaNv9DFR1pg04eMNUlfFgPHfkqqb/46FZLRBrC633jcltMpDmqp8zbZA Upz4y1/BK0sy2GJCBpHehzBAi+YAoISoI5uFYnSqgtIAgvJuvJbYwxOV08UUeHsgXLgh XQikS4NjRWu4qcv8kGL2AqcqzO880PjMbV4ZfkqKPPrsZe3u6kYtKm8KDqcHyksjYycj ABFTNSr8Ye6v4AZv2Ma44G9RZEWMO0m2OucGzT/A/I+WhENoLOhYnlscrPRKTAgzIaqC zezA== X-Gm-Message-State: ACrzQf3LA5r34Sm9H0P4//WPGcCIuBOmQgyo7vB2iXTSQXuFekCBhHeB t5Ddlf13J2VDFNuRbM+mvVB4E/6XdnfiwH6f6O6R9HjzwHdl5TrQ5AyLwONQCQ6QViW+hZyXtxC dvR4iN6Ptg+m4kRRHmv72VJIS X-Received: by 2002:ac8:53ce:0:b0:3a5:122:fb79 with SMTP id c14-20020ac853ce000000b003a50122fb79mr1948886qtq.452.1668115672719; Thu, 10 Nov 2022 13:27:52 -0800 (PST) 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 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <7140E1D7-B1B9-4462-ADDA-E313A7A90A68@gmail.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_H2,SPF_HELO_NONE,SPF_NONE 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 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