Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4685859iob; Sun, 8 May 2022 21:59:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3WGGQ+zEmYBvydN9zT935FqMzwKBl6Fq00wHPnJ4yX9gzwqd3IpjZt1m4+KBr/pIDL5pn X-Received: by 2002:a17:90b:3442:b0:1d9:8af8:28ff with SMTP id lj2-20020a17090b344200b001d98af828ffmr16607999pjb.201.1652072384944; Sun, 08 May 2022 21:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652072384; cv=none; d=google.com; s=arc-20160816; b=xS0h4EMWe/+ucndVwsmiGbM1GVObizKG5PJsCoddu0huG3ipgSq92oM7tjecpDI3KM 7bXXSW//skBz/MSuRe6/oF65aUct9xsZLlbgiYWB30sbPznhglwag5mFIdUMNNoGNl13 jrS1rNJB/XZ1sBYQRPIpMH6xEJkvJbJYOcdxMB0H+RJeDscYPQknC55XG0u1nhfYyInF co1IrODSG5mwtZNHh5Z+yc+dwF9uErte9+iyJcb/zwyP9XPZdCn1YTrl/qozwxCAn18J 4uTTqkS7fmJe8iGGEpRQJrSdLKZP+wXGFVr1sYZl7urtRNQtsFO8rdJLPLX5fHzoF+Dr Ottw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=c10qzHJmVxfsiehgqcs2gX6uGM8V8BViU8QHO44Ateo=; b=E9GoAtxVnquKL/4yowe5s+y14QMImhFDJldnmXfzrXPwVMt79/jO3UdxqqFc8S15mp tswpS6CE3/E+CegUNiL78JNQ6GYNwNW4LIuWAjvDs8rr/TAnXRawznh2rAk1Ajc3rRQB 864bDIXgf0/PkrnvnfTm9PsMojVB0PmE5zQ1Y2v0EfUxqMd7V3kQnc5wcXC9uRWyYtp7 GpDU+JwWu7v69HebJndcxZ0wwhlELnSIXKhp2HKVPKfeWb+1i1ZCVx0X4ERDy4jhVi9f GXGPO3ZXBN3LZ+5E4K4VQ6ExCJToy724gdtz2ulQQysCSiO9ztZAC1IIOOK8oDG7tYG7 ZxXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gHKcBZOQ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z13-20020a170903018d00b00153b2d1651dsi12620386plg.293.2022.05.08.21.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:59:44 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gHKcBZOQ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 761ABFE2; Sun, 8 May 2022 21:55:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386289AbiEEW3K (ORCPT + 99 others); Thu, 5 May 2022 18:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386309AbiEEW3B (ORCPT ); Thu, 5 May 2022 18:29:01 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573A9B85 for ; Thu, 5 May 2022 15:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651789518; x=1683325518; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=J7EFq8xXxu64ehJhvDLKryqmTjxBXFcI4TKtKuJ5cYg=; b=gHKcBZOQfXgsRL6ZDAhRQCPeTcbdvFopoaRbkJc06ZPTdUzQ7Mn7+zpv i1mwIqoLCaz7+3Nd5gnTtz87F9EgP04dvyNPQXmZOmTjTzOSM+feqe40c GBeRmNQn0C0fMbtH1MprEo4Ic0PhXc++6SyWslnOw/7ziUdclkEw5b7T1 g2IOQMOinoLpKnkp3W6ejdX7mSPGSKz0G268ujhUHgAsKxatIXvbBFvSI mZjuev1TfVehdKrbmeap0zR744jNA12i+gGP8MQRRhoHKDAXkqGKKzKL3 qTDb+XbHPP6+smK3CDiiCHBrSh4VkVyDqfRIoeFebK61BuIoBBqaNcwbX A==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="293474091" X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="293474091" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 15:25:17 -0700 X-IronPort-AV: E=Sophos;i="5.91,203,1647327600"; d="scan'208";a="654432618" Received: from anthienn-mobl1.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.254.4.139]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 15:25:12 -0700 Message-ID: Subject: Re: [PATCH v5 3/3] x86/tdx: Add Quote generation support From: Kai Huang To: Sathyanarayanan Kuppuswamy , Dave Hansen , "Kirill A. Shutemov" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , "Kirill A . Shutemov" , Tony Luck , Andi Kleen , Wander Lairson Costa , Isaku Yamahata , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, linux-kernel@vger.kernel.org Date: Fri, 06 May 2022 10:25:11 +1200 In-Reply-To: <5d34ac93-09dc-ea93-bffe-f3995647cd5b@linux.intel.com> References: <20220501183500.2242828-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20220501183500.2242828-4-sathyanarayanan.kuppuswamy@linux.intel.com> <243e918c523320ba3d216cbe22d24fe5ce33f370.camel@intel.com> <20220503012721.ok7fbvxmnvsr6qny@box.shutemov.name> <58d07b2d-cef5-17ed-9c57-e12fe5665e04@intel.com> <40ccd0f0-35a1-5aa7-9e51-25ab196d79e5@linux.intel.com> <1534b975275b78d61d851eb86faa226fd9be5c7a.camel@intel.com> <5d34ac93-09dc-ea93-bffe-f3995647cd5b@linux.intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, 2022-05-05 at 12:03 -0700, Sathyanarayanan Kuppuswamy wrote: > Hi Kai, > > On 5/5/22 3:50 AM, Kai Huang wrote: > > > > > + /* Submit GetQuote Request */ > > > + ret = tdx_get_quote_hypercall(buf); > > > + if (ret) { > > > + pr_err("GetQuote hypercall failed, status:%lx\n", ret); > > > + ret = -EIO; > > > + goto free_entry; > > > + } > > > + > > > + /* Add current quote entry to quote_list */ > > > + add_quote_entry(entry); > > > + > > > + /* Wait for attestation completion */ > > > + ret = wait_for_completion_interruptible(&entry->compl); > > > + if (ret < 0) { > > > + ret = -EIO; > > > + goto del_entry; > > > + } > > > > This is misuse of wait_for_completion_interruptible(). > > > > xxx_interruptible() essentially means this operation can be interrupted by > > signal. Using xxx_interruptible() in driver IOCTL essentially means when it > > returns due to signal, the IOCTL should return -EINTR to let userspace know that > > your application received some signal needs handling, and this IOCTL isn't > > finished and you should retry. So here we should return -EINTR (and cleanup all > > staff has been done) when wait_for_completion_interruptible() returns - > > ERESTARTSYS (in fact, it returns only -ERESTARTSYS or 0). > > > But in this case, I was expecting the user agent to check the Quote > buffer status code to understand the IN_FLIGHT, SUCCESS or FAILURE > status and handle it appropriately. So IMO, it should not matter what > we return for the failure case. For the IN_FLIGHT case, they can retry > if they want after checking the status code. Couple of issues around your statement: 1) When wait_for_completion_interruptible() returns error, you never copied the data back to userspace. Therefore userspace cannot check buffer status. Your assumption is wrong. 2) Even if you copy the data back to userspace, there's no guarantee *after* you do the copy, the VMM won't update the buffer status. So this doesn't work. 3) You only provide one IOCTL. Even if userspace can retry, you will create a new buffer, and ask VMM to do it again. Then what happens to the old buffer? VMM is still owning it, and can update it, but you have already converted it back to private, and freed it. I really don't see how your statement is correct. > > But I agree that EINTR is the appropriate return value for an > interrupted case. So, I will change it. > > > > > Since normally userspace application just ignore signals, and in this particular > > case, asking userspace to retry just makes things more complicated to handle, I > > I am not sure how the user agent is going to be implemented. So I don't > want to make any assumptions. In this case, we are not asking user space > to implement the retry support using signals. But we are just giving > them option to do it. It is up to them if they want to use it. As I see you are not providing any functionality to allow userspace to retry. -- Thanks, -Kai