From patchwork Wed Aug 1 07:34:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 952624 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41h2yx0NBtz9s3q for ; Thu, 2 Aug 2018 18:14:47 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 482721A95F2 for ; Thu, 2 Aug 2018 10:14:44 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id AE0293E61BA for ; Thu, 2 Aug 2018 10:14:42 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id 66092601A67 for ; Thu, 2 Aug 2018 10:14:40 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="42978697" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 Aug 2018 16:14:37 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 0154A4B6ADE7; Thu, 2 Aug 2018 16:14:37 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Thu, 2 Aug 2018 16:14:39 +0800 From: Xiao Yang To: Date: Wed, 1 Aug 2018 15:34:53 +0800 Message-ID: <1533108893-13078-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 0154A4B6ADE7.AB53D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.5 required=7.0 tests=DATE_IN_PAST_24_48 autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: ebiggers@google.com Subject: [LTP] [PATCH] syscalls/shmctl05.c: Fix ENOSPC error X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Running shmctl05 got the following error on some distros(e.g. RHEL7.5): ------------------------------------------------------ tst_safe_sysv_ipc.c:111: BROK: shmctl05.c:51: shmget(61455, 4096, 3c0) failed: ENOSPC shmctl05.c:104: WARN: pthread_join(..., (nil)) failed: EDEADLK tst_safe_sysv_ipc.c:111: BROK: shmctl05.c:81: shmget(61455, 4096, 3c0) failed: ENOSPC ------------------------------------------------------- From shmctl(2) manpage, shmctl(IPC_RMID) just marks a shm segment to be destroyed, and the segment will only actually be destroyed after the last process detaches it (i.e., when the shm_nattch member of the associated structure shmid_ds is zero). So it is possible for the number of created shm segments to exceed the system-wide maximum number (e.g. shmmni is 4096) if only shmctl(IPC_RMID) has been called. From shmdt(2) manpage, a successful shmdt(2) call will decrement the shm_nattch by one. So we should call shmdt(2) to decrement the shm_nattch to zero before calling shmctl(IPC_RMID). Add shmdt(2) to ensure that all shm segments are actually destroyed. Signed-off-by: Xiao Yang --- testcases/kernel/syscalls/ipc/shmctl/shmctl05.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c index a960cc9..0eb0776 100644 --- a/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c +++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c @@ -92,6 +92,8 @@ static void do_test(void) "Unexpected remap_file_pages() error"); } tst_fzsync_wait_a(&fzsync_pair); + /* ensure that a shm segment will actually be destroyed */ + SAFE_SHMDT(addr); } tst_res(TPASS, "didn't crash");