Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1180666rwd; Thu, 8 Jun 2023 13:34:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SuozRiVuVQEjiYv5muy/GinPbXulPOfI4fgz/pn2H7cTkCGNZ/dFRfYKgSqwa0in4Xmyo X-Received: by 2002:a17:902:bcc5:b0:1b0:3d54:357d with SMTP id o5-20020a170902bcc500b001b03d54357dmr5208949pls.24.1686256466792; Thu, 08 Jun 2023 13:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686256466; cv=none; d=google.com; s=arc-20160816; b=lLTgIUOAHcAdM+kxCHqN1+DIEUujCIxBSN0mgZMxIF/dya7Ki6UBRgT3N2REcrl0em AM2SEIaNPKZYqbzMotMS3UrycDU39wtmHQRALoFi323zBTVFrP2HcCedpy0LyB22Mmy/ /wJk5enVWyvCD6Pq+jvzLxE2kNurBkSavOiceDAisbLmOU9lTnGf4OOYRBR3bSojOQ8t Vio5M85tm9CpLr4PMcz05hENFACrjQLlWEioKiBdRAIYw40ViY59mRz4rySmW/GROT0s sQRIsEN7tsIYXtsfpYweSYlq3qCkU4PpeHMlGB88C8NjemA6hnBZXkXLkbERe4DLH0tK J7ug== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=KaorFROknjCn9/iVhBQO9PAsd8HYdHVJN5C9ENR6YJY=; b=OrC+3FN7pax4A22ve8CgAaL67MDNI2b0mOvl2pIXgOJq/3YjAHludHDd6nBA2T2c/F w+pf3pbfD2EZrUi+NlLzVbbsNVh58l/jcK0W8BSeoDBA6QqWOLi41Wqyu1EF5Ut41aFe sSoUXHgrcBoQ53MemOj9XmEEjmjHZlSgy5vCAASPFshEbsLrO3Vr+Qm6YzmqbH+FdHPK bl9MC1o+QIGVvhQVPYjZcYIhHAn0rPKeiTq4JRN+A256tviiT6bG28uPOflI4ayAHZ4t IPh6PbdDViKvkXZJ+kLJdGEpFMtsoXwrObiGyykYAqQ/F87rN7MIN8xz1xSE9UUjn0TY NHVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=d4haJP3T; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ku4-20020a170903288400b001b03213eb84si1476519plb.516.2023.06.08.13.34.13; Thu, 08 Jun 2023 13:34:26 -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=@gmail.com header.s=20221208 header.b=d4haJP3T; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234560AbjFHULA (ORCPT + 99 others); Thu, 8 Jun 2023 16:11:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbjFHUK6 (ORCPT ); Thu, 8 Jun 2023 16:10:58 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD07C1707; Thu, 8 Jun 2023 13:10:57 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-652a6cf1918so850933b3a.1; Thu, 08 Jun 2023 13:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686255057; x=1688847057; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=KaorFROknjCn9/iVhBQO9PAsd8HYdHVJN5C9ENR6YJY=; b=d4haJP3T5+svy6N/pjKXZzN+9c59xnjk5MNne8EWxsJ/F2y/AlcU5khc1lDxZACmPo 5b8jd+FRn5zkglJwxsdgxLh08r6HR8hekliatKKBP8cwWWBwT7Y2GsvRTFHdmxSTvyan 45ayfpDci0sng7uLskyryB5GJ5Ytg6MS75CEdCSUg8NaULBGuL+PgGUvq0VVNwS7BuBQ lTRYptfzi6HfFxncQMUNbNdTqSSXD05bJ1nffB0u5ZhkkzMrZVeVNPa6hX7WwVKirAXv Q6kbsiDNw0pNPHn42Ft0AhI+I8uAl6p8WcbiheTYwuFVplwK+8BluGY1DknYeKbuYk5K fApA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686255057; x=1688847057; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KaorFROknjCn9/iVhBQO9PAsd8HYdHVJN5C9ENR6YJY=; b=WUixBEfXKWI6hBlhqPPb7Jt7vmxS1J6KwnWb+8Gona0XbluFosMDB5plLEVUBGStAv QEjyud+Z5ewz9ruPKzhKMl0tbv3EzYgCuOCL+pCGjeLBP7upKGDbEhcY2khCyzUW5fq1 nr6QFURP0VxNjLF/LyujfS1Ylb423cgIjlGeF6JEa8EfBMJ/Isll2hWnJlFWXSwNn2nw n1E2NyqoLwtmL9fEDxVECouwq4OB00yKZntw9Etv1pX/LDG/asYQM9Wc9/TmdQOiRQEr azIxDqfdVnww3Yq8R9XtUXzZZelZT3xyDlAf1WD7qyo8A3jx/c7rC/tHbukQiIAFyDCr XARQ== X-Gm-Message-State: AC+VfDzChoXDk6eBA7uBfGFLSAiQlmXWfRKVMrTomM3tMgGLNe0I87fi rg+faQ0j+822p90VO2kiOVM= X-Received: by 2002:a05:6a00:812:b0:658:2818:edd4 with SMTP id m18-20020a056a00081200b006582818edd4mr8062710pfk.13.1686255056839; Thu, 08 Jun 2023 13:10:56 -0700 (PDT) Received: from localhost ([192.55.54.50]) by smtp.gmail.com with ESMTPSA id u5-20020a62ed05000000b006580e98326esm389759pfh.42.2023.06.08.13.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 13:10:56 -0700 (PDT) Date: Thu, 8 Jun 2023 13:10:54 -0700 From: Isaku Yamahata To: "Wang, Wei W" Cc: Isaku Yamahata , "Yamahata, Isaku" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Paolo Bonzini , "Aktas, Erdem" , "Christopherson,, Sean" , "Shahar, Sagi" , David Matlack , "Huang, Kai" , Zhi Wang , "Chen, Bo2" , Sean Christopherson Subject: Re: [PATCH v14 011/113] KVM: TDX: Add C wrapper functions for SEAMCALLs to the TDX module Message-ID: <20230608201054.GK2244082@ls.amr.corp.intel.com> References: <37b118268ccf73d8e9cc1ef8f9fb7376fb732d60.1685333727.git.isaku.yamahata@intel.com> <20230607181537.GG2244082@ls.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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, Jun 08, 2023 at 01:43:27AM +0000, "Wang, Wei W" wrote: > On Thursday, June 8, 2023 2:16 AM, Isaku Yamahata wrote: > > On Mon, Jun 05, 2023 at 03:20:19PM +0000, "Wang, Wei W" > > wrote: > > > > +static inline u64 kvm_seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9, > > > > + struct tdx_module_output *out) { > > > > + u64 ret; > > > > + > > > > + ret = __seamcall(op, rcx, rdx, r8, r9, out); > > > > + if (unlikely(ret == TDX_SEAMCALL_UD)) { > > > > + /* > > > > + * TDX requires VMXON or #UD. In the case of reboot or > > > > kexec, > > > > + * VMX is made off (VMXOFF) by kvm reboot notifier, > > > > + * kvm_reboot(), while TDs are still running. The callers > > > > check > > > > + * the returned error and complain. Suppress it by returning 0. > > > > + */ > > > > > > Curious how do the callers check the returned error when " Suppress it > > > by returning 0" here. > > > > It doesn't make sense for the caller to check the error and warn when > > kvm_rebooting = true. > > Let's make it "return kvm_rebooting ? 0 : ret;" instread of "return 0;". > > Does it make sense? > > Seems no need. The comments look confusing, and not aligned to what > the code achieves. From what I read: > - if kvm_rebooting=true there: return 0 to caller and no error or warning happens > - if kvm_rebooting=false there: crash the system via kvm_spurious_fault. > In this non-rebooting case, I think the callers don’t get a chance to read the > returned value and complain. How about this comment? if (unlikely(ret == TDX_SEAMCALL_UD)) { /* * TDX requires VMXON or #UD. In the case of reboot or kexec, * kvm shutdown notifier, kvm_shutdown(), makes VMX off (VMXOFF) * while TDs can be still running to invoke SEAMCALL. It * results in superfluous errors or warnings. * If rebooting, return 0 to suppress superfluous messages. * If not rebooting, panic by kvm_spurious_fault(). */ kvm_spurious_fault(); return 0; } > Another thing is, have you double-checked that invocation of seamcalls > indeed returns TDX_SEAMCALL_UD when VMX=off? I observed it several times during testing tdx module initialization. Here is the example I dug out from my debug logs. tdx: SEAMCALL failed: CPU 162 is not in VMX operation. tdx: TDX module initialization failed (-22) kvm_intel: Failed to initialize TDX module. -- Isaku Yamahata