9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9fans@9fans.net
Subject: Re: [9fans] imagereclaim()
Date: Sun,  2 Mar 2014 04:55:22 +0100	[thread overview]
Message-ID: <122a1b862278abf61a07a806168993ac@felloff.net> (raw)
In-Reply-To: <4578ec4fd74cba90ed1d96bfb4fa6e25@mikro.quanstro.net>

checked nix/port/page.c. your duppage() is wrong.

	/* don't dup pages with no image */
	if(p->ref == 0 || p->image == nil || p->image->notext)
		return 0;

	/*
	 *  normal lock ordering is to call
	 *  lock(&pga) before lock(p).
	 *  To avoid deadlock, we have to drop
	 *  our locks and try again.
	 */
	if(!canlock(&pga)){
		unlock(p);
		if(up)
			sched();
		lock(p);
		goto retry;
	}

you need to check p->ref != 1 instead of p->ref == 0. the page
passed to duppage() is still cached. after you unlock(p), someone
can come in and take a reference to the page from the image
cache (lookpage()), making p->ref > 1 once you get the lock back.

put an assert or print in there after the if(!canlock(&pga){} block
to check p->ref.

when this happens, the caller to duppage() (fixfault) must not
modify the page or use it in his procs segment (on copy on write)
but make a copy for itself because the other processes that
grabbed the reference is (commited to) reading it (outside of the
page lock of course, so you already lost when p->ref != 1).

--
cinap



  reply	other threads:[~2014-03-02  3:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-01 21:46 cinap_lenrek
2014-03-01 21:55 ` erik quanstrom
2014-03-01 22:22   ` cinap_lenrek
2014-03-01 22:52     ` erik quanstrom
2014-03-01 23:05       ` cinap_lenrek
2014-03-01 23:11         ` erik quanstrom
2014-03-01 23:14         ` Charles Forsyth
2014-03-02  1:21           ` cinap_lenrek
2014-03-02  3:14             ` erik quanstrom
2014-03-02  3:55               ` cinap_lenrek [this message]
2014-03-02  4:05                 ` erik quanstrom
2014-03-02  4:30                   ` cinap_lenrek
2014-03-02  9:48                 ` Charles Forsyth
2014-03-02 18:46                   ` cinap_lenrek
2014-03-02 18:53                     ` Charles Forsyth
2014-03-02 22:59                       ` Anthony Martin
2014-03-03  1:00                         ` erik quanstrom
2014-03-01 23:09     ` Charles Forsyth

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=122a1b862278abf61a07a806168993ac@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9fans@9fans.net \
    /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;
as well as URLs for NNTP newsgroup(s).