From patchwork Fri Jul 26 23:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743570 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E9BAC3DA49 for ; Sat, 27 Jul 2024 00:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FGNMZjC6zrq4QPk0aaY9W+lI1TKYWYG7APrsjifVvZM=; b=qOJXNxsIloTbEuGPcGeHReXR5X q8Koy4/8N7lu7QnxwlC+eS4opIQ2OTc1aMbqkSv5ZuaZyBhRvyXGdd/tSpXVxSq3CNsz1eOJAIo2n /aQoWgu50nnexvguZIT/uKPwDwMsWF/A6iv0DL+Kx3r6M9Es9jC7nnaT3rfoegzZf1WwK6lMRfEAj o7Shp6qG8KQ07CovKy0vSC5ObrC3x5GVGmfO/Yvh6XTSjSQrN1ANHooTzkoDqgzk1yU+Qn0Woqbfd FI64J+qs2zRlaiFtUpab716hlwMeFJHjZ14nckJRJxhGr2L449bSY+apZa31emJS/0uy1Bfzkwbnx Qlf5eYiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVKe-00000005j4K-2akL; Sat, 27 Jul 2024 00:30:44 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUmF-00000005REP-1WPj for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:55:16 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6648363b329so5175957b3.3 for ; Fri, 26 Jul 2024 16:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038110; x=1722642910; darn=lists.infradead.org; h=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=FGNMZjC6zrq4QPk0aaY9W+lI1TKYWYG7APrsjifVvZM=; b=ZLp5txfxYH6q2vmavmG997qwjBolQPC+YcsmUXhWlVmZ9Qtc9WeyBrgRwFoGpBRUqN A51TRObFHCPZux/6+OeZWCDVR74M2+zX97YgUSY5HkSdJN2KuSCALfx/8uhLtIx/PNm9 04wdf3t/H+Py3bLaECsLQikDqOzFiE1n5NBElBNvSpgTHhmB5PLV2YB90pbSiLuRV0Db Zi3NbkAr6GfD7asOEJBKfvQSCSYtpPypzvvq9sA0c/28R1q8DMrDhOBZjeFN3Fo8d9X+ wyKHVY785vOeY63wLXv+8EqRnORHy7maTE2XpetWWUFEi9IR5qooRG5IDZEIhugWtDQA /Q4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038110; x=1722642910; h=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=FGNMZjC6zrq4QPk0aaY9W+lI1TKYWYG7APrsjifVvZM=; b=SPlNWZkB6oE2LhaRpKtv4ZlcHeYMvAZMM4YDCuqUuhxMJbdv2vH2bBV38aXObUji2p c6CsIM9fATAVuBXFE96NkarNtSRmaqEN4J3cbIDHogIGqjvHDm5L92alWZZbk8pPCaEW K/MVM0w9lvbXn2JVgXn1FDRKfL30dP0s9cHTvKJWT0de/C1Ca2NiGvWKohHpkvLRm/nS 3JbuufozZTJtLXoNIj9rBMN0Ku+yUzdcwwQakNsLUxOhVNpXkcIGJwwWcuMiuaOOFq16 pbZu/cqCrJvtJQw3L8RA9R9DO1Zx4XG33IZF9n6d58YmWaKH7IIOxuzKUesg4P4sBnD1 sNSg== X-Forwarded-Encrypted: i=1; AJvYcCVZm2PBMcs27waXj7ErFisAJuTa1c/JRQhhkomvqevGsOarGR6w6nY1KFYCFpHZry2xSN7+1/srcwrinBhBpl77+Fq1RrECxmhgcLVAXObIK6EXePc= X-Gm-Message-State: AOJu0YzYZjJneE3J70XeqaDIsLTXlte4LuzgYsMaDBLArlKaP2/Bt8wj tlzYIbf2Vo26sSERAky/VZheFYqEoUcgQw+pkfQaHMaULVJYVE+GvEJth8los3tin5B1O8ThyuF Lcw== X-Google-Smtp-Source: AGHT+IFLZWO6XOpdLpjl0c1N0cYikN5d5kXLguU/WRS6HZfMhk4D9x8u+2tsxxP6CN0/8qHX8YjuuRQeC7A= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:830:b0:61b:e103:804d with SMTP id 00721157ae682-67a004a2a4amr37877b3.0.1722038109325; Fri, 26 Jul 2024 16:55:09 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:22 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-74-seanjc@google.com> Subject: [PATCH v12 73/84] KVM: PPC: Use kvm_vcpu_map() to map guest memory to patch dcbz instructions 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, David Matlack , David Stevens X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165511_677503_B76AED67 X-CRM114-Status: GOOD ( 13.09 ) X-BeenThere: linux-arm-kernel@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: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use kvm_vcpu_map() when patching dcbz in guest memory, as a regular GUP isn't technically sufficient when writing to data in the target pages. As per Documentation/core-api/pin_user_pages.rst: Correct (uses FOLL_PIN calls): pin_user_pages() write to the data within the pages unpin_user_pages() INCORRECT (uses FOLL_GET calls): get_user_pages() write to the data within the pages put_page() As a happy bonus, using kvm_vcpu_{,un}map() takes care of creating a mapping and marking the page dirty. Signed-off-by: Sean Christopherson --- arch/powerpc/kvm/book3s_pr.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c index ae4757ac0848..393c18958a5b 100644 --- a/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c @@ -639,28 +639,27 @@ static void kvmppc_set_pvr_pr(struct kvm_vcpu *vcpu, u32 pvr) */ static void kvmppc_patch_dcbz(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte) { - struct page *hpage; + struct kvm_host_map map; u64 hpage_offset; u32 *page; - int i; + int i, r; - hpage = gfn_to_page(vcpu->kvm, pte->raddr >> PAGE_SHIFT); - if (!hpage) + r = kvm_vcpu_map(vcpu, pte->raddr >> PAGE_SHIFT, &map); + if (r) return; hpage_offset = pte->raddr & ~PAGE_MASK; hpage_offset &= ~0xFFFULL; hpage_offset /= 4; - page = kmap_atomic(hpage); + page = map.hva; /* patch dcbz into reserved instruction, so we trap */ for (i=hpage_offset; i < hpage_offset + (HW_PAGE_SIZE / 4); i++) if ((be32_to_cpu(page[i]) & 0xff0007ff) == INS_DCBZ) page[i] &= cpu_to_be32(0xfffffff7); - kunmap_atomic(page); - put_page(hpage); + kvm_vcpu_unmap(vcpu, &map); } static bool kvmppc_visible_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)