Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2364783rdb; Mon, 5 Feb 2024 04:33:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcT0NHg4i3IGytMr8OtnlI0Q0OqvPWWU2nK0Db1sWCmDAUz4d+EiBHm5sJorx0aakKbPM2 X-Received: by 2002:a17:902:ea0c:b0:1d9:9fa7:4e0b with SMTP id s12-20020a170902ea0c00b001d99fa74e0bmr6930613plg.43.1707136387332; Mon, 05 Feb 2024 04:33:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707136387; cv=pass; d=google.com; s=arc-20160816; b=tHtJayEeypVC+GgY4Mxs5OQJqcow5jF70vosvTEAtUSfsKYBihA91/dreRuomD6TRp MFwXIWKQ1G+mPbwTGR+V4q7P41Ht1NApGoP5NC4RDD8HsmGy3be53z7/7tPMWbHAXB40 wX/YXRdV6bNVlNS/LPq0u9bQ6IJujam9yrXF/Zm9It2RbaXSa6O+GZsxQNR37dxIGyLm KSr6gQmiBgxHFnXzci3e+La3z/x74SxV6gX7X1mP0XjTKEkwomrsXy1/+f03s4tfYXM3 uRbzVKMtyvDQ3t+W9qXLocdN0srVSmdQqYmOo6lLvP17GEiU36r+1gOLIWeJSiatOAQR J1ig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nHBURAsv2kVj18uGoBS/ynF5eAKuZbHIuIE7fti0DT8=; fh=H8NL5COill8HUAxuSHhnUc4YpZN421yAKJDa+78L1ck=; b=AM9vHrchtXk8DARnfTEeUeM78vsStDRtK3TPHyDa/PwiO0P6DpWMQK/IM07/bsBBz8 2iIFZArhIkKi4xeoFx5S9exhJrGdC+a3ee053F83kFwt9O/6xpjEC8Jd4OEfAP7oLAY7 Pfb5Znm7EPbYIqjx47fqhffmFMZqBtURmzA0r2h24B5eRYOnFjQKcxrOBU4gaipZy8Ry Bf+al8gi3jbR1bWgppAUKiQmeGt6lVlSsbKsisliP3mCtJ3oQ9s9mJ0Gb1pLA08027NP e0N3JYLVeOjAJwRugu4sQrbEMv17jmSgd4AstM8jCoweiF9h8pX9Y39hAwFsEp6HmOkQ l7/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=tPu64pUv; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-52562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com X-Forwarded-Encrypted: i=1; AJvYcCV1c7dYNP0huFFc3OnS8sPjZfgMDAYihGxk7unp8LhWL4FgMh9S70qrvnhg7jJsa7bRb4f82xYhCRQ6P41PEu77qH7WF2eioBkzrVrsGw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y15-20020a17090322cf00b001d991a0da23si3629329plg.102.2024.02.05.04.33.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 04:33:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=tPu64pUv; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-52562-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 161AAB22729 for ; Mon, 5 Feb 2024 12:11:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45D6A208DE; Mon, 5 Feb 2024 12:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="tPu64pUv" Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E369200C3; Mon, 5 Feb 2024 12:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.152 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707134767; cv=none; b=jr+433HzYYAtjj+BxAl+SVaMSqVuXS9x6saff/uj1A8eGyY6Fw8DvRuYxJjigUInFdoDQ+gl/TDMnaelpwYCwBgtxpOEn2+1euExWWX+SFTe28mnq+9scTGnErgETxTNyczCMin4BBySZRqpaBK3ISD7bVKGO2c94u7XIk3fGa0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707134767; c=relaxed/simple; bh=wiv5U2uS8hUNGvTNLpJMav4y5mpoMA0A7e/DcQgUB54=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cItoH1kD6BBUG1ze24SXY7eIs18Ol8VIwjTLBPQD6tCuyUwNL4uJlvsCupedWL7J/93A0kEMU042wJbnGC4qb/D9yU4ehwM4z/RxCrlefUT7f0PT487XQRsHYMjLDQIjI3qhvCv8/7YPNbtXaHLn+jwdZZ3BWzaFi4NZsIRlElc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=tPu64pUv; arc=none smtp.client-ip=52.119.213.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1707134766; x=1738670766; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nHBURAsv2kVj18uGoBS/ynF5eAKuZbHIuIE7fti0DT8=; b=tPu64pUvAr6GnsEJ2eZJyq16WF88nHXybjAkbNmSFVN6DizbghynKDZN VMYgd63kckia0/Kh+s2KMXDnCkauoyNrhzbwajn+MWNP0ZFgLFFKsJ3fv tODXa+LUMh4p3y8a2ACA2lLkRz1SBH6fWIl1iSwR08WAmOWQ2Qkpzd9a9 4=; X-IronPort-AV: E=Sophos;i="6.05,245,1701129600"; d="scan'208";a="635764854" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 12:06:02 +0000 Received: from EX19MTAEUA002.ant.amazon.com [10.0.43.254:50504] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.28.192:2525] with esmtp (Farcaster) id a892883c-e384-427e-8387-b1c5e5820895; Mon, 5 Feb 2024 12:05:50 +0000 (UTC) X-Farcaster-Flow-ID: a892883c-e384-427e-8387-b1c5e5820895 Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:05:49 +0000 Received: from dev-dsk-jgowans-1a-a3faec1f.eu-west-1.amazon.com (172.19.112.191) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 12:05:43 +0000 From: James Gowans To: CC: Eric Biederman , , "Joerg Roedel" , Will Deacon , , Alexander Viro , "Christian Brauner" , , Paolo Bonzini , Sean Christopherson , , Andrew Morton , , Alexander Graf , David Woodhouse , "Jan H . Schoenherr" , Usama Arif , Anthony Yznaga , Stanislav Kinsburskii , , , Subject: [RFC 15/18] pkernfs: register device memory for IOMMU domain pgtables Date: Mon, 5 Feb 2024 12:02:00 +0000 Message-ID: <20240205120203.60312-16-jgowans@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205120203.60312-1-jgowans@amazon.com> References: <20240205120203.60312-1-jgowans@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D042UWB002.ant.amazon.com (10.13.139.175) To EX19D014EUC004.ant.amazon.com (10.252.51.182) Similarly to the root/context pgtables, the IOMMU driver also does phys_to_virt when walking the domain pgtables. To make this work properly the physical memory needs to be mapped in at the correct place in the direct map. Register a memory device to support this. The alternative would be to wrap all of the phys_to_virt functions in something which is pkernfs aware. --- fs/pkernfs/iommu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/pkernfs/iommu.c b/fs/pkernfs/iommu.c index 5d0b256e7dd8..073b9dd48237 100644 --- a/fs/pkernfs/iommu.c +++ b/fs/pkernfs/iommu.c @@ -9,6 +9,7 @@ void pkernfs_get_region_for_ppts(struct file *ppts, struct pkernfs_region *pkern struct pkernfs_inode *pkernfs_inode; unsigned long *mappings_block_vaddr; unsigned long inode_idx; + int rc; /* * For a pkernfs region block, the "mappings_block" field is still @@ -22,7 +23,20 @@ void pkernfs_get_region_for_ppts(struct file *ppts, struct pkernfs_region *pkern mappings_block_vaddr = (unsigned long *)pkernfs_addr_for_block(NULL, pkernfs_inode->mappings_block); set_bit(0, mappings_block_vaddr); - pkernfs_region->vaddr = mappings_block_vaddr; + + dev_set_name(&pkernfs_region->dev, "vfio-ppt-%s", pkernfs_inode->filename); + rc = device_register(&pkernfs_region->dev); + if (rc) + pr_err("device_register failed: %i\n", rc); + + pkernfs_region->pgmap.range.start = pkernfs_base + + (pkernfs_inode->mappings_block * PMD_SIZE); + pkernfs_region->pgmap.range.end = + pkernfs_region->pgmap.range.start + PMD_SIZE - 1; + pkernfs_region->pgmap.nr_range = 1; + pkernfs_region->pgmap.type = MEMORY_DEVICE_GENERIC; + pkernfs_region->vaddr = + devm_memremap_pages(&pkernfs_region->dev, &pkernfs_region->pgmap); pkernfs_region->paddr = pkernfs_base + (pkernfs_inode->mappings_block * (2 << 20)); } void pkernfs_alloc_iommu_root_pgtables(struct pkernfs_region *pkernfs_region) -- 2.40.1