From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEA6AC05027 for ; Tue, 14 Feb 2023 15:27:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 165186B0074; Tue, 14 Feb 2023 10:27:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EDF26B0075; Tue, 14 Feb 2023 10:27:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA85D6B0078; Tue, 14 Feb 2023 10:27:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DDF316B0074 for ; Tue, 14 Feb 2023 10:27:01 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AFFCA401FC for ; Tue, 14 Feb 2023 15:27:01 +0000 (UTC) X-FDA: 80466275442.24.BD3D837 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf27.hostedemail.com (Postfix) with ESMTP id 2C8994000A for ; Tue, 14 Feb 2023 15:26:57 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="X5/ZCPe2"; spf=none (imf27.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676388418; a=rsa-sha256; cv=none; b=5WGaDtkb9bfZ66eI5ol6F5BYPq6na/FaSKhLFvNumgu99OSCRSaDLdOJd7Rv1th+f3mv9O UBaruElsNb/o3dJD70qvV/kcIGj2N7I7PKUh9gDUaWqC+MYQOf+O5p9msBjBO79T9hQjm9 mIcjCPisBqyd+ZzAD/W6/E43ZumO000= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="X5/ZCPe2"; spf=none (imf27.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676388418; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2EnIovssVvP6O5SvRgUEVDWtbXeOafyJH3FigQrR9WM=; b=VkIoERhIsLoL2ri/UWQRJCiHs1/Q8ProxaW8Bi5QW5AUUJtUFpm1QovXT0hswK8eOIQxCX WykLkx9npM+24y6L2tiJq4B81XOH3bsxq/wAXI+k39S4f4CqFao2AS1BNQpsOGsNg+L2VY SkxqBD/6NZJEZ3XOg1/nM7i082KG3Qw= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2EnIovssVvP6O5SvRgUEVDWtbXeOafyJH3FigQrR9WM=; b=X5/ZCPe2J5h0cKKIxtipKsW48q Q8b18C/bo4pqRbA/604PvLWAudq+XNWTai9gymifQv/P9dlMwu2Ouk5mtsBgq3NnP7AgVfK8xm+EQ GEv2XfIus8NpuuHchFRRNwxIXG94DkLagHFngpwV58OIxND6gnANbpevgWqWAiic/R6cWMQ+OL8yV HqrED6cR8uNAHFYWcnm6MJUbmpT8e56dHSgKWKmHoSCFciU4NEB5sqFCNj4t45unVxkDaUc+XvcSE sEM7vW0cPZOld2DCt2EM1M1qtXY3TRhcfLdcbJc4EvsEw7jASz30jjlaJslzfBtEsPDU12oD9mKNe 3BOY3ucw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pRxC3-009fh2-13; Tue, 14 Feb 2023 15:26:08 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 169E1302E82; Tue, 14 Feb 2023 13:42:54 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id EA1D523BC86ED; Tue, 14 Feb 2023 13:42:53 +0100 (CET) Date: Tue, 14 Feb 2023 13:42:53 +0100 From: Peter Zijlstra To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, dave.hansen@intel.com, tglx@linutronix.de, seanjc@google.com, pbonzini@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, kirill.shutemov@linux.intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, tony.luck@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, david@redhat.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v9 05/18] x86/virt/tdx: Add SEAMCALL infrastructure Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 2C8994000A X-Rspamd-Server: rspam01 X-Stat-Signature: ps666f166h1owhr64hued4n4why6ibay X-HE-Tag: 1676388417-616242 X-HE-Meta: U2FsdGVkX1+tBT+NtPSdrzeCQ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Dd4nPKesi11AkoB4854t36BISBP7aUWvKkrLuoEME38 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Feb 14, 2023 at 12:59:12AM +1300, Kai Huang wrote: > +/* > + * Wrapper of __seamcall() to convert SEAMCALL leaf function error code > + * to kernel error code. @seamcall_ret and @out contain the SEAMCALL > + * leaf function return code and the additional output respectively if > + * not NULL. > + */ > +static int __always_unused seamcall(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9, > + u64 *seamcall_ret, > + struct tdx_module_output *out) > +{ > + int cpu, ret = 0; > + u64 sret; > + > + /* Need a stable CPU id for printing error message */ > + cpu = get_cpu(); > + > + sret = __seamcall(fn, rcx, rdx, r8, r9, out); > + > + /* Save SEAMCALL return code if the caller wants it */ > + if (seamcall_ret) > + *seamcall_ret = sret; > + > + /* SEAMCALL was successful */ > + if (!sret) > + goto out; I'm thinking you want if (likely(!sret)), here. That whole switch thing should end up in cold storage. > + > + switch (sret) { > + case TDX_SEAMCALL_GP: > + /* > + * tdx_enable() has already checked that BIOS has > + * enabled TDX at the very beginning before going > + * forward. It's likely a firmware bug if the > + * SEAMCALL still caused #GP. > + */ > + pr_err_once("[firmware bug]: TDX is not enabled by BIOS.\n"); > + ret = -ENODEV; > + break; > + case TDX_SEAMCALL_VMFAILINVALID: > + pr_err_once("TDX module is not loaded.\n"); > + ret = -ENODEV; > + break; > + case TDX_SEAMCALL_UD: > + pr_err_once("SEAMCALL failed: CPU %d is not in VMX operation.\n", > + cpu); > + ret = -EINVAL; > + break; > + default: > + pr_err_once("SEAMCALL failed: CPU %d: leaf %llu, error 0x%llx.\n", > + cpu, fn, sret); > + if (out) > + pr_err_once("additional output: rcx 0x%llx, rdx 0x%llx, r8 0x%llx, r9 0x%llx, r10 0x%llx, r11 0x%llx.\n", > + out->rcx, out->rdx, out->r8, > + out->r9, out->r10, out->r11); > + ret = -EIO; > + } > +out: > + put_cpu(); > + return ret; > +}