From patchwork Sun Jan 12 09:55:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13936299 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0FFE18FC74 for ; Sun, 12 Jan 2025 09:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675739; cv=none; b=S5BZKzVF49wSr2X+TZQvLdgrEpvUvKeUGxpFgOVUB1fABs2GuAUVH2jk13iP4bNCZp7LjFIvPIOI3bbsq1g0livKBlZfF5irDJFFkOoekqPQjGzv6OOnFIdPY35D+ABAirBfOHRgTnypfSThkA+Las+lP5HHB4UIx81to2XV1gM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675739; c=relaxed/simple; bh=zXt8gel/yANsANDIs5B5Mdvh1QFGb9YfZgkI8pbrooQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N2XPGjF7mFZtlkit/6zOnzd5CKPvUmKidDKpHa8EpRqkeBgrLM80OYQOZYl9pZWZOXN3gyaGikWWZ8v2Wmgxg+ErWwNepwt/T0Pl8FjrHKHcufiAD7GohHJO5GP4jp/Lc4tIJG9VqZRgpMz91X1rjaGSlNFw7RlX0R3FD5KDuks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MyiqCQSE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MyiqCQSE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736675736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q2g0sdh+W5glSkagx457PsA9cI+PMduPyER5qBCP9uo=; b=MyiqCQSEX9/f5RPFMIV9OXNz4JZLjEaeXiNHzT7FyJVa7aCMW4thttRvgeAr8gNTfrR2fu Y3bbIjE+LyEhMZiF2rHFYug+6yDgCWp8HYPgEpfUz1Wp5WbWVLkYXXi+jsXTZUuMSh0/Oc BheqC1ZSZiH89PfGCLX1NqY1E2eVca8= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-198-AktupQARMUeowRVosCKcjg-1; Sun, 12 Jan 2025 04:55:35 -0500 X-MC-Unique: AktupQARMUeowRVosCKcjg-1 X-Mimecast-MFC-AGG-ID: AktupQARMUeowRVosCKcjg Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-aa69e84128aso266640666b.1 for ; Sun, 12 Jan 2025 01:55:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736675733; x=1737280533; 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=q2g0sdh+W5glSkagx457PsA9cI+PMduPyER5qBCP9uo=; b=CvcvCXonnd78C3K2Kb0HODEIMmEZWaj8yowg5UUzF94jwAceIxc2gWmNnvj7AYbyLN zithEnSFvvn1pIYBYiKmAzBc631OEbAoi7a9S3sqH/BBQVla+kaxJnNUsKjwOsF3iaj9 bnFTMU+FrKOGJxs58gXz9qtoZEoGRHxdYSf68LkVnXA9qodeuxzCSY7B9Vj2nlX6Alm2 DjVYAmeX2vKglCDskCwEj+Y8KM5T2esbaJHgVKDG4RkAw3Rxe9D5l5g4fEcOP/HICuug GIhUKbZ9OMfxzMueMUZaqhNCf4E5NEagaP6PYnqeItXG2FCOtYQBPaCYp6dvf2bzekc9 JPBA== X-Forwarded-Encrypted: i=1; AJvYcCVWaLleqY1fqILi8PnpbzvNF+Dy3/dpK02wvKzZoMb3xwloFmDY6H4G7x11LjduoJ80UBk=@vger.kernel.org X-Gm-Message-State: AOJu0YxGtjxusl0LegK+RodKTHRiwR1yRzGuX8e0Z7K93H5EwMbgMUbp TSE7k58fcCYGn3yTMoiYGaQLdyXeC9Ro52FjrHXZBL/bVjlKKo6wCD6+QaOQ1lbwgpD7Mq+0A5b BsgQ038CH70Vi0zi9nAzRKug8SdgoPVxE2mVSlJmmUn7NkWQtoM+cJ7FXcYdV X-Gm-Gg: ASbGncuSPth6IbGeA6BHUCZItIJONm6BUFtj6UQGlyfSVCcyMOvD8E5WYrE0QNGCYnc ycxI1XYPTLMWiACMDFFhn1nCKCPs1OcxqLR8P5IAOJDflc4uyzMAfjeoLPnNtj2WS7jo1a8keml NORnjskLKW5cCyRWWxPSIpWdm3rJNbi90RthbbP0fqPq4BPhQGQUBQdlkL4LO8hLwtEcvnYMlLY dm2/6zupDXFhV0G48RJWSmAbZTS/0GX2aUaeBPA0pRA0dGWnPTvNnwfsPM= X-Received: by 2002:a17:907:d1b:b0:aac:23f4:f971 with SMTP id a640c23a62f3a-ab2ab70a173mr1753854666b.33.1736675733514; Sun, 12 Jan 2025 01:55:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxwq3cSzmX3Sr/t/JxywDCCAqRMgXJsypEs7qUCiLJx2f+d/bQof+BQSWZDWOMCFQMp6aY9A== X-Received: by 2002:a17:907:d1b:b0:aac:23f4:f971 with SMTP id a640c23a62f3a-ab2ab70a173mr1753853166b.33.1736675733170; Sun, 12 Jan 2025 01:55:33 -0800 (PST) Received: from [192.168.10.3] ([151.62.105.73]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c95647absm352956366b.118.2025.01.12.01.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 01:55:31 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, linuxppc-dev@lists.ozlabs.org, regressions@lists.linux.dev, Christian Zigotzky , stable@vger.kernel.org Subject: [PATCH 1/5] KVM: e500: always restore irqs Date: Sun, 12 Jan 2025 10:55:23 +0100 Message-ID: <20250112095527.434998-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250112095527.434998-1-pbonzini@redhat.com> References: <20250112095527.434998-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If find_linux_pte fails, IRQs will not be restored. This is unlikely to happen in practice since it would have been reported as hanging hosts, but it should of course be fixed anyway. Cc: stable@vger.kernel.org Reported-by: Sean Christopherson Signed-off-by: Paolo Bonzini --- arch/powerpc/kvm/e500_mmu_host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index e5a145b578a4..6824e8139801 100644 --- a/arch/powerpc/kvm/e500_mmu_host.c +++ b/arch/powerpc/kvm/e500_mmu_host.c @@ -479,7 +479,6 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, if (pte_present(pte)) { wimg = (pte_val(pte) >> PTE_WIMGE_SHIFT) & MAS2_WIMGE_MASK; - local_irq_restore(flags); } else { local_irq_restore(flags); pr_err_ratelimited("%s: pte not present: gfn %lx,pfn %lx\n", @@ -488,8 +487,9 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, goto out; } } + local_irq_restore(flags); + writable = kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg); - kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize, ref, gvaddr, stlbe); From patchwork Sun Jan 12 09:55:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13936300 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E0671A8F8E for ; Sun, 12 Jan 2025 09:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675743; cv=none; b=A5iA9q7aMyGSkxgsW+dvV2I+EhjDoiP3a1m5bOaosqwOKbalIn9z8PUA5MU0BYO6pGWh2LvDPD4PvrhMpBUWbvQmT9SS781eyQEEsVxwSB/4ia+p0bAitIE2JK2BVmMdx0YysGzCDkj3qm0XZswvgEGyk5Wyx/h5NfizkTAl/C0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675743; c=relaxed/simple; bh=RUtYNoQ9BCw8rR1uJmMHYjgVRzEI8pcTkgifDneD3LU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sCuUt33pqgPhFIaOY/Zudet2H4xioWA2BD1OvnnQiJsZMqYmI8iAN5Cjk1A4jVjnUZemQLDqa5r78lyQ8lg4mY2nFMhAutYtWUbyqWKc9hYPwzsEbRW1maN6Zg8ceockenrTm0SxcXCsdvTNyBLU6ZQY/fA61vDGMJBEu4zwYZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TGWhKRkq; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TGWhKRkq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736675741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ia6sv5K1rPK0oxjj8pHkn374uhH5Bs7h1d/ShzUvYRM=; b=TGWhKRkqI4FJL/iZYxN9527HZOhpdpoMIHyz2PUt39+dY8LlRW0gOmmO9Qk52AHGveFDa8 MH0/Wy9IL1CM0WRU8VslyLct8uzgBCCvgxWHDKW/V6GrFeFepS8rcuG/lZkJ3Sd3yoGhxS eWEVpEs9BZ8E01DyVM5ZSbTVCy4MnFI= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-16-Iyz-Hcm7Pa-SjY-9loRl2w-1; Sun, 12 Jan 2025 04:55:37 -0500 X-MC-Unique: Iyz-Hcm7Pa-SjY-9loRl2w-1 X-Mimecast-MFC-AGG-ID: Iyz-Hcm7Pa-SjY-9loRl2w Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-aa6732a1af5so359838866b.3 for ; Sun, 12 Jan 2025 01:55:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736675736; x=1737280536; 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=Ia6sv5K1rPK0oxjj8pHkn374uhH5Bs7h1d/ShzUvYRM=; b=vutd5MpZWpnlfm2nof7wr5Zy7BIGZeW0oMoqKw3t2Lg1dIyM+hJJtkvine8b9v0FX8 0hy7dhhzaokWgQlyBZ9sFyr6ogCScW5joP7lWOi+GhAoI784I3oH3Pi7Sh2G2Lx6/5vH Zrye2v6j5qZ7bo1JP/P6OnGuHS84JoigRqewMFT28wXnvJN9qLvz3ju9ji/HiDdGCbZS IMtOuf+diBw31SDQAMdkXu7gu2MtFZQgE9pgtIHm/egr3rqpqa0XI5NF49RjUFMmX3Qh 5VdCVVfF22l/n4OzhKCEwAAKa9TWC/CdCQP2KiNw8jrg22lfWiC2NjJTcUL5yKbLA8YX kSiw== X-Forwarded-Encrypted: i=1; AJvYcCWTWDqm+IVJjL8dJQOi2SoT+DETUDDRWutr6umG/6DUiErPvb+K0DDDdqKHMbwODnECC2Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwhkF/WDV1E/roi/w/ERWtYyUO/O9CmwXebd6RjxBWk27YryJ81 BCWhgoyKGXekFXZRg5Zp57oWY628YwQ8Ty6am0c3QkHCsw5TVAJ+P5+bxbXUDKZhOb6uh/FDs45 WpeP95f1sbqgRtPK029LudsQ4dljGEa5RnuHHgh95v5sEAH1lmQ== X-Gm-Gg: ASbGncvKQxGkXtHEHmy7aT+/6ErgyPR2v7+BHOyUtYBEj/cSTdoT/BUOSCmA1u771ln fKWiizeahK/eu/O+nx7cXyiyDqAirQw5W+F9rfsvE/LCw8EMqMzY+XTpMN2DZ7PChp252giXDTH kbfkrSmAoEkvodmbWPIT63u6B3YD0ZSV6EeznpljI++MkkxKlzGf0MRnzc7box725pjv3vJ08+p je2CiHzD8IRNSfLP9feaNXZvVHTxS71MLLxFKyh8nmq9GKOFQCdz9IHY9U= X-Received: by 2002:a17:906:478f:b0:aab:dc3e:1c84 with SMTP id a640c23a62f3a-ab2ab703f93mr1611128366b.17.1736675736618; Sun, 12 Jan 2025 01:55:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IE57lWwmpDxmyLrpFomxsQp5nUpO/tCN5jrf13BA6wccxa5tYF5ClNyyJ2YVR15koS+dU7MVg== X-Received: by 2002:a17:906:478f:b0:aab:dc3e:1c84 with SMTP id a640c23a62f3a-ab2ab703f93mr1611127466b.17.1736675736279; Sun, 12 Jan 2025 01:55:36 -0800 (PST) Received: from [192.168.10.3] ([151.62.105.73]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c905e283sm356143866b.31.2025.01.12.01.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 01:55:34 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, linuxppc-dev@lists.ozlabs.org, regressions@lists.linux.dev, Christian Zigotzky Subject: [PATCH 2/5] KVM: e500: use shadow TLB entry as witness for writability Date: Sun, 12 Jan 2025 10:55:24 +0100 Message-ID: <20250112095527.434998-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250112095527.434998-1-pbonzini@redhat.com> References: <20250112095527.434998-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 kvmppc_e500_ref_setup is returning whether the guest TLB entry is writable, which is than passed to kvm_release_faultin_page. This makes little sense for two reasons: first, because the function sets up the private data for the page and the return value feels like it has been bolted on the side; second, because what really matters is whether the _shadow_ TLB entry is writable. If it is not writable, the page can be released as non-dirty. Shift from using tlbe_is_writable(gtlbe) to doing the same check on the shadow TLB entry. Signed-off-by: Paolo Bonzini --- arch/powerpc/kvm/e500_mmu_host.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index 6824e8139801..c266c02f120f 100644 --- a/arch/powerpc/kvm/e500_mmu_host.c +++ b/arch/powerpc/kvm/e500_mmu_host.c @@ -242,7 +242,7 @@ static inline int tlbe_is_writable(struct kvm_book3e_206_tlb_entry *tlbe) return tlbe->mas7_3 & (MAS3_SW|MAS3_UW); } -static inline bool kvmppc_e500_ref_setup(struct tlbe_ref *ref, +static inline void kvmppc_e500_ref_setup(struct tlbe_ref *ref, struct kvm_book3e_206_tlb_entry *gtlbe, kvm_pfn_t pfn, unsigned int wimg) { @@ -251,8 +251,6 @@ static inline bool kvmppc_e500_ref_setup(struct tlbe_ref *ref, /* Use guest supplied MAS2_G and MAS2_E */ ref->flags |= (gtlbe->mas2 & MAS2_ATTRIB_MASK) | wimg; - - return tlbe_is_writable(gtlbe); } static inline void kvmppc_e500_ref_release(struct tlbe_ref *ref) @@ -489,9 +487,10 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, } local_irq_restore(flags); - writable = kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg); + kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg); kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize, ref, gvaddr, stlbe); + writable = tlbe_is_writable(stlbe); /* Clear i-cache for new pages */ kvmppc_mmu_flush_icache(pfn); From patchwork Sun Jan 12 09:55:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13936301 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FF2F1AC88B for ; Sun, 12 Jan 2025 09:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675745; cv=none; b=StRE37oTjXKrXkZJeLCFizgT5jMGtA/cqpRMRMv9EBKNhq0Cky435a4DTC3pKWlBqldEIHo/Y1NYtE7DUGgAzWLYvFklu0Suk+gJl6UWWDbMLIs8ALhpsWvHmIkLpPVRBBiwRk6fKf+2vwCbt83iB49ookky8J0lWYeYLyN5VQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675745; c=relaxed/simple; bh=PYlVa2Y/YXHDakzTrdegPPAivF2UKPgqtms42a4RRMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UwJuZ4L/Xn9XZGzsAkZCVFmWOZtD4Ad7nMKKUIQQGJfhlpgJ+WRau38ehSAaCfndbh3E3SNCHC00RjdPk9wki32F4p4SrmZjQCxJcAQJXSYx0ff3gkzFEE5OLlQt+T5IyUvFdh0dnvUksMl4LpJ+C8pWgm4hQtOzyv+82s0HglQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bPw9wnow; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bPw9wnow" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736675742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TZOi2vhUk9IqOWLL4VjvE3yvErD9voRzbqxDd4bb0e4=; b=bPw9wnowqcwKRJRYZGQ/jyaH3WX2DcQ4BXJgTWV3cJiXQ7bTr9She/My2WtvZkgrAGilm+ Wsi3dXapEaPSU14uF7qpCFb0OoL250bVBbilgyBpUIQRwpZjbLAGhkGqwVcOO+H2ZJ4Egc dK51UBvidGAjfyIH9mdHDIC1m08JwxE= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-qWWX-L79PKaGn2UkwXMxVw-1; Sun, 12 Jan 2025 04:55:41 -0500 X-MC-Unique: qWWX-L79PKaGn2UkwXMxVw-1 X-Mimecast-MFC-AGG-ID: qWWX-L79PKaGn2UkwXMxVw Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-aaf8f016bb1so318040866b.2 for ; Sun, 12 Jan 2025 01:55:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736675740; x=1737280540; 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=TZOi2vhUk9IqOWLL4VjvE3yvErD9voRzbqxDd4bb0e4=; b=WWKM20GRz7JGBzQlyP2edcpJzrpHqZ0gxgrAxcjeJ170wBm6M3wiHZ0wHTcTJjN9Dl /LJEn+RZH/Eq7ujUeAgczVxBB6a5RIlzxbdc3C6xI47eHTiZLrppvmsJ0Q1DelsLYjNj aoBpEipx9lBfnMCq0xqXuyXNTKTjBzoxH/tZAc6nr4P51i64wpHbCvRSBy8VaokvhfEt 0OJaQGHh2lQkGFBOlUR3Um6HXgob3rdffJtChAb0KbsCWeBFOKtmMAmcBOK0TQFNOHLF K6bRjhFsiHNf5rhHH/+SUQ5QGmYx96R9Y/etVfo6jpzFDSM453oHnbvKAKnv1TdgCmDj DFuA== X-Forwarded-Encrypted: i=1; AJvYcCXBEhPh0jtyExLe+83omKwPvs1JwGqsjKxStu/bdeuO3NS2HDzGkjLxikumeZM/AOEHh5k=@vger.kernel.org X-Gm-Message-State: AOJu0YxvZqbnmX7RfzJ5CORODe2LLSZfMLGuw5mUG0LZ3kSuZE7cd2Xo xlKTx7DxvAVNjRLQu7qU7kPva8aVmpp/GtKLInj5riHZjgA0o2LuKCnYc+vGQQeyN9YXC36oQ6d bPnWn1csbkjdDm/sM/l1j+1HjP34c4Yphn6F56LJjvzlm5IAPUg== X-Gm-Gg: ASbGncsus7zUDY2pGGe4cFmYUccBqQfuuqVtGEw4JxIUZ5QM8Hvu9d/868ZZTosk4X2 9PUrKHnNhYMnGgaOzNEk/rf26LcBk0zN11XR+cg5li91xKLCHVQ2FLKUBHkKM1vRcqciK4fKykZ C+ohEJCaTcvXMBeySSYgsTcePnE8GJiC0PcB2KZka5Bo5GIuJ3iKZgQtSrpTVT+ZyodEU85gp7P AeKmXXRhG43HPLRoKbygITMCkfcnVpoiUzLgCGfQzPJREi7VvtvCHpJDzg= X-Received: by 2002:a17:906:f58d:b0:aab:f014:fc9a with SMTP id a640c23a62f3a-ab2ab703f01mr1331418366b.22.1736675739788; Sun, 12 Jan 2025 01:55:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYiuGhI+4msFAOUKvZ179BJ3utaua0uWFviKs7CY/tGCvPWvPtqZvorhRWNQWYuMTsu6u8Aw== X-Received: by 2002:a17:906:f58d:b0:aab:f014:fc9a with SMTP id a640c23a62f3a-ab2ab703f01mr1331416766b.22.1736675739453; Sun, 12 Jan 2025 01:55:39 -0800 (PST) Received: from [192.168.10.3] ([151.62.105.73]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2e8c753fdsm226853266b.184.2025.01.12.01.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 01:55:37 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, linuxppc-dev@lists.ozlabs.org, regressions@lists.linux.dev, Christian Zigotzky Subject: [PATCH 3/5] KVM: e500: track host-writability of pages Date: Sun, 12 Jan 2025 10:55:25 +0100 Message-ID: <20250112095527.434998-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250112095527.434998-1-pbonzini@redhat.com> References: <20250112095527.434998-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the possibility of marking a page so that the UW and SW bits are force-cleared. This is stored in the private info so that it persists across multiple calls to kvmppc_e500_setup_stlbe. Signed-off-by: Paolo Bonzini --- arch/powerpc/kvm/e500.h | 2 ++ arch/powerpc/kvm/e500_mmu_host.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h index 6d0d329cbb35..f9acf866c709 100644 --- a/arch/powerpc/kvm/e500.h +++ b/arch/powerpc/kvm/e500.h @@ -34,6 +34,8 @@ enum vcpu_ftr { #define E500_TLB_BITMAP (1 << 30) /* TLB1 entry is mapped by host TLB0 */ #define E500_TLB_TLB0 (1 << 29) +/* entry is writable on the host */ +#define E500_TLB_WRITABLE (1 << 28) /* bits [6-5] MAS2_X1 and MAS2_X0 and [4-0] bits for WIMGE */ #define E500_TLB_MAS2_ATTR (0x7f) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index c266c02f120f..b1be39639d4a 100644 --- a/arch/powerpc/kvm/e500_mmu_host.c +++ b/arch/powerpc/kvm/e500_mmu_host.c @@ -45,11 +45,14 @@ static inline unsigned int tlb1_max_shadow_size(void) return host_tlb_params[1].entries - tlbcam_index - 1; } -static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode) +static inline u32 e500_shadow_mas3_attrib(u32 mas3, bool writable, int usermode) { /* Mask off reserved bits. */ mas3 &= MAS3_ATTRIB_MASK; + if (!writable) + mas3 &= ~(MAS3_UW|MAS3_SW); + #ifndef CONFIG_KVM_BOOKE_HV if (!usermode) { /* Guest is in supervisor mode, @@ -244,10 +247,13 @@ static inline int tlbe_is_writable(struct kvm_book3e_206_tlb_entry *tlbe) static inline void kvmppc_e500_ref_setup(struct tlbe_ref *ref, struct kvm_book3e_206_tlb_entry *gtlbe, - kvm_pfn_t pfn, unsigned int wimg) + kvm_pfn_t pfn, unsigned int wimg, + bool writable) { ref->pfn = pfn; ref->flags = E500_TLB_VALID; + if (writable) + ref->flags |= E500_TLB_WRITABLE; /* Use guest supplied MAS2_G and MAS2_E */ ref->flags |= (gtlbe->mas2 & MAS2_ATTRIB_MASK) | wimg; @@ -303,6 +309,7 @@ static void kvmppc_e500_setup_stlbe( { kvm_pfn_t pfn = ref->pfn; u32 pr = vcpu->arch.shared->msr & MSR_PR; + bool writable = !!(ref->flags & E500_TLB_WRITABLE); BUG_ON(!(ref->flags & E500_TLB_VALID)); @@ -310,7 +317,7 @@ static void kvmppc_e500_setup_stlbe( stlbe->mas1 = MAS1_TSIZE(tsize) | get_tlb_sts(gtlbe) | MAS1_VALID; stlbe->mas2 = (gvaddr & MAS2_EPN) | (ref->flags & E500_TLB_MAS2_ATTR); stlbe->mas7_3 = ((u64)pfn << PAGE_SHIFT) | - e500_shadow_mas3_attrib(gtlbe->mas7_3, pr); + e500_shadow_mas3_attrib(gtlbe->mas7_3, writable, pr); } static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, @@ -487,7 +494,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, } local_irq_restore(flags); - kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg); + kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg, true); kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize, ref, gvaddr, stlbe); writable = tlbe_is_writable(stlbe); From patchwork Sun Jan 12 09:55:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13936302 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60FC61B140D for ; Sun, 12 Jan 2025 09:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675750; cv=none; b=B2okHL4aRl5YPyTmd0EhkjCH0IalNqheUk21GGRcfP7Gv8qXZB9TsKv7lRGTAklXfy5XSeUwR/xNM0oYzWvMKDa+5Bo4znGr2+WPIRLbI14WYSgJ3jLC6F1E15VRtunozZrbzFWQiwpaRju8sBJv2ycxHGAWIphgm39VkFc8rak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675750; c=relaxed/simple; bh=2SDn49FT0scN9brUsaT1uzAqhvETvcU7A9zYxcIRZEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j9QdT2JpT5Rbr4tQnHox/Wqbrv/Q1JT9E2Kr3LQnlSxqgcsx1QZpIuozVgFtx1pXD+3yVXJbcJHgsuvi9BUVpj0RFRinArgl9ZCkMn4vQal/dZUIE/6ktTzK+RTrU74jw1qgiItd66hiaHBWrSzVSOQv8ZYaEijzBu2c+HNe818= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aOqwnfXH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aOqwnfXH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736675748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=53tOW+li8LibaZME0FEdug9t3b3VYRiHfAOklFpMuVY=; b=aOqwnfXHXIIMd82SZWUW7AHe2WPYns6JRqdzXdMDZYp2ogQdV6g9z6GYi/9yqJ902KNWrD U5RgKm161IhEcQplJSAE6Ol2Gy/RlpXTnXmUbDdW+6ByJkSA/PjkX1SJI8dHhQNyTYe4JG qMYNlBtzFRiCdbeE3ZHmOYb88vUlMOY= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-532-BvsvCi8PNzGF_MPtYQ12wA-1; Sun, 12 Jan 2025 04:55:45 -0500 X-MC-Unique: BvsvCi8PNzGF_MPtYQ12wA-1 X-Mimecast-MFC-AGG-ID: BvsvCi8PNzGF_MPtYQ12wA Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-aafba50f3a6so325323766b.2 for ; Sun, 12 Jan 2025 01:55:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736675743; x=1737280543; 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=53tOW+li8LibaZME0FEdug9t3b3VYRiHfAOklFpMuVY=; b=wutVd3UaNvSlOjc3DDoykncENBEeaqimIub7BXr68oWbrnXBUcOTwaBBEXE9Lli3C+ aDxOcK/XobAQCgYHF3CRJ99Bqcl0rmHu4yN4ugSf9guxT+/ISqfFu8C/xTLkKk2UhhMe cCURkUVLiQOJBhhqXjOWSCJgEOfNrvekAOW5EZyGDzOZmiI+PCWLMjnAcfvRCipKRlwI Tfh+LiT5Co3AWRlLDNnWiZR8ae18DruwwkkwTfvr+YDoXpkVHGYSsu1L8b10zaqENeGS l5BtsNj8+4Ws47XAOLwlXNU1TV/e8+XW82gMFmJvkO2z1zjxWW2BwaQj8Bv9K1pZSr5H cDlA== X-Forwarded-Encrypted: i=1; AJvYcCVV5zVMN+S5UrJgfYeRzsF174z6YRc/4zVV3pvGRiC6NwsRig7YqQ89cnPxRDIkoAFaf2U=@vger.kernel.org X-Gm-Message-State: AOJu0YxocGsLFYFa04o0IqC0QENZCqjBFE0F0mv/Qw6vF7QHA6FEyWRV LRoaW6U5jWMEuBugJxCQZXoT2gYTeSW5tqx3Puwxq52i0OLnIyQxZClfta8C4b66n69NaaAIMfv 5mp0Oc6jNcSV1B8/4RJyA9agLzR/7QrPrTjk9q+kgE+8Rl4At91TK93hPQy+j X-Gm-Gg: ASbGncszhXd7V1v8GQF6LOG1fsdq23I5WxCeAJFihN6Ux1M4k8YizcTg/UhHqTpvTQP 5xBIFVjJjxDQHQNaSf6bEXAZVQZ5ollwoCz0MTyE6iFLHHAz/fqrazh0zcqJuVJvanu264hK2J8 piQZ7bg5NoRIYipRHmhkRT52v53mg9fNB+aj7C/9Fk87mQBpScN9Zg1NCUAHBKbdqzTChm0eKvh Kg7uMffZkQEIpU/fH0ndZsCH4YLfLq2A+CxbNtcppNrYfG6xGyWC0ExSTs= X-Received: by 2002:a17:907:7f1e:b0:aab:c78c:a7ed with SMTP id a640c23a62f3a-ab2abde30a8mr1561037766b.49.1736675742913; Sun, 12 Jan 2025 01:55:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGJlu2i7msf3zvSzymzm23VI3HB+hujDx3jJa79Xm9BhmbLM60jNLT6BqjxStf0JBpA+edAQ== X-Received: by 2002:a17:907:7f1e:b0:aab:c78c:a7ed with SMTP id a640c23a62f3a-ab2abde30a8mr1561036366b.49.1736675742572; Sun, 12 Jan 2025 01:55:42 -0800 (PST) Received: from [192.168.10.3] ([151.62.105.73]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c905e2ebsm363088866b.10.2025.01.12.01.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 01:55:40 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, linuxppc-dev@lists.ozlabs.org, regressions@lists.linux.dev, Christian Zigotzky Subject: [PATCH 4/5] KVM: e500: map readonly host pages for read Date: Sun, 12 Jan 2025 10:55:26 +0100 Message-ID: <20250112095527.434998-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250112095527.434998-1-pbonzini@redhat.com> References: <20250112095527.434998-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The new __kvm_faultin_pfn() function is upset by the fact that e500 KVM ignores host page permissions - __kvm_faultin requires a "writable" outgoing argument, but e500 KVM is nonchalantly passing NULL. If the host page permissions do not include writability, the shadow TLB entry is forcibly mapped read-only. Signed-off-by: Paolo Bonzini --- arch/powerpc/kvm/e500_mmu_host.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index b1be39639d4a..b38679e5821b 100644 --- a/arch/powerpc/kvm/e500_mmu_host.c +++ b/arch/powerpc/kvm/e500_mmu_host.c @@ -374,6 +374,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, unsigned long slot_start, slot_end; pfnmap = 1; + writable = vma->vm_flags & VM_WRITE; start = vma->vm_pgoff; end = start + @@ -449,7 +450,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, if (likely(!pfnmap)) { tsize_pages = 1UL << (tsize + 10 - PAGE_SHIFT); - pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, NULL, &page); + pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, &writable, &page); if (is_error_noslot_pfn(pfn)) { if (printk_ratelimit()) pr_err("%s: real page not found for gfn %lx\n", @@ -494,7 +495,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, } local_irq_restore(flags); - kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg, true); + kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg, writable); kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize, ref, gvaddr, stlbe); writable = tlbe_is_writable(stlbe); From patchwork Sun Jan 12 09:55:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13936303 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EE081B2183 for ; Sun, 12 Jan 2025 09:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675751; cv=none; b=kCN+8mD2OI5nzM1YGksGuFOFYI0v+dz3C6E8v3QqdmNkpF7eXtjcBvhe6Be22XP97sWbFDXpbpgQKiLmXyS5k0qxuOkF2tJzMY+PM++krlYtlKL5zDg5NtI2sb6lTiG6C7oKUX6ZFCC/mvaizyEnIMXrpeEDptgIwWnZqZqfbCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736675751; c=relaxed/simple; bh=hLGdHo4tiVX9rnua7cU6TNNXH51b2lPfYTsAAypovsw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZNDW9tp3EpSoPtKJdVsXZT69zNe9tcTWjgFdgGOL6mxurTR4Fjn3oJyjEnoP+d7c1Gq0zx82//9EwJ8A0ZuS7JCtffgc2hnA3LI2HHwBwKiMx3IEfu7eU7a5KHE290uqoWKNSNm5xLxABhw/DdVf3wOGiflnJiEDr9yAVEK1dz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KVXsJV0k; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KVXsJV0k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736675748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Oz+x9gnVbLji0IqeGhkpb/XHZ9boA09CCOsisxRXiHY=; b=KVXsJV0kPV05jx456PxUUgHBdIM+8atoZrcyGS7a4aYwxD08PZsuKzG16ASYGt3cUroa/a LuB921lNbeOzJOBDCYCY/I5E5ICn8pdAJtogVTX+idcohM37v+ngZCxb+0Y5EmlhUnMjm7 K4hLP7fUal+p5aZlMFFPIMKm9ng/2YI= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-454-TNe7VltMPty86gXRNsGmxg-1; Sun, 12 Jan 2025 04:55:47 -0500 X-MC-Unique: TNe7VltMPty86gXRNsGmxg-1 X-Mimecast-MFC-AGG-ID: TNe7VltMPty86gXRNsGmxg Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5d3f0411814so2848824a12.0 for ; Sun, 12 Jan 2025 01:55:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736675746; x=1737280546; 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=Oz+x9gnVbLji0IqeGhkpb/XHZ9boA09CCOsisxRXiHY=; b=UFua4NLoyTKJOHBTIXAknhHkNAc+cqHS9b1YHC9McOgnJlBp1z3QA8tv284CIYjPUg 3m7kl1dUraYZ1IA3OEyqBVp65kRi+x6BLmA9aW+SS7yuX26hJ2F0Mf0gxlZLrxQgrO3a e32r4Q+kvtZmwI2SJbEq6cawyIMrTM2/RD9aRryY1EiHnPvt+mJ9F1C+yzw7sp2iLIay 4UKH2TVl1mfCQm2Hi4Af3GG6JDHmBZlyC+SEZ9vNL3YKcUhm5+Q45BRn1PsM5c1RBiP6 0/ONqkypVAtky456mfTizB7FodTGvXwkq+Q9D8RY5nCRkXPJ4VH98mZamzJ+64yYVvQ/ AgmA== X-Forwarded-Encrypted: i=1; AJvYcCWMhx9Tw/+crjWrXSucU/+O/gtfxB5Qdq12ITlBt3WC1hsyM7FpAQuOO3vhnvdPuqK+dyM=@vger.kernel.org X-Gm-Message-State: AOJu0YyurAF3dkugMkY6DY97ja3vg5jV3XWH4BA1N4imElQxem0VnOSq bYKhafNfvj0c+kpieR/Mu2kGT8pVO9nAPLTP8bcAiRQfIuaHiLIEZ6AU4CNe+TVX37nRmIaJvB1 iW5U9JI9zo8N2bE1iBrl4sTxZh/e4U8W1AmD6GK37/keK/Sw6sA== X-Gm-Gg: ASbGncu/J1hUrcyQXDIKZXqHFvNz4jImc5Yv/Bp6nh8o4NH11wYvpbx/dBgKYIQsKpC iwtpGTrWFunkqQs2UvzZ9sbKGS9/kOJCTXhYOg43zYNc0w/hCZu+JR1frBawocYWhGwJ1GDbIG7 GfVaTNB5P6oYCSaGOHSS219JAqNH3My5mb8HXqbEs8tvI900QVfzirZHT4koMz+OJDKPmcy7H4n f/9f4TNbaoQQ0tT9AGvMlCtpJY1whIhXNEuZ8QVHnVU4ff1J0huSNhtU7A= X-Received: by 2002:a05:6402:51d0:b0:5d2:7346:3ecb with SMTP id 4fb4d7f45d1cf-5d972e08366mr15294468a12.12.1736675745739; Sun, 12 Jan 2025 01:55:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwE26l9isFf3nQZmRGpyTPcP8J8/ysUQYlXL5+4ti/a8bZoN63209mlmD5afvsephqydEaqg== X-Received: by 2002:a05:6402:51d0:b0:5d2:7346:3ecb with SMTP id 4fb4d7f45d1cf-5d972e08366mr15294450a12.12.1736675745359; Sun, 12 Jan 2025 01:55:45 -0800 (PST) Received: from [192.168.10.3] ([151.62.105.73]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d9900c3fccsm3491359a12.21.2025.01.12.01.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 01:55:43 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, linuxppc-dev@lists.ozlabs.org, regressions@lists.linux.dev, Christian Zigotzky Subject: [PATCH 5/5] KVM: e500: perform hugepage check after looking up the PFN Date: Sun, 12 Jan 2025 10:55:27 +0100 Message-ID: <20250112095527.434998-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250112095527.434998-1-pbonzini@redhat.com> References: <20250112095527.434998-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 e500 KVM tries to bypass __kvm_faultin_pfn() in order to map VM_PFNMAP VMAs as huge pages. This is a Bad Idea because VM_PFNMAP VMAs could become noncontiguous as a result of callsto remap_pfn_range(). Instead, use the already existing host PTE lookup to retrieve a valid host-side mapping level after __kvm_faultin_pfn() has returned. Then find the largest size that will satisfy the guest's request while staying within a single host PTE. Signed-off-by: Paolo Bonzini --- arch/powerpc/kvm/e500_mmu_host.c | 178 ++++++++++++------------------- 1 file changed, 69 insertions(+), 109 deletions(-) diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index b38679e5821b..06caf8bbbe2b 100644 --- a/arch/powerpc/kvm/e500_mmu_host.c +++ b/arch/powerpc/kvm/e500_mmu_host.c @@ -326,15 +326,14 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, struct tlbe_ref *ref) { struct kvm_memory_slot *slot; - unsigned long pfn = 0; /* silence GCC warning */ + unsigned int psize; + unsigned long pfn; struct page *page = NULL; unsigned long hva; - int pfnmap = 0; int tsize = BOOK3E_PAGESZ_4K; int ret = 0; unsigned long mmu_seq; struct kvm *kvm = vcpu_e500->vcpu.kvm; - unsigned long tsize_pages = 0; pte_t *ptep; unsigned int wimg = 0; pgd_t *pgdir; @@ -356,111 +355,12 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, slot = gfn_to_memslot(vcpu_e500->vcpu.kvm, gfn); hva = gfn_to_hva_memslot(slot, gfn); - if (tlbsel == 1) { - struct vm_area_struct *vma; - mmap_read_lock(kvm->mm); - - vma = find_vma(kvm->mm, hva); - if (vma && hva >= vma->vm_start && - (vma->vm_flags & VM_PFNMAP)) { - /* - * This VMA is a physically contiguous region (e.g. - * /dev/mem) that bypasses normal Linux page - * management. Find the overlap between the - * vma and the memslot. - */ - - unsigned long start, end; - unsigned long slot_start, slot_end; - - pfnmap = 1; - writable = vma->vm_flags & VM_WRITE; - - start = vma->vm_pgoff; - end = start + - vma_pages(vma); - - pfn = start + ((hva - vma->vm_start) >> PAGE_SHIFT); - - slot_start = pfn - (gfn - slot->base_gfn); - slot_end = slot_start + slot->npages; - - if (start < slot_start) - start = slot_start; - if (end > slot_end) - end = slot_end; - - tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >> - MAS1_TSIZE_SHIFT; - - /* - * e500 doesn't implement the lowest tsize bit, - * or 1K pages. - */ - tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1); - - /* - * Now find the largest tsize (up to what the guest - * requested) that will cover gfn, stay within the - * range, and for which gfn and pfn are mutually - * aligned. - */ - - for (; tsize > BOOK3E_PAGESZ_4K; tsize -= 2) { - unsigned long gfn_start, gfn_end; - tsize_pages = 1UL << (tsize - 2); - - gfn_start = gfn & ~(tsize_pages - 1); - gfn_end = gfn_start + tsize_pages; - - if (gfn_start + pfn - gfn < start) - continue; - if (gfn_end + pfn - gfn > end) - continue; - if ((gfn & (tsize_pages - 1)) != - (pfn & (tsize_pages - 1))) - continue; - - gvaddr &= ~((tsize_pages << PAGE_SHIFT) - 1); - pfn &= ~(tsize_pages - 1); - break; - } - } else if (vma && hva >= vma->vm_start && - is_vm_hugetlb_page(vma)) { - unsigned long psize = vma_kernel_pagesize(vma); - - tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >> - MAS1_TSIZE_SHIFT; - - /* - * Take the largest page size that satisfies both host - * and guest mapping - */ - tsize = min(__ilog2(psize) - 10, tsize); - - /* - * e500 doesn't implement the lowest tsize bit, - * or 1K pages. - */ - tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1); - } - - mmap_read_unlock(kvm->mm); - } - - if (likely(!pfnmap)) { - tsize_pages = 1UL << (tsize + 10 - PAGE_SHIFT); - pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, &writable, &page); - if (is_error_noslot_pfn(pfn)) { - if (printk_ratelimit()) - pr_err("%s: real page not found for gfn %lx\n", - __func__, (long)gfn); - return -EINVAL; - } - - /* Align guest and physical address to page map boundaries */ - pfn &= ~(tsize_pages - 1); - gvaddr &= ~((tsize_pages << PAGE_SHIFT) - 1); + pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, &writable, &page); + if (is_error_noslot_pfn(pfn)) { + if (printk_ratelimit()) + pr_err("%s: real page not found for gfn %lx\n", + __func__, (long)gfn); + return -EINVAL; } spin_lock(&kvm->mmu_lock); @@ -478,7 +378,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, * can't run hence pfn won't change. */ local_irq_save(flags); - ptep = find_linux_pte(pgdir, hva, NULL, NULL); + ptep = find_linux_pte(pgdir, hva, NULL, &psize); if (ptep) { pte_t pte = READ_ONCE(*ptep); @@ -495,6 +395,66 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, } local_irq_restore(flags); + if (psize && tlbsel == 1) { + unsigned long psize_pages, tsize_pages; + unsigned long start, end; + unsigned long slot_start, slot_end; + + psize_pages = 1UL << (psize - PAGE_SHIFT); + start = pfn & ~(psize_pages - 1); + end = start + psize_pages; + + slot_start = pfn - (gfn - slot->base_gfn); + slot_end = slot_start + slot->npages; + + if (start < slot_start) + start = slot_start; + if (end > slot_end) + end = slot_end; + + tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >> + MAS1_TSIZE_SHIFT; + + /* + * Any page size that doesn't satisfy the host mapping + * will fail the start and end tests. + */ + tsize = min(psize - PAGE_SHIFT + BOOK3E_PAGESZ_4K, tsize); + + /* + * e500 doesn't implement the lowest tsize bit, + * or 1K pages. + */ + tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1); + + /* + * Now find the largest tsize (up to what the guest + * requested) that will cover gfn, stay within the + * range, and for which gfn and pfn are mutually + * aligned. + */ + + for (; tsize > BOOK3E_PAGESZ_4K; tsize -= 2) { + unsigned long gfn_start, gfn_end; + tsize_pages = 1UL << (tsize - 2); + + gfn_start = gfn & ~(tsize_pages - 1); + gfn_end = gfn_start + tsize_pages; + + if (gfn_start + pfn - gfn < start) + continue; + if (gfn_end + pfn - gfn > end) + continue; + if ((gfn & (tsize_pages - 1)) != + (pfn & (tsize_pages - 1))) + continue; + + gvaddr &= ~((tsize_pages << PAGE_SHIFT) - 1); + pfn &= ~(tsize_pages - 1); + break; + } + } + kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg, writable); kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize, ref, gvaddr, stlbe);