Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1821378rdb; Wed, 20 Sep 2023 23:45:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOUHVD8QpwuZ0pfWasj0UQA4kccwDv7Qa2TLbPqST60RJof4OFumzG+M7ShVMacesjNU2W X-Received: by 2002:a17:903:2345:b0:1c3:a4f2:7cc1 with SMTP id c5-20020a170903234500b001c3a4f27cc1mr4650624plh.5.1695278719579; Wed, 20 Sep 2023 23:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695278719; cv=none; d=google.com; s=arc-20160816; b=SZEIWWoXlW2wLg8d+AXzhY/iqq2Zs2f5VTmD4x0crZW2Z4u875OgQ2JhuTvVa9AYll j5SbTJzkVC5rDL5IigobB2OaomT8Nvk3lIMpL16rIhGa4XNF4OcAvMmy50br7WrSqJzD NkmogIlDXBqq1htQydKGfdenbrWuUR+MHmNwCCTEmete7L2D2dfLEHQpQTbnwYt9T/an vP4qzlhnS5su+s1llyDo48L2LmtsweyC4ycmjsRevpsOfEYx68UdkR4eeCoqcjZc4HYQ fuVu9g4BOs4S44999vGNQepqt/erKyKOGu8eITya4BTPriJJNYOkGMlAauNLf2EZ2gKZ xLJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=QzWGpKQ7VC3VmGaMJqQZQAes686Ovy1BMDI5RayaZQQ=; fh=eCG3jbs+eLMdOqpyI8r2I98gfcYXx1T645hWeDuk4eQ=; b=lG6brEULy5S/K971Nl5msDINAmzsprGSNNRcNEPhMegd1CjIX4Ly1aFlRsdZ5SsxKd 31QXk6xdvKjWb4t4eh0VTZqhowVLn3cAk9KcEFea+Negr1ugXvhCyPnfM78takob5H86 X9jtqFo7s6xLY3TOzhWbbwQSAIJYRKjc7EknHbZGabQzMhY5cxUfFSdGG9YsezSk45n4 iimSh/BUAULZ3bPW9BLK0BuRs5Qlfm1rzQy02jcXcjtb9iVEsHion2APxa72Hx/5JwCc vG6MDPLPkEdpXtBjm1it0eZjB8SqojnPV88YOAxwIbL2HPg2W7HX7wE4tTaSRD5LY3iA nP3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k1MtCZww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f5-20020a170902ce8500b001c446f12975si787719plg.447.2023.09.20.23.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 23:45:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k1MtCZww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 963008077546; Wed, 20 Sep 2023 11:08:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229639AbjITSI4 (ORCPT + 99 others); Wed, 20 Sep 2023 14:08:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbjITSIz (ORCPT ); Wed, 20 Sep 2023 14:08:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C770EB9 for ; Wed, 20 Sep 2023 11:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695233329; x=1726769329; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=+v3bN4jZAuS5dnJ4c3CbLpISfxHCdKuf8qMN+4iFJNg=; b=k1MtCZwwXsW/mOuF1ySe4tzMP8LxghkoiTC1Ty5Lq0lJQDHdOJFwN5oL eOKALLjhLWNBdE1IU6fqNVMM+On1vzrcMo7V7BL3LQfyu6pD3ma5B7OCF uvfU8F0Ep33Dbh01s6/NWu816nBFsMgPLA76uPiNlFaqkl9DgPcC7wTa5 0iwOQiclXAXZdj1p1dT1rhCKf5lI2ZZK0ICpmBjI8fvqWeyIcPbkvvt+U k9RElm4pWpI6F0zDvqRm/aqYQPgTSKHNCCZlw2gHtiuAV25DVOrBRFaGb L4ghSTv7esmDH3jKr0gv1sUpwRpnA+DWLbypqvq1KeHikVpJsEpGltM2/ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="359684993" X-IronPort-AV: E=Sophos;i="6.03,162,1694761200"; d="scan'208";a="359684993" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Sep 2023 11:08:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="993713790" X-IronPort-AV: E=Sophos;i="6.03,162,1694761200"; d="scan'208";a="993713790" Received: from pkmanna-mobl3.amr.corp.intel.com (HELO [10.209.53.192]) ([10.209.53.192]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Sep 2023 11:08:48 -0700 Message-ID: Date: Wed, 20 Sep 2023 11:08:49 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] virt: tdx-guest: Add Quote generation support using TSM_REPORTS Content-Language: en-US To: "Kirill A . Shutemov" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Dan Williams , "H . Peter Anvin" , Tony Luck , Wander Lairson Costa , Erdem Aktas , Dionna Amalie Glaze , Qinkun Bao , Guorui Yu , linux-coco@lists.linux.dev, x86@kernel.org, linux-kernel@vger.kernel.org References: <20230914031349.23516-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20230920131633.ig6ldmwavpu7uhss@box.shutemov.name> <0031e031-10a8-43b1-a29c-8e1cf913eaad@linux.intel.com> <20230920175248.6foe67cwfe5oaa7u@box.shutemov.name> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20230920175248.6foe67cwfe5oaa7u@box.shutemov.name> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 20 Sep 2023 11:08:53 -0700 (PDT) On 9/20/2023 10:52 AM, Kirill A . Shutemov wrote: > On Wed, Sep 20, 2023 at 08:27:39AM -0700, Kuppuswamy Sathyanarayanan wrote: >> >> >> On 9/20/2023 6:16 AM, Kirill A . Shutemov wrote: >>>> +static u8 *tdx_report_new(const struct tsm_desc *desc, void *data, size_t *outblob_len) >>>> +{ >>>> + struct tdx_quote_buf *quote_buf = quote_data; >>>> + int ret; >>>> + u8 *buf; >>>> + u64 err; >>>> + >>>> + if (mutex_lock_interruptible("e_lock)) >>>> + return ERR_PTR(-EINTR); >>>> + >>>> + /* >>>> + * If the previous request is timedout or interrupted, and the >>>> + * Quote buf status is still in GET_QUOTE_IN_FLIGHT (owned by >>>> + * VMM), don't permit any new request. >>>> + */ >>>> + if (quote_buf->status == GET_QUOTE_IN_FLIGHT) { >>>> + ret = -EBUSY; >>>> + goto done; >>>> + } >>>> + >>>> + if (desc->inblob_len != TDX_REPORTDATA_LEN) { >>>> + ret = -EINVAL; >>>> + goto done; >>>> + } >>>> + >>>> + /* TDX attestation only supports default format request */ >>>> + if (desc->outblob_format != TSM_FORMAT_DEFAULT) { >>>> + ret = -EINVAL; >>>> + goto done; >>>> + } >>>> + >>>> + u8 *reportdata __free(kfree) = kmalloc(TDX_REPORTDATA_LEN, GFP_KERNEL); >>> __free() is new to me. Good to know. >>> >>> But are we okay now with declaring variables in the middle of the >>> function? Any reason we can't do at the top? >> >> Declaring variables at the top is no longer a hard requirement. The main reason >> for declaring it here is to use __free cleanup function. If we use top >> declaration, then we have free it manually. > > What's wrong with allocating it it there too? My thinking is to allocate it when we really need it. We only need this memory if the GetQuote hypercall is successful. We can also allocate it at the top and there is nothing wrong with it, but it will not be used in failure cases. Since top declarations are not a requirement, why allocate it early? > -- Sathyanarayanan Kuppuswamy Linux Kernel Developer