Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1654481pxp; Thu, 17 Mar 2022 13:43:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUy6COIMdRJ6GtCZZODxzRmC6BYOgpX05D5luPe25lhk/yVhcBJcFHJoCGynxCK9utGMwJ X-Received: by 2002:a63:1060:0:b0:374:6edc:7cfc with SMTP id 32-20020a631060000000b003746edc7cfcmr5197804pgq.500.1647549792606; Thu, 17 Mar 2022 13:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647549792; cv=none; d=google.com; s=arc-20160816; b=ovRDDT6O3j8IPABxAIu08xwp+DHNaokTfiblATXehbDyoqIZaqAsx1Qao895Y+696w aNI15OdtmeMc2Ldhss3ivQp8hMZ5JkuyhmDWgZoW8Yme4GNOmp7nF0mrp/Rj0vcD3N2i flJsdQpmMyLN1y+LKoSprbRHhSGVgUlTSsIXgI+Q+9+lvCuiANwhQMrhhVygIBXeTZp+ LAioHnSmPcXh05hNnn2i43k+Z3Fc/riVyX2ZxqTdbyovigPEUrIUpPx390CEE8iJWSHA lYlZZ4cyj0t+HTTDnyjBx+2h3r4JS476MT+EZThyjl7abKHh+oC2ClP7N+lYRU9vUBsC C60Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=xwa5B4vbC87faqjFjpMX9eHkgYU0LzWzNDEusWEFXMA=; b=eDgqC6XCvutmgPx4rDDeu0uVDd2Q0qxQKRK7hF73CPqqaTV4b5PUQC49f+DIusr0MF UITR2TcHOqiuC1lKLMY5sz/rr9V+DQfOv0yVbHLRBefaoSWm3+DusniO0hBHQ2+lk13A OPuC8OGWeBw0sLXVuUa775aQkb9g7R56MhbLEZt7EZ1792iQqfmR4rG2fM/pgQkpCmls b8yzvnz6xniPYO619YzUfIkqs8xAJhqQISCjfDvqp0g8hUsfO2quk8rpYEldCDk1R9EA zHdk8HsFCfPw7PmmWAJQ2aOTmDKlGW7eowiI66i7A69Q4XSWUWD44Ej/qvSCPQiIV58Q qlcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aXAczIdC; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a10-20020a170902ecca00b00153b2d16494si117213plh.156.2022.03.17.13.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 13:43:12 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aXAczIdC; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 406D717F3D9; Thu, 17 Mar 2022 13:11:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235174AbiCQOk2 (ORCPT + 99 others); Thu, 17 Mar 2022 10:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235175AbiCQOk1 (ORCPT ); Thu, 17 Mar 2022 10:40:27 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B715E9F3BB for ; Thu, 17 Mar 2022 07:39:10 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1647527949; 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: in-reply-to:in-reply-to:references:references; bh=xwa5B4vbC87faqjFjpMX9eHkgYU0LzWzNDEusWEFXMA=; b=aXAczIdCT5b8wJP+mVoY4R7Jp71iJt3bhoK/69/KoIRyiBa/T/4Pj+y2huc4Woeq/Bvy9y K5KYUWYAeQpJ0dOqohhKdBqKo2y2ahxG0URwLLpgVusUw51sFfPLDe9lponrYBoGIbn+lv pMvGyKXnUIUyFM4urZX6sMOpUVdiRWMzAMeDFybIEOqGqQiHNRvOrapDE6/rji/LUgm+ti WugGYbkFVfPhbBWdzRvJg9zjN2zPjM/bkgpZjK6OLelo2K/FkZvRoDUuhudkmJAfdK9kIy 9QVGp1leQkjhk4jxa3wHF2NT78+j3Y2CAYuvTubXD+LJfYgS7vonFLcZzvaanw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1647527949; 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: in-reply-to:in-reply-to:references:references; bh=xwa5B4vbC87faqjFjpMX9eHkgYU0LzWzNDEusWEFXMA=; b=Z1UtT6VeZQ8ZBxrky5MMlNxZgSh5g7/X0sLp/gp7EYSwLoJpG95TC8LaYJGS2w16xM1/1g a3u60SY+mRSeOUBg== To: "Kirill A. Shutemov" Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org, sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv6 05/30] x86/tdx: Exclude shared bit from __PHYSICAL_MASK In-Reply-To: <20220317135820.frdppktft4flzhha@black.fi.intel.com> References: <20220316020856.24435-1-kirill.shutemov@linux.intel.com> <20220316020856.24435-6-kirill.shutemov@linux.intel.com> <87czil303j.ffs@tglx> <20220317135820.frdppktft4flzhha@black.fi.intel.com> Date: Thu, 17 Mar 2022 15:39:08 +0100 Message-ID: <87r170d4oj.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Thu, Mar 17 2022 at 16:58, Kirill A. Shutemov wrote: > On Thu, Mar 17, 2022 at 01:16:00AM +0100, Thomas Gleixner wrote: >> On Wed, Mar 16 2022 at 05:08, Kirill A. Shutemov wrote: >> > @@ -82,6 +82,14 @@ void __init tdx_early_init(void) >> > >> > cc_set_vendor(CC_VENDOR_INTEL); >> > >> > + /* >> > + * All bits above GPA width are reserved and kernel treats shared bit >> > + * as flag, not as part of physical address. >> > + * >> > + * Adjust physical mask to only cover valid GPA bits. >> > + */ >> > + physical_mask &= GENMASK_ULL(gpa_width - 2, 0); >> > + >> >> Hrm. I forgot about the second use case for gpa_width, but my comment >> about ordering still stands. OTOH: >> >> GENMASK_ULL(gpa_width - 2, 0) == BIT_UL(gpa_width - 1) - 1 >> >> right? So you really can consolidate on the fact that cc_mask is a >> single bit which is above the guests physical address space boundary. >> >> I.e. make the code tell the story instead of adding lengthy comments >> explaining the obfuscation. > > So it will looks something like this: > > > cc_set_vendor(CC_VENDOR_INTEL); > cc_mask = get_cc_mask(); > cc_set_mask(cc_mask); > > /* > * All bits above GPA width are reserved and kernel treats shared bit > * as flag, not as part of physical address. > * > * Adjust physical mask to only cover valid GPA bits. > */ > physical_mask &= cc_mask - 1; > > I still think these comments are useful. I hided comment for cc_mask > calclulation inside get_cc_mask(). > > Does it look fine to you? Yes.