Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4673312rwo; Tue, 25 Jul 2023 09:16:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlF5jBReob+TuaMaE9jVI6tsCEtoXg/nOJr9UCnoj+ErKxENOW5AdrrnHgEDBA6Bye8JlFyp X-Received: by 2002:a17:906:218a:b0:997:eab5:f1c3 with SMTP id 10-20020a170906218a00b00997eab5f1c3mr10748398eju.73.1690301781168; Tue, 25 Jul 2023 09:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690301781; cv=none; d=google.com; s=arc-20160816; b=FymysZv5fPf/rlv0dAVFQoyAGs3159w2uWhQppax1EkJlpQQL8moOE15iLpjgLhltx abRN0UhzIGPoVt0DqH5x56f5VH+D4TfwX1PcUKa4PwjfXMUwoaqV2rEBYuBMLcO1z+El p7t8Ypk7rIVnIr+r3taY3mMrNo1N82XufHT9hjQVAhFDkhL3Nta0B9DDlwJJeXw6PtNr 4Voe+rfxGOWBrvyFYe3XypEa3uQ92/dzl2G1MbfFbO9+t0nguQ4QX+n7YglceKVF5hjw PSJqw3zbyPcGvOzYYmnJrTDCV5xKylHZK+Rzd7imKcrCSf6w8Ejd7ma2sCTQjiv1EizX rJGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=zJL188spEdf8jlBHFLQkEZlti0TXRFH+U5cu91h9YR8=; fh=zCmuo4oByQ99xPnrFoYR3gZOsS2Cm6yHYmSWExNNth0=; b=Jh1J6R9IlE2+71P9gJ4TPHeFX0S1r0i80B92DK0cEdwkTvq8WDFbGLJPmM1f7ALtjc 5XuOU3EXbfuuaXfzriH7Fv2kuxH0QO+B8PwflraKNQ6k3oyM49SINenVdMVb4I2R8c4w cDeVrekh9ycAfwbOIojTtm45wi+EcLwBdehM1iXiOsMu7wlVp7uCo8YF/0uQHaoKlpw+ LR1E0IPwEcydNpj/rAQ8wwsEVPDSRfI03n/BU9cKB8x4cIQggIAawMlkmz3Gf8aYcFQC Xf9Rn1WXjeFnOdQIeriqKrtpo+RvNQdjjqIYOa1Fp0oSRQbiwe4CRyME+0vCNDFbeHNN l3oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=SQwtCbch; 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 r16-20020a170906351000b0099b6c03e567si6713085eja.353.2023.07.25.09.15.56; Tue, 25 Jul 2023 09:16:21 -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=20221208 header.b=SQwtCbch; 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 S229877AbjGYPgP (ORCPT + 99 others); Tue, 25 Jul 2023 11:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbjGYPgN (ORCPT ); Tue, 25 Jul 2023 11:36:13 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34D151BF8 for ; Tue, 25 Jul 2023 08:36:12 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-58419550c3aso19125577b3.0 for ; Tue, 25 Jul 2023 08:36:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690299371; x=1690904171; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zJL188spEdf8jlBHFLQkEZlti0TXRFH+U5cu91h9YR8=; b=SQwtCbchLJBC6JVt0au7UKzD6DauTBO7Ht/6fLayaAtmMn1ddu11cTpSkwaJcaV44a NWDLUE0AHkMJ4OT/Wo7KKa/YKEmgrg0sjWJQN5tC7BKxnoeKzmpoqnaHQej2Uu5AZKaU MvfCkMQ/9S4mtrQujLRuCkTF6VGlYXZv0SHwd9+lehD/ByMW+ku5ouyZWo63QG79Jti3 dL/iU2UqJCVbtC1Tx31JmqLDfUvOX+276nwpWwK0qsvBNUuQKVklM8KpdqkZ/6XnBUk1 1RvPq2UqE4epZmu8AYwV6Qsx5xkIVtSB41MiB+RgQ3vXNb1HvKO7/DjgvM5UJNPUqDWt qGtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690299371; x=1690904171; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zJL188spEdf8jlBHFLQkEZlti0TXRFH+U5cu91h9YR8=; b=O5DDkxRmG3EROENdX2ZPXT2kUQ8xJvVxJGUYc4gcXoL6UJWtZq78BXWfo0Zl4HVjWo nNmeE2R8vYmORToSMK4J/8OpEdLgldn3ud4o2EKG5rZ5ABYqqb8oTZTRYQiEvEXBr7lK 0SbOb7SmoPcpA5a/NqiGYGYYgAR1RS0HgUb2i3bMNZABdK+25x7sRrQJObtlN4RKnDla XwXSHdSucoht+KjZJBWELpTpNzpCIEoF55JmcgvNsROoaIpGKfzLlcLIUctxllgKsfqU vhALW1YaYh8vNrCgCyaaL8QvUXOGUPwR9IaE++m16zhhd6OEWMvJkZkiv+PgqQNkyD5+ yZYA== X-Gm-Message-State: ABy/qLYbpWYVpCasHHC08lJi7GC5trB6dm8ULe16fThkwahvtpKljt+Z c3HTNjtfFEzfPQwfYTLDPucY1N4CRqk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:af21:0:b0:56c:e585:8b17 with SMTP id n33-20020a81af21000000b0056ce5858b17mr89738ywh.5.1690299371207; Tue, 25 Jul 2023 08:36:11 -0700 (PDT) Date: Tue, 25 Jul 2023 08:36:09 -0700 In-Reply-To: <9e8a98ad-1f8d-a09c-3173-71c5c3ab5ed4@intel.com> Mime-Version: 1.0 References: <8c0b7babbdd777a33acd4f6b0f831ae838037806.1689893403.git.isaku.yamahata@intel.com> <9e8a98ad-1f8d-a09c-3173-71c5c3ab5ed4@intel.com> Message-ID: Subject: Re: [RFC PATCH v4 09/10] KVM: x86: Make struct sev_cmd common for KVM_MEM_ENC_OP From: Sean Christopherson To: Xiaoyao Li Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , erdemaktas@google.com, Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, linux-coco@lists.linux.dev, Chao Peng , Ackerley Tng , Vishal Annapurve , Yuan Yao Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 Tue, Jul 25, 2023, Xiaoyao Li wrote: > On 7/21/2023 10:51 PM, Sean Christopherson wrote: > > On Thu, Jul 20, 2023, isaku.yamahata@intel.com wrote: > > > diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h > > > index aa7a56a47564..32883e520b00 100644 > > > --- a/arch/x86/include/uapi/asm/kvm.h > > > +++ b/arch/x86/include/uapi/asm/kvm.h > > > @@ -562,6 +562,39 @@ struct kvm_pmu_event_filter { > > > /* x86-specific KVM_EXIT_HYPERCALL flags. */ > > > #define KVM_EXIT_HYPERCALL_LONG_MODE BIT(0) > > > +struct kvm_mem_enc_cmd { > > > + /* sub-command id of KVM_MEM_ENC_OP. */ > > > + __u32 id; > > > + /* > > > + * Auxiliary flags for sub-command. If sub-command doesn't use it, > > > + * set zero. > > > + */ > > > + __u32 flags; > > > + /* > > > + * Data for sub-command. An immediate or a pointer to the actual > > > + * data in process virtual address. If sub-command doesn't use it, > > > + * set zero. > > > + */ > > > + __u64 data; > > > + /* > > > + * Supplemental error code in the case of error. > > > + * SEV error code from the PSP or TDX SEAMCALL status code. > > > + * The caller should set zero. > > > + */ > > > + union { > > > + struct { > > > + __u32 error; > > > + /* > > > + * KVM_SEV_LAUNCH_START and KVM_SEV_RECEIVE_START > > > + * require extra data. Not included in struct > > > + * kvm_sev_launch_start or struct kvm_sev_receive_start. > > > + */ > > > + __u32 sev_fd; > > > + }; > > > + __u64 error64; > > > + }; > > > +}; > > > > Eww. Why not just use an entirely different struct for TDX? I don't see what > > benefit this provides other than a warm fuzzy feeling that TDX and SEV share a > > struct. Practically speaking, KVM will likely take on more work to forcefully > > smush the two together than if they're separate things. > > generalizing the struct of KVM_MEM_ENC_OP should be the first step. It's not just the one structure though. The "data" field is a pointer to yet another layer of commands, and SEV has a rather big pile of those. Making kvm_mem_enc_cmd common is just putting lipstick on a pig since the vast majority of the structures associated with the ioctl() would still be vendor specific. struct kvm_sev_launch_start struct kvm_sev_launch_update_data struct kvm_sev_launch_secret struct kvm_sev_launch_measure struct kvm_sev_guest_status struct kvm_sev_dbg struct kvm_sev_attestation_report struct kvm_sev_send_start struct kvm_sev_send_update_data struct kvm_sev_receive_start struct kvm_sev_receive_update_data FWIW, I really dislike KVM's uAPI for KVM_MEM_ENC_OP. The above structures are all basically copied verbatim from PSP firmware structures, i.e. the commands and their payloads are tightly coupled to "hardware" and essentially have no abstraction whatsoever. But that ship has already sailed, and practically speaking trying to provide a layer of abstraction might not of worked very well anyways. In other words, unless there's an obvious and easy way path to convergence, I recommend you don't spend much time/effort on trying to share code with TDX.