Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp198209rdb; Mon, 15 Jan 2024 18:21:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IElejCxgHe6wNhq1wQaq+TjAuQQ7c3wXvNcvdk6x3QHLWUxESbXZ6QVXIZemeMKFTN+2qjH X-Received: by 2002:ad4:5c89:0:b0:681:1adc:7bb5 with SMTP id o9-20020ad45c89000000b006811adc7bb5mr8800152qvh.120.1705371680335; Mon, 15 Jan 2024 18:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705371680; cv=none; d=google.com; s=arc-20160816; b=iaC5z+RsLG7U9aOueJg2uzrQVoBMFKHUGfexlAtUnx+A3O7zRos42FeQX0v3xCgfzv DDgkZeQkWj/V7rGxBXbIskFNyWiPU8VeRR3JzzsvkwcB8xLQ6Xt35OJX7mozjZ8/d6N5 dOIh9g0+8VrNQkgZdpGmKG96r2hRUjIn4WD/TP38tZS+bbmJd0s4ieyaQVEdT4Dv6NOl Oa+fSu/tSJW+9c5BWcu65wvw70698CujkL2SmtVWVLNonLotVzFmX3DH3lVBatBZcur5 LwrvfwAkaLrkJycXV30Hb3KK9D6enkQnblgy68r+xeWZm3zm9uip3PrdneYGRZPw8ybF 2SWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=WMHKxJ/T5Ct44oYlSE+LYrzOvXToXwBp+RoVB/ApQnM=; fh=NIsPzUZjaJ3tPkVc3BtGzQZbr06zzzUFoB+mXYLA6CI=; b=Dpx+cXx+A98vEVILYhHfxwmMGNXwjq4Tnw6vGzNTGqEqUKXI2ClJGh4JlVDZAD6FUI 5GJa6upUiZwR+7wF1nqUB4J9D0Y7IU0H/j4C+/PfOsCtjf7q9DG/JJVdjvQDsABUkLp9 9QnFkiWxq9hDtKo1T3xSOb1YMJy78vxe2/nKufoavqiCvgQb6KqHGXRsNQk/TMMLTLXa vMgaOAYjh+MvZu3LwOcbldiRPzkbODInPeOg7Fd4qOdOx/xDnK5Pc27UO0GsMFjFP78h ebTf13TvXpP9pyj9LfsxKEBHDHPp/3ZNURrTGtff4czJvmhGSnx6mOMhk5pw806zZc6i 64Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZCykdmhL; spf=pass (google.com: domain of linux-kernel+bounces-26927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26927-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o10-20020a0c8c4a000000b0067a8bf10affsi9172559qvb.220.2024.01.15.18.21.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 18:21:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZCykdmhL; spf=pass (google.com: domain of linux-kernel+bounces-26927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26927-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1C1601C22758 for ; Tue, 16 Jan 2024 02:21:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2900B8C11; Tue, 16 Jan 2024 02:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZCykdmhL" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ACA529AD; Tue, 16 Jan 2024 02:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d5dfda4319so2686595ad.0; Mon, 15 Jan 2024 18:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705371630; x=1705976430; darn=vger.kernel.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=WMHKxJ/T5Ct44oYlSE+LYrzOvXToXwBp+RoVB/ApQnM=; b=ZCykdmhLScgfeqb281iOMeUrZMW4PUe2S+xqz/V10DHHmGI+QWxsmEY6eHMIErddtC SquMAIRSHz9auI0PWAOyfZ9g2GqO2TtBDhE06EvyEU0+mbCZj7QwVxRWXVAks91dN41b 5dElEkitgj1l5QFdfB8VsT/173ACtlBN2PnP3v0Gb0KL7dBO2GLDhrxiqlwlV30tjjjn G+BjUgKIlEeXNb34BHZO/dyjjmCoWoDjfdyR6Wf2ipQnjfI8mmob8vtvhu0oaNrPxD6H xnt/iUg9uFHBvC6I0+IptHhEMMFep73VdkmRNlVVGaulGjbnyEPaKL/xwAehdiAbAXNq eByw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705371630; x=1705976430; 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=WMHKxJ/T5Ct44oYlSE+LYrzOvXToXwBp+RoVB/ApQnM=; b=sNAvadX+4ztSUX1+veRcMetXfB6jkVy1nTouuHODuLMiVCD/bBTopPm2827YwQWxif QlU5gx7M6eJhKHot5qKFannoXAdackSW95Zdolqf+q2eatsHciiRcacwUmGZjkqIndB+ cx6D63l0HUi8N4OYbhlNhGHkS3Q/KFVup0N2E7xENvy6E91Gewj+5FfIU+af+oXVsZ8O H9h/oresRuzjO6IGj9v9YrKGZyiwWxw0IIV2B6I41nTeW7ZqfC5nGbnzuzZ08HtopJpF cWxIpS3SV8ruzefBIJImfX1Lfo2duu5rhAEezl1vPVlvyqFO7DnGX2m3k9AhdkUdmhUi kefQ== X-Gm-Message-State: AOJu0YyfRLiZuKgE1bGkwbDtI2arpyMPwxreQpLR8KRtxWwJq3DDQb13 sL12w/VGCR1kBR3oCWTWUBg= X-Received: by 2002:a17:903:2808:b0:1d4:75c6:9560 with SMTP id kp8-20020a170903280800b001d475c69560mr2742635plb.59.1705371630377; Mon, 15 Jan 2024 18:20:30 -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 kn14-20020a170903078e00b001d1d1ef8be5sm8193379plb.173.2024.01.15.18.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 18:20:30 -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, 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 v4 1/3] x86/hyperv: Use slow_virt_to_phys() in page transition hypervisor callback Date: Mon, 15 Jan 2024 18:20:06 -0800 Message-Id: <20240116022008.1023398-2-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240116022008.1023398-1-mhklinux@outlook.com> References: <20240116022008.1023398-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 callback. 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 | 12 +++++++++++- arch/x86/mm/pat/set_memory.c | 12 ++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 02e55237d919..851107c77f4d 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -515,6 +515,8 @@ static bool hv_vtom_set_host_visibility(unsigned long kbuffer, int pagecount, bo enum hv_mem_host_visibility visibility = enc ? VMBUS_PAGE_NOT_VISIBLE : VMBUS_PAGE_VISIBLE_READ_WRITE; u64 *pfn_array; + phys_addr_t paddr; + void *vaddr; int ret = 0; bool result = true; int i, pfn; @@ -524,7 +526,15 @@ 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. + */ + vaddr = (void *)kbuffer + (i * HV_HYP_PAGE_SIZE); + paddr = slow_virt_to_phys(vaddr); + pfn_array[pfn] = paddr >> HV_HYP_PAGE_SHIFT; pfn++; if (pfn == HV_MAX_MODIFY_GPA_REP_COUNT || i == pagecount - 1) { diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index bda9f129835e..e76ac64b516e 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -755,10 +755,14 @@ 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. + * Note that as long as the PTEs are well-formed with correct PFNs, this + * works without checking the PRESENT bit in the leaf PTE. This is unlike + * the similar vmalloc_to_page() and derivatives. Callers may depend on + * this behavior. + * + * 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