From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 1AF2A1B061 for ; Tue, 10 Jul 2018 10:22:28 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 01:22:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,333,1526367600"; d="scan'208";a="53896602" Received: from jguo15x-mobl3.ccr.corp.intel.com (HELO [10.67.68.57]) ([10.67.68.57]) by fmsmga008.fm.intel.com with ESMTP; 10 Jul 2018 01:22:24 -0700 To: Andrew Rybchenko , stephen@networkplumber.org, bruce.richardson@intel.com, ferruh.yigit@intel.com, konstantin.ananyev@intel.com, gaetan.rivet@6wind.com, jingjing.wu@intel.com, thomas@monjalon.net, motih@mellanox.com, matan@mellanox.com, harry.van.haaren@intel.com, qi.z.zhang@intel.com, shaopeng.he@intel.com, bernard.iremonger@intel.com, wenzhuo.lu@intel.com References: <1498711073-42917-1-git-send-email-jia.guo@intel.com> <1531137666-10351-1-git-send-email-jia.guo@intel.com> <1531137666-10351-6-git-send-email-jia.guo@intel.com> Cc: jblunck@infradead.org, shreyansh.jain@nxp.com, dev@dpdk.org, helin.zhang@intel.com From: Jeff Guo Message-ID: <7d719385-51e5-a45b-341a-d07f7cb92445@intel.com> Date: Tue, 10 Jul 2018 16:22:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v7 5/7] bus: add helper to handle sigbus X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jul 2018 08:22:29 -0000 On 7/9/2018 9:48 PM, Andrew Rybchenko wrote: > On 09.07.2018 15:01, Jeff Guo wrote: >> This patch aim to add a helper to iterate all buses to find the >> corresponding bus to handle the sigbus error. >> >> Signed-off-by: Jeff Guo >> Acked-by: Shaopeng He >> --- >> v7->v6: >> no change >> --- >> lib/librte_eal/common/eal_common_bus.c | 42 >> ++++++++++++++++++++++++++++++++++ >> lib/librte_eal/common/eal_private.h | 12 ++++++++++ >> 2 files changed, 54 insertions(+) >> >> diff --git a/lib/librte_eal/common/eal_common_bus.c >> b/lib/librte_eal/common/eal_common_bus.c >> index 0943851..8856adc 100644 >> --- a/lib/librte_eal/common/eal_common_bus.c >> +++ b/lib/librte_eal/common/eal_common_bus.c >> @@ -37,6 +37,7 @@ >> #include >> #include >> #include >> +#include >> #include "eal_private.h" >> @@ -242,3 +243,44 @@ rte_bus_get_iommu_class(void) >> } >> return mode; >> } >> + >> +static int >> +bus_handle_sigbus(const struct rte_bus *bus, >> + const void *failure_addr) >> +{ >> + int ret; >> + >> + if (!bus->sigbus_handler) { >> + RTE_LOG(ERR, EAL, "Function sigbus_handler not supported by " >> + "bus (%s)\n", bus->name); > > It is not an error. It is OK that some buses cannot handle SIGBUS. > yes, it is. >> + return -1; >> + } >> + >> + ret = bus->sigbus_handler(failure_addr); >> + rte_errno = ret; >> + >> + return !(bus->sigbus_handler && ret <= 0); > > There is no point to check bus->sigbus_handler here. It is already > checked above. > So, it should be just: > return ret > 0; > I.e. we should continue search if the address is not handled by any > device > on the bus (we should stop if it is handled (ret==0) or failed to to > handle > (ret < 0)). > i will modify it, thanks. >> +} >> + >> +int >> +rte_bus_sigbus_handler(const void *failure_addr) >> +{ >> + struct rte_bus *bus; >> + >> + int ret = 0; >> + int old_errno = rte_errno; >> + >> + rte_errno = 0; >> + >> + bus = rte_bus_find(NULL, bus_handle_sigbus, failure_addr); >> + /* failed to handle the sigbus, pass the new errno. */ >> + if (!bus) >> + ret = 1; >> + else if (rte_errno == -1) > > I'm still thinking it is bad to keep negative value in rte_errno here. > i think the rte_errno just no used for the caller if return -1. Since if find bus but process failed, will use rte_exit to process whatever the rte_errno value. Only return 1 means use the origin sigbus handler that will care about the errno. >> + return -1; >> + >> + /* otherwise restore the old errno. */ >> + rte_errno = old_errno; >> + >> + return ret; >> +} >> diff --git a/lib/librte_eal/common/eal_private.h >> b/lib/librte_eal/common/eal_private.h >> index bdadc4d..2337e71 100644 >> --- a/lib/librte_eal/common/eal_private.h >> +++ b/lib/librte_eal/common/eal_private.h >> @@ -258,4 +258,16 @@ int rte_mp_channel_init(void); >> */ >> void dev_callback_process(char *device_name, enum >> rte_dev_event_type event); >> +/** >> + * Iterate all buses to find the corresponding bus, to handle the >> sigbus error. >> + * @param failure_addr >> + * Pointer of the fault address of the sigbus error. >> + * >> + * @return >> + * 0 success to handle the sigbus. >> + * -1 failed to handle the sigbus >> + * 1 no bus can handler the sigbus >> + */ >> +int rte_bus_sigbus_handler(const void *failure_addr); >> + >> #endif /* _EAL_PRIVATE_H_ */ >