Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17450933rwd; Tue, 27 Jun 2023 03:15:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7K8BJMyKJIFJ5wKZErWJB21rWeOwjb73hn7vYsbmzbNz/stxv52dpxAQVe+++qs2E0d5WQ X-Received: by 2002:a05:6a20:2455:b0:126:669f:4b with SMTP id t21-20020a056a20245500b00126669f004bmr10622589pzc.6.1687860944047; Tue, 27 Jun 2023 03:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687860944; cv=none; d=google.com; s=arc-20160816; b=DbWn9Ngv9DJkBJ/JCwJ5tOjyzXa9gNDPaP+wBkjVLwAPXHrxxU1JEjzZA2IyAuzsUD +s5wniZ31LVVaFCgP3EP75Yo5lp3r1DbipXc83gjnHRM2wKwEu8mItiAQWKjtICYhcp5 NRVCD4Nheq7fUXuw2h/g+JwIDLri4kOAOr4ESgn31vowokCELBT4qtVjtYjHgfsM44l1 B2eYrdaKOo63s21unqMFfEwbvad5J8+KQHmrkMA782LrlTnCBUv9xshGL17dOATXTW+H ANssxGKjmjW8VxZ4huIN7SfnkV2sejxl0+H2UT/CNMyT33bBT6+bxRmPsHLOdSIO7BUc kNjg== 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=D6SK+owre2dKCa3QUB+joO/wubvXgRYVMrsY3OmdZSU=; fh=U3TJmJHrqmoyVzdr5WTQxA/qFKy1nY/GQSZ6ivpgig8=; b=pXInq9Bp4nQRDNzy2l7nAldSGrRmDXYM3aegIAzNouT545VdEFl4aK+1OtHGrRIzSq ApEC0r5JyAh8c41xkvmfsXFvq7un8gQzawcRr0c3716juw0eC7XqJQOUTMiq7WTMD/rK dPWqgV6woABrSR6S1EvxPoLSSdU4nW2xrtkh+qpC/fQaplq7aUO4t2JVPgV55iUd04h4 5N189IU4e+PjY8T0P+iICVCJIAM59COATHBJmssByecHbXztQEVsv8gN6DnkoYaebUxO Aj14Q0VHnuR1P8ybeqDBZdZvszi5K+UxJ4nIZ6H9e/vHbSLRkhqkoWmKZjZLtR/XVklt uKIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OrBdq7Em; 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 m7-20020a1709026bc700b001b5395382a0si6603349plt.212.2023.06.27.03.15.09; Tue, 27 Jun 2023 03:15:44 -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=OrBdq7Em; 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 S231700AbjF0Jx1 (ORCPT + 99 others); Tue, 27 Jun 2023 05:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231805AbjF0Jwn (ORCPT ); Tue, 27 Jun 2023 05:52:43 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 037722958; Tue, 27 Jun 2023 02:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687859544; x=1719395544; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=eMQjSnWISAaYo3C4cvXdou1DofAukXurvqYsZXMKRUs=; b=OrBdq7EmQonnfTh+2fj9J+QlBt8/rLpNwaLGxy6bxvTMZ8PWpdaMPJx+ nx5Tdh+vt8Gi/HdUECsVPpA43mn5NovQFyO6xDdt8hGzYZ3rsxQP0pk1Y 58OHaxCedT1ZnMzKgh1jAuwwcQmdFIzACPPsW5ioT7areQrp5FsQqdxgg zGd56TF20R4tXexxIoARhEc/VHG4Deo/rYNvCc7Lv93JnvHR8yrtJmG3p Zjt1mxanqvnWQ0HezhSUeXQAtnSrm8/oeBQosrSLbwg2Wis+BWzrUHxZ2 eZtR7RaAIfvyrIrCy8SnN2m1c4+X2KnmtG1X/IYmwjTS8YDARHwBaKRS8 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10753"; a="427528589" X-IronPort-AV: E=Sophos;i="6.01,162,1684825200"; d="scan'208";a="427528589" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 02:51:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10753"; a="781794199" X-IronPort-AV: E=Sophos;i="6.01,162,1684825200"; d="scan'208";a="781794199" Received: from rbhaumik-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.217.121]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 02:51:27 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id D2229103732; Tue, 27 Jun 2023 12:51:24 +0300 (+03) Date: Tue, 27 Jun 2023 12:51:24 +0300 From: kirill.shutemov@linux.intel.com To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, dave.hansen@intel.com, tony.luck@intel.com, peterz@infradead.org, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ashok.raj@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, ying.huang@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, nik.borisov@suse.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v12 08/22] x86/virt/tdx: Get information about TDX module and TDX-capable memory Message-ID: <20230627095124.nhiypr6ivi4kdfrw@box.shutemov.name> References: 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,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 02:12:38AM +1200, Kai Huang wrote: > static int init_tdx_module(void) > { > + struct tdsysinfo_struct *sysinfo; > + struct cmr_info *cmr_array; > + int ret; > + > + /* > + * Get the TDSYSINFO_STRUCT and CMRs from the TDX module. > + * > + * The buffers of the TDSYSINFO_STRUCT and the CMR array passed > + * to the TDX module must be 1024-bytes and 512-bytes aligned > + * respectively. Allocate one page to accommodate them both and > + * also meet those alignment requirements. > + */ > + sysinfo = (struct tdsysinfo_struct *)__get_free_page(GFP_KERNEL); > + if (!sysinfo) > + return -ENOMEM; > + cmr_array = (struct cmr_info *)((unsigned long)sysinfo + PAGE_SIZE / 2); > + > + BUILD_BUG_ON(PAGE_SIZE / 2 < TDSYSINFO_STRUCT_SIZE); > + BUILD_BUG_ON(PAGE_SIZE / 2 < sizeof(struct cmr_info) * MAX_CMRS); This works, but why not just use slab for this? kmalloc has 512 and 1024 pools already and you won't waste memory for rounding up. Something like this: sysinfo = kmalloc(TDSYSINFO_STRUCT_SIZE, GFP_KERNEL); if (!sysinfo) return -ENOMEM; cmr_array_size = sizeof(struct cmr_info) * MAX_CMRS; /* CMR array has to be 512-aligned */ cmr_array_size = round_up(cmr_array_size, 512); cmr_array = kmalloc(cmr_array_size, GFP_KERNEL); if (!cmr_array) { kfree(sysinfo); return -ENOMEM; } ? -- Kiryl Shutsemau / Kirill A. Shutemov