Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17604217rwd; Tue, 27 Jun 2023 05:29:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7GcS0Cm5B8zs8rOz9B9X/CYRmMNiqXh/SmozjNujsJ7zfY+eKDHBy28vb1OnL1v2q260Zx X-Received: by 2002:a05:6808:2a63:b0:3a1:dac8:9c1f with SMTP id fu3-20020a0568082a6300b003a1dac89c1fmr5712158oib.29.1687868960733; Tue, 27 Jun 2023 05:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687868960; cv=none; d=google.com; s=arc-20160816; b=wa3DfTDMeNvf8upQilOD2D62yJwgtHYUxofCDkGsyjQCK7O/uh6oNBiNFMUUY1Exyw 6f6Tbnp5BQnpmcHZY0ohMy8g7qph+v8A0fEtBXoolmV48gebG5srmgLWJj2IowpaHRB+ J9WR9uFTRsqupHmsPMVlt0Mn/0mBuH9qSLV69xCxLiYF8HZ1UUr+gnW6oSnbPXdkDaS+ 2PUBp90Ox5fREXkUgKmiKv1o1BTfnfeU4EpJgcICcm6HmEdFH4O22iNWWranXL71in3K hBnzMe+jvXJC/ZxNdBVhT1l4SW+rP1FQzGDbUODzckIxid1ujx14UcuY0+Amr7Zqqn/4 gkQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wK7yA0pjmYWcR0GdJVJojbTZ/AohDP7swFuJRA53W3w=; fh=rbzmoA0bikWEBYlDL/lhkNYsobMOqoq0KkcJh9LNcYs=; b=bTm/3h5iO0JlHlMoI/A4MK/hU1cQVEZi2V/qs6iwFwPm92Xpt5T+C84yjP/LDp1a9A +tvBXamUcykX9KlLG3TrhftdIdicN2JciVfRZodaz5aE2wnsC+YId/ApJkzVx7nJ12I7 WZIx6+vZLdFgBEthYO87g+fBXt2M6l3ghHjpNh726Ze1KskipbaNC4JOeyNxVikEqsQK gMkNIgW/F7xx3pC1c5sYzNoShgjX8HeErIwT6cwoew8ZsBJ9NKfkMO98TC/4WurUaLZ4 2ybEVcakgsnA1I/N5Qzf7xeBtMSu17IcpqrOMaAGixjFp/MtXtLOCuSt0BBSzaQwMTS2 lzDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UhlkP5V7; 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 y188-20020a6364c5000000b00502ee712648si7526591pgb.578.2023.06.27.05.29.08; Tue, 27 Jun 2023 05:29:20 -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=UhlkP5V7; 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 S230058AbjF0MTH (ORCPT + 99 others); Tue, 27 Jun 2023 08:19:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjF0MTG (ORCPT ); Tue, 27 Jun 2023 08:19:06 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8EBB1999; Tue, 27 Jun 2023 05:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687868344; x=1719404344; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=S/Oh83wIoz8iTjgXyFj7FBvLQ6z/1uq7Rt97/C+Sd54=; b=UhlkP5V77gYWSjHPKHlfFoxLhqjpTxGu3c4H7WKrpD1jaJ2Rj7OThxmC kogpxGeUMrU9ozH7RrmikkPX3U9hEoh/JCiiaIpj0JznH50AXczy0z8+i 7BKfL7RrdNv5LRF0T2muSqFT6KjWZRHv4LFvwywmrNCCGpXgo73Nb1upx fxU2ENeRQELt92z3QBkOLsmRkm9LVvKmSjKYmluvGw/KKyYDu6l25JqhC eXuQi2E3dPoONTlCMzzcox850guSlqS+ON4MNuXxPtfuP/sMSWov6VITI FplneC5xXvV7ojDOpXK3nKzUMx1Jq0WCmcZ488aWiMtN7G61x8MGW8WCL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10753"; a="364105346" X-IronPort-AV: E=Sophos;i="6.01,162,1684825200"; d="scan'208";a="364105346" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 05:19:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10753"; a="963174691" X-IronPort-AV: E=Sophos;i="6.01,162,1684825200"; d="scan'208";a="963174691" Received: from rbhaumik-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.217.121]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 05:18:56 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 453D0103738; Tue, 27 Jun 2023 15:18:53 +0300 (+03) Date: Tue, 27 Jun 2023 15:18:53 +0300 From: "kirill.shutemov@linux.intel.com" To: "Huang, Kai" Cc: "kvm@vger.kernel.org" , "Raj, Ashok" , "Hansen, Dave" , "david@redhat.com" , "bagasdotme@gmail.com" , "Luck, Tony" , "ak@linux.intel.com" , "Wysocki, Rafael J" , "linux-kernel@vger.kernel.org" , "Christopherson,, Sean" , "mingo@redhat.com" , "pbonzini@redhat.com" , "linux-mm@kvack.org" , "tglx@linutronix.de" , "Yamahata, Isaku" , "Chatre, Reinette" , "nik.borisov@suse.com" , "hpa@zytor.com" , "peterz@infradead.org" , "Shahar, Sagi" , "imammedo@redhat.com" , "bp@alien8.de" , "Gao, Chao" , "Brown, Len" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Huang, Ying" , "x86@kernel.org" , "Williams, Dan J" Subject: Re: [PATCH v12 07/22] x86/virt/tdx: Add skeleton to enable TDX on demand Message-ID: <20230627121853.ek5zr7sfiezfkfyj@box.shutemov.name> References: <104d324cd68b12e14722ee5d85a660cccccd8892.1687784645.git.kai.huang@intel.com> <20230627095012.ln47s62pqzdrnb7x@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Tue, Jun 27, 2023 at 10:34:04AM +0000, Huang, Kai wrote: > On Tue, 2023-06-27 at 12:50 +0300, kirill.shutemov@linux.intel.com wrote: > > On Tue, Jun 27, 2023 at 02:12:37AM +1200, Kai Huang wrote: > > > + /* > > > + * The TDX module global initialization only needs to be done > > > + * once on any cpu. > > > + */ > > > + raw_spin_lock_irqsave(&tdx_global_init_lock, flags); > > > > I don't understand how the comment justifies using raw spin lock. > > > > This comment is for using lock in general. The reason to use raw_ version is > because this function gets called in IRQ context, and for PREEMPT_RT kernel the > normal spinlock is converted to sleeping lock. Sorry, but this still doesn't explain anything. Why converting to sleeping lock here is wrong? There are plenty spin_lock_irqsave() users all over the kernel that are fine to be converted to sleeping lock on RT kernel. Why this use-case is special enough to justify raw_? From the documentation: raw_spinlock_t is a strict spinning lock implementation in all kernels, including PREEMPT_RT kernels. Use raw_spinlock_t only in real critical core code, low-level interrupt handling and places where disabling preemption or interrupts is required, for example, to safely access hardware state. raw_spinlock_t can sometimes also be used when the critical section is tiny, thus avoiding RT-mutex overhead. How does it apply here? > Dave suggested to comment on the function rather than comment on the > raw_spin_lock directly, e.g., no other kernel code does that: > > https://lore.kernel.org/linux-mm/d2b3bc5e-1371-0c50-8ecb-64fc70917d42@intel.com/ > > So I commented the function in this version: > > +/* > + * Do the module global initialization if not done yet. > + * It's always called with interrupts and preemption disabled. > + */ If interrupts are always disabled why do you need _irqsave()? -- Kiryl Shutsemau / Kirill A. Shutemov