Message ID | 20231106071226.9656-2-tina.zhang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2487809vqu; Sun, 5 Nov 2023 23:14:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGu66dXHfB8bC3zU6OWMbHWbSVdBPa64ENRSzxmHZeogRjcM2tNqSK09GzokllJb3TznZv1 X-Received: by 2002:a17:903:30d4:b0:1c4:4462:f1bd with SMTP id s20-20020a17090330d400b001c44462f1bdmr19901409plc.35.1699254885727; Sun, 05 Nov 2023 23:14:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699254885; cv=none; d=google.com; s=arc-20160816; b=BFTYjn+5I8txh5C1FDKz8NaKRNIXpb60ry6kpl3YD8wqBCElyRSQeuumqArAZ2q7uH rDf7Xo4x3SKYXCcxlMny9uzNWqkRqpreOjdh/zDLvEruLWS/qM2tG3QDgleTIMt+f9gr BmZDbT9UiOsb18ou4v1oTzoHn/3kznov2jK23u763O2dhYBPmyji3g0AVUjz59B/p/ct Hyv24GI93Sz1xuAbGxpqYjIxorraFWdstLDVSLkAXUzG84gSWT7gSFsFEWexGZ0OWj3X qpwY6zsiFj5zGLEIajudQrzynI6zeYEWue9vYxE7GS9o+3Qd1CXlfGcY/9VdyAhEpZaC 0bJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4OSmhB13o36GGCYPfP32Z4ZWypmqrm49R+/69lLR000=; fh=Q9/c0/1s/r5nQXfLb7W3lFTON2d/CYIL48MtbxJzpb8=; b=1E9yquIRwka6HdcmyBTlOZATe2xyBcyOJb1jxFY9KLTGzCOtT98JlSeTPG4BdXe9Zm qMRygBARJK8YYU889Mr13NmWps9T6/V5lBL7o7jE7uJWuQESS0VbOAZexPxso9JjxVwM L+VLRzRCJFETlr1twixqHnCRm7ny5iSQAq6qHTAb0mIYTVJdwCnwfXTwuOtypCCdm6gb +2jxOZwd4SpVWc3AFnqyqFVkjKARaXa3DDLT8EG3sYFWeh25VwJfEGjvZ/YFPkv+QMZ7 jF7qsrsVNjprGxEgKAEvLNf0XnQRzUmD/rSeY/z2TT3CaTbYglsYSGIW4LFNsAS03CHZ MsPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Yz3QYMGX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id o10-20020a170903300a00b001c61bd9db5csi6959259pla.317.2023.11.05.23.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 23:14:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Yz3QYMGX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id AA41980A2379; Sun, 5 Nov 2023 23:14:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbjKFHOE (ORCPT <rfc822;lhua1029@gmail.com> + 35 others); Mon, 6 Nov 2023 02:14:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjKFHOD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Nov 2023 02:14:03 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44A93D8 for <linux-kernel@vger.kernel.org>; Sun, 5 Nov 2023 23:14: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=1699254841; x=1730790841; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c9GeMl676tMxuvRJHqXrxAMwFdaSUf5heq0NrXZPU0Q=; b=Yz3QYMGXBJaVza0EErGtDr++UqnzoYwipTPYBeeJZIjZITKxzCNvxyGV KKMiM9oe9bDJdynXu5iR4jDXxeE8W+vLpWHzrthCKCkcDOF1q8woWVMRT kyxVKLDI3dC5HsfrKiiElE4+lgelm0dCGwKJw5AWPpD1eXuiKUVAZl5i8 OQprKUnp0uHtkv8jhE5TW13W7zobrb5UwfKAPRX69pMGcS41kg11Ysd8l PShFL+qPhrtR/6mf2KjT6eBw4SVKDTf0f00AJ2gvk9FRwqeLmSxBiNr6B jExKqBxZgF4P6i6w3y2B2P9wXUbivZW8Qbh8UuDFFVryElB5cA4we0pft g==; X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="10759042" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="10759042" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2023 23:14:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="1093690868" X-IronPort-AV: E=Sophos;i="6.03,280,1694761200"; d="scan'208";a="1093690868" Received: from sqa-gate.sh.intel.com (HELO localhost.localdomain) ([10.239.48.212]) by fmsmga005.fm.intel.com with ESMTP; 05 Nov 2023 23:13:57 -0800 From: Tina Zhang <tina.zhang@intel.com> To: Jean-Philippe Brucker <jean-philippe@linaro.org>, Kevin Tian <kevin.tian@intel.com>, Lu Baolu <baolu.lu@linux.intel.com>, joro@8bytes.org, will@kernel.org, Yi Liu <yi.l.liu@intel.com> Cc: virtualization@lists.linux-foundation.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Tina Zhang <tina.zhang@intel.com> Subject: [RFC PATCH 1/5] iommu/virtio-iommu: Correct the values of granule and nr_pages Date: Mon, 6 Nov 2023 02:12:22 -0500 Message-Id: <20231106071226.9656-2-tina.zhang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231106071226.9656-1-tina.zhang@intel.com> References: <20231106071226.9656-1-tina.zhang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 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,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 fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 05 Nov 2023 23:14:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781797891208579922 X-GMAIL-MSGID: 1781797891208579922 |
Series |
virtio-iommu: Add VT-d IO page table
|
|
Commit Message
Zhang, Tina
Nov. 6, 2023, 7:12 a.m. UTC
The value of granule is ilog2(pgsize). When the value of pgsize isn't
a power of two, granule would make pgsize less than the actual size of
pgsize. E.g., if pgsize = 0x6000 and granule = ilog2(gather->pgsize), then
granule = 0xe. 2^0xe = 0x4000 makes the pgsize (0x4000) smaller than the
actual pgsize (0x6000). Invalidating IOTLB with smaller range would lead
to cache incoherence. So, roundup pgsize value to the nearest power of 2
to make sure the granule won't make pgsize less than the actual size. The
value of "gather->end - gather->start + 1" also needs similar adjustment.
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
---
drivers/iommu/virtio-iommu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 08e310672e57..b1ceaac974e2 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -1289,8 +1289,8 @@ static void viommu_iotlb_sync(struct iommu_domain *domain, if (!gather->pgsize) return; - granule = ilog2(gather->pgsize); - nr_pages = (gather->end - gather->start + 1) >> granule; + granule = ilog2(__roundup_pow_of_two(gather->pgsize)); + nr_pages = __roundup_pow_of_two(gather->end - gather->start + 1) >> granule; req = (struct virtio_iommu_req_invalidate) { .head.type = VIRTIO_IOMMU_T_INVALIDATE, .inv_gran = cpu_to_le16(VIRTIO_IOMMU_INVAL_G_VA),