linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: GIRISH K S <ks.giri@samsung.com>
To: Jerome Glisse <j.glisse@gmail.com>, Girish KS <girishks2000@gmail.com>
Cc: "J??e Glisse" <jglisse@redhat.com>,
	"Christophe Harle" <charle@nvidia.com>,
	"Mark Hairgrove" <mhairgrove@nvidia.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Arvind Gopalakrishnan" <arvindg@nvidia.com>,
	"Jatin Kumar" <jakumar@nvidia.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"Greg Stoner" <Greg.Stoner@amd.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"Cameron Buschardt" <cabuschardt@nvidia.com>,
	"Rik van Riel" <riel@redhat.com>,
	"Paul Blinzer" <Paul.Blinzer@amd.com>,
	"Lucien Dunning" <ldunning@nvidia.com>,
	"Johannes Weiner" <jweiner@redhat.com>,
	"Haggai Eran" <haggaie@mellanox.com>,
	"Michael Mantor" <Michael.Mantor@amd.com>,
	"Laurent Morichetti" <Laurent.Morichetti@amd.com>,
	"Larry Woodman" <lwoodman@redhat.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Brendan Conoboy" <blc@redhat.com>,
	"John Bridgman" <John.Bridgman@amd.com>,
	"Subhash Gutti" <sgutti@nvidia.com>,
	"Roland Dreier" <roland@purestorage.com>,
	"Duncan Poole" <dpoole@nvidia.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"Alexander Deucher" <Alexander.Deucher@amd.com>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Andrea Arcangeli" <aarcange@redhat.com>,
	"Leonid Shamis" <Leonid.Shamis@amd.com>,
	"Sherry Cheung" <SCheung@nvidia.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Shachar Raindel" <raindel@mellanox.com>,
	"Liran Liss" <liranl@mellanox.com>,
	"Ben Sander" <ben.sander@amd.com>,
	"Joe Donohue" <jdonohue@redhat.com>,
	"Mel Gorman" <mgorman@suse.de>, "H. Peter Anvin" <hpa@zytor.com>,
	"Peter Zijlstra" <peterz@infradead.org>
Subject: Re: Re: [PATCH 05/15] HMM: introduce heterogeneous memory management v4.
Date: Mon, 03 Aug 2015 12:21:14 +0000 (GMT)	[thread overview]
Message-ID: <359230388.367691438604474011.JavaMail.weblogic@epmlwas08c> (raw)



------- Original Message -------
Sender : Jerome Glisse<j.glisse@gmail.com>
Date : Aug 03, 2015 17:26 (GMT+05:30)
Title : Re: [PATCH 05/15] HMM: introduce heterogeneous memory management v4.

On Mon, Aug 03, 2015 at 01:20:13PM +0530, Girish KS wrote:
> On 18-Jul-2015 12:47 am, "J��e Glisse" wrote:
> >

[...]

> > +int hmm_mirror_register(struct hmm_mirror *mirror)
> > +{
> > +       struct mm_struct *mm = current->mm;
> > +       struct hmm *hmm = NULL;
> > +       int ret = 0;
> > +
> > +       /* Sanity checks. */
> > +       BUG_ON(!mirror);
> > +       BUG_ON(!mirror->device);
> > +       BUG_ON(!mm);
> > +
> > +       /*
> > +        * Initialize the mirror struct fields, the mlist init and del
> dance is
> > +        * necessary to make the error path easier for driver and for hmm.
> > +        */
> > +       kref_init(&mirror->kref);
> > +       INIT_HLIST_NODE(&mirror->mlist);
> > +       INIT_LIST_HEAD(&mirror->dlist);
> > +       spin_lock(&mirror->device->lock);
> > +       list_add(&mirror->dlist, &mirror->device->mirrors);
> > +       spin_unlock(&mirror->device->lock);
> > +
> > +       down_write(&mm->mmap_sem);
> > +
> > +       hmm = mm->hmm ? hmm_ref(hmm) : NULL;
> 
> Instead of hmm mm->hmm would be the right param to be passed.  Here even
> though mm->hmm is true hmm_ref returns NULL. Because hmm is not updated
> after initialization in the beginning.

ENOPARSE ? While this can be simplified to hmm = hmm_ref(mm->hmm); I do not
see what you mean. The mm struct might already have a valid hmm field set,
and that valid hmm struct might also already be in the process of being
destroy. So hmm_ref() might either return the same hmm pointer if the hmm
object is not about to be release or NULL. But at this point there is no
certainty on the return value of hmm_ref().

I didn't mean hmm = hmm_ref(mm->hmm);. I ll try to put it in a better way. The hmm local variable is initialized to NULL in the start of the function (struct hmm *hmm = NULL;), and this is not modified till it is passed to  hmm_ref.  So hmm_ref would always return a NULL irrespective of mm->hmm is NULL or valid address.  
So  the statement hmm = mm->hmm ? hmm_ref(hmm) : NULL; should be replaced as hmm = mm->hmm ? hmm_ref(mm->hmm) : NULL;. 
Also Assume mm->hmm had a hmm object assigned to it before entering this function. Since the hmm_ref(hmm) returns NULL always, previously assigned mm->hmm address would be overwritten by the  allocation and assignment that happen below in this function.

Note that because we have the mmap sem in write mode we know it is safe
to dereference mm->hmm and even to overwrite that field it if it is being
destroy concurently.

Cheers,
J��e

             reply	other threads:[~2015-08-03 12:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 12:21 GIRISH K S [this message]
2015-08-04 14:17 ` Jerome Glisse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=359230388.367691438604474011.JavaMail.weblogic@epmlwas08c \
    --to=ks.giri@samsung.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Greg.Stoner@amd.com \
    --cc=John.Bridgman@amd.com \
    --cc=Laurent.Morichetti@amd.com \
    --cc=Leonid.Shamis@amd.com \
    --cc=Michael.Mantor@amd.com \
    --cc=Paul.Blinzer@amd.com \
    --cc=SCheung@nvidia.com \
    --cc=aarcange@redhat.com \
    --cc=airlied@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=arvindg@nvidia.com \
    --cc=ben.sander@amd.com \
    --cc=blc@redhat.com \
    --cc=cabuschardt@nvidia.com \
    --cc=charle@nvidia.com \
    --cc=dpoole@nvidia.com \
    --cc=girishks2000@gmail.com \
    --cc=haggaie@mellanox.com \
    --cc=hpa@zytor.com \
    --cc=j.glisse@gmail.com \
    --cc=jakumar@nvidia.com \
    --cc=jdonohue@redhat.com \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=jweiner@redhat.com \
    --cc=ldunning@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liranl@mellanox.com \
    --cc=lwoodman@redhat.com \
    --cc=mgorman@suse.de \
    --cc=mhairgrove@nvidia.com \
    --cc=peterz@infradead.org \
    --cc=raindel@mellanox.com \
    --cc=riel@redhat.com \
    --cc=roland@purestorage.com \
    --cc=sgutti@nvidia.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox