From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id CB1FA548B; Tue, 3 Jul 2018 11:07:16 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jul 2018 02:07:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,302,1526367600"; d="scan'208";a="69239320" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.237.220.109]) ([10.237.220.109]) by fmsmga001.fm.intel.com with ESMTP; 03 Jul 2018 02:07:13 -0700 To: Alejandro Lucero , dev@dpdk.org Cc: stable@dpdk.org, maxime.coquelin@redhat.com References: <1530552423-32301-1-git-send-email-alejandro.lucero@netronome.com> <1530552423-32301-2-git-send-email-alejandro.lucero@netronome.com> From: "Burakov, Anatoly" Message-ID: Date: Tue, 3 Jul 2018 10:07:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1530552423-32301-2-git-send-email-alejandro.lucero@netronome.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-stable] [PATCH 1/6] mem: add function for checking memsegs IOVAs addresses 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: , X-List-Received-Date: Tue, 03 Jul 2018 09:07:18 -0000 On 02-Jul-18 6:26 PM, Alejandro Lucero wrote: > A device can suffer addressing limitations. This functions checks > memsegs have iovas within the supported range based on dma mask. > > PMD should use this during initialization if supported devices > suffer addressing limitations, returning an error if this function > returns memsegs out of range. > > Another potential usage is for emulated IOMMU hardware with addressing > limitations. > > Signed-off-by: Alejandro Lucero > --- > + const struct rte_mem_config *mcfg; > + uint64_t mask; > + int i; > + int ret = 0; > + > + /* create dma mask */ > + mask = 1ULL << maskbits; > + mask -= 1; mask = ~((1ULL << maskbits) - 1); ? IMO this makes it much more clear what you're trying to do. > + > + /* get pointer to global configuration */ > + mcfg = rte_eal_get_configuration()->mem_config; > + > + for (i = 0; i < RTE_MAX_MEMSEG; i++) { > + if (mcfg->memseg[i].addr == NULL) > + break; > + > + if (mcfg->memseg[i].iova & ~mask) { > + ret = -1; > + break; > + } > + } > + > + if (!ret) > + return ret; > + > + RTE_LOG(INFO, EAL, "memseg[%d] iova %"PRIx64" out of range:\n", > + i, mcfg->memseg[i].iova); > + RTE_LOG(INFO, EAL, "\tusing dma mask %"PRIx64"\n", mask); > + > + return -1; The control flow looks weird to me. You break if iova has any bits that are in the mask, then you display log messages and return -1. How about just logging error and returning -1, and simply returning 0 after the loop? -- Thanks, Anatoly