From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E7981A0032 for ; Fri, 29 Oct 2021 12:09:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D723341158; Fri, 29 Oct 2021 12:09:33 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 3DAF841158 for ; Fri, 29 Oct 2021 12:09:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635502172; 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=89QEmcGImSQabMZV2sORPy1/S1Tdta/+jOVO1gO3GRw=; b=WXaCMbzWbO3m+W84DDFwaQA9ejmIDUs1oi93NopIJHDuqrKATMt/dE1xnrEw/kpedhvsTj CusYjFCHwc4YtipeDfcYROJ2lo6FsL91ClkEChlqbnDfhNnbJJMt2Hsz2eUc042qeCnEJj x0YWJzI9drA5a3djGumFpYbqWWjMhYw= 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-11-x_o9uYLnN82OjrCto3lSzg-1; Fri, 29 Oct 2021 06:09:27 -0400 X-MC-Unique: x_o9uYLnN82OjrCto3lSzg-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 6C736100C677; Fri, 29 Oct 2021 10:09:26 +0000 (UTC) Received: from [10.39.208.19] (unknown [10.39.208.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDBD05C3E0; Fri, 29 Oct 2021 10:09:13 +0000 (UTC) Message-ID: Date: Fri, 29 Oct 2021 12:09:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 To: Olivier Matz , dev@dpdk.org Cc: Anatoly Burakov , David Marchand , stable@dpdk.org References: <20211029095310.30785-1-olivier.matz@6wind.com> From: Maxime Coquelin In-Reply-To: <20211029095310.30785-1-olivier.matz@6wind.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-stable] [PATCH] eal/memory: fix unused SIGBUS handler X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 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 Olivier, On 10/29/21 11:53, Olivier Matz wrote: > Since its introduction in 2018, the SIGBUS handler was never registered, > and all related functions were unused. > > A SIGBUS can be received by the application when accessing to hugepages > even if mmap() was successful, This happens especially when running > inside containers when there is not enough hugepages. In this case, we > need to recover. A similar scheme can be found in eal_memory.c. > > Fixes: 582bed1e1d1d ("mem: support mapping hugepages at runtime") > Cc: stable@dpdk.org > > Signed-off-by: Olivier Matz > --- > lib/eal/linux/eal_memalloc.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c > index 0ec8542283..337f2bc739 100644 > --- a/lib/eal/linux/eal_memalloc.c > +++ b/lib/eal/linux/eal_memalloc.c > @@ -107,7 +107,7 @@ static struct rte_memseg_list local_memsegs[RTE_MAX_MEMSEG_LISTS]; > > static sigjmp_buf huge_jmpenv; > > -static void __rte_unused huge_sigbus_handler(int signo __rte_unused) > +static void huge_sigbus_handler(int signo __rte_unused) > { > siglongjmp(huge_jmpenv, 1); > } > @@ -116,7 +116,7 @@ static void __rte_unused huge_sigbus_handler(int signo __rte_unused) > * non-static local variable in the stack frame calling sigsetjmp might be > * clobbered by a call to longjmp. > */ > -static int __rte_unused huge_wrap_sigsetjmp(void) > +static int huge_wrap_sigsetjmp(void) > { > return sigsetjmp(huge_jmpenv, 1); > } > @@ -124,7 +124,7 @@ static int __rte_unused huge_wrap_sigsetjmp(void) > static struct sigaction huge_action_old; > static int huge_need_recover; > > -static void __rte_unused > +static void > huge_register_sigbus(void) > { > sigset_t mask; > @@ -139,7 +139,7 @@ huge_register_sigbus(void) > huge_need_recover = !sigaction(SIGBUS, &action, &huge_action_old); > } > > -static void __rte_unused > +static void > huge_recover_sigbus(void) > { > if (huge_need_recover) { > @@ -576,6 +576,8 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, > mmap_flags = MAP_SHARED | MAP_POPULATE | MAP_FIXED; > } > > + huge_register_sigbus(); > + > /* > * map the segment, and populate page tables, the kernel fills > * this segment with zeros if it's a new page. > @@ -651,6 +653,8 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, > __func__); > #endif > > + huge_recover_sigbus(); > + > ms->addr = addr; > ms->hugepage_sz = alloc_sz; > ms->len = alloc_sz; > @@ -664,6 +668,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, > mapped: > munmap(addr, alloc_sz); > unmapped: > + huge_recover_sigbus(); > flags = EAL_RESERVE_FORCE_ADDRESS; > new_addr = eal_get_virtual_area(addr, &alloc_sz, alloc_sz, 0, flags); > if (new_addr != addr) { > I had almost the same series ready, instead that I installed/removed the handler before/after the loop of alloc_seg(). I don't think this is necessary though, so I'm fine with your patch, which is simpler: Reviewed-by: Maxime Coquelin Thanks, Maxime