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 X-Spam-Level: X-Spam-Status: No, score=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DAC6C433DF for ; Mon, 25 May 2020 08:02:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AD5720870 for ; Mon, 25 May 2020 08:02:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alien8.de header.i=@alien8.de header.b="RmXdg7Qx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729660AbgEYICf (ORCPT ); Mon, 25 May 2020 04:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725809AbgEYICf (ORCPT ); Mon, 25 May 2020 04:02:35 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62738C061A0E; Mon, 25 May 2020 01:02:35 -0700 (PDT) Received: from zn.tnic (p200300ec2f06f3004418adec9d2f63e2.dip0.t-ipconnect.de [IPv6:2003:ec:2f06:f300:4418:adec:9d2f:63e2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 514AC1EC0116; Mon, 25 May 2020 10:02:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1590393752; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=HbItycmNHopexuynDp8v3E/cG41XLiYYR0XUaufHcT4=; b=RmXdg7Qxfd5JvK24kf//ZDbwbxh9yQ5WD9aNGgVJpTGZHMBxdRlxPXD/+P3C9pxjmN05Qr 5k/sXpwDV7HfYvnPa5HDdxDwTKYlbnKTymFHiUjx9bi13AXJXs4jZcYgeAQv5CG+57bxS3 17uS9WxUnIQaMuJTnaWakP3wDY6lsTk= Date: Mon, 25 May 2020 10:02:26 +0200 From: Borislav Petkov To: Joerg Roedel Cc: x86@kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v3 51/75] x86/sev-es: Handle MMIO events Message-ID: <20200525080226.GB25636@zn.tnic> References: <20200428151725.31091-1-joro@8bytes.org> <20200428151725.31091-52-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200428151725.31091-52-joro@8bytes.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Tue, Apr 28, 2020 at 05:17:01PM +0200, Joerg Roedel wrote: > +static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt, > + unsigned int bytes, bool read) > +{ > + u64 exit_code, exit_info_1, exit_info_2; > + unsigned long ghcb_pa = __pa(ghcb); > + void __user *ref; > + > + ref = insn_get_addr_ref(&ctxt->insn, ctxt->regs); > + if (ref == (void __user *)-1L) > + return ES_UNSUPPORTED; > + > + exit_code = read ? SVM_VMGEXIT_MMIO_READ : SVM_VMGEXIT_MMIO_WRITE; > + > + exit_info_1 = vc_slow_virt_to_phys(ghcb, (unsigned long)ref); > + exit_info_2 = bytes; /* Can never be greater than 8 */ No trailing comments pls - put them over the line. > + ghcb->save.sw_scratch = ghcb_pa + offsetof(struct ghcb, shared_buffer); > + > + return sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, exit_info_1, exit_info_2); > +} > + > +static enum es_result vc_handle_mmio_twobyte_ops(struct ghcb *ghcb, > + struct es_em_ctxt *ctxt) > +{ > + struct insn *insn = &ctxt->insn; > + unsigned int bytes = 0; > + enum es_result ret; > + int sign_byte; > + long *reg_data; > + > + switch (insn->opcode.bytes[1]) { > + /* MMIO Read w/ zero-extension */ > + case 0xb6: > + bytes = 1; > + /* Fallthrough */ I'm guessing we're supposed to annotate it this way now: WARNING: Prefer 'fallthrough;' over fallthrough comment #139: FILE: arch/x86/kernel/sev-es.c:504: + /* Fallthrough */ > + case 0xb7: > + if (!bytes) > + bytes = 2; > + > + ret = vc_do_mmio(ghcb, ctxt, bytes, true); > + if (ret) > + break; > + > + /* Zero extend based on operand size */ > + reg_data = vc_insn_get_reg(ctxt); That function can return NULL - you need to test reg_data. Ditto for all its invocations. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette