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 9EB9CA04B1 for ; Thu, 5 Nov 2020 13:41:55 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8AB9BC31B; Thu, 5 Nov 2020 13:41:54 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 3E47BC325 for ; Thu, 5 Nov 2020 13:41:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604580111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sBpe+ndkG4YYcvu8jDt/j2/Lv9YWhi8SRlTp1H+g9xs=; b=Zr1aib8AruB4UHEaNYlSLYyLJQG/iB3rUdZC3o4na0ot/MwhNuTet4XG9G54X4Y4ZuVDuP BxgCIX0zuS9S6YWCNlCF3kNenJ6sV+yggjhMnZj+pERjuRjL/K5UMispei7OCxiG52Xwkj X03WzLS6hRI6GfiomCy4a20GcvCElyo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-0VeYLEwRONG82kf-hJxFdQ-1; Thu, 05 Nov 2020 07:41:49 -0500 X-MC-Unique: 0VeYLEwRONG82kf-hJxFdQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 45C651074646; Thu, 5 Nov 2020 12:41:48 +0000 (UTC) Received: from rh.redhat.com (ovpn-113-249.ams2.redhat.com [10.36.113.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B7045C3E1; Thu, 5 Nov 2020 12:41:47 +0000 (UTC) From: Kevin Traynor To: David Marchand Cc: Anatoly Burakov , dpdk stable Date: Thu, 5 Nov 2020 12:39:50 +0000 Message-Id: <20201105124015.306404-43-ktraynor@redhat.com> In-Reply-To: <20201105124015.306404-1-ktraynor@redhat.com> References: <20201105124015.306404-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ktraynor@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-stable] patch 'mem: fix allocation in container with SELinux' has been queued to LTS release 18.11.11 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" Hi, FYI, your patch has been queued to LTS release 18.11.11 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/10/20. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/2a3e5d6205c2087e1879dceb1bd573bccab4469a Thanks. Kevin. --- >From 2a3e5d6205c2087e1879dceb1bd573bccab4469a Mon Sep 17 00:00:00 2001 From: David Marchand Date: Thu, 10 Sep 2020 18:24:07 +0200 Subject: [PATCH] mem: fix allocation in container with SELinux [ upstream commit aa48ddf4f0d2a9f90cd9247ac779ced55588c27a ] This is something we encountered while working in an OpenShift environment with SELinux enabled. In this environment, a DPDK application could create/write to hugepage files but removing them was refused. This resulted in dirty files being reused when starting a new DPDK application and triggered random crashes / erratic behavior. Getting a SELinux setup can be a challenge, and even more if you add containers to the picture :-). So here is a reproducer for the interested testers: # cat >wrap.c < #include #include #include #include #include #include int unlink(const char *pathname) { static int (*orig)(const char *pathname) = NULL; struct stat st; if (orig == NULL) orig = dlsym(RTLD_NEXT, "unlink"); if (strstr(pathname, "rtemap_") != NULL && stat(pathname, &st) == 0) { fprintf(stderr, "### refused unlink for %s\n", pathname); errno = EACCES; return -1; } fprintf(stderr, "### called unlink for %s\n", pathname); return orig(pathname); } int unlinkat(int dirfd, const char *pathname, int flags) { static int (*orig)(int dirfd, const char *pathname, int flags) = NULL; struct stat st; if (orig == NULL) orig = dlsym(RTLD_NEXT, "unlinkat"); if (strstr(pathname, "rtemap_") != NULL && fstatat(dirfd, pathname, &st, flags) == 0) { fprintf(stderr, "### refused unlinkat for %s\n", pathname); errno = EACCES; return -1; } fprintf(stderr, "### called unlinkat for %s\n", pathname); return orig(dirfd, pathname, flags); } EOF # gcc -fPIC -shared -o libwrap.so wrap.c -ldl # \rm /dev/hugepages/rtemap* # # First run is fine # LD_PRELOAD=libwrap.so dpdk-testpmd -w 0000:01:00.0 -- -i [...] Configuring Port 0 (socket 0) Port 0: 24:6E:96:3C:52:D8 Checking link statuses... Done testpmd> # # Second run we have dirty memory # LD_PRELOAD=libwrap.so dpdk-testpmd -w 0000:01:00.0 -- -i [...] ### refused unlinkat for rtemap_0 [...] Port 0 is now not stopped Please stop the ports first Done testpmd> Removing hugepage files is done in multiple places and the memory allocation code is complex. This fix tries to do the minimum and avoids touching other paths. If trying to remove the hugepage file before allocating a page fails, the error is reported to the caller and the user will see a memory allocation error log. Fixes: 582bed1e1d1d ("mem: support mapping hugepages at runtime") Signed-off-by: David Marchand Acked-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_memalloc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c index 518314d89c..dea2b5ec93 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c @@ -420,4 +420,19 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi, if (fd < 0) { + /* A primary process is the only one creating these + * files. If there is a leftover that was not cleaned + * by clear_hugedir(), we must *now* make sure to drop + * the file or we will remap old stuff while the rest + * of the code is built on the assumption that a new + * page is clean. + */ + if (rte_eal_process_type() == RTE_PROC_PRIMARY && + unlink(path) == -1 && + errno != ENOENT) { + RTE_LOG(DEBUG, EAL, "%s(): could not remove '%s': %s\n", + __func__, path, strerror(errno)); + return -1; + } + fd = open(path, O_CREAT | O_RDWR, 0600); if (fd < 0) { -- 2.26.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2020-11-05 12:38:55.073275999 +0000 +++ 0043-mem-fix-allocation-in-container-with-SELinux.patch 2020-11-05 12:38:54.244896023 +0000 @@ -1 +1 @@ -From aa48ddf4f0d2a9f90cd9247ac779ced55588c27a Mon Sep 17 00:00:00 2001 +From 2a3e5d6205c2087e1879dceb1bd573bccab4469a Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit aa48ddf4f0d2a9f90cd9247ac779ced55588c27a ] + @@ -96 +97,0 @@ -Cc: stable@dpdk.org @@ -101 +102 @@ - lib/librte_eal/linux/eal_memalloc.c | 15 +++++++++++++++ + lib/librte_eal/linuxapp/eal/eal_memalloc.c | 15 +++++++++++++++ @@ -104,5 +105,5 @@ -diff --git a/lib/librte_eal/linux/eal_memalloc.c b/lib/librte_eal/linux/eal_memalloc.c -index db60e79975..40a5c4aa1d 100644 ---- a/lib/librte_eal/linux/eal_memalloc.c -+++ b/lib/librte_eal/linux/eal_memalloc.c -@@ -330,4 +330,19 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi, +diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c +index 518314d89c..dea2b5ec93 100644 +--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c ++++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c +@@ -420,4 +420,19 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,