From patchwork Tue Jan 16 02:20:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 13520331 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 61D5DC47422 for ; Tue, 16 Jan 2024 02:20:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09D5D6B0075; Mon, 15 Jan 2024 21:20:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 050736B007B; Mon, 15 Jan 2024 21:20:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0E556B0078; Mon, 15 Jan 2024 21:20:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AA8986B0075 for ; Mon, 15 Jan 2024 21:20:33 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7ABCBC01A2 for ; Tue, 16 Jan 2024 02:20:33 +0000 (UTC) X-FDA: 81683570346.17.41FFB90 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf06.hostedemail.com (Postfix) with ESMTP id 90D7D180007 for ; Tue, 16 Jan 2024 02:20:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AWwP+PGK; spf=pass (imf06.hostedemail.com: domain of mhkelley58@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=mhkelley58@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705371631; a=rsa-sha256; cv=none; b=X71AUkFk83msbMc/PaFFW1oTIgMO0PfcsYa7lfTV6xgxZEc9LXDChRl2c9U5p4PbrtryFh S8Z9Mtn0TfIJ4E8qw6lzyrMx7sGAbOwLHAKtzcR1zeAXKczsjja4HzkXr7t8rz4DvhLfQQ vRqVZNrbgaQmBGDUSuwBZByI5ddz6F4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AWwP+PGK; spf=pass (imf06.hostedemail.com: domain of mhkelley58@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=mhkelley58@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705371631; 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=WMHKxJ/T5Ct44oYlSE+LYrzOvXToXwBp+RoVB/ApQnM=; b=afns1U1TahlzvPugmHNejrIhe1ZAukdg8FKEXkK2Tc63XXR7p6SbnUy/xBlatMUGuOsWnv 1qtpKEYMGr2I75ILydylFuYG9P+N9LDAI9PM2fqZ9FgMrkl92AKH7wCuHAV09ngsHLDwPb N2IPhWvMgx7VyMc9dslA2jnNo0j68Zo= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d3f29fea66so51625425ad.3 for ; Mon, 15 Jan 2024 18:20:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705371630; x=1705976430; 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=WMHKxJ/T5Ct44oYlSE+LYrzOvXToXwBp+RoVB/ApQnM=; b=AWwP+PGKD6idvzBPJF9D2gsIQTKNMUFvQFzk4P+ExbCPd99IE97DKPCg1L6RlEgCNH /PhxeTtJ80yVokxqd1AFXu19zZ/iR/tTpiliSxSw6MShy6LXLRdZheD+byl48O1EsjRd UNLupCELWSuEuBhONf8umfHr4adISKPIMBR6xUoYMUwmX8DA9dYqixI2ivKkKuCLWpiv 8Q7VDjFr5vPGdA7Pe49FVMO3h9ommiAzhkxs8MqA/UwpRUDBj8bhhtSmiv65psQTRGTc kaR61LP6rOtGNOZUjzl9w9gprQuWV8WQlTxIz8x4X4yNhdzudydmta8izkbnvM5iP7WO qA2Q== 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=n6V8oGgtdgTL1UXWWXK5VDQ8xeUgRNiYjw4UTJ+6SejW9+JAV3VtZjhgMjYdMtG3xD pa4COHUGG0ajNdho7gMQC5O1zSrEIewmMVi3ualkIIpArMzdch5KA4D94ade24tNlBN3 hLoJ3QwhAcJ3Rryz4OvhgHJtTYHTvYA48Bq5S44AV8vJoHu7XE9yWLDGkB07wG1O35HF DDWrdavduMDFum0bcilU0FND+5YbUAwoZ23M5Q1cSIgUiGcDy0UQfeeOoKY+qmCzZuKt y8hGaXyE9bol5PaQN5Ujd9qsnbx4BwBXulxjYqy0qCFB0vfCwVuKFRBkFm5U14U/i0sB TgNw== X-Gm-Message-State: AOJu0YyhOjMPvYUpPXR17UzFgoL2VJLZ05aOvhzSrbuMuMiPrFuUzPaJ 3jjnYL3jW7QXu1JuLcGWhmA= X-Google-Smtp-Source: AGHT+IGKhIpxJK9risAw80iB9x8SFXIfFEzqHrHFHgbziciGN/6OZbZls+x7EV8Jy+UwtVv+JbHLlQ== 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 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 90D7D180007 X-Stat-Signature: odqbw4oybmz63eunsnpwyfk14xbfamue X-Rspam-User: X-HE-Tag: 1705371631-978175 X-HE-Meta: U2FsdGVkX1/0M/AzSq3tM+E0kMzhcujR/KWH8ggF0zwSwjOMzJYIjyIVumNX6ScrstakpMBeBvoWF0TiNcQ5qiw4p5skzp1I/56+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LPcaIz5GmLNv3E10/UtgbdQx0F42hCX79wmatJVGDjE4u/AgOs3wNkVUZ84tAH/v+gx+J5TXGIY/ZHTlGZMc84P15ChlYC3Xj3nSpc7ml5Ax+oR8ER10MojCT3OciiAULtn2NyH6qQHbfTdVbq9YYnzcB5E0wx0R5sKkyNVf+t7ZDCxjXslUMV8zIJoIYzcpmpCOwF5NmnOrbSnPWv5LkY3e90Me/Y7s21UaN4x+vRrEwDXO8j1SNQfUgD+H087kZ2tii38aQKJ9sOQFC5A+FCGmafU43bHPo7prK1mEEoVty9wz907z277D+zStEegosujjazDptpyNaCmD//TBxIRp8Qjc3MRp4/jeLE34GIYqpmoQGU2WXyxgspFF6bJy03qiB2q7xG6agM/hpIYXs/uLHMGNHL+uncUm+mbPPVA9oVBjDFhlbadLMZAmwKzyeeMjRzvcYoA== 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 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 Reviewed-by: Rick Edgecombe Acked-by: Kirill A. Shutemov --- 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) {