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 25288A0547; Wed, 12 Oct 2022 11:18:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F0E1742D6E; Wed, 12 Oct 2022 11:18:39 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2070.outbound.protection.outlook.com [40.107.244.70]) by mails.dpdk.org (Postfix) with ESMTP id E6E4242B6D for ; Wed, 12 Oct 2022 11:18:37 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I6bCvqDNszFC4ym6F/hX2M1GSzW4GmnFWSMFQNuCciHrew3H4lS0GIazJ1k6OqBRVq8+10Wfg5oc89ynB/lfYemKpDqIF75bk+rWkt4OcEvvFVTeLI5eeKVbLfRXVpMk5fOMohXlb1d+R5/rz31pkv/5r0esZ4fr/YZcJVzVBae9jxL0tV3uCCYTFoyoBN4qrtK7FmvwU3nyP/qPQXymvJKaXqN7VbNZ/kWRH9G5/m/y1lBG0Seb7ok5/8vsFkUaR1PtKwCgwbb1mO2/IcN/zJTc6CgMuF1fQasYUE6dEU7Vm296LLPzSEQkeqvh/5iYP7jE7Y0pj989YFX3luLWqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0065Uzc9bF3Nn9O16YX4erleA/eR88U30I3qpr9kTJ8=; b=cx93UcktJsIhfitvybDwZqtjfdhO7LRqebySCcycHb9BZx4b0juWvUd77s0k9mbV7S/AegjBhzm0wGfepLbSDQUmby38tgpflpkJoOFVgIkRGcHfhTFw0Tx029zMVC4uqPPvU+eVo+Q0bR0ZmoYNSN4WBAmeBqXO/8HnnOJFqOZYVhTo3BkPb2yypeLljQHV5WJXeZyrUOPgLgcvC2gSh5Av0DEtwyLD3GAGibCE6CDUN1pEmG3lX4vSHTu4ExVvzZEcKla7QlGba/buG4urZtPFhH0b9lRg+8O5SfDQOviYKTaXWVql7O+3cEi6Yav56xGr8St3Fu2BSBOQUisTVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0065Uzc9bF3Nn9O16YX4erleA/eR88U30I3qpr9kTJ8=; b=F4QyrQfq+Ecxa2QKY2bY7aN7ok9luUOVHHOhej7kWyUzQWhVW1mGBZcZ6UUp1tyQDJ+eqMzKb6U1RG2x6o58LZoPB5cKbqdHKCkP2bsEjTxh1qcDjwxKJ3w9/NitDvUMdsdMdQ62f/H/bOxwDn9yDnLGJpVd7+Z2agDeDrft+/U= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB4297.namprd12.prod.outlook.com (2603:10b6:5:211::20) by BN9PR12MB5384.namprd12.prod.outlook.com (2603:10b6:408:105::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Wed, 12 Oct 2022 09:18:31 +0000 Received: from DM6PR12MB4297.namprd12.prod.outlook.com ([fe80::b9fd:e732:4585:6b25]) by DM6PR12MB4297.namprd12.prod.outlook.com ([fe80::b9fd:e732:4585:6b25%7]) with mapi id 15.20.5676.036; Wed, 12 Oct 2022 09:18:31 +0000 Message-ID: Date: Wed, 12 Oct 2022 10:18:27 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.2 Subject: Re: [PATCH v4] pci: read amd iommu virtual address width Content-Language: en-US To: Michael Piszczek Cc: Vipin.Varghese@amd.com, dev@dpdk.org References: <20220912160157.3642968-2-mpiszczek@ddn.com> <20221011140854.777428-1-mpiszczek@ddn.com> From: Ferruh Yigit In-Reply-To: <20221011140854.777428-1-mpiszczek@ddn.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0314.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a4::14) To DM6PR12MB4297.namprd12.prod.outlook.com (2603:10b6:5:211::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB4297:EE_|BN9PR12MB5384:EE_ X-MS-Office365-Filtering-Correlation-Id: fde04a8e-834f-4ca0-b62d-08daac32baf1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NjgPWKGVg7rptoYxs+O1qa/9Z4m8Kwu2qs6IfO7JEv7uPYQrdWYe1daDfsO/tNgPFKUUYgapxLdRNmsZWMJ7q0e7BUb1EFrdOBW85uyxhiHyx6ZOT6pYmHM3JI5rw3bp9ILnUJvzhJMJdN6hXBNVhS4U/wd1/tH/j50cYX+sVjFzTGrtpmtryFUbGx+mY7+kgUba/0cpAK8Omzn4HK3/6yvqeUETtZ7gr/HxLQ47gq0LvgboPfhy1UgbQdUqrLLmbLI7dD9pjRK5HDoKyD1Q3FpQKlInEfWSBMuhHbO77CfVX0fZMs1n2LDKym+nYRDeROb7jmF+4jGfUEa1Ae/9+64MDhBogf3/HqvhMBYL7MAVw1Lnzg2B9XwJNsXB1hPXh2X8hRLDywDm79hguUj+lTFTT83jbmhqEMQFLraPsyJ/VJduqI7Rth2o45erKvRkw256RVH9H0qdaZtoamV3BS5Mie6APPba6ks4jdK2KPMyATGW0hbBDfXJlwE/VuUSsZOXUKfyjOw8+JhqqAqII4ldMwTQxdN51KrYpwmFbZQldBui/eDkuACm020ol70+w4eZLIYhPzZWydfwlIb4mKWMBHH/Tv0VJOTJrciCgPsRI2x+RqoK9fp4AxLo1ceTmKqIyPO0BwY6PlyM/4q2MG2UilnpDJT4HiEY/x0fvWiyC3CnlgsA17qw8Q9s9TUwfEcXU8on5sWoc8fQboCiPorbSrEskhxecrXoCXa4cS6xMuc/DYMl/dwEbYbEGL0mdj4QqxYFkam+E0YcQMsSUcjrx37ltdf2cGl3xEVjRZ0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB4297.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199015)(83380400001)(36756003)(31686004)(86362001)(31696002)(41300700001)(5660300002)(38100700002)(2616005)(186003)(8676002)(26005)(53546011)(478600001)(6506007)(6512007)(6666004)(6486002)(66476007)(316002)(66946007)(6916009)(66556008)(8936002)(44832011)(2906002)(4326008)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Ymg2WGl6dUJHYXpqTzl3RmQyOXFNbVpabk9yWE9PK1o5S2hzbU16NzJ3M0ZW?= =?utf-8?B?clNOOU1VdUVZVGhRZk4xNWU0RElMaXN4dmt1aTJVcThib0lXOWY5akZFUGZY?= =?utf-8?B?Z0RIdDNITHIrUHFFbzRHakh3QkFkSkwzNTBOSWlkcVV1dHB5RUVCZmtVQ3Vq?= =?utf-8?B?SzFrbjU5dlY2MHZ2MURkTy9qa0xQS2JZdHEyQVlBc3Q0Qnp1am85UUpVcHI2?= =?utf-8?B?NTd6OU1zb2YxNzZjVitCbjJJMnJQS3pyMnFmMy9CMnZDR09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YTmRmampoK3c2MzR6ZHFVNVNCanB1OXZXS1ZjR1BXZ3hq?= =?utf-8?Q?JHP/18bUO89CyQlesnKzVqPZb?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fde04a8e-834f-4ca0-b62d-08daac32baf1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4297.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2022 09:18:31.3122 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lwW+OuiFNGK1CGqR7ooPyKczLV50/TQhZdM+ngngYwKaYIA8A+JkvAVh8b+ZzE3d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5384 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 10/11/2022 3:08 PM, Michael Piszczek wrote: > Add code to read the virtual address width for AMD processors. > > Signed-off-by: Michael Piszczek > --- > drivers/bus/pci/linux/pci.c | 48 ++++++++++++++++++++++++------------- > 1 file changed, 32 insertions(+), 16 deletions(-) > > diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c > index ebd1395502..cdac634e6c 100644 > --- a/drivers/bus/pci/linux/pci.c > +++ b/drivers/bus/pci/linux/pci.c > @@ -480,15 +480,18 @@ rte_pci_scan(void) > } > > #if defined(RTE_ARCH_X86) > + > bool > pci_device_iommu_support_va(const struct rte_pci_device *dev) > { > #define VTD_CAP_MGAW_SHIFT 16 > #define VTD_CAP_MGAW_MASK (0x3fULL << VTD_CAP_MGAW_SHIFT) > +#define RD_AMD_CAP_VASIZE_SHIFT 15 > +#define RD_AMD_CAP_VASIZE_MASK (0x7F << RD_AMD_CAP_VASIZE_SHIFT) > const struct rte_pci_addr *addr = &dev->addr; > char filename[PATH_MAX]; > FILE *fp; > - uint64_t mgaw, vtd_cap_reg = 0; > + uint64_t mgaw = 0, cap_reg = 0; > > snprintf(filename, sizeof(filename), > "%s/" PCI_PRI_FMT "/iommu/intel-iommu/cap", > @@ -496,26 +499,39 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev) > addr->function); > > fp = fopen(filename, "r"); > - if (fp == NULL) { > - /* We don't have an Intel IOMMU, assume VA supported */ > - if (errno == ENOENT) > - return true; > - > - RTE_LOG(ERR, EAL, "%s(): can't open %s: %s\n", > - __func__, filename, strerror(errno)); > - return false; > - } > + if (fp != NULL) { > + /* We have an Intel IOMMU */ > + if (fscanf(fp, "%" PRIx64, &cap_reg) != 1) { > + RTE_LOG(ERR, EAL, "%s(): can't read %s\n", __func__, filename); > + fclose(fp); > + return false; > + } > > - /* We have an Intel IOMMU */ > - if (fscanf(fp, "%" PRIx64, &vtd_cap_reg) != 1) { > - RTE_LOG(ERR, EAL, "%s(): can't read %s\n", __func__, filename); > fclose(fp); > - return false; > + mgaw = ((cap_reg & VTD_CAP_MGAW_MASK) >> VTD_CAP_MGAW_SHIFT) + 1; > } > + else { > + snprintf(filename, sizeof(filename), > + "%s/" PCI_PRI_FMT "/iommu/amd-iommu/cap", > + rte_pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid, > + addr->function); > + As suggested in v3, instead of first trying to open intel file later amd file, what do you think to use glob() function to detect the file? > + fp = fopen(filename, "r"); > + if (fp != NULL) { > + /* We have an Amd IOMMU */ > + if (fscanf(fp, "%" PRIx64, &cap_reg) != 1) { > + RTE_LOG(ERR, EAL, "%s(): can't read %s\n", __func__, filename); > + fclose(fp); > + return false; > + } > > - fclose(fp); > + fclose(fp); > + mgaw = ((cap_reg & RD_AMD_CAP_VASIZE_MASK) >> RD_AMD_CAP_VASIZE_SHIFT) + 1; > + } > + } > > - mgaw = ((vtd_cap_reg & VTD_CAP_MGAW_MASK) >> VTD_CAP_MGAW_SHIFT) + 1; > + if (mgaw == 0) > + return false; > > /* > * Assuming there is no limitation by now. We can not know at this point