Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp800186rwb; Thu, 18 Aug 2022 12:26:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR5nvuTQRF7RjBY+qMn7ZuYSeIbhQlO0lSWCNFWfyQkKaCG5TV4lLIp7horeKT6WSGB6lTpM X-Received: by 2002:a17:907:2bd6:b0:730:a2f7:f885 with SMTP id gv22-20020a1709072bd600b00730a2f7f885mr2773976ejc.214.1660850814087; Thu, 18 Aug 2022 12:26:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660850814; cv=none; d=google.com; s=arc-20160816; b=P4d0iRp1L6PoJ7gTJLsoZf7W80mGHc9hOCfBhG3ZF/MkEQMT0QUjKv8AXBVjoiBA16 cpnFD1OYEtJ174l46zT7xSXnvVN/8j2WwweobxOuzyvPQeItQ8Xd3ssE63FW8buyH8ZY uequSpx9v6v+XsX9c0GmHxIFO7G9qne4BQWNWNiVFN5OGJmjHP6b/g5JRd0DSluM7bxd 8NI4IR6XJesj/cY6s0coH0347OkpDpcTvSKpnAJobZPNW+/QrQNIy+EIr+lQ5x/Mdg7D Bmtjgg27R4Pgx+gKeGY/8YNxYnWBtAepKUSGie0fmOq1XAoXfqZhyfi0T0IrpDygeDJj /lHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=NLXxzLfpertkCh7pqMuyBZ0dtciDt6C/zyyyhRKQC5k=; b=QZs/unAuWMJBzWyDsgFIVsQczeSyubIpTvHd0GCMgaxgqhBdWw8vLhwsX3zs+m1oMM iAjMNtWHN3qKz3o7mp+r22d01d8yoxJ959/raiBQId5+c+DPLo93GCy0nkANYIOducCV zoMZXZyelTYpz9+yvQ7tsgMTFH8mmVn4xs6V1foFqEwg8F9O4PhQG00+VeMzzIxLfE4m v1AXFnTqYyPGfmUZnWMb5sTk0HhQWQ2esyPTqonYvJC93/yUwTgts92RxuaLXbpIkBRi Wa0Bx6MJLSdTIIl0Uq5Dhm28Ue76b1nEtlcBOapUOo7rPeSjoqHLE2+3JvfxdH6gdi9o Tkqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QbDRhjd3; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i19-20020a170906851300b0073053b85cf8si1403211ejx.364.2022.08.18.12.26.26; Thu, 18 Aug 2022 12:26:54 -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=@linux.dev header.s=key1 header.b=QbDRhjd3; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345428AbiHRTFU (ORCPT + 99 others); Thu, 18 Aug 2022 15:05:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233465AbiHRTFT (ORCPT ); Thu, 18 Aug 2022 15:05:19 -0400 Received: from out1.migadu.com (out1.migadu.com [IPv6:2001:41d0:2:863f::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5D07B959D; Thu, 18 Aug 2022 12:05:17 -0700 (PDT) Date: Thu, 18 Aug 2022 21:05:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1660849515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NLXxzLfpertkCh7pqMuyBZ0dtciDt6C/zyyyhRKQC5k=; b=QbDRhjd3503yNjCD2mOOhYXLkQ2FBbucLznvFoZTl5FUXbmKCok/YevU8XVEOKaMib5vTU 3ElBIrnxbnHrsmPs8ejqKTk124Phc1ETIGOKc/2b30+8XKh9/QAfMuOOl6b7toR4o8vd0h ebKKD+PNN1PJv8geoltKMbA6iN1Jh8c= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Andrew Jones To: Sean Christopherson Cc: Peter Gonda , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, marcorr@google.com, michael.roth@amd.com, thomas.lendacky@amd.com, joro@8bytes.org, mizhang@google.com, pbonzini@redhat.com, vannapurve@google.com Subject: Re: [V3 10/11] KVM: selftests: Add ucall pool based implementation Message-ID: <20220818190514.ny77xpfwiruah6m5@kamzik> References: <20220810152033.946942-1-pgonda@google.com> <20220810152033.946942-11-pgonda@google.com> <20220816161350.b7x5brnyz5pyi7te@kamzik> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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, Aug 18, 2022 at 04:00:40PM +0000, Sean Christopherson wrote: > On Tue, Aug 16, 2022, Andrew Jones wrote: > > On Wed, Aug 10, 2022 at 08:20:32AM -0700, Peter Gonda wrote: > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > > index 132c0e98bf49..ee70531e8e51 100644 > > > --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > > +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > > @@ -81,12 +81,16 @@ void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) > > > > > > if (run->exit_reason == KVM_EXIT_MMIO && > > > run->mmio.phys_addr == (uint64_t)ucall_exit_mmio_addr) { > > > - vm_vaddr_t gva; > > > + uint64_t ucall_addr; > > > > Why change this vm_vaddr_t to a uint64_t? We shouldn't, because... > > > > > > > > TEST_ASSERT(run->mmio.is_write && run->mmio.len == 8, > > > "Unexpected ucall exit mmio address access"); > > > - memcpy(&gva, run->mmio.data, sizeof(gva)); > > > - return addr_gva2hva(vcpu->vm, gva); > > > + memcpy(&ucall_addr, run->mmio.data, sizeof(ucall_addr)); > > > > ...here we assume it's a vm_vaddr_t and only... > > > > > + > > > + if (vcpu->vm->use_ucall_pool) > > > + return (void *)ucall_addr; > > > > ...here do we know otherwise. So only here should be any casting. > > It technically should be a union, because if sizeof(vm_vaddr_t) < sizeof(void *) > then declaring it as a vm_addr_t will do the wrong thing. But then it's possible > that this could read too many bytes and inducs failure. So I guess what we really > need is a "static_assert(sizeof(vm_vaddr_t) == sizeof(void *))". ack > > But why is "use_ucall_pool" optional? Unless there's a use case that fundamentally > conflicts with the pool approach, let's make the pool approach the _only_ approach. > IIRC, ARM's implementation isn't thread safe, i.e. there's at least one other use > case that _needs_ the pool implementation. Really? The ucall structure is on the vcpu's stack like the other architectures. Ah, you're probably thinking about the shared address used to exit to userspace. The address doesn't matter as long as no VM maps it, but, yes, a multi-VM test where the VMs have different maps could end up breaking ucalls for one or more VMs. It wouldn't be hard to make that address per-VM, though, if ever necessary. > > By supporting both, we are signing ourselves up for extra maintenance and pain, > e.g. inevitably we'll break whichever option isn't the default and not notice for > quite some time. uc pools are currently limited to a single VM. That could be changed, but at the expense of even more code to maintain. The simple uc implementation is, well, simple, and also supports multiple VMs. I'd prefer we keep that one and keep it as the default. Thanks, drew