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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 A141CC48BD1 for ; Fri, 11 Jun 2021 14:20:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A6436141C for ; Fri, 11 Jun 2021 14:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231756AbhFKOWj (ORCPT ); Fri, 11 Jun 2021 10:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231180AbhFKOWh (ORCPT ); Fri, 11 Jun 2021 10:22:37 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41CC3C0617AF; Fri, 11 Jun 2021 07:20:39 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id 4D7A52FA; Fri, 11 Jun 2021 16:20:37 +0200 (CEST) Date: Fri, 11 Jun 2021 16:20:36 +0200 From: Joerg Roedel To: Borislav Petkov Cc: x86@kernel.org, Joerg Roedel , 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 , Sean Christopherson , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v4 2/6] x86/sev-es: Disable IRQs while GHCB is active Message-ID: References: <20210610091141.30322-1-joro@8bytes.org> <20210610091141.30322-3-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 11, 2021 at 04:05:15PM +0200, Borislav Petkov wrote: > On Thu, Jun 10, 2021 at 11:11:37AM +0200, Joerg Roedel wrote: > Why not simply "sandwich" them: > > local_irq_save() > sev_es_get_ghcb() > > ...blablabla > > sev_es_put_ghcb() > local_irq_restore(); > > in every call site? I am not a fan of this, because its easily forgotten to add local_irq_save()/local_irq_restore() calls around those. Yes, we can add irqs_disabled() assertions to the functions, but we can as well just disable/enable IRQs in them. Only the previous value of EFLAGS.IF needs to be carried from one function to the other. > Hmm, so why aren't you accessing/setting data->ghcb_active and > data->backup_ghcb_active safely using cmpxchg() if this path can be > interrupted by an NMI? Using cmpxchg is not necessary here. It is all per-cpu data, so local to the current cpu. If an NMI happens anywhere in sev_es_get_ghcb() it can still use the GHCB, because the interrupted #VC handler will not start writing to it before sev_es_get_ghcb() returned. Problems only come up when one path starts writing to the GHCB, but that happens long after it is marked active. Regards, Joerg