Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp943383pxw; Sat, 9 Apr 2022 06:03:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySDvhx+zIFgkpZRwBWN9fkBdDc/Cup/ohLn6yZ9kGu82CUuP/Z2BVsL1rD4cKBYw7gl2+v X-Received: by 2002:a05:6e02:190f:b0:2c6:74aa:cc73 with SMTP id w15-20020a056e02190f00b002c674aacc73mr9675170ilu.29.1649509411082; Sat, 09 Apr 2022 06:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649509411; cv=none; d=google.com; s=arc-20160816; b=J/aJN3V0f08cvCkKej2i7womfNt6Xjp6nQTssoyV2tsIgD3yTJhoXKQDbqPLNOtXTd YIxlnzJtnOvQWt3aPntz9j9Tk17bV2pxy0B+Tb59C0lkuLO2PQm9lhZSfFYSuJXER5Ce otJ6COayzKQuU92iSo5XSejhu6Thz5wTLSYAVF/enAebJbc5L76Ia2kNIy1/ZTC06GDf ys1MZ54OzE/wLwlt1vk0Pe3Kg0VLyRCFC9KweaB/gY6BwLvaM8mfmWAvgaz3MXCnpnrP avk1LhEyh6ix9APsg70kQnTf/pLxZ6r8+psw+QfH/PXWm8zTAZODC7l99pAKE2hoSAs7 uRpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=BkGdoHLswvpJjboCXfZgZ+85aeuWdeSvWIDJTg8hjJA=; b=c96LICxBWHPBGtZs9xV8UG/pdqx9/HpkagJcsZbGNcn+o8Nn7rbvybK4hst2x+dDbp DsL0NXjmW1WcGWP2ZcRx/vCiG0W75/5qiiWzM5lIoh8ykA/gPZeqJNI1lwOE2RU1rzv+ S7Uw0MBqwNRJJ/OW4+60+Noqo4mVPzbSKEpYGEASdgufl3lo+8ZY0UrXRxncFcP6aA0H kozljZCJ5823KJon52ql51hSwoD6G1NkIyJ7H+Zrch87CDLp7sPCu7Z65UmwuqcYskCc zD+k15VE0V7BHmVjKmDucurOr5KEeGvXCpIjkaGM+wmY7o1o44Jcm7eXMVhtkdVrcJr8 u2WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pJvyoIX8; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k7-20020a5d91c7000000b0064958084553si1713127ior.112.2022.04.09.06.03.09; Sat, 09 Apr 2022 06:03:31 -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=@kernel.org header.s=k20201202 header.b=pJvyoIX8; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236866AbiDHRB7 (ORCPT + 99 others); Fri, 8 Apr 2022 13:01:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbiDHRB6 (ORCPT ); Fri, 8 Apr 2022 13:01:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4483167F3; Fri, 8 Apr 2022 09:59:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CB4146215B; Fri, 8 Apr 2022 16:59:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DA17C385A3; Fri, 8 Apr 2022 16:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649437193; bh=hezvIR97K/d6etxHTUv4PJyXJtleS81JAhoNf2K+8hI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pJvyoIX8LUcDdClF6OFL1/JUuOZNt2xQp37DthOnlJeEXcZ56oLmJkFbQtZwerNyc OhbWw6+aLK6oGjqw6b25PfyzLj/AER9VlLmiAM+LQ/5i8MhbiDdri4zZWMHRT70gZb beYDmMBo+z6TAuKrplYTcbLyPGZ0hxlxcjjCAv4GZcfa7rmmNE0Tm8ScvVtZiDwK0/ HPUz15e3Z+HLPa200pCAwdmPKO8rqplGm8IR0Vt9Qf0SBL+hZjTlKybHoFqlK5ywtl +h7sEDyDqpVv9V7oeXyMTXXtQf9LODvrgCG8l409Qh2jN/UJJskyutVqSOhdcpYZEt bcpiteTImFr1A== Received: from sofa.misterjones.org ([185.219.108.64] helo=billy-the-mountain.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ncrxe-002pMe-Kb; Fri, 08 Apr 2022 17:59:50 +0100 Date: Fri, 08 Apr 2022 17:59:42 +0100 Message-ID: <87v8vj1pfl.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta 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 Subject: Re: [PATCH v5 02/10] KVM: arm64: Setup a framework for hypercall bitmap firmware registers In-Reply-To: References: <20220407011605.1966778-1-rananta@google.com> <20220407011605.1966778-3-rananta@google.com> <87ilrlb6un.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: rananta@google.com, drjones@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, pbonzini@redhat.com, catalin.marinas@arm.com, will@kernel.org, pshier@google.com, ricarkol@google.com, oupton@google.com, reijiw@google.com, jingzhangos@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Thu, 07 Apr 2022 18:24:14 +0100, Raghavendra Rao Ananta wrote: > > Hi Marc, > > > > +#define KVM_REG_ARM_STD_BIT_TRNG_V1_0 BIT(0) > > > > I'm really in two minds about this. Having one bit per service is easy > > from an implementation perspective, but is also means that this > > disallow fine grained control over which hypercalls are actually > > available. If tomorrow TRNG 1.1 adds a new hypercall and that KVM > > implements both, how does the selection mechanism works? You will > > need a version selector (a la PSCI), which defeats this API somehow > > (and renders the name of the #define invalid). > > > > I wonder if a more correct way to look at this is to enumerate the > > hypercalls themselves (all 5 of them), though coming up with an > > encoding is tricky (RNG32 and RNG64 would clash, for example). > > > > Thoughts? > > > I was on the fence about this too. The TRNG spec (ARM DEN 0098, > Table-4) mentions that v1.0 should have VERSION, FEATURES, GET_UUID, > and RND as mandatory features. Hence, if KVM advertised that it > supports TRNG v1.0, I thought it would be best to expose all or > nothing of v1.0 by guarding them with a single bit. > Broadly, the idea is to have a bit per version. If v1.1 comes along, > we can have another bit for that. If it's not too ugly to implement, > we can be a little more aggressive and ensure that userspace doesn't > enable v1.1 without enabling v1.0. OK, that'd be assuming that we'll never see a service where version A is incompatible with version B and that we have to exclude one or the other. Meh. Let's cross that bridge once it is actually built. [...] > > > + mutex_lock(&kvm->lock); > > > + > > > + /* > > > + * If the VM (any vCPU) has already started running, return success > > > + * if there's no change in the value. Else, return -EBUSY. > > > > No, this should *always* fail if a vcpu has started. Otherwise, you > > start allowing hard to spot races. > > > The idea came from the fact that userspace could spawn multiple > threads to configure the vCPU registers. Since we don't have the > VM-scoped registers yet, it may be possible that userspace has issued > a KVM_RUN on one of the vCPU, while the others are lagging behind and > still configuring the registers. The slower threads may see -EBUSY and > could panic. But if you feel that it's an overkill and the userspace > should deal with it, we can return EBUSY for all writes after KVM_RUN. I'd rather have that. There already is stuff that rely on things not changing once a vcpu has run, so I'd rather be consistent. > > > > + */ > > > + if (test_bit(KVM_ARCH_FLAG_HAS_RAN_ONCE, &kvm->arch.flags)) { > > > + ret = *fw_reg_bmap != val ? -EBUSY : 0; > > > + goto out; > > > + } > > > + > > > + WRITE_ONCE(*fw_reg_bmap, val); > > > > I'm not sure what this WRITE_ONCE guards against. Do you expect > > concurrent reads at this stage? > > > Again, the assumption here is that userspace could have multiple > threads reading and writing to these registers. Without the VM scoped > registers in place, we may end up with a read/write to the same memory > location for all the vCPUs. We only have one vcpu updating this at any given time (that's what the lock ensures). A simple write should be OK, as far as I can tell. Thanks, M. -- Without deviation from the norm, progress is not possible.