From patchwork Fri Dec 2 03:30:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25E7AC4167B for ; Fri, 2 Dec 2022 03:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232100AbiLBDce (ORCPT ); Thu, 1 Dec 2022 22:32:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232054AbiLBDcP (ORCPT ); Thu, 1 Dec 2022 22:32:15 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021020.outbound.protection.outlook.com [40.93.199.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0916D9B39; Thu, 1 Dec 2022 19:32:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bcvcUcxGHqP+bRG4DXN3e8wE7xKIzxxtx6+94IoZJCpVWPQ/Be4USKZLx/7Uta+xTCq0OPbzFEee9GSjfUa0Yh0d9e29PwJZyGr4AgOaT52C4BiS9UdVwc4QK9rFQHg2rHC7EcCsG0qSt4iAkMo1Pj7VysY7ivfD5KLRTFiTiE9r7+MfDcu/dybi4HfJRdjTxdwhwZ6ngrOafXaAjjQyXXtaMM50pwUOqO6NHoLUZ36Iv+RuYkoP7c5Xc+SdushaLcq2n/QMZ/ArJT4KNafMOwHk2V9ABY0Kxs8rVWejcI8pWEPoTE0Oe1+Ko9vAGm+1J2glQLxKqgBXdGqarBHXYQ== 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=Lk2VDA8PK6HH9QYkfJfq+OgtogjLpKdOY0dq2ImQLko=; b=DzQZFd/ILOo1L+GVi5me9Neihx0ZoGk4v9pkZXVbrQ2Zwp1Wr0UjvKFLTAaYjKxYuioNBTCYOLgqejwt3KyF65/vW1PVnYqARDsGYCIk/T20bn1SLofJMGhAKdp0+RIrK1AtkU3hYHCcNvo/7fnK6W6F6i+HOUz2eOubTg+KriMTk8Gx3AHnN/r/9IfvDWXdLv2VemIsoBOyXcVe7CIEZfYHK4JNeBMwncBb5Ze6h1F5t5MInpvKsRAvJaRY/5uDRhcdZTJWe4OiTGOStKidgWY5egHz2OB8aQE6yPuhoNQ0fO0q5pTrogyhoqbjknoWV84BR0YbMG+ebywRa30nlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Lk2VDA8PK6HH9QYkfJfq+OgtogjLpKdOY0dq2ImQLko=; b=LW7edWm+INDzPE5bcFFbciEhMLU0gOOI1ycwQv1LFHa7yNcSHS/aiTj3NQbwdgL2MUK8+X3zyV9Ro4T7zsK2gry3MOwb0R9cJ858b9tf7x4iHXaNdL2bJVGlWIVNdUL2kw7zRnUGTH5Tu+wz5ey12+5ntXnQhgBdaq6C4AubcOI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:05 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:05 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 01/13] x86/ioapic: Gate decrypted mapping on cc_platform_has() attribute Date: Thu, 1 Dec 2022 19:30:19 -0800 Message-Id: <1669951831-4180-2-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: b62a164f-714a-4679-711b-08dad415c85b X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L95MwJiDD8Ho40Ixp3kZUdI1547fVrQjP/+WpHo6LSOeLDz6pcRK563/JONVINVGqUYIV2bD3fhu9hn6oI4ngF1PBUu2NcGS5CNPSmTYdb5Lz02bBv8m2UNvKzVUWre5jmDYky2SAJOVrFuPwdtgPW9Leg5X8PjFflf8y5jbk4gvv7CxUB53uCQQ59qGJ6C6IgvBuZFdLPBQnruV7zFmpYdXVZTy6SWU5BrtqusOS654T9v0viwEOsDfEFMUzpcYLvFZKTjk53Z+kuOdPZQRw/m7CamydFsDGZWj8eSyIBfEp3Su+ZnjOOASecRC2xgqPoqJfKFeAuf1n2QIrH5gRVPDf46TkGTWcfsHVYSin8gTU1byc4c1QJenZt4ar1jM8XrF2ZhLuelIKzLQWYP6JFCZcRjC8W7APNw+yPUbXqVfgGFjVwwR+aqFWbgBPMdnUtiMS4Oxz/6kFlaFUNWLzr2y5mX7IdcD4kGeS7brv2M1DQd/TAhIwPWQlmjPUa/M3Fnn6o/WLK4d2Teui3d0CL3YnFzHZ/bortOpkazCv/VQmudo8vzQpBkndRzAIurxksO+ryLWnT0ETl2kb7OOHbx3MzdoyADuotcjKNMQT3gUNPgeXGGeeK/CsZ8xaiEthUlN65K+nXQHniEA10zYTz0FezL+m9mU1uaD6VUOh2Gz6mA8pap7cdC3SsM0AHvC2vo4HERVSEByDQb1vyTL2v0ROE8hTFz9/icE4c07zDYAotN0stOTsY9oOWa8V10h X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(6666004)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TOouGj/nnkA9oIKK9EX/XO0EeNNwHZBIe7Tu1FgkUZP/OPslwWR/XbEViWdtPx0VGNa2nKHXEz0ev7Nlabik/T7nnP2VAvFN7MGG7zoK1LFZClvorMp6WSxzjqEcul7twUKTVomuz67UudhU6ZUM1/75KWJXiSETw80NzTgMdfRKixhWv9IG8lrDeEv/ZejzCZFHrT+lpO3w9dpsT7O/KDA9WXBDDkypmyXTuZR6QHxOT4jRRJWvNb7kw2N2eVccC3Yc3HHKtmV40cY2LFesfWfCrn47Mu1FIIo8/rP9YhdVRCHRPMe6m39iogTmDLNj9wCzYYICUTQtDchdog3Ly6EZYwaPoWu1sNovOWXyzj58rPTsYvM/gqBylPsXEnYPOzcQmcrtSz/sXWYJMA22PakAro7CjhkZ6n19YvDrGWAmOhTdQov5gWSuQ2vCNf+1JhfyU5Q/Czt54/d4dBHf21SnfZffXAP7q3zqHAGoY8P57FpmyU23YT+VK7nlDBDe40htzsvA8lY5NoV24/Hss+gbOrsuQDhmZSjqNR4BcbZXazpECTqI0mZVF0MO5fhF+tULRzFS+TxuKbivdi9s2R0Ux6034q2wV9Ukf9/ukGdK4FDMUEwhss/Uo0hUax73LiAQKIhRr5XD2GMp8fs0SYddiRFXIoshL4iFnkm0OyHrBOusl9Jzu8qdo1sahqZcxFj3gzYFCK/dLVjfU0pxHqAZO/7UALQcY8Qq6ihevhpUDMAyCGIuwQ7UEkM+l5sA0jUA3/8e9MxZ+B95XJkRf7XOidnCpQx0YsBcn3Ji6mDTuiRV0Xrh+FpIz1fkPJN7TX8Ng+4qgUGAvlgMzNywb7kLnrEk2g7mYztdBF2GHTAQRm2Q/wEQelQ29bCYdmdyFM3w9MwiBjywc5rHgw2Q9vZBKCV+9Sc0z8VuJOPjAMNNYqjKUCqnAfveatT5VcTEMwSM0OeOyKoA+9opKAfOA0IcxLkiByOA0TmqaGB6teRcPxtkYg4FwJUQ1CACBxWrRjOSCAWThldcfG+j0W3wusERArzkk1Qx6ZXPALSXEP6/yfcn4+DRimf8mJxox505dKLJHrDxG7dMnOzsOfAHZwUEDPYrzhzSWQ6aPT0qazqDRGoQrevPDYUw3Qq1195KZqg5cFLSZ6H8Kr84vvvy3q2NXijRygO0pLIVJqOPrQP19dAC+pwmV8IkKVcUOraJqbXLUsGKgH2nA0+k5WfvnZf1OpppMxZfEpCdyQ1cEPEHk+XdQIFxQFJR+10nf0mDDpphivHGFMR2uj7I2XGLeYT5vMjf7I3Lfbb6UTD7cdHHnEnHKgvLrE6bYloN7v6GJFiyQ7/3irJDO0JtDRY9iD6HVOGDap8z1i4y3TknWsWC9Iu4SUAn+Cj16FbiliLbDSWZ3xnOZLC1E5d3N5WptSC1aM6bZZ8yUimqBi/XqeBtP2EtSuXGVEpMbUGeKeri+liFQH/hdOOybyXuehdkDtS6XYwkmDdHN7inMkpmLvfA0DcTG9tLObtoRhpKjI+YbBBTYWvpJfSmdRioYv7YYshYF24kXmAcxin84aTV9oD1A140tCaLqjPYTo/RKm9qIfJccq3ICSZsd/Eu9KXqYQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b62a164f-714a-4679-711b-08dad415c85b X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:04.9541 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kS5Wpc5s6X4RKXDwKEZ3DcO3lMjG7pQ4amWqULAqvMIbaG+TF91DhqD9uPNsz1FuuMNbDHdwOEfBxPChOwL0xg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Current code always maps the IO-APIC as shared (decrypted) in a confidential VM. But Hyper-V guest VMs on AMD SEV-SNP with vTOM enabled use a paravisor running in VMPL0 to emulate the IO-APIC. In such a case, the IO-APIC must be accessed as private (encrypted). Fix this by gating the IO-APIC decrypted mapping on a new cc_platform_has() attribute that a subsequent patch in the series will set only for guests using vTOM. Signed-off-by: Michael Kelley Reviewed-by: Wei Liu Reviewed-by: Kuppuswamy Sathyanarayanan --- arch/x86/kernel/apic/io_apic.c | 3 ++- include/linux/cc_platform.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index a868b76..2b70e2e 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -2686,7 +2686,8 @@ static void io_apic_set_fixmap(enum fixed_addresses idx, phys_addr_t phys) * Ensure fixmaps for IOAPIC MMIO respect memory encryption pgprot * bits, just like normal ioremap(): */ - flags = pgprot_decrypted(flags); + if (!cc_platform_has(CC_ATTR_ACCESS_IOAPIC_ENCRYPTED)) + flags = pgprot_decrypted(flags); __set_fixmap(idx, phys, flags); } diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index cb0d6cd..7b63a7d 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -90,6 +90,18 @@ enum cc_attr { * Examples include TDX Guest. */ CC_ATTR_HOTPLUG_DISABLED, + + /** + * @CC_ATTR_ACCESS_IOAPIC_ENCRYPTED: Guest VM IO-APIC is encrypted + * + * The platform/OS is running as a guest/virtual machine with + * an IO-APIC that is emulated by a paravisor running in the + * guest VM context. As such, the IO-APIC is accessed in the + * encrypted portion of the guest physical address space. + * + * Examples include Hyper-V SEV-SNP guests using vTOM. + */ + CC_ATTR_ACCESS_IOAPIC_ENCRYPTED, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM From patchwork Fri Dec 2 03:30:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73ABFC4332F for ; Fri, 2 Dec 2022 03:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232178AbiLBDcu (ORCPT ); Thu, 1 Dec 2022 22:32:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbiLBDcd (ORCPT ); Thu, 1 Dec 2022 22:32:33 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021020.outbound.protection.outlook.com [40.93.199.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2D5ADA208; Thu, 1 Dec 2022 19:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EkUuYKAPTuLoq2Ak/ssOO4P2DvqhZRdmTVpsFRnAG3d2QjxmbZX03OxOIEBbJ+4fMwaEAmTtft86bS7CbFnY8aWjcJqsxfNED1q+M1fINLJLj7GlJeQXpV09yXq8N3j1aUexmrEW2YagDj2mk+7JdMqrD9dSsw07onjUQxdL0u0GmS4uxwxLTZFye6YsMLJmXAm3xXhzaHfw69A0iBEzm/GyzttxOtYRcMlTD8CH1c4EAiPVsBqWoNsBwF0m2YE0ni2hMqUIIMX3aEBScPsHoY/IN1fSOSzqQJnr/v28c0Pg1gBZu6zRa7aPHM2t2pUE3aJ1JByGqH9FDMTK5aHumg== 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=My+3F4xeoCZ4C3uLqj81e5Dg1XL4CiWYfO/yE8xDujE=; b=DD/Qmda2+SbPSf4T8WBpXGwmxgnskmT4Rjy6skx/Ny7qk00Wk6CYYiCxaPbSUAqji0nvtOeoNkmRESrXliQBhzkSwKNbzfSqLcTejccsBLqvjsj5pxYoBFWB9tUT4is3iZ7QROfLUNotMtDvXDbgVyra+yk7pw6rYSksdI9eKVNFW8LvVjtUpvSsQ/OlUxlEpHYdLC3fgSu0+pNYbNNRK4xWn8VTErNlmmPg1hbkYXXhJgc6dvzNKIUAcSLTJyeGbj0ndcdjU3X3/ds9IumuZofX4JZnGFA2T2GHy0Dq2fEWkP5kgQHd2sXN3tD/8YoGwIGuvAI3xM4exF3JMZFacw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=My+3F4xeoCZ4C3uLqj81e5Dg1XL4CiWYfO/yE8xDujE=; b=bZ1F1mUiLIdzulNSaVVD8gvuxzngphyUqS5gZN4QKk0ElC67exuUrSBqB9ZspHtJlcfhhnJB8udY3gt6A8nN8vqIb23q8kYDvaB6Gj3ymjN+VTKY/z7wxGVtHz7+rCkqS2R3yDtwd6iw+GMA06lf5FrJR6w6EvXHE95u2aEnuio= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:07 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:07 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 02/13] x86/hyperv: Reorder code in prep for subsequent patch Date: Thu, 1 Dec 2022 19:30:20 -0800 Message-Id: <1669951831-4180-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: 05cf62b7-47ea-4b4d-390c-08dad415c9a7 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VsDVGJxIZsDzgbUvCed+nL94IByovZKi2QE4ZDsYVKbrRPVt7tlucaQ8Yy33pREcoZIEvhwk8YWvknFIuRRoT7VrsSO+mcZDVhqdvUVTw4nm9xw3BZk+KAE4fJHV1JTuKgBBGIWllRFnYfHXl6kU8ohjTRrx5sp1duLqBBGKrldMPDHBP3s0Rj6iulNsu+pvc+BuvGvOf4zMvA8rnoJsAhallruWOGjqcHlxMRYbtNdu4GgL53VG9/f4vtZCYsN1JhmYujt6wyqL2/ay+z6B5g73RapZQIdFwOoF8f7q/50U2ItYO5yyBT3Cffn46YtgoPyYHEF/LDsKJSbgnWXEoZf1iHZeiuPOpvZPVkiQVn+TOc280I5nMs9VPgN4hhK53ptz0WkxqimfZzCdX0KtpGxJlCiFqjwEbS00hWu4wkhsWgDuZ0NbZqVtZ3nIkO6QV/2qGzTPPgGjpV/k8912+esPPlNDrL1g13ZzmN9Mt5YKzM+fAB5Lc0fwFTtrF099Hwc5rIwC0KctPhIKJOyTvyR74fzGRs7eTJbN3z3BuqILVQX7AA9TJTEyuE9R/XRqqky08g9GSW9zBgxMoc8VxcgIeE4HLB7ArdgKznGoQ+ZtJwtj6blx4rFTc1RgdIlpsrBaU0+qdlJkrgB0ncUiUWdr5vf159y4bIWfGF2AcJKJ0Iz6+OJjFPENAEgaZ6hmgNrR52KoCgQ1dWJ+4hrRTgc94shoAUxXexd2bXQAommfj1sC+okkLfMeFeIRHhaZ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(6666004)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3QzDZycjFG0ZjOmhnB7P3sG1vI046PZBw6dvujls9hMVwHb3a28upmVw9LrbLhbrNB4yW+s4/ax1QmxWWv9iR0rn1/Eo0BW1vbYRtQ73i1me4SmgQsg1WruBzKVyDgMExnJ7Dv90w2DvO3uzLGzFi3J7l51ZLQCeGhOpl+xscParIILrjzJApjtUif9Q4eGBtFysIbyEJsrzXMYVyopMkaekNjfBe+ZjNa1u19KiyI5cLb0amW6D0Ssp08+/d3YWI1PJKowGrxuFqCV4x3/RAiir2SZblAw4aeiOo9Iqze9V7FVNqUg2+Gq5tsPQZDSsDwg/Vl16+xhRoB3p2PCFB99bjmbsq/EqGpMco9ek47ly/xwG6tSoHh9cqk2Pn4IhwKvpAW3SbBOMH3yQUQcaXZLIHQ+C2OZ2IkNUK4fceNhm0ej4l3astpln3WO09tyf50XVL2+jLQjayQi9nGT5Z2cezf+YgtUIWtSReGcta89E2Uq/a2xDg9ERidBwiV3qAc3oRgOAV9WV6UQ3DB10Y91wjnWex+syxPDCH88XafeNvV5Qf+BKnm/ofgO7HnoYqsUZfzFdpoFansRmw7oELJLF1U1ld9dUOrrZmn8GygwK0mjKUSKX0i4NiZyfd/efgbaor1njaCUwFp/OoboWmuafaDz2H/eXXppuDjaZuxw57Ut1PnDsDy6TCdb2Fh8rtUynI8JrvIVhNacQdwpRF+TF6PDqeT2BVCS4zVUd31WLIBzdHSOoluIKF0jhXS1g1vmn2DpnqZxYIMGvR/phTuxN+bSORQuEaWQzLXIEjEtlozWpdaJXf48XybXDlkO/YoMYujjoZlalB56vYB7RzGWNb7Mrm4oycupA5wxhpuVaSVCR/eApJdiINmB8NDdBe8WZ/aXjx8V1HYdR30R2PpISYwtlAvV1h5e9/4sChymSamrxdNQFZel4n8GK+ZGVBk3WboDXL2nRpuGaya/uBDnxttNVbWS1PFuOBsQ64CaVQKI2QfTGMBuIPMb4z/obrWmtnkFnpEwff50dtNSfG2x58gAVteUdbBveVMAGdsCB40iH/S09sHj3tzLsSwp/3eCdVT5y1UAoQhFVPizBpval4tOMnu4ddqxTyYPjtaSXoQha+JRknvqaRzqX0+YALquzQE5ITChhcZ7nuVXNUbQUjKTLYz8f/cyFhaw7ulHtSAiJwzcf+hM4kRjdY09fkqCT2dS3TI03JHuNx2XDq6RAR0hMLYcPrrOiasZjMz0c1QJnQ1TxzmrXfku+fMcVYVGQ4ye/yhKPF+FQ7bzJJ+EYou6kueSgNzd9bDyYw7MhUwp/S4bWMRlaSIuQmNX7BzyQs7bN9Nu6cPoOHv7Uderc1cjybzG9Fe8PhV805mBBNfvGtN9e/xaPEozjf+WXPeAq3asJK5R+LjVySNehaTCf3dcxp/syaQN0wrtjVyxPmaBH32IcapmdBZTTsxYSGv2cPGd4ZLDW//D3bYcEEZ1YeKDsRYeOkCICqRSSD8RmZk0+U7virEQHorvB51MGz1IssZW3Zj/BucP079Ksjz0LZ3R4roVNZyp0ED/fbWOIH8h8dcoj1cJcbXjWx5gKrcpaTHWrJP7HgEqt3AZ8aw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05cf62b7-47ea-4b4d-390c-08dad415c9a7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:07.1752 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: S82k+ZnyTB7SQXdiFPaNc6wA0dRJRtNoF2OvlbiJBQqUGfrX6zh+jbYpsp3wTdKWqr3WokklhGLnsYGviBpGpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Reorder some code as preparation for a subsequent patch. No functional change. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 68 +++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 1dbcbd9..f33c67e 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -235,40 +235,6 @@ void hv_ghcb_msr_read(u64 msr, u64 *value) EXPORT_SYMBOL_GPL(hv_ghcb_msr_read); #endif -enum hv_isolation_type hv_get_isolation_type(void) -{ - if (!(ms_hyperv.priv_high & HV_ISOLATION)) - return HV_ISOLATION_TYPE_NONE; - return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b); -} -EXPORT_SYMBOL_GPL(hv_get_isolation_type); - -/* - * hv_is_isolation_supported - Check system runs in the Hyper-V - * isolation VM. - */ -bool hv_is_isolation_supported(void) -{ - if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) - return false; - - if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) - return false; - - return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE; -} - -DEFINE_STATIC_KEY_FALSE(isolation_type_snp); - -/* - * hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based - * isolation VM. - */ -bool hv_isolation_type_snp(void) -{ - return static_branch_unlikely(&isolation_type_snp); -} - /* * hv_mark_gpa_visibility - Set pages visible to host via hvcall. * @@ -387,3 +353,37 @@ void hv_unmap_memory(void *addr) { vunmap(addr); } + +enum hv_isolation_type hv_get_isolation_type(void) +{ + if (!(ms_hyperv.priv_high & HV_ISOLATION)) + return HV_ISOLATION_TYPE_NONE; + return FIELD_GET(HV_ISOLATION_TYPE, ms_hyperv.isolation_config_b); +} +EXPORT_SYMBOL_GPL(hv_get_isolation_type); + +/* + * hv_is_isolation_supported - Check system runs in the Hyper-V + * isolation VM. + */ +bool hv_is_isolation_supported(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_HYPERVISOR)) + return false; + + if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) + return false; + + return hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE; +} + +DEFINE_STATIC_KEY_FALSE(isolation_type_snp); + +/* + * hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based + * isolation VM. + */ +bool hv_isolation_type_snp(void) +{ + return static_branch_unlikely(&isolation_type_snp); +} From patchwork Fri Dec 2 03:30:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49BF5C4332F for ; Fri, 2 Dec 2022 03:33:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbiLBDdA (ORCPT ); Thu, 1 Dec 2022 22:33:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232118AbiLBDce (ORCPT ); Thu, 1 Dec 2022 22:32:34 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021020.outbound.protection.outlook.com [40.93.199.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB86CDA21B; Thu, 1 Dec 2022 19:32:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eup+UgVEn5ii3ebb1/kzyPOGNIIkCvJ8QYGKUyr13fbQVDP73CeQGKuLaRP2luWnJivdyrLTHNbO1wxjb4j8sKOmIVJGMsx4+OBJW9kK+O9wadiDi8LoRHoVxsJlkco2q6a8NHHcWFBEMsTMvsC7g++aLe5J6cPn6dfSKdmq7wRJuC/3ZpBGXVBpFd0L8hNPkhbS10C0QUY6eRsR8BCOJmhTMVifewXXzGJxkgHLfKnDm/exJ73vQ3ugkRlidsAHxQPlEuKMQqGztOpurpVnqCarxybchpl158ml8LIJSry9RKd+qv6vS/k1kdU+snPMSgmfJGc1u0KCIe6nLP6wLw== 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=DPzeS3vuc5jrpXr50Jyf5rW/rJkXmca3k54eyBANkUc=; b=ItNKaBljjceQYXbdfcraEzpn8sCJDeOGtGe0wPdH8izkKClyRvb5Sc4/7zvl1sGifJConukCYKxwo4ApqOrM1RsnI2mY76NgDuAYL1MCo92NQupShhZ4OWUbK/7M/EDA17vak1FNQl2tem6TuJQufMdayUJwEConrKF7vFpFe3UZEw3QE8imQl5LBqxgP4bUrP/ik/TGFGEw2PFARxj/UjBXo+4749MAzVR4JKYYLT1ZI7/KzDHkILlAS0jDv1oPCmxcIN+SnIsF48J7CuRKDxpBXUWxvGCOEoHdIkReA+x0xUIAaVZHZ23SgxiGN95hH1EuKXxg2iKFzFvnWc+6PA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DPzeS3vuc5jrpXr50Jyf5rW/rJkXmca3k54eyBANkUc=; b=YUw5vkBcWDALOJK4Muldv7vvpEK8vwBgCUeMZZz7f2ynVzsCCa0Br4uV63gP/fvH8YKodI8tUw1uj1zcjAobUGQjov7mq1Qz6emq2u3GKCq4meDdy6J73X8Vi0pe944rVP0vQNPHVu+/4+Prqjdtx7sQAhQXNLRhtsqLnIakPvM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:09 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:09 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 03/13] Drivers: hv: Explicitly request decrypted in vmap_pfn() calls Date: Thu, 1 Dec 2022 19:30:21 -0800 Message-Id: <1669951831-4180-4-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: e6bf6661-c1ee-413b-67d3-08dad415caf7 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A8LVF7SjF2oBU285AIvLRLOewZ+1PRTkolYBtH/b239WSUfqH7kSg1Nv93Kr3upWoeWpDg/S0RyJDUVyILaGLnOhfOSJAYvjWCuRukoIFKRlovaATK0pSuJWAmd42xCqhcKPThTNrlzoOKJTRbx9pOmrOetdTTCIpvVDOmRU+O0ryDXgToyphpLX92cZ+goucV4bcCXrkcXOGAK70K5oLfN/5DdAHVuM0Bm/AG86kAwzbRdhlZL32F0aEwRO/PfnMmttOHzWvMeuS7sgnQUIrwSdHT/k25qOVKtjrgRfrrdfKts0AsAhP0sKlUiLedUzY9fDc6NrUFJ9gpEfIUKtZ7C5MSvXxN7mBdy1NWvkAHH3RrA9ZckgUVBwK0Z0L1Y0n/KR2R0AQs/rBTN1hQtvy8YUZhrMhJ8YzYmqAVuAV04RCTHNelOxvwN5Gex6DNbZOY4X1qUqbm3J8a9Vz/8nAG7HjwCuQCzZJBEh682Ykjq4Yf69a/v6jtZfTiMhKF8PEP5tg7QHgrJVLwb0iJWAf697zkyW4O7+r8ftWRg8Cerv1H/SbTpjAGZiNfDvOVp5LodyygbTdeZD+Y7pnLf7XQaiKKYoEQUl3hqAsyHmjmnP/v/urlKQ9NuE/tQeyqPYMvPKMFO3WqxhDECfOi9bSBCvGSgYlCJGnH8IS7O2zwaMPnKfmMu08RFRYPkMH8VIO+uLHqbemg7PnSCL6tiEgx5zqo8WUXxXO0UrEsU5Vsoz8dVJrj+ajK0ZHq5S5ptN X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(6666004)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BHxpQDi1MeWxxnA4r5KnOdRMnXDy48AnUoUarlXTajVcq8ngIEQVgcmXSNPiFdWzvP/e4gUm4mQ2sTpKjf7chjGt3/kBSI88KLh3ldVi9Yhc88NdhgZ6nGcdog/M5KRR7zcpnF/hNEP5AD3uhYXoVQOGVNkWG3EhXV9ERVydxEzeo02R4vefw44bqsH9t1qE+PXSxd1JD9nUxGiNLa+oEMoPM9V+JplGvotojaqW1eJKNVzv2Wm2KxoHD0NOHYL5D3y33wZFbVIuD/huylrFNtcEvCWwjSV5HmXLz/UTDAvP96D9tux4XzNri2hkNzZ10uuxAZjRnOXUlRMhvUaGbvGfmqPrxh+6Kg6ADbToaRP8+C5pwOUyeGO6hpXz2N1quh7JngRxcksZyqo119wR/E/RpssauZiOpcmvbW96hMRDVrww7Xw8gCB7j493W/gsb8Nz6MNox1u9l/r06bBHU32VF0nmOvt5Av8sG7Zdz2z6ftz6CsoFfdmh9A2Rs8A+JNgSzGTS0m8EAIh/2T7d8GPmSi6MY3GT0aHCjH9MwLL1Is0o/E1YNfxZLZP9USqXOEF9XzS1oTd4x+TDyqMYuusuxl1b8LZ+TnX4gxvRopiDmtmR3XVkc0bqQlCUgpncb3RgHEZ/ipXaA4ylG1rlCAhgyj7C4bniHSD/qYUdKNCaPSNu/tiZb1NwX+2D8zJ4DB7aAPp5Faessr4ZtrI7keojKKYI10BjMWybJb39Bi0VfOQGo5aFtn1iKMlKwBG/r7edETBlIU1fvFZlH3g2YfJim27BVtA3nJ9zxRz3MwmXwjZOI78kLkTtSNsGbZKVgnZb525PK2IPgXJl8krrMt6BnB3fEihuGwLyhE58yMqiCa2PmUdy7xhVdFPElBi4h9qohqIShVGN0fFkE3PqqNuGBM/uFtnOVqOEabhlRsCauFuTu2t56ETBIsRSxVZPMmIR53XId34hVFXcy0Bg7eIdhqhRSAA+0WyKyt1oaFRZzJWKuGsyYI3aq07DjltYxHbCvonJUrz0ULGXhvNWjUox650qtm1Rc0WXQC9aunkg+pMdKM4MGxpu+3Rl4azseyRjBdMgN5TWnfbXnXbDH9qzd4bqWpR6uNzWyr126WfbGmNDfTRCojavpbimHaj3bklQZ/Pp7cL9zpvNUcVf2SJnxuyaD2lmOSjPKWyueAdAOtGxLjHfhV1K8oqtRcU/0oG2ZyxMs5ygY0NSuQtUrbJCKZVqxtJRHuppP+f3UdJ+5Adshmp3BLrTcIYF+b7IBFsW94FJqKiFKSHpRKaVEmIuklSQsmutKbPP2d46RAKzjpa4lhOQr3tsjNkcN0aJZvLoQR+UNrOle2aZiolMwaXqe8zoUEMk7uFpMWP75vyUScKwkeHj0E+BcfRGNuDFmO0WozikUYb6RR2YkpxRHafssfHHRZaevypBATX1tS+uyNCN2lDXXfes75P/lMGk8JE+2QQGh8QoCDXdqR464kwsiGUqhlikiBgLhSFWgVb3a64L9qWP4DbfYOlv3ifM29XQ9oDh0MQTkhqHMez/26XNXIfxOtQ3QzhVs417k7rO2ECSfNAO6IsRhm1gNb4tpd9up6MIPm/MpBJbym5FXg== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6bf6661-c1ee-413b-67d3-08dad415caf7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:09.3772 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Bq/CTvNjQr3KyMXDGsIYBapFjYbmeXQakSTbsmehANQ2SjkyHM7/Zxnp3xpKAwy2yzIMJLkoFksYiSZHHrVLLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation for a subsequent patch, update vmap_pfn() calls to explicitly request that the mapping be for decrypted access to the memory. There's no change in functionality since the PFNs passed to vmap_pfn() are above the shared_gpa_boundary, implicitly producing a decrypted mapping. But explicitly requesting decrypted allows the code to work before and after a subsequent patch that will cause vmap_pfn() to mask the PFNs to being below the shared_gpa_boundary. While another subsesquent patch removes the vmap_pfn() calls entirely, this temporary tweak avoids the need for a large patch that makes all the changes at once. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 2 +- drivers/hv/ring_buffer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index f33c67e..e8be4c2 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -343,7 +343,7 @@ void *hv_map_memory(void *addr, unsigned long size) pfns[i] = vmalloc_to_pfn(addr + i * PAGE_SIZE) + (ms_hyperv.shared_gpa_boundary >> PAGE_SHIFT); - vaddr = vmap_pfn(pfns, size / PAGE_SIZE, PAGE_KERNEL_IO); + vaddr = vmap_pfn(pfns, size / PAGE_SIZE, pgprot_decrypted(PAGE_KERNEL_NOENC)); kfree(pfns); return vaddr; diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index c6692fd..57667b29 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -211,7 +211,7 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, ring_info->ring_buffer = (struct hv_ring_buffer *) vmap_pfn(pfns_wraparound, page_cnt * 2 - 1, - PAGE_KERNEL); + pgprot_decrypted(PAGE_KERNEL_NOENC)); kfree(pfns_wraparound); if (!ring_info->ring_buffer) From patchwork Fri Dec 2 03:30:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F8F0C47088 for ; Fri, 2 Dec 2022 03:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232263AbiLBDdS (ORCPT ); Thu, 1 Dec 2022 22:33:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232159AbiLBDcr (ORCPT ); Thu, 1 Dec 2022 22:32:47 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021020.outbound.protection.outlook.com [40.93.199.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81C77DA22E; Thu, 1 Dec 2022 19:32:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IHPPiR9yhrlvuG2SemGfchRIGdSeP4xATNyO5k4byPtXGOEd3/yYWDUh031sRn0mpFWoWSyEsNj+4AbTw2F9VebIUe15GKt9nUpXYhQ4WhSV4OJL32Oy4Q12FcJNnysycOxq1quZGbT8n/Wv0DTVPcoIaABp4chI6+zZaREp8mqZ18VGS2KThCIQKeimQ7Ba+SxBU+fPC87SDraRaE3xT6kHQ8Qb6Fxg0HzdA5Q0Ffo3jDo6WARFnQOOd7G2qn5puom/4suQ/q/FFQTXUbfDB8W6nVunTrW9U7v2xJl3IdkJG1NXID8naMwXxDUVvKFZ1hzF4cBX1afmPIzUdKCo3A== 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=1MmvKlC2N8d9H1KlID4hNY8Dgzjf+zin3uI5uHOTsQU=; b=kH0khYMziJzOxnFS5067QsBOM5fDUdm6R+EnG/C8X0wiI/kjbEq5cz8kVGr+5ionFLESXf6ic1OgNVIgLh85WvH4gpk4iXeYZClypHTBKBmKMrk1sRKV2/hdjdirDzaGepjayHcFQa2bHnqnBXJuBYF0tIoQjfcS/38nZPSLwSNAQLcJuihCpC9PVFgf0zrRycenHcVo+y0ElYe8pvbNyKoS1MElamteomwRlvWlRfrvDWOETnjZWTwcb6kXGc1yJpjYXL25WD/68VSHkmauUvF5x1XPA9oQgdzRxBzoVzYEzNY1WdtvXTkF1mPjhZMZXRRxSS7zss7tdCgK96BPUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1MmvKlC2N8d9H1KlID4hNY8Dgzjf+zin3uI5uHOTsQU=; b=WE8+khlUWXZ+dD8jLnROP4xuOBFvEmb4B+dJUyIZf2KY0G0NKvF6inOTvXfZkuBIAZmcsAxEDv1lmXFVcuVRZodjAA9SVTFldwmHZ+E8tFlSP/YMPLs2cWs8Jzsyy0qt9xym81i/AgA7DEnXXjfw8ZfySF8ViP8m7YtLTKq9Lqo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:11 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:11 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 04/13] x86/mm: Handle decryption/re-encryption of bss_decrypted consistently Date: Thu, 1 Dec 2022 19:30:22 -0800 Message-Id: <1669951831-4180-5-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: 3fba225d-e669-4df1-ba9e-08dad415cc47 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R7Ciea5H4LCbtcpCC61yl7MzY/fg+EUB74pXSyIbrABRofgOa2/MUMRA/SDPqNzJDq6hneE78hQnVKDs2tTk5HLoc3jLur/rv9/uQdv0sog+CHFu9Oq4Thp383oNo4ycXuGC394/87LS02a9h/1JPUTMHGcs6I0XCHiL7e0Ou0y0HgcB2Dv/KTdpf+yRO7HAuUM5amtN/WuLZ46BuOL1PtLc74RPLanY0f8IVdRV3YC3AhNcMcntjQdm1YnyAdEvHOwYI3huVlou07JdFIDWuhTy2+Hv0We/cQ2Eyf4LGTWyDB8MXgViqMyfBOJe6vADE8Yaphl3G+1NAAImpew26y9AsuK4GRGuXkTJbUvUFUPdyKIWuDCnQ8dZSG6IGjzYL/bqeE6YEIrcmN0T3dEkMU5NuD9HE/aq9LS9CL3Y4xQsYefRP0XYGJhI65Pu1KNLmN5libUhOn9AEnDntMr+8CFNVcZxVK7NOqD5EwFDXLbLYOWCRGKzDP+5y/UCYBmtaVAzX4G8bIRz3a+ekifIQp6LxTkLMt9qfhhjLZUctGNx1ER3HizDTwaGSJDbbiVQ7O6LMXJD3Uc1Ja/Z/wOerZDXveSBVsJs1H1G8IHMKZ71xcq9EFBi3e2RS/p8FZkwlcztT1Q7uYkD7JoYkfhBUJ3nF2f6elGl5u8BY53WWtg0nGlyiKPVLB/7CLKoBPZXAYHrkuzuSZl4Fp3maELldVAWx9BXzQirQ5EBNnIweipLYY/zukv7RCXk5kW+P/tq X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(6666004)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pAorPs2drsSUgfXNCQHEjXrKgvYn8dlKqzxJxiyVYo+u60UGGGs339KWd/b0IKe6BVEdh5aWhNdemaV+bwyV+ry4sJuSOj9FzItAObdOXjKGjvMtIbfh0j+ML+NByXnFG2ZWtYvgi7ugcPC6x4Nb0afDwxhwbnEr2AhhncK6r/9Bn3S64sV3jmG7FoFnh7pI3Exds2l0LqkdSh2MB0cZNz+8x5Yyek6BLrKICY0DlsHzpzeZ9za/Skd7E4M/MwMfy6HoCkbKMQULW+lJ8oX2YGopnKIDrN+D/wi5zwKgMjPxZWXpWZBmdzIqxh3c0+f8e+TV/DUuV274zORDR5fF+Pw14rA8t7NlIlbobEISME9ptdb99qFl/UYkHM8lvZV7fxYQAA//zDzHgVrRPHRURfeAxAmLqj2AyJWTxG5pqUHBQsMWs2K7We53ywPholxQDkryA/mhTPvHuKUZFdve1y1foOiBb/xEhZyRRZBfeh86hJd3ybkJnSSW18Qg91jonGGt5F33Vf3E+rIhsgiUWfvDbjAVAi6w0l6v/mM1BPUaqpByg4w1eg300LzC4zf7jOnJCUUuz7uca5/sg0FSYrsIJH3m7AS/zTMW71oZn4kh0m1reaBxKB/B3+oT9AbVQA4vJpcapVbxemwvaibcWFpQkWDcbezR0rTANm1X2rEAHdE4BsQcB2C3ebVTqM1BANED8HcHz7gATf00nRm3Wh8FKwbnZ8KrizPIPHgi2biCgHB1EsnxRtq+tERVezJP2ia7ufnk7ZDNOXJO0+uWbUhgZLYJyPUbH/iGpGrkSnRRxA2evAUNw8e4MZAvaIgTbqpNDgT5B3acm8IlPswg/uvP+W87gIwgIGp6bAGoDkT7PdlcaeAw9r9Ww9CfBagrMRJqLgWk+INzS6xzSJ1v3nayaqjtSjzYJWtz0lzr1mhdLE9Z9+nmW2elgsCeBZQaHYrD36kHca216L9ZtWwOk2EHXSujFW5SsOp8s9GpXsRAEnbWCHbsDdjMgvWWHLx+aY7v1CuKLr1Ncmy6JHUq7ZlX96/05kLkyZtUJgYCrYjBbkTMdLSolayhkllUQkQRBwcDZ/sFaWk1FCzSYLv+Z+0VaPFpvQJd9fOpnLV3QfWpl7JEN68PeOdaL37ck4Wwmj5DSTwTakeKgX3nUbD1ojGRzejrdb9J8qZ7N1qlR3iXfSgJIoj/vZi1tMd9Nbn67mewWWGMO+IusgkTt3qFREN/MhD0kaYQunvnIMzrDmiS5p3UB6Koe6SihtAdrn9ic7rMqe1jmRlyrmaogvFkT9DSdr7fWw2WJbGGmUq2dRrxiOo+/oZpNmUq3Q9Hbzuk0m2UuRFm15RUD/afqwsCAEUy9fyUZvsOyXCjlXLXy/hKVQX1ZYZ/nDRs0gzk5AAFHmF286lEmgsnh0SBVyN4Uty2qH3pqSYoqOyvA0IgWrvNAD9yTY5MyCjoczovSJz1eO09XljVTJNMFNl8UVB4/5CbNuLNGEKHOBaWp6ipgM4E29Dg1/KBAAc4XXYYA3AJ6UOAbGQ8ooOpkbL/oDA8ln1mzsIIlw9d1pJ46FmoLuIimyyQgO8jsYAc1xhdT571uip2jDOXGn8LS8oQlkRsXQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fba225d-e669-4df1-ba9e-08dad415cc47 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:11.5500 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CPjsSO7WfKi091HVyH1+4c88yUJmywQ+R45n53SbDsdxTp6ZnhLpFDvgOoIQVnVOEi2vzJg/IJt3lUxRRbgexg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Current code in sme_postprocess_startup() decrypts the bss_decrypted section when sme_me_mask is non-zero. But code in mem_encrypt_free_decrypted_mem() re-encrypts the unused portion based on CC_ATTR_MEM_ENCRYPT. In a Hyper-V guest VM using vTOM, these conditions are not equivalent as sme_me_mask is always zero when using vTOM. Consequently, mem_encrypt_free_decrypted_mem() attempts to re-encrypt memory that was never decrypted. Fix this in mem_encrypt_free_decrypted_mem() by conditioning the re-encryption on the same test for non-zero sme_me_mask. Hyper-V guests using vTOM don't need the bss_decrypted section to be decrypted, so skipping the decryption/re-encryption doesn't cause a problem. Fixes: e9d1d2bb75b2 ("treewide: Replace the use of mem_encrypt_active() with cc_platform_has()") Signed-off-by: Michael Kelley Reviewed-by: Tom Lendacky --- arch/x86/mm/mem_encrypt_amd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 9c4d8db..e0b51c0 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -513,10 +513,14 @@ void __init mem_encrypt_free_decrypted_mem(void) npages = (vaddr_end - vaddr) >> PAGE_SHIFT; /* - * The unused memory range was mapped decrypted, change the encryption - * attribute from decrypted to encrypted before freeing it. + * If the unused memory range was mapped decrypted, change the encryption + * attribute from decrypted to encrypted before freeing it. Base the + * re-encryption on the same condition used for the decryption in + * sme_postprocess_startup(). Higher level abstractions, such as + * CC_ATTR_MEM_ENCRYPT, aren't necessarily equivalent in a Hyper-V VM + * using vTOM, where sme_me_mask is always zero. */ - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { + if (sme_me_mask) { r = set_memory_encrypted(vaddr, npages); if (r) { pr_warn("failed to free unused decrypted pages\n"); From patchwork Fri Dec 2 03:30:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67B8DC4321E for ; Fri, 2 Dec 2022 03:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232111AbiLBDdV (ORCPT ); Thu, 1 Dec 2022 22:33:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232185AbiLBDc4 (ORCPT ); Thu, 1 Dec 2022 22:32:56 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021023.outbound.protection.outlook.com [40.93.199.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81EDEDA227; Thu, 1 Dec 2022 19:32:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gxqZoQQddbxno1wEbDpgd0dZK5gzQxAoYq+mDiLwLPHcBjZSWTYxR2LL1KWrunSV9LlBGvijZxuDCCrDhtSCvckPg88ir6kaibEaZMg1UhfO1jeeWSUY7SYgQOsSWyXcRLWpqBnrWmIYUKLGFcMnW1J8PxkWodmW3Z6rdxf0Nw4VTAequQxirUkHXO3bBZ21qNnjem6tBrxdDnd5IKqXOll9cS9l6BwK1aa9pyif9dMI/oIkQ6J0a1iX9jA9olWQUR0dlVWV8zHK7WanQ6k3ktPIsqimPcvwr7y6HsxK61cCQdUNHjV4f6ySE7R1kj5cyCcf6cMeNcOWS6S6TijABQ== 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=VezcU7/usf/P2gz28QoctXZiJW9x05+beUA8cfnfEUE=; b=jH+5NIB0+GWK9eTSrhlQtxY+SyrBj4yeQ0Zj6qISAS0rmsn0IFWyoIu/UpEwrHpTyxSzLwDikmAAXeZXj2De3XHc/Yotp2Ej22/UmfzWqojHZwcB0kKmB7V0nVSwHyVgNrykwj/FynTut3ylnV6hRQSS7BpJHRJ77ErrI4sXGTobGtGUsnZxoxDzcDu0Q7OjOhu24EQBEH42KhpkQRrAtkFgza5i+PRICDKf3eK4m6PLpSMiApJwiBOQK3RVYXHtliDZkhHkzw6LZcMWqS9sG64NnZXZWCcOtrDULnLyW4tlImpiXUV1SLs/Y03f86AaJuP0PoIYS8gzWLNHvAUlPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VezcU7/usf/P2gz28QoctXZiJW9x05+beUA8cfnfEUE=; b=TyPKXxG7FNxRY0XIJKm7Kxwl2puO0b5WRJTVk4XWl8tupcPRmkpbrYcX75IZViIOemi0E0W4/12vYIXhAuJdiUhTTpN9O5cxIhReG/LcEaa7mH1+HLd7ziediybLNZBRniuyXI7ifc02BPMruUFOyYTAQHSqN+kKhKNIl07EbSE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:13 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:13 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 05/13] init: Call mem_encrypt_init() after Hyper-V hypercall init is done Date: Thu, 1 Dec 2022 19:30:23 -0800 Message-Id: <1669951831-4180-6-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b9fd4a8-525c-48cd-4eb1-08dad415cd93 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JVxET2OhyiDAEVPbyQP4isyXi6VFd+KFTzrDBWGzrsLYYlZBoR49D02Px9v9qsTqkFH7RgCXVG0AbE1vbTYoGOBvcJaWxZP4loe+vKel/JOF3bMdUKhdHlUSSJSo5WD1zY96hq1sj551oer0mIrR/6PxeYhD5No6l9A6R8yinijA7rNrb3zf7eAuWxX7RqgrjmTIMwY7BGMflqZm3vWDJTbA4iwornz9hKhgTqQbM7DnfOCIp0Mxld3Tq/BFM8YdwuYdHF+ZyO6f9kKTcNytLFdt8P5rBec8j4vG9FU0/WUKCE16M1zDUrDP4HgGCKeDha5eF1MoaOgTfb3K7BNf4cWJFp1I0IPvQiek6+uH6p7Q82dVgAuNfNLDsfZObt5C/Qr1SxgUjSPHwBu4A7m7Ff1YG3CgDie5miNHHk2dpX4g7/k8JKZ4boGbf1mixXq6FhgaBi2Gnnl8uJah7sgAeOqRBt7ld5Ad77tI1wGbyngedNyiBlVHuu+GdtlinqYTofTdWMDZ/FuSu5w8XBmPKyPZUHfPgiZS0USMcK+ssRPbGrjIuVqGMwm1GVOVITLI2rWSQBMMkybWEkLJ0936vKzFW4nv7zNunVxrVsyxP+mUTeRDRd8w4FauHFfMXmf3nJdvNTD13FNGM+99QLl0ctC7zo9f9+D722eWyuM5nRXxS5ofQt2w45PzGW+pCGqEpB50od/Hf7+dXGU6ENpM2KaxVhi9FTCKtEgfRiFQ9iE5mGmF0bZI1MzYVOJw0eYb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(6666004)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lcqtmS43Ol5ajoc5zpOaXU0mJoN15umyI1+IquMZ2QkEQNShy2jKChrdDMJdFQyw/Qjqnv93n2gIL+bm0yMOFSipJkEZP6Dg5wBC4Pi4anW0P5XjRSQJ2giQmXoSi3py6mj5TqTeLj+zLVzrlc3UogsHreFoS5bK0DUDEOtmRRxmQJ6gYGnwX6JtcmZQktnh+Spehs0C6GhFUYHRkhbTZSdHGAnyYFXkUvgu2VEBN6uJHjhWhLhhcjsI6ZliuHiLBaaLFaZRIN3Q8GkvQEwlkjEwkai2RsEwuaR93YmKCBOaMqvuNaAkRPManOqv6UUoSgeYK1sfQ5ZHrSttGe4mYIHrOM3GwzsezRiv9kNU+uSgbMaPihgn3o3jYJX3jHXVYqNh2erkwX3oWHlr+ySUhqEVyTmY6e8Ex/NcJ3ShbkILHDqB0t7zniS2yzqEq/NC8UnPqeEYteSyKB9gbBYjRd2UIfbZ4m/Cg2U7L/WnsgIWOjJOpFxRzMw0M9IIjkD48RZfSs9DiuDVsdAsORyO8JVX1YisrqS/iOC6ktmbRK/QMtXH+IcR/9gQirM0YzkCDowFiLLTVLsWWoQnKAsurFYWaQct1BdTK4pnUWS3Tw9IpheNaxpF8mHXji0VNPdrxIyowagoqKqJcvCpbvReH9wf72cBH3wucD6kLDVz5Jht8OSCr0JMHJGs9pkF7ZZt3by+EBT3bxk5TH2BpCpay8bDR3AwlhESfnEnJ8KRB7R/dj79NHkjsSUKhy+284KhsxNSjNQ7ufNlXtv1LfbxjGeTeptu4Ez39GkY7/JS5hDt2mRXdBZWD8So7R56TxAequd+Xqt3i9i4I3mtoMckC+8xgdnrABi+T2Q9XOmu9IhqCU/tUpNyLKnV8jsW1fCKXNLRfqOUqDNcAv/K+EgqbgkaYmvzAtihDK0QYXB+OUTJLJ0HvT4Wk5nuXsSZVRpxjICI+MPj1jjEj96jbhSii8Yn8y6REXX0WWZhGDyWD170/k6tXrHp26j6wAr2QPyvRnfZtx5azF7KEsY35o52lCLm2QRmuMG5HrkodSRCNw3xJxKRwP0sD7VguA9zrcvEky2rMVjBoGqJP3yP7imYYXB/UyVa24CdjcGJpkSiFSkZQbQCPrv8iZr3K48a9DsgQnzCJqndnharH1YVko9Ee7BNw9cXxhesA6dzc7LhU086OKeObGydm4J1lLYt4s+IrwU5QuiIfgyKDJ6F/N5fDlP42+3Z0hfWkl6dBFI5u4776fLYf9NJC2DORnBaYBPBj6S059L/2lGGLIf5rOiX/hoghf3N5P+ixoPNTSM8jxJpdR0WNqC4UzGXVaOoIon80W8oHQtuJaKieu6CEUn4biprEFmVvE+1Reh5m1V4M3IlXWEvIaxBJbbFaZTZZvYX24+KYYaRapdw/ZMMYiu7cjICwmswmB6PD3w4r8xPNOAKgQ7qCFHlolQlUJz+T4ID6m4cY75skGPqacBechn/IeTcOI7Nq4Oj2CyInQF7yq4LOCPq5IsDslky5GKLS9EbKETT37sC1/1n9jSUWmoutdAEkjhahqVpUnjsczA4a+ZqJTIu4RI/cnq6FDoUxH0Gc/RIAxAE16qnrZ/d8asjuw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b9fd4a8-525c-48cd-4eb1-08dad415cd93 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:13.7521 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dmLPB4x4Ax9gsQtHgdXs1REf4UegYvm8XUdOuP0hhE7z+mMNW3iHBrjq4iU8uMbJawqDh2YiN66dgL54bAO+fQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Full Hyper-V initialization, including support for hypercalls, is done as an apic_post_init callback via late_time_init(). mem_encrypt_init() needs to make hypercalls when it marks swiotlb memory as decrypted. But mem_encrypt_init() is currently called a few lines before late_time_init(), so the hypercalls don't work. Fix this by moving mem_encrypt_init() after late_time_init() and related clock initializations. The intervening initializations don't do any I/O that requires the swiotlb, so moving mem_encrypt_init() slightly later has no impact. Signed-off-by: Michael Kelley Reviewed-by: Tom Lendacky --- init/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/init/main.c b/init/main.c index e1c3911..5a7c466 100644 --- a/init/main.c +++ b/init/main.c @@ -1088,14 +1088,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) */ locking_selftest(); - /* - * This needs to be called before any devices perform DMA - * operations that might use the SWIOTLB bounce buffers. It will - * mark the bounce buffers as decrypted so that their usage will - * not cause "plain-text" data to be decrypted when accessed. - */ - mem_encrypt_init(); - #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok && page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { @@ -1112,6 +1104,17 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) late_time_init(); sched_clock_init(); calibrate_delay(); + + /* + * This needs to be called before any devices perform DMA + * operations that might use the SWIOTLB bounce buffers. It will + * mark the bounce buffers as decrypted so that their usage will + * not cause "plain-text" data to be decrypted when accessed. It + * must be called after late_time_init() so that Hyper-V x86/x64 + * hypercalls work when the SWIOTLB bounce buffers are decrypted. + */ + mem_encrypt_init(); + pid_idr_init(); anon_vma_init(); #ifdef CONFIG_X86 From patchwork Fri Dec 2 03:30:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5F8EC4332F for ; Fri, 2 Dec 2022 03:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232298AbiLBDde (ORCPT ); Thu, 1 Dec 2022 22:33:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232129AbiLBDdP (ORCPT ); Thu, 1 Dec 2022 22:33:15 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021024.outbound.protection.outlook.com [40.93.199.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7CE9DC4C1; Thu, 1 Dec 2022 19:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PvCLb0uBlLJ7YyaaqiPf6HE1y5UiDj4gXkqTwUpv6fYHgK/joUEjtQ4e5PJpAhErtuQyW1rKV3CkTo+Y7/txiO3sXbkmTHvOpaYUMeqwRkcQdsUc0T66qc68A4fS0/Fbb11gHxfqrUedrkwk2ZqRcIdDfR0KFTvJrr2MOZaonpG32fu9mDcv4tVaWw2UO4NUPGwznn9+vsW7xb8H2RkEg4LOb5yBU7rnEUKEZxlCMZ3rrMop/4bmWQEBu4z2jpToQtFhC1ZlFSheKDKHxB8NkCr24Du3nbytu63b33/grxv/7SSOKZVE4/aOnqaFgHkzlKDsxYYD6QzIHs6QhgbG0w== 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=E7OkiJ1Fod6y/3kxg51h0zwlEPqSz5o+PfX4g5FI6PU=; b=XOZsLw6qMvQKHLRd0AvjNxzI4U9yZSRwZh2B9c5wpZ5WFtoN+FM+7BPhUo+KPpI5QqwRXZnCP3wYB/Bq4JNRBPose0ylKZaGWPuTQHLK7QR6GMeDpe2auJxCYC/80Zcz6H6g8d7DpJ0TagCpkxEBlt5vbZ6745BjMib5IC59RfbCJ79eB+61DVB5GBYkNlKRbPkHNwBaCqS+3YeO+r6FG1PTa4Q+xw17FyMpN69CMEOeIfro/xW3fQYChJg1CYNNsxR90wnlBf/s7pJwJbYx390VTmpU1RpzPOPmbXrCL1hIp7fmyB2qJzRca2keXBMF7GZEXgKFXKfPUUBtih0UkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E7OkiJ1Fod6y/3kxg51h0zwlEPqSz5o+PfX4g5FI6PU=; b=LaEwiI2f7jDjIJNvH/WgGsucolY8NWUairvDDR95HQ7eJyDrPrARQ+Zj7lbiqnwk4bruItb6qpJ+r2ga40awCMAFQYbx4TezgtX9UUFIn+Hww6KHz1dRvhbs1WxS8bFwUTT+Sv7XsNCEfEA+8Pzfo4F18ofmziZY+a0l9S71HV8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:16 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:16 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 06/13] x86/hyperv: Change vTOM handling to use standard coco mechanisms Date: Thu, 1 Dec 2022 19:30:24 -0800 Message-Id: <1669951831-4180-7-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: 2dba546e-6a69-4214-db7c-08dad415cee5 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e0VBMIzt0lFG/EceTFiQUYUnFhfignci0Zfyb9MTBx1qkH/37Ajn2TFv36cXSOkgIxGhhUxqcCTpY0RgIUF3Xt/Wtmm6BGLdikAoySh7DYvdOblEut3sZRC+UC0KfldxX2f7sJRJhfyhMM4azgn5DuE/By3O/LddyO/HU2/B3JxtvEbRoLD2yy/asthbh2pfxnKhg6oWYOn3p+f7fZwjEr/HBtczclpBdELzk+73D2m7bR2DQ7MfRlTZLX1AtXc/mJpga3IpkUo5ilB5y5HNjrjJIsc2nZ/TWQDVLIYdlRV+H5ShdiwjVjqO6heirkhLre043EkFTJMRuPCCIge+lPYwaw5OwN3XCphGEyg4yOKJcA3xzghPagzBSgwkrJsYLJztUIGQwAP9r7qiF+Om9tAulaKjqcB2duztZ2bxwUmouTImVt6oDmsC49DK9vq9Hc39kIf9V1t9MeURnXsYRwArRuzS6yBj3tME7V1fPpvkvcRT0avXJwPTea1r0P/6V98GvjDNtP1IomUaObT/N9GTpl8OMYchuh9k+ZM+aPotKC1JJ0nAmqETBTM3rQD6hizwY692vBtw9DnWJNtHwUEMxWw+bMUKov88uxP3grrQUTcFfxJS4j73mVJ7SrP2dlFkNhWjjQLQsNSbHx6R5yTVKqrMsYhFh5SD113rPJSPYEQIzkY7Qc4RwyfO84LnNUKhU0G/OaB/pl8RVJX+LUTgRPsyEY8RsIEMqaEfABTnTUP6GlOWShk33pI23P9hg9KcUArbO5Fomoa7+DiEHh4w7pIz/HVy11XcAWKt4ong6kZlx9wv9UK0RP185TGEjW0s7cjfsSC1lnkr+fNa3g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(30864003)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(6666004)(107886003)(6486002)(966005)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8t++c45qXRlkjvgdh6xaDsoC5phrogepB2tcosjx0BDb/5ItLA+kW+1olToh0W6o9zZ1fxyblvuski+2RDa/UnwEbU+2HbJV0T04mppjvh4GNTKty3vLNDxjsUQ8X89dK+b2KYIfE/XB6pIF2D60IcmDhE8vruI74JEtELtN3Wihm9hmhExCpXGRco5fzKm05D0SEZeluNQ7SayL/z2P3gGGyLTdRofxIwN7HS1MaUu71O389DE6puPQWR1iW7HKFFd6jz6zI3fPdkbbY+qWgeC9JyNmuBvlrL676K8bI0/rQ3I8PgF7WyEVkHAQ4ayFQcoHTZuQpr5ACk3unZj//jEpLCcvwvgbo7sPCUPYPSCIEYp8uXWSHPz5rBkeCJ+7n0Dhm4sV+G60LJE46r19AQKCHatPEyu/UatftLYRbyIIk8ssRA96Ldr+lF2SLuNOE3kEeKR8AMZSpDfaie/PZY8axBLvQAN/bdiTI8QU7xoHEPxmu3xQNN1khW8HyavfAMMk/FbPENTqnQpDcGgpWuD8nsDK0hIw165W0NmDueoVlxkSwXlWAmpI3+M//mEkwAxDob79YdN3Np+wxszQC51tFZkvyTuylViHSlvQS0v6enMKUYpM5g2CMzGR231/zuzFAlDxPf2IlsAxqY1HJjmDqPxFykmR0EusrrQo5TXALtOdiuvOARTsfL8dbmBaO+w/K+srfOLUxtaUNE04bvM5gAZRP2SGmc/mk34ja324h4rXMbe5rQhjIdIkwt23mRCPSoRvJVyStRdf/LuaFuk/S/g9ArbW2yvwDYMFjx0TDbUNtU+RiYinOhR332bFdcK6y0EgcejthF/ZBnPaTeg+WjKuvKRDlrYS5CScqr1wGnIZa2rJfDlbL7Jr05acv0St6ChuYMqMtT/WXAHtYpDN/ZNzA21FD/BqJq2CoNiJIfefNOzEpZn8hTYganFSfcMSBRS1+x2es040KS4b4edla+/WqY27SUcp3Up5DsHVgT8+S/8IjOp/kADkfrle0K060NfTGDwepJS8F5+f3vn+v9LJIL2NsrplsDwWPgQPJfpBA0rs52KVJrDORNJeXD2cFZYczNTJjPcSaoYzosy8whfUo0aRJConGFTaUYThg3oa9Asw6Y0von13+FSgLvG4y4dDxANk3oj3+w6N7pjQ80fRs1dmdsOKn3s/78LNbeJe2sFJIxQ/5+3t0pfaV/4tXl6A8i+DJxvB0dfGQftFg/oIi458qjyGHd285UAQtjxKrGhO6/hFFoBXuMzADQvPdfOTA7qwFUlbT0RtkExyQsqQUkvZ/nc6JD2IW2jszUKg5wBqads00sHLSX3uuGlzKPp8NXEO6QkjRLW5z9zD3kRy/5CklPUXzpk/5kMtwJtjwzfPn2QFm30MPUn67jnxTKAVC5dsywGdJ7hqF24580bgV/V4CXpYZ1y8FXEsMB/lrlUWOZwAK7KnniJHTR9eNprJ+vfhcCir0mF8Un+wE6S7HhhRszEPD6SRJncI1nEAUAc/lSHFeXE7KmHXaKXALRNh2baeu7zb0+adMpfNmjkxINnFs9XnwTS3O17R/ddnXCADvBsjLyBkYtSqZR4iZWL+afECui18uV8L0Q== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dba546e-6a69-4214-db7c-08dad415cee5 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:15.9262 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: umsDaGMVAcFn1BTPi4EjRDy/l+sMW27N4f/OQYXRhKKS0ThcpP32Xj4LHWPOhe30Ic0LZfrd9IrlknspWD5grQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hyper-V guests on AMD SEV-SNP hardware have the option of using the "virtual Top Of Memory" (vTOM) feature specified by the SEV-SNP architecture. With vTOM, shared vs. private memory accesses are controlled by splitting the guest physical address space into two halves. vTOM is the dividing line where the uppermost bit of the physical address space is set; e.g., with 47 bits of guest physical address space, vTOM is 0x400000000000 (bit 46 is set). Guest physical memory is accessible at two parallel physical addresses -- one below vTOM and one above vTOM. Accesses below vTOM are private (encrypted) while accesses above vTOM are shared (decrypted). In this sense, vTOM is like the GPA.SHARED bit in Intel TDX. Support for Hyper-V guests using vTOM was added to the Linux kernel in two patch sets[1][2]. This support treats the vTOM bit as part of the physical address. For accessing shared (decrypted) memory, these patch sets create a second kernel virtual mapping that maps to physical addresses above vTOM. A better approach is to treat the vTOM bit as a protection flag, not as part of the physical address. This new approach is like the approach for the GPA.SHARED bit in Intel TDX. Rather than creating a second kernel virtual mapping, the existing mapping is updated using recently added coco mechanisms. When memory is changed between private and shared using set_memory_decrypted() and set_memory_encrypted(), the PTEs for the existing kernel mapping are changed to add or remove the vTOM bit in the guest physical address, just as with TDX. The hypercalls to change the memory status on the host side are made using the existing callback mechanism. Everything just works, with a minor tweak to map the IO-APIC to use private accesses. To accomplish the switch in approach, the following must be done in this single patch: * Update Hyper-V initialization to set the cc_mask based on vTOM and do other coco initialization. * Update physical_mask so the vTOM bit is no longer treated as part of the physical address * Remove CC_VENDOR_HYPERV and merge the associated vTOM functionality under CC_VENDOR_AMD. Update cc_mkenc() and cc_mkdec() to set/clear the vTOM bit as a protection flag. * Code already exists to make hypercalls to inform Hyper-V about pages changing between shared and private. Update this code to run as a callback from __set_memory_enc_pgtable(). * Remove the Hyper-V special case from __set_memory_enc_dec() * Remove the Hyper-V specific call to swiotlb_update_mem_attributes() since mem_encrypt_init() will now do it. [1] https://lore.kernel.org/all/20211025122116.264793-1-ltykernel@gmail.com/ [2] https://lore.kernel.org/all/20211213071407.314309-1-ltykernel@gmail.com/ Signed-off-by: Michael Kelley --- arch/x86/coco/core.c | 37 ++++++++++++++++++++-------- arch/x86/hyperv/hv_init.c | 11 --------- arch/x86/hyperv/ivm.c | 52 +++++++++++++++++++++++++++++++--------- arch/x86/include/asm/coco.h | 1 - arch/x86/include/asm/mshyperv.h | 8 ++----- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/mshyperv.c | 15 ++++++------ arch/x86/mm/pat/set_memory.c | 3 --- 8 files changed, 78 insertions(+), 50 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 49b44f8..c361c52 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -44,6 +44,24 @@ static bool intel_cc_platform_has(enum cc_attr attr) static bool amd_cc_platform_has(enum cc_attr attr) { #ifdef CONFIG_AMD_MEM_ENCRYPT + + /* + * Handle the SEV-SNP vTOM case where sme_me_mask must be zero, + * and the other levels of SME/SEV functionality, including C-bit + * based SEV-SNP, must not be enabled. + */ + if (sev_status & MSR_AMD64_SNP_VTOM_ENABLED) { + switch (attr) { + case CC_ATTR_GUEST_MEM_ENCRYPT: + case CC_ATTR_MEM_ENCRYPT: + case CC_ATTR_ACCESS_IOAPIC_ENCRYPTED: + return true; + default: + return false; + } + } + + /* Handle the C-bit case */ switch (attr) { case CC_ATTR_MEM_ENCRYPT: return sme_me_mask; @@ -76,11 +94,6 @@ static bool amd_cc_platform_has(enum cc_attr attr) #endif } -static bool hyperv_cc_platform_has(enum cc_attr attr) -{ - return attr == CC_ATTR_GUEST_MEM_ENCRYPT; -} - bool cc_platform_has(enum cc_attr attr) { switch (vendor) { @@ -88,8 +101,6 @@ bool cc_platform_has(enum cc_attr attr) return amd_cc_platform_has(attr); case CC_VENDOR_INTEL: return intel_cc_platform_has(attr); - case CC_VENDOR_HYPERV: - return hyperv_cc_platform_has(attr); default: return false; } @@ -103,11 +114,14 @@ u64 cc_mkenc(u64 val) * encryption status of the page. * * - for AMD, bit *set* means the page is encrypted - * - for Intel *clear* means encrypted. + * - for AMD with vTOM and for Intel, *clear* means encrypted */ switch (vendor) { case CC_VENDOR_AMD: - return val | cc_mask; + if (sev_status & MSR_AMD64_SNP_VTOM_ENABLED) + return val & ~cc_mask; + else + return val | cc_mask; case CC_VENDOR_INTEL: return val & ~cc_mask; default: @@ -120,7 +134,10 @@ u64 cc_mkdec(u64 val) /* See comment in cc_mkenc() */ switch (vendor) { case CC_VENDOR_AMD: - return val & ~cc_mask; + if (sev_status & MSR_AMD64_SNP_VTOM_ENABLED) + return val | cc_mask; + else + return val & ~cc_mask; case CC_VENDOR_INTEL: return val | cc_mask; default: diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index a823fde..6dbfb26 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -29,7 +29,6 @@ #include #include #include -#include int hyperv_init_cpuhp; u64 hv_current_partition_id = ~0ull; @@ -504,16 +503,6 @@ void __init hyperv_init(void) /* Query the VMs extended capability once, so that it can be cached. */ hv_query_ext_cap(0); -#ifdef CONFIG_SWIOTLB - /* - * Swiotlb bounce buffer needs to be mapped in extra address - * space. Map function doesn't work in the early place and so - * call swiotlb_update_mem_attributes() here. - */ - if (hv_is_isolation_supported()) - swiotlb_update_mem_attributes(); -#endif - return; clean_guest_os_id: diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index e8be4c2..8e2717d 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -233,7 +235,6 @@ void hv_ghcb_msr_read(u64 msr, u64 *value) local_irq_restore(flags); } EXPORT_SYMBOL_GPL(hv_ghcb_msr_read); -#endif /* * hv_mark_gpa_visibility - Set pages visible to host via hvcall. @@ -286,27 +287,25 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[], } /* - * hv_set_mem_host_visibility - Set specified memory visible to host. + * hv_vtom_set_host_visibility - Set specified memory visible to host. * * In Isolation VM, all guest memory is encrypted from host and guest * needs to set memory visible to host via hvcall before sharing memory * with host. This function works as wrap of hv_mark_gpa_visibility() * with memory base and size. */ -int hv_set_mem_host_visibility(unsigned long kbuffer, int pagecount, bool visible) +static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bool enc) { - enum hv_mem_host_visibility visibility = visible ? - VMBUS_PAGE_VISIBLE_READ_WRITE : VMBUS_PAGE_NOT_VISIBLE; + enum hv_mem_host_visibility visibility = enc ? + VMBUS_PAGE_NOT_VISIBLE : VMBUS_PAGE_VISIBLE_READ_WRITE; u64 *pfn_array; int ret = 0; + bool result = true; int i, pfn; - if (!hv_is_isolation_supported() || !hv_hypercall_pg) - return 0; - pfn_array = kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL); if (!pfn_array) - return -ENOMEM; + return false; for (i = 0, pfn = 0; i < pagecount; i++) { pfn_array[pfn] = virt_to_hvpfn((void *)kbuffer + i * HV_HYP_PAGE_SIZE); @@ -315,17 +314,48 @@ int hv_set_mem_host_visibility(unsigned long kbuffer, int pagecount, bool visibl if (pfn == HV_MAX_MODIFY_GPA_REP_COUNT || i == pagecount - 1) { ret = hv_mark_gpa_visibility(pfn, pfn_array, visibility); - if (ret) + if (ret) { + result = false; goto err_free_pfn_array; + } pfn = 0; } } err_free_pfn_array: kfree(pfn_array); - return ret; + return result; +} + +static bool hv_vtom_tlb_flush_required(bool private) +{ + return true; } +static bool hv_vtom_cache_flush_required(void) +{ + return false; +} + +void __init hv_vtom_init(void) +{ + /* + * By design, a VM using vTOM doesn't see the SEV setting, + * so SEV initialization is bypassed and sev_status isn't set. + * Set it here to indicate a vTOM VM. + */ + sev_status = MSR_AMD64_SNP_VTOM_ENABLED; + cc_set_vendor(CC_VENDOR_AMD); + cc_set_mask(ms_hyperv.shared_gpa_boundary); + physical_mask &= ms_hyperv.shared_gpa_boundary - 1; + + x86_platform.guest.enc_cache_flush_required = hv_vtom_cache_flush_required; + x86_platform.guest.enc_tlb_flush_required = hv_vtom_tlb_flush_required; + x86_platform.guest.enc_status_change_finish = hv_vtom_set_host_visibility; +} + +#endif /* CONFIG_AMD_MEM_ENCRYPT */ + /* * hv_map_memory - map memory to extra space in the AMD SEV-SNP Isolation VM. */ diff --git a/arch/x86/include/asm/coco.h b/arch/x86/include/asm/coco.h index 3d98c3a..d2c6a2e 100644 --- a/arch/x86/include/asm/coco.h +++ b/arch/x86/include/asm/coco.h @@ -7,7 +7,6 @@ enum cc_vendor { CC_VENDOR_NONE, CC_VENDOR_AMD, - CC_VENDOR_HYPERV, CC_VENDOR_INTEL, }; diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 6d502f3..010768d 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -172,18 +172,19 @@ static inline void hv_apic_init(void) {} int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector, struct hv_interrupt_entry *entry); int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry); -int hv_set_mem_host_visibility(unsigned long addr, int numpages, bool visible); #ifdef CONFIG_AMD_MEM_ENCRYPT void hv_ghcb_msr_write(u64 msr, u64 value); void hv_ghcb_msr_read(u64 msr, u64 *value); bool hv_ghcb_negotiate_protocol(void); void hv_ghcb_terminate(unsigned int set, unsigned int reason); +void hv_vtom_init(void); #else static inline void hv_ghcb_msr_write(u64 msr, u64 value) {} static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {} static inline bool hv_ghcb_negotiate_protocol(void) { return false; } static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {} +static inline void hv_vtom_init(void) {} #endif extern bool hv_isolation_type_snp(void); @@ -239,11 +240,6 @@ static inline int hyperv_flush_guest_mapping_range(u64 as, } static inline void hv_set_register(unsigned int reg, u64 value) { } static inline u64 hv_get_register(unsigned int reg) { return 0; } -static inline int hv_set_mem_host_visibility(unsigned long addr, int numpages, - bool visible) -{ - return -1; -} #endif /* CONFIG_HYPERV */ diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 37ff475..6a6e70e 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -565,6 +565,7 @@ #define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT) #define MSR_AMD64_SEV_ES_ENABLED BIT_ULL(MSR_AMD64_SEV_ES_ENABLED_BIT) #define MSR_AMD64_SEV_SNP_ENABLED BIT_ULL(MSR_AMD64_SEV_SNP_ENABLED_BIT) +#define MSR_AMD64_SNP_VTOM_ENABLED BIT_ULL(3) #define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 8316139..b080795 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -33,7 +33,6 @@ #include #include #include -#include /* Is Linux running as the root partition? */ bool hv_root_partition; @@ -325,8 +324,10 @@ static void __init ms_hyperv_init_platform(void) if (ms_hyperv.priv_high & HV_ISOLATION) { ms_hyperv.isolation_config_a = cpuid_eax(HYPERV_CPUID_ISOLATION_CONFIG); ms_hyperv.isolation_config_b = cpuid_ebx(HYPERV_CPUID_ISOLATION_CONFIG); - ms_hyperv.shared_gpa_boundary = - BIT_ULL(ms_hyperv.shared_gpa_boundary_bits); + + if (ms_hyperv.shared_gpa_boundary_active) + ms_hyperv.shared_gpa_boundary = + BIT_ULL(ms_hyperv.shared_gpa_boundary_bits); pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n", ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); @@ -337,11 +338,6 @@ static void __init ms_hyperv_init_platform(void) swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; #endif } - /* Isolation VMs are unenlightened SEV-based VMs, thus this check: */ - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { - if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE) - cc_set_vendor(CC_VENDOR_HYPERV); - } } if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { @@ -410,6 +406,9 @@ static void __init ms_hyperv_init_platform(void) i8253_clear_counter_on_shutdown = false; #if IS_ENABLED(CONFIG_HYPERV) + if ((hv_get_isolation_type() == HV_ISOLATION_TYPE_VBS) || + (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP)) + hv_vtom_init(); /* * Setup the hook to get control post apic initialization. */ diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 356758b..b037954 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2175,9 +2175,6 @@ static int __set_memory_enc_pgtable(unsigned long addr, int numpages, bool enc) static int __set_memory_enc_dec(unsigned long addr, int numpages, bool enc) { - if (hv_is_isolation_supported()) - return hv_set_mem_host_visibility(addr, numpages, !enc); - if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) return __set_memory_enc_pgtable(addr, numpages, enc); From patchwork Fri Dec 2 03:30:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6FFEC4321E for ; Fri, 2 Dec 2022 03:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231387AbiLBDd5 (ORCPT ); Thu, 1 Dec 2022 22:33:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232218AbiLBDdQ (ORCPT ); Thu, 1 Dec 2022 22:33:16 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021023.outbound.protection.outlook.com [40.93.199.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CA06DC4D0; Thu, 1 Dec 2022 19:32:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OQCQYTMHdofX6Kl3RwIwSauRwugomKAC7E67IENsRaXY6esYNewI17STcv1Act4t4BWqJ22zc/DC03py7OYPGPuTQkiiO/eC4sHMU0rnrCzqQ8Rbaf/bMeMFI1/QklsgVITi+n+USYo1vAK5HdYxpRsW5bBkmSUclV07UFZTN/Gkz4VsHr6/rC8ejAgWCzVwUSkpoPp83hvx4iLYFqYJp3eQmMoyCBKmiPe3Z+7giR+VVwFJHz6nhcpvOiZ6WhiCgNXJWQmH6k0G53d8Vxsmu3mC+OGdIMDF3s2NDW5f5g8sJ4yyc8lb9akaxbtIShDQdzdXxLQZ61mwpMw61fZX9w== 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=rS+XEDLCYXK3kG0pGvcV2b4OXTcv8/63SxxK34hw9ig=; b=fVSJMSwNKi6X0wFvmWqTlltgnuzo6wOFy0oZzDVbnvAhrSSRtJYpTkGASc3C64mpBl4O1nctJiFBVTkM6/FI7i1+fVhjwV8l9cYNr9Vk7MTY9ECYK86p3pI/2+z3ifMghoh+YhAI96iipi5Tv2BsgfcZRgDH/c02qcMflhdcuB6C5RSNXLbTm+acBYvRQkgvuO0jT7o7jwWz0qbZaLgeWrTy24ddkM/XDCPuvCIcjqt2hi0AVQf0XZLXNciCmAlP67/Szw7tppG2b+Tdh0YS9ZumXcTxx0gZF5jn7cWR+/wtcfebU+CFjb1bpFlsHpMmguum22pouEOnTuC5Fbrhfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rS+XEDLCYXK3kG0pGvcV2b4OXTcv8/63SxxK34hw9ig=; b=O16sotbRg4k3nM11+wkbrkLhgY1EzMRL/4PiclV0C3Sia2+FD+XdnWAYZbNE6oFhjUySiyz3uUej/l7hVwB871ilAIa8R1Mc3xatJjWP/lF+5GIe+vkPLTgyMsQ792WbJ/Bx9fM2lfAcxFPzFl7w81lWX7iGYU0AjFRzansjtsE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:18 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:18 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 07/13] swiotlb: Remove bounce buffer remapping for Hyper-V Date: Thu, 1 Dec 2022 19:30:25 -0800 Message-Id: <1669951831-4180-8-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: 7927bf86-f1b6-4679-089d-08dad415d02f X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w9MsoS3wimC9jm/xwiRfi3EHesfJMxTdePz9btR5h7V9ZeLCoJaEhO/rK98J39e6fd1KmRF80KruYQIpy28J+4DhjUDzLmLYyfiuWN9N0DpjybmAWHQMSm1KF5saTlP9fAT9LaDJSYP2yJiDiFGnLZwYuXFvaXYfRvSes+kZlGgu7Jsvdtaz8iA7yMWc5C8gElvXeeQPoOoqOGz9yxTfFoCKNmcMAVtvgjicBqF0qmNfjnQgUyCIzUmuUZT+V3oSCLUz181NpxbP6XjdjV8EtZqSZ4Vrx9STkZfAeU6slHuWBXmWH5S5TvBqpKVP534H/e9F34OLoRtaDOGKE2dwSkozukUwLevLgyTaMqskycLOJLWfg2tVngG+XAmewsih3OxTh4KSNokAyir9Gu3HjRz+lJZ66x8qD1TcEKpjs89Sl8XgavdPlJ9EbeoD3/bV5WRrBWhZ2uaowBrmjLChsoJrafakHErlVe87/c4+GhAWy7ckVwC2Frfp8FOdiCLvqzugYRW9oG43+fyr9eUewn/XflORTYwN/O4p2a9XryGNYUqvWyKze5/jlYOEWmvFN/+CAc0PdaxTftZxzmg/pbe100NO3sAdNusQ+sA2LLQSVN8k4wASUlGGopFyn+zEV1ojXqQj7YnYvbGYBcb3dS5zFCm6Ep1NxSURYr1rghx0aKcPX76BVdT32dg8t8c/1SafBBnWesRyLk9WbhkQ3+chVP9dHdOc+/qEzG1jjasIt1rpIto1xBMaqunfCWi/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(6666004)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aU/9xGzKxFIRTeQTSX9UzGFPdxXUrtUIpmbwhYJ5Vib7IcXpWvjYZPcevzvVInz86qtz+ePuPaZtRZ/lojUTDUBjN6OEWE2cs6/erfL7QxWerhjI7bD4zHoH+5saJzWeOWjCHezIMBvK96EkK79pEVk9ssjmBSG6fDN+K/uPfvGPHE9GSc3mocgH601a1WvR7B4+8YNxcA+kGFBH2h6U5fW+C4lGRm+aySxx4H+dJFTnRzbHb5ND/FWp6Oo527rzmpq3XGivex5e0DwhMpH+VtBHJGzX9S7geX2/Sgs7nNGKA+4BuxuzLVUdH98UxfY+TjaIRNNWdwF8jDApgMvrkfElkXB0EwUhvJLxldmUAdZn8eVafhOqrqsq/0j/42dpFlj2q5VgLnZ+5hRPYipTvEwGn0+lLkOahO+n90zz2DhCguk46Q7BWfRAykJxmkdcBlamWCvFkijGIdGmX6aUgAV77ueoHq4pv7szKoWPAL1Du/xWFdGm5lPqhr92CV6rWwyBYwmPzCyfSQj/AAUt1aaQihi1vUbrjx/qg3kCVj9PdkDkHQ+40Dz0/dnaY7WUI0BG1kn9jE4T35YF1BdE+8zSUqJJvDktVdUUcPNcRykCVlyvxAw2yzVS8iU/TGAGqOzZSjJ2XZx5+iF7sWYMWj0xjjy8kRjM7+N/p3+FniAPvBAwuytYQ5B2fXLK/YW99IejE1Ok/VWvbpJHtHw88wTRnx+i9so1oauR7l674ZHZ9mB5cy8pxkn9J0AoT8v1JhY7ROY4mgAftN7gAuM8oZN9qxi0q8S15Ezssrs1wmZ4Tor3Q1mL38+cw4O90xY9NkpWblZLAXf2I6DUVqltmWX1Y/+rejpXImQrFVbRcfy0RsKHFH1yQXb95828WwRXwmdZtdu0naJa4BL9xYW0fJ9d/0uLfSTqdMy5tgNTvtV4tqt6RBH7LZ9rh+Qy+cTHFNjmwx+oI4eaaRQImDFx3IXyqz8NBarZNUf6h64SpbF5rg5ipTqqc0QBLYDVg7NG00jTr0jOotv02Pbwx/j84eSlgWO7Vxio9Pcx4RmmoQ8g9+NwyQ4X0x39gIOfs2EnX4w1r/rJJqEgruBVOdYkarP85Ct3Qydzm4T6a/U+PnCnDODEmVtZH48zmOzVSWx7ZPwbhVUjzFFQKEuL4kebxhKy7kiF2yOGrn/+j2k3d8nWJldHMrMAa2llBl8lqUzkqj3apHdDZjzhFWr1n2+IuL7K/MTAp+761Oa4iTvdm85BLmvUBK/WUrh59UaTxL0H3K4Z/85gu9OxgAy4kkrS7hh5hL/zlV0jEb5XXIIcCgXxxRxEvymwdHd+oG0kpg+4I5dTy214eX7FGgSPclepqTes8d8XVMlgvB6NaEOSbpSESGbWzbrFtzYFawpVVtmVe1NaXzfttVCzhRrULbj4UDLV7HZN9gzYxmggz+vyuaj4ANYkGQfYrqRW80rI/to34V4iVs0iZna00TCMvoyRFLb8xgcR9yt+7YJCQmqXcBuzHtuN0hmFW9DBC+gMQ6ChXxpez24B1VYIKtBUtH+8W8Or0qPQF2RCiBP6TPahJlcm2EcFZarqWNq6jH00AppGbMrR0iyjUdtfET+7cL4WxQ== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7927bf86-f1b6-4679-089d-08dad415d02f X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:18.0991 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sXZhNu+Khgxse57w1bnydlxsN1bhfNkbSwTjDTOGQpd0zbY34hZ8vCMrjVFMZBSXKMIhEpv5Ov0Zqi7fYA/vwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove swiotlb_unencrypted_base and the associated code. Signed-off-by: Michael Kelley Acked-by: Christoph Hellwig Acked-by: Borislav Petkov (AMD) --- arch/x86/kernel/cpu/mshyperv.c | 7 +------ include/linux/swiotlb.h | 2 -- kernel/dma/swiotlb.c | 45 +----------------------------------------- 3 files changed, 2 insertions(+), 52 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index b080795..c87e411 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -332,12 +331,8 @@ static void __init ms_hyperv_init_platform(void) pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n", ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); - if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) { + if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) static_branch_enable(&isolation_type_snp); -#ifdef CONFIG_SWIOTLB - swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; -#endif - } } if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 35bc4e2..13d7075 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -185,6 +185,4 @@ static inline bool is_swiotlb_for_alloc(struct device *dev) } #endif /* CONFIG_DMA_RESTRICTED_POOL */ -extern phys_addr_t swiotlb_unencrypted_base; - #endif /* __LINUX_SWIOTLB_H */ diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index a34c38b..d3d6be0 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -73,8 +73,6 @@ struct io_tlb_slot { struct io_tlb_mem io_tlb_default_mem; -phys_addr_t swiotlb_unencrypted_base; - static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT; static unsigned long default_nareas; @@ -210,34 +208,6 @@ static inline unsigned long nr_slots(u64 val) } /* - * Remap swioltb memory in the unencrypted physical address space - * when swiotlb_unencrypted_base is set. (e.g. for Hyper-V AMD SEV-SNP - * Isolation VMs). - */ -#ifdef CONFIG_HAS_IOMEM -static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) -{ - void *vaddr = NULL; - - if (swiotlb_unencrypted_base) { - phys_addr_t paddr = mem->start + swiotlb_unencrypted_base; - - vaddr = memremap(paddr, bytes, MEMREMAP_WB); - if (!vaddr) - pr_err("Failed to map the unencrypted memory %pa size %lx.\n", - &paddr, bytes); - } - - return vaddr; -} -#else -static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) -{ - return NULL; -} -#endif - -/* * Early SWIOTLB allocation may be too early to allow an architecture to * perform the desired operations. This function allows the architecture to * call SWIOTLB when the operations are possible. It needs to be called @@ -246,18 +216,12 @@ static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes) void __init swiotlb_update_mem_attributes(void) { struct io_tlb_mem *mem = &io_tlb_default_mem; - void *vaddr; unsigned long bytes; if (!mem->nslabs || mem->late_alloc) return; - vaddr = phys_to_virt(mem->start); bytes = PAGE_ALIGN(mem->nslabs << IO_TLB_SHIFT); - set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); - - mem->vaddr = swiotlb_mem_remap(mem, bytes); - if (!mem->vaddr) - mem->vaddr = vaddr; + set_memory_decrypted((unsigned long)mem->vaddr, bytes >> PAGE_SHIFT); } static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, @@ -288,13 +252,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, mem->slots[i].alloc_size = 0; } - /* - * If swiotlb_unencrypted_base is set, the bounce buffer memory will - * be remapped and cleared in swiotlb_update_mem_attributes. - */ - if (swiotlb_unencrypted_base) - return; - memset(vaddr, 0, bytes); mem->vaddr = vaddr; return; From patchwork Fri Dec 2 03:30:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8390C4332F for ; Fri, 2 Dec 2022 03:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232245AbiLBDeI (ORCPT ); Thu, 1 Dec 2022 22:34:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232244AbiLBDdR (ORCPT ); Thu, 1 Dec 2022 22:33:17 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021023.outbound.protection.outlook.com [40.93.199.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 341A0DC4DA; Thu, 1 Dec 2022 19:32:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=goelepv1eVhh5zF5Xa+6Gui2hpqRbjFcCBhiFD2N1YSwn/f6kqT3sdNELJy4j9RLoehDeTw9iQa5u9rloO9Tew2Q10oewu0Bz4twYqA0bx7rRVGkgaR2HR232Bp4FJIMmmZRwaaS1e/4QMuNOI2TPzRi3oo0wTtnSbl9o0uSr11h9Dn2ExM8kqA1EqrQeJYYgy8W3QzCXiBV0UNvyvohEqlUk6IdFQ2qgg6Fs9jVNhkTBc/HYA5SZwNpVG+l43OEzsk6OLkv7lC45rrCEWYI9DwBOBS0be4CTvzQczWXdi+5aVDWxhYyNLmP2u4b58Y2mXes803uY0GVlXqF4X69KQ== 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=kvE6SyTZq6LB5flL+POxNJmNnPxQpwBAtj9alMcKL+8=; b=kXpIPmm4Otp8/VqdZD0iV1yACA6kCKZHniNn2fVMMvAM43GIflO7YYLPLF+F4TjyNvZeNNKqVeyceexZbgzcnxFlzLNThXGs7orTi8N7hbHMH5nJa2b7W+4KBx23SMb0XVfSkVNAwSL1zhvqyv+e9EGcY1f/hlO6PGlxkMo26Y2mLZT4s+s/oWiDx2vniZ5Dv+o6iWs2n+vmEAwk6y7VMi36eVjw+J3bjkc0+fX4aU5B/nf0tpUXxWr4CwLFgGK1yMAuchLxEevsS/l5w8496Yx7SJpHrdp+iPIVbm9NLEyTh7I1uD0WN47zJBcgsiE5CLJtPz728PiRz0c42+KTMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kvE6SyTZq6LB5flL+POxNJmNnPxQpwBAtj9alMcKL+8=; b=WNPcwoW8aLf8vUVk9u31FYzTMV+31xF9dj199sTl3QsEY+JKlmqTzYo+RIrrddlySfAv2uzh8CBjqtVoLR7ncTyoc9nuBjHn/jplbPMbbkcXtmSpN2pZIDsOHz9ZI83dk/SzXSnMO50JURtvzbmcEb0cwORtUIXZMm6jKwVbyKc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:20 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:20 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 08/13] Drivers: hv: vmbus: Remove second mapping of VMBus monitor pages Date: Thu, 1 Dec 2022 19:30:26 -0800 Message-Id: <1669951831-4180-9-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: f3582eea-0c6f-4e94-a511-08dad415d17c X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xKUE+nD/cWn9j1MCsk4i9J8t/+QA4VFlj0itk8Wy7K7sXhIBeVr9tZEpQx0virljBeXeXmBqL5gM4r0/RGAJuwqimsDIM9OPwGlea1/fz0hGWeEEMfaUicezAwMjBmx2MKIZQafdcUKzFLN9jO+W93lTI5PYDvcAmR2c8bI03njIOVdBexZDf6Pz+9LDrD4mhoLWLG2qsRKcyHz22A7yxIn75+gQ5PdSPUO23AaPckvtTlNqHPeCSbM1sl+S45Mjp6IBCCOPGA5MPj1effLGSnyxFECjXghwD2J+FRkAl7uJJOl8HzpDwwFAtuySBhS48sXNhkGMOXLR6QEQdBHGUqSUhcapzVvYZQjs74V7LRcP0OVCXf5OwvWdrO/Kaj/gXWU5wyBotAG9JRvoZHo0hUxEKAheny4kIDV6AFSo8uXoHdc221HFahGl7MTt4byJMNYyiK2W3fFkXLfAffb4dZBX+zN4i96MPt+LX0RZQhOejBWJ+v2v4nbiyDzN/o/sviNPwhQjhgxCQ4N0DQsPah1VZkQbMhdCQuhMduONM/zIcXUph3qs+1rc8whNLvtKsYF3Yj8ZSoVWorAJ6S1om6ftNKGQJp87tSlWFlGRfN9phnM9K+qYfhaB0ry8DGIv+boscItVApdUy5awqi3DACs9ys/vMgZooiN/P/Hk0hVkCgmJhHnmx0tE9IDR2nZy/wBbJR4/HxCB8EjWsHs5OX070jog6ZlHIV29GT4oOm0U/0k9dKQl6Ec+AUPV58IP X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GD2K80y3YdKlKAfNsulHz6bHC902YayHqikDOwGN34qEoxSYZDD5XkRCBj9CcNow8vNLYRKYmE/hfRU9A7tqzNGnRIDBOn2bxHF5P1RMf4unAzG40ZI0YnOWs9qt0U/dFuGp0I0bF0t8xq1xmjEbKh6bc4OuII6o951nX5WhxiPqmMYuCRE1vLFvyG0Ii1LWgBVpx7r99Ia9I15+OCskKqkHWSlgDZ9od5xcomgfm3ISqVp6ZDLIm3ODaIOYRJVzcoN0S5LzUqnsWCfFoL643nJ2X0LSuc59gi6UNZz5Y0metSmDA/3NV1oG2alwseHn8cHGf5w+OZc5MVy76W2yi/cuRMrmKzpk+s2EadyB/xvCXCz9ZEG7J8lwmnYCaygXJ5/ul9qERJgRmDD4nVi4ZiFTiQs5NuThqaKtYntKIN385VcK3cqxROe5PL9+8AqS53Y8aJZ0T7qwMtGPf28LnRtPM5rSeSY0Ic8GnijHd0CGmOHaWCB+uTfYnQFYWb4qnnuMN+UksafxlEHKUWV8ZByrzmEjtSKClqqe0q7U0NQTvNPEqERSf5O2GMIUS8IzaCJseCVBHIf8FowBr/pKW4Vwk4kFMtuE9AFLlur1lhS98AZj4nQGFGZWbhiAMij8oPs/5dwN+kok0ETT3qC4kNciuCd3yH/0lvlTxog7oQz2EN/GCPZEGccRiL9JFPU5QQEQi3mH/quQMjcnK6w9Fqm3WytBDZwp68SdzTrtJWk3yWbqAGIFHeOjqwJUz5mk9hPwr9Vp1Sufc1+CkHro1pQ48uHMv4wu+giolJZA9stPL8L34bPbnn3l091p2U7FEuM0Y7PaZ1q5QHYcm0yQH+T87KNsTDRFqhjsxv40MhS1DdMxME0VWprLzz1UPkEmnkAr96NMzeGBF5/7LcuZNRST1UA2VOttr20fcWMt6QuqSAwuDmLwYmmF2BUvJqtkPfKvAeWhNqV1ovJrvBKkC4/IUaOyaxIRM+7qog5au9dralPsZkEhKf1rdCMY8PGG3BrL0kMBSo429nKm7K5kTAHaMVcPhDNo67GM2oMGoryHDSbWXohPk+KHmWS8DJiMaEg5TO/t/dvYDbahk+UkXdqFmMlOaxQyP9Rw6i4Q4voNOpZ2r9zIW19c1noF4RtPNBWjpc6sG+vBMzw7oUQhRkJPVNYPC2YydQUfBAkJcDB29oh3n2CSnAsJNeFjFm9x4ImNSENUmIk2OsO5f/+9rFryf5V8tXUEZj3mxsC1k/jiHj0scfKSCtyVu2MzYV9YHHhqtJj21P+acMN40wjMY8fSEWLCsUIgn+IZzPmzXUIx/d7hekz1pERHST9sVLhuuQSaCoJYw+J4UmUgoM/2XACQFzlmyqOYvBiD1v29WJL3iQ3NdIultp7kcaoLUZfePyjolFfHoxdq15Kvg/Q7GL1PXB0A7aBuDUo1jDh4NZ9IICvLdyFiIhhlOS8XOvwgrOB44c+aNjbD+HxvaPkwcaSFCkLVrkGW36fphwjVGUezW4MGr+cybqLJWHeO1UCFEypLOdaQKzkNJhbY5iqO3Tct2JTXHNEBGBPUStk8OSKLZMueNka1WK58ErtkvBOHHO15G43fnQQkPdp9rIQxZg== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3582eea-0c6f-4e94-a511-08dad415d17c X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:20.2854 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EGU3GhbDkMjDil2V+78KJgCB0ZPLUE+wVpvoTiyfonrcFG2+Myc0BAXjmkdQMLafqv9eScbfbxAijGPHe14wYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for VMBus monitor pages. Because set_memory_decrypted() and set_memory_encrypted() are no-ops in normal VMs, it's not even necessary to test for being in a Confidential VM (a.k.a., "Isolation VM"). Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/connection.c | 113 ++++++++++++---------------------------------- drivers/hv/hyperv_vmbus.h | 2 - 2 files changed, 28 insertions(+), 87 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 9dc27e5..f670cfd 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -104,8 +104,14 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) vmbus_connection.msg_conn_id = VMBUS_MESSAGE_CONNECTION_ID; } - msg->monitor_page1 = vmbus_connection.monitor_pages_pa[0]; - msg->monitor_page2 = vmbus_connection.monitor_pages_pa[1]; + /* + * shared_gpa_boundary is zero in non-SNP VMs, so it's safe to always + * bitwise OR it + */ + msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]) | + ms_hyperv.shared_gpa_boundary; + msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]) | + ms_hyperv.shared_gpa_boundary; msg->target_vcpu = hv_cpu_number_to_vp_number(VMBUS_CONNECT_CPU); @@ -219,72 +225,27 @@ int vmbus_connect(void) * Setup the monitor notification facility. The 1st page for * parent->child and the 2nd page for child->parent */ - vmbus_connection.monitor_pages[0] = (void *)hv_alloc_hyperv_zeroed_page(); - vmbus_connection.monitor_pages[1] = (void *)hv_alloc_hyperv_zeroed_page(); + vmbus_connection.monitor_pages[0] = (void *)hv_alloc_hyperv_page(); + vmbus_connection.monitor_pages[1] = (void *)hv_alloc_hyperv_page(); if ((vmbus_connection.monitor_pages[0] == NULL) || (vmbus_connection.monitor_pages[1] == NULL)) { ret = -ENOMEM; goto cleanup; } - vmbus_connection.monitor_pages_original[0] - = vmbus_connection.monitor_pages[0]; - vmbus_connection.monitor_pages_original[1] - = vmbus_connection.monitor_pages[1]; - vmbus_connection.monitor_pages_pa[0] - = virt_to_phys(vmbus_connection.monitor_pages[0]); - vmbus_connection.monitor_pages_pa[1] - = virt_to_phys(vmbus_connection.monitor_pages[1]); - - if (hv_is_isolation_supported()) { - ret = set_memory_decrypted((unsigned long) - vmbus_connection.monitor_pages[0], - 1); - ret |= set_memory_decrypted((unsigned long) - vmbus_connection.monitor_pages[1], - 1); - if (ret) - goto cleanup; - - /* - * Isolation VM with AMD SNP needs to access monitor page via - * address space above shared gpa boundary. - */ - if (hv_isolation_type_snp()) { - vmbus_connection.monitor_pages_pa[0] += - ms_hyperv.shared_gpa_boundary; - vmbus_connection.monitor_pages_pa[1] += - ms_hyperv.shared_gpa_boundary; - - vmbus_connection.monitor_pages[0] - = memremap(vmbus_connection.monitor_pages_pa[0], - HV_HYP_PAGE_SIZE, - MEMREMAP_WB); - if (!vmbus_connection.monitor_pages[0]) { - ret = -ENOMEM; - goto cleanup; - } - - vmbus_connection.monitor_pages[1] - = memremap(vmbus_connection.monitor_pages_pa[1], - HV_HYP_PAGE_SIZE, - MEMREMAP_WB); - if (!vmbus_connection.monitor_pages[1]) { - ret = -ENOMEM; - goto cleanup; - } - } - - /* - * Set memory host visibility hvcall smears memory - * and so zero monitor pages here. - */ - memset(vmbus_connection.monitor_pages[0], 0x00, - HV_HYP_PAGE_SIZE); - memset(vmbus_connection.monitor_pages[1], 0x00, - HV_HYP_PAGE_SIZE); + ret = set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[0], 1); + ret |= set_memory_decrypted((unsigned long) + vmbus_connection.monitor_pages[1], 1); + if (ret) + goto cleanup; - } + /* + * Set_memory_decrypted() will change the memory contents if + * decryption occurs, so zero monitor pages here. + */ + memset(vmbus_connection.monitor_pages[0], 0x00, HV_HYP_PAGE_SIZE); + memset(vmbus_connection.monitor_pages[1], 0x00, HV_HYP_PAGE_SIZE); msginfo = kzalloc(sizeof(*msginfo) + sizeof(struct vmbus_channel_initiate_contact), @@ -376,31 +337,13 @@ void vmbus_disconnect(void) vmbus_connection.int_page = NULL; } - if (hv_is_isolation_supported()) { - /* - * memunmap() checks input address is ioremap address or not - * inside. It doesn't unmap any thing in the non-SNP CVM and - * so not check CVM type here. - */ - memunmap(vmbus_connection.monitor_pages[0]); - memunmap(vmbus_connection.monitor_pages[1]); - - set_memory_encrypted((unsigned long) - vmbus_connection.monitor_pages_original[0], - 1); - set_memory_encrypted((unsigned long) - vmbus_connection.monitor_pages_original[1], - 1); - } + set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[0], 1); + set_memory_encrypted((unsigned long)vmbus_connection.monitor_pages[1], 1); - hv_free_hyperv_page((unsigned long) - vmbus_connection.monitor_pages_original[0]); - hv_free_hyperv_page((unsigned long) - vmbus_connection.monitor_pages_original[1]); - vmbus_connection.monitor_pages_original[0] = - vmbus_connection.monitor_pages[0] = NULL; - vmbus_connection.monitor_pages_original[1] = - vmbus_connection.monitor_pages[1] = NULL; + hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[0]); + hv_free_hyperv_page((unsigned long)vmbus_connection.monitor_pages[1]); + vmbus_connection.monitor_pages[0] = NULL; + vmbus_connection.monitor_pages[1] = NULL; } /* diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index dc673ed..167ac51 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -241,8 +241,6 @@ struct vmbus_connection { * is child->parent notification */ struct hv_monitor_page *monitor_pages[2]; - void *monitor_pages_original[2]; - phys_addr_t monitor_pages_pa[2]; struct list_head chn_msg_list; spinlock_t channelmsg_lock; From patchwork Fri Dec 2 03:30:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BF97C4332F for ; Fri, 2 Dec 2022 03:34:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232261AbiLBDeF (ORCPT ); Thu, 1 Dec 2022 22:34:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232241AbiLBDdR (ORCPT ); Thu, 1 Dec 2022 22:33:17 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021023.outbound.protection.outlook.com [40.93.199.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C6EC2AD8; Thu, 1 Dec 2022 19:32:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EeUV7OLK2KWPBh5NuVpoExZnmy+fDZK48PlFBTwed7oKWEJza5L5G5i4vujeZ2x4kRYxNnAljNfopSkutS2Qis4GoFjDOLcbLrIlz+NdLzi0N4Z0EGyu4+a/hxnBHa29p7nwb1YNuFarR+E+KBi9xIlkT/XHklRYRdF5xenID+KGeGkMakIVtUJ8hL0vGmTQfU4Bc977g/MDepkm6+XZ5Vfa7GHZGHU3QBgnfxflxFvm4swYnxtDWG+jvdyZaY7Tb5IGxOFJTbwitVTv3VfUKzedqLBrdC0d0mn/3b6v9oMhY8AL8HuDVIjYlNwK+2rYRKLrf93V3FqVlGX+S7rAmA== 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=2BgK/x2W5lMaNW4JFyzo6Zk/DXGfuC968f19LbsR/ig=; b=lL6PzcQDyIyJMIx8vVQJipLGA8Gep40wRXGgyoJ0Sv81DD9xK8gHcP89PRjjw3a6s17C14EEqu0OhfTc1s6tRWm2IsWOJVHA2IF3sMmgOyxInHPUcdLoc+F/mHdRmkc+ZDQpFD9HS9bHghx/71F0ipBYCzkYOQUGA9Qe1XuUjmIFeE0SxAb7JPbZy5SA/tHuwTC8xmUu6zjQA+7jcTEI+sHR40ZCrBJOBqqdNEyWCnqQGk4S4rRkPsL9C9H69F6W18ZoYjeUWg1wuK2rC6dUBid3nqhffKwnZiX15EaUJXk5VhH/ok6VqaPve/hPK0454fs/KVnq4WAWMRs64C/yxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2BgK/x2W5lMaNW4JFyzo6Zk/DXGfuC968f19LbsR/ig=; b=YEn9SdBTHrIjGdLVOnXWN/elE4is/e/NmqVCY5FfVtD/2pxeTggkN0ZYZDk1T4VQSqhnbA6YfhpoHJHZKfGKbkDVaLOIqV4CMo4USzbGWgcl2L6GEidDK8/l++7iyCaXltROEPzyEbPi7S7paB3NN5MsOx4t2AaWH83YrjEW7mM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:22 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:22 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 09/13] Drivers: hv: vmbus: Remove second way of mapping ring buffers Date: Thu, 1 Dec 2022 19:30:27 -0800 Message-Id: <1669951831-4180-10-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ae30e38-577c-400a-3519-08dad415d2c8 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zp5lXaRrWIjBPf4S/lqjOxGu/uxqEiA9YvKWFLinOoqZznT8vOfEspq58IAeO4w3IP+z3NuOZFTd4PRUmUn6xrAt6QB9lYII3WMgQ0zeqE/s9f/km5FgmPTPDaa105i+FNJfx0wifN5tP+6Hh+utRX/kLhcUv2/DOiJHAI3M31a1aeVp4bLdWTObNSAobHqDkFTXb6Y18+pqqO+7kKLYJ0Wu9UrfP4RcxRbh3yErazTJy2QzIUTF3KCioQbJGOIGW8Mp9NkfjFUc2fXtxgbb5Qf2QUiNlTlEs4Lnl++2khY5lc6mT0MBawNicP2L+DX9HIOrYHUZqpCFdODgbGPCtRdDa8CA/1dxYL9JBa/ydkX7WWxEZVkctlslKK6ZBzBs1BiFB8d9DveP6DZkxzqWNwu5UzU8KjgXEutaeR4OLi6S11JilGlYLIiMCJbguj1sY8zts6zaRh3W+wNK3qulgZlrTD7Jc/xlDeniQTduLdPpHud9Rnq0Cky5VmOqiSD0UkE0D5a/IgVCZZcRMmF7lGyC7SlXjGCp5l9OMrl/w7V7yfOLTqtn7IqeClDGJXuwhh+Ot45F77B+7mH/Mls92Bo8t0XzE7jHMZEWUBNpKsSvww9wChZj6Pz71t3ohNtzxRnB+M0EATSNArgMNw1uDQRrNPpm8ifcLc7eiQXDJx/CPHpDUUqyUsbG4c4aYGxROShR1k95xtcEIHeL3zF57gpzO+WR49O6K0IVAhpcx4at3evgE0+L9VohFCwed0nn X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5vTt4oya+/jcwpiY1jT9NhbkGmv8YTQth0QMnrf3a++Qxboi6R2o4xnBbWOETOn8O5773kk9QlL2Ikr7n36fLcOgaiuMdmX4h/PBGKyLP66z/XJ3JJ1VkmMMm3PxRvVb32MiPW5c5WZq9z5xDRn4Af1e9xt8SZqDPdZcmsfFmOxrL/GfIMY956zKZai8LtPxaAO5ZxtMzcYnPYl670lflruAec8F0EXOxm/diD6Feuj/n0P/B+yP2hBZ6WLNMYKSN5dbcehBd1EywcZA6wuh89+yhPvwESwgPbhOrx06MWRv0zrTTfLbiYDv+RwSyrKX3E5CESV8/sqdx+fMLZtZaOcuQcT6gqJWdgEiEq358p70bDPiOlsw8Pc6ybSaV5ciSBAtJYYNn35AEQbur5byJobjGdia8U67UE/rliaZERB9hTpKaYDISbl7hWr7Tg16GPvKAp/C8lvdVpjRrOlo+LWh6yWIwoBMmJo5q5CvqqLliHBVYuwBzrZhfnlKeZ/DTaef7dJ3pakq++3jkdGwvWAGao9xUBggP6Owyg8VkqRGpem00sv0fJa09Vr8d418ggyGuHXP8E/V8hs7nMgx1dTD9+Xn8jZbdeIMVkCekclbMRijGgvqNVv1Yxx3U0hbC/pdKHUeK4ntYApsqxoWEcqa/+hD6uoe4cpiXabN58gBX1ncmEjD6X6bFNIa968eaAmA1dTklj1VcMyGRIIbiFQmpj6bWMaVH2oOQBqaMBJRWHn3Scn+qKbu/r6lnJ3PER8tS9RUa/pJIb7UQONvctzF9qWWydNH8Vcc/ESXKy5Jumq8tpW7CiabAGevqb01xlvRKTFrLWnTAmoDt1NbcAMNO7u5UC21O/fNgSI6G0PaQ4pnEBIv0xTo56myKp2EadHFGoPaxVKg7TreO86/uO/gQABPMXPLSR5ZTshL60lMpNvsW4UcpMm/wbx5W1xpJXkl0AC4XdeIYkn2+2IHNQyG9uG5LzURiiGkjCAcHBEd3PPoGOd8d8DApQqZyb4cDvMZJw/lc5d3DTjtc/SjxOlQJYUu5M/IFS+1wJa9/1JBOhKdx/cR3zTf+HAScc1neiXJUzvf8CQR9wU4YMiQnh7zklRHpxcec0i/tcGSpiQbqV0wo9AhGlb2PDZg5/WuLR6kzeeQrJrbfc07Lgtn6MV95ag8rt2IMqwE8nhQCQZtScCGis6nP2iI7ux9D0s3ORO3lL3iOU2KM84g6h7MEJtfqdt6gpwMXg/uZZhPAbapBxhy/bH06FkgcrN7emXkUP+52wYUXdh2ZMGcK++eURbrSUmNuTEcCOB+qoo6ivM1xZSNUN5I+3jhseaRiJnna+37uHjTb/C5GNYD/P1pw43af0tylVnu7UaKv67CsAmtyUeT2S4/Qzlk23PmUOYzeCfWymEY9LCiswU4tQQMdZEKJltnMXIPuSvt62ZWE7ucrEGTDbbdyrayJWWYhPYH5oqST292fg98zEOIDOwh11CnSvieQiGkk3SoTCkQ1hGQEAjHPbs0RfU+PbZGUCHkx3LPO7vPtEjbxvZp99eI8N136dNbjQUeQCEUXUp98g5yHWO50pEVYAmRKRDjvcXnJ6SnqG77Jj3rOmxk+XXh/g== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ae30e38-577c-400a-3519-08dad415d2c8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:22.5052 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XYLby82ApD1YcNPdfJvqGgD7noZVNfBpTaigsnwkeqpNpE75brW4otDLdF3TSiyC3vC7DvORPnLGiT6KFhheZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), it's no longer necessary to have separate code paths for mapping VMBus ring buffers for for normal VMs and for Confidential VMs. As such, remove the code path that uses vmap_pfn(), and set the protection flags argument to vmap() to account for the difference between normal and Confidential VMs. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- drivers/hv/ring_buffer.c | 62 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 57667b29..3783d9d 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -186,8 +186,6 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, struct page *pages, u32 page_cnt, u32 max_pkt_size) { struct page **pages_wraparound; - unsigned long *pfns_wraparound; - u64 pfn; int i; BUILD_BUG_ON((sizeof(struct hv_ring_buffer) != PAGE_SIZE)); @@ -196,50 +194,30 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, * First page holds struct hv_ring_buffer, do wraparound mapping for * the rest. */ - if (hv_isolation_type_snp()) { - pfn = page_to_pfn(pages) + - PFN_DOWN(ms_hyperv.shared_gpa_boundary); + pages_wraparound = kcalloc(page_cnt * 2 - 1, + sizeof(struct page *), + GFP_KERNEL); + if (!pages_wraparound) + return -ENOMEM; - pfns_wraparound = kcalloc(page_cnt * 2 - 1, - sizeof(unsigned long), GFP_KERNEL); - if (!pfns_wraparound) - return -ENOMEM; - - pfns_wraparound[0] = pfn; - for (i = 0; i < 2 * (page_cnt - 1); i++) - pfns_wraparound[i + 1] = pfn + i % (page_cnt - 1) + 1; - - ring_info->ring_buffer = (struct hv_ring_buffer *) - vmap_pfn(pfns_wraparound, page_cnt * 2 - 1, - pgprot_decrypted(PAGE_KERNEL_NOENC)); - kfree(pfns_wraparound); - - if (!ring_info->ring_buffer) - return -ENOMEM; - - /* Zero ring buffer after setting memory host visibility. */ - memset(ring_info->ring_buffer, 0x00, PAGE_SIZE * page_cnt); - } else { - pages_wraparound = kcalloc(page_cnt * 2 - 1, - sizeof(struct page *), - GFP_KERNEL); - if (!pages_wraparound) - return -ENOMEM; - - pages_wraparound[0] = pages; - for (i = 0; i < 2 * (page_cnt - 1); i++) - pages_wraparound[i + 1] = - &pages[i % (page_cnt - 1) + 1]; + pages_wraparound[0] = pages; + for (i = 0; i < 2 * (page_cnt - 1); i++) + pages_wraparound[i + 1] = + &pages[i % (page_cnt - 1) + 1]; - ring_info->ring_buffer = (struct hv_ring_buffer *) - vmap(pages_wraparound, page_cnt * 2 - 1, VM_MAP, - PAGE_KERNEL); + ring_info->ring_buffer = (struct hv_ring_buffer *) + vmap(pages_wraparound, page_cnt * 2 - 1, VM_MAP, + pgprot_decrypted(PAGE_KERNEL_NOENC)); - kfree(pages_wraparound); - if (!ring_info->ring_buffer) - return -ENOMEM; - } + kfree(pages_wraparound); + if (!ring_info->ring_buffer) + return -ENOMEM; + /* + * Ensure the header page is zero'ed since + * encryption status may have changed. + */ + memset(ring_info->ring_buffer, 0, HV_HYP_PAGE_SIZE); ring_info->ring_buffer->read_index = ring_info->ring_buffer->write_index = 0; From patchwork Fri Dec 2 03:30:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062136 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9093AC4332F for ; Fri, 2 Dec 2022 03:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232285AbiLBDeq (ORCPT ); Thu, 1 Dec 2022 22:34:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232270AbiLBDdT (ORCPT ); Thu, 1 Dec 2022 22:33:19 -0500 Received: from CY4PR02CU007-vft-obe.outbound.protection.outlook.com (mail-westcentralusazon11021023.outbound.protection.outlook.com [40.93.199.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E03DF3A; Thu, 1 Dec 2022 19:32:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e6EcD6NFJY5R1cOH7dW6UG8Uf1+gtYRI30/7JlNzyzRQ+K878vf2JOKCdNeUpZ9u5dO5zXNkT/EJw6bj+es5grUln/1lF9uS/SWbPVVP2MsTBpYwtTQJaOiNMvvb0djv73WlfajxrorImdy7MnAQbQaEoNq2Ay6Oo9FY9F4+GoDwFFms6T3VfaDKGBkIyIWY9ybaqQFHsNi2b4/Xs+1rC6gRxOSuy2oQzUx7/Nkdv1A8F7kfHuGdx1D5vi22ztP7C90WDs+TQsbh/SYOpk+TZro5kYDEYIG7dh8p81GXab+z/btAxcMNlb5Bi9RLM/+IXaePvLRT+EJhajjzxn3nbw== 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=CLvLpvSwNbIGXks/vU31yhV4PgqEudo572uGrbfS4zk=; b=oXFpdQmkf1Btm7jWnMKr6lLFpQxiZFbf8TmcBp6Y16pyUxKi9A71wCfpwKkWgrs3zirBw6p7ILjlHLw2HP0ylIqLrgiTN0rEDYj6CLjWAkjBtzqJBtR2p0kLp4JfC7wA9z1gugD0NY3I0nE6Pa2cDLS8s+Qe6t1rEVK0hVp6aHPuzSf6fDorpSH0eI2XHiE4RpUXBDsXzHqDdgWFhqwplSRnL2lNm7rDiiK3/J1QEBn4+zvFMkJRZ6UI5M1MXH6P85hqob3Q3G/dOdA4eBng1lg3RC+Ui+6HqjgvJOLQfzP1B/gb5v0agMMlMjzfwV0DngCpSBqtNB6bm4xy6q0ajQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CLvLpvSwNbIGXks/vU31yhV4PgqEudo572uGrbfS4zk=; b=IuuZXYpcWwqR/NpebKSpVDXYIMkHgKOZJRKD4U/D3J2Je+cBV82ikeTQgQ3F8nFhYejDCd7b+B/TjPe0N+FhSDE+E6QCEPkm5b0twEJKphLQKIZ1YAUVO8MrtVh3P1707HiU9be468I43CIpEBuTA1YrPFSLIQL39RWlceTbpto= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by BL0PR2101MB1316.namprd21.prod.outlook.com (2603:10b6:208:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8; Fri, 2 Dec 2022 03:32:24 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:24 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 10/13] hv_netvsc: Remove second mapping of send and recv buffers Date: Thu, 1 Dec 2022 19:30:28 -0800 Message-Id: <1669951831-4180-11-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|BL0PR2101MB1316:EE_ X-MS-Office365-Filtering-Correlation-Id: a6664ff8-452e-4284-9c84-08dad415d41a X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AjdUBeSzzuytcdRkD/V5e0q5PfYXVopWMa/2piT0GZYIkc4I0QLPHI/zLgABQLaoBFH0oLEuLQRf28USRTZfdUcDOYrj6j9pgyTqXvjjRM8oz1p8LVEtrChs5gZ7t5Mv2cecZZbVw12GYlu1LTt6t7T+A6+6Xngiabd+ylNnRP3DIyS1jBwpNgRe+WXX1Pi6RpQ1hp2j2jNJxIWRC/GpO3THpPdHEO3D4CE06ZeLXCd0650o7gcHVMuJnTR8HnQ6bYOu0WASdH4IQn3ZszuHrvXqxf0eeBl81fBQnZbFeIC5NzEEKRXhzqoQZSPdimqDbMeIZf2pHgWxkwPwnCui2AIs+WHelAQ7/fNC6l2nDYSc86PMHczlfFr94NNwat2Myw0CT+P0DG4vZ51GXRPXe9bnw941QobydKeqfqrEmNRzbMHqe51rkVhWckz9/sdBigKQ5LmbDUBShZn3QgFyR6c1ZaMHF6jed3ys6N45E6RnlPWulDGji79Rc85IBW3CUnaCQX3FKn6ENxSfJ1QSoglEZ6rYkCtaL8v924vm320cPR8CfamaIOM9VTHGllW4IUVhu+qOBBdOcdBH5135mpqOTI0uBf16VaUTEb+CiVCcB1Epk5L2igjdgbyXEDw4K+NnFlGHO8JgaABNHHwQx5oup2WTH/JudyJLCoIiph97xz+eoRehiLiHeQ8XxaklR0afYyog7Ga3OinTGQA8C71q98iT5BQH07FnqYFeGYTtURgzvk/C7t/fy65qYwem X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(396003)(39860400002)(366004)(451199015)(86362001)(921005)(41300700001)(36756003)(2616005)(186003)(8936002)(5660300002)(66476007)(66556008)(52116002)(66946007)(82960400001)(7406005)(8676002)(7416002)(6506007)(107886003)(6486002)(316002)(478600001)(10290500003)(4326008)(6512007)(26005)(82950400001)(38100700002)(38350700002)(2906002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zuG15Q7e3ElnC7eEyOuHyHjB9JYN+ErNBCCruAXPbgSBThz/Y5YemdnSPjY24285oKRkWTTNfYd9kMOS1p8sCn4tnX1Y62PRp2e6aIOnfaoCqVsFRDk6lzyNuyEvqd2xxh8v7rYF3C1PrDyYIR8abSBT92kxXEJL23ciDp59wrTG9fIQsyuJTEM9Hz0lycQI/0VwiXmxAWZ7Ex9vx1buRRuaswE9+3kjGNTebaS/qmeksFjPNrx74ketG0zIR+8iZCUGfG8OTW7n1K5tlQUxDwryiUyvbOYOlImJPQx8tKozSt9gZLXHJRPMDAim5+7UMFDCsoexkOdc+m1zVLsN2LKKwK3DB6CAj7u9sabglMyYblSAtAgeMB+0wS8Kobj1DvoQmkI6o9aAV65hZrxEVIMVRmHi75YvySGAG9iZXYkNjoqSvy0oKt5fXy68qrmyi/uHYItx1HS2ANbfxJtdSg/vsD+sPd5hdd9z+H7RyEMWa1OI71TnMSwT9kNnBMLp+Vyl1fJHbQj/amXXd68W4iIO6lyn5ggp5+TGXZYNrR/KfK4K4fXsFR5CZM2J9a3iI4mtFKZF5TeI3ti+b7USoB47OyvIL6MsOU/0S9DtZpipqOQeTtUzbTOGa/ZPZzEFEtVzTN8Zgoiv8OTEkf9w9ucxLOLDWzkjP/65FjMBdqTMGsAP12YkjqaJgGKxdE8rFfYwl/mPtX+HoAvIjX4HRXtg87TFClQmE4LcoHqf6qMkrkur/nG7uJnnXTAW9CjJhtoN/PpQun0z50UPWC4qWp+noRBNyxiKQ6lrhuuyW87QskdUtMuZPxSu8x8j5IR4S+JkDZdBcS8HSLOlzZox52Tez2CSw2GcCF/LlX4PRF+aANtPSVNiNvqTXNzJBhWm1paN+ftXSmTabauBdzaF7oN72m1YGFo2sfRC1+brI+k+1WQL4Mz6LxZImz02V/UJKEBLfw/7uWVEEd03c9fxsAeFYRDPTM2yqsStefYOqZsWo/edsEJ76w0eB4v2azBAuQmosmCwq3Rmn7PIrj42YhTGjEEmqqoMz83AXv8c9KFzSn01R1OpljzQHmRbeNXmM33A/1s1D8A6cOVSxrV+FlAPtlX+w+zhlKhbPJ2raSX4PzwrEjKVYWlnbvs56stlXFr+8F6lEC2cbNNUVv04k5UrZExL1ISOizo7836Rl8p9Bx/T4s8ZXNjIIvvlrUlTM0+Uq7Om58PN8PZVoYrZLER4RLZJB4KVBqusEBxje6M7I4mnGNktI/7YuT35pStXLZL/2goaWLNQBoUKQYKdKZE+PfDFFmuL4X3TL540mAdyKfeOO+haexbRl2doOw8+4GcfxhweaBHUcKeoyN8HanES7m4WoQEUVU9dyfk8NmpYQJLAR8C2xHKMjjvSFhHik65NwTFGM8ORwQbA7uxIEnIDzz5/xd7wppPJAPA+fzjaX60JaYbc1GOPmg2vJ9DJJiwHcXEtJLdbGfWdDziDg3ra/z448eGlvTVLLHNJfRhXjOJUQEkZwWCQYAvt/7VNW2xMT4sjr7qkJc2Xodh1cn9JR27AgMEwEAmYKDKMTGmPJQurJgP8b01ORBhJVfvvSrpz7DBL7xKO6MUxDn6fyw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6664ff8-452e-4284-9c84-08dad415d41a X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:24.6761 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: L6dlaqNRUaFGQB5dx03gnBWUL5XTu4Uzt/57baOAEU3/ntRbtnVG7b00AmKYaqkJITgUNhv1ELSkZSLo0f4gTg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1316 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org With changes to how Hyper-V guest VMs flip memory between private (encrypted) and shared (decrypted), creating a second kernel virtual mapping for shared memory is no longer necessary. Everything needed for the transition to shared is handled by set_memory_decrypted(). As such, remove the code to create and manage the second mapping for the pre-allocated send and recv buffers. This mapping is the last user of hv_map_memory()/hv_unmap_memory(), so delete these functions as well. Finally, hv_map_memory() is the last user of vmap_pfn() in Hyper-V guest code, so remove the Kconfig selection of VMAP_PFN. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 28 ------------------------ drivers/hv/Kconfig | 1 - drivers/hv/hv_common.c | 11 ---------- drivers/net/hyperv/hyperv_net.h | 2 -- drivers/net/hyperv/netvsc.c | 48 ++--------------------------------------- include/asm-generic/mshyperv.h | 2 -- 6 files changed, 2 insertions(+), 90 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 8e2717d..83b71bd 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -356,34 +356,6 @@ void __init hv_vtom_init(void) #endif /* CONFIG_AMD_MEM_ENCRYPT */ -/* - * hv_map_memory - map memory to extra space in the AMD SEV-SNP Isolation VM. - */ -void *hv_map_memory(void *addr, unsigned long size) -{ - unsigned long *pfns = kcalloc(size / PAGE_SIZE, - sizeof(unsigned long), GFP_KERNEL); - void *vaddr; - int i; - - if (!pfns) - return NULL; - - for (i = 0; i < size / PAGE_SIZE; i++) - pfns[i] = vmalloc_to_pfn(addr + i * PAGE_SIZE) + - (ms_hyperv.shared_gpa_boundary >> PAGE_SHIFT); - - vaddr = vmap_pfn(pfns, size / PAGE_SIZE, pgprot_decrypted(PAGE_KERNEL_NOENC)); - kfree(pfns); - - return vaddr; -} - -void hv_unmap_memory(void *addr) -{ - vunmap(addr); -} - enum hv_isolation_type hv_get_isolation_type(void) { if (!(ms_hyperv.priv_high & HV_ISOLATION)) diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig index 0747a8f..9a074cb 100644 --- a/drivers/hv/Kconfig +++ b/drivers/hv/Kconfig @@ -8,7 +8,6 @@ config HYPERV || (ARM64 && !CPU_BIG_ENDIAN)) select PARAVIRT select X86_HV_CALLBACK_VECTOR if X86 - select VMAP_PFN help Select this option to run Linux as a Hyper-V client operating system. diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index ae68298..566735f 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -308,14 +308,3 @@ u64 __weak hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_s return HV_STATUS_INVALID_PARAMETER; } EXPORT_SYMBOL_GPL(hv_ghcb_hypercall); - -void __weak *hv_map_memory(void *addr, unsigned long size) -{ - return NULL; -} -EXPORT_SYMBOL_GPL(hv_map_memory); - -void __weak hv_unmap_memory(void *addr) -{ -} -EXPORT_SYMBOL_GPL(hv_unmap_memory); diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index dd5919e..33d51e3 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -1139,7 +1139,6 @@ struct netvsc_device { /* Receive buffer allocated by us but manages by NetVSP */ void *recv_buf; - void *recv_original_buf; u32 recv_buf_size; /* allocated bytes */ struct vmbus_gpadl recv_buf_gpadl_handle; u32 recv_section_cnt; @@ -1148,7 +1147,6 @@ struct netvsc_device { /* Send buffer allocated by us */ void *send_buf; - void *send_original_buf; u32 send_buf_size; struct vmbus_gpadl send_buf_gpadl_handle; u32 send_section_cnt; diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 9352dad..661bbe6 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -154,17 +154,8 @@ static void free_netvsc_device(struct rcu_head *head) int i; kfree(nvdev->extension); - - if (nvdev->recv_original_buf) - vfree(nvdev->recv_original_buf); - else - vfree(nvdev->recv_buf); - - if (nvdev->send_original_buf) - vfree(nvdev->send_original_buf); - else - vfree(nvdev->send_buf); - + vfree(nvdev->recv_buf); + vfree(nvdev->send_buf); bitmap_free(nvdev->send_section_map); for (i = 0; i < VRSS_CHANNEL_MAX; i++) { @@ -347,7 +338,6 @@ static int netvsc_init_buf(struct hv_device *device, struct nvsp_message *init_packet; unsigned int buf_size; int i, ret = 0; - void *vaddr; /* Get receive buffer area. */ buf_size = device_info->recv_sections * device_info->recv_section_size; @@ -383,17 +373,6 @@ static int netvsc_init_buf(struct hv_device *device, goto cleanup; } - if (hv_isolation_type_snp()) { - vaddr = hv_map_memory(net_device->recv_buf, buf_size); - if (!vaddr) { - ret = -ENOMEM; - goto cleanup; - } - - net_device->recv_original_buf = net_device->recv_buf; - net_device->recv_buf = vaddr; - } - /* Notify the NetVsp of the gpadl handle */ init_packet = &net_device->channel_init_pkt; memset(init_packet, 0, sizeof(struct nvsp_message)); @@ -497,17 +476,6 @@ static int netvsc_init_buf(struct hv_device *device, goto cleanup; } - if (hv_isolation_type_snp()) { - vaddr = hv_map_memory(net_device->send_buf, buf_size); - if (!vaddr) { - ret = -ENOMEM; - goto cleanup; - } - - net_device->send_original_buf = net_device->send_buf; - net_device->send_buf = vaddr; - } - /* Notify the NetVsp of the gpadl handle */ init_packet = &net_device->channel_init_pkt; memset(init_packet, 0, sizeof(struct nvsp_message)); @@ -762,12 +730,6 @@ void netvsc_device_remove(struct hv_device *device) netvsc_teardown_send_gpadl(device, net_device, ndev); } - if (net_device->recv_original_buf) - hv_unmap_memory(net_device->recv_buf); - - if (net_device->send_original_buf) - hv_unmap_memory(net_device->send_buf); - /* Release all resources */ free_netvsc_device_rcu(net_device); } @@ -1831,12 +1793,6 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device, netif_napi_del(&net_device->chan_table[0].napi); cleanup2: - if (net_device->recv_original_buf) - hv_unmap_memory(net_device->recv_buf); - - if (net_device->send_original_buf) - hv_unmap_memory(net_device->send_buf); - free_netvsc_device(&net_device->rcu); return ERR_PTR(ret); diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index bfb9eb9..6fabc4a 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -267,8 +267,6 @@ static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset, void hyperv_cleanup(void); bool hv_query_ext_cap(u64 cap_query); void hv_setup_dma_ops(struct device *dev, bool coherent); -void *hv_map_memory(void *addr, unsigned long size); -void hv_unmap_memory(void *addr); #else /* CONFIG_HYPERV */ static inline bool hv_is_hyperv_initialized(void) { return false; } static inline bool hv_is_hibernation_supported(void) { return false; } From patchwork Fri Dec 2 03:30:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9721C4332F for ; Fri, 2 Dec 2022 03:34:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232098AbiLBDeC (ORCPT ); Thu, 1 Dec 2022 22:34:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbiLBDdR (ORCPT ); Thu, 1 Dec 2022 22:33:17 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11022027.outbound.protection.outlook.com [52.101.63.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0893865BC; Thu, 1 Dec 2022 19:32:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MYuPdWxNUs8KwschDwyIEfMtePPadA/bMmAPpjI6YKZ+/a7SgdbsbYG8HQxQ14msiwv6N5v3Cpi7WqE5mJuIbzGDnv/7HZ9hR40PWGFi/eLSFv9BCLfCsGcIKUMtfpeH44GKuwXdBTP1OB6VCXX4SPTQYTtuCMPj/w+00gnIFkxjWRcCsPox7BL2DF6S+9TNFAHTohm/JNm3qPCimQmC8x4flEdEN+07eMZIxvV/vWqWKM8wCQxqAI512P0W7R8Fp8r7k+GEqO2CrPNsX0Cvy8ijViwv5Ej+GJTe8Q2mBtAlaUNazNY6VolRPQBS32pflPK/qAxR473zM1xV1XgWOA== 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=AcnvgpzsxhSuI65c5UvEjo1C3IpsG+3rnruV2R/KQIM=; b=aAqwJonhH7rUfv4CVBCj1edGta4iWgnzIrO90hHO5DcukYaE/J9EtcUiUFbVvA0EPFZeQ69aeVU6FQwK6MInPT4mBBA2mkm0loodbxM9MjXy+zmM2nLMam/fGYdkIhMKInzVHwsWpW4ZYZmTXnRKmK4O+GcJAn+DthrL1K2ljaQKgfHNUVUs7hUjLzMXgIaROnNPBsifL9XbYGW7iBcQcASSr5iWf3Go8hPctQxEYn7EaIm5IRVJEH8iwZdR68/NVnDdFU+7QZJp46sm9ZSqL1JwltUsHSoXuJLY/rgdo0LyVo+DXxmAa8dI9JQLiZhDno3FA5AdYG4APZLk53qi4w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AcnvgpzsxhSuI65c5UvEjo1C3IpsG+3rnruV2R/KQIM=; b=IZJdLq7VMWZZneUdXSkXp6A5dKmXrdimggL160Zncq89yOJd5zQ48WdEHZruqWAi8++bGi2ET0gGMJ8bWN7VdhQl93hrzgPK5sIcsPCbwCgy4Y3WOzr5RAQyd81z+6GwUXDwUX38UONkb0YCPh3jwYd8PiEbei+//mU4DUidBWk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by DM6PR21MB1340.namprd21.prod.outlook.com (2603:10b6:5:175::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.4; Fri, 2 Dec 2022 03:32:27 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:27 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 11/13] Drivers: hv: Don't remap addresses that are above shared_gpa_boundary Date: Thu, 1 Dec 2022 19:30:29 -0800 Message-Id: <1669951831-4180-12-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|DM6PR21MB1340:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e8f2460-dd23-4a2e-f4a4-08dad415d563 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WpO1MtFr2GFW9XPdEFUZ73I0vWq2PWa27ZnwxP40g3xEj56bV9WpvBgfkk0rXlAtzrv1/4wfq+mwZ6qiZJK08BkTXjHnp1cSxekMCfk3iSsL8hs7ZNWDsvGExKFPDBJddgWC7uoO3y959CuEAXm8npAxILN/LrzpVJgOneuz/zWE7GXJgUEr+Pjei/E/veitsvXPktqXfuEO1c8MKh93Ly42ldaLJC92pMxPh0JxadkO+QXUZKSeviej9GGU7bAZE+vEj3zsvz91cNr3ketRUIFWmJSIQBMCTWqG4rtgGau35AlbgOssTYYxhppXXyleYd1mOJuJ6SOcmKMCOfuQZnJ8iiS4bNNQF1O30HS7qi3x+ikirefhv+o+acKhtr3p3McAcY2PdJvbYcGZQXW7c1bO3q5SSkP1roiCRe9iyJjmnDM3JimRd8wv4EJRo3ZrCIFLrSBkf+w21TKcmylrwpGcF0ZnbIm8f/9UUIj0ywpovKOHQNxRzbYxK50m9kBOezwuLLQ0YMlcuVSIgm63dOgPFGEJlHSKFX20scJ+gNoOm0DsgFd3NlctBiAkk4tESiyK6WucxpwKDZJLicTCszc8FdjCk1UIJZoNYDF7JC7iBbXxNLmStMkA+L42wLLIUOUiJ33CXgon7GAh6XKz1uhtuuo5VlLYvuU6S/gg9Pj32QRFmCZ2i4OUFULao+XILyDPDZtH0zrdsktUf3U/V0xnifpCnAFO135/M5WlHsiYJrhF2ApoKJALJinONrXI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(136003)(396003)(39860400002)(366004)(451199015)(186003)(8936002)(8676002)(10290500003)(2616005)(107886003)(86362001)(2906002)(36756003)(7416002)(41300700001)(82950400001)(7406005)(82960400001)(66476007)(66556008)(83380400001)(66946007)(316002)(4326008)(921005)(5660300002)(52116002)(478600001)(6486002)(6506007)(38350700002)(6512007)(38100700002)(26005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: egjLJMd1g7mee5I+0sqB+nAezJkeAzNULiYxv36vncLAbv8gt7HaJ3+V8/J7eA+UOHvdIq1h8dVQ1xcDIFSJYSvFsb9OBPRY8nTdZ48zYFaEmBegYetaND5Fi6Y4yHdCitWeQU4AhgKZ4rzzVbqPI+Hh1nFncfXcJRuquXPvUiT4cJgd6RkhC8WzZo6hssIRX6rruLSsX7B8o7l9Y0ZwuR9Gk3dzdMfr5WIF9ACkwb7f8XkNucy1pEsnn+hoOqP9O8954XvXElqFnyuMusmT9gmKDgaVjre3fvOxf/8lfXLX4xEmxzCPnFwlEL/9u22uCreIqUA3EoAQZXTI/4LhBArnP0RoWJ4/cBTDTE9jCqcjMX+oa8vaJZcf0sG9xYja0HGRMJBBfBMIf1v4Vt0fK/UUwyCb1xXWFCt9G2/m8e/RY0UoZwVevoG+DR2xfSDhlUnHFsr87ydWaTZosRz/FKNxMjdEbp6y1T729QB1Tsv1g7r9wif+XV41mqN5Lx/tySgdAcuEkrSr3LCvNtXJJ+d1u9uTNsb0vuh6nfJvh/X2t0DVZ5v2g63KtNE+Je1VuEbGCkcFIVUTa94Jdarhid4qFfDyqP0dDLskLnmrLu8HZQxugXLQakwU8pMKbKK7T0p9smPnfCTIxvYuhvnYIuxf6GOxGVFDqfuUFd8B/c0MpwmkMdkqTkG9IO8Qz1RZct/7eiLebmmWNjLmAL5WHmC8lnNXs58F5ik2LTBQLN0jDwns/yzFDHoYgXOAuchKTKr5LalRcDmYTQl/bpKFbm1d00aji7BaHMvfYjxfXQsmARCzFA/z8Oa38tRA7y3I0BmZUkXz2MPvLxRns4F/3F5gLi9U80MuVykhR9ZA0KFv5s11EHBadReSMwmVBg5QF/hSJ0aBnePekH0MonW3S8u4l4gAuIpmwEL8iy6yfe+ZiGwWUJcQxlu9tY9dy6ygRkYQ2DmrhK2W7xQepi3xUOKulGZNr5b2kYeMH6lom4ynQLvAhUJLBQjfYhOX56cxmH7AjimL34drJ08GNbnYT51N7CYV/Gq+F2lcNDF6rX3JLnhv64ix87kqfOzZWp84OK3pPGx2CbOb3l+jc00GFJzSUqA/BTrXxY7axWm99tM88ckO03L3SOwhFu5B6VIRaNXYV4Lcx1GdmVew+ja1gi76HWMNyg7ARiGMcK2HJ0ApMiPcQ2IY4jFZlww8kISemi4jxBkF+BoSJ65R/l50x0QJlX3xYbDvwd+skWR0bkit2Rl0ci1lSsdeDsymMfb+/wk/zCzjXaxAE0b8CM36uKbpG38LZMS+yJo1hLd63jX1N22bdR78e9WEgyKhXeDmJ4Aa7CtuBr0XUM5FnVlO4lEnsoh8j79iMHty9eLG7uEEQrc64HPFOarhu6hE/pmFEwF2hSnHhLWErBRUOAbBHcBLWcvMMtfGFRkieSdTTUpgTf+BlvtbdVgVzs/FjY8AhkOy3rT2IJWHrLm5WAGYuJmjBpfVLhaeBKMoydGr0KlQ1bPTdcEawfvxyT145aXZTO0A2wBKO0ixPp8N1KQVWkiqAPShXWAlrPzINkCo4YY0BCT99GfgzuJmy+euPcMRSW84lR4UK7OK5na7glJ9WA== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e8f2460-dd23-4a2e-f4a4-08dad415d563 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:26.8658 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yFH4xa6ZoERTKuHzhP0VC2pOLXfHN63fLgbI+4bKQG+T5hMKAhD1AoNLLJxQjlMLt8JXld39RnsZ3t+/apod8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR21MB1340 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org With the vTOM bit now treated as a protection flag and not part of the physical address, avoid remapping physical addresses with vTOM set since technically such addresses aren't valid. Use ioremap_cache() instead of memremap() to ensure that the mapping provides decrypted access, which will correctly set the vTOM bit as a protection flag. While this change is not required for correctness with the current implementation of memremap(), for general code hygiene it's better to not depend on the mapping functions doing something reasonable with a physical address that is out-of-range. While here, fix typos in two error messages. Signed-off-by: Michael Kelley Reviewed-by: Tianyu Lan --- arch/x86/hyperv/hv_init.c | 7 +++++-- drivers/hv/hv.c | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 6dbfb26..9070a78 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -63,7 +63,10 @@ static int hyperv_init_ghcb(void) * memory boundary and map it here. */ rdmsrl(MSR_AMD64_SEV_ES_GHCB, ghcb_gpa); - ghcb_va = memremap(ghcb_gpa, HV_HYP_PAGE_SIZE, MEMREMAP_WB); + + /* Mask out vTOM bit. ioremap_cache() maps decrypted */ + ghcb_gpa &= ~ms_hyperv.shared_gpa_boundary; + ghcb_va = (void *)ioremap_cache(ghcb_gpa, HV_HYP_PAGE_SIZE); if (!ghcb_va) return -ENOMEM; @@ -217,7 +220,7 @@ static int hv_cpu_die(unsigned int cpu) if (hv_ghcb_pg) { ghcb_va = (void **)this_cpu_ptr(hv_ghcb_pg); if (*ghcb_va) - memunmap(*ghcb_va); + iounmap(*ghcb_va); *ghcb_va = NULL; } diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 4d6480d..410e6c4 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -217,11 +217,13 @@ void hv_synic_enable_regs(unsigned int cpu) simp.simp_enabled = 1; if (hv_isolation_type_snp()) { + /* Mask out vTOM bit. ioremap_cache() maps decrypted */ + u64 base = (simp.base_simp_gpa << HV_HYP_PAGE_SHIFT) & + ~ms_hyperv.shared_gpa_boundary; hv_cpu->synic_message_page - = memremap(simp.base_simp_gpa << HV_HYP_PAGE_SHIFT, - HV_HYP_PAGE_SIZE, MEMREMAP_WB); + = (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE); if (!hv_cpu->synic_message_page) - pr_err("Fail to map syinc message page.\n"); + pr_err("Fail to map synic message page.\n"); } else { simp.base_simp_gpa = virt_to_phys(hv_cpu->synic_message_page) >> HV_HYP_PAGE_SHIFT; @@ -234,12 +236,13 @@ void hv_synic_enable_regs(unsigned int cpu) siefp.siefp_enabled = 1; if (hv_isolation_type_snp()) { - hv_cpu->synic_event_page = - memremap(siefp.base_siefp_gpa << HV_HYP_PAGE_SHIFT, - HV_HYP_PAGE_SIZE, MEMREMAP_WB); - + /* Mask out vTOM bit. ioremap_cache() maps decrypted */ + u64 base = (siefp.base_siefp_gpa << HV_HYP_PAGE_SHIFT) & + ~ms_hyperv.shared_gpa_boundary; + hv_cpu->synic_event_page + = (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE); if (!hv_cpu->synic_event_page) - pr_err("Fail to map syinc event page.\n"); + pr_err("Fail to map synic event page.\n"); } else { siefp.base_siefp_gpa = virt_to_phys(hv_cpu->synic_event_page) >> HV_HYP_PAGE_SHIFT; @@ -316,7 +319,7 @@ void hv_synic_disable_regs(unsigned int cpu) */ simp.simp_enabled = 0; if (hv_isolation_type_snp()) - memunmap(hv_cpu->synic_message_page); + iounmap(hv_cpu->synic_message_page); else simp.base_simp_gpa = 0; @@ -326,7 +329,7 @@ void hv_synic_disable_regs(unsigned int cpu) siefp.siefp_enabled = 0; if (hv_isolation_type_snp()) - memunmap(hv_cpu->synic_event_page); + iounmap(hv_cpu->synic_event_page); else siefp.base_siefp_gpa = 0; From patchwork Fri Dec 2 03:30:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A9DCC636F8 for ; Fri, 2 Dec 2022 03:34:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232380AbiLBDeo (ORCPT ); Thu, 1 Dec 2022 22:34:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232269AbiLBDdT (ORCPT ); Thu, 1 Dec 2022 22:33:19 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11022022.outbound.protection.outlook.com [52.101.63.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57F0019C29; Thu, 1 Dec 2022 19:32:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oPPLKjRbNWTTcO1AmAofKuzGuYgCsdBWFqsdpFH2EoFlJNWMykxIaG91gXeohrfeGPYjSWEcODYmX0X4t00QHVfmG/cy6u0fuIfFbQZDppEUCsjtW3PlEOvCepHKjDjSha1z25ilPSZNogjDv2vDIvSUyvDj0OsGI3PsZNhK3sovUxoPqTifWVvDbPWv9D7W5plnO4nXrpT1iOM/04zKL1NCyomg/8iBk7EF06OhSEf0mbLOUHxG/A0xA17i6l9tTrCDXCxBHviH4VI3cUZV9plMmRWCU8PCIyweWi4Fka8K5ypXTgQKEBGx4v7Z5Wh1LBtYNhdMJmVPD9KBu+D1PQ== 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=Fao+CpNeHFJc4G6Mr1e63n4rwyy3SRB0nquX09ZWVsw=; b=ADlKeqrgTy/lWHI3A7MwaBdU5TR+6lM6GP5B+D1C0XwQwXsZ7KEJr1MqW56tTbw2bL8uWS7HwzjuTK0LrTifshilpQ15ZFqV9JS4p80A58jhUGRLjo2Doy7IsJw7WNQgvPC1Vv+Kbt9Sh9eJM4ZVrDRI5N3hgURdDg7WapB/BhLsAQ/eBmJKliP7Rr6XkZ7xTGBsMbIXCa9fbQ4D/hn4JMokem8bSwoL6j0HcJysdtvfLdZ1XVSMM5sLlOzJ7pstpe5ZISVDDNIVn1bbbN80LpfyGe7W/pOsYmuI3C5Ux7PFhcaQ6Rh9gaitW/7nO1hqNMQ/DiXd+ffQYgfP0xmI4w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Fao+CpNeHFJc4G6Mr1e63n4rwyy3SRB0nquX09ZWVsw=; b=jbzL4LbSjCyUajX1/r7JoUuH0oR/5rQqjX5KGrxPLxTYREBf3g3Cjk6Co6p1bK9RCe9OTYlkZYX27uZe2BPozbWHUvPNpuZzmpHpGEI+ZidexHx7dSDMlm8RRwtJNyM7Ga2hPUBPvl+f0x4Yjl63hGr7Pv/bUdSMlp9/HOY5yYc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by DM6PR21MB1340.namprd21.prod.outlook.com (2603:10b6:5:175::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.4; Fri, 2 Dec 2022 03:32:29 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:29 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 12/13] PCI: hv: Add hypercalls to read/write MMIO space Date: Thu, 1 Dec 2022 19:30:30 -0800 Message-Id: <1669951831-4180-13-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|DM6PR21MB1340:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d9b17aa-f78d-4f1f-8d02-08dad415d6b1 X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kdzk4RHK8iKrC7YdoSTARdQ5T76p38djC0WRxKfFVvarMDJwtGTPHepxGeSGWhhu97hXjRRrr2dYKu5D8Evr1FecSgMlUAonRcWy39NRcZIQV26o8JgS4dFma3YoV6qF+jsibt6HtKrFN6R8DcYj2uXFFrY9O3Vvww5LkuyNb/V/PzYTW7epptHL2uH2OOs37aOw6swY+32yPiUlgkjgG2pGZ9uXs/5/pa83gkaHF/MzgUUNX3QRWKNKuPaa1MMK3JEF1Y+YJDxN1Ozkg1oDleuugBA9Uuc18hY0jvkOHTn8LipR00712Cy3YKBVzTPN+Fw8niLxjZQ4eIuf2sfCIrVRF3F/7LR3gPDxg5IJ2ud9F3y7P4NarqtHrxrPChsMT3mQQTHfewhTtbaoO8h9jbuRjSYtcytyolWLvgaDspCgiYKixhYlZb2hjKdC7xl7+MPjHiugsgQwU+hR3nonmXC4saqJaZtCcha7V0do1UoNpygILQhQ/HmHp4kIXJISK2RwhBj/DO9dRdnR6Kf4Z76R0hbTXPCAqc8iE//lwjni5eiKGIVXoJ2625LA+4JjaGJrY5j1+dplQcrpXbmbl76sSOoGsYKsI8xlh3jMhKkzcBFo+U1/i3/qwxufPFlx0/tMOsStx7CC4QmWeNj64kq6bR5R32bzjeItCS/haXupA7GWjTfM+F4iDJIXu0rH+sU1wHV95FK/qc6t5vC8R/mC/eH75gHbsPdHFoG65AIbXWA+tHGy0qLu1hJBh9QV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(136003)(396003)(39860400002)(366004)(451199015)(186003)(8936002)(8676002)(10290500003)(2616005)(107886003)(86362001)(2906002)(36756003)(7416002)(41300700001)(82950400001)(7406005)(82960400001)(66476007)(66556008)(83380400001)(66946007)(316002)(4326008)(921005)(5660300002)(52116002)(478600001)(6486002)(6506007)(6666004)(38350700002)(6512007)(38100700002)(26005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1LOXEKhGdHpK6ln5RcaKi10eb0QrMdOOBBMy/VsireyC5X4DvAGtaUfK9pgvBWW1YhR43YxaA154DSOUvKUtFJZLWmWWLYZS4hc1wRWJoc1ZaBAWLm33E8Yi6dcF3jKE/jTCsjz5j7ms9WK9Z1WNExu3sZZQYbTWHTgZpYaEesCIgWAA5/Rf8jB2S960rZG/EpkA8RUr3x5pZfCCrtbhGcEFktk0EKeCoEUdyyTjsp1b0RSXBnmwuLDdr/pYBsyMujCTAnlogBmubKD8BuIrpMvvt2Z/F4IQsS2qNhV1o8HoXk6HhxLvtqrpBwb9SZUQQobs8y//am1VPq/4IOMjIHf2AaAnljF9zrCB1JeZVGd2KAh0LzkQT7nL7jKcfM99IM7ukeoYvsjZ7Y1n/KnOU7gAzRmTW7VSVmA/Fb+QcMYdcahdbt26qp0jCGSefRlDtgNkl4QQv0k1guLpmA7XRk6W9ostjJ0/DIhKrSy7L7XogQxMpSYLjgA3fDtBAVoqN//GNQ7zwjYUZAHO1w/+0uoOsMKWxXyc9Fffozea8ep7gfq+wWrkYCmjaV6tSVopdbLPvQrddUB/akkRB2V8xsMa4fBKPM3i7d4IuiLDwHfKdI+lxOpx/kkaWTDO7MnS6vKibqcKkWymTRwdbkr2O4a5Cth7iIO0a1XmX+mzz8ArTfU4rZe5NKu3dkV1PQa2Aa0xArdMOQLul026T7a376DniCR9rk0LCbQ70PuhKm15LA5QgDd1InnNa34rNP+m2OjCSYSwW+cngNwglJ8azhnI83MKqtorMjWmxKFxlLmJdKaivAlZAhf94wScFMQJZbLZbS7Dm4r8dg4GxS5UixjUYxCQ/1t/AoG8I7mPHNf+AmoqxZW9NaxwrlIspnjsKaAyBssZn7UO2JJDp2rZt3iBMy1+g6Z1x+TjoFcxl7k6WRrZYO3J25bhhsyMH+lmGRb4Nx6mMjEktK41fhvSypqn4KI9ccGzV8BE7Bq7fDcpqiMnsvR+nuwFUDjGMUujY82GUSaNou3+kiIjpuZTlHTvabbQcQLJ9w2AmqoE3IXf6Nx7K80kDXa/PBpgL09wQbxLCW80x7aTpw1Yb2pHnbhfj716LPKbksZkCbUg0NZAFRfHBqlx/84w9VWp7wZeyl5Rs4MKafMY78bPZ9Qvxw0lfhzfrbhErLenTnNwHpguEoAs2roBjO2DKU3ZgLtdhrTP5IDbdDUCvU1XX8BI7j+g2fKxFY6uwZ52Ltxxx1q0HSVG+DIrxpoInKR82QFPBURCuBu+Juhyeq1wKnfdwJVjXNspC5aovmzmPCM1yeHLujvnkLCIDNgZlx2bs6FVEk24t01SKrrCJQ0P6YrRxZt63KVkhlApLRP9YrQyz0c8Bwlx8TT9zY5pBUyLPkiYcTeV8TLMxRm1Lkuk7czD90b5CDTDHq+8QGfMZFKOwQMmI5caMf3ok7z1s5ZVk789Jtp+ek3kTfENUPdqj2gkLDvSp9EHGjFIXk5OvDqxlhkAQgbIAUazVwXL3VK4neA9G9qaDkij/F/N01FJ4tgb2hJoQw4y+hXYzo5SniMeoh2OfVENXXr9+3B8gzSmynmt9fMC1U/eL/RstHuQINEGpw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d9b17aa-f78d-4f1f-8d02-08dad415d6b1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:29.0208 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gkuCLU+DZWqqm4UP4Fhxq5RhS0nsXtYqSBlnNbbjAAJ2J5Q8S9/z9+x5duUybzWfdpU1s40LCWaGRvBAeV5a9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR21MB1340 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To support PCI pass-thru devices in Confidential VMs, Hyper-V has added hypercalls to read and write MMIO space. Add the appropriate definitions to hyperv-tlfs.h and implement functions to make the hypercalls. These functions are used in a subsequent patch. Co-developed-by: Dexuan Cui Signed-off-by: Dexuan Cui Signed-off-by: Michael Kelley Reviewed-by: Haiyang Zhang --- arch/x86/include/asm/hyperv-tlfs.h | 3 ++ drivers/pci/controller/pci-hyperv.c | 64 +++++++++++++++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 22 +++++++++++++ 3 files changed, 89 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 6d9368e..4d67c38 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -117,6 +117,9 @@ /* Recommend using enlightened VMCS */ #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14) +/* Use hypercalls for MMIO config space access */ +#define HV_X64_USE_MMIO_HYPERCALLS BIT(21) + /* * CPU management features identification. * These are HYPERV_CPUID_CPU_MANAGEMENT_FEATURES.EAX bits. diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 084f531..bbe6e36 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1041,6 +1041,70 @@ static int wslot_to_devfn(u32 wslot) return PCI_DEVFN(slot_no.bits.dev, slot_no.bits.func); } +static void hv_pci_read_mmio(struct device *dev, phys_addr_t gpa, int size, u32 *val) +{ + struct hv_mmio_read_input *in; + struct hv_mmio_read_output *out; + u64 ret; + + /* + * Must be called with interrupts disabled so it is safe + * to use the per-cpu input argument page. Use it for + * both input and output. + */ + in = *this_cpu_ptr(hyperv_pcpu_input_arg); + out = *this_cpu_ptr(hyperv_pcpu_input_arg) + sizeof(*in); + in->gpa = gpa; + in->size = size; + + ret = hv_do_hypercall(HVCALL_MMIO_READ, in, out); + if (hv_result_success(ret)) { + switch (size) { + case 1: + *val = *(u8 *)(out->data); + break; + case 2: + *val = *(u16 *)(out->data); + break; + default: + *val = *(u32 *)(out->data); + break; + } + } else + dev_err(dev, "MMIO read hypercall error %llx addr %llx size %d\n", + ret, gpa, size); +} + +static void hv_pci_write_mmio(struct device *dev, phys_addr_t gpa, int size, u32 val) +{ + struct hv_mmio_write_input *in; + u64 ret; + + /* + * Must be called with interrupts disabled so it is safe + * to use the per-cpu input argument memory. + */ + in = *this_cpu_ptr(hyperv_pcpu_input_arg); + in->gpa = gpa; + in->size = size; + switch (size) { + case 1: + *(u8 *)(in->data) = val; + break; + case 2: + *(u16 *)(in->data) = val; + break; + default: + *(u32 *)(in->data) = val; + break; + } + + ret = hv_do_hypercall(HVCALL_MMIO_WRITE, in, NULL); + if (!hv_result_success(ret)) + dev_err(dev, "MMIO write hypercall error %llx addr %llx size %d\n", + ret, gpa, size); +} + /* * PCI Configuration Space for these root PCI buses is implemented as a pair * of pages in memory-mapped I/O space. Writing to the first page chooses diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index b17c6ee..fcab07b 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -168,6 +168,8 @@ struct ms_hyperv_tsc_page { #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 #define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db +#define HVCALL_MMIO_READ 0x0106 +#define HVCALL_MMIO_WRITE 0x0107 /* Extended hypercalls */ #define HV_EXT_CALL_QUERY_CAPABILITIES 0x8001 @@ -790,4 +792,24 @@ struct hv_memory_hint { union hv_gpa_page_range ranges[]; } __packed; +/* Data structures for HVCALL_MMIO_READ and HVCALL_MMIO_WRITE */ +#define HV_HYPERCALL_MMIO_MAX_DATA_LENGTH 64 + +struct hv_mmio_read_input { + u64 gpa; + u32 size; + u32 reserved; +} __packed; + +struct hv_mmio_read_output { + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; +} __packed; + +struct hv_mmio_write_input { + u64 gpa; + u32 size; + u32 reserved; + u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; +} __packed; + #endif From patchwork Fri Dec 2 03:30:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael Kelley (LINUX)" X-Patchwork-Id: 13062137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7612DC47088 for ; Fri, 2 Dec 2022 03:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232402AbiLBDfN (ORCPT ); Thu, 1 Dec 2022 22:35:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231992AbiLBDdk (ORCPT ); Thu, 1 Dec 2022 22:33:40 -0500 Received: from DM4PR02CU001-vft-obe.outbound.protection.outlook.com (mail-centralusazon11022022.outbound.protection.outlook.com [52.101.63.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F059F27168; Thu, 1 Dec 2022 19:32:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J5LjHiYA2VqmUTkBTTp7JO1G3opLxMC8aJp+5ADu7Kkeay5OCJIJUSBtbXd9q+3E7zFjXJxcTHFJMVUgZk68SG9e+jqrqn34tBmj8wE5NATqAnIJgQfzu0+fWNIDItFPi7PThl0kNJ7qyXr9fWuF1vWH83efMaKCMBZc14YPJ5WhCv7OY79nLq9L1Lp+JNICrWE+9BSQGtYfQDzDBFnO+VYKQNk3xtN2qh1cWeio4S06FlSeAQXW+l5ZY8kfqJBW+4ZTG4W52VWNzkhWab/AFgqojHrlEEltEqS0V4fWtAtEbxN5ftNCLtvNqbKH/An3FJcGtNiJZVZXFzMfvXjydA== 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=tGndZWQu3HNngqcEmna4NaG2bsukODbgQidpOqhCV9o=; b=GzwMXlvjww6lIe2KciB2ymLKsEAUc/VSwchLXg4Qw4pCmO19W0rlwQEznM6rO1DfPGfrMr9OMvXiefbvPz/BvJXkL3jORjZNdts7+NAhbsWXeV6DNB5NuDVVvllWHTg8d4OS5fFAWXmQNdf1+2uaTsk9NQitHUF72yRejo5FMQ036JTzX4y2IusRmys4wji5dSoYAC1DxDKsP0ycw8ulkFlciI/39l1WdjHDLshcKlFgBF1ns5Wb8JQg0FDYVHHrdVaHQAnkiDTwrVWkhJanL4IAmyoaTRDw1EjUM8u1Zzw3pvfVWXe/g+IjqfTRwoZEJtyVRFWrjGsizGooCTPZcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tGndZWQu3HNngqcEmna4NaG2bsukODbgQidpOqhCV9o=; b=YnfbAKKmxnGy3gdXss0wLsEYhFhE+xRMMDUH2X6GZDTcljlAjRYQM6hnw3iVbUCagAGdF7lcEmVbo2EelneGyr/RWO3HdGFSMd1ifbW/q50t/o4PS2xfkWxcdLMzXhU3M1dXaDEZCqN8XD3SSO63DfXiZ168Zc6mL4QPjB4PVV8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by DM6PR21MB1340.namprd21.prod.outlook.com (2603:10b6:5:175::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.4; Fri, 2 Dec 2022 03:32:31 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::c3e3:a6ef:232c:299b%9]) with mapi id 15.20.5901.008; Fri, 2 Dec 2022 03:32:31 +0000 From: Michael Kelley To: hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, seanjc@google.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com Subject: [Patch v4 13/13] PCI: hv: Enable PCI pass-thru devices in Confidential VMs Date: Thu, 1 Dec 2022 19:30:31 -0800 Message-Id: <1669951831-4180-14-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> References: <1669951831-4180-1-git-send-email-mikelley@microsoft.com> X-ClientProxiedBy: MW4PR04CA0234.namprd04.prod.outlook.com (2603:10b6:303:87::29) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|DM6PR21MB1340:EE_ X-MS-Office365-Filtering-Correlation-Id: 50aa3d65-8d63-47c5-26db-08dad415d7fd X-LD-Processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: reXaGvaLxRQrzRadew4MyuUK4g7qHyAtWRhe/JwPWTQ4VQl/tUnXrAv5wIxyfzfMm/MAq33r5iGmZrdpsPrnqTmW/qP3T1BiI6V2d679JaQTIj/XOFtB5NWDz9Rc7Lp8/Oafg0CK3dHLDLdlElXKzJYsNjTtXzPuj151jo4+EUmXW8rwWh1Jp9M1QHPHVXC4IPUIVP17PmXxjWWI/bTrcAyPtW+zujE2rcdbFmdSluLQz7/DwYdcsQ1SaAxZnpSuKPNOovbV7vl74HP3SGGvmjrATtsHdlyIquGObqp03oerwxQ930Tp4AIpvX/gdoIUhsJIS3kDCvnDzeYEFGti2Z3OXcaSYSvOB6SBeHKH35exlldLOU2VE1klgheMio5napyF58/ff5+ew5KfleULQy8aRmYQVHtLDJ5sWphq2OEEPNi97hEjB6Pt/UPpBJ6fYH9DWbEsE5g10nu4+7inAlMUwjGWVJTyInO791kLqODat2oqKNh7NOyO5IDjzfJqL87Rj2/7wQYDSIskibDPhM0G41a5pMIn/IVxlF4767bXcrmqe+jJ/E+OUG0CivMxXlhv/tPRw/TG+Tkl3VDC3zdktH5ATd64MVVnIYgRRFTR4FQG7zRBaNYZYb/XhGQIXAmtfeCEbcyI5Y2vB6aLEndtBkdNcSJXazjULWvBMe1uPWnMqkp9lMoqokg3qn0hEIYUC43PWtZP9jHqNgz5O58sHzNZQdkhuD4m/sivDMUz7U64QfqD8nA0UEcx7ixHQuQRDQmtu3AQrPHleyTQW6jkDVaiANawCt4SW4Ze+4g= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(136003)(396003)(39860400002)(366004)(451199015)(186003)(8936002)(8676002)(10290500003)(2616005)(107886003)(86362001)(2906002)(36756003)(7416002)(41300700001)(82950400001)(7406005)(82960400001)(66476007)(66556008)(83380400001)(66946007)(316002)(4326008)(921005)(5660300002)(966005)(52116002)(478600001)(6486002)(6506007)(38350700002)(6512007)(38100700002)(26005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Spsx7FsEZFbvF8xBh80t+EDnNYzomTV70AnCBwTz/b8y74ABGvbgLBPyFoiIf7sq5C3ad4UfJuVJWwRiGVYPauVkGJfKzghXmYiLfcT7YCCwenNLvTDLIWKvnXzIIVbyhSMCpiNActz/Vl6ORubnJEqHtKSlgIDn5pb/ABeDQU0VmjPkt6Wj7ZJuOiETzbVQdlJGHvAQez5B6yxAiH75Ef0uUeuYRuDlBBgX3orpHA77Cr87EvDerb2XmmjQ6yWzrcj6roSvel1cduizKbGU9kwHeX6OL7TdC+VuTHcSe9RFhvQ0yyj3sP7ZnB6bFsXTpX1U3pOwZywve9/wQPeMAv/GaFA78bWACqGsndQ5YsVtmRBbvT66h1QDPOVge32agrYVxqvZxpuMXNwjJVuKCow6i+37mRvIfsjL6NnQEilOdnAdKzVGG7eGyWoJjTTO1EblVReibU55lwBMivIHjcf8i40HtGvdg0Bl+VCqaYfPqGNu7mJH+2jB2y0Bbwwgd7gKWzNTyY8evMvGWgXuihlDb1zLcEPX+rAxLcRCgYNsfpmDOwKzw1TKArIEPI6eVoYva72fU2PzL5GdIzH9pWcKkXyyjY972K58Rv0lmu0bCn6PltfzZEB9vJdU7L6TtHTb6zx5aCVDd9wCQOsMvYKOmx5cpdcsy2kO4+bOZlj1+eN3xM5mO+dydAgoaa7CUDU2QQn7VwYkzFY+wrIbDreSMlQkbht62HWsEYUh1CeO104vmhzjWezRwoV65aerzsUAlh2El0+bsbLMCmXWeLVkWlhtqoR+4vwlwk+w5J+N3kN+WvcVPqwXtjWZybOS6jhx5Yfb6iREBWIEWz6HgQ8qhTKX8iIURkTvWFOv4xd0o9WdCOCBIWJcitqhViq4gA5Q9JD9udv00pdHydraKB02qrJP9OMAYqIy9BuPdxMhb0MrXYeFulZg9U2+p3ROx+n9UI3AcztEi0NL67EnPF8Hq7Nc+7U1HhmcCN5frWhufOW43iPAdZOgJhMIb2c7w7lZSbQFgJCplHjThPKe9YE03AjQSutl74mxWgIvGwPdQSljxwzgihq5o7VEe8PGQXqibOKgttlLPBUt3l6vZciWt0kuXdCAJvORAfsY0FEmponHt1AiGM03+AgINnJ/hBri0x5zQkMSIxNADmaKTasBSQE/0pdC+udnvTgjF1aANEdEMhudYiN+LxAy+xnDPH8VhCwdyOr8rZ7uOnuXZ9sWEpw5017vkIvdx7lAeRROigdwdgL41NB58DZaT8kvASbqdiaBgFTXfhWA5b7VvKS3tTc5NxcPf/LMBuWl/j3/CPe9q1v36MlzpNxfQk8Ho/XeCJY7r+V/45VQTYWENlsddh0IyyPGpu1u5bFD6LADG/f/Xqdlwx6MEjQTeHqOTnmFATdYdrNz57o38obzLBo5GY9oIUcB1Ahex9ZBBn9Isddr36IWT3oW8MJYZspurt0rRlB2WWyDdL7GPbX+J7NYRrJHAPFyJg/4rOdUpKfwK6lhZSc6Z9dsi2fTsEJMVG/4suYoPJzk+ilUZBNcbQcXa36M4O+GMS8wiqVck+RN+oE6hKkVeDD7+MnsyeJFvE2SM/GV/lrJffmBWEx+Cw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50aa3d65-8d63-47c5-26db-08dad415d7fd X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 03:32:31.1795 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iIxtsxtlCDyNbBy2cVCA7IKh/MrCUq5j/8hWQ0JY9qhkcdS/shQuIVn6VhFp0EnbrjV+EgQFHlQzBBTUS7v5EQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR21MB1340 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For PCI pass-thru devices in a Confidential VM, Hyper-V requires that PCI config space be accessed via hypercalls. In normal VMs, config space accesses are trapped to the Hyper-V host and emulated. But in a confidential VM, the host can't access guest memory to decode the instruction for emulation, so an explicit hypercall must be used. Update the PCI config space access functions to use the hypercalls when such use is indicated by Hyper-V flags. Also, set the flag to allow the Hyper-V PCI driver to be loaded and used in a Confidential VM (a.k.a., "Isolation VM"). The driver has previously been hardened against a malicious Hyper-V host[1]. [1] https://lore.kernel.org/all/20220511223207.3386-2-parri.andrea@gmail.com/ Co-developed-by: Dexuan Cui Signed-off-by: Dexuan Cui Signed-off-by: Michael Kelley Reviewed-by: Boqun Feng --- drivers/hv/channel_mgmt.c | 2 +- drivers/pci/controller/pci-hyperv.c | 168 ++++++++++++++++++++++-------------- 2 files changed, 105 insertions(+), 65 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index cc23b90..007f26d 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -67,7 +67,7 @@ { .dev_type = HV_PCIE, HV_PCIE_GUID, .perf_device = false, - .allowed_in_isolated = false, + .allowed_in_isolated = true, }, /* Synthetic Frame Buffer */ diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index bbe6e36..f874f89 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -514,6 +514,7 @@ struct hv_pcibus_device { /* Highest slot of child device with resources allocated */ int wslot_res_allocated; + bool use_calls; /* Use hypercalls to access mmio cfg space */ /* hypercall arg, must not cross page boundary */ struct hv_retarget_device_interrupt retarget_msi_interrupt_params; @@ -1123,8 +1124,10 @@ static void hv_pci_write_mmio(struct device *dev, phys_addr_t gpa, int size, u32 static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where, int size, u32 *val) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + int offset = where + CFG_PAGE_OFFSET; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; /* * If the attempt is to read the IDs or the ROM BAR, simulate that. @@ -1152,56 +1155,79 @@ static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where, */ *val = 0; } else if (where + size <= CFG_PAGE_SIZE) { - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); - /* Choose the function to be read. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start reading. */ - mb(); - /* Read from that function's config space. */ - switch (size) { - case 1: - *val = readb(addr); - break; - case 2: - *val = readw(addr); - break; - default: - *val = readl(addr); - break; + + spin_lock_irqsave(&hbus->config_lock, flags); + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + offset; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(dev, addr, size, val); + } else { + void __iomem *addr = hbus->cfg_addr + offset; + + /* Choose the function to be read. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before reading. */ + mb(); + /* Read from that function's config space. */ + switch (size) { + case 1: + *val = readb(addr); + break; + case 2: + *val = readw(addr); + break; + default: + *val = readl(addr); + break; + } + /* + * Make sure the read was done before we release the + * spinlock allowing consecutive reads/writes. + */ + mb(); } - /* - * Make sure the read was done before we release the spinlock - * allowing consecutive reads/writes. - */ - mb(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, - "Attempt to read beyond a function's config space.\n"); + dev_err(dev, "Attempt to read beyond a function's config space.\n"); } } static u16 hv_pcifront_get_vendor_id(struct hv_pci_dev *hpdev) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + u32 val; u16 ret; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + - PCI_VENDOR_ID; - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); + spin_lock_irqsave(&hbus->config_lock, flags); - /* Choose the function to be read. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start reading. */ - mb(); - /* Read from that function's config space. */ - ret = readw(addr); - /* - * mb() is not required here, because the spin_unlock_irqrestore() - * is a barrier. - */ + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + + CFG_PAGE_OFFSET + PCI_VENDOR_ID; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_read_mmio(dev, addr, 2, &val); + ret = val; /* Truncates to 16 bits */ + } else { + void __iomem *addr = hbus->cfg_addr + CFG_PAGE_OFFSET + + PCI_VENDOR_ID; + /* Choose the function to be read. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before we start reading. */ + mb(); + /* Read from that function's config space. */ + ret = readw(addr); + /* + * mb() is not required here, because the + * spin_unlock_irqrestore() is a barrier. + */ + } - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); return ret; } @@ -1216,39 +1242,51 @@ static u16 hv_pcifront_get_vendor_id(struct hv_pci_dev *hpdev) static void _hv_pcifront_write_config(struct hv_pci_dev *hpdev, int where, int size, u32 val) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct device *dev = &hbus->hdev->device; + int offset = where + CFG_PAGE_OFFSET; unsigned long flags; - void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; if (where >= PCI_SUBSYSTEM_VENDOR_ID && where + size <= PCI_CAPABILITY_LIST) { /* SSIDs and ROM BARs are read-only */ } else if (where >= PCI_COMMAND && where + size <= CFG_PAGE_SIZE) { - spin_lock_irqsave(&hpdev->hbus->config_lock, flags); - /* Choose the function to be written. (See comment above) */ - writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); - /* Make sure the function was chosen before we start writing. */ - wmb(); - /* Write to that function's config space. */ - switch (size) { - case 1: - writeb(val, addr); - break; - case 2: - writew(val, addr); - break; - default: - writel(val, addr); - break; + spin_lock_irqsave(&hbus->config_lock, flags); + + if (hbus->use_calls) { + phys_addr_t addr = hbus->mem_config->start + offset; + + hv_pci_write_mmio(dev, hbus->mem_config->start, 4, + hpdev->desc.win_slot.slot); + hv_pci_write_mmio(dev, addr, size, val); + } else { + void __iomem *addr = hbus->cfg_addr + offset; + + /* Choose the function to write. (See comment above) */ + writel(hpdev->desc.win_slot.slot, hbus->cfg_addr); + /* Make sure the function was chosen before writing. */ + wmb(); + /* Write to that function's config space. */ + switch (size) { + case 1: + writeb(val, addr); + break; + case 2: + writew(val, addr); + break; + default: + writel(val, addr); + break; + } + /* + * Make sure the write was done before we release the + * spinlock allowing consecutive reads/writes. + */ + mb(); } - /* - * Make sure the write was done before we release the spinlock - * allowing consecutive reads/writes. - */ - mb(); - spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); + spin_unlock_irqrestore(&hbus->config_lock, flags); } else { - dev_err(&hpdev->hbus->hdev->device, - "Attempt to write beyond a function's config space.\n"); + dev_err(dev, "Attempt to write beyond a function's config space.\n"); } } @@ -3627,6 +3665,7 @@ static int hv_pci_probe(struct hv_device *hdev, hbus->bridge->domain_nr = dom; #ifdef CONFIG_X86 hbus->sysdata.domain = dom; + hbus->use_calls = !!(ms_hyperv.hints & HV_X64_USE_MMIO_HYPERCALLS); #elif defined(CONFIG_ARM64) /* * Set the PCI bus parent to be the corresponding VMbus @@ -3636,6 +3675,7 @@ static int hv_pci_probe(struct hv_device *hdev, * information to devices created on the bus. */ hbus->sysdata.parent = hdev->device.parent; + hbus->use_calls = false; #endif hbus->hdev = hdev;