Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1941116pxb; Thu, 7 Oct 2021 19:26:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxY0pprdKd8PmiTymzArgb7xVw/XgKf14V5eq06NAB1Nl37VXXlv328Z8VAMQr0jAemL0OP X-Received: by 2002:a17:902:ed8c:b0:13f:136f:efb1 with SMTP id e12-20020a170902ed8c00b0013f136fefb1mr1963865plj.56.1633660019259; Thu, 07 Oct 2021 19:26:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633660019; cv=none; d=google.com; s=arc-20160816; b=yG3pNCGuf6300IcYpIkQ5A2U1HRRL+FOMUxkAAwwmUDrzHDsMaQ7inukXnVS9au+Ga rhDA5c1hUev4IbFmOIdmibx4CPWiPl1y0Kn3xcouh2xBEoWoWf43oElGbQeB5ZAFcpvT AeH59pD1FYp55/qibVlTWW1/cmcKLFKzmKEBNC6XnhNcaMCeZ52RV2f/DSG0s5gT8Yaa cKAuPiOprR1B+LzS34NEVQ5TPtS3gJ261wKUFEuqDGjSxgHLpa+wFGeyDKAsEdPbe7ha ztaNERrbgN1LtEK/fs6N3rbC9cdW5h1oPR4dxtP1/BlWct2ThXGUt1pcvv4fzBzri+yY R7aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=PSGitCMHbifk75d/1ll6jF218LaxOTbsUi7YKwP21NE=; b=WEQe+G0EmA6KeOenhYgLpKPJnUSAlutI87Ceu8k5kP6o3FE2AvkUVMMftiySY+bPvh Gv/sgbzumc+S+WJQYkSY8VoU43ryUhPw4E/WE2gNVzpVcNSwU1+Fwd1yO8nd4ZuScK38 ZCpFN0nLlRI39b2VYOPvDIe2TsoNlwDdwfeBF/LNJ4K78VvXqYIQyyncnfcRnAXbj4cz 9xytFpncqU4HSgTO8QKJlmuoCNjMAmSI9Uu1g/lGlILfF/x+avBHKJyzutfnUatshBvf VF5qcZ4hEusLv4aRV3k9swsYfTJ1BGR0OY31+99dc6ngMkUEOtlS/w9kHJuGifmUqA7i Y4Aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u18si1286177plq.139.2021.10.07.19.26.45; Thu, 07 Oct 2021 19:26:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235560AbhJHC1o (ORCPT + 99 others); Thu, 7 Oct 2021 22:27:44 -0400 Received: from mga04.intel.com ([192.55.52.120]:19306 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbhJHC1n (ORCPT ); Thu, 7 Oct 2021 22:27:43 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="225194662" X-IronPort-AV: E=Sophos;i="5.85,356,1624345200"; d="scan'208";a="225194662" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 19:25:48 -0700 X-IronPort-AV: E=Sophos;i="5.85,356,1624345200"; d="scan'208";a="624554949" Received: from mlazarux-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.209.19.27]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 19:25:47 -0700 Subject: Re: [PATCH v8 11/11] x86/tdx: Handle CPUID via #VE To: Josh Poimboeuf Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini , David Hildenbrand , Andrea Arcangeli , Juergen Gross , Deep Shah , VMware Inc , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org References: <20211005025205.1784480-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20211005025205.1784480-12-sathyanarayanan.kuppuswamy@linux.intel.com> <20211006202630.chblrhdqepsbtdaa@treble> From: "Kuppuswamy, Sathyanarayanan" Message-ID: <02e4f583-39dd-cac9-5b51-5fa9ba81b996@linux.intel.com> Date: Thu, 7 Oct 2021 19:25:44 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211006202630.chblrhdqepsbtdaa@treble> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/6/21 1:26 PM, Josh Poimboeuf wrote: > On Mon, Oct 04, 2021 at 07:52:05PM -0700, Kuppuswamy Sathyanarayanan wrote: >> +static u64 tdx_handle_cpuid(struct pt_regs *regs) >> +{ >> + struct tdx_hypercall_output out = {0}; >> + u64 ret; >> + >> + /* >> + * Emulate CPUID instruction via hypercall. More info about >> + * ABI can be found in TDX Guest-Host-Communication Interface >> + * (GHCI), section titled "VP.VMCALL". >> + */ >> + ret = _tdx_hypercall(EXIT_REASON_CPUID, regs->ax, regs->cx, 0, 0, &out); >> + >> + /* >> + * As per TDX GHCI CPUID ABI, r12-r15 registers contains contents of >> + * EAX, EBX, ECX, EDX registers after CPUID instruction execution. >> + * So copy the register contents back to pt_regs. >> + */ >> + regs->ax = out.r12; >> + regs->bx = out.r13; >> + regs->cx = out.r14; >> + regs->dx = out.r15; > > Does it still make sense to save the regs if _tdx_hypercall() returns an > error? We don't need to save it in failure case. I will add check for error case in next version. > >> + >> + return ret; > > Also I'm wondering about error handling for all these _tdx_hypercall() > wrapper functions which are called by the #VE handler. > > First, there are some inconsistencies in whether and how they return the > r10 error. Since we have only cared about zero/non-zero return value, we did not check for consistency. May be I can convert all handler return values to bool. > > - _tdx_halt() warns and doesn't return anything. Since tdx_halt handler is shared with pv_ops, we can't return anything back (so we use WARN_ON to report the error). > > - tdx_read_msr_safe() and tdx_write_msr_safe() convert all errors to -EIO. Return value does not matter. we only check for zero/non-zero value in tdx_handle_virtualization_exception(). we have used -EIO to convey that it is an IO error. > > - tdx_handle_cpuid() returns the raw vmcall error. > > Second, as far as I can tell, the #VE handler doesn't check the actual > return code value, other than checking for non-zero. Should it at least > be printed in a warning? I don't think this is required. We can use trace to check the error code or argument details in failure case. Since we don't really use the error value, I am planning to change the #VE handler return type to bool. > -- Sathyanarayanan Kuppuswamy Linux Kernel Developer