Received: by 10.192.165.148 with SMTP id m20csp3882931imm; Mon, 23 Apr 2018 14:17:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+cbZL3rc3V436Oisg95ZkeArgysYrjxkQgErZg8MZhXFZxGF1E+b9mtfzrO7CxoSe8oWcQ X-Received: by 2002:a17:902:3281:: with SMTP id z1-v6mr22012567plb.226.1524518236820; Mon, 23 Apr 2018 14:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524518236; cv=none; d=google.com; s=arc-20160816; b=ODCa30rqjhKlKmEkbi5MiGzblSfhH7x/OU7iGmgfLLGZ58gtvmhVMhScpivqECKCCM Njy7MIjBiI6yUYSLMrbX5OnNXc7v+TQMB/bUa/7uZiJMbRZQDxUUcvp9l08Rpw0SMZic mFhMOhtqZfq9RAhjqgyKQCUYpvm8rI41TnxX0HFw9BZ3ZYwRZ2LH8e7cibVgmgYSfRr1 CVxTUYn3GiYd4u1NvWTnRPWUq7BjkhHMc38kw4zDdj0R7hMXoQoD1UyTOcmQyeip1Z5a N2FQOyijBPeyYwbU62yHnsv09n3UjZ1pL/ev12aGXBcun1CzrmkGreWkIOKUiL6PERIc BsZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :arc-authentication-results; bh=A52EOVB/JqWdKPIhzum9MvGnC3lyF0pk/bA6PikPJ3I=; b=ttc6+W0O/GpqCEbrGGwM4yTkviqYV+8klfr6YlueI3470xJXGUz20TLtqEIeLTl4f+ uSJQXxwbVg98mEgoEwU3+Q9cNc8lfMf2U/Job7cXDmzSAtQlbNOuyXGEzeJKPpEpgHvB tHT1ZQyT+CDvBS3lvyWGVtRFOkJiBJHJB5ehV6IXr17QQw14OKiXvdnQzzVQMx9ffZwc 9e6v/tiL85EJcnsQv5VM8fKfDab5M5tctQPQeIxA3o0wcY+OTcPLiemEMhPSMrlUYydu YMVX1x7q0AkN/hkhHNGwHvlsW3pKZraWXle/OhwDmkMV6fcYxpNkcojc7FktOiAKmzB8 heng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q87si12246322pfa.272.2018.04.23.14.17.01; Mon, 23 Apr 2018 14:17:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932448AbeDWVOi (ORCPT + 99 others); Mon, 23 Apr 2018 17:14:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:50938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932191AbeDWVOf (ORCPT ); Mon, 23 Apr 2018 17:14:35 -0400 Received: from [192.168.0.217] (c-71-202-137-17.hsd1.ca.comcast.net [71.202.137.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 93EF221782; Mon, 23 Apr 2018 21:14:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93EF221782 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org Subject: Re: [PATCH net-next 0/4] mm,tcp: provide mmap_hook to solve lockdep issue To: Eric Dumazet , "David S . Miller" Cc: netdev , linux-kernel , Soheil Hassas Yeganeh , Eric Dumazet , linux-mm , Linux API References: <20180420155542.122183-1-edumazet@google.com> From: Andy Lutomirski Message-ID: <9ed6083f-d731-945c-dbcd-f977c5600b03@kernel.org> Date: Mon, 23 Apr 2018 14:14:33 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180420155542.122183-1-edumazet@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/20/2018 08:55 AM, Eric Dumazet wrote: > This patch series provide a new mmap_hook to fs willing to grab > a mutex before mm->mmap_sem is taken, to ensure lockdep sanity. > > This hook allows us to shorten tcp_mmap() execution time (while mmap_sem > is held), and improve multi-threading scalability. > I think that the right solution is to rework mmap() on TCP sockets a bit. The current approach in net-next is very strange for a few reasons: 1. It uses mmap() as an operation that has side effects besides just creating a mapping. If nothing else, it's surprising, since mmap() doesn't usually do that. But it's also causing problems like what you're seeing. 2. The performance is worse than it needs to be. mmap() is slow, and I doubt you'll find many mm developers who consider this particular abuse of mmap() to be a valid thing to optimize for. 3. I'm not at all convinced the accounting is sane. As far as I can tell, you're allowing unprivileged users to increment the count on network-owned pages, limited only by available virtual memory, without obviously charging it to the socket buffer limits. It looks like a program that simply forgot to call munmap() would cause the system to run out of memory, and I see no reason to expect the OOM killer to have any real chance of killing the right task. 4. Error handling sucks. If I try to mmap() a large range (which is the whole point -- using a small range will kill performance) and not quite all of it can be mapped, then I waste a bunch of time in the kernel and get *none* of the range mapped. I would suggest that you rework the interface a bit. First a user would call mmap() on a TCP socket, which would create an empty VMA. (It would set vm_ops to point to tcp_vm_ops or similar so that the TCP code could recognize it, but it would have no effect whatsoever on the TCP state machine. Reading the VMA would get SIGBUS.) Then a user would call a new ioctl() or setsockopt() function and pass something like: struct tcp_zerocopy_receive { void *address; size_t length; }; The kernel would verify that [address, address+length) is entirely inside a single TCP VMA and then would do the vm_insert_range magic. On success, length is changed to the length that actually got mapped. The kernel could do this while holding mmap_sem for *read*, and it could get the lock ordering right. If and when mm range locks ever get merged, it could switch to using a range lock. Then you could use MADV_DONTNEED or another ioctl/setsockopt to zap the part of the mapping that you're done with. Does this seem reasonable? It should involve very little code change, it will run faster, it will scale better, and it is much less weird IMO.