Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp464648imn; Wed, 3 Aug 2022 11:21:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Ynwv9nhnn/pqKHmpghZhIZ+h5m3qP7b6cI+HT13neLN/C9cOdQS/Uy3c71kQj10sbibyt X-Received: by 2002:a17:902:eb91:b0:16d:d4b1:ce95 with SMTP id q17-20020a170902eb9100b0016dd4b1ce95mr25835646plg.56.1659550884565; Wed, 03 Aug 2022 11:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659550884; cv=none; d=google.com; s=arc-20160816; b=e5e/4hXy6hUC79aeoJ2zSNNfpf8Y36tmYnaaBzcUrJJc+O5FgaIyMlNVPu+RTIyDs9 h4h6qGNvluyslJQj/abN7tQrNGdtzKESp3QmWzLnbOmlaq6L+wsEJzKo8ZvGz8GO5KYX GGEw0Iuc7vrPgOGYVIlap7gRbc++9krehs8jdTY3t+STDsWEk4DccMj7E02gR28WzLcX dgDjrpxcYx8/I4KLWZz0G3zsbiCCQc7MA16nhHDvL8Wx+Ii1sJ08ON+sO0SzGQjMnaRa UK1tIGJsdsU9WvWKwaQTqyw3VnvlwwCPqKOOczWq2l9F+5cH4rHNn9/ZzluzvG9AhQoq 54eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=08OjMXZ2wbWMw6p9o6XW5YzytY0/UiW+AaRO4aY6VXM=; b=Sg3FbQ98FeJyR506tlVBg0jU6/v+A4RCISiGA3otXjMgc7Am7LnToTf8dpXmLTh/fa xHXwk2cKNEf4aWRB4L+uFH+TxEuq8hXqNXmGtPx3b9ZkHN8GiXXcd3iCJ5/rZGDK82Du Un4k8wBlU/pztqQiRFYc+n7q8OK1Ypj2U271WPf4kF5R9UDMPP2xQy25YkaxXBhw1Gg5 2Xtm7OxeE0e/hlB5zRMSJNm6V7qvVJuVCIKf9EaHDcL8PjiCpnzx4t+a+Y2nlmi7XbPa dVJLLU0CR4J2vgkXcla9JeIRcmxCKeelhh+41TWDE1tTJDScitthwyzz3Huoz1S03wQL MMAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N31wp8+G; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t7-20020a056a0021c700b0052ab2efeec4si9767731pfj.280.2022.08.03.11.21.09; Wed, 03 Aug 2022 11:21:24 -0700 (PDT) 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=@intel.com header.s=Intel header.b=N31wp8+G; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237679AbiHCSR4 (ORCPT + 99 others); Wed, 3 Aug 2022 14:17:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237394AbiHCSRw (ORCPT ); Wed, 3 Aug 2022 14:17:52 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 133D95A175 for ; Wed, 3 Aug 2022 11:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659550668; x=1691086668; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=HSprJA3h+9xu55RyAVG01fa5qBNtYY99LJPlZZrdu+s=; b=N31wp8+GK9TJ/lQapFEeaUDJQiYVn3XDhifMFUqLxzGEqqGJmx9J+WvI m115f5GkxIYzC6JfjgMPFRDbe47WoYQIMBE+i7ku5V6FBSebdpfqBTZV3 t0Ol8B1+c3BwunJUKfmbvKaoXZ2bPIooJcGjss8ZX9sgh5WuSSbdPIfkp UH1GnTjFHzS/9uQGuMgH9Xzz9FZSl/eFC8tQLDKyaeun9j+lxBJzjbIzj ArrwgWyRuD5ktojwIY/WfgX4P1dUR9MR7W7D9e7D5HWvMPNN8xjOx/34C MYtN6D0/MZaFw0RphNj2Hp6yS2rCImw/0csR1JPg3wZKSkm3oemyjftk6 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10428"; a="289755269" X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="289755269" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2022 11:17:47 -0700 X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="631253638" Received: from buichris-mobl.amr.corp.intel.com (HELO [10.209.124.150]) ([10.209.124.150]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2022 11:17:46 -0700 Message-ID: Date: Wed, 3 Aug 2022 11:17:46 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1.1 1/2] x86/sev: Use per-CPU PSC structure in prep for unaccepted memory support Content-Language: en-US To: Tom Lendacky , linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "Kirill A. Shutemov" , "H. Peter Anvin" , Michael Roth , Joerg Roedel , Andy Lutomirski , Peter Zijlstra References: <1b50311c-448b-96aa-1d96-f4bfed409c1f@amd.com> <2a2adc3570ae9c24d03fff877c4fe79ed43605e0.1659550264.git.thomas.lendacky@amd.com> From: Dave Hansen In-Reply-To: <2a2adc3570ae9c24d03fff877c4fe79ed43605e0.1659550264.git.thomas.lendacky@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/3/22 11:11, Tom Lendacky wrote: > + /* > + * Use the MSR protocol when either: > + * - executing in an NMI to avoid any possibility of a deadlock > + * - per-CPU GHCBs are not yet registered, since __vmgexit_psc() > + * uses the per-CPU GHCB. > + */ > + if (in_nmi() || !ghcb_percpu_ready) > + return early_set_pages_state(__pa(vaddr), npages, op); > + > + spin_lock_irqsave(&psc_desc_lock, flags); Would it be simpler to just do a spin_trylock_irqsave()? You fall back to early_set_pages_state() whenever you can't acquire the lock. That avoids even having to know what the situations are where you _might_ recurse. If it recurses, the trylock will just naturally fail. You simply can't have bugs where the "(in_nmi() || !ghcb_percpu_ready)" conditional was wrong.