Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3082656iob; Mon, 16 May 2022 12:41:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPJAOy4ROOJW3tc/c6LC7ld1yL9h4aH+gHat7DaQM3G4LYx8ww64rNp53n0N0yyTCwDJ2/ X-Received: by 2002:a05:6402:322a:b0:42a:a0b9:1459 with SMTP id g42-20020a056402322a00b0042aa0b91459mr12025488eda.134.1652730075366; Mon, 16 May 2022 12:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652730075; cv=none; d=google.com; s=arc-20160816; b=BEFrp0ycubKBX0QftJVMGGnyi8+yqFWHnGsm2x8WhP6KeOsePGdceFiKSSoJCkW4zp lHUEajLnjM0ZcYSCNjCZ7rhw5q8NdzG+P5pH/O2dwzKyooIpb+icrCM3TttKkyDYcX7u VCgUvCCd5tBwnkt3mZqPJw+oYQWYyNXMUMibPfS/7FszjisJUqd5V31yisHJfkX+QmXW XGEng+HvBI7m7/ZFzpLErnWfphz7jK9wgz/xpZbnMaRc7MhjhBCI4fK9nfMB+ucfXNBz ajFU9xaycA2Wkxf6zO171sxUPkppy2L/UoW6TQAW0nIp5tspzBUY9NveNlP2OxmsyusC VtXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9C8bpp6d21XdJaEwrvELDm0aYiNE+NJR0NE35SfqoPw=; b=GHlHqsEeyduDNZQk/BbF9Ma5Ml5hFaAm2SGanFZ3WsZe5R3HYWM9/qyozSSO+kA3np Xt1n6Eim6bG/diYTJOxL3xUNoQZie7evaF2iPgnRVzAIPnUin+YNSLPy1IlnPJmZoJPW 2z/j0X02Xgm+o5lQBgcP9EqYok9Cn1Fq/0zPlycdP+gtarcWMfmNF2a4cU3M4PIyzyJB fRB4pEAusjiTJx6o88attJZxyfzSIue8s9rL68oTTbUcMju6DdxfhJL/V1HhnwQSvDDc rWlIz3WspAhLLkxBsopVdSGCmTSRL6g9e2nJNzjcEv71bHYMXWCb6/hDbitHW2BJFvAx i1rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JOhFs1aN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i18-20020a05640242d200b0041d76544adcsi13509384edc.542.2022.05.16.12.40.49; Mon, 16 May 2022 12:41:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JOhFs1aN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344881AbiEPSbk (ORCPT + 99 others); Mon, 16 May 2022 14:31:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344948AbiEPSbX (ORCPT ); Mon, 16 May 2022 14:31:23 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C4A3E5E3 for ; Mon, 16 May 2022 11:31:02 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id y41so14764443pfw.12 for ; Mon, 16 May 2022 11:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=9C8bpp6d21XdJaEwrvELDm0aYiNE+NJR0NE35SfqoPw=; b=JOhFs1aNvRIY7bmGE74VDs+kZuh4q3JIlp+QrRMyFp/PLiOT8r/3UwgXQt6bqHPI65 NNYmecm+jORBOX+gKz9WJLCJGXE8LtJQC5YL5L0PG2VmJTEBS8s7+BEqGJwsS/8+CAYW nVtpgMTT9AXF2n5UP9Os5QjiIR9UeLBr/gS7D8XWO4BYz4RxM7rWHE32W8yus+feXD/Q 6c9Ngj5rWTW8OVkRdB4rlL0vYTmsqa2mDT/HwyIbkm1tp/SHRbUR9Gaw11RKuYsiNckv aWfNEoZFgG65UKfiNR9mOJwX/KkL4MaqZDcAOWzWPHerMRs6yhZwBq+5tbLfJvRRz/ie gAKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=9C8bpp6d21XdJaEwrvELDm0aYiNE+NJR0NE35SfqoPw=; b=pR8Zuv4eNAHIRD+I12J+LozIN5Y1Z5HBalNuXulqcjXQAlbnSB1wVrSzQXTTscqcyx Ny8X6NqSB5LYf0MM7jr7EgWRqsCk9k8KdKkMNlNEJytTRt3LwvrVmJyReg4DzPoIlPig vqFqPcY8sGu5I/ODTR0VbA8QJ64Y2fI1ge67HKodl4m6yLhMt2n8E30H2djE/CYSnL48 miLggmVnr+sS+aOBUqkIUraEk0Nx8+JwR25kK58HJq2pitL//oGy9Q6OM977yUH6LQwz 4tZ2W/sba29KTn6UZPV/Aos+Fi+q7AjYwQyZ5XDEH04DxLCHK1kJr44OoNwk5rZyxsJ3 hTmg== X-Gm-Message-State: AOAM531NrT8MltbbhaGiWpp0SaBr0wwHqjHG9HR0PnZTlF6+GkooCKWg cJ7voOUI+LgKeyz+xjMxGLGiXSvFrMpZmG70jhLL5A== X-Received: by 2002:a65:4581:0:b0:3f2:638f:6f76 with SMTP id o1-20020a654581000000b003f2638f6f76mr6735655pgq.324.1652725861290; Mon, 16 May 2022 11:31:01 -0700 (PDT) MIME-Version: 1.0 References: <20220502233853.1233742-1-rananta@google.com> <878rri8r78.wl-maz@kernel.org> <878rriicez.wl-maz@kernel.org> <87ilq55swj.wl-maz@kernel.org> In-Reply-To: <87ilq55swj.wl-maz@kernel.org> From: Raghavendra Rao Ananta Date: Mon, 16 May 2022 11:30:48 -0700 Message-ID: Subject: Re: [PATCH v7 0/9] KVM: arm64: Add support for hypercall services selection To: Marc Zyngier Cc: Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 16, 2022 at 9:44 AM Marc Zyngier wrote: > > On Tue, 03 May 2022 22:09:29 +0100, > Raghavendra Rao Ananta wrote: > > > > On Tue, May 3, 2022 at 1:33 PM Marc Zyngier wrote: > > > > > > On Tue, 03 May 2022 19:49:13 +0100, > > > Raghavendra Rao Ananta wrote: > > > > > > > > Hi Marc, > > > > > > > > On Tue, May 3, 2022 at 10:24 AM Marc Zyngier wrote= : > > > > > > > > > > On Tue, 03 May 2022 00:38:44 +0100, > > > > > Raghavendra Rao Ananta wrote: > > > > > > > > > > > > Hello, > > > > > > > > > > > > Continuing the discussion from [1], the series tries to add sup= port > > > > > > for the userspace to elect the hypercall services that it wishe= s > > > > > > to expose to the guest, rather than the guest discovering them > > > > > > unconditionally. The idea employed by the series was taken from > > > > > > [1] as suggested by Marc Z. > > > > > > > > > > As it took some time to get there, and that there was still a bun= ch of > > > > > things to address, I've taken the liberty to apply my own fixes t= o the > > > > > series. > > > > > > > > > > Please have a look at [1], and let me know if you're OK with the > > > > > result. If you are, I'll merge the series for 5.19. > > > > > > > > > > Thanks, > > > > > > > > > > M. > > > > > > > > > Thank you for speeding up the process; appreciate it. However, the > > > > series's selftest patches have a dependency on Oliver's > > > > PSCI_SYSTEM_SUSPEND's selftest patches [1][2]. Can we pull them in > > > > too? > > > > > > Urgh... I guess this is the time to set some ground rules: > > > > > > - Please don't introduce dependencies between series, that's > > > unmanageable. I really need to see each series independently, and i= f > > > there is a merge conflict, that's my job to fix (and I don't really > > > mind). > > > > > > - If there is a dependency between series, please post a version of > > > the required patches as a prefix to your series, assuming this > > > prefix is itself standalone. If it isn't, then something really is > > > wrong, and the series should be resplit. > > > > > > - You also should be basing your series on an *official* tag from > > > Linus' tree (preferably -rc1, -rc2 or -rc3), and not something > > > random like any odd commit from the KVM tree (I had conflicts while > > > applying this on -rc3, probably due to the non-advertised dependenc= y > > > on Oliver's series). > > > > > Thanks for picking the dependency patches. I'll keep these mind the > > next time I push changes. > > > > > > > > > > aarch64/hypercalls.c: In function =E2=80=98guest_test_hvc=E2=80=99: > > > > aarch64/hypercalls.c:95:30: error: storage size of =E2=80=98res=E2= =80=99 isn=E2=80=99t known > > > > 95 | struct arm_smccc_res res; > > > > | ^~~ > > > > aarch64/hypercalls.c:103:17: warning: implicit declaration of funct= ion > > > > =E2=80=98smccc_hvc=E2=80=99 [-Wimplicit-function-declaration] > > > > 103 | smccc_hvc(hc_info->func_id, hc_info->arg1, = 0, > > > > 0, 0, 0, 0, 0, &res); > > > > | ^~~~~~~~~ > > > > > > > > > > I've picked the two patches, which means they will most likely appear > > > twice in the history. In the future, please reach out so that we can > > > organise this better. > > > > > > > Also, just a couple of readability nits in the fixed version: > > > > > > > > 1. Patch-2/9, hypercall.c:kvm_hvc_call_default_allowed(), in the > > > > 'default' case, do you think we should probably add a small comment > > > > that mentions we are checking for func_id in the PSCI range? > > > > > > Dumped a one-liner there. > > > > > > > 2. Patch-2/9, arm_hypercall.h, clear all the macros in this patch > > > > itself instead of doing it in increments (unless there's some reaso= n > > > > that I'm missing)? > > > > > > Ah, rebasing leftovers, now gone. > > > > > > I've pushed an updated branch again, please have a look. > > > > > Thanks for addressing these. The series looks good now. > > Except it doesn't. > > I introduced a bug by overly simplifying kvm_arm_set_fw_reg_bmap(), as > we have to allow userspace writing the *same* value. As it turns out, > QEMU restores all the registers on each reboot. Which as the vcpus > have all run. This in turns triggers another issue in QEMU, which > instead of taking the hint ans stopping there, sends all the vcpus > into the guest in one go with random states... Crap happens. > > I'll wear a brown paper bag for the rest of the day and add the > following patch to the branch. > > Thanks, > > M. > > From 528ada2811ba0bb2b2db5bf0f829b48c50f3c13c Mon Sep 17 00:00:00 2001 > From: Marc Zyngier > Date: Mon, 16 May 2022 17:32:54 +0100 > Subject: [PATCH] KVM: arm64: Fix hypercall bitmap writeback when vcpus ha= ve > already run > > We generally want to disallow hypercall bitmaps being changed > once vcpus have already run. But we must allow the write if > the written value is unchanged so that userspace can rewrite > the register file on reboot, for example. > > Without this, a QEMU-based VM will fail to reboot correctly. > > The original code was correct, and it is me that introduced > the regression. > > Fixes: 05714cab7d63 ("KVM: arm64: Setup a framework for hypercall bitmap = firmware registers") > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/hypercalls.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c > index ccbd3cefb91a..c9f401fa01a9 100644 > --- a/arch/arm64/kvm/hypercalls.c > +++ b/arch/arm64/kvm/hypercalls.c > @@ -379,7 +379,8 @@ static int kvm_arm_set_fw_reg_bmap(struct kvm_vcpu *v= cpu, u64 reg_id, u64 val) > > mutex_lock(&kvm->lock); > > - if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags)) { > + if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags) && > + val !=3D *fw_reg_bmap) { > ret =3D -EBUSY; > goto out; > } Ha, not your fault. We have been going back and forth on this aspect of the design. Thanks for correcting this. However, since this changes the API behavior, I think we may have to amend the documentation as well: diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rs= t index b5ccec4572d7..ab04979bf104 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -2615,7 +2615,8 @@ KVM_SET_ONE_REG. Note: These registers are immutable once any of the vCPUs of the VM has run at least once. A KVM_SET_ONE_REG in such a scenario will return -a -EBUSY to userspace. +a -EBUSY to userspace if there's an update in the bitmap. If there's no +change in the value, it'll simply return a 0. (See Documentation/virt/kvm/arm/hypercalls.rst for more details.) diff --git a/Documentation/virt/kvm/arm/hypercalls.rst b/Documentation/virt/kvm/arm/hypercalls.rst index 3e23084644ba..275f4dbe5792 100644 --- a/Documentation/virt/kvm/arm/hypercalls.rst +++ b/Documentation/virt/kvm/arm/hypercalls.rst @@ -91,9 +91,10 @@ desired bitmap back via SET_ONE_REG. The features for the registers that are untouched, probably because userspace isn't aware of them, will be exposed as is to the guest. -Note that KVM will not allow the userspace to configure the registers -anymore once any of the vCPUs has run at least once. Instead, it will -return a -EBUSY. +Note that KVM will not allow the userspace to update the registers +with a new value anymore once any of the vCPUs has run at least once, +and will return a -EBUSY. However, a 'write' of the previously configured +value is allowed and returns a 0. The pseudo-firmware bitmap register are as follows: @@ -129,10 +130,10 @@ The pseudo-firmware bitmap register are as follows: Errors: - =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -ENOENT Unknown register accessed. - -EBUSY Attempt a 'write' to the register after the VM has started. + -EBUSY Attempt to update the register bitmap after the VM has start= ed. -EINVAL Invalid bitmap written to the register. - =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D .. [1] https://developer.arm.com/-/media/developer/pdf/ARM_DEN_0070A_Firmw= are_interfaces_for_mitigating_CVE-2017-5715.pdf Thank you. Raghavendra > -- > 2.34.1 > > > -- > Without deviation from the norm, progress is not possible.