Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1431655pxb; Wed, 2 Feb 2022 05:02:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFIWthoRPaQpddGd2IvrMXDpdzu/pL6ei/wWUSnX99zDw1RQNBC9G3+QJWt7/0KS6R9jOR X-Received: by 2002:a63:2a45:: with SMTP id q66mr23992315pgq.484.1643806922519; Wed, 02 Feb 2022 05:02:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643806922; cv=none; d=google.com; s=arc-20160816; b=snxcLDtMwhHaUM4RzSdPumN+493sjC0rdRUa2CqUfoufkDJwzLDAoA4IeZQlOSGyRV qD1mPTKcPTIuQ8HSXpE6+dNCgXLtPxsS9bKyrkIl9OEHXV0hy159LoTNxEEqS3Jon37J YVdfgemQRKiYZwZXmaO5jUM5dg35TPHVGfOj5GeBqsEG9sc90ZlVGGD+dCgkvUu+hIVA 8Nv6aK3ieGTYARwnJhxzSwYyJEGEd+yn9Pk0LCyKHRaJuYJWKSffUbtR8KrBMLJgsDou tCFmsmJFUYOS5g3pM10JYG3jI/d98CLYkfR5FlsyHZqojSs2t94pvGdvERBKpUojJU59 G0ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=G1LxckeTVB2vMoGxab5Ja8WoF2V2W5GSADlv8IPeXW8=; b=H/GGME3ym+Z8ItOB3pYELbAvE1Phe0mlAZAG3VYLCUKPW2Wa2gbIY34+5Ehx07TYjL VXssR3Ubfrujp/fNIHLPjMh10mJXM32tn/YreIeCEdyLbT94v59m3BD0QVx5F8yWlUy7 yQphCN+yghg8w9WOgiTOFmeQEiQv4e3U2obQnW91ZQ59soqzjLQPel07wGGAy9olBjsg seJSOPsa7VqnyOqaZXlfSTelAiU0eNTkx2bFUHGf+6N1KGS28OksaA4vmFWLre2a3Y2n C/lYQJjZrSFLWKNsUjrcH3c5o56zUEd0v1+/dqATPWbFg4fdnXXNusF+3kJB6WbP3LW9 O7Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=YBNeovTx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ik5GgfEY; 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=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j10si21577402plx.255.2022.02.02.05.01.39; Wed, 02 Feb 2022 05:02:02 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=YBNeovTx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ik5GgfEY; 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=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233656AbiBAViH (ORCPT + 99 others); Tue, 1 Feb 2022 16:38:07 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:41944 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbiBAViH (ORCPT ); Tue, 1 Feb 2022 16:38:07 -0500 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1643751486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=G1LxckeTVB2vMoGxab5Ja8WoF2V2W5GSADlv8IPeXW8=; b=YBNeovTxvzYJwo04kW/WWVu0oMQtWL5zDdHrdUnYOFxZzJ5iFs3MhHRjuxrgalf4CXlFjH HI0fwTiSKwv6fx1+5m/csDBENaWQfXBb4V17KQemvDAKO39mGlrJmhkvOwXrWxPNDW1KdE +VkUkWZnV7R6g4S/0qjvWD3wLYqQDiD13ERPbMBl1XYST+zX0kPXTVMNBC1gyQZq7Unn9M 09VmoRxwiFI1SleTop05MwOpMR7uXcZCZ7jYIM8gDPFx7YtlRQFV3wklRakZ89pWiK8dGm /fLNs+9sbsV9h4CMAMh9kIG23wjRHQ0IPzwiB73NAX6zyaoDAg8NhIaj3a+clg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1643751486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=G1LxckeTVB2vMoGxab5Ja8WoF2V2W5GSADlv8IPeXW8=; b=ik5GgfEYI5Bs06dK4yNms/elzRll2T+oGl4eQYG2WtVjVWU2gDhlnFuixetmY7zX1vt3TX /DWoOGhTpreMelAQ== To: "Kirill A. Shutemov" , mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: Re: [PATCHv2 06/29] x86/tdx: Add MSR support for TDX guests In-Reply-To: <20220124150215.36893-7-kirill.shutemov@linux.intel.com> References: <20220124150215.36893-1-kirill.shutemov@linux.intel.com> <20220124150215.36893-7-kirill.shutemov@linux.intel.com> Date: Tue, 01 Feb 2022 22:38:05 +0100 Message-ID: <871r0mz2rm.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 24 2022 at 18:01, Kirill A. Shutemov wrote: > +static bool tdx_read_msr(unsigned int msr, u64 *val) > +{ > + struct tdx_hypercall_output out; > + > + /* > + * Emulate the MSR read via hypercall. More info about ABI > + * can be found in TDX Guest-Host-Communication Interface > + * (GHCI), sec titled "TDG.VP.VMCALL". > + */ > + if (_tdx_hypercall(EXIT_REASON_MSR_READ, msr, 0, 0, 0, &out)) > + return false; > + > + *val = out.r11; > + > + return true; > +} > + > +static bool tdx_write_msr(unsigned int msr, unsigned int low, > + unsigned int high) > +{ > + u64 ret; > + > + /* > + * Emulate the MSR write via hypercall. More info about ABI > + * can be found in TDX Guest-Host-Communication Interface > + * (GHCI) sec titled "TDG.VP.VMCALL". > + */ > + ret = _tdx_hypercall(EXIT_REASON_MSR_WRITE, msr, (u64)high << 32 | low, > + 0, 0, NULL); > + > + return ret ? false : true; > +} > + > bool tdx_get_ve_info(struct ve_info *ve) > { > struct tdx_module_output out; > @@ -132,11 +165,22 @@ static bool tdx_virt_exception_user(struct pt_regs *regs, struct ve_info *ve) > static bool tdx_virt_exception_kernel(struct pt_regs *regs, struct ve_info *ve) > { > bool ret = false; > + u64 val; > > switch (ve->exit_reason) { > case EXIT_REASON_HLT: > ret = tdx_halt(); > break; > + case EXIT_REASON_MSR_READ: > + ret = tdx_read_msr(regs->cx, &val); > + if (ret) { > + regs->ax = lower_32_bits(val); > + regs->dx = upper_32_bits(val); > + } > + break; Why here? static bool tdx_read_msr(struct pt_regs *regs) { struct tdx_hypercall_output out; /* * Emulate the MSR read via hypercall. More info about ABI * can be found in TDX Guest-Host-Communication Interface * (GHCI), sec titled "TDG.VP.VMCALL". */ if (_tdx_hypercall(EXIT_REASON_MSR_READ, regs->cx, 0, 0, 0, &out)) return false; regs->ax = lower_32_bits(out.r11); regs->dx = upper_32_bits(out.r11); return true; } and static bool tdx_read_msr(struct pt_regs *regs) { /* * Emulate the MSR write via hypercall. More info about ABI * can be found in TDX Guest-Host-Communication Interface * (GHCI) sec titled "TDG.VP.VMCALL". */ return !!_tdx_hypercall(EXIT_REASON_MSR_WRITE, regs->cx, (u64)regs->dx << 32 | regs->ax, 0, 0, NULL); } Also the switch case can be simplified as the only action after 'break;' is 'return ret': switch (ve->exit_reason) { case EXIT_REASON_HLT: return tdx_halt(); case EXIT_REASON_MSR_READ: return tdx_read_msr(regs); case EXIT_REASON_MSR_WRITE: return tdx_write_msr(regs); default: .... Hmm? Thanks, tglx