Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4434702rdb; Mon, 11 Dec 2023 21:39:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJ3kyj3Bohjj+PhSEpbOdKlXPI8snb1p+4t9bZhTOEhnqA6YjeNCGK5F/A4MpvB4uqByuJ X-Received: by 2002:a05:6808:4446:b0:3ba:130b:af64 with SMTP id ep6-20020a056808444600b003ba130baf64mr2710495oib.38.1702359553625; Mon, 11 Dec 2023 21:39:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702359553; cv=none; d=google.com; s=arc-20160816; b=EV8LKRHv4ur7w1IkP14+7gOBgIT52oJq6o8BPBpRtkZM8qmG9piIN9HtLSS3Eedhe5 BKb0pJqtElQQJ+dGPvyC79ri1S6YEGsfbP5gwsr2mh+mgKH0Na4NgJLyBLCfzSHFn7YH KF41TdFB/UBmZ4UdaTfa3k1XDMDXgW7YdjzPm4MrCbh+gfqGTtxDSRZbBkAMnp/dySiR i/Rw7bapw/cp3vSc2g6AqPYdLOBPihsiCpLB1owYrQoSGuhoJwrZVqzGbx4lkrOYTT9Z /aaOxpxczbIvnwjMfZ75neS/VR8hya95rIHGot0nLtGVDazKbx4wju7o9uHgiDgD8K5e lh5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=2K22u1rujRERU0TWB9kCNOOAWAbo3CmSYhs8AehNp8U=; fh=JpfWtCw9fBPh0qfGxT1K2yf4i+TGEOcQwG1UWtdiC3c=; b=MNLnnJNXVJEFzN3wq/rJzZmpy6YpcplX8F7yygc8svBk6qkjDVN00/enZB4X58txt2 ojwQ4ZyQMnDPnZDLy3PAh/EDZHjFXRqr6/iSxgxbbNmlMThwvOOUOE7SkFBs9j77j0dW N6bDU1RqadeY5nuJUUB41g9u8waZT/mrB8pPDc9U/2WjVp8C5dqQ8hFjOwjP0TrPcFLW zgOvifb9tRBsuQGER1bh2ZJOyDj55k5xxaJ1jrRyUyDV1Wb/5vU8nh5BkKk+5X2YpcsQ 1h8e7nshJf16itb2q0zkMbPwzJEoIviX/Z+MSC1othA2Q/rt8KcSBK1adwZNa2SkKnWq huxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nTlffpbo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id k6-20020aa788c6000000b006cbf2bc1af9si7167714pff.0.2023.12.11.21.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 21:39:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nTlffpbo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D92E4805B062; Mon, 11 Dec 2023 21:39:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229537AbjLLFi4 (ORCPT + 99 others); Tue, 12 Dec 2023 00:38:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjLLFiy (ORCPT ); Tue, 12 Dec 2023 00:38:54 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EE67BD for ; Mon, 11 Dec 2023 21:39:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702359541; x=1733895541; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=URPPQzLd2OI8UNUzOy+LBsiW7V7L/EcaPm3oslOKIC4=; b=nTlffpboGZpWrNXcswqaAHv52ZqlXfZAP25GSAK4u+tlaa0XdZQuYr3A 5HZ4J6Z7iSVUNLZF2Lo/Z63t1ifvlHWhjSLV5xKONfeA68Swj+V2DT2JV ssHyV6NbKstnzW3aKhZPmo3x5DKERm0Plv6MjcYRWibK4Bm7eQU1+b5eG jksmlvHlvnZoEnjiroMA0JZe8EhmUCqc3Ki+x2uyYcUTHy3NXsOojzb/2 NOG6EAOCOjibM2x8yI7IdKLUTZPFZTmyHkC97aVYNK6yMtDJwjEbbhjh/ BIsev/1eqIVJe9UDWD6Pw2wGIQ/52Y2oxjrWOyBNgAqW3NWekiDEkDAw9 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="461231777" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="461231777" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 21:39:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="917149775" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="917149775" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by fmsmga001.fm.intel.com with ESMTP; 11 Dec 2023 21:38:58 -0800 Message-ID: <11b4b1db-2fde-413c-a203-0734bc18f4f7@linux.intel.com> Date: Tue, 12 Dec 2023 13:34:19 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/6] iommu/vt-d: Setup scalable mode context entry in probe path Content-Language: en-US To: Jason Gunthorpe References: <20231205012203.244584-1-baolu.lu@linux.intel.com> <20231205012203.244584-2-baolu.lu@linux.intel.com> <20231211173826.GE1489931@ziepe.ca> From: Baolu Lu In-Reply-To: <20231211173826.GE1489931@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 21:39:10 -0800 (PST) On 12/12/23 1:38 AM, Jason Gunthorpe wrote: > On Tue, Dec 05, 2023 at 09:21:58AM +0800, Lu Baolu wrote: >> +/* >> + * Get the PASID directory size for scalable mode context entry. >> + * Value of X in the PDTS field of a scalable mode context entry >> + * indicates PASID directory with 2^(X + 7) entries. >> + */ >> +static unsigned long context_get_sm_pds(struct pasid_table *table) >> +{ >> + unsigned long pds, max_pde; >> + >> + max_pde = table->max_pasid >> PASID_PDE_SHIFT; >> + pds = find_first_bit(&max_pde, MAX_NR_PASID_BITS); >> + if (pds < 7) >> + return 0; >> + >> + return pds - 7; > This seems like a convoluted way to write > max(ilog2(table-max_pasid) - 7,0) > > ? Yes. :-) Something like, max(ilog2(table->max_pasid >> PASID_PDE_SHIFT) - 7, 0) Best regards, baolu