From patchwork Fri Aug 9 16:09:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13758935 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 5A7DAC52D7C for ; Fri, 9 Aug 2024 16:09:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 940296B00AB; Fri, 9 Aug 2024 12:09:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EF966B00AC; Fri, 9 Aug 2024 12:09:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71E396B00AD; Fri, 9 Aug 2024 12:09:43 -0400 (EDT) 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 4DB7D6B00AB for ; Fri, 9 Aug 2024 12:09:43 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0CD6212117E for ; Fri, 9 Aug 2024 16:09:43 +0000 (UTC) X-FDA: 82433192646.05.CA91536 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 00C042002B for ; Fri, 9 Aug 2024 16:09:40 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YPhU4q7v; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723219732; a=rsa-sha256; cv=none; b=gHpxqasm2At56Gptgx1nX62hxJkou6hR1Xkz4xxZ242DZ84nqU8Iy6yknCYh6zDupWEJ2M Uo+kqRB2bi4WJ963t17rx4qnJrFQSaQk0K95Nqry4fQG9GNJ+wJAVifRQG/bOy8UT5/9wx EY2tWGRHUTyuX0aZu/XwcwHTfpIQOhM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YPhU4q7v; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723219732; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XgMG3z25w/FU4W74BEAmfGyy8QhkBSj3TNUPa/vYriM=; b=FQKhaftHAnj/rJkn11t2iu77Lypbby+gtMjrzry2b9JFi53JMv9fPUpMbC4fKzUKnM3Jir N16FQ5it9g2koqQ5ZKlb3XNwm3GDVWhY7EMUnwUuRxotAeXKlPyKEhI1MAlSgkd+qE7Q4D 2c5ijApKfz+hJnQH9/R5umwvQC8QDmg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723219780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XgMG3z25w/FU4W74BEAmfGyy8QhkBSj3TNUPa/vYriM=; b=YPhU4q7vBmE+shzeD+qcwbh8e578X+hGr3vuwNeBm5qYqMxsMBnME+zKlxZN7JnCarnqL2 yTKc1TIdFJl2CKURUSHheXT3gTeIMavlJlMCO1vMsS7VtZKDZ4ZLtL6g1VrU9fF135a2D6 YhTZ1Ot52w7rd8XGzCds6VOcOi3H04U= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-F6oSDlBEMLS1mxBgvznuag-1; Fri, 09 Aug 2024 12:09:39 -0400 X-MC-Unique: F6oSDlBEMLS1mxBgvznuag-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6b7a47a271cso6056356d6.2 for ; Fri, 09 Aug 2024 09:09:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723219778; x=1723824578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XgMG3z25w/FU4W74BEAmfGyy8QhkBSj3TNUPa/vYriM=; b=sc8wJxr1ZOA/mllAaTIYMC+6QPVZSnRxOa4Xveq4jzQrvj8cSUrHA8NYEOFXurZAHH 3SLlUV7GAzfALiwYlP9rwJX2PRQIbuiEC7hSu61sSsqtctZwte+XNl0zpoRGe1gNNjj/ qAaahfhH7ASQviQqVMP8wJGqEjVFdJpivtOqTS+ZJr40Uq/+CaIzeFJigFJhK7DKV/3n EB2Q0X+67+lCv09AQ9Y/2wL8zSL1Exd8Og7SpnFRelrR2kq7cYXV4D70qI5GCcY2N93I Oq4fbHbqdJ1LflI1LC7pGI3KkjVmG9FJnEMwgVexqyzAs5kA3CuETqtd36dGHMWQLkkn kSuA== X-Gm-Message-State: AOJu0YxB7YHCOBqELVhz8WCrjwKulP//lpKmDsvfM86sRuP76EQNhSQG YRjyn9L7PsTGX24WO4d2iY+Wy0U0aObcMEJjJCZigFDqS47npysBk3b6HWai7m8CdmFy0HrjHoX rQ2FioOLY2d8B5zMEbl5mddzKw/sgGW9tsjHUN0lyWTijhKtHpvhfqu0EMtm0awRWV/fPisQmlQ vqRu+uEyHBFMBVbXsGC3LHV/5G1f67yVwe X-Received: by 2002:ac8:5dd3:0:b0:447:dfa0:283e with SMTP id d75a77b69052e-4531251fe34mr11225581cf.1.1723219778067; Fri, 09 Aug 2024 09:09:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6MoN+Dd8Hdt5Y2cXuQIqSY6AztxI8VpmGorOFfK4YC2KlFlbKhz5m1DVHT1NSvONycoblfw== X-Received: by 2002:ac8:5dd3:0:b0:447:dfa0:283e with SMTP id d75a77b69052e-4531251fe34mr11225161cf.1.1723219777518; Fri, 09 Aug 2024 09:09:37 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-451c870016csm22526741cf.19.2024.08.09.09.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 09:09:36 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , Oscar Salvador , Jason Gunthorpe , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, peterx@redhat.com, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , David Hildenbrand , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao Subject: [PATCH 10/19] KVM: Use follow_pfnmap API Date: Fri, 9 Aug 2024 12:09:00 -0400 Message-ID: <20240809160909.1023470-11-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240809160909.1023470-1-peterx@redhat.com> References: <20240809160909.1023470-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 00C042002B X-Rspam-User: X-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oQG69yC+2sICpx2Vdyk2QrjXVm5WKn27UZdh5BJNgnxccvnHYiyTQ1Iw4Q1tVgibE8/h9lOfniAsJByUZCXOtUqV7acOGA90LzRQA41Dh5gQPVnUJN9mZq/bPQcHFBMpG1J6I4QC0TZ5jiEPga41KVnvKufu+tsiEuFCXz86KiocFVi1z/QYm55pLA4yDYANx1n/8n7BHXDY6+4wTZKl9q5NCfWA1OKL327fqhZ0q9+NHA8M4Z1pH2b9cEqSlVGb6GLNsLNisKj4DOc+IYIP4yh0exVoIHkaUm+wAn41wPsP0C+gDs7v43/Wf4IRizIRznBBVj+6Ac0s0KzXbKY5ZORnlHvApERR9wBa1dqaNdTU2zEitxJz0JKOYenPDGs9JHTMs7AABUW8TPF1fNu8u7L1cTou8BDOBdl9Wj1lFOurOlo60IjaridTQo+CE7BdJvrl1A9PFueY1chrlArTe9KxEkg5/SBeV8= 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: Use the new pfnmap API to allow huge MMIO mappings for VMs. The rest work is done perfectly on the other side (host_pfn_mapping_level()). Cc: Paolo Bonzini Cc: Sean Christopherson Signed-off-by: Peter Xu --- virt/kvm/kvm_main.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d0788d0a72cc..9fb1c527a8e1 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2862,13 +2862,11 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, unsigned long addr, bool write_fault, bool *writable, kvm_pfn_t *p_pfn) { + struct follow_pfnmap_args args = { .vma = vma, .address = addr }; kvm_pfn_t pfn; - pte_t *ptep; - pte_t pte; - spinlock_t *ptl; int r; - r = follow_pte(vma, addr, &ptep, &ptl); + r = follow_pfnmap_start(&args); if (r) { /* * get_user_pages fails for VM_IO and VM_PFNMAP vmas and does @@ -2883,21 +2881,19 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, if (r) return r; - r = follow_pte(vma, addr, &ptep, &ptl); + r = follow_pfnmap_start(&args); if (r) return r; } - pte = ptep_get(ptep); - - if (write_fault && !pte_write(pte)) { + if (write_fault && !args.writable) { pfn = KVM_PFN_ERR_RO_FAULT; goto out; } if (writable) - *writable = pte_write(pte); - pfn = pte_pfn(pte); + *writable = args.writable; + pfn = args.pfn; /* * Get a reference here because callers of *hva_to_pfn* and @@ -2918,9 +2914,8 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, */ if (!kvm_try_get_pfn(pfn)) r = -EFAULT; - out: - pte_unmap_unlock(ptep, ptl); + follow_pfnmap_end(&args); *p_pfn = pfn; return r;