From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id 33F424CE4 for ; Sun, 8 Jul 2018 15:30:57 +0200 (CEST) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us4.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id 7A78F140059; Sun, 8 Jul 2018 13:30:54 +0000 (UTC) Received: from [192.168.1.16] (85.187.13.33) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Sun, 8 Jul 2018 14:30:42 +0100 To: Jeff Guo , , , , , , , , , , , , , CC: , , , References: <1498711073-42917-1-git-send-email-jia.guo@intel.com> <1530776333-30318-1-git-send-email-jia.guo@intel.com> <1530776333-30318-6-git-send-email-jia.guo@intel.com> From: Andrew Rybchenko Message-ID: <06569f3a-58f6-d069-5234-4900f0f5f0fb@solarflare.com> Date: Sun, 8 Jul 2018 16:30:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1530776333-30318-6-git-send-email-jia.guo@intel.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [85.187.13.33] X-ClientProxiedBy: ocex03.SolarFlarecom.com (10.20.40.36) To ukex01.SolarFlarecom.com (10.17.10.4) X-TM-AS-Product-Ver: SMEX-11.0.0.1191-8.100.1062-23954.003 X-TM-AS-Result: No--9.221600-0.000000-31 X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-MDID: 1531056656-UAWNAYnNKYl5 Subject: Re: [dpdk-dev] [PATCH V5 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: Sun, 08 Jul 2018 13:30:57 -0000 On 05.07.2018 10:38, 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 > --- > v5->v4: > refine the errno restore logic > --- > lib/librte_eal/common/eal_common_bus.c | 36 +++++++++++++++++++++++++++++++++- > lib/librte_eal/common/eal_private.h | 12 ++++++++++++ > 2 files changed, 47 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c > index 0943851..c9f3566 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" > > @@ -220,7 +221,6 @@ rte_bus_find_by_device_name(const char *str) > return rte_bus_find(NULL, bus_can_parse, name); > } > > - Unrelated change. > /* > * Get iommu class of devices on the bus. > */ > @@ -242,3 +242,37 @@ rte_bus_get_iommu_class(void) > } > return mode; > } > + > +static int > +bus_handle_sigbus(const struct rte_bus *bus, > + const void *failure_addr) > +{ > + int ret; > + > + ret = bus->sigbus_handler(failure_addr); Shouldn't bus->sigbus_handler be checked here against NULL? It looks like not all buses implement it. > + rte_errno = ret; > + > + return !(bus->sigbus_handler && ret <= 0); > +} > + > +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 && rte_errno == -1) > + return -1; > + else if (!bus) > + ret = 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..a91c4b5 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); Empty line is missing after the function. > #endif /* _EAL_PRIVATE_H_ */