Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp776686pxa; Thu, 27 Aug 2020 15:49:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTN+SnK/Jrh9Wj8vFBgVc09WrobqLgSF8y6+7fUG3FMJOniO6ppdLvVc8zlHgP7mkSPSAN X-Received: by 2002:a17:906:3a02:: with SMTP id z2mr22751187eje.287.1598568561240; Thu, 27 Aug 2020 15:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598568561; cv=none; d=google.com; s=arc-20160816; b=M89CvJf6BADZ6CLV7+AGvDZbqqDG6OBdrjReJKx0r+Lz7V4Wuen7Y+pek7N5l2uXl6 T7B5iVgeiJRkQhkmOA8eJo5JrQrIlYvkjRjoD99yIhWpWVE5U6uuibgQ39a98bdgHr3w Ccn4pIaw8QunpfvzDD6hKvPQNlavmwKKLoRSSbZIdfDeknWzbJLF7eUX0YJxCURfw0NN a/IW4SLghfbFa9tAg1TKz11yKeECIosRUE7seWHa5WGBEurcGZYiXplNNnjV7Q65BjsJ z7uhRlOQpLNo1mAD+WQKRY2Q6CTXTbPlFcqV+ZwEOo7DggcmxHlHuVRJGJvAQ71Ob0Lf P4rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=Y2apmauJqQxWRpgQvwb+Zmg3D+lXVvnQVjZBHrBv0Go=; b=J8Ovc7akEsaPK0ETecCnLcVmEpb3JU5ANhQSGJSN2RzlLaqmGB9tTJh5u9EiYao7Ie IRFGfujJyXxKExnsqMbLjVz05oKWZArql3lqFTT4PvS1nUo6l/3sT5mJiOrlmZgTB8Ky ny3Plh4MxX8F4py43bAM1wX74PWzP89TeLNfmtwFsILUP64Gc2A674uVARrRQxrlu1I3 6U+rET+gjhgf9a7omr2Ikg/Z5nFWWjXl+LEIdDvBbchdJ6E1jj+x8rPRf006rD2PuLbx syWB+GmIXMJoDp8TpBUi2l21qz6LHYOV6DTIzv/3gIgmXBAA9e/S+62D7VtKwTO/JmhG svUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RsiMaFmh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y10si2522009edi.9.2020.08.27.15.48.58; Thu, 27 Aug 2020 15:49:21 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RsiMaFmh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728019AbgH0WsQ (ORCPT + 99 others); Thu, 27 Aug 2020 18:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726706AbgH0WsO (ORCPT ); Thu, 27 Aug 2020 18:48:14 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E7A4C061264; Thu, 27 Aug 2020 15:48:13 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id p25so7764061qkp.2; Thu, 27 Aug 2020 15:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Y2apmauJqQxWRpgQvwb+Zmg3D+lXVvnQVjZBHrBv0Go=; b=RsiMaFmhnOCD5XVKA2gNSkEsXK540EqNGscrDEBjxtDvkRikQp/qmY1NJ+ybo84OOp Eyvfz5G4N10SSYayeFA3jEXXizLZsivTuL8P3vHjoqdhZYH1AAh8+r+yQHvpbvtwBDih TunbvS1/nhe7a5QXX7X+7H4UFu0uUwcD8l8R5B+/IRg/H9tPcKGZpW7lZotP6A1vowpC cW8o5ARcOqPUoFjGR5IevTyD14DTtEW1k59XzNa2kd7bKjjK4NHTpiHH7kVpjQ4UbvQQ RhP+gz9w9wFjZO2cfdU4nYyNQJoBUHuA5zUxu2JtD5tWMLNNKWL8WRkcggs3/PlWfRjN OMNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=Y2apmauJqQxWRpgQvwb+Zmg3D+lXVvnQVjZBHrBv0Go=; b=kpSI5DCFkFMKCOMImfdwNz9jhP4tt5NmfG4qB/OPvreQvw4/Kiri5kBgf/xVKMGQuN 9XFN04DfrNaJx10mcDrfor58HXr/wo4AqnW9Z0tk3v/wlRwGfXyM49PiEtmc4G0aUMAC 8GyW/phR4hBUF5yNbicqVLHFUgFnhJAwA8Sm2ZulGUYMIHLIbLKWb/Va00gytr0vEUns i32ipez3lIN6s/rUhfgLrCFRHhyuuK+eo3cwMYjYmV7NVy7Ad7isUXrmzquqUud+igVN vOSI6YS++BDQ1HxlZJkh4G1inGZrdJiWzudOFfe4t48pX1zvP+htHtvtHGzZYNQkf+fE qYAg== X-Gm-Message-State: AOAM533hwM9uiEP2Y+o9KidN2rLsCeCgDisfZJvyUy1xcfalXC8cSCgF x+nH9Sg4PTC95wZAqxg+A2g= X-Received: by 2002:a05:620a:148a:: with SMTP id w10mr14211312qkj.281.1598568492613; Thu, 27 Aug 2020 15:48:12 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id a20sm2909161qtw.45.2020.08.27.15.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 15:48:12 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Thu, 27 Aug 2020 18:48:10 -0400 To: Joerg Roedel Cc: x86@kernel.org, Joerg Roedel , Tom Lendacky , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v6 27/76] x86/sev-es: Add CPUID handling to #VC handler Message-ID: <20200827224810.GA986963@rani.riverdale.lan> References: <20200824085511.7553-1-joro@8bytes.org> <20200824085511.7553-28-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200824085511.7553-28-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 24, 2020 at 10:54:22AM +0200, Joerg Roedel wrote: > From: Tom Lendacky > > Handle #VC exceptions caused by CPUID instructions. These happen in > early boot code when the KASLR code checks for RDTSC. > > Signed-off-by: Tom Lendacky > [ jroedel@suse.de: Adapt to #VC handling framework ] > Co-developed-by: Joerg Roedel > Signed-off-by: Joerg Roedel > Link: https://lore.kernel.org/r/20200724160336.5435-27-joro@8bytes.org > --- > + > +static enum es_result vc_handle_cpuid(struct ghcb *ghcb, > + struct es_em_ctxt *ctxt) > +{ > + struct pt_regs *regs = ctxt->regs; > + u32 cr4 = native_read_cr4(); > + enum es_result ret; > + > + ghcb_set_rax(ghcb, regs->ax); > + ghcb_set_rcx(ghcb, regs->cx); > + > + if (cr4 & X86_CR4_OSXSAVE) Will this ever happen? trampoline_32bit_src will clear CR4 except for PAE and possibly LA57, no? > + /* Safe to read xcr0 */ > + ghcb_set_xcr0(ghcb, xgetbv(XCR_XFEATURE_ENABLED_MASK)); > + else > + /* xgetbv will cause #GP - use reset value for xcr0 */ > + ghcb_set_xcr0(ghcb, 1); > + > + ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0); > + if (ret != ES_OK) > + return ret; > + > + if (!(ghcb_rax_is_valid(ghcb) && > + ghcb_rbx_is_valid(ghcb) && > + ghcb_rcx_is_valid(ghcb) && > + ghcb_rdx_is_valid(ghcb))) > + return ES_VMM_ERROR; > + > + regs->ax = ghcb->save.rax; > + regs->bx = ghcb->save.rbx; > + regs->cx = ghcb->save.rcx; > + regs->dx = ghcb->save.rdx; > + > + return ES_OK; > +} > -- > 2.28.0 >