From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bk0-f45.google.com (mail-bk0-f45.google.com [209.85.214.45]) by dpdk.org (Postfix) with ESMTP id 4E4D21F3 for ; Thu, 12 Sep 2013 17:28:11 +0200 (CEST) Received: by mail-bk0-f45.google.com with SMTP id mx11so4233696bkb.4 for ; Thu, 12 Sep 2013 08:28:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:organization:to:subject:date:user-agent:cc :references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id; bh=08EQFRzQFFmbbZwkL+3MvXJ/bTb3VB1tgiWxy10C0/k=; b=SxdWtSsWFOa9nfjHceBj8twB+IhJw3SuDV8xyTrj5RvsXiLSGNisz8VM6iUcLeuSDD 6yrGBEvka0OL2WSk/5+aTj/Cys+IfrVc2tCCtvX38BvQJTSUwLvExUN0tDwXQi+JdhVv MejC5wsdmytNpw0+apdUWCKkzy3pgqpeh5FDj13szPWMG/IlU8V3/Pnv9Z4jmzAjTQTd HeMUI9bAG1+DnB0xCjSMPOJQLhhxkAODy15wJJivBKa8z/Dvh3GIhgZxGad906dioZuU dKT+4HJCnw3pyX3ZsYU0un2eN8egSBBpj7wJRMX5cupzUgZTJlmiMF2fxazVXSLKhm4E AKLA== X-Gm-Message-State: ALoCoQk7nPkaRvaKGwevuxIOEFbbhPta7l2dtkKeYvZwMJgddZE9AMb7JLh/g4s14Fwwuwerpf1A X-Received: by 10.204.167.74 with SMTP id p10mr7154278bky.26.1378999727776; Thu, 12 Sep 2013 08:28:47 -0700 (PDT) Received: from angus.localnet (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id pk7sm1422864bkb.2.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Sep 2013 08:28:47 -0700 (PDT) From: Thomas Monjalon Organization: 6WIND To: Tetsuya Mukawa Date: Thu, 12 Sep 2013 17:28:46 +0200 User-Agent: KMail/1.13.7 (Linux/3.2.0-4-amd64; KDE/4.8.4; x86_64; ; ) References: <1378280075-2076-1-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1378280075-2076-1-git-send-email-mukawa@igel.co.jp> MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201309121728.46471.thomas.monjalon@6wind.com> Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH] pci: fix closing an unopened file descriptor X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Sep 2013 15:28:11 -0000 04/09/2013 09:34, Tetsuya Mukawa : > If CONFIG_RTE_EAL_UNBIND_PORTS is set and virtio-net is used, an unopened > file descriptor will be illegally closed in the finalized phase of EAL. > The fix adds a correct initial value to the file descriptor, and check it > before closing it. > > Signed-off-by: Tetsuya Mukawa Thanks for the patch. I have reproduced the issue only once. It seems that fd 0 is open most of the time. But the patch seems OK so I applied it with light modifications: --- pci: fix closing an unopened file descriptor If CONFIG_RTE_EAL_UNBIND_PORTS is set and a non Intel PMD is used, an unopened file descriptor will be illegally closed in the finalized phase of EAL. The fix adds a correct initial value to the file descriptor, and check it before closing it. Signed-off-by: Tetsuya Mukawa Acked-by: Thomas Monjalon --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -514,6 +514,7 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, } memset(dev, 0, sizeof(*dev)); + dev->intr_handle.fd = -1; dev->addr.domain = domain; dev->addr.bus = bus; dev->addr.devid = devid; @@ -718,7 +719,7 @@ pci_exit_process(struct rte_pci_device *dev) RTE_LOG(ERR, EAL, "Error with munmap\n"); return -1; } - if (close(dev->intr_handle.fd) == -1){ + if ((dev->intr_handle.fd != -1) && (close(dev->intr_handle.fd) == -1)) { RTE_LOG(ERR, EAL, "Error closing interrupt handle\n"); return -1; }