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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64A7CC433FE for ; Tue, 22 Nov 2022 10:11:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF1716B0071; Tue, 22 Nov 2022 05:10:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DA08D6B0073; Tue, 22 Nov 2022 05:10:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8F596B0074; Tue, 22 Nov 2022 05:10:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B9A2F6B0071 for ; Tue, 22 Nov 2022 05:10:59 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 736E61C6523 for ; Tue, 22 Nov 2022 10:10:59 +0000 (UTC) X-FDA: 80160659838.17.DC26AC1 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf24.hostedemail.com (Postfix) with ESMTP id 36AB5180017 for ; Tue, 22 Nov 2022 10:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2kluR8XS/5l2vEzd270Z9ykwF5m8DT9IrYcaeynxfAY=; b=d6+qGB5BG/okyjo+T6PgxWuj8F NiFipH0849DEGMlf5aUr7bJHGWYBrgu0/Ge7R6qXNkY3IGC8R2UzcvbH9B4Y7s/IUzdzSSt1J34re w/ptngkZSYG/iTiBptnCDbEnHiJY/9YAsp3c9Mb9/So0DzVoImDGM9KcUbLVXZiQaig8Rb27KHize X9G4UbIITIeQKHqOxFO+ciMp6bORDsUNhKLBnzWI4irR7rteseajYbJ6SahLvAhs63rhgBUYeEo07 xs9dx9aTWKxrYoUw4FCqqXM91+Hnt00h1cY3uokF/3aQwH3NZUeWhlwR8xhpQI9bM4Vrg6mKmtz/N tmQc6P1w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxQEs-003P1G-RT; Tue, 22 Nov 2022 10:10:50 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 80540300244; Tue, 22 Nov 2022 11:10:48 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5BA3E2D66D658; Tue, 22 Nov 2022 11:10:48 +0100 (CET) Date: Tue, 22 Nov 2022 11:10:48 +0100 From: Peter Zijlstra To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, kirill.shutemov@linux.intel.com, ying.huang@intel.com, reinette.chatre@intel.com, len.brown@intel.com, tony.luck@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v7 10/20] x86/virt/tdx: Use all system memory when initializing TDX module as TDX memory Message-ID: References: <9b545148275b14a8c7edef1157f8ec44dc8116ee.1668988357.git.kai.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9b545148275b14a8c7edef1157f8ec44dc8116ee.1668988357.git.kai.huang@intel.com> ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=d6+qGB5B; spf=none (imf24.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669111858; a=rsa-sha256; cv=none; b=hAN3cb2HMUKUc7qaPQL/8/uDhfXtYcUdVwvGRo4468V5p3RxMYSQetf2Aqg5m456GVOnk1 1qV1yvF3Io3KNo6oAV7KumjPlQ/4hT1erN6GDkSotmLpSEggsBhhW5Gh9QQOEjL2n1WQm7 3DdQuLP5qLVaBwu0+JCIhOIDv4euhro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669111858; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2kluR8XS/5l2vEzd270Z9ykwF5m8DT9IrYcaeynxfAY=; b=yX3zbXbbNXn61MYg0PBUfDvoi25ddBG9vptzfkkbhWxNuNxVXrbOQ4/VbGcELIGCaFt9C0 qEOUggwbrqDAdNJa+7Dfa+n2w4rR4NrVzgIvGAwrRt3OYBf1skb/6oEJXV1mRICk7NdjPo icttG+wIkm00VtVdJW0MWMapCyuNW90= X-Rspamd-Queue-Id: 36AB5180017 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=d6+qGB5B; spf=none (imf24.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none X-Rspamd-Server: rspam06 X-Stat-Signature: ij5ta131dj7bxnje65nfgtu5pbhy47fi X-HE-Tag: 1669111855-48014 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Nov 21, 2022 at 01:26:32PM +1300, Kai Huang wrote: > +static int build_tdx_memory(void) > +{ > + unsigned long start_pfn, end_pfn; > + int i, nid, ret; > + > + for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { > + /* > + * The first 1MB may not be reported as TDX convertible > + * memory. Manually exclude them as TDX memory. > + * > + * This is fine as the first 1MB is already reserved in > + * reserve_real_mode() and won't end up to ZONE_DMA as > + * free page anyway. > + */ > + start_pfn = max(start_pfn, (unsigned long)SZ_1M >> PAGE_SHIFT); > + if (start_pfn >= end_pfn) > + continue; > + > + /* Verify memory is truly TDX convertible memory */ > + if (!pfn_range_covered_by_cmr(start_pfn, end_pfn)) { > + pr_info("Memory region [0x%lx, 0x%lx) is not TDX convertible memorry.\n", > + start_pfn << PAGE_SHIFT, > + end_pfn << PAGE_SHIFT); > + return -EINVAL; Given how tdx_cc_memory_compatible() below relies on tdx_memlist being empty; this error patch is wrong and should goto err. > + } > + > + /* > + * Add the memory regions as TDX memory. The regions in > + * memblock has already guaranteed they are in address > + * ascending order and don't overlap. > + */ > + ret = add_tdx_memblock(start_pfn, end_pfn, nid); > + if (ret) > + goto err; > + } > + > + return 0; > +err: > + free_tdx_memory(); > + return ret; > +} > +bool tdx_cc_memory_compatible(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct tdx_memblock *tmb; > + > + /* Empty list means TDX isn't enabled successfully */ > + if (list_empty(&tdx_memlist)) > + return true; > + > + list_for_each_entry(tmb, &tdx_memlist, list) { > + /* > + * The new range is TDX memory if it is fully covered > + * by any TDX memory block. > + */ > + if (start_pfn >= tmb->start_pfn && end_pfn <= tmb->end_pfn) > + return true; > + } > + return false; > +}