Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp304536pxt; Wed, 4 Aug 2021 23:34:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS3R8rallJP3HCMkgz8xAWSy4c6YtXF3VQDDy9C1juDmRm1n/7OK07DVOHCvwC6vR0NUmQ X-Received: by 2002:a6b:7209:: with SMTP id n9mr223258ioc.67.1628145283121; Wed, 04 Aug 2021 23:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628145283; cv=none; d=google.com; s=arc-20160816; b=UjDUtLLJQoS5CDRh3JIR9WBjjMOrOVPABHgVGu3WvCERvMJr8RXvamjZxTi2+w9R7e SfnBQhAZ+pDFR7izE8L0hMGchsh+zzpMSnw3gPNK+moD1YIQtv+BK7miTOqEKxS6+wsb GEj1oe53ft5mZIm0iBYI0QtT4iJMsfJQTaZVsOJwbLNsC/steDZ0caDvbfnWOx4FfdIY hk/NY5qiou3449gclPyV6p1oBPYfp9hu9rDSMTPk90S8Kt6CXE+sWrZv7eWP3CIzXaE6 QwGMIA8zZkrA1JM83YBS/prWZU65dYeNovqgBjUbnlNueJCVC9VoJq8v0YHsmYmvStfa qVYw== 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; bh=UnpJEdt3Km6x5lPaAdAAZxxIHdvuzZi+2dX8+UkJJMs=; b=UsVgoYTZuMA0ezWlfK77/U55W11esloSPBb4yR2yyONDlLVhJL6F6X6K/N7aYkOtRq wKZPvzU6JbU/ATOFKyrbGN9cC3ia8GD2M+eXzxSUgRuhMCrl4Jd38c0iZGY82yz9uXE6 /umooK3qe+b8S7DXXkElXbsmS9fOvtfPyiNIyynDdU0BVWBcS2jD+thu3zT9nvDXl+Ul lPuAX9ozz4PrXCxkAPYlB928OoIGr14OsJxcJilKV22QzvL+cBMgUesu0ceX11CIm5kg Xytd29Q+uo++AoBNqLEMR+kp13wx6C4I13zGHxPl1KFIXAYC//7VZp8dQnxflX4JvkjB JuXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si5093274jat.55.2021.08.04.23.34.31; Wed, 04 Aug 2021 23:34:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237009AbhHEAy2 (ORCPT + 99 others); Wed, 4 Aug 2021 20:54:28 -0400 Received: from mga09.intel.com ([134.134.136.24]:27477 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236905AbhHEAyH (ORCPT ); Wed, 4 Aug 2021 20:54:07 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="214027483" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="214027483" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:45 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="437617274" Received: from mjkendri-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.17.117]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:42 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Bjorn Helgaas , Richard Henderson , Thomas Bogendoerfer , James E J Bottomley , Helge Deller , "David S . Miller" , Arnd Bergmann , Jonathan Corbet , "Michael S . Tsirkin" Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 11/15] pci: Add pci_iomap_shared{,_range} Date: Wed, 4 Aug 2021 17:52:14 -0700 Message-Id: <20210805005218.2912076-12-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen Add a new variant of pci_iomap for mapping all PCI resources of a devices as shared memory with a hypervisor in a confidential guest. Signed-off-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan --- include/asm-generic/pci_iomap.h | 6 +++++ lib/pci_iomap.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/asm-generic/pci_iomap.h b/include/asm-generic/pci_iomap.h index d4f16dcc2ed7..0178ddd7ad88 100644 --- a/include/asm-generic/pci_iomap.h +++ b/include/asm-generic/pci_iomap.h @@ -18,6 +18,12 @@ extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar, extern void __iomem *pci_iomap_wc_range(struct pci_dev *dev, int bar, unsigned long offset, unsigned long maxlen); +extern void __iomem *pci_iomap_shared(struct pci_dev *dev, int bar, + unsigned long max); +extern void __iomem *pci_iomap_shared_range(struct pci_dev *dev, int bar, + unsigned long offset, + unsigned long maxlen); + /* Create a virtual mapping cookie for a port on a given PCI device. * Do not call this directly, it exists to make it easier for architectures * to override */ diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c index 6251c3f651c6..b04e8689eab3 100644 --- a/lib/pci_iomap.c +++ b/lib/pci_iomap.c @@ -25,6 +25,11 @@ static void __iomem *map_ioremap_wc(phys_addr_t addr, size_t size) return ioremap_wc(addr, size); } +static void __iomem *map_ioremap_shared(phys_addr_t addr, size_t size) +{ + return ioremap_shared(addr, size); +} + static void __iomem *pci_iomap_range_map(struct pci_dev *dev, int bar, unsigned long offset, @@ -101,6 +106,47 @@ void __iomem *pci_iomap_wc_range(struct pci_dev *dev, } EXPORT_SYMBOL_GPL(pci_iomap_wc_range); +/** + * pci_iomap_shared_range - create a virtual shared mapping cookie for a + * PCI BAR + * @dev: PCI device that owns the BAR + * @bar: BAR number + * @offset: map memory at the given offset in BAR + * @maxlen: max length of the memory to map + * + * Remap a pci device's resources shared in a confidential guest. + * For more details see pci_iomap_range's documentation. + * + * @maxlen specifies the maximum length to map. To get access to + * the complete BAR from offset to the end, pass %0 here. + */ +void __iomem *pci_iomap_shared_range(struct pci_dev *dev, int bar, + unsigned long offset, unsigned long maxlen) +{ + return pci_iomap_range_map(dev, bar, offset, maxlen, + map_ioremap_shared); +} +EXPORT_SYMBOL_GPL(pci_iomap_shared_range); + +/** + * pci_iomap_shared - create a virtual shared mapping cookie for a PCI BAR + * @dev: PCI device that owns the BAR + * @bar: BAR number + * @maxlen: length of the memory to map + * + * See pci_iomap for details. This function creates a shared mapping + * with the host for confidential hosts. + * + * @maxlen specifies the maximum length to map. To get access to the + * complete BAR without checking for its length first, pass %0 here. + */ +void __iomem *pci_iomap_shared(struct pci_dev *dev, int bar, + unsigned long maxlen) +{ + return pci_iomap_shared_range(dev, bar, 0, maxlen); +} +EXPORT_SYMBOL_GPL(pci_iomap_shared); + /** * pci_iomap - create a virtual mapping cookie for a PCI BAR * @dev: PCI device that owns the BAR -- 2.25.1