From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicholas Piggin Date: Thu, 04 Mar 2021 11:02:49 +0000 Subject: Re: [PATCH v2 28/37] KVM: PPC: Book3S HV P9: Add helpers for OS SPR handling Message-Id: <1614855554.y6ukh6cl5v.astroid@bobo.none> List-Id: References: <20210225134652.2127648-1-npiggin@gmail.com> <20210225134652.2127648-29-npiggin@gmail.com> <87pn0hwq9f.fsf@linux.ibm.com> In-Reply-To: <87pn0hwq9f.fsf@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Fabiano Rosas , kvm-ppc@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Excerpts from Fabiano Rosas's message of March 3, 2021 1:04 am: > Nicholas Piggin writes: > >> This is a first step to wrapping supervisor and user SPR saving and >> loading up into helpers, which will then be called independently in >> bare metal and nested HV cases in order to optimise SPR access. >> >> Signed-off-by: Nicholas Piggin >> --- > > > >> +/* vcpu guest regs must already be saved */ >> +static void restore_p9_host_os_sprs(struct kvm_vcpu *vcpu, >> + struct p9_host_os_sprs *host_os_sprs) >> +{ >> + mtspr(SPRN_PSPB, 0); >> + mtspr(SPRN_WORT, 0); >> + mtspr(SPRN_UAMOR, 0); >> + mtspr(SPRN_PSPB, 0); > > Not your fault, but PSPB is set twice here. Yeah you're right. >> + >> + mtspr(SPRN_DSCR, host_os_sprs->dscr); >> + mtspr(SPRN_TIDR, host_os_sprs->tidr); >> + mtspr(SPRN_IAMR, host_os_sprs->iamr); >> + >> + if (host_os_sprs->amr != vcpu->arch.amr) >> + mtspr(SPRN_AMR, host_os_sprs->amr); >> + >> + if (host_os_sprs->fscr != vcpu->arch.fscr) >> + mtspr(SPRN_FSCR, host_os_sprs->fscr); >> +} >> + > > > >> @@ -3605,34 +3666,10 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, >> vcpu->arch.dec_expires = dec + tb; >> vcpu->cpu = -1; >> vcpu->arch.thread_cpu = -1; >> - vcpu->arch.ctrl = mfspr(SPRN_CTRLF); >> - >> - vcpu->arch.iamr = mfspr(SPRN_IAMR); >> - vcpu->arch.pspb = mfspr(SPRN_PSPB); >> - vcpu->arch.fscr = mfspr(SPRN_FSCR); >> - vcpu->arch.tar = mfspr(SPRN_TAR); >> - vcpu->arch.ebbhr = mfspr(SPRN_EBBHR); >> - vcpu->arch.ebbrr = mfspr(SPRN_EBBRR); >> - vcpu->arch.bescr = mfspr(SPRN_BESCR); >> - vcpu->arch.wort = mfspr(SPRN_WORT); >> - vcpu->arch.tid = mfspr(SPRN_TIDR); >> - vcpu->arch.amr = mfspr(SPRN_AMR); >> - vcpu->arch.uamor = mfspr(SPRN_UAMOR); >> - vcpu->arch.dscr = mfspr(SPRN_DSCR); >> - >> - mtspr(SPRN_PSPB, 0); >> - mtspr(SPRN_WORT, 0); >> - mtspr(SPRN_UAMOR, 0); >> - mtspr(SPRN_DSCR, host_dscr); >> - mtspr(SPRN_TIDR, host_tidr); >> - mtspr(SPRN_IAMR, host_iamr); >> - mtspr(SPRN_PSPB, 0); >> >> - if (host_amr != vcpu->arch.amr) >> - mtspr(SPRN_AMR, host_amr); >> + restore_p9_host_os_sprs(vcpu, &host_os_sprs); >> >> - if (host_fscr != vcpu->arch.fscr) >> - mtspr(SPRN_FSCR, host_fscr); >> + store_spr_state(vcpu); > > store_spr_state should come first, right? We want to save the guest > state before restoring the host state. Yes good catch. I switched that back around later but looks like I never brought the fix back to the right patch. Interestingly, things pretty much work like this if the guest or host doesn't do anything much with the SPRs! Thanks, Nick From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F665C433E6 for ; Thu, 4 Mar 2021 11:03:32 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5341464F2B for ; Thu, 4 Mar 2021 11:03:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5341464F2B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4DrnzP3SZ4z3cn2 for ; Thu, 4 Mar 2021 22:03:29 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VG/4OHrD; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VG/4OHrD; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Drnyw4Brzz3cYD for ; Thu, 4 Mar 2021 22:03:03 +1100 (AEDT) Received: by mail-pf1-x42d.google.com with SMTP id 192so11657568pfv.0 for ; Thu, 04 Mar 2021 03:03:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :message-id:content-transfer-encoding; bh=+gWRxcdUXMQou9ziU1lKLrEon8VwgQT0NWd6SS7G4WA=; b=VG/4OHrDaovLA3OwfWlPeMGZwqwJmibuMwD9pS1rOUXRvuUoHHwifAksU4b05zfxTa tsjvOXmESHzDbxC9GpjoCmjTkhLU3dwTQgfzRVDCgTkDE+ghjMThKSw73l7cQ5/SbLEt IoXUrWyPXtV16vrq4YZAxMXUwL9PsvkGLbYDzngCtHQkXl1CxFZ7g7/CguAWwGxoz+80 vkvzWHLNSWCn6mrr/epHi2uc9dyMLSPbsHHQIfZIiWhGUnpuHCkRhmyNGQolgCoj/A+h u2o9Ec42TjIY+KhUfNhkhlI75Cp8u37JqSx3JYwLSzdu033xWfpoQ6CSRjNsAjAoGjAX kFdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=+gWRxcdUXMQou9ziU1lKLrEon8VwgQT0NWd6SS7G4WA=; b=pTDlYOJd27vo37210a1lQAjokD9IoBMNyuAeMvXxnYimfkFtz5p/cFHkYDXUco8UHi 6djqcEOyo1KW1ukrMAudgj8yHFVygqTkGaxXflBK4AaV3flBGX8QRbyaRLkFdO5VzYys Ib7bAaHOQo6XWgdRZr8Z9s/yNd4IECcKWk5sZm/ZPG8KljyGc6/XVCBbxMFagxFMBl3i 3L5QWDvOYIKSkQ3SwdUawDgkVnpwyGlwST8GlzXFqhs0ohxhF5mgVo/9kjCW1aARZc9I dzJn69BiVI0k7GXw6iG9Zp32CDVY7kHuqXlqpPbenWRMavIENUcHxGZ3cm/xvk1KjQHu yvOA== X-Gm-Message-State: AOAM533FnKt40emAPgBMmpgNNjMCCrmfhDDBrGfnyvEwSWSGw+1g4esv N68aKiY0roYg2iFpx82GA5A= X-Google-Smtp-Source: ABdhPJw7HGv6gZKtEV1R5UJu3lP8PDz4gVRtiwaqTD13kyQhdKUKNvA25N45gXzYzF1JzriQeZbPTA== X-Received: by 2002:a05:6a00:22d1:b029:1b4:9bb5:724c with SMTP id f17-20020a056a0022d1b02901b49bb5724cmr3667161pfj.63.1614855776615; Thu, 04 Mar 2021 03:02:56 -0800 (PST) Received: from localhost (58-6-239-121.tpgi.com.au. [58.6.239.121]) by smtp.gmail.com with ESMTPSA id n24sm2591073pgl.27.2021.03.04.03.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 03:02:55 -0800 (PST) Date: Thu, 04 Mar 2021 21:02:49 +1000 From: Nicholas Piggin Subject: Re: [PATCH v2 28/37] KVM: PPC: Book3S HV P9: Add helpers for OS SPR handling To: Fabiano Rosas , kvm-ppc@vger.kernel.org References: <20210225134652.2127648-1-npiggin@gmail.com> <20210225134652.2127648-29-npiggin@gmail.com> <87pn0hwq9f.fsf@linux.ibm.com> In-Reply-To: <87pn0hwq9f.fsf@linux.ibm.com> MIME-Version: 1.0 Message-Id: <1614855554.y6ukh6cl5v.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Excerpts from Fabiano Rosas's message of March 3, 2021 1:04 am: > Nicholas Piggin writes: >=20 >> This is a first step to wrapping supervisor and user SPR saving and >> loading up into helpers, which will then be called independently in >> bare metal and nested HV cases in order to optimise SPR access. >> >> Signed-off-by: Nicholas Piggin >> --- >=20 > >=20 >> +/* vcpu guest regs must already be saved */ >> +static void restore_p9_host_os_sprs(struct kvm_vcpu *vcpu, >> + struct p9_host_os_sprs *host_os_sprs) >> +{ >> + mtspr(SPRN_PSPB, 0); >> + mtspr(SPRN_WORT, 0); >> + mtspr(SPRN_UAMOR, 0); >> + mtspr(SPRN_PSPB, 0); >=20 > Not your fault, but PSPB is set twice here. Yeah you're right. >> + >> + mtspr(SPRN_DSCR, host_os_sprs->dscr); >> + mtspr(SPRN_TIDR, host_os_sprs->tidr); >> + mtspr(SPRN_IAMR, host_os_sprs->iamr); >> + >> + if (host_os_sprs->amr !=3D vcpu->arch.amr) >> + mtspr(SPRN_AMR, host_os_sprs->amr); >> + >> + if (host_os_sprs->fscr !=3D vcpu->arch.fscr) >> + mtspr(SPRN_FSCR, host_os_sprs->fscr); >> +} >> + >=20 > >=20 >> @@ -3605,34 +3666,10 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu = *vcpu, u64 time_limit, >> vcpu->arch.dec_expires =3D dec + tb; >> vcpu->cpu =3D -1; >> vcpu->arch.thread_cpu =3D -1; >> - vcpu->arch.ctrl =3D mfspr(SPRN_CTRLF); >> - >> - vcpu->arch.iamr =3D mfspr(SPRN_IAMR); >> - vcpu->arch.pspb =3D mfspr(SPRN_PSPB); >> - vcpu->arch.fscr =3D mfspr(SPRN_FSCR); >> - vcpu->arch.tar =3D mfspr(SPRN_TAR); >> - vcpu->arch.ebbhr =3D mfspr(SPRN_EBBHR); >> - vcpu->arch.ebbrr =3D mfspr(SPRN_EBBRR); >> - vcpu->arch.bescr =3D mfspr(SPRN_BESCR); >> - vcpu->arch.wort =3D mfspr(SPRN_WORT); >> - vcpu->arch.tid =3D mfspr(SPRN_TIDR); >> - vcpu->arch.amr =3D mfspr(SPRN_AMR); >> - vcpu->arch.uamor =3D mfspr(SPRN_UAMOR); >> - vcpu->arch.dscr =3D mfspr(SPRN_DSCR); >> - >> - mtspr(SPRN_PSPB, 0); >> - mtspr(SPRN_WORT, 0); >> - mtspr(SPRN_UAMOR, 0); >> - mtspr(SPRN_DSCR, host_dscr); >> - mtspr(SPRN_TIDR, host_tidr); >> - mtspr(SPRN_IAMR, host_iamr); >> - mtspr(SPRN_PSPB, 0); >> >> - if (host_amr !=3D vcpu->arch.amr) >> - mtspr(SPRN_AMR, host_amr); >> + restore_p9_host_os_sprs(vcpu, &host_os_sprs); >> >> - if (host_fscr !=3D vcpu->arch.fscr) >> - mtspr(SPRN_FSCR, host_fscr); >> + store_spr_state(vcpu); >=20 > store_spr_state should come first, right? We want to save the guest > state before restoring the host state. Yes good catch. I switched that back around later but looks like I never brought the fix back to the right patch. Interestingly, things=20 pretty much work like this if the guest or host doesn't do anything much with the SPRs! Thanks, Nick