From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by dpdk.org (Postfix) with ESMTP id C6D9725D9 for ; Fri, 10 Aug 2018 10:35:49 +0200 (CEST) Received: by mail-ed1-f67.google.com with SMTP id o8-v6so4355475edt.13 for ; Fri, 10 Aug 2018 01:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=diArTv+ewGBH2pFjOIWd7tDcx4YRwuSHvJIla7O6zPg=; b=Q4OIYqzb8DmHYpeSU5dEBzAFLvc4TWOur8o57rm3FjY1WaEpMKt5I1IC0330142YBV lJ5pBoQbtHEKXSFT1Ae2fhNWC9PlEMQSP3mHFY5M1ccFNRea2rMLuBDRsQFBQ03SEXzW c9rckSV/Ukq6d7W1Tr/t1yA/pTXx716VNXS2AYTUDwIIjGDvP99Gd+PKDe8gdciU70kT W412c0fhSlKsIxCMDh0zTgoV8qxF4kFyxhPl3GCre+I5RjLRXaOe9fEVqLG68NJQvlv/ Do+BcO427tmJEgv4drs6LCP7ZrDP6x7boAYpN4ZQIYRd3BxoSePqaYx8MjyZIz2d/EQJ xBZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=diArTv+ewGBH2pFjOIWd7tDcx4YRwuSHvJIla7O6zPg=; b=Az/eD1KT4IsLNQpBWEyZhpB7nPMFWOxe+dYBrVv8qzRY5DGocTJY4viA7O7gNwqkw9 z/IxpmsPNzOF00ebZPDWrfu0Uffb0uF1fl6RBFE6Xg2FTddG5tpkXt24R8KcVBplSi/e VOihclLVjFRdjgRRXPXIjZ0BqfpVXPV/j1zh008m/txxjnscaD8fwDZfdqL8P4CfphYy YkyrKnaqYrejwwSTC+fkZTN6C/inrBWhgLI/TFCauxVP47hf5swplsUvsLJM1P+1we50 97O3/cqCrbU2DfQ1EuVWKmhPr0VxILBCgQTDvUYzIZlyBur59yNQTneTWgy5H+YwGgus y/PA== X-Gm-Message-State: AOUpUlF153AJ+sl6RzhHVPmY3Lh7t4E3nNuSJAdjLbE/oxFbP9yzPgTn NdrnIQc/m92MMfbfKLbsOqmBI/fcJOTnLHMi+b0= X-Google-Smtp-Source: AA+uWPwznoXXAIl3Tl6CT5qYv4G3Ylx/+vofzX63MXwdmSuRJf/K8Uno8kw7REcUa3qB4X4eNBFONkIgit3669m3dt0= X-Received: by 2002:a50:99db:: with SMTP id n27-v6mr7143270edb.111.1533890149442; Fri, 10 Aug 2018 01:35:49 -0700 (PDT) MIME-Version: 1.0 References: <1533494497-16253-1-git-send-email-quzeyao@gmail.com> <20180809100344.15af7e9c@xeon-e3> In-Reply-To: <20180809100344.15af7e9c@xeon-e3> From: Drocula Date: Fri, 10 Aug 2018 16:35:38 +0800 Message-ID: To: Stephen Hemminger Cc: maxime.coquelin@redhat.com, dev@dpdk.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [PATCH] bus/pci: check if 5-level paging is enabled when testing IOMMU address width 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: Fri, 10 Aug 2018 08:35:49 -0000 First, thanks for your suggestions. When using the MAP_FIXED flag, mmap will return an MMAP_FAILED if 0xf0000000000000 is not available. In this case, I want mmap to return an address near 0xf0000000000000. I will submit v2. On Fri, Aug 10, 2018, 01:03 Stephen Hemminger wrote: > Thanks for the patch, there are some minor style/cleanups that > could be done. > > > #if defined(RTE_ARCH_X86) > > Isn't this going to apply to 64 bit only? > > > +/* > > + * Try to detect whether the system uses 5-level page table. > > + */ > > +static bool > > +system_uses_PML5(void) > > +{ > > + void *page_4k, *mask = (void *)0xf0000000000000; > > Magic constants expressed like this seem wrong. Why not use > shift to make it obvious. > > Also, you are assuming a particular layout of memory on > Linux which might be problematic. Plus if there is already > some memory in use there, it won't work. > > > + page_4k = mmap(mask, 4096, PROT_READ | PROT_WRITE, > > + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); > > Since you are probing maybe MAP_FIXED is what you want. > > > + > > + if (page_4k == (void *) -1) > > + return false; > Use MMAP_FAILED here. > > > + munmap(page_4k, 4096); > > + > > + if ((unsigned long)page_4k & (unsigned long)mask) > > + return true; > > + return false; > > Wouldn't this work the same for what you expect? > return page_4k == mask; > > I.e you expect kernel to put page where you want. >