Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1409675rdb; Wed, 20 Sep 2023 08:21:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtIxjIKXY037kp1QTJjVLZMlf82Qc+giiN5BWonyKCU7wnBALwJDrhX/zJeiaBsn+mRvYe X-Received: by 2002:a17:90a:bf0b:b0:263:fbe5:2125 with SMTP id c11-20020a17090abf0b00b00263fbe52125mr2839731pjs.15.1695223297595; Wed, 20 Sep 2023 08:21:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1695223297; cv=pass; d=google.com; s=arc-20160816; b=wJhKtBpKx8x+I2Lk8cW4c/BI2YEDZn8+Vjof/26TM4prKZQ145oKoI841VThyQdxaX NMzB9m6lAF19Ztj02Gjzzi5WbOlZ5IW0cRs2EBRbtWy4Sdq1OlyjfOxeKCNpE2WWihr8 ExKflaiIXTW3buSzvmnfO13GxSTYS67U05vFzfRWjsoLIkXW7r0Unv1uHGynQMV9SyYp 7ST9TouBhoNqMugBS+HHCQwv35CXlvLbxcsRX5Yl+/52XkXefO1IQtPDe2AHvbAdWw/X AVtxUVMrAlUl2lL5M5ylJdTVA+NQiCKVEPNynIjisy+Kh9tRbPR5g+O1n09TPC0mx1qX T0jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=J5u5Yq3YuHRARolHIAmYJYLOKZwbb0f3b4u+zIdySoU=; fh=vhhF6wPnqt/ybpdrUm/uVeqv5K7uwQyZYM1JS2w8SlU=; b=dtAGRfIbZHeLE9qreNn3Tcm5WDuaTR1C6hw6WiNRtT7/Le/XCxn3nl7xnCZi9ihefM B+6ZZ/QvLzMkABLdd8Yss85RNAb6o4M0M2XgVYiSuGfnWM1YfK7WooEKDVi2CI8luftZ FhjMO9/orQ06w7qDcahfqGF1OFy102FrL6c+0jo41uRbEY89TgwPuKA+Qrbd2zZg7bwJ 6qxSzyfjE5GBCl8QqO3z0vy0iBYvafJemCWNzoF25Dupr1y/voEMuinqDUMwNfKmnTWg +kSqYr4uvWyWldOqaDUNHeO6rOvoX4EN5n28MdKD0qPe7FJ79Gq7L7kjh5KVe4HnLBEQ E/tQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=spVG53kr; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id gz18-20020a17090b0ed200b002719ad11d97si1843000pjb.137.2023.09.20.08.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:21:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=spVG53kr; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 2BBEE81A7BF8; Wed, 20 Sep 2023 06:19:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234760AbjITNSj (ORCPT + 99 others); Wed, 20 Sep 2023 09:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbjITNSf (ORCPT ); Wed, 20 Sep 2023 09:18:35 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EE5091; Wed, 20 Sep 2023 06:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nDkHM8hfTphUSWwQ/GRSO/ITsPBYEHFFlRxnPZMrtJLW4U0bbijrb9nbaIHcKhnIGOBem1HytgtJC8h4rQ5GYjzwAge8ShkBzegce7ymo1wWj0bgeTf3DFPFBhLUPi3VK/Cc1ujXeKPWCFX9Ikyqp+tEHvzI8P6bm9bhJLQP24Aevy0pGK31EaEvNdBRBI0NeW6J/6jd9Q4HB19FxnjHMm9D2mFOwIeU4h9E6WF3KBfXHKvVH4he1/N2gJaPerYrOAUN6V/q8w/XdD8xCNhO8GuKfYP/OAhsKCEJAC3cbK9sG5xAfuWNRP2cUH3eI9hBLP3LK9iX+tzy6x+HoceoKA== 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=J5u5Yq3YuHRARolHIAmYJYLOKZwbb0f3b4u+zIdySoU=; b=IZeTTw3q7jZFqm8D2Qnk52KmrZOqFi203VaL/E/PWeNoTGDr7VSb8hP8h7iodal9Nh1qBhRr7mGky9oQslCN/mlVIyIqWuY4fFhw8C32dyI768p2VUi/6S3m49DBt47fYvj1o44iNLUCyHIhMoS1zu68LHcv8MN7Di+/knrar59YcoVnnjtLaaSv76B4ZUyry1keumVanMa2tHyTWz6WQawDKqswfZ/Ui0e6XabjmPBTdqMCFnhZ1rMv9a1s0G3CwuzMJwumRzbwuDSaPnbHv2hpDzax0x37p4BMAOOtMT3breJI53Yh2H9bFIxYzKPzeywO9y+Pqg7xIttEvo/1FA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J5u5Yq3YuHRARolHIAmYJYLOKZwbb0f3b4u+zIdySoU=; b=spVG53krI5NOWfNovKHjRWoc4Zm27177a3xShY4clOVKcklbRyigXa8tlmCEN3M83CuAfM6xfiEeVoXIww518Xpaf74rYRZdkEF1YcuNHgX4pdL7WftoM8VOMNBMzuurg9BrfPugb4HMNbRm+ucS2a5cJrAwhNI4YDL11UMpbXdcDfBjOtEb1044E0P8WXme3AZyVr9wMvIZt6cbz+0WTPG2EgEHVwVJPhXwgTVOQkp54FMT3WAh2yor1J9QWPojdpBFmnX7zlEE+IoFr0EEWG1lbdl7OE0WxHKuK5SfCYPF8BNj7rCj/pCJx3sReOnOLpIPkBm6/A/+YFxSztO1bQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CH0PR12MB5330.namprd12.prod.outlook.com (2603:10b6:610:d5::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.20; Wed, 20 Sep 2023 13:18:25 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::faf:4cd0:ae27:1073]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::faf:4cd0:ae27:1073%6]) with mapi id 15.20.6792.026; Wed, 20 Sep 2023 13:18:25 +0000 Date: Wed, 20 Sep 2023 10:18:22 -0300 From: Jason Gunthorpe To: "Liu, Yi L" Cc: Baolu Lu , "joro@8bytes.org" , "alex.williamson@redhat.com" , "Tian, Kevin" , "robin.murphy@arm.com" , "cohuck@redhat.com" , "eric.auger@redhat.com" , "nicolinc@nvidia.com" , "kvm@vger.kernel.org" , "mjrosato@linux.ibm.com" , "chao.p.peng@linux.intel.com" , "yi.y.sun@linux.intel.com" , "peterx@redhat.com" , "jasowang@redhat.com" , "shameerali.kolothum.thodi@huawei.com" , "lulu@redhat.com" , "suravee.suthikulpanit@amd.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "Duan, Zhenzhong" , "Martins, Joao" Subject: Re: [PATCH 6/6] iommu/vt-d: Add domain_alloc_user op Message-ID: <20230920131822.GZ13733@nvidia.com> References: <20230919092523.39286-1-yi.l.liu@intel.com> <20230919092523.39286-7-yi.l.liu@intel.com> <7aa8fd9e-e43d-db68-bdb6-fe4f891255ca@linux.intel.com> <20230920130522.GV13733@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: BY5PR20CA0010.namprd20.prod.outlook.com (2603:10b6:a03:1f4::23) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB5330:EE_ X-MS-Office365-Filtering-Correlation-Id: 45373b7c-748f-4750-7fba-08dbb9dc1211 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YO68aSxL3OkUDrMeZxEMB7RtMXkYjC3HiTcn3SY7Laza7McvBQfkCaTa6Xs7W3MIzWKGz9LubLQ2xc2wsIpFt7UhPug70elQCxGQHj6rl3sBmOJQbCs9qP2Umcy9smkd1XOXG2HxVEccxxDw3lK6anNPvZTnlLadEEMuBunQFZTKbgFhtZvmNZ9OP3xBMV2wP+SbA10TRMV5AZoQG6yk9CUGzfpjjO14V2qP5m3WIEFtBCY8/LV3JqaTXgiwTC5PNXnaJIgv8HLwXtMwfjPFf5FyoyP6OlgXy4yInWVzRqwbI+obOchwigpb0JZi1zEBQL0dpOBSSSc2WOFfls11RK4CHRG7NYB1vuST6L5t4d5ghzp5UgZQ44xFJWyT7g2i8SxbLGsUbNmb+BQGYyPz1/+B7BP2pIayrpWCWDoPNp9FfXS9vFzTCEeHyDDd8gBu8mrfclmH+gbO2kT0EorEVDqFEbjCkuoHr0z2myqOEXWBRY275N2Vd5seXt6IjyI/BLqRwRRx35bWlfxpcrbzdLZaPjxpHSIWygGxWgi3ktx5hx/Q52R87l1wrimV3J9z X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(346002)(376002)(396003)(366004)(39860400002)(451199024)(186009)(1800799009)(4326008)(8936002)(8676002)(41300700001)(36756003)(6486002)(6506007)(5660300002)(6666004)(6512007)(26005)(1076003)(2616005)(6916009)(316002)(86362001)(54906003)(478600001)(66556008)(66946007)(66476007)(33656002)(2906002)(83380400001)(7416002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?RxSZ80Hev3j9ZZz7F3f2y1+QvGpSw2zHOCvULGKnzpgm9kd94JQNLSiAK5lN?= =?us-ascii?Q?GdloLm/TzxS23chT8agNLvgX0wwHWZ07iTuPGRoMqYzM7Wb5TzM9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IEBSBt6bPqFxfddGGJHfKtSnvsybOEBEac1?= =?us-ascii?Q?9vpYB6563coWC0ed2GBS/lXKTaSPyz4EuwN9lBnS0AJHlfa2IMABRd7iVMEd?= =?us-ascii?Q?3pWMACG3orqPE0wo0Jh4XE7Sw9aP3i1ylYrS8Cn54ht9hGI1o7WugMX/lwNQ?= =?us-ascii?Q?szfZ0oEZVSUi5DlhvwILVWWmNZlj0rfiMN1l2OmzIPIfNfI9hJ5O3uyXpVOG?= =?us-ascii?Q?H/c6xLk/PQHk9hKnvkVu0gK3wiC09mBf5J8KKL39A/8+YcSr/OrSgNteCdHC?= =?us-ascii?Q?Ku/Og9325d1yf4ycevhFbrNl6a6mZhsGEGtfQqzb+JvCpUHOqeJwAxQN39QJ?= =?us-ascii?Q?uJ/LesRCHtwhjtmkwfYpUwc5HTUFiu+Kwx3gfu9nT2bf95Zno+M56igWy7+Q?= =?us-ascii?Q?udSUMkXOTlFVLosQlDKQB1+UjJ0m4dscHkJakHvdBzZmwSqXJggz5vskmmZ7?= =?us-ascii?Q?RCLRJwI45TmQFjrxkun8AhT0hcCqpXzmUWh8yVKN0PNeZLVrsWBNEtwe5Dx5?= =?us-ascii?Q?9eVEX1JlFMpqRDF+c6ZRgf9BthiXgZu6YYh56hq8ZcQxnn0OeoyeeZdAcy1h?= =?us-ascii?Q?wNWN2dOBNaj2EvFnPdSbpiscjvpyXXQqKzD9mhi3?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45373b7c-748f-4750-7fba-08dbb9dc1211 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 13:18:25.1147 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: t/WM7KXs70h0iWv7+N/quviPHXtMUyXpmo16rt52yQlADfGt6Y2IOeJihbpN5I7M X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5330 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 20 Sep 2023 06:19:01 -0700 (PDT) On Wed, Sep 20, 2023 at 01:10:04PM +0000, Liu, Yi L wrote: > > From: Jason Gunthorpe > > Sent: Wednesday, September 20, 2023 9:05 PM > > > > On Wed, Sep 20, 2023 at 01:28:41PM +0800, Baolu Lu wrote: > > > > > > > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > > > > index 5db283c17e0d..491bcde1ff96 100644 > > > > --- a/drivers/iommu/intel/iommu.c > > > > +++ b/drivers/iommu/intel/iommu.c > > > > @@ -4074,6 +4074,25 @@ static struct iommu_domain > > *intel_iommu_domain_alloc(unsigned type) > > > > return NULL; > > > > } > > > > +static struct iommu_domain * > > > > +intel_iommu_domain_alloc_user(struct device *dev, u32 flags) > > > > +{ > > > > + struct iommu_domain *domain; > > > > + struct intel_iommu *iommu; > > > > + > > > > + iommu = device_to_iommu(dev, NULL, NULL); > > > > + if (!iommu) > > > > + return ERR_PTR(-ENODEV); > > > > + > > > > + if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu- > > >ecap)) > > > > + return ERR_PTR(-EOPNOTSUPP); > > > > There is a check missing for supported flags > > > > if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) > > return ERR_PTR(-EOPNOTSUPP); > > Well, the iommufd has such check. But I also noticed your another > reply to Weijiang. So your preference is to do the flags validation > in iommu driver instead of iommufd. Isn't it? The core code should check that only kernel known bits are set The driver code should check that only driver supported bits are set. Today there is only one bit so the checks are the same code. Tomorrow when we add a new bit the checks will not be the same Jason