From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D156C61D85 for ; Tue, 21 Nov 2023 21:20:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEBCF6B0461; Tue, 21 Nov 2023 16:20:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C740D6B0464; Tue, 21 Nov 2023 16:20:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B142B6B046F; Tue, 21 Nov 2023 16:20:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 81F0E6B0464 for ; Tue, 21 Nov 2023 16:20:38 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 631041604EC for ; Tue, 21 Nov 2023 21:20:38 +0000 (UTC) X-FDA: 81483230556.14.E2A2722 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf11.hostedemail.com (Postfix) with ESMTP id 2B20A4001E for ; Tue, 21 Nov 2023 21:20:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Sh6XPXEY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of mhkelley58@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=mhkelley58@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700601635; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rbfDwkGJGwxULqg8ltFjMn30Y46reH21KWF1N/yir7w=; b=Pb0lXKInF4xhUBr6RDbMuIZik0MsDVBhzXjit8deNrJQR4oV2zfte/MsMZ57SIK6kQjb3s dGumgEe0mHfVByDdosJmsa1CX09/mLDXEiHcazlmAq6xAgI15qO+bsTtN4wfleqLL6OdqZ yNDLI5b7m6O55YRN8GNLIvG4nEHcINY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Sh6XPXEY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of mhkelley58@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=mhkelley58@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700601635; a=rsa-sha256; cv=none; b=LjVLRwxG4PEa03blVHxg0gObd21+fvvDEC3RY//eGh3v307AnbsUF119n91EnJOWe3ugsm p1KPgVTWa2uB419WzEk19RYvISaYsgDLwRhY8UZGAievCIK3ERzdWmbLI5XF01nTLFAIxT 08+G6ECMF+cXv/xgVHCB4ty6QzADc9I= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1ce95f96edcso25961985ad.0 for ; Tue, 21 Nov 2023 13:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700601634; x=1701206434; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rbfDwkGJGwxULqg8ltFjMn30Y46reH21KWF1N/yir7w=; b=Sh6XPXEY40TqhHPtYmmyMWBx5IapYbjbEAplyuRmjqSpJ2Tur025WGwZnQ1tnfyxUm +nPDSfi07sM1zIUKvPaP+tJ5fBzsA4N2M46anJxzeRNu3HY0XtxsLT6MTDzJhdDEy4oY uhvGVPaE6NdkXfrQ1tbyDViKvlqCFxqFH/0ekDy8JZwwlDIbn4+oNcoheBEBe1CROExk qE9IsYxRvKEb9aRtIhsBIrLxr/BSfs+oksho6i83ByXz3Z9C7BrjRUzBjo5Hi+w1kDiE /xLt+fq2DSAQ/3IpbyxgHkwCuEl4NwIWhScOIi4hfRIu3AHg1Fc2H7Dh4cYvjTTVzRAr BMEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700601634; x=1701206434; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rbfDwkGJGwxULqg8ltFjMn30Y46reH21KWF1N/yir7w=; b=MIshGndP86lhtQIkvT6yuns6ciX3a0EgbHBR73CBNEmy+cv78xblwreHocKE+x3sR+ QExkTxvotvzM+53o1BSk/GYASIt7PivJ4fAG0IhyL4gFdNqKR27j9jo3VxXCezWG4feH xnfJVVdQkIjQhQIgJ10j1xmSF1+nthSq7Z6DL7athUWcGoE+MaZojK2vFeJKIBRKXCMx MetFo4hli0XwAHPtKZduVsQXlaTXdsa5H07y/prvo5/65JKI7+KPcrg838DUAQdeaZS6 9qBsKmdgO3MC3KW3W2+BQG9MOjMCbRV2gLCWukIE6kKUyvHBf85E7Ag6465hTEiAJaII 5fuQ== X-Gm-Message-State: AOJu0YxKEAkWpowTdRI2TQ3cCDTnqZ/LWMmI6hYNWLnT9MqVpNQ8KOs1 6Z0ZapcJ/V0PwijYiodlhcw= X-Google-Smtp-Source: AGHT+IEOsjamSGHkOASGUCwZPWO7OmI3DBmh+Jjr7fpstRfuOke2KTseFR9lGErT7CmT9qeaxU040A== X-Received: by 2002:a17:903:32c1:b0:1cf:6656:69cf with SMTP id i1-20020a17090332c100b001cf665669cfmr467098plr.21.1700601634054; Tue, 21 Nov 2023 13:20:34 -0800 (PST) Received: from localhost.localdomain (c-73-254-87-52.hsd1.wa.comcast.net. [73.254.87.52]) by smtp.gmail.com with ESMTPSA id j2-20020a170902758200b001bf52834696sm8281924pll.207.2023.11.21.13.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 13:20:33 -0800 (PST) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kirill.shutemov@linux.intel.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, thomas.lendacky@amd.com, ardb@kernel.org, jroedel@suse.de, seanjc@google.com, rick.p.edgecombe@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, linux-hyperv@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 1/8] x86/coco: Use slow_virt_to_phys() in page transition hypervisor callbacks Date: Tue, 21 Nov 2023 13:20:09 -0800 Message-Id: <20231121212016.1154303-2-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121212016.1154303-1-mhklinux@outlook.com> References: <20231121212016.1154303-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 2B20A4001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5uo14radq6m1fccb7cjdsh7az53hjham X-HE-Tag: 1700601634-905407 X-HE-Meta: U2FsdGVkX1/qRCYmgSw0Rn03Y4bO3sRuFfZeoV/Xfy3BzFjaBzLQTTTr2jfWImUxNz9oTwG70tvyGM+CWOXf6uwqmF/iL4oZEEV7IIGzXh2iRk/DiOHwISUjVpk2TF8Apy5CMYiOkXuRea37QSLa2nLQfhb7oKu9fLBhTVoTnHtVLG/GJCql1YoPKpkZ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QYxBwbDMGtU4VcKv4dSEVldp7v7gpeC08ktzZH1m8D807SXLKP0/vBPjoLFJ1LlaGbiowtsiq5cEuPNwpyz6taaRuoxIR1mzCTWrKtrIOh9j3BgdbkLh5UKo9sT5IYhVDoW920W8r6gt/mvkzm+njIbKWlf1pTJqCDwSYjQQYwtcMSUrfrNMM0RcLtlYh4Pzhzmo5VbjxCw+M5EfLTjlJ/NNhQre/BOZE5FxNyodv1+vVTpnxK+/A5hCjOy5r4Wb9Rom04hNhvmrw1tGohCSUZCXuE5GvySu9reDgJXFrv9rtCDXJncsjxQRlfGGjvfm8JX+uh1/Ym3miJ9lJf5FD1KJMnR+Z/Zn5pe98x3W3lokfQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Michael Kelley In preparation for temporarily marking pages not present during a transition between encrypted and decrypted, use slow_virt_to_phys() in the hypervisor callbacks. As long as the PFN is correct, slow_virt_to_phys() works even if the leaf PTE is not present. The existing functions that depend on vmalloc_to_page() all require that the leaf PTE be marked present, so they don't work. Update the comments for slow_virt_to_phys() to note this broader usage and the requirement to work even if the PTE is not marked present. Signed-off-by: Michael Kelley --- arch/x86/hyperv/ivm.c | 9 ++++++++- arch/x86/kernel/sev.c | 8 +++++++- arch/x86/mm/pat/set_memory.c | 13 +++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 02e55237d919..8ba18635e338 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -524,7 +524,14 @@ static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bo return false; for (i = 0, pfn = 0; i < pagecount; i++) { - pfn_array[pfn] = virt_to_hvpfn((void *)kbuffer + i * HV_HYP_PAGE_SIZE); + /* + * Use slow_virt_to_phys() because the PRESENT bit has been + * temporarily cleared in the PTEs. slow_virt_to_phys() works + * without the PRESENT bit while virt_to_hvpfn() or similar + * does not. + */ + pfn_array[pfn] = slow_virt_to_phys((void *)kbuffer + + i * HV_HYP_PAGE_SIZE) >> HV_HYP_PAGE_SHIFT; pfn++; if (pfn == HV_MAX_MODIFY_GPA_REP_COUNT || i == pagecount - 1) { diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 70472eebe719..7eac92c07a58 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -811,7 +811,13 @@ static unsigned long __set_pages_state(struct snp_psc_desc *data, unsigned long hdr->end_entry = i; if (is_vmalloc_addr((void *)vaddr)) { - pfn = vmalloc_to_pfn((void *)vaddr); + /* + * Use slow_virt_to_phys() because the PRESENT bit has been + * temporarily cleared in the PTEs. slow_virt_to_phys() works + * without the PRESENT bit while vmalloc_to_pfn() or similar + * does not. + */ + pfn = slow_virt_to_phys((void *)vaddr) >> PAGE_SHIFT; use_large_entry = false; } else { pfn = __pa(vaddr) >> PAGE_SHIFT; diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index bda9f129835e..8e19796e7ce5 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -755,10 +755,15 @@ pmd_t *lookup_pmd_address(unsigned long address) * areas on 32-bit NUMA systems. The percpu areas can * end up in this kind of memory, for instance. * - * This could be optimized, but it is only intended to be - * used at initialization time, and keeping it - * unoptimized should increase the testing coverage for - * the more obscure platforms. + * It is also used in callbacks for CoCo VM page transitions between private + * and shared because it works when the PRESENT bit is not set in the leaf + * PTE. In such cases, the state of the PTEs, including the PFN, is otherwise + * known to be valid, so the returned physical address is correct. The similar + * function vmalloc_to_pfn() can't be used because it requires the PRESENT bit. + * + * This could be optimized, but it is only used in paths that are not perf + * sensitive, and keeping it unoptimized should increase the testing coverage + * for the more obscure platforms. */ phys_addr_t slow_virt_to_phys(void *__virt_addr) { -- 2.25.1