From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3F07DA0471 for ; Mon, 12 Aug 2019 12:04:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0C02F1BE87; Mon, 12 Aug 2019 12:04:00 +0200 (CEST) Received: from mail-vs1-f67.google.com (mail-vs1-f67.google.com [209.85.217.67]) by dpdk.org (Postfix) with ESMTP id B151E1BDFD for ; Mon, 12 Aug 2019 12:03:56 +0200 (CEST) Received: by mail-vs1-f67.google.com with SMTP id q16so3738147vsm.2 for ; Mon, 12 Aug 2019 03:03:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6gdYANRzB0oQ3XxPh+4/8m6ghsShS7Q3qpCDfdW8jhQ=; b=bpL6DB+KaIuGMcgCtWQeaWPbBkvRhj0GJKghosN37anypTfRsQXbfZ/yESUpJjGr/6 MOQV8lXCdFrgLJMzKIA7VxMgfAgoBAaigcw6nmkbreYoikri+d7aLlEaqYLi0VwTZtui Nr/HieuC23F+WZ5YbYWNUqiy8fZA0mjudcZKLzM7KN01aahviLjxkwDSBzvJhWEdEPwj 7JqPs0ZuNSCg6/DthFrDaN5fnMQle7dRsKcQTtZ9MAuEfFqss9nPCkMEAhw46INXRb5f dgyjdHCtJmOCo29yx04XDGgWOYadNdz8AR0TZotVJj6sgSygiWx6GG/E1OhsPttv1tnc veTA== X-Gm-Message-State: APjAAAVfdPxAxQ4skeWh7CA22+T3x6PabdWTxmRgbTKIwZX7iNlDkw1r uwunUY0fIPc1b+ivb11W1FSYaLBtr98MQUR0MHBI9A== X-Google-Smtp-Source: APXvYqy2YzLDIjjtz33rWyEMN4+hX/c3t7RL513FvTs6VnTsuPz2buNzWTYLQWcM9ChdCnhbOfZVbvJXp9x5+nWFimU= X-Received: by 2002:a67:3251:: with SMTP id y78mr11837445vsy.39.1565604236007; Mon, 12 Aug 2019 03:03:56 -0700 (PDT) MIME-Version: 1.0 References: <67a795e77bc9f5ac79ab78a878ae19abbead9f50.1563984454.git.anatoly.burakov@intel.com> In-Reply-To: <67a795e77bc9f5ac79ab78a878ae19abbead9f50.1563984454.git.anatoly.burakov@intel.com> From: David Marchand Date: Mon, 12 Aug 2019 12:03:44 +0200 Message-ID: To: Anatoly Burakov Cc: dev , Bruce Richardson , Stephen Hemminger , dpdk stable Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] eal: fix proc type auto detection X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" On Wed, Jul 24, 2019 at 6:08 PM Anatoly Burakov wrote: > > Currently, primary process holds an exclusive lock on the config > file, thereby preventing other primaries from spinning up. However, > when the primary dies, the lock is no longer being held, even though > there might be other secondary processes still running. > > The fix is two-fold. First of all, downgrade the primary process's > exclusive lock to a shared lock once we have it. Second of all, > also take out shared locks on the config from the secondaries. We > are using fcntl() locks, which get dropped when the file handle is > closed, so also remove the closure of config file handle. > > Fixes: af75078fece3 ("first public release") > Cc: stable@dpdk.org > > Signed-off-by: Anatoly Burakov > --- > > Notes: > v4: > - Fixed FreeBSD log message to match Linux version > > v3: > - Added similar changes to FreeBSD version > > v2: > - Adjusted indentation > > lib/librte_eal/freebsd/eal/eal.c | 36 +++++++++++++++++++++++++++---- > lib/librte_eal/linux/eal/eal.c | 37 +++++++++++++++++++++++++++----- > 2 files changed, 64 insertions(+), 9 deletions(-) > > diff --git a/lib/librte_eal/freebsd/eal/eal.c b/lib/librte_eal/freebsd/eal/eal.c > index d53f0fe69..69995bf8f 100644 > --- a/lib/librte_eal/freebsd/eal/eal.c > +++ b/lib/librte_eal/freebsd/eal/eal.c > @@ -72,6 +72,13 @@ static struct flock wr_lock = { > .l_len = sizeof(early_mem_config.memsegs), > }; > > +static struct flock rd_lock = { > + .l_type = F_RDLCK, > + .l_whence = SEEK_SET, > + .l_start = offsetof(struct rte_mem_config, memsegs), > + .l_len = sizeof(early_mem_config.memsegs), > +}; > + > /* Address of global and public configuration */ > static struct rte_config rte_config = { > .mem_config = &early_mem_config, > @@ -249,8 +256,21 @@ rte_eal_config_create(void) > if (retval < 0){ > close(mem_cfg_fd); > mem_cfg_fd = -1; > - RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary " > - "process running?\n", pathname); > + RTE_LOG(ERR, EAL, "Cannot create exclusive lock on '%s'. " > + "Is another process running?\n", pathname); > + return -1; > + } > + > + /* we hold an exclusive lock - now downgrade it to a read lock to allow > + * other processes to also hold onto this file while preventing other > + * primaries from spinning up. > + */ > + retval = fcntl(mem_cfg_fd, F_SETLK, &rd_lock); > + if (retval < 0) { > + close(mem_cfg_fd); > + mem_cfg_fd = -1; > + RTE_LOG(ERR, EAL, "Cannot downgrade to shared lock on '%s': %s\n", > + pathname, strerror(errno)); > return -1; > } > > @@ -292,6 +312,16 @@ rte_eal_config_attach(void) > return -1; > } > } > + /* lock the file to prevent primary from initializing while this > + * process is still running. > + */ > + if (fcntl(mem_cfg_fd, F_SETLK, &rd_lock) < 0) { > + close(mem_cfg_fd); > + mem_cfg_fd = -1; > + RTE_LOG(ERR, EAL, "Cannot create shared lock on '%s': %s\n", > + pathname, strerror(errno)); > + return -1; > + } > > rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config), > PROT_READ, MAP_SHARED, mem_cfg_fd, 0); > @@ -330,8 +360,6 @@ rte_eal_config_reattach(void) > mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr, > sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED, > mem_cfg_fd, 0); > - close(mem_cfg_fd); > - mem_cfg_fd = -1; > > if (mem_config == MAP_FAILED) { > RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n", We are missing a mem_cfg_fd cleanup if mmap failed. > diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c > index 34db78753..0f0726703 100644 > --- a/lib/librte_eal/linux/eal/eal.c > +++ b/lib/librte_eal/linux/eal/eal.c > @@ -83,6 +83,13 @@ static struct flock wr_lock = { > .l_len = sizeof(early_mem_config.memsegs), > }; > > +static struct flock rd_lock = { > + .l_type = F_RDLCK, > + .l_whence = SEEK_SET, > + .l_start = offsetof(struct rte_mem_config, memsegs), > + .l_len = sizeof(early_mem_config.memsegs), > +}; > + > /* Address of global and public configuration */ > static struct rte_config rte_config = { > .mem_config = &early_mem_config, > @@ -343,8 +350,21 @@ rte_eal_config_create(void) > if (retval < 0){ > close(mem_cfg_fd); > mem_cfg_fd = -1; > - RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary " > - "process running?\n", pathname); > + RTE_LOG(ERR, EAL, "Cannot create exclusive lock on '%s'. " > + "Is another process running?\n", pathname); > + return -1; > + } > + > + /* we hold an exclusive lock - now downgrade it to a read lock to allow > + * other processes to also hold onto this file while preventing other > + * primaries from spinning up. > + */ > + retval = fcntl(mem_cfg_fd, F_SETLK, &rd_lock); > + if (retval < 0) { > + close(mem_cfg_fd); > + mem_cfg_fd = -1; > + RTE_LOG(ERR, EAL, "Cannot downgrade to shared lock on '%s': %s\n", > + pathname, strerror(errno)); > return -1; > } > > @@ -389,6 +409,16 @@ rte_eal_config_attach(void) > return -1; > } > } > + /* lock the file to prevent primary from initializing while this > + * process is still running. > + */ > + if (fcntl(mem_cfg_fd, F_SETLK, &rd_lock) < 0) { > + close(mem_cfg_fd); > + mem_cfg_fd = -1; > + RTE_LOG(ERR, EAL, "Cannot create shared lock on '%s': %s\n", > + pathname, strerror(errno)); > + return -1; > + } > > /* map it as read-only first */ > mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config), > @@ -427,9 +457,6 @@ rte_eal_config_reattach(void) > sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED, > mem_cfg_fd, 0); > > - close(mem_cfg_fd); > - mem_cfg_fd = -1; > - > if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) { > if (mem_config != MAP_FAILED) { > /* errno is stale, don't use */ Idem. Reviewed-by: David Marchand With https://patchwork.dpdk.org/patch/56501/, the code is now really close between Linux and FreeBSD, could it go to common entirely? -- David Marchand