From patchwork Thu Oct 10 18:24:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 1995820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Jy70mVil; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=alq1Gi8I; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XPkcg6rSmz1xsc for ; Fri, 11 Oct 2024 09:16:35 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Z4JarTIHnSZeEyh0hmUFaTICNHBXHcC6FxeWhz7zdBQ=; b=Jy70mVilYziR96 LibUMP1SQ4TXvflH4MELDGWEhvAhzw2U+OGpqQrcHkQJCeTgXLTUsLpEHavajeTGFP5B4bCBGisY1 y8lFMYNZjpzMhWVniDRSB4KIwIAR1bZkYsGPmjCY5vdvoz6Q3DZb0qr+GvIBhig6cWL7A9a0nHUeC i1dz11xdXhy1HIxunIGID0zGWq2Mriuw0DG5oDOzzl6dx9ieXAZpdAsqA5gW4BgrLLEn6fakBC89+ J2S8gJFKfJxYY998PelnPpxhv9+J1gTJhs3ZC7zpJ0LX04JJ4lt+EsQXmnAv3QjtMnqMsa+eqJvU1 ER4IdgsvqBTs/DmMoAGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sz1SU-0000000EVxw-2VSB; Thu, 10 Oct 2024 22:16:34 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syxsv-0000000Drlv-04rG for kvm-riscv@lists.infradead.org; Thu, 10 Oct 2024 18:27:38 +0000 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-7e9b2d75d6dso895811a12.1 for ; Thu, 10 Oct 2024 11:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728584856; x=1729189656; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:from:to:cc:subject:date :message-id:reply-to; bh=04eHUk6AClz9cRMQcjlWjE46ZR1uXceY2ogFB00LGDM=; b=alq1Gi8IKHXoRenVXYXecNt3KC/lj7CRLd4Ivpw77cRV2hhaqmorMgi3dwBXJZi2Z3 +oSIHdym3Kp6z1HFNs3xH8wtQWXWauU8ROxoDYovdX651koTj7r/xxKLyCYmTJRKZ2Q7 SZ6WMuDGYO+bEyQTNVfOCYgEzHS+3cAAeAuzf6XXFt3BezmXoMSk1NB74uRtHh2g67pb m2KGWKyP5u4SgLIVf5Unq6dz72HfCgCIZ6QIcRV/fMvo9IuyY/oxw9iWwhx0/1tvNyg4 NQoXsHYuYADad7JGxE3yi6t0dOyKX2LqcGYeBRRgvvWIXq3TkwikALhUOeoR75a/tGED uyZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584856; x=1729189656; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=04eHUk6AClz9cRMQcjlWjE46ZR1uXceY2ogFB00LGDM=; b=Y1TV1LO5Zib9Jv5vaO3hZwVW73YUef2bVYhmcnlXHDTBbhep7cKCcwKOoKH95vot6a J5qRiDFexywybhIVZYtGsqoAthxAjfgGxIWkM+4cqlsTVRoJ+pjef3LpKBuHM125zw5b ULGR1nEnni5PzXJ3BMmuY1kIraxG6oqYSCqlsM7XqEas8sPyE9NhB04GweXa30wh3Amc xQ02zpAvt+kL0/xFXGBuQq2d7VutvB7WgLTPVvX8Jh2cZu+RTFhNDj5DFtcuu75x9Xfw hzMlJmACW8xj25J+L2wNYs2hr9DZ+PLnw9Jc+IqtdFgtsYBpHi2h1TiZgu7rOqgM2Bwz dPng== X-Forwarded-Encrypted: i=1; AJvYcCXkDdtFkY4zc1YIgqPfgafbrnAzfNbGEzD2Ru+eT+4ccD8LVekcBJnJ+s4WwtabDjukZomcNgI8VYg=@lists.infradead.org X-Gm-Message-State: AOJu0Yx3ToIfO7ZfxaG32i/ESD1Moe59f4xDsznT4fc8pvsTNyDUOOXs 1nUCa5YoePdgfjSkdFWmzkGyBf9Daz67tZje4KV1ACWTlzKNYZN2h5W63JWeLGssV0OCrzQf4Kx HTQ== X-Google-Smtp-Source: AGHT+IHGiwNd3UbnZUzPre1tk98dNYoM10q7gFGG4lq0PldsJuDm1rxMHI+g8Yc3UsVnmkzWnOurUMFmqIQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a17:903:41c4:b0:20c:8f78:67c9 with SMTP id d9443c01a7336-20c8f786946mr26385ad.5.1728584855618; Thu, 10 Oct 2024 11:27:35 -0700 (PDT) Date: Thu, 10 Oct 2024 11:24:19 -0700 In-Reply-To: <20241010182427.1434605-1-seanjc@google.com> Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241010182427.1434605-78-seanjc@google.com> Subject: [PATCH v13 77/85] KVM: arm64: Use __gfn_to_page() when copying MTE tags to/from userspace From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, " =?utf-8?q?Alex_Benn=C3=A9e?= " , Yan Zhao , David Matlack , David Stevens , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_112737_158190_94208241 X-CRM114-Status: GOOD ( 10.54 ) X-Spam-Score: -9.5 (---------) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__Use_=5F=5Fgfn=5Fto=5Fpage=28=29_instea?= =?unknown-8bit?q?d_when_copying_MTE_tags_between?= =?unknown-8bit?q?_guest_and_userspace=2E_This_will_eventually_allow_removing?= =?unknown-8bit?q?_gfn=5Fto=5Fpfn=5Fprot=28=29=2C?= =?unknown-8bit?b?IGdmbl90b19wZm4oKSwga3ZtX3Bmbl90b19yZWZjb3VudGVkX3BhZ2Uo?= =?unknown-8bit?b?KSwgYW5kIHJlbGF0ZWQgQVBJcy4gVGVzdGVkLWJ5Og==?= =?unknown-8bit?q?_Alex_Benn=C3=A9e_=3Calex=2Ebennee=40linaro=2Eorg=3E_Signed?= =?unknown-8bit?q?-off-by=3A_Sean_Christopherson_=3Cseanjc=40google=2Ecom=3E?= =?unknown-8bit?q?_---_arch/arm64/kvm/guest=2Ec_=7C_21_+++++++++_1_file_chang?= =?unknown-8bit?q?ed=2C_9_insertions=28+=29=2C?= =?unknown-8bit?b?IDEyIGRlbGV0aSBbLi4uXSA=?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-9=2E5_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyNjA3OmY4YjA6NDg2NDoyMDowOjA6MDo1NGEgbGlzdGVkIGluXQ==?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_-7=2E5_USER=5FIN=5FDEF=5FDKIM=5FWL____From=3A_address_is_i?= =?unknown-8bit?q?n_the_default_DKIM_welcome-list?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FAU__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from_author=27s?= =?unknown-8bit?q?_domain?= =?unknown-8bit?q?_-1=2E9_BAYES=5F00_______________BODY=3A_Bayes_spam_probabi?= =?unknown-8bit?q?lity_is_0_to_1=25?= =?unknown-8bit?q?_=5Bscore=3A_0=2E0000=5D?= =?unknown-8bit?q?_-0=2E0_DKIMWL=5FWL=5FMED__________DKIMwl=2Eorg_-_Medium_tr?= =?unknown-8bit?q?ust_sender?= X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use __gfn_to_page() instead when copying MTE tags between guest and userspace. This will eventually allow removing gfn_to_pfn_prot(), gfn_to_pfn(), kvm_pfn_to_refcounted_page(), and related APIs. Tested-by: Alex Bennée Signed-off-by: Sean Christopherson --- arch/arm64/kvm/guest.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 962f985977c2..4cd7ffa76794 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -1051,20 +1051,18 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm, } while (length > 0) { - kvm_pfn_t pfn = gfn_to_pfn_prot(kvm, gfn, write, NULL); + struct page *page = __gfn_to_page(kvm, gfn, write); void *maddr; unsigned long num_tags; - struct page *page; - if (is_error_noslot_pfn(pfn)) { - ret = -EFAULT; - goto out; - } - - page = pfn_to_online_page(pfn); if (!page) { + ret = -EFAULT; + goto out; + } + + if (!pfn_to_online_page(page_to_pfn(page))) { /* Reject ZONE_DEVICE memory */ - kvm_release_pfn_clean(pfn); + kvm_release_page_unused(page); ret = -EFAULT; goto out; } @@ -1078,7 +1076,7 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm, /* No tags in memory, so write zeros */ num_tags = MTE_GRANULES_PER_PAGE - clear_user(tags, MTE_GRANULES_PER_PAGE); - kvm_release_pfn_clean(pfn); + kvm_release_page_clean(page); } else { /* * Only locking to serialise with a concurrent @@ -1093,8 +1091,7 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm, if (num_tags != MTE_GRANULES_PER_PAGE) mte_clear_page_tags(maddr); set_page_mte_tagged(page); - - kvm_release_pfn_dirty(pfn); + kvm_release_page_dirty(page); } if (num_tags != MTE_GRANULES_PER_PAGE) {