From owner-svn-src-all@FreeBSD.ORG Wed Feb 25 09:22:00 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6D28A75; Wed, 25 Feb 2015 09:22:00 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5863E7A4; Wed, 25 Feb 2015 09:22:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1P9M07J090005; Wed, 25 Feb 2015 09:22:00 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1P9M0GF090004; Wed, 25 Feb 2015 09:22:00 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201502250922.t1P9M0GF090004@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Wed, 25 Feb 2015 09:22:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r279274 - stable/9/sys/kern X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Feb 2015 09:22:00 -0000 Author: kib Date: Wed Feb 25 09:21:59 2015 New Revision: 279274 URL: https://svnweb.freebsd.org/changeset/base/279274 Log: MFC r278963: If malloc() sleeps, Giant is dropped. Recheck for another thread doing our work. Remove unneeded check for failed M_WAITOK allocation. Modified: stable/9/sys/kern/sysv_shm.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/sysv_shm.c ============================================================================== --- stable/9/sys/kern/sysv_shm.c Wed Feb 25 09:21:04 2015 (r279273) +++ stable/9/sys/kern/sysv_shm.c Wed Feb 25 09:21:59 2015 (r279274) @@ -357,9 +357,22 @@ kern_shmat(td, shmid, shmaddr, shmflg) if (shmmap_s == NULL) { shmmap_s = malloc(shminfo.shmseg * sizeof(struct shmmap_state), M_SHM, M_WAITOK); - for (i = 0; i < shminfo.shmseg; i++) - shmmap_s[i].shmid = -1; - p->p_vmspace->vm_shm = shmmap_s; + + /* + * If malloc() above sleeps, the Giant lock is + * temporarily dropped, which allows another thread to + * allocate shmmap_state and set vm_shm. Recheck + * vm_shm and free the new shmmap_state if another one + * is already allocated. + */ + if (p->p_vmspace->vm_shm != NULL) { + free(shmmap_s, M_SHM); + shmmap_s = p->p_vmspace->vm_shm; + } else { + for (i = 0; i < shminfo.shmseg; i++) + shmmap_s[i].shmid = -1; + p->p_vmspace->vm_shm = shmmap_s; + } } shmseg = shm_find_segment_by_shmid(shmid); if (shmseg == NULL) { @@ -826,8 +839,6 @@ shmrealloc(void) return; newsegs = malloc(shminfo.shmmni * sizeof(*newsegs), M_SHM, M_WAITOK); - if (newsegs == NULL) - return; for (i = 0; i < shmalloced; i++) bcopy(&shmsegs[i], &newsegs[i], sizeof(newsegs[0])); for (; i < shminfo.shmmni; i++) {