Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp51000yba; Tue, 23 Apr 2019 19:17:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyx/qkdHwWjZXDuxOp0yCw2KmYdZXz+yOxGNXyZyT0OCGGRE2e7Qpqh4/mGjAUVJ+Wd1/Vq X-Received: by 2002:a17:902:d701:: with SMTP id w1mr28179053ply.124.1556072247253; Tue, 23 Apr 2019 19:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556072247; cv=none; d=google.com; s=arc-20160816; b=n+f4piVu7GcDd3ikhWz4oJAAgqrNEpuhYuVsMPSX+WEW+TkVwJ2V9LBhC48LzxhmaB M+Ih9IDtegS7ALqP0jRVcqebqdGWTVVWnHIks0vMb96Bf+IVZjSPOlp7ZkMoX2w3VR4Z 60Rd4IVQAO3QzI2wgxbYOiZD9OobHCSURMycR3vS01Q9qPk7oswRDAWcIsYlhHEqRWji Zbxm1G5qsmDoqG5qV8Du6iFVUX3b0oaEc9w2DTksO8w9FfUzozVi/+nAXAvTxh4jOFuU qBXf25h8PgU5kl5THaCKQKESSSCLTCmDWHaOz10CrI354CGTqMkdqjV/tDtaEgln4YTA cU9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date; bh=kQmhkHN5hyeJimxYTaaldIckakDurZeywqT4DVGXRH4=; b=ZF6RhfPJzvuLjCzdPYB/MPPZPCSVq/sCQ/8wJ8jAWiheSHns+76y7Iod+vTTbU6u31 EkbuFYNJeTxRpY9CqQ20qpXu7ttmMEvVn5M3OyUjsRXGldq7Zjje4g32EBtWxWMdP3hm TGzyVDl10hg721MudwszL/TlIbSMCh+f5+ZgryGM/tr3UNyiMTfXZrOLV6zc3odDkXxf 9elem/9Qn0C/yD7x289tCBty8jkYkzB0FTcXu0E29Sv/k26WiXp2pYNwqyuoqRc6LlLc EPpaMBFCkSyZNl3WLpIZd5OaLn25b3gKI5fGjzjVxb9hd/V+TvcGHQDbLfTPX25pIYGy b8sA== 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 x6si2526206pln.74.2019.04.23.19.17.11; Tue, 23 Apr 2019 19:17:27 -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 S1729310AbfDXCPz convert rfc822-to-8bit (ORCPT + 99 others); Tue, 23 Apr 2019 22:15:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:43690 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726920AbfDXCPz (ORCPT ); Tue, 23 Apr 2019 22:15:55 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9AF78AC63; Wed, 24 Apr 2019 02:15:53 +0000 (UTC) Date: Tue, 23 Apr 2019 19:15:44 -0700 From: Davidlohr Bueso To: Daniel Jordan Cc: Christophe Leroy , akpm@linux-foundation.org, Alexey Kardashevskiy , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Paul Mackerras , Christoph Lameter , linuxppc-dev@lists.ozlabs.org, jgg@mellanox.com Subject: Re: [PATCH 5/6] powerpc/mmu: drop mmap_sem now that locked_vm is atomic Message-ID: <20190424021544.ygqa4hvwbyb6nuxp@linux-r8p5> Mail-Followup-To: Daniel Jordan , Christophe Leroy , akpm@linux-foundation.org, Alexey Kardashevskiy , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Paul Mackerras , Christoph Lameter , linuxppc-dev@lists.ozlabs.org, jgg@mellanox.com References: <20190402204158.27582-1-daniel.m.jordan@oracle.com> <20190402204158.27582-6-daniel.m.jordan@oracle.com> <964bd5b0-f1e5-7bf0-5c58-18e75c550841@c-s.fr> <20190403164002.hued52o4mga4yprw@ca-dmjordan1.us.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20190403164002.hued52o4mga4yprw@ca-dmjordan1.us.oracle.com> User-Agent: NeoMutt/20180323 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 03 Apr 2019, Daniel Jordan wrote: >On Wed, Apr 03, 2019 at 06:58:45AM +0200, Christophe Leroy wrote: >> Le 02/04/2019 ? 22:41, Daniel Jordan a ?crit?: >> > With locked_vm now an atomic, there is no need to take mmap_sem as >> > writer. Delete and refactor accordingly. >> >> Could you please detail the change ? > >Ok, I'll be more specific in the next version, using some of your language in >fact. :) > >> It looks like this is not the only >> change. I'm wondering what the consequences are. >> >> Before we did: >> - lock >> - calculate future value >> - check the future value is acceptable >> - update value if future value acceptable >> - return error if future value non acceptable >> - unlock >> >> Now we do: >> - atomic update with future (possibly too high) value >> - check the new value is acceptable >> - atomic update back with older value if new value not acceptable and return >> error >> >> So if a concurrent action wants to increase locked_vm with an acceptable >> step while another one has temporarily set it too high, it will now fail. >> >> I think we should keep the previous approach and do a cmpxchg after >> validating the new value. Wouldn't the cmpxchg alternative also be exposed the locked_vm changing between validating the new value and the cmpxchg() and we'd bogusly fail even when there is still just because the value changed (I'm assuming we don't hold any locks, otherwise all this is pointless). current_locked = atomic_read(&mm->locked_vm); new_locked = current_locked + npages; if (new_locked < lock_limit) if (cmpxchg(&mm->locked_vm, current_locked, new_locked) == current_locked) /* ENOMEM */ > >That's a good idea, and especially worth doing considering that an arbitrary >number of threads that charge a low amount of locked_vm can fail just because >one thread charges lots of it. Yeah but the window for this is quite small, I doubt it would be a real issue. What if before doing the atomic_add_return(), we first did the racy new_locked check for ENOMEM, then do the speculative add and cleanup, if necessary. This would further reduce the scope of the window where false ENOMEM can occur. >pinned_vm appears to be broken the same way, so I can fix it too unless someone >beats me to it. This should not be a surprise for the rdma folks. Cc'ing Jason nonetheless. Thanks, Davidlohr