Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2188952ybm; Thu, 23 May 2019 12:50:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyuJfJyRayCMRwBg8R4pKwjwVt8qqDV5xvSnks213vGzMzim0Vbvh9d43UpVNgMJH/S0Z7S X-Received: by 2002:a63:6c83:: with SMTP id h125mr53759695pgc.86.1558641010587; Thu, 23 May 2019 12:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558641010; cv=none; d=google.com; s=arc-20160816; b=xoRpWf6eJQOcmOSTq/i2HPnZApp7K4rf1bzmekXVhcV0lPnrYj7esBlPxKp8wxL6eU oSWwocazaF0VdUWzOgqN4mU10hUwoJsLPSu+wQVQ/g2WC5+z7Ji2enYLj0XxXimqIkru rGE1P349SApqVn8UEt7iGVYH6L+x1tyzpVWtQR/CsrS0DlkjxAIaQ+4LgnDDw5BffMTf N7wCuatCZn6bs+0gBMzoM1JiyB4QaaDOFwOLsq/EtiaYLurVGLqdBvKMXI2eUnXemUD/ qAop1EN0hdzDHHWLpxhmavMQuhnbqCgK+dtbrDwLrdbXcKNRpNz3SIETsZfdBmsGvENm okkQ== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=k6jEOw1s8FeruI8avosu7qbsQ0qwz52OhsgSY45eojI=; b=zzbnjgdEOeA3A/12z0/fZkHSSy/ETECKkcQsXa7EG/xfZs1MdkvHcTGHg8tyqVnFNr uER2Zoi3qxPYk+NKB4pfHq4Rk0a01pX4mgML+0o6CZ5KTbzw6/4s5LjMVeqgEW5t5HPA 1O2Ruk+4yrZn/JU0JRomoFwrJghVJrMqqGwbGkILFRjFI9i20Ijy0D+MgppbtaITcp1y AyRs35AWgF+HjEPMYpl71GhGC3G5ptJORdxp1JPjm9RCNn0gP5+KEab3+5+9ZntmkAv5 me27LcwRFgCctLXPeX1TDwOxgcM5qniwjg25bBZ+oWvl7ThPQqAffLcGLtq5wkhnTlWV RK1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=RslugHZP; 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 c12si662769pgh.191.2019.05.23.12.49.54; Thu, 23 May 2019 12:50:10 -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; dkim=pass header.i=@ziepe.ca header.s=google header.b=RslugHZP; 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 S2388930AbfEWTrd (ORCPT + 99 others); Thu, 23 May 2019 15:47:33 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:38920 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388912AbfEWTrb (ORCPT ); Thu, 23 May 2019 15:47:31 -0400 Received: by mail-qt1-f195.google.com with SMTP id y42so8220604qtk.6 for ; Thu, 23 May 2019 12:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=k6jEOw1s8FeruI8avosu7qbsQ0qwz52OhsgSY45eojI=; b=RslugHZP7bdpXCoWjNFMFQd+0DDkcFEtYA5UVOgDxkZL8DRCyAf3elcV7gyLZv/N3r Au3nZzEUorYMt3KTRDl7iv9fLmChs7tw2dtFGtlmc/DBiS0nlVYvpkwT6Dfudk9xbuyz 29strAD1fMKYdTpCqzwPqg55vYFzEm91Y+tKBVbSs0faM+hj/8TQ66RkpRoR1Y2OLu78 iwOrAgEuvBQAVVKO1yr4ctVHMPrpTFGPva06945X7+4ck5IWhcPXK6FPL/djJP49AdSu /sKVmxWjm/MJ5+sSVv3VJd6I8c9VlS2/Xre1Ku7275dhaawiX2LkVSmNlfEM/zlDsEso kIzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=k6jEOw1s8FeruI8avosu7qbsQ0qwz52OhsgSY45eojI=; b=QYkL1CM0F2JqhYLoPpN0I6sAiYkAAC4SudQfnDeEdpCK2PAbtsGHdS6tGFsXV7OQdk AMJRd/8a+YNU0khWqpRxTznx15f/+mw2CvfG+Cc+kOSRKRGI93jd9X1d7ltiB1IjxP55 8w6gFte1bO2s8DBdBIbQHI2/zen/SWz9dPhgI0uysBCYWnWYQ8dmtqsw8Ny9Yi3sRPlh sCPCFw1/8qdPAwti2I1LXrocb0KI4C1/t+ayiY8scxGU4ZA/jO9+fcuRv9Lns0InFyqn 9whb3sLHyH56yOqmGyL1eC+3HhPVdkXbduSdQhKNhjhOaGE2KQICQKkjjU9dqYh4wed7 Fqtw== X-Gm-Message-State: APjAAAW6oAoGkKL0Cz4XPHjJUcWHlD7/avYXxB3rVFDK8QDP500WPEoS YKm5qgNYl88s3IrsYfn0eWm+UjW4GOw= X-Received: by 2002:ac8:3658:: with SMTP id n24mr83121461qtb.354.1558640850167; Thu, 23 May 2019 12:47:30 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-49-251.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.49.251]) by smtp.gmail.com with ESMTPSA id n190sm159698qkb.83.2019.05.23.12.47.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 May 2019 12:47:29 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1hTtgX-000173-14; Thu, 23 May 2019 16:47:29 -0300 Date: Thu, 23 May 2019 16:47:29 -0300 From: Jason Gunthorpe To: Jerome Glisse Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Leon Romanovsky , Doug Ledford , Artemy Kovalyov , Moni Shoua , Mike Marciniszyn , Kaike Wan , Dennis Dalessandro Subject: Re: [PATCH v4 0/1] Use HMM for ODP v4 Message-ID: <20190523194729.GJ12159@ziepe.ca> References: <20190522235737.GD15389@ziepe.ca> <20190523150432.GA5104@redhat.com> <20190523154149.GB12159@ziepe.ca> <20190523155207.GC5104@redhat.com> <20190523163429.GC12159@ziepe.ca> <20190523173302.GD5104@redhat.com> <20190523175546.GE12159@ziepe.ca> <20190523182458.GA3571@redhat.com> <20190523191038.GG12159@ziepe.ca> <20190523193959.GA5658@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190523193959.GA5658@redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 03:39:59PM -0400, Jerome Glisse wrote: > On Thu, May 23, 2019 at 04:10:38PM -0300, Jason Gunthorpe wrote: > > > > On Thu, May 23, 2019 at 02:24:58PM -0400, Jerome Glisse wrote: > > > I can not take mmap_sem in range_register, the READ_ONCE is fine and > > > they are no race as we do take a reference on the hmm struct thus > > > > Of course there are use after free races with a READ_ONCE scheme, I > > shouldn't have to explain this. > > Well i can not think of anything again here the mm->hmm can not > change while driver is calling hmm_range_register() Oh of course! It is so confusing because the new code makes it look like it could be changing... > so if you want i can remove the READ_ONCE() this does not change > anything. Please just write it as: /* The caller must hold a valid struct hmm_mirror to call this api, * and a valid hmm_mirror guarantees mm->hmm is valid. */ range->hmm = mm->hmm; kref_get(&range->hmm->kref); All the READ_ONCE/kref_get_not_zero/!hmm just obfuscates the reality that hmm is non-NULL and constant here or the caller is using the API wrong. kref_get will reliably oops or WARN_ON if it is misused which is a fine amount of debugging. Jason